|
21 | 21 | import org.cgutman.usbip.server.protocol.dev.UsbIpSubmitUrbReply;
|
22 | 22 | import org.cgutman.usbip.usb.DescriptorReader;
|
23 | 23 | import org.cgutman.usbip.usb.UsbDeviceDescriptor;
|
| 24 | +import org.cgutman.usbip.usb.XferUtils; |
24 | 25 |
|
25 | 26 | import android.annotation.SuppressLint;
|
26 | 27 | import android.app.PendingIntent;
|
@@ -286,46 +287,18 @@ public void run() {
|
286 | 287 | buff.array().length, msg.direction == UsbIpDevicePacket.USBIP_DIR_IN ? "in" : "out",
|
287 | 288 | selectedEndpoint.getEndpointNumber());
|
288 | 289 |
|
289 |
| - // Bulk is handled via a helper method |
290 |
| - byte[] bulkBuffer = buff.array(); |
291 |
| - |
292 |
| - int bytesTransferred = 0; |
293 |
| - while (bytesTransferred < bulkBuffer.length) { |
294 |
| - byte[] remainingBuffer = new byte[bulkBuffer.length - bytesTransferred]; |
295 |
| - |
296 |
| - if (msg.direction == UsbIpDevicePacket.USBIP_DIR_OUT) { |
297 |
| - // Copy input data into the new buffer |
298 |
| - System.arraycopy(bulkBuffer, bytesTransferred, remainingBuffer, 0, remainingBuffer.length); |
299 |
| - } |
300 |
| - |
301 |
| - int res = context.devConn.bulkTransfer(selectedEndpoint, remainingBuffer, |
302 |
| - remainingBuffer.length, msg.interval); |
303 |
| - if (res < 0) { |
304 |
| - // Failed transfer terminates the bulk transfer |
305 |
| - System.err.println("Bulk Xfer failed: "+res); |
306 |
| - sendReply(replyOut, reply, ProtoDefs.ST_NA); |
307 |
| - return; |
308 |
| - } |
309 |
| - |
310 |
| - if (msg.direction == UsbIpDevicePacket.USBIP_DIR_IN) { |
311 |
| - // Copy output data into the original buffer |
312 |
| - System.arraycopy(remainingBuffer, 0, bulkBuffer, bytesTransferred, res); |
313 |
| - } |
314 |
| - |
315 |
| - bytesTransferred += res; |
316 |
| - |
317 |
| - if (res < selectedEndpoint.getMaxPacketSize()) { |
318 |
| - // A packet less than the maximum size for this endpoint |
319 |
| - // indicates the transfer has ended |
320 |
| - break; |
321 |
| - } |
322 |
| - } |
| 290 | + int res = XferUtils.doBulkTransfer(context.devConn,selectedEndpoint, buff.array(), msg.interval); |
323 | 291 |
|
324 | 292 | System.out.printf("Bulk transfer complete with %d bytes (wanted %d)\n",
|
325 |
| - bytesTransferred, msg.transferBufferLength); |
| 293 | + res, msg.transferBufferLength); |
326 | 294 |
|
327 |
| - reply.actualLength = bytesTransferred; |
328 |
| - reply.status = ProtoDefs.ST_OK; |
| 295 | + if (res < 0) { |
| 296 | + reply.status = ProtoDefs.ST_NA; |
| 297 | + } |
| 298 | + else { |
| 299 | + reply.actualLength = res; |
| 300 | + reply.status = ProtoDefs.ST_OK; |
| 301 | + } |
329 | 302 | sendReply(replyOut, reply, reply.status);
|
330 | 303 | }
|
331 | 304 | else if (selectedEndpoint.getType() == UsbConstants.USB_ENDPOINT_XFER_INT) {
|
@@ -429,25 +402,22 @@ public void submitUrbRequest(OutputStream replyOut, UsbIpSubmitUrb msg) {
|
429 | 402 | short value = bb.getShort();
|
430 | 403 | short index = bb.getShort();
|
431 | 404 | short length = bb.getShort();
|
432 |
| - |
433 |
| - System.out.printf("%x %x %x %x %x\n", |
434 |
| - requestType, request, value, index, length); |
435 | 405 |
|
436 | 406 | if (length != 0) {
|
437 | 407 | reply.inData = new byte[length];
|
438 | 408 | }
|
439 |
| - int res = devConn.controlTransfer(requestType, request, value, |
440 |
| - index, |
441 |
| - (requestType & 0x80) != 0 ? reply.inData : msg.outData, |
442 |
| - length, msg.interval); |
| 409 | + |
| 410 | + int res = XferUtils.doControlTransfer(devConn, requestType, request, value, index, |
| 411 | + (requestType & 0x80) != 0 ? reply.inData : msg.outData, length, msg.interval); |
443 | 412 | if (res < 0) {
|
444 |
| - System.err.println("Control Xfer failed: "+res); |
445 |
| - sendReply(replyOut, reply, ProtoDefs.ST_NA); |
446 |
| - return; |
| 413 | + reply.status = ProtoDefs.ST_NA; |
| 414 | + } |
| 415 | + else { |
| 416 | + reply.actualLength = res; |
| 417 | + reply.status = ProtoDefs.ST_OK; |
447 | 418 | }
|
448 | 419 |
|
449 |
| - reply.actualLength = res; |
450 |
| - sendReply(replyOut, reply, ProtoDefs.ST_OK); |
| 420 | + sendReply(replyOut, reply, reply.status); |
451 | 421 | return;
|
452 | 422 | }
|
453 | 423 | else {
|
|
0 commit comments