From patchwork Sun Nov 4 23:46:00 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Golle X-Patchwork-Id: 992811 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=lists.openwrt.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=makrotopia.org Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="JnmMf2AQ"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42pCBk6M08zB6PH for ; Mon, 5 Nov 2018 10:46:38 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Subject:In-Reply-To:MIME-Version: References:Message-ID:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=H1/aleMAKDaCj3JkjF2Vmlrtt/AqpwOdmxaccuRXg3A=; b=JnmMf2AQu6OK7z CNW1KbfVYBpwN69nlbvpksUJvY5yTpkHdj2VXaaGicqorxbMbqdJvr6UIbtoTr5f5sAD7Tvt4bFVT 6rPYiBIFIRx3Lgcdj9EzFgRUWmPejdMBN2LTPh5bSd/p7wF4YMuwrL08NvVnJJAE6e6o2fM7Gjh7D GDOAakJVRh7g7QuDsa4tzGWGciDvYduJG16mEZ0ojMB10z9HhrWqdoh2SO7DK+6yCP63sFp9TLM6z 8zXZY1vQx9iX8zPK0TD11QLuGTZ4rXmPont814xoFRD5Uy27mby9fyPVBCkbpAxkRc+OxLexaD6hx 2U8VoLlTjf7cQVl67+4w==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gJS68-0006k4-Aw; Sun, 04 Nov 2018 23:46:28 +0000 Received: from fudo.makrotopia.org ([2a07:2ec0:3002::71]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gJS64-0006jN-Ib for openwrt-devel@lists.openwrt.org; Sun, 04 Nov 2018 23:46:26 +0000 Received: from local by fudo.makrotopia.org with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.91) (envelope-from ) id 1gJS5m-0005mE-VR; Mon, 05 Nov 2018 00:46:07 +0100 Date: Mon, 5 Nov 2018 00:46:00 +0100 From: Daniel Golle To: openwrt-devel@lists.openwrt.org Message-ID: <20181104234553.GA6732@makrotopia.org> References: <20181104222241.GA5970@makrotopia.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20181104222241.GA5970@makrotopia.org> User-Agent: Mutt/1.10.1 (2018-07-13) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181104_154624_772059_716E2AAD X-CRM114-Status: GOOD ( 21.42 ) X-Spam-Score: -0.0 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record Subject: [OpenWrt-Devel] [PATCH v3] uqmi: allow matching IMSI for qmi networks X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Felix Fietkau , Koen Vandeputte , Florian Eckert , Matti Laakso Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org 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). In order to allow multiple configurations using the same character device, add locking in netifd protocol handler to avoid overlapping execution of uqmi of the same device. Signed-off-by: Daniel Golle --- package/network/utils/uqmi/Makefile | 2 +- .../utils/uqmi/files/lib/netifd/proto/qmi.sh | 54 ++++++++++++++++--- 2 files changed, 49 insertions(+), 7 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..2edbe7c28e 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" @@ -68,10 +69,16 @@ proto_qmi_setup() { return 1 } + lockname="/var/lock/LCK..$devname" + lock "$lockname" + echo "Waiting for SIM initialization" local uninitialized_timeout=0 while uqmi -s -d "$device" --get-pin-status | grep '"UIM uninitialized"' > /dev/null; do - [ -e "$device" ] || return 1 + [ -e "$device" ] || { + lock -u "$lockname" + return 1 + } if [ "$uninitialized_timeout" -lt "$timeout" ]; then let uninitialized_timeout++ sleep 1; @@ -79,16 +86,29 @@ proto_qmi_setup() { echo "SIM not initialized" proto_notify_error "$interface" SIM_NOT_INITIALIZED proto_block_restart "$interface" + lock -u "$lockname" return 1 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 + lock -u "$lockname" + 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 || { echo "Unable to verify PIN" proto_notify_error "$interface" PIN_FAILED proto_block_restart "$interface" + lock -u "$lockname" return 1 } } @@ -106,6 +126,7 @@ proto_qmi_setup() { echo "SIM locked PUK required" proto_notify_error "$interface" PUK_NEEDED proto_block_restart "$interface" + lock -u "$lockname" return 1 ;; not_verified) @@ -113,6 +134,7 @@ proto_qmi_setup() { echo "PIN verify count value is $pin1_verify_tries this is below the limit of 3" proto_notify_error "$interface" PIN_TRIES_BELOW_LIMIT proto_block_restart "$interface" + lock -u "$lockname" return 1 } if [ -n "$pincode" ]; then @@ -120,12 +142,14 @@ proto_qmi_setup() { echo "Unable to verify PIN" proto_notify_error "$interface" PIN_FAILED proto_block_restart "$interface" + lock -u "$lockname" return 1 } else echo "PIN not specified but required" proto_notify_error "$interface" PIN_NOT_SPECIFIED proto_block_restart "$interface" + lock -u "$lockname" return 1 fi ;; @@ -136,6 +160,7 @@ proto_qmi_setup() { echo "PIN status failed ($pin1_status)" proto_notify_error "$interface" PIN_STATUS_FAILED proto_block_restart "$interface" + lock -u "$lockname" return 1 ;; esac @@ -156,6 +181,7 @@ proto_qmi_setup() { echo "Unable to set PLMN" proto_notify_error "$interface" PLMN_FAILED proto_block_restart "$interface" + lock -u "$lockname" return 1 } } @@ -172,6 +198,7 @@ proto_qmi_setup() { [ -f /sys/class/net/$ifname/qmi/raw_ip ] || { echo "Device only supports raw-ip mode but is missing this required driver attribute: /sys/class/net/$ifname/qmi/raw_ip" + lock -u "$lockname" return 1 } @@ -184,7 +211,10 @@ proto_qmi_setup() { echo "Waiting for network registration" local registration_timeout=0 while uqmi -s -d "$device" --get-serving-system | grep '"searching"' > /dev/null; do - [ -e "$device" ] || return 1 + [ -e "$device" ] || { + lock -u "$lockname" + return 1 + } if [ "$registration_timeout" -lt "$timeout" ]; then let registration_timeout++ sleep 1; @@ -192,6 +222,7 @@ proto_qmi_setup() { echo "Network registration failed" proto_notify_error "$interface" NETWORK_REGISTRATION_FAILED proto_block_restart "$interface" + lock -u "$lockname" return 1 fi done @@ -215,6 +246,7 @@ proto_qmi_setup() { if ! [ "$cid_4" -eq "$cid_4" ] 2> /dev/null; then echo "Unable to obtain client ID" proto_notify_error "$interface" NO_CID + lock -u "$lockname" return 1 fi @@ -234,6 +266,7 @@ proto_qmi_setup() { echo "Unable to connect IPv4" uqmi -s -d "$device" --set-client-id wds,"$cid_4" --release-client-id wds > /dev/null 2>&1 proto_notify_error "$interface" CALL_FAILED + lock -u "$lockname" return 1 fi @@ -243,6 +276,7 @@ proto_qmi_setup() { echo "No data link!" uqmi -s -d "$device" --set-client-id wds,"$cid_4" --release-client-id wds > /dev/null 2>&1 proto_notify_error "$interface" CALL_FAILED + lock -u "$lockname" return 1 } } @@ -252,6 +286,7 @@ proto_qmi_setup() { if ! [ "$cid_6" -eq "$cid_6" ] 2> /dev/null; then echo "Unable to obtain client ID" proto_notify_error "$interface" NO_CID + lock -u "$lockname" return 1 fi @@ -271,6 +306,7 @@ proto_qmi_setup() { echo "Unable to connect IPv6" uqmi -s -d "$device" --set-client-id wds,"$cid_6" --release-client-id wds > /dev/null 2>&1 proto_notify_error "$interface" CALL_FAILED + lock -u "$lockname" return 1 fi @@ -280,6 +316,7 @@ proto_qmi_setup() { echo "No data link!" uqmi -s -d "$device" --set-client-id wds,"$cid_6" --release-client-id wds > /dev/null 2>&1 proto_notify_error "$interface" CALL_FAILED + lock -u "$lockname" return 1 } } @@ -343,6 +380,7 @@ proto_qmi_setup() { json_close_object ubus call network add_dynamic "$(json_dump)" } + lock -u "$lockname" } qmi_wds_stop() { @@ -367,10 +405,12 @@ qmi_wds_stop() { proto_qmi_teardown() { local interface="$1" - local device cid_4 pdh_4 cid_6 pdh_6 + local device localname cid_4 pdh_4 cid_6 pdh_6 json_get_vars device [ -n "$ctl_device" ] && device=$ctl_device + lockname="/var/lock/LCK..$(basename "$device")" + lock "$lockname" echo "Stopping network $interface" @@ -383,6 +423,8 @@ proto_qmi_teardown() { proto_init_update "*" 0 proto_send_update "$interface" + + lock -u "$lockname" } [ -n "$INCLUDE_ONLY" ] || {