2010-08-14 · in Tech Notes · 1018 words

Vodafone's Top Up and Go product is a pay-as-you-go 3G Internet service. As I write (August 2010), you pay £15 for each chunk of credit, which lasts a month, and gives you three gigabytes of data, through a NAT setup with (for some reason) a transparent HTTP proxy. The latency is pretty awful — SSH is just about usable — but if you've got no other option it certainly works.

Before you read any further: the way I did it is not the easiest way of setting this up. In theory, NetworkManager (the desktop networking daemon that most Linux distributions ship with my default) should be able to configure it automatically. Failing that, Vodafone's R&D group provide Betavine Connection Manager, an open-source tool for driving the various cards they support, which exposes the right D-Bus interfaces for NetworkManager to be able to talk to it. (This is why I went for Vodafone rather than one of the other suppliers — much of the information below came from peering at the source for BCM.)

What I'm describing here is how to use Vodafone's service without NetworkManager. This is useful if (like me) you think NM is the spawn of the devil, or (also like me) NM completely fails to work for you in its usual undiagnosable way. Sakis3G is another way of avoiding NM, but I didn't discover it until after I'd figured out the below.

Make it a modem

(Before you fit the SIM to the modem, you may like to go through the registration dance described below.)

The modem that I got with the package is a ZTE K3570-Z, a USB stick with a SIM slot and a single LED for diagnostics (read the manual provided). As with lots of these modems, when it's first plugged in it appears to be a CD drive with the Windows drivers on. You have to send it a magic command to make it appear as a modem. On Linux, all you need to do is install usb_modeswitch, which uses a udev hook to spot the device being plugged in and flip it into the right mode.

Once it's in modem mode (for the K3570-Z, using the option kernel module), you'll see some serial ports showing up. I'd assumed that my 1990s modem-wrangling skills were long obsolete, but no, these devices still accept the Hayes command set: you can open a terminal and type AT commands at them, and they'll respond quite happily.

Why do you get multiple ports showing up? It's so you can do several things with it at once: you'll use one of the ports to dial up a PPP connection to the ISP (yes, really), and you can use the others to send and receive text messages and the like at the same time. The caveat is that only one of the ports will let you make dialup connections; the others will either hang or give an error in response to the ATD dialling command. For me, ttyUSB3 works (and it turned out this was what was tripping up NetworkManager — it was using the wrong port to dial); if you get errors, try the others.

A useful command to feed to the modem at this point is AT+ZCDRUN=8, which will make it appear as a modem immediately rather than needing to be mode-switched.

Configure PPP

If you've configured PPP for a landline modem before, this is much the same, just with some extra setup commands to tell the modem which wireless service to use. The important thing to know is the APN for your service, which you specify using an AT+CGDCONT= command. If you don't get this right, you'll get a ConfNak error from the PPP connection as it refuses to give you an IP address. For Top Up and Go, the APN is PPBUNDLE.INTERNET; for Vodafone's contract bundle it's different (look at the BCM source for more details).

The pppd config (in /etc/ppp/peers/vodafone) looks like this:

# pppd config for Vodafone Top Up and Go with a K3570-Z USB stick
# ATD only works on ttyUSB3 for me (others hang or give NO CARRIER)
/dev/ttyUSB3 460800 crtscts
connect "/usr/sbin/chat -v -f /etc/chatscripts/vodafone"
# Authentication is required
user web
password web
# Using CCP causes "Protocol-Reject for 'Compression Control Protocol'"
# Using VJ compression gives a ConfNak

And the corresponding chatscript (in /etc/chatscripts/vodafone) is:

# This is the initialisation sequence from the Windows driver.
"" "AT"
"OK" "ATV1"
"OK" "ATE0"
"OK" "AT&F&D2&C1S0=0"
# This is the APN for Top Up and Go ("internet" for contract).
"OK" "ATDT*99#"
CONNECT \\d\\c

Once those are set up, and assuming the serial port is correct, you should be able to bring up the link using pppd debug dump nodetach call vodafone. It'll produce copious debug output on the terminal and syslog, which'll be useful if anything goes wrong. If it's given you an IP address then you're probably OK.

Registering the SIM

The Windows software will tell you how much credit you've got, but that's not much help if you're using pppd. However, if you register the SIM on Vodafone's web site, it'll tell you how much of your package you've used, and let you top it up online.

The only problem is that to do this, you have to know the phone number. This isn't printed on the packaging anywhere, nor does it appear to be stored in the usual location on the SIM. I resorted to putting the SIM in a normal phone and dialling *#100#, which'll ask the network for the number. Feed that into Vodafone's web site, and it'll send you a text message with a confirmation code. Once it's registered, put the SIM back in the modem.

(If you want to receive the text message using the modem, open a terminal on one of the non-PPP ports. It'll say something like +CMTI: "ME",1 when the message is received, meaning it's received a message and stored it in area ME, slot 1. To retrieve the message, select the area with AT+CPMS="ME", read it with AT+CMGR=1, then delete it with AT+CMGD=1.)