HOWTO: iPhone internet connection sharing via USB

Would you like to share some of your solutions for certain problems? Tips or tricks? Post here. All new topics are automatically moderated.

HOWTO: iPhone internet connection sharing via USB

Postby Zare » 07 Dec 2010, 13:42

This will probably also work for iPod/iPad also, but i don't have those.

Enable "tethering" (don't you just love these web2.0 yuppie words? pfff...) in your device. Go to settings, network, internet tethering, and activate it.

1. Kernel iPhone USB ethernet support

There's a kernel module [FILE]if_ipheth.ko[/FILE] in FreeBSD 8-STABLE (8.2-PRERELEASE as of writing this text), i'm not sure about earlier versions. I had the file in 8.1-RELEASE, but i can't say would it work because i haven't completed the whole procedure under 8.1-RELEASE.

So just kldload that file and/or include it in your [file]/boot/loader.conf[/file]

2. USB libraries needed for communication

We'll need libimobiledevice, libplist, usbmuxd and ipheth_pair. usbmuxd will establish connection to iPhone, and it needs libimobiledevice as a main dependency. libplist comes as libimobiledevice dependency. ipheth_pair will do actual pairing, communicating with device via usbmuxd. Before that happens we can't use iPhone as gateway.

[CMD="$"]wget --no-check-certificate ... .3.tar.bz2[/CMD]
[CMD="$"]tar xvfj libplist-1.3.tar.bz2 && cd libplist-1.3[/CMD]
[CMD="$"]mkdir build && cd build && cmake ..[/CMD]
[CMD="#"]make install[/CMD]

[CMD="$"]tar xvfj libimobiledevice-1.0.4.tar.bz2 && cd libimobiledevice-1.0.4[/CMD]
[CMD="$"]./configure LDFLAGS="-L/usr/local/lib/"[/CMD]
[CMD="#"]make install[/CMD]

[CMD="$"]wget ... .6.tar.bz2[/CMD]
[CMD="$"]tar xvfj usbmuxd-1.0.6.tar.bz2 && cd usbmuxd-1.0.6[/CMD]
[CMD="$"]mkdir build && cd build && cmake ..[/CMD]
[CMD="#"]make install[/CMD]

If all goes ok, you'll have a functioning usbmuxd under [file]/usr/local/sbin/usbmuxd[/file]. Now we need to take care of pairing program;

[cmd="$"]git clone git://[/cmd]
[cmd="$"]cd ipheth/ipheth-pair[/cmd]

Forget the Makefile and just run this;

[cmd="$"]cc -Wall -O2 ipheth-pair.c -o ipheth-pair -L/usr/local/lib -I/usr/local/include -limobiledevice[/cmd]

3. Running / testing procedure

Hook up your iPhone to USB port, and you should see something like this from your kernel output;

Code: Select all
ugen7.2: <Apple Inc.> at usbus7

Now, run usbmuxd as root in foreground mode, so we see it's output

[cmd="#"]/usr/local/sbin/usbmuxd -U root -f[/cmd]

This output indicates that communication to device has been established;

Code: Select all
[14:33:13.113][3] usbmuxd v1.0.6 starting up
[14:33:13.119][3] Could not check kernel ownership of interface 0 for device 7-2: -99
[14:33:13.170][3] Connecting to new device on location 0x70002 as ID 1
[14:33:13.170][3] Initialization complete
[14:33:13.171][3] Connected to v1.0 device 1 on location 0x70002 with serial number 37edfec09f8b80ea839ddbf01cf44030d942551b

OK, let's now recheck kernel output via [FILE]dmesg[/FILE], kernel driver should now be able to create an ethernet device for iPhone's gateway connection;

Code: Select all
ipheth0: <Apple Inc. iPhone, class 0/0, rev 2.00/0.01, addr 2> on usbus7
ue0: <USB Ethernet> on ipheth0
ue0: Ethernet address: 78:ca:39:75:f8:ab

So the device ue0 is created, but until we pair we won't have connectivity. Go back to the directory where you compiled ipheth-pair and run it. If all goes well it'll just drop you back to prompt without error message, and the blue title "Internet Tethering" will start blinking below the status bar of your iPhone.

Just poll the device via DHCP and you're good to go.

[cmd="#"]dhclient ue0[/cmd]

Note : for some reason, DHCP client does not push default gateway to my routing table and DNS server entry into [file]resolv.conf[/file]. Default gw is the address you'll get your lease from (in my case, but the DNS server isn't, in my case it's (note it's still private scope). I had to connect my phone to Windows machine to see what kind of address USB<->ETH adapter over there gets.

I haven't had time to check stability of this mechanism.
Posts: 385
Joined: 16 Nov 2008, 23:05
Location: Split, Dalmatia

Postby vermaden » 09 Dec 2010, 00:02

Does it work for ANY iPhone, or only for older ones, or only for lates ones?
Does it work for hacked/jailbroken iPhones?
Religions, worst damnation of mankind.
"FreeBSD has always been the operating system that GNU/Linux should have been." Frank Pohlmann, IBM
User avatar
Giant Locked
Posts: 2317
Joined: 16 Nov 2008, 19:37
Location: pl_PL.lodz

Postby Zare » 09 Dec 2010, 08:13

I have iPhone 3GS. It should work with 3G and 4 also. And author of ipheth driver says it should work on 2G's with some patches. Since this mechanism is using Apple's protocol (you have same functionality in Windows or OSX), your phone doesn't have to be jailbroken.

I'm sorry, you asked does it work for jailbroken phones? Yes it does, my phone is jailbroken. Because jailed iPhone is really a dumb brick.

Keep in mind that jailbreaking doesn't modify system software, which recent cases against Apple proved. On the other hand, unlocking modifies system baseband code and i'm not sure would it work. There's no sane reason why it shouldn't but my phone isn't unlocked so i can't be 100% sure.
Posts: 385
Joined: 16 Nov 2008, 23:05
Location: Split, Dalmatia

Return to Howtos & FAQs (Moderated)

Who is online

Users browsing this forum: No registered users and 2 guests