5 . /usr/share/libubox/jshn.sh
7 [ -s $CFG ] || /bin/board_detect || exit 1
8 [ -s /etc/config/network -a -s /etc/config/system ] && exit 0
10 generate_static_network() {
12 delete network.loopback
13 set network.loopback='interface'
14 set network.loopback.ifname='lo'
15 set network.loopback.proto='static'
16 set network.loopback.ipaddr='127.0.0.1'
17 set network.loopback.netmask='255.0.0.0'
18 delete network.globals
19 set network.globals='globals'
20 set network.globals.ula_prefix='auto'
23 if json_is_a dsl object; then
25 if json_is_a atmbridge object; then
27 local vpi vci encaps payload
28 json_get_vars vpi vci encaps payload
31 set network.atm='atm-bridge'
32 set network.atm.vpi='$vpi'
33 set network.atm.vci='$vci'
34 set network.atm.encaps='$encaps'
35 set network.atm.payload='$payload'
40 if json_is_a modem object; then
42 local type annex firmware tone xfer_mode
43 json_get_vars type annex firmware tone xfer_mode
47 set network.dsl.annex='$annex'
48 set network.dsl.firmware='$firmware'
49 set network.dsl.tone='$tone'
50 set network.dsl.xfer_mode='$xfer_mode'
60 local ifname macaddr protocol type ipaddr netmask
64 json_get_vars ifname macaddr protocol ipaddr netmask
68 [ -n "$ifname" ] || return
70 # force bridge for multi-interface devices (and lan)
72 *\ * | lan:*) type="bridge" ;;
77 set network.$1='interface'
78 set network.$1.type='$type'
79 set network.$1.ifname='$ifname'
80 set network.$1.proto='none'
83 [ -n "$macaddr" ] && uci -q batch <<-EOF
85 set network.$1_dev='device'
86 set network.$1_dev.name='$ifname'
87 set network.$1_dev.macaddr='$macaddr'
94 lan) ipad=${ipaddr:-"192.168.1.1"} ;;
95 *) ipad=${ipaddr:-"192.168.$((addr_offset++)).1"} ;;
98 netm=${netmask:-"255.255.255.0"}
101 set network.$1.proto='static'
102 set network.$1.ipaddr='$ipad'
103 set network.$1.netmask='$netm'
104 set network.$1.ip6assign='60'
109 # fixup IPv6 slave interface if parent is a bridge
110 [ "$type" = "bridge" ] && ifname="br-$1"
113 set network.$1.proto='dhcp'
115 set network.${1}6='interface'
116 set network.${1}6.ifname='$ifname'
117 set network.${1}6.proto='dhcpv6'
122 # fixup IPv6 slave interface
126 set network.$1.proto='pppoe'
127 set network.$1.username='username'
128 set network.$1.password='password'
129 set network.$1.ipv6='auto'
131 set network.${1}6='interface'
132 set network.${1}6.ifname='$ifname'
133 set network.${1}6.proto='dhcpv6'
139 generate_switch_vlans_ports() {
141 local port ports role roles num attr val
147 if json_is_a roles array; then
148 json_get_keys roles roles
151 for role in $roles; do
157 add network switch_vlan
158 set network.@switch_vlan[-1].device='$switch'
159 set network.@switch_vlan[-1].vlan='$role'
160 set network.@switch_vlan[-1].ports='$ports'
169 # write port specific settings
172 if json_is_a ports array; then
173 json_get_keys ports ports
176 for port in $ports; do
180 if json_is_a attr object; then
181 json_get_keys attr attr
184 add network switch_port
185 set network.@switch_port[-1].device='$switch'
186 set network.@switch_port[-1].port=$num
189 for attr in $attr; do
190 json_get_var val "$attr"
191 uci -q set network.@switch_port[-1].$attr="$val"
208 json_get_vars enable reset blinkrate cpu_port
212 set network.@switch[-1].name='$key'
213 set network.@switch[-1].reset='$reset'
214 set network.@switch[-1].enable_vlan='$enable'
215 set network.@switch[-1].blinkrate='$blinkrate'
218 generate_switch_vlans_ports "$1"
225 generate_static_system() {
227 delete system.@system[0]
229 set system.@system[-1].hostname='lede'
230 set system.@system[-1].timezone='UTC'
231 set system.@system[-1].ttylogin='0'
232 set system.@system[-1].log_size='64'
233 set system.@system[-1].urandom_seed='0'
236 set system.ntp='timeserver'
237 set system.ntp.enabled='1'
238 set system.ntp.enable_server='0'
239 add_list system.ntp.server='0.lede.pool.ntp.org'
240 add_list system.ntp.server='1.lede.pool.ntp.org'
241 add_list system.ntp.server='2.lede.pool.ntp.org'
242 add_list system.ntp.server='3.lede.pool.ntp.org'
245 if json_is_a system object; then
248 if json_get_var hostname hostname; then
249 uci -q set "system.@system[-1].hostname=$hostname"
252 if json_is_a ntpserver array; then
254 json_get_keys keys ntpserver
255 json_select ntpserver
256 uci -q delete "system.ntp.server"
260 if json_get_var server "$key"; then
261 uci -q add_list "system.ntp.server=$server"
272 local cfg="rssid_$key"
273 local refresh threshold
277 json_get_vars refresh threshold
283 set system.$cfg='rssid'
284 set system.$cfg.dev='$key'
285 set system.$cfg.refresh='$refresh'
286 set system.$cfg.threshold='$threshold'
296 json_get_vars name sysfs type trigger default
300 set system.$cfg='led'
301 set system.$cfg.name='$name'
302 set system.$cfg.sysfs='$sysfs'
303 set system.$cfg.trigger='$trigger'
304 set system.$cfg.default='$default'
310 json_get_vars gpio inverted
312 set system.$cfg.trigger='gpio'
313 set system.$cfg.gpio='$gpio'
314 set system.$cfg.inverted='$inverted'
320 json_get_vars device mode
322 set system.$cfg.trigger='netdev'
323 set system.$cfg.mode='$mode'
324 set system.$cfg.dev='$device'
332 set system.$cfg.trigger='usbdev'
333 set system.$cfg.interval='50'
334 set system.$cfg.dev='$device'
340 json_get_values ports ports
341 uci set system.$cfg.trigger='usbport'
342 for port in $ports; do
343 uci add_list system.$cfg.port=$port
348 local iface minq maxq offset factor
349 json_get_vars iface minq maxq offset factor
351 set system.$cfg.trigger='rssi'
352 set system.$cfg.iface='rssid_$iface'
353 set system.$cfg.minq='$minq'
354 set system.$cfg.maxq='$maxq'
355 set system.$cfg.offset='$offset'
356 set system.$cfg.factor='$factor'
361 local port_mask speed_mask
362 json_get_vars port_mask speed_mask
364 set system.$cfg.port_mask='$port_mask'
365 set system.$cfg.speed_mask='$speed_mask'
371 json_get_vars port_state
373 set system.$cfg.port_state='$port_state'
378 local delayon delayoff
379 json_get_vars delayon delayoff
381 set system.$cfg.trigger='$type'
382 set system.$cfg.delayon='$delayon'
383 set system.$cfg.delayoff='$delayoff'
392 generate_gpioswitch() {
395 json_select gpioswitch
397 local name pin default
398 json_get_vars name pin default
401 set system.$cfg='gpio_switch'
402 set system.$cfg.name='$name'
403 set system.$cfg.gpio_pin='$pin'
404 set system.$cfg.default='$default'
411 json_load "$(cat ${CFG})"
413 if [ ! -s /etc/config/network ]; then
414 touch /etc/config/network
415 generate_static_network
417 json_get_keys keys network
418 for key in $keys; do generate_network $key; done
420 json_get_keys keys switch
421 for key in $keys; do generate_switch $key; done
424 if [ ! -s /etc/config/system ]; then
425 touch /etc/config/system
426 generate_static_system
428 json_get_keys keys rssimon
429 for key in $keys; do generate_rssimon $key; done
431 json_get_keys keys gpioswitch
432 for key in $keys; do generate_gpioswitch $key; done
434 json_get_keys keys led
435 for key in $keys; do generate_led $key; done