]>
git.zerfleddert.de Git - usb-driver/blob - usb-driver.c
a5fae9bdd22b7160d0b7ce69ae19c1cacb19c538
1 #if defined(__GNUC__) && !defined(__STRICT_ANSI__)
6 #define REAL_LIBC RTLD_NEXT
8 #define REAL_LIBC ((void *) -1L)
17 #include <sys/types.h>
24 static int (*ioctl_func
) (int, int, void *) = NULL
;
25 static int windrvrfd
= 0;
26 static struct usb_bus
*busses
= NULL
;
27 static struct usb_device
*usb_cable
;
28 static unsigned long card_type
;
32 void hexdump(unsigned char *buf
, int len
);
33 void diff(unsigned char *buf1
, unsigned char *buf2
, int len
);
35 int usb_deviceinfo(unsigned char *buf
) {
40 struct usb_device_info
*udi
= (struct usb_device_info
*)(buf
+len
);
42 udi
->Descriptor
.bLength
= sizeof(WDU_DEVICE_DESCRIPTOR
);
43 udi
->Descriptor
.bDescriptorType
= usb_cable
->descriptor
.bDescriptorType
;
44 udi
->Descriptor
.bcdUSB
= usb_cable
->descriptor
.bcdUSB
;
45 udi
->Descriptor
.bDeviceClass
= usb_cable
->descriptor
.bDeviceClass
;
46 udi
->Descriptor
.bDeviceSubClass
= usb_cable
->descriptor
.bDeviceSubClass
;
47 udi
->Descriptor
.bDeviceProtocol
= usb_cable
->descriptor
.bDeviceProtocol
;
48 udi
->Descriptor
.bMaxPacketSize0
= usb_cable
->descriptor
.bMaxPacketSize0
;
49 udi
->Descriptor
.idVendor
= usb_cable
->descriptor
.idVendor
;
50 udi
->Descriptor
.idProduct
= usb_cable
->descriptor
.idProduct
;
51 udi
->Descriptor
.bcdDevice
= usb_cable
->descriptor
.bcdDevice
;
52 udi
->Descriptor
.iManufacturer
= usb_cable
->descriptor
.iManufacturer
;
53 udi
->Descriptor
.iProduct
= usb_cable
->descriptor
.iProduct
;
54 udi
->Descriptor
.iSerialNumber
= usb_cable
->descriptor
.iSerialNumber
;
55 udi
->Descriptor
.bNumConfigurations
= usb_cable
->descriptor
.bNumConfigurations
;
57 /* TODO: Fix Pipe0! */
58 udi
->Pipe0
.dwNumber
= 0x00;
59 udi
->Pipe0
.dwMaximumPacketSize
= usb_cable
->descriptor
.bMaxPacketSize0
;
61 udi
->Pipe0
.direction
= 3;
62 udi
->Pipe0
.dwInterval
= 0;
65 len
= sizeof(struct usb_device_info
);
67 for (i
=0; i
<usb_cable
->descriptor
.bNumConfigurations
; i
++)
69 struct usb_config_descriptor
*conf_desc
= &usb_cable
->config
[i
];
71 WDU_CONFIGURATION
*cfg
= (WDU_CONFIGURATION
*)(buf
+len
);
73 cfg
->Descriptor
.bLength
= conf_desc
->bLength
;
74 cfg
->Descriptor
.bDescriptorType
= conf_desc
->bDescriptorType
;
75 cfg
->Descriptor
.wTotalLength
= conf_desc
->wTotalLength
;
76 cfg
->Descriptor
.bNumInterfaces
= conf_desc
->bNumInterfaces
;
77 cfg
->Descriptor
.bConfigurationValue
= conf_desc
->bConfigurationValue
;
78 cfg
->Descriptor
.iConfiguration
= conf_desc
->iConfiguration
;
79 cfg
->Descriptor
.bmAttributes
= conf_desc
->bmAttributes
;
80 cfg
->Descriptor
.MaxPower
= conf_desc
->MaxPower
;
82 cfg
->dwNumInterfaces
= conf_desc
->bNumInterfaces
;
84 len
+= sizeof(WDU_CONFIGURATION
);
86 for (j
=0; j
<conf_desc
->bNumInterfaces
; j
++) {
87 WDU_INTERFACE
*iface
= (WDU_INTERFACE
*)(buf
+len
);
88 iface
->dwNumAltSettings
= usb_cable
->config
[i
].interface
[j
].num_altsetting
;
90 len
+= sizeof(WDU_INTERFACE
);
93 len
+= sizeof(WDU_INTERFACE
) * conf_desc
->bNumInterfaces
;
96 for (j
=0; j
<conf_desc
->bNumInterfaces
; j
++)
98 struct usb_interface
*interface
= &usb_cable
->config
[i
].interface
[j
];
99 for(k
=0; k
<interface
->num_altsetting
; k
++)
101 unsigned char bNumEndpoints
;
102 bNumEndpoints
= interface
->altsetting
[k
].bNumEndpoints
;
104 WDU_ALTERNATE_SETTING
*altset
= (WDU_ALTERNATE_SETTING
*)(buf
+len
);
106 altset
->Descriptor
.bLength
= interface
->altsetting
[k
].bLength
;
107 altset
->Descriptor
.bDescriptorType
= interface
->altsetting
[k
].bDescriptorType
;
108 altset
->Descriptor
.bInterfaceNumber
= interface
->altsetting
[k
].bInterfaceNumber
;
109 altset
->Descriptor
.bAlternateSetting
= interface
->altsetting
[k
].bAlternateSetting
;
110 altset
->Descriptor
.bNumEndpoints
= interface
->altsetting
[k
].bNumEndpoints
;
111 altset
->Descriptor
.bInterfaceClass
= interface
->altsetting
[k
].bInterfaceClass
;
112 altset
->Descriptor
.bInterfaceSubClass
= interface
->altsetting
[k
].bInterfaceSubClass
;
113 altset
->Descriptor
.bInterfaceProtocol
= interface
->altsetting
[k
].bInterfaceProtocol
;
114 altset
->Descriptor
.iInterface
= interface
->altsetting
[k
].iInterface
;
117 len
+=sizeof(WDU_ALTERNATE_SETTING
);
120 for (l
= 0; l
< bNumEndpoints
; l
++) {
121 WDU_ENDPOINT_DESCRIPTOR
*ed
= (WDU_ENDPOINT_DESCRIPTOR
*)(buf
+len
);
124 ed
->bLength
= interface
->altsetting
[k
].endpoint
[l
].bLength
;
125 ed
->bDescriptorType
= interface
->altsetting
[k
].endpoint
[l
].bDescriptorType
;
126 ed
->bEndpointAddress
= interface
->altsetting
[k
].endpoint
[l
].bEndpointAddress
;
127 ed
->bmAttributes
= interface
->altsetting
[k
].endpoint
[l
].bmAttributes
;
128 ed
->wMaxPacketSize
= interface
->altsetting
[k
].endpoint
[l
].wMaxPacketSize
;
129 ed
->bInterval
= interface
->altsetting
[k
].endpoint
[l
].bInterval
;
131 len
+= sizeof(WDU_ENDPOINT_DESCRIPTOR
);
133 pi
= (WDU_PIPE_INFO
*)(buf
+len
);
135 pi
->dwNumber
= interface
->altsetting
[k
].endpoint
[l
].bEndpointAddress
;
136 pi
->dwMaximumPacketSize
= WDU_GET_MAX_PACKET_SIZE(interface
->altsetting
[k
].endpoint
[l
].wMaxPacketSize
);
137 pi
->type
= interface
->altsetting
[k
].endpoint
[l
].bmAttributes
& USB_ENDPOINT_TYPE_MASK
;
138 if (pi
->type
== PIPE_TYPE_CONTROL
)
139 pi
->direction
= WDU_DIR_IN_OUT
;
142 pi
->direction
= interface
->altsetting
[k
].endpoint
[l
].bEndpointAddress
& USB_ENDPOINT_DIR_MASK
? WDU_DIR_IN
: WDU_DIR_OUT
;
145 pi
->dwInterval
= interface
->altsetting
[k
].endpoint
[l
].bInterval
;
147 len
+= sizeof(WDU_PIPE_INFO
);
150 len
+=(sizeof(WDU_ENDPOINT_DESCRIPTOR
)+sizeof(WDU_PIPE_INFO
))*bNumEndpoints
;
159 int do_wdioctl(int fd
, unsigned int request
, unsigned char *wdioctl
) {
160 struct header_struct
* wdheader
= (struct header_struct
*)wdioctl
;
161 struct version_struct
*version
;
164 if (wdheader
->magic
!= MAGIC
) {
165 fprintf(stderr
,"!!!ERROR: magic header does not match!!!\n");
166 return (*ioctl_func
) (fd
, request
, wdioctl
);
171 version
= (struct version_struct
*)(wdheader
->data
);
172 strcpy(version
->version
, "WinDriver no more");
173 version
->versionul
= 999;
174 fprintf(stderr
,"faking VERSION\n");
178 fprintf(stderr
,"faking LICENSE\n");
183 //struct card_register* cr = (struct card_register*)(wdheader->data);
184 /* Todo: LPT-Port already in use */
186 fprintf(stderr
,"faking CARD_REGISTER\n");
190 fprintf(stderr
,"in USB_TRANSFER");
192 struct usb_transfer
*ut
= (struct usb_transfer
*)(wdheader
->data
);
194 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
);
195 fprintf(stderr
,"setup packet: ");
196 hexdump(ut
->SetupPacket
, 8);
197 fprintf(stderr
,"\n");
198 if (!ut
->fRead
&& ut
->dwBufferSize
)
200 hexdump(ut
->pBuffer
, ut
->dwBufferSize
);
201 fprintf(stderr
,"\n");
205 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
208 fprintf(stderr
,"Transferred: %lu (%s)\n",ut
->dwBytesTransferred
, (ut
->fRead
?"read":"write"));
209 if (ut
->fRead
&& ut
->dwBytesTransferred
)
211 fprintf(stderr
,"Read: ");
212 hexdump(ut
->pBuffer
, ut
->dwBytesTransferred
);
214 fprintf(stderr
,"\n");
219 fprintf(stderr
,"faking INT_ENABLE");
221 struct interrupt
*it
= (struct interrupt
*)(wdheader
->data
);
223 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
);
226 //ret = (*ioctl_func) (fd, request, wdioctl);
232 fprintf(stderr
,"INT_DISABLE\n");
234 struct interrupt
*it
= (struct interrupt
*)(wdheader
->data
);
236 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
);
238 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
243 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
);
247 case USB_SET_INTERFACE
:
248 fprintf(stderr
,"USB_SET_INTERFACE\n");
250 struct usb_set_interface
*usi
= (struct usb_set_interface
*)(wdheader
->data
);
252 fprintf(stderr
,"unique: %lu, interfacenum: %lu, alternatesetting: %lu, options: %lx\n", usi
->dwUniqueID
, usi
->dwInterfaceNum
, usi
->dwAlternateSetting
, usi
->dwOptions
);
254 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
259 case USB_GET_DEVICE_DATA
:
260 fprintf(stderr
,"USB_GET_DEVICE_DATA\n");
262 struct usb_get_device_data
*ugdd
= (struct usb_get_device_data
*)(wdheader
->data
);
265 fprintf(stderr
, "unique: %lu, bytes: %lu, options: %lx\n", ugdd
->dwUniqueID
, ugdd
->dwBytes
, ugdd
->dwOptions
);
266 pSize
= ugdd
->dwBytes
;
268 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
270 if (!ugdd
->dwBytes
) {
272 ugdd
->dwBytes
= usb_deviceinfo(NULL
);
275 //unique: 94, bytes: 276, options: 0
277 //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
278 //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
279 //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
280 //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
281 //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
282 //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
283 //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
284 //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
285 //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
286 //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
287 //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
288 //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
289 //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
290 //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
291 //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
292 //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
293 //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
294 //00 00 00 00 00 00 00 00
296 usb_deviceinfo((unsigned char*)ugdd
->pBuf
);
300 struct usb_device_info
*udi
= (struct usb_device_info
*)ugdd
->pBuf
;
302 fprintf(stderr
, "Vendor: %x\n", udi
->Descriptor
.idVendor
);
304 hexdump(ugdd
->pBuf
, pSize
);
305 fprintf(stderr
, "\n");
311 fprintf(stderr
,"EVENT_REGISTER\n");
313 struct event
*e
= (struct event
*)(wdheader
->data
);
317 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
);
318 for (i
= 0; i
< e
->dwNumMatchTables
; i
++) {
319 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
);
321 for (bus
= busses
; bus
; bus
= bus
->next
) {
322 struct usb_device
*dev
;
324 for (dev
= bus
->devices
; dev
; dev
= dev
->next
) {
325 struct usb_device_descriptor
*desc
= &(dev
->descriptor
);
327 if((desc
->idVendor
== e
->matchTables
[i
].VendorId
) &&
328 (desc
->idProduct
== e
->matchTables
[i
].ProductId
) &&
329 (desc
->bDeviceClass
== e
->matchTables
[i
].bDeviceClass
) &&
330 (desc
->bDeviceSubClass
== e
->matchTables
[i
].bDeviceSubClass
)) {
331 struct usb_interface
*interface
= dev
->config
->interface
;
334 for (ai
= 0; ai
< interface
->num_altsetting
; ai
++) {
335 fprintf(stderr
, "intclass: %x, intsubclass: %x, intproto: %x\n", interface
->altsetting
[i
].bInterfaceClass
, interface
->altsetting
[i
].bInterfaceSubClass
, interface
->altsetting
[i
].bInterfaceProtocol
);
336 if ((interface
->altsetting
[i
].bInterfaceSubClass
== e
->matchTables
[i
].bInterfaceSubClass
) &&
337 (interface
->altsetting
[i
].bInterfaceProtocol
== e
->matchTables
[i
].bInterfaceProtocol
)){
338 /* TODO: check interfaceClass! */
339 fprintf(stderr
,"!!!FOUND DEVICE WITH LIBUSB!!!\n");
341 card_type
= e
->dwCardType
;
350 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
353 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
);
354 for (i
= 0; i
< e
->dwNumMatchTables
; i
++)
355 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
);
360 fprintf(stderr
,"TRANSFER\n");
362 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
366 case EVENT_UNREGISTER
:
367 fprintf(stderr
,"EVENT_UNREGISTER\n");
369 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
374 fprintf(stderr
,"INT_WAIT\n");
376 struct interrupt
*it
= (struct interrupt
*)(wdheader
->data
);
378 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
);
381 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
387 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
);
391 case CARD_UNREGISTER
:
392 fprintf(stderr
,"CARD_UNREGISTER\n");
394 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
399 fprintf(stderr
,"EVENT_PULL\n");
401 struct event
*e
= (struct event
*)(wdheader
->data
);
404 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
);
405 for (i
= 0; i
< e
->dwNumMatchTables
; i
++)
406 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
);
409 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
412 //handle: 1, action: 0, status: 0, eventid: 0, cardtype: 0, kplug: 0, options: 0, dev: 0:0, unique: 0, ver: 1, nummatch: 1
413 //match: dev: 0:0, class: 0, subclass: 0, intclass: 0, intsubclass: 0, intproto: 0
414 //handle: 1, action: 1, status: 0, eventid: 109, cardtype: 4294967294, kplug: 0, options: 0, dev: 0:0, unique: 90, ver: 1, nummatch: 1
415 //match: dev: 3fd:8, class: 0, subclass: 0, intclass: ff, intsubclass: 0, intproto: 0
417 struct usb_interface
*interface
= usb_cable
->config
->interface
;
419 e
->dwCardType
= card_type
;
422 e
->u
.Usb
.dwUniqueID
= 4711;
423 e
->matchTables
[0].VendorId
= usb_cable
->descriptor
.idVendor
;
424 e
->matchTables
[0].ProductId
= usb_cable
->descriptor
.idProduct
;
425 e
->matchTables
[0].bDeviceClass
= usb_cable
->descriptor
.bDeviceClass
;
426 e
->matchTables
[0].bDeviceSubClass
= usb_cable
->descriptor
.bDeviceSubClass
;
427 e
->matchTables
[0].bInterfaceClass
= interface
->altsetting
[0].bInterfaceClass
;
428 e
->matchTables
[0].bInterfaceSubClass
= interface
->altsetting
[0].bInterfaceSubClass
;
429 e
->matchTables
[0].bInterfaceProtocol
= interface
->altsetting
[0].bInterfaceProtocol
;
433 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
);
434 for (i
= 0; i
< e
->dwNumMatchTables
; i
++)
435 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
);
440 fprintf(stderr
,"!!!Unsupported IOCTL: %x!!!\n", request
);
442 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
451 typedef int (*open_funcptr_t
) (const char *, int, mode_t
);
453 int open (const char *pathname
, int flags
, ...)
455 static open_funcptr_t func
= NULL
;
461 func
= (open_funcptr_t
) dlsym (REAL_LIBC
, "open");
463 if (flags
& O_CREAT
) {
464 va_start(args
, flags
);
465 mode
= va_arg(args
, mode_t
);
469 if (!strcmp (pathname
, "/dev/windrvr6")) {
470 fprintf(stderr
,"opening windrvr6\n");
472 windrvrfd
= fd
= (*func
) ("/dev/null", flags
, mode
);
474 windrvrfd
= fd
= (*func
) (pathname
, flags
, mode
);
481 busses
= usb_get_busses();
484 fd
= (*func
) (pathname
, flags
, mode
);
490 void diff(unsigned char *buf1
, unsigned char *buf2
, int len
) {
493 for(i
=0; i
<len
; i
++) {
494 if (buf1
[i
] != buf2
[i
]) {
495 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
]:'.'));
500 void hexdump(unsigned char *buf
, int len
) {
503 for(i
=0; i
<len
; i
++) {
504 fprintf(stderr
,"%02x ", buf
[i
]);
506 fprintf(stderr
,"\n");
510 int ioctl(int fd
, int request
, ...)
517 ioctl_func
= (int (*) (int, int, void *)) dlsym (REAL_LIBC
, "ioctl");
519 va_start (args
, request
);
520 argp
= va_arg (args
, void *);
524 ret
= do_wdioctl(fd
, request
, argp
);
526 ret
= (*ioctl_func
) (fd
, request
, argp
);
532 void *mmap(void *start
, size_t length
, int prot
, int flags
, int fd
, off_t offset
)
534 static void* (*func
) (void *, size_t, int, int, int, off_t
) = NULL
;
538 func
= (void* (*) (void *, size_t, int, int, int, off_t
)) dlsym (REAL_LIBC
, "mmap");
540 ret
= (*func
) (start
, length
, prot
, flags
, fd
, offset
);
541 fprintf(stderr
,"MMAP: %x, %d, %d, %d, %d, %d -> %x\n", (unsigned int)start
, length
, prot
, flags
, fd
, offset
, (unsigned int)ret
);
548 void *mmap64(void *start
, size_t length
, int prot
, int flags
, int fd
, off64_t offset
)
550 static void* (*func
) (void *, size_t, int, int, int, off64_t
) = NULL
;
554 func
= (void* (*) (void *, size_t, int, int, int, off64_t
)) dlsym (REAL_LIBC
, "mmap64");
556 ret
= (*func
) (start
, length
, prot
, flags
, fd
, offset
);
557 fprintf(stderr
,"MMAP64: %x, %d, %d, %d, %d, %lld -> %x\n", (unsigned int)start
, length
, prot
, flags
, fd
, offset
, (unsigned int)ret
);
564 void *mmap2(void *start
, size_t length
, int prot
, int flags
, int fd
, off_t pgoffset
)
566 static void* (*func
) (void *, size_t, int, int, int, off_t
) = NULL
;
570 func
= (void* (*) (void *, size_t, int, int, int, off_t
)) dlsym (REAL_LIBC
, "mmap2");
572 ret
= (*func
) (start
, length
, prot
, flags
, fd
, pgoffset
);
573 fprintf(stderr
,"MMAP2: %x, %d, %d, %d, %d, %d -> %x\n", (unsigned int)start
, length
, prot
, flags
, fd
, pgoffset
, (unsigned int)ret
);
580 void *malloc(size_t size
)
582 static void* (*func
) (size_t) = NULL
;
586 func
= (void* (*) (size_t)) dlsym(REAL_LIBC
, "malloc");
588 ret
= (*func
) (size
);
590 //fprintf(stderr,"MALLOC: %d -> %x\n", size, (unsigned int) ret);