]> git.zerfleddert.de Git - usb-driver/blobdiff - usb-driver.c
Ho Hum
[usb-driver] / usb-driver.c
index 3f22b08e1090d8055e612a0be8841124cf3ff3a9..e92467f95b2ebbea50967bbb7cfa5b86ecbb4e4c 100644 (file)
@@ -28,6 +28,7 @@ static struct usb_bus *busses = NULL;
 static struct usb_device *usbdevice;
 static usb_dev_handle *usb_devhandle = NULL;
 static unsigned long card_type;
+static int ints_enabled = 0;
 
 #define NO_WINDRVR 1
 
@@ -248,6 +249,7 @@ int do_wdioctl(int fd, unsigned int request, unsigned char *wdioctl) {
                        fprintf(stderr,"in USB_TRANSFER");
                        {
                                struct usb_transfer *ut = (struct usb_transfer*)(wdheader->data);
+                               int requesttype, request, value, index, size;
 
                                fprintf(stderr," unique: %lu, pipe: %lu, read: %lu, options: %lx, size: %lu, timeout: %lx\n", ut->dwUniqueID, ut->dwPipeNum, ut->fRead, ut->dwOptions, ut->dwBufferSize, ut->dwTimeout);
                                fprintf(stderr,"setup packet: ");
@@ -261,6 +263,22 @@ int do_wdioctl(int fd, unsigned int request, unsigned char *wdioctl) {
 
 #ifndef NO_WINDRVR
                                ret = (*ioctl_func) (fd, request, wdioctl);
+#else
+                               /* http://www.jungo.com/support/documentation/windriver/802/wdusb_man_mhtml/node55.html#SECTION001213000000000000000 */
+                               requesttype = ut->SetupPacket[0];
+                               request = ut->SetupPacket[1];
+                               value = ut->SetupPacket[2] | (ut->SetupPacket[3] << 8);
+                               index = ut->SetupPacket[4] | (ut->SetupPacket[5] << 8);
+                               size = ut->SetupPacket[6] | (ut->SetupPacket[7] << 8);
+                               fprintf(stderr, "requesttype: %x, request: %x, value: %u, index: %u, size: %u\n", requesttype, request, value, index, size);
+                               ret = usb_control_msg(usb_devhandle, requesttype, request, value, index, ut->pBuffer, size, ut->dwTimeout);
+                               if (ret < 0) {
+                                       fprintf(stderr, "usb_control_msg: %d\n", ret);
+                               } else {
+                                       ut->dwBytesTransferred = ret;
+                                       ret = 0;
+                               }
+                                       
 #endif
 
                                fprintf(stderr,"Transferred: %lu (%s)\n",ut->dwBytesTransferred, (ut->fRead?"read":"write"));
@@ -268,19 +286,20 @@ int do_wdioctl(int fd, unsigned int request, unsigned char *wdioctl) {
                                {
                                        fprintf(stderr,"Read: ");
                                        hexdump(ut->pBuffer, ut->dwBytesTransferred);
+                                       fprintf(stderr,"\n");
                                }
-                               fprintf(stderr,"\n");
                        }
                        break;
 
                case INT_ENABLE:
-                       fprintf(stderr,"faking INT_ENABLE");
+                       fprintf(stderr,"INT_ENABLE\n");
                        {
                                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);
 
                                it->fEnableOk = 1;
+                               ints_enabled = 1;
                                //ret = (*ioctl_func) (fd, request, wdioctl);
                        }
 
@@ -297,6 +316,7 @@ int do_wdioctl(int fd, unsigned int request, unsigned char *wdioctl) {
 #else
                                it->dwCounter = 0;
                                it->fStopped = 1;
+                               ints_enabled = 0;
 #endif
                                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);
                        }
@@ -312,12 +332,23 @@ int do_wdioctl(int fd, unsigned int request, unsigned char *wdioctl) {
                                ret = (*ioctl_func) (fd, request, wdioctl);
 #else
                                if (usbdevice) {
-                                       int iface;
-
                                        if (!usb_devhandle)
                                                usb_devhandle = usb_open(usbdevice);
-//MGMG
-                                       ret = usb_claim_interface(usb_devhandle, iface);
+
+                                       /* FIXME: Select right interface! */
+                                       ret = usb_claim_interface(usb_devhandle, usbdevice->config[0].interface[usi->dwInterfaceNum].altsetting[usi->dwAlternateSetting].bInterfaceNumber);
+                                       if (!ret) {
+                                               //ret = usb_set_configuration(usb_devhandle, usbdevice->config[0].bConfigurationValue);
+                                               if(!ret) {
+                                                       ret = usb_set_altinterface(usb_devhandle, usi->dwAlternateSetting);
+                                                       if (ret)
+                                                               fprintf(stderr, "usb_set_altinterface: %d\n", ret);
+                                               } else {
+                                                       fprintf(stderr, "usb_set_configuration: %d (%s)\n", ret, usb_strerror());
+                                               }
+                                       } else {
+                                               fprintf(stderr, "usb_claim_interface: %d -> %d (%s)\n", usbdevice->config[0].interface[usi->dwInterfaceNum].altsetting[usi->dwAlternateSetting].bInterfaceNumber, ret, usb_strerror());
+                                       }
                                }
 #endif
                                fprintf(stderr,"unique: %lu, interfacenum: %lu, alternatesetting: %lu, options: %lx\n", usi->dwUniqueID, usi->dwInterfaceNum, usi->dwAlternateSetting, usi->dwOptions);
@@ -325,16 +356,14 @@ int do_wdioctl(int fd, unsigned int request, unsigned char *wdioctl) {
                        break;
 
                case USB_GET_DEVICE_DATA:
-                       fprintf(stderr,"USB_GET_DEVICE_DATA\n");
+                       fprintf(stderr,"faking USB_GET_DEVICE_DATA\n");
                        {
                                struct usb_get_device_data *ugdd = (struct usb_get_device_data*)(wdheader->data);
                                int pSize;
 
                                fprintf(stderr, "unique: %lu, bytes: %lu, options: %lx\n", ugdd->dwUniqueID, ugdd->dwBytes, ugdd->dwOptions);
                                pSize = ugdd->dwBytes;
-#ifndef NO_WINDRVR
-                               ret = (*ioctl_func) (fd, request, wdioctl);
-#else
+                               //ret = (*ioctl_func) (fd, request, wdioctl);
                                if (!ugdd->dwBytes) {
                                        if (usbdevice) {
                                                ugdd->dwBytes = usb_deviceinfo(NULL);
@@ -342,14 +371,11 @@ int do_wdioctl(int fd, unsigned int request, unsigned char *wdioctl) {
                                } else {
                                        usb_deviceinfo((unsigned char*)ugdd->pBuf);
                                }
-#endif
+
                                if (pSize) {
                                        struct usb_device_info *udi = (struct usb_device_info*)ugdd->pBuf;
 
                                        fprintf(stderr, "Vendor: %x\n", udi->Descriptor.idVendor);
-
-                                       hexdump(ugdd->pBuf, pSize);
-                                       fprintf(stderr, "\n");
                                }
                        }
                        break;
@@ -438,15 +464,15 @@ int do_wdioctl(int fd, unsigned int request, unsigned char *wdioctl) {
                                        if (it->dwCounter == 0) {
                                                it->dwCounter = 1;
                                        } else {
-                                               //FIXME: signal 
-                                               kill(getpid(), SIGHUP);
+                                               //FIXME: signal durch FUTEX, overload futex!
+                                               while(ints_enabled) {sleep(1);}
                                        }
                                } else {
-                                       kill(getpid(), SIGHUP);
+                                       while(ints_enabled) {sleep(1);}
                                }
 #endif
 
-                               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);
+                               fprintf(stderr,"INT_WAIT_RETURN: 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;
 
@@ -481,7 +507,7 @@ int do_wdioctl(int fd, unsigned int request, unsigned char *wdioctl) {
                                        e->dwCardType = card_type;
                                        e->dwAction = 1;
                                        e->dwEventId = 109;
-                                       e->u.Usb.dwUniqueID = 4711;
+                                       e->u.Usb.dwUniqueID = 110;
                                        e->matchTables[0].VendorId = usbdevice->descriptor.idVendor;
                                        e->matchTables[0].ProductId = usbdevice->descriptor.idProduct;
                                        e->matchTables[0].bDeviceClass = usbdevice->descriptor.bDeviceClass;
@@ -495,6 +521,7 @@ int do_wdioctl(int fd, unsigned int request, unsigned char *wdioctl) {
                                fprintf(stderr,"handle: %lu, action: %lu, status: %lu, eventid: %lu, cardtype: %lx, 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: %04x:%04x, 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;
 
@@ -590,6 +617,20 @@ int ioctl(int fd, int request, ...)
        return ret;
 }
 
+int futex(int *uaddr, int op, int val, const struct timespec *timeout, int *uaddr2, int val3) {
+       static int (*func) (int*, int, int, const struct timespec*, int*, int) = NULL;
+       int ret;
+
+       if (!func)
+               func = (int (*) (int*, int, int, const struct timespec*, int*, int)) dlsym(REAL_LIBC, "futex");
+
+       fprintf(stderr,"FUTEX: %x\n", (unsigned int)uaddr);
+       ret = (*func) (uaddr, op, val, timeout, uaddr2, val3);
+
+       return ret;
+}
+
+
 #if 0
 void *mmap(void *start, size_t length, int prot, int flags, int fd, off_t offset)
 {
Impressum, Datenschutz