From aeac21423657cf79455f56c89b8bb2b76ff8286b Mon Sep 17 00:00:00 2001 From: John Crispin Date: Wed, 9 Aug 2023 11:21:54 +0200 Subject: [PATCH] hostapd: backport more hot-reload fixes Signed-off-by: John Crispin --- .../files/lib/netifd/wireless/mac80211.sh | 13 +++- feeds/wifi-ax/hostapd/files/wdev.uc | 2 +- .../files/lib/netifd/wireless/mac80211.sh | 2 +- ...rt-hostapd-ucode-wifi-reload-support.patch | 64 +++++++++---------- 4 files changed, 41 insertions(+), 40 deletions(-) diff --git a/feeds/wifi-ath10k/mac80211/files/lib/netifd/wireless/mac80211.sh b/feeds/wifi-ath10k/mac80211/files/lib/netifd/wireless/mac80211.sh index 89a9f6ae1..2dbc2432f 100644 --- a/feeds/wifi-ath10k/mac80211/files/lib/netifd/wireless/mac80211.sh +++ b/feeds/wifi-ath10k/mac80211/files/lib/netifd/wireless/mac80211.sh @@ -776,7 +776,7 @@ mac80211_prepare_iw_htmode() { mac80211_add_mesh_params() { for var in $MP_CONFIG_INT $MP_CONFIG_BOOL $MP_CONFIG_STRING; do - eval "mp_val=\"\$var\"" + eval "mp_val=\"\$$var\"" [ -n "$mp_val" ] && json_add_string "$var" "$mp_val" done } @@ -1102,14 +1102,18 @@ drv_mac80211_setup() { json_get_values scan_list scan_list json_select .. + json_select data && { + json_get_var prev_rxantenna rxantenna + json_get_var prev_txantenna txantenna + json_select .. + } + find_phy || { echo "Could not find PHY for device '$1'" wireless_set_retry 0 return 1 } - wireless_set_data phy="$phy" - local wdev local cwdev local found @@ -1144,6 +1148,9 @@ drv_mac80211_setup() { [ "$txantenna" = "all" ] && txantenna=0xffffffff [ "$rxantenna" = "all" ] && rxantenna=0xffffffff + [ "$rxantenna" = "$prev_rxantenna" -a "$txantenna" = "$prev_txantenna" ] || mac80211_reset_config "$phy" + wireless_set_data phy="$phy" txantenna="$txantenna" rxantenna="$rxantenna" + iw phy "$phy" set antenna $txantenna $rxantenna >/dev/null 2>&1 iw phy "$phy" set antenna_gain $antenna_gain >/dev/null 2>&1 iw phy "$phy" set distance "$distance" >/dev/null 2>&1 diff --git a/feeds/wifi-ax/hostapd/files/wdev.uc b/feeds/wifi-ax/hostapd/files/wdev.uc index 896f5261f..5b321423e 100644 --- a/feeds/wifi-ax/hostapd/files/wdev.uc +++ b/feeds/wifi-ax/hostapd/files/wdev.uc @@ -46,7 +46,7 @@ function iface_start(wdev) push(cmd, key, wdev[key]); system(cmd); } else if (wdev.mode == "mesh") { - let cmd = [ "iw", "dev", ifname, "mesh", "join", ssid, "freq", wdev.freq, wdev.htmode ]; + let cmd = [ "iw", "dev", ifname, "mesh", "join", wdev.ssid, "freq", wdev.freq, wdev.htmode ]; for (let key in [ "beacon-interval", "mcast-rate" ]) if (wdev[key]) push(cmd, key, wdev[key]); diff --git a/feeds/wifi-ax/mac80211/files/lib/netifd/wireless/mac80211.sh b/feeds/wifi-ax/mac80211/files/lib/netifd/wireless/mac80211.sh index 244d8e852..e98e79205 100644 --- a/feeds/wifi-ax/mac80211/files/lib/netifd/wireless/mac80211.sh +++ b/feeds/wifi-ax/mac80211/files/lib/netifd/wireless/mac80211.sh @@ -705,7 +705,7 @@ mac80211_prepare_iw_htmode() { mac80211_add_mesh_params() { for var in $MP_CONFIG_INT $MP_CONFIG_BOOL $MP_CONFIG_STRING; do - eval "mp_val=\"\$var\"" + eval "mp_val=\"\$$var\"" [ -n "$mp_val" ] && json_add_string "$var" "$mp_val" done } diff --git a/patches/wifi/0025-backport-hostapd-ucode-wifi-reload-support.patch b/patches/wifi/0025-backport-hostapd-ucode-wifi-reload-support.patch index f59f31b41..e1fec76db 100644 --- a/patches/wifi/0025-backport-hostapd-ucode-wifi-reload-support.patch +++ b/patches/wifi/0025-backport-hostapd-ucode-wifi-reload-support.patch @@ -1,4 +1,4 @@ -From 87450a717bf0e9e82566c89debb60e6ba7d4fe4a Mon Sep 17 00:00:00 2001 +From 629630e0f11126913dd39e927af3f7d643a0c0f3 Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Thu, 6 Jul 2023 08:33:25 +0000 Subject: [PATCH] backport hostapd ucode / wifi reload support @@ -14,7 +14,7 @@ Signed-off-by: Felix Fietkau .../hostapd/files/hostapd-basic.config | 2 +- .../hostapd/files/hostapd-full.config | 6 +- .../network/services/hostapd/files/hostapd.sh | 23 - - .../network/services/hostapd/files/hostapd.uc | 408 + + .../network/services/hostapd/files/hostapd.uc | 402 + .../services/hostapd/files/radius.clients | 1 + .../services/hostapd/files/radius.config | 9 + .../services/hostapd/files/radius.init | 42 + @@ -103,7 +103,7 @@ Signed-off-by: Felix Fietkau .../hostapd/src/wpa_supplicant/ubus.h | 11 - .../hostapd/src/wpa_supplicant/ucode.c | 177 + .../hostapd/src/wpa_supplicant/ucode.h | 38 + - 98 files changed, 15515 insertions(+), 2535 deletions(-) + 98 files changed, 15509 insertions(+), 2535 deletions(-) create mode 100644 package/network/services/hostapd/README.md create mode 100644 package/network/services/hostapd/files/common.uc create mode 100644 package/network/services/hostapd/files/hostapd.uc @@ -2460,10 +2460,10 @@ index 68dbd374ff..62703dc2f4 100644 } diff --git a/package/network/services/hostapd/files/hostapd.uc b/package/network/services/hostapd/files/hostapd.uc new file mode 100644 -index 0000000000..386ff72f7b +index 0000000000..b52732adcb --- /dev/null +++ b/package/network/services/hostapd/files/hostapd.uc -@@ -0,0 +1,408 @@ +@@ -0,0 +1,402 @@ +let libubus = require("ubus"); +import { open, readfile } from "fs"; +import { wdev_create, wdev_remove, is_equal, vlist_new, phy_is_fullmac } from "common"; @@ -2497,35 +2497,24 @@ index 0000000000..386ff72f7b + wdev_remove(bss.ifname); +} + -+function write_lines(f, data) ++function iface_gen_config(phy, config) +{ -+ for (let line in data) { -+ f.write(line); -+ f.write("\n"); -+ } -+} -+ -+function iface_write_config(phy, config) -+{ -+ config.file = `/var/run/ap-${phy}.conf`; -+ -+ let f = open(config.file, "w"); -+ if (!f) { -+ hostapd.printf(`Failed to open file ${config.file}`); -+ return; -+ } -+ -+ write_lines(f, config.radio.data); -+ f.write(`channel=${config.radio.channel}\n`); ++ let str = `data: ++${join("\n", config.radio.data)} ++channel=${config.radio.channel} ++`; + + for (let i = 0; i < length(config.bss); i++) { + let bss = config.bss[i]; + let type = i > 0 ? "bss" : "interface"; + -+ f.write(`${type}=${bss.ifname}\n`); -+ write_lines(f, bss.data); ++ str += ` ++${type}=${bss.ifname} ++${join("\n", bss.data)} ++`; + } -+ f.close(); ++ ++ return str; +} + +function iface_restart(phy, config, old_config) @@ -2542,7 +2531,8 @@ index 0000000000..386ff72f7b + let err = wdev_create(phy, bss.ifname, { mode: "ap" }); + if (err) + hostapd.printf(`Failed to create ${bss.ifname} on phy ${phy}: ${err}`); -+ if (hostapd.add_iface(`bss_config=${bss.ifname}:${config.file}`) < 0) { ++ let config_inline = iface_gen_config(phy, config); ++ if (hostapd.add_iface(`bss_config=${bss.ifname}:${config_inline}`) < 0) { + hostapd.printf(`hostapd.add_iface failed for phy ${phy} ifname=${bss.ifname}`); + return; + } @@ -2593,6 +2583,9 @@ index 0000000000..386ff72f7b + if (is_equal(old_config.bss, config.bss)) + return true; + ++ if (!old_config.bss || !old_config.bss[0]) ++ return false; ++ + if (config.bss[0].ifname != old_config.bss[0].ifname) + return false; + @@ -2600,13 +2593,15 @@ index 0000000000..386ff72f7b + if (!iface) + return false; + ++ let config_inline = iface_gen_config(phy, config); ++ + bss_reload_psk(iface.bss[0], config.bss[0], old_config.bss[0]); + if (!is_equal(config.bss[0], old_config.bss[0])) { + if (phy_is_fullmac(phy)) + return false; + + hostapd.printf(`Reload config for bss '${config.bss[0].ifname}' on phy '${phy}'`); -+ if (iface.bss[0].set_config(config.file, 0) < 0) { ++ if (iface.bss[0].set_config(config_inline, 0) < 0) { + hostapd.printf(`Failed to set config`); + return false; + } @@ -2626,6 +2621,7 @@ index 0000000000..386ff72f7b + if (!new_cfg[name]) { + hostapd.printf(`Remove bss '${name}' on phy '${phy}'`); + bss.delete(); ++ wdev_remove(name); + continue; + } + @@ -2642,7 +2638,7 @@ index 0000000000..386ff72f7b + return false; + } + -+ if (bss.set_config(config.file, idx) < 0) { ++ if (bss.set_config(config_inline, idx) < 0) { + hostapd.printf(`Failed to set config`); + return false; + } @@ -2657,7 +2653,7 @@ index 0000000000..386ff72f7b + return false; + } + -+ if (iface.add_bss(config.file, idx) < 0) { ++ if (iface.add_bss(config_inline, idx) < 0) { + hostapd.printf(`Failed to add bss`); + return false; + } @@ -2675,8 +2671,6 @@ index 0000000000..386ff72f7b + if (!config) + return iface_remove(old_config); + -+ iface_write_config(phy, config); -+ + let ret = iface_reload_config(phy, config, old_config); + if (ret) { + hostapd.printf(`Reloaded settings for phy ${phy}`); @@ -2964,7 +2958,7 @@ index 0000000000..03e2fc8fae +} diff --git a/package/network/services/hostapd/files/wdev.uc b/package/network/services/hostapd/files/wdev.uc new file mode 100644 -index 0000000000..896f5261fb +index 0000000000..5b321423eb --- /dev/null +++ b/package/network/services/hostapd/files/wdev.uc @@ -0,0 +1,156 @@ @@ -3016,7 +3010,7 @@ index 0000000000..896f5261fb + push(cmd, key, wdev[key]); + system(cmd); + } else if (wdev.mode == "mesh") { -+ let cmd = [ "iw", "dev", ifname, "mesh", "join", ssid, "freq", wdev.freq, wdev.htmode ]; ++ let cmd = [ "iw", "dev", ifname, "mesh", "join", wdev.ssid, "freq", wdev.freq, wdev.htmode ]; + for (let key in [ "beacon-interval", "mcast-rate" ]) + if (wdev[key]) + push(cmd, key, wdev[key]);