From b1dbd89de8a3fbbf80757758c8a0c84542c46ead Mon Sep 17 00:00:00 2001 From: Jakob Olsson Date: Fri, 20 Aug 2021 15:26:15 +0200 Subject: [PATCH] map-controller: sync mapcontroller creds from wireless uci --- map-agent/files/lib/wifi/multiap | 91 ++++++++++++++++++- map-controller/files/etc/init.d/mapcontroller | 6 +- 2 files changed, 95 insertions(+), 2 deletions(-) diff --git a/map-agent/files/lib/wifi/multiap b/map-agent/files/lib/wifi/multiap index e79d775ed..774c1fa63 100755 --- a/map-agent/files/lib/wifi/multiap +++ b/map-agent/files/lib/wifi/multiap @@ -7,7 +7,7 @@ # write_credentials - write bBSS credentials to fBSS . /lib/functions.sh - +. /usr/share/libubox/jshn.sh diff=0 usage() { @@ -280,6 +280,94 @@ brcm_teardown_iface() { +sync_mapcontroller_from_wireless() { + ubus -t 5 wait_for wifi + [ "$?" != "0" ] && return + + [ ! -f "/etc/config/wireless" ] && return + + status=$(ubus -S call wifi status) + + device_to_band() { + local ifname=$1 + json_load "$status" + json_select "radios" + json_get_keys keys + + for key in $keys; do + json_select $key + json_get_var name name + + if [ "$name" != "$ifname" ]; then + json_select .. + continue + fi + + json_get_var band band + + if [ "$band" == "5GHz" ]; then + echo "5" + elif [ "$band" == "2.4GHz" ]; then + echo "2" + fi + + break + done + + json_cleanup + } + + wireless_process_iface() { + local section=$1 + local type="" + config_get multi_ap $section multi_ap 0 + + [ "$multi_ap" == "0" ] && return + + config_get mode $section mode "ap" + + [ "$mode" != "ap" ] && return + + if [ "$multi_ap" == "1" ]; then + type="bk-credentials" + else + type="fh-credentials" + fi + + config_get ssid $section ssid + config_get key $section key + config_get encryption $section encryption + config_get device $section device + + band=$(device_to_band $device) + + [ "$band" == "" ] && return + + cntlr_section=$(uci add mapcontroller ${type}) + uci set mapcontroller.${cntlr_section}.ssid="$ssid" + uci set mapcontroller.${cntlr_section}.key="$key" + uci set mapcontroller.${cntlr_section}.encryption="$encryption" + uci set mapcontroller.${cntlr_section}.band="$band" + uci set mapcontroller.${cntlr_section}.vlan="1" + uci set mapcontroller.${cntlr_section}.multi_ap="$multi_ap" + } + + mapcontroller_teardown() { + local section=$1 + + uci delete mapcontroller.$1 + } + + config_load mapcontroller + config_foreach mapcontroller_teardown bk-credentials + config_foreach mapcontroller_teardown fh-credentials + + config_load wireless + config_foreach wireless_process_iface wifi-iface + uci commit mapcontroller +} + + func=$1 shift @@ -292,6 +380,7 @@ case "$func" in bsta_steer) bsta_steer $@;; write_bsta_config) write_bsta_config $@;; teardown_iface) brcm_teardown_iface $@;; + sync_mapcontroller_from_wireless) sync_mapcontroller_from_wireless $@;; --help|help) usage;; *) usage; exit 1;; esac diff --git a/map-controller/files/etc/init.d/mapcontroller b/map-controller/files/etc/init.d/mapcontroller index b397b3656..69276515c 100755 --- a/map-controller/files/etc/init.d/mapcontroller +++ b/map-controller/files/etc/init.d/mapcontroller @@ -19,6 +19,8 @@ start_service() { config_get_bool enabled controller enabled 1 [ "$enabled" -eq 0 ] && return + /lib/wifi/multiap sync_mapcontroller_from_wireless + procd_open_instance procd_set_param command "/usr/sbin/mapcontroller" "-d" @@ -38,12 +40,14 @@ start_service() { service_triggers() { - procd_add_reload_trigger "mapcontroller" + procd_add_reload_trigger "mapcontroller" "wireless" } reload_service() { local enabled + /lib/wifi/multiap sync_mapcontroller_from_wireless + config_load "mapcontroller" config_get_bool enabled controller enabled 1 if [ "$enabled" -eq 0 ]; then