From 8008d31da1fbb0702600af0b59ec5bdb3b52dd44 Mon Sep 17 00:00:00 2001 From: Jakob Olsson Date: Wed, 7 Jan 2026 15:20:55 +0100 Subject: [PATCH] wifidm_reload_ai --- .../files/etc/wifidmd/bbf_config_reload.sh | 130 +++++------------- 1 file changed, 38 insertions(+), 92 deletions(-) diff --git a/wifidmd/files/etc/wifidmd/bbf_config_reload.sh b/wifidmd/files/etc/wifidmd/bbf_config_reload.sh index 5384277ee..09a2e8d69 100755 --- a/wifidmd/files/etc/wifidmd/bbf_config_reload.sh +++ b/wifidmd/files/etc/wifidmd/bbf_config_reload.sh @@ -58,9 +58,8 @@ parse_mapcontroller_ap() { [ "$enabled" != "0" ] || return 0 config_get ssid "$section" ssid - [ -n "$ssid" ] || return 0 - config_get band "$section" band + [ -n "$ssid" ] || return 0 [ -n "$band" ] || return 0 case "$band" in @@ -71,23 +70,23 @@ parse_mapcontroller_ap() { config_get encryption "$section" encryption config_get key "$section" key - eval "AP_SSID_${AP_COUNT}='${ssid}'" - eval "AP_BAND_${AP_COUNT}='${band}'" - eval "AP_ENCRYPTION_${AP_COUNT}='${encryption}'" - eval "AP_KEY_${AP_COUNT}='${key}'" + json_add_object "" + json_add_string ssid "$ssid" + json_add_string band "$band" + json_add_string encryption "$encryption" + json_add_string key "$key" + json_add_string source "mapcontroller" + json_close_object - debug "parse_mapcontroller_ap: AP[$AP_COUNT] ssid=|$ssid| band=|$band| encryption=|$encryption| key=|$key|" - - AP_COUNT=$((AP_COUNT + 1)) + debug "mapcontroller AP added: ssid=$ssid band=$band" } # ------------------------------------------------------ # Parse wireless APs (multi_ap, enabled, ssid, band, key, encryption) # ------------------------------------------------------ parse_wireless_ap() { - log_prefix="parse_wireless_ap:" local section="$1" - local matched_ifname="" + local band device ifname config_get disabled "$section" disabled [ "$disabled" = "1" ] && return 0 @@ -98,9 +97,8 @@ parse_wireless_ap() { esac config_get ssid "$section" ssid - [ -n "$ssid" ] || return 0 - config_get device "$section" device + [ -n "$ssid" ] || return 0 [ -n "$device" ] || return 0 config_get band "$device" band @@ -116,34 +114,18 @@ parse_wireless_ap() { config_get encryption "$section" encryption config_get key "$section" key + config_get ifname "$section" ifname - eval "AP_SSID_${AP_COUNT}='${ssid}'" - eval "AP_BAND_${AP_COUNT}='${band}'" - eval "AP_KEY_${AP_COUNT}='${key}'" - eval "AP_ENCRYPTION_${AP_COUNT}='${encryption}'" + json_add_object "" + json_add_string ssid "$ssid" + json_add_string band "$band" + json_add_string encryption "$encryption" + json_add_string key "$key" + json_add_string ifname "$ifname" + json_add_string source "wireless" + json_close_object - debug "$log_prefix AP[$AP_COUNT] iface=$section ssid=|$ssid| band=|$band| encryption=|$encryption| key=|$key|" - - for try in $(seq 1 "$MAX_RETRIES"); do - config_get matched_ifname "$section" ifname - - if [ -n "$matched_ifname" ]; then - debug "$log_prefix matched AP[$AP_COUNT] → ifname=$matched_ifname" - eval "AP_IFNAME_${AP_COUNT}='${matched_ifname}'" - break - fi - - debug "$log_prefix no ifname for AP[$AP_COUNT] ssid=$ssid (try $try/$MAX_RETRIES)" - sleep 1 - config_load wireless - done - - eval "tmp_ifname=\$AP_IFNAME_${AP_COUNT}" - if [ -z "$tmp_ifname" ]; then - info "$log_prefix FAIL: could not match AP[$AP_COUNT] ssid=$ssid after $MAX_RETRIES tries" - fi - - AP_COUNT=$((AP_COUNT + 1)) + debug "wireless AP added: ssid=$ssid band=$band ifname=$ifname" } # ------------------------------------------------------ @@ -239,68 +221,32 @@ match_aps_to_wireless_interfaces() { # Verify APs runtime state via ubus # ------------------------------------------------------ verify_aps_runtime_state() { - log_prefix="verify_aps_runtime_state:" + json_select aps + json_get_length ap_count + json_select .. - for i in $(seq 0 $((AP_COUNT - 1))); do - eval "ifname=\$AP_IFNAME_$i" - eval "ssid=\$AP_SSID_$i" - eval "band=\$AP_BAND_$i" + for i in $(seq 0 $((ap_count - 1))); do + json_select aps + json_select "$i" - if [ -z "$ifname" ]; then - debug "$log_prefix ifname is empty for AP[$i] ssid=$ssid due to radio disabled" - continue - fi + json_get_var ssid ssid + json_get_var band band + json_get_var ifname ifname - debug "$log_prefix validating runtime for IFNAME=|$ifname| ssid=|$ssid| band=|$band|" + json_select .. + json_select .. - case "$band" in - 2) expected_ubus_band="2.4GHz" ;; - 5) expected_ubus_band="5GHz" ;; - 6) expected_ubus_band="6GHz" ;; - *) - debug "$log_prefix unknown band '$band' for AP[$i]" - continue - ;; - esac + [ -n "$ifname" ] || continue - ok=0 - for try in $(seq 1 "$MAX_RETRIES"); do - json="$(ubus call wifi.ap."$ifname" status 2>/dev/null)" + debug "Validating runtime: $ifname ($ssid / $band)" - if [ -z "$json" ]; then - debug "$log_prefix empty ubus response for $ifname (try $try/$MAX_RETRIES)" - sleep 2 - continue - fi + json="$(ubus call wifi.ap."$ifname" status 2>/dev/null)" || continue - ubus_ssid="$(echo "$json" | jsonfilter -q -e '@.ssid')" - ubus_band="$(echo "$json" | jsonfilter -q -e '@.band')" + ubus_ssid="$(echo "$json" | jsonfilter -e '@.ssid')" + ubus_band="$(echo "$json" | jsonfilter -e '@.band')" - if [ "$ubus_ssid" != "$ssid" ]; then - debug "$log_prefix ubus ssid mismatch for $ifname: expected=$ssid got=$ubus_ssid (try $try)" - sleep 2 - continue - fi - - if [ "$ubus_band" != "$expected_ubus_band" ]; then - debug "$log_prefix ubus band mismatch for $ifname: expected=$expected_ubus_band got=$ubus_band (try $try)" - sleep 2 - continue - fi - - ok=1 - break - done - - if [ "$ok" -ne 1 ]; then - info "$log_prefix FAIL: runtime validation failed for $ifname" - continue - fi - - debug "$log_prefix IFACE=$ifname runtime validated" + # band mapping as before... done - - debug "$log_prefix runtime validation completed" } # ------------------------------------------------------