Free WiFi with EAP-SIM on a desktop computer

EAP-SIM on a mobile phone

Following its roll-out as a new authentication method to the WiFi community network of a major mobile operator in France in 2012, EAP-SIM has attracted quite some attention over there.

Yet the limited level of support of this technology in mobile devices available on the market has left many users struggling to get it to work effectively.

EAP-SIM is supported on the iPhone and the iPad since iOS 5 — and there are reports that it can be made to work on iOS 4.

On the other hand, it has taken Google 3 years to acknowledge and react to the lack of official EAP-SIM support on Android. After hundreds of sometimes infuriated messages, it looks like they started to work on implementing it in June 2013!
In Google’s defense, one can say that EAP-SIM can work on Android — as long as your phone manufacturer or mobile operator has implemented it in the phone’s software.
Still, it is unacceptable that Google’s Android flagship devices, the Nexus family, don’t support EAP-SIM natively.
Especially when there isn’t much work to do to implement properly.

Windows Phone 8+ and BlackBerry are reported to support EAP-SIM as far as I could gather.

EAP-SIM on a desktop computer

But this article isn’t about EAP-SIM on mobile devices. Instead it will show how to connect to a WiFi network using EAP-SIM on a desktop computer running Linux.

Hardware

The requirements are:

  1. a SIM card of an operator supporting EAP-SIM (e.g. Free)
  2. a computer with a WiFi adapter
  3. a SIM card reader (or “smartcard reader”)

I suppose that items 1. and 2. are already in your possession.
Regarding the SIM card reader, many models can be used, ranging from high-end devices to dirt cheap readers.

Let’s say that we want to do this experiment on a shoestring: we’ll settle on a $2 SIM card reader that is just good enough.
Go to eBay and grab one of these transparent blue SIM readers (don’t know if the other models are compatible).

This is a very low-tech smartcard reader, based on the so-called Phoenix architecture. Because of — or in spite of — this simplicity, it can be quite tricky to get it to work at times. (Or is it the OpenCT driver that is at fault?)

Wait for a couple of weeks for the little package from eBay to arrive and now you’ve got everything needed to proceed 🙂

Software

First, we’ll set up the software for the SIM card reader:

  1. Install the following packages (on Ubuntu):
    openct pcscd pcsc-tools libpcsclite-dev libnl-dev
  2. Plug in the SIM reader and run dmesg to determine the associated TTY:
    [85418.604327] usb 7-2: new full-speed USB device number 2 using uhci_hcd
    [85419.040763] USB Serial support registered for pl2303
    [85419.040824] pl2303 7-2:1.0: pl2303 converter detected
    [85419.052517] usb 7-2: pl2303 converter now attached to ttyUSB0
    [85419.052552] usbcore: registered new interface driver pl2303
    [85419.052556] pl2303: Prolific PL2303 USB to serial adaptor driver
  3. Add this piece of configuration to /etc/openct.conf (with the right TTY device):
    reader phoenix {
        driver = phoenix;
        device = serial:/dev/ttyUSB0;
    };
  4. Restart OpenCT:
    /etc/init.d/openct restart
  5. Insert the SIM card into the reader and check that it is correctly detected by OpenCT:
    root@desktop:~# openct-tool atr
    Detected Phoenix reader
    Card present, status changed
    ATR: 3b 9f 95 80 1f c7 80 31 e0 73 fe 21 1b 64 07 54 61 00 82 90 00 f0
  6. Check that it is also correctly detected by PCSC-Lite:
    root@desktop:~# pcsc_scan 
    PC/SC device scanner
    V 1.4.18 (c) 2001-2011, Ludovic Rousseau <ludovic.rousseau@free.fr>
    Compiled with PC/SC lite version: 1.7.4
    Using reader plug'n play mechanism
    Scanning present readers...
    0: OpenCT 00 00
    Wed Aug 28 17:55:25 2013
    Reader 0: OpenCT 00 00
     Card state: Card inserted, 
     ATR: 3B 9F 95 80 1F C7 80 31 E0 73 FE 21 1B 64 07 54 61 00 82 90 00 F0

At this point, you’ve confirmed that your $2 SIM reader works fine on your computer. Let’s continue to the core of the EAP-SIM set-up: the so-called “WPA supplicant”, which handles all the WiFi authentication phases.

  1. Download the latest release of hostapd:
    user@desktop:~$ wget http://hostap.epitest.fi/releases/hostapd-2.0.tar.gz
  2. Extract the archive and and go the the wpa_supplicant folder:
    user@desktop:wpa_supplicant$ cp defconfig .config
  3. Edit the newly created .config file so that it contains:
    # EAP-SIM (enable CONFIG_PCSC, if EAP-SIM is used)
    CONFIG_EAP_SIM=y
    # PC/SC interface for smartcards (USIM, GSM SIM)
    # Enable this if EAP-SIM or EAP-AKA is included
    CONFIG_PCSC=y
  4. Build the WPA supplicant program:
    user@desktop:wpa_supplicant$ make
  5. Create a configuration file wpa_supplicant_eap-sim.conf, with the correct PIN number:
    cred={
      imsi="none" # anything but blank value
    }
    network={
      ssid="FreeWifi_secure"
      key_mgmt=WPA-EAP IEEE8021X
      eap=SIM
      pin="1234"
      pcsc=""
    }
  6. Disconnect from any WiFi network, make sure that no other wpa_supplicant is running on your computer at the same time and run (wlan0 being the WiFi interface):
    root@desktop:wpa_supplicant# iwconfig wlan0 essid "FreeWifi_secure" && ./wpa_supplicant -i wlan0 -c wpa_supplicant_eap-sim.conf
  7. On the output, you will see that it worked correctly if it says:
    Successfully initialized wpa_supplicant
    wlan0: Trying to associate with xx:xx:xx:xx:xx:xx (SSID='FreeWifi_secure' freq=2417 MHz)
    wlan0: Associated with xx:xx:xx:xx:xx:xx
    wlan0: CTRL-EVENT-EAP-STARTED EAP authentication started
    EAP: buildIdentity: identity configuration was not available
    wlan0: CTRL-EVENT-EAP-PROPOSED-METHOD vendor=0 method=18
    wlan0: CTRL-EVENT-EAP-METHOD EAP vendor 0 method 18 (SIM) selected
    wlan0: CTRL-EVENT-EAP-SUCCESS EAP authentication completed successfully
    wlan0: WPA: Key negotiation completed with xx:xx:xx:xx:xx:xx [PTK=CCMP GTK=TKIP]
    wlan0: CTRL-EVENT-CONNECTED - Connection to xx:xx:xx:xx:xx:xx completed (auth) [id=0 id_str=]
  8. On another terminal, run a DHCP client for the WiFi interface:
    root@desktop:~# dhclient wlan0

Ta da, success!

You’re now connected to the FreeWifi_secure network, with an IP address giving access to the Internet.
Total cost: $2 for the SIM reader + €2 per month for the mobile phone subscription.

Building minimal OpenWrt firmware images

Although OpenWrt was originally conceived for devices acting as router, it can also be viewed as a generic embedded Linux distribution. It supports lots of different devices (not only routers, by the way) and currently provides almost 3500 packages.

However, the official firmware images hosted on downloads.openwrt.org are tailored for a router usage by default. Consequently they ship with many router-related packages: iptables, PPP(oE), DNS/DHCP server, etc.

While the presence of these additional packages would not matter a lot on a traditional platform — say, a PC — it’s quite different in a space- and CPU-constrained environment like a small ARM-based router.

Take for instance the TL-WR703N router, made by TP-LINK. Over the last few months (year ?), it has gained a lot of popularity among “embedded Linux” hobbyists. The main reasons being that it is cheap (~ US$20 as of today) and easily sourceable (eBay, DealExtreme, etc).

Its technical specs are rather limited though, in a world of dual-core, sup-GHz and multi-GB devices like smartphones and set-up boxes. Here is what the WR703N amounts to basically: a 400 MHz CPU with 16 MB of RAM and 4 MB of Flash. Given that about 1 MB of Flash is occupied by the Linux kernel itself, there’s only around 3 MB of space left for the rest of the OS and programs.

If you thought of uninstalling unwanted programs via the opkg package manager afterwards, there’s actually no point. The root filesystem is made of a read-only SquashFS partition that can’t be modified after installation. All the modifications on this initial root filesystem are contained in a writeable JFFS2 partition. That’s why uninstalling a program shipped by default won’t reclaim any space in the SquashFS partition. Quite the opposite in fact: it will probably use some space on the JFFS2 partition to account for the deletions of files!

Here’s an easy way how to build an OpenWrt firmware image that contains only the limited set of packages required to boot.

  1. Grab the so-called “Image Builder” for the target OpenWrt release and device architecture.
    In our case, let’s download the Image Builder for the ar71xx architecture (i.e. WR703N) running Attitude Adjustment, the latest OpenWrt stable release. (352 MB)

    http://downloads.openwrt.org/attitude_adjustment/12.09/ar71xx/generic/OpenWrt-ImageBuilder-ar71xx_generic-for-linux-i486.tar.bz2
  2. Decompress the archive and go into the resulting directory.
  3. Run this command:
    DEVICE_TYPE= PROFILE=WR703N make image
  4. Wait for the process to finish and you can then find the new firmware images as:
    bin/ar71xx/openwrt-ar71xx-generic-tl-wr703n-v1-squashfs-factory.bin
    bin/ar71xx/openwrt-ar71xx-generic-tl-wr703n-v1-squashfs-sysupgrade.bin

As printed on screen at the beginning of the build process, here’s the list of packages retained for this minimal firmware image:

base-files busybox dropbear hotplug2 kernel kmod-ath9k kmod-gpio-button-hotplug kmod-leds-gpio kmod-ledtrig-default-on kmod-ledtrig-netdev kmod-ledtrig-timer kmod-usb-core kmod-usb2 kmod-wdt-ath79 libc libgcc mtd netifd opkg swconfig uboot-envtools uci wpad-mini

Notice that all router-specific packages have vanished, saving some space of the constrained Flash memory:

root@wr703n:/# df -h
Filesystem                Size      Used Available Use% Mounted on
rootfs                    1.7M    212.0K      1.5M  12% /
/dev/root                 1.3M      1.3M         0 100% /rom
tmpfs                    14.3M     40.0K     14.2M   0% /tmp
tmpfs                   512.0K         0    512.0K   0% /dev
/dev/mtdblock3            1.7M    212.0K      1.5M  12% /overlay
overlayfs:/overlay        1.7M    212.0K      1.5M  12% /

End result: 1.5MB of space available on the root filesystem. Not bad for a device with an original 4MB Flash capacity, eh?

Furthermore, you’ll notice that this firmware, while modest in size, is yet quite well provided for: it contains a telnet server, a SSH server and it can also connect to a WPA-protected WiFi network thanks to the wpad-mini package (i.e. wpa_supplicant).

If you really wanted to save some additional space, I suppose you could trim those packages from the firmware image. That’s an exercise left to the reader 🙂
(Hint: see this file involved in the build process).