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

          Line data    Source code
       1             : /*      $OpenBSD: usb_quirks.c,v 1.75 2018/07/10 09:46:18 jasper Exp $ */
       2             : /*      $NetBSD: usb_quirks.c,v 1.45 2003/05/10 17:47:14 hamajima Exp $ */
       3             : /*      $FreeBSD: src/sys/dev/usb/usb_quirks.c,v 1.30 2003/01/02 04:15:55 imp Exp $     */
       4             : 
       5             : /*
       6             :  * Copyright (c) 1998 The NetBSD Foundation, Inc.
       7             :  * All rights reserved.
       8             :  *
       9             :  * This code is derived from software contributed to The NetBSD Foundation
      10             :  * by Lennart Augustsson (lennart@augustsson.net) at
      11             :  * Carlstedt Research & Technology.
      12             :  *
      13             :  * Redistribution and use in source and binary forms, with or without
      14             :  * modification, are permitted provided that the following conditions
      15             :  * are met:
      16             :  * 1. Redistributions of source code must retain the above copyright
      17             :  *    notice, this list of conditions and the following disclaimer.
      18             :  * 2. Redistributions in binary form must reproduce the above copyright
      19             :  *    notice, this list of conditions and the following disclaimer in the
      20             :  *    documentation and/or other materials provided with the distribution.
      21             :  *
      22             :  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
      23             :  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
      24             :  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
      25             :  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
      26             :  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
      27             :  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
      28             :  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
      29             :  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
      30             :  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
      31             :  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
      32             :  * POSSIBILITY OF SUCH DAMAGE.
      33             :  */
      34             : 
      35             : #include <sys/param.h>
      36             : #include <sys/systm.h>
      37             : 
      38             : #include <dev/usb/usb.h>
      39             : 
      40             : #include <dev/usb/usbdevs.h>
      41             : #include <dev/usb/usb_quirks.h>
      42             : 
      43             : #ifdef USB_DEBUG
      44             : extern int usbdebug;
      45             : #endif
      46             : 
      47             : #define ANY 0xffff
      48             : 
      49             : const struct usbd_quirk_entry {
      50             :         u_int16_t idVendor;
      51             :         u_int16_t idProduct;
      52             :         u_int16_t bcdDevice;
      53             :         struct usbd_quirks quirks;
      54             : } usb_quirks[] = {
      55             :  { USB_VENDOR_KYE, USB_PRODUCT_KYE_NICHE,           0x100, { UQ_NO_SET_PROTO}},
      56             :  { USB_VENDOR_INSIDEOUT, USB_PRODUCT_INSIDEOUT_EDGEPORT4,
      57             :                                                     0x094, { UQ_SWAP_UNICODE}},
      58             :  { USB_VENDOR_QTRONIX, USB_PRODUCT_QTRONIX_980N,    0x110, { UQ_SPUR_BUT_UP }},
      59             :  { USB_VENDOR_ALCOR2, USB_PRODUCT_ALCOR2_KBD_HUB,   0x001, { UQ_SPUR_BUT_UP }},
      60             :  { USB_VENDOR_MCT, USB_PRODUCT_MCT_HUB0100,         0x102, { UQ_BUS_POWERED }},
      61             :  { USB_VENDOR_MCT, USB_PRODUCT_MCT_USB232,          0x102, { UQ_BUS_POWERED }},
      62             :  { USB_VENDOR_METRICOM, USB_PRODUCT_METRICOM_RICOCHET_GS,
      63             :         0x100, { UQ_ASSUME_CM_OVER_DATA }},
      64             :  { USB_VENDOR_SANYO, USB_PRODUCT_SANYO_SCP4900,
      65             :         0x000, { UQ_ASSUME_CM_OVER_DATA }},
      66             :  { USB_VENDOR_MOTOROLA2, USB_PRODUCT_MOTOROLA2_T720C,
      67             :         0x001, { UQ_ASSUME_CM_OVER_DATA }},
      68             :  { USB_VENDOR_EICON, USB_PRODUCT_EICON_DIVA852,
      69             :         0x100, { UQ_ASSUME_CM_OVER_DATA }},
      70             :  /* YAMAHA router's ucdDevice is the version of firmware and often changes. */
      71             :  { USB_VENDOR_YAMAHA, USB_PRODUCT_YAMAHA_RTA54I,
      72             :         ANY, { UQ_ASSUME_CM_OVER_DATA }},
      73             :  { USB_VENDOR_YAMAHA, USB_PRODUCT_YAMAHA_RTA55I,
      74             :         ANY, { UQ_ASSUME_CM_OVER_DATA }},
      75             :  { USB_VENDOR_YAMAHA, USB_PRODUCT_YAMAHA_RTW65B,
      76             :         ANY, { UQ_ASSUME_CM_OVER_DATA }},
      77             :  { USB_VENDOR_YAMAHA, USB_PRODUCT_YAMAHA_RTW65I,
      78             :         ANY, { UQ_ASSUME_CM_OVER_DATA }},
      79             :  { USB_VENDOR_QUALCOMM, USB_PRODUCT_QUALCOMM_MSM_MODEM,
      80             :         ANY, { UQ_ASSUME_CM_OVER_DATA }},
      81             :  { USB_VENDOR_QUALCOMM2, USB_PRODUCT_QUALCOMM2_MSM_PHONE,
      82             :         ANY, { UQ_ASSUME_CM_OVER_DATA }},
      83             :  { USB_VENDOR_SUNTAC, USB_PRODUCT_SUNTAC_AS64LX,
      84             :         0x100, { UQ_ASSUME_CM_OVER_DATA }},
      85             :  { USB_VENDOR_CMOTECH, USB_PRODUCT_CMOTECH_CM5100P,
      86             :         ANY, { UQ_ASSUME_CM_OVER_DATA }},
      87             :  { USB_VENDOR_CMOTECH, USB_PRODUCT_CMOTECH_CCU550,
      88             :         ANY, { UQ_ASSUME_CM_OVER_DATA }},
      89             :  { USB_VENDOR_CMOTECH, USB_PRODUCT_CMOTECH_CNU550pro,
      90             :         ANY, { UQ_ASSUME_CM_OVER_DATA }},
      91             :  { USB_VENDOR_SIEMENS2, USB_PRODUCT_SIEMENS2_ES75,
      92             :         ANY, { UQ_ASSUME_CM_OVER_DATA }},
      93             : 
      94             :  { USB_VENDOR_TI, USB_PRODUCT_TI_UTUSB41,           0x110, { UQ_POWER_CLAIM }},
      95             : 
      96             :  /* XXX These should have a revision number, but I don't know what they are. */
      97             :  { USB_VENDOR_HP, USB_PRODUCT_HP_895C,              ANY,   { UQ_BROKEN_BIDIR }},
      98             :  { USB_VENDOR_HP, USB_PRODUCT_HP_880C,              ANY,   { UQ_BROKEN_BIDIR }},
      99             :  { USB_VENDOR_HP, USB_PRODUCT_HP_815C,              ANY,   { UQ_BROKEN_BIDIR }},
     100             :  { USB_VENDOR_HP, USB_PRODUCT_HP_810C,              ANY,   { UQ_BROKEN_BIDIR }},
     101             :  { USB_VENDOR_HP, USB_PRODUCT_HP_830C,              ANY,   { UQ_BROKEN_BIDIR }},
     102             :  { USB_VENDOR_HP, USB_PRODUCT_HP_885C,              ANY,   { UQ_BROKEN_BIDIR }},
     103             :  { USB_VENDOR_HP, USB_PRODUCT_HP_840C,              ANY,   { UQ_BROKEN_BIDIR }},
     104             :  { USB_VENDOR_HP, USB_PRODUCT_HP_816C,              ANY,   { UQ_BROKEN_BIDIR }},
     105             :  { USB_VENDOR_HP, USB_PRODUCT_HP_959C,              ANY,   { UQ_BROKEN_BIDIR }},
     106             :  { USB_VENDOR_HP, USB_PRODUCT_HP_1220C,             ANY,   { UQ_BROKEN_BIDIR }},
     107             :  { USB_VENDOR_NEC, USB_PRODUCT_NEC_PICTY900,        ANY,   { UQ_BROKEN_BIDIR }},
     108             :  { USB_VENDOR_NEC, USB_PRODUCT_NEC_PICTY760,        ANY,   { UQ_BROKEN_BIDIR }},
     109             :  { USB_VENDOR_NEC, USB_PRODUCT_NEC_PICTY920,        ANY,   { UQ_BROKEN_BIDIR }},
     110             :  { USB_VENDOR_NEC, USB_PRODUCT_NEC_PICTY800,        ANY,   { UQ_BROKEN_BIDIR }},
     111             : 
     112             :  { USB_VENDOR_APPLE, USB_PRODUCT_APPLE_IPHONE,          ANY,    { UQ_BAD_HID }},
     113             :  { USB_VENDOR_APPLE, USB_PRODUCT_APPLE_IPHONE_3G,       ANY,    { UQ_BAD_HID }},
     114             :  { USB_VENDOR_APPLE, USB_PRODUCT_APPLE_IPHONE_3GS,      ANY,    { UQ_BAD_HID }},
     115             :  { USB_VENDOR_APPLE, USB_PRODUCT_APPLE_IPHONE_4_CDMA,   ANY,    { UQ_BAD_HID }},
     116             :  { USB_VENDOR_APPLE, USB_PRODUCT_APPLE_IPHONE_4_GSM,    ANY,    { UQ_BAD_HID }},
     117             :  { USB_VENDOR_APPLE, USB_PRODUCT_APPLE_IPHONE_4S,       ANY,    { UQ_BAD_HID }},
     118             :  { USB_VENDOR_APPLE, USB_PRODUCT_APPLE_IPHONE_6,        ANY,    { UQ_BAD_HID }},
     119             :  { USB_VENDOR_APPLE, USB_PRODUCT_APPLE_IPOD_TOUCH,      ANY,    { UQ_BAD_HID }},
     120             :  { USB_VENDOR_APPLE, USB_PRODUCT_APPLE_IPOD_TOUCH_2G,   ANY,    { UQ_BAD_HID }},
     121             :  { USB_VENDOR_APPLE, USB_PRODUCT_APPLE_IPOD_TOUCH_3G,   ANY,    { UQ_BAD_HID }},
     122             :  { USB_VENDOR_APPLE, USB_PRODUCT_APPLE_IPOD_TOUCH_4G,   ANY,    { UQ_BAD_HID }},
     123             :  { USB_VENDOR_APPLE, USB_PRODUCT_APPLE_IPAD,            ANY,    { UQ_BAD_HID }},
     124             :  { USB_VENDOR_APPLE, USB_PRODUCT_APPLE_IPAD2,           ANY,    { UQ_BAD_HID }},
     125             :  { USB_VENDOR_APPLE, USB_PRODUCT_APPLE_SPEAKERS,        ANY,    { UQ_BAD_HID }},
     126             :  { USB_VENDOR_CYPRESS, USB_PRODUCT_CYPRESS_SISPM_OLD,   ANY,    { UQ_BAD_HID }},
     127             :  { USB_VENDOR_CYPRESS, USB_PRODUCT_CYPRESS_SISPM,       ANY,    { UQ_BAD_HID }},
     128             :  { USB_VENDOR_CYPRESS, USB_PRODUCT_CYPRESS_SISPM_FLASH, ANY,    { UQ_BAD_HID }},
     129             :  { USB_VENDOR_MICROCHIP, USB_PRODUCT_MICROCHIP_USBLCD20x2,      ANY,    { UQ_BAD_HID }},
     130             :  { USB_VENDOR_MICROCHIP, USB_PRODUCT_MICROCHIP_USBLCD256x64,    ANY,    { UQ_BAD_HID }},
     131             :  { USB_VENDOR_MECANIQUE, USB_PRODUCT_MECANIQUE_WISPY,   ANY,    { UQ_BAD_HID }},
     132             :  { USB_VENDOR_METAGEEK, USB_PRODUCT_METAGEEK_WISPY24I,  ANY,    { UQ_BAD_HID }},
     133             :  { USB_VENDOR_MUSTEK2, USB_PRODUCT_MUSTEK2_PM800,       ANY,    { UQ_BAD_HID }},
     134             :  { USB_VENDOR_OMRON, USB_PRODUCT_OMRON_BX35F,           ANY,    { UQ_BAD_HID }},
     135             :  { USB_VENDOR_OMRON, USB_PRODUCT_OMRON_BX50F,           ANY,    { UQ_BAD_HID }},
     136             :  { USB_VENDOR_OMRON, USB_PRODUCT_OMRON_BY35S,           ANY,    { UQ_BAD_HID }},
     137             :  { USB_VENDOR_TENX, USB_PRODUCT_TENX_MISSILE,           ANY,    { UQ_BAD_HID }},
     138             :  { USB_VENDOR_TERRATEC, USB_PRODUCT_TERRATEC_AUREON,    ANY,    { UQ_BAD_HID }},
     139             :  { USB_VENDOR_TI, USB_PRODUCT_TI_MSP430,                ANY,    { UQ_BAD_HID }},
     140             :  { USB_VENDOR_VELLEMAN, USB_PRODUCT_VELLEMAN_K8055,     ANY,    { UQ_BAD_HID }},
     141             :  { USB_VENDOR_DREAMLINK, USB_PRODUCT_DREAMLINK_ULMB1,   ANY,    { UQ_BAD_HID }},
     142             : 
     143             :  { USB_VENDOR_HUAWEI, USB_PRODUCT_HUAWEI_E220,  ANY,    { UQ_NO_STRINGS }},
     144             :  { USB_VENDOR_SHANTOU, USB_PRODUCT_SHANTOU_DM9601, ANY, { UQ_NO_STRINGS }},
     145             :  { USB_VENDOR_RALINK, USB_PRODUCT_RALINK_RT2573, ANY,   { UQ_NO_STRINGS }},
     146             : 
     147             :  /* MS keyboards do weird things */
     148             :  { USB_VENDOR_MICROSOFT, USB_PRODUCT_MICROSOFT_WLNOTEBOOK,
     149             :         ANY, { UQ_MS_BAD_CLASS | UQ_MS_LEADING_BYTE }},
     150             :  { USB_VENDOR_MICROSOFT, USB_PRODUCT_MICROSOFT_WLNOTEBOOK2,
     151             :         ANY, { UQ_MS_BAD_CLASS | UQ_MS_LEADING_BYTE }},
     152             : 
     153             :  { 0, 0, 0, { 0 } }
     154             : };
     155             : 
     156             : #define bANY 0xff
     157             : const struct usbd_dev_quirk_entry {
     158             :         u_int8_t bDeviceClass;
     159             :         u_int8_t bDeviceSubClass;
     160             :         u_int8_t bDeviceProtocol;
     161             :         struct usbd_quirks quirks;
     162             : } usb_dev_quirks[] = {
     163             :  { 0, 0, 0, { 0 } }
     164             : };
     165             : 
     166             : const struct usbd_quirks usbd_no_quirk = { 0 };
     167             : 
     168             : const struct usbd_quirks *
     169           0 : usbd_find_quirk(usb_device_descriptor_t *d)
     170             : {
     171             :         const struct usbd_quirk_entry *t;
     172             :         const struct usbd_dev_quirk_entry *td;
     173           0 :         u_int16_t vendor = UGETW(d->idVendor);
     174           0 :         u_int16_t product = UGETW(d->idProduct);
     175           0 :         u_int16_t revision = UGETW(d->bcdDevice);
     176             : 
     177             :         /* search device specific quirks entry */
     178           0 :         for (t = usb_quirks; t->idVendor != 0; t++) {
     179           0 :                 if (t->idVendor  == vendor &&
     180           0 :                     t->idProduct == product &&
     181           0 :                     (t->bcdDevice == ANY || t->bcdDevice == revision)) {
     182             : #ifdef USB_DEBUG
     183             :                         if (usbdebug && t->quirks.uq_flags)
     184             :                                 printf("usbd_find_quirk for specific device 0x%04x/0x%04x/%x: %d\n",
     185             :                                         vendor, product, UGETW(d->bcdDevice),
     186             :                                         t->quirks.uq_flags);
     187             : #endif
     188             :         
     189           0 :                         return (&t->quirks);
     190             :                 }
     191             :         }
     192             :         /* no device specific quirks found, search class specific entry */
     193           0 :         for (td = usb_dev_quirks; td->bDeviceClass != 0; td++) {
     194           0 :                 if (td->bDeviceClass == d->bDeviceClass &&
     195           0 :                     (td->bDeviceSubClass == bANY ||
     196           0 :                      td->bDeviceSubClass == d->bDeviceSubClass) &&
     197           0 :                     (td->bDeviceProtocol == bANY ||
     198           0 :                      td->bDeviceProtocol == d->bDeviceProtocol)) {
     199             : #ifdef USB_DEBUG
     200             :                         if (usbdebug && td->quirks.uq_flags)
     201             :                                 printf("usbd_find_quirk for device class 0x%02x/0x%02x/%x: %d\n",
     202             :                                         d->bDeviceClass, d->bDeviceSubClass, 
     203             :                                         UGETW(d->bcdDevice),
     204             :                                         td->quirks.uq_flags);
     205             : #endif
     206           0 :                         return (&td->quirks);
     207             :                 }
     208             :         }
     209             : 
     210           0 :         return (&usbd_no_quirk);
     211           0 : }

Generated by: LCOV version 1.13