How to use usb.h?

Discussion in 'iOS Development' started by mohitd2000, Jul 10, 2010.

  1. mohitd2000

    mohitd2000 Member

    Joined:
    Jul 6, 2009
    Messages:
    231
    Likes Received:
    0
    Device:
    3G iPod touch
    After browsing through the iRecovery source code, I noticed a certain include (usb.h) that seemed to do almost everything. So I used make then copied the include files into /usr/include. So my question is, how could I use it to send commands to my iPod touch via USB? Or is it easier said than done?
  2. lauNchD

    lauNchD Well-Known Member

    Joined:
    Jan 27, 2008
    Messages:
    1,844
    Likes Received:
    261
    Device:
    iPhone 5 (Black)
    usb.h is the (relatively) low-level libusb header. libusb enables you to communicate with just about any USB device and send it "raw" messages.
    This is useful for Recovery/DFU Mode, because it uses a proprietary binary protocol, but nothing else, really (when trying to communicate with an iDevice).

    What's your problem with libusbmuxd?
    ------------------double post merged------------------
    BTW: You can't just "send commands" to your iPod. That's recovery mode. If you really need to, you can set up an SSH relay (usually a program that opens the SSH port [22] on your iPod, connects to it, and maps it to a different port on your computer so a normal SSH client can connect to the iPod).
  3. mohitd2000

    mohitd2000 Member

    Joined:
    Jul 6, 2009
    Messages:
    231
    Likes Received:
    0
    Device:
    3G iPod touch
    When I try to run cmake in usbmuxd-1.0.4/usbmuxd-1.0.4, I get:

    Please Register or Log in to view images

    What is this library USB??? I have libusb installed and there is no library on Cygwin called USB? Or is the USB_INCLUDE_DIR and USB_LIBRARY paths wrong and I have to manually edit them?

    Oh how stupid of me. I forgot to set USB_INCLUDE_DIR from USB_INCLUDE_DIR-NOTFOUND (XD) to /usr/include. >_<

    But what this library I recently found called libimobiledevice that seems to take (great) advantage of usbmuxd and libusb. I will use that I guess. It is written entirely in C/C++ and even has API documentation!
  4. lauNchD

    lauNchD Well-Known Member

    Joined:
    Jan 27, 2008
    Messages:
    1,844
    Likes Received:
    261
    Device:
    iPhone 5 (Black)
    Well, that would work for high-level stuff like syncing and AFC (Apple's somewhat crippled file access system), but not for custom communication with, say, some kind of app/daemon running on the iPod.
    The libimobiledevice site actually says you should use libusbmuxd (or the tool that comes with it) for SSH over USB, etc.
  5. mohitd2000

    mohitd2000 Member

    Joined:
    Jul 6, 2009
    Messages:
    231
    Likes Received:
    0
    Device:
    3G iPod touch
    Is there any documentation for usbmuxd or sample source code?
  6. lauNchD

    lauNchD Well-Known Member

    Joined:
    Jan 27, 2008
    Messages:
    1,844
    Likes Received:
    261
    Device:
    iPhone 5 (Black)
    It's in the source tarball!
    (I think the header files _are_ the documentation)
  7. mohitd2000

    mohitd2000 Member

    Joined:
    Jul 6, 2009
    Messages:
    231
    Likes Received:
    0
    Device:
    3G iPod touch
    How would I issue commands like killall SpringBoard? I was thinking via:
    Code:
    int usbmuxd_send(int sfd, const char *data, uint32_t len, uint32_t *sent_bytes);
    Where const char *data is a string literal with "killall SpringBoard". Would that work?
  8. lauNchD

    lauNchD Well-Known Member

    Joined:
    Jan 27, 2008
    Messages:
    1,844
    Likes Received:
    261
    Device:
    iPhone 5 (Black)
    No.

    The relay tool is included in the libusbmuxd package, too.
  9. mohitd2000

    mohitd2000 Member

    Joined:
    Jul 6, 2009
    Messages:
    231
    Likes Received:
    0
    Device:
    3G iPod touch
    You mean iProxy?
  10. lauNchD

    lauNchD Well-Known Member

    Joined:
    Jan 27, 2008
    Messages:
    1,844
    Likes Received:
    261
    Device:
    iPhone 5 (Black)
    Yeah.
    You run it (local TCP port: something "non-standard"; device TCP port: 22), then, you basically SSH into your own computer using the local TCP port you set in iProxy, but everything gets relayed through usbmuxd to your iPod.

Share This Page