diff mbox series

[OpenWrt-Devel,PATCH/RFC] uqmi: allow matching IMSI for qmi networks

Message ID 20181104210804.GA5482@makrotopia.org
State Superseded
Delegated to: Koen Vandeputte
Headers show
Series [OpenWrt-Devel,PATCH/RFC] uqmi: allow matching IMSI for qmi networks | expand

Commit Message

Daniel Golle Nov. 4, 2018, 9:08 p.m. UTC
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 could have configuration
for different SIM cards selected automatically when the card was either
swapped physically or in software (as possible on the APU3 board).

Signed-off-by: Daniel Golle <daniel@makrotopia.org>
---
 .../utils/uqmi/files/lib/netifd/proto/qmi.sh       | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)
diff mbox series

Patch

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..ec1b936177 100755
--- a/package/network/utils/uqmi/files/lib/netifd/proto/qmi.sh
+++ b/package/network/utils/uqmi/files/lib/netifd/proto/qmi.sh
@@ -28,12 +28,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"
 
@@ -68,6 +68,14 @@  proto_qmi_setup() {
 		return 1
 	}
 
+	imsi_actual="$(uqmi -s -d "$device" --get-imsi | cut -d'"' -f2)"
+	[ -n "$imsi" -a "$imsi" != "$imsi_actual" ] && {
+		echo "Configured IMSI doesn't match SIM card."
+		proto_notify_error "$interface" NO_IFACE
+		proto_set_available "$interface" 0
+		return 1
+	}
+
 	echo "Waiting for SIM initialization"
 	local uninitialized_timeout=0
 	while uqmi -s -d "$device" --get-pin-status | grep '"UIM uninitialized"' > /dev/null; do