umbim: work out the ifname instead of relying on it being in uci
authorJohn Crispin <john@openwrt.org>
Wed, 8 Oct 2014 08:00:07 +0000 (08:00 +0000)
committerJohn Crispin <john@openwrt.org>
Wed, 8 Oct 2014 08:00:07 +0000 (08:00 +0000)
Signed-off-by: John Crispin <blogic@openwrt.org>
SVN-Revision: 42832

package/network/utils/umbim/files/lib/netifd/proto/mbim.sh

index a777c9bd60e366b65a9f5f8b0003c85a8e589e60..46802f2d3c5dd40ca4d93b4905ae1e197e5ec42d 100755 (executable)
@@ -7,6 +7,8 @@ init_proto "$@"
 #DBG=-v
 
 proto_mbim_init_config() {
 #DBG=-v
 
 proto_mbim_init_config() {
+       available=1
+       no_device=1
        proto_config_add_string "device:device"
        proto_config_add_string apn
        proto_config_add_string pincode
        proto_config_add_string "device:device"
        proto_config_add_string apn
        proto_config_add_string pincode
@@ -36,6 +38,18 @@ proto_mbim_setup() {
                proto_block_restart "$interface"
                return 1
        }
                proto_block_restart "$interface"
                return 1
        }
+
+       devname="$(basename "$device")"
+       devpath="$(readlink -f /sys/class/usbmisc/$devname/device/)"
+       ifname="$( ls "$devpath"/net )"
+
+       [ -n "$ifname" ] || {
+               logger -p daemon.err -t "mbim[$$]" "Failed to find matching interface"
+               proto_notify_error "$interface" NO_IFNAME
+               proto_set_available "$interface" 0
+               return 1
+       }
+
        [ -n "$apn" ] || {
                logger -p daemon.err -t "mbim[$$]" "No APN specified"
                proto_notify_error "$interface" NO_APN
        [ -n "$apn" ] || {
                logger -p daemon.err -t "mbim[$$]" "No APN specified"
                proto_notify_error "$interface" NO_APN
@@ -116,14 +130,14 @@ proto_mbim_setup() {
 
        json_init
        json_add_string name "${interface}_dhcp"
 
        json_init
        json_add_string name "${interface}_dhcp"
-       json_add_string ifname "@$interface"
+       json_add_string ifname "$ifname"
        json_add_string proto "dhcp"
        json_close_object
        ubus call network add_dynamic "$(json_dump)"
 
        json_init
        json_add_string name "${interface}_dhcpv6"
        json_add_string proto "dhcp"
        json_close_object
        ubus call network add_dynamic "$(json_dump)"
 
        json_init
        json_add_string name "${interface}_dhcpv6"
-       json_add_string ifname "@$interface"
+       json_add_string ifname "$ifname"
        json_add_string proto "dhcpv6"
        ubus call network add_dynamic "$(json_dump)"
 }
        json_add_string proto "dhcpv6"
        ubus call network add_dynamic "$(json_dump)"
 }