uqmi: inherit firewall zone membership to virtual sub interfaces
[openwrt/staging/blogic.git] / package / network / utils / uqmi / files / lib / netifd / proto / qmi.sh
index bfe01ddcc39843264ffd08105e48c3e675198c0f..f4b30b87eb7970451ab8a638f6c7383d7ce37495 100755 (executable)
@@ -68,6 +68,8 @@ proto_qmi_setup() {
                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
                [ -e "$device" ] || return 1
                if [ "$uninitialized_timeout" -lt "$timeout" ]; then
@@ -81,7 +83,7 @@ proto_qmi_setup() {
                fi
        done
 
-       if uqmi -s -d "$device" --get-pin-status | grep '"Not supported"' > /dev/null; then
+       if uqmi -s -d "$device" --get-pin-status | grep '"Not supported"\|"Invalid QMI command"' > /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"
@@ -94,6 +96,7 @@ proto_qmi_setup() {
                . /usr/share/libubox/jshn.sh
                json_load "$(uqmi -s -d "$device" --get-pin-status)"
                json_get_var pin1_status pin1_status
+               json_get_var pin1_verify_tries pin1_verify_tries
 
                case "$pin1_status" in
                        disabled)
@@ -106,6 +109,12 @@ proto_qmi_setup() {
                                return 1
                                ;;
                        not_verified)
+                               [ "$pin1_verify_tries" -lt "3" ] && {
+                                       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"
+                                       return 1
+                               }
                                if [ -n "$pincode" ]; then
                                        uqmi -s -d "$device" --verify-pin1 "$pincode" > /dev/null 2>&1 || uqmi -s -d "$device" --uim-verify-pin1 "$pincode" > /dev/null 2>&1 || {
                                                echo "Unable to verify PIN"
@@ -289,6 +298,9 @@ proto_qmi_setup() {
        }
        proto_close_data
        proto_send_update "$interface"
+
+       local zone="$(fw3 -q network "$interface" 2>/dev/null)"
+
        [ -n "$pdh_6" ] && {
                if [ -z "$dhcpv6" -o "$dhcpv6" = 0 ]; then
                        json_load "$(uqmi -s -d $device --set-client-id wds,$cid_6 --get-current-settings)"
@@ -309,6 +321,11 @@ proto_qmi_setup() {
                                proto_add_dns_server "$dns1_6"
                                proto_add_dns_server "$dns2_6"
                        }
+                       [ -n "$zone" ] && {
+                               proto_add_data
+                               json_add_string zone "$zone"
+                               proto_close_data
+                       }
                        proto_send_update "$interface"
                else
                        json_init
@@ -319,6 +336,7 @@ proto_qmi_setup() {
                        proto_add_dynamic_defaults
                        # RFC 7278: Extend an IPv6 /64 Prefix to LAN
                        json_add_string extendprefix 1
+                       [ -n "$zone" ] && json_add_string zone "$zone"
                        json_close_object
                        ubus call network add_dynamic "$(json_dump)"
                fi
@@ -331,6 +349,7 @@ proto_qmi_setup() {
                json_add_string proto "dhcp"
                [ -n "$ip4table" ] && json_add_string ip4table "$ip4table"
                proto_add_dynamic_defaults
+               [ -n "$zone" ] && json_add_string zone "$zone"
                json_close_object
                ubus call network add_dynamic "$(json_dump)"
        }