Tethering the iPhone 3g with Linux.

The aspect of the iPhone that made me hesitate in buying one the most was losing my ability to gain internet connectivity on my laptop though my phone. I’ve used this when I’m out of town at times to get connectivity, and it’s been quite the handy tool when there are no wifi hotspots to be found.

Today, I jailbroke my phone and managed to get a SOCKS proxy running on it. With a bit of Ad-Hoc wifi from my laptop, browsing the web with more Gs was easily at my fingertips. Here’s what I did.

  1. Jailbreak the iPhone. I used winpwn. It was pretty easy, and the internet will tell you how.
  2. Install 3proxy, insomniac, and either OpenSSH or mobile terminal.
  3. Either from a ssh session or the terminal, run proxy
  4. Set up a DHCP server on the laptop. This requires a config file, which I’ll include later. You could also use a static IP if that’s your bag.
  5. Bring the wifi card down and set it in Ad-Hoc mode. I did this using NetworkManager because I’ve become lazy, but its pretty easy to do with iwconfig as well.
  6. Take the wifi card up and assign it an IP in the same subnet as what your dhcp server is using.
  7. Turn on insomnia so your wifi connection doesn’t get shut down when the device goes idle.
  8. Have the iPhone connect to the Ad-Hoc network. I left dhcpd in foreground mode with debug on to watch the phone request an IP.
  9. Set firefox to use a SOCKS v5 proxy on port 1080 with the IP address your phone.
  10. Enable network.proxy.socks_remote_dns in about:config in Firefox. You need DNS to be routed across the proxy rather than firefox trying to hit whatever (likely invalid) nameserver is in /etc/resolv.conf
  11. Enjoy the internets.

The end result is your traffic goes over wifi to a proxy on the iPhone, and then out the 3G radio to ATT’s network. It’s a little flaky and to be honest I only plan on using this when I have no other means of using the Internet and I really need connectivity. The 3G network aspect of this is rather nice compared to the EDGE speeds I was used to with the Pearl. Being able to talk to the GPRS modem on the phone was much more functional, though. Proxies are a pain. I haven’t checked to see if ping times are worse or better over HSDPA versus EDGE.

As for the dhcpd.conf, it was pretty minimalist:

ddns-update-style ad-hoc;
subnet 192.168.1.0 netmask 255.255.255.0 {
    range 192.168.1.10 192.168.1.20;
}

It could be simpler, and I could do static IP assignment so I don’t have to adjust Firefox’s proxy settings, but it worked long enough as a proof of concept.

X Server memory usage.

I would really like to know what’s causing my X server to have 350+MB private writable memory allocated after a few days of uptime.

pmap say what

Does anybody have any ideas or suggestions for investigation?

Tethering a Blackberry Pearl in Linux

Tonight I decided to try and get on the internet using my Pearl as a GPRS modem. It took a couple hours of poking and prodding, but I managed to get it to work.

Software used:

All of those components except for pppd and chat had to be compiled and installed on my laptop, which runs Slackware 12. The order listed for the applications I had to compile is the order in which I built them, as XmBlackberry depends on OpenMotif , Xlt, and opensync. Additionally, I had to edit a large portion of the opensync directory in XmBlackberry to get it to build against that particular version of opensync, as one of the header files contained an underscore where it was referenced with a dash in XmBlackberry.

Aside from that single build snafu (or series of snafus), I largely followed this blog post, which as excellent directions that don’t directly correspond to working with AT&T’s network. Once everything is built, about all that is left relates to the differences betweeing using T-Mobile and AT&T.

Rather than producing a detailed guide like that, I’ll just note my config files, as they differ somewhat.

Here’s my chat script, which works with AT&T. I placed it in /etc/chatscripts/blackberry

ECHO ON
ABORT BUSY ABORT 'NO CARRIER' ABORT VOICE ABORT 'NO DIALTONE' ABORT 'NO DIAL TONE' ABORT 'NO ANSWER' ABORT DELAYED ABORT ERROR
'' ATZ 'OK' 'AT+CGDCONT=1,"IP","WAP.CINGULAR"'
OK 'ATD*99***1#'

Next up is /etc/ppp/peers/blackberry
debug
nodetach
/dev/pts/6
115200
noauth
connect "/usr/sbin/chat -f /etc/chatscripts/blackberry"
modem
defaultroute
noipdefault
user "username"
password "password"
remotename provider
ipparam provider
persist
usepeerdns

Most of the difference here is that I specify something for username and password. These don’t seem to matter for PAP authentication with AT&T, but pppd doesn’t want to do authentication without those two options being specified with *something* in them. Additionally I specify persist so pppd will reconnect when I get disconnected.

Anyway, once you’ve plugged in your Pearl, ran bcharge -o to put it in single device mode, fired up XmBlackberry and clicked on the option menu to create the /dev/pts/* device, pointed your pppd config at that device node, and run pppd with that configuration, likely you’ll end up with magical cell phone internets!

For those lucky peope who work through all of this, your reward is a nice network device reported by ifconfig.


ppp0 Link encap:Point-to-Point Protocol
inet addr:10.121.157.122 P-t-P:10.0.0.2 Mask:255.255.255.255
UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1500 Metric:1
RX packets:5 errors:0 dropped:0 overruns:0 frame:0
TX packets:7 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:3
RX bytes:68 (68.0 b) TX bytes:123 (123.0 b)

The only downside I’ve found is that I get kicked off consistently every two minutes. I think this might be because I don’t pay for ‘tethering’ my phone. If I intended to drop a card into my laptop to use their network frequently, I’d consider paying for it. As is, I already pay for unlimited data and I don’t plan to use my phone as a modem often. It will be handy when I’m out of town, but otherwise this is pretty cumbersome and not all that speedy.

[EDIT]

After a bit of searching, it turns out that adding
lcp-echo-failure 0
lcp-echo-interval 0

to my peer file fixes the two minute disconnect issue. Looks like pppd was defaulting to expecting an lcp echo, which didn’t happen, so it would disconnect.

This edit was made over my GPRS connection. :)

Shameless navelgazing.

In the interests of laziness, I formatted my desktop (was running Slackware 11), and installed Ubuntu 7.04 x86_64. Lately I’ve cared less about handling low-level administration of my desktop, so it seemed like a good idea.

Things that went good

  • Installation (minus one issue, see below)
  • Suspend-to-ram works pretty darn well after some tweaking
  • Installing flash from a guide on the interwebs
  • Keeping my gnome profile, other settings
  • Non-free codec and driver installation
  • Nearly everything else

Things that went bad

  • The graphical live CD couldn’t get X started in a sane manner
  • X after the install was absolutely hosed.
  • That’s about it

Over all that’s pretty good, but WTF on X not working. I have a plane old NVIDIA 6200 pci-e card. There’s nothing odd about it at all. When X came up on the live CD, it just displayed garbage. So, I dropped back to the console, fired up vim, and changed xorg.conf to use vesa instead of nv. After a quick jump to runlevel 3, going back to runlevel 4 got me to a nice gnome desktop.

When I rebooted into my minty fresh installation, whatever Ubuntu crapped out in the form of xorg.conf didn’t play well with my 4:3 LCD’s h-sync and vertical refresh. I had this problem when I first got the monitor (the image got shoved over to the right half of the monitor, and the monitor displayed a ‘Unsupported Mode’ warning). I figured nvidia-settings would make life better when I got the nvidia driver installed. No dice. I eventually tracked down an old backup of my xorg.conf, and copied the relevant monitor, device, and screen sections to get proper settings for both my monitors and twinview set up. Honestly this isn’t too much of a problem for a person who has been running Slackware for a while, but I thought Ubuntu would do a much better job handling X than it did.

Getting flash installed was pretty simple. I just googled “ubuntu amd64 flash”, and came up with a forum topic which had instructions for installing necessary 32bit libs flash needs and a neat little wrapper to make a 64bit firefox embed flash nicely.

Suspend to ram worked out of the box decently, with a couple of snags. First off, the network didn’t come back up. By default Ubuntu thinks the forcedeth module for my ethernet card should be unloaded, and since forcedeth is a reverse-engineered driver the hardware ends up in a wonky state when that happens. The module didn’t get loaded back in the kernel after waking the machine up, and when manually modprobe’d the device got a different MAC address. That’s not a big deal except I have static IP assignments with dns names associated with them on my home network, and I like to have that working. Adding forcedeth to MODULES_WHITELIST in /etc/default/acpi-support fixed that, and now the network plays nicely with suspending. Secondly, I’d get graphical glitches, non-working ttys, and vbetool pegging the crap out of one of my cores after resuming. Commenting out SAVE_VBE_STATE and POST_VIDEO fixed that, and video comes back nicely now. Other than those two things and something (gnome-power-manager or hal?) thinking that my machine didn’t suspend correctly when it did and giving me a notification about it, suspend works really well on this machine and allows me to save a ballpark $9 on my electric bill each month.

On the codec front, after remembering that Ubuntu doesn’t ship mp3, wma/v, or ac3 support out of the box, I opened up a few of these files in Totem. This brought up a dialog asking me if I wanted to download something to decode that file format, warning me about legal issues with such non-free and horribly patent-encumbered software. Installing them got me support for them for all my gstreamer-based applications (Totem and Rhythmbox are all I care about). Dropline Gnome never shipped totem-gstreamer, or decoders for wmv and ac3. Heck, I tried to get ac3 decoding going in gstreamer myself, and I couldn’t find anything outside of a €7 plug-in offered by Fluendo that I’m not going to pay for to decode the one ac3 album I have. The decoder that Ubuntu knew about doesn’t seek in the files, but I can live with that. Windows media files play decently; the decoder is better in some respects than the hackish wine-wrappered mplayer solution I had gotten working back a few years ago with Windows dlls. So, I’m pretty pleased with the media situation.

Anyway after a few hours of poking at issues, I’ve got a desktop working better than I had after two years of maintaining a Slackware installation on this machine, and I get to be lazier than before! I do have to give up the great dev environment that Slackware gives me, and that sucks, but them’s the breaks. I still plan on keeping Slack on my laptop for the time being, as it works better with getting Linux to consume little power. Otherwise, Ubuntu seems quite nice for my needs.

I’m keeping my Slackware case badge though.