diff options
author | Nikias Bassen | 2009-08-03 19:00:38 +0200 |
---|---|---|
committer | Nikias Bassen | 2009-08-03 19:00:38 +0200 |
commit | 1d006240c339dd950c5b4da8000289fba9105c0d (patch) | |
tree | 9940243490fe6e215dc56d7979c7579be3c0c435 /src/usbmux.c | |
parent | dcc304e88a4d1e2261871a5d4a66bdc8fe4b5339 (diff) | |
download | usbmuxd-1d006240c339dd950c5b4da8000289fba9105c0d.tar.gz usbmuxd-1d006240c339dd950c5b4da8000289fba9105c0d.tar.bz2 |
Fix usb communication problem
To do this properly, we just have to send an additional zero length usb
packet when we encounter a packet of size wMaxPacketSize or one of its
multiplicants.
Diffstat (limited to 'src/usbmux.c')
-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 { struct usb_dev_handle *usbdev; struct usb_device *__device; receivebuf_t usbReceive; + int wMaxPacketSize; }; typedef struct { @@ -272,6 +273,24 @@ static int usbmux_config_usb_device(usbmux_device_t device) log_debug_msg("done.\n"); } + // get the last configuration + struct usb_config_descriptor *cfg = &device->__device->config[device->__device->descriptor.bNumConfigurations-1]; + if (cfg && cfg->bNumInterfaces >= 2) { + struct usb_interface *ifp = &cfg->interface[1]; + if (ifp && ifp->num_altsetting >= 1) { + struct usb_interface_descriptor *as = &ifp->altsetting[0]; + int i; + for (i = 0; i < as->bNumEndpoints; i++) { + struct usb_endpoint_descriptor *ep=&as->endpoint[i]; + if (ep->bEndpointAddress == BULKOUT) { + device->wMaxPacketSize = ep->wMaxPacketSize; + } + } + } + } + + log_debug_msg("Setting wMaxPacketSize to %d\n", device->wMaxPacketSize); + do { bytes = usb_bulk_read(device->usbdev, BULKIN, buf, 512, 800); } while (bytes > 0); @@ -316,6 +335,9 @@ int usbmux_get_specific_device(int bus_n, int dev_n, newdevice->usbReceive.leftover = 0; newdevice->usbReceive.capacity = 0; + // wMaxPacketSize + newdevice->wMaxPacketSize = 64; + // Initialize libusb usb_init(); usb_find_busses(); @@ -328,7 +350,7 @@ int usbmux_get_specific_device(int bus_n, int dev_n, if (strtol(dev->filename, NULL, 10) == dev_n) { newdevice->__device = dev; newdevice->usbdev = usb_open(newdevice->__device); - if (!newdevice->usbdev) { + if (!newdevice->usbdev) { fprintf(stderr, "%s: Error: usb_open(): %s\n", __func__, usb_strerror()); } if (usbmux_config_usb_device(newdevice) == 0) { @@ -495,6 +517,15 @@ if (toto_debug > 0) { datalen -= bytes; continue; } + if ((bytes % device->wMaxPacketSize) == 0) { + log_debug_msg("NOTE: sending NULL packet\n"); + char nullp = 0; + int res = usb_bulk_write(device->usbdev, BULKOUT, + &nullp, 0, timeout); + if (res < 0) { + log_debug_msg("ERROR: NULL packet write returned %d\n", res); + } + } } while (0); // fall out if (bytes > 0) { |