refactor: dial logic and modem detect logic
This commit is contained in:
parent
c9d7202778
commit
12d039cbc5
@ -3,7 +3,7 @@
|
||||
|
||||
include $(TOPDIR)/rules.mk
|
||||
|
||||
PKG_NAME:=luci-app-modem
|
||||
PKG_NAME:=luci-app-5gmodem
|
||||
LUCI_TITLE:=LuCI support for Modem
|
||||
LUCI_PKGARCH:=all
|
||||
PKG_VERSION:=1.4.4
|
||||
@ -27,13 +27,11 @@ LUCI_DEPENDS:=+luci-compat +kmod-usb-net +kmod-usb-net-cdc-ether +kmod-usb-acm \
|
||||
+kmod-pcie_mhi \
|
||||
+pciutils \
|
||||
+quectel-CM-5G \
|
||||
+modemmanager \
|
||||
+luci-proto-modemmanager \
|
||||
+sms-tool \
|
||||
+jq +grep +bc\
|
||||
|
||||
|
||||
define Package/luci-app-modem/conffiles
|
||||
define Package/luci-app-5gmodem/conffiles
|
||||
/etc/config/modem
|
||||
endef
|
||||
|
||||
|
@ -43,6 +43,8 @@ function index()
|
||||
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
|
||||
|
||||
--插件设置
|
||||
@ -723,6 +725,70 @@ function getIMEI()
|
||||
|
||||
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")
|
||||
|
@ -791,9 +791,17 @@
|
||||
else if (data_tab == "set_imei") {
|
||||
get_imei_info();
|
||||
}
|
||||
else if (data_tab == "set_sim" ){
|
||||
XHR.get('<%=luci.dispatcher.build_url("admin", "network", "modem", "get_sim")%>', { "port": at_port },
|
||||
function (x, data) {
|
||||
set_sim_view(data);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
// 定时触发更新AT串口
|
||||
XHR.poll(5,'<%=luci.dispatcher.build_url("admin", "network", "modem", "get_at_port")%>', null,
|
||||
(function()
|
||||
@ -1211,7 +1219,24 @@
|
||||
|
||||
}
|
||||
|
||||
function set_sim_view(slot){
|
||||
let sim_current_slot = slot["current_slot"];
|
||||
let sim_nextboot_slot = slot["nextboot_slot"];
|
||||
sim_current_view = document.getElementById("sim_slot_current");
|
||||
sim_nextboot_view = document.getElementById("sim_slot_nextboot");
|
||||
sim_current_view.innerHTML = sim_current_slot;
|
||||
sim_nextboot_view.innerHTML = sim_nextboot_slot;
|
||||
}
|
||||
|
||||
function set_sim(){
|
||||
select = document.getElementById("sim_slot_select");
|
||||
slot = select.value;
|
||||
XHR.get('<%=luci.dispatcher.build_url("admin", "network", "modem", "set_sim")%>', {"slot": slot },
|
||||
function (x, data) {
|
||||
set_sim_view(data);
|
||||
}
|
||||
);
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="cbi-map" id="cbi-modem-debug">
|
||||
@ -1351,6 +1376,7 @@
|
||||
<li class="cbi-tab-disabled" data-tab="lockband_tab"><a href="#"><%:LockBand Settings%></a></li>
|
||||
<li class="cbi-tab-disabled" data-tab="lockcell_tab"><a href="#"><%:Lock Cell/Arfcn Settings%></a></li>
|
||||
<li class="cbi-tab-disabled" data-tab="set_imei_tab"><a href="#"><%:Set IMEI%></a></li>
|
||||
<li class="cbi-tab-disabled" data-tab="set_sim_tab"><a href="#"><%:Switch SIM%></a></li>
|
||||
</ul>
|
||||
|
||||
<div class="cbi-section-node cbi-section-node-tabbed" id="tab_context">
|
||||
@ -1670,6 +1696,43 @@
|
||||
<input type="button" class="cbi-button-apply" onclick="set_imei()" value="<%:Apply%>">
|
||||
|
||||
</div>
|
||||
|
||||
<!-- 设置SIM卡槽 -->
|
||||
<div class="cbi-section" data-tab="set_sim_tab" data-tab-title="<%:Switch SIM%>" data-tab-active="false"
|
||||
style="display: none;">
|
||||
<table class="table cbi-section-table">
|
||||
<tbody id="sim_slot_setting">
|
||||
<tr class="tr cbi-section-table-titles anonymous">
|
||||
<th>
|
||||
<%:SIM Slot|Now%>
|
||||
</th>
|
||||
<th>
|
||||
<%:SIM Slot|Next Boot%>
|
||||
</th>
|
||||
<th>
|
||||
<%:SIM Slot|Setting%>
|
||||
</th>
|
||||
</tr>
|
||||
<tr class="tr">
|
||||
<td class="td" style="width: auto;">
|
||||
<span id="sim_slot_current"></span>
|
||||
</td>
|
||||
<td class="td cbi-value-field">
|
||||
<span id="sim_slot_nextboot"></span>
|
||||
</td>
|
||||
<td class="td cbi-value-field">
|
||||
<select name="sim_slot_select" id="sim_slot_select" class="cbi-input-select">
|
||||
<option value="SIM1"><%:SIM1 (Close to power)%></option>
|
||||
<option value="SIM2"><%:SIM2 (Away from power)%></option>
|
||||
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<input type="button" class="cbi-button-apply" onclick="set_sim()" value="<%:Apply%>">
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
@ -3,6 +3,7 @@ config global 'global'
|
||||
option enable_dial '1'
|
||||
option modem_number '0'
|
||||
option manual_configuration '0'
|
||||
option ethernet "cpewan0"
|
||||
|
||||
config custom-commands
|
||||
option description '****************通用****************'
|
||||
|
@ -1,5 +1,5 @@
|
||||
#!/bin/sh /etc/rc.common
|
||||
START=90
|
||||
START=95
|
||||
STOP=13
|
||||
USE_PROCD=1
|
||||
|
||||
@ -11,9 +11,9 @@ MODEM_RUN_CONFIG="${MODEM_RUNDIR}/config.cache"
|
||||
|
||||
start_service() {
|
||||
mkdir -p $MODEM_RUNDIR
|
||||
local scan=$(uci -q get modem.@global[0].manual_configuration)
|
||||
echo "scan=$scan"
|
||||
if [ "$scan" = "0" ]; then
|
||||
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
|
||||
|
@ -64,14 +64,14 @@ get_quick_commands()
|
||||
}
|
||||
|
||||
#拨号日志
|
||||
# $1:AT命令
|
||||
# $1:log mesg
|
||||
# $2:日志路径
|
||||
dial_log()
|
||||
{
|
||||
local at_command="$1"
|
||||
local logmsg="$1"
|
||||
local path="$2"
|
||||
|
||||
#打印日志
|
||||
local update_time=$(date +"%Y-%m-%d %H:%M:%S")
|
||||
echo "[${update_time}] Send AT command ${at_command} to modem" >> "${path}"
|
||||
}
|
||||
echo "[${update_time}] ${logmsg} " >> "${path}"
|
||||
}
|
||||
|
@ -60,6 +60,7 @@ 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]+")
|
||||
@ -79,11 +80,13 @@ check_ip()
|
||||
check_ip_command="AT+CGPADDR=1"
|
||||
;;
|
||||
"lte")
|
||||
check_ip_command="AT+CGPADDR=1"
|
||||
;;
|
||||
"lte_mediatek")
|
||||
check_ip_command="AT+CGPADDR=3"
|
||||
if [ "$define_connect" = "3" ];then
|
||||
check_ip_command="AT+CGPADDR=3"
|
||||
else
|
||||
check_ip_command="AT+CGPADDR=1"
|
||||
fi
|
||||
;;
|
||||
|
||||
esac
|
||||
;;
|
||||
"fibocom")
|
||||
@ -139,6 +142,8 @@ set_if()
|
||||
uci set network.${interface_name}.defaultroute='1'
|
||||
uci set network.${interface_name}.peerdns='0'
|
||||
uci set network.${interface_name}.metric='10'
|
||||
uci add_list network.${interface_name}.dns='114.114.114.114'
|
||||
uci add_list network.${interface_name}.dns='119.29.29.29'
|
||||
|
||||
|
||||
#添加或修改网络配置
|
||||
@ -147,8 +152,6 @@ set_if()
|
||||
uci set network.${interface6_name}.extendprefix='1'
|
||||
uci set network.${interface6_name}.ifname="@${interface_name}"
|
||||
uci set network.${interface6_name}.device="@${interface_name}"
|
||||
uci commit network
|
||||
|
||||
|
||||
local num=$(uci show firewall | grep "name='wan'" | wc -l)
|
||||
local wwan_num=$(uci -q get firewall.@zone[$num].network | grep -w "${interface_name}" | wc -l)
|
||||
@ -161,6 +164,7 @@ set_if()
|
||||
fi
|
||||
uci commit network
|
||||
uci commit firewall
|
||||
ifup ${interface_name}
|
||||
dial_log "create interface $interface_name" "$log_path"
|
||||
|
||||
fi
|
||||
@ -182,7 +186,7 @@ set_if()
|
||||
uci set network.${interface_name}.device="${set_modem_netcard}"
|
||||
|
||||
uci commit network
|
||||
/etc/init.d/network restart
|
||||
ifup ${interface_name}
|
||||
dial_log "set interface $interface_name to $modem_netcard" "$log_path"
|
||||
fi
|
||||
}
|
||||
@ -192,7 +196,6 @@ flush_if()
|
||||
uci delete network.${interface_name}
|
||||
uci delete network.${interface6_name}
|
||||
uci commit network
|
||||
/etc/init.d/network restart
|
||||
dial_log "delete interface $interface_name" "$log_path"
|
||||
|
||||
}
|
||||
@ -311,8 +314,13 @@ at_dial()
|
||||
cgdcont_command="AT+CGDCONT=1,\"$pdp_type\",\"$apn\""
|
||||
;;
|
||||
"lte")
|
||||
at_command="AT+QNETDEVCTL=1,3,1"
|
||||
cgdcont_command="AT+CGDCONT=1,\"$pdp_type\",\"$apn\""
|
||||
if [ "$define_connect" = "3" ];then
|
||||
at_command="AT+QNETDEVCTL=3,3,1"
|
||||
cgdcont_command="AT+CGDCONT=3,\"$pdp_type\",\"$apn\""
|
||||
else
|
||||
at_command="AT+QNETDEVCTL=1,3,1"
|
||||
cgdcont_command="AT+CGDCONT=1,\"$pdp_type\",\"$apn\""
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
at_command="AT+QNETDEVCTL=1,3,1"
|
||||
@ -352,7 +360,7 @@ ip_change_fm350()
|
||||
{
|
||||
dial_log "ip_change_fm350" "$log_path"
|
||||
at_command="AT+CGPADDR=3"
|
||||
local ipv4_config=$(at ${at_port} ${at_command} | grep "+CGPADDR: " | awk -F',' '{print $2}' | sed 's/"//g')
|
||||
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"
|
||||
local public_dns2_ipv4="119.29.29.29"
|
||||
local public_dns1_ipv6="2400:3200::1"
|
||||
@ -388,7 +396,8 @@ ip_change_fm350()
|
||||
uci add_list network.${interface_name}.dns="${ipv4_dns1}"
|
||||
uci add_list network.${interface_name}.dns="${ipv4_dns2}"
|
||||
uci commit network
|
||||
/etc/init.d/network restart
|
||||
ifdown ${interface_name}
|
||||
ifup ${interface_name}
|
||||
dial_log "set interface $interface_name to $ipv4_config" "$log_path"
|
||||
|
||||
}
|
||||
|
@ -725,24 +725,7 @@ enable_dial()
|
||||
# $1:网络设备
|
||||
disable_dial()
|
||||
{
|
||||
local network="$1"
|
||||
|
||||
local i=0
|
||||
while true; do
|
||||
#查看该网络设备的配置是否启用
|
||||
local modem_network=$(uci -q get modem.@dial-config[${i}].network)
|
||||
[ -z "$modem_network" ] && break
|
||||
if [ "$network" = "$modem_network" ]; then
|
||||
local enable=$(uci -q get modem.@dial-config[${i}].enable)
|
||||
if [ "$enable" = "1" ]; then
|
||||
uci set modem.@dial-config[${i}].enable=0
|
||||
uci commit modem
|
||||
service modem reload
|
||||
break
|
||||
fi
|
||||
fi
|
||||
i=$((i+1))
|
||||
done
|
||||
/etc/init.d/modem_network restart
|
||||
}
|
||||
|
||||
#设置模组串口
|
||||
|
4
luci-app-modem/root/usr/share/modem/usb_modem_scan.sh
Normal file → Executable file
4
luci-app-modem/root/usr/share/modem/usb_modem_scan.sh
Normal file → Executable file
@ -1,3 +1,5 @@
|
||||
sleep 10
|
||||
#!/bin/sh
|
||||
sleep 15
|
||||
logger -t usb_modem_scan "Start to scan USB modem"
|
||||
source /usr/share/modem/modem_scan.sh
|
||||
modem_scan
|
||||
|
Loading…
x
Reference in New Issue
Block a user