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