Home | History | Annotate | Line # | Download | only in usb
umodeswitch.c revision 1.3.2.2
      1  1.3.2.2  skrll /*	$NetBSD: umodeswitch.c,v 1.3.2.2 2017/08/28 17:52:28 skrll Exp $	*/
      2  1.3.2.2  skrll 
      3  1.3.2.2  skrll /*-
      4  1.3.2.2  skrll  * Copyright (c) 2009, 2017 The NetBSD Foundation, Inc.
      5  1.3.2.2  skrll  * All rights reserved.
      6  1.3.2.2  skrll  *
      7  1.3.2.2  skrll  * This code is derived from software contributed to The NetBSD Foundation.
      8  1.3.2.2  skrll  *
      9  1.3.2.2  skrll  * Redistribution and use in source and binary forms, with or without
     10  1.3.2.2  skrll  * modification, are permitted provided that the following conditions
     11  1.3.2.2  skrll  * are met:
     12  1.3.2.2  skrll  * 1. Redistributions of source code must retain the above copyright
     13  1.3.2.2  skrll  *    notice, this list of conditions and the following disclaimer.
     14  1.3.2.2  skrll  * 2. Redistributions in binary form must reproduce the above copyright
     15  1.3.2.2  skrll  *    notice, this list of conditions and the following disclaimer in the
     16  1.3.2.2  skrll  *    documentation and/or other materials provided with the distribution.
     17  1.3.2.2  skrll  *
     18  1.3.2.2  skrll  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     19  1.3.2.2  skrll  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     20  1.3.2.2  skrll  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     21  1.3.2.2  skrll  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     22  1.3.2.2  skrll  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     23  1.3.2.2  skrll  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     24  1.3.2.2  skrll  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     25  1.3.2.2  skrll  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     26  1.3.2.2  skrll  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     27  1.3.2.2  skrll  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     28  1.3.2.2  skrll  * POSSIBILITY OF SUCH DAMAGE.
     29  1.3.2.2  skrll  */
     30  1.3.2.2  skrll 
     31  1.3.2.2  skrll 
     32  1.3.2.2  skrll #include <sys/cdefs.h>
     33  1.3.2.2  skrll __KERNEL_RCSID(0, "$NetBSD: umodeswitch.c,v 1.3.2.2 2017/08/28 17:52:28 skrll Exp $");
     34  1.3.2.2  skrll 
     35  1.3.2.2  skrll #include <sys/param.h>
     36  1.3.2.2  skrll #include <sys/systm.h>
     37  1.3.2.2  skrll #include <sys/kernel.h>
     38  1.3.2.2  skrll #include <sys/kmem.h>
     39  1.3.2.2  skrll #include <sys/bus.h>
     40  1.3.2.2  skrll #include <sys/conf.h>
     41  1.3.2.2  skrll #include <sys/tty.h>
     42  1.3.2.2  skrll 
     43  1.3.2.2  skrll #include <dev/usb/usb.h>
     44  1.3.2.2  skrll #include <dev/usb/usbdi.h>
     45  1.3.2.2  skrll #include <dev/usb/usbdivar.h>
     46  1.3.2.2  skrll #include <dev/usb/usbdi_util.h>
     47  1.3.2.2  skrll 
     48  1.3.2.2  skrll #include "usbdevs.h"
     49  1.3.2.2  skrll 
     50  1.3.2.2  skrll /*
     51  1.3.2.2  skrll  * This device driver handles devices that have two personalities.
     52  1.3.2.2  skrll  * The first uses the 'usbdevif'
     53  1.3.2.2  skrll  * interface attribute so that a match will claim the entire USB device
     54  1.3.2.2  skrll  * for itself. This is used for when a device needs to be mode-switched
     55  1.3.2.2  skrll  * and ensures any other interfaces present cannot be claimed by other
     56  1.3.2.2  skrll  * drivers while the mode-switch is in progress.
     57  1.3.2.2  skrll  */
     58  1.3.2.2  skrll static int umodeswitch_match(device_t, cfdata_t, void *);
     59  1.3.2.2  skrll static void umodeswitch_attach(device_t, device_t, void *);
     60  1.3.2.2  skrll static int umodeswitch_detach(device_t, int);
     61  1.3.2.2  skrll 
     62  1.3.2.2  skrll CFATTACH_DECL2_NEW(umodeswitch, 0, umodeswitch_match,
     63  1.3.2.2  skrll     umodeswitch_attach, umodeswitch_detach, NULL, NULL, NULL);
     64  1.3.2.2  skrll 
     65  1.3.2.2  skrll static int
     66  1.3.2.2  skrll send_bulkmsg(struct usbd_device *dev, void *cmd, size_t cmdlen)
     67  1.3.2.2  skrll {
     68  1.3.2.2  skrll 	struct usbd_interface *iface;
     69  1.3.2.2  skrll 	usb_interface_descriptor_t *id;
     70  1.3.2.2  skrll 	usb_endpoint_descriptor_t *ed;
     71  1.3.2.2  skrll 	struct usbd_pipe *pipe;
     72  1.3.2.2  skrll 	struct usbd_xfer *xfer;
     73  1.3.2.2  skrll 	int err, i;
     74  1.3.2.2  skrll 
     75  1.3.2.2  skrll 	/* Move the device into the configured state. */
     76  1.3.2.2  skrll 	err = usbd_set_config_index(dev, 0, 0);
     77  1.3.2.2  skrll 	if (err) {
     78  1.3.2.2  skrll 		aprint_error("%s: failed to set config index\n", __func__);
     79  1.3.2.2  skrll 		return UMATCH_NONE;
     80  1.3.2.2  skrll 	}
     81  1.3.2.2  skrll 
     82  1.3.2.2  skrll 	err = usbd_device2interface_handle(dev, 0, &iface);
     83  1.3.2.2  skrll 	if (err != 0) {
     84  1.3.2.2  skrll 		aprint_error("%s: failed to get interface\n", __func__);
     85  1.3.2.2  skrll 		return UMATCH_NONE;
     86  1.3.2.2  skrll 	}
     87  1.3.2.2  skrll 
     88  1.3.2.2  skrll 	id = usbd_get_interface_descriptor(iface);
     89  1.3.2.2  skrll 	ed = NULL;
     90  1.3.2.2  skrll 	for (i = 0 ; i < id->bNumEndpoints ; i++) {
     91  1.3.2.2  skrll 		ed = usbd_interface2endpoint_descriptor(iface, i);
     92  1.3.2.2  skrll 		if (ed == NULL)
     93  1.3.2.2  skrll 			continue;
     94  1.3.2.2  skrll 		if (UE_GET_DIR(ed->bEndpointAddress) != UE_DIR_OUT)
     95  1.3.2.2  skrll 			continue;
     96  1.3.2.2  skrll 		if ((ed->bmAttributes & UE_XFERTYPE) == UE_BULK)
     97  1.3.2.2  skrll 			break;
     98  1.3.2.2  skrll 	}
     99  1.3.2.2  skrll 
    100  1.3.2.2  skrll 	if (i == id->bNumEndpoints)
    101  1.3.2.2  skrll 		return UMATCH_NONE;
    102  1.3.2.2  skrll 
    103  1.3.2.2  skrll 	err = usbd_open_pipe(iface, ed->bEndpointAddress,
    104  1.3.2.2  skrll 	    USBD_EXCLUSIVE_USE, &pipe);
    105  1.3.2.2  skrll 	if (err != 0) {
    106  1.3.2.2  skrll 		aprint_error("%s: failed to open bulk transfer pipe %d\n",
    107  1.3.2.2  skrll 		    __func__, ed->bEndpointAddress);
    108  1.3.2.2  skrll 		return UMATCH_NONE;
    109  1.3.2.2  skrll 	}
    110  1.3.2.2  skrll 
    111  1.3.2.2  skrll 	int error = usbd_create_xfer(pipe, cmdlen, 0, 0, &xfer);
    112  1.3.2.2  skrll 	if (!error) {
    113  1.3.2.2  skrll 
    114  1.3.2.2  skrll 		usbd_setup_xfer(xfer, NULL, cmd, cmdlen,
    115  1.3.2.2  skrll 		    USBD_SYNCHRONOUS, USBD_DEFAULT_TIMEOUT, NULL);
    116  1.3.2.2  skrll 
    117  1.3.2.2  skrll 		err = usbd_transfer(xfer);
    118  1.3.2.2  skrll 
    119  1.3.2.2  skrll #if 0 /* XXXpooka: at least my huawei "fails" this always, but still detaches */
    120  1.3.2.2  skrll 		if (err)
    121  1.3.2.2  skrll 			aprint_error("%s: transfer failed\n", __func__);
    122  1.3.2.2  skrll #else
    123  1.3.2.2  skrll 		err = 0;
    124  1.3.2.2  skrll #endif
    125  1.3.2.2  skrll 		usbd_destroy_xfer(xfer);
    126  1.3.2.2  skrll 	} else {
    127  1.3.2.2  skrll 		aprint_error("%s: failed to allocate xfer\n", __func__);
    128  1.3.2.2  skrll 		err = USBD_NOMEM;
    129  1.3.2.2  skrll 	}
    130  1.3.2.2  skrll 
    131  1.3.2.2  skrll 	usbd_abort_pipe(pipe);
    132  1.3.2.2  skrll 	usbd_close_pipe(pipe);
    133  1.3.2.2  skrll 
    134  1.3.2.2  skrll 	return err == USBD_NORMAL_COMPLETION ? UMATCH_HIGHEST : UMATCH_NONE;
    135  1.3.2.2  skrll }
    136  1.3.2.2  skrll 
    137  1.3.2.2  skrll /* Byte 0..3: Command Block Wrapper (CBW) signature */
    138  1.3.2.2  skrll static void
    139  1.3.2.2  skrll set_cbw(unsigned char *cmd)
    140  1.3.2.2  skrll {
    141  1.3.2.2  skrll 	cmd[0] = 0x55;
    142  1.3.2.2  skrll 	cmd[1] = 0x53;
    143  1.3.2.2  skrll 	cmd[2] = 0x42;
    144  1.3.2.2  skrll 	cmd[3] = 0x43;
    145  1.3.2.2  skrll }
    146  1.3.2.2  skrll 
    147  1.3.2.2  skrll static int
    148  1.3.2.2  skrll u3g_bulk_scsi_eject(struct usbd_device *dev)
    149  1.3.2.2  skrll {
    150  1.3.2.2  skrll 	unsigned char cmd[31];
    151  1.3.2.2  skrll 
    152  1.3.2.2  skrll 	memset(cmd, 0, sizeof(cmd));
    153  1.3.2.2  skrll 	/* Byte 0..3: Command Block Wrapper (CBW) signature */
    154  1.3.2.2  skrll 	set_cbw(cmd);
    155  1.3.2.2  skrll 	/* 4..7: CBW Tag, has to unique, but only a single transfer used. */
    156  1.3.2.2  skrll 	cmd[4] = 0x01;
    157  1.3.2.2  skrll 	/* 8..11: CBW Transfer Length, no data here */
    158  1.3.2.2  skrll 	/* 12: CBW Flag: output, so 0 */
    159  1.3.2.2  skrll 	/* 13: CBW Lun: 0 */
    160  1.3.2.2  skrll 	/* 14: CBW Length */
    161  1.3.2.2  skrll 	cmd[14] = 0x06;
    162  1.3.2.2  skrll 
    163  1.3.2.2  skrll 	/* Rest is the SCSI payload */
    164  1.3.2.2  skrll 
    165  1.3.2.2  skrll 	/* 0: SCSI START/STOP opcode */
    166  1.3.2.2  skrll 	cmd[15] = 0x1b;
    167  1.3.2.2  skrll 	/* 1..3 unused */
    168  1.3.2.2  skrll 	/* 4 Load/Eject command */
    169  1.3.2.2  skrll 	cmd[19] = 0x02;
    170  1.3.2.2  skrll 	/* 5: unused */
    171  1.3.2.2  skrll 
    172  1.3.2.2  skrll 	return send_bulkmsg(dev, cmd, sizeof(cmd));
    173  1.3.2.2  skrll }
    174  1.3.2.2  skrll 
    175  1.3.2.2  skrll static int
    176  1.3.2.2  skrll u3g_bulk_ata_eject(struct usbd_device *dev)
    177  1.3.2.2  skrll {
    178  1.3.2.2  skrll 	unsigned char cmd[31];
    179  1.3.2.2  skrll 
    180  1.3.2.2  skrll 	memset(cmd, 0, sizeof(cmd));
    181  1.3.2.2  skrll 	/* Byte 0..3: Command Block Wrapper (CBW) signature */
    182  1.3.2.2  skrll 	set_cbw(cmd);
    183  1.3.2.2  skrll 	/* 4..7: CBW Tag, has to unique, but only a single transfer used. */
    184  1.3.2.2  skrll 	cmd[4] = 0x01;
    185  1.3.2.2  skrll 	/* 8..11: CBW Transfer Length, no data here */
    186  1.3.2.2  skrll 	/* 12: CBW Flag: output, so 0 */
    187  1.3.2.2  skrll 	/* 13: CBW Lun: 0 */
    188  1.3.2.2  skrll 	/* 14: CBW Length */
    189  1.3.2.2  skrll 	cmd[14] = 0x06;
    190  1.3.2.2  skrll 
    191  1.3.2.2  skrll 	/* Rest is the SCSI payload */
    192  1.3.2.2  skrll 
    193  1.3.2.2  skrll 	/* 0: ATA pass-through */
    194  1.3.2.2  skrll 	cmd[15] = 0x85;
    195  1.3.2.2  skrll 	/* 1..3 unused */
    196  1.3.2.2  skrll 	/* 4 XXX What is this command? */
    197  1.3.2.2  skrll 	cmd[19] = 0x24;
    198  1.3.2.2  skrll 	/* 5: unused */
    199  1.3.2.2  skrll 
    200  1.3.2.2  skrll 	return send_bulkmsg(dev, cmd, sizeof(cmd));
    201  1.3.2.2  skrll }
    202  1.3.2.2  skrll 
    203  1.3.2.2  skrll static int
    204  1.3.2.2  skrll u3g_huawei_reinit(struct usbd_device *dev)
    205  1.3.2.2  skrll {
    206  1.3.2.2  skrll 	/*
    207  1.3.2.2  skrll 	 * The Huawei device presents itself as a umass device with Windows
    208  1.3.2.2  skrll 	 * drivers on it. After installation of the driver, it reinits into a
    209  1.3.2.2  skrll 	 * 3G serial device.
    210  1.3.2.2  skrll 	 */
    211  1.3.2.2  skrll 	usb_device_request_t req;
    212  1.3.2.2  skrll 	usb_config_descriptor_t *cdesc;
    213  1.3.2.2  skrll 
    214  1.3.2.2  skrll 	/* Get the config descriptor */
    215  1.3.2.2  skrll 	cdesc = usbd_get_config_descriptor(dev);
    216  1.3.2.2  skrll 	if (cdesc == NULL) {
    217  1.3.2.2  skrll 		usb_device_descriptor_t dd;
    218  1.3.2.2  skrll 
    219  1.3.2.2  skrll 		if (usbd_get_device_desc(dev, &dd) != 0)
    220  1.3.2.2  skrll 			return UMATCH_NONE;
    221  1.3.2.2  skrll 
    222  1.3.2.2  skrll 		if (dd.bNumConfigurations != 1)
    223  1.3.2.2  skrll 			return UMATCH_NONE;
    224  1.3.2.2  skrll 
    225  1.3.2.2  skrll 		if (usbd_set_config_index(dev, 0, 1) != 0)
    226  1.3.2.2  skrll 			return UMATCH_NONE;
    227  1.3.2.2  skrll 
    228  1.3.2.2  skrll 		cdesc = usbd_get_config_descriptor(dev);
    229  1.3.2.2  skrll 
    230  1.3.2.2  skrll 		if (cdesc == NULL)
    231  1.3.2.2  skrll 			return UMATCH_NONE;
    232  1.3.2.2  skrll 	}
    233  1.3.2.2  skrll 
    234  1.3.2.2  skrll 	/*
    235  1.3.2.2  skrll 	 * One iface means umass mode, more than 1 (4 usually) means 3G mode.
    236  1.3.2.2  skrll 	 *
    237  1.3.2.2  skrll 	 * XXX: We should check the first interface's device class just to be
    238  1.3.2.2  skrll 	 * sure. If it's a mass storage device, then we can be fairly certain
    239  1.3.2.2  skrll 	 * it needs a mode-switch.
    240  1.3.2.2  skrll 	 */
    241  1.3.2.2  skrll 	if (cdesc->bNumInterface > 1)
    242  1.3.2.2  skrll 		return UMATCH_NONE;
    243  1.3.2.2  skrll 
    244  1.3.2.2  skrll 	req.bmRequestType = UT_WRITE_DEVICE;
    245  1.3.2.2  skrll 	req.bRequest = UR_SET_FEATURE;
    246  1.3.2.2  skrll 	USETW(req.wValue, UF_DEVICE_REMOTE_WAKEUP);
    247  1.3.2.2  skrll 	USETW(req.wIndex, UHF_PORT_SUSPEND);
    248  1.3.2.2  skrll 	USETW(req.wLength, 0);
    249  1.3.2.2  skrll 
    250  1.3.2.2  skrll 	(void) usbd_do_request(dev, &req, 0);
    251  1.3.2.2  skrll 
    252  1.3.2.2  skrll 	return UMATCH_HIGHEST; /* Prevent umass from attaching */
    253  1.3.2.2  skrll }
    254  1.3.2.2  skrll 
    255  1.3.2.2  skrll static int
    256  1.3.2.2  skrll u3g_huawei_k3765_reinit(struct usbd_device *dev)
    257  1.3.2.2  skrll {
    258  1.3.2.2  skrll 	unsigned char cmd[31];
    259  1.3.2.2  skrll 
    260  1.3.2.2  skrll 	/* magic string adapted from some webpage */
    261  1.3.2.2  skrll 	memset(cmd, 0, sizeof(cmd));
    262  1.3.2.2  skrll 	/* Byte 0..3: Command Block Wrapper (CBW) signature */
    263  1.3.2.2  skrll 	set_cbw(cmd);
    264  1.3.2.2  skrll 
    265  1.3.2.2  skrll 	cmd[15]= 0x11;
    266  1.3.2.2  skrll 	cmd[16]= 0x06;
    267  1.3.2.2  skrll 
    268  1.3.2.2  skrll 	return send_bulkmsg(dev, cmd, sizeof(cmd));
    269  1.3.2.2  skrll }
    270  1.3.2.2  skrll static int
    271  1.3.2.2  skrll u3g_huawei_e171_reinit(struct usbd_device *dev)
    272  1.3.2.2  skrll {
    273  1.3.2.2  skrll 	unsigned char cmd[31];
    274  1.3.2.2  skrll 
    275  1.3.2.2  skrll 	/* magic string adapted from some webpage */
    276  1.3.2.2  skrll 	memset(cmd, 0, sizeof(cmd));
    277  1.3.2.2  skrll 	/* Byte 0..3: Command Block Wrapper (CBW) signature */
    278  1.3.2.2  skrll 	set_cbw(cmd);
    279  1.3.2.2  skrll 
    280  1.3.2.2  skrll 	cmd[15]= 0x11;
    281  1.3.2.2  skrll 	cmd[16]= 0x06;
    282  1.3.2.2  skrll 	cmd[17]= 0x20;
    283  1.3.2.2  skrll 	cmd[20]= 0x01;
    284  1.3.2.2  skrll 
    285  1.3.2.2  skrll 	return send_bulkmsg(dev, cmd, sizeof(cmd));
    286  1.3.2.2  skrll }
    287  1.3.2.2  skrll 
    288  1.3.2.2  skrll static int
    289  1.3.2.2  skrll u3g_huawei_e353_reinit(struct usbd_device *dev)
    290  1.3.2.2  skrll {
    291  1.3.2.2  skrll 	unsigned char cmd[31];
    292  1.3.2.2  skrll 
    293  1.3.2.2  skrll 	/* magic string adapted from some webpage */
    294  1.3.2.2  skrll 	memset(cmd, 0, sizeof(cmd));
    295  1.3.2.2  skrll 	/* Byte 0..3: Command Block Wrapper (CBW) signature */
    296  1.3.2.2  skrll 	set_cbw(cmd);
    297  1.3.2.2  skrll 
    298  1.3.2.2  skrll 	cmd[4] = 0x7f;
    299  1.3.2.2  skrll 	cmd[9] = 0x02;
    300  1.3.2.2  skrll 	cmd[12] = 0x80;
    301  1.3.2.2  skrll 	cmd[14] = 0x0a;
    302  1.3.2.2  skrll 	cmd[15] = 0x11;
    303  1.3.2.2  skrll 	cmd[16] = 0x06;
    304  1.3.2.2  skrll 	cmd[17] = 0x20;
    305  1.3.2.2  skrll 	cmd[23] = 0x01;
    306  1.3.2.2  skrll 
    307  1.3.2.2  skrll 	return send_bulkmsg(dev, cmd, sizeof(cmd));
    308  1.3.2.2  skrll }
    309  1.3.2.2  skrll 
    310  1.3.2.2  skrll static int
    311  1.3.2.2  skrll u3g_sierra_reinit(struct usbd_device *dev)
    312  1.3.2.2  skrll {
    313  1.3.2.2  skrll 	/* Some Sierra devices presents themselves as a umass device with
    314  1.3.2.2  skrll 	 * Windows drivers on it. After installation of the driver, it
    315  1.3.2.2  skrll 	 * reinits into a * 3G serial device.
    316  1.3.2.2  skrll 	 */
    317  1.3.2.2  skrll 	usb_device_request_t req;
    318  1.3.2.2  skrll 
    319  1.3.2.2  skrll 	req.bmRequestType = UT_VENDOR;
    320  1.3.2.2  skrll 	req.bRequest = UR_SET_INTERFACE;
    321  1.3.2.2  skrll 	USETW(req.wValue, UF_DEVICE_REMOTE_WAKEUP);
    322  1.3.2.2  skrll 	USETW(req.wIndex, UHF_PORT_CONNECTION);
    323  1.3.2.2  skrll 	USETW(req.wLength, 0);
    324  1.3.2.2  skrll 
    325  1.3.2.2  skrll 	(void) usbd_do_request(dev, &req, 0);
    326  1.3.2.2  skrll 
    327  1.3.2.2  skrll 	return UMATCH_HIGHEST; /* Match to prevent umass from attaching */
    328  1.3.2.2  skrll }
    329  1.3.2.2  skrll 
    330  1.3.2.2  skrll static int
    331  1.3.2.2  skrll u3g_4gsystems_reinit(struct usbd_device *dev)
    332  1.3.2.2  skrll {
    333  1.3.2.2  skrll 	/* magic string adapted from usb_modeswitch database */
    334  1.3.2.2  skrll 	unsigned char cmd[31];
    335  1.3.2.2  skrll 
    336  1.3.2.2  skrll 	memset(cmd, 0, sizeof(cmd));
    337  1.3.2.2  skrll 	/* Byte 0..3: Command Block Wrapper (CBW) signature */
    338  1.3.2.2  skrll 	set_cbw(cmd);
    339  1.3.2.2  skrll 
    340  1.3.2.2  skrll 	cmd[4] = 0x12;
    341  1.3.2.2  skrll 	cmd[5] = 0x34;
    342  1.3.2.2  skrll 	cmd[6] = 0x56;
    343  1.3.2.2  skrll 	cmd[7] = 0x78;
    344  1.3.2.2  skrll 	cmd[8] = 0x80;
    345  1.3.2.2  skrll 	cmd[12] = 0x80;
    346  1.3.2.2  skrll 	cmd[14] = 0x06;
    347  1.3.2.2  skrll 	cmd[15] = 0x06;
    348  1.3.2.2  skrll 	cmd[16] = 0xf5;
    349  1.3.2.2  skrll 	cmd[17] = 0x04;
    350  1.3.2.2  skrll 	cmd[18] = 0x02;
    351  1.3.2.2  skrll 	cmd[19] = 0x52;
    352  1.3.2.2  skrll 	cmd[20] = 0x70;
    353  1.3.2.2  skrll 
    354  1.3.2.2  skrll 	return send_bulkmsg(dev, cmd, sizeof(cmd));
    355  1.3.2.2  skrll }
    356  1.3.2.2  skrll 
    357  1.3.2.2  skrll /*
    358  1.3.2.2  skrll  * First personality:
    359  1.3.2.2  skrll  *
    360  1.3.2.2  skrll  * Claim the entire device if a mode-switch is required.
    361  1.3.2.2  skrll  */
    362  1.3.2.2  skrll 
    363  1.3.2.2  skrll static int
    364  1.3.2.2  skrll umodeswitch_match(device_t parent, cfdata_t match, void *aux)
    365  1.3.2.2  skrll {
    366  1.3.2.2  skrll 	struct usb_attach_arg *uaa = aux;
    367  1.3.2.2  skrll 
    368  1.3.2.2  skrll 	/*
    369  1.3.2.2  skrll 	 * Huawei changes product when it is configured as a modem.
    370  1.3.2.2  skrll 	 */
    371  1.3.2.2  skrll 	switch (uaa->uaa_vendor) {
    372  1.3.2.2  skrll 	case USB_VENDOR_HUAWEI:
    373  1.3.2.2  skrll 		if (uaa->uaa_product == USB_PRODUCT_HUAWEI_K3765)
    374  1.3.2.2  skrll 			return UMATCH_NONE;
    375  1.3.2.2  skrll 
    376  1.3.2.2  skrll 		switch (uaa->uaa_product) {
    377  1.3.2.2  skrll 		case USB_PRODUCT_HUAWEI_E1750INIT:
    378  1.3.2.2  skrll 		case USB_PRODUCT_HUAWEI_K3765INIT:
    379  1.3.2.2  skrll 			return u3g_huawei_k3765_reinit(uaa->uaa_device);
    380  1.3.2.2  skrll 			break;
    381  1.3.2.2  skrll 		case USB_PRODUCT_HUAWEI_E171INIT:
    382  1.3.2.2  skrll 			return u3g_huawei_e171_reinit(uaa->uaa_device);
    383  1.3.2.2  skrll 			break;
    384  1.3.2.2  skrll 		case USB_PRODUCT_HUAWEI_E353INIT:
    385  1.3.2.2  skrll 			return u3g_huawei_e353_reinit(uaa->uaa_device);
    386  1.3.2.2  skrll 			break;
    387  1.3.2.2  skrll 		default:
    388  1.3.2.2  skrll 			return u3g_huawei_reinit(uaa->uaa_device);
    389  1.3.2.2  skrll 			break;
    390  1.3.2.2  skrll 		}
    391  1.3.2.2  skrll 		break;
    392  1.3.2.2  skrll 
    393  1.3.2.2  skrll 	case USB_VENDOR_NOVATEL2:
    394  1.3.2.2  skrll 		switch (uaa->uaa_product){
    395  1.3.2.2  skrll 		case USB_PRODUCT_NOVATEL2_MC950D_DRIVER:
    396  1.3.2.2  skrll 		case USB_PRODUCT_NOVATEL2_U760_DRIVER:
    397  1.3.2.2  skrll 			return u3g_bulk_scsi_eject(uaa->uaa_device);
    398  1.3.2.2  skrll 			break;
    399  1.3.2.2  skrll 		default:
    400  1.3.2.2  skrll 			break;
    401  1.3.2.2  skrll 		}
    402  1.3.2.2  skrll 		break;
    403  1.3.2.2  skrll 
    404  1.3.2.2  skrll 	case USB_VENDOR_QUALCOMM:
    405  1.3.2.2  skrll 		if (uaa->uaa_product == USB_PRODUCT_QUALCOMM_NTT_DOCOMO_L02C_STORAGE)
    406  1.3.2.2  skrll 			return u3g_bulk_scsi_eject(uaa->uaa_device);
    407  1.3.2.2  skrll 		break;
    408  1.3.2.2  skrll 
    409  1.3.2.2  skrll 	case USB_VENDOR_RALINK:
    410  1.3.2.2  skrll 		switch (uaa->uaa_product){
    411  1.3.2.2  skrll 		case USB_PRODUCT_RALINK_RT73:
    412  1.3.2.2  skrll 			return u3g_bulk_scsi_eject(uaa->uaa_device);
    413  1.3.2.2  skrll 			break;
    414  1.3.2.2  skrll 		}
    415  1.3.2.2  skrll 		break;
    416  1.3.2.2  skrll 
    417  1.3.2.2  skrll 	case USB_VENDOR_SIERRA:
    418  1.3.2.2  skrll 		if (uaa->uaa_product == USB_PRODUCT_SIERRA_INSTALLER)
    419  1.3.2.2  skrll 			return u3g_sierra_reinit(uaa->uaa_device);
    420  1.3.2.2  skrll 		break;
    421  1.3.2.2  skrll 
    422  1.3.2.2  skrll 	case USB_VENDOR_ZTE:
    423  1.3.2.2  skrll 		switch (uaa->uaa_product){
    424  1.3.2.2  skrll 		case USB_PRODUCT_ZTE_INSTALLER:
    425  1.3.2.2  skrll 		case USB_PRODUCT_ZTE_MF820D_INSTALLER:
    426  1.3.2.2  skrll 			(void)u3g_bulk_ata_eject(uaa->uaa_device);
    427  1.3.2.2  skrll 			(void)u3g_bulk_scsi_eject(uaa->uaa_device);
    428  1.3.2.2  skrll 			return UMATCH_HIGHEST;
    429  1.3.2.2  skrll 		default:
    430  1.3.2.2  skrll 			break;
    431  1.3.2.2  skrll 		}
    432  1.3.2.2  skrll 		break;
    433  1.3.2.2  skrll 
    434  1.3.2.2  skrll 	case USB_VENDOR_4GSYSTEMS:
    435  1.3.2.2  skrll 		if (uaa->uaa_product == USB_PRODUCT_4GSYSTEMS_XSSTICK_P14_INSTALLER)
    436  1.3.2.2  skrll 			return u3g_4gsystems_reinit(uaa->uaa_device);
    437  1.3.2.2  skrll 		break;
    438  1.3.2.2  skrll 
    439  1.3.2.2  skrll 	default:
    440  1.3.2.2  skrll 		break;
    441  1.3.2.2  skrll 	}
    442  1.3.2.2  skrll 
    443  1.3.2.2  skrll 	return UMATCH_NONE;
    444  1.3.2.2  skrll }
    445  1.3.2.2  skrll 
    446  1.3.2.2  skrll static void
    447  1.3.2.2  skrll umodeswitch_attach(device_t parent, device_t self, void *aux)
    448  1.3.2.2  skrll {
    449  1.3.2.2  skrll 	struct usb_attach_arg *uaa = aux;
    450  1.3.2.2  skrll 
    451  1.3.2.2  skrll 	aprint_naive("\n");
    452  1.3.2.2  skrll 	aprint_normal(": Switching off umass mode\n");
    453  1.3.2.2  skrll 
    454  1.3.2.2  skrll 	if (uaa->uaa_vendor == USB_VENDOR_NOVATEL2) {
    455  1.3.2.2  skrll 		switch (uaa->uaa_product) {
    456  1.3.2.2  skrll 	    	case USB_PRODUCT_NOVATEL2_MC950D_DRIVER:
    457  1.3.2.2  skrll 	    	case USB_PRODUCT_NOVATEL2_U760_DRIVER:
    458  1.3.2.2  skrll 			/* About to disappear... */
    459  1.3.2.2  skrll 			return;
    460  1.3.2.2  skrll 			break;
    461  1.3.2.2  skrll 		default:
    462  1.3.2.2  skrll 			break;
    463  1.3.2.2  skrll 		}
    464  1.3.2.2  skrll 	}
    465  1.3.2.2  skrll 
    466  1.3.2.2  skrll 	/* Move the device into the configured state. */
    467  1.3.2.2  skrll 	(void) usbd_set_config_index(uaa->uaa_device, 0, 1);
    468  1.3.2.2  skrll }
    469  1.3.2.2  skrll 
    470  1.3.2.2  skrll static int
    471  1.3.2.2  skrll umodeswitch_detach(device_t self, int flags)
    472  1.3.2.2  skrll {
    473  1.3.2.2  skrll 
    474  1.3.2.2  skrll 	return 0;
    475  1.3.2.2  skrll }
    476