mirror of
https://github.com/coolsnowwolf/lede.git
synced 2025-04-16 04:13:31 +00:00
umbim: Fix typos, PIN check, IP config
Add pdptype param, for selecting IPv4, IPv6, or IPv4v6 Fix check for required PIN, only pin1 (SIM pin) matters Get IP config directly from modem, no need for DHCP Fix return value from proto_mbim_setup() Signed-off-by: Howard Chu <hyc@symas.com>
This commit is contained in:
parent
e3373ca72e
commit
0470e2a73d
@ -1,7 +1,7 @@
|
|||||||
include $(TOPDIR)/rules.mk
|
include $(TOPDIR)/rules.mk
|
||||||
|
|
||||||
PKG_NAME:=umbim
|
PKG_NAME:=umbim
|
||||||
PKG_RELEASE:=$(AUTORELEASE)
|
PKG_RELEASE:=2
|
||||||
|
|
||||||
PKG_SOURCE_PROTO:=git
|
PKG_SOURCE_PROTO:=git
|
||||||
PKG_SOURCE_URL=$(PROJECT_GIT)/project/umbim.git
|
PKG_SOURCE_URL=$(PROJECT_GIT)/project/umbim.git
|
||||||
|
@ -11,6 +11,7 @@ proto_mbim_init_config() {
|
|||||||
available=1
|
available=1
|
||||||
no_device=1
|
no_device=1
|
||||||
proto_config_add_string "device:device"
|
proto_config_add_string "device:device"
|
||||||
|
proto_config_add_string pdptype
|
||||||
proto_config_add_string apn
|
proto_config_add_string apn
|
||||||
proto_config_add_string pincode
|
proto_config_add_string pincode
|
||||||
proto_config_add_string delay
|
proto_config_add_string delay
|
||||||
@ -23,13 +24,24 @@ proto_mbim_init_config() {
|
|||||||
_proto_mbim_setup() {
|
_proto_mbim_setup() {
|
||||||
local interface="$1"
|
local interface="$1"
|
||||||
local tid=2
|
local tid=2
|
||||||
local ret
|
|
||||||
|
|
||||||
local device apn pincode delay $PROTO_DEFAULT_OPTIONS
|
local device pdptype apn pincode delay auth username password $PROTO_DEFAULT_OPTIONS
|
||||||
json_get_vars device apn pincode delay auth username password $PROTO_DEFAULT_OPTIONS
|
json_get_vars device pdptype apn pincode delay auth username password $PROTO_DEFAULT_OPTIONS
|
||||||
|
|
||||||
[ -n "$ctl_device" ] && device=$ctl_device
|
[ -n "$ctl_device" ] && device=$ctl_device
|
||||||
|
|
||||||
|
pdptype=$(echo "$pdptype" | awk '{print tolower($0)}')
|
||||||
|
case "$pdptype" in
|
||||||
|
ip )
|
||||||
|
pdptype="ipv4"
|
||||||
|
;;
|
||||||
|
ipv4 | ipv6 | ipv4v6 | ipv4-and-ipv6 )
|
||||||
|
;;
|
||||||
|
* )
|
||||||
|
pdptype="default"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
[ -n "$device" ] || {
|
[ -n "$device" ] || {
|
||||||
echo "mbim[$$]" "No control device specified"
|
echo "mbim[$$]" "No control device specified"
|
||||||
proto_notify_error "$interface" NO_DEVICE
|
proto_notify_error "$interface" NO_DEVICE
|
||||||
@ -82,11 +94,17 @@ _proto_mbim_setup() {
|
|||||||
tid=$((tid + 1))
|
tid=$((tid + 1))
|
||||||
|
|
||||||
echo "mbim[$$]" "Checking pin"
|
echo "mbim[$$]" "Checking pin"
|
||||||
umbim $DBG -n -t $tid -d $device pinstate || {
|
local pinstate="/var/run/mbim.$$.pinstate"
|
||||||
echo "mbim[$$]" "PIN required"
|
umbim $DBG -n -t $tid -d $device pinstate > "$pinstate" 2>&1 || {
|
||||||
proto_notify_error "$interface" PIN_FAILED
|
local pin
|
||||||
proto_block_restart "$interface"
|
pin=$(awk '$2=="pin:" {print $5}' "$pinstate")
|
||||||
return 1
|
# we only need pin1 (the SIM pin) to connect
|
||||||
|
[ "$pin" = "pin1" ] && {
|
||||||
|
echo "mbim[$$]" "PIN required"
|
||||||
|
proto_notify_error "$interface" PIN_FAILED
|
||||||
|
proto_block_restart "$interface"
|
||||||
|
return 1
|
||||||
|
}
|
||||||
}
|
}
|
||||||
tid=$((tid + 1))
|
tid=$((tid + 1))
|
||||||
|
|
||||||
@ -115,41 +133,89 @@ _proto_mbim_setup() {
|
|||||||
tid=$((tid + 1))
|
tid=$((tid + 1))
|
||||||
|
|
||||||
echo "mbim[$$]" "Connect to network"
|
echo "mbim[$$]" "Connect to network"
|
||||||
while ! umbim $DBG -n -t $tid -d $device connect "$apn" "$auth" "$username" "$password"; do
|
while ! umbim $DBG -n -t $tid -d $device connect "$pdptype:$apn" "$auth" "$username" "$password"; do
|
||||||
tid=$((tid + 1))
|
tid=$((tid + 1))
|
||||||
sleep 1;
|
sleep 1;
|
||||||
done
|
done
|
||||||
tid=$((tid + 1))
|
tid=$((tid + 1))
|
||||||
|
|
||||||
uci_set_state network $interface tid "$tid"
|
echo "mbim[$$]" "Connected, obtain IP address and configure interface"
|
||||||
|
local config="/var/run/mbim.$$.config"
|
||||||
|
umbim $DBG -n -t $tid -d $device config > "$config" || {
|
||||||
|
echo "mbim[$$]" "Failed to obtain IP address"
|
||||||
|
proto_notify_error "$interface" CONFIG_FAILED
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
tid=$((tid + 1))
|
||||||
|
|
||||||
echo "mbim[$$]" "Connected, starting DHCP"
|
|
||||||
proto_init_update "$ifname" 1
|
proto_init_update "$ifname" 1
|
||||||
|
proto_add_data
|
||||||
|
json_add_int tid $tid
|
||||||
|
proto_close_data
|
||||||
proto_send_update "$interface"
|
proto_send_update "$interface"
|
||||||
|
|
||||||
json_init
|
local ip_4 ip_6
|
||||||
json_add_string name "${interface}_4"
|
ip_4=$(awk '$1=="ipv4address:" {print $2}' "$config")
|
||||||
json_add_string ifname "@$interface"
|
ip_6=$(awk '$1=="ipv6address:" {print $2}' "$config")
|
||||||
json_add_string proto "dhcp"
|
[ -n "$ip_4" ] || [ -n "$ip_6" ] || {
|
||||||
proto_add_dynamic_defaults
|
echo "mbim[$$]" "Failed to obtain IP addresses"
|
||||||
json_close_object
|
proto_notify_error "$interface" CONFIG_FAILED
|
||||||
ubus call network add_dynamic "$(json_dump)"
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
json_init
|
proto_init_update "$ifname" 1
|
||||||
json_add_string name "${interface}_6"
|
proto_set_keep 1
|
||||||
json_add_string ifname "@$interface"
|
local ip mask gateway mtu dns dns_servers
|
||||||
json_add_string proto "dhcpv6"
|
|
||||||
json_add_string extendprefix 1
|
[ -n "$ip_4" ] && {
|
||||||
proto_add_dynamic_defaults
|
echo "mbim[$$]" "Configure IPv4 on $ifname"
|
||||||
ubus call network add_dynamic "$(json_dump)"
|
ip=${ip_4%%/*}
|
||||||
|
mask=${ip_4##*/}
|
||||||
|
gateway=$(awk '$1=="ipv4gateway:" {print $2}' "$config")
|
||||||
|
mtu=$(awk '$1=="ipv4mtu:" {print $2}' "$config")
|
||||||
|
[ "$mtu" ] && ip link set "$ifname" mtu "$mtu"
|
||||||
|
|
||||||
|
proto_add_ipv4_address "$ip" "$mask"
|
||||||
|
[ "$defaultroute" = 0 ] || proto_add_ipv4_route 0.0.0.0 0 "$gateway" "$ip_4" "$metric"
|
||||||
|
[ "$peerdns" = 0 ] || {
|
||||||
|
dns_servers=$(awk '$1=="ipv4dnsserver:" {printf "%s ",$2}' "$config")
|
||||||
|
for dns in $dns_servers; do
|
||||||
|
proto_add_dns_server "$dns"
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
[ -n "$ip_6" ] && {
|
||||||
|
echo "mbim[$$]" "Configure IPv6 on $ifname"
|
||||||
|
ip=${ip_6%%/*}
|
||||||
|
mask=${ip_6##*/}
|
||||||
|
gateway=$(awk '$1=="ipv6gateway:" {print $2}' "$config")
|
||||||
|
mtu=$(awk '$1=="ipv6mtu:" {print $2}' "$config")
|
||||||
|
[ "$mtu" ] && ip -6 link set "$ifname" mtu "$mtu"
|
||||||
|
|
||||||
|
proto_add_ipv6_address "$ip" "$mask"
|
||||||
|
proto_add_ipv6_prefix "$ip_6"
|
||||||
|
[ "$defaultroute" = 0 ] || proto_add_ipv6_route "::" 0 "$gateway" "$metric" "" "$ip_6"
|
||||||
|
[ "$peerdns" = 0 ] || {
|
||||||
|
dns_servers=$(awk '$1=="ipv6dnsserver:" {printf "%s ",$2}' "$config")
|
||||||
|
for dns in $dns_servers; do
|
||||||
|
proto_add_dns_server "$dns"
|
||||||
|
done
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
proto_send_update "$interface"
|
||||||
|
echo "mbim[$$]" "Connection setup complete"
|
||||||
}
|
}
|
||||||
|
|
||||||
proto_mbim_setup() {
|
proto_mbim_setup() {
|
||||||
local ret
|
local ret
|
||||||
|
|
||||||
_proto_mbim_setup $@
|
_proto_mbim_setup "$@"
|
||||||
ret=$?
|
ret=$?
|
||||||
|
|
||||||
|
rm -f "/var/run/mbim.$$."*
|
||||||
|
|
||||||
[ "$ret" = 0 ] || {
|
[ "$ret" = 0 ] || {
|
||||||
logger "mbim bringup failed, retry in 15s"
|
logger "mbim bringup failed, retry in 15s"
|
||||||
sleep 15
|
sleep 15
|
||||||
@ -161,17 +227,13 @@ proto_mbim_setup() {
|
|||||||
proto_mbim_teardown() {
|
proto_mbim_teardown() {
|
||||||
local interface="$1"
|
local interface="$1"
|
||||||
|
|
||||||
local device
|
local device tid
|
||||||
json_get_vars device
|
json_get_vars device tid
|
||||||
local tid=$(uci_get_state network $interface tid)
|
|
||||||
|
|
||||||
[ -n "$ctl_device" ] && device=$ctl_device
|
[ -n "$ctl_device" ] && device=$ctl_device
|
||||||
|
|
||||||
echo "mbim[$$]" "Stopping network"
|
echo "mbim[$$]" "Stopping network"
|
||||||
[ -n "$tid" ] && {
|
[ -n "$tid" ] && umbim $DBG -t$tid -d "$device" disconnect
|
||||||
umbim $DBG -t$tid -d "$device" disconnect
|
|
||||||
uci_revert_state network $interface tid
|
|
||||||
}
|
|
||||||
|
|
||||||
proto_init_update "*" 0
|
proto_init_update "*" 0
|
||||||
proto_send_update "$interface"
|
proto_send_update "$interface"
|
||||||
|
Loading…
Reference in New Issue
Block a user