summaryrefslogtreecommitdiff
path: root/sysutils/usbutil/patches/patch-ab
blob: 7c4bfd266630e5c02de76d7d8e9601da6e4c250c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
$NetBSD: patch-ab,v 1.4 2010/12/25 14:03:57 jmcneill Exp $

--- usbctl.c.orig	2002-02-25 00:50:55.000000000 +0000
+++ usbctl.c
@@ -27,12 +27,18 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <sys/types.h>
+#include <sys/ioctl.h>
 #include <fcntl.h>
 #include <unistd.h>
 #include <err.h>
 #include <errno.h>
+#ifdef __DragonFly__
+#include <bus/usb/usb.h>
+#include <bus/usb/usbhid.h>
+#else
 #include <dev/usb/usb.h>
 #include <dev/usb/usbhid.h>
+#endif
 
 #ifndef USB_STACK_VERSION
 #define ucr_addr addr
@@ -52,6 +58,21 @@
 #define UICLASS_HUB UCLASS_HUB
 #endif
 
+#ifndef UDESC_INTERFACE_ASSOC
+#define UDESC_INTERFACE_ASSOC 0x0b
+typedef struct {
+	uByte		bLength;
+	uByte		bDescriptorType;
+	uByte		bFirstInterface;
+	uByte		bInterfaceCount;
+	uByte		bFunctionClass;
+	uByte		bFunctionSubClass;
+	uByte		bFunctionProtocol;
+	uByte		iFunction
+} UPACKED usb_interface_assoc_descriptor_t;
+#define USB_INTERFACE_ASSOC_DESCRIPTOR_SIZE 8
+#endif
+
 #define USBDEV "/dev/usb0"
 
 /* Backwards compatibility */
@@ -62,6 +83,7 @@
 #endif
 
 #define NSTRINGS
+#define STRINGLANG
 
 int num = 0;
 
@@ -80,17 +102,43 @@ getstring(int si, char *s)
 	int r, i, n;
 	u_int16_t c;
 	usb_string_descriptor_t us;
+	int lang = 0;
 
 	if (si == 0 || num) {
 		*s = 0;
 		return;
 	}
+
+#ifdef STRINGLANG
 	req.ucr_addr = usbaddr;
 	req.ucr_request.bmRequestType = UT_READ_DEVICE;
 	req.ucr_request.bRequest = UR_GET_DESCRIPTOR;
 	req.ucr_data = &us;
-	USETW2(req.ucr_request.wValue, UDESC_STRING, si);
+	USETW2(req.ucr_request.wValue, UDESC_STRING, 0);
 	USETW(req.ucr_request.wIndex, 0);
+	USETW(req.ucr_request.wLength, sizeof(usb_string_descriptor_t));
+	req.ucr_flags = USBD_SHORT_XFER_OK;
+	r = ioctl(usbf, USB_REQUEST, &req);
+	if (r < 0) {
+		fprintf(stderr, "get lang tbl failed (error=%d)\n", errno);
+		*s = 0;
+		return;
+	}
+	if (req.ucr_actlen > 0 && us.bLength >= 4) {
+		lang = UGETW(us.bString[0]);
+#if 0
+		printf("getstring: %d langs, using %d\n",
+		       (us.bLength - 2) / 2, lang);
+#endif
+	}
+#endif
+
+	req.ucr_addr = usbaddr;
+	req.ucr_request.bmRequestType = UT_READ_DEVICE;
+	req.ucr_request.bRequest = UR_GET_DESCRIPTOR;
+	req.ucr_data = &us;
+	USETW2(req.ucr_request.wValue, UDESC_STRING, si);
+	USETW(req.ucr_request.wIndex, lang);
 #ifdef NSTRINGS
 	USETW(req.ucr_request.wLength, sizeof(usb_string_descriptor_t));
 	req.ucr_flags = USBD_SHORT_XFER_OK;
@@ -154,6 +202,7 @@ descTypeName(int t)
 	case UDESC_STRING: p = "string"; break;
 	case UDESC_INTERFACE: p = "interface"; break;
 	case UDESC_ENDPOINT: p = "endpoint"; break;
+	case UDESC_INTERFACE_ASSOC: p = "iad"; break;
 	case 0x20: p = "cs_undefined"; break;
 	case UDESC_CS_DEVICE: p = "cs_device"; break;
 	case UDESC_CS_CONFIG: p = "cs_config"; break;
@@ -278,6 +327,21 @@ bInterfaceProtocol=%d iInterface=%d(%s)\
 	       d->iInterface, ifc);
 }
 
+void
+priad(usb_interface_assoc_descriptor_t *d)
+{
+	char func[MAXSTR];
+	getstring(d->iFunction, func);
+	if (d->bDescriptorType != UDESC_INTERFACE_ASSOC) printf("weird descriptorType, should be %d\n", UDESC_INTERFACE_ASSOC);
+	printf("\
+bLength=%d bDescriptorType=%s bFirstInterface=%d bInterfaceCount=%d\n\
+bFunctionClass=%d bFunctionSubClass=%d bFunctionProtocol=%d\n\
+iFunction=%d(%s)\n",
+	    d->bLength, descTypeName(d->bDescriptorType), d->bFirstInterface,
+	    d->bInterfaceCount, d->bFunctionClass, d->bFunctionSubClass,
+	    d->bFunctionProtocol, d->iFunction, func);
+}
+
 char *xfernames[] = { "control", "isochronous", "bulk", "interrupt" };
 char *xfertypes[] = { "", "-async", "-adaptive", "-sync" };
 
@@ -384,7 +448,7 @@ struct usb_cdc_union_descriptor {
 };
 
 void
-prcdcd(usb_descriptor_t *ud)
+prcdcd(struct usb_cdc_header_descriptor *ud)
 {
 	if (ud->bDescriptorType != UDESC_CS_INTERFACE)
 		printf("prcdcd: strange bDescriptorType=%d\n", 
@@ -630,7 +694,7 @@ gethubdesc(int f, usb_hub_descriptor_t *
 	req.ucr_addr = addr;
 	req.ucr_request.bmRequestType = UT_READ_CLASS_DEVICE;
 	req.ucr_request.bRequest = UR_GET_DESCRIPTOR;
-	USETW(req.ucr_request.wValue, 0);
+	USETW2(req.ucr_request.wValue, UDESC_HUB, 0);
 	USETW(req.ucr_request.wIndex, 0);
 	USETW(req.ucr_request.wLength, USB_HUB_DESCRIPTOR_SIZE);
 	req.ucr_data = d;
@@ -1145,6 +1209,11 @@ prdesc(void *p, int *class, int *subclas
 		prhubd(p);
 		break;
 #endif
+	case UDESC_INTERFACE_ASSOC:
+		printf("INTERFACE ASSOCIATION descriptor:\n");
+		priad(p);
+		break;
+		break;
 	case UDESC_CS_DEVICE:
 		if (*class == UICLASS_HID) {
 			usb_hid_descriptor_t *hid = p;
@@ -1243,8 +1312,8 @@ prdesc(void *p, int *class, int *subclas
 	default:
 	def:
 		printf("Unknown descriptor (class %d/%d):\n", *class, *subclass);
-		printf("bLength=%d bDescriptorType=%d bDescriptorSubtype=%d ...\n", d->bLength, 
-		       d->bDescriptorType, d->bDescriptorSubtype
+		printf("bLength=%d bDescriptorType=%d ...\n", d->bLength, 
+		       d->bDescriptorType
 		       );
 		break;
 	}
@@ -1321,6 +1390,7 @@ main(int argc, char **argv)
 
 	if (!doaddr)
 		prunits(f);
+#ifndef __NetBSD__
 	if (!nodisc) {
 		r = ioctl(f, USB_DISCOVER);
 		if (r < 0)
@@ -1329,6 +1399,7 @@ main(int argc, char **argv)
 		if (disconly)
 			exit(0);
 	}
+#endif
 
 	for(addr = 0; addr < USB_MAX_DEVICES; addr++) {
 		if (doaddr != -1 && addr != doaddr)