X-Git-Url: http://cvs.zerfleddert.de/cgi-bin/gitweb.cgi/usb-driver/blobdiff_plain/1f62c14e4f95d8a27377b558676d78ccb9d522c3..0dca330e46ffe5fe5dc5973af026f83b4d06be01:/usb-driver.c diff --git a/usb-driver.c b/usb-driver.c index a7d14bf..bdf3350 100644 --- a/usb-driver.c +++ b/usb-driver.c @@ -46,10 +46,11 @@ static int (*ioctl_func) (int, int, void *) = NULL; static int windrvrfd = -1; static int parportfd = -1; -static int parportnum = 0; static unsigned long ppbase = 0; static unsigned long ecpbase = 0; FILE *modulesfp = NULL; +FILE *baseaddrfp = NULL; +int baseaddrnum = 0; static int modules_read = 0; static struct usb_bus *busses = NULL; static struct usb_device *usbdevice; @@ -241,6 +242,7 @@ int pp_transfer(WD_TRANSFER *tr, int fd, unsigned int request, unsigned char *wd int ret = 0; unsigned long port = (unsigned long)tr->dwPort; unsigned char val; + static int last_pp_write = 0; DPRINTF("dwPort: 0x%lx, cmdTrans: %lu, dwbytes: %ld, fautoinc: %ld, dwoptions: %ld\n", (unsigned long)tr->dwPort, tr->cmdTrans, tr->dwBytes, @@ -268,6 +270,7 @@ int pp_transfer(WD_TRANSFER *tr, int fd, unsigned int request, unsigned char *wd case PP_WRITE: ret = ioctl(parportfd, PPWDATA, &val); + last_pp_write = val; break; default: @@ -276,10 +279,17 @@ int pp_transfer(WD_TRANSFER *tr, int fd, unsigned int request, unsigned char *wd break; } } else if (port == ppbase + PP_STATUS) { - DPRINTF("status port\n"); + DPRINTF("status port (last write: %d)\n", last_pp_write); switch(tr->cmdTrans) { case PP_READ: ret = ioctl(parportfd, PPRSTATUS, &val); +#ifdef FORCE_PC3_IDENT + val &= 95; + if (last_pp_write & 64) + val |= 32; + else + val |= 128; +#endif break; case PP_WRITE: @@ -345,7 +355,7 @@ int do_wdioctl(int fd, unsigned int request, unsigned char *wdioctl) { switch(request & ~(0xc0000000)) { case VERSION: version = (struct version_struct*)(wdheader->data); - strcpy(version->version, "WinDriver no more"); + strcpy(version->version, "libusb-driver.so $Revision: 1.60 $"); version->versionul = 802; DPRINTF("VERSION\n"); break; @@ -376,10 +386,8 @@ int do_wdioctl(int fd, unsigned int request, unsigned char *wdioctl) { ret = (*ioctl_func) (fd, request, wdioctl); #else if (parportfd < 0) { - if (ppbase && ((unsigned long)cr->Card.Item[0].I.IO.dwAddr != ppbase)) - parportnum++; - - snprintf(ppdev, sizeof(ppdev), "/dev/parport%d", parportnum); + snprintf(ppdev, sizeof(ppdev), "/dev/parport%lu", + (unsigned long)cr->Card.Item[0].I.IO.dwAddr / 0x10); DPRINTF("opening %s\n", ppdev); parportfd = open(ppdev, O_RDWR|O_EXCL); @@ -941,19 +949,32 @@ int close(int fd) { FILE *fopen(const char *path, const char *mode) { FILE *ret; static FILE* (*func) (const char*, const char*) = NULL; + char buf[256]; + int i; if (!func) func = (FILE* (*) (const char*, const char*)) dlsym(RTLD_NEXT, "fopen"); ret = (*func) (path, mode); - if (!strcmp (path, "/proc/modules")) { + if (!strcmp(path, "/proc/modules")) { DPRINTF("opening /proc/modules\n"); #ifdef NO_WINDRVR modulesfp = ret; modules_read = 0; #endif } + + if (ret) { + for (i = 0; i < 4; i++) { + snprintf(buf, sizeof(buf), "/proc/sys/dev/parport/parport%d/base-addr", i); + if (!strcmp(path, buf)) { + DPRINTF("open base-addr of parport%d\n", i); + baseaddrfp = ret; + baseaddrnum = i; + } + } + } return ret; } @@ -961,6 +982,7 @@ FILE *fopen(const char *path, const char *mode) { char *fgets(char *s, int size, FILE *stream) { static char* (*func) (char*, int, FILE*) = NULL; const char modules[][256] = {"windrvr6 1 0 - Live 0xdeadbeef\n", "parport_pc 1 0 - Live 0xdeadbeef\n"}; + char buf[256]; char *ret = NULL; @@ -973,6 +995,11 @@ char *fgets(char *s, int size, FILE *stream) { ret = s; modules_read++; } + } else if (baseaddrfp == stream) { + snprintf(s, sizeof(buf), "%d\t%d\n", + (baseaddrnum) * 0x10, + ((baseaddrnum) * 0x10) + 0x400); + ret = s; } else { ret = (*func)(s,size,stream); } @@ -989,6 +1016,10 @@ int fclose(FILE *fp) { if (fp == modulesfp) { modulesfp = NULL; } + + if (fp == baseaddrfp) { + baseaddrfp = NULL; + } return (*func)(fp); }