User Tools

Site Tools


equipment:dongle_ap

Setting up a wireless access point with a USB dongle

This tutorial uses the following software and hardware: Ubuntu 16.04 and a TP-Link WN-722N 2.4 GHz wireless-N USB dongle. It should also apply to other wireless hardware and Linux distributions. The interface name, generated from the MAC address of the device (the standard behavior in Ubuntu 16.04 when it comes to USB dongles) is, in this case, wlx18a6f71f1ad9.

Why?

Ubuntu already has in built-in ad-hoc functionality. However, it has shown to be very unreliable, and it does not have the possibility to use WPA encryption. For this reason we prefer to use a more powerful, customized solution: running a proper wireless AP using the hostapd daemon, combined with the isc-dhcp-server daemon for handling DHCP (IP address allocation).

Setting up

1. Installing the DHCP server

To install the DHCP server, run:

sudo apt install isc-dhcp-server

Open /etc/dhcp/dhcpd.conf and add a section which defines the address pool in the network. In this case, the network is 192.168.5.x, and connected devices get adresses in the range from 192.168.5.2 to 192.168.5.254.

subnet 192.168.5.0 netmask 255.255.255.0 {
  range 192.168.5.2 192.168.5.254;
  option subnet-mask 255.255.255.0;
  option broadcast-address 192.168.5.255;
}

Next, open /etc/default/isc-dhcp-server and set the interface isc-dhcp-server binds to:

INTERFACES="wlx18a6f71f1ad9"

2. Installing hostapd

Install the prerequisites and the Debian/Ubuntu version of hostapd:

sudo apt install libnl-3-dev libnl-genl-3-dev hostapd

The hostapd binary that comes with the package limits dual channel (40 MHz) functionality if the specified channels are already occupied by existing networks. However, as the 2.4 GHz spectrum is nowadays usually very crowded, this means that if this check was kept in place, most of the time we could not use the full declared capabilities of the wireless device. Most standalone access points already ignore this part of the standard. In order to fix this, hostapd needs to be patched and recompiled from source.

(Installing the hostapd package sounds redundant, if it is already going to be built from source. However, the Ubuntu/Debian version comes with some useful distribution-centric things such as an if-pre-up.d script which automatically starts hostapd when the interface is brought up).

The source of hostapd is available here (latest: v2.6 at the time of writing). Grab it from there and unpack it. Open the hostapd directory, make a copy of the file defconfig and name it .config. Open it, find the following lines and edit (uncomment) them:

CONFIG_LIBNL32=y
CONFIG_IEEE80211N=y

Next, open src/ap/hw_features.c, find the following block of code and delete it entirely:

if (!oper40) {
	wpa_printf(MSG_INFO, "20/40 MHz operation not permitted on "
		   "channel pri=%d sec=%d based on overlapping BSSes",
		   iface->conf->channel,
		   iface->conf->channel +
		   iface->conf->secondary_channel * 4);
	iface->conf->secondary_channel = 0;
	if (iface->drv_flags & WPA_DRIVER_FLAGS_HT_2040_COEX) {
		/*
		 * TODO: Could consider scheduling another scan to check
		 * if channel width can be changed if no coex reports
		 * are received from associating stations.
		 */
	}
}

Finally, to build and install, run (from the hostapd directory):

make
sudo make install BINDIR=/usr/sbin

3. Configuring the network interface and hostapd

To configure the network interface, add a section to /etc/network/interfaces. In this example, this will set the interface to use a fixed address 192.168.5.1.

auto wlx18a6f71f1ad9
iface wlx18a6f71f1ad9 inet static
  hostapd /etc/hostapd/hostapd.conf
  post-up service isc-dhcp-server restart
  address 192.168.5.1
  netmask 255.255.255.0

Create (as root) a file named /etc/hostapd/hostapd.conf with the following contents:

interface=wlx18a6f71f1ad9
driver=nl80211
country_code=HR
ctrl_interface=/var/run/hostapd
ctrl_interface_group=0
ssid=AMACAL
hw_mode=g
channel=6
beacon_int=100
dtim_period=2
max_num_sta=50
rts_threshold=2347
fragm_threshold=2346
wmm_enabled=1
ap_isolate=0
ieee80211n=1
ht_capab=[HT40-][RX-STBC1][HT20][SHORT-GI-40][SHORT-GI-20][DSSS_CCK-40]
logger_syslog=-1
logger_syslog_level=2
logger_stdout=-1
logger_stdout_level=2
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
ieee80211d=1

# Uncomment these lines to enable WPA
#wpa=3
#wpa_passphrase=YourPassPhrase
#wpa_key_mgmt=WPA-PSK
#wpa_pairwise=TKIP
#rsn_pairwise=CCMP

Customize if necessary. The file is interface-specific; if running APs from multiple interfaces, create multiple .conf files and add them to the appropriate interfaces in /etc/network/interfaces using the hostapd directive, as shown above.

The ht_capab line describes the set of high throughput capabilities supported by the wireless hardware. For example, [HT40-] means that the high throughput mode with 2×20 MHz channels will be used, with the main channel having a lower frequency than the auxiliary channel (the opposite combination being [HT40+]; this choice affects which channels can be selected, e.g. for 2.4 GHz: HT40- 5-13; HT40+ 1-9). SHORT-GI means a short guard interval is used, which usually increases throughput. However, a too short guard interval can cause problems with inter-symbol interference when multipath signal reflections are present.

To aid you in configuring ht_capab, you can list the capabilities of your wireless hardware using the command iw list. For more information on configuring hostapd.conf, see the example config file in /usr/share/doc/hostapd/examples/hostapd.conf.gz.

equipment/dongle_ap.txt · Last modified: 2017/05/12 09:29 (external edit)