base-files: fix wrong ucidef_set_network_device_mac network-device entry
[openwrt/openwrt.git] / package / base-files / files / lib / functions / uci-defaults.sh
index 134c527d8d5576a5626c7d747e12c26ee1dd0ff8..6f395ec24b2a4ec6236d256e05e6a56faa81c91c 100644 (file)
@@ -39,7 +39,13 @@ ucidef_set_interface() {
 
                [ -n "$opt" -a -n "$val" ] || break
 
-               json_add_string "$opt" "$val"
+               [ "$opt" = "device" -a "$val" != "${val/ //}" ] && {
+                       json_select_array "ports"
+                       for e in $val; do json_add_string "" "$e"; done
+                       json_close_array
+               } || {
+                       json_add_string "$opt" "$val"
+               }
        done
 
        if ! json_is_a protocol string; then
@@ -73,11 +79,11 @@ ucidef_set_compat_version() {
 }
 
 ucidef_set_interface_lan() {
-       ucidef_set_interface "lan" ifname "$1" protocol "${2:-static}"
+       ucidef_set_interface "lan" device "$1" protocol "${2:-static}"
 }
 
 ucidef_set_interface_wan() {
-       ucidef_set_interface "wan" ifname "$1" protocol "${2:-dhcp}"
+       ucidef_set_interface "wan" device "$1" protocol "${2:-dhcp}"
 }
 
 ucidef_set_interfaces_lan_wan() {
@@ -90,7 +96,7 @@ ucidef_set_interfaces_lan_wan() {
 
 ucidef_set_bridge_device() {
        json_select_object bridge
-       json_add_string name "${1:switch0}"
+       json_add_string name "${1:-switch0}"
        json_select ..
 }
 
@@ -101,13 +107,21 @@ ucidef_set_bridge_mac() {
 }
 
 ucidef_set_network_device_mac() {
-       json_select_object "network-device"
+       json_select_object "network_device"
        json_select_object "${1}"
        json_add_string macaddr "${2}"
        json_select ..
        json_select ..
 }
 
+ucidef_set_network_device_path() {
+       json_select_object "network_device"
+       json_select_object "$1"
+       json_add_string path "$2"
+       json_select ..
+       json_select ..
+}
+
 _ucidef_add_switch_port() {
        # inherited: $num $device $need_tag $want_untag $role $index $prev_role
        # inherited: $n_cpu $n_ports $n_vlan $cpu0 $cpu1 $cpu2 $cpu3 $cpu4 $cpu5
@@ -195,14 +209,14 @@ _ucidef_finish_switch_roles() {
 
                        json_select_object "$role"
                                # attach previous interfaces (for multi-switch devices)
-                               json_get_var devices ifname
+                               json_get_var devices device
                                if ! list_contains devices "$device"; then
                                        devices="${devices:+$devices }$device"
                                fi
                        json_select ..
                json_select ..
 
-               ucidef_set_interface "$role" ifname "$devices"
+               ucidef_set_interface "$role" device "$devices"
        done
 }
 
@@ -412,6 +426,15 @@ ucidef_set_led_default() {
        json_select ..
 }
 
+ucidef_set_led_heartbeat() {
+       _ucidef_set_led_common "$1" "$2" "$3"
+
+       json_add_string trigger heartbeat
+       json_select ..
+
+       json_select ..
+}
+
 ucidef_set_led_gpio() {
        local gpio="$4"
        local inverted="$5"
@@ -623,6 +646,21 @@ ucidef_set_ntpserver() {
        json_select ..
 }
 
+ucidef_add_wlan() {
+       local path="$1"; shift
+
+       ucidef_wlan_idx=${ucidef_wlan_idx:-0}
+
+       json_select_object wlan
+       json_select_object "wl$ucidef_wlan_idx"
+       json_add_string path "$path"
+       json_add_fields "$@"
+       json_select ..
+       json_select ..
+
+       ucidef_wlan_idx="$((ucidef_wlan_idx + 1))"
+}
+
 board_config_update() {
        json_init
        [ -f ${CFG} ] && json_load "$(cat ${CFG})"