6 .
/usr
/share
/libubox
/jshn.sh
9 local _json_no_warning
=1
20 json_select_object
() {
21 local _json_no_warning
=1
32 _ucidef_set_interface
() {
36 json_select_object
"$name"
37 json_add_string ifname
"$iface"
41 ucidef_set_board_id
() {
42 json_select_object model
43 json_add_string id
"$1"
47 ucidef_set_model_name
() {
48 json_select_object model
49 json_add_string name
"$1"
53 ucidef_set_interface_loopback
()
59 ucidef_set_interface_lan
() {
62 json_select_object network
63 _ucidef_set_interface lan
"$lan_if"
67 ucidef_set_interface_wan
() {
70 json_select_object network
71 _ucidef_set_interface wan
"$wan_if"
75 ucidef_set_interfaces_lan_wan
() {
79 json_select_object network
80 _ucidef_set_interface lan
"$lan_if"
81 _ucidef_set_interface wan
"$wan_if"
90 json_select_object switch
92 json_select_object
"$name"
93 json_add_boolean
enable "$enable"
94 json_add_boolean
reset "$reset"
100 ucidef_add_switch_attr
() {
105 json_select_object switch
106 json_select_object
"$name"
109 [0-9]) json_add_int
"$key" "$val" ;;
110 *) json_add_string
"$key" "$val" ;;
117 _ucidef_add_switch_port
() {
118 # inherited: $num $device $need_tag $role $index $prev_role
119 # inherited: $n_cpu $n_ports $n_vlan $cpu0 $cpu1 $cpu2 $cpu3 $cpu4 $cpu5
121 n_ports
=$
((n_ports
+ 1))
123 json_select_array ports
125 json_add_int num
"$num"
126 [ -n "$device" ] && json_add_string device
"$device"
127 [ -n "$need_tag" ] && json_add_boolean need_tag
"$need_tag"
128 [ -n "$role" ] && json_add_string role
"$role"
129 [ -n "$index" ] && json_add_int index
"$index"
133 # record pointer to cpu entry for lookup in _ucidef_finish_switch_roles()
134 [ -n "$device" ] && {
135 export "cpu$n_cpu=$n_ports"
139 # create/append object to role list
141 json_select_array roles
143 if [ "$role" != "$prev_role" ]; then
145 json_add_string role
"$role"
146 json_add_string ports
"$num"
150 n_vlan
=$
((n_vlan
+ 1))
152 json_select_object
"$n_vlan"
153 json_get_var port ports
154 json_add_string ports
"$port $num"
162 _ucidef_finish_switch_roles
() {
163 # inherited: $name $n_cpu $n_vlan $cpu0 $cpu1 $cpu2 $cpu3 $cpu4 $cpu5
164 local index role roles num device need_tag port ports
168 json_get_keys roles roles
172 for index
in $roles; do
173 eval "port=\$cpu$(((index - 1) % n_cpu))"
179 json_get_vars num device need_tag
183 if [ $n_vlan -gt $n_cpu -o ${need_tag:-0} -eq 1 ]; then
185 device
="${device}.${index}"
190 json_get_vars role ports
191 json_add_string ports
"$ports $num"
192 json_add_string device
"$device"
198 json_select_object network
199 json_select_object
"$role"
200 # attach previous interfaces (for multi-switch devices)
201 local prev_device
; json_get_var prev_device ifname
202 if ! list_contains prev_device
"$device"; then
203 device
="${prev_device:+$prev_device }$device"
205 json_add_string ifname
"$device"
211 ucidef_add_switch_ports
() {
212 local name
="$1"; shift
213 local port num role device index need_tag prev_role
214 local cpu0 cpu1 cpu2 cpu3 cpu4 cpu5
215 local n_cpu
=0 n_vlan
=0 n_ports
=0
217 json_select_object switch
218 json_select_object
"$name"
226 [ "${num%t}" != "$num" ] && {
234 role
="${port#[0-9]*:}"; role
="${role%:*}"
242 if [ -n "$num" ] && [ -n "$device$role" ]; then
243 _ucidef_add_switch_port
246 unset num device role index need_tag
252 _ucidef_finish_switch_roles
255 ucidef_add_switch_port_attr
() {
262 json_select_object switch
263 json_select_object
"$name"
265 json_get_keys ports ports
266 json_select_array ports
272 if [ -n "$num" ] && [ $num -eq $port ]; then
273 json_select_object attr
276 [0-9]) json_add_int
"$key" "$val" ;;
277 *) json_add_string
"$key" "$val" ;;
291 ucidef_set_interface_macaddr
() {
295 json_select_object network
297 json_select
"$network"
303 json_add_string macaddr
"$macaddr"
309 ucidef_set_led_netdev
() {
315 json_select_object led
317 json_select_object
"$1"
318 json_add_string name
"$name"
319 json_add_string
type netdev
320 json_add_string sysfs
"$sysfs"
321 json_add_string device
"$dev"
327 ucidef_set_led_usbdev
() {
333 json_select_object led
335 json_select_object
"$1"
336 json_add_string name
"$name"
337 json_add_string
type usb
338 json_add_string sysfs
"$sysfs"
339 json_add_string device
"$dev"
345 ucidef_set_led_wlan
() {
351 json_select_object led
353 json_select_object
"$1"
354 json_add_string name
"$name"
355 json_add_string
type trigger
356 json_add_string sysfs
"$sysfs"
357 json_add_string trigger
"$trigger"
363 ucidef_set_led_switch
() {
370 json_select_object led
372 json_select_object
"$1"
373 json_add_string name
"$name"
374 json_add_string
type switch
375 json_add_string sysfs
"$sysfs"
376 json_add_string trigger
"$trigger"
377 json_add_string port_mask
"$port_mask"
383 ucidef_set_led_default
() {
389 json_select_object led
391 json_select_object
"$1"
392 json_add_string name
"$name"
393 json_add_string sysfs
"$sysfs"
394 json_add_string default
"$default"
400 ucidef_set_led_gpio
() {
407 json_select_object led
409 json_select_object
"$1"
410 json_add_string
type gpio
411 json_add_string name
"$name"
412 json_add_string sysfs
"$sysfs"
413 json_add_string trigger
"$trigger"
414 json_add_int gpio
"$gpio"
415 json_add_boolean inverted
"$inverted"
421 ucidef_set_led_rssi
() {
431 json_select_object led
433 json_select_object
"$1"
434 json_add_string
type rssi
435 json_add_string name
"$name"
436 json_add_string iface
"$iface"
437 json_add_string sysfs
"$sysfs"
438 json_add_string minq
"$minq"
439 json_add_string maxq
"$maxq"
440 json_add_string offset
"$offset"
441 json_add_string
factor "$factor"
447 ucidef_set_rssimon
() {
452 json_select_object rssimon
454 json_select_object
"$dev"
455 [ -n "$refresh" ] && json_add_int refresh
"$refresh"
456 [ -n "$threshold" ] && json_add_int threshold
"$threshold"
463 board_config_update
() {
465 [ -f ${CFG} ] && json_load
"$(cat ${CFG})"
468 board_config_flush
() {
469 json_dump
-i > /tmp
/.board.json
470 mv /tmp
/.board.json
${CFG}