X-Git-Url: http://git.openwrt.org/?a=blobdiff_plain;f=switch.c;h=b2835610203e27efc833c55ce9a7ec490554a17c;hb=8a47c4b6649f8437bb60300471400d558426612e;hp=b8fe88e39e377096dead882fd1a2826e8d277584;hpb=01ecc3b9764d1dd89cf36ede0a2d98f9adb0cd33;p=project%2Fusbmode.git diff --git a/switch.c b/switch.c index b8fe88e..b283561 100644 --- a/switch.c +++ b/switch.c @@ -11,6 +11,7 @@ enum { DATA_RELEASE_DELAY, DATA_CONFIG, DATA_ALT, + DATA_DEV_CLASS, __DATA_MAX }; @@ -319,6 +320,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 +377,7 @@ enum { MODE_SEQUANS, MODE_MOBILE_ACTION, MODE_CISCO, + MODE_MBIM, __MODE_MAX }; @@ -360,6 +397,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) @@ -373,12 +411,17 @@ void handle_switch(struct usbdev_data *data) [DATA_RESPONSE] = { .name = "response", .type = BLOBMSG_TYPE_BOOL }, [DATA_CONFIG] = { .name = "config", .type = BLOBMSG_TYPE_INT32 }, [DATA_ALT] = { .name = "alt", .type = BLOBMSG_TYPE_INT32 }, + [DATA_DEV_CLASS] = { .name = "t_class", .type = BLOBMSG_TYPE_INT32 }, }; struct blob_attr *tb[__DATA_MAX]; int mode = MODE_GENERIC; + int t_class = 0; blobmsg_parse(data_policy, __DATA_MAX, tb, blobmsg_data(data->info), blobmsg_data_len(data->info)); + if (tb[DATA_DEV_CLASS]) + t_class = blobmsg_get_u32(tb[DATA_DEV_CLASS]); + if (tb[DATA_INTERFACE]) data->interface = blobmsg_get_u32(tb[DATA_INTERFACE]); @@ -394,6 +437,9 @@ void handle_switch(struct usbdev_data *data) if (tb[DATA_RESPONSE]) data->need_response = blobmsg_get_bool(tb[DATA_RESPONSE]); + if (t_class > 0 && data->dev_class != t_class) + return; + if (tb[DATA_MODE]) { const char *modestr; int i;