diff --git a/doc/ChangeLog.md b/doc/ChangeLog.md index 11f0229cfd..e95fe229ec 100644 --- a/doc/ChangeLog.md +++ b/doc/ChangeLog.md @@ -48,6 +48,9 @@ All notable changes to the project are documented in this file. - Changing the mode of a Wi-Fi interface, e.g., from station to mesh point, made the whole configuration change fail to apply, although the commit was reported as successful +- #1393: a radio can hold more than one Wi-Fi station interface as long + as only one of them is enabled. The others keep their settings, e.g., + for another network, and are switched to with the `enabled` flag - NanoPi R2S: the LAN port got a random MAC address on every boot - `show interface` was slow, in particular on devices with a modem - The octet counters of an interface stopped counting after a while, diff --git a/doc/wifi.md b/doc/wifi.md index 3780f83595..49f8ba5af5 100644 --- a/doc/wifi.md +++ b/doc/wifi.md @@ -583,9 +583,11 @@ You can verify the configuration with `show hardware radio0` to see radio settings, and `show interface` to see all active AP interfaces. > [!NOTE] -> A radio hosts any number of access points but only one station, and -> the station follows its access point's channel, see [Current -> Limitations](#current-limitations). +> A radio hosts any number of access points but only one enabled +> station. More stations can be configured on it as long as they are +> disabled, e.g., to keep the settings for other networks and switch +> with the `enabled` flag. The station follows its access point's +> channel, see [Current Limitations](#current-limitations). ## Fast Roaming Between Access Points diff --git a/src/confd/src/if-wifi.c b/src/confd/src/if-wifi.c index f93b93a5b6..8316b0f90b 100644 --- a/src/confd/src/if-wifi.c +++ b/src/confd/src/if-wifi.c @@ -186,6 +186,29 @@ int wifi_mode_changed(struct lyd_node *wifi) return 0; } +/* + * The mode's wpa_supplicant runs only while the interface is enabled, + * another station on the radio may be the enabled one. A running + * instance keeps stale driver state on a recreated netdev, so restart. + */ +static void wifi_gen_service(FILE *fp, const char *svc, const char *ifname, + struct lyd_node *cif, bool restart) +{ + if (!lydx_is_enabled(cif, "enabled")) { + fprintf(fp, "initctl -bfq disable %s@%s\n", svc, ifname); + fprintf(fp, "initctl -bnq stop %s:%s\n", svc, ifname); + fprintf(fp, "if pid=$(cat " WPA_SUPPLICANT_PID " 2>/dev/null); then\n" + "\ttimeout 5 sh -c \"while kill -0 $pid 2>/dev/null; do sleep 0.1; done\"\n" + "fi\n", ifname); + return; + } + + fprintf(fp, "initctl -bfq enable %s@%s\n", svc, ifname); + fprintf(fp, "initctl -bfq touch %s@%s\n", svc, ifname); + if (restart) + fprintf(fp, "initctl -bnq restart %s:%s\n", svc, ifname); +} + /* * A changed wpa_supplicant config only takes effect when the daemon * reloads it, so nudge the service whenever the wifi subtree changed. @@ -196,7 +219,7 @@ static int wifi_gen_reload(struct lyd_node *dif, struct lyd_node *cif, struct da const char *svc; FILE *fp; - if (!lydx_get_child(dif, "wifi")) + if (!lydx_get_child(dif, "wifi") && !lydx_get_child(dif, "enabled")) return SR_ERR_OK; switch (wifi_get_mode(cif)) { @@ -216,7 +239,7 @@ static int wifi_gen_reload(struct lyd_node *dif, struct lyd_node *cif, struct da if (!fp) return SR_ERR_INTERNAL; - fprintf(fp, "initctl -bfq touch %s@%s\n", svc, ifname); + wifi_gen_service(fp, svc, ifname, cif, false); fclose(fp); return SR_ERR_OK; @@ -712,9 +735,7 @@ int wifi_add_iface(struct lyd_node *cif, struct dagger *net) if (!station) break; /* No mode yet, the netdev is created but idle */ wifi_gen_station(cif); - fprintf(iw, "initctl -bfq enable station@%s\n", ifname); - fprintf(iw, "initctl -bfq touch station@%s\n", ifname); - fprintf(iw, "initctl -bnq restart station:%s\n", ifname); + wifi_gen_service(iw, "station", ifname, cif, true); break; } case wifi_wds: { @@ -732,9 +753,7 @@ int wifi_add_iface(struct lyd_node *cif, struct dagger *net) case wifi_mesh: fprintf(iw, "iw phy %s interface add %s type mesh%s\n", radio, ifname, addr); wifi_gen_mesh(cif); - fprintf(iw, "initctl -bfq enable mesh@%s\n", ifname); - fprintf(iw, "initctl -bfq touch mesh@%s\n", ifname); - fprintf(iw, "initctl -bnq restart mesh:%s\n", ifname); + wifi_gen_service(iw, "mesh", ifname, cif, true); break; default: ERROR("WiFi mode %d unknown", mode); diff --git a/src/confd/yang/confd/infix-if-wifi.yang b/src/confd/yang/confd/infix-if-wifi.yang index 7f7fc393fc..fdc977bb6f 100644 --- a/src/confd/yang/confd/infix-if-wifi.yang +++ b/src/confd/yang/confd/infix-if-wifi.yang @@ -49,6 +49,13 @@ submodule infix-if-wifi { - Security: WPA2/WPA3 with keystore integration - Operational state: Connection status, RSSI, client lists"; + revision 2026-11-02 { + description + "A radio may hold several station or mesh point interfaces as long + as only one of them is enabled."; + reference "internal"; + } + revision 2026-10-06 { description "Access point and mesh point require the box-wide Wi-Fi country code, @@ -163,8 +170,8 @@ submodule infix-if-wifi { must "derived-from-or-self(/iehw:hardware/iehw:component[iehw:name=current()]/iehw:class, 'ih:wifi')" { error-message "Referenced hardware component must be a Wi-Fi radio (class 'ih:wifi')"; } - must "count(/if:interfaces/if:interface[wifi/radio = current()][not(wifi/access-point)][not(wifi/wds-link)]) <= 1" { - error-message "Only one station interface is allowed per radio"; + must "count(/if:interfaces/if:interface[wifi/radio = current()][not(wifi/access-point)][not(wifi/wds-link)][if:enabled = 'true']) <= 1" { + error-message "Only one enabled station interface is allowed per radio"; } description diff --git a/src/confd/yang/confd/infix-if-wifi@2026-10-06.yang b/src/confd/yang/confd/infix-if-wifi@2026-11-02.yang similarity index 100% rename from src/confd/yang/confd/infix-if-wifi@2026-10-06.yang rename to src/confd/yang/confd/infix-if-wifi@2026-11-02.yang