]> git.zerfleddert.de Git - usb-driver/blobdiff - usb-driver.c
return wd version 802
[usb-driver] / usb-driver.c
index b92c9516a6e8f35c989f4a5b407690194bf94ac9..75a1bc5255a11ef64f1c2b1423f85edef351bc43 100644 (file)
@@ -20,7 +20,8 @@
 #include <stdio.h>
 #include <usb.h>
 #include <signal.h>
-#include "xilinx.h"
+#include <pthread.h>
+#include "usb-driver.h"
 
 static int (*ioctl_func) (int, int, void *) = NULL;
 static int windrvrfd = 0;
@@ -31,10 +32,12 @@ static struct usb_device *usbdevice;
 static usb_dev_handle *usb_devhandle = NULL;
 static unsigned long card_type;
 static int ints_enabled = 0;
+static pthread_mutex_t int_wait = PTHREAD_MUTEX_INITIALIZER;
 
 #define NO_WINDRVR 1
 #undef DEBUG
 
+#ifdef DEBUG
 void hexdump(unsigned char *buf, int len) {
        int i;
 
@@ -44,6 +47,7 @@ void hexdump(unsigned char *buf, int len) {
                        fprintf(stderr,"\n");
        }
 }
+#endif
 
 int usb_deviceinfo(unsigned char *buf) {
        int i,j,k,l;
@@ -73,7 +77,7 @@ int usb_deviceinfo(unsigned char *buf) {
                udi->Pipe0.dwNumber = 0x00;
                udi->Pipe0.dwMaximumPacketSize = usbdevice->descriptor.bMaxPacketSize0;
                udi->Pipe0.type = 0;
-               udi->Pipe0.direction = 3;
+               udi->Pipe0.direction = WDU_DIR_IN_OUT;
                udi->Pipe0.dwInterval = 0;
 
                pConfigs = &(udi->pConfigs);
@@ -219,7 +223,7 @@ int do_wdioctl(int fd, unsigned int request, unsigned char *wdioctl) {
                case VERSION:
                        version = (struct version_struct*)(wdheader->data);
                        strcpy(version->version, "WinDriver no more");
-                       version->versionul = 999;
+                       version->versionul = 802;
 #ifdef DEBUG
                        fprintf(stderr,"faking VERSION\n");
 #endif
@@ -232,10 +236,12 @@ int do_wdioctl(int fd, unsigned int request, unsigned char *wdioctl) {
                        break;
 
                case CARD_REGISTER:
+                       /* TODO: Implement for LPT-support */
+#if 0
                        {
-                               //struct card_register* cr = (struct card_register*)(wdheader->data);
-                               /* Todo: LPT-Port already in use */
+                               struct card_register* cr = (struct card_register*)(wdheader->data);
                        }
+#endif
 #ifdef DEBUG
                        fprintf(stderr,"faking CARD_REGISTER\n");
 #endif
@@ -318,7 +324,7 @@ int do_wdioctl(int fd, unsigned int request, unsigned char *wdioctl) {
 
                                it->fEnableOk = 1;
                                ints_enabled = 1;
-                               //ret = (*ioctl_func) (fd, request, wdioctl);
+                               pthread_mutex_trylock(&int_wait);
                        }
 
                        break;
@@ -339,6 +345,7 @@ int do_wdioctl(int fd, unsigned int request, unsigned char *wdioctl) {
                                it->dwCounter = 0;
                                it->fStopped = 1;
                                ints_enabled = 0;
+                               pthread_mutex_unlock(&int_wait);
 #endif
 #ifdef DEBUG
                                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);
@@ -366,7 +373,6 @@ int do_wdioctl(int fd, unsigned int request, unsigned char *wdioctl) {
                                        /* 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)
@@ -397,7 +403,6 @@ int do_wdioctl(int fd, unsigned int request, unsigned char *wdioctl) {
                                fprintf(stderr, "unique: %lu, bytes: %lu, options: %lx\n", ugdd->dwUniqueID, ugdd->dwBytes, ugdd->dwOptions);
 #endif
                                pSize = ugdd->dwBytes;
-                               //ret = (*ioctl_func) (fd, request, wdioctl);
                                if (!ugdd->dwBytes) {
                                        if (usbdevice) {
                                                ugdd->dwBytes = usb_deviceinfo(NULL);
@@ -508,10 +513,12 @@ int do_wdioctl(int fd, unsigned int request, unsigned char *wdioctl) {
                                        if (it->dwCounter == 0) {
                                                it->dwCounter = 1;
                                        } else {
-                                               while(ints_enabled) {sleep(1);}
+                                               pthread_mutex_lock(&int_wait);
+                                               pthread_mutex_unlock(&int_wait);
                                        }
                                } else {
-                                       while(ints_enabled) {sleep(1);}
+                                       pthread_mutex_lock(&int_wait);
+                                       pthread_mutex_unlock(&int_wait);
                                }
 #endif
 
@@ -582,8 +589,7 @@ int do_wdioctl(int fd, unsigned int request, unsigned char *wdioctl) {
        return ret;
 }
 
-int ioctl(int fd, int request, ...)
-{
+int ioctl(int fd, int request, ...) {
        va_list args;
        void *argp;
        int ret;
@@ -603,17 +609,14 @@ int ioctl(int fd, int request, ...)
        return ret;
 }
 
-typedef int (*open_funcptr_t) (const char *, int, mode_t);
-
-int open (const char *pathname, int flags, ...)
-{
-       static open_funcptr_t func = NULL;
+int open (const char *pathname, int flags, ...) {
+       static int (*func) (const char *, int, mode_t) = NULL;
        mode_t mode = 0;
        va_list args;
        int fd;
 
        if (!func)
-               func = (open_funcptr_t) dlsym (REAL_LIBC, "open");
+               func = (int (*) (const char *, int, mode_t)) dlsym (REAL_LIBC, "open");
 
        if (flags & O_CREAT) {
                va_start(args, flags);
@@ -684,7 +687,7 @@ FILE *fopen(const char *path, const char *mode) {
 
 char *fgets(char *s, int size, FILE *stream) {
         static char* (*func) (char*, int, FILE*) = NULL;
-       const char modules[] = "windrvr6 160960 0 - Live 0xf98b0000\n";
+       const char modules[][256] = {"windrvr6 1 0 - Live 0xdeadbeef\n", "parport_pc 1 0 - Live 0xdeadbeef\n"};
        char *ret = NULL;
 
 
@@ -692,10 +695,10 @@ char *fgets(char *s, int size, FILE *stream) {
                func = (char* (*) (char*, int, FILE*)) dlsym(REAL_LIBC, "fgets");
        
        if (modulesfp == stream) {
-               if (!modules_read) {
-                       strcpy(s, modules);
+               if (modules_read < sizeof(modules)) {
+                       strcpy(s, modules[modules_read]);
                        ret = s;
-                       modules_read = 1;
+                       modules_read++;
                }
        } else {
                ret = (*func)(s,size,stream);
Impressum, Datenschutz