mirror of
https://github.com/Ysurac/openmptcprouter.git
synced 2025-03-09 15:40:20 +00:00
Add tools for RUTX platform on 6.1 kernel
This commit is contained in:
parent
f9d849ae11
commit
34d19875d7
34 changed files with 4894 additions and 0 deletions
54
6.1/target/linux/ipq40xx/base-files/lib/functions/board.sh
Normal file
54
6.1/target/linux/ipq40xx/base-files/lib/functions/board.sh
Normal file
|
@ -0,0 +1,54 @@
|
|||
|
||||
. /usr/share/libubox/jshn.sh
|
||||
|
||||
# when device contains 2 internal modems, this function will return '2' if
|
||||
# selected modem(inc_id) is builtin and primary.
|
||||
# And if it's only builtin, then '1'
|
||||
is_builtin_modem() {
|
||||
local inc_id="$1"
|
||||
local modem modems id builtin primary
|
||||
|
||||
json_init
|
||||
json_load_file "/etc/board.json"
|
||||
|
||||
json_get_keys modems modems
|
||||
json_select modems
|
||||
|
||||
for modem in $modems; do
|
||||
json_select "$modem"
|
||||
json_get_vars id builtin primary
|
||||
|
||||
[ "$id" = "$inc_id" ] && {
|
||||
[ -n "$builtin" ] && {
|
||||
[ -n "$primary" ] && {
|
||||
echo 2
|
||||
return
|
||||
}
|
||||
|
||||
echo 1
|
||||
return
|
||||
}
|
||||
|
||||
echo 0
|
||||
return
|
||||
}
|
||||
|
||||
json_select ..
|
||||
done
|
||||
|
||||
echo 0
|
||||
}
|
||||
|
||||
is_dual_modem() {
|
||||
json_init
|
||||
json_load_file "/etc/board.json"
|
||||
|
||||
json_get_keys hwinfo hwinfo
|
||||
json_select hwinfo
|
||||
|
||||
json_get_vars dual_modem
|
||||
|
||||
[ "$dual_modem" = "1" ] && echo 1 || echo 0
|
||||
|
||||
json_select ..
|
||||
}
|
196
6.1/target/linux/ipq40xx/base-files/lib/functions/migrate.sh
Normal file
196
6.1/target/linux/ipq40xx/base-files/lib/functions/migrate.sh
Normal file
|
@ -0,0 +1,196 @@
|
|||
#!/bin/sh
|
||||
|
||||
. /lib/functions.sh
|
||||
. /usr/share/libubox/jshn.sh
|
||||
|
||||
CFG_PATH="/etc/config/"
|
||||
|
||||
get_section_name() {
|
||||
local ___var="$1"
|
||||
[ "$#" -ge 1 ] && shift
|
||||
local ___type="$1"
|
||||
[ "$#" -ge 1 ] && shift
|
||||
local section cfgtype
|
||||
|
||||
[ -z "$CONFIG_SECTIONS" ] && return 0
|
||||
for section in ${CONFIG_SECTIONS}; do
|
||||
config_get cfgtype "$section" TYPE
|
||||
[ -n "$___type" -a "x$cfgtype" != "x$___type" ] && continue
|
||||
eval export "${___var}=\${section}"
|
||||
return 0
|
||||
done
|
||||
}
|
||||
|
||||
_set_option() {
|
||||
local option="$1"
|
||||
local value="$2"
|
||||
|
||||
uci_set "$_NEW_CONFIG" "$_NEW_SEC_NAME" "$option" "$value"
|
||||
}
|
||||
|
||||
_set_list_option() {
|
||||
local option="$1"
|
||||
local value="$2"
|
||||
|
||||
for element in $value; do
|
||||
uci_add_list "$_NEW_CONFIG" "$_NEW_SEC_NAME" "$option" "$element"
|
||||
done
|
||||
}
|
||||
|
||||
_del_uci_element() {
|
||||
local section="$1"
|
||||
local option="$2"
|
||||
|
||||
uci_remove "$_OLD_CONFIG" "$section" "$option"
|
||||
}
|
||||
_option_cond_cb() {
|
||||
local value=$3
|
||||
|
||||
json_select $2
|
||||
json_get_var old 1
|
||||
json_get_var new 2
|
||||
|
||||
[ "$old" = "$value" ] && _COND_VALUE="$new"
|
||||
|
||||
json_select ..
|
||||
}
|
||||
|
||||
_parse_condition(){
|
||||
local value="$1"
|
||||
|
||||
_COND_VALUE=
|
||||
json_for_each_item _option_cond_cb "if" "$value"
|
||||
}
|
||||
|
||||
_option_rule_cb(){
|
||||
local rule="$1"
|
||||
local option="$2"
|
||||
local value
|
||||
|
||||
[ -n "$rule" ] || return 0
|
||||
|
||||
json_select "$option"
|
||||
json_get_vars new_name "if" default cb type
|
||||
|
||||
if [ -n "$cb" ]; then
|
||||
eval "$cb \"\$option\" \"\$_OLD_SEC_NAME\" \"\$_NEW_SEC_NAME\""
|
||||
[ "$?" -eq 0 ] && {
|
||||
json_select ..
|
||||
return 0
|
||||
}
|
||||
|
||||
value="$_OPTION_VALUE"
|
||||
else
|
||||
config_get value $_OLD_SEC_NAME "$option" "$default"
|
||||
fi
|
||||
|
||||
[ -n "$if" ] && {
|
||||
_parse_condition "$value"
|
||||
value="${_COND_VALUE:-${value:-$default}}"
|
||||
}
|
||||
|
||||
if [ -n "$type" -a "$type" = "list" ]; then
|
||||
_set_list_option "${new_name:-$option}" "$value"
|
||||
else
|
||||
_set_option "${new_name:-$option}" "$value"
|
||||
fi
|
||||
|
||||
json_select ..
|
||||
}
|
||||
|
||||
_init_section() {
|
||||
local sec_t
|
||||
|
||||
json_get_vars old_name new_name new_type old_type
|
||||
[ -n "$old_name" -o -n "$old_type" ] || return 1
|
||||
|
||||
if [ -z "$old_name" ]; then
|
||||
get_section_name _OLD_SEC_NAME "$old_type"
|
||||
else
|
||||
_OLD_SEC_NAME=$old_name
|
||||
fi
|
||||
|
||||
_NEW_SEC_NAME=$new_name
|
||||
_OLD_SEC_TYPE=$old_type
|
||||
_NEW_SEC_TYPE=${new_type:-$old_type}
|
||||
[ -n "$_NEW_SEC_TYPE" ] || \
|
||||
eval "_NEW_SEC_TYPE=\$CONFIG_${_OLD_SEC_NAME}_TYPE"
|
||||
|
||||
if [ -n "$_NEW_SEC_NAME" ]; then
|
||||
uci set "$_NEW_CONFIG"."$_NEW_SEC_NAME"="$_NEW_SEC_TYPE"
|
||||
else
|
||||
_NEW_SEC_NAME="$(uci -q add "$_NEW_CONFIG" "$_NEW_SEC_TYPE")"
|
||||
fi
|
||||
|
||||
[ -n "$_NEW_SEC_NAME" ] || return 1
|
||||
}
|
||||
|
||||
_section_rule_cb(){
|
||||
local rule="$1"
|
||||
local section="$2"
|
||||
local value
|
||||
|
||||
[ -n "$rule" ] || return 0
|
||||
|
||||
json_select "$section"
|
||||
json_get_vars cb old_name new_name new_type old_type remove
|
||||
[ -n "$cb" ] && {
|
||||
eval "$cb \"\$old_name\" \"\$new_name\" \"\$old_type\" \"\$new_type\""
|
||||
[ "$?" -eq 0 ] && {
|
||||
json_select ..
|
||||
return 0
|
||||
}
|
||||
}
|
||||
|
||||
_init_section
|
||||
[ $? -ne 0 ] && {
|
||||
logger -t "Migration" "Unable to init section"
|
||||
json_select ..
|
||||
|
||||
return 1
|
||||
}
|
||||
|
||||
json_for_each_item _option_rule_cb options
|
||||
json_select ..
|
||||
[ -n "$remove" ] && {
|
||||
_del_uci_element "$old_name"
|
||||
uci_commit "$_OLD_CONFIG"
|
||||
}
|
||||
}
|
||||
|
||||
_init_config() {
|
||||
json_select config
|
||||
json_get_vars old_name new_name
|
||||
|
||||
[ -n "$old_name" ] || return 1
|
||||
[ -f "$CFG_PATH$old_name" ] || return 1
|
||||
[ -f "$CFG_PATH$new_name" ] || touch $CFG_PATH$new_name
|
||||
|
||||
config_load "$old_name"
|
||||
_NEW_CONFIG="${new_name:-$old_name}"
|
||||
_OLD_CONFIG="$old_name"
|
||||
|
||||
json_select ..
|
||||
}
|
||||
|
||||
migrate() {
|
||||
local remove
|
||||
local json_file="$1"
|
||||
|
||||
[ -f "$json_file" ] || return 0
|
||||
|
||||
json_init
|
||||
json_load_file "$json_file"
|
||||
json_select
|
||||
_init_config
|
||||
[ $? -ne 0 ] && {
|
||||
logger -t "Migration" "Unable to load config"
|
||||
return 1
|
||||
}
|
||||
|
||||
json_for_each_item _section_rule_cb sections
|
||||
uci_commit "$_NEW_CONFIG"
|
||||
|
||||
json_get_vars remove
|
||||
[ -n "$remove" ] && rm "$CFG_PATH$_OLD_CONFIG"
|
||||
}
|
313
6.1/target/linux/ipq40xx/base-files/lib/functions/network.sh
Normal file
313
6.1/target/linux/ipq40xx/base-files/lib/functions/network.sh
Normal file
|
@ -0,0 +1,313 @@
|
|||
# 1: destination variable
|
||||
# 2: interface
|
||||
# 3: path
|
||||
# 4: separator
|
||||
# 5: limit
|
||||
__network_ifstatus() {
|
||||
local __tmp
|
||||
|
||||
[ -z "$__NETWORK_CACHE" ] && {
|
||||
__tmp="$(ubus call network.interface dump 2>&1)"
|
||||
case "$?" in
|
||||
4) : ;;
|
||||
0) export __NETWORK_CACHE="$__tmp" ;;
|
||||
*) echo "$__tmp" >&2 ;;
|
||||
esac
|
||||
}
|
||||
|
||||
__tmp="$(jsonfilter ${4:+-F "$4"} ${5:+-l "$5"} -s "${__NETWORK_CACHE:-{}}" -e "$1=@.interface${2:+[@.interface='$2']}$3")"
|
||||
|
||||
[ -z "$__tmp" ] && \
|
||||
unset "$1" && \
|
||||
return 1
|
||||
|
||||
eval "$__tmp"
|
||||
}
|
||||
|
||||
# determine first IPv4 address of given logical interface
|
||||
# 1: destination variable
|
||||
# 2: interface
|
||||
network_get_ipaddr() {
|
||||
__network_ifstatus "$1" "$2" "['ipv4-address'][0].address";
|
||||
}
|
||||
|
||||
# determine first IPv6 address of given logical interface
|
||||
# 1: destination variable
|
||||
# 2: interface
|
||||
network_get_ipaddr6() {
|
||||
__network_ifstatus "$1" "$2" "['ipv6-address'][0].address" || \
|
||||
__network_ifstatus "$1" "$2" "['ipv6-prefix-assignment'][0]['local-address'].address" || \
|
||||
return 1
|
||||
}
|
||||
|
||||
# determine first IPv4 subnet of given logical interface
|
||||
# 1: destination variable
|
||||
# 2: interface
|
||||
network_get_subnet() {
|
||||
__network_ifstatus "$1" "$2" "['ipv4-address'][0]['address','mask']" "/"
|
||||
}
|
||||
|
||||
# determine first IPv6 subnet of given logical interface
|
||||
# 1: destination variable
|
||||
# 2: interface
|
||||
network_get_subnet6() {
|
||||
local __nets __addr
|
||||
|
||||
if network_get_subnets6 __nets "$2"; then
|
||||
# Attempt to return first non-fe80::/10, non-fc::/7 range
|
||||
for __addr in $__nets; do
|
||||
case "$__addr" in fe[8ab]?:*|f[cd]??:*)
|
||||
continue
|
||||
esac
|
||||
export "$1=$__addr"
|
||||
return 0
|
||||
done
|
||||
|
||||
# Attempt to return first non-fe80::/10 range
|
||||
for __addr in $__nets; do
|
||||
case "$__addr" in fe[8ab]?:*)
|
||||
continue
|
||||
esac
|
||||
export "$1=$__addr"
|
||||
return 0
|
||||
done
|
||||
|
||||
# Return first item
|
||||
for __addr in $__nets; do
|
||||
export "$1=$__addr"
|
||||
return 0
|
||||
done
|
||||
fi
|
||||
|
||||
unset "$1"
|
||||
return 1
|
||||
}
|
||||
|
||||
# determine first IPv6 prefix of given logical interface
|
||||
# 1: destination variable
|
||||
# 2: interface
|
||||
network_get_prefix6() {
|
||||
__network_ifstatus "$1" "$2" "['ipv6-prefix'][0]['address','mask']" "/"
|
||||
}
|
||||
|
||||
# determine all IPv4 addresses of given logical interface
|
||||
# 1: destination variable
|
||||
# 2: interface
|
||||
network_get_ipaddrs() {
|
||||
__network_ifstatus "$1" "$2" "['ipv4-address'][*].address"
|
||||
}
|
||||
|
||||
# determine all IPv6 addresses of given logical interface
|
||||
# 1: destination variable
|
||||
# 2: interface
|
||||
network_get_ipaddrs6() {
|
||||
local __addr
|
||||
local __list=""
|
||||
|
||||
if __network_ifstatus "__addr" "$2" "['ipv6-address'][*].address"; then
|
||||
for __addr in $__addr; do
|
||||
__list="${__list:+$__list }${__addr}"
|
||||
done
|
||||
fi
|
||||
|
||||
if __network_ifstatus "__addr" "$2" "['ipv6-prefix-assignment'][*]['local-address'].address"; then
|
||||
for __addr in $__addr; do
|
||||
__list="${__list:+$__list }${__addr}"
|
||||
done
|
||||
fi
|
||||
|
||||
if [ -n "$__list" ]; then
|
||||
export "$1=$__list"
|
||||
return 0
|
||||
fi
|
||||
|
||||
unset "$1"
|
||||
return 1
|
||||
}
|
||||
|
||||
# determine all IP addresses of given logical interface
|
||||
# 1: destination variable
|
||||
# 2: interface
|
||||
network_get_ipaddrs_all() {
|
||||
local __addr __addr6
|
||||
|
||||
network_get_ipaddrs __addr "$2"
|
||||
network_get_ipaddrs6 __addr6 "$2"
|
||||
|
||||
if [ -n "$__addr" -o -n "$__addr6" ]; then
|
||||
export "$1=${__addr:+$__addr }$__addr6"
|
||||
return 0
|
||||
fi
|
||||
|
||||
unset "$1"
|
||||
return 1
|
||||
}
|
||||
|
||||
# determine all IPv4 subnets of given logical interface
|
||||
# 1: destination variable
|
||||
# 2: interface
|
||||
network_get_subnets() {
|
||||
__network_ifstatus "$1" "$2" "['ipv4-address'][*]['address','mask']" "/ "
|
||||
}
|
||||
|
||||
# determine all IPv6 subnets of given logical interface
|
||||
# 1: destination variable
|
||||
# 2: interface
|
||||
network_get_subnets6() {
|
||||
local __addr __mask
|
||||
local __list=""
|
||||
|
||||
if __network_ifstatus "__addr" "$2" "['ipv6-address'][*]['address','mask']" "/ "; then
|
||||
for __addr in $__addr; do
|
||||
__list="${__list:+$__list }${__addr}"
|
||||
done
|
||||
fi
|
||||
|
||||
if __network_ifstatus "__addr" "$2" "['ipv6-prefix-assignment'][*]['local-address'].address" && \
|
||||
__network_ifstatus "__mask" "$2" "['ipv6-prefix-assignment'][*].mask"; then
|
||||
for __addr in $__addr; do
|
||||
__list="${__list:+$__list }${__addr}/${__mask%% *}"
|
||||
__mask="${__mask#* }"
|
||||
done
|
||||
fi
|
||||
|
||||
if [ -n "$__list" ]; then
|
||||
export "$1=$__list"
|
||||
return 0
|
||||
fi
|
||||
|
||||
unset "$1"
|
||||
return 1
|
||||
}
|
||||
|
||||
# determine all IPv6 prefixes of given logical interface
|
||||
# 1: destination variable
|
||||
# 2: interface
|
||||
network_get_prefixes6() {
|
||||
__network_ifstatus "$1" "$2" "['ipv6-prefix'][*]['address','mask']" "/ "
|
||||
}
|
||||
|
||||
# determine IPv4 gateway of given logical interface
|
||||
# 1: destination variable
|
||||
# 2: interface
|
||||
# 3: consider inactive gateway if "true" (optional)
|
||||
network_get_gateway() {
|
||||
__network_ifstatus "$1" "$2" ".route[@.target='0.0.0.0' && !@.table].nexthop" "" 1 && \
|
||||
return 0
|
||||
|
||||
[ "$3" = 1 -o "$3" = "true" ] && \
|
||||
__network_ifstatus "$1" "$2" ".inactive.route[@.target='0.0.0.0' && !@.table].nexthop" "" 1
|
||||
}
|
||||
|
||||
# determine IPv6 gateway of given logical interface
|
||||
# 1: destination variable
|
||||
# 2: interface
|
||||
# 3: consider inactive gateway if "true" (optional)
|
||||
network_get_gateway6() {
|
||||
__network_ifstatus "$1" "$2" ".route[@.target='::' && !@.table].nexthop" "" 1 && \
|
||||
return 0
|
||||
|
||||
[ "$3" = 1 -o "$3" = "true" ] && \
|
||||
__network_ifstatus "$1" "$2" ".inactive.route[@.target='::' && !@.table].nexthop" "" 1
|
||||
}
|
||||
|
||||
# determine the DNS servers of the given logical interface
|
||||
# 1: destination variable
|
||||
# 2: interface
|
||||
# 3: consider inactive servers if "true" (optional)
|
||||
network_get_dnsserver() {
|
||||
__network_ifstatus "$1" "$2" "['dns-server'][*]" && return 0
|
||||
|
||||
[ "$3" = 1 -o "$3" = "true" ] && \
|
||||
__network_ifstatus "$1" "$2" ".inactive['dns-server'][*]"
|
||||
}
|
||||
|
||||
# determine the domains of the given logical interface
|
||||
# 1: destination variable
|
||||
# 2: interface
|
||||
# 3: consider inactive domains if "true" (optional)
|
||||
network_get_dnssearch() {
|
||||
__network_ifstatus "$1" "$2" "['dns-search'][*]" && return 0
|
||||
|
||||
[ "$3" = 1 -o "$3" = "true" ] && \
|
||||
__network_ifstatus "$1" "$2" ".inactive['dns-search'][*]"
|
||||
}
|
||||
|
||||
# 1: destination variable
|
||||
# 2: addr
|
||||
# 3: inactive
|
||||
# 4: limit
|
||||
__network_wan()
|
||||
{
|
||||
limit=1
|
||||
[ -n "$4" ] && limit="$4"
|
||||
__network_ifstatus "$1" "" \
|
||||
"[@.route[@.target='$2' && !@.table]].interface" "" $limit && \
|
||||
return 0
|
||||
|
||||
[ "$3" = 1 -o "$3" = "true" ] && \
|
||||
__network_ifstatus "$1" "" \
|
||||
"[@.inactive.route[@.target='$2' && !@.table]].interface" "" $limit
|
||||
}
|
||||
|
||||
# find the logical interface which holds the current IPv4 default route
|
||||
# 1: destination variable
|
||||
# 2: consider inactive default routes if "true" (optional)
|
||||
network_find_wan() { __network_wan "$1" "0.0.0.0" "$2" "$3"; }
|
||||
|
||||
# find the logical interface which holds the current IPv6 default route
|
||||
# 1: destination variable
|
||||
# 2: consider inactive default routes if "true" (optional)
|
||||
network_find_wan6() { __network_wan "$1" "::" "$2"; }
|
||||
|
||||
# test whether the given logical interface is running
|
||||
# 1: interface
|
||||
network_is_up()
|
||||
{
|
||||
local __up
|
||||
__network_ifstatus "__up" "$1" ".up" && [ "$__up" = 1 ]
|
||||
}
|
||||
|
||||
# determine the protocol of the given logical interface
|
||||
# 1: destination variable
|
||||
# 2: interface
|
||||
network_get_protocol() { __network_ifstatus "$1" "$2" ".proto"; }
|
||||
|
||||
# determine the uptime of the given logical interface
|
||||
# 1: destination variable
|
||||
# 2: interface
|
||||
network_get_uptime() { __network_ifstatus "$1" "$2" ".uptime"; }
|
||||
|
||||
# determine the metric of the given logical interface
|
||||
# 1: destination variable
|
||||
# 2: interface
|
||||
network_get_metric() { __network_ifstatus "$1" "$2" ".metric"; }
|
||||
|
||||
# determine the layer 3 linux network device of the given logical interface
|
||||
# 1: destination variable
|
||||
# 2: interface
|
||||
network_get_device() { __network_ifstatus "$1" "$2" ".l3_device"; }
|
||||
|
||||
# determine the layer 2 linux network device of the given logical interface
|
||||
# 1: destination variable
|
||||
# 2: interface
|
||||
network_get_physdev() { __network_ifstatus "$1" "$2" ".device"; }
|
||||
|
||||
# defer netifd actions on the given linux network device
|
||||
# 1: device name
|
||||
network_defer_device()
|
||||
{
|
||||
ubus call network.device set_state \
|
||||
"$(printf '{ "name": "%s", "defer": true }' "$1")" 2>/dev/null
|
||||
}
|
||||
|
||||
# continue netifd actions on the given linux network device
|
||||
# 1: device name
|
||||
network_ready_device()
|
||||
{
|
||||
ubus call network.device set_state \
|
||||
"$(printf '{ "name": "%s", "defer": false }' "$1")" 2>/dev/null
|
||||
}
|
||||
|
||||
# flush the internal value cache to force re-reading values from ubus
|
||||
network_flush_cache() { unset __NETWORK_CACHE; }
|
143
6.1/target/linux/ipq40xx/base-files/lib/functions/teltonika-defaults.sh
Executable file
143
6.1/target/linux/ipq40xx/base-files/lib/functions/teltonika-defaults.sh
Executable file
|
@ -0,0 +1,143 @@
|
|||
#!/bin/ash
|
||||
|
||||
. /lib/functions.sh
|
||||
. /usr/share/libubox/jshn.sh
|
||||
|
||||
ucidef_add_static_modem_info() {
|
||||
#Parameters: model usb_id sim_count other_params
|
||||
local model usb_id count
|
||||
local modem_counter=0
|
||||
local sim_count=1
|
||||
|
||||
model="$1"
|
||||
usb_id="$2"
|
||||
|
||||
[ -n "$3" ] && sim_count="$3"
|
||||
|
||||
json_get_keys count modems
|
||||
[ -n "$count" ] && modem_counter="$(echo "$count" | wc -w)"
|
||||
|
||||
json_select_array "modems"
|
||||
json_add_object
|
||||
json_add_string id "$usb_id"
|
||||
json_add_string num "$((modem_counter + 1))"
|
||||
json_add_boolean builtin 1
|
||||
json_add_int simcount "$sim_count"
|
||||
|
||||
for i in "$@"; do
|
||||
case "$i" in
|
||||
primary)
|
||||
json_add_boolean primary 1
|
||||
;;
|
||||
gps_out)
|
||||
json_add_boolean gps_out 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
json_close_object
|
||||
json_select ..
|
||||
}
|
||||
|
||||
ucidef_add_serial_capabilities() {
|
||||
json_select_array serial
|
||||
json_add_object
|
||||
[ -n "$1" ] && {
|
||||
json_select_array devices
|
||||
for d in $1; do
|
||||
json_add_string "" $d
|
||||
done
|
||||
json_select ..
|
||||
}
|
||||
|
||||
json_select_array bauds
|
||||
for b in $2; do
|
||||
json_add_string "" $b
|
||||
done
|
||||
json_select ..
|
||||
|
||||
json_select_array data_bits
|
||||
for n in $3; do
|
||||
json_add_string "" $n
|
||||
done
|
||||
json_select ..
|
||||
|
||||
json_select_array flow_control
|
||||
for n in $4; do
|
||||
json_add_string "" $n
|
||||
done
|
||||
json_select ..
|
||||
|
||||
json_select_array stop_bits
|
||||
for n in $5; do
|
||||
json_add_string "" $n
|
||||
done
|
||||
json_select ..
|
||||
|
||||
json_select_array parity_types
|
||||
for n in $6; do
|
||||
json_add_string "" $n
|
||||
done
|
||||
json_select ..
|
||||
|
||||
json_add_string "path" $7
|
||||
|
||||
json_close_object
|
||||
json_select ..
|
||||
}
|
||||
|
||||
ucidef_add_wlan_bssid_limit() {
|
||||
json_select_object wlan
|
||||
json_add_object "$1"
|
||||
json_add_int bssid_limit "$2"
|
||||
json_close_object
|
||||
json_select ..
|
||||
}
|
||||
|
||||
ucidef_set_hwinfo() {
|
||||
local args=" $* "
|
||||
local options='
|
||||
dual_sim
|
||||
at_sim
|
||||
wifi
|
||||
dual_band_ssid
|
||||
wps
|
||||
mobile
|
||||
gps
|
||||
usb
|
||||
poe
|
||||
bluetooth
|
||||
ethernet
|
||||
sfp_port
|
||||
ios
|
||||
sfp_switch
|
||||
rs232
|
||||
rs485
|
||||
console
|
||||
dual_modem
|
||||
sd_card
|
||||
sw_rst_on_init
|
||||
dsa
|
||||
hw_nat
|
||||
'
|
||||
|
||||
json_select_object hwinfo
|
||||
|
||||
for opt in $options; do
|
||||
if [[ "$args" =~ " $(echo "$opt" | tr -d '\011\012\015\040') " ]]; then
|
||||
json_add_boolean "$opt" 1
|
||||
else
|
||||
json_add_boolean "$opt" 0
|
||||
fi
|
||||
done
|
||||
|
||||
json_select ..
|
||||
}
|
||||
|
||||
ucidef_set_release_version() {
|
||||
json_add_string release_version "$1"
|
||||
}
|
||||
|
||||
ucidef_set_usb_jack() {
|
||||
json_add_string "usb_jack" "$1"
|
||||
}
|
68
6.1/target/linux/ipq40xx/base-files/lib/functions/teltonika-functions.sh
Executable file
68
6.1/target/linux/ipq40xx/base-files/lib/functions/teltonika-functions.sh
Executable file
|
@ -0,0 +1,68 @@
|
|||
#!/bin/sh
|
||||
|
||||
. /usr/share/libubox/jshn.sh
|
||||
|
||||
is_ios_enabled() {
|
||||
local ios
|
||||
json_load_file "/etc/board.json" &&
|
||||
json_select hwinfo &&
|
||||
json_get_var ios ios && [ "$ios" = "1" ]
|
||||
}
|
||||
|
||||
# set_tty_options <device_path> <baudrate> <databits> <parity> <stopbits> <flowcontrol> <duplex> <echo>
|
||||
set_tty_options() {
|
||||
local PARITY_TMP=""
|
||||
local SBITS_TMP=""
|
||||
local FCTRL_TMP=""
|
||||
|
||||
case "$4" in
|
||||
"odd") PARITY_TMP="parenb parodd -cmspar" ;;
|
||||
"even") PARITY_TMP="parenb -parodd -cmspar" ;;
|
||||
"mark") PARITY_TMP="parenb parodd cmspar";;
|
||||
"space") PARITY_TMP="parenb -parodd cmspar";;
|
||||
*) PARITY_TMP="-parenb -parodd -cmspar" ;;
|
||||
esac
|
||||
|
||||
case "$5" in
|
||||
1) SBITS_TMP="-cstopb" ;;
|
||||
2) SBITS_TMP="cstopb" ;;
|
||||
*) SBITS_TMP="-cstopb" ;;
|
||||
esac
|
||||
|
||||
case "$6" in
|
||||
"none") FCTRL_TMP="-crtscts -ixon -ixoff" ;;
|
||||
"rts/cts") FCTRL_TMP="crtscts -ixon -ixoff" ;;
|
||||
"xon/xoff") FCTRL_TMP="-crtscts ixon ixoff" ;;
|
||||
*) FCTRL_TMP="-crtscts -ixon -ixoff" ;;
|
||||
esac
|
||||
|
||||
case "$7" in
|
||||
0 | 1)
|
||||
echo "$7" >/sys/class/gpio/rs485_rx_en/value
|
||||
;;
|
||||
esac
|
||||
|
||||
if [ "$8" == "1" ]; then
|
||||
FCTRL_TMP="$FCTRL_TMP echo"
|
||||
else
|
||||
FCTRL_TMP="$FCTRL_TMP -echo"
|
||||
fi
|
||||
|
||||
local stty_retries=0
|
||||
while ! stty -F "$1" "$2" cs"$3" $PARITY_TMP "$SBITS_TMP" $FCTRL_TMP; do
|
||||
if [ $stty_retries -lt 5 ]; then
|
||||
stty_retries=$((stty_retries + 1))
|
||||
echo "stty was unable to set all the parameters, retrying in 10 seconds"
|
||||
sleep 10
|
||||
else
|
||||
echo "stty failed, continuing anyway"
|
||||
break
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
to_lower() {
|
||||
tr '[A-Z]' '[a-z]' <<-EOF
|
||||
$@
|
||||
EOF
|
||||
}
|
|
@ -0,0 +1,726 @@
|
|||
#!/bin/ash
|
||||
|
||||
. /lib/functions.sh
|
||||
. /usr/share/libubox/jshn.sh
|
||||
|
||||
json_select_array() {
|
||||
local _json_no_warning=1
|
||||
|
||||
json_select "$1"
|
||||
[ $? = 0 ] && return
|
||||
|
||||
json_add_array "$1"
|
||||
json_close_array
|
||||
|
||||
json_select "$1"
|
||||
}
|
||||
|
||||
json_select_object() {
|
||||
local _json_no_warning=1
|
||||
|
||||
json_select "$1"
|
||||
[ $? = 0 ] && return
|
||||
|
||||
json_add_object "$1"
|
||||
json_close_object
|
||||
|
||||
json_select "$1"
|
||||
}
|
||||
|
||||
ucidef_set_interface() {
|
||||
local network=$1; shift
|
||||
|
||||
[ -z "$network" ] && return
|
||||
|
||||
json_select_object network
|
||||
json_select_object "$network"
|
||||
|
||||
while [ -n "$1" ]; do
|
||||
local opt=$1; shift
|
||||
local val=$1; shift
|
||||
|
||||
[ -n "$opt" -a -n "$val" ] || break
|
||||
|
||||
[ "$opt" = "device" -a "$val" != "${val/ //}" ] && {
|
||||
json_select_array "ports"
|
||||
for e in $val; do json_add_string "" "$e"; done
|
||||
json_close_array
|
||||
} || {
|
||||
json_add_string "$opt" "$val"
|
||||
}
|
||||
done
|
||||
|
||||
if ! json_is_a proto string; then
|
||||
case "$network" in
|
||||
lan) json_add_string proto static ;;
|
||||
wan) json_add_string proto dhcp ;;
|
||||
*) json_add_string proto none ;;
|
||||
esac
|
||||
fi
|
||||
|
||||
json_select ..
|
||||
json_select ..
|
||||
}
|
||||
|
||||
ucidef_set_interface_default_macaddr() {
|
||||
local network="$1" ifname
|
||||
|
||||
json_select_object 'network'
|
||||
json_select_object "$network"
|
||||
if json_is_a ports array; then
|
||||
json_select_array 'ports'
|
||||
json_get_keys port_id
|
||||
for i in $port_id; do
|
||||
json_get_var port "$i"
|
||||
ifname="${ifname} $port"
|
||||
done
|
||||
json_select ..
|
||||
else
|
||||
json_get_var ifname 'device'
|
||||
fi
|
||||
json_select ..
|
||||
json_select ..
|
||||
|
||||
for i in $ifname; do
|
||||
local macaddr="$2"; shift
|
||||
[ -n "$macaddr" ] || break
|
||||
json_select_object 'network-device'
|
||||
json_select_object "$i"
|
||||
json_add_string 'macaddr' "$macaddr"
|
||||
json_select ..
|
||||
json_select ..
|
||||
done
|
||||
}
|
||||
|
||||
ucidef_set_board_id() {
|
||||
json_select_object model
|
||||
json_add_string id "$1"
|
||||
json_select ..
|
||||
}
|
||||
|
||||
ucidef_set_board_platform() {
|
||||
json_select_object model
|
||||
json_add_string platform "$1"
|
||||
json_select ..
|
||||
}
|
||||
|
||||
ucidef_set_model_name() {
|
||||
json_select_object model
|
||||
json_add_string name "$1"
|
||||
json_select ..
|
||||
}
|
||||
|
||||
ucidef_set_compat_version() {
|
||||
json_select_object system
|
||||
json_add_string compat_version "${1:-1.0}"
|
||||
json_select ..
|
||||
}
|
||||
|
||||
ucidef_set_interface_lan() {
|
||||
ucidef_set_interface "lan" device "$1" proto "${2:-static}"
|
||||
}
|
||||
|
||||
ucidef_set_interface_wan() {
|
||||
ucidef_set_interface "wan" device "$1" proto "${2:-dhcp}"
|
||||
}
|
||||
|
||||
ucidef_set_interfaces_lan_wan() {
|
||||
local lan_if="$1"
|
||||
local wan_if="$2"
|
||||
|
||||
ucidef_set_interface_lan "$lan_if"
|
||||
ucidef_set_interface_wan "$wan_if"
|
||||
}
|
||||
|
||||
_ucidef_add_switch_port() {
|
||||
# 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))
|
||||
|
||||
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 "$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 ..
|
||||
|
||||
# record pointer to cpu entry for lookup in _ucidef_finish_switch_roles()
|
||||
[ -n "$device" ] && {
|
||||
export "cpu$n_cpu=$n_ports"
|
||||
n_cpu=$((n_cpu + 1))
|
||||
}
|
||||
|
||||
# create/append object to role list
|
||||
[ -n "$role" ] && {
|
||||
json_select_array roles
|
||||
|
||||
if [ "$role" != "$prev_role" ]; then
|
||||
json_add_object
|
||||
json_add_string role "$role"
|
||||
json_add_string ports "$num"
|
||||
json_close_object
|
||||
|
||||
prev_role="$role"
|
||||
n_vlan=$((n_vlan + 1))
|
||||
else
|
||||
json_select_object "$n_vlan"
|
||||
json_get_var port ports
|
||||
json_add_string ports "$port $num"
|
||||
json_select ..
|
||||
fi
|
||||
|
||||
json_select ..
|
||||
}
|
||||
}
|
||||
|
||||
_ucidef_finish_switch_roles() {
|
||||
# inherited: $name $n_cpu $n_vlan $cpu0 $cpu1 $cpu2 $cpu3 $cpu4 $cpu5
|
||||
local index role roles num device need_tag want_untag port ports
|
||||
|
||||
json_select switch
|
||||
json_select "$name"
|
||||
json_get_keys roles roles
|
||||
json_select ..
|
||||
json_select ..
|
||||
|
||||
for index in $roles; do
|
||||
eval "port=\$cpu$(((index - 1) % n_cpu))"
|
||||
|
||||
json_select switch
|
||||
json_select "$name"
|
||||
json_select ports
|
||||
json_select "$port"
|
||||
json_get_vars num device need_tag want_untag
|
||||
json_select ..
|
||||
json_select ..
|
||||
|
||||
if [ ${need_tag:-0} -eq 1 -o ${want_untag:-0} -ne 1 ]; then
|
||||
num="${num}t"
|
||||
device="${device}.${index}"
|
||||
fi
|
||||
|
||||
json_select roles
|
||||
json_select "$index"
|
||||
json_get_vars role ports
|
||||
json_add_string ports "$ports $num"
|
||||
json_add_string device "$device"
|
||||
json_select ..
|
||||
json_select ..
|
||||
json_select ..
|
||||
json_select ..
|
||||
|
||||
json_select_object network
|
||||
local devices
|
||||
|
||||
json_select_object "$role"
|
||||
# attach previous interfaces (for multi-switch devices)
|
||||
json_get_var devices device
|
||||
if ! list_contains devices "$device"; then
|
||||
devices="${devices:+$devices }$device"
|
||||
fi
|
||||
json_select ..
|
||||
json_select ..
|
||||
|
||||
ucidef_set_interface "$role" device "$devices"
|
||||
done
|
||||
}
|
||||
|
||||
ucidef_set_ar8xxx_switch_mib() {
|
||||
local name="$1"
|
||||
local type="$2"
|
||||
local interval="$3"
|
||||
|
||||
json_select_object switch
|
||||
json_select_object "$name"
|
||||
json_add_int ar8xxx_mib_type $type
|
||||
json_add_int ar8xxx_mib_poll_interval $interval
|
||||
json_select ..
|
||||
json_select ..
|
||||
}
|
||||
|
||||
ucidef_add_switch() {
|
||||
local enabled=1
|
||||
if [ "$1" = "enabled" ]; then
|
||||
shift
|
||||
enabled="$1"
|
||||
shift
|
||||
fi
|
||||
|
||||
local name="$1"; shift
|
||||
local port num role device index need_tag prev_role
|
||||
local cpu0 cpu1 cpu2 cpu3 cpu4 cpu5
|
||||
local n_cpu=0 n_vlan=0 n_ports=0
|
||||
|
||||
json_select_object switch
|
||||
json_select_object "$name"
|
||||
json_add_boolean enable "$enabled"
|
||||
json_add_boolean reset 1
|
||||
|
||||
for port in "$@"; do
|
||||
case "$port" in
|
||||
[0-9]*@*)
|
||||
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%%:*}"
|
||||
index="${port##*:}"
|
||||
role="${port#[0-9]*:}"; role="${role%:*}"
|
||||
;;
|
||||
[0-9]*:*)
|
||||
num="${port%%:*}"
|
||||
role="${port##*:}"
|
||||
;;
|
||||
esac
|
||||
|
||||
if [ -n "$num" ] && [ -n "$device$role" ]; then
|
||||
_ucidef_add_switch_port
|
||||
fi
|
||||
|
||||
unset num device role index need_tag want_untag
|
||||
done
|
||||
json_select ..
|
||||
json_select ..
|
||||
|
||||
_ucidef_finish_switch_roles
|
||||
}
|
||||
|
||||
ucidef_add_switch_attr() {
|
||||
local name="$1"
|
||||
local key="$2"
|
||||
local val="$3"
|
||||
|
||||
json_select_object switch
|
||||
json_select_object "$name"
|
||||
|
||||
case "$val" in
|
||||
true|false) [ "$val" != "true" ]; json_add_boolean "$key" $? ;;
|
||||
[0-9]) json_add_int "$key" "$val" ;;
|
||||
*) json_add_string "$key" "$val" ;;
|
||||
esac
|
||||
|
||||
json_select ..
|
||||
json_select ..
|
||||
}
|
||||
|
||||
ucidef_add_switch_port_attr() {
|
||||
local name="$1"
|
||||
local port="$2"
|
||||
local key="$3"
|
||||
local val="$4"
|
||||
local ports i num
|
||||
|
||||
json_select_object switch
|
||||
json_select_object "$name"
|
||||
|
||||
json_get_keys ports ports
|
||||
json_select_array ports
|
||||
|
||||
for i in $ports; do
|
||||
json_select "$i"
|
||||
json_get_var num num
|
||||
|
||||
if [ -n "$num" ] && [ $num -eq $port ]; then
|
||||
json_select_object attr
|
||||
|
||||
case "$val" in
|
||||
true|false) [ "$val" != "true" ]; json_add_boolean "$key" $? ;;
|
||||
[0-9]) json_add_int "$key" "$val" ;;
|
||||
*) json_add_string "$key" "$val" ;;
|
||||
esac
|
||||
|
||||
json_select ..
|
||||
fi
|
||||
|
||||
json_select ..
|
||||
done
|
||||
|
||||
json_select ..
|
||||
json_select ..
|
||||
json_select ..
|
||||
}
|
||||
|
||||
ucidef_set_interface_macaddr() {
|
||||
local network="$1"
|
||||
local macaddr="$2"
|
||||
|
||||
ucidef_set_interface "$network" macaddr "$macaddr"
|
||||
}
|
||||
|
||||
ucidef_add_atm_bridge() {
|
||||
local vpi="$1"
|
||||
local vci="$2"
|
||||
local encaps="$3"
|
||||
local payload="$4"
|
||||
local nameprefix="$5"
|
||||
|
||||
json_select_object dsl
|
||||
json_select_object atmbridge
|
||||
json_add_int vpi "$vpi"
|
||||
json_add_int vci "$vci"
|
||||
json_add_string encaps "$encaps"
|
||||
json_add_string payload "$payload"
|
||||
json_add_string nameprefix "$nameprefix"
|
||||
json_select ..
|
||||
json_select ..
|
||||
}
|
||||
|
||||
ucidef_add_adsl_modem() {
|
||||
local annex="$1"
|
||||
local firmware="$2"
|
||||
|
||||
json_select_object dsl
|
||||
json_select_object modem
|
||||
json_add_string type "adsl"
|
||||
json_add_string annex "$annex"
|
||||
json_add_string firmware "$firmware"
|
||||
json_select ..
|
||||
json_select ..
|
||||
}
|
||||
|
||||
ucidef_add_vdsl_modem() {
|
||||
local annex="$1"
|
||||
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 tone "$tone"
|
||||
json_add_string xfer_mode "$xfer_mode"
|
||||
json_select ..
|
||||
json_select ..
|
||||
}
|
||||
|
||||
ucidef_set_led_ataport() {
|
||||
_ucidef_set_led_trigger "$1" "$2" "$3" ata"$4"
|
||||
}
|
||||
|
||||
_ucidef_set_led_common() {
|
||||
local cfg="led_$1"
|
||||
local name="$2"
|
||||
local sysfs="$3"
|
||||
|
||||
json_select_object led
|
||||
|
||||
json_select_object "$1"
|
||||
json_add_string name "$name"
|
||||
json_add_string sysfs "$sysfs"
|
||||
}
|
||||
|
||||
ucidef_set_led_default() {
|
||||
local default="$4"
|
||||
|
||||
_ucidef_set_led_common "$1" "$2" "$3"
|
||||
|
||||
json_add_string default "$default"
|
||||
json_select ..
|
||||
|
||||
json_select ..
|
||||
}
|
||||
|
||||
ucidef_set_led_gpio() {
|
||||
local gpio="$4"
|
||||
local inverted="$5"
|
||||
|
||||
_ucidef_set_led_common "$1" "$2" "$3"
|
||||
|
||||
json_add_string trigger "$trigger"
|
||||
json_add_string type gpio
|
||||
json_add_int gpio "$gpio"
|
||||
json_add_boolean inverted "$inverted"
|
||||
json_select ..
|
||||
|
||||
json_select ..
|
||||
}
|
||||
|
||||
ucidef_set_led_ide() {
|
||||
_ucidef_set_led_trigger "$1" "$2" "$3" disk-activity
|
||||
}
|
||||
|
||||
ucidef_set_led_netdev() {
|
||||
local dev="$4"
|
||||
local mode="${5:-link tx rx}"
|
||||
|
||||
_ucidef_set_led_common "$1" "$2" "$3"
|
||||
|
||||
json_add_string type netdev
|
||||
json_add_string device "$dev"
|
||||
json_add_string mode "$mode"
|
||||
json_select ..
|
||||
|
||||
json_select ..
|
||||
}
|
||||
|
||||
ucidef_set_led_oneshot() {
|
||||
_ucidef_set_led_timer $1 $2 $3 "oneshot" $4 $5
|
||||
}
|
||||
|
||||
ucidef_set_led_portstate() {
|
||||
local port_state="$4"
|
||||
|
||||
_ucidef_set_led_common "$1" "$2" "$3"
|
||||
|
||||
json_add_string trigger port_state
|
||||
json_add_string type portstate
|
||||
json_add_string port_state "$port_state"
|
||||
json_select ..
|
||||
|
||||
json_select ..
|
||||
}
|
||||
|
||||
ucidef_set_led_rssi() {
|
||||
local iface="$4"
|
||||
local minq="$5"
|
||||
local maxq="$6"
|
||||
local offset="${7:-0}"
|
||||
local factor="${8:-1}"
|
||||
|
||||
_ucidef_set_led_common "$1" "$2" "$3"
|
||||
|
||||
json_add_string type rssi
|
||||
json_add_string name "$name"
|
||||
json_add_string iface "$iface"
|
||||
json_add_string minq "$minq"
|
||||
json_add_string maxq "$maxq"
|
||||
json_add_string offset "$offset"
|
||||
json_add_string factor "$factor"
|
||||
json_select ..
|
||||
|
||||
json_select ..
|
||||
}
|
||||
|
||||
ucidef_set_led_switch() {
|
||||
local trigger_name="$4"
|
||||
local port_mask="$5"
|
||||
local speed_mask="$6"
|
||||
local mode="$7"
|
||||
|
||||
_ucidef_set_led_common "$1" "$2" "$3"
|
||||
|
||||
json_add_string trigger "$trigger_name"
|
||||
json_add_string type switch
|
||||
json_add_string mode "$mode"
|
||||
json_add_string port_mask "$port_mask"
|
||||
json_add_string speed_mask "$speed_mask"
|
||||
json_select ..
|
||||
|
||||
json_select ..
|
||||
}
|
||||
|
||||
_ucidef_set_led_timer() {
|
||||
local trigger_name="$4"
|
||||
local delayon="$5"
|
||||
local delayoff="$6"
|
||||
|
||||
_ucidef_set_led_common "$1" "$2" "$3"
|
||||
|
||||
json_add_string type "$trigger_name"
|
||||
json_add_string trigger "$trigger_name"
|
||||
json_add_int delayon "$delayon"
|
||||
json_add_int delayoff "$delayoff"
|
||||
json_select ..
|
||||
|
||||
json_select ..
|
||||
}
|
||||
|
||||
ucidef_set_led_timer() {
|
||||
_ucidef_set_led_timer $1 $2 $3 "timer" $4 $5
|
||||
}
|
||||
|
||||
_ucidef_set_led_trigger() {
|
||||
local trigger_name="$4"
|
||||
|
||||
_ucidef_set_led_common "$1" "$2" "$3"
|
||||
|
||||
json_add_string trigger "$trigger_name"
|
||||
json_select ..
|
||||
|
||||
json_select ..
|
||||
}
|
||||
|
||||
ucidef_set_led_usbdev() {
|
||||
local dev="$4"
|
||||
|
||||
_ucidef_set_led_common "$1" "$2" "$3"
|
||||
|
||||
json_add_string type usb
|
||||
json_add_string device "$dev"
|
||||
json_select ..
|
||||
|
||||
json_select ..
|
||||
}
|
||||
|
||||
ucidef_set_led_usbhost() {
|
||||
_ucidef_set_led_trigger "$1" "$2" "$3" usb-host
|
||||
}
|
||||
|
||||
ucidef_set_led_usbport() {
|
||||
local obj="$1"
|
||||
local name="$2"
|
||||
local sysfs="$3"
|
||||
shift
|
||||
shift
|
||||
shift
|
||||
|
||||
_ucidef_set_led_common "$obj" "$name" "$sysfs"
|
||||
|
||||
json_add_string type usbport
|
||||
json_select_array ports
|
||||
for port in "$@"; do
|
||||
json_add_string port "$port"
|
||||
done
|
||||
json_select ..
|
||||
json_select ..
|
||||
|
||||
json_select ..
|
||||
}
|
||||
|
||||
ucidef_set_led_wlan() {
|
||||
_ucidef_set_led_trigger "$1" "$2" "$3" "$4"
|
||||
}
|
||||
|
||||
ucidef_set_rssimon() {
|
||||
local dev="$1"
|
||||
local refresh="$2"
|
||||
local threshold="$3"
|
||||
|
||||
json_select_object rssimon
|
||||
|
||||
json_select_object "$dev"
|
||||
[ -n "$refresh" ] && json_add_int refresh "$refresh"
|
||||
[ -n "$threshold" ] && json_add_int threshold "$threshold"
|
||||
json_select ..
|
||||
|
||||
json_select ..
|
||||
}
|
||||
|
||||
ucidef_add_gpio_switch() {
|
||||
local cfg="$1"
|
||||
local name="$2"
|
||||
local pin="$3"
|
||||
local default="${4:-0}"
|
||||
|
||||
json_select_object gpioswitch
|
||||
json_select_object "$cfg"
|
||||
json_add_string name "$name"
|
||||
json_add_int pin "$pin"
|
||||
json_add_int default "$default"
|
||||
json_select ..
|
||||
json_select ..
|
||||
}
|
||||
|
||||
ucidef_set_hostname() {
|
||||
local hostname="$1"
|
||||
|
||||
json_select_object system
|
||||
json_add_string hostname "$hostname"
|
||||
json_select ..
|
||||
}
|
||||
|
||||
ucidef_set_ntpserver() {
|
||||
local server
|
||||
|
||||
json_select_object system
|
||||
json_select_array ntpserver
|
||||
for server in "$@"; do
|
||||
json_add_string "" "$server"
|
||||
done
|
||||
json_select ..
|
||||
json_select ..
|
||||
}
|
||||
|
||||
ucidef_set_network_options() {
|
||||
json_add_object "network_options"
|
||||
n=$#
|
||||
|
||||
for i in $(seq $((n / 2))); do
|
||||
opt="$1"
|
||||
val="$2"
|
||||
|
||||
if [ "$val" -eq "$val" ] 2>/dev/null; then
|
||||
json_add_int "$opt" "$val"
|
||||
else
|
||||
[ "$val" = "true" ] && val=1 || val=0
|
||||
json_add_boolean "$opt" "$val"
|
||||
fi
|
||||
shift; shift
|
||||
done
|
||||
json_close_object
|
||||
}
|
||||
|
||||
ucidef_set_poe() {
|
||||
json_add_object poe
|
||||
json_add_int "chip_count" "$1"
|
||||
json_add_int "budget" "$2"
|
||||
json_add_int "poe_ports" "$3"
|
||||
shift 3
|
||||
json_add_array ports
|
||||
while [ $# -gt 0 ]
|
||||
do
|
||||
json_add_object ""
|
||||
json_add_string "name" "$1"
|
||||
json_add_string "class" "$2"
|
||||
json_add_int "budget" "$3"
|
||||
json_close_object
|
||||
shift 3
|
||||
done
|
||||
json_close_array
|
||||
json_add_array poe_chips
|
||||
json_close_array
|
||||
json_close_object
|
||||
}
|
||||
|
||||
ucidef_set_poe_chip() {
|
||||
json_select_object poe
|
||||
json_select_array poe_chips
|
||||
json_add_object ""
|
||||
for port in "$@"; do
|
||||
case "$port" in
|
||||
0X*)
|
||||
json_add_string address "$port"
|
||||
;;
|
||||
[0-9]:*)
|
||||
json_add_string chan"${port%%:*}" "${port##*:}"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
json_close_object
|
||||
json_select ..
|
||||
json_select ..
|
||||
}
|
||||
|
||||
board_config_update() {
|
||||
json_init
|
||||
[ -f ${CFG} ] && json_load "$(cat ${CFG})"
|
||||
|
||||
# auto-initialize model id and name if applicable
|
||||
if ! json_is_a model object; then
|
||||
json_select_object model
|
||||
[ -f "/tmp/sysinfo/board_name" ] && \
|
||||
json_add_string id "$(cat /tmp/sysinfo/board_name)"
|
||||
[ -f "/tmp/sysinfo/model" ] && \
|
||||
json_add_string name "$(cat /tmp/sysinfo/model)"
|
||||
json_select ..
|
||||
fi
|
||||
}
|
||||
|
||||
board_config_flush() {
|
||||
json_dump -i -o ${CFG}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue