]> cvs.zerfleddert.de Git - usb-driver/blobdiff - usb-driver.c
reset the USB cable when /dev/windrvr6 is closed.
[usb-driver] / usb-driver.c
index b230afadc917a73ee45741c1faeca029c8975d26..6320b9f74fe4bee537b735ca49700dcb317797e0 100644 (file)
@@ -39,6 +39,8 @@
 #include <errno.h>
 #include <inttypes.h>
 #include <sys/ioctl.h>
+#include <sys/utsname.h>
+#include <bits/wordsize.h>
 #include "usb-driver.h"
 #include "config.h"
 
@@ -47,9 +49,9 @@ static int windrvrfd = -1;
 static unsigned long ppbase = 0;
 static unsigned long ecpbase = 0;
 static struct parport_config *pport = NULL;
-FILE *modulesfp = NULL;
-FILE *baseaddrfp = NULL;
-int baseaddrnum = 0;
+static FILE *modulesfp = NULL;
+static FILE *baseaddrfp = NULL;
+static int baseaddrnum = 0;
 static int modules_read = 0;
 static struct usb_bus *busses = NULL;
 static struct usb_device *usbdevice;
@@ -72,7 +74,7 @@ void hexdump(unsigned char *buf, int len) {
        fprintf(stderr,"\n");
 }
 
-int usb_deviceinfo(unsigned char *buf) {
+static int usb_deviceinfo(unsigned char *buf) {
        int i,j,k,l;
        int len = 0;
        WDU_CONFIGURATION **pConfigs, **pActiveConfig;
@@ -232,7 +234,7 @@ int usb_deviceinfo(unsigned char *buf) {
        return len;
 }
 
-int do_wdioctl(int fd, unsigned int request, unsigned char *wdioctl) {
+static int do_wdioctl(int fd, unsigned int request, unsigned char *wdioctl) {
        struct header_struct* wdheader = (struct header_struct*)wdioctl;
        struct version_struct *version;
        int ret = 0;
@@ -245,7 +247,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, "libusb-driver.so $Revision: 1.69 $");
+                       strcpy(version->version, "libusb-driver.so version: " USB_DRIVER_VERSION);
                        version->versionul = 802;
                        DPRINTF("VERSION\n");
                        break;
@@ -466,6 +468,8 @@ int do_wdioctl(int fd, unsigned int request, unsigned char *wdioctl) {
                        {
                                struct event *e = (struct event*)(wdheader->data);
                                struct usb_bus *bus;
+                               char* devpos;
+                               int busnum = -1, devnum = -1;
                                int i;
 
                                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",
@@ -477,6 +481,37 @@ int do_wdioctl(int fd, unsigned int request, unsigned char *wdioctl) {
                                e->u.Usb.dwUniqueID, e->dwEventVer,
                                e->dwNumMatchTables);
 
+                               devpos = getenv("XILINX_USB_DEV");
+                               if (devpos != NULL) {
+                                       int j;
+                                       char *devstr = NULL, *remainder;
+
+                                       DPRINTF("XILINX_USB_DEV=%s\n", devpos);
+
+                                       for (j = 0; j < strlen(devpos) && devpos[j] != 0; j++) {
+                                               if (devpos[j] == ':') {
+                                                       devpos[j] = 0;
+                                                       devstr = &(devpos[j+1]);
+                                               }
+                                       }
+
+                                       if (devstr && strlen(devstr) > 0) {
+                                               busnum = strtol(devpos, &remainder, 10);
+                                               if (devpos == remainder) {
+                                                       busnum = -1;
+                                               } else {
+                                                       devnum = strtol(devstr, &remainder, 10);
+                                                       if (devstr == remainder) {
+                                                               busnum = -1;
+                                                               devnum = -1;
+                                                       } else {
+                                                               fprintf(stderr,"Using XILINX platform cable USB at %03d:%03d\n",
+                                                               busnum, devnum);
+                                                       }
+                                               }
+                                       }
+                               }
+
                                for (i = 0; i < e->dwNumMatchTables; i++) {
 
                                        DPRINTF("match: dev: %04x:%04x, class: %x, subclass: %x, intclass: %x, intsubclass: %x, intproto: %x\n",
@@ -491,13 +526,17 @@ int do_wdioctl(int fd, unsigned int request, unsigned char *wdioctl) {
                                        for (bus = busses; bus; bus = bus->next) {
                                                struct usb_device *dev;
 
+                                               if ((devnum != -1) && (strtol(bus->dirname, NULL, 10) != busnum))
+                                                       continue;
+
                                                for (dev = bus->devices; dev; dev = dev->next) {
                                                        struct usb_device_descriptor *desc = &(dev->descriptor);
 
                                                        if((desc->idVendor == e->matchTables[i].VendorId) &&
                                                           (desc->idProduct == e->matchTables[i].ProductId) &&
                                                           (desc->bDeviceClass == e->matchTables[i].bDeviceClass) &&
-                                                          (desc->bDeviceSubClass == e->matchTables[i].bDeviceSubClass)) {
+                                                          (desc->bDeviceSubClass == e->matchTables[i].bDeviceSubClass) &&
+                                                          ((devnum == -1) || (strtol(dev->filename, NULL, 10) == devnum)) ) {
                                                                   int ac;
                                                                   for (ac = 0; ac < desc->bNumConfigurations; ac++) {
                                                                           struct usb_interface *interface = dev->config[ac].interface;
@@ -636,7 +675,10 @@ int do_wdioctl(int fd, unsigned int request, unsigned char *wdioctl) {
 #ifndef NO_WINDRVR
                                ret = (*ioctl_func) (fd, request, wdioctl);
 #else
-                               pport->close(cr->hCard);
+                               if (pport)
+                                       pport->close(cr->hCard);
+
+                               pport = NULL;
 #endif
                        }
                        break;
@@ -788,8 +830,12 @@ int close(int fd) {
                if (usbinterface >= 0)
                        usb_release_interface(usb_devhandle, usbinterface);
 
-               if (usb_devhandle)
+               if (usb_devhandle) {
+#ifndef NO_USB_RESET
+                       usb_reset(usb_devhandle);
+#endif
                        usb_close(usb_devhandle);
+               }
 
                usb_devhandle = NULL;
                usbinterface = -1;
@@ -890,10 +936,28 @@ int access(const char *pathname, int mode) {
 
        if (!func)
                func = (int (*) (const char*, int)) dlsym(RTLD_NEXT, "access");
-       
-       if (!strcmp(pathname, "/dev/windrvr6")) {
+
+       if (pathname && !strcmp(pathname, "/dev/windrvr6")) {
                return 0;
        } else {
                return (*func)(pathname, mode);
        }
 }
+
+#if __WORDSIZE == 32
+int uname (struct utsname *__name) {
+       static int (*func) (struct utsname*);
+       int ret;
+
+       if (!func)
+               func = (int (*) (struct utsname*)) dlsym(RTLD_NEXT, "uname");
+       
+       ret = (*func)(__name);
+
+       if (ret == 0 && (!strcmp(__name->machine, "x86_64"))) {
+               strcpy(__name->machine, "i686");
+       }
+       
+       return ret;
+}
+#endif
Impressum, Datenschutz