umbim/uqmi: sync with upstream

This commit is contained in:
coolsnowwolf 2024-01-17 23:19:27 +08:00
parent 311b20a4cd
commit 1975f13219
3 changed files with 198 additions and 113 deletions

View File

@ -1,13 +1,13 @@
include $(TOPDIR)/rules.mk
PKG_NAME:=umbim
PKG_RELEASE:=3
PKG_RELEASE:=24
PKG_SOURCE_PROTO:=git
PKG_SOURCE_URL=$(PROJECT_GIT)/project/umbim.git
PKG_SOURCE_DATE:=2019-09-11
PKG_SOURCE_VERSION:=184b707ddaa0acee84d02e0ffe599cb8b67782bd
PKG_MIRROR_HASH:=482ff69144f81fafed99035840f5a24e772472f2df2f3ac0219d6de791ac5835
PKG_SOURCE_DATE:=2022-08-13
PKG_SOURCE_VERSION:=146bc77c98ace3d1cc672986669650d2e1da71f3
PKG_MIRROR_HASH:=3cf04858ff5c3f529904f9789b094aa9645ad41c91f553e6fc3fcd3cb341d359
PKG_MAINTAINER:=John Crispin <john@phrozen.org>
PKG_LICENSE:=GPL-2.0
@ -32,7 +32,7 @@ define Package/umbim/description
endef
TARGET_CFLAGS += \
-I$(STAGING_DIR)/usr/include -ffunction-sections -fdata-sections -Wno-address-of-packed-member
-I$(STAGING_DIR)/usr/include -ffunction-sections -fdata-sections
TARGET_LDFLAGS += -Wl,--gc-sections

View File

@ -11,37 +11,48 @@ proto_mbim_init_config() {
available=1
no_device=1
proto_config_add_string "device:device"
proto_config_add_string pdptype
proto_config_add_string apn
proto_config_add_string pincode
proto_config_add_string delay
proto_config_add_boolean allow_roaming
proto_config_add_boolean allow_partner
proto_config_add_string auth
proto_config_add_string username
proto_config_add_string password
[ -e /proc/sys/net/ipv6 ] && proto_config_add_string ipv6
proto_config_add_string dhcp
proto_config_add_string dhcpv6
proto_config_add_string pdptype
proto_config_add_int mtu
proto_config_add_defaults
}
_proto_mbim_get_field() {
local field="$1"
shift
local mbimconfig="$@"
echo "$mbimconfig" | while read -r line; do
variable=${line%%:*}
[ "$variable" = "$field" ] || continue;
value=${line##* }
echo -n "$value "
done
}
_proto_mbim_setup() {
local interface="$1"
local tid=2
local ret
local device pdptype apn pincode delay auth username password $PROTO_DEFAULT_OPTIONS
json_get_vars device pdptype apn pincode delay auth username password $PROTO_DEFAULT_OPTIONS
local device apn pincode delay auth username password allow_roaming allow_partner
local dhcp dhcpv6 pdptype ip4table ip6table mtu $PROTO_DEFAULT_OPTIONS
json_get_vars device apn pincode delay auth username password allow_roaming allow_partner
json_get_vars dhcp dhcpv6 pdptype ip4table ip6table mtu $PROTO_DEFAULT_OPTIONS
[ ! -e /proc/sys/net/ipv6 ] && ipv6=0 || json_get_var ipv6 ipv6
[ -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" ] || {
echo "mbim[$$]" "No control device specified"
proto_notify_error "$interface" NO_DEVICE
@ -77,6 +88,8 @@ _proto_mbim_setup() {
echo "mbim[$$]" "Reading capabilities"
umbim $DBG -n -d $device caps || {
echo "mbim[$$]" "Failed to read modem caps"
tid=$((tid + 1))
umbim $DBG -t $tid -d "$device" disconnect
proto_notify_error "$interface" PIN_FAILED
return 1
}
@ -86,6 +99,8 @@ _proto_mbim_setup() {
echo "mbim[$$]" "Sending pin"
umbim $DBG -n -t $tid -d $device unlock "$pincode" || {
echo "mbim[$$]" "Unable to verify PIN"
tid=$((tid + 1))
umbim $DBG -t $tid -d "$device" disconnect
proto_notify_error "$interface" PIN_FAILED
proto_block_restart "$interface"
return 1
@ -94,129 +109,199 @@ _proto_mbim_setup() {
tid=$((tid + 1))
echo "mbim[$$]" "Checking pin"
local pinstate="/var/run/mbim.$$.pinstate"
umbim $DBG -n -t $tid -d $device pinstate > "$pinstate" 2>&1 || {
local pin
pin=$(awk '$2=="pin:" {print $5}' "$pinstate")
# we only need pin1 (the SIM pin) to connect
[ "$pin" = "pin1" ] && {
umbim $DBG -n -t $tid -d $device pinstate
[ $? -eq 2 ] && {
echo "mbim[$$]" "PIN required"
tid=$((tid + 1))
umbim $DBG -t $tid -d "$device" disconnect
proto_notify_error "$interface" PIN_FAILED
proto_block_restart "$interface"
return 1
}
}
tid=$((tid + 1))
echo "mbim[$$]" "Checking subscriber"
umbim $DBG -n -t $tid -d $device subscriber || {
echo "mbim[$$]" "Subscriber init failed"
tid=$((tid + 1))
umbim $DBG -t $tid -d "$device" disconnect
proto_notify_error "$interface" NO_SUBSCRIBER
return 1
}
tid=$((tid + 1))
echo "mbim[$$]" "Register with network"
umbim $DBG -n -t $tid -d $device registration || {
echo "mbim[$$]" "Subscriber registration failed"
connected=0
umbim $DBG -n -t $tid -d $device registration
reg_status=$?
case $reg_status in
0) echo "mbim[$$]" "Registered in home mode"
tid=$((tid + 1))
connected=1;;
4) if [ "$allow_roaming" = "1" ]; then
echo "mbim[$$]" "Registered in roaming mode"
tid=$((tid + 1))
connected=1
fi;;
5) if [ "$allow_partner" = "1" ]; then
echo "mbim[$$]" "Registered in partner mode"
tid=$((tid + 1))
connected=1
fi;;
esac
if [ $connected -ne 1 ]; then
echo "mbim[$$]" "Subscriber registration failed (code $reg_status)"
tid=$((tid + 1))
umbim $DBG -t $tid -d "$device" disconnect
proto_notify_error "$interface" NO_REGISTRATION
return 1
}
tid=$((tid + 1))
fi
echo "mbim[$$]" "Attach to network"
umbim $DBG -n -t $tid -d $device attach || {
echo "mbim[$$]" "Failed to attach to network"
tid=$((tid + 1))
umbim $DBG -t $tid -d "$device" disconnect
proto_notify_error "$interface" ATTACH_FAILED
return 1
}
tid=$((tid + 1))
pdptype=$(echo "$pdptype" | awk '{print tolower($0)}')
[ "$ipv6" = 0 ] && pdptype="ipv4"
local req_pdptype="" # Pass "default" PDP type to umbim if unconfigured
[ "$pdptype" = "ipv4" -o "$pdptype" = "ipv6" -o "$pdptype" = "ipv4v6" ] && req_pdptype="$pdptype:"
local connect_state
echo "mbim[$$]" "Connect to network"
while ! umbim $DBG -n -t $tid -d $device connect "$pdptype:$apn" "$auth" "$username" "$password"; do
connect_state=$(umbim $DBG -n -t $tid -d $device connect "$req_pdptype$apn" "$auth" "$username" "$password") || {
echo "mbim[$$]" "Failed to connect bearer"
tid=$((tid + 1))
sleep 1;
done
tid=$((tid + 1))
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
umbim $DBG -t $tid -d "$device" disconnect
proto_notify_error "$interface" CONNECT_FAILED
return 1
}
tid=$((tid + 1))
proto_init_update "$ifname" 1
proto_add_data
json_add_int tid $tid
proto_close_data
proto_send_update "$interface"
echo "$connect_state"
local iptype="$(echo "$connect_state" | grep iptype: | awk '{print $4}')"
local ip_4 ip_6
ip_4=$(awk '$1=="ipv4address:" {print $2}' "$config")
ip_6=$(awk '$1=="ipv6address:" {print $2}' "$config")
[ -n "$ip_4" ] || [ -n "$ip_6" ] || {
echo "mbim[$$]" "Failed to obtain IP addresses"
proto_notify_error "$interface" CONFIG_FAILED
return 1
}
echo "mbim[$$]" "Connected"
local zone="$(fw3 -q network "$interface" 2>/dev/null)"
echo "mbim[$$]" "Setting up $ifname"
local mbimconfig="$(umbim $DBG -n -t $tid -d $device config)"
echo "$mbimconfig"
tid=$((tid + 1))
proto_init_update "$ifname" 1
proto_set_keep 1
local ip mask gateway mtu dns dns_servers
[ -n "$ip_4" ] && {
echo "mbim[$$]" "Configure IPv4 on $ifname"
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" "128"
proto_add_ipv6_prefix "$ip_6"
proto_add_ipv6_route "$gateway" "128"
[ "$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"
[ -z "$dhcp" ] && dhcp="auto"
[ -z "$dhcpv6" ] && dhcpv6="auto"
[ "$iptype" != "ipv6" ] && {
json_init
json_add_string name "${interface}_4"
json_add_string ifname "@$interface"
ipv4address=$(_proto_mbim_get_field ipv4address "$mbimconfig")
if [ -n "$ipv4address" -a "$dhcp" != 1 ]; then
json_add_string proto "static"
json_add_array ipaddr
for address in $ipv4address; do
json_add_string "" "$address"
done
json_close_array
json_add_string gateway $(_proto_mbim_get_field ipv4gateway "$mbimconfig")
elif [ "$dhcp" != 0 ]; then
echo "mbim[$$]" "Starting DHCP on $ifname"
json_add_string proto "dhcp"
fi
[ "$peerdns" = 0 -a "$dhcp" != 1 ] || {
json_add_array dns
for server in $(_proto_mbim_get_field ipv4dnsserver "$mbimconfig"); do
json_add_string "" "$server"
done
json_close_array
}
proto_add_dynamic_defaults
[ -n "$zone" ] && json_add_string zone "$zone"
[ -n "$ip4table" ] && json_add_string ip4table "$ip4table"
json_close_object
ubus call network add_dynamic "$(json_dump)"
}
[ "$iptype" != "ipv4" ] && {
json_init
json_add_string name "${interface}_6"
json_add_string ifname "@$interface"
ipv6address=$(_proto_mbim_get_field ipv6address "$mbimconfig")
if [ -n "$ipv6address" -a "$dhcpv6" != 1 ]; then
json_add_string proto "static"
json_add_array ip6addr
for address in $ipv6address; do
json_add_string "" "$address"
done
json_close_array
json_add_array ip6prefix
for address in $ipv6address; do
json_add_string "" "$address"
done
json_close_array
json_add_string ip6gw $(_proto_mbim_get_field ipv6gateway "$mbimconfig")
elif [ "$dhcpv6" != 0 ]; then
echo "mbim[$$]" "Starting DHCPv6 on $ifname"
json_add_string proto "dhcpv6"
json_add_string extendprefix 1
fi
[ "$peerdns" = 0 -a "$dhcpv6" != 1 ] || {
json_add_array dns
for server in $(_proto_mbim_get_field ipv6dnsserver "$mbimconfig"); do
json_add_string "" "$server"
done
json_close_array
}
proto_add_dynamic_defaults
[ -n "$zone" ] && json_add_string zone "$zone"
[ -n "$ip6table" ] && json_add_string ip6table "$ip6table"
json_close_object
ubus call network add_dynamic "$(json_dump)"
}
[ -z "$mtu" ] && {
local ipv4mtu=$(_proto_mbim_get_field ipv4mtu "$mbimconfig")
ipv4mtu="${ipv4mtu:-0}"
local ipv6mtu=$(_proto_mbim_get_field ipv6mtu "$mbimconfig")
ipv6mtu="${ipv6mtu:-0}"
mtu=$((ipv6mtu > ipv4mtu ? ipv6mtu : ipv4mtu))
}
[ -n "$mtu" -a "$mtu" != 0 ] && {
echo Setting MTU of $ifname to $mtu
/sbin/ip link set dev $ifname mtu $mtu
}
uci_set_state network $interface tid "$tid"
}
proto_mbim_setup() {
local ret
_proto_mbim_setup "$@"
_proto_mbim_setup $@
ret=$?
rm -f "/var/run/mbim.$$."*
[ "$ret" = 0 ] || {
logger "mbim bringup failed, retry in 15s"
sleep 15
@ -228,13 +313,17 @@ proto_mbim_setup() {
proto_mbim_teardown() {
local interface="$1"
local device tid
json_get_vars device tid
local device
json_get_vars device
local tid=$(uci_get_state network $interface tid)
[ -n "$ctl_device" ] && device=$ctl_device
echo "mbim[$$]" "Stopping network"
[ -n "$tid" ] && umbim $DBG -t$tid -d "$device" disconnect
[ -n "$tid" ] && {
umbim $DBG -t $tid -d "$device" disconnect
uci_revert_state network $interface tid
}
proto_init_update "*" 0
proto_send_update "$interface"

View File

@ -1,7 +1,7 @@
include $(TOPDIR)/rules.mk
PKG_NAME:=uqmi
PKG_RELEASE:=$(AUTORELEASE)
PKG_RELEASE:=1
PKG_SOURCE_PROTO:=git
PKG_SOURCE_URL=$(PROJECT_GIT)/project/uqmi.git
@ -33,11 +33,7 @@ endef
TARGET_CFLAGS += -I$(STAGING_DIR)/usr/include -ffunction-sections -fdata-sections
ifeq ($(GCC_MAJOR_VERSION),12)
TARGET_CFLAGS += -Wno-error=dangling-pointer -Wno-error=maybe-uninitialized
endif
ifeq ($(GCC_MAJOR_VERSION),13)
ifneq (,$(findstring $(GCC_MAJOR_VERSION), 12 13))
TARGET_CFLAGS += -Wno-error=dangling-pointer -Wno-error=maybe-uninitialized
endif