[OpenWrt-Devel] [PATCH v2] uqmi: allow matching IMSI for qmi networks

Daniel Golle daniel at makrotopia.org
Sun Nov 4 17:22:50 EST 2018


Introduce 'imsi' configuration option for proto 'qmi' network
interfaces. Setting it makes sure the configuration only gets used
on the intended SIM card. In this way, one can have many configurations
for different SIM cards selected automatically when the card was either
swapped physically or in software (as possible on the APU3 board).
We may need to add locking in dev.c function
int qmi_device_open(struct qmi_dev *qmi, const char *path)
to avoid multiple instances of uqmi operating on the same chardev.

Signed-off-by: Daniel Golle <daniel at makrotopia.org>
---
 package/network/utils/uqmi/Makefile             |  2 +-
 .../utils/uqmi/files/lib/netifd/proto/qmi.sh    | 17 ++++++++++++++---
 2 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/package/network/utils/uqmi/Makefile b/package/network/utils/uqmi/Makefile
index b2f3474400..8eaf0bff3f 100644
--- a/package/network/utils/uqmi/Makefile
+++ b/package/network/utils/uqmi/Makefile
@@ -1,7 +1,7 @@
 include $(TOPDIR)/rules.mk
 
 PKG_NAME:=uqmi
-PKG_RELEASE:=5
+PKG_RELEASE:=6
 
 PKG_SOURCE_PROTO:=git
 PKG_SOURCE_URL=$(PROJECT_GIT)/project/uqmi.git
diff --git a/package/network/utils/uqmi/files/lib/netifd/proto/qmi.sh b/package/network/utils/uqmi/files/lib/netifd/proto/qmi.sh
index 9b2f69f009..f52f28676b 100755
--- a/package/network/utils/uqmi/files/lib/netifd/proto/qmi.sh
+++ b/package/network/utils/uqmi/files/lib/netifd/proto/qmi.sh
@@ -10,6 +10,7 @@ proto_qmi_init_config() {
 	available=1
 	no_device=1
 	proto_config_add_string "device:device"
+	proto_config_add_string imsi
 	proto_config_add_string apn
 	proto_config_add_string auth
 	proto_config_add_string username
@@ -28,12 +29,12 @@ proto_qmi_init_config() {
 
 proto_qmi_setup() {
 	local interface="$1"
-	local dataformat connstat
-	local device apn auth username password pincode delay modes pdptype profile dhcpv6 autoconnect plmn timeout $PROTO_DEFAULT_OPTIONS
+	local dataformat connstat imsi_actual
+	local device imsi apn auth username password pincode delay modes pdptype profile dhcpv6 autoconnect plmn timeout $PROTO_DEFAULT_OPTIONS
 	local ip4table ip6table
 	local cid_4 pdh_4 cid_6 pdh_6
 	local ip_6 ip_prefix_length gateway_6 dns1_6 dns2_6
-	json_get_vars device apn auth username password pincode delay modes pdptype profile dhcpv6 autoconnect plmn ip4table ip6table timeout $PROTO_DEFAULT_OPTIONS
+	json_get_vars device imsi apn auth username password pincode delay modes pdptype profile dhcpv6 autoconnect plmn ip4table ip6table timeout $PROTO_DEFAULT_OPTIONS
 
 	[ "$timeout" = "" ] && timeout="10"
 
@@ -83,6 +84,16 @@ proto_qmi_setup() {
 		fi
 	done
 
+	[ -n "$imsi" ] && {
+		imsi_actual="$(uqmi -s -d "$device" --get-imsi | cut -d'"' -f2)"
+		[ "$imsi" = "$imsi_actual" ] || {
+			echo "Configured IMSI doesn't match SIM card."
+			proto_notify_error "$interface" SIM_WRONG
+			proto_set_available "$interface" 0
+			return 1
+		}
+	}
+
 	if uqmi -s -d "$device" --get-pin-status | grep '"Not supported"' > /dev/null; then
 		[ -n "$pincode" ] && {
 			uqmi -s -d "$device" --verify-pin1 "$pincode" > /dev/null || uqmi -s -d "$device" --uim-verify-pin1 "$pincode" > /dev/null || {
-- 
2.19.1


_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel



More information about the openwrt-devel mailing list