X-Git-Url: http://git.zerfleddert.de/cgi-bin/gitweb.cgi/usb-driver/blobdiff_plain/9c9fd67cec6a89fb5fb05b16af00d05a7573c2eb..b0f621dd6a5f05639017d33b3f2c74d1a9665226:/usb-driver.c diff --git a/usb-driver.c b/usb-driver.c index 02b4106..d613865 100644 --- a/usb-driver.c +++ b/usb-driver.c @@ -20,9 +20,8 @@ #include #include "xilinx.h" -#define SNIFFLEN 4096 -static unsigned char lastbuf[4096]; static int (*ioctl_func) (int, int, void *) = NULL; +static int windrvrfd = 0; void hexdump(unsigned char *buf, int len); void diff(unsigned char *buf1, unsigned char *buf2, int len); @@ -33,8 +32,8 @@ int do_wdioctl(int fd, unsigned int request, unsigned char *wdioctl) { int ret = 0; if (wdheader->magic != MAGIC) { - fprintf(stderr,"!!!ERROR: Header does not match!!!\n"); - return; + fprintf(stderr,"!!!ERROR: magic header does not match!!!\n"); + return (*ioctl_func) (fd, request, wdioctl); } switch(request) { @@ -44,19 +43,25 @@ int do_wdioctl(int fd, unsigned int request, unsigned char *wdioctl) { version->versionul = 999; fprintf(stderr,"faking VERSION\n"); break; + + case LICENSE: + fprintf(stderr,"faking LICENSE\n"); + break; + case CARD_REGISTER: { - struct card_register* cr = (struct card_register*)(wdheader->data); + //struct card_register* cr = (struct card_register*)(wdheader->data); /* Todo: LPT-Port already in use */ } fprintf(stderr,"faking CARD_REGISTER\n"); break; + case USB_TRANSFER: fprintf(stderr,"in USB_TRANSFER"); { struct usb_transfer *ut = (struct usb_transfer*)(wdheader->data); - fprintf(stderr," unique: %d, pipe: %d, read: %d, options: %x, size: %d, timeout: %x\n", ut->dwUniqueID, ut->dwPipeNum, ut->fRead, ut->dwOptions, ut->dwBufferSize, ut->dwTimeout); + 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: "); hexdump(ut->SetupPacket, 8); fprintf(stderr,"\n"); @@ -68,7 +73,7 @@ int do_wdioctl(int fd, unsigned int request, unsigned char *wdioctl) { ret = (*ioctl_func) (fd, request, wdioctl); - fprintf(stderr,"Transferred: %d (%s)\n",ut->dwBytesTransferred, (ut->fRead?"read":"write")); + fprintf(stderr,"Transferred: %lu (%s)\n",ut->dwBytesTransferred, (ut->fRead?"read":"write")); if (ut->fRead && ut->dwBytesTransferred) { fprintf(stderr,"Read: "); @@ -77,12 +82,13 @@ int do_wdioctl(int fd, unsigned int request, unsigned char *wdioctl) { fprintf(stderr,"\n"); } break; + case INT_ENABLE: fprintf(stderr,"faking INT_ENABLE"); { struct interrupt *it = (struct interrupt*)(wdheader->data); - fprintf(stderr," Handle: %d, Options: %x, ncmds: %d\n", it->hInterrupt, it->dwOptions, it->dwCmds); + fprintf(stderr," Handle: %lu, Options: %lx, ncmds: %lu\n", it->hInterrupt, it->dwOptions, it->dwCmds); it->fEnableOk = 1; //ret = (*ioctl_func) (fd, request, wdioctl); @@ -95,7 +101,7 @@ int do_wdioctl(int fd, unsigned int request, unsigned char *wdioctl) { { struct interrupt *it = (struct interrupt*)(wdheader->data); - fprintf(stderr," Handle: %d, Options: %x, ncmds: %d\n", it->hInterrupt, it->dwOptions, it->dwCmds); + fprintf(stderr," Handle: %lu, Options: %lx, ncmds: %lu\n", it->hInterrupt, it->dwOptions, it->dwCmds); hexdump(wdheader->data, wdheader->size); //it->dwCounter = 0; @@ -112,7 +118,7 @@ int do_wdioctl(int fd, unsigned int request, unsigned char *wdioctl) { { struct usb_set_interface *usi = (struct usb_set_interface*)(wdheader->data); - fprintf(stderr,"unique: %d, interfacenum: %d, alternatesetting: %d, options: %x\n", usi->dwUniqueID, usi->dwInterfaceNum, usi->dwAlternateSetting, usi->dwOptions); + fprintf(stderr,"unique: %lu, interfacenum: %lu, alternatesetting: %lu, options: %lx\n", usi->dwUniqueID, usi->dwInterfaceNum, usi->dwAlternateSetting, usi->dwOptions); ret = (*ioctl_func) (fd, request, wdioctl); } break; @@ -123,7 +129,7 @@ int do_wdioctl(int fd, unsigned int request, unsigned char *wdioctl) { struct usb_get_device_data *ugdd = (struct usb_get_device_data*)(wdheader->data); int pSize; - fprintf(stderr, "uniqe: %d, bytes: %d, options: %x\n", ugdd->dwUniqueID, ugdd->dwBytes, ugdd->dwOptions); + fprintf(stderr, "uniqe: %lu, bytes: %lu, options: %lx\n", ugdd->dwUniqueID, ugdd->dwBytes, ugdd->dwOptions); pSize = ugdd->dwBytes; ret = (*ioctl_func) (fd, request, wdioctl); if (pSize) { @@ -133,8 +139,22 @@ int do_wdioctl(int fd, unsigned int request, unsigned char *wdioctl) { } break; - case LICENSE: - fprintf(stderr,"faking LICENSE\n"); + case EVENT_REGISTER: + fprintf(stderr,"EVENT_REGISTER\n"); + { + struct event *e = (struct event*)(wdheader->data); + 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); + + 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: @@ -149,7 +169,19 @@ 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\n", it->hInterrupt, it->dwOptions, it->dwCmds); + + hexdump(wdheader->data, wdheader->size); + ret = (*ioctl_func) (fd, request, wdioctl); + //ret = 0; + //it->dwCounter++; + fprintf(stderr,"\n\n"); + hexdump(wdheader->data, wdheader->size); + fprintf(stderr,"\n"); + } break; case CARD_UNREGISTER: @@ -162,11 +194,6 @@ int do_wdioctl(int fd, unsigned int request, unsigned char *wdioctl) { ret = (*ioctl_func) (fd, request, wdioctl); break; - case EVENT_REGISTER: - fprintf(stderr,"EVENT_REGISTER\n"); - ret = (*ioctl_func) (fd, request, wdioctl); - break; - default: ret = (*ioctl_func) (fd, request, wdioctl); } @@ -177,10 +204,6 @@ int do_wdioctl(int fd, unsigned int request, unsigned char *wdioctl) { typedef int (*open_funcptr_t) (const char *, int, mode_t); -static windrvrfd = 0; -static void* mmapped = NULL; -static size_t mmapplen = 0; - int open (const char *pathname, int flags, ...) { static open_funcptr_t func = NULL;