HowTos/roaming with wpa supplicant

From OpenZaurus

Contents

Notes

  • WPA is not possible with USB prism chipset based devices such as the built-in wifi in the SL-6000/Tosa.
  • This howto assumes that you have some basic knowledge of the Linux command line (ie, how to change directories, edit files, change file permissions, etc)
  • If something I say here is too vague or blatantly wrong, tell me and I'll try to clarify/correct it.
  • Make backups of files you edit!
  • WPA-Supplicant allow to connect to any WiFi networks - nevermind whether they use WPA, WPA2, WEP or no encryption.

There is a tool wpa-gui for X11 enviroments which allow to configure networks for WPA Supplicant.

Making it work

First of all, you'll need to edit /etc/network/interfaces. Comment out your current wireless config and add a section that looks like the following :

# Wireless interfaces (WPA roaming!)
iface wlan0 inet dhcp
       wpa-conf /etc/wpa_supplicant.conf
       wpa-driver hostap

# Wireless interfaces
#iface wlan0 inet dhcp
#       wireless_mode managed
#       wireless_essid myap
#       wireless_key off

It is important that there is only 1 space between wpa-xxx and the setting as otherwise the current wpa_supplicant scripts in OZ will fail to start wpa_supplicant.

For wpa-driver, you can specify either hostap or wext. Theoretically any card that can be used with iwconfig should work with wext, but on my card (LinkSys 802.11b) only hostap worked. YMMV.

Next, you'll need to edit /etc/wpa_supplicant.conf to include the networks you wish to connect to. A good example is the one at the wpa_supplicant page.

Next you'll need a script in /etc/network/if-pre-up.d to handle running wpa_supplicant before the interface is brought up, and shutting down wpa_supplicant after the interface is brought down. The script may already be provided with the package in OpenZaurus. Otherwise, you may adapt this example. I made this script by cutting down the /etc/network/if-pre-up.d/wpasupplicant script in Ubuntu Dapper (which is the same script that's in recent versions of Debian, I think). Here it is:

#!/bin/sh


WPA_SUP_BIN="/usr/sbin/wpa_supplicant"
WPA_SUP_PNAME="wpa_supplicant"
WPA_SUP_PIDFILE="/var/run/wpa_supplicant.$IFACE.pid"
WPA_SUP_OPTIONS="-B -P $WPA_SUP_PIDFILE -i $IFACE"

VERBOSITY=0


if [ -s "$IF_WPA_CONF" ]; then
	WPA_SUP_CONF="-c $IF_WPA_CONF"
else
	exit 0
fi

if [ ! -x "$WPA_SUP_BIN" ]; then
	
	if [ "$VERBOSITY" = "1" ]; then
		echo "$WPA_SUP_PNAME: binaries not executable or missing from $WPA_SUP_BIN"
	fi
	
	exit 1
fi

if [ "$MODE" = "start" ] ; then
	# driver type of interface, defaults to wext when undefined
	if [ -s "/etc/wpa_supplicant/driver.$IFACE" ]; then
		IF_WPA_DRIVER=$(cat "/etc/wpa_supplicant/driver.$IFACE")
	elif [ -z "$IF_WPA_DRIVER" ]; then
		
		if [ "$VERBOSITY" = "1" ]; then
			echo "$WPA_SUP_PNAME: wpa-driver not provided, using \"wext\""
		fi
		
		IF_WPA_DRIVER="wext"
	fi
	
	# if we have passed the criteria, start wpa_supplicant
	if [ -n "$WPA_SUP_CONF" ]; then
		
		if [ "$VERBOSITY" = "1" ]; then
			echo "$WPA_SUP_PNAME: $WPA_SUP_BIN $WPA_SUP_OPTIONS $WPA_SUP_CONF -D $IF_WPA_DRIVER"
		fi
		
		start-stop-daemon --start --quiet \
			--name $WPA_SUP_PNAME --startas $WPA_SUP_BIN --pidfile $WPA_SUP_PIDFILE \
			--  $WPA_SUP_OPTIONS $WPA_SUP_CONF -D $IF_WPA_DRIVER
	fi

	# if the interface socket exists, then wpa_supplicant was invoked successfully
	if [ -S "$WPA_COMMON_CTRL_IFACE/$IFACE" ]; then
	
		if [ "$VERBOSITY" = "1" ]; then
			echo "$WPA_SUP_PNAME: ctrl_interface socket located at $WPA_COMMON_CTRL_IFACE/$IFACE"
		fi

		exit 0
		
	fi
	
elif [ "$MODE" = "stop" ]; then

	if [ -f "$WPA_SUP_PIDFILE" ]; then
		
		if [ "$VERBOSITY" = "1" ]; then
			echo "$WPA_SUP_PNAME: terminating $WPA_SUP_PNAME daemon"
		fi
		
		start-stop-daemon --stop --quiet \
			--name $WPA_SUP_PNAME --pidfile	$WPA_SUP_PIDFILE
			
		if [ -S "$WPA_COMMON_CTRL_IFACE/$IFACE" ]; then
			rm -f $WPA_COMMON_CTRL_IFACE/$IFACE
		fi
			
		if [ -f "$WPA_SUP_PIDFILE" ]; then
			rm -f $WPA_SUP_PIDFILE
		fi
	fi

fi

exit 0

(Sorry about those long lines.)

Be sure to symlink the file from if-pre-up.d to if-post-down.d

Also, make sure to make that file executable by root.

And that should do it! The first time you test it, you might want to run (-v option helps see some of the commands that get started) :

ifdown -v wlan0 ; ifup -v wlan0

That way you will be able to see any error messages that get displayed.

Additional Notes

  1. It's likely that running the GUI network configuration tool in Opie or GPE will overwrite the wireless config in your /etc/network/interfaces .
  2. I've tested this on wpa_supplicant 0.4.8 and kernel 2.6.16 on an Akita.
  3. I just tested this on my collie with with wpa_supplicant 0.4.8 and it makes anything wireless-related segfault. Switching the config back and rebooting fixes it. Can someone else do further testing to make sure it isnt just my particular hardware? --rm_you
  4. When I prevent udhcpc from starting before wpa_supplicant has set up the wlan connection it works. When udhcpc is started by ifup before wpa_supplicant established the connection all my wireless-commands segfault, too. --rabinath


Installing a newer firmware on the card

I couldn't get WPA (using wpa_supplicant) to work on my Prism2 card without upgrading the STA firmware. This can be done without risk by uploading the new image to RAM.

First load the hostap driver, and unload the orinoco one (modprobe -r orinoco_cs).

To find out the versions in your card, use hostap_diag. Example:

root@spitz:~# hostap_diag wlan0
Host AP driver diagnostics information for 'wlan0'

NICID: id=0x8002 v1.0.0 (HWB3163-01,02,03,04 Rev A)
PRIID: id=0x0015 v0.3.0
STAID: id=0x001f v1.7.1 (station firmware)

My card had an old version of the STA firmware: "STAID: id=0x001f v0.8.3 (station firmware)", and WPA doesn't work with it. (Works fine with v1.7.1)

To solve this, download the latest firmware. You want to update the STA firmware, included in the "secondary-RAM" directory in that tar file.

To find out which one is compatible with your card, use the following command:

prism2_srec wlan0 firmware.hex

Example of a compatible file:

root@spitz:~/firmware/secondary-RAM# prism2_srec wlan0 r1010701.hex 
srec summary for r1010701.hex
Included file name: r1010701.hex
Component: 0x001f 1.7.1 (station firmware)

Verifying update compatibility and combining data:
OK.

Update the firmware using the -r option:

prism2_srec wlan0 -r r1010701.hex

To do this process automatically, I copied the firmware file to /etc/hostap/ and wrote the following in /etc/network/interfaces :

iface wlan0 inet dhcp
       pre-up prism2_srec wlan0 -r /etc/hostap/r1010701.hex
       pre-up wpa_supplicant -B -Dwext -iwlan0 -c/etc/wpa_supplicant.conf
       post-down killall wpa_supplicant


Note that I'm using wpa_supplicant with the wext driver. With the updated firmware, it works with the -Dwext option as well as with -Dhostap.

The /etc/wpa_supplicant.conf contains:

ctrl_interface=/var/run/wpa_supplicant
ctrl_interface_group=0
eapol_version=1
ap_scan=1
fast_reauth=1
network={
       ssid="myssid"
       proto=WPA
       pairwise=TKIP
       psk="very secret and secure passphrase"
       priority=1
}

More info on updating the firmware here, and here. (--amaldo)