diff options
| -rw-r--r-- | src/usbmux.c | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/src/usbmux.c b/src/usbmux.c index 1d6497e..dd3ac1a 100644 --- a/src/usbmux.c +++ b/src/usbmux.c | |||
| @@ -58,6 +58,7 @@ struct usbmux_device_int { | |||
| 58 | struct usb_dev_handle *usbdev; | 58 | struct usb_dev_handle *usbdev; |
| 59 | struct usb_device *__device; | 59 | struct usb_device *__device; |
| 60 | receivebuf_t usbReceive; | 60 | receivebuf_t usbReceive; |
| 61 | int wMaxPacketSize; | ||
| 61 | }; | 62 | }; |
| 62 | 63 | ||
| 63 | typedef struct { | 64 | typedef struct { |
| @@ -272,6 +273,24 @@ static int usbmux_config_usb_device(usbmux_device_t device) | |||
| 272 | log_debug_msg("done.\n"); | 273 | log_debug_msg("done.\n"); |
| 273 | } | 274 | } |
| 274 | 275 | ||
| 276 | // get the last configuration | ||
| 277 | struct usb_config_descriptor *cfg = &device->__device->config[device->__device->descriptor.bNumConfigurations-1]; | ||
| 278 | if (cfg && cfg->bNumInterfaces >= 2) { | ||
| 279 | struct usb_interface *ifp = &cfg->interface[1]; | ||
| 280 | if (ifp && ifp->num_altsetting >= 1) { | ||
| 281 | struct usb_interface_descriptor *as = &ifp->altsetting[0]; | ||
| 282 | int i; | ||
| 283 | for (i = 0; i < as->bNumEndpoints; i++) { | ||
| 284 | struct usb_endpoint_descriptor *ep=&as->endpoint[i]; | ||
| 285 | if (ep->bEndpointAddress == BULKOUT) { | ||
| 286 | device->wMaxPacketSize = ep->wMaxPacketSize; | ||
| 287 | } | ||
| 288 | } | ||
| 289 | } | ||
| 290 | } | ||
| 291 | |||
| 292 | log_debug_msg("Setting wMaxPacketSize to %d\n", device->wMaxPacketSize); | ||
| 293 | |||
| 275 | do { | 294 | do { |
| 276 | bytes = usb_bulk_read(device->usbdev, BULKIN, buf, 512, 800); | 295 | bytes = usb_bulk_read(device->usbdev, BULKIN, buf, 512, 800); |
| 277 | } while (bytes > 0); | 296 | } while (bytes > 0); |
| @@ -316,6 +335,9 @@ int usbmux_get_specific_device(int bus_n, int dev_n, | |||
| 316 | newdevice->usbReceive.leftover = 0; | 335 | newdevice->usbReceive.leftover = 0; |
| 317 | newdevice->usbReceive.capacity = 0; | 336 | newdevice->usbReceive.capacity = 0; |
| 318 | 337 | ||
| 338 | // wMaxPacketSize | ||
| 339 | newdevice->wMaxPacketSize = 64; | ||
| 340 | |||
| 319 | // Initialize libusb | 341 | // Initialize libusb |
| 320 | usb_init(); | 342 | usb_init(); |
| 321 | usb_find_busses(); | 343 | usb_find_busses(); |
| @@ -328,7 +350,7 @@ int usbmux_get_specific_device(int bus_n, int dev_n, | |||
| 328 | if (strtol(dev->filename, NULL, 10) == dev_n) { | 350 | if (strtol(dev->filename, NULL, 10) == dev_n) { |
| 329 | newdevice->__device = dev; | 351 | newdevice->__device = dev; |
| 330 | newdevice->usbdev = usb_open(newdevice->__device); | 352 | newdevice->usbdev = usb_open(newdevice->__device); |
| 331 | if (!newdevice->usbdev) { | 353 | if (!newdevice->usbdev) { |
| 332 | fprintf(stderr, "%s: Error: usb_open(): %s\n", __func__, usb_strerror()); | 354 | fprintf(stderr, "%s: Error: usb_open(): %s\n", __func__, usb_strerror()); |
| 333 | } | 355 | } |
| 334 | if (usbmux_config_usb_device(newdevice) == 0) { | 356 | if (usbmux_config_usb_device(newdevice) == 0) { |
| @@ -495,6 +517,15 @@ if (toto_debug > 0) { | |||
| 495 | datalen -= bytes; | 517 | datalen -= bytes; |
| 496 | continue; | 518 | continue; |
| 497 | } | 519 | } |
| 520 | if ((bytes % device->wMaxPacketSize) == 0) { | ||
| 521 | log_debug_msg("NOTE: sending NULL packet\n"); | ||
| 522 | char nullp = 0; | ||
| 523 | int res = usb_bulk_write(device->usbdev, BULKOUT, | ||
| 524 | &nullp, 0, timeout); | ||
| 525 | if (res < 0) { | ||
| 526 | log_debug_msg("ERROR: NULL packet write returned %d\n", res); | ||
| 527 | } | ||
| 528 | } | ||
| 498 | } while (0); // fall out | 529 | } while (0); // fall out |
| 499 | 530 | ||
| 500 | if (bytes > 0) { | 531 | if (bytes > 0) { |
