wuwei
2025-05-28 7c16e785d2ece656fb0822f7b2514f59dd23e91d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/bin/sh
file=/work/config.json
jsoner=/usr/sbin/jsoner
 
apnEnable=`$jsoner -g $file 4g.apn`
enable=`$jsoner -g $file 4g.enable`
apn=`$jsoner -g $file 4g.apnName`
usr=`$jsoner -g $file 4g.user`
passwd=`$jsoner -g $file 4g.passwd`
auth=`$jsoner -g $file 4g.authType`
auth1=$auth
echo "4gEnable : $enable"
echo "apnEnable: $apnEnable"
echo "apn      : $apn"
echo "usr      : $usr"
echo "passwd   : $passwd"
echo "auth     : $authType"
 
#************************************************
 
if [ $enable != "true" ]
then 
    echo "4g is not enable. exit"
    exit
fi
 
if [ $auth -eq -1 ]
then 
     echo "auth is auto mode"
     auth=""
     auth1=0
fi
 
#HuaWei E909
initHwWeiModule()
{
echo -e "ATE0\n\r" > /dev/ttyUSB0 
if [ $apnEnable != "true" ]
then
    echo "use common mode, init hw."
    echo -e "AT^CURC=0\n\r" > /dev/ttyUSB0
    echo  "net cmd: AT^NDISDUP=1,1" 
    echo -e "AT^NDISDUP=1,1\n\r" > /dev/ttyUSB0
else
    echo "use apn mode;"
    echo -e "AT^CURC=0\n\r" > /dev/ttyUSB0
    echo -e "AT+CFUN=0\r\n" > /dev/ttyUSB0
    sleep 1
    echo -e "AT^AUTHDATA=0,$auth1,,\"$passwd\",\"$usr\"\r\n" > /dev/ttyUSB0
    sleep 1
    echo -e "AT+CGDCONT=0,\"IP\",\"$apn\"\r\n" > /dev/ttyUSB0
    sleep 1
    echo -e "AT+CFUN=1\r\n" > /dev/ttyUSB0
    sleep 1 
    echo -e "AT^NDISDUP=1,1,\"$apn\",\"$usr\",\"$passwd\",$auth\n\r" > /dev/ttyUSB0
    echo  "net cmd: AT^NDISDUP=1,1,\"$apn\",\"$usr\",\"$passwd\",$auth" 
fi
 
}
 
initEC20xx()
{
#if [ $apnEnable != "true" ]
#then
    echo "use common mode, init ec20x."
    echo -e "AT+QCFG=\"nat\",1\r\n" > /dev/ttyUSB2
    echo  "net cmd: AT+QNETDEVCTL=2,1,1" 
    echo -e "AT+QNETDEVCTL=2,1,1\r\n" > /dev/ttyUSB2
#else
#    echo "use apn mode;"
#fi
 
}
 
counter=0
while true
do
    if [ -c /dev/ttyUSB1 ]
    then
        echo "4g module is connected!"
        break;
    else 
        echo "4g module is not connected."
    fi
    counter=`expr $counter + 1`
    if [ $counter -gt 5 ]
    then
        echo "check times: $counter break!"
        exit
    fi
    sleep 1;
done
 
grep -rn "15c1" /proc/tty/driver/usbserial > /dev/null
if [ $? -eq 0 ]
then 
echo "init hw module"
initHwWeiModule
else 
echo "init ec module"
initEC20xx
fi
 
ifconfig usb0 up
udhcpc   -i usb0