1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Driver for USB Mass Storage devices
4  * Usual Tables File for usb-storage and libusual
5  *
6  * Copyright (C) 2009 Alan Stern (stern@rowland.harvard.edu)
7  *
8  * Please see http://www.one-eyed-alien.net/~mdharm/linux-usb for more
9  * information about this driver.
10  */
11 
12 #include <linux/kernel.h>
13 #include <linux/module.h>
14 #include <linux/usb.h>
15 #include <linux/usb_usual.h>
16 
17 
18 /*
19  * The table of devices
20  */
21 #define UNUSUAL_DEV(id_vendor, id_product, bcdDeviceMin, bcdDeviceMax, \
22 		    vendorName, productName, useProtocol, useTransport, \
23 		    initFunction, flags) \
24 { USB_DEVICE_VER(id_vendor, id_product, bcdDeviceMin, bcdDeviceMax), \
25   .driver_info = (flags) }
26 
27 #define COMPLIANT_DEV	UNUSUAL_DEV
28 
29 #define USUAL_DEV(useProto, useTrans) \
30 { USB_INTERFACE_INFO(USB_CLASS_MASS_STORAGE, useProto, useTrans) }
31 
32 /* Define the device is matched with Vendor ID and interface descriptors */
33 #define UNUSUAL_VENDOR_INTF(id_vendor, cl, sc, pr, \
34 			vendorName, productName, useProtocol, useTransport, \
35 			initFunction, flags) \
36 { \
37 	.match_flags = USB_DEVICE_ID_MATCH_INT_INFO \
38 				| USB_DEVICE_ID_MATCH_VENDOR, \
39 	.idVendor    = (id_vendor), \
40 	.bInterfaceClass = (cl), \
41 	.bInterfaceSubClass = (sc), \
42 	.bInterfaceProtocol = (pr), \
43 	.driver_info = (flags) \
44 }
45 
46 struct usb_device_id usb_storage_usb_ids[] = {
47 #	include "unusual_devs.h"
48 	{ }		/* Terminating entry */
49 };
50 MODULE_DEVICE_TABLE(usb, usb_storage_usb_ids);
51 
52 #undef UNUSUAL_DEV
53 #undef COMPLIANT_DEV
54 #undef USUAL_DEV
55 #undef UNUSUAL_VENDOR_INTF
56 
57 /*
58  * The table of devices to ignore
59  */
60 struct ignore_entry {
61 	u16	vid, pid, bcdmin, bcdmax;
62 };
63 
64 #define UNUSUAL_DEV(id_vendor, id_product, bcdDeviceMin, bcdDeviceMax, \
65 		    vendorName, productName, useProtocol, useTransport, \
66 		    initFunction, flags) \
67 {					\
68 	.vid	= id_vendor,		\
69 	.pid 	= id_product,		\
70 	.bcdmin	= bcdDeviceMin,		\
71 	.bcdmax = bcdDeviceMax,		\
72 }
73 
74 static struct ignore_entry ignore_ids[] = {
75 #	include "unusual_alauda.h"
76 #	include "unusual_cypress.h"
77 #	include "unusual_datafab.h"
78 #	include "unusual_ene_ub6250.h"
79 #	include "unusual_freecom.h"
80 #	include "unusual_isd200.h"
81 #	include "unusual_jumpshot.h"
82 #	include "unusual_karma.h"
83 #	include "unusual_onetouch.h"
84 #	include "unusual_realtek.h"
85 #	include "unusual_sddr09.h"
86 #	include "unusual_sddr55.h"
87 #	include "unusual_usbat.h"
88 	{ }		/* Terminating entry */
89 };
90 
91 #undef UNUSUAL_DEV
92 
93 /* Return an error if a device is in the ignore_ids list */
94 int usb_usual_ignore_device(struct usb_interface *intf)
95 {
96 	struct usb_device *udev;
97 	unsigned vid, pid, bcd;
98 	struct ignore_entry *p;
99 
100 	udev = interface_to_usbdev(intf);
101 	vid = le16_to_cpu(udev->descriptor.idVendor);
102 	pid = le16_to_cpu(udev->descriptor.idProduct);
103 	bcd = le16_to_cpu(udev->descriptor.bcdDevice);
104 
105 	for (p = ignore_ids; p->vid; ++p) {
106 		if (p->vid == vid && p->pid == pid &&
107 				p->bcdmin <= bcd && p->bcdmax >= bcd)
108 			return -ENXIO;
109 	}
110 	return 0;
111 }
112