LCOV - code coverage report
Current view: top level - dev/usb - umsm.c (source / functions) Hit Total Coverage
Test: 6.4 Lines: 0 262 0.0 %
Date: 2018-10-19 03:25:38 Functions: 0 11 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*      $OpenBSD: umsm.c,v 1.114 2018/08/15 14:13:07 mpi Exp $  */
       2             : 
       3             : /*
       4             :  * Copyright (c) 2008 Yojiro UO <yuo@nui.org>
       5             :  * Copyright (c) 2006 Jonathan Gray <jsg@openbsd.org>
       6             :  *
       7             :  * Permission to use, copy, modify, and distribute this software for any
       8             :  * purpose with or without fee is hereby granted, provided that the above
       9             :  * copyright notice and this permission notice appear in all copies.
      10             :  *
      11             :  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
      12             :  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
      13             :  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
      14             :  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
      15             :  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
      16             :  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
      17             :  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
      18             :  */
      19             : 
      20             : /* Driver for Qualcomm MSM EVDO and UMTS communication devices */
      21             : 
      22             : #include <sys/param.h>
      23             : #include <sys/systm.h>
      24             : #include <sys/kernel.h>
      25             : #include <sys/malloc.h>
      26             : #include <sys/device.h>
      27             : #include <sys/conf.h>
      28             : #include <sys/tty.h>
      29             : 
      30             : #include <dev/usb/usb.h>
      31             : #include <dev/usb/usbdi.h>
      32             : #include <dev/usb/usbdevs.h>
      33             : #include <dev/usb/ucomvar.h>
      34             : #include <dev/usb/usbcdc.h>
      35             : #include <dev/usb/umassvar.h>
      36             : #undef DPRINTF  /* undef DPRINTF for umass */
      37             : 
      38             : #ifdef UMSM_DEBUG
      39             : int     umsmdebug = 0;
      40             : #define DPRINTFN(n, x)  do { if (umsmdebug > (n)) printf x; } while (0)
      41             : #else
      42             : #define DPRINTFN(n, x)
      43             : #endif
      44             : 
      45             : #define DPRINTF(x) DPRINTFN(0, x)
      46             : 
      47             : #define UMSMBUFSZ       4096
      48             : #define UMSM_INTR_INTERVAL      100     /* ms */
      49             : #define E220_MODE_CHANGE_REQUEST 0x2
      50             : #define TRUINSTALL_CHANGEMODE_REQUEST 0x0b
      51             : 
      52             : int umsm_match(struct device *, void *, void *);
      53             : void umsm_attach(struct device *, struct device *, void *);
      54             : int umsm_detach(struct device *, int);
      55             : 
      56             : int umsm_open(void *, int);
      57             : void umsm_close(void *, int);
      58             : void umsm_intr(struct usbd_xfer *, void *, usbd_status);
      59             : void umsm_get_status(void *, int, u_char *, u_char *);
      60             : void umsm_set(void *, int, int, int);
      61             : 
      62             : struct umsm_softc {
      63             :         struct device            sc_dev;
      64             :         struct usbd_device      *sc_udev;
      65             :         struct usbd_interface   *sc_iface;
      66             :         int                      sc_iface_no;
      67             :         struct device           *sc_subdev;
      68             :         uint16_t                 sc_flag;
      69             : 
      70             :         /* interrupt ep */
      71             :         int                      sc_intr_number;
      72             :         struct usbd_pipe        *sc_intr_pipe;
      73             :         u_char                  *sc_intr_buf;
      74             :         int                      sc_isize;
      75             : 
      76             :         u_char                   sc_lsr;        /* Local status register */
      77             :         u_char                   sc_msr;        /* status register */
      78             :         u_char                   sc_dtr;        /* current DTR state */
      79             :         u_char                   sc_rts;        /* current RTS state */
      80             : };
      81             : 
      82             : usbd_status umsm_huawei_changemode(struct usbd_device *);
      83             : usbd_status umsm_truinstall_changemode(struct usbd_device *);
      84             : usbd_status umsm_umass_changemode(struct umsm_softc *);
      85             : 
      86             : struct ucom_methods umsm_methods = {
      87             :         umsm_get_status,
      88             :         umsm_set,
      89             :         NULL,
      90             :         NULL,
      91             :         umsm_open,
      92             :         umsm_close,
      93             :         NULL,
      94             :         NULL,
      95             : };
      96             : 
      97             : struct umsm_type {
      98             :         struct usb_devno        umsm_dev;
      99             :         uint16_t                umsm_flag;
     100             : /* device type */
     101             : #define DEV_NORMAL      0x0000
     102             : #define DEV_HUAWEI      0x0001
     103             : #define DEV_TRUINSTALL  0x0002
     104             : #define DEV_UMASS1      0x0010
     105             : #define DEV_UMASS2      0x0020
     106             : #define DEV_UMASS3      0x0040
     107             : #define DEV_UMASS4      0x0080
     108             : #define DEV_UMASS5      0x0100
     109             : #define DEV_UMASS6      0x0200
     110             : #define DEV_UMASS7      0x0400
     111             : #define DEV_UMASS8      0x1000
     112             : #define DEV_UMASS       (DEV_UMASS1 | DEV_UMASS2 | DEV_UMASS3 | DEV_UMASS4 | \
     113             :     DEV_UMASS5 | DEV_UMASS6 | DEV_UMASS7 | DEV_UMASS8)
     114             : };
     115             : 
     116             : static const struct umsm_type umsm_devs[] = {
     117             :         {{ USB_VENDOR_AIRPRIME, USB_PRODUCT_AIRPRIME_PC5220 }, 0},
     118             :         {{ USB_VENDOR_AIRPRIME, USB_PRODUCT_AIRPRIME_AIRCARD_313U }, 0},
     119             : 
     120             :         {{ USB_VENDOR_ANYDATA,  USB_PRODUCT_ANYDATA_A2502 }, 0},
     121             :         {{ USB_VENDOR_ANYDATA,  USB_PRODUCT_ANYDATA_ADU_500A }, 0},
     122             :         {{ USB_VENDOR_ANYDATA,  USB_PRODUCT_ANYDATA_ADU_E100H }, 0},
     123             : 
     124             :         {{ USB_VENDOR_DELL,     USB_PRODUCT_DELL_EU870D }, 0},
     125             :         {{ USB_VENDOR_DELL,     USB_PRODUCT_DELL_U740 }, 0},
     126             :         {{ USB_VENDOR_DELL,     USB_PRODUCT_DELL_W5500 }, 0},
     127             : 
     128             :         {{ USB_VENDOR_HUAWEI,   USB_PRODUCT_HUAWEI_E161 }, DEV_UMASS5},
     129             :         {{ USB_VENDOR_HUAWEI,   USB_PRODUCT_HUAWEI_E173S_INIT }, DEV_UMASS5},
     130             :         {{ USB_VENDOR_HUAWEI,   USB_PRODUCT_HUAWEI_E173S }, 0},
     131             :         {{ USB_VENDOR_HUAWEI,   USB_PRODUCT_HUAWEI_E180 }, DEV_HUAWEI},
     132             :         {{ USB_VENDOR_HUAWEI,   USB_PRODUCT_HUAWEI_E181 }, DEV_HUAWEI},
     133             :         {{ USB_VENDOR_HUAWEI,   USB_PRODUCT_HUAWEI_E182 }, DEV_UMASS5},
     134             :         {{ USB_VENDOR_HUAWEI,   USB_PRODUCT_HUAWEI_E1820 }, DEV_UMASS5},
     135             :         {{ USB_VENDOR_HUAWEI,   USB_PRODUCT_HUAWEI_E220 }, DEV_HUAWEI},
     136             :         {{ USB_VENDOR_HUAWEI,   USB_PRODUCT_HUAWEI_E303 }, DEV_UMASS5},
     137             :         {{ USB_VENDOR_HUAWEI,   USB_PRODUCT_HUAWEI_E353_INIT }, DEV_UMASS5},
     138             :         {{ USB_VENDOR_HUAWEI,   USB_PRODUCT_HUAWEI_E510 }, DEV_HUAWEI},
     139             :         {{ USB_VENDOR_HUAWEI,   USB_PRODUCT_HUAWEI_E618 }, DEV_HUAWEI},
     140             :         {{ USB_VENDOR_HUAWEI,   USB_PRODUCT_HUAWEI_E392_INIT }, DEV_UMASS5},
     141             :         {{ USB_VENDOR_HUAWEI,   USB_PRODUCT_HUAWEI_EM770W }, 0},
     142             :         {{ USB_VENDOR_HUAWEI,   USB_PRODUCT_HUAWEI_Mobile }, DEV_HUAWEI},
     143             :         {{ USB_VENDOR_HUAWEI,   USB_PRODUCT_HUAWEI_K3765_INIT }, DEV_UMASS5},
     144             :         {{ USB_VENDOR_HUAWEI,   USB_PRODUCT_HUAWEI_K3765 }, 0},
     145             :         {{ USB_VENDOR_HUAWEI,   USB_PRODUCT_HUAWEI_K3772_INIT }, DEV_UMASS5},
     146             :         {{ USB_VENDOR_HUAWEI,   USB_PRODUCT_HUAWEI_K3772 }, 0},
     147             :         {{ USB_VENDOR_HUAWEI,   USB_PRODUCT_HUAWEI_MU609 }, DEV_TRUINSTALL},
     148             :         {{ USB_VENDOR_HUAWEI,   USB_PRODUCT_HUAWEI_K4510 }, DEV_UMASS5},
     149             :         {{ USB_VENDOR_HUAWEI,   USB_PRODUCT_HUAWEI_K4511 }, DEV_UMASS5},
     150             :         {{ USB_VENDOR_HUAWEI,   USB_PRODUCT_HUAWEI_E1750 }, DEV_UMASS5},
     151             :         {{ USB_VENDOR_HUAWEI,   USB_PRODUCT_HUAWEI_E1752 }, 0},
     152             :         {{ USB_VENDOR_HUAWEI,   USB_PRODUCT_HUAWEI_E3372 }, DEV_UMASS5},
     153             : 
     154             :         {{ USB_VENDOR_HYUNDAI,  USB_PRODUCT_HYUNDAI_UM175 }, 0},
     155             : 
     156             :         {{ USB_VENDOR_LONGCHEER, USB_PRODUCT_LONGCHEER_D21LCMASS }, DEV_UMASS3},
     157             :         {{ USB_VENDOR_LONGCHEER, USB_PRODUCT_LONGCHEER_D21LC }, 0},
     158             :         {{ USB_VENDOR_LONGCHEER, USB_PRODUCT_LONGCHEER_510FUMASS }, DEV_UMASS3},
     159             :         {{ USB_VENDOR_LONGCHEER, USB_PRODUCT_LONGCHEER_510FU }, 0},
     160             : 
     161             :         {{ USB_VENDOR_KYOCERA2, USB_PRODUCT_KYOCERA2_KPC650 }, 0},
     162             : 
     163             :         {{ USB_VENDOR_MEDIATEK, USB_PRODUCT_MEDIATEK_UMASS }, DEV_UMASS8},
     164             :         {{ USB_VENDOR_MEDIATEK, USB_PRODUCT_MEDIATEK_DC_4COM }, 0},
     165             : 
     166             :         /* XXX Some qualcomm devices are missing */
     167             :         {{ USB_VENDOR_QUALCOMM, USB_PRODUCT_QUALCOMM_MSM_DRIVER }, DEV_UMASS1},
     168             :         {{ USB_VENDOR_QUALCOMM, USB_PRODUCT_QUALCOMM_MSM_DRIVER2 }, DEV_UMASS4},
     169             :         {{ USB_VENDOR_QUALCOMM, USB_PRODUCT_QUALCOMM_MSM_HSDPA }, 0},
     170             :         {{ USB_VENDOR_QUALCOMM, USB_PRODUCT_QUALCOMM_MSM_HSDPA2 }, 0},
     171             :         {{ USB_VENDOR_QUALCOMM, USB_PRODUCT_QUALCOMM_MSM_HSDPA3 }, 0},
     172             : 
     173             :         {{ USB_VENDOR_QUANTA2, USB_PRODUCT_QUANTA2_UMASS }, DEV_UMASS4},
     174             :         {{ USB_VENDOR_QUANTA2, USB_PRODUCT_QUANTA2_Q101 }, 0},
     175             : 
     176             :         {{ USB_VENDOR_ZTE, USB_PRODUCT_ZTE_AC2746 }, 0},
     177             :         {{ USB_VENDOR_ZTE, USB_PRODUCT_ZTE_UMASS_INSTALLER }, DEV_UMASS4},
     178             :         {{ USB_VENDOR_ZTE, USB_PRODUCT_ZTE_UMASS_INSTALLER2 }, DEV_UMASS6},
     179             :         {{ USB_VENDOR_ZTE, USB_PRODUCT_ZTE_UMASS_INSTALLER3 }, DEV_UMASS7},
     180             :         {{ USB_VENDOR_ZTE, USB_PRODUCT_ZTE_UMASS_INSTALLER4 }, DEV_UMASS4},
     181             :         {{ USB_VENDOR_ZTE, USB_PRODUCT_ZTE_K3565Z }, 0},
     182             :         {{ USB_VENDOR_ZTE, USB_PRODUCT_ZTE_MF112 }, DEV_UMASS4},
     183             :         {{ USB_VENDOR_ZTE, USB_PRODUCT_ZTE_MF633 }, 0},
     184             :         {{ USB_VENDOR_ZTE, USB_PRODUCT_ZTE_MF637 }, 0},
     185             :         {{ USB_VENDOR_ZTE, USB_PRODUCT_ZTE_MSA110UP }, 0},
     186             : 
     187             :         {{ USB_VENDOR_NOVATEL, USB_PRODUCT_NOVATEL_EXPRESSCARD }, 0},
     188             :         {{ USB_VENDOR_NOVATEL, USB_PRODUCT_NOVATEL_MERLINV620 }, 0},
     189             :         {{ USB_VENDOR_NOVATEL, USB_PRODUCT_NOVATEL_MERLINV740 }, 0},
     190             :         {{ USB_VENDOR_NOVATEL, USB_PRODUCT_NOVATEL_V720 }, 0},
     191             :         {{ USB_VENDOR_NOVATEL, USB_PRODUCT_NOVATEL_MERLINU740 }, 0},
     192             :         {{ USB_VENDOR_NOVATEL, USB_PRODUCT_NOVATEL_MERLINU740_2 }, 0},
     193             :         {{ USB_VENDOR_NOVATEL, USB_PRODUCT_NOVATEL_U870 }, 0},
     194             :         {{ USB_VENDOR_NOVATEL, USB_PRODUCT_NOVATEL_XU870 }, 0},
     195             :         {{ USB_VENDOR_NOVATEL, USB_PRODUCT_NOVATEL_EU870D }, 0},
     196             :         {{ USB_VENDOR_NOVATEL, USB_PRODUCT_NOVATEL_X950D }, 0},
     197             :         {{ USB_VENDOR_NOVATEL, USB_PRODUCT_NOVATEL_ES620 }, 0},
     198             :         {{ USB_VENDOR_NOVATEL, USB_PRODUCT_NOVATEL_U720 }, 0},
     199             :         {{ USB_VENDOR_NOVATEL, USB_PRODUCT_NOVATEL_U727 }, DEV_UMASS1},
     200             :         {{ USB_VENDOR_NOVATEL, USB_PRODUCT_NOVATEL_MC950D }, 0},
     201             :         {{ USB_VENDOR_NOVATEL, USB_PRODUCT_NOVATEL_MERLINX950D }, DEV_UMASS4},
     202             :         {{ USB_VENDOR_NOVATEL, USB_PRODUCT_NOVATEL_ZEROCD2 }, DEV_UMASS4},
     203             :         {{ USB_VENDOR_NOVATEL, USB_PRODUCT_NOVATEL_U760 }, DEV_UMASS4},
     204             :         {{ USB_VENDOR_NOVATEL, USB_PRODUCT_NOVATEL_MC760 }, 0},
     205             :         {{ USB_VENDOR_NOVATEL, USB_PRODUCT_NOVATEL_MC760CD }, DEV_UMASS4},
     206             : 
     207             :         {{ USB_VENDOR_NOVATEL1, USB_PRODUCT_NOVATEL1_FLEXPACKGPS }, 0},
     208             : 
     209             :         {{ USB_VENDOR_NOKIA2, USB_PRODUCT_NOKIA2_CS15UMASS }, DEV_UMASS4},
     210             :         {{ USB_VENDOR_NOKIA2, USB_PRODUCT_NOKIA2_CS15 }, 0},
     211             : 
     212             :         {{ USB_VENDOR_OPTION, USB_PRODUCT_OPTION_GT3GFUSION }, 0},
     213             :         {{ USB_VENDOR_OPTION, USB_PRODUCT_OPTION_GT3GPLUS }, 0},
     214             :         {{ USB_VENDOR_OPTION, USB_PRODUCT_OPTION_GT3GQUAD }, 0},
     215             :         {{ USB_VENDOR_OPTION, USB_PRODUCT_OPTION_GT3GQUADPLUS }, 0},
     216             :         {{ USB_VENDOR_OPTION, USB_PRODUCT_OPTION_GSICON72 }, DEV_UMASS1},
     217             :         {{ USB_VENDOR_OPTION, USB_PRODUCT_OPTION_GTHSUPA380E }, 0},
     218             :         {{ USB_VENDOR_OPTION, USB_PRODUCT_OPTION_GTMAX36 }, 0},
     219             :         {{ USB_VENDOR_OPTION, USB_PRODUCT_OPTION_ICON225 }, DEV_UMASS2},
     220             :         {{ USB_VENDOR_OPTION, USB_PRODUCT_OPTION_ICON505 }, DEV_UMASS1},
     221             :         {{ USB_VENDOR_OPTION, USB_PRODUCT_OPTION_SCORPION }, 0},
     222             :         {{ USB_VENDOR_OPTION, USB_PRODUCT_OPTION_VODAFONEMC3G }, 0},
     223             : 
     224             :         {{ USB_VENDOR_SIERRA, USB_PRODUCT_SIERRA_EM5625 }, 0},
     225             :         {{ USB_VENDOR_SIERRA, USB_PRODUCT_SIERRA_MC5720 }, 0},
     226             :         {{ USB_VENDOR_SIERRA, USB_PRODUCT_SIERRA_AIRCARD_595 }, 0},
     227             :         {{ USB_VENDOR_SIERRA, USB_PRODUCT_SIERRA_MC5725 }, 0},
     228             :         {{ USB_VENDOR_SIERRA, USB_PRODUCT_SIERRA_AC597E }, 0},
     229             :         {{ USB_VENDOR_SIERRA, USB_PRODUCT_SIERRA_C597 }, 0},
     230             :         {{ USB_VENDOR_SIERRA, USB_PRODUCT_SIERRA_AC595U }, 0},
     231             :         {{ USB_VENDOR_SIERRA, USB_PRODUCT_SIERRA_AIRCARD_580 }, 0},
     232             :         {{ USB_VENDOR_SIERRA, USB_PRODUCT_SIERRA_MC5720_2 }, 0},
     233             :         {{ USB_VENDOR_SIERRA, USB_PRODUCT_SIERRA_MC5725_2 }, 0},
     234             :         {{ USB_VENDOR_SIERRA, USB_PRODUCT_SIERRA_MC8755_2 }, 0},
     235             :         {{ USB_VENDOR_SIERRA, USB_PRODUCT_SIERRA_MC8765 }, 0},
     236             :         {{ USB_VENDOR_SIERRA, USB_PRODUCT_SIERRA_MC8755 }, 0},
     237             :         {{ USB_VENDOR_SIERRA, USB_PRODUCT_SIERRA_MC8775 }, 0},
     238             :         {{ USB_VENDOR_SIERRA, USB_PRODUCT_SIERRA_MC8755_3 }, 0},
     239             :         {{ USB_VENDOR_SIERRA, USB_PRODUCT_SIERRA_MC8775_2 }, 0},
     240             :         {{ USB_VENDOR_SIERRA, USB_PRODUCT_SIERRA_AIRCARD_875 }, 0},
     241             :         {{ USB_VENDOR_SIERRA, USB_PRODUCT_SIERRA_MC8780 }, 0},
     242             :         {{ USB_VENDOR_SIERRA, USB_PRODUCT_SIERRA_MC8781 }, 0},
     243             :         {{ USB_VENDOR_SIERRA, USB_PRODUCT_SIERRA_MC8790 }, 0},
     244             :         {{ USB_VENDOR_SIERRA, USB_PRODUCT_SIERRA_AC880 }, 0},
     245             :         {{ USB_VENDOR_SIERRA, USB_PRODUCT_SIERRA_AC881 }, 0},
     246             :         {{ USB_VENDOR_SIERRA, USB_PRODUCT_SIERRA_AC880E }, 0},
     247             :         {{ USB_VENDOR_SIERRA, USB_PRODUCT_SIERRA_AC881E }, 0},
     248             :         {{ USB_VENDOR_SIERRA, USB_PRODUCT_SIERRA_AC880U }, 0},
     249             :         {{ USB_VENDOR_SIERRA, USB_PRODUCT_SIERRA_AC881U }, 0},
     250             :         {{ USB_VENDOR_SIERRA, USB_PRODUCT_SIERRA_AC885U }, 0},
     251             :         {{ USB_VENDOR_SIERRA, USB_PRODUCT_SIERRA_C01SW }, 0},
     252             :         {{ USB_VENDOR_SIERRA, USB_PRODUCT_SIERRA_USB305}, 0},
     253             :         {{ USB_VENDOR_SIERRA, USB_PRODUCT_SIERRA_MC7304}, 0},
     254             :         {{ USB_VENDOR_SIERRA, USB_PRODUCT_SIERRA_TRUINSTALL }, DEV_TRUINSTALL},
     255             :         {{ USB_VENDOR_SIERRA, USB_PRODUCT_SIERRA_MC8355}, 0},
     256             :         {{ USB_VENDOR_SIERRA, USB_PRODUCT_SIERRA_AIRCARD_340U}, 0},
     257             :         {{ USB_VENDOR_SIERRA, USB_PRODUCT_SIERRA_AIRCARD_770S}, 0},
     258             :         {{ USB_VENDOR_SIERRA, USB_PRODUCT_SIERRA_MC7455}, 0},
     259             : 
     260             :         {{ USB_VENDOR_SIMCOM, USB_PRODUCT_SIMCOM_SIM7600E}, 0},
     261             : 
     262             :         {{ USB_VENDOR_TCTMOBILE, USB_PRODUCT_TCTMOBILE_UMASS }, DEV_UMASS3},
     263             :         {{ USB_VENDOR_TCTMOBILE, USB_PRODUCT_TCTMOBILE_UMASS_2 }, DEV_UMASS3},
     264             :         {{ USB_VENDOR_TCTMOBILE, USB_PRODUCT_TCTMOBILE_UMSM }, 0},
     265             :         {{ USB_VENDOR_TCTMOBILE, USB_PRODUCT_TCTMOBILE_UMSM_2 }, 0},
     266             :         {{ USB_VENDOR_TCTMOBILE, USB_PRODUCT_TCTMOBILE_UMSM_3 }, 0},
     267             : 
     268             :         {{ USB_VENDOR_TOSHIBA, USB_PRODUCT_TOSHIBA_HSDPA }, 0},
     269             : 
     270             :         {{ USB_VENDOR_HP, USB_PRODUCT_HP_HS2300 }, 0},
     271             : 
     272             :         {{ USB_VENDOR_CMOTECH, USB_PRODUCT_CMOTECH_CNU510 }, 0}, /* ??? */
     273             :         {{ USB_VENDOR_CMOTECH, USB_PRODUCT_CMOTECH_CCU550 }, 0}, /* ??? */
     274             :         {{ USB_VENDOR_CMOTECH, USB_PRODUCT_CMOTECH_CGU628 }, DEV_UMASS1},
     275             :         {{ USB_VENDOR_CMOTECH, USB_PRODUCT_CMOTECH_CGU628_DISK }, 0},
     276             :         {{ USB_VENDOR_CMOTECH, USB_PRODUCT_CMOTECH_CNU680 }, DEV_UMASS1},
     277             : };
     278             : 
     279             : #define umsm_lookup(v, p) ((const struct umsm_type *)usb_lookup(umsm_devs, v, p))
     280             : 
     281             : struct cfdriver umsm_cd = {
     282             :         NULL, "umsm", DV_DULL
     283             : };
     284             : 
     285             : const struct cfattach umsm_ca = {
     286             :         sizeof(struct umsm_softc), umsm_match, umsm_attach, umsm_detach
     287             : };
     288             : 
     289             : int
     290           0 : umsm_match(struct device *parent, void *match, void *aux)
     291             : {
     292           0 :         struct usb_attach_arg *uaa = aux;
     293             :         usb_interface_descriptor_t *id;
     294             :         uint16_t flag;
     295             : 
     296           0 :         if (uaa->iface == NULL)
     297           0 :                 return UMATCH_NONE;
     298             : 
     299             :         /*
     300             :          * Some devices (eg Huawei E220) have multiple interfaces and some
     301             :          * of them are of class umass. Don't claim ownership in such case.
     302             :          */
     303           0 :         if (umsm_lookup(uaa->vendor, uaa->product) != NULL) {
     304           0 :                 id = usbd_get_interface_descriptor(uaa->iface);
     305           0 :                 flag = umsm_lookup(uaa->vendor, uaa->product)->umsm_flag;
     306             : 
     307           0 :                 if (id == NULL || id->bInterfaceClass == UICLASS_MASS) {
     308             :                         /*
     309             :                          * Some high-speed modems require special care.
     310             :                          */
     311           0 :                         if (flag & DEV_HUAWEI) {
     312           0 :                                 if (uaa->ifaceno != 2)
     313           0 :                                         return UMATCH_VENDOR_IFACESUBCLASS;
     314             :                                 else
     315           0 :                                         return UMATCH_NONE;
     316           0 :                         } else if (flag & DEV_UMASS) {
     317           0 :                                 return UMATCH_VENDOR_IFACESUBCLASS;
     318           0 :                         } else if (flag & DEV_TRUINSTALL) {
     319           0 :                                 return UMATCH_VENDOR_IFACESUBCLASS;
     320             :                         } else
     321           0 :                                 return UMATCH_NONE;
     322             :                 /*
     323             :                  * Some devices have interfaces which fail to attach but in
     324             :                  * addition seem to make the remaining interfaces unusable. Only
     325             :                  * attach whitelisted interfaces in this case.
     326             :                  */
     327           0 :                 } else if ((uaa->vendor == USB_VENDOR_MEDIATEK &&
     328           0 :                             uaa->product == USB_PRODUCT_MEDIATEK_DC_4COM) &&
     329           0 :                            !(id->bInterfaceClass == UICLASS_VENDOR &&
     330           0 :                             ((id->bInterfaceSubClass == 0x02 &&
     331           0 :                               id->bInterfaceProtocol == 0x01) ||
     332           0 :                              (id->bInterfaceSubClass == 0x00 &&
     333           0 :                               id->bInterfaceProtocol == 0x00)))) {
     334           0 :                         return UMATCH_NONE;
     335             :                 } else
     336           0 :                         return UMATCH_VENDOR_IFACESUBCLASS;
     337             :         }
     338             : 
     339           0 :         return UMATCH_NONE;
     340           0 : }
     341             : 
     342             : void
     343           0 : umsm_attach(struct device *parent, struct device *self, void *aux)
     344             : {
     345           0 :         struct umsm_softc *sc = (struct umsm_softc *)self;
     346           0 :         struct usb_attach_arg *uaa = aux;
     347           0 :         struct ucom_attach_args uca;
     348             :         usb_interface_descriptor_t *id;
     349             :         usb_endpoint_descriptor_t *ed;
     350             :         int i;
     351             : 
     352           0 :         bzero(&uca, sizeof(uca));
     353           0 :         sc->sc_udev = uaa->device;
     354           0 :         sc->sc_iface = uaa->iface;
     355           0 :         sc->sc_flag  = umsm_lookup(uaa->vendor, uaa->product)->umsm_flag;
     356             : 
     357           0 :         id = usbd_get_interface_descriptor(sc->sc_iface);
     358             : 
     359             :         /*
     360             :          * Some 3G modems have multiple interfaces and some of them
     361             :          * are umass class. Don't claim ownership in such case.
     362             :          */
     363           0 :         if (id == NULL || id->bInterfaceClass == UICLASS_MASS) {
     364             :                 /*
     365             :                  * Some 3G modems require a special request to
     366             :                  * enable their modem function.
     367             :                  */
     368           0 :                 if ((sc->sc_flag & DEV_HUAWEI) && uaa->ifaceno == 0) {
     369           0 :                         umsm_huawei_changemode(uaa->device);
     370           0 :                         printf("%s: umass only mode. need to reattach\n",
     371           0 :                                 sc->sc_dev.dv_xname);
     372           0 :                 } else if (sc->sc_flag & DEV_TRUINSTALL) {
     373           0 :                         umsm_truinstall_changemode(uaa->device);
     374           0 :                         printf("%s: truinstall mode. need to reattach\n",
     375           0 :                                 sc->sc_dev.dv_xname);
     376           0 :                 } else if ((sc->sc_flag & DEV_UMASS) && uaa->ifaceno == 0) {
     377           0 :                         umsm_umass_changemode(sc);
     378           0 :                 }
     379             : 
     380             :                 /*
     381             :                  * The device will reset its own bus from the device side
     382             :                  * when its mode was changed, so just return.
     383             :                  */
     384           0 :                 return;
     385             :         }
     386             : 
     387           0 :         sc->sc_iface_no = id->bInterfaceNumber;
     388           0 :         uca.bulkin = uca.bulkout = -1;
     389           0 :         sc->sc_intr_number = sc->sc_isize = -1;
     390           0 :         for (i = 0; i < id->bNumEndpoints; i++) {
     391           0 :                 ed = usbd_interface2endpoint_descriptor(sc->sc_iface, i);
     392           0 :                 if (ed == NULL) {
     393           0 :                         printf("%s: no endpoint descriptor found for %d\n",
     394           0 :                             sc->sc_dev.dv_xname, i);
     395           0 :                         usbd_deactivate(sc->sc_udev);
     396           0 :                         return;
     397             :                 }
     398             : 
     399           0 :                 if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN &&
     400           0 :                     UE_GET_XFERTYPE(ed->bmAttributes) == UE_INTERRUPT) {
     401           0 :                         sc->sc_intr_number = ed->bEndpointAddress;
     402           0 :                         sc->sc_isize = UGETW(ed->wMaxPacketSize);
     403             :                         DPRINTF(("%s: find interrupt endpoint for %s\n",
     404             :                                 __func__, sc->sc_dev.dv_xname));
     405           0 :                 } else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN &&
     406           0 :                     UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK)
     407           0 :                         uca.bulkin = ed->bEndpointAddress;
     408           0 :                 else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_OUT &&
     409           0 :                     UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK)
     410           0 :                         uca.bulkout = ed->bEndpointAddress;
     411             :         }
     412           0 :         if (uca.bulkin == -1 || uca.bulkout == -1) {
     413           0 :                 printf("%s: missing endpoint\n", sc->sc_dev.dv_xname);
     414           0 :                 usbd_deactivate(sc->sc_udev);
     415           0 :                 return;
     416             :         }
     417             : 
     418           0 :         sc->sc_dtr = sc->sc_rts = -1;
     419             : 
     420             :         /* We need to force size as some devices lie */
     421           0 :         uca.ibufsize = UMSMBUFSZ;
     422           0 :         uca.obufsize = UMSMBUFSZ;
     423           0 :         uca.ibufsizepad = UMSMBUFSZ;
     424           0 :         uca.opkthdrlen = 0;
     425           0 :         uca.device = sc->sc_udev;
     426           0 :         uca.iface = sc->sc_iface;
     427           0 :         uca.methods = &umsm_methods;
     428           0 :         uca.arg = sc;
     429           0 :         uca.info = NULL;
     430           0 :         uca.portno = UCOM_UNK_PORTNO;
     431             : 
     432           0 :         sc->sc_subdev = config_found_sm(self, &uca, ucomprint, ucomsubmatch);
     433           0 : }
     434             : 
     435             : int
     436           0 : umsm_detach(struct device *self, int flags)
     437             : {
     438           0 :         struct umsm_softc *sc = (struct umsm_softc *)self;
     439             :         int rv = 0;
     440             : 
     441             :         /* close the interrupt endpoint if that is opened */
     442           0 :         if (sc->sc_intr_pipe != NULL) {
     443           0 :                 usbd_abort_pipe(sc->sc_intr_pipe);
     444           0 :                 usbd_close_pipe(sc->sc_intr_pipe);
     445           0 :                 free(sc->sc_intr_buf, M_USBDEV, sc->sc_isize);
     446           0 :                 sc->sc_intr_pipe = NULL;
     447           0 :         }
     448             : 
     449           0 :         usbd_deactivate(sc->sc_udev);
     450           0 :         if (sc->sc_subdev != NULL) {
     451           0 :                 rv = config_detach(sc->sc_subdev, flags);
     452           0 :                 sc->sc_subdev = NULL;
     453           0 :         }
     454             : 
     455           0 :         return (rv);
     456             : }
     457             : 
     458             : int
     459           0 : umsm_open(void *addr, int portno)
     460             : {
     461           0 :         struct umsm_softc *sc = addr;
     462             :         int err;
     463             : 
     464           0 :         if (usbd_is_dying(sc->sc_udev))
     465           0 :                 return (ENXIO);
     466             : 
     467           0 :         if (sc->sc_intr_number != -1 && sc->sc_intr_pipe == NULL) {
     468           0 :                 sc->sc_intr_buf = malloc(sc->sc_isize, M_USBDEV, M_WAITOK);
     469           0 :                 err = usbd_open_pipe_intr(sc->sc_iface,
     470           0 :                     sc->sc_intr_number,
     471             :                     USBD_SHORT_XFER_OK,
     472             :                     &sc->sc_intr_pipe,
     473             :                     sc,
     474             :                     sc->sc_intr_buf,
     475           0 :                     sc->sc_isize,
     476             :                     umsm_intr,
     477             :                     UMSM_INTR_INTERVAL);
     478           0 :                 if (err) {
     479           0 :                         printf("%s: cannot open interrupt pipe (addr %d)\n",
     480           0 :                             sc->sc_dev.dv_xname,
     481           0 :                             sc->sc_intr_number);
     482           0 :                         return (EIO);
     483             :                 }
     484             :         }
     485             : 
     486           0 :         return (0);
     487           0 : }
     488             : 
     489             : void
     490           0 : umsm_close(void *addr, int portno)
     491             : {
     492           0 :         struct umsm_softc *sc = addr;
     493             :         int err;
     494             : 
     495           0 :         if (usbd_is_dying(sc->sc_udev))
     496           0 :                 return;
     497             : 
     498           0 :         if (sc->sc_intr_pipe != NULL) {
     499           0 :                 usbd_abort_pipe(sc->sc_intr_pipe);
     500           0 :                 err = usbd_close_pipe(sc->sc_intr_pipe);
     501           0 :                 if (err)
     502           0 :                         printf("%s: close interrupt pipe failed: %s\n",
     503           0 :                             sc->sc_dev.dv_xname,
     504           0 :                             usbd_errstr(err));
     505           0 :                 free(sc->sc_intr_buf, M_USBDEV, sc->sc_isize);
     506           0 :                 sc->sc_intr_pipe = NULL;
     507           0 :         }
     508           0 : }
     509             : 
     510             : void
     511           0 : umsm_intr(struct usbd_xfer *xfer, void *priv,
     512             :         usbd_status status)
     513             : {
     514           0 :         struct umsm_softc *sc = priv;
     515             :         struct usb_cdc_notification *buf;
     516             :         u_char mstatus;
     517             : 
     518           0 :         buf = (struct usb_cdc_notification *)sc->sc_intr_buf;
     519           0 :         if (usbd_is_dying(sc->sc_udev))
     520           0 :                 return;
     521             : 
     522           0 :         if (status != USBD_NORMAL_COMPLETION) {
     523           0 :                 if (status == USBD_NOT_STARTED || status == USBD_CANCELLED)
     524           0 :                         return;
     525             : 
     526             :                 DPRINTF(("%s: umsm_intr: abnormal status: %s\n",
     527             :                     sc->sc_dev.dv_xname, usbd_errstr(status)));
     528           0 :                 usbd_clear_endpoint_stall_async(sc->sc_intr_pipe);
     529           0 :                 return;
     530             :         }
     531             : 
     532           0 :         if (buf->bmRequestType != UCDC_NOTIFICATION) {
     533             : #if 1 /* test */
     534           0 :                 printf("%s: this device is not using CDC notify message in intr pipe.\n"
     535             :                     "Please send your dmesg to <bugs@openbsd.org>, thanks.\n",
     536           0 :                     sc->sc_dev.dv_xname);
     537           0 :                 printf("%s: intr buffer 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x\n",
     538             :                     sc->sc_dev.dv_xname,
     539           0 :                     sc->sc_intr_buf[0], sc->sc_intr_buf[1],
     540           0 :                     sc->sc_intr_buf[2], sc->sc_intr_buf[3],
     541           0 :                     sc->sc_intr_buf[4], sc->sc_intr_buf[5],
     542           0 :                     sc->sc_intr_buf[6]);
     543             : #else
     544             :                 DPRINTF(("%s: umsm_intr: unknown message type(0x%02x)\n",
     545             :                     sc->sc_dev.dv_xname, buf->bmRequestType));
     546             : #endif
     547           0 :                 return;
     548             :         }
     549             : 
     550           0 :         if (buf->bNotification == UCDC_N_SERIAL_STATE) {
     551             :                 /* invalid message length, discard it */
     552           0 :                 if (UGETW(buf->wLength) != 2)
     553           0 :                         return;
     554             :                 /* XXX: sc_lsr is always 0 */
     555           0 :                 sc->sc_lsr = sc->sc_msr = 0;
     556           0 :                 mstatus = buf->data[0];
     557           0 :                 if (ISSET(mstatus, UCDC_N_SERIAL_RI))
     558           0 :                         sc->sc_msr |= UMSR_RI;
     559           0 :                 if (ISSET(mstatus, UCDC_N_SERIAL_DSR))
     560           0 :                         sc->sc_msr |= UMSR_DSR;
     561           0 :                 if (ISSET(mstatus, UCDC_N_SERIAL_DCD))
     562           0 :                         sc->sc_msr |= UMSR_DCD;
     563           0 :         } else if (buf->bNotification != UCDC_N_CONNECTION_SPEED_CHANGE) {
     564             :                 DPRINTF(("%s: umsm_intr: unknown notify message (0x%02x)\n",
     565             :                     sc->sc_dev.dv_xname, buf->bNotification));
     566           0 :                 return;
     567             :         }
     568             : 
     569           0 :         ucom_status_change((struct ucom_softc *)sc->sc_subdev);
     570           0 : }
     571             : 
     572             : void
     573           0 : umsm_get_status(void *addr, int portno, u_char *lsr, u_char *msr)
     574             : {
     575           0 :         struct umsm_softc *sc = addr;
     576             : 
     577           0 :         if (lsr != NULL)
     578           0 :                 *lsr = sc->sc_lsr;
     579           0 :         if (msr != NULL)
     580           0 :                 *msr = sc->sc_msr;
     581           0 : }
     582             : 
     583             : void
     584           0 : umsm_set(void *addr, int portno, int reg, int onoff)
     585             : {
     586           0 :         struct umsm_softc *sc = addr;
     587           0 :         usb_device_request_t req;
     588             :         int ls;
     589             : 
     590           0 :         switch (reg) {
     591             :         case UCOM_SET_DTR:
     592           0 :                 if (sc->sc_dtr == onoff)
     593           0 :                         return;
     594           0 :                 sc->sc_dtr = onoff;
     595           0 :                 break;
     596             :         case UCOM_SET_RTS:
     597           0 :                 if (sc->sc_rts == onoff)
     598           0 :                         return;
     599           0 :                 sc->sc_rts = onoff;
     600           0 :                 break;
     601             :         default:
     602           0 :                 return;
     603             :         }
     604             : 
     605             :         /* build a usb request */
     606           0 :         ls = (sc->sc_dtr ? UCDC_LINE_DTR : 0) |
     607           0 :              (sc->sc_rts ? UCDC_LINE_RTS : 0);
     608           0 :         req.bmRequestType = UT_WRITE_CLASS_INTERFACE;
     609           0 :         req.bRequest = UCDC_SET_CONTROL_LINE_STATE;
     610           0 :         USETW(req.wValue, ls);
     611           0 :         USETW(req.wIndex, sc->sc_iface_no);
     612           0 :         USETW(req.wLength, 0);
     613             : 
     614           0 :         (void)usbd_do_request(sc->sc_udev, &req, 0);
     615           0 : }
     616             : 
     617             : usbd_status
     618           0 : umsm_huawei_changemode(struct usbd_device *dev)
     619             : {
     620           0 :         usb_device_request_t req;
     621             :         usbd_status err;
     622             : 
     623           0 :         req.bmRequestType = UT_WRITE_DEVICE;
     624           0 :         req.bRequest = UR_SET_FEATURE;
     625           0 :         USETW(req.wValue, UF_DEVICE_REMOTE_WAKEUP);
     626           0 :         USETW(req.wIndex, E220_MODE_CHANGE_REQUEST);
     627           0 :         USETW(req.wLength, 0);
     628             : 
     629           0 :         err = usbd_do_request(dev, &req, 0);
     630           0 :         if (err)
     631           0 :                 return (EIO);
     632             : 
     633           0 :         return (0);
     634           0 : }
     635             : 
     636             : usbd_status
     637           0 : umsm_truinstall_changemode(struct usbd_device *dev)
     638             : {
     639           0 :         usb_device_request_t req;
     640             :         usbd_status err;
     641           0 :         req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
     642           0 :         req.bRequest = TRUINSTALL_CHANGEMODE_REQUEST;
     643           0 :         USETW(req.wValue, 0x1);
     644           0 :         USETW(req.wIndex, 0);
     645           0 :         USETW(req.wLength, 0);
     646             : 
     647           0 :         err = usbd_do_request(dev, &req, 0);
     648           0 :         if (err)
     649           0 :                 return (EIO);
     650             : 
     651           0 :         return (0);
     652           0 : }
     653             : 
     654             : usbd_status
     655           0 : umsm_umass_changemode(struct umsm_softc *sc)
     656             : {
     657             : #define UMASS_CMD_REZERO_UNIT           0x01
     658             : #define UMASS_CMD_START_STOP            0x1b
     659             : #define UMASS_CMDPARAM_EJECT            0x02
     660             : #define UMASS_SERVICE_ACTION_OUT        0x9f
     661             :         usb_interface_descriptor_t *id;
     662             :         usb_endpoint_descriptor_t *ed;
     663             :         struct usbd_xfer *xfer;
     664           0 :         struct usbd_pipe *cmdpipe;
     665             :         usbd_status err;
     666             :         u_int32_t n;
     667             :         void *bufp;
     668             :         int target_ep, i;
     669             : 
     670           0 :         struct umass_bbb_cbw cbw;
     671             :         static int dCBWTag = 0x12345678;
     672             : 
     673             :         USETDW(cbw.dCBWSignature, CBWSIGNATURE);
     674           0 :         USETDW(cbw.dCBWTag, dCBWTag);
     675             :         cbw.bCBWLUN   = 0;
     676             :         cbw.bCDBLength= 6;
     677           0 :         bzero(cbw.CBWCDB, sizeof(cbw.CBWCDB));
     678             : 
     679           0 :         switch (sc->sc_flag) {
     680             :         case DEV_UMASS1:
     681             :                 USETDW(cbw.dCBWDataTransferLength, 0x0);
     682             :                 cbw.bCBWFlags = CBWFLAGS_OUT;
     683             :                 cbw.CBWCDB[0] = UMASS_CMD_REZERO_UNIT;
     684             :                 cbw.CBWCDB[1] = 0x0;    /* target LUN: 0 */
     685           0 :                 break;
     686             :         case DEV_UMASS2:
     687             :                 USETDW(cbw.dCBWDataTransferLength, 0x1);
     688             :                 cbw.bCBWFlags = CBWFLAGS_IN;
     689             :                 cbw.CBWCDB[0] = UMASS_CMD_REZERO_UNIT;
     690             :                 cbw.CBWCDB[1] = 0x0;    /* target LUN: 0 */
     691           0 :                 break;
     692             :         case DEV_UMASS3: /* longcheer */
     693             :                 USETDW(cbw.dCBWDataTransferLength, 0x80);
     694             :                 cbw.bCBWFlags = CBWFLAGS_IN;
     695             :                 cbw.CBWCDB[0] = 0x06;
     696             :                 cbw.CBWCDB[1] = 0xf5;
     697             :                 cbw.CBWCDB[2] = 0x04;
     698             :                 cbw.CBWCDB[3] = 0x02;
     699             :                 cbw.CBWCDB[4] = 0x52;
     700             :                 cbw.CBWCDB[5] = 0x70;
     701           0 :                 break;
     702             :         case DEV_UMASS4:
     703             :                 USETDW(cbw.dCBWDataTransferLength, 0x0);
     704             :                 cbw.bCBWFlags = CBWFLAGS_OUT;
     705             :                 cbw.CBWCDB[0] = UMASS_CMD_START_STOP;
     706             :                 cbw.CBWCDB[1] = 0x00;   /* target LUN: 0 */
     707             :                 cbw.CBWCDB[4] = UMASS_CMDPARAM_EJECT;
     708           0 :                 break;
     709             :         case DEV_UMASS5:
     710             :                 cbw.bCBWFlags = CBWFLAGS_OUT;
     711             :                 cbw.CBWCDB[0] = 0x11;
     712             :                 cbw.CBWCDB[1] = 0x06;
     713           0 :                 break;
     714             :         case DEV_UMASS6:        /* ZTE */
     715             :                 USETDW(cbw.dCBWDataTransferLength, 0x20);
     716             :                 cbw.bCBWFlags = CBWFLAGS_IN;
     717             :                 cbw.bCDBLength= 12;
     718             :                 cbw.CBWCDB[0] = 0x85;
     719             :                 cbw.CBWCDB[1] = 0x01;
     720             :                 cbw.CBWCDB[2] = 0x01;
     721             :                 cbw.CBWCDB[3] = 0x01;
     722             :                 cbw.CBWCDB[4] = 0x18;
     723             :                 cbw.CBWCDB[5] = 0x01;
     724             :                 cbw.CBWCDB[6] = 0x01;
     725             :                 cbw.CBWCDB[7] = 0x01;
     726             :                 cbw.CBWCDB[8] = 0x01;
     727             :                 cbw.CBWCDB[9] = 0x01;
     728           0 :                 break;
     729             :         case DEV_UMASS7:        /* ZTE */
     730             :                 USETDW(cbw.dCBWDataTransferLength, 0xc0);
     731             :                 cbw.bCBWFlags = CBWFLAGS_IN;
     732             :                 cbw.CBWCDB[0] = UMASS_SERVICE_ACTION_OUT;
     733             :                 cbw.CBWCDB[1] = 0x03;
     734           0 :                 break;
     735             :         case DEV_UMASS8:
     736             :                 USETDW(cbw.dCBWDataTransferLength, 0x0);
     737             :                 cbw.bCBWFlags = CBWFLAGS_OUT;
     738             :                 cbw.CBWCDB[0] = 0xf0;
     739             :                 cbw.CBWCDB[1] = 0x01;
     740             :                 cbw.CBWCDB[2] = 0x03;
     741           0 :                 break;
     742             :         default:
     743             :                 DPRINTF(("%s: unknown device type.\n", sc->sc_dev.dv_xname));
     744             :                 break;
     745             :         }
     746             : 
     747             :         /* get command endpoint address */
     748           0 :         id = usbd_get_interface_descriptor(sc->sc_iface);
     749           0 :         for (i = 0; i < id->bNumEndpoints; i++) {
     750           0 :                 ed = usbd_interface2endpoint_descriptor(sc->sc_iface, i);
     751           0 :                 if (ed == NULL) {
     752           0 :                         return (USBD_IOERROR);
     753             :                 }
     754             : 
     755           0 :                 if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_OUT &&
     756           0 :                     UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK)
     757           0 :                         target_ep = ed->bEndpointAddress;
     758             :         }
     759             : 
     760             :         /* open command endppoint */
     761           0 :         err = usbd_open_pipe(sc->sc_iface, target_ep,
     762             :                 USBD_EXCLUSIVE_USE, &cmdpipe);
     763           0 :         if (err) {
     764             :                 DPRINTF(("%s: open pipe for modem change cmd failed: %s\n",
     765             :                     sc->sc_dev.dv_xname, usbd_errstr(err)));
     766           0 :                 return (err);
     767             :         }
     768             : 
     769           0 :         xfer = usbd_alloc_xfer(sc->sc_udev);
     770           0 :         if (xfer == NULL) {
     771           0 :                 usbd_close_pipe(cmdpipe);
     772           0 :                 return (USBD_NOMEM);
     773             :         } else {
     774           0 :                 bufp = usbd_alloc_buffer(xfer, UMASS_BBB_CBW_SIZE);
     775           0 :                 if (bufp == NULL)
     776           0 :                         err = USBD_NOMEM;
     777             :                 else {
     778             :                         n = UMASS_BBB_CBW_SIZE;
     779           0 :                         memcpy(bufp, &cbw, UMASS_BBB_CBW_SIZE);
     780           0 :                         usbd_setup_xfer(xfer, cmdpipe, 0, bufp, n,
     781             :                             USBD_NO_COPY | USBD_SYNCHRONOUS, 0, NULL);
     782           0 :                         err = usbd_transfer(xfer);
     783           0 :                         if (err) {
     784           0 :                                 usbd_clear_endpoint_stall(cmdpipe);
     785             :                                 DPRINTF(("%s: send error:%s", __func__,
     786             :                                     usbd_errstr(err)));
     787           0 :                         }
     788             :                 }
     789           0 :                 usbd_close_pipe(cmdpipe);
     790           0 :                 usbd_free_buffer(xfer);
     791           0 :                 usbd_free_xfer(xfer);
     792             :         }
     793             : 
     794           0 :         return (err);
     795           0 : }

Generated by: LCOV version 1.13