]>
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> |
2a7af812 | 22 | #include <signal.h> |
da3ba95a | 23 | #include "xilinx.h" |
cdc711dc | 24 | |
9c9fd67c | 25 | static int (*ioctl_func) (int, int, void *) = NULL; |
2c2119eb | 26 | static int windrvrfd = 0; |
f10480d1 | 27 | static struct usb_bus *busses = NULL; |
2a7af812 | 28 | static struct usb_device *usbdevice; |
29 | static usb_dev_handle *usb_devhandle = NULL; | |
292160ed | 30 | static unsigned long card_type; |
ca18111b | 31 | static int ints_enabled = 0; |
292160ed | 32 | |
795992ad | 33 | #define NO_WINDRVR 1 |
cdc711dc | 34 | |
35 | void hexdump(unsigned char *buf, int len); | |
da3ba95a | 36 | void diff(unsigned char *buf1, unsigned char *buf2, int len); |
cdc711dc | 37 | |
792bf5f2 | 38 | //unique: 94, bytes: 276, options: 0 |
39 | //Vendor: 3fd | |
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 | |
3664a3e3 | 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 | |
792bf5f2 | 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 | |
3664a3e3 | 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 | |
792bf5f2 | 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 | |
f95f1d2e | 58 | int usb_deviceinfo(unsigned char *buf) { |
59 | int i,j,k,l; | |
60 | int len = 0; | |
3664a3e3 | 61 | WDU_CONFIGURATION **pConfigs, **pActiveConfig; |
62 | WDU_INTERFACE **pActiveInterface; | |
f95f1d2e | 63 | |
64 | if (buf) { | |
65 | struct usb_device_info *udi = (struct usb_device_info*)(buf+len); | |
66 | ||
67 | udi->Descriptor.bLength = sizeof(WDU_DEVICE_DESCRIPTOR); | |
2a7af812 | 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; | |
f95f1d2e | 81 | |
82 | /* TODO: Fix Pipe0! */ | |
83 | udi->Pipe0.dwNumber = 0x00; | |
2a7af812 | 84 | udi->Pipe0.dwMaximumPacketSize = usbdevice->descriptor.bMaxPacketSize0; |
f95f1d2e | 85 | udi->Pipe0.type = 0; |
86 | udi->Pipe0.direction = 3; | |
87 | udi->Pipe0.dwInterval = 0; | |
3664a3e3 | 88 | |
89 | pConfigs = &(udi->pConfigs); | |
90 | pActiveConfig = &(udi->pActiveConfig); | |
91 | pActiveInterface = &(udi->pActiveInterface[0]); | |
f95f1d2e | 92 | } |
93 | ||
94 | len = sizeof(struct usb_device_info); | |
95 | ||
2a7af812 | 96 | for (i=0; i<usbdevice->descriptor.bNumConfigurations; i++) |
f95f1d2e | 97 | { |
2a7af812 | 98 | struct usb_config_descriptor *conf_desc = &usbdevice->config[i]; |
3664a3e3 | 99 | WDU_INTERFACE **pInterfaces; |
100 | WDU_ALTERNATE_SETTING **pAlternateSettings[conf_desc->bNumInterfaces]; | |
101 | WDU_ALTERNATE_SETTING **pActiveAltSetting[conf_desc->bNumInterfaces]; | |
102 | ||
f95f1d2e | 103 | if (buf) { |
104 | WDU_CONFIGURATION *cfg = (WDU_CONFIGURATION*)(buf+len); | |
105 | ||
3664a3e3 | 106 | *pConfigs = cfg; |
107 | *pActiveConfig = cfg; | |
108 | ||
f95f1d2e | 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; | |
117 | ||
118 | cfg->dwNumInterfaces = conf_desc->bNumInterfaces; | |
3664a3e3 | 119 | |
120 | pInterfaces = &(cfg->pInterfaces); | |
f95f1d2e | 121 | } |
122 | len += sizeof(WDU_CONFIGURATION); | |
3664a3e3 | 123 | |
f95f1d2e | 124 | if (buf) { |
3664a3e3 | 125 | *pInterfaces = (WDU_INTERFACE*)(buf+len); |
f95f1d2e | 126 | for (j=0; j<conf_desc->bNumInterfaces; j++) { |
127 | WDU_INTERFACE *iface = (WDU_INTERFACE*)(buf+len); | |
3664a3e3 | 128 | |
129 | pActiveInterface[j] = iface; | |
130 | ||
131 | pAlternateSettings[j] = &(iface->pAlternateSettings); | |
2a7af812 | 132 | iface->dwNumAltSettings = usbdevice->config[i].interface[j].num_altsetting; |
3664a3e3 | 133 | pActiveAltSetting[j] = &(iface->pActiveAltSetting); |
f95f1d2e | 134 | |
135 | len += sizeof(WDU_INTERFACE); | |
136 | } | |
137 | } else { | |
138 | len += sizeof(WDU_INTERFACE) * conf_desc->bNumInterfaces; | |
139 | } | |
140 | ||
141 | for (j=0; j<conf_desc->bNumInterfaces; j++) | |
142 | { | |
2a7af812 | 143 | struct usb_interface *interface = &usbdevice->config[i].interface[j]; |
3664a3e3 | 144 | |
145 | if (buf) { | |
146 | *pAlternateSettings[j] = (WDU_ALTERNATE_SETTING*)(buf+len); | |
147 | /* FIXME: */ | |
148 | *pActiveAltSetting[j] = (WDU_ALTERNATE_SETTING*)(buf+len); | |
149 | } | |
150 | ||
f95f1d2e | 151 | for(k=0; k<interface->num_altsetting; k++) |
152 | { | |
3664a3e3 | 153 | unsigned char bNumEndpoints = interface->altsetting[k].bNumEndpoints; |
154 | WDU_ENDPOINT_DESCRIPTOR **pEndpointDescriptors; | |
155 | WDU_PIPE_INFO **pPipes; | |
156 | ||
f95f1d2e | 157 | if (buf) { |
158 | WDU_ALTERNATE_SETTING *altset = (WDU_ALTERNATE_SETTING*)(buf+len); | |
159 | ||
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; | |
3664a3e3 | 169 | pEndpointDescriptors = &(altset->pEndpointDescriptors); |
170 | pPipes = &(altset->pPipes); | |
f95f1d2e | 171 | |
172 | } | |
173 | len +=sizeof(WDU_ALTERNATE_SETTING); | |
174 | ||
175 | if (buf) { | |
3664a3e3 | 176 | *pEndpointDescriptors = (WDU_ENDPOINT_DESCRIPTOR*)(buf+len); |
f95f1d2e | 177 | for (l = 0; l < bNumEndpoints; l++) { |
178 | WDU_ENDPOINT_DESCRIPTOR *ed = (WDU_ENDPOINT_DESCRIPTOR*)(buf+len); | |
f95f1d2e | 179 | |
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; | |
186 | ||
187 | len += sizeof(WDU_ENDPOINT_DESCRIPTOR); | |
792bf5f2 | 188 | } |
f95f1d2e | 189 | |
3664a3e3 | 190 | *pPipes = (WDU_PIPE_INFO*)(buf+len); |
792bf5f2 | 191 | for (l = 0; l < bNumEndpoints; l++) { |
192 | WDU_PIPE_INFO *pi = (WDU_PIPE_INFO*)(buf+len); | |
f95f1d2e | 193 | |
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; | |
199 | else | |
200 | { | |
201 | pi->direction = interface->altsetting[k].endpoint[l].bEndpointAddress & USB_ENDPOINT_DIR_MASK ? WDU_DIR_IN : WDU_DIR_OUT; | |
202 | } | |
203 | ||
204 | pi->dwInterval = interface->altsetting[k].endpoint[l].bInterval; | |
205 | ||
206 | len += sizeof(WDU_PIPE_INFO); | |
207 | } | |
208 | } else { | |
209 | len +=(sizeof(WDU_ENDPOINT_DESCRIPTOR)+sizeof(WDU_PIPE_INFO))*bNumEndpoints; | |
210 | } | |
211 | } | |
212 | } | |
213 | } | |
214 | ||
215 | return len; | |
216 | } | |
217 | ||
9c9fd67c | 218 | int do_wdioctl(int fd, unsigned int request, unsigned char *wdioctl) { |
cdc711dc | 219 | struct header_struct* wdheader = (struct header_struct*)wdioctl; |
9c9fd67c | 220 | struct version_struct *version; |
221 | int ret = 0; | |
cdc711dc | 222 | |
da3ba95a | 223 | if (wdheader->magic != MAGIC) { |
2c2119eb | 224 | fprintf(stderr,"!!!ERROR: magic header does not match!!!\n"); |
225 | return (*ioctl_func) (fd, request, wdioctl); | |
cdc711dc | 226 | } |
227 | ||
ca18111b | 228 | fprintf(stderr,"PID %d: ",getpid()); |
cdc711dc | 229 | switch(request) { |
da3ba95a | 230 | case VERSION: |
9c9fd67c | 231 | version = (struct version_struct*)(wdheader->data); |
232 | strcpy(version->version, "WinDriver no more"); | |
233 | version->versionul = 999; | |
234 | fprintf(stderr,"faking VERSION\n"); | |
cdc711dc | 235 | break; |
2c2119eb | 236 | |
237 | case LICENSE: | |
238 | fprintf(stderr,"faking LICENSE\n"); | |
239 | break; | |
240 | ||
9c9fd67c | 241 | case CARD_REGISTER: |
242 | { | |
2c2119eb | 243 | //struct card_register* cr = (struct card_register*)(wdheader->data); |
9c9fd67c | 244 | /* Todo: LPT-Port already in use */ |
245 | } | |
246 | fprintf(stderr,"faking CARD_REGISTER\n"); | |
da3ba95a | 247 | break; |
2c2119eb | 248 | |
da3ba95a | 249 | case USB_TRANSFER: |
9c9fd67c | 250 | fprintf(stderr,"in USB_TRANSFER"); |
da3ba95a | 251 | { |
252 | struct usb_transfer *ut = (struct usb_transfer*)(wdheader->data); | |
253 | ||
2c2119eb | 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); |
9c9fd67c | 255 | fprintf(stderr,"setup packet: "); |
256 | hexdump(ut->SetupPacket, 8); | |
257 | fprintf(stderr,"\n"); | |
258 | if (!ut->fRead && ut->dwBufferSize) | |
259 | { | |
260 | hexdump(ut->pBuffer, ut->dwBufferSize); | |
261 | fprintf(stderr,"\n"); | |
262 | } | |
263 | ||
795992ad | 264 | #ifndef NO_WINDRVR |
9c9fd67c | 265 | ret = (*ioctl_func) (fd, request, wdioctl); |
292160ed | 266 | #endif |
9c9fd67c | 267 | |
2c2119eb | 268 | fprintf(stderr,"Transferred: %lu (%s)\n",ut->dwBytesTransferred, (ut->fRead?"read":"write")); |
9c9fd67c | 269 | if (ut->fRead && ut->dwBytesTransferred) |
270 | { | |
271 | fprintf(stderr,"Read: "); | |
272 | hexdump(ut->pBuffer, ut->dwBytesTransferred); | |
ca18111b | 273 | fprintf(stderr,"\n"); |
9c9fd67c | 274 | } |
da3ba95a | 275 | } |
cdc711dc | 276 | break; |
2c2119eb | 277 | |
da3ba95a | 278 | case INT_ENABLE: |
ca18111b | 279 | fprintf(stderr,"INT_ENABLE\n"); |
da3ba95a | 280 | { |
9c9fd67c | 281 | struct interrupt *it = (struct interrupt*)(wdheader->data); |
cdc711dc | 282 | |
ca18111b | 283 | hexdump(wdheader->data, wdheader->size); |
53f639f2 | 284 | 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 | 285 | |
9c9fd67c | 286 | it->fEnableOk = 1; |
ca18111b | 287 | ints_enabled = 1; |
9c9fd67c | 288 | //ret = (*ioctl_func) (fd, request, wdioctl); |
289 | } | |
cdc711dc | 290 | |
cdc711dc | 291 | break; |
9c9fd67c | 292 | |
da3ba95a | 293 | case INT_DISABLE: |
9c9fd67c | 294 | fprintf(stderr,"INT_DISABLE\n"); |
da3ba95a | 295 | { |
9c9fd67c | 296 | struct interrupt *it = (struct interrupt*)(wdheader->data); |
da3ba95a | 297 | |
53f639f2 | 298 | 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 | 299 | #ifndef NO_WINDRVR |
9c9fd67c | 300 | ret = (*ioctl_func) (fd, request, wdioctl); |
e71b6bf3 | 301 | #else |
302 | it->dwCounter = 0; | |
303 | it->fStopped = 1; | |
ca18111b | 304 | ints_enabled = 0; |
292160ed | 305 | #endif |
53f639f2 | 306 | 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 | 307 | } |
da3ba95a | 308 | break; |
da3ba95a | 309 | |
9c9fd67c | 310 | case USB_SET_INTERFACE: |
311 | fprintf(stderr,"USB_SET_INTERFACE\n"); | |
da3ba95a | 312 | { |
9c9fd67c | 313 | struct usb_set_interface *usi = (struct usb_set_interface*)(wdheader->data); |
314 | ||
2c2119eb | 315 | fprintf(stderr,"unique: %lu, interfacenum: %lu, alternatesetting: %lu, options: %lx\n", usi->dwUniqueID, usi->dwInterfaceNum, usi->dwAlternateSetting, usi->dwOptions); |
795992ad | 316 | #ifndef NO_WINDRVR |
9c9fd67c | 317 | ret = (*ioctl_func) (fd, request, wdioctl); |
2a7af812 | 318 | #else |
319 | if (usbdevice) { | |
320 | int iface; | |
321 | ||
322 | if (!usb_devhandle) | |
323 | usb_devhandle = usb_open(usbdevice); | |
324 | //MGMG | |
325 | ret = usb_claim_interface(usb_devhandle, iface); | |
326 | } | |
292160ed | 327 | #endif |
2a7af812 | 328 | fprintf(stderr,"unique: %lu, interfacenum: %lu, alternatesetting: %lu, options: %lx\n", usi->dwUniqueID, usi->dwInterfaceNum, usi->dwAlternateSetting, usi->dwOptions); |
da3ba95a | 329 | } |
cdc711dc | 330 | break; |
da3ba95a | 331 | |
9c9fd67c | 332 | case USB_GET_DEVICE_DATA: |
ca18111b | 333 | fprintf(stderr,"faking USB_GET_DEVICE_DATA\n"); |
9c9fd67c | 334 | { |
335 | struct usb_get_device_data *ugdd = (struct usb_get_device_data*)(wdheader->data); | |
336 | int pSize; | |
337 | ||
e71b6bf3 | 338 | fprintf(stderr, "unique: %lu, bytes: %lu, options: %lx\n", ugdd->dwUniqueID, ugdd->dwBytes, ugdd->dwOptions); |
9c9fd67c | 339 | pSize = ugdd->dwBytes; |
ca18111b | 340 | //ret = (*ioctl_func) (fd, request, wdioctl); |
e71b6bf3 | 341 | if (!ugdd->dwBytes) { |
2a7af812 | 342 | if (usbdevice) { |
f95f1d2e | 343 | ugdd->dwBytes = usb_deviceinfo(NULL); |
e71b6bf3 | 344 | } |
345 | } else { | |
f95f1d2e | 346 | usb_deviceinfo((unsigned char*)ugdd->pBuf); |
e71b6bf3 | 347 | } |
ca18111b | 348 | |
9c9fd67c | 349 | if (pSize) { |
e71b6bf3 | 350 | struct usb_device_info *udi = (struct usb_device_info*)ugdd->pBuf; |
351 | ||
352 | fprintf(stderr, "Vendor: %x\n", udi->Descriptor.idVendor); | |
da3ba95a | 353 | } |
354 | } | |
9c9fd67c | 355 | break; |
356 | ||
b0f621dd | 357 | case EVENT_REGISTER: |
358 | fprintf(stderr,"EVENT_REGISTER\n"); | |
359 | { | |
360 | struct event *e = (struct event*)(wdheader->data); | |
ac22d975 | 361 | struct usb_bus *bus; |
b0f621dd | 362 | int i; |
363 | ||
364 | 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 | 365 | for (i = 0; i < e->dwNumMatchTables; i++) { |
e71b6bf3 | 366 | 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 | 367 | |
ac22d975 | 368 | for (bus = busses; bus; bus = bus->next) { |
369 | struct usb_device *dev; | |
370 | ||
371 | for (dev = bus->devices; dev; dev = dev->next) { | |
372 | struct usb_device_descriptor *desc = &(dev->descriptor); | |
373 | ||
374 | if((desc->idVendor == e->matchTables[i].VendorId) && | |
375 | (desc->idProduct == e->matchTables[i].ProductId) && | |
376 | (desc->bDeviceClass == e->matchTables[i].bDeviceClass) && | |
377 | (desc->bDeviceSubClass == e->matchTables[i].bDeviceSubClass)) { | |
2a7af812 | 378 | int ac; |
379 | for (ac = 0; ac < desc->bNumConfigurations; ac++) { | |
380 | struct usb_interface *interface = dev->config[ac].interface; | |
381 | int ai; | |
382 | ||
383 | for (ai = 0; ai < interface->num_altsetting; ai++) { | |
384 | fprintf(stderr, "intclass: %x, intsubclass: %x, intproto: %x\n", interface->altsetting[i].bInterfaceClass, interface->altsetting[i].bInterfaceSubClass, interface->altsetting[i].bInterfaceProtocol); | |
385 | if ((interface->altsetting[ai].bInterfaceSubClass == e->matchTables[i].bInterfaceSubClass) && | |
386 | (interface->altsetting[ai].bInterfaceProtocol == e->matchTables[i].bInterfaceProtocol)){ | |
387 | /* TODO: check interfaceClass! */ | |
388 | fprintf(stderr,"!!!FOUND DEVICE WITH LIBUSB!!!\n"); | |
389 | usbdevice = dev; | |
390 | card_type = e->dwCardType; | |
391 | } | |
392 | } | |
393 | } | |
ac22d975 | 394 | } |
395 | } | |
396 | } | |
397 | } | |
398 | ||
795992ad | 399 | #ifndef NO_WINDRVR |
b0f621dd | 400 | ret = (*ioctl_func) (fd, request, wdioctl); |
2a7af812 | 401 | #else |
402 | //handle: 0, action: 16371, status: 0, eventid: 0, cardtype: 4294967294, kplug: 0, options: 0, dev: 0:0, unique: 0, ver: 1, nummatch: 2 | |
403 | //handle: 1, action: 16371, status: 0, eventid: 0, cardtype: 4294967294, kplug: 0, options: 0, dev: 0:0, unique: 0, ver: 1, nummatch: 2 | |
404 | e->handle++; | |
292160ed | 405 | #endif |
b0f621dd | 406 | |
407 | 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); | |
408 | for (i = 0; i < e->dwNumMatchTables; i++) | |
e71b6bf3 | 409 | 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 | 410 | } |
411 | break; | |
412 | ||
da3ba95a | 413 | case TRANSFER: |
9c9fd67c | 414 | fprintf(stderr,"TRANSFER\n"); |
795992ad | 415 | #ifndef NO_WINDRVR |
9c9fd67c | 416 | ret = (*ioctl_func) (fd, request, wdioctl); |
292160ed | 417 | #endif |
9c9fd67c | 418 | break; |
419 | ||
da3ba95a | 420 | case EVENT_UNREGISTER: |
9c9fd67c | 421 | fprintf(stderr,"EVENT_UNREGISTER\n"); |
795992ad | 422 | #ifndef NO_WINDRVR |
9c9fd67c | 423 | ret = (*ioctl_func) (fd, request, wdioctl); |
292160ed | 424 | #endif |
9c9fd67c | 425 | break; |
426 | ||
da3ba95a | 427 | case INT_WAIT: |
9c9fd67c | 428 | fprintf(stderr,"INT_WAIT\n"); |
b0f621dd | 429 | { |
430 | struct interrupt *it = (struct interrupt*)(wdheader->data); | |
431 | ||
ca18111b | 432 | hexdump(wdheader->data, wdheader->size); |
53f639f2 | 433 | 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 | 434 | |
795992ad | 435 | #ifndef NO_WINDRVR |
b0f621dd | 436 | ret = (*ioctl_func) (fd, request, wdioctl); |
292160ed | 437 | #else |
2a7af812 | 438 | if (usbdevice) { |
439 | if (it->dwCounter == 0) { | |
440 | it->dwCounter = 1; | |
441 | } else { | |
adfa5221 | 442 | //FIXME: signal durch FUTEX, overload futex! |
ca18111b | 443 | while(ints_enabled) {sleep(1);} |
2a7af812 | 444 | } |
94038a57 | 445 | } else { |
ca18111b | 446 | while(ints_enabled) {sleep(1);} |
2a7af812 | 447 | } |
292160ed | 448 | #endif |
449 | ||
ca18111b | 450 | 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); |
b0f621dd | 451 | } |
9c9fd67c | 452 | break; |
453 | ||
da3ba95a | 454 | case CARD_UNREGISTER: |
9c9fd67c | 455 | fprintf(stderr,"CARD_UNREGISTER\n"); |
795992ad | 456 | #ifndef NO_WINDRVR |
9c9fd67c | 457 | ret = (*ioctl_func) (fd, request, wdioctl); |
292160ed | 458 | #endif |
9c9fd67c | 459 | break; |
460 | ||
da3ba95a | 461 | case EVENT_PULL: |
9c9fd67c | 462 | fprintf(stderr,"EVENT_PULL\n"); |
b1831983 | 463 | { |
464 | struct event *e = (struct event*)(wdheader->data); | |
465 | int i; | |
466 | ||
2a7af812 | 467 | 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); |
b1831983 | 468 | for (i = 0; i < e->dwNumMatchTables; i++) |
e71b6bf3 | 469 | 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 | 470 | |
795992ad | 471 | #ifndef NO_WINDRVR |
b1831983 | 472 | ret = (*ioctl_func) (fd, request, wdioctl); |
292160ed | 473 | #else |
474 | //EVENT_PULL | |
475 | //handle: 1, action: 0, status: 0, eventid: 0, cardtype: 0, kplug: 0, options: 0, dev: 0:0, unique: 0, ver: 1, nummatch: 1 | |
476 | //match: dev: 0:0, class: 0, subclass: 0, intclass: 0, intsubclass: 0, intproto: 0 | |
477 | //handle: 1, action: 1, status: 0, eventid: 109, cardtype: 4294967294, kplug: 0, options: 0, dev: 0:0, unique: 90, ver: 1, nummatch: 1 | |
478 | //match: dev: 3fd:8, class: 0, subclass: 0, intclass: ff, intsubclass: 0, intproto: 0 | |
2a7af812 | 479 | if (usbdevice) { |
480 | struct usb_interface *interface = usbdevice->config->interface; | |
292160ed | 481 | |
482 | e->dwCardType = card_type; | |
483 | e->dwAction = 1; | |
484 | e->dwEventId = 109; | |
ca18111b | 485 | e->u.Usb.dwUniqueID = 110; |
2a7af812 | 486 | e->matchTables[0].VendorId = usbdevice->descriptor.idVendor; |
487 | e->matchTables[0].ProductId = usbdevice->descriptor.idProduct; | |
488 | e->matchTables[0].bDeviceClass = usbdevice->descriptor.bDeviceClass; | |
489 | e->matchTables[0].bDeviceSubClass = usbdevice->descriptor.bDeviceSubClass; | |
292160ed | 490 | e->matchTables[0].bInterfaceClass = interface->altsetting[0].bInterfaceClass; |
491 | e->matchTables[0].bInterfaceSubClass = interface->altsetting[0].bInterfaceSubClass; | |
492 | e->matchTables[0].bInterfaceProtocol = interface->altsetting[0].bInterfaceProtocol; | |
493 | } | |
494 | #endif | |
b1831983 | 495 | |
2a7af812 | 496 | 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); |
b1831983 | 497 | for (i = 0; i < e->dwNumMatchTables; i++) |
e71b6bf3 | 498 | 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); |
ca18111b | 499 | |
b1831983 | 500 | } |
9c9fd67c | 501 | break; |
502 | ||
da3ba95a | 503 | default: |
292160ed | 504 | fprintf(stderr,"!!!Unsupported IOCTL: %x!!!\n", request); |
795992ad | 505 | #ifndef NO_WINDRVR |
9c9fd67c | 506 | ret = (*ioctl_func) (fd, request, wdioctl); |
292160ed | 507 | #endif |
508 | break; | |
cdc711dc | 509 | } |
da3ba95a | 510 | |
9c9fd67c | 511 | return ret; |
cdc711dc | 512 | } |
513 | ||
514 | ||
515 | typedef int (*open_funcptr_t) (const char *, int, mode_t); | |
516 | ||
cdc711dc | 517 | int open (const char *pathname, int flags, ...) |
518 | { | |
519 | static open_funcptr_t func = NULL; | |
520 | mode_t mode = 0; | |
521 | va_list args; | |
522 | int fd; | |
523 | ||
524 | if (!func) | |
525 | func = (open_funcptr_t) dlsym (REAL_LIBC, "open"); | |
526 | ||
527 | if (flags & O_CREAT) { | |
528 | va_start(args, flags); | |
529 | mode = va_arg(args, mode_t); | |
530 | va_end(args); | |
531 | } | |
532 | ||
cdc711dc | 533 | if (!strcmp (pathname, "/dev/windrvr6")) { |
534 | fprintf(stderr,"opening windrvr6\n"); | |
795992ad | 535 | #ifdef NO_WINDRVR |
01b99d52 | 536 | windrvrfd = fd = (*func) ("/dev/null", flags, mode); |
537 | #else | |
538 | windrvrfd = fd = (*func) (pathname, flags, mode); | |
539 | #endif | |
f10480d1 | 540 | if (!busses) { |
541 | usb_init(); | |
542 | usb_find_busses(); | |
543 | usb_find_devices(); | |
544 | ||
545 | busses = usb_get_busses(); | |
546 | } | |
01b99d52 | 547 | } else { |
548 | fd = (*func) (pathname, flags, mode); | |
cdc711dc | 549 | } |
550 | ||
551 | return fd; | |
552 | } | |
553 | ||
554 | void diff(unsigned char *buf1, unsigned char *buf2, int len) { | |
555 | int i; | |
556 | ||
557 | for(i=0; i<len; i++) { | |
558 | if (buf1[i] != buf2[i]) { | |
559 | 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]:'.')); | |
560 | } | |
561 | } | |
562 | } | |
563 | ||
564 | void hexdump(unsigned char *buf, int len) { | |
565 | int i; | |
566 | ||
567 | for(i=0; i<len; i++) { | |
568 | fprintf(stderr,"%02x ", buf[i]); | |
569 | if ((i % 16) == 15) | |
570 | fprintf(stderr,"\n"); | |
571 | } | |
572 | } | |
573 | ||
574 | int ioctl(int fd, int request, ...) | |
575 | { | |
cdc711dc | 576 | va_list args; |
577 | void *argp; | |
cdc711dc | 578 | int ret; |
579 | ||
9c9fd67c | 580 | if (!ioctl_func) |
581 | ioctl_func = (int (*) (int, int, void *)) dlsym (REAL_LIBC, "ioctl"); | |
cdc711dc | 582 | |
583 | va_start (args, request); | |
584 | argp = va_arg (args, void *); | |
585 | va_end (args); | |
586 | ||
9c9fd67c | 587 | if (fd == windrvrfd) |
588 | ret = do_wdioctl(fd, request, argp); | |
589 | else | |
590 | ret = (*ioctl_func) (fd, request, argp); | |
cdc711dc | 591 | |
cdc711dc | 592 | return ret; |
593 | } | |
594 | ||
ca18111b | 595 | int futex(int *uaddr, int op, int val, const struct timespec *timeout, int *uaddr2, int val3) { |
596 | static int (*func) (int*, int, int, const struct timespec*, int*, int) = NULL; | |
597 | int ret; | |
598 | ||
599 | if (!func) | |
600 | func = (int (*) (int*, int, int, const struct timespec*, int*, int)) dlsym(REAL_LIBC, "futex"); | |
601 | ||
602 | fprintf(stderr,"FUTEX: %x\n", (unsigned int)uaddr); | |
603 | ret = (*func) (uaddr, op, val, timeout, uaddr2, val3); | |
604 | ||
605 | return ret; | |
606 | } | |
607 | ||
608 | ||
da3ba95a | 609 | #if 0 |
cdc711dc | 610 | void *mmap(void *start, size_t length, int prot, int flags, int fd, off_t offset) |
611 | { | |
612 | static void* (*func) (void *, size_t, int, int, int, off_t) = NULL; | |
613 | void *ret; | |
614 | ||
615 | if (!func) | |
616 | func = (void* (*) (void *, size_t, int, int, int, off_t)) dlsym (REAL_LIBC, "mmap"); | |
617 | ||
618 | ret = (*func) (start, length, prot, flags, fd, offset); | |
619 | fprintf(stderr,"MMAP: %x, %d, %d, %d, %d, %d -> %x\n", (unsigned int)start, length, prot, flags, fd, offset, (unsigned int)ret); | |
620 | mmapped = ret; | |
621 | mmapplen = length; | |
622 | ||
623 | return ret; | |
624 | } | |
625 | ||
626 | void *mmap64(void *start, size_t length, int prot, int flags, int fd, off64_t offset) | |
627 | { | |
628 | static void* (*func) (void *, size_t, int, int, int, off64_t) = NULL; | |
629 | void *ret; | |
630 | ||
631 | if (!func) | |
632 | func = (void* (*) (void *, size_t, int, int, int, off64_t)) dlsym (REAL_LIBC, "mmap64"); | |
633 | ||
634 | ret = (*func) (start, length, prot, flags, fd, offset); | |
635 | fprintf(stderr,"MMAP64: %x, %d, %d, %d, %d, %lld -> %x\n", (unsigned int)start, length, prot, flags, fd, offset, (unsigned int)ret); | |
636 | mmapped = ret; | |
637 | mmapplen = length; | |
638 | ||
639 | return ret; | |
640 | } | |
641 | ||
642 | void *mmap2(void *start, size_t length, int prot, int flags, int fd, off_t pgoffset) | |
643 | { | |
644 | static void* (*func) (void *, size_t, int, int, int, off_t) = NULL; | |
645 | void *ret; | |
646 | ||
647 | if (!func) | |
648 | func = (void* (*) (void *, size_t, int, int, int, off_t)) dlsym (REAL_LIBC, "mmap2"); | |
649 | ||
650 | ret = (*func) (start, length, prot, flags, fd, pgoffset); | |
651 | fprintf(stderr,"MMAP2: %x, %d, %d, %d, %d, %d -> %x\n", (unsigned int)start, length, prot, flags, fd, pgoffset, (unsigned int)ret); | |
652 | mmapped = ret; | |
653 | mmapplen = length; | |
654 | ||
655 | return ret; | |
656 | } | |
657 | ||
658 | void *malloc(size_t size) | |
659 | { | |
660 | static void* (*func) (size_t) = NULL; | |
661 | void *ret; | |
662 | ||
663 | if (!func) | |
664 | func = (void* (*) (size_t)) dlsym(REAL_LIBC, "malloc"); | |
665 | ||
666 | ret = (*func) (size); | |
667 | ||
668 | //fprintf(stderr,"MALLOC: %d -> %x\n", size, (unsigned int) ret); | |
669 | ||
670 | return ret; | |
671 | } | |
da3ba95a | 672 | #endif |
cdc711dc | 673 | |
674 | ||
675 | #endif |