This commit is contained in:
siriling 2024-10-30 18:42:15 +08:00
parent dac4d1c7af
commit c97f9492e6
17 changed files with 1970 additions and 234 deletions

View File

@ -11,22 +11,11 @@ PKG_LICENSE:=GPLv3
PKG_LINCESE_FILES:=LICENSE
PKF_MAINTAINER:=Siriling <siriling@qq.com>
LUCI_DEPENDS:=+luci-compat \
+kmod-usb2 +kmod-usb3 \
+kmod-usb-net-sierrawireless +kmod-usb-ohci \
+kmod-usb-serial-option +kmod-usb-serial +kmod-usb-serial-qualcomm \
+kmod-usb-net +kmod-usb-acm \
+kmod-usb-wdm +kmod-usb-net-qmi-wwan \
+kmod-usb-net-cdc-ether \
+kmod-usb-net-cdc-mbim \
+kmod-usb-net-rndis \
+kmod-usb-net-cdc-ncm +kmod-usb-net-huawei-cdc-ncm \
+usbutils \
+pciutils \
+quectel-CM-5G \
+modemmanager \
+luci-proto-modemmanager \
+sms-tool \
+jq
+bc +jq
define Package/luci-app-modem/conffiles
/etc/config/modem

View File

@ -26,6 +26,7 @@
| 厂家名称 | 模组名称 | 平台 | 数据传输模式 | 端口模式 |
| -------- | -------------------------------------------------- | -------- | ------------ | ---------------------------- |
| 华为 | MH5000-31 | 华为 | USB | ECMNCM |
| 移远通信 | RG200U-CNDONGLE版 | 紫光展锐 | USB | ECMMBIMRNDISNCM |
| 移远通信 | RM500U-CN | 紫光展锐 | USB | ECMMBIMRNDISNCM |
| 移远通信 | RM500U-EA | 紫光展锐 | USB | ECMMBIMRNDISNCM |

View File

@ -34,6 +34,7 @@ function index()
entry({"admin", "network", "modem", "set_mode"}, call("setMode"), nil).leaf = true
entry({"admin", "network", "modem", "get_network_prefer_info"}, call("getNetworkPreferInfo"), nil).leaf = true
entry({"admin", "network", "modem", "set_network_prefer"}, call("setNetworkPrefer"), nil).leaf = true
entry({"admin", "network", "modem", "set_band_prefer"}, call("setBandPrefer"), nil).leaf = true
entry({"admin", "network", "modem", "get_self_test_info"}, call("getSelfTestInfo"), nil).leaf = true
entry({"admin", "network", "modem", "get_quick_commands"}, call("getQuickCommands"), nil).leaf = true
entry({"admin", "network", "modem", "send_at_command"}, call("sendATCommand"), nil).leaf = true
@ -587,14 +588,24 @@ end
function getNetworkPreferInfo()
local at_port = http.formvalue("port")
--获取制造商
local manufacturer=getManufacturer(at_port)
--获取制造商,数据接口,模组名称
local manufacturer
local data_interface
local name
uci:foreach("modem", "modem-device", function (modem_device)
if at_port == modem_device["at_port"] then
manufacturer=modem_device["manufacturer"]
data_interface=modem_device["data_interface"]
name=modem_device["name"]
return true --跳出循环
end
end)
--获取值
local network_prefer_info
if manufacturer~="unknown" then
--获取模组网络偏好
local command="source "..script_path..manufacturer..".sh && "..manufacturer.."_get_network_prefer "..at_port
local command="source "..script_path..manufacturer..".sh && "..manufacturer.."_get_network_prefer "..at_port.." "..data_interface.." "..name
local result=shell(command)
network_prefer_info=json.parse(result)
end
@ -615,8 +626,18 @@ function setNetworkPrefer()
local at_port = http.formvalue("port")
local network_prefer_config = json.stringify(http.formvalue("prefer_config"))
--获取制造商
local manufacturer=getManufacturer(at_port)
--获取制造商,数据接口,模组名称
local manufacturer
local data_interface
local name
uci:foreach("modem", "modem-device", function (modem_device)
if at_port == modem_device["at_port"] then
manufacturer=modem_device["manufacturer"]
data_interface=modem_device["data_interface"]
name=modem_device["name"]
return true --跳出循环
end
end)
--设置模组网络偏好
local command="source "..script_path..manufacturer..".sh && "..manufacturer.."_set_network_prefer "..at_port.." "..network_prefer_config
@ -624,11 +645,48 @@ function setNetworkPrefer()
--获取设置好后的模组网络偏好
local network_prefer={}
if at_port and manufacturer and manufacturer~="unknown" then
local command="source "..script_path..manufacturer..".sh && "..manufacturer.."_get_network_prefer "..at_port
local result=shell(command)
network_prefer=json.parse(result)
end
-- if at_port and manufacturer and manufacturer~="unknown" then
-- local command="source "..script_path..manufacturer..".sh && "..manufacturer.."_get_network_prefer "..at_port.." "..data_interface.." "..name
-- local result=shell(command)
-- network_prefer=json.parse(result)
-- end
-- 写入Web界面
luci.http.prepare_content("application/json")
luci.http.write_json(network_prefer)
end
--[[
@Description
]]
function setBandPrefer()
local at_port = http.formvalue("port")
local network_prefer_config = json.stringify(http.formvalue("prefer_config"))
--获取制造商,数据接口,模组名称
local manufacturer
local data_interface
local name
uci:foreach("modem", "modem-device", function (modem_device)
if at_port == modem_device["at_port"] then
manufacturer=modem_device["manufacturer"]
data_interface=modem_device["data_interface"]
name=modem_device["name"]
return true --跳出循环
end
end)
--设置模组网络偏好
local command="source "..script_path..manufacturer..".sh && "..manufacturer.."_set_band_prefer "..at_port.." "..network_prefer_config
shell(command)
--获取设置好后的模组网络偏好
local network_prefer={}
-- if at_port and manufacturer and manufacturer~="unknown" then
-- local command="source "..script_path..manufacturer..".sh && "..manufacturer.."_get_network_prefer "..at_port.." "..data_interface.." "..name
-- local result=shell(command)
-- network_prefer=json.parse(result)
-- end
-- 写入Web界面
luci.http.prepare_content("application/json")

View File

@ -46,6 +46,39 @@
copy_to_input();
});
// 设置网络偏好事件
set_network_prefer_event();
}
// 设置频段偏好事件
function set_band_prefer_event(network_type)
{
//获取网络偏好选项元素
var prefer_option_auto = document.getElementById(network_type+'_prefer_option_auto');
var prefer_option_custom = document.getElementById(network_type+'_prefer_option_custom');
//网络偏好选项为自动时触发
prefer_option_auto.addEventListener('change', function() {
if (prefer_option_auto.checked)
{
//禁用偏好复选框
disabled_prefer_custom_config(network_type+"_",true);
//全选偏好复选框
all_choose_prefer_custom_config(network_type+"_",true);
}
});
//网络偏好选项为自定义时触发
prefer_option_custom.addEventListener('change', function() {
if (prefer_option_custom.checked)
{
//禁用偏好复选框
disabled_prefer_custom_config(network_type+"_",false);
}
});
}
// 设置网络偏好事件
function set_network_prefer_event()
{
//获取网络偏好选项元素
var prefer_option_auto = document.getElementById('prefer_option_auto');
var prefer_option_custom = document.getElementById('prefer_option_custom');
@ -54,9 +87,9 @@
if (prefer_option_auto.checked)
{
//禁用偏好复选框
disabled_prefer_custom_config(true);
disabled_prefer_custom_config("",true);
//全选偏好复选框
all_choose_prefer_custom_config(true);
all_choose_prefer_custom_config("",true);
}
});
//网络偏好选项为自定义时触发
@ -64,9 +97,15 @@
if (prefer_option_custom.checked)
{
//禁用偏好复选框
disabled_prefer_custom_config(false);
disabled_prefer_custom_config("",false);
}
});
//设置频段偏好事件
set_band_prefer_event("5g");
set_band_prefer_event("4g");
set_band_prefer_event("3g");
set_band_prefer_event("2g");
}
//设置标签菜单事件
@ -412,9 +451,9 @@
}
// 全选网络偏好复选框
function all_choose_prefer_custom_config(status)
function all_choose_prefer_custom_config(id_prefix,status)
{
var checkboxes=document.getElementById('prefer_custom_config').querySelectorAll('input[type="checkbox"]');
var checkboxes=document.getElementById(id_prefix+'prefer_custom_config').querySelectorAll('input[type="checkbox"]');
for(checkbox of checkboxes)
{
//设置网络偏好复选框状态
@ -423,9 +462,9 @@
}
// 禁用网络偏好复选框
function disabled_prefer_custom_config(status)
function disabled_prefer_custom_config(id_prefix,status)
{
var checkboxes=document.getElementById('prefer_custom_config').querySelectorAll('input[type="checkbox"]');
var checkboxes=document.getElementById(id_prefix+'prefer_custom_config').querySelectorAll('input[type="checkbox"]');
for(checkbox of checkboxes)
{
//禁用
@ -433,6 +472,25 @@
}
}
// 禁用网络偏好功能
function disabled_network_prefer_function(id_prefix,status)
{
//偏好选项
var prefer_option_auto = document.getElementById('prefer_option_auto');
prefer_option_auto.disabled=status;
document.getElementById('prefer_option_custom').disabled=status;
//网络偏好为自动则不启用
if (!prefer_option_auto.checked)
{
//偏好复选框
disabled_prefer_custom_config("",status);
}
//偏好按钮
document.getElementById(id_prefix+'_prefer_button').disabled=status;
}
// 禁用功能
function disabled_function(function_name,status)
{
@ -454,20 +512,10 @@
//网络偏好
else if (function_name=="network_prefer")
{
//偏好选项
document.getElementById('prefer_option_auto').disabled=status;
document.getElementById('prefer_option_custom').disabled=status;
//网络偏好为自动则不启用
var prefer_option_auto = document.getElementById('prefer_option_auto');
if (!prefer_option_auto.checked)
{
//偏好复选框
disabled_prefer_custom_config(status);
}
//偏好按钮
document.getElementById('network_prefer_button').disabled=status;
// 网络类型
disabled_network_prefer_function("network",status);
// 频段
disabled_network_prefer_function("band",status);
}
}
@ -549,29 +597,131 @@
);
}
// 获取当前网络视图
function get_current_prefer_view(network_prefer)
// 设置网络偏好视图
function set_network_prefer_view(network_prefer)
{
var current_prefer_view="";
var current_prefer_view=""; //当前网络偏好
var prefer_check_view=""; //网络偏好复选框
var network_type_count=0; //统计已启用的网络类型
//自动状态判断(全部选中为自动)
if (network_prefer["3G"]&&network_prefer["4G"]&&network_prefer["5G"])
for(var keys of network_prefer)
{
//更新当前偏好
current_prefer_view="AUTO";
}
else
{
//更新当前偏好
for(key in network_prefer)
for(var key in keys)
{
if (network_prefer[key]) {
var band_info_display="none"; //频段偏好显示
var is_check=""; //是否选中(启用)
var network_type=key.toLowerCase(); //转小写
//已启动的网络类型
if (keys[key]["enable"])
{
//设置偏好视图
current_prefer_view+=key+" ";
if (keys[key]["band"].length!=0) {
band_info_display="block";
}
is_check="checked";
network_type_count++;
}
//设置偏好复选框视图
prefer_check_view+='<span class="cbi-checkbox"><input id="prefer_config_'+network_type+'" type="checkbox" class="cbi-input-checkbox" value="'+network_type+'" '+is_check+'><span>'+key+'</span></span> &nbsp;';
//频段偏好
var current_prefer_band_view=""; //当前频段偏好
var band_prefer_check_view=""; //频段偏好复选框
var band_count=0; //统计已启用的频段
for(var bands of keys[key]["band"])
{
for(var band in bands)
{
var band_is_check=""; //是否选中(启用)
var band_name=band.toLowerCase(); //转小写
//已启动的频段
if (bands[band])
{
//设置偏好视图
current_prefer_band_view+=band+" ";
band_is_check="checked";
band_count++;
}
//设置频段偏好复选框视图
band_prefer_check_view+='<span class="cbi-checkbox"><input id="band_prefer_config_'+band_name+'" type="checkbox" class="cbi-input-checkbox" value="'+band_name+'" '+band_is_check+'><span>'+band+'</span></span> &nbsp;';
}
}
//设置当前频段偏好(全未启用则为空)
if (band_count==0)
{
current_prefer_band_view="NONE";
}
document.getElementById(network_type+'_current_prefer').innerHTML=current_prefer_band_view;
var first_cache=document.getElementById("first_cache");
if (first_cache.checked)
{
//设置频段偏好复选框
document.getElementById(network_type+'_band_check').innerHTML=band_prefer_check_view;
//自动状态判断(全部启用为自动)
if (band_count==Object.keys(keys[key]["band"]).length)
{
//设置偏好选项
document.getElementById(network_type+'_prefer_option_auto').checked=true;
//更新偏好配置
all_choose_prefer_custom_config(network_type+"_",true);
//禁用用偏好复选框
disabled_prefer_custom_config(network_type+"_",true);
}
else
{
//设置偏好选项
document.getElementById(network_type+'_prefer_option_custom').checked=true;
//启用偏好复选框
disabled_prefer_custom_config(network_type+"_",false);
}
}
//设置频段偏好显示
document.getElementById("cbi-"+network_type+"_band_info").style.display=band_info_display;
}
}
//设置当前网络偏好(全部启用为自动)
if (network_type_count==Object.keys(network_prefer).length) {
current_prefer_view="AUTO";
}
document.getElementById('current_prefer').innerHTML=current_prefer_view;
var first_cache=document.getElementById("first_cache");
if (first_cache.checked)
{
//设置网络偏好复选框
document.getElementById('network_type_check').innerHTML=prefer_check_view;
//自动状态判断(全部启用为自动)
if (network_type_count==Object.keys(network_prefer).length)
{
//设置偏好选项
document.getElementById('prefer_option_auto').checked=true;
//更新偏好配置
all_choose_prefer_custom_config("",true);
//禁用用偏好复选框
disabled_prefer_custom_config("",true);
}
else
{
//设置偏好选项
document.getElementById('prefer_option_custom').checked=true;
//启用偏好复选框
disabled_prefer_custom_config("",false);
}
//设置第一次获取数据标志
first_cache.checked=false;
}
return current_prefer_view;
}
// 设置网络偏好信息
@ -580,45 +730,57 @@
//获取模组网络偏好
var network_prefer=network_prefer_info["network_prefer"];
//获取偏好视图
var current_prefer_view=get_current_prefer_view(network_prefer);
//设置网络偏好视图
set_network_prefer_view(network_prefer);
//设置当前网络偏好
document.getElementById('current_prefer').innerHTML=current_prefer_view;
// //设置当前网络偏好
// document.getElementById('current_prefer').innerHTML=current_prefer_view;
//设置偏好选项和复选框
var first_cache=document.getElementById("first_cache");
if (first_cache.checked)
{
if (network_prefer["3G"]&&network_prefer["4G"]&&network_prefer["5G"])
{
//设置偏好选项
document.getElementById('prefer_option_auto').checked=true;
//更新偏好配置
all_choose_prefer_custom_config(true);
//禁用用偏好复选框
disabled_prefer_custom_config(true);
}
else
{
//设置偏好选项
document.getElementById('prefer_option_custom').checked=true;
//更新偏好配置
for (key in network_prefer)
{
//设置偏好配置
var prefer_config_element=document.getElementById('prefer_config_'+key.toLowerCase());
if (prefer_config_element!=null) {
prefer_config_element.checked=network_prefer[key];
}
}
//启用偏好复选框
disabled_prefer_custom_config(false);
}
// //设置偏好选项和复选框
// var first_cache=document.getElementById("first_cache");
// if (first_cache.checked)
// {
// var count=0; //统计启用
// var prefer_check_view="";
// for(var keys of network_prefer)
// {
// for(var key in keys)
// {
// var network_type=key.toLowerCase(); //转小写
// var is_check=""; //是否选中(启用)
// if (keys[key]["enable"])
// {
// is_check="checked";
// count++;
// }
// //设置偏好复选框视图
// prefer_check_view+='<span class="cbi-checkbox"><input id="prefer_config_'+network_type+'" type="checkbox" class="cbi-input-checkbox" value="'+network_type+'" '+is_check+'><span>'+key+'</span></span> &nbsp;';
// }
// }
//设置第一次获取数据标志
first_cache.checked=false;
}
// //设置网络偏好复现框
// document.getElementById('network_type_check').innerHTML=prefer_check_view;
// //自动状态判断(全部启用为自动)
// if (count==Object.keys(network_prefer).length) {
// //设置偏好选项
// document.getElementById('prefer_option_auto').checked=true;
// //更新偏好配置
// all_choose_prefer_custom_config("",true);
// //禁用用偏好复选框
// disabled_prefer_custom_config("",true);
// }
// else
// {
// //设置偏好选项
// document.getElementById('prefer_option_custom').checked=true;
// //启用偏好复选框
// disabled_prefer_custom_config("",false);
// }
// //设置第一次获取数据标志
// first_cache.checked=false;
// }
}
// 设置模组自检信息
@ -708,33 +870,30 @@
//获取偏好配置
var network_prefer_config={};
if (prefer_option=="auto")
var checkboxes=document.getElementById('prefer_custom_config').querySelectorAll('input[type="checkbox"]');
for(checkbox of checkboxes)
{
network_prefer_config["3G"]=1;
network_prefer_config["4G"]=1;
network_prefer_config["5G"]=1;
}
else
{
var checkboxes=document.getElementById('prefer_custom_config').querySelectorAll('input[type="checkbox"]');
for(checkbox of checkboxes)
{
network_prefer_config[checkbox.value.toUpperCase()]=Number(checkbox.checked);
}
//获取网络类型配置
var network_prefer={};
network_prefer["enable"]=Number(checkbox.checked);
var network_type=checkbox.value;
network_prefer_config[network_type.toUpperCase()]=network_prefer;
}
//设置偏好
XHR.get('<%=luci.dispatcher.build_url("admin", "network", "modem", "set_network_prefer")%>', {"port":at_port,"prefer_config":network_prefer_config},
function(x, data)
{
//获取模组网络偏好
var network_prefer=data["network_prefer"];
// //获取模组网络偏好
// var network_prefer=data["network_prefer"];
//获取当前偏好视图
var current_prefer_view=get_current_prefer_view(network_prefer);
// //获取当前偏好视图
// var current_prefer_view=get_current_prefer_view(network_prefer);
//设置模组当前网络偏好
document.getElementById('current_prefer').innerHTML=current_prefer_view;
// //设置模组当前网络偏好
// document.getElementById('current_prefer').innerHTML=current_prefer_view;
//启用功能
disabled_function("network_prefer",false);
@ -742,6 +901,118 @@
);
}
// 设置频段偏好
function set_band_prefer()
{
//禁用功能
disabled_function("network_prefer",true);
//获取偏好选项
var prefer_option = document.querySelector('input[name="prefer_option"]:checked').value;
//获取选中的模组
var at_port = document.getElementById("modem_select").value;
//获取偏好配置
var network_prefer_config={};
var checkboxes=document.getElementById('prefer_custom_config').querySelectorAll('input[type="checkbox"]');
for(checkbox of checkboxes)
{
//获取网络类型配置
var network_prefer={};
network_prefer["enable"]=Number(checkbox.checked);
//获取频段配置
network_prefer["band"]=[];
if (checkbox.checked)
{
var network_type=checkbox.value;
var band_check_element=document.getElementById(network_type+"_band_check");
var bands=band_check_element.querySelectorAll('input[type="checkbox"]');
for(band of bands)
{
var band_config={};
band_config[band.value.toUpperCase().replace("-","_")]=Number(band.checked);
network_prefer["band"].push(band_config);
}
}
network_prefer_config[network_type.toUpperCase()]=network_prefer;
}
//设置偏好
XHR.get('<%=luci.dispatcher.build_url("admin", "network", "modem", "set_band_prefer")%>', {"port":at_port,"prefer_config":network_prefer_config},
function(x, data)
{
// //获取模组网络偏好
// var network_prefer=data["network_prefer"];
// //获取当前偏好视图
// var current_prefer_view=get_current_prefer_view(network_prefer);
// //设置模组当前网络偏好
// document.getElementById('current_prefer').innerHTML=current_prefer_view;
//启用功能
disabled_function("network_prefer",false);
}
);
}
// 设置网络偏好
// function set_band_prefer()
// {
// //禁用功能
// disabled_function("network_prefer",true);
// //获取偏好选项
// var prefer_option = document.querySelector('input[name="prefer_option"]:checked').value;
// //获取选中的模组
// var at_port = document.getElementById("modem_select").value;
// //获取偏好配置
// var network_prefer_config={};
// //获取网络类型配置
// var checkboxes=document.getElementById('prefer_custom_config').querySelectorAll('input[type="checkbox"]');
// for(checkbox of checkboxes)
// {
// network_prefer_config[checkbox.value.toUpperCase()]["enable"]=Number(checkbox.checked);
// if (checkbox.checked)
// {
// //获取频段配置
// var band_checkboxes=document.getElementById(checkbox.value+'prefer_custom_config').querySelectorAll('input[type="checkbox"]');
// for(band_checkbox of band_checkboxes)
// {
// network_prefer_config[checkbox.value.toUpperCase()]["band"]=Number(band_checkbox.checked);
// }
// }
// else
// {
// network_prefer_config[checkbox.value.toUpperCase()]["band"]="[]";
// }
// }
// //设置偏好
// XHR.get('<%=luci.dispatcher.build_url("admin", "network", "modem", "set_network_prefer")%>', {"port":at_port,"prefer_config":network_prefer_config},
// function(x, data)
// {
// //获取模组网络偏好
// var network_prefer=data["network_prefer"];
// //获取当前偏好视图
// var current_prefer_view=get_current_prefer_view(network_prefer);
// //设置模组当前网络偏好
// document.getElementById('current_prefer').innerHTML=current_prefer_view;
// //启用功能
// disabled_function("network_prefer",false);
// }
// );
// }
// 获取模组调试信息
function get_modem_debug_info()
{
@ -1066,6 +1337,7 @@
<th class="th cbi-section-table-cell"><%:Option%></th>
<th class="th cbi-section-table-cell"><%:Config%></th>
<th class="th cbi-section-table-cell cbi-section-actions"></th>
<th class="th cbi-section-table-cell cbi-section-actions"></th>
</tr>
<tr class="tr cbi-section-table-row cbi-rowstyle-1">
<td class="td cbi-value-field" data-title="<%:Current%>" id="current_prefer"></td>
@ -1082,8 +1354,8 @@
</div>
</td>
<td class="td cbi-value-field" data-title="<%:Config%>" id="prefer_custom_config">
<div>
<span class="cbi-checkbox">
<div id="network_type_check"></div>
<!-- <span class="cbi-checkbox">
<input id="prefer_config_3g" type="checkbox" class="cbi-input-checkbox" value="3g">
<span><%:3G%></span>
</span> &nbsp;
@ -1095,13 +1367,19 @@
<input id="prefer_config_5g" type="checkbox" class="cbi-input-checkbox" value="5g">
<span><%:5G%></span>
</span>
</div>
</div> -->
</td>
<td class="td">
<div>
<!-- <button class="btn cbi-button cbi-button-apply" id="network_prefer_button" onclick="set_network_prefer()" alt="<%:Apply Network Prefer%>" title="<%:Apply Network Prefer%>"><%:Apply Network Prefer%></button> -->
<button class="btn cbi-button cbi-button-apply" id="network_prefer_button" onclick="set_network_prefer()" alt="<%:Apply%>" title="<%:Apply%>"><%:Apply%></button>
</div>
</td>
<td class="td" style="display: none;">
<div>
<button class="btn cbi-button cbi-button-apply" id="band_prefer_button" onclick="set_band_prefer()" alt="<%:Apply Band Prefer%>" title="<%:Apply Band Prefer%>"><%:Apply Band Prefer%></button>
</div>
</td>
</tr>
</tbody>
</table>
@ -1187,6 +1465,146 @@
</div>
</div>
<fieldset class="cbi-section" id="cbi-5g_band_info" style="display: none;">
<div class="cbi-section fade-in">
<!-- <legend><%:5G Band Preferences%></legend> -->
<h3><%:5G Band Preferences%></h3>
<table class="table cbi-section-table">
<tbody>
<tr class="tr cbi-section-table-titles anonymous">
<th class="th cbi-section-table-cell"><%:Current%></th>
<th class="th cbi-section-table-cell"><%:Option%></th>
<th class="th cbi-section-table-cell"><%:Config%></th>
<th class="th cbi-section-table-cell cbi-section-actions"></th>
</tr>
<tr class="tr cbi-section-table-row cbi-rowstyle-1">
<td class="td cbi-value-field" data-title="<%:Current%>" id="5g_current_prefer"></td>
<td class="td cbi-value-field" data-title="<%:Option%>" id="5g_prefer_option">
<div>
<span class="cbi-radio">
<input type="radio" name="5g_prefer_option" id="5g_prefer_option_auto" value="auto" checked="true">
<span><%:Auto%></span>
</span>&nbsp;
<span class="cbi-radio">
<input type="radio" name="5g_prefer_option" id="5g_prefer_option_custom" value="custom">
<span><%:Custom%></span>
</span>
</div>
</td>
<td class="td cbi-value-field" data-title="<%:Config%>" id="5g_prefer_custom_config">
<div id="5g_band_check"></div>
</td>
</tr>
</tbody>
</table>
</div>
</fieldset>
<fieldset class="cbi-section" id="cbi-4g_band_info" style="display: none;">
<div class="cbi-section fade-in">
<!-- <legend><%:4G Band Preferences%></legend> -->
<h3><%:4G Band Preferences%></h3>
<table class="table cbi-section-table">
<tbody>
<tr class="tr cbi-section-table-titles anonymous">
<th class="th cbi-section-table-cell"><%:Current%></th>
<th class="th cbi-section-table-cell"><%:Option%></th>
<th class="th cbi-section-table-cell"><%:Config%></th>
<th class="th cbi-section-table-cell cbi-section-actions"></th>
</tr>
<tr class="tr cbi-section-table-row cbi-rowstyle-1">
<td class="td cbi-value-field" data-title="<%:Current%>" id="4g_current_prefer"></td>
<td class="td cbi-value-field" data-title="<%:Option%>" id="4g_prefer_option">
<div>
<span class="cbi-radio">
<input type="radio" name="4g_prefer_option" id="4g_prefer_option_auto" value="auto" checked="true">
<span><%:Auto%></span>
</span>&nbsp;
<span class="cbi-radio">
<input type="radio" name="4g_prefer_option" id="4g_prefer_option_custom" value="custom">
<span><%:Custom%></span>
</span>
</div>
</td>
<td class="td cbi-value-field" data-title="<%:Config%>" id="4g_prefer_custom_config">
<div id="4g_band_check"></div>
</td>
</tr>
</tbody>
</table>
</div>
</fieldset>
<fieldset class="cbi-section" id="cbi-3g_band_info" style="display: none;">
<div class="cbi-section fade-in">
<!-- <legend><%:3G Band Preferences%></legend> -->
<h3><%:3G Band Preferences%></h3>
<table class="table cbi-section-table">
<tbody>
<tr class="tr cbi-section-table-titles anonymous">
<th class="th cbi-section-table-cell"><%:Current%></th>
<th class="th cbi-section-table-cell"><%:Option%></th>
<th class="th cbi-section-table-cell"><%:Config%></th>
<th class="th cbi-section-table-cell cbi-section-actions"></th>
</tr>
<tr class="tr cbi-section-table-row cbi-rowstyle-1">
<td class="td cbi-value-field" data-title="<%:Current%>" id="3g_current_prefer"></td>
<td class="td cbi-value-field" data-title="<%:Option%>" id="3g_prefer_option">
<div>
<span class="cbi-radio">
<input type="radio" name="3g_prefer_option" id="3g_prefer_option_auto" value="auto" checked="true">
<span><%:Auto%></span>
</span>&nbsp;
<span class="cbi-radio">
<input type="radio" name="3g_prefer_option" id="3g_prefer_option_custom" value="custom">
<span><%:Custom%></span>
</span>
</div>
</td>
<td class="td cbi-value-field" data-title="<%:Config%>" id="3g_prefer_custom_config">
<div id="3g_band_check"></div>
</td>
</tr>
</tbody>
</table>
</div>
</fieldset>
<fieldset class="cbi-section" id="cbi-2g_band_info" style="display: none;">
<div class="cbi-section fade-in">
<!-- <legend><%:2G Band Preferences%></legend> -->
<h3><%:2G Band Preferences%></h3>
<table class="table cbi-section-table">
<tbody>
<tr class="tr cbi-section-table-titles anonymous">
<th class="th cbi-section-table-cell"><%:Current%></th>
<th class="th cbi-section-table-cell"><%:Option%></th>
<th class="th cbi-section-table-cell"><%:Config%></th>
<th class="th cbi-section-table-cell cbi-section-actions"></th>
</tr>
<tr class="tr cbi-section-table-row cbi-rowstyle-1">
<td class="td cbi-value-field" data-title="<%:Current%>" id="2g_current_prefer"></td>
<td class="td cbi-value-field" data-title="<%:Option%>" id="2g_prefer_option">
<div>
<span class="cbi-radio">
<input type="radio" name="2g_prefer_option" id="2g_prefer_option_auto" value="auto" checked="true">
<span><%:Auto%></span>
</span>&nbsp;
<span class="cbi-radio">
<input type="radio" name="2g_prefer_option" id="2g_prefer_option_custom" value="custom">
<span><%:Custom%></span>
</span>
</div>
</td>
<td class="td cbi-value-field" data-title="<%:Config%>" id="2g_prefer_custom_config">
<div id="2g_band_check"></div>
</td>
</tr>
</tbody>
</table>
</div>
</fieldset>
</div>
<%+footer%>

View File

@ -329,4 +329,64 @@ config custom-commands
config custom-commands
option description '重启模组 > AT+RESET'
option command 'AT+RESET'
option command 'AT+RESET'
config custom-commands
option description '****************华为****************'
option command 'ATI'
config custom-commands
option description '获取SIM卡卡槽状态 > AT^SIMSLOT?'
option command 'AT^SIMSLOT?'
config custom-commands
option description '设置当前使用的为卡1 > AT^SIMSWITCH=1'
option command 'AT^SIMSWITCH=1'
config custom-commands
option description '设置当前使用的为卡2 > AT^SIMSWITCH=0'
option command 'AT^SIMSWITCH=0'
config custom-commands
option description '查询网络信息 > AT^SYSINFOEX'
option command 'AT^SYSINFOEX'
config custom-commands
option description '查询当前拨号模式 > AT^SETMODE?'
option command 'AT^SETMODE?'
config custom-commands
option description 'ECM拨号模式Linux > AT^SETMODE=0'
option command 'AT^SETMODE=0'
config custom-commands
option description 'NCM拨号模式Windows > AT^SETMODE=1'
option command 'AT^SETMODE=1'
config custom-commands
option description 'ECM拨号模式LinuxDebug > AT^SETMODE=2'
option command 'AT^SETMODE=2'
config custom-commands
option description 'NCM拨号模式Windows,Debug > AT^SETMODE=3'
option command 'AT^SETMODE=3'
config custom-commands
option description '锁4G > AT^SYSCFGEX="03",40000000,1,2,7FFFFFFFFFFFFFFF,,'
option command 'AT^SYSCFGEX="03",40000000,1,2,7FFFFFFFFFFFFFFF,,'
config custom-commands
option description '锁5G > AT^SYSCFGEX="08",40000000,1,2,7FFFFFFFFFFFFFFF,,'
option command 'AT^SYSCFGEX="08",40000000,1,2,7FFFFFFFFFFFFFFF,,'
config custom-commands
option description '恢复自动搜索网络 > AT^SYSCFGEX="00",3FFFFFFF,1,2,7FFFFFFFFFFFFFFF,,'
option command 'AT^SYSCFGEX="00",3FFFFFFF,1,2,7FFFFFFFFFFFFFFF,,'
config custom-commands
option description '获取模组温度 > AT^CHIPTEMP?'
option command 'AT^CHIPTEMP?'
config custom-commands
option description '重启模组 > AT^RESET'
option command 'AT^RESET'

View File

@ -445,6 +445,8 @@ stop_ecm()
fi
elif [ "$manufacturer" = "meig" ]; then
at_command="AT^NDISDUP=${define_connect},0"
elif [ "$manufacturer" = "huawei" ]; then
at_command="AT^NDISDUP=${define_connect},0"
else
at_command='ATI'
fi
@ -633,13 +635,12 @@ dial()
[ -z "${modem_no}" ] && return 0
#获取模组的拨号模式
local time=0
local time=20
local mode
while [ $time -lt 10 ]; do
for i in $(seq 1 ${time}); do
mode=$(get_mode ${modem_no})
[ -n "$mode" ] && [ "$mode" != "unknown" ] && break
sleep 5s
time=$((time+1))
done
#获取不到拨号模式

View File

@ -159,6 +159,23 @@
{"获取模组温度 > AT+TEMP":"AT+TEMP"},
{"重启模组 > AT+RESET":"AT+RESET"}
]
},
"huawei":{
"hisilicon":[
{"设置当前使用的为卡1 > AT^SIMSWITCH=1":"AT^SIMSWITCH=1"},
{"设置当前使用的为卡2 > AT^SIMSWITCH=0":"AT^SIMSWITCH=0"},
{"查询网络信息 > AT^SYSINFOEX":"AT^SYSINFOEX"},
{"查询当前拨号模式 > AT^SETMODE?":"AT^SETMODE?"},
{"ECM拨号模式Linux > AT^SETMODE=0":"AT^SETMODE=0"},
{"NCM拨号模式Windows > AT^SETMODE=1":"AT^SETMODE=1"},
{"ECM拨号模式LinuxDebug > AT^SETMODE=2":"AT^SETMODE=2"},
{"NCM拨号模式Windows,Debug > AT^SETMODE=3":"AT^SETMODE=3"},
{"锁4G > AT^SYSCFGEX=\"03\",40000000,1,2,7FFFFFFFFFFFFFFF,,":"AT^SYSCFGEX=\"03\",40000000,1,2,7FFFFFFFFFFFFFFF,,"},
{"锁5G > AT^SYSCFGEX=\"08\",40000000,1,2,7FFFFFFFFFFFFFFF,,":"AT^SYSCFGEX=\"08\",40000000,1,2,7FFFFFFFFFFFFFFF,,"},
{"恢复自动搜索网络 > AT^SYSCFGEX=\"00\",3FFFFFFF,1,2,7FFFFFFFFFFFFFFF,,":"AT^SYSCFGEX=\"00\",3FFFFFFF,1,2,7FFFFFFFFFFFFFFF,,"},
{"获取模组温度 > AT^CHIPTEMP?":"AT^CHIPTEMP?"},
{"重启模组 > AT^RESET":"AT^RESET"}
]
}
}
}

View File

@ -43,7 +43,7 @@ fibocom_get_dns()
#获取DNS地址
at_command="AT+GTDNS=${define_connect}"
local response=$(at ${at_port} ${at_command} | grep "+GTDNS: " | grep -E '[0-9]+.[0-9]+.[0-9]+.[0-9]+' | sed -n '1p')
local response=$(sh ${SCRIPT_DIR}/modem_at.sh ${at_port} ${at_command} | grep "+GTDNS: " | grep -E '[0-9]+.[0-9]+.[0-9]+.[0-9]+' | sed -n '1p')
local ipv4_dns1=$(echo "${response}" | awk -F'"' '{print $2}' | awk -F',' '{print $1}')
[ -z "$ipv4_dns1" ] && {
@ -203,29 +203,32 @@ fibocom_set_mode()
#获取网络偏好
# $1:AT串口
# $2:数据接口
# $3:模组名称
fibocom_get_network_prefer()
{
local at_port="$1"
at_command="AT+GTACT?"
local network_prefer_num=$(sh ${SCRIPT_DIR}/modem_at.sh $at_port $at_command | grep "+GTACT:" | awk -F',' '{print $1}' | sed 's/+GTACT: //g')
local data_interface="$2"
local modem_name="$3"
at_command="AT+GTACT?"
local response=$(sh ${SCRIPT_DIR}/modem_at.sh ${at_port} ${at_command} | grep "+GTACT:" | sed 's/+GTACT: //g')
local network_type_num=$(echo "$response" | awk -F',' '{print $1}')
#获取网络类型
# local network_prefer_2g="0";
local network_prefer_3g="0";
local network_prefer_4g="0";
local network_prefer_5g="0";
#匹配不同的网络类型
case "$network_prefer_num" in
case "$network_type_num" in
"1") network_prefer_3g="1" ;;
"2") network_prefer_4g="1" ;;
"4")
network_prefer_3g="1"
network_prefer_4g="1"
;;
"10")
network_prefer_3g="1"
network_prefer_4g="1"
network_prefer_5g="1"
;;
"14") network_prefer_5g="1" ;;
"16")
network_prefer_3g="1"
@ -235,26 +238,37 @@ fibocom_get_network_prefer()
network_prefer_4g="1"
network_prefer_5g="1"
;;
"20")
network_prefer_3g="1"
network_prefer_4g="1"
network_prefer_5g="1"
;;
*)
"10"|"20"|*)
network_prefer_3g="1"
network_prefer_4g="1"
network_prefer_5g="1"
;;
esac
#获取频段信息
# local band_2g_info="[]"
local band_3g_info="[]"
local band_4g_info="[]"
local band_5g_info="[]"
#生成网络偏好
local network_prefer="{
\"network_prefer\":{
\"3G\":$network_prefer_3g,
\"4G\":$network_prefer_4g,
\"5G\":$network_prefer_5g
}
\"network_prefer\":[
{\"3G\":{
\"enable\":$network_prefer_3g,
\"band\":$band_3g_info
}},
{\"4G\":{
\"enable\":$network_prefer_4g,
\"band\":$band_4g_info
}},
{\"5G\":{
\"enable\":$network_prefer_5g,
\"band\":$band_5g_info
}}
]
}"
echo "$network_prefer"
echo "${network_prefer}"
}
#设置网络偏好
@ -265,41 +279,41 @@ fibocom_set_network_prefer()
local at_port="$1"
local network_prefer="$2"
#获取网络偏好数字
local network_prefer_num
#获取网络偏好配置
local network_prefer_config
#获取选中的数量
local count=$(echo "$network_prefer" | grep -o "1" | wc -l)
#获取每个偏好的值
local network_prefer_3g=$(echo "$network_prefer" | jq -r '.["3G"]')
local network_prefer_4g=$(echo "$network_prefer" | jq -r '.["4G"]')
local network_prefer_5g=$(echo "$network_prefer" | jq -r '.["5G"]')
#获取启用的网络偏好
local enable_5g=$(echo "$network_prefer" | jq -r '.["5G"].enable')
local enable_4g=$(echo "$network_prefer" | jq -r '.["4G"].enable')
local enable_3g=$(echo "$network_prefer" | jq -r '.["3G"].enable')
case "$count" in
"1")
if [ "$network_prefer_3g" = "1" ]; then
network_prefer_num="1"
elif [ "$network_prefer_4g" = "1" ]; then
network_prefer_num="2"
elif [ "$network_prefer_5g" = "1" ]; then
network_prefer_num="14"
if [ "$enable_3g" = "1" ]; then
network_prefer_config="1"
elif [ "$enable_4g" = "1" ]; then
network_prefer_config="2"
elif [ "$enable_5g" = "1" ]; then
network_prefer_config="14"
fi
;;
"2")
if [ "$network_prefer_3g" = "1" ] && [ "$network_prefer_4g" = "1" ]; then
network_prefer_num="4"
elif [ "$network_prefer_3g" = "1" ] && [ "$network_prefer_5g" = "1" ]; then
network_prefer_num="16"
elif [ "$network_prefer_4g" = "1" ] && [ "$network_prefer_5g" = "1" ]; then
network_prefer_num="17"
if [ "$enable_3g" = "1" ] && [ "$enable_4g" = "1" ]; then
network_prefer_config="4"
elif [ "$enable_3g" = "1" ] && [ "$enable_5g" = "1" ]; then
network_prefer_config="16"
elif [ "$enable_4g" = "1" ] && [ "$enable_5g" = "1" ]; then
network_prefer_config="17"
fi
;;
"3") network_prefer_num="20" ;;
*) network_prefer_num="10" ;;
"3") network_prefer_config="20" ;;
*) network_prefer_config="10" ;;
esac
echo "$network_prefer_config" >> /root/a
#设置模组
at_command="AT+GTACT=$network_prefer_num"
at_command="AT+GTACT=${network_prefer_config}"
sh ${SCRIPT_DIR}/modem_at.sh $at_port "$at_command"
}

View File

@ -0,0 +1,915 @@
#!/bin/sh
# Copyright (C) 2023 Siriling <siriling@qq.com>
#脚本目录
SCRIPT_DIR="/usr/share/modem"
#预设
huawei_presets()
{
#关闭模组主动上报
at_command='AT^CURC=0'
sh "${SCRIPT_DIR}/modem_at.sh" "$at_port" "$at_command"
#开启5G NA NSA接入
at_command='AT^C5GOPTION=1,3,3'
sh "${SCRIPT_DIR}/modem_at.sh" "$at_port" "$at_command"
}
#获取DNS
# $1:AT串口
# $2:连接定义
huawei_get_dns()
{
local at_port="$1"
local define_connect="$2"
[ -z "$define_connect" ] && {
define_connect="1"
}
local public_dns1_ipv4="223.5.5.5"
local public_dns2_ipv4="119.29.29.29"
local public_dns1_ipv6="2400:3200::1" #下一代互联网北京研究中心240C::6666阿里2400:3200::1腾讯2402:4e00::
local public_dns2_ipv6="2402:4e00::"
#获取DNS地址IPv4
at_command="AT^DHCP=${define_connect}"
local response=$(sh ${SCRIPT_DIR}/modem_at.sh ${at_port} ${at_command} | grep "\^DHCP:" | sed -n '1p')
local ipv4_dns1=$(echo "${response}" | awk -F',' '{print $5}')
if [ -z "$ipv4_dns1" ]; then
ipv4_dns1="${public_dns1_ipv4}"
else
#按字节byte将十六进制拆分并转换为对应的十进制表示
ipv4_dns1=$(echo "$ipv4_dns1" | awk '{
for (i = length; i >= 1; i -= 2) {
printf "%d.", "0x" substr($0, i-1, 2)
}
}')
ipv4_dns1="${ipv4_dns1%?}"
fi
local ipv4_dns2=$(echo "${response}" | awk -F',' '{print $6}')
if [ -z "$ipv4_dns2" ]; then
ipv4_dns2="${public_dns1_ipv4}"
else
#按字节byte将十六进制拆分并转换为对应的十进制表示
ipv4_dns2=$(echo "$ipv4_dns2" | awk '{
for (i = length; i >= 1; i -= 2) {
printf "%d.", "0x" substr($0, i-1, 2)
}
}')
ipv4_dns2="${ipv4_dns2%?}"
fi
#获取DNS地址IPv6
at_command="AT^DHCPV6=${define_connect}"
local response=$(sh ${SCRIPT_DIR}/modem_at.sh ${at_port} ${at_command} | grep "\^DHCPV6:" | sed -n '1p')
local ipv6_dns1=$(echo "${response}" | awk -F',' '{print $5}')
[ -z "$ipv6_dns1" ] && {
ipv6_dns1="${public_dns1_ipv6}"
}
local ipv6_dns2=$(echo "${response}" | awk -F',' '{print $6}')
[ -z "$ipv6_dns2" ] && {
ipv6_dns2="${public_dns2_ipv6}"
}
dns="{
\"dns\":{
\"ipv4_dns1\":\"$ipv4_dns1\",
\"ipv4_dns2\":\"$ipv4_dns2\",
\"ipv6_dns1\":\"$ipv6_dns1\",
\"ipv6_dns2\":\"$ipv6_dns2\"
}
}"
echo "$dns"
}
#获取拨号模式
# $1:AT串口
# $2:平台
huawei_get_mode()
{
local at_port="$1"
local platform="$2"
at_command="AT^SETMODE?"
local mode_num=$(sh ${SCRIPT_DIR}/modem_at.sh ${at_port} ${at_command} | grep "\^SETMODE:" | awk -F': ' '{print $2}' | sed 's/\r//g')
if [ -z "$mode_num" ]; then
echo "unknown"
return
fi
#获取芯片平台
if [ -z "$platform" ]; then
local modem_number=$(uci -q get modem.@global[0].modem_number)
for i in $(seq 0 $((modem_number-1))); do
local at_port_tmp=$(uci -q get modem.modem$i.at_port)
if [ "$at_port" = "$at_port_tmp" ]; then
platform=$(uci -q get modem.modem$i.platform)
break
fi
done
fi
local mode
case "$platform" in
"hisilicon")
case "$mode_num" in
"0"|"2") mode="ecm" ;;
"1"|"3") mode="ncm" ;;
"4") mode="unknown" ;;
*) mode="$mode_num" ;;
esac
;;
*)
mode="$mode_num"
;;
esac
echo "${mode}"
}
#设置拨号模式
# $1:AT串口
# $2:拨号模式配置
huawei_set_mode()
{
local at_port="$1"
local mode_config="$2"
#获取芯片平台
local platform
local modem_number=$(uci -q get modem.@global[0].modem_number)
for i in $(seq 0 $((modem_number-1))); do
local at_port_tmp=$(uci -q get modem.modem$i.at_port)
if [ "$at_port" = "$at_port_tmp" ]; then
platform=$(uci -q get modem.modem$i.platform)
break
fi
done
#获取拨号模式配置
local mode_num
case "$platform" in
"hisilicon")
case "$mode_config" in
"ecm") mode_num="0" ;;
*) mode_num="0" ;;
esac
;;
*)
mode_num="0"
;;
esac
#设置模组
at_command="AT^SETMODE=${mode_num}"
sh ${SCRIPT_DIR}/modem_at.sh ${at_port} "${at_command}"
}
#获取位
# $1:频段名称
huawei_get_bit()
{
local band_name="$1"
local bit
case "$band_name" in
"DCS_1800") bit="8" ;;
"E-GSM_900"|"E_GSM_900") bit="9" ;;
"P-GSM_900"|"P_GSM_900") bit="10" ;;
"GSM_450") bit="17" ;;
"GSM_480") bit="18" ;;
"GSM_750") bit="19" ;;
"GSM_850") bit="20" ;;
"R-GSM_900"|"R_GSM_900") bit="21" ;;
"PCS_1900") bit="22" ;;
esac
echo "${bit}"
}
#获取频段信息
# $1:频段二进制数
# $2:支持的频段
# $3:频段类型2G3G4G5G
huawei_get_band_info()
{
local band_bin="$1"
local support_band="$2"
local band_type="$3"
local band_info=""
local support_band=$(echo "$support_band" | sed 's/,/ /g')
if [ "$band_type" = "2G" ]; then
for band in $support_band; do
#获取bit位
local bit=$(huawei_get_bit ${band})
#获取值
local enable="${band_bin: $((-bit)):1}"
[ -z "$enable" ] && enable="0"
#设置频段信息
# band_info=$(echo ${band_info} | jq '. += [{"'$band'":'$enable'}]')
band_info="${band_info},{\"$band\":$enable}"
done
else
#频段频段起始,前缀位置
local start_bit
local band_prefix
case "$band_type" in
"3G")
start_bit="23"
band_prefix="WCDMA_B"
;;
"4G")
start_bit="1"
band_prefix="LTE_BC"
;;
"5G")
start_bit="1"
band_prefix="NR5G_N"
;;
esac
for band in $support_band; do
#获取值从start_bit位开始
local enable="${band_bin: $((-band-start_bit+1)):1}"
[ -z "$enable" ] && enable="0"
#设置频段信息
# band_info=$(echo ${band_info} | jq '. += [{'$band_prefix$band':'$enable'}]')
band_info="${band_info},{\"$band_prefix$band\":$enable}"
done
fi
#去掉第一个,
band_info="["${band_info/,/}"]"
# band_info="[${band_info%?}]"
echo "${band_info}"
}
#获取网络偏好
# $1:AT串口
# $2:数据接口
# $3:模组名称
huawei_get_network_prefer()
{
local at_port="$1"
local data_interface="$2"
local modem_name="$3"
at_command="AT^SYSCFGEX?"
local response=$(sh ${SCRIPT_DIR}/modem_at.sh ${at_port} ${at_command} | grep "\^SYSCFGEX:" | sed 's/\^SYSCFGEX://g')
local network_type_num=$(echo "$response" | awk -F'"' '{print $2}')
#获取网络类型
local network_prefer_2g="0";
local network_prefer_3g="0";
local network_prefer_4g="0";
local network_prefer_5g="0";
#匹配不同的网络类型
local auto=$(echo "${network_type_num}" | grep "00")
if [ -n "$auto" ]; then
network_prefer_2g="1"
network_prefer_3g="1"
network_prefer_4g="1"
network_prefer_5g="1"
else
local gsm=$(echo "${network_type_num}" | grep "01")
local wcdma=$(echo "${network_type_num}" | grep "02")
local lte=$(echo "${network_type_num}" | grep "03")
local nr=$(echo "${network_type_num}" | grep "08")
if [ -n "$gsm" ]; then
network_prefer_2g="1"
fi
if [ -n "$wcdma" ]; then
network_prefer_3g="1"
fi
if [ -n "$lte" ]; then
network_prefer_4g="1"
fi
if [ -n "$nr" ]; then
network_prefer_5g="1"
fi
fi
#获取模组信息
local modem_info=$(jq '.modem_support.'$data_interface'."'$modem_name'"' ${SCRIPT_DIR}/modem_support.json)
#获取模组支持的频段
local support_2g_band=$(echo "$modem_info" | jq -r '.band_2g')
local support_3g_band=$(echo "$modem_info" | jq -r '.band_3g')
local support_4g_band=$(echo "$modem_info" | jq -r '.band_4g')
local support_5g_band=$(echo "$modem_info" | jq -r '.band_5g')
#获取频段信息
local band_hex_2g_3g=$(echo "$response" | awk -F',' '{print $2}')
#十六进制转二进制
local bin_2g_3g=$(echo "obase=2; ibase=16; $band_hex_2g_3g" | bc)
local band_2g_info=$(huawei_get_band_info "${bin_2g_3g}" "${support_2g_band}" "2G")
local band_3g_info=$(huawei_get_band_info "${bin_2g_3g}" "${support_3g_band}" "3G")
local band_hex_4g_5g=$(echo "$response" | awk -F',' '{print $5}' | sed 's/\r//g')
#十六进制转二进制
local bin_4g_5g=$(echo "obase=2; ibase=16; $band_hex_4g_5g" | bc)
local band_4g_info=$(huawei_get_band_info "${bin_4g_5g}" "${support_4g_band}" "4G")
local band_5g_info=$(huawei_get_band_info "${bin_4g_5g}" "${support_5g_band}" "5G")
#生成网络偏好
local network_prefer="{
\"network_prefer\":[
{\"2G\":{
\"enable\":$network_prefer_2g,
\"band\":$band_2g_info
}},
{\"3G\":{
\"enable\":$network_prefer_3g,
\"band\":$band_3g_info
}},
{\"4G\":{
\"enable\":$network_prefer_4g,
\"band\":$band_4g_info
}},
{\"5G\":{
\"enable\":$network_prefer_5g,
\"band\":$band_5g_info
}}
]
}"
echo "${network_prefer}"
}
#设置网络偏好
# $1:AT串口
# $2:网络偏好配置
huawei_set_network_prefer()
{
local at_port="$1"
local network_prefer="$2"
#获取启用的网络偏好
local enable_5g=$(echo "$network_prefer" | jq -r '.["5G"].enable')
local enable_4g=$(echo "$network_prefer" | jq -r '.["4G"].enable')
local enable_3g=$(echo "$network_prefer" | jq -r '.["3G"].enable')
local enable_2g=$(echo "$network_prefer" | jq -r '.["2G"].enable')
#获取网络偏好配置
local network_prefer_config
[ "$enable_5g" = "1" ] && network_prefer_config="${network_prefer_config}08"
[ "$enable_4g" = "1" ] && network_prefer_config="${network_prefer_config}03"
[ "$enable_3g" = "1" ] && network_prefer_config="${network_prefer_config}02"
[ "$enable_2g" = "1" ] && network_prefer_config="${network_prefer_config}01"
[ -z "$network_prefer_config" ] && network_prefer_config="99"
#设置模组
at_command='AT^SYSCFGEX="'${network_prefer_config}'",40000000,1,2,40000000,,'
sh ${SCRIPT_DIR}/modem_at.sh "${at_port}" "${at_command}"
}
#设置频段
# $1:AT串口
# $2:频段偏好配置
huawei_set_band_prefer()
{
local at_port="$1"
local network_prefer="$2"
#获取选中的数量
local count=$(echo "$network_prefer" | grep -o "1" | wc -l)
#获取每个偏好的值
local network_prefer_5g=$(echo "$network_prefer" | jq -r '.["5G"]')
local network_prefer_4g=$(echo "$network_prefer" | jq -r '.["4G"]')
local network_prefer_3g=$(echo "$network_prefer" | jq -r '.["3G"]')
local network_prefer_2g=$(echo "$network_prefer" | jq -r '.["2G"]')
#获取启用的网络偏好
local enable_5g=$(echo "$network_prefer_5g" | jq -r '.enable')
local enable_4g=$(echo "$network_prefer_4g" | jq -r '.enable')
local enable_3g=$(echo "$network_prefer_3g" | jq -r '.enable')
local enable_2g=$(echo "$network_prefer_2g" | jq -r '.enable')
#获取网络偏好配置和频段偏好配置
local network_prefer_config
local band_hex_2g_3g=0
local band_hex_4g_5g=0
[ "$enable_5g" = "1" ] && {
network_prefer_config="${network_prefer_config}08"
local band_tmp=$(echo "$network_prefer_5g" | jq -r '.band[]')
local i=0
local bands=$(echo "$band_tmp" | jq -r 'to_entries | .[] | .key')
#遍历band的值
for band in $bands; do
local value=$(echo "$network_prefer_5g" | jq -r '.band'"[$i].$band")
[ "$value" = "1" ] && {
#获取bit位
local bit=$(echo "$band" | sed 's/NR5G_N//g')
#获取值
local result=$(echo "obase=16; ibase=10; 2^($bit-1)" | bc)
band_hex_4g_5g=$(echo "obase=16; ibase=16; $band_hex_4g_5g + $result" | bc)
}
i=$((i+1))
done
}
[ "$enable_4g" = "1" ] && {
network_prefer_config="${network_prefer_config}03"
local band_tmp=$(echo "$network_prefer_4g" | jq -r '.band[]')
local i=0
local bands=$(echo "$band_tmp" | jq -r 'to_entries | .[] | .key')
#遍历band的值
for band in $bands; do
local value=$(echo "$network_prefer_4g" | jq -r '.band'"[$i].$band")
[ "$value" = "1" ] && {
#获取bit位
local bit=$(echo "$band" | sed 's/LTE_BC//g')
#获取值
local result=$(echo "obase=16; ibase=10; 2^($bit-1)" | bc)
band_hex_4g_5g=$(echo "obase=16; ibase=16; $band_hex_4g_5g + $result" | bc)
}
i=$((i+1))
done
}
[ "$enable_3g" = "1" ] && {
network_prefer_config="${network_prefer_config}02"
local band_tmp=$(echo "$network_prefer_3g" | jq -r '.band[]')
local i=0
local bands=$(echo "$band_tmp" | jq -r 'to_entries | .[] | .key')
#遍历band的值
for band in $bands; do
local value=$(echo "$network_prefer_3g" | jq -r '.band'"[$i].$band")
[ "$value" = "1" ] && {
#获取bit位
local bit=$(echo "$band" | sed 's/WCDMA_B//g')
#获取值
local result=$(echo "obase=16; ibase=10; 2^($bit+22-1)" | bc)
band_hex_2g_3g=$(echo "obase=16; ibase=16; $band_hex_2g_3g + $result" | bc)
}
i=$((i+1))
done
}
[ "$enable_2g" = "1" ] && {
network_prefer_config="${network_prefer_config}01"
local band_tmp=$(echo "$network_prefer_2g" | jq -r '.band[]')
local i=0
local bands=$(echo "$band_tmp" | jq -r 'to_entries | .[] | .key')
#遍历band的值
for band in $bands; do
# band_format=$(echo "$band" | sed 's/-/_/g')
local value=$(echo "$network_prefer_2g" | jq -r '.band'"[$i].$band")
[ "$value" = "1" ] && {
#获取bit位
local bit=$(huawei_get_bit ${band})
#获取值
local result=$(echo "obase=16; ibase=10; 2^($bit-1)" | bc)
band_hex_2g_3g=$(echo "obase=16; ibase=16; $band_hex_2g_3g + $result" | bc)
}
i=$((i+1))
done
}
[ -z "$network_prefer_config" ] && network_prefer_config="99"
#设置模组
at_command='AT^SYSCFGEX="'${network_prefer_config}'",'"${band_hex_2g_3g},1,2,${band_hex_4g_5g},,"
sh ${SCRIPT_DIR}/modem_at.sh "${at_port}" "${at_command}"
}
#获取电压
# $1:AT串口
huawei_get_voltage()
{
local at_port="$1"
# #Voltage电压
# at_command="AT+ADCREAD=0"
# local voltage=$(sh ${SCRIPT_DIR}/modem_at.sh $at_port $at_command | grep "+ADCREAD:" | awk -F' ' '{print $2}' | sed 's/\r//g')
# voltage=$(awk "BEGIN{ printf \"%.2f\", $voltage / 1000000 }" | sed 's/\.*0*$//')
# echo "${voltage}"
}
#获取温度
# $1:AT串口
huawei_get_temperature()
{
local at_port="$1"
#Temperature温度
at_command="AT^CHIPTEMP?"
response=$(sh ${SCRIPT_DIR}/modem_at.sh $at_port $at_command | grep "\^CHIPTEMP" | awk -F',' '{print $6}' | sed 's/\r//g')
local temperature
if [ -n "$response" ]; then
response=$(awk "BEGIN{ printf \"%.2f\", $response / 10 }" | sed 's/\.*0*$//')
temperature="${response}$(printf "\xc2\xb0")C"
else
temperature="NaN $(printf "\xc2\xb0")C"
fi
echo "${temperature}"
}
#获取连接状态
# $1:AT串口
# $2:连接定义
huawei_get_connect_status()
{
local at_port="$1"
local define_connect="$2"
#默认值为1
[ -z "$define_connect" ] && {
define_connect="1"
}
at_command="AT+CGPADDR=${define_connect}"
local ipv4=$(sh ${SCRIPT_DIR}/modem_at.sh ${at_port} ${at_command} | grep "+CGPADDR: " | awk -F'"' '{print $2}')
local not_ip="0.0.0.0"
#设置连接状态
local connect_status
if [ -z "$ipv4" ] || [[ "$ipv4" = *"$not_ip"* ]]; then
connect_status="disconnect"
else
connect_status="connect"
fi
echo "${connect_status}"
}
#基本信息
huawei_base_info()
{
debug "Huawei base info"
#Name名称
at_command="AT+CGMM"
name=$(sh ${SCRIPT_DIR}/modem_at.sh $at_port $at_command | grep "+CGMM: " | awk -F': ' '{print $2}' | sed 's/\r//g')
#Manufacturer制造商
at_command="AT+CGMI"
manufacturer=$(sh ${SCRIPT_DIR}/modem_at.sh $at_port $at_command | sed -n '2p' | sed 's/\r//g')
#Revision固件版本
at_command="AT+CGMR"
revision=$(sh ${SCRIPT_DIR}/modem_at.sh $at_port $at_command | sed -n '2p' | sed 's/\r//g')
#Mode拨号模式
mode=$(huawei_get_mode ${at_port} ${platform} | tr 'a-z' 'A-Z')
#Temperature温度
temperature=$(huawei_get_temperature ${at_port})
}
#获取SIM卡状态
# $1:SIM卡状态标志
huawei_get_sim_status()
{
local sim_status
case $1 in
"") sim_status="miss" ;;
*"ERROR"*) sim_status="miss" ;;
*"READY"*) sim_status="ready" ;;
*"SIM PIN"*) sim_status="MT is waiting SIM PIN to be given" ;;
*"SIM PUK"*) sim_status="MT is waiting SIM PUK to be given" ;;
*"PH-FSIM PIN"*) sim_status="MT is waiting phone-to-SIM card password to be given" ;;
*"PH-FSIM PIN"*) sim_status="MT is waiting phone-to-very first SIM card password to be given" ;;
*"PH-FSIM PUK"*) sim_status="MT is waiting phone-to-very first SIM card unblocking password to be given" ;;
*"SIM PIN2"*) sim_status="MT is waiting SIM PIN2 to be given" ;;
*"SIM PUK2"*) sim_status="MT is waiting SIM PUK2 to be given" ;;
*"PH-NET PIN"*) sim_status="MT is waiting network personalization password to be given" ;;
*"PH-NET PUK"*) sim_status="MT is waiting network personalization unblocking password to be given" ;;
*"PH-NETSUB PIN"*) sim_status="MT is waiting network subset personalization password to be given" ;;
*"PH-NETSUB PUK"*) sim_status="MT is waiting network subset personalization unblocking password to be given" ;;
*"PH-SP PIN"*) sim_status="MT is waiting service provider personalization password to be given" ;;
*"PH-SP PUK"*) sim_status="MT is waiting service provider personalization unblocking password to be given" ;;
*"PH-CORP PIN"*) sim_status="MT is waiting corporate personalization password to be given" ;;
*"PH-CORP PUK"*) sim_status="MT is waiting corporate personalization unblocking password to be given" ;;
*) sim_status="unknown" ;;
esac
echo "${sim_status}"
}
#SIM卡信息
huawei_sim_info()
{
debug "Huawei sim info"
#SIM SlotSIM卡卡槽
# at_command="AT^SIMSLOT?"
# response=$(sh ${SCRIPT_DIR}/modem_at.sh ${at_port} ${at_command} | grep "\^SIMSLOT:" | awk -F': ' '{print $2}' | awk -F',' '{print $2}')
# if [ "$response" != "0" ]; then
# sim_slot="1"
# else
# sim_slot="2"
# fi
sim_slot="1"
#IMEI国际移动设备识别码
at_command="AT+CGSN"
imei=$(sh ${SCRIPT_DIR}/modem_at.sh ${at_port} ${at_command} | sed -n '2p' | sed 's/\r//g')
#SIM StatusSIM状态
at_command="AT+CPIN?"
sim_status_flag=$(sh ${SCRIPT_DIR}/modem_at.sh ${at_port} ${at_command} | grep "+CPIN: ")
sim_status=$(huawei_get_sim_status "$sim_status_flag")
if [ "$sim_status" != "ready" ]; then
return
fi
#ISP互联网服务提供商
at_command="AT+COPS?"
isp=$(sh ${SCRIPT_DIR}/modem_at.sh ${at_port} ${at_command} | grep "+COPS" | awk -F'"' '{print $2}')
# if [ "$isp" = "CHN-CMCC" ] || [ "$isp" = "CMCC" ]|| [ "$isp" = "46000" ]; then
# isp="中国移动"
# elif [ "$isp" = "CHN-UNICOM" ] || [ "$isp" = "UNICOM" ] || [ "$isp" = "46001" ]; then
# isp="中国联通"
# elif [ "$isp" = "CHN-CT" ] || [ "$isp" = "CT" ] || [ "$isp" = "46011" ]; then
# isp="中国电信"
# fi
#SIM NumberSIM卡号码手机号
at_command="AT+CNUM"
sim_number=$(sh ${SCRIPT_DIR}/modem_at.sh ${at_port} ${at_command} | grep "+CNUM: " | awk -F'"' '{print $2}')
[ -z "$sim_number" ] && {
sim_number=$(sh ${SCRIPT_DIR}/modem_at.sh ${at_port} ${at_command} | grep "+CNUM: " | awk -F'"' '{print $4}')
}
#IMSI国际移动用户识别码
at_command="AT+CIMI"
imsi=$(sh ${SCRIPT_DIR}/modem_at.sh $at_port $at_command | sed -n '2p' | sed 's/\r//g')
#ICCID集成电路卡识别码
at_command="AT+ICCID"
iccid=$(sh ${SCRIPT_DIR}/modem_at.sh ${at_port} ${at_command} | grep -o "+ICCID:[ ]*[-0-9]\+" | grep -o "[-0-9]\{1,4\}")
}
#获取网络类型
# $1:网络类型数字
huawei_get_rat()
{
local rat
case $1 in
"0"|"1"|"3"|"8") rat="GSM" ;;
"2"|"4"|"5"|"6"|"9"|"10") rat="WCDMA" ;;
"7") rat="LTE" ;;
"11"|"12") rat="NR" ;;
esac
echo "${rat}"
}
#获取信号强度指示4G
# $1:信号强度指示数字
huawei_get_rssi()
{
local rssi
case $1 in
"99") rssi="unknown" ;;
* ) rssi=$((2 * $1 - 113)) ;;
esac
echo "$rssi"
}
#网络信息
huawei_network_info()
{
debug "Huawei network info"
#Connect Status连接状态
connect_status=$(huawei_get_connect_status ${at_port} ${define_connect})
if [ "$connect_status" != "connect" ]; then
return
fi
#Network Type网络类型
at_command="AT^SYSINFOEX"
network_type=$(sh ${SCRIPT_DIR}/modem_at.sh ${at_port} ${at_command} | grep "\^SYSINFOEX:" | awk -F'"' '{print $4}')
[ -z "$network_type" ] && {
at_command='AT+COPS?'
local rat_num=$(sh ${SCRIPT_DIR}/modem_at.sh ${at_port} ${at_command} | grep "+COPS:" | awk -F',' '{print $4}' | sed 's/\r//g')
network_type=$(huawei_get_rat ${rat_num})
}
#设置网络类型为5G时信号强度指示用RSRP代替
# at_command="AT+GTCSQNREN=1"
# sh ${SCRIPT_DIR}/modem_at.sh $at_port $at_command
#CSQ信号强度
at_command="AT+CSQ"
response=$(sh ${SCRIPT_DIR}/modem_at.sh $at_port $at_command | grep "+CSQ:" | sed 's/+CSQ: //g' | sed 's/\r//g')
#RSSI4G信号强度指示
# rssi_num=$(echo $response | awk -F',' '{print $1}')
# rssi=$(huawei_get_rssi $rssi_num)
#BER4G信道误码率
# ber=$(echo $response | awk -F',' '{print $2}')
# #PER信号强度
# if [ -n "$csq" ]; then
# per=$(($csq * 100/31))"%"
# fi
#AMBR最大比特率
at_command="AT^DHCP?"
response=$(sh ${SCRIPT_DIR}/modem_at.sh $at_port $at_command | grep "\^DHCP:" | sed 's/\^DHCP: //g' | sed 's/\r//g')
ambr_ul_tmp=$(echo "$response" | awk -F',' '{print $8}')
ambr_dl_tmp=$(echo "$response" | awk -F',' '{print $7}')
[ -z "$ambr_ul_tmp" ] && {
at_command="AT^DHCPV6?"
response=$(sh ${SCRIPT_DIR}/modem_at.sh $at_port $at_command | grep "\^DHCPV6:" | sed 's/\^DHCPV6: //g' | sed 's/\r//g')
ambr_ul_tmp=$(echo "$response" | awk -F',' '{print $8}')
ambr_dl_tmp=$(echo "$response" | awk -F',' '{print $7}')
}
#AMBR UL上行签约速率单位Mbps
ambr_ul=$(awk "BEGIN{ printf \"%.2f\", $ambr_ul_tmp / 1000000 }" | sed 's/\.*0*$//')
#AMBR DL下行签约速率单位Mbps
ambr_dl=$(awk "BEGIN{ printf \"%.2f\", $ambr_dl_tmp / 1000000 }" | sed 's/\.*0*$//')
# #速率统计
# at_command='AT^DSFLOWQRY'
# response=$(sh ${SCRIPT_DIR}/modem_at.sh $at_port $at_command | grep "\^DSFLOWRPT:" | sed 's/\^DSFLOWRPT: //g' | sed 's/\r//g')
# #当前上传速率单位Byte/s
# tx_rate=$(echo $response | awk -F',' '{print $1}')
# #当前下载速率单位Byte/s
# rx_rate=$(echo $response | awk -F',' '{print $2}')
}
#获取NR子载波间隔
# $1:NR子载波间隔数字
huawei_get_scs()
{
local scs
case $1 in
"0") scs="15" ;;
"1") scs="30" ;;
"2") scs="60" ;;
"3") scs="120" ;;
"4") scs="240" ;;
*) scs=$(awk "BEGIN{ print 2^$1 * 15 }") ;;
esac
echo "$scs"
}
#获取频段
# $1:网络类型
# $2:频段数字
huawei_get_band()
{
local band
case $1 in
"GSM")
case $2 in
"0") band="850" ;;
"1") band="900" ;;
"2") band="1800" ;;
"3") band="1900" ;;
esac
;;
"WCDMA") band="$2" ;;
"LTE") band="$(($2-100))" ;;
"NR") band="$2" band="${band#*50}" ;;
esac
echo "$band"
}
#小区信息
huawei_cell_info()
{
debug "Huawei cell info"
at_command="AT^MONSC"
response=$(sh ${SCRIPT_DIR}/modem_at.sh $at_port $at_command | grep "\^MONSC:" | sed 's/\^MONSC: //')
local rat=$(echo "$response" | awk -F',' '{print $1}')
case $rat in
"NR")
network_mode="NR5G-SA Mode"
nr_mcc=$(echo "$response" | awk -F',' '{print $2}')
nr_mnc=$(echo "$response" | awk -F',' '{print $3}')
nr_arfcn=$(echo "$response" | awk -F',' '{print $4}')
nr_scs_num=$(echo "$response" | awk -F',' '{print $5}')
nr_scs=$(huawei_get_scs ${nr_scs_num})
nr_cell_id=$(echo "$response" | awk -F',' '{print $6}')
nr_physical_cell_id=$(echo "$response" | awk -F',' '{print $7}')
nr_tac=$(echo "$response" | awk -F',' '{print $8}')
nr_rsrp=$(echo "$response" | awk -F',' '{print $9}')
nr_rsrq=$(echo "$response" | awk -F',' '{print $10}')
nr_sinr=$(echo "$response" | awk -F',' '{print $11}' | sed 's/\r//g')
;;
"LTE-NR")
network_mode="EN-DC Mode"
#LTE
endc_lte_mcc=$(echo "$response" | awk -F',' '{print $2}')
endc_lte_mnc=$(echo "$response" | awk -F',' '{print $3}')
endc_lte_earfcn=$(echo "$response" | awk -F',' '{print $4}')
endc_lte_cell_id=$(echo "$response" | awk -F',' '{print $5}')
endc_lte_physical_cell_id=$(echo "$response" | awk -F',' '{print $6}')
endc_lte_tac=$(echo "$response" | awk -F',' '{print $7}')
endc_lte_rsrp=$(echo "$response" | awk -F',' '{print $8}')
endc_lte_rsrq=$(echo "$response" | awk -F',' '{print $9}')
endc_lte_rxlev=$(echo "$response" | awk -F',' '{print $10}' | sed 's/\r//g')
#NR5G-NSA
endc_nr_mcc=$(echo "$response" | awk -F',' '{print $2}')
endc_nr_mnc=$(echo "$response" | awk -F',' '{print $3}')
endc_nr_arfcn=$(echo "$response" | awk -F',' '{print $4}')
endc_nr_scs_num=$(echo "$response" | awk -F',' '{print $5}')
endc_nr_scs=$(huawei_get_scs ${nr_scs_num})
endc_nr_cell_id=$(echo "$response" | awk -F',' '{print $6}')
endc_nr_physical_cell_id=$(echo "$response" | awk -F',' '{print $7}')
endc_nr_tac=$(echo "$response" | awk -F',' '{print $8}')
endc_nr_rsrp=$(echo "$response" | awk -F',' '{print $9}')
endc_nr_rsrq=$(echo "$response" | awk -F',' '{print $10}')
endc_nr_sinr=$(echo "$response" | awk -F',' '{print $11}' | sed 's/\r//g')
;;
"LTE"|"eMTC"|"NB-IoT")
network_mode="LTE Mode"
lte_mcc=$(echo "$response" | awk -F',' '{print $2}')
lte_mnc=$(echo "$response" | awk -F',' '{print $3}')
lte_earfcn=$(echo "$response" | awk -F',' '{print $4}')
lte_cell_id=$(echo "$response" | awk -F',' '{print $5}')
lte_physical_cell_id=$(echo "$response" | awk -F',' '{print $6}')
lte_tac=$(echo "$response" | awk -F',' '{print $7}')
lte_rsrp=$(echo "$response" | awk -F',' '{print $8}')
lte_rsrq=$(echo "$response" | awk -F',' '{print $9}')
lte_rxlev=$(echo "$response" | awk -F',' '{print $10}' | sed 's/\r//g')
;;
"WCDMA"|"TD-SCDMA"|"UMTS")
network_mode="WCDMA Mode"
wcdma_mcc=$(echo "$response" | awk -F',' '{print $2}')
wcdma_mnc=$(echo "$response" | awk -F',' '{print $3}')
wcdma_arfcn=$(echo "$response" | awk -F',' '{print $4}')
wcdma_psc=$(echo "$response" | awk -F',' '{print $5}')
wcdma_cell_id=$(echo "$response" | awk -F',' '{print $6}')
wcdma_lac=$(echo "$response" | awk -F',' '{print $7}')
wcdma_rscp=$(echo "$response" | awk -F',' '{print $8}')
wcdma_rxlev=$(echo "$response" | awk -F',' '{print $9}')
wcdma_ecn0=$(echo "$response" | awk -F',' '{print $10}')
wcdma_drx=$(echo "$response" | awk -F',' '{print $11}')
wcdma_ura=$(echo "$response" | awk -F',' '{print $12}' | sed 's/\r//g')
;;
"GSM")
network_mode="GSM Mode"
gsm_mcc=$(echo "$response" | awk -F',' '{print $2}')
gsm_mnc=$(echo "$response" | awk -F',' '{print $3}')
gsm_band_num=$(echo "$response" | awk -F',' '{print $4}')
gsm_band=$(huawei_get_band "GSM" ${gsm_band_num})
gsm_arfcn=$(echo "$response" | awk -F',' '{print $5}')
gsm_bsic=$(echo "$response" | awk -F',' '{print $6}')
gsm_cell_id=$(echo "$response" | awk -F',' '{print $7}')
gsm_lac=$(echo "$response" | awk -F',' '{print $8}')
gsm_rxlev=$(echo "$response" | awk -F',' '{print $9}')
gsm_rx_quality=$(echo "$response" | awk -F',' '{print $10}')
gsm_ta=$(echo "$response" | awk -F',' '{print $11}' | sed 's/\r//g')
;;
esac
}
#获取华为模组信息
# $1:AT串口
# $2:平台
# $3:连接定义
get_huawei_info()
{
debug "get huawei info"
#设置AT串口
at_port="$1"
platform="$2"
define_connect="$3"
#基本信息
huawei_base_info
#SIM卡信息
huawei_sim_info
if [ "$sim_status" != "ready" ]; then
return
fi
#网络信息
huawei_network_info
if [ "$connect_status" != "connect" ]; then
return
fi
#小区信息
huawei_cell_info
}

View File

@ -35,7 +35,7 @@ meig_get_dns()
#获取DNS地址
at_command="AT+CGCONTRDP=${define_connect}"
local response=$(at ${at_port} ${at_command} | grep "+CGCONTRDP: " | grep -E '[0-9]+.[0-9]+.[0-9]+.[0-9]+' | sed -n '1p')
local response=$(sh ${SCRIPT_DIR}/modem_at.sh ${at_port} ${at_command} | grep "+CGCONTRDP: " | grep -E '[0-9]+.[0-9]+.[0-9]+.[0-9]+' | sed -n '1p')
local ipv4_dns1=$(echo "${response}" | awk -F',' '{print $7}' | awk -F' ' '{print $1}')
[ -z "$ipv4_dns1" ] && {
@ -161,28 +161,122 @@ meig_set_mode()
sh ${SCRIPT_DIR}/modem_at.sh ${at_port} "${at_command}"
}
#获取位
# $1:频段名称
meig_get_bit()
{
local band_name="$1"
local bit
case "$band_name" in
"DCS_1800") bit="8" ;;
"E-GSM_900") bit="9" ;;
"P-GSM_900") bit="10" ;;
"GSM_450") bit="17" ;;
"GSM_480") bit="18" ;;
"GSM_750") bit="19" ;;
"GSM_850") bit="20" ;;
"R-GSM_900") bit="21" ;;
"PCS_1900") bit="22" ;;
esac
echo "${bit}"
}
#获取频段信息
# $1:频段二进制数
# $2:支持的频段
# $3:频段类型2G3G4G5G
meig_get_band_info()
{
local band_bin="$1"
local support_band="$2"
local band_type="$3"
local band_info=""
local support_band=$(echo "$support_band" | sed 's/,/ /g')
if [ "$band_type" = "2G" ]; then
for band in $support_band; do
#获取bit位
local bit=$(meig_get_bit ${band})
#获取值
local enable="${band_bin: $((-bit)):1}"
[ -z "$enable" ] && enable="0"
#设置频段信息
# band_info=$(echo ${band_info} | jq '. += [{"'$band'":'$enable'}]')
band_info="${band_info},{\"$band\":$enable}"
done
else
#频段频段起始,前缀位置
local start_bit
local band_prefix
case "$band_type" in
"3G")
start_bit="23"
band_prefix="WCDMA_B"
;;
"4G")
start_bit="1"
band_prefix="LTE_BC"
;;
"5G")
start_bit="1"
band_prefix="NR5G_N"
;;
esac
for band in $support_band; do
#获取值从start_bit位开始
local enable="${band_bin: $((-band-start_bit+1)):1}"
[ -z "$enable" ] && enable="0"
#设置频段信息
# band_info=$(echo ${band_info} | jq '. += [{'$band_prefix$band':'$enable'}]')
band_info="${band_info},{\"$band_prefix$band\":$enable}"
done
fi
#去掉第一个,
band_info="["${band_info/,/}"]"
# band_info="[${band_info%?}]"
echo "${band_info}"
}
#获取网络偏好
# $1:AT串口
# $2:数据接口
# $3:模组名称
meig_get_network_prefer()
{
local at_port="$1"
local data_interface="$2"
local modem_name="$3"
at_command="AT^SYSCFGEX?"
local response=$(sh ${SCRIPT_DIR}/modem_at.sh ${at_port} ${at_command} | grep "\^SYSCFGEX:" | awk -F'"' '{print $2}')
local response=$(sh ${SCRIPT_DIR}/modem_at.sh ${at_port} ${at_command} | grep "\^SYSCFGEX:" | sed 's/\^SYSCFGEX://g')
local network_type_num=$(echo "$response" | awk -F'"' '{print $2}')
#获取网络类型
local network_prefer_2g="0";
local network_prefer_3g="0";
local network_prefer_4g="0";
local network_prefer_5g="0";
#匹配不同的网络类型
local auto=$(echo "${response}" | grep "00")
local auto=$(echo "${network_type_num}" | grep "00")
if [ -n "$auto" ]; then
network_prefer_2g="1"
network_prefer_3g="1"
network_prefer_4g="1"
network_prefer_5g="1"
else
local wcdma=$(echo "${response}" | grep "02")
local lte=$(echo "${response}" | grep "03")
local nr=$(echo "${response}" | grep "04")
local gsm=$(echo "${network_type_num}" | grep "01")
local wcdma=$(echo "${network_type_num}" | grep "02")
local lte=$(echo "${network_type_num}" | grep "03")
local nr=$(echo "${network_type_num}" | grep "04")
if [ -n "$gsm" ]; then
network_prefer_2g="1"
fi
if [ -n "$wcdma" ]; then
network_prefer_3g="1"
fi
@ -194,14 +288,58 @@ meig_get_network_prefer()
fi
fi
#获取模组信息
local modem_info=$(jq '.modem_support.'$data_interface'."'$modem_name'"' ${SCRIPT_DIR}/modem_support.json)
#获取模组支持的频段
local support_2g_band=$(echo "$modem_info" | jq -r '.band_2g')
local support_3g_band=$(echo "$modem_info" | jq -r '.band_3g')
local support_4g_band=$(echo "$modem_info" | jq -r '.band_4g')
local support_5g_band=$(echo "$modem_info" | jq -r '.band_5g')
#获取2G3G频段信息
local band_hex_2g_3g=$(echo "$response" | awk -F',' '{print $2}')
#十六进制转二进制
local bin_2g_3g=$(echo "obase=2; ibase=16; $band_hex_2g_3g" | bc)
local band_2g_info=$(meig_get_band_info "${bin_2g_3g}" "${support_2g_band}" "2G")
local band_3g_info=$(meig_get_band_info "${bin_2g_3g}" "${support_3g_band}" "3G")
#获取4G频段信息
local band_hex_4g_1=$(echo "$response" | awk -F',' '{print $5}' | sed 's/\r//g')
local band_hex_4g_2=$(echo "$response" | awk -F',' '{print $7}' | sed 's/\r//g')
#十六进制转二进制
local bin_4g=$(echo "obase=2; ibase=16; $band_hex_4g_1 + $band_hex_4g_2" | bc)
local band_4g_info=$(meig_get_band_info "${bin_4g}" "${support_4g_band}" "4G")
#获取5G频段信息
local band_hex_5g_1=$(echo "$response" | awk -F',' '{print $8}' | sed 's/\r//g')
local band_hex_5g_2=$(echo "$response" | awk -F',' '{print $9}' | sed 's/\r//g')
#十六进制转二进制
local bin_5g=$(echo "obase=2; ibase=16; $band_hex_5g_1 + $band_hex_5g_2" | bc)
local band_5g_info=$(meig_get_band_info "${bin_5g}" "${support_5g_band}" "5G")
#生成网络偏好
local network_prefer="{
\"network_prefer\":{
\"3G\":$network_prefer_3g,
\"4G\":$network_prefer_4g,
\"5G\":$network_prefer_5g
}
\"network_prefer\":[
{\"2G\":{
\"enable\":$network_prefer_2g,
\"band\":$band_2g_info
}},
{\"3G\":{
\"enable\":$network_prefer_3g,
\"band\":$band_3g_info
}},
{\"4G\":{
\"enable\":$network_prefer_4g,
\"band\":$band_4g_info
}},
{\"5G\":{
\"enable\":$network_prefer_5g,
\"band\":$band_5g_info
}}
]
}"
echo "$network_prefer"
echo "${network_prefer}"
}
#设置网络偏好
@ -215,35 +353,18 @@ meig_set_network_prefer()
#获取网络偏好配置
local network_prefer_config
#获取选中的数量
local count=$(echo "$network_prefer" | grep -o "1" | wc -l)
#获取每个偏好的值
local network_prefer_3g=$(echo "$network_prefer" | jq -r '.["3G"]')
local network_prefer_4g=$(echo "$network_prefer" | jq -r '.["4G"]')
local network_prefer_5g=$(echo "$network_prefer" | jq -r '.["5G"]')
#获取启用的网络偏好
local enable_5g=$(echo "$network_prefer" | jq -r '.["5G"].enable')
local enable_4g=$(echo "$network_prefer" | jq -r '.["4G"].enable')
local enable_3g=$(echo "$network_prefer" | jq -r '.["3G"].enable')
case "$count" in
"1")
if [ "$network_prefer_3g" = "1" ]; then
network_prefer_config="02"
elif [ "$network_prefer_4g" = "1" ]; then
network_prefer_config="03"
elif [ "$network_prefer_5g" = "1" ]; then
network_prefer_config="04"
fi
;;
"2")
if [ "$network_prefer_3g" = "1" ] && [ "$network_prefer_4g" = "1" ]; then
network_prefer_config="0302"
elif [ "$network_prefer_3g" = "1" ] && [ "$network_prefer_5g" = "1" ]; then
network_prefer_config="0402"
elif [ "$network_prefer_4g" = "1" ] && [ "$network_prefer_5g" = "1" ]; then
network_prefer_config="0403"
fi
;;
"3") network_prefer_config="00" ;;
*) network_prefer_config="00" ;;
esac
#获取网络偏好配置
local network_prefer_config
[ "$enable_5g" = "1" ] && network_prefer_config="${network_prefer_config}04"
[ "$enable_4g" = "1" ] && network_prefer_config="${network_prefer_config}03"
[ "$enable_3g" = "1" ] && network_prefer_config="${network_prefer_config}02"
[ -z "$network_prefer_config" ] && network_prefer_config="00"
#设置模组
at_command='AT^SYSCFGEX="'${network_prefer_config}'",all,0,2,all,all,all,all,1'
@ -314,7 +435,7 @@ meig_get_connect_status()
#基本信息
meig_base_info()
{
debug "meig base info"
debug "Meig base info"
#Name名称
at_command="AT+CGMM"
@ -365,7 +486,7 @@ meig_get_sim_status()
#SIM卡信息
meig_sim_info()
{
debug "meig sim info"
debug "Meig sim info"
#SIM SlotSIM卡卡槽
at_command="AT^SIMSLOT?"
@ -517,7 +638,7 @@ meig_get_lte_ambr()
#网络信息
meig_network_info()
{
debug "meig network info"
debug "Meig network info"
#Connect Status连接状态
connect_status=$(meig_get_connect_status ${at_port} ${define_connect})

View File

@ -0,0 +1,94 @@
#!/bin/sh
# Copyright (C) 2023 Siriling <siriling@qq.com>
#脚本目录
SCRIPT_DIR="/usr/share/modem"
source "${SCRIPT_DIR}/modem_debug.sh"
#初始化模组频段
init_modem_band()
{
#2G
DCS_1800="-"
E-GSM_900="-"
P-GSM_900="-"
GSM_450="-"
GSM_480="-"
GSM_750="-"
GSM_850="-"
R-GSM_900="-"
PCS_1900="-"
#3G
#4G
B1="-"
B2="-"
B3="-"
B4="-"
B5="-"
B6="-"
B7="-"
B8="-"
B9="-"
B10="-"
B11="-"
B12="-"
B13="-"
B14="-"
B17="-"
B18="-"
B19="-"
B20="-"
B21="-"
B25="-"
B26="-"
B28="-"
B29="-"
B30="-"
B32="-"
B34="-"
B38="-"
B39="-"
B40="-"
B41="-"
B42="-"
B66="-"
B71="-"
#5G
N1="-"
N2="-"
N3="-"
N5="-"
N7="-"
N8="-"
N12="-"
N20="-"
N25="-"
N28="-"
N38="-"
N40="-"
N41="-"
N48="-"
N66="-"
N71="-"
N77="-"
N78="-"
N79="-"
}
#获取模组数据信息
# $1:AT串口
# $2:制造商
# $3:平台
# $4:连接定义
modem_band()
{
#初始化模组频段
debug "初始化模组频段"
init_modem_band
debug "初始化模组频段完成"
}
modem_band "$1" "$2" "$3" "$4"

View File

@ -7,6 +7,7 @@ SCRIPT_DIR="/usr/share/modem"
source "${SCRIPT_DIR}/quectel.sh"
source "${SCRIPT_DIR}/fibocom.sh"
source "${SCRIPT_DIR}/meig.sh"
source "${SCRIPT_DIR}/huawei.sh"
# source "${SCRIPT_DIR}/simcom.sh"
#调试开关

View File

@ -371,6 +371,7 @@ get_modem_info()
"fibocom") get_fibocom_info "${at_port}" "${platform}" "${define_connect}" ;;
"meig") get_meig_info "${at_port}" "${platform}" "${define_connect}" ;;
"simcom") get_simcom_info "${at_port}" "${platform}" "${define_connect}" ;;
"huawei") get_huawei_info "${at_port}" "${platform}" "${define_connect}" ;;
*) debug "未适配该模组" ;;
esac

View File

@ -24,13 +24,13 @@ reset_network_interface()
local interface_name_ipv6="wwan6_5g_${modem_no}"
#获取IPv4地址
at_command="AT+CGPADDR=${define_connect}"
local ipv4=$(at ${at_port} ${at_command} | grep "+CGPADDR: " | awk -F',' '{print $2}' | sed 's/"//g')
local at_command="AT+CGPADDR=${define_connect}"
local ipv4=$(at ${at_port} ${at_command} | grep "+CGPADDR: " | sed -n '1p' | awk -F',' '{print $2}' | sed 's/"//g')
#输出日志
# echo "[$(date +"%Y-%m-%d %H:%M:%S")] Get Modem new IPv4 address : ${ipv4}" >> "${MODEM_RUNDIR}/modem${modem_no}_dial.cache"
#获取DNS地址
dns=$(fibocom_get_dns ${at_port} ${define_connect})
local dns=$(fibocom_get_dns ${at_port} ${define_connect})
local ipv4_dns1=$(echo "${dns}" | jq -r '.dns.ipv4_dns1')
local ipv4_dns2=$(echo "${dns}" | jq -r '.dns.ipv4_dns2')
#输出日志
@ -117,13 +117,15 @@ ecm_dial()
# at "${at_port}" "${at_command}"
#拨号
at_command
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}"
elif [ "$manufacturer" = "meig" ]; then
at_command="AT^NDISDUP=${define_connect},1"
elif [ "$manufacturer" = "huawei" ]; then
at_command="AT^NDISDUP=${define_connect},1"
else
at_command='ATI'
fi
@ -150,10 +152,10 @@ rndis_dial()
local define_connect="$4"
local modem_no="$5"
#手动设置IP广和通FM350-GL
#手动拨号广和通FM350-GL
if [ "$manufacturer" = "fibocom" ] && [ "$platform" = "mediatek" ]; then
at_command="AT+CGACT=1,${define_connect}"
local at_command="AT+CGACT=1,${define_connect}"
#打印日志
dial_log "${at_command}" "${MODEM_RUNDIR}/modem${modem_no}_dial.cache"
#激活并拨号
@ -228,7 +230,7 @@ modem_network_task()
#网络连接检查
local at_command="AT+CGPADDR=${define_connect}"
local ipv4=$(at ${at_port} ${at_command} | grep "+CGPADDR: " | awk -F',' '{print $2}' | sed 's/"//g')
local ipv4=$(at ${at_port} ${at_command} | grep "+CGPADDR: " | sed -n '1p' | awk -F',' '{print $2}' | sed 's/"//g')
if [ -z "$ipv4" ]; then

View File

@ -55,7 +55,8 @@
"platform":"qualcomm",
"data_interface":"usb",
"define_connect":"1",
"modes":["qmi","gobinet","ecm","mbim","rndis","ncm"]
"modes":["qmi","gobinet","ecm","mbim","rndis","ncm"],
"band_5g":"1,2,3,5,7,8,12,20,25,28,38,40,41,48,66,71,77,78,79,257,258,260,261"
},
"rm502q-ae":{
"manufacturer_id":"2c7c",
@ -152,6 +153,18 @@
"data_interface":"usb",
"define_connect":"1",
"modes":["qmi","gobinet","ecm","rndis","ncm"]
},
"mh5000-31":{
"manufacturer_id":"12d1",
"manufacturer":"huawei",
"platform":"hisilicon",
"data_interface":"usb",
"define_connect":"1",
"modes":["ecm","ncm"],
"band_2g":"DCS_1800,E-GSM_900,P-GSM_900,GSM_850,R-GSM_900,PCS_1900",
"band_3g":"1,2,5,6,8,9,19",
"band_4g":"1,2,3,4,5,6,7,8,9,10,11,12,13,14,17,18,19,20,21,25,26,28,33,34,35,36,37,38,39,40,41,42,43",
"band_5g":"1,2,3,5,7,8,12,20,25,28,38,40,41,78,79"
}
},
"pcie":{
@ -258,6 +271,12 @@
"vendor_id":["2dee"],
"product_id":["4d57","4d58","4d59"]
}
},
"huawei":{
"hisilicon":{
"vendor_id":["12d1"],
"product_id":["15c3"]
}
}
}
}

View File

@ -83,6 +83,7 @@ m_modem_presets()
"fibocom") fibocom_presets ;;
"meig") meig_presets ;;
"simcom") simcom_presets ;;
"huawei") huawei_presets ;;
esac
}

View File

@ -30,7 +30,7 @@ quectel_get_dns()
#获取DNS地址
at_command="AT+GTDNS=${define_connect}"
local response=$(at ${at_port} ${at_command} | grep "+GTDNS: ")
local response=$(sh ${SCRIPT_DIR}/modem_at.sh ${at_port} ${at_command} | grep "+GTDNS: ")
local ipv4_dns1=$(echo "${response}" | awk -F'"' '{print $2}' | awk -F',' '{print $1}')
[ -z "$ipv4_dns1" ] && {
@ -174,12 +174,20 @@ quectel_set_mode()
#获取网络偏好
# $1:AT串口
# $2:数据接口
# $3:模组名称
quectel_get_network_prefer()
{
local at_port="$1"
local data_interface="$2"
local modem_name="$3"
at_command='AT+QNWPREFCFG="mode_pref"'
local response=$(sh ${SCRIPT_DIR}/modem_at.sh ${at_port} ${at_command} | grep "+QNWPREFCFG:" | awk -F',' '{print $2}' | sed 's/\r//g')
local response=$(sh ${SCRIPT_DIR}/modem_at.sh ${at_port} ${at_command} | grep "+QNWPREFCFG:" | sed 's/\r//g')
local network_type_num=$(echo "$response" | awk -F',' '{print $2}')
#获取网络类型
# local network_prefer_2g="0";
local network_prefer_3g="0";
local network_prefer_4g="0";
local network_prefer_5g="0";
@ -205,14 +213,30 @@ quectel_get_network_prefer()
fi
fi
#获取频段信息
# local band_2g_info="[]"
local band_3g_info="[]"
local band_4g_info="[]"
local band_5g_info="[]"
#生成网络偏好
local network_prefer="{
\"network_prefer\":{
\"3G\":$network_prefer_3g,
\"4G\":$network_prefer_4g,
\"5G\":$network_prefer_5g
}
\"network_prefer\":[
{\"3G\":{
\"enable\":$network_prefer_3g,
\"band\":$band_3g_info
}},
{\"4G\":{
\"enable\":$network_prefer_4g,
\"band\":$band_4g_info
}},
{\"5G\":{
\"enable\":$network_prefer_5g,
\"band\":$band_5g_info
}}
]
}"
echo "$network_prefer"
echo "${network_prefer}"
}
#设置网络偏好
@ -223,32 +247,32 @@ quectel_set_network_prefer()
local at_port="$1"
local network_prefer="$2"
#获取网络偏好配置
#获取网络偏好配置
local network_prefer_config
#获取选中的数量
local count=$(echo "$network_prefer" | grep -o "1" | wc -l)
#获取每个偏好的值
local network_prefer_3g=$(echo "$network_prefer" | jq -r '.["3G"]')
local network_prefer_4g=$(echo "$network_prefer" | jq -r '.["4G"]')
local network_prefer_5g=$(echo "$network_prefer" | jq -r '.["5G"]')
#获取启用的网络偏好
local enable_5g=$(echo "$network_prefer" | jq -r '.["5G"].enable')
local enable_4g=$(echo "$network_prefer" | jq -r '.["4G"].enable')
local enable_3g=$(echo "$network_prefer" | jq -r '.["3G"].enable')
case "$count" in
"1")
if [ "$network_prefer_3g" = "1" ]; then
if [ "$enable_3g" = "1" ]; then
network_prefer_config="WCDMA"
elif [ "$network_prefer_4g" = "1" ]; then
elif [ "$enable_4g" = "1" ]; then
network_prefer_config="LTE"
elif [ "$network_prefer_5g" = "1" ]; then
elif [ "$enable_5g" = "1" ]; then
network_prefer_config="NR5G"
fi
;;
"2")
if [ "$network_prefer_3g" = "1" ] && [ "$network_prefer_4g" = "1" ]; then
if [ "$enable_3g" = "1" ] && [ "$enable_4g" = "1" ]; then
network_prefer_config="WCDMA:LTE"
elif [ "$network_prefer_3g" = "1" ] && [ "$network_prefer_5g" = "1" ]; then
elif [ "$enable_3g" = "1" ] && [ "$enable_5g" = "1" ]; then
network_prefer_config="WCDMA:NR5G"
elif [ "$network_prefer_4g" = "1" ] && [ "$network_prefer_5g" = "1" ]; then
elif [ "$enable_4g" = "1" ] && [ "$enable_5g" = "1" ]; then
network_prefer_config="LTE:NR5G"
fi
;;
@ -934,7 +958,7 @@ quectel_cell_info()
esac
}
# SIMCOM获取基站信息
# Quectel获取基站信息
Quectel_Cellinfo()
{
# return