]> git.zerfleddert.de Git - usb-driver/blobdiff - usb-driver.c
find the device!
[usb-driver] / usb-driver.c
index cf17890ec75ba56780d63b3ce40e4bae173f1af6..f49cb163ec35c26547cd28147519c9489d304118 100644 (file)
 #include <sys/stat.h>
 #include <sys/time.h>
 #include <stdio.h>
+#include <usb.h>
 #include "xilinx.h"
 
 static int (*ioctl_func) (int, int, void *) = NULL;
 static int windrvrfd = 0;
+static struct usb_bus *busses = NULL;
+static struct usb_device *usb_cable;
 
 void hexdump(unsigned char *buf, int len);
 void diff(unsigned char *buf1, unsigned char *buf2, int len);
@@ -88,7 +91,7 @@ int do_wdioctl(int fd, unsigned int request, unsigned char *wdioctl) {
                        {
                                struct interrupt *it = (struct interrupt*)(wdheader->data);
 
-                               fprintf(stderr," Handle: %lu, Options: %lx, ncmds: %lu\n", it->hInterrupt, it->dwOptions, it->dwCmds);
+                               fprintf(stderr,"Handle: %lu, Options: %lx, ncmds: %lu, enableok: %lu, count: %lu, lost: %lu, stopped: %lu\n", it->hInterrupt, it->dwOptions, it->dwCmds, it->fEnableOk, it->dwCounter, it->dwLost, it->fStopped);
 
                                it->fEnableOk = 1;
                                //ret = (*ioctl_func) (fd, request, wdioctl);
@@ -101,15 +104,11 @@ int do_wdioctl(int fd, unsigned int request, unsigned char *wdioctl) {
                        {
                                struct interrupt *it = (struct interrupt*)(wdheader->data);
 
-                               fprintf(stderr," Handle: %lu, Options: %lx, ncmds: %lu\n", it->hInterrupt, it->dwOptions, it->dwCmds);
-
-                               hexdump(wdheader->data, wdheader->size);
+                               fprintf(stderr,"Handle: %lu, Options: %lx, ncmds: %lu, enableok: %lu, count: %lu, lost: %lu, stopped: %lu\n", it->hInterrupt, it->dwOptions, it->dwCmds, it->fEnableOk, it->dwCounter, it->dwLost, it->fStopped);
                                //it->dwCounter = 0;
                                //it->fStopped = 1;
                                ret = (*ioctl_func) (fd, request, wdioctl);
-                               fprintf(stderr,"\n\n");
-                               hexdump(wdheader->data, wdheader->size);
-                               fprintf(stderr,"\n");
+                               fprintf(stderr,"Handle: %lu, Options: %lx, ncmds: %lu, enableok: %lu, count: %lu, lost: %lu, stopped: %lu\n", it->hInterrupt, it->dwOptions, it->dwCmds, it->fEnableOk, it->dwCounter, it->dwLost, it->fStopped);
                        }
                        break;
 
@@ -139,6 +138,52 @@ int do_wdioctl(int fd, unsigned int request, unsigned char *wdioctl) {
                        }
                        break;
 
+               case EVENT_REGISTER:
+                       fprintf(stderr,"EVENT_REGISTER\n");
+                       {
+                               struct event *e = (struct event*)(wdheader->data);
+                               struct usb_bus *bus;
+                               int i;
+
+                               fprintf(stderr,"handle: %lu, action: %lu, status: %lu, eventid: %lu, cardtype: %lu, kplug: %lu, options: %lu, dev: %lx:%lx, unique: %lu, ver: %lu, nummatch: %lu\n", e->handle, e->dwAction, e->dwStatus, e->dwEventId, e->dwCardType, e->hKernelPlugIn, e->dwOptions, e->u.Usb.deviceId.dwVendorId, e->u.Usb.deviceId.dwProductId, e->u.Usb.dwUniqueID, e->dwEventVer, e->dwNumMatchTables);
+                               for (i = 0; i < e->dwNumMatchTables; i++) {
+                                       fprintf(stderr,"match: dev: %x:%x, class: %x, subclass: %x, intclass: %x, intsubclass: %x, intproto: %x\n", e->matchTables[i].VendorId, e->matchTables[i].ProductId, e->matchTables[i].bDeviceClass, e->matchTables[i].bDeviceSubClass, e->matchTables[i].bInterfaceClass, e->matchTables[i].bInterfaceSubClass, e->matchTables[i].bInterfaceProtocol);
+
+                                       for (bus = busses; bus; bus = bus->next) {
+                                               struct usb_device *dev;
+
+                                               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)) {
+                                                               struct usb_interface *interface = dev->config->interface;
+                                                               int ai;
+                                                               
+                                                               for (ai = 0; ai < interface->num_altsetting; ai++) {
+                                                                       fprintf(stderr, "intclass: %x, intsubclass: %x, intproto: %x\n", interface->altsetting[i].bInterfaceClass, interface->altsetting[i].bInterfaceSubClass, interface->altsetting[i].bInterfaceProtocol);
+                                                                       if ((interface->altsetting[i].bInterfaceSubClass == e->matchTables[i].bInterfaceSubClass) &&
+                                                                           (interface->altsetting[i].bInterfaceProtocol == e->matchTables[i].bInterfaceProtocol)){
+                                                                               /* TODO: check interfaceClass! */
+                                                                               fprintf(stderr,"!!!FOUND DEVICE WITH LIBUSB!!!\n");
+                                                                               usb_cable = dev;
+                                                                       }
+                                                               }
+                                                       }
+                                               }
+                                       }
+                               }
+
+                               ret = (*ioctl_func) (fd, request, wdioctl);
+
+                               fprintf(stderr,"handle: %lu, action: %lu, status: %lu, eventid: %lu, cardtype: %lu, kplug: %lu, options: %lu, dev: %lx:%lx, unique: %lu, ver: %lu, nummatch: %lu\n", e->handle, e->dwAction, e->dwStatus, e->dwEventId, e->dwCardType, e->hKernelPlugIn, e->dwOptions, e->u.Usb.deviceId.dwVendorId, e->u.Usb.deviceId.dwProductId, e->u.Usb.dwUniqueID, e->dwEventVer, e->dwNumMatchTables);
+                               for (i = 0; i < e->dwNumMatchTables; i++)
+                                       fprintf(stderr,"match: dev: %x:%x, class: %x, subclass: %x, intclass: %x, intsubclass: %x, intproto: %x\n", e->matchTables[i].VendorId, e->matchTables[i].ProductId, e->matchTables[i].bDeviceClass, e->matchTables[i].bDeviceSubClass, e->matchTables[i].bInterfaceClass, e->matchTables[i].bInterfaceSubClass, e->matchTables[i].bInterfaceProtocol);
+                       }
+                       break;
+
                case TRANSFER:
                        fprintf(stderr,"TRANSFER\n");
                        ret = (*ioctl_func) (fd, request, wdioctl);
@@ -151,7 +196,14 @@ int do_wdioctl(int fd, unsigned int request, unsigned char *wdioctl) {
 
                case INT_WAIT:
                        fprintf(stderr,"INT_WAIT\n");
-                       ret = (*ioctl_func) (fd, request, wdioctl);
+                       {
+                               struct interrupt *it = (struct interrupt*)(wdheader->data);
+
+                               fprintf(stderr,"Handle: %lu, Options: %lx, ncmds: %lu, enableok: %lu, count: %lu, lost: %lu, stopped: %lu\n", it->hInterrupt, it->dwOptions, it->dwCmds, it->fEnableOk, it->dwCounter, it->dwLost, it->fStopped);
+
+                               ret = (*ioctl_func) (fd, request, wdioctl);
+                               fprintf(stderr,"Handle: %lu, Options: %lx, ncmds: %lu, enableok: %lu, count: %lu, lost: %lu, stopped: %lu\n", it->hInterrupt, it->dwOptions, it->dwCmds, it->fEnableOk, it->dwCounter, it->dwLost, it->fStopped);
+                       }
                        break;
 
                case CARD_UNREGISTER:
@@ -161,12 +213,20 @@ int do_wdioctl(int fd, unsigned int request, unsigned char *wdioctl) {
 
                case EVENT_PULL:
                        fprintf(stderr,"EVENT_PULL\n");
-                       ret = (*ioctl_func) (fd, request, wdioctl);
-                       break;
+                       {
+                               struct event *e = (struct event*)(wdheader->data);
+                               int i;
 
-               case EVENT_REGISTER:
-                       fprintf(stderr,"EVENT_REGISTER\n");
-                       ret = (*ioctl_func) (fd, request, wdioctl);
+                               fprintf(stderr,"handle: %lu, action: %lu, status: %lu, eventid: %lu, cardtype: %lu, kplug: %lu, options: %lu, dev: %lx:%lx, unique: %lu, ver: %lu, nummatch: %lu\n", e->handle, e->dwAction, e->dwStatus, e->dwEventId, e->dwCardType, e->hKernelPlugIn, e->dwOptions, e->u.Usb.deviceId.dwVendorId, e->u.Usb.deviceId.dwProductId, e->u.Usb.dwUniqueID, e->dwEventVer, e->dwNumMatchTables);
+                               for (i = 0; i < e->dwNumMatchTables; i++)
+                                       fprintf(stderr,"match: dev: %x:%x, class: %x, subclass: %x, intclass: %x, intsubclass: %x, intproto: %x\n", e->matchTables[i].VendorId, e->matchTables[i].ProductId, e->matchTables[i].bDeviceClass, e->matchTables[i].bDeviceSubClass, e->matchTables[i].bInterfaceClass, e->matchTables[i].bInterfaceSubClass, e->matchTables[i].bInterfaceProtocol);
+
+                               ret = (*ioctl_func) (fd, request, wdioctl);
+
+                               fprintf(stderr,"handle: %lu, action: %lu, status: %lu, eventid: %lu, cardtype: %lu, kplug: %lu, options: %lu, dev: %lx:%lx, unique: %lu, ver: %lu, nummatch: %lu\n", e->handle, e->dwAction, e->dwStatus, e->dwEventId, e->dwCardType, e->hKernelPlugIn, e->dwOptions, e->u.Usb.deviceId.dwVendorId, e->u.Usb.deviceId.dwProductId, e->u.Usb.dwUniqueID, e->dwEventVer, e->dwNumMatchTables);
+                               for (i = 0; i < e->dwNumMatchTables; i++)
+                                       fprintf(stderr,"match: dev: %x:%x, class: %x, subclass: %x, intclass: %x, intsubclass: %x, intproto: %x\n", e->matchTables[i].VendorId, e->matchTables[i].ProductId, e->matchTables[i].bDeviceClass, e->matchTables[i].bDeviceSubClass, e->matchTables[i].bInterfaceClass, e->matchTables[i].bInterfaceSubClass, e->matchTables[i].bInterfaceProtocol);
+                       }
                        break;
 
                default:
@@ -200,6 +260,13 @@ int open (const char *pathname, int flags, ...)
        if (!strcmp (pathname, "/dev/windrvr6")) {
                fprintf(stderr,"opening windrvr6\n");
                windrvrfd = fd;
+               if (!busses) {
+                       usb_init();
+                       usb_find_busses();
+                       usb_find_devices();
+
+                       busses = usb_get_busses();
+               }
        }
 
        return fd;
Impressum, Datenschutz