X-Git-Url: http://cvs.zerfleddert.de/cgi-bin/gitweb.cgi/usb-driver/blobdiff_plain/94038a57ca0af1bf450c966fc89f057261b0d5f0..a70f4f388bbe08fbc80c4b587da4c0a781f475da:/usb-driver.c?ds=inline diff --git a/usb-driver.c b/usb-driver.c index 3f22b08..c4afaf5 100644 --- a/usb-driver.c +++ b/usb-driver.c @@ -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 @@ -261,6 +262,32 @@ 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 */ + if (ut->dwPipeNum == 0) { /* control pipe */ + int requesttype, request, value, index, size; + 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); + } else { + if (ut->fRead) { + ret = usb_bulk_read(usb_devhandle, ut->dwPipeNum, ut->pBuffer, ut->dwBufferSize, ut->dwTimeout); + + } else { + ret = usb_bulk_write(usb_devhandle, ut->dwPipeNum, ut->pBuffer, ut->dwBufferSize, ut->dwTimeout); + } + } + + if (ret < 0) { + fprintf(stderr, "usb_transfer: %d (%s)\n", ret, usb_strerror()); + } else { + ut->dwBytesTransferred = ret; + ret = 0; + } #endif fprintf(stderr,"Transferred: %lu (%s)\n",ut->dwBytesTransferred, (ut->fRead?"read":"write")); @@ -268,19 +295,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 +325,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 +341,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 +365,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 +380,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 +473,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 +516,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 +530,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 +626,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) {