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>
41 #include "usb-driver.h"
43 static int (*ioctl_func
) (int, int, void *) = NULL
;
44 static int windrvrfd
= -1;
45 FILE *modulesfp
= NULL
;
46 static int modules_read
= 0;
47 static struct usb_bus
*busses
= NULL
;
48 static struct usb_device
*usbdevice
;
49 static usb_dev_handle
*usb_devhandle
= NULL
;
50 static int usbinterface
= -1;
51 static unsigned long card_type
;
52 static int ints_enabled
= 0;
53 static pthread_mutex_t int_wait
= PTHREAD_MUTEX_INITIALIZER
;
58 #define DPRINTF(format, args...) fprintf(stderr, format, ##args)
59 void hexdump(unsigned char *buf
, int len
) {
62 for(i
=0; i
<len
; i
++) {
63 fprintf(stderr
,"%02x ", buf
[i
]);
70 #define DPRINTF(format, args...)
73 int usb_deviceinfo(unsigned char *buf
) {
76 WDU_CONFIGURATION
**pConfigs
, **pActiveConfig
;
77 WDU_INTERFACE
**pActiveInterface
;
80 struct usb_device_info
*udi
= (struct usb_device_info
*)(buf
+len
);
82 udi
->Descriptor
.bLength
= sizeof(WDU_DEVICE_DESCRIPTOR
);
83 udi
->Descriptor
.bDescriptorType
= usbdevice
->descriptor
.bDescriptorType
;
84 udi
->Descriptor
.bcdUSB
= usbdevice
->descriptor
.bcdUSB
;
85 udi
->Descriptor
.bDeviceClass
= usbdevice
->descriptor
.bDeviceClass
;
86 udi
->Descriptor
.bDeviceSubClass
= usbdevice
->descriptor
.bDeviceSubClass
;
87 udi
->Descriptor
.bDeviceProtocol
= usbdevice
->descriptor
.bDeviceProtocol
;
88 udi
->Descriptor
.bMaxPacketSize0
= usbdevice
->descriptor
.bMaxPacketSize0
;
89 udi
->Descriptor
.idVendor
= usbdevice
->descriptor
.idVendor
;
90 udi
->Descriptor
.idProduct
= usbdevice
->descriptor
.idProduct
;
91 udi
->Descriptor
.bcdDevice
= usbdevice
->descriptor
.bcdDevice
;
92 udi
->Descriptor
.iManufacturer
= usbdevice
->descriptor
.iManufacturer
;
93 udi
->Descriptor
.iProduct
= usbdevice
->descriptor
.iProduct
;
94 udi
->Descriptor
.iSerialNumber
= usbdevice
->descriptor
.iSerialNumber
;
95 udi
->Descriptor
.bNumConfigurations
= usbdevice
->descriptor
.bNumConfigurations
;
97 /* TODO: Fix Pipe0! */
98 udi
->Pipe0
.dwNumber
= 0x00;
99 udi
->Pipe0
.dwMaximumPacketSize
= usbdevice
->descriptor
.bMaxPacketSize0
;
101 udi
->Pipe0
.direction
= WDU_DIR_IN_OUT
;
102 udi
->Pipe0
.dwInterval
= 0;
104 pConfigs
= &(udi
->pConfigs
);
105 pActiveConfig
= &(udi
->pActiveConfig
);
106 pActiveInterface
= &(udi
->pActiveInterface
[0]);
109 len
= sizeof(struct usb_device_info
);
111 for (i
=0; i
<usbdevice
->descriptor
.bNumConfigurations
; i
++)
113 struct usb_config_descriptor
*conf_desc
= &usbdevice
->config
[i
];
114 WDU_INTERFACE
**pInterfaces
;
115 WDU_ALTERNATE_SETTING
**pAlternateSettings
[conf_desc
->bNumInterfaces
];
116 WDU_ALTERNATE_SETTING
**pActiveAltSetting
[conf_desc
->bNumInterfaces
];
119 WDU_CONFIGURATION
*cfg
= (WDU_CONFIGURATION
*)(buf
+len
);
122 *pActiveConfig
= cfg
;
124 cfg
->Descriptor
.bLength
= conf_desc
->bLength
;
125 cfg
->Descriptor
.bDescriptorType
= conf_desc
->bDescriptorType
;
126 cfg
->Descriptor
.wTotalLength
= conf_desc
->wTotalLength
;
127 cfg
->Descriptor
.bNumInterfaces
= conf_desc
->bNumInterfaces
;
128 cfg
->Descriptor
.bConfigurationValue
= conf_desc
->bConfigurationValue
;
129 cfg
->Descriptor
.iConfiguration
= conf_desc
->iConfiguration
;
130 cfg
->Descriptor
.bmAttributes
= conf_desc
->bmAttributes
;
131 cfg
->Descriptor
.MaxPower
= conf_desc
->MaxPower
;
133 cfg
->dwNumInterfaces
= conf_desc
->bNumInterfaces
;
135 pInterfaces
= &(cfg
->pInterfaces
);
137 len
+= sizeof(WDU_CONFIGURATION
);
140 *pInterfaces
= (WDU_INTERFACE
*)(buf
+len
);
141 for (j
=0; j
<conf_desc
->bNumInterfaces
; j
++) {
142 WDU_INTERFACE
*iface
= (WDU_INTERFACE
*)(buf
+len
);
144 pActiveInterface
[j
] = iface
;
146 pAlternateSettings
[j
] = &(iface
->pAlternateSettings
);
147 iface
->dwNumAltSettings
= usbdevice
->config
[i
].interface
[j
].num_altsetting
;
148 pActiveAltSetting
[j
] = &(iface
->pActiveAltSetting
);
150 len
+= sizeof(WDU_INTERFACE
);
153 len
+= sizeof(WDU_INTERFACE
) * conf_desc
->bNumInterfaces
;
156 for (j
=0; j
<conf_desc
->bNumInterfaces
; j
++)
158 struct usb_interface
*interface
= &usbdevice
->config
[i
].interface
[j
];
161 *pAlternateSettings
[j
] = (WDU_ALTERNATE_SETTING
*)(buf
+len
);
163 *pActiveAltSetting
[j
] = (WDU_ALTERNATE_SETTING
*)(buf
+len
);
166 for(k
=0; k
<interface
->num_altsetting
; k
++)
168 unsigned char bNumEndpoints
= interface
->altsetting
[k
].bNumEndpoints
;
169 WDU_ENDPOINT_DESCRIPTOR
**pEndpointDescriptors
;
170 WDU_PIPE_INFO
**pPipes
;
173 WDU_ALTERNATE_SETTING
*altset
= (WDU_ALTERNATE_SETTING
*)(buf
+len
);
175 altset
->Descriptor
.bLength
= interface
->altsetting
[k
].bLength
;
176 altset
->Descriptor
.bDescriptorType
= interface
->altsetting
[k
].bDescriptorType
;
177 altset
->Descriptor
.bInterfaceNumber
= interface
->altsetting
[k
].bInterfaceNumber
;
178 altset
->Descriptor
.bAlternateSetting
= interface
->altsetting
[k
].bAlternateSetting
;
179 altset
->Descriptor
.bNumEndpoints
= interface
->altsetting
[k
].bNumEndpoints
;
180 altset
->Descriptor
.bInterfaceClass
= interface
->altsetting
[k
].bInterfaceClass
;
181 altset
->Descriptor
.bInterfaceSubClass
= interface
->altsetting
[k
].bInterfaceSubClass
;
182 altset
->Descriptor
.bInterfaceProtocol
= interface
->altsetting
[k
].bInterfaceProtocol
;
183 altset
->Descriptor
.iInterface
= interface
->altsetting
[k
].iInterface
;
184 pEndpointDescriptors
= &(altset
->pEndpointDescriptors
);
185 pPipes
= &(altset
->pPipes
);
188 len
+=sizeof(WDU_ALTERNATE_SETTING
);
191 *pEndpointDescriptors
= (WDU_ENDPOINT_DESCRIPTOR
*)(buf
+len
);
192 for (l
= 0; l
< bNumEndpoints
; l
++) {
193 WDU_ENDPOINT_DESCRIPTOR
*ed
= (WDU_ENDPOINT_DESCRIPTOR
*)(buf
+len
);
195 ed
->bLength
= interface
->altsetting
[k
].endpoint
[l
].bLength
;
196 ed
->bDescriptorType
= interface
->altsetting
[k
].endpoint
[l
].bDescriptorType
;
197 ed
->bEndpointAddress
= interface
->altsetting
[k
].endpoint
[l
].bEndpointAddress
;
198 ed
->bmAttributes
= interface
->altsetting
[k
].endpoint
[l
].bmAttributes
;
199 ed
->wMaxPacketSize
= interface
->altsetting
[k
].endpoint
[l
].wMaxPacketSize
;
200 ed
->bInterval
= interface
->altsetting
[k
].endpoint
[l
].bInterval
;
202 len
+= sizeof(WDU_ENDPOINT_DESCRIPTOR
);
205 *pPipes
= (WDU_PIPE_INFO
*)(buf
+len
);
206 for (l
= 0; l
< bNumEndpoints
; l
++) {
207 WDU_PIPE_INFO
*pi
= (WDU_PIPE_INFO
*)(buf
+len
);
209 pi
->dwNumber
= interface
->altsetting
[k
].endpoint
[l
].bEndpointAddress
;
210 pi
->dwMaximumPacketSize
= WDU_GET_MAX_PACKET_SIZE(interface
->altsetting
[k
].endpoint
[l
].wMaxPacketSize
);
211 pi
->type
= interface
->altsetting
[k
].endpoint
[l
].bmAttributes
& USB_ENDPOINT_TYPE_MASK
;
212 if (pi
->type
== PIPE_TYPE_CONTROL
)
213 pi
->direction
= WDU_DIR_IN_OUT
;
216 pi
->direction
= interface
->altsetting
[k
].endpoint
[l
].bEndpointAddress
& USB_ENDPOINT_DIR_MASK
? WDU_DIR_IN
: WDU_DIR_OUT
;
219 pi
->dwInterval
= interface
->altsetting
[k
].endpoint
[l
].bInterval
;
221 len
+= sizeof(WDU_PIPE_INFO
);
224 len
+=(sizeof(WDU_ENDPOINT_DESCRIPTOR
)+sizeof(WDU_PIPE_INFO
))*bNumEndpoints
;
233 int do_wdioctl(int fd
, unsigned int request
, unsigned char *wdioctl
) {
234 struct header_struct
* wdheader
= (struct header_struct
*)wdioctl
;
235 struct version_struct
*version
;
238 if (wdheader
->magic
!= MAGIC
) {
239 fprintf(stderr
,"!!!ERROR: magic header does not match!!!\n");
240 return (*ioctl_func
) (fd
, request
, wdioctl
);
243 switch(request
& ~(0xc0000000)) {
245 version
= (struct version_struct
*)(wdheader
->data
);
246 strcpy(version
->version
, "WinDriver no more");
247 version
->versionul
= 802;
248 DPRINTF("VERSION\n");
252 DPRINTF("LICENSE\n");
255 case CARD_REGISTER_OLD
:
257 /* TODO: Implement for LPT-support */
260 struct card_register
* cr
= (struct card_register
*)(wdheader
->data
);
263 DPRINTF("CARD_REGISTER\n");
267 DPRINTF("in USB_TRANSFER");
269 struct usb_transfer
*ut
= (struct usb_transfer
*)(wdheader
->data
);
272 DPRINTF(" unique: %lu, pipe: %lu, read: %lu, options: %lx, size: %lu, timeout: %lx\n",
273 ut
->dwUniqueID
, ut
->dwPipeNum
, ut
->fRead
,
274 ut
->dwOptions
, ut
->dwBufferSize
, ut
->dwTimeout
);
275 DPRINTF("setup packet: ");
276 hexdump(ut
->SetupPacket
, 8);
278 if (!ut
->fRead
&& ut
->dwBufferSize
)
280 hexdump(ut
->pBuffer
, ut
->dwBufferSize
);
285 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
287 /* http://www.jungo.com/support/documentation/windriver/802/wdusb_man_mhtml/node55.html#SECTION001213000000000000000 */
288 if (ut
->dwPipeNum
== 0) { /* control pipe */
289 int requesttype
, request
, value
, index
, size
;
290 requesttype
= ut
->SetupPacket
[0];
291 request
= ut
->SetupPacket
[1];
292 value
= ut
->SetupPacket
[2] | (ut
->SetupPacket
[3] << 8);
293 index
= ut
->SetupPacket
[4] | (ut
->SetupPacket
[5] << 8);
294 size
= ut
->SetupPacket
[6] | (ut
->SetupPacket
[7] << 8);
295 DPRINTF("requesttype: %x, request: %x, value: %u, index: %u, size: %u\n", requesttype
, request
, value
, index
, size
);
296 ret
= usb_control_msg(usb_devhandle
, requesttype
, request
, value
, index
, ut
->pBuffer
, size
, ut
->dwTimeout
);
299 ret
= usb_bulk_read(usb_devhandle
, ut
->dwPipeNum
, ut
->pBuffer
, ut
->dwBufferSize
, ut
->dwTimeout
);
302 ret
= usb_bulk_write(usb_devhandle
, ut
->dwPipeNum
, ut
->pBuffer
, ut
->dwBufferSize
, ut
->dwTimeout
);
307 fprintf(stderr
, "usb_transfer: %d (%s)\n", ret
, usb_strerror());
309 ut
->dwBytesTransferred
= ret
;
315 DPRINTF("Transferred: %lu (%s)\n",ut
->dwBytesTransferred
, (ut
->fRead
?"read":"write"));
316 if (ut
->fRead
&& ut
->dwBytesTransferred
)
319 hexdump(ut
->pBuffer
, ut
->dwBytesTransferred
);
327 DPRINTF("INT_ENABLE\n");
329 struct interrupt
*it
= (struct interrupt
*)(wdheader
->data
);
331 DPRINTF("Handle: %lu, Options: %lx, ncmds: %lu, enableok: %lu, count: %lu, lost: %lu, stopped: %lu\n",
332 it
->hInterrupt
, it
->dwOptions
,
333 it
->dwCmds
, it
->fEnableOk
, it
->dwCounter
,
334 it
->dwLost
, it
->fStopped
);
339 pthread_mutex_trylock(&int_wait
);
345 DPRINTF("INT_DISABLE\n");
347 struct interrupt
*it
= (struct interrupt
*)(wdheader
->data
);
349 DPRINTF("Handle: %lu, Options: %lx, ncmds: %lu, enableok: %lu, count: %lu, lost: %lu, stopped: %lu\n",
350 it
->hInterrupt
, it
->dwOptions
,
351 it
->dwCmds
, it
->fEnableOk
, it
->dwCounter
,
352 it
->dwLost
, it
->fStopped
);
354 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
359 if (pthread_mutex_trylock(&int_wait
) == EBUSY
)
360 pthread_mutex_unlock(&int_wait
);
362 DPRINTF("Handle: %lu, Options: %lx, ncmds: %lu, enableok: %lu, count: %lu, lost: %lu, stopped: %lu\n",
363 it
->hInterrupt
, it
->dwOptions
,
364 it
->dwCmds
, it
->fEnableOk
, it
->dwCounter
,
365 it
->dwLost
, it
->fStopped
);
369 case USB_SET_INTERFACE
:
370 DPRINTF("USB_SET_INTERFACE\n");
372 struct usb_set_interface
*usi
= (struct usb_set_interface
*)(wdheader
->data
);
374 DPRINTF("unique: %lu, interfacenum: %lu, alternatesetting: %lu, options: %lx\n",
375 usi
->dwUniqueID
, usi
->dwInterfaceNum
,
376 usi
->dwAlternateSetting
, usi
->dwOptions
);
378 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
382 usb_devhandle
= usb_open(usbdevice
);
384 /* FIXME: Select right interface! */
385 ret
= usb_claim_interface(usb_devhandle
, usbdevice
->config
[0].interface
[usi
->dwInterfaceNum
].altsetting
[usi
->dwAlternateSetting
].bInterfaceNumber
);
388 usbinterface
= usbdevice
->config
[0].interface
[usi
->dwInterfaceNum
].altsetting
[usi
->dwAlternateSetting
].bInterfaceNumber
;
389 ret
= usb_set_altinterface(usb_devhandle
, usi
->dwAlternateSetting
);
391 fprintf(stderr
, "usb_set_altinterface: %d\n", ret
);
393 fprintf(stderr
, "usb_set_configuration: %d (%s)\n", ret
, usb_strerror());
396 fprintf(stderr
, "usb_claim_interface: %d -> %d (%s)\n",
397 usbdevice
->config
[0].interface
[usi
->dwInterfaceNum
].altsetting
[usi
->dwAlternateSetting
].bInterfaceNumber
,
398 ret
, usb_strerror());
402 DPRINTF("unique: %lu, interfacenum: %lu, alternatesetting: %lu, options: %lx\n",
403 usi
->dwUniqueID
, usi
->dwInterfaceNum
,
404 usi
->dwAlternateSetting
, usi
->dwOptions
);
408 case USB_GET_DEVICE_DATA_OLD
:
409 case USB_GET_DEVICE_DATA
:
410 DPRINTF("USB_GET_DEVICE_DATA\n");
412 struct usb_get_device_data
*ugdd
= (struct usb_get_device_data
*)(wdheader
->data
);
415 DPRINTF("unique: %lu, bytes: %lu, options: %lx\n",
416 ugdd
->dwUniqueID
, ugdd
->dwBytes
,
419 pSize
= ugdd
->dwBytes
;
420 if (!ugdd
->dwBytes
) {
422 ugdd
->dwBytes
= usb_deviceinfo(NULL
);
425 usb_deviceinfo((unsigned char*)ugdd
->pBuf
);
430 case EVENT_REGISTER_OLD
:
432 DPRINTF("EVENT_REGISTER\n");
434 struct event
*e
= (struct event
*)(wdheader
->data
);
438 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",
439 e
->handle
, e
->dwAction
,
440 e
->dwStatus
, e
->dwEventId
, e
->dwCardType
,
441 e
->hKernelPlugIn
, e
->dwOptions
,
442 e
->u
.Usb
.deviceId
.dwVendorId
,
443 e
->u
.Usb
.deviceId
.dwProductId
,
444 e
->u
.Usb
.dwUniqueID
, e
->dwEventVer
,
445 e
->dwNumMatchTables
);
447 for (i
= 0; i
< e
->dwNumMatchTables
; i
++) {
449 DPRINTF("match: dev: %04x:%04x, class: %x, subclass: %x, intclass: %x, intsubclass: %x, intproto: %x\n",
450 e
->matchTables
[i
].VendorId
,
451 e
->matchTables
[i
].ProductId
,
452 e
->matchTables
[i
].bDeviceClass
,
453 e
->matchTables
[i
].bDeviceSubClass
,
454 e
->matchTables
[i
].bInterfaceClass
,
455 e
->matchTables
[i
].bInterfaceSubClass
,
456 e
->matchTables
[i
].bInterfaceProtocol
);
458 for (bus
= busses
; bus
; bus
= bus
->next
) {
459 struct usb_device
*dev
;
461 for (dev
= bus
->devices
; dev
; dev
= dev
->next
) {
462 struct usb_device_descriptor
*desc
= &(dev
->descriptor
);
464 if((desc
->idVendor
== e
->matchTables
[i
].VendorId
) &&
465 (desc
->idProduct
== e
->matchTables
[i
].ProductId
) &&
466 (desc
->bDeviceClass
== e
->matchTables
[i
].bDeviceClass
) &&
467 (desc
->bDeviceSubClass
== e
->matchTables
[i
].bDeviceSubClass
)) {
469 for (ac
= 0; ac
< desc
->bNumConfigurations
; ac
++) {
470 struct usb_interface
*interface
= dev
->config
[ac
].interface
;
473 for (ai
= 0; ai
< interface
->num_altsetting
; ai
++) {
475 DPRINTF("intclass: %x, intsubclass: %x, intproto: %x\n",
476 interface
->altsetting
[i
].bInterfaceClass
,
477 interface
->altsetting
[i
].bInterfaceSubClass
,
478 interface
->altsetting
[i
].bInterfaceProtocol
);
480 if ((interface
->altsetting
[ai
].bInterfaceSubClass
== e
->matchTables
[i
].bInterfaceSubClass
) &&
481 (interface
->altsetting
[ai
].bInterfaceProtocol
== e
->matchTables
[i
].bInterfaceProtocol
)){
482 /* TODO: check interfaceClass! */
483 DPRINTF("found device with libusb\n");
485 card_type
= e
->dwCardType
;
495 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
501 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",
502 e
->handle
, e
->dwAction
,
503 e
->dwStatus
, e
->dwEventId
, e
->dwCardType
,
504 e
->hKernelPlugIn
, e
->dwOptions
,
505 e
->u
.Usb
.deviceId
.dwVendorId
,
506 e
->u
.Usb
.deviceId
.dwProductId
,
507 e
->u
.Usb
.dwUniqueID
, e
->dwEventVer
,
508 e
->dwNumMatchTables
);
510 for (i
= 0; i
< e
->dwNumMatchTables
; i
++)
511 DPRINTF("match: dev: %04x:%04x, class: %x, subclass: %x, intclass: %x, intsubclass: %x, intproto: %x\n",
512 e
->matchTables
[i
].VendorId
,
513 e
->matchTables
[i
].ProductId
,
514 e
->matchTables
[i
].bDeviceClass
,
515 e
->matchTables
[i
].bDeviceSubClass
,
516 e
->matchTables
[i
].bInterfaceClass
,
517 e
->matchTables
[i
].bInterfaceSubClass
,
518 e
->matchTables
[i
].bInterfaceProtocol
);
525 DPRINTF("TRANSFER\n");
527 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
531 case EVENT_UNREGISTER
:
532 DPRINTF("EVENT_UNREGISTER\n");
534 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
539 DPRINTF("INT_WAIT\n");
541 struct interrupt
*it
= (struct interrupt
*)(wdheader
->data
);
543 DPRINTF("Handle: %lu, Options: %lx, ncmds: %lu, enableok: %lu, count: %lu, lost: %lu, stopped: %lu\n",
544 it
->hInterrupt
, it
->dwOptions
,
545 it
->dwCmds
, it
->fEnableOk
, it
->dwCounter
,
546 it
->dwLost
, it
->fStopped
);
549 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
552 if (it
->dwCounter
== 0) {
555 pthread_mutex_lock(&int_wait
);
556 pthread_mutex_unlock(&int_wait
);
559 pthread_mutex_lock(&int_wait
);
560 pthread_mutex_unlock(&int_wait
);
564 DPRINTF("INT_WAIT_RETURN: Handle: %lu, Options: %lx, ncmds: %lu, enableok: %lu, count: %lu, lost: %lu, stopped: %lu\n",
565 it
->hInterrupt
, it
->dwOptions
, it
->dwCmds
,
566 it
->fEnableOk
, it
->dwCounter
, it
->dwLost
,
571 case CARD_UNREGISTER
:
572 DPRINTF("CARD_UNREGISTER\n");
574 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
579 DPRINTF("EVENT_PULL\n");
581 struct event
*e
= (struct event
*)(wdheader
->data
);
585 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",
586 e
->handle
, e
->dwAction
, e
->dwStatus
,
587 e
->dwEventId
, e
->dwCardType
, e
->hKernelPlugIn
,
588 e
->dwOptions
, e
->u
.Usb
.deviceId
.dwVendorId
,
589 e
->u
.Usb
.deviceId
.dwProductId
,
590 e
->u
.Usb
.dwUniqueID
, e
->dwEventVer
,
591 e
->dwNumMatchTables
);
593 for (i
= 0; i
< e
->dwNumMatchTables
; i
++)
594 DPRINTF("match: dev: %04x:%04x, class: %x, subclass: %x, intclass: %x, intsubclass: %x, intproto: %x\n",
595 e
->matchTables
[i
].VendorId
,
596 e
->matchTables
[i
].ProductId
,
597 e
->matchTables
[i
].bDeviceClass
,
598 e
->matchTables
[i
].bDeviceSubClass
,
599 e
->matchTables
[i
].bInterfaceClass
,
600 e
->matchTables
[i
].bInterfaceSubClass
,
601 e
->matchTables
[i
].bInterfaceProtocol
);
605 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
608 struct usb_interface
*interface
= usbdevice
->config
->interface
;
610 e
->dwCardType
= card_type
;
613 e
->u
.Usb
.dwUniqueID
= 110;
614 e
->matchTables
[0].VendorId
= usbdevice
->descriptor
.idVendor
;
615 e
->matchTables
[0].ProductId
= usbdevice
->descriptor
.idProduct
;
616 e
->matchTables
[0].bDeviceClass
= usbdevice
->descriptor
.bDeviceClass
;
617 e
->matchTables
[0].bDeviceSubClass
= usbdevice
->descriptor
.bDeviceSubClass
;
618 e
->matchTables
[0].bInterfaceClass
= interface
->altsetting
[0].bInterfaceClass
;
619 e
->matchTables
[0].bInterfaceSubClass
= interface
->altsetting
[0].bInterfaceSubClass
;
620 e
->matchTables
[0].bInterfaceProtocol
= interface
->altsetting
[0].bInterfaceProtocol
;
625 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",
626 e
->handle
, e
->dwAction
, e
->dwStatus
,
627 e
->dwEventId
, e
->dwCardType
, e
->hKernelPlugIn
,
628 e
->dwOptions
, e
->u
.Usb
.deviceId
.dwVendorId
,
629 e
->u
.Usb
.deviceId
.dwProductId
,
630 e
->u
.Usb
.dwUniqueID
, e
->dwEventVer
,
631 e
->dwNumMatchTables
);
633 for (i
= 0; i
< e
->dwNumMatchTables
; i
++)
634 DPRINTF("match: dev: %04x:%04x, class: %x, subclass: %x, intclass: %x, intsubclass: %x, intproto: %x\n",
635 e
->matchTables
[i
].VendorId
,
636 e
->matchTables
[i
].ProductId
,
637 e
->matchTables
[i
].bDeviceClass
,
638 e
->matchTables
[i
].bDeviceSubClass
,
639 e
->matchTables
[i
].bInterfaceClass
,
640 e
->matchTables
[i
].bInterfaceSubClass
,
641 e
->matchTables
[i
].bInterfaceProtocol
);
648 fprintf(stderr
,"!!!Unsupported IOCTL: %x!!!\n", request
);
650 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
658 int ioctl(int fd
, int request
, ...) {
664 ioctl_func
= (int (*) (int, int, void *)) dlsym (RTLD_NEXT
, "ioctl");
666 va_start (args
, request
);
667 argp
= va_arg (args
, void *);
671 ret
= do_wdioctl(fd
, request
, argp
);
673 ret
= (*ioctl_func
) (fd
, request
, argp
);
678 int open (const char *pathname
, int flags
, ...) {
679 static int (*func
) (const char *, int, mode_t
) = NULL
;
685 func
= (int (*) (const char *, int, mode_t
)) dlsym (RTLD_NEXT
, "open");
687 if (flags
& O_CREAT
) {
688 va_start(args
, flags
);
689 mode
= va_arg(args
, mode_t
);
693 if (!strcmp (pathname
, "/dev/windrvr6")) {
694 DPRINTF("opening windrvr6\n");
696 windrvrfd
= fd
= (*func
) ("/dev/null", flags
, mode
);
698 windrvrfd
= fd
= (*func
) (pathname
, flags
, mode
);
705 busses
= usb_get_busses();
711 return (*func
) (pathname
, flags
, mode
);
715 static int (*func
) (int) = NULL
;
718 func
= (int (*) (int)) dlsym(RTLD_NEXT
, "close");
720 if (fd
== windrvrfd
&& windrvrfd
>= 0) {
721 DPRINTF("close windrvrfd\n");
722 if (usbinterface
>= 0)
723 usb_release_interface(usb_devhandle
, usbinterface
);
726 usb_close(usb_devhandle
);
728 usb_devhandle
= NULL
;
736 FILE *fopen(const char *path
, const char *mode
) {
738 static FILE* (*func
) (const char*, const char*) = NULL
;
741 func
= (FILE* (*) (const char*, const char*)) dlsym(RTLD_NEXT
, "fopen");
743 ret
= (*func
) (path
, mode
);
745 if (!strcmp (path
, "/proc/modules")) {
746 DPRINTF("opening /proc/modules\n");
756 char *fgets(char *s
, int size
, FILE *stream
) {
757 static char* (*func
) (char*, int, FILE*) = NULL
;
758 const char modules
[][256] = {"windrvr6 1 0 - Live 0xdeadbeef\n", "parport_pc 1 0 - Live 0xdeadbeef\n"};
763 func
= (char* (*) (char*, int, FILE*)) dlsym(RTLD_NEXT
, "fgets");
765 if (modulesfp
== stream
) {
766 if (modules_read
< sizeof(modules
)) {
767 strcpy(s
, modules
[modules_read
]);
772 ret
= (*func
)(s
,size
,stream
);
778 int fclose(FILE *fp
) {
779 static int (*func
) (FILE*) = NULL
;
782 func
= (int (*) (FILE*)) dlsym(RTLD_NEXT
, "fclose");
784 if (fp
== modulesfp
) {
791 int access(const char *pathname
, int mode
) {
792 static int (*func
) (const char*, int);
795 func
= (int (*) (const char*, int)) dlsym(RTLD_NEXT
, "access");
797 if (!strcmp(pathname
, "/dev/windrvr6")) {
800 return (*func
)(pathname
, mode
);