diff --git a/luci/luci-app-qmodem/luasrc/model/cbi/qmodem/dial_config.lua b/luci/luci-app-qmodem/luasrc/model/cbi/qmodem/dial_config.lua index 59f49ed..a9727c8 100644 --- a/luci/luci-app-qmodem/luasrc/model/cbi/qmodem/dial_config.lua +++ b/luci/luci-app-qmodem/luasrc/model/cbi/qmodem/dial_config.lua @@ -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" diff --git a/luci/luci-app-qmodem/luasrc/model/cbi/qmodem/modem_config.lua b/luci/luci-app-qmodem/luasrc/model/cbi/qmodem/modem_config.lua index 2906ebb..15053fe 100644 --- a/luci/luci-app-qmodem/luasrc/model/cbi/qmodem/modem_config.lua +++ b/luci/luci-app-qmodem/luasrc/model/cbi/qmodem/modem_config.lua @@ -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" diff --git a/luci/luci-app-qmodem/po/zh-cn/qmodem.po b/luci/luci-app-qmodem/po/zh-cn/qmodem.po index 9f60990..f965a78 100644 --- a/luci/luci-app-qmodem/po/zh-cn/qmodem.po +++ b/luci/luci-app-qmodem/po/zh-cn/qmodem.po @@ -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模组。" \ No newline at end of file diff --git a/luci/luci-app-qmodem/po/zh_Hans/qmodem.po b/luci/luci-app-qmodem/po/zh_Hans/qmodem.po index 9f60990..f965a78 100644 --- a/luci/luci-app-qmodem/po/zh_Hans/qmodem.po +++ b/luci/luci-app-qmodem/po/zh_Hans/qmodem.po @@ -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模组。" \ No newline at end of file diff --git a/luci/luci-app-qmodem/root/usr/share/qmodem/modem_dial.sh b/luci/luci-app-qmodem/root/usr/share/qmodem/modem_dial.sh index 7f52306..5e1ada1 100755 --- a/luci/luci-app-qmodem/root/usr/share/qmodem/modem_dial.sh +++ b/luci/luci-app-qmodem/root/usr/share/qmodem/modem_dial.sh @@ -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