修改底层逻辑,添加FM350模组支持

This commit is contained in:
ling 2024-04-07 21:27:38 +08:00
parent e70b06161a
commit ed129d6348
29 changed files with 2705 additions and 894 deletions

View File

@ -54,25 +54,46 @@ end
at_command AT命令 at_command AT命令
]] ]]
function at(at_port,at_command) function at(at_port,at_command)
local odpall = io.popen("cd "..script_path.." && source "..script_path.."modem_debug.sh && at "..at_port.." "..at_command) local odpall = io.popen("source "..script_path.."modem_debug.sh && at "..at_port.." "..at_command)
local odp = odpall:read("*a") local odp = odpall:read("*a")
odpall:close() odpall:close()
odp=string.gsub(odp, "\r", "") odp=string.gsub(odp, "\r", "")
return odp return odp
end 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 odpall = io.popen("source "..script_path..manufacturer..".sh && "..manufacturer.."_get_mode "..at_port.." "..platform)
opd = odpall:read("*a")
odpall:close()
mode = string.gsub(opd, "\n", "")
end
return mode
end
--[[ --[[
@Description @Description
@Params @Params
at_port AT串口 at_port AT串口
manufacturer manufacturer
define_connect
]] ]]
function getModemConnectStatus(at_port,manufacturer) function getModemConnectStatus(at_port,manufacturer,define_connect)
local connect_status="unknown" local connect_status="unknown"
if at_port and manufacturer~="unknown" then if at_port and manufacturer~="unknown" then
local odpall = io.popen("cd "..script_path.." && source "..script_path..manufacturer..".sh && "..manufacturer.."_get_connect_status "..at_port) local odpall = io.popen("source "..script_path..manufacturer..".sh && "..manufacturer.."_get_connect_status "..at_port.." "..define_connect)
opd = odpall:read("*a") opd = odpall:read("*a")
odpall:close() odpall:close()
connect_status = string.gsub(opd, "\n", "") connect_status = string.gsub(opd, "\n", "")
@ -94,7 +115,7 @@ function getModemDeviceInfo(at_port)
--获取数据接口 --获取数据接口
local data_interface=modem_device["data_interface"]:upper() local data_interface=modem_device["data_interface"]:upper()
--获取连接状态 --获取连接状态
local connect_status=getModemConnectStatus(modem_device["at_port"],modem_device["manufacturer"]) local connect_status=getModemConnectStatus(modem_device["at_port"],modem_device["manufacturer"],modem_device["define_connect"])
--设置值 --设置值
modem_device_info=modem_device modem_device_info=modem_device
@ -113,10 +134,10 @@ end
at_port AT串口 at_port AT串口
manufacturer manufacturer
]] ]]
function getModemMoreInfo(at_port,manufacturer) function getModemMoreInfo(at_port,manufacturer,define_connect)
--获取模组信息 --获取模组信息
local odpall = io.popen("sh "..script_path.."modem_info.sh".." "..at_port.." "..manufacturer) local odpall = io.popen("sh "..script_path.."modem_info.sh".." "..at_port.." "..manufacturer.." "..define_connect)
local opd = odpall:read("*a") local opd = odpall:read("*a")
odpall:close() odpall:close()
@ -138,7 +159,7 @@ function getModemInfo()
local modem_more_info local modem_more_info
if at_port then if at_port then
modem_device_info=getModemDeviceInfo(at_port) modem_device_info=getModemDeviceInfo(at_port)
modem_more_info=getModemMoreInfo(at_port,modem_device_info["manufacturer"]) modem_more_info=getModemMoreInfo(at_port,modem_device_info["manufacturer"],modem_device_info["define_connect"])
end end
--设置信息 --设置信息
@ -254,16 +275,21 @@ function getModems()
local translation={} local translation={}
uci:foreach("modem", "modem-device", function (modem_device) uci:foreach("modem", "modem-device", function (modem_device)
-- 获取连接状态 -- 获取连接状态
local connect_status=getModemConnectStatus(modem_device["at_port"],modem_device["manufacturer"]) 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) translation[connect_status]=luci.i18n.translate(connect_status)
translation[modem_device["name"]]=luci.i18n.translate(modem_device["name"]) if modem_device["name"] then
translation[modem_device["mode"]]=luci.i18n.translate(modem_device["mode"]) translation[modem_device["name"]]=luci.i18n.translate(modem_device["name"])
end
translation[mode]=luci.i18n.translate(mode)
-- 设置值 -- 设置值
local modem=modem_device local modem=modem_device
modem["connect_status"]=connect_status modem["connect_status"]=connect_status
modem["mode"]=mode
local modem_tmp={} local modem_tmp={}
modem_tmp[modem_device[".name"]]=modem modem_tmp[modem_device[".name"]]=modem
@ -381,7 +407,7 @@ function getQuickCommands()
local commands={} local commands={}
if quick_option=="auto" then if quick_option=="auto" then
--获取模组AT命令 --获取模组AT命令
-- local odpall = io.popen("cd "..script_path.." && source "..script_path.."modem_debug.sh && get_quick_commands "..quick_option.." "..manufacturer) -- local odpall = io.popen(source "..script_path.."modem_debug.sh && get_quick_commands "..quick_option.." "..manufacturer)
local odpall = io.popen("cat "..script_path..manufacturer.."_at_commands.json") local odpall = io.popen("cat "..script_path..manufacturer.."_at_commands.json")
local opd = odpall:read("*a") local opd = odpall:read("*a")
odpall:close() odpall:close()
@ -437,13 +463,13 @@ function setNetworkPrefer()
end) end)
--设置模组网络偏好 --设置模组网络偏好
local odpall = io.popen("cd "..script_path.." && source "..script_path..manufacturer..".sh && "..manufacturer.."_set_network_prefer "..at_port.." "..network_prefer_config) local odpall = io.popen("source "..script_path..manufacturer..".sh && "..manufacturer.."_set_network_prefer "..at_port.." "..network_prefer_config)
odpall:close() odpall:close()
--获取设置好后的模组网络偏好 --获取设置好后的模组网络偏好
local network_prefer={} local network_prefer={}
if at_port and manufacturer and manufacturer~="unknown" then if at_port and manufacturer and manufacturer~="unknown" then
local odpall = io.popen("cd "..script_path.." && source "..script_path..manufacturer..".sh && "..manufacturer.."_get_network_prefer "..at_port) local odpall = io.popen("source "..script_path..manufacturer..".sh && "..manufacturer.."_get_network_prefer "..at_port)
local opd = odpall:read("*a") local opd = odpall:read("*a")
network_prefer=json.parse(opd) network_prefer=json.parse(opd)
odpall:close() odpall:close()
@ -473,13 +499,13 @@ function setMode()
end) end)
--设置模组拨号模式 --设置模组拨号模式
local odpall = io.popen("cd "..script_path.." && source "..script_path..manufacturer..".sh && "..manufacturer.."_set_mode "..at_port.." "..mode_config) local odpall = io.popen("source "..script_path..manufacturer..".sh && "..manufacturer.."_set_mode "..at_port.." "..mode_config)
odpall:close() odpall:close()
--获取设置好后的模组拨号模式 --获取设置好后的模组拨号模式
local mode local mode
if at_port and manufacturer and manufacturer~="unknown" then if at_port and manufacturer and manufacturer~="unknown" then
local odpall = io.popen("cd "..script_path.." && source "..script_path..manufacturer..".sh && "..manufacturer.."_get_mode "..at_port) local odpall = io.popen("source "..script_path..manufacturer..".sh && "..manufacturer.."_get_mode "..at_port)
mode = odpall:read("*a") mode = odpall:read("*a")
mode=string.gsub(mode, "\n", "") mode=string.gsub(mode, "\n", "")
odpall:close() odpall:close()
@ -509,7 +535,7 @@ function getModeInfo(at_port,manufacturer)
end) end)
--获取模组拨号模式 --获取模组拨号模式
local odpall = io.popen("cd "..script_path.." && source "..script_path..manufacturer..".sh && "..manufacturer.."_get_mode "..at_port) local odpall = io.popen("source "..script_path..manufacturer..".sh && "..manufacturer.."_get_mode "..at_port)
local opd = odpall:read("*a") local opd = odpall:read("*a")
odpall:close() odpall:close()
local mode=string.gsub(opd, "\n", "") local mode=string.gsub(opd, "\n", "")
@ -531,7 +557,7 @@ end
function getNetworkPreferInfo(at_port,manufacturer) function getNetworkPreferInfo(at_port,manufacturer)
--获取模组网络偏好 --获取模组网络偏好
local odpall = io.popen("cd "..script_path.." && source "..script_path..manufacturer..".sh && "..manufacturer.."_get_network_prefer "..at_port) local odpall = io.popen("source "..script_path..manufacturer..".sh && "..manufacturer.."_get_network_prefer "..at_port)
local opd = odpall:read("*a") local opd = odpall:read("*a")
odpall:close() odpall:close()
local network_prefer_info=json.parse(opd) local network_prefer_info=json.parse(opd)
@ -539,6 +565,23 @@ function getNetworkPreferInfo(at_port,manufacturer)
return network_prefer_info return network_prefer_info
end end
--[[
@Description
@Params
at_port AT串口
manufacturer
]]
function getSelfTestInfo(at_port,manufacturer)
--获取模组自检信息
local odpall = io.popen("source "..script_path..manufacturer..".sh && "..manufacturer.."_get_self_test_info "..at_port)
local opd = odpall:read("*a")
odpall:close()
local self_test_info=json.parse(opd)
return self_test_info
end
--[[ --[[
@Description @Description
]] ]]
@ -559,15 +602,18 @@ function getModemDebugInfo()
--获取值 --获取值
local mode_info={} local mode_info={}
local network_prefer_info={} local network_prefer_info={}
local self_test_info={}
if manufacturer~="unknown" then if manufacturer~="unknown" then
mode_info=getModeInfo(at_port,manufacturer) mode_info=getModeInfo(at_port,manufacturer)
network_prefer_info=getNetworkPreferInfo(at_port,manufacturer) network_prefer_info=getNetworkPreferInfo(at_port,manufacturer)
self_test_info=getSelfTestInfo(at_port,manufacturer)
end end
--设置值 --设置值
local modem_debug_info={} local modem_debug_info={}
modem_debug_info["mode_info"]=mode_info modem_debug_info["mode_info"]=mode_info
modem_debug_info["network_prefer_info"]=network_prefer_info modem_debug_info["network_prefer_info"]=network_prefer_info
modem_debug_info["self_test_info"]=self_test_info
-- 写入Web界面 -- 写入Web界面
luci.http.prepare_content("application/json") luci.http.prepare_content("application/json")

View File

@ -84,6 +84,12 @@ pdp_type:value("ipv4", translate("IPv4"))
pdp_type:value("ipv6", translate("IPv6")) pdp_type:value("ipv6", translate("IPv6"))
pdp_type:value("ipv4v6", translate("IPv4/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")) apn = s:taboption("advanced", Value, "apn", translate("APN"))
apn.default = "" apn.default = ""

View File

@ -68,6 +68,7 @@ o.cfgvalue = function(t, n)
return translate(dial_tool) return translate(dial_tool)
end end
o = s:option(DummyValue, "pdp_type", translate("PDP Type")) o = s:option(DummyValue, "pdp_type", translate("PDP Type"))
o.cfgvalue = function(t, n) o.cfgvalue = function(t, n)
local pdp_type = (Value.cfgvalue(t, n) or "") local pdp_type = (Value.cfgvalue(t, n) or "")
@ -79,6 +80,10 @@ o.cfgvalue = function(t, n)
return pdp_type return pdp_type
end end
o = s:option(Flag, "network_bridge", translate("Network Bridge"))
o.width = "5%"
o.rmempty = false
o = s:option(DummyValue, "apn", translate("APN")) o = s:option(DummyValue, "apn", translate("APN"))
o.cfgvalue = function(t, n) o.cfgvalue = function(t, n)
local apn = (Value.cfgvalue(t, n) or "") local apn = (Value.cfgvalue(t, n) or "")

View File

@ -182,6 +182,8 @@
document.getElementById("cbi-mode").style.display="none"; document.getElementById("cbi-mode").style.display="none";
//隐藏网络偏好界面 //隐藏网络偏好界面
document.getElementById("cbi-network-prefer").style.display="none"; document.getElementById("cbi-network-prefer").style.display="none";
//隐藏模组自检界面
document.getElementById("cbi-modem-self-test").style.display="none";
//隐藏AT界面 //隐藏AT界面
document.getElementById("cbi-at").style.display="none"; document.getElementById("cbi-at").style.display="none";
} }
@ -208,6 +210,8 @@
document.getElementById("cbi-mode").style.display="none"; document.getElementById("cbi-mode").style.display="none";
//隐藏网络偏好界面 //隐藏网络偏好界面
document.getElementById("cbi-network-prefer").style.display="none"; document.getElementById("cbi-network-prefer").style.display="none";
//隐藏模组自检界面
document.getElementById("cbi-modem-self-test").style.display="none";
} }
// 全功能界面 // 全功能界面
@ -217,6 +221,8 @@
document.getElementById("cbi-mode").style.display="block"; document.getElementById("cbi-mode").style.display="block";
//显示网络偏好界面 //显示网络偏好界面
document.getElementById("cbi-network-prefer").style.display="block"; document.getElementById("cbi-network-prefer").style.display="block";
//显示模组自检界面
document.getElementById("cbi-modem-self-test").style.display="block";
//隐藏提示信息 //隐藏提示信息
document.getElementById("cbi-info").style.display="none"; document.getElementById("cbi-info").style.display="none";
} }
@ -320,12 +326,14 @@
//拨号模式 //拨号模式
if (function_name=="mode") if (function_name=="mode")
{ {
//模式选项 modes=["qmi","ecm","mbim","rndis","ncm"]
document.getElementById('mode_option_qmi').disabled=status; for(mode of modes)
document.getElementById('mode_option_ecm').disabled=status; {
document.getElementById('mode_option_mbim').disabled=status; mode_element=document.getElementById('mode_option_'+mode)
document.getElementById('mode_option_rndis').disabled=status; if (mode_element!=null) {
document.getElementById('mode_option_ncm').disabled=status; mode_element.disabled=status;
}
}
//模式按钮 //模式按钮
document.getElementById('mode_button').disabled=status; document.getElementById('mode_button').disabled=status;
@ -484,6 +492,49 @@
} }
} }
// 设置模组自检信息
function set_modem_self_test_info(self_test_info)
{
// console.log(self_test_info);
//获取模组自检
// var self_test=self_test_info["self_test"];
// //获取自检视图
// var self_test_view=set_current_self_test_view(self_test);
// //获取
// var self_test_view=set_current_self_test_view(self_test);
// //设置当前电压信息
// document.getElementById('current_voltage').innerHTML=current_self_test_view;
document.getElementById('current_voltage').innerHTML=self_test_info/1000;
// 设置电压状态
var state = '';
var css = '';
if (self_test_info<3135)
{
state = "<%:Abnormal%>";
color = "red";
}
else if (self_test_info>3135 && self_test_info<3300)
{
state = "<%:Low%>";
color = "goldenrod";
}
else //大于33003.3V
{
state = "<%:Normal%>";
color = "green";
}
var voltage_status=document.getElementById('voltage_status');
voltage_status.innerHTML=state;
voltage_status.style.color=color
// //设置当前温度信息
// document.getElementById('current_temperature').innerHTML=current_self_test_view;
}
// 设置网络偏好 // 设置网络偏好
function set_network_prefer() function set_network_prefer()
{ {
@ -543,6 +594,7 @@
{ {
var mode_info=data["mode_info"]; var mode_info=data["mode_info"];
var network_prefer_info=data["network_prefer_info"]; var network_prefer_info=data["network_prefer_info"];
var self_test_info=data["self_test_info"];
if (Object.keys(mode_info).length==0||Object.keys(network_prefer_info).length==0) { if (Object.keys(mode_info).length==0||Object.keys(network_prefer_info).length==0) {
//显示未适配模组界面 //显示未适配模组界面
not_adapted_modems_view(); not_adapted_modems_view();
@ -555,6 +607,9 @@
//设置网络偏好信息 //设置网络偏好信息
set_network_prefer_info(network_prefer_info,debug_params.first_cache); set_network_prefer_info(network_prefer_info,debug_params.first_cache);
//设置模组自检信息
set_modem_self_test_info(self_test_info);
//设置第一次获取数据标志 //设置第一次获取数据标志
debug_params.first_cache=false; debug_params.first_cache=false;
@ -599,6 +654,9 @@
get_quick_commands(); get_quick_commands();
} }
modem_select_cache=select_modem_name; modem_select_cache=select_modem_name;
//设置第一次获取数据标志
debug_params.first_cache=true;
} }
//获取模组调试信息 //获取模组调试信息
@ -693,6 +751,54 @@
</div> </div>
</fieldset> </fieldset>
<!-- <fieldset class="cbi-section" id="cbi-mode" style="display: none;">
<div class="cbi-section">
<ul class="cbi-tabmenu">
<li class="cbi-tab" data-tab="traffic"><a href="#">流量分布</a></li>
<li class="cbi-tab-disabled" data-tab="layer7"><a href="#">应用层协议</a></li>
<li class="cbi-tab-disabled" data-tab="ipv6"><a href="#">IPv6</a></li>
<li class="cbi-tab-disabled" data-tab="export"><a href="#">导出</a></li>
</ul> -->
<!-- <div class="cbi-section-node cbi-section-node-tabbed" id="cbi-modem-bcfdc2df58a1440a9bab98c7d37ce93c" data-tab-group="0" data-initialized="true">
<div class="cbi-tabcontainer" id="container.modem.bcfdc2df58a1440a9bab98c7d37ce93c.general" data-tab="general" data-tab-title="常规设置" data-tab-active="true">
<div class="cbi-value" id="cbi-modem-bcfdc2df58a1440a9bab98c7d37ce93c-enable" data-index="1" data-depends="[]"><label class="cbi-value-title" for="cbid.modem.bcfdc2df58a1440a9bab98c7d37ce93c.enable">启用</label>
<div class="cbi-value-field">
<div id="cbid.modem.bcfdc2df58a1440a9bab98c7d37ce93c.enable" class="cbi-checkbox" data-idref="e234c82a"><input type="hidden" name="cbi.cbe.modem.bcfdc2df58a1440a9bab98c7d37ce93c.enable" value="1"><input id="cbe81b0aab" name="cbid.modem.bcfdc2df58a1440a9bab98c7d37ce93c.enable" type="checkbox" value="1" checked="" data-widget-id="widget.cbid.modem.bcfdc2df58a1440a9bab98c7d37ce93c.enable"><label for="cbe81b0aab"></label></div>
</div></div>
<div class="cbi-value" id="cbi-modem-bcfdc2df58a1440a9bab98c7d37ce93c-remarks" data-index="2" data-depends="[]"><label class="cbi-value-title" for="cbid.modem.bcfdc2df58a1440a9bab98c7d37ce93c.remarks">备注</label>
<div class="cbi-value-field">
<div id="cbid.modem.bcfdc2df58a1440a9bab98c7d37ce93c.remarks" data-idref="30622a74"><input id="widget.cbid.modem.bcfdc2df58a1440a9bab98c7d37ce93c.remarks" name="cbid.modem.bcfdc2df58a1440a9bab98c7d37ce93c.remarks" type="text" class="cbi-input-text" value="5GUSB"></div>
</div></div>
<div class="cbi-value cbi-value-last" id="cbi-modem-bcfdc2df58a1440a9bab98c7d37ce93c-network" data-index="3" data-depends="[]"><label class="cbi-value-title" for="cbid.modem.bcfdc2df58a1440a9bab98c7d37ce93c.network">移动网络</label>
<div class="cbi-value-field">
<div id="cbid.modem.bcfdc2df58a1440a9bab98c7d37ce93c.network" data-idref="f8c7e254"><select id="widget.cbid.modem.bcfdc2df58a1440a9bab98c7d37ce93c.network" name="cbid.modem.bcfdc2df58a1440a9bab98c7d37ce93c.network" size="1" class="cbi-input-select"><option value="wwan0" selected="">wwan0 (FM150-AE)</option></select></div>
</div></div>
</div>
<div class="cbi-tabcontainer" id="container.modem.bcfdc2df58a1440a9bab98c7d37ce93c.advanced" data-tab="advanced" data-tab-title="高级设置" data-tab-active="false">
<div class="cbi-value" id="cbi-modem-bcfdc2df58a1440a9bab98c7d37ce93c-dial_tool" data-index="1" data-depends="[]"><label class="cbi-value-title" for="cbid.modem.bcfdc2df58a1440a9bab98c7d37ce93c.dial_tool">拨号工具</label>
<div class="cbi-value-field">
<div id="cbid.modem.bcfdc2df58a1440a9bab98c7d37ce93c.dial_tool" data-idref="184707a1"><select id="widget.cbid.modem.bcfdc2df58a1440a9bab98c7d37ce93c.dial_tool" name="cbid.modem.bcfdc2df58a1440a9bab98c7d37ce93c.dial_tool" size="1" class="cbi-input-select"><option value="">自动选择</option><option value="quectel-CM">移远模组拨号工具</option><option value="mmcli" selected="">mmcli</option></select></div>
<div class="cbi-value-description">
After switching the dialing tool, it may be necessary to restart the module or restart the router to recognize the module.
</div></div></div>
<div class="cbi-value" id="cbi-modem-bcfdc2df58a1440a9bab98c7d37ce93c-pdp_type" data-index="2" data-depends="[]"><label class="cbi-value-title" for="cbid.modem.bcfdc2df58a1440a9bab98c7d37ce93c.pdp_type">网络类型</label>
<div class="cbi-value-field">
<div id="cbid.modem.bcfdc2df58a1440a9bab98c7d37ce93c.pdp_type" data-idref="74f51b28"><select id="widget.cbid.modem.bcfdc2df58a1440a9bab98c7d37ce93c.pdp_type" name="cbid.modem.bcfdc2df58a1440a9bab98c7d37ce93c.pdp_type" size="1" class="cbi-input-select"><option value="ipv4">IPv4</option><option value="ipv6">IPv6</option><option value="ipv4v6" selected="">IPv4/IPv6</option></select></div>
</div></div>
<div class="cbi-value" id="cbi-modem-bcfdc2df58a1440a9bab98c7d37ce93c-apn" data-index="3" data-depends="[]"><label class="cbi-value-title" for="cbid.modem.bcfdc2df58a1440a9bab98c7d37ce93c.apn">接入点</label>
<div class="cbi-value-field">
<div id="cbid.modem.bcfdc2df58a1440a9bab98c7d37ce93c.apn" class="cbi-dropdown" optional="" tabindex="0" data-idref="a314df9e"><ul tabindex="-1"><li data-value="" selected="" display="0">自动选择</li><li data-value="cmnet">中国移动</li><li data-value="3gnet">中国联通</li><li data-value="ctnet">中国电信</li><li data-value="cbnet">中国广电</li><li data-value="5gscuiot">天际通</li><li data-value="-" unselectable=""><input type="text" class="create-item-input" placeholder="-- 自定义 --"></li></ul><span class="more" tabindex="-1">···</span><span class="open" tabindex="-1"></span><div><input type="hidden" name="cbid.modem.bcfdc2df58a1440a9bab98c7d37ce93c.apn" value=""></div></div>
</div></div>
<div class="cbi-value cbi-value-last" id="cbi-modem-bcfdc2df58a1440a9bab98c7d37ce93c-auth" data-index="4" data-depends="[]"><label class="cbi-value-title" for="cbid.modem.bcfdc2df58a1440a9bab98c7d37ce93c.auth">认证类型</label>
<div class="cbi-value-field">
<div id="cbid.modem.bcfdc2df58a1440a9bab98c7d37ce93c.auth" data-idref="8b4f94b8"><select id="widget.cbid.modem.bcfdc2df58a1440a9bab98c7d37ce93c.auth" name="cbid.modem.bcfdc2df58a1440a9bab98c7d37ce93c.auth" size="1" class="cbi-input-select"><option value="none" selected=""></option><option value="both">PAP/CHAP均使用</option><option value="pap">PAP</option><option value="chap">CHAP</option></select></div>
</div>
</div>
</div>
</div> -->
<!-- </div>
</fieldset> -->
<fieldset class="cbi-section" id="cbi-mode" style="display: none;"> <fieldset class="cbi-section" id="cbi-mode" style="display: none;">
<div class="cbi-section cbi-tblsection"> <div class="cbi-section cbi-tblsection">
<!-- <legend><%:Mode%></legend> --> <!-- <legend><%:Mode%></legend> -->
@ -794,6 +900,32 @@
</div> </div>
</fieldset> </fieldset>
<fieldset class="cbi-section" id="cbi-modem-self-test" style="display: none;">
<div class="cbi-section fade-in">
<!-- <legend><%:Self Test%></legend> -->
<h3><%:Self Test%></h3>
<table class="table cbi-section-table">
<tbody>
<tr class="tr cbi-section-table-titles anonymous">
<th class="th cbi-section-table-cell"><%:Item%></th>
<th class="th cbi-section-table-cell"><%:Current%></th>
<th class="th cbi-section-table-cell"><%:Status%></th>
</tr>
<tr class="tr cbi-section-table-row cbi-rowstyle-1">
<td class="td cbi-value-field" data-title="<%:Item%>" id="voltage_label">电压</td>
<td class="td cbi-value-field" data-title="<%:Current%>" id="current_voltage"></td>
<td class="td cbi-value-field" data-title="<%:Status%>" id="voltage_status">-</td>
</tr>
<!-- <tr class="tr cbi-section-table-row cbi-rowstyle-2">
<td class="td cbi-value-field" data-title="<%:Item%>" id="temperature_label">温度</td>
<td class="td cbi-value-field" data-title="<%:Current%>" id="current_temperature">-</td>
<td class="td cbi-value-field" data-title="<%:Status%>" id="temperature_status">正常</td>
</tr> -->
</tbody>
</table>
</div>
</fieldset>
<fieldset class="cbi-section" id="cbi-at" style="display: none;"> <fieldset class="cbi-section" id="cbi-at" style="display: none;">
<div class="cbi-section fade-in"> <div class="cbi-section fade-in">
<!-- <legend><%:AT Command%></legend> --> <!-- <legend><%:AT Command%></legend> -->

View File

@ -0,0 +1,157 @@
# OpenWRT软件开发
# 一、相关文档
UCI系统https://openwrt.org/docs/guide-user/base-system/uci
OpenWRT命令解释器https://openwrt.org/zh/docs/guide-user/base-system/user.beginner.cli
热插拔https://openwrt.org/zh/docs/guide-user/base-system/hotplug
网络基础配置https://openwrt.org/zh/docs/guide-user/base-system/basic-networking
Web界面相关
- 自定义主题https://github.com/openwrt/luci/wiki/HowTo:-Create-Themes
- 模块参考https://github.com/openwrt/luci/wiki/Modules
- 模板参考https://github.com/openwrt/luci/wiki/Templates
- 实例参考https://blog.csdn.net/byb123/article/details/77921486/
- 实例参考https://api.dandelioncloud.cn/article/details/1546689075828965377
# 二、网络配置
在任何网络配置更改(通过uci或其他方式)之后,你需要输入以下内容来重载网络配置:
```shell
service network reload
```
如果您安装的版本没有提供`service`命令,则可以使用:
```shell
/etc/init.d/network reload
```
# 三、拨号程序
拨号步骤
```shell
run_dial()
{
local enabled
config_get_bool enabled $1 enabled
if [ "$enabled" = "1" ]; then
local apn
local user
local password
local auth
local ipv6
local device
#获取配置
config_get apn $1 apn
config_get user $1 user
config_get password $1 password
config_get auth $1 auth
config_get ipv6 $1 ipv6
config_get device $1 device
devname="$(basename "$device")" #获取调制解调器/dev/cdc-wdm0->cdc-wdm0
devicepath="$(find /sys/class/ -name $devname)" #找到设备快捷路径/sys/class/net/cdc-wdm0
devpath="$(readlink -f $devicepath/device/)" #找出连接的物理设备路径/sys/devices/.../
ifname="$( ls "$devpath"/net )" #获取设备名/sys/devices/.../net->cdc-wdm0
procd_open_instance #打开一个示例
procd_set_param command quectel-CM #设置参数
if [ "$ipv6" = 1 ]; then
procd_append_param command -4 -6
fi
if [ "$apn" != "" ];then
procd_append_param command -s $apn
fi
if [ "$user" != "" ]; then
procd_append_param command $user
fi
if [ "$password" != "" ]; then
procd_append_param command $password
fi
if [ "$auth" != "" ]; then
procd_append_param command $auth
fi
if [ "$device" != "" ]; then
procd_append_param command -i $ifname
fi
procd_set_param respawn
procd_close_instance
if [ -d /sys/class/net/rmnet_mhi0 ]; then
pre_set rmnet_mhi0.1
elif [ -d /sys/class/net/wwan0_1 ]; then
pre_set wwan0_1
elif [ -d /sys/class/net/wwan0.1 ]; then
pre_set wwan0.1
elif [ -d /sys/class/net/wwan0 ]; then
pre_set wwan0
fi
fi
sleep 15
}
```
# 四、shell
获取设备物理路径
device_bus_path.sh
```shell
#!/bin/sh
#获取物理设备地址
local device_name="$(basename "$1")"
local device_path="$(find /sys/class/ -name $device_name)"
local device_physical_path="$(readlink -f $device_path/device/)"
local device_bus_path=$(dirname "$device_physical_path")
return $device_bus_path
```
设置配置
setConfig.sh
```shell
#!/bin/sh
#处理获取到的路径
substr="${parentDir/\/sys\/devices\//}"
echo $substr
#写入到配置中
uci set modem.modem1.path="$substr"
uci commit modem2
```
# 五、Git
查看当前文件的权限
```shell
git ls-tree HEAD
```
直接修改
修改提交文件的权限
```shell
git update-index --chmod=+x <file>
```
提交时修改
```shell
git add --chmod=+x -- <file>
```

View File

@ -0,0 +1,420 @@
<%+header%>
<%
local fs = require "nixio.fs"
local uci = luci.model.uci.cursor()
nosms = 1
if not fs.stat("/etc/nosim") then
nosms = 0
end
havegps = 0
if fs.stat("/etc/havegps") then
havegps = 1
end
%>
<style>g {color:grey; font-size:75%; vertical-align: super;}</style>
<script type="text/javascript" src="<%=resource%>/xhr.js"></script>
<script type="text/javascript">//<![CDATA[
window.onload=function()
{
//获取模块选择框元素
var modem_select = document.getElementById('modem_select');
// 更换模组AT串口时触发
modem_select.addEventListener('change', function() {
// 更新数据
update();
});
}
//获取小区信息视图
function get_cell_info_view(network_mode_info)
{
//初始化视图
var cell_info_view='';
//遍历每一条信息
for (var info of network_mode_info)
{
//遍历每一条信息里的键
for (var key in info)
{
var full_name=info["full_name"];
if (full_name==null)
{
full_name='';
}
//不显示空的信息
if (key!="full_name"&&info[key]!="")
{
cell_info_view+='<tr><td width="20%" title="'+full_name+'">'+<%: key %>+' :</td><td id="'+key+'">'+info[key]+'</td><td></td></tr>';
// cell_info_view+='<tr><td width="20%" title="'+full_name+'">'+<%:Message%>+' :</td><td id="'+key+'">'+info[key]+'</td><td></td></tr>';
}
}
}
return cell_info_view;
}
//获取小区信息
function show_cell_info(cell_info) {
//获取网络模式
var network_mode=Object.keys(cell_info)[0];
//获取网络模式下的信息
var network_mode_info=cell_info[network_mode];
//获取表格
var cell_info_Element=document.getElementById("cell_info");
//初始化视图
var cell_info_view='<caption>'+<%:network_mode%>+'</caption>';
if (network_mode=="EN-DC Mode")
{
var lte=network_mode_info[0]["LTE"];
cell_info_view+='<tr><td colspan="3">LTE</td></tr>';
cell_info_view+=get_cell_info_view(lte);
var nsa=network_mode_info[1]["NR5G-NSA"];
cell_info_view+='<tr><td colspan="3">NR5G-NSA</td></tr>';
cell_info_view+=get_cell_info_view(nsa);
}
else
{
// cell_info_view+='<tr><td colspan="3">NR5G-NSA</td></tr>';
cell_info_view+=get_cell_info_view(network_mode_info);
}
cell_info_Element.innerHTML=cell_info_view;
}
// 更新模组数据
function update()
{
var at_port="";
if (modem_select.options.length!=0) {
at_port=modem_select.options[modem_select.selectedIndex].value;
}
else {
return
}
XHR.get('<%=luci.dispatcher.build_url("admin", "network", "modem", "get_modem_info")%>', {"port":at_port},
function(x, modem_info)
{
console.log(modem_info);
var base_info=modem_info["base_info"];
var connect_status=base_info["connect_status"];
for (var key in base_info)
{
var base_info_Element=document.getElementById(key);
if (base_info_Element!=null)
{
base_info_Element.innerHTML=base_info[key];
}
}
var more_info=modem_info["more_info"];
//基本信息
base_info=more_info["base_info"];
for (var key in base_info)
{
var base_info_Element=document.getElementById(key);
if (base_info_Element!=null)
{
base_info_Element.innerHTML=base_info[key];
}
}
//SIM卡信息
var sim_info=more_info["sim_info"];
for (var key in sim_info)
{
var sim_info_Element=document.getElementById(key);
if (sim_info_Element!=null)
{
sim_info_Element.innerHTML=sim_info[key];
}
}
// 信息显示控制
// 隐藏提示信息
document.getElementById("cbi-info").style.display="none";
// 显示基本信息
document.getElementById("cbi-baseinfo").style.display="block";
// 显示SIM卡信息
document.getElementById("cbi-siminfo").style.display="block";
//网络信息
var network_info=more_info["network_info"];
for (var key in network_info)
{
var network_info_Element=document.getElementById(key);
if (network_info_Element!=null)
{
network_info_Element.innerHTML=network_info[key];
}
}
//小区信息
var cell_info=more_info["cell_info"];
if (cell_info!=null)
{
show_cell_info(cell_info);
}
// 信息显示控制
if (connect_status=="connect")
{
// 显示网络信息
document.getElementById("cbi-networkinfo").style.display="block";
// 显示小区信息
document.getElementById("cbi-cellinfo").style.display="block";
}
else
{
// 隐藏网络信息
document.getElementById("cbi-networkinfo").style.display="none";
// 隐藏小区信息
document.getElementById("cbi-cellinfo").style.display="none";
}
}
);
}
// 定时触发更新AT串口和模组数据
XHR.poll(5,'<%=luci.dispatcher.build_url("admin", "network", "modem", "get_at_port")%>', null,
function(x, port)
{
//获取模块选择框元素
var modem_select = document.getElementById('modem_select');
// 记录所选
var selected=modem_select.value;
// 删除原来的选项
modem_select.options.length=0;
// 更新keyAT串口value模块名称
for (var key in port)
{
var option = document.createElement('option');
option.text = port[key].trim();
option.value = key;
modem_select.appendChild(option);
}
// 恢复原来的选择
for (let i = 0; i < modem_select.options.length; i++)
{
if(modem_select.options[i].value == selected)
{
modem_select.selectedIndex=i;
break;
}
}
// 信息显示控制
if (port.length==0)
{
// 更新提示信息
document.getElementById("info_message").innerHTML="<strong><%:No modems found%></strong>";
// 隐藏提示信息
document.getElementById("cbi-info").style.display="block";
// 隐藏基本信息
document.getElementById("cbi-baseinfo").style.display="none";
// 隐藏SIM卡信息
document.getElementById("cbi-siminfo").style.display="none";
// 隐藏网络信息
document.getElementById("cbi-networkinfo").style.display="none";
// 隐藏小区信息
document.getElementById("cbi-cellinfo").style.display="none";
}
update();
}
);
modemtype=0;
cell=0;
portx="-";
phonenx = "";
hided = 0;
function clear_data()
{
document.getElementById('port').innerHTML="<%:Changing Port%>";
document.getElementById('csq').innerHTML="-";
document.getElementById('per').innerHTML="-";
document.getElementById('rssi').innerHTML="-";
// document.getElementById('modem').innerHTML="-";
document.getElementById('cops').innerHTML="-";
document.getElementById('net_type').innerHTML="-";
document.getElementById('lac').innerHTML="-";
document.getElementById('cid').innerHTML="-";
document.getElementById('lacn').innerHTML="-";
document.getElementById('cidn').innerHTML="-";
document.getElementById('mcc').innerHTML="-";
document.getElementById('mnc').innerHTML="-";
document.getElementById('rnc').innerHTML="-";
document.getElementById('rncn').innerHTML="-";
document.getElementById('down').innerHTML="-";
document.getElementById('up').innerHTML="-";
document.getElementById('ecio').innerHTML="-";
document.getElementById('rscp').innerHTML="-";
document.getElementById('ecio1').innerHTML="-";
document.getElementById('rscp1').innerHTML="-";
document.getElementById('netmode').innerHTML="-";
document.getElementById('manufacturer').innerHTML=" ";
document.getElementById('chan').innerHTML=" ";
document.getElementById('conmon').innerHTML="-";
document.getElementById('phone').value="-";
document.getElementById('imei').innerHTML="-";
document.getElementById('imsi').innerHTML="-";
document.getElementById('iccid').innerHTML="-";
document.getElementById('lband').innerHTML="-";
document.getElementById('pci').innerHTML="-";
<% if havegps == 1 then %>
document.getElementById('lat').innerHTML="-";
document.getElementById('long').innerHTML="-";
<% end %>
// document.getElementById('idvp').innerHTML="-";
// document.getElementById('phonen').value="-";
}
//]]>
</script>
<div class="cbi-map" id="cbi-modem">
<h2 name="content"><%:Modem Information%></h2>
<div class="cbi-map-descr"><%:%></div>
<!-- <fieldset class="cbi-section" id="simwarn" style="display:none;">
<legend><%:SIM警告%></legend>
<table width="550" border="0">
<tr>
<td width="10%"></td>
<td width="60%"><div align="left" id="simsg" style="font-size:1.875em"><strong></strong></div></td>
<td width="30%"></td>
</tr>
</table>
</fieldset> -->
<fieldset class="cbi-section" id="cbi-info" style="display: block;">
<h3><%:Message%></h3>
<table width="550" border="0">
<tr>
<td width="10%"></td>
<td width="60%">
<div align="left" id="info_message" style="font-size:1.875em">
<img src="<%=resource%>/icons/loading.gif" alt="<%:Loading%>" style="vertical-align:middle"/>
<%:Loading modem status%>...
</div>
</td>
<td width="30%"></td>
</tr>
</table>
</fieldset>
<fieldset class="cbi-section" id="cbi-baseinfo" style="display: none;">
<h3><%:Base Information%></h3>
<table width="100%" cellspacing="10">
<tr><td width="20%"><%:Modem%> :</td><td id="modem_name">
<select name="modem_select" id="modem_select"></select>
</td><td></td></tr>
<tr><td width="20%"><%:Manufacturer%> :</td><td id="manufacturer"></td><td></td></tr>
<tr><td width="20%"><%:Revision%>:</td><td id="revision"></td><td></td></tr>
<tr><td width="20%"><%:Data Interface%> :</td><td id="data_interface"></td><td></td></tr>
<tr><td width="20%"><%:Mode%> :</td><td id="mode"></td><td></td></tr>
<tr><td width="20%"><%:AT Port%> :</td><td id="at_port"></td><td></td></tr>
<tr><td width="20%"><%:Mobile Network%> :</td><td id="network"></td><td></td></tr>
<tr><td width="20%"><%:Temperature%> :</td><td id="temperature"></td><td></td></tr>
<tr><td width="20%"><%:Update Time%> :</td><td id="update_time"></td><td></td></tr>
</table>
</fieldset>
<% if nosms == 0 then %>
<% end %>
<fieldset class="cbi-section" id="cbi-siminfo" style="display: none;">
<h3><%:SIM Information%></h3>
<table width="100%" cellspacing="10">
<tr><td width="20%"><%:ISP%> :</td><td id="isp"></td><td></td></tr>
<tr><td width="20%"><%:IMEI%> :</td><td id="imei"></td><td></td></tr>
<tr><td width="20%"><%:IMSI%> :</td><td id="imsi"></td><td></td></tr>
<tr><td width="20%"><%:ICCID%> :</td><td id="iccid"></td><td></td></tr>
<tr><td width="20%"><%:SIM Number%> :</td><td id="sim_number"></td><td></td></tr>
</table>
</fieldset>
<fieldset class="cbi-section" id="cbi-networkinfo" style="display: none;">
<h3><%:Network Information%></h3>
<table width="100%" cellspacing="10">
<tr><td width="20%"><%:Network Type%> :</td><td id="network_type"></td><td></td></tr>
</table>
</fieldset>
<fieldset class="cbi-section" id="cbi-cellinfo" style="display: none;">
<h3><%:Cell Information%></h3>
<table width="100%" cellspacing="10" id="cell_info">
<!-- <tr><td width="20%"><%:MCC/MNC 国家码/网络码 %> :</td><td id="nr_mcc"></td><td id="nr_mnc"></td></tr>
<tr><td width="20%"><%:Duplex Mode 双工模式 %> :</td><td id="nr_duplex_mode"></td><td></td></tr>
<tr><td width="20%"><%:Cell ID 小区ID %> :</td><td><ul><span id="nr_cell_id" class="r"></span><span id="cidn" class="r"></span></ul></td><td></td></tr>
<tr><td width="20%"><%:Physical Cell ID 物理小区ID %> :</td><td id="nr_physical_cell_id"></td><td></td></tr>
<tr><td width="20%"><%:TAC 跟踪区编码 %> :</td><td id="nr_tac"></td><td></td></tr>
<tr><td width="20%" title="<%:Absolute Radio-Frequency Channel Number%>"><%:ARFCN 绝对射频信道号 : %></td><td id="nr_arfcn"></td><td></td></tr>
<tr><td width="20%"><%:Band 频段 : %></td><td id="nr_band"></td><td></td></tr>
<tr><td width="20%"><%:UL Bandwidth 上行带宽 %> :</td><td id="nr_ul_bandwidth"></td><td></td></tr>
<tr><td width="20%"><%:DL Bandwidth 下行带宽 %> :</td><td id="nr_dl_bandwidth"></td><td></td></tr>
<tr><td width="20%" title="<%:Reference Signal Received Power%>"><%:RSRP 参考信号接收功率 %> :</td><td id="nr_rsrp"></td><td></td></tr>
<tr><td width="20%" title="<%:Reference Signal Received Quality%>"><%:RSRQ 参考信号接收质量 %> :</td><td id="nr_rsrq"></td><td></td></tr>
<tr><td width="20%" title="<%:Signal to Interference plus Noise Ratio Bandwidth%>"><%:SINR 信号与干扰加噪声比 %> :</td><td id="nr_sinr"></td><td></td></tr>
<tr><td width="20%"><%:SCS NR子载波间隔 %> :</td><td id="nr_scs"></td><td></td></tr>
<tr><td width="20%"title="<%:Received Signal Level%>"><%:RxLev 接收信号电平 %> :</td><td id="nr_rxlev"></td><td></td></tr> -->
</table>
</fieldset>
<!-- <fieldset class="cbi-section" id="cbi-networkinfo" style="display: none;">
<h3><%:网络信息%></h3>
<table width="100%" cellspacing="10">
<tr><td width="20%"><%:Network Type 网络类型 %> :</td><td id="network_type"></td><td></td></tr>
<tr><td width="20%"><%:CSQ : %></td><td id="csq"></td><td></td></tr>
<tr><td width="20%"><%:信号强度 : %></td><td id="per"></td><td></td></tr>
<tr><td width="20%"><%:RSSI 信号接收强度 : %></td><td id="rssi"></td><td></td></tr>
<tr><td width="20%"><%:RSRQ 参考信号接收质量 : %></td><td><ul><span id="ecio" class="r"></span><span id="ecio1" class="r"></span></ul></td><td></td></tr>
<tr><td width="20%"><%:RSRP 参考信号接收功率 : %></td><td><ul><span id="rscp" class="r"></span><span id="rscp1" class="r"></span></ul></td><td></td></tr>
<tr><td width="20%"><%:SINR 信噪比 : %></td><td id="sinr"></td><td></td></tr>
<tr><td width="20%"><%:连接状态监控 : %></td><td id="conmon"></td><td></td></tr>
</table>
</fieldset>
<fieldset class="cbi-section" id="cbi-stationinfo" style="display: none;">
<h3><%:基站信息%></h3>
<table width="100%" cellspacing="10">
<tr><td width="20%"><%:MCC/MNC 国家码/网络码 %> :</td><td id="mcc"></td><td id="mnc"></td></tr>
<tr><td width="20%"><%:eNB ID : %></td><td><ul><span id="rnc" class="r"></span><span id="rncn" class="r"></span></ul></td><td></td></tr>
<tr><td width="20%"><%:TAC : %></td><td><ul><span id="lac" class="r"></span><span id="lacn" class="r"></span></ul></td><td></td></tr>
<tr><td width="20%"><%:Cell ID : %></td><td><ul><span id="cid" class="r"></span><span id="cidn" class="r"></span></ul></td><td></td></tr>
<tr><td width="20%"><%:Band 频段 : %></td><td id="lband"></td><td></td></tr>
<tr><td width="20%"><%:Channel 频点 : %></td><td id="channel"></td><td></td></tr>
<tr><td width="20%"><%:PCI 物理小区标识 : %></td><td id="pci"></td><td></td></tr>
<tr><td width="20%"><%:Maximum Qos 最大Qos级别 : %></td><td><ul><span id="down" class="r"></span><span id="up" class="r"></span></ul></td><td></td></tr>
</table>
</fieldset> -->
<% if havegps == 1 then %>
<fieldset class="cbi-section" id="cbi-gpsinfo">
<h3><%:GPS 定位%></h3>
<table width="550" border="0">
<tr>
<td width="30%"><div align="right"><%:纬度 %> :</div></td>
<td><ul id="lat"></ul></td>
<td width="1%">&nbsp;</td>
</tr>
<tr>
<td><div align="right"><%:经度 %> :</div></td>
<td><ul id="long"></ul></td>
<td>&nbsp;</td>
</tr>
</table>
</fieldset>
<% end %>
</div>
<%+footer%>

View File

@ -0,0 +1,124 @@
<%#
Copyright 2014 Aedan Renner <chipdankly@gmail.com>
Copyright 2018 Florian Eckert <fe@dev.tdt.de>
Licensed to the public under the GNU General Public License v2.
-%>
<script type="text/javascript">//<![CDATA[
XHR.poll(5, '<%=luci.dispatcher.build_url("admin", "network", "modem", "get_modems")%>', null,
function(x, modems)
{
console.log(modems);
if (modems.length!=0)
{
var modems_div=document.getElementById('modem_status_text');
//默认显示为模块加载中
var modem_view=String.format('<img src="<%=resource%>/icons/loading.gif" alt="<%:Loading%>" style="vertical-align:middle"/>'+"<%:Loading modem status...%>");
modems_div.innerHTML=modem_view;
modem_view = '';
for ( var key in modems)
{
var modem=modems[key];
// 检查模组名
if (modem["name"]==null) {
continue;
}
// 检查拨号模式
if (modem["mode"]==null) {
continue;
}
// 获取连接状态
var connect_status;
if (modem["connect_status"]!=null) {
// 首字母大写
connect_status=modem["connect_status"].charAt(0).toUpperCase() + modem["connect_status"].slice(1);
}
var state = '';
var css = '';
switch (modem["connect_status"])
{
case 'connect':
state = '<%:Connect%>';
css = 'success';
break;
case 'disconnect':
state = '<%:Disconnect%>';
css = 'danger';
break;
default:
state = '<%:Disabled%>';
css = 'warning';
break;
}
modem_view += String.format(
'<div class="alert-message %s">',
css
);
modem_view += String.format(
'<div><strong>No: </strong>%s</div>',
modem[".name"].slice(-1)
);
modem_view += String.format(
'<div><strong><%:Modem Name%>: </strong>%s</div>',
modem.name.toUpperCase()
);
modem_view += String.format(
'<div><strong><%:Data Interface%>: </strong>%s</div>',
modem.data_interface.toUpperCase()
);
modem_view += String.format(
'<div><strong><%:Mode%>: </strong>%s</div>',
modem.mode.toUpperCase()
);
modem_view += String.format(
'<div><strong><%:Mobile Network%>: </strong>%s</div>',
modem.network
);
modem_view += String.format(
'<div><strong><%:Connect Status%>: </strong>%s</div>',
<%:connect_status%>
);
modem_view += '</div>'
}
// 有参数不存在,则不显示模块状态
if (modem_view != '')
{
modems_div.innerHTML=modem_view;
// 显示模块状态(状态加载完成才显示)
document.getElementById("modem_status_field").style.display="block";
}
}
else
{
// 隐藏模块状态
document.getElementById("modem_status_field").style.display="none";
}
}
);
//]]>
</script>
<style type="text/css">
#modem_status_text > div {
display: inline-block;
margin: 1rem;
padding: 1rem;
width: 15rem;
float: left;
line-height: 125%;
}
</style>
<!-- 默认隐藏模块状态 -->
<fieldset id="modem_status_field" class="cbi-section" style="display: none;">
<!-- <legend><%:Modem Status%></legend> -->
<h3><%:Modem Status%></h3>
<div id="modem_status_text">
<strong><%:No modems found%></strong>
</div>
</fieldset>

View File

@ -1,458 +0,0 @@
msgid "Base Setting"
msgstr "基本设置"
msgid "Modem"
msgstr "移动通信模组"
msgid "Modem Config"
msgstr "模组配置"
msgid "Modem Status"
msgstr "模组状态"
msgid "Modem Name"
msgstr "模组名称"
msgid "Modem Debug"
msgstr "模组调试"
msgid "Modem Select"
msgstr "模组选择"
msgid "Check information about adapted modem on this page"
msgstr "在此页面查看已适配模组的信息"
msgid "Not adapted to this modem"
msgstr "未适配该模组"
msgid "Loading modem information"
msgstr "正在加载模组信息"
msgid "Loading modem status"
msgstr "正在加载模组状态"
msgid "Loading modem"
msgstr "正在加载模组"
msgid "Dial Config"
msgstr "拨号配置"
msgid "Add dialing configuration to all modules on this page"
msgstr "在此页面给所有模组添加拨号配置"
msgid "Global Config"
msgstr "全局配置"
msgid "connect"
msgstr "已连接"
msgid "disconnect"
msgstr "未连接"
msgid "disabled"
msgstr "未启用"
msgid "Data Interface"
msgstr "数据接口"
msgid "Mode"
msgstr "模式"
msgid "Connect Status"
msgstr "连接状态"
msgid "Config List"
msgstr "配置列表"
msgid "Debug Your Module"
msgstr "调试你的模组"
msgid "Select a modem for debugging"
msgstr "选择一个模组进行调试"
msgid "Network Preferences"
msgstr "网络偏好"
msgid "Current"
msgstr "当前"
msgid "Option"
msgstr "选项"
msgid "Config"
msgstr "配置"
msgid "AT Command"
msgstr "AT命令"
msgid "Quick Option"
msgstr "快捷选项"
msgid "Auto"
msgstr "自动"
msgid "Custom"
msgstr "自定义"
msgid "Quick Commands"
msgstr "快捷命令"
msgid "Enter Command"
msgstr "输入命令"
msgid "Apply"
msgstr "应用"
msgid "Send"
msgstr "发送"
msgid "Clean"
msgstr "清空"
msgid "Response"
msgstr "响应"
msgid "Return to old page"
msgstr "返回旧界面"
msgid "Return to modem debug"
msgstr "返回模组调试界面"
msgid "Custom quick commands"
msgstr "自定义快捷命令"
msgid "Customize your quick commands"
msgstr "自定义你的快捷命令"
msgid "Custom Commands"
msgstr "自定义命令"
msgid "Serial Number"
msgstr "序号"
msgid "Description"
msgstr "描述"
msgid "Command"
msgstr "命令"
msgid "Modem Information"
msgstr "模组信息"
msgid "No modems found"
msgstr "没有找到模组"
msgid "Check to enable all configurations"
msgstr "勾选启用全部配置"
msgid "General Settings"
msgstr "通用配置"
msgid "Advanced Settings"
msgstr "高级配置"
msgid "Remarks"
msgstr "备注"
msgid "Mobile Network"
msgstr "移动网络"
msgid "UNKNOWN"
msgstr "未知"
msgid "unknown"
msgstr "未知"
msgid "Mobile network not found"
msgstr "未发现移动网络"
msgid "The network device was not found"
msgstr "找不到网络设备"
msgid "Only display the modes available for the adaptation modem"
msgstr "仅显示适配模组可用的拨号模式"
msgid "Dial Tool"
msgstr "拨号工具"
msgid "After switching the dialing tool, it may be necessary to restart the module or restart the router to recognize the module."
msgstr "切换拨号工具后,可能需要重启模组或重启路由器才能识别模组。"
msgid "Auto Choose"
msgstr "自动选择"
msgid "quectel-CM"
msgstr "移远模组拨号工具"
msgid "mmcli"
msgstr "模组管理工具"
msgid "PDP Type"
msgstr "网络类型"
msgid "APN"
msgstr "接入点"
msgid "China Mobile"
msgstr "中国移动"
msgid "China Unicom"
msgstr "中国联通"
msgid "China Telecom"
msgstr "中国电信"
msgid "China Broadcast"
msgstr "中国广电"
msgid "Skytone"
msgstr "天际通"
msgid "Authentication Type"
msgstr "认证类型"
msgid "PAP/CHAP (both)"
msgstr "PAP/CHAP (均使用)"
msgid "NONE"
msgstr "无"
msgid "PAP/CHAP Username"
msgstr "PAP/CHAP 用户名"
msgid "PAP/CHAP Password"
msgstr "PAP/CHAP 密码"
msgid "Message"
msgstr "信息"
msgid "Base Information"
msgstr "基本信息"
msgid "Manufacturer"
msgstr "制造商"
msgid "Revision"
msgstr "固件版本"
msgid "AT Port"
msgstr "AT串口"
msgid "Temperature"
msgstr "温度"
msgid "Update Time"
msgstr "更新时间"
msgid "SIM Information"
msgstr "SIM卡信息"
msgid "Unknown SIM card status"
msgstr "未知SIM卡状态"
msgid "SIM card not inserted"
msgstr "SIM卡未插入"
msgid "ISP"
msgstr "运营商"
msgid "SIM Status"
msgstr "SIM卡状态"
msgid "miss"
msgstr "未插入"
msgid "locked"
msgstr "锁定"
msgid "SIM Slot"
msgstr "SIM卡卡槽"
msgid "SIM Number"
msgstr "SIM卡号码"
msgid "IMEI"
msgstr "国际移动设备识别码"
msgid "IMSI"
msgstr "国际移动用户识别码"
msgid "ICCID"
msgstr "集成电路卡识别码"
msgid "Network Information"
msgstr "网络信息"
msgid "Network Type"
msgstr "网络类型"
msgid "Tx Rate"
msgstr "上传速率"
msgid "Rx Rate"
msgstr "下载速率"
msgid "RSSI"
msgstr "接收信号强度指示"
msgid "BER"
msgstr "信道误码率"
msgid "Cell Information"
msgstr "小区信息"
msgid "Network Mode"
msgstr "网络模式"
msgid "NR5G-SA Mode"
msgstr "NR5G-SA 模式"
msgid "EN-DC Mode"
msgstr "EN-DC 模式"
msgid "LTE Mode"
msgstr "LTE 模式"
msgid "WCDMA Mode"
msgstr "WCDMA 模式"
msgid "MCC"
msgstr "移动国家代码"
msgid "MNC"
msgstr "移动网络代码"
msgid "Duplex Mode"
msgstr "双工模式"
msgid "LAC"
msgstr "位置区码"
msgid "Cell ID"
msgstr "小区ID"
msgid "Physical Cell ID"
msgstr "物理小区ID"
msgid "TAC"
msgstr "跟踪区编码"
msgid "ARFCN"
msgstr "绝对射频信道号"
msgid "EARFCN"
msgstr "E-UTRA绝对射频信道号"
msgid "UARFCN"
msgstr "UTRA绝对射频信道号"
msgid "Band"
msgstr "频段"
msgid "Freq band indicator"
msgstr "频带指示"
msgid "UL Bandwidth"
msgstr "上行带宽"
msgid "DL Bandwidth"
msgstr "下行带宽"
msgid "RSRP"
msgstr "参考信号接收功率"
msgid "RSRQ"
msgstr "参考信号接收质量"
msgid "RSSI"
msgstr "接收信号强度指示"
msgid "SINR"
msgstr "信号与干扰加噪声比"
msgid "RSSNR"
msgstr "信号干扰比"
msgid "SCS"
msgstr "NR子载波间隔"
msgid "CQI"
msgstr "信道质量指示"
msgid "TX Power"
msgstr "TX 功率"
msgid "PSC"
msgstr "主扰码"
msgid "RAC"
msgstr "路由区域码"
msgid "RSCP"
msgstr "接收信号码功率"
msgid "每比特能量与干扰功率密度(干扰比)之比"
msgstr "Eb/Io"
msgid "每比特能量与噪声功率密度(噪声比)之比"
msgstr "Eb/No"
msgid "每码片能量与干扰功率密度(干扰比)之比"
msgstr "Ec/Io"
msgid "每码片能量与噪声功率密度(噪声比)之比"
msgstr "Ec/No"
msgid "Physical Channel"
msgstr "物理信道"
msgid "Spreading Factor"
msgstr "扩频因子"
msgid "Slot"
msgstr "插槽格式"
msgid "Speech Code"
msgstr "语音编码"
msgid "Compression Mode"
msgstr "压缩模式"
msgid "RxLev"
msgstr "接收信号功率"
msgid "CHN-CMCC"
msgstr "中国移动"
msgid "CMCC"
msgstr "中国移动"
msgid "46000"
msgstr "中国移动"
msgid "CHN-UNICOM"
msgstr "中国联通"
msgid "UNICOM"
msgstr "中国联通"
msgid "CUCC"
msgstr "中国联通"
msgid "46001"
msgstr "中国联通"
msgid "CHN-CT"
msgstr "中国电信"
msgid "CHN-TELECOM"
msgstr "中国电信"
msgid "CTCC"
msgstr "中国电信"
msgid "CT"
msgstr "中国电信"
msgid "46011"
msgstr "中国电信"

View File

@ -31,6 +31,10 @@ config custom-commands
option description '查询PDP信息 > AT+CGDCONT?' option description '查询PDP信息 > AT+CGDCONT?'
option command 'AT+CGDCONT?' option command 'AT+CGDCONT?'
config custom-commands
option description '查询PDP地址 > AT+CGPADDR'
option command 'AT+CGPADDR'
config custom-commands config custom-commands
option description '最小功能模式 > AT+CFUN=0' option description '最小功能模式 > AT+CFUN=0'
option command 'AT+CFUN=0' option command 'AT+CFUN=0'
@ -204,7 +208,7 @@ config custom-commands
option command 'AT+GTUSBMODE=18' option command 'AT+GTUSBMODE=18'
config custom-commands config custom-commands
option description '锁4G > AT+GTACT=2":"AT+GTACT=2' option description '锁4G > AT+GTACT=2'
option command 'AT+GTACT=2' option command 'AT+GTACT=2'
config custom-commands config custom-commands

View File

@ -0,0 +1,24 @@
#!/bin/sh
# Copyright (C) 2023 Siriling <siriling@qq.com>
#导入组件工具
source "/usr/share/modem/modem_util.sh"
#网络设备名称不存在,退出
[ -z "${INTERFACE}" ] && exit
#网络设备路径不存在,退出
[ -z "${DEVPATH}" ] && exit
#始终确保存在运行目录
mkdir -m 0755 -p "${MODEM_RUNDIR}"
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

View File

@ -0,0 +1,19 @@
#!/bin/sh
# Copyright (C) 2023 Siriling <siriling@qq.com>
#导入组件工具
source "/usr/share/modem/modem_util.sh"
#只在添加和移除的时候执行
# [ "$ACTION" != "add" ] && [ "$ACTION" != "remove" ] && exit
#设备号不存在退出去掉多余的tty设备
[ -z "${DEVNUM}" ] && exit
#测试
# test_usb_hotplug
#始终确保存在运行目录
mkdir -m 0755 -p "${MODEM_RUNDIR}"
#设置USB设备
m_check_usb_device "${ACTION}" "${DEVNUM}" "${PRODUCT}" "/sys${DEVPATH}"

View File

@ -1,18 +1,28 @@
#!/bin/sh /etc/rc.common #!/bin/sh /etc/rc.common
# Copyright (C) 2006-2014 OpenWrt.org # Copyright (C) 2023 Siriling <siriling@qq.com>
START=90 START=90
STOP=13 STOP=13
USE_PROCD=1 USE_PROCD=1
#脚本目录
SCRIPT_DIR="/usr/share/modem"
#运行目录
MODEM_RUNDIR="/var/run/modem"
MODEM_RUN_CONFIG="${MODEM_RUNDIR}/config.cache"
#导入组件工具
source "${SCRIPT_DIR}/modem_debug.sh"
#设置拨号模式 #设置拨号模式
# $1:拨号模式 # $1:拨号模式
# set_mode() # set_mode()
# { # {
# #获取AT串口、制造商、模块名 # #获取AT串口、制造商、模块名
# local at_port=$(uci -q get modem.modem$modem_no.at_port) # local at_port=$(uci -q get modem.modem${modem_no}.at_port)
# local manufacturer=$(uci -q get modem.modem$modem_no.manufacturer) # local manufacturer=$(uci -q get modem.modem${modem_no}.manufacturer)
# local name=$(uci -q get modem.modem$modem_no.name) # local name=$(uci -q get modem.modem${modem_no}.name)
# #分制造商设置不同的AT命令 # #分制造商设置不同的AT命令
# local command # local command
@ -30,7 +40,7 @@ USE_PROCD=1
# #查询当前拨号模式 # #查询当前拨号模式
# command='AT+QCFG="usbnet"' # command='AT+QCFG="usbnet"'
# local at_result=$(sh /usr/share/modem/modem_at.sh $at_port $command) # local at_result=$(sh ${SCRIPT_DIR}/modem_at.sh $at_port $command)
# if [[ "$at_result" != *"$mode_num"* ]]; then # if [[ "$at_result" != *"$mode_num"* ]]; then
# #切换到指定的拨号模式 # #切换到指定的拨号模式
@ -43,7 +53,7 @@ USE_PROCD=1
# "ncm") command='AT+QCFG="usbnet",5' ;; # "ncm") command='AT+QCFG="usbnet",5' ;;
# *) command='AT+QCFG="usbnet",0' ;; # *) command='AT+QCFG="usbnet",0' ;;
# esac # esac
# at_result=$(sh /usr/share/modem/modem_at.sh "$at_port" "$command") # at_result=$(sh ${SCRIPT_DIR}/modem_at.sh "$at_port" "$command")
# #移远切换模式后,还需要重启模块,待测试 # #移远切换模式后,还需要重启模块,待测试
# sleep 5 # sleep 5
# modem_scan # modem_scan
@ -63,7 +73,7 @@ USE_PROCD=1
# #查询当前拨号模式 # #查询当前拨号模式
# command='AT+GTUSBMODE?' # command='AT+GTUSBMODE?'
# local at_result=$(sh /usr/share/modem/modem_at.sh $at_port $command) # local at_result=$(sh ${SCRIPT_DIR}/modem_at.sh $at_port $command)
# if [[ "$at_result" != *"$mode_num"* ]]; then # if [[ "$at_result" != *"$mode_num"* ]]; then
# #切换到指定的拨号模式 # #切换到指定的拨号模式
# case $1 in # case $1 in
@ -75,7 +85,7 @@ USE_PROCD=1
# "ncm") command='AT+GTUSBMODE=23' ;; # "ncm") command='AT+GTUSBMODE=23' ;;
# *) command='AT+GTUSBMODE=32' ;; # *) command='AT+GTUSBMODE=32' ;;
# esac # esac
# at_result=$(sh /usr/share/modem/modem_at.sh "$at_port" "$command") # at_result=$(sh ${SCRIPT_DIR}/modem_at.sh "$at_port" "$command")
# sleep 5 # sleep 5
# modem_scan # modem_scan
# fi # fi
@ -93,10 +103,12 @@ USE_PROCD=1
# $1:网络接口名称 # $1:网络接口名称
set_firewall() set_firewall()
{ {
local num=`uci show firewall | grep "name='wan'" | wc -l` local interface_name="$1"
local wwan_num=`uci -q get firewall.@zone[$num].network | grep -w "$1" | wc -l`
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)
if [ "$wwan_num" = "0" ]; then if [ "$wwan_num" = "0" ]; then
uci add_list firewall.@zone[$num].network="$1" uci add_list firewall.@zone[$num].network="${interface_name}"
fi fi
uci commit firewall uci commit firewall
} }
@ -106,20 +118,21 @@ set_firewall()
# $2:网络接口 # $2:网络接口
set_ipv4_interface() set_ipv4_interface()
{ {
#配置中不存在这个网络接口配置,或这个网络接口配置的设备不同 local interface_name="$1"
if [ "$(uci -q get network.$1.device)" != "$2" ] && [ "$(uci -q get network.$1.ifname)" != "$2" ]; then local network_interface="$2"
uci set network.$1='interface'
uci set network.$1.proto='dhcp'
uci set network.$1.device="$2"
uci set network.$1.ifname="$2"
uci commit network
#加入WAN防火墙 #添加或修改网络配置
set_firewall $1 uci set network.${interface_name}='interface'
uci set network.${interface_name}.proto='dhcp'
uci set network.${interface_name}.device="${network_interface}"
uci set network.${interface_name}.ifname="${network_interface}"
uci commit network
#启动网络接口 #加入WAN防火墙
ifup $1 set_firewall "${interface_name}"
fi
#启动网络接口
ifup "${interface_name}"
} }
#设置IPv6网络接口 #设置IPv6网络接口
@ -127,23 +140,22 @@ set_ipv4_interface()
# $2:网络接口 # $2:网络接口
set_ipv6_interface() set_ipv6_interface()
{ {
if [ "$(uci -q get network.$1.device)" != "$2" ] && [ "$(uci -q get network.$1.ifname)" != "$2" ] ; then local interface_name="$1"
uci set network.$1='interface' local network_interface="$2"
uci set network.$1.proto='dhcpv6'
uci set network.$1.extendprefix='1'
uci set network.$1.device="$2"
uci set network.$1.ifname="$2"
uci commit network
#加入WAN防火墙 #添加或修改网络配置
set_firewall $1 uci set network.${interface_name}='interface'
else uci set network.${interface_name}.proto='dhcpv6'
uci set network.$1.extendprefix='1' uci set network.${interface_name}.extendprefix='1'
uci commit network uci set network.${interface_name}.device="${network_interface}"
fi uci set network.${interface_name}.ifname="${network_interface}"
uci commit network
#加入WAN防火墙
set_firewall "${interface_name}"
#启动网络接口 #启动网络接口
ifup $1 ifup "${interface_name}"
} }
#设置IPV4和IPv6网络接口 #设置IPV4和IPv6网络接口
@ -152,10 +164,14 @@ set_ipv6_interface()
# $3:网络接口 # $3:网络接口
set_ipv4v6_interface() set_ipv4v6_interface()
{ {
local ipv4_interface_name="$1"
local ipv6_interface_name="$2"
local network_interface="$3"
#设置IPV4网络接口 #设置IPV4网络接口
set_ipv4_interface $1 $3 set_ipv4_interface "${ipv4_interface_name}" "${network_interface}"
#设置IPV6网络接口别名 #设置IPV6网络接口别名
set_ipv6_interface $2 "@$1" set_ipv6_interface "${ipv6_interface_name}" "@${ipv4_interface_name}"
} }
#设置网络接口 #设置网络接口
@ -163,11 +179,14 @@ set_ipv4v6_interface()
# $2:网络接口 # $2:网络接口
set_interface() set_interface()
{ {
local modem_no="$1"
local network_interface="$2"
case $pdp_type in case $pdp_type in
"ipv4") set_ipv4_interface wwan_5g_$1 $2 ;; "ipv4") set_ipv4_interface "wwan_5g_${modem_no}" "${network_interface}" ;;
"ipv6") set_ipv6_interface wwan6_5g_$1 $2 ;; "ipv6") set_ipv6_interface "wwan6_5g_${modem_no}" "${network_interface}" ;;
"ipv4v6") set_ipv4v6_interface "wwan_5g_$1" "wwan6_5g_$1" $2 ;; "ipv4v6") set_ipv4v6_interface "wwan_5g_${modem_no}" "wwan6_5g_${modem_no}" "${network_interface}" ;;
*) set_ipv4v6_interface "wwan_5g_$1" "wwan6_5g_$1" $2 ;; *) set_ipv4v6_interface "wwan_5g_${modem_no}" "wwan6_5g_${modem_no}" "${network_interface}" ;;
esac esac
} }
@ -176,32 +195,38 @@ quectel_cm()
{ {
#拨号 #拨号
procd_open_instance procd_open_instance
procd_set_param command quectel-CM procd_set_param command "quectel-CM"
case $pdp_type in case $pdp_type in
"ipv4") procd_append_param command -4 ;; "ipv4") procd_append_param command "-4" ;;
"ipv6") procd_append_param command -6 ;; "ipv6") procd_append_param command "-6" ;;
"ipv4v6") procd_append_param command -4 -6 ;; "ipv4v6") procd_append_param command "-4" "-6" ;;
*) procd_append_param command -4 -6 ;; *) procd_append_param command "-4" "-6" ;;
esac esac
if [ "$network_bridge" = "1" ]; then
procd_append_param command "-b"
fi
if [ "$apn" != "" ]; then if [ "$apn" != "" ]; then
procd_append_param command -s $apn procd_append_param command "-s" "$apn"
fi fi
if [ "$username" != "" ]; then if [ "$username" != "" ]; then
procd_append_param command $username procd_append_param command "$username"
fi fi
if [ "$password" != "" ]; then if [ "$password" != "" ]; then
procd_append_param command $password procd_append_param command "$password"
fi fi
if [ "$auth" != "none" ]; then if [ "$auth" != "none" ]; then
procd_append_param command $auth procd_append_param command "$auth"
fi fi
if [ "$network" != "" ]; then if [ "$network" != "" ]; then
procd_append_param command -i $network procd_append_param command "-i" "$network"
fi fi
#日志
procd_append_param command "-f" "${MODEM_RUNDIR}/modem${modem_no}_dial.cache"
procd_set_param respawn procd_set_param respawn
procd_set_param procd_pid /var/run/modem/modem$modem_no.pid procd_set_param procd_pid "${MODEM_RUNDIR}/modem${modem_no}.pid"
procd_close_instance procd_close_instance
} }
@ -210,58 +235,52 @@ quectel_cm()
# $2:模组路径 # $2:模组路径
set_interface_modemmanager() set_interface_modemmanager()
{ {
if [ "$(uci -q get network.$1.device)" != "$2" ] ; then local interface_name="$1"
uci set network.$1='interface' local path="$2"
uci set network.$1.proto='modemmanager'
uci set network.$1.device="$2" if [ "$(uci -q get network.${interface_name}.device)" != "${path}" ] ; then
uci set network.$1.auth="$auth" uci set network.${interface_name}='interface'
uci set network.$1.iptype="$pdp_type" uci set network.${interface_name}.proto='modemmanager'
uci set network.${interface_name}.device="${path}"
uci set network.${interface_name}.auth="$auth"
uci set network.${interface_name}.iptype="$pdp_type"
if [ "$apn" != "" ]; then if [ "$apn" != "" ]; then
uci set network.$1.apn="$apn" uci set network.${interface_name}.apn="$apn"
fi fi
if [ "$pincode" != "" ]; then if [ "$pincode" != "" ]; then
uci set network.$1.pincode="$pincode" uci set network.${interface_name}.pincode="$pincode"
fi fi
if [ "$username" != "" ]; then if [ "$username" != "" ]; then
uci set network.$1.username="$username" uci set network.${interface_name}.username="$username"
fi fi
if [ "$password" != "" ]; then if [ "$password" != "" ]; then
uci set network.$1.password="$password" uci set network.${interface_name}.password="$password"
fi fi
uci commit network uci commit network
#加入WAN防火墙 #加入WAN防火墙
set_firewall $1 set_firewall "${interface_name}"
fi fi
#启动网络接口 #启动网络接口
ifup $1 ifup "${interface_name}"
} }
#模块管理 #模块管理
modemmanager() modemmanager()
{ {
#获取接口名称 #获取接口名称
local interface_name="wwan_5g_$modem_no" local interface_name="wwan_5g_${modem_no}"
#获取调制解调器设备(模组路径) #获取调制解调器设备(模组路径)
local path=$(uci -q get modem.modem$modem_no.path) local path=$(uci -q get modem.modem${modem_no}.path)
#设置Modem Manager网络接口 #设置Modem Manager网络接口
set_interface_modemmanager "$interface_name" "$path" set_interface_modemmanager "$interface_name" "$path"
#获取网络接口、AT串口、制造商
local network_interface=$(uci -q get modem.modem$modem_no.network_interface)
local at_port=$(uci -q get modem.modem$modem_no.at_port)
local manufacturer=$(uci -q get modem.modem$modem_no.manufacturer)
#设置网络接口
set_interface $modem_no "$network_interface"
#拨号 #拨号
procd_open_instance procd_open_instance
procd_set_param command sh /usr/share/modem/modem_network_task.sh "$id" "$at_port" "$manufacturer" "modemmanager" "$interface_name" procd_set_param command sh ${SCRIPT_DIR}/modem_network_task.sh "${id}" "${modem_no}" "modemmanager"
procd_set_param respawn procd_set_param respawn
procd_close_instance procd_close_instance
} }
@ -269,8 +288,8 @@ modemmanager()
qmi() qmi()
{ {
#设置网络接口 #设置网络接口
local network_interface=$(uci -q get modem.modem$modem_no.network_interface) local network_interface=$(uci -q get modem.modem${modem_no}.network_interface)
set_interface $modem_no "$network_interface" set_interface "${modem_no}" "$network_interface"
#选择拨号工具 #选择拨号工具
case $dial_tool in case $dial_tool in
@ -283,32 +302,28 @@ qmi()
gobinet() gobinet()
{ {
#获取网络接口、AT串口、制造商 #获取网络接口
local network_interface=$(uci -q get modem.modem$modem_no.network_interface) local network_interface=$(uci -q get modem.modem${modem_no}.network_interface)
local at_port=$(uci -q get modem.modem$modem_no.at_port)
local manufacturer=$(uci -q get modem.modem$modem_no.manufacturer)
#设置网络接口 #设置网络接口
set_interface $modem_no "$network_interface" set_interface "${modem_no}" "$network_interface"
#拨号 #拨号
procd_open_instance procd_open_instance
procd_set_param command sh /usr/share/modem/modem_network_task.sh "$id" "$at_port" "$manufacturer" "gobinet" procd_set_param command sh ${SCRIPT_DIR}/modem_network_task.sh "${id}" "${modem_no}" "gobinet"
procd_set_param respawn procd_set_param respawn
procd_close_instance procd_close_instance
} }
ecm() ecm()
{ {
#获取网络接口、AT串口、制造商 #获取网络接口
local network_interface=$(uci -q get modem.modem$modem_no.network_interface) local network_interface=$(uci -q get modem.modem${modem_no}.network_interface)
local at_port=$(uci -q get modem.modem$modem_no.at_port)
local manufacturer=$(uci -q get modem.modem$modem_no.manufacturer)
#设置网络接口 #设置网络接口
set_interface $modem_no "$network_interface" set_interface "${modem_no}" "$network_interface"
#拨号 #拨号
procd_open_instance procd_open_instance
procd_set_param command sh /usr/share/modem/modem_network_task.sh "$id" "$at_port" "$manufacturer" "ecm" procd_set_param command sh ${SCRIPT_DIR}/modem_network_task.sh "${id}" "${modem_no}" "ecm"
procd_set_param respawn procd_set_param respawn
procd_close_instance procd_close_instance
} }
@ -320,8 +335,16 @@ mbim()
rndis() rndis()
{ {
ecm #获取网络接口
#广和通的rndis和ecm不同后续再测试 local network_interface=$(uci -q get modem.modem${modem_no}.network_interface)
#设置网络接口
set_interface "${modem_no}" "$network_interface"
#拨号
procd_open_instance
procd_set_param command sh ${SCRIPT_DIR}/modem_network_task.sh "${id}" "${modem_no}" "rndis"
procd_set_param respawn
procd_close_instance
} }
ncm() ncm()
@ -345,16 +368,16 @@ stop_qmi()
#Modem Manager #Modem Manager
#获取接口名称 #获取接口名称
local interface_name="wwan_5g_$modem_no" local interface_name="wwan_5g_${modem_no}"
if [[ "$command" = *"$interface_name"* ]]; then if [[ "$command" = *"$interface_name"* ]]; then
local pid=$(echo "$response" | jq -r ".modem.instances.$i.pid") local pid=$(echo "$response" | jq -r ".modem.instances.$i.pid")
kill $pid >/dev/null 2>&1 kill $pid >/dev/null 2>&1
#获取调制解调器设备(模组路径) #获取调制解调器设备(模组路径)
local path=$(uci -q get modem.modem$modem_no.path) local path=$(uci -q get modem.modem${modem_no}.path)
mmcli -m "$path" --simple-disconnect mmcli -m "$path" --simple-disconnect
#删除网络接口 #删除网络接口
uci del network.$interface_name uci -q del network.${interface_name}
uci commit network uci commit network
fi fi
done done
@ -363,35 +386,46 @@ stop_qmi()
stop_gobinet() stop_gobinet()
{ {
#获取AT串口、制造商 #获取AT串口、制造商
local at_port=$(uci -q get modem.modem$modem_no.at_port) local at_port=$(uci -q get modem.modem${modem_no}.at_port)
local manufacturer=$(uci -q get modem.modem$modem_no.manufacturer) local manufacturer=$(uci -q get modem.modem${modem_no}.manufacturer)
#停止拨号 #停止拨号
local command="sh /usr/share/modem/modem_at.sh $at_port" local at_command
if [ "$manufacturer" = "quectel" ]; then if [ "$manufacturer" = "quectel" ]; then
$command 'ATI' at_command='ATI'
elif [ "$manufacturer" = "fibocom" ]; then elif [ "$manufacturer" = "fibocom" ]; then
$command 'AT$QCRMCALL=0,1' at_command='AT$QCRMCALL=0,1'
else else
$command 'ATI' at_command='ATI'
fi fi
tmp=$(at "${at_port}" "${at_command}")
} }
stop_ecm() stop_ecm()
{ {
#获取AT串口、制造商 #获取AT串口、制造商、平台、连接定义
local at_port=$(uci -q get modem.modem$modem_no.at_port) local at_port=$(uci -q get modem.modem${modem_no}.at_port)
local manufacturer=$(uci -q get modem.modem$modem_no.manufacturer) 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 command="sh /usr/share/modem/modem_at.sh $at_port" local at_command
if [ "$manufacturer" = "quectel" ]; then if [ "$manufacturer" = "quectel" ]; then
$command 'ATI' at_command="AT+QNETDEVCTL=${define_connect},2,1"
elif [ "$manufacturer" = "fibocom" ]; then elif [ "$manufacturer" = "fibocom" ]; then
$command 'AT+GTRNDIS=0,1' #联发科平台广和通FM350-GL
if [ "$platform" = "mediatek" ]; then
at_command="AT+CGACT=0,${define_connect}"
else
at_command="AT+GTRNDIS=0,${define_connect}"
fi
else else
$command 'ATI' at_command='ATI'
fi fi
tmp=$(at "${at_port}" "${at_command}")
} }
stop_mbim() stop_mbim()
@ -417,10 +451,10 @@ get_modem_no()
local modem_number=$(uci -q get modem.@global[0].modem_number) local modem_number=$(uci -q get modem.@global[0].modem_number)
local modem_network local modem_network
for i in $(seq 0 $((modem_number-1))); do for i in $(seq 0 $((modem_number-1))); do
modem_network=$(uci -q get modem.modem$i.network) modem_network=$(uci -q get modem.modem${i}.network)
if [ "$modem_network" = "$1" ]; then if [ "$modem_network" = "$1" ]; then
#模块序号 #模块序号
modem_no=$i modem_no=${i}
break break
fi fi
done done
@ -430,6 +464,8 @@ get_modem_no()
# $1:配置ID # $1:配置ID
get_instance_status() get_instance_status()
{ {
local config_id="$1"
#获取modem的实例信息 #获取modem的实例信息
local response=$(ubus call service list '{"name": "modem"}') local response=$(ubus call service list '{"name": "modem"}')
local instance_number=$(echo "$response" | jq -r ".modem.instances | length") local instance_number=$(echo "$response" | jq -r ".modem.instances | length")
@ -439,9 +475,9 @@ get_instance_status()
local command=$(echo "$response" | jq -r ".modem.instances.instance$i.command") local command=$(echo "$response" | jq -r ".modem.instances.instance$i.command")
if [ "$running_status" = "true" ] && [[ "$command" = *"$network"* ]]; then if [ "$running_status" = "true" ] && [[ "$command" = *"$network"* ]]; then
#查看配置ID是否记录在已运行的文件里 #查看配置ID是否记录在已运行的文件里
local run_config="/tmp/modem/run_config" local run_config="/var/run/modem"
local run_config_id=$(grep -n "$network" "$run_config" | cut -d ';' -f 2) local run_config_id=$(grep -n "$network" "$run_config" | cut -d ',' -f 2)
if [ "$1" = "$run_config_id" ]; then if [ "${config_id}" = "$run_config_id" ]; then
status=2 status=2
break break
else else
@ -452,6 +488,54 @@ get_instance_status()
done done
} }
#获取拨号模式
# $1:模块号
get_mode()
{
local modem_no="$1"
local manufacturer=$(uci -q get modem.modem${modem_no}.manufacturer)
local at_port=$(uci -q get modem.modem${modem_no}.at_port)
local platform=$(uci -q get modem.modem${modem_no}.platform)
mode=$(${manufacturer}_get_mode ${at_port} ${platform})
echo "$mode"
}
#网络预设
connect_presets()
{
local at_port=$(uci -q get modem.modem${modem_no}.at_port)
#运营商选择设置
local at_command='AT+COPS=0,0'
tmp=$(at "${at_port}" "${at_command}")
#设置IPv6地址格式
at_command='AT+CGPIAF=1,0,0,0'
tmp=$(at "${at_port}" "${at_command}")
#获取连接定义
local define_connect=$(uci -q get modem.modem${modem_no}.define_connect)
#获取PDP类型和APN
local pdp_type_tmp="IPV4V6"
if [ -n "$pdp_type" ]; then
pdp_type_tmp=$(echo $pdp_type | tr 'a-z' 'A-Z')
fi
local apn_tmp=""
if [ -n "$apn" ]; then
apn_tmp=$(echo $apn | tr 'a-z' 'A-Z')
fi
#PDP设置
at_command="AT+CGDCONT=$define_connect,\"$pdp_type_tmp\",\"$apn_tmp\""
tmp=$(at "${at_port}" "${at_command}")
#制造商私有预设
# quectel_presets
# fibocom_presets
}
#停止拨号 #停止拨号
# $1:配置ID # $1:配置ID
stop_dial() stop_dial()
@ -460,18 +544,20 @@ stop_dial()
local network=$(uci -q get modem.$1.network) #移动网络 local network=$(uci -q get modem.$1.network) #移动网络
#把配置ID从临时列表中移除 #把配置ID从临时列表中移除
local run_config="/tmp/modem/run_config" if [ -f "${MODEM_RUN_CONFIG}" ] && grep -q "${network}" "${MODEM_RUN_CONFIG}"; then
local row_no=$(grep -n "$id" "$run_config" | cut -d ':' -f 1) #该配置ID在运行需要删除记录
if [ -z "$row_no" ]; then sed -i "/${id}/d" "${MODEM_RUN_CONFIG}"
else
return 0 return 0
fi fi
#该配置ID在运行需要删除记录
sed -i "$row_no"d $run_config
#获取模块序号 #获取模块序号
get_modem_no $network get_modem_no "${network}"
#获取模组的拨号模式 #获取模组的拨号模式
local mode=$(uci -q get modem.modem$modem_no.mode) [ -z "${modem_no}" ] && return 0
local mode=$(get_mode ${modem_no})
[ -z "$mode" ] && return
#根据不同的拨号模式停止拨号 #根据不同的拨号模式停止拨号
if [ "$mode" = "qmi" ]; then if [ "$mode" = "qmi" ]; then
@ -501,50 +587,56 @@ dial()
return 0 return 0
} }
local remarks #备注 local remarks #备注
local network #移动网络 local network #移动网络
local dial_tool #拨号工具 local dial_tool #拨号工具
local pdp_type #网络类型IP类型 local pdp_type #网络类型IP类型
local apn #接入点 local network_bridge #网络桥接
local username #用户名 local apn #接入点
local password #密码 local username #用户名
local auth #认证类型 local password #密码
local auth #认证类型
config_get remarks $1 remarks config_get remarks $1 remarks
config_get network $1 network config_get network $1 network
config_get dial_tool $1 dial_tool config_get dial_tool $1 dial_tool
config_get pdp_type $1 pdp_type config_get pdp_type $1 pdp_type
config_get network_bridge $1 network_bridge
config_get apn $1 apn config_get apn $1 apn
config_get username $1 username config_get username $1 username
config_get password $1 password config_get password $1 password
config_get auth $1 auth config_get auth $1 auth
#获取模块序号 #获取模块序号
get_modem_no $network get_modem_no "${network}"
#获取模组的拨号模式 #获取模组的拨号模式
[ -z "$modem_no" ] && return 0 [ -z "${modem_no}" ] && return 0
local mode=$(uci -q get modem.modem$modem_no.mode) local mode=$(get_mode ${modem_no})
if [ "$mode" = "unknown" ]; then [ -z "$mode" ] && {
mode="qmi" mode="qmi";
fi }
#查看移动网络是否已经有配置在运行 #查看移动网络是否已经有配置在运行
local run_path="/tmp/modem" mkdir -m 0755 -p "${MODEM_RUNDIR}"
mkdir -p $run_path if [ -f "${MODEM_RUN_CONFIG}" ]; then #文件存在
local run_config="/tmp/modem/run_config" if grep -q "${network}" "${MODEM_RUN_CONFIG}"; then #是否记录该移动网络
local row_no=$(grep -n "$network" "$run_config" | cut -d ':' -f 1) #1:wwan0;abc->1 local config_id=$(awk -v network="${network}" -F',' '!/^#/ && $0 ~ network { print $2 }' "${MODEM_RUN_CONFIG}")
if [ -z "$row_no" ]; then #未记录该移动网络 #该移动网络已存在,且已有其他配置运行
#把已运行的配置ID加入到记录中 if [ "$id" != "$config_id" ]; then
echo "$network;$id" >> "$run_path/run_config" uci set modem.$1.enable=0
else uci commit modem
local run_config_id=$(grep -n "$network" "$run_config" | cut -d ';' -f 2) return 0
if [ "$id" != "$run_config_id" ]; then #该移动网络已存在,且已有其他配置运行 fi
uci set modem.$1.enable=0 else
uci commit modem echo "${network},${id}" >> "${MODEM_RUN_CONFIG}"
return 0
fi fi
else
echo "${network},${id}" >> "${MODEM_RUN_CONFIG}"
fi fi
#设置网络预设
connect_presets
#根据不同的拨号模式拨号 #根据不同的拨号模式拨号
if [ "$mode" = "qmi" ]; then if [ "$mode" = "qmi" ]; then
qmi qmi
@ -588,7 +680,7 @@ stop_service()
local modem_number=$(uci -q get modem.@global[0].modem_number) local modem_number=$(uci -q get modem.@global[0].modem_number)
for i in $(seq 0 $((modem_number-1))); do for i in $(seq 0 $((modem_number-1))); do
modem_no=$i modem_no=$i
local mode=$(uci -q get modem.modem$modem_no.mode) local mode=$(uci -q get modem.modem${modem_no}.mode)
case $mode in case $mode in
"gobinet") stop_gobinet ;; "gobinet") stop_gobinet ;;
"ecm") stop_ecm ;; "ecm") stop_ecm ;;

View File

@ -1,12 +1,18 @@
#!/bin/sh /etc/rc.common #!/bin/sh /etc/rc.common
# Copyright (C) 2023 Siriling <siriling@qq.com>
START=99 START=70
STOP=13 STOP=13
USE_PROCD=1 USE_PROCD=1
start_service() { #脚本目录
procd_open_instance #启动实例 SCRIPT_DIR="/usr/share/modem"
procd_set_param command /bin/sh /usr/share/modem/modem_task.sh
procd_set_param respawn # 定义respawn参数告知procd当task程序退出后尝试进行重启 start_service()
procd_close_instance #关闭实例 {
/bin/sh ${SCRIPT_DIR}/modem_init.sh
# procd_open_instance #启动实例
# procd_set_param command /bin/sh /usr/share/modem/modem_init.sh
# procd_set_param respawn # 定义respawn参数告知procd当task程序退出后尝试进行重启
# procd_close_instance #关闭实例
} }

View File

@ -1,9 +1,10 @@
#!/bin/sh #!/bin/sh
# Copyright (C) 2023 Siriling <siriling@qq.com>
uci -q get modem.global >/dev/null || uci -q batch <<-EOF >/dev/null uci -q get modem.global >/dev/null || uci -q batch <<-EOF >/dev/null
set modem.global=global set modem.global=global
set modem.global.enable=1 set modem.global.enable=1
set modem.global.modem_number=0 set modem.@global[0].modem_number=0
commit modem commit modem
EOF EOF

View File

@ -7,6 +7,7 @@
{"查询网络信号质量5G > AT+CESQ":"AT+CESQ"}, {"查询网络信号质量5G > AT+CESQ":"AT+CESQ"},
{"查询网络信息 > AT+COPS?":"AT+COPS?"}, {"查询网络信息 > AT+COPS?":"AT+COPS?"},
{"查询PDP信息 > AT+CGDCONT?":"AT+CGDCONT?"}, {"查询PDP信息 > AT+CGDCONT?":"AT+CGDCONT?"},
{"查询PDP地址 > AT+CGPADDR":"AT+CGPADDR"},
{"最小功能模式 > AT+CFUN=0":"AT+CFUN=0"}, {"最小功能模式 > AT+CFUN=0":"AT+CFUN=0"},
{"全功能模式 > AT+CFUN=1":"AT+CFUN=1"}, {"全功能模式 > AT+CFUN=1":"AT+CFUN=1"},
{"重启模组 > AT+CFUN=1,1":"AT+CFUN=1,1"}, {"重启模组 > AT+CFUN=1,1":"AT+CFUN=1,1"},

View File

@ -1,5 +1,24 @@
#!/bin/sh #!/bin/sh
current_dir="$(dirname "$0")" # Copyright (C) 2023 Siriling <siriling@qq.com>
#脚本目录
SCRIPT_DIR="/usr/share/modem"
#预设
fibocom_presets()
{
#自动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"
}
#获取拨号模式 #获取拨号模式
# $1:AT串口 # $1:AT串口
@ -7,13 +26,14 @@ current_dir="$(dirname "$0")"
fibocom_get_mode() fibocom_get_mode()
{ {
local at_port="$1" local at_port="$1"
local platform="$2"
at_command="AT+GTUSBMODE?" at_command="AT+GTUSBMODE?"
local mode_num=$(sh $current_dir/modem_at.sh $at_port $at_command | grep "+GTUSBMODE:" | sed 's/+GTUSBMODE: //g' | sed 's/\r//g') local mode_num=$(sh ${SCRIPT_DIR}/modem_at.sh $at_port $at_command | grep "+GTUSBMODE:" | sed 's/+GTUSBMODE: //g' | sed 's/\r//g')
#获取芯片平台 #获取芯片平台
local platform="$2"
if [ -z "$platform" ]; then if [ -z "$platform" ]; then
local modem_number=$(uci -q get modem.global.modem_number) local modem_number=$(uci -q get modem.@global[0].modem_number)
for i in $(seq 0 $((modem_number-1))); do for i in $(seq 0 $((modem_number-1))); do
local at_port_tmp=$(uci -q get modem.modem$i.at_port) local at_port_tmp=$(uci -q get modem.modem$i.at_port)
if [ "$at_port" = "$at_port_tmp" ]; then if [ "$at_port" = "$at_port_tmp" ]; then
@ -80,7 +100,7 @@ fibocom_set_mode()
#获取芯片平台 #获取芯片平台
local platform local platform
local modem_number=$(uci -q get modem.global.modem_number) local modem_number=$(uci -q get modem.@global[0].modem_number)
for i in $(seq 0 $((modem_number-1))); do for i in $(seq 0 $((modem_number-1))); do
local at_port_tmp=$(uci -q get modem.modem$i.at_port) local at_port_tmp=$(uci -q get modem.modem$i.at_port)
if [ "$at_port" = "$at_port_tmp" ]; then if [ "$at_port" = "$at_port_tmp" ]; then
@ -127,7 +147,7 @@ fibocom_set_mode()
#设置模组 #设置模组
at_command="AT+GTUSBMODE=$mode_num" at_command="AT+GTUSBMODE=$mode_num"
sh $current_dir/modem_at.sh $at_port "$at_command" sh ${SCRIPT_DIR}/modem_at.sh $at_port "$at_command"
} }
#获取网络偏好 #获取网络偏好
@ -136,7 +156,7 @@ fibocom_get_network_prefer()
{ {
local at_port="$1" local at_port="$1"
at_command="AT+GTACT?" at_command="AT+GTACT?"
local network_prefer_num=$(sh $current_dir/modem_at.sh $at_port $at_command | grep "+GTACT:" | awk -F',' '{print $1}' | sed 's/+GTACT: //g') 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_3g="0"; local network_prefer_3g="0";
local network_prefer_4g="0"; local network_prefer_4g="0";
@ -229,27 +249,47 @@ fibocom_set_network_prefer()
#设置模组 #设置模组
local at_port="$1" local at_port="$1"
at_command="AT+GTACT=$network_prefer_num" at_command="AT+GTACT=$network_prefer_num"
sh $current_dir/modem_at.sh $at_port "$at_command" sh ${SCRIPT_DIR}/modem_at.sh $at_port "$at_command"
}
#获取自检信息
# $1:AT串口
fibocom_get_self_test_info()
{
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}"
} }
#获取连接状态 #获取连接状态
# $1:AT串口 # $1:AT串口
# $2:连接定义
fibocom_get_connect_status() fibocom_get_connect_status()
{ {
local at_port="$1" local at_port="$1"
at_command="AT+CGDCONT?" local define_connect="$2"
local response=$(sh $current_dir/modem_at.sh $at_port $at_command | sed -n '2p' | awk -F'"' '{print $6}') #默认值为1
local not_ip="0.0.0.0,0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0" [ -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 local connect_status
if [ "$response" = "$not_ip" ]; then if [ -z "$ipv4" ] || [[ "$ipv4" = *"$not_ip"* ]]; then
connect_status="disconnect" connect_status="disconnect"
else else
connect_status="connect" connect_status="connect"
fi fi
echo "$connect_status" echo "${connect_status}"
} }
#基本信息 #基本信息
@ -258,21 +298,21 @@ fibocom_base_info()
debug "Fibocom base info" debug "Fibocom base info"
#Name名称 #Name名称
at_command="AT+CGMM" at_command="AT+CGMM?"
name=$(sh $current_dir/modem_at.sh $at_port $at_command | sed -n '2p' | sed 's/\r//g') name=$(sh ${SCRIPT_DIR}/modem_at.sh $at_port $at_command | grep "+CGMM: " | awk -F'"' '{print $2}')
#Manufacturer制造商 #Manufacturer制造商
at_command="AT+CGMI" at_command="AT+CGMI?"
manufacturer=$(sh $current_dir/modem_at.sh $at_port $at_command | sed -n '2p' | sed 's/\r//g') manufacturer=$(sh ${SCRIPT_DIR}/modem_at.sh $at_port $at_command | grep "+CGMI: " | awk -F'"' '{print $2}')
#Revision固件版本 #Revision固件版本
at_command="AT+CGMR" at_command="AT+CGMR?"
revision=$(sh $current_dir/modem_at.sh $at_port $at_command | sed -n '2p' | sed 's/\r//g') revision=$(sh ${SCRIPT_DIR}/modem_at.sh $at_port $at_command | grep "+CGMR: " | awk -F'"' '{print $2}')
#Mode拨号模式 #Mode拨号模式
mode=$(fibocom_get_mode $at_port | tr 'a-z' 'A-Z') mode=$(fibocom_get_mode $at_port | tr 'a-z' 'A-Z')
#Temperature温度 #Temperature温度
at_command="AT+MTSM=1,6" at_command="AT+MTSM=1,6"
response=$(sh $current_dir/modem_at.sh $at_port $at_command | sed -n '2p' | sed 's/+MTSM: //g' | sed 's/\r//g') response=$(sh ${SCRIPT_DIR}/modem_at.sh $at_port $at_command | sed -n '2p' | sed 's/+MTSM: //g' | sed 's/\r//g')
if [ -n "$response" ]; then if [ -n "$response" ]; then
temperature="$response$(printf "\xc2\xb0")C" temperature="$response$(printf "\xc2\xb0")C"
fi fi
@ -304,7 +344,7 @@ fibocom_get_sim_status()
*"PH-CORP PUK"*) sim_status="MT is waiting corporate personalization unblocking password to be given" ;; *"PH-CORP PUK"*) sim_status="MT is waiting corporate personalization unblocking password to be given" ;;
*) sim_status="unknown" ;; *) sim_status="unknown" ;;
esac esac
echo "$sim_status" echo "${sim_status}"
} }
#SIM卡信息 #SIM卡信息
@ -313,16 +353,16 @@ fibocom_sim_info()
debug "Fibocom sim info" debug "Fibocom sim info"
#SIM SlotSIM卡卡槽 #SIM SlotSIM卡卡槽
at_command="AT+GTDUALSIM" at_command="AT+GTDUALSIM?"
sim_slot=$(sh $current_dir/modem_at.sh $at_port $at_command | grep "+GTDUALSIM:" | awk -F'"' '{print $2}' | sed 's/SUB//g') sim_slot=$(sh ${SCRIPT_DIR}/modem_at.sh ${at_port} ${at_command} | grep "+GTDUALSIM" | awk -F'"' '{print $2}' | sed 's/SUB//g')
#IMEI国际移动设备识别码 #IMEI国际移动设备识别码
at_command="AT+CGSN" at_command="AT+CGSN?"
imei=$(sh $current_dir/modem_at.sh $at_port $at_command | sed -n '2p' | sed 's/\r//g') imei=$(sh ${SCRIPT_DIR}/modem_at.sh ${at_port} ${at_command} | grep "+CGSN: " | awk -F'"' '{print $2}')
#SIM StatusSIM状态 #SIM StatusSIM状态
at_command="AT+CPIN?" at_command="AT+CPIN?"
sim_status_flag=$(sh $current_dir/modem_at.sh $at_port $at_command | sed -n '2p') sim_status_flag=$(sh ${SCRIPT_DIR}/modem_at.sh ${at_port} ${at_command} | grep "+CPIN: ")
sim_status=$(fibocom_get_sim_status "$sim_status_flag") sim_status=$(fibocom_get_sim_status "$sim_status_flag")
if [ "$sim_status" != "ready" ]; then if [ "$sim_status" != "ready" ]; then
@ -331,7 +371,7 @@ fibocom_sim_info()
#ISP互联网服务提供商 #ISP互联网服务提供商
at_command="AT+COPS?" at_command="AT+COPS?"
isp=$(sh $current_dir/modem_at.sh $at_port $at_command | sed -n '2p' | awk -F'"' '{print $2}') 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 # if [ "$isp" = "CHN-CMCC" ] || [ "$isp" = "CMCC" ]|| [ "$isp" = "46000" ]; then
# isp="中国移动" # isp="中国移动"
# elif [ "$isp" = "CHN-UNICOM" ] || [ "$isp" = "UNICOM" ] || [ "$isp" = "46001" ]; then # elif [ "$isp" = "CHN-UNICOM" ] || [ "$isp" = "UNICOM" ] || [ "$isp" = "46001" ]; then
@ -341,16 +381,36 @@ fibocom_sim_info()
# fi # fi
#SIM NumberSIM卡号码手机号 #SIM NumberSIM卡号码手机号
at_command="AT+CNUM?" at_command="AT+CNUM"
sim_number=$(sh $current_dir/modem_at.sh $at_port $at_command | sed -n '2p' | awk -F'"' '{print $2}') 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国际移动用户识别码 #IMSI国际移动用户识别码
at_command="AT+CIMI" at_command="AT+CIMI?"
imsi=$(sh $current_dir/modem_at.sh $at_port $at_command | sed -n '2p' | sed 's/\r//g') imsi=$(sh ${SCRIPT_DIR}/modem_at.sh ${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}')
}
#ICCID集成电路卡识别码 #ICCID集成电路卡识别码
at_command="AT+ICCID" at_command="AT+ICCID"
iccid=$(sh $current_dir/modem_at.sh $at_port $at_command | grep -o "+ICCID:[ ]*[-0-9]\+" | grep -o "[-0-9]\{1,4\}") iccid=$(sh ${SCRIPT_DIR}/modem_at.sh ${at_port} ${at_command} | grep -o "+ICCID:[ ]*[-0-9]\+" | grep -o "[-0-9]\{1,4\}")
}
#获取网络类型
# $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}"
} }
#获取信号强度指示4G #获取信号强度指示4G
@ -371,22 +431,28 @@ fibocom_network_info()
debug "Fibocom network info" debug "Fibocom network info"
#Connect Status连接状态 #Connect Status连接状态
connect_status=$(fibocom_get_connect_status $at_port) connect_status=$(fibocom_get_connect_status ${at_port} ${define_connect})
if [ "$connect_status" != "connect" ]; then if [ "$connect_status" != "connect" ]; then
return return
fi fi
#Network Type网络类型 #Network Type网络类型
at_command="AT+PSRAT?" at_command="AT+PSRAT?"
network_type=$(sh $current_dir/modem_at.sh $at_port $at_command | grep "+PSRAT:" | sed 's/+PSRAT: //g' | sed 's/\r//g') network_type=$(sh ${SCRIPT_DIR}/modem_at.sh ${at_port} ${at_command} | grep "+PSRAT:" | sed 's/+PSRAT: //g' | sed 's/\r//g')
[ -z "$network_type" ] && {
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')
network_type=$(fibocom_get_rat ${rat_num})
}
#设置网络类型为5G时信号强度指示用RSRP代替 #设置网络类型为5G时信号强度指示用RSRP代替
# at_command="AT+GTCSQNREN=1" # at_command="AT+GTCSQNREN=1"
# sh $current_dir/modem_at.sh $at_port $at_command # sh ${SCRIPT_DIR}/modem_at.sh $at_port $at_command
#CSQ信号强度 #CSQ信号强度
at_command="AT+CSQ" at_command="AT+CSQ"
response=$(sh $current_dir/modem_at.sh $at_port $at_command | grep "+CSQ:" | sed 's/+CSQ: //g' | sed 's/\r//g') response=$(sh ${SCRIPT_DIR}/modem_at.sh $at_port $at_command | grep "+CSQ:" | sed 's/+CSQ: //g' | sed 's/\r//g')
#RSSI4G信号强度指示 #RSSI4G信号强度指示
# rssi_num=$(echo $response | awk -F',' '{print $1}') # rssi_num=$(echo $response | awk -F',' '{print $1}')
@ -401,7 +467,7 @@ fibocom_network_info()
#速率统计 #速率统计
at_command="AT+GTSTATIS?" at_command="AT+GTSTATIS?"
response=$(sh $current_dir/modem_at.sh $at_port $at_command | grep "+GTSTATIS:" | sed 's/+GTSTATIS: //g' | sed 's/\r//g') response=$(sh ${SCRIPT_DIR}/modem_at.sh $at_port $at_command | grep "+GTSTATIS:" | sed 's/+GTSTATIS: //g' | sed 's/\r//g')
#当前上传速率单位Byte/s #当前上传速率单位Byte/s
tx_rate=$(echo $response | awk -F',' '{print $2}') tx_rate=$(echo $response | awk -F',' '{print $2}')
@ -524,10 +590,19 @@ fibocom_cell_info()
#RSRQRSRPSINR #RSRQRSRPSINR
at_command='AT+GTCCINFO?' at_command='AT+GTCCINFO?'
response=$(sh $current_dir/modem_at.sh $at_port $at_command) response=$(sh ${SCRIPT_DIR}/modem_at.sh $at_port $at_command)
local rat=$(echo "$response" | grep "service" | awk -F' ' '{print $1}') 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})
}
response=$(echo "$response" | sed -n '4p') response=$(echo "$response" | sed -n '4p')
case $rat in case $rat in
"NR") "NR")
network_mode="NR5G-SA Mode" network_mode="NR5G-SA Mode"
@ -538,16 +613,16 @@ fibocom_cell_info()
nr_arfcn=$(echo "$response" | awk -F',' '{print $7}') nr_arfcn=$(echo "$response" | awk -F',' '{print $7}')
nr_physical_cell_id=$(echo "$response" | awk -F',' '{print $8}') nr_physical_cell_id=$(echo "$response" | awk -F',' '{print $8}')
nr_band_num=$(echo "$response" | awk -F',' '{print $9}') nr_band_num=$(echo "$response" | awk -F',' '{print $9}')
nr_band=$(fibocom_get_band "NR" $nr_band_num) nr_band=$(fibocom_get_band "NR" ${nr_band_num})
nr_dl_bandwidth_num=$(echo "$response" | awk -F',' '{print $10}') nr_dl_bandwidth_num=$(echo "$response" | awk -F',' '{print $10}')
nr_dl_bandwidth=$(fibocom_get_nr_dl_bandwidth $nr_dl_bandwidth_num) nr_dl_bandwidth=$(fibocom_get_nr_dl_bandwidth ${nr_dl_bandwidth_num})
nr_sinr=$(echo "$response" | awk -F',' '{print $11}') nr_sinr=$(echo "$response" | awk -F',' '{print $11}')
nr_rxlev_num=$(echo "$response" | awk -F',' '{print $12}') nr_rxlev_num=$(echo "$response" | awk -F',' '{print $12}')
nr_rxlev=$(fibocom_get_rxlev "NR" $nr_rxlev_num) nr_rxlev=$(fibocom_get_rxlev "NR" ${nr_rxlev_num})
nr_rsrp_num=$(echo "$response" | awk -F',' '{print $13}') nr_rsrp_num=$(echo "$response" | awk -F',' '{print $13}')
nr_rsrp=$(fibocom_get_rsrp "NR" $nr_rsrp_num) nr_rsrp=$(fibocom_get_rsrp "NR" ${nr_rsrp_num})
nr_rsrq_num=$(echo "$response" | awk -F',' '{print $14}' | sed 's/\r//g') nr_rsrq_num=$(echo "$response" | awk -F',' '{print $14}' | sed 's/\r//g')
nr_rsrq=$(fibocom_get_rsrq "NR" $nr_rsrq_num) nr_rsrq=$(fibocom_get_rsrq "NR" ${nr_rsrq_num})
;; ;;
"LTE-NR") "LTE-NR")
network_mode="EN-DC Mode" network_mode="EN-DC Mode"
@ -559,18 +634,18 @@ fibocom_cell_info()
endc_lte_earfcn=$(echo "$response" | awk -F',' '{print $7}') endc_lte_earfcn=$(echo "$response" | awk -F',' '{print $7}')
endc_lte_physical_cell_id=$(echo "$response" | awk -F',' '{print $8}') endc_lte_physical_cell_id=$(echo "$response" | awk -F',' '{print $8}')
endc_lte_band_num=$(echo "$response" | awk -F',' '{print $9}') endc_lte_band_num=$(echo "$response" | awk -F',' '{print $9}')
endc_lte_band=$(fibocom_get_band "LTE" $endc_lte_band_num) endc_lte_band=$(fibocom_get_band "LTE" ${endc_lte_band_num})
ul_bandwidth_num=$(echo "$response" | awk -F',' '{print $10}') ul_bandwidth_num=$(echo "$response" | awk -F',' '{print $10}')
endc_lte_ul_bandwidth=$(fibocom_get_ul_bandwidth $ul_bandwidth_num) endc_lte_ul_bandwidth=$(fibocom_get_ul_bandwidth ${ul_bandwidth_num})
endc_lte_dl_bandwidth="$endc_lte_ul_bandwidth" endc_lte_dl_bandwidth="$endc_lte_ul_bandwidth"
endc_lte_rssnr_num=$(echo "$response" | awk -F',' '{print $11}') endc_lte_rssnr_num=$(echo "$response" | awk -F',' '{print $11}')
endc_lte_rssnr=$(fibocom_get_rssnr $endc_lte_rssnr_num) endc_lte_rssnr=$(fibocom_get_rssnr ${endc_lte_rssnr_num})
endc_lte_rxlev_num=$(echo "$response" | awk -F',' '{print $12}') endc_lte_rxlev_num=$(echo "$response" | awk -F',' '{print $12}')
endc_lte_rxlev=$(fibocom_get_rxlev "LTE" $endc_lte_rxlev_num) endc_lte_rxlev=$(fibocom_get_rxlev "LTE" ${endc_lte_rxlev_num})
endc_lte_rsrp_num=$(echo "$response" | awk -F',' '{print $13}') endc_lte_rsrp_num=$(echo "$response" | awk -F',' '{print $13}')
endc_lte_rsrp=$(fibocom_get_rsrp "LTE" $endc_lte_rsrp_num) endc_lte_rsrp=$(fibocom_get_rsrp "LTE" ${endc_lte_rsrp_num})
endc_lte_rsrq_num=$(echo "$response" | awk -F',' '{print $14}' | sed 's/\r//g') 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=$(fibocom_get_rsrq "LTE" ${endc_lte_rsrq_num})
#NR5G-NSA #NR5G-NSA
endc_nr_mcc=$(echo "$response" | awk -F',' '{print $3}') endc_nr_mcc=$(echo "$response" | awk -F',' '{print $3}')
endc_nr_mnc=$(echo "$response" | awk -F',' '{print $4}') endc_nr_mnc=$(echo "$response" | awk -F',' '{print $4}')
@ -579,16 +654,16 @@ fibocom_cell_info()
endc_nr_arfcn=$(echo "$response" | awk -F',' '{print $7}') endc_nr_arfcn=$(echo "$response" | awk -F',' '{print $7}')
endc_nr_physical_cell_id=$(echo "$response" | awk -F',' '{print $8}') endc_nr_physical_cell_id=$(echo "$response" | awk -F',' '{print $8}')
endc_nr_band_num=$(echo "$response" | awk -F',' '{print $9}') endc_nr_band_num=$(echo "$response" | awk -F',' '{print $9}')
endc_nr_band=$(fibocom_get_band "NR" $endc_nr_band_num) endc_nr_band=$(fibocom_get_band "NR" ${endc_nr_band_num})
nr_dl_bandwidth_num=$(echo "$response" | awk -F',' '{print $10}') nr_dl_bandwidth_num=$(echo "$response" | awk -F',' '{print $10}')
endc_nr_dl_bandwidth=$(fibocom_get_nr_dl_bandwidth $nr_dl_bandwidth_num) endc_nr_dl_bandwidth=$(fibocom_get_nr_dl_bandwidth ${nr_dl_bandwidth_num})
endc_nr_sinr=$(echo "$response" | awk -F',' '{print $11}') endc_nr_sinr=$(echo "$response" | awk -F',' '{print $11}')
endc_nr_rxlev_num=$(echo "$response" | awk -F',' '{print $12}') endc_nr_rxlev_num=$(echo "$response" | awk -F',' '{print $12}')
endc_nr_rxlev=$(fibocom_get_rxlev "NR" $endc_nr_rxlev_num) endc_nr_rxlev=$(fibocom_get_rxlev "NR" ${endc_nr_rxlev_num})
endc_nr_rsrp_num=$(echo "$response" | awk -F',' '{print $13}') endc_nr_rsrp_num=$(echo "$response" | awk -F',' '{print $13}')
endc_nr_rsrp=$(fibocom_get_rsrp "NR" $endc_nr_rsrp_num) endc_nr_rsrp=$(fibocom_get_rsrp "NR" ${endc_nr_rsrp_num})
endc_nr_rsrq_num=$(echo "$response" | awk -F',' '{print $14}' | sed 's/\r//g') 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=$(fibocom_get_rsrq "NR" ${endc_nr_rsrq_num})
;; ;;
"LTE"|"eMTC"|"NB-IoT") "LTE"|"eMTC"|"NB-IoT")
network_mode="LTE Mode" network_mode="LTE Mode"
@ -599,17 +674,17 @@ fibocom_cell_info()
lte_earfcn=$(echo "$response" | awk -F',' '{print $7}') lte_earfcn=$(echo "$response" | awk -F',' '{print $7}')
lte_physical_cell_id=$(echo "$response" | awk -F',' '{print $8}') lte_physical_cell_id=$(echo "$response" | awk -F',' '{print $8}')
lte_band_num=$(echo "$response" | awk -F',' '{print $9}') lte_band_num=$(echo "$response" | awk -F',' '{print $9}')
lte_band=$(fibocom_get_band "LTE" $lte_band_num) lte_band=$(fibocom_get_band "LTE" ${lte_band_num})
ul_bandwidth_num=$(echo "$response" | awk -F',' '{print $10}') ul_bandwidth_num=$(echo "$response" | awk -F',' '{print $10}')
lte_ul_bandwidth=$(fibocom_get_ul_bandwidth $ul_bandwidth_num) lte_ul_bandwidth=$(fibocom_get_ul_bandwidth ${ul_bandwidth_num})
lte_dl_bandwidth="$lte_ul_bandwidth" lte_dl_bandwidth="$lte_ul_bandwidth"
lte_rssnr=$(echo "$response" | awk -F',' '{print $11}') lte_rssnr=$(echo "$response" | awk -F',' '{print $11}')
lte_rxlev_num=$(echo "$response" | awk -F',' '{print $12}') lte_rxlev_num=$(echo "$response" | awk -F',' '{print $12}')
lte_rxlev=$(fibocom_get_rxlev "LTE" $lte_rxlev_num) lte_rxlev=$(fibocom_get_rxlev "LTE" ${lte_rxlev_num})
lte_rsrp_num=$(echo "$response" | awk -F',' '{print $13}') lte_rsrp_num=$(echo "$response" | awk -F',' '{print $13}')
lte_rsrp=$(fibocom_get_rsrp "LTE" $lte_rsrp_num) lte_rsrp=$(fibocom_get_rsrp "LTE" ${lte_rsrp_num})
lte_rsrq_num=$(echo "$response" | awk -F',' '{print $14}' | sed 's/\r//g') lte_rsrq_num=$(echo "$response" | awk -F',' '{print $14}' | sed 's/\r//g')
lte_rsrq=$(fibocom_get_rsrq "LTE" $lte_rsrq_num) lte_rsrq=$(fibocom_get_rsrq "LTE" ${lte_rsrq_num})
;; ;;
"WCDMA"|"UMTS") "WCDMA"|"UMTS")
network_mode="WCDMA Mode" network_mode="WCDMA Mode"
@ -620,15 +695,15 @@ fibocom_cell_info()
wcdma_uarfcn=$(echo "$response" | awk -F',' '{print $7}') wcdma_uarfcn=$(echo "$response" | awk -F',' '{print $7}')
wcdma_psc=$(echo "$response" | awk -F',' '{print $8}') wcdma_psc=$(echo "$response" | awk -F',' '{print $8}')
wcdma_band_num=$(echo "$response" | awk -F',' '{print $9}') wcdma_band_num=$(echo "$response" | awk -F',' '{print $9}')
wcdma_band=$(fibocom_get_band "WCDMA" $wcdma_band_num) wcdma_band=$(fibocom_get_band "WCDMA" ${wcdma_band_num})
wcdma_ecno=$(echo "$response" | awk -F',' '{print $10}') wcdma_ecno=$(echo "$response" | awk -F',' '{print $10}')
wcdma_rscp=$(echo "$response" | awk -F',' '{print $11}') wcdma_rscp=$(echo "$response" | awk -F',' '{print $11}')
wcdma_rac=$(echo "$response" | awk -F',' '{print $12}') wcdma_rac=$(echo "$response" | awk -F',' '{print $12}')
wcdma_rxlev_num=$(echo "$response" | awk -F',' '{print $13}') wcdma_rxlev_num=$(echo "$response" | awk -F',' '{print $13}')
wcdma_rxlev=$(fibocom_get_rxlev "WCDMA" $wcdma_rxlev_num) wcdma_rxlev=$(fibocom_get_rxlev "WCDMA" ${wcdma_rxlev_num})
wcdma_reserved=$(echo "$response" | awk -F',' '{print $14}') wcdma_reserved=$(echo "$response" | awk -F',' '{print $14}')
wcdma_ecio_num=$(echo "$response" | awk -F',' '{print $15}' | sed 's/\r//g') wcdma_ecio_num=$(echo "$response" | awk -F',' '{print $15}' | sed 's/\r//g')
wcdma_ecio=$(fibocom_get_ecio $wcdma_ecio_num) wcdma_ecio=$(fibocom_get_ecio ${wcdma_ecio_num})
;; ;;
esac esac
} }
@ -638,18 +713,18 @@ fibocom_cell_info()
Fibocom_Cellinfo() Fibocom_Cellinfo()
{ {
#baseinfo.gcom #baseinfo.gcom
OX=$( sh $current_dir/modem_at.sh $at_port "ATI") OX=$( sh ${SCRIPT_DIR}/modem_at.sh $at_port "ATI")
OX=$( sh $current_dir/modem_at.sh $at_port "AT+CGEQNEG=1") OX=$( sh ${SCRIPT_DIR}/modem_at.sh $at_port "AT+CGEQNEG=1")
#cellinfo0.gcom #cellinfo0.gcom
# OX1=$( sh $current_dir/modem_at.sh $at_port "AT+COPS=3,0;+COPS?") # OX1=$( sh ${SCRIPT_DIR}/modem_at.sh $at_port "AT+COPS=3,0;+COPS?")
# OX2=$( sh $current_dir/modem_at.sh $at_port "AT+COPS=3,2;+COPS?") # OX2=$( sh ${SCRIPT_DIR}/modem_at.sh $at_port "AT+COPS=3,2;+COPS?")
OX=$OX1" "$OX2 OX=$OX1" "$OX2
#cellinfo.gcom #cellinfo.gcom
OY1=$( sh $current_dir/modem_at.sh $at_port "AT+CREG=2;+CREG?;+CREG=0") OY1=$( sh ${SCRIPT_DIR}/modem_at.sh $at_port "AT+CREG=2;+CREG?;+CREG=0")
OY2=$( sh $current_dir/modem_at.sh $at_port "AT+CEREG=2;+CEREG?;+CEREG=0") OY2=$( sh ${SCRIPT_DIR}/modem_at.sh $at_port "AT+CEREG=2;+CEREG?;+CEREG=0")
OY3=$( sh $current_dir/modem_at.sh $at_port "AT+C5GREG=2;+C5GREG?;+C5GREG=0") OY3=$( sh ${SCRIPT_DIR}/modem_at.sh $at_port "AT+C5GREG=2;+C5GREG?;+C5GREG=0")
OY=$OY1" "$OY2" "$OY3 OY=$OY1" "$OY2" "$OY3
@ -767,11 +842,13 @@ Fibocom_Cellinfo()
#获取Fibocom模块信息 #获取Fibocom模块信息
# $1:AT串口 # $1:AT串口
# $2:连接定义
get_fibocom_info() get_fibocom_info()
{ {
debug "get fibocom info" debug "get fibocom info"
#设置AT串口 #设置AT串口
at_port=$1 at_port="$1"
define_connect="$2"
#基本信息 #基本信息
fibocom_base_info fibocom_base_info
@ -796,7 +873,7 @@ get_fibocom_info()
# Fibocom_Cellinfo # Fibocom_Cellinfo
#基站信息 #基站信息
OX=$( sh $current_dir/modem_at.sh $at_port "AT+CPSI?") OX=$( sh ${SCRIPT_DIR}/modem_at.sh $at_port "AT+CPSI?")
rec=$(echo "$OX" | grep "+CPSI:") rec=$(echo "$OX" | grep "+CPSI:")
w=$(echo $rec |grep "NO SERVICE"| wc -l) w=$(echo $rec |grep "NO SERVICE"| wc -l)
if [ $w -ge 1 ];then if [ $w -ge 1 ];then
@ -874,7 +951,7 @@ get_fibocom_info()
fi fi
#CNMP #CNMP
OX=$( sh $current_dir/modem_at.sh $at_port "AT+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\}") CNMP=$(echo "$OX" | grep -o "+CNMP:[ ]*[0-9]\{1,3\}" | grep -o "[0-9]\{1,3\}")
if [ -n "$CNMP" ]; then if [ -n "$CNMP" ]; then
case $CNMP in case $CNMP in
@ -896,7 +973,7 @@ get_fibocom_info()
fi fi
# CMGRMI 信息 # CMGRMI 信息
OX=$( sh $current_dir/modem_at.sh $at_port "AT+CMGRMI=4") OX=$( sh ${SCRIPT_DIR}/modem_at.sh $at_port "AT+CMGRMI=4")
CAINFO=$(echo "$OX" | grep -o "$REGXz" | tr ' ' ':') CAINFO=$(echo "$OX" | grep -o "$REGXz" | tr ' ' ':')
if [ -n "$CAINFO" ]; then if [ -n "$CAINFO" ]; then
for CASV in $(echo "$CAINFO"); do for CASV in $(echo "$CAINFO"); do

View File

@ -6,6 +6,7 @@
{"查询网络信号质量5G > AT+CESQ":"AT+CESQ"}, {"查询网络信号质量5G > AT+CESQ":"AT+CESQ"},
{"查询网络信息 > AT+COPS?":"AT+COPS?"}, {"查询网络信息 > AT+COPS?":"AT+COPS?"},
{"查询PDP信息 > AT+CGDCONT?":"AT+CGDCONT?"}, {"查询PDP信息 > AT+CGDCONT?":"AT+CGDCONT?"},
{"查询PDP地址 > AT+CGPADDR":"AT+CGPADDR"},
{"最小功能模式 > AT+CFUN=0":"AT+CFUN=0"}, {"最小功能模式 > AT+CFUN=0":"AT+CFUN=0"},
{"全功能模式 > AT+CFUN=1":"AT+CFUN=1"}, {"全功能模式 > AT+CFUN=1":"AT+CFUN=1"},
{"设置当前使用的为卡1 > AT+GTDUALSIM=0":"AT+GTDUALSIM=0"}, {"设置当前使用的为卡1 > AT+GTDUALSIM=0":"AT+GTDUALSIM=0"},

View File

@ -1,8 +1,11 @@
#!/bin/sh #!/bin/sh
current_dir="$(dirname "$0")" # Copyright (C) 2023 Siriling <siriling@qq.com>
source "$current_dir/modem_debug.sh"
#脚本目录
SCRIPT_DIR="/usr/share/modem"
source "${SCRIPT_DIR}/modem_debug.sh"
#发送at命令 #发送at命令
# $1 AT串口 # $1 AT串口
# $2 AT命令 # $2 AT命令
at $1 $2 at "$1" "$2"

View File

@ -1,8 +1,12 @@
#!/bin/sh #!/bin/sh
current_dir="$(dirname "$0")" # Copyright (C) 2023 Siriling <siriling@qq.com>
source "$current_dir/quectel.sh"
source "$current_dir/fibocom.sh" #脚本目录
source "$current_dir/simcom.sh" SCRIPT_DIR="/usr/share/modem"
source "${SCRIPT_DIR}/quectel.sh"
source "${SCRIPT_DIR}/fibocom.sh"
# source "${SCRIPT_DIR}/simcom.sh"
#调试开关 #调试开关
# 0关闭 # 0关闭
@ -26,14 +30,15 @@ debug()
# $2 AT命令 # $2 AT命令
at() at()
{ {
local at_port="$1"
local new_str="${2/[$]/$}" local new_str="${2/[$]/$}"
local atCommand="${new_str/\"/\"}" local at_command="${new_str/\"/\"}"
#echo #echo
# echo -e $2 > $1 2>&1 # echo -e "${at_command}"" > "${at_port}" 2>&1
#sms_tool #sms_tool
sms_tool -d $1 at $atCommand 2>&1 sms_tool -d "${at_port}" at "${at_command}" 2>&1
} }
#测试时打开 #测试时打开
@ -45,11 +50,27 @@ at()
# $2:制造商 # $2:制造商
get_quick_commands() get_quick_commands()
{ {
local quick_option="$1"
local manufacturer="$2"
local quick_commands local quick_commands
case $1 in case "$quick_option" in
"auto") quick_commands=$(cat $current_dir/$2_at_commands.json) ;; "auto") quick_commands=$(cat ${SCRIPT_DIR}/${manufacturer}_at_commands.json) ;;
"custom") quick_commands=$(cat /etc/modem/custom_at_commands.json) ;; "custom") quick_commands=$(cat /etc/modem/custom_at_commands.json) ;;
*) quick_commands=$(cat $current_dir/$2_at_commands.json) ;; *) quick_commands=$(cat ${SCRIPT_DIR}/${manufacturer}_at_commands.json) ;;
esac esac
echo "$quick_commands" echo "$quick_commands"
} }
#拨号日志
# $1:AT命令
# $2:日志路径
dial_log()
{
local at_command="$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}"
}

View File

@ -1,9 +1,12 @@
#!/bin/sh #!/bin/sh
current_dir="$(dirname "$0")" # Copyright (C) 2023 Siriling <siriling@qq.com>
source "$current_dir/modem_debug.sh"
source "$current_dir/quectel.sh" #脚本目录
source "$current_dir/fibocom.sh" SCRIPT_DIR="/usr/share/modem"
# source "$current_dir/simcom.sh" source "${SCRIPT_DIR}/modem_debug.sh"
# source "${SCRIPT_DIR}/quectel.sh"
# source "${SCRIPT_DIR}/fibocom.sh"
# source "${SCRIPT_DIR}/simcom.sh"
#初值化数据结构 #初值化数据结构
init_modem_info() init_modem_info()
@ -344,7 +347,7 @@ get_modem_info()
#检查模块状态(是否处于重启,重置,串口异常状态) #检查模块状态(是否处于重启,重置,串口异常状态)
local at_command="ATI" local at_command="ATI"
local response=$(sh $current_dir/modem_at.sh $at_port $at_command) local response=$(sh ${SCRIPT_DIR}/modem_at.sh $at_port $at_command)
if [[ "$response" = *"failed"* ]] || [[ "$response" = *"$at_port"* ]]; then if [[ "$response" = *"failed"* ]] || [[ "$response" = *"$at_port"* ]]; then
debug "模组AT串口未就绪" debug "模组AT串口未就绪"
return return
@ -353,9 +356,9 @@ get_modem_info()
debug "根据模组的制造商获取信息" debug "根据模组的制造商获取信息"
#更多信息获取 #更多信息获取
case $manufacturer in case $manufacturer in
"quectel") get_quectel_info $at_port ;; "quectel") get_quectel_info "${at_port}" "${define_connect}" ;;
"fibocom") get_fibocom_info $at_port ;; "fibocom") get_fibocom_info "${at_port}" "${define_connect}" ;;
"simcom") get_simcom_info $at_port ;; "simcom") get_simcom_info "${at_port}" "${define_connect}" ;;
*) debug "未适配该模组" ;; *) debug "未适配该模组" ;;
esac esac
@ -366,6 +369,7 @@ get_modem_info()
#获取模组数据信息 #获取模组数据信息
# $1:AT串口 # $1:AT串口
# $2:制造商 # $2:制造商
# $3:连接定义
modem_info() modem_info()
{ {
#初值化模组信息 #初值化模组信息
@ -374,8 +378,10 @@ modem_info()
debug "初值化模组信息完成" debug "初值化模组信息完成"
#获取模组信息 #获取模组信息
at_port=$1 at_port="$1"
manufacturer=$2 manufacturer="$2"
define_connect="$3"
debug "获取模组信息" debug "获取模组信息"
get_modem_info get_modem_info
@ -387,4 +393,4 @@ modem_info()
# checkMobileNetwork # checkMobileNetwork
} }
modem_info $1 $2 modem_info "$1" "$2" "$3"

View File

@ -0,0 +1,27 @@
#!/bin/sh
# Copyright (C) 2023 Siriling <siriling@qq.com>
#脚本目录
SCRIPT_DIR="/usr/share/modem"
source "${SCRIPT_DIR}/modem_util.sh"
#模组配置初始化
modem_init()
{
#防止开机时存在
# [ -d "$MODEM_RUNDIR" ] && rm -rf "${MODEM_RUNDIR}"
m_log "info" "Clearing all modem configurations"
#清空模组配置
local modem_no
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

View File

@ -1,85 +1,209 @@
#!/bin/sh #!/bin/sh
current_dir="$(dirname "$0")" # Copyright (C) 2023 Siriling <siriling@qq.com>
source "$current_dir/modem_debug.sh"
source "$current_dir/modem_scan.sh"
#ECM拨号 #脚本目录
# $1:AT串口 SCRIPT_DIR="/usr/share/modem"
# $2:制造商
ecm_dial() #运行目录
{ MODEM_RUNDIR="/var/run/modem"
#拨号
local manufacturer=$2 #导入组件工具
local at_command source "${SCRIPT_DIR}/modem_debug.sh"
if [ "$manufacturer" = "quectel" ]; then
at_command='ATI'
elif [ "$manufacturer" = "fibocom" ]; then
at_command='AT+GTRNDIS=1,1'
else
at_command='ATI'
fi
sh "$current_dir/modem_at.sh" $1 $at_command
}
#GobiNet拨号 #GobiNet拨号
# $1:AT串口 # $1:AT串口
# $2:制造商 # $2:制造商
# $3:连接定义
gobinet_dial() 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 manufacturer=$2
local at_command local at_command
if [ "$manufacturer" = "quectel" ]; then if [ "$manufacturer" = "quectel" ]; then
at_command='ATI' at_command='ATI'
elif [ "$manufacturer" = "fibocom" ]; then elif [ "$manufacturer" = "fibocom" ]; then
at_command='AT$QCRMCALL=1,1' at_command='AT$QCRMCALL=1,3'
else else
at_command='ATI' at_command='ATI'
fi fi
sh "$current_dir/modem_at.sh" $1 $at_command
#打印日志
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}"
sleep 2s
#拨号
local 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}"
else
at_command='ATI'
fi
#打印日志
dial_log "${at_command}" "${MODEM_RUNDIR}/modem${modem_no}_dial.cache"
at "${at_port}" "${at_command}"
}
#RNDIS拨号
# $1:AT串口
# $2:制造商
# $3:平台
# $4:连接定义
# $5:接口名称
rndis_dial()
{
local at_port="$1"
local manufacturer="$2"
local platform="$3"
local define_connect="$4"
local interface_name="$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}"
#获取IPv4地址
at_command="AT+CGPADDR=${define_connect}"
local ipv4=$(at ${at_port} ${at_command} | grep "+CGPADDR: " | awk -F',' '{print $2}' | sed 's/"//g')
#设置静态地址
local ipv4_config=$(uci -q get network.${interface_name}.ipaddr)
if [ "$ipv4_config" != "$ipv4" ]; then
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 commit network
service network reload
fi
else
#拨号
ecm_dial "${at_port}" "${manufacturer}"
fi
} }
#Modem Manager拨号 #Modem Manager拨号
# $1:接口名称 # $1:接口名称
# $2:连接定义
modemmanager_dial() modemmanager_dial()
{ {
#激活
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 "$1"; ifup "$1";
} }
#检查模组网络连接 #检查模组网络连接
# $1:配置ID # $1:配置ID
# $2:AT串口 # $2:模组序号
# $3:制造商 # $3:拨号模式
# $4:拨号模式
# $5:接口名称
modem_network_task() 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}"
#重载配置解决AT命令发不出去的问题
# service modem reload
#IPv4地址缓存
local ipv4_cache
while true; do while true; do
#全局
local enable=$(uci -q get modem.@global[0].enable) local enable=$(uci -q get modem.@global[0].enable)
if [ "$enable" != "1" ] ;then if [ "$enable" != "1" ]; then
break break
fi fi
enable=$(uci -q get modem.$1.enable) #单个模组
if [ "$enable" != "1" ] ;then enable=$(uci -q get modem.$config_id.enable)
if [ "$enable" != "1" ]; then
break break
fi fi
#网络连接检查 #网络连接检查
debug "开启网络连接检查任务" local at_command="AT+CGPADDR=${define_connect}"
local at_port=$2 local ipv4=$(at ${at_port} ${at_command} | grep "+CGPADDR: " | awk -F'"' '{print $2}')
local at_command="AT+COPS?"
local connect_status=$(sh $current_dir/modem_at.sh $at_port $at_command | sed -n '2p') if [ -z "$ipv4" ] || [[ "$ipv4" = *"0.0.0.0"* ]] || [ "$ipv4" != "$ipv4_cache" ]; then
if [ "$connect_status" = "0" ]; then
case "$4" in if [ -z "$ipv4" ]; then
"ecm") ecm_dial "$at_port" "$3" ;; #输出日志
"gobinet") gobinet_dial "$at_port" "$3" ;; echo "$(date +"%Y-%m-%d %H:%M:%S") redefine connect" >> "${MODEM_RUNDIR}/modem${modem_no}_dial.cache"
"modemmanager") modemmanager_dial "$5" ;; service network modem
*) ecm_dial "$at_port" "$3" ;; sleep 1s
else
#缓存当前IP
ipv4_cache="${ipv4}"
#输出日志
echo "$(date +"%Y-%m-%d %H:%M:%S") Modem${modem_no} current IP : ${ipv4}" >> "${MODEM_RUNDIR}/modem${modem_no}_dial.cache"
fi
#输出日志
echo "$(date +"%Y-%m-%d %H:%M:%S") check or redial" >> "${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}" "${interface_name}" ;;
"modemmanager") modemmanager_dial "${interface_name}" "${define_connect}" ;;
*) ecm_dial "${at_port}" "${manufacturer}" "${define_connect}" ;;
esac esac
fi fi
debug "结束网络连接检查任务"
sleep 10s sleep 5s
done done
} }
modem_network_task $1 $2 $3 $4 modem_network_task "$1" "$2" "$3"

View File

@ -1,43 +1,73 @@
#!/bin/sh #!/bin/sh
current_dir="$(dirname "$0")" # Copyright (C) 2023 Siriling <siriling@qq.com>
source "$current_dir/modem_debug.sh"
#获取USB串口总线地址 #脚本目录
# $1:USB串口 SCRIPT_DIR="/usr/share/modem"
getUSBDeviceBusPath() source "${SCRIPT_DIR}/modem_debug.sh"
#获取设备物理地址
# $1:网络设备或串口
get_device_physical_path()
{ {
local device_name="$(basename "$1")" local device_name="$(basename "$1")"
local device_path="$(find /sys/class/ -name $device_name)" local device_path="$(find /sys/class/ -name $device_name)"
local device_physical_path="$(readlink -f $device_path/device/)" local device_physical_path="$(readlink -f $device_path/device/)"
echo "$device_physical_path"
}
#获取设备总线地址
# $1:网络设备
# $2:USB或者PCIE标志
get_device_bus_path()
{
local device_physical_path="$(get_device_physical_path $1)"
local device_bus_path="$device_physical_path"
if [ "$2" = "usb" ]; then
#USB设备路径需要再获取上一层
device_bus_path=$(dirname "$device_bus_path")
#判断路径是否带有usb排除其他eth网络设备
if [[ "$device_physical_path" = *"usb"* ]]; then
echo "$device_bus_path"
fi
elif [ "$2" = "pcie" ]; then
echo "$device_bus_path"
fi
}
#获取USB串口总线地址
# $1:USB串口
get_usb_device_bus_path()
{
local device_physical_path="$(get_device_physical_path $1)"
#获取父路径的上两层 #获取父路径的上两层
local tmp=$(dirname "$device_physical_path") local tmp=$(dirname "$device_physical_path")
local device_bus_path=$(dirname $tmp) local device_bus_path=$(dirname $tmp)
echo $device_bus_path echo "$device_bus_path"
} }
#获取设备总线地址 #获取PCIE串口总线地址
# $1:网络设备或PCIE串口 # $1:PCIE串口
getDeviceBusPath() get_pcie_device_bus_path()
{ {
local device_name="$(basename "$1")" local device_physical_path="$(get_device_physical_path $1)"
local device_path="$(find /sys/class/ -name $device_name)"
local device_physical_path="$(readlink -f $device_path/device/)"
local device_bus_path=$device_physical_path local device_bus_path="$device_physical_path"
if [ "$device_name" != "mhi_BHI" ]; then #未考虑多个mhi_BHI的情况 if [ "$device_name" != "mhi_BHI" ]; then #未考虑多个mhi_BHI的情况
device_bus_path=$(dirname "$device_physical_path") device_bus_path=$(dirname "$device_physical_path")
fi fi
echo $device_bus_path echo "$device_bus_path"
} }
#设置模块配置 #设置模配置
# $1:模块序号 # $1:模序号
# $2:设备数据接口 # $2:设备数据接口
# $3:总线地址 # $3:总线地址
setModemConfig() set_modem_config()
{ {
#判断地址是否为net #判断地址是否为net
local path=$(basename "$3") local path=$(basename "$3")
@ -74,11 +104,11 @@ setModemConfig()
modem_count=$((modem_count + 1)) modem_count=$((modem_count + 1))
} }
#设置模串口配置 #设置模串口配置
# $modem_count:模计数 # $modem_count:模计数
# $1:总线地址 # $1:总线地址
# $2:串口 # $2:串口
setPortConfig() set_port_config()
{ {
#处理获取到的地址 #处理获取到的地址
# local substr="${1/\/sys\/devices\//}" #x86平台替换掉/sys/devices/ # local substr="${1/\/sys\/devices\//}" #x86平台替换掉/sys/devices/
@ -87,21 +117,21 @@ setPortConfig()
local substr=$1 #路径存在不同,暂不处理 local substr=$1 #路径存在不同,暂不处理
for i in $(seq 0 $((modem_count-1))); do for i in $(seq 0 $((modem_count-1))); do
#当前模的物理地址 #当前模的物理地址
local path=$(uci -q get modem.modem$i.path) local path=$(uci -q get modem.modem$i.path)
if [ "$substr" = "$path" ]; then if [ "$substr" = "$path" ]; then
#添加新的串口 #添加新的串口
uci add_list modem.modem$i.ports="$2" uci add_list modem.modem${i}.ports="$2"
#写入到配置中解决老版本luci问题 #写入到配置中解决老版本luci问题
uci commit modem uci commit modem
#判断是不是AT串口 #判断是不是AT串口
local response=$(sh $current_dir/modem_at.sh $2 "ATI") local response="$(sh ${SCRIPT_DIR}/modem_at.sh $2 'ATI')"
local str1="No" #No response from modem. local str1="No" #No response from modem.
local str2="failed" local str2="failed"
if [[ "$response" != *"$str1"* ]] && [[ "$response" != *"$str2"* ]]; then if [[ "$response" != *"$str1"* ]] && [[ "$response" != *"$str2"* ]] && [ -n "$response" ]; then
#原先的AT串口会被覆盖掉是否需要加判断 #原先的AT串口会被覆盖掉是否需要加判断
uci set modem.modem$i.at_port="$2" uci set modem.modem${i}.at_port="$2"
setModemInfoConfig $i $2 set_modem_info_config "$i" "$2"
fi fi
break break
fi fi
@ -112,16 +142,16 @@ setPortConfig()
# $modem_count:模组计数 # $modem_count:模组计数
# $1:模组序号 # $1:模组序号
# $2:AT串口 # $2:AT串口
setModemInfoConfig() set_modem_info_config()
{ {
#获取数据接口 #获取数据接口
local data_interface=$(uci -q get modem.modem$1.data_interface) local data_interface=$(uci -q get modem.modem$1.data_interface)
#获取支持的模组 #获取支持的模组
local modem_support=$(cat $current_dir/modem_support.json) local modem_support=$(cat ${SCRIPT_DIR}/modem_support.json)
#获取模组名 #获取模组名
local at_response=$(sh $current_dir/modem_at.sh $2 "AT+CGMM" | sed -n '2p' | sed 's/\r//g' | tr 'A-Z' 'a-z') local at_response=$(sh ${SCRIPT_DIR}/modem_at.sh $2 "AT+CGMM" | sed -n '2p' | sed 's/\r//g' | tr 'A-Z' 'a-z')
#获取模组信息 #获取模组信息
local modem_info=$(echo $modem_support | jq '.modem_support.'$data_interface'."'$at_response'"') local modem_info=$(echo $modem_support | jq '.modem_support.'$data_interface'."'$at_response'"')
@ -145,7 +175,7 @@ setModemInfoConfig()
#获取平台 #获取平台
platform=$(echo $modem_info | jq -r '.platform') platform=$(echo $modem_info | jq -r '.platform')
#获取当前的拨号模式 #获取当前的拨号模式
mode=$(source $current_dir/$manufacturer.sh && "$manufacturer"_get_mode $2 $platform) mode=$(source ${SCRIPT_DIR}/$manufacturer.sh && "$manufacturer"_get_mode $2 $platform)
#获取支持的拨号模式 #获取支持的拨号模式
modes=$(echo $modem_info | jq -r '.modes[]') modes=$(echo $modem_info | jq -r '.modes[]')
fi fi
@ -165,55 +195,74 @@ setModemInfoConfig()
done done
} }
#设置模数量 #设置模数量
setModemCount() set_modem_count()
{ {
uci set modem.global.modem_number="$modem_count" uci set modem.@global[0].modem_number="$modem_count"
#数量为0时清空模列表 #数量为0时清空模列表
if [ "$modem_count" = "0" ]; then if [ "$modem_count" = "0" ]; then
for i in $(seq 0 $((modem_count-1))); do for i in $(seq 0 $((modem_count-1))); do
uci -q del modem.modem$i uci -q del modem.modem${i}
done done
fi fi
} }
#模块计数 #设置USB模组基本信息
# $1:USB网络设备
set_usb_modem_config()
{
for network in $usb_network; do
local usb_device_bus_path=$(get_device_bus_path $network "usb")
if [ -z "$usb_device_bus_path" ]; then
continue
else
set_modem_config $modem_count "usb" $usb_device_bus_path
fi
done
}
#设置PCIE模组基本信息
# $1:PCIE网络设备
set_pcie_modem_config()
{
for network in $pcie_network; do
local pcie_device_bus_path=$(get_device_bus_path $network "pcie")
if [ -z "$pcie_device_bus_path" ]; then
continue
else
set_modem_config $modem_count "pcie" $pcie_device_bus_path
fi
done
}
#模组计数
modem_count=0 modem_count=0
#模块支持文件 #模支持文件
modem_support_file="$current_dir/modem_support" modem_support_file="${SCRIPT_DIR}/modem_support"
#设置模块信息 #设置模信息
modem_scan() modem_scan()
{ {
#初始化 #初始化
modem_count=0 modem_count=0
########设置模块基本信息######## ########设置模基本信息########
#USB #USB
local usb_network local usb_network
usb_network=$(find /sys/class/net -name usb*) usb_network="$(find /sys/class/net -name usb*)" #ECM RNDIS NCM
for network in $usb_network; do set_usb_modem_config "$usb_network"
local usb_device_bus_path=$(getDeviceBusPath $network) usb_network="$(find /sys/class/net -name wwan*)" #QMI MBIM
setModemConfig $modem_count "usb" $usb_device_bus_path set_usb_modem_config "$usb_network"
done usb_network="$(find /sys/class/net -name eth*)" #RNDIS
usb_network=$(find /sys/class/net -name wwan*) set_usb_modem_config "$usb_network"
for network in $usb_network; do
local usb_device_bus_path=$(getDeviceBusPath $network)
setModemConfig $modem_count "usb" $usb_device_bus_path
done
#PCIE #PCIE
local pcie_network local pcie_network
pcie_network=$(find /sys/class/net -name mhi_hwip*) #通用mhi驱动 pcie_network="$(find /sys/class/net -name mhi_hwip*)" #通用mhi驱动
for network in $pcie_network; do set_pcie_modem_config "$pcie_network"
local pcie_device_bus_path=$(getDeviceBusPath $network) pcie_network="$(find /sys/class/net -name rmnet_mhi*)" #制造商mhi驱动
setModemConfig $modem_count "pcie" $pcie_device_bus_path set_pcie_modem_config "$pcie_network"
done
pcie_network=$(find /sys/class/net -name rmnet_mhi*) #制造商mhi驱动
for network in $pcie_network; do
local pcie_device_bus_path=$(getDeviceBusPath $network)
setModemConfig $modem_count "pcie" $pcie_device_bus_path
done
########设置模串口######## ########设置模组串口########
#清除原串口配置 #清除原串口配置
for i in $(seq 0 $((modem_count-1))); do for i in $(seq 0 $((modem_count-1))); do
uci -q del modem.modem$i.ports uci -q del modem.modem$i.ports
@ -221,23 +270,23 @@ modem_scan()
#USB串口 #USB串口
local usb_port=$(find /dev -name ttyUSB*) local usb_port=$(find /dev -name ttyUSB*)
for port in $usb_port; do for port in $usb_port; do
local usb_port_device_bus_path=$(getUSBDeviceBusPath $port) local usb_port_device_bus_path="$(get_usb_device_bus_path $port)"
setPortConfig $usb_port_device_bus_path $port set_port_config $usb_port_device_bus_path $port
done done
#PCIE串口 #PCIE串口
local pcie_port local pcie_port
pcie_port=$(find /dev -name wwan*) pcie_port=$(find /dev -name wwan*)
for port in $pcie_port; do for port in $pcie_port; do
local pcie_port_device_bus_path=$(getDeviceBusPath $port) local pcie_port_device_bus_path="$(get_pcie_device_bus_path $port)"
setPortConfig $pcie_port_device_bus_path $port set_port_config $pcie_port_device_bus_path $port
done done
pcie_port=$(find /dev -name mhi*) pcie_port=$(find /dev -name mhi*)
for port in $pcie_port; do for port in $pcie_port; do
local pcie_port_device_bus_path=$(getDeviceBusPath $port) local pcie_port_device_bus_path="$(get_pcie_device_bus_path $port)"
setPortConfig $pcie_port_device_bus_path $port set_port_config $pcie_port_device_bus_path $port
done done
########设置模数量######## ########设置模数量########
setModemCount set_modem_count
#写入到配置中 #写入到配置中
uci commit modem uci commit modem

View File

@ -2,69 +2,91 @@
"modem_support":{ "modem_support":{
"usb":{ "usb":{
"rg200u-cn":{ "rg200u-cn":{
"manufacturer_id":"2c7c",
"manufacturer":"quectel", "manufacturer":"quectel",
"platform":"unisoc", "platform":"unisoc",
"network_interface":"usb", "network_interface":"usb",
"define_connect":"1",
"modes":["ecm","mbim","rndis","ncm"] "modes":["ecm","mbim","rndis","ncm"]
}, },
"rm500u-cn":{ "rm500u-cn":{
"manufacturer_id":"2c7c",
"manufacturer":"quectel", "manufacturer":"quectel",
"platform":"unisoc", "platform":"unisoc",
"network_interface":"usb", "network_interface":"usb",
"define_connect":"1",
"modes":["ecm","mbim","rndis","ncm"] "modes":["ecm","mbim","rndis","ncm"]
}, },
"rm500q-gl":{ "rm500q-gl":{
"manufacturer_id":"2c7c",
"manufacturer":"quectel", "manufacturer":"quectel",
"platform":"qualcomm", "platform":"qualcomm",
"network_interface":"usb", "network_interface":"usb",
"define_connect":"1",
"modes":["qmi","gobinet","ecm","mbim","rndis","ncm"] "modes":["qmi","gobinet","ecm","mbim","rndis","ncm"]
}, },
"rm502q-gl":{ "rm502q-gl":{
"manufacturer_id":"2c7c",
"manufacturer":"quectel", "manufacturer":"quectel",
"platform":"qualcomm", "platform":"qualcomm",
"network_interface":"usb", "network_interface":"usb",
"define_connect":"1",
"modes":["qmi","gobinet","ecm","mbim","rndis","ncm"] "modes":["qmi","gobinet","ecm","mbim","rndis","ncm"]
}, },
"rm502q-ae":{ "rm502q-ae":{
"manufacturer_id":"2c7c",
"manufacturer":"quectel", "manufacturer":"quectel",
"platform":"qualcomm", "platform":"qualcomm",
"network_interface":"usb", "network_interface":"usb",
"define_connect":"1",
"modes":["qmi","gobinet","ecm","mbim","rndis","ncm"] "modes":["qmi","gobinet","ecm","mbim","rndis","ncm"]
}, },
"rm520n-cn":{ "rm520n-cn":{
"manufacturer_id":"2c7c",
"manufacturer":"quectel", "manufacturer":"quectel",
"platform":"qualcomm", "platform":"qualcomm",
"network_interface":"usb", "network_interface":"usb",
"define_connect":"1",
"modes":["qmi","gobinet","ecm","mbim","rndis","ncm"] "modes":["qmi","gobinet","ecm","mbim","rndis","ncm"]
}, },
"rm520n-gl":{ "rm520n-gl":{
"manufacturer_id":"2c7c",
"manufacturer":"quectel", "manufacturer":"quectel",
"platform":"qualcomm", "platform":"qualcomm",
"network_interface":"usb", "network_interface":"usb",
"define_connect":"1",
"modes":["qmi","gobinet","ecm","mbim","rndis","ncm"] "modes":["qmi","gobinet","ecm","mbim","rndis","ncm"]
}, },
"fm650-cn":{ "fm650-cn":{
"manufacturer_id":"2cb7",
"manufacturer":"fibocom", "manufacturer":"fibocom",
"platform":"unisoc", "platform":"unisoc",
"network_interface":"usb", "network_interface":"usb",
"define_connect":"1",
"modes":["ecm","mbim","rndis","ncm"] "modes":["ecm","mbim","rndis","ncm"]
}, },
"fm350-gl":{ "fm350-gl":{
"manufacturer_id":"0e8d",
"manufacturer":"fibocom", "manufacturer":"fibocom",
"platform":"mediatek", "platform":"mediatek",
"network_interface":"usb", "network_interface":"usb",
"define_connect":"3",
"modes":["rndis"] "modes":["rndis"]
}, },
"fm150-ae":{ "fm150-ae":{
"manufacturer_id":"2cb7",
"manufacturer":"fibocom", "manufacturer":"fibocom",
"platform":"qualcomm", "platform":"qualcomm",
"network_interface":"usb", "network_interface":"usb",
"define_connect":"1",
"modes":["qmi","gobinet","ecm","mbim","rndis","ncm"] "modes":["qmi","gobinet","ecm","mbim","rndis","ncm"]
}, },
"fm160-cn":{ "fm160-cn":{
"manufacturer_id":"2cb7",
"manufacturer":"fibocom", "manufacturer":"fibocom",
"platform":"qualcomm", "platform":"qualcomm",
"network_interface":"usb", "network_interface":"usb",
"define_connect":"1",
"modes":["qmi","gobinet","ecm","mbim","rndis","ncm"] "modes":["qmi","gobinet","ecm","mbim","rndis","ncm"]
} }
}, },
@ -73,25 +95,29 @@
"manufacturer":"quectel", "manufacturer":"quectel",
"platform":"qualcomm", "platform":"qualcomm",
"network_interface":"pcie", "network_interface":"pcie",
"define_connect":"1",
"modes":["qmi","gobinet","mbim"] "modes":["qmi","gobinet","mbim"]
}, },
"rm502q-gl":{ "rm502q-gl":{
"manufacturer":"fibocom", "manufacturer":"fibocom",
"platform":"qualcomm", "platform":"qualcomm",
"network_interface":"pcie", "network_interface":"pcie",
"define_connect":"1",
"modes":["qmi","gobinet","mbim"] "modes":["qmi","gobinet","mbim"]
}, },
"fm350-gl":{ "fm350-gl":{
"manufacturer":"fibocom", "manufacturer":"fibocom",
"platform":"mediatek", "platform":"mediatek",
"network_interface":"pcie", "network_interface":"pcie",
"define_connect":"1",
"modes":["mbim"] "modes":["mbim"]
}, },
"fm150-ae":{ "fm150-ae":{
"manufacturer":"fibocom", "manufacturer":"fibocom",
"platform":"qualcomm", "platform":"qualcomm",
"network_interface":"pcie", "network_interface":"pcie",
"modes":["qmi"] "define_connect":"1",
"modes":["qmi","mbim"]
} }
} }
} }

View File

@ -1,7 +1,10 @@
#!/bin/sh #!/bin/sh
current_dir="$(dirname "$0")" # Copyright (C) 2023 Siriling <siriling@qq.com>
source "$current_dir/modem_debug.sh"
source "$current_dir/modem_scan.sh" #脚本目录
SCRIPT_DIR="/usr/share/modem"
source "${SCRIPT_DIR}/modem_debug.sh"
source "${SCRIPT_DIR}/modem_scan.sh"
#模组扫描任务 #模组扫描任务
modem_scan_task() modem_scan_task()

View File

@ -0,0 +1,845 @@
#!/bin/sh
# Copyright (C) 2023 Siriling <siriling@qq.com>
#脚本目录
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()
{
local level="$1";
logger -p "daemon.${level}" -t "Modem[$$]" "hotplug: $*"
}
#上报USB事件
# $1:事件行为addremovebind
# $2:类型
# $3:名称或设备ID
# $4:路径
m_report_event()
{
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:网络设备路径
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 $3 }' "${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:事件行为addremovebind
# $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
#添加ID
echo "${manufacturer_id} ${product_id}" >> "${new_id_path}"
}
#设置模组硬件配置
# $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
# }
#判断路径是否带有usb排除其他eth网络设备
if [ "$data_interface" != "pcie" ] && [[ "$device_physical_path" != *"usb"* ]]; then
return
fi
#获取模组序号
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
#设置物理路径状态
m_set_physical_path_status "${physical_path}" "processed"
}
#删除模组配置
# $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}"
#打印日志
m_log "info" "Modem${modem_no} (${physical_path}) removed"
}
#设置USB设备
# $1:事件行为addremovebind
# $2:制造商ID
# $3:产品ID
# $4:物理路径
m_set_usb_device()
{
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
#删除模组配置
m_del_modem_config "${physical_path}"
fi
}
#重新尝试设置模组
# $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} | sed -n '2p' | sed 's/\r//g' | tr 'A-Z' 'a-z')
}
[ -n "$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'"')
#获取制造商
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 -q del modem.modem${modem_no}.modes #删除原来的拨号模式列表
for mode in $modes; do
uci add_list modem.modem${modem_no}.modes="${mode}"
done
#PDP设置
at_command="AT+CGDCONT=$define_connect,\"IPV4V6\",\"\""
at "${at_port}" "${at_command}"
#打印日志
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 at_command="AT+CGMM?"
local modem_name=$(at ${at_port} ${at_command} | grep "+CGMM: " | awk -F'"' '{print $2}' | tr 'A-Z' 'a-z')
#获取模组支持列表
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"
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"
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}"
for mode in $modes; do
uci add_list modem.modem${modem_no}.modes="${mode}"
done
#PDP设置
at_command="AT+CGDCONT=$define_connect,\"IPV4V6\",\"\""
at "${at_port}" "${at_command}"
#打印日志
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()
{
local modem_no="$1"
local port="$2"
local physical_path="$3"
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}"
#设置模组配置
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:事件行为addremovebind
# $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:事件行为addremovebind
# $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()
{
local network="$1"
local i=0
while true; do
#查看该网络设备的配置是否启用
local modem_network=$(uci -q get modem.@config[${i}].network)
[ -z "$modem_network" ] && break
if [ "$network" = "$modem_network" ]; then
local enable=$(uci -q get modem.@config[${i}].enable)
if [ "$enable" = "1" ]; then
service modem reload
break
fi
fi
i=$((i+1))
done
}
#禁用拨号
# $1:网络设备
disable_dial()
{
local network="$1"
local i=0
while true; do
#查看该网络设备的配置是否启用
local modem_network=$(uci -q get modem.@config[${i}].network)
[ -z "$modem_network" ] && break
if [ "$network" = "$modem_network" ]; then
local enable=$(uci -q get modem.@config[${i}].enable)
if [ "$enable" = "1" ]; then
uci set modem.@config[${i}].enable=0
uci commit modem
service modem reload
break
fi
fi
i=$((i+1))
done
}
#设置PCIE设备串口
# $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*)
else
all_port=$(find ${physical_path} -name mhi_*)
fi
fi
#不存在串口,返回
[ -z "${all_port}" ] && return
#设置串口
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
#跳过重复的串口
[[ "$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:事件行为addremovebind
# $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}"
fi
}
#设置网络设备
# $1:事件行为addremovebind
# $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
#上报事件
m_report_event "${action}" "net" "${network}" "${network_path}"
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
}

View File

@ -1,5 +1,15 @@
#!/bin/sh #!/bin/sh
current_dir="$(dirname "$0")" # Copyright (C) 2023 Siriling <siriling@qq.com>
#脚本目录
SCRIPT_DIR="/usr/share/modem"
#预设
quectel_presets()
{
at_command='ATI'
# sh "${SCRIPT_DIR}/modem_at.sh" "$at_port" "$at_command"
}
#获取拨号模式 #获取拨号模式
# $1:AT串口 # $1:AT串口
@ -7,17 +17,18 @@ current_dir="$(dirname "$0")"
quectel_get_mode() quectel_get_mode()
{ {
local at_port="$1" local at_port="$1"
local platform="$2"
at_command='AT+QCFG="usbnet"' at_command='AT+QCFG="usbnet"'
local mode_num=$(sh $current_dir/modem_at.sh $at_port $at_command | grep "+QCFG:" | sed 's/+QCFG: "usbnet",//g' | sed 's/\r//g') local mode_num=$(sh ${SCRIPT_DIR}/modem_at.sh $at_port $at_command | grep "+QCFG:" | sed 's/+QCFG: "usbnet",//g' | sed 's/\r//g')
#获取芯片平台 #获取芯片平台
local platform="$2"
if [ -z "$platform" ]; then if [ -z "$platform" ]; then
local modem_number=$(uci -q get modem.global.modem_number) local modem_number=$(uci -q get modem.@global[0].modem_number)
for i in $(seq 0 $((modem_number-1))); do for i in $(seq 0 $((modem_number-1))); do
local at_port_tmp=$(uci -q get modem.modem$i.at_port) local at_port_tmp=$(uci -q get modem.modem${i}.at_port)
if [ "$at_port" = "$at_port_tmp" ]; then if [ "$at_port" = "$at_port_tmp" ]; then
platform=$(uci -q get modem.modem$i.platform) platform=$(uci -q get modem.modem${i}.platform)
break break
fi fi
done done
@ -33,7 +44,7 @@ quectel_get_mode()
"2") mode="mbim" ;; "2") mode="mbim" ;;
"3") mode="rndis" ;; "3") mode="rndis" ;;
"5") mode="ncm" ;; "5") mode="ncm" ;;
*) mode="$mode_num" ;; *) mode="${mode_num}" ;;
esac esac
;; ;;
"unisoc") "unisoc")
@ -42,14 +53,14 @@ quectel_get_mode()
"2") mode="mbim" ;; "2") mode="mbim" ;;
"3") mode="rndis" ;; "3") mode="rndis" ;;
"5") mode="ncm" ;; "5") mode="ncm" ;;
*) mode="$mode_num" ;; *) mode="${mode_num}" ;;
esac esac
;; ;;
*) *)
mode="$mode_num" mode="${mode_num}"
;; ;;
esac esac
echo "$mode" echo "${mode}"
} }
#设置拨号模式 #设置拨号模式
@ -61,7 +72,7 @@ quectel_set_mode()
#获取芯片平台 #获取芯片平台
local platform local platform
local modem_number=$(uci -q get modem.global.modem_number) local modem_number=$(uci -q get modem.@global[0].modem_number)
for i in $(seq 0 $((modem_number-1))); do for i in $(seq 0 $((modem_number-1))); do
local at_port_tmp=$(uci -q get modem.modem$i.at_port) local at_port_tmp=$(uci -q get modem.modem$i.at_port)
if [ "$at_port" = "$at_port_tmp" ]; then if [ "$at_port" = "$at_port_tmp" ]; then
@ -99,8 +110,8 @@ quectel_set_mode()
esac esac
#设置模组 #设置模组
at_command='AT+QCFG="usbnet",'$mode_num at_command='AT+QCFG="usbnet",'${mode_num}
sh $current_dir/modem_at.sh $at_port "$at_command" sh ${SCRIPT_DIR}/modem_at.sh "${at_port}" "${at_command}"
} }
#获取网络偏好 #获取网络偏好
@ -109,7 +120,7 @@ quectel_get_network_prefer()
{ {
local at_port="$1" local at_port="$1"
at_command='AT+QNWPREFCFG="mode_pref"' at_command='AT+QNWPREFCFG="mode_pref"'
local response=$(sh $current_dir/modem_at.sh $at_port $at_command | grep "+QNWPREFCFG:" | awk -F',' '{print $2}' | sed 's/\r//g') local response=$(sh ${SCRIPT_DIR}/modem_at.sh ${at_port} ${at_command} | grep "+QNWPREFCFG:" | awk -F',' '{print $2}' | sed 's/\r//g')
local network_prefer_3g="0"; local network_prefer_3g="0";
local network_prefer_4g="0"; local network_prefer_4g="0";
@ -188,28 +199,61 @@ quectel_set_network_prefer()
#设置模组 #设置模组
local at_port="$1" local at_port="$1"
at_command='AT+QNWPREFCFG="mode_pref",'$network_prefer_config at_command='AT+QNWPREFCFG="mode_pref",'${network_prefer_config}
sh $current_dir/modem_at.sh $at_port "$at_command" sh ${SCRIPT_DIR}/modem_at.sh "${at_port}" "${at_command}"
}
#获取自检信息
# $1:AT串口
quectel_get_self_test_info()
{
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}"
} }
#获取连接状态 #获取连接状态
# $1:AT串口 # $1:AT串口
# $2:连接定义
quectel_get_connect_status() quectel_get_connect_status()
{ {
local at_port="$1" local at_port="$1"
at_command="AT+QNWINFO" local define_connect="$2"
local response=$(sh $current_dir/modem_at.sh $at_port $at_command | grep "+QNWINFO:") #默认值为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 local connect_status
if [[ "$response" = *"No Service"* ]]; then if [ -z "$ipv4" ] || [[ "$ipv4" = *"$not_ip"* ]]; then
connect_status="disconnect"
elif [[ "$response" = *"Unknown Service"* ]]; then
connect_status="disconnect" connect_status="disconnect"
else else
connect_status="connect" connect_status="connect"
fi 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" echo "$connect_status"
} }
@ -220,26 +264,26 @@ quectel_base_info()
#Name名称 #Name名称
at_command="AT+CGMM" at_command="AT+CGMM"
name=$(sh $current_dir/modem_at.sh $at_port $at_command | sed -n '2p' | sed 's/\r//g') name=$(sh ${SCRIPT_DIR}/modem_at.sh $at_port $at_command | sed -n '2p' | sed 's/\r//g')
#Manufacturer制造商 #Manufacturer制造商
at_command="AT+CGMI" at_command="AT+CGMI"
manufacturer=$(sh $current_dir/modem_at.sh $at_port $at_command | sed -n '2p' | sed 's/\r//g') manufacturer=$(sh ${SCRIPT_DIR}/modem_at.sh $at_port $at_command | sed -n '2p' | sed 's/\r//g')
#Revision固件版本 #Revision固件版本
at_command="ATI" at_command="ATI"
revision=$(sh $current_dir/modem_at.sh $at_port $at_command | grep "Revision:" | sed 's/Revision: //g' | sed 's/\r//g') revision=$(sh ${SCRIPT_DIR}/modem_at.sh $at_port $at_command | grep "Revision:" | sed 's/Revision: //g' | sed 's/\r//g')
# at_command="AT+CGMR" # at_command="AT+CGMR"
# revision=$(sh $current_dir/modem_at.sh $at_port $at_command | sed -n '2p' | sed 's/\r//g') # revision=$(sh ${SCRIPT_DIR}/modem_at.sh $at_port $at_command | sed -n '2p' | sed 's/\r//g')
#Mode拨号模式 #Mode拨号模式
mode=$(quectel_get_mode $at_port | tr 'a-z' 'A-Z') mode=$(quectel_get_mode $at_port | tr 'a-z' 'A-Z')
#Temperature温度 #Temperature温度
at_command="AT+QTEMP" at_command="AT+QTEMP"
response=$(sh $current_dir/modem_at.sh $at_port $at_command | sed -n '2p' | awk -F'"' '{print $4}') response=$(sh ${SCRIPT_DIR}/modem_at.sh $at_port $at_command | sed -n '2p' | awk -F'"' '{print $4}')
if [ -n "$response" ]; then if [ -n "$response" ]; then
temperature="$response$(printf "\xc2\xb0")C" temperature="$response$(printf "\xc2\xb0")C"
fi fi
# response=$(sh $current_dir/modem_at.sh $at_port $at_command | grep "+QTEMP:") # response=$(sh ${SCRIPT_DIR}/modem_at.sh $at_port $at_command | grep "+QTEMP:")
# QTEMP=$(echo $response | grep -o -i "+QTEMP: [0-9]\{1,3\}") # QTEMP=$(echo $response | grep -o -i "+QTEMP: [0-9]\{1,3\}")
# if [ -z "$QTEMP" ]; then # if [ -z "$QTEMP" ]; then
# QTEMP=$(echo $response | grep -o -i "+QTEMP:[ ]\?\"XO[_-]THERM[_-][^,]\+,[\"]\?[0-9]\{1,3\}" | grep -o "[0-9]\{1,3\}") # QTEMP=$(echo $response | grep -o -i "+QTEMP:[ ]\?\"XO[_-]THERM[_-][^,]\+,[\"]\?[0-9]\{1,3\}" | grep -o "[0-9]\{1,3\}")
@ -290,15 +334,15 @@ quectel_sim_info()
#SIM SlotSIM卡卡槽 #SIM SlotSIM卡卡槽
at_command="AT+QUIMSLOT?" at_command="AT+QUIMSLOT?"
sim_slot=$(sh $current_dir/modem_at.sh $at_port $at_command | grep "+QUIMSLOT:" | awk -F' ' '{print $2}' | sed 's/\r//g') sim_slot=$(sh ${SCRIPT_DIR}/modem_at.sh $at_port $at_command | grep "+QUIMSLOT:" | awk -F' ' '{print $2}' | sed 's/\r//g')
#IMEI国际移动设备识别码 #IMEI国际移动设备识别码
at_command="AT+CGSN" at_command="AT+CGSN"
imei=$(sh $current_dir/modem_at.sh $at_port $at_command | sed -n '2p' | sed 's/\r//g') imei=$(sh ${SCRIPT_DIR}/modem_at.sh $at_port $at_command | sed -n '2p' | sed 's/\r//g')
#SIM StatusSIM状态 #SIM StatusSIM状态
at_command="AT+CPIN?" at_command="AT+CPIN?"
sim_status_flag=$(sh $current_dir/modem_at.sh $at_port $at_command | sed -n '2p') 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=$(quectel_get_sim_status "$sim_status_flag")
if [ "$sim_status" != "ready" ]; then if [ "$sim_status" != "ready" ]; then
@ -307,7 +351,7 @@ quectel_sim_info()
#ISP互联网服务提供商 #ISP互联网服务提供商
at_command="AT+COPS?" at_command="AT+COPS?"
isp=$(sh $current_dir/modem_at.sh $at_port $at_command | sed -n '2p' | awk -F'"' '{print $2}') isp=$(sh ${SCRIPT_DIR}/modem_at.sh $at_port $at_command | sed -n '2p' | awk -F'"' '{print $2}')
# if [ "$isp" = "CHN-CMCC" ] || [ "$isp" = "CMCC" ]|| [ "$isp" = "46000" ]; then # if [ "$isp" = "CHN-CMCC" ] || [ "$isp" = "CMCC" ]|| [ "$isp" = "46000" ]; then
# isp="中国移动" # isp="中国移动"
# # elif [ "$isp" = "CHN-UNICOM" ] || [ "$isp" = "UNICOM" ] || [ "$isp" = "46001" ]; then # # elif [ "$isp" = "CHN-UNICOM" ] || [ "$isp" = "UNICOM" ] || [ "$isp" = "46001" ]; then
@ -320,15 +364,15 @@ quectel_sim_info()
#SIM NumberSIM卡号码手机号 #SIM NumberSIM卡号码手机号
at_command="AT+CNUM" at_command="AT+CNUM"
sim_number=$(sh $current_dir/modem_at.sh $at_port $at_command | sed -n '2p' | awk -F'"' '{print $4}') sim_number=$(sh ${SCRIPT_DIR}/modem_at.sh $at_port $at_command | sed -n '2p' | awk -F'"' '{print $4}')
#IMSI国际移动用户识别码 #IMSI国际移动用户识别码
at_command="AT+CIMI" at_command="AT+CIMI"
imsi=$(sh $current_dir/modem_at.sh $at_port $at_command | sed -n '2p' | sed 's/\r//g') imsi=$(sh ${SCRIPT_DIR}/modem_at.sh $at_port $at_command | sed -n '2p' | sed 's/\r//g')
#ICCID集成电路卡识别码 #ICCID集成电路卡识别码
at_command="AT+ICCID" at_command="AT+ICCID"
# iccid=$(sh $current_dir/modem_at.sh $at_port $at_command | grep -o "+ICCID:[ ]*[-0-9]\+" | grep -o "[-0-9]\{1,4\}") # iccid=$(sh ${SCRIPT_DIR}/modem_at.sh $at_port $at_command | grep -o "+ICCID:[ ]*[-0-9]\+" | grep -o "[-0-9]\{1,4\}")
} }
#获取信号强度指示 #获取信号强度指示
@ -349,7 +393,7 @@ quectel_network_info()
debug "Quectel network info" debug "Quectel network info"
#Connect Status连接状态 #Connect Status连接状态
connect_status=$(quectel_get_connect_status $at_port) connect_status=$(quectel_get_connect_status ${at_port} ${define_connect})
if [ "$connect_status" != "connect" ]; then if [ "$connect_status" != "connect" ]; then
return return
fi fi
@ -357,11 +401,11 @@ quectel_network_info()
#Network Type网络类型 #Network Type网络类型
# at_command="AT+COPS?" # at_command="AT+COPS?"
at_command="AT+QNWINFO" at_command="AT+QNWINFO"
network_type=$(sh $current_dir/modem_at.sh $at_port $at_command | grep "+QNWINFO:" | awk -F'"' '{print $2}') network_type=$(sh ${SCRIPT_DIR}/modem_at.sh ${at_port} ${at_command} | grep "+QNWINFO:" | awk -F'"' '{print $2}')
#CSQ信号强度 #CSQ信号强度
at_command="AT+CSQ" at_command="AT+CSQ"
response=$(sh $current_dir/modem_at.sh $at_port $at_command | grep "+CSQ:" | sed 's/+CSQ: //g' | sed 's/\r//g') response=$(sh ${SCRIPT_DIR}/modem_at.sh ${at_port} ${at_command} | grep "+CSQ:" | sed 's/+CSQ: //g' | sed 's/\r//g')
#RSSI信号强度指示 #RSSI信号强度指示
# rssi_num=$(echo $response | awk -F',' '{print $1}') # rssi_num=$(echo $response | awk -F',' '{print $1}')
@ -376,7 +420,7 @@ quectel_network_info()
#速率统计 #速率统计
at_command='AT+QNWCFG="up/down"' at_command='AT+QNWCFG="up/down"'
response=$(sh $current_dir/modem_at.sh $at_port $at_command | grep "+QNWCFG:" | sed 's/+QNWCFG: "up/down",//g' | sed 's/\r//g') response=$(sh ${SCRIPT_DIR}/modem_at.sh $at_port $at_command | grep "+QNWCFG:" | sed 's/+QNWCFG: "up\/down",//g' | sed 's/\r//g')
#当前上传速率单位Byte/s #当前上传速率单位Byte/s
tx_rate=$(echo $response | awk -F',' '{print $1}') tx_rate=$(echo $response | awk -F',' '{print $1}')
@ -497,7 +541,7 @@ quectel_cell_info()
debug "Quectel cell info" debug "Quectel cell info"
at_command='AT+QENG="servingcell"' at_command='AT+QENG="servingcell"'
response=$(sh $current_dir/modem_at.sh $at_port $at_command) response=$(sh ${SCRIPT_DIR}/modem_at.sh $at_port $at_command)
local lte=$(echo "$response" | grep "+QENG: \"LTE\"") local lte=$(echo "$response" | grep "+QENG: \"LTE\"")
local nr5g_nsa=$(echo "$response" | grep "+QENG: \"NR5G-NSA\"") local nr5g_nsa=$(echo "$response" | grep "+QENG: \"NR5G-NSA\"")
@ -919,7 +963,8 @@ get_quectel_info()
{ {
debug "get quectel info" debug "get quectel info"
#设置AT串口 #设置AT串口
at_port=$1 at_port="$1"
define_connect="$2"
#基本信息 #基本信息
quectel_base_info quectel_base_info

View File

@ -6,6 +6,7 @@
{"查询网络信号质量5G > AT+CESQ":"AT+CESQ"}, {"查询网络信号质量5G > AT+CESQ":"AT+CESQ"},
{"查询网络信息 > AT+COPS?":"AT+COPS?"}, {"查询网络信息 > AT+COPS?":"AT+COPS?"},
{"查询PDP信息 > AT+CGDCONT?":"AT+CGDCONT?"}, {"查询PDP信息 > AT+CGDCONT?":"AT+CGDCONT?"},
{"查询PDP地址 > AT+CGPADDR":"AT+CGPADDR"},
{"最小功能模式 > AT+CFUN=0":"AT+CFUN=0"}, {"最小功能模式 > AT+CFUN=0":"AT+CFUN=0"},
{"全功能模式 > AT+CFUN=1":"AT+CFUN=1"}, {"全功能模式 > AT+CFUN=1":"AT+CFUN=1"},
{"SIM卡状态上报 > AT+QSIMSTAT?":"AT+QSIMSTAT?"}, {"SIM卡状态上报 > AT+QSIMSTAT?":"AT+QSIMSTAT?"},

View File

@ -1,4 +1,8 @@
#!/bin/sh #!/bin/sh
# Copyright (C) 2023 Siriling <siriling@qq.com>
#脚本目录
SCRIPT_DIR="/usr/share/modem"
#查询信息强度 #查询信息强度
All_CSQ() All_CSQ()