@@ -577,7 +577,7 @@ public void submitUrbRequest(Socket s, UsbIpSubmitUrb msg) {
577
577
578
578
// We have to handle certain control requests (SET_CONFIGURATION/SET_INTERFACE) by calling
579
579
// Android APIs rather than just submitting the URB directly to the device
580
- if (!UsbControlHelper .handleInternalControlTransfer (dev , devConn , requestType , request , value , index )) {
580
+ if (!UsbControlHelper .handleInternalControlTransfer (context , requestType , request , value , index )) {
581
581
do {
582
582
res = XferUtils .doControlTransfer (devConn , requestType , request , value , index ,
583
583
(requestType & 0x80 ) != 0 ? reply .inData : msg .outData , length , 1000 );
@@ -613,35 +613,40 @@ public void submitUrbRequest(Socket s, UsbIpSubmitUrb msg) {
613
613
else {
614
614
// Find the correct endpoint
615
615
UsbEndpoint selectedEndpoint = null ;
616
- for (int i = 0 ; i < dev .getInterfaceCount (); i ++) {
617
- // Check each interface
618
- UsbInterface iface = dev .getInterface (i );
619
- for (int j = 0 ; j < iface .getEndpointCount (); j ++) {
620
- // Check the endpoint number
621
- UsbEndpoint endpoint = iface .getEndpoint (j );
622
- if (msg .ep == endpoint .getEndpointNumber ()) {
623
- // Check the direction
624
- if (msg .direction == UsbIpDevicePacket .USBIP_DIR_IN ) {
625
- if (endpoint .getDirection () != UsbConstants .USB_DIR_IN ) {
626
- continue ;
616
+ if (context .activeConfiguration != null ) {
617
+ for (int i = 0 ; i < context .activeConfiguration .getInterfaceCount (); i ++) {
618
+ // Check each interface
619
+ UsbInterface iface = context .activeConfiguration .getInterface (i );
620
+ for (int j = 0 ; j < iface .getEndpointCount (); j ++) {
621
+ // Check the endpoint number
622
+ UsbEndpoint endpoint = iface .getEndpoint (j );
623
+ if (msg .ep == endpoint .getEndpointNumber ()) {
624
+ // Check the direction
625
+ if (msg .direction == UsbIpDevicePacket .USBIP_DIR_IN ) {
626
+ if (endpoint .getDirection () != UsbConstants .USB_DIR_IN ) {
627
+ continue ;
628
+ }
627
629
}
628
- }
629
- else {
630
- if ( endpoint . getDirection () != UsbConstants . USB_DIR_OUT ) {
631
- continue ;
630
+ else {
631
+ if ( endpoint . getDirection () != UsbConstants . USB_DIR_OUT ) {
632
+ continue ;
633
+ }
632
634
}
635
+
636
+ // This the right endpoint
637
+ selectedEndpoint = endpoint ;
638
+ break ;
633
639
}
634
-
635
- // This the right endpoint
636
- selectedEndpoint = endpoint ;
640
+ }
641
+
642
+ // Check if we found the endpoint on the last interface
643
+ if (selectedEndpoint != null ) {
637
644
break ;
638
645
}
639
646
}
640
-
641
- // Check if we found the endpoint on the last interface
642
- if (selectedEndpoint != null ) {
643
- break ;
644
- }
647
+ }
648
+ else {
649
+ System .err .println ("Attempted to transfer to non-control EP before SET_CONFIGURATION!" );
645
650
}
646
651
647
652
if (selectedEndpoint == null ) {
@@ -735,13 +740,6 @@ public boolean attachToDevice(Socket s, String busId) {
735
740
return false ;
736
741
}
737
742
738
- // Claim all interfaces since we don't know which one the client wants
739
- for (int i = 0 ; i < dev .getInterfaceCount (); i ++) {
740
- if (!devConn .claimInterface (dev .getInterface (i ), true )) {
741
- System .err .println ("Unable to claim interface " +dev .getInterface (i ).getId ());
742
- }
743
- }
744
-
745
743
// Create a context for this attachment
746
744
AttachedDeviceContext context = new AttachedDeviceContext ();
747
745
context .devConn = devConn ;
@@ -841,11 +839,5 @@ public void abortUrbRequest(Socket s, UsbIpUnlinkUrb msg) {
841
839
found ? UsbIpSubmitUrb .USBIP_STATUS_URB_ABORTED :
842
840
-22 ); // EINVAL
843
841
}
844
-
845
- static class AttachedDeviceContext {
846
- public UsbDevice device ;
847
- public UsbDeviceConnection devConn ;
848
- public ThreadPoolExecutor requestPool ;
849
- public HashSet <UsbIpSubmitUrb > activeMessages ;
850
- }
842
+
851
843
}
0 commit comments