]>
Commit | Line | Data |
---|---|---|
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 | 24 | static int (*ioctl_func) (int, int, void *) = NULL; |
2c2119eb | 25 | static int windrvrfd = 0; |
f10480d1 | 26 | static struct usb_bus *busses = NULL; |
ac22d975 | 27 | static struct usb_device *usb_cable; |
292160ed | 28 | static unsigned long card_type; |
29 | ||
e71b6bf3 | 30 | //#define USE_LIBUSB 1 |
cdc711dc | 31 | |
32 | void hexdump(unsigned char *buf, int len); | |
da3ba95a | 33 | void diff(unsigned char *buf1, unsigned char *buf2, int len); |
cdc711dc | 34 | |
9c9fd67c | 35 | int 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 | ||
292160ed | 80 | #ifndef USE_LIBUSB |
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); |
292160ed | 113 | #ifndef USE_LIBUSB |
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); |
292160ed | 129 | #ifndef USE_LIBUSB |
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 | } | |
292160ed | 146 | #ifndef USE_LIBUSB |
9c9fd67c | 147 | ret = (*ioctl_func) (fd, request, wdioctl); |
e71b6bf3 | 148 | #else |
149 | if (!ugdd->dwBytes) { | |
150 | if (usb_cable) { | |
151 | ugdd->dwBytes = sizeof(struct usb_device_info) - 8 + (sizeof(WDU_CONFIGURATION)*2) + sizeof(WDU_INTERFACE) * 6; | |
152 | /* TODO: Fixme */ | |
153 | ugdd->dwBytes = 276; | |
154 | } | |
155 | } else { | |
156 | struct usb_device_info *udi = (struct usb_device_info*)ugdd->pBuf; | |
01b99d52 | 157 | struct usb_endpoint_descriptor *ep; |
e71b6bf3 | 158 | unsigned char dings[] = {0x12, 0x01, 0x00, 0x02, 0x00, 0x00, 0x00, 0x40, 0xfd, 0x03, 0x08, 0x00, 0x00, 0x00, 0x01, 0x02, |
159 | 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | |
160 | 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x45, 0x21, 0x08, 0x38, 0x45, 0x21, 0x08, | |
161 | 0x4c, 0x45, 0x21, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | |
162 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | |
163 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | |
164 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | |
165 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | |
166 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | |
167 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | |
168 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x02, 0x20, 0x00, 0x01, 0x02, 0x00, 0x80, | |
169 | 0x8c, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x4c, 0x45, 0x21, 0x08, 0x58, 0x45, 0x21, 0x08, | |
170 | 0x01, 0x00, 0x00, 0x00, 0x58, 0x45, 0x21, 0x08, 0x09, 0x04, 0x00, 0x00, 0x02, 0xff, 0x00, 0x00, | |
171 | 0x00, 0x00, 0x00, 0x00, 0x6c, 0x45, 0x21, 0x08, 0x7c, 0x45, 0x21, 0x08, 0x07, 0x05, 0x02, 0x02, | |
172 | 0x00, 0x02, 0x00, 0x00, 0x07, 0x05, 0x86, 0x02, 0x00, 0x02, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, | |
173 | 0x00, 0x02, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | |
174 | 0x86, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, | |
175 | 0x00, 0x00, 0x00, 0x00}; | |
176 | ||
177 | //unique: 94, bytes: 276, options: 0 | |
178 | //Vendor: 3fd | |
179 | //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 | |
180 | //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 | |
181 | //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 | |
182 | //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 | |
183 | //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 | |
184 | //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 | |
185 | //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 | |
186 | //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 | |
187 | //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 | |
188 | //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 | |
189 | //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 | |
190 | //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 | |
191 | //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 | |
192 | //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 | |
193 | //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 | |
194 | //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 | |
195 | //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 | |
196 | //00 00 00 00 00 00 00 00 | |
197 | ||
198 | bzero(udi, ugdd->dwBytes); | |
199 | //memcpy(udi, dings, 276); | |
200 | udi->Descriptor.bLength = sizeof(WDU_DEVICE_DESCRIPTOR); | |
201 | udi->Descriptor.bDescriptorType = usb_cable->descriptor.bDescriptorType; | |
202 | udi->Descriptor.bcdUSB = usb_cable->descriptor.bcdUSB; | |
203 | udi->Descriptor.bDeviceClass = usb_cable->descriptor.bDeviceClass; | |
204 | udi->Descriptor.bDeviceSubClass = usb_cable->descriptor.bDeviceSubClass; | |
205 | udi->Descriptor.bDeviceProtocol = usb_cable->descriptor.bDeviceProtocol; | |
206 | udi->Descriptor.bMaxPacketSize0 = usb_cable->descriptor.bMaxPacketSize0; | |
207 | udi->Descriptor.idVendor = usb_cable->descriptor.idVendor; | |
208 | udi->Descriptor.idProduct = usb_cable->descriptor.idProduct; | |
209 | udi->Descriptor.bcdDevice = usb_cable->descriptor.bcdDevice; | |
210 | udi->Descriptor.iManufacturer = usb_cable->descriptor.iManufacturer; | |
211 | udi->Descriptor.iProduct = usb_cable->descriptor.iProduct; | |
212 | udi->Descriptor.iSerialNumber = usb_cable->descriptor.iSerialNumber; | |
213 | udi->Descriptor.bNumConfigurations = usb_cable->descriptor.bNumConfigurations; | |
01b99d52 | 214 | |
215 | ep = usb_cable->config->interface->altsetting[0].endpoint; | |
216 | ||
217 | udi->Pipe0.dwNumber = 0x00; | |
218 | udi->Pipe0.dwMaximumPacketSize = usb_cable->descriptor.bMaxPacketSize0; | |
219 | udi->Pipe0.type = 0; | |
220 | udi->Pipe0.direction = 3; | |
221 | udi->Pipe0.dwInterval = 0; | |
222 | // ab offset 168 config desc | |
e71b6bf3 | 223 | } |
292160ed | 224 | #endif |
9c9fd67c | 225 | if (pSize) { |
e71b6bf3 | 226 | struct usb_device_info *udi = (struct usb_device_info*)ugdd->pBuf; |
227 | ||
228 | fprintf(stderr, "Vendor: %x\n", udi->Descriptor.idVendor); | |
229 | ||
9c9fd67c | 230 | hexdump(ugdd->pBuf, pSize); |
231 | fprintf(stderr, "\n"); | |
da3ba95a | 232 | } |
233 | } | |
9c9fd67c | 234 | break; |
235 | ||
b0f621dd | 236 | case EVENT_REGISTER: |
237 | fprintf(stderr,"EVENT_REGISTER\n"); | |
238 | { | |
239 | struct event *e = (struct event*)(wdheader->data); | |
ac22d975 | 240 | struct usb_bus *bus; |
b0f621dd | 241 | int i; |
242 | ||
243 | 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 | 244 | for (i = 0; i < e->dwNumMatchTables; i++) { |
e71b6bf3 | 245 | 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 | 246 | |
ac22d975 | 247 | for (bus = busses; bus; bus = bus->next) { |
248 | struct usb_device *dev; | |
249 | ||
250 | for (dev = bus->devices; dev; dev = dev->next) { | |
251 | struct usb_device_descriptor *desc = &(dev->descriptor); | |
252 | ||
253 | if((desc->idVendor == e->matchTables[i].VendorId) && | |
254 | (desc->idProduct == e->matchTables[i].ProductId) && | |
255 | (desc->bDeviceClass == e->matchTables[i].bDeviceClass) && | |
256 | (desc->bDeviceSubClass == e->matchTables[i].bDeviceSubClass)) { | |
257 | struct usb_interface *interface = dev->config->interface; | |
258 | int ai; | |
259 | ||
260 | for (ai = 0; ai < interface->num_altsetting; ai++) { | |
261 | fprintf(stderr, "intclass: %x, intsubclass: %x, intproto: %x\n", interface->altsetting[i].bInterfaceClass, interface->altsetting[i].bInterfaceSubClass, interface->altsetting[i].bInterfaceProtocol); | |
262 | if ((interface->altsetting[i].bInterfaceSubClass == e->matchTables[i].bInterfaceSubClass) && | |
263 | (interface->altsetting[i].bInterfaceProtocol == e->matchTables[i].bInterfaceProtocol)){ | |
264 | /* TODO: check interfaceClass! */ | |
265 | fprintf(stderr,"!!!FOUND DEVICE WITH LIBUSB!!!\n"); | |
266 | usb_cable = dev; | |
292160ed | 267 | card_type = e->dwCardType; |
ac22d975 | 268 | } |
269 | } | |
270 | } | |
271 | } | |
272 | } | |
273 | } | |
274 | ||
292160ed | 275 | #ifndef USE_LIBUSB |
b0f621dd | 276 | ret = (*ioctl_func) (fd, request, wdioctl); |
292160ed | 277 | #endif |
b0f621dd | 278 | |
279 | 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); | |
280 | for (i = 0; i < e->dwNumMatchTables; i++) | |
e71b6bf3 | 281 | 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 | 282 | } |
283 | break; | |
284 | ||
da3ba95a | 285 | case TRANSFER: |
9c9fd67c | 286 | fprintf(stderr,"TRANSFER\n"); |
292160ed | 287 | #ifndef USE_LIBUSB |
9c9fd67c | 288 | ret = (*ioctl_func) (fd, request, wdioctl); |
292160ed | 289 | #endif |
9c9fd67c | 290 | break; |
291 | ||
da3ba95a | 292 | case EVENT_UNREGISTER: |
9c9fd67c | 293 | fprintf(stderr,"EVENT_UNREGISTER\n"); |
292160ed | 294 | #ifndef USE_LIBUSB |
9c9fd67c | 295 | ret = (*ioctl_func) (fd, request, wdioctl); |
292160ed | 296 | #endif |
9c9fd67c | 297 | break; |
298 | ||
da3ba95a | 299 | case INT_WAIT: |
9c9fd67c | 300 | fprintf(stderr,"INT_WAIT\n"); |
b0f621dd | 301 | { |
302 | struct interrupt *it = (struct interrupt*)(wdheader->data); | |
303 | ||
53f639f2 | 304 | 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 | 305 | |
292160ed | 306 | #ifndef USE_LIBUSB |
b0f621dd | 307 | ret = (*ioctl_func) (fd, request, wdioctl); |
292160ed | 308 | #else |
309 | if (usb_cable) | |
310 | it->dwCounter++; | |
311 | #endif | |
312 | ||
53f639f2 | 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); |
b0f621dd | 314 | } |
9c9fd67c | 315 | break; |
316 | ||
da3ba95a | 317 | case CARD_UNREGISTER: |
9c9fd67c | 318 | fprintf(stderr,"CARD_UNREGISTER\n"); |
292160ed | 319 | #ifndef USE_LIBUSB |
9c9fd67c | 320 | ret = (*ioctl_func) (fd, request, wdioctl); |
292160ed | 321 | #endif |
9c9fd67c | 322 | break; |
323 | ||
da3ba95a | 324 | case EVENT_PULL: |
9c9fd67c | 325 | fprintf(stderr,"EVENT_PULL\n"); |
b1831983 | 326 | { |
327 | struct event *e = (struct event*)(wdheader->data); | |
328 | int i; | |
329 | ||
330 | 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); | |
331 | for (i = 0; i < e->dwNumMatchTables; i++) | |
e71b6bf3 | 332 | 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 | 333 | |
292160ed | 334 | #ifndef USE_LIBUSB |
b1831983 | 335 | ret = (*ioctl_func) (fd, request, wdioctl); |
292160ed | 336 | #else |
337 | //EVENT_PULL | |
338 | //handle: 1, action: 0, status: 0, eventid: 0, cardtype: 0, kplug: 0, options: 0, dev: 0:0, unique: 0, ver: 1, nummatch: 1 | |
339 | //match: dev: 0:0, class: 0, subclass: 0, intclass: 0, intsubclass: 0, intproto: 0 | |
340 | //handle: 1, action: 1, status: 0, eventid: 109, cardtype: 4294967294, kplug: 0, options: 0, dev: 0:0, unique: 90, ver: 1, nummatch: 1 | |
341 | //match: dev: 3fd:8, class: 0, subclass: 0, intclass: ff, intsubclass: 0, intproto: 0 | |
342 | if (usb_cable) { | |
343 | struct usb_interface *interface = usb_cable->config->interface; | |
344 | ||
345 | e->dwCardType = card_type; | |
346 | e->dwAction = 1; | |
347 | e->dwEventId = 109; | |
348 | e->u.Usb.dwUniqueID = 4711; | |
349 | e->matchTables[0].VendorId = usb_cable->descriptor.idVendor; | |
350 | e->matchTables[0].ProductId = usb_cable->descriptor.idProduct; | |
351 | e->matchTables[0].bDeviceClass = usb_cable->descriptor.bDeviceClass; | |
352 | e->matchTables[0].bDeviceSubClass = usb_cable->descriptor.bDeviceSubClass; | |
353 | e->matchTables[0].bInterfaceClass = interface->altsetting[0].bInterfaceClass; | |
354 | e->matchTables[0].bInterfaceSubClass = interface->altsetting[0].bInterfaceSubClass; | |
355 | e->matchTables[0].bInterfaceProtocol = interface->altsetting[0].bInterfaceProtocol; | |
356 | } | |
357 | #endif | |
b1831983 | 358 | |
359 | 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); | |
360 | for (i = 0; i < e->dwNumMatchTables; i++) | |
e71b6bf3 | 361 | 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 | 362 | } |
9c9fd67c | 363 | break; |
364 | ||
da3ba95a | 365 | default: |
292160ed | 366 | fprintf(stderr,"!!!Unsupported IOCTL: %x!!!\n", request); |
367 | #ifndef USE_LIBUSB | |
9c9fd67c | 368 | ret = (*ioctl_func) (fd, request, wdioctl); |
292160ed | 369 | #endif |
370 | break; | |
cdc711dc | 371 | } |
da3ba95a | 372 | |
9c9fd67c | 373 | return ret; |
cdc711dc | 374 | } |
375 | ||
376 | ||
377 | typedef int (*open_funcptr_t) (const char *, int, mode_t); | |
378 | ||
cdc711dc | 379 | int open (const char *pathname, int flags, ...) |
380 | { | |
381 | static open_funcptr_t func = NULL; | |
382 | mode_t mode = 0; | |
383 | va_list args; | |
384 | int fd; | |
385 | ||
386 | if (!func) | |
387 | func = (open_funcptr_t) dlsym (REAL_LIBC, "open"); | |
388 | ||
389 | if (flags & O_CREAT) { | |
390 | va_start(args, flags); | |
391 | mode = va_arg(args, mode_t); | |
392 | va_end(args); | |
393 | } | |
394 | ||
cdc711dc | 395 | if (!strcmp (pathname, "/dev/windrvr6")) { |
396 | fprintf(stderr,"opening windrvr6\n"); | |
01b99d52 | 397 | #ifdef USE_LIBUSB |
398 | windrvrfd = fd = (*func) ("/dev/null", flags, mode); | |
399 | #else | |
400 | windrvrfd = fd = (*func) (pathname, flags, mode); | |
401 | #endif | |
f10480d1 | 402 | if (!busses) { |
403 | usb_init(); | |
404 | usb_find_busses(); | |
405 | usb_find_devices(); | |
406 | ||
407 | busses = usb_get_busses(); | |
408 | } | |
01b99d52 | 409 | } else { |
410 | fd = (*func) (pathname, flags, mode); | |
cdc711dc | 411 | } |
412 | ||
413 | return fd; | |
414 | } | |
415 | ||
416 | void diff(unsigned char *buf1, unsigned char *buf2, int len) { | |
417 | int i; | |
418 | ||
419 | for(i=0; i<len; i++) { | |
420 | if (buf1[i] != buf2[i]) { | |
421 | 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]:'.')); | |
422 | } | |
423 | } | |
424 | } | |
425 | ||
426 | void hexdump(unsigned char *buf, int len) { | |
427 | int i; | |
428 | ||
429 | for(i=0; i<len; i++) { | |
430 | fprintf(stderr,"%02x ", buf[i]); | |
431 | if ((i % 16) == 15) | |
432 | fprintf(stderr,"\n"); | |
433 | } | |
434 | } | |
435 | ||
436 | int ioctl(int fd, int request, ...) | |
437 | { | |
cdc711dc | 438 | va_list args; |
439 | void *argp; | |
cdc711dc | 440 | int ret; |
441 | ||
9c9fd67c | 442 | if (!ioctl_func) |
443 | ioctl_func = (int (*) (int, int, void *)) dlsym (REAL_LIBC, "ioctl"); | |
cdc711dc | 444 | |
445 | va_start (args, request); | |
446 | argp = va_arg (args, void *); | |
447 | va_end (args); | |
448 | ||
9c9fd67c | 449 | if (fd == windrvrfd) |
450 | ret = do_wdioctl(fd, request, argp); | |
451 | else | |
452 | ret = (*ioctl_func) (fd, request, argp); | |
cdc711dc | 453 | |
cdc711dc | 454 | return ret; |
455 | } | |
456 | ||
da3ba95a | 457 | #if 0 |
cdc711dc | 458 | void *mmap(void *start, size_t length, int prot, int flags, int fd, off_t offset) |
459 | { | |
460 | static void* (*func) (void *, size_t, int, int, int, off_t) = NULL; | |
461 | void *ret; | |
462 | ||
463 | if (!func) | |
464 | func = (void* (*) (void *, size_t, int, int, int, off_t)) dlsym (REAL_LIBC, "mmap"); | |
465 | ||
466 | ret = (*func) (start, length, prot, flags, fd, offset); | |
467 | fprintf(stderr,"MMAP: %x, %d, %d, %d, %d, %d -> %x\n", (unsigned int)start, length, prot, flags, fd, offset, (unsigned int)ret); | |
468 | mmapped = ret; | |
469 | mmapplen = length; | |
470 | ||
471 | return ret; | |
472 | } | |
473 | ||
474 | void *mmap64(void *start, size_t length, int prot, int flags, int fd, off64_t offset) | |
475 | { | |
476 | static void* (*func) (void *, size_t, int, int, int, off64_t) = NULL; | |
477 | void *ret; | |
478 | ||
479 | if (!func) | |
480 | func = (void* (*) (void *, size_t, int, int, int, off64_t)) dlsym (REAL_LIBC, "mmap64"); | |
481 | ||
482 | ret = (*func) (start, length, prot, flags, fd, offset); | |
483 | fprintf(stderr,"MMAP64: %x, %d, %d, %d, %d, %lld -> %x\n", (unsigned int)start, length, prot, flags, fd, offset, (unsigned int)ret); | |
484 | mmapped = ret; | |
485 | mmapplen = length; | |
486 | ||
487 | return ret; | |
488 | } | |
489 | ||
490 | void *mmap2(void *start, size_t length, int prot, int flags, int fd, off_t pgoffset) | |
491 | { | |
492 | static void* (*func) (void *, size_t, int, int, int, off_t) = NULL; | |
493 | void *ret; | |
494 | ||
495 | if (!func) | |
496 | func = (void* (*) (void *, size_t, int, int, int, off_t)) dlsym (REAL_LIBC, "mmap2"); | |
497 | ||
498 | ret = (*func) (start, length, prot, flags, fd, pgoffset); | |
499 | fprintf(stderr,"MMAP2: %x, %d, %d, %d, %d, %d -> %x\n", (unsigned int)start, length, prot, flags, fd, pgoffset, (unsigned int)ret); | |
500 | mmapped = ret; | |
501 | mmapplen = length; | |
502 | ||
503 | return ret; | |
504 | } | |
505 | ||
506 | void *malloc(size_t size) | |
507 | { | |
508 | static void* (*func) (size_t) = NULL; | |
509 | void *ret; | |
510 | ||
511 | if (!func) | |
512 | func = (void* (*) (size_t)) dlsym(REAL_LIBC, "malloc"); | |
513 | ||
514 | ret = (*func) (size); | |
515 | ||
516 | //fprintf(stderr,"MALLOC: %d -> %x\n", size, (unsigned int) ret); | |
517 | ||
518 | return ret; | |
519 | } | |
da3ba95a | 520 | #endif |
cdc711dc | 521 | |
522 | ||
523 | #endif |