feat: scan special modem&mtk v4/v6 check support
feat: scan special modem&mtk v4/v6 check support
This commit is contained in:
commit
d813c0be80
@ -73,10 +73,16 @@ extend_prefix = s:taboption("advanced", Flag, "extend_prefix", translate("Extend
|
||||
extend_prefix.description = translate("Once checking, the prefix will be apply to lan zone")
|
||||
extend_prefix.default = "0"
|
||||
|
||||
-- 软重启
|
||||
soft_reboot = s:taboption("advanced", Flag, "soft_reboot", translate("Soft Reboot"))
|
||||
soft_reboot.description = translate("enable modem soft reboot")
|
||||
soft_reboot.default = "0"
|
||||
|
||||
-- 350 v4/v6存活检查
|
||||
mtk_check = s:taboption("advanced", Flag, "mtk_check", translate("MTK V4/V6 Check"))
|
||||
mtk_check.description = translate("Only for Fibocom MTK modem.")
|
||||
mtk_check.default = "0"
|
||||
|
||||
-- 网络类型
|
||||
pdp_type= s:taboption("advanced", ListValue, "pdp_type", translate("PDP Type"))
|
||||
pdp_type.default = "ipv4v6"
|
||||
|
@ -69,9 +69,15 @@ name.cfgvalue = function(t, n)
|
||||
return Value.cfgvalue(t, n) or "-"
|
||||
end
|
||||
|
||||
-- Soft Reboot
|
||||
soft_reboot = s:option(Flag, "soft_reboot", translate("Soft Reboot"))
|
||||
soft_reboot.default = "0"
|
||||
|
||||
-- MTK Check
|
||||
mtk_check = s:option(Flag, "mtk_check", translate("MTK V4/V6 Check"))
|
||||
mtk_check.description = translate("Only for Fibocom MTK modem.")
|
||||
mtk_check.default = "0"
|
||||
|
||||
-- PDP Context Index
|
||||
define_connect = s:option(Value, "define_connect", translate("PDP Context Index"))
|
||||
define_connect.default = "1"
|
||||
|
@ -812,5 +812,11 @@ msgstr "拨号前执行的AT命令。"
|
||||
msgid "(still in beta)"
|
||||
msgstr "(仍在测试中)"
|
||||
|
||||
msgid “(beta)"
|
||||
msgid "(beta)"
|
||||
msgstr "(测试)"
|
||||
|
||||
msgid "MTK V4/V6 Check"
|
||||
msgstr "MTK V4/V6 存活检测"
|
||||
|
||||
msgid "Only for Fibocom MTK modem."
|
||||
msgstr "只适用于广和通MTK模组。"
|
@ -812,5 +812,11 @@ msgstr "拨号前执行的AT命令。"
|
||||
msgid "(still in beta)"
|
||||
msgstr "(仍在测试中)"
|
||||
|
||||
msgid “(beta)"
|
||||
msgid "(beta)"
|
||||
msgstr "(测试)"
|
||||
|
||||
msgid "MTK V4/V6 Check"
|
||||
msgstr "MTK V4/V6 存活检测"
|
||||
|
||||
msgid "Only for Fibocom MTK modem."
|
||||
msgstr "只适用于广和通MTK模组。"
|
@ -114,6 +114,7 @@ update_config()
|
||||
config_get en_bridge $modem_config en_bridge
|
||||
config_get do_not_add_dns $modem_config do_not_add_dns
|
||||
config_get dns_list $modem_config dns_list
|
||||
[ "$manufacturer" == "fibocom" ] && [ "$platform" == "mediatek" ] && config_get mtk_check $modem_config mtk_check
|
||||
config_get global_dial main enable_dial
|
||||
# config_get ethernet_5g u$modem_config ethernet 转往口获取命令更新,待测试
|
||||
config_foreach get_associate_ethernet_by_path modem-slot
|
||||
@ -263,14 +264,6 @@ check_ip()
|
||||
fi
|
||||
|
||||
if [ -n "$ipaddr" ];then
|
||||
if [ $mtk -eq 1 ] && echo "$ipv4_config" | grep -qE '^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$'; then
|
||||
if [ "$pdp_type" = "ipv4v6" ];then
|
||||
if ! ping -c 2 -w 5 2400:3200::1 > /dev/null 2>&1; then
|
||||
m_debug "ipv6 is down,try to restart"
|
||||
ifdown "$interface6_name" && sleep 2 && ifup "$interface6_name"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
ipv6=$(echo $ipaddr | grep -oE "\b([0-9a-fA-F]{0,4}:){2,7}[0-9a-fA-F]{0,4}\b")
|
||||
ipv4=$(echo $ipaddr | grep -oE "\b([0-9]{1,3}\.){3}[0-9]{1,3}\b")
|
||||
if [ "$manufacturer" = "simcom" ];then
|
||||
@ -298,6 +291,84 @@ check_ip()
|
||||
fi
|
||||
}
|
||||
|
||||
check_mtk_connection()
|
||||
{
|
||||
local lock_file="${MODEM_RUNDIR}/${modem_config}_dir/mtk_check.lock"
|
||||
local result_file="${MODEM_RUNDIR}/${modem_config}_dir/mtk_check_result"
|
||||
|
||||
if [ -f "$lock_file" ]; then
|
||||
local lock_time=$(stat -c %Y "$lock_file" 2>/dev/null || echo 0)
|
||||
local current_time=$(cat /proc/uptime | awk '{print int($1)}')
|
||||
if [ $((current_time - lock_time)) -lt 5 ]; then
|
||||
return 0
|
||||
else
|
||||
rm -f "$lock_file"
|
||||
fi
|
||||
fi
|
||||
|
||||
touch "$lock_file"
|
||||
|
||||
(
|
||||
if [ "$mtk" -eq 1 ] && [ -n "$ipv4" ] && [ -n "$modem_netcard" ]; then
|
||||
local test=0
|
||||
|
||||
if ping -I "$modem_netcard" -c 1 -w 2 1.1.1.1 > /dev/null 2>&1; then
|
||||
test=1
|
||||
elif ping -I "$modem_netcard" -c 1 -w 2 8.8.8.8 > /dev/null 2>&1; then
|
||||
test=1
|
||||
elif [ -n "$gateway" ] && ping -I "$modem_netcard" -c 1 -w 2 "$gateway" > /dev/null 2>&1; then
|
||||
test=1
|
||||
fi
|
||||
|
||||
if [ "$test" -eq 0 ]; then
|
||||
m_debug "IPv4 connection test failed, will redial"
|
||||
echo "failed" > "$result_file"
|
||||
rm -f "$lock_file"
|
||||
return 1
|
||||
fi
|
||||
|
||||
local ifup_time=$(ubus call network.interface.$interface6_name status 2>/dev/null | jsonfilter -e '@.uptime' 2>/dev/null || echo 0)
|
||||
if [ -n "$ifup_time" ] && [ "$ifup_time" -gt 10 ] && { [ "$pdp_type" = "ipv4v6" ] || [ "$pdp_type" = "IPV4V6" ]; } && [ -n "$ipv6" ]; then
|
||||
local ipv6_test=0
|
||||
|
||||
if ping6 -I "$modem_netcard" -c 1 -w 2 2400:3200::1 > /dev/null 2>&1; then
|
||||
ipv6_test=1
|
||||
elif ping6 -I "$modem_netcard" -c 1 -w 2 2001:4860:4860::8888 > /dev/null 2>&1; then
|
||||
ipv6_test=1
|
||||
fi
|
||||
|
||||
if [ "$ipv6_test" -eq 0 ]; then
|
||||
m_debug "IPv6 connection test failed, restarting IPv6 interface"
|
||||
if [ -n "$interface6_name" ]; then
|
||||
ifdown "$interface6_name" && sleep 2 && ifup "$interface6_name"
|
||||
m_debug "Restarted IPv6 interface $interface6_name"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "success" > "$result_file"
|
||||
else
|
||||
echo "skipped" > "$result_file"
|
||||
fi
|
||||
|
||||
rm -f "$lock_file"
|
||||
) &
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
read_mtk_check_result()
|
||||
{
|
||||
local result_file="${MODEM_RUNDIR}/${modem_config}_dir/mtk_check_result"
|
||||
if [ -f "$result_file" ]; then
|
||||
local result=$(cat "$result_file")
|
||||
if [ "$result" = "failed" ]; then
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
append_to_fw_zone()
|
||||
{
|
||||
local fw_zone=$1
|
||||
@ -974,6 +1045,7 @@ at_dial_monitor()
|
||||
check_ip
|
||||
at_dial
|
||||
ipv4_cache=$ipv4
|
||||
last_mtk_check=0
|
||||
while true; do
|
||||
check_ip
|
||||
if [ $connection_status -eq 0 ];then
|
||||
@ -987,13 +1059,32 @@ at_dial_monitor()
|
||||
fi
|
||||
sleep 10
|
||||
else
|
||||
#检测ipv4是否变化
|
||||
sleep 15
|
||||
if [ "$ipv4" != "$ipv4_cache" ];then
|
||||
check_mtk_if_needed() {
|
||||
if [ "$mtk_check" = "1" ]; then
|
||||
current_time=$(cat /proc/uptime | awk '{print int($1)}')
|
||||
if [ "$mtk" -eq 1 ]; then
|
||||
check_mtk_connection
|
||||
read_mtk_check_result
|
||||
if [ $? -eq 1 ]; then
|
||||
at_dial
|
||||
fi
|
||||
last_mtk_check=$current_time
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
if [ "$ipv4" != "$ipv4_cache" ]; then
|
||||
handle_ip_change
|
||||
ipv6_cache=$ipv6
|
||||
ipv4_cache=$ipv4
|
||||
continue
|
||||
fi
|
||||
sleep 5
|
||||
check_mtk_if_needed
|
||||
sleep 5
|
||||
check_mtk_if_needed
|
||||
sleep 5
|
||||
check_mtk_if_needed
|
||||
fi
|
||||
check_logfile_line
|
||||
done
|
||||
|
@ -0,0 +1,38 @@
|
||||
{
|
||||
"modem_port_rule": {
|
||||
"usb": {
|
||||
"305a:1421": {
|
||||
"name": "gm800",
|
||||
"mode": "qmi",
|
||||
"option_driver": 1,
|
||||
"include": [
|
||||
"1.1"
|
||||
]
|
||||
},
|
||||
"305a:1404": {
|
||||
"name": "gm800",
|
||||
"mode": "rndis",
|
||||
"option_driver": 0,
|
||||
"include": [
|
||||
"1.1"
|
||||
]
|
||||
},
|
||||
"2dee:4d23": {
|
||||
"name": "srm825xeu",
|
||||
"mode": "ecm",
|
||||
"option_driver": 1,
|
||||
"include": [
|
||||
"1.1"
|
||||
]
|
||||
},
|
||||
"2dee:4d38": {
|
||||
"name": "srm825xeu",
|
||||
"mode": "rndis",
|
||||
"option_driver": 1,
|
||||
"include": [
|
||||
"1.3"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -4,6 +4,7 @@ action=$1
|
||||
config=$2
|
||||
slot_type=$3
|
||||
modem_support=$(cat /usr/share/qmodem/modem_support.json)
|
||||
modem_port_rule=$(cat /usr/share/qmodem/modem_port_rule.json)
|
||||
debug_subject="modem_scan"
|
||||
source /lib/functions.sh
|
||||
source /usr/share/qmodem/modem_util.sh
|
||||
@ -183,7 +184,7 @@ scan_pcie_slot_interfaces()
|
||||
dun_devices=$(ls "$devices_path" | grep -E "wwan[0-9]at[0-9]")
|
||||
fi
|
||||
fi
|
||||
echo "net_devices: $net_devices dun_devices: $dun_devices"
|
||||
m_debug "net_devices: $net_devices dun_devices: $dun_devices"
|
||||
at_ports="$dun_devices"
|
||||
[ -n "$net_devices" ] && get_associate_usb $slot
|
||||
if [ -n "$associated_usb" ] && [ -d "/sys/bus/usb/devices/$associated_usb" ]; then
|
||||
@ -225,6 +226,34 @@ scan_usb_slot_interfaces()
|
||||
net_devices=""
|
||||
tty_devices=""
|
||||
[ ! -d "$slot_path" ] && return
|
||||
|
||||
slot_vid=$(cat "$slot_path/idVendor" 2>/dev/null || echo "")
|
||||
slot_pid=$(cat "$slot_path/idProduct" 2>/dev/null || echo "")
|
||||
|
||||
# m_debug "($slot_vid:$slot_pid) $slot_path"
|
||||
|
||||
if [ -n "$slot_vid" ] && [ -n "$slot_pid" ]; then
|
||||
modem_port_config=$(echo $modem_port_rule | jq '.modem_port_rule."'$slot_type'"."'$slot_vid:$slot_pid'"')
|
||||
if [ "$modem_port_config" != "null" ] && [ -n "$modem_port_config" ]; then
|
||||
config_modem_name=$(echo $modem_port_config | jq -r '.name' 2>/dev/null || echo "")
|
||||
include_ports=$(echo $modem_port_config | jq -r '.include[]' 2>/dev/null || echo "")
|
||||
option_driver=$(echo $modem_port_config | jq -r '.option_driver' 2>/dev/null || echo "0")
|
||||
|
||||
if [ -n "$include_ports" ]; then
|
||||
include_mode=1
|
||||
m_debug "using special config for $config_modem_name($slot_vid:$slot_pid) with ports: $include_ports"
|
||||
fi
|
||||
fi
|
||||
else
|
||||
m_debug "Unable to read VID/PID from device path: $slot_path"
|
||||
fi
|
||||
|
||||
if [ "$option_driver" = "1" ] && [ -n "$slot_vid" ] && [ -n "$slot_pid" ]; then
|
||||
if ! echo "$slot_vid $slot_pid" > /sys/bus/usb-serial/drivers/option1/new_id 2>/dev/null; then
|
||||
m_debug "failed to set option driver"
|
||||
fi
|
||||
fi
|
||||
|
||||
local slot_interfaces=$(ls $slot_path | grep -E "$slot:[0-9]\.[0-9]+")
|
||||
for interface in $slot_interfaces; do
|
||||
unset device
|
||||
@ -234,6 +263,9 @@ scan_usb_slot_interfaces()
|
||||
[ ! -d "$interface_driver_path" ] && continue
|
||||
interface_driver=$(basename $(readlink $interface_driver_path))
|
||||
[ -z "$interface_driver" ] && continue
|
||||
|
||||
local if_port=$(echo "$interface" | grep -oE "[0-9]+\.[0-9]+$" || echo "")
|
||||
|
||||
case $interface_driver in
|
||||
option|\
|
||||
cdc_acm|\
|
||||
@ -244,7 +276,22 @@ scan_usb_slot_interfaces()
|
||||
[ -z "$ttyUSB_device" ] && [ -z "$ttyACM_device" ] && continue
|
||||
[ -n "$ttyUSB_device" ] && device="$ttyUSB_device"
|
||||
[ -n "$ttyACM_device" ] && device="$ttyACM_device"
|
||||
[ -z "$tty_devices" ] && tty_devices="$device" || tty_devices="$tty_devices $device"
|
||||
|
||||
local should_include=1
|
||||
|
||||
if [ $include_mode -eq 1 ]; then
|
||||
should_include=0
|
||||
for included_port in $include_ports; do
|
||||
if [ -n "$if_port" ] && [ "$included_port" = "$if_port" ]; then
|
||||
should_include=1
|
||||
break
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
if [ $should_include -eq 1 ]; then
|
||||
[ -z "$tty_devices" ] && tty_devices="$device" || tty_devices="$tty_devices $device"
|
||||
fi
|
||||
;;
|
||||
qmi_wwan*|\
|
||||
cdc_mbim|\
|
||||
|
Loading…
x
Reference in New Issue
Block a user