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 #include "usb-driver.h"
26 static int (*ioctl_func
) (int, int, void *) = NULL
;
27 static int windrvrfd
= 0;
29 static int modules_read
= 0;
30 static struct usb_bus
*busses
= NULL
;
31 static struct usb_device
*usbdevice
;
32 static usb_dev_handle
*usb_devhandle
= NULL
;
33 static unsigned long card_type
;
34 static int ints_enabled
= 0;
35 static pthread_mutex_t int_wait
= PTHREAD_MUTEX_INITIALIZER
;
41 void hexdump(unsigned char *buf
, int len
) {
44 for(i
=0; i
<len
; i
++) {
45 fprintf(stderr
,"%02x ", buf
[i
]);
52 int usb_deviceinfo(unsigned char *buf
) {
55 WDU_CONFIGURATION
**pConfigs
, **pActiveConfig
;
56 WDU_INTERFACE
**pActiveInterface
;
59 struct usb_device_info
*udi
= (struct usb_device_info
*)(buf
+len
);
61 udi
->Descriptor
.bLength
= sizeof(WDU_DEVICE_DESCRIPTOR
);
62 udi
->Descriptor
.bDescriptorType
= usbdevice
->descriptor
.bDescriptorType
;
63 udi
->Descriptor
.bcdUSB
= usbdevice
->descriptor
.bcdUSB
;
64 udi
->Descriptor
.bDeviceClass
= usbdevice
->descriptor
.bDeviceClass
;
65 udi
->Descriptor
.bDeviceSubClass
= usbdevice
->descriptor
.bDeviceSubClass
;
66 udi
->Descriptor
.bDeviceProtocol
= usbdevice
->descriptor
.bDeviceProtocol
;
67 udi
->Descriptor
.bMaxPacketSize0
= usbdevice
->descriptor
.bMaxPacketSize0
;
68 udi
->Descriptor
.idVendor
= usbdevice
->descriptor
.idVendor
;
69 udi
->Descriptor
.idProduct
= usbdevice
->descriptor
.idProduct
;
70 udi
->Descriptor
.bcdDevice
= usbdevice
->descriptor
.bcdDevice
;
71 udi
->Descriptor
.iManufacturer
= usbdevice
->descriptor
.iManufacturer
;
72 udi
->Descriptor
.iProduct
= usbdevice
->descriptor
.iProduct
;
73 udi
->Descriptor
.iSerialNumber
= usbdevice
->descriptor
.iSerialNumber
;
74 udi
->Descriptor
.bNumConfigurations
= usbdevice
->descriptor
.bNumConfigurations
;
76 /* TODO: Fix Pipe0! */
77 udi
->Pipe0
.dwNumber
= 0x00;
78 udi
->Pipe0
.dwMaximumPacketSize
= usbdevice
->descriptor
.bMaxPacketSize0
;
80 udi
->Pipe0
.direction
= 3;
81 udi
->Pipe0
.dwInterval
= 0;
83 pConfigs
= &(udi
->pConfigs
);
84 pActiveConfig
= &(udi
->pActiveConfig
);
85 pActiveInterface
= &(udi
->pActiveInterface
[0]);
88 len
= sizeof(struct usb_device_info
);
90 for (i
=0; i
<usbdevice
->descriptor
.bNumConfigurations
; i
++)
92 struct usb_config_descriptor
*conf_desc
= &usbdevice
->config
[i
];
93 WDU_INTERFACE
**pInterfaces
;
94 WDU_ALTERNATE_SETTING
**pAlternateSettings
[conf_desc
->bNumInterfaces
];
95 WDU_ALTERNATE_SETTING
**pActiveAltSetting
[conf_desc
->bNumInterfaces
];
98 WDU_CONFIGURATION
*cfg
= (WDU_CONFIGURATION
*)(buf
+len
);
101 *pActiveConfig
= cfg
;
103 cfg
->Descriptor
.bLength
= conf_desc
->bLength
;
104 cfg
->Descriptor
.bDescriptorType
= conf_desc
->bDescriptorType
;
105 cfg
->Descriptor
.wTotalLength
= conf_desc
->wTotalLength
;
106 cfg
->Descriptor
.bNumInterfaces
= conf_desc
->bNumInterfaces
;
107 cfg
->Descriptor
.bConfigurationValue
= conf_desc
->bConfigurationValue
;
108 cfg
->Descriptor
.iConfiguration
= conf_desc
->iConfiguration
;
109 cfg
->Descriptor
.bmAttributes
= conf_desc
->bmAttributes
;
110 cfg
->Descriptor
.MaxPower
= conf_desc
->MaxPower
;
112 cfg
->dwNumInterfaces
= conf_desc
->bNumInterfaces
;
114 pInterfaces
= &(cfg
->pInterfaces
);
116 len
+= sizeof(WDU_CONFIGURATION
);
119 *pInterfaces
= (WDU_INTERFACE
*)(buf
+len
);
120 for (j
=0; j
<conf_desc
->bNumInterfaces
; j
++) {
121 WDU_INTERFACE
*iface
= (WDU_INTERFACE
*)(buf
+len
);
123 pActiveInterface
[j
] = iface
;
125 pAlternateSettings
[j
] = &(iface
->pAlternateSettings
);
126 iface
->dwNumAltSettings
= usbdevice
->config
[i
].interface
[j
].num_altsetting
;
127 pActiveAltSetting
[j
] = &(iface
->pActiveAltSetting
);
129 len
+= sizeof(WDU_INTERFACE
);
132 len
+= sizeof(WDU_INTERFACE
) * conf_desc
->bNumInterfaces
;
135 for (j
=0; j
<conf_desc
->bNumInterfaces
; j
++)
137 struct usb_interface
*interface
= &usbdevice
->config
[i
].interface
[j
];
140 *pAlternateSettings
[j
] = (WDU_ALTERNATE_SETTING
*)(buf
+len
);
142 *pActiveAltSetting
[j
] = (WDU_ALTERNATE_SETTING
*)(buf
+len
);
145 for(k
=0; k
<interface
->num_altsetting
; k
++)
147 unsigned char bNumEndpoints
= interface
->altsetting
[k
].bNumEndpoints
;
148 WDU_ENDPOINT_DESCRIPTOR
**pEndpointDescriptors
;
149 WDU_PIPE_INFO
**pPipes
;
152 WDU_ALTERNATE_SETTING
*altset
= (WDU_ALTERNATE_SETTING
*)(buf
+len
);
154 altset
->Descriptor
.bLength
= interface
->altsetting
[k
].bLength
;
155 altset
->Descriptor
.bDescriptorType
= interface
->altsetting
[k
].bDescriptorType
;
156 altset
->Descriptor
.bInterfaceNumber
= interface
->altsetting
[k
].bInterfaceNumber
;
157 altset
->Descriptor
.bAlternateSetting
= interface
->altsetting
[k
].bAlternateSetting
;
158 altset
->Descriptor
.bNumEndpoints
= interface
->altsetting
[k
].bNumEndpoints
;
159 altset
->Descriptor
.bInterfaceClass
= interface
->altsetting
[k
].bInterfaceClass
;
160 altset
->Descriptor
.bInterfaceSubClass
= interface
->altsetting
[k
].bInterfaceSubClass
;
161 altset
->Descriptor
.bInterfaceProtocol
= interface
->altsetting
[k
].bInterfaceProtocol
;
162 altset
->Descriptor
.iInterface
= interface
->altsetting
[k
].iInterface
;
163 pEndpointDescriptors
= &(altset
->pEndpointDescriptors
);
164 pPipes
= &(altset
->pPipes
);
167 len
+=sizeof(WDU_ALTERNATE_SETTING
);
170 *pEndpointDescriptors
= (WDU_ENDPOINT_DESCRIPTOR
*)(buf
+len
);
171 for (l
= 0; l
< bNumEndpoints
; l
++) {
172 WDU_ENDPOINT_DESCRIPTOR
*ed
= (WDU_ENDPOINT_DESCRIPTOR
*)(buf
+len
);
174 ed
->bLength
= interface
->altsetting
[k
].endpoint
[l
].bLength
;
175 ed
->bDescriptorType
= interface
->altsetting
[k
].endpoint
[l
].bDescriptorType
;
176 ed
->bEndpointAddress
= interface
->altsetting
[k
].endpoint
[l
].bEndpointAddress
;
177 ed
->bmAttributes
= interface
->altsetting
[k
].endpoint
[l
].bmAttributes
;
178 ed
->wMaxPacketSize
= interface
->altsetting
[k
].endpoint
[l
].wMaxPacketSize
;
179 ed
->bInterval
= interface
->altsetting
[k
].endpoint
[l
].bInterval
;
181 len
+= sizeof(WDU_ENDPOINT_DESCRIPTOR
);
184 *pPipes
= (WDU_PIPE_INFO
*)(buf
+len
);
185 for (l
= 0; l
< bNumEndpoints
; l
++) {
186 WDU_PIPE_INFO
*pi
= (WDU_PIPE_INFO
*)(buf
+len
);
188 pi
->dwNumber
= interface
->altsetting
[k
].endpoint
[l
].bEndpointAddress
;
189 pi
->dwMaximumPacketSize
= WDU_GET_MAX_PACKET_SIZE(interface
->altsetting
[k
].endpoint
[l
].wMaxPacketSize
);
190 pi
->type
= interface
->altsetting
[k
].endpoint
[l
].bmAttributes
& USB_ENDPOINT_TYPE_MASK
;
191 if (pi
->type
== PIPE_TYPE_CONTROL
)
192 pi
->direction
= WDU_DIR_IN_OUT
;
195 pi
->direction
= interface
->altsetting
[k
].endpoint
[l
].bEndpointAddress
& USB_ENDPOINT_DIR_MASK
? WDU_DIR_IN
: WDU_DIR_OUT
;
198 pi
->dwInterval
= interface
->altsetting
[k
].endpoint
[l
].bInterval
;
200 len
+= sizeof(WDU_PIPE_INFO
);
203 len
+=(sizeof(WDU_ENDPOINT_DESCRIPTOR
)+sizeof(WDU_PIPE_INFO
))*bNumEndpoints
;
212 int do_wdioctl(int fd
, unsigned int request
, unsigned char *wdioctl
) {
213 struct header_struct
* wdheader
= (struct header_struct
*)wdioctl
;
214 struct version_struct
*version
;
217 if (wdheader
->magic
!= MAGIC
) {
218 fprintf(stderr
,"!!!ERROR: magic header does not match!!!\n");
219 return (*ioctl_func
) (fd
, request
, wdioctl
);
224 version
= (struct version_struct
*)(wdheader
->data
);
225 strcpy(version
->version
, "WinDriver no more");
226 version
->versionul
= 999;
228 fprintf(stderr
,"faking VERSION\n");
234 fprintf(stderr
,"faking LICENSE\n");
239 /* TODO: Implement for LPT-support */
242 struct card_register
* cr
= (struct card_register
*)(wdheader
->data
);
246 fprintf(stderr
,"faking CARD_REGISTER\n");
252 fprintf(stderr
,"in USB_TRANSFER");
255 struct usb_transfer
*ut
= (struct usb_transfer
*)(wdheader
->data
);
258 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
);
259 fprintf(stderr
,"setup packet: ");
260 hexdump(ut
->SetupPacket
, 8);
261 fprintf(stderr
,"\n");
263 if (!ut
->fRead
&& ut
->dwBufferSize
)
265 hexdump(ut
->pBuffer
, ut
->dwBufferSize
);
266 fprintf(stderr
,"\n");
271 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
273 /* http://www.jungo.com/support/documentation/windriver/802/wdusb_man_mhtml/node55.html#SECTION001213000000000000000 */
274 if (ut
->dwPipeNum
== 0) { /* control pipe */
275 int requesttype
, request
, value
, index
, size
;
276 requesttype
= ut
->SetupPacket
[0];
277 request
= ut
->SetupPacket
[1];
278 value
= ut
->SetupPacket
[2] | (ut
->SetupPacket
[3] << 8);
279 index
= ut
->SetupPacket
[4] | (ut
->SetupPacket
[5] << 8);
280 size
= ut
->SetupPacket
[6] | (ut
->SetupPacket
[7] << 8);
282 fprintf(stderr
, "requesttype: %x, request: %x, value: %u, index: %u, size: %u\n", requesttype
, request
, value
, index
, size
);
284 ret
= usb_control_msg(usb_devhandle
, requesttype
, request
, value
, index
, ut
->pBuffer
, size
, ut
->dwTimeout
);
287 ret
= usb_bulk_read(usb_devhandle
, ut
->dwPipeNum
, ut
->pBuffer
, ut
->dwBufferSize
, ut
->dwTimeout
);
290 ret
= usb_bulk_write(usb_devhandle
, ut
->dwPipeNum
, ut
->pBuffer
, ut
->dwBufferSize
, ut
->dwTimeout
);
295 fprintf(stderr
, "usb_transfer: %d (%s)\n", ret
, usb_strerror());
297 ut
->dwBytesTransferred
= ret
;
303 fprintf(stderr
,"Transferred: %lu (%s)\n",ut
->dwBytesTransferred
, (ut
->fRead
?"read":"write"));
304 if (ut
->fRead
&& ut
->dwBytesTransferred
)
306 fprintf(stderr
,"Read: ");
307 hexdump(ut
->pBuffer
, ut
->dwBytesTransferred
);
308 fprintf(stderr
,"\n");
316 fprintf(stderr
,"INT_ENABLE\n");
319 struct interrupt
*it
= (struct interrupt
*)(wdheader
->data
);
322 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
);
327 pthread_mutex_trylock(&int_wait
);
334 fprintf(stderr
,"INT_DISABLE\n");
337 struct interrupt
*it
= (struct interrupt
*)(wdheader
->data
);
340 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
);
343 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
348 pthread_mutex_unlock(&int_wait
);
351 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
);
356 case USB_SET_INTERFACE
:
358 fprintf(stderr
,"USB_SET_INTERFACE\n");
361 struct usb_set_interface
*usi
= (struct usb_set_interface
*)(wdheader
->data
);
364 fprintf(stderr
,"unique: %lu, interfacenum: %lu, alternatesetting: %lu, options: %lx\n", usi
->dwUniqueID
, usi
->dwInterfaceNum
, usi
->dwAlternateSetting
, usi
->dwOptions
);
367 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
371 usb_devhandle
= usb_open(usbdevice
);
373 /* FIXME: Select right interface! */
374 ret
= usb_claim_interface(usb_devhandle
, usbdevice
->config
[0].interface
[usi
->dwInterfaceNum
].altsetting
[usi
->dwAlternateSetting
].bInterfaceNumber
);
377 ret
= usb_set_altinterface(usb_devhandle
, usi
->dwAlternateSetting
);
379 fprintf(stderr
, "usb_set_altinterface: %d\n", ret
);
381 fprintf(stderr
, "usb_set_configuration: %d (%s)\n", ret
, usb_strerror());
384 fprintf(stderr
, "usb_claim_interface: %d -> %d (%s)\n", usbdevice
->config
[0].interface
[usi
->dwInterfaceNum
].altsetting
[usi
->dwAlternateSetting
].bInterfaceNumber
, ret
, usb_strerror());
389 fprintf(stderr
,"unique: %lu, interfacenum: %lu, alternatesetting: %lu, options: %lx\n", usi
->dwUniqueID
, usi
->dwInterfaceNum
, usi
->dwAlternateSetting
, usi
->dwOptions
);
394 case USB_GET_DEVICE_DATA
:
396 fprintf(stderr
,"faking USB_GET_DEVICE_DATA\n");
399 struct usb_get_device_data
*ugdd
= (struct usb_get_device_data
*)(wdheader
->data
);
403 fprintf(stderr
, "unique: %lu, bytes: %lu, options: %lx\n", ugdd
->dwUniqueID
, ugdd
->dwBytes
, ugdd
->dwOptions
);
405 pSize
= ugdd
->dwBytes
;
406 if (!ugdd
->dwBytes
) {
408 ugdd
->dwBytes
= usb_deviceinfo(NULL
);
411 usb_deviceinfo((unsigned char*)ugdd
->pBuf
);
418 fprintf(stderr
,"EVENT_REGISTER\n");
421 struct event
*e
= (struct event
*)(wdheader
->data
);
426 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
);
428 for (i
= 0; i
< e
->dwNumMatchTables
; i
++) {
430 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
);
433 for (bus
= busses
; bus
; bus
= bus
->next
) {
434 struct usb_device
*dev
;
436 for (dev
= bus
->devices
; dev
; dev
= dev
->next
) {
437 struct usb_device_descriptor
*desc
= &(dev
->descriptor
);
439 if((desc
->idVendor
== e
->matchTables
[i
].VendorId
) &&
440 (desc
->idProduct
== e
->matchTables
[i
].ProductId
) &&
441 (desc
->bDeviceClass
== e
->matchTables
[i
].bDeviceClass
) &&
442 (desc
->bDeviceSubClass
== e
->matchTables
[i
].bDeviceSubClass
)) {
444 for (ac
= 0; ac
< desc
->bNumConfigurations
; ac
++) {
445 struct usb_interface
*interface
= dev
->config
[ac
].interface
;
448 for (ai
= 0; ai
< interface
->num_altsetting
; ai
++) {
450 fprintf(stderr
, "intclass: %x, intsubclass: %x, intproto: %x\n", interface
->altsetting
[i
].bInterfaceClass
, interface
->altsetting
[i
].bInterfaceSubClass
, interface
->altsetting
[i
].bInterfaceProtocol
);
452 if ((interface
->altsetting
[ai
].bInterfaceSubClass
== e
->matchTables
[i
].bInterfaceSubClass
) &&
453 (interface
->altsetting
[ai
].bInterfaceProtocol
== e
->matchTables
[i
].bInterfaceProtocol
)){
454 /* TODO: check interfaceClass! */
456 fprintf(stderr
,"!!!FOUND DEVICE WITH LIBUSB!!!\n");
459 card_type
= e
->dwCardType
;
469 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
475 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
);
476 for (i
= 0; i
< e
->dwNumMatchTables
; i
++)
477 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
);
483 fprintf(stderr
,"TRANSFER\n");
485 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
489 case EVENT_UNREGISTER
:
491 fprintf(stderr
,"EVENT_UNREGISTER\n");
494 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
500 fprintf(stderr
,"INT_WAIT\n");
503 struct interrupt
*it
= (struct interrupt
*)(wdheader
->data
);
506 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
);
510 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
513 if (it
->dwCounter
== 0) {
516 pthread_mutex_lock(&int_wait
);
517 pthread_mutex_unlock(&int_wait
);
520 pthread_mutex_lock(&int_wait
);
521 pthread_mutex_unlock(&int_wait
);
526 fprintf(stderr
,"INT_WAIT_RETURN: 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
);
531 case CARD_UNREGISTER
:
532 fprintf(stderr
,"CARD_UNREGISTER\n");
534 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
540 fprintf(stderr
,"EVENT_PULL\n");
543 struct event
*e
= (struct event
*)(wdheader
->data
);
547 fprintf(stderr
,"handle: %lu, action: %lu, status: %lu, eventid: %lu, cardtype: %lx, 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
);
548 for (i
= 0; i
< e
->dwNumMatchTables
; i
++)
549 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
);
553 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
556 struct usb_interface
*interface
= usbdevice
->config
->interface
;
558 e
->dwCardType
= card_type
;
561 e
->u
.Usb
.dwUniqueID
= 110;
562 e
->matchTables
[0].VendorId
= usbdevice
->descriptor
.idVendor
;
563 e
->matchTables
[0].ProductId
= usbdevice
->descriptor
.idProduct
;
564 e
->matchTables
[0].bDeviceClass
= usbdevice
->descriptor
.bDeviceClass
;
565 e
->matchTables
[0].bDeviceSubClass
= usbdevice
->descriptor
.bDeviceSubClass
;
566 e
->matchTables
[0].bInterfaceClass
= interface
->altsetting
[0].bInterfaceClass
;
567 e
->matchTables
[0].bInterfaceSubClass
= interface
->altsetting
[0].bInterfaceSubClass
;
568 e
->matchTables
[0].bInterfaceProtocol
= interface
->altsetting
[0].bInterfaceProtocol
;
573 fprintf(stderr
,"handle: %lu, action: %lu, status: %lu, eventid: %lu, cardtype: %lx, 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
);
574 for (i
= 0; i
< e
->dwNumMatchTables
; i
++)
575 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
);
582 fprintf(stderr
,"!!!Unsupported IOCTL: %x!!!\n", request
);
584 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
592 int ioctl(int fd
, int request
, ...) {
598 ioctl_func
= (int (*) (int, int, void *)) dlsym (REAL_LIBC
, "ioctl");
600 va_start (args
, request
);
601 argp
= va_arg (args
, void *);
605 ret
= do_wdioctl(fd
, request
, argp
);
607 ret
= (*ioctl_func
) (fd
, request
, argp
);
612 int open (const char *pathname
, int flags
, ...) {
613 static int (*func
) (const char *, int, mode_t
) = NULL
;
619 func
= (int (*) (const char *, int, mode_t
)) dlsym (REAL_LIBC
, "open");
621 if (flags
& O_CREAT
) {
622 va_start(args
, flags
);
623 mode
= va_arg(args
, mode_t
);
627 if (!strcmp (pathname
, "/dev/windrvr6")) {
629 fprintf(stderr
,"opening windrvr6\n");
632 windrvrfd
= fd
= (*func
) ("/dev/null", flags
, mode
);
634 windrvrfd
= fd
= (*func
) (pathname
, flags
, mode
);
641 busses
= usb_get_busses();
647 return (*func
) (pathname
, flags
, mode
);
651 static int (*func
) (int) = NULL
;
654 func
= (int (*) (int)) dlsym(REAL_LIBC
, "close");
656 if (fd
== windrvrfd
) {
658 fprintf(stderr
,"close windrvrfd\n");
666 FILE *fopen(const char *path
, const char *mode
) {
668 static FILE* (*func
) (const char*, const char*) = NULL
;
671 func
= (FILE* (*) (const char*, const char*)) dlsym(REAL_LIBC
, "fopen");
673 ret
= (*func
) (path
, mode
);
675 if (!strcmp (path
, "/proc/modules")) {
677 fprintf(stderr
,"opening /proc/modules\n");
688 char *fgets(char *s
, int size
, FILE *stream
) {
689 static char* (*func
) (char*, int, FILE*) = NULL
;
690 const char modules
[] = "windrvr6 160960 0 - Live 0xf98b0000\n";
695 func
= (char* (*) (char*, int, FILE*)) dlsym(REAL_LIBC
, "fgets");
697 if (modulesfp
== stream
) {
704 ret
= (*func
)(s
,size
,stream
);
710 int fclose(FILE *fp
) {
711 static int (*func
) (FILE*) = NULL
;
714 func
= (int (*) (FILE*)) dlsym(REAL_LIBC
, "fclose");
716 if (fp
== modulesfp
) {