uqmi: inherit firewall zone membership to virtual sub interfaces
[openwrt/openwrt.git] / package / network / utils / comgt / files / ncm.sh
index 73d1e05e3fcb37344c979df8212da161e09768e4..9aaaa25f37f1ae4e38fdfb83cc5a14089fed6cc6 100644 (file)
@@ -25,7 +25,7 @@ proto_ncm_init_config() {
 proto_ncm_setup() {
        local interface="$1"
 
-       local manufacturer initialize setmode connect ifname devname devpath
+       local manufacturer initialize setmode connect finalize ifname devname devpath
 
        local device apn auth username password pincode delay mode pdptype profile $PROTO_DEFAULT_OPTIONS
        json_get_vars device apn auth username password pincode delay mode pdptype profile $PROTO_DEFAULT_OPTIONS
@@ -105,9 +105,21 @@ proto_ncm_setup() {
                        return 1
                }
        }
+
+       json_get_values configure configure
+       echo "Configuring modem"
+       for i in $configure; do
+               eval COMMAND="$i" gcom -d "$device" -s /etc/gcom/runcommand.gcom || {
+                       echo "Failed to configure modem"
+                       proto_notify_error "$interface" CONFIGURE_FAILED
+                       return 1
+               }
+       done
+
        [ -n "$mode" ] && {
                json_select modes
                json_get_var setmode "$mode"
+               echo "Setting mode"
                eval COMMAND="$setmode" gcom -d "$device" -s /etc/gcom/runcommand.gcom || {
                        echo "Failed to set operating mode"
                        proto_notify_error "$interface" SETMODE_FAILED
@@ -118,26 +130,34 @@ proto_ncm_setup() {
 
        echo "Starting network $interface"
        json_get_vars connect
+       echo "Connecting modem"
        eval COMMAND="$connect" gcom -d "$device" -s /etc/gcom/runcommand.gcom || {
                echo "Failed to connect"
                proto_notify_error "$interface" CONNECT_FAILED
                return 1
        }
 
+       json_get_vars finalize
+
        echo "Setting up $ifname"
-       
        proto_init_update "$ifname" 1
        proto_add_data
        json_add_string "manufacturer" "$manufacturer"
        proto_close_data
        proto_send_update "$interface"
 
+       local zone="$(fw3 -q network "$interface" 2>/dev/null)"
+
        [ "$pdptype" = "IP" -o "$pdptype" = "IPV4V6" ] && {
                json_init
                json_add_string name "${interface}_4"
                json_add_string ifname "@$interface"
                json_add_string proto "dhcp"
                proto_add_dynamic_defaults
+               [ -n "$zone" ] && {
+                       json_add_string zone "$zone"
+               }
+               json_close_object
                ubus call network add_dynamic "$(json_dump)"
        }
 
@@ -148,8 +168,21 @@ proto_ncm_setup() {
                json_add_string proto "dhcpv6"
                json_add_string extendprefix 1
                proto_add_dynamic_defaults
+               [ -n "$zone" ] && {
+                       json_add_string zone "$zone"
+               }
+               json_close_object
                ubus call network add_dynamic "$(json_dump)"
        }
+
+       [ -n "$finalize" ] && {
+               eval COMMAND="$finalize" gcom -d "$device" -s /etc/gcom/runcommand.gcom || {
+                       echo "Failed to configure modem"
+                       proto_notify_error "$interface" FINALIZE_FAILED
+                       return 1
+               }
+       }
+
 }
 
 proto_ncm_teardown() {