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
;
59 #define DPRINTF(format, args...) fprintf(stderr, format, ##args)
60 void hexdump(unsigned char *buf
, int len
) {
63 for(i
=0; i
<len
; i
++) {
64 fprintf(stderr
,"%02x ", buf
[i
]);
71 #define DPRINTF(format, args...)
74 int usb_deviceinfo(unsigned char *buf
) {
77 WDU_CONFIGURATION
**pConfigs
, **pActiveConfig
;
78 WDU_INTERFACE
**pActiveInterface
;
81 struct usb_device_info
*udi
= (struct usb_device_info
*)(buf
+len
);
83 udi
->Descriptor
.bLength
= sizeof(WDU_DEVICE_DESCRIPTOR
);
84 udi
->Descriptor
.bDescriptorType
= usbdevice
->descriptor
.bDescriptorType
;
85 udi
->Descriptor
.bcdUSB
= usbdevice
->descriptor
.bcdUSB
;
86 udi
->Descriptor
.bDeviceClass
= usbdevice
->descriptor
.bDeviceClass
;
87 udi
->Descriptor
.bDeviceSubClass
= usbdevice
->descriptor
.bDeviceSubClass
;
88 udi
->Descriptor
.bDeviceProtocol
= usbdevice
->descriptor
.bDeviceProtocol
;
89 udi
->Descriptor
.bMaxPacketSize0
= usbdevice
->descriptor
.bMaxPacketSize0
;
90 udi
->Descriptor
.idVendor
= usbdevice
->descriptor
.idVendor
;
91 udi
->Descriptor
.idProduct
= usbdevice
->descriptor
.idProduct
;
92 udi
->Descriptor
.bcdDevice
= usbdevice
->descriptor
.bcdDevice
;
93 udi
->Descriptor
.iManufacturer
= usbdevice
->descriptor
.iManufacturer
;
94 udi
->Descriptor
.iProduct
= usbdevice
->descriptor
.iProduct
;
95 udi
->Descriptor
.iSerialNumber
= usbdevice
->descriptor
.iSerialNumber
;
96 udi
->Descriptor
.bNumConfigurations
= usbdevice
->descriptor
.bNumConfigurations
;
98 /* TODO: Fix Pipe0! */
99 udi
->Pipe0
.dwNumber
= 0x00;
100 udi
->Pipe0
.dwMaximumPacketSize
= usbdevice
->descriptor
.bMaxPacketSize0
;
102 udi
->Pipe0
.direction
= WDU_DIR_IN_OUT
;
103 udi
->Pipe0
.dwInterval
= 0;
105 pConfigs
= &(udi
->pConfigs
);
106 pActiveConfig
= &(udi
->pActiveConfig
);
107 pActiveInterface
= &(udi
->pActiveInterface
[0]);
110 len
= sizeof(struct usb_device_info
);
112 for (i
=0; i
<usbdevice
->descriptor
.bNumConfigurations
; i
++)
114 struct usb_config_descriptor
*conf_desc
= &usbdevice
->config
[i
];
115 WDU_INTERFACE
**pInterfaces
;
116 WDU_ALTERNATE_SETTING
**pAlternateSettings
[conf_desc
->bNumInterfaces
];
117 WDU_ALTERNATE_SETTING
**pActiveAltSetting
[conf_desc
->bNumInterfaces
];
120 WDU_CONFIGURATION
*cfg
= (WDU_CONFIGURATION
*)(buf
+len
);
123 *pActiveConfig
= cfg
;
125 cfg
->Descriptor
.bLength
= conf_desc
->bLength
;
126 cfg
->Descriptor
.bDescriptorType
= conf_desc
->bDescriptorType
;
127 cfg
->Descriptor
.wTotalLength
= conf_desc
->wTotalLength
;
128 cfg
->Descriptor
.bNumInterfaces
= conf_desc
->bNumInterfaces
;
129 cfg
->Descriptor
.bConfigurationValue
= conf_desc
->bConfigurationValue
;
130 cfg
->Descriptor
.iConfiguration
= conf_desc
->iConfiguration
;
131 cfg
->Descriptor
.bmAttributes
= conf_desc
->bmAttributes
;
132 cfg
->Descriptor
.MaxPower
= conf_desc
->MaxPower
;
134 cfg
->dwNumInterfaces
= conf_desc
->bNumInterfaces
;
136 pInterfaces
= &(cfg
->pInterfaces
);
138 len
+= sizeof(WDU_CONFIGURATION
);
141 *pInterfaces
= (WDU_INTERFACE
*)(buf
+len
);
142 for (j
=0; j
<conf_desc
->bNumInterfaces
; j
++) {
143 WDU_INTERFACE
*iface
= (WDU_INTERFACE
*)(buf
+len
);
145 pActiveInterface
[j
] = iface
;
147 pAlternateSettings
[j
] = &(iface
->pAlternateSettings
);
148 iface
->dwNumAltSettings
= usbdevice
->config
[i
].interface
[j
].num_altsetting
;
149 pActiveAltSetting
[j
] = &(iface
->pActiveAltSetting
);
151 len
+= sizeof(WDU_INTERFACE
);
154 len
+= sizeof(WDU_INTERFACE
) * conf_desc
->bNumInterfaces
;
157 for (j
=0; j
<conf_desc
->bNumInterfaces
; j
++)
159 struct usb_interface
*interface
= &usbdevice
->config
[i
].interface
[j
];
162 *pAlternateSettings
[j
] = (WDU_ALTERNATE_SETTING
*)(buf
+len
);
164 *pActiveAltSetting
[j
] = (WDU_ALTERNATE_SETTING
*)(buf
+len
);
167 for(k
=0; k
<interface
->num_altsetting
; k
++)
169 unsigned char bNumEndpoints
= interface
->altsetting
[k
].bNumEndpoints
;
170 WDU_ENDPOINT_DESCRIPTOR
**pEndpointDescriptors
;
171 WDU_PIPE_INFO
**pPipes
;
174 WDU_ALTERNATE_SETTING
*altset
= (WDU_ALTERNATE_SETTING
*)(buf
+len
);
176 altset
->Descriptor
.bLength
= interface
->altsetting
[k
].bLength
;
177 altset
->Descriptor
.bDescriptorType
= interface
->altsetting
[k
].bDescriptorType
;
178 altset
->Descriptor
.bInterfaceNumber
= interface
->altsetting
[k
].bInterfaceNumber
;
179 altset
->Descriptor
.bAlternateSetting
= interface
->altsetting
[k
].bAlternateSetting
;
180 altset
->Descriptor
.bNumEndpoints
= interface
->altsetting
[k
].bNumEndpoints
;
181 altset
->Descriptor
.bInterfaceClass
= interface
->altsetting
[k
].bInterfaceClass
;
182 altset
->Descriptor
.bInterfaceSubClass
= interface
->altsetting
[k
].bInterfaceSubClass
;
183 altset
->Descriptor
.bInterfaceProtocol
= interface
->altsetting
[k
].bInterfaceProtocol
;
184 altset
->Descriptor
.iInterface
= interface
->altsetting
[k
].iInterface
;
185 pEndpointDescriptors
= &(altset
->pEndpointDescriptors
);
186 pPipes
= &(altset
->pPipes
);
189 len
+=sizeof(WDU_ALTERNATE_SETTING
);
192 *pEndpointDescriptors
= (WDU_ENDPOINT_DESCRIPTOR
*)(buf
+len
);
193 for (l
= 0; l
< bNumEndpoints
; l
++) {
194 WDU_ENDPOINT_DESCRIPTOR
*ed
= (WDU_ENDPOINT_DESCRIPTOR
*)(buf
+len
);
196 ed
->bLength
= interface
->altsetting
[k
].endpoint
[l
].bLength
;
197 ed
->bDescriptorType
= interface
->altsetting
[k
].endpoint
[l
].bDescriptorType
;
198 ed
->bEndpointAddress
= interface
->altsetting
[k
].endpoint
[l
].bEndpointAddress
;
199 ed
->bmAttributes
= interface
->altsetting
[k
].endpoint
[l
].bmAttributes
;
200 ed
->wMaxPacketSize
= interface
->altsetting
[k
].endpoint
[l
].wMaxPacketSize
;
201 ed
->bInterval
= interface
->altsetting
[k
].endpoint
[l
].bInterval
;
203 len
+= sizeof(WDU_ENDPOINT_DESCRIPTOR
);
206 *pPipes
= (WDU_PIPE_INFO
*)(buf
+len
);
207 for (l
= 0; l
< bNumEndpoints
; l
++) {
208 WDU_PIPE_INFO
*pi
= (WDU_PIPE_INFO
*)(buf
+len
);
210 pi
->dwNumber
= interface
->altsetting
[k
].endpoint
[l
].bEndpointAddress
;
211 pi
->dwMaximumPacketSize
= WDU_GET_MAX_PACKET_SIZE(interface
->altsetting
[k
].endpoint
[l
].wMaxPacketSize
);
212 pi
->type
= interface
->altsetting
[k
].endpoint
[l
].bmAttributes
& USB_ENDPOINT_TYPE_MASK
;
213 if (pi
->type
== PIPE_TYPE_CONTROL
)
214 pi
->direction
= WDU_DIR_IN_OUT
;
217 pi
->direction
= interface
->altsetting
[k
].endpoint
[l
].bEndpointAddress
& USB_ENDPOINT_DIR_MASK
? WDU_DIR_IN
: WDU_DIR_OUT
;
220 pi
->dwInterval
= interface
->altsetting
[k
].endpoint
[l
].bInterval
;
222 len
+= sizeof(WDU_PIPE_INFO
);
225 len
+=(sizeof(WDU_ENDPOINT_DESCRIPTOR
)+sizeof(WDU_PIPE_INFO
))*bNumEndpoints
;
234 int pp_transfer(WD_TRANSFER
*tr
, int fd
, unsigned int request
, unsigned char *wdioctl
) {
237 DPRINTF("dwPort: 0x%lx, cmdTrans: %lu, dwbytes: %ld, fautoinc: %ld, dwoptions: %ld\n",
238 (unsigned long)tr
->dwPort
, tr
->cmdTrans
, tr
->dwBytes
,
239 tr
->fAutoinc
, tr
->dwOptions
);
242 if (tr
->cmdTrans
== 13)
243 DPRINTF("write byte: %d\n", tr
->Data
.Byte
);
247 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
250 DPRINTF("dwPortReturn: 0x%lx, cmdTrans: %lu, dwbytes: %ld, fautoinc: %ld, dwoptions: %ld\n",
251 (unsigned long)tr
->dwPort
, tr
->cmdTrans
, tr
->dwBytes
,
252 tr
->fAutoinc
, tr
->dwOptions
);
254 if (tr
->cmdTrans
== 10)
255 DPRINTF("read byte: %d\n", tr
->Data
.Byte
);
261 int do_wdioctl(int fd
, unsigned int request
, unsigned char *wdioctl
) {
262 struct header_struct
* wdheader
= (struct header_struct
*)wdioctl
;
263 struct version_struct
*version
;
266 if (wdheader
->magic
!= MAGIC
) {
267 fprintf(stderr
,"!!!ERROR: magic header does not match!!!\n");
268 return (*ioctl_func
) (fd
, request
, wdioctl
);
271 switch(request
& ~(0xc0000000)) {
273 version
= (struct version_struct
*)(wdheader
->data
);
274 strcpy(version
->version
, "WinDriver no more");
275 version
->versionul
= 802;
276 DPRINTF("VERSION\n");
280 DPRINTF("LICENSE\n");
283 case CARD_REGISTER_OLD
:
285 /* TODO: Implement for LPT-support */
288 struct card_register
* cr
= (struct card_register
*)(wdheader
->data
);
290 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
292 /* TODO: Open /dev/parport, check, ... */
295 DPRINTF("hCard: %lu\n", cr
->hCard
);
298 DPRINTF("CARD_REGISTER\n");
302 DPRINTF("in USB_TRANSFER");
304 struct usb_transfer
*ut
= (struct usb_transfer
*)(wdheader
->data
);
307 DPRINTF(" unique: %lu, pipe: %lu, read: %lu, options: %lx, size: %lu, timeout: %lx\n",
308 ut
->dwUniqueID
, ut
->dwPipeNum
, ut
->fRead
,
309 ut
->dwOptions
, ut
->dwBufferSize
, ut
->dwTimeout
);
310 DPRINTF("setup packet: ");
311 hexdump(ut
->SetupPacket
, 8);
313 if (!ut
->fRead
&& ut
->dwBufferSize
)
315 hexdump(ut
->pBuffer
, ut
->dwBufferSize
);
320 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
322 /* http://www.jungo.com/support/documentation/windriver/802/wdusb_man_mhtml/node55.html#SECTION001213000000000000000 */
323 if (ut
->dwPipeNum
== 0) { /* control pipe */
324 int requesttype
, request
, value
, index
, size
;
325 requesttype
= ut
->SetupPacket
[0];
326 request
= ut
->SetupPacket
[1];
327 value
= ut
->SetupPacket
[2] | (ut
->SetupPacket
[3] << 8);
328 index
= ut
->SetupPacket
[4] | (ut
->SetupPacket
[5] << 8);
329 size
= ut
->SetupPacket
[6] | (ut
->SetupPacket
[7] << 8);
330 DPRINTF("requesttype: %x, request: %x, value: %u, index: %u, size: %u\n", requesttype
, request
, value
, index
, size
);
331 ret
= usb_control_msg(usb_devhandle
, requesttype
, request
, value
, index
, ut
->pBuffer
, size
, ut
->dwTimeout
);
334 ret
= usb_bulk_read(usb_devhandle
, ut
->dwPipeNum
, ut
->pBuffer
, ut
->dwBufferSize
, ut
->dwTimeout
);
337 ret
= usb_bulk_write(usb_devhandle
, ut
->dwPipeNum
, ut
->pBuffer
, ut
->dwBufferSize
, ut
->dwTimeout
);
342 fprintf(stderr
, "usb_transfer: %d (%s)\n", ret
, usb_strerror());
344 ut
->dwBytesTransferred
= ret
;
350 DPRINTF("Transferred: %lu (%s)\n",ut
->dwBytesTransferred
, (ut
->fRead
?"read":"write"));
351 if (ut
->fRead
&& ut
->dwBytesTransferred
)
354 hexdump(ut
->pBuffer
, ut
->dwBytesTransferred
);
362 DPRINTF("INT_ENABLE\n");
364 struct interrupt
*it
= (struct interrupt
*)(wdheader
->data
);
366 DPRINTF("Handle: %lu, Options: %lx, ncmds: %lu, enableok: %lu, count: %lu, lost: %lu, stopped: %lu\n",
367 it
->hInterrupt
, it
->dwOptions
,
368 it
->dwCmds
, it
->fEnableOk
, it
->dwCounter
,
369 it
->dwLost
, it
->fStopped
);
374 pthread_mutex_trylock(&int_wait
);
380 DPRINTF("INT_DISABLE\n");
382 struct interrupt
*it
= (struct interrupt
*)(wdheader
->data
);
384 DPRINTF("Handle: %lu, Options: %lx, ncmds: %lu, enableok: %lu, count: %lu, lost: %lu, stopped: %lu\n",
385 it
->hInterrupt
, it
->dwOptions
,
386 it
->dwCmds
, it
->fEnableOk
, it
->dwCounter
,
387 it
->dwLost
, it
->fStopped
);
389 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
394 if (pthread_mutex_trylock(&int_wait
) == EBUSY
)
395 pthread_mutex_unlock(&int_wait
);
397 DPRINTF("Handle: %lu, Options: %lx, ncmds: %lu, enableok: %lu, count: %lu, lost: %lu, stopped: %lu\n",
398 it
->hInterrupt
, it
->dwOptions
,
399 it
->dwCmds
, it
->fEnableOk
, it
->dwCounter
,
400 it
->dwLost
, it
->fStopped
);
404 case USB_SET_INTERFACE
:
405 DPRINTF("USB_SET_INTERFACE\n");
407 struct usb_set_interface
*usi
= (struct usb_set_interface
*)(wdheader
->data
);
409 DPRINTF("unique: %lu, interfacenum: %lu, alternatesetting: %lu, options: %lx\n",
410 usi
->dwUniqueID
, usi
->dwInterfaceNum
,
411 usi
->dwAlternateSetting
, usi
->dwOptions
);
413 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
417 usb_devhandle
= usb_open(usbdevice
);
419 /* FIXME: Select right interface! */
420 ret
= usb_claim_interface(usb_devhandle
, usbdevice
->config
[0].interface
[usi
->dwInterfaceNum
].altsetting
[usi
->dwAlternateSetting
].bInterfaceNumber
);
423 usbinterface
= usbdevice
->config
[0].interface
[usi
->dwInterfaceNum
].altsetting
[usi
->dwAlternateSetting
].bInterfaceNumber
;
424 ret
= usb_set_altinterface(usb_devhandle
, usi
->dwAlternateSetting
);
426 fprintf(stderr
, "usb_set_altinterface: %d\n", ret
);
428 fprintf(stderr
, "usb_set_configuration: %d (%s)\n", ret
, usb_strerror());
431 fprintf(stderr
, "usb_claim_interface: %d -> %d (%s)\n",
432 usbdevice
->config
[0].interface
[usi
->dwInterfaceNum
].altsetting
[usi
->dwAlternateSetting
].bInterfaceNumber
,
433 ret
, usb_strerror());
437 DPRINTF("unique: %lu, interfacenum: %lu, alternatesetting: %lu, options: %lx\n",
438 usi
->dwUniqueID
, usi
->dwInterfaceNum
,
439 usi
->dwAlternateSetting
, usi
->dwOptions
);
443 case USB_GET_DEVICE_DATA_OLD
:
444 case USB_GET_DEVICE_DATA
:
445 DPRINTF("USB_GET_DEVICE_DATA\n");
447 struct usb_get_device_data
*ugdd
= (struct usb_get_device_data
*)(wdheader
->data
);
450 DPRINTF("unique: %lu, bytes: %lu, options: %lx\n",
451 ugdd
->dwUniqueID
, ugdd
->dwBytes
,
454 pSize
= ugdd
->dwBytes
;
455 if (!ugdd
->dwBytes
) {
457 ugdd
->dwBytes
= usb_deviceinfo(NULL
);
460 usb_deviceinfo((unsigned char*)ugdd
->pBuf
);
465 case EVENT_REGISTER_OLD
:
467 DPRINTF("EVENT_REGISTER\n");
469 struct event
*e
= (struct event
*)(wdheader
->data
);
473 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",
474 e
->handle
, e
->dwAction
,
475 e
->dwStatus
, e
->dwEventId
, e
->dwCardType
,
476 e
->hKernelPlugIn
, e
->dwOptions
,
477 e
->u
.Usb
.deviceId
.dwVendorId
,
478 e
->u
.Usb
.deviceId
.dwProductId
,
479 e
->u
.Usb
.dwUniqueID
, e
->dwEventVer
,
480 e
->dwNumMatchTables
);
482 for (i
= 0; i
< e
->dwNumMatchTables
; i
++) {
484 DPRINTF("match: dev: %04x:%04x, class: %x, subclass: %x, intclass: %x, intsubclass: %x, intproto: %x\n",
485 e
->matchTables
[i
].VendorId
,
486 e
->matchTables
[i
].ProductId
,
487 e
->matchTables
[i
].bDeviceClass
,
488 e
->matchTables
[i
].bDeviceSubClass
,
489 e
->matchTables
[i
].bInterfaceClass
,
490 e
->matchTables
[i
].bInterfaceSubClass
,
491 e
->matchTables
[i
].bInterfaceProtocol
);
493 for (bus
= busses
; bus
; bus
= bus
->next
) {
494 struct usb_device
*dev
;
496 for (dev
= bus
->devices
; dev
; dev
= dev
->next
) {
497 struct usb_device_descriptor
*desc
= &(dev
->descriptor
);
499 if((desc
->idVendor
== e
->matchTables
[i
].VendorId
) &&
500 (desc
->idProduct
== e
->matchTables
[i
].ProductId
) &&
501 (desc
->bDeviceClass
== e
->matchTables
[i
].bDeviceClass
) &&
502 (desc
->bDeviceSubClass
== e
->matchTables
[i
].bDeviceSubClass
)) {
504 for (ac
= 0; ac
< desc
->bNumConfigurations
; ac
++) {
505 struct usb_interface
*interface
= dev
->config
[ac
].interface
;
508 for (ai
= 0; ai
< interface
->num_altsetting
; ai
++) {
510 DPRINTF("intclass: %x, intsubclass: %x, intproto: %x\n",
511 interface
->altsetting
[i
].bInterfaceClass
,
512 interface
->altsetting
[i
].bInterfaceSubClass
,
513 interface
->altsetting
[i
].bInterfaceProtocol
);
515 if ((interface
->altsetting
[ai
].bInterfaceSubClass
== e
->matchTables
[i
].bInterfaceSubClass
) &&
516 (interface
->altsetting
[ai
].bInterfaceProtocol
== e
->matchTables
[i
].bInterfaceProtocol
)){
517 /* TODO: check interfaceClass! */
518 DPRINTF("found device with libusb\n");
520 card_type
= e
->dwCardType
;
530 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
536 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",
537 e
->handle
, e
->dwAction
,
538 e
->dwStatus
, e
->dwEventId
, e
->dwCardType
,
539 e
->hKernelPlugIn
, e
->dwOptions
,
540 e
->u
.Usb
.deviceId
.dwVendorId
,
541 e
->u
.Usb
.deviceId
.dwProductId
,
542 e
->u
.Usb
.dwUniqueID
, e
->dwEventVer
,
543 e
->dwNumMatchTables
);
545 for (i
= 0; i
< e
->dwNumMatchTables
; i
++)
546 DPRINTF("match: dev: %04x:%04x, class: %x, subclass: %x, intclass: %x, intsubclass: %x, intproto: %x\n",
547 e
->matchTables
[i
].VendorId
,
548 e
->matchTables
[i
].ProductId
,
549 e
->matchTables
[i
].bDeviceClass
,
550 e
->matchTables
[i
].bDeviceSubClass
,
551 e
->matchTables
[i
].bInterfaceClass
,
552 e
->matchTables
[i
].bInterfaceSubClass
,
553 e
->matchTables
[i
].bInterfaceProtocol
);
560 DPRINTF("TRANSFER\n");
562 WD_TRANSFER
*tr
= (WD_TRANSFER
*)(wdheader
->data
);
564 ret
= pp_transfer(tr
, fd
, request
, wdioctl
);
569 DPRINTF("MULTI_TRANSFER\n");
571 WD_TRANSFER
*tr
= (WD_TRANSFER
*)(wdheader
->data
);
572 unsigned long num
= wdheader
->size
/sizeof(WD_TRANSFER
);
576 for (i
= 0; i
< num
; i
++) {
577 DPRINTF("Transfer %d:\n", i
+1);
579 wdheader
->size
= sizeof(WD_TRANSFER
);
581 wdheader
->data
= tr
+ i
;
583 ret
= pp_transfer(tr
+ i
, fd
, request
, wdioctl
);
594 case EVENT_UNREGISTER
:
595 DPRINTF("EVENT_UNREGISTER\n");
597 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
602 DPRINTF("INT_WAIT\n");
604 struct interrupt
*it
= (struct interrupt
*)(wdheader
->data
);
606 DPRINTF("Handle: %lu, Options: %lx, ncmds: %lu, enableok: %lu, count: %lu, lost: %lu, stopped: %lu\n",
607 it
->hInterrupt
, it
->dwOptions
,
608 it
->dwCmds
, it
->fEnableOk
, it
->dwCounter
,
609 it
->dwLost
, it
->fStopped
);
612 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
615 if (it
->dwCounter
== 0) {
618 pthread_mutex_lock(&int_wait
);
619 pthread_mutex_unlock(&int_wait
);
622 pthread_mutex_lock(&int_wait
);
623 pthread_mutex_unlock(&int_wait
);
627 DPRINTF("INT_WAIT_RETURN: Handle: %lu, Options: %lx, ncmds: %lu, enableok: %lu, count: %lu, lost: %lu, stopped: %lu\n",
628 it
->hInterrupt
, it
->dwOptions
, it
->dwCmds
,
629 it
->fEnableOk
, it
->dwCounter
, it
->dwLost
,
634 case CARD_UNREGISTER
:
635 DPRINTF("CARD_UNREGISTER\n");
637 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
642 DPRINTF("EVENT_PULL\n");
644 struct event
*e
= (struct event
*)(wdheader
->data
);
648 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",
649 e
->handle
, e
->dwAction
, e
->dwStatus
,
650 e
->dwEventId
, e
->dwCardType
, e
->hKernelPlugIn
,
651 e
->dwOptions
, e
->u
.Usb
.deviceId
.dwVendorId
,
652 e
->u
.Usb
.deviceId
.dwProductId
,
653 e
->u
.Usb
.dwUniqueID
, e
->dwEventVer
,
654 e
->dwNumMatchTables
);
656 for (i
= 0; i
< e
->dwNumMatchTables
; i
++)
657 DPRINTF("match: dev: %04x:%04x, class: %x, subclass: %x, intclass: %x, intsubclass: %x, intproto: %x\n",
658 e
->matchTables
[i
].VendorId
,
659 e
->matchTables
[i
].ProductId
,
660 e
->matchTables
[i
].bDeviceClass
,
661 e
->matchTables
[i
].bDeviceSubClass
,
662 e
->matchTables
[i
].bInterfaceClass
,
663 e
->matchTables
[i
].bInterfaceSubClass
,
664 e
->matchTables
[i
].bInterfaceProtocol
);
668 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
671 struct usb_interface
*interface
= usbdevice
->config
->interface
;
673 e
->dwCardType
= card_type
;
676 e
->u
.Usb
.dwUniqueID
= 110;
677 e
->matchTables
[0].VendorId
= usbdevice
->descriptor
.idVendor
;
678 e
->matchTables
[0].ProductId
= usbdevice
->descriptor
.idProduct
;
679 e
->matchTables
[0].bDeviceClass
= usbdevice
->descriptor
.bDeviceClass
;
680 e
->matchTables
[0].bDeviceSubClass
= usbdevice
->descriptor
.bDeviceSubClass
;
681 e
->matchTables
[0].bInterfaceClass
= interface
->altsetting
[0].bInterfaceClass
;
682 e
->matchTables
[0].bInterfaceSubClass
= interface
->altsetting
[0].bInterfaceSubClass
;
683 e
->matchTables
[0].bInterfaceProtocol
= interface
->altsetting
[0].bInterfaceProtocol
;
688 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",
689 e
->handle
, e
->dwAction
, e
->dwStatus
,
690 e
->dwEventId
, e
->dwCardType
, e
->hKernelPlugIn
,
691 e
->dwOptions
, e
->u
.Usb
.deviceId
.dwVendorId
,
692 e
->u
.Usb
.deviceId
.dwProductId
,
693 e
->u
.Usb
.dwUniqueID
, e
->dwEventVer
,
694 e
->dwNumMatchTables
);
696 for (i
= 0; i
< e
->dwNumMatchTables
; i
++)
697 DPRINTF("match: dev: %04x:%04x, class: %x, subclass: %x, intclass: %x, intsubclass: %x, intproto: %x\n",
698 e
->matchTables
[i
].VendorId
,
699 e
->matchTables
[i
].ProductId
,
700 e
->matchTables
[i
].bDeviceClass
,
701 e
->matchTables
[i
].bDeviceSubClass
,
702 e
->matchTables
[i
].bInterfaceClass
,
703 e
->matchTables
[i
].bInterfaceSubClass
,
704 e
->matchTables
[i
].bInterfaceProtocol
);
711 fprintf(stderr
,"!!!Unsupported IOCTL: %x!!!\n", request
);
713 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
721 int ioctl(int fd
, int request
, ...) {
727 ioctl_func
= (int (*) (int, int, void *)) dlsym (RTLD_NEXT
, "ioctl");
729 va_start (args
, request
);
730 argp
= va_arg (args
, void *);
734 ret
= do_wdioctl(fd
, request
, argp
);
736 ret
= (*ioctl_func
) (fd
, request
, argp
);
741 int open (const char *pathname
, int flags
, ...) {
742 static int (*func
) (const char *, int, mode_t
) = NULL
;
748 func
= (int (*) (const char *, int, mode_t
)) dlsym (RTLD_NEXT
, "open");
750 if (flags
& O_CREAT
) {
751 va_start(args
, flags
);
752 mode
= va_arg(args
, mode_t
);
756 if (!strcmp (pathname
, "/dev/windrvr6")) {
757 DPRINTF("opening windrvr6\n");
759 windrvrfd
= fd
= (*func
) ("/dev/null", flags
, mode
);
761 windrvrfd
= fd
= (*func
) (pathname
, flags
, mode
);
768 busses
= usb_get_busses();
774 return (*func
) (pathname
, flags
, mode
);
778 static int (*func
) (int) = NULL
;
781 func
= (int (*) (int)) dlsym(RTLD_NEXT
, "close");
783 if (fd
== windrvrfd
&& windrvrfd
>= 0) {
784 DPRINTF("close windrvrfd\n");
785 if (usbinterface
>= 0)
786 usb_release_interface(usb_devhandle
, usbinterface
);
789 usb_close(usb_devhandle
);
791 usb_devhandle
= NULL
;
799 FILE *fopen(const char *path
, const char *mode
) {
801 static FILE* (*func
) (const char*, const char*) = NULL
;
804 func
= (FILE* (*) (const char*, const char*)) dlsym(RTLD_NEXT
, "fopen");
806 ret
= (*func
) (path
, mode
);
808 if (!strcmp (path
, "/proc/modules")) {
809 DPRINTF("opening /proc/modules\n");
819 char *fgets(char *s
, int size
, FILE *stream
) {
820 static char* (*func
) (char*, int, FILE*) = NULL
;
821 const char modules
[][256] = {"windrvr6 1 0 - Live 0xdeadbeef\n", "parport_pc 1 0 - Live 0xdeadbeef\n"};
826 func
= (char* (*) (char*, int, FILE*)) dlsym(RTLD_NEXT
, "fgets");
828 if (modulesfp
== stream
) {
829 if (modules_read
< sizeof(modules
)) {
830 strcpy(s
, modules
[modules_read
]);
835 ret
= (*func
)(s
,size
,stream
);
841 int fclose(FILE *fp
) {
842 static int (*func
) (FILE*) = NULL
;
845 func
= (int (*) (FILE*)) dlsym(RTLD_NEXT
, "fclose");
847 if (fp
== modulesfp
) {
854 int access(const char *pathname
, int mode
) {
855 static int (*func
) (const char*, int);
858 func
= (int (*) (const char*, int)) dlsym(RTLD_NEXT
, "access");
860 if (!strcmp(pathname
, "/dev/windrvr6")) {
863 return (*func
)(pathname
, mode
);