1 #if defined(__GNUC__) && !defined(__STRICT_ANSI__)
6 #define REAL_LIBC RTLD_NEXT
8 #define REAL_LIBC ((void *) -1L)
17 #include <sys/types.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
;
40 void hexdump(unsigned char *buf
, int len
) {
43 for(i
=0; i
<len
; i
++) {
44 fprintf(stderr
,"%02x ", buf
[i
]);
50 int usb_deviceinfo(unsigned char *buf
) {
53 WDU_CONFIGURATION
**pConfigs
, **pActiveConfig
;
54 WDU_INTERFACE
**pActiveInterface
;
57 struct usb_device_info
*udi
= (struct usb_device_info
*)(buf
+len
);
59 udi
->Descriptor
.bLength
= sizeof(WDU_DEVICE_DESCRIPTOR
);
60 udi
->Descriptor
.bDescriptorType
= usbdevice
->descriptor
.bDescriptorType
;
61 udi
->Descriptor
.bcdUSB
= usbdevice
->descriptor
.bcdUSB
;
62 udi
->Descriptor
.bDeviceClass
= usbdevice
->descriptor
.bDeviceClass
;
63 udi
->Descriptor
.bDeviceSubClass
= usbdevice
->descriptor
.bDeviceSubClass
;
64 udi
->Descriptor
.bDeviceProtocol
= usbdevice
->descriptor
.bDeviceProtocol
;
65 udi
->Descriptor
.bMaxPacketSize0
= usbdevice
->descriptor
.bMaxPacketSize0
;
66 udi
->Descriptor
.idVendor
= usbdevice
->descriptor
.idVendor
;
67 udi
->Descriptor
.idProduct
= usbdevice
->descriptor
.idProduct
;
68 udi
->Descriptor
.bcdDevice
= usbdevice
->descriptor
.bcdDevice
;
69 udi
->Descriptor
.iManufacturer
= usbdevice
->descriptor
.iManufacturer
;
70 udi
->Descriptor
.iProduct
= usbdevice
->descriptor
.iProduct
;
71 udi
->Descriptor
.iSerialNumber
= usbdevice
->descriptor
.iSerialNumber
;
72 udi
->Descriptor
.bNumConfigurations
= usbdevice
->descriptor
.bNumConfigurations
;
74 /* TODO: Fix Pipe0! */
75 udi
->Pipe0
.dwNumber
= 0x00;
76 udi
->Pipe0
.dwMaximumPacketSize
= usbdevice
->descriptor
.bMaxPacketSize0
;
78 udi
->Pipe0
.direction
= 3;
79 udi
->Pipe0
.dwInterval
= 0;
81 pConfigs
= &(udi
->pConfigs
);
82 pActiveConfig
= &(udi
->pActiveConfig
);
83 pActiveInterface
= &(udi
->pActiveInterface
[0]);
86 len
= sizeof(struct usb_device_info
);
88 for (i
=0; i
<usbdevice
->descriptor
.bNumConfigurations
; i
++)
90 struct usb_config_descriptor
*conf_desc
= &usbdevice
->config
[i
];
91 WDU_INTERFACE
**pInterfaces
;
92 WDU_ALTERNATE_SETTING
**pAlternateSettings
[conf_desc
->bNumInterfaces
];
93 WDU_ALTERNATE_SETTING
**pActiveAltSetting
[conf_desc
->bNumInterfaces
];
96 WDU_CONFIGURATION
*cfg
= (WDU_CONFIGURATION
*)(buf
+len
);
101 cfg
->Descriptor
.bLength
= conf_desc
->bLength
;
102 cfg
->Descriptor
.bDescriptorType
= conf_desc
->bDescriptorType
;
103 cfg
->Descriptor
.wTotalLength
= conf_desc
->wTotalLength
;
104 cfg
->Descriptor
.bNumInterfaces
= conf_desc
->bNumInterfaces
;
105 cfg
->Descriptor
.bConfigurationValue
= conf_desc
->bConfigurationValue
;
106 cfg
->Descriptor
.iConfiguration
= conf_desc
->iConfiguration
;
107 cfg
->Descriptor
.bmAttributes
= conf_desc
->bmAttributes
;
108 cfg
->Descriptor
.MaxPower
= conf_desc
->MaxPower
;
110 cfg
->dwNumInterfaces
= conf_desc
->bNumInterfaces
;
112 pInterfaces
= &(cfg
->pInterfaces
);
114 len
+= sizeof(WDU_CONFIGURATION
);
117 *pInterfaces
= (WDU_INTERFACE
*)(buf
+len
);
118 for (j
=0; j
<conf_desc
->bNumInterfaces
; j
++) {
119 WDU_INTERFACE
*iface
= (WDU_INTERFACE
*)(buf
+len
);
121 pActiveInterface
[j
] = iface
;
123 pAlternateSettings
[j
] = &(iface
->pAlternateSettings
);
124 iface
->dwNumAltSettings
= usbdevice
->config
[i
].interface
[j
].num_altsetting
;
125 pActiveAltSetting
[j
] = &(iface
->pActiveAltSetting
);
127 len
+= sizeof(WDU_INTERFACE
);
130 len
+= sizeof(WDU_INTERFACE
) * conf_desc
->bNumInterfaces
;
133 for (j
=0; j
<conf_desc
->bNumInterfaces
; j
++)
135 struct usb_interface
*interface
= &usbdevice
->config
[i
].interface
[j
];
138 *pAlternateSettings
[j
] = (WDU_ALTERNATE_SETTING
*)(buf
+len
);
140 *pActiveAltSetting
[j
] = (WDU_ALTERNATE_SETTING
*)(buf
+len
);
143 for(k
=0; k
<interface
->num_altsetting
; k
++)
145 unsigned char bNumEndpoints
= interface
->altsetting
[k
].bNumEndpoints
;
146 WDU_ENDPOINT_DESCRIPTOR
**pEndpointDescriptors
;
147 WDU_PIPE_INFO
**pPipes
;
150 WDU_ALTERNATE_SETTING
*altset
= (WDU_ALTERNATE_SETTING
*)(buf
+len
);
152 altset
->Descriptor
.bLength
= interface
->altsetting
[k
].bLength
;
153 altset
->Descriptor
.bDescriptorType
= interface
->altsetting
[k
].bDescriptorType
;
154 altset
->Descriptor
.bInterfaceNumber
= interface
->altsetting
[k
].bInterfaceNumber
;
155 altset
->Descriptor
.bAlternateSetting
= interface
->altsetting
[k
].bAlternateSetting
;
156 altset
->Descriptor
.bNumEndpoints
= interface
->altsetting
[k
].bNumEndpoints
;
157 altset
->Descriptor
.bInterfaceClass
= interface
->altsetting
[k
].bInterfaceClass
;
158 altset
->Descriptor
.bInterfaceSubClass
= interface
->altsetting
[k
].bInterfaceSubClass
;
159 altset
->Descriptor
.bInterfaceProtocol
= interface
->altsetting
[k
].bInterfaceProtocol
;
160 altset
->Descriptor
.iInterface
= interface
->altsetting
[k
].iInterface
;
161 pEndpointDescriptors
= &(altset
->pEndpointDescriptors
);
162 pPipes
= &(altset
->pPipes
);
165 len
+=sizeof(WDU_ALTERNATE_SETTING
);
168 *pEndpointDescriptors
= (WDU_ENDPOINT_DESCRIPTOR
*)(buf
+len
);
169 for (l
= 0; l
< bNumEndpoints
; l
++) {
170 WDU_ENDPOINT_DESCRIPTOR
*ed
= (WDU_ENDPOINT_DESCRIPTOR
*)(buf
+len
);
172 ed
->bLength
= interface
->altsetting
[k
].endpoint
[l
].bLength
;
173 ed
->bDescriptorType
= interface
->altsetting
[k
].endpoint
[l
].bDescriptorType
;
174 ed
->bEndpointAddress
= interface
->altsetting
[k
].endpoint
[l
].bEndpointAddress
;
175 ed
->bmAttributes
= interface
->altsetting
[k
].endpoint
[l
].bmAttributes
;
176 ed
->wMaxPacketSize
= interface
->altsetting
[k
].endpoint
[l
].wMaxPacketSize
;
177 ed
->bInterval
= interface
->altsetting
[k
].endpoint
[l
].bInterval
;
179 len
+= sizeof(WDU_ENDPOINT_DESCRIPTOR
);
182 *pPipes
= (WDU_PIPE_INFO
*)(buf
+len
);
183 for (l
= 0; l
< bNumEndpoints
; l
++) {
184 WDU_PIPE_INFO
*pi
= (WDU_PIPE_INFO
*)(buf
+len
);
186 pi
->dwNumber
= interface
->altsetting
[k
].endpoint
[l
].bEndpointAddress
;
187 pi
->dwMaximumPacketSize
= WDU_GET_MAX_PACKET_SIZE(interface
->altsetting
[k
].endpoint
[l
].wMaxPacketSize
);
188 pi
->type
= interface
->altsetting
[k
].endpoint
[l
].bmAttributes
& USB_ENDPOINT_TYPE_MASK
;
189 if (pi
->type
== PIPE_TYPE_CONTROL
)
190 pi
->direction
= WDU_DIR_IN_OUT
;
193 pi
->direction
= interface
->altsetting
[k
].endpoint
[l
].bEndpointAddress
& USB_ENDPOINT_DIR_MASK
? WDU_DIR_IN
: WDU_DIR_OUT
;
196 pi
->dwInterval
= interface
->altsetting
[k
].endpoint
[l
].bInterval
;
198 len
+= sizeof(WDU_PIPE_INFO
);
201 len
+=(sizeof(WDU_ENDPOINT_DESCRIPTOR
)+sizeof(WDU_PIPE_INFO
))*bNumEndpoints
;
210 int do_wdioctl(int fd
, unsigned int request
, unsigned char *wdioctl
) {
211 struct header_struct
* wdheader
= (struct header_struct
*)wdioctl
;
212 struct version_struct
*version
;
215 if (wdheader
->magic
!= MAGIC
) {
216 fprintf(stderr
,"!!!ERROR: magic header does not match!!!\n");
217 return (*ioctl_func
) (fd
, request
, wdioctl
);
222 version
= (struct version_struct
*)(wdheader
->data
);
223 strcpy(version
->version
, "WinDriver no more");
224 version
->versionul
= 999;
226 fprintf(stderr
,"faking VERSION\n");
232 fprintf(stderr
,"faking LICENSE\n");
237 /* TODO: Implement for LPT-support */
240 struct card_register
* cr
= (struct card_register
*)(wdheader
->data
);
244 fprintf(stderr
,"faking CARD_REGISTER\n");
250 fprintf(stderr
,"in USB_TRANSFER");
253 struct usb_transfer
*ut
= (struct usb_transfer
*)(wdheader
->data
);
256 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
);
257 fprintf(stderr
,"setup packet: ");
258 hexdump(ut
->SetupPacket
, 8);
259 fprintf(stderr
,"\n");
261 if (!ut
->fRead
&& ut
->dwBufferSize
)
263 hexdump(ut
->pBuffer
, ut
->dwBufferSize
);
264 fprintf(stderr
,"\n");
269 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
271 /* http://www.jungo.com/support/documentation/windriver/802/wdusb_man_mhtml/node55.html#SECTION001213000000000000000 */
272 if (ut
->dwPipeNum
== 0) { /* control pipe */
273 int requesttype
, request
, value
, index
, size
;
274 requesttype
= ut
->SetupPacket
[0];
275 request
= ut
->SetupPacket
[1];
276 value
= ut
->SetupPacket
[2] | (ut
->SetupPacket
[3] << 8);
277 index
= ut
->SetupPacket
[4] | (ut
->SetupPacket
[5] << 8);
278 size
= ut
->SetupPacket
[6] | (ut
->SetupPacket
[7] << 8);
280 fprintf(stderr
, "requesttype: %x, request: %x, value: %u, index: %u, size: %u\n", requesttype
, request
, value
, index
, size
);
282 ret
= usb_control_msg(usb_devhandle
, requesttype
, request
, value
, index
, ut
->pBuffer
, size
, ut
->dwTimeout
);
285 ret
= usb_bulk_read(usb_devhandle
, ut
->dwPipeNum
, ut
->pBuffer
, ut
->dwBufferSize
, ut
->dwTimeout
);
288 ret
= usb_bulk_write(usb_devhandle
, ut
->dwPipeNum
, ut
->pBuffer
, ut
->dwBufferSize
, ut
->dwTimeout
);
293 fprintf(stderr
, "usb_transfer: %d (%s)\n", ret
, usb_strerror());
295 ut
->dwBytesTransferred
= ret
;
301 fprintf(stderr
,"Transferred: %lu (%s)\n",ut
->dwBytesTransferred
, (ut
->fRead
?"read":"write"));
302 if (ut
->fRead
&& ut
->dwBytesTransferred
)
304 fprintf(stderr
,"Read: ");
305 hexdump(ut
->pBuffer
, ut
->dwBytesTransferred
);
306 fprintf(stderr
,"\n");
314 fprintf(stderr
,"INT_ENABLE\n");
317 struct interrupt
*it
= (struct interrupt
*)(wdheader
->data
);
320 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
);
325 pthread_mutex_trylock(&int_wait
);
332 fprintf(stderr
,"INT_DISABLE\n");
335 struct interrupt
*it
= (struct interrupt
*)(wdheader
->data
);
338 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
);
341 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
346 pthread_mutex_unlock(&int_wait
);
349 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
);
354 case USB_SET_INTERFACE
:
356 fprintf(stderr
,"USB_SET_INTERFACE\n");
359 struct usb_set_interface
*usi
= (struct usb_set_interface
*)(wdheader
->data
);
362 fprintf(stderr
,"unique: %lu, interfacenum: %lu, alternatesetting: %lu, options: %lx\n", usi
->dwUniqueID
, usi
->dwInterfaceNum
, usi
->dwAlternateSetting
, usi
->dwOptions
);
365 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
369 usb_devhandle
= usb_open(usbdevice
);
371 /* FIXME: Select right interface! */
372 ret
= usb_claim_interface(usb_devhandle
, usbdevice
->config
[0].interface
[usi
->dwInterfaceNum
].altsetting
[usi
->dwAlternateSetting
].bInterfaceNumber
);
375 ret
= usb_set_altinterface(usb_devhandle
, usi
->dwAlternateSetting
);
377 fprintf(stderr
, "usb_set_altinterface: %d\n", ret
);
379 fprintf(stderr
, "usb_set_configuration: %d (%s)\n", ret
, usb_strerror());
382 fprintf(stderr
, "usb_claim_interface: %d -> %d (%s)\n", usbdevice
->config
[0].interface
[usi
->dwInterfaceNum
].altsetting
[usi
->dwAlternateSetting
].bInterfaceNumber
, ret
, usb_strerror());
387 fprintf(stderr
,"unique: %lu, interfacenum: %lu, alternatesetting: %lu, options: %lx\n", usi
->dwUniqueID
, usi
->dwInterfaceNum
, usi
->dwAlternateSetting
, usi
->dwOptions
);
392 case USB_GET_DEVICE_DATA
:
394 fprintf(stderr
,"faking USB_GET_DEVICE_DATA\n");
397 struct usb_get_device_data
*ugdd
= (struct usb_get_device_data
*)(wdheader
->data
);
401 fprintf(stderr
, "unique: %lu, bytes: %lu, options: %lx\n", ugdd
->dwUniqueID
, ugdd
->dwBytes
, ugdd
->dwOptions
);
403 pSize
= ugdd
->dwBytes
;
404 if (!ugdd
->dwBytes
) {
406 ugdd
->dwBytes
= usb_deviceinfo(NULL
);
409 usb_deviceinfo((unsigned char*)ugdd
->pBuf
);
416 fprintf(stderr
,"EVENT_REGISTER\n");
419 struct event
*e
= (struct event
*)(wdheader
->data
);
424 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
);
426 for (i
= 0; i
< e
->dwNumMatchTables
; i
++) {
428 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
);
431 for (bus
= busses
; bus
; bus
= bus
->next
) {
432 struct usb_device
*dev
;
434 for (dev
= bus
->devices
; dev
; dev
= dev
->next
) {
435 struct usb_device_descriptor
*desc
= &(dev
->descriptor
);
437 if((desc
->idVendor
== e
->matchTables
[i
].VendorId
) &&
438 (desc
->idProduct
== e
->matchTables
[i
].ProductId
) &&
439 (desc
->bDeviceClass
== e
->matchTables
[i
].bDeviceClass
) &&
440 (desc
->bDeviceSubClass
== e
->matchTables
[i
].bDeviceSubClass
)) {
442 for (ac
= 0; ac
< desc
->bNumConfigurations
; ac
++) {
443 struct usb_interface
*interface
= dev
->config
[ac
].interface
;
446 for (ai
= 0; ai
< interface
->num_altsetting
; ai
++) {
448 fprintf(stderr
, "intclass: %x, intsubclass: %x, intproto: %x\n", interface
->altsetting
[i
].bInterfaceClass
, interface
->altsetting
[i
].bInterfaceSubClass
, interface
->altsetting
[i
].bInterfaceProtocol
);
450 if ((interface
->altsetting
[ai
].bInterfaceSubClass
== e
->matchTables
[i
].bInterfaceSubClass
) &&
451 (interface
->altsetting
[ai
].bInterfaceProtocol
== e
->matchTables
[i
].bInterfaceProtocol
)){
452 /* TODO: check interfaceClass! */
454 fprintf(stderr
,"!!!FOUND DEVICE WITH LIBUSB!!!\n");
457 card_type
= e
->dwCardType
;
467 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
473 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
);
474 for (i
= 0; i
< e
->dwNumMatchTables
; i
++)
475 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
);
481 fprintf(stderr
,"TRANSFER\n");
483 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
487 case EVENT_UNREGISTER
:
489 fprintf(stderr
,"EVENT_UNREGISTER\n");
492 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
498 fprintf(stderr
,"INT_WAIT\n");
501 struct interrupt
*it
= (struct interrupt
*)(wdheader
->data
);
504 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
);
508 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
511 if (it
->dwCounter
== 0) {
514 pthread_mutex_lock(&int_wait
);
517 pthread_mutex_lock(&int_wait
);
522 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
);
527 case CARD_UNREGISTER
:
528 fprintf(stderr
,"CARD_UNREGISTER\n");
530 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
536 fprintf(stderr
,"EVENT_PULL\n");
539 struct event
*e
= (struct event
*)(wdheader
->data
);
543 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
);
544 for (i
= 0; i
< e
->dwNumMatchTables
; i
++)
545 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
);
549 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
552 struct usb_interface
*interface
= usbdevice
->config
->interface
;
554 e
->dwCardType
= card_type
;
557 e
->u
.Usb
.dwUniqueID
= 110;
558 e
->matchTables
[0].VendorId
= usbdevice
->descriptor
.idVendor
;
559 e
->matchTables
[0].ProductId
= usbdevice
->descriptor
.idProduct
;
560 e
->matchTables
[0].bDeviceClass
= usbdevice
->descriptor
.bDeviceClass
;
561 e
->matchTables
[0].bDeviceSubClass
= usbdevice
->descriptor
.bDeviceSubClass
;
562 e
->matchTables
[0].bInterfaceClass
= interface
->altsetting
[0].bInterfaceClass
;
563 e
->matchTables
[0].bInterfaceSubClass
= interface
->altsetting
[0].bInterfaceSubClass
;
564 e
->matchTables
[0].bInterfaceProtocol
= interface
->altsetting
[0].bInterfaceProtocol
;
569 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
);
570 for (i
= 0; i
< e
->dwNumMatchTables
; i
++)
571 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
);
578 fprintf(stderr
,"!!!Unsupported IOCTL: %x!!!\n", request
);
580 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
588 int ioctl(int fd
, int request
, ...)
595 ioctl_func
= (int (*) (int, int, void *)) dlsym (REAL_LIBC
, "ioctl");
597 va_start (args
, request
);
598 argp
= va_arg (args
, void *);
602 ret
= do_wdioctl(fd
, request
, argp
);
604 ret
= (*ioctl_func
) (fd
, request
, argp
);
609 typedef int (*open_funcptr_t
) (const char *, int, mode_t
);
611 int open (const char *pathname
, int flags
, ...)
613 static open_funcptr_t func
= NULL
;
619 func
= (open_funcptr_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
) {