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