net: uqmi: fix blocking in endless loops when unplugging device
[openwrt/staging/chunkeey.git] / package / network / utils / uqmi / files / lib / netifd / proto / qmi.sh
index 1f260ae3c2ce368caefcb0225cf1d70f0972f485..f5c8768601081b3ddc42a9952073a9a4c35b2171 100755 (executable)
@@ -21,16 +21,17 @@ proto_qmi_init_config() {
        proto_config_add_int profile
        proto_config_add_boolean dhcpv6
        proto_config_add_boolean autoconnect
+       proto_config_add_int plmn
        proto_config_add_defaults
 }
 
 proto_qmi_setup() {
        local interface="$1"
 
-       local device apn auth username password pincode delay modes pdptype profile dhcpv6 autoconnect $PROTO_DEFAULT_OPTIONS
+       local device apn auth username password pincode delay modes pdptype profile dhcpv6 autoconnect plmn $PROTO_DEFAULT_OPTIONS
        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 $PROTO_DEFAULT_OPTIONS
+       json_get_vars device apn auth username password pincode delay modes pdptype profile dhcpv6 autoconnect plmn $PROTO_DEFAULT_OPTIONS
 
        [ "$metric" = "" ] && metric="0"
 
@@ -64,6 +65,7 @@ proto_qmi_setup() {
        [ -n "$delay" ] && sleep "$delay"
 
        while uqmi -s -d "$device" --get-pin-status | grep '"UIM uninitialized"' > /dev/null; do
+               [ -e "$device" ] || return 1
                sleep 1;
        done
 
@@ -76,12 +78,32 @@ proto_qmi_setup() {
                }
        }
 
+       [ -n "$plmn" ] && {
+               local mcc mnc
+               if [ "$plmn" = 0 ]; then
+                       mcc=0
+                       mnc=0
+                       echo "Setting PLMN to auto"
+               else
+                       mcc=${plmn:0:3}
+                       mnc=${plmn:3}
+                       echo "Setting PLMN to $plmn"
+               fi
+               uqmi -s -d "$device" --set-plmn --mcc "$mcc" --mnc "$mnc" || {
+                       echo "Unable to set PLMN"
+                       proto_notify_error "$interface" PLMN_FAILED
+                       proto_block_restart "$interface"
+                       return 1
+               }
+       }
+
        uqmi -s -d "$device" --set-data-format 802.3
        uqmi -s -d "$device" --wda-set-data-format 802.3
        uqmi -s -d "$device" --sync
 
        echo "Waiting for network registration"
        while uqmi -s -d "$device" --get-serving-system | grep '"searching"' > /dev/null; do
+               [ -e "$device" ] || return 1
                sleep 5;
        done