base-files: uci-defaults: allow setting wireless defaults
authorDaniel Golle <daniel@makrotopia.org>
Sat, 20 Nov 2021 01:43:20 +0000 (01:43 +0000)
committerJohn Crispin <john@phrozen.org>
Wed, 2 Oct 2024 13:41:33 +0000 (15:41 +0200)
Introduce new uci-default functions:
 - ucidef_set_wireless band ssid [encryption] [key]
 - ucidef_set_country cc

They are supposed to be used in /etc/board.d/* scripts to define
board-specific defaults for wireless.

Signed-off-by: Daniel Golle <daniel@makrotopia.org>
Signed-off-by: John Crispin <john@phrozen.org>
package/base-files/files/lib/functions/uci-defaults.sh

index b89cc8e9e309abbb187a4d93a0aa49e08e6c180b..ba7288c2c6bcc21a39d04405d4169bceb380ef0e 100644 (file)
@@ -642,6 +642,41 @@ ucidef_set_hostname() {
        json_select ..
 }
 
+ucidef_set_wireless() {
+       local band="$1"
+       local ssid="$2"
+       local encryption="$3"
+       local key="$4"
+
+       case "$band" in
+       all|2g|5g|6g) ;;
+       *) return;;
+       esac
+       [ -z "$ssid" ] && return
+
+       json_select_object wlan
+               json_select_object defaults
+                       json_select_object ssids
+                               json_select_object "$band"
+                                       json_add_string ssid "$ssid"
+                                       [ -n "$encryption" ] && json_add_string encryption "$encryption"
+                                       [ -n "$key" ] && json_add_string key "$key"
+                               json_select ..
+                       json_select ..
+               json_select ..
+       json_select ..
+}
+
+ucidef_set_country() {
+       local country="$1"
+
+       json_select_object wlan
+               json_select_object defaults
+                       json_add_string country "$country"
+               json_select ..
+       json_select ..
+}
+
 ucidef_set_ntpserver() {
        local server