4 # Copyright (C) 2011 shibby
7 LOCK
="/tmp/switch3g.lock"
8 if [ -f $LOCK ]; then #lock exist
9 logger
3G MODEM
- previous proces of switch3g still working
13 DEVNR
=`nvram get modem_dev`
14 PIN
=`nvram get modem_pin`
15 IS_PIN
=`nvram get modem_pin | wc -w`
16 MODE
=`nvram get wan_proto`
18 if [ "$MODE" == "lte" ]; then
23 DEV0
=`cat /proc/bus/usb/devices | grep Driver | grep cdc_acm | wc -l`
24 DEV1
=`cat /proc/bus/usb/devices | grep Driver | grep option | wc -l`
25 DEV2
=`cat /proc/bus/usb/devices | grep Driver | grep sierra | wc -l`
26 DEV3
=`cat /proc/bus/usb/devices | grep Driver | grep usbserial | wc -l`
28 if [ "$DEV0" -gt 0 ]; then
29 logger
3G MODEM already found
- using cdc-acm module
30 nvram
set 3g_module
=cdc-acm
31 if [ "$IS_PIN" == "1" ]; then
32 PINCODE
="$PIN" gcom
-d /dev
/$DEVNR -s /etc
/gcom
/setpin.gcom
36 elif [ "$DEV1" -gt 0 ]; then
37 logger
3G MODEM already found
- using option module
38 nvram
set 3g_module
=option
39 if [ "$IS_PIN" == "1" ]; then
40 PINCODE
="$PIN" gcom
-d /dev
/$DEVNR -s /etc
/gcom
/setpin.gcom
44 elif [ "$DEV2" -gt 0 ]; then
45 logger
3G MODEM already found
- using sierra module
46 nvram
set 3g_module
=sierra
47 if [ "$IS_PIN" == "1" ]; then
48 PINCODE
="$PIN" gcom
-d /dev
/$DEVNR -s /etc
/gcom
/setpin.gcom
52 elif [ "$DEV3" -gt 0 ]; then
53 logger
3G MODEM already found
- using usbserial module
54 nvram
set 3g_module
=usbserial
55 if [ "$IS_PIN" == "1" ]; then
56 PINCODE
="$PIN" gcom
-d /dev
/$DEVNR -s /etc
/gcom
/setpin.gcom
61 #modem not found, try detect
63 DEVICES
=`lsusb | awk '{print $6}'`
65 for SWITCH
in $DEVICES; do
66 SEARCH
=`ls /etc/usb_modeswitch.d/$SWITCH | wc -l`
70 if [ "$SEARCH" == "1" ]; then
71 logger
3G MODEM FOUND
- $SWITCH - Switching ...
72 DV
=`echo $SWITCH | cut -d ":" -f1`
73 DP
=`echo $SWITCH | cut -d ":" -f2`
74 /usr
/sbin
/usb_modeswitch
-Q -c /etc
/usb_modeswitch.d
/$SWITCH -v $DV -p $DP
76 TEST1
=`cat /etc/usb_modeswitch.d/$SWITCH | grep "TargetVendor" | cut -d "=" -f2 | wc -l`
77 if [ "$TEST1" == "1" ]; then
78 VENDOR
=`cat /etc/usb_modeswitch.d/$SWITCH | grep "TargetVendor" | cut -d "=" -f2 | cut -d "x" -f2`
80 VENDOR
=`echo $SWITCH | cut -d ":" -f1`
83 TEST2
=`lsusb | awk '{print $6}' | grep $VENDOR | wc -l`
84 if [ "$TEST2" == "1" ]; then
85 PRODUCT
=`lsusb | awk '{print $6}' | grep $VENDOR | cut -d ":" -f2`
86 logger
3G MODEM ready
- $VENDOR:$PRODUCT
87 echo "$VENDOR:$PRODUCT" > /tmp
/3g.detect
92 #trying option and sierra module first
97 DEV0
=`cat /proc/bus/usb/devices | grep Driver | grep cdc_acm | wc -l`
98 DEV1
=`cat /proc/bus/usb/devices | grep Driver | grep option | wc -l`
99 DEV2
=`cat /proc/bus/usb/devices | grep Driver | grep sierra | wc -l`
100 if [ "$DEV0" -gt 0 ]; then
101 logger
3G MODEM ready
- using cdc-acm module
102 nvram
set 3g_module
=cdc-acm
103 if [ "$IS_PIN" == "1" ]; then
104 PINCODE
="$PIN" gcom
-d /dev
/$DEVNR -s /etc
/gcom
/setpin.gcom
108 elif [ "$DEV1" -gt 0 ]; then
109 logger
3G MODEM ready
- using option module
110 nvram
set 3g_module
=option
111 if [ "$IS_PIN" == "1" ]; then
112 PINCODE
="$PIN" gcom
-d /dev
/$DEVNR -s /etc
/gcom
/setpin.gcom
116 elif [ "$DEV2" -gt 0 ]; then
117 logger
3G MODEM ready
- using sierra module
118 nvram
set 3g_module
=sierra
119 if [ "$IS_PIN" == "1" ]; then
120 PINCODE
="$PIN" gcom
-d /dev
/$DEVNR -s /etc
/gcom
/setpin.gcom
125 logger
3G MODEM not found by cdc-acm
, option or sierra module. Trying usbserial ...
127 #rmmod cdc_acm //we can`t do that. I don`t know why...
132 IS_VENDOR
=`echo $VENDOR | wc -w`
133 if [ "$IS_VENDOR" -gt 0 ]; then
134 IS_PRODUCT
=`echo $PRODUCT | wc -w`
135 if [ "$IS_PRODUCT" -gt 0 ]; then
136 logger
3G MODEM
- loading module usbserial
138 insmod usbserial vendor
=0x
$VENDOR product
=0x
$PRODUCT
139 echo "$VENDOR:$PRODUCT" > /tmp
/3g.detect
143 DEV
=`cat /proc/bus/usb/devices | grep Driver | grep usbserial | wc -l`
144 if [ "$DEV" -gt 0 ]; then
145 logger
3G MODEM ready
- using usbserial module
146 nvram
set 3g_module
=usbserial
147 if [ "$IS_PIN" == "1" ]; then
148 PINCODE
="$PIN" gcom
-d /dev
/$DEVNR -s /etc
/gcom
/setpin.gcom
152 elif [ -f /tmp
/3g.detect
]; then
153 VENDOR
=`cat /tmp/3g.detect | cut -d ":" -f1`
154 PRODUCT
=`cat /tmp/3g.detect | cut -d ":" -f2`
155 TEST3
=`lsusb | grep $VENDOR | grep $PRODUCT | wc -l`
156 if [ "$TEST3" == "1" ]; then
157 logger
3G MODEM FOUND
- already switched
- Last know
$VENDOR:$PRODUCT
159 DEV
=`cat /proc/bus/usb/devices | grep Driver | grep usbserial | wc -l`
160 if [ "$DEV" -gt 0 ]; then
161 logger
3G MODEM ready
- using usbserial module
162 nvram
set 3g_module
=usbserial
163 if [ "$IS_PIN" == "1" ]; then
164 PINCODE
="$PIN" gcom
-d /dev
/$DEVNR -s /etc
/gcom
/setpin.gcom
169 logger
3G MODEM
- loading module
171 insmod usbserial vendor
=0x
$VENDOR product
=0x
$PRODUCT
172 echo "$VENDOR:$PRODUCT" > /tmp
/3g.detect
173 nvram
set 3g_module
=usbserial
174 if [ "$IS_PIN" == "1" ]; then
175 PINCODE
="$PIN" gcom
-d /dev
/$DEVNR -s /etc
/gcom
/setpin.gcom
182 #last change. try load usbserial for each usb devices
183 DEVICES
=`lsusb | awk '{print $6}'`
184 for SWITCH
in $DEVICES; do
185 VENDOR
=`echo $SWITCH | cut -d ":" -f1`
186 PRODUCT
=`echo $SWITCH | cut -d ":" -f2`
188 insmod usbserial vendor
=0x
$VENDOR product
=0x
$PRODUCT
190 DEV
=`cat /proc/bus/usb/devices | grep Driver | grep usbserial | wc -l`
191 if [ "$DEV" -gt 0 ]; then
192 logger
3G MODEM ready
- using usbserial module
193 nvram
set 3g_module
=usbserial
194 echo "$VENDOR:$PRODUCT" > /tmp
/3g.detect
196 if [ "$IS_PIN" == "1" ]; then
197 PINCODE
="$PIN" gcom
-d /dev
/$DEVNR -s /etc
/gcom
/setpin.gcom
209 if [ "$NO" == "1" ]; then
210 logger
3G MODEM not found ... sorry
213 #check signal strength
214 CSQ
=`gcom -d /dev/$DEVNR -s /etc/gcom/getstrength.gcom | grep "CSQ:" | cut -d " " -f2 | cut -d "," -f1`
216 logger
"3G MODEM Signal Strength: $DBM dBm"