2024-01-11 14:30:31 +08:00

123 lines
2.6 KiB
Bash
Executable File

#!/bin/sh /etc/rc.common
# Copyright (C) 2006-2014 OpenWrt.org
START=94
STOP=13
USE_PROCD=1
pre_set()
{
[ "$(uci get network.wwan_5g.ifname)" != "$1" ] && {
uci set network.wwan_5g='interface'
uci set network.wwan_5g.ifname="$1"
uci set network.wwan_5g.proto='dhcp'
if [ "$ipv6" = 1 ]; then
uci set network.wwan6_5g='interface'
uci set network.wwan6_5g.ifname="$1"
uci set network.wwan6_5g.proto='dhcpv6'
uci set network.wwan6_5g.extendprefix='1'
fi
uci commit network
num=`uci show firewall |grep "name='wan'" |wc -l`
wwan_5g_num=`uci get firewall.@zone[$num].network |grep -w wwan_5g |wc -l`
wwan6_5g_num=`uci get firewall.@zone[$num].network |grep -w wwan6_5g |wc -l`
if [ "$wwan_5g_num" = "0" ]; then
uci add_list firewall.@zone[$num].network='wwan_5g'
fi
if [ "$ipv6" = 1 ]; then
if [ "$wwan6_5g_num" = "0" ]; then
uci add_list firewall.@zone[$num].network='wwan6_5g'
fi
fi
uci commit firewall
ifup wwan_5g
if [ "$ipv6" = 1 ]; then
ifup wwan6_5g
fi
}
[ "$(uci get network.wwan6_5g.ifname)" = "$1" ] && {
uci set network.wwan6_5g.extendprefix='1'
uci commit network
}
}
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")"
devicepath="$(find /sys/class/ -name $devname)"
devpath="$(readlink -f $devicepath/device/)"
ifname="$( ls "$devpath"/net )"
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
}
service_triggers()
{
procd_add_reload_trigger "hypermodem"
}
start_service() {
config_load hypermodem
config_foreach run_dial service
}
stop_service()
{
killall quectel-CM >/dev/null 2>&1
}