5 .
/usr
/share
/libubox
/jshn.sh
9 generate_static_network
() {
11 delete network.loopback
12 set network.loopback='interface'
13 set network.loopback.ifname='lo'
14 set network.loopback.proto='static'
15 set network.loopback.ipaddr='127.0.0.1'
16 set network.loopback.netmask='255.0.0.0'
17 delete network.globals
18 set network.globals='globals'
19 set network.globals.ula_prefix='auto'
22 if json_is_a dsl object
; then
24 if json_is_a atmbridge object
; then
26 local vpi vci encaps payload
27 json_get_vars vpi vci encaps payload
30 set network.atm='atm-bridge'
31 set network.atm.vpi='$vpi'
32 set network.atm.vci='$vci'
33 set network.atm.encaps='$encaps'
34 set network.atm.payload='$payload'
39 if json_is_a modem object
; then
41 local type annex firmware tone xfer_mode
42 json_get_vars
type annex firmware tone xfer_mode
46 set network.dsl.annex='$annex'
47 set network.dsl.firmware='$firmware'
48 set network.dsl.tone='$tone'
49 set network.dsl.xfer_mode='$xfer_mode'
59 local ifname macaddr protocol
type ipaddr netmask
63 json_get_vars ifname macaddr protocol ipaddr netmask
67 [ -n "$ifname" ] ||
return
69 # force bridge for multi-interface devices (and lan)
71 *\
* | lan
:*) type="bridge" ;;
76 set network.$1='interface'
77 set network.$1.type='$type'
78 set network.$1.ifname='$ifname'
79 set network.$1.proto='none'
82 [ -n "$macaddr" ] && uci
-q batch <<-EOF
84 set network.$1_dev='device'
85 set network.$1_dev.name='$ifname'
86 set network.$1_dev.macaddr='$macaddr'
93 lan
) ipad
=${ipaddr:-"192.168.1.1"} ;;
94 *) ipad
=${ipaddr:-"192.168.$((addr_offset++)).1"} ;;
97 netm
=${netmask:-"255.255.255.0"}
100 set network.$1.proto='static'
101 set network.$1.ipaddr='$ipad'
102 set network.$1.netmask='$netm'
103 set network.$1.ip6assign='60'
108 # fixup IPv6 slave interface if parent is a bridge
109 [ "$type" = "bridge" ] && ifname
="br-$1"
112 set network.$1.proto='dhcp'
114 set network.${1}6='interface'
115 set network.${1}6.ifname='$ifname'
116 set network.${1}6.proto='dhcpv6'
121 # fixup IPv6 slave interface
125 set network.$1.proto='pppoe'
126 set network.$1.username='username'
127 set network.$1.password='password'
128 set network.$1.ipv6='auto'
130 set network.${1}6='interface'
131 set network.${1}6.ifname='$ifname'
132 set network.${1}6.proto='dhcpv6'
138 generate_switch_vlans_ports
() {
140 local port ports role roles num attr val
146 if json_is_a roles array
; then
147 json_get_keys roles roles
150 for role
in $roles; do
156 add network switch_vlan
157 set network.@switch_vlan[-1].device='$switch'
158 set network.@switch_vlan[-1].vlan='$role'
159 set network.@switch_vlan[-1].ports='$ports'
168 # write port specific settings
171 if json_is_a ports array
; then
172 json_get_keys ports ports
175 for port
in $ports; do
179 if json_is_a attr object
; then
180 json_get_keys attr attr
183 add network switch_port
184 set network.@switch_port[-1].device='$switch'
185 set network.@switch_port[-1].port=$num
188 for attr
in $attr; do
189 json_get_var val
"$attr"
190 uci
-q set network.@switch_port
[-1].
$attr="$val"
207 json_get_vars
enable reset blinkrate cpu_port
211 set network.@switch[-1].name='$key'
212 set network.@switch[-1].reset='$reset'
213 set network.@switch[-1].enable_vlan='$enable'
214 set network.@switch[-1].blinkrate='$blinkrate'
217 generate_switch_vlans_ports
"$1"
224 generate_static_system
() {
226 delete system.@system[0]
228 set system.@system[-1].hostname='lede'
229 set system.@system[-1].timezone='UTC'
230 set system.@system[-1].ttylogin='0'
233 set system.ntp='timeserver'
234 set system.ntp.enabled='1'
235 set system.ntp.enable_server='0'
236 add_list system.ntp.server='0.openwrt.pool.ntp.org'
237 add_list system.ntp.server='1.openwrt.pool.ntp.org'
238 add_list system.ntp.server='2.openwrt.pool.ntp.org'
239 add_list system.ntp.server='3.openwrt.pool.ntp.org'
242 if json_is_a system object
; then
245 if json_get_var hostname hostname
; then
246 uci
-q set "system.@system[-1].hostname=$hostname"
249 if json_is_a ntpserver array
; then
251 json_get_keys keys ntpserver
252 json_select ntpserver
253 uci
-q delete
"system.ntp.server"
257 if json_get_var server
"$key"; then
258 uci
-q add_list
"system.ntp.server=$server"
269 local cfg
="rssid_$key"
270 local refresh threshold
274 json_get_vars refresh threshold
280 set system.$cfg='rssid'
281 set system.$cfg.dev='$key'
282 set system.$cfg.refresh='$refresh'
283 set system.$cfg.threshold='$threshold'
293 json_get_vars name sysfs
type trigger default
297 set system.$cfg='led'
298 set system.$cfg.name='$name'
299 set system.$cfg.sysfs='$sysfs'
300 set system.$cfg.trigger='$trigger'
301 set system.$cfg.default='$default'
307 json_get_vars gpio inverted
309 set system.$cfg.trigger='gpio'
310 set system.$cfg.gpio='$gpio'
311 set system.$cfg.inverted='$inverted'
317 json_get_vars device mode
319 set system.$cfg.trigger='netdev'
320 set system.$cfg.mode='$mode'
321 set system.$cfg.dev='$device'
329 set system.$cfg.trigger='usbdev'
330 set system.$cfg.interval='50'
331 set system.$cfg.dev='$device'
336 local iface minq maxq offset
factor
337 json_get_vars iface minq maxq offset
factor
339 set system.$cfg.trigger='rssi'
340 set system.$cfg.iface='rssid_$iface'
341 set system.$cfg.minq='$minq'
342 set system.$cfg.maxq='$maxq'
343 set system.$cfg.offset='$offset'
344 set system.$cfg.factor='$factor'
349 local port_mask speed_mask
350 json_get_vars port_mask speed_mask
352 set system.$cfg.port_mask='$port_mask'
353 set system.$cfg.speed_mask='$speed_mask'
358 local delayon delayoff
359 json_get_vars delayon delayoff
361 set system.$cfg.trigger='$type'
362 set system.$cfg.delayon='$delayon'
363 set system.$cfg.delayoff='$delayoff'
372 generate_gpioswitch
() {
375 json_select gpioswitch
377 local name pin default
378 json_get_vars name pin default
381 set system.$cfg='gpio_switch'
382 set system.$cfg.name='$name'
383 set system.$cfg.gpio_pin='$pin'
384 set system.$cfg.default='$default'
391 json_load
"$(cat ${CFG})"
393 generate_static_network
395 json_get_keys keys network
396 for key
in $keys; do generate_network
$key; done
398 json_get_keys keys switch
399 for key
in $keys; do generate_switch
$key; done
402 generate_static_system
404 json_get_keys keys rssimon
405 for key
in $keys; do generate_rssimon
$key; done
407 json_get_keys keys gpioswitch
408 for key
in $keys; do generate_gpioswitch
$key; done
410 json_get_keys keys led
411 for key
in $keys; do generate_led
$key; done