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
);
262 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
266 DPRINTF("CARD_REGISTER\n");
270 DPRINTF("in USB_TRANSFER");
272 struct usb_transfer
*ut
= (struct usb_transfer
*)(wdheader
->data
);
275 DPRINTF(" unique: %lu, pipe: %lu, read: %lu, options: %lx, size: %lu, timeout: %lx\n",
276 ut
->dwUniqueID
, ut
->dwPipeNum
, ut
->fRead
,
277 ut
->dwOptions
, ut
->dwBufferSize
, ut
->dwTimeout
);
278 DPRINTF("setup packet: ");
279 hexdump(ut
->SetupPacket
, 8);
281 if (!ut
->fRead
&& ut
->dwBufferSize
)
283 hexdump(ut
->pBuffer
, ut
->dwBufferSize
);
288 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
290 /* http://www.jungo.com/support/documentation/windriver/802/wdusb_man_mhtml/node55.html#SECTION001213000000000000000 */
291 if (ut
->dwPipeNum
== 0) { /* control pipe */
292 int requesttype
, request
, value
, index
, size
;
293 requesttype
= ut
->SetupPacket
[0];
294 request
= ut
->SetupPacket
[1];
295 value
= ut
->SetupPacket
[2] | (ut
->SetupPacket
[3] << 8);
296 index
= ut
->SetupPacket
[4] | (ut
->SetupPacket
[5] << 8);
297 size
= ut
->SetupPacket
[6] | (ut
->SetupPacket
[7] << 8);
298 DPRINTF("requesttype: %x, request: %x, value: %u, index: %u, size: %u\n", requesttype
, request
, value
, index
, size
);
299 ret
= usb_control_msg(usb_devhandle
, requesttype
, request
, value
, index
, ut
->pBuffer
, size
, ut
->dwTimeout
);
302 ret
= usb_bulk_read(usb_devhandle
, ut
->dwPipeNum
, ut
->pBuffer
, ut
->dwBufferSize
, ut
->dwTimeout
);
305 ret
= usb_bulk_write(usb_devhandle
, ut
->dwPipeNum
, ut
->pBuffer
, ut
->dwBufferSize
, ut
->dwTimeout
);
310 fprintf(stderr
, "usb_transfer: %d (%s)\n", ret
, usb_strerror());
312 ut
->dwBytesTransferred
= ret
;
318 DPRINTF("Transferred: %lu (%s)\n",ut
->dwBytesTransferred
, (ut
->fRead
?"read":"write"));
319 if (ut
->fRead
&& ut
->dwBytesTransferred
)
322 hexdump(ut
->pBuffer
, ut
->dwBytesTransferred
);
330 DPRINTF("INT_ENABLE\n");
332 struct interrupt
*it
= (struct interrupt
*)(wdheader
->data
);
334 DPRINTF("Handle: %lu, Options: %lx, ncmds: %lu, enableok: %lu, count: %lu, lost: %lu, stopped: %lu\n",
335 it
->hInterrupt
, it
->dwOptions
,
336 it
->dwCmds
, it
->fEnableOk
, it
->dwCounter
,
337 it
->dwLost
, it
->fStopped
);
342 pthread_mutex_trylock(&int_wait
);
348 DPRINTF("INT_DISABLE\n");
350 struct interrupt
*it
= (struct interrupt
*)(wdheader
->data
);
352 DPRINTF("Handle: %lu, Options: %lx, ncmds: %lu, enableok: %lu, count: %lu, lost: %lu, stopped: %lu\n",
353 it
->hInterrupt
, it
->dwOptions
,
354 it
->dwCmds
, it
->fEnableOk
, it
->dwCounter
,
355 it
->dwLost
, it
->fStopped
);
357 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
362 if (pthread_mutex_trylock(&int_wait
) == EBUSY
)
363 pthread_mutex_unlock(&int_wait
);
365 DPRINTF("Handle: %lu, Options: %lx, ncmds: %lu, enableok: %lu, count: %lu, lost: %lu, stopped: %lu\n",
366 it
->hInterrupt
, it
->dwOptions
,
367 it
->dwCmds
, it
->fEnableOk
, it
->dwCounter
,
368 it
->dwLost
, it
->fStopped
);
372 case USB_SET_INTERFACE
:
373 DPRINTF("USB_SET_INTERFACE\n");
375 struct usb_set_interface
*usi
= (struct usb_set_interface
*)(wdheader
->data
);
377 DPRINTF("unique: %lu, interfacenum: %lu, alternatesetting: %lu, options: %lx\n",
378 usi
->dwUniqueID
, usi
->dwInterfaceNum
,
379 usi
->dwAlternateSetting
, usi
->dwOptions
);
381 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
385 usb_devhandle
= usb_open(usbdevice
);
387 /* FIXME: Select right interface! */
388 ret
= usb_claim_interface(usb_devhandle
, usbdevice
->config
[0].interface
[usi
->dwInterfaceNum
].altsetting
[usi
->dwAlternateSetting
].bInterfaceNumber
);
391 usbinterface
= usbdevice
->config
[0].interface
[usi
->dwInterfaceNum
].altsetting
[usi
->dwAlternateSetting
].bInterfaceNumber
;
392 ret
= usb_set_altinterface(usb_devhandle
, usi
->dwAlternateSetting
);
394 fprintf(stderr
, "usb_set_altinterface: %d\n", ret
);
396 fprintf(stderr
, "usb_set_configuration: %d (%s)\n", ret
, usb_strerror());
399 fprintf(stderr
, "usb_claim_interface: %d -> %d (%s)\n",
400 usbdevice
->config
[0].interface
[usi
->dwInterfaceNum
].altsetting
[usi
->dwAlternateSetting
].bInterfaceNumber
,
401 ret
, usb_strerror());
405 DPRINTF("unique: %lu, interfacenum: %lu, alternatesetting: %lu, options: %lx\n",
406 usi
->dwUniqueID
, usi
->dwInterfaceNum
,
407 usi
->dwAlternateSetting
, usi
->dwOptions
);
411 case USB_GET_DEVICE_DATA_OLD
:
412 case USB_GET_DEVICE_DATA
:
413 DPRINTF("USB_GET_DEVICE_DATA\n");
415 struct usb_get_device_data
*ugdd
= (struct usb_get_device_data
*)(wdheader
->data
);
418 DPRINTF("unique: %lu, bytes: %lu, options: %lx\n",
419 ugdd
->dwUniqueID
, ugdd
->dwBytes
,
422 pSize
= ugdd
->dwBytes
;
423 if (!ugdd
->dwBytes
) {
425 ugdd
->dwBytes
= usb_deviceinfo(NULL
);
428 usb_deviceinfo((unsigned char*)ugdd
->pBuf
);
433 case EVENT_REGISTER_OLD
:
435 DPRINTF("EVENT_REGISTER\n");
437 struct event
*e
= (struct event
*)(wdheader
->data
);
441 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",
442 e
->handle
, e
->dwAction
,
443 e
->dwStatus
, e
->dwEventId
, e
->dwCardType
,
444 e
->hKernelPlugIn
, e
->dwOptions
,
445 e
->u
.Usb
.deviceId
.dwVendorId
,
446 e
->u
.Usb
.deviceId
.dwProductId
,
447 e
->u
.Usb
.dwUniqueID
, e
->dwEventVer
,
448 e
->dwNumMatchTables
);
450 for (i
= 0; i
< e
->dwNumMatchTables
; i
++) {
452 DPRINTF("match: dev: %04x:%04x, class: %x, subclass: %x, intclass: %x, intsubclass: %x, intproto: %x\n",
453 e
->matchTables
[i
].VendorId
,
454 e
->matchTables
[i
].ProductId
,
455 e
->matchTables
[i
].bDeviceClass
,
456 e
->matchTables
[i
].bDeviceSubClass
,
457 e
->matchTables
[i
].bInterfaceClass
,
458 e
->matchTables
[i
].bInterfaceSubClass
,
459 e
->matchTables
[i
].bInterfaceProtocol
);
461 for (bus
= busses
; bus
; bus
= bus
->next
) {
462 struct usb_device
*dev
;
464 for (dev
= bus
->devices
; dev
; dev
= dev
->next
) {
465 struct usb_device_descriptor
*desc
= &(dev
->descriptor
);
467 if((desc
->idVendor
== e
->matchTables
[i
].VendorId
) &&
468 (desc
->idProduct
== e
->matchTables
[i
].ProductId
) &&
469 (desc
->bDeviceClass
== e
->matchTables
[i
].bDeviceClass
) &&
470 (desc
->bDeviceSubClass
== e
->matchTables
[i
].bDeviceSubClass
)) {
472 for (ac
= 0; ac
< desc
->bNumConfigurations
; ac
++) {
473 struct usb_interface
*interface
= dev
->config
[ac
].interface
;
476 for (ai
= 0; ai
< interface
->num_altsetting
; ai
++) {
478 DPRINTF("intclass: %x, intsubclass: %x, intproto: %x\n",
479 interface
->altsetting
[i
].bInterfaceClass
,
480 interface
->altsetting
[i
].bInterfaceSubClass
,
481 interface
->altsetting
[i
].bInterfaceProtocol
);
483 if ((interface
->altsetting
[ai
].bInterfaceSubClass
== e
->matchTables
[i
].bInterfaceSubClass
) &&
484 (interface
->altsetting
[ai
].bInterfaceProtocol
== e
->matchTables
[i
].bInterfaceProtocol
)){
485 /* TODO: check interfaceClass! */
486 DPRINTF("found device with libusb\n");
488 card_type
= e
->dwCardType
;
498 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
504 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",
505 e
->handle
, e
->dwAction
,
506 e
->dwStatus
, e
->dwEventId
, e
->dwCardType
,
507 e
->hKernelPlugIn
, e
->dwOptions
,
508 e
->u
.Usb
.deviceId
.dwVendorId
,
509 e
->u
.Usb
.deviceId
.dwProductId
,
510 e
->u
.Usb
.dwUniqueID
, e
->dwEventVer
,
511 e
->dwNumMatchTables
);
513 for (i
= 0; i
< e
->dwNumMatchTables
; i
++)
514 DPRINTF("match: dev: %04x:%04x, class: %x, subclass: %x, intclass: %x, intsubclass: %x, intproto: %x\n",
515 e
->matchTables
[i
].VendorId
,
516 e
->matchTables
[i
].ProductId
,
517 e
->matchTables
[i
].bDeviceClass
,
518 e
->matchTables
[i
].bDeviceSubClass
,
519 e
->matchTables
[i
].bInterfaceClass
,
520 e
->matchTables
[i
].bInterfaceSubClass
,
521 e
->matchTables
[i
].bInterfaceProtocol
);
528 DPRINTF("TRANSFER\n");
530 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
535 DPRINTF("MULTI_TRANSFER\n");
537 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
541 case EVENT_UNREGISTER
:
542 DPRINTF("EVENT_UNREGISTER\n");
544 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
549 DPRINTF("INT_WAIT\n");
551 struct interrupt
*it
= (struct interrupt
*)(wdheader
->data
);
553 DPRINTF("Handle: %lu, Options: %lx, ncmds: %lu, enableok: %lu, count: %lu, lost: %lu, stopped: %lu\n",
554 it
->hInterrupt
, it
->dwOptions
,
555 it
->dwCmds
, it
->fEnableOk
, it
->dwCounter
,
556 it
->dwLost
, it
->fStopped
);
559 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
562 if (it
->dwCounter
== 0) {
565 pthread_mutex_lock(&int_wait
);
566 pthread_mutex_unlock(&int_wait
);
569 pthread_mutex_lock(&int_wait
);
570 pthread_mutex_unlock(&int_wait
);
574 DPRINTF("INT_WAIT_RETURN: Handle: %lu, Options: %lx, ncmds: %lu, enableok: %lu, count: %lu, lost: %lu, stopped: %lu\n",
575 it
->hInterrupt
, it
->dwOptions
, it
->dwCmds
,
576 it
->fEnableOk
, it
->dwCounter
, it
->dwLost
,
581 case CARD_UNREGISTER
:
582 DPRINTF("CARD_UNREGISTER\n");
584 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
589 DPRINTF("EVENT_PULL\n");
591 struct event
*e
= (struct event
*)(wdheader
->data
);
595 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",
596 e
->handle
, e
->dwAction
, e
->dwStatus
,
597 e
->dwEventId
, e
->dwCardType
, e
->hKernelPlugIn
,
598 e
->dwOptions
, e
->u
.Usb
.deviceId
.dwVendorId
,
599 e
->u
.Usb
.deviceId
.dwProductId
,
600 e
->u
.Usb
.dwUniqueID
, e
->dwEventVer
,
601 e
->dwNumMatchTables
);
603 for (i
= 0; i
< e
->dwNumMatchTables
; i
++)
604 DPRINTF("match: dev: %04x:%04x, class: %x, subclass: %x, intclass: %x, intsubclass: %x, intproto: %x\n",
605 e
->matchTables
[i
].VendorId
,
606 e
->matchTables
[i
].ProductId
,
607 e
->matchTables
[i
].bDeviceClass
,
608 e
->matchTables
[i
].bDeviceSubClass
,
609 e
->matchTables
[i
].bInterfaceClass
,
610 e
->matchTables
[i
].bInterfaceSubClass
,
611 e
->matchTables
[i
].bInterfaceProtocol
);
615 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
618 struct usb_interface
*interface
= usbdevice
->config
->interface
;
620 e
->dwCardType
= card_type
;
623 e
->u
.Usb
.dwUniqueID
= 110;
624 e
->matchTables
[0].VendorId
= usbdevice
->descriptor
.idVendor
;
625 e
->matchTables
[0].ProductId
= usbdevice
->descriptor
.idProduct
;
626 e
->matchTables
[0].bDeviceClass
= usbdevice
->descriptor
.bDeviceClass
;
627 e
->matchTables
[0].bDeviceSubClass
= usbdevice
->descriptor
.bDeviceSubClass
;
628 e
->matchTables
[0].bInterfaceClass
= interface
->altsetting
[0].bInterfaceClass
;
629 e
->matchTables
[0].bInterfaceSubClass
= interface
->altsetting
[0].bInterfaceSubClass
;
630 e
->matchTables
[0].bInterfaceProtocol
= interface
->altsetting
[0].bInterfaceProtocol
;
635 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",
636 e
->handle
, e
->dwAction
, e
->dwStatus
,
637 e
->dwEventId
, e
->dwCardType
, e
->hKernelPlugIn
,
638 e
->dwOptions
, e
->u
.Usb
.deviceId
.dwVendorId
,
639 e
->u
.Usb
.deviceId
.dwProductId
,
640 e
->u
.Usb
.dwUniqueID
, e
->dwEventVer
,
641 e
->dwNumMatchTables
);
643 for (i
= 0; i
< e
->dwNumMatchTables
; i
++)
644 DPRINTF("match: dev: %04x:%04x, class: %x, subclass: %x, intclass: %x, intsubclass: %x, intproto: %x\n",
645 e
->matchTables
[i
].VendorId
,
646 e
->matchTables
[i
].ProductId
,
647 e
->matchTables
[i
].bDeviceClass
,
648 e
->matchTables
[i
].bDeviceSubClass
,
649 e
->matchTables
[i
].bInterfaceClass
,
650 e
->matchTables
[i
].bInterfaceSubClass
,
651 e
->matchTables
[i
].bInterfaceProtocol
);
658 fprintf(stderr
,"!!!Unsupported IOCTL: %x!!!\n", request
);
660 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
668 int ioctl(int fd
, int request
, ...) {
674 ioctl_func
= (int (*) (int, int, void *)) dlsym (RTLD_NEXT
, "ioctl");
676 va_start (args
, request
);
677 argp
= va_arg (args
, void *);
681 ret
= do_wdioctl(fd
, request
, argp
);
683 ret
= (*ioctl_func
) (fd
, request
, argp
);
688 int open (const char *pathname
, int flags
, ...) {
689 static int (*func
) (const char *, int, mode_t
) = NULL
;
695 func
= (int (*) (const char *, int, mode_t
)) dlsym (RTLD_NEXT
, "open");
697 if (flags
& O_CREAT
) {
698 va_start(args
, flags
);
699 mode
= va_arg(args
, mode_t
);
703 if (!strcmp (pathname
, "/dev/windrvr6")) {
704 DPRINTF("opening windrvr6\n");
706 windrvrfd
= fd
= (*func
) ("/dev/null", flags
, mode
);
708 windrvrfd
= fd
= (*func
) (pathname
, flags
, mode
);
715 busses
= usb_get_busses();
721 return (*func
) (pathname
, flags
, mode
);
725 static int (*func
) (int) = NULL
;
728 func
= (int (*) (int)) dlsym(RTLD_NEXT
, "close");
730 if (fd
== windrvrfd
&& windrvrfd
>= 0) {
731 DPRINTF("close windrvrfd\n");
732 if (usbinterface
>= 0)
733 usb_release_interface(usb_devhandle
, usbinterface
);
736 usb_close(usb_devhandle
);
738 usb_devhandle
= NULL
;
746 FILE *fopen(const char *path
, const char *mode
) {
748 static FILE* (*func
) (const char*, const char*) = NULL
;
751 func
= (FILE* (*) (const char*, const char*)) dlsym(RTLD_NEXT
, "fopen");
753 ret
= (*func
) (path
, mode
);
755 if (!strcmp (path
, "/proc/modules")) {
756 DPRINTF("opening /proc/modules\n");
766 char *fgets(char *s
, int size
, FILE *stream
) {
767 static char* (*func
) (char*, int, FILE*) = NULL
;
768 const char modules
[][256] = {"windrvr6 1 0 - Live 0xdeadbeef\n", "parport_pc 1 0 - Live 0xdeadbeef\n"};
773 func
= (char* (*) (char*, int, FILE*)) dlsym(RTLD_NEXT
, "fgets");
775 if (modulesfp
== stream
) {
776 if (modules_read
< sizeof(modules
)) {
777 strcpy(s
, modules
[modules_read
]);
782 ret
= (*func
)(s
,size
,stream
);
788 int fclose(FILE *fp
) {
789 static int (*func
) (FILE*) = NULL
;
792 func
= (int (*) (FILE*)) dlsym(RTLD_NEXT
, "fclose");
794 if (fp
== modulesfp
) {
801 int access(const char *pathname
, int mode
) {
802 static int (*func
) (const char*, int);
805 func
= (int (*) (const char*, int)) dlsym(RTLD_NEXT
, "access");
807 if (!strcmp(pathname
, "/dev/windrvr6")) {
810 return (*func
)(pathname
, mode
);