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 #include <sys/stdint.h>
28 #include <sys/stddef.h>
29 #include <sys/param.h>
30 #include <sys/queue.h>
31 #include <sys/types.h>
32 #include <sys/systm.h>
33 #include <sys/kernel.h>
35 #include <sys/linker_set.h>
36 #include <sys/module.h>
38 #include <sys/mutex.h>
39 #include <sys/condvar.h>
40 #include <sys/sysctl.h>
42 #include <sys/unistd.h>
43 #include <sys/callout.h>
44 #include <sys/malloc.h>
47 #include <dev/usb/usb.h>
48 #include <dev/usb/usbdi.h>
50 /*------------------------------------------------------------------------*
51 * usbd_lookup_id_by_info
53 * This functions takes an array of "struct usb_device_id" and tries
54 * to match the entries with the information in "struct usbd_lookup_info".
56 * NOTE: The "sizeof_id" parameter must be a multiple of the
57 * usb_device_id structure size. Else the behaviour of this function
61 * NULL: No match found.
62 * Else: Pointer to matching entry.
63 *------------------------------------------------------------------------*/
64 const struct usb_device_id *
65 usbd_lookup_id_by_info(const struct usb_device_id *id, usb_size_t sizeof_id,
66 const struct usbd_lookup_info *info)
68 const struct usb_device_id *id_end;
73 id_end = (const void *)(((const uint8_t *)id) + sizeof_id);
76 * Keep on matching array entries until we find a match or
77 * until we reach the end of the matching array:
79 for (; id != id_end; id++) {
81 if ((id->match_flag_vendor) &&
82 (id->idVendor != info->idVendor)) {
85 if ((id->match_flag_product) &&
86 (id->idProduct != info->idProduct)) {
89 if ((id->match_flag_dev_lo) &&
90 (id->bcdDevice_lo > info->bcdDevice)) {
93 if ((id->match_flag_dev_hi) &&
94 (id->bcdDevice_hi < info->bcdDevice)) {
97 if ((id->match_flag_dev_class) &&
98 (id->bDeviceClass != info->bDeviceClass)) {
101 if ((id->match_flag_dev_subclass) &&
102 (id->bDeviceSubClass != info->bDeviceSubClass)) {
105 if ((id->match_flag_dev_protocol) &&
106 (id->bDeviceProtocol != info->bDeviceProtocol)) {
109 if ((info->bDeviceClass == 0xFF) &&
110 (!(id->match_flag_vendor)) &&
111 ((id->match_flag_int_class) ||
112 (id->match_flag_int_subclass) ||
113 (id->match_flag_int_protocol))) {
116 if ((id->match_flag_int_class) &&
117 (id->bInterfaceClass != info->bInterfaceClass)) {
120 if ((id->match_flag_int_subclass) &&
121 (id->bInterfaceSubClass != info->bInterfaceSubClass)) {
124 if ((id->match_flag_int_protocol) &&
125 (id->bInterfaceProtocol != info->bInterfaceProtocol)) {
128 /* We found a match! */
136 /*------------------------------------------------------------------------*
137 * usbd_lookup_id_by_uaa - factored out code
142 *------------------------------------------------------------------------*/
144 usbd_lookup_id_by_uaa(const struct usb_device_id *id, usb_size_t sizeof_id,
145 struct usb_attach_arg *uaa)
147 id = usbd_lookup_id_by_info(id, sizeof_id, &uaa->info);
149 /* copy driver info */
150 uaa->driver_info = id->driver_info;