How to use hostapd (AP mode)

What is hostapd

Last time, I explained how to use hostap's wpa_supplicant (client mode).

This time, I would like to explain how to use hostapd (AP mode).

 

hostapd is open source software for making wireless LAN devices act as AP/authentication servers.

Like wpa_supplicant, it supports various OS and drivers, and the user interface also supports CUI/GUI.

environment

This time, the environment used is Ubuntu16.04 + Kernel4.9.11 +QCA9377(Qualcomm Wireless LAN products) will be combined.

Basic usage of hostapd

hostapd operates as an AP/authentication server by setting the information of the AP or authentication server to operate.

hostapd can be operated with a user interface (CUI/GUI).

By writing the setting information in the hostapd.conf file in advance, hostapd will operate as an AP/authentication server just by starting it.

By using the user interface, it is possible to perform dynamic processing such as disconnecting a connected Client device or starting WPS.

Setting up and starting hostapd

First, prepare the hostapd configuration file.

This time, we will proceed while explaining the parameters to be set when starting as an AP.

Below is the contents of the configuration file (hostapd.conf (name is arbitrary)).

Unlike wpa_supplicant.conf, AP settings cannot be changed dynamically and must be written.

The example below is a WPA2-PSK/WPA3-SAE AP configuration. (WPS compatible)

A client device that supports WPA3-SAE is WPA3-SAE, and a client device that does not support WPA3-SAE but supports WPA2-PSK can be connected with WPA2-PSK.

As with wpa_supplicant, default values are applied to some parameters that are not set.

interface=wlan0 driver=nl80211 ctrl_interface=/var/run/hostapd country_code=JP ssid=test channel=1 <= APのチャネルをch1に指定します。0にした場合サポートしていればACSが動作します。(CONFIG_ACSを有効にしてhostapdをビルドします) hw_mode=g <= Phyモードを11gに指定します。 ieee80211n=1 <= 11nを有効にします。 wpa=2 <= WPA2/3を有効化します。(wpa=1はWPA) wpa_key_mgmt=SAE WPA-PSK <= 対応するkey_mgmtです。(複数サポートする場合は半角スペースで分けます) wpa_passphrase=12345678 <= パスワード(PSK)をセットします。 auth_algs=1 <= WEPでなければ’1’です。 wpa_pairwise=CCMP group_cipher=CCMP ieee80211w=1 <= SAEに対応する場合1/2が必要になります。(1:Optional,2:Mandatory) ※2にするとPMFを有効化していないWPA2デバイスが接続できなくなります。 ここから下の設定はWPS用です。 eap_server=1 <= WPS処理用のInternalRADIUSサーバーを有効にします。 wps_state=2 config_methods=virtual_push_button <= PBCを有効にします。 これは最低限ツようなパラメーターになります。デバイス名など相手に渡すことが可能なパラメーターオプションがいくつかあります。 以下のパラメーターでMACアドレスのフィルタリングが可能です。 macaddr_acl=0 <= 0:accept_mac_fileに記載のあるデバイスのみ接続を許可します。1:deny_mac_fileに記載のあるデバイス以外のデバイスの接続を許可します。 accept_mac_file=/etc/hostapd.accept <= 接続を許可するデバイスのMACアドレスを記載します。 #deny_mac_file=/etc/hostapd.deny <= 接続を拒否するデバイスのMACアドレスを記載します。

Start hostapd with the following command.

hostapd hostapd.conf &

test@test-ThinkPad-T430:~# ./hostapd ./hostapd.conf &
test@test-ThinkPad-T430:~# rfkill: Cannot open RFKILL contro[   96.249484] IPv6: ADDRCONF(NETDEV_UP): wlan0: link is not ready
l device
[   96.258172] IPv6: ADDRCONF(NETDEV_CHANGE): wlan0: link becomes ready
wlan0: interface state UNINITIALIZED->COUNTRY_UPDATE
random: Only 11/20 bytes of strong random data available
random: Not enough entropy pool available for secure operations
WPA: Not enough entropy in random pool for secure operations - update keys later when the first station connects
Device is trying to offload WPS Probe Response while not supporting this
[   96.298691] DEBUGFS PEER MAC = 0x66:0x55:0x44:0x33:0x22:0x11
[   96.423291] TXRX: Couldn't find peer from ID 13 - skipping security inits
wlan0: interface state COUNTRY_UPDATE->ENABLED
wlan0: AP-ENABLED
wlan0: IEEE 802.11 driver had channel switch: freq=2412, ht=1, vht_ch=0x0, he_ch=0x0, offset=0, width=1 (20 MHz), cf1=2412, cf2=0
wlan0: CTRL-EVENT-CHANNEL-SWITCH freq=2412 ht_enabled=1 ch_offset=0 ch_width=20 MHz cf1=2412 cf2=0 dfs=0
wlan0: AP-CSA-FINISHED freq=2412 dfs=0

If “AP-ENABLED” is displayed, the startup is successful.

At this point, the AP is found and connectable from the Client device.

wlan0: STA 36:29:44:b3:09:28 IEEE 802.11: associated
[13014.665300] TXRX: Couldn't find peer from ID 13 - skipping security inits
wlan0: AP-STA-CONNECTED 11:22:33:44:55:66
wlan0: STA 11:22:33:44:55:66 RADIUS: starting accounting session 92BBDCD2D27E1BC8
wlan0: STA 11:22:33:44:55:66 WPA: pairwise key handshake completed (RSN)
wlan0: EAPOL-4WAY-HS-COMPLETED 11:22:33:44:55:66

When connecting from the Client device, such a log is output.
“AP-STA-CONNECTED” is displayed when Associate is successful, and “EAPOL-4WAY-HS-COMPLETED” is displayed when 4way handshake is successful.
After that, you will be able to communicate by assigning a fixed IP or starting a dhcp server.

Control command

Start hostapd_cli in interactive mode.

hostapd_cli -iwlan0 -p/var/run/hostapd

 

The main commands used after starting the AP are described.

list_sta: Display connected client devices.

deauthenticate/disassociate <Mac address (all in ff:ff:ff:ff:ff:ff)>: Disconnect target MAC or all devices.

chan_switch <beacon count until channel switch is executed> <destination freq>: Execute channel switch.

wps_pbc: Wait for WPS in PBC mode.

> list_sta
66:55:44:33:22:11

deauthenticate/disassociate <Mac address (all in ff:ff:ff:ff:ff:ff)>: Disconnect target MAC or all devices.

> deauthenticate 66:55:44:33:22:11
wlan0: AP-STA-DISCONNECTED 66:55:44:33:22:11
<3>AP-STA-DISCONNECTED 66:55:44:33:22:11
OK
> wlan0: STA 66:55:44:33:22:11 IEEE 802.11: disassociated
> deauthenticate ff:ff:ff:ff:ff:ff
wlan0: AP-STA-DISCONNECTED 11:22:33:44:55:66
<3>AP-STA-DISCONNECTED 11:22:33:44:55:66
wlan0: AP-STA-DISCONNECTED 66:55:44:33:22:11
<3>AP-STA-DISCONNECTED 66:55:44:33:22:11
> disassociate ff:ff:ff:ff:ff:ff
wlan0: AP-STA-DISCONNECTED 11:22:33:44:55:66
<3>AP-STA-DISCONNECTED 11:22:33:44:55:66
wlan0: AP-STA-DISCONNECTED 66:55:44:33:22:11
<3>AP-STA-DISCONNECTED 66:55:44:33:22:11
wlan0: STA 11:22:33:44:55:66 IEEE 802.11: disassociated
OK
wlan0: STA 66:55:44:33:22:11 IEEE 802.11: disassociated

chan_switch <beacon count until channel switch is executed> <destination freq>: Execute channel switch.

>chan_switch 5 2417
wlan0: IEEE 802.11 CHAN_SWITCH HE config 0x2 VHT config 0x2
OK
> wlan0: IEEE 802.11 driver had channel switch: freq=2417, ht=1, vht_ch=0x2, he_ch=0x2, offset=0, width=1 (20 MHz), cf1=2417, cf2=0
wlan0: CTRL-EVENT-CHANNEL-SWITCH freq=2417 ht_enabled=1 ch_offset=0 ch_width=20 MHz cf1=2417 cf2=0 dfs=0
Device is trying to offload WPS Probe Response while not supporting this
<3>CTRL-EVENT-CHANNEL-SWITCH freq=2417 ht_enabled=1 ch_offset=0 ch_width=20 MHz cf1=2417 cf2=0 dfs=0
wlan0: AP-CSA-FINISHED freq=2417 dfs=0
<3>AP-CSA-FINISHED freq=2417 dfs=0

wps_pbc: Wait for WPS in PBC mode.

Running PBC on the Client device connects using WPS.

> wps_pbc
Device is trying to offload WPS Probe Response while not supporting this
wlan0: WPS-PBC-ACTIVE
<3>WPS-PBC-ACTIVE
OK
> <3>WPS-ENROLLEE-SEEN 66:55:44:33:22:11 a00c1d3d-c455-5e48-8cde-e4c00922335f 10-0050F204-5 0x4288 4 1 [bullhead]
wlan0: STA 66:55:44:33:22:11 IEEE 802.11: associated
wlan0: CTRL-EVENT-EAP-STARTED 66:55:44:33:22:11
wlan0: CTRL-EVENT-EAP-PROPOSED-METHOD vendor=0 method=1
<3>CTRL-EVENT-EAP-STARTED 66:55:44:33:22:11
<3>CTRL-EVENT-EAP-PROPOSED-METHOD vendor=0 method=1
wlan0: CTRL-EVENT-EAP-PROPOSED-METHOD vendor=14122 method=254
<3>CTRL-EVENT-EAP-PROPOSED-METHOD vendor=14122 method=254
[  496.526711] DEBUGFS PEER MAC = 0x66:0x55:0x44:0x33:0x22:0x11
wlan0: WPS-REG-SUCCESS 66:55:44:33:22:11 a00c1d3d-c455-5e48-8cde-e4c00922335f
Device is trying to offload WPS Probe Response while not supporting this
<3>WPS-REG-SUCCESS 66:55:44:33:22:11 a00c1d3d-c455-5e48-8cde-e4c00922335f
wlan0: WPS-PBC-DISABLE
wlan0: WPS-SUCCESS
<3>WPS-PBC-DISABLE
<3>WPS-SUCCESS
wlan0: CTRL-EVENT-EAP-FAILURE 66:55:44:33:22:11
<3>CTRL-EVENT-EAP-FAILURE 66:55:44:33:22:11
wlan0: STA 78:f8:82:a0:6e:97 IEEE 802.1X: authentication failed - EAP type: 0 (unknown)
wlan0: STA 78:f8:82:a0:6e:97 IEEE 802.1X: Supplicant used different EAP type: 254 (expanded)
wlan0: STA 78:f8:82:a0:6e:97 IEEE 802.11: disassociated
wlan0: STA 78:f8:82:a0:6e:97 IEEE[  496.815449] DEBUGFS PEER MAC = 0x66:0x55:0x44:0x33:0x22:0x11
 802.11: associated
[  496.817535] TXRX: Couldn't find peer from ID 13 - skipping security inits
wlan0: AP-STA-CONNECTED 66:55:44:33:22:11
wlan0: STA 66:55:44:33:22:11 RADIUS: starting accounting session CDEA32F20FD8605F
<3>AP-STA-CONNECTED 66:55:44:33:22:11
wlan0: STA 66:55:44:33:22:11 WPA: pairwise key handshake completed (RSN)
wlan0: EAPOL-4WAY-HS-COMPLETED 66:55:44:33:22:11
<3>EAPOL-4WAY-HS-COMPLETED 66:55:44:33:22:11

Summary

This time, I explained the basic usage of hostapd.

Next time, I will use wpa_supplicant to explain the basic usage of P2P.


Qualcomm's Wi-Fi products support Linux + wpa_supplicant/hostapd as a reference.

If you are interested in our products, please contact us using the form below.

Inquiry

If you have any questions about Qualcomm products, please contact us from the link below.

To Qualcomm manufacturer information Top

If you want to return to Qualcomm manufacturer information top page, please click below.