Gentoo Linux wireless success: Netgear WG311, madwifi, wpa_supplicant

(Also check out my HOWTO for the Netgear WG111, which is a USB device.)

It seems like there are 100 different ways to do wifi on Linux, and there is so much incomplete documentation floating around on all of them. I just finally got mine working, so I wanted to post a complete start-to-finish howto.

First of all, I'm running a 2.6.11-gentoo-r9 kernel on a Pentium-III system. My network card is a Netgear WG311 (v1, which isn't shown on the card, it just says WG311) PCI card, which does 802.11b/g. This card uses an Atheros chip:

[root@host]# lspci
0000:00:0c.0 Ethernet controller: Atheros Communications, Inc.
	AR5212 802.11abg NIC (rev 01)

First I got the latest baselayout, which was 1.11.13:

[root@host]# emerge -vabk baselayout

Since baselayout changes /etc so much, and since dispatch-conf regularly borks my files, I make a complete backup of /etc before doing any etc-update or dispatch-conf. The whole of /etc is only a few tens of MB so it's no big deal to backup the whole thing:

[root@host]# mkdir /arch
[root@host]# cp -a /etc /arch/etc-arch20050722-before-new-baselayout

Next I run etc-update to auto-merge trivial /etc changes, but then I exit it (use the "-1" option) and do dispatch-conf to manually merge the non-trivial changes.

OK, back to the topic at hand:

[root@host]# emerge -vabk wireless-tools
[root@host]# emerge -vabk wpa_supplicant
[root@host]# emerge -vabk madwifi-driver
[root@host]# emerge -vabk madwifi-tools

This gets me wireless-tools-27-r1, wpa_supplicant-0.3.8-r1, madwifi-driver-0.1_pre20050420, and madwifi-tools-0.1_pre20050420.

Merging madwifi-driver told me to do some stuff when it finished, but I ignored it for now.

Next, start the driver and check that the modules all load:

[root@host]# modprobe ath_pci
[root@host]# lsmod|grep ath
ath_pci                52832  0
ath_rate_amrr           7076  1 ath_pci
wlan                  106652  3 ath_pci,ath_rate_amrr
ath_hal               146864  2 ath_pci

Now put this into /etc/conf.d/net:

modules=( "wpa_supplicant" )
wpa_supplicant_ath0="-Dmadwifi"
wpa_timeout_ath0=20
# optionally set the IP and router for your wireless card to use.
# if you're using DHCP you can skip these.
ifconfig_ath0=( "192.168.1.10 netmask 255.255.255.0" )
routes_ath0=( "default gw 192.168.1.1" )

Now create /etc/wpa_supplicant.conf by copying it from /etc/wpa_supplicant.conf.example. Delete all the example network blocks at the bottom, and put just this one in:

network={
	ssid="my_network_name"

	# Don't put the password in here like this...
	#psk="my WPA password"
	#
	# ...instead, use the wpa_passphrase utility to
	# generate a hash from your SSID and password,
	# and enter that hash here:
	psk=da6b245c5de62423e6d263c822...

	key_mgmt=WPA-PSK
	proto=WPA
}

Since that file now contains your network credentials (even though they are hashed and thus relatively safe), make it readable by only root:

[root@host]# chmod 0600 /etc/wpa_supplicant.conf

Create your net.ath0 device:

[root@host]# cd /etc/init.d
[root@host]# ln -s net.eth0 net.ath0

Now your configuration should be complete; just restart the driver:

[root@host]# rmmod ath_pci ath_rate_amrr wlan ath_hal
[root@host]# lsmod|grep ath
(there should be no output)
[root@host]# modprobe ath_pci

Run iwconfig and ifconfig to see that it's up:

[root@host]# iwconfig ath0
ath0      IEEE 802.11g  ESSID:"yourssid" 
          Mode:Managed  Frequency:2.462 GHz  Access Point:
		00:XX:XX:XX:XX:9E   
          Bit Rate:36 Mb/s   Tx-Power:50 dBm   Sensitivity=0/3 
          Retry:off   RTS thr:off   Fragment thr:off
          Encryption key:4CCD-DCC5-3CC8-2CC9-4CCE-DCC1-9CCC-8CC7
		Security mode:restricted
          Power Management:off
          Link Quality=23/94  Signal level=-72 dBm  Noise level=-95 dBm
          Rx invalid nwid:0  Rx invalid crypt:0  Rx invalid frag:0
          Tx excessive retries:0  Invalid misc:0   Missed beacon:0

[root@host]# ifconfig ath0
ath0      Link encap:Ethernet  HWaddr 00:XX:XX:XX:XX:32 
          inet addr:192.168.1.10  Bcast:192.168.1.255
		Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:4 errors:4 dropped:0 overruns:0 frame:4
          TX packets:3 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:199
          RX bytes:548 (548.0 b)  TX bytes:417 (417.0 b)
          Interrupt:11 Memory:f8d40000-f8d50000

You win!

Now to test it, stop your wired network card:

[root@host]# /etc/init.d/net.eth0 stop

But now your default route is gone, because it was mapped through eth0:

[root@host]# route
Kernel IP routing table
Destination   Gateway     Genmask        Flags Metric Ref   Use Iface
192.168.1.0   *           255.255.255.0  U     0      0       0 ath0
loopback      localhost   255.0.0.0      UG    0      0       0 lo

So add it back, on ath0:

[root@host]# route add default gw 192.168.1.1

[root@host]# route
Kernel IP routing table
Destination   Gateway       Genmask        Flags Metric Ref   Use Iface
192.168.1.0   *             255.255.255.0  U     0      0       0 ath0
loopback      localhost     255.0.0.0      UG    0      0       0 lo
default       192.168.1.1   0.0.0.0        UG    0      0       0 ath0

Now your network should be working properly.

To make your ath0 start at boot:

[root@host]# rc-update add net.ath0 default
 * net.ath0 added to runlevel default
 * rc-update complete.

And to stop eth0 from starting anymore:

[root@host]# rc-update del net.eth0 default
 * net.eth0 removed from the following runlevels: default
 * rc-update complete.

Verify it:

[root@host]# rc-update show|grep -i net
               local |      default nonetwork
            net.ath0 |      default           
            net.eth0 |
              net.lo | boot                   
            net.ppp0 |                       
            netmount |      default

Finally, edit /etc/modules.autoload.d/kernel-2.6 and add a new line at the bottom that says just "ath_pci" (without quotes); this will load the driver automatically when your system starts.

Now reboot and the wireless network card should be working.


(Note: I also posted this in the Gentoo Forums.)