]> cvs.zerfleddert.de Git - usb-driver/blame - usb-driver.c
move card_type into xpcu_s
[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>
c42237a3
MG
42#include <sys/utsname.h>
43#include <bits/wordsize.h>
2c0c1255 44#include "usb-driver.h"
3e670223 45#include "config.h"
cbfa0ac6 46#include "xpcu.h"
cdc711dc 47
9c9fd67c 48static int (*ioctl_func) (int, int, void *) = NULL;
332ced7a 49static int windrvrfd = -1;
54357994 50static unsigned long ppbase = 0;
51static unsigned long ecpbase = 0;
25ba7a49 52static struct parport_config *pport = NULL;
cbfa0ac6 53static struct xpcu_s *xpcu = NULL;
be59993b
MG
54static FILE *modulesfp = NULL;
55static FILE *baseaddrfp = NULL;
56static int baseaddrnum = 0;
723d9aa0 57static int modules_read = 0;
ca18111b 58static int ints_enabled = 0;
533f4b68 59static pthread_mutex_t int_wait = PTHREAD_MUTEX_INITIALIZER;
292160ed 60
795992ad 61#define NO_WINDRVR 1
723d9aa0 62
63void hexdump(unsigned char *buf, int len) {
64 int i;
65
66 for(i=0; i<len; i++) {
67 fprintf(stderr,"%02x ", buf[i]);
68 if ((i % 16) == 15)
69 fprintf(stderr,"\n");
70 }
f1405f13 71 fprintf(stderr,"\n");
723d9aa0 72}
cdc711dc 73
cf55ed64 74
be59993b 75static int do_wdioctl(int fd, unsigned int request, unsigned char *wdioctl) {
cdc711dc 76 struct header_struct* wdheader = (struct header_struct*)wdioctl;
9c9fd67c 77 struct version_struct *version;
78 int ret = 0;
cdc711dc 79
da3ba95a 80 if (wdheader->magic != MAGIC) {
2c2119eb 81 fprintf(stderr,"!!!ERROR: magic header does not match!!!\n");
82 return (*ioctl_func) (fd, request, wdioctl);
cdc711dc 83 }
84
bdc65937 85 switch(request & ~(0xc0000000)) {
da3ba95a 86 case VERSION:
9c9fd67c 87 version = (struct version_struct*)(wdheader->data);
81cf3658 88 strcpy(version->version, "libusb-driver.so version: " USB_DRIVER_VERSION);
90831fba 89 version->versionul = 802;
f1405f13 90 DPRINTF("VERSION\n");
cdc711dc 91 break;
2c2119eb 92
93 case LICENSE:
f1405f13 94 DPRINTF("LICENSE\n");
2c2119eb 95 break;
96
f152c048 97 case CARD_REGISTER_OLD:
9c9fd67c 98 case CARD_REGISTER:
54357994 99 DPRINTF("CARD_REGISTER\n");
9c9fd67c 100 {
533f4b68 101 struct card_register* cr = (struct card_register*)(wdheader->data);
54357994 102
103 DPRINTF("Items: %lu, Addr: 0x%lx, bytes: %lu, bar: %lu\n",
104 cr->Card.dwItems,
105 (unsigned long)cr->Card.Item[0].I.IO.dwAddr,
106 cr->Card.Item[0].I.IO.dwBytes,
107 cr->Card.Item[0].I.IO.dwBar);
108
109 DPRINTF("Items: %lu, Addr: 0x%lx, bytes: %lu, bar: %lu\n",
110 cr->Card.dwItems,
111 (unsigned long)cr->Card.Item[1].I.IO.dwAddr,
112 cr->Card.Item[1].I.IO.dwBytes,
113 cr->Card.Item[1].I.IO.dwBar);
576995a8 114#ifndef NO_WINDRVR
115 ret = (*ioctl_func) (fd, request, wdioctl);
ac9e3f59 116#else
bccac33b 117
25ba7a49 118 pport = config_get((unsigned long)cr->Card.Item[0].I.IO.dwAddr / 0x10);
61e0de7a 119 if (!pport)
120 break;
121
25ba7a49 122 ret = pport->open((unsigned long)cr->Card.Item[0].I.IO.dwAddr / 0x10);
3e670223 123
5e3d963b 124 ppbase = (unsigned long)cr->Card.Item[0].I.IO.dwAddr;
bccac33b 125
5e3d963b 126 if (cr->Card.dwItems > 1 && cr->Card.Item[1].I.IO.dwAddr)
127 ecpbase = (unsigned long)cr->Card.Item[1].I.IO.dwAddr;
19b2e286 128
5e3d963b 129 if (ret >= 0) {
130 cr->hCard = ret;
131 } else {
19b2e286 132 cr->hCard = 0;
5e3d963b 133 }
576995a8 134#endif
ac9e3f59 135 DPRINTF("hCard: %lu\n", cr->hCard);
9c9fd67c 136 }
da3ba95a 137 break;
2c2119eb 138
da3ba95a 139 case USB_TRANSFER:
f1405f13 140 DPRINTF("in USB_TRANSFER");
da3ba95a 141 {
142 struct usb_transfer *ut = (struct usb_transfer*)(wdheader->data);
143
723d9aa0 144#ifdef DEBUG
f1405f13 145 DPRINTF(" unique: %lu, pipe: %lu, read: %lu, options: %lx, size: %lu, timeout: %lx\n",
146 ut->dwUniqueID, ut->dwPipeNum, ut->fRead,
147 ut->dwOptions, ut->dwBufferSize, ut->dwTimeout);
cf55ed64
MG
148 if (ut->dwPipeNum == 0) {
149 DPRINTF("setup packet: ");
150 hexdump(ut->SetupPacket, 8);
151 }
723d9aa0 152
9c9fd67c 153 if (!ut->fRead && ut->dwBufferSize)
154 {
155 hexdump(ut->pBuffer, ut->dwBufferSize);
9c9fd67c 156 }
723d9aa0 157#endif
9c9fd67c 158
795992ad 159#ifndef NO_WINDRVR
9c9fd67c 160 ret = (*ioctl_func) (fd, request, wdioctl);
411af373 161#else
6c235d59 162 xpcu_transfer(xpcu, ut);
292160ed 163#endif
9c9fd67c 164
723d9aa0 165#ifdef DEBUG
f1405f13 166 DPRINTF("Transferred: %lu (%s)\n",ut->dwBytesTransferred, (ut->fRead?"read":"write"));
9c9fd67c 167 if (ut->fRead && ut->dwBytesTransferred)
168 {
f1405f13 169 DPRINTF("Read: ");
9c9fd67c 170 hexdump(ut->pBuffer, ut->dwBytesTransferred);
171 }
723d9aa0 172#endif
da3ba95a 173 }
cdc711dc 174 break;
2c2119eb 175
f152c048 176 case INT_ENABLE_OLD:
da3ba95a 177 case INT_ENABLE:
f1405f13 178 DPRINTF("INT_ENABLE\n");
da3ba95a 179 {
9c9fd67c 180 struct interrupt *it = (struct interrupt*)(wdheader->data);
cdc711dc 181
f1405f13 182 DPRINTF("Handle: %lu, Options: %lx, ncmds: %lu, enableok: %lu, count: %lu, lost: %lu, stopped: %lu\n",
183 it->hInterrupt, it->dwOptions,
184 it->dwCmds, it->fEnableOk, it->dwCounter,
185 it->dwLost, it->fStopped);
cdc711dc 186
9c9fd67c 187 it->fEnableOk = 1;
9ba1e383 188 it->fStopped = 0;
ca18111b 189 ints_enabled = 1;
533f4b68 190 pthread_mutex_trylock(&int_wait);
9c9fd67c 191 }
cdc711dc 192
cdc711dc 193 break;
9c9fd67c 194
da3ba95a 195 case INT_DISABLE:
f1405f13 196 DPRINTF("INT_DISABLE\n");
da3ba95a 197 {
9c9fd67c 198 struct interrupt *it = (struct interrupt*)(wdheader->data);
da3ba95a 199
f1405f13 200 DPRINTF("Handle: %lu, Options: %lx, ncmds: %lu, enableok: %lu, count: %lu, lost: %lu, stopped: %lu\n",
201 it->hInterrupt, it->dwOptions,
202 it->dwCmds, it->fEnableOk, it->dwCounter,
203 it->dwLost, it->fStopped);
795992ad 204#ifndef NO_WINDRVR
9c9fd67c 205 ret = (*ioctl_func) (fd, request, wdioctl);
e71b6bf3 206#else
207 it->dwCounter = 0;
208 it->fStopped = 1;
ca18111b 209 ints_enabled = 0;
9ba1e383 210 if (pthread_mutex_trylock(&int_wait) == EBUSY)
211 pthread_mutex_unlock(&int_wait);
292160ed 212#endif
f1405f13 213 DPRINTF("Handle: %lu, Options: %lx, ncmds: %lu, enableok: %lu, count: %lu, lost: %lu, stopped: %lu\n",
214 it->hInterrupt, it->dwOptions,
215 it->dwCmds, it->fEnableOk, it->dwCounter,
216 it->dwLost, it->fStopped);
da3ba95a 217 }
da3ba95a 218 break;
da3ba95a 219
9c9fd67c 220 case USB_SET_INTERFACE:
f1405f13 221 DPRINTF("USB_SET_INTERFACE\n");
da3ba95a 222 {
9c9fd67c 223 struct usb_set_interface *usi = (struct usb_set_interface*)(wdheader->data);
224
f1405f13 225 DPRINTF("unique: %lu, interfacenum: %lu, alternatesetting: %lu, options: %lx\n",
226 usi->dwUniqueID, usi->dwInterfaceNum,
227 usi->dwAlternateSetting, usi->dwOptions);
795992ad 228#ifndef NO_WINDRVR
9c9fd67c 229 ret = (*ioctl_func) (fd, request, wdioctl);
2a7af812 230#else
0c2db148 231 xpcu_set_interface(xpcu, usi);
292160ed 232#endif
f1405f13 233 DPRINTF("unique: %lu, interfacenum: %lu, alternatesetting: %lu, options: %lx\n",
234 usi->dwUniqueID, usi->dwInterfaceNum,
235 usi->dwAlternateSetting, usi->dwOptions);
da3ba95a 236 }
cdc711dc 237 break;
da3ba95a 238
f152c048 239 case USB_GET_DEVICE_DATA_OLD:
9c9fd67c 240 case USB_GET_DEVICE_DATA:
f1405f13 241 DPRINTF("USB_GET_DEVICE_DATA\n");
9c9fd67c 242 {
243 struct usb_get_device_data *ugdd = (struct usb_get_device_data*)(wdheader->data);
244 int pSize;
245
f1405f13 246 DPRINTF("unique: %lu, bytes: %lu, options: %lx\n",
247 ugdd->dwUniqueID, ugdd->dwBytes,
248 ugdd->dwOptions);
249
9c9fd67c 250 pSize = ugdd->dwBytes;
e71b6bf3 251 if (!ugdd->dwBytes) {
cbfa0ac6
MG
252 if (xpcu->dev) {
253 ugdd->dwBytes = xpcu_deviceinfo(xpcu, NULL);
e71b6bf3 254 }
255 } else {
cbfa0ac6 256 xpcu_deviceinfo(xpcu, (unsigned char*)ugdd->pBuf);
e71b6bf3 257 }
da3ba95a 258 }
9c9fd67c 259 break;
260
f152c048 261 case EVENT_REGISTER_OLD:
b0f621dd 262 case EVENT_REGISTER:
f1405f13 263 DPRINTF("EVENT_REGISTER\n");
b0f621dd 264 {
265 struct event *e = (struct event*)(wdheader->data);
ac22d975 266 struct usb_bus *bus;
3a2a22bc
MG
267 char* devpos;
268 int busnum = -1, devnum = -1;
b0f621dd 269 int i;
270
f1405f13 271 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",
272 e->handle, e->dwAction,
273 e->dwStatus, e->dwEventId, e->dwCardType,
274 e->hKernelPlugIn, e->dwOptions,
275 e->u.Usb.deviceId.dwVendorId,
276 e->u.Usb.deviceId.dwProductId,
277 e->u.Usb.dwUniqueID, e->dwEventVer,
278 e->dwNumMatchTables);
279
3a2a22bc
MG
280 devpos = getenv("XILINX_USB_DEV");
281 if (devpos != NULL) {
282 int j;
283 char *devstr = NULL, *remainder;
284
285 DPRINTF("XILINX_USB_DEV=%s\n", devpos);
286
287 for (j = 0; j < strlen(devpos) && devpos[j] != 0; j++) {
288 if (devpos[j] == ':') {
289 devpos[j] = 0;
290 devstr = &(devpos[j+1]);
291 }
292 }
d377df04 293
3a2a22bc
MG
294 if (devstr && strlen(devstr) > 0) {
295 busnum = strtol(devpos, &remainder, 10);
296 if (devpos == remainder) {
297 busnum = -1;
298 } else {
299 devnum = strtol(devstr, &remainder, 10);
300 if (devstr == remainder) {
77683ab6 301 busnum = -1;
3a2a22bc
MG
302 devnum = -1;
303 } else {
304 fprintf(stderr,"Using XILINX platform cable USB at %03d:%03d\n",
305 busnum, devnum);
306 }
307 }
308 }
309 }
d377df04 310
ac22d975 311 for (i = 0; i < e->dwNumMatchTables; i++) {
f1405f13 312
313 DPRINTF("match: dev: %04x:%04x, class: %x, subclass: %x, intclass: %x, intsubclass: %x, intproto: %x\n",
314 e->matchTables[i].VendorId,
315 e->matchTables[i].ProductId,
316 e->matchTables[i].bDeviceClass,
317 e->matchTables[i].bDeviceSubClass,
318 e->matchTables[i].bInterfaceClass,
319 e->matchTables[i].bInterfaceSubClass,
320 e->matchTables[i].bInterfaceProtocol);
b0f621dd 321
cbfa0ac6 322 for (bus = xpcu->busses; bus; bus = bus->next) {
ac22d975 323 struct usb_device *dev;
324
3a2a22bc
MG
325 if ((devnum != -1) && (strtol(bus->dirname, NULL, 10) != busnum))
326 continue;
327
ac22d975 328 for (dev = bus->devices; dev; dev = dev->next) {
329 struct usb_device_descriptor *desc = &(dev->descriptor);
330
331 if((desc->idVendor == e->matchTables[i].VendorId) &&
332 (desc->idProduct == e->matchTables[i].ProductId) &&
333 (desc->bDeviceClass == e->matchTables[i].bDeviceClass) &&
d377df04 334 (desc->bDeviceSubClass == e->matchTables[i].bDeviceSubClass) &&
a2a952c0 335 ((devnum == -1) || (strtol(dev->filename, NULL, 10) == devnum)) ) {
2a7af812 336 int ac;
337 for (ac = 0; ac < desc->bNumConfigurations; ac++) {
338 struct usb_interface *interface = dev->config[ac].interface;
339 int ai;
340
341 for (ai = 0; ai < interface->num_altsetting; ai++) {
f1405f13 342
343 DPRINTF("intclass: %x, intsubclass: %x, intproto: %x\n",
344 interface->altsetting[i].bInterfaceClass,
345 interface->altsetting[i].bInterfaceSubClass,
346 interface->altsetting[i].bInterfaceProtocol);
347
2a7af812 348 if ((interface->altsetting[ai].bInterfaceSubClass == e->matchTables[i].bInterfaceSubClass) &&
349 (interface->altsetting[ai].bInterfaceProtocol == e->matchTables[i].bInterfaceProtocol)){
350 /* TODO: check interfaceClass! */
f1405f13 351 DPRINTF("found device with libusb\n");
cbfa0ac6 352 xpcu->dev = dev;
4f347185 353 xpcu->card_type = e->dwCardType;
2a7af812 354 }
355 }
356 }
ac22d975 357 }
358 }
359 }
360 }
361
795992ad 362#ifndef NO_WINDRVR
b0f621dd 363 ret = (*ioctl_func) (fd, request, wdioctl);
2a7af812 364#else
2a7af812 365 e->handle++;
292160ed 366#endif
b0f621dd 367
723d9aa0 368#ifdef DEBUG
f1405f13 369 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",
370 e->handle, e->dwAction,
371 e->dwStatus, e->dwEventId, e->dwCardType,
372 e->hKernelPlugIn, e->dwOptions,
373 e->u.Usb.deviceId.dwVendorId,
374 e->u.Usb.deviceId.dwProductId,
375 e->u.Usb.dwUniqueID, e->dwEventVer,
376 e->dwNumMatchTables);
377
b0f621dd 378 for (i = 0; i < e->dwNumMatchTables; i++)
f1405f13 379 DPRINTF("match: dev: %04x:%04x, class: %x, subclass: %x, intclass: %x, intsubclass: %x, intproto: %x\n",
380 e->matchTables[i].VendorId,
381 e->matchTables[i].ProductId,
382 e->matchTables[i].bDeviceClass,
383 e->matchTables[i].bDeviceSubClass,
384 e->matchTables[i].bInterfaceClass,
385 e->matchTables[i].bInterfaceSubClass,
386 e->matchTables[i].bInterfaceProtocol);
723d9aa0 387#endif
b0f621dd 388 }
389 break;
390
f152c048 391 case TRANSFER_OLD:
da3ba95a 392 case TRANSFER:
f1405f13 393 DPRINTF("TRANSFER\n");
ac9e3f59 394 {
395 WD_TRANSFER *tr = (WD_TRANSFER*)(wdheader->data);
396
1dac5195 397#ifndef NO_WINDRVR
398 ret = (*ioctl_func) (fd, request, wdioctl);
399#else
25ba7a49 400 ret = pport->transfer(tr, fd, request, ppbase, ecpbase, 1);
1dac5195 401#endif
ac9e3f59 402 }
9c9fd67c 403 break;
404
54357994 405 case MULTI_TRANSFER_OLD:
576995a8 406 case MULTI_TRANSFER:
407 DPRINTF("MULTI_TRANSFER\n");
ac9e3f59 408 {
409 WD_TRANSFER *tr = (WD_TRANSFER*)(wdheader->data);
410 unsigned long num = wdheader->size/sizeof(WD_TRANSFER);
1dac5195 411#ifndef NO_WINDRVR
412 ret = (*ioctl_func) (fd, request, wdioctl);
413#else
25ba7a49 414 ret = pport->transfer(tr, fd, request, ppbase, ecpbase, num);
ac9e3f59 415#endif
ac9e3f59 416 }
576995a8 417 break;
418
da3ba95a 419 case EVENT_UNREGISTER:
f1405f13 420 DPRINTF("EVENT_UNREGISTER\n");
795992ad 421#ifndef NO_WINDRVR
9c9fd67c 422 ret = (*ioctl_func) (fd, request, wdioctl);
292160ed 423#endif
9c9fd67c 424 break;
425
da3ba95a 426 case INT_WAIT:
f1405f13 427 DPRINTF("INT_WAIT\n");
b0f621dd 428 {
429 struct interrupt *it = (struct interrupt*)(wdheader->data);
430
f1405f13 431 DPRINTF("Handle: %lu, Options: %lx, ncmds: %lu, enableok: %lu, count: %lu, lost: %lu, stopped: %lu\n",
432 it->hInterrupt, it->dwOptions,
433 it->dwCmds, it->fEnableOk, it->dwCounter,
434 it->dwLost, it->fStopped);
b0f621dd 435
795992ad 436#ifndef NO_WINDRVR
b0f621dd 437 ret = (*ioctl_func) (fd, request, wdioctl);
292160ed 438#else
cbfa0ac6 439 if (xpcu->dev) {
2a7af812 440 if (it->dwCounter == 0) {
441 it->dwCounter = 1;
442 } else {
533f4b68 443 pthread_mutex_lock(&int_wait);
be452175 444 pthread_mutex_unlock(&int_wait);
2a7af812 445 }
94038a57 446 } else {
533f4b68 447 pthread_mutex_lock(&int_wait);
be452175 448 pthread_mutex_unlock(&int_wait);
2a7af812 449 }
292160ed 450#endif
451
f1405f13 452 DPRINTF("INT_WAIT_RETURN: Handle: %lu, Options: %lx, ncmds: %lu, enableok: %lu, count: %lu, lost: %lu, stopped: %lu\n",
453 it->hInterrupt, it->dwOptions, it->dwCmds,
454 it->fEnableOk, it->dwCounter, it->dwLost,
455 it->fStopped);
b0f621dd 456 }
9c9fd67c 457 break;
458
da3ba95a 459 case CARD_UNREGISTER:
f1405f13 460 DPRINTF("CARD_UNREGISTER\n");
54357994 461 {
462 struct card_register* cr = (struct card_register*)(wdheader->data);
463
464 DPRINTF("Addr: 0x%lx, bytes: %lu, bar: %lu\n",
465 (unsigned long)cr->Card.Item[0].I.IO.dwAddr,
466 cr->Card.Item[0].I.IO.dwBytes,
467 cr->Card.Item[0].I.IO.dwBar);
468
469 DPRINTF("hCard: %lu\n", cr->hCard);
470
795992ad 471#ifndef NO_WINDRVR
54357994 472 ret = (*ioctl_func) (fd, request, wdioctl);
473#else
72ce448b
MG
474 if (pport)
475 pport->close(cr->hCard);
476
477 pport = NULL;
292160ed 478#endif
54357994 479 }
9c9fd67c 480 break;
481
da3ba95a 482 case EVENT_PULL:
f1405f13 483 DPRINTF("EVENT_PULL\n");
b1831983 484 {
485 struct event *e = (struct event*)(wdheader->data);
723d9aa0 486#ifdef DEBUG
b1831983 487 int i;
488
f1405f13 489 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",
490 e->handle, e->dwAction, e->dwStatus,
491 e->dwEventId, e->dwCardType, e->hKernelPlugIn,
492 e->dwOptions, e->u.Usb.deviceId.dwVendorId,
493 e->u.Usb.deviceId.dwProductId,
494 e->u.Usb.dwUniqueID, e->dwEventVer,
495 e->dwNumMatchTables);
496
b1831983 497 for (i = 0; i < e->dwNumMatchTables; i++)
f1405f13 498 DPRINTF("match: dev: %04x:%04x, class: %x, subclass: %x, intclass: %x, intsubclass: %x, intproto: %x\n",
499 e->matchTables[i].VendorId,
500 e->matchTables[i].ProductId,
501 e->matchTables[i].bDeviceClass,
502 e->matchTables[i].bDeviceSubClass,
503 e->matchTables[i].bInterfaceClass,
504 e->matchTables[i].bInterfaceSubClass,
505 e->matchTables[i].bInterfaceProtocol);
723d9aa0 506#endif
b1831983 507
795992ad 508#ifndef NO_WINDRVR
b1831983 509 ret = (*ioctl_func) (fd, request, wdioctl);
292160ed 510#else
cbfa0ac6
MG
511 if (xpcu->dev) {
512 struct usb_interface *interface = xpcu->dev->config->interface;
292160ed 513
4f347185 514 e->dwCardType = xpcu->card_type;
292160ed 515 e->dwAction = 1;
516 e->dwEventId = 109;
ca18111b 517 e->u.Usb.dwUniqueID = 110;
cbfa0ac6
MG
518 e->matchTables[0].VendorId = xpcu->dev->descriptor.idVendor;
519 e->matchTables[0].ProductId = xpcu->dev->descriptor.idProduct;
520 e->matchTables[0].bDeviceClass = xpcu->dev->descriptor.bDeviceClass;
521 e->matchTables[0].bDeviceSubClass = xpcu->dev->descriptor.bDeviceSubClass;
292160ed 522 e->matchTables[0].bInterfaceClass = interface->altsetting[0].bInterfaceClass;
523 e->matchTables[0].bInterfaceSubClass = interface->altsetting[0].bInterfaceSubClass;
524 e->matchTables[0].bInterfaceProtocol = interface->altsetting[0].bInterfaceProtocol;
525 }
526#endif
b1831983 527
723d9aa0 528#ifdef DEBUG
f1405f13 529 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",
530 e->handle, e->dwAction, e->dwStatus,
531 e->dwEventId, e->dwCardType, e->hKernelPlugIn,
532 e->dwOptions, e->u.Usb.deviceId.dwVendorId,
533 e->u.Usb.deviceId.dwProductId,
534 e->u.Usb.dwUniqueID, e->dwEventVer,
535 e->dwNumMatchTables);
536
b1831983 537 for (i = 0; i < e->dwNumMatchTables; i++)
f1405f13 538 DPRINTF("match: dev: %04x:%04x, class: %x, subclass: %x, intclass: %x, intsubclass: %x, intproto: %x\n",
539 e->matchTables[i].VendorId,
540 e->matchTables[i].ProductId,
541 e->matchTables[i].bDeviceClass,
542 e->matchTables[i].bDeviceSubClass,
543 e->matchTables[i].bInterfaceClass,
544 e->matchTables[i].bInterfaceSubClass,
545 e->matchTables[i].bInterfaceProtocol);
723d9aa0 546#endif
ca18111b 547
b1831983 548 }
9c9fd67c 549 break;
550
da3ba95a 551 default:
292160ed 552 fprintf(stderr,"!!!Unsupported IOCTL: %x!!!\n", request);
795992ad 553#ifndef NO_WINDRVR
9c9fd67c 554 ret = (*ioctl_func) (fd, request, wdioctl);
292160ed 555#endif
556 break;
cdc711dc 557 }
da3ba95a 558
9c9fd67c 559 return ret;
cdc711dc 560}
561
54357994 562int ioctl(int fd, unsigned long int request, ...) {
dbda1264 563 va_list args;
564 void *argp;
565 int ret;
566
567 if (!ioctl_func)
f1405f13 568 ioctl_func = (int (*) (int, int, void *)) dlsym (RTLD_NEXT, "ioctl");
dbda1264 569
570 va_start (args, request);
571 argp = va_arg (args, void *);
572 va_end (args);
573
332ced7a 574 if (fd == windrvrfd)
dbda1264 575 ret = do_wdioctl(fd, request, argp);
576 else
577 ret = (*ioctl_func) (fd, request, argp);
578
579 return ret;
580}
cdc711dc 581
be452175 582int open (const char *pathname, int flags, ...) {
583 static int (*func) (const char *, int, mode_t) = NULL;
cdc711dc 584 mode_t mode = 0;
585 va_list args;
586 int fd;
587
588 if (!func)
f1405f13 589 func = (int (*) (const char *, int, mode_t)) dlsym (RTLD_NEXT, "open");
cdc711dc 590
591 if (flags & O_CREAT) {
592 va_start(args, flags);
593 mode = va_arg(args, mode_t);
594 va_end(args);
595 }
596
cdc711dc 597 if (!strcmp (pathname, "/dev/windrvr6")) {
f1405f13 598 DPRINTF("opening windrvr6\n");
795992ad 599#ifdef NO_WINDRVR
01b99d52 600 windrvrfd = fd = (*func) ("/dev/null", flags, mode);
601#else
602 windrvrfd = fd = (*func) (pathname, flags, mode);
603#endif
cbfa0ac6
MG
604 if (!xpcu)
605 xpcu = xpcu_open();
723d9aa0 606
607 return fd;
cdc711dc 608 }
609
723d9aa0 610 return (*func) (pathname, flags, mode);
cdc711dc 611}
612
723d9aa0 613int close(int fd) {
614 static int (*func) (int) = NULL;
cdc711dc 615
723d9aa0 616 if (!func)
f1405f13 617 func = (int (*) (int)) dlsym(RTLD_NEXT, "close");
723d9aa0 618
11d01742 619 if (fd == windrvrfd && windrvrfd >= 0) {
f1405f13 620 DPRINTF("close windrvrfd\n");
010cbaa6 621
6234190b
MG
622 if (xpcu)
623 xpcu_close(xpcu);
010cbaa6 624
cbfa0ac6 625 xpcu = NULL;
332ced7a 626 windrvrfd = -1;
cdc711dc 627 }
cdc711dc 628
723d9aa0 629 return (*func) (fd);
cdc711dc 630}
631
723d9aa0 632FILE *fopen(const char *path, const char *mode) {
633 FILE *ret;
634 static FILE* (*func) (const char*, const char*) = NULL;
0dca330e 635 char buf[256];
636 int i;
ca18111b 637
638 if (!func)
f1405f13 639 func = (FILE* (*) (const char*, const char*)) dlsym(RTLD_NEXT, "fopen");
ca18111b 640
3e670223 641 for (i = 0; i < 4; i++) {
642 snprintf(buf, sizeof(buf), "/proc/sys/dev/parport/parport%d/base-addr", i);
643 if (!strcmp(path, buf)) {
644 DPRINTF("open base-addr of parport%d\n", i);
645 if (config_is_real_pport(i)) {
646 ret = (*func) (path, mode);
647 } else {
648 ret = (*func) ("/dev/null", mode);
649 }
650
651 if (ret) {
652 baseaddrfp = ret;
653 baseaddrnum = i;
654 }
655
656 return ret;
657 }
658 }
659
660 ret = (*func) (path, mode);
ca18111b 661
0dca330e 662 if (!strcmp(path, "/proc/modules")) {
f1405f13 663 DPRINTF("opening /proc/modules\n");
723d9aa0 664#ifdef NO_WINDRVR
dbda1264 665 modulesfp = ret;
723d9aa0 666 modules_read = 0;
667#endif
668 }
cdc711dc 669
670 return ret;
671}
672
dbda1264 673char *fgets(char *s, int size, FILE *stream) {
674 static char* (*func) (char*, int, FILE*) = NULL;
16f6b164 675 const char modules[][256] = {"windrvr6 1 0 - Live 0xdeadbeef\n", "parport_pc 1 0 - Live 0xdeadbeef\n"};
0dca330e 676 char buf[256];
dbda1264 677 char *ret = NULL;
678
cdc711dc 679
680 if (!func)
f1405f13 681 func = (char* (*) (char*, int, FILE*)) dlsym(RTLD_NEXT, "fgets");
723d9aa0 682
dbda1264 683 if (modulesfp == stream) {
54357994 684 if (modules_read < sizeof(modules) / sizeof(modules[0])) {
16f6b164 685 strcpy(s, modules[modules_read]);
dbda1264 686 ret = s;
16f6b164 687 modules_read++;
dbda1264 688 }
0dca330e 689 } else if (baseaddrfp == stream) {
690 snprintf(s, sizeof(buf), "%d\t%d\n",
691 (baseaddrnum) * 0x10,
692 ((baseaddrnum) * 0x10) + 0x400);
693 ret = s;
723d9aa0 694 } else {
dbda1264 695 ret = (*func)(s,size,stream);
723d9aa0 696 }
cdc711dc 697
698 return ret;
699}
700
dbda1264 701int fclose(FILE *fp) {
702 static int (*func) (FILE*) = NULL;
cdc711dc 703
dbda1264 704 if (!func)
f1405f13 705 func = (int (*) (FILE*)) dlsym(RTLD_NEXT, "fclose");
cdc711dc 706
dbda1264 707 if (fp == modulesfp) {
708 modulesfp = NULL;
709 }
0dca330e 710
711 if (fp == baseaddrfp) {
712 baseaddrfp = NULL;
713 }
dbda1264 714
715 return (*func)(fp);
cdc711dc 716}
419f2c98 717
718int access(const char *pathname, int mode) {
719 static int (*func) (const char*, int);
720
721 if (!func)
f1405f13 722 func = (int (*) (const char*, int)) dlsym(RTLD_NEXT, "access");
3eee002c 723
b8b756f5 724 if (pathname && !strcmp(pathname, "/dev/windrvr6")) {
419f2c98 725 return 0;
726 } else {
727 return (*func)(pathname, mode);
728 }
729}
c42237a3
MG
730
731#if __WORDSIZE == 32
732int uname (struct utsname *__name) {
733 static int (*func) (struct utsname*);
734 int ret;
735
736 if (!func)
737 func = (int (*) (struct utsname*)) dlsym(RTLD_NEXT, "uname");
738
739 ret = (*func)(__name);
740
741 if (ret == 0 && (!strcmp(__name->machine, "x86_64"))) {
742 strcpy(__name->machine, "i686");
743 }
744
745 return ret;
746}
747#endif
Impressum, Datenschutz