summaryrefslogtreecommitdiff
path: root/package/network/utils/wwan/files
diff options
context:
space:
mode:
authorJohn Crispin <john@openwrt.org>2014-10-08 08:01:20 +0000
committerJohn Crispin <john@openwrt.org>2014-10-08 08:01:20 +0000
commit90120bb7712361d67edb84faee78f2b191e1158b (patch)
tree09269a89a6d98cd7f0c5589f07ff37556b896e1c /package/network/utils/wwan/files
parent1df98fcd5adbf50c9fb0d2718879616d0e3c67b8 (diff)
downloadmtk-20170518-90120bb7712361d67edb84faee78f2b191e1158b.zip
mtk-20170518-90120bb7712361d67edb84faee78f2b191e1158b.tar.gz
mtk-20170518-90120bb7712361d67edb84faee78f2b191e1158b.tar.bz2
wwan: add a generic 3g/4g proto
this proto handler will detect which of 3g, qmi, mbim, ncm or directip you need for a stick and setup uci automagically Signed-off-by: John Crispin <blogic@openwrt.org> SVN-Revision: 42837
Diffstat (limited to 'package/network/utils/wwan/files')
-rwxr-xr-xpackage/network/utils/wwan/files/wwan.sh119
-rw-r--r--package/network/utils/wwan/files/wwan.usb18
-rw-r--r--package/network/utils/wwan/files/wwan.usbmisc25
3 files changed, 162 insertions, 0 deletions
diff --git a/package/network/utils/wwan/files/wwan.sh b/package/network/utils/wwan/files/wwan.sh
new file mode 100755
index 0000000..6b33600
--- /dev/null
+++ b/package/network/utils/wwan/files/wwan.sh
@@ -0,0 +1,119 @@
+#!/bin/sh
+
+. /lib/functions.sh
+. ../netifd-proto.sh
+init_proto "$@"
+
+INCLUDE_ONLY=1
+
+ctl_device=""
+dat_device=""
+
+proto_mbim_setup() { echo "wwan[$$] mbim proto is missing"; }
+proto_qmi_setup() { echo "wwan[$$] qmi proto is missing"; }
+proto_ncm_setup() { echo "wwan[$$] ncm proto is missing"; }
+proto_3g_setup() { echo "wwan[$$] 3g proto is missing"; }
+proto_directip_setup() { echo "wwan[$$] directip proto is missing"; }
+
+[ -f ./mbim.sh ] && . ./mbim.sh
+[ -f ./ncm.sh ] && . ./ncm.sh
+[ -f ./qmi.sh ] && . ./qmi.sh
+[ -f ./3g.sh ] && { . ./ppp.sh; . ./3g.sh; }
+[ -f ./directip.sh ] && . ./directip.sh
+
+proto_wwan_init_config() {
+ available=1
+ no_device=1
+
+ proto_config_add_string apn
+ proto_config_add_string auth
+ proto_config_add_string username
+ proto_config_add_string password
+ proto_config_add_string pincode
+ proto_config_add_string delay
+ proto_config_add_string modes
+}
+
+proto_wwan_setup() {
+ local driver usb devicename desc
+
+ for a in `ls /sys/bus/usb/devices`; do
+ local vendor product
+ [ -z "$usb" -a -f /sys/bus/usb/devices/$a/idVendor -a -f /sys/bus/usb/devices/$a/idProduct ] || continue
+ vendor=$(cat /sys/bus/usb/devices/$a/idVendor)
+ product=$(cat /sys/bus/usb/devices/$a/idProduct)
+ [ -f /lib/network/wwan/$vendor:$product ] && {
+ usb=/lib/network/wwan/$vendor:$product
+ devicename=$a
+ }
+ done
+
+ [ -n "$usb" ] && {
+ local old_cb control data
+
+ json_set_namespace wwan old_cb
+ json_init
+ json_load "$(cat $usb)"
+ json_select
+ json_get_vars desc control data
+ json_set_namespace $old_cb
+
+ [ -n "$control" -a -n "$data" ] && {
+ ttys=$(ls -d /sys/bus/usb/devices/$devicename/${devicename}*/tty* | sed "s/.*\///g" | tr "\n" " ")
+ ctl_device=/dev/$(echo $ttys | cut -d" " -f $((control + 1)))
+ dat_device=/dev/$(echo $ttys | cut -d" " -f $((data + 1)))
+ driver=comgt
+ }
+ }
+
+ [ -z "$ctl_device" ] && for net in $(ls /sys/class/net/ | grep wwan); do
+ [ -z "$ctl_device" ] || continue
+ driver=$(grep DRIVER /sys/class/net/$net/device/uevent | cut -d= -f2)
+ case "$driver" in
+ qmi_wwan|cdc_mbim)
+ ctl_device=/dev/$(ls /sys/class/net/$net/device/usbmisc)
+ ;;
+ sierra_net|*cdc_ncm)
+ ctl_device=/dev/$(cd /sys/class/net/$net/; find ../../../ -name ttyUSB* |xargs basename | head -n1)
+ ;;
+ *) continue;;
+ esac
+ echo "wwan[$$]" "Using proto:$proto device:$ctl_device iface:$net desc:$desc"
+ done
+
+ [ -n "$ctl_device" ] || {
+ echo "wwan[$$]" "No valid device was found"
+ proto_notify_error "$interface" NO_DEVICE
+ proto_block_restart "$interface"
+ return 1
+ }
+
+ uci_set_state network $interface driver "$driver"
+ uci_set_state network $interface ctl_device "$ctl_device"
+ uci_set_state network $interface dat_device "$dat_device"
+
+ case $driver in
+ qmi_wwan) proto_qmi_setup $@ ;;
+ cdc_mbim) proto_mbim_setup $@ ;;
+ sierra_net) proto_directip_setup $@ ;;
+ comgt) proto_3g_setup $@ ;;
+ *cdc_ncm) proto_ncm_setup $@ ;;
+ esac
+}
+
+proto_wwan_teardown() {
+ local interface=$1
+ local driver=$(uci_get_state network $interface driver)
+ ctl_device=$(uci_get_state network $interface ctl_device)
+ dat_device=$(uci_get_state network $interface dat_device)
+
+ case $driver in
+ qmi_wwan) proto_qmi_teardown $@ ;;
+ cdc_mbim) proto_mbim_teardown $@ ;;
+ sierra_net) proto_mbim_teardown $@ ;;
+ comgt) proto_3g_teardown $@ ;;
+ *cdc_ncm) proto_ncm_teardown $@ ;;
+ esac
+}
+
+add_protocol wwan
diff --git a/package/network/utils/wwan/files/wwan.usb b/package/network/utils/wwan/files/wwan.usb
new file mode 100644
index 0000000..507b002
--- /dev/null
+++ b/package/network/utils/wwan/files/wwan.usb
@@ -0,0 +1,18 @@
+[ "$ACTION" = add -a "$DEVTYPE" = usb_device ] || exit 0
+
+vid=$(cat /sys$DEVPATH/idVendor)
+pid=$(cat /sys$DEVPATH/idProduct)
+[ -f "/lib/network/wwan/$vid:$pid" ] || exit 0
+
+find_wwan_iface() {
+ local cfg="$1"
+ local proto
+ config_get proto "$cfg" proto
+ [ "$proto" = wwan ] || return 0
+ proto_set_available "$cfg" 1
+ ifup $cfg
+ exit 0
+}
+
+config_load network
+config_foreach find_wwan_iface interface
diff --git a/package/network/utils/wwan/files/wwan.usbmisc b/package/network/utils/wwan/files/wwan.usbmisc
new file mode 100644
index 0000000..404a5cc
--- /dev/null
+++ b/package/network/utils/wwan/files/wwan.usbmisc
@@ -0,0 +1,25 @@
+#!/bin/sh
+
+[ "$ACTION" = add ] || exit 0
+[ "${DEVNAME/[0-9]/}" = cdc-wdm ] || exit 0
+
+. /lib/functions.sh
+. /lib/netifd/netifd-proto.sh
+
+find_wwan_iface() {
+ local cfg="$1"
+
+ local proto device
+ config_get proto "$cfg" proto
+ config_get device "$cfg" device
+
+ [ "$proto" = wwan ] || [ "$proto" = mbim ] || [ "$proto" = qmi ] || return 0
+ [ -z "$device" -a "$proto" = wwan ] || [ "$device" = "/dev/$DEVNAME" ] || return 0
+
+ proto_set_available "$cfg" 1
+ ifup "$cfg"
+ exit 0
+}
+
+config_load network
+config_foreach find_wwan_iface interface