cdc711dc |
1 | #if defined(__GNUC__) && !defined(__STRICT_ANSI__) |
2 | |
3 | #define _GNU_SOURCE 1 |
4 | |
5 | #if defined(RTLD_NEXT) |
6 | #define REAL_LIBC RTLD_NEXT |
7 | #else |
8 | #define REAL_LIBC ((void *) -1L) |
9 | #endif |
10 | |
11 | #include <dlfcn.h> |
12 | #include <stdarg.h> |
13 | #include <stdlib.h> |
14 | #include <string.h> |
15 | #include <unistd.h> |
16 | #include <fcntl.h> |
17 | #include <sys/types.h> |
18 | #include <sys/stat.h> |
19 | #include <sys/time.h> |
20 | #include <stdio.h> |
f10480d1 |
21 | #include <usb.h> |
da3ba95a |
22 | #include "xilinx.h" |
cdc711dc |
23 | |
9c9fd67c |
24 | static int (*ioctl_func) (int, int, void *) = NULL; |
2c2119eb |
25 | static int windrvrfd = 0; |
f10480d1 |
26 | static struct usb_bus *busses = NULL; |
ac22d975 |
27 | static struct usb_device *usb_cable; |
292160ed |
28 | static unsigned long card_type; |
29 | |
795992ad |
30 | #define NO_WINDRVR 1 |
cdc711dc |
31 | |
32 | void hexdump(unsigned char *buf, int len); |
da3ba95a |
33 | void diff(unsigned char *buf1, unsigned char *buf2, int len); |
cdc711dc |
34 | |
792bf5f2 |
35 | //unique: 94, bytes: 276, options: 0 |
36 | //Vendor: 3fd |
37 | //12 01 00 02 00 00 00 40 fd 03 08 00 00 00 01 02 12 01 00 02 00 00 00 40 fd 03 08 00 00 00 01 02 |
38 | //00 01 00 00 00 00 00 00 40 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 40 00 00 00 00 00 00 00 |
3664a3e3 |
39 | //03 00 00 00 00 00 00 00 38 45 21 08 38 45 21 08 03 00 00 00 00 00 00 00 38 45 21 08 38 45 21 08 |
40 | //4c 45 21 08 00 00 00 00 00 00 00 00 00 00 00 00 4c 45 21 08 00 00 00 00 00 00 00 00 00 00 00 00 |
792bf5f2 |
41 | //00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |
42 | //00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |
43 | //00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |
44 | //00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |
45 | //00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |
46 | //00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |
47 | //00 00 00 00 00 00 00 00 09 02 20 00 01 02 00 80 00 00 00 00 00 00 00 00 09 02 20 00 01 02 00 80 |
3664a3e3 |
48 | //8c 00 00 00 01 00 00 00 4c 45 21 08 58 45 21 08 8c 00 00 00 01 00 00 00 4c 45 21 08 58 45 21 08 |
49 | //01 00 00 00 58 45 21 08 09 04 00 00 02 ff 00 00 01 00 00 00 58 45 21 08 09 04 00 00 02 ff 00 00 |
50 | //00 00 00 00 6c 45 21 08 7c 45 21 08 07 05 02 02 00 00 00 00 6c 45 21 08 7c 45 21 08 07 05 02 02 |
792bf5f2 |
51 | //00 02 00 00 07 05 86 02 00 02 00 00 02 00 00 00 00 02 00 00 07 05 86 02 00 02 00 00 02 00 00 00 |
52 | //00 02 00 00 02 00 00 00 02 00 00 00 00 00 00 00 00 02 00 00 02 00 00 00 02 00 00 00 00 00 00 00 |
53 | //86 00 00 00 00 02 00 00 02 00 00 00 01 00 00 00 86 00 00 00 00 02 00 00 02 00 00 00 01 00 00 00 |
54 | //00 00 00 00 00 00 00 00 |
f95f1d2e |
55 | int usb_deviceinfo(unsigned char *buf) { |
56 | int i,j,k,l; |
57 | int len = 0; |
3664a3e3 |
58 | WDU_CONFIGURATION **pConfigs, **pActiveConfig; |
59 | WDU_INTERFACE **pActiveInterface; |
f95f1d2e |
60 | |
61 | if (buf) { |
62 | struct usb_device_info *udi = (struct usb_device_info*)(buf+len); |
63 | |
64 | udi->Descriptor.bLength = sizeof(WDU_DEVICE_DESCRIPTOR); |
65 | udi->Descriptor.bDescriptorType = usb_cable->descriptor.bDescriptorType; |
66 | udi->Descriptor.bcdUSB = usb_cable->descriptor.bcdUSB; |
67 | udi->Descriptor.bDeviceClass = usb_cable->descriptor.bDeviceClass; |
68 | udi->Descriptor.bDeviceSubClass = usb_cable->descriptor.bDeviceSubClass; |
69 | udi->Descriptor.bDeviceProtocol = usb_cable->descriptor.bDeviceProtocol; |
70 | udi->Descriptor.bMaxPacketSize0 = usb_cable->descriptor.bMaxPacketSize0; |
71 | udi->Descriptor.idVendor = usb_cable->descriptor.idVendor; |
72 | udi->Descriptor.idProduct = usb_cable->descriptor.idProduct; |
73 | udi->Descriptor.bcdDevice = usb_cable->descriptor.bcdDevice; |
74 | udi->Descriptor.iManufacturer = usb_cable->descriptor.iManufacturer; |
75 | udi->Descriptor.iProduct = usb_cable->descriptor.iProduct; |
76 | udi->Descriptor.iSerialNumber = usb_cable->descriptor.iSerialNumber; |
77 | udi->Descriptor.bNumConfigurations = usb_cable->descriptor.bNumConfigurations; |
78 | |
79 | /* TODO: Fix Pipe0! */ |
80 | udi->Pipe0.dwNumber = 0x00; |
81 | udi->Pipe0.dwMaximumPacketSize = usb_cable->descriptor.bMaxPacketSize0; |
82 | udi->Pipe0.type = 0; |
83 | udi->Pipe0.direction = 3; |
84 | udi->Pipe0.dwInterval = 0; |
3664a3e3 |
85 | |
86 | pConfigs = &(udi->pConfigs); |
87 | pActiveConfig = &(udi->pActiveConfig); |
88 | pActiveInterface = &(udi->pActiveInterface[0]); |
f95f1d2e |
89 | } |
90 | |
91 | len = sizeof(struct usb_device_info); |
92 | |
93 | for (i=0; i<usb_cable->descriptor.bNumConfigurations; i++) |
94 | { |
95 | struct usb_config_descriptor *conf_desc = &usb_cable->config[i]; |
3664a3e3 |
96 | WDU_INTERFACE **pInterfaces; |
97 | WDU_ALTERNATE_SETTING **pAlternateSettings[conf_desc->bNumInterfaces]; |
98 | WDU_ALTERNATE_SETTING **pActiveAltSetting[conf_desc->bNumInterfaces]; |
99 | |
f95f1d2e |
100 | if (buf) { |
101 | WDU_CONFIGURATION *cfg = (WDU_CONFIGURATION*)(buf+len); |
102 | |
3664a3e3 |
103 | *pConfigs = cfg; |
104 | *pActiveConfig = cfg; |
105 | |
f95f1d2e |
106 | cfg->Descriptor.bLength = conf_desc->bLength; |
107 | cfg->Descriptor.bDescriptorType = conf_desc->bDescriptorType; |
108 | cfg->Descriptor.wTotalLength = conf_desc->wTotalLength; |
109 | cfg->Descriptor.bNumInterfaces = conf_desc->bNumInterfaces; |
110 | cfg->Descriptor.bConfigurationValue = conf_desc->bConfigurationValue; |
111 | cfg->Descriptor.iConfiguration = conf_desc->iConfiguration; |
112 | cfg->Descriptor.bmAttributes = conf_desc->bmAttributes; |
113 | cfg->Descriptor.MaxPower = conf_desc->MaxPower; |
114 | |
115 | cfg->dwNumInterfaces = conf_desc->bNumInterfaces; |
3664a3e3 |
116 | |
117 | pInterfaces = &(cfg->pInterfaces); |
f95f1d2e |
118 | } |
119 | len += sizeof(WDU_CONFIGURATION); |
3664a3e3 |
120 | |
f95f1d2e |
121 | if (buf) { |
3664a3e3 |
122 | *pInterfaces = (WDU_INTERFACE*)(buf+len); |
f95f1d2e |
123 | for (j=0; j<conf_desc->bNumInterfaces; j++) { |
124 | WDU_INTERFACE *iface = (WDU_INTERFACE*)(buf+len); |
3664a3e3 |
125 | |
126 | pActiveInterface[j] = iface; |
127 | |
128 | pAlternateSettings[j] = &(iface->pAlternateSettings); |
f95f1d2e |
129 | iface->dwNumAltSettings = usb_cable->config[i].interface[j].num_altsetting; |
3664a3e3 |
130 | pActiveAltSetting[j] = &(iface->pActiveAltSetting); |
f95f1d2e |
131 | |
132 | len += sizeof(WDU_INTERFACE); |
133 | } |
134 | } else { |
135 | len += sizeof(WDU_INTERFACE) * conf_desc->bNumInterfaces; |
136 | } |
137 | |
138 | for (j=0; j<conf_desc->bNumInterfaces; j++) |
139 | { |
140 | struct usb_interface *interface = &usb_cable->config[i].interface[j]; |
3664a3e3 |
141 | |
142 | if (buf) { |
143 | *pAlternateSettings[j] = (WDU_ALTERNATE_SETTING*)(buf+len); |
144 | /* FIXME: */ |
145 | *pActiveAltSetting[j] = (WDU_ALTERNATE_SETTING*)(buf+len); |
146 | } |
147 | |
f95f1d2e |
148 | for(k=0; k<interface->num_altsetting; k++) |
149 | { |
3664a3e3 |
150 | unsigned char bNumEndpoints = interface->altsetting[k].bNumEndpoints; |
151 | WDU_ENDPOINT_DESCRIPTOR **pEndpointDescriptors; |
152 | WDU_PIPE_INFO **pPipes; |
153 | |
f95f1d2e |
154 | if (buf) { |
155 | WDU_ALTERNATE_SETTING *altset = (WDU_ALTERNATE_SETTING*)(buf+len); |
156 | |
157 | altset->Descriptor.bLength = interface->altsetting[k].bLength; |
158 | altset->Descriptor.bDescriptorType = interface->altsetting[k].bDescriptorType; |
159 | altset->Descriptor.bInterfaceNumber = interface->altsetting[k].bInterfaceNumber; |
160 | altset->Descriptor.bAlternateSetting = interface->altsetting[k].bAlternateSetting; |
161 | altset->Descriptor.bNumEndpoints = interface->altsetting[k].bNumEndpoints; |
162 | altset->Descriptor.bInterfaceClass = interface->altsetting[k].bInterfaceClass; |
163 | altset->Descriptor.bInterfaceSubClass = interface->altsetting[k].bInterfaceSubClass; |
164 | altset->Descriptor.bInterfaceProtocol = interface->altsetting[k].bInterfaceProtocol; |
165 | altset->Descriptor.iInterface = interface->altsetting[k].iInterface; |
3664a3e3 |
166 | pEndpointDescriptors = &(altset->pEndpointDescriptors); |
167 | pPipes = &(altset->pPipes); |
f95f1d2e |
168 | |
169 | } |
170 | len +=sizeof(WDU_ALTERNATE_SETTING); |
171 | |
172 | if (buf) { |
3664a3e3 |
173 | *pEndpointDescriptors = (WDU_ENDPOINT_DESCRIPTOR*)(buf+len); |
f95f1d2e |
174 | for (l = 0; l < bNumEndpoints; l++) { |
175 | WDU_ENDPOINT_DESCRIPTOR *ed = (WDU_ENDPOINT_DESCRIPTOR*)(buf+len); |
f95f1d2e |
176 | |
177 | ed->bLength = interface->altsetting[k].endpoint[l].bLength; |
178 | ed->bDescriptorType = interface->altsetting[k].endpoint[l].bDescriptorType; |
179 | ed->bEndpointAddress = interface->altsetting[k].endpoint[l].bEndpointAddress; |
180 | ed->bmAttributes = interface->altsetting[k].endpoint[l].bmAttributes; |
181 | ed->wMaxPacketSize = interface->altsetting[k].endpoint[l].wMaxPacketSize; |
182 | ed->bInterval = interface->altsetting[k].endpoint[l].bInterval; |
183 | |
184 | len += sizeof(WDU_ENDPOINT_DESCRIPTOR); |
792bf5f2 |
185 | } |
f95f1d2e |
186 | |
3664a3e3 |
187 | *pPipes = (WDU_PIPE_INFO*)(buf+len); |
792bf5f2 |
188 | for (l = 0; l < bNumEndpoints; l++) { |
189 | WDU_PIPE_INFO *pi = (WDU_PIPE_INFO*)(buf+len); |
f95f1d2e |
190 | |
191 | pi->dwNumber = interface->altsetting[k].endpoint[l].bEndpointAddress; |
192 | pi->dwMaximumPacketSize = WDU_GET_MAX_PACKET_SIZE(interface->altsetting[k].endpoint[l].wMaxPacketSize); |
193 | pi->type = interface->altsetting[k].endpoint[l].bmAttributes & USB_ENDPOINT_TYPE_MASK; |
194 | if (pi->type == PIPE_TYPE_CONTROL) |
195 | pi->direction = WDU_DIR_IN_OUT; |
196 | else |
197 | { |
198 | pi->direction = interface->altsetting[k].endpoint[l].bEndpointAddress & USB_ENDPOINT_DIR_MASK ? WDU_DIR_IN : WDU_DIR_OUT; |
199 | } |
200 | |
201 | pi->dwInterval = interface->altsetting[k].endpoint[l].bInterval; |
202 | |
203 | len += sizeof(WDU_PIPE_INFO); |
204 | } |
205 | } else { |
206 | len +=(sizeof(WDU_ENDPOINT_DESCRIPTOR)+sizeof(WDU_PIPE_INFO))*bNumEndpoints; |
207 | } |
208 | } |
209 | } |
210 | } |
211 | |
212 | return len; |
213 | } |
214 | |
9c9fd67c |
215 | int do_wdioctl(int fd, unsigned int request, unsigned char *wdioctl) { |
cdc711dc |
216 | struct header_struct* wdheader = (struct header_struct*)wdioctl; |
9c9fd67c |
217 | struct version_struct *version; |
218 | int ret = 0; |
cdc711dc |
219 | |
da3ba95a |
220 | if (wdheader->magic != MAGIC) { |
2c2119eb |
221 | fprintf(stderr,"!!!ERROR: magic header does not match!!!\n"); |
222 | return (*ioctl_func) (fd, request, wdioctl); |
cdc711dc |
223 | } |
224 | |
cdc711dc |
225 | switch(request) { |
da3ba95a |
226 | case VERSION: |
9c9fd67c |
227 | version = (struct version_struct*)(wdheader->data); |
228 | strcpy(version->version, "WinDriver no more"); |
229 | version->versionul = 999; |
230 | fprintf(stderr,"faking VERSION\n"); |
cdc711dc |
231 | break; |
2c2119eb |
232 | |
233 | case LICENSE: |
234 | fprintf(stderr,"faking LICENSE\n"); |
235 | break; |
236 | |
9c9fd67c |
237 | case CARD_REGISTER: |
238 | { |
2c2119eb |
239 | //struct card_register* cr = (struct card_register*)(wdheader->data); |
9c9fd67c |
240 | /* Todo: LPT-Port already in use */ |
241 | } |
242 | fprintf(stderr,"faking CARD_REGISTER\n"); |
da3ba95a |
243 | break; |
2c2119eb |
244 | |
da3ba95a |
245 | case USB_TRANSFER: |
9c9fd67c |
246 | fprintf(stderr,"in USB_TRANSFER"); |
da3ba95a |
247 | { |
248 | struct usb_transfer *ut = (struct usb_transfer*)(wdheader->data); |
249 | |
2c2119eb |
250 | fprintf(stderr," unique: %lu, pipe: %lu, read: %lu, options: %lx, size: %lu, timeout: %lx\n", ut->dwUniqueID, ut->dwPipeNum, ut->fRead, ut->dwOptions, ut->dwBufferSize, ut->dwTimeout); |
9c9fd67c |
251 | fprintf(stderr,"setup packet: "); |
252 | hexdump(ut->SetupPacket, 8); |
253 | fprintf(stderr,"\n"); |
254 | if (!ut->fRead && ut->dwBufferSize) |
255 | { |
256 | hexdump(ut->pBuffer, ut->dwBufferSize); |
257 | fprintf(stderr,"\n"); |
258 | } |
259 | |
795992ad |
260 | #ifndef NO_WINDRVR |
9c9fd67c |
261 | ret = (*ioctl_func) (fd, request, wdioctl); |
292160ed |
262 | #endif |
9c9fd67c |
263 | |
2c2119eb |
264 | fprintf(stderr,"Transferred: %lu (%s)\n",ut->dwBytesTransferred, (ut->fRead?"read":"write")); |
9c9fd67c |
265 | if (ut->fRead && ut->dwBytesTransferred) |
266 | { |
267 | fprintf(stderr,"Read: "); |
268 | hexdump(ut->pBuffer, ut->dwBytesTransferred); |
269 | } |
da3ba95a |
270 | fprintf(stderr,"\n"); |
271 | } |
cdc711dc |
272 | break; |
2c2119eb |
273 | |
da3ba95a |
274 | case INT_ENABLE: |
9c9fd67c |
275 | fprintf(stderr,"faking INT_ENABLE"); |
da3ba95a |
276 | { |
9c9fd67c |
277 | struct interrupt *it = (struct interrupt*)(wdheader->data); |
cdc711dc |
278 | |
53f639f2 |
279 | fprintf(stderr,"Handle: %lu, Options: %lx, ncmds: %lu, enableok: %lu, count: %lu, lost: %lu, stopped: %lu\n", it->hInterrupt, it->dwOptions, it->dwCmds, it->fEnableOk, it->dwCounter, it->dwLost, it->fStopped); |
cdc711dc |
280 | |
9c9fd67c |
281 | it->fEnableOk = 1; |
282 | //ret = (*ioctl_func) (fd, request, wdioctl); |
283 | } |
cdc711dc |
284 | |
cdc711dc |
285 | break; |
9c9fd67c |
286 | |
da3ba95a |
287 | case INT_DISABLE: |
9c9fd67c |
288 | fprintf(stderr,"INT_DISABLE\n"); |
da3ba95a |
289 | { |
9c9fd67c |
290 | struct interrupt *it = (struct interrupt*)(wdheader->data); |
da3ba95a |
291 | |
53f639f2 |
292 | fprintf(stderr,"Handle: %lu, Options: %lx, ncmds: %lu, enableok: %lu, count: %lu, lost: %lu, stopped: %lu\n", it->hInterrupt, it->dwOptions, it->dwCmds, it->fEnableOk, it->dwCounter, it->dwLost, it->fStopped); |
795992ad |
293 | #ifndef NO_WINDRVR |
9c9fd67c |
294 | ret = (*ioctl_func) (fd, request, wdioctl); |
e71b6bf3 |
295 | #else |
296 | it->dwCounter = 0; |
297 | it->fStopped = 1; |
292160ed |
298 | #endif |
53f639f2 |
299 | fprintf(stderr,"Handle: %lu, Options: %lx, ncmds: %lu, enableok: %lu, count: %lu, lost: %lu, stopped: %lu\n", it->hInterrupt, it->dwOptions, it->dwCmds, it->fEnableOk, it->dwCounter, it->dwLost, it->fStopped); |
da3ba95a |
300 | } |
da3ba95a |
301 | break; |
da3ba95a |
302 | |
9c9fd67c |
303 | case USB_SET_INTERFACE: |
304 | fprintf(stderr,"USB_SET_INTERFACE\n"); |
da3ba95a |
305 | { |
9c9fd67c |
306 | struct usb_set_interface *usi = (struct usb_set_interface*)(wdheader->data); |
307 | |
2c2119eb |
308 | fprintf(stderr,"unique: %lu, interfacenum: %lu, alternatesetting: %lu, options: %lx\n", usi->dwUniqueID, usi->dwInterfaceNum, usi->dwAlternateSetting, usi->dwOptions); |
795992ad |
309 | #ifndef NO_WINDRVR |
9c9fd67c |
310 | ret = (*ioctl_func) (fd, request, wdioctl); |
292160ed |
311 | #endif |
da3ba95a |
312 | } |
cdc711dc |
313 | break; |
da3ba95a |
314 | |
9c9fd67c |
315 | case USB_GET_DEVICE_DATA: |
316 | fprintf(stderr,"USB_GET_DEVICE_DATA\n"); |
317 | { |
318 | struct usb_get_device_data *ugdd = (struct usb_get_device_data*)(wdheader->data); |
319 | int pSize; |
320 | |
e71b6bf3 |
321 | fprintf(stderr, "unique: %lu, bytes: %lu, options: %lx\n", ugdd->dwUniqueID, ugdd->dwBytes, ugdd->dwOptions); |
9c9fd67c |
322 | pSize = ugdd->dwBytes; |
795992ad |
323 | #ifndef NO_WINDRVR |
9c9fd67c |
324 | ret = (*ioctl_func) (fd, request, wdioctl); |
e71b6bf3 |
325 | #else |
326 | if (!ugdd->dwBytes) { |
327 | if (usb_cable) { |
f95f1d2e |
328 | ugdd->dwBytes = usb_deviceinfo(NULL); |
e71b6bf3 |
329 | } |
330 | } else { |
f95f1d2e |
331 | usb_deviceinfo((unsigned char*)ugdd->pBuf); |
e71b6bf3 |
332 | } |
292160ed |
333 | #endif |
9c9fd67c |
334 | if (pSize) { |
e71b6bf3 |
335 | struct usb_device_info *udi = (struct usb_device_info*)ugdd->pBuf; |
336 | |
337 | fprintf(stderr, "Vendor: %x\n", udi->Descriptor.idVendor); |
338 | |
9c9fd67c |
339 | hexdump(ugdd->pBuf, pSize); |
340 | fprintf(stderr, "\n"); |
da3ba95a |
341 | } |
342 | } |
9c9fd67c |
343 | break; |
344 | |
b0f621dd |
345 | case EVENT_REGISTER: |
346 | fprintf(stderr,"EVENT_REGISTER\n"); |
347 | { |
348 | struct event *e = (struct event*)(wdheader->data); |
ac22d975 |
349 | struct usb_bus *bus; |
b0f621dd |
350 | int i; |
351 | |
352 | fprintf(stderr,"handle: %lu, action: %lu, status: %lu, eventid: %lu, cardtype: %lu, kplug: %lu, options: %lu, dev: %lx:%lx, unique: %lu, ver: %lu, nummatch: %lu\n", e->handle, e->dwAction, e->dwStatus, e->dwEventId, e->dwCardType, e->hKernelPlugIn, e->dwOptions, e->u.Usb.deviceId.dwVendorId, e->u.Usb.deviceId.dwProductId, e->u.Usb.dwUniqueID, e->dwEventVer, e->dwNumMatchTables); |
ac22d975 |
353 | for (i = 0; i < e->dwNumMatchTables; i++) { |
e71b6bf3 |
354 | fprintf(stderr,"match: dev: %04x:%04x, class: %x, subclass: %x, intclass: %x, intsubclass: %x, intproto: %x\n", e->matchTables[i].VendorId, e->matchTables[i].ProductId, e->matchTables[i].bDeviceClass, e->matchTables[i].bDeviceSubClass, e->matchTables[i].bInterfaceClass, e->matchTables[i].bInterfaceSubClass, e->matchTables[i].bInterfaceProtocol); |
b0f621dd |
355 | |
ac22d975 |
356 | for (bus = busses; bus; bus = bus->next) { |
357 | struct usb_device *dev; |
358 | |
359 | for (dev = bus->devices; dev; dev = dev->next) { |
360 | struct usb_device_descriptor *desc = &(dev->descriptor); |
361 | |
362 | if((desc->idVendor == e->matchTables[i].VendorId) && |
363 | (desc->idProduct == e->matchTables[i].ProductId) && |
364 | (desc->bDeviceClass == e->matchTables[i].bDeviceClass) && |
365 | (desc->bDeviceSubClass == e->matchTables[i].bDeviceSubClass)) { |
366 | struct usb_interface *interface = dev->config->interface; |
367 | int ai; |
368 | |
369 | for (ai = 0; ai < interface->num_altsetting; ai++) { |
370 | fprintf(stderr, "intclass: %x, intsubclass: %x, intproto: %x\n", interface->altsetting[i].bInterfaceClass, interface->altsetting[i].bInterfaceSubClass, interface->altsetting[i].bInterfaceProtocol); |
371 | if ((interface->altsetting[i].bInterfaceSubClass == e->matchTables[i].bInterfaceSubClass) && |
372 | (interface->altsetting[i].bInterfaceProtocol == e->matchTables[i].bInterfaceProtocol)){ |
373 | /* TODO: check interfaceClass! */ |
374 | fprintf(stderr,"!!!FOUND DEVICE WITH LIBUSB!!!\n"); |
375 | usb_cable = dev; |
292160ed |
376 | card_type = e->dwCardType; |
ac22d975 |
377 | } |
378 | } |
379 | } |
380 | } |
381 | } |
382 | } |
383 | |
795992ad |
384 | #ifndef NO_WINDRVR |
b0f621dd |
385 | ret = (*ioctl_func) (fd, request, wdioctl); |
292160ed |
386 | #endif |
b0f621dd |
387 | |
388 | fprintf(stderr,"handle: %lu, action: %lu, status: %lu, eventid: %lu, cardtype: %lu, kplug: %lu, options: %lu, dev: %lx:%lx, unique: %lu, ver: %lu, nummatch: %lu\n", e->handle, e->dwAction, e->dwStatus, e->dwEventId, e->dwCardType, e->hKernelPlugIn, e->dwOptions, e->u.Usb.deviceId.dwVendorId, e->u.Usb.deviceId.dwProductId, e->u.Usb.dwUniqueID, e->dwEventVer, e->dwNumMatchTables); |
389 | for (i = 0; i < e->dwNumMatchTables; i++) |
e71b6bf3 |
390 | fprintf(stderr,"match: dev: %04x:%04x, class: %x, subclass: %x, intclass: %x, intsubclass: %x, intproto: %x\n", e->matchTables[i].VendorId, e->matchTables[i].ProductId, e->matchTables[i].bDeviceClass, e->matchTables[i].bDeviceSubClass, e->matchTables[i].bInterfaceClass, e->matchTables[i].bInterfaceSubClass, e->matchTables[i].bInterfaceProtocol); |
b0f621dd |
391 | } |
392 | break; |
393 | |
da3ba95a |
394 | case TRANSFER: |
9c9fd67c |
395 | fprintf(stderr,"TRANSFER\n"); |
795992ad |
396 | #ifndef NO_WINDRVR |
9c9fd67c |
397 | ret = (*ioctl_func) (fd, request, wdioctl); |
292160ed |
398 | #endif |
9c9fd67c |
399 | break; |
400 | |
da3ba95a |
401 | case EVENT_UNREGISTER: |
9c9fd67c |
402 | fprintf(stderr,"EVENT_UNREGISTER\n"); |
795992ad |
403 | #ifndef NO_WINDRVR |
9c9fd67c |
404 | ret = (*ioctl_func) (fd, request, wdioctl); |
292160ed |
405 | #endif |
9c9fd67c |
406 | break; |
407 | |
da3ba95a |
408 | case INT_WAIT: |
9c9fd67c |
409 | fprintf(stderr,"INT_WAIT\n"); |
b0f621dd |
410 | { |
411 | struct interrupt *it = (struct interrupt*)(wdheader->data); |
412 | |
53f639f2 |
413 | fprintf(stderr,"Handle: %lu, Options: %lx, ncmds: %lu, enableok: %lu, count: %lu, lost: %lu, stopped: %lu\n", it->hInterrupt, it->dwOptions, it->dwCmds, it->fEnableOk, it->dwCounter, it->dwLost, it->fStopped); |
b0f621dd |
414 | |
795992ad |
415 | #ifndef NO_WINDRVR |
b0f621dd |
416 | ret = (*ioctl_func) (fd, request, wdioctl); |
292160ed |
417 | #else |
418 | if (usb_cable) |
419 | it->dwCounter++; |
420 | #endif |
421 | |
53f639f2 |
422 | fprintf(stderr,"Handle: %lu, Options: %lx, ncmds: %lu, enableok: %lu, count: %lu, lost: %lu, stopped: %lu\n", it->hInterrupt, it->dwOptions, it->dwCmds, it->fEnableOk, it->dwCounter, it->dwLost, it->fStopped); |
b0f621dd |
423 | } |
9c9fd67c |
424 | break; |
425 | |
da3ba95a |
426 | case CARD_UNREGISTER: |
9c9fd67c |
427 | fprintf(stderr,"CARD_UNREGISTER\n"); |
795992ad |
428 | #ifndef NO_WINDRVR |
9c9fd67c |
429 | ret = (*ioctl_func) (fd, request, wdioctl); |
292160ed |
430 | #endif |
9c9fd67c |
431 | break; |
432 | |
da3ba95a |
433 | case EVENT_PULL: |
9c9fd67c |
434 | fprintf(stderr,"EVENT_PULL\n"); |
b1831983 |
435 | { |
436 | struct event *e = (struct event*)(wdheader->data); |
437 | int i; |
438 | |
439 | fprintf(stderr,"handle: %lu, action: %lu, status: %lu, eventid: %lu, cardtype: %lu, kplug: %lu, options: %lu, dev: %lx:%lx, unique: %lu, ver: %lu, nummatch: %lu\n", e->handle, e->dwAction, e->dwStatus, e->dwEventId, e->dwCardType, e->hKernelPlugIn, e->dwOptions, e->u.Usb.deviceId.dwVendorId, e->u.Usb.deviceId.dwProductId, e->u.Usb.dwUniqueID, e->dwEventVer, e->dwNumMatchTables); |
440 | for (i = 0; i < e->dwNumMatchTables; i++) |
e71b6bf3 |
441 | fprintf(stderr,"match: dev: %04x:%04x, class: %x, subclass: %x, intclass: %x, intsubclass: %x, intproto: %x\n", e->matchTables[i].VendorId, e->matchTables[i].ProductId, e->matchTables[i].bDeviceClass, e->matchTables[i].bDeviceSubClass, e->matchTables[i].bInterfaceClass, e->matchTables[i].bInterfaceSubClass, e->matchTables[i].bInterfaceProtocol); |
b1831983 |
442 | |
795992ad |
443 | #ifndef NO_WINDRVR |
b1831983 |
444 | ret = (*ioctl_func) (fd, request, wdioctl); |
292160ed |
445 | #else |
446 | //EVENT_PULL |
447 | //handle: 1, action: 0, status: 0, eventid: 0, cardtype: 0, kplug: 0, options: 0, dev: 0:0, unique: 0, ver: 1, nummatch: 1 |
448 | //match: dev: 0:0, class: 0, subclass: 0, intclass: 0, intsubclass: 0, intproto: 0 |
449 | //handle: 1, action: 1, status: 0, eventid: 109, cardtype: 4294967294, kplug: 0, options: 0, dev: 0:0, unique: 90, ver: 1, nummatch: 1 |
450 | //match: dev: 3fd:8, class: 0, subclass: 0, intclass: ff, intsubclass: 0, intproto: 0 |
451 | if (usb_cable) { |
452 | struct usb_interface *interface = usb_cable->config->interface; |
453 | |
454 | e->dwCardType = card_type; |
455 | e->dwAction = 1; |
456 | e->dwEventId = 109; |
457 | e->u.Usb.dwUniqueID = 4711; |
458 | e->matchTables[0].VendorId = usb_cable->descriptor.idVendor; |
459 | e->matchTables[0].ProductId = usb_cable->descriptor.idProduct; |
460 | e->matchTables[0].bDeviceClass = usb_cable->descriptor.bDeviceClass; |
461 | e->matchTables[0].bDeviceSubClass = usb_cable->descriptor.bDeviceSubClass; |
462 | e->matchTables[0].bInterfaceClass = interface->altsetting[0].bInterfaceClass; |
463 | e->matchTables[0].bInterfaceSubClass = interface->altsetting[0].bInterfaceSubClass; |
464 | e->matchTables[0].bInterfaceProtocol = interface->altsetting[0].bInterfaceProtocol; |
465 | } |
466 | #endif |
b1831983 |
467 | |
468 | fprintf(stderr,"handle: %lu, action: %lu, status: %lu, eventid: %lu, cardtype: %lu, kplug: %lu, options: %lu, dev: %lx:%lx, unique: %lu, ver: %lu, nummatch: %lu\n", e->handle, e->dwAction, e->dwStatus, e->dwEventId, e->dwCardType, e->hKernelPlugIn, e->dwOptions, e->u.Usb.deviceId.dwVendorId, e->u.Usb.deviceId.dwProductId, e->u.Usb.dwUniqueID, e->dwEventVer, e->dwNumMatchTables); |
469 | for (i = 0; i < e->dwNumMatchTables; i++) |
e71b6bf3 |
470 | fprintf(stderr,"match: dev: %04x:%04x, class: %x, subclass: %x, intclass: %x, intsubclass: %x, intproto: %x\n", e->matchTables[i].VendorId, e->matchTables[i].ProductId, e->matchTables[i].bDeviceClass, e->matchTables[i].bDeviceSubClass, e->matchTables[i].bInterfaceClass, e->matchTables[i].bInterfaceSubClass, e->matchTables[i].bInterfaceProtocol); |
b1831983 |
471 | } |
9c9fd67c |
472 | break; |
473 | |
da3ba95a |
474 | default: |
292160ed |
475 | fprintf(stderr,"!!!Unsupported IOCTL: %x!!!\n", request); |
795992ad |
476 | #ifndef NO_WINDRVR |
9c9fd67c |
477 | ret = (*ioctl_func) (fd, request, wdioctl); |
292160ed |
478 | #endif |
479 | break; |
cdc711dc |
480 | } |
da3ba95a |
481 | |
9c9fd67c |
482 | return ret; |
cdc711dc |
483 | } |
484 | |
485 | |
486 | typedef int (*open_funcptr_t) (const char *, int, mode_t); |
487 | |
cdc711dc |
488 | int open (const char *pathname, int flags, ...) |
489 | { |
490 | static open_funcptr_t func = NULL; |
491 | mode_t mode = 0; |
492 | va_list args; |
493 | int fd; |
494 | |
495 | if (!func) |
496 | func = (open_funcptr_t) dlsym (REAL_LIBC, "open"); |
497 | |
498 | if (flags & O_CREAT) { |
499 | va_start(args, flags); |
500 | mode = va_arg(args, mode_t); |
501 | va_end(args); |
502 | } |
503 | |
cdc711dc |
504 | if (!strcmp (pathname, "/dev/windrvr6")) { |
505 | fprintf(stderr,"opening windrvr6\n"); |
795992ad |
506 | #ifdef NO_WINDRVR |
01b99d52 |
507 | windrvrfd = fd = (*func) ("/dev/null", flags, mode); |
508 | #else |
509 | windrvrfd = fd = (*func) (pathname, flags, mode); |
510 | #endif |
f10480d1 |
511 | if (!busses) { |
512 | usb_init(); |
513 | usb_find_busses(); |
514 | usb_find_devices(); |
515 | |
516 | busses = usb_get_busses(); |
517 | } |
01b99d52 |
518 | } else { |
519 | fd = (*func) (pathname, flags, mode); |
cdc711dc |
520 | } |
521 | |
522 | return fd; |
523 | } |
524 | |
525 | void diff(unsigned char *buf1, unsigned char *buf2, int len) { |
526 | int i; |
527 | |
528 | for(i=0; i<len; i++) { |
529 | if (buf1[i] != buf2[i]) { |
530 | fprintf(stderr,"Diff at %d: %02x(%c)->%02x(%c)\n", i, buf1[i], ((buf1[i] >= 31 && buf1[i] <= 126)?buf1[i]:'.'), buf2[i], ((buf2[i] >= 31 && buf2[i] <= 126)?buf2[i]:'.')); |
531 | } |
532 | } |
533 | } |
534 | |
535 | void hexdump(unsigned char *buf, int len) { |
536 | int i; |
537 | |
538 | for(i=0; i<len; i++) { |
539 | fprintf(stderr,"%02x ", buf[i]); |
540 | if ((i % 16) == 15) |
541 | fprintf(stderr,"\n"); |
542 | } |
543 | } |
544 | |
545 | int ioctl(int fd, int request, ...) |
546 | { |
cdc711dc |
547 | va_list args; |
548 | void *argp; |
cdc711dc |
549 | int ret; |
550 | |
9c9fd67c |
551 | if (!ioctl_func) |
552 | ioctl_func = (int (*) (int, int, void *)) dlsym (REAL_LIBC, "ioctl"); |
cdc711dc |
553 | |
554 | va_start (args, request); |
555 | argp = va_arg (args, void *); |
556 | va_end (args); |
557 | |
9c9fd67c |
558 | if (fd == windrvrfd) |
559 | ret = do_wdioctl(fd, request, argp); |
560 | else |
561 | ret = (*ioctl_func) (fd, request, argp); |
cdc711dc |
562 | |
cdc711dc |
563 | return ret; |
564 | } |
565 | |
da3ba95a |
566 | #if 0 |
cdc711dc |
567 | void *mmap(void *start, size_t length, int prot, int flags, int fd, off_t offset) |
568 | { |
569 | static void* (*func) (void *, size_t, int, int, int, off_t) = NULL; |
570 | void *ret; |
571 | |
572 | if (!func) |
573 | func = (void* (*) (void *, size_t, int, int, int, off_t)) dlsym (REAL_LIBC, "mmap"); |
574 | |
575 | ret = (*func) (start, length, prot, flags, fd, offset); |
576 | fprintf(stderr,"MMAP: %x, %d, %d, %d, %d, %d -> %x\n", (unsigned int)start, length, prot, flags, fd, offset, (unsigned int)ret); |
577 | mmapped = ret; |
578 | mmapplen = length; |
579 | |
580 | return ret; |
581 | } |
582 | |
583 | void *mmap64(void *start, size_t length, int prot, int flags, int fd, off64_t offset) |
584 | { |
585 | static void* (*func) (void *, size_t, int, int, int, off64_t) = NULL; |
586 | void *ret; |
587 | |
588 | if (!func) |
589 | func = (void* (*) (void *, size_t, int, int, int, off64_t)) dlsym (REAL_LIBC, "mmap64"); |
590 | |
591 | ret = (*func) (start, length, prot, flags, fd, offset); |
592 | fprintf(stderr,"MMAP64: %x, %d, %d, %d, %d, %lld -> %x\n", (unsigned int)start, length, prot, flags, fd, offset, (unsigned int)ret); |
593 | mmapped = ret; |
594 | mmapplen = length; |
595 | |
596 | return ret; |
597 | } |
598 | |
599 | void *mmap2(void *start, size_t length, int prot, int flags, int fd, off_t pgoffset) |
600 | { |
601 | static void* (*func) (void *, size_t, int, int, int, off_t) = NULL; |
602 | void *ret; |
603 | |
604 | if (!func) |
605 | func = (void* (*) (void *, size_t, int, int, int, off_t)) dlsym (REAL_LIBC, "mmap2"); |
606 | |
607 | ret = (*func) (start, length, prot, flags, fd, pgoffset); |
608 | fprintf(stderr,"MMAP2: %x, %d, %d, %d, %d, %d -> %x\n", (unsigned int)start, length, prot, flags, fd, pgoffset, (unsigned int)ret); |
609 | mmapped = ret; |
610 | mmapplen = length; |
611 | |
612 | return ret; |
613 | } |
614 | |
615 | void *malloc(size_t size) |
616 | { |
617 | static void* (*func) (size_t) = NULL; |
618 | void *ret; |
619 | |
620 | if (!func) |
621 | func = (void* (*) (size_t)) dlsym(REAL_LIBC, "malloc"); |
622 | |
623 | ret = (*func) (size); |
624 | |
625 | //fprintf(stderr,"MALLOC: %d -> %x\n", size, (unsigned int) ret); |
626 | |
627 | return ret; |
628 | } |
da3ba95a |
629 | #endif |
cdc711dc |
630 | |
631 | |
632 | #endif |