How to charge an iPad with USB port and devd(8)

April 14, 2013 by · Leave a Comment 

If you happen to have one of those Apple iPad gadgets, you’ve probably discovered at some point that iPads do not particularly like to charge themselves through your computer’s (or laptop’s) USB ports, even when the port is definitely capable of providing enough current (i.e., full powered).

In 2010, some clever soul sniffed the “magic” USB command, and wrote simple utility, on top of libusb-1.0, which enables charging from USB port. It can be found in the FreeBSD Ports Collection under sysutils/ipad_charge. Unfortunately, it’s a C program, with single hardcoded product id, so it doesn’t work with new iPads, for example, without patching. There is also no support for FreeBSD’s devd(8); original author only provides rule for Linuxish udev. (There are a few forks of the original utility available which support vast range of Apple devices, e.g. this one.)

Luckily, FreeBSD allows for simple things to be done in simple ways. Why bother with building and running some external binary, when usbconfig(8) conveniently provides do_request command to send hand-crafted requests to USB devices?

This is where the magic happens in the original C implementation:

libusb_control_transfer(dev_handle, CTRL_OUT, 0x40, 0x6400,
    enable ? 0x6400 : 0, NULL, 0, 2000)

This can be translated into the following do_request (command-line example; replace ellipsis with actual iPad device name as it appears in your system per usbconfig list):

$ usbconfig -d ... do_request 0x40 0x40 0x6400 0x6400 0x0

Doing it manually is fine for initial testing, but ultimately we’d want devd(8) daemon to take care of this for us every time we plug in an iPad. I’ve come up with the following code, which I put into /etc/devd/ipad.conf file:

attach 0 {
    match "vendor" "0x05ac";
    match "product" "(0x129a|0x12ab)";
    action "usbconfig -d $device-name do_request 0x40 0x40 0x6400 0x6400 0x0";

With devd(8) hook, we no longer have to build anything, and can easily augment match "product" line for upcoming new models (provided that this USB hack still applies to them, but so far it seems to be true for all iPads from the first to the latest fourth; I’ve included product ids I was able to test myself). I guess that detach method could also be added, but it’s probably not necessary: once iPad is plugged out, the port gets reset or something.

About danfe

Speak Your Mind

Tell us what you're thinking...
and oh, if you want a pic to show with your comment, go get a gravatar!