From: Felix Fietkau Date: Thu, 30 May 2013 17:45:11 +0000 (+0200) Subject: find endpoint addresses X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=ae5b25523c3ef805a84f16a477ff8b4663060b02;p=oweals%2Fusbmode.git find endpoint addresses --- diff --git a/main.c b/main.c index cf58c17..b7461ad 100644 --- a/main.c +++ b/main.c @@ -19,8 +19,8 @@ static int verbose = 0; static const char *config_file = DEFAULT_CONFIG; static struct blob_buf conf; -static struct blob_attr **messages; -static int n_messages; +struct blob_attr **messages = NULL; +int n_messages = 0; static struct avl_tree devices; @@ -192,6 +192,8 @@ parse_interface_config(libusb_device *dev, struct usbdev_data *data) { struct libusb_config_descriptor *config; const struct libusb_interface *iface; + const struct libusb_interface_descriptor *alt; + int i; data->interface = -1; if (libusb_get_config_descriptor(dev, 0, &config)) @@ -205,7 +207,28 @@ parse_interface_config(libusb_device *dev, struct usbdev_data *data) if (!iface->num_altsetting) return; - data->interface = iface->altsetting[0].bInterfaceNumber; + alt = &iface->altsetting[0]; + data->interface = alt->bInterfaceNumber; + + for (i = 0; i < alt->bNumEndpoints; i++) { + const struct libusb_endpoint_descriptor *ep = &alt->endpoint[i]; + bool out = false; + + if (data->msg_endpoint && data->response_endpoint) + break; + + if ((ep->bmAttributes & LIBUSB_TRANSFER_TYPE_MASK) != + LIBUSB_TRANSFER_TYPE_BULK) + continue; + + out = (ep->bEndpointAddress & LIBUSB_ENDPOINT_DIR_MASK) == + LIBUSB_ENDPOINT_OUT; + + if (!data->msg_endpoint && out) + data->msg_endpoint = ep->bEndpointAddress; + if (!data->response_endpoint && !out) + data->response_endpoint = ep->bEndpointAddress; + } } static void iterate_devs(cmd_cb_t cb) diff --git a/switch.h b/switch.h index eb5968f..ab09f11 100644 --- a/switch.h +++ b/switch.h @@ -10,11 +10,16 @@ struct usbdev_data { libusb_device_handle *devh; struct blob_attr *info; int interface; + int msg_endpoint; + int response_endpoint; char idstr[10]; char mfg[128], prod[128], serial[128]; }; +extern struct blob_attr **messages; +extern int n_messages; + void handle_switch(struct usbdev_data *data); #endif