Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions app/src/main/java/org/cgutman/usbip/service/UsbIpService.java
Original file line number Diff line number Diff line change
Expand Up @@ -558,10 +558,11 @@ public void submitUrbRequest(Socket s, UsbIpSubmitUrb msg) {
context.activeMessages.add(msg);

int res;

boolean isDeviceToHost = (requestType & 0x80) != 0;

do {
res = XferUtils.doControlTransfer(devConn, requestType, request, value, index,
(requestType & 0x80) != 0 ? reply.inData : msg.outData, length, 1000);
isDeviceToHost ? reply.inData : msg.outData, length, 1000);

if (context.requestPool.isShutdown()) {
// Bail if the queue is being torn down
Expand All @@ -578,7 +579,7 @@ public void submitUrbRequest(Socket s, UsbIpSubmitUrb msg) {
reply.status = res;
}
else {
reply.actualLength = res;
reply.actualLength = isDeviceToHost ? res : 0;
reply.status = ProtoDefs.ST_OK;
}

Expand Down
3 changes: 2 additions & 1 deletion app/src/main/java/org/cgutman/usbip/usb/XferUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,10 @@ public static int doBulkTransfer(UsbDeviceConnection devConn, UsbEndpoint endpoi

bytesTransferred += res;

if (res < endpoint.getMaxPacketSize()) {
if (res != endpoint.getMaxPacketSize()) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I wonder if this is needed or if the while condition is sufficient. Does it work properly if you remove this check entirely?

Copy link
Author

@paweljasinski paweljasinski Oct 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First of all the request comes with buff.length (expected) size of 65536. The only reasonable interpretation is maximum size. So we can't check buff.length vs. transferred size. Yubikey is sending back a certificate which is a variable size.
Second, I know this code is by definition wrong, because I can manipulate certificate to be exactly max packet size.

Now back to your question.
If I take the condition out it will terminate with timeout and return error.
Perhaps if there is nothing more, it would return right away. Nop, it is a real timeout with 1000ms.
I am reading the server part of the linux driver to figure out how it is done. First impression, things depend on transfer flags.

// A packet less than the maximum size for this endpoint
// indicates the transfer has ended
// For some devices (yubikey) the res is greater than max packet size
break;
}
}
Expand Down