summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelix Fietkau <nbd@openwrt.org>2013-05-30 19:45:11 +0200
committerFelix Fietkau <nbd@openwrt.org>2013-05-30 19:45:11 +0200
commitae5b25523c3ef805a84f16a477ff8b4663060b02 (patch)
treed7b5bfcc29a7586528c343d3c614c38c1ba4c88d
parentc90c4320a4b60fe299505d5186fb501002b0f625 (diff)
find endpoint addresses
-rw-r--r--main.c29
-rw-r--r--switch.h5
2 files changed, 31 insertions, 3 deletions
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