ath9k & hostapd HOWTO

Some little time ago I purchased a TP-Link TL-WN951N wireless card for my penguin box.  I had lofty intentions to use it in master mode as an access point and retire my Netgear wireless router (it hasn’t been used as a router for over a year).  Seeing as the TL-WN951N uses an Atheros chipset which are among the more well-supported in Linux, I figured it would be simple.

In the end it was.  But the road to success was fraught with furious SSH sessions and swearing about almost nonexistent documentation.  Many hours were spent groping the internet for information on how to make it all work that didn’t rely on you being one of the driver or back-end software developers (who, to be fair, in the discussions I read were very helpful).

Finally though the stars aligned and now it all works peachily.  This is how to make it happen:

  • Update  your kernel to 2.6.30.  Earlier ath9k driver versions in previous kernels are either non-functional in master mode, or unreliable in operation (2.6.29 works, but the connection drops out every 5 minutes).
  • Make sure you have a recent version of hostapd installed.  hostapd 0.6.9 is recommended (along with its various dependencies).
  • You need to have wireless-tools and iw installed so that the wireless card is available to be configured by hostapd and the networking subsystem.

These three steps cover the most important software items to make it all work.  If you would like your wireless clients to be assigned IPs via dhcp, don’t forget to install dhcpd and configure it (details below).

On to setting it all up.  Check first that your wireless card is available:

#iwconfig

wlan0     IEEE 802.11bgn  Mode:Master  Frequency:2.437 GHz  Tx-Power=20 dBm
Retry min limit:7   RTS thr:off   Fragment thr:off
Encryption key:
Power Management:off
Link Quality:0  Signal level:0  Noise level:0
Rx invalid nwid:0  Rx invalid crypt:0  Rx invalid frag:0
Tx excessive retries:0  Invalid misc:0   Missed beacon:0

If you receive only “no wireless extensions” messages, or “command not found” ensure that the wireless-tools package is properly installed and that you have rebooted if you updated your kernel.

Make a note of the wireless adaptor name – here ‘wlan0’.  Yours is likely to be similar, if not the same.  Choose now a subnet for your wireless network to operate in.  I use 192.168.3.0/24, but you can choose one that suits your setup or preference.  192.168.3.1 will be the access point IP, and all other wireless clients will have an address in the range 192.168.3.2 – 192.168.3.254 that you can assign or have setup automatically by DHCP.  We can now set the access point network information (substitute your preferred IP address and appropriate network mask):

#ifconfig wlan0 192.168.3.1 netmask 255.255.255.0

This alone won’t do much – we still need hostapd to allow wireless clients to talk to our card.  Now, hostapd is a tremendous piece of software.  It can perform just about any kind of network authentication and access control you can think of.  The list of options and configurations is mindboggling.  As is the almost complete lack of quality documentation, which is a shame and de rigeur for complex daemon software.  Thankfully very few parameters need to be tweaked to make it “just work”.  We will set our AP up to offer WPA and WPA2 connections (WEP is weaksauce and shame on you if you intend to run an unsecured network).

Open up your favourite editor (I prefer nano, because I’m not masochistic enough to use ed or vi) and create your very own hostapd.conf file:

interface=#Your_WLAN_name_here#
driver=nl80211

ssid=#Your_SSID_here#

channel=6
hw_mode=g

auth_algs=1
wpa=3
wpa_passphrase=#Your_preshared_key_here#
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP CCMP
rsn_pairwise=CCMP

Of course,  insert the correct details for the wlan name (e.g. wlan0), the SSID (e.g. my_wifi) and your preferred psk – make sure it’s not something stupid 🙂

No config items for 802.11n mode are included – my limited testing hasn’t yet shown any way to make it work (but I didn’t try very hard).  In that little stream of options there we have specified the following:

  • Linux kernel MAC80211 interface operation (supported by the ath9k driver)
  • 54Mb (802.11g) operation.  You can change the channel to suit your preference or environment
  • WPA or WPA2 operation

The other settings give hostapd further details about encryption settings to implement.  Those shown will allow Linux and Windows clients to connect reliably.  Including my Squeezebox 🙂

Now we can try it all out:

#hostapd -d hostapd.conf

Ensure you use the correct path to your previously created hostapd.conf file.  You should experience a large amount of debug spam, but no funny messages or warnings should be forthcoming.  Your access point is now working.  On to testing!  Grab your preferred wireless client (laptop, netbook, Squeezebox, whatever) and look for your new network.  Providing you enter the correct network key you will soon have a successful connection; albeit without any network traffic since not much happens without an IP.  If you are happy to stick with static IPs, set one up for each of your clients, either by ifconfig in Linux, or through the usual Control Panel nonsense in Windows.  However, static IPs are a bit of a pain in the butt.  Let’s play with out dhcpd.conf file.

If you use the reasonably-standard dhcp3-server package, locate and open dhcpd.conf in the /etc/dhcp3/ directory and add something like the following:

subnet 192.168.3.0 netmask 255.255.255.0 {
range 192.168.3.10 192.168.3.49;
option routers 192.168.2.1;
option ip-forwarding off;
option subnet-mask 255.255.255.0;
option broadcast-address 192.168.3.255;
}

Ensure you provide correct values for the subnet, range, and routers values.  The “option routers” value can safely be set to the IP of the local ethernet adaptor in your box.  The range values can be any legal IP in the subnet you chose, excluding the previously set IP of your wireless adaptor and the broadcast address (the x.x.x.255 one).  Save dhcpd.conf and restart dhcpd:

#./etc/init.d/dhcpd restart

Your should now be able to connect to your new wireless network and be assigned an appropriate address automagically.  If you are unhappy about having your wired and wireless networks on different subnets, you can involve yourself in bridging the two, but it really isn’t necessary to make everything all work – providing your router box is set up correctly you will have no routing issues between the two networks.

One final comment – if you are running an iptables-based firewall on your penguin box, don’t forget to insert the appropriate input, output and forwarding chains to allow your wireless packets to be allowed to go somewhere.

12 thoughts on “ath9k & hostapd HOWTO

  1. By the way….
    If your network support 802.11n 300Mbps you need to add some lines to enable it.

    wme_enabled=1
    ieee80211n=1
    ht_capab=[HT40+][SHORT-GI-40][DSSS_CCK-40]

    Enjoy!

  2. Pingback: Hostapd tutorial | Badegar

  3. Pingback: Ath9k as AP in Arch Linux « Doom ???

  4. Hello,

    Thanks for tutorial.

    I used this so i can connect with my phone to my laptop, it connects but internet is not working.
    From laptop i can ping phone IP, i used static IP.

    Any suggestion?

  5. Pingback: Creazione di Un Hotspot Wifi con Coova-chilli e scheda Atheros | Luca Rossi - IT Freelance

  6. Pingback: anybody know any programs i can use to turn my laptop into a wifi hotspot?

  7. Thanks so much for this guide! I was about to give up on getting this card to work when I found this blog post. Everything worked perfectly after following these steps.

  8. Pingback: undertakingyou » Blog Archive » Laptop to an AP

  9. @orange
    I noticed this as well, but it turns out the solution was just to push on and ignore it – hostapd will be able to put the card into Master mode even if iwconfig refuses. I found an explanation here.

    iwconfig wlan0 mode master fails This is failure by design. The mac80211 stack does not contain the required components to run in master mode by itself… Rather than let users set it to master mode and not have it work, it tells you that the operation is not supported…..With mac80211, you NEED hostapd for any sort of functional access point.

  10. I’ve got the same card and objective, but I’m having trouble getting my card into Master Mode. Any tips on that? I am running Ubuntu 9.10 on kernel 2.6.31-17-generic and ath9k appears to be the wireless driver I am using. Running iwconfig wlan0 mode master returns “SET failed on device wlan0 ; Invalid argument.

Leave a Reply