X-Git-Url: http://git.openwrt.org/?p=project%2Fusbmode.git;a=blobdiff_plain;f=switch.c;h=587a2af05c538fee2a8eedce768dd9ccf51395e7;hp=b8fe88e39e377096dead882fd1a2826e8d277584;hb=HEAD;hpb=01ecc3b9764d1dd89cf36ede0a2d98f9adb0cd33 diff --git a/switch.c b/switch.c index b8fe88e..3716bb7 100644 --- a/switch.c +++ b/switch.c @@ -1,8 +1,10 @@ +// SPDX-License-Identifier: GPL-2.0-or-later #include #include "switch.h" enum { DATA_MODE, + DATA_MODEVAL, DATA_MSG, DATA_INTERFACE, DATA_MSG_EP, @@ -11,6 +13,7 @@ enum { DATA_RELEASE_DELAY, DATA_CONFIG, DATA_ALT, + DATA_DEV_CLASS, __DATA_MAX }; @@ -151,6 +154,20 @@ static void handle_huaweinew(struct usbdev_data *data, struct blob_attr **tb) send_messages(data, msgs, ARRAY_SIZE(msgs)); } +static void handle_option(struct usbdev_data *data, struct blob_attr **tb) +{ + static struct msg_entry msgs[] = { + { + "\x55\x53\x42\x43\x12\x34\x56\x78\x00\x00\x00\x00\x00\x00\x06\x01" + "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", 31 + } + }; + + detach_driver(data); + data->need_response = false; + send_messages(data, msgs, ARRAY_SIZE(msgs)); +} + static void handle_standardeject(struct usbdev_data *data, struct blob_attr **tb) { static struct msg_entry msgs[] = { @@ -160,6 +177,12 @@ static void handle_standardeject(struct usbdev_data *data, struct blob_attr **tb }, { "\x55\x53\x42\x43\x12\x34\x56\x79\x00\x00\x00\x00\x00\x00\x06\x1b" "\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", 31 + }, { + "\x55\x53\x42\x43\x12\x34\x56\x78\x00\x00\x00\x00\x00\x01\x06\x1e" + "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", 31 + }, { + "\x55\x53\x42\x43\x12\x34\x56\x79\x00\x00\x00\x00\x00\x01\x06\x1b" + "\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", 31 } }; @@ -319,6 +342,70 @@ 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 handle_quanta(struct usbdev_data *data, struct blob_attr **tb) +{ + int type = LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE | LIBUSB_ENDPOINT_IN; + + detach_driver(data); + send_control_packet(data, type, 0xff, 0, 0, 8); +} + +static void handle_blackberry(struct usbdev_data *data, struct blob_attr **tb) +{ + int type = LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE | LIBUSB_ENDPOINT_IN; + + detach_driver(data); + send_control_packet(data, type, 0xb1, 0x0000, 0, 8); + send_control_packet(data, type, 0xa9, 0x000e, 0, 8); +} + +static void handle_pantech(struct usbdev_data *data, struct blob_attr **tb) +{ + int type = LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE | LIBUSB_ENDPOINT_OUT; + int val = 1; + + if (tb[DATA_MODEVAL]) + val = blobmsg_get_u32(tb[DATA_MODEVAL]); + detach_driver(data); + if (val > 1) + send_control_packet(data, type, 0x70, val, 0, 0); +} + static void set_alt_setting(struct usbdev_data *data, int setting) { if (libusb_claim_interface(data->devh, data->interface)) @@ -341,6 +428,11 @@ enum { MODE_SEQUANS, MODE_MOBILE_ACTION, MODE_CISCO, + MODE_MBIM, + MODE_OPTION, + MODE_QUANTA, + MODE_BLACKBERRY, + MODE_PANTECH, __MODE_MAX }; @@ -360,12 +452,18 @@ 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 }, + [MODE_OPTION] = { "Option", handle_option }, + [MODE_QUANTA] = { "Quanta", handle_quanta }, + [MODE_BLACKBERRY] = { "Blackberry", handle_blackberry }, + [MODE_PANTECH] = { "Pantech", handle_pantech }, }; void handle_switch(struct usbdev_data *data) { static const struct blobmsg_policy data_policy[__DATA_MAX] = { [DATA_MODE] = { .name = "mode", .type = BLOBMSG_TYPE_STRING }, + [DATA_MODEVAL] = { .name = "modeval", .type = BLOBMSG_TYPE_INT32 }, [DATA_MSG] = { .name = "msg", .type = BLOBMSG_TYPE_ARRAY }, [DATA_INTERFACE] = { .name = "interface", .type = BLOBMSG_TYPE_INT32 }, [DATA_MSG_EP] = { .name = "msg_endpoint", .type = BLOBMSG_TYPE_INT32 }, @@ -373,12 +471,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 +497,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; @@ -415,8 +521,11 @@ void handle_switch(struct usbdev_data *data) config_new = blobmsg_get_u32(tb[DATA_CONFIG]); if (libusb_get_configuration(data->devh, &config) || - config != config_new) + config != config_new) { + libusb_set_configuration(data->devh, 0); + usleep(100000); libusb_set_configuration(data->devh, config_new); + } } if (tb[DATA_ALT]) {