1
0
Fork 0
mirror of https://github.com/Ysurac/openmptcprouter.git synced 2025-03-09 15:40:20 +00:00

Some part of 6.1 RUTX support

This commit is contained in:
Ycarus (Yannick Chabanois) 2023-08-15 16:11:13 +02:00
parent cfce9f52b2
commit 21b307a2f6
16 changed files with 3061 additions and 370 deletions

View file

@ -38,3 +38,17 @@ is_builtin_modem() {
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 ..
}

View file

@ -3,41 +3,6 @@
. /lib/functions.sh
. /usr/share/libubox/jshn.sh
ucidef_add_nand_info() {
local model="$1"
model=${model:0:7}
json_select_object nand
case "$model" in
TRB1412)
json_add_int blocksize 128
json_add_int pagesize 2048
json_add_int subpagesize 2048
;;
TRB1422 |\
TRB1423 |\
TRB1452)
json_add_int blocksize 256
json_add_int pagesize 4096
json_add_int subpagesize 4096
;;
TRB14*0)
json_add_int blocksize 128
json_add_int pagesize 2048
json_add_int subpagesize 2048
;;
TRB14*1)
json_add_int blocksize 256
json_add_int pagesize 4096
json_add_int subpagesize 4096
;;
esac
json_select ..
}
ucidef_add_static_modem_info() {
#Parameters: model usb_id sim_count other_params
local model usb_id count
@ -74,114 +39,6 @@ ucidef_add_static_modem_info() {
json_select ..
}
ucidef_add_trb14x_lte_modem() {
print_array() {
json_add_array $1
for element in $2
do
json_add_string "" "$(echo $element)"
done
json_close_array
}
#Parameters: model primary
local model vendor product boudrate gps type desc control region modem_counter
modem_counter=1
json_select_array "modems"
model="$1"
model=${model:0:7}
case "$model" in
TRB1422)
vendor=05c6
product=9215
;;
TRB1412 |\
TRB1423 |\
TRB1452 |\
TRB140*)
vendor=2c7c
product=0125
;;
TRB14*)
vendor=2c7c
product=0121
;;
esac
case "$model" in
TRB1412 |\
TRB14*0)
region="EU"
[ "$product" = "0121" ] && {
lte_bands="1 3 7 8 20 28"
trysg_bands="wcdma_2100 wcdma_900"
dug_bands="gsm_1800 gsm_900"
}
[ "$product" = "0125" ] && {
lte_bands="1 3 7 8 20 28 38 40 41"
trysg_bands="wcdma_2100 wcdma_900"
dug_bands="gsm_1800 gsm_900"
}
;;
TRB1422)
region="CE"
lte_bands="1 3 5 8 34 38 39 40 41"
trysg_bands="bc-0-a-system bc-0-b-system wcdma_2100 wcdma_900"
dug_bands="gsm_1800 gsm_900"
;;
TRB1423 |\
TRB1452 |\
TRB14*1)
region="AU"
[ "$product" = "0121" ] && {
lte_bands="1 2 3 4 5 7 8 28 40"
trysg_bands="wcdma_2100 wcdma_1900 wcdma_900 wcdma_850"
dug_bands="gsm_1800 gsm_900 gsm_850 gsm_1900"
}
[ "$product" = "0125" ] && {
lte_bands="1 2 3 4 5 7 8 28 40"
trysg_bands="wcdma_2100 wcdma_1900 wcdma_900 wcdma_850"
dug_bands="gsm_1800 gsm_900 gsm_850 gsm_1900"
}
;;
esac
[ -f "/lib/network/wwan/$vendor:$product" ] && {
devicename="3-1"
json_set_namespace defaults old_cb
json_load "$(cat /lib/network/wwan/$vendor:$product)"
json_get_vars gps boudrate type desc control stop_bits
json_set_namespace $old_cb
[ "${devicename%%:*}" = "$devicename" ] && {
json_add_object
json_add_string id "$devicename"
json_add_string num "$modem_counter"
json_add_string vendor "$vendor"
json_add_string product "$product"
json_add_string stop_bits "$stop_bits"
json_add_string gps "$gps"
json_add_string boudrate "$boudrate"
json_add_string type "$type"
json_add_string desc "$desc"
json_add_string region "$region"
json_add_string control "$control"
json_add_int simcount 1
json_add_boolean builtin 1
[ -n "$2" ] && json_add_boolean primary 1
json_add_object service_modes
[ -z "$lte_bands" ] || print_array "4G" "$lte_bands"
[ -z "$trysg_bands" ] || print_array "3G" "$trysg_bands"
[ -z "$dug_bands" ] || print_array "2G" "$dug_bands"
json_close_object
json_close_object
}
}
json_select ..
}
ucidef_add_serial_capabilities() {
json_select_array serial
json_add_object
@ -204,81 +61,83 @@ ucidef_add_serial_capabilities() {
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 function
local dual_sim=0
local wifi=0
local dual_band_ssid=0
local wps=0
local mobile=0
local gps=0
local usb=0
local bluetooth=0
local ethernet=0
local sfp_port=0
local ios=0
for function in "$@"; do
case "$function" in
dual_sim)
dual_sim=1
;;
wifi)
wifi=1
;;
dual_band_ssid)
dual_band_ssid=1
;;
wps)
wps=1
;;
mobile)
mobile=1
;;
gps)
gps=1
;;
usb)
usb=1
;;
bluetooth)
bluetooth=1
;;
ethernet)
ethernet=1
;;
sfp_port)
sfp_port=1
;;
ios)
ios=1
;;
at_sim)
at_sim=1
;;
esac
done
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
json_add_boolean dual_sim "$dual_sim"
json_add_boolean usb "$usb"
json_add_boolean bluetooth "$bluetooth"
json_add_boolean wifi "$wifi"
json_add_boolean dual_band_ssid "$dual_band_ssid"
json_add_boolean wps "$wps"
json_add_boolean mobile "$mobile"
json_add_boolean gps "$gps"
json_add_boolean ethernet "$ethernet"
json_add_boolean sfp_port "$sfp_port"
json_add_boolean ios "$ios"
json_add_boolean at_sim "$at_sim"
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"
}

View file

@ -4,7 +4,65 @@
is_ios_enabled() {
local ios
json_load_file "/etc/board.json" && \
json_select hwinfo && \
json_get_var ios ios && [ "$ios" = "1" ]
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
}

View file

@ -40,11 +40,14 @@ ucidef_set_interface() {
local val=$1; shift
[ -n "$opt" -a -n "$val" ] || break
case "$val" in
true) json_add_boolean "$opt" "1" ;;
false) json_add_boolean "$opt" "0" ;;
*) json_add_string "$opt" "$val" ;;
esac
[ "$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
@ -59,6 +62,36 @@ ucidef_set_interface() {
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"
@ -84,11 +117,11 @@ ucidef_set_compat_version() {
}
ucidef_set_interface_lan() {
ucidef_set_interface "lan" ifname "$1" proto "${2:-static}"
ucidef_set_interface "lan" device "$1" proto "${2:-static}"
}
ucidef_set_interface_wan() {
ucidef_set_interface "wan" ifname "$1" proto "${2:-dhcp}"
ucidef_set_interface "wan" device "$1" proto "${2:-dhcp}"
}
ucidef_set_interfaces_lan_wan() {
@ -186,14 +219,14 @@ _ucidef_finish_switch_roles() {
json_select_object "$role"
# attach previous interfaces (for multi-switch devices)
json_get_var devices ifname
json_get_var devices device
if ! list_contains devices "$device"; then
devices="${devices:+$devices }$device"
fi
json_select ..
json_select ..
ucidef_set_interface "$role" ifname "$devices"
ucidef_set_interface "$role" device "$devices"
done
}
@ -210,7 +243,14 @@ ucidef_set_ar8xxx_switch_mib() {
json_select ..
}
ucidef_add_switch() {
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
@ -218,7 +258,7 @@ ucidef_add_switch() {
json_select_object switch
json_select_object "$name"
json_add_boolean enable 1
json_add_boolean enable "$enabled"
json_add_boolean reset 1
for port in "$@"; do
@ -606,6 +646,66 @@ ucidef_set_ntpserver() {
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})"