diff options
author | John Crispin <blogic@openwrt.org> | 2014-08-24 20:15:01 +0200 |
---|---|---|
committer | John Crispin <blogic@openwrt.org> | 2014-08-24 20:15:59 +0200 |
commit | 993a9a542791953c4804f7ddbb3a07756738e37a (patch) | |
tree | 7e46cd607dd9c2536fc728f44b43eb2eb8ed32f2 | |
parent | 01ecc3b9764d1dd89cf36ede0a2d98f9adb0cd33 (diff) |
add a mbim eject handler
Signed-off-by: John Crispin <blogic@openwrt.org>
-rwxr-xr-x | convert-modeswitch.pl | 1 | ||||
-rw-r--r-- | main.c | 2 | ||||
-rw-r--r-- | switch.c | 37 | ||||
-rw-r--r-- | switch.h | 1 |
4 files changed, 41 insertions, 0 deletions
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, @@ -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)); @@ -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) @@ -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; |