Remove TCP Vegas support (ARM7)
[tomato.git] / release / src-rt-6.x.4708 / router / others / switch3g
blob5ccb83f3c31b5773fbcf2da092652a10033bbc4e
1 #!/bin/sh
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
10 exit 0
11 else
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
19 exit 0
22 # is modem ready?
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
34 rm $LOCK
35 break;
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
42 rm $LOCK
43 break;
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
50 rm $LOCK
51 break;
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
58 rm $LOCK
59 break;
60 else
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`
68 # vendor:product
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`
79 else
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
90 done
92 #trying option and sierra module first
93 modprobe cdc-acm
94 modprobe option
95 modprobe sierra
96 sleep 2
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
106 rm $LOCK
107 break;
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
114 rm $LOCK
115 break;
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
122 rm $LOCK
123 break;
124 else
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...
128 modprobe -r sierra
129 modprobe -r option
130 modprobe -r cdc-acm
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
137 rmmod 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
150 rm $LOCK
151 break;
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
166 rm $LOCK
167 break;
168 else
169 logger 3G MODEM - loading module
170 rmmod usbserial
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
177 rm $LOCK
178 break;
181 else
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`
187 rmmod usbserial
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
195 NO=0
196 if [ "$IS_PIN" == "1" ]; then
197 PINCODE="$PIN" gcom -d /dev/$DEVNR -s /etc/gcom/setpin.gcom
199 rm $LOCK
200 break;
201 else
202 NO=1
204 done
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`
215 DBM=$((-113+CSQ*2))
216 logger "3G MODEM Signal Strength: $DBM dBm"
218 #end script
221 #remove lock
222 rm $LOCK