]>
git.zerfleddert.de Git - usb-driver/blob - usb-driver.c
e92467f95b2ebbea50967bbb7cfa5b86ecbb4e4c
1 #if defined(__GNUC__) && !defined(__STRICT_ANSI__)
6 #define REAL_LIBC RTLD_NEXT
8 #define REAL_LIBC ((void *) -1L)
17 #include <sys/types.h>
25 static int (*ioctl_func
) (int, int, void *) = NULL
;
26 static int windrvrfd
= 0;
27 static struct usb_bus
*busses
= NULL
;
28 static struct usb_device
*usbdevice
;
29 static usb_dev_handle
*usb_devhandle
= NULL
;
30 static unsigned long card_type
;
31 static int ints_enabled
= 0;
35 void hexdump(unsigned char *buf
, int len
);
36 void diff(unsigned char *buf1
, unsigned char *buf2
, int len
);
38 //unique: 94, bytes: 276, options: 0
40 //12 01 00 02 00 00 00 40 fd 03 08 00 00 00 01 02 12 01 00 02 00 00 00 40 fd 03 08 00 00 00 01 02
41 //00 01 00 00 00 00 00 00 40 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 40 00 00 00 00 00 00 00
42 //03 00 00 00 00 00 00 00 38 45 21 08 38 45 21 08 03 00 00 00 00 00 00 00 38 45 21 08 38 45 21 08
43 //4c 45 21 08 00 00 00 00 00 00 00 00 00 00 00 00 4c 45 21 08 00 00 00 00 00 00 00 00 00 00 00 00
44 //00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
45 //00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
46 //00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
47 //00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
48 //00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
49 //00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
50 //00 00 00 00 00 00 00 00 09 02 20 00 01 02 00 80 00 00 00 00 00 00 00 00 09 02 20 00 01 02 00 80
51 //8c 00 00 00 01 00 00 00 4c 45 21 08 58 45 21 08 8c 00 00 00 01 00 00 00 4c 45 21 08 58 45 21 08
52 //01 00 00 00 58 45 21 08 09 04 00 00 02 ff 00 00 01 00 00 00 58 45 21 08 09 04 00 00 02 ff 00 00
53 //00 00 00 00 6c 45 21 08 7c 45 21 08 07 05 02 02 00 00 00 00 6c 45 21 08 7c 45 21 08 07 05 02 02
54 //00 02 00 00 07 05 86 02 00 02 00 00 02 00 00 00 00 02 00 00 07 05 86 02 00 02 00 00 02 00 00 00
55 //00 02 00 00 02 00 00 00 02 00 00 00 00 00 00 00 00 02 00 00 02 00 00 00 02 00 00 00 00 00 00 00
56 //86 00 00 00 00 02 00 00 02 00 00 00 01 00 00 00 86 00 00 00 00 02 00 00 02 00 00 00 01 00 00 00
57 //00 00 00 00 00 00 00 00
58 int usb_deviceinfo(unsigned char *buf
) {
61 WDU_CONFIGURATION
**pConfigs
, **pActiveConfig
;
62 WDU_INTERFACE
**pActiveInterface
;
65 struct usb_device_info
*udi
= (struct usb_device_info
*)(buf
+len
);
67 udi
->Descriptor
.bLength
= sizeof(WDU_DEVICE_DESCRIPTOR
);
68 udi
->Descriptor
.bDescriptorType
= usbdevice
->descriptor
.bDescriptorType
;
69 udi
->Descriptor
.bcdUSB
= usbdevice
->descriptor
.bcdUSB
;
70 udi
->Descriptor
.bDeviceClass
= usbdevice
->descriptor
.bDeviceClass
;
71 udi
->Descriptor
.bDeviceSubClass
= usbdevice
->descriptor
.bDeviceSubClass
;
72 udi
->Descriptor
.bDeviceProtocol
= usbdevice
->descriptor
.bDeviceProtocol
;
73 udi
->Descriptor
.bMaxPacketSize0
= usbdevice
->descriptor
.bMaxPacketSize0
;
74 udi
->Descriptor
.idVendor
= usbdevice
->descriptor
.idVendor
;
75 udi
->Descriptor
.idProduct
= usbdevice
->descriptor
.idProduct
;
76 udi
->Descriptor
.bcdDevice
= usbdevice
->descriptor
.bcdDevice
;
77 udi
->Descriptor
.iManufacturer
= usbdevice
->descriptor
.iManufacturer
;
78 udi
->Descriptor
.iProduct
= usbdevice
->descriptor
.iProduct
;
79 udi
->Descriptor
.iSerialNumber
= usbdevice
->descriptor
.iSerialNumber
;
80 udi
->Descriptor
.bNumConfigurations
= usbdevice
->descriptor
.bNumConfigurations
;
82 /* TODO: Fix Pipe0! */
83 udi
->Pipe0
.dwNumber
= 0x00;
84 udi
->Pipe0
.dwMaximumPacketSize
= usbdevice
->descriptor
.bMaxPacketSize0
;
86 udi
->Pipe0
.direction
= 3;
87 udi
->Pipe0
.dwInterval
= 0;
89 pConfigs
= &(udi
->pConfigs
);
90 pActiveConfig
= &(udi
->pActiveConfig
);
91 pActiveInterface
= &(udi
->pActiveInterface
[0]);
94 len
= sizeof(struct usb_device_info
);
96 for (i
=0; i
<usbdevice
->descriptor
.bNumConfigurations
; i
++)
98 struct usb_config_descriptor
*conf_desc
= &usbdevice
->config
[i
];
99 WDU_INTERFACE
**pInterfaces
;
100 WDU_ALTERNATE_SETTING
**pAlternateSettings
[conf_desc
->bNumInterfaces
];
101 WDU_ALTERNATE_SETTING
**pActiveAltSetting
[conf_desc
->bNumInterfaces
];
104 WDU_CONFIGURATION
*cfg
= (WDU_CONFIGURATION
*)(buf
+len
);
107 *pActiveConfig
= cfg
;
109 cfg
->Descriptor
.bLength
= conf_desc
->bLength
;
110 cfg
->Descriptor
.bDescriptorType
= conf_desc
->bDescriptorType
;
111 cfg
->Descriptor
.wTotalLength
= conf_desc
->wTotalLength
;
112 cfg
->Descriptor
.bNumInterfaces
= conf_desc
->bNumInterfaces
;
113 cfg
->Descriptor
.bConfigurationValue
= conf_desc
->bConfigurationValue
;
114 cfg
->Descriptor
.iConfiguration
= conf_desc
->iConfiguration
;
115 cfg
->Descriptor
.bmAttributes
= conf_desc
->bmAttributes
;
116 cfg
->Descriptor
.MaxPower
= conf_desc
->MaxPower
;
118 cfg
->dwNumInterfaces
= conf_desc
->bNumInterfaces
;
120 pInterfaces
= &(cfg
->pInterfaces
);
122 len
+= sizeof(WDU_CONFIGURATION
);
125 *pInterfaces
= (WDU_INTERFACE
*)(buf
+len
);
126 for (j
=0; j
<conf_desc
->bNumInterfaces
; j
++) {
127 WDU_INTERFACE
*iface
= (WDU_INTERFACE
*)(buf
+len
);
129 pActiveInterface
[j
] = iface
;
131 pAlternateSettings
[j
] = &(iface
->pAlternateSettings
);
132 iface
->dwNumAltSettings
= usbdevice
->config
[i
].interface
[j
].num_altsetting
;
133 pActiveAltSetting
[j
] = &(iface
->pActiveAltSetting
);
135 len
+= sizeof(WDU_INTERFACE
);
138 len
+= sizeof(WDU_INTERFACE
) * conf_desc
->bNumInterfaces
;
141 for (j
=0; j
<conf_desc
->bNumInterfaces
; j
++)
143 struct usb_interface
*interface
= &usbdevice
->config
[i
].interface
[j
];
146 *pAlternateSettings
[j
] = (WDU_ALTERNATE_SETTING
*)(buf
+len
);
148 *pActiveAltSetting
[j
] = (WDU_ALTERNATE_SETTING
*)(buf
+len
);
151 for(k
=0; k
<interface
->num_altsetting
; k
++)
153 unsigned char bNumEndpoints
= interface
->altsetting
[k
].bNumEndpoints
;
154 WDU_ENDPOINT_DESCRIPTOR
**pEndpointDescriptors
;
155 WDU_PIPE_INFO
**pPipes
;
158 WDU_ALTERNATE_SETTING
*altset
= (WDU_ALTERNATE_SETTING
*)(buf
+len
);
160 altset
->Descriptor
.bLength
= interface
->altsetting
[k
].bLength
;
161 altset
->Descriptor
.bDescriptorType
= interface
->altsetting
[k
].bDescriptorType
;
162 altset
->Descriptor
.bInterfaceNumber
= interface
->altsetting
[k
].bInterfaceNumber
;
163 altset
->Descriptor
.bAlternateSetting
= interface
->altsetting
[k
].bAlternateSetting
;
164 altset
->Descriptor
.bNumEndpoints
= interface
->altsetting
[k
].bNumEndpoints
;
165 altset
->Descriptor
.bInterfaceClass
= interface
->altsetting
[k
].bInterfaceClass
;
166 altset
->Descriptor
.bInterfaceSubClass
= interface
->altsetting
[k
].bInterfaceSubClass
;
167 altset
->Descriptor
.bInterfaceProtocol
= interface
->altsetting
[k
].bInterfaceProtocol
;
168 altset
->Descriptor
.iInterface
= interface
->altsetting
[k
].iInterface
;
169 pEndpointDescriptors
= &(altset
->pEndpointDescriptors
);
170 pPipes
= &(altset
->pPipes
);
173 len
+=sizeof(WDU_ALTERNATE_SETTING
);
176 *pEndpointDescriptors
= (WDU_ENDPOINT_DESCRIPTOR
*)(buf
+len
);
177 for (l
= 0; l
< bNumEndpoints
; l
++) {
178 WDU_ENDPOINT_DESCRIPTOR
*ed
= (WDU_ENDPOINT_DESCRIPTOR
*)(buf
+len
);
180 ed
->bLength
= interface
->altsetting
[k
].endpoint
[l
].bLength
;
181 ed
->bDescriptorType
= interface
->altsetting
[k
].endpoint
[l
].bDescriptorType
;
182 ed
->bEndpointAddress
= interface
->altsetting
[k
].endpoint
[l
].bEndpointAddress
;
183 ed
->bmAttributes
= interface
->altsetting
[k
].endpoint
[l
].bmAttributes
;
184 ed
->wMaxPacketSize
= interface
->altsetting
[k
].endpoint
[l
].wMaxPacketSize
;
185 ed
->bInterval
= interface
->altsetting
[k
].endpoint
[l
].bInterval
;
187 len
+= sizeof(WDU_ENDPOINT_DESCRIPTOR
);
190 *pPipes
= (WDU_PIPE_INFO
*)(buf
+len
);
191 for (l
= 0; l
< bNumEndpoints
; l
++) {
192 WDU_PIPE_INFO
*pi
= (WDU_PIPE_INFO
*)(buf
+len
);
194 pi
->dwNumber
= interface
->altsetting
[k
].endpoint
[l
].bEndpointAddress
;
195 pi
->dwMaximumPacketSize
= WDU_GET_MAX_PACKET_SIZE(interface
->altsetting
[k
].endpoint
[l
].wMaxPacketSize
);
196 pi
->type
= interface
->altsetting
[k
].endpoint
[l
].bmAttributes
& USB_ENDPOINT_TYPE_MASK
;
197 if (pi
->type
== PIPE_TYPE_CONTROL
)
198 pi
->direction
= WDU_DIR_IN_OUT
;
201 pi
->direction
= interface
->altsetting
[k
].endpoint
[l
].bEndpointAddress
& USB_ENDPOINT_DIR_MASK
? WDU_DIR_IN
: WDU_DIR_OUT
;
204 pi
->dwInterval
= interface
->altsetting
[k
].endpoint
[l
].bInterval
;
206 len
+= sizeof(WDU_PIPE_INFO
);
209 len
+=(sizeof(WDU_ENDPOINT_DESCRIPTOR
)+sizeof(WDU_PIPE_INFO
))*bNumEndpoints
;
218 int do_wdioctl(int fd
, unsigned int request
, unsigned char *wdioctl
) {
219 struct header_struct
* wdheader
= (struct header_struct
*)wdioctl
;
220 struct version_struct
*version
;
223 if (wdheader
->magic
!= MAGIC
) {
224 fprintf(stderr
,"!!!ERROR: magic header does not match!!!\n");
225 return (*ioctl_func
) (fd
, request
, wdioctl
);
230 version
= (struct version_struct
*)(wdheader
->data
);
231 strcpy(version
->version
, "WinDriver no more");
232 version
->versionul
= 999;
233 fprintf(stderr
,"faking VERSION\n");
237 fprintf(stderr
,"faking LICENSE\n");
242 //struct card_register* cr = (struct card_register*)(wdheader->data);
243 /* Todo: LPT-Port already in use */
245 fprintf(stderr
,"faking CARD_REGISTER\n");
249 fprintf(stderr
,"in USB_TRANSFER");
251 struct usb_transfer
*ut
= (struct usb_transfer
*)(wdheader
->data
);
252 int requesttype
, request
, value
, index
, size
;
254 fprintf(stderr
," unique: %lu, pipe: %lu, read: %lu, options: %lx, size: %lu, timeout: %lx\n", ut
->dwUniqueID
, ut
->dwPipeNum
, ut
->fRead
, ut
->dwOptions
, ut
->dwBufferSize
, ut
->dwTimeout
);
255 fprintf(stderr
,"setup packet: ");
256 hexdump(ut
->SetupPacket
, 8);
257 fprintf(stderr
,"\n");
258 if (!ut
->fRead
&& ut
->dwBufferSize
)
260 hexdump(ut
->pBuffer
, ut
->dwBufferSize
);
261 fprintf(stderr
,"\n");
265 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
267 /* http://www.jungo.com/support/documentation/windriver/802/wdusb_man_mhtml/node55.html#SECTION001213000000000000000 */
268 requesttype
= ut
->SetupPacket
[0];
269 request
= ut
->SetupPacket
[1];
270 value
= ut
->SetupPacket
[2] | (ut
->SetupPacket
[3] << 8);
271 index
= ut
->SetupPacket
[4] | (ut
->SetupPacket
[5] << 8);
272 size
= ut
->SetupPacket
[6] | (ut
->SetupPacket
[7] << 8);
273 fprintf(stderr
, "requesttype: %x, request: %x, value: %u, index: %u, size: %u\n", requesttype
, request
, value
, index
, size
);
274 ret
= usb_control_msg(usb_devhandle
, requesttype
, request
, value
, index
, ut
->pBuffer
, size
, ut
->dwTimeout
);
276 fprintf(stderr
, "usb_control_msg: %d\n", ret
);
278 ut
->dwBytesTransferred
= ret
;
284 fprintf(stderr
,"Transferred: %lu (%s)\n",ut
->dwBytesTransferred
, (ut
->fRead
?"read":"write"));
285 if (ut
->fRead
&& ut
->dwBytesTransferred
)
287 fprintf(stderr
,"Read: ");
288 hexdump(ut
->pBuffer
, ut
->dwBytesTransferred
);
289 fprintf(stderr
,"\n");
295 fprintf(stderr
,"INT_ENABLE\n");
297 struct interrupt
*it
= (struct interrupt
*)(wdheader
->data
);
299 fprintf(stderr
,"Handle: %lu, Options: %lx, ncmds: %lu, enableok: %lu, count: %lu, lost: %lu, stopped: %lu\n", it
->hInterrupt
, it
->dwOptions
, it
->dwCmds
, it
->fEnableOk
, it
->dwCounter
, it
->dwLost
, it
->fStopped
);
303 //ret = (*ioctl_func) (fd, request, wdioctl);
309 fprintf(stderr
,"INT_DISABLE\n");
311 struct interrupt
*it
= (struct interrupt
*)(wdheader
->data
);
313 fprintf(stderr
,"Handle: %lu, Options: %lx, ncmds: %lu, enableok: %lu, count: %lu, lost: %lu, stopped: %lu\n", it
->hInterrupt
, it
->dwOptions
, it
->dwCmds
, it
->fEnableOk
, it
->dwCounter
, it
->dwLost
, it
->fStopped
);
315 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
321 fprintf(stderr
,"Handle: %lu, Options: %lx, ncmds: %lu, enableok: %lu, count: %lu, lost: %lu, stopped: %lu\n", it
->hInterrupt
, it
->dwOptions
, it
->dwCmds
, it
->fEnableOk
, it
->dwCounter
, it
->dwLost
, it
->fStopped
);
325 case USB_SET_INTERFACE
:
326 fprintf(stderr
,"USB_SET_INTERFACE\n");
328 struct usb_set_interface
*usi
= (struct usb_set_interface
*)(wdheader
->data
);
330 fprintf(stderr
,"unique: %lu, interfacenum: %lu, alternatesetting: %lu, options: %lx\n", usi
->dwUniqueID
, usi
->dwInterfaceNum
, usi
->dwAlternateSetting
, usi
->dwOptions
);
332 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
336 usb_devhandle
= usb_open(usbdevice
);
338 /* FIXME: Select right interface! */
339 ret
= usb_claim_interface(usb_devhandle
, usbdevice
->config
[0].interface
[usi
->dwInterfaceNum
].altsetting
[usi
->dwAlternateSetting
].bInterfaceNumber
);
341 //ret = usb_set_configuration(usb_devhandle, usbdevice->config[0].bConfigurationValue);
343 ret
= usb_set_altinterface(usb_devhandle
, usi
->dwAlternateSetting
);
345 fprintf(stderr
, "usb_set_altinterface: %d\n", ret
);
347 fprintf(stderr
, "usb_set_configuration: %d (%s)\n", ret
, usb_strerror());
350 fprintf(stderr
, "usb_claim_interface: %d -> %d (%s)\n", usbdevice
->config
[0].interface
[usi
->dwInterfaceNum
].altsetting
[usi
->dwAlternateSetting
].bInterfaceNumber
, ret
, usb_strerror());
354 fprintf(stderr
,"unique: %lu, interfacenum: %lu, alternatesetting: %lu, options: %lx\n", usi
->dwUniqueID
, usi
->dwInterfaceNum
, usi
->dwAlternateSetting
, usi
->dwOptions
);
358 case USB_GET_DEVICE_DATA
:
359 fprintf(stderr
,"faking USB_GET_DEVICE_DATA\n");
361 struct usb_get_device_data
*ugdd
= (struct usb_get_device_data
*)(wdheader
->data
);
364 fprintf(stderr
, "unique: %lu, bytes: %lu, options: %lx\n", ugdd
->dwUniqueID
, ugdd
->dwBytes
, ugdd
->dwOptions
);
365 pSize
= ugdd
->dwBytes
;
366 //ret = (*ioctl_func) (fd, request, wdioctl);
367 if (!ugdd
->dwBytes
) {
369 ugdd
->dwBytes
= usb_deviceinfo(NULL
);
372 usb_deviceinfo((unsigned char*)ugdd
->pBuf
);
376 struct usb_device_info
*udi
= (struct usb_device_info
*)ugdd
->pBuf
;
378 fprintf(stderr
, "Vendor: %x\n", udi
->Descriptor
.idVendor
);
384 fprintf(stderr
,"EVENT_REGISTER\n");
386 struct event
*e
= (struct event
*)(wdheader
->data
);
390 fprintf(stderr
,"handle: %lu, action: %lu, status: %lu, eventid: %lu, cardtype: %lu, kplug: %lu, options: %lu, dev: %lx:%lx, unique: %lu, ver: %lu, nummatch: %lu\n", e
->handle
, e
->dwAction
, e
->dwStatus
, e
->dwEventId
, e
->dwCardType
, e
->hKernelPlugIn
, e
->dwOptions
, e
->u
.Usb
.deviceId
.dwVendorId
, e
->u
.Usb
.deviceId
.dwProductId
, e
->u
.Usb
.dwUniqueID
, e
->dwEventVer
, e
->dwNumMatchTables
);
391 for (i
= 0; i
< e
->dwNumMatchTables
; i
++) {
392 fprintf(stderr
,"match: dev: %04x:%04x, class: %x, subclass: %x, intclass: %x, intsubclass: %x, intproto: %x\n", e
->matchTables
[i
].VendorId
, e
->matchTables
[i
].ProductId
, e
->matchTables
[i
].bDeviceClass
, e
->matchTables
[i
].bDeviceSubClass
, e
->matchTables
[i
].bInterfaceClass
, e
->matchTables
[i
].bInterfaceSubClass
, e
->matchTables
[i
].bInterfaceProtocol
);
394 for (bus
= busses
; bus
; bus
= bus
->next
) {
395 struct usb_device
*dev
;
397 for (dev
= bus
->devices
; dev
; dev
= dev
->next
) {
398 struct usb_device_descriptor
*desc
= &(dev
->descriptor
);
400 if((desc
->idVendor
== e
->matchTables
[i
].VendorId
) &&
401 (desc
->idProduct
== e
->matchTables
[i
].ProductId
) &&
402 (desc
->bDeviceClass
== e
->matchTables
[i
].bDeviceClass
) &&
403 (desc
->bDeviceSubClass
== e
->matchTables
[i
].bDeviceSubClass
)) {
405 for (ac
= 0; ac
< desc
->bNumConfigurations
; ac
++) {
406 struct usb_interface
*interface
= dev
->config
[ac
].interface
;
409 for (ai
= 0; ai
< interface
->num_altsetting
; ai
++) {
410 fprintf(stderr
, "intclass: %x, intsubclass: %x, intproto: %x\n", interface
->altsetting
[i
].bInterfaceClass
, interface
->altsetting
[i
].bInterfaceSubClass
, interface
->altsetting
[i
].bInterfaceProtocol
);
411 if ((interface
->altsetting
[ai
].bInterfaceSubClass
== e
->matchTables
[i
].bInterfaceSubClass
) &&
412 (interface
->altsetting
[ai
].bInterfaceProtocol
== e
->matchTables
[i
].bInterfaceProtocol
)){
413 /* TODO: check interfaceClass! */
414 fprintf(stderr
,"!!!FOUND DEVICE WITH LIBUSB!!!\n");
416 card_type
= e
->dwCardType
;
426 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
428 //handle: 0, action: 16371, status: 0, eventid: 0, cardtype: 4294967294, kplug: 0, options: 0, dev: 0:0, unique: 0, ver: 1, nummatch: 2
429 //handle: 1, action: 16371, status: 0, eventid: 0, cardtype: 4294967294, kplug: 0, options: 0, dev: 0:0, unique: 0, ver: 1, nummatch: 2
433 fprintf(stderr
,"handle: %lu, action: %lu, status: %lu, eventid: %lu, cardtype: %lu, kplug: %lu, options: %lu, dev: %lx:%lx, unique: %lu, ver: %lu, nummatch: %lu\n", e
->handle
, e
->dwAction
, e
->dwStatus
, e
->dwEventId
, e
->dwCardType
, e
->hKernelPlugIn
, e
->dwOptions
, e
->u
.Usb
.deviceId
.dwVendorId
, e
->u
.Usb
.deviceId
.dwProductId
, e
->u
.Usb
.dwUniqueID
, e
->dwEventVer
, e
->dwNumMatchTables
);
434 for (i
= 0; i
< e
->dwNumMatchTables
; i
++)
435 fprintf(stderr
,"match: dev: %04x:%04x, class: %x, subclass: %x, intclass: %x, intsubclass: %x, intproto: %x\n", e
->matchTables
[i
].VendorId
, e
->matchTables
[i
].ProductId
, e
->matchTables
[i
].bDeviceClass
, e
->matchTables
[i
].bDeviceSubClass
, e
->matchTables
[i
].bInterfaceClass
, e
->matchTables
[i
].bInterfaceSubClass
, e
->matchTables
[i
].bInterfaceProtocol
);
440 fprintf(stderr
,"TRANSFER\n");
442 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
446 case EVENT_UNREGISTER
:
447 fprintf(stderr
,"EVENT_UNREGISTER\n");
449 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
454 fprintf(stderr
,"INT_WAIT\n");
456 struct interrupt
*it
= (struct interrupt
*)(wdheader
->data
);
458 fprintf(stderr
,"Handle: %lu, Options: %lx, ncmds: %lu, enableok: %lu, count: %lu, lost: %lu, stopped: %lu\n", it
->hInterrupt
, it
->dwOptions
, it
->dwCmds
, it
->fEnableOk
, it
->dwCounter
, it
->dwLost
, it
->fStopped
);
461 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
464 if (it
->dwCounter
== 0) {
467 //FIXME: signal durch FUTEX, overload futex!
468 while(ints_enabled
) {sleep(1);}
471 while(ints_enabled
) {sleep(1);}
475 fprintf(stderr
,"INT_WAIT_RETURN: Handle: %lu, Options: %lx, ncmds: %lu, enableok: %lu, count: %lu, lost: %lu, stopped: %lu\n", it
->hInterrupt
, it
->dwOptions
, it
->dwCmds
, it
->fEnableOk
, it
->dwCounter
, it
->dwLost
, it
->fStopped
);
479 case CARD_UNREGISTER
:
480 fprintf(stderr
,"CARD_UNREGISTER\n");
482 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
487 fprintf(stderr
,"EVENT_PULL\n");
489 struct event
*e
= (struct event
*)(wdheader
->data
);
492 fprintf(stderr
,"handle: %lu, action: %lu, status: %lu, eventid: %lu, cardtype: %lx, kplug: %lu, options: %lu, dev: %lx:%lx, unique: %lu, ver: %lu, nummatch: %lu\n", e
->handle
, e
->dwAction
, e
->dwStatus
, e
->dwEventId
, e
->dwCardType
, e
->hKernelPlugIn
, e
->dwOptions
, e
->u
.Usb
.deviceId
.dwVendorId
, e
->u
.Usb
.deviceId
.dwProductId
, e
->u
.Usb
.dwUniqueID
, e
->dwEventVer
, e
->dwNumMatchTables
);
493 for (i
= 0; i
< e
->dwNumMatchTables
; i
++)
494 fprintf(stderr
,"match: dev: %04x:%04x, class: %x, subclass: %x, intclass: %x, intsubclass: %x, intproto: %x\n", e
->matchTables
[i
].VendorId
, e
->matchTables
[i
].ProductId
, e
->matchTables
[i
].bDeviceClass
, e
->matchTables
[i
].bDeviceSubClass
, e
->matchTables
[i
].bInterfaceClass
, e
->matchTables
[i
].bInterfaceSubClass
, e
->matchTables
[i
].bInterfaceProtocol
);
497 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
500 //handle: 1, action: 0, status: 0, eventid: 0, cardtype: 0, kplug: 0, options: 0, dev: 0:0, unique: 0, ver: 1, nummatch: 1
501 //match: dev: 0:0, class: 0, subclass: 0, intclass: 0, intsubclass: 0, intproto: 0
502 //handle: 1, action: 1, status: 0, eventid: 109, cardtype: 4294967294, kplug: 0, options: 0, dev: 0:0, unique: 90, ver: 1, nummatch: 1
503 //match: dev: 3fd:8, class: 0, subclass: 0, intclass: ff, intsubclass: 0, intproto: 0
505 struct usb_interface
*interface
= usbdevice
->config
->interface
;
507 e
->dwCardType
= card_type
;
510 e
->u
.Usb
.dwUniqueID
= 110;
511 e
->matchTables
[0].VendorId
= usbdevice
->descriptor
.idVendor
;
512 e
->matchTables
[0].ProductId
= usbdevice
->descriptor
.idProduct
;
513 e
->matchTables
[0].bDeviceClass
= usbdevice
->descriptor
.bDeviceClass
;
514 e
->matchTables
[0].bDeviceSubClass
= usbdevice
->descriptor
.bDeviceSubClass
;
515 e
->matchTables
[0].bInterfaceClass
= interface
->altsetting
[0].bInterfaceClass
;
516 e
->matchTables
[0].bInterfaceSubClass
= interface
->altsetting
[0].bInterfaceSubClass
;
517 e
->matchTables
[0].bInterfaceProtocol
= interface
->altsetting
[0].bInterfaceProtocol
;
521 fprintf(stderr
,"handle: %lu, action: %lu, status: %lu, eventid: %lu, cardtype: %lx, kplug: %lu, options: %lu, dev: %lx:%lx, unique: %lu, ver: %lu, nummatch: %lu\n", e
->handle
, e
->dwAction
, e
->dwStatus
, e
->dwEventId
, e
->dwCardType
, e
->hKernelPlugIn
, e
->dwOptions
, e
->u
.Usb
.deviceId
.dwVendorId
, e
->u
.Usb
.deviceId
.dwProductId
, e
->u
.Usb
.dwUniqueID
, e
->dwEventVer
, e
->dwNumMatchTables
);
522 for (i
= 0; i
< e
->dwNumMatchTables
; i
++)
523 fprintf(stderr
,"match: dev: %04x:%04x, class: %x, subclass: %x, intclass: %x, intsubclass: %x, intproto: %x\n", e
->matchTables
[i
].VendorId
, e
->matchTables
[i
].ProductId
, e
->matchTables
[i
].bDeviceClass
, e
->matchTables
[i
].bDeviceSubClass
, e
->matchTables
[i
].bInterfaceClass
, e
->matchTables
[i
].bInterfaceSubClass
, e
->matchTables
[i
].bInterfaceProtocol
);
529 fprintf(stderr
,"!!!Unsupported IOCTL: %x!!!\n", request
);
531 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
540 typedef int (*open_funcptr_t
) (const char *, int, mode_t
);
542 int open (const char *pathname
, int flags
, ...)
544 static open_funcptr_t func
= NULL
;
550 func
= (open_funcptr_t
) dlsym (REAL_LIBC
, "open");
552 if (flags
& O_CREAT
) {
553 va_start(args
, flags
);
554 mode
= va_arg(args
, mode_t
);
558 if (!strcmp (pathname
, "/dev/windrvr6")) {
559 fprintf(stderr
,"opening windrvr6\n");
561 windrvrfd
= fd
= (*func
) ("/dev/null", flags
, mode
);
563 windrvrfd
= fd
= (*func
) (pathname
, flags
, mode
);
570 busses
= usb_get_busses();
573 fd
= (*func
) (pathname
, flags
, mode
);
579 void diff(unsigned char *buf1
, unsigned char *buf2
, int len
) {
582 for(i
=0; i
<len
; i
++) {
583 if (buf1
[i
] != buf2
[i
]) {
584 fprintf(stderr
,"Diff at %d: %02x(%c)->%02x(%c)\n", i
, buf1
[i
], ((buf1
[i
] >= 31 && buf1
[i
] <= 126)?buf1
[i
]:'.'), buf2
[i
], ((buf2
[i
] >= 31 && buf2
[i
] <= 126)?buf2
[i
]:'.'));
589 void hexdump(unsigned char *buf
, int len
) {
592 for(i
=0; i
<len
; i
++) {
593 fprintf(stderr
,"%02x ", buf
[i
]);
595 fprintf(stderr
,"\n");
599 int ioctl(int fd
, int request
, ...)
606 ioctl_func
= (int (*) (int, int, void *)) dlsym (REAL_LIBC
, "ioctl");
608 va_start (args
, request
);
609 argp
= va_arg (args
, void *);
613 ret
= do_wdioctl(fd
, request
, argp
);
615 ret
= (*ioctl_func
) (fd
, request
, argp
);
620 int futex(int *uaddr
, int op
, int val
, const struct timespec
*timeout
, int *uaddr2
, int val3
) {
621 static int (*func
) (int*, int, int, const struct timespec
*, int*, int) = NULL
;
625 func
= (int (*) (int*, int, int, const struct timespec
*, int*, int)) dlsym(REAL_LIBC
, "futex");
627 fprintf(stderr
,"FUTEX: %x\n", (unsigned int)uaddr
);
628 ret
= (*func
) (uaddr
, op
, val
, timeout
, uaddr2
, val3
);
635 void *mmap(void *start
, size_t length
, int prot
, int flags
, int fd
, off_t offset
)
637 static void* (*func
) (void *, size_t, int, int, int, off_t
) = NULL
;
641 func
= (void* (*) (void *, size_t, int, int, int, off_t
)) dlsym (REAL_LIBC
, "mmap");
643 ret
= (*func
) (start
, length
, prot
, flags
, fd
, offset
);
644 fprintf(stderr
,"MMAP: %x, %d, %d, %d, %d, %d -> %x\n", (unsigned int)start
, length
, prot
, flags
, fd
, offset
, (unsigned int)ret
);
651 void *mmap64(void *start
, size_t length
, int prot
, int flags
, int fd
, off64_t offset
)
653 static void* (*func
) (void *, size_t, int, int, int, off64_t
) = NULL
;
657 func
= (void* (*) (void *, size_t, int, int, int, off64_t
)) dlsym (REAL_LIBC
, "mmap64");
659 ret
= (*func
) (start
, length
, prot
, flags
, fd
, offset
);
660 fprintf(stderr
,"MMAP64: %x, %d, %d, %d, %d, %lld -> %x\n", (unsigned int)start
, length
, prot
, flags
, fd
, offset
, (unsigned int)ret
);
667 void *mmap2(void *start
, size_t length
, int prot
, int flags
, int fd
, off_t pgoffset
)
669 static void* (*func
) (void *, size_t, int, int, int, off_t
) = NULL
;
673 func
= (void* (*) (void *, size_t, int, int, int, off_t
)) dlsym (REAL_LIBC
, "mmap2");
675 ret
= (*func
) (start
, length
, prot
, flags
, fd
, pgoffset
);
676 fprintf(stderr
,"MMAP2: %x, %d, %d, %d, %d, %d -> %x\n", (unsigned int)start
, length
, prot
, flags
, fd
, pgoffset
, (unsigned int)ret
);
683 void *malloc(size_t size
)
685 static void* (*func
) (size_t) = NULL
;
689 func
= (void* (*) (size_t)) dlsym(REAL_LIBC
, "malloc");
691 ret
= (*func
) (size
);
693 //fprintf(stderr,"MALLOC: %d -> %x\n", size, (unsigned int) ret);