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