add a mbim eject handler
authorJohn Crispin <blogic@openwrt.org>
Sun, 24 Aug 2014 18:15:01 +0000 (20:15 +0200)
committerJohn Crispin <blogic@openwrt.org>
Sun, 24 Aug 2014 18:15:59 +0000 (20:15 +0200)
Signed-off-by: John Crispin <blogic@openwrt.org>
convert-modeswitch.pl
main.c
switch.c
switch.h

index 8086e53..7b2323b 100755 (executable)
@@ -59,6 +59,7 @@ my %options = (
        MessageContent3 => $msg_option,
        WaitBefore => [ ],
        DetachStorageOnly => [ ],
+       MBIM => $mode_option,
        HuaweiMode => $mode_option,
        HuaweiNewMode => $mode_option,
        SierraMode => $mode_option,
diff --git a/main.c b/main.c
index 22e1705..859a90a 100644 (file)
--- a/main.c
+++ b/main.c
@@ -261,6 +261,8 @@ static void iterate_devs(cmd_cb_t cb)
                if (libusb_open(usbdevs[i], &data.devh))
                        continue;
 
+               data.dev = usbdevs[i];
+
                libusb_get_string_descriptor_ascii(
                        data.devh, data.desc.iManufacturer,
                        (void *) data.mfg, sizeof(data.mfg));
index b8fe88e..2c33d9c 100644 (file)
--- a/switch.c
+++ b/switch.c
@@ -319,6 +319,41 @@ static void handle_cisco(struct usbdev_data *data, struct blob_attr **tb)
        send_messages(data, msgs, ARRAY_SIZE(msgs));
 }
 
+static void handle_mbim(struct usbdev_data *data, struct blob_attr **tb)
+{
+       int j;
+
+       if (data->desc.bNumConfigurations < 2)
+               return;
+
+       for (j = 0; j < data->desc.bNumConfigurations; j++) {
+               struct libusb_config_descriptor *config;
+               int i;
+
+               libusb_get_config_descriptor(data->dev, j, &config);
+
+               for (i = 0; i < config->bNumInterfaces; i++) {
+                       if (config->interface[i].altsetting[0].bInterfaceClass == 2) {
+                               if (config->interface[i].altsetting[0].bInterfaceSubClass == 0x0e) {
+                                       struct libusb_config_descriptor *active;
+                                       int count = 5;
+
+                                       libusb_get_active_config_descriptor(data->dev, &active);
+                                       if (active->bConfigurationValue == config->bConfigurationValue)
+                                               return;
+                                       while ((libusb_set_configuration(data->devh, config->bConfigurationValue) < 0) && --count)
+                                               libusb_detach_kernel_driver(data->devh, active->interface[0].altsetting[0].bInterfaceNumber);
+
+                                       libusb_free_config_descriptor(config);
+                                       return;
+                               }
+                       }
+               }
+
+               libusb_free_config_descriptor(config);
+       }
+}
+
 static void set_alt_setting(struct usbdev_data *data, int setting)
 {
        if (libusb_claim_interface(data->devh, data->interface))
@@ -341,6 +376,7 @@ enum {
        MODE_SEQUANS,
        MODE_MOBILE_ACTION,
        MODE_CISCO,
+       MODE_MBIM,
        __MODE_MAX
 };
 
@@ -360,6 +396,7 @@ static const struct {
        [MODE_SEQUANS] = { "Sequans", handle_sequans },
        [MODE_MOBILE_ACTION] = { "MobileAction", handle_mobile_action },
        [MODE_CISCO] = { "Cisco", handle_cisco },
+       [MODE_MBIM] = { "MBIM", handle_mbim },
 };
 
 void handle_switch(struct usbdev_data *data)
index 246a29a..97c14f3 100644 (file)
--- a/switch.h
+++ b/switch.h
@@ -7,6 +7,7 @@
 struct usbdev_data {
        struct libusb_device_descriptor desc;
        struct libusb_config_descriptor *config;
+       libusb_device *dev;
        libusb_device_handle *devh;
        struct blob_attr *info;
        int interface;