]> git.zerfleddert.de Git - usb-driver/commitdiff
really support multiple parallel ports
authormichael <michael>
Sun, 1 Apr 2007 15:47:52 +0000 (15:47 +0000)
committermichael <michael>
Sun, 1 Apr 2007 15:47:52 +0000 (15:47 +0000)
usb-driver.c
usb-driver.h

index a7d14bf5f8a93f05b9d8f53b4c9ab9663c2ab5c7..fa2611e8c3ea19c9261a4f4488fa083554076aec 100644 (file)
@@ -46,9 +46,9 @@
 static int (*ioctl_func) (int, int, void *) = NULL;
 static int windrvrfd = -1;
 static int parportfd = -1;
-static int parportnum = 0;
 static unsigned long ppbase = 0;
 static unsigned long ecpbase = 0;
+static struct pports *pplist = NULL;
 FILE *modulesfp = NULL;
 static int modules_read = 0;
 static struct usb_bus *busses = NULL;
@@ -376,10 +376,36 @@ int do_wdioctl(int fd, unsigned int request, unsigned char *wdioctl) {
                                ret = (*ioctl_func) (fd, request, wdioctl);
 #else
                                if (parportfd < 0) {
-                                       if (ppbase && ((unsigned long)cr->Card.Item[0].I.IO.dwAddr != ppbase))
-                                               parportnum++;
+                                       int max = -1;
+                                       struct pports **port = &pplist;
 
-                                       snprintf(ppdev, sizeof(ppdev), "/dev/parport%d", parportnum);
+                                       while (*port) {
+                                               DPRINTF("Looking up parallel port in linked list, entry: %d\n", (*port)->num);
+                                               if (max < (*port)->num)
+                                                       max = (*port)->num;
+
+                                               if ((*port)->base == (unsigned long)cr->Card.Item[0].I.IO.dwAddr) {
+                                                       break;
+                                               }
+
+                                               port = &((*port)->next);
+                                       }
+
+                                       if (!(*port)) { /* not found */
+                                               (*port) = malloc(sizeof(struct pports));
+                                               if (!(*port)) {
+                                                       perror("malloc");
+                                                       exit(EXIT_FAILURE);
+                                               }
+
+                                               (*port)->base = (unsigned long)cr->Card.Item[0].I.IO.dwAddr;
+                                               (*port)->num = max+1;
+                                               (*port)->next = NULL;
+
+                                               DPRINTF("parallel port not in linked list, new entry: %d\n", (*port)->num);
+                                       }
+
+                                       snprintf(ppdev, sizeof(ppdev), "/dev/parport%d", (*port)->num);
                                        DPRINTF("opening %s\n", ppdev);
                                        parportfd = open(ppdev, O_RDWR|O_EXCL);
 
index 3487b7bb631241a5c2c59fe86ac42a8beb4ccf9d..5bfd9377848f45cf43629810886d423ebd910c59 100644 (file)
 
 #define WDU_GET_MAX_PACKET_SIZE(x)                ((unsigned short) (((x) & 0x7ff) * (1 + (((x) & 0x1800) >> 11))))
 
+struct pports {
+       unsigned long base;
+       int num;
+       struct pports *next;
+};
+
 /* http://www.jungo.com/support/documentation/windriver/811/wdusb_man_mhtml/node78.html#SECTION001734000000000000000 */
 
 struct header_struct {
Impressum, Datenschutz