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