]>
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> |
2c0c1255 | 42 | #include "usb-driver.h" |
3e670223 | 43 | #include "config.h" |
cdc711dc | 44 | |
9c9fd67c | 45 | static int (*ioctl_func) (int, int, void *) = NULL; |
332ced7a | 46 | static int windrvrfd = -1; |
54357994 | 47 | static unsigned long ppbase = 0; |
48 | static unsigned long ecpbase = 0; | |
25ba7a49 | 49 | static struct parport_config *pport = NULL; |
332ced7a | 50 | FILE *modulesfp = NULL; |
0dca330e | 51 | FILE *baseaddrfp = NULL; |
52 | int baseaddrnum = 0; | |
723d9aa0 | 53 | static int modules_read = 0; |
f10480d1 | 54 | static struct usb_bus *busses = NULL; |
2a7af812 | 55 | static struct usb_device *usbdevice; |
56 | static usb_dev_handle *usb_devhandle = NULL; | |
010cbaa6 | 57 | static int usbinterface = -1; |
b72b86b4 | 58 | static unsigned long card_type; |
ca18111b | 59 | static int ints_enabled = 0; |
533f4b68 | 60 | static pthread_mutex_t int_wait = PTHREAD_MUTEX_INITIALIZER; |
292160ed | 61 | |
795992ad | 62 | #define NO_WINDRVR 1 |
723d9aa0 | 63 | |
64 | void hexdump(unsigned char *buf, int len) { | |
65 | int i; | |
66 | ||
67 | for(i=0; i<len; i++) { | |
68 | fprintf(stderr,"%02x ", buf[i]); | |
69 | if ((i % 16) == 15) | |
70 | fprintf(stderr,"\n"); | |
71 | } | |
f1405f13 | 72 | fprintf(stderr,"\n"); |
723d9aa0 | 73 | } |
cdc711dc | 74 | |
f95f1d2e | 75 | int usb_deviceinfo(unsigned char *buf) { |
76 | int i,j,k,l; | |
77 | int len = 0; | |
3664a3e3 | 78 | WDU_CONFIGURATION **pConfigs, **pActiveConfig; |
79 | WDU_INTERFACE **pActiveInterface; | |
f95f1d2e | 80 | |
81 | if (buf) { | |
82 | struct usb_device_info *udi = (struct usb_device_info*)(buf+len); | |
83 | ||
84 | udi->Descriptor.bLength = sizeof(WDU_DEVICE_DESCRIPTOR); | |
2a7af812 | 85 | udi->Descriptor.bDescriptorType = usbdevice->descriptor.bDescriptorType; |
86 | udi->Descriptor.bcdUSB = usbdevice->descriptor.bcdUSB; | |
87 | udi->Descriptor.bDeviceClass = usbdevice->descriptor.bDeviceClass; | |
88 | udi->Descriptor.bDeviceSubClass = usbdevice->descriptor.bDeviceSubClass; | |
89 | udi->Descriptor.bDeviceProtocol = usbdevice->descriptor.bDeviceProtocol; | |
90 | udi->Descriptor.bMaxPacketSize0 = usbdevice->descriptor.bMaxPacketSize0; | |
91 | udi->Descriptor.idVendor = usbdevice->descriptor.idVendor; | |
92 | udi->Descriptor.idProduct = usbdevice->descriptor.idProduct; | |
93 | udi->Descriptor.bcdDevice = usbdevice->descriptor.bcdDevice; | |
94 | udi->Descriptor.iManufacturer = usbdevice->descriptor.iManufacturer; | |
95 | udi->Descriptor.iProduct = usbdevice->descriptor.iProduct; | |
96 | udi->Descriptor.iSerialNumber = usbdevice->descriptor.iSerialNumber; | |
97 | udi->Descriptor.bNumConfigurations = usbdevice->descriptor.bNumConfigurations; | |
f95f1d2e | 98 | |
99 | /* TODO: Fix Pipe0! */ | |
100 | udi->Pipe0.dwNumber = 0x00; | |
2a7af812 | 101 | udi->Pipe0.dwMaximumPacketSize = usbdevice->descriptor.bMaxPacketSize0; |
f95f1d2e | 102 | udi->Pipe0.type = 0; |
8923df66 | 103 | udi->Pipe0.direction = WDU_DIR_IN_OUT; |
f95f1d2e | 104 | udi->Pipe0.dwInterval = 0; |
3664a3e3 | 105 | |
106 | pConfigs = &(udi->pConfigs); | |
107 | pActiveConfig = &(udi->pActiveConfig); | |
108 | pActiveInterface = &(udi->pActiveInterface[0]); | |
f95f1d2e | 109 | } |
110 | ||
111 | len = sizeof(struct usb_device_info); | |
112 | ||
2a7af812 | 113 | for (i=0; i<usbdevice->descriptor.bNumConfigurations; i++) |
f95f1d2e | 114 | { |
2a7af812 | 115 | struct usb_config_descriptor *conf_desc = &usbdevice->config[i]; |
3664a3e3 | 116 | WDU_INTERFACE **pInterfaces; |
117 | WDU_ALTERNATE_SETTING **pAlternateSettings[conf_desc->bNumInterfaces]; | |
118 | WDU_ALTERNATE_SETTING **pActiveAltSetting[conf_desc->bNumInterfaces]; | |
119 | ||
f95f1d2e | 120 | if (buf) { |
121 | WDU_CONFIGURATION *cfg = (WDU_CONFIGURATION*)(buf+len); | |
122 | ||
3664a3e3 | 123 | *pConfigs = cfg; |
124 | *pActiveConfig = cfg; | |
125 | ||
f95f1d2e | 126 | cfg->Descriptor.bLength = conf_desc->bLength; |
127 | cfg->Descriptor.bDescriptorType = conf_desc->bDescriptorType; | |
128 | cfg->Descriptor.wTotalLength = conf_desc->wTotalLength; | |
129 | cfg->Descriptor.bNumInterfaces = conf_desc->bNumInterfaces; | |
130 | cfg->Descriptor.bConfigurationValue = conf_desc->bConfigurationValue; | |
131 | cfg->Descriptor.iConfiguration = conf_desc->iConfiguration; | |
132 | cfg->Descriptor.bmAttributes = conf_desc->bmAttributes; | |
133 | cfg->Descriptor.MaxPower = conf_desc->MaxPower; | |
134 | ||
135 | cfg->dwNumInterfaces = conf_desc->bNumInterfaces; | |
3664a3e3 | 136 | |
137 | pInterfaces = &(cfg->pInterfaces); | |
f95f1d2e | 138 | } |
139 | len += sizeof(WDU_CONFIGURATION); | |
3664a3e3 | 140 | |
f95f1d2e | 141 | if (buf) { |
3664a3e3 | 142 | *pInterfaces = (WDU_INTERFACE*)(buf+len); |
f95f1d2e | 143 | for (j=0; j<conf_desc->bNumInterfaces; j++) { |
144 | WDU_INTERFACE *iface = (WDU_INTERFACE*)(buf+len); | |
3664a3e3 | 145 | |
146 | pActiveInterface[j] = iface; | |
147 | ||
148 | pAlternateSettings[j] = &(iface->pAlternateSettings); | |
2a7af812 | 149 | iface->dwNumAltSettings = usbdevice->config[i].interface[j].num_altsetting; |
3664a3e3 | 150 | pActiveAltSetting[j] = &(iface->pActiveAltSetting); |
f95f1d2e | 151 | |
152 | len += sizeof(WDU_INTERFACE); | |
153 | } | |
154 | } else { | |
155 | len += sizeof(WDU_INTERFACE) * conf_desc->bNumInterfaces; | |
156 | } | |
157 | ||
158 | for (j=0; j<conf_desc->bNumInterfaces; j++) | |
159 | { | |
2a7af812 | 160 | struct usb_interface *interface = &usbdevice->config[i].interface[j]; |
3664a3e3 | 161 | |
162 | if (buf) { | |
163 | *pAlternateSettings[j] = (WDU_ALTERNATE_SETTING*)(buf+len); | |
164 | /* FIXME: */ | |
165 | *pActiveAltSetting[j] = (WDU_ALTERNATE_SETTING*)(buf+len); | |
166 | } | |
167 | ||
f95f1d2e | 168 | for(k=0; k<interface->num_altsetting; k++) |
169 | { | |
3664a3e3 | 170 | unsigned char bNumEndpoints = interface->altsetting[k].bNumEndpoints; |
171 | WDU_ENDPOINT_DESCRIPTOR **pEndpointDescriptors; | |
172 | WDU_PIPE_INFO **pPipes; | |
173 | ||
f95f1d2e | 174 | if (buf) { |
175 | WDU_ALTERNATE_SETTING *altset = (WDU_ALTERNATE_SETTING*)(buf+len); | |
176 | ||
177 | altset->Descriptor.bLength = interface->altsetting[k].bLength; | |
178 | altset->Descriptor.bDescriptorType = interface->altsetting[k].bDescriptorType; | |
179 | altset->Descriptor.bInterfaceNumber = interface->altsetting[k].bInterfaceNumber; | |
180 | altset->Descriptor.bAlternateSetting = interface->altsetting[k].bAlternateSetting; | |
181 | altset->Descriptor.bNumEndpoints = interface->altsetting[k].bNumEndpoints; | |
182 | altset->Descriptor.bInterfaceClass = interface->altsetting[k].bInterfaceClass; | |
183 | altset->Descriptor.bInterfaceSubClass = interface->altsetting[k].bInterfaceSubClass; | |
184 | altset->Descriptor.bInterfaceProtocol = interface->altsetting[k].bInterfaceProtocol; | |
185 | altset->Descriptor.iInterface = interface->altsetting[k].iInterface; | |
3664a3e3 | 186 | pEndpointDescriptors = &(altset->pEndpointDescriptors); |
187 | pPipes = &(altset->pPipes); | |
f95f1d2e | 188 | |
189 | } | |
190 | len +=sizeof(WDU_ALTERNATE_SETTING); | |
191 | ||
192 | if (buf) { | |
3664a3e3 | 193 | *pEndpointDescriptors = (WDU_ENDPOINT_DESCRIPTOR*)(buf+len); |
f95f1d2e | 194 | for (l = 0; l < bNumEndpoints; l++) { |
195 | WDU_ENDPOINT_DESCRIPTOR *ed = (WDU_ENDPOINT_DESCRIPTOR*)(buf+len); | |
f95f1d2e | 196 | |
197 | ed->bLength = interface->altsetting[k].endpoint[l].bLength; | |
198 | ed->bDescriptorType = interface->altsetting[k].endpoint[l].bDescriptorType; | |
199 | ed->bEndpointAddress = interface->altsetting[k].endpoint[l].bEndpointAddress; | |
200 | ed->bmAttributes = interface->altsetting[k].endpoint[l].bmAttributes; | |
201 | ed->wMaxPacketSize = interface->altsetting[k].endpoint[l].wMaxPacketSize; | |
202 | ed->bInterval = interface->altsetting[k].endpoint[l].bInterval; | |
203 | ||
204 | len += sizeof(WDU_ENDPOINT_DESCRIPTOR); | |
792bf5f2 | 205 | } |
f95f1d2e | 206 | |
3664a3e3 | 207 | *pPipes = (WDU_PIPE_INFO*)(buf+len); |
792bf5f2 | 208 | for (l = 0; l < bNumEndpoints; l++) { |
209 | WDU_PIPE_INFO *pi = (WDU_PIPE_INFO*)(buf+len); | |
f95f1d2e | 210 | |
211 | pi->dwNumber = interface->altsetting[k].endpoint[l].bEndpointAddress; | |
212 | pi->dwMaximumPacketSize = WDU_GET_MAX_PACKET_SIZE(interface->altsetting[k].endpoint[l].wMaxPacketSize); | |
213 | pi->type = interface->altsetting[k].endpoint[l].bmAttributes & USB_ENDPOINT_TYPE_MASK; | |
214 | if (pi->type == PIPE_TYPE_CONTROL) | |
215 | pi->direction = WDU_DIR_IN_OUT; | |
216 | else | |
217 | { | |
218 | pi->direction = interface->altsetting[k].endpoint[l].bEndpointAddress & USB_ENDPOINT_DIR_MASK ? WDU_DIR_IN : WDU_DIR_OUT; | |
219 | } | |
220 | ||
221 | pi->dwInterval = interface->altsetting[k].endpoint[l].bInterval; | |
222 | ||
223 | len += sizeof(WDU_PIPE_INFO); | |
224 | } | |
225 | } else { | |
226 | len +=(sizeof(WDU_ENDPOINT_DESCRIPTOR)+sizeof(WDU_PIPE_INFO))*bNumEndpoints; | |
227 | } | |
228 | } | |
229 | } | |
230 | } | |
231 | ||
232 | return len; | |
233 | } | |
234 | ||
9c9fd67c | 235 | int do_wdioctl(int fd, unsigned int request, unsigned char *wdioctl) { |
cdc711dc | 236 | struct header_struct* wdheader = (struct header_struct*)wdioctl; |
9c9fd67c | 237 | struct version_struct *version; |
238 | int ret = 0; | |
cdc711dc | 239 | |
da3ba95a | 240 | if (wdheader->magic != MAGIC) { |
2c2119eb | 241 | fprintf(stderr,"!!!ERROR: magic header does not match!!!\n"); |
242 | return (*ioctl_func) (fd, request, wdioctl); | |
cdc711dc | 243 | } |
244 | ||
bdc65937 | 245 | switch(request & ~(0xc0000000)) { |
da3ba95a | 246 | case VERSION: |
9c9fd67c | 247 | version = (struct version_struct*)(wdheader->data); |
81cf3658 | 248 | strcpy(version->version, "libusb-driver.so version: " USB_DRIVER_VERSION); |
90831fba | 249 | version->versionul = 802; |
f1405f13 | 250 | DPRINTF("VERSION\n"); |
cdc711dc | 251 | break; |
2c2119eb | 252 | |
253 | case LICENSE: | |
f1405f13 | 254 | DPRINTF("LICENSE\n"); |
2c2119eb | 255 | break; |
256 | ||
f152c048 | 257 | case CARD_REGISTER_OLD: |
9c9fd67c | 258 | case CARD_REGISTER: |
54357994 | 259 | DPRINTF("CARD_REGISTER\n"); |
9c9fd67c | 260 | { |
533f4b68 | 261 | struct card_register* cr = (struct card_register*)(wdheader->data); |
54357994 | 262 | |
263 | DPRINTF("Items: %lu, Addr: 0x%lx, bytes: %lu, bar: %lu\n", | |
264 | cr->Card.dwItems, | |
265 | (unsigned long)cr->Card.Item[0].I.IO.dwAddr, | |
266 | cr->Card.Item[0].I.IO.dwBytes, | |
267 | cr->Card.Item[0].I.IO.dwBar); | |
268 | ||
269 | DPRINTF("Items: %lu, Addr: 0x%lx, bytes: %lu, bar: %lu\n", | |
270 | cr->Card.dwItems, | |
271 | (unsigned long)cr->Card.Item[1].I.IO.dwAddr, | |
272 | cr->Card.Item[1].I.IO.dwBytes, | |
273 | cr->Card.Item[1].I.IO.dwBar); | |
576995a8 | 274 | #ifndef NO_WINDRVR |
275 | ret = (*ioctl_func) (fd, request, wdioctl); | |
ac9e3f59 | 276 | #else |
bccac33b | 277 | |
25ba7a49 | 278 | pport = config_get((unsigned long)cr->Card.Item[0].I.IO.dwAddr / 0x10); |
61e0de7a | 279 | if (!pport) |
280 | break; | |
281 | ||
25ba7a49 | 282 | ret = pport->open((unsigned long)cr->Card.Item[0].I.IO.dwAddr / 0x10); |
3e670223 | 283 | |
5e3d963b | 284 | ppbase = (unsigned long)cr->Card.Item[0].I.IO.dwAddr; |
bccac33b | 285 | |
5e3d963b | 286 | if (cr->Card.dwItems > 1 && cr->Card.Item[1].I.IO.dwAddr) |
287 | ecpbase = (unsigned long)cr->Card.Item[1].I.IO.dwAddr; | |
19b2e286 | 288 | |
5e3d963b | 289 | if (ret >= 0) { |
290 | cr->hCard = ret; | |
291 | } else { | |
19b2e286 | 292 | cr->hCard = 0; |
5e3d963b | 293 | } |
576995a8 | 294 | #endif |
ac9e3f59 | 295 | DPRINTF("hCard: %lu\n", cr->hCard); |
9c9fd67c | 296 | } |
da3ba95a | 297 | break; |
2c2119eb | 298 | |
da3ba95a | 299 | case USB_TRANSFER: |
f1405f13 | 300 | DPRINTF("in USB_TRANSFER"); |
da3ba95a | 301 | { |
302 | struct usb_transfer *ut = (struct usb_transfer*)(wdheader->data); | |
303 | ||
723d9aa0 | 304 | #ifdef DEBUG |
f1405f13 | 305 | DPRINTF(" unique: %lu, pipe: %lu, read: %lu, options: %lx, size: %lu, timeout: %lx\n", |
306 | ut->dwUniqueID, ut->dwPipeNum, ut->fRead, | |
307 | ut->dwOptions, ut->dwBufferSize, ut->dwTimeout); | |
308 | DPRINTF("setup packet: "); | |
9c9fd67c | 309 | hexdump(ut->SetupPacket, 8); |
723d9aa0 | 310 | |
9c9fd67c | 311 | if (!ut->fRead && ut->dwBufferSize) |
312 | { | |
313 | hexdump(ut->pBuffer, ut->dwBufferSize); | |
9c9fd67c | 314 | } |
723d9aa0 | 315 | #endif |
9c9fd67c | 316 | |
795992ad | 317 | #ifndef NO_WINDRVR |
9c9fd67c | 318 | ret = (*ioctl_func) (fd, request, wdioctl); |
411af373 | 319 | #else |
320 | /* http://www.jungo.com/support/documentation/windriver/802/wdusb_man_mhtml/node55.html#SECTION001213000000000000000 */ | |
a70f4f38 | 321 | if (ut->dwPipeNum == 0) { /* control pipe */ |
322 | int requesttype, request, value, index, size; | |
323 | requesttype = ut->SetupPacket[0]; | |
324 | request = ut->SetupPacket[1]; | |
325 | value = ut->SetupPacket[2] | (ut->SetupPacket[3] << 8); | |
326 | index = ut->SetupPacket[4] | (ut->SetupPacket[5] << 8); | |
327 | size = ut->SetupPacket[6] | (ut->SetupPacket[7] << 8); | |
f1405f13 | 328 | DPRINTF("requesttype: %x, request: %x, value: %u, index: %u, size: %u\n", requesttype, request, value, index, size); |
a70f4f38 | 329 | ret = usb_control_msg(usb_devhandle, requesttype, request, value, index, ut->pBuffer, size, ut->dwTimeout); |
330 | } else { | |
331 | if (ut->fRead) { | |
332 | ret = usb_bulk_read(usb_devhandle, ut->dwPipeNum, ut->pBuffer, ut->dwBufferSize, ut->dwTimeout); | |
333 | ||
334 | } else { | |
335 | ret = usb_bulk_write(usb_devhandle, ut->dwPipeNum, ut->pBuffer, ut->dwBufferSize, ut->dwTimeout); | |
336 | } | |
337 | } | |
338 | ||
411af373 | 339 | if (ret < 0) { |
a70f4f38 | 340 | fprintf(stderr, "usb_transfer: %d (%s)\n", ret, usb_strerror()); |
411af373 | 341 | } else { |
342 | ut->dwBytesTransferred = ret; | |
343 | ret = 0; | |
344 | } | |
292160ed | 345 | #endif |
9c9fd67c | 346 | |
723d9aa0 | 347 | #ifdef DEBUG |
f1405f13 | 348 | DPRINTF("Transferred: %lu (%s)\n",ut->dwBytesTransferred, (ut->fRead?"read":"write")); |
9c9fd67c | 349 | if (ut->fRead && ut->dwBytesTransferred) |
350 | { | |
f1405f13 | 351 | DPRINTF("Read: "); |
9c9fd67c | 352 | hexdump(ut->pBuffer, ut->dwBytesTransferred); |
353 | } | |
723d9aa0 | 354 | #endif |
da3ba95a | 355 | } |
cdc711dc | 356 | break; |
2c2119eb | 357 | |
f152c048 | 358 | case INT_ENABLE_OLD: |
da3ba95a | 359 | case INT_ENABLE: |
f1405f13 | 360 | DPRINTF("INT_ENABLE\n"); |
da3ba95a | 361 | { |
9c9fd67c | 362 | struct interrupt *it = (struct interrupt*)(wdheader->data); |
cdc711dc | 363 | |
f1405f13 | 364 | DPRINTF("Handle: %lu, Options: %lx, ncmds: %lu, enableok: %lu, count: %lu, lost: %lu, stopped: %lu\n", |
365 | it->hInterrupt, it->dwOptions, | |
366 | it->dwCmds, it->fEnableOk, it->dwCounter, | |
367 | it->dwLost, it->fStopped); | |
cdc711dc | 368 | |
9c9fd67c | 369 | it->fEnableOk = 1; |
9ba1e383 | 370 | it->fStopped = 0; |
ca18111b | 371 | ints_enabled = 1; |
533f4b68 | 372 | pthread_mutex_trylock(&int_wait); |
9c9fd67c | 373 | } |
cdc711dc | 374 | |
cdc711dc | 375 | break; |
9c9fd67c | 376 | |
da3ba95a | 377 | case INT_DISABLE: |
f1405f13 | 378 | DPRINTF("INT_DISABLE\n"); |
da3ba95a | 379 | { |
9c9fd67c | 380 | struct interrupt *it = (struct interrupt*)(wdheader->data); |
da3ba95a | 381 | |
f1405f13 | 382 | DPRINTF("Handle: %lu, Options: %lx, ncmds: %lu, enableok: %lu, count: %lu, lost: %lu, stopped: %lu\n", |
383 | it->hInterrupt, it->dwOptions, | |
384 | it->dwCmds, it->fEnableOk, it->dwCounter, | |
385 | it->dwLost, it->fStopped); | |
795992ad | 386 | #ifndef NO_WINDRVR |
9c9fd67c | 387 | ret = (*ioctl_func) (fd, request, wdioctl); |
e71b6bf3 | 388 | #else |
389 | it->dwCounter = 0; | |
390 | it->fStopped = 1; | |
ca18111b | 391 | ints_enabled = 0; |
9ba1e383 | 392 | if (pthread_mutex_trylock(&int_wait) == EBUSY) |
393 | pthread_mutex_unlock(&int_wait); | |
292160ed | 394 | #endif |
f1405f13 | 395 | DPRINTF("Handle: %lu, Options: %lx, ncmds: %lu, enableok: %lu, count: %lu, lost: %lu, stopped: %lu\n", |
396 | it->hInterrupt, it->dwOptions, | |
397 | it->dwCmds, it->fEnableOk, it->dwCounter, | |
398 | it->dwLost, it->fStopped); | |
da3ba95a | 399 | } |
da3ba95a | 400 | break; |
da3ba95a | 401 | |
9c9fd67c | 402 | case USB_SET_INTERFACE: |
f1405f13 | 403 | DPRINTF("USB_SET_INTERFACE\n"); |
da3ba95a | 404 | { |
9c9fd67c | 405 | struct usb_set_interface *usi = (struct usb_set_interface*)(wdheader->data); |
406 | ||
f1405f13 | 407 | DPRINTF("unique: %lu, interfacenum: %lu, alternatesetting: %lu, options: %lx\n", |
408 | usi->dwUniqueID, usi->dwInterfaceNum, | |
409 | usi->dwAlternateSetting, usi->dwOptions); | |
795992ad | 410 | #ifndef NO_WINDRVR |
9c9fd67c | 411 | ret = (*ioctl_func) (fd, request, wdioctl); |
2a7af812 | 412 | #else |
413 | if (usbdevice) { | |
2a7af812 | 414 | if (!usb_devhandle) |
415 | usb_devhandle = usb_open(usbdevice); | |
d0676964 | 416 | |
417 | /* FIXME: Select right interface! */ | |
418 | ret = usb_claim_interface(usb_devhandle, usbdevice->config[0].interface[usi->dwInterfaceNum].altsetting[usi->dwAlternateSetting].bInterfaceNumber); | |
419 | if (!ret) { | |
411af373 | 420 | if(!ret) { |
010cbaa6 | 421 | usbinterface = usbdevice->config[0].interface[usi->dwInterfaceNum].altsetting[usi->dwAlternateSetting].bInterfaceNumber; |
411af373 | 422 | ret = usb_set_altinterface(usb_devhandle, usi->dwAlternateSetting); |
423 | if (ret) | |
424 | fprintf(stderr, "usb_set_altinterface: %d\n", ret); | |
425 | } else { | |
426 | fprintf(stderr, "usb_set_configuration: %d (%s)\n", ret, usb_strerror()); | |
427 | } | |
d0676964 | 428 | } else { |
f1405f13 | 429 | fprintf(stderr, "usb_claim_interface: %d -> %d (%s)\n", |
430 | usbdevice->config[0].interface[usi->dwInterfaceNum].altsetting[usi->dwAlternateSetting].bInterfaceNumber, | |
431 | ret, usb_strerror()); | |
d0676964 | 432 | } |
2a7af812 | 433 | } |
292160ed | 434 | #endif |
f1405f13 | 435 | DPRINTF("unique: %lu, interfacenum: %lu, alternatesetting: %lu, options: %lx\n", |
436 | usi->dwUniqueID, usi->dwInterfaceNum, | |
437 | usi->dwAlternateSetting, usi->dwOptions); | |
da3ba95a | 438 | } |
cdc711dc | 439 | break; |
da3ba95a | 440 | |
f152c048 | 441 | case USB_GET_DEVICE_DATA_OLD: |
9c9fd67c | 442 | case USB_GET_DEVICE_DATA: |
f1405f13 | 443 | DPRINTF("USB_GET_DEVICE_DATA\n"); |
9c9fd67c | 444 | { |
445 | struct usb_get_device_data *ugdd = (struct usb_get_device_data*)(wdheader->data); | |
446 | int pSize; | |
447 | ||
f1405f13 | 448 | DPRINTF("unique: %lu, bytes: %lu, options: %lx\n", |
449 | ugdd->dwUniqueID, ugdd->dwBytes, | |
450 | ugdd->dwOptions); | |
451 | ||
9c9fd67c | 452 | pSize = ugdd->dwBytes; |
e71b6bf3 | 453 | if (!ugdd->dwBytes) { |
2a7af812 | 454 | if (usbdevice) { |
f95f1d2e | 455 | ugdd->dwBytes = usb_deviceinfo(NULL); |
e71b6bf3 | 456 | } |
457 | } else { | |
f95f1d2e | 458 | usb_deviceinfo((unsigned char*)ugdd->pBuf); |
e71b6bf3 | 459 | } |
da3ba95a | 460 | } |
9c9fd67c | 461 | break; |
462 | ||
f152c048 | 463 | case EVENT_REGISTER_OLD: |
b0f621dd | 464 | case EVENT_REGISTER: |
f1405f13 | 465 | DPRINTF("EVENT_REGISTER\n"); |
b0f621dd | 466 | { |
467 | struct event *e = (struct event*)(wdheader->data); | |
ac22d975 | 468 | struct usb_bus *bus; |
3a2a22bc MG |
469 | char* devpos; |
470 | int busnum = -1, devnum = -1; | |
b0f621dd | 471 | int i; |
472 | ||
f1405f13 | 473 | 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", |
474 | e->handle, e->dwAction, | |
475 | e->dwStatus, e->dwEventId, e->dwCardType, | |
476 | e->hKernelPlugIn, e->dwOptions, | |
477 | e->u.Usb.deviceId.dwVendorId, | |
478 | e->u.Usb.deviceId.dwProductId, | |
479 | e->u.Usb.dwUniqueID, e->dwEventVer, | |
480 | e->dwNumMatchTables); | |
481 | ||
3a2a22bc MG |
482 | devpos = getenv("XILINX_USB_DEV"); |
483 | if (devpos != NULL) { | |
484 | int j; | |
485 | char *devstr = NULL, *remainder; | |
486 | ||
487 | DPRINTF("XILINX_USB_DEV=%s\n", devpos); | |
488 | ||
489 | for (j = 0; j < strlen(devpos) && devpos[j] != 0; j++) { | |
490 | if (devpos[j] == ':') { | |
491 | devpos[j] = 0; | |
492 | devstr = &(devpos[j+1]); | |
493 | } | |
494 | } | |
d377df04 | 495 | |
3a2a22bc MG |
496 | if (devstr && strlen(devstr) > 0) { |
497 | busnum = strtol(devpos, &remainder, 10); | |
498 | if (devpos == remainder) { | |
499 | busnum = -1; | |
500 | } else { | |
501 | devnum = strtol(devstr, &remainder, 10); | |
502 | if (devstr == remainder) { | |
503 | devnum = -1; | |
504 | } else { | |
505 | fprintf(stderr,"Using XILINX platform cable USB at %03d:%03d\n", | |
506 | busnum, devnum); | |
507 | } | |
508 | } | |
509 | } | |
510 | } | |
d377df04 | 511 | |
ac22d975 | 512 | for (i = 0; i < e->dwNumMatchTables; i++) { |
f1405f13 | 513 | |
514 | DPRINTF("match: dev: %04x:%04x, class: %x, subclass: %x, intclass: %x, intsubclass: %x, intproto: %x\n", | |
515 | e->matchTables[i].VendorId, | |
516 | e->matchTables[i].ProductId, | |
517 | e->matchTables[i].bDeviceClass, | |
518 | e->matchTables[i].bDeviceSubClass, | |
519 | e->matchTables[i].bInterfaceClass, | |
520 | e->matchTables[i].bInterfaceSubClass, | |
521 | e->matchTables[i].bInterfaceProtocol); | |
b0f621dd | 522 | |
ac22d975 | 523 | for (bus = busses; bus; bus = bus->next) { |
524 | struct usb_device *dev; | |
525 | ||
3a2a22bc MG |
526 | if ((devnum != -1) && (strtol(bus->dirname, NULL, 10) != busnum)) |
527 | continue; | |
528 | ||
ac22d975 | 529 | for (dev = bus->devices; dev; dev = dev->next) { |
530 | struct usb_device_descriptor *desc = &(dev->descriptor); | |
531 | ||
532 | if((desc->idVendor == e->matchTables[i].VendorId) && | |
533 | (desc->idProduct == e->matchTables[i].ProductId) && | |
534 | (desc->bDeviceClass == e->matchTables[i].bDeviceClass) && | |
d377df04 MG |
535 | (desc->bDeviceSubClass == e->matchTables[i].bDeviceSubClass) && |
536 | ((devnum == -1) || (dev->devnum == devnum)) ) { | |
2a7af812 | 537 | int ac; |
538 | for (ac = 0; ac < desc->bNumConfigurations; ac++) { | |
539 | struct usb_interface *interface = dev->config[ac].interface; | |
540 | int ai; | |
541 | ||
542 | for (ai = 0; ai < interface->num_altsetting; ai++) { | |
f1405f13 | 543 | |
544 | DPRINTF("intclass: %x, intsubclass: %x, intproto: %x\n", | |
545 | interface->altsetting[i].bInterfaceClass, | |
546 | interface->altsetting[i].bInterfaceSubClass, | |
547 | interface->altsetting[i].bInterfaceProtocol); | |
548 | ||
2a7af812 | 549 | if ((interface->altsetting[ai].bInterfaceSubClass == e->matchTables[i].bInterfaceSubClass) && |
550 | (interface->altsetting[ai].bInterfaceProtocol == e->matchTables[i].bInterfaceProtocol)){ | |
551 | /* TODO: check interfaceClass! */ | |
f1405f13 | 552 | DPRINTF("found device with libusb\n"); |
2a7af812 | 553 | usbdevice = dev; |
554 | card_type = e->dwCardType; | |
555 | } | |
556 | } | |
557 | } | |
ac22d975 | 558 | } |
559 | } | |
560 | } | |
561 | } | |
562 | ||
795992ad | 563 | #ifndef NO_WINDRVR |
b0f621dd | 564 | ret = (*ioctl_func) (fd, request, wdioctl); |
2a7af812 | 565 | #else |
2a7af812 | 566 | e->handle++; |
292160ed | 567 | #endif |
b0f621dd | 568 | |
723d9aa0 | 569 | #ifdef DEBUG |
f1405f13 | 570 | 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", |
571 | e->handle, e->dwAction, | |
572 | e->dwStatus, e->dwEventId, e->dwCardType, | |
573 | e->hKernelPlugIn, e->dwOptions, | |
574 | e->u.Usb.deviceId.dwVendorId, | |
575 | e->u.Usb.deviceId.dwProductId, | |
576 | e->u.Usb.dwUniqueID, e->dwEventVer, | |
577 | e->dwNumMatchTables); | |
578 | ||
b0f621dd | 579 | for (i = 0; i < e->dwNumMatchTables; i++) |
f1405f13 | 580 | DPRINTF("match: dev: %04x:%04x, class: %x, subclass: %x, intclass: %x, intsubclass: %x, intproto: %x\n", |
581 | e->matchTables[i].VendorId, | |
582 | e->matchTables[i].ProductId, | |
583 | e->matchTables[i].bDeviceClass, | |
584 | e->matchTables[i].bDeviceSubClass, | |
585 | e->matchTables[i].bInterfaceClass, | |
586 | e->matchTables[i].bInterfaceSubClass, | |
587 | e->matchTables[i].bInterfaceProtocol); | |
723d9aa0 | 588 | #endif |
b0f621dd | 589 | } |
590 | break; | |
591 | ||
f152c048 | 592 | case TRANSFER_OLD: |
da3ba95a | 593 | case TRANSFER: |
f1405f13 | 594 | DPRINTF("TRANSFER\n"); |
ac9e3f59 | 595 | { |
596 | WD_TRANSFER *tr = (WD_TRANSFER*)(wdheader->data); | |
597 | ||
1dac5195 | 598 | #ifndef NO_WINDRVR |
599 | ret = (*ioctl_func) (fd, request, wdioctl); | |
600 | #else | |
25ba7a49 | 601 | ret = pport->transfer(tr, fd, request, ppbase, ecpbase, 1); |
1dac5195 | 602 | #endif |
ac9e3f59 | 603 | } |
9c9fd67c | 604 | break; |
605 | ||
54357994 | 606 | case MULTI_TRANSFER_OLD: |
576995a8 | 607 | case MULTI_TRANSFER: |
608 | DPRINTF("MULTI_TRANSFER\n"); | |
ac9e3f59 | 609 | { |
610 | WD_TRANSFER *tr = (WD_TRANSFER*)(wdheader->data); | |
611 | unsigned long num = wdheader->size/sizeof(WD_TRANSFER); | |
1dac5195 | 612 | #ifndef NO_WINDRVR |
613 | ret = (*ioctl_func) (fd, request, wdioctl); | |
614 | #else | |
25ba7a49 | 615 | ret = pport->transfer(tr, fd, request, ppbase, ecpbase, num); |
ac9e3f59 | 616 | #endif |
ac9e3f59 | 617 | } |
576995a8 | 618 | break; |
619 | ||
da3ba95a | 620 | case EVENT_UNREGISTER: |
f1405f13 | 621 | DPRINTF("EVENT_UNREGISTER\n"); |
795992ad | 622 | #ifndef NO_WINDRVR |
9c9fd67c | 623 | ret = (*ioctl_func) (fd, request, wdioctl); |
292160ed | 624 | #endif |
9c9fd67c | 625 | break; |
626 | ||
da3ba95a | 627 | case INT_WAIT: |
f1405f13 | 628 | DPRINTF("INT_WAIT\n"); |
b0f621dd | 629 | { |
630 | struct interrupt *it = (struct interrupt*)(wdheader->data); | |
631 | ||
f1405f13 | 632 | DPRINTF("Handle: %lu, Options: %lx, ncmds: %lu, enableok: %lu, count: %lu, lost: %lu, stopped: %lu\n", |
633 | it->hInterrupt, it->dwOptions, | |
634 | it->dwCmds, it->fEnableOk, it->dwCounter, | |
635 | it->dwLost, it->fStopped); | |
b0f621dd | 636 | |
795992ad | 637 | #ifndef NO_WINDRVR |
b0f621dd | 638 | ret = (*ioctl_func) (fd, request, wdioctl); |
292160ed | 639 | #else |
2a7af812 | 640 | if (usbdevice) { |
641 | if (it->dwCounter == 0) { | |
642 | it->dwCounter = 1; | |
643 | } else { | |
533f4b68 | 644 | pthread_mutex_lock(&int_wait); |
be452175 | 645 | pthread_mutex_unlock(&int_wait); |
2a7af812 | 646 | } |
94038a57 | 647 | } else { |
533f4b68 | 648 | pthread_mutex_lock(&int_wait); |
be452175 | 649 | pthread_mutex_unlock(&int_wait); |
2a7af812 | 650 | } |
292160ed | 651 | #endif |
652 | ||
f1405f13 | 653 | DPRINTF("INT_WAIT_RETURN: Handle: %lu, Options: %lx, ncmds: %lu, enableok: %lu, count: %lu, lost: %lu, stopped: %lu\n", |
654 | it->hInterrupt, it->dwOptions, it->dwCmds, | |
655 | it->fEnableOk, it->dwCounter, it->dwLost, | |
656 | it->fStopped); | |
b0f621dd | 657 | } |
9c9fd67c | 658 | break; |
659 | ||
da3ba95a | 660 | case CARD_UNREGISTER: |
f1405f13 | 661 | DPRINTF("CARD_UNREGISTER\n"); |
54357994 | 662 | { |
663 | struct card_register* cr = (struct card_register*)(wdheader->data); | |
664 | ||
665 | DPRINTF("Addr: 0x%lx, bytes: %lu, bar: %lu\n", | |
666 | (unsigned long)cr->Card.Item[0].I.IO.dwAddr, | |
667 | cr->Card.Item[0].I.IO.dwBytes, | |
668 | cr->Card.Item[0].I.IO.dwBar); | |
669 | ||
670 | DPRINTF("hCard: %lu\n", cr->hCard); | |
671 | ||
795992ad | 672 | #ifndef NO_WINDRVR |
54357994 | 673 | ret = (*ioctl_func) (fd, request, wdioctl); |
674 | #else | |
72ce448b MG |
675 | if (pport) |
676 | pport->close(cr->hCard); | |
677 | ||
678 | pport = NULL; | |
292160ed | 679 | #endif |
54357994 | 680 | } |
9c9fd67c | 681 | break; |
682 | ||
da3ba95a | 683 | case EVENT_PULL: |
f1405f13 | 684 | DPRINTF("EVENT_PULL\n"); |
b1831983 | 685 | { |
686 | struct event *e = (struct event*)(wdheader->data); | |
723d9aa0 | 687 | #ifdef DEBUG |
b1831983 | 688 | int i; |
689 | ||
f1405f13 | 690 | 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", |
691 | e->handle, e->dwAction, e->dwStatus, | |
692 | e->dwEventId, e->dwCardType, e->hKernelPlugIn, | |
693 | e->dwOptions, e->u.Usb.deviceId.dwVendorId, | |
694 | e->u.Usb.deviceId.dwProductId, | |
695 | e->u.Usb.dwUniqueID, e->dwEventVer, | |
696 | e->dwNumMatchTables); | |
697 | ||
b1831983 | 698 | for (i = 0; i < e->dwNumMatchTables; i++) |
f1405f13 | 699 | DPRINTF("match: dev: %04x:%04x, class: %x, subclass: %x, intclass: %x, intsubclass: %x, intproto: %x\n", |
700 | e->matchTables[i].VendorId, | |
701 | e->matchTables[i].ProductId, | |
702 | e->matchTables[i].bDeviceClass, | |
703 | e->matchTables[i].bDeviceSubClass, | |
704 | e->matchTables[i].bInterfaceClass, | |
705 | e->matchTables[i].bInterfaceSubClass, | |
706 | e->matchTables[i].bInterfaceProtocol); | |
723d9aa0 | 707 | #endif |
b1831983 | 708 | |
795992ad | 709 | #ifndef NO_WINDRVR |
b1831983 | 710 | ret = (*ioctl_func) (fd, request, wdioctl); |
292160ed | 711 | #else |
2a7af812 | 712 | if (usbdevice) { |
713 | struct usb_interface *interface = usbdevice->config->interface; | |
292160ed | 714 | |
715 | e->dwCardType = card_type; | |
716 | e->dwAction = 1; | |
717 | e->dwEventId = 109; | |
ca18111b | 718 | e->u.Usb.dwUniqueID = 110; |
2a7af812 | 719 | e->matchTables[0].VendorId = usbdevice->descriptor.idVendor; |
720 | e->matchTables[0].ProductId = usbdevice->descriptor.idProduct; | |
721 | e->matchTables[0].bDeviceClass = usbdevice->descriptor.bDeviceClass; | |
722 | e->matchTables[0].bDeviceSubClass = usbdevice->descriptor.bDeviceSubClass; | |
292160ed | 723 | e->matchTables[0].bInterfaceClass = interface->altsetting[0].bInterfaceClass; |
724 | e->matchTables[0].bInterfaceSubClass = interface->altsetting[0].bInterfaceSubClass; | |
725 | e->matchTables[0].bInterfaceProtocol = interface->altsetting[0].bInterfaceProtocol; | |
726 | } | |
727 | #endif | |
b1831983 | 728 | |
723d9aa0 | 729 | #ifdef DEBUG |
f1405f13 | 730 | 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", |
731 | e->handle, e->dwAction, e->dwStatus, | |
732 | e->dwEventId, e->dwCardType, e->hKernelPlugIn, | |
733 | e->dwOptions, e->u.Usb.deviceId.dwVendorId, | |
734 | e->u.Usb.deviceId.dwProductId, | |
735 | e->u.Usb.dwUniqueID, e->dwEventVer, | |
736 | e->dwNumMatchTables); | |
737 | ||
b1831983 | 738 | for (i = 0; i < e->dwNumMatchTables; i++) |
f1405f13 | 739 | DPRINTF("match: dev: %04x:%04x, class: %x, subclass: %x, intclass: %x, intsubclass: %x, intproto: %x\n", |
740 | e->matchTables[i].VendorId, | |
741 | e->matchTables[i].ProductId, | |
742 | e->matchTables[i].bDeviceClass, | |
743 | e->matchTables[i].bDeviceSubClass, | |
744 | e->matchTables[i].bInterfaceClass, | |
745 | e->matchTables[i].bInterfaceSubClass, | |
746 | e->matchTables[i].bInterfaceProtocol); | |
723d9aa0 | 747 | #endif |
ca18111b | 748 | |
b1831983 | 749 | } |
9c9fd67c | 750 | break; |
751 | ||
da3ba95a | 752 | default: |
292160ed | 753 | fprintf(stderr,"!!!Unsupported IOCTL: %x!!!\n", request); |
795992ad | 754 | #ifndef NO_WINDRVR |
9c9fd67c | 755 | ret = (*ioctl_func) (fd, request, wdioctl); |
292160ed | 756 | #endif |
757 | break; | |
cdc711dc | 758 | } |
da3ba95a | 759 | |
9c9fd67c | 760 | return ret; |
cdc711dc | 761 | } |
762 | ||
54357994 | 763 | int ioctl(int fd, unsigned long int request, ...) { |
dbda1264 | 764 | va_list args; |
765 | void *argp; | |
766 | int ret; | |
767 | ||
768 | if (!ioctl_func) | |
f1405f13 | 769 | ioctl_func = (int (*) (int, int, void *)) dlsym (RTLD_NEXT, "ioctl"); |
dbda1264 | 770 | |
771 | va_start (args, request); | |
772 | argp = va_arg (args, void *); | |
773 | va_end (args); | |
774 | ||
332ced7a | 775 | if (fd == windrvrfd) |
dbda1264 | 776 | ret = do_wdioctl(fd, request, argp); |
777 | else | |
778 | ret = (*ioctl_func) (fd, request, argp); | |
779 | ||
780 | return ret; | |
781 | } | |
cdc711dc | 782 | |
be452175 | 783 | int open (const char *pathname, int flags, ...) { |
784 | static int (*func) (const char *, int, mode_t) = NULL; | |
cdc711dc | 785 | mode_t mode = 0; |
786 | va_list args; | |
787 | int fd; | |
788 | ||
789 | if (!func) | |
f1405f13 | 790 | func = (int (*) (const char *, int, mode_t)) dlsym (RTLD_NEXT, "open"); |
cdc711dc | 791 | |
792 | if (flags & O_CREAT) { | |
793 | va_start(args, flags); | |
794 | mode = va_arg(args, mode_t); | |
795 | va_end(args); | |
796 | } | |
797 | ||
cdc711dc | 798 | if (!strcmp (pathname, "/dev/windrvr6")) { |
f1405f13 | 799 | DPRINTF("opening windrvr6\n"); |
795992ad | 800 | #ifdef NO_WINDRVR |
01b99d52 | 801 | windrvrfd = fd = (*func) ("/dev/null", flags, mode); |
802 | #else | |
803 | windrvrfd = fd = (*func) (pathname, flags, mode); | |
804 | #endif | |
f10480d1 | 805 | if (!busses) { |
806 | usb_init(); | |
807 | usb_find_busses(); | |
808 | usb_find_devices(); | |
809 | ||
810 | busses = usb_get_busses(); | |
811 | } | |
723d9aa0 | 812 | |
813 | return fd; | |
cdc711dc | 814 | } |
815 | ||
723d9aa0 | 816 | return (*func) (pathname, flags, mode); |
cdc711dc | 817 | } |
818 | ||
723d9aa0 | 819 | int close(int fd) { |
820 | static int (*func) (int) = NULL; | |
cdc711dc | 821 | |
723d9aa0 | 822 | if (!func) |
f1405f13 | 823 | func = (int (*) (int)) dlsym(RTLD_NEXT, "close"); |
723d9aa0 | 824 | |
11d01742 | 825 | if (fd == windrvrfd && windrvrfd >= 0) { |
f1405f13 | 826 | DPRINTF("close windrvrfd\n"); |
010cbaa6 | 827 | if (usbinterface >= 0) |
828 | usb_release_interface(usb_devhandle, usbinterface); | |
829 | ||
830 | if (usb_devhandle) | |
831 | usb_close(usb_devhandle); | |
832 | ||
833 | usb_devhandle = NULL; | |
834 | usbinterface = -1; | |
332ced7a | 835 | windrvrfd = -1; |
cdc711dc | 836 | } |
cdc711dc | 837 | |
723d9aa0 | 838 | return (*func) (fd); |
cdc711dc | 839 | } |
840 | ||
723d9aa0 | 841 | FILE *fopen(const char *path, const char *mode) { |
842 | FILE *ret; | |
843 | static FILE* (*func) (const char*, const char*) = NULL; | |
0dca330e | 844 | char buf[256]; |
845 | int i; | |
ca18111b | 846 | |
847 | if (!func) | |
f1405f13 | 848 | func = (FILE* (*) (const char*, const char*)) dlsym(RTLD_NEXT, "fopen"); |
ca18111b | 849 | |
3e670223 | 850 | for (i = 0; i < 4; i++) { |
851 | snprintf(buf, sizeof(buf), "/proc/sys/dev/parport/parport%d/base-addr", i); | |
852 | if (!strcmp(path, buf)) { | |
853 | DPRINTF("open base-addr of parport%d\n", i); | |
854 | if (config_is_real_pport(i)) { | |
855 | ret = (*func) (path, mode); | |
856 | } else { | |
857 | ret = (*func) ("/dev/null", mode); | |
858 | } | |
859 | ||
860 | if (ret) { | |
861 | baseaddrfp = ret; | |
862 | baseaddrnum = i; | |
863 | } | |
864 | ||
865 | return ret; | |
866 | } | |
867 | } | |
868 | ||
869 | ret = (*func) (path, mode); | |
ca18111b | 870 | |
0dca330e | 871 | if (!strcmp(path, "/proc/modules")) { |
f1405f13 | 872 | DPRINTF("opening /proc/modules\n"); |
723d9aa0 | 873 | #ifdef NO_WINDRVR |
dbda1264 | 874 | modulesfp = ret; |
723d9aa0 | 875 | modules_read = 0; |
876 | #endif | |
877 | } | |
cdc711dc | 878 | |
879 | return ret; | |
880 | } | |
881 | ||
dbda1264 | 882 | char *fgets(char *s, int size, FILE *stream) { |
883 | static char* (*func) (char*, int, FILE*) = NULL; | |
16f6b164 | 884 | const char modules[][256] = {"windrvr6 1 0 - Live 0xdeadbeef\n", "parport_pc 1 0 - Live 0xdeadbeef\n"}; |
0dca330e | 885 | char buf[256]; |
dbda1264 | 886 | char *ret = NULL; |
887 | ||
cdc711dc | 888 | |
889 | if (!func) | |
f1405f13 | 890 | func = (char* (*) (char*, int, FILE*)) dlsym(RTLD_NEXT, "fgets"); |
723d9aa0 | 891 | |
dbda1264 | 892 | if (modulesfp == stream) { |
54357994 | 893 | if (modules_read < sizeof(modules) / sizeof(modules[0])) { |
16f6b164 | 894 | strcpy(s, modules[modules_read]); |
dbda1264 | 895 | ret = s; |
16f6b164 | 896 | modules_read++; |
dbda1264 | 897 | } |
0dca330e | 898 | } else if (baseaddrfp == stream) { |
899 | snprintf(s, sizeof(buf), "%d\t%d\n", | |
900 | (baseaddrnum) * 0x10, | |
901 | ((baseaddrnum) * 0x10) + 0x400); | |
902 | ret = s; | |
723d9aa0 | 903 | } else { |
dbda1264 | 904 | ret = (*func)(s,size,stream); |
723d9aa0 | 905 | } |
cdc711dc | 906 | |
907 | return ret; | |
908 | } | |
909 | ||
dbda1264 | 910 | int fclose(FILE *fp) { |
911 | static int (*func) (FILE*) = NULL; | |
cdc711dc | 912 | |
dbda1264 | 913 | if (!func) |
f1405f13 | 914 | func = (int (*) (FILE*)) dlsym(RTLD_NEXT, "fclose"); |
cdc711dc | 915 | |
dbda1264 | 916 | if (fp == modulesfp) { |
917 | modulesfp = NULL; | |
918 | } | |
0dca330e | 919 | |
920 | if (fp == baseaddrfp) { | |
921 | baseaddrfp = NULL; | |
922 | } | |
dbda1264 | 923 | |
924 | return (*func)(fp); | |
cdc711dc | 925 | } |
419f2c98 | 926 | |
927 | int access(const char *pathname, int mode) { | |
928 | static int (*func) (const char*, int); | |
929 | ||
930 | if (!func) | |
f1405f13 | 931 | func = (int (*) (const char*, int)) dlsym(RTLD_NEXT, "access"); |
3eee002c | 932 | |
b8b756f5 | 933 | if (pathname && !strcmp(pathname, "/dev/windrvr6")) { |
419f2c98 | 934 | return 0; |
935 | } else { | |
936 | return (*func)(pathname, mode); | |
937 | } | |
938 | } |