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>
40 #include "usb-driver.h"
42 static int (*ioctl_func
) (int, int, void *) = NULL
;
43 static int windrvrfd
= 0;
45 static int modules_read
= 0;
46 static struct usb_bus
*busses
= NULL
;
47 static struct usb_device
*usbdevice
;
48 static usb_dev_handle
*usb_devhandle
= NULL
;
49 static unsigned long card_type
;
50 static int ints_enabled
= 0;
51 static pthread_mutex_t int_wait
= PTHREAD_MUTEX_INITIALIZER
;
57 #define DPRINTF(format, args...) fprintf(stderr, format, ##args)
58 void hexdump(unsigned char *buf
, int len
) {
61 for(i
=0; i
<len
; i
++) {
62 fprintf(stderr
,"%02x ", buf
[i
]);
69 #define DPRINTF(format, args...)
72 int usb_deviceinfo(unsigned char *buf
) {
75 WDU_CONFIGURATION
**pConfigs
, **pActiveConfig
;
76 WDU_INTERFACE
**pActiveInterface
;
79 struct usb_device_info
*udi
= (struct usb_device_info
*)(buf
+len
);
81 udi
->Descriptor
.bLength
= sizeof(WDU_DEVICE_DESCRIPTOR
);
82 udi
->Descriptor
.bDescriptorType
= usbdevice
->descriptor
.bDescriptorType
;
83 udi
->Descriptor
.bcdUSB
= usbdevice
->descriptor
.bcdUSB
;
84 udi
->Descriptor
.bDeviceClass
= usbdevice
->descriptor
.bDeviceClass
;
85 udi
->Descriptor
.bDeviceSubClass
= usbdevice
->descriptor
.bDeviceSubClass
;
86 udi
->Descriptor
.bDeviceProtocol
= usbdevice
->descriptor
.bDeviceProtocol
;
87 udi
->Descriptor
.bMaxPacketSize0
= usbdevice
->descriptor
.bMaxPacketSize0
;
88 udi
->Descriptor
.idVendor
= usbdevice
->descriptor
.idVendor
;
89 udi
->Descriptor
.idProduct
= usbdevice
->descriptor
.idProduct
;
90 udi
->Descriptor
.bcdDevice
= usbdevice
->descriptor
.bcdDevice
;
91 udi
->Descriptor
.iManufacturer
= usbdevice
->descriptor
.iManufacturer
;
92 udi
->Descriptor
.iProduct
= usbdevice
->descriptor
.iProduct
;
93 udi
->Descriptor
.iSerialNumber
= usbdevice
->descriptor
.iSerialNumber
;
94 udi
->Descriptor
.bNumConfigurations
= usbdevice
->descriptor
.bNumConfigurations
;
96 /* TODO: Fix Pipe0! */
97 udi
->Pipe0
.dwNumber
= 0x00;
98 udi
->Pipe0
.dwMaximumPacketSize
= usbdevice
->descriptor
.bMaxPacketSize0
;
100 udi
->Pipe0
.direction
= WDU_DIR_IN_OUT
;
101 udi
->Pipe0
.dwInterval
= 0;
103 pConfigs
= &(udi
->pConfigs
);
104 pActiveConfig
= &(udi
->pActiveConfig
);
105 pActiveInterface
= &(udi
->pActiveInterface
[0]);
108 len
= sizeof(struct usb_device_info
);
110 for (i
=0; i
<usbdevice
->descriptor
.bNumConfigurations
; i
++)
112 struct usb_config_descriptor
*conf_desc
= &usbdevice
->config
[i
];
113 WDU_INTERFACE
**pInterfaces
;
114 WDU_ALTERNATE_SETTING
**pAlternateSettings
[conf_desc
->bNumInterfaces
];
115 WDU_ALTERNATE_SETTING
**pActiveAltSetting
[conf_desc
->bNumInterfaces
];
118 WDU_CONFIGURATION
*cfg
= (WDU_CONFIGURATION
*)(buf
+len
);
121 *pActiveConfig
= cfg
;
123 cfg
->Descriptor
.bLength
= conf_desc
->bLength
;
124 cfg
->Descriptor
.bDescriptorType
= conf_desc
->bDescriptorType
;
125 cfg
->Descriptor
.wTotalLength
= conf_desc
->wTotalLength
;
126 cfg
->Descriptor
.bNumInterfaces
= conf_desc
->bNumInterfaces
;
127 cfg
->Descriptor
.bConfigurationValue
= conf_desc
->bConfigurationValue
;
128 cfg
->Descriptor
.iConfiguration
= conf_desc
->iConfiguration
;
129 cfg
->Descriptor
.bmAttributes
= conf_desc
->bmAttributes
;
130 cfg
->Descriptor
.MaxPower
= conf_desc
->MaxPower
;
132 cfg
->dwNumInterfaces
= conf_desc
->bNumInterfaces
;
134 pInterfaces
= &(cfg
->pInterfaces
);
136 len
+= sizeof(WDU_CONFIGURATION
);
139 *pInterfaces
= (WDU_INTERFACE
*)(buf
+len
);
140 for (j
=0; j
<conf_desc
->bNumInterfaces
; j
++) {
141 WDU_INTERFACE
*iface
= (WDU_INTERFACE
*)(buf
+len
);
143 pActiveInterface
[j
] = iface
;
145 pAlternateSettings
[j
] = &(iface
->pAlternateSettings
);
146 iface
->dwNumAltSettings
= usbdevice
->config
[i
].interface
[j
].num_altsetting
;
147 pActiveAltSetting
[j
] = &(iface
->pActiveAltSetting
);
149 len
+= sizeof(WDU_INTERFACE
);
152 len
+= sizeof(WDU_INTERFACE
) * conf_desc
->bNumInterfaces
;
155 for (j
=0; j
<conf_desc
->bNumInterfaces
; j
++)
157 struct usb_interface
*interface
= &usbdevice
->config
[i
].interface
[j
];
160 *pAlternateSettings
[j
] = (WDU_ALTERNATE_SETTING
*)(buf
+len
);
162 *pActiveAltSetting
[j
] = (WDU_ALTERNATE_SETTING
*)(buf
+len
);
165 for(k
=0; k
<interface
->num_altsetting
; k
++)
167 unsigned char bNumEndpoints
= interface
->altsetting
[k
].bNumEndpoints
;
168 WDU_ENDPOINT_DESCRIPTOR
**pEndpointDescriptors
;
169 WDU_PIPE_INFO
**pPipes
;
172 WDU_ALTERNATE_SETTING
*altset
= (WDU_ALTERNATE_SETTING
*)(buf
+len
);
174 altset
->Descriptor
.bLength
= interface
->altsetting
[k
].bLength
;
175 altset
->Descriptor
.bDescriptorType
= interface
->altsetting
[k
].bDescriptorType
;
176 altset
->Descriptor
.bInterfaceNumber
= interface
->altsetting
[k
].bInterfaceNumber
;
177 altset
->Descriptor
.bAlternateSetting
= interface
->altsetting
[k
].bAlternateSetting
;
178 altset
->Descriptor
.bNumEndpoints
= interface
->altsetting
[k
].bNumEndpoints
;
179 altset
->Descriptor
.bInterfaceClass
= interface
->altsetting
[k
].bInterfaceClass
;
180 altset
->Descriptor
.bInterfaceSubClass
= interface
->altsetting
[k
].bInterfaceSubClass
;
181 altset
->Descriptor
.bInterfaceProtocol
= interface
->altsetting
[k
].bInterfaceProtocol
;
182 altset
->Descriptor
.iInterface
= interface
->altsetting
[k
].iInterface
;
183 pEndpointDescriptors
= &(altset
->pEndpointDescriptors
);
184 pPipes
= &(altset
->pPipes
);
187 len
+=sizeof(WDU_ALTERNATE_SETTING
);
190 *pEndpointDescriptors
= (WDU_ENDPOINT_DESCRIPTOR
*)(buf
+len
);
191 for (l
= 0; l
< bNumEndpoints
; l
++) {
192 WDU_ENDPOINT_DESCRIPTOR
*ed
= (WDU_ENDPOINT_DESCRIPTOR
*)(buf
+len
);
194 ed
->bLength
= interface
->altsetting
[k
].endpoint
[l
].bLength
;
195 ed
->bDescriptorType
= interface
->altsetting
[k
].endpoint
[l
].bDescriptorType
;
196 ed
->bEndpointAddress
= interface
->altsetting
[k
].endpoint
[l
].bEndpointAddress
;
197 ed
->bmAttributes
= interface
->altsetting
[k
].endpoint
[l
].bmAttributes
;
198 ed
->wMaxPacketSize
= interface
->altsetting
[k
].endpoint
[l
].wMaxPacketSize
;
199 ed
->bInterval
= interface
->altsetting
[k
].endpoint
[l
].bInterval
;
201 len
+= sizeof(WDU_ENDPOINT_DESCRIPTOR
);
204 *pPipes
= (WDU_PIPE_INFO
*)(buf
+len
);
205 for (l
= 0; l
< bNumEndpoints
; l
++) {
206 WDU_PIPE_INFO
*pi
= (WDU_PIPE_INFO
*)(buf
+len
);
208 pi
->dwNumber
= interface
->altsetting
[k
].endpoint
[l
].bEndpointAddress
;
209 pi
->dwMaximumPacketSize
= WDU_GET_MAX_PACKET_SIZE(interface
->altsetting
[k
].endpoint
[l
].wMaxPacketSize
);
210 pi
->type
= interface
->altsetting
[k
].endpoint
[l
].bmAttributes
& USB_ENDPOINT_TYPE_MASK
;
211 if (pi
->type
== PIPE_TYPE_CONTROL
)
212 pi
->direction
= WDU_DIR_IN_OUT
;
215 pi
->direction
= interface
->altsetting
[k
].endpoint
[l
].bEndpointAddress
& USB_ENDPOINT_DIR_MASK
? WDU_DIR_IN
: WDU_DIR_OUT
;
218 pi
->dwInterval
= interface
->altsetting
[k
].endpoint
[l
].bInterval
;
220 len
+= sizeof(WDU_PIPE_INFO
);
223 len
+=(sizeof(WDU_ENDPOINT_DESCRIPTOR
)+sizeof(WDU_PIPE_INFO
))*bNumEndpoints
;
232 int do_wdioctl(int fd
, unsigned int request
, unsigned char *wdioctl
) {
233 struct header_struct
* wdheader
= (struct header_struct
*)wdioctl
;
234 struct version_struct
*version
;
237 if (wdheader
->magic
!= MAGIC
) {
238 fprintf(stderr
,"!!!ERROR: magic header does not match!!!\n");
239 return (*ioctl_func
) (fd
, request
, wdioctl
);
244 version
= (struct version_struct
*)(wdheader
->data
);
245 strcpy(version
->version
, "WinDriver no more");
246 version
->versionul
= 802;
247 DPRINTF("VERSION\n");
251 DPRINTF("LICENSE\n");
255 /* TODO: Implement for LPT-support */
258 struct card_register
* cr
= (struct card_register
*)(wdheader
->data
);
261 DPRINTF("CARD_REGISTER\n");
265 DPRINTF("in USB_TRANSFER");
267 struct usb_transfer
*ut
= (struct usb_transfer
*)(wdheader
->data
);
270 DPRINTF(" unique: %lu, pipe: %lu, read: %lu, options: %lx, size: %lu, timeout: %lx\n",
271 ut
->dwUniqueID
, ut
->dwPipeNum
, ut
->fRead
,
272 ut
->dwOptions
, ut
->dwBufferSize
, ut
->dwTimeout
);
273 DPRINTF("setup packet: ");
274 hexdump(ut
->SetupPacket
, 8);
276 if (!ut
->fRead
&& ut
->dwBufferSize
)
278 hexdump(ut
->pBuffer
, ut
->dwBufferSize
);
283 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
285 /* http://www.jungo.com/support/documentation/windriver/802/wdusb_man_mhtml/node55.html#SECTION001213000000000000000 */
286 if (ut
->dwPipeNum
== 0) { /* control pipe */
287 int requesttype
, request
, value
, index
, size
;
288 requesttype
= ut
->SetupPacket
[0];
289 request
= ut
->SetupPacket
[1];
290 value
= ut
->SetupPacket
[2] | (ut
->SetupPacket
[3] << 8);
291 index
= ut
->SetupPacket
[4] | (ut
->SetupPacket
[5] << 8);
292 size
= ut
->SetupPacket
[6] | (ut
->SetupPacket
[7] << 8);
293 DPRINTF("requesttype: %x, request: %x, value: %u, index: %u, size: %u\n", requesttype
, request
, value
, index
, size
);
294 ret
= usb_control_msg(usb_devhandle
, requesttype
, request
, value
, index
, ut
->pBuffer
, size
, ut
->dwTimeout
);
297 ret
= usb_bulk_read(usb_devhandle
, ut
->dwPipeNum
, ut
->pBuffer
, ut
->dwBufferSize
, ut
->dwTimeout
);
300 ret
= usb_bulk_write(usb_devhandle
, ut
->dwPipeNum
, ut
->pBuffer
, ut
->dwBufferSize
, ut
->dwTimeout
);
305 fprintf(stderr
, "usb_transfer: %d (%s)\n", ret
, usb_strerror());
307 ut
->dwBytesTransferred
= ret
;
313 DPRINTF("Transferred: %lu (%s)\n",ut
->dwBytesTransferred
, (ut
->fRead
?"read":"write"));
314 if (ut
->fRead
&& ut
->dwBytesTransferred
)
317 hexdump(ut
->pBuffer
, ut
->dwBytesTransferred
);
324 DPRINTF("INT_ENABLE\n");
326 struct interrupt
*it
= (struct interrupt
*)(wdheader
->data
);
328 DPRINTF("Handle: %lu, Options: %lx, ncmds: %lu, enableok: %lu, count: %lu, lost: %lu, stopped: %lu\n",
329 it
->hInterrupt
, it
->dwOptions
,
330 it
->dwCmds
, it
->fEnableOk
, it
->dwCounter
,
331 it
->dwLost
, it
->fStopped
);
336 pthread_mutex_trylock(&int_wait
);
342 DPRINTF("INT_DISABLE\n");
344 struct interrupt
*it
= (struct interrupt
*)(wdheader
->data
);
346 DPRINTF("Handle: %lu, Options: %lx, ncmds: %lu, enableok: %lu, count: %lu, lost: %lu, stopped: %lu\n",
347 it
->hInterrupt
, it
->dwOptions
,
348 it
->dwCmds
, it
->fEnableOk
, it
->dwCounter
,
349 it
->dwLost
, it
->fStopped
);
351 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
356 if (pthread_mutex_trylock(&int_wait
) == EBUSY
)
357 pthread_mutex_unlock(&int_wait
);
359 DPRINTF("Handle: %lu, Options: %lx, ncmds: %lu, enableok: %lu, count: %lu, lost: %lu, stopped: %lu\n",
360 it
->hInterrupt
, it
->dwOptions
,
361 it
->dwCmds
, it
->fEnableOk
, it
->dwCounter
,
362 it
->dwLost
, it
->fStopped
);
366 case USB_SET_INTERFACE
:
367 DPRINTF("USB_SET_INTERFACE\n");
369 struct usb_set_interface
*usi
= (struct usb_set_interface
*)(wdheader
->data
);
371 DPRINTF("unique: %lu, interfacenum: %lu, alternatesetting: %lu, options: %lx\n",
372 usi
->dwUniqueID
, usi
->dwInterfaceNum
,
373 usi
->dwAlternateSetting
, usi
->dwOptions
);
375 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
379 usb_devhandle
= usb_open(usbdevice
);
381 /* FIXME: Select right interface! */
382 ret
= usb_claim_interface(usb_devhandle
, usbdevice
->config
[0].interface
[usi
->dwInterfaceNum
].altsetting
[usi
->dwAlternateSetting
].bInterfaceNumber
);
385 ret
= usb_set_altinterface(usb_devhandle
, usi
->dwAlternateSetting
);
387 fprintf(stderr
, "usb_set_altinterface: %d\n", ret
);
389 fprintf(stderr
, "usb_set_configuration: %d (%s)\n", ret
, usb_strerror());
392 fprintf(stderr
, "usb_claim_interface: %d -> %d (%s)\n",
393 usbdevice
->config
[0].interface
[usi
->dwInterfaceNum
].altsetting
[usi
->dwAlternateSetting
].bInterfaceNumber
,
394 ret
, usb_strerror());
398 DPRINTF("unique: %lu, interfacenum: %lu, alternatesetting: %lu, options: %lx\n",
399 usi
->dwUniqueID
, usi
->dwInterfaceNum
,
400 usi
->dwAlternateSetting
, usi
->dwOptions
);
404 case USB_GET_DEVICE_DATA
:
405 DPRINTF("USB_GET_DEVICE_DATA\n");
407 struct usb_get_device_data
*ugdd
= (struct usb_get_device_data
*)(wdheader
->data
);
410 DPRINTF("unique: %lu, bytes: %lu, options: %lx\n",
411 ugdd
->dwUniqueID
, ugdd
->dwBytes
,
414 pSize
= ugdd
->dwBytes
;
415 if (!ugdd
->dwBytes
) {
417 ugdd
->dwBytes
= usb_deviceinfo(NULL
);
420 usb_deviceinfo((unsigned char*)ugdd
->pBuf
);
426 DPRINTF("EVENT_REGISTER\n");
428 struct event
*e
= (struct event
*)(wdheader
->data
);
432 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",
433 e
->handle
, e
->dwAction
,
434 e
->dwStatus
, e
->dwEventId
, e
->dwCardType
,
435 e
->hKernelPlugIn
, e
->dwOptions
,
436 e
->u
.Usb
.deviceId
.dwVendorId
,
437 e
->u
.Usb
.deviceId
.dwProductId
,
438 e
->u
.Usb
.dwUniqueID
, e
->dwEventVer
,
439 e
->dwNumMatchTables
);
441 for (i
= 0; i
< e
->dwNumMatchTables
; i
++) {
443 DPRINTF("match: dev: %04x:%04x, class: %x, subclass: %x, intclass: %x, intsubclass: %x, intproto: %x\n",
444 e
->matchTables
[i
].VendorId
,
445 e
->matchTables
[i
].ProductId
,
446 e
->matchTables
[i
].bDeviceClass
,
447 e
->matchTables
[i
].bDeviceSubClass
,
448 e
->matchTables
[i
].bInterfaceClass
,
449 e
->matchTables
[i
].bInterfaceSubClass
,
450 e
->matchTables
[i
].bInterfaceProtocol
);
452 for (bus
= busses
; bus
; bus
= bus
->next
) {
453 struct usb_device
*dev
;
455 for (dev
= bus
->devices
; dev
; dev
= dev
->next
) {
456 struct usb_device_descriptor
*desc
= &(dev
->descriptor
);
458 if((desc
->idVendor
== e
->matchTables
[i
].VendorId
) &&
459 (desc
->idProduct
== e
->matchTables
[i
].ProductId
) &&
460 (desc
->bDeviceClass
== e
->matchTables
[i
].bDeviceClass
) &&
461 (desc
->bDeviceSubClass
== e
->matchTables
[i
].bDeviceSubClass
)) {
463 for (ac
= 0; ac
< desc
->bNumConfigurations
; ac
++) {
464 struct usb_interface
*interface
= dev
->config
[ac
].interface
;
467 for (ai
= 0; ai
< interface
->num_altsetting
; ai
++) {
469 DPRINTF("intclass: %x, intsubclass: %x, intproto: %x\n",
470 interface
->altsetting
[i
].bInterfaceClass
,
471 interface
->altsetting
[i
].bInterfaceSubClass
,
472 interface
->altsetting
[i
].bInterfaceProtocol
);
474 if ((interface
->altsetting
[ai
].bInterfaceSubClass
== e
->matchTables
[i
].bInterfaceSubClass
) &&
475 (interface
->altsetting
[ai
].bInterfaceProtocol
== e
->matchTables
[i
].bInterfaceProtocol
)){
476 /* TODO: check interfaceClass! */
477 DPRINTF("found device with libusb\n");
479 card_type
= e
->dwCardType
;
489 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
495 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",
496 e
->handle
, e
->dwAction
,
497 e
->dwStatus
, e
->dwEventId
, e
->dwCardType
,
498 e
->hKernelPlugIn
, e
->dwOptions
,
499 e
->u
.Usb
.deviceId
.dwVendorId
,
500 e
->u
.Usb
.deviceId
.dwProductId
,
501 e
->u
.Usb
.dwUniqueID
, e
->dwEventVer
,
502 e
->dwNumMatchTables
);
504 for (i
= 0; i
< e
->dwNumMatchTables
; i
++)
505 DPRINTF("match: dev: %04x:%04x, class: %x, subclass: %x, intclass: %x, intsubclass: %x, intproto: %x\n",
506 e
->matchTables
[i
].VendorId
,
507 e
->matchTables
[i
].ProductId
,
508 e
->matchTables
[i
].bDeviceClass
,
509 e
->matchTables
[i
].bDeviceSubClass
,
510 e
->matchTables
[i
].bInterfaceClass
,
511 e
->matchTables
[i
].bInterfaceSubClass
,
512 e
->matchTables
[i
].bInterfaceProtocol
);
518 DPRINTF("TRANSFER\n");
520 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
524 case EVENT_UNREGISTER
:
525 DPRINTF("EVENT_UNREGISTER\n");
527 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
532 DPRINTF("INT_WAIT\n");
534 struct interrupt
*it
= (struct interrupt
*)(wdheader
->data
);
536 DPRINTF("Handle: %lu, Options: %lx, ncmds: %lu, enableok: %lu, count: %lu, lost: %lu, stopped: %lu\n",
537 it
->hInterrupt
, it
->dwOptions
,
538 it
->dwCmds
, it
->fEnableOk
, it
->dwCounter
,
539 it
->dwLost
, it
->fStopped
);
542 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
545 if (it
->dwCounter
== 0) {
548 pthread_mutex_lock(&int_wait
);
549 pthread_mutex_unlock(&int_wait
);
552 pthread_mutex_lock(&int_wait
);
553 pthread_mutex_unlock(&int_wait
);
557 DPRINTF("INT_WAIT_RETURN: Handle: %lu, Options: %lx, ncmds: %lu, enableok: %lu, count: %lu, lost: %lu, stopped: %lu\n",
558 it
->hInterrupt
, it
->dwOptions
, it
->dwCmds
,
559 it
->fEnableOk
, it
->dwCounter
, it
->dwLost
,
564 case CARD_UNREGISTER
:
565 DPRINTF("CARD_UNREGISTER\n");
567 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
572 DPRINTF("EVENT_PULL\n");
574 struct event
*e
= (struct event
*)(wdheader
->data
);
578 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",
579 e
->handle
, e
->dwAction
, e
->dwStatus
,
580 e
->dwEventId
, e
->dwCardType
, e
->hKernelPlugIn
,
581 e
->dwOptions
, e
->u
.Usb
.deviceId
.dwVendorId
,
582 e
->u
.Usb
.deviceId
.dwProductId
,
583 e
->u
.Usb
.dwUniqueID
, e
->dwEventVer
,
584 e
->dwNumMatchTables
);
586 for (i
= 0; i
< e
->dwNumMatchTables
; i
++)
587 DPRINTF("match: dev: %04x:%04x, class: %x, subclass: %x, intclass: %x, intsubclass: %x, intproto: %x\n",
588 e
->matchTables
[i
].VendorId
,
589 e
->matchTables
[i
].ProductId
,
590 e
->matchTables
[i
].bDeviceClass
,
591 e
->matchTables
[i
].bDeviceSubClass
,
592 e
->matchTables
[i
].bInterfaceClass
,
593 e
->matchTables
[i
].bInterfaceSubClass
,
594 e
->matchTables
[i
].bInterfaceProtocol
);
598 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
601 struct usb_interface
*interface
= usbdevice
->config
->interface
;
603 e
->dwCardType
= card_type
;
606 e
->u
.Usb
.dwUniqueID
= 110;
607 e
->matchTables
[0].VendorId
= usbdevice
->descriptor
.idVendor
;
608 e
->matchTables
[0].ProductId
= usbdevice
->descriptor
.idProduct
;
609 e
->matchTables
[0].bDeviceClass
= usbdevice
->descriptor
.bDeviceClass
;
610 e
->matchTables
[0].bDeviceSubClass
= usbdevice
->descriptor
.bDeviceSubClass
;
611 e
->matchTables
[0].bInterfaceClass
= interface
->altsetting
[0].bInterfaceClass
;
612 e
->matchTables
[0].bInterfaceSubClass
= interface
->altsetting
[0].bInterfaceSubClass
;
613 e
->matchTables
[0].bInterfaceProtocol
= interface
->altsetting
[0].bInterfaceProtocol
;
618 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",
619 e
->handle
, e
->dwAction
, e
->dwStatus
,
620 e
->dwEventId
, e
->dwCardType
, e
->hKernelPlugIn
,
621 e
->dwOptions
, e
->u
.Usb
.deviceId
.dwVendorId
,
622 e
->u
.Usb
.deviceId
.dwProductId
,
623 e
->u
.Usb
.dwUniqueID
, e
->dwEventVer
,
624 e
->dwNumMatchTables
);
626 for (i
= 0; i
< e
->dwNumMatchTables
; i
++)
627 DPRINTF("match: dev: %04x:%04x, class: %x, subclass: %x, intclass: %x, intsubclass: %x, intproto: %x\n",
628 e
->matchTables
[i
].VendorId
,
629 e
->matchTables
[i
].ProductId
,
630 e
->matchTables
[i
].bDeviceClass
,
631 e
->matchTables
[i
].bDeviceSubClass
,
632 e
->matchTables
[i
].bInterfaceClass
,
633 e
->matchTables
[i
].bInterfaceSubClass
,
634 e
->matchTables
[i
].bInterfaceProtocol
);
641 fprintf(stderr
,"!!!Unsupported IOCTL: %x!!!\n", request
);
643 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
651 int ioctl(int fd
, int request
, ...) {
657 ioctl_func
= (int (*) (int, int, void *)) dlsym (RTLD_NEXT
, "ioctl");
659 va_start (args
, request
);
660 argp
= va_arg (args
, void *);
664 ret
= do_wdioctl(fd
, request
, argp
);
666 ret
= (*ioctl_func
) (fd
, request
, argp
);
671 int open (const char *pathname
, int flags
, ...) {
672 static int (*func
) (const char *, int, mode_t
) = NULL
;
678 func
= (int (*) (const char *, int, mode_t
)) dlsym (RTLD_NEXT
, "open");
680 if (flags
& O_CREAT
) {
681 va_start(args
, flags
);
682 mode
= va_arg(args
, mode_t
);
686 if (!strcmp (pathname
, "/dev/windrvr6")) {
687 DPRINTF("opening windrvr6\n");
689 windrvrfd
= fd
= (*func
) ("/dev/null", flags
, mode
);
691 windrvrfd
= fd
= (*func
) (pathname
, flags
, mode
);
698 busses
= usb_get_busses();
704 return (*func
) (pathname
, flags
, mode
);
708 static int (*func
) (int) = NULL
;
711 func
= (int (*) (int)) dlsym(RTLD_NEXT
, "close");
713 if (fd
== windrvrfd
) {
714 DPRINTF("close windrvrfd\n");
721 FILE *fopen(const char *path
, const char *mode
) {
723 static FILE* (*func
) (const char*, const char*) = NULL
;
726 func
= (FILE* (*) (const char*, const char*)) dlsym(RTLD_NEXT
, "fopen");
728 ret
= (*func
) (path
, mode
);
730 if (!strcmp (path
, "/proc/modules")) {
731 DPRINTF("opening /proc/modules\n");
741 char *fgets(char *s
, int size
, FILE *stream
) {
742 static char* (*func
) (char*, int, FILE*) = NULL
;
743 const char modules
[][256] = {"windrvr6 1 0 - Live 0xdeadbeef\n", "parport_pc 1 0 - Live 0xdeadbeef\n"};
748 func
= (char* (*) (char*, int, FILE*)) dlsym(RTLD_NEXT
, "fgets");
750 if (modulesfp
== stream
) {
751 if (modules_read
< sizeof(modules
)) {
752 strcpy(s
, modules
[modules_read
]);
757 ret
= (*func
)(s
,size
,stream
);
763 int fclose(FILE *fp
) {
764 static int (*func
) (FILE*) = NULL
;
767 func
= (int (*) (FILE*)) dlsym(RTLD_NEXT
, "fclose");
769 if (fp
== modulesfp
) {
776 int access(const char *pathname
, int mode
) {
777 static int (*func
) (const char*, int);
780 func
= (int (*) (const char*, int)) dlsym(RTLD_NEXT
, "access");
782 if (!strcmp(pathname
, "/dev/windrvr6")) {
785 return (*func
)(pathname
, mode
);