From: John Crispin Date: Sun, 24 Aug 2014 18:15:01 +0000 (+0200) Subject: add a mbim eject handler X-Git-Url: http://git.archive.openwrt.org/?p=project%2Fusbmode.git;a=commitdiff_plain;h=993a9a542791953c4804f7ddbb3a07756738e37a add a mbim eject handler Signed-off-by: John Crispin --- diff --git a/convert-modeswitch.pl b/convert-modeswitch.pl index 8086e53..7b2323b 100755 --- a/convert-modeswitch.pl +++ b/convert-modeswitch.pl @@ -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 --- 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)); diff --git a/switch.c b/switch.c index b8fe88e..2c33d9c 100644 --- 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) diff --git a/switch.h b/switch.h index 246a29a..97c14f3 100644 --- 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;