]>
git.zerfleddert.de Git - usb-driver/blob - usb-driver.c
60d0073c264aa07c3197fd0c52a999034ea94463
1 #if defined(__GNUC__) && !defined(__STRICT_ANSI__)
6 #define REAL_LIBC RTLD_NEXT
8 #define REAL_LIBC ((void *) -1L)
17 #include <sys/types.h>
25 static int (*ioctl_func
) (int, int, void *) = NULL
;
26 static int windrvrfd
= 0;
27 static int modulesfd
= 0;
28 static int modules_read
= 0;
29 static struct usb_bus
*busses
= NULL
;
30 static struct usb_device
*usbdevice
;
31 static usb_dev_handle
*usb_devhandle
= NULL
;
32 static unsigned long card_type
;
33 static int ints_enabled
= 0;
38 void hexdump(unsigned char *buf
, int len
) {
41 for(i
=0; i
<len
; i
++) {
42 fprintf(stderr
,"%02x ", buf
[i
]);
48 int usb_deviceinfo(unsigned char *buf
) {
51 WDU_CONFIGURATION
**pConfigs
, **pActiveConfig
;
52 WDU_INTERFACE
**pActiveInterface
;
55 struct usb_device_info
*udi
= (struct usb_device_info
*)(buf
+len
);
57 udi
->Descriptor
.bLength
= sizeof(WDU_DEVICE_DESCRIPTOR
);
58 udi
->Descriptor
.bDescriptorType
= usbdevice
->descriptor
.bDescriptorType
;
59 udi
->Descriptor
.bcdUSB
= usbdevice
->descriptor
.bcdUSB
;
60 udi
->Descriptor
.bDeviceClass
= usbdevice
->descriptor
.bDeviceClass
;
61 udi
->Descriptor
.bDeviceSubClass
= usbdevice
->descriptor
.bDeviceSubClass
;
62 udi
->Descriptor
.bDeviceProtocol
= usbdevice
->descriptor
.bDeviceProtocol
;
63 udi
->Descriptor
.bMaxPacketSize0
= usbdevice
->descriptor
.bMaxPacketSize0
;
64 udi
->Descriptor
.idVendor
= usbdevice
->descriptor
.idVendor
;
65 udi
->Descriptor
.idProduct
= usbdevice
->descriptor
.idProduct
;
66 udi
->Descriptor
.bcdDevice
= usbdevice
->descriptor
.bcdDevice
;
67 udi
->Descriptor
.iManufacturer
= usbdevice
->descriptor
.iManufacturer
;
68 udi
->Descriptor
.iProduct
= usbdevice
->descriptor
.iProduct
;
69 udi
->Descriptor
.iSerialNumber
= usbdevice
->descriptor
.iSerialNumber
;
70 udi
->Descriptor
.bNumConfigurations
= usbdevice
->descriptor
.bNumConfigurations
;
72 /* TODO: Fix Pipe0! */
73 udi
->Pipe0
.dwNumber
= 0x00;
74 udi
->Pipe0
.dwMaximumPacketSize
= usbdevice
->descriptor
.bMaxPacketSize0
;
76 udi
->Pipe0
.direction
= 3;
77 udi
->Pipe0
.dwInterval
= 0;
79 pConfigs
= &(udi
->pConfigs
);
80 pActiveConfig
= &(udi
->pActiveConfig
);
81 pActiveInterface
= &(udi
->pActiveInterface
[0]);
84 len
= sizeof(struct usb_device_info
);
86 for (i
=0; i
<usbdevice
->descriptor
.bNumConfigurations
; i
++)
88 struct usb_config_descriptor
*conf_desc
= &usbdevice
->config
[i
];
89 WDU_INTERFACE
**pInterfaces
;
90 WDU_ALTERNATE_SETTING
**pAlternateSettings
[conf_desc
->bNumInterfaces
];
91 WDU_ALTERNATE_SETTING
**pActiveAltSetting
[conf_desc
->bNumInterfaces
];
94 WDU_CONFIGURATION
*cfg
= (WDU_CONFIGURATION
*)(buf
+len
);
99 cfg
->Descriptor
.bLength
= conf_desc
->bLength
;
100 cfg
->Descriptor
.bDescriptorType
= conf_desc
->bDescriptorType
;
101 cfg
->Descriptor
.wTotalLength
= conf_desc
->wTotalLength
;
102 cfg
->Descriptor
.bNumInterfaces
= conf_desc
->bNumInterfaces
;
103 cfg
->Descriptor
.bConfigurationValue
= conf_desc
->bConfigurationValue
;
104 cfg
->Descriptor
.iConfiguration
= conf_desc
->iConfiguration
;
105 cfg
->Descriptor
.bmAttributes
= conf_desc
->bmAttributes
;
106 cfg
->Descriptor
.MaxPower
= conf_desc
->MaxPower
;
108 cfg
->dwNumInterfaces
= conf_desc
->bNumInterfaces
;
110 pInterfaces
= &(cfg
->pInterfaces
);
112 len
+= sizeof(WDU_CONFIGURATION
);
115 *pInterfaces
= (WDU_INTERFACE
*)(buf
+len
);
116 for (j
=0; j
<conf_desc
->bNumInterfaces
; j
++) {
117 WDU_INTERFACE
*iface
= (WDU_INTERFACE
*)(buf
+len
);
119 pActiveInterface
[j
] = iface
;
121 pAlternateSettings
[j
] = &(iface
->pAlternateSettings
);
122 iface
->dwNumAltSettings
= usbdevice
->config
[i
].interface
[j
].num_altsetting
;
123 pActiveAltSetting
[j
] = &(iface
->pActiveAltSetting
);
125 len
+= sizeof(WDU_INTERFACE
);
128 len
+= sizeof(WDU_INTERFACE
) * conf_desc
->bNumInterfaces
;
131 for (j
=0; j
<conf_desc
->bNumInterfaces
; j
++)
133 struct usb_interface
*interface
= &usbdevice
->config
[i
].interface
[j
];
136 *pAlternateSettings
[j
] = (WDU_ALTERNATE_SETTING
*)(buf
+len
);
138 *pActiveAltSetting
[j
] = (WDU_ALTERNATE_SETTING
*)(buf
+len
);
141 for(k
=0; k
<interface
->num_altsetting
; k
++)
143 unsigned char bNumEndpoints
= interface
->altsetting
[k
].bNumEndpoints
;
144 WDU_ENDPOINT_DESCRIPTOR
**pEndpointDescriptors
;
145 WDU_PIPE_INFO
**pPipes
;
148 WDU_ALTERNATE_SETTING
*altset
= (WDU_ALTERNATE_SETTING
*)(buf
+len
);
150 altset
->Descriptor
.bLength
= interface
->altsetting
[k
].bLength
;
151 altset
->Descriptor
.bDescriptorType
= interface
->altsetting
[k
].bDescriptorType
;
152 altset
->Descriptor
.bInterfaceNumber
= interface
->altsetting
[k
].bInterfaceNumber
;
153 altset
->Descriptor
.bAlternateSetting
= interface
->altsetting
[k
].bAlternateSetting
;
154 altset
->Descriptor
.bNumEndpoints
= interface
->altsetting
[k
].bNumEndpoints
;
155 altset
->Descriptor
.bInterfaceClass
= interface
->altsetting
[k
].bInterfaceClass
;
156 altset
->Descriptor
.bInterfaceSubClass
= interface
->altsetting
[k
].bInterfaceSubClass
;
157 altset
->Descriptor
.bInterfaceProtocol
= interface
->altsetting
[k
].bInterfaceProtocol
;
158 altset
->Descriptor
.iInterface
= interface
->altsetting
[k
].iInterface
;
159 pEndpointDescriptors
= &(altset
->pEndpointDescriptors
);
160 pPipes
= &(altset
->pPipes
);
163 len
+=sizeof(WDU_ALTERNATE_SETTING
);
166 *pEndpointDescriptors
= (WDU_ENDPOINT_DESCRIPTOR
*)(buf
+len
);
167 for (l
= 0; l
< bNumEndpoints
; l
++) {
168 WDU_ENDPOINT_DESCRIPTOR
*ed
= (WDU_ENDPOINT_DESCRIPTOR
*)(buf
+len
);
170 ed
->bLength
= interface
->altsetting
[k
].endpoint
[l
].bLength
;
171 ed
->bDescriptorType
= interface
->altsetting
[k
].endpoint
[l
].bDescriptorType
;
172 ed
->bEndpointAddress
= interface
->altsetting
[k
].endpoint
[l
].bEndpointAddress
;
173 ed
->bmAttributes
= interface
->altsetting
[k
].endpoint
[l
].bmAttributes
;
174 ed
->wMaxPacketSize
= interface
->altsetting
[k
].endpoint
[l
].wMaxPacketSize
;
175 ed
->bInterval
= interface
->altsetting
[k
].endpoint
[l
].bInterval
;
177 len
+= sizeof(WDU_ENDPOINT_DESCRIPTOR
);
180 *pPipes
= (WDU_PIPE_INFO
*)(buf
+len
);
181 for (l
= 0; l
< bNumEndpoints
; l
++) {
182 WDU_PIPE_INFO
*pi
= (WDU_PIPE_INFO
*)(buf
+len
);
184 pi
->dwNumber
= interface
->altsetting
[k
].endpoint
[l
].bEndpointAddress
;
185 pi
->dwMaximumPacketSize
= WDU_GET_MAX_PACKET_SIZE(interface
->altsetting
[k
].endpoint
[l
].wMaxPacketSize
);
186 pi
->type
= interface
->altsetting
[k
].endpoint
[l
].bmAttributes
& USB_ENDPOINT_TYPE_MASK
;
187 if (pi
->type
== PIPE_TYPE_CONTROL
)
188 pi
->direction
= WDU_DIR_IN_OUT
;
191 pi
->direction
= interface
->altsetting
[k
].endpoint
[l
].bEndpointAddress
& USB_ENDPOINT_DIR_MASK
? WDU_DIR_IN
: WDU_DIR_OUT
;
194 pi
->dwInterval
= interface
->altsetting
[k
].endpoint
[l
].bInterval
;
196 len
+= sizeof(WDU_PIPE_INFO
);
199 len
+=(sizeof(WDU_ENDPOINT_DESCRIPTOR
)+sizeof(WDU_PIPE_INFO
))*bNumEndpoints
;
208 int do_wdioctl(int fd
, unsigned int request
, unsigned char *wdioctl
) {
209 struct header_struct
* wdheader
= (struct header_struct
*)wdioctl
;
210 struct version_struct
*version
;
213 if (wdheader
->magic
!= MAGIC
) {
214 fprintf(stderr
,"!!!ERROR: magic header does not match!!!\n");
215 return (*ioctl_func
) (fd
, request
, wdioctl
);
220 version
= (struct version_struct
*)(wdheader
->data
);
221 strcpy(version
->version
, "WinDriver no more");
222 version
->versionul
= 999;
224 fprintf(stderr
,"faking VERSION\n");
230 fprintf(stderr
,"faking LICENSE\n");
236 //struct card_register* cr = (struct card_register*)(wdheader->data);
237 /* Todo: LPT-Port already in use */
240 fprintf(stderr
,"faking CARD_REGISTER\n");
246 fprintf(stderr
,"in USB_TRANSFER");
249 struct usb_transfer
*ut
= (struct usb_transfer
*)(wdheader
->data
);
252 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
);
253 fprintf(stderr
,"setup packet: ");
254 hexdump(ut
->SetupPacket
, 8);
255 fprintf(stderr
,"\n");
257 if (!ut
->fRead
&& ut
->dwBufferSize
)
259 hexdump(ut
->pBuffer
, ut
->dwBufferSize
);
260 fprintf(stderr
,"\n");
265 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
267 /* http://www.jungo.com/support/documentation/windriver/802/wdusb_man_mhtml/node55.html#SECTION001213000000000000000 */
268 if (ut
->dwPipeNum
== 0) { /* control pipe */
269 int requesttype
, request
, value
, index
, size
;
270 requesttype
= ut
->SetupPacket
[0];
271 request
= ut
->SetupPacket
[1];
272 value
= ut
->SetupPacket
[2] | (ut
->SetupPacket
[3] << 8);
273 index
= ut
->SetupPacket
[4] | (ut
->SetupPacket
[5] << 8);
274 size
= ut
->SetupPacket
[6] | (ut
->SetupPacket
[7] << 8);
276 fprintf(stderr
, "requesttype: %x, request: %x, value: %u, index: %u, size: %u\n", requesttype
, request
, value
, index
, size
);
278 ret
= usb_control_msg(usb_devhandle
, requesttype
, request
, value
, index
, ut
->pBuffer
, size
, ut
->dwTimeout
);
281 ret
= usb_bulk_read(usb_devhandle
, ut
->dwPipeNum
, ut
->pBuffer
, ut
->dwBufferSize
, ut
->dwTimeout
);
284 ret
= usb_bulk_write(usb_devhandle
, ut
->dwPipeNum
, ut
->pBuffer
, ut
->dwBufferSize
, ut
->dwTimeout
);
289 fprintf(stderr
, "usb_transfer: %d (%s)\n", ret
, usb_strerror());
291 ut
->dwBytesTransferred
= ret
;
297 fprintf(stderr
,"Transferred: %lu (%s)\n",ut
->dwBytesTransferred
, (ut
->fRead
?"read":"write"));
298 if (ut
->fRead
&& ut
->dwBytesTransferred
)
300 fprintf(stderr
,"Read: ");
301 hexdump(ut
->pBuffer
, ut
->dwBytesTransferred
);
302 fprintf(stderr
,"\n");
310 fprintf(stderr
,"INT_ENABLE\n");
313 struct interrupt
*it
= (struct interrupt
*)(wdheader
->data
);
316 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
);
321 //ret = (*ioctl_func) (fd, request, wdioctl);
328 fprintf(stderr
,"INT_DISABLE\n");
331 struct interrupt
*it
= (struct interrupt
*)(wdheader
->data
);
334 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
);
337 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
344 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
);
349 case USB_SET_INTERFACE
:
351 fprintf(stderr
,"USB_SET_INTERFACE\n");
354 struct usb_set_interface
*usi
= (struct usb_set_interface
*)(wdheader
->data
);
357 fprintf(stderr
,"unique: %lu, interfacenum: %lu, alternatesetting: %lu, options: %lx\n", usi
->dwUniqueID
, usi
->dwInterfaceNum
, usi
->dwAlternateSetting
, usi
->dwOptions
);
360 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
364 usb_devhandle
= usb_open(usbdevice
);
366 /* FIXME: Select right interface! */
367 ret
= usb_claim_interface(usb_devhandle
, usbdevice
->config
[0].interface
[usi
->dwInterfaceNum
].altsetting
[usi
->dwAlternateSetting
].bInterfaceNumber
);
369 //ret = usb_set_configuration(usb_devhandle, usbdevice->config[0].bConfigurationValue);
371 ret
= usb_set_altinterface(usb_devhandle
, usi
->dwAlternateSetting
);
373 fprintf(stderr
, "usb_set_altinterface: %d\n", ret
);
375 fprintf(stderr
, "usb_set_configuration: %d (%s)\n", ret
, usb_strerror());
378 fprintf(stderr
, "usb_claim_interface: %d -> %d (%s)\n", usbdevice
->config
[0].interface
[usi
->dwInterfaceNum
].altsetting
[usi
->dwAlternateSetting
].bInterfaceNumber
, ret
, usb_strerror());
383 fprintf(stderr
,"unique: %lu, interfacenum: %lu, alternatesetting: %lu, options: %lx\n", usi
->dwUniqueID
, usi
->dwInterfaceNum
, usi
->dwAlternateSetting
, usi
->dwOptions
);
388 case USB_GET_DEVICE_DATA
:
390 fprintf(stderr
,"faking USB_GET_DEVICE_DATA\n");
393 struct usb_get_device_data
*ugdd
= (struct usb_get_device_data
*)(wdheader
->data
);
397 fprintf(stderr
, "unique: %lu, bytes: %lu, options: %lx\n", ugdd
->dwUniqueID
, ugdd
->dwBytes
, ugdd
->dwOptions
);
399 pSize
= ugdd
->dwBytes
;
400 //ret = (*ioctl_func) (fd, request, wdioctl);
401 if (!ugdd
->dwBytes
) {
403 ugdd
->dwBytes
= usb_deviceinfo(NULL
);
406 usb_deviceinfo((unsigned char*)ugdd
->pBuf
);
413 fprintf(stderr
,"EVENT_REGISTER\n");
416 struct event
*e
= (struct event
*)(wdheader
->data
);
421 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
);
423 for (i
= 0; i
< e
->dwNumMatchTables
; i
++) {
425 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
);
428 for (bus
= busses
; bus
; bus
= bus
->next
) {
429 struct usb_device
*dev
;
431 for (dev
= bus
->devices
; dev
; dev
= dev
->next
) {
432 struct usb_device_descriptor
*desc
= &(dev
->descriptor
);
434 if((desc
->idVendor
== e
->matchTables
[i
].VendorId
) &&
435 (desc
->idProduct
== e
->matchTables
[i
].ProductId
) &&
436 (desc
->bDeviceClass
== e
->matchTables
[i
].bDeviceClass
) &&
437 (desc
->bDeviceSubClass
== e
->matchTables
[i
].bDeviceSubClass
)) {
439 for (ac
= 0; ac
< desc
->bNumConfigurations
; ac
++) {
440 struct usb_interface
*interface
= dev
->config
[ac
].interface
;
443 for (ai
= 0; ai
< interface
->num_altsetting
; ai
++) {
445 fprintf(stderr
, "intclass: %x, intsubclass: %x, intproto: %x\n", interface
->altsetting
[i
].bInterfaceClass
, interface
->altsetting
[i
].bInterfaceSubClass
, interface
->altsetting
[i
].bInterfaceProtocol
);
447 if ((interface
->altsetting
[ai
].bInterfaceSubClass
== e
->matchTables
[i
].bInterfaceSubClass
) &&
448 (interface
->altsetting
[ai
].bInterfaceProtocol
== e
->matchTables
[i
].bInterfaceProtocol
)){
449 /* TODO: check interfaceClass! */
451 fprintf(stderr
,"!!!FOUND DEVICE WITH LIBUSB!!!\n");
454 card_type
= e
->dwCardType
;
464 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
470 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
);
471 for (i
= 0; i
< e
->dwNumMatchTables
; i
++)
472 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
);
478 fprintf(stderr
,"TRANSFER\n");
480 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
484 case EVENT_UNREGISTER
:
486 fprintf(stderr
,"EVENT_UNREGISTER\n");
489 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
495 fprintf(stderr
,"INT_WAIT\n");
498 struct interrupt
*it
= (struct interrupt
*)(wdheader
->data
);
501 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
);
505 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
508 if (it
->dwCounter
== 0) {
511 while(ints_enabled
) {sleep(1);}
514 while(ints_enabled
) {sleep(1);}
519 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
);
524 case CARD_UNREGISTER
:
525 fprintf(stderr
,"CARD_UNREGISTER\n");
527 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
533 fprintf(stderr
,"EVENT_PULL\n");
536 struct event
*e
= (struct event
*)(wdheader
->data
);
540 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
);
541 for (i
= 0; i
< e
->dwNumMatchTables
; i
++)
542 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
);
546 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
549 struct usb_interface
*interface
= usbdevice
->config
->interface
;
551 e
->dwCardType
= card_type
;
554 e
->u
.Usb
.dwUniqueID
= 110;
555 e
->matchTables
[0].VendorId
= usbdevice
->descriptor
.idVendor
;
556 e
->matchTables
[0].ProductId
= usbdevice
->descriptor
.idProduct
;
557 e
->matchTables
[0].bDeviceClass
= usbdevice
->descriptor
.bDeviceClass
;
558 e
->matchTables
[0].bDeviceSubClass
= usbdevice
->descriptor
.bDeviceSubClass
;
559 e
->matchTables
[0].bInterfaceClass
= interface
->altsetting
[0].bInterfaceClass
;
560 e
->matchTables
[0].bInterfaceSubClass
= interface
->altsetting
[0].bInterfaceSubClass
;
561 e
->matchTables
[0].bInterfaceProtocol
= interface
->altsetting
[0].bInterfaceProtocol
;
566 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
);
567 for (i
= 0; i
< e
->dwNumMatchTables
; i
++)
568 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
);
575 fprintf(stderr
,"!!!Unsupported IOCTL: %x!!!\n", request
);
577 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
586 typedef int (*open_funcptr_t
) (const char *, int, mode_t
);
588 int open (const char *pathname
, int flags
, ...)
590 static open_funcptr_t func
= NULL
;
596 func
= (open_funcptr_t
) dlsym (REAL_LIBC
, "open");
598 if (flags
& O_CREAT
) {
599 va_start(args
, flags
);
600 mode
= va_arg(args
, mode_t
);
604 if (!strcmp (pathname
, "/dev/windrvr6")) {
606 fprintf(stderr
,"opening windrvr6\n");
609 windrvrfd
= fd
= (*func
) ("/dev/null", flags
, mode
);
611 windrvrfd
= fd
= (*func
) (pathname
, flags
, mode
);
618 busses
= usb_get_busses();
624 return (*func
) (pathname
, flags
, mode
);
628 static int (*func
) (int) = NULL
;
631 func
= (int (*) (int)) dlsym(REAL_LIBC
, "close");
633 if (fd
== windrvrfd
) {
635 fprintf(stderr
,"close windrvrfd\n");
640 if (fd
== modulesfd
) {
642 fprintf(stderr
,"close modulesfd\n");
650 FILE *fopen(const char *path
, const char *mode
) {
652 static FILE* (*func
) (const char*, const char*) = NULL
;
655 func
= (FILE* (*) (const char*, const char*)) dlsym(REAL_LIBC
, "fopen");
657 ret
= (*func
) (path
, mode
);
659 if (!strcmp (path
, "/proc/modules")) {
661 fprintf(stderr
,"opening /proc/modules\n");
664 modulesfd
= fileno(ret
);
672 ssize_t
read(int fd
, void *buf
, size_t count
) {
674 static ssize_t (*func
) (int, void*, size_t) = NULL
;
675 const char modules
[] = "windrvr6 160960 0 - Live 0xf98b0000\n";
678 func
= (ssize_t (*) (int, void*, size_t)) dlsym(REAL_LIBC
, "read");
680 if ((!modules_read
) && (fd
== modulesfd
)) {
681 strcpy(buf
, modules
);
682 ret
= strlen(modules
);
685 ret
= (*func
) (fd
, buf
, count
);
691 int ioctl(int fd
, int request
, ...)
698 ioctl_func
= (int (*) (int, int, void *)) dlsym (REAL_LIBC
, "ioctl");
700 va_start (args
, request
);
701 argp
= va_arg (args
, void *);
705 ret
= do_wdioctl(fd
, request
, argp
);
707 ret
= (*ioctl_func
) (fd
, request
, argp
);