]> git.zerfleddert.de Git - usb-driver/blame_incremental - usb-driver.c
config descriptor
[usb-driver] / usb-driver.c
... / ...
CommitLineData
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>
21#include <usb.h>
22#include "xilinx.h"
23
24static int (*ioctl_func) (int, int, void *) = NULL;
25static int windrvrfd = 0;
26static struct usb_bus *busses = NULL;
27static struct usb_device *usb_cable;
28static unsigned long card_type;
29
30#define USE_LIBUSB 1
31
32void hexdump(unsigned char *buf, int len);
33void diff(unsigned char *buf1, unsigned char *buf2, int len);
34
35int do_wdioctl(int fd, unsigned int request, unsigned char *wdioctl) {
36 struct header_struct* wdheader = (struct header_struct*)wdioctl;
37 struct version_struct *version;
38 int ret = 0;
39
40 if (wdheader->magic != MAGIC) {
41 fprintf(stderr,"!!!ERROR: magic header does not match!!!\n");
42 return (*ioctl_func) (fd, request, wdioctl);
43 }
44
45 switch(request) {
46 case VERSION:
47 version = (struct version_struct*)(wdheader->data);
48 strcpy(version->version, "WinDriver no more");
49 version->versionul = 999;
50 fprintf(stderr,"faking VERSION\n");
51 break;
52
53 case LICENSE:
54 fprintf(stderr,"faking LICENSE\n");
55 break;
56
57 case CARD_REGISTER:
58 {
59 //struct card_register* cr = (struct card_register*)(wdheader->data);
60 /* Todo: LPT-Port already in use */
61 }
62 fprintf(stderr,"faking CARD_REGISTER\n");
63 break;
64
65 case USB_TRANSFER:
66 fprintf(stderr,"in USB_TRANSFER");
67 {
68 struct usb_transfer *ut = (struct usb_transfer*)(wdheader->data);
69
70 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);
71 fprintf(stderr,"setup packet: ");
72 hexdump(ut->SetupPacket, 8);
73 fprintf(stderr,"\n");
74 if (!ut->fRead && ut->dwBufferSize)
75 {
76 hexdump(ut->pBuffer, ut->dwBufferSize);
77 fprintf(stderr,"\n");
78 }
79
80#ifndef USE_LIBUSB
81 ret = (*ioctl_func) (fd, request, wdioctl);
82#endif
83
84 fprintf(stderr,"Transferred: %lu (%s)\n",ut->dwBytesTransferred, (ut->fRead?"read":"write"));
85 if (ut->fRead && ut->dwBytesTransferred)
86 {
87 fprintf(stderr,"Read: ");
88 hexdump(ut->pBuffer, ut->dwBytesTransferred);
89 }
90 fprintf(stderr,"\n");
91 }
92 break;
93
94 case INT_ENABLE:
95 fprintf(stderr,"faking INT_ENABLE");
96 {
97 struct interrupt *it = (struct interrupt*)(wdheader->data);
98
99 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);
100
101 it->fEnableOk = 1;
102 //ret = (*ioctl_func) (fd, request, wdioctl);
103 }
104
105 break;
106
107 case INT_DISABLE:
108 fprintf(stderr,"INT_DISABLE\n");
109 {
110 struct interrupt *it = (struct interrupt*)(wdheader->data);
111
112 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);
113#ifndef USE_LIBUSB
114 ret = (*ioctl_func) (fd, request, wdioctl);
115#else
116 it->dwCounter = 0;
117 it->fStopped = 1;
118#endif
119 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);
120 }
121 break;
122
123 case USB_SET_INTERFACE:
124 fprintf(stderr,"USB_SET_INTERFACE\n");
125 {
126 struct usb_set_interface *usi = (struct usb_set_interface*)(wdheader->data);
127
128 fprintf(stderr,"unique: %lu, interfacenum: %lu, alternatesetting: %lu, options: %lx\n", usi->dwUniqueID, usi->dwInterfaceNum, usi->dwAlternateSetting, usi->dwOptions);
129#ifndef USE_LIBUSB
130 ret = (*ioctl_func) (fd, request, wdioctl);
131#endif
132 }
133 break;
134
135 case USB_GET_DEVICE_DATA:
136 fprintf(stderr,"USB_GET_DEVICE_DATA\n");
137 {
138 struct usb_get_device_data *ugdd = (struct usb_get_device_data*)(wdheader->data);
139 int pSize;
140
141 fprintf(stderr, "unique: %lu, bytes: %lu, options: %lx\n", ugdd->dwUniqueID, ugdd->dwBytes, ugdd->dwOptions);
142 pSize = ugdd->dwBytes;
143 if (pSize) {
144 hexdump(ugdd->pBuf, pSize);
145 }
146#ifndef USE_LIBUSB
147 ret = (*ioctl_func) (fd, request, wdioctl);
148#else
149 if (!ugdd->dwBytes) {
150 if (usb_cable) {
151 ugdd->dwBytes = sizeof(struct usb_device_info) - 8 + (sizeof(WDU_CONFIGURATION)*2) + sizeof(WDU_INTERFACE) * 6;
152 /* TODO: Fixme */
153 ugdd->dwBytes = 276;
154 }
155 } else {
156 struct usb_device_info_get *udi = (struct usb_device_info_get*)ugdd->pBuf;
157 struct usb_endpoint_descriptor *ep;
158unsigned char dings[] = {0x12, 0x01, 0x00, 0x02, 0x00, 0x00, 0x00, 0x40, 0xfd, 0x03, 0x08, 0x00, 0x00, 0x00, 0x01, 0x02,
1590x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1600x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x45, 0x21, 0x08, 0x38, 0x45, 0x21, 0x08,
1610x4c, 0x45, 0x21, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1620x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1630x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1640x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1650x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1660x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1670x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1680x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x02, 0x20, 0x00, 0x01, 0x02, 0x00, 0x80,
1690x8c, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x4c, 0x45, 0x21, 0x08, 0x58, 0x45, 0x21, 0x08,
1700x01, 0x00, 0x00, 0x00, 0x58, 0x45, 0x21, 0x08, 0x09, 0x04, 0x00, 0x00, 0x02, 0xff, 0x00, 0x00,
1710x00, 0x00, 0x00, 0x00, 0x6c, 0x45, 0x21, 0x08, 0x7c, 0x45, 0x21, 0x08, 0x07, 0x05, 0x02, 0x02,
1720x00, 0x02, 0x00, 0x00, 0x07, 0x05, 0x86, 0x02, 0x00, 0x02, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
1730x00, 0x02, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1740x86, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
1750x00, 0x00, 0x00, 0x00};
176
177//unique: 94, bytes: 276, options: 0
178//Vendor: 3fd
179//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
180//00 01 00 00 00 00 00 00 40 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00
181//03 00 00 00 00 00 00 00 38 45 21 08 38 45 21 08 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
182//4c 45 21 08 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
183//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
184//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
185//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
186//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
187//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
188//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
189//00 00 00 00 00 00 00 00 09 02 20 00 01 02 00 80 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
190//8c 00 00 00 01 00 00 00 4c 45 21 08 58 45 21 08 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
191//01 00 00 00 58 45 21 08 09 04 00 00 02 ff 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
192//00 00 00 00 6c 45 21 08 7c 45 21 08 07 05 02 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
193//00 02 00 00 07 05 86 02 00 02 00 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
194//00 02 00 00 02 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
195//86 00 00 00 00 02 00 00 02 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
196//00 00 00 00 00 00 00 00
197
198 bzero(udi, ugdd->dwBytes);
199 //memcpy(udi, dings, 276);
200 udi->Descriptor.bLength = sizeof(WDU_DEVICE_DESCRIPTOR);
201 udi->Descriptor.bDescriptorType = usb_cable->descriptor.bDescriptorType;
202 udi->Descriptor.bcdUSB = usb_cable->descriptor.bcdUSB;
203 udi->Descriptor.bDeviceClass = usb_cable->descriptor.bDeviceClass;
204 udi->Descriptor.bDeviceSubClass = usb_cable->descriptor.bDeviceSubClass;
205 udi->Descriptor.bDeviceProtocol = usb_cable->descriptor.bDeviceProtocol;
206 udi->Descriptor.bMaxPacketSize0 = usb_cable->descriptor.bMaxPacketSize0;
207 udi->Descriptor.idVendor = usb_cable->descriptor.idVendor;
208 udi->Descriptor.idProduct = usb_cable->descriptor.idProduct;
209 udi->Descriptor.bcdDevice = usb_cable->descriptor.bcdDevice;
210 udi->Descriptor.iManufacturer = usb_cable->descriptor.iManufacturer;
211 udi->Descriptor.iProduct = usb_cable->descriptor.iProduct;
212 udi->Descriptor.iSerialNumber = usb_cable->descriptor.iSerialNumber;
213 udi->Descriptor.bNumConfigurations = usb_cable->descriptor.bNumConfigurations;
214
215 ep = usb_cable->config->interface->altsetting[0].endpoint;
216
217 udi->Pipe0.dwNumber = 0x00;
218 udi->Pipe0.dwMaximumPacketSize = usb_cable->descriptor.bMaxPacketSize0;
219 udi->Pipe0.type = 0;
220 udi->Pipe0.direction = 3;
221 udi->Pipe0.dwInterval = 0;
222
223 udi->cfg.Descriptor.bLength = usb_cable->config->bLength;
224 udi->cfg.Descriptor.bDescriptorType = usb_cable->config->bDescriptorType;
225 udi->cfg.Descriptor.wTotalLength = usb_cable->config->wTotalLength;
226 udi->cfg.Descriptor.bNumInterfaces = usb_cable->config->bNumInterfaces;
227 udi->cfg.Descriptor.bConfigurationValue = usb_cable->config->bConfigurationValue;
228 udi->cfg.Descriptor.iConfiguration = usb_cable->config->iConfiguration;
229 udi->cfg.Descriptor.bmAttributes = usb_cable->config->bmAttributes;
230 udi->cfg.Descriptor.MaxPower = usb_cable->config->MaxPower;
231
232 // ab offset 168 config desc
233 }
234#endif
235 if (pSize) {
236 struct usb_device_info *udi = (struct usb_device_info*)ugdd->pBuf;
237
238 fprintf(stderr, "Vendor: %x\n", udi->Descriptor.idVendor);
239
240 hexdump(ugdd->pBuf, pSize);
241 fprintf(stderr, "\n");
242 }
243 }
244 break;
245
246 case EVENT_REGISTER:
247 fprintf(stderr,"EVENT_REGISTER\n");
248 {
249 struct event *e = (struct event*)(wdheader->data);
250 struct usb_bus *bus;
251 int i;
252
253 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);
254 for (i = 0; i < e->dwNumMatchTables; i++) {
255 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);
256
257 for (bus = busses; bus; bus = bus->next) {
258 struct usb_device *dev;
259
260 for (dev = bus->devices; dev; dev = dev->next) {
261 struct usb_device_descriptor *desc = &(dev->descriptor);
262
263 if((desc->idVendor == e->matchTables[i].VendorId) &&
264 (desc->idProduct == e->matchTables[i].ProductId) &&
265 (desc->bDeviceClass == e->matchTables[i].bDeviceClass) &&
266 (desc->bDeviceSubClass == e->matchTables[i].bDeviceSubClass)) {
267 struct usb_interface *interface = dev->config->interface;
268 int ai;
269
270 for (ai = 0; ai < interface->num_altsetting; ai++) {
271 fprintf(stderr, "intclass: %x, intsubclass: %x, intproto: %x\n", interface->altsetting[i].bInterfaceClass, interface->altsetting[i].bInterfaceSubClass, interface->altsetting[i].bInterfaceProtocol);
272 if ((interface->altsetting[i].bInterfaceSubClass == e->matchTables[i].bInterfaceSubClass) &&
273 (interface->altsetting[i].bInterfaceProtocol == e->matchTables[i].bInterfaceProtocol)){
274 /* TODO: check interfaceClass! */
275 fprintf(stderr,"!!!FOUND DEVICE WITH LIBUSB!!!\n");
276 usb_cable = dev;
277 card_type = e->dwCardType;
278 }
279 }
280 }
281 }
282 }
283 }
284
285#ifndef USE_LIBUSB
286 ret = (*ioctl_func) (fd, request, wdioctl);
287#endif
288
289 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);
290 for (i = 0; i < e->dwNumMatchTables; i++)
291 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);
292 }
293 break;
294
295 case TRANSFER:
296 fprintf(stderr,"TRANSFER\n");
297#ifndef USE_LIBUSB
298 ret = (*ioctl_func) (fd, request, wdioctl);
299#endif
300 break;
301
302 case EVENT_UNREGISTER:
303 fprintf(stderr,"EVENT_UNREGISTER\n");
304#ifndef USE_LIBUSB
305 ret = (*ioctl_func) (fd, request, wdioctl);
306#endif
307 break;
308
309 case INT_WAIT:
310 fprintf(stderr,"INT_WAIT\n");
311 {
312 struct interrupt *it = (struct interrupt*)(wdheader->data);
313
314 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);
315
316#ifndef USE_LIBUSB
317 ret = (*ioctl_func) (fd, request, wdioctl);
318#else
319 if (usb_cable)
320 it->dwCounter++;
321#endif
322
323 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);
324 }
325 break;
326
327 case CARD_UNREGISTER:
328 fprintf(stderr,"CARD_UNREGISTER\n");
329#ifndef USE_LIBUSB
330 ret = (*ioctl_func) (fd, request, wdioctl);
331#endif
332 break;
333
334 case EVENT_PULL:
335 fprintf(stderr,"EVENT_PULL\n");
336 {
337 struct event *e = (struct event*)(wdheader->data);
338 int i;
339
340 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);
341 for (i = 0; i < e->dwNumMatchTables; i++)
342 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);
343
344#ifndef USE_LIBUSB
345 ret = (*ioctl_func) (fd, request, wdioctl);
346#else
347//EVENT_PULL
348//handle: 1, action: 0, status: 0, eventid: 0, cardtype: 0, kplug: 0, options: 0, dev: 0:0, unique: 0, ver: 1, nummatch: 1
349//match: dev: 0:0, class: 0, subclass: 0, intclass: 0, intsubclass: 0, intproto: 0
350//handle: 1, action: 1, status: 0, eventid: 109, cardtype: 4294967294, kplug: 0, options: 0, dev: 0:0, unique: 90, ver: 1, nummatch: 1
351//match: dev: 3fd:8, class: 0, subclass: 0, intclass: ff, intsubclass: 0, intproto: 0
352 if (usb_cable) {
353 struct usb_interface *interface = usb_cable->config->interface;
354
355 e->dwCardType = card_type;
356 e->dwAction = 1;
357 e->dwEventId = 109;
358 e->u.Usb.dwUniqueID = 4711;
359 e->matchTables[0].VendorId = usb_cable->descriptor.idVendor;
360 e->matchTables[0].ProductId = usb_cable->descriptor.idProduct;
361 e->matchTables[0].bDeviceClass = usb_cable->descriptor.bDeviceClass;
362 e->matchTables[0].bDeviceSubClass = usb_cable->descriptor.bDeviceSubClass;
363 e->matchTables[0].bInterfaceClass = interface->altsetting[0].bInterfaceClass;
364 e->matchTables[0].bInterfaceSubClass = interface->altsetting[0].bInterfaceSubClass;
365 e->matchTables[0].bInterfaceProtocol = interface->altsetting[0].bInterfaceProtocol;
366 }
367#endif
368
369 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);
370 for (i = 0; i < e->dwNumMatchTables; i++)
371 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);
372 }
373 break;
374
375 default:
376 fprintf(stderr,"!!!Unsupported IOCTL: %x!!!\n", request);
377#ifndef USE_LIBUSB
378 ret = (*ioctl_func) (fd, request, wdioctl);
379#endif
380 break;
381 }
382
383 return ret;
384}
385
386
387typedef int (*open_funcptr_t) (const char *, int, mode_t);
388
389int open (const char *pathname, int flags, ...)
390{
391 static open_funcptr_t func = NULL;
392 mode_t mode = 0;
393 va_list args;
394 int fd;
395
396 if (!func)
397 func = (open_funcptr_t) dlsym (REAL_LIBC, "open");
398
399 if (flags & O_CREAT) {
400 va_start(args, flags);
401 mode = va_arg(args, mode_t);
402 va_end(args);
403 }
404
405 if (!strcmp (pathname, "/dev/windrvr6")) {
406 fprintf(stderr,"opening windrvr6\n");
407#ifdef USE_LIBUSB
408 windrvrfd = fd = (*func) ("/dev/null", flags, mode);
409#else
410 windrvrfd = fd = (*func) (pathname, flags, mode);
411#endif
412 if (!busses) {
413 usb_init();
414 usb_find_busses();
415 usb_find_devices();
416
417 busses = usb_get_busses();
418 }
419 } else {
420 fd = (*func) (pathname, flags, mode);
421 }
422
423 return fd;
424}
425
426void diff(unsigned char *buf1, unsigned char *buf2, int len) {
427 int i;
428
429 for(i=0; i<len; i++) {
430 if (buf1[i] != buf2[i]) {
431 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]:'.'));
432 }
433 }
434}
435
436void hexdump(unsigned char *buf, int len) {
437 int i;
438
439 for(i=0; i<len; i++) {
440 fprintf(stderr,"%02x ", buf[i]);
441 if ((i % 16) == 15)
442 fprintf(stderr,"\n");
443 }
444}
445
446int ioctl(int fd, int request, ...)
447{
448 va_list args;
449 void *argp;
450 int ret;
451
452 if (!ioctl_func)
453 ioctl_func = (int (*) (int, int, void *)) dlsym (REAL_LIBC, "ioctl");
454
455 va_start (args, request);
456 argp = va_arg (args, void *);
457 va_end (args);
458
459 if (fd == windrvrfd)
460 ret = do_wdioctl(fd, request, argp);
461 else
462 ret = (*ioctl_func) (fd, request, argp);
463
464 return ret;
465}
466
467#if 0
468void *mmap(void *start, size_t length, int prot, int flags, int fd, off_t offset)
469{
470 static void* (*func) (void *, size_t, int, int, int, off_t) = NULL;
471 void *ret;
472
473 if (!func)
474 func = (void* (*) (void *, size_t, int, int, int, off_t)) dlsym (REAL_LIBC, "mmap");
475
476 ret = (*func) (start, length, prot, flags, fd, offset);
477 fprintf(stderr,"MMAP: %x, %d, %d, %d, %d, %d -> %x\n", (unsigned int)start, length, prot, flags, fd, offset, (unsigned int)ret);
478 mmapped = ret;
479 mmapplen = length;
480
481 return ret;
482}
483
484void *mmap64(void *start, size_t length, int prot, int flags, int fd, off64_t offset)
485{
486 static void* (*func) (void *, size_t, int, int, int, off64_t) = NULL;
487 void *ret;
488
489 if (!func)
490 func = (void* (*) (void *, size_t, int, int, int, off64_t)) dlsym (REAL_LIBC, "mmap64");
491
492 ret = (*func) (start, length, prot, flags, fd, offset);
493 fprintf(stderr,"MMAP64: %x, %d, %d, %d, %d, %lld -> %x\n", (unsigned int)start, length, prot, flags, fd, offset, (unsigned int)ret);
494 mmapped = ret;
495 mmapplen = length;
496
497 return ret;
498}
499
500void *mmap2(void *start, size_t length, int prot, int flags, int fd, off_t pgoffset)
501{
502 static void* (*func) (void *, size_t, int, int, int, off_t) = NULL;
503 void *ret;
504
505 if (!func)
506 func = (void* (*) (void *, size_t, int, int, int, off_t)) dlsym (REAL_LIBC, "mmap2");
507
508 ret = (*func) (start, length, prot, flags, fd, pgoffset);
509 fprintf(stderr,"MMAP2: %x, %d, %d, %d, %d, %d -> %x\n", (unsigned int)start, length, prot, flags, fd, pgoffset, (unsigned int)ret);
510 mmapped = ret;
511 mmapplen = length;
512
513 return ret;
514}
515
516void *malloc(size_t size)
517{
518 static void* (*func) (size_t) = NULL;
519 void *ret;
520
521 if (!func)
522 func = (void* (*) (size_t)) dlsym(REAL_LIBC, "malloc");
523
524 ret = (*func) (size);
525
526 //fprintf(stderr,"MALLOC: %d -> %x\n", size, (unsigned int) ret);
527
528 return ret;
529}
530#endif
531
532
533#endif
Impressum, Datenschutz