From 71c8a39a6ec18ef7776eb6750943cc1dc2e1d51c Mon Sep 17 00:00:00 2001 From: fujr Date: Tue, 23 Jul 2024 15:19:17 +0800 Subject: [PATCH] update to version 2.0 --- luci-app-modem-hc/Makefile | 22 + .../luasrc/controller/modem_hc.lua | 82 + .../luasrc/model/cbi/modem_hc/modem_sim.lua | 29 + .../luasrc/view/modem_hc/modem_sim.htm | 64 + luci-app-modem-hc/po/zh-cn/modem_hc.po | 21 + luci-app-modem-hc/po/zh_Hans/modem_hc.po | 21 + luci-app-modem-hc/root/etc/config/modem_sim | 4 + luci-app-modem-hc/root/etc/init.d/modem_sim | 35 + .../root/usr/share/modem/modem_sim.sh | 183 ++ luci-app-modem-mwan-single-module/Makefile | 22 + .../luasrc/controller/modem_mwan.lua | 9 + .../luasrc/model/cbi/modem/mwan_config.lua | 0 .../po/zh-cn/modem_mwan.po | 12 + .../po/zh_Hans/modem_mwan.po | 12 + .../root/etc/config/modem_mwan | 2 +- .../root/etc/init.d/modem_mwan | 5 + .../root/usr/share/modem/modem_mwan.sh | 0 luci-app-modem-mwan/Makefile | 22 + .../luasrc/controller/modem_mwan.lua | 9 + .../luasrc/model/cbi/modem/mwan_config.lua | 48 + luci-app-modem-mwan/po/zh-cn/modem_mwan.po | 24 + luci-app-modem-mwan/po/zh_Hans/modem_mwan.po | 24 + .../root/etc/config/modem_mwan | 29 + .../root/etc/init.d/modem_mwan | 35 + .../root/usr/share/modem/modem_mwan.sh | 158 + luci-app-modem-sms/Makefile | 17 + .../luasrc/controller/modem_sms.lua | 51 + .../luasrc/view/modem_sms/modem_sms.htm | 908 ++++++ luci-app-modem-sms/po/zh-cn/modem_sms.po | 27 + luci-app-modem-sms/po/zh_Hans/modem_sms.po | 33 + luci-app-modem-ttl/Makefile | 22 + .../luasrc/controller/modem_ttl.lua | 8 + .../luasrc/model/cbi/modem/modem_ttl.lua | 18 + luci-app-modem-ttl/root/etc/config/modem_ttl | 1 + luci-app-modem-ttl/root/etc/init.d/modem_ttl | 65 + luci-app-modem/Makefile | 8 +- .../luci-static/resources/icons/sms.png | Bin 9221 -> 0 bytes .../luci-static/resources/icons/sms2.png | Bin 1365 -> 0 bytes .../resources/view/status/include/11_modem.js | 92 + luci-app-modem/luasrc/controller/modem.lua | 1083 +------ .../luasrc/model/cbi/modem/dial_config.lua | 122 +- .../luasrc/model/cbi/modem/dial_overview.lua | 81 +- .../luasrc/model/cbi/modem/modem_config.lua | 162 -- .../luasrc/model/cbi/modem/plugin_config.lua | 78 - .../model/cbi/modem/quick_commands_config.lua | 30 - .../luasrc/view/modem/at_command_old.htm | 290 -- .../luasrc/view/modem/dial_overview.htm | 351 +++ .../luasrc/view/modem/hide_dial_config_id.htm | 20 - .../view/modem/hide_manual_config_modem.htm | 19 - .../luasrc/view/modem/list_status.htm | 19 - .../luasrc/view/modem/mode_info.htm | 51 - .../luasrc/view/modem/modem_debug.htm | 2566 ++++++----------- .../luasrc/view/modem/modem_debug_new.htm | 509 ---- .../luasrc/view/modem/modem_dial_log.htm | 283 -- .../luasrc/view/modem/modem_info.htm | 1254 +++----- .../luasrc/view/modem/modem_status.htm | 160 - .../luasrc/view/modem/plugin_info.htm | 276 -- luci-app-modem/luasrc/view/modem/status.htm | 3 - .../luasrc/view/modem/tblsection.htm | 203 -- .../luasrc/view/modem/tblsection_command.htm | 208 -- luci-app-modem/po/ru/modem.po | 263 ++ luci-app-modem/po/zh-cn/modem.po | 128 +- luci-app-modem/po/zh_Hans/modem.po | 136 +- luci-app-modem/quickinstall.sh | 6 + .../root/etc/config/custom_at_commands | 332 --- luci-app-modem/root/etc/config/modem | 272 -- .../root/etc/hotplug.d/net/20-modem-net | 40 +- .../root/etc/hotplug.d/usb/20-modem-usb | 30 +- luci-app-modem/root/etc/init.d/modem_init | 45 + luci-app-modem/root/etc/init.d/modem_network | 41 +- luci-app-modem/root/etc/init.d/modem_scan | 21 - .../root/etc/uci-defaults/99-add-5g-handler | 69 + .../root/usr/libexec/rpcd/modem_ctrl | 79 + .../root/usr/share/modem/fibocom.sh | 1362 ++++----- .../root/usr/share/modem/generic.sh | 288 ++ luci-app-modem/root/usr/share/modem/meig.sh | 835 ------ .../root/usr/share/modem/modem_at.sh | 11 - .../root/usr/share/modem/modem_ctrl.sh | 171 ++ .../root/usr/share/modem/modem_debug.sh | 77 - .../root/usr/share/modem/modem_dial.sh | 398 ++- .../root/usr/share/modem/modem_info.sh | 407 --- .../root/usr/share/modem/modem_init.sh | 23 - .../usr/share/modem/modem_network_task.sh | 301 -- .../root/usr/share/modem/modem_scan.sh | 350 ++- .../root/usr/share/modem/modem_support.json | 32 + .../root/usr/share/modem/modem_task.sh | 25 - .../root/usr/share/modem/modem_util.sh | 1021 +------ .../root/usr/share/modem/quectel.sh | 1761 +++++------ luci-app-modem/root/usr/share/modem/simcom.sh | 303 -- .../root/usr/share/modem/usb_modem_scan.sh | 5 - .../usr/share/rpcd/acl.d/luci-app-modem.json | 8 + 91 files changed, 7217 insertions(+), 11513 deletions(-) create mode 100644 luci-app-modem-hc/Makefile create mode 100644 luci-app-modem-hc/luasrc/controller/modem_hc.lua create mode 100644 luci-app-modem-hc/luasrc/model/cbi/modem_hc/modem_sim.lua create mode 100644 luci-app-modem-hc/luasrc/view/modem_hc/modem_sim.htm create mode 100644 luci-app-modem-hc/po/zh-cn/modem_hc.po create mode 100644 luci-app-modem-hc/po/zh_Hans/modem_hc.po create mode 100755 luci-app-modem-hc/root/etc/config/modem_sim create mode 100755 luci-app-modem-hc/root/etc/init.d/modem_sim create mode 100755 luci-app-modem-hc/root/usr/share/modem/modem_sim.sh create mode 100644 luci-app-modem-mwan-single-module/Makefile create mode 100644 luci-app-modem-mwan-single-module/luasrc/controller/modem_mwan.lua rename {luci-app-modem => luci-app-modem-mwan-single-module}/luasrc/model/cbi/modem/mwan_config.lua (100%) create mode 100644 luci-app-modem-mwan-single-module/po/zh-cn/modem_mwan.po create mode 100644 luci-app-modem-mwan-single-module/po/zh_Hans/modem_mwan.po rename {luci-app-modem => luci-app-modem-mwan-single-module}/root/etc/config/modem_mwan (86%) rename {luci-app-modem => luci-app-modem-mwan-single-module}/root/etc/init.d/modem_mwan (95%) rename {luci-app-modem => luci-app-modem-mwan-single-module}/root/usr/share/modem/modem_mwan.sh (100%) create mode 100644 luci-app-modem-mwan/Makefile create mode 100644 luci-app-modem-mwan/luasrc/controller/modem_mwan.lua create mode 100644 luci-app-modem-mwan/luasrc/model/cbi/modem/mwan_config.lua create mode 100644 luci-app-modem-mwan/po/zh-cn/modem_mwan.po create mode 100644 luci-app-modem-mwan/po/zh_Hans/modem_mwan.po create mode 100644 luci-app-modem-mwan/root/etc/config/modem_mwan create mode 100755 luci-app-modem-mwan/root/etc/init.d/modem_mwan create mode 100755 luci-app-modem-mwan/root/usr/share/modem/modem_mwan.sh create mode 100644 luci-app-modem-sms/Makefile create mode 100644 luci-app-modem-sms/luasrc/controller/modem_sms.lua create mode 100644 luci-app-modem-sms/luasrc/view/modem_sms/modem_sms.htm create mode 100644 luci-app-modem-sms/po/zh-cn/modem_sms.po create mode 100644 luci-app-modem-sms/po/zh_Hans/modem_sms.po create mode 100644 luci-app-modem-ttl/Makefile create mode 100644 luci-app-modem-ttl/luasrc/controller/modem_ttl.lua create mode 100644 luci-app-modem-ttl/luasrc/model/cbi/modem/modem_ttl.lua create mode 100644 luci-app-modem-ttl/root/etc/config/modem_ttl create mode 100755 luci-app-modem-ttl/root/etc/init.d/modem_ttl delete mode 100644 luci-app-modem/htdocs/luci-static/resources/icons/sms.png delete mode 100644 luci-app-modem/htdocs/luci-static/resources/icons/sms2.png create mode 100644 luci-app-modem/htdocs/luci-static/resources/view/status/include/11_modem.js delete mode 100644 luci-app-modem/luasrc/model/cbi/modem/modem_config.lua delete mode 100644 luci-app-modem/luasrc/model/cbi/modem/plugin_config.lua delete mode 100644 luci-app-modem/luasrc/model/cbi/modem/quick_commands_config.lua delete mode 100644 luci-app-modem/luasrc/view/modem/at_command_old.htm create mode 100644 luci-app-modem/luasrc/view/modem/dial_overview.htm delete mode 100644 luci-app-modem/luasrc/view/modem/hide_dial_config_id.htm delete mode 100644 luci-app-modem/luasrc/view/modem/hide_manual_config_modem.htm delete mode 100644 luci-app-modem/luasrc/view/modem/list_status.htm delete mode 100644 luci-app-modem/luasrc/view/modem/mode_info.htm delete mode 100644 luci-app-modem/luasrc/view/modem/modem_debug_new.htm delete mode 100644 luci-app-modem/luasrc/view/modem/modem_dial_log.htm delete mode 100644 luci-app-modem/luasrc/view/modem/modem_status.htm delete mode 100644 luci-app-modem/luasrc/view/modem/plugin_info.htm delete mode 100644 luci-app-modem/luasrc/view/modem/status.htm delete mode 100644 luci-app-modem/luasrc/view/modem/tblsection.htm delete mode 100644 luci-app-modem/luasrc/view/modem/tblsection_command.htm create mode 100644 luci-app-modem/po/ru/modem.po create mode 100755 luci-app-modem/quickinstall.sh delete mode 100644 luci-app-modem/root/etc/config/custom_at_commands mode change 100644 => 100755 luci-app-modem/root/etc/hotplug.d/net/20-modem-net mode change 100644 => 100755 luci-app-modem/root/etc/hotplug.d/usb/20-modem-usb create mode 100755 luci-app-modem/root/etc/init.d/modem_init delete mode 100755 luci-app-modem/root/etc/init.d/modem_scan create mode 100755 luci-app-modem/root/etc/uci-defaults/99-add-5g-handler create mode 100755 luci-app-modem/root/usr/libexec/rpcd/modem_ctrl create mode 100755 luci-app-modem/root/usr/share/modem/generic.sh delete mode 100755 luci-app-modem/root/usr/share/modem/meig.sh delete mode 100755 luci-app-modem/root/usr/share/modem/modem_at.sh create mode 100755 luci-app-modem/root/usr/share/modem/modem_ctrl.sh delete mode 100755 luci-app-modem/root/usr/share/modem/modem_debug.sh delete mode 100755 luci-app-modem/root/usr/share/modem/modem_info.sh delete mode 100644 luci-app-modem/root/usr/share/modem/modem_init.sh delete mode 100755 luci-app-modem/root/usr/share/modem/modem_network_task.sh delete mode 100755 luci-app-modem/root/usr/share/modem/modem_task.sh delete mode 100755 luci-app-modem/root/usr/share/modem/simcom.sh delete mode 100755 luci-app-modem/root/usr/share/modem/usb_modem_scan.sh diff --git a/luci-app-modem-hc/Makefile b/luci-app-modem-hc/Makefile new file mode 100644 index 0000000..6439479 --- /dev/null +++ b/luci-app-modem-hc/Makefile @@ -0,0 +1,22 @@ +# Copyright (C) 2024 Tom +# This is free software, licensed under the GNU General Public License v3. + +include $(TOPDIR)/rules.mk + +PKG_NAME:=luci-app-5gmodem-hc +LUCI_TITLE:=hc-g50 sim switch +LUCI_PKGARCH:=all +PKG_VERSION:=2.0 +PKG_LICENSE:=GPLv3 +PKG_LINCESE_FILES:=LICENSE +PKF_MAINTAINER:=fujr +LUCI_DEPENDS:=+luci-app-5gmodem + + +define Package/luci-app-5gmodem-hc/conffiles +/etc/config/modem_sim +endef + +include $(TOPDIR)/feeds/luci/luci.mk + +# call BuildPackage - OpenWrt buildroot signature diff --git a/luci-app-modem-hc/luasrc/controller/modem_hc.lua b/luci-app-modem-hc/luasrc/controller/modem_hc.lua new file mode 100644 index 0000000..236e237 --- /dev/null +++ b/luci-app-modem-hc/luasrc/controller/modem_hc.lua @@ -0,0 +1,82 @@ +module("luci.controller.modem_hc", package.seeall) +local http = require "luci.http" +local fs = require "nixio.fs" +local json = require("luci.jsonc") +function index() + --sim卡配置 + entry({"admin", "network", "modem", "modem_sim"}, cbi("modem_hc/modem_sim"), luci.i18n.translate("SIM Config"), 23).leaf = true + entry({"admin", "network", "modem", "set_sim"}, call("setSIM"), nil).leaf = true + entry({"admin", "network", "modem", "get_sim"}, call("getSIM"), nil).leaf = true +end + +function getSimSlot(sim_path) + local sim_slot = fs.readfile(sim_path) + local current_slot = string.match(sim_slot, "%d") + if current_slot == "0" then + return "SIM2" + else + return "SIM1" + end +end + +function shell(command) + local odpall = io.popen(command) + local odp = odpall:read("*a") + odpall:close() + return odp +end + + +function getNextBootSlot() + local fw_print_cmd = "fw_printenv -n sim2" + local nextboot_slot = shell(fw_print_cmd) + if nextboot_slot == "" then + return "SIM1" + else + return "SIM2" + end +end + +function writeJsonResponse(current_slot, nextboot_slot) + local result_json = {} + result_json["current_slot"] = current_slot + result_json["nextboot_slot"] = nextboot_slot + luci.http.prepare_content("application/json") + luci.http.write_json(result_json) +end + +function getSIM() + local sim_path = "/sys/class/gpio/sim/value" + local current_slot = getSimSlot(sim_path) + local nextboot_slot = getNextBootSlot() + writeJsonResponse(current_slot, nextboot_slot) +end + +function setSIM() + local sim_gpio = "/sys/class/gpio/sim/value" + local modem_gpio = "/sys/class/gpio/4g/value" + local sim_slot = http.formvalue("slot") + local pre_detect = getSimSlot(sim_gpio) + + local reset_module = 1 + if pre_detect == sim_slot then + reset_module = 0 + end + if sim_slot == "SIM1" then + sysfs_cmd = "echo 1 >"..sim_gpio + fw_setenv_cmd = "fw_setenv sim2" + elseif sim_slot == "SIM2" then + sysfs_cmd = "echo 0 >"..sim_gpio + fw_setenv_cmd = "fw_setenv sim2 1" + end + shell(sysfs_cmd) + shell(fw_setenv_cmd) + if reset_module == 1 then + shell("echo 0 >"..modem_gpio) + os.execute("sleep 1") + shell("echo 1 >"..modem_gpio) + end + local current_slot = getSimSlot(sim_gpio) + local nextboot_slot = getNextBootSlot() + writeJsonResponse(current_slot, nextboot_slot) +end diff --git a/luci-app-modem-hc/luasrc/model/cbi/modem_hc/modem_sim.lua b/luci-app-modem-hc/luasrc/model/cbi/modem_hc/modem_sim.lua new file mode 100644 index 0000000..3512ed2 --- /dev/null +++ b/luci-app-modem-hc/luasrc/model/cbi/modem_hc/modem_sim.lua @@ -0,0 +1,29 @@ +m = Map("modem_sim", translate("SIM Settings")) +s = m:section(TypedSection, "global", translate("SIM Settings")) +s.anonymous = true +s.addremove = false + + + +sim_auto_switch = s:option(Flag, "sim_auto_switch", translate("SIM Auto Switch")) +sim_auto_switch.default = "0" + +detect_interval = s:option(Value, "detect_interval", translate("Network Detect Interval")) +detect_interval.default = 15 + +judge_time = s:option(Value, "judge_time", translate("Network Down Judge Times")) +judge_time.default = 5 + +ping_dest = s:option(DynamicList, "ping_dest", translate("Ping Destination")) + +o = s:option(Value, "wwan_ifname", translate("WWAN Interface")) +o.description = translate("Please enter the WWAN interface name") +o.template = "cbi/network_netlist" +-- o.widget = "optional" +o.nocreate = true + +o.default = "cpewan0" + +m:section(SimpleSection).template = "modem_hc/modem_sim" + +return m diff --git a/luci-app-modem-hc/luasrc/view/modem_hc/modem_sim.htm b/luci-app-modem-hc/luasrc/view/modem_hc/modem_sim.htm new file mode 100644 index 0000000..9292199 --- /dev/null +++ b/luci-app-modem-hc/luasrc/view/modem_hc/modem_sim.htm @@ -0,0 +1,64 @@ + + + +
+ + + + + + + + + + + + + +
+ <%:SIM Slot%>|<%:Now%> + + <%:SIM Slot%>|<%:Next Boot%> + + <%:SIM Slot%>|<%:Setting%> +
+ + + + + +
+ + +
diff --git a/luci-app-modem-hc/po/zh-cn/modem_hc.po b/luci-app-modem-hc/po/zh-cn/modem_hc.po new file mode 100644 index 0000000..3b84ed0 --- /dev/null +++ b/luci-app-modem-hc/po/zh-cn/modem_hc.po @@ -0,0 +1,21 @@ +#view/modem_sim.htm +msgid "SIM Slot" +msgstr "SIM卡卡槽" + +msgid "Now" +msgstr "当前" + +msgid "Next Boot" +msgstr "下次启动" + +msgid "Setting' +msgstr "设置" + +msgid "SIM1 (Close to power)" +msgstr "SIM1 (靠近电源)" + +msgid "SIM2 (Away from power)" +msgstr "SIM2 (远离电源)" + +msgid "Set SIM" +msgstr "设置SIM卡" diff --git a/luci-app-modem-hc/po/zh_Hans/modem_hc.po b/luci-app-modem-hc/po/zh_Hans/modem_hc.po new file mode 100644 index 0000000..3b84ed0 --- /dev/null +++ b/luci-app-modem-hc/po/zh_Hans/modem_hc.po @@ -0,0 +1,21 @@ +#view/modem_sim.htm +msgid "SIM Slot" +msgstr "SIM卡卡槽" + +msgid "Now" +msgstr "当前" + +msgid "Next Boot" +msgstr "下次启动" + +msgid "Setting' +msgstr "设置" + +msgid "SIM1 (Close to power)" +msgstr "SIM1 (靠近电源)" + +msgid "SIM2 (Away from power)" +msgstr "SIM2 (远离电源)" + +msgid "Set SIM" +msgstr "设置SIM卡" diff --git a/luci-app-modem-hc/root/etc/config/modem_sim b/luci-app-modem-hc/root/etc/config/modem_sim new file mode 100755 index 0000000..bd18184 --- /dev/null +++ b/luci-app-modem-hc/root/etc/config/modem_sim @@ -0,0 +1,4 @@ +config global + option sim_auto_switch '1' + option detect_interval '15' + option judge_time '5' diff --git a/luci-app-modem-hc/root/etc/init.d/modem_sim b/luci-app-modem-hc/root/etc/init.d/modem_sim new file mode 100755 index 0000000..d1155f2 --- /dev/null +++ b/luci-app-modem-hc/root/etc/init.d/modem_sim @@ -0,0 +1,35 @@ +#!/bin/sh /etc/rc.common +USE_PROCD=1 +START=99 +STOP=10 +PROG="/usr/share/modem/modem_sim.sh" +start_service() { + local sim_auto_switch=$(uci -q get modem_sim.@global[0].sim_auto_switch) + logger -t modem_sim start_service $sim_auto_switch + if [ "$sim_auto_switch" == 1 ];then + start_instace + else + stop_service + fi +} + +start_instace(){ + procd_open_instance "$PROG" + procd_set_param command /usr/share/modem/modem_sim.sh + procd_close_instance + logger -t modem_sim running +} + +reload_service() { + stop + start +} + +stop_service() { + logger -t modem_sim stop_service + service_stop "$PROG" +} + +service_triggers() { + procd_add_reload_trigger 'modem_sim' +} diff --git a/luci-app-modem-hc/root/usr/share/modem/modem_sim.sh b/luci-app-modem-hc/root/usr/share/modem/modem_sim.sh new file mode 100755 index 0000000..548b617 --- /dev/null +++ b/luci-app-modem-hc/root/usr/share/modem/modem_sim.sh @@ -0,0 +1,183 @@ +#!/bin/sh +sim_gpio="/sys/class/gpio/sim/value" +modem_gpio="/sys/class/gpio/4g/value" +ping_dest=$(uci -q get modem_sim.@global[0].ping_dest) +wwan_ifname=$(uci -q get modem_sim.@global[0].wwan_ifname) +[ -n $wwan_ifname ] && modem_config=$wwan_ifname +is_empty=$(uci -q get modem.$modem_config) +[ -z $is_empty ] && unset modem_config +[ -z "$modem_config" ] && get_first_avalible_config +netdev=$(ifstatus $wwan_ifname | jq -r .device) +judge_time=$(uci -q get modem_sim.@global[0].judge_time) +detect_interval=$(uci -q get modem_sim.@global[0].detect_interval) +[ -z $detect_interval ] && detect_interval=10 +[ -z $judge_time ] && judge_time=5 + +set_modem_config() +{ + cfg=$1 + [ -n "$modem_config" ] && return + config_get state $1 state + [ -n "$state" ] && [ "$state" != "disabled" ] && modem_config=$cfg +} + +get_first_avalible_config() +{ + . /lib/functions.sh + config_load modem + config_foreach set_modem_config modem-device +} + +sendat() +{ + tty=$1 + cmd=$2 + sms_tool -d $tty at $cmd 2>&1 +} + +reboot_modem() { + echo 0 > $modem_gpio + sleep 1 + echo 1 > $modem_gpio +} + +switch_sim() { + if [ -f $sim_gpio ]; then + sim_status=$(cat $sim_gpio) + if [ $sim_status -eq 0 ]; then + echo 1 > $sim_gpio + else + echo 0 > $sim_gpio + fi + reboot_modem + logger -t modem_sim "switch sim from $sim_status to $(cat $sim_gpio)" + fi +} + +ping_monitor() { + #ping_dest为空则不进行ping检测 ,如果有多个,用空格隔开 + has_success=0 + for dest in $ping_dest; do + ping -c 1 -W 1 $dest -I $netdev > /dev/null + if [ $? -eq 0 ]; then + return 1 + fi + done + return 0 +} + +at_dial_monitor() { + ttydev=$1 + define_connect=$2 + #检查拨号状况,有v4或v6地址则返回1 + at_cmd="AT+CGPADDR=1" + [ "$define_connect" == "3" ] && at_cmd="AT+CGPADDR=3" + expect="+CGPADDR:" + result=$(sendat $ttydev $at_cmd | grep "$expect") + if [ -n "$result" ];then + ipv6=$(echo $result | grep -oE "\b([0-9a-fA-F]{0,4}:){2,7}[0-9a-fA-F]{0,4}\b") + ipv4=$(echo $result | grep -oE "\b([0-9]{1,3}\.){3}[0-9]{1,3}\b") + disallow_ipv4="0.0.0.0" + #remove the disallow ip + if [ "$ipv4" == "$disallow_ipv4" ];then + ipv4="" + fi + if [ -n "$ipv4" ] || [ -n "$ipv6" ];then + return 1 + fi + fi + return 0 +} + +at_sim_monitor() { + ttydev=$1 + #检查sim卡状态,有sim卡则返回1 + expect="+CPIN: READY" + result=$(sendat $ttydev "AT+CPIN?" | grep -o "$expect") + if [ -n "$result" ]; then + return 1 + fi + return 0 +} + +precheck() +{ + modem_config=$1 + config=$(uci -q show modem.$modem_config) + [ -z "$config" ] && return 1 + ttydev=$(uci -q get modem.$modem_config.at_port) + enable_dial=$(uci -q get modem.$modem_config.enable_dial) + global_en=$(uci -q get modem.global.enable_dial) + [ "$global_en" == "0" ] && return 1 + [ -z "$enable_dial" ] || [ "$enable_dial" == "0" ] && return 1 + [ -z "$ttydev" ] && return 1 + [ ! -e "$ttydev" ] && return 1 + return 0 + + +} + +fail_times=0 +main_monitor() { + + while true; do + #检测前置条件:1.tty存在 2.配置信息存在 3.拨号功能已开启 + precheck $modem_config + if [ $? -eq 1 ]; then + sleep $detect_interval + continue + fi + #检查ping状态,超过judge_time则切卡 + if [ -n "$ping_dest" ]; then + ping_monitor + ping_result=$? + fi + + [ -z $ttydev ] && ttydev=$(uci -q get modem.$modem_config.at_port) + [ -z $define_connect ] && define_connect=$(uci -q get modem.$modem_config.define_connect) + if [ -n $define_connect ] && [ -n $ttydev ];then + at_dial_monitor $ttydev $define_connect + dial_result=$? + fi + if [ -n $ttydev ];then + at_sim_monitor $ttydev; + sim_result=$? + fi + + + if [ -n "$ping_dest" ];then + #策略:ping成功则重置fail_times,否则fail_times累加 + [ -z "$dial_result" ] && dial_result=1 + [ -z "$sim_result" ] && sim_result=1 + fail_total=$((3 - $ping_result - $dial_result - $sim_result)) + if [ $ping_result -eq 1 ]; then + fail_times=0 + else + fail_times=$(($fail_times + $fail_total)) + fi + + #如果失败次数超过judge_time * 3则切卡 切卡后等待3分钟 + else + #策略 无ping则检测拨号和sim卡状态,拨号成功则重置fail_times,否则fail_times累加 + [ -z "$dial_result" ] && dial_result=1 + [ -z "$sim_result" ] && sim_result=1 + fail_total=$((2 - $dial_result - $sim_result)) + if [ $dial_result -eq 1 ]; then + fail_times=0 + else + fail_times=$(($fail_times + $fail_total)) + fi + fi + logger -t modem_sim "ping_result:$ping_result dial_result:$dial_result sim_result:$sim_result fail_times:$fail_times fail_total:$fail_total fail_times:$fail_times" + if [ $fail_times -ge $(($judge_time * 2)) ]; then + switch_sim + fail_times=0 + sleep 240 + fi + sleep $detect_interval + done +} + +sleep 180 + +main_monitor diff --git a/luci-app-modem-mwan-single-module/Makefile b/luci-app-modem-mwan-single-module/Makefile new file mode 100644 index 0000000..cb6df78 --- /dev/null +++ b/luci-app-modem-mwan-single-module/Makefile @@ -0,0 +1,22 @@ +# Copyright (C) 2024 Tom +# This is free software, licensed under the GNU General Public License v3. + +include $(TOPDIR)/rules.mk + +PKG_NAME:=luci-app-5modem-mwan-single-module +LUCI_TITLE:=Luci modem mwan support +LUCI_PKGARCH:=all +PKG_VERSION:=2.0 +PKG_LICENSE:=GPLv3 +PKG_LINCESE_FILES:=LICENSE +PKF_MAINTAINER:=fujr +LUCI_DEPENDS:=+luci-app-5gmodem +luci-app-mwan3 + + +define Package/luci-app-5gmodem-mwan/conffiles +/etc/config/modem_mwan +endef + +include $(TOPDIR)/feeds/luci/luci.mk + +# call BuildPackage - OpenWrt buildroot signature diff --git a/luci-app-modem-mwan-single-module/luasrc/controller/modem_mwan.lua b/luci-app-modem-mwan-single-module/luasrc/controller/modem_mwan.lua new file mode 100644 index 0000000..542cf91 --- /dev/null +++ b/luci-app-modem-mwan-single-module/luasrc/controller/modem_mwan.lua @@ -0,0 +1,9 @@ +module("luci.controller.modem_mwan", package.seeall) + +function index() + if not nixio.fs.access("/etc/config/modem_mwan") then + return + end + --mwan配置 + entry({"admin", "network", "modem", "mwan_config"}, cbi("modem/mwan_config"), luci.i18n.translate("Mwan Config"), 21).leaf = true +end diff --git a/luci-app-modem/luasrc/model/cbi/modem/mwan_config.lua b/luci-app-modem-mwan-single-module/luasrc/model/cbi/modem/mwan_config.lua similarity index 100% rename from luci-app-modem/luasrc/model/cbi/modem/mwan_config.lua rename to luci-app-modem-mwan-single-module/luasrc/model/cbi/modem/mwan_config.lua diff --git a/luci-app-modem-mwan-single-module/po/zh-cn/modem_mwan.po b/luci-app-modem-mwan-single-module/po/zh-cn/modem_mwan.po new file mode 100644 index 0000000..8386bd2 --- /dev/null +++ b/luci-app-modem-mwan-single-module/po/zh-cn/modem_mwan.po @@ -0,0 +1,12 @@ +#model/modem_mwan.lua +msgid "same source ip address will always use the same wan interface" +msgstr "相同的源IP地址将在一定时间内始终使用相同的WAN接口" + +msgid "Check and modify the mwan configuration" +msgstr "检查和修改mwan配置" + +msgid "sticky mode" +msgstr "粘性模式" + +msgid "sticky timeout" +msgstr "粘性超时" diff --git a/luci-app-modem-mwan-single-module/po/zh_Hans/modem_mwan.po b/luci-app-modem-mwan-single-module/po/zh_Hans/modem_mwan.po new file mode 100644 index 0000000..8386bd2 --- /dev/null +++ b/luci-app-modem-mwan-single-module/po/zh_Hans/modem_mwan.po @@ -0,0 +1,12 @@ +#model/modem_mwan.lua +msgid "same source ip address will always use the same wan interface" +msgstr "相同的源IP地址将在一定时间内始终使用相同的WAN接口" + +msgid "Check and modify the mwan configuration" +msgstr "检查和修改mwan配置" + +msgid "sticky mode" +msgstr "粘性模式" + +msgid "sticky timeout" +msgstr "粘性超时" diff --git a/luci-app-modem/root/etc/config/modem_mwan b/luci-app-modem-mwan-single-module/root/etc/config/modem_mwan similarity index 86% rename from luci-app-modem/root/etc/config/modem_mwan rename to luci-app-modem-mwan-single-module/root/etc/config/modem_mwan index 28d02b3..e17c6b8 100644 --- a/luci-app-modem/root/etc/config/modem_mwan +++ b/luci-app-modem-mwan-single-module/root/etc/config/modem_mwan @@ -1,6 +1,6 @@ config ipv4 'ipv4' option wan_ifname 'wan' - option wwan_ifname 'wwan_5g_0' + option wwan_ifname '2_1' list track_ip 'test.ustc.edu.cn' list track_ip 'cip.cc' list track_ip '208.67.222.222' diff --git a/luci-app-modem/root/etc/init.d/modem_mwan b/luci-app-modem-mwan-single-module/root/etc/init.d/modem_mwan similarity index 95% rename from luci-app-modem/root/etc/init.d/modem_mwan rename to luci-app-modem-mwan-single-module/root/etc/init.d/modem_mwan index e137c45..2c04d8a 100755 --- a/luci-app-modem/root/etc/init.d/modem_mwan +++ b/luci-app-modem-mwan-single-module/root/etc/init.d/modem_mwan @@ -51,3 +51,8 @@ stop_service() { service_triggers() { procd_add_reload_trigger 'modem_mwan' } + +reload_service() { + stop + start +} diff --git a/luci-app-modem/root/usr/share/modem/modem_mwan.sh b/luci-app-modem-mwan-single-module/root/usr/share/modem/modem_mwan.sh similarity index 100% rename from luci-app-modem/root/usr/share/modem/modem_mwan.sh rename to luci-app-modem-mwan-single-module/root/usr/share/modem/modem_mwan.sh diff --git a/luci-app-modem-mwan/Makefile b/luci-app-modem-mwan/Makefile new file mode 100644 index 0000000..97de8cb --- /dev/null +++ b/luci-app-modem-mwan/Makefile @@ -0,0 +1,22 @@ +# Copyright (C) 2024 Tom +# This is free software, licensed under the GNU General Public License v3. + +include $(TOPDIR)/rules.mk + +PKG_NAME:=luci-app-5gmodem-mwan +LUCI_TITLE:=Luci modem mwan support +LUCI_PKGARCH:=all +PKG_VERSION:=2.0 +PKG_LICENSE:=GPLv3 +PKG_LINCESE_FILES:=LICENSE +PKF_MAINTAINER:=fujr +LUCI_DEPENDS:=+luci-app-5gmodem +luci-app-mwan3 + + +define Package/luci-app-5gmodem-mwan/conffiles +/etc/config/modem_mwan +endef + +include $(TOPDIR)/feeds/luci/luci.mk + +# call BuildPackage - OpenWrt buildroot signature diff --git a/luci-app-modem-mwan/luasrc/controller/modem_mwan.lua b/luci-app-modem-mwan/luasrc/controller/modem_mwan.lua new file mode 100644 index 0000000..542cf91 --- /dev/null +++ b/luci-app-modem-mwan/luasrc/controller/modem_mwan.lua @@ -0,0 +1,9 @@ +module("luci.controller.modem_mwan", package.seeall) + +function index() + if not nixio.fs.access("/etc/config/modem_mwan") then + return + end + --mwan配置 + entry({"admin", "network", "modem", "mwan_config"}, cbi("modem/mwan_config"), luci.i18n.translate("Mwan Config"), 21).leaf = true +end diff --git a/luci-app-modem-mwan/luasrc/model/cbi/modem/mwan_config.lua b/luci-app-modem-mwan/luasrc/model/cbi/modem/mwan_config.lua new file mode 100644 index 0000000..144e878 --- /dev/null +++ b/luci-app-modem-mwan/luasrc/model/cbi/modem/mwan_config.lua @@ -0,0 +1,48 @@ + + +local d = require "luci.dispatcher" +local uci = luci.model.uci.cursor() +local sys = require "luci.sys" +local script_path="/usr/share/modem/" + +m = Map("modem_mwan") +m.title = translate("Mwan Config") +m.description = translate("Check and modify the mwan configuration") +s = m:section(NamedSection, "global", "global", translate("gloal Config")) +s.anonymous = true +s.addremove = false +enable_mwan = s:option(Flag, "enable_mwan", translate("Enable MWAN")) +sticky = s:option(Flag,"sticky_mode",translate("sticky mode")) +sticky.default = 0 +sticky.description = translate("same source ip address will always use the same wan interface") +sticky_timeout = s:option(Value,"sticky_timeout",translate("sticky timeout")) +sticky_timeout.default = 300 +sticky_timeout.datatype = "uinteger" +sticky_timeout:depends("sticky_mode",1) + +s = m:section(TypedSection, "ipv4", translate("IPV4 Config")) +s.anonymous = true +s.addremove = true +s.template = "cbi/tblsection" +member_interface = s:option(DynamicList, "member_interface", translate("Interface")) +member_interface.rmempty = true +member_interface.datatype = "network" +member_interface.template = "cbi/network_netlist" +member_interface.widget = "select" + +o = s:option(DynamicList, 'member_track_ip', translate('Track IP')) +o.datatype = 'host' +member_priority = s:option(Value, "member_priority", translate("Priority")) +member_priority.rmempty = true +member_priority.datatype = "uinteger" +member_priority.default = 1 +-- member_priority:depends("member_interface", "") + +member_weight = s:option(Value, "member_weight", translate("Weight")) +member_weight.rmempty = true +member_weight.datatype = "uinteger" +member_weight.default = 1 +-- member_weight:depends("member_interface", "") + + +return m diff --git a/luci-app-modem-mwan/po/zh-cn/modem_mwan.po b/luci-app-modem-mwan/po/zh-cn/modem_mwan.po new file mode 100644 index 0000000..df11a2f --- /dev/null +++ b/luci-app-modem-mwan/po/zh-cn/modem_mwan.po @@ -0,0 +1,24 @@ +#model/modem_mwan.lua +msgid "same source ip address will always use the same wan interface" +msgstr "相同的源IP地址将在一定时间内始终使用相同的WAN接口" + +msgid "Check and modify the mwan configuration" +msgstr "检查和修改mwan配置" + +msgid "sticky mode" +msgstr "粘性模式" + +msgid "sticky timeout" +msgstr "粘性超时" + +msgid "member_track_ip" +msgstr "成员跟踪IP" + +msgid "member_interface" +msgstr "成员接口" + +msgid "member_priority" +msgstr "成员优先级" + +msgid "member_weight" +msgstr "成员权重" diff --git a/luci-app-modem-mwan/po/zh_Hans/modem_mwan.po b/luci-app-modem-mwan/po/zh_Hans/modem_mwan.po new file mode 100644 index 0000000..7e4e6e8 --- /dev/null +++ b/luci-app-modem-mwan/po/zh_Hans/modem_mwan.po @@ -0,0 +1,24 @@ +#model/modem_mwan.lua +msgid "same source ip address will always use the same wan interface" +msgstr "相同的源IP地址将在一定时间内始终使用相同的WAN接口" + +msgid "Check and modify the mwan configuration" +msgstr "检查和修改mwan配置" + +msgid "sticky mode" +msgstr "粘性模式" + +msgid "sticky timeout" +msgstr "粘性超时" + +msgid "member_track_ip" +msgstr "成员跟踪IP" + +msgid "Interface" +msgstr "成员接口" + +msgid "Priority" +msgstr "成员优先级" + +msgid "Weight" +msgstr "成员权重" diff --git a/luci-app-modem-mwan/root/etc/config/modem_mwan b/luci-app-modem-mwan/root/etc/config/modem_mwan new file mode 100644 index 0000000..b7547a4 --- /dev/null +++ b/luci-app-modem-mwan/root/etc/config/modem_mwan @@ -0,0 +1,29 @@ +config ipv4 + list member_track_ip 'test.ustc.edu.cn' + list member_track_ip 'cip.cc' + list member_track_ip '208.67.222.222' + list member_track_ip '208.67.220.220' + list member_interface 'wan' + option member_priority '1' + option member_weight '1' + +config ipv4 + list member_track_ip 'test.ustc.edu.cn' + list member_track_ip 'cip.cc' + list member_track_ip '208.67.222.222' + list member_track_ip '208.67.220.220' + list member_interface '2_1_2' + option member_priority '2' + option member_weight '1' + +config ipv4 + list member_track_ip 'test.ustc.edu.cn' + list member_track_ip 'cip.cc' + list member_track_ip '208.67.222.222' + list member_track_ip '208.67.220.220' + list member_interface '2_1_4' + option member_priority '2' + option member_weight '1' + +config global 'global' + option enable_mwan '1' diff --git a/luci-app-modem-mwan/root/etc/init.d/modem_mwan b/luci-app-modem-mwan/root/etc/init.d/modem_mwan new file mode 100755 index 0000000..2da7bfa --- /dev/null +++ b/luci-app-modem-mwan/root/etc/init.d/modem_mwan @@ -0,0 +1,35 @@ +#!/bin/sh /etc/rc.common +USE_PROCD=1 +START=30 + +start_mwan3() +{ + proto=$1 + logger -t modem_mwan "before set $proto start" + /usr/share/modem/modem_mwan.sh $proto start + logger -t modem_mwan "set $proto start" + +} + +start_service() { + logger -t modem_mwan "start modem_mwan" + config_load modem_mwan + config_get enable global enable_mwan 0 + if [ "$enable" = "0" ]; then + stop_service + fi + start_mwan3 ipv4 +} + +stop_service() { + /usr/share/modem/modem_mwan.sh ipv4 stop +} + +service_triggers() { + procd_add_reload_trigger 'modem_mwan' +} + +reload_service() { + stop + start +} diff --git a/luci-app-modem-mwan/root/usr/share/modem/modem_mwan.sh b/luci-app-modem-mwan/root/usr/share/modem/modem_mwan.sh new file mode 100755 index 0000000..adc2dcb --- /dev/null +++ b/luci-app-modem-mwan/root/usr/share/modem/modem_mwan.sh @@ -0,0 +1,158 @@ +#! /bin/sh +. /lib/functions.sh + + + + + + +append_if(){ + interface=$1 + track_ip=$2 + uci batch < +# This is free software, licensed under the GNU General Public License v3. + +include $(TOPDIR)/rules.mk + +PKG_NAME:=luci-app-5gmodem-sms +LUCI_TITLE:=Luci modem sms support +LUCI_PKGARCH:=all +PKG_VERSION:=2.0 +PKG_LICENSE:=GPLv3 +PKG_LINCESE_FILES:=LICENSE +PKF_MAINTAINER:=fujr +LUCI_DEPENDS:=+luci-app-5gmodem + +include $(TOPDIR)/feeds/luci/luci.mk + +# call BuildPackage - OpenWrt buildroot signature diff --git a/luci-app-modem-sms/luasrc/controller/modem_sms.lua b/luci-app-modem-sms/luasrc/controller/modem_sms.lua new file mode 100644 index 0000000..78c2d70 --- /dev/null +++ b/luci-app-modem-sms/luasrc/controller/modem_sms.lua @@ -0,0 +1,51 @@ +module("luci.controller.modem_sms", package.seeall) +local http = require "luci.http" +local fs = require "nixio.fs" +local json = require("luci.jsonc") +local modem_ctrl = "/usr/share/modem/modem_ctrl.sh " + +function shell(command) + local odpall = io.popen(command) + local odp = odpall:read("*a") + odpall:close() + return odp +end + +function index() + --sim卡配置 + entry({"admin", "network", "modem", "modem_sms"},template("modem_sms/modem_sms"), luci.i18n.translate("SMS"), 11).leaf = true + entry({"admin", "network", "modem", "send_sms"}, call("sendSMS"), nil).leaf = true + entry({"admin", "network", "modem", "get_sms"}, call("getSMS"), nil).leaf = true + entry({"admin", "network", "modem", "delete_sms"}, call("delSMS"), nil).leaf = true +end + +function getSMS() + local cfg_id = http.formvalue("cfg") + response = shell(modem_ctrl .. "get_sms " .. cfg_id) + http.prepare_content("application/json") + http.write(response) +end + +function sendSMS() + local cfg_id = http.formvalue("cfg") + local pdu = http.formvalue("pdu") + if pdu then + response = shell(modem_ctrl .. "send_raw_pdu " .. cfg_id .. " \"" .. pdu .. "\"") + else + local phone_number = http.formvalue("phone_number") + local message_content = http.formvalue("message_content") + json_cmd = string.format('{\\"phone_number\\":\\"%s\\",\\"message_content\\":\\"%s\\"}', phone_number, message_content) + response = shell(modem_ctrl .. "send_sms " .. cfg_id .." \"".. json_cmd .. "\"") + + end + http.prepare_content("application/json") + http.write(response) +end + +function delSMS() + local cfg_id = http.formvalue("cfg") + local index = http.formvalue("index") + response = shell(modem_ctrl .. "delete_sms " .. cfg_id .. " \"" ..index.."\"") + http.prepare_content("application/json") + http.write(response) +end diff --git a/luci-app-modem-sms/luasrc/view/modem_sms/modem_sms.htm b/luci-app-modem-sms/luasrc/view/modem_sms/modem_sms.htm new file mode 100644 index 0000000..2f072cc --- /dev/null +++ b/luci-app-modem-sms/luasrc/view/modem_sms/modem_sms.htm @@ -0,0 +1,908 @@ +<%+header%> + +
+
+
+ + + + + + + +
<%:Modem Name%> + +
+
+
+
+<%+footer%> diff --git a/luci-app-modem-sms/po/zh-cn/modem_sms.po b/luci-app-modem-sms/po/zh-cn/modem_sms.po new file mode 100644 index 0000000..ee12f84 --- /dev/null +++ b/luci-app-modem-sms/po/zh-cn/modem_sms.po @@ -0,0 +1,27 @@ +#modem_sms.htm +msgid "Sender" +msgstr "发信人" + +msgid "Timestamp" +msgstr "时间戳" + +msgid "Content" +msgstr "内容" + +msgid "Send SMS" +msgstr "发送短信" + +msgid "Send" +msgstr "发送" + +msgid "Delete" +msgstr "删除" + +msgid "SMS" +msgstr "短信" + +msgid "Message Content" +msgstr "短信内容" + +msgid "Phone Number" +msgstr "电话号码" diff --git a/luci-app-modem-sms/po/zh_Hans/modem_sms.po b/luci-app-modem-sms/po/zh_Hans/modem_sms.po new file mode 100644 index 0000000..3e81e8a --- /dev/null +++ b/luci-app-modem-sms/po/zh_Hans/modem_sms.po @@ -0,0 +1,33 @@ +#modem_sms.htm +msgid "Sender" +msgstr "发信人" + +msgid "Timestamp" +msgstr "时间戳" + +msgid "Content" +msgstr "内容" + +msgid "Send SMS" +msgstr "发送短信" + +msgid "Send" +msgstr "发送" + +msgid "Delete" +msgstr "删除" + +msgid "SMS" +msgstr "短信" + +msgid "Message Content" +msgstr "短信内容" + +msgid "Phone Number" +msgstr "电话号码" + +msgid "Send SMS Failed" +msgstr "发送短信失败" + +msgid "Send SMS Success" +msgstr "发送短信成功" diff --git a/luci-app-modem-ttl/Makefile b/luci-app-modem-ttl/Makefile new file mode 100644 index 0000000..8e1c97b --- /dev/null +++ b/luci-app-modem-ttl/Makefile @@ -0,0 +1,22 @@ +# Copyright (C) 2024 Tom +# This is free software, licensed under the GNU General Public License v3. + +include $(TOPDIR)/rules.mk + +PKG_NAME:=luci-app-5gmodem-ttl +LUCI_TITLE:=Luci modem ttl support +LUCI_PKGARCH:=all +PKG_VERSION:=2.0 +PKG_LICENSE:=GPLv3 +PKG_LINCESE_FILES:=LICENSE +PKF_MAINTAINER:=fujr +LUCI_DEPENDS:=+luci-app-5gmodem + + +define Package/luci-app-5gmodem-ttl/conffiles +/etc/config/modem_ttl +endef + +include $(TOPDIR)/feeds/luci/luci.mk + +# call BuildPackage - OpenWrt buildroot signature diff --git a/luci-app-modem-ttl/luasrc/controller/modem_ttl.lua b/luci-app-modem-ttl/luasrc/controller/modem_ttl.lua new file mode 100644 index 0000000..7854dc4 --- /dev/null +++ b/luci-app-modem-ttl/luasrc/controller/modem_ttl.lua @@ -0,0 +1,8 @@ +-- Copyright 2024 Siriling +module("luci.controller.modem_ttl", package.seeall) +function index() + if not nixio.fs.access("/etc/config/modem_ttl") then + return + end + entry({"admin", "network", "modem", "modem_ttl"}, cbi("modem/modem_ttl"), luci.i18n.translate("TTL Config"), 22).leaf = true +end diff --git a/luci-app-modem-ttl/luasrc/model/cbi/modem/modem_ttl.lua b/luci-app-modem-ttl/luasrc/model/cbi/modem/modem_ttl.lua new file mode 100644 index 0000000..067652d --- /dev/null +++ b/luci-app-modem-ttl/luasrc/model/cbi/modem/modem_ttl.lua @@ -0,0 +1,18 @@ +m = Map("modem_ttl", translate("TTL Config")) +s = m:section(NamedSection, "global", "global", translate("Global Config")) + +enable = s:option(Flag, "enable", translate("Enable")) +enable.default = "0" + +ttl = s:option(Value, "ttl", translate("TTL")) +ttl.default = 64 +ttl.datatype = "uinteger" + +o = s:option(Value, "ifname", translate("Interface")) +o.rmempty = ture +o.template = "cbi/network_netlist" +o.widget = "optional" +o.nocreate = true +o.unspecified = true + +return m diff --git a/luci-app-modem-ttl/root/etc/config/modem_ttl b/luci-app-modem-ttl/root/etc/config/modem_ttl new file mode 100644 index 0000000..1cc1b61 --- /dev/null +++ b/luci-app-modem-ttl/root/etc/config/modem_ttl @@ -0,0 +1 @@ +config global 'global' diff --git a/luci-app-modem-ttl/root/etc/init.d/modem_ttl b/luci-app-modem-ttl/root/etc/init.d/modem_ttl new file mode 100755 index 0000000..0e19520 --- /dev/null +++ b/luci-app-modem-ttl/root/etc/init.d/modem_ttl @@ -0,0 +1,65 @@ +#!/bin/sh /etc/rc.common +START=95 +STOP=13 +USE_PROCD=1 + +. /usr/share/libubox/jshn.sh +. /lib/functions.sh +start_service() +{ + config_load 'modem_ttl' + config_get enable 'global' 'enable' '0' + if [ "$enable" == 0 ]; then + return + fi + set_if_ttl +} + +set_if_ttl() +{ + config_get ifname 'global' 'ifname' + config_get ttl 'global' 'ttl' + iface=$(ifstatus $ifname) + json_load "$iface" + json_get_var device device + IPT="iptables" + IPT6="ip6tables" + logger -t modem_ttl "Setting TTL for $device to $ttl" + comment="modem_ttl" + $IPT -t mangle -A PREROUTING -i $device -j TTL --ttl-set $ttl -m comment --comment $comment + $IPT -t mangle -A POSTROUTING -o $device -j TTL --ttl-set $ttl -m comment --comment $comment + $IPT6 -t mangle -A PREROUTING -i $device -j HL --hl-set $ttl -m comment --comment $comment + $IPT6 -t mangle -A POSTROUTING -o $device -j HL --hl-set $ttl -m comment --comment $comment +} + +stop_service(){ + IPT_PREROUTING=$(iptables -t mangle -L PREROUTING -n --line-numbers | grep modem_ttl | awk '{print $1}') + IPT_POSTROUTING=$(iptables -t mangle -L POSTROUTING -n --line-numbers | grep modem_ttl | awk '{print $1}') + IPT6_PREROUTING=$(ip6tables -t mangle -L PREROUTING -n --line-numbers | grep modem_ttl | awk '{print $1}') + IPT6_POSTROUTING=$(ip6tables -t mangle -L POSTROUTING -n --line-numbers | grep modem_ttl | awk '{print $1}') + if [ -n "$IPT_PREROUTING" ]; then + iptables -t mangle -D PREROUTING $IPT_PREROUTING + fi + if [ -n "$IPT_POSTROUTING" ]; then + iptables -t mangle -D POSTROUTING $IPT_POSTROUTING + fi + if [ -n "$IPT6_PREROUTING" ]; then + ip6tables -t mangle -D PREROUTING $IPT6_PREROUTING + fi + if [ -n "$IPT6_POSTROUTING" ]; then + ip6tables -t mangle -D POSTROUTING $IPT6_POSTROUTING + fi +} + +service_triggers() +{ + procd_add_reload_trigger "modem_ttl" + procd_add_reload_trigger "network" + #netdev +} + +reload_service() +{ + stop + start +} diff --git a/luci-app-modem/Makefile b/luci-app-modem/Makefile index 482f00a..f35534b 100644 --- a/luci-app-modem/Makefile +++ b/luci-app-modem/Makefile @@ -1,4 +1,5 @@ # Copyright (C) 2023 Siriling +# Copyright (C) 2024 Tom # This is free software, licensed under the GNU General Public License v3. include $(TOPDIR)/rules.mk @@ -6,10 +7,10 @@ include $(TOPDIR)/rules.mk PKG_NAME:=luci-app-5gmodem LUCI_TITLE:=LuCI support for Modem LUCI_PKGARCH:=all -PKG_VERSION:=1.4.4 +PKG_VERSION:=2.0 PKG_LICENSE:=GPLv3 PKG_LINCESE_FILES:=LICENSE -PKF_MAINTAINER:=Siriling +PKF_MAINTAINER:=Tom LUCI_DEPENDS:=+luci-compat +kmod-usb-net +kmod-usb-net-cdc-ether +kmod-usb-acm \ +kmod-usb-net-rndis \ +kmod-usb-net-sierrawireless +kmod-usb-ohci\ @@ -29,7 +30,8 @@ LUCI_DEPENDS:=+luci-compat +kmod-usb-net +kmod-usb-net-cdc-ether +kmod-usb-acm \ +quectel-CM-5G \ +sms-tool \ +jq +grep +bc\ - + +coreutils +coreutils-stat + define Package/luci-app-5gmodem/conffiles /etc/config/modem diff --git a/luci-app-modem/htdocs/luci-static/resources/icons/sms.png b/luci-app-modem/htdocs/luci-static/resources/icons/sms.png deleted file mode 100644 index b036e813f546c56ad0e934e1c7ec9ee359f469b4..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 9221 zcmV+gB>LNlP) zaB^>EX>4U6ba`-PAZ2)IW&i+q+O3;cc4WD7MgK7h4FTQ^2X-yZK*QHQK$69(?v|cR zu}LP=;9ejijtQX6{*Qk@=HK{NT(l;pQgh4M@-Md7eCI*6?_a+^osIYB`{V01_xtna z`vuQaf#2c%S@Y-l&GVl3`_J?9GfwCE^kbm5KQD~mU+ABKeEnSD^ZeI^f_oRR>oZXQ z3>5t5%JKa@K3C4ImY-Aje9oTF>vtLWHu@1m@i}EzB0rTN8n+e-I?zUgym zd=2#b-{$MBo_q2;xM1&3|L!vA+l8)Y?$5;gT&O(uq4AS@cz0_E8MnaW_F3D{qW;sr zf4Y0~^Y%Ys|1GTFkK8{z|B1HwibD3E7s4M=%HO~L_Ia1S2KpncH+Da+oa^_Me|x?p z*MCmge1%Wn=d60pezWT_Gv)l5)Ynw*Bi=W(TK7|#uVS+y2`dlu)%dEE#Uz)Oop$gw zU2~pL9v9tm-5s~@@98GD82$Ez-`-C{boFE<7|qY1;6{D9;|l>^gxZHmN(7$u-}mC~ zW!t^nq|BDF%kft47)-hHzy31+>Ko6k3FmD6UMud)E9j=Mo@irpj&Sz26UEr^; zKmRGNfe5C%%#{gtJIotmB=;-1!VPrbjfvl{h+SEq0azj~owyknh=9%1jmz9o@xD06 zLRJFQxpg0+A4I^VXUy@1BM}*kU|cH*ieE5E5=0rlvv53 zo5b((YCK!Y*APx{k`yx{=A$Fv zg{ToR5?e8|)y3!)ImOI2PgNw(O(q3rIYo>J#_fDM?mKp$$Qf4g|0Qmw)EhVde~p|` z=>EmX{WWfX7qun4n>S*w47I2>P<_07@l{|vf#@a;yDbQ_BwmtM=te5WJB(a>Tfyu8Jnv+_dJ&1U@n!uAfoJI;y)AXd^a3L&%Wh4lZaa{etxsiT)p#X%|%oacwQOr zz7pP_)}%hyis7unLJejVS8geS4ZX*`U8{pE%%OH+@0@NCk?jQBVJvcnWIDv?`n4A9IV=)DmzWZTfAA}L2sK>TCwY(!G-StUY;g#BD`Fp9Fhh{tbyRdgP zy+<_~M$ZJcCA$^_?K8L{*f*B08BXb$Bs-Iv;qR)9_6PFX-nC|jUrZhr4TiNy-)}nE z_61X&!?+|?ITSYqnwZeczOEJ0DURrd$!%}jPHk>(a?5N+sdM;pjvJkyWWzo#ltaem zcZqUxylWCl+I!iuR2qG_RLkiz)wQ=_(t$^z4ziGsFb+eC#`MuU(i=yk*f|cVFp0~s ziRmvt1vfJeqgxU2C1$ZQ*WwzKq3(l6trtMnO#yR1qbA?)yeyT&Qs&VzI7V#@Gq{=F zGI8_-t}$N?GTbIydUPZ>`Z!F+<#&NK-o*n|x3=e=n=NMEC)0|B97uCgL8yg5p#X(c zgaS@>lK)d#0DNWD5fGRT@YVgMsFqKJKTVtFa!sH`ImHI*QZ?k|%q~$z(ajSGl0YI6 zOHaOQF$ZAkS7}tyY$lL~i=^ZmfIkWJBK?_u%+wRvmQG8KD)}no1Ww*r^h$=6ary-! z^E(oCj0r&n=)qblw{1vmC zf;Mg*yp0R0Amzw?g47~d%3Qfmh9h}E4g<;9UD}>@?vRz-iHw7CHrUqF3DX5)!vd0k z4XX1I#tY4cfe=i6lao|&ghhzyX3~j7q?X+aEm=eP9xh^gi=<1Wim9H8PHbs8Y9&uq z1){R6nheMueOEcyCFVY{jT4+IH|GUMfb;l;N`%1BdT@<_oI3U ze+3Ejp+n&umnJDBVfAnoB>BczQ9TKel}PApzaG>SkgoSoxW&P|#~{wbma%wm>aqBd zclMLYh0tM!!Dvu)MKNnJ%$d^MH!nyS{ayh5nA?vv6=geN+rd1kqZ0fgM<^yADc+pW zd(^3-C-8r01i|+Us1r)NRR)}?>ODh_>2?;vlCX?Rm=CKa0%?I70g6psE-4{dz<6dT z4;M!l`Cdn%i!2pFnK2$aZl3X&bwew}QIIxF-t;~p{XIMU;7W0;vI<+3kzIu^k6pEO z@@%(32~n#cWJLo|x3@wM$*~-QeUH%Zb$>7$_%JDKR%Q8;EtpUx27rc!oJh8Ta+X{q zpEmRktT%)7LGGwZ`_8LD3^Oo-k8Ku8K9f{{DVg5&eFh}M9TW#C`$3Q&O`l~d5HY`0 z#+3%jMaKYdwOR)tP)# z1Lnh;FyYjTK?QMb1RB65uG=aciyD|UesB|k=jRuQO0|w#AOH{nC;^5=Mwo8n7woDD z(e2WBidd79(j#&m`*Qf`h{&3aY>e1@6ih3R_jWjD&X?CnQnIX`nijB7JAWjkA+s*r z_$)3m?O~e(EVmn;x`6Hik`wSoo0;C$W%(-#_hO+?;w=>m_N^`yte{yYN8#>F?q|lH z;1#-=ppXCo**=5uQN4$eA)^uUW^E8LfGK($6h%`3+7(pVHyx1n%!ks6FCCzu0g9qG z%^HXZ@M)+B&!7s2WC^RUV4-W!fPQ6976&BZ=9 z$QMtcwA3sBKuF(%wjJCNWCo4{KmiFs(TWv_;l!WXjBky{_04R^zK&E&0@2;(Sekn5 z5~)D)r~n(!D5i$VEVfrL1I7055&F-kB}S!0yCm)v)3&?+76;ZKK#sQ%#Nx%fH!gHPLLBU68%XNbd{n7g>sXFg=)!&<}Q;70Gy63;*c zraBhjGs1)|FUwFdz&l_gVYJ|usJaObpGS3=3R7y{9{7YP;KNjgf`4zD(vlI{0Py)_ zGI|t>Cowu{OPzIU7+r`yk{lZtvw?Kj5IG5ks>Qz`C6g{p3Nf)|h1<+zwi3}5+|Th~ ze_Dt}^pOneBSz*dBS!6J;>1mah+zW)16BlM2x0<>7}4dvQK)bGfhu#c%IcN&!5;e) zpMGK3fAh4t&+l*eBdI78kXG{W_YZHY$DbD{N6mtD5elJUSZqr6<%t{tK(l;YattjK z6)LsK2v=6ZVVkK!56`d|n2a(Z_Yp7A8^qztS5IVQ)J?FM0U4kKbijVZ(S1RWZYHq%;PF{D-S0+t6-~Yf7SUO>z?HG2MNGRWIYJ1icAz zL#Y}dWRiP_swVY8>e7*ShY=ta9_Qc&86NlxODp1yxkS7K6aIKy#8>D>iB%5iobj%s zOKc7hI^V)1^;ToT@FsHmE`UQF`OyXu1NU`X#0iOQF7R6zqC8@G(b!=yBDxLRTv@Q< z3t;HNRhhQk_tu>N3I0RS3`7LU8c{0%Cv`rhb>Yy2Ix7T@aghu#5`JL?(t}(LxgoJe z%v8ZZL#xw~i#nrB5d%Ra@pK230?eah`$wFy5F=bfBM&xK$7(R^g)c(WMv?l3&YnyW zwl9k4uCNvnjY!c7)lISW7Q2e0@QZ;wNTN6;qxvFx7*UDN;Dv!QVmi^S)CeUD_tm3D zlC%KifQxDHWmhjn>!*gsOb-pLW}zWWym>JTzEbHur4*SZtOXVzRM2|Rr}!i>Gxc;Z zCk{r;6}7Q9xjqN{U|{x^S?nccvvS@IYzASH8V zT8YaHlmo(-HDiS>E*A-nuR=0}jnHC2>#q6$Qv-p)t&ZlXpEmr5s zjJzS?gu9_!=b1_eIXTv(e6Pv+tjYJ1^bB*(ZergE!KPpeCt2%=pu75U-)b&-ud8_>d%2(b*Ss-aUZ6O&$j9c z5I`nf;yHP|8Vu+O#u{2AF5;1Dcn$nZb3>iVajO{%x6O`iFXZS3gZlux5b|X>R5?K9 z#PZS*d)*+l)sjluV#09k>d@h7m%0Iv z7bD>d2?EjQ=7z0r7C4TnwvF}x8hLW)S(<>5Ce;dcgFxUT4~CK8=n6mu0V`Y> zND$Ld7RRlTLd`f$JQHc>6|x8jc{!sKS|L|A@f{g3#+Y7*grl4YdsqR9dBL9qVGYR& z*6>)bj)BM}%0CrSqvP`s$w;@T5~gB3&Jw*UXeH8Ipcs4vIuJbV+9-?YLDt%n3R7(d z3|q^v_UmD#T!5rwNnMoi;4&k7r7v?u9*2zzOeA3)0Y%2`5zvjgYcLFq15}~Xxs*l3 zj{qV`kWuhA9vd#c+)t9LLANUNdL%p)M_))mf`T-`I58qF4ZDLS1}>qF0S7ImnCcY8 z=9wD5Cex!bQD?Vl3TMl>uPT(4C}Zi+nMa+1gS>LWsi!$qR?-|GWFZpj1*18U85>cD zWJp0cDuGL-kVXT0_8J7p@eH>UAYh-umxEuoF-{PP!Eor+$5vX)n}(;TVLP_6k|>@` zf>XPwz^gRTJA|yLM;p^HFo5^k?mO=$ z()M~xhD3@=4+BDO%6w&@1B0`*22gJ4qak;bcUjr&95WPU<>;uTUQ1F3)evuLQ>aAh zx10J_sgF=7?xG2G7vpT(0t+4vmd8Szkic8Uu99nHy_vUuUYh?k%fofGqwY&piyX%O z3v0^jcSB^7D7b}vdCK3u4us$p+)2PC^%f7CP;g&7GW^C zr7e&l^bFgXDodibFzo}-fI7N+7I&0sQA$gK3&#t5WA+oPXa&5t3lIj?O`TG|=2eSG zC^~6QXyQojda@YVhU6iR+@QT^1D<-w1Jj(SXvAlZAGu-hW&@s8pR|c4GZo!M?Swpf zHJQ*NFbTPc%XK+APj(OZ$kjvoPU`6pA5-PceM#1eycfY1-rpT!!30R-mi3 z>5s-!zin^)mcg>8HXWs#(8SXv;GiQ^E#ucuhZ2ROMd`NYad#!uu+*-^jZ#Ep5H%DS zbzM}~M-5}dxz_xXuMXxIpS==0U%T^Q{XV-T;cK^KHKR3^1#JPKQ5ziS$NBC-?S$4W zl5ojni@>nMT`FjIpc-qjnj?-S5i4yS>WVc!pj8RnI7*lyW|1hY##TFeXg^hk3yZK9 z)WB*5yc^&TuxCS*Hogo_=gMjybrO9{wY%yI00Wli=e|(=0`uN1;v$X9B%QoLdM{iF zHNY2cOt3nwcaqcVamT#N4|gyP=mz;#v~fV$<&8#CGPBFTQ@#TUZF+a^kw;v+|^ zM}YLqLz_`Pd;?k=!B%doAD+swyik}Qu{bXl{W}(Xw4>^8r&;W>;Uut*sc*?R=_K#* zWnwdPS9wX%yiGw$BaOS809f2r`s^rRo00gkKzJC;Gk=GPy2{uv#FiNr!ES*gl$hH4 z;{u7Ad}tZ%m~`3ftaB0s0}qOt^is2u;)wJU_)#xPOdYS4O%7wN#oM4Xfc3==>YVGP0kA_Kzp-bb6D_`+XUzLb_n z8_x1y`Kb?vS! zwMj|oD2Im-YCal>2Z+PD-JVRfzpkU>XN1^Giq2eKEA=dh4~g9+L9A<*82eU_C&4G|F=u0tU~JZV($ZICqhibTLrGmtpKKkEWchzh@~xw3t!1FlW5 zh?ZEY=AL)0R0zXP$knMuhgvey?Ks`*FHR8dUERjDDIruMQAFc{pad-^ZE9)L8y?Y! z`}UWM#G|Qy+oYcMN1xk%o%A3M$mFC3B-&8DYy{-zBj)#hxB4=l-Z-vSeT=BH4lPw% z-c=Ix_cnR31Or*y@BUXc_H(pjlr^;Fz0o%cL$1hqyNS)j5(U|)eXwGj4yAkVc&~*yqco8(fS|4X@gW6r!GrXKjOaHNVP3r+S!vn`klndXa-t$LuT= zH`ZYh3rb|j$ni!5jB>ITT~XWnmwO8z?vNp<6SW&Yl>7U;kDPsaJ!$i2ulm=yhEJRO zHNfpZJzbP(JT`BfdOJf|fFlsn)~YA;K2vaRsL$f?bb#CoKQUj3(X6A2*RAAb0&ZFT z*8tgdCrLj@yaI4w6tQ`idq*g^Z80x=tSTQ{O}5wf(q_w91`{|womZS=nXi1E{QcGj z(vyHdA+-xPgEP>51XRFU`?j@IE8V<39vwYJ$Y(Q6!b6?j`OU6;bE7=U;>5 zFnK$HnFuN*6=K{U!1g2p;j zWGN&wr|d+`XgFDnfN{-~6j>3FEj34vMbUXa$Y(*bV*Z130{uI6pdrAf*5Hxn_ z=uK&!t3$zWT;vK!^C@&A2FOw?62WZGMkq*POfVJ#i~{drk=MvAYSP^L4N~0Dv%fg$ zU|$_HscN{VqCFq{Bh{u;UiTexDO)>!;9~g3#a;+X$8fAQ28!O#%*AyU2=1zC*UpVD ztMViiZ&G>7t~H}ha?=i5o;r}D7HOS#L*gQ~^4Af!onE)HOk84BSo5@1g8g;Eo;Xim;{5y)=k9eV z)Hec1ke5B_2tb#?<`aMo&}R-ejfhhN8@0@rSC;}1bPojKSa`Rod3bvv>k9<~s)#6N zf0rN`kmJ{CeElX%v*aBz^J+Vt@wa+ZEt=-HWmB_J^kc(T<0_3IE=jUAB z0Mrot?w)D;9Dr1gi)+~A&tHurLLZJlR;(P zRjTm|u>mM!xjR_|1P#^+Hk7zlhu?#oGQ$BwAzTB=t`TjiTuK}71d}QE9V&^>5vE%b z8(LceBb|x^*bZn7WPl5unu2eK;+MA;B#5QdVF!M6P-m+OU!TFhjRE2`9A*MDn82Tb zMnZm0tcW%Q@$bl6^_e;;Hw+dZ3fB<_08tGS$!s!pXH`!8&=0vc6ug5H2954OB-3lS zbTvy&S1L{bJIk{z9lz5?<<$Pt(t&)kNK#6NCeYhWJ55oqr~{=f8A!CNM~W*#hU?r%SZa&|tz;pZOyml+ zI@~+TI_h+qQ%t~-nvy!v+Q1sn5k~dWspPjd1P)rA1jHohy{uWuZCla+CTI;MqW^`ZzV=Kmj(PVFl7j|9pkVHP9*NOp zV+H;?UeS_{ZPgHv%#cG-PwbIH`6qHPb`a{v4xzsnfAB+)q6Qof%Rc@~dN4ouAqR|d z?z4{H_~CEq;V*PyxX>V3u9X#EEU|9a+0lZn&MWDZH?R~Wua*ld;;f2Cu7mS9haB2 z?b8xkF6x9Vc%cKe_$d6;wH^3!2tc$1ogF2Ew!m=uGZ2Aexv8TT_NJ1TEP;!A@gex=t+LL~ ze66?nGXNw7uAjX4PyRYOR@u|7c^-|Qd}Gb*Mfr|i&X~~XI&j!1wrrw z#Ldk~(M3x9Us7lh+H7*q--1AHR!9McVpc!PL$)6zNb6Ngw?Qi#uqCk(nE@gvt| zm)|&-92R(H$jGMWi9^I>j5;c)!a|f*jT94U+K+qqM;w2OTr#;TVB}ap4JstZ5B>+gyETi`Q*Kfq z4)ng*_Qx2|w+plyw*7r<+pQD8{|sDd9e=F}#6C%HbhOA35ZneXt~;8%2VCv|;U`@( zBuDbo6pBUQ{fxdT4-DS|18Z(??R}g+09op4`35*R1jb90z3%bu{_fuXJ=5;*2f}f3 z$Ilec2LJ#724YJ`L;(H({s8{#7}SCQ000SaNLh0L04^f{04^f|c%?sf00007bV*G` z2jvV85gjnopGYwP000?uMObu0Z*6U5Zgc=ca%Ew3Wn>_CX>@2HM@dakSAh-}000E! zNkloFhDt0-ykrv0X0Gm24dg;YMxjy!(SGUg=QL&@JLamGC^m1N48IFbn#em7bFfuK?H(;RMWNYgA1yg z_d+NE*%XuoP^AJX1J(l*+udO2Kffrl!S^Jp&b!LUG#K30T!sYb=t})LaqQ9UKwIu_ zrUe519+;x{_h)CVT~<(UJQK-BZHGD2kwE0Z=mFPn-aAu0{k27iTp@C%Opovw?7!sD>{s0DQq zD~}Kz@@FoK;&Srrle6mJ#91)C25h)`TxhWsuqs%QTrwqRtV2`;j4MHvTvez6@gCS% zpfKVUZ``tJCN!2AkZ>p*RM|kVnk%2v=PqfC8V+;hwH(pdVf9LSxhCLU7Zuqd}lC9!DK0#@P9-QF}1 z5=fReciOk(v7*Xceg)Nl=BphYrKQE;v85%W^ZT7$UCFz>>F%0I730M-1|XBkW-niD zZ=W)0Y*}%%Fd_oRz?Qdm9^Y2Ks!^aP{$o>m&Fsq3<#}Gn!=L{Z5pl|(rqecE9`*JB zR}5qao_YQD;nYATY1LxY5~vbbC9pQ9SvLmx5dv$mN^Vc>AVCy3aOjtdKp&9wV54wJ zGSli(eKiwf^T7-{bkdQNJZbh8B@np z`vrbj#dQW;QRVxtxZHRydQUj@`}ym&b0(c|k+%b_K)18(5oj`SqYzrgLRZa>J*(>G z&#Rgfj~5pYZEqqE&qahE4mCEvv|{0zVa{*4w>K{dfg=J}!f<&MG*>{=c*@pQZhNnG zVnum8K4$c&a3+)CW_wqE;!bj)cFF8R$gubtI;qy5?oOQwD8K$3Z$j6n3Pz&?TRfX_W3 z>>L-mdB_2{rm(OO&cz|=yU1IC-aP62{{r}qjV%JT0sNGLuln5~8KO>#JxE4?q9NQH be4qXWXHQajJ#~#t00000NkvXXu0mjfyr5CZ diff --git a/luci-app-modem/htdocs/luci-static/resources/icons/sms2.png b/luci-app-modem/htdocs/luci-static/resources/icons/sms2.png deleted file mode 100644 index eeb13c5e674a1a826e0f8f0fdb809834922e1d3c..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1365 zcmV-b1*-aqP)EX>4Tx04R}tkv&MmKpe$iQ>7}k4(*`gkfAzR5EXHhDi*;)X)CnqU~=gfG-*gu zTpR`0f`cE6RRbkxtGNhls^O2g@DIiiS!&O&nHKjq-(z z!wTmu&T6^JTKD8H^yjpd6xV5vAciHxk$?ypRg_SMg$S)0DJGJ%A9e8$H~k56$>b`5 zkz)ZBsF0d|@IUz7t(l*ibdvm0p!>zPKSlxHF3_mi_V=-EH%AO zt%Z+(foN9LZ_VkgwU5&WAWdB@-v9@P zz*vE@*InM-)7jg_CX>@2HM@dakSAh-}0009lNkl3);i_xxh&zU`YW(NM_B_D3B3d(07uYwH%kIooE2pE9_0t8?{g8ocMJ&Yn~AB7-I z+Ae?e?(#S9$Oqf27a_h401ANtPS6r`J@AA;fvyK^5CX^ux!(_vDUoDAxb^4wd^V49 z&B%x_f{x&bU?1lm^c1sEW?}_>3}FG0Awot71m)4iqjB~q{f~ynA;AP^8^;O2qXNgQ zt}{`^QFc&vka!A}5rQKmif3{uPKfou2ROI!sA^kJ;By33^-7QeR3Ql@Hc-wZj1Xxs zGjit!w1gaDej5WWf&nGq zZ`N!m zkc$g}VtuA1;LF`L?*G&h7#1x~!NZPano6TIWNB!lWixgdD@bp#5TUq}&8xyw=XlgB zKYi|bR0NA!&E9*-fkaIzp(M#ne4n3p!Mw^>3FC9L4#RB-uU5}7bCix&OXKt222d@v~Uodcxa!gfjslTV}&Oh7^HfxJdQG= zl;LtF5)ep?Pzu2=1A(Ps@1Ci2bFD(BM7^UjpaH@nFal}FSt1LXAb~U}=O932w^k`9 z!Q(^^`j;e0A6Y8c{jZI{c~S{y%ZFJ zZteQY=9RNdw0vsBiB64t4fN_+N2Z=4sEU3nqE|j&`6JFskRLFn*FkQqzwle|{{sF2 XGLww0Jg8t@00000NkvXXu0mjfu%1_o diff --git a/luci-app-modem/htdocs/luci-static/resources/view/status/include/11_modem.js b/luci-app-modem/htdocs/luci-static/resources/view/status/include/11_modem.js new file mode 100644 index 0000000..cdd96d6 --- /dev/null +++ b/luci-app-modem/htdocs/luci-static/resources/view/status/include/11_modem.js @@ -0,0 +1,92 @@ +'use strict'; +'require baseclass'; +'require rpc'; + +var callModemInfo = rpc.declare({ + object: 'modem_ctrl', + method: 'info' +}); + +function progressbar(value, max, min, unit) { + var value = parseInt(value) || 0, + max = parseInt(max) || 100, + min = parseInt(min) || 0, + unit = unit || '', + pc = Math.floor((100 / (max - min)) * (value - min)); + + return E('div', { + 'class': 'cbi-progressbar', + 'title': '%s / %s%s (%d%%)'.format(value, max, unit,pc) + }, E('div', { 'style': 'width:%.2f%%'.format(pc) })); +} + + +return baseclass.extend({ + title: _('Modem Info'), + + load: function() { + return Promise.all([ + L.resolveDefault(callModemInfo(), {}), + ]); + }, + + render: function(data) { + + var table = E('table', { 'class': 'table' }); + try { + var infos = data[0].info + var fields = []; + for (let modem_info of infos) { + var info = modem_info.modem_info; + + for (var entry of info) { + var full_name = entry.full_name; + if (entry.value == null) { + continue + } + if ((entry.class == 'Base Information') ||(entry.class == '"SIM Information"') || (entry.class == 'Cell Information' && entry.type == 'progress_bar')) { + fields.push(_(full_name)); + fields.push(entry); + } + } + + if (fields.length == 0) { + table.appendChild(E('tr', { 'class': 'tr' }, [ + E('td', { 'class': 'td left', 'width': '100%' }, [ _('No modem information available') ]) + ])); + return table; + } + } + + + + for (var i = 0; i < fields.length; i += 2) { + let entry, type, value; + entry = fields[i + 1]; + type = entry.type; + if (type == 'progress_bar') { + value = E('td', { 'class': 'td left' }, [ + (entry.value != null) ? progressbar(entry.value, entry.max_value, entry.min_value, entry.unit) : '?' + ]) + } else { + value = E('td', { 'class': 'td left' }, [ (fields[i + 1] != null) ? entry.value : '?' ]) + } + + table.appendChild(E('tr', { 'class': 'tr' }, [ + E('td', { 'class': 'td left', 'width': '33%' }, [ fields[i] ]), + value + ])); + } + + return table; + } + catch (e) { + table.appendChild(E('tr', { 'class': 'tr' }, [ + E('td', { 'class': 'td left', 'width': '100%' }, [ _('No modem information available') ]) + ])); + return table; + } + + + } +}); diff --git a/luci-app-modem/luasrc/controller/modem.lua b/luci-app-modem/luasrc/controller/modem.lua index 50dd35d..2256aa2 100644 --- a/luci-app-modem/luasrc/controller/modem.lua +++ b/luci-app-modem/luasrc/controller/modem.lua @@ -6,69 +6,26 @@ local json = require("luci.jsonc") uci = luci.model.uci.cursor() local script_path="/usr/share/modem/" local run_path="/tmp/run/modem/" +local modem_ctrl = "/usr/share/modem/modem_ctrl.sh " function index() if not nixio.fs.access("/etc/config/modem") then return end - entry({"admin", "network", "modem"}, alias("admin", "network", "modem", "modem_info"), translate("Modem"), 100).dependent = true - --mwan配置 - entry({"admin", "network", "modem", "mwan_config"}, cbi("modem/mwan_config"), translate("Mwan Config"), 1).leaf = true + entry({"admin", "network", "modem"}, alias("admin", "network", "modem", "modem_info"), luci.i18n.translate("Modem"), 100).dependent = true --模块信息 - entry({"admin", "network", "modem", "modem_info"}, template("modem/modem_info"), translate("Modem Information"),10).leaf = true - entry({"admin", "network", "modem", "get_at_port"}, call("getATPort"), nil).leaf = true - entry({"admin", "network", "modem", "get_modem_info"}, call("getModemInfo")).leaf = true - + entry({"admin", "network", "modem", "modem_info"}, template("modem/modem_info"), luci.i18n.translate("Modem Information"),2).leaf = true + entry({"admin", "network", "modem", "get_modem_cfg"}, call("getModemCFG"), nil).leaf = true + entry({"admin", "network", "modem", "modem_ctrl"}, call("modemCtrl")).leaf = true --拨号配置 - entry({"admin", "network", "modem", "dial_overview"},cbi("modem/dial_overview"),translate("Dial Overview"),20).leaf = true + entry({"admin", "network", "modem", "dial_overview"},cbi("modem/dial_overview"),luci.i18n.translate("Dial Overview"),3).leaf = true entry({"admin", "network", "modem", "dial_config"}, cbi("modem/dial_config")).leaf = true - entry({"admin", "network", "modem", "get_modems"}, call("getModems"), nil).leaf = true - entry({"admin", "network", "modem", "get_dial_log_info"}, call("getDialLogInfo"), nil).leaf = true - entry({"admin", "network", "modem", "clean_dial_log"}, call("cleanDialLog"), nil).leaf = true - entry({"admin", "network", "modem", "status"}, call("act_status")).leaf = true - + entry({"admin", "network", "modem", "modems_dial_overview"}, call("getOverviews"), nil).leaf = true --模块调试 - entry({"admin", "network", "modem", "modem_debug"},template("modem/modem_debug"),translate("Modem Debug"),30).leaf = true - entry({"admin", "network", "modem", "quick_commands_config"}, cbi("modem/quick_commands_config")).leaf = true - entry({"admin", "network", "modem", "get_mode_info"}, call("getModeInfo"), nil).leaf = true - entry({"admin", "network", "modem", "set_mode"}, call("setMode"), nil).leaf = true - entry({"admin", "network", "modem", "get_network_prefer_info"}, call("getNetworkPreferInfo"), nil).leaf = true - entry({"admin", "network", "modem", "set_network_prefer"}, call("setNetworkPrefer"), nil).leaf = true - entry({"admin", "network", "modem", "get_lockband"}, call("getLockBand"), nil).leaf = true - entry({"admin", "network", "modem", "set_lockband"}, call("setLockBand"), nil).leaf = true - entry({"admin", "network", "modem", "get_neighbor_cellinfo"}, call("getNeighbor"), nil).leaf = true - entry({"admin", "network", "modem", "set_lock_cell"}, call("setLockCell"), nil).leaf = true - entry({"admin", "network", "modem", "get_self_test_info"}, call("getSelfTestInfo"), nil).leaf = true - entry({"admin", "network", "modem", "get_quick_commands"}, call("getQuickCommands"), nil).leaf = true + entry({"admin", "network", "modem", "modem_debug"},template("modem/modem_debug"),luci.i18n.translate("Modem Debug"),4).leaf = true entry({"admin", "network", "modem", "send_at_command"}, call("sendATCommand"), nil).leaf = true - entry({"admin", "network", "modem", "get_imei"}, call("getIMEI"), nil).leaf = true - entry({"admin", "network", "modem", "set_imei"}, call("setIMEI"), nil).leaf = true - entry({"admin", "network", "modem", "get_sim"}, call("getSIM"), nil).leaf = true - entry({"admin", "network", "modem", "set_sim"}, call("setSIM"), nil).leaf = true - -- entry({"admin", "network", "modem", "get_modem_debug_info"}, call("getModemDebugInfo"), nil).leaf = true - - --插件设置 - entry({"admin", "network", "modem", "plugin_config"},cbi("modem/plugin_config"),translate("Plugin Config"),40).leaf = true - entry({"admin", "network", "modem", "modem_config"}, cbi("modem/modem_config")).leaf = true entry({"admin", "network", "modem", "modem_scan"}, call("modemScan"), nil).leaf = true - - --插件信息 - entry({"admin", "network", "modem", "plugin_info"},template("modem/plugin_info"),translate("Plugin Info"),50).leaf = true - entry({"admin", "network", "modem", "get_plugin_info"}, call("getPluginInfo"), nil).leaf = true - - --AT命令旧界面 - entry({"admin", "network", "modem", "at_command_old"},template("modem/at_command_old")).leaf = true -end - ---[[ -@Description 判断字符串是否含有字母 -@Params - str 字符串 -]] -function hasLetters(str) - local pattern = "%a" -- 匹配字母的正则表达式 - return string.find(str, pattern) ~= nil end --[[ @@ -83,6 +40,47 @@ function shell(command) return odp end +function translate_modem_info(result) + modem_info = result["modem_info"] + response = {} + for k,entry in pairs(modem_info) do + if type(entry) == "table" then + key = entry["key"] + full_name = entry["full_name"] + if full_name then + full_name = luci.i18n.translate(full_name) + elseif key then + full_name = luci.i18n.translate(key) + end + entry["full_name"] = full_name + if entry["class"] then + entry["class"] = luci.i18n.translate(entry["class"]) + end + table.insert(response, entry) + end + end + return response +end + +function modemCtrl() + local action = http.formvalue("action") + local cfg_id = http.formvalue("cfg") + local params = http.formvalue("params") + local translate = http.formvalue("translate") + if params then + result = shell(modem_ctrl..action.." "..cfg_id.." ".."\""..params.."\"") + else + result = shell(modem_ctrl..action.." "..cfg_id) + end + if translate == "1" then + modem_more_info = json.parse(result) + modem_more_info = translate_modem_info(modem_more_info) + result = json.stringify(modem_more_info) + end + luci.http.prepare_content("application/json") + luci.http.write(result) +end + --[[ @Description 执行AT命令 @Params @@ -90,432 +88,95 @@ end at_command AT命令 ]] function at(at_port,at_command) - local command="source "..script_path.."modem_debug.sh && at "..at_port.." "..at_command + local command="source "..script_path.."modem_util.sh && at "..at_port.." "..at_command local result=shell(command) result=string.gsub(result, "\r", "") return result end ---[[ -@Description 获取制造商 -@Params - at_port AT串口 -]] -function getManufacturer(at_port) - - local manufacturer - uci:foreach("modem", "modem-device", function (modem_device) - if at_port == modem_device["at_port"] then - manufacturer=modem_device["manufacturer"] - return true --跳出循环 - end - end) - - return manufacturer -end - ---[[ -@Description 获取模组拨号模式 -@Params - at_port AT串口 - manufacturer 制造商 - platform 平台 -]] -function getMode(at_port,manufacturer,platform) - local mode="unknown" - - if at_port and manufacturer~="unknown" then - local command="source "..script_path..manufacturer..".sh && "..manufacturer.."_get_mode "..at_port.." "..platform - local result=shell(command) - mode=string.gsub(result, "\n", "") - end - - return mode -end - ---[[ -@Description 获取模组支持的拨号模式 -@Params - at_port AT串口 -]] -function getModes(at_port) - - local modes - uci:foreach("modem", "modem-device", function (modem_device) - if at_port == modem_device["at_port"] then - modes=modem_device["modes"] - return true --跳出循环 - end - end) - - return modes -end - ---[[ -@Description 获取模组连接状态 -@Params - at_port AT串口 - manufacturer 制造商 - define_connect 连接定义 -]] -function getModemConnectStatus(at_port,manufacturer,define_connect) - - local connect_status="unknown" - - if at_port and manufacturer~="unknown" then - local command="source "..script_path..manufacturer..".sh && "..manufacturer.."_get_connect_status "..at_port.." "..define_connect - local result=shell(command) - connect_status=string.gsub(result, "\n", "") - end - - return connect_status -end - ---[[ -@Description 获取模组设备信息 -@Params - at_port AT串口 -]] -function getModemDeviceInfo(at_port) - local modem_device_info={} - - uci:foreach("modem", "modem-device", function (modem_device) - if at_port == modem_device["at_port"] then - --获取数据接口 - local data_interface=modem_device["data_interface"]:upper() - --获取连接状态 - local connect_status=getModemConnectStatus(modem_device["at_port"],modem_device["manufacturer"],modem_device["define_connect"]) - - --设置值 - modem_device_info=modem_device - modem_device_info["data_interface"]=data_interface - modem_device_info["connect_status"]=connect_status - return true - end - end) - - return modem_device_info -end - ---[[ -@Description 获取模组更多信息 -@Params - at_port AT串口 - manufacturer 制造商 -]] -function getModemMoreInfo(at_port,manufacturer,platform,define_connect) - - --获取模组信息 - local command="sh "..script_path.."modem_info.sh".." "..at_port.." "..manufacturer.." "..platform.." "..define_connect - local result=shell(command) - - --设置值 - local modem_more_info=json.parse(result) - return modem_more_info -end - ---[[ -@Description 模块状态获取 -]] -function getModemInfo() - - --获取AT串口 - local at_port = http.formvalue("port") - - --获取信息 - local modem_device_info - local modem_more_info - if at_port then - modem_device_info=getModemDeviceInfo(at_port) - modem_more_info=getModemMoreInfo(at_port,modem_device_info["manufacturer"],modem_device_info["platform"],modem_device_info["define_connect"]) - end - - --设置信息 - local modem_info={} - modem_info["device_info"]=modem_device_info - modem_info["more_info"]=modem_more_info - - --设置翻译 - local translation={} - --设备信息翻译 - -- if modem_device_info then - -- local name=modem_device_info["name"] - -- translation[name]=luci.i18n.translate(name) - -- local manufacturer=modem_device_info["manufacturer"] - -- translation[manufacturer]=luci.i18n.translate(manufacturer) - -- local mode=modem_device_info["mode"] - -- translation[mode]=luci.i18n.translate(mode) - -- local data_interface=modem_device_info["data_interface"] - -- translation[data_interface]=luci.i18n.translate(data_interface) - -- local network=modem_device_info["network"] - -- translation[network]=luci.i18n.translate(network) - -- end - - --基本信息翻译 - -- if modem_more_info["base_info"] then - -- for key in pairs(modem_more_info["base_info"]) do - -- local value=modem_more_info["base_info"][key] - -- --翻译值 - -- translation[value]=luci.i18n.translate(value) - -- end - -- end - --SIM卡信息翻译 - if modem_more_info["sim_info"] then - local sim_info=modem_more_info["sim_info"] - for i = 1, #sim_info do - local info = sim_info[i] - for key in pairs(info) do - --翻译键 - translation[key]=luci.i18n.translate(key) - -- local value=info[key] - -- if hasLetters(value) then - -- --翻译值 - -- translation[value]=luci.i18n.translate(value) - -- end - end - end - end - --网络信息翻译 - if modem_more_info["network_info"] then - local network_info=modem_more_info["network_info"] - for i = 1, #network_info do - local info = network_info[i] - for key in pairs(info) do - --翻译键 - translation[key]=luci.i18n.translate(key) - -- local value=info[key] - -- if hasLetters(value) then - -- --翻译值 - -- translation[value]=luci.i18n.translate(value) - -- end - end - end - end - --小区信息翻译 - if modem_more_info["cell_info"] then - for network_mode_key in pairs(modem_more_info["cell_info"]) do - --翻译网络模式 - translation[network_mode_key]=luci.i18n.translate(network_mode_key) - if network_mode_key == "EN-DC Mode" then - local network_mode=modem_more_info["cell_info"][network_mode_key] - for i = 1, #network_mode do - for key in pairs(network_mode[i]) do - --获取每个网络类型信息 - local network_type=network_mode[i][key] - for j = 1, #network_type do - local info = network_type[j] - for key in pairs(info) do - translation[key]=luci.i18n.translate(key) - end - end - end - end - else - --获取网络类型信息 - local network_type=modem_more_info["cell_info"][network_mode_key] - for i = 1, #network_type do - local info = network_type[i] - for key in pairs(info) do - translation[key]=luci.i18n.translate(key) - end - end - end - end - end - --添加额外翻译 - translation["Unknown"]=luci.i18n.translate("Unknown") - translation["Excellent"]=luci.i18n.translate("Excellent") - translation["Good"]=luci.i18n.translate("Good") - translation["Fair"]=luci.i18n.translate("Fair") - translation["Bad"]=luci.i18n.translate("Bad") - - --整合数据 - local data={} - data["modem_info"]=modem_info - data["translation"]=translation - - -- 写入Web界面 - luci.http.prepare_content("application/json") - luci.http.write_json(data) -end --[[ @Description 获取模组信息 ]] -function getModems() - +function getOverviews() -- 获取所有模组 local modems={} - local translation={} + local logs={} uci:foreach("modem", "modem-device", function (modem_device) - -- 获取连接状态 - local connect_status=getModemConnectStatus(modem_device["at_port"],modem_device["manufacturer"],modem_device["define_connect"]) - -- 获取拨号模式 - local mode=getMode(modem_device["at_port"],modem_device["manufacturer"],modem_device["platform"]) - - -- 获取翻译 - translation[connect_status]=luci.i18n.translate(connect_status) - if modem_device["name"] then - translation[modem_device["name"]]=luci.i18n.translate(modem_device["name"]) + section_name = modem_device[".name"] + modem_name = modem_device["name"] + modem_state = modem_device["state"] + if modem_state == "disabled" then + return end - translation[mode]=luci.i18n.translate(mode) - - -- 设置值 - local modem=modem_device - modem["connect_status"]=connect_status - modem["mode"]=mode - - local modem_tmp={} - modem_tmp[modem_device[".name"]]=modem - table.insert(modems,modem_tmp) +--模组信息部分 + cmd = modem_ctrl.."base_info "..section_name + result = shell(cmd) + json_result = json.parse(result) + modem_info = json_result["modem_info"] + tmp_info = {} + name = { + type = "plain_text", + key = "name", + value = modem_name + } + table.insert(tmp_info, name) + for k,v in pairs(modem_info) do + full_name = v["full_name"] + if full_name then + v["full_name"] = luci.i18n.translate(full_name) + end + table.insert(tmp_info, v) + end + table.insert(modems, tmp_info) + --拨号日志部分 + log_path = run_path..section_name.."_dir/dial_log" + if fs.access(log_path) then + log_msg = fs.readfile(log_path) + modem_log = {} + modem_log["log_msg"] = log_msg + modem_log["section_name"] = section_name + modem_log["name"] = modem_name + table.insert(logs, modem_log) + end end) -- 设置值 local data={} data["modems"]=modems - data["translation"]=translation - - -- 写入Web界面 + data["logs"]=logs luci.http.prepare_content("application/json") luci.http.write_json(data) end ---[[ -@Description 获取拨号日志信息 -]] -function getDialLogInfo() - - local command="find "..run_path.." -name \"modem*_dial.cache\"" - local result=shell(command) +function getModemCFG() - local log_paths=string.split(result, "\n") - table.sort(log_paths) - - local logs={} - local names={} - local translation={} - for key in pairs(log_paths) do - - local log_path=log_paths[key] - - if log_path ~= "" then - -- 获取模组 - local tmp=string.gsub(log_path, run_path, "") - local modem=string.gsub(tmp, "_dial.cache", "") - local modem_name=uci:get("modem", modem, "name") - - -- 获取日志内容 - local command="cat "..log_path - log=shell(command) - - -- 排序插入 - modem_log={} - modem_log[modem]=log - table.insert(logs, modem_log) - - --设置模组名 - names[modem]=modem_name - -- 设置翻译 - translation[modem_name]=luci.i18n.translate(modem_name) - end - end - - -- 设置值 - local data={} - data["dial_log_info"]=logs - data["modem_name_info"]=names - data["translation"]=translation - - -- 写入Web界面 - luci.http.prepare_content("application/json") - luci.http.write_json(data) -end - ---[[ -@Description 清空拨号日志 -]] -function cleanDialLog() - - -- 获取拨号日志路径 - local dial_log_path = http.formvalue("path") - - -- 清空拨号日志 - local command=": > "..dial_log_path - shell(command) - - -- 设置值 - local data={} - data["clean_result"]="clean dial log" - - -- 写入Web界面 - luci.http.prepare_content("application/json") - luci.http.write_json(data) -end - ---[[ -@Description 模块列表状态函数 -]] -function act_status() - local e = {} - e.index = luci.http.formvalue("index") - e.status = luci.sys.call(string.format("busybox ps -w | grep -v 'grep' | grep '/var/etc/socat/%s' >/dev/null", luci.http.formvalue("id"))) == 0 - luci.http.prepare_content("application/json") - luci.http.write_json(e) -end - ---[[ -@Description 获取模组的备注 -@Params - network 移动网络 -]] -function getModemRemarks(network) - local remarks="" - uci:foreach("modem", "dial-config", function (config) - ---配置启用,且备注存在 - if network == config["network"] and config["enable"] == "1" then - if config["remarks"] then - remarks=" ("..config["remarks"]..")" --" (备注)" - - return true --跳出循环 - end - end - end) - return remarks -end - ---[[ -@Description 获取AT串口 -]] -function getATPort() - - local at_ports={} + local cfgs={} local translation={} uci:foreach("modem", "modem-device", function (modem_device) + modem_state = modem_device["state"] + if modem_state == "disabled" then + return + end --获取模组的备注 local network=modem_device["network"] - local remarks=getModemRemarks(network) - + local remarks=modem_device["remarks"] + local config_name=modem_device[".name"] --设置模组AT串口 - if modem_device["name"] and modem_device["at_port"] then - - local name=modem_device["name"]:upper()..remarks - if modem_device["name"] == "unknown" then - translation[modem_device["name"]]=luci.i18n.translate(modem_device["name"]) - name=modem_device["name"]..remarks - end - - local at_port = modem_device["at_port"] - --排序插入 - at_port_tmp={} - at_port_tmp[at_port]=name - table.insert(at_ports, at_port_tmp) - end + local cfg = modem_device[".name"] + local at_port=modem_device["at_port"] + local name=modem_device["name"]:upper() + local config = {} + config["name"] = name + config["at_port"] = at_port + config["cfg"] = cfg + table.insert(cfgs, config) end) -- 设置值 local data={} - data["at_ports"]=at_ports + data["cfgs"]=cfgs data["translation"]=translation -- 写入Web界面 @@ -523,384 +184,8 @@ function getATPort() luci.http.write_json(data) end ---[[ -@Description 获取拨号模式信息 -]] -function getModeInfo() - local at_port = http.formvalue("port") - - --获取值 - local mode_info={} - uci:foreach("modem", "modem-device", function (modem_device) - if at_port == modem_device["at_port"] then - - --获取制造商 - local manufacturer=modem_device["manufacturer"] - if manufacturer=="unknown" then - return true --跳出循环 - end - - --获取支持的拨号模式 - local modes=modem_device["modes"] - - --获取模组拨号模式 - local mode=getMode(at_port,manufacturer,modem_device["platform"]) - - --设置模式信息 - mode_info["mode"]=mode - mode_info["modes"]=modes - - return true --跳出循环 - end - end) - - --设置值 - local modem_debug_info={} - modem_debug_info["mode_info"]=mode_info - - -- 写入Web界面 - luci.http.prepare_content("application/json") - luci.http.write_json(modem_debug_info) -end - ---[[ -@Description 设置拨号模式 -]] -function setMode() - local at_port = http.formvalue("port") - local mode_config = http.formvalue("mode_config") - - --获取制造商 - local manufacturer=getManufacturer(at_port) - - --设置模组拨号模式 - local command="source "..script_path..manufacturer..".sh && "..manufacturer.."_set_mode "..at_port.." "..mode_config - shell(command) - - --获取设置好后的模组拨号模式 - local mode - if at_port and manufacturer and manufacturer~="unknown" then - local command="source "..script_path..manufacturer..".sh && "..manufacturer.."_get_mode "..at_port - local result=shell(command) - mode=string.gsub(result, "\n", "") - end - - -- 写入Web界面 - luci.http.prepare_content("application/json") - luci.http.write_json(mode) -end - ---[[ -@Description 获取网络偏好信息 -]] -function getNetworkPreferInfo() - local at_port = http.formvalue("port") - - --获取制造商 - local manufacturer=getManufacturer(at_port) - - --获取值 - local network_prefer_info - if manufacturer~="unknown" then - --获取模组网络偏好 - local command="source "..script_path..manufacturer..".sh && "..manufacturer.."_get_network_prefer "..at_port - local result=shell(command) - network_prefer_info=json.parse(result) - end - - --设置值 - local modem_debug_info={} - modem_debug_info["network_prefer_info"]=network_prefer_info - - -- 写入Web界面 - luci.http.prepare_content("application/json") - luci.http.write_json(modem_debug_info) -end - ---[[ -@Description 设置网络偏好 -]] -function setNetworkPrefer() - local at_port = http.formvalue("port") - local network_prefer_config = json.stringify(http.formvalue("prefer_config")) - - --获取制造商 - local manufacturer=getManufacturer(at_port) - - --设置模组网络偏好 - local command="source "..script_path..manufacturer..".sh && "..manufacturer.."_set_network_prefer "..at_port.." "..network_prefer_config - shell(command) - - --获取设置好后的模组网络偏好 - local network_prefer={} - if at_port and manufacturer and manufacturer~="unknown" then - local command="source "..script_path..manufacturer..".sh && "..manufacturer.."_get_network_prefer "..at_port - local result=shell(command) - network_prefer=json.parse(result) - end - - -- 写入Web界面 - luci.http.prepare_content("application/json") - luci.http.write_json(network_prefer) -end - -function getNeighbor() - local at_port = http.formvalue("port") - local manufacturer = getManufacturer(at_port) - local command="source "..script_path..manufacturer..".sh && "..manufacturer.."_get_neighborcell "..at_port - local result=shell(command) - local neighbor_cellinfo=json.parse(result) - luci.http.prepare_content("application/json") - luci.http.write_json(neighbor_cellinfo) -end - -function setLockCell() - local at_port = http.formvalue("port") - local manufacturer = getManufacturer(at_port) - local func = http.formvalue("func") - local pci = http.formvalue("pci") == nil and 0 or http.formvalue("pci") - local arfcn = http.formvalue("arfcn") == nil and 0 or http.formvalue("arfcn") - local scs = http.formvalue("scs") == nil and 0 or http.formvalue("scs") - local nrband = http.formvalue("nrband") == nil and 0 or http.formvalue("nrband") - local celltype = http.formvalue("celltype") == nil and 0 or http.formvalue("celltype") - response={} - - local command="source "..script_path..manufacturer..".sh && "..manufacturer.."_setlockcell "..at_port.." "..func .." "..celltype.." "..arfcn.." "..pci.." "..scs.." "..nrband - local command=string.format("source %s%s.sh && %s_setlockcell \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\"",script_path,manufacturer,manufacturer,at_port,func,celltype,arfcn,pci,scs,nrband) - local result=shell(command) - response["response"]=result - response["time"]=os.date("%Y-%m-%d %H:%M:%S") - - luci.http.prepare_content("application/json") - luci.http.write_json(response) -end - -function getLockBand() - local at_port = http.formvalue("port") - local manufacturer = getManufacturer(at_port) - local command="source "..script_path..manufacturer..".sh && "..manufacturer.."_get_lockband "..at_port - local result=shell(command) - --获取锁频配置 - local lock_band_config={} - if at_port and manufacturer and manufacturer~="unknown" then - local command="source "..script_path..manufacturer..".sh && "..manufacturer.."_get_lockband "..at_port - local result=shell(command) - lock_band_config=json.parse(result) - end - luci.http.prepare_content("application/json") - luci.http.write_json(lock_band_config) -end -function setLockBand() - local at_port = http.formvalue("port") - local lock_band_config = http.formvalue("lock_band_config") - local rat = http.formvalue("rat") - - --获取制造商 - local manufacturer = getManufacturer(at_port) - local command1="source "..script_path..manufacturer..".sh && "..manufacturer.."_set_lockband "..at_port.." "..lock_band_config.." "..rat - local result1=shell(command1) - --获取锁频配置 - local lock_band_config={} - if at_port and manufacturer and manufacturer~="unknown" then - local command="source "..script_path..manufacturer..".sh && "..manufacturer.."_get_lockband "..at_port - local result=shell(command) - lock_band_config=json.parse(result) - end - lock_band_config["command"]=command1 - lock_band_config["result"]=result1 - luci.http.prepare_content("application/json") - luci.http.write_json(lock_band_config) -end - -function getIMEI() - local at_port = http.formvalue("port") - local manufacturer = getManufacturer(at_port) - local command="source "..script_path..manufacturer..".sh && "..manufacturer.."_get_imei "..at_port - local result=shell(command) - local result_json = {} - result_json["imei"] = result - luci.http.prepare_content("application/json") - luci.http.write_json(result_json) - -end - -function getSimSlot(sim_path) - local sim_slot = fs.readfile(sim_path) - local current_slot = string.match(sim_slot, "%d") - if current_slot == "0" then - return "SIM2" - else - return "SIM1" - end -end - -function getNextBootSlot() - local fw_print_cmd = "fw_printenv -n sim2" - local nextboot_slot = shell(fw_print_cmd) - if nextboot_slot == "" then - return "SIM1" - else - return "SIM2" - end -end - -function writeJsonResponse(current_slot, nextboot_slot) - local result_json = {} - result_json["current_slot"] = current_slot - result_json["nextboot_slot"] = nextboot_slot - luci.http.prepare_content("application/json") - luci.http.write_json(result_json) -end - -function getSIM() - local sim_path = "/sys/class/gpio/sim/value" - local current_slot = getSimSlot(sim_path) - local nextboot_slot = getNextBootSlot() - writeJsonResponse(current_slot, nextboot_slot) -end - -function setSIM() - local sim_gpio = "/sys/class/gpio/sim/value" - local modem_gpio = "/sys/class/gpio/4g/value" - local sim_slot = http.formvalue("slot") - local pre_detect = getSimSlot(sim_gpio) - - local reset_module = 1 - if pre_detect == sim_slot then - reset_module = 0 - end - if sim_slot == "SIM1" then - sysfs_cmd = "echo 1 >"..sim_gpio - fw_setenv_cmd = "fw_setenv sim2" - elseif sim_slot == "SIM2" then - sysfs_cmd = "echo 0 >"..sim_gpio - fw_setenv_cmd = "fw_setenv sim2 1" - end - shell(sysfs_cmd) - shell(fw_setenv_cmd) - if reset_module == 1 then - shell("echo 0 >"..modem_gpio) - os.execute("sleep 1") - shell("echo 1 >"..modem_gpio) - end - local current_slot = getSimSlot(sim_gpio) - local nextboot_slot = getNextBootSlot() - writeJsonResponse(current_slot, nextboot_slot) -end - -function setIMEI() - local at_port = http.formvalue("port") - local imei = http.formvalue("imei") - local manufacturer = getManufacturer(at_port) - local command="source "..script_path..manufacturer..".sh && "..manufacturer.."_set_imei "..at_port .." "..imei - shell(command) - local command1="source "..script_path..manufacturer..".sh && "..manufacturer.."_get_imei "..at_port - local result=shell(command1) - local result_json = {} - result_json["imei"] = result - luci.http.prepare_content("application/json") - luci.http.write_json(result_json) -end - ---[[ -@Description 获取自检信息 -]] -function getSelfTestInfo() - local at_port = http.formvalue("port") - - --获取制造商 - local manufacturer=getManufacturer(at_port) - - --获取值 - local self_test_info={} - if manufacturer~="unknown" then - --获取模组电压 - local command="source "..script_path..manufacturer..".sh && "..manufacturer.."_get_voltage "..at_port - local result=shell(command) - self_test_info["voltage"]=json.parse(result) - - --获取模组温度 - command="source "..script_path..manufacturer..".sh && "..manufacturer.."_get_temperature "..at_port - result=shell(command) - self_test_info["temperature"]=json.parse(result) - end - - --设置值 - local modem_debug_info={} - modem_debug_info["self_test_info"]=self_test_info - - -- 写入Web界面 - luci.http.prepare_content("application/json") - luci.http.write_json(modem_debug_info) -end - ---[[ -@Description 获取快捷命令 -]] -function getQuickCommands() - - --获取快捷命令选项 - local quick_option = http.formvalue("option") - --获取AT串口 - local at_port = http.formvalue("port") - - local manufacturer - local platform - uci:foreach("modem", "modem-device", function (modem_device) - if at_port == modem_device["at_port"] then - --获取制造商 - manufacturer=modem_device["manufacturer"] - --获取平台 - platform=modem_device["platform"] - return true --跳出循环 - end - end) - - --未适配模组时,快捷命令选项为自定义 - if manufacturer=="unknown" or manufacturer=="unknown" then - quick_option="custom" - end - - local quick_commands={} - local commands={} - if quick_option=="auto" then - - --获取通用模组AT命令 - local command="jq '.quick_commands.general' \""..script_path.."at_commands.json\"" - local result=shell(command) - local general_commands=json.parse(result) - - --获取特殊模组AT命令 - command="jq '.quick_commands."..manufacturer.."."..platform.."' \""..script_path.."at_commands.json\"" - result=shell(command) - local special_commands=json.parse(result) - - --把通用命令和特殊命令整合到一起 - for i = 1, #special_commands do - local special_command = special_commands[i] - table.insert(general_commands,special_command) - end - - quick_commands["quick_commands"]=general_commands - else - uci:foreach("custom_at_commands", "custom-commands", function (custom_commands) - local command={} - command[custom_commands["description"]]=custom_commands["command"] - table.insert(commands,command) - end) - quick_commands["quick_commands"]=commands - end - - -- 写入Web界面 - luci.http.prepare_content("application/json") - luci.http.write_json(quick_commands) -end - ---[[ -@Description 发送AT命令 -]] function sendATCommand() local at_port = http.formvalue("port") local at_command = http.formvalue("command") @@ -916,170 +201,14 @@ function sendATCommand() luci.http.write_json(response) end ---[[ -@Description 获取模组调试信息 -]] --- function getModemDebugInfo() --- local at_port = http.formvalue("port") - --- --获取制造商 --- local manufacturer=getManufacturer(at_port) - --- --获取值 --- local mode_info={} --- local network_prefer_info={} --- local self_test_info={} --- if manufacturer~="unknown" then --- mode_info=getModeInfo(at_port,manufacturer) --- network_prefer_info=getNetworkPreferInfo(at_port,manufacturer) --- self_test_info=getSelfTestInfo(at_port,manufacturer) --- end - --- -- 设置值 --- local modem_debug_info={} --- modem_debug_info["mode_info"]=mode_info --- modem_debug_info["network_prefer_info"]=network_prefer_info --- modem_debug_info["self_test_info"]=self_test_info - --- -- 写入Web界面 --- luci.http.prepare_content("application/json") --- luci.http.write_json(modem_debug_info) --- end - --[[ @Description 模组扫描 ]] function modemScan() - local command="source "..script_path.."modem_scan.sh && modem_scan" + local command=script_path.."modem_scan.sh scan" local result=shell(command) - -- 写入Web界面 luci.http.prepare_content("application/json") luci.http.write_json(result) end - ---[[ -@Description 设置插件版本信息 -@Params - info 信息 -]] -function setPluginVersionInfo(info) - - -- 正则表达式 - local version_regular_expression="[0-9]+.[0-9]+.[0-9]+" - - for key in pairs(info) do - - -- 获取插件版本 - local command="opkg list-installed | grep -oE '"..key.." - "..version_regular_expression.."' | awk -F' ' '{print $3}' | tr -d '\n'" - local plugin_version=shell(command) - - if plugin_version~="" then - info[key]=plugin_version - end - end - -end - ---[[ -@Description 获取内核模块状态 -@Params - result 命令返回值 -]] -function getModelStatus(result) - local model_status="Not loaded" - - if result~="" then - model_status="Loaded" - end - - return model_status -end - ---[[ -@Description 设置内核模块状态 -@Params - info 信息 -]] -function setModelStatus(info) - - for key in pairs(info) do - - -- 获取内核模块名 - local model_name=key:gsub(".ko","") - - local command="lsmod | grep -oE '"..model_name.." '" - local result=shell(command) - local model_status=getModelStatus(result) - - -- 修改信息表 - info[key]=model_status - end - -end - ---[[ -@Description 获取插件信息 -]] -function getPluginInfo() - - -- 设置翻译 - translation={} - translation["Unknown"]=luci.i18n.translate("Unknown") - translation["Not installed"]=luci.i18n.translate("Not installed") - translation["Loaded"]=luci.i18n.translate("Loaded") - translation["Not loaded"]=luci.i18n.translate("Not loaded") - - -- 获取插件信息 - local plugin_info={} - plugin_info["luci-app-modem"]="Unknown" - setPluginVersionInfo(plugin_info) - - -- 获取拨号工具信息 - local dial_tool_info={} - dial_tool_info["quectel-CM-5G"]="Not installed" - dial_tool_info["modemmanager"]="Not installed" - setPluginVersionInfo(dial_tool_info) - - -- 获取通用驱动信息 - local general_driver_info={} - general_driver_info["usbnet.ko"]="Not loaded" - general_driver_info["option.ko"]="Not loaded" - -- general_driver_info["qcserial.ko"]="Not loaded" - setModelStatus(general_driver_info) - - -- 获取模组USB驱动信息 - local usb_driver_info={} - usb_driver_info["qmi_wwan.ko"]="Not loaded" - usb_driver_info["GobiNet.ko"]="Not loaded" - usb_driver_info["cdc_ether.ko"]="Not loaded" - usb_driver_info["cdc_mbim.ko"]="Not loaded" - usb_driver_info["rndis_host.ko"]="Not loaded" - usb_driver_info["cdc_ncm.ko"]="Not loaded" - setModelStatus(usb_driver_info) - - -- 获取模组PCIE驱动信息 - local pcie_driver_info={} - pcie_driver_info["mhi_net.ko"]="Not loaded" - pcie_driver_info["qrtr_mhi.ko"]="Not loaded" - pcie_driver_info["mhi_pci_generic.ko"]="Not loaded" - pcie_driver_info["mhi_wwan_mbim.ko"]="Not loaded" - pcie_driver_info["mhi_wwan_ctrl.ko"]="Not loaded" - pcie_driver_info["pcie_mhi.ko"]="Not loaded" - pcie_driver_info["mtk_pcie_wwan_m80.ko"]="Not loaded" - setModelStatus(pcie_driver_info) - - -- 设置值 - local data={} - data["translation"]=translation - data["plugin_info"]=plugin_info - data["dial_tool_info"]=dial_tool_info - data["general_driver_info"]=general_driver_info - data["usb_driver_info"]=usb_driver_info - data["pcie_driver_info"]=pcie_driver_info - - -- 写入Web界面 - luci.http.prepare_content("application/json") - luci.http.write_json(data) -end diff --git a/luci-app-modem/luasrc/model/cbi/modem/dial_config.lua b/luci-app-modem/luasrc/model/cbi/modem/dial_config.lua index cf1fdca..3eb458f 100644 --- a/luci-app-modem/luasrc/model/cbi/modem/dial_config.lua +++ b/luci-app-modem/luasrc/model/cbi/modem/dial_config.lua @@ -14,7 +14,7 @@ s:tab("advanced", translate("Advanced Settings")) --------general-------- -- 是否启用 -enable = s:taboption("general", Flag, "enable", translate("Enable")) +enable = s:taboption("general", Flag, "enable_dial", translate("enable_dial")) enable.default = "0" enable.rmempty = false @@ -22,82 +22,23 @@ enable.rmempty = false remarks = s:taboption("general", Value, "remarks", translate("Remarks")) remarks.rmempty = true --- 移动网络 --- network = s:taboption("general", Value, "network", translate("Mobile Network")) -network = s:taboption("general", ListValue, "network", translate("Mobile Network")) --- network.default = "" -network.rmempty = false +-- AT串口 +at_port = s:taboption("general",Value, "at_port", translate("AT Port")) +at_port.placeholder = translate("Not null") +at_port.rmempty = false --- 获取移动网络,并显示设备名 -function getMobileNetwork() - local modem_number=uci:get('modem','global','modem_number') - if modem_number == "0" then - network:value("",translate("Mobile network not found")) - end - - return - -- for i=0,modem_number-1 do - -- --获取模块名 - -- local modem_name = uci:get('modem','modem'..i,'name') - -- if modem_name == nil then - -- modem_name = "unknown" - -- end - -- --设置网络 - -- modem_network = uci:get('modem','modem'..i,'network') - -- if modem_network ~= nil then - -- network:value(modem_network,modem_network.." ("..translate(modem_name:upper())..")") - -- end - -- end - - uci:foreach("modem", "modem-device", function (modem_device) - - --获取模块名 - local modem_name=modem_device["name"] - --获取网络 - local modem_network=modem_device["network"] - - --设置网络值 - network:value(modem_network,modem_network.." ("..translate(modem_name:upper())..")") - end) -end - -getMobileNetwork() - --- 拨号模式 --- mode = s:taboption("general", ListValue, "mode", translate("Mode")) --- mode.rmempty = false --- mode.description = translate("Only display the modes available for the adaptation modem") --- local modes = {"qmi","gobinet","ecm","mbim","rndis","ncm"} --- for i in ipairs(modes) do --- mode:value(modes[i],string.upper(modes[i])) --- end - --- 添加获取拨号模式信息 --- m:append(Template("modem/mode_info")) - ---------advanced-------- - --- 拨号工具 -dial_tool = s:taboption("advanced", ListValue, "dial_tool", translate("Dial Tool")) -dial_tool.description = translate("After switching the dialing tool, it may be necessary to restart the module or restart the router to recognize the module.") -dial_tool.rmempty = true -dial_tool:value("", translate("Auto Choose")) -dial_tool:value("quectel-CM", translate("quectel-CM")) -dial_tool:value("mmcli", translate("mmcli")) +ra_master = s:taboption("advanced", Flag, "ra_master", translate("RA Master")) +ra_master.description = translate("After checking, This interface will enable IPV6 RA Master.Only one interface can be set to RA Master.") +ra_master.default = "0" -- 网络类型 pdp_type= s:taboption("advanced", ListValue, "pdp_type", translate("PDP Type")) pdp_type.default = "ipv4v6" pdp_type.rmempty = false -pdp_type:value("ipv4", translate("IPv4")) +pdp_type:value("ip", translate("IPv4")) pdp_type:value("ipv6", translate("IPv6")) pdp_type:value("ipv4v6", translate("IPv4/IPv6")) --- 网络桥接 -network_bridge = s:taboption("advanced", Flag, "network_bridge", translate("Network Bridge")) -network_bridge.description = translate("After checking, enable network interface bridge.") -network_bridge.default = "0" -network_bridge.rmempty = false -- 接入点 apn = s:taboption("advanced", Value, "apn", translate("APN")) @@ -131,13 +72,54 @@ password:depends("auth", "both") password:depends("auth", "pap") password:depends("auth", "chap") +pincode = s:taboption("advanced", Value, "pincode", translate("PIN Code")) +pincode.description = translate("If the PIN code is not set, leave it blank.") + +--卡2 +apn = s:taboption("advanced", Value, "apn2", translate("APN").." 2") +apn.description = translate("If solt 2 config is not set,will use slot 1 config.") +apn.default = "" +apn.rmempty = true +apn:value("", translate("Auto Choose")) +apn:value("cmnet", translate("China Mobile")) +apn:value("3gnet", translate("China Unicom")) +apn:value("ctnet", translate("China Telecom")) +apn:value("cbnet", translate("China Broadcast")) +apn:value("5gscuiot", translate("Skytone")) + +auth = s:taboption("advanced", ListValue, "auth2", translate("Authentication Type").. " 2") +auth.default = "none" +auth.rmempty = false +auth:value("none", translate("NONE")) +auth:value("both", translate("PAP/CHAP (both)")) +auth:value("pap", "PAP") +auth:value("chap", "CHAP") + +username = s:taboption("advanced", Value, "username2", translate("PAP/CHAP Username").. " 2") +username.rmempty = true +username:depends("auth2", "both") +username:depends("auth2", "pap") +username:depends("auth2", "chap") + +password = s:taboption("advanced", Value, "password2", translate("PAP/CHAP Password").. " 2") +password.rmempty = true +password.password = true +password:depends("auth2", "both") +password:depends("auth2", "pap") +password:depends("auth2", "chap") + +pincode = s:taboption("advanced", Value, "pincode2", translate("PIN Code").. " 2") +pincode.description = translate("If the PIN code is not set, leave it blank.") + +metric = s:taboption("advanced", Value, "metric", translate("Metric")) +metric.description = translate("The metric value is used to determine the priority of the route. The smaller the value, the higher the priority. Cannot duplicate.") +metric.default = "10" + -- 配置ID id = s:taboption("advanced", ListValue, "id", translate("Config ID")) id.rmempty = false id:value(arg[1]) -- uci:set('modem',arg[1],'id',arg[1]) --- 隐藏配置ID -m:append(Template("modem/hide_dial_config_id")) return m diff --git a/luci-app-modem/luasrc/model/cbi/modem/dial_overview.lua b/luci-app-modem/luasrc/model/cbi/modem/dial_overview.lua index ede2baf..1ef9dbf 100644 --- a/luci-app-modem/luasrc/model/cbi/modem/dial_overview.lua +++ b/luci-app-modem/luasrc/model/cbi/modem/dial_overview.lua @@ -11,63 +11,53 @@ s = m:section(NamedSection, "global", "global", translate("Global Config")) s.anonymous = true s.addremove = false +-- 模组扫描 +o = s:option(Button, "modem_scan", translate("Modem Scan")) +o.template = "modem/modem_scan" + +-- 启用手动配置 +o = s:option(Flag, "manual_configuration", translate("Manual Configuration")) +o.rmempty = false +o.description = translate("Enable the manual configuration of modem information").." " translate("(After enable, the automatic scanning and configuration function for modem information will be disabled)") + + o = s:option(Flag, "enable_dial", translate("Enable Dial")) o.rmempty = false o.description = translate("Enable dial configurations") --- 添加模块状态 -m:append(Template("modem/modem_status")) +o = s:option(Button, "reload_dial", translate("Reload Dial Configurations")) +o.inputstyle = "apply" +o.description = translate("Manually Reload dial configurations When the dial configuration fails to take effect") +o.write = function() + sys.call("/etc/init.d/modem_network reload") + luci.http.redirect(d.build_url("admin", "network", "modem", "dial_overview")) +end s = m:section(TypedSection, "modem-device", translate("Config List")) -s.anonymous = true s.addremove = ture -s.template = "modem/tblsection" +s.template = "cbi/tblsection" s.extedit = d.build_url("admin", "network", "modem", "dial_config", "%s") --- function s.create(uci, t) --- local uuid = string.gsub(luci.sys.exec("echo -n $(cat /proc/sys/kernel/random/uuid)"), "-", "") --- t = uuid --- TypedSection.create(uci, t) --- luci.http.redirect(uci.extedit:format(t)) --- end --- function s.remove(uci, t) --- uci.map.proceed = true --- uci.map:del(t) --- luci.http.redirect(d.build_url("admin", "network", "modem","dial_overview")) --- end - o = s:option(Flag, "enable_dial", translate("enable_dial")) o.width = "5%" o.rmempty = false --- o = s:option(DummyValue, "status", translate("Status")) --- o.template = "modem/status" --- o.value = translate("Collecting data...") +o = s:option(DummyValue, "name", translate("Modem Name")) +o.cfgvalue = function(t, n) + local name = (Value.cfgvalue(t, n) or "") + return name:upper() +end o = s:option(DummyValue, "remarks", translate("Remarks")) -o = s:option(DummyValue, "network", translate("Mobile Network")) +o = s:option(DummyValue, "state", translate("Modem Status")) o.cfgvalue = function(t, n) - -- 检测移动网络是否存在 - local network = (Value.cfgvalue(t, n) or "") - local odpall = io.popen("ls /sys/class/net/ | grep -w "..network.." | wc -l") - local odp = odpall:read("*a"):gsub("\n","") - odpall:close() - if odp ~= "0" then - return network - else - return translate("The network device was not found") - end + local name = translate(Value.cfgvalue(t, n) or "") + return name:upper() end -o = s:option(DummyValue, "dial_tool", translate("Dial Tool")) -o.cfgvalue = function(t, n) - local dial_tool = (Value.cfgvalue(t, n) or "") - if dial_tool == "" then - dial_tool = translate("Auto Choose") - end - return translate(dial_tool) -end + + o = s:option(DummyValue, "pdp_type", translate("PDP Type")) @@ -81,9 +71,6 @@ o.cfgvalue = function(t, n) return pdp_type end -o = s:option(Flag, "network_bridge", translate("Network Bridge")) -o.width = "5%" -o.rmempty = false o = s:option(DummyValue, "apn", translate("APN")) o.cfgvalue = function(t, n) @@ -94,9 +81,17 @@ o.cfgvalue = function(t, n) return apn end +remove_btn = s:option(Button, "_remove", translate("Remove")) +remove_btn.inputstyle = "remove" +function remove_btn.write(self, section) + local shell + shell="/usr/share/modem/modem_scan.sh remove "..section + luci.sys.call(shell) + --refresh the page + luci.http.redirect(d.build_url("admin", "network", "modem", "dial_overview")) +end -- 添加模块拨号日志 -m:append(Template("modem/modem_dial_log")) +m:append(Template("modem/dial_overview")) --- m:append(Template("modem/list_status")) return m diff --git a/luci-app-modem/luasrc/model/cbi/modem/modem_config.lua b/luci-app-modem/luasrc/model/cbi/modem/modem_config.lua deleted file mode 100644 index 8eca767..0000000 --- a/luci-app-modem/luasrc/model/cbi/modem/modem_config.lua +++ /dev/null @@ -1,162 +0,0 @@ -local dispatcher = require "luci.dispatcher" -local uci = require "luci.model.uci".cursor() -local sys = require "luci.sys" -local json = require("luci.jsonc") -local script_path="/usr/share/modem/" - ---[[ -@Description 执行Shell脚本 -@Params - command sh命令 -]] -function shell(command) - local odpall = io.popen(command) - local odp = odpall:read("*a") - odpall:close() - return odp -end - ---[[ -@Description 获取支持的模组信息 -@Params - data_interface 数据接口 -]] -function getSupportModems(data_interface) - local command="cat "..script_path.."modem_support.json" - local result=json.parse(shell(command)) - return result["modem_support"][data_interface] -end - ---[[ -@Description 按照制造商给模组分类 -]] -function getManufacturers() - - local manufacturers={} - - -- 获取支持的模组 - local support_modem=getSupportModems("usb") - -- USB - for modem in pairs(support_modem) do - - local manufacturer=support_modem[modem]["manufacturer"] - if manufacturers[manufacturer] then - -- 直接插入 - table.insert(manufacturers[manufacturer],modem) - else - -- 不存在先创建一个空表 - local tmp={} - table.insert(tmp,modem) - manufacturers[manufacturer]=tmp - end - end - - -- 获取支持的模组 - local support_modem=getSupportModems("pcie") - -- PCIE - for modem in pairs(support_modem) do - - local manufacturer=support_modem[modem]["manufacturer"] - if manufacturers[manufacturer] then - -- 直接插入 - table.insert(manufacturers[manufacturer],modem) - else - -- 不存在先创建一个空表 - local tmp={} - table.insert(tmp,modem) - manufacturers[manufacturer]=tmp - end - end - - return manufacturers -end - -m = Map("modem", translate("Modem Config")) -m.redirect = dispatcher.build_url("admin", "network", "modem","plugin_config") - -s = m:section(NamedSection, arg[1], "modem-device", "") -s.addremove = false -s.dynamic = false - --- 手动配置 -manual = s:option(Flag, "manual", translate("Manual")) -manual.default = "1" -manual.rmempty = false --- uci:set('modem','modem-device','manual',1) - --- 隐藏手动配置 -m:append(Template("modem/hide_manual_config_modem")) - --- 移动网络 -mobile_network = s:option(ListValue, "network", translate("Mobile Network")) -mobile_network.rmempty = true - --- 获取移动网络 -function getMobileNetwork() - - --获取所有的网络接口 - local networks = sys.exec("ls -l /sys/class/net/ 2>/dev/null |awk '{print $9}' 2>/dev/null") - - --遍历所有网络接口 - for network in string.gmatch(networks, "%S+") do - - -- 只处理最上级的网络设备 - -- local count=$(echo "${network_path}" | grep -o "/net" | wc -l) - -- [ "$count" -ge "2" ] && return - - -- 获取网络设备路径 - local command="readlink -f /sys/class/net/"..network - local network_path=shell(command) - - -- 判断路径是否带有usb(排除其他eth网络设备) - local flag="0" - if network_path:find("eth") and not network_path:find("usb") then - flag="1" - end - - if flag=="0" then - if network:find("usb") or network:find("wwan") or network:find("eth") then - --设置USB移动网络 - mobile_network:value(network) - elseif network:find("mhi_hwip") or network:find("rmnet_mhi") then - --设置PCIE移动网络 - mobile_network:value(network) - end - end - - end -end - -getMobileNetwork() - --- 模组名称 -name = s:option(ListValue, "name", translate("Modem Name")) -name.placeholder = translate("Not null") -name.rmempty = false - --- 按照制造商给模组分类 -local manufacturers=getManufacturers() - -for key in pairs(manufacturers) do - local modems=manufacturers[key] - -- 排序 - table.sort(modems) - - for i in pairs(modems) do - -- 首字母大写 - local first_str=string.sub(key, 1, 1) - local manufacturer = string.upper(first_str)..string.sub(key, 2) - -- 设置值 - name:value(modems[i],manufacturer.." "..modems[i]:upper()) - end -end - --- AT串口 -at_port = s:option(Value, "at_port", translate("AT Port")) -at_port.placeholder = translate("Not null") -at_port.rmempty = false - -enable_dial = s:option(Flag, "enable_dial", translate("enable_dial")) -enable_dial.default = 1 -enable_dial.rmempty = false -return m diff --git a/luci-app-modem/luasrc/model/cbi/modem/plugin_config.lua b/luci-app-modem/luasrc/model/cbi/modem/plugin_config.lua deleted file mode 100644 index 2fea5e5..0000000 --- a/luci-app-modem/luasrc/model/cbi/modem/plugin_config.lua +++ /dev/null @@ -1,78 +0,0 @@ -local d = require "luci.dispatcher" -local uci = luci.model.uci.cursor() -local sys = require "luci.sys" -local script_path="/usr/share/modem/" - -m = Map("modem") -m.title = translate("Plugin Config") -m.description = translate("Check and modify the plugin configuration") - -font_red = [[]] -font_off = [[]] -bold_on = [[]] -bold_off = [[]] - ---全局配置 -s = m:section(TypedSection, "global", translate("Global Config")) -s.anonymous = true -s.addremove = false - --- 模组扫描 -o = s:option(Button, "modem_scan", translate("Modem Scan")) -o.template = "modem/modem_scan" - --- 启用手动配置 -o = s:option(Flag, "manual_configuration", font_red..bold_on..translate("Manual Configuration")..bold_off..font_off) -o.rmempty = false -o.description = translate("Enable the manual configuration of modem information").." "..font_red..bold_on.. translate("(After enable, the automatic scanning and configuration function for modem information will be disabled)")..bold_off..font_off - --- 配置模组信息 -s = m:section(TypedSection, "modem-device", translate("Modem Config")) -s.anonymous = true -s.addremove = true --- s.sortable = true -s.template = "modem/tblsection" -s.extedit = d.build_url("admin", "network", "modem", "modem_config", "%s") - -function s.create(uci, t) - -- 获取模组序号 - -- local modem_no=tonumber(uci.map:get("@global[0]","modem_number")) -- 将字符串转换为数字类型 - local modem_no=0 - local uci_tmp=luci.model.uci.cursor() - uci_tmp:foreach("modem", "modem-device", function (modem_device) - modem_no=modem_no+1 - end) - - t="modem"..modem_no - TypedSection.create(uci, t) - -- 设置手动配置 - -- uci.map:set(t,"manual","1") - luci.http.redirect(uci.extedit:format(t)) -end - -function s.remove(uci, t) - uci.map.proceed = true - uci.map:del(t) - luci.http.redirect(d.build_url("admin", "network", "modem","plugin_config")) -end - --- 移动网络 -o = s:option(DummyValue, "network", translate("Network")) - --- 模组名称 -o = s:option(DummyValue, "name", translate("Modem Name")) -o.cfgvalue = function(t, n) - local name = (Value.cfgvalue(t, n) or "") - return name:upper() -end - --- AT串口 -o = s:option(DummyValue, "at_port", translate("AT Port")) - -o = s:option(Flag,'enable_dial',translate('Enable Dial')) --- o = s:option(Value, "at_port", translate("AT Port")) --- o.placeholder = translate("Not null") --- o.rmempty = false --- o.optional = false - -return m diff --git a/luci-app-modem/luasrc/model/cbi/modem/quick_commands_config.lua b/luci-app-modem/luasrc/model/cbi/modem/quick_commands_config.lua deleted file mode 100644 index fabc3c9..0000000 --- a/luci-app-modem/luasrc/model/cbi/modem/quick_commands_config.lua +++ /dev/null @@ -1,30 +0,0 @@ --- Copyright 2024 Siriling - -local dispatcher = require "luci.dispatcher" -local fs = require "nixio.fs" -local http = require "luci.http" -local uci = require "luci.model.uci".cursor() - -m = Map("custom_at_commands") -m.title = translate("Custom quick commands") -m.description = translate("Customize your quick commands") -m.redirect = dispatcher.build_url("admin", "network", "modem","modem_debug") - --- 自定义命令 -- -s = m:section(TypedSection, "custom-commands", translate("Custom Commands")) -s.anonymous = true -s.addremove = true -s.sortable = true -s.template = "modem/tblsection_command" - -description = s:option(Value, "description", translate("Description")) -description.placeholder = translate("Not null") -description.rmempty = true -description.optional = false - -command = s:option(Value, "command", translate("Command")) -command.placeholder = translate("Not null") -command.rmempty = true -command.optional = false - -return m diff --git a/luci-app-modem/luasrc/view/modem/at_command_old.htm b/luci-app-modem/luasrc/view/modem/at_command_old.htm deleted file mode 100644 index 000d10c..0000000 --- a/luci-app-modem/luasrc/view/modem/at_command_old.htm +++ /dev/null @@ -1,290 +0,0 @@ -<%+header%> - - - - - -

<%:AT Commands%>

-
<%:Debug Your Module%>
- -
-
-

<%:Message%>

- - - - -
-
- <%:Loading%> - <%:Loading modem%>... -
-
-
-
- - - -<%+footer%> - diff --git a/luci-app-modem/luasrc/view/modem/dial_overview.htm b/luci-app-modem/luasrc/view/modem/dial_overview.htm new file mode 100644 index 0000000..99e6f25 --- /dev/null +++ b/luci-app-modem/luasrc/view/modem/dial_overview.htm @@ -0,0 +1,351 @@ + + diff --git a/luci-app-modem/luasrc/view/modem/hide_dial_config_id.htm b/luci-app-modem/luasrc/view/modem/hide_dial_config_id.htm deleted file mode 100644 index ac396be..0000000 --- a/luci-app-modem/luasrc/view/modem/hide_dial_config_id.htm +++ /dev/null @@ -1,20 +0,0 @@ - \ No newline at end of file diff --git a/luci-app-modem/luasrc/view/modem/hide_manual_config_modem.htm b/luci-app-modem/luasrc/view/modem/hide_manual_config_modem.htm deleted file mode 100644 index 2106e08..0000000 --- a/luci-app-modem/luasrc/view/modem/hide_manual_config_modem.htm +++ /dev/null @@ -1,19 +0,0 @@ - diff --git a/luci-app-modem/luasrc/view/modem/list_status.htm b/luci-app-modem/luasrc/view/modem/list_status.htm deleted file mode 100644 index 0d7a0bc..0000000 --- a/luci-app-modem/luasrc/view/modem/list_status.htm +++ /dev/null @@ -1,19 +0,0 @@ - diff --git a/luci-app-modem/luasrc/view/modem/mode_info.htm b/luci-app-modem/luasrc/view/modem/mode_info.htm deleted file mode 100644 index 77431bc..0000000 --- a/luci-app-modem/luasrc/view/modem/mode_info.htm +++ /dev/null @@ -1,51 +0,0 @@ - \ No newline at end of file diff --git a/luci-app-modem/luasrc/view/modem/modem_debug.htm b/luci-app-modem/luasrc/view/modem/modem_debug.htm index e4bd1c2..58bfa3e 100644 --- a/luci-app-modem/luasrc/view/modem/modem_debug.htm +++ b/luci-app-modem/luasrc/view/modem/modem_debug.htm @@ -1,1740 +1,992 @@ <%+header%> - - - -
-

<%:Modem Debug%>

-
<%:Debug Your Module%>
- - - - -
-
-

<%:Message%>

- +
+
+
+ - + -
-
- <%:Loading%> - <%:Loading modem%>... -
+
<%:Modem Name%> +
-
+ +
- - - - - -
- -
- - - - - - - - - - - - - - - -
<%:Current%><%:Config%>
- - -
- -
-
-
- - - - - - - - - - - - - - - - - - - -
-
- <%+footer%> diff --git a/luci-app-modem/luasrc/view/modem/modem_debug_new.htm b/luci-app-modem/luasrc/view/modem/modem_debug_new.htm deleted file mode 100644 index 4f1afbd..0000000 --- a/luci-app-modem/luasrc/view/modem/modem_debug_new.htm +++ /dev/null @@ -1,509 +0,0 @@ -<%+header%> - -
-

- <%:Modem Debug%> -

-
- <%:Debug Your Module%> -
- - - - - -
-
-

- <%:Message%> -

- - - - -
-
- <%:Loading%> - <%:Loading modem%>... -
-
-
-
- - - - - -
- -
- - - - - - - - - - - - - - - -
- <%:Current%> - - <%:Config%> -
- - -
- -
-
-
- - - - - - - - - - - - -
- -
- - <%+footer%> diff --git a/luci-app-modem/luasrc/view/modem/modem_dial_log.htm b/luci-app-modem/luasrc/view/modem/modem_dial_log.htm deleted file mode 100644 index c9606d1..0000000 --- a/luci-app-modem/luasrc/view/modem/modem_dial_log.htm +++ /dev/null @@ -1,283 +0,0 @@ - - - - - diff --git a/luci-app-modem/luasrc/view/modem/modem_info.htm b/luci-app-modem/luasrc/view/modem/modem_info.htm index 1c0f677..071e1d4 100644 --- a/luci-app-modem/luasrc/view/modem/modem_info.htm +++ b/luci-app-modem/luasrc/view/modem/modem_info.htm @@ -1,949 +1,365 @@ <%+header%> -<% -local fs = require "nixio.fs" -local uci = luci.model.uci.cursor() + - - +
+
+
+ + + + + + + +
<%:Modem Name%> -
-

<%:Modem Information%>

-
<%:Check the information of the adapted modem%>
- -
-
-

<%:Message%>

- - - - - - - -
-
- <%:Loading%> - <%:Loading modem information%>... -
-
-
-
- - - - <% if nosms == 0 then %> - <% end %> - - - - - - - - - - <% if havegps == 1 then %> - - <% end %> - +
+
+
<%+footer%> - diff --git a/luci-app-modem/luasrc/view/modem/modem_status.htm b/luci-app-modem/luasrc/view/modem/modem_status.htm deleted file mode 100644 index 364cd10..0000000 --- a/luci-app-modem/luasrc/view/modem/modem_status.htm +++ /dev/null @@ -1,160 +0,0 @@ - - - - - - diff --git a/luci-app-modem/luasrc/view/modem/plugin_info.htm b/luci-app-modem/luasrc/view/modem/plugin_info.htm deleted file mode 100644 index 17df663..0000000 --- a/luci-app-modem/luasrc/view/modem/plugin_info.htm +++ /dev/null @@ -1,276 +0,0 @@ -<%+header%> - - - -
-

<%:Plugin Info%>

-
<%:Check the version information of the plugin%>
- - - - -
-
- -

<%:Plugin Info%>

-
-
- -
-
- -
- -
-
-
-
-
- -
-
- -

<%:Dial Tool Info%>

-
-
- -
-
- -
- -
-
-
- -
-
- -
- -
-
-
-
-
- -
-
- -

<%:Modem General Driver Info%>

- - - - - - - - - - - - - - - - - - - -
<%:Driver Type%><%:Kernel Model%><%:Status%>
<%:USB Network%>usbnet.ko-
<%:Serial Port%>option.ko-
-
-
- -
-
- -

<%:Modem USB Driver Info%>

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
<%:Driver Type%><%:Kernel Model%><%:Status%>
<%:QMI%>qmi_wwan.ko-
<%:GobiNet%>GobiNet.ko-
<%:ECM%>cdc_ether.ko-
<%:MBIM%>cdc_mbim.ko-
<%:RNDIS%>rndis_host.ko-
<%:NCM%>cdc_ncm.ko-
-
-
- -
-
- -

<%:Modem PCIE Driver Info%>

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
<%:Driver Type%><%:Kernel Model%><%:Status%>
<%:General%>mhi_net.ko-
<%:General%>qrtr_mhi.ko-
<%:General%>mhi_pci_generic.ko-
<%:General%>mhi_wwan_mbim.ko-
<%:General%>mhi_wwan_ctrl.ko-
<%:Private%>pcie_mhi.ko-
<%:Private%>mtk_pcie_wwan_m80.ko-
-
-
- -
- -<%+footer%> diff --git a/luci-app-modem/luasrc/view/modem/status.htm b/luci-app-modem/luasrc/view/modem/status.htm deleted file mode 100644 index 241baae..0000000 --- a/luci-app-modem/luasrc/view/modem/status.htm +++ /dev/null @@ -1,3 +0,0 @@ -<%+cbi/valueheader%> --- -<%+cbi/valuefooter%> diff --git a/luci-app-modem/luasrc/view/modem/tblsection.htm b/luci-app-modem/luasrc/view/modem/tblsection.htm deleted file mode 100644 index 1cba660..0000000 --- a/luci-app-modem/luasrc/view/modem/tblsection.htm +++ /dev/null @@ -1,203 +0,0 @@ -<%- -local rowcnt = 0 - -function rowstyle() - rowcnt = rowcnt + 1 - if rowcnt % 2 == 0 then - return " cbi-rowstyle-1" - else - return " cbi-rowstyle-2" - end -end - -function width(o) - if o.width then - if type(o.width) == 'number' then - return ' style="width:%dpx"' % o.width - end - return ' style="width:%s"' % o.width - end - return '' -end - -local has_titles = false -local has_descriptions = false - -local anonclass = (not self.anonymous or self.sectiontitle) and "named" or "anonymous" -local titlename = ifattr(not self.anonymous or self.sectiontitle, "data-title", translate("Name")) - -local i, k -for i, k in pairs(self.children) do - if not k.typename then - k.typename = k.template and k.template:gsub("^.+/", "") or "" - end - - if not has_titles and k.title and #k.title > 0 then - has_titles = true - end - - if not has_descriptions and k.description and #k.description > 0 then - has_descriptions = true - end -end - -function render_titles() - if not has_titles then - return - end - - %>><% - - local i, k - for i, k in ipairs(self.children) do - if not k.optional then - %>><% - - if k.titleref then - %><% - end - - write(k.title) - - if k.titleref then - %><% - end - - %><% - end - end - - if self.sortable or self.extedit or self.addremove then - %><% - end - - %><% - - rowcnt = rowcnt + 1 -end - -function render_descriptions() - if not has_descriptions then - return - end - - %><% - - local i, k - for i, k in ipairs(self.children) do - if not k.optional then - %>><% - - write(k.description) - - %><% - end - end - - if self.sortable or self.extedit or self.addremove then - %><% - end - - %><% - - rowcnt = rowcnt + 1 -end - --%> - - -
- <% if self.title and #self.title > 0 then -%> -

<%=self.title%>

- <%- end %> - <%- if self.sortable then -%> - - <%- end -%> -
<%=self.description%>
- - <%- - render_titles() - render_descriptions() - - local isempty, section, i, k = true, nil, nil - for i, k in ipairs(self:cfgsections()) do - isempty = false - section = k - - local sectionname = striptags((type(self.sectiontitle) == "function") and self:sectiontitle(section) or k) - local sectiontitle = ifattr(sectionname and (not self.anonymous or self.sectiontitle), "data-title", sectionname, true) - local colorclass = (self.extedit or self.rowcolors) and rowstyle() or "" - local scope = { - valueheader = "cbi/cell_valueheader", - valuefooter = "cbi/cell_valuefooter" - } - -%> - > - <%- - local node - for k, node in ipairs(self.children) do - if not node.optional then - node:render(section, scope or {}) - end - end - -%> - - <%- if self.sortable or self.extedit or self.addremove then -%> - - <%- end -%> - - <%- end -%> - - <%- if isempty then -%> - - - - <%- end -%> -
-
- <%- if self.sortable then -%> - - - <% end; if self.extedit then -%> - onclick="location.href='<%=self.extedit:format(section)%>'" - <%- elseif type(self.extedit) == "function" then - %> onclick="location.href='<%=self:extedit(section)%>'" - <%- end - %> alt="<%:Edit%>" title="<%:Edit%>" /> - <% end; if self.addremove then %> - - <%- end -%> -
-
<%:This section contains no values yet%>
- - <% if self.error then %> -
-
    <% for _, c in pairs(self.error) do for _, e in ipairs(c) do -%> -
  • <%=pcdata(e):gsub("\n","
    ")%>
  • - <%- end end %>
-
- <% end %> - - <%- if self.addremove then -%> - <% if self.template_addremove then include(self.template_addremove) else -%> -
- <% if self.anonymous then %> - - <% else %> - <% if self.invalid_cts then -%> -
<%:Invalid%>
- <%- end %> -
- -
- - <% end %> -
- <%- end %> - <%- end -%> -
- diff --git a/luci-app-modem/luasrc/view/modem/tblsection_command.htm b/luci-app-modem/luasrc/view/modem/tblsection_command.htm deleted file mode 100644 index 92839c8..0000000 --- a/luci-app-modem/luasrc/view/modem/tblsection_command.htm +++ /dev/null @@ -1,208 +0,0 @@ -<%- -local rowcnt = 0 - -function rowstyle() - rowcnt = rowcnt + 1 - if rowcnt % 2 == 0 then - return " cbi-rowstyle-1" - else - return " cbi-rowstyle-2" - end -end - -function width(o) - if o.width then - if type(o.width) == 'number' then - return ' style="width:%dpx"' % o.width - end - return ' style="width:%s"' % o.width - end - return '' -end - -local has_titles = false -local has_descriptions = false - -local anonclass = (not self.anonymous or self.sectiontitle) and "named" or "anonymous" -local titlename = ifattr(not self.anonymous or self.sectiontitle, "data-title", translate("Name")) - -local i, k -for i, k in pairs(self.children) do - if not k.typename then - k.typename = k.template and k.template:gsub("^.+/", "") or "" - end - - if not has_titles and k.title and #k.title > 0 then - has_titles = true - end - - if not has_descriptions and k.description and #k.description > 0 then - has_descriptions = true - end -end - -function render_titles() - if not has_titles then - return - end - - %>> - <%:Serial Number%> - <% - local i, k - for i, k in ipairs(self.children) do - if not k.optional then - %>><% - - if k.titleref then - %><% - end - - write(k.title) - - if k.titleref then - %><% - end - - %><% - end - end - - if self.sortable or self.extedit or self.addremove then - %><% - end - - %><% - - rowcnt = rowcnt + 1 -end - -function render_descriptions() - if not has_descriptions then - return - end - - %><% - - local i, k - for i, k in ipairs(self.children) do - if not k.optional then - %>><% - - write(k.description) - - %><% - end - end - - if self.sortable or self.extedit or self.addremove then - %><% - end - - %><% - - rowcnt = rowcnt + 1 -end - --%> - - -
- <% if self.title and #self.title > 0 then -%> -

<%=self.title%>

- <%- end %> - <%- if self.sortable then -%> - - <%- end -%> -
<%=self.description%>
- - <%- - render_titles() - render_descriptions() - - local num = 1 - local isempty, section, i, k = true, nil, nil - for i, k in ipairs(self:cfgsections()) do - isempty = false - section = k - - local sectionname = striptags((type(self.sectiontitle) == "function") and self:sectiontitle(section) or k) - local sectiontitle = ifattr(sectionname and (not self.anonymous or self.sectiontitle), "data-title", sectionname, true) - local colorclass = (self.extedit or self.rowcolors) and rowstyle() or "" - local scope = { - valueheader = "cbi/cell_valueheader", - valuefooter = "cbi/cell_valuefooter" - } - -%> - > - - <%- - local node - for k, node in ipairs(self.children) do - if not node.optional then - node:render(section, scope or {}) - end - end - -%> - <%- if self.sortable or self.extedit or self.addremove then -%> - - <%- end -%> - - <%- end -%> - - <%- if isempty then -%> - - - - <%- end -%> -
-

<%=num%>

- <% num = num + 1 -%> -
-
- <%- if self.sortable then -%> - - - <% end; if self.extedit then -%> - onclick="location.href='<%=self.extedit:format(section)%>'" - <%- elseif type(self.extedit) == "function" then - %> onclick="location.href='<%=self:extedit(section)%>'" - <%- end - %> alt="<%:Edit%>" title="<%:Edit%>" /> - <% end; if self.addremove then %> - - <%- end -%> -
-
<%:This section contains no values yet%>
- - <% if self.error then %> -
-
    <% for _, c in pairs(self.error) do for _, e in ipairs(c) do -%> -
  • <%=pcdata(e):gsub("\n","
    ")%>
  • - <%- end end %>
-
- <% end %> - - <%- if self.addremove then -%> - <% if self.template_addremove then include(self.template_addremove) else -%> -
- <% if self.anonymous then %> - - <% else %> - <% if self.invalid_cts then -%> -
<%:Invalid%>
- <%- end %> -
- -
- - <% end %> -
- <%- end %> - <%- end -%> -
- diff --git a/luci-app-modem/po/ru/modem.po b/luci-app-modem/po/ru/modem.po new file mode 100644 index 0000000..9faca8a --- /dev/null +++ b/luci-app-modem/po/ru/modem.po @@ -0,0 +1,263 @@ +msgid "Modem Information" +msgstr "Информация о модеме" + +msgid "Dial Overview" +msgstr "Обзор набора" + +msgid "Modem Debug" +msgstr "Отладка модема" + + +msgid "Mwan Config" +msgstr "Настройка Mwan" + +msgid "TTL Config" +msgstr "Настройка TTL" + +msgid "Plugin Config" +msgstr "Настройка плагина" + +msgid "Modem Name" +msgstr "Название модема" + + +msgid "Base Information" +msgstr "Основная информация" + +msgid "Производитель" +msgstr "Производитель" + + +msgid "Ревизия" +msgstr "Ревизия" + + +msgid "AT Port" +msgstr "AT Порт" + +msgid "Temperature" +msgstr "Температура" + + +msgid "Voltage" +msgstr "Напряжение" + + +msgid "Connect Status" +msgstr "Статус подключения" + +msgid "Yes" +msgstr "Да" + +msgid "SIM Information" +msgstr "Информация о SIM" + +msgid "SIM Status" +msgstr "Статус SIM" + +msgid "ready" +msgstr "готово" + +msgid "Internet Service Provider" +msgstr "Интернет-провайдер" + +msgid "SIM Slot" +msgstr "Слот SIM" + +msgid "International Mobile Equipment Identity" +msgstr "Международный идентификатор мобильного оборудования" + +msgid "Международный идентификатор абонента мобильной связи" +msgstr "Международный идентификатор абонента мобильной связи" + + +msgid "Integrate Circuit Card Identity" +msgstr "Идентификатор интегральной схемы карты" + + +msgid "Network Information" +msgstr "Информация о сети" + +msgid "Network Type" +msgstr "Тип сети" + +msgid "TDD NR5G" +msgstr "TDD NR5G" + +msgid "Channel Quality Indicator for Uplink" +msgstr "Индикатор качества канала для передачи" + +msgid "Channel Quality Indicator for Downlink" +msgstr "Индикатор качества канала для приема" + +msgid "Access Maximum Bit Rate for Uplink" +msgstr "Максимальная скорость передачи данных для передачи" + +msgid "Access Maximum Bit Rate for Downlink" +msgstr "Максимальная скорость передачи данных для приема" + +msgid "Transmit Rate" +msgstr "Скорость передачи" + + +msgid "Receive Rate" +msgstr "Скорость приема" + + +msgid "Cell Information" +msgstr "Информация о ячейке" + +msgid "Режим сети" +msgstr "Режим сети" + + +msgid "Мобильный код страны" +msgstr "Мобильный код страны" + + +msgid "Мобильный код сети" +msgstr "Мобильный код сети" + + +msgid "Duplex Mode" +msgstr "Режим дуплекса" + +msgid "TDD" +msgstr "TDD" + +msgid "ID ячейки" +msgstr "ID ячейки" + +msgid "Physical Cell ID" +msgstr "Физический ID ячейки" + +msgid "Tracking area code of cell servedby neighbor Enb" +msgstr "Код зоны отслеживания ячейки, обслуживаемой соседним Enb" + + +msgid "Absolute Radio-Frequency Channel Number" +msgstr "Абсолютный номер радиочастотного канала" + + +msgid "Диапазон" +msgstr "Диапазон" + +msgid "DL Bandwidth" +msgstr "Ширина полосы пропускания DL" + + +msgid "Reference Signal Received Power" +msgstr "Мощность принятого опорного сигнала" + +msgid "Reference Signal Received Quality" +msgstr "Качество принятого опорного сигнала" + +msgid "Signal to Interference plus Noise Ratio Bandwidth" +msgstr "Отношение сигнал/шум плюс полоса пропускания помех" + +msgid "Serving Cell Receive Level" +msgstr "Уровень приема обслуживающей ячейки" + +msgid "Check and add modem dialing configurations" +msgstr "Проверьте и добавьте конфигурации набора модема" + +msgid "Global Config" +msgstr "Глобальная конфигурация" + +msgid "Enable Dial" +msgstr "Включить набор" + +msgid "Enable dial configurations" +msgstr "Включить конфигурации набора" + +msgid "Reload Dial Configurations" +msgstr "Перезагрузить конфигурации набора" + +msgid "Manually Reload dial configurations When the dial configuration fails to take effect" +msgstr "Вручную перезагрузите конфигурации набора, когда конфигурация набора не вступает в силу" + +msgid "Config List" +msgstr "Список конфигураций" + +msgid "enable_dial" +msgstr "включить_набор" + +msgid "Remarks" +msgstr "Замечания" + +msgid "Mobile Network" +msgstr "Мобильная сеть" + +msgid "Dial Tool" +msgstr "Инструмент набора" + +msgid "Тип PDP" +msgstr "Тип PDP" + +msgid "Network Bridge" +msgstr "Сетевой мост" + + +msgid "Auto Choose" +msgstr "Автовыбор" + + +msgid "Modem Name" +msgstr "Название модема" + +msgid "Dial Mode" +msgstr "Режим набора" + +msgid "Rat Prefer" +msgstr "Предпочтительный Rat" + +msgid "Set IMEI" +msgstr "Установить IMEI" + +msgid "Neighbor Cell" +msgstr "Соседняя ячейка" + +msgid "Lock Band" +msgstr "Заблокировать диапазон" + +msgid "Dial Mode" +msgstr "Режим набора" + +msgid "Current Mode" +msgstr "Текущий режим" + +msgid "Plugin Config" +msgstr "Настройка плагина" + +msgid "Check and modify the plugin configuration" +msgstr "Проверьте и измените конфигурацию плагина" + +msgid "Global Config" +msgstr "Глобальная конфигурация" + +msgid "Modem Scan" +msgstr "Сканирование модема" + +msgid "The automatic configuration modem is triggered only at modem startup, otherwise, manual scanning is necessary" +msgstr "Автоматическая конфигурация модема запускается только при запуске модема, в противном случае необходимо ручное сканирование" + +msgid "Manual Configuration" +msgstr "Ручная конфигурация" + +msgid "Enable the manual configuration of modem information (After enable, the automatic scanning and configuration function for modem information will be disabled)" +msgstr "Включите ручную конфигурацию информации о модеме (после включения функция автоматического сканирования и конфигурации информации о модеме будет отключена)" + +msgid "Modem Config" +msgstr "Конфигурация модема" + +msgid "Удалить" +msgstr "Удалить" + +msgid "Сеть" +msgstr "Сеть" + +msgid "Modem Name" +msgstr "Название модема" + +msgid "AT Port" +msgstr "AT Порт" diff --git a/luci-app-modem/po/zh-cn/modem.po b/luci-app-modem/po/zh-cn/modem.po index a929e8a..cd4d09e 100644 --- a/luci-app-modem/po/zh-cn/modem.po +++ b/luci-app-modem/po/zh-cn/modem.po @@ -680,14 +680,6 @@ msgstr "输入SCS" msgid "Enter NRBAND" msgstr "输入NR频段" -msgid "SIM Slot|Now" -msgstr "SIM卡卡槽|当前" - -msgid "SIM Slot|Next Boot" -msgstr "SIM卡卡槽|下次启动" - -msgid "SIM Slot|Setting' -msgstr "SIM卡卡槽|设置" msgid "SIM1 (Close to power)" msgstr "SIM1 (靠近电源)" @@ -742,3 +734,123 @@ msgstr "启用多WAN" msgid "Mwan Config" msgstr "多WAN设置" + +msgid "Network Down Judge Times" +msgstr "网络下线判断次数" + +msgid "Network Detect Interval" +msgstr "网络检测间隔" + +msgid "SIM Auto Switch" +msgstr "SIM卡自动切换" + +msgid "Ping Destination" +msgstr "Ping目标" + +msgid "SIM Settings" +msgstr "SIM卡设置" + +msgid "SIM Config" +msgstr "SIM卡配置" + +msgid "TTL Config" +msgstr "TTL配置" + +msgid "enable_dial" +msgstr "启用拨号" + +#modem_info.htm +msgid "Reference Signal Received Power" +msgstr "参考信号接收功率(RSRP)" + +msgid "Reference Signal Received Quality" +msgstr "参考信号接收质量(RSRQ)" + +msgid "Absolute Radio-Frequency Channel Number" +msgstr "绝对射频信道号(ARFCN)" + +msgid "Tracking area code of cell servedby neighbor Enb" +msgstr "邻区Enb服务的跟踪区编码(TAC)" + +msgid "Received Signal Level" +msgstr "接收信号级别(RxLev)" + +msgid "Signal to Interference plus Noise Ratio Bandwidth" +msgstr "信噪比带宽(SINR)" + +msgid "International Mobile Equipment Identity" +msgstr "国际移动设备识别码(IMEI)" + +msgid "Integrate Circuit Card Identity" +msgstr "集成电路卡识别码(ICCID)" + +#dial_overview.htm +msgid "Manually Reload dial configurations When the dial configuration fails to take effect" +msgstr "当拨号配置无法生效时,手动重新加载拨号配置" + +msgid "Reload Dial Configurations" +msgstr "重新加载拨号配置" + +#modem_debug.htm +msgid "Dial Mode" +msgstr "拨号模式" + +msgid "Current Mode" +msgstr "当前模式" + +msgid "Rat Prefer" +msgstr "制式偏好" + +msgid "Setting" +msgstr "设置" + +msgid "Neighbor Cell" +msgstr "邻区" + +msgid "Lock Cell Setting" +msgstr "锁定小区设置" + +msgid "Lock Band" +msgstr "锁定频段" + +msgid "Select All" +msgstr "全选" + +msgid "Disconnected" +msgstr "未连接" + +msgid "Serving Cell Receive Level" +msgstr "服务小区接收信号级别(Srxlev)" + +msgid "Internet Service Provider" +msgstr "互联网服务提供商(ISP)" + +msgid "SIM Error,Error code:" +msgstr "SIM卡错误,错误码:" + +msgid "Warning!" +msgstr "警告!" + +msgid "PIN Code" +msgstr "PIN码" + +msgid "If the PIN code is not set, leave it blank." +msgstr "如果未设置PIN码,请留空。" + +msgid "RA Master" +msgstr "IPV6中继 主" + +msgid "After checking, This interface will enable IPV6 RA Master.Only one interface can be set to RA Master." +msgstr "勾选后,此接口将启用IPV6中继主。只能设置一个接口为RA主。" + +msgid "The metric value is used to determine the priority of the route. The smaller the value, the higher the priority. Cannot duplicate." +msgstr "度量值用于确定路由的优先级。值越小,优先级越高。不能重复。" + +msgid "Modem Log" +msgstr "模组日志" + +msgid "enabled" +msgstr "已启用" + +msgid "disabled" +msgstr "已禁用" diff --git a/luci-app-modem/po/zh_Hans/modem.po b/luci-app-modem/po/zh_Hans/modem.po index 4165162..470e583 100644 --- a/luci-app-modem/po/zh_Hans/modem.po +++ b/luci-app-modem/po/zh_Hans/modem.po @@ -646,6 +646,7 @@ msgstr "通用" msgid "Private" msgstr "私有" + msgid "Switch SIM" msgstr "切换SIM卡" @@ -679,14 +680,6 @@ msgstr "输入SCS" msgid "Enter NRBAND" msgstr "输入NR频段" -msgid "SIM Slot|Now" -msgstr "SIM卡卡槽|当前" - -msgid "SIM Slot|Next Boot" -msgstr "SIM卡卡槽|下次启动" - -msgid "SIM Slot|Setting' -msgstr "SIM卡卡槽|设置" msgid "SIM1 (Close to power)" msgstr "SIM1 (靠近电源)" @@ -742,14 +735,125 @@ msgstr "启用多WAN" msgid "Mwan Config" msgstr "多WAN设置" -msgid "sticky mode" -msgstr "粘滞模式" +msgid "Network Down Judge Times" +msgstr "网络下线判断次数" -msgid "same source ip address will always use the same wan interface" -msgstr "相同源IP会使用同一个WAN出口" +msgid "Network Detect Interval" +msgstr "网络检测间隔" -msgid "sticky timeout" -msgstr "粘滞超时" +msgid "SIM Auto Switch" +msgstr "SIM卡自动切换" -msgid "Check and modify the mwan configuration" -msgstr "检查并修改mwan配置" +msgid "Ping Destination" +msgstr "Ping目标" + +msgid "SIM Settings" +msgstr "SIM卡设置" + +msgid "SIM Config" +msgstr "SIM卡配置" + +msgid "TTL Config" +msgstr "TTL配置" + +msgid "enable_dial" +msgstr "启用拨号" + +#modem_info.htm +msgid "Reference Signal Received Power" +msgstr "参考信号接收功率(RSRP)" + +msgid "Reference Signal Received Quality" +msgstr "参考信号接收质量(RSRQ)" + +msgid "Absolute Radio-Frequency Channel Number" +msgstr "绝对射频信道号(ARFCN)" + +msgid "Tracking area code of cell servedby neighbor Enb" +msgstr "邻区Enb服务的跟踪区编码(TAC)" + +msgid "Received Signal Level" +msgstr "接收信号级别(RxLev)" + +msgid "Signal to Interference plus Noise Ratio Bandwidth" +msgstr "信噪比带宽(SINR)" + +msgid "International Mobile Equipment Identity" +msgstr "国际移动设备识别码(IMEI)" + +msgid "Integrate Circuit Card Identity" +msgstr "集成电路卡识别码(ICCID)" + +#dial_overview.htm +msgid "Manually Reload dial configurations When the dial configuration fails to take effect" +msgstr "当拨号配置无法生效时,手动重新加载拨号配置" + +msgid "Reload Dial Configurations" +msgstr "重新加载拨号配置" + +#modem_debug.htm +msgid "Dial Mode" +msgstr "拨号模式" + +msgid "Current Mode" +msgstr "当前模式" + +msgid "Rat Prefer" +msgstr "制式偏好" + +msgid "Setting" +msgstr "设置" + +msgid "Neighbor Cell" +msgstr "邻区" + +msgid "Lock Cell Setting" +msgstr "锁定小区设置" + +msgid "Lock Band" +msgstr "锁定频段" + +msgid "Select All" +msgstr "全选" + +msgid "Disconnected" +msgstr "未连接" + +msgid "Serving Cell Receive Level" +msgstr "服务小区接收信号级别(Srxlev)" + +msgid "Internet Service Provider" +msgstr "互联网服务提供商(ISP)" + +msgid "SIM Error,Error code:" +msgstr "SIM卡错误,错误码:" + +msgid "Warning!" +msgstr "警告!" + +msgid "PIN Code" +msgstr "PIN码" + +msgid "If solt 2 config is not set,will use slot 1 config." +msgstr "如果未设置卡槽2配置,将使用卡槽1配置。" + +msgid "If the PIN code is not set, leave it blank." +msgstr "如果未设置PIN码,请留空。" + +msgid "RA Master" +msgstr "IPV6中继 主" + +msgid "After checking, This interface will enable IPV6 RA Master.Only one interface can be set to RA Master." +msgstr "勾选后,此接口将启用IPV6中继主。只能设置一个接口为RA主。" + +msgid "The metric value is used to determine the priority of the route. The smaller the value, the higher the priority. Cannot duplicate." +msgstr "度量值用于确定路由的优先级。值越小,优先级越高。不能重复。" + +msgid "Modem Log" +msgstr "模组日志" + +msgid "enabled" +msgstr "已启用" + +msgid "disabled" +msgstr "已禁用" diff --git a/luci-app-modem/quickinstall.sh b/luci-app-modem/quickinstall.sh new file mode 100755 index 0000000..9192da6 --- /dev/null +++ b/luci-app-modem/quickinstall.sh @@ -0,0 +1,6 @@ +#!/bin/sh +host=$1 +scp -oHostkeyalgorithms=+ssh-rsa -r luasrc/* root@$host:/usr/lib/lua/luci/ +scp -oHostkeyalgorithms=+ssh-rsa -r root/usr/* root@$host:/usr/ +scp -oHostkeyalgorithms=+ssh-rsa -r root/etc/init.d/* root@$host:/etc/init.d/ +ssh -oHostkeyalgorithms=+ssh-rsa root@$host rm -rf /tmp/luci-indexcache diff --git a/luci-app-modem/root/etc/config/custom_at_commands b/luci-app-modem/root/etc/config/custom_at_commands deleted file mode 100644 index 8612106..0000000 --- a/luci-app-modem/root/etc/config/custom_at_commands +++ /dev/null @@ -1,332 +0,0 @@ - -config custom-commands - option description '****************通用****************' - option command 'ATI' - -config custom-commands - option description '模组信息 > ATI' - option command 'ATI' - -config custom-commands - option description '查询SIM卡状态 > AT+CPIN?' - option command 'AT+CPIN?' - -config custom-commands - option description '查询网络信号质量(4G) > AT+CSQ' - option command 'AT+CSQ' - -config custom-commands - option description '查询网络信号质量(5G) > AT+CESQ' - option command 'AT+CESQ' - -config custom-commands - option description '查询网络信息 > AT+COPS?' - option command 'AT+COPS?' - -config custom-commands - option description '查询PDP信息 > AT+CGDCONT?' - option command 'AT+CGDCONT?' - -config custom-commands - option description '查询PDP地址 > AT+CGPADDR' - option command 'AT+CGPADDR' - -config custom-commands - option description '查询模组IMEI > AT+CGSN' - option command 'AT+CGSN' - -config custom-commands - option description '查询模组IMEI > AT+GSN' - option command 'AT+GSN' - -config custom-commands - option description '查看当前电压' - option command 'AT+CBC' - -config custom-commands - option description '最小功能模式 > AT+CFUN=0' - option command 'AT+CFUN=0' - -config custom-commands - option description '全功能模式 > AT+CFUN=1' - option command 'AT+CFUN=1' - -config custom-commands - option description '重启模组 > AT+CFUN=1,1' - option command 'AT+CFUN=1,1' - -config custom-commands - option description '****************移远****************' - option command 'ATI' - -config custom-commands - option description 'SIM卡状态上报 > AT+QSIMSTAT?' - option command 'AT+QSIMSTAT?' - -config custom-commands - option description '设置当前使用的为卡1 > AT+QUIMSLOT=1' - option command 'AT+QUIMSLOT=1' - -config custom-commands - option description '设置当前使用的为卡2 > AT+QUIMSLOT=2' - option command 'AT+QUIMSLOT=2' - -config custom-commands - option description '查询网络信息 > AT+QNWINFO' - option command 'AT+QNWINFO' - -config custom-commands - option description '查询SIM卡签约速率 > AT+QNWCFG="nr5g_ambr"' - option command 'AT+QNWCFG="nr5g_ambr"' - -config custom-commands - option description '查询载波聚合参数 > AT+QCAINFO' - option command 'AT+QCAINFO' - -config custom-commands - option description '查询当前拨号模式 > AT+QCFG="usbnet"' - option command 'AT+QCFG="usbnet"' - -config custom-commands - option description 'QMI/GobiNet拨号 > AT+QCFG="usbnet",0' - option command 'AT+QCFG="usbnet",0' - -config custom-commands - option description 'ECM拨号 > AT+QCFG="usbnet",1' - option command 'AT+QCFG="usbnet",1' - -config custom-commands - option description 'MBIM拨号 > AT+QCFG="usbnet",2' - option command 'AT+QCFG="usbnet",2' - -config custom-commands - option description 'RNDIS拨号 > AT+QCFG="usbnet",3' - option command 'AT+QCFG="usbnet",3' - -config custom-commands - option description 'NCM拨号 > AT+QCFG="usbnet",5' - option command 'AT+QCFG="usbnet",5' - -config custom-commands - option description '锁4G > AT+QNWPREFCFG="mode_pref",LTE' - option command 'AT+QNWPREFCFG="mode_pref",LTE' - -config custom-commands - option description '锁5G > AT+QNWPREFCFG="mode_pref",NR5G' - option command 'AT+QNWPREFCFG="mode_pref",NR5G' - -config custom-commands - option description '锁5G NSA > AT+QNWPREFCFG="mode_pref",NR5G-NSA' - option command 'AT+QNWPREFCFG="mode_pref",NR5G-NSA' - -config custom-commands - option description '锁5G SA > AT+QNWPREFCFG="mode_pref",NR5G-SA' - option command 'AT+QNWPREFCFG="mode_pref",NR5G-SA' - -config custom-commands - option description '恢复自动搜索网络 > AT+QNWPREFCFG="mode_pref",AUTO' - option command 'AT+QNWPREFCFG="mode_pref",AUTO' - -config custom-commands - option description '查询模组IMEI > AT+EGMR=0,7' - option command 'AT+EGMR=0,7' - -config custom-commands - option description '更改模组IMEI > AT+EGMR=1,7,"IMEI"' - option command 'AT+EGMR=1,7,"在此设置IMEI"' - -config custom-commands - option description '获取模组温度 > AT+QTEMP' - option command 'AT+QTEMP' - -config custom-commands - option description '切换为USB通信端口 > AT+QCFG="data_interface",0,0' - option command 'AT+QCFG="data_interface",0,0' - -config custom-commands - option description '切换为PCIE通信端口 > AT+QCFG="data_interface",1,0' - option command 'AT+QCFG="data_interface",1,0' - -config custom-commands - option description '查看当前USB速率 > AT+QCFG="usbspeed"' - option command 'AT+QCFG="usbspeed"' - -config custom-commands - option description '切换为USB2.0 > AT+QCFG="usbspeed","20"' - option command 'AT+QCFG="usbspeed","20"' - -config custom-commands - option description '切换为USB3.1 Gen1(5Gbps) > AT+QCFG="usbspeed","311"' - option command 'AT+QCFG="usbspeed","311"' - -config custom-commands - option description '切换为USB3.1 Gen1(10Gbps) > AT+QCFG="usbspeed","312"' - option command 'AT+QCFG="usbspeed","312"' - -config custom-commands - option description '重置模组 > AT+QCFG="ResetFactory"' - option command 'AT+QCFG="ResetFactory"' - -config custom-commands - option description '****************广和通****************' - option command 'ATI' - -config custom-commands - option description '设置当前使用的为卡1 > AT+GTDUALSIM=0' - option command 'AT+GTDUALSIM=0' - -config custom-commands - option description '设置当前使用的为卡2 > AT+GTDUALSIM=1' - option command 'AT+GTDUALSIM=1' - -config custom-commands - option description 'ECM手动拨号 > AT+GTRNDIS=1,1' - option command 'AT+GTRNDIS=1,1' - -config custom-commands - option description 'ECM拨号断开 > AT+GTRNDIS=0,1' - option command 'AT+GTRNDIS=0,1' - -config custom-commands - option description '查询当前端口模式 > AT+GTUSBMODE?' - option command 'AT+GTUSBMODE?' - -config custom-commands - option description 'QMI/GobiNet拨号 > AT+GTUSBMODE=32' - option command 'AT+GTUSBMODE=32' - -config custom-commands - option description 'ECM拨号 > AT+GTUSBMODE=18' - option command 'AT+GTUSBMODE=18' - -config custom-commands - option description 'MBIM拨号 > AT+GTUSBMODE=30' - option command 'AT+GTUSBMODE=30' - -config custom-commands - option description 'RNDIS拨号 > AT+GTUSBMODE=24' - option command 'AT+GTUSBMODE=24' - -config custom-commands - option description 'NCM拨号 > AT+GTUSBMODE=18' - option command 'AT+GTUSBMODE=18' - -config custom-commands - option description '锁4G > AT+GTACT=2' - option command 'AT+GTACT=2' - -config custom-commands - option description '锁5G > AT+GTACT=14' - option command 'AT+GTACT=14' - -config custom-commands - option description '恢复自动搜索网络 > AT+GTACT=20' - option command 'AT+GTACT=20' - -config custom-commands - option description '查询当前连接的网络类型 > AT+PSRAT?' - option command 'AT+PSRAT?' - -config custom-commands - option description '查询模组IMEI > AT+GTSN=0,7' - option command 'AT+GTSN=0,7' - -config custom-commands - option description '更改模组IMEI > AT+GTSN=1,7,"IMEI"' - option command 'AT+GTSN=1,7,"在此设置IMEI"' - -config custom-commands - option description '报告一次当前BBIC的温度 > AT+MTSM=1,6' - option command 'AT+MTSM=1,6' - -config custom-commands - option description '报告一次当前射频的温度 > AT+MTSM=1,7' - option command 'AT+MTSM=1,7' - -config custom-commands - option description '获取当前温度 > AT+GTLADC' - option command 'AT+GTLADC' - -config custom-commands - option description '重启模组 > AT+CFUN=15' - option command 'AT+CFUN=15' - -config custom-commands - option description '****************美格****************' - option command 'ATI' - -config custom-commands - option description 'SIM卡状态上报 > AT^SIMSLOTURC=1' - option command 'AT^SIMSLOTURC=1' - -config custom-commands - option description '获取SIM卡卡槽状态 > AT^SIMSLOT?' - option command 'AT^SIMSLOT?' - -config custom-commands - option description '设置当前使用的为卡1 > AT^SIMSLOT=1' - option command 'AT^SIMSLOT=1' - -config custom-commands - option description '设置当前使用的为卡2 > AT^SIMSLOT=2' - option command 'AT^SIMSLOT=2' - -config custom-commands - option description '查询网络信息 > AT^SYSINFOEX' - option command 'AT^SYSINFOEX' - -config custom-commands - option description '查询载波聚合小区信息 > AT^CELLINFO=3' - option command 'AT^CELLINFO=3' - -config custom-commands - option description '查询当前拨号模式 > AT+SER?' - option command 'AT+SER?' - -config custom-commands - option description 'QMI/GobiNet拨号 > AT+SER=1,1' - option command 'AT+SER=1,1' - -config custom-commands - option description 'ECM拨号 > AT+SER=2,1' - option command 'AT+SER=2,1' - -config custom-commands - option description 'MBIM拨号 > AT+SER=3,1' - option command 'AT+SER=3,1' - -config custom-commands - option description 'RNDIS拨号 > AT+SER=3,1' - option command 'AT+SER=3,1' - -config custom-commands - option description 'NCM拨号 > AT+SER=2,1' - option command 'AT+SER=2,1' - -config custom-commands - option description '锁4G > AT^SYSCFGEX="03",all,0,2,all,all,all,all,1' - option command 'AT^SYSCFGEX="03",all,0,2,all,all,all,all,1' - -config custom-commands - option description '锁5G > AT^SYSCFGEX="04",all,0,2,all,all,all,all,1' - option command 'AT^SYSCFGEX="04",all,0,2,all,all,all,all,1' - -config custom-commands - option description '恢复自动搜索网络 > AT^SYSCFGEX="00",all,0,2,all,all,all,all,1' - option command 'AT^SYSCFGEX="00",all,0,2,all,all,all,all,1' - -config custom-commands - option description '查询模组IMEI > AT+LCTSN=0,7' - option command 'AT+LCTSN=0,7' - -config custom-commands - option description '更改模组IMEI > AT+LCTSN=1,7,"IMEI"' - option command 'AT+LCTSN=1,7,"在此设置IMEI"' - -config custom-commands - option description '获取模组温度 > AT+TEMP' - option command 'AT+TEMP' - -config custom-commands - option description '重启模组 > AT+RESET' - option command 'AT+RESET' \ No newline at end of file diff --git a/luci-app-modem/root/etc/config/modem b/luci-app-modem/root/etc/config/modem index 8e32086..fc03ac4 100644 --- a/luci-app-modem/root/etc/config/modem +++ b/luci-app-modem/root/etc/config/modem @@ -1,276 +1,4 @@ - config global 'global' option enable_dial '1' option modem_number '0' option manual_configuration '0' - option ethernet "cpewan0" - -config custom-commands - option description '****************通用****************' - option command 'ATI' - -config custom-commands - option description '模组信息 > ATI' - option command 'ATI' - -config custom-commands - option description '查询SIM卡状态 > AT+CPIN?' - option command 'AT+CPIN?' - -config custom-commands - option description '查询网络信号质量(4G) > AT+CSQ' - option command 'AT+CSQ' - -config custom-commands - option description '查询网络信号质量(5G) > AT+CESQ' - option command 'AT+CESQ' - -config custom-commands - option description '查询网络信息 > AT+COPS?' - option command 'AT+COPS?' - -config custom-commands - option description '查询PDP信息 > AT+CGDCONT?' - option command 'AT+CGDCONT?' - -config custom-commands - option description '查询PDP地址 > AT+CGPADDR' - option command 'AT+CGPADDR' - -config custom-commands - option description '最小功能模式 > AT+CFUN=0' - option command 'AT+CFUN=0' - -config custom-commands - option description '全功能模式 > AT+CFUN=1' - option command 'AT+CFUN=1' - -config custom-commands - option description '重启模组 > AT+CFUN=1,1' - option command 'AT+CFUN=1,1' - -config custom-commands - option description '****************移远****************' - option command 'ATI' - -config custom-commands - option description 'SIM卡状态上报 > AT+QSIMSTAT?' - option command 'AT+QSIMSTAT?' - -config custom-commands - option description '设置当前使用的为卡1 > AT+QUIMSLOT=1' - option command 'AT+QUIMSLOT=1' - -config custom-commands - option description '设置当前使用的为卡2 > AT+QUIMSLOT=2' - option command 'AT+QUIMSLOT=2' - -config custom-commands - option description '查询网络信息 > AT+QNWINFO' - option command 'AT+QNWINFO' - -config custom-commands - option description '查询SIM卡签约速率 > AT+QNWCFG="nr5g_ambr"' - option command 'AT+QNWCFG="nr5g_ambr"' - -config custom-commands - option description '查询载波聚合参数 > AT+QCAINFO' - option command 'AT+QCAINFO' - -config custom-commands - option description '查询当前拨号模式 > AT+QCFG="usbnet"' - option command 'AT+QCFG="usbnet"' - -config custom-commands - option description 'QMI/GobiNet拨号 > AT+QCFG="usbnet",0' - option command 'AT+QCFG="usbnet",0' - -config custom-commands - option description 'ECM拨号 > AT+QCFG="usbnet",1' - option command 'AT+QCFG="usbnet",1' - -config custom-commands - option description 'MBIM拨号 > AT+QCFG="usbnet",2' - option command 'AT+QCFG="usbnet",2' - -config custom-commands - option description 'RNDIS拨号 > AT+QCFG="usbnet",3' - option command 'AT+QCFG="usbnet",3' - -config custom-commands - option description 'NCM拨号 > AT+QCFG="usbnet",5' - option command 'AT+QCFG="usbnet",5' - -config custom-commands - option description '锁4G > AT+QNWPREFCFG="mode_pref",LTE' - option command 'AT+QNWPREFCFG="mode_pref",LTE' - -config custom-commands - option description '锁5G > AT+QNWPREFCFG="mode_pref",NR5G' - option command 'AT+QNWPREFCFG="mode_pref",NR5G' - -config custom-commands - option description '锁5G NSA > AT+QNWPREFCFG="mode_pref",NR5G-NSA' - option command 'AT+QNWPREFCFG="mode_pref",NR5G-NSA' - -config custom-commands - option description '锁5G SA > AT+QNWPREFCFG="mode_pref",NR5G-SA' - option command 'AT+QNWPREFCFG="mode_pref",NR5G-SA' - -config custom-commands - option description '恢复自动搜索网络 > AT+QNWPREFCFG="mode_pref",AUTO' - option command 'AT+QNWPREFCFG="mode_pref",AUTO' - -config custom-commands - option description '查询模组IMEI > AT+CGSN' - option command 'AT+CGSN' - -config custom-commands - option description '查询模组IMEI > AT+GSN' - option command 'AT+GSN' - -config custom-commands - option description '更改模组IMEI > AT+EGMR=1,7,"IMEI"' - option command 'AT+EGMR=1,7,"在此设置IMEI"' - -config custom-commands - option description '获取模组温度 > AT+QTEMP' - option command 'AT+QTEMP' - -config custom-commands - option description '切换为USB通信端口 > AT+QCFG="data_interface",0,0' - option command 'AT+QCFG="data_interface",0,0' - -config custom-commands - option description '切换为PCIE通信端口 > AT+QCFG="data_interface",1,0' - option command 'AT+QCFG="data_interface",1,0' - -config custom-commands - option description '查看当前USB速率 > AT+QCFG="usbspeed"' - option command 'AT+QCFG="usbspeed"' - -config custom-commands - option description '切换为USB2.0 > AT+QCFG="usbspeed","20"' - option command 'AT+QCFG="usbspeed","20"' - -config custom-commands - option description '切换为USB3.1 Gen1(5Gbps) > AT+QCFG="usbspeed","311"' - option command 'AT+QCFG="usbspeed","311"' - -config custom-commands - option description '切换为USB3.1 Gen1(10Gbps) > AT+QCFG="usbspeed","312"' - option command 'AT+QCFG="usbspeed","312"' - -config custom-commands - option description '重置模组 > AT+QCFG="ResetFactory"' - option command 'AT+QCFG="ResetFactory"' - -config custom-commands - option description '****************广和通****************' - option command 'ATI' - -config custom-commands - option description '设置当前使用的为卡1 > AT+GTDUALSIM=0' - option command 'AT+GTDUALSIM=0' - -config custom-commands - option description '设置当前使用的为卡2 > AT+GTDUALSIM=1' - option command 'AT+GTDUALSIM=1' - -config custom-commands - option description 'ECM手动拨号 > AT+GTRNDIS=1,1' - option command 'AT+GTRNDIS=1,1' - -config custom-commands - option description 'ECM拨号断开 > AT+GTRNDIS=0,1' - option command 'AT+GTRNDIS=0,1' - -config custom-commands - option description '查询当前端口模式 > AT+GTUSBMODE?' - option command 'AT+GTUSBMODE?' - -config custom-commands - option description 'QMI/GobiNet拨号 > AT+GTUSBMODE=32' - option command 'AT+GTUSBMODE=32' - -config custom-commands - option description 'ECM拨号 > AT+GTUSBMODE=18' - option command 'AT+GTUSBMODE=18' - -config custom-commands - option description 'MBIM拨号 > AT+GTUSBMODE=30' - option command 'AT+GTUSBMODE=30' - -config custom-commands - option description 'RNDIS拨号 > AT+GTUSBMODE=24' - option command 'AT+GTUSBMODE=24' - -config custom-commands - option description 'NCM拨号 > AT+GTUSBMODE=18' - option command 'AT+GTUSBMODE=18' - -config custom-commands - option description '锁4G > AT+GTACT=2' - option command 'AT+GTACT=2' - -config custom-commands - option description '锁5G > AT+GTACT=14' - option command 'AT+GTACT=14' - -config custom-commands - option description '恢复自动搜索网络 > AT+GTACT=20' - option command 'AT+GTACT=20' - -config custom-commands - option description '查询当前连接的网络类型 > AT+PSRAT?' - option command 'AT+PSRAT?' - -config custom-commands - option description '查询模组IMEI > AT+CGSN?' - option command 'AT+CGSN?' - -config custom-commands - option description '查询模组IMEI > AT+GSN?' - option command 'AT+GSN?' - -config custom-commands - option description '更改模组IMEI > AT+GTSN=1,7,"IMEI"' - option command 'AT+GTSN=1,7,"在此设置IMEI"' - -config custom-commands - option description '报告一次当前BBIC的温度 > AT+MTSM=1,6' - option command 'AT+MTSM=1,6' - -config custom-commands - option description '报告一次当前射频的温度 > AT+MTSM=1,7' - option command 'AT+MTSM=1,7' - -config custom-commands - option description '重置模组 > AT+CFUN=15' - option command 'AT+CFUN=15' - - -config dial-config 'defa0' - option network_bridge '0' - option enable '1' - option network 'wwan0' - option pdp_type 'ipv4v6' - option auth 'none' - option id 'defa0' - -config dial-config 'defa1' - option network_bridge '0' - option enable '1' - option network 'usb0' - option pdp_type 'ipv4v6' - option auth 'none' - option id 'defa1' - - -config dial-config 'defa2' - option network_bridge '0' - option enable '1' - option network 'eth2' - option pdp_type 'ipv4v6' - option auth 'none' - option id 'defa2' diff --git a/luci-app-modem/root/etc/hotplug.d/net/20-modem-net b/luci-app-modem/root/etc/hotplug.d/net/20-modem-net old mode 100644 new mode 100755 index 62499e7..fb12f2a --- a/luci-app-modem/root/etc/hotplug.d/net/20-modem-net +++ b/luci-app-modem/root/etc/hotplug.d/net/20-modem-net @@ -1,29 +1,25 @@ #!/bin/sh -# Copyright (C) 2023 Siriling - -#导入组件工具 -source "/usr/share/modem/modem_util.sh" - +# Copyright (C) 2024 Tom +manual=$(uci get -q modem.global.manual_configuration) +[ "${manual}" -eq 1 ] && exit +logger -t modem_hotplug "net slot: ${DEVPATH} action: ${ACTION}" #网络设备名称不存在,退出 [ -z "${INTERFACE}" ] && exit #网络设备路径不存在,退出 [ -z "${DEVPATH}" ] && exit -#始终确保存在运行目录 -mkdir -m 0755 -p "${MODEM_RUNDIR}" +slot_path=$(readlink -f "/sys/${DEVPATH}/device") +[ -z "${slot_path}" ] && exit +slot_dir=$(dirname "${slot_path}") +slot=$(basename "${slot_dir}") +#设备路径不存在,退出 -#初始化模组配置 -# [[ "${INTERFACE}" = *"ip6tnl0"* ]] && { -# sh "${SCRIPT_DIR}/modem_init.sh" -# } - -if [[ "${INTERFACE}" = *"usb"* ]] || [[ "${INTERFACE}" = *"wwan"* ]] || [[ "${INTERFACE}" = *"eth"* ]]; then - #配置网络设备 - m_set_network_device "${ACTION}" "${INTERFACE}" "/sys${DEVPATH}" "usb" - -elif [[ "${INTERFACE}" = *"mhi_hwip"* ]] || [[ "${INTERFACE}" = *"rmnet_mhi"* ]]; then - #配置网络设备 - m_set_network_device "${ACTION}" "${INTERFACE}" "/sys${DEVPATH}" "pcie" -else - exit -fi +[ -d "/sys/bus/usb/devices/${slot}" ] && slot_type="usb" +[ -d "/sys/bus/pci/devices/${slot}" ] && slot_type="pcie" +[ -z "${slot_type}" ] && exit +logger -t modem_hotplug "net slot: ${slot} action: ${ACTION} slot_type: ${slot_type}" +case "${ACTION}" in + add) + /usr/share/modem/modem_scan.sh add "${slot}" "${slot_type}" + ;; +esac diff --git a/luci-app-modem/root/etc/hotplug.d/usb/20-modem-usb b/luci-app-modem/root/etc/hotplug.d/usb/20-modem-usb old mode 100644 new mode 100755 index 702b28b..707340b --- a/luci-app-modem/root/etc/hotplug.d/usb/20-modem-usb +++ b/luci-app-modem/root/etc/hotplug.d/usb/20-modem-usb @@ -1,19 +1,19 @@ #!/bin/sh -# Copyright (C) 2023 Siriling - -#导入组件工具 -source "/usr/share/modem/modem_util.sh" - -#只在添加和移除的时候执行 -# [ "$ACTION" != "add" ] && [ "$ACTION" != "remove" ] && exit -#设备号不存在,退出(去掉多余的tty设备) +# Copyright (C) 2024 Tom +manual=$(uci get -q modem.global.manual_configuration) +[ "${manual}" -eq 1 ] && exit +logger -t modem_hotplug "usb_event slot: ${DEVPATH} action: ${ACTION}" [ -z "${DEVNUM}" ] && exit -#测试 -# test_usb_hotplug -#始终确保存在运行目录 -mkdir -m 0755 -p "${MODEM_RUNDIR}" - -#设置USB设备 -m_check_usb_device "${ACTION}" "${DEVNUM}" "${PRODUCT}" "/sys${DEVPATH}" +slot=$(basename "${DEVPATH}") +logger -t modem_hotplug "usb_event run slot: ${slot} action: ${ACTION}" +case "${ACTION}" in + bind|\ + add) + /usr/share/modem/modem_scan.sh add "${slot}" usb + ;; + remove) + /usr/share/modem/modem_scan.sh disable "${slot}" usb + ;; +esac diff --git a/luci-app-modem/root/etc/init.d/modem_init b/luci-app-modem/root/etc/init.d/modem_init new file mode 100755 index 0000000..2d4765b --- /dev/null +++ b/luci-app-modem/root/etc/init.d/modem_init @@ -0,0 +1,45 @@ +#!/bin/sh /etc/rc.common +START=80 +STOP=30 +USE_PROCD=1 + +. /lib/functions.sh + +start_service() { + + config_load modem + config_foreach mk_rundir modem-device + config_get manual_configuration global manual_configuration + [ "$manual_configuration" -eq 1 ] && return + logger -t modem_init "modem init" + config_foreach try_modem modem-slot +} + +mk_rundir() +{ + modem_cfg="$1" + mkdir -p "/var/run/modem/${modem_cfg}_dir" +} + +try_modem() +{ + config_get slot "$1" slot + config_get type "$1" type + case "$type" in + usb) + path="/sys/bus/usb/devices/${slot}" + ;; + pcie) + path="/sys/bus/pci/devices/${slot}" + ;; + esac + + if [ -d "$path" ]; then + logger -t modem_init "try modem $1" + procd_open_instance "try_$1" + procd_set_param command "ash" "/usr/share/modem/modem_scan.sh" "add" "$slot" "$type" + procd_close_instance + else + /usr/share/modem/modem_scan.sh disable "$slot" + fi +} diff --git a/luci-app-modem/root/etc/init.d/modem_network b/luci-app-modem/root/etc/init.d/modem_network index 511903b..5b7ee2b 100755 --- a/luci-app-modem/root/etc/init.d/modem_network +++ b/luci-app-modem/root/etc/init.d/modem_network @@ -8,9 +8,6 @@ SCRIPT_DIR="/usr/share/modem" #运行目录 MODEM_RUNDIR="/var/run/modem" -MODEM_RUN_CONFIG="${MODEM_RUNDIR}/config.cache" -#导入组件工具 -source "${SCRIPT_DIR}/modem_scan.sh" service_triggers() { @@ -20,44 +17,46 @@ service_triggers() start_service() { mkdir -p $MODEM_RUNDIR - local enable_dial=$(uci -q get modem.@global[0].enable_dial) - if [ "$enable_dial" = "0" ]; then - stop_service - else + #加载模组配置 config_load modem - config_foreach dial_modem modem-device - fi + config_get enabled global enable_dial + [ "$enabled" = "0" ] && config_foreach hang_modem modem-device && stop + config_foreach run_modem modem-device } reload_service() { - stop_service - start_service + stop + start } stop_service() { #清理运行目录 - rm -rf $MODEM_RUNDIR config_load modem config_foreach hang_modem modem-device } -dial_modem() + + +run_modem() { - config_get enable_dial $1 enable_dial - if [ "$enable_dial" == "1" ];then - procd_open_instance "modem_$1" - procd_set_param command "/usr/share/modem/modem_dial.sh" "$1" "dial" - procd_set_param respawn - procd_close_instance - else + config_get enabled $1 enable_dial + if [ "$enabled" = "0" ] ;then hang_modem $1 + return fi + procd_open_instance "modem_$1" + procd_set_param command "/usr/share/modem/modem_dial.sh" "$1" dial + procd_set_param respawn + procd_close_instance + logger -t modem_network "dial modem $1" } hang_modem() { - /usr/share/modem/modem_dial.sh $1 hang + service_stop "modem_$1" + "/usr/share/modem/modem_dial.sh" "$1" hang + logger -t modem_network "hang modem $1" } diff --git a/luci-app-modem/root/etc/init.d/modem_scan b/luci-app-modem/root/etc/init.d/modem_scan deleted file mode 100755 index 0726a69..0000000 --- a/luci-app-modem/root/etc/init.d/modem_scan +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/sh /etc/rc.common -START=95 -STOP=13 -USE_PROCD=1 - -#运行目录 -MODEM_RUNDIR="/var/run/modem" -MODEM_RUN_CONFIG="${MODEM_RUNDIR}/config.cache" - - - -start_service() { - mkdir -p $MODEM_RUNDIR - local dontscan=$(uci -q get modem.@global[0].manual_configuration) - logger -t modem_scan "manual_configuration: $dontscan" - if [ "$dontscan" == "0" ]; then - procd_open_instance "modem_scan_service" - procd_set_param command /usr/share/modem/usb_modem_scan.sh - procd_close_instance - fi -} diff --git a/luci-app-modem/root/etc/uci-defaults/99-add-5g-handler b/luci-app-modem/root/etc/uci-defaults/99-add-5g-handler new file mode 100755 index 0000000..4de6df2 --- /dev/null +++ b/luci-app-modem/root/etc/uci-defaults/99-add-5g-handler @@ -0,0 +1,69 @@ +#!/bin/sh + +. /lib/functions.sh +. /lib/functions/uci-defaults.sh +. /lib/functions/system.sh + +modem_settings() +{ + local board="$1" + + case $board in + HC,HC-G80) + + #mini pci slot + uci set modem.u1_1_4="modem-slot" + uci set modem.u1_1_4.slot="1-1.4" + uci set modem.u1_1_4.type="usb" + uci set modem.u1_1_4.net_led="wwan" + #m.2 slot (usb2.0) + uci set modem.u1_1_1="modem-slot" + uci set modem.u1_1_1.slot="1-1.1" + uci set modem.u1_1_1.type="usb" + uci set modem.u1_1_1.net_led="wwan" + uci set modem.u1_1_1.ethernet="cpewan0" + #m.2 slot (usb3.0) + uci set modem.u2_1="modem-slot" + uci set modem.u2_1.slot="2-1" + uci set modem.u2_1.type="usb" + uci set modem.u2_1.net_led="wwan" + uci set modem.u2_1.ethernet="cpewan0" + uci commit modem + ;; + huasifei,ws3006) + #m2 usb3.0 + #(slot 2) + uci set modem.u2_1_2="modem-slot" + uci set modem.u2_1_2.slot="2-1.2" + uci set modem.u2_1_2.type="usb" + uci set modem.u2_1_2.net_led="wwan2" + uci set modem.u2_1_2.sim_led="green:sim2" + #(slot 1) + uci set modem.u2_1_4="modem-slot" + uci set modem.u2_1_4.slot="2-1.4" + uci set modem.u2_1_4.type="usb" + uci set modem.u2_1_4.net_led="wwan1" + uci set modem.u2_1_4.sim_led="green:sim1" + #mini pci slot + #(slot 2) + uci set modem.u1_1_2="modem-slot" + uci set modem.u1_1_2.slot="1-1.2" + uci set modem.u1_1_2.type="usb" + uci set modem.u1_1_2.net_led="wwan2" + uci set modem.u1_1_2.sim_led="green:sim2" + #(slot 1) + uci set modem.u1_1_3="modem-slot" + uci set modem.u1_1_3.slot="1-1.3" + uci set modem.u1_1_3.type="usb" + uci set modem.u1_1_3.net_led="wwan1" + uci set modem.u1_1_3.sim_led="green:sim1" + + uci commit modem + ;; + + esac +} + +board=$(board_name) +modem_settings $board +exit 0 diff --git a/luci-app-modem/root/usr/libexec/rpcd/modem_ctrl b/luci-app-modem/root/usr/libexec/rpcd/modem_ctrl new file mode 100755 index 0000000..bf36cd0 --- /dev/null +++ b/luci-app-modem/root/usr/libexec/rpcd/modem_ctrl @@ -0,0 +1,79 @@ +#!/bin/sh +. /lib/functions.sh +info() +{ + state=$(uci get modem.$1.state) + if [ "$state" = "disabled" ]; then + return + fi + info=$(/usr/share/modem/modem_ctrl.sh info $1) + json_array=$(echo $json_array | jq ". += [ $info ]") +} + +sim_info() +{ + state=$(uci get modem.$1.state) + if [ "$state" = "disabled" ]; then + return + fi + /usr/share/modem/modem_ctrl.sh sim_info $1 +} + +base_info() +{ + state=$(uci get modem.$1.state) + if [ "$state" = "disabled" ]; then + return + fi + /usr/share/modem/modem_ctrl.sh base_info $1 +} + +network_info() +{ + state=$(uci get modem.$1.state) + if [ "$state" = "disabled" ]; then + return + fi + /usr/share/modem/modem_ctrl.sh network_info $1 +} + + +cell_info() +{ + state=$(uci get modem.$1.state) + if [ "$state" = "disabled" ]; then + return + fi + /usr/share/modem/modem_ctrl.sh cell_info $1 +} +case "$1" in + list) + echo '{ "info": { }, "base_info": { }, "failme": {} }' + ;; + call) + case "$2" in + "info") + json_array="[]" + config_load modem + config_foreach info modem-device + echo "{\"info\":$json_array}" + ;; + "base_info") + config_load modem + config_foreach base_info modem-device + ;; + "sim_info") + config_load modem + config_foreach sim_info modem-device + ;; + "network_info") + config_load modem + config_foreach network_info modem-device + ;; + "cell_info") + config_load modem + config_foreach cell_info modem-device + ;; + esac + ;; +esac diff --git a/luci-app-modem/root/usr/share/modem/fibocom.sh b/luci-app-modem/root/usr/share/modem/fibocom.sh index 575f40a..ed0acf5 100755 --- a/luci-app-modem/root/usr/share/modem/fibocom.sh +++ b/luci-app-modem/root/usr/share/modem/fibocom.sh @@ -1,112 +1,19 @@ #!/bin/sh # Copyright (C) 2023 Siriling -#脚本目录 -SCRIPT_DIR="/usr/share/modem" -source /usr/share/libubox/jshn.sh -#预设 -fibocom_presets() -{ - #设置IPv6地址格式 - at_command='AT+CGPIAF=1,0,0,0' - sh "${SCRIPT_DIR}/modem_at.sh" "$at_port" "$at_command" - - #自动DHCP - at_command='AT+GTAUTODHCP=1' - sh "${SCRIPT_DIR}/modem_at.sh" "$at_port" "$at_command" - - #启用IP直通 - at_command='AT+GTIPPASS=1,1' - sh "${SCRIPT_DIR}/modem_at.sh" "$at_port" "$at_command" - - #启用自动拨号 - at_command='AT+GTAUTOCONNECT=1' - sh "${SCRIPT_DIR}/modem_at.sh" "$at_port" "$at_command" -} - -#获取DNS -# $1:AT串口 -# $2:连接定义 -fibocom_get_dns() -{ - local at_port="$1" - local define_connect="$2" - - [ -z "$define_connect" ] && { - define_connect="1" - } - - local public_dns1_ipv4="223.5.5.5" - local public_dns2_ipv4="119.29.29.29" - local public_dns1_ipv6="2400:3200::1" #下一代互联网北京研究中心:240C::6666,阿里:2400:3200::1,腾讯:2402:4e00:: - local public_dns2_ipv6="2402:4e00::" - - #获取DNS地址 - at_command="AT+GTDNS=${define_connect}" - local response=$(at ${at_port} ${at_command} | grep "+GTDNS: " | grep -E '[0-9]+.[0-9]+.[0-9]+.[0-9]+' | sed -n '1p') - - local ipv4_dns1=$(echo "${response}" | awk -F'"' '{print $2}' | awk -F',' '{print $1}') - [ -z "$ipv4_dns1" ] && { - ipv4_dns1="${public_dns1_ipv4}" - } - - local ipv4_dns2=$(echo "${response}" | awk -F'"' '{print $4}' | awk -F',' '{print $1}') - [ -z "$ipv4_dns2" ] && { - ipv4_dns2="${public_dns2_ipv4}" - } - - local ipv6_dns1=$(echo "${response}" | awk -F'"' '{print $2}' | awk -F',' '{print $2}') - [ -z "$ipv6_dns1" ] && { - ipv6_dns1="${public_dns1_ipv6}" - } - - local ipv6_dns2=$(echo "${response}" | awk -F'"' '{print $4}' | awk -F',' '{print $2}') - [ -z "$ipv6_dns2" ] && { - ipv6_dns2="${public_dns2_ipv6}" - } - - dns="{ - \"dns\":{ - \"ipv4_dns1\":\"$ipv4_dns1\", - \"ipv4_dns2\":\"$ipv4_dns2\", - \"ipv6_dns1\":\"$ipv6_dns1\", - \"ipv6_dns2\":\"$ipv6_dns2\" - } - }" - - echo "$dns" -} - +source /usr/share/modem/generic.sh +debug_subject="fibocom_ctrl" #获取拨号模式 # $1:AT串口 # $2:平台 -fibocom_get_mode() +get_mode() { - local at_port="$1" - local platform="$2" - - at_command="AT+GTUSBMODE?" - local mode_num=$(sh ${SCRIPT_DIR}/modem_at.sh ${at_port} ${at_command} | grep "+GTUSBMODE:" | sed 's/+GTUSBMODE: //g' | sed 's/\r//g') - - if [ -z "$mode_num" ]; then - echo "unknown" - return - fi - - #获取芯片平台 - if [ -z "$platform" ]; then - local modem_number=$(uci -q get modem.@global[0].modem_number) - for i in $(seq 0 $((modem_number-1))); do - local at_port_tmp=$(uci -q get modem.modem$i.at_port) - if [ "$at_port" = "$at_port_tmp" ]; then - platform=$(uci -q get modem.modem$i.platform) - break - fi - done - fi + local at_command="AT+GTUSBMODE?" + local mode_num=$(at ${at_port} ${at_command} | grep "+GTUSBMODE:" | sed 's/+GTUSBMODE: //g' | sed 's/\r//g') local mode case "$platform" in + "lte"|\ "qualcomm") case "$mode_num" in "17") mode="qmi" ;; #- @@ -150,30 +57,22 @@ fibocom_get_mode() mode="$mode_num" ;; esac - echo "${mode}" + available_modes=$(uci -q get modem.$config_section.modes) + json_add_object "mode" + for available_mode in $available_modes; do + if [ "$mode" = "$available_mode" ]; then + json_add_string "$available_mode" "1" + else + json_add_string "$available_mode" "0" + fi + done + json_close_objectget_imei } #设置拨号模式 -# $1:AT串口 -# $2:拨号模式配置 -fibocom_set_mode() +set_mode() { - local at_port="$1" - local mode_config="$2" - - #获取芯片平台 - local platform - local modem_number=$(uci -q get modem.@global[0].modem_number) - for i in $(seq 0 $((modem_number-1))); do - local at_port_tmp=$(uci -q get modem.modem$i.at_port) - if [ "$at_port" = "$at_port_tmp" ]; then - platform=$(uci -q get modem.modem$i.platform) - break - fi - done - - #获取拨号模式配置 - local mode_num + local mode_config=$1 case "$platform" in "qualcomm") case "$mode_config" in @@ -203,6 +102,15 @@ fibocom_set_mode() *) mode_num="41" ;; esac ;; + "lte") + case "$mode_config" in + "qmi") mode_num="17" ;; + "ecm") mode_num="18" ;; + "rndis") mode_num="24" ;; + "ncm") mode_num="18" ;; + *) mode_num="32" ;; + esac + ;; *) mode_num="32" ;; @@ -210,16 +118,18 @@ fibocom_set_mode() #设置模组 at_command="AT+GTUSBMODE=${mode_num}" - sh ${SCRIPT_DIR}/modem_at.sh ${at_port} "${at_command}" + res=$(at "${at_port}" "${at_command}") + json_select "result" + json_add_string "set_mode" "$res" + json_add_string "mode" "$mode_config" + json_close_object } #获取网络偏好 -# $1:AT串口 -fibocom_get_network_prefer() +get_network_prefer_nr() { - local at_port="$1" at_command="AT+GTACT?" - local network_prefer_num=$(sh ${SCRIPT_DIR}/modem_at.sh $at_port $at_command | grep "+GTACT:" | awk -F',' '{print $1}' | sed 's/+GTACT: //g') + local network_prefer_num=$(at $at_port $at_command | grep "+GTACT:" | awk -F',' '{print $1}' | sed 's/+GTACT: //g') local network_prefer_3g="0"; local network_prefer_4g="0"; @@ -259,50 +169,37 @@ fibocom_get_network_prefer() ;; esac - local network_prefer="{ - \"network_prefer\":{ - \"3G\":$network_prefer_3g, - \"4G\":$network_prefer_4g, - \"5G\":$network_prefer_5g - } - }" - echo "$network_prefer" + json_add_object network_prefer + json_add_string 3G $network_prefer_3g + json_add_string 4G $network_prefer_4g + json_add_string 5G $network_prefer_5g + json_close_array } #设置网络偏好 -# $1:AT串口 -# $2:网络偏好配置 -fibocom_set_network_prefer() +# $1:网络偏好配置 +set_network_prefer_nr() { - local at_port="$1" - local network_prefer="$2" - - #获取网络偏好数字 - local network_prefer_num - - #获取选中的数量 - local count=$(echo "$network_prefer" | grep -o "1" | wc -l) - #获取每个偏好的值 - local network_prefer_3g=$(echo "$network_prefer" | jq -r '.["3G"]') - local network_prefer_4g=$(echo "$network_prefer" | jq -r '.["4G"]') - local network_prefer_5g=$(echo "$network_prefer" | jq -r '.["5G"]') - + network_prefer_3g=$(echo $1 |jq -r 'contains(["3G"])') + network_prefer_4g=$(echo $1 |jq -r 'contains(["4G"])') + network_prefer_5g=$(echo $1 |jq -r 'contains(["5G"])') + count=$(echo $1 |jq -r 'length') case "$count" in "1") - if [ "$network_prefer_3g" = "1" ]; then - network_prefer_num="1" - elif [ "$network_prefer_4g" = "1" ]; then + if [ "$network_prefer_3g" = "true" ]; then + network_prefer_num="true" + elif [ "$network_prefer_4g" = "true" ]; then network_prefer_num="2" - elif [ "$network_prefer_5g" = "1" ]; then + elif [ "$network_prefer_5g" = "true" ]; then network_prefer_num="14" fi ;; "2") - if [ "$network_prefer_3g" = "1" ] && [ "$network_prefer_4g" = "1" ]; then + if [ "$network_prefer_3g" = "true" ] && [ "$network_prefer_4g" = "true" ]; then network_prefer_num="4" - elif [ "$network_prefer_3g" = "1" ] && [ "$network_prefer_5g" = "1" ]; then + elif [ "$network_prefer_3g" = "true" ] && [ "$network_prefer_5g" = "true" ]; then network_prefer_num="16" - elif [ "$network_prefer_4g" = "1" ] && [ "$network_prefer_5g" = "1" ]; then + elif [ "$network_prefer_4g" = "true" ] && [ "$network_prefer_5g" = "true" ]; then network_prefer_num="17" fi ;; @@ -312,42 +209,152 @@ fibocom_set_network_prefer() #设置模组 at_command="AT+GTACT=$network_prefer_num" - sh ${SCRIPT_DIR}/modem_at.sh $at_port "$at_command" + res=$(at $at_port "$at_command") + json_select_object "result" + json_add_string "status" "$res" + json_close_object } +#获取网络偏好 +get_network_prefer_lte() +{ + at_command="AT+GTACT?" + local network_prefer_num=$(at $at_port $at_command | grep "+GTACT:" | awk -F',' '{print $1}' | sed 's/+GTACT: //g') + + local network_prefer_3g="0"; + local network_prefer_4g="0"; + + #匹配不同的网络类型 + case "$network_prefer_num" in + "1") network_prefer_3g="1" ;; + "2") network_prefer_4g="1" ;; + "4") + network_prefer_3g="1" + network_prefer_4g="1" + ;; + "10") + network_prefer_3g="1" + network_prefer_4g="1" + ;; + *) + network_prefer_3g="1" + network_prefer_4g="1" + ;; + esac + + json_add_object network_prefer + json_add_string 3G $network_prefer_3g + json_add_string 4G $network_prefer_4g + json_close_array +} + +#设置网络偏好 +# $1:网络偏好配置 +set_network_prefer_lte() +{ + network_prefer_3g=$(echo $1 |jq -r 'contains(["3G"])') + network_prefer_4g=$(echo $1 |jq -r 'contains(["4G"])') + count=$(echo $1 |jq -r 'length') + case "$count" in + "1") + if [ "$network_prefer_3g" = "true" ]; then + network_prefer_num="1" + elif [ "$network_prefer_4g" = "true" ]; then + network_prefer_num="2" + fi + ;; + "2") + if [ "$network_prefer_3g" = "true" ] && [ "$network_prefer_4g" = "true" ]; then + network_prefer_num="10" + fi + ;; + *) network_prefer_num="10" ;; + esac + + #设置模组 + at_command="AT+GTACT=$network_prefer_num" + res=$(at $at_port "$at_command") + json_select_object "result" + json_add_string "status" "$res" + json_add_string raw "$1" + json_add_string "network_prefer_num" "$network_prefer_num" + json_add_string "network_prefer_3g" "$network_prefer_3g" + json_add_string "network_prefer_4g" "$network_prefer_4g" + json_close_object +} + +get_network_prefer() +{ + case $platform in + "qualcomm") + get_network_prefer_nr + ;; + "unisoc") + get_network_prefer_nr + ;; + "mediatek") + get_network_prefer_nr + ;; + "lte") + get_network_prefer_lte + ;; + *) + get_network_prefer_nr + ;; + esac +} + +set_network_prefer() +{ + case $platform in + "qualcomm") + set_network_prefer_nr $1 + ;; + "unisoc") + set_network_prefer_nr $1 + ;; + "mediatek") + set_network_prefer_nr $1 + ;; + "lte") + set_network_prefer_lte $1 + ;; + *) + set_network_prefer_nr $1 + ;; + esac +} #获取电压 # $1:AT串口 -fibocom_get_voltage() +get_voltage() { - local at_port="$1" - - #Voltage(电压) at_command="AT+CBC" - local voltage=$(sh ${SCRIPT_DIR}/modem_at.sh $at_port $at_command | grep "+CBC:" | awk -F',' '{print $2}' | sed 's/\r//g') - echo "${voltage}" + local voltage=$(at $at_port $at_command | grep "+CBC:" | awk -F',' '{print $2}' | sed 's/\r//g') + [ -n $voltage ] && { + voltage="${voltage}mV" + } + add_plain_info_entry "voltage" "$voltage" "Voltage" } #获取温度 # $1:AT串口 -fibocom_get_temperature() +get_temperature() { - local at_port="$1" - #Temperature(温度) at_command="AT+MTSM=1,6" - response=$(sh ${SCRIPT_DIR}/modem_at.sh $at_port $at_command | grep "+MTSM: " | sed 's/+MTSM: //g' | sed 's/\r//g') + response=$(at $at_port $at_command | grep "+MTSM: " | sed 's/+MTSM: //g' | sed 's/\r//g') [ -z "$response" ] && { #Fx160及以后型号 at_command="AT+GTLADC" - response=$(sh ${SCRIPT_DIR}/modem_at.sh $at_port $at_command | grep "cpu" | awk -F' ' '{print $2}' | sed 's/\r//g') + response=$(at $at_port $at_command | grep "cpu" | awk -F' ' '{print $2}' | sed 's/\r//g') response="${response:0:2}" } [ -z "$response" ] && { #联发科平台 at_command="AT+GTSENRDTEMP=1" - response=$(sh ${SCRIPT_DIR}/modem_at.sh $at_port $at_command | grep "+GTSENRDTEMP: " | awk -F',' '{print $2}' | sed 's/\r//g') + response=$(at $at_port $at_command | grep "+GTSENRDTEMP: " | awk -F',' '{print $2}' | sed 's/\r//g') response="${response:0:2}" } @@ -356,108 +363,59 @@ fibocom_get_temperature() temperature="${response}$(printf "\xc2\xb0")C" } - echo "${temperature}" + add_plain_info_entry "temperature" "$temperature" "Temperature" } -#获取连接状态 -# $1:AT串口 -# $2:连接定义 -fibocom_get_connect_status() -{ - local at_port="$1" - local define_connect="$2" - #默认值为1 - [ -z "$define_connect" ] && { - define_connect="1" - } - - at_command="AT+CGPADDR=${define_connect}" - local ipv4=$(sh ${SCRIPT_DIR}/modem_at.sh ${at_port} ${at_command} | grep "+CGPADDR: " | awk -F'"' '{print $2}') - local not_ip="0.0.0.0" - - #设置连接状态 - local connect_status - if [ -z "$ipv4" ] || [[ "$ipv4" = *"$not_ip"* ]]; then - connect_status="disconnect" - else - connect_status="connect" - fi - - echo "${connect_status}" -} #基本信息 -fibocom_base_info() +base_info() { - debug "Fibocom base info" + m_debug "Fibocom base info" #Name(名称) at_command="AT+CGMM?" - name=$(sh ${SCRIPT_DIR}/modem_at.sh $at_port $at_command | grep "+CGMM: " | awk -F'"' '{print $2}') + name=$(at $at_port $at_command | grep "+CGMM: " | awk -F'"' '{print $2}') #Manufacturer(制造商) at_command="AT+CGMI?" - manufacturer=$(sh ${SCRIPT_DIR}/modem_at.sh $at_port $at_command | grep "+CGMI: " | awk -F'"' '{print $2}') + manufacturer=$(at $at_port $at_command | grep "+CGMI: " | awk -F'"' '{print $2}') #Revision(固件版本) at_command="AT+CGMR?" - revision=$(sh ${SCRIPT_DIR}/modem_at.sh $at_port $at_command | grep "+CGMR: " | awk -F'"' '{print $2}') + revision=$(at $at_port $at_command | grep "+CGMR: " | awk -F'"' '{print $2}') - #Mode(拨号模式) - mode=$(fibocom_get_mode ${at_port} ${platform} | tr 'a-z' 'A-Z') - - #Temperature(温度) - temperature=$(fibocom_get_temperature $at_port) + class="Base Information" + add_plain_info_entry "manufacturer" "$manufacturer" "Manufacturer" + add_plain_info_entry "revision" "$revision" "Revision" + add_plain_info_entry "at_port" "$at_port" "AT Port" + get_temperature + get_voltage + get_connect_status } #获取SIM卡状态 # $1:SIM卡状态标志 -fibocom_get_sim_status() -{ - local sim_status - case $1 in - "") sim_status="miss" ;; - *"ERROR"*) sim_status="miss" ;; - *"READY"*) sim_status="ready" ;; - *"SIM PIN"*) sim_status="MT is waiting SIM PIN to be given" ;; - *"SIM PUK"*) sim_status="MT is waiting SIM PUK to be given" ;; - *"PH-FSIM PIN"*) sim_status="MT is waiting phone-to-SIM card password to be given" ;; - *"PH-FSIM PIN"*) sim_status="MT is waiting phone-to-very first SIM card password to be given" ;; - *"PH-FSIM PUK"*) sim_status="MT is waiting phone-to-very first SIM card unblocking password to be given" ;; - *"SIM PIN2"*) sim_status="MT is waiting SIM PIN2 to be given" ;; - *"SIM PUK2"*) sim_status="MT is waiting SIM PUK2 to be given" ;; - *"PH-NET PIN"*) sim_status="MT is waiting network personalization password to be given" ;; - *"PH-NET PUK"*) sim_status="MT is waiting network personalization unblocking password to be given" ;; - *"PH-NETSUB PIN"*) sim_status="MT is waiting network subset personalization password to be given" ;; - *"PH-NETSUB PUK"*) sim_status="MT is waiting network subset personalization unblocking password to be given" ;; - *"PH-SP PIN"*) sim_status="MT is waiting service provider personalization password to be given" ;; - *"PH-SP PUK"*) sim_status="MT is waiting service provider personalization unblocking password to be given" ;; - *"PH-CORP PIN"*) sim_status="MT is waiting corporate personalization password to be given" ;; - *"PH-CORP PUK"*) sim_status="MT is waiting corporate personalization unblocking password to be given" ;; - *) sim_status="unknown" ;; - esac - echo "${sim_status}" -} + #SIM卡信息 -fibocom_sim_info() +sim_info() { - debug "Fibocom sim info" + m_debug "Fibocom sim info" #SIM Slot(SIM卡卡槽) at_command="AT+GTDUALSIM?" - sim_slot=$(sh ${SCRIPT_DIR}/modem_at.sh ${at_port} ${at_command} | grep "+GTDUALSIM" | awk -F'"' '{print $2}' | sed 's/SUB//g') + sim_slot=$(at ${at_port} ${at_command} | grep "+GTDUALSIM" | awk -F'"' '{print $2}' | sed 's/SUB//g') #IMEI(国际移动设备识别码) at_command="AT+CGSN?" - imei=$(sh ${SCRIPT_DIR}/modem_at.sh ${at_port} ${at_command} | grep "+CGSN: " | awk -F'"' '{print $2}') + imei=$(at ${at_port} ${at_command} | grep "+CGSN: " | awk -F'"' '{print $2}') #SIM Status(SIM状态) at_command="AT+CPIN?" - sim_status_flag=$(sh ${SCRIPT_DIR}/modem_at.sh ${at_port} ${at_command} | grep "+CPIN: ") + sim_status_flag=$(at ${at_port} ${at_command} | grep "+CPIN: ") [ -z "$sim_status_flag" ] && { - sim_status_flag=$(sh ${SCRIPT_DIR}/modem_at.sh ${at_port} ${at_command} | grep "+CME") + sim_status_flag=$(at ${at_port} ${at_command} | grep "+CME") } - sim_status=$(fibocom_get_sim_status "$sim_status_flag") + sim_status=$(get_sim_status "$sim_status_flag") if [ "$sim_status" != "ready" ]; then return @@ -465,7 +423,7 @@ fibocom_sim_info() #ISP(互联网服务提供商) at_command="AT+COPS?" - isp=$(sh ${SCRIPT_DIR}/modem_at.sh ${at_port} ${at_command} | grep "+COPS" | awk -F'"' '{print $2}') + isp=$(at ${at_port} ${at_command} | grep "+COPS" | awk -F'"' '{print $2}') # if [ "$isp" = "CHN-CMCC" ] || [ "$isp" = "CMCC" ]|| [ "$isp" = "46000" ]; then # isp="中国移动" # elif [ "$isp" = "CHN-UNICOM" ] || [ "$isp" = "UNICOM" ] || [ "$isp" = "46001" ]; then @@ -476,44 +434,59 @@ fibocom_sim_info() #SIM Number(SIM卡号码,手机号) at_command="AT+CNUM" - sim_number=$(sh ${SCRIPT_DIR}/modem_at.sh ${at_port} ${at_command} | grep "+CNUM: " | awk -F'"' '{print $2}') + sim_number=$(at ${at_port} ${at_command} | grep "+CNUM: " | awk -F'"' '{print $2}') [ -z "$sim_number" ] && { - sim_number=$(sh ${SCRIPT_DIR}/modem_at.sh ${at_port} ${at_command} | grep "+CNUM: " | awk -F'"' '{print $4}') + sim_number=$(at ${at_port} ${at_command} | grep "+CNUM: " | awk -F'"' '{print $4}') } #IMSI(国际移动用户识别码) at_command="AT+CIMI?" - imsi=$(sh ${SCRIPT_DIR}/modem_at.sh ${at_port} ${at_command} | grep "+CIMI: " | awk -F' ' '{print $2}' | sed 's/"//g' | sed 's/\r//g') + imsi=$(at ${at_port} ${at_command} | grep "+CIMI: " | awk -F' ' '{print $2}' | sed 's/"//g' | sed 's/\r//g') [ -z "$sim_number" ] && { - imsi=$(sh ${SCRIPT_DIR}/modem_at.sh ${at_port} ${at_command} | grep "+CIMI: " | awk -F'"' '{print $2}') + imsi=$(at ${at_port} ${at_command} | grep "+CIMI: " | awk -F'"' '{print $2}') } #ICCID(集成电路卡识别码) at_command="AT+ICCID" - iccid=$(sh ${SCRIPT_DIR}/modem_at.sh ${at_port} ${at_command} | grep -o "+ICCID:[ ]*[-0-9]\+" | grep -o "[-0-9]\{1,4\}") + iccid=$(at ${at_port} ${at_command} | grep -o "+ICCID:[ ]*[-0-9]\+" | grep -o "[-0-9]\{1,4\}") + class="SIM Information" + case "$sim_status" in + "ready") + add_plain_info_entry "SIM Status" "$sim_status" "SIM Status" + add_plain_info_entry "ISP" "$isp" "Internet Service Provider" + add_plain_info_entry "SIM Slot" "$sim_slot" "SIM Slot" + add_plain_info_entry "SIM Number" "$sim_number" "SIM Number" + add_plain_info_entry "IMEI" "$imei" "International Mobile Equipment Identity" + add_plain_info_entry "IMSI" "$imsi" "International Mobile Subscriber Identity" + add_plain_info_entry "ICCID" "$iccid" "Integrate Circuit Card Identity" + ;; + "miss") + add_plain_info_entry "SIM Status" "$sim_status" "SIM Status" + add_plain_info_entry "IMEI" "$imei" "International Mobile Equipment Identity" + ;; + "unknown") + add_plain_info_entry "SIM Status" "$sim_status" "SIM Status" + ;; + *) + add_plain_info_entry "SIM Status" "$sim_status" "SIM Status" + add_plain_info_entry "SIM Slot" "$sim_slot" "SIM Slot" + add_plain_info_entry "IMEI" "$imei" "International Mobile Equipment Identity" + add_plain_info_entry "IMSI" "$imsi" "International Mobile Subscriber Identity" + add_plain_info_entry "ICCID" "$iccid" "Integrate Circuit Card Identity" + ;; + esac } -fibocom_get_imei() +get_imei() { - local at_port="$1" at_command="AT+CGSN?" - imei=$(sh ${SCRIPT_DIR}/modem_at.sh ${at_port} ${at_command} | grep "+CGSN: " | awk -F'"' '{print $2}'| grep -E '[0-9]+') - echo "$imei" + imei=$(at ${at_port} ${at_command} | grep "+CGSN: " | awk -F'"' '{print $2}'| grep -E '[0-9]+') + json_add_string "imei" "$imei" } -fibocom_set_imei() +set_imei() { - local at_port="$1" - local imei="$2" - local platform - local modem_number=$(uci -q get modem.@global[0].modem_number) - for i in $(seq 0 $((modem_number-1))); do - local at_port_tmp=$(uci -q get modem.modem$i.at_port) - if [ "$at_port" = "$at_port_tmp" ]; then - platform=$(uci -q get modem.modem$i.platform) - break - fi - done + imei="$1" case "$platform" in "qualcomm") at_command="AT+GTSN=1,7,\"$imei\"" @@ -524,72 +497,51 @@ fibocom_set_imei() "mediatek") at_command="AT+EGMREXT=1,7,\"$imei\"" ;; + "lte") + at_command="AT+LCTSN=1,7,\"$imei\"" + ;; *) at_command="AT+GTSN=1,7,\"$imei\"" ;; esac - #重定向stderr - res=$(sh ${SCRIPT_DIR}/modem_at.sh ${at_port} "${at_command}") 2>&1 -} -#获取网络类型 -# $1:网络类型数字 -fibocom_get_rat() -{ - local rat - case $1 in - "0"|"1"|"3"|"8") rat="GSM" ;; - "2"|"4"|"5"|"6"|"9"|"10") rat="WCDMA" ;; - "7") rat="LTE" ;; - "11"|"12") rat="NR" ;; - esac - echo "${rat}" + res=$(at ${at_port} "${at_command}") 2>&1 + json_select "result" + json_add_string "set_imei" "$res" + json_close_object + get_imei + } -#获取信号强度指示(4G) -# $1:信号强度指示数字 -fibocom_get_rssi() -{ - local rssi - case $1 in - "99") rssi="unknown" ;; - * ) rssi=$((2 * $1 - 113)) ;; - esac - echo "$rssi" -} + + #网络信息 -fibocom_network_info() +network_info() { - debug "Fibocom network info" - - #Connect Status(连接状态) - connect_status=$(fibocom_get_connect_status ${at_port} ${define_connect}) - if [ "$connect_status" != "connect" ]; then - return - fi + m_debug "Fibocom network info" #Network Type(网络类型) at_command="AT+PSRAT?" - network_type=$(sh ${SCRIPT_DIR}/modem_at.sh ${at_port} ${at_command} | grep "+PSRAT:" | sed 's/+PSRAT: //g' | sed 's/\r//g') + network_type=$(at ${at_port} ${at_command} | grep "+PSRAT:" | sed 's/+PSRAT: //g' | sed 's/\r//g') [ -z "$network_type" ] && { at_command='AT+COPS?' - local rat_num=$(sh ${SCRIPT_DIR}/modem_at.sh ${at_port} ${at_command} | grep "+COPS:" | awk -F',' '{print $4}' | sed 's/\r//g') - network_type=$(fibocom_get_rat ${rat_num}) + local rat_num=$(at ${at_port} ${at_command} | grep "+COPS:" | awk -F',' '{print $4}' | sed 's/\r//g') + network_type=$(get_rat ${rat_num}) } #设置网络类型为5G时,信号强度指示用RSRP代替 # at_command="AT+GTCSQNREN=1" - # sh ${SCRIPT_DIR}/modem_at.sh $at_port $at_command + # at $at_port $at_command #CSQ(信号强度) at_command="AT+CSQ" - response=$(sh ${SCRIPT_DIR}/modem_at.sh $at_port $at_command | grep "+CSQ:" | sed 's/+CSQ: //g' | sed 's/\r//g') + response=$(at $at_port $at_command | grep "+CSQ:" | sed 's/+CSQ: //g' | sed 's/\r//g') #RSSI(4G信号强度指示) # rssi_num=$(echo $response | awk -F',' '{print $1}') - # rssi=$(fibocom_get_rssi $rssi_num) + # rssi=$(get_rssi $rssi_num) #BER(4G信道误码率) # ber=$(echo $response | awk -F',' '{print $2}') @@ -600,43 +552,70 @@ fibocom_network_info() #速率统计 at_command="AT+GTSTATIS?" - response=$(sh ${SCRIPT_DIR}/modem_at.sh $at_port $at_command | grep "+GTSTATIS:" | sed 's/+GTSTATIS: //g' | sed 's/\r//g') + response=$(at $at_port $at_command | grep "+GTSTATIS:" | sed 's/+GTSTATIS: //g' | sed 's/\r//g') #当前上传速率(单位,Byte/s) tx_rate=$(echo $response | awk -F',' '{print $2}') #当前下载速率(单位,Byte/s) rx_rate=$(echo $response | awk -F',' '{print $1}') + class="Network Information" + add_plain_info_entry "Network Type" "$network_type" "Network Type" + add_plain_info_entry "CQI UL" "$cqi_ul" "Channel Quality Indicator for Uplink" + add_plain_info_entry "CQI DL" "$cqi_dl" "Channel Quality Indicator for Downlink" + add_plain_info_entry "AMBR UL" "$ambr_ul" "Access Maximum Bit Rate for Uplink" + add_plain_info_entry "AMBR DL" "$ambr_dl" "Access Maximum Bit Rate for Downlink" + add_plain_info_entry "Tx Rate" "$tx_rate B/s" "Transmit Rate" + add_plain_info_entry "Rx Rate" "$rx_rate B/s" "Receive Rate" +} + +get_lockband(){ + json_add_object "lockband" + case $platform in + "qualcomm") + get_lockband_nr + ;; + "unisoc") + get_lockband_nr + ;; + "mediatek") + get_lockband_nr + ;; + "lte") + get_lockband_lte + ;; + *) + get_lockband_nr + ;; + esac + json_close_object } #锁频信息 -fibocom_get_lockband() +get_lockband_nr() { - local at_port="$1" - debug "Fibocom get lockband info" + m_debug "Fibocom get lockband info" get_lockband_config_command="AT+GTACT?" get_available_band_command="AT+GTACT=?" - get_lockband_config_res=$(sh ${SCRIPT_DIR}/modem_at.sh $at_port $get_lockband_config_command) - get_available_band_res=$(sh ${SCRIPT_DIR}/modem_at.sh $at_port $get_available_band_command) - json_init - + get_lockband_config_res=$(at $at_port $get_lockband_config_command) + get_available_band_res=$(at $at_port $get_available_band_command) json_add_object "UMTS" - json_add_object "available_band" - json_close_object + json_add_array "available_band" + json_close_array json_add_array "lock_band" json_close_object json_close_object json_add_object "LTE" - json_add_object "available_band" - json_close_object + json_add_array "available_band" + json_close_array json_add_array "lock_band" json_close_object json_close_object json_add_object "NR" - json_add_object "available_band" - json_close_object + json_add_array "available_band" + json_close_array json_add_array "lock_band" - json_close_object + json_close_array json_close_object index=0 for i in $(echo "$get_available_band_res"| sed 's/\r//g' | awk -F"[()]" '{for(j=8; j= 100 LTE + if [ $i -lt 100 ]; then + json_select "UMTS" + json_select "available_band" + add_avalible_band_entry "$i" "UMTS_$i" + json_select ".." + json_select ".." + if [ $select_all_band -eq 1 ]; then + json_select "UMTS" + json_select "lock_band" + json_add_string "" "$i" + json_select ".." + json_select ".." + fi + else + json_select "LTE" + json_select "available_band" + trim_first_letter=$(echo "$i" | sed 's/^.//') + add_avalible_band_entry "$i" "LTE_$trim_first_letter" + json_select ".." + json_select ".." + if [ $select_all_band -eq 1 ]; then + json_select "LTE" + json_select "lock_band" + json_add_string "" "$i" + json_select ".." + json_select ".." + fi + fi + done + + for i in $(echo "$get_lockband_config_res" | sed 's/\r//g' | awk -F"," '{for(k='$seq'; k<=NF; k++) print $k}' ); do + # i 0,100 UMTS + # i 100,5000 LTE + # i 5000,10000 NR + if [ -z "$i" ]; then + continue + fi + if [ $i -lt 100 ]; then + json_select "UMTS" + json_select "lock_band" + json_add_string "" "$i" + json_select ".." + json_select ".." + elif [ $i -lt 500 ]; then + json_select "LTE" + json_select "lock_band" + json_add_string "" "$i" + json_select ".." + json_select ".." + fi + done + json_close_array } -fibocom_get_neighborcell() +set_lockband() { - local at_port="$1" - debug "Fibocom get neighborcell info" + config=$1 + band_class=$(echo $config | jq -r '.band_class') + lock_band=$(echo $config | jq -r '.lock_band') + case $platform in + "qualcomm") + set_lockband_nr + ;; + "unisoc") + set_lockband_nr + ;; + "mediatek") + set_lockband_nr + ;; + "lte") + set_lockband_lte + ;; + *) + set_lockband_nr + ;; + esac + json_select "result" + json_add_string "set_lockband" "$res" + json_add_string "config" "$config" + json_add_string "band_class" "$band_class" + json_add_string "lock_band" "$lock_band" + json_close_object +} +#设置锁频 +set_lockband_nr() +{ + m_debug "Fibocom set lockband info" + get_lockband_config_command="AT+GTACT?" + get_lockband_config_res=$(at $at_port $get_lockband_config_command) + network_prefer_config=$(echo $get_lockband_config_res |cut -d : -f 2| awk -F"," '{ print $1","$2","$3}' |tr -d ' ') + local lock_band="$network_prefer_config,$lock_band" + local set_lockband_command="AT+GTACT=$lock_band" + res=$(at $at_port $set_lockband_command) +} + +set_lockband_lte() +{ + m_debug "Fibocom set lte lockband" + get_lockband_config_command="AT+GTACT?" + get_lockband_config_res=$(at $at_port $get_lockband_config_command) + network_prefer_config=$(echo $get_lockband_config_res |cut -d : -f 2| awk -F"," '{ print $1}' |tr -d ' ') + local lock_band="$network_prefer_config,,,$lock_band" + local set_lockband_command="AT+GTACT=$lock_band" + res=$(at $at_port $set_lockband_command) +} + +get_neighborcell() +{ + m_debug "Fibocom get neighborcell info" get_neighborcell_command="AT+GTCCINFO?" get_lockcell_command="AT+GTCELLLOCK?" cell_type="undefined" - json_init - json_add_object "Feature" - json_add_string "Unlock" "1" - json_add_string "Lock PCI" "2" - json_add_string "Lock ARFCN" "3" - json_add_string "Lock Current" "4" - json_add_string "Reboot Modem" "5" - json_close_object + json_add_object "neighborcell" json_add_array "NR" json_close_array json_add_array "LTE" json_close_array - sh ${SCRIPT_DIR}/modem_at.sh $at_port $get_neighborcell_command > /tmp/neighborcell + at $at_port $get_neighborcell_command > /tmp/neighborcell while IFS= read -r line; do #跳过空行 line=$(echo $line | sed 's/\r//g') @@ -823,7 +916,7 @@ fibocom_get_neighborcell() esac done < "/tmp/neighborcell" - result=`sh ${SCRIPT_DIR}/modem_at.sh $at_port $get_lockcell_command | grep "+GTCELLLOCK:" | sed 's/+GTCELLLOCK: //g' | sed 's/\r//g'` + result=`at $at_port $get_lockcell_command | grep "+GTCELLLOCK:" | sed 's/+GTCELLLOCK: //g' | sed 's/\r//g'` #$1:lockcell_status $2:cell_type $3:lock_type $4:arfcn $5:pci $6:scs $7:nr_band json_add_object "lockcell_status" if [ -n "$result" ]; then @@ -849,96 +942,64 @@ fibocom_get_neighborcell() pci=$(echo "$result" | awk -F',' '{print $5}') scs=$(echo "$result" | awk -F',' '{print $6}') nr_band=$(echo "$result" | awk -F',' '{print $7}') - json_add_string "lockcell_status" "$lockcell_status" - json_add_string "cell_type" "$cell_type" - json_add_string "lock_type" "$lock_type" - json_add_string "arfcn" "$arfcn" - json_add_string "pci" "$pci" - json_add_string "scs" "$scs" - json_add_string "nr_band" "$nr_band" + json_add_string "Status" "$lockcell_status" + json_add_string "Rat" "$cell_type" + json_add_string "Lock Type" "$lock_type" + json_add_string "ARFCN" "$arfcn" + json_add_string "PCI" "$pci" + json_add_string "SCS" "$scs" + json_add_string "NR BAND" "$nr_band" fi json_close_object - - json_dump + json_close_object } -fibocom_setlockcell(){ - #at_port,func,celltype,arfcn,pci,scs,nrband - # "unlockcell" "1" - # "lockpci" "2" - # "lockarfcn" "3" - # "lockcurrent" "4" - # "reboot modem" "5" - local at_port="$1" - local func="$2" - local cell_type="$3" - local arfcn="$4" - local pci="$5" - local scs="$6" - local nrband="$7" - case $func in - "1") - fibocom_unlockcell $at_port - ;; - "2") - fibocom_lockpci $at_port $cell_type $arfcn $pci $scs $nrband - ;; - "3") - fibocom_lockarfcn $at_port $cell_type $arfcn - ;; - "4") - fibocom_lockcurrent $at_port - ;; - "5") - sh ${SCRIPT_DIR}/modem_reboot.sh $at_port at+cfun=1,1 - ;; - esac + +set_neighborcell(){ + json_param=$1 + rat=$(echo $json_param | jq -r '.rat') + pci=$(echo $json_param | jq -r '.pci') + arfcn=$(echo $json_param | jq -r '.arfcn') + band=$(echo $json_param | jq -r '.band') + scs=$(echo $json_param | jq -r '.scs') + lockcell_all + json_select "result" + json_add_string "setlockcell" "$res" + json_add_string "rat" "$rat" + json_add_string "pci" "$pci" + json_add_string "arfcn" "$arfcn" + json_add_string "band" "$band" + json_add_string "scs" "$scs" + json_close_object } -fibocom_unlockcell() -{ - local at_port="$1" - local unlockcell_command="AT+GTCELLLOCK=0" - sh ${SCRIPT_DIR}/modem_at.sh $at_port $unlockcell_command -} - -fibocom_lockcurrent() -{ - local at_port="$1" - local unlockcell_command="AT+GTCELLLOCK=1" - sh ${SCRIPT_DIR}/modem_at.sh $at_port $unlockcell_command -} - -fibocom_lockpci() -{ - local at_port="$1" - local cell_type="$2" - local arfcn="$3" - local pci="$4" - local scs="$5" - local nrband="$6" - if [ "$cell_type" == 1 ]; then - local set_lockcell_command="AT+GTCELLLOCK=1,$cell_type,0,$arfcn,$pci,$scs,50$nrband" +lockcell_all(){ + if [ -z "$pci" ] && [ -z "$arfcn" ]; then + local unlockcell="AT+GTCELLLOCK=0" + res1=$(at $at_port $unlockcell) + res=$res1 else - local set_lockcell_command="AT+GTCELLLOCK=1,$cell_type,0,$arfcn,$pci" + if [ -z $pci ] && [ -n $arfcn ]; then + lockpci_nr="AT+GTCELLLOCK=1,1,1,$arfcn" + lockpci_lte="AT+GTCELLLOCK=1,0,1,$arfcn" + + elif [ -n $pci ] && [ -n $arfcn ]; then + lockpci_nr="AT+GTCELLLOCK=1,1,0,$arfcn,$pci,$scs,50$band" + lockpci_lte="AT+GTCELLLOCK=1,0,0,$arfcn,$pci" + fi + if [ "$pci" -eq 0 ] && [ "$arfcn" -eq 0 ]; then + lockpci_nr="AT+GTCELLLOCK=1" + lockpci_lte="AT+GTCELLLOCK=1" + fi + if [ "$rat" -eq 1 ]; then + res=$(at $at_port $lockpci_nr) + elif [ "$rat" -eq 0 ]; then + res=$(at $at_port $lockpci_lte) + fi fi - echo $set_lockcell_command - sh ${SCRIPT_DIR}/modem_at.sh $at_port $set_lockcell_command } -fibocom_lockarfcn() -{ - local at_port="$1" - local cell_type="$2" - local arfcn="$3" - local set_lockcell_command="AT+GTCELLLOCK=1,$cell_type,1,$arfcn" - echo $set_lockcell_command - sh ${SCRIPT_DIR}/modem_at.sh $at_port $set_lockcell_command -} -#获取频段 -# $1:网络类型 -# $2:频段数字 -fibocom_get_band() +get_band() { local band case $1 in @@ -952,7 +1013,7 @@ fibocom_get_band() #获取带宽 # $1:网络类型 # $2:带宽数字 -fibocom_get_bandwidth() +get_bandwidth() { local network_type="$1" local bandwidth_num="$2" @@ -978,7 +1039,7 @@ fibocom_get_bandwidth() #获取信噪比 # $1:网络类型 # $2:信噪比数字 -fibocom_get_sinr() +get_sinr() { local sinr case $1 in @@ -991,7 +1052,7 @@ fibocom_get_sinr() #获取接收信号功率 # $1:网络类型 # $2:接收信号功率数字 -fibocom_get_rxlev() +get_rxlev() { local rxlev case $1 in @@ -1006,7 +1067,7 @@ fibocom_get_rxlev() #获取参考信号接收功率 # $1:网络类型 # $2:参考信号接收功率数字 -fibocom_get_rsrp() +get_rsrp() { local rsrp case $1 in @@ -1019,7 +1080,7 @@ fibocom_get_rsrp() #获取参考信号接收质量 # $1:网络类型 # $2:参考信号接收质量数字 -fibocom_get_rsrq() +get_rsrq() { local rsrq case $1 in @@ -1031,7 +1092,7 @@ fibocom_get_rsrq() #获取信号干扰比 # $1:信号干扰比数字 -fibocom_get_rssnr() +get_rssnr() { #去掉小数点后的0 local rssnr=$(awk "BEGIN{ printf \"%.2f\", $1 / 2 }" | sed 's/\.*0*$//') @@ -1040,27 +1101,27 @@ fibocom_get_rssnr() #获取Ec/Io # $1:Ec/Io数字 -fibocom_get_ecio() +get_ecio() { local ecio=$(awk "BEGIN{ printf \"%.2f\", $1 * 0.5 - 24.5 }" | sed 's/\.*0*$//') echo "$ecio" } #小区信息 -fibocom_cell_info() +cell_info() { - debug "Fibocom cell info" + m_debug "Fibocom cell info" at_command='AT+GTCCINFO?' - response=$(sh ${SCRIPT_DIR}/modem_at.sh $at_port $at_command) + response=$(at $at_port $at_command) local rat=$(echo "$response" | grep "service" | awk -F' ' '{print $1}') #适配联发科平台(FM350-GL) [ -z "$rat" ] && { at_command='AT+COPS?' - rat_num=$(sh ${SCRIPT_DIR}/modem_at.sh $at_port $at_command | grep "+COPS:" | awk -F',' '{print $4}' | sed 's/\r//g') - rat=$(fibocom_get_rat ${rat_num}) + rat_num=$(at $at_port $at_command | grep "+COPS:" | awk -F',' '{print $4}' | sed 's/\r//g') + rat=$(get_rat ${rat_num}) } for response in $response; do @@ -1077,17 +1138,17 @@ fibocom_cell_info() nr_arfcn=$(echo "$response" | awk -F',' '{print $7}') nr_physical_cell_id=$(echo "$response" | awk -F',' '{print $8}') nr_band_num=$(echo "$response" | awk -F',' '{print $9}') - nr_band=$(fibocom_get_band "NR" ${nr_band_num}) + nr_band=$(get_band "NR" ${nr_band_num}) nr_dl_bandwidth_num=$(echo "$response" | awk -F',' '{print $10}') - nr_dl_bandwidth=$(fibocom_get_bandwidth "NR" ${nr_dl_bandwidth_num}) + nr_dl_bandwidth=$(get_bandwidth "NR" ${nr_dl_bandwidth_num}) nr_sinr_num=$(echo "$response" | awk -F',' '{print $11}') - nr_sinr=$(fibocom_get_sinr "NR" ${nr_sinr_num}) + nr_sinr=$(get_sinr "NR" ${nr_sinr_num}) nr_rxlev_num=$(echo "$response" | awk -F',' '{print $12}') - nr_rxlev=$(fibocom_get_rxlev "NR" ${nr_rxlev_num}) + nr_rxlev=$(get_rxlev "NR" ${nr_rxlev_num}) nr_rsrp_num=$(echo "$response" | awk -F',' '{print $13}') - nr_rsrp=$(fibocom_get_rsrp "NR" ${nr_rsrp_num}) + nr_rsrp=$(get_rsrp "NR" ${nr_rsrp_num}) nr_rsrq_num=$(echo "$response" | awk -F',' '{print $14}' | sed 's/\r//g') - nr_rsrq=$(fibocom_get_rsrq "NR" ${nr_rsrq_num}) + nr_rsrq=$(get_rsrq "NR" ${nr_rsrq_num}) ;; "LTE-NR") network_mode="EN-DC Mode" @@ -1099,18 +1160,18 @@ fibocom_cell_info() endc_lte_earfcn=$(echo "$response" | awk -F',' '{print $7}') endc_lte_physical_cell_id=$(echo "$response" | awk -F',' '{print $8}') endc_lte_band_num=$(echo "$response" | awk -F',' '{print $9}') - endc_lte_band=$(fibocom_get_band "LTE" ${endc_lte_band_num}) + endc_lte_band=$(get_band "LTE" ${endc_lte_band_num}) ul_bandwidth_num=$(echo "$response" | awk -F',' '{print $10}') - endc_lte_ul_bandwidth=$(fibocom_get_bandwidth "LTE" ${ul_bandwidth_num}) + endc_lte_ul_bandwidth=$(get_bandwidth "LTE" ${ul_bandwidth_num}) endc_lte_dl_bandwidth="$endc_lte_ul_bandwidth" endc_lte_rssnr_num=$(echo "$response" | awk -F',' '{print $11}') - endc_lte_rssnr=$(fibocom_get_rssnr ${endc_lte_rssnr_num}) + endc_lte_rssnr=$(get_rssnr ${endc_lte_rssnr_num}) endc_lte_rxlev_num=$(echo "$response" | awk -F',' '{print $12}') - endc_lte_rxlev=$(fibocom_get_rxlev "LTE" ${endc_lte_rxlev_num}) + endc_lte_rxlev=$(get_rxlev "LTE" ${endc_lte_rxlev_num}) endc_lte_rsrp_num=$(echo "$response" | awk -F',' '{print $13}') - endc_lte_rsrp=$(fibocom_get_rsrp "LTE" ${endc_lte_rsrp_num}) + endc_lte_rsrp=$(get_rsrp "LTE" ${endc_lte_rsrp_num}) endc_lte_rsrq_num=$(echo "$response" | awk -F',' '{print $14}' | sed 's/\r//g') - endc_lte_rsrq=$(fibocom_get_rsrq "LTE" ${endc_lte_rsrq_num}) + endc_lte_rsrq=$(get_rsrq "LTE" ${endc_lte_rsrq_num}) #NR5G-NSA endc_nr_mcc=$(echo "$response" | awk -F',' '{print $3}') endc_nr_mnc=$(echo "$response" | awk -F',' '{print $4}') @@ -1119,17 +1180,17 @@ fibocom_cell_info() endc_nr_arfcn=$(echo "$response" | awk -F',' '{print $7}') endc_nr_physical_cell_id=$(echo "$response" | awk -F',' '{print $8}') endc_nr_band_num=$(echo "$response" | awk -F',' '{print $9}') - endc_nr_band=$(fibocom_get_band "NR" ${endc_nr_band_num}) + endc_nr_band=$(get_band "NR" ${endc_nr_band_num}) nr_dl_bandwidth_num=$(echo "$response" | awk -F',' '{print $10}') - endc_nr_dl_bandwidth=$(fibocom_get_bandwidth "NR" ${nr_dl_bandwidth_num}) + endc_nr_dl_bandwidth=$(get_bandwidth "NR" ${nr_dl_bandwidth_num}) endc_nr_sinr_num=$(echo "$response" | awk -F',' '{print $11}') - endc_nr_sinr=$(fibocom_get_sinr "NR" ${endc_nr_sinr_num}) + endc_nr_sinr=$(get_sinr "NR" ${endc_nr_sinr_num}) endc_nr_rxlev_num=$(echo "$response" | awk -F',' '{print $12}') - endc_nr_rxlev=$(fibocom_get_rxlev "NR" ${endc_nr_rxlev_num}) + endc_nr_rxlev=$(get_rxlev "NR" ${endc_nr_rxlev_num}) endc_nr_rsrp_num=$(echo "$response" | awk -F',' '{print $13}') - endc_nr_rsrp=$(fibocom_get_rsrp "NR" ${endc_nr_rsrp_num}) + endc_nr_rsrp=$(get_rsrp "NR" ${endc_nr_rsrp_num}) endc_nr_rsrq_num=$(echo "$response" | awk -F',' '{print $14}' | sed 's/\r//g') - endc_nr_rsrq=$(fibocom_get_rsrq "NR" ${endc_nr_rsrq_num}) + endc_nr_rsrq=$(get_rsrq "NR" ${endc_nr_rsrq_num}) ;; "LTE"|"eMTC"|"NB-IoT") network_mode="LTE Mode" @@ -1140,17 +1201,17 @@ fibocom_cell_info() lte_earfcn=$(echo "$response" | awk -F',' '{print $7}') lte_physical_cell_id=$(echo "$response" | awk -F',' '{print $8}') lte_band_num=$(echo "$response" | awk -F',' '{print $9}') - lte_band=$(fibocom_get_band "LTE" ${lte_band_num}) + lte_band=$(get_band "LTE" ${lte_band_num}) ul_bandwidth_num=$(echo "$response" | awk -F',' '{print $10}') - lte_ul_bandwidth=$(fibocom_get_bandwidth "LTE" ${ul_bandwidth_num}) + lte_ul_bandwidth=$(get_bandwidth "LTE" ${ul_bandwidth_num}) lte_dl_bandwidth="$lte_ul_bandwidth" lte_rssnr=$(echo "$response" | awk -F',' '{print $11}') lte_rxlev_num=$(echo "$response" | awk -F',' '{print $12}') - lte_rxlev=$(fibocom_get_rxlev "LTE" ${lte_rxlev_num}) + lte_rxlev=$(get_rxlev "LTE" ${lte_rxlev_num}) lte_rsrp_num=$(echo "$response" | awk -F',' '{print $13}') - lte_rsrp=$(fibocom_get_rsrp "LTE" ${lte_rsrp_num}) + lte_rsrp=$(get_rsrp "LTE" ${lte_rsrp_num}) lte_rsrq_num=$(echo "$response" | awk -F',' '{print $14}' | sed 's/\r//g') - lte_rsrq=$(fibocom_get_rsrq "LTE" ${lte_rsrq_num}) + lte_rsrq=$(get_rsrq "LTE" ${lte_rsrq_num}) ;; "WCDMA"|"UMTS") network_mode="WCDMA Mode" @@ -1161,15 +1222,15 @@ fibocom_cell_info() wcdma_uarfcn=$(echo "$response" | awk -F',' '{print $7}') wcdma_psc=$(echo "$response" | awk -F',' '{print $8}') wcdma_band_num=$(echo "$response" | awk -F',' '{print $9}') - wcdma_band=$(fibocom_get_band "WCDMA" ${wcdma_band_num}) + wcdma_band=$(get_band "WCDMA" ${wcdma_band_num}) wcdma_ecno=$(echo "$response" | awk -F',' '{print $10}') wcdma_rscp=$(echo "$response" | awk -F',' '{print $11}') wcdma_rac=$(echo "$response" | awk -F',' '{print $12}') wcdma_rxlev_num=$(echo "$response" | awk -F',' '{print $13}') - wcdma_rxlev=$(fibocom_get_rxlev "WCDMA" ${wcdma_rxlev_num}) + wcdma_rxlev=$(get_rxlev "WCDMA" ${wcdma_rxlev_num}) wcdma_reserved=$(echo "$response" | awk -F',' '{print $14}') wcdma_ecio_num=$(echo "$response" | awk -F',' '{print $15}' | sed 's/\r//g') - wcdma_ecio=$(fibocom_get_ecio ${wcdma_ecio_num}) + wcdma_ecio=$(get_ecio ${wcdma_ecio_num}) ;; esac @@ -1182,286 +1243,105 @@ fibocom_cell_info() #只选择第一个,然后退出 break } + done -} - - -# fibocom获取基站信息 -Fibocom_Cellinfo() -{ - #baseinfo.gcom - OX=$( sh ${SCRIPT_DIR}/modem_at.sh $at_port "ATI") - OX=$( sh ${SCRIPT_DIR}/modem_at.sh $at_port "AT+CGEQNEG=1") - - #cellinfo0.gcom - # OX1=$( sh ${SCRIPT_DIR}/modem_at.sh $at_port "AT+COPS=3,0;+COPS?") - # OX2=$( sh ${SCRIPT_DIR}/modem_at.sh $at_port "AT+COPS=3,2;+COPS?") - OX=$OX1" "$OX2 - - #cellinfo.gcom - OY1=$( sh ${SCRIPT_DIR}/modem_at.sh $at_port "AT+CREG=2;+CREG?;+CREG=0") - OY2=$( sh ${SCRIPT_DIR}/modem_at.sh $at_port "AT+CEREG=2;+CEREG?;+CEREG=0") - OY3=$( sh ${SCRIPT_DIR}/modem_at.sh $at_port "AT+C5GREG=2;+C5GREG?;+C5GREG=0") - OY=$OY1" "$OY2" "$OY3 - - - OXx=$OX - OX=$(echo $OX | tr 'a-z' 'A-Z') - OY=$(echo $OY | tr 'a-z' 'A-Z') - OX=$OX" "$OY - - #debug "$OX" - #debug "$OY" - - COPS="-" - COPS_MCC="-" - COPS_MNC="-" - COPSX=$(echo $OXx | grep -o "+COPS: [01],0,.\+," | cut -d, -f3 | grep -o "[^\"]\+") - - if [ "x$COPSX" != "x" ]; then - COPS=$COPSX - fi - - COPSX=$(echo $OX | grep -o "+COPS: [01],2,.\+," | cut -d, -f3 | grep -o "[^\"]\+") - - if [ "x$COPSX" != "x" ]; then - COPS_MCC=${COPSX:0:3} - COPS_MNC=${COPSX:3:3} - if [ "$COPS" = "-" ]; then - COPS=$(awk -F[\;] '/'$COPS'/ {print $2}' $ROOTER/signal/mccmnc.data) - [ "x$COPS" = "x" ] && COPS="-" - fi - fi - - if [ "$COPS" = "-" ]; then - COPS=$(echo "$O" | awk -F[\"] '/^\+COPS: 0,0/ {print $2}') - if [ "x$COPS" = "x" ]; then - COPS="-" - COPS_MCC="-" - COPS_MNC="-" - fi - fi - COPS_MNC=" "$COPS_MNC - - OX=$(echo "${OX//[ \"]/}") - CID="" - CID5="" - RAT="" - REGV=$(echo "$OX" | grep -o "+C5GREG:2,[0-9],[A-F0-9]\{2,6\},[A-F0-9]\{5,10\},[0-9]\{1,2\}") - if [ -n "$REGV" ]; then - LAC5=$(echo "$REGV" | cut -d, -f3) - LAC5=$LAC5" ($(printf "%d" 0x$LAC5))" - CID5=$(echo "$REGV" | cut -d, -f4) - CID5L=$(printf "%010X" 0x$CID5) - RNC5=${CID5L:1:6} - RNC5=$RNC5" ($(printf "%d" 0x$RNC5))" - CID5=${CID5L:7:3} - CID5="Short $(printf "%X" 0x$CID5) ($(printf "%d" 0x$CID5)), Long $(printf "%X" 0x$CID5L) ($(printf "%d" 0x$CID5L))" - RAT=$(echo "$REGV" | cut -d, -f5) - fi - REGV=$(echo "$OX" | grep -o "+CEREG:2,[0-9],[A-F0-9]\{2,4\},[A-F0-9]\{5,8\}") - REGFMT="3GPP" - if [ -z "$REGV" ]; then - REGV=$(echo "$OX" | grep -o "+CEREG:2,[0-9],[A-F0-9]\{2,4\},[A-F0-9]\{1,3\},[A-F0-9]\{5,8\}") - REGFMT="SW" - fi - if [ -n "$REGV" ]; then - LAC=$(echo "$REGV" | cut -d, -f3) - LAC=$(printf "%04X" 0x$LAC)" ($(printf "%d" 0x$LAC))" - if [ $REGFMT = "3GPP" ]; then - CID=$(echo "$REGV" | cut -d, -f4) - else - CID=$(echo "$REGV" | cut -d, -f5) - fi - CIDL=$(printf "%08X" 0x$CID) - RNC=${CIDL:1:5} - RNC=$RNC" ($(printf "%d" 0x$RNC))" - CID=${CIDL:6:2} - CID="Short $(printf "%X" 0x$CID) ($(printf "%d" 0x$CID)), Long $(printf "%X" 0x$CIDL) ($(printf "%d" 0x$CIDL))" - - else - REGV=$(echo "$OX" | grep -o "+CREG:2,[0-9],[A-F0-9]\{2,4\},[A-F0-9]\{2,8\}") - if [ -n "$REGV" ]; then - LAC=$(echo "$REGV" | cut -d, -f3) - CID=$(echo "$REGV" | cut -d, -f4) - if [ ${#CID} -gt 4 ]; then - LAC=$(printf "%04X" 0x$LAC)" ($(printf "%d" 0x$LAC))" - CIDL=$(printf "%08X" 0x$CID) - RNC=${CIDL:1:3} - CID=${CIDL:4:4} - CID="Short $(printf "%X" 0x$CID) ($(printf "%d" 0x$CID)), Long $(printf "%X" 0x$CIDL) ($(printf "%d" 0x$CIDL))" - else - LAC="" - fi - else - LAC="" - fi - fi - REGSTAT=$(echo "$REGV" | cut -d, -f2) - if [ "$REGSTAT" == "5" -a "$COPS" != "-" ]; then - COPS_MNC=$COPS_MNC" (Roaming)" - fi - if [ -n "$CID" -a -n "$CID5" ] && [ "$RAT" == "13" -o "$RAT" == "10" ]; then - LAC="4G $LAC, 5G $LAC5" - CID="4G $CID
5G $CID5" - RNC="4G $RNC, 5G $RNC5" - elif [ -n "$CID5" ]; then - LAC=$LAC5 - CID=$CID5 - RNC=$RNC5 - fi - if [ -z "$LAC" ]; then - LAC="-" - CID="-" - RNC="-" - fi -} - -#获取广和通模组信息 -# $1:AT串口 -# $2:平台 -# $3:连接定义 -get_fibocom_info() -{ - debug "get fibocom info" - #设置AT串口 - at_port="$1" - platform="$2" - define_connect="$3" - - #基本信息 - fibocom_base_info - - #SIM卡信息 - fibocom_sim_info - if [ "$sim_status" != "ready" ]; then - return - fi - - #网络信息 - fibocom_network_info - if [ "$connect_status" != "connect" ]; then - return - fi - - #小区信息 - fibocom_cell_info - - return - - # Fibocom_Cellinfo - - #基站信息 - OX=$( sh ${SCRIPT_DIR}/modem_at.sh $at_port "AT+CPSI?") - rec=$(echo "$OX" | grep "+CPSI:") - w=$(echo $rec |grep "NO SERVICE"| wc -l) - if [ $w -ge 1 ];then - debug "NO SERVICE" - return - fi - w=$(echo $rec |grep "NR5G_"| wc -l) - if [ $w -ge 1 ];then - - w=$(echo $rec |grep "32768"| wc -l) - if [ $w -ge 1 ];then - debug "-32768" - return - fi - - debug "$rec" - rec1=${rec##*+CPSI:} - #echo "$rec1" - MODE="${rec1%%,*}" # MODE="NR5G" - rect1=${rec1#*,} - rect1s="${rect1%%,*}" #Online - rect2=${rect1#*,} - rect2s="${rect2%%,*}" #460-11 - rect3=${rect2#*,} - rect3s="${rect3%%,*}" #0xCFA102 - rect4=${rect3#*,} - rect4s="${rect4%%,*}" #55744245764 - rect5=${rect4#*,} - rect5s="${rect5%%,*}" #196 - rect6=${rect5#*,} - rect6s="${rect6%%,*}" #NR5G_BAND78 - rect7=${rect6#*,} - rect7s="${rect7%%,*}" #627264 - rect8=${rect7#*,} - rect8s="${rect8%%,*}" #-940 - rect9=${rect8#*,} - rect9s="${rect9%%,*}" #-110 - # "${rec1##*,}" #最后一位 - rect10=${rect9#*,} - rect10s="${rect10%%,*}" #最后一位 - PCI=$rect5s - LBAND="n"$(echo $rect6s | cut -d, -f0 | grep -o "BAND[0-9]\{1,3\}" | grep -o "[0-9]\+") - CHANNEL=$rect7s - RSCP=$(($(echo $rect8s | cut -d, -f0) / 10)) - ECIO=$(($(echo $rect9s | cut -d, -f0) / 10)) - if [ "$CSQ_PER" = "-" ]; then - CSQ_PER=$((100 - (($RSCP + 31) * 100/-125)))"%" - fi - SINR=$(($(echo $rect10s | cut -d, -f0) / 10))" dB" - fi - w=$(echo $rec |grep "LTE"|grep "EUTRAN"| wc -l) - if [ $w -ge 1 ];then - rec1=${rec#*EUTRAN-} - lte_band=${rec1%%,*} #EUTRAN-BAND - rec1=${rec1#*,} - rec1=${rec1#*,} - rec1=${rec1#*,} - rec1=${rec1#*,} - #rec1=${rec1#*,} - rec1=${rec1#*,} - lte_rssi=${rec1%%,*} #LTE_RSSI - lte_rssi=`expr $lte_rssi / 10` #LTE_RSSI - debug "LTE_BAND=$lte_band LTE_RSSI=$lte_rssi" - if [ $rssi == 0 ];then - rssi=$lte_rssi - fi - fi - w=$(echo $rec |grep "WCDMA"| wc -l) - if [ $w -ge 1 ];then - w=$(echo $rec |grep "UNKNOWN"|wc -l) - if [ $w -ge 1 ];then - debug "UNKNOWN BAND" - return - fi - fi - - #CNMP - OX=$( sh ${SCRIPT_DIR}/modem_at.sh $at_port "AT+CNMP?") - CNMP=$(echo "$OX" | grep -o "+CNMP:[ ]*[0-9]\{1,3\}" | grep -o "[0-9]\{1,3\}") - if [ -n "$CNMP" ]; then - case $CNMP in - "2"|"55" ) - NETMODE="1" ;; - "13" ) - NETMODE="3" ;; - "14" ) - NETMODE="5" ;; - "38" ) - NETMODE="7" ;; - "71" ) - NETMODE="9" ;; - "109" ) - NETMODE="8" ;; - * ) - NETMODE="0" ;; - esac - fi - - # CMGRMI 信息 - OX=$( sh ${SCRIPT_DIR}/modem_at.sh $at_port "AT+CMGRMI=4") - CAINFO=$(echo "$OX" | grep -o "$REGXz" | tr ' ' ':') - if [ -n "$CAINFO" ]; then - for CASV in $(echo "$CAINFO"); do - LBAND=$LBAND"
B"$(echo "$CASV" | cut -d, -f4) - BW=$(echo "$CASV" | cut -d, -f5) - decode_bw - LBAND=$LBAND" (CA, Bandwidth $BW MHz)" - CHANNEL="$CHANNEL, "$(echo "$CASV" | cut -d, -f2) - PCI="$PCI, "$(echo "$CASV" | cut -d, -f7) - done - fi + class="Cell Information" + add_plain_info_entry "network_mode" "$network_mode" "Network Mode" + case $network_mode in + "NR5G-SA Mode") + add_plain_info_entry "MMC" "$nr_mcc" "Mobile Country Code" + add_plain_info_entry "MNC" "$nr_mnc" "Mobile Network Code" + add_plain_info_entry "Duplex Mode" "$nr_duplex_mode" "Duplex Mode" + add_plain_info_entry "Cell ID" "$nr_cell_id" "Cell ID" + add_plain_info_entry "Physical Cell ID" "$nr_physical_cell_id" "Physical Cell ID" + add_plain_info_entry "TAC" "$nr_tac" "Tracking area code of cell servedby neighbor Enb" + add_plain_info_entry "ARFCN" "$nr_arfcn" "Absolute Radio-Frequency Channel Number" + add_plain_info_entry "Band" "$nr_band" "Band" + add_plain_info_entry "DL Bandwidth" "$nr_dl_bandwidth" "DL Bandwidth" + add_bar_info_entry "RSRP" "$nr_rsrp" "Reference Signal Received Power" -187 -29 Dbm + add_bar_info_entry "RSRQ" "$nr_rsrq" "Reference Signal Received Quality" -43 20 Dbm + add_bar_info_entry "SINR" "$nr_sinr" "Signal to Interference plus Noise Ratio Bandwidth" -23 40 DB + add_bar_info_entry "RxLev" "$nr_rxlev" "Received Signal Level" -140 -20 Dbm + add_plain_info_entry "SCS" "$nr_scs" "SCS" + add_plain_info_entry "Srxlev" "$nr_srxlev" "Serving Cell Receive Level" + ;; + "EN-DC Mode") + add_plain_info_entry "LTE" "LTE" "" + add_plain_info_entry "MCC" "$endc_lte_mcc" "Mobile Country Code" + add_plain_info_entry "MNC" "$endc_lte_mnc" "Mobile Network Code" + add_plain_info_entry "Duplex Mode" "$endc_lte_duplex_mode" "Duplex Mode" + add_plain_info_entry "Cell ID" "$endc_lte_cell_id" "Cell ID" + add_plain_info_entry "Physical Cell ID" "$endc_lte_physical_cell_id" "Physical Cell ID" + add_plain_info_entry "EARFCN" "$endc_lte_earfcn" "E-UTRA Absolute Radio Frequency Channel Number" + add_plain_info_entry "Freq band indicator" "$endc_lte_freq_band_ind" "Freq band indicator" + add_plain_info_entry "Band" "$endc_lte_band" "Band" + add_plain_info_entry "UL Bandwidth" "$endc_lte_ul_bandwidth" "UL Bandwidth" + add_plain_info_entry "DL Bandwidth" "$endc_lte_dl_bandwidth" "DL Bandwidth" + add_plain_info_entry "TAC" "$endc_lte_tac" "Tracking area code of cell servedby neighbor Enb" + add_bar_info_entry "RSRP" "$endc_lte_rsrp" "Reference Signal Received Power" -140 -44 Dbm + add_bar_info_entry "RSRQ" "$endc_lte_rsrq" "Reference Signal Received Quality" -20 20 Dbm + add_bar_info_entry "RSSI" "$endc_lte_rssi" "Received Signal Strength Indicator" -140 -44 Dbm + add_bar_info_entry "SINR" "$endc_lte_sinr" "Signal to Interference plus Noise Ratio Bandwidth" -23 40 DB + add_plain_info_entry "RxLev" "$endc_lte_rxlev" "Received Signal Level" + add_plain_info_entry "RSSNR" "$endc_lte_rssnr" "Radio Signal Strength Noise Ratio" + add_plain_info_entry "CQI" "$endc_lte_cql" "Channel Quality Indicator" + add_plain_info_entry "TX Power" "$endc_lte_tx_power" "TX Power" + add_plain_info_entry "Srxlev" "$endc_lte_srxlev" "Serving Cell Receive Level" + add_plain_info_entry NR5G-NSA "NR5G-NSA" "" + add_plain_info_entry "MCC" "$endc_nr_mcc" "Mobile Country Code" + add_plain_info_entry "MNC" "$endc_nr_mnc" "Mobile Network Code" + add_plain_info_entry "Physical Cell ID" "$endc_nr_physical_cell_id" "Physical Cell ID" + add_plain_info_entry "ARFCN" "$endc_nr_arfcn" "Absolute Radio-Frequency Channel Number" + add_plain_info_entry "Band" "$endc_nr_band" "Band" + add_plain_info_entry "DL Bandwidth" "$endc_nr_dl_bandwidth" "DL Bandwidth" + add_bar_info_entry "RSRP" "$endc_nr_rsrp" "Reference Signal Received Power" -187 -29 Dbm + add_bar_info_entry "RSRQ" "$endc_nr_rsrq" "Reference Signal Received Quality" -43 20 Dbm + add_bar_info_entry "SINR" "$endc_nr_sinr" "Signal to Interference plus Noise Ratio Bandwidth" -23 40 DB + add_plain_info_entry "SCS" "$endc_nr_scs" "SCS" + + ;; + "LTE Mode") + add_plain_info_entry "MCC" "$lte_mcc" "Mobile Country Code" + add_plain_info_entry "MNC" "$lte_mnc" "Mobile Network Code" + add_plain_info_entry "Duplex Mode" "$lte_duplex_mode" "Duplex Mode" + add_plain_info_entry "Cell ID" "$lte_cell_id" "Cell ID" + add_plain_info_entry "Physical Cell ID" "$lte_physical_cell_id" "Physical Cell ID" + add_plain_info_entry "EARFCN" "$lte_earfcn" "E-UTRA Absolute Radio Frequency Channel Number" + add_plain_info_entry "Freq band indicator" "$lte_freq_band_ind" "Freq band indicator" + add_plain_info_entry "Band" "$lte_band" "Band" + add_plain_info_entry "UL Bandwidth" "$lte_ul_bandwidth" "UL Bandwidth" + add_plain_info_entry "DL Bandwidth" "$lte_dl_bandwidth" "DL Bandwidth" + add_plain_info_entry "TAC" "$lte_tac" "Tracking area code of cell servedby neighbor Enb" + add_bar_info_entry "RSRP" "$lte_rsrp" "Reference Signal Received Power" -140 -44 Dbm + add_bar_info_entry "RSRQ" "$lte_rsrq" "Reference Signal Received Quality" -20 20 Dbm + add_bar_info_entry "RSSI" "$lte_rssi" "Received Signal Strength Indicator" -140 -44 Dbm + add_bar_info_entry "SINR" "$lte_sinr" "Signal to Interference plus Noise Ratio Bandwidth" -23 40 DB + add_plain_info_entry "RxLev" "$lte_rxlev" "Received Signal Level" + add_plain_info_entry "RSSNR" "$lte_rssnr" "Radio Signal Strength Noise Ratio" + add_plain_info_entry "CQI" "$lte_cql" "Channel Quality Indicator" + add_plain_info_entry "TX Power" "$lte_tx_power" "TX Power" + add_plain_info_entry "Srxlev" "$lte_srxlev" "Serving Cell Receive Level" + + ;; + "WCDMA Mode") + add_plain_info_entry "MCC" "$wcdma_mcc" "Mobile Country Code" + add_plain_info_entry "MNC" "$wcdma_mnc" "Mobile Network Code" + add_plain_info_entry "LAC" "$wcdma_lac" "Location Area Code" + add_plain_info_entry "Cell ID" "$wcdma_cell_id" "Cell ID" + add_plain_info_entry "UARFCN" "$wcdma_uarfcn" "UTRA Absolute Radio Frequency Channel Number" + add_plain_info_entry "PSC" "$wcdma_psc" "Primary Scrambling Code" + add_plain_info_entry "RAC" "$wcdma_rac" "Routing Area Code" + add_plain_info_entry "Band" "$wcdma_band" "Band" + add_bar_info_entry "RSCP" "$wcdma_rscp" "Received Signal Code Power" -120 -25 Dbm + add_plain_info_entry "Ec/Io" "$wcdma_ecio" "Ec/Io" + add_plain_info_entry "Ec/No" "$wcdma_ecno" "Ec/No" + add_plain_info_entry "Physical Channel" "$wcdma_phych" "Physical Channel" + add_plain_info_entry "Spreading Factor" "$wcdma_sf" "Spreading Factor" + add_plain_info_entry "Slot" "$wcdma_slot" "Slot" + add_plain_info_entry "Speech Code" "$wcdma_speech_code" "Speech Code" + add_plain_info_entry "Compression Mode" "$wcdma_com_mod" "Compression Mode" + add_plain_info_entry "RxLev" "$wcdma_rxlev" "RxLev" + + ;; + esac } diff --git a/luci-app-modem/root/usr/share/modem/generic.sh b/luci-app-modem/root/usr/share/modem/generic.sh new file mode 100755 index 0000000..8f2849c --- /dev/null +++ b/luci-app-modem/root/usr/share/modem/generic.sh @@ -0,0 +1,288 @@ +#!/bin/sh +SCRIPT_DIR="/usr/share/modem" +source /usr/share/libubox/jshn.sh +source "${SCRIPT_DIR}/modem_util.sh" +add_plain_info_entry() +{ + key=$1 + value=$2 + key_full_name=$3 + class_overwrite=$4 + if [ -n "$class_overwrite" ]; then + class="$class_overwrite" + fi + json_add_object "" + json_add_string key "$key" + json_add_string value "$value" + json_add_string "full_name" "$key_full_name" + json_add_string "type" "plain_text" + if [ -n "$class" ]; then + json_add_string "class" "$class" + fi + json_close_object +} + +add_warning_message_entry() +{ + key=$1 + value=$2 + key_full_name=$3 + class_overwrite=$4 + if [ -n "$class_overwrite" ]; then + class="$class_overwrite" + fi + json_add_object "" + json_add_string key "$key" + json_add_string value "$value" + json_add_string "full_name" "$key_full_name" + json_add_string "type" "warnning_message" + if [ -n "$class" ]; then + json_add_string "class" "$class" + fi + json_close_object +} + +add_bar_info_entry() +{ + key=$1 + value=$2 + key_full_name=$3 + min_value=$4 + max_value=$5 + unit=$6 + class_overwrite=$7 + if [ -n "$class_overwrite" ]; then + class="$class_overwrite" + fi + json_add_object "" + json_add_string key "$key" + json_add_string value "$value" + json_add_string min_value "$min_value" + json_add_string max_value "$max_value" + json_add_string "full_name" "$key_full_name" + json_add_string "unit" "$unit" + json_add_string "type" "progress_bar" + if [ -n "$class" ]; then + json_add_string "class" "$class" + fi + json_close_object +} + +add_avalible_band_entry() +{ + band_id=$1 + band_name=$2 + json_add_object "" + json_add_string band_id "$band_id" + json_add_string band_name "$band_name" + json_add_string "type" "avalible_band" + json_close_object +} + + +get_dns() +{ + [ -z "$define_connect" ] && { + define_connect="1" + } + + local public_dns1_ipv4="223.5.5.5" + local public_dns2_ipv4="119.29.29.29" + local public_dns1_ipv6="2400:3200::1" #下一代互联网北京研究中心:240C::6666,阿里:2400:3200::1,腾讯:2402:4e00:: + local public_dns2_ipv6="2402:4e00::" + + #获取DNS地址 + at_command="AT+GTDNS=${define_connect}" + local response=$(at ${at_port} ${at_command} | grep "+GTDNS: ") + + local ipv4_dns1=$(echo "${response}" | awk -F'"' '{print $2}' | awk -F',' '{print $1}') + [ -z "$ipv4_dns1" ] && { + ipv4_dns1="${public_dns1_ipv4}" + } + + local ipv4_dns2=$(echo "${response}" | awk -F'"' '{print $4}' | awk -F',' '{print $1}') + [ -z "$ipv4_dns2" ] && { + ipv4_dns2="${public_dns2_ipv4}" + } + + local ipv6_dns1=$(echo "${response}" | awk -F'"' '{print $2}' | awk -F',' '{print $2}') + [ -z "$ipv6_dns1" ] && { + ipv6_dns1="${public_dns1_ipv6}" + } + + local ipv6_dns2=$(echo "${response}" | awk -F'"' '{print $4}' | awk -F',' '{print $2}') + [ -z "$ipv6_dns2" ] && { + ipv6_dns2="${public_dns2_ipv6}" + } + json_add_object "dns" + json_add_string "ipv4_dns1" "$ipv4_dns1" + json_add_string "ipv4_dns2" "$ipv4_dns2" + json_add_string "ipv6_dns1" "$ipv6_dns1" + json_add_string "ipv6_dns2" "$ipv6_dns2" + json_close_object +} + +get_sim_status() +{ + local sim_status + case $1 in + "") + sim_status="miss" + sim_state_code=0 + ;; + *"ERROR"*) + sim_status="miss" + sim_state_code=0 + ;; + *"READY"*) + sim_status="ready" + sim_state_code=1 + ;; + *"SIM PIN"*) + sim_status="MT is waiting SIM PIN to be given" + sim_state_code=2 + ;; + *"SIM PUK"*) + sim_status="MT is waiting SIM PUK to be given" + sim_state_code=3 + ;; + *"PH-FSIM PIN"*) + sim_status="MT is waiting phone-to-SIM card password to be given" + sim_state_code=4 + ;; + *"PH-FSIM PIN"*) + sim_status="MT is waiting phone-to-very first SIM card password to be given" + sim_state_code=5 + ;; + *"PH-FSIM PUK"*) + sim_status="MT is waiting phone-to-very first SIM card unblocking password to be given" + sim_state_code=6 + ;; + *"SIM PIN2"*) + sim_status="MT is waiting SIM PIN2 to be given" + sim_state_code=7 + ;; + *"SIM PUK2"*) + sim_status="MT is waiting SIM PUK2 to be given" + sim_state_code=8 + ;; + *"PH-NET PIN"*) + sim_status="MT is waiting network personalization password to be given" + sim_state_code=9 + ;; + *"PH-NET PUK"*) + sim_status="MT is waiting network personalization unblocking password to be given" + sim_state_code=10 + ;; + *"PH-NETSUB PIN"*) + sim_status="MT is waiting network subset personalization password to be given" + sim_state_code=11 + ;; + *"PH-NETSUB PUK"*) + sim_status="MT is waiting network subset personalization unblocking password to be given" + sim_state_code=12 + ;; + *"PH-SP PIN"*) + sim_status="MT is waiting service provider personalization password to be given" + sim_state_code=13 + ;; + *"PH-SP PUK"*) + sim_status="MT is waiting service provider personalization unblocking password to be given" + sim_state_code=14 + ;; + *"PH-CORP PIN"*) + sim_status="MT is waiting corporate personalization password to be given" + sim_state_code=16 + ;; + + *"PH-CORP PUK"*) + sim_status="MT is waiting corporate personalization unblocking password to be given" + sim_state_code=17 + ;; + *) + sim_status="unknown" + sim_state_code=99 + ;; + esac + echo "$sim_status" +} + +#获取信号强度指示 +# $1:信号强度指示数字 +get_rssi() +{ + local rssi + case $1 in + "99") rssi="unknown" ;; + * ) rssi=$((2 * $1 - 113)) ;; + esac + echo "$rssi" +} + +#获取网络类型 +# $1:网络类型数字 +get_rat() +{ + local rat + case $1 in + "0"|"1"|"3"|"8") rat="GSM" ;; + "2"|"4"|"5"|"6"|"9"|"10") rat="WCDMA" ;; + "7") rat="LTE" ;; + "11"|"12") rat="NR" ;; + esac + echo "${rat}" +} + +#获取连接状态 +#return raw data +get_connect_status() +{ + at_cmd="AT+CGPADDR=1" + [ "$define_connect" == "3" ] && at_cmd="AT+CGPADDR=3" + expect="+CGPADDR:" + result=$(at $at_port $at_cmd | grep $expect) + if [ -n "$result" ];then + ipv6=$(echo $result | grep -oE "\b([0-9a-fA-F]{0,4}:){2,7}[0-9a-fA-F]{0,4}\b") + ipv4=$(echo $result | grep -oE "\b([0-9]{1,3}\.){3}[0-9]{1,3}\b") + disallow_ipv4="0.0.0.0" + #remove the disallow ip + if [ "$ipv4" == "$disallow_ipv4" ];then + ipv4="" + fi + fi + if [ -n "$ipv4" ] || [ -n "$ipv6" ];then + connect_status="Yes" + else + connect_status="No" + fi + add_plain_info_entry "connect_status" "$connect_status" "Connect Status" +} + +#获取移远模组信息 +# $1:AT串口 +# $2:平台 +# $3:连接定义 +get_info() +{ + #基本信息 + base_info + + #SIM卡信息 + sim_info + if [ "$sim_status" != "ready" ]; then + add_warning_message_entry "sim_status" "$sim_status" "SIM Error,Error code:" "warning" + return + fi + + #网络信息 + network_info + if [ "$connect_status" != "Yes" ]; then + return + fi + + #小区信息 + cell_info + + return + +} diff --git a/luci-app-modem/root/usr/share/modem/meig.sh b/luci-app-modem/root/usr/share/modem/meig.sh deleted file mode 100755 index ed9b5c4..0000000 --- a/luci-app-modem/root/usr/share/modem/meig.sh +++ /dev/null @@ -1,835 +0,0 @@ -#!/bin/sh -# Copyright (C) 2023 Siriling - -#脚本目录 -SCRIPT_DIR="/usr/share/modem" - -#预设 -meig_presets() -{ - #关闭自动上报系统模式变化 - at_command='AT^MODE=0' - sh "${SCRIPT_DIR}/modem_at.sh" "$at_port" "$at_command" - - #关闭自动上报DS流量 - at_command='AT^DSFLOWRPT=0,0,1' - sh "${SCRIPT_DIR}/modem_at.sh" "$at_port" "$at_command" -} - -#获取DNS -# $1:AT串口 -# $2:连接定义 -meig_get_dns() -{ - local at_port="$1" - local define_connect="$2" - - [ -z "$define_connect" ] && { - define_connect="1" - } - - local public_dns1_ipv4="223.5.5.5" - local public_dns2_ipv4="119.29.29.29" - local public_dns1_ipv6="2400:3200::1" #下一代互联网北京研究中心:240C::6666,阿里:2400:3200::1,腾讯:2402:4e00:: - local public_dns2_ipv6="2402:4e00::" - - #获取DNS地址 - at_command="AT+CGCONTRDP=${define_connect}" - local response=$(at ${at_port} ${at_command} | grep "+CGCONTRDP: " | grep -E '[0-9]+.[0-9]+.[0-9]+.[0-9]+' | sed -n '1p') - - local ipv4_dns1=$(echo "${response}" | awk -F',' '{print $7}' | awk -F' ' '{print $1}') - [ -z "$ipv4_dns1" ] && { - ipv4_dns1="${public_dns1_ipv4}" - } - - local ipv4_dns2=$(echo "${response}" | awk -F',' '{print $8}' | awk -F' ' '{print $1}') - [ -z "$ipv4_dns2" ] && { - ipv4_dns2="${public_dns2_ipv4}" - } - - local ipv6_dns1=$(echo "${response}" | awk -F',' '{print $7}' | awk -F' ' '{print $2}') - [ -z "$ipv6_dns1" ] && { - ipv6_dns1="${public_dns1_ipv6}" - } - - local ipv6_dns2=$(echo "${response}" | awk -F',' '{print $8}' | awk -F' ' '{print $2}' | sed 's/\r//g') - [ -z "$ipv6_dns2" ] && { - ipv6_dns2="${public_dns2_ipv6}" - } - - dns="{ - \"dns\":{ - \"ipv4_dns1\":\"$ipv4_dns1\", - \"ipv4_dns2\":\"$ipv4_dns2\", - \"ipv6_dns1\":\"$ipv6_dns1\", - \"ipv6_dns2\":\"$ipv6_dns2\" - } - }" - - echo "$dns" -} - -#获取拨号模式 -# $1:AT串口 -# $2:平台 -meig_get_mode() -{ - local at_port="$1" - local platform="$2" - - at_command="AT+SER?" - local mode_num=$(sh ${SCRIPT_DIR}/modem_at.sh ${at_port} ${at_command} | grep "+SER:" | sed 's/+SER: //g' | sed 's/\r//g') - - if [ -z "$mode_num" ]; then - echo "unknown" - return - fi - - #获取芯片平台 - if [ -z "$platform" ]; then - local modem_number=$(uci -q get modem.@global[0].modem_number) - for i in $(seq 0 $((modem_number-1))); do - local at_port_tmp=$(uci -q get modem.modem$i.at_port) - if [ "$at_port" = "$at_port_tmp" ]; then - platform=$(uci -q get modem.modem$i.platform) - break - fi - done - fi - - local mode - case "$platform" in - "qualcomm") - case "$mode_num" in - "1") mode="qmi" ;; #- - # "1") mode="gobinet" ;; - "2") mode="ecm" ;; - "7") mode="mbim" ;; - "3") mode="rndis" ;; - "2") mode="ncm" ;; - *) mode="$mode_num" ;; - esac - ;; - *) - mode="$mode_num" - ;; - esac - echo "${mode}" -} - -#设置拨号模式 -# $1:AT串口 -# $2:拨号模式配置 -meig_set_mode() -{ - local at_port="$1" - local mode_config="$2" - - #获取芯片平台 - local platform - local modem_number=$(uci -q get modem.@global[0].modem_number) - for i in $(seq 0 $((modem_number-1))); do - local at_port_tmp=$(uci -q get modem.modem$i.at_port) - if [ "$at_port" = "$at_port_tmp" ]; then - platform=$(uci -q get modem.modem$i.platform) - break - fi - done - - #获取拨号模式配置 - local mode_num - case "$platform" in - "qualcomm") - case "$mode_config" in - "qmi") mode_num="1" ;; - # "gobinet") mode_num="1" ;; - "ecm") mode_num="2" ;; - "mbim") mode_num="7" ;; - "rndis") mode_num="3" ;; - "ncm") mode_num="2" ;; - *) mode_num="1" ;; - esac - ;; - *) - mode_num="1" - ;; - esac - - #设置模组 - at_command="AT+SER=${mode_num},1" - sh ${SCRIPT_DIR}/modem_at.sh ${at_port} "${at_command}" -} - -#获取网络偏好 -# $1:AT串口 -meig_get_network_prefer() -{ - local at_port="$1" - at_command="AT^SYSCFGEX?" - local response=$(sh ${SCRIPT_DIR}/modem_at.sh ${at_port} ${at_command} | grep "\^SYSCFGEX:" | awk -F'"' '{print $2}') - - local network_prefer_3g="0"; - local network_prefer_4g="0"; - local network_prefer_5g="0"; - - #匹配不同的网络类型 - local auto=$(echo "${response}" | grep "00") - if [ -n "$auto" ]; then - network_prefer_3g="1" - network_prefer_4g="1" - network_prefer_5g="1" - else - local wcdma=$(echo "${response}" | grep "02") - local lte=$(echo "${response}" | grep "03") - local nr=$(echo "${response}" | grep "04") - if [ -n "$wcdma" ]; then - network_prefer_3g="1" - fi - if [ -n "$lte" ]; then - network_prefer_4g="1" - fi - if [ -n "$nr" ]; then - network_prefer_5g="1" - fi - fi - - local network_prefer="{ - \"network_prefer\":{ - \"3G\":$network_prefer_3g, - \"4G\":$network_prefer_4g, - \"5G\":$network_prefer_5g - } - }" - echo "$network_prefer" -} - -#设置网络偏好 -# $1:AT串口 -# $2:网络偏好配置 -meig_set_network_prefer() -{ - local at_port="$1" - local network_prefer="$2" - - #获取网络偏好配置 - local network_prefer_config - - #获取选中的数量 - local count=$(echo "$network_prefer" | grep -o "1" | wc -l) - #获取每个偏好的值 - local network_prefer_3g=$(echo "$network_prefer" | jq -r '.["3G"]') - local network_prefer_4g=$(echo "$network_prefer" | jq -r '.["4G"]') - local network_prefer_5g=$(echo "$network_prefer" | jq -r '.["5G"]') - - case "$count" in - "1") - if [ "$network_prefer_3g" = "1" ]; then - network_prefer_config="02" - elif [ "$network_prefer_4g" = "1" ]; then - network_prefer_config="03" - elif [ "$network_prefer_5g" = "1" ]; then - network_prefer_config="04" - fi - ;; - "2") - if [ "$network_prefer_3g" = "1" ] && [ "$network_prefer_4g" = "1" ]; then - network_prefer_config="0302" - elif [ "$network_prefer_3g" = "1" ] && [ "$network_prefer_5g" = "1" ]; then - network_prefer_config="0402" - elif [ "$network_prefer_4g" = "1" ] && [ "$network_prefer_5g" = "1" ]; then - network_prefer_config="0403" - fi - ;; - "3") network_prefer_config="00" ;; - *) network_prefer_config="00" ;; - esac - - #设置模组 - at_command='AT^SYSCFGEX="'${network_prefer_config}'",all,0,2,all,all,all,all,1' - sh ${SCRIPT_DIR}/modem_at.sh "${at_port}" "${at_command}" -} - -#获取电压 -# $1:AT串口 -meig_get_voltage() -{ - local at_port="$1" - - # #Voltage(电压) - # at_command="AT+ADCREAD=0" - # local voltage=$(sh ${SCRIPT_DIR}/modem_at.sh $at_port $at_command | grep "+ADCREAD:" | awk -F' ' '{print $2}' | sed 's/\r//g') - # voltage=$(awk "BEGIN{ printf \"%.2f\", $voltage / 1000000 }" | sed 's/\.*0*$//') - # echo "${voltage}" -} - -#获取温度 -# $1:AT串口 -meig_get_temperature() -{ - local at_port="$1" - - #Temperature(温度) - at_command="AT+TEMP" - response=$(sh ${SCRIPT_DIR}/modem_at.sh $at_port $at_command | grep 'TEMP: "cpu0-0-usr"' | awk -F'"' '{print $4}') - - local temperature - if [ -n "$response" ]; then - temperature="${response}$(printf "\xc2\xb0")C" - fi - - echo "${temperature}" -} - -#获取连接状态 -# $1:AT串口 -# $2:连接定义 -meig_get_connect_status() -{ - local at_port="$1" - local define_connect="$2" - - #默认值为1 - [ -z "$define_connect" ] && { - define_connect="1" - } - - at_command="AT+CGPADDR=${define_connect}" - local ipv4=$(sh ${SCRIPT_DIR}/modem_at.sh ${at_port} ${at_command} | grep "+CGPADDR: " | awk -F',' '{print $2}') - local not_ip="0.0.0.0" - - #设置连接状态 - local connect_status - if [ -z "$ipv4" ] || [[ "$ipv4" = *"$not_ip"* ]]; then - connect_status="disconnect" - else - connect_status="connect" - fi - - echo "${connect_status}" -} - -#基本信息 -meig_base_info() -{ - debug "meig base info" - - #Name(名称) - at_command="AT+CGMM" - name=$(sh ${SCRIPT_DIR}/modem_at.sh $at_port $at_command | grep "+CGMM: " | awk -F': ' '{print $2}' | sed 's/\r//g') - #Manufacturer(制造商) - at_command="AT+CGMI" - manufacturer=$(sh ${SCRIPT_DIR}/modem_at.sh $at_port $at_command | grep "+CGMI: " | awk -F': ' '{print $2}' | sed 's/\r//g') - #Revision(固件版本) - at_command="AT+CGMR" - revision=$(sh ${SCRIPT_DIR}/modem_at.sh $at_port $at_command | grep "+CGMR: " | awk -F': ' '{print $2}' | sed 's/\r//g') - - #Mode(拨号模式) - mode=$(meig_get_mode ${at_port} ${platform} | tr 'a-z' 'A-Z') - - #Temperature(温度) - temperature=$(meig_get_temperature ${at_port}) -} - -#获取SIM卡状态 -# $1:SIM卡状态标志 -meig_get_sim_status() -{ - local sim_status - case $1 in - "") sim_status="miss" ;; - *"ERROR"*) sim_status="miss" ;; - *"READY"*) sim_status="ready" ;; - *"SIM PIN"*) sim_status="MT is waiting SIM PIN to be given" ;; - *"SIM PUK"*) sim_status="MT is waiting SIM PUK to be given" ;; - *"PH-FSIM PIN"*) sim_status="MT is waiting phone-to-SIM card password to be given" ;; - *"PH-FSIM PIN"*) sim_status="MT is waiting phone-to-very first SIM card password to be given" ;; - *"PH-FSIM PUK"*) sim_status="MT is waiting phone-to-very first SIM card unblocking password to be given" ;; - *"SIM PIN2"*) sim_status="MT is waiting SIM PIN2 to be given" ;; - *"SIM PUK2"*) sim_status="MT is waiting SIM PUK2 to be given" ;; - *"PH-NET PIN"*) sim_status="MT is waiting network personalization password to be given" ;; - *"PH-NET PUK"*) sim_status="MT is waiting network personalization unblocking password to be given" ;; - *"PH-NETSUB PIN"*) sim_status="MT is waiting network subset personalization password to be given" ;; - *"PH-NETSUB PUK"*) sim_status="MT is waiting network subset personalization unblocking password to be given" ;; - *"PH-SP PIN"*) sim_status="MT is waiting service provider personalization password to be given" ;; - *"PH-SP PUK"*) sim_status="MT is waiting service provider personalization unblocking password to be given" ;; - *"PH-CORP PIN"*) sim_status="MT is waiting corporate personalization password to be given" ;; - *"PH-CORP PUK"*) sim_status="MT is waiting corporate personalization unblocking password to be given" ;; - *) sim_status="unknown" ;; - esac - echo "${sim_status}" -} - -#SIM卡信息 -meig_sim_info() -{ - debug "meig sim info" - - #SIM Slot(SIM卡卡槽) - at_command="AT^SIMSLOT?" - response=$(sh ${SCRIPT_DIR}/modem_at.sh ${at_port} ${at_command} | grep "\^SIMSLOT:" | awk -F': ' '{print $2}' | awk -F',' '{print $2}') - - if [ "$response" != "0" ]; then - sim_slot="1" - else - sim_slot="2" - fi - - #IMEI(国际移动设备识别码) - at_command="AT+CGSN" - imei=$(sh ${SCRIPT_DIR}/modem_at.sh ${at_port} ${at_command} | sed -n '2p' | sed 's/\r//g') - - #SIM Status(SIM状态) - at_command="AT+CPIN?" - sim_status_flag=$(sh ${SCRIPT_DIR}/modem_at.sh ${at_port} ${at_command} | grep "+CPIN: ") - sim_status=$(meig_get_sim_status "$sim_status_flag") - - if [ "$sim_status" != "ready" ]; then - return - fi - - #ISP(互联网服务提供商) - at_command="AT+COPS?" - isp=$(sh ${SCRIPT_DIR}/modem_at.sh ${at_port} ${at_command} | grep "+COPS" | awk -F'"' '{print $2}') - # if [ "$isp" = "CHN-CMCC" ] || [ "$isp" = "CMCC" ]|| [ "$isp" = "46000" ]; then - # isp="中国移动" - # elif [ "$isp" = "CHN-UNICOM" ] || [ "$isp" = "UNICOM" ] || [ "$isp" = "46001" ]; then - # isp="中国联通" - # elif [ "$isp" = "CHN-CT" ] || [ "$isp" = "CT" ] || [ "$isp" = "46011" ]; then - # isp="中国电信" - # fi - - #SIM Number(SIM卡号码,手机号) - at_command="AT+CNUM" - sim_number=$(sh ${SCRIPT_DIR}/modem_at.sh ${at_port} ${at_command} | grep "+CNUM: " | awk -F'"' '{print $2}') - [ -z "$sim_number" ] && { - sim_number=$(sh ${SCRIPT_DIR}/modem_at.sh ${at_port} ${at_command} | grep "+CNUM: " | awk -F'"' '{print $4}') - } - - #IMSI(国际移动用户识别码) - at_command="AT+CIMI" - imsi=$(sh ${SCRIPT_DIR}/modem_at.sh $at_port $at_command | sed -n '2p' | sed 's/\r//g') - - #ICCID(集成电路卡识别码) - at_command="AT+ICCID" - iccid=$(sh ${SCRIPT_DIR}/modem_at.sh ${at_port} ${at_command} | grep -o "+ICCID:[ ]*[-0-9]\+" | grep -o "[-0-9]\{1,4\}") -} - -#获取网络类型 -# $1:网络类型数字 -meig_get_rat() -{ - local rat - case $1 in - "0"|"1"|"3"|"8") rat="GSM" ;; - "2"|"4"|"5"|"6"|"9"|"10") rat="WCDMA" ;; - "7") rat="LTE" ;; - "11"|"12") rat="NR" ;; - esac - echo "${rat}" -} - -#获取信号强度指示(4G) -# $1:信号强度指示数字 -meig_get_rssi() -{ - local rssi - case $1 in - "99") rssi="unknown" ;; - * ) rssi=$((2 * $1 - 113)) ;; - esac - echo "$rssi" -} - -#获取4G签约速率 -# $1:AT响应 -# $2:上行或下行标志 -meig_get_lte_ambr() -{ - local response="$1" - local flag="$2" - - local ambr - case $flag in - "ul") - #使用awk拆分字符串 - ambr=$(echo "$response" | awk -F',' '{ - #使用split()函数将字符串拆分为数组 - n = split($0, arr, ",") - - #循环遍历每个值 - for (i = 1; i <= n-2; i=i+2) - { - if (arr[i] != "0") { - tmp = arr[i] - } - else { - break - } - } - print tmp - }') - ;; - "dl") - #使用awk拆分字符串 - ambr=$(echo "$response" | awk -F',' '{ - #使用split()函数将字符串拆分为数组 - n = split($0, arr, ",") - - #循环遍历每个值 - for (i = 2; i <= n-2; i=i+2) - { - if (arr[i] != "0") { - tmp = arr[i] - } - else { - break - } - } - print tmp - }') - ;; - * ) - #使用awk拆分字符串 - ambr=$(echo "$response" | awk -F',' '{ - #使用split()函数将字符串拆分为数组 - n = split($0, arr, ",") - - #循环遍历每个值 - for (i = 2; i <= n-2; i=i+2) - { - if (arr[i] != "0") { - tmp = arr[i] - } - else { - break - } - } - print tmp - }') - ;; - esac - echo "$ambr" -} - -#网络信息 -meig_network_info() -{ - debug "meig network info" - - #Connect Status(连接状态) - connect_status=$(meig_get_connect_status ${at_port} ${define_connect}) - if [ "$connect_status" != "connect" ]; then - return - fi - - #Network Type(网络类型) - at_command="AT^SYSINFOEX" - network_type=$(sh ${SCRIPT_DIR}/modem_at.sh ${at_port} ${at_command} | grep "\^SYSINFOEX:" | awk -F'"' '{print $4}') - - [ -z "$network_type" ] && { - at_command='AT+COPS?' - local rat_num=$(sh ${SCRIPT_DIR}/modem_at.sh ${at_port} ${at_command} | grep "+COPS:" | awk -F',' '{print $4}' | sed 's/\r//g') - network_type=$(meig_get_rat ${rat_num}) - } - - #设置网络类型为5G时,信号强度指示用RSRP代替 - # at_command="AT+GTCSQNREN=1" - # sh ${SCRIPT_DIR}/modem_at.sh $at_port $at_command - - #CSQ(信号强度) - at_command="AT+CSQ" - response=$(sh ${SCRIPT_DIR}/modem_at.sh $at_port $at_command | grep "+CSQ:" | sed 's/+CSQ: //g' | sed 's/\r//g') - - #RSSI(4G信号强度指示) - # rssi_num=$(echo $response | awk -F',' '{print $1}') - # rssi=$(meig_get_rssi $rssi_num) - #BER(4G信道误码率) - # ber=$(echo $response | awk -F',' '{print $2}') - - # #PER(信号强度) - # if [ -n "$csq" ]; then - # per=$(($csq * 100/31))"%" - # fi - - #最大比特率,信道质量指示 - at_command="AT^DSAMBR=${define_connect}" - response=$(sh ${SCRIPT_DIR}/modem_at.sh $at_port $at_command | grep "\^DSAMBR:" | awk -F': ' '{print $2}') - - at_command='AT+COPS?' - local rat_num=$(sh ${SCRIPT_DIR}/modem_at.sh ${at_port} ${at_command} | grep "+COPS:" | awk -F',' '{print $4}' | sed 's/\r//g') - local network_type_tmp=$(meig_get_rat ${rat_num}) - case $network_type_tmp in - "LTE") - ambr_ul_tmp=$(meig_get_lte_ambr ${response} "ul") - ambr_dl_tmp=$(meig_get_lte_ambr ${response} "dl") - ;; - "NR") - ambr_ul_tmp=$(echo "$response" | awk -F',' '{print $9}') - ambr_dl_tmp=$(echo "$response" | awk -F',' '{print $10}' | sed 's/\r//g') - ;; - *) - ambr_ul_tmp=$(meig_get_lte_ambr ${response} "ul") - ambr_dl_tmp=$(meig_get_lte_ambr ${response} "dl") - ;; - esac - - #AMBR UL(上行签约速率,单位,Mbps) - ambr_ul=$(awk "BEGIN{ printf \"%.2f\", $ambr_ul_tmp / 1024 }" | sed 's/\.*0*$//') - #AMBR DL(下行签约速率,单位,Mbps) - ambr_dl=$(awk "BEGIN{ printf \"%.2f\", $ambr_dl_tmp / 1024 }" | sed 's/\.*0*$//') - - # #速率统计 - # at_command='AT^DSFLOWQRY' - # response=$(sh ${SCRIPT_DIR}/modem_at.sh $at_port $at_command | grep "\^DSFLOWRPT:" | sed 's/\^DSFLOWRPT: //g' | sed 's/\r//g') - - # #当前上传速率(单位,Byte/s) - # tx_rate=$(echo $response | awk -F',' '{print $1}') - - # #当前下载速率(单位,Byte/s) - # rx_rate=$(echo $response | awk -F',' '{print $2}') -} - -#获取频段 -# $1:网络类型 -# $2:频段数字 -meig_get_band() -{ - local band - case $1 in - "WCDMA") band="$2" ;; - "LTE") band="$2" ;; - "NR") band="$2" ;; - esac - echo "$band" -} - -#获取带宽 -# $1:网络类型 -# $2:带宽数字 -meig_get_bandwidth() -{ - local network_type="$1" - local bandwidth_num="$2" - - local bandwidth - case $network_type in - "LTE") bandwidth=$(( $bandwidth_num / 5 )) ;; - "NR") bandwidth="$bandwidth_num" ;; - esac - echo "$bandwidth" -} - -#获取参考信号接收功率 -# $1:网络类型 -# $2:参考信号接收功率数字 -meig_get_rsrp() -{ - local rsrp - case $1 in - "LTE") rsrp=$(($2-141)) ;; - "NR") rsrp=$(($2-157)) ;; - esac - echo "$rsrp" -} - -#获取参考信号接收质量 -# $1:网络类型 -# $2:参考信号接收质量数字 -meig_get_rsrq() -{ - local rsrq - case $1 in - "LTE") rsrq=$(awk "BEGIN{ printf \"%.2f\", $2 * 0.5 - 20 }" | sed 's/\.*0*$//') ;; - "NR") rsrq=$(awk -v num="$2" "BEGIN{ printf \"%.2f\", (num+1) * 0.5 - 44 }" | sed 's/\.*0*$//') ;; - esac - echo "$rsrq" -} - -#获取信噪比 -# $1:信噪比数字 -meig_get_sinr() -{ - local sinr=$(awk "BEGIN{ printf \"%.2f\", $1 / 10 }" | sed 's/\.*0*$//') - echo "$sinr" -} - -#小区信息 -meig_cell_info() -{ - debug "Meig cell info" - - at_command="AT^CELLINFO=${define_connect}" - response=$(sh ${SCRIPT_DIR}/modem_at.sh $at_port $at_command | grep "\^CELLINFO:" | sed 's/\^CELLINFO://') - - local rat=$(echo "$response" | awk -F',' '{print $1}') - - case $rat in - "5G") - network_mode="NR5G-SA Mode" - nr_duplex_mode=$(echo "$response" | awk -F',' '{print $2}') - nr_mcc=$(echo "$response" | awk -F',' '{print $3}') - nr_mnc=$(echo "$response" | awk -F',' '{print $4}') - nr_cell_id=$(echo "$response" | awk -F',' '{print $5}') - nr_physical_cell_id=$(echo "$response" | awk -F',' '{print $6}') - nr_tac=$(echo "$response" | awk -F',' '{print $7}') - nr_band_num=$(echo "$response" | awk -F',' '{print $8}') - nr_band=$(meig_get_band "NR" ${nr_band_num}) - nr_dl_bandwidth_num=$(echo "$response" | awk -F',' '{print $9}') - nr_dl_bandwidth=$(meig_get_bandwidth "NR" ${nr_dl_bandwidth_num}) - nr_scs=$(echo "$response" | awk -F',' '{print $10}') - nr_fr_type=$(echo "$response" | awk -F',' '{print $11}') - nr_dl_channel=$(echo "$response" | awk -F',' '{print $12}') - nr_ul_channel=$(echo "$response" | awk -F',' '{print $13}') - nr_rssi=$(echo "$response" | awk -F',' '{print $14}') - nr_rsrp=$(echo "$response" | awk -F',' '{print $15}') - nr_rsrq=$(echo "$response" | awk -F',' '{print $16}') - nr_sinr_num=$(echo "$response" | awk -F',' '{print $17}') - nr_sinr=$(meig_get_sinr ${nr_sinr_num}) - nr_vonr=$(echo "$response" | awk -F',' '{print $18}' | sed 's/\r//g') - ;; - "LTE-NR") - network_mode="EN-DC Mode" - #LTE - endc_lte_duplex_mode=$(echo "$response" | awk -F',' '{print $2}') - endc_lte_mcc=$(echo "$response" | awk -F',' '{print $3}') - endc_lte_mnc=$(echo "$response" | awk -F',' '{print $4}') - endc_lte_global_cell_id=$(echo "$response" | awk -F',' '{print $5}') - endc_lte_physical_cell_id=$(echo "$response" | awk -F',' '{print $6}') - # endc_lte_eNBID=$(echo "$response" | awk -F',' '{print $7}') - endc_lte_cell_id=$(echo "$response" | awk -F',' '{print $8}') - endc_lte_tac=$(echo "$response" | awk -F',' '{print $9}') - endc_lte_band_num=$(echo "$response" | awk -F',' '{print $10}') - endc_lte_band=$(meig_get_band "LTE" ${endc_lte_band_num}) - ul_bandwidth_num=$(echo "$response" | awk -F',' '{print $11}') - endc_lte_ul_bandwidth=$(meig_get_bandwidth "LTE" ${ul_bandwidth_num}) - endc_lte_dl_bandwidth="$endc_lte_ul_bandwidth" - endc_lte_dl_channel=$(echo "$response" | awk -F',' '{print $12}') - endc_lte_ul_channel=$(echo "$response" | awk -F',' '{print $13}') - endc_lte_rssi=$(echo "$response" | awk -F',' '{print $14}') - endc_lte_rsrp=$(echo "$response" | awk -F',' '{print $15}') - endc_lte_rsrq=$(echo "$response" | awk -F',' '{print $16}') - endc_lte_sinr_num=$(echo "$response" | awk -F',' '{print $17}') - endc_lte_sinr=$(meig_get_sinr ${endc_lte_sinr_num}) - endc_lte_rssnr=$(echo "$response" | awk -F',' '{print $18}') - # endc_lte_ue_category=$(echo "$response" | awk -F',' '{print $19}') - # endc_lte_pathloss=$(echo "$response" | awk -F',' '{print $20}') - # endc_lte_cqi=$(echo "$response" | awk -F',' '{print $21}') - endc_lte_tx_power=$(echo "$response" | awk -F',' '{print $22}') - # endc_lte_tm=$(echo "$response" | awk -F',' '{print $23}') - # endc_lte_qci=$(echo "$response" | awk -F',' '{print $24}') - # endc_lte_volte=$(echo "$response" | awk -F',' '{print $25}') - # endc_lte_ims_sms=$(echo "$response" | awk -F',' '{print $26}') - # endc_lte_sib2_plmn_r15_info_present=$(echo "$response" | awk -F',' '{print $27}') - # endc_lte_sib2_upr_layer_ind=$(echo "$response" | awk -F',' '{print $28}') - # endc_lte_restrict_dcnr=$(echo "$response" | awk -F',' '{print $29}') - #NR5G-NSA - endc_nr_mcc=$(echo "$response" | awk -F',' '{print $3}') - endc_nr_mnc=$(echo "$response" | awk -F',' '{print $4}') - endc_nr_global_cell_id=$(echo "$response" | awk -F',' '{print $5}') - endc_nr_physical_cell_id=$(echo "$response" | awk -F',' '{print $6}') - endc_nr_cell_id=$(echo "$response" | awk -F',' '{print $8}') - endc_nr_tac=$(echo "$response" | awk -F',' '{print $9}') - endc_nr_rsrp=$(echo "$response" | awk -F',' '{print $30}') - endc_nr_rsrq=$(echo "$response" | awk -F',' '{print $31}') - endc_nr_sinr_num=$(echo "$response" | awk -F',' '{print $32}') - endc_nr_sinr=$(meig_get_sinr ${endc_nr_sinr_num}) - endc_nr_band_num=$(echo "$response" | awk -F',' '{print $33}') - endc_nr_band=$(meig_get_band "NR" ${endc_nr_band_num}) - endc_nr_freq=$(echo "$response" | awk -F',' '{print $34}') - nr_dl_bandwidth_num=$(echo "$response" | awk -F',' '{print $35}') - endc_nr_dl_bandwidth=$(meig_get_bandwidth "NR" ${nr_dl_bandwidth_num}) - # endc_nr_pci=$(echo "$response" | awk -F',' '{print $36}') - endc_nr_scs=$(echo "$response" | awk -F',' '{print $37}' | sed 's/\r//g') - ;; - "LTE"|"eMTC"|"NB-IoT") - network_mode="LTE Mode" - lte_duplex_mode=$(echo "$response" | awk -F',' '{print $2}') - lte_mcc=$(echo "$response" | awk -F',' '{print $3}') - lte_mnc=$(echo "$response" | awk -F',' '{print $4}') - lte_global_cell_id=$(echo "$response" | awk -F',' '{print $5}') - lte_physical_cell_id=$(echo "$response" | awk -F',' '{print $6}') - lte_eNBID=$(echo "$response" | awk -F',' '{print $7}') - lte_cell_id=$(echo "$response" | awk -F',' '{print $8}') - let_tac=$(echo "$response" | awk -F',' '{print $9}') - # lte_earfcn=$(echo "$response" | awk -F',' '{print $7}') - lte_band_num=$(echo "$response" | awk -F',' '{print $10}') - lte_band=$(meig_get_band "LTE" ${lte_band_num}) - ul_bandwidth_num=$(echo "$response" | awk -F',' '{print $11}') - lte_ul_bandwidth=$(meig_get_bandwidth "LTE" ${ul_bandwidth_num}) - lte_dl_bandwidth="$lte_ul_bandwidth" - lte_dl_channel=$(echo "$response" | awk -F',' '{print $12}') - lte_ul_channel=$(echo "$response" | awk -F',' '{print $13}') - lte_rssi=$(echo "$response" | awk -F',' '{print $14}') - lte_rsrp=$(echo "$response" | awk -F',' '{print $15}') - lte_rsrq=$(echo "$response" | awk -F',' '{print $16}') - lte_sinr_num=$(echo "$response" | awk -F',' '{print $17}') - lte_sinr=$(meig_get_sinr ${lte_sinr_num}) - lte_rssnr=$(echo "$response" | awk -F',' '{print $18}') - # lte_ue_category=$(echo "$response" | awk -F',' '{print $19}') - # lte_pathloss=$(echo "$response" | awk -F',' '{print $20}') - # lte_cqi=$(echo "$response" | awk -F',' '{print $21}') - lte_tx_power=$(echo "$response" | awk -F',' '{print $22}') - # lte_tm=$(echo "$response" | awk -F',' '{print $23}') - # lte_qci=$(echo "$response" | awk -F',' '{print $24}') - # lte_volte=$(echo "$response" | awk -F',' '{print $25}') - # lte_ims_sms=$(echo "$response" | awk -F',' '{print $26}') - # lte_sib2_plmn_r15_info_present=$(echo "$response" | awk -F',' '{print $27}') - # lte_sib2_upr_layer_ind=$(echo "$response" | awk -F',' '{print $28}') - # lte_restrict_dcnr=$(echo "$response" | awk -F',' '{print $29}' | sed 's/\r//g') - ;; - "WCDMA"|"UMTS") - network_mode="WCDMA Mode" - wcdma_mcc=$(echo "$response" | awk -F',' '{print $2}') - wcdma_mnc=$(echo "$response" | awk -F',' '{print $3}') - wcdma_global_cell_id=$(echo "$response" | awk -F',' '{print $4}') - wcdma_psc=$(echo "$response" | awk -F',' '{print $5}') - wcdma_NodeB=$(echo "$response" | awk -F',' '{print $6}') - wcdma_cell_id=$(echo "$response" | awk -F',' '{print $7}') - wcdma_lac=$(echo "$response" | awk -F',' '{print $8}') - wcdma_band_num=$(echo "$response" | awk -F',' '{print $9}') - wcdma_band=$(meig_get_band "WCDMA" ${wcdma_band_num}) - wcdma_dl_channel=$(echo "$response" | awk -F',' '{print $10}') - wcdma_ul_channel=$(echo "$response" | awk -F',' '{print $11}') - wcdma_rssi=$(echo "$response" | awk -F',' '{print $12}') - wcdma_ecio=$(echo "$response" | awk -F',' '{print $13}') - # wcdma_sir=$(echo "$response" | awk -F',' '{print $14}') - wcdma_rscp=$(echo "$response" | awk -F',' '{print $15}' | sed 's/\r//g') - ;; - "GSM") - network_mode="GSM Mode" - gsm_mcc=$(echo "$response" | awk -F',' '{print $3}') - gsm_mnc=$(echo "$response" | awk -F',' '{print $4}') - ;; - esac -} - -#获取美格模组信息 -# $1:AT串口 -# $2:平台 -# $3:连接定义 -get_meig_info() -{ - debug "get meig info" - #设置AT串口 - at_port="$1" - platform="$2" - define_connect="$3" - - #基本信息 - meig_base_info - - #SIM卡信息 - meig_sim_info - if [ "$sim_status" != "ready" ]; then - return - fi - - #网络信息 - meig_network_info - if [ "$connect_status" != "connect" ]; then - return - fi - - #小区信息 - meig_cell_info -} \ No newline at end of file diff --git a/luci-app-modem/root/usr/share/modem/modem_at.sh b/luci-app-modem/root/usr/share/modem/modem_at.sh deleted file mode 100755 index 5e57b0b..0000000 --- a/luci-app-modem/root/usr/share/modem/modem_at.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/sh -# Copyright (C) 2023 Siriling - -#脚本目录 -SCRIPT_DIR="/usr/share/modem" -source "${SCRIPT_DIR}/modem_debug.sh" - -#发送at命令 -# $1 AT串口 -# $2 AT命令 -at "$1" "$2" \ No newline at end of file diff --git a/luci-app-modem/root/usr/share/modem/modem_ctrl.sh b/luci-app-modem/root/usr/share/modem/modem_ctrl.sh new file mode 100755 index 0000000..ea71a85 --- /dev/null +++ b/luci-app-modem/root/usr/share/modem/modem_ctrl.sh @@ -0,0 +1,171 @@ +#!/bin/sh +source /usr/share/libubox/jshn.sh +method=$1 +config_section=$2 +at_port=$(uci get modem.$config_section.at_port) +vendor=$(uci get modem.$config_section.manufacturer) +platform=$(uci get modem.$config_section.platform) +define_connect=$(uci get modem.$config_section.define_connect) +[ -z "$define_connect" ] && { + define_connect="1" +} + +case $vendor in + "quectel") + . /usr/share/modem/quectel.sh + ;; + "fibocom") + . /usr/share/modem/fibocom.sh + ;; + *) + . /usr/share/modem/generic.sh + ;; +esac + +try_cache() { + cache_timeout=$1 + cache_file=$2 + function_name=$3 + current_time=$(date +%s) + file_time=$(stat -t $cache_file | awk '{print $14}') + if [ ! -f $cache_file ] || [ $(($current_time - $file_time)) -gt $cache_timeout ]; then + touch $cache_file + json_add_array modem_info + $function_name + json_close_array + json_dump > $cache_file + return 1 + else + cat $cache_file + exit 0 + fi +} + +get_sms(){ + cache_timeout=$1 + cache_file=$2 + current_time=$(date +%s) + file_time=$(stat -t $cache_file | awk '{print $14}') + if [ ! -f $cache_file ] || [ $(($current_time - $file_time)) -gt $cache_timeout ]; then + touch $cache_file + sms_tool -d $at_port -j recv > $cache_file + cat $cache_file + else + cat $cache_file + fi +} + + +#会初始化一个json对象 命令执行结果会保存在json对象中 +json_init +json_add_object result +json_close_object +case $method in + "clear_dial_log") + json_select result + log_file="/var/run/modem/${config_section}_dir/dial_log" + [ -f $log_file ] && echo "" > $log_file && json_add_string status "1" || json_add_string status "0" + json_close_object + ;; + "get_dns") + get_dns + ;; + "get_imei") + get_imei + ;; + "set_imei") + set_imei $3 + ;; + "get_mode") + get_mode + ;; + "set_mode") + set_mode $3 + ;; + "get_network_prefer") + get_network_prefer + ;; + "set_network_prefer") + set_network_prefer $3 + ;; + "get_lockband") + get_lockband + ;; + "set_lockband") + set_lockband $3 + ;; + "get_neighborcell") + get_neighborcell + ;; + "set_neighborcell") + set_neighborcell $3 + ;; + "base_info") + cache_file="/tmp/cache_$1_$2" + try_cache 10 $cache_file base_info + ;; + "sim_info") + cache_file="/tmp/cache_$1_$2" + try_cache 10 $cache_file sim_info + ;; + "cell_info") + cache_file="/tmp/cache_$1_$2" + try_cache 10 $cache_file cell_info + ;; + "network_info") + cache_file="/tmp/cache_$1_$2" + try_cache 10 $cache_file network_info + ;; + "info") + cache_file="/tmp/cache_$1_$2" + try_cache 10 $cache_file get_info + ;; + "get_sms") + get_sms 10 /tmp/cache_sms_$2 + exit + ;; + "send_sms") + cmd_json=$3 + phone_number=$(echo $cmd_json | jq -r '.phone_number') + message_content=$(echo $cmd_json | jq -r '.message_content') + sms_tool -d $at_port send "$phone_number" "$message_content" > /dev/null + json_select result + if [ "$?" == 0 ]; then + json_add_string status "1" + json_add_string cmd "sms_tool -d $at_port send \"$phone_number\" \"$message_content\"" + json_add_string "cmd_json" "$cmd_json" + else + json_add_string status "0" + fi + json_close_object + ;; + "send_raw_pdu") + cmd=$3 + res=$(sms_tool -d $at_port send_raw_pdu "$cmd" ) + json_select result + if [ "$?" == 0 ]; then + json_add_string status "1" + json_add_string cmd "sms_tool -d $at_port send_raw_pdu \"$cmd\"" + json_add_string "res" "$res" + else + json_add_string status "0" + fi + ;; + "delete_sms") + json_select result + index=$3 + for i in $index; do + sms_tool -d $at_port delete $i > /dev/null + touch /tmp/cache_sms_$2 + if [ "$?" == 0 ]; then + json_add_string status "1" + json_add_string "index$i" "sms_tool -d $at_port delete $i" + else + json_add_string status "0" + fi + done + json_close_object + rm -rf /tmp/cache_sms_$2 + ;; +esac +json_dump diff --git a/luci-app-modem/root/usr/share/modem/modem_debug.sh b/luci-app-modem/root/usr/share/modem/modem_debug.sh deleted file mode 100755 index 0a83129..0000000 --- a/luci-app-modem/root/usr/share/modem/modem_debug.sh +++ /dev/null @@ -1,77 +0,0 @@ -#!/bin/sh -# Copyright (C) 2023 Siriling - -#脚本目录 -SCRIPT_DIR="/usr/share/modem" - -source "${SCRIPT_DIR}/quectel.sh" -source "${SCRIPT_DIR}/fibocom.sh" -source "${SCRIPT_DIR}/meig.sh" -# source "${SCRIPT_DIR}/simcom.sh" - -#调试开关 -# 0关闭 -# 1打开 -# 2输出到文件 -switch=0 -out_file="/tmp/modem.log" #输出文件 -#日志信息 -debug() -{ - time=$(date "+%Y-%m-%d %H:%M:%S") #获取系统时间 - if [ $switch = 1 ]; then - echo $time $1 #打印输出 - elif [ $switch = 2 ]; then - echo $time $1 >> $outfile #输出到文件 - fi -} - -#发送at命令 -# $1 AT串口 -# $2 AT命令 -at() -{ - local at_port="$1" - local new_str="${2/[$]/$}" - local at_command="${new_str/\"/\"}" - - #echo - # echo -e "${at_command}"" > "${at_port}" 2>&1 - - #sms_tool - sms_tool -d "${at_port}" at "${at_command}" 2>&1 -} - -#测试时打开 -# debug $1 -# at $1 $2 - -#获取快捷命令 -# $1:快捷选项 -# $2:制造商 -get_quick_commands() -{ - local quick_option="$1" - local manufacturer="$2" - - local quick_commands - case "$quick_option" in - "auto") quick_commands=$(cat ${SCRIPT_DIR}/${manufacturer}_at_commands.json) ;; - "custom") quick_commands=$(cat /etc/modem/custom_at_commands.json) ;; - *) quick_commands=$(cat ${SCRIPT_DIR}/${manufacturer}_at_commands.json) ;; - esac - echo "$quick_commands" -} - -#拨号日志 -# $1:log mesg -# $2:日志路径 -dial_log() -{ - local logmsg="$1" - local path="$2" - - #打印日志 - local update_time=$(date +"%Y-%m-%d %H:%M:%S") - echo "[${update_time}] ${logmsg} " >> "${path}" -} diff --git a/luci-app-modem/root/usr/share/modem/modem_dial.sh b/luci-app-modem/root/usr/share/modem/modem_dial.sh index 07564bb..8b7a03f 100755 --- a/luci-app-modem/root/usr/share/modem/modem_dial.sh +++ b/luci-app-modem/root/usr/share/modem/modem_dial.sh @@ -2,10 +2,47 @@ source /lib/functions.sh #运行目录 MODEM_RUNDIR="/var/run/modem" -#脚本目录 SCRIPT_DIR="/usr/share/modem" -#导入组件工具 -source "${SCRIPT_DIR}/modem_debug.sh" + +modem_config=$1 +mkdir -p "${MODEM_RUNDIR}/${modem_config}_dir" +log_file="${MODEM_RUNDIR}/${modem_config}_dir/dial_log" +debug_subject="modem_dial" +source "${SCRIPT_DIR}/generic.sh" +touch $log_file + +set_led() +{ + local type=$1 + local modem_config=$2 + local value=$3 + case $data_interface in + usb) + config_get sim_led u$modem_config sim_led + config_get net_led u$modem_config net_led + ;; + pcie) + config_get sim_led p$modem_config sim_led + config_get net_led p$modem_config net_led + ;; + *) + #usb + config_get sim_led u$modem_config sim_led + config_get net_led u$modem_config net_led + ;; + esac + case $type in + sim) + echo $value > /sys/class/leds/$sim_led/brightness + ;; + net) + uci set system.led_${net_led}.dev=$value + uci commit system + /etc/init.d/led restart + ;; + esac +} + get_driver() { for i in $(find $modem_path -name driver);do @@ -44,29 +81,125 @@ get_driver() done echo $mode } -config_load modem -modem_config=$1 -log_path="${MODEM_RUNDIR}/${modem_config}_dial.cache" -config_get apn $modem_config apn -config_get modem_path $modem_config path -config_get modem_dial $modem_config enable_dial -config_get dial_tool $modem_config dial_tool -config_get pdp_type $modem_config pdp_type -config_get network_bridge $modem_config network_bridge -config_get apn $modem_config apn -config_get username $modem_config username -config_get password $modem_config password -config_get auth $modem_config auth -config_get at_port $modem_config at_port -config_get manufacturer $modem_config manufacturer -config_get platform $modem_config platform -config_get define_connect $modem_config define_connect -modem_netcard=$(ls $(find $modem_path -name net |tail -1) | awk -F'/' '{print $NF}') -interface_name=wwan_5g_$(echo $modem_config | grep -oE "[0-9]+") -interface6_name=wwan6_5g_$(echo $modem_config | grep -oE "[0-9]+") -ethernet_5g=$(uci -q get modem.global.ethernet) -driver=$(get_driver) -dial_log "modem_path=$modem_path,driver=$driver,interface=$interface_name,at_port=$at_port" "$log_path" + +unlock_sim() +{ + pin=$1 + sim_lock_file="/var/run/modem/${modem_config}_dir/pincode" + lock ${sim_lock_file}.lock + if [ -f $sim_lock_file ] && [ "$pin" == "$(cat $sim_lock_file)"];then + m_debug "pin code is already try" + else + + res=$(at "$at_port" "AT+CPIN=\"$pin\"") + case "$?" in + 0) + m_debug "unlock sim card with pin code $pin success" + ;; + *) + echo $pin > $sim_lock_file + m_debug "info" "unlock sim card with pin code $pin failed,block try until nextboot" + ;; + esac + fi + lock -u ${sim_lock_file}.lock + +} + +update_config() +{ + config_load modem + config_get state $modem_config state + config_get enable_dial $modem_config enable_dial + config_get modem_path $modem_config path + config_get dial_tool $modem_config dial_tool + config_get pdp_type $modem_config pdp_type + config_get network_bridge $modem_config network_bridge + config_get metric $modem_config metric + config_get at_port $modem_config at_port + config_get manufacturer $modem_config manufacturer + config_get platform $modem_config platform + config_get define_connect $modem_config define_connect + config_get ra_master $modem_config ra_master + config_get global_dial global enable_dial + config_get ethernet_5g u$modem_config ethernet + driver=$(get_driver) + update_sim_slot + case $sim_slot in + 1) + config_get apn $modem_config apn + config_get username $modem_config username + config_get password $modem_config password + config_get auth $modem_config auth + config_get pincode $modem_config pincode + ;; + 2) + config_get apn $modem_config apn2 + config_get username $modem_config username2 + config_get password $modem_config password2 + config_get auth $modem_config auth2 + config_get pincode $modem_config pincode2 + [ -z "$apn" ] && config_get apn $modem_config apn + [ -z "$username" ] && config_get username $modem_config username + [ -z "$password" ] && config_get password $modem_config password + [ -z "$auth" ] && config_get auth $modem_config auth + [ -z "$pin" ] && config_get pincode $modem_config pincode + ;; + *) + config_get apn $modem_config apn + config_get username $modem_config username + config_get password $modem_config password + config_get auth $modem_config auth + config_get pincode $modem_config pincode + ;; + esac + modem_net=$(find $modem_path -name net |tail -1) + modem_netcard=$(ls $modem_net) + interface_name=$modem_config + interface6_name=${modem_config}v6 +} + +check_dial_prepare() +{ + cpin=$(at "$at_port" "AT+CPIN?") + get_sim_status "$cpin" + case $sim_state_code in + "0") + m_debug "info sim card is miss" + ;; + "1") + m_debug "info sim card is ready" + sim_fullfill=1 + ;; + "2") + m_debug "pin code required" + [ -n "$pincode" ] && unlock_sim $pincode + ;; + *) + m_debug "info sim card state is $sim_state_code" + ;; + esac + + if [ "$sim_fullfill" = "1" ];then + set_led "sim" $modem_config 255 + else + set_led "sim" $modem_config 0 + fi + if [ -n "$modem_netcard" ] && [ -d "/sys/class/net/$modem_netcard" ];then + netdev_fullfill=1 + else + netdev_fullfill=0 + fi + + if [ "$enable_dial" = "1" ] && [ "$sim_fullfill" = "1" ] && [ "$state" != "disabled" ] ;then + config_fullfill=1 + fi + if [ "$config_fullfill" = "1" ] && [ "$sim_fullfill" = "1" ] && [ "$netdev_fullfill" = "1" ] ;then + return 1 + else + return 0 + fi +} check_ip() { @@ -126,10 +259,9 @@ check_ip() if [ -n "$ipv4" ] && [ -n "$ipv6" ];then connection_status=3 fi - dial_log "current ip [$ipv6],[$ipv4],connection_status=$connection_status" "$log_path" else connection_status="-1" - dial_log "at port response unexpected $ipaddr" "$log_path" + m_debug "at port response unexpected $ipaddr" fi } @@ -142,7 +274,7 @@ set_if() uci set network.${interface_name}.proto='dhcp' uci set network.${interface_name}.defaultroute='1' uci set network.${interface_name}.peerdns='0' - uci set network.${interface_name}.metric='10' + uci set network.${interface_name}.metric="${metric}" uci add_list network.${interface_name}.dns='114.114.114.114' uci add_list network.${interface_name}.dns='119.29.29.29' local num=$(uci show firewall | grep "name='wan'" | wc -l) @@ -150,7 +282,6 @@ set_if() if [ "$wwan_num" = "0" ]; then uci add_list firewall.@zone[$num].network="${interface_name}" fi - #set ipv6 #if pdptype contain 6 if [ -n "$(echo $pdp_type | grep "6")" ];then @@ -159,44 +290,53 @@ set_if() uci set network.lan.ip6class="${interface6_name}" uci set network.${interface6_name}='interface' uci set network.${interface6_name}.proto='dhcpv6' - uci set network.${interface6_name}.extendprefix='1' uci set network.${interface6_name}.ifname="@${interface_name}" uci set network.${interface6_name}.device="@${interface_name}" - uci set network.${interface6_name}.metric='10' + uci set network.${interface6_name}.metric="${metric}" + if [ "$ra_master" = "1" ];then + uci set dhcp.${interface6_name}='dhcp' + uci set dhcp.${interface6_name}.interface="${interface6_name}" + uci set dhcp.${interface6_name}.ra='relay' + uci set dhcp.${interface6_name}.ndp='relay' + uci set dhcp.${interface6_name}.master='1' + uci set dhcp.${interface6_name}.ignore='1' + uci set dhcp.lan.ra='relay' + uci set dhcp.lan.ndp='relay' + uci set dhcp.lan.dhcpv6='relay' + uci commit dhcp + fi local wwan6_num=$(uci -q get firewall.@zone[$num].network | grep -w "${interface6_name}" | wc -l) if [ "$wwan6_num" = "0" ]; then uci add_list firewall.@zone[$num].network="${interface6_name}" fi fi - - - uci commit network uci commit firewall ifup ${interface_name} - dial_log "create interface $interface_name" "$log_path" + m_debug "create interface $interface_name" fi - + set_modem_netcard=$modem_netcard if [ -z "$set_modem_netcard" ];then - dial_log "no netcard found" "$log_path" + m_debug "no netcard found" fi ethernet_check=$(handle_5gethernet) - if [ -n "$ethernet_check" ];then + if [ -n "$ethernet_check" ] && [ -n "/sys/class/net/$ethernet_5g" ] && [ -n "$ethernet_5g" ];then set_modem_netcard=$ethernet_5g fi + #set led + set_led "net" $modem_config $set_modem_netcard origin_netcard=$(uci -q get network.$interface_name.ifname) origin_device=$(uci -q get network.$interface_name.device) if [ "$origin_netcard" == "$set_modem_netcard" ] && [ "$origin_device" == "$set_modem_netcard" ];then - dial_log "interface $interface_name already set to $set_modem_netcard" "$log_path" + m_debug "interface $interface_name already set to $set_modem_netcard" else uci set network.${interface_name}.ifname="${set_modem_netcard}" uci set network.${interface_name}.device="${set_modem_netcard}" - uci commit network ifup ${interface_name} - dial_log "set interface $interface_name to $modem_netcard" "$log_path" + m_debug "set interface $interface_name to $set_modem_netcard" fi } @@ -204,14 +344,26 @@ flush_if() { uci delete network.${interface_name} uci delete network.${interface6_name} + uci delete dhcp.${interface6_name} uci commit network - dial_log "delete interface $interface_name" "$log_path" + uci commit dhcp + set_led "net" $modem_config + set_led "sim" $modem_config 0 + m_debug "delete interface $interface_name" } dial(){ + update_config + m_debug "modem_path=$modem_path,driver=$driver,interface=$interface_name,at_port=$at_port,using_sim_slot:$sim_slot" + while [ "$dial_prepare" != 1 ] ; do + sleep 5 + update_config + check_dial_prepare + dial_prepare=$? + done set_if - dial_log "dialing $modem_path driver $driver" "$log_path" + m_debug "dialing $modem_path driver $driver" case $driver in "qmi") qmi_dial @@ -234,7 +386,14 @@ dial(){ esac } -hang() +wwan_hang() +{ + #kill quectel-CM + killall quectel-CM +} + + +ecm_hang() { if [ "$manufacturer" = "quectel" ]; then at_command="AT+QNETDEVCTL=1,2,1" @@ -252,6 +411,29 @@ hang() fi tmp=$(at "${at_port}" "${at_command}") +} + + +hang() +{ + m_debug "hang up $modem_path driver $driver" + case $driver in + "ncm") + ecm_hang + ;; + "ecm") + ecm_hang + ;; + "rndis") + ecm_hang + ;; + "qmi") + wwan_hang + ;; + "mbim") + wwan_hang + ;; + esac flush_if } @@ -269,7 +451,7 @@ qmi_dial() cmd_line="quectel-CM" case $pdp_type in - "ipv4") cmd_line="$cmd_line -4" ;; + "ip") cmd_line="$cmd_line -4" ;; "ipv6") cmd_line="$cmd_line -6" ;; "ipv4v6") cmd_line="$cmd_line -4 -6" ;; *) cmd_line="$cmd_line -4 -6" ;; @@ -293,8 +475,8 @@ qmi_dial() if [ -n "$modem_netcard" ]; then cmd_line="$cmd_line -i $modem_netcard" fi - dial_log "dialing $cmd_line" "$log_path" - cmd_line="$cmd_line -f $log_path" + + cmd_line="$cmd_line -f $log_file" $cmd_line @@ -306,7 +488,7 @@ at_dial() apn="auto" fi if [ -z "$pdp_type" ];then - pdp_type="IPV4V6" + pdp_type="IP" fi local at_command='AT+COPS=0,0' tmp=$(at "${at_port}" "${at_command}") @@ -359,15 +541,14 @@ at_dial() ;; esac - dial_log "dialing vendor:$manufacturer;platform:$platform; $cgdcont_command" "$log_path" - dial_log "dialing vendor:$manufacturer;platform:$platform; $at_command" "$log_path" + m_debug "dialing vendor:$manufacturer;platform:$platform; $cgdcont_command ; $at_command" at "${at_port}" "${cgdcont_command}" at "$at_port" "$at_command" } ip_change_fm350() { - dial_log "ip_change_fm350" "$log_path" + m_debug "ip_change_fm350" at_command="AT+CGPADDR=3" local ipv4_config=$(at ${at_port} ${at_command} | cut -d, -f2 | grep -oE '[0-9]+.[0-9]+.[0-9]+.[0-9]+') local public_dns1_ipv4="223.5.5.5" @@ -407,49 +588,93 @@ ip_change_fm350() uci commit network ifdown ${interface_name} ifup ${interface_name} - dial_log "set interface $interface_name to $ipv4_config" "$log_path" + m_debug "set interface $interface_name to $ipv4_config" } handle_5gethernet() +{ + case $manufacturer in + "quectel") + case $platform in + "qualcomm") + quectel_qualcomm_ethernet + ;; + "unisoc") + quectel_unisoc_ethernet + ;; + esac + ;; + esac +} + +quectel_unisoc_ethernet() { case "$driver" in "ncm"|\ "ecm"|\ "rndis") - case "$manufacturer" in - "quectel") - case "$platform" in - "unisoc") - check_ethernet_cmd="AT+QCFG=\"ethernet\"" - time=0 - while [ $time -lt 5 ]; do - result=$(sh ${SCRIPT_DIR}/modem_at.sh $at_port $check_ethernet_cmd | grep "+QCFG:") - if [ -n "$result" ]; then - if [ -n "$(echo $result | grep "ethernet\",1")" ]; then - echo "1" - dial_log "5G Ethernet mode is enabled" "$log_path" - break - fi - fi - sleep 5 - time=$((time+1)) - done - ;; - esac - ;; - esac + check_ethernet_cmd="AT+QCFG=\"ethernet\"" + time=0 + while [ $time -lt 5 ]; do + result=$(at $at_port $check_ethernet_cmd | grep "+QCFG:") + if [ -n "$result" ]; then + if [ -n "$(echo $result | grep "ethernet\",1")" ]; then + echo "1" + m_debug "5G Ethernet mode is enabled" + break + fi + fi + sleep 5 + time=$((time+1)) + done ;; esac } +quectel_qualcomm_ethernet() +{ + case "$driver" in + "mbim") + eth_driver_at="AT+QETH=\"eth_driver\"" + data_interface_at="AT+QCFG=\"data_interface\"" + ehter_driver_expect="\"r8125\",1" + data_interface_expect="\"data_interface\",1" + + time=0 + while [ $time -lt 5 ]; do + eth_driver_result=$(at $at_port $eth_driver_at | grep "+QETH:") + time=$(($time+1)) + sleep 1 + if [ -n "$eth_driver_result" ];then + break + fi + done + time=0 + while [ $time -lt 5 ]; do + data_interface_result=$(at $at_port $data_interface_at | grep "+QCFG:") + time=$(($time+1)) + sleep 1 + if [ -n "$data_interface_result" ];then + break + fi + done + eth_driver_pass=$(echo $eth_driver_result | grep "$ehter_driver_expect") + data_interface_pass=$(echo $data_interface_result | grep "$data_interface_expect") + if [ -n "$eth_driver_pass" ] && [ -n "$data_interface_pass" ];then + echo "1" + m_debug "5G Ethernet mode is enabled" + fi + ;; + esac +} handle_ip_change() { export ipv4 export ipv6 export connection_status - dial_log "ip changed from $ipv6_cache,$ipv4_cache to $ipv6,$ipv4" "$log_path" + m_debug "ip changed from $ipv6_cache,$ipv4_cache to $ipv6,$ipv4" case $manufacturer in "fibocom") case $platform in @@ -463,10 +688,10 @@ handle_ip_change() check_logfile_line() { - local line=$(wc -l $log_path | awk '{print $1}') + local line=$(wc -l $log_file | awk '{print $1}') if [ $line -gt 300 ];then - echo "" > $log_path - dial_log "log file line is over 300,clear it" "$log_path" + echo "" > $log_file + m_debug "log file line is over 300,clear it" fi } @@ -487,7 +712,7 @@ at_dial_monitor() at_dial unexpected_response_count=0 fi - sleep 5 + sleep 10 else #检测ipv4是否变化 sleep 15 @@ -499,12 +724,19 @@ at_dial_monitor() fi check_logfile_line done - } -case $2 in +case "$2" in "hang") + debug_subject="modem_hang" + update_config hang;; "dial") - dial;; + case "$state" in + "disabled") + debug_subject="modem_hang" + hang;; + *) + dial;; + esac esac diff --git a/luci-app-modem/root/usr/share/modem/modem_info.sh b/luci-app-modem/root/usr/share/modem/modem_info.sh deleted file mode 100755 index 94d7d99..0000000 --- a/luci-app-modem/root/usr/share/modem/modem_info.sh +++ /dev/null @@ -1,407 +0,0 @@ -#!/bin/sh -# Copyright (C) 2023 Siriling - -#脚本目录 -SCRIPT_DIR="/usr/share/modem" -source "${SCRIPT_DIR}/modem_debug.sh" - -#初值化数据结构 -init_modem_info() -{ - #基本信息 - name='unknown' #名称 - manufacturer='unknown' #制造商 - revision='-' #固件版本 - at_port='-' #AT串口 - mode='unknown' #拨号模式 - temperature="NaN $(printf "\xc2\xb0")C" #温度 - update_time='-' #更新时间 - - #SIM卡信息 - sim_status="unknown" #SIM卡状态 - sim_slot="-" #SIM卡卡槽 - isp="-" #运营商(互联网服务提供商) - sim_number='-' #SIM卡号码(手机号) - imei='-' #IMEI - imsi='-' #IMSI - iccid='-' #ICCID - - #网络信息 - connect_status="disconnect" #SIM卡状态 - network_type="-" #蜂窝网络类型 - cqi_ul="-" #上行信道质量指示 - cqi_dl="-" #下行信道质量指示 - ambr_ul="-" #上行签约速率 - ambr_dl="-" #下行签约速率 - tx_rate="-" #上传速率 - rx_rate="-" #下载速率 - - #小区信息 - network_mode="-" #网络模式 - #NR5G-SA模式 - nr_mcc='' - nr_mnc='' - nr_duplex_mode='' - nr_cell_id='' - nr_physical_cell_id='' - nr_tac='' - nr_arfcn='' - nr_band='' - nr_dl_bandwidth='' - nr_rsrp='' - nr_rsrq='' - nr_sinr='' - nr_rxlev='' - nr_scs='' - nr_srxlev='' - #EN-DC模式(LTE) - endc_lte_mcc='' - endc_lte_mnc='' - endc_lte_duplex_mode='' - endc_lte_cell_id='' - endc_lte_physical_cell_id='' - endc_lte_earfcn='' - endc_lte_freq_band_ind='' - endc_lte_ul_bandwidth='' - endc_lte_dl_bandwidth='' - endc_lte_tac='' - endc_lte_rsrp='' - endc_lte_rsrq='' - endc_lte_rssi='' - endc_lte_sinr='' - endc_lte_rxlev='' - endc_lte_cql='' - endc_lte_tx_power='' - endc_lte_srxlev='' - #EN-DC模式(NR5G-NSA) - endc_nr_mcc='' - endc_nr_mnc='' - endc_nr_physical_cell_id='' - endc_nr_arfcn='' - endc_nr_band='' - endc_nr_dl_bandwidth='' - endc_nr_rsrp='' - endc_nr_rsrq='' - endc_nr_sinr='' - endc_nr_scs='' - #LTE模式 - lte_mcc='' - lte_mnc='' - lte_duplex_mode='' - lte_cell_id='' - lte_physical_cell_id='' - lte_earfcn='' - lte_freq_band_ind='' - lte_ul_bandwidth='' - lte_dl_bandwidth='' - lte_tac='' - lte_rsrp='' - lte_rsrq='' - lte_rssi='' - lte_sinr='' - lte_rxlev='' - lte_cql='' - lte_tx_power='' - lte_srxlev='' - #WCDMA模式 - wcdma_mcc='' - wcdma_mnc='' - wcdma_lac='' - wcdma_cell_id='' - wcdma_uarfcn='' - wcdma_psc='' - wcdma_rac='' - wcdma_rscp='' - wcdma_ecio='' - wcdma_phych='' - wcdma_sf='' - wcdma_slot='' - wcdma_speech_code='' - wcdma_com_mod='' -} - -#设置基本信息 -set_base_info() -{ - base_info="\"base_info\":{ - \"manufacturer\":\"$manufacturer\", - \"revision\":\"$revision\", - \"at_port\":\"$at_port\", - \"mode\":\"$mode\", - \"temperature\":\"$temperature\", - \"update_time\":\"$update_time\" - }," -} - -#设置SIM卡信息 -set_sim_info() -{ - if [ "$sim_status" = "ready" ]; then - sim_info="\"sim_info\":[ - {\"SIM Status\":\"$sim_status\", \"full_name\":\"SIM Status\"}, - {\"ISP\":\"$isp\", \"full_name\":\"Internet Service Provider\"}, - {\"SIM Slot\":\"$sim_slot\", \"full_name\":\"SIM Slot\"}, - {\"SIM Number\":\"$sim_number\", \"full_name\":\"SIM Number\"}, - {\"IMEI\":\"$imei\", \"full_name\":\"International Mobile Equipment Identity\"}, - {\"IMSI\":\"$imsi\", \"full_name\":\"International Mobile Subscriber Identity\"}, - {\"ICCID\":\"$iccid\", \"full_name\":\"Integrate Circuit Card Identity\"} - ]," - elif [ "$sim_status" = "miss" ]; then - sim_info="\"sim_info\":[ - {\"SIM Status\":\"$sim_status\", \"full_name\":\"SIM Status\"}, - {\"IMEI\":\"$imei\", \"full_name\":\"International Mobile Equipment Identity\"} - ]," - elif [ "$sim_status" = "unknown" ]; then - sim_info="\"sim_info\":[ - {\"SIM Status\":\"$sim_status\", \"full_name\":\"SIM Status\"} - ]," - else - sim_info="\"sim_info\":[ - {\"SIM Status\":\"$sim_status\", \"full_name\":\"SIM Status\"}, - {\"SIM Slot\":\"$sim_slot\", \"full_name\":\"SIM Slot\"}, - {\"IMEI\":\"$imei\", \"full_name\":\"International Mobile Equipment Identity\"}, - {\"IMSI\":\"$imsi\", \"full_name\":\"International Mobile Subscriber Identity\"}, - {\"ICCID\":\"$iccid\", \"full_name\":\"Integrate Circuit Card Identity\"} - ]," - fi -} - -#设置网络信息 -set_network_info() -{ - network_info="\"network_info\":[ - {\"Network Type\":\"$network_type\", \"full_name\":\"Network Type\"}, - {\"CQI UL\":\"$cqi_ul\", \"full_name\":\"Channel Quality Indicator for Uplink\"}, - {\"CQI DL\":\"$cqi_dl\", \"full_name\":\"Channel Quality Indicator for Downlink\"}, - {\"AMBR UL\":\"$ambr_ul\", \"full_name\":\"Access Maximum Bit Rate for Uplink\"}, - {\"AMBR DL\":\"$ambr_dl\", \"full_name\":\"Access Maximum Bit Rate for Downlink\"}, - {\"Tx Rate\":\"$tx_rate\", \"full_name\":\"Transmit Rate\"}, - {\"Rx Rate\":\"$rx_rate\", \"full_name\":\"Receive Rate\"} - ]," -} - -#设置信号信息 -set_cell_info() -{ - if [ "$network_mode" = "NR5G-SA Mode" ]; then - cell_info="\"cell_info\":{ - \"NR5G-SA Mode\":[ - {\"MCC\":\"$nr_mcc\", \"full_name\":\"Mobile Country Code\"}, - {\"MNC\":\"$nr_mnc\", \"full_name\":\"Mobile Network Code\"}, - {\"Duplex Mode\":\"$nr_duplex_mode\", \"full_name\":\"Duplex Mode\"}, - {\"Cell ID\":\"$nr_cell_id\", \"full_name\":\"Cell ID\"}, - {\"Physical Cell ID\":\"$nr_physical_cell_id\", \"full_name\":\"Physical Cell ID\"}, - {\"TAC\":\"$nr_tac\", \"full_name\":\"Tracking area code of cell servedby neighbor Enb\"}, - {\"ARFCN\":\"$nr_arfcn\", \"full_name\":\"Absolute Radio-Frequency Channel Number\"}, - {\"Band\":\"$nr_band\", \"full_name\":\"Band\"}, - {\"DL Bandwidth\":\"$nr_dl_bandwidth\", \"full_name\":\"DL Bandwidth\"}, - {\"RSRP\":\"$nr_rsrp\", \"full_name\":\"Reference Signal Received Power\"}, - {\"RSRQ\":\"$nr_rsrq\", \"full_name\":\"Reference Signal Received Quality\"}, - {\"SINR\":\"$nr_sinr\", \"full_name\":\"Signal to Interference plus Noise Ratio Bandwidth\"}, - {\"RxLev\":\"$nr_rxlev\", \"full_name\":\"Received Signal Level\"}, - {\"SCS\":\"$nr_scs\", \"full_name\":\"SCS\"}, - {\"Srxlev\":\"$nr_srxlev\", \"full_name\":\"Serving Cell Receive Level\"} - ] - }" - elif [ "$network_mode" = "EN-DC Mode" ]; then - cell_info="\"cell_info\":{ - \"EN-DC Mode\":[ - {\"LTE\":[ - {\"MCC\":\"$endc_lte_mcc\", \"full_name\":\"Mobile Country Code\"}, - {\"MNC\":\"$endc_lte_mnc\", \"full_name\":\"Mobile Network Code\"}, - {\"Duplex Mode\":\"$endc_lte_duplex_mode\", \"full_name\":\"Duplex Mode\"}, - {\"Cell ID\":\"$endc_lte_cell_id\", \"full_name\":\"Cell ID\"}, - {\"Physical Cell ID\":\"$endc_lte_physical_cell_id\", \"full_name\":\"Physical Cell ID\"}, - {\"EARFCN\":\"$endc_lte_earfcn\", \"full_name\":\"E-UTRA Absolute Radio Frequency Channel Number\"}, - {\"Freq band indicator\":\"$endc_lte_freq_band_ind\", \"full_name\":\"Freq band indicator\"}, - {\"Band\":\"$endc_lte_band\", \"full_name\":\"Band\"}, - {\"UL Bandwidth\":\"$endc_lte_ul_bandwidth\", \"full_name\":\"UL Bandwidth\"}, - {\"DL Bandwidth\":\"$endc_lte_dl_bandwidth\", \"full_name\":\"DL Bandwidth\"}, - {\"TAC\":\"$endc_lte_tac\", \"full_name\":\"Tracking area code of cell servedby neighbor Enb\"}, - {\"RSRP\":\"$endc_lte_rsrp\", \"full_name\":\"Reference Signal Received Power\"}, - {\"RSRQ\":\"$endc_lte_rsrq\", \"full_name\":\"Reference Signal Received Quality\"}, - {\"RSSI\":\"$endc_lte_rssi\", \"full_name\":\"Received Signal Strength Indicator\"}, - {\"SINR\":\"$endc_lte_sinr\", \"full_name\":\"Signal to Interference plus Noise Ratio Bandwidth\"}, - {\"RxLev\":\"$endc_lte_rxlev\", \"full_name\":\"Received Signal Level\"}, - {\"RSSNR\":\"$endc_lte_rssnr\", \"full_name\":\"Radio Signal Strength Noise Ratio\"}, - {\"CQI\":\"$endc_lte_cql\", \"full_name\":\"Channel Quality Indicator\"}, - {\"TX Power\":\"$endc_lte_tx_power\", \"full_name\":\"TX Power\"}, - {\"Srxlev\":\"$endc_lte_srxlev\", \"full_name\":\"Serving Cell Receive Level\"} - ] - }, - - {\"NR5G-NSA\":[ - {\"MCC\":\"$endc_nr_mcc\", \"full_name\":\"Mobile Country Code\"}, - {\"MNC\":\"$endc_nr_mnc\", \"full_name\":\"Mobile Network Code\"}, - {\"Physical Cell ID\":\"$endc_nr_physical_cell_id\", \"full_name\":\"Physical Cell ID\"}, - {\"ARFCN\":\"$endc_nr_arfcn\", \"full_name\":\"Absolute Radio-Frequency Channel Number\"}, - {\"Band\":\"$endc_nr_band\", \"full_name\":\"Band\"}, - {\"DL Bandwidth\":\"$endc_nr_dl_bandwidth\", \"full_name\":\"DL Bandwidth\"}, - {\"RSRP\":\"$endc_nr_rsrp\", \"full_name\":\"Reference Signal Received Power\"}, - {\"RSRQ\":\"$endc_nr_rsrq\", \"full_name\":\"Reference Signal Received Quality\"}, - {\"SINR\":\"$endc_nr_sinr\", \"full_name\":\"Signal to Interference plus Noise Ratio Bandwidth\"}, - {\"SCS\":\"$endc_nr_scs\", \"full_name\":\"SCS\"} - ] - } - ] - }" - elif [ "$network_mode" = "LTE Mode" ]; then - cell_info="\"cell_info\":{ - \"LTE Mode\":[ - {\"MCC\":\"$lte_mcc\", \"full_name\":\"Mobile Country Code\"}, - {\"MNC\":\"$lte_mnc\", \"full_name\":\"Mobile Network Code\"}, - {\"Duplex Mode\":\"$lte_duplex_mode\", \"full_name\":\"Duplex Mode\"}, - {\"Cell ID\":\"$lte_cell_id\", \"full_name\":\"Cell ID\"}, - {\"Physical Cell ID\":\"$lte_physical_cell_id\", \"full_name\":\"Physical Cell ID\"}, - {\"EARFCN\":\"$lte_earfcn\", \"full_name\":\"E-UTRA Absolute Radio Frequency Channel Number\"}, - {\"Freq band indicator\":\"$lte_freq_band_ind\", \"full_name\":\"Freq band indicator\"}, - {\"Band\":\"$lte_band\", \"full_name\":\"Band\"}, - {\"UL Bandwidth\":\"$lte_ul_bandwidth\", \"full_name\":\"UL Bandwidth\"}, - {\"DL Bandwidth\":\"$lte_dl_bandwidth\", \"full_name\":\"DL Bandwidth\"}, - {\"TAC\":\"$lte_tac\", \"full_name\":\"Tracking area code of cell servedby neighbor Enb\"}, - {\"RSRP\":\"$lte_rsrp\", \"full_name\":\"Reference Signal Received Power\"}, - {\"RSRQ\":\"$lte_rsrq\", \"full_name\":\"Reference Signal Received Quality\"}, - {\"RSSI\":\"$lte_rssi\", \"full_name\":\"Received Signal Strength Indicator\"}, - {\"SINR\":\"$lte_sinr\", \"full_name\":\"Signal to Interference plus Noise Ratio Bandwidth\"}, - {\"RxLev\":\"$lte_rxlev\", \"full_name\":\"RxLev\"}, - {\"RSSNR\":\"$lte_rssnr\", \"full_name\":\"Radio Signal Strength Noise Ratio\"}, - {\"CQI\":\"$lte_cql\", \"full_name\":\"Channel Quality Indicator\"}, - {\"TX Power\":\"$lte_tx_power\", \"full_name\":\"TX Power\"}, - {\"Srxlev\":\"$lte_srxlev\", \"full_name\":\"Serving Cell Receive Level\"} - ] - }" - elif [ "$network_mode" = "WCDMA Mode" ]; then - cell_info="\"cell_info\":{ - \"WCDMA Mode\":[ - {\"MCC\":\"$wcdma_mcc\", \"full_name\":\"Mobile Country Code\"}, - {\"MNC\":\"$wcdma_mnc\", \"full_name\":\"Mobile Network Code\"}, - {\"LAC\":\"$wcdma_lac\", \"full_name\":\"Location Area Code\"}, - {\"Cell ID\":\"$wcdma_cell_id\", \"full_name\":\"Cell ID\"}, - {\"UARFCN\":\"$wcdma_uarfcn\", \"full_name\":\"UTRA Absolute Radio Frequency Channel Number\"}, - {\"PSC\":\"$wcdma_psc\", \"full_name\":\"Primary Scrambling Code\"}, - {\"RAC\":\"$wcdma_rac\", \"full_name\":\"Routing Area Code\"}, - {\"Band\":\"$wcdma_band\", \"full_name\":\"Band\"}, - {\"RSCP\":\"$wcdma_rscp\", \"full_name\":\"Received Signal Code Power\"}, - {\"Ec/Io\":\"$wcdma_ecio\", \"full_name\":\"Ec/Io\"}, - {\"Ec/No\":\"$wcdma_ecno\", \"full_name\":\"Ec/No\"}, - {\"Physical Channel\":\"$wcdma_phych\", \"full_name\":\"Physical Channel\"}, - {\"Spreading Factor\":\"$wcdma_sf\", \"full_name\":\"Spreading Factor\"}, - {\"Slot\":\"$wcdma_slot\", \"full_name\":\"Slot\"}, - {\"Speech Code\":\"$wcdma_speech_code\", \"full_name\":\"Speech Code\"}, - {\"Compression Mode\":\"$wcdma_com_mod\", \"full_name\":\"Compression Mode\"}, - {\"RxLev\":\"$wcdma_rxlev\", \"full_name\":\"RxLev\"} - ] - }" - fi -} - -#以Json格式保存模组信息 -info_to_json() -{ - base_info="\"base_info\":{}," - sim_info="\"sim_info\":{}," - network_info="\"network_info\":{}," - cell_info="\"cell_info\":{}" - - #设置基本信息 - set_base_info - - #判断是否适配 - if [ "$manufacturer" != "unknown" ]; then - #设置SIM卡信息 - set_sim_info - fi - - #判断插卡和连接状态 - if [ "$sim_status" = "ready" ] && [ "$connect_status" = "connect" ]; then - #设置网络信息 - set_network_info - #设置小区信息 - set_cell_info - fi - - #拼接所有信息(不要漏掉最后一个}) - modem_info="{$base_info$modem_info$sim_info$network_info$cell_info}" -} - # echo $ECIO #参考信号接收质量 RSRQ ecio - # echo $ECIO1 #参考信号接收质量 RSRQ ecio1 - # echo $RSCP #参考信号接收功率 RSRP rscp0 - # echo $RSCP1 #参考信号接收功率 RSRP rscp1 - # echo $SINR #信噪比 SINR rv["sinr"] - - # #基站信息 - # echo $COPS_MCC #MCC - # echo $$COPS_MNC #MNC - # echo $LAC #eNB ID - # echo '' #LAC_NUM - # echo $RNC #TAC - # echo '' #RNC_NUM - # echo $CID - # echo '' #CID_NUM - # echo $LBAND - # echo $channel - # echo $PCI - # echo $MODTYPE - # echo $QTEMP - -#获取模组信息 -get_modem_info() -{ - update_time=$(date +"%Y-%m-%d %H:%M:%S") - - debug "检查模组的AT串口" - #获取模块AT串口 - if [ -z "$at_port" ]; then - debug "模组没有AT串口" - return - fi - - #检查模块状态(是否处于重启,重置,串口异常状态) - local at_command="ATI" - local response=$(sh ${SCRIPT_DIR}/modem_at.sh $at_port $at_command) - if [[ "$response" = *"failed"* ]] || [[ "$response" = *"$at_port"* ]]; then - debug "模组AT串口未就绪" - return - fi - - debug "根据模组的制造商获取信息" - #更多信息获取 - case $manufacturer in - "quectel") get_quectel_info "${at_port}" "${platform}" "${define_connect}" ;; - "fibocom") get_fibocom_info "${at_port}" "${platform}" "${define_connect}" ;; - "meig") get_meig_info "${at_port}" "${platform}" "${define_connect}" ;; - "simcom") get_simcom_info "${at_port}" "${platform}" "${define_connect}" ;; - *) debug "未适配该模组" ;; - esac - - #获取更新时间 - update_time=$(date +"%Y-%m-%d %H:%M:%S") -} - -#获取模组数据信息 -# $1:AT串口 -# $2:制造商 -# $3:平台 -# $4:连接定义 -modem_info() -{ - #初值化模组信息 - debug "初值化模组信息" - init_modem_info - debug "初值化模组信息完成" - - #获取模组信息 - at_port="$1" - manufacturer="$2" - platform="$3" - define_connect="$4" - - debug "获取模组信息" - get_modem_info - - #整合模块信息 - info_to_json - echo $modem_info -} - -modem_info "$1" "$2" "$3" "$4" \ No newline at end of file diff --git a/luci-app-modem/root/usr/share/modem/modem_init.sh b/luci-app-modem/root/usr/share/modem/modem_init.sh deleted file mode 100644 index 2a9530e..0000000 --- a/luci-app-modem/root/usr/share/modem/modem_init.sh +++ /dev/null @@ -1,23 +0,0 @@ -#!/bin/sh -# Copyright (C) 2023 Siriling - -#脚本目录 -SCRIPT_DIR="/usr/share/modem" -source "${SCRIPT_DIR}/modem_util.sh" - -#模组配置初始化 -modem_init() -{ - m_log "info" "Clearing all modem configurations" - #清空模组配置 - local modem_count=$(uci -q get modem.@global[0].modem_number) - for i in $(seq 0 $((modem_count-1))); do - #删除该模组的配置 - uci -q del modem.modem${i} - done - uci set modem.@global[0].modem_number=0 - uci commit modem - m_log "info" "All module configurations cleared" -} - -modem_init \ No newline at end of file diff --git a/luci-app-modem/root/usr/share/modem/modem_network_task.sh b/luci-app-modem/root/usr/share/modem/modem_network_task.sh deleted file mode 100755 index 9921f7a..0000000 --- a/luci-app-modem/root/usr/share/modem/modem_network_task.sh +++ /dev/null @@ -1,301 +0,0 @@ -#!/bin/sh -# Copyright (C) 2023 Siriling - -#脚本目录 -SCRIPT_DIR="/usr/share/modem" - -#运行目录 -MODEM_RUNDIR="/var/run/modem" - -#导入组件工具 -source "${SCRIPT_DIR}/modem_debug.sh" - -#重设网络接口 -# $1:AT串口 -# $4:连接定义 -# $5:模组序号 -reset_network_interface() -{ - local at_port="$1" - local define_connect="$2" - local modem_no="$3" - - local interface_name="wwan_5g_${modem_no}" - local interface_name_ipv6="wwan6_5g_${modem_no}" - - #获取IPv4地址 - at_command="AT+CGPADDR=${define_connect}" - local ipv4=$(at ${at_port} ${at_command} | grep "+CGPADDR: " | awk -F',' '{print $2}' | sed 's/"//g') - #输出日志 - # echo "[$(date +"%Y-%m-%d %H:%M:%S")] Get Modem new IPv4 address : ${ipv4}" >> "${MODEM_RUNDIR}/modem${modem_no}_dial.cache" - - #获取DNS地址 - dns=$(fibocom_get_dns ${at_port} ${define_connect}) - local ipv4_dns1=$(echo "${dns}" | jq -r '.dns.ipv4_dns1') - local ipv4_dns2=$(echo "${dns}" | jq -r '.dns.ipv4_dns2') - #输出日志 - echo "[$(date +"%Y-%m-%d %H:%M:%S")] Get Modem IPv4 DNS1: ${ipv4_dns1}" >> "${MODEM_RUNDIR}/modem${modem_no}_dial.cache" - echo "[$(date +"%Y-%m-%d %H:%M:%S")] Get Modem IPv4 DNS2: ${ipv4_dns2}" >> "${MODEM_RUNDIR}/modem${modem_no}_dial.cache" - - #比较的网络接口中的IPv4地址 - local ipv4_config=$(uci -q get network.${interface_name}.ipaddr) - if [ "$ipv4_config" == "$ipv4" ]; then - #输出日志 - echo "[$(date +"%Y-%m-%d %H:%M:%S")] IPv4 address is the same as in the network interface, skip" >> "${MODEM_RUNDIR}/modem${modem_no}_dial.cache" - else - #输出日志 - echo "[$(date +"%Y-%m-%d %H:%M:%S")] Reset network interface ${interface_name}" >> "${MODEM_RUNDIR}/modem${modem_no}_dial.cache" - - #设置静态地址 - uci set network.${interface_name}.proto='static' - uci set network.${interface_name}.ipaddr="${ipv4}" - uci set network.${interface_name}.netmask='255.255.255.0' - uci set network.${interface_name}.gateway="${ipv4%.*}.1" - uci set network.${interface_name}.peerdns='0' - uci -q del network.${interface_name}.dns - uci add_list network.${interface_name}.dns="${ipv4_dns1}" - uci add_list network.${interface_name}.dns="${ipv4_dns2}" - uci commit network - service network reload - - #输出日志 - echo "[$(date +"%Y-%m-%d %H:%M:%S")] Reset network interface successful" >> "${MODEM_RUNDIR}/modem${modem_no}_dial.cache" - fi -} - -#GobiNet拨号 -# $1:AT串口 -# $2:制造商 -# $3:连接定义 -gobinet_dial() -{ - local at_port="$1" - local manufacturer="$2" - local define_connect="$3" - - #激活 - local at_command="AT+CGACT=1,${define_connect}" - #打印日志 - dial_log "${at_command}" "${MODEM_RUNDIR}/modem${modem_no}_dial.cache" - - at "${at_port}" "${at_command}" - - #拨号 - local at_command - if [ "$manufacturer" = "quectel" ]; then - at_command='ATI' - elif [ "$manufacturer" = "fibocom" ]; then - at_command='AT$QCRMCALL=1,3' - elif [ "$manufacturer" = "meig" ]; then - at_command="ATI" - else - at_command='ATI' - fi - - #打印日志 - dial_log "${at_command}" "${MODEM_RUNDIR}/modem${modem_no}_dial.cache" - - at "${at_port}" "${at_command}" -} - -#ECM拨号 -# $1:AT串口 -# $2:制造商 -# $3:连接定义 -ecm_dial() -{ - local at_port="$1" - local manufacturer="$2" - local define_connect="$3" - - #激活 - # local at_command="AT+CGACT=1,${define_connect}" - # #打印日志 - # dial_log "${at_command}" "${MODEM_RUNDIR}/modem${modem_no}_dial.cache" - - # at "${at_port}" "${at_command}" - - #拨号 - at_command - if [ "$manufacturer" = "quectel" ]; then - at_command="AT+QNETDEVCTL=${define_connect},3,1" - elif [ "$manufacturer" = "fibocom" ]; then - at_command="AT+GTRNDIS=1,${define_connect}" - elif [ "$manufacturer" = "meig" ]; then - at_command="AT$QCRMCALL=1,1,${define_connect},2,1" - else - at_command='ATI' - fi - - #打印日志 - dial_log "${at_command}" "${MODEM_RUNDIR}/modem${modem_no}_dial.cache" - - at "${at_port}" "${at_command}" - - sleep 2s -} - -#RNDIS拨号 -# $1:AT串口 -# $2:制造商 -# $3:平台 -# $4:连接定义 -# $5:模组序号 -rndis_dial() -{ - local at_port="$1" - local manufacturer="$2" - local platform="$3" - local define_connect="$4" - local modem_no="$5" - - #手动设置IP(广和通FM350-GL) - if [ "$manufacturer" = "fibocom" ] && [ "$platform" = "mediatek" ]; then - - at_command="AT+CGACT=1,${define_connect}" - #打印日志 - dial_log "${at_command}" "${MODEM_RUNDIR}/modem${modem_no}_dial.cache" - #激活并拨号 - at "${at_port}" "${at_command}" - - sleep 3s - else - #拨号 - ecm_dial "${at_port}" "${manufacturer}" "${define_connect}" - fi -} - -#Modem Manager拨号 -# $1:接口名称 -# $2:连接定义 -modemmanager_dial() -{ - local interface_name="$1" - local define_connect="$2" - - # #激活 - # local at_command="AT+CGACT=1,${define_connect}" - # #打印日志 - # dial_log "${at_command}" "${MODEM_RUNDIR}/modem${modem_no}_dial.cache" - # at "${at_port}" "${at_command}" - - #启动网络接口 - ifup "${interface_name}"; -} - -#检查模组网络连接 -# $1:配置ID -# $2:模组序号 -# $3:拨号模式 -modem_network_task() -{ - local config_id="$1" - local modem_no="$2" - local mode="$3" - - #获取AT串口,制造商,平台,连接定义,接口名称 - local at_port=$(uci -q get modem.modem${modem_no}.at_port) - local manufacturer=$(uci -q get modem.modem${modem_no}.manufacturer) - local platform=$(uci -q get modem.modem${modem_no}.platform) - local define_connect=$(uci -q get modem.modem${modem_no}.define_connect) - local interface_name="wwan_5g_${modem_no}" - local interface_name_ipv6="wwan6_5g_${modem_no}" - - #重载配置(解决AT命令发不出去的问题) - # service modem reload - - #IPv4地址缓存 - local ipv4_cache - - #输出日志 - echo "[$(date +"%Y-%m-%d %H:%M:%S")] Start network task" >> "${MODEM_RUNDIR}/modem${modem_no}_dial.cache" - while true; do - #全局 - local enable_dial=$(uci -q get modem.@global[0].enable_dial) - if [ "$enable_dial" != "1" ]; then - #输出日志 - echo "[$(date +"%Y-%m-%d %H:%M:%S")] The dialing configuration has been disabled, this network task quit" >> "${MODEM_RUNDIR}/modem${modem_no}_dial.cache" - break - fi - #单个模组 - enable=$(uci -q get modem.${config_id}.enable) - if [ "$enable" != "1" ]; then - #输出日志 - echo "[$(date +"%Y-%m-%d %H:%M:%S")] The modem has disabled dialing, this network task quit" >> "${MODEM_RUNDIR}/modem${modem_no}_dial.cache" - break - fi - - #网络连接检查 - local at_command="AT+CGPADDR=${define_connect}" - local ipv4=$(at ${at_port} ${at_command} | grep "+CGPADDR: " | awk -F',' '{print $2}' | sed 's/"//g') - - if [ -z "$ipv4" ]; then - - [ "$mode" = "modemmanager" ] && { - #拨号工具为modemmanager时,不需要重新设置连接定义 - continue - } - - #输出日志 - echo "[$(date +"%Y-%m-%d %H:%M:%S")] Unable to get IPv4 address" >> "${MODEM_RUNDIR}/modem${modem_no}_dial.cache" - echo "[$(date +"%Y-%m-%d %H:%M:%S")] Redefine connect to ${define_connect}" >> "${MODEM_RUNDIR}/modem${modem_no}_dial.cache" - service modem reload - - #输出日志 - echo "[$(date +"%Y-%m-%d %H:%M:%S")] Modem dial" >> "${MODEM_RUNDIR}/modem${modem_no}_dial.cache" - #拨号(针对获取IPv4返回为空的模组) - case "$mode" in - "gobinet") gobinet_dial "${at_port}" "${manufacturer}" "${define_connect}" ;; - "ecm") ecm_dial "${at_port}" "${manufacturer}" "${define_connect}" ;; - "rndis") rndis_dial "${at_port}" "${manufacturer}" "${platform}" "${define_connect}" "${modem_no}" ;; - "modemmanager") modemmanager_dial "${interface_name}" "${define_connect}" ;; - *) ecm_dial "${at_port}" "${manufacturer}" "${define_connect}" ;; - esac - - elif [[ "$ipv4" = *"0.0.0.0"* ]]; then - - #输出日志 - echo "[$(date +"%Y-%m-%d %H:%M:%S")] Modem${modem_no} current IPv4 address : ${ipv4}" >> "${MODEM_RUNDIR}/modem${modem_no}_dial.cache" - - #输出日志 - echo "[$(date +"%Y-%m-%d %H:%M:%S")] Modem dial" >> "${MODEM_RUNDIR}/modem${modem_no}_dial.cache" - #拨号 - case "$mode" in - "gobinet") gobinet_dial "${at_port}" "${manufacturer}" "${define_connect}" ;; - "ecm") ecm_dial "${at_port}" "${manufacturer}" "${define_connect}" ;; - "rndis") rndis_dial "${at_port}" "${manufacturer}" "${platform}" "${define_connect}" "${modem_no}" ;; - "modemmanager") modemmanager_dial "${interface_name}" "${define_connect}" ;; - *) ecm_dial "${at_port}" "${manufacturer}" "${define_connect}" ;; - esac - - elif [ "$ipv4" != "$ipv4_cache" ]; then - - #第一次缓存IP为空时不输出日志 - [ -n "$ipv4_cache" ] && { - #输出日志 - echo "[$(date +"%Y-%m-%d %H:%M:%S")] Modem${modem_no} IPv4 address has changed" >> "${MODEM_RUNDIR}/modem${modem_no}_dial.cache" - } - - #输出日志 - echo "[$(date +"%Y-%m-%d %H:%M:%S")] Modem${modem_no} current IPv4 address : ${ipv4}" >> "${MODEM_RUNDIR}/modem${modem_no}_dial.cache" - - #缓存当前IP - ipv4_cache="${ipv4}" - - #重新设置网络接口(广和通FM350-GL) - if [ "$manufacturer" = "fibocom" ] && [ "$platform" = "mediatek" ]; then - reset_network_interface "${at_port}" "${define_connect}" "${modem_no}" - sleep 3s - fi - - [ "$mode" != "modemmanager" ] && { - #重新启动网络接口 - ifup "${interface_name}" - ifup "${interface_name_ipv6}" - } - fi - sleep 5s - done -} - -modem_network_task "$1" "$2" "$3" \ No newline at end of file diff --git a/luci-app-modem/root/usr/share/modem/modem_scan.sh b/luci-app-modem/root/usr/share/modem/modem_scan.sh index 0e823c8..5eb27d3 100755 --- a/luci-app-modem/root/usr/share/modem/modem_scan.sh +++ b/luci-app-modem/root/usr/share/modem/modem_scan.sh @@ -1,82 +1,286 @@ -#!/bin/sh -# Copyright (C) 2023 Siriling +#/bin/sh -#脚本目录 -SCRIPT_DIR="/usr/share/modem" -source "${SCRIPT_DIR}/modem_util.sh" +action=$1 +config=$2 +slot_type=$3 +modem_support=$(cat /usr/share/modem/modem_support.json) -#获取设备物理地址 -# $1:网络设备或串口 -get_device_physical_path() +source /usr/share/modem/modem_util.sh + +scan() { - local device_name="$(basename "$1")" - local device_path="$(find /sys/class/ -name $device_name)" - local device_physical_path="$(readlink -f $device_path/device/)" - echo "$device_physical_path" -} - -#设置模组配置 -# $1:网络设备 -# $2:网络设备系统路径 -set_modem_config() -{ - local network="$(basename $sys_network)" - local network_path="$(readlink -f $sys_network)" - - #只处理最上级的网络设备 - local count=$(echo "${network_path}" | grep -o "/net" | wc -l) - [ "$count" -ge "2" ] && return - - #判断路径是否带有usb(排除其他eth网络设备) - if [[ "$network" = *"eth"* ]] && [[ "$network_path" != *"usb"* ]]; then - return - fi - - #获取物理路径 - local device_physical_path=$(m_get_device_physical_path ${network_path}) - #设置物理设备 - m_set_physical_device "scan" "${network}" "${device_physical_path}" - - #启用拨号 - enable_dial "${network}" -} - -#设置系统网络设备 -# $1:系统网络设备列表 -set_sys_network_config() -{ - local sys_networks="$1" - - for sys_network in $sys_networks; do - local network="$(basename $sys_network)" - set_modem_config "${network}" "${sys_network}" + scan_usb + scan_pcie + #remove duplicate + usb_slots=$(echo $usb_slots | uniq ) + pcie_slots=$(echo $pcie_slots | uniq ) + for slot in $usb_slots; do + slot_type="usb" + add $slot + done + for slot in $pcie_slots; do + slot_type="pcie" + add $slot done } -#设置模组信息 -modem_scan() +scan_usb() { - #模组配置初始化 - sh "${SCRIPT_DIR}/modem_init.sh" - - #发起模组添加事件 - #USB - local sys_network - sys_network="$(find /sys/class/net -name usb*)" #ECM RNDIS NCM - set_sys_network_config "$sys_network" - sys_network="$(find /sys/class/net -name wwan*)" #QMI MBIM - set_sys_network_config "$sys_network" - sys_network="$(find /sys/class/net -name eth*)" #RNDIS - set_sys_network_config "$sys_network" - - #PCIE - sys_network="$(find /sys/class/net -name mhi_hwip*)" #(通用mhi驱动) - set_sys_network_config "$sys_network" - sys_network="$(find /sys/class/net -name rmnet_mhi*)" #(制造商mhi驱动) - set_sys_network_config "$sys_network" - - echo "modem scan complete" + usb_net_device_prefixs="usb eth wwan" + usb_slots="" + for usb_net_device_prefix in $usb_net_device_prefixs; do + usb_netdev=$(ls /sys/class/net | grep -E "${usb_net_device_prefix}") + for netdev in $usb_netdev; do + netdev_path=$(readlink -f "/sys/class/net/$netdev/device/") + [ -z "$netdev_path" ] && continue + [ -z "$(echo $netdev_path | grep usb)" ] && continue + usb_slot=$(basename $(dirname $netdev_path)) + echo "netdev_path: $netdev_path usb slot: $usb_slot" + [ -z "$usb_slots" ] && usb_slots="$usb_slot" || usb_slots="$usb_slots $usb_slot" + done + done } -#测试时打开 -# modem_scan \ No newline at end of file +scan_pcie() +{ + #not implemented + echo "scan_pcie" +} + +scan_usb_slot_interfaces() +{ + local slot=$1 + local slot_path="/sys/bus/usb/devices/$slot" + net_devices="" + tty_devices="" + [ ! -d "$slot_path" ] && return + local slot_interfaces=$(ls $slot_path | grep -E "$slot:[0-9]\.[0-9]+") + for interface in $slot_interfaces; do + unset device + unset ttyUSB_device + unset ttyACM_device + interface_driver_path="$slot_path/$interface/driver" + [ ! -d "$interface_driver_path" ] && continue + interface_driver=$(basename $(readlink $interface_driver_path)) + [ -z "$interface_driver" ] && continue + case $interface_driver in + option|\ + usbserial) + ttyUSB_device=$(ls "$slot_path/$interface/" | grep ttyUSB) + ttyACM_device=$(ls "$slot_path/$interface/" | grep ttyACM) + [ -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" + ;; + qmi_wwan*|\ + cdc_mbim|\ + cdc_ncm|\ + cdc_ether|\ + rndis_host) + net_path="$slot_path/$interface/net" + [ ! -d "$net_path" ] && continue + device=$(ls $net_path) + [ -z "$net_devices" ] && net_devices="$device" || net_devices="$net_devices $device" + ;; + esac + done + echo "net_devices: $net_devices tty_devices: $tty_devices" + at_ports="$tty_devices" + validate_at_port +} + +validate_at_port() +{ + valid_at_ports="" + for at_port in $at_ports; do + dev_path="/dev/$at_port" + [ ! -e "$dev_path" ] && continue + res=$(at $dev_path "AT") + [ -z "$res" ] && continue + [ "$res" == *"No"* ] && [ "$res" == *"failed"* ] && continue #for sms_tools No response from modem + valid_at_port="$at_port" + [ -z "$valid_at_ports" ] && valid_at_ports="$valid_at_port" || valid_at_ports="$valid_at_ports $valid_at_port" + done +} + +match_config() +{ + local name=$(echo $1 | sed 's/\r//g' | tr 'A-Z' 'a-z') + [[ "$name" = *"nl678"* ]] && name="nl678" + + [[ "$name" = *"em120k"* ]] && name="em120k" + + #FM350-GL-00 5G Module + [[ "$name" = *"fm350-gl"* ]] && name="fm350-gl" + + #RM500U-CNV + [[ "$name" = *"rm500u-cn"* ]] && name="rm500u-cn" + + [[ "$name" = *"rm500u-ea"* ]] && name="rm500u-ea" + + #rg200u-cn + [[ "$name" = *"rg200u-cn"* ]] && name="rg200u-cn" + + modem_config=$(echo $modem_support | jq '.modem_support."'$slot_type'"."'$name'"') + [ "$modem_config" == "null" ] && return + modem_name=$name + manufacturer=$(echo $modem_config | jq -r ".manufacturer") + platform=$(echo $modem_config | jq -r ".platform") + define_connect=$(echo $modem_config | jq -r ".define_connect") + modes=$(echo $modem_config | jq -r ".modes[]") +} + +get_modem_model() +{ + local at_port=$1 + cgmm=$(at $at_port "AT+CGMM") + cgmm_1=$(at $at_port "AT+CGMM?") + name_1=$(echo -e "$cgmm" |grep "+CGMM: " | awk -F': ' '{print $2}') + name_2=$(echo -e "$cgmm_1" |grep "+CGMM: " | awk -F'"' '{print $2} '| cut -d ' ' -f 1) + name_3=$(echo -e "$cgmm" | sed -n '2p') + modem_name="" + [ -n "$name_1" ] && match_config "$name_1" + [ -n "$name_2" ] && [ -z "$modem_name" ] && match_config "$name_2" + [ -n "$name_3" ] && [ -z "$modem_name" ] && match_config "$name_3" + [ -z "$modem_name" ] && return 1 + return 0 +} + +add() +{ + local slot=$1 + lock -n /tmp/lock/modem_add_$slot + [ $? -eq 1 ] && return + #slot_type is usb or pcie + #section name is replace slot .:- with _ + section_name=$(echo $slot | sed 's/[\.:-]/_/g') + is_exist=$(uci get modem.$section_name) + case $slot_type in + "usb") + scan_usb_slot_interfaces $slot + ;; + "pcie") + #not implemented + ;; + esac + for at_port in $valid_at_ports; do + get_modem_model "/dev/$at_port" + [ $? -eq 0 ] && break + done + [ -z "$modem_name" ] && lock -u /tmp/lock/modem_add_$slot && return + m_debug "add modem $modem_name slot $slot slot_type $slot_type" + if [ -n "$is_exist" ]; then + #network at_port state name 不变,则不需要重启网络 + orig_network=$(uci get modem.$section_name.network) + orig_at_port=$(uci get modem.$section_name.at_port) + orig_state=$(uci get modem.$section_name.state) + orig_name=$(uci get modem.$section_name.name) + uci del modem.$section_name.modes + uci del modem.$section_name.valid_at_ports + uci del modem.$section_name.tty_devices + uci del modem.$section_name.net_devices + uci del modem.$section_name.ports + uci set modem.$section_name.state="enabled" + else + #aqcuire lock + lock /tmp/lock/modem_add + modem_count=$(uci get modem.@global[0].modem_count) + [ -z "$modem_count" ] && modem_count=0 + modem_count=$(($modem_count+1)) + uci set modem.@global[0].modem_count=$modem_count + uci set modem.$section_name=modem-device + uci commit modem + lock -u /tmp/lock/modem_add + #release lock + metric=$(($modem_count+10)) + uci batch << EOF +set modem.$section_name.path="/sys/bus/usb/devices/$slot/" +set modem.$section_name.data_interface="$slot_type" +set modem.$section_name.enable_dial="1" +set modem.$section_name.pdp_type="ip" +set modem.$section_name.state="enabled" +set modem.$section_name.metric=$metric +EOF + fi + uci batch < - -#脚本目录 -SCRIPT_DIR="/usr/share/modem" -source "${SCRIPT_DIR}/modem_debug.sh" -source "${SCRIPT_DIR}/modem_scan.sh" - -#模组扫描任务 -modem_scan_task() -{ - sleep 8s #刚开机需要等待移动网络出来 - while true; do - enable_dial=$(uci -q get modem.@global[0].enable_dial) - if [ "$enable_dial" = "1" ]; then - #扫描模块 - debug "开启模块扫描任务" - modem_scan - debug "结束模块扫描任务" - fi - sleep 10s - done -} - -modem_scan_task \ No newline at end of file diff --git a/luci-app-modem/root/usr/share/modem/modem_util.sh b/luci-app-modem/root/usr/share/modem/modem_util.sh index 0e36048..d81fb88 100755 --- a/luci-app-modem/root/usr/share/modem/modem_util.sh +++ b/luci-app-modem/root/usr/share/modem/modem_util.sh @@ -1,951 +1,114 @@ #!/bin/sh -# Copyright (C) 2023 Siriling +# Copyright (C) 2024 Tom -#脚本目录 -SCRIPT_DIR="/usr/share/modem" - -#运行目录 -MODEM_RUNDIR="/var/run/modem" -MODEM_PID_FILE="${MODEM_RUNDIR}/modem.pid" -MODEM_CDC_WDM_CACHE="${MODEM_RUNDIR}/cdc_wdm.cache" -MODEM_PHYSICAL_DEVICE_CACHE="${MODEM_RUNDIR}/physical_device.cache" -MODEM_EVENTS_CACHE="${MODEM_RUNDIR}/events.cache" - -#导入组件工具 -source "/lib/functions.sh" -source "/lib/netifd/netifd-proto.sh" -source "${SCRIPT_DIR}/modem_debug.sh" - -#日志 -# $1:日志等级 -m_log() +at() { - local level="$1"; - logger -p "daemon.${level}" -t "Modem[$$]" "hotplug: $*" + local at_port=$1 + local new_str="${2/[$]/$}" + local atcmd="${new_str/\"/\"}" + sms_tool -d $at_port at "$atcmd" } -#生成16进制数 -generate_hex() { - echo "$(openssl rand -hex 1)" -} - -#生成随机MAC地址 -generate_mac_address() { - local mac="" - for i in $(seq 1 6); do - mac="${mac}$(generate_hex)" - if [[ $i != 6 ]]; then - mac="${mac}:" - fi - done - echo "$mac" -} - -#上报USB事件 -# $1:事件行为(add,remove,bind) -# $2:类型 -# $3:名称或设备ID -# $4:路径 -m_report_event() +log2file() { - local action="$1" - local type="$2" - local name="$3" - local physical_path="$4" - - #缓存事件信息 - echo "${action},${type},${name},${physical_path}" >> "${MODEM_EVENTS_CACHE}" - #输出事件处理日志 - m_log "debug" "event reported: action=${action}, type=${type}, name=${name}" -} - -#模组预设 -# $1:AT串口 -# $2:连接定义 -m_modem_presets() -{ - local at_port="$1" - local define_connect="$2" - - #运营商选择设置 - local at_command='AT+COPS=0,0' - at "${at_port}" "${at_command}" - - #设置IPv6地址格式 - at_command='AT+CGPIAF=1,0,0,0' - at "${at_port}" "${at_command}" - - #PDP设置 - at_command="AT+CGDCONT=${define_connect},\"IPV4V6\",\"\"" - at "${at_port}" "${at_command}" -} - -#获取设备物理路径 -# $1:网络设备路径 -m_get_device_physical_path() -{ - local tmp_path="$1" - - while true; do - tmp_path=$(dirname "${tmp_path}") - - #跳出循环条件 - [ -z "${tmp_path}" ] || [ "${tmp_path}" = "/" ] && return - - #USB设备 - [ -f "${tmp_path}"/idVendor ] && [ -f "${tmp_path}"/idProduct ] && { - tmp_path=$(readlink -f "$tmp_path") - echo "${tmp_path}" - return - } - - #PCIE设备 - [ -f "${tmp_path}"/vendor ] && [ -f "${tmp_path}"/device ] && { - tmp_path=$(readlink -f "$tmp_path") - echo "${tmp_path}" - return - } - done -} - -#删除物理路径状态 -# $1:设备物理路径 -m_del_physical_path_status() -{ - # local network="$1" - local physical_path="$1" - - #删除网络设备 - # [ -f "${MODEM_PHYSICAL_DEVICE_CACHE}" ] && { - # #删除 - # sed -i "/${network}/d" "${MODEM_PHYSICAL_DEVICE_CACHE}" - # } - - #通过物理路径删除 - local escaped_physical_path - [ -f "${MODEM_PHYSICAL_DEVICE_CACHE}" ] && { - # escape '/', '\' and '&' for sed... - escaped_physical_path=$(echo "$physical_path" | sed -e 's/[\/&]/\\&/g') - #删除 - sed -i "/${escaped_physical_path}/d" "${MODEM_PHYSICAL_DEVICE_CACHE}" - } -} - -#获取设备物理路径状态 -# $1:设备物理路径 -m_get_physical_path_status() -{ - local physical_path="$1" - - [ -f "${MODEM_PHYSICAL_DEVICE_CACHE}" ] || return - - #获取状态(不包含注释并且包含physical_path的行,获取以,分割的第二个字符串) - awk -v physical_path="${physical_path}" -F',' '!/^#/ && $0 ~ physical_path { print $2 }' "${MODEM_PHYSICAL_DEVICE_CACHE}" -} - -#设置设备物理路径状态 -# $1:设备物理路径 -# $2:状态 -m_set_physical_path_status() -{ - local physical_path="$1" - local status="$2" - - #删除物理路径状态 - m_del_physical_path_status "${physical_path}" - - #缓存物理路径状态 - echo "${physical_path},${status}" >> "${MODEM_PHYSICAL_DEVICE_CACHE}" -} - -#缓存cdc-wdm -# $1:网络设备 -m_cdc_wdm_cache() -{ - local network="$1" - - #获取cdc-wdm - local cdc_wdm=$(ls "/sys/class/net/${network}/device/usbmisc/") - [ -z "${cdc_wdm}" ] && return - - #缓存 - echo "${network},${cdc_wdm}" >> "${MODEM_CDC_WDM_CACHE}" - - echo "${cdc_wdm}" -} - -#取消缓存cdc-wdm -# $1:网络设备 -m_cdc_wdm_del_cache() -{ - local wwan="$1" - - [ -f "${MODEM_CDC_WDM_CACHE}" ] || return - - #获取cdc-wdm(不包含注释并且包含network的行,获取以,分割的第二个字符串) - local cdc_wdm=$(awk -v network="${network}" -F',' '!/^#/ && $0 ~ network { print $2 }' "${MODEM_CDC_WDM_CACHE}") - [ -n "${cdc_wdm}" ] || return - - #取消缓存 - sed -i "/${network},${cdc_wdm}/d" "${MODEM_CDC_WDM_CACHE}" - - echo "${cdc_wdm}" -} - -#cdc-wdm处理 -# $1:事件行为(add,remove,bind) -# $2:名称 -# $3:路径 -m_cdc_wdm() -{ - local action="$1" - local name="$2" - local physical_path="$4" - - #获取cdc-wdm - local cdc_wdm="" - #操作缓存 - case "${action}" in - "add") cdc_wdm=$(m_cdc_wdm_cache "${name}") ;; - "remove") cdc_wdm=$(m_cdc_wdm_del_cache "${name}") ;; - esac - - if [ -n "${cdc_wdm}" ]; then - #输出cdc-wdm事件处理日志 - m_log "${action} cdc interface ${cdc_wdm}: cdc-wdm event processed" - #上报cdc-wdm事件 - m_report_event "${action}" "usbmisc" "${cdc_wdm}" "/sys${physical_path}" - fi -} - -#添加USB模组ID -# $1:制造商ID -# $2:产品ID -m_add_usb_id() -{ - local manufacturer_id="$1" - local product_id="$2" - - local new_id_path="/sys/bus/usb-serial/drivers/generic/new_id" - - #如果已经添加则返回 - grep -q "${manufacturer_id} ${product_id}" "${new_id_path}" && return - - while true; do - if [ -f "$new_id_path" ]; then - #添加ID - echo "${manufacturer_id} ${product_id}" >> "${new_id_path}" - break - fi - sleep 5s - done -} - -#设置模组硬件配置 -# $1:物理路径 -m_set_modem_hardware_config() -{ - local physical_path="$1" - - #获取设备数据接口 - local data_interface - if [[ "$physical_path" = *"usb"* ]]; then - data_interface="usb" - else - data_interface="pcie" - fi - - # [ "$data_interface" = "usb" ] && { - # #不存在网络接口 - # local net_count="$(find ${physical_path} -name net | wc -l)" - # if [ "$net_count" -le "0" ]; then - # #撤销 - # uci revert modem - # return - # fi - # } - - #是否是第一次添加(初始化模组) - local count=$(grep -o "processed" ${MODEM_PHYSICAL_DEVICE_CACHE} | wc -l) - #是否开启手动配置 - local manual_configuration=$(uci -q get modem.@global[0].manual_configuration) - [ "$count" = "0" ] && [ "$manual_configuration" = "0" ] && { - #模组配置初始化 - sh "${SCRIPT_DIR}/modem_init.sh" - } - - #设置物理路径状态 - m_set_physical_path_status "${physical_path}" "processed" - - #获取模组序号 - local modem_no=$(uci -q get modem.@global[0].modem_number) - #增加模组计数 - local modem_number=$((modem_no + 1)) - uci set modem.@global[0].modem_number="${modem_number}" - - #设置模组硬件配置 - uci set modem.modem${modem_no}="modem-device" - uci set modem.modem${modem_no}.data_interface="${data_interface}" - uci set modem.modem${modem_no}.path="${physical_path}" - - uci commit modem -} - -#删除模组配置 -# $1:物理路径 -m_del_modem_config() -{ - local physical_path="$1" - - #获取模组数量 - local modem_number=$(uci -q get modem.@global[0].modem_number) - #获取模组序号 - local modem_no - for i in $(seq 0 $((modem_number-1))); do - local modem_path=$(uci -q get modem.modem${i}.path) - if [ "$modem_path" = "$physical_path" ]; then - modem_no="$i" - break - fi - done - - [ -z "$modem_no" ] && return - - #删除该模组的配置 - uci -q del modem.modem${modem_no} - uci -q set modem.@global[0].modem_number=$((modem_number-1)) - uci commit modem - - #删除物理路径状态 - m_del_physical_path_status "${physical_path}" + local subject="$1" + local msg="$2" + local path="$3" #打印日志 - m_log "info" "Modem${modem_no} (${physical_path}) removed" + local update_time=$(date +"%Y-%m-%d %H:%M:%S") + echo "[${update_time}] ${subject}:${msg} " >> "${path}" } -#设置USB设备 -# $1:事件行为(add,remove,bind) -# $2:制造商ID -# $3:产品ID -# $4:物理路径 -m_set_usb_device() +log2sys() { - local action="$1" - local manufacturer_id="$2" - local product_id="$3" - local physical_path="$4" - - if [ "$action" = "add" ]; then - #添加USB模组ID - m_add_usb_id "${manufacturer_id}" "${product_id}" - - #设置模组配置 - # m_set_modem_hardware_config "${physical_path}" - - elif [ "$action" = "remove" ]; then - - #手动配置 - local manual_configuration=$(uci -q get modem.@global[0].manual_configuration) - [ "${manual_configuration}" = "1" ] && return - - #删除模组配置 - m_del_modem_config "${physical_path}" - fi + local subject="$1" + local msg="$2" + logger -t "$subject" "$msg" } -#处理特殊的模组名称 -# $1:模组名称 -handle_special_modem_name() +m_debug () { - local modem_name="$1" - - #FM350-GL-00 5G Module - [[ "$modem_name" = *"fm350-gl"* ]] && { - modem_name="fm350-gl" - } - - #RM500U-CNV - [[ "$modem_name" = *"rm500u-cn"* ]] && { - modem_name="rm500u-cn" - } - - echo "$modem_name" -} - -#重新尝试设置模组 -# $1:模组序号 -# $2:AT串口 -# $3:模组支持列表 -retry_set_modem_config() -{ - local modem_no="$1" - local at_port="$2" - local modem_support="$3" - - local time=0 - while true; do - - #打印日志 - m_log "info" "Try again to configure the Modem${modem_no}" - - [ "$time" = "2" ] && break - - #获取模组名称 - local at_command="AT+CGMM?" - local modem_name=$(at ${at_port} ${at_command} | grep "+CGMM: " | awk -F'"' '{print $2}' | tr 'A-Z' 'a-z') - - #再一次获取模组名称 - [ -z "$modem_name" ] && { - at_command="AT+CGMM" - modem_name=$(at ${at_port} ${at_command} | grep "+CGMM: " | awk -F': ' '{print $2}' | sed 's/\r//g' | tr 'A-Z' 'a-z') - } - - #再一次获取模组名称 - [ -z "$modem_name" ] && { - at_command="AT+CGMM" - modem_name=$(at ${at_port} ${at_command} | sed -n '2p' | sed 's/\r//g' | tr 'A-Z' 'a-z') - } - - #处理特殊的模组名称 - [ -n "$modem_name" ] && { - modem_name="$(handle_special_modem_name ${modem_name})" - } - - - #获取模组信息 - local data_interface=$(uci -q get modem.modem${modem_no}.data_interface) - local modem_info=$(echo ${modem_support} | jq '.modem_support.'$data_interface'."'$modem_name'"') - - [ -n "$modem_name" ] && [ "$modem_info" != "null" ] && { - - #获取制造商 - local manufacturer=$(echo ${modem_info} | jq -r '.manufacturer') - #获取平台 - local platform=$(echo ${modem_info} | jq -r '.platform') - #获取连接定义 - local define_connect=$(echo ${modem_info} | jq -r '.define_connect') - #获取支持的拨号模式 - local modes=$(echo ${modem_info} | jq -r '.modes[]') - - uci set modem.modem${modem_no}.name="${modem_name}" - uci set modem.modem${modem_no}.manufacturer="${manufacturer}" - uci set modem.modem${modem_no}.platform="${platform}" - uci set modem.modem${modem_no}.define_connect="${define_connect}" - uci set modem.modem${modem_no}.enable_dial=1 - uci set modem.modem${modem_no}.pdp_type="ipv4v6" - uci -q del modem.modem${modem_no}.modes #删除原来的拨号模式列表 - for mode in $modes; do - uci add_list modem.modem${modem_no}.modes="${mode}" - done - - #设置模组预设 - m_modem_presets "${at_port}" "${define_connect}" - #打印日志 - m_log "info" "Successfully retrying to configure the Modem ${modem_name}" - - break - } - - time=$((time+1)) - sleep 5s - done -} - -#设置模组配置 -# $1:模组序号 -# $2:物理路径 -m_set_modem_config() -{ - local modem_no="$1" - local physical_path="$2" - - #获取AT串口 - local at_port=$(uci -q get modem.modem${modem_no}.at_port) - - #获取模组名称 - local modem_name=$(uci -q get modem.modem${modem_no}.name) - if [ "$modem_name" == "unknown" ]; then - #返回空 - modem_name="" - fi - [ -z "$modem_name" ] && { - local at_command="AT+CGMM?" - modem_name=$(at ${at_port} ${at_command} | grep "+CGMM: " | awk -F'"' '{print $2}' | tr 'A-Z' 'a-z' |cut -d ' ' -f 1) - logger -t modem_ttl "try_1_get_modem_name: ${modem_name}" - } - - #再一次获取模组名称 - [ -z "$modem_name" ] && { - at_command="AT+CGMM" - modem_name=$(at ${at_port} ${at_command} | grep "+CGMM: " | awk -F': ' '{print $2}' | sed 's/\r//g' | tr 'A-Z' 'a-z') - logger -t modem_ttl "try_2_get_modem_name: ${modem_name}" - } - - #再一次获取模组名称 - [ -z "$modem_name" ] && { - at_command="AT+CGMM" - modem_name=$(at ${at_port} ${at_command} | sed -n '2p' | sed 's/\r//g' | tr 'A-Z' 'a-z') - logger -t modem_ttl "try_3_get_modem_name: ${modem_name}" - } - - #处理特殊的模组名称 - [ -n "$modem_name" ] && { - logger -t modem_ttl "handle_special_modem_name: ${modem_name}" - modem_name="$(handle_special_modem_name ${modem_name})" - } - - #获取模组支持列表 - local modem_support=$(cat ${SCRIPT_DIR}/modem_support.json) - #获取模组信息 - local data_interface=$(uci -q get modem.modem${modem_no}.data_interface) - local modem_info=$(echo ${modem_support} | jq '.modem_support.'$data_interface'."'$modem_name'"') - - local manufacturer - local platform - local define_connect - local modes - local log_message - if [ -z "$modem_name" ] || [ "$modem_info" = "null" ]; then - modem_name="unknown" - manufacturer="unknown" - platform="unknown" - define_connect="1" - modes="qmi gobinet ecm mbim rndis ncm" - #设置日志信息 - log_message="An unknown Modem${modem_no} (${physical_path}) was found" + [ -z "$debug_subject" ] && subject="modem_util" || subject="$debug_subject" + [ -n "$direct_debug" ] && echo "$subject" "$1" + if [ -n "$log_file" ];then + logger -t "$subject" "$1" + log2file "$subject" "$1" "$log_file" else - #获取制造商 - manufacturer=$(echo ${modem_info} | jq -r '.manufacturer') - #获取平台 - platform=$(echo ${modem_info} | jq -r '.platform') - #获取连接定义 - define_connect=$(echo ${modem_info} | jq -r '.define_connect') - #获取支持的拨号模式 - modes=$(echo ${modem_info} | jq -r '.modes[]') - #设置日志信息 - log_message="Configuration Modem${modem_no} ${modem_name} (${physical_path}) successful" + log2sys "$subject" "$1" fi - - uci set modem.modem${modem_no}.name="${modem_name}" - uci set modem.modem${modem_no}.manufacturer="${manufacturer}" - uci set modem.modem${modem_no}.define_connect="${define_connect}" - uci set modem.modem${modem_no}.platform="${platform}" - uci set modem.modem${modem_no}.enable_dial=1 - uci set modem.modem${modem_no}.pdp_type="ipv4v6" - uci -q del modem.modem${modem_no}.modes #删除原来的拨号模式列表 - for mode in $modes; do - uci add_list modem.modem${modem_no}.modes="${mode}" - done - #设置模组预设 - m_modem_presets "${at_port}" "${define_connect}" - - #打印日志 - m_log "info" "${log_message}" - - #重新尝试设置模组 - [ "$modem_name" = "unknown" ] && { - retry_set_modem_config "${modem_no}" "${at_port}" "${modem_support}" - } } -#设置USB AT串口 -# $1:模组序号 -# $2:串口 -# $3:物理路径 -m_set_usb_at_port() +update_sim_slot() { - local modem_no="$1" - local port="$2" - local physical_path="$3" + . /lib/functions.sh + board=$(board_name) + case $board in + HC,HC-G80*) + sim_pin="/sys/class/gpio/sim/value" + sim_pin_value=$(cat $sim_pin) + [ "$sim_pin_value" == "0" ] && sim_slot="2" || sim_slot="1" + #电平高表示SIM卡在卡槽1,电平低表示SIM卡在卡槽2 + debug "update_sim_slot:sim_slot=$sim_slot" + ;; + huasifei,ws3006) + sim_pin="/sys/class/gpio/dual_sim/value" + #电平高则都在卡槽1,电平低则需要使用at查询 + [ "$(cat $sim_pin)" == "1" ] && sim_slot="1" || at_get_slot + ;; + *) + at_get_slot + ;; + esac +} - local modem_at_port=$(uci -q get modem.modem${modem_no}.at_port) - [ -z "$modem_at_port" ] && { - local response="$(sh ${SCRIPT_DIR}/modem_at.sh ${port} 'ATI')" - local str1="No" #No response from modem. - local str2="failed" - if [[ "$response" != *"$str1"* ]] && [[ "$response" != *"$str2"* ]] && [ -n "$response" ]; then - #原先的AT串口会被覆盖掉(是否需要加判断) - uci set modem.modem${modem_no}.at_port="${port}" +at_get_slot() +{ + case $vendor in + "quectel") + at_res=$(at $at_port AT+QSIMDET? |grep +QSIMDET: |awk -F: '{print $2}') + case "$at_res" in + "1") + sim_slot="1" + ;; + "2") + sim_slot="2" + ;; + *) + sim_slot="1" + ;; + *) + sim_slot="1" + ;; + esac + ;; + "fibocom") + at_res=$(at $at_port AT+GTDUALSIM? |grep +GTDUALSIM: |awk -F: '{print $2}') + case $at_res in + "0") + sim_slot="1" + ;; + "1") + sim_slot="2" + ;; + *) + sim_slot="1" + ;; + *) + sim_slot="1" + ;; + esac + ;; - #设置模组配置 - m_set_modem_config "${modem_no}" "${physical_path}" - uci commit modem - fi - } -} - -#设置PCIE AT串口 -# $1:模组序号 -# $2:串口 -# $3:物理路径 -m_set_pcie_at_port() -{ - local modem_no="$1" - local port="$2" - local physical_path="$3" - - #设置AT串口 - uci set modem.modem${modem_no}.at_port="${port}" - - #设置模组配置 - m_set_modem_config "${modem_no}" "${physical_path}" - uci commit modem -} - -#设置ttyUSB设备 -# $1:事件行为(add,remove,bind) -# $2:物理路径 -m_set_tty_device() -{ - local action="$1" - local physical_path="$2" - - if [ "$action" = "bind" ]; then - - #获取模组数量 - local modem_number=$(uci -q get modem.@global[0].modem_number) - #获取模组序号 - local modem_no - for i in $(seq 0 $((modem_number-1))); do - local modem_path=$(uci -q get modem.modem${i}.path) - if [[ "$physical_path" = *"$modem_path"* ]]; then - modem_no="${i}" - break - fi - done - - [ -z "$modem_no" ] && return - - #获取ttyUSB - local tty_usb=$(find ${physical_path} -type d -name ttyUSB* | sed -n '1p') - #不存在tty,退出 - [ -z "$tty_usb" ] && return - local port="/dev/$(basename ${tty_usb})" - - #添加串口 - uci add_list modem.modem${modem_no}.ports="${port}" - uci commit modem - - #设置AT串口 - m_set_usb_at_port "${modem_no}" "${port}" "${physical_path}" - fi -} - -#检查USB设备 -# $1:事件行为(add,remove,bind) -# $2:设备号 -# $2:设备ID -# $3:物理路径 -m_check_usb_device() -{ - local action="$1" - local device_num="$2" - local device_id="$3" - local physical_path="$4" - - #获取制造商ID - local manufacturer_id=$(echo "$device_id" | awk -F'/' '{printf "%04s", $1}' | tr ' ' '0') - #获取产品ID - local product_id=$(echo "$device_id" | awk -F'/' '{printf "%04s", $2}' | tr ' ' '0') - - #获取模组支持列表 - local modem_support=$(cat ${SCRIPT_DIR}/modem_support.json) - - [[ "$modem_support" = *"$manufacturer_id"* ]] && { - #上报USB事件 - m_report_event "${action}" "usb" "${manufacturer_id}:${product_id}" "${physical_path}" - - if [ -n "$device_num" ]; then - #设置USB设备 - m_set_usb_device "${action}" "${manufacturer_id}" "${product_id}" "${physical_path}" - # else - #设置ttyUSB设备 - # m_set_tty_device "${action}" "${physical_path}" - fi - } -} - -#设置模组网络配置 -# $1:网络设备 -# $2:物理路径 -m_set_network_config() -{ - local network="$1" - local physical_path="$2" - - #获取模组数量 - local modem_number=$(uci -q get modem.@global[0].modem_number) - #获取模组序号 - local modem_no - for i in $(seq 0 $((modem_number-1))); do - local modem_path=$(uci -q get modem.modem${i}.path) - if [ "$modem_path" = "$physical_path" ]; then - modem_no="${i}" - break - fi - done - - #没有模组时跳过 - [ -z "$modem_no" ] && return - - #判断地址是否为net - # local path=$(basename "$physical_path") - # if [ "$path" = "net" ]; then - # return - # fi - - #获取网络接口 - local net_path="$(find ${physical_path} -name net | sed -n '1p')" - local net_net_interface_path="${net_path}" - - #子目录下存在网络接口 - local net_count="$(find ${physical_path} -name net | wc -l)" - if [ "$net_count" = "2" ]; then - net_net_interface_path="$(find ${physical_path} -name net | sed -n '2p')" - fi - local network_interface=$(ls ${net_net_interface_path}) - - #设置模组网络配置 - uci set modem.modem${modem_no}.network="${network}" - uci set modem.modem${modem_no}.network_interface="${network_interface}" - uci commit modem - - #打印日志 - m_log "info" "Configuration Modem${modem_no} Network ${network} (${physical_path}) successful" -} - -#启用拨号 -# $1:网络设备 -enable_dial() -{ - /etc/init.d/modem_network restart -} - -#禁用拨号 -# $1:网络设备 -disable_dial() -{ - /etc/init.d/modem_network restart -} - -#设置模组串口 -# $1:物理路径 -m_set_modem_port() -{ - local physical_path="$1" - - #获取模组数量 - local modem_number=$(uci -q get modem.@global[0].modem_number) - #获取模组序号 - local modem_no - for i in $(seq 0 $((modem_number-1))); do - local modem_path=$(uci -q get modem.modem${i}.path) - if [ "$modem_path" = "$physical_path" ]; then - modem_no="${i}" - break - fi - done - - #没有模组时跳过 - [ -z "$modem_no" ] && return - - #获取当前路径下所有的串口 - local data_interface=$(uci -q get modem.modem${modem_no}.data_interface) - local all_port - if [ "$data_interface" = "usb" ]; then - all_port=$(find ${physical_path} -name ttyUSB*) - else - local mhi_hwip=$(find ${physical_path} -name mhi_hwip*) - if [ -n "$mhi_hwip" ]; then - all_port=$(find ${physical_path} -name wwan*) - all_port=$(echo "$all_port" | sed '1,2d') - else - all_port=$(find ${physical_path} -name mhi_*) - fi - fi - - #不存在串口,返回 - [ -z "${all_port}" ] && return - - #删除原串口 - uci -q del modem.modem${modem_no}.ports - #设置串口 - local port_cache - for port_path in $all_port; do - - local port_tmp="$(basename ${port_path})" - local port="/dev/${port_tmp}" - - #跳过重复的串口 - [ "$port" = "$port_cache" ] && continue - #跳过多余串口(PCIE) - [[ "$port" = *"mhi_uci_q"* ]] && continue - [[ "$port" = *"mhi_cntrl_q"* ]] && continue - - #添加串口 - uci add_list modem.modem${modem_no}.ports="${port}" - uci commit modem - - #设置AT串口 - if [ "$data_interface" = "usb" ]; then - m_set_usb_at_port "${modem_no}" "${port}" "${physical_path}" - elif [[ "$port" = *"at"* ]]; then - m_set_pcie_at_port "${modem_no}" "${port}" "${physical_path}" - elif [[ "$port" = *"DUN"* ]]; then - m_set_pcie_at_port "${modem_no}" "${port}" "${physical_path}" - fi - - #缓存当前串口 - port_cache="${port}" - done -} - -#设置物理设备 -# $1:事件行为(add,remove,bind,scan) -# $2:网络设备 -# $3:物理路径 -m_set_physical_device() -{ - local action="$1" - local network="$2" - local physical_path="$3" - - if [ "$action" = "add" ]; then - - #已经添加过路径,退出 - local physical_path_status=$(m_get_physical_path_status ${physical_path}) - [ "$physical_path_status" = "processed" ] && return - - #设置模组硬件配置 - m_set_modem_hardware_config "${physical_path}" - - #设置模组网络配置 - m_set_network_config "${network}" "${physical_path}" - - #设置模组串口 - m_set_modem_port "${physical_path}" - - elif [ "$action" = "remove" ]; then - #删除模组配置 - m_del_modem_config "${physical_path}" - elif [ "$action" = "scan" ]; then - - #设置模组硬件配置 - m_set_modem_hardware_config "${physical_path}" - - #设置模组网络配置 - m_set_network_config "${network}" "${physical_path}" - - #设置模组串口 - m_set_modem_port "${physical_path}" - fi -} - -#设置网络设备 -# $1:事件行为(add,remove,bind) -# $2:网络设备 -# $3:物理路径 -# $4:数据接口 -m_set_network_device() -{ - local action="$1" - local network="$2" - local network_path="$3" - local data_interface="$4" - - #只处理最上级的网络设备 - local count=$(echo "${network_path}" | grep -o "/net" | wc -l) - [ "$count" -ge "2" ] && return - - #判断路径是否带有usb(排除其他eth网络设备) - if [[ "$network" = *"eth"* ]] && [[ "$network_path" != *"usb"* ]]; then - return - fi - - #上报事件 - m_report_event "${action}" "net" "${network}" "${network_path}" - - #手动配置 - local manual_configuration=$(uci -q get modem.@global[0].manual_configuration) - [ "${manual_configuration}" = "1" ] && return - - if [ "$action" = "add" ]; then - - if [ "$data_interface" = "usb" ]; then - #获取物理路径 - local device_physical_path=$(m_get_device_physical_path ${network_path}) - #设置USB网络设备 - # m_set_network_config "${network}" "${device_physical_path}" - #设置物理设备 - m_set_physical_device "${action}" "${network}" "${device_physical_path}" - else - #获取物理路径 - local device_physical_path=$(m_get_device_physical_path ${network_path}) - #设置物理设备 - m_set_physical_device "${action}" "${network}" "${device_physical_path}" - fi - #启用拨号 - # sleep 60s - enable_dial "${network}" - - elif [ "$action" = "remove" ]; then - - #USB设备通过USB事件删除 - [ "$data_interface" = "pcie" ] && { - #获取物理路径 - local device_physical_path=$(m_get_device_physical_path ${network_path}) - #设置物理设备 - m_set_physical_device "${action}" "${network}" "${device_physical_path}" - } - - #停止拨号 - # disable_dial "${network}" - - #打印日志 - m_log "info" "Network ${network} (${network_path}) removed" - fi -} - -#测试Net热插拔 -test_net_hotplug() -{ - echo ACTION:"$ACTION" >> /root/test - echo DEVICENAME:"$DEVICENAME" >> /root/test - echo PATH:"$PATH" >> /root/test - echo DEVPATH:"$DEVPATH" >> /root/test - echo DEVTYPE:"$DEVTYPE" >> /root/test - echo INTERFACE:"$INTERFACE" >> /root/test - echo PRODUCT:"$PRODUCT" >> /root/test -} - -#测试USB热插拔 -test_usb_hotplug() -{ - echo ACTION:"$ACTION" >> /root/test - echo DEVICENAME:"$DEVICENAME" >> /root/test - echo DEVPATH:"$DEVPATH" >> /root/test - echo DEVNUM:"$DEVNUM" >> /root/test - echo DRIVER:"$DRIVER" >> /root/test - echo TYPE:"$TYPE" >> /root/test - echo PRODUCT:"$PRODUCT" >> /root/test - echo SEQNUM:"$SEQNUM" >> /root/test - echo BUSNUM:"$BUSNUM" >> /root/test - echo MAJOR:"$MAJOR" >> /root/test - echo MINOR:"$MINOR" >> /root/test -} - -#测试tty热插拔 -test_tty_hotplug() -{ - echo ACTION:"$ACTION" >> /root/test - echo DEVICENAME:"$DEVICENAME" >> /root/test - echo DEVPATH:"$DEVPATH" >> /root/test - echo DEVNUM:"$DEVNUM" >> /root/test - echo DRIVER:"$DRIVER" >> /root/test - echo TYPE:"$TYPE" >> /root/test - echo PRODUCT:"$PRODUCT" >> /root/test - echo SEQNUM:"$SEQNUM" >> /root/test - echo BUSNUM:"$BUSNUM" >> /root/test - echo MAJOR:"$MAJOR" >> /root/test - echo MINOR:"$MINOR" >> /root/test + *) + at_q_res=$(at $at_port AT+QSIMDET? |grep +QSIMDET: |awk -F: '{print $2}') + at_f_res=$(at $at_port AT+GTDUALSIM? |grep +GTDUALSIM: |awk -F: '{print $2}') + [ "$at_q_res" == "1" ] && sim_slot="1" && return + [ "$at_q_res" == "2" ] && sim_slot="2" && return + [ "$at_f_res" == "0" ] && sim_slot="1" && return + [ "$at_f_res" == "1" ] && sim_slot="2" && return + sim_slot="1" + ;; + + esac } diff --git a/luci-app-modem/root/usr/share/modem/quectel.sh b/luci-app-modem/root/usr/share/modem/quectel.sh index d7144f3..9fa66a8 100755 --- a/luci-app-modem/root/usr/share/modem/quectel.sh +++ b/luci-app-modem/root/usr/share/modem/quectel.sh @@ -1,111 +1,32 @@ #!/bin/sh -# Copyright (C) 2023 Siriling -#脚本目录 -SCRIPT_DIR="/usr/share/modem" -source /usr/share/libubox/jshn.sh -#预设 -quectel_presets() -{ - at_command='ATI' - # sh "${SCRIPT_DIR}/modem_at.sh" "$at_port" "$at_command" -} - -#获取DNS -# $1:AT串口 -# $2:连接定义 -quectel_get_dns() -{ - local at_port="$1" - local define_connect="$2" - - [ -z "$define_connect" ] && { - define_connect="1" - } - - local public_dns1_ipv4="223.5.5.5" - local public_dns2_ipv4="119.29.29.29" - local public_dns1_ipv6="2400:3200::1" #下一代互联网北京研究中心:240C::6666,阿里:2400:3200::1,腾讯:2402:4e00:: - local public_dns2_ipv6="2402:4e00::" - - #获取DNS地址 - at_command="AT+GTDNS=${define_connect}" - local response=$(at ${at_port} ${at_command} | grep "+GTDNS: ") - - local ipv4_dns1=$(echo "${response}" | awk -F'"' '{print $2}' | awk -F',' '{print $1}') - [ -z "$ipv4_dns1" ] && { - ipv4_dns1="${public_dns1_ipv4}" - } - - local ipv4_dns2=$(echo "${response}" | awk -F'"' '{print $4}' | awk -F',' '{print $1}') - [ -z "$ipv4_dns2" ] && { - ipv4_dns2="${public_dns2_ipv4}" - } - - local ipv6_dns1=$(echo "${response}" | awk -F'"' '{print $2}' | awk -F',' '{print $2}') - [ -z "$ipv6_dns1" ] && { - ipv6_dns1="${public_dns1_ipv6}" - } - - local ipv6_dns2=$(echo "${response}" | awk -F'"' '{print $4}' | awk -F',' '{print $2}') - [ -z "$ipv6_dns2" ] && { - ipv6_dns2="${public_dns2_ipv6}" - } - - dns="{ - \"dns\":{ - \"ipv4_dns1\":\"$ipv4_dns1\", - \"ipv4_dns2\":\"$ipv4_dns2\", - \"ipv6_dns1\":\"$ipv6_dns1\", - \"ipv6_dns2\":\"$ipv6_dns2\" - } - }" - - echo "$dns" -} - -quectel_get_imei(){ - local at_port="$1" +source /usr/share/modem/generic.sh +debug_subject="quectel_ctrl" +#return raw data +get_imei(){ at_command="AT+CGSN" - imei=$(sh ${SCRIPT_DIR}/modem_at.sh $at_port $at_command | sed -n '2p' | grep -E '[0-9]+' ) - echo "$imei" + imei=$(at $at_port $at_command | grep -o "[0-9]\{15\}") + json_add_string "imei" "$imei" } -quectel_set_imei(){ - local at_port="$1" - local imei="$2" +#return raw data +set_imei(){ + local imei="$1" at_command="AT+EGMR=1,7,\"$imei\"" - res=$(sh ${SCRIPT_DIR}/modem_at.sh $at_port $at_command) + res=$(at $at_port $at_command) + json_select "result" + json_add_string "set_imei" "$res" + json_close_object + get_imei } #获取拨号模式 # $1:AT串口 # $2:平台 -quectel_get_mode() +get_mode() { - local at_port="$1" - local platform="$2" - modem_number=$(uci -q get modem.@global[0].modem_number) at_command='AT+QCFG="usbnet"' - local mode_num=$(sh ${SCRIPT_DIR}/modem_at.sh ${at_port} ${at_command} | grep "+QCFG:" | sed 's/+QCFG: "usbnet",//g' | sed 's/\r//g') - - if [ -z "$mode_num" ]; then - echo "unknown" - return - fi - - #获取芯片平台 - if [ -z "$platform" ]; then - local modem_number=$(uci -q get modem.@global[0].modem_number) - for i in $(seq 0 $((modem_number-1))); do - local at_port_tmp=$(uci -q get modem.modem${i}.at_port) - if [ "$at_port" = "$at_port_tmp" ]; then - platform=$(uci -q get modem.modem${i}.platform) - break - fi - done - fi - + local mode_num=$(at ${at_port} ${at_command} | grep "+QCFG:" | sed 's/+QCFG: "usbnet",//g' | sed 's/\r//g') local mode case "$platform" in "qualcomm") @@ -128,6 +49,7 @@ quectel_get_mode() *) mode="${mode_num}" ;; esac ;; + "lte12"|\ "lte") case "$mode_num" in "0") mode="qmi" ;; @@ -143,32 +65,26 @@ quectel_get_mode() mode="${mode_num}" ;; esac - echo "${mode}" + available_modes=$(uci -q get modem.$config_section.modes) + json_add_object "mode" + for available_mode in $available_modes; do + if [ "$mode" = "$available_mode" ]; then + json_add_string "$available_mode" "1" + else + json_add_string "$available_mode" "0" + fi + done + json_close_object } #设置拨号模式 -# $1:AT串口 -# $2:拨号模式配置 -quectel_set_mode() +set_mode() { - local at_port="$1" - - #获取芯片平台 - local platform - local modem_number=$(uci -q get modem.@global[0].modem_number) - for i in $(seq 0 $((modem_number-1))); do - local at_port_tmp=$(uci -q get modem.modem$i.at_port) - if [ "$at_port" = "$at_port_tmp" ]; then - platform=$(uci -q get modem.modem$i.platform) - break - fi - done - #获取拨号模式配置 - local mode_num + local mode=$1 case "$platform" in "qualcomm") - case "$2" in + case "$mode" in "qmi") mode_num="0" ;; # "gobinet") mode_num="0" ;; "ecm") mode_num="1" ;; @@ -179,7 +95,7 @@ quectel_set_mode() esac ;; "unisoc") - case "$2" in + case "$mode" in "ecm") mode_num="1" ;; "mbim") mode_num="2" ;; "rndis") mode_num="3" ;; @@ -187,8 +103,9 @@ quectel_set_mode() *) mode_num="0" ;; esac ;; + "lte12"|\ "lte") - case "$2" in + case "$mode" in "qmi") mode_num="0" ;; # "gobinet") mode_num="0" ;; "ecm") mode_num="1" ;; @@ -206,73 +123,66 @@ quectel_set_mode() #设置模组 at_command='AT+QCFG="usbnet",'${mode_num} - sh ${SCRIPT_DIR}/modem_at.sh "${at_port}" "${at_command}" + res=$(at "${at_port}" "${at_command}") + json_select "result" + json_add_string "set_mode" "$res" + json_close_object } #获取网络偏好 # $1:AT串口 -quectel_get_network_prefer() +get_network_prefer() { - local at_port="$1" - local platform - local modem_number=$(uci -q get modem.@global[0].modem_number) - for i in $(seq 0 $((modem_number-1))); do - local at_port_tmp=$(uci -q get modem.modem$i.at_port) - if [ "$at_port" = "$at_port_tmp" ]; then - platform=$(uci -q get modem.modem$i.platform) - break - fi - done - logger -t modem "quectel_get_network_prefer $platform" case "$platform" in + "lte12"|\ "qualcomm") - quectel_get_network_prefer_nr $at_port + get_network_prefer_nr ;; "unisoc") - quectel_get_network_prefer_nr $at_port + get_network_prefer_nr ;; "lte") - quectel_get_network_prefer_lte $at_port + get_network_prefer_lte ;; *) - quectel_get_network_prefer_nr $at_port + get_network_prefer_nr ;; esac + json_add_object network_prefer + json_add_string 3G $network_prefer_3g + json_add_string 4G $network_prefer_4g + case $platform in + "qualcomm") + json_add_string 5G $network_prefer_5g + ;; + "unisoc") + json_add_string 5G $network_prefer_5g + ;; + esac + json_close_array } -quectel_get_network_prefer_lte() +get_network_prefer_lte() { - local at_port="$1" at_command='AT+QCFG="nwscanmode"' - logger -t modem "quectel_get_network_prefer_lte" - local response=$(sh ${SCRIPT_DIR}/modem_at.sh ${at_port} ${at_command} | grep "+QCFG:" | awk -F'",' '{print $2}' | sed 's/\r//g' |grep -o "[0-9]") - local network_prefer_3g="0"; - local network_prefer_4g="0"; + response=$(at ${at_port} ${at_command} | grep "+QCFG:" | awk -F'",' '{print $2}' | sed 's/\r//g' |grep -o "[0-9]") + network_prefer_3g="0"; + network_prefer_4g="0"; case "$response" in "0") network_prefer_3g="1"; network_prefer_4g="1" ;; "3") network_prefer_4g="1" ;; esac - local network_prefer="{ - \"network_prefer\":{ - \"3G\":$network_prefer_3g, - \"4G\":$network_prefer_4g, - \"5G\":0 - } - }" - echo "$network_prefer" } -quectel_get_network_prefer_nr() +get_network_prefer_nr() { - logger -t modem "quectel_get_network_prefer_nr" - local at_port="$1" at_command='AT+QNWPREFCFG="mode_pref"' - local response=$(sh ${SCRIPT_DIR}/modem_at.sh ${at_port} ${at_command} | grep "+QNWPREFCFG:" | awk -F',' '{print $2}' | sed 's/\r//g') + local response=$(at ${at_port} ${at_command} | grep "+QNWPREFCFG:" | awk -F',' '{print $2}' | sed 's/\r//g') - local network_prefer_3g="0"; - local network_prefer_4g="0"; - local network_prefer_5g="0"; + network_prefer_3g="0"; + network_prefer_4g="0"; + network_prefer_5g="0"; #匹配不同的网络类型 local auto=$(echo "${response}" | grep "AUTO") @@ -294,75 +204,42 @@ quectel_get_network_prefer_nr() network_prefer_5g="1" fi fi - - local network_prefer="{ - \"network_prefer\":{ - \"3G\":$network_prefer_3g, - \"4G\":$network_prefer_4g, - \"5G\":$network_prefer_5g - } - }" - echo "$network_prefer" } - - - - - #设置网络偏好 # $1:AT串口 # $2:网络偏好配置 -quectel_set_network_prefer() +set_network_prefer() { - local at_port="$1" - local network_prefer="$2" - local platform - local modem_number=$(uci -q get modem.@global[0].modem_number) - for i in $(seq 0 $((modem_number-1))); do - local at_port_tmp=$(uci -q get modem.modem$i.at_port) - if [ "$at_port" = "$at_port_tmp" ]; then - platform=$(uci -q get modem.modem$i.platform) - break - fi - done - logger -t modem "quectel_set_network_prefer $platform $network_prefer" + network_prefer_3g=$(echo $1 |jq -r 'contains(["3G"])') + network_prefer_4g=$(echo $1 |jq -r 'contains(["4G"])') + network_prefer_5g=$(echo $1 |jq -r 'contains(["5G"])') + length=$(echo $1 |jq -r 'length') + case "$platform" in + "lte12"|\ "qualcomm") - quectel_set_network_prefer_nr $at_port $network_prefer + set_network_prefer_nr $at_port $network_prefer ;; "unisoc") - quectel_set_network_prefer_nr $at_port $network_prefer + set_network_prefer_nr $at_port $network_prefer ;; "lte") - quectel_set_network_prefer_lte $at_port $network_prefer + set_network_prefer_lte $at_port $network_prefer ;; *) - quectel_set_network_prefer_nr $at_port $network_prefer + set_network_prefer_nr $at_port $network_prefer ;; esac } -quectel_set_network_prefer_lte() +set_network_prefer_lte() { - local at_port="$1" - local network_prefer="$2" - - #获取网络偏好配置 - local network_prefer_config - - #获取选中的数量 - local count=$(echo "$network_prefer" | grep -o "1" | wc -l) - #获取每个偏好的值 - local network_prefer_3g=$(echo "$network_prefer" | jq -r '.["3G"]') - local network_prefer_4g=$(echo "$network_prefer" | jq -r '.["4G"]') - local network_prefer_5g=$(echo "$network_prefer" | jq -r '.["5G"]') - - case "$count" in + case "$length" in "1") - if [ "$network_prefer_3g" = "1" ]; then + if [ "$network_prefer_3g" = "true" ]; then network_prefer_config="0" - elif [ "$network_prefer_4g" = "1" ]; then + elif [ "$network_prefer_4g" = "true" ]; then network_prefer_config="3" fi ;; @@ -372,41 +249,29 @@ quectel_set_network_prefer_lte() #设置模组 at_command='AT+QCFG="nwscanmode",'${network_prefer_config} - sh ${SCRIPT_DIR}/modem_at.sh "${at_port}" "${at_command}" + at "${at_port}" "${at_command}" } -quectel_set_network_prefer_nr() + +set_network_prefer_nr() { - local at_port="$1" - local network_prefer="$2" - - #获取网络偏好配置 - local network_prefer_config - - #获取选中的数量 - local count=$(echo "$network_prefer" | grep -o "1" | wc -l) - #获取每个偏好的值 - local network_prefer_3g=$(echo "$network_prefer" | jq -r '.["3G"]') - local network_prefer_4g=$(echo "$network_prefer" | jq -r '.["4G"]') - local network_prefer_5g=$(echo "$network_prefer" | jq -r '.["5G"]') - - case "$count" in + case "$length" in "1") - if [ "$network_prefer_3g" = "1" ]; then + if [ "$network_prefer_3g" = "true" ]; then network_prefer_config="WCDMA" - elif [ "$network_prefer_4g" = "1" ]; then + elif [ "$network_prefer_4g" = "true" ]; then network_prefer_config="LTE" - elif [ "$network_prefer_5g" = "1" ]; then + elif [ "$network_prefer_5g" = "true" ]; then network_prefer_config="NR5G" fi ;; "2") - if [ "$network_prefer_3g" = "1" ] && [ "$network_prefer_4g" = "1" ]; then + if [ "$network_prefer_3g" = "true" ] && [ "$network_prefer_4g" = "true" ]; then network_prefer_config="WCDMA:LTE" - elif [ "$network_prefer_3g" = "1" ] && [ "$network_prefer_5g" = "1" ]; then + elif [ "$network_prefer_3g" = "true" ] && [ "$network_prefer_5g" = "true" ]; then network_prefer_config="WCDMA:NR5G" - elif [ "$network_prefer_4g" = "1" ] && [ "$network_prefer_5g" = "1" ]; then + elif [ "$network_prefer_4g" = "true" ] && [ "$network_prefer_5g" = "true" ]; then network_prefer_config="LTE:NR5G" fi ;; @@ -416,173 +281,86 @@ quectel_set_network_prefer_nr() #设置模组 at_command='AT+QNWPREFCFG="mode_pref",'${network_prefer_config} - sh ${SCRIPT_DIR}/modem_at.sh "${at_port}" "${at_command}" + at "${at_port}" "${at_command}" } #获取电压 # $1:AT串口 -quectel_get_voltage() +get_voltage() { - local at_port="$1" - - #Voltage(电压) at_command="AT+CBC" - local voltage=$(sh ${SCRIPT_DIR}/modem_at.sh ${at_port} ${at_command} | grep "+CBC:" | awk -F',' '{print $3}' | sed 's/\r//g') - echo "${voltage}" + local voltage=$(at ${at_port} ${at_command} | grep "+CBC:" | awk -F',' '{print $3}' | sed 's/\r//g') + [ -n "$voltage" ] && { + add_plain_info_entry "voltage" "$voltage mV" "Voltage" + } } #获取温度 -# $1:AT串口 -quectel_get_temperature() -{ - local at_port="$1" - +#return raw data +get_temperature() +{ #Temperature(温度) at_command="AT+QTEMP" - + local temp local line=1 - retry=0 - while [ $retry -lt 5 ]; do - response=$(sh ${SCRIPT_DIR}/modem_at.sh ${at_port} ${at_command} | grep "+QTEMP:" | sed -n "${line}p" | awk -F'"' '{print $4}') - [ $response -gt 0 ] && break - line=$((line+1)) - retry=$((retry+1)) + QTEMP=$(at ${at_port} ${at_command} | grep "+QTEMP:") + for line in $( echo -e "$QTEMP" ); do + temp=$(echo $line | grep -o "[0-9]\{1,3\}") + if [ -n "$temp" ]; then + break + fi done - - local temperature - if [ -n "$response" ]; then - temperature="${response}$(printf "\xc2\xb0")C" + if [ -n "$temp" ]; then + temp="${temp}$(printf "\xc2\xb0")C" fi - - # response=$(sh ${SCRIPT_DIR}/modem_at.sh ${at_port} ${at_command} | grep "+QTEMP:") - # QTEMP=$(echo $response | grep -o -i "+QTEMP: [0-9]\{1,3\}") - # if [ -z "$QTEMP" ]; then - # QTEMP=$(echo $response | grep -o -i "+QTEMP:[ ]\?\"XO[_-]THERM[_-][^,]\+,[\"]\?[0-9]\{1,3\}" | grep -o "[0-9]\{1,3\}") - # fi - # if [ -z "$QTEMP" ]; then - # QTEMP=$(echo $response | grep -o -i "+QTEMP:[ ]\?\"MDM-CORE-USR.\+[0-9]\{1,3\}\"" | cut -d\" -f4) - # fi - # if [ -z "$QTEMP" ]; then - # QTEMP=$(echo $response | grep -o -i "+QTEMP:[ ]\?\"MDMSS.\+[0-9]\{1,3\}\"" | cut -d\" -f4) - # fi - # if [ -n "$QTEMP" ]; then - # CTEMP=$(echo $QTEMP | grep -o -i "[0-9]\{1,3\}")$(printf "\xc2\xb0")"C" - # fi - - echo "${temperature}" + add_plain_info_entry "temperature" "$temp" "Temperature" } -#获取连接状态 -# $1:AT串口 -# $2:连接定义 -quectel_get_connect_status() -{ - local at_port="$1" - local define_connect="$2" - #默认值为1 - [ -z "$define_connect" ] && { - define_connect="1" - } - - at_command="AT+CGPADDR=${define_connect}" - local ipv4=$(sh ${SCRIPT_DIR}/modem_at.sh $at_port $at_command | grep "+CGPADDR: " | awk -F'"' '{print $2}') - local not_ip="0.0.0.0" - - #设置连接状态 - local connect_status - if [ -z "$ipv4" ] || [[ "$ipv4" = *"$not_ip"* ]]; then - connect_status="disconnect" - else - connect_status="connect" - fi - - #方法二 - # at_command="AT+QNWINFO" - - # local response=$(sh ${SCRIPT_DIR}/modem_at.sh $at_port $at_command | grep "+QNWINFO:") - - # local connect_status - # if [[ "$response" = *"No Service"* ]]; then - # connect_status="disconnect" - # elif [[ "$response" = *"Unknown Service"* ]]; then - # connect_status="disconnect" - # else - # connect_status="connect" - # fi - - echo "$connect_status" -} #基本信息 -quectel_base_info() +base_info() { - debug "Quectel base info" + m_debug "Quectel base info" #Name(名称) at_command="AT+CGMM" - name=$(sh ${SCRIPT_DIR}/modem_at.sh $at_port $at_command | sed -n '2p' | sed 's/\r//g') + name=$(at $at_port $at_command | sed -n '2p' | sed 's/\r//g') #Manufacturer(制造商) at_command="AT+CGMI" - manufacturer=$(sh ${SCRIPT_DIR}/modem_at.sh $at_port $at_command | sed -n '2p' | sed 's/\r//g') + manufacturer=$(at $at_port $at_command | sed -n '2p' | sed 's/\r//g') #Revision(固件版本) at_command="ATI" - revision=$(sh ${SCRIPT_DIR}/modem_at.sh $at_port $at_command | grep "Revision:" | sed 's/Revision: //g' | sed 's/\r//g') + revision=$(at $at_port $at_command | grep "Revision:" | sed 's/Revision: //g' | sed 's/\r//g') # at_command="AT+CGMR" - # revision=$(sh ${SCRIPT_DIR}/modem_at.sh $at_port $at_command | sed -n '2p' | sed 's/\r//g') - - #Mode(拨号模式) - mode=$(quectel_get_mode ${at_port} ${platform} | tr 'a-z' 'A-Z') - - #Temperature(温度) - temperature=$(quectel_get_temperature ${at_port}) + # revision=$(at $at_port $at_command | sed -n '2p' | sed 's/\r//g') + class="Base Information" + add_plain_info_entry "manufacturer" "$manufacturer" "Manufacturer" + add_plain_info_entry "revision" "$revision" "Revision" + add_plain_info_entry "at_port" "$at_port" "AT Port" + get_temperature + get_voltage + get_connect_status } -#获取SIM卡状态 -# $1:SIM卡状态标志 -quectel_get_sim_status() -{ - local sim_status - case $1 in - "") sim_status="miss" ;; - *"READY"*) sim_status="ready" ;; - *"SIM PIN"*) sim_status="MT is waiting SIM PIN to be given" ;; - *"SIM PUK"*) sim_status="MT is waiting SIM PUK to be given" ;; - *"PH-FSIM PIN"*) sim_status="MT is waiting phone-to-SIM card password to be given" ;; - *"PH-FSIM PIN"*) sim_status="MT is waiting phone-to-very first SIM card password to be given" ;; - *"PH-FSIM PUK"*) sim_status="MT is waiting phone-to-very first SIM card unblocking password to be given" ;; - *"SIM PIN2"*) sim_status="MT is waiting SIM PIN2 to be given" ;; - *"SIM PUK2"*) sim_status="MT is waiting SIM PUK2 to be given" ;; - *"PH-NET PIN"*) sim_status="MT is waiting network personalization password to be given" ;; - *"PH-NET PUK"*) sim_status="MT is waiting network personalization unblocking password to be given" ;; - *"PH-NETSUB PIN"*) sim_status="MT is waiting network subset personalization password to be given" ;; - *"PH-NETSUB PUK"*) sim_status="MT is waiting network subset personalization unblocking password to be given" ;; - *"PH-SP PIN"*) sim_status="MT is waiting service provider personalization password to be given" ;; - *"PH-SP PUK"*) sim_status="MT is waiting service provider personalization unblocking password to be given" ;; - *"PH-CORP PIN"*) sim_status="MT is waiting corporate personalization password to be given" ;; - *"PH-CORP PUK"*) sim_status="MT is waiting corporate personalization unblocking password to be given" ;; - *) sim_status="unknown" ;; - esac - echo "$sim_status" -} #SIM卡信息 -quectel_sim_info() +sim_info() { - debug "Quectel sim info" + m_debug "Quectel sim info" #SIM Slot(SIM卡卡槽) at_command="AT+QUIMSLOT?" - sim_slot=$(sh ${SCRIPT_DIR}/modem_at.sh $at_port $at_command | grep "+QUIMSLOT:" | awk -F' ' '{print $2}' | sed 's/\r//g') + sim_slot=$(at $at_port $at_command | grep "+QUIMSLOT:" | awk -F' ' '{print $2}' | sed 's/\r//g') #IMEI(国际移动设备识别码) at_command="AT+CGSN" - imei=$(sh ${SCRIPT_DIR}/modem_at.sh $at_port $at_command | sed -n '2p' | sed 's/\r//g') + imei=$(at $at_port $at_command | sed -n '2p' | sed 's/\r//g') #SIM Status(SIM状态) at_command="AT+CPIN?" - sim_status_flag=$(sh ${SCRIPT_DIR}/modem_at.sh $at_port $at_command | sed -n '2p') - sim_status=$(quectel_get_sim_status "$sim_status_flag") + sim_status_flag=$(at $at_port $at_command | sed -n '2p') + sim_status=$(get_sim_status "$sim_status_flag") if [ "$sim_status" != "ready" ]; then return @@ -590,7 +368,7 @@ quectel_sim_info() #ISP(互联网服务提供商) at_command="AT+COPS?" - isp=$(sh ${SCRIPT_DIR}/modem_at.sh $at_port $at_command | sed -n '2p' | awk -F'"' '{print $2}') + isp=$(at $at_port $at_command | sed -n '2p' | awk -F'"' '{print $2}') # if [ "$isp" = "CHN-CMCC" ] || [ "$isp" = "CMCC" ]|| [ "$isp" = "46000" ]; then # isp="中国移动" # # elif [ "$isp" = "CHN-UNICOM" ] || [ "$isp" = "UNICOM" ] || [ "$isp" = "46001" ]; then @@ -603,71 +381,67 @@ quectel_sim_info() #SIM Number(SIM卡号码,手机号) at_command="AT+CNUM" - sim_number=$(sh ${SCRIPT_DIR}/modem_at.sh $at_port $at_command | sed -n '2p' | awk -F'"' '{print $4}') + sim_number=$(at $at_port $at_command | sed -n '2p' | awk -F'"' '{print $4}') #IMSI(国际移动用户识别码) at_command="AT+CIMI" - imsi=$(sh ${SCRIPT_DIR}/modem_at.sh $at_port $at_command | sed -n '2p' | sed 's/\r//g') + imsi=$(at $at_port $at_command | sed -n '2p' | sed 's/\r//g') #ICCID(集成电路卡识别码) at_command="AT+ICCID" - # iccid=$(sh ${SCRIPT_DIR}/modem_at.sh $at_port $at_command | grep -o "+ICCID:[ ]*[-0-9]\+" | grep -o "[-0-9]\{1,4\}") -} - -#获取网络类型 -# $1:网络类型数字 -quectel_get_rat() -{ - local rat - case $1 in - "0"|"1"|"3"|"8") rat="GSM" ;; - "2"|"4"|"5"|"6"|"9"|"10") rat="WCDMA" ;; - "7") rat="LTE" ;; - "11"|"12") rat="NR" ;; - esac - echo "${rat}" -} - -#获取信号强度指示 -# $1:信号强度指示数字 -quectel_get_rssi() -{ - local rssi - case $1 in - "99") rssi="unknown" ;; - * ) rssi=$((2 * $1 - 113)) ;; - esac - echo "$rssi" + iccid=$(at $at_port $at_command | grep -o "+ICCID:[ ]*[-0-9]\+" | grep -o "[-0-9]\{1,4\}") + class="SIM Information" + case "$sim_status" in + "ready") + add_plain_info_entry "SIM Status" "$sim_status" "SIM Status" + add_plain_info_entry "ISP" "$isp" "Internet Service Provider" + add_plain_info_entry "SIM Slot" "$sim_slot" "SIM Slot" + add_plain_info_entry "SIM Number" "$sim_number" "SIM Number" + add_plain_info_entry "IMEI" "$imei" "International Mobile Equipment Identity" + add_plain_info_entry "IMSI" "$imsi" "International Mobile Subscriber Identity" + add_plain_info_entry "ICCID" "$iccid" "Integrate Circuit Card Identity" + ;; + "miss") + add_plain_info_entry "SIM Status" "$sim_status" "SIM Status" + add_plain_info_entry "IMEI" "$imei" "International Mobile Equipment Identity" + ;; + "unknown") + add_plain_info_entry "SIM Status" "$sim_status" "SIM Status" + ;; + *) + add_plain_info_entry "SIM Status" "$sim_status" "SIM Status" + add_plain_info_entry "SIM Slot" "$sim_slot" "SIM Slot" + add_plain_info_entry "IMEI" "$imei" "International Mobile Equipment Identity" + add_plain_info_entry "IMSI" "$imsi" "International Mobile Subscriber Identity" + add_plain_info_entry "ICCID" "$iccid" "Integrate Circuit Card Identity" + ;; + esac } #网络信息 -quectel_network_info() +network_info() { - debug "Quectel network info" + m_debug "Quectel network info" #Connect Status(连接状态) - connect_status=$(quectel_get_connect_status ${at_port} ${define_connect}) - if [ "$connect_status" != "connect" ]; then - return - fi #Network Type(网络类型) at_command="AT+QNWINFO" - network_type=$(sh ${SCRIPT_DIR}/modem_at.sh ${at_port} ${at_command} | grep "+QNWINFO:" | awk -F'"' '{print $2}') + network_type=$(at ${at_port} ${at_command} | grep "+QNWINFO:" | awk -F'"' '{print $2}') [ -z "$network_type" ] && { at_command='AT+COPS?' - local rat_num=$(sh ${SCRIPT_DIR}/modem_at.sh ${at_port} ${at_command} | grep "+COPS:" | awk -F',' '{print $4}' | sed 's/\r//g') - network_type=$(quectel_get_rat ${rat_num}) + local rat_num=$(at ${at_port} ${at_command} | grep "+COPS:" | awk -F',' '{print $4}' | sed 's/\r//g') + network_type=$(get_rat ${rat_num}) } #CSQ(信号强度) at_command="AT+CSQ" - response=$(sh ${SCRIPT_DIR}/modem_at.sh ${at_port} ${at_command} | grep "+CSQ:" | sed 's/+CSQ: //g' | sed 's/\r//g') + response=$(at ${at_port} ${at_command} | grep "+CSQ:" | sed 's/+CSQ: //g' | sed 's/\r//g') #RSSI(信号强度指示) # rssi_num=$(echo $response | awk -F',' '{print $1}') - # rssi=$(quectel_get_rssi $rssi_num) + # rssi=$(get_rssi $rssi_num) #Ber(信道误码率) # ber=$(echo $response | awk -F',' '{print $2}') @@ -678,7 +452,7 @@ quectel_network_info() #最大比特率,信道质量指示 at_command='AT+QNWCFG="nr5g_ambr"' - response=$(sh ${SCRIPT_DIR}/modem_at.sh $at_port $at_command | grep "+QNWCFG:") + response=$(at $at_port $at_command | grep "+QNWCFG:") for context in $response; do local apn=$(echo "$context" | awk -F'"' '{print $4}' | tr 'a-z' 'A-Z') if [ -n "$apn" ] && [ "$apn" != "IMS" ]; then @@ -696,19 +470,27 @@ quectel_network_info() #速率统计 at_command='AT+QNWCFG="up/down"' - response=$(sh ${SCRIPT_DIR}/modem_at.sh $at_port $at_command | grep "+QNWCFG:" | sed 's/+QNWCFG: "up\/down",//g' | sed 's/\r//g') + response=$(at $at_port $at_command | grep "+QNWCFG:" | sed 's/+QNWCFG: "up\/down",//g' | sed 's/\r//g') #当前上传速率(单位,Byte/s) tx_rate=$(echo $response | awk -F',' '{print $1}') #当前下载速率(单位,Byte/s) rx_rate=$(echo $response | awk -F',' '{print $2}') + class="Network Information" + add_plain_info_entry "Network Type" "$network_type" "Network Type" + add_plain_info_entry "CQI UL" "$cqi_ul" "Channel Quality Indicator for Uplink" + add_plain_info_entry "CQI DL" "$cqi_dl" "Channel Quality Indicator for Downlink" + add_plain_info_entry "AMBR UL" "$ambr_ul" "Access Maximum Bit Rate for Uplink" + add_plain_info_entry "AMBR DL" "$ambr_dl" "Access Maximum Bit Rate for Downlink" + add_plain_info_entry "Tx Rate" "$tx_rate" "Transmit Rate" + add_plain_info_entry "Rx Rate" "$rx_rate" "Receive Rate" } #获取频段 # $1:网络类型 # $2:频段数字 -quectel_get_band() +get_band() { local band case $1 in @@ -719,10 +501,10 @@ quectel_get_band() echo "$band" } -quectel_get_lockband_nr() +get_lockband_nr() { local at_port="$1" - debug "Quectel sdx55 get lockband info" + m_debug "Quectel sdx55 get lockband info" get_wcdma_config_command='AT+QNWPREFCFG="gw_band"' get_lte_config_command='AT+QNWPREFCFG="lte_band"' get_nsa_nr_config_command='AT+QNWPREFCFG="nsa_nr5g_band"' @@ -731,60 +513,60 @@ quectel_get_lockband_nr() lte_avalible_band="1,2,3,4,5,7,8,12,13,14,17,18,19,20,25,26,28,29,30,32,34,38,39,40,41,42,66,71" nsa_nr_avalible_band="1,2,3,5,7,8,12,20,25,28,38,40,41,48,66,71,77,78,79,257,258,260,261" sa_nr_avalible_band="1,2,3,5,7,8,12,20,25,28,38,40,41,48,66,71,77,78,79" - gw_band=$(sh ${SCRIPT_DIR}/modem_at.sh $at_port $get_wcdma_config_command |grep -e "+QNWPREFCFG: " ) - lte_band=$(sh ${SCRIPT_DIR}/modem_at.sh $at_port $get_lte_config_command|grep -e "+QNWPREFCFG: ") - nsa_nr_band=$(sh ${SCRIPT_DIR}/modem_at.sh $at_port $get_nsa_nr_config_command|grep -e "+QNWPREFCFG: ") - sa_nr_band=$(sh ${SCRIPT_DIR}/modem_at.sh $at_port $get_sa_nr_config_command|grep -e "+QNWPREFCFG: ") - json_init + gw_band=$(at $at_port $get_wcdma_config_command |grep -e "+QNWPREFCFG: " ) + lte_band=$(at $at_port $get_lte_config_command|grep -e "+QNWPREFCFG: ") + nsa_nr_band=$(at $at_port $get_nsa_nr_config_command|grep -e "+QNWPREFCFG: ") + sa_nr_band=$(at $at_port $get_sa_nr_config_command|grep -e "+QNWPREFCFG: ") json_add_object "UMTS" - json_add_object "available_band" - json_close_object + json_add_array "available_band" + json_close_array json_add_array "lock_band" json_close_object json_close_object json_add_object "LTE" - json_add_object "available_band" - json_close_object + json_add_array "available_band" + json_close_array json_add_array "lock_band" + json_close_array json_close_object - json_close_object + json_add_object "NR" - json_add_object "available_band" - json_close_object + json_add_array "available_band" + json_close_array json_add_array "lock_band" - json_close_object + json_close_array json_close_object json_add_object "NR_NSA" - json_add_object "available_band" - json_close_object + json_add_array "available_band" + json_close_array json_add_array "lock_band" - json_close_object + json_close_array json_close_object for i in $(echo "$wcdma_avalible_band" | awk -F"," '{for(j=1; j<=NF; j++) print $j}'); do json_select "UMTS" json_select "available_band" - json_add_string "$i" "UMTS_$i" + add_avalible_band_entry "$i" "UMTS_$i" json_select .. json_select .. done for i in $(echo "$lte_avalible_band" | awk -F"," '{for(j=1; j<=NF; j++) print $j}'); do json_select "LTE" json_select "available_band" - json_add_string "$i" "LTE_B$i" + add_avalible_band_entry "$i" "LTE_B$i" json_select .. json_select .. done for i in $(echo "$nsa_nr_avalible_band" | awk -F"," '{for(j=1; j<=NF; j++) print $j}'); do json_select "NR_NSA" json_select "available_band" - json_add_string "$i" "NSA_NR_N$i" + add_avalible_band_entry "$i" "NSA_NR_N$i" json_select .. json_select .. done for i in $(echo "$sa_nr_avalible_band" | awk -F"," '{for(j=1; j<=NF; j++) print $j}'); do json_select "NR" json_select "available_band" - json_add_string "$i" "SA_NR_N$i" + add_avalible_band_entry "$i" "SA_NR_N$i" json_select .. json_select .. done @@ -826,8 +608,155 @@ quectel_get_lockband_nr() fi done json_close_array - json_result=`json_dump` - echo "$json_result" +} + +get_lockband_lte12() +{ + m_debug "Quectel sdx55 get lockband info" + get_wcdma_config_command='AT+QNWPREFCFG="gw_band"' + get_lte_config_command='AT+QNWPREFCFG="lte_band"' + get_nsa_nr_config_command='AT+QNWPREFCFG="nsa_nr5g_band"' + get_sa_nr_config_command='AT+QNWPREFCFG="nr5g_band"' + wcdma_avalible_band="1,2,3,4,5,6,7,8,9,19" + lte_avalible_band="1,2,3,4,5,7,8,12,13,14,17,18,19,20,25,26,28,29,30,32,34,38,39,40,41,42,66,71" + nsa_nr_avalible_band="1,2,3,5,7,8,12,20,25,28,38,40,41,48,66,71,77,78,79,257,258,260,261" + sa_nr_avalible_band="1,2,3,5,7,8,12,20,25,28,38,40,41,48,66,71,77,78,79" + gw_band=$(at $at_port $get_wcdma_config_command |grep -e "+QNWPREFCFG: " ) + lte_band=$(at $at_port $get_lte_config_command|grep -e "+QNWPREFCFG: ") + nsa_nr_band=$(at $at_port $get_nsa_nr_config_command|grep -e "+QNWPREFCFG: ") + sa_nr_band=$(at $at_port $get_sa_nr_config_command|grep -e "+QNWPREFCFG: ") + json_add_object "UMTS" + json_add_array "available_band" + json_close_array + json_add_array "lock_band" + json_close_object + json_close_object + json_add_object "LTE" + json_add_array "available_band" + json_close_array + json_add_array "lock_band" + json_close_array + json_close_object + for i in $(echo "$wcdma_avalible_band" | awk -F"," '{for(j=1; j<=NF; j++) print $j}'); do + json_select "UMTS" + json_select "available_band" + add_avalible_band_entry "$i" "UMTS_$i" + json_select .. + json_select .. + done + for i in $(echo "$lte_avalible_band" | awk -F"," '{for(j=1; j<=NF; j++) print $j}'); do + json_select "LTE" + json_select "available_band" + add_avalible_band_entry "$i" "LTE_B$i" + json_select .. + json_select .. + done + #+QNWPREFCFG: "nr5g_band",1:3:7:20:28:40:41:71:77:78:79 + for i in $(echo "$gw_band" | cut -d, -f2 |tr -d '\r' | awk -F":" '{for(j=1; j<=NF; j++) print $j}'); do + if [ -n "$i" ]; then + json_select "UMTS" + json_select "lock_band" + json_add_string "" "$i" + json_select .. + json_select .. + fi + done + for i in $(echo "$lte_band" | cut -d, -f2|tr -d '\r' | awk -F":" '{for(j=1; j<=NF; j++) print $j}'); do + if [ -n "$i" ]; then + json_select "LTE" + json_select "lock_band" + json_add_string "" "$i" + json_select .. + json_select .. + fi + done + json_close_array +} + +get_lockband_unisoc() +{ + local at_port="$1" + m_debug "Quectel sdx55 get lockband info" + get_wcdma_config_command='AT+QNWPREFCFG="gw_band"' + get_lte_config_command='AT+QNWPREFCFG="lte_band"' + get_nsa_nr_config_command='AT+QNWPREFCFG="nsa_nr5g_band"' + get_sa_nr_config_command='AT+QNWPREFCFG="nr5g_band"' + wcdma_avalible_band="1,2,3,4,5,6,7,8,9,19" + lte_avalible_band="1,2,3,4,5,7,8,12,13,14,17,18,19,20,25,26,28,29,30,32,34,38,39,40,41,42,66,71" + nsa_nr_avalible_band="1,2,3,5,7,8,12,20,25,28,38,40,41,48,66,71,77,78,79,257,258,260,261" + sa_nr_avalible_band="1,2,3,5,7,8,12,20,25,28,38,40,41,48,66,71,77,78,79" + gw_band=$(at $at_port $get_wcdma_config_command |grep -e "+QNWPREFCFG: " ) + lte_band=$(at $at_port $get_lte_config_command|grep -e "+QNWPREFCFG: ") + nsa_nr_band=$(at $at_port $get_nsa_nr_config_command|grep -e "+QNWPREFCFG: ") + sa_nr_band=$(at $at_port $get_sa_nr_config_command|grep -e "+QNWPREFCFG: ") + json_add_object "UMTS" + json_add_array "available_band" + json_close_array + json_add_array "lock_band" + json_close_object + json_close_object + json_add_object "LTE" + json_add_array "available_band" + json_close_array + json_add_array "lock_band" + json_close_array + json_close_object + json_add_object "NR" + json_add_array "available_band" + json_close_array + json_add_array "lock_band" + json_close_array + json_close_object + for i in $(echo "$wcdma_avalible_band" | awk -F"," '{for(j=1; j<=NF; j++) print $j}'); do + json_select "UMTS" + json_select "available_band" + add_avalible_band_entry "$i" "UMTS_$i" + json_select .. + json_select .. + done + for i in $(echo "$lte_avalible_band" | awk -F"," '{for(j=1; j<=NF; j++) print $j}'); do + json_select "LTE" + json_select "available_band" + add_avalible_band_entry "$i" "LTE_B$i" + json_select .. + json_select .. + done + for i in $(echo "$sa_nr_avalible_band" | awk -F"," '{for(j=1; j<=NF; j++) print $j}'); do + json_select "NR" + json_select "available_band" + add_avalible_band_entry "$i" "NR_N$i" + json_select .. + json_select .. + done + #+QNWPREFCFG: "nr5g_band",1:3:7:20:28:40:41:71:77:78:79 + for i in $(echo "$gw_band" | cut -d, -f2 |tr -d '\r' | awk -F":" '{for(j=1; j<=NF; j++) print $j}'); do + if [ -n "$i" ]; then + json_select "UMTS" + json_select "lock_band" + json_add_string "" "$i" + json_select .. + json_select .. + fi + done + for i in $(echo "$lte_band" | cut -d, -f2|tr -d '\r' | awk -F":" '{for(j=1; j<=NF; j++) print $j}'); do + if [ -n "$i" ]; then + json_select "LTE" + json_select "lock_band" + json_add_string "" "$i" + json_select .. + json_select .. + fi + done + for i in $(echo "$sa_nr_band" | cut -d, -f2|tr -d '\r' | awk -F":" '{for(j=1; j<=NF; j++) print $j}'); do + if [ -n "$i" ]; then + json_select "NR" + json_select "lock_band" + json_add_string "" "$i" + json_select .. + json_select .. + fi + done + json_close_array } convert2band() @@ -835,7 +764,7 @@ convert2band() hex_band=$1 hex=$(echo $hex_band | grep -o "[0-9A-F]\{1,16\}") if [ -z "$hex" ]; then - echo Invalid band + retrun fi band_list="" bin=$(echo "ibase=16;obase=2;$hex" | bc) @@ -865,30 +794,29 @@ convert2hex() fi } -quectel_get_lockband_lte() +get_lockband_lte() { local at_port="$1" local commamd="AT+QCFG=\"band\"" - LTE_LOCK=$(sh ${SCRIPT_DIR}/modem_at.sh $at_port "$commamd" |grep '+QCFG:'| awk -F, '{print $3}' | sed 's/"//g' | tr '[:a-z:]' '[:A-Z:]') + LTE_LOCK=$(at $at_port "$commamd" |grep '+QCFG:'| awk -F, '{print $3}' | sed 's/"//g' | tr '[:a-z:]' '[:A-Z:]') if [ -z "$LOCK_BAND" ]; then LOCK_BAND="Unknown" fi LOCK_BAND=$(convert2band $LTE_LOCK) - json_init json_add_object "Lte" - json_add_object available_band - json_add_string "1" "B01" - json_add_string "3" "B03" - json_add_string "5" "B05" - json_add_string "7" "B07" - json_add_string "8" "B08" - json_add_string "20" "B20" - json_add_string "34" "B34" - json_add_string "38" "B38" - json_add_string "39" "B39" - json_add_string "40" "B40" - json_add_string "41" "B41" - json_close_object + json_add_array available_band + add_avalible_band_entry "1" "B01" + add_avalible_band_entry "3" "B03" + add_avalible_band_entry "5" "B05" + json_adadd_avalible_band_entryd_string "7" "B07" + add_avalible_band_entry "8" "B08" + add_avalible_band_entry "20" "B20" + add_avalible_band_entry "34" "B34" + add_avalible_band_entry "38" "B38" + add_avalible_band_entry "39" "B39" + json_addadd_avalible_band_entry_string "40" "B40" + add_avalible_band_entry "41" "B41" + json_close_array json_add_array "lock_band" for band in $(echo $LOCK_BAND | tr ',' '\n' | sort -n | uniq); do json_add_string "" $band @@ -896,105 +824,93 @@ quectel_get_lockband_lte() json_close_array json_close_object json_close_object - json_dump } -quectel_get_lockband() +get_lockband() { - local at_port="$1" - local platform - local modem_number=$(uci -q get modem.@global[0].modem_number) - for i in $(seq 0 $((modem_number-1))); do - local at_port_tmp=$(uci -q get modem.modem$i.at_port) - if [ "$at_port" = "$at_port_tmp" ]; then - platform=$(uci -q get modem.modem$i.platform) - break - fi - done + json_add_object "lockband" case "$platform" in "qualcomm") - quectel_get_lockband_nr $at_port + get_lockband_nr $at_port ;; "unisoc") - quectel_get_lockband_nr $at_port + get_lockband_unisoc $at_port ;; 'lte') - quectel_get_lockband_lte $at_port + get_lockband_lte $at_port ;; + "lte12") + get_lockband_lte12 + ;; *) - quectel_get_lockband_lte $at_port + get_lockband_lte $at_port ;; esac + json_close_object } -quectel_set_lockband_lte() +set_lockband_lte() { - at_port=$1 - band=$2 - if [ -z $band ]; then - echo "Invalid band" - fi - hex=$(convert2hex $band) - sh ${SCRIPT_DIR}/modem_at.sh $at_port 'AT+QCFG="band",0,'${hex}',0' 2>&1 > /dev/null + hex=$(convert2hex $lock_band) + res=$(at $at_port 'AT+QCFG="band",0,'${hex}',0' 2>&1 > /dev/null) } -quectel_set_lockband_nr(){ - local at_port="$1" - local lock_band="$2" - local rat="$3" +set_lockband_nr(){ lock_band=$(echo $lock_band | tr ',' ':') - case "$rat" in + case "$band_class" in "UMTS") at_command="AT+QNWPREFCFG=\"gw_band\",$lock_band" - res=$(sh ${SCRIPT_DIR}/modem_at.sh $at_port $at_command) + res=$(at $at_port $at_command) ;; "LTE") at_command="AT+QNWPREFCFG=\"lte_band\",$lock_band" - res=$(sh ${SCRIPT_DIR}/modem_at.sh $at_port $at_command) + res=$(at $at_port $at_command) ;; "NR_NSA") at_command="AT+QNWPREFCFG=\"nsa_nr5g_band\",$lock_band" - res=$(sh ${SCRIPT_DIR}/modem_at.sh $at_port $at_command) + res=$(at $at_port $at_command) ;; "NR") at_command="AT+QNWPREFCFG=\"nr5g_band\",$lock_band" - res=$(sh ${SCRIPT_DIR}/modem_at.sh $at_port $at_command) + res=$(at $at_port $at_command) ;; esac - json_init - json_add_string result "$res" - json_result=`json_dump` - echo "$json_result" } #设置锁频 -quectel_set_lockband() +set_lockband() { - debug "quectel set lockband info" - local at_port="$1" - local rat="$3" - case "$rat" in - "Lte") - quectel_set_lockband_lte $at_port $2 + m_debug "quectel set lockband info" + config=$1 + #{"band_class":"NR","lock_band":"41,78,79"} + band_class=$(echo $config | jq -r '.band_class') + lock_band=$(echo $config | jq -r '.lock_band') + case "$platform" in + "lte") + set_lockband_lte ;; *) - quectel_set_lockband_nr $at_port $2 $3 + set_lockband_nr ;; esac - + json_select "result" + json_add_string "set_lockband" "$res" + json_add_string "config" "$config" + json_add_string "band_class" "$band_class" + json_add_string "lock_band" "$lock_band" + json_close_object } -quectel_get_neighborcell_qualcomm(){ - local at_port="$1" +get_neighborcell_qualcomm(){ local at_command='AT+QENG="neighbourcell"' nr_lock_check="AT+QNWLOCK=\"common\/5g\"" lte_lock_check="AT+QNWLOCK=\"common\/4g\"" - lte_status=$(sh ${SCRIPT_DIR}/modem_at.sh $at_port $lte_lock_check | grep "+QNWLOCK:") + lte_status=$(at $at_port $lte_lock_check | grep "+QNWLOCK:") lte_lock_status=$(echo $lte_status | awk -F',' '{print $2}') lte_lock_freq=$(echo $lte_status | awk -F',' '{print $3}') lte_lock_pci=$(echo $lte_status | awk -F',' '{print $4}') - nr_status=$(sh ${SCRIPT_DIR}/modem_at.sh $at_port $nr_lock_check | grep "+QNWLOCK:") + nr_status=$(at $at_port $nr_lock_check | grep "+QNWLOCK:") nr_lock_status=$(echo $nr_status | awk -F',' '{print $2}') nr_lock_pci=$(echo $nr_status | awk -F',' '{print $3}') nr_lock_freq=$(echo $nr_status | awk -F',' '{print $4}') @@ -1012,8 +928,7 @@ quectel_get_neighborcell_qualcomm(){ fi - sh ${SCRIPT_DIR}/modem_at.sh $at_port $at_command > /tmp/quectel_neighborcell - json_init + at $at_port $at_command > /tmp/neighborcell json_add_object "Feature" json_add_string "Unlock" "2" json_add_string "Lock PCI" "1" @@ -1096,16 +1011,13 @@ quectel_get_neighborcell_qualcomm(){ json_close_object json_select ".." fi - done < /tmp/quectel_neighborcell - json_result=`json_dump` - echo "$json_result" + done < /tmp/neighborcell } -quectel_get_neighborcell_lte(){ - local at_port="$1" +get_neighborcell_lte(){ local at_command='AT+QENG="neighbourcell"' lte_lock_check="AT+QNWLOCK=\"common/lte\"" - lte_status=$(sh ${SCRIPT_DIR}/modem_at.sh $at_port $lte_lock_check | grep "+QNWLOCK:") + lte_status=$(at $at_port $lte_lock_check | grep "+QNWLOCK:") lte_lock_status=$(echo $lte_status | awk -F',' '{print $2}') lte_lock_freq=$(echo $lte_status | awk -F',' '{print $3}') lte_lock_pci=$(echo $lte_status | awk -F',' '{print $4}') @@ -1122,13 +1034,7 @@ quectel_get_neighborcell_lte(){ else lte_lock_status="" fi - sh ${SCRIPT_DIR}/modem_at.sh $at_port $at_command > /tmp/quectel_neighborcell - json_init - json_add_object "Feature" - json_add_string "Unlock" "5" - json_add_string "Lock PCI" "6" - json_add_string "Lock ARFCN" "7" - json_close_object + at $at_port $at_command > /tmp/neighborcell json_add_array "NR" json_close_array json_add_array "LTE" @@ -1179,85 +1085,248 @@ quectel_get_neighborcell_lte(){ json_close_object json_select ".." fi - done < /tmp/quectel_neighborcell - json_result=`json_dump` - echo "$json_result" + done < /tmp/neighborcell } -quectel_get_neighborcell(){ - debug "quectel set lockband info" - local at_port="$1" - local platform - local modem_number=$(uci -q get modem.@global[0].modem_number) - for i in $(seq 0 $((modem_number-1))); do - local at_port_tmp=$(uci -q get modem.modem$i.at_port) - if [ "$at_port" = "$at_port_tmp" ]; then - platform=$(uci -q get modem.modem$i.platform) - break +get_neighborcell_unisoc(){ + local at_command='AT+QENG="neighbourcell"' + nr_lock_check="AT+QNWLOCK=\"common/5g\"" + lte_lock_check="AT+QNWLOCK=\"common/lte\"" + lte_status=$(at $at_port $lte_lock_check | grep "+QNWLOCK:") + lte_lock_freq=$(echo $lte_status | awk -F',' '{print $2}') + lte_lock_pci=$(echo $lte_status | awk -F',' '{print $3}') + nr_status=$(at $at_port $nr_lock_check | grep "+QNWLOCK:") + nr_lock_pci=$(echo $nr_status | awk -F',' '{print $2}') + nr_lock_freq=$(echo $nr_status | awk -F',' '{print $3}') + [ -n "$lte_lock_freq" ] && lte_lock_status="locked" + [ -n "$nr_lock_freq" ] && nr_lock_status="locked" + + + at $at_port $at_command > /tmp/neighborcell + json_add_array "NR" + json_close_array + json_add_array "LTE" + json_close_array + json_add_object "lockcell_status" + if [ -n "$lte_lock_status" ]; then + json_add_string "LTE" "$lte_lock_status" + json_add_string "LTE_Freq" "$lte_lock_freq" + json_add_string "LTE_PCI" "$lte_lock_pci" + else + json_add_string "LTE" "unlock" + fi + if [ -n "$nr_lock_status" ]; then + json_add_string "NR" "$nr_lock_status" + json_add_string "NR_Freq" "$nr_lock_freq" + json_add_string "NR_PCI" "$nr_lock_pci" + else + json_add_string "NR" "unlock" + fi + json_close_object + while read line; do + if [ -n "$(echo $line | grep "+QENG:")" ]; then + # +QENG: "neighbourcell intra","LTE",,,< + # RSRQ>,,,,,,,, + # …] + # [+QENG: "neighbourcell inter","LTE",,,< + # RSRQ>,,,,,,, + # …] + # [+QENG:"neighbourcell","WCDMA",,,,,,, + # …] + line=$(echo $line | sed 's/+QENG: //g') + case $line in + *WCDMA*) + type="WCDMA" + + arfcn=$(echo $line | awk -F',' '{print $3}') + pci=$(echo $line | awk -F',' '{print $4}') + rscp=$(echo $line | awk -F',' '{print $6}') + ecno=$(echo $line | awk -F',' '{print $7}') + ;; + *LTE*) + type="LTE" + neighbourcell=$(echo $line | awk -F',' '{print $1}' | tr -d '"') + arfcn=$(echo $line | awk -F',' '{print $3}') + pci=$(echo $line | awk -F',' '{print $4}') + rsrp=$(echo $line | awk -F',' '{print $5}') + rsrq=$(echo $line | awk -F',' '{print $6}') + + ;; + *NR*) + type="NR" + arfcn=$(echo $line | awk -F',' '{print $3}') + pci=$(echo $line | awk -F',' '{print $4}') + rsrp=$(echo $line | awk -F',' '{print $5}') + rsrq=$(echo $line | awk -F',' '{print $6}') + ;; + esac + json_select $type + json_add_object "" + json_add_string "neighbourcell" "$neighbourcell" + json_add_string "arfcn" "$arfcn" + json_add_string "pci" "$pci" + json_add_string "rscp" "$rscp" + json_add_string "ecno" "$ecno" + json_add_string "rsrp" "$rsrp" + json_add_string "rsrq" "$rsrq" + json_close_object + json_select ".." fi - done + done < /tmp/neighborcell +} + +get_neighborcell(){ + m_debug "quectel set lockband info" + json_add_object "neighborcell" case "$platform" in + "lte12"|\ "qualcomm") - quectel_get_neighborcell_qualcomm $at_port + get_neighborcell_qualcomm ;; "unisoc") - quectel_get_neighborcell_unisoc $at_port + get_neighborcell_unisoc ;; "lte") - quectel_get_neighborcell_lte $at_port + get_neighborcell_lte ;; esac + json_close_object } -quectel_setlockcell(){ + + +set_neighborcell(){ #at_port,func,celltype,arfcn,pci,scs,nrband # "lockpci" "1" # "unlockcell" "2" # "manually search" "3" # "reboot modem" "4" + json_param=$1 +# {\"rat\":1,\"pci\":\"113\",\"arfcn\":\"627264\",\"band\":\"\",\"scs\":0}" + rat=$(echo $json_param | jq -r '.rat') + pci=$(echo $json_param | jq -r '.pci') + arfcn=$(echo $json_param | jq -r '.arfcn') + band=$(echo $json_param | jq -r '.band') + scs=$(echo $json_param | jq -r '.scs') + case $platform in + "lte12"|\ + "qualcomm") + lockcell_qualcomm + ;; + "unisoc") + lockcell_unisoc + ;; + "lte") + lockcell_lte + ;; + esac + json_select "result" + json_add_string "setlockcell" "$res" + json_add_string "rat" "$rat" + json_add_string "pci" "$pci" + json_add_string "arfcn" "$arfcn" + json_add_string "band" "$band" + json_add_string "scs" "$scs" + json_close_object +} + +lockcell_qualcomm(){ + if [ -z "$pci" ] && [ -z "$arfcn" ]; then + unlock4g="AT+QNWLOCK=\"common/4g\",0" + unlocknr="AT+QNWLOCK=\"common/5g\",0" + res1=$(at $1 $unlocknr) + res2=$(at $1 $unlock4g) + res=$res1,$res2 + else + lock4g="AT+QNWLOCK=\"common/4g\",1,$arfcn,$pci" + locknr="AT+QNWLOCK=\"common/5g\",1,$pci,$arfcn,$scs,$band" + if [ $rat = "1" ]; then + res=$(at $at_port $locknr) + else + res=$(at $at_port $lock4g) + fi + fi + +} + +lockcell_unisoc(){ + if [ -z "$pci" ] && [ -z "$arfcn" ]; then + unlock4g="AT+QNWLOCK=\"common/lte\",0" + unlocknr="AT+QNWLOCK=\"common/5g\",0" + res1=$(at $at_port $unlocknr) + res2=$(at $at_port $unlock4g) + res=$res1,$res2 + else + lock4g="AT+QNWLOCK=\"common/lte\",1,$arfcn,$pci" + locknr="AT+QNWLOCK=\"common/5g\",1,$arfcn,$pci" + if [ $rat = "1" ]; then + res=$(at $at_port $locknr) + else + res=$(at $at_port $lock4g) + fi + fi +} + +lockcell_lte(){ + if [ -z "$pci" ] && [ -z "$arfcn" ]; then + unlocklte="AT+QNWLOCK=\"common/lte\",0" + res1=$(at $at_port $unlocklte) + res=$res1 + else + if [ -z $pci ] && [ -n $arfcn ]; then + locklte="AT+QNWLOCK=\"common/lte\",1,$arfcn,0" + elif [ -n $pci ] && [ -n $arfcn ]; then + locklte="AT+QNWLOCK=\"common/lte\",2,$arfcn,$pci" + fi + res=$(at $at_port $locklte) + fi +} + +unlockcell(){ + unlock4g="AT+QNWLOCK=\"common/4g\",0" + unlocknr="AT+QNWLOCK=\"common/5g\",0" + res2=$(at $1 $unlocknr) + res3=$(at $1 $unlock4g) +} + +unlockcell_unisoc(){ + unlock4g="AT+QNWLOCK=\"common/lte\",0" + unlocknr="AT+QNWLOCK=\"common/5g\",0" + res2=$(at $1 $unlocknr) + res3=$(at $1 $unlock4g) +} + +unlockcell_lte(){ + unlocklte="AT+QNWLOCK=\"common/lte\",0" + res1=$(at $1 $unlocklte) +} + +lockpci_unisoc(){ local at_port="$1" - local func="$2" - local cell_type="$3" - local arfcn="$4" - local pci="$5" - local scs="$6" - local nrband="$7" - case $func in - "1") - quectel_lockpci $at_port $cell_type $arfcn $pci $scs $nrband + local cell_type="$2" + local arfcn="$3" + local pci="$4" + echo 1:$cell_type 2:$arfcn 3:$pci + case $cell_type in + 0) + lock4g="AT+QNWLOCK=\"common/lte\",1,$arfcn,$pci" + res=$(at $at_port $lock4g) + echo $lock4g res:$res ;; - "2") - quectel_unlockcell $at_port - ;; - - "4") - sh ${SCRIPT_DIR}/modem_reboot.sh $at_port at+cfun=1,1 - ;; - "5") - quectel_unlockcell_lte $at_port - ;; - "6") - quectel_lockpci_lte $at_port $cell_type $arfcn $pci $scs $nrband - ;; - "7") - quectel_lockarfn_lte $at_port $cell_type $arfcn $pci $scs $nrband + 1) + locknr="AT+QNWLOCK=\"common/5g\",1,$arfcn,$pci" + res=$(at $at_port $locknr) + echo $locknr res:$res ;; esac } -quectel_unlockcell(){ - unlock4g="AT+QNWLOCK=\"common/4g\",0" - unlocknr="AT+QNWLOCK=\"common/5g\",0" - res2=$(sh ${SCRIPT_DIR}/modem_at.sh $1 $unlocknr) - res3=$(sh ${SCRIPT_DIR}/modem_at.sh $1 $unlock4g) -} - -quectel_unlockcell_lte(){ - unlocklte="AT+QNWLOCK=\"common/lte\",0" - res1=$(sh ${SCRIPT_DIR}/modem_at.sh $1 $unlocklte) -} - -quectel_lockpci_nr(){ +lockpci_nr(){ local at_port="$1" local cell_type="$2" local arfcn="$3" @@ -1275,15 +1344,15 @@ quectel_lockpci_nr(){ if [ "$cell_type" = "0" ]; then lock4g="AT+QNWLOCK=\"common/4g\",1,$arfcn,$pci" - res=$(sh ${SCRIPT_DIR}/modem_at.sh $at_port $locklte) + res=$(at $at_port $locklte) elif [ "$cell_type" = "1" ]; then locknr="AT+QNWLOCK=\"common/5g\",1,$pci,$arfcn,$scs,$nrband" echo $locknr - res=$(sh ${SCRIPT_DIR}/modem_at.sh $at_port $locknr) + res=$(at $at_port $locknr) fi } -quectel_lockpci_lte(){ +lockpci_lte(){ local at_port="$1" local cell_type="$2" local arfcn="$3" @@ -1291,10 +1360,10 @@ quectel_lockpci_lte(){ local scs="$5" local nrband="$6" locklte="AT+QNWLOCK=\"common/lte\",2,$arfcn,$pci" - res=$(sh ${SCRIPT_DIR}/modem_at.sh $at_port $locklte) + res=$(at $at_port $locklte) } -quectel_lockarfn_lte(){ +lockarfn_lte(){ local at_port="$1" local cell_type="$2" local arfcn="$3" @@ -1302,13 +1371,13 @@ quectel_lockarfn_lte(){ local scs="$5" local nrband="$6" locklte="AT+QNWLOCK=\"common/lte\",1,$arfcn,0" - res=$(sh ${SCRIPT_DIR}/modem_at.sh $at_port $locklte) + res=$(at $at_port $locklte) } #UL_bandwidth # $1:上行带宽数字 -quectel_get_bandwidth() +get_bandwidth() { local network_type="$1" local bandwidth_num="$2" @@ -1336,7 +1405,7 @@ quectel_get_bandwidth() #获取NR子载波间隔 # $1:NR子载波间隔数字 -quectel_get_scs() +get_scs() { local scs case $1 in @@ -1352,7 +1421,7 @@ quectel_get_scs() #获取物理信道 # $1:物理信道数字 -quectel_get_phych() +get_phych() { local phych case $1 in @@ -1364,7 +1433,7 @@ quectel_get_phych() #获取扩频因子 # $1:扩频因子数字 -quectel_get_sf() +get_sf() { local sf case $1 in @@ -1376,7 +1445,7 @@ quectel_get_sf() #获取插槽格式 # $1:插槽格式数字 -quectel_get_slot() +get_slot() { local slot=$1 # case $1 in @@ -1387,12 +1456,12 @@ quectel_get_slot() } #小区信息 -quectel_cell_info() +cell_info() { - debug "Quectel cell info" + m_debug "Quectel cell info" at_command='AT+QENG="servingcell"' - response=$(sh ${SCRIPT_DIR}/modem_at.sh $at_port $at_command) + response=$(at $at_port $at_command) local lte=$(echo "$response" | grep "+QENG: \"LTE\"") local nr5g_nsa=$(echo "$response" | grep "+QENG: \"NR5G-NSA\"") @@ -1407,11 +1476,11 @@ quectel_cell_info() endc_lte_physical_cell_id=$(echo "$lte" | awk -F',' '{print $6}') endc_lte_earfcn=$(echo "$lte" | awk -F',' '{print $7}') endc_lte_freq_band_ind_num=$(echo "$lte" | awk -F',' '{print $8}') - endc_lte_freq_band_ind=$(quectel_get_band "LTE" $endc_lte_freq_band_ind_num) + endc_lte_freq_band_ind=$(get_band "LTE" $endc_lte_freq_band_ind_num) ul_bandwidth_num=$(echo "$lte" | awk -F',' '{print $9}') - endc_lte_ul_bandwidth=$(quectel_get_bandwidth "LTE" $ul_bandwidth_num) + endc_lte_ul_bandwidth=$(get_bandwidth "LTE" $ul_bandwidth_num) dl_bandwidth_num=$(echo "$lte" | awk -F',' '{print $10}') - endc_lte_dl_bandwidth=$(quectel_get_bandwidth "LTE" $dl_bandwidth_num) + endc_lte_dl_bandwidth=$(get_bandwidth "LTE" $dl_bandwidth_num) endc_lte_tac=$(echo "$lte" | awk -F',' '{print $11}') endc_lte_rsrp=$(echo "$lte" | awk -F',' '{print $12}') endc_lte_rsrq=$(echo "$lte" | awk -F',' '{print $13}') @@ -1429,11 +1498,11 @@ quectel_cell_info() endc_nr_rsrq=$(echo "$nr5g_nsa" | awk -F',' '{print $7}') endc_nr_arfcn=$(echo "$nr5g_nsa" | awk -F',' '{print $8}') endc_nr_band_num=$(echo "$nr5g_nsa" | awk -F',' '{print $9}') - endc_nr_band=$(quectel_get_band "NR" $endc_nr_band_num) + endc_nr_band=$(get_band "NR" $endc_nr_band_num) nr_dl_bandwidth_num=$(echo "$nr5g_nsa" | awk -F',' '{print $10}') - endc_nr_dl_bandwidth=$(quectel_get_bandwidth "NR" $nr_dl_bandwidth_num) + endc_nr_dl_bandwidth=$(get_bandwidth "NR" $nr_dl_bandwidth_num) scs_num=$(echo "$nr5g_nsa" | awk -F',' '{print $16}' | sed 's/\r//g') - endc_nr_scs=$(quectel_get_scs $scs_num) + endc_nr_scs=$(get_scs $scs_num) else #SA,LTE,WCDMA模式 response=$(echo "$response" | grep "+QENG:") @@ -1449,14 +1518,14 @@ quectel_cell_info() nr_tac=$(echo "$response" | awk -F',' '{print $9}') nr_arfcn=$(echo "$response" | awk -F',' '{print $10}') nr_band_num=$(echo "$response" | awk -F',' '{print $11}') - nr_band=$(quectel_get_band "NR" $nr_band_num) + nr_band=$(get_band "NR" $nr_band_num) nr_dl_bandwidth_num=$(echo "$response" | awk -F',' '{print $12}') - nr_dl_bandwidth=$(quectel_get_bandwidth "NR" $nr_dl_bandwidth_num) + nr_dl_bandwidth=$(get_bandwidth "NR" $nr_dl_bandwidth_num) nr_rsrp=$(echo "$response" | awk -F',' '{print $13}') nr_rsrq=$(echo "$response" | awk -F',' '{print $14}') nr_sinr=$(echo "$response" | awk -F',' '{print $15}') nr_scs_num=$(echo "$response" | awk -F',' '{print $16}') - nr_scs=$(quectel_get_scs $nr_scs_num) + nr_scs=$(get_scs $nr_scs_num) nr_srxlev=$(echo "$response" | awk -F',' '{print $17}' | sed 's/\r//g') ;; "LTE"|"CAT-M"|"CAT-NB") @@ -1468,11 +1537,11 @@ quectel_cell_info() lte_physical_cell_id=$(echo "$response" | awk -F',' '{print $8}') lte_earfcn=$(echo "$response" | awk -F',' '{print $9}') lte_freq_band_ind_num=$(echo "$response" | awk -F',' '{print $10}') - lte_freq_band_ind=$(quectel_get_band "LTE" $lte_freq_band_ind_num) + lte_freq_band_ind=$(get_band "LTE" $lte_freq_band_ind_num) ul_bandwidth_num=$(echo "$response" | awk -F',' '{print $11}') - lte_ul_bandwidth=$(quectel_get_bandwidth "LTE" $ul_bandwidth_num) + lte_ul_bandwidth=$(get_bandwidth "LTE" $ul_bandwidth_num) dl_bandwidth_num=$(echo "$response" | awk -F',' '{print $12}') - lte_dl_bandwidth=$(quectel_get_bandwidth "LTE" $dl_bandwidth_num) + lte_dl_bandwidth=$(get_bandwidth "LTE" $dl_bandwidth_num) lte_tac=$(echo "$response" | awk -F',' '{print $13}') lte_rsrp=$(echo "$response" | awk -F',' '{print $14}') lte_rsrq=$(echo "$response" | awk -F',' '{print $15}') @@ -1494,444 +1563,112 @@ quectel_cell_info() wcdma_rscp=$(echo "$response" | awk -F',' '{print $11}') wcdma_ecio=$(echo "$response" | awk -F',' '{print $12}') wcdma_phych_num=$(echo "$response" | awk -F',' '{print $13}') - wcdma_phych=$(quectel_get_phych $wcdma_phych_num) + wcdma_phych=$(get_phych $wcdma_phych_num) wcdma_sf_num=$(echo "$response" | awk -F',' '{print $14}') - wcdma_sf=$(quectel_get_sf $wcdma_sf_num) + wcdma_sf=$(get_sf $wcdma_sf_num) wcdma_slot_num=$(echo "$response" | awk -F',' '{print $15}') - wcdma_slot=$(quectel_get_slot $wcdma_slot_num) + wcdma_slot=$(get_slot $wcdma_slot_num) wcdma_speech_code=$(echo "$response" | awk -F',' '{print $16}') wcdma_com_mod=$(echo "$response" | awk -F',' '{print $17}' | sed 's/\r//g') ;; esac fi - - return - - NR_NSA=$(echo $response | grep -o -i "+QENG:[ ]\?\"NR5G-NSA\",") - NR_SA=$(echo $response | grep -o -i "+QENG: \"SERVINGCELL\",[^,]\+,\"NR5G-SA\",\"[DFT]\{3\}\",") - if [ -n "$NR_NSA" ]; then - QENG=",,"$(echo $response" " | grep -o -i "+QENG: \"LTE\".\+\"NR5G-NSA\"," | tr " " ",") - QENG5=$(echo $response | grep -o -i "+QENG:[ ]\?\"NR5G-NSA\",[0-9]\{3\},[0-9]\{2,3\},[0-9]\{1,5\},-[0-9]\{2,5\},[-0-9]\{1,3\},-[0-9]\{2,3\},[0-9]\{1,7\},[0-9]\{1,3\}.\{1,6\}") - if [ -z "$QENG5" ]; then - QENG5=$(echo $response | grep -o -i "+QENG:[ ]\?\"NR5G-NSA\",[0-9]\{3\},[0-9]\{2,3\},[0-9]\{1,5\},-[0-9]\{2,3\},[-0-9]\{1,3\},-[0-9]\{2,3\}") - if [ -n "$QENG5" ]; then - QENG5=$QENG5",," - fi - fi - elif [ -n "$NR_SA" ]; then - QENG=$(echo $NR_SA | tr " " ",") - QENG5=$(echo $response | grep -o -i "+QENG: \"SERVINGCELL\",[^,]\+,\"NR5G-SA\",\"[DFT]\{3\}\",[ 0-9]\{3,4\},[0-9]\{2,3\},[0-9A-F]\{1,10\},[0-9]\{1,5\},[0-9A-F]\{2,6\},[0-9]\{6,7\},[0-9]\{1,3\},[0-9]\{1,2\},-[0-9]\{2,5\},-[0-9]\{2,3\},[-0-9]\{1,3\}") - else - QENG=$(echo $response" " | grep -o -i "+QENG: [^ ]\+ " | tr " " ",") - fi - - RAT=$(echo $QENG | cut -d, -f4 | grep -o "[-A-Z5]\{3,7\}") - case $RAT in - "GSM") - # MODE="GSM" - ;; - "WCDMA") - channel=$(echo $QENG | cut -d, -f9) - rscp="-"$(echo $QENG | cut -d, -f12 | grep -o "[0-9]\{1,3\}") - ecio=$(echo $QENG | cut -d, -f13) - ecio="-"$(echo $ecio | grep -o "[0-9]\{1,3\}") - ;; - "LTE"|"CAT-M"|"CAT-NB") - PCI=$(echo $QENG | cut -d, -f9) - channel=$(echo $QENG | cut -d, -f10) - LBAND=$(echo $QENG | cut -d, -f11 | grep -o "[0-9]\{1,3\}") - BW=$(echo $QENG | cut -d, -f12) - lte_bw - BWU=$BW - BW=$(echo $QENG | cut -d, -f13) - lte_bw - BWD=$BW - if [ -z "$BWD" ]; then - BWD="unknown" - fi - if [ -z "$BWU" ]; then - BWU="unknown" - fi - if [ -n "$LBAND" ]; then - LBAND="B"$LBAND" (Bandwidth $BWD MHz Down | $BWU MHz Up)" - fi - RSRP=$(echo $QENG | cut -d, -f15 | grep -o "[0-9]\{1,3\}") - if [ -n "$RSRP" ]; then - RSCP="-"$RSRP - RSRPLTE=$RSCP - fi - rsrq=$(echo $QENG | cut -d, -f16 | grep -o "[0-9]\{1,3\}") - if [ -n "$rsrq" ]; then - ecio="-"$rsrq - fi - rssi=$(echo $QENG | cut -d, -f17 | grep -o "\-[0-9]\{1,3\}") - if [ -n "$rssi" ]; then - CSQ_RSSI=$rssi" dBm" - fi - sinrr=$(echo $QENG | cut -d, -f18 | grep -o "[0-9]\{1,3\}") - if [ -n "$sinrr" ]; then - if [ $sinrr -le 25 ]; then - sinrr=$((($(echo $sinrr) * 2) -20))" dB" - fi - fi - - if [ -n "$NR_NSA" ]; then - if [ -n "$QENG5" ] && [ -n "$LBAND" ] && [ "$RSCP" != "-" ] && [ "$ecio" != "-" ]; then - PCI="$PCI, "$(echo $QENG5 | cut -d, -f4) - SCHV=$(echo $QENG5 | cut -d, -f8) - SLBV=$(echo $QENG5 | cut -d, -f9) - BW=$(echo $QENG5 | cut -d, -f10 | grep -o "[0-9]\{1,3\}") - if [ -n "$SLBV" ]; then - LBAND=$LBAND"
n"$SLBV - if [ -n "$BW" ]; then - nr_bw - LBAND=$LBAND" (Bandwidth $BW MHz)" - fi - if [ "$SCHV" -ge 123400 ]; then - channel=$channel", "$SCHV - else - channel=$channel", -" - fi - else - LBAND=$LBAND"
nxx (unknown NR5G band)" - channel=$channel", -" - fi - RSCP=$RSCP" dBm
"$(echo $QENG5 | cut -d, -f5) - sinrr=$(echo $QENG5 | cut -d, -f6 | grep -o "[0-9]\{1,3\}") - if [ -n "$sinrr" ]; then - if [ $sinrr -le 30 ]; then - SINR=$SINR"
"$((($(echo $sinrr) * 2) -20))" dB" - fi - fi - ecio=$ecio" (4G) dB
"$(echo $QENG5 | cut -d, -f7)" (5G) " - fi - fi - if [ -z "$LBAND" ]; then - LBAND="-" - else - if [ -n "$QCA" ]; then - QCA=$(echo $QCA | grep -o "\"S[CS]\{2\}\"[-0-9A-Z,\"]\+") - for QCAL in $(echo "$QCA"); do - if [ $(echo "$QCAL" | cut -d, -f7) = "2" ]; then - SCHV=$(echo $QCAL | cut -d, -f2 | grep -o "[0-9]\+") - SRATP="B" - if [ -n "$SCHV" ]; then - channel="$channel, $SCHV" - if [ "$SCHV" -gt 123400 ]; then - SRATP="n" - fi - fi - SLBV=$(echo $QCAL | cut -d, -f6 | grep -o "[0-9]\{1,2\}") - if [ -n "$SLBV" ]; then - LBAND=$LBAND"
"$SRATP$SLBV - BWD=$(echo $QCAL | cut -d, -f3 | grep -o "[0-9]\{1,3\}") - if [ -n "$BWD" ]; then - UPDOWN=$(echo $QCAL | cut -d, -f13) - case "$UPDOWN" in - "UL" ) - CATYPE="CA"$(printf "\xe2\x86\x91") ;; - "DL" ) - CATYPE="CA"$(printf "\xe2\x86\x93") ;; - * ) - CATYPE="CA" ;; - esac - if [ $BWD -gt 14 ]; then - LBAND=$LBAND" ("$CATYPE", Bandwidth "$(($(echo $BWD) / 5))" MHz)" - else - LBAND=$LBAND" ("$CATYPE", Bandwidth 1.4 MHz)" - fi - fi - LBAND=$LBAND - fi - PCI="$PCI, "$(echo $QCAL | cut -d, -f8) - fi - done - fi - fi - if [ $RAT = "CAT-M" ] || [ $RAT = "CAT-NB" ]; then - LBAND="B$(echo $QENG | cut -d, -f11) ($RAT)" - fi - ;; - "NR5G-SA") - if [ -n "$QENG5" ]; then - #AT+qnwcfg="NR5G_AMBR" #查询速度 - PCI=$(echo $QENG5 | cut -d, -f8) - channel=$(echo $QENG5 | cut -d, -f10) - LBAND=$(echo $QENG5 | cut -d, -f11) - BW=$(echo $QENG5 | cut -d, -f12) - nr_bw - LBAND="n"$LBAND" (Bandwidth $BW MHz)" - RSCP=$(echo $QENG5 | cut -d, -f13) - ecio=$(echo $QENG5 | cut -d, -f14) - if [ "$CSQ_PER" = "-" ]; then - RSSI=$(rsrp2rssi $RSCP $BW) - CSQ_PER=$((100 - (($RSSI + 51) * 100/-62)))"%" - CSQ=$((($RSSI + 113) / 2)) - CSQ_RSSI=$RSSI" dBm" - fi - SINRR=$(echo $QENG5 | cut -d, -f15 | grep -o "[0-9]\{1,3\}") - if [ -n "$SINRR" ]; then - if [ $SINRR -le 30 ]; then - SINR=$((($(echo $SINRR) * 2) -20))" dB" - fi - fi - fi - ;; + class="Cell Information" + add_plain_info_entry "network_mode" "$network_mode" "Network Mode" + case $network_mode in + "NR5G-SA Mode") + add_plain_info_entry "MMC" "$nr_mcc" "Mobile Country Code" + add_plain_info_entry "MNC" "$nr_mnc" "Mobile Network Code" + add_plain_info_entry "Duplex Mode" "$nr_duplex_mode" "Duplex Mode" + add_plain_info_entry "Cell ID" "$nr_cell_id" "Cell ID" + add_plain_info_entry "Physical Cell ID" "$nr_physical_cell_id" "Physical Cell ID" + add_plain_info_entry "TAC" "$nr_tac" "Tracking area code of cell servedby neighbor Enb" + add_plain_info_entry "ARFCN" "$nr_arfcn" "Absolute Radio-Frequency Channel Number" + add_plain_info_entry "Band" "$nr_band" "Band" + add_plain_info_entry "DL Bandwidth" "$nr_dl_bandwidth" "DL Bandwidth" + add_bar_info_entry "RSRP" "$nr_rsrp" "Reference Signal Received Power" -187 -29 Dbm + add_bar_info_entry "RSRQ" "$nr_rsrq" "Reference Signal Received Quality" -43 20 Dbm + add_bar_info_entry "SINR" "$nr_sinr" "Signal to Interference plus Noise Ratio Bandwidth" -23 40 DB + add_plain_info_entry "RxLev" "$nr_rxlev" "Received Signal Level" + add_plain_info_entry "SCS" "$nr_scs" "SCS" + add_plain_info_entry "Srxlev" "$nr_srxlev" "Serving Cell Receive Level" + + ;; + "EN-DC Mode") + add_plain_info_entry "LTE" "LTE" "" + add_plain_info_entry "MCC" "$endc_lte_mcc" "Mobile Country Code" + add_plain_info_entry "MNC" "$endc_lte_mnc" "Mobile Network Code" + add_plain_info_entry "Duplex Mode" "$endc_lte_duplex_mode" "Duplex Mode" + add_plain_info_entry "Cell ID" "$endc_lte_cell_id" "Cell ID" + add_plain_info_entry "Physical Cell ID" "$endc_lte_physical_cell_id" "Physical Cell ID" + add_plain_info_entry "EARFCN" "$endc_lte_earfcn" "E-UTRA Absolute Radio Frequency Channel Number" + add_plain_info_entry "Freq band indicator" "$endc_lte_freq_band_ind" "Freq band indicator" + add_plain_info_entry "Band" "$endc_lte_band" "Band" + add_plain_info_entry "UL Bandwidth" "$endc_lte_ul_bandwidth" "UL Bandwidth" + add_plain_info_entry "DL Bandwidth" "$endc_lte_dl_bandwidth" "DL Bandwidth" + add_plain_info_entry "TAC" "$endc_lte_tac" "Tracking area code of cell servedby neighbor Enb" + add_bar_info_entry "RSRP" "$endc_lte_rsrp" "Reference Signal Received Power" -140 -44 Dbm + add_bar_info_entry "RSRQ" "$endc_lte_rsrq" "Reference Signal Received Quality" -20 20 Dbm + add_bar_info_entry "RSSI" "$endc_lte_rssi" "Received Signal Strength Indicator" -140 -44 Dbm + add_bar_info_entry "SINR" "$endc_lte_sinr" "Signal to Interference plus Noise Ratio Bandwidth" -23 40 DB + add_plain_info_entry "RxLev" "$endc_lte_rxlev" "Received Signal Level" + add_plain_info_entry "RSSNR" "$endc_lte_rssnr" "Radio Signal Strength Noise Ratio" + add_plain_info_entry "CQI" "$endc_lte_cql" "Channel Quality Indicator" + add_plain_info_entry "TX Power" "$endc_lte_tx_power" "TX Power" + add_plain_info_entry "Srxlev" "$endc_lte_srxlev" "Serving Cell Receive Level" + add_plain_info_entry NR5G-NSA "NR5G-NSA" "" + add_plain_info_entry "MCC" "$endc_nr_mcc" "Mobile Country Code" + add_plain_info_entry "MNC" "$endc_nr_mnc" "Mobile Network Code" + add_plain_info_entry "Physical Cell ID" "$endc_nr_physical_cell_id" "Physical Cell ID" + add_plain_info_entry "ARFCN" "$endc_nr_arfcn" "Absolute Radio-Frequency Channel Number" + add_plain_info_entry "Band" "$endc_nr_band" "Band" + add_plain_info_entry "DL Bandwidth" "$endc_nr_dl_bandwidth" "DL Bandwidth" + add_bar_info_entry "RSRP" "$endc_nr_rsrp" "Reference Signal Received Power" -187 -29 Dbm + add_bar_info_entry "RSRQ" "$endc_nr_rsrq" "Reference Signal Received Quality" -43 20 Dbm + add_bar_info_entry "SINR" "$endc_nr_sinr" "Signal to Interference plus Noise Ratio Bandwidth" -23 40 DB + add_plain_info_entry "SCS" "$endc_nr_scs" "SCS" + ;; + "LTE Mode") + add_plain_info_entry "MCC" "$lte_mcc" "Mobile Country Code" + add_plain_info_entry "MNC" "$lte_mnc" "Mobile Network Code" + add_plain_info_entry "Duplex Mode" "$lte_duplex_mode" "Duplex Mode" + add_plain_info_entry "Cell ID" "$lte_cell_id" "Cell ID" + add_plain_info_entry "Physical Cell ID" "$lte_physical_cell_id" "Physical Cell ID" + add_plain_info_entry "EARFCN" "$lte_earfcn" "E-UTRA Absolute Radio Frequency Channel Number" + add_plain_info_entry "Freq band indicator" "$lte_freq_band_ind" "Freq band indicator" + add_plain_info_entry "Band" "$lte_band" "Band" + add_plain_info_entry "UL Bandwidth" "$lte_ul_bandwidth" "UL Bandwidth" + add_plain_info_entry "DL Bandwidth" "$lte_dl_bandwidth" "DL Bandwidth" + add_plain_info_entry "TAC" "$lte_tac" "Tracking area code of cell servedby neighbor Enb" + add_bar_info_entry "RSRQ" "$lte_rsrq" "Reference Signal Received Quality" -20 20 Dbm + add_bar_info_entry "RSSI" "$lte_rssi" "Received Signal Strength Indicator" -140 -44 Dbm + add_bar_info_entry "SINR" "$lte_sinr" "Signal to Interference plus Noise Ratio Bandwidth" -23 40 DB + add_plain_info_entry "RxLev" "$lte_rxlev" "Received Signal Level" + add_plain_info_entry "RSSNR" "$lte_rssnr" "Radio Signal Strength Noise Ratio" + add_plain_info_entry "CQI" "$lte_cql" "Channel Quality Indicator" + add_plain_info_entry "TX Power" "$lte_tx_power" "TX Power" + add_plain_info_entry "Srxlev" "$lte_srxlev" "Serving Cell Receive Level" + + ;; + "WCDMA Mode") + add_plain_info_entry "MCC" "$wcdma_mcc" "Mobile Country Code" + add_plain_info_entry "MNC" "$wcdma_mnc" "Mobile Network Code" + add_plain_info_entry "LAC" "$wcdma_lac" "Location Area Code" + add_plain_info_entry "Cell ID" "$wcdma_cell_id" "Cell ID" + add_plain_info_entry "UARFCN" "$wcdma_uarfcn" "UTRA Absolute Radio Frequency Channel Number" + add_plain_info_entry "PSC" "$wcdma_psc" "Primary Scrambling Code" + add_plain_info_entry "RAC" "$wcdma_rac" "Routing Area Code" + add_plain_info_entry "Band" "$wcdma_band" "Band" + add_bar_info_entry "RSCP" "$wcdma_rscp" "Received Signal Code Power" -120 -25 Dbm + add_plain_info_entry "Ec/Io" "$wcdma_ecio" "Ec/Io" + add_plain_info_entry "Ec/No" "$wcdma_ecno" "Ec/No" + add_plain_info_entry "Physical Channel" "$wcdma_phych" "Physical Channel" + add_plain_info_entry "Spreading Factor" "$wcdma_sf" "Spreading Factor" + add_plain_info_entry "Slot" "$wcdma_slot" "Slot" + add_plain_info_entry "Speech Code" "$wcdma_speech_code" "Speech Code" + add_plain_info_entry "Compression Mode" "$wcdma_com_mod" "Compression Mode" + add_plain_info_entry "RxLev" "$wcdma_rxlev" "RxLev" + + ;; esac } - -# SIMCOM获取基站信息 -Quectel_Cellinfo() -{ - # return - #cellinfo0.gcom - OX1=$( sh modem_at.sh $at_port "AT+COPS=3,0;+COPS?") - OX2=$( sh modem_at.sh $at_port "AT+COPS=3,2;+COPS?") - OX=$OX1" "$OX2 - - #cellinfo.gcom - OY1=$( sh modem_at.sh $at_port "AT+CREG=2;+CREG?;+CREG=0") - OY2=$( sh modem_at.sh $at_port "AT+CEREG=2;+CEREG?;+CEREG=0") - OY3=$( sh modem_at.sh $at_port "AT+C5GREG=2;+C5GREG?;+C5GREG=0") - OY=$OY1" "$OY2" "$OY3 - - - OXx=$OX - OX=$(echo $OX | tr 'a-z' 'A-Z') - OY=$(echo $OY | tr 'a-z' 'A-Z') - OX=$OX" "$OY - - #debug "$OX" - #debug "$OY" - - COPS="-" - COPS_MCC="-" - COPS_MNC="-" - COPSX=$(echo $OXx | grep -o "+COPS: [01],0,.\+," | cut -d, -f3 | grep -o "[^\"]\+") - - if [ "x$COPSX" != "x" ]; then - COPS=$COPSX - fi - - COPSX=$(echo $OX | grep -o "+COPS: [01],2,.\+," | cut -d, -f3 | grep -o "[^\"]\+") - - if [ "x$COPSX" != "x" ]; then - COPS_MCC=${COPSX:0:3} - COPS_MNC=${COPSX:3:3} - if [ "$COPS" = "-" ]; then - COPS=$(awk -F[\;] '/'$COPS'/ {print $2}' $ROOTER/signal/mccmnc.data) - [ "x$COPS" = "x" ] && COPS="-" - fi - fi - - if [ "$COPS" = "-" ]; then - COPS=$(echo "$O" | awk -F[\"] '/^\+COPS: 0,0/ {print $2}') - if [ "x$COPS" = "x" ]; then - COPS="-" - COPS_MCC="-" - COPS_MNC="-" - fi - fi - COPS_MNC=" "$COPS_MNC - - OX=$(echo "${OX//[ \"]/}") - CID="" - CID5="" - RAT="" - REGV=$(echo "$OX" | grep -o "+C5GREG:2,[0-9],[A-F0-9]\{2,6\},[A-F0-9]\{5,10\},[0-9]\{1,2\}") - if [ -n "$REGV" ]; then - LAC5=$(echo "$REGV" | cut -d, -f3) - LAC5=$LAC5" ($(printf "%d" 0x$LAC5))" - CID5=$(echo "$REGV" | cut -d, -f4) - CID5L=$(printf "%010X" 0x$CID5) - RNC5=${CID5L:1:6} - RNC5=$RNC5" ($(printf "%d" 0x$RNC5))" - CID5=${CID5L:7:3} - CID5="Short $(printf "%X" 0x$CID5) ($(printf "%d" 0x$CID5)), Long $(printf "%X" 0x$CID5L) ($(printf "%d" 0x$CID5L))" - RAT=$(echo "$REGV" | cut -d, -f5) - fi - REGV=$(echo "$OX" | grep -o "+CEREG:2,[0-9],[A-F0-9]\{2,4\},[A-F0-9]\{5,8\}") - REGFMT="3GPP" - if [ -z "$REGV" ]; then - REGV=$(echo "$OX" | grep -o "+CEREG:2,[0-9],[A-F0-9]\{2,4\},[A-F0-9]\{1,3\},[A-F0-9]\{5,8\}") - REGFMT="SW" - fi - if [ -n "$REGV" ]; then - LAC=$(echo "$REGV" | cut -d, -f3) - LAC=$(printf "%04X" 0x$LAC)" ($(printf "%d" 0x$LAC))" - if [ $REGFMT = "3GPP" ]; then - CID=$(echo "$REGV" | cut -d, -f4) - else - CID=$(echo "$REGV" | cut -d, -f5) - fi - CIDL=$(printf "%08X" 0x$CID) - RNC=${CIDL:1:5} - RNC=$RNC" ($(printf "%d" 0x$RNC))" - CID=${CIDL:6:2} - CID="Short $(printf "%X" 0x$CID) ($(printf "%d" 0x$CID)), Long $(printf "%X" 0x$CIDL) ($(printf "%d" 0x$CIDL))" - - else - REGV=$(echo "$OX" | grep -o "+CREG:2,[0-9],[A-F0-9]\{2,4\},[A-F0-9]\{2,8\}") - if [ -n "$REGV" ]; then - LAC=$(echo "$REGV" | cut -d, -f3) - CID=$(echo "$REGV" | cut -d, -f4) - if [ ${#CID} -gt 4 ]; then - LAC=$(printf "%04X" 0x$LAC)" ($(printf "%d" 0x$LAC))" - CIDL=$(printf "%08X" 0x$CID) - RNC=${CIDL:1:3} - CID=${CIDL:4:4} - CID="Short $(printf "%X" 0x$CID) ($(printf "%d" 0x$CID)), Long $(printf "%X" 0x$CIDL) ($(printf "%d" 0x$CIDL))" - else - LAC="" - fi - else - LAC="" - fi - fi - REGSTAT=$(echo "$REGV" | cut -d, -f2) - if [ "$REGSTAT" == "5" -a "$COPS" != "-" ]; then - COPS_MNC=$COPS_MNC" (Roaming)" - fi - if [ -n "$CID" -a -n "$CID5" ] && [ "$RAT" == "13" -o "$RAT" == "10" ]; then - LAC="4G $LAC, 5G $LAC5" - CID="4G $CID
5G $CID5" - RNC="4G $RNC, 5G $RNC5" - elif [ -n "$CID5" ]; then - LAC=$LAC5 - CID=$CID5 - RNC=$RNC5 - fi - if [ -z "$LAC" ]; then - LAC="-" - CID="-" - RNC="-" - fi -} - -#获取移远模组信息 -# $1:AT串口 -# $2:平台 -# $3:连接定义 -get_quectel_info() -{ - debug "get quectel info" - #设置AT串口 - at_port="$1" - platform="$2" - define_connect="$3" - - #基本信息 - quectel_base_info - - #SIM卡信息 - quectel_sim_info - if [ "$sim_status" != "ready" ]; then - return - fi - - #网络信息 - quectel_network_info - if [ "$connect_status" != "connect" ]; then - return - fi - - #小区信息 - quectel_cell_info - - return - - # Quectel_Cellinfo - - # - OX=$( sh modem_at.sh $at_port "AT+QCAINFO" | grep "+QCAINFO:" ) - QCA=$(echo $OX" " | grep -o -i "+QCAINFO: \"S[CS]\{2\}\".\+NWSCANMODE" | tr " " ",") - - - # - OX=$( sh modem_at.sh $at_port 'AT+QCFG="nwscanmode"' | grep "+QCAINFO:" ) - QNSM=$(echo $OX | grep -o -i "+QCFG: \"NWSCANMODE\",[0-9]") - QNSM=$(echo "$QNSM" | grep -o "[0-9]") - if [ -n "$QNSM" ]; then - MODTYPE="6" - case $QNSM in - "0" ) - NETMODE="1" ;; - "1" ) - NETMODE="3" ;; - "2"|"5" ) - NETMODE="5" ;; - "3" ) - NETMODE="7" ;; - esac - fi - if [ -n "$QNWP" ]; then - MODTYPE="6" - case $QNWP in - "AUTO" ) - NETMODE="1" ;; - "WCDMA" ) - NETMODE="5" ;; - "LTE" ) - NETMODE="7" ;; - "LTE:NR5G" ) - NETMODE="8" ;; - "NR5G" ) - NETMODE="9" ;; - esac - fi - - - # - OX=$( sh modem_at.sh $at_port 'AT+QNWPREFCFG="mode_pref"' | grep "+QNWPREFCFG:" ) - QNWP=$(echo $OX | grep -o -i "+QNWPREFCFG: \"MODE_PREF\",[A-Z5:]\+" | cut -d, -f2) - - # - OX=$( sh modem_at.sh $at_port "AT+QRSRP" | grep "+QRSRP:" ) - QRSRP=$(echo "$OX" | grep -o -i "+QRSRP:[^,]\+,-[0-9]\{1,5\},-[0-9]\{1,5\},-[0-9]\{1,5\}[^ ]*") - if [ -n "$QRSRP" ] && [ "$RAT" != "WCDMA" ]; then - QRSRP1=$(echo $QRSRP | cut -d, -f1 | grep -o "[-0-9]\+") - QRSRP2=$(echo $QRSRP | cut -d, -f2) - QRSRP3=$(echo $QRSRP | cut -d, -f3) - QRSRP4=$(echo $QRSRP | cut -d, -f4) - QRSRPtype=$(echo $QRSRP | cut -d, -f5) - if [ "$QRSRPtype" == "NR5G" ]; then - if [ -n "$NR_SA" ]; then - RSCP=$QRSRP1 - if [ -n "$QRPRP2" -a "$QRSRP2" != "-32768" ]; then - RSCP1="RxD "$QRSRP2 - fi - if [ -n "$QRSRP3" -a "$QRSRP3" != "-32768" ]; then - RSCP=$RSCP" dBm
"$QRSRP3 - fi - if [ -n "$QRSRP4" -a "$QRSRP4" != "-32768" ]; then - RSCP1="RxD "$QRSRP4 - fi - else - RSCP=$RSRPLTE - if [ -n "$QRSRP1" -a "$QRSRP1" != "-32768" ]; then - RSCP=$RSCP" (4G) dBm
"$QRSRP1 - if [ -n "$QRSRP2" -a "$QRSRP2" != "-32768" ]; then - RSCP="$RSCP,$QRSRP2" - if [ -n "$QRSRP3" -a "$QRSRP3" != "-32768" ]; then - RSCP="$RSCP,$QRSRP3" - if [ -n "$QRSRP4" -a "$QRSRP4" != "-32768" ]; then - RSCP="$RSCP,$QRSRP4" - fi - fi - RSCP=$RSCP" (5G) " - fi - fi - fi - elif [ "$QRSRP2$QRSRP3$QRSRP4" != "-44-44-44" -a -z "$QENG5" ]; then - RSCP=$QRSRP1 - if [ "$QRSRP3$QRSRP4" == "-140-140" -o "$QRSRP3$QRSRP4" == "-44-44" -o "$QRSRP3$QRSRP4" == "-32768-32768" ]; then - RSCP1="RxD "$(echo $QRSRP | cut -d, -f2) - else - RSCP=$RSCP" dBm (RxD "$QRSRP2" dBm)
"$QRSRP3 - RSCP1="RxD "$QRSRP4 - fi - fi - fi - - -} diff --git a/luci-app-modem/root/usr/share/modem/simcom.sh b/luci-app-modem/root/usr/share/modem/simcom.sh deleted file mode 100755 index 502f58a..0000000 --- a/luci-app-modem/root/usr/share/modem/simcom.sh +++ /dev/null @@ -1,303 +0,0 @@ -#!/bin/sh -# Copyright (C) 2023 Siriling - -#脚本目录 -SCRIPT_DIR="/usr/share/modem" - -#查询信息强度 -All_CSQ() -{ - debug "All_CSQ" - #信号 - OX=$( sh modem_at.sh $at_port "AT+CSQ" |grep "+CSQ:") - OX=$(echo $OX | tr 'a-z' 'A-Z') - CSQ=$(echo "$OX" | grep -o "+CSQ: [0-9]\{1,2\}" | grep -o "[0-9]\{1,2\}") - if [ $CSQ = "99" ]; then - CSQ="" - fi - if [ -n "$CSQ" ]; then - CSQ_PER=$(($CSQ * 100/31))"%" - CSQ_RSSI=$((2 * CSQ - 113))" dBm" - else - CSQ="-" - CSQ_PER="-" - CSQ_RSSI="-" - fi -} - -# SIMCOM获取基站信息 -SIMCOM_Cellinfo() -{ - #baseinfo.gcom - OX=$( sh modem_at.sh 2 "ATI") - OX=$( sh modem_at.sh 2 "AT+CGEQNEG=1") - - #cellinfo0.gcom - OX1=$( sh modem_at.sh 2 "AT+COPS=3,0;+COPS?") - OX2=$( sh modem_at.sh 2 "AT+COPS=3,2;+COPS?") - OX=$OX1" "$OX2 - - #cellinfo.gcom - OY1=$( sh modem_at.sh 2 "AT+CREG=2;+CREG?;+CREG=0") - OY2=$( sh modem_at.sh 2 "AT+CEREG=2;+CEREG?;+CEREG=0") - OY3=$( sh modem_at.sh 2 "AT+C5GREG=2;+C5GREG?;+C5GREG=0") - OY=$OY1" "$OY2" "$OY3 - - - OXx=$OX - OX=$(echo $OX | tr 'a-z' 'A-Z') - OY=$(echo $OY | tr 'a-z' 'A-Z') - OX=$OX" "$OY - - #debug "$OX" - #debug "$OY" - - COPS="-" - COPS_MCC="-" - COPS_MNC="-" - COPSX=$(echo $OXx | grep -o "+COPS: [01],0,.\+," | cut -d, -f3 | grep -o "[^\"]\+") - - if [ "x$COPSX" != "x" ]; then - COPS=$COPSX - fi - - COPSX=$(echo $OX | grep -o "+COPS: [01],2,.\+," | cut -d, -f3 | grep -o "[^\"]\+") - - if [ "x$COPSX" != "x" ]; then - COPS_MCC=${COPSX:0:3} - COPS_MNC=${COPSX:3:3} - if [ "$COPS" = "-" ]; then - COPS=$(awk -F[\;] '/'$COPS'/ {print $2}' $ROOTER/signal/mccmnc.data) - [ "x$COPS" = "x" ] && COPS="-" - fi - fi - - if [ "$COPS" = "-" ]; then - COPS=$(echo "$O" | awk -F[\"] '/^\+COPS: 0,0/ {print $2}') - if [ "x$COPS" = "x" ]; then - COPS="-" - COPS_MCC="-" - COPS_MNC="-" - fi - fi - COPS_MNC=" "$COPS_MNC - - OX=$(echo "${OX//[ \"]/}") - CID="" - CID5="" - RAT="" - REGV=$(echo "$OX" | grep -o "+C5GREG:2,[0-9],[A-F0-9]\{2,6\},[A-F0-9]\{5,10\},[0-9]\{1,2\}") - if [ -n "$REGV" ]; then - LAC5=$(echo "$REGV" | cut -d, -f3) - LAC5=$LAC5" ($(printf "%d" 0x$LAC5))" - CID5=$(echo "$REGV" | cut -d, -f4) - CID5L=$(printf "%010X" 0x$CID5) - RNC5=${CID5L:1:6} - RNC5=$RNC5" ($(printf "%d" 0x$RNC5))" - CID5=${CID5L:7:3} - CID5="Short $(printf "%X" 0x$CID5) ($(printf "%d" 0x$CID5)), Long $(printf "%X" 0x$CID5L) ($(printf "%d" 0x$CID5L))" - RAT=$(echo "$REGV" | cut -d, -f5) - fi - REGV=$(echo "$OX" | grep -o "+CEREG:2,[0-9],[A-F0-9]\{2,4\},[A-F0-9]\{5,8\}") - REGFMT="3GPP" - if [ -z "$REGV" ]; then - REGV=$(echo "$OX" | grep -o "+CEREG:2,[0-9],[A-F0-9]\{2,4\},[A-F0-9]\{1,3\},[A-F0-9]\{5,8\}") - REGFMT="SW" - fi - if [ -n "$REGV" ]; then - LAC=$(echo "$REGV" | cut -d, -f3) - LAC=$(printf "%04X" 0x$LAC)" ($(printf "%d" 0x$LAC))" - if [ $REGFMT = "3GPP" ]; then - CID=$(echo "$REGV" | cut -d, -f4) - else - CID=$(echo "$REGV" | cut -d, -f5) - fi - CIDL=$(printf "%08X" 0x$CID) - RNC=${CIDL:1:5} - RNC=$RNC" ($(printf "%d" 0x$RNC))" - CID=${CIDL:6:2} - CID="Short $(printf "%X" 0x$CID) ($(printf "%d" 0x$CID)), Long $(printf "%X" 0x$CIDL) ($(printf "%d" 0x$CIDL))" - - else - REGV=$(echo "$OX" | grep -o "+CREG:2,[0-9],[A-F0-9]\{2,4\},[A-F0-9]\{2,8\}") - if [ -n "$REGV" ]; then - LAC=$(echo "$REGV" | cut -d, -f3) - CID=$(echo "$REGV" | cut -d, -f4) - if [ ${#CID} -gt 4 ]; then - LAC=$(printf "%04X" 0x$LAC)" ($(printf "%d" 0x$LAC))" - CIDL=$(printf "%08X" 0x$CID) - RNC=${CIDL:1:3} - CID=${CIDL:4:4} - CID="Short $(printf "%X" 0x$CID) ($(printf "%d" 0x$CID)), Long $(printf "%X" 0x$CIDL) ($(printf "%d" 0x$CIDL))" - else - LAC="" - fi - else - LAC="" - fi - fi - REGSTAT=$(echo "$REGV" | cut -d, -f2) - if [ "$REGSTAT" == "5" -a "$COPS" != "-" ]; then - COPS_MNC=$COPS_MNC" (Roaming)" - fi - if [ -n "$CID" -a -n "$CID5" ] && [ "$RAT" == "13" -o "$RAT" == "10" ]; then - LAC="4G $LAC, 5G $LAC5" - CID="4G $CID
5G $CID5" - RNC="4G $RNC, 5G $RNC5" - elif [ -n "$CID5" ]; then - LAC=$LAC5 - CID=$CID5 - RNC=$RNC5 - fi - if [ -z "$LAC" ]; then - LAC="-" - CID="-" - RNC="-" - fi -} -SIMCOM_SIMINFO() -{ - debug "Quectel_SIMINFO" - # 获取IMEI - IMEI=$( sh modem_at.sh $at_port "AT+CGSN" | sed -n '2p' ) - # 获取IMSI - IMSI=$( sh modem_at.sh $at_port "AT+CIMI" | sed -n '2p' ) - # 获取ICCID - ICCID=$( sh modem_at.sh $at_port "AT+ICCID" | grep -o "+ICCID:[ ]*[-0-9]\+" | grep -o "[-0-9]\{1,4\}" ) - # 获取电话号码 - phone=$( sh modem_at.sh $at_port "AT+CNUM" | grep "+CNUM:" ) -} -#simcom查找基站AT -get_simcom_data() -{ - debug "get simcom data" - #设置AT串口 - at_port=$1 - - All_CSQ - SIMCOM_SIMINFO - SIMCOM_Cellinfo - - #温度 - OX=$( sh modem_at.sh $at_port "AT+CPMUTEMP") - TEMP=$(echo "$OX" | grep -o "+CPMUTEMP:[ ]*[-0-9]\+" | grep -o "[-0-9]\{1,4\}") - if [ -n "$TEMP" ]; then - TEMP=$(echo $TEMP)$(printf "\xc2\xb0")"C" - fi - - - #基站信息 - OX=$( sh modem_at.sh $at_port "AT+CPSI?") - rec=$(echo "$OX" | grep "+CPSI:") - w=$(echo $rec |grep "NO SERVICE"| wc -l) - if [ $w -ge 1 ];then - debug "NO SERVICE" - return - fi - w=$(echo $rec |grep "NR5G_"| wc -l) - if [ $w -ge 1 ];then - - w=$(echo $rec |grep "32768"| wc -l) - if [ $w -ge 1 ];then - debug "-32768" - return - fi - - debug "$rec" - rec1=${rec##*+CPSI:} - #echo "$rec1" - MODE="${rec1%%,*}" # MODE="NR5G" - rect1=${rec1#*,} - rect1s="${rect1%%,*}" #Online - rect2=${rect1#*,} - rect2s="${rect2%%,*}" #460-11 - rect3=${rect2#*,} - rect3s="${rect3%%,*}" #0xCFA102 - rect4=${rect3#*,} - rect4s="${rect4%%,*}" #55744245764 - rect5=${rect4#*,} - rect5s="${rect5%%,*}" #196 - rect6=${rect5#*,} - rect6s="${rect6%%,*}" #NR5G_BAND78 - rect7=${rect6#*,} - rect7s="${rect7%%,*}" #627264 - rect8=${rect7#*,} - rect8s="${rect8%%,*}" #-940 - rect9=${rect8#*,} - rect9s="${rect9%%,*}" #-110 - # "${rec1##*,}" #最后一位 - rect10=${rect9#*,} - rect10s="${rect10%%,*}" #最后一位 - PCI=$rect5s - LBAND="n"$(echo $rect6s | cut -d, -f0 | grep -o "BAND[0-9]\{1,3\}" | grep -o "[0-9]\+") - CHANNEL=$rect7s - RSCP=$(($(echo $rect8s | cut -d, -f0) / 10)) - ECIO=$(($(echo $rect9s | cut -d, -f0) / 10)) - if [ "$CSQ_PER" = "-" ]; then - CSQ_PER=$((100 - (($RSCP + 31) * 100/-125)))"%" - fi - SINR=$(($(echo $rect10s | cut -d, -f0) / 10))" dB" - fi - w=$(echo $rec |grep "LTE"|grep "EUTRAN"| wc -l) - if [ $w -ge 1 ];then - rec1=${rec#*EUTRAN-} - lte_band=${rec1%%,*} #EUTRAN-BAND - rec1=${rec1#*,} - rec1=${rec1#*,} - rec1=${rec1#*,} - rec1=${rec1#*,} - #rec1=${rec1#*,} - rec1=${rec1#*,} - lte_rssi=${rec1%%,*} #LTE_RSSI - lte_rssi=`expr $lte_rssi / 10` #LTE_RSSI - debug "LTE_BAND=$lte_band LTE_RSSI=$lte_rssi" - if [ $rssi == 0 ];then - rssi=$lte_rssi - fi - fi - w=$(echo $rec |grep "WCDMA"| wc -l) - if [ $w -ge 1 ];then - w=$(echo $rec |grep "UNKNOWN"|wc -l) - if [ $w -ge 1 ];then - debug "UNKNOWN BAND" - return - fi - fi - - #CNMP - OX=$( sh modem_at.sh $at_port "AT+CNMP?") - CNMP=$(echo "$OX" | grep -o "+CNMP:[ ]*[0-9]\{1,3\}" | grep -o "[0-9]\{1,3\}") - if [ -n "$CNMP" ]; then - case $CNMP in - "2"|"55" ) - NETMODE="1" ;; - "13" ) - NETMODE="3" ;; - "14" ) - NETMODE="5" ;; - "38" ) - NETMODE="7" ;; - "71" ) - NETMODE="9" ;; - "109" ) - NETMODE="8" ;; - * ) - NETMODE="0" ;; - esac - fi - - # CMGRMI 信息 - OX=$( sh modem_at.sh $at_port "AT+CMGRMI=4") - CAINFO=$(echo "$OX" | grep -o "$REGXz" | tr ' ' ':') - if [ -n "$CAINFO" ]; then - for CASV in $(echo "$CAINFO"); do - LBAND=$LBAND"
B"$(echo "$CASV" | cut -d, -f4) - BW=$(echo "$CASV" | cut -d, -f5) - decode_bw - LBAND=$LBAND" (CA, Bandwidth $BW MHz)" - CHANNEL="$CHANNEL, "$(echo "$CASV" | cut -d, -f2) - PCI="$PCI, "$(echo "$CASV" | cut -d, -f7) - done - fi - -} diff --git a/luci-app-modem/root/usr/share/modem/usb_modem_scan.sh b/luci-app-modem/root/usr/share/modem/usb_modem_scan.sh deleted file mode 100755 index 1a05483..0000000 --- a/luci-app-modem/root/usr/share/modem/usb_modem_scan.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/sh -sleep 15 -logger -t usb_modem_scan "Start to scan USB modem" -source /usr/share/modem/modem_scan.sh -modem_scan diff --git a/luci-app-modem/root/usr/share/rpcd/acl.d/luci-app-modem.json b/luci-app-modem/root/usr/share/rpcd/acl.d/luci-app-modem.json index 61edd0c..c2e9267 100644 --- a/luci-app-modem/root/usr/share/rpcd/acl.d/luci-app-modem.json +++ b/luci-app-modem/root/usr/share/rpcd/acl.d/luci-app-modem.json @@ -7,5 +7,13 @@ "write": { "uci": [ "modem" ] } + }, + "luci-mod-status-index": { + "description": "Grant access to main status display", + "read": { + "ubus": { + "modem_ctrl": [ "info","base_info" ] + } + } } }