]> cvs.zerfleddert.de Git - usb-driver/blobdiff - usb-driver.c
add xpcu_set_interface
[usb-driver] / usb-driver.c
index 647a5bcf2ba7be8a6a13a0172e6c7476b4713398..1a37f54255ec4d098792163def8066eed65b0a0d 100644 (file)
@@ -160,32 +160,7 @@ static int do_wdioctl(int fd, unsigned int request, unsigned char *wdioctl) {
 #ifndef NO_WINDRVR
                                ret = (*ioctl_func) (fd, request, wdioctl);
 #else
-                               xpcu_claim(xpcu, XPCU_CLAIM);
-                               /* 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);
-                                       DPRINTF("requesttype: %x, request: %x, value: %u, index: %u, size: %u\n", requesttype, request, value, index, size);
-                                       ret = usb_control_msg(xpcu->handle, requesttype, request, value, index, ut->pBuffer, size, ut->dwTimeout);
-                               } else {
-                                       if (ut->fRead) {
-                                               ret = usb_bulk_read(xpcu->handle, ut->dwPipeNum, ut->pBuffer, ut->dwBufferSize, ut->dwTimeout);
-                                       } else {
-                                               ret = usb_bulk_write(xpcu->handle, ut->dwPipeNum, ut->pBuffer, ut->dwBufferSize, ut->dwTimeout);
-                                       }
-                                       xpcu_claim(xpcu, XPCU_RELEASE);
-                               }
-
-                               if (ret < 0) {
-                                       fprintf(stderr, "usb_transfer: %d (%s)\n", ret, usb_strerror());
-                               } else {
-                                       ut->dwBytesTransferred = ret;
-                                       ret = 0;
-                               }
+                               xpcu_transfer(xpcu, ut);
 #endif
 
 #ifdef DEBUG
@@ -254,20 +229,7 @@ static int do_wdioctl(int fd, unsigned int request, unsigned char *wdioctl) {
 #ifndef NO_WINDRVR
                                ret = (*ioctl_func) (fd, request, wdioctl);
 #else
-                               if (xpcu->dev) {
-                                       if (!xpcu->handle) {
-                                               xpcu->handle = usb_open(xpcu->dev);
-#ifndef NO_USB_RESET
-                                               if (xpcu->handle) {
-                                                       usb_reset(xpcu->handle);
-                                                       xpcu->handle = usb_open(xpcu->dev);
-                                               }
-#endif
-                                       }
-
-                                       xpcu->interface = xpcu->dev->config[0].interface[usi->dwInterfaceNum].altsetting[usi->dwAlternateSetting].bInterfaceNumber;
-                                       xpcu->alternate = usi->dwAlternateSetting;
-                               }
+                               xpcu_set_interface(xpcu, usi);
 #endif
                                DPRINTF("unique: %lu, interfacenum: %lu, alternatesetting: %lu, options: %lx\n",
                                usi->dwUniqueID, usi->dwInterfaceNum,
@@ -658,13 +620,9 @@ int close(int fd) {
        if (fd == windrvrfd && windrvrfd >= 0) {
                DPRINTF("close windrvrfd\n");
 
-               if (xpcu->handle) {
-                       xpcu_claim(xpcu, XPCU_RELEASE);
-                       usb_close(xpcu->handle);
-               }
+               if (xpcu)
+                       xpcu_close(xpcu);
 
-               xpcu->handle = NULL;
-               xpcu->interface = -1;
                xpcu = NULL;
                windrvrfd = -1;
        }
Impressum, Datenschutz