698 lines
17 KiB
Bash
Executable File
698 lines
17 KiB
Bash
Executable File
#!/bin/sh /etc/rc.common
|
||
# Copyright (C) 2023 Siriling <siriling@qq.com>
|
||
|
||
START=90
|
||
STOP=13
|
||
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:拨号模式
|
||
# set_mode()
|
||
# {
|
||
# #获取AT串口、制造商、模块名
|
||
# local at_port=$(uci -q get modem.modem${modem_no}.at_port)
|
||
# local manufacturer=$(uci -q get modem.modem${modem_no}.manufacturer)
|
||
# local name=$(uci -q get modem.modem${modem_no}.name)
|
||
|
||
# #分制造商设置不同的AT命令
|
||
# local command
|
||
# if [ "$manufacturer" = "quectel" ]; then
|
||
# local mode_num
|
||
# case $1 in
|
||
# "qmi") mode_num='0' ;;
|
||
# "gobinet") mode_num='0' ;;
|
||
# "ecm") mode_num='1' ;;
|
||
# "mbim") mode_num='2' ;;
|
||
# "rndis") mode_num='3' ;;
|
||
# "ncm") mode_num='5' ;;
|
||
# *) mode_num='0' ;;
|
||
# esac
|
||
|
||
# #查询当前拨号模式
|
||
# command='AT+QCFG="usbnet"'
|
||
# local at_result=$(sh ${SCRIPT_DIR}/modem_at.sh $at_port $command)
|
||
# if [[ "$at_result" != *"$mode_num"* ]]; then
|
||
|
||
# #切换到指定的拨号模式
|
||
# case $1 in
|
||
# "qmi") command='AT+QCFG="usbnet",0' ;;
|
||
# "gobinet") command='AT+QCFG="usbnet",0' ;;
|
||
# "ecm") command='AT+QCFG="usbnet",1' ;;
|
||
# "mbim") command='AT+QCFG="usbnet",2' ;;
|
||
# "rndis") command='AT+QCFG="usbnet",3' ;;
|
||
# "ncm") command='AT+QCFG="usbnet",5' ;;
|
||
# *) command='AT+QCFG="usbnet",0' ;;
|
||
# esac
|
||
# at_result=$(sh ${SCRIPT_DIR}/modem_at.sh "$at_port" "$command")
|
||
# #移远切换模式后,还需要重启模块,待测试
|
||
# sleep 5
|
||
# modem_scan
|
||
# fi
|
||
# elif [ "$manufacturer" = "fibocom" ]; then
|
||
# if [ "$name" = "fm150-ae" ]; then
|
||
# local mode_num
|
||
# case $1 in
|
||
# "qmi") mode_num='32' ;;
|
||
# "gobinet") mode_num='32' ;;
|
||
# "ecm") mode_num='23' ;;
|
||
# "mbim") mode_num='29' ;;
|
||
# "rndis") mode_num='24' ;;
|
||
# "ncm") mode_num='23' ;;
|
||
# *) mode_num='32' ;;
|
||
# esac
|
||
|
||
# #查询当前拨号模式
|
||
# command='AT+GTUSBMODE?'
|
||
# local at_result=$(sh ${SCRIPT_DIR}/modem_at.sh $at_port $command)
|
||
# if [[ "$at_result" != *"$mode_num"* ]]; then
|
||
# #切换到指定的拨号模式
|
||
# case $1 in
|
||
# "qmi") command='AT+GTUSBMODE=32' ;;
|
||
# "gobinet") command='AT+GTUSBMODE=32' ;;
|
||
# "ecm") command='AT+GTUSBMODE=23' ;;
|
||
# "mbim") command='AT+GTUSBMODE=29' ;;
|
||
# "rndis") command='AT+GTUSBMODE=24' ;;
|
||
# "ncm") command='AT+GTUSBMODE=23' ;;
|
||
# *) command='AT+GTUSBMODE=32' ;;
|
||
# esac
|
||
# at_result=$(sh ${SCRIPT_DIR}/modem_at.sh "$at_port" "$command")
|
||
# sleep 5
|
||
# modem_scan
|
||
# fi
|
||
# elif [ "$name" = "fm650" ]; then
|
||
# #待处理
|
||
# echo "fm650"
|
||
# fi
|
||
# else
|
||
# #没有匹配到制造商,需要手动切换模块的拨号模式
|
||
# echo "请手动切换模块的拨号模式"
|
||
# fi
|
||
# }
|
||
|
||
#设置防火墙
|
||
# $1:网络接口名称
|
||
set_firewall()
|
||
{
|
||
local interface_name="$1"
|
||
|
||
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
|
||
uci add_list firewall.@zone[$num].network="${interface_name}"
|
||
fi
|
||
uci commit firewall
|
||
}
|
||
|
||
#设置IPv4网络接口
|
||
# $1:网络接口名称
|
||
# $2:网络接口
|
||
set_ipv4_interface()
|
||
{
|
||
local interface_name="$1"
|
||
local network_interface="$2"
|
||
|
||
#添加或修改网络配置
|
||
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防火墙
|
||
set_firewall "${interface_name}"
|
||
|
||
#启动网络接口
|
||
ifup "${interface_name}"
|
||
}
|
||
|
||
#设置IPv6网络接口
|
||
# $1:网络接口名称
|
||
# $2:网络接口
|
||
set_ipv6_interface()
|
||
{
|
||
local interface_name="$1"
|
||
local network_interface="$2"
|
||
|
||
#添加或修改网络配置
|
||
uci set network.${interface_name}='interface'
|
||
uci set network.${interface_name}.proto='dhcpv6'
|
||
uci set network.${interface_name}.extendprefix='1'
|
||
uci set network.${interface_name}.device="${network_interface}"
|
||
uci set network.${interface_name}.ifname="${network_interface}"
|
||
uci commit network
|
||
|
||
#加入WAN防火墙
|
||
set_firewall "${interface_name}"
|
||
|
||
#启动网络接口
|
||
ifup "${interface_name}"
|
||
}
|
||
|
||
#设置IPV4和IPv6网络接口
|
||
# $1:IPV4网络接口名称
|
||
# $2:IPv6网络接口名称
|
||
# $3:网络接口
|
||
set_ipv4v6_interface()
|
||
{
|
||
local ipv4_interface_name="$1"
|
||
local ipv6_interface_name="$2"
|
||
local network_interface="$3"
|
||
|
||
#设置IPV4网络接口
|
||
set_ipv4_interface "${ipv4_interface_name}" "${network_interface}"
|
||
#设置IPV6网络接口(别名)
|
||
set_ipv6_interface "${ipv6_interface_name}" "@${ipv4_interface_name}"
|
||
}
|
||
|
||
#设置网络接口
|
||
# $1:模块序号
|
||
# $2:网络接口
|
||
set_interface()
|
||
{
|
||
local modem_no="$1"
|
||
local network_interface="$2"
|
||
|
||
case $pdp_type in
|
||
"ipv4") set_ipv4_interface "wwan_5g_${modem_no}" "${network_interface}" ;;
|
||
"ipv6") set_ipv6_interface "wwan6_5g_${modem_no}" "${network_interface}" ;;
|
||
"ipv4v6") set_ipv4v6_interface "wwan_5g_${modem_no}" "wwan6_5g_${modem_no}" "${network_interface}" ;;
|
||
*) set_ipv4v6_interface "wwan_5g_${modem_no}" "wwan6_5g_${modem_no}" "${network_interface}" ;;
|
||
esac
|
||
}
|
||
|
||
#移远拨号工具
|
||
quectel_cm()
|
||
{
|
||
#拨号
|
||
procd_open_instance
|
||
procd_set_param command "quectel-CM"
|
||
|
||
case $pdp_type in
|
||
"ipv4") procd_append_param command "-4" ;;
|
||
"ipv6") procd_append_param command "-6" ;;
|
||
"ipv4v6") procd_append_param command "-4" "-6" ;;
|
||
*) procd_append_param command "-4" "-6" ;;
|
||
esac
|
||
|
||
if [ "$network_bridge" = "1" ]; then
|
||
procd_append_param command "-b"
|
||
fi
|
||
if [ "$apn" != "" ]; then
|
||
procd_append_param command "-s" "$apn"
|
||
fi
|
||
if [ "$username" != "" ]; then
|
||
procd_append_param command "$username"
|
||
fi
|
||
if [ "$password" != "" ]; then
|
||
procd_append_param command "$password"
|
||
fi
|
||
if [ "$auth" != "none" ]; then
|
||
procd_append_param command "$auth"
|
||
fi
|
||
if [ "$network" != "" ]; then
|
||
procd_append_param command "-i" "$network"
|
||
fi
|
||
#日志
|
||
procd_append_param command "-f" "${MODEM_RUNDIR}/modem${modem_no}_dial.cache"
|
||
|
||
procd_set_param respawn
|
||
procd_set_param procd_pid "${MODEM_RUNDIR}/modem${modem_no}.pid"
|
||
procd_close_instance
|
||
}
|
||
|
||
#设置网络接口(Modem Manager)
|
||
# $1:接口名称
|
||
# $2:模组路径
|
||
set_interface_modemmanager()
|
||
{
|
||
local interface_name="$1"
|
||
local path="$2"
|
||
|
||
if [ "$(uci -q get network.${interface_name}.device)" != "${path}" ] ; then
|
||
uci set network.${interface_name}='interface'
|
||
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
|
||
uci set network.${interface_name}.apn="$apn"
|
||
fi
|
||
if [ "$pincode" != "" ]; then
|
||
uci set network.${interface_name}.pincode="$pincode"
|
||
fi
|
||
if [ "$username" != "" ]; then
|
||
uci set network.${interface_name}.username="$username"
|
||
fi
|
||
if [ "$password" != "" ]; then
|
||
uci set network.${interface_name}.password="$password"
|
||
fi
|
||
|
||
uci commit network
|
||
|
||
#加入WAN防火墙
|
||
set_firewall "${interface_name}"
|
||
fi
|
||
|
||
#启动网络接口
|
||
ifup "${interface_name}"
|
||
}
|
||
|
||
#模块管理
|
||
modemmanager()
|
||
{
|
||
#获取接口名称
|
||
local interface_name="wwan_5g_${modem_no}"
|
||
#获取调制解调器设备(模组路径)
|
||
local path=$(uci -q get modem.modem${modem_no}.path)
|
||
#设置Modem Manager网络接口
|
||
set_interface_modemmanager "$interface_name" "$path"
|
||
|
||
#拨号
|
||
procd_open_instance
|
||
procd_set_param command sh ${SCRIPT_DIR}/modem_network_task.sh "${id}" "${modem_no}" "modemmanager"
|
||
procd_set_param respawn
|
||
procd_close_instance
|
||
}
|
||
|
||
qmi()
|
||
{
|
||
#设置网络接口
|
||
local network_interface=$(uci -q get modem.modem${modem_no}.network_interface)
|
||
set_interface "${modem_no}" "$network_interface"
|
||
|
||
#选择拨号工具
|
||
case $dial_tool in
|
||
"quectel-CM") quectel_cm ;;
|
||
"mmcli") modemmanager ;;
|
||
"") quectel_cm ;;
|
||
*) quectel_cm ;;
|
||
esac
|
||
}
|
||
|
||
gobinet()
|
||
{
|
||
#获取网络接口
|
||
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}" "gobinet"
|
||
procd_set_param respawn
|
||
procd_close_instance
|
||
}
|
||
|
||
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}" "ecm"
|
||
procd_set_param respawn
|
||
procd_close_instance
|
||
}
|
||
|
||
mbim()
|
||
{
|
||
qmi
|
||
}
|
||
|
||
rndis()
|
||
{
|
||
#获取网络接口
|
||
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()
|
||
{
|
||
ecm
|
||
}
|
||
|
||
stop_qmi()
|
||
{
|
||
#获取modem的实例信息
|
||
local response=$(ubus call service list '{"name": "modem"}')
|
||
local instance_number=$(echo "$response" | jq -r '.modem.instances | length')
|
||
for i in $(seq 1 $((instance_number))); do
|
||
#获取拨号命令
|
||
local command=$(echo "$response" | jq -r ".modem.instances.instance$i.command")
|
||
#移远拨号工具
|
||
if [[ "$command" = *"$network"* ]]; then
|
||
local pid=$(echo "$response" | jq -r ".modem.instances.$i.pid")
|
||
kill $pid >/dev/null 2>&1
|
||
fi
|
||
|
||
#Modem Manager
|
||
#获取接口名称
|
||
local interface_name="wwan_5g_${modem_no}"
|
||
if [[ "$command" = *"$interface_name"* ]]; then
|
||
local pid=$(echo "$response" | jq -r ".modem.instances.$i.pid")
|
||
kill $pid >/dev/null 2>&1
|
||
|
||
#获取调制解调器设备(模组路径)
|
||
local path=$(uci -q get modem.modem${modem_no}.path)
|
||
mmcli -m "$path" --simple-disconnect
|
||
#删除网络接口
|
||
uci -q del network.${interface_name}
|
||
uci commit network
|
||
fi
|
||
done
|
||
}
|
||
|
||
stop_gobinet()
|
||
{
|
||
#获取AT串口、制造商
|
||
local at_port=$(uci -q get modem.modem${modem_no}.at_port)
|
||
local manufacturer=$(uci -q get modem.modem${modem_no}.manufacturer)
|
||
|
||
#停止拨号
|
||
local at_command
|
||
if [ "$manufacturer" = "quectel" ]; then
|
||
at_command='ATI'
|
||
elif [ "$manufacturer" = "fibocom" ]; then
|
||
at_command='AT$QCRMCALL=0,1'
|
||
else
|
||
at_command='ATI'
|
||
fi
|
||
|
||
tmp=$(at "${at_port}" "${at_command}")
|
||
}
|
||
|
||
stop_ecm()
|
||
{
|
||
#获取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 at_command
|
||
if [ "$manufacturer" = "quectel" ]; then
|
||
at_command="AT+QNETDEVCTL=${define_connect},2,1"
|
||
elif [ "$manufacturer" = "fibocom" ]; then
|
||
#联发科平台(广和通FM350-GL)
|
||
if [ "$platform" = "mediatek" ]; then
|
||
at_command="AT+CGACT=0,${define_connect}"
|
||
else
|
||
at_command="AT+GTRNDIS=0,${define_connect}"
|
||
fi
|
||
else
|
||
at_command='ATI'
|
||
fi
|
||
|
||
tmp=$(at "${at_port}" "${at_command}")
|
||
}
|
||
|
||
stop_mbim()
|
||
{
|
||
stop_qmi
|
||
}
|
||
|
||
stop_rndis()
|
||
{
|
||
stop_ecm
|
||
#广和通的rndis和ecm不同,后续再测试
|
||
}
|
||
|
||
stop_ncm()
|
||
{
|
||
stop_ecm
|
||
}
|
||
|
||
#获取模块序号
|
||
# $1:移动网络
|
||
get_modem_no()
|
||
{
|
||
local modem_number=$(uci -q get modem.@global[0].modem_number)
|
||
local modem_network
|
||
for i in $(seq 0 $((modem_number-1))); do
|
||
modem_network=$(uci -q get modem.modem${i}.network)
|
||
if [ "$modem_network" = "$1" ]; then
|
||
#模块序号
|
||
modem_no=${i}
|
||
break
|
||
fi
|
||
done
|
||
}
|
||
|
||
#获取实例运行状态(未使用)
|
||
# $1:配置ID
|
||
get_instance_status()
|
||
{
|
||
local config_id="$1"
|
||
|
||
#获取modem的实例信息
|
||
local response=$(ubus call service list '{"name": "modem"}')
|
||
local instance_number=$(echo "$response" | jq -r ".modem.instances | length")
|
||
for i in $(seq 1 $((instance_number))); do
|
||
#获取运行状态和拨号命令
|
||
local running_status=$(echo "$response" | jq -r ".modem.instances.instance$i.running")
|
||
local command=$(echo "$response" | jq -r ".modem.instances.instance$i.command")
|
||
if [ "$running_status" = "true" ] && [[ "$command" = *"$network"* ]]; then
|
||
#查看配置ID是否记录在已运行的文件里
|
||
local run_config="/var/run/modem"
|
||
local run_config_id=$(grep -n "$network" "$run_config" | cut -d ',' -f 2)
|
||
if [ "${config_id}" = "$run_config_id" ]; then
|
||
status=2
|
||
break
|
||
else
|
||
status=1
|
||
break
|
||
fi
|
||
fi
|
||
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
|
||
stop_dial()
|
||
{
|
||
local id="$1" #配置ID
|
||
local network=$(uci -q get modem.$1.network) #移动网络
|
||
|
||
#把配置ID从临时列表中移除
|
||
if [ -f "${MODEM_RUN_CONFIG}" ] && grep -q "${network}" "${MODEM_RUN_CONFIG}"; then
|
||
#该配置ID在运行,需要删除记录
|
||
sed -i "/${id}/d" "${MODEM_RUN_CONFIG}"
|
||
else
|
||
return 0
|
||
fi
|
||
|
||
#获取模块序号
|
||
get_modem_no "${network}"
|
||
|
||
#获取模组的拨号模式
|
||
[ -z "${modem_no}" ] && return 0
|
||
local mode=$(get_mode ${modem_no})
|
||
[ -z "$mode" ] && return
|
||
|
||
#根据不同的拨号模式停止拨号
|
||
if [ "$mode" = "qmi" ]; then
|
||
stop_qmi
|
||
elif [ "$mode" = "gobinet" ]; then
|
||
stop_gobinet
|
||
elif [ "$mode" = "ecm" ]; then
|
||
stop_ecm
|
||
elif [ "$mode" = "mbim" ]; then
|
||
stop_mbim
|
||
elif [ "$mode" = "rndis" ]; then
|
||
stop_rndis
|
||
elif [ "$mode" = "ncm" ]; then
|
||
stop_ncm
|
||
fi
|
||
}
|
||
|
||
dial()
|
||
{
|
||
local enable #启用
|
||
local id #ID
|
||
|
||
config_get enable $1 enable
|
||
config_get id $1 id
|
||
[ "$enable" = "0" ] && {
|
||
stop_dial "$id"
|
||
return 0
|
||
}
|
||
|
||
local remarks #备注
|
||
local network #移动网络
|
||
local dial_tool #拨号工具
|
||
local pdp_type #网络类型(IP类型)
|
||
local network_bridge #网络桥接
|
||
local apn #接入点
|
||
local username #用户名
|
||
local password #密码
|
||
local auth #认证类型
|
||
|
||
config_get remarks $1 remarks
|
||
config_get network $1 network
|
||
config_get dial_tool $1 dial_tool
|
||
config_get pdp_type $1 pdp_type
|
||
config_get network_bridge $1 network_bridge
|
||
config_get apn $1 apn
|
||
config_get username $1 username
|
||
config_get password $1 password
|
||
config_get auth $1 auth
|
||
|
||
#获取模块序号
|
||
get_modem_no "${network}"
|
||
[ -z "${modem_no}" ] && return 0
|
||
|
||
#获取模组的拨号模式
|
||
local mode
|
||
while true; do
|
||
mode=$(get_mode ${modem_no})
|
||
if [ -n "$mode" ]; then
|
||
break
|
||
fi
|
||
sleep 5s
|
||
done
|
||
|
||
#查看移动网络是否已经有配置在运行
|
||
mkdir -m 0755 -p "${MODEM_RUNDIR}"
|
||
if [ -f "${MODEM_RUN_CONFIG}" ]; then #文件存在
|
||
if grep -q "${network}" "${MODEM_RUN_CONFIG}"; then #是否记录该移动网络
|
||
local config_id=$(awk -v network="${network}" -F',' '!/^#/ && $0 ~ network { print $2 }' "${MODEM_RUN_CONFIG}")
|
||
#该移动网络已存在,且已有其他配置运行
|
||
if [ "$id" != "$config_id" ]; then
|
||
uci set modem.$1.enable=0
|
||
uci commit modem
|
||
return 0
|
||
fi
|
||
else
|
||
echo "${network},${id}" >> "${MODEM_RUN_CONFIG}"
|
||
fi
|
||
else
|
||
echo "${network},${id}" >> "${MODEM_RUN_CONFIG}"
|
||
fi
|
||
|
||
#设置网络预设
|
||
connect_presets
|
||
|
||
#根据不同的拨号模式拨号
|
||
if [ "$mode" = "qmi" ]; then
|
||
qmi
|
||
elif [ "$mode" = "gobinet" ]; then
|
||
gobinet
|
||
elif [ "$mode" = "ecm" ]; then
|
||
ecm
|
||
elif [ "$mode" = "mbim" ]; then
|
||
mbim
|
||
elif [ "$mode" = "rndis" ]; then
|
||
rndis
|
||
elif [ "$mode" = "ncm" ]; then
|
||
ncm
|
||
fi
|
||
|
||
# sleep 15
|
||
}
|
||
|
||
service_triggers()
|
||
{
|
||
procd_add_reload_trigger "modem"
|
||
}
|
||
|
||
start_service() {
|
||
local enable=$(uci -q get modem.@global[0].enable)
|
||
if [ "$enable" = "0" ]; then
|
||
stop_service
|
||
else
|
||
config_load modem
|
||
config_foreach dial "config"
|
||
fi
|
||
}
|
||
|
||
stop_service()
|
||
{
|
||
#删除记录文件
|
||
rm -rf /tmp/modem
|
||
#停止qmi、mbim拨号
|
||
killall quectel-CM >/dev/null 2>&1
|
||
#停止gobinet、ecm、rndis、ncm拨号
|
||
local modem_number=$(uci -q get modem.@global[0].modem_number)
|
||
for i in $(seq 0 $((modem_number-1))); do
|
||
modem_no=$i
|
||
local mode=$(uci -q get modem.modem${modem_no}.mode)
|
||
case $mode in
|
||
"gobinet") stop_gobinet ;;
|
||
"ecm") stop_ecm ;;
|
||
"rndis") stop_rndis ;;
|
||
"ncm") stop_ncm ;;
|
||
*) stop_ecm ;;
|
||
esac
|
||
done
|
||
}
|