3 * Copyright (c) 2008 Hans Petter Selasky. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 #ifdef USB_GLOBAL_INCLUDE_FILE
28 #include USB_GLOBAL_INCLUDE_FILE
30 #include <sys/stdint.h>
31 #include <sys/stddef.h>
32 #include <sys/param.h>
33 #include <sys/queue.h>
34 #include <sys/types.h>
35 #include <sys/systm.h>
36 #include <sys/kernel.h>
38 #include <sys/module.h>
40 #include <sys/mutex.h>
41 #include <sys/condvar.h>
42 #include <sys/sysctl.h>
44 #include <sys/unistd.h>
45 #include <sys/callout.h>
46 #include <sys/malloc.h>
48 #include <sys/limits.h>
49 #include <sys/endian.h>
51 #include <dev/usb/usb.h>
52 #include <dev/usb/usbdi.h>
53 #endif /* USB_GLOBAL_INCLUDE_FILE */
55 /*------------------------------------------------------------------------*
56 * usbd_lookup_id_by_info
58 * This functions takes an array of "struct usb_device_id" and tries
59 * to match the entries with the information in "struct usbd_lookup_info".
61 * NOTE: The "sizeof_id" parameter must be a multiple of the
62 * usb_device_id structure size. Else the behaviour of this function
66 * NULL: No match found.
67 * Else: Pointer to matching entry.
68 *------------------------------------------------------------------------*/
69 const struct usb_device_id *
70 usbd_lookup_id_by_info(const struct usb_device_id *id, usb_size_t sizeof_id,
71 const struct usbd_lookup_info *info)
73 const struct usb_device_id *id_end;
78 id_end = (const void *)(((const uint8_t *)id) + sizeof_id);
81 * Keep on matching array entries until we find a match or
82 * until we reach the end of the matching array:
84 for (; id != id_end; id++) {
86 if ((id->match_flag_vendor) &&
87 (id->idVendor != info->idVendor)) {
90 if ((id->match_flag_product) &&
91 (id->idProduct != info->idProduct)) {
94 if ((id->match_flag_dev_lo) &&
95 (id->bcdDevice_lo > info->bcdDevice)) {
98 if ((id->match_flag_dev_hi) &&
99 (id->bcdDevice_hi < info->bcdDevice)) {
102 if ((id->match_flag_dev_class) &&
103 (id->bDeviceClass != info->bDeviceClass)) {
106 if ((id->match_flag_dev_subclass) &&
107 (id->bDeviceSubClass != info->bDeviceSubClass)) {
110 if ((id->match_flag_dev_protocol) &&
111 (id->bDeviceProtocol != info->bDeviceProtocol)) {
114 if ((id->match_flag_int_class) &&
115 (id->bInterfaceClass != info->bInterfaceClass)) {
118 if ((id->match_flag_int_subclass) &&
119 (id->bInterfaceSubClass != info->bInterfaceSubClass)) {
122 if ((id->match_flag_int_protocol) &&
123 (id->bInterfaceProtocol != info->bInterfaceProtocol)) {
126 /* We found a match! */
134 /*------------------------------------------------------------------------*
135 * usbd_lookup_id_by_uaa - factored out code
140 *------------------------------------------------------------------------*/
142 usbd_lookup_id_by_uaa(const struct usb_device_id *id, usb_size_t sizeof_id,
143 struct usb_attach_arg *uaa)
145 id = usbd_lookup_id_by_info(id, sizeof_id, &uaa->info);
147 /* copy driver info */
148 uaa->driver_info = id->driver_info;
154 /*------------------------------------------------------------------------*
155 * Export the USB device ID format we use to userspace tools.
156 *------------------------------------------------------------------------*/
157 #if BYTE_ORDER == LITTLE_ENDIAN
163 #if defined(KLD_MODULE) && (USB_HAVE_ID_SECTION != 0)
164 static const char __section("bus_autoconf_format") __used usb_id_format[] = {
166 /* Declare that three different sections use the same format */
169 "usb_device_id{256,:}"
172 /* List size of fields in the usb_device_id structure */
174 "mf_vendor{" U16_XOR ",1}"
175 "mf_product{" U16_XOR ",1}"
176 "mf_dev_lo{" U16_XOR ",1}"
177 "mf_dev_hi{" U16_XOR ",1}"
179 "mf_dev_class{" U16_XOR ",1}"
180 "mf_dev_subclass{" U16_XOR ",1}"
181 "mf_dev_protocol{" U16_XOR ",1}"
182 "mf_int_class{" U16_XOR ",1}"
184 "mf_int_subclass{" U16_XOR ",1}"
185 "mf_int_protocol{" U16_XOR ",1}"
186 "unused{" U16_XOR ",6}"
188 "idVendor[0]{" U16_XOR ",8}"
189 "idVendor[1]{" U16_XOR ",8}"
190 "idProduct[0]{" U16_XOR ",8}"
191 "idProduct[1]{" U16_XOR ",8}"
192 "bcdDevice_lo[0]{" U16_XOR ",8}"
193 "bcdDevice_lo[1]{" U16_XOR ",8}"
194 "bcdDevice_hi[0]{" U16_XOR ",8}"
195 "bcdDevice_hi[1]{" U16_XOR ",8}"
198 "bDeviceSubClass{0,8}"
199 "bDeviceProtocol{0,8}"
200 "bInterfaceClass{0,8}"
201 "bInterfaceSubClass{0,8}"
202 "bInterfaceProtocol{0,8}"
204 #if USB_HAVE_COMPAT_LINUX
205 "mfl_vendor{" U16_XOR ",1}"
206 "mfl_product{" U16_XOR ",1}"
207 "mfl_dev_lo{" U16_XOR ",1}"
208 "mfl_dev_hi{" U16_XOR ",1}"
210 "mfl_dev_class{" U16_XOR ",1}"
211 "mfl_dev_subclass{" U16_XOR ",1}"
212 "mfl_dev_protocol{" U16_XOR ",1}"
213 "mfl_int_class{" U16_XOR ",1}"
215 "mfl_int_subclass{" U16_XOR ",1}"
216 "mfl_int_protocol{" U16_XOR ",1}"
217 "unused{" U16_XOR ",6}"