]>
Commit | Line | Data |
---|---|---|
54357994 | 1 | /* libusb/ppdev connector for XILINX impact |
f1405f13 | 2 | * |
3 | * Copyright (c) 2007 Michael Gernoth <michael@gernoth.net> | |
4 | * | |
5 | * Permission is hereby granted, free of charge, to any person obtaining a copy | |
6 | * of this software and associated documentation files (the "Software"), to | |
7 | * deal in the Software without restriction, including without limitation the | |
8 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or | |
9 | * sell copies of the Software, and to permit persons to whom the Software is | |
10 | * furnished to do so, subject to the following conditions: | |
11 | * | |
12 | * The above copyright notice and this permission notice shall be included in | |
13 | * all copies or substantial portions of the Software. | |
14 | * | |
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | |
20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS | |
21 | * IN THE SOFTWARE. | |
22 | */ | |
cdc711dc | 23 | |
24 | #define _GNU_SOURCE 1 | |
25 | ||
cdc711dc | 26 | #include <dlfcn.h> |
27 | #include <stdarg.h> | |
28 | #include <stdlib.h> | |
29 | #include <string.h> | |
30 | #include <unistd.h> | |
31 | #include <fcntl.h> | |
32 | #include <sys/types.h> | |
33 | #include <sys/stat.h> | |
34 | #include <sys/time.h> | |
35 | #include <stdio.h> | |
f10480d1 | 36 | #include <usb.h> |
2a7af812 | 37 | #include <signal.h> |
533f4b68 | 38 | #include <pthread.h> |
9ba1e383 | 39 | #include <errno.h> |
11d01742 | 40 | #include <inttypes.h> |
54357994 | 41 | #include <sys/ioctl.h> |
42 | #include <linux/parport.h> | |
43 | #include <linux/ppdev.h> | |
2c0c1255 | 44 | #include "usb-driver.h" |
19b2e286 | 45 | #ifdef JTAGKEY |
46 | #include "jtagkey.h" | |
47 | #endif | |
cdc711dc | 48 | |
9c9fd67c | 49 | static int (*ioctl_func) (int, int, void *) = NULL; |
332ced7a | 50 | static int windrvrfd = -1; |
54357994 | 51 | static int parportfd = -1; |
54357994 | 52 | static unsigned long ppbase = 0; |
53 | static unsigned long ecpbase = 0; | |
332ced7a | 54 | FILE *modulesfp = NULL; |
0dca330e | 55 | FILE *baseaddrfp = NULL; |
56 | int baseaddrnum = 0; | |
723d9aa0 | 57 | static int modules_read = 0; |
f10480d1 | 58 | static struct usb_bus *busses = NULL; |
2a7af812 | 59 | static struct usb_device *usbdevice; |
60 | static usb_dev_handle *usb_devhandle = NULL; | |
010cbaa6 | 61 | static int usbinterface = -1; |
b72b86b4 | 62 | static unsigned long card_type; |
ca18111b | 63 | static int ints_enabled = 0; |
533f4b68 | 64 | static pthread_mutex_t int_wait = PTHREAD_MUTEX_INITIALIZER; |
292160ed | 65 | |
795992ad | 66 | #define NO_WINDRVR 1 |
723d9aa0 | 67 | |
be452175 | 68 | #ifdef DEBUG |
723d9aa0 | 69 | void hexdump(unsigned char *buf, int len) { |
70 | int i; | |
71 | ||
72 | for(i=0; i<len; i++) { | |
73 | fprintf(stderr,"%02x ", buf[i]); | |
74 | if ((i % 16) == 15) | |
75 | fprintf(stderr,"\n"); | |
76 | } | |
f1405f13 | 77 | fprintf(stderr,"\n"); |
723d9aa0 | 78 | } |
be452175 | 79 | #endif |
cdc711dc | 80 | |
f95f1d2e | 81 | int usb_deviceinfo(unsigned char *buf) { |
82 | int i,j,k,l; | |
83 | int len = 0; | |
3664a3e3 | 84 | WDU_CONFIGURATION **pConfigs, **pActiveConfig; |
85 | WDU_INTERFACE **pActiveInterface; | |
f95f1d2e | 86 | |
87 | if (buf) { | |
88 | struct usb_device_info *udi = (struct usb_device_info*)(buf+len); | |
89 | ||
90 | udi->Descriptor.bLength = sizeof(WDU_DEVICE_DESCRIPTOR); | |
2a7af812 | 91 | udi->Descriptor.bDescriptorType = usbdevice->descriptor.bDescriptorType; |
92 | udi->Descriptor.bcdUSB = usbdevice->descriptor.bcdUSB; | |
93 | udi->Descriptor.bDeviceClass = usbdevice->descriptor.bDeviceClass; | |
94 | udi->Descriptor.bDeviceSubClass = usbdevice->descriptor.bDeviceSubClass; | |
95 | udi->Descriptor.bDeviceProtocol = usbdevice->descriptor.bDeviceProtocol; | |
96 | udi->Descriptor.bMaxPacketSize0 = usbdevice->descriptor.bMaxPacketSize0; | |
97 | udi->Descriptor.idVendor = usbdevice->descriptor.idVendor; | |
98 | udi->Descriptor.idProduct = usbdevice->descriptor.idProduct; | |
99 | udi->Descriptor.bcdDevice = usbdevice->descriptor.bcdDevice; | |
100 | udi->Descriptor.iManufacturer = usbdevice->descriptor.iManufacturer; | |
101 | udi->Descriptor.iProduct = usbdevice->descriptor.iProduct; | |
102 | udi->Descriptor.iSerialNumber = usbdevice->descriptor.iSerialNumber; | |
103 | udi->Descriptor.bNumConfigurations = usbdevice->descriptor.bNumConfigurations; | |
f95f1d2e | 104 | |
105 | /* TODO: Fix Pipe0! */ | |
106 | udi->Pipe0.dwNumber = 0x00; | |
2a7af812 | 107 | udi->Pipe0.dwMaximumPacketSize = usbdevice->descriptor.bMaxPacketSize0; |
f95f1d2e | 108 | udi->Pipe0.type = 0; |
8923df66 | 109 | udi->Pipe0.direction = WDU_DIR_IN_OUT; |
f95f1d2e | 110 | udi->Pipe0.dwInterval = 0; |
3664a3e3 | 111 | |
112 | pConfigs = &(udi->pConfigs); | |
113 | pActiveConfig = &(udi->pActiveConfig); | |
114 | pActiveInterface = &(udi->pActiveInterface[0]); | |
f95f1d2e | 115 | } |
116 | ||
117 | len = sizeof(struct usb_device_info); | |
118 | ||
2a7af812 | 119 | for (i=0; i<usbdevice->descriptor.bNumConfigurations; i++) |
f95f1d2e | 120 | { |
2a7af812 | 121 | struct usb_config_descriptor *conf_desc = &usbdevice->config[i]; |
3664a3e3 | 122 | WDU_INTERFACE **pInterfaces; |
123 | WDU_ALTERNATE_SETTING **pAlternateSettings[conf_desc->bNumInterfaces]; | |
124 | WDU_ALTERNATE_SETTING **pActiveAltSetting[conf_desc->bNumInterfaces]; | |
125 | ||
f95f1d2e | 126 | if (buf) { |
127 | WDU_CONFIGURATION *cfg = (WDU_CONFIGURATION*)(buf+len); | |
128 | ||
3664a3e3 | 129 | *pConfigs = cfg; |
130 | *pActiveConfig = cfg; | |
131 | ||
f95f1d2e | 132 | cfg->Descriptor.bLength = conf_desc->bLength; |
133 | cfg->Descriptor.bDescriptorType = conf_desc->bDescriptorType; | |
134 | cfg->Descriptor.wTotalLength = conf_desc->wTotalLength; | |
135 | cfg->Descriptor.bNumInterfaces = conf_desc->bNumInterfaces; | |
136 | cfg->Descriptor.bConfigurationValue = conf_desc->bConfigurationValue; | |
137 | cfg->Descriptor.iConfiguration = conf_desc->iConfiguration; | |
138 | cfg->Descriptor.bmAttributes = conf_desc->bmAttributes; | |
139 | cfg->Descriptor.MaxPower = conf_desc->MaxPower; | |
140 | ||
141 | cfg->dwNumInterfaces = conf_desc->bNumInterfaces; | |
3664a3e3 | 142 | |
143 | pInterfaces = &(cfg->pInterfaces); | |
f95f1d2e | 144 | } |
145 | len += sizeof(WDU_CONFIGURATION); | |
3664a3e3 | 146 | |
f95f1d2e | 147 | if (buf) { |
3664a3e3 | 148 | *pInterfaces = (WDU_INTERFACE*)(buf+len); |
f95f1d2e | 149 | for (j=0; j<conf_desc->bNumInterfaces; j++) { |
150 | WDU_INTERFACE *iface = (WDU_INTERFACE*)(buf+len); | |
3664a3e3 | 151 | |
152 | pActiveInterface[j] = iface; | |
153 | ||
154 | pAlternateSettings[j] = &(iface->pAlternateSettings); | |
2a7af812 | 155 | iface->dwNumAltSettings = usbdevice->config[i].interface[j].num_altsetting; |
3664a3e3 | 156 | pActiveAltSetting[j] = &(iface->pActiveAltSetting); |
f95f1d2e | 157 | |
158 | len += sizeof(WDU_INTERFACE); | |
159 | } | |
160 | } else { | |
161 | len += sizeof(WDU_INTERFACE) * conf_desc->bNumInterfaces; | |
162 | } | |
163 | ||
164 | for (j=0; j<conf_desc->bNumInterfaces; j++) | |
165 | { | |
2a7af812 | 166 | struct usb_interface *interface = &usbdevice->config[i].interface[j]; |
3664a3e3 | 167 | |
168 | if (buf) { | |
169 | *pAlternateSettings[j] = (WDU_ALTERNATE_SETTING*)(buf+len); | |
170 | /* FIXME: */ | |
171 | *pActiveAltSetting[j] = (WDU_ALTERNATE_SETTING*)(buf+len); | |
172 | } | |
173 | ||
f95f1d2e | 174 | for(k=0; k<interface->num_altsetting; k++) |
175 | { | |
3664a3e3 | 176 | unsigned char bNumEndpoints = interface->altsetting[k].bNumEndpoints; |
177 | WDU_ENDPOINT_DESCRIPTOR **pEndpointDescriptors; | |
178 | WDU_PIPE_INFO **pPipes; | |
179 | ||
f95f1d2e | 180 | if (buf) { |
181 | WDU_ALTERNATE_SETTING *altset = (WDU_ALTERNATE_SETTING*)(buf+len); | |
182 | ||
183 | altset->Descriptor.bLength = interface->altsetting[k].bLength; | |
184 | altset->Descriptor.bDescriptorType = interface->altsetting[k].bDescriptorType; | |
185 | altset->Descriptor.bInterfaceNumber = interface->altsetting[k].bInterfaceNumber; | |
186 | altset->Descriptor.bAlternateSetting = interface->altsetting[k].bAlternateSetting; | |
187 | altset->Descriptor.bNumEndpoints = interface->altsetting[k].bNumEndpoints; | |
188 | altset->Descriptor.bInterfaceClass = interface->altsetting[k].bInterfaceClass; | |
189 | altset->Descriptor.bInterfaceSubClass = interface->altsetting[k].bInterfaceSubClass; | |
190 | altset->Descriptor.bInterfaceProtocol = interface->altsetting[k].bInterfaceProtocol; | |
191 | altset->Descriptor.iInterface = interface->altsetting[k].iInterface; | |
3664a3e3 | 192 | pEndpointDescriptors = &(altset->pEndpointDescriptors); |
193 | pPipes = &(altset->pPipes); | |
f95f1d2e | 194 | |
195 | } | |
196 | len +=sizeof(WDU_ALTERNATE_SETTING); | |
197 | ||
198 | if (buf) { | |
3664a3e3 | 199 | *pEndpointDescriptors = (WDU_ENDPOINT_DESCRIPTOR*)(buf+len); |
f95f1d2e | 200 | for (l = 0; l < bNumEndpoints; l++) { |
201 | WDU_ENDPOINT_DESCRIPTOR *ed = (WDU_ENDPOINT_DESCRIPTOR*)(buf+len); | |
f95f1d2e | 202 | |
203 | ed->bLength = interface->altsetting[k].endpoint[l].bLength; | |
204 | ed->bDescriptorType = interface->altsetting[k].endpoint[l].bDescriptorType; | |
205 | ed->bEndpointAddress = interface->altsetting[k].endpoint[l].bEndpointAddress; | |
206 | ed->bmAttributes = interface->altsetting[k].endpoint[l].bmAttributes; | |
207 | ed->wMaxPacketSize = interface->altsetting[k].endpoint[l].wMaxPacketSize; | |
208 | ed->bInterval = interface->altsetting[k].endpoint[l].bInterval; | |
209 | ||
210 | len += sizeof(WDU_ENDPOINT_DESCRIPTOR); | |
792bf5f2 | 211 | } |
f95f1d2e | 212 | |
3664a3e3 | 213 | *pPipes = (WDU_PIPE_INFO*)(buf+len); |
792bf5f2 | 214 | for (l = 0; l < bNumEndpoints; l++) { |
215 | WDU_PIPE_INFO *pi = (WDU_PIPE_INFO*)(buf+len); | |
f95f1d2e | 216 | |
217 | pi->dwNumber = interface->altsetting[k].endpoint[l].bEndpointAddress; | |
218 | pi->dwMaximumPacketSize = WDU_GET_MAX_PACKET_SIZE(interface->altsetting[k].endpoint[l].wMaxPacketSize); | |
219 | pi->type = interface->altsetting[k].endpoint[l].bmAttributes & USB_ENDPOINT_TYPE_MASK; | |
220 | if (pi->type == PIPE_TYPE_CONTROL) | |
221 | pi->direction = WDU_DIR_IN_OUT; | |
222 | else | |
223 | { | |
224 | pi->direction = interface->altsetting[k].endpoint[l].bEndpointAddress & USB_ENDPOINT_DIR_MASK ? WDU_DIR_IN : WDU_DIR_OUT; | |
225 | } | |
226 | ||
227 | pi->dwInterval = interface->altsetting[k].endpoint[l].bInterval; | |
228 | ||
229 | len += sizeof(WDU_PIPE_INFO); | |
230 | } | |
231 | } else { | |
232 | len +=(sizeof(WDU_ENDPOINT_DESCRIPTOR)+sizeof(WDU_PIPE_INFO))*bNumEndpoints; | |
233 | } | |
234 | } | |
235 | } | |
236 | } | |
237 | ||
238 | return len; | |
239 | } | |
240 | ||
ac9e3f59 | 241 | int pp_transfer(WD_TRANSFER *tr, int fd, unsigned int request, unsigned char *wdioctl) { |
242 | int ret = 0; | |
28e7c368 | 243 | unsigned long port = (unsigned long)tr->dwPort; |
54357994 | 244 | unsigned char val; |
19b2e286 | 245 | static unsigned char last_pp_write = 0; |
246 | ||
247 | #ifdef JTAGKEY | |
248 | /* FIXME: Config file and mor intelligent mapping! */ | |
249 | if (ppbase == 0x30) | |
250 | return jtagkey_transfer(tr, fd, request, ppbase, ecpbase, 1); | |
251 | #endif | |
ac9e3f59 | 252 | |
253 | DPRINTF("dwPort: 0x%lx, cmdTrans: %lu, dwbytes: %ld, fautoinc: %ld, dwoptions: %ld\n", | |
254 | (unsigned long)tr->dwPort, tr->cmdTrans, tr->dwBytes, | |
255 | tr->fAutoinc, tr->dwOptions); | |
54357994 | 256 | |
257 | val = tr->Data.Byte; | |
ac9e3f59 | 258 | |
259 | #ifdef DEBUG | |
260 | if (tr->cmdTrans == 13) | |
54357994 | 261 | DPRINTF("write byte: %d\n", val); |
ac9e3f59 | 262 | #endif |
263 | ||
264 | #ifndef NO_WINDRVR | |
265 | ret = (*ioctl_func) (fd, request, wdioctl); | |
54357994 | 266 | #else |
267 | if (parportfd < 0) | |
268 | return ret; | |
269 | ||
28e7c368 | 270 | if (port == ppbase + PP_DATA) { |
271 | DPRINTF("data port\n"); | |
272 | switch(tr->cmdTrans) { | |
273 | case PP_READ: | |
274 | ret = 0; /* We don't support reading of the data port */ | |
275 | break; | |
276 | ||
277 | case PP_WRITE: | |
278 | ret = ioctl(parportfd, PPWDATA, &val); | |
cdc9c5bf | 279 | last_pp_write = val; |
28e7c368 | 280 | break; |
281 | ||
282 | default: | |
283 | fprintf(stderr,"!!!Unsupported TRANSFER command: %lu!!!\n", tr->cmdTrans); | |
284 | ret = -1; | |
285 | break; | |
286 | } | |
287 | } else if (port == ppbase + PP_STATUS) { | |
cdc9c5bf | 288 | DPRINTF("status port (last write: %d)\n", last_pp_write); |
28e7c368 | 289 | switch(tr->cmdTrans) { |
290 | case PP_READ: | |
291 | ret = ioctl(parportfd, PPRSTATUS, &val); | |
05e1bfcd | 292 | #ifdef FORCE_PC3_IDENT |
19b2e286 | 293 | val &= 0x5f; |
294 | if (last_pp_write & 0x40) | |
295 | val |= 0x20; | |
cdc9c5bf | 296 | else |
19b2e286 | 297 | val |= 0x80; |
cdc9c5bf | 298 | #endif |
28e7c368 | 299 | break; |
300 | ||
301 | case PP_WRITE: | |
302 | ret = 0; /* Status Port is readonly */ | |
303 | break; | |
304 | ||
305 | default: | |
306 | fprintf(stderr,"!!!Unsupported TRANSFER command: %lu!!!\n", tr->cmdTrans); | |
307 | ret = -1; | |
308 | break; | |
309 | } | |
310 | } else if (port == ppbase + PP_CONTROL) { | |
311 | DPRINTF("control port\n"); | |
312 | switch(tr->cmdTrans) { | |
313 | case PP_READ: | |
314 | ret = ioctl(parportfd, PPRCONTROL, &val); | |
315 | break; | |
316 | ||
317 | case PP_WRITE: | |
318 | ret = ioctl(parportfd, PPWCONTROL, &val); | |
319 | break; | |
320 | ||
321 | default: | |
322 | fprintf(stderr,"!!!Unsupported TRANSFER command: %lu!!!\n", tr->cmdTrans); | |
323 | ret = -1; | |
324 | break; | |
325 | } | |
54fc4508 | 326 | } else if ((port == ecpbase + PP_ECP_CFGA) && ecpbase) { |
327 | DPRINTF("ECP_CFGA port\n"); | |
328 | } else if ((port == ecpbase + PP_ECP_CFGB) && ecpbase) { | |
329 | DPRINTF("ECP_CFGB port\n"); | |
330 | } else if ((port == ecpbase + PP_ECP_ECR) && ecpbase) { | |
331 | DPRINTF("ECP_ECR port\n"); | |
28e7c368 | 332 | } else { |
54fc4508 | 333 | DPRINTF("access to unsupported address range!\n"); |
28e7c368 | 334 | ret = 0; |
54357994 | 335 | } |
336 | ||
337 | tr->Data.Byte = val; | |
ac9e3f59 | 338 | #endif |
339 | ||
340 | DPRINTF("dwPortReturn: 0x%lx, cmdTrans: %lu, dwbytes: %ld, fautoinc: %ld, dwoptions: %ld\n", | |
341 | (unsigned long)tr->dwPort, tr->cmdTrans, tr->dwBytes, | |
342 | tr->fAutoinc, tr->dwOptions); | |
343 | #ifdef DEBUG | |
344 | if (tr->cmdTrans == 10) | |
345 | DPRINTF("read byte: %d\n", tr->Data.Byte); | |
346 | #endif | |
347 | ||
348 | return ret; | |
349 | } | |
350 | ||
9c9fd67c | 351 | int do_wdioctl(int fd, unsigned int request, unsigned char *wdioctl) { |
cdc711dc | 352 | struct header_struct* wdheader = (struct header_struct*)wdioctl; |
9c9fd67c | 353 | struct version_struct *version; |
354 | int ret = 0; | |
cdc711dc | 355 | |
da3ba95a | 356 | if (wdheader->magic != MAGIC) { |
2c2119eb | 357 | fprintf(stderr,"!!!ERROR: magic header does not match!!!\n"); |
358 | return (*ioctl_func) (fd, request, wdioctl); | |
cdc711dc | 359 | } |
360 | ||
bdc65937 | 361 | switch(request & ~(0xc0000000)) { |
da3ba95a | 362 | case VERSION: |
9c9fd67c | 363 | version = (struct version_struct*)(wdheader->data); |
bccac33b | 364 | strcpy(version->version, "libusb-driver.so $Revision: 1.62 $"); |
90831fba | 365 | version->versionul = 802; |
f1405f13 | 366 | DPRINTF("VERSION\n"); |
cdc711dc | 367 | break; |
2c2119eb | 368 | |
369 | case LICENSE: | |
f1405f13 | 370 | DPRINTF("LICENSE\n"); |
2c2119eb | 371 | break; |
372 | ||
f152c048 | 373 | case CARD_REGISTER_OLD: |
9c9fd67c | 374 | case CARD_REGISTER: |
54357994 | 375 | DPRINTF("CARD_REGISTER\n"); |
9c9fd67c | 376 | { |
533f4b68 | 377 | struct card_register* cr = (struct card_register*)(wdheader->data); |
54357994 | 378 | char ppdev[32]; |
379 | ||
380 | DPRINTF("Items: %lu, Addr: 0x%lx, bytes: %lu, bar: %lu\n", | |
381 | cr->Card.dwItems, | |
382 | (unsigned long)cr->Card.Item[0].I.IO.dwAddr, | |
383 | cr->Card.Item[0].I.IO.dwBytes, | |
384 | cr->Card.Item[0].I.IO.dwBar); | |
385 | ||
386 | DPRINTF("Items: %lu, Addr: 0x%lx, bytes: %lu, bar: %lu\n", | |
387 | cr->Card.dwItems, | |
388 | (unsigned long)cr->Card.Item[1].I.IO.dwAddr, | |
389 | cr->Card.Item[1].I.IO.dwBytes, | |
390 | cr->Card.Item[1].I.IO.dwBar); | |
576995a8 | 391 | #ifndef NO_WINDRVR |
392 | ret = (*ioctl_func) (fd, request, wdioctl); | |
ac9e3f59 | 393 | #else |
19b2e286 | 394 | |
395 | /* FIXME: Ugly hack which maps amontec JtagKey to 4. parallel port */ | |
396 | #ifdef JTAGKEY | |
bccac33b | 397 | if ((unsigned long)cr->Card.Item[0].I.IO.dwAddr == 0x30) { |
398 | ret=jtagkey_init(0x0403, 0xcff8); /* I need a config file... */ | |
399 | cr->hCard = 0xff; | |
400 | ppbase = (unsigned long)cr->Card.Item[0].I.IO.dwAddr; | |
401 | if (ret < 0) | |
402 | cr->hCard = 0; | |
403 | ||
404 | break; | |
405 | } | |
19b2e286 | 406 | #endif |
bccac33b | 407 | if (parportfd < 0) { |
408 | snprintf(ppdev, sizeof(ppdev), "/dev/parport%lu", | |
409 | (unsigned long)cr->Card.Item[0].I.IO.dwAddr / 0x10); | |
410 | DPRINTF("opening %s\n", ppdev); | |
411 | parportfd = open(ppdev, O_RDWR|O_EXCL); | |
412 | ||
413 | if (parportfd < 0) | |
414 | fprintf(stderr,"Can't open %s: %s\n", ppdev, strerror(errno)); | |
415 | } | |
19b2e286 | 416 | |
bccac33b | 417 | if (parportfd >= 0) { |
418 | int pmode; | |
19b2e286 | 419 | |
bccac33b | 420 | if (ioctl(parportfd, PPCLAIM) == -1) |
421 | return ret; | |
54357994 | 422 | |
bccac33b | 423 | ecpbase = 0; |
424 | pmode = IEEE1284_MODE_COMPAT; | |
425 | if (ioctl(parportfd, PPNEGOT, &pmode) == -1) | |
426 | return ret; | |
19b2e286 | 427 | |
bccac33b | 428 | if (cr->Card.dwItems > 1 && cr->Card.Item[1].I.IO.dwAddr) { |
429 | DPRINTF("ECP mode requested\n"); | |
430 | ecpbase = (unsigned long)cr->Card.Item[1].I.IO.dwAddr; | |
431 | /* TODO: Implement ECP mode */ | |
54357994 | 432 | #if 0 |
bccac33b | 433 | pmode = IEEE1284_MODE_ECP; |
54357994 | 434 | |
bccac33b | 435 | if (ioctl(parportfd, PPNEGOT, &pmode) == -1) { |
436 | ecpbase = 0; | |
437 | pmode = IEEE1284_MODE_COMPAT; | |
438 | if (ioctl(parportfd, PPNEGOT, &pmode) == -1) | |
439 | return ret; | |
440 | } | |
19b2e286 | 441 | #endif |
bccac33b | 442 | } |
443 | ||
444 | cr->hCard = parportfd; | |
54357994 | 445 | } |
19b2e286 | 446 | |
447 | ppbase = (unsigned long)cr->Card.Item[0].I.IO.dwAddr; | |
448 | if (ret < 0) | |
449 | cr->hCard = 0; | |
576995a8 | 450 | #endif |
ac9e3f59 | 451 | DPRINTF("hCard: %lu\n", cr->hCard); |
9c9fd67c | 452 | } |
da3ba95a | 453 | break; |
2c2119eb | 454 | |
da3ba95a | 455 | case USB_TRANSFER: |
f1405f13 | 456 | DPRINTF("in USB_TRANSFER"); |
da3ba95a | 457 | { |
458 | struct usb_transfer *ut = (struct usb_transfer*)(wdheader->data); | |
459 | ||
723d9aa0 | 460 | #ifdef DEBUG |
f1405f13 | 461 | DPRINTF(" unique: %lu, pipe: %lu, read: %lu, options: %lx, size: %lu, timeout: %lx\n", |
462 | ut->dwUniqueID, ut->dwPipeNum, ut->fRead, | |
463 | ut->dwOptions, ut->dwBufferSize, ut->dwTimeout); | |
464 | DPRINTF("setup packet: "); | |
9c9fd67c | 465 | hexdump(ut->SetupPacket, 8); |
723d9aa0 | 466 | |
9c9fd67c | 467 | if (!ut->fRead && ut->dwBufferSize) |
468 | { | |
469 | hexdump(ut->pBuffer, ut->dwBufferSize); | |
9c9fd67c | 470 | } |
723d9aa0 | 471 | #endif |
9c9fd67c | 472 | |
795992ad | 473 | #ifndef NO_WINDRVR |
9c9fd67c | 474 | ret = (*ioctl_func) (fd, request, wdioctl); |
411af373 | 475 | #else |
476 | /* http://www.jungo.com/support/documentation/windriver/802/wdusb_man_mhtml/node55.html#SECTION001213000000000000000 */ | |
a70f4f38 | 477 | if (ut->dwPipeNum == 0) { /* control pipe */ |
478 | int requesttype, request, value, index, size; | |
479 | requesttype = ut->SetupPacket[0]; | |
480 | request = ut->SetupPacket[1]; | |
481 | value = ut->SetupPacket[2] | (ut->SetupPacket[3] << 8); | |
482 | index = ut->SetupPacket[4] | (ut->SetupPacket[5] << 8); | |
483 | size = ut->SetupPacket[6] | (ut->SetupPacket[7] << 8); | |
f1405f13 | 484 | DPRINTF("requesttype: %x, request: %x, value: %u, index: %u, size: %u\n", requesttype, request, value, index, size); |
a70f4f38 | 485 | ret = usb_control_msg(usb_devhandle, requesttype, request, value, index, ut->pBuffer, size, ut->dwTimeout); |
486 | } else { | |
487 | if (ut->fRead) { | |
488 | ret = usb_bulk_read(usb_devhandle, ut->dwPipeNum, ut->pBuffer, ut->dwBufferSize, ut->dwTimeout); | |
489 | ||
490 | } else { | |
491 | ret = usb_bulk_write(usb_devhandle, ut->dwPipeNum, ut->pBuffer, ut->dwBufferSize, ut->dwTimeout); | |
492 | } | |
493 | } | |
494 | ||
411af373 | 495 | if (ret < 0) { |
a70f4f38 | 496 | fprintf(stderr, "usb_transfer: %d (%s)\n", ret, usb_strerror()); |
411af373 | 497 | } else { |
498 | ut->dwBytesTransferred = ret; | |
499 | ret = 0; | |
500 | } | |
292160ed | 501 | #endif |
9c9fd67c | 502 | |
723d9aa0 | 503 | #ifdef DEBUG |
f1405f13 | 504 | DPRINTF("Transferred: %lu (%s)\n",ut->dwBytesTransferred, (ut->fRead?"read":"write")); |
9c9fd67c | 505 | if (ut->fRead && ut->dwBytesTransferred) |
506 | { | |
f1405f13 | 507 | DPRINTF("Read: "); |
9c9fd67c | 508 | hexdump(ut->pBuffer, ut->dwBytesTransferred); |
509 | } | |
723d9aa0 | 510 | #endif |
da3ba95a | 511 | } |
cdc711dc | 512 | break; |
2c2119eb | 513 | |
f152c048 | 514 | case INT_ENABLE_OLD: |
da3ba95a | 515 | case INT_ENABLE: |
f1405f13 | 516 | DPRINTF("INT_ENABLE\n"); |
da3ba95a | 517 | { |
9c9fd67c | 518 | struct interrupt *it = (struct interrupt*)(wdheader->data); |
cdc711dc | 519 | |
f1405f13 | 520 | DPRINTF("Handle: %lu, Options: %lx, ncmds: %lu, enableok: %lu, count: %lu, lost: %lu, stopped: %lu\n", |
521 | it->hInterrupt, it->dwOptions, | |
522 | it->dwCmds, it->fEnableOk, it->dwCounter, | |
523 | it->dwLost, it->fStopped); | |
cdc711dc | 524 | |
9c9fd67c | 525 | it->fEnableOk = 1; |
9ba1e383 | 526 | it->fStopped = 0; |
ca18111b | 527 | ints_enabled = 1; |
533f4b68 | 528 | pthread_mutex_trylock(&int_wait); |
9c9fd67c | 529 | } |
cdc711dc | 530 | |
cdc711dc | 531 | break; |
9c9fd67c | 532 | |
da3ba95a | 533 | case INT_DISABLE: |
f1405f13 | 534 | DPRINTF("INT_DISABLE\n"); |
da3ba95a | 535 | { |
9c9fd67c | 536 | struct interrupt *it = (struct interrupt*)(wdheader->data); |
da3ba95a | 537 | |
f1405f13 | 538 | DPRINTF("Handle: %lu, Options: %lx, ncmds: %lu, enableok: %lu, count: %lu, lost: %lu, stopped: %lu\n", |
539 | it->hInterrupt, it->dwOptions, | |
540 | it->dwCmds, it->fEnableOk, it->dwCounter, | |
541 | it->dwLost, it->fStopped); | |
795992ad | 542 | #ifndef NO_WINDRVR |
9c9fd67c | 543 | ret = (*ioctl_func) (fd, request, wdioctl); |
e71b6bf3 | 544 | #else |
545 | it->dwCounter = 0; | |
546 | it->fStopped = 1; | |
ca18111b | 547 | ints_enabled = 0; |
9ba1e383 | 548 | if (pthread_mutex_trylock(&int_wait) == EBUSY) |
549 | pthread_mutex_unlock(&int_wait); | |
292160ed | 550 | #endif |
f1405f13 | 551 | DPRINTF("Handle: %lu, Options: %lx, ncmds: %lu, enableok: %lu, count: %lu, lost: %lu, stopped: %lu\n", |
552 | it->hInterrupt, it->dwOptions, | |
553 | it->dwCmds, it->fEnableOk, it->dwCounter, | |
554 | it->dwLost, it->fStopped); | |
da3ba95a | 555 | } |
da3ba95a | 556 | break; |
da3ba95a | 557 | |
9c9fd67c | 558 | case USB_SET_INTERFACE: |
f1405f13 | 559 | DPRINTF("USB_SET_INTERFACE\n"); |
da3ba95a | 560 | { |
9c9fd67c | 561 | struct usb_set_interface *usi = (struct usb_set_interface*)(wdheader->data); |
562 | ||
f1405f13 | 563 | DPRINTF("unique: %lu, interfacenum: %lu, alternatesetting: %lu, options: %lx\n", |
564 | usi->dwUniqueID, usi->dwInterfaceNum, | |
565 | usi->dwAlternateSetting, usi->dwOptions); | |
795992ad | 566 | #ifndef NO_WINDRVR |
9c9fd67c | 567 | ret = (*ioctl_func) (fd, request, wdioctl); |
2a7af812 | 568 | #else |
569 | if (usbdevice) { | |
2a7af812 | 570 | if (!usb_devhandle) |
571 | usb_devhandle = usb_open(usbdevice); | |
d0676964 | 572 | |
573 | /* FIXME: Select right interface! */ | |
574 | ret = usb_claim_interface(usb_devhandle, usbdevice->config[0].interface[usi->dwInterfaceNum].altsetting[usi->dwAlternateSetting].bInterfaceNumber); | |
575 | if (!ret) { | |
411af373 | 576 | if(!ret) { |
010cbaa6 | 577 | usbinterface = usbdevice->config[0].interface[usi->dwInterfaceNum].altsetting[usi->dwAlternateSetting].bInterfaceNumber; |
411af373 | 578 | ret = usb_set_altinterface(usb_devhandle, usi->dwAlternateSetting); |
579 | if (ret) | |
580 | fprintf(stderr, "usb_set_altinterface: %d\n", ret); | |
581 | } else { | |
582 | fprintf(stderr, "usb_set_configuration: %d (%s)\n", ret, usb_strerror()); | |
583 | } | |
d0676964 | 584 | } else { |
f1405f13 | 585 | fprintf(stderr, "usb_claim_interface: %d -> %d (%s)\n", |
586 | usbdevice->config[0].interface[usi->dwInterfaceNum].altsetting[usi->dwAlternateSetting].bInterfaceNumber, | |
587 | ret, usb_strerror()); | |
d0676964 | 588 | } |
2a7af812 | 589 | } |
292160ed | 590 | #endif |
f1405f13 | 591 | DPRINTF("unique: %lu, interfacenum: %lu, alternatesetting: %lu, options: %lx\n", |
592 | usi->dwUniqueID, usi->dwInterfaceNum, | |
593 | usi->dwAlternateSetting, usi->dwOptions); | |
da3ba95a | 594 | } |
cdc711dc | 595 | break; |
da3ba95a | 596 | |
f152c048 | 597 | case USB_GET_DEVICE_DATA_OLD: |
9c9fd67c | 598 | case USB_GET_DEVICE_DATA: |
f1405f13 | 599 | DPRINTF("USB_GET_DEVICE_DATA\n"); |
9c9fd67c | 600 | { |
601 | struct usb_get_device_data *ugdd = (struct usb_get_device_data*)(wdheader->data); | |
602 | int pSize; | |
603 | ||
f1405f13 | 604 | DPRINTF("unique: %lu, bytes: %lu, options: %lx\n", |
605 | ugdd->dwUniqueID, ugdd->dwBytes, | |
606 | ugdd->dwOptions); | |
607 | ||
9c9fd67c | 608 | pSize = ugdd->dwBytes; |
e71b6bf3 | 609 | if (!ugdd->dwBytes) { |
2a7af812 | 610 | if (usbdevice) { |
f95f1d2e | 611 | ugdd->dwBytes = usb_deviceinfo(NULL); |
e71b6bf3 | 612 | } |
613 | } else { | |
f95f1d2e | 614 | usb_deviceinfo((unsigned char*)ugdd->pBuf); |
e71b6bf3 | 615 | } |
da3ba95a | 616 | } |
9c9fd67c | 617 | break; |
618 | ||
f152c048 | 619 | case EVENT_REGISTER_OLD: |
b0f621dd | 620 | case EVENT_REGISTER: |
f1405f13 | 621 | DPRINTF("EVENT_REGISTER\n"); |
b0f621dd | 622 | { |
623 | struct event *e = (struct event*)(wdheader->data); | |
ac22d975 | 624 | struct usb_bus *bus; |
b0f621dd | 625 | int i; |
626 | ||
f1405f13 | 627 | DPRINTF("handle: %lu, action: %lu, status: %lu, eventid: %lu, cardtype: %lu, kplug: %lu, options: %lu, dev: %lx:%lx, unique: %lu, ver: %lu, nummatch: %lu\n", |
628 | e->handle, e->dwAction, | |
629 | e->dwStatus, e->dwEventId, e->dwCardType, | |
630 | e->hKernelPlugIn, e->dwOptions, | |
631 | e->u.Usb.deviceId.dwVendorId, | |
632 | e->u.Usb.deviceId.dwProductId, | |
633 | e->u.Usb.dwUniqueID, e->dwEventVer, | |
634 | e->dwNumMatchTables); | |
635 | ||
ac22d975 | 636 | for (i = 0; i < e->dwNumMatchTables; i++) { |
f1405f13 | 637 | |
638 | DPRINTF("match: dev: %04x:%04x, class: %x, subclass: %x, intclass: %x, intsubclass: %x, intproto: %x\n", | |
639 | e->matchTables[i].VendorId, | |
640 | e->matchTables[i].ProductId, | |
641 | e->matchTables[i].bDeviceClass, | |
642 | e->matchTables[i].bDeviceSubClass, | |
643 | e->matchTables[i].bInterfaceClass, | |
644 | e->matchTables[i].bInterfaceSubClass, | |
645 | e->matchTables[i].bInterfaceProtocol); | |
b0f621dd | 646 | |
ac22d975 | 647 | for (bus = busses; bus; bus = bus->next) { |
648 | struct usb_device *dev; | |
649 | ||
650 | for (dev = bus->devices; dev; dev = dev->next) { | |
651 | struct usb_device_descriptor *desc = &(dev->descriptor); | |
652 | ||
653 | if((desc->idVendor == e->matchTables[i].VendorId) && | |
654 | (desc->idProduct == e->matchTables[i].ProductId) && | |
655 | (desc->bDeviceClass == e->matchTables[i].bDeviceClass) && | |
656 | (desc->bDeviceSubClass == e->matchTables[i].bDeviceSubClass)) { | |
2a7af812 | 657 | int ac; |
658 | for (ac = 0; ac < desc->bNumConfigurations; ac++) { | |
659 | struct usb_interface *interface = dev->config[ac].interface; | |
660 | int ai; | |
661 | ||
662 | for (ai = 0; ai < interface->num_altsetting; ai++) { | |
f1405f13 | 663 | |
664 | DPRINTF("intclass: %x, intsubclass: %x, intproto: %x\n", | |
665 | interface->altsetting[i].bInterfaceClass, | |
666 | interface->altsetting[i].bInterfaceSubClass, | |
667 | interface->altsetting[i].bInterfaceProtocol); | |
668 | ||
2a7af812 | 669 | if ((interface->altsetting[ai].bInterfaceSubClass == e->matchTables[i].bInterfaceSubClass) && |
670 | (interface->altsetting[ai].bInterfaceProtocol == e->matchTables[i].bInterfaceProtocol)){ | |
671 | /* TODO: check interfaceClass! */ | |
f1405f13 | 672 | DPRINTF("found device with libusb\n"); |
2a7af812 | 673 | usbdevice = dev; |
674 | card_type = e->dwCardType; | |
675 | } | |
676 | } | |
677 | } | |
ac22d975 | 678 | } |
679 | } | |
680 | } | |
681 | } | |
682 | ||
795992ad | 683 | #ifndef NO_WINDRVR |
b0f621dd | 684 | ret = (*ioctl_func) (fd, request, wdioctl); |
2a7af812 | 685 | #else |
2a7af812 | 686 | e->handle++; |
292160ed | 687 | #endif |
b0f621dd | 688 | |
723d9aa0 | 689 | #ifdef DEBUG |
f1405f13 | 690 | DPRINTF("handle: %lu, action: %lu, status: %lu, eventid: %lu, cardtype: %lu, kplug: %lu, options: %lu, dev: %lx:%lx, unique: %lu, ver: %lu, nummatch: %lu\n", |
691 | e->handle, e->dwAction, | |
692 | e->dwStatus, e->dwEventId, e->dwCardType, | |
693 | e->hKernelPlugIn, e->dwOptions, | |
694 | e->u.Usb.deviceId.dwVendorId, | |
695 | e->u.Usb.deviceId.dwProductId, | |
696 | e->u.Usb.dwUniqueID, e->dwEventVer, | |
697 | e->dwNumMatchTables); | |
698 | ||
b0f621dd | 699 | for (i = 0; i < e->dwNumMatchTables; i++) |
f1405f13 | 700 | DPRINTF("match: dev: %04x:%04x, class: %x, subclass: %x, intclass: %x, intsubclass: %x, intproto: %x\n", |
701 | e->matchTables[i].VendorId, | |
702 | e->matchTables[i].ProductId, | |
703 | e->matchTables[i].bDeviceClass, | |
704 | e->matchTables[i].bDeviceSubClass, | |
705 | e->matchTables[i].bInterfaceClass, | |
706 | e->matchTables[i].bInterfaceSubClass, | |
707 | e->matchTables[i].bInterfaceProtocol); | |
723d9aa0 | 708 | #endif |
b0f621dd | 709 | } |
710 | break; | |
711 | ||
f152c048 | 712 | case TRANSFER_OLD: |
da3ba95a | 713 | case TRANSFER: |
f1405f13 | 714 | DPRINTF("TRANSFER\n"); |
ac9e3f59 | 715 | { |
716 | WD_TRANSFER *tr = (WD_TRANSFER*)(wdheader->data); | |
717 | ||
718 | ret = pp_transfer(tr, fd, request, wdioctl); | |
719 | } | |
9c9fd67c | 720 | break; |
721 | ||
54357994 | 722 | case MULTI_TRANSFER_OLD: |
576995a8 | 723 | case MULTI_TRANSFER: |
724 | DPRINTF("MULTI_TRANSFER\n"); | |
ac9e3f59 | 725 | { |
726 | WD_TRANSFER *tr = (WD_TRANSFER*)(wdheader->data); | |
727 | unsigned long num = wdheader->size/sizeof(WD_TRANSFER); | |
728 | int i; | |
729 | ||
ac9e3f59 | 730 | for (i = 0; i < num; i++) { |
731 | DPRINTF("Transfer %d:\n", i+1); | |
576995a8 | 732 | #ifndef NO_WINDRVR |
ac9e3f59 | 733 | wdheader->size = sizeof(WD_TRANSFER); |
734 | request = TRANSFER; | |
735 | wdheader->data = tr + i; | |
576995a8 | 736 | #endif |
ac9e3f59 | 737 | ret = pp_transfer(tr + i, fd, request, wdioctl); |
738 | } | |
739 | ||
740 | #ifndef NO_WINDRVR | |
741 | wdheader->data = tr; | |
742 | #endif | |
743 | ||
744 | return ret; | |
745 | } | |
576995a8 | 746 | break; |
747 | ||
da3ba95a | 748 | case EVENT_UNREGISTER: |
f1405f13 | 749 | DPRINTF("EVENT_UNREGISTER\n"); |
795992ad | 750 | #ifndef NO_WINDRVR |
9c9fd67c | 751 | ret = (*ioctl_func) (fd, request, wdioctl); |
292160ed | 752 | #endif |
9c9fd67c | 753 | break; |
754 | ||
da3ba95a | 755 | case INT_WAIT: |
f1405f13 | 756 | DPRINTF("INT_WAIT\n"); |
b0f621dd | 757 | { |
758 | struct interrupt *it = (struct interrupt*)(wdheader->data); | |
759 | ||
f1405f13 | 760 | DPRINTF("Handle: %lu, Options: %lx, ncmds: %lu, enableok: %lu, count: %lu, lost: %lu, stopped: %lu\n", |
761 | it->hInterrupt, it->dwOptions, | |
762 | it->dwCmds, it->fEnableOk, it->dwCounter, | |
763 | it->dwLost, it->fStopped); | |
b0f621dd | 764 | |
795992ad | 765 | #ifndef NO_WINDRVR |
b0f621dd | 766 | ret = (*ioctl_func) (fd, request, wdioctl); |
292160ed | 767 | #else |
2a7af812 | 768 | if (usbdevice) { |
769 | if (it->dwCounter == 0) { | |
770 | it->dwCounter = 1; | |
771 | } else { | |
533f4b68 | 772 | pthread_mutex_lock(&int_wait); |
be452175 | 773 | pthread_mutex_unlock(&int_wait); |
2a7af812 | 774 | } |
94038a57 | 775 | } else { |
533f4b68 | 776 | pthread_mutex_lock(&int_wait); |
be452175 | 777 | pthread_mutex_unlock(&int_wait); |
2a7af812 | 778 | } |
292160ed | 779 | #endif |
780 | ||
f1405f13 | 781 | DPRINTF("INT_WAIT_RETURN: Handle: %lu, Options: %lx, ncmds: %lu, enableok: %lu, count: %lu, lost: %lu, stopped: %lu\n", |
782 | it->hInterrupt, it->dwOptions, it->dwCmds, | |
783 | it->fEnableOk, it->dwCounter, it->dwLost, | |
784 | it->fStopped); | |
b0f621dd | 785 | } |
9c9fd67c | 786 | break; |
787 | ||
da3ba95a | 788 | case CARD_UNREGISTER: |
f1405f13 | 789 | DPRINTF("CARD_UNREGISTER\n"); |
54357994 | 790 | { |
791 | struct card_register* cr = (struct card_register*)(wdheader->data); | |
792 | ||
793 | DPRINTF("Addr: 0x%lx, bytes: %lu, bar: %lu\n", | |
794 | (unsigned long)cr->Card.Item[0].I.IO.dwAddr, | |
795 | cr->Card.Item[0].I.IO.dwBytes, | |
796 | cr->Card.Item[0].I.IO.dwBar); | |
797 | ||
798 | DPRINTF("hCard: %lu\n", cr->hCard); | |
799 | ||
795992ad | 800 | #ifndef NO_WINDRVR |
54357994 | 801 | ret = (*ioctl_func) (fd, request, wdioctl); |
802 | #else | |
803 | if (parportfd == cr->hCard && parportfd >= 0) { | |
804 | ioctl(parportfd, PPRELEASE); | |
805 | close(parportfd); | |
806 | parportfd = -1; | |
54357994 | 807 | } |
292160ed | 808 | #endif |
54357994 | 809 | } |
9c9fd67c | 810 | break; |
811 | ||
da3ba95a | 812 | case EVENT_PULL: |
f1405f13 | 813 | DPRINTF("EVENT_PULL\n"); |
b1831983 | 814 | { |
815 | struct event *e = (struct event*)(wdheader->data); | |
723d9aa0 | 816 | #ifdef DEBUG |
b1831983 | 817 | int i; |
818 | ||
f1405f13 | 819 | DPRINTF("handle: %lu, action: %lu, status: %lu, eventid: %lu, cardtype: %lx, kplug: %lu, options: %lu, dev: %lx:%lx, unique: %lu, ver: %lu, nummatch: %lu\n", |
820 | e->handle, e->dwAction, e->dwStatus, | |
821 | e->dwEventId, e->dwCardType, e->hKernelPlugIn, | |
822 | e->dwOptions, e->u.Usb.deviceId.dwVendorId, | |
823 | e->u.Usb.deviceId.dwProductId, | |
824 | e->u.Usb.dwUniqueID, e->dwEventVer, | |
825 | e->dwNumMatchTables); | |
826 | ||
b1831983 | 827 | for (i = 0; i < e->dwNumMatchTables; i++) |
f1405f13 | 828 | DPRINTF("match: dev: %04x:%04x, class: %x, subclass: %x, intclass: %x, intsubclass: %x, intproto: %x\n", |
829 | e->matchTables[i].VendorId, | |
830 | e->matchTables[i].ProductId, | |
831 | e->matchTables[i].bDeviceClass, | |
832 | e->matchTables[i].bDeviceSubClass, | |
833 | e->matchTables[i].bInterfaceClass, | |
834 | e->matchTables[i].bInterfaceSubClass, | |
835 | e->matchTables[i].bInterfaceProtocol); | |
723d9aa0 | 836 | #endif |
b1831983 | 837 | |
795992ad | 838 | #ifndef NO_WINDRVR |
b1831983 | 839 | ret = (*ioctl_func) (fd, request, wdioctl); |
292160ed | 840 | #else |
2a7af812 | 841 | if (usbdevice) { |
842 | struct usb_interface *interface = usbdevice->config->interface; | |
292160ed | 843 | |
844 | e->dwCardType = card_type; | |
845 | e->dwAction = 1; | |
846 | e->dwEventId = 109; | |
ca18111b | 847 | e->u.Usb.dwUniqueID = 110; |
2a7af812 | 848 | e->matchTables[0].VendorId = usbdevice->descriptor.idVendor; |
849 | e->matchTables[0].ProductId = usbdevice->descriptor.idProduct; | |
850 | e->matchTables[0].bDeviceClass = usbdevice->descriptor.bDeviceClass; | |
851 | e->matchTables[0].bDeviceSubClass = usbdevice->descriptor.bDeviceSubClass; | |
292160ed | 852 | e->matchTables[0].bInterfaceClass = interface->altsetting[0].bInterfaceClass; |
853 | e->matchTables[0].bInterfaceSubClass = interface->altsetting[0].bInterfaceSubClass; | |
854 | e->matchTables[0].bInterfaceProtocol = interface->altsetting[0].bInterfaceProtocol; | |
855 | } | |
856 | #endif | |
b1831983 | 857 | |
723d9aa0 | 858 | #ifdef DEBUG |
f1405f13 | 859 | DPRINTF("handle: %lu, action: %lu, status: %lu, eventid: %lu, cardtype: %lx, kplug: %lu, options: %lu, dev: %lx:%lx, unique: %lu, ver: %lu, nummatch: %lu\n", |
860 | e->handle, e->dwAction, e->dwStatus, | |
861 | e->dwEventId, e->dwCardType, e->hKernelPlugIn, | |
862 | e->dwOptions, e->u.Usb.deviceId.dwVendorId, | |
863 | e->u.Usb.deviceId.dwProductId, | |
864 | e->u.Usb.dwUniqueID, e->dwEventVer, | |
865 | e->dwNumMatchTables); | |
866 | ||
b1831983 | 867 | for (i = 0; i < e->dwNumMatchTables; i++) |
f1405f13 | 868 | DPRINTF("match: dev: %04x:%04x, class: %x, subclass: %x, intclass: %x, intsubclass: %x, intproto: %x\n", |
869 | e->matchTables[i].VendorId, | |
870 | e->matchTables[i].ProductId, | |
871 | e->matchTables[i].bDeviceClass, | |
872 | e->matchTables[i].bDeviceSubClass, | |
873 | e->matchTables[i].bInterfaceClass, | |
874 | e->matchTables[i].bInterfaceSubClass, | |
875 | e->matchTables[i].bInterfaceProtocol); | |
723d9aa0 | 876 | #endif |
ca18111b | 877 | |
b1831983 | 878 | } |
9c9fd67c | 879 | break; |
880 | ||
da3ba95a | 881 | default: |
292160ed | 882 | fprintf(stderr,"!!!Unsupported IOCTL: %x!!!\n", request); |
795992ad | 883 | #ifndef NO_WINDRVR |
9c9fd67c | 884 | ret = (*ioctl_func) (fd, request, wdioctl); |
292160ed | 885 | #endif |
886 | break; | |
cdc711dc | 887 | } |
da3ba95a | 888 | |
9c9fd67c | 889 | return ret; |
cdc711dc | 890 | } |
891 | ||
54357994 | 892 | int ioctl(int fd, unsigned long int request, ...) { |
dbda1264 | 893 | va_list args; |
894 | void *argp; | |
895 | int ret; | |
896 | ||
897 | if (!ioctl_func) | |
f1405f13 | 898 | ioctl_func = (int (*) (int, int, void *)) dlsym (RTLD_NEXT, "ioctl"); |
dbda1264 | 899 | |
900 | va_start (args, request); | |
901 | argp = va_arg (args, void *); | |
902 | va_end (args); | |
903 | ||
332ced7a | 904 | if (fd == windrvrfd) |
dbda1264 | 905 | ret = do_wdioctl(fd, request, argp); |
906 | else | |
907 | ret = (*ioctl_func) (fd, request, argp); | |
908 | ||
909 | return ret; | |
910 | } | |
cdc711dc | 911 | |
be452175 | 912 | int open (const char *pathname, int flags, ...) { |
913 | static int (*func) (const char *, int, mode_t) = NULL; | |
cdc711dc | 914 | mode_t mode = 0; |
915 | va_list args; | |
916 | int fd; | |
917 | ||
918 | if (!func) | |
f1405f13 | 919 | func = (int (*) (const char *, int, mode_t)) dlsym (RTLD_NEXT, "open"); |
cdc711dc | 920 | |
921 | if (flags & O_CREAT) { | |
922 | va_start(args, flags); | |
923 | mode = va_arg(args, mode_t); | |
924 | va_end(args); | |
925 | } | |
926 | ||
cdc711dc | 927 | if (!strcmp (pathname, "/dev/windrvr6")) { |
f1405f13 | 928 | DPRINTF("opening windrvr6\n"); |
795992ad | 929 | #ifdef NO_WINDRVR |
01b99d52 | 930 | windrvrfd = fd = (*func) ("/dev/null", flags, mode); |
931 | #else | |
932 | windrvrfd = fd = (*func) (pathname, flags, mode); | |
933 | #endif | |
f10480d1 | 934 | if (!busses) { |
935 | usb_init(); | |
936 | usb_find_busses(); | |
937 | usb_find_devices(); | |
938 | ||
939 | busses = usb_get_busses(); | |
940 | } | |
723d9aa0 | 941 | |
942 | return fd; | |
cdc711dc | 943 | } |
944 | ||
723d9aa0 | 945 | return (*func) (pathname, flags, mode); |
cdc711dc | 946 | } |
947 | ||
723d9aa0 | 948 | int close(int fd) { |
949 | static int (*func) (int) = NULL; | |
cdc711dc | 950 | |
723d9aa0 | 951 | if (!func) |
f1405f13 | 952 | func = (int (*) (int)) dlsym(RTLD_NEXT, "close"); |
723d9aa0 | 953 | |
11d01742 | 954 | if (fd == windrvrfd && windrvrfd >= 0) { |
f1405f13 | 955 | DPRINTF("close windrvrfd\n"); |
010cbaa6 | 956 | if (usbinterface >= 0) |
957 | usb_release_interface(usb_devhandle, usbinterface); | |
958 | ||
959 | if (usb_devhandle) | |
960 | usb_close(usb_devhandle); | |
961 | ||
962 | usb_devhandle = NULL; | |
963 | usbinterface = -1; | |
332ced7a | 964 | windrvrfd = -1; |
cdc711dc | 965 | } |
cdc711dc | 966 | |
723d9aa0 | 967 | return (*func) (fd); |
cdc711dc | 968 | } |
969 | ||
723d9aa0 | 970 | FILE *fopen(const char *path, const char *mode) { |
971 | FILE *ret; | |
972 | static FILE* (*func) (const char*, const char*) = NULL; | |
0dca330e | 973 | char buf[256]; |
974 | int i; | |
ca18111b | 975 | |
976 | if (!func) | |
f1405f13 | 977 | func = (FILE* (*) (const char*, const char*)) dlsym(RTLD_NEXT, "fopen"); |
ca18111b | 978 | |
19b2e286 | 979 | #ifdef JTAGKEY |
980 | /* FIXME: Hack for parport mapping */ | |
981 | if (!strcmp(path, "/proc/sys/dev/parport/parport3/base-addr")) { | |
982 | ret = (*func) ("/dev/null", mode); | |
983 | } else | |
984 | #endif | |
985 | ret = (*func) (path, mode); | |
ca18111b | 986 | |
0dca330e | 987 | if (!strcmp(path, "/proc/modules")) { |
f1405f13 | 988 | DPRINTF("opening /proc/modules\n"); |
723d9aa0 | 989 | #ifdef NO_WINDRVR |
dbda1264 | 990 | modulesfp = ret; |
723d9aa0 | 991 | modules_read = 0; |
992 | #endif | |
993 | } | |
0dca330e | 994 | |
995 | if (ret) { | |
996 | for (i = 0; i < 4; i++) { | |
997 | snprintf(buf, sizeof(buf), "/proc/sys/dev/parport/parport%d/base-addr", i); | |
998 | if (!strcmp(path, buf)) { | |
999 | DPRINTF("open base-addr of parport%d\n", i); | |
1000 | baseaddrfp = ret; | |
1001 | baseaddrnum = i; | |
1002 | } | |
1003 | } | |
1004 | } | |
cdc711dc | 1005 | |
1006 | return ret; | |
1007 | } | |
1008 | ||
dbda1264 | 1009 | char *fgets(char *s, int size, FILE *stream) { |
1010 | static char* (*func) (char*, int, FILE*) = NULL; | |
16f6b164 | 1011 | const char modules[][256] = {"windrvr6 1 0 - Live 0xdeadbeef\n", "parport_pc 1 0 - Live 0xdeadbeef\n"}; |
0dca330e | 1012 | char buf[256]; |
dbda1264 | 1013 | char *ret = NULL; |
1014 | ||
cdc711dc | 1015 | |
1016 | if (!func) | |
f1405f13 | 1017 | func = (char* (*) (char*, int, FILE*)) dlsym(RTLD_NEXT, "fgets"); |
723d9aa0 | 1018 | |
dbda1264 | 1019 | if (modulesfp == stream) { |
54357994 | 1020 | if (modules_read < sizeof(modules) / sizeof(modules[0])) { |
16f6b164 | 1021 | strcpy(s, modules[modules_read]); |
dbda1264 | 1022 | ret = s; |
16f6b164 | 1023 | modules_read++; |
dbda1264 | 1024 | } |
0dca330e | 1025 | } else if (baseaddrfp == stream) { |
1026 | snprintf(s, sizeof(buf), "%d\t%d\n", | |
1027 | (baseaddrnum) * 0x10, | |
1028 | ((baseaddrnum) * 0x10) + 0x400); | |
1029 | ret = s; | |
723d9aa0 | 1030 | } else { |
dbda1264 | 1031 | ret = (*func)(s,size,stream); |
723d9aa0 | 1032 | } |
cdc711dc | 1033 | |
1034 | return ret; | |
1035 | } | |
1036 | ||
dbda1264 | 1037 | int fclose(FILE *fp) { |
1038 | static int (*func) (FILE*) = NULL; | |
cdc711dc | 1039 | |
dbda1264 | 1040 | if (!func) |
f1405f13 | 1041 | func = (int (*) (FILE*)) dlsym(RTLD_NEXT, "fclose"); |
cdc711dc | 1042 | |
dbda1264 | 1043 | if (fp == modulesfp) { |
1044 | modulesfp = NULL; | |
1045 | } | |
0dca330e | 1046 | |
1047 | if (fp == baseaddrfp) { | |
1048 | baseaddrfp = NULL; | |
1049 | } | |
dbda1264 | 1050 | |
1051 | return (*func)(fp); | |
cdc711dc | 1052 | } |
419f2c98 | 1053 | |
1054 | int access(const char *pathname, int mode) { | |
1055 | static int (*func) (const char*, int); | |
1056 | ||
1057 | if (!func) | |
f1405f13 | 1058 | func = (int (*) (const char*, int)) dlsym(RTLD_NEXT, "access"); |
419f2c98 | 1059 | |
1060 | if (!strcmp(pathname, "/dev/windrvr6")) { | |
1061 | return 0; | |
1062 | } else { | |
1063 | return (*func)(pathname, mode); | |
1064 | } | |
1065 | } |