comgt: ncm: allow specification of interface name
[openwrt/openwrt.git] / package / network / utils / comgt / files / ncm.sh
index 6545091c82f38ccc616a562931eddf4815cdf5ba..38a4ba7a0bfdd6b96e542e315025f6dbf1ae792f 100644 (file)
@@ -10,6 +10,7 @@ proto_ncm_init_config() {
        no_device=1
        available=1
        proto_config_add_string "device:device"
+       proto_config_add_string ifname
        proto_config_add_string apn
        proto_config_add_string auth
        proto_config_add_string username
@@ -25,10 +26,10 @@ proto_ncm_init_config() {
 proto_ncm_setup() {
        local interface="$1"
 
-       local manufacturer initialize setmode connect finalize ifname devname devpath
+       local manufacturer initialize setmode connect finalize 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
+       local device ifname  apn auth username password pincode delay mode pdptype profile $PROTO_DEFAULT_OPTIONS
+       json_get_vars device ifname apn auth username password pincode delay mode pdptype profile $PROTO_DEFAULT_OPTIONS
 
        [ "$metric" = "" ] && metric="0"
 
@@ -53,17 +54,20 @@ proto_ncm_setup() {
                return 1
        }
 
-       devname="$(basename "$device")"
-       case "$devname" in
-       'tty'*)
-               devpath="$(readlink -f /sys/class/tty/$devname/device)"
-               ifname="$( ls "$devpath"/../../*/net )"
-               ;;
-       *)
-               devpath="$(readlink -f /sys/class/usbmisc/$devname/device/)"
-               ifname="$( ls "$devpath"/net )"
-               ;;
-       esac
+       [ -z "$ifname" ] && {
+               devname="$(basename "$device")"
+               case "$devname" in
+               'tty'*)
+                       devpath="$(readlink -f /sys/class/tty/$devname/device)"
+                       ifname="$( ls "$devpath"/../../*/net )"
+                       ;;
+               *)
+                       devpath="$(readlink -f /sys/class/usbmisc/$devname/device/)"
+                       ifname="$( ls "$devpath"/net )"
+                       ;;
+               esac
+       }
+
        [ -n "$ifname" ] || {
                echo "The interface could not be found."
                proto_notify_error "$interface" NO_IFACE