Linux Wireless AP Configuration


Configuring wireless in Linux can be complex. A very common question is how does one configure an IEEE802.11 radio as an Access Point (AP) from the command line interface (CLI). This question is difficult to answer due to evolving wireless technologies. Several tools have been created to aid in configuring these devices, but are generally not user friendly or portable across operating systems (OS).

For example, in the OpenWrt OS, the UCI System allows users to configure their wireless devices easily through the CLI. But because this tool is tightly integrated into OpenWrt, it is not easily portable to other OS’s such as Yocto or Ubuntu. Other OS’s attempt to solve wireless configuration in their own way, but fail to provide an easy solution from the serial console (e.g. using NetworkManager in Ubuntu).

Gateworks has created an open-source script called hostapd-conf that creates configuration files for the Host Access Point Daemon (hostapd), a standard Linux user space daemon that is capable of creating and managing wireless APs. Both tools are provided by default on our Yocto 1.8 BSP. The inspiration came from the simplicity of the tool wpa_passphrase, a simple CLI tool that allows for an easy way to connect to wireless APs.

The hostapd-conf script is written for users wanting to create an AP out of a radio with optional WPA2 encryption. It gathers information on a specified wireless interface through iw and uses the data to generate a proper hostapd.conf file. It has only a few dependencies to run: iw, sed, grep, and cut. It should be noted that the ‘full’ version of these tools are required as opposed to the ‘busybox’ version.

The hostapd-conf script usage is shown below:

root@ventana:~# hostapd-conf --help
hostapd-conf [OPTIONS] <iface> <ssid> <channel> [<htmode>] [<passphrase>]

 --help           - This help
 --br-name <name> - Name of bridge
 --wds <0|1>      - Enable WDS
 --version        - Print this version: v1.0

hostapd-conf also has the ability to list supported MCS Rates (e.g. HT20, VHT80 etc) per channel that the radio is allowed to emit radiation on. For example, the WLE350NX radio, an 802.11a/b/g/n radio, has the following channels that it may emit on:

root@ventana:~# hostapd-conf wlan0
ERROR: SSID is empty

Available Channel Information on phy2
Band 1:
Channel  Freq  Allowed HT Modes
0        0000  HT20 HT40 HT40+ HT40-
1        2412  HT20 HT40 HT40+
2        2417  HT20 HT40 HT40+
3        2422  HT20 HT40 HT40+
4        2427  HT20 HT40 HT40+
5        2432  HT20 HT40 HT40+ HT40-
6        2437  HT20 HT40 HT40+ HT40-
7        2442  HT20 HT40 HT40+ HT40-
8        2447  HT20 HT40 HT40+ HT40-
9        2452  HT20 HT40 HT40+ HT40-
10       2457  HT20 HT40 HT40-
11       2462  HT20 HT40 HT40-

Band 2:
Channel  Freq  Allowed HT Modes
0        0000  HT20 HT40 HT40+ HT40-
36       5180  HT20 HT40 HT40+
40       5200  HT20 HT40 HT40-
44       5220  HT20 HT40 HT40+
48       5240  HT20 HT40 HT40-
149      5745  HT20 HT40 HT40+
153      5765  HT20 HT40 HT40-
157      5785  HT20 HT40 HT40+
161      5805  HT20 HT40 HT40-
165      5825  HT20 HT40 HT40+

From the above output, it is shown that the WLE350NX radio has two bands to select from, 2.4GHz and 5GHz. Each band offers a specific range of channels it can output on with their allowed MCS Rates, which hostapd-conf details out. Please note that the ‘0’ channel is special to hostapd. It enables Automatic Channel Selection (ACS) in order to allow the radio to pick the best channel to emit radiation on.

The following invocation of hostapd-conf will create a configuration file to output at 5.18GHz with 40MHz bandwidth, with an SSID of “wlan0-ssid” and WPA2 passphrase of “nowayinside”:

root@ventana:~# hostapd-conf wlan0 "wlan0-ssid" 36 HT40 "nowayinside"
 IFACE:      wlan0
 PHY:        phy2
 SSID:       wlan0-ssid
 CHANNEL:    36
 FREQ:       5180
 BANDS:      1 2
 HWMODE:     a
 HTMODE:     HT40
 PASSPHRASE: nowayinside

Written to hostapd-phy2.conf

The output of the script, hostapd-phy2.conf, now holds the proper configuration required by hostapd to configure the radio to these specifications. Please take care to edit this newly created file manually if your country requires Dynamic Frequency Selection (DFS) for the channel you are emitting on. The following lines may need to be uncommented / edited:


In an example system, four wireless radio’s were connected to a Gateworks GW5400 Single Board Computer: 1x using ath5k, 2x using ath9k, and 1x using ath10k. After following the above steps for each of the radio’s in the system, hostapd was invoked and all four radio’s were configured with different channels and technologies.

By default, hostapd will use the configuration file located at /etc/hostapd.conf. Because of this, first stop any hostapd instance that is running. Then, simply start it as a background process, for example:

root@ventana:~# /etc/init.d/hostapd stop
Stopping HOSTAP Daemon: stopped /usr/sbin/hostapd (pid 14876)
root@ventana:~# hostapd -B hostapd-phy0.conf hostapd-phy1.conf hostapd-phy2.conf hostapd-phy3.conf
Configuration file: hostapd-phy0.conf
Configuration file: hostapd-phy1.conf
Configuration file: hostapd-phy2.conf
Configuration file: hostapd-phy3.conf
[   34.390709] IPv6: ADDRCONF(NETDEV_UP): wlan3: link is not ready
wlan3: interface state UNINITIALIZED->HT_SCAN
[   34.409563] IPv6: ADDRCONF(NETDEV_UP): wlan2: link is not ready
Using interface wlan2 with hwaddr 00:24:2b:38:be:db and ssid "wlan2-ssid"
[   34.473223] IPv6: ADDRCONF(NETDEV_CHANGE): wlan2: link becomes ready
wlan2: interface state UNINITIALIZED->ENABLED
[   34.514817] IPv6: ADDRCONF(NETDEV_UP): wlan0: link is not ready
wlan0: interface state UNINITIALIZED->HT_SCAN
[   34.542100] IPv6: ADDRCONF(NETDEV_UP): wlan1: link is not ready
wlan1: interface state UNINITIALIZED->HT_SCAN
root@ventana:~# [   34.614847] IPv6: ADDRCONF(NETDEV_CHANGE): wlan3: link becomes ready
[   34.798881] IPv6: ADDRCONF(NETDEV_CHANGE): wlan0: link becomes ready
[   35.620978] IPv6: ADDRCONF(NETDEV_CHANGE): wlan1: link becomes ready

Other examples may also be found here on our Wireless wiki page. There are examples on how to create a routed AP, bridged AP, and includes other valuable information