From f40f84c27534159066c94dadc0c08e0b255c3e26 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Bj=C3=B8rn=20Mork?= Date: Mon, 18 Dec 2017 15:00:56 +0100 Subject: [PATCH] support PantechMode MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit The behaviour of the usb_modeswitch "Pantech" mode depends on the option value, so we need to propagate this via the json config to the usbmode tool. Signed-off-by: Bjørn Mork --- convert-modeswitch.pl | 9 +++++++++ switch.c | 16 ++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/convert-modeswitch.pl b/convert-modeswitch.pl index 48d0fd4..b1530bd 100755 --- a/convert-modeswitch.pl +++ b/convert-modeswitch.pl @@ -46,9 +46,15 @@ sub add_mode { return $_[1]; } +sub add_modeval { + return unless ($_[1] && $_[1] =~ /^\d+$/); + $_[0]->{"ModeValue"} = $_[1]; +} + my $hex_option = [ undef, \&add_hex ]; my $msg_option = [ undef, \&add_message ]; my $mode_option = [ "Mode", \&add_mode ]; +my $value_mode_option = [ "Mode", \&add_mode, \&add_modeval ]; my %options = ( TargetVendor => $hex_option, TargetProductList => [ "TargetProduct", sub { return [ map(hex,split(/,/, $_[0])) ]; } ], @@ -64,6 +70,7 @@ my %options = ( HuaweiNewMode => $mode_option, QuantaMode => $mode_option, BlackberryMode => $mode_option, + PantechMode => $value_mode_option, OptionMode => $mode_option, SierraMode => $mode_option, SonyMode => $mode_option, @@ -116,6 +123,7 @@ sub parse_file($) { next; }; + $opt->[2] and &{$opt->[2]}($dev, $val, $var); $opt->[1] and $val = &{$opt->[1]}($val, $var); $opt->[0] and $var = $opt->[0]; $dev->{$var} = $val; @@ -210,6 +218,7 @@ foreach my $devid (sort keys %devices) { dev_opt($cur->{TargetClass}, "t_class", "int", \$sep); dev_opt($cur->{DetachStorageOnly}, "detach_storage", "bool", \$sep); dev_opt($cur->{Mode}, "mode", "string", \$sep); + dev_opt($cur->{ModeValue}, "modeval", "int", \$sep); dev_opt($cur->{NoDriverLoading}, "no_driver", "bool", \$sep); dev_opt($cur->{MessageEndpoint}, "msg_endpoint", "int", \$sep); my $msg = [ diff --git a/switch.c b/switch.c index fe25e80..cc04237 100644 --- a/switch.c +++ b/switch.c @@ -3,6 +3,7 @@ enum { DATA_MODE, + DATA_MODEVAL, DATA_MSG, DATA_INTERFACE, DATA_MSG_EP, @@ -392,6 +393,18 @@ static void handle_blackberry(struct usbdev_data *data, struct blob_attr **tb) 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)) @@ -418,6 +431,7 @@ enum { MODE_OPTION, MODE_QUANTA, MODE_BLACKBERRY, + MODE_PANTECH, __MODE_MAX }; @@ -441,12 +455,14 @@ static const struct { [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 }, -- 2.30.2