small fixes
[usb-driver] / usb-driver.c
CommitLineData
cdc711dc 1#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
2
3#define _GNU_SOURCE 1
4
5#if defined(RTLD_NEXT)
6#define REAL_LIBC RTLD_NEXT
7#else
8#define REAL_LIBC ((void *) -1L)
9#endif
10
11#include <dlfcn.h>
12#include <stdarg.h>
13#include <stdlib.h>
14#include <string.h>
15#include <unistd.h>
16#include <fcntl.h>
17#include <sys/types.h>
18#include <sys/stat.h>
19#include <sys/time.h>
20#include <stdio.h>
f10480d1 21#include <usb.h>
da3ba95a 22#include "xilinx.h"
cdc711dc 23
9c9fd67c 24static int (*ioctl_func) (int, int, void *) = NULL;
2c2119eb 25static int windrvrfd = 0;
f10480d1 26static struct usb_bus *busses = NULL;
ac22d975 27static struct usb_device *usb_cable;
292160ed 28static unsigned long card_type;
29
795992ad 30#define NO_WINDRVR 1
cdc711dc 31
32void hexdump(unsigned char *buf, int len);
da3ba95a 33void diff(unsigned char *buf1, unsigned char *buf2, int len);
cdc711dc 34
792bf5f2 35//unique: 94, bytes: 276, options: 0
36//Vendor: 3fd
37//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
38//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
39//03 00 00 00 00 00 00 00 38 45 21 08 38 45 21 08 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
40//4c 45 21 08 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
41//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
42//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
43//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
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 09 02 20 00 01 02 00 80 00 00 00 00 00 00 00 00 09 02 20 00 01 02 00 80
48//8c 00 00 00 01 00 00 00 4c 45 21 08 58 45 21 08 8c 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00
49//01 00 00 00 58 45 21 08 09 04 00 00 02 ff 00 00 01 00 00 00 00 00 00 00 09 04 00 00 02 ff 00 00
50//00 00 00 00 6c 45 21 08 7c 45 21 08 07 05 02 02 00 00 00 00 00 00 00 00 00 00 00 00 07 05 02 02
51//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
52//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
53//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
54//00 00 00 00 00 00 00 00
f95f1d2e 55int usb_deviceinfo(unsigned char *buf) {
56 int i,j,k,l;
57 int len = 0;
58
59 if (buf) {
60 struct usb_device_info *udi = (struct usb_device_info*)(buf+len);
61
62 udi->Descriptor.bLength = sizeof(WDU_DEVICE_DESCRIPTOR);
63 udi->Descriptor.bDescriptorType = usb_cable->descriptor.bDescriptorType;
64 udi->Descriptor.bcdUSB = usb_cable->descriptor.bcdUSB;
65 udi->Descriptor.bDeviceClass = usb_cable->descriptor.bDeviceClass;
66 udi->Descriptor.bDeviceSubClass = usb_cable->descriptor.bDeviceSubClass;
67 udi->Descriptor.bDeviceProtocol = usb_cable->descriptor.bDeviceProtocol;
68 udi->Descriptor.bMaxPacketSize0 = usb_cable->descriptor.bMaxPacketSize0;
69 udi->Descriptor.idVendor = usb_cable->descriptor.idVendor;
70 udi->Descriptor.idProduct = usb_cable->descriptor.idProduct;
71 udi->Descriptor.bcdDevice = usb_cable->descriptor.bcdDevice;
72 udi->Descriptor.iManufacturer = usb_cable->descriptor.iManufacturer;
73 udi->Descriptor.iProduct = usb_cable->descriptor.iProduct;
74 udi->Descriptor.iSerialNumber = usb_cable->descriptor.iSerialNumber;
75 udi->Descriptor.bNumConfigurations = usb_cable->descriptor.bNumConfigurations;
76
77 /* TODO: Fix Pipe0! */
78 udi->Pipe0.dwNumber = 0x00;
79 udi->Pipe0.dwMaximumPacketSize = usb_cable->descriptor.bMaxPacketSize0;
80 udi->Pipe0.type = 0;
81 udi->Pipe0.direction = 3;
82 udi->Pipe0.dwInterval = 0;
83 }
84
85 len = sizeof(struct usb_device_info);
86
87 for (i=0; i<usb_cable->descriptor.bNumConfigurations; i++)
88 {
89 struct usb_config_descriptor *conf_desc = &usb_cable->config[i];
90 if (buf) {
91 WDU_CONFIGURATION *cfg = (WDU_CONFIGURATION*)(buf+len);
92
93 cfg->Descriptor.bLength = conf_desc->bLength;
94 cfg->Descriptor.bDescriptorType = conf_desc->bDescriptorType;
95 cfg->Descriptor.wTotalLength = conf_desc->wTotalLength;
96 cfg->Descriptor.bNumInterfaces = conf_desc->bNumInterfaces;
97 cfg->Descriptor.bConfigurationValue = conf_desc->bConfigurationValue;
98 cfg->Descriptor.iConfiguration = conf_desc->iConfiguration;
99 cfg->Descriptor.bmAttributes = conf_desc->bmAttributes;
100 cfg->Descriptor.MaxPower = conf_desc->MaxPower;
101
102 cfg->dwNumInterfaces = conf_desc->bNumInterfaces;
103 }
104 len += sizeof(WDU_CONFIGURATION);
105 if (buf) {
106 for (j=0; j<conf_desc->bNumInterfaces; j++) {
107 WDU_INTERFACE *iface = (WDU_INTERFACE*)(buf+len);
108 iface->dwNumAltSettings = usb_cable->config[i].interface[j].num_altsetting;
109
110 len += sizeof(WDU_INTERFACE);
111 }
112 } else {
113 len += sizeof(WDU_INTERFACE) * conf_desc->bNumInterfaces;
114 }
115
116 for (j=0; j<conf_desc->bNumInterfaces; j++)
117 {
118 struct usb_interface *interface = &usb_cable->config[i].interface[j];
119 for(k=0; k<interface->num_altsetting; k++)
120 {
121 unsigned char bNumEndpoints;
122 bNumEndpoints = interface->altsetting[k].bNumEndpoints;
123 if (buf) {
124 WDU_ALTERNATE_SETTING *altset = (WDU_ALTERNATE_SETTING*)(buf+len);
125
126 altset->Descriptor.bLength = interface->altsetting[k].bLength;
127 altset->Descriptor.bDescriptorType = interface->altsetting[k].bDescriptorType;
128 altset->Descriptor.bInterfaceNumber = interface->altsetting[k].bInterfaceNumber;
129 altset->Descriptor.bAlternateSetting = interface->altsetting[k].bAlternateSetting;
130 altset->Descriptor.bNumEndpoints = interface->altsetting[k].bNumEndpoints;
131 altset->Descriptor.bInterfaceClass = interface->altsetting[k].bInterfaceClass;
132 altset->Descriptor.bInterfaceSubClass = interface->altsetting[k].bInterfaceSubClass;
133 altset->Descriptor.bInterfaceProtocol = interface->altsetting[k].bInterfaceProtocol;
134 altset->Descriptor.iInterface = interface->altsetting[k].iInterface;
135
136 }
137 len +=sizeof(WDU_ALTERNATE_SETTING);
138
139 if (buf) {
140 for (l = 0; l < bNumEndpoints; l++) {
141 WDU_ENDPOINT_DESCRIPTOR *ed = (WDU_ENDPOINT_DESCRIPTOR*)(buf+len);
f95f1d2e 142
143 ed->bLength = interface->altsetting[k].endpoint[l].bLength;
144 ed->bDescriptorType = interface->altsetting[k].endpoint[l].bDescriptorType;
145 ed->bEndpointAddress = interface->altsetting[k].endpoint[l].bEndpointAddress;
146 ed->bmAttributes = interface->altsetting[k].endpoint[l].bmAttributes;
147 ed->wMaxPacketSize = interface->altsetting[k].endpoint[l].wMaxPacketSize;
148 ed->bInterval = interface->altsetting[k].endpoint[l].bInterval;
149
150 len += sizeof(WDU_ENDPOINT_DESCRIPTOR);
792bf5f2 151 }
f95f1d2e 152
792bf5f2 153 for (l = 0; l < bNumEndpoints; l++) {
154 WDU_PIPE_INFO *pi = (WDU_PIPE_INFO*)(buf+len);
f95f1d2e 155
156 pi->dwNumber = interface->altsetting[k].endpoint[l].bEndpointAddress;
157 pi->dwMaximumPacketSize = WDU_GET_MAX_PACKET_SIZE(interface->altsetting[k].endpoint[l].wMaxPacketSize);
158 pi->type = interface->altsetting[k].endpoint[l].bmAttributes & USB_ENDPOINT_TYPE_MASK;
159 if (pi->type == PIPE_TYPE_CONTROL)
160 pi->direction = WDU_DIR_IN_OUT;
161 else
162 {
163 pi->direction = interface->altsetting[k].endpoint[l].bEndpointAddress & USB_ENDPOINT_DIR_MASK ? WDU_DIR_IN : WDU_DIR_OUT;
164 }
165
166 pi->dwInterval = interface->altsetting[k].endpoint[l].bInterval;
167
168 len += sizeof(WDU_PIPE_INFO);
169 }
170 } else {
171 len +=(sizeof(WDU_ENDPOINT_DESCRIPTOR)+sizeof(WDU_PIPE_INFO))*bNumEndpoints;
172 }
173 }
174 }
175 }
176
177 return len;
178}
179
9c9fd67c 180int do_wdioctl(int fd, unsigned int request, unsigned char *wdioctl) {
cdc711dc 181 struct header_struct* wdheader = (struct header_struct*)wdioctl;
9c9fd67c 182 struct version_struct *version;
183 int ret = 0;
cdc711dc 184
da3ba95a 185 if (wdheader->magic != MAGIC) {
2c2119eb 186 fprintf(stderr,"!!!ERROR: magic header does not match!!!\n");
187 return (*ioctl_func) (fd, request, wdioctl);
cdc711dc 188 }
189
cdc711dc 190 switch(request) {
da3ba95a 191 case VERSION:
9c9fd67c 192 version = (struct version_struct*)(wdheader->data);
193 strcpy(version->version, "WinDriver no more");
194 version->versionul = 999;
195 fprintf(stderr,"faking VERSION\n");
cdc711dc 196 break;
2c2119eb 197
198 case LICENSE:
199 fprintf(stderr,"faking LICENSE\n");
200 break;
201
9c9fd67c 202 case CARD_REGISTER:
203 {
2c2119eb 204 //struct card_register* cr = (struct card_register*)(wdheader->data);
9c9fd67c 205 /* Todo: LPT-Port already in use */
206 }
207 fprintf(stderr,"faking CARD_REGISTER\n");
da3ba95a 208 break;
2c2119eb 209
da3ba95a 210 case USB_TRANSFER:
9c9fd67c 211 fprintf(stderr,"in USB_TRANSFER");
da3ba95a 212 {
213 struct usb_transfer *ut = (struct usb_transfer*)(wdheader->data);
214
2c2119eb 215 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);
9c9fd67c 216 fprintf(stderr,"setup packet: ");
217 hexdump(ut->SetupPacket, 8);
218 fprintf(stderr,"\n");
219 if (!ut->fRead && ut->dwBufferSize)
220 {
221 hexdump(ut->pBuffer, ut->dwBufferSize);
222 fprintf(stderr,"\n");
223 }
224
795992ad 225#ifndef NO_WINDRVR
9c9fd67c 226 ret = (*ioctl_func) (fd, request, wdioctl);
292160ed 227#endif
9c9fd67c 228
2c2119eb 229 fprintf(stderr,"Transferred: %lu (%s)\n",ut->dwBytesTransferred, (ut->fRead?"read":"write"));
9c9fd67c 230 if (ut->fRead && ut->dwBytesTransferred)
231 {
232 fprintf(stderr,"Read: ");
233 hexdump(ut->pBuffer, ut->dwBytesTransferred);
234 }
da3ba95a 235 fprintf(stderr,"\n");
236 }
cdc711dc 237 break;
2c2119eb 238
da3ba95a 239 case INT_ENABLE:
9c9fd67c 240 fprintf(stderr,"faking INT_ENABLE");
da3ba95a 241 {
9c9fd67c 242 struct interrupt *it = (struct interrupt*)(wdheader->data);
cdc711dc 243
53f639f2 244 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);
cdc711dc 245
9c9fd67c 246 it->fEnableOk = 1;
247 //ret = (*ioctl_func) (fd, request, wdioctl);
248 }
cdc711dc 249
cdc711dc 250 break;
9c9fd67c 251
da3ba95a 252 case INT_DISABLE:
9c9fd67c 253 fprintf(stderr,"INT_DISABLE\n");
da3ba95a 254 {
9c9fd67c 255 struct interrupt *it = (struct interrupt*)(wdheader->data);
da3ba95a 256
53f639f2 257 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);
795992ad 258#ifndef NO_WINDRVR
9c9fd67c 259 ret = (*ioctl_func) (fd, request, wdioctl);
e71b6bf3 260#else
261 it->dwCounter = 0;
262 it->fStopped = 1;
292160ed 263#endif
53f639f2 264 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);
da3ba95a 265 }
da3ba95a 266 break;
da3ba95a 267
9c9fd67c 268 case USB_SET_INTERFACE:
269 fprintf(stderr,"USB_SET_INTERFACE\n");
da3ba95a 270 {
9c9fd67c 271 struct usb_set_interface *usi = (struct usb_set_interface*)(wdheader->data);
272
2c2119eb 273 fprintf(stderr,"unique: %lu, interfacenum: %lu, alternatesetting: %lu, options: %lx\n", usi->dwUniqueID, usi->dwInterfaceNum, usi->dwAlternateSetting, usi->dwOptions);
795992ad 274#ifndef NO_WINDRVR
9c9fd67c 275 ret = (*ioctl_func) (fd, request, wdioctl);
292160ed 276#endif
da3ba95a 277 }
cdc711dc 278 break;
da3ba95a 279
9c9fd67c 280 case USB_GET_DEVICE_DATA:
281 fprintf(stderr,"USB_GET_DEVICE_DATA\n");
282 {
283 struct usb_get_device_data *ugdd = (struct usb_get_device_data*)(wdheader->data);
284 int pSize;
285
e71b6bf3 286 fprintf(stderr, "unique: %lu, bytes: %lu, options: %lx\n", ugdd->dwUniqueID, ugdd->dwBytes, ugdd->dwOptions);
9c9fd67c 287 pSize = ugdd->dwBytes;
795992ad 288#ifndef NO_WINDRVR
9c9fd67c 289 ret = (*ioctl_func) (fd, request, wdioctl);
e71b6bf3 290#else
291 if (!ugdd->dwBytes) {
292 if (usb_cable) {
f95f1d2e 293 ugdd->dwBytes = usb_deviceinfo(NULL);
e71b6bf3 294 }
295 } else {
f95f1d2e 296 usb_deviceinfo((unsigned char*)ugdd->pBuf);
e71b6bf3 297 }
292160ed 298#endif
9c9fd67c 299 if (pSize) {
e71b6bf3 300 struct usb_device_info *udi = (struct usb_device_info*)ugdd->pBuf;
301
302 fprintf(stderr, "Vendor: %x\n", udi->Descriptor.idVendor);
303
9c9fd67c 304 hexdump(ugdd->pBuf, pSize);
305 fprintf(stderr, "\n");
da3ba95a 306 }
307 }
9c9fd67c 308 break;
309
b0f621dd 310 case EVENT_REGISTER:
311 fprintf(stderr,"EVENT_REGISTER\n");
312 {
313 struct event *e = (struct event*)(wdheader->data);
ac22d975 314 struct usb_bus *bus;
b0f621dd 315 int i;
316
317 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);
ac22d975 318 for (i = 0; i < e->dwNumMatchTables; i++) {
e71b6bf3 319 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);
b0f621dd 320
ac22d975 321 for (bus = busses; bus; bus = bus->next) {
322 struct usb_device *dev;
323
324 for (dev = bus->devices; dev; dev = dev->next) {
325 struct usb_device_descriptor *desc = &(dev->descriptor);
326
327 if((desc->idVendor == e->matchTables[i].VendorId) &&
328 (desc->idProduct == e->matchTables[i].ProductId) &&
329 (desc->bDeviceClass == e->matchTables[i].bDeviceClass) &&
330 (desc->bDeviceSubClass == e->matchTables[i].bDeviceSubClass)) {
331 struct usb_interface *interface = dev->config->interface;
332 int ai;
333
334 for (ai = 0; ai < interface->num_altsetting; ai++) {
335 fprintf(stderr, "intclass: %x, intsubclass: %x, intproto: %x\n", interface->altsetting[i].bInterfaceClass, interface->altsetting[i].bInterfaceSubClass, interface->altsetting[i].bInterfaceProtocol);
336 if ((interface->altsetting[i].bInterfaceSubClass == e->matchTables[i].bInterfaceSubClass) &&
337 (interface->altsetting[i].bInterfaceProtocol == e->matchTables[i].bInterfaceProtocol)){
338 /* TODO: check interfaceClass! */
339 fprintf(stderr,"!!!FOUND DEVICE WITH LIBUSB!!!\n");
340 usb_cable = dev;
292160ed 341 card_type = e->dwCardType;
ac22d975 342 }
343 }
344 }
345 }
346 }
347 }
348
795992ad 349#ifndef NO_WINDRVR
b0f621dd 350 ret = (*ioctl_func) (fd, request, wdioctl);
292160ed 351#endif
b0f621dd 352
353 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);
354 for (i = 0; i < e->dwNumMatchTables; i++)
e71b6bf3 355 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);
b0f621dd 356 }
357 break;
358
da3ba95a 359 case TRANSFER:
9c9fd67c 360 fprintf(stderr,"TRANSFER\n");
795992ad 361#ifndef NO_WINDRVR
9c9fd67c 362 ret = (*ioctl_func) (fd, request, wdioctl);
292160ed 363#endif
9c9fd67c 364 break;
365
da3ba95a 366 case EVENT_UNREGISTER:
9c9fd67c 367 fprintf(stderr,"EVENT_UNREGISTER\n");
795992ad 368#ifndef NO_WINDRVR
9c9fd67c 369 ret = (*ioctl_func) (fd, request, wdioctl);
292160ed 370#endif
9c9fd67c 371 break;
372
da3ba95a 373 case INT_WAIT:
9c9fd67c 374 fprintf(stderr,"INT_WAIT\n");
b0f621dd 375 {
376 struct interrupt *it = (struct interrupt*)(wdheader->data);
377
53f639f2 378 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);
b0f621dd 379
795992ad 380#ifndef NO_WINDRVR
b0f621dd 381 ret = (*ioctl_func) (fd, request, wdioctl);
292160ed 382#else
383 if (usb_cable)
384 it->dwCounter++;
385#endif
386
53f639f2 387 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);
b0f621dd 388 }
9c9fd67c 389 break;
390
da3ba95a 391 case CARD_UNREGISTER:
9c9fd67c 392 fprintf(stderr,"CARD_UNREGISTER\n");
795992ad 393#ifndef NO_WINDRVR
9c9fd67c 394 ret = (*ioctl_func) (fd, request, wdioctl);
292160ed 395#endif
9c9fd67c 396 break;
397
da3ba95a 398 case EVENT_PULL:
9c9fd67c 399 fprintf(stderr,"EVENT_PULL\n");
b1831983 400 {
401 struct event *e = (struct event*)(wdheader->data);
402 int i;
403
404 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);
405 for (i = 0; i < e->dwNumMatchTables; i++)
e71b6bf3 406 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);
b1831983 407
795992ad 408#ifndef NO_WINDRVR
b1831983 409 ret = (*ioctl_func) (fd, request, wdioctl);
292160ed 410#else
411//EVENT_PULL
412//handle: 1, action: 0, status: 0, eventid: 0, cardtype: 0, kplug: 0, options: 0, dev: 0:0, unique: 0, ver: 1, nummatch: 1
413//match: dev: 0:0, class: 0, subclass: 0, intclass: 0, intsubclass: 0, intproto: 0
414//handle: 1, action: 1, status: 0, eventid: 109, cardtype: 4294967294, kplug: 0, options: 0, dev: 0:0, unique: 90, ver: 1, nummatch: 1
415//match: dev: 3fd:8, class: 0, subclass: 0, intclass: ff, intsubclass: 0, intproto: 0
416 if (usb_cable) {
417 struct usb_interface *interface = usb_cable->config->interface;
418
419 e->dwCardType = card_type;
420 e->dwAction = 1;
421 e->dwEventId = 109;
422 e->u.Usb.dwUniqueID = 4711;
423 e->matchTables[0].VendorId = usb_cable->descriptor.idVendor;
424 e->matchTables[0].ProductId = usb_cable->descriptor.idProduct;
425 e->matchTables[0].bDeviceClass = usb_cable->descriptor.bDeviceClass;
426 e->matchTables[0].bDeviceSubClass = usb_cable->descriptor.bDeviceSubClass;
427 e->matchTables[0].bInterfaceClass = interface->altsetting[0].bInterfaceClass;
428 e->matchTables[0].bInterfaceSubClass = interface->altsetting[0].bInterfaceSubClass;
429 e->matchTables[0].bInterfaceProtocol = interface->altsetting[0].bInterfaceProtocol;
430 }
431#endif
b1831983 432
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++)
e71b6bf3 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);
b1831983 436 }
9c9fd67c 437 break;
438
da3ba95a 439 default:
292160ed 440 fprintf(stderr,"!!!Unsupported IOCTL: %x!!!\n", request);
795992ad 441#ifndef NO_WINDRVR
9c9fd67c 442 ret = (*ioctl_func) (fd, request, wdioctl);
292160ed 443#endif
444 break;
cdc711dc 445 }
da3ba95a 446
9c9fd67c 447 return ret;
cdc711dc 448}
449
450
451typedef int (*open_funcptr_t) (const char *, int, mode_t);
452
cdc711dc 453int open (const char *pathname, int flags, ...)
454{
455 static open_funcptr_t func = NULL;
456 mode_t mode = 0;
457 va_list args;
458 int fd;
459
460 if (!func)
461 func = (open_funcptr_t) dlsym (REAL_LIBC, "open");
462
463 if (flags & O_CREAT) {
464 va_start(args, flags);
465 mode = va_arg(args, mode_t);
466 va_end(args);
467 }
468
cdc711dc 469 if (!strcmp (pathname, "/dev/windrvr6")) {
470 fprintf(stderr,"opening windrvr6\n");
795992ad 471#ifdef NO_WINDRVR
01b99d52 472 windrvrfd = fd = (*func) ("/dev/null", flags, mode);
473#else
474 windrvrfd = fd = (*func) (pathname, flags, mode);
475#endif
f10480d1 476 if (!busses) {
477 usb_init();
478 usb_find_busses();
479 usb_find_devices();
480
481 busses = usb_get_busses();
482 }
01b99d52 483 } else {
484 fd = (*func) (pathname, flags, mode);
cdc711dc 485 }
486
487 return fd;
488}
489
490void diff(unsigned char *buf1, unsigned char *buf2, int len) {
491 int i;
492
493 for(i=0; i<len; i++) {
494 if (buf1[i] != buf2[i]) {
495 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]:'.'));
496 }
497 }
498}
499
500void hexdump(unsigned char *buf, int len) {
501 int i;
502
503 for(i=0; i<len; i++) {
504 fprintf(stderr,"%02x ", buf[i]);
505 if ((i % 16) == 15)
506 fprintf(stderr,"\n");
507 }
508}
509
510int ioctl(int fd, int request, ...)
511{
cdc711dc 512 va_list args;
513 void *argp;
cdc711dc 514 int ret;
515
9c9fd67c 516 if (!ioctl_func)
517 ioctl_func = (int (*) (int, int, void *)) dlsym (REAL_LIBC, "ioctl");
cdc711dc 518
519 va_start (args, request);
520 argp = va_arg (args, void *);
521 va_end (args);
522
9c9fd67c 523 if (fd == windrvrfd)
524 ret = do_wdioctl(fd, request, argp);
525 else
526 ret = (*ioctl_func) (fd, request, argp);
cdc711dc 527
cdc711dc 528 return ret;
529}
530
da3ba95a 531#if 0
cdc711dc 532void *mmap(void *start, size_t length, int prot, int flags, int fd, off_t offset)
533{
534 static void* (*func) (void *, size_t, int, int, int, off_t) = NULL;
535 void *ret;
536
537 if (!func)
538 func = (void* (*) (void *, size_t, int, int, int, off_t)) dlsym (REAL_LIBC, "mmap");
539
540 ret = (*func) (start, length, prot, flags, fd, offset);
541 fprintf(stderr,"MMAP: %x, %d, %d, %d, %d, %d -> %x\n", (unsigned int)start, length, prot, flags, fd, offset, (unsigned int)ret);
542 mmapped = ret;
543 mmapplen = length;
544
545 return ret;
546}
547
548void *mmap64(void *start, size_t length, int prot, int flags, int fd, off64_t offset)
549{
550 static void* (*func) (void *, size_t, int, int, int, off64_t) = NULL;
551 void *ret;
552
553 if (!func)
554 func = (void* (*) (void *, size_t, int, int, int, off64_t)) dlsym (REAL_LIBC, "mmap64");
555
556 ret = (*func) (start, length, prot, flags, fd, offset);
557 fprintf(stderr,"MMAP64: %x, %d, %d, %d, %d, %lld -> %x\n", (unsigned int)start, length, prot, flags, fd, offset, (unsigned int)ret);
558 mmapped = ret;
559 mmapplen = length;
560
561 return ret;
562}
563
564void *mmap2(void *start, size_t length, int prot, int flags, int fd, off_t pgoffset)
565{
566 static void* (*func) (void *, size_t, int, int, int, off_t) = NULL;
567 void *ret;
568
569 if (!func)
570 func = (void* (*) (void *, size_t, int, int, int, off_t)) dlsym (REAL_LIBC, "mmap2");
571
572 ret = (*func) (start, length, prot, flags, fd, pgoffset);
573 fprintf(stderr,"MMAP2: %x, %d, %d, %d, %d, %d -> %x\n", (unsigned int)start, length, prot, flags, fd, pgoffset, (unsigned int)ret);
574 mmapped = ret;
575 mmapplen = length;
576
577 return ret;
578}
579
580void *malloc(size_t size)
581{
582 static void* (*func) (size_t) = NULL;
583 void *ret;
584
585 if (!func)
586 func = (void* (*) (size_t)) dlsym(REAL_LIBC, "malloc");
587
588 ret = (*func) (size);
589
590 //fprintf(stderr,"MALLOC: %d -> %x\n", size, (unsigned int) ret);
591
592 return ret;
593}
da3ba95a 594#endif
cdc711dc 595
596
597#endif
Impressum, Datenschutz