summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Hector Martin2009-08-13 00:56:59 +0200
committerGravatar Hector Martin2009-08-13 01:29:55 +0200
commit882543b1e42a960b714fa3aa9b05f9029513b5c1 (patch)
tree48ed88ceb58b5b3072b17623b7fbe31fbae9fc7b
parent339112a796f774600a55ab143cad0a6123496606 (diff)
downloadusbmuxd-882543b1e42a960b714fa3aa9b05f9029513b5c1.tar.gz
usbmuxd-882543b1e42a960b714fa3aa9b05f9029513b5c1.tar.bz2
Remove obsolete patches, update code and comments for libusb git.
Please use libusb git as of the time of this writing, or 1.0.3 whenever it comes out.
-rw-r--r--README26
-rw-r--r--patches/libusb-add-zlp-flag.patch24
-rw-r--r--patches/valgrind-usbdevfs.patch133
-rw-r--r--usbmuxd/usb-linux.c4
-rw-r--r--usbmuxd/usb.h6
5 files changed, 16 insertions, 177 deletions
diff --git a/README b/README
index 7e5c2bb..430f217 100644
--- a/README
+++ b/README
@@ -8,22 +8,18 @@ command/response payloads instead of binary blobs. The outer binary protocol is
still the same used but now the only command/response format is 8 (plist).
The server is under the usbmuxd directory. You'll need CMake and libusb 1.0 to
-build it. In addition, you need to apply the libusb patch in the patches/
-directory. If you want to debug using valgrind, apply the valgrind patch to
-improve the handling of the USB device filesystem ioctls.
+build it. Due to a bug in zero-length packet handling, you'll need either the
+git version of libusb or 1.0.3, whenever it comes out.
There is a Python client library in the python-client directory. It should be
compatible with Windows, Linux, and OSX (using the Apple usbmuxd on Win and OSX)
tcprelay.py implements a TCP connection forwarder that lets you pipe TCP
-connections to localhost to the phone. Run it with --help for usage. Note that
-under OSX you'll have to change the socket path from /tmp/usbmuxd to
-/var/run/usbmuxd (there is no socket path on Windows, only a TCP connection to
-localhost). The Python client lib is also compatible with the new plist-based
-protocol and should automatically select it if it sees such a server. However,
-you need Python 2.6 for Windows and Linux in this case, since the plistlib
-module doesn't come with older versions under these OSes (not that you'll have a
-server that supports this protocol under Linux. TODO: does Windows iTunes even
-use this yet?)
+connections to localhost to the phone. Run it with --help for usage. The Python
+client lib is also compatible with the new plist-based protocol and should
+automatically select it if it sees such a server. However, you need Python 2.6
+for Windows and Linux in this case, since the plistlib module doesn't come with
+older versions under these OSes (not that you'll have a server that supports
+this protocol under Linux. TODO: does Windows iTunes use this yet?)
ARCHITECTURE
@@ -100,7 +96,9 @@ GOTCHAS AND ANNOYANCES
The usbmuxd CONNECT request port field is byte-swapped (network-endian). This is
even more annoying for the plist based protocol, since it's even true there
(where the field is plain text). So even for the plain text int, you need to
-swap the bytes (port 22 becomes <integer>5632</integer>).
+swap the bytes (port 22 becomes <integer>5632</integer>). I have no clue if this
+is the case on the new plist protocol on PPC macs (is the newer iTunes available
+for those?)
There are a bunch of gotchas due to the USB framing, and this is even worse
because implementations tend to get it wrong (i.e. libusb, and this is the
@@ -135,7 +133,7 @@ is normally not an issue, but it's annoying for debugging because lost packets
gets out of sync and then might crash and burn dozens of packets later.
The server needs a proper front-end (i.e. daemonizing, commandline options,
-etc), a lot of testing, and some optimizing.
+etc), more testing, and some optimizing.
Someone should probably do some edge-case testing on the TCP stuff.
diff --git a/patches/libusb-add-zlp-flag.patch b/patches/libusb-add-zlp-flag.patch
deleted file mode 100644
index add9f97..0000000
--- a/patches/libusb-add-zlp-flag.patch
+++ /dev/null
@@ -1,24 +0,0 @@
-diff -ur libusb-1.0.0/libusb/os/linux_usbfs.c libusb-1.0.0-mod/libusb/os/linux_usbfs.c
---- libusb-1.0.0/libusb/os/linux_usbfs.c 2008-12-13 20:43:20.000000000 +0100
-+++ libusb-1.0.0-mod/libusb/os/linux_usbfs.c 2009-04-30 04:25:12.000000000 +0200
-@@ -1295,7 +1295,8 @@
- urb->buffer_length = transfer->length % MAX_BULK_BUFFER_LENGTH;
- else
- urb->buffer_length = MAX_BULK_BUFFER_LENGTH;
--
-+ if ((!(transfer->endpoint & LIBUSB_ENDPOINT_DIR_MASK)) && (i == num_urbs - 1))
-+ urb->flags = USBFS_URB_ZLP;
- r = ioctl(dpriv->fd, IOCTL_USBFS_SUBMITURB, urb);
- if (r < 0) {
- int j;
-diff -ur libusb-1.0.0/libusb/os/linux_usbfs.h libusb-1.0.0-mod/libusb/os/linux_usbfs.h
---- libusb-1.0.0/libusb/os/linux_usbfs.h 2008-07-16 16:17:57.000000000 +0200
-+++ libusb-1.0.0-mod/libusb/os/linux_usbfs.h 2009-04-30 04:08:27.000000000 +0200
-@@ -63,6 +63,7 @@
- #define USBFS_URB_DISABLE_SPD 1
- #define USBFS_URB_ISO_ASAP 2
- #define USBFS_URB_QUEUE_BULK 0x10
-+#define USBFS_URB_ZLP 0x40
-
- enum usbfs_urb_type {
- USBFS_URB_TYPE_ISO = 0,
diff --git a/patches/valgrind-usbdevfs.patch b/patches/valgrind-usbdevfs.patch
deleted file mode 100644
index 9287573..0000000
--- a/patches/valgrind-usbdevfs.patch
+++ /dev/null
@@ -1,133 +0,0 @@
-diff -ur -x '*~' valgrind-3.4.1/coregrind/m_syswrap/syswrap-generic.c valgrind-3.4.1-mod/coregrind/m_syswrap/syswrap-generic.c
---- valgrind-3.4.1/coregrind/m_syswrap/syswrap-generic.c 2009-03-01 23:01:09.000000000 +0100
-+++ valgrind-3.4.1-mod/coregrind/m_syswrap/syswrap-generic.c 2009-04-29 15:44:08.000000000 +0200
-@@ -4160,23 +4160,56 @@
- struct vki_usbdevfs_urb *vkuu = (struct vki_usbdevfs_urb *)ARG3;
-
- /* Not the whole struct needs to be initialized */
-- PRE_MEM_READ( "ioctl(USBDEVFS_SUBMITURB).ep", (Addr)&vkuu->endpoint, sizeof(vkuu->endpoint));
-+ PRE_MEM_READ( "ioctl(USBDEVFS_SUBMITURB).endpoint", (Addr)&vkuu->endpoint, sizeof(vkuu->endpoint));
- PRE_MEM_READ( "ioctl(USBDEVFS_SUBMITURB).type", (Addr)&vkuu->type, sizeof(vkuu->type));
- PRE_MEM_READ( "ioctl(USBDEVFS_SUBMITURB).flags", (Addr)&vkuu->flags, sizeof(vkuu->flags));
- PRE_MEM_READ( "ioctl(USBDEVFS_SUBMITURB).buffer", (Addr)&vkuu->buffer, sizeof(vkuu->buffer));
-- PRE_MEM_READ( "ioctl(USBDEVFS_SUBMITURB).buffer_length", (Addr)&vkuu->buffer_length, sizeof(vkuu->buffer_length));
-- PRE_MEM_READ( "ioctl(USBDEVFS_SUBMITURB).usercontext", (Addr)&vkuu->usercontext, sizeof(vkuu->usercontext));
-- if (vkuu->endpoint & 0x80)
-- PRE_MEM_WRITE( "ioctl(USBDEVFS_URB).buffer", (Addr)vkuu->buffer, vkuu->buffer_length);
-- else
-- PRE_MEM_READ( "ioctl(USBDEVFS_URB).buffer", (Addr)vkuu->buffer, vkuu->buffer_length);
-- /* FIXME: Does not handle all cases this ioctl can do, ISOs are missing. */
-+ PRE_MEM_READ( "ioctl(USBDEVFS_SUBMITURB).signr", (Addr)&vkuu->signr, sizeof(vkuu->signr));
-+ PRE_MEM_WRITE( "ioctl(USBDEVFS_SUBMITURB).status", (Addr)&vkuu->status, sizeof(vkuu->status));
-+ if (vkuu->type == VKI_USBDEVFS_URB_TYPE_CONTROL) {
-+ struct vki_usbdevfs_setuppacket *vkusp = (struct vki_usbdevfs_setuppacket *)vkuu->buffer;
-+ PRE_MEM_READ( "ioctl(USBDEVFS_SUBMITURB).buffer_length", (Addr)&vkuu->buffer_length, sizeof(vkuu->buffer_length));
-+ PRE_MEM_READ( "ioctl(USBDEVFS_SUBMITURB).buffer.setup_packet", (Addr)vkusp, sizeof(*vkusp));
-+ if (vkusp->bRequestType & 0x80)
-+ PRE_MEM_WRITE( "ioctl(USBDEVFS_SUBMITURB).buffer.data", (Addr)(vkusp+1), vkuu->buffer_length - sizeof(*vkusp));
-+ else
-+ PRE_MEM_READ( "ioctl(USBDEVFS_SUBMITURB).buffer.data", (Addr)(vkusp+1), vkuu->buffer_length - sizeof(*vkusp));
-+ PRE_MEM_WRITE( "ioctl(USBDEVFS_SUBMITURB).actual_length", (Addr)&vkuu->actual_length, sizeof(vkuu->actual_length));
-+ } else if (vkuu->type == VKI_USBDEVFS_URB_TYPE_ISO) {
-+ int total_length = 0;
-+ int i;
-+ PRE_MEM_READ( "ioctl(USBDEVFS_SUBMITURB).number_of_packets", (Addr)&vkuu->number_of_packets, sizeof(vkuu->number_of_packets));
-+ for(i=0; i<vkuu->number_of_packets; i++) {
-+ PRE_MEM_READ( "ioctl(USBDEVFS_SUBMITURB).iso_frame_desc[].length", (Addr)&vkuu->iso_frame_desc[i].length, sizeof(vkuu->iso_frame_desc[i].length));
-+ PRE_MEM_WRITE( "ioctl(USBDEVFS_SUBMITURB).iso_frame_desc[].actual_length", (Addr)&vkuu->iso_frame_desc[i].actual_length, sizeof(vkuu->iso_frame_desc[i].actual_length));
-+ PRE_MEM_WRITE( "ioctl(USBDEVFS_SUBMITURB).iso_frame_desc[].status", (Addr)&vkuu->iso_frame_desc[i].status, sizeof(vkuu->iso_frame_desc[i].status));
-+ total_length += vkuu->iso_frame_desc[i].length;
-+ }
-+ if (vkuu->endpoint & 0x80)
-+ PRE_MEM_WRITE( "ioctl(USBDEVFS_SUBMITURB).buffer", (Addr)vkuu->buffer, total_length);
-+ else
-+ PRE_MEM_READ( "ioctl(USBDEVFS_SUBMITURB).buffer", (Addr)vkuu->buffer, total_length);
-+ PRE_MEM_WRITE( "ioctl(USBDEVFS_SUBMITURB).error_count", (Addr)&vkuu->error_count, sizeof(vkuu->error_count));
-+ } else {
-+ PRE_MEM_READ( "ioctl(USBDEVFS_SUBMITURB).buffer_length", (Addr)&vkuu->buffer_length, sizeof(vkuu->buffer_length));
-+ if (vkuu->endpoint & 0x80)
-+ PRE_MEM_WRITE( "ioctl(USBDEVFS_SUBMITURB).buffer", (Addr)vkuu->buffer, vkuu->buffer_length);
-+ else
-+ PRE_MEM_READ( "ioctl(USBDEVFS_SUBMITURB).buffer", (Addr)vkuu->buffer, vkuu->buffer_length);
-+ PRE_MEM_WRITE( "ioctl(USBDEVFS_SUBMITURB).actual_length", (Addr)&vkuu->actual_length, sizeof(vkuu->actual_length));
-+ }
- break;
- }
-+ case VKI_USBDEVFS_DISCARDURB:
-+ break;
- case VKI_USBDEVFS_REAPURB:
-+ if ( ARG3 ) {
-+ PRE_MEM_WRITE( "ioctl(USBDEVFS_REAPURB)", ARG3, sizeof(struct vki_usbdevfs_urb **));
-+ break;
-+ }
- case VKI_USBDEVFS_REAPURBNDELAY:
- if ( ARG3 ) {
-- PRE_MEM_READ( "ioctl(USBDEVFS_SUBMITURB)", ARG3, sizeof(struct vki_usbdevfs_urb *));
-+ PRE_MEM_WRITE( "ioctl(USBDEVFS_REAPURBNDELAY)", ARG3, sizeof(struct vki_usbdevfs_urb **));
- break;
- }
- case VKI_USBDEVFS_CONNECTINFO:
-@@ -4986,11 +5019,31 @@
- case VKI_USBDEVFS_REAPURBNDELAY:
- if ( ARG3 ) {
- struct vki_usbdevfs_urb **vkuu = (struct vki_usbdevfs_urb**)ARG3;
-+ POST_MEM_WRITE((Addr)vkuu, sizeof(*vkuu));
- if (!*vkuu)
- break;
- POST_MEM_WRITE((Addr) &((*vkuu)->status),sizeof((*vkuu)->status));
-- if ((*vkuu)->endpoint & 0x80)
-- POST_MEM_WRITE((Addr)(*vkuu)->buffer, (*vkuu)->actual_length);
-+ if ((*vkuu)->type == VKI_USBDEVFS_URB_TYPE_CONTROL) {
-+ struct vki_usbdevfs_setuppacket *vkusp = (struct vki_usbdevfs_setuppacket *)(*vkuu)->buffer;
-+ if (vkusp->bRequestType & 0x80)
-+ POST_MEM_WRITE((Addr)(vkusp+1), (*vkuu)->buffer_length - sizeof(*vkusp));
-+ POST_MEM_WRITE((Addr)&(*vkuu)->actual_length, sizeof((*vkuu)->actual_length));
-+ } else if ((*vkuu)->type == VKI_USBDEVFS_URB_TYPE_ISO) {
-+ char *bp = (*vkuu)->buffer;
-+ int i;
-+ for(i=0; i<(*vkuu)->number_of_packets; i++) {
-+ POST_MEM_WRITE((Addr)&(*vkuu)->iso_frame_desc[i].actual_length, sizeof((*vkuu)->iso_frame_desc[i].actual_length));
-+ POST_MEM_WRITE((Addr)&(*vkuu)->iso_frame_desc[i].status, sizeof((*vkuu)->iso_frame_desc[i].status));
-+ if ((*vkuu)->endpoint & 0x80)
-+ POST_MEM_WRITE((Addr)bp, (*vkuu)->iso_frame_desc[i].actual_length);
-+ bp += (*vkuu)->iso_frame_desc[i].length; // FIXME: or actual_length??
-+ }
-+ POST_MEM_WRITE((Addr)&(*vkuu)->error_count, sizeof((*vkuu)->error_count));
-+ } else {
-+ if ((*vkuu)->endpoint & 0x80)
-+ POST_MEM_WRITE((Addr)(*vkuu)->buffer, (*vkuu)->actual_length);
-+ POST_MEM_WRITE((Addr)&(*vkuu)->actual_length, sizeof((*vkuu)->actual_length));
-+ }
- break;
- }
- case VKI_USBDEVFS_CONNECTINFO:
-diff -ur -x '*~' valgrind-3.4.1/include/vki/vki-linux.h valgrind-3.4.1-mod/include/vki/vki-linux.h
---- valgrind-3.4.1/include/vki/vki-linux.h 2009-03-01 22:46:45.000000000 +0100
-+++ valgrind-3.4.1-mod/include/vki/vki-linux.h 2009-04-29 15:42:05.000000000 +0200
-@@ -2325,11 +2325,26 @@
- #define VKI_USBDEVFS_BULK _VKI_IOWR('U', 2, struct vki_usbdevfs_bulktransfer)
- #define VKI_USBDEVFS_GETDRIVER _VKI_IOW('U', 8, struct vki_usbdevfs_getdriver)
- #define VKI_USBDEVFS_SUBMITURB _VKI_IOR('U', 10, struct vki_usbdevfs_urb)
-+#define VKI_USBDEVFS_DISCARDURB _VKI_IO('U', 11)
- #define VKI_USBDEVFS_REAPURB _VKI_IOW('U', 12, void *)
- #define VKI_USBDEVFS_REAPURBNDELAY _VKI_IOW('U', 13, void *)
- #define VKI_USBDEVFS_CONNECTINFO _VKI_IOW('U', 17, struct vki_usbdevfs_connectinfo)
- #define VKI_USBDEVFS_IOCTL _VKI_IOWR('U', 18, struct vki_usbdevfs_ioctl)
-
-+#define VKI_USBDEVFS_URB_TYPE_ISO 0
-+#define VKI_USBDEVFS_URB_TYPE_INTERRUPT 1
-+#define VKI_USBDEVFS_URB_TYPE_CONTROL 2
-+#define VKI_USBDEVFS_URB_TYPE_BULK 3
-+
-+// this is missing in usbdevice_fs.h
-+struct vki_usbdevfs_setuppacket {
-+ __vki_u8 bRequestType;
-+ __vki_u8 bRequest;
-+ __vki_u16 wValue;
-+ __vki_u16 wIndex;
-+ __vki_u16 wLength;
-+};
-+
- //----------------------------------------------------------------------
- // From linux-2.6.20.1/include/linux/i2c.h
- //----------------------------------------------------------------------
diff --git a/usbmuxd/usb-linux.c b/usbmuxd/usb-linux.c
index b401cde..44eba2c 100644
--- a/usbmuxd/usb-linux.c
+++ b/usbmuxd/usb-linux.c
@@ -138,7 +138,7 @@ int usb_send(struct usb_device *dev, const unsigned char *buf, int length)
libusb_free_transfer(xfer);
return res;
}
- collection_add(&dev->tx_xfers, xfer);/*
+ collection_add(&dev->tx_xfers, xfer);
if((length % 512) == 0) {
usbmuxd_log(LL_DEBUG, "Send ZLP");
// Send Zero Length Packet
@@ -152,7 +152,7 @@ int usb_send(struct usb_device *dev, const unsigned char *buf, int length)
return res;
}
collection_add(&dev->tx_xfers, xfer);
- }*/
+ }
return 0;
}
diff --git a/usbmuxd/usb.h b/usbmuxd/usb.h
index 8a48308..7eea707 100644
--- a/usbmuxd/usb.h
+++ b/usbmuxd/usb.h
@@ -29,16 +29,14 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
// libusb fragments packets larger than this (usbfs limitation)
// on input, this creates race conditions and other issues
-// I don't think the device uses larger packets
-// if it does then we're going to have to implement proper framing...
#define USB_MRU 16384
// max transmission packet size
// libusb fragments these too, but doesn't send ZLPs so we're safe
-// but maybe we need to send a ZLP ourselves at the end (see usb-linux.h)
+// but we need to send a ZLP ourselves at the end (see usb-linux.c)
// we're using 3 * 16384 to optimize for the fragmentation
// this results in three URBs per full transfer, 32 USB packets each
-// if there are ZLP issues this should make them show up too
+// if there are ZLP issues this should make them show up easily too
#define USB_MTU (3 * 16384)
#define USB_PACKET_SIZE 512