set network.globals='globals'
set network.globals.ula_prefix='auto'
EOF
+
+ if json_is_a dsl object; then
+ json_select dsl
+ if json_is_a atmbridge object; then
+ json_select atmbridge
+ local vpi vci encaps payload
+ json_get_vars vpi vci encaps payload
+ uci -q batch <<-EOF
+ delete network.atm
+ set network.atm='atm-bridge'
+ set network.atm.vpi='$vpi'
+ set network.atm.vci='$vci'
+ set network.atm.encaps='$encaps'
+ set network.atm.payload='$payload'
+ EOF
+ json_select ..
+ fi
+
+ if json_is_a modem object; then
+ json_select modem
+ local type annex firmware tone xfer_mode
+ json_get_vars type annex firmware tone xfer_mode
+ uci -q batch <<-EOF
+ delete network.dsl
+ set network.dsl='$type'
+ set network.dsl.annex='$annex'
+ set network.dsl.firmware='$firmware'
+ set network.dsl.tone='$tone'
+ set network.dsl.xfer_mode='$xfer_mode'
+ EOF
+ json_select ..
+ fi
+ json_select ..
+ fi
}
+addr_offset=2
generate_network() {
- local ifname macaddr type
+ local ifname macaddr protocol type
json_select network
json_select "$1"
- json_get_vars ifname macaddr
+ json_get_vars ifname macaddr protocol
json_select ..
json_select ..
set network.$1.type='$type'
set network.$1.ifname='$ifname'
set network.$1.proto='none'
- set network.$1.macaddr='$macaddr'
EOF
- case "$1" in
- lan)
+ [ -n "$macaddr" ] && uci -q batch <<-EOF
+ delete network.$1_dev
+ set network.$1_dev='device'
+ set network.$1_dev.name='$ifname'
+ set network.$1_dev.macaddr='$macaddr'
+ EOF
+
+ case "$protocol" in
+ static)
+ local ipaddr
+ case "$1" in
+ lan) ipaddr="192.168.1.1" ;;
+ *) ipaddr="192.168.$((addr_offset++)).1" ;;
+ esac
+
uci -q batch <<-EOF
set network.$1.proto='static'
- set network.$1.ipaddr='192.168.1.1'
+ set network.$1.ipaddr='$ipaddr'
set network.$1.netmask='255.255.255.0'
set network.$1.ip6assign='60'
EOF
;;
- wan)
+
+ dhcp)
+ # fixup IPv6 slave interface if parent is a bridge
+ [ "$type" = "bridge" ] && ifname="br-$1"
+
uci -q batch <<-EOF
set network.$1.proto='dhcp'
- delete network.wan6
- set network.wan6='interface'
- set network.wan6.type='$type'
- set network.wan6.ifname='$ifname'
- set network.wan6.proto='dhcpv6'
+ delete network.${1}6
+ set network.${1}6='interface'
+ set network.${1}6.ifname='$ifname'
+ set network.${1}6.proto='dhcpv6'
+ EOF
+ ;;
+
+ pppoe)
+ # fixup IPv6 slave interface
+ ifname="pppoe-$1"
+
+ uci -q batch <<-EOF
+ set network.$1.proto='pppoe'
+ set network.$1.username='username'
+ set network.$1.password='password'
+ set network.$1.ipv6='auto'
+ delete network.${1}6
+ set network.${1}6='interface'
+ set network.${1}6.ifname='$ifname'
+ set network.${1}6.proto='dhcpv6'
EOF
;;
esac
json_select ..
}
+generate_gpioswitch() {
+ local cfg="$1"
+
+ json_select gpioswitch
+ json_select "$cfg"
+ local name pin default
+ json_get_vars name pin default
+ uci -q batch <<-EOF
+ delete system.$cfg
+ set system.$cfg='gpio_switch'
+ set system.$cfg.name='$name'
+ set system.$cfg.gpio_pin='$pin'
+ set system.$cfg.default='$default'
+ EOF
+ json_select ..
+ json_select ..
+}
+
json_init
json_load "$(cat ${CFG})"
json_get_keys keys rssimon
for key in $keys; do generate_rssimon $key; done
+json_get_keys keys gpioswitch
+for key in $keys; do generate_gpioswitch $key; done
+
json_get_keys keys led
for key in $keys; do generate_led $key; done