fix(reliability): resolve STA netdev by phy membership (netifd ignores ifname); sae-mixed for PSK uplinks

This commit is contained in:
2026-08-22 20:37:11 -06:00
parent 132cf4d77a
commit 501fa455ce
2 changed files with 46 additions and 6 deletions
@@ -20,10 +20,39 @@ def current_role():
return 'idle'
def associated():
"""BSSID of the uplink AP when wlan1up is associated, else None."""
def _sta_netdev():
"""Actual netdev carrying the radio1 STA. OpenWrt ignores a requested
ifname for mac80211 STA ifaces (comes up as phy1-sta0), so resolve by
phy membership + managed type instead of by name."""
from server import device_run
rc, out, err = device_run(['iw', 'dev', IFACE, 'link'], timeout=10)
rc, out, err = device_run(['iw', 'dev'], timeout=10)
if rc != 0:
return None
current = None
managed = []
for line in (out or '').splitlines():
line = line.strip()
if line.startswith('Interface '):
current = line.split()[1]
elif line.startswith('type managed') and current:
if not current.startswith('wlan0'):
managed.append(current)
current = None
for name in managed:
rc2, o2, _ = device_run(
['readlink', '/sys/class/net/%s/phy80211' % name], timeout=10)
if rc2 == 0 and 'phy1' in (o2 or ''):
return name
return None
def associated():
"""BSSID of the uplink AP when the radio1 STA is associated, else None."""
from server import device_run
dev = _sta_netdev()
if not dev:
return None
rc, out, err = device_run(['iw', 'dev', dev, 'link'], timeout=10)
if rc != 0 or 'Connected' not in (out or ''):
return None
for line in (out or '').splitlines():
@@ -71,8 +100,10 @@ def set_role(role, ssid=None, psk=None):
['uci', 'set', 'wireless.wlan1up.mode=sta'],
['uci', 'set', 'wireless.wlan1up.network=cli'],
['uci', 'set', 'wireless.wlan1up.ssid=%s' % ssid],
# sae-mixed = WPA2-PSK/WPA3-SAE transition; associates with
# either security mode. 'none' for open networks.
['uci', 'set', 'wireless.wlan1up.encryption=%s'
% ('psk2' if psk else 'none')],
% ('sae-mixed' if psk else 'none')],
['uci', 'set', 'wireless.wlan1up.disabled=0'],
]
if psk: