Raspberry Pi Zero W: WiFi client mode not working

I am able to get an RPi Zero W working just fine in Access Point (AP) mode using the image at https://openwrt.org/toh/raspberry_pi_foundation/raspberry_pi without issues. However, I have been trying to get it to connect to my wireless network as a client, using Luci (the web interface) and uci (the command line), without any success.

Here is a minimal non-working example configuration:

root@OpenWrt:/# cat /etc/config/wireless 

config wifi-device 'radio0'
	option type 'mac80211'
	option path 'platform/soc/20300000.mmcnr/mmc_host/mmc1/mmc1:0001/mmc1:0001:1'
	option channel 'auto'
	option disabled '0'

config wifi-iface 'default_radio0'
	option device 'radio0'
	option network 'lan'
	option mode 'sta'
	option ssid 'XXXX'
	option encryption 'psk2'
	option key 'XXXXXXXX'
root@OpenWrt:/# cat /etc/config/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 'fddc:dc26:9e82::/48'

config device
	option name 'br-lan'
	option type 'bridge'
	list ports 'wlan0'

config interface 'lan'
	option device 'br-lan'
	option proto 'dhcp'

I'm connected to the RPi by serial console. When I do /etc/init.d/network restart, I get no kernel messages and I don't see any connection attempts in my home router (which is also running openwrt).

What am I doing wrong? How can I diagnose this further?

---- Here is what else I've tried: ----

Before all this, I installed raspbian and got it to connect to my home WiFi just fine. I have also tried the config above with option country 'GB' and option channel '3', but that seems to make no difference.

The openwrt install image comes with AP mode configured but disabled. When I enable the AP, it works find and I am able to connect to it and login with Luci. In the web interface, in the wireless settings, I am able to 'scan' for my WiFi and get Luci to set it up, which generates the interface default_radio0 like I have shown above. However, it then fails to connect to my WiFi. I see these kernel messages:

[ 1642.087635] ieee80211 phy0: brcmf_escan_timeout: timer expired
[ 1642.558109] br-lan: port 1(wlan0-1) entered disabled state
[ 1642.890438] br-lan: port 1(wlan0-1) entered blocking state
[ 1642.897341] br-lan: port 1(wlan0-1) entered forwarding state
[ 1643.608769] br-lan: port 1(wlan0-1) entered disabled state
[ 1644.282848] br-lan: port 1(wlan0-1) entered blocking state
[ 1644.289585] br-lan: port 1(wlan0-1) entered forwarding state
[ 1644.768828] br-lan: port 1(wlan0-1) entered disabled state
[ 1644.887450] br-lan: port 1(wlan0-1) entered blocking state
[ 1644.894181] br-lan: port 1(wlan0-1) entered forwarding state
[ 1654.887633] ieee80211 phy0: brcmf_escan_timeout: timer expired
[ 1655.361775] br-lan: port 1(wlan0-1) entered disabled state
[ 1655.686428] br-lan: port 1(wlan0-1) entered blocking state
[ 1655.693719] br-lan: port 1(wlan0-1) entered forwarding state
[ 1656.408787] br-lan: port 1(wlan0-1) entered disabled state
[ 1657.106593] br-lan: port 1(wlan0-1) entered blocking state
[ 1657.113308] br-lan: port 1(wlan0-1) entered forwarding state
[ 1657.612989] br-lan: port 1(wlan0-1) entered disabled state
[ 1658.456191] br-lan: port 1(wlan0-1) entered blocking state
[ 1658.463160] br-lan: port 1(wlan0-1) entered forwarding state
[ 1658.931869] br-lan: port 1(wlan0-1) entered disabled state
[ 1659.851091] br-lan: port 1(wlan0-1) entered blocking state
[ 1659.857719] br-lan: port 1(wlan0-1) entered forwarding state
[ 1660.329569] br-lan: port 1(wlan0-1) entered disabled state
[ 1661.232759] br-lan: port 1(wlan0-1) entered blocking state
[ 1661.239640] br-lan: port 1(wlan0-1) entered forwarding state
[ 1661.710538] br-lan: port 1(wlan0-1) entered disabled state
[ 1662.625207] br-lan: port 1(wlan0-1) entered blocking state
[ 1662.631844] br-lan: port 1(wlan0-1) entered forwarding state
[ 1663.101137] br-lan: port 1(wlan0-1) entered disabled state
[ 1663.255249] br-lan: port 1(wlan0-1) entered blocking state
[ 1663.261842] br-lan: port 1(wlan0-1) entered forwarding state

And on my home router I see:

Sat Dec 17 17:07:51 2022 daemon.notice hostapd: wlan0: AP-STA-DISCONNECTED b8:27:eb:4d:02:47
Sat Dec 17 17:07:51 2022 daemon.info hostapd: wlan0: STA b8:27:eb:4d:02:47 IEEE 802.11: disassociated
Sat Dec 17 17:07:52 2022 daemon.info hostapd: wlan0: STA b8:27:eb:4d:02:47 IEEE 802.11: authenticated
Sat Dec 17 17:07:52 2022 daemon.info hostapd: wlan0: STA b8:27:eb:4d:02:47 IEEE 802.11: associated (aid 7)
Sat Dec 17 17:07:52 2022 daemon.notice hostapd: wlan0: AP-STA-CONNECTED b8:27:eb:4d:02:47
Sat Dec 17 17:07:52 2022 daemon.info hostapd: wlan0: STA b8:27:eb:4d:02:47 WPA: pairwise key handshake completed (RSN)
Sat Dec 17 17:07:52 2022 daemon.notice hostapd: wlan0: EAPOL-4WAY-HS-COMPLETED b8:27:eb:4d:02:47
Sat Dec 17 17:07:53 2022 daemon.notice hostapd: wlan0: AP-STA-DISCONNECTED b8:27:eb:4d:02:47
Sat Dec 17 17:07:53 2022 daemon.info hostapd: wlan0: STA b8:27:eb:4d:02:47 IEEE 802.11: disassociated
Sat Dec 17 17:07:54 2022 daemon.info hostapd: wlan0: STA b8:27:eb:4d:02:47 IEEE 802.11: authenticated
Sat Dec 17 17:07:54 2022 daemon.info hostapd: wlan0: STA b8:27:eb:4d:02:47 IEEE 802.11: associated (aid 7)
Sat Dec 17 17:07:54 2022 daemon.notice hostapd: wlan0: AP-STA-CONNECTED b8:27:eb:4d:02:47
Sat Dec 17 17:07:54 2022 daemon.info hostapd: wlan0: STA b8:27:eb:4d:02:47 WPA: pairwise key handshake completed (RSN)
Sat Dec 17 17:07:54 2022 daemon.notice hostapd: wlan0: EAPOL-4WAY-HS-COMPLETED b8:27:eb:4d:02:47
Sat Dec 17 17:07:54 2022 daemon.notice hostapd: wlan0: AP-STA-DISCONNECTED b8:27:eb:4d:02:47

So this is what I get when I'm trying to get the wireless to work in AP+STA mode using Luci. Supposedly, that should work because iw list shows:

...
	valid interface combinations:
		 * #{ managed } <= 1, #{ P2P-device } <= 1, #{ P2P-client, P2P-GO } <= 1,
		   total <= 3, #channels <= 2
		 * #{ managed } <= 1, #{ AP } <= 1, #{ P2P-client } <= 1, #{ P2P-device } <= 1,
		   total <= 4, #channels <= 1
...

seems like same problem here:

Create a wan network and attach the wifi STA to it. In /etc/config/network, add this:

config interface 'wan'
    option proto 'dhcp'

Then use option network 'wan' in the wifi-iface settings. On the radio wifi-device, always set the country code. The band (2g or 5g) and htmode also need to be set. A STA will scan all channels looking for an AP, so channel selection is not important.

I tried this before, and I tried it again on your suggestion. I added an interface 'wwan' on DHCP and wireless interface 'wifinet1'. I have 'band' and 'htmode' options set too. Here is the configuration I end up with:

root@OpenWrt:/# cat /etc/config/wireless

config wifi-device 'radio0'
	option type 'mac80211'
	option path 'platform/soc/20300000.mmcnr/mmc_host/mmc1/mmc1:0001/mmc1:0001:1'
	option channel '1'
	option band '2g'
	option htmode 'HT20'
	option disabled '0'
	option cell_density '0'

config wifi-iface 'default_radio0'
	option device 'radio0'
	option network 'lan'
	option mode 'ap'
	option ssid 'OpenWrt'
	option encryption 'psk2'
	option key 'XXXXXXXX'

config wifi-iface 'wifinet1'
	option device 'radio0'
	option mode 'sta'
	option network 'wwan'
	option ssid 'XXXX'
	option encryption 'psk2'
	option key 'XXXXXXXX'

root@OpenWrt:/# cat /etc/config/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 'fd7e:9abd:9970::/48'

config device
	option name 'br-lan'
	option type 'bridge'
	list ports 'wlan0'

config interface 'lan'
	option device 'br-lan'
	option proto 'static'
	option ipaddr '192.168.1.1'
	option netmask '255.255.255.0'
	option ip6assign '60'

config interface 'wwan'
	option proto 'dhcp'

This seems to encourage the RPi to attempt to connect to my home WiFi as client, but it remains unsuccessful. Here are the messages I get on the serial console:

[  657.142501] br-lan: port 1(wlan0-1) entered blocking state
[  657.149687] br-lan: port 1(wlan0-1) entered disabled state
[  657.156954] device wlan0-1 entered promiscuous mode
[  660.519635] IPv6: ADDRCONF(NETDEV_CHANGE): wlan0: link becomes ready
[  660.809166] IPv6: ADDRCONF(NETDEV_CHANGE): wlan0-1: link becomes ready
[  660.818288] br-lan: port 1(wlan0-1) entered blocking state
[  660.825834] br-lan: port 1(wlan0-1) entered forwarding state
[  661.299112] IPv6: ADDRCONF(NETDEV_CHANGE): br-lan: link becomes ready
[  661.518621] br-lan: port 1(wlan0-1) entered disabled state
[  662.098171] br-lan: port 1(wlan0-1) entered blocking state
[  662.105662] br-lan: port 1(wlan0-1) entered forwarding state
*** LAST 3 LINES REPEAT FEW TIMES ***
[  679.527632] ieee80211 phy0: brcmf_escan_timeout: timer expired
[  680.001705] br-lan: port 1(wlan0-1) entered disabled state
[  680.324092] br-lan: port 1(wlan0-1) entered blocking state
[  680.330814] br-lan: port 1(wlan0-1) entered forwarding state
*** LAST 3 LINES REPEAT ***

And the messages from my home router are just like the ones posted earlier:

Sat Dec 17 21:28:04 2022 daemon.info hostapd: wlan0: STA b8:27:eb:4d:02:47 IEEE 802.11: authenticated
Sat Dec 17 21:28:04 2022 daemon.info hostapd: wlan0: STA b8:27:eb:4d:02:47 IEEE 802.11: associated (aid 7)
Sat Dec 17 21:28:04 2022 daemon.notice hostapd: wlan0: AP-STA-CONNECTED b8:27:eb:4d:02:47
Sat Dec 17 21:28:04 2022 daemon.info hostapd: wlan0: STA b8:27:eb:4d:02:47 WPA: pairwise key handshake completed (RSN)
Sat Dec 17 21:28:04 2022 daemon.notice hostapd: wlan0: EAPOL-4WAY-HS-COMPLETED b8:27:eb:4d:02:47
Sat Dec 17 21:28:04 2022 daemon.notice hostapd: wlan0: AP-STA-DISCONNECTED b8:27:eb:4d:02:47
Sat Dec 17 21:28:04 2022 daemon.info hostapd: wlan0: STA b8:27:eb:4d:02:47 IEEE 802.11: disassociated
Sat Dec 17 21:28:05 2022 daemon.info hostapd: wlan0: STA b8:27:eb:4d:02:47 IEEE 802.11: deauthenticated due to inactivity (timer DEAUTH/REMOVE)
*** LINES ABOVE REPEAT *** 

Ok, I've managed to make some progress. If I remove the AP and only have the wwan STA as in the early config I posted, it connects to my home router as a client. Now I need to figure out how to connect the 'lan' interface to my home network. wwan is connected to the 'wan' firewall zone.

Thanks to @mk24 for pointing me in the right direction.

So it seems the Pi Zero W has two issues:

  1. It doesn't like being in AP+STA mode, so need to remove the AP before enabling the STA
  2. If the wifi is in STA mode, it doesn't like it when the connected network interface (in /etc/config/network) is connected to a bridge device. I had to remove the 'br-lan' device from the 'lan' interface.

That is a known hardware (firmware) restriction with brcmfmac, nothing that could be changed.

The IEEE 802.11 standards don't allow STA interfaces to be part of a bridge, the packet headers only reserve space for 3 MAC addresses (bridging would hard-require a fourth to be in there). Workarounds in the sense of WDS/ 4addr exist, but they are non-standard and only available for nl80211 based drivers on both sides of the connection (the way they work, is by setting up a tandem on AP/ STA operations on the same radio - which isn't possible with brcmfmac hardware).

I've also found that a Pi client will not connect if the AP has 802.11w enabled at all, even if it is set to "optional." I don't know if that's still the case.

(802.11w known as "Management Frame Protection" is a useful security feature that applies a crypto signature to the basic control packets used to connect and disconnect from an AP. Without MFP, an attacker within WiFi range can make a denial of service attack by transmitting fake disassociate packets.)

RPi Zero W doesnt support working as client and access point at the same time

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.