base-files: uci-defaults: support requesting untagged switch port configuration
[openwrt/openwrt.git] / package / base-files / files / lib / functions / uci-defaults.sh
index 84b78b84ef747f08de61a6a260015fd0b0e6ac6d..3500d49baabd06bdd0dec568dea32c942118138a 100755 (executable)
@@ -1,7 +1,5 @@
 #!/bin/ash
 
-CFG=/etc/board.json
-
 . /lib/functions.sh
 . /usr/share/libubox/jshn.sh
 
@@ -89,8 +87,14 @@ ucidef_set_interfaces_lan_wan() {
        json_select ..
 }
 
+ucidef_set_interface_raw() {
+       json_select_object network
+       _ucidef_set_interface "$@"
+       json_select ..
+}
+
 _ucidef_add_switch_port() {
-       # inherited: $num $device $need_tag $role $index $prev_role
+       # inherited: $num $device $need_tag $want_untag $role $index $prev_role
        # inherited: $n_cpu $n_ports $n_vlan $cpu0 $cpu1 $cpu2 $cpu3 $cpu4 $cpu5
 
        n_ports=$((n_ports + 1))
@@ -98,10 +102,11 @@ _ucidef_add_switch_port() {
        json_select_array ports
                json_add_object
                        json_add_int num "$num"
-                       [ -n "$device"   ] && json_add_string  device   "$device"
-                       [ -n "$need_tag" ] && json_add_boolean need_tag "$need_tag"
-                       [ -n "$role"     ] && json_add_string  role     "$role"
-                       [ -n "$index"    ] && json_add_int     index    "$index"
+                       [ -n "$device"     ] && json_add_string  device     "$device"
+                       [ -n "$need_tag"   ] && json_add_boolean need_tag   "$need_tag"
+                       [ -n "$want_untag" ] && json_add_boolean want_untag "$want_untag"
+                       [ -n "$role"       ] && json_add_string  role       "$role"
+                       [ -n "$index"      ] && json_add_int     index      "$index"
                json_close_object
        json_select ..
 
@@ -136,7 +141,7 @@ _ucidef_add_switch_port() {
 
 _ucidef_finish_switch_roles() {
        # inherited: $name $n_cpu $n_vlan $cpu0 $cpu1 $cpu2 $cpu3 $cpu4 $cpu5
-       local index role roles num device need_tag port ports
+       local index role roles num device need_tag want_untag port ports
 
        json_select switch
                json_select "$name"
@@ -151,7 +156,7 @@ _ucidef_finish_switch_roles() {
                        json_select "$name"
                                json_select ports
                                        json_select "$port"
-                                               json_get_vars num device need_tag
+                                               json_get_vars num device need_tag want_untag
                                        json_select ..
                                json_select ..
 
@@ -203,10 +208,15 @@ ucidef_add_switch() {
                                                num="${port%%@*}"
                                                device="${port##*@}"
                                                need_tag=0
+                                               want_untag=0
                                                [ "${num%t}" != "$num" ] && {
                                                        num="${num%t}"
                                                        need_tag=1
                                                }
+                                               [ "${num%u}" != "$num" ] && {
+                                                       num="${num%u}"
+                                                       want_untag=1
+                                               }
                                        ;;
                                        [0-9]*:*:[0-9]*)
                                                num="${port%%:*}"
@@ -223,7 +233,7 @@ ucidef_add_switch() {
                                        _ucidef_add_switch_port
                                fi
 
-                               unset num device role index need_tag
+                               unset num device role index need_tag want_untag
                        done
                json_select ..
        json_select ..
@@ -335,15 +345,13 @@ ucidef_add_adsl_modem() {
 
 ucidef_add_vdsl_modem() {
        local annex="$1"
-       local firmware="$2"
-       local tone="$3"
-       local xfer_mode="$4"
+       local tone="$2"
+       local xfer_mode="$3"
 
        json_select_object dsl
                json_select_object modem
                        json_add_string type "vdsl"
                        json_add_string annex "$annex"
-                       json_add_string firmware "$firmware"
                        json_add_string tone "$tone"
                        json_add_string xfer_mode "$xfer_mode"
                json_select ..
@@ -355,6 +363,7 @@ ucidef_set_led_netdev() {
        local name="$2"
        local sysfs="$3"
        local dev="$4"
+       local mode="${5:-link tx rx}"
 
        json_select_object led
 
@@ -363,6 +372,7 @@ ucidef_set_led_netdev() {
        json_add_string type netdev
        json_add_string sysfs "$sysfs"
        json_add_string device "$dev"
+       json_add_string mode "$mode"
        json_select ..
 
        json_select ..
@@ -386,6 +396,30 @@ ucidef_set_led_usbdev() {
        json_select ..
 }
 
+ucidef_set_led_usbport() {
+       local obj="$1"
+       local name="$2"
+       local sysfs="$3"
+       shift
+       shift
+       shift
+
+       json_select_object led
+
+       json_select_object "$obj"
+       json_add_string name "$name"
+       json_add_string type usbport
+       json_add_string sysfs "$sysfs"
+       json_select_array ports
+               for port in "$@"; do
+                       json_add_string port "$port"
+               done
+       json_select ..
+       json_select ..
+
+       json_select ..
+}
+
 ucidef_set_led_wlan() {
        local cfg="led_$1"
        local name="$2"
@@ -410,6 +444,7 @@ ucidef_set_led_switch() {
        local sysfs="$3"
        local trigger="$4"
        local port_mask="$5"
+       local speed_mask="$6"
 
        json_select_object led
 
@@ -419,6 +454,26 @@ ucidef_set_led_switch() {
        json_add_string sysfs "$sysfs"
        json_add_string trigger "$trigger"
        json_add_string port_mask "$port_mask"
+       json_add_string speed_mask "$speed_mask"
+       json_select ..
+
+       json_select ..
+}
+
+ucidef_set_led_portstate() {
+       local cfg="led_$1"
+       local name="$2"
+       local sysfs="$3"
+       local port_state="$4"
+
+       json_select_object led
+
+       json_select_object "$1"
+       json_add_string name "$name"
+       json_add_string type portstate
+       json_add_string sysfs "$sysfs"
+       json_add_string trigger port_state
+       json_add_string port_state "$port_state"
        json_select ..
 
        json_select ..