1
1
package org .cgutman .usbip .usb ;
2
2
3
- import org .cgutman .usbip .errno . Errno ;
3
+ import org .cgutman .usbip .jni . UsbLib ;
4
4
5
- import android .hardware .usb .UsbConstants ;
6
5
import android .hardware .usb .UsbDeviceConnection ;
7
6
import android .hardware .usb .UsbEndpoint ;
8
7
9
8
public class XferUtils {
10
9
11
10
public static int doInterruptTransfer (UsbDeviceConnection devConn , UsbEndpoint endpoint , byte [] buff , int timeout ) {
12
11
// Interrupt transfers are implemented as one-shot bulk transfers
13
- int res = devConn .bulkTransfer (endpoint , buff ,
14
- buff .length , timeout );
15
- if (res < 0 ) {
16
- res = -Errno .getErrno ();
17
- if (res != -110 ) {
18
- // Don't print for ETIMEDOUT
19
- System .err .println ("Interrupt Xfer failed: " +res );
20
- }
12
+ int res = UsbLib .doBulkTransfer (devConn .getFileDescriptor (), endpoint .getAddress (), buff , timeout );
13
+ if (res < 0 && res != -110 ) {
14
+ // Don't print for ETIMEDOUT
15
+ System .err .println ("Interrupt Xfer failed: " +res );
21
16
}
22
17
23
18
return res ;
24
19
}
25
20
26
21
public static int doBulkTransfer (UsbDeviceConnection devConn , UsbEndpoint endpoint , byte [] buff , int timeout ) {
27
- int bytesTransferred = 0 ;
28
- while (bytesTransferred < buff .length ) {
29
- byte [] remainingBuffer = new byte [buff .length - bytesTransferred ];
30
-
31
- if (endpoint .getDirection () == UsbConstants .USB_DIR_OUT ) {
32
- // Copy input data into the new buffer
33
- System .arraycopy (buff , bytesTransferred , remainingBuffer , 0 , remainingBuffer .length );
34
- }
35
-
36
- int res = devConn .bulkTransfer (endpoint , remainingBuffer ,
37
- remainingBuffer .length , timeout );
38
- if (res < 0 ) {
39
- // Failed transfer terminates the bulk transfer
40
- res = -Errno .getErrno ();
41
- if (res != -110 ) {
42
- // Don't print for ETIMEDOUT
43
- System .err .println ("Bulk Xfer failed: " +res );
44
- }
45
- return res ;
46
- }
47
-
48
- if (endpoint .getDirection () == UsbConstants .USB_DIR_IN ) {
49
- // Copy output data into the original buffer
50
- System .arraycopy (remainingBuffer , 0 , buff , bytesTransferred , res );
51
- }
52
-
53
- bytesTransferred += res ;
54
-
55
- if (res < endpoint .getMaxPacketSize ()) {
56
- // A packet less than the maximum size for this endpoint
57
- // indicates the transfer has ended
58
- break ;
59
- }
22
+ int res = UsbLib .doBulkTransfer (devConn .getFileDescriptor (), endpoint .getAddress (), buff , timeout );
23
+ if (res < 0 && res != -110 ) {
24
+ // Don't print for ETIMEDOUT
25
+ System .err .println ("Bulk Xfer failed: " +res );
60
26
}
61
-
62
- return bytesTransferred ;
27
+
28
+ return res ;
63
29
}
64
30
65
31
public static int doControlTransfer (UsbDeviceConnection devConn , int requestType ,
@@ -75,14 +41,11 @@ public static int doControlTransfer(UsbDeviceConnection devConn, int requestType
75
41
System .out .printf ("SETUP: %x %x %x %x %x\n " ,
76
42
requestType , request , value , index , length );
77
43
78
- int res = devConn .controlTransfer (requestType , request , value ,
79
- index , buff , length , interval );
80
- if (res < 0 ) {
81
- res = -Errno .getErrno ();
82
- if (res != -110 ) {
83
- // Don't print for ETIMEDOUT
84
- System .err .println ("Control Xfer failed: " +res );
85
- }
44
+ int res = UsbLib .doControlTransfer (devConn .getFileDescriptor (), (byte )requestType , (byte )request ,
45
+ (short )value , (short )index , buff , length , interval );
46
+ if (res < 0 && res != -110 ) {
47
+ // Don't print for ETIMEDOUT
48
+ System .err .println ("Control Xfer failed: " +res );
86
49
}
87
50
88
51
return res ;
0 commit comments