Problems when trying to use WiFi AP and STA

I am trying to setup a NanoPi R5C as a travel router. I just installed the latest snapshot and am having trouble getting my WiFi STA and AP to behave nicely on 2.4 GHz. If I only want the R5C to be an AP, that works fine. If I only want it to be a STA, that works fine. If I want it to be a STA and an AP and the STA is available, that works fine. If I want it to be a STA and an AP and the STA is unavailable, the AP crashes.

I found this old bug (https://dev.archive.openwrt.org/ticket/12000.html) that seems to describe my problem and led me to the travelmate package (https://github.com/openwrt/packages/blob/master/net/travelmate/files/README.md), but that did not fix the problem for me.

The router has a 3rd party Realtek m.2 WiFi card that seems to be supported by OpenWRT and supports AP and STA modes

# lspci -nnks 0000:01:00.0
0000:01:00.0 Network controller [0280]: Realtek Semiconductor Co., Ltd. RTL8822CE 802.11ac PCIe Wireless Network Adapter [10ec:c822]
	Subsystem: AzureWave Device [1a3b:3751]
	Kernel driver in use: rtw_8822ce
# iw list
Wiphy phy0
        ...
	Supported interface modes:
		 * IBSS
		 * managed
		 * AP
		 * AP/VLAN
		 * monitor
		 * mesh point
        ...
	valid interface combinations:
		 * #{ managed } <= 1, #{ AP } <= 1,
		   total <= 2, #channels <= 1
       ...

My network configuration has a bunch of crap, but I do not think it is causing any issues

# cat network 

config interface 'loopback'
	option device 'lo'
	option proto 'static'
	option ipaddr '127.0.0.1'
	option netmask '255.0.0.0'

config globals 'globals'
	option ula_prefix 'fd9b:cbb3:5a0a::/48'

config device
	option name 'eth0'
	option macaddr '1e:a9:38:13:57:1f'

config device
	option name 'eth1'
	option macaddr '1e:a9:38:13:57:1e'

config device
	option type 'bridge'
	option name 'switch0'
	list ports 'eth0'
	list ports 'eth1'
	option bridge_empty '1'

config interface 'WWAN'
	option device 'phy0-sta0'
	option proto 'dhcp'

config interface 'WAN'
	option device 'switch0.8'
	option proto 'dhcp'

config interface 'Home'
	option proto 'static'
	option device 'switch0.16'
	option ipaddr '192.168.16.1'
	option netmask '255.255.255.0'

config interface 'IoT'
	option proto 'static'
	option device 'switch0.17'
	option ipaddr '192.168.17.1'
	option netmask '255.255.255.0'

config interface 'Guest'
	option proto 'static'
	option device 'switch0.18'
	option ipaddr '192.168.18.1'
	option netmask '255.255.255.0'

config interface 'Lab'
	option proto 'static'
	option device 'switch0.19'
	option ipaddr '192.168.19.1'
	option netmask '255.255.255.0'
	option disabled '1'

config interface 'Management'
	option proto 'static'
	option device 'switch0.24'
	option ipaddr '192.168.24.1'
	option netmask '255.255.255.0'

config bridge-vlan
	option device 'switch0'
	option vlan '8'
	list ports 'eth0:t'
	list ports 'eth1:u*'

config bridge-vlan
	option device 'switch0'
	option vlan '16'
	list ports 'eth0:u*'

config bridge-vlan
	option device 'switch0'
	option vlan '17'
	list ports 'eth0:t'

config bridge-vlan
	option device 'switch0'
	option vlan '18'
	list ports 'eth0:t'

config bridge-vlan
	option device 'switch0'
	option vlan '19'
	list ports 'eth0:t'

config bridge-vlan
	option device 'switch0'
	option vlan '24'
	list ports 'eth0:t'
# cat firewall 

config defaults
	option input 'DROP'
	option output 'DROP'
	option forward 'DROP'
	option synflood_protect '1'

config zone
	option name 'WAN'
	option masq '1'
	option mtu_fix '1'
	option input 'DROP'
	option output 'ACCEPT'
	option forward 'DROP'
	list network 'WAN'
	list network 'WWAN'

config zone
	option name 'Home'
	option input 'ACCEPT'
	option output 'ACCEPT'
	option forward 'DROP'
	list network 'Home'

config zone
	option name 'IoT'
	option input 'ACCEPT'
	option output 'ACCEPT'
	option forward 'DROP'
	list network 'IoT'

config zone
	option name 'Guest'
	option input 'ACCEPT'
	option output 'ACCEPT'
	option forward 'DROP'
	list network 'Guest'

config zone
	option name 'Lab'
	option input 'ACCEPT'
	option output 'ACCEPT'
	option forward 'DROP'
	list network 'Lab'

config zone
	option name 'Management'
	option input 'ACCEPT'
	option output 'ACCEPT'
	option forward 'DROP'
	list network 'Management'

config forwarding
	option src 'Home'
	option dest 'WAN'

config forwarding
	option src 'IoT'
	option dest 'WAN'

config forwarding
	option src 'Guest'
	option dest 'WAN'

config forwarding
	option src 'Lab'
	option dest 'WAN'

config forwarding
	option src 'Management'
	option dest 'WAN'

config rule
	option name 'Allow-DHCP-Renew'
	option src 'WAN'
	option proto 'udp'
	option dest_port '68'
	option target 'ACCEPT'
	option family 'ipv4'
# cat dhcp 

config dnsmasq
	option domainneeded '1'
	option boguspriv '1'
	option filterwin2k '0'
	option localise_queries '1'
	option rebind_protection '1'
	option rebind_localhost '1'
	option local '/lan/'
	option domain 'lan'
	option expandhosts '1'
	option nonegcache '0'
	option cachesize '1000'
	option authoritative '1'
	option readethers '1'
	option leasefile '/tmp/dhcp.leases'
	option resolvfile '/tmp/resolv.conf.d/resolv.conf.auto'
	option nonwildcard '1'
	option localservice '1'
	option ednspacket_max '1232'
	option filter_aaaa '0'
	option filter_a '0'

config dhcp 'WAN'
	option interface 'WAN'
	option ignore '1'

config dhcp 'Home'
	option interface 'Home'
	option start '128'
	option limit '127'
	option leasetime '12h'

config dhcp 'IoT'
	option interface 'IoT'
	option start '128'
	option limit '127'
	option leasetime '12h'

config dhcp 'Guest'
	option interface 'Guest'
	option start '128'
	option limit '127'
	option leasetime '12h'

config dhcp 'Lab'
	option interface 'Lab'
	option start '128'
	option limit '127'
	option leasetime '12h'

config dhcp 'Management'
	option interface 'Management'
	option start '128'
	option limit '127'
	option leasetime '12h'
# cat wireless 

config wifi-device 'radio0'
	option type 'mac80211'
	option path '3c0000000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0'
	option band '2g'
	option htmode 'HT20'
	option cell_density '0'
	option channel 'auto'

config wifi-iface 'wifinet0'
	option device 'radio0'
	option mode 'ap'
	option ssid 'TheKingOfTown'
	option encryption 'psk2'
	option key '********'
	option network 'Home'
	option disabled '0'

config wifi-iface 'trm_uplink2'
	option device 'radio0'
	option mode 'sta'
	option network 'WWAN'
	option ssid 'Trogdor'
	option encryption 'psk2+ccmp'
	option key '********'
	option disabled '1'
# cat travelmate 

config travelmate 'global'
	option trm_enabled '1'
	option trm_captive '1'
	option trm_proactive '1'
	option trm_netcheck '0'
	option trm_autoadd '0'
	option trm_mail '0'
	option trm_debug '1'
	option trm_iface 'WWAN'
	option trm_vpn '0'
	option trm_randomize '0'
	option trm_radio 'radio0'

config uplink
	option enabled '1'
	option device 'radio0'
	option ssid 'Trogdor'
	option con_start_expiry '0'
	option con_end_expiry '0'
	option con_start '2024.09.23-15:00:52'

Simultaneously?

1 Like

Set channel to anything, not auto. "background scan" from starting AP iis not that background usually, it will settle on sta channel anyway. Did i mention country code?

1 Like

It seems to. I can create the TheKingOfTown AP on the NanoPi router and connect to it from my laptop while the NanoPi router is connected to my phone hotspot Trogdor. If I turn my phone hotspot Trogdor off, TheKingOfTown AP disappears. If I disable Trogdor on the NanoPi ( option disabled '1') in /etc/config/wireless and reboot, the TheKingOfTown AP reappears and I can connect.

Whats in the logs?
on high function radio ike athXk or mt76 this does not happen.

Running travelmate seems to make things unstable (maybe that is the issue). Here are the logs when travelmate is disabled, Trogdor (my phone hotspot) is unavailable but is option disabled '1' in /etc/config/wireless, the channel is set to 1 (and not auto as you suggested) and things crash.

Mon Sep 23 16:34:05 2024 daemon.notice hostapd: Set new config for phy phy0:
Mon Sep 23 16:34:05 2024 daemon.notice hostapd: Remove interface 'phy0'
Mon Sep 23 16:34:05 2024 daemon.notice hostapd: phy0-ap0: interface state ENABLED->DISABLED
Mon Sep 23 16:34:05 2024 daemon.notice hostapd: phy0-ap0: AP-DISABLED
Mon Sep 23 16:34:05 2024 daemon.notice hostapd: phy0-ap0: CTRL-EVENT-TERMINATING
Mon Sep 23 16:34:05 2024 daemon.err hostapd: rmdir[ctrl_interface=/var/run/hostapd]: Permission denied
Mon Sep 23 16:34:05 2024 daemon.notice hostapd: nl80211: deinit ifname=phy0-ap0 disabled_11b_rates=0
Mon Sep 23 16:34:05 2024 kern.info kernel: [  540.741339] rtw_8822ce 0000:01:00.0 phy0-ap0: left allmulticast mode
Mon Sep 23 16:34:05 2024 kern.info kernel: [  540.741931] rtw_8822ce 0000:01:00.0 phy0-ap0: left promiscuous mode
Mon Sep 23 16:34:05 2024 kern.info kernel: [  540.742566] switch0: port 3(phy0-ap0) entered disabled state
Mon Sep 23 16:34:05 2024 daemon.notice netifd: WAN (3245): udhcpc: sending renew to server 192.168.19.2
Mon Sep 23 16:34:05 2024 daemon.notice netifd: WAN (3245): udhcpc: lease of 192.168.19.237 obtained from 192.168.19.2, lease time 43200
Mon Sep 23 16:34:05 2024 daemon.notice wpa_supplicant[1295]: Set new config for phy phy0
Mon Sep 23 16:34:05 2024 daemon.notice wpa_supplicant[1295]: Remove interface phy0-sta0
Mon Sep 23 16:34:05 2024 daemon.notice wpa_supplicant[1295]: phy0-sta0: CTRL-EVENT-DSCP-POLICY clear_all
Mon Sep 23 16:34:05 2024 daemon.notice wpa_supplicant[1295]: phy0-sta0: CTRL-EVENT-DSCP-POLICY clear_all
Mon Sep 23 16:34:05 2024 daemon.notice wpa_supplicant[1295]: nl80211: deinit ifname=phy0-sta0 disabled_11b_rates=0
Mon Sep 23 16:34:05 2024 daemon.err wpa_supplicant[1295]: rmdir[ctrl_interface=/var/run/wpa_supplicant]: Permission denied
Mon Sep 23 16:34:06 2024 daemon.notice netifd: Interface 'WWAN' is disabled
Mon Sep 23 16:34:06 2024 daemon.notice netifd: Wireless device 'radio0' is now down
Mon Sep 23 16:34:06 2024 daemon.notice netifd: radio0 (6082): WARNING: Variable 'data' does not exist or is not an array/object
Mon Sep 23 16:34:06 2024 daemon.notice hostapd: Set new config for phy phy0:
Mon Sep 23 16:34:06 2024 daemon.notice wpa_supplicant[1295]: Set new config for phy phy0
Mon Sep 23 16:34:06 2024 daemon.notice netifd: radio0 (6082): sh: out of range
Mon Sep 23 16:34:06 2024 daemon.notice wpa_supplicant[1295]: Set new config for phy phy0
Mon Sep 23 16:34:06 2024 daemon.notice hostapd: Set new config for phy phy0: /var/run/hostapd-phy0.conf
Mon Sep 23 16:34:06 2024 daemon.notice hostapd: Restart interface for phy phy0
Mon Sep 23 16:34:06 2024 daemon.notice wpa_supplicant[1295]: Set new config for phy phy0
Mon Sep 23 16:34:07 2024 daemon.notice netifd: Interface 'WWAN' is enabled
Mon Sep 23 16:34:07 2024 daemon.notice wpa_supplicant[1295]: phy0-sta0: CTRL-EVENT-DSCP-POLICY clear_all
Mon Sep 23 16:34:07 2024 daemon.notice netifd: Wireless device 'radio0' is now up
Mon Sep 23 16:34:07 2024 daemon.notice netifd: Interface 'WWAN' is disabled
Mon Sep 23 16:34:07 2024 daemon.notice netifd: Interface 'WWAN' is enabled
Mon Sep 23 16:34:07 2024 daemon.notice wpa_supplicant[1295]: phy0-sta0: CTRL-EVENT-DSCP-POLICY clear_all
Mon Sep 23 16:34:07 2024 daemon.notice wpa_supplicant[1295]: nl80211: deinit ifname=phy0-sta0 disabled_11b_rates=0
Mon Sep 23 16:34:07 2024 daemon.err wpa_supplicant[1295]: rmdir[ctrl_interface=/var/run/wpa_supplicant]: Permission denied
Mon Sep 23 16:34:07 2024 daemon.notice hostapd: Configuration file: data: driver=nl80211 logger_syslog=127 logger_syslog_level=2 logger_stdout=127 logger_stdout_level=2 hw_mode=g supported_rates=60 90 120 180 240 360 480 540 basic_rates=60 120 240 beacon_int=100 chanlist=1 noscan=1 #num_global_macaddr=1 ieee80211n=1 ht_coex=0 ht_capab=[LDPC][SHORT-GI-20][SHORT-GI-40][TX-STBC][RX-STBC1][MAX-AMSDU-7935][DSSS_CCK-40] channel=1  interface=phy0-ap0 bssid=ec:2e:98:48:f9:ad ctrl_interface=/var/run/hostapd ap_isolate=1 bss_load_update_period=60 chan_util_avg_period=600 disassoc_low_ack=1 skip_inactivity_poll=0 preamble=1 wmm_enabled=1 ignore_broadcast_ssid=0 uapsd_advertisement_enabled=1 utf8_ssid=1 multi_ap=0 wpa_passphrase=****** wpa_psk_file=/var/run/hostapd-phy0-ap0.psk auth_algs=1 wpa=2 wpa_pairwise=CCMP ssid=TheKingOfTown bridge=switch0 wds_bridge= snoop_iface=switch0.16 wpa_disable_eapol_key_retries=0 wpa_key_mgmt=WPA-PSK okc=0 disable_pmksa_caching=1 dynamic_vlan=0 vlan_naming=1 vlan_no_bridge=1 vlan_
Mon Sep 23 16:34:07 2024 daemon.notice netifd: Interface 'WWAN' is disabled
Mon Sep 23 16:34:07 2024 kern.info kernel: [  542.722108] switch0: port 3(phy0-ap0) entered blocking state
Mon Sep 23 16:34:07 2024 kern.info kernel: [  542.722622] switch0: port 3(phy0-ap0) entered disabled state
Mon Sep 23 16:34:07 2024 kern.info kernel: [  542.723149] rtw_8822ce 0000:01:00.0 phy0-ap0: entered allmulticast mode
Mon Sep 23 16:34:07 2024 kern.info kernel: [  542.723897] rtw_8822ce 0000:01:00.0 phy0-ap0: entered promiscuous mode
Mon Sep 23 16:34:07 2024 kern.info kernel: [  542.724575] switch0: port 3(phy0-ap0) entered blocking state
Mon Sep 23 16:34:07 2024 kern.info kernel: [  542.725094] switch0: port 3(phy0-ap0) entered forwarding state
Mon Sep 23 16:34:07 2024 daemon.notice netifd: WAN (3245): udhcpc: sending renew to server 192.168.19.2
Mon Sep 23 16:34:07 2024 daemon.notice netifd: WAN (3245): udhcpc: lease of 192.168.19.237 obtained from 192.168.19.2, lease time 43200
Mon Sep 23 16:34:07 2024 daemon.notice netifd: Network device 'phy0-ap0' link is up
Mon Sep 23 16:34:08 2024 daemon.notice hostapd: phy0-ap0: interface state UNINITIALIZED->ENABLED
Mon Sep 23 16:34:08 2024 daemon.notice hostapd: phy0-ap0: AP-ENABLED
Mon Sep 23 16:34:08 2024 daemon.notice netifd: Interface 'WWAN' is enabled
Mon Sep 23 16:34:09 2024 daemon.notice netifd: Network device 'phy0-ap0' link is down
Mon Sep 23 16:34:09 2024 kern.info kernel: [  544.274953] switch0: port 3(phy0-ap0) entered disabled state
Mon Sep 23 16:34:13 2024 daemon.notice hostapd: handle_probe_req: send failed

Isn't this the expected behavior? When both are active, AP and STA have to be on the same channel; so, until the STA part connects to the upstream AP, the local AP part has to be disabled.

1 Like

It might be the expected behavior if you are smarter than I, but it is not desirable behavior for a travel router.

Yes, this is a known and longstanding annoyance for single radio devices.

A travel routers with multiple radios can help here. At the very least, you can have the uplink set on one of the radios 2.4G XOR 5G, and your other radio will remain up and operational regardless of the availability of the upstream AP/SSID.

That said, you appear to have travelmate installed -- it was designed specifically for this situation. It can help you manage the list/priority of uplink SSIDs (and bonus, activate VPNs conditionally and a few other things) and it has a graceful failover as it determines that an upstream connection cannot be established. If there isn't an available connection after it goes through the list of SSIDs (based on your configuration), it will stop the STA mode and bring up the radio in AP only mode, thus allowing you to connect.

3 Likes

Thank you for this info. While not the behavior I want, knowing that it is not my configure or WiFi card that is causing problems is helpful. I turned off travelmate, because it seamed to be making things laggy, but will try it again.

Travelmate depends on making repeated scans to see if the AP has come back so that the STA can be re-enabled. Some cards / drivers are not good at scanning while active. You could test this manually while running only an AP request a scan.

1 Like

on a single radio device set this to 0, it mitigates the above mentioned scanning issue.

2 Likes

I wasn't trying to be smarter than anyone, just trying to explain that there is nothing wrong with your hardware or your configuration.

1 Like

This was helpful. It makes travelmate usable and not bring the entire system down. That said, I could not get my single radio setup to behave with travelmate. I gave up and just added a second USB WiFi card and called it a day.