add code for getting the primary interface
authorFelix Fietkau <nbd@openwrt.org>
Thu, 30 May 2013 17:23:25 +0000 (19:23 +0200)
committerFelix Fietkau <nbd@openwrt.org>
Thu, 30 May 2013 17:23:25 +0000 (19:23 +0200)
main.c
switch.h

diff --git a/main.c b/main.c
index 5f5c4ff..cf58c17 100644 (file)
--- a/main.c
+++ b/main.c
@@ -187,6 +187,27 @@ find_dev_data(struct usbdev_data *data, struct device *dev)
        return NULL;
 }
 
        return NULL;
 }
 
+static void
+parse_interface_config(libusb_device *dev, struct usbdev_data *data)
+{
+       struct libusb_config_descriptor *config;
+       const struct libusb_interface *iface;
+
+       data->interface = -1;
+       if (libusb_get_config_descriptor(dev, 0, &config))
+               return;
+
+       data->config = config;
+       if (!config->bNumInterfaces)
+               return;
+
+       iface = &config->interface[0];
+       if (!iface->num_altsetting)
+               return;
+
+       data->interface = iface->altsetting[0].bInterfaceNumber;
+}
+
 static void iterate_devs(cmd_cb_t cb)
 {
        struct usbdev_data data;
 static void iterate_devs(cmd_cb_t cb)
 {
        struct usbdev_data data;
@@ -221,9 +242,15 @@ static void iterate_devs(cmd_cb_t cb)
                        data.devh, data.desc.iSerialNumber,
                        (void *) data.serial, sizeof(data.serial));
 
                        data.devh, data.desc.iSerialNumber,
                        (void *) data.serial, sizeof(data.serial));
 
+               parse_interface_config(usbdevs[i], &data);
+
                data.info = find_dev_data(&data, dev);
                if (data.info)
                        cb(&data);
                data.info = find_dev_data(&data, dev);
                if (data.info)
                        cb(&data);
+
+               if (data.config)
+                       libusb_free_config_descriptor(data.config);
+
                libusb_close(data.devh);
        }
 }
                libusb_close(data.devh);
        }
 }
index eda94c2..a6d5297 100644 (file)
--- a/switch.h
+++ b/switch.h
@@ -6,8 +6,10 @@
 
 struct usbdev_data {
        struct libusb_device_descriptor desc;
 
 struct usbdev_data {
        struct libusb_device_descriptor desc;
+       struct libusb_config_descriptor *config;
        libusb_device_handle *devh;
        struct blob_attr *info;
        libusb_device_handle *devh;
        struct blob_attr *info;
+       int interface;
 
        char idstr[10];
        char mfg[128], prod[128], serial[128];
 
        char idstr[10];
        char mfg[128], prod[128], serial[128];