]> git.zerfleddert.de Git - usb-driver/blobdiff - usb-driver.c
cleanup parallel support a bit
[usb-driver] / usb-driver.c
index 881b67bf050fb19f5a45efe0620062e729d63a07..b4a15490f807824f5b18cf379e34f6f4b1c81af6 100644 (file)
@@ -258,33 +258,65 @@ int pp_transfer(WD_TRANSFER *tr, int fd, unsigned int request, unsigned char *wd
        if (parportfd < 0)
                return ret;
 
-       switch(tr->cmdTrans) {
-               case 10: /* Read Byte */
-                       if ((unsigned long)tr->dwPort == ppbase) { /* Data Port */
-                               ret = 0; /* We don't support reading of the data port */
-                       } else if ((unsigned long)tr->dwPort == ppbase + 1) { /* Status Port */
-                               DPRINTF("status port\n");
-                               ret = ioctl(parportfd, PPRSTATUS, &val);
-                       } else if ((unsigned long)tr->dwPort == ppbase + 2) { /* Control Port */
-                               DPRINTF("control port\n");
-                               ret = ioctl(parportfd, PPRCONTROL, &val);
+       switch((unsigned long)tr->dwPort - ppbase) {
+               case PP_DATA:
+                       DPRINTF("data port\n");
+                       switch(tr->cmdTrans) {
+                               case PP_READ:
+                                       ret = 0; /* We don't support reading of the data port */
+                                       break;
+
+                               case PP_WRITE:
+                                       ret = ioctl(parportfd, PPWDATA, &val);
+                                       break;
+
+                               default:
+                                       fprintf(stderr,"!!!Unsupported TRANSFER command: %lu!!!\n", tr->cmdTrans);
+                                       ret = -1;
+                                       break;
                        }
-                       break;
-               case 13: /* Write Byte */
-                       if ((unsigned long)tr->dwPort == ppbase) { /* Data Port */
-                               DPRINTF("data port\n");
-                               ret = ioctl(parportfd, PPWDATA, &val);
-                       } else if ((unsigned long)tr->dwPort == ppbase + 1) { /* Status Port */
-                               ret = 0; /* Status Port is readonly */
-                       } else if ((unsigned long)tr->dwPort == ppbase + 2) { /* Control Port */
-                               DPRINTF("control port\n");
-                               ret = ioctl(parportfd, PPWCONTROL, &val);
+               break;
+
+               case PP_STATUS:
+                       DPRINTF("status port\n");
+                       switch(tr->cmdTrans) {
+                               case PP_READ:
+                                       ret = ioctl(parportfd, PPRSTATUS, &val);
+                                       break;
+
+                               case PP_WRITE:
+                                       ret = 0; /* Status Port is readonly */
+                                       break;
+
+                               default:
+                                       fprintf(stderr,"!!!Unsupported TRANSFER command: %lu!!!\n", tr->cmdTrans);
+                                       ret = -1;
+                                       break;
                        }
-                       break;
+               break;
+
+               case PP_CONTROL:
+                       DPRINTF("control port\n");
+                       switch(tr->cmdTrans) {
+                               case PP_READ:
+                                       ret = ioctl(parportfd, PPRCONTROL, &val);
+                                       break;
+
+                               case PP_WRITE:
+                                       ret = ioctl(parportfd, PPWCONTROL, &val);
+                                       break;
+
+                               default:
+                                       fprintf(stderr,"!!!Unsupported TRANSFER command: %lu!!!\n", tr->cmdTrans);
+                                       ret = -1;
+                                       break;
+                       }
+               break;
+
                default:
-                       fprintf(stderr,"!!!Unsupported TRANSFER command: %lu!!!\n", tr->cmdTrans);
-                       ret = -1;
-                       break;
+                       DPRINTF("access to unsupported address range (probably ECP)!\n");
+                       ret = 0;
+               break;
        }
 
        tr->Data.Byte = val;
@@ -349,6 +381,9 @@ int do_wdioctl(int fd, unsigned int request, unsigned char *wdioctl) {
                                        DPRINTF("opening %s\n", ppdev);
                                        parportfd = open(ppdev, O_RDWR|O_EXCL);
                                        parportnum++;
+
+                                       if (parportfd < 0)
+                                               fprintf(stderr,"Can't open %s: %s\n", ppdev, strerror(errno));
                                }
 
                                if (parportfd >= 0) {
@@ -357,17 +392,20 @@ int do_wdioctl(int fd, unsigned int request, unsigned char *wdioctl) {
                                        if (ioctl(parportfd, PPCLAIM) == -1)
                                                return ret;
 
+                                       ecpbase = 0;
                                        pmode = IEEE1284_MODE_COMPAT;
                                        if (ioctl(parportfd, PPNEGOT, &pmode) == -1)
                                                return ret;
                                        
-                                       if (cr->Card.dwItems > 1) {
+                                       if (cr->Card.dwItems > 1 && cr->Card.Item[1].I.IO.dwBytes) {
+                                               DPRINTF("ECP mode requested\n");
                                                ecpbase = cr->Card.Item[1].I.IO.dwBytes;
                                                /* TODO: Implement ECP mode */
 #if 0
                                                pmode = IEEE1284_MODE_ECP;
 
                                                if (ioctl(parportfd, PPNEGOT, &pmode) == -1) {
+                                                       ecpbase = 0;
                                                        pmode = IEEE1284_MODE_COMPAT;
                                                        if (ioctl(parportfd, PPNEGOT, &pmode) == -1)
                                                                return ret;
Impressum, Datenschutz