12 proto_mbim_setup
() { echo "wwan[$$] mbim proto is missing"; }
13 proto_qmi_setup
() { echo "wwan[$$] qmi proto is missing"; }
14 proto_ncm_setup
() { echo "wwan[$$] ncm proto is missing"; }
15 proto_3g_setup
() { echo "wwan[$$] 3g proto is missing"; }
16 proto_directip_setup
() { echo "wwan[$$] directip proto is missing"; }
18 [ -f .
/mbim.sh
] && . .
/mbim.sh
19 [ -f .
/ncm.sh
] && . .
/ncm.sh
20 [ -f .
/qmi.sh
] && . .
/qmi.sh
21 [ -f .
/3g.sh
] && { . .
/ppp.sh
; . .
/3g.sh
; }
22 [ -f .
/directip.sh
] && . .
/directip.sh
24 proto_wwan_init_config
() {
28 proto_config_add_string apn
29 proto_config_add_string auth
30 proto_config_add_string username
31 proto_config_add_string password
32 proto_config_add_string pincode
33 proto_config_add_string delay
34 proto_config_add_string modes
35 proto_config_add_string bus
39 local driver usb devicename desc bus
43 if [ -L "/sys/bus/usb/devices/${bus}" ]; then
44 if [ -f "/sys/bus/usb/devices/${bus}/idVendor" ] \
45 && [ -f "/sys/bus/usb/devices/${bus}/idProduct" ]; then
47 vendor
=$
(cat /sys
/bus
/usb
/devices
/${bus}/idVendor
)
48 product
=$
(cat /sys
/bus
/usb
/devices
/${bus}/idProduct
)
49 [ -f /lib
/network
/wwan
/$vendor:$product ] && {
50 usb
=/lib
/network
/wwan
/$vendor:$product
54 echo "wwan[$$]" "Specified usb bus ${bus} was not found"
55 proto_notify_error
"$interface" NO_USB
56 proto_block_restart
"$interface"
60 echo "wwan[$$]" "Searching for a valid wwan usb device..."
61 for a
in `ls /sys/bus/usb/devices`; do
63 [ -z "$usb" -a -f /sys
/bus
/usb
/devices
/$a/idVendor
-a -f /sys
/bus
/usb
/devices
/$a/idProduct
] ||
continue
64 vendor
=$
(cat /sys
/bus
/usb
/devices
/$a/idVendor
)
65 product
=$
(cat /sys
/bus
/usb
/devices
/$a/idProduct
)
66 [ -f /lib
/network
/wwan
/$vendor:$product ] && {
67 usb
=/lib
/network
/wwan
/$vendor:$product
73 echo "wwan[$$]" "Using wwan usb device on bus $devicename"
76 local old_cb control data
78 json_set_namespace wwan old_cb
80 json_load
"$(cat "$usb")"
82 json_get_vars desc control data
83 json_set_namespace
"$old_cb"
85 [ -n "$control" -a -n "$data" ] && {
86 ttys
=$
(ls -d /sys
/bus
/usb
/devices
/$devicename/${devicename}*/tty?
* /sys
/bus
/usb
/devices
/$devicename/${devicename}*/tty
/tty?
* |
sed "s/.*\///g" |
tr "\n" " ")
87 ctl_device
=/dev
/$
(echo $ttys | cut
-d" " -f $
((control
+ 1)))
88 dat_device
=/dev
/$
(echo $ttys | cut
-d" " -f $
((data
+ 1)))
93 [ -z "$ctl_device" ] && for net
in $
(ls /sys
/class
/net
/ |
grep -e wwan
-e usb
); do
94 [ -z "$ctl_device" ] ||
continue
96 [ $
(readlink
/sys
/class
/net
/$net |
grep $bus) ] ||
continue
98 driver
=$
(grep DRIVER
/sys
/class
/net
/$net/device
/uevent | cut
-d= -f2)
101 ctl_device
=/dev
/$
(ls /sys
/class
/net
/$net/device
/usbmisc
)
103 sierra_net|cdc_ether|
*cdc_ncm
)
104 ctl_device
=/dev
/$
(cd /sys
/class
/net
/$net/; find ..
/..
/..
/ -name ttyUSB
* |
xargs -n1 basename |
head -n1)
108 echo "wwan[$$]" "Using proto:$proto device:$ctl_device iface:$net desc:$desc"
111 [ -n "$ctl_device" ] ||
{
112 echo "wwan[$$]" "No valid device was found"
113 proto_notify_error
"$interface" NO_DEVICE
114 proto_block_restart
"$interface"
118 uci_set_state network
"$interface" driver
"$driver"
119 uci_set_state network
"$interface" ctl_device
"$ctl_device"
120 uci_set_state network
"$interface" dat_device
"$dat_device"
123 qmi_wwan
) proto_qmi_setup $@
;;
124 cdc_mbim
) proto_mbim_setup $@
;;
125 sierra_net
) proto_directip_setup $@
;;
126 comgt
) proto_3g_setup $@
;;
127 cdc_ether|
*cdc_ncm
) proto_ncm_setup $@
;;
131 proto_wwan_teardown
() {
133 local driver
=$
(uci_get_state network
"$interface" driver
)
134 ctl_device
=$
(uci_get_state network
"$interface" ctl_device
)
135 dat_device
=$
(uci_get_state network
"$interface" dat_device
)
138 qmi_wwan
) proto_qmi_teardown $@
;;
139 cdc_mbim
) proto_mbim_teardown $@
;;
140 sierra_net
) proto_directip_teardown $@
;;
141 comgt
) proto_3g_teardown $@
;;
142 cdc_ether|
*cdc_ncm
) proto_ncm_teardown $@
;;