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 8086e53aa9ea087a29f938a15db10ad86a40a360..7b2323b51860c821839c7917ae81ae99bb0a24bb 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 22e17052e7107069816a6ccfcce05c0b111a53df..859a90a421c84ede8512ddd123ef60a78f64c962 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 b8fe88e39e377096dead882fd1a2826e8d277584..2c33d9c25f81e28f6f90ff9320459390be5ec1a1 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 246a29a519df31164c758767d96224c8f3983f90..97c14f3ce411a3a181e64719a10c600bffc54dfc 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;