WLAN Configuration

May I have your support on how to configure the WLAN interfaces from switching between AP- and managed- modes?

Default Setting

root@bpi-r3:/# iw dev
phy#1
        Interface wlan1
                ifindex 14
                wdev 0x100000001
                addr 82:0c:43:26:60:00
                type managed
                txpower 23.00 dBm
                multicast TXQ:
                        qsz-byt qsz-pkt flows   drops   marks   overlmt hashcol tx-bytes        tx-packets
                        0       0       0       0       0       0       0       0               0
phy#0
        Interface wlan0
                ifindex 13
                wdev 0x1
                addr 00:0c:43:26:60:00
                ssid r3_AP0
                type AP
                channel 1 (2412 MHz), width: 20 MHz (no HT), center1: 2412 MHz
                txpower 20.00 dBm
                multicast TXQ:
                        qsz-byt qsz-pkt flows   drops   marks   overlmt hashcol tx-bytes        tx-packets
                        0       0       0       0       0       0       0       0               0
root@bpi-r3:/#

2.4GHz

root@bpi-r3:/# cat /etc/hostapd/hostapd_wlan0.conf
#ctrl_interface=/var/run/hostapd
#ctrl_interface_group=0 # These 2 are just parameters so that the hostap daemon runs.

interface=wlan0
#interface=ap0
driver=nl80211

ssid=r3_AP0

hw_mode=g
#channel=2
#channel=4
channel=1
#macaddr_acl=0
auth_algs=1
#ignore_broadcast_ssid=0
wpa=2
wmm_enabled=1
wpa_passphrase=12345678
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP
root@bpi-r3:/#

5GHz

root@bpi-r3:/# cat /etc/hostapd/hostapd_wlan1.conf
ctrl_interface=/var/run/hostapd_2
#ctrl_interface_group=0 # These 2 are just parameters so that the hostap daemon runs.

interface=wlan1
#interface=ap0
driver=nl80211

ssid=r3_AP1

#2.4G
hw_mode=g
channel=1

#5G-Support
country_code=DE
ieee80211n=1
ieee80211d=1
hw_mode=a
#34-50 step 2
#channel=40
#channel=44

channel=36
ieee80211h=1
require_vht=1
ht_capab=[GF][HT40+][SHORT-GI-20][SHORT-GI-40][RX-STBC1][DSSS_CCK-40]
vht_oper_chwidth=1
vht_capab=[SHORT-GI-80][RX-STBC-1][RX-ANTENNA-PATTERN][TX-ANTENNA-PATTERN]

#42 would be the centered frequency center channel number for 36 primary
#channel only if this were a 80 MHz channel, so the combination here is
#invalid. You would either need to change this to use vht_oper_chwidth=1
#or set vht_oper_centr_freq_seg0_idx=0 if you want to use a 40 MHz
#channel.

vht_oper_centr_freq_seg0_idx=42


#channel=60
ieee80211ac=1
wmm_enabled=1

#security
wpa=2
wpa_passphrase=12345678
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP CCMP
#ignore_broadcast_ssid=0
auth_algs=1
#rsn_pairwise=CCMP

#macaddr_acl=0
#accept_mac_file=/etc/hostapd/acl_accept
#deny_mac_file=/etc/hostapd/acl_deny

#macaddr_acl=1
#accept_mac_file=/etc/hostapd/hostapd.allow
root@bpi-r3:/#

Thanks,
Bruce

I followed instructions from the link systemctl - hostapd on two interfaces (two configuration files) - Unix & Linux Stack Exchange.

Here is the real practice:

mv /etc/hostapd/hostapd_wlan0.conf /etc/hostapd/wlan0.conf
mv /etc/hostapd/hostapd_wlan1.conf /etc/hostapd/wlan1.conf

/etc/init.d/hostapd stop

systemctl enable --now hostapd@wlan0
systemctl enable --now hostapd@wlan1

# Check the changes
iw dev
ps auwx | grep hostapd

# Apply changes in runtime
systemctl restart hostapd@wlan0
systemctl restart hostapd@wlan1

If it works, edit the file /usr/lib/systemd/system/hostapd.service with 2 separated services for wlan0 and wlan1:

root@bpi-r3:/# cat /usr/lib/systemd/system/hostapd.service
[Unit]
Description=Access point and authentication server for Wi-Fi and Ethernet
Documentation=man:hostapd(8)
After=network.target
ConditionFileNotEmpty=/etc/hostapd/hostapd.conf

[Service]
Type=forking
PIDFile=/run/hostapd.wlan0.pid
Restart=on-failure
RestartSec=2
Environment=DAEMON_CONF=/etc/hostapd/wlan0.conf
EnvironmentFile=-/etc/default/hostapd
ExecStart=/usr/sbin/hostapd -B -P $PIDFile $DAEMON_OPTS ${DAEMON_CONF}

[Service]
Type=forking
PIDFile=/run/hostapd.wlan1.pid
Restart=on-failure
RestartSec=2
Environment=DAEMON_CONF=/etc/hostapd/wlan1.conf
EnvironmentFile=-/etc/default/hostapd
ExecStart=/usr/sbin/hostapd -B -P $PIDFile $DAEMON_OPTS ${DAEMON_CONF}

[Install]
WantedBy=multi-user.target
root@bpi-r3:/#

Reboot to see if it applies the config automatically:

root@bpi-r3:/# ps auwx | grep hostapd
root        2985  0.1  0.2  11480  5648 ?        Ss   15:28   0:00 /usr/sbin/hostapd -B -P /run/hostapd.wlan1.pid /etc/hostapd/wlan1.conf
root        3030  0.0  0.1  11364  3264 ?        Ss   15:28   0:00 /usr/sbin/hostapd -B -P /run/hostapd.wlan0.pid /etc/hostapd/wlan0.conf
root        3097  0.0  0.0   3688  1856 ttyS0    S+   15:29   0:00 grep --color=auto hostapd
root@bpi-r3:/#
root@bpi-r3:/#
root@bpi-r3:/# iw dev
phy#1
        Interface wlan1
                ifindex 14
                wdev 0x100000001
                addr 82:0c:43:26:60:00
                ssid bpi-r3_bruce_5G
                type AP
                channel 149 (5745 MHz), width: 80 MHz, center1: 5775 MHz
                txpower 13.00 dBm
                multicast TXQ:
                        qsz-byt qsz-pkt flows   drops   marks   overlmt hashcol tx-bytes        tx-packets
                        0       0       0       0       0       0       0       0               0
phy#0
        Interface wlan0
                ifindex 13
                wdev 0x1
                addr 00:0c:43:26:60:00
                ssid bpi-r3_bruce_2.4G
                type AP
                channel 9 (2452 MHz), width: 20 MHz (no HT), center1: 2452 MHz
                txpower 20.00 dBm
                multicast TXQ:
                        qsz-byt qsz-pkt flows   drops   marks   overlmt hashcol tx-bytes        tx-packets
                        0       0       0       0       0       0       0       0               0
root@bpi-r3:/#

Tbh, I do not understand the problem :slight_smile:

Is second hostapd not started on bootup (you enable it already) or does it run in any error…which? Or is this a tutorial how it can be done?

Hi,

At the beginning, I was asking ways to configure modes (ap/managed/monitor/etc…) for wlan0 and wlan1. The default hostapd just brings up wlan0 but wlan1. That appears wlan0 operates in AP mode while wlan1 is in managed mode, by default.

After that, I commented a way I used to configure both interfaces in AP modes, even the system reboot.

It would be nice if you could share ways to configure various modes such as managed and monitor.

This service is started with:

systemctl start hostapd

But you are using the @ in the service name, a systemd template unit. It is used like this:

systemctl start hostapd@xxx

It uses the file:

`/usr/lib/systemd/system/[email protected]`

Mind the @ in the filename.

Inside this file it is defined how to use xxx.

For hostapd xxx should be the filename of the .conf, without the extension.

Hope this will help you find the unexplained behavior of the services you are starting.

Also you can use:

systemctl status hostapd@xxx

To check if the service is started successfully.

Edit:

If using the template service file, you should stop and disable the non-template service.

1 Like

Thanks for your explanation.

Yes, I’m able to operate WLAN interfaces in AP mode since the system already has /etc/hostapd/wlan*.conf, and I’ve hardcoded the /usr/lib/systemd/system/hostapd.service as above comment.

Do you know the ways to switch modes, e.g. ap, managed, monitor and etc…?

This file is part of the hostapd package and your changes are lost when the hostapd package is updated

This is why they introduced the template service, so you can use that instead of editing the service file.

Alternatively, you can use a drop-in file for the hostapd.service, where you can put your changes.

As for your changes about managed, you either run hostapd or wpa_supplicant on your wlan interface. Using it as accesspoint or client. Or what exactly do you want to change here?

Yes, I have already prepared the 2 config files /etc/hostapd/wlan*.conf as they are worked with the template service “systemctl restart hostapd@wlan*” in runtime.

A way to maintain changes after reboot which I know is to edit the hostapd.service file as above, i.e. hardcoding 2 separated services for wlan0 and wlan1.

Instead, could you provide example(s) to show how a drop-in file (with its filename, path, content) works with the 2 config files /etc/hostapd/wlan*.conf?

My aim is to hold 2 config files for wlan0 and wlan1 → save changes (e.g. ap/managed/monitor mode) there → restart service / reboot system → the changes being applied automatically.

systemctl disable hostapd
systemctl enable hostapd@wlan0
systemctl enable hostapd@wlan1