1 /* libusb connector for XILINX impact
3 * Copyright (c) 2007 Michael Gernoth <michael@gernoth.net>
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to
7 * deal in the Software without restriction, including without limitation the
8 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
9 * sell copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
32 #include <sys/types.h>
39 #include "usb-driver.h"
41 static int (*ioctl_func
) (int, int, void *) = NULL
;
42 static int windrvrfd
= 0;
44 static int modules_read
= 0;
45 static struct usb_bus
*busses
= NULL
;
46 static struct usb_device
*usbdevice
;
47 static usb_dev_handle
*usb_devhandle
= NULL
;
48 static unsigned long card_type
;
49 static int ints_enabled
= 0;
50 static pthread_mutex_t int_wait
= PTHREAD_MUTEX_INITIALIZER
;
56 #define DPRINTF(format, args...) fprintf(stderr, format, ##args)
57 void hexdump(unsigned char *buf
, int len
) {
60 for(i
=0; i
<len
; i
++) {
61 fprintf(stderr
,"%02x ", buf
[i
]);
68 #define DPRINTF(format, args...)
71 int usb_deviceinfo(unsigned char *buf
) {
74 WDU_CONFIGURATION
**pConfigs
, **pActiveConfig
;
75 WDU_INTERFACE
**pActiveInterface
;
78 struct usb_device_info
*udi
= (struct usb_device_info
*)(buf
+len
);
80 udi
->Descriptor
.bLength
= sizeof(WDU_DEVICE_DESCRIPTOR
);
81 udi
->Descriptor
.bDescriptorType
= usbdevice
->descriptor
.bDescriptorType
;
82 udi
->Descriptor
.bcdUSB
= usbdevice
->descriptor
.bcdUSB
;
83 udi
->Descriptor
.bDeviceClass
= usbdevice
->descriptor
.bDeviceClass
;
84 udi
->Descriptor
.bDeviceSubClass
= usbdevice
->descriptor
.bDeviceSubClass
;
85 udi
->Descriptor
.bDeviceProtocol
= usbdevice
->descriptor
.bDeviceProtocol
;
86 udi
->Descriptor
.bMaxPacketSize0
= usbdevice
->descriptor
.bMaxPacketSize0
;
87 udi
->Descriptor
.idVendor
= usbdevice
->descriptor
.idVendor
;
88 udi
->Descriptor
.idProduct
= usbdevice
->descriptor
.idProduct
;
89 udi
->Descriptor
.bcdDevice
= usbdevice
->descriptor
.bcdDevice
;
90 udi
->Descriptor
.iManufacturer
= usbdevice
->descriptor
.iManufacturer
;
91 udi
->Descriptor
.iProduct
= usbdevice
->descriptor
.iProduct
;
92 udi
->Descriptor
.iSerialNumber
= usbdevice
->descriptor
.iSerialNumber
;
93 udi
->Descriptor
.bNumConfigurations
= usbdevice
->descriptor
.bNumConfigurations
;
95 /* TODO: Fix Pipe0! */
96 udi
->Pipe0
.dwNumber
= 0x00;
97 udi
->Pipe0
.dwMaximumPacketSize
= usbdevice
->descriptor
.bMaxPacketSize0
;
99 udi
->Pipe0
.direction
= WDU_DIR_IN_OUT
;
100 udi
->Pipe0
.dwInterval
= 0;
102 pConfigs
= &(udi
->pConfigs
);
103 pActiveConfig
= &(udi
->pActiveConfig
);
104 pActiveInterface
= &(udi
->pActiveInterface
[0]);
107 len
= sizeof(struct usb_device_info
);
109 for (i
=0; i
<usbdevice
->descriptor
.bNumConfigurations
; i
++)
111 struct usb_config_descriptor
*conf_desc
= &usbdevice
->config
[i
];
112 WDU_INTERFACE
**pInterfaces
;
113 WDU_ALTERNATE_SETTING
**pAlternateSettings
[conf_desc
->bNumInterfaces
];
114 WDU_ALTERNATE_SETTING
**pActiveAltSetting
[conf_desc
->bNumInterfaces
];
117 WDU_CONFIGURATION
*cfg
= (WDU_CONFIGURATION
*)(buf
+len
);
120 *pActiveConfig
= cfg
;
122 cfg
->Descriptor
.bLength
= conf_desc
->bLength
;
123 cfg
->Descriptor
.bDescriptorType
= conf_desc
->bDescriptorType
;
124 cfg
->Descriptor
.wTotalLength
= conf_desc
->wTotalLength
;
125 cfg
->Descriptor
.bNumInterfaces
= conf_desc
->bNumInterfaces
;
126 cfg
->Descriptor
.bConfigurationValue
= conf_desc
->bConfigurationValue
;
127 cfg
->Descriptor
.iConfiguration
= conf_desc
->iConfiguration
;
128 cfg
->Descriptor
.bmAttributes
= conf_desc
->bmAttributes
;
129 cfg
->Descriptor
.MaxPower
= conf_desc
->MaxPower
;
131 cfg
->dwNumInterfaces
= conf_desc
->bNumInterfaces
;
133 pInterfaces
= &(cfg
->pInterfaces
);
135 len
+= sizeof(WDU_CONFIGURATION
);
138 *pInterfaces
= (WDU_INTERFACE
*)(buf
+len
);
139 for (j
=0; j
<conf_desc
->bNumInterfaces
; j
++) {
140 WDU_INTERFACE
*iface
= (WDU_INTERFACE
*)(buf
+len
);
142 pActiveInterface
[j
] = iface
;
144 pAlternateSettings
[j
] = &(iface
->pAlternateSettings
);
145 iface
->dwNumAltSettings
= usbdevice
->config
[i
].interface
[j
].num_altsetting
;
146 pActiveAltSetting
[j
] = &(iface
->pActiveAltSetting
);
148 len
+= sizeof(WDU_INTERFACE
);
151 len
+= sizeof(WDU_INTERFACE
) * conf_desc
->bNumInterfaces
;
154 for (j
=0; j
<conf_desc
->bNumInterfaces
; j
++)
156 struct usb_interface
*interface
= &usbdevice
->config
[i
].interface
[j
];
159 *pAlternateSettings
[j
] = (WDU_ALTERNATE_SETTING
*)(buf
+len
);
161 *pActiveAltSetting
[j
] = (WDU_ALTERNATE_SETTING
*)(buf
+len
);
164 for(k
=0; k
<interface
->num_altsetting
; k
++)
166 unsigned char bNumEndpoints
= interface
->altsetting
[k
].bNumEndpoints
;
167 WDU_ENDPOINT_DESCRIPTOR
**pEndpointDescriptors
;
168 WDU_PIPE_INFO
**pPipes
;
171 WDU_ALTERNATE_SETTING
*altset
= (WDU_ALTERNATE_SETTING
*)(buf
+len
);
173 altset
->Descriptor
.bLength
= interface
->altsetting
[k
].bLength
;
174 altset
->Descriptor
.bDescriptorType
= interface
->altsetting
[k
].bDescriptorType
;
175 altset
->Descriptor
.bInterfaceNumber
= interface
->altsetting
[k
].bInterfaceNumber
;
176 altset
->Descriptor
.bAlternateSetting
= interface
->altsetting
[k
].bAlternateSetting
;
177 altset
->Descriptor
.bNumEndpoints
= interface
->altsetting
[k
].bNumEndpoints
;
178 altset
->Descriptor
.bInterfaceClass
= interface
->altsetting
[k
].bInterfaceClass
;
179 altset
->Descriptor
.bInterfaceSubClass
= interface
->altsetting
[k
].bInterfaceSubClass
;
180 altset
->Descriptor
.bInterfaceProtocol
= interface
->altsetting
[k
].bInterfaceProtocol
;
181 altset
->Descriptor
.iInterface
= interface
->altsetting
[k
].iInterface
;
182 pEndpointDescriptors
= &(altset
->pEndpointDescriptors
);
183 pPipes
= &(altset
->pPipes
);
186 len
+=sizeof(WDU_ALTERNATE_SETTING
);
189 *pEndpointDescriptors
= (WDU_ENDPOINT_DESCRIPTOR
*)(buf
+len
);
190 for (l
= 0; l
< bNumEndpoints
; l
++) {
191 WDU_ENDPOINT_DESCRIPTOR
*ed
= (WDU_ENDPOINT_DESCRIPTOR
*)(buf
+len
);
193 ed
->bLength
= interface
->altsetting
[k
].endpoint
[l
].bLength
;
194 ed
->bDescriptorType
= interface
->altsetting
[k
].endpoint
[l
].bDescriptorType
;
195 ed
->bEndpointAddress
= interface
->altsetting
[k
].endpoint
[l
].bEndpointAddress
;
196 ed
->bmAttributes
= interface
->altsetting
[k
].endpoint
[l
].bmAttributes
;
197 ed
->wMaxPacketSize
= interface
->altsetting
[k
].endpoint
[l
].wMaxPacketSize
;
198 ed
->bInterval
= interface
->altsetting
[k
].endpoint
[l
].bInterval
;
200 len
+= sizeof(WDU_ENDPOINT_DESCRIPTOR
);
203 *pPipes
= (WDU_PIPE_INFO
*)(buf
+len
);
204 for (l
= 0; l
< bNumEndpoints
; l
++) {
205 WDU_PIPE_INFO
*pi
= (WDU_PIPE_INFO
*)(buf
+len
);
207 pi
->dwNumber
= interface
->altsetting
[k
].endpoint
[l
].bEndpointAddress
;
208 pi
->dwMaximumPacketSize
= WDU_GET_MAX_PACKET_SIZE(interface
->altsetting
[k
].endpoint
[l
].wMaxPacketSize
);
209 pi
->type
= interface
->altsetting
[k
].endpoint
[l
].bmAttributes
& USB_ENDPOINT_TYPE_MASK
;
210 if (pi
->type
== PIPE_TYPE_CONTROL
)
211 pi
->direction
= WDU_DIR_IN_OUT
;
214 pi
->direction
= interface
->altsetting
[k
].endpoint
[l
].bEndpointAddress
& USB_ENDPOINT_DIR_MASK
? WDU_DIR_IN
: WDU_DIR_OUT
;
217 pi
->dwInterval
= interface
->altsetting
[k
].endpoint
[l
].bInterval
;
219 len
+= sizeof(WDU_PIPE_INFO
);
222 len
+=(sizeof(WDU_ENDPOINT_DESCRIPTOR
)+sizeof(WDU_PIPE_INFO
))*bNumEndpoints
;
231 int do_wdioctl(int fd
, unsigned int request
, unsigned char *wdioctl
) {
232 struct header_struct
* wdheader
= (struct header_struct
*)wdioctl
;
233 struct version_struct
*version
;
236 if (wdheader
->magic
!= MAGIC
) {
237 fprintf(stderr
,"!!!ERROR: magic header does not match!!!\n");
238 return (*ioctl_func
) (fd
, request
, wdioctl
);
243 version
= (struct version_struct
*)(wdheader
->data
);
244 strcpy(version
->version
, "WinDriver no more");
245 version
->versionul
= 802;
246 DPRINTF("VERSION\n");
250 DPRINTF("LICENSE\n");
254 /* TODO: Implement for LPT-support */
257 struct card_register
* cr
= (struct card_register
*)(wdheader
->data
);
260 DPRINTF("CARD_REGISTER\n");
264 DPRINTF("in USB_TRANSFER");
266 struct usb_transfer
*ut
= (struct usb_transfer
*)(wdheader
->data
);
269 DPRINTF(" unique: %lu, pipe: %lu, read: %lu, options: %lx, size: %lu, timeout: %lx\n",
270 ut
->dwUniqueID
, ut
->dwPipeNum
, ut
->fRead
,
271 ut
->dwOptions
, ut
->dwBufferSize
, ut
->dwTimeout
);
272 DPRINTF("setup packet: ");
273 hexdump(ut
->SetupPacket
, 8);
275 if (!ut
->fRead
&& ut
->dwBufferSize
)
277 hexdump(ut
->pBuffer
, ut
->dwBufferSize
);
282 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
284 /* http://www.jungo.com/support/documentation/windriver/802/wdusb_man_mhtml/node55.html#SECTION001213000000000000000 */
285 if (ut
->dwPipeNum
== 0) { /* control pipe */
286 int requesttype
, request
, value
, index
, size
;
287 requesttype
= ut
->SetupPacket
[0];
288 request
= ut
->SetupPacket
[1];
289 value
= ut
->SetupPacket
[2] | (ut
->SetupPacket
[3] << 8);
290 index
= ut
->SetupPacket
[4] | (ut
->SetupPacket
[5] << 8);
291 size
= ut
->SetupPacket
[6] | (ut
->SetupPacket
[7] << 8);
292 DPRINTF("requesttype: %x, request: %x, value: %u, index: %u, size: %u\n", requesttype
, request
, value
, index
, size
);
293 ret
= usb_control_msg(usb_devhandle
, requesttype
, request
, value
, index
, ut
->pBuffer
, size
, ut
->dwTimeout
);
296 ret
= usb_bulk_read(usb_devhandle
, ut
->dwPipeNum
, ut
->pBuffer
, ut
->dwBufferSize
, ut
->dwTimeout
);
299 ret
= usb_bulk_write(usb_devhandle
, ut
->dwPipeNum
, ut
->pBuffer
, ut
->dwBufferSize
, ut
->dwTimeout
);
304 fprintf(stderr
, "usb_transfer: %d (%s)\n", ret
, usb_strerror());
306 ut
->dwBytesTransferred
= ret
;
312 DPRINTF("Transferred: %lu (%s)\n",ut
->dwBytesTransferred
, (ut
->fRead
?"read":"write"));
313 if (ut
->fRead
&& ut
->dwBytesTransferred
)
316 hexdump(ut
->pBuffer
, ut
->dwBytesTransferred
);
323 DPRINTF("INT_ENABLE\n");
325 struct interrupt
*it
= (struct interrupt
*)(wdheader
->data
);
327 DPRINTF("Handle: %lu, Options: %lx, ncmds: %lu, enableok: %lu, count: %lu, lost: %lu, stopped: %lu\n",
328 it
->hInterrupt
, it
->dwOptions
,
329 it
->dwCmds
, it
->fEnableOk
, it
->dwCounter
,
330 it
->dwLost
, it
->fStopped
);
334 pthread_mutex_trylock(&int_wait
);
340 DPRINTF("INT_DISABLE\n");
342 struct interrupt
*it
= (struct interrupt
*)(wdheader
->data
);
344 DPRINTF("Handle: %lu, Options: %lx, ncmds: %lu, enableok: %lu, count: %lu, lost: %lu, stopped: %lu\n",
345 it
->hInterrupt
, it
->dwOptions
,
346 it
->dwCmds
, it
->fEnableOk
, it
->dwCounter
,
347 it
->dwLost
, it
->fStopped
);
349 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
354 pthread_mutex_unlock(&int_wait
);
356 DPRINTF("Handle: %lu, Options: %lx, ncmds: %lu, enableok: %lu, count: %lu, lost: %lu, stopped: %lu\n",
357 it
->hInterrupt
, it
->dwOptions
,
358 it
->dwCmds
, it
->fEnableOk
, it
->dwCounter
,
359 it
->dwLost
, it
->fStopped
);
363 case USB_SET_INTERFACE
:
364 DPRINTF("USB_SET_INTERFACE\n");
366 struct usb_set_interface
*usi
= (struct usb_set_interface
*)(wdheader
->data
);
368 DPRINTF("unique: %lu, interfacenum: %lu, alternatesetting: %lu, options: %lx\n",
369 usi
->dwUniqueID
, usi
->dwInterfaceNum
,
370 usi
->dwAlternateSetting
, usi
->dwOptions
);
372 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
376 usb_devhandle
= usb_open(usbdevice
);
378 /* FIXME: Select right interface! */
379 ret
= usb_claim_interface(usb_devhandle
, usbdevice
->config
[0].interface
[usi
->dwInterfaceNum
].altsetting
[usi
->dwAlternateSetting
].bInterfaceNumber
);
382 ret
= usb_set_altinterface(usb_devhandle
, usi
->dwAlternateSetting
);
384 fprintf(stderr
, "usb_set_altinterface: %d\n", ret
);
386 fprintf(stderr
, "usb_set_configuration: %d (%s)\n", ret
, usb_strerror());
389 fprintf(stderr
, "usb_claim_interface: %d -> %d (%s)\n",
390 usbdevice
->config
[0].interface
[usi
->dwInterfaceNum
].altsetting
[usi
->dwAlternateSetting
].bInterfaceNumber
,
391 ret
, usb_strerror());
395 DPRINTF("unique: %lu, interfacenum: %lu, alternatesetting: %lu, options: %lx\n",
396 usi
->dwUniqueID
, usi
->dwInterfaceNum
,
397 usi
->dwAlternateSetting
, usi
->dwOptions
);
401 case USB_GET_DEVICE_DATA
:
402 DPRINTF("USB_GET_DEVICE_DATA\n");
404 struct usb_get_device_data
*ugdd
= (struct usb_get_device_data
*)(wdheader
->data
);
407 DPRINTF("unique: %lu, bytes: %lu, options: %lx\n",
408 ugdd
->dwUniqueID
, ugdd
->dwBytes
,
411 pSize
= ugdd
->dwBytes
;
412 if (!ugdd
->dwBytes
) {
414 ugdd
->dwBytes
= usb_deviceinfo(NULL
);
417 usb_deviceinfo((unsigned char*)ugdd
->pBuf
);
423 DPRINTF("EVENT_REGISTER\n");
425 struct event
*e
= (struct event
*)(wdheader
->data
);
429 DPRINTF("handle: %lu, action: %lu, status: %lu, eventid: %lu, cardtype: %lu, kplug: %lu, options: %lu, dev: %lx:%lx, unique: %lu, ver: %lu, nummatch: %lu\n",
430 e
->handle
, e
->dwAction
,
431 e
->dwStatus
, e
->dwEventId
, e
->dwCardType
,
432 e
->hKernelPlugIn
, e
->dwOptions
,
433 e
->u
.Usb
.deviceId
.dwVendorId
,
434 e
->u
.Usb
.deviceId
.dwProductId
,
435 e
->u
.Usb
.dwUniqueID
, e
->dwEventVer
,
436 e
->dwNumMatchTables
);
438 for (i
= 0; i
< e
->dwNumMatchTables
; i
++) {
440 DPRINTF("match: dev: %04x:%04x, class: %x, subclass: %x, intclass: %x, intsubclass: %x, intproto: %x\n",
441 e
->matchTables
[i
].VendorId
,
442 e
->matchTables
[i
].ProductId
,
443 e
->matchTables
[i
].bDeviceClass
,
444 e
->matchTables
[i
].bDeviceSubClass
,
445 e
->matchTables
[i
].bInterfaceClass
,
446 e
->matchTables
[i
].bInterfaceSubClass
,
447 e
->matchTables
[i
].bInterfaceProtocol
);
449 for (bus
= busses
; bus
; bus
= bus
->next
) {
450 struct usb_device
*dev
;
452 for (dev
= bus
->devices
; dev
; dev
= dev
->next
) {
453 struct usb_device_descriptor
*desc
= &(dev
->descriptor
);
455 if((desc
->idVendor
== e
->matchTables
[i
].VendorId
) &&
456 (desc
->idProduct
== e
->matchTables
[i
].ProductId
) &&
457 (desc
->bDeviceClass
== e
->matchTables
[i
].bDeviceClass
) &&
458 (desc
->bDeviceSubClass
== e
->matchTables
[i
].bDeviceSubClass
)) {
460 for (ac
= 0; ac
< desc
->bNumConfigurations
; ac
++) {
461 struct usb_interface
*interface
= dev
->config
[ac
].interface
;
464 for (ai
= 0; ai
< interface
->num_altsetting
; ai
++) {
466 DPRINTF("intclass: %x, intsubclass: %x, intproto: %x\n",
467 interface
->altsetting
[i
].bInterfaceClass
,
468 interface
->altsetting
[i
].bInterfaceSubClass
,
469 interface
->altsetting
[i
].bInterfaceProtocol
);
471 if ((interface
->altsetting
[ai
].bInterfaceSubClass
== e
->matchTables
[i
].bInterfaceSubClass
) &&
472 (interface
->altsetting
[ai
].bInterfaceProtocol
== e
->matchTables
[i
].bInterfaceProtocol
)){
473 /* TODO: check interfaceClass! */
474 DPRINTF("found device with libusb\n");
476 card_type
= e
->dwCardType
;
486 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
492 DPRINTF("handle: %lu, action: %lu, status: %lu, eventid: %lu, cardtype: %lu, kplug: %lu, options: %lu, dev: %lx:%lx, unique: %lu, ver: %lu, nummatch: %lu\n",
493 e
->handle
, e
->dwAction
,
494 e
->dwStatus
, e
->dwEventId
, e
->dwCardType
,
495 e
->hKernelPlugIn
, e
->dwOptions
,
496 e
->u
.Usb
.deviceId
.dwVendorId
,
497 e
->u
.Usb
.deviceId
.dwProductId
,
498 e
->u
.Usb
.dwUniqueID
, e
->dwEventVer
,
499 e
->dwNumMatchTables
);
501 for (i
= 0; i
< e
->dwNumMatchTables
; i
++)
502 DPRINTF("match: dev: %04x:%04x, class: %x, subclass: %x, intclass: %x, intsubclass: %x, intproto: %x\n",
503 e
->matchTables
[i
].VendorId
,
504 e
->matchTables
[i
].ProductId
,
505 e
->matchTables
[i
].bDeviceClass
,
506 e
->matchTables
[i
].bDeviceSubClass
,
507 e
->matchTables
[i
].bInterfaceClass
,
508 e
->matchTables
[i
].bInterfaceSubClass
,
509 e
->matchTables
[i
].bInterfaceProtocol
);
515 DPRINTF("TRANSFER\n");
517 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
521 case EVENT_UNREGISTER
:
522 DPRINTF("EVENT_UNREGISTER\n");
524 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
529 DPRINTF("INT_WAIT\n");
531 struct interrupt
*it
= (struct interrupt
*)(wdheader
->data
);
533 DPRINTF("Handle: %lu, Options: %lx, ncmds: %lu, enableok: %lu, count: %lu, lost: %lu, stopped: %lu\n",
534 it
->hInterrupt
, it
->dwOptions
,
535 it
->dwCmds
, it
->fEnableOk
, it
->dwCounter
,
536 it
->dwLost
, it
->fStopped
);
539 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
542 if (it
->dwCounter
== 0) {
545 pthread_mutex_lock(&int_wait
);
546 pthread_mutex_unlock(&int_wait
);
549 pthread_mutex_lock(&int_wait
);
550 pthread_mutex_unlock(&int_wait
);
554 DPRINTF("INT_WAIT_RETURN: Handle: %lu, Options: %lx, ncmds: %lu, enableok: %lu, count: %lu, lost: %lu, stopped: %lu\n",
555 it
->hInterrupt
, it
->dwOptions
, it
->dwCmds
,
556 it
->fEnableOk
, it
->dwCounter
, it
->dwLost
,
561 case CARD_UNREGISTER
:
562 DPRINTF("CARD_UNREGISTER\n");
564 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
569 DPRINTF("EVENT_PULL\n");
571 struct event
*e
= (struct event
*)(wdheader
->data
);
575 DPRINTF("handle: %lu, action: %lu, status: %lu, eventid: %lu, cardtype: %lx, kplug: %lu, options: %lu, dev: %lx:%lx, unique: %lu, ver: %lu, nummatch: %lu\n",
576 e
->handle
, e
->dwAction
, e
->dwStatus
,
577 e
->dwEventId
, e
->dwCardType
, e
->hKernelPlugIn
,
578 e
->dwOptions
, e
->u
.Usb
.deviceId
.dwVendorId
,
579 e
->u
.Usb
.deviceId
.dwProductId
,
580 e
->u
.Usb
.dwUniqueID
, e
->dwEventVer
,
581 e
->dwNumMatchTables
);
583 for (i
= 0; i
< e
->dwNumMatchTables
; i
++)
584 DPRINTF("match: dev: %04x:%04x, class: %x, subclass: %x, intclass: %x, intsubclass: %x, intproto: %x\n",
585 e
->matchTables
[i
].VendorId
,
586 e
->matchTables
[i
].ProductId
,
587 e
->matchTables
[i
].bDeviceClass
,
588 e
->matchTables
[i
].bDeviceSubClass
,
589 e
->matchTables
[i
].bInterfaceClass
,
590 e
->matchTables
[i
].bInterfaceSubClass
,
591 e
->matchTables
[i
].bInterfaceProtocol
);
595 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
598 struct usb_interface
*interface
= usbdevice
->config
->interface
;
600 e
->dwCardType
= card_type
;
603 e
->u
.Usb
.dwUniqueID
= 110;
604 e
->matchTables
[0].VendorId
= usbdevice
->descriptor
.idVendor
;
605 e
->matchTables
[0].ProductId
= usbdevice
->descriptor
.idProduct
;
606 e
->matchTables
[0].bDeviceClass
= usbdevice
->descriptor
.bDeviceClass
;
607 e
->matchTables
[0].bDeviceSubClass
= usbdevice
->descriptor
.bDeviceSubClass
;
608 e
->matchTables
[0].bInterfaceClass
= interface
->altsetting
[0].bInterfaceClass
;
609 e
->matchTables
[0].bInterfaceSubClass
= interface
->altsetting
[0].bInterfaceSubClass
;
610 e
->matchTables
[0].bInterfaceProtocol
= interface
->altsetting
[0].bInterfaceProtocol
;
615 DPRINTF("handle: %lu, action: %lu, status: %lu, eventid: %lu, cardtype: %lx, kplug: %lu, options: %lu, dev: %lx:%lx, unique: %lu, ver: %lu, nummatch: %lu\n",
616 e
->handle
, e
->dwAction
, e
->dwStatus
,
617 e
->dwEventId
, e
->dwCardType
, e
->hKernelPlugIn
,
618 e
->dwOptions
, e
->u
.Usb
.deviceId
.dwVendorId
,
619 e
->u
.Usb
.deviceId
.dwProductId
,
620 e
->u
.Usb
.dwUniqueID
, e
->dwEventVer
,
621 e
->dwNumMatchTables
);
623 for (i
= 0; i
< e
->dwNumMatchTables
; i
++)
624 DPRINTF("match: dev: %04x:%04x, class: %x, subclass: %x, intclass: %x, intsubclass: %x, intproto: %x\n",
625 e
->matchTables
[i
].VendorId
,
626 e
->matchTables
[i
].ProductId
,
627 e
->matchTables
[i
].bDeviceClass
,
628 e
->matchTables
[i
].bDeviceSubClass
,
629 e
->matchTables
[i
].bInterfaceClass
,
630 e
->matchTables
[i
].bInterfaceSubClass
,
631 e
->matchTables
[i
].bInterfaceProtocol
);
638 fprintf(stderr
,"!!!Unsupported IOCTL: %x!!!\n", request
);
640 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
648 int ioctl(int fd
, int request
, ...) {
654 ioctl_func
= (int (*) (int, int, void *)) dlsym (RTLD_NEXT
, "ioctl");
656 va_start (args
, request
);
657 argp
= va_arg (args
, void *);
661 ret
= do_wdioctl(fd
, request
, argp
);
663 ret
= (*ioctl_func
) (fd
, request
, argp
);
668 int open (const char *pathname
, int flags
, ...) {
669 static int (*func
) (const char *, int, mode_t
) = NULL
;
675 func
= (int (*) (const char *, int, mode_t
)) dlsym (RTLD_NEXT
, "open");
677 if (flags
& O_CREAT
) {
678 va_start(args
, flags
);
679 mode
= va_arg(args
, mode_t
);
683 if (!strcmp (pathname
, "/dev/windrvr6")) {
684 DPRINTF("opening windrvr6\n");
686 windrvrfd
= fd
= (*func
) ("/dev/null", flags
, mode
);
688 windrvrfd
= fd
= (*func
) (pathname
, flags
, mode
);
695 busses
= usb_get_busses();
701 return (*func
) (pathname
, flags
, mode
);
705 static int (*func
) (int) = NULL
;
708 func
= (int (*) (int)) dlsym(RTLD_NEXT
, "close");
710 if (fd
== windrvrfd
) {
711 DPRINTF("close windrvrfd\n");
718 FILE *fopen(const char *path
, const char *mode
) {
720 static FILE* (*func
) (const char*, const char*) = NULL
;
723 func
= (FILE* (*) (const char*, const char*)) dlsym(RTLD_NEXT
, "fopen");
725 ret
= (*func
) (path
, mode
);
727 if (!strcmp (path
, "/proc/modules")) {
728 DPRINTF("opening /proc/modules\n");
738 char *fgets(char *s
, int size
, FILE *stream
) {
739 static char* (*func
) (char*, int, FILE*) = NULL
;
740 const char modules
[][256] = {"windrvr6 1 0 - Live 0xdeadbeef\n", "parport_pc 1 0 - Live 0xdeadbeef\n"};
745 func
= (char* (*) (char*, int, FILE*)) dlsym(RTLD_NEXT
, "fgets");
747 if (modulesfp
== stream
) {
748 if (modules_read
< sizeof(modules
)) {
749 strcpy(s
, modules
[modules_read
]);
754 ret
= (*func
)(s
,size
,stream
);
760 int fclose(FILE *fp
) {
761 static int (*func
) (FILE*) = NULL
;
764 func
= (int (*) (FILE*)) dlsym(RTLD_NEXT
, "fclose");
766 if (fp
== modulesfp
) {
773 int access(const char *pathname
, int mode
) {
774 static int (*func
) (const char*, int);
777 func
= (int (*) (const char*, int)) dlsym(RTLD_NEXT
, "access");
779 if (!strcmp(pathname
, "/dev/windrvr6")) {
782 return (*func
)(pathname
, mode
);