Loading...
1/*
2 * drivers/usb/core/otg_whitelist.h
3 *
4 * Copyright (C) 2004 Texas Instruments
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 */
11
12/*
13 * This OTG Whitelist is the OTG "Targeted Peripheral List". It should
14 * mostly use of USB_DEVICE() or USB_DEVICE_VER() entries..
15 *
16 * YOU _SHOULD_ CHANGE THIS LIST TO MATCH YOUR PRODUCT AND ITS TESTING!
17 */
18
19static struct usb_device_id whitelist_table [] = {
20
21/* hubs are optional in OTG, but very handy ... */
22{ USB_DEVICE_INFO(USB_CLASS_HUB, 0, 0), },
23{ USB_DEVICE_INFO(USB_CLASS_HUB, 0, 1), },
24
25#ifdef CONFIG_USB_PRINTER /* ignoring nonstatic linkage! */
26/* FIXME actually, printers are NOT supposed to use device classes;
27 * they're supposed to use interface classes...
28 */
29{ USB_DEVICE_INFO(7, 1, 1) },
30{ USB_DEVICE_INFO(7, 1, 2) },
31{ USB_DEVICE_INFO(7, 1, 3) },
32#endif
33
34#ifdef CONFIG_USB_NET_CDCETHER
35/* Linux-USB CDC Ethernet gadget */
36{ USB_DEVICE(0x0525, 0xa4a1), },
37/* Linux-USB CDC Ethernet + RNDIS gadget */
38{ USB_DEVICE(0x0525, 0xa4a2), },
39#endif
40
41#if defined(CONFIG_USB_TEST) || defined(CONFIG_USB_TEST_MODULE)
42/* gadget zero, for testing */
43{ USB_DEVICE(0x0525, 0xa4a0), },
44#endif
45
46{ } /* Terminating entry */
47};
48
49static int is_targeted(struct usb_device *dev)
50{
51 struct usb_device_id *id = whitelist_table;
52
53 /* possible in developer configs only! */
54 if (!dev->bus->otg_port)
55 return 1;
56
57 /* HNP test device is _never_ targeted (see OTG spec 6.6.6) */
58 if ((le16_to_cpu(dev->descriptor.idVendor) == 0x1a0a &&
59 le16_to_cpu(dev->descriptor.idProduct) == 0xbadd))
60 return 0;
61
62 /* NOTE: can't use usb_match_id() since interface caches
63 * aren't set up yet. this is cut/paste from that code.
64 */
65 for (id = whitelist_table; id->match_flags; id++) {
66 if ((id->match_flags & USB_DEVICE_ID_MATCH_VENDOR) &&
67 id->idVendor != le16_to_cpu(dev->descriptor.idVendor))
68 continue;
69
70 if ((id->match_flags & USB_DEVICE_ID_MATCH_PRODUCT) &&
71 id->idProduct != le16_to_cpu(dev->descriptor.idProduct))
72 continue;
73
74 /* No need to test id->bcdDevice_lo != 0, since 0 is never
75 greater than any unsigned number. */
76 if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_LO) &&
77 (id->bcdDevice_lo > le16_to_cpu(dev->descriptor.bcdDevice)))
78 continue;
79
80 if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_HI) &&
81 (id->bcdDevice_hi < le16_to_cpu(dev->descriptor.bcdDevice)))
82 continue;
83
84 if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_CLASS) &&
85 (id->bDeviceClass != dev->descriptor.bDeviceClass))
86 continue;
87
88 if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_SUBCLASS) &&
89 (id->bDeviceSubClass != dev->descriptor.bDeviceSubClass))
90 continue;
91
92 if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_PROTOCOL) &&
93 (id->bDeviceProtocol != dev->descriptor.bDeviceProtocol))
94 continue;
95
96 return 1;
97 }
98
99 /* add other match criteria here ... */
100
101
102 /* OTG MESSAGE: report errors here, customize to match your product */
103 dev_err(&dev->dev, "device v%04x p%04x is not supported\n",
104 le16_to_cpu(dev->descriptor.idVendor),
105 le16_to_cpu(dev->descriptor.idProduct));
106#ifdef CONFIG_USB_OTG_WHITELIST
107 return 0;
108#else
109 return 1;
110#endif
111}
112
1// SPDX-License-Identifier: GPL-2.0+
2/*
3 * drivers/usb/core/otg_whitelist.h
4 *
5 * Copyright (C) 2004 Texas Instruments
6 */
7
8/*
9 * This OTG and Embedded Host Whitelist is "Targeted Peripheral List".
10 * It should mostly use of USB_DEVICE() or USB_DEVICE_VER() entries..
11 *
12 * YOU _SHOULD_ CHANGE THIS LIST TO MATCH YOUR PRODUCT AND ITS TESTING!
13 */
14
15static struct usb_device_id whitelist_table[] = {
16
17/* hubs are optional in OTG, but very handy ... */
18{ USB_DEVICE_INFO(USB_CLASS_HUB, 0, 0), },
19{ USB_DEVICE_INFO(USB_CLASS_HUB, 0, 1), },
20
21#ifdef CONFIG_USB_PRINTER /* ignoring nonstatic linkage! */
22/* FIXME actually, printers are NOT supposed to use device classes;
23 * they're supposed to use interface classes...
24 */
25{ USB_DEVICE_INFO(7, 1, 1) },
26{ USB_DEVICE_INFO(7, 1, 2) },
27{ USB_DEVICE_INFO(7, 1, 3) },
28#endif
29
30#ifdef CONFIG_USB_NET_CDCETHER
31/* Linux-USB CDC Ethernet gadget */
32{ USB_DEVICE(0x0525, 0xa4a1), },
33/* Linux-USB CDC Ethernet + RNDIS gadget */
34{ USB_DEVICE(0x0525, 0xa4a2), },
35#endif
36
37#if IS_ENABLED(CONFIG_USB_TEST)
38/* gadget zero, for testing */
39{ USB_DEVICE(0x0525, 0xa4a0), },
40#endif
41
42{ } /* Terminating entry */
43};
44
45static int is_targeted(struct usb_device *dev)
46{
47 struct usb_device_id *id = whitelist_table;
48
49 /* HNP test device is _never_ targeted (see OTG spec 6.6.6) */
50 if ((le16_to_cpu(dev->descriptor.idVendor) == 0x1a0a &&
51 le16_to_cpu(dev->descriptor.idProduct) == 0xbadd))
52 return 0;
53
54 /* OTG PET device is always targeted (see OTG 2.0 ECN 6.4.2) */
55 if ((le16_to_cpu(dev->descriptor.idVendor) == 0x1a0a &&
56 le16_to_cpu(dev->descriptor.idProduct) == 0x0200))
57 return 1;
58
59 /* NOTE: can't use usb_match_id() since interface caches
60 * aren't set up yet. this is cut/paste from that code.
61 */
62 for (id = whitelist_table; id->match_flags; id++) {
63 if ((id->match_flags & USB_DEVICE_ID_MATCH_VENDOR) &&
64 id->idVendor != le16_to_cpu(dev->descriptor.idVendor))
65 continue;
66
67 if ((id->match_flags & USB_DEVICE_ID_MATCH_PRODUCT) &&
68 id->idProduct != le16_to_cpu(dev->descriptor.idProduct))
69 continue;
70
71 /* No need to test id->bcdDevice_lo != 0, since 0 is never
72 greater than any unsigned number. */
73 if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_LO) &&
74 (id->bcdDevice_lo > le16_to_cpu(dev->descriptor.bcdDevice)))
75 continue;
76
77 if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_HI) &&
78 (id->bcdDevice_hi < le16_to_cpu(dev->descriptor.bcdDevice)))
79 continue;
80
81 if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_CLASS) &&
82 (id->bDeviceClass != dev->descriptor.bDeviceClass))
83 continue;
84
85 if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_SUBCLASS) &&
86 (id->bDeviceSubClass != dev->descriptor.bDeviceSubClass))
87 continue;
88
89 if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_PROTOCOL) &&
90 (id->bDeviceProtocol != dev->descriptor.bDeviceProtocol))
91 continue;
92
93 return 1;
94 }
95
96 /* add other match criteria here ... */
97
98
99 /* OTG MESSAGE: report errors here, customize to match your product */
100 dev_err(&dev->dev, "device v%04x p%04x is not supported\n",
101 le16_to_cpu(dev->descriptor.idVendor),
102 le16_to_cpu(dev->descriptor.idProduct));
103
104 return 0;
105}
106