1 /* libusb/ppdev 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 <sys/ioctl.h>
42 #include <sys/utsname.h>
43 #include <bits/wordsize.h>
44 #include "usb-driver.h"
47 static int (*ioctl_func
) (int, int, void *) = NULL
;
48 static int windrvrfd
= -1;
49 static unsigned long ppbase
= 0;
50 static unsigned long ecpbase
= 0;
51 static struct parport_config
*pport
= NULL
;
52 static FILE *modulesfp
= NULL
;
53 static FILE *baseaddrfp
= NULL
;
54 static int baseaddrnum
= 0;
55 static int modules_read
= 0;
56 static struct usb_bus
*busses
= NULL
;
57 static struct usb_device
*usbdevice
;
58 static usb_dev_handle
*usb_devhandle
= NULL
;
59 static int usbinterface
= -1;
60 static int usbalternate
= -1;
61 static unsigned long card_type
;
62 static int ints_enabled
= 0;
63 static pthread_mutex_t int_wait
= PTHREAD_MUTEX_INITIALIZER
;
67 void hexdump(unsigned char *buf
, int len
) {
70 for(i
=0; i
<len
; i
++) {
71 fprintf(stderr
,"%02x ", buf
[i
]);
78 static int usb_deviceinfo(unsigned char *buf
) {
81 WDU_CONFIGURATION
**pConfigs
, **pActiveConfig
;
82 WDU_INTERFACE
**pActiveInterface
;
85 struct usb_device_info
*udi
= (struct usb_device_info
*)(buf
+len
);
87 udi
->Descriptor
.bLength
= sizeof(WDU_DEVICE_DESCRIPTOR
);
88 udi
->Descriptor
.bDescriptorType
= usbdevice
->descriptor
.bDescriptorType
;
89 udi
->Descriptor
.bcdUSB
= usbdevice
->descriptor
.bcdUSB
;
90 udi
->Descriptor
.bDeviceClass
= usbdevice
->descriptor
.bDeviceClass
;
91 udi
->Descriptor
.bDeviceSubClass
= usbdevice
->descriptor
.bDeviceSubClass
;
92 udi
->Descriptor
.bDeviceProtocol
= usbdevice
->descriptor
.bDeviceProtocol
;
93 udi
->Descriptor
.bMaxPacketSize0
= usbdevice
->descriptor
.bMaxPacketSize0
;
94 udi
->Descriptor
.idVendor
= usbdevice
->descriptor
.idVendor
;
95 udi
->Descriptor
.idProduct
= usbdevice
->descriptor
.idProduct
;
96 udi
->Descriptor
.bcdDevice
= usbdevice
->descriptor
.bcdDevice
;
97 udi
->Descriptor
.iManufacturer
= usbdevice
->descriptor
.iManufacturer
;
98 udi
->Descriptor
.iProduct
= usbdevice
->descriptor
.iProduct
;
99 udi
->Descriptor
.iSerialNumber
= usbdevice
->descriptor
.iSerialNumber
;
100 udi
->Descriptor
.bNumConfigurations
= usbdevice
->descriptor
.bNumConfigurations
;
102 /* TODO: Fix Pipe0! */
103 udi
->Pipe0
.dwNumber
= 0x00;
104 udi
->Pipe0
.dwMaximumPacketSize
= usbdevice
->descriptor
.bMaxPacketSize0
;
106 udi
->Pipe0
.direction
= WDU_DIR_IN_OUT
;
107 udi
->Pipe0
.dwInterval
= 0;
109 pConfigs
= &(udi
->pConfigs
);
110 pActiveConfig
= &(udi
->pActiveConfig
);
111 pActiveInterface
= &(udi
->pActiveInterface
[0]);
114 len
= sizeof(struct usb_device_info
);
116 for (i
=0; i
<usbdevice
->descriptor
.bNumConfigurations
; i
++)
118 struct usb_config_descriptor
*conf_desc
= &usbdevice
->config
[i
];
119 WDU_INTERFACE
**pInterfaces
;
120 WDU_ALTERNATE_SETTING
**pAlternateSettings
[conf_desc
->bNumInterfaces
];
121 WDU_ALTERNATE_SETTING
**pActiveAltSetting
[conf_desc
->bNumInterfaces
];
124 WDU_CONFIGURATION
*cfg
= (WDU_CONFIGURATION
*)(buf
+len
);
127 *pActiveConfig
= cfg
;
129 cfg
->Descriptor
.bLength
= conf_desc
->bLength
;
130 cfg
->Descriptor
.bDescriptorType
= conf_desc
->bDescriptorType
;
131 cfg
->Descriptor
.wTotalLength
= conf_desc
->wTotalLength
;
132 cfg
->Descriptor
.bNumInterfaces
= conf_desc
->bNumInterfaces
;
133 cfg
->Descriptor
.bConfigurationValue
= conf_desc
->bConfigurationValue
;
134 cfg
->Descriptor
.iConfiguration
= conf_desc
->iConfiguration
;
135 cfg
->Descriptor
.bmAttributes
= conf_desc
->bmAttributes
;
136 cfg
->Descriptor
.MaxPower
= conf_desc
->MaxPower
;
138 cfg
->dwNumInterfaces
= conf_desc
->bNumInterfaces
;
140 pInterfaces
= &(cfg
->pInterfaces
);
142 len
+= sizeof(WDU_CONFIGURATION
);
145 *pInterfaces
= (WDU_INTERFACE
*)(buf
+len
);
146 for (j
=0; j
<conf_desc
->bNumInterfaces
; j
++) {
147 WDU_INTERFACE
*iface
= (WDU_INTERFACE
*)(buf
+len
);
149 pActiveInterface
[j
] = iface
;
151 pAlternateSettings
[j
] = &(iface
->pAlternateSettings
);
152 iface
->dwNumAltSettings
= usbdevice
->config
[i
].interface
[j
].num_altsetting
;
153 pActiveAltSetting
[j
] = &(iface
->pActiveAltSetting
);
155 len
+= sizeof(WDU_INTERFACE
);
158 len
+= sizeof(WDU_INTERFACE
) * conf_desc
->bNumInterfaces
;
161 for (j
=0; j
<conf_desc
->bNumInterfaces
; j
++)
163 struct usb_interface
*interface
= &usbdevice
->config
[i
].interface
[j
];
166 *pAlternateSettings
[j
] = (WDU_ALTERNATE_SETTING
*)(buf
+len
);
168 *pActiveAltSetting
[j
] = (WDU_ALTERNATE_SETTING
*)(buf
+len
);
171 for(k
=0; k
<interface
->num_altsetting
; k
++)
173 unsigned char bNumEndpoints
= interface
->altsetting
[k
].bNumEndpoints
;
174 WDU_ENDPOINT_DESCRIPTOR
**pEndpointDescriptors
;
175 WDU_PIPE_INFO
**pPipes
;
178 WDU_ALTERNATE_SETTING
*altset
= (WDU_ALTERNATE_SETTING
*)(buf
+len
);
180 altset
->Descriptor
.bLength
= interface
->altsetting
[k
].bLength
;
181 altset
->Descriptor
.bDescriptorType
= interface
->altsetting
[k
].bDescriptorType
;
182 altset
->Descriptor
.bInterfaceNumber
= interface
->altsetting
[k
].bInterfaceNumber
;
183 altset
->Descriptor
.bAlternateSetting
= interface
->altsetting
[k
].bAlternateSetting
;
184 altset
->Descriptor
.bNumEndpoints
= interface
->altsetting
[k
].bNumEndpoints
;
185 altset
->Descriptor
.bInterfaceClass
= interface
->altsetting
[k
].bInterfaceClass
;
186 altset
->Descriptor
.bInterfaceSubClass
= interface
->altsetting
[k
].bInterfaceSubClass
;
187 altset
->Descriptor
.bInterfaceProtocol
= interface
->altsetting
[k
].bInterfaceProtocol
;
188 altset
->Descriptor
.iInterface
= interface
->altsetting
[k
].iInterface
;
189 pEndpointDescriptors
= &(altset
->pEndpointDescriptors
);
190 pPipes
= &(altset
->pPipes
);
193 len
+=sizeof(WDU_ALTERNATE_SETTING
);
196 *pEndpointDescriptors
= (WDU_ENDPOINT_DESCRIPTOR
*)(buf
+len
);
197 for (l
= 0; l
< bNumEndpoints
; l
++) {
198 WDU_ENDPOINT_DESCRIPTOR
*ed
= (WDU_ENDPOINT_DESCRIPTOR
*)(buf
+len
);
200 ed
->bLength
= interface
->altsetting
[k
].endpoint
[l
].bLength
;
201 ed
->bDescriptorType
= interface
->altsetting
[k
].endpoint
[l
].bDescriptorType
;
202 ed
->bEndpointAddress
= interface
->altsetting
[k
].endpoint
[l
].bEndpointAddress
;
203 ed
->bmAttributes
= interface
->altsetting
[k
].endpoint
[l
].bmAttributes
;
204 ed
->wMaxPacketSize
= interface
->altsetting
[k
].endpoint
[l
].wMaxPacketSize
;
205 ed
->bInterval
= interface
->altsetting
[k
].endpoint
[l
].bInterval
;
207 len
+= sizeof(WDU_ENDPOINT_DESCRIPTOR
);
210 *pPipes
= (WDU_PIPE_INFO
*)(buf
+len
);
211 for (l
= 0; l
< bNumEndpoints
; l
++) {
212 WDU_PIPE_INFO
*pi
= (WDU_PIPE_INFO
*)(buf
+len
);
214 pi
->dwNumber
= interface
->altsetting
[k
].endpoint
[l
].bEndpointAddress
;
215 pi
->dwMaximumPacketSize
= WDU_GET_MAX_PACKET_SIZE(interface
->altsetting
[k
].endpoint
[l
].wMaxPacketSize
);
216 pi
->type
= interface
->altsetting
[k
].endpoint
[l
].bmAttributes
& USB_ENDPOINT_TYPE_MASK
;
217 if (pi
->type
== PIPE_TYPE_CONTROL
)
218 pi
->direction
= WDU_DIR_IN_OUT
;
221 pi
->direction
= interface
->altsetting
[k
].endpoint
[l
].bEndpointAddress
& USB_ENDPOINT_DIR_MASK
? WDU_DIR_IN
: WDU_DIR_OUT
;
224 pi
->dwInterval
= interface
->altsetting
[k
].endpoint
[l
].bInterval
;
226 len
+= sizeof(WDU_PIPE_INFO
);
229 len
+=(sizeof(WDU_ENDPOINT_DESCRIPTOR
)+sizeof(WDU_PIPE_INFO
))*bNumEndpoints
;
238 static int usb_claim(int claim
) {
240 static int claimed
= 0;
242 if (usbinterface
< 0)
249 ret
= usb_claim_interface(usb_devhandle
, usbinterface
);
252 ret
= usb_set_altinterface(usb_devhandle
, usbalternate
);
254 fprintf(stderr
, "usb_set_altinterface: %d\n", ret
);
256 fprintf(stderr
, "usb_claim_interface: %d -> %d (%s)\n",
257 usbinterface
, ret
, usb_strerror());
263 ret
= usb_release_interface(usb_devhandle
, usbinterface
);
271 static int do_wdioctl(int fd
, unsigned int request
, unsigned char *wdioctl
) {
272 struct header_struct
* wdheader
= (struct header_struct
*)wdioctl
;
273 struct version_struct
*version
;
276 if (wdheader
->magic
!= MAGIC
) {
277 fprintf(stderr
,"!!!ERROR: magic header does not match!!!\n");
278 return (*ioctl_func
) (fd
, request
, wdioctl
);
281 switch(request
& ~(0xc0000000)) {
283 version
= (struct version_struct
*)(wdheader
->data
);
284 strcpy(version
->version
, "libusb-driver.so version: " USB_DRIVER_VERSION
);
285 version
->versionul
= 802;
286 DPRINTF("VERSION\n");
290 DPRINTF("LICENSE\n");
293 case CARD_REGISTER_OLD
:
295 DPRINTF("CARD_REGISTER\n");
297 struct card_register
* cr
= (struct card_register
*)(wdheader
->data
);
299 DPRINTF("Items: %lu, Addr: 0x%lx, bytes: %lu, bar: %lu\n",
301 (unsigned long)cr
->Card
.Item
[0].I
.IO
.dwAddr
,
302 cr
->Card
.Item
[0].I
.IO
.dwBytes
,
303 cr
->Card
.Item
[0].I
.IO
.dwBar
);
305 DPRINTF("Items: %lu, Addr: 0x%lx, bytes: %lu, bar: %lu\n",
307 (unsigned long)cr
->Card
.Item
[1].I
.IO
.dwAddr
,
308 cr
->Card
.Item
[1].I
.IO
.dwBytes
,
309 cr
->Card
.Item
[1].I
.IO
.dwBar
);
311 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
314 pport
= config_get((unsigned long)cr
->Card
.Item
[0].I
.IO
.dwAddr
/ 0x10);
318 ret
= pport
->open((unsigned long)cr
->Card
.Item
[0].I
.IO
.dwAddr
/ 0x10);
320 ppbase
= (unsigned long)cr
->Card
.Item
[0].I
.IO
.dwAddr
;
322 if (cr
->Card
.dwItems
> 1 && cr
->Card
.Item
[1].I
.IO
.dwAddr
)
323 ecpbase
= (unsigned long)cr
->Card
.Item
[1].I
.IO
.dwAddr
;
331 DPRINTF("hCard: %lu\n", cr
->hCard
);
336 DPRINTF("in USB_TRANSFER");
338 struct usb_transfer
*ut
= (struct usb_transfer
*)(wdheader
->data
);
341 DPRINTF(" unique: %lu, pipe: %lu, read: %lu, options: %lx, size: %lu, timeout: %lx\n",
342 ut
->dwUniqueID
, ut
->dwPipeNum
, ut
->fRead
,
343 ut
->dwOptions
, ut
->dwBufferSize
, ut
->dwTimeout
);
344 if (ut
->dwPipeNum
== 0) {
345 DPRINTF("setup packet: ");
346 hexdump(ut
->SetupPacket
, 8);
349 if (!ut
->fRead
&& ut
->dwBufferSize
)
351 hexdump(ut
->pBuffer
, ut
->dwBufferSize
);
356 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
359 /* http://www.jungo.com/support/documentation/windriver/802/wdusb_man_mhtml/node55.html#SECTION001213000000000000000 */
360 if (ut
->dwPipeNum
== 0) { /* control pipe */
361 int requesttype
, request
, value
, index
, size
;
362 requesttype
= ut
->SetupPacket
[0];
363 request
= ut
->SetupPacket
[1];
364 value
= ut
->SetupPacket
[2] | (ut
->SetupPacket
[3] << 8);
365 index
= ut
->SetupPacket
[4] | (ut
->SetupPacket
[5] << 8);
366 size
= ut
->SetupPacket
[6] | (ut
->SetupPacket
[7] << 8);
367 DPRINTF("requesttype: %x, request: %x, value: %u, index: %u, size: %u\n", requesttype
, request
, value
, index
, size
);
368 ret
= usb_control_msg(usb_devhandle
, requesttype
, request
, value
, index
, ut
->pBuffer
, size
, ut
->dwTimeout
);
371 ret
= usb_bulk_read(usb_devhandle
, ut
->dwPipeNum
, ut
->pBuffer
, ut
->dwBufferSize
, ut
->dwTimeout
);
373 ret
= usb_bulk_write(usb_devhandle
, ut
->dwPipeNum
, ut
->pBuffer
, ut
->dwBufferSize
, ut
->dwTimeout
);
379 fprintf(stderr
, "usb_transfer: %d (%s)\n", ret
, usb_strerror());
381 ut
->dwBytesTransferred
= ret
;
387 DPRINTF("Transferred: %lu (%s)\n",ut
->dwBytesTransferred
, (ut
->fRead
?"read":"write"));
388 if (ut
->fRead
&& ut
->dwBytesTransferred
)
391 hexdump(ut
->pBuffer
, ut
->dwBytesTransferred
);
399 DPRINTF("INT_ENABLE\n");
401 struct interrupt
*it
= (struct interrupt
*)(wdheader
->data
);
403 DPRINTF("Handle: %lu, Options: %lx, ncmds: %lu, enableok: %lu, count: %lu, lost: %lu, stopped: %lu\n",
404 it
->hInterrupt
, it
->dwOptions
,
405 it
->dwCmds
, it
->fEnableOk
, it
->dwCounter
,
406 it
->dwLost
, it
->fStopped
);
411 pthread_mutex_trylock(&int_wait
);
417 DPRINTF("INT_DISABLE\n");
419 struct interrupt
*it
= (struct interrupt
*)(wdheader
->data
);
421 DPRINTF("Handle: %lu, Options: %lx, ncmds: %lu, enableok: %lu, count: %lu, lost: %lu, stopped: %lu\n",
422 it
->hInterrupt
, it
->dwOptions
,
423 it
->dwCmds
, it
->fEnableOk
, it
->dwCounter
,
424 it
->dwLost
, it
->fStopped
);
426 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
431 if (pthread_mutex_trylock(&int_wait
) == EBUSY
)
432 pthread_mutex_unlock(&int_wait
);
434 DPRINTF("Handle: %lu, Options: %lx, ncmds: %lu, enableok: %lu, count: %lu, lost: %lu, stopped: %lu\n",
435 it
->hInterrupt
, it
->dwOptions
,
436 it
->dwCmds
, it
->fEnableOk
, it
->dwCounter
,
437 it
->dwLost
, it
->fStopped
);
441 case USB_SET_INTERFACE
:
442 DPRINTF("USB_SET_INTERFACE\n");
444 struct usb_set_interface
*usi
= (struct usb_set_interface
*)(wdheader
->data
);
446 DPRINTF("unique: %lu, interfacenum: %lu, alternatesetting: %lu, options: %lx\n",
447 usi
->dwUniqueID
, usi
->dwInterfaceNum
,
448 usi
->dwAlternateSetting
, usi
->dwOptions
);
450 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
454 usb_devhandle
= usb_open(usbdevice
);
456 usbinterface
= usbdevice
->config
[0].interface
[usi
->dwInterfaceNum
].altsetting
[usi
->dwAlternateSetting
].bInterfaceNumber
;
457 usbalternate
= usi
->dwAlternateSetting
;
460 DPRINTF("unique: %lu, interfacenum: %lu, alternatesetting: %lu, options: %lx\n",
461 usi
->dwUniqueID
, usi
->dwInterfaceNum
,
462 usi
->dwAlternateSetting
, usi
->dwOptions
);
466 case USB_GET_DEVICE_DATA_OLD
:
467 case USB_GET_DEVICE_DATA
:
468 DPRINTF("USB_GET_DEVICE_DATA\n");
470 struct usb_get_device_data
*ugdd
= (struct usb_get_device_data
*)(wdheader
->data
);
473 DPRINTF("unique: %lu, bytes: %lu, options: %lx\n",
474 ugdd
->dwUniqueID
, ugdd
->dwBytes
,
477 pSize
= ugdd
->dwBytes
;
478 if (!ugdd
->dwBytes
) {
480 ugdd
->dwBytes
= usb_deviceinfo(NULL
);
483 usb_deviceinfo((unsigned char*)ugdd
->pBuf
);
488 case EVENT_REGISTER_OLD
:
490 DPRINTF("EVENT_REGISTER\n");
492 struct event
*e
= (struct event
*)(wdheader
->data
);
495 int busnum
= -1, devnum
= -1;
498 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",
499 e
->handle
, e
->dwAction
,
500 e
->dwStatus
, e
->dwEventId
, e
->dwCardType
,
501 e
->hKernelPlugIn
, e
->dwOptions
,
502 e
->u
.Usb
.deviceId
.dwVendorId
,
503 e
->u
.Usb
.deviceId
.dwProductId
,
504 e
->u
.Usb
.dwUniqueID
, e
->dwEventVer
,
505 e
->dwNumMatchTables
);
507 devpos
= getenv("XILINX_USB_DEV");
508 if (devpos
!= NULL
) {
510 char *devstr
= NULL
, *remainder
;
512 DPRINTF("XILINX_USB_DEV=%s\n", devpos
);
514 for (j
= 0; j
< strlen(devpos
) && devpos
[j
] != 0; j
++) {
515 if (devpos
[j
] == ':') {
517 devstr
= &(devpos
[j
+1]);
521 if (devstr
&& strlen(devstr
) > 0) {
522 busnum
= strtol(devpos
, &remainder
, 10);
523 if (devpos
== remainder
) {
526 devnum
= strtol(devstr
, &remainder
, 10);
527 if (devstr
== remainder
) {
531 fprintf(stderr
,"Using XILINX platform cable USB at %03d:%03d\n",
538 for (i
= 0; i
< e
->dwNumMatchTables
; i
++) {
540 DPRINTF("match: dev: %04x:%04x, class: %x, subclass: %x, intclass: %x, intsubclass: %x, intproto: %x\n",
541 e
->matchTables
[i
].VendorId
,
542 e
->matchTables
[i
].ProductId
,
543 e
->matchTables
[i
].bDeviceClass
,
544 e
->matchTables
[i
].bDeviceSubClass
,
545 e
->matchTables
[i
].bInterfaceClass
,
546 e
->matchTables
[i
].bInterfaceSubClass
,
547 e
->matchTables
[i
].bInterfaceProtocol
);
549 for (bus
= busses
; bus
; bus
= bus
->next
) {
550 struct usb_device
*dev
;
552 if ((devnum
!= -1) && (strtol(bus
->dirname
, NULL
, 10) != busnum
))
555 for (dev
= bus
->devices
; dev
; dev
= dev
->next
) {
556 struct usb_device_descriptor
*desc
= &(dev
->descriptor
);
558 if((desc
->idVendor
== e
->matchTables
[i
].VendorId
) &&
559 (desc
->idProduct
== e
->matchTables
[i
].ProductId
) &&
560 (desc
->bDeviceClass
== e
->matchTables
[i
].bDeviceClass
) &&
561 (desc
->bDeviceSubClass
== e
->matchTables
[i
].bDeviceSubClass
) &&
562 ((devnum
== -1) || (strtol(dev
->filename
, NULL
, 10) == devnum
)) ) {
564 for (ac
= 0; ac
< desc
->bNumConfigurations
; ac
++) {
565 struct usb_interface
*interface
= dev
->config
[ac
].interface
;
568 for (ai
= 0; ai
< interface
->num_altsetting
; ai
++) {
570 DPRINTF("intclass: %x, intsubclass: %x, intproto: %x\n",
571 interface
->altsetting
[i
].bInterfaceClass
,
572 interface
->altsetting
[i
].bInterfaceSubClass
,
573 interface
->altsetting
[i
].bInterfaceProtocol
);
575 if ((interface
->altsetting
[ai
].bInterfaceSubClass
== e
->matchTables
[i
].bInterfaceSubClass
) &&
576 (interface
->altsetting
[ai
].bInterfaceProtocol
== e
->matchTables
[i
].bInterfaceProtocol
)){
577 /* TODO: check interfaceClass! */
578 DPRINTF("found device with libusb\n");
580 card_type
= e
->dwCardType
;
590 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
596 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",
597 e
->handle
, e
->dwAction
,
598 e
->dwStatus
, e
->dwEventId
, e
->dwCardType
,
599 e
->hKernelPlugIn
, e
->dwOptions
,
600 e
->u
.Usb
.deviceId
.dwVendorId
,
601 e
->u
.Usb
.deviceId
.dwProductId
,
602 e
->u
.Usb
.dwUniqueID
, e
->dwEventVer
,
603 e
->dwNumMatchTables
);
605 for (i
= 0; i
< e
->dwNumMatchTables
; i
++)
606 DPRINTF("match: dev: %04x:%04x, class: %x, subclass: %x, intclass: %x, intsubclass: %x, intproto: %x\n",
607 e
->matchTables
[i
].VendorId
,
608 e
->matchTables
[i
].ProductId
,
609 e
->matchTables
[i
].bDeviceClass
,
610 e
->matchTables
[i
].bDeviceSubClass
,
611 e
->matchTables
[i
].bInterfaceClass
,
612 e
->matchTables
[i
].bInterfaceSubClass
,
613 e
->matchTables
[i
].bInterfaceProtocol
);
620 DPRINTF("TRANSFER\n");
622 WD_TRANSFER
*tr
= (WD_TRANSFER
*)(wdheader
->data
);
625 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
627 ret
= pport
->transfer(tr
, fd
, request
, ppbase
, ecpbase
, 1);
632 case MULTI_TRANSFER_OLD
:
634 DPRINTF("MULTI_TRANSFER\n");
636 WD_TRANSFER
*tr
= (WD_TRANSFER
*)(wdheader
->data
);
637 unsigned long num
= wdheader
->size
/sizeof(WD_TRANSFER
);
639 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
641 ret
= pport
->transfer(tr
, fd
, request
, ppbase
, ecpbase
, num
);
646 case EVENT_UNREGISTER
:
647 DPRINTF("EVENT_UNREGISTER\n");
649 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
654 DPRINTF("INT_WAIT\n");
656 struct interrupt
*it
= (struct interrupt
*)(wdheader
->data
);
658 DPRINTF("Handle: %lu, Options: %lx, ncmds: %lu, enableok: %lu, count: %lu, lost: %lu, stopped: %lu\n",
659 it
->hInterrupt
, it
->dwOptions
,
660 it
->dwCmds
, it
->fEnableOk
, it
->dwCounter
,
661 it
->dwLost
, it
->fStopped
);
664 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
667 if (it
->dwCounter
== 0) {
670 pthread_mutex_lock(&int_wait
);
671 pthread_mutex_unlock(&int_wait
);
674 pthread_mutex_lock(&int_wait
);
675 pthread_mutex_unlock(&int_wait
);
679 DPRINTF("INT_WAIT_RETURN: Handle: %lu, Options: %lx, ncmds: %lu, enableok: %lu, count: %lu, lost: %lu, stopped: %lu\n",
680 it
->hInterrupt
, it
->dwOptions
, it
->dwCmds
,
681 it
->fEnableOk
, it
->dwCounter
, it
->dwLost
,
686 case CARD_UNREGISTER
:
687 DPRINTF("CARD_UNREGISTER\n");
689 struct card_register
* cr
= (struct card_register
*)(wdheader
->data
);
691 DPRINTF("Addr: 0x%lx, bytes: %lu, bar: %lu\n",
692 (unsigned long)cr
->Card
.Item
[0].I
.IO
.dwAddr
,
693 cr
->Card
.Item
[0].I
.IO
.dwBytes
,
694 cr
->Card
.Item
[0].I
.IO
.dwBar
);
696 DPRINTF("hCard: %lu\n", cr
->hCard
);
699 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
702 pport
->close(cr
->hCard
);
710 DPRINTF("EVENT_PULL\n");
712 struct event
*e
= (struct event
*)(wdheader
->data
);
716 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",
717 e
->handle
, e
->dwAction
, e
->dwStatus
,
718 e
->dwEventId
, e
->dwCardType
, e
->hKernelPlugIn
,
719 e
->dwOptions
, e
->u
.Usb
.deviceId
.dwVendorId
,
720 e
->u
.Usb
.deviceId
.dwProductId
,
721 e
->u
.Usb
.dwUniqueID
, e
->dwEventVer
,
722 e
->dwNumMatchTables
);
724 for (i
= 0; i
< e
->dwNumMatchTables
; i
++)
725 DPRINTF("match: dev: %04x:%04x, class: %x, subclass: %x, intclass: %x, intsubclass: %x, intproto: %x\n",
726 e
->matchTables
[i
].VendorId
,
727 e
->matchTables
[i
].ProductId
,
728 e
->matchTables
[i
].bDeviceClass
,
729 e
->matchTables
[i
].bDeviceSubClass
,
730 e
->matchTables
[i
].bInterfaceClass
,
731 e
->matchTables
[i
].bInterfaceSubClass
,
732 e
->matchTables
[i
].bInterfaceProtocol
);
736 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
739 struct usb_interface
*interface
= usbdevice
->config
->interface
;
741 e
->dwCardType
= card_type
;
744 e
->u
.Usb
.dwUniqueID
= 110;
745 e
->matchTables
[0].VendorId
= usbdevice
->descriptor
.idVendor
;
746 e
->matchTables
[0].ProductId
= usbdevice
->descriptor
.idProduct
;
747 e
->matchTables
[0].bDeviceClass
= usbdevice
->descriptor
.bDeviceClass
;
748 e
->matchTables
[0].bDeviceSubClass
= usbdevice
->descriptor
.bDeviceSubClass
;
749 e
->matchTables
[0].bInterfaceClass
= interface
->altsetting
[0].bInterfaceClass
;
750 e
->matchTables
[0].bInterfaceSubClass
= interface
->altsetting
[0].bInterfaceSubClass
;
751 e
->matchTables
[0].bInterfaceProtocol
= interface
->altsetting
[0].bInterfaceProtocol
;
756 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",
757 e
->handle
, e
->dwAction
, e
->dwStatus
,
758 e
->dwEventId
, e
->dwCardType
, e
->hKernelPlugIn
,
759 e
->dwOptions
, e
->u
.Usb
.deviceId
.dwVendorId
,
760 e
->u
.Usb
.deviceId
.dwProductId
,
761 e
->u
.Usb
.dwUniqueID
, e
->dwEventVer
,
762 e
->dwNumMatchTables
);
764 for (i
= 0; i
< e
->dwNumMatchTables
; i
++)
765 DPRINTF("match: dev: %04x:%04x, class: %x, subclass: %x, intclass: %x, intsubclass: %x, intproto: %x\n",
766 e
->matchTables
[i
].VendorId
,
767 e
->matchTables
[i
].ProductId
,
768 e
->matchTables
[i
].bDeviceClass
,
769 e
->matchTables
[i
].bDeviceSubClass
,
770 e
->matchTables
[i
].bInterfaceClass
,
771 e
->matchTables
[i
].bInterfaceSubClass
,
772 e
->matchTables
[i
].bInterfaceProtocol
);
779 fprintf(stderr
,"!!!Unsupported IOCTL: %x!!!\n", request
);
781 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
789 int ioctl(int fd
, unsigned long int request
, ...) {
795 ioctl_func
= (int (*) (int, int, void *)) dlsym (RTLD_NEXT
, "ioctl");
797 va_start (args
, request
);
798 argp
= va_arg (args
, void *);
802 ret
= do_wdioctl(fd
, request
, argp
);
804 ret
= (*ioctl_func
) (fd
, request
, argp
);
809 int open (const char *pathname
, int flags
, ...) {
810 static int (*func
) (const char *, int, mode_t
) = NULL
;
816 func
= (int (*) (const char *, int, mode_t
)) dlsym (RTLD_NEXT
, "open");
818 if (flags
& O_CREAT
) {
819 va_start(args
, flags
);
820 mode
= va_arg(args
, mode_t
);
824 if (!strcmp (pathname
, "/dev/windrvr6")) {
825 DPRINTF("opening windrvr6\n");
827 windrvrfd
= fd
= (*func
) ("/dev/null", flags
, mode
);
829 windrvrfd
= fd
= (*func
) (pathname
, flags
, mode
);
836 busses
= usb_get_busses();
842 return (*func
) (pathname
, flags
, mode
);
846 static int (*func
) (int) = NULL
;
849 func
= (int (*) (int)) dlsym(RTLD_NEXT
, "close");
851 if (fd
== windrvrfd
&& windrvrfd
>= 0) {
852 DPRINTF("close windrvrfd\n");
855 usb_close(usb_devhandle
);
857 usb_devhandle
= NULL
;
865 FILE *fopen(const char *path
, const char *mode
) {
867 static FILE* (*func
) (const char*, const char*) = NULL
;
872 func
= (FILE* (*) (const char*, const char*)) dlsym(RTLD_NEXT
, "fopen");
874 for (i
= 0; i
< 4; i
++) {
875 snprintf(buf
, sizeof(buf
), "/proc/sys/dev/parport/parport%d/base-addr", i
);
876 if (!strcmp(path
, buf
)) {
877 DPRINTF("open base-addr of parport%d\n", i
);
878 if (config_is_real_pport(i
)) {
879 ret
= (*func
) (path
, mode
);
881 ret
= (*func
) ("/dev/null", mode
);
893 ret
= (*func
) (path
, mode
);
895 if (!strcmp(path
, "/proc/modules")) {
896 DPRINTF("opening /proc/modules\n");
906 char *fgets(char *s
, int size
, FILE *stream
) {
907 static char* (*func
) (char*, int, FILE*) = NULL
;
908 const char modules
[][256] = {"windrvr6 1 0 - Live 0xdeadbeef\n", "parport_pc 1 0 - Live 0xdeadbeef\n"};
914 func
= (char* (*) (char*, int, FILE*)) dlsym(RTLD_NEXT
, "fgets");
916 if (modulesfp
== stream
) {
917 if (modules_read
< sizeof(modules
) / sizeof(modules
[0])) {
918 strcpy(s
, modules
[modules_read
]);
922 } else if (baseaddrfp
== stream
) {
923 snprintf(s
, sizeof(buf
), "%d\t%d\n",
924 (baseaddrnum
) * 0x10,
925 ((baseaddrnum
) * 0x10) + 0x400);
928 ret
= (*func
)(s
,size
,stream
);
934 int fclose(FILE *fp
) {
935 static int (*func
) (FILE*) = NULL
;
938 func
= (int (*) (FILE*)) dlsym(RTLD_NEXT
, "fclose");
940 if (fp
== modulesfp
) {
944 if (fp
== baseaddrfp
) {
951 int access(const char *pathname
, int mode
) {
952 static int (*func
) (const char*, int);
955 func
= (int (*) (const char*, int)) dlsym(RTLD_NEXT
, "access");
957 if (pathname
&& !strcmp(pathname
, "/dev/windrvr6")) {
960 return (*func
)(pathname
, mode
);
965 int uname (struct utsname
*__name
) {
966 static int (*func
) (struct utsname
*);
970 func
= (int (*) (struct utsname
*)) dlsym(RTLD_NEXT
, "uname");
972 ret
= (*func
)(__name
);
974 if (ret
== 0 && (!strcmp(__name
->machine
, "x86_64"))) {
975 strcpy(__name
->machine
, "i686");