首先,我用的是广和通公司开发、生产的G600 GSM/GPRS模块开发套件(型号:GT8611-G6)。G600开发套件是广和通公司以FIBOCOM G600 GSM/GPRS模块为基础,按工业标准开发的无线数据通信产品。以下是具体过程:
一.配置内核
在以前的基础上配置内核支持ppp上网功能:
make menuconfig
DeviceDrivers--→
Network devicesupport---→
<*> PPP (point-to-point protocol) support
[*] PPP multilink support (EXPERIMENTAL)
<*> PPP support for async serial ports
<*> PPP support for sync tty ports
<*> PPP Deflate compression
<*> PPP BSD-Compress compression
二、制作chat和pppd工具
lingyun@localhost apps]$ mkdir ppp
[lingyun@localhost apps]$ cd ppp/
[lingyun@localhost ppp]$ ls
[lingyun@localhost ppp]$ wget ftp://ftp.samba.org/pub/ppp/ppp-2.4.4.tar.gz
[lingyun@localhost ppp]$ tar zxf ppp-2.4.4.tar.gz
[lingyun@localhost ppp]$ ls
ppp-2.4.4 ppp-2.4.4.tar.gz
[lingyun@localhost ppp]$ cd ppp-2.4.4
[lingyun@localhost ppp-2.4.4]$ ls
Changes-2.3 contrib linux pppdump README.eap-srp README.MSCHAP81 scripts
chat etc.ppp modules pppstats README.linux README.pppoe SETUP
common FAQ PLUGINS README README.MPPE README.pwfd solaris
configure include pppd README.cbcp README.MSCHAP80 README.sol2
[lingyun@localhost ppp-2.4.4]$ ./configure
Configuring for Linux
Creating Makefiles.
Makefile <= linux/Makefile.top
pppd/Makefile <= pppd/Makefile.linux
pppstats/Makefile <= pppstats/Makefile.linux
chat/Makefile <= chat/Makefile.linux
pppdump/Makefile <= pppdump/Makefile.linux
pppd/plugins/Makefile <= pppd/plugins/Makefile.linux
pppd/plugins/rp-pppoe/Makefile <= pppd/plugins/rp-pppoe/Makefile.linux
pppd/plugins/radius/Makefile <= pppd/plugins/radius/Makefile.linux
pppd/plugins/pppoatm/Makefile <= pppd/plugins/pppoatm/Makefile.linux
配置chat
[lingyun@localhost ppp-2.4.4]$ cd chat
[lingyun@localhost chat]$ ls
chat.8 chat.c Makefile Makefile.linux Makefile.sol2
[lingyun@localhost chat]$ vim chat.c
168 if (timeout_next) {
1169 timeout_next = 0;
1170 s = clean(s,0); /*add by liuchengdeng*/
1171 timeout = atoi(s);
1172 free(s); /* add by liuchengdeng */
1173
1174 if (timeout <= 0)
1175 timeout = DEFAULT_CHAT_TIMEOUT;
[lingyun@localhost chat]$ vim Makefile
3 DESTDIR = $(INSTROOT)/usr/local
4 BINDIR = $(DESTDIR)/sbin
5 MANDIR = $(DESTDIR)/share/man/man8
6 CC=/opt/buildroot-2011.11/arm920t/usr/bin/arm-linux-gcc #add by liuchengdeng
7
8 CDEF1= -DTERMIOS # Use the termios structure
18
19 all: chat
20
21 chat: chat.o
22 $(CC) -static -o chat chat.o # modify by liuchengdeng
23
24 chat.o: chat.c
[lingyun@localhost chat]$ cd ..
[lingyun@localhost ppp-2.4.4]$ ls
Changes-2.3 contrib linux pppd README.cbcp README.MSCHAP80 README.sol2
chat etc.ppp Makefile pppdump README.eap-srp README.MSCHAP81 scripts
common FAQ modules pppstats README.linux README.pppoe SETUP
configure include PLUGINS README README.MPPE README.pwfd solaris
配置 pppd
[lingyun@localhost ppp-2.4.4]$ cd pppd
[lingyun@localhost ppp-2.4.4]$vim Makefile
添加交叉编译器的路径:
CC =/opt/buildroot-2011.11/arm920t/usr/bin/arm-linux-gcc
注释掉以下几个配置:
48#MPPE=y
53#FILTER=y
70#PLUGIN=y
[lingyun@localhost pppd]$ vim auth.c
修改如下:
1315 hadchap = -1;
1316 //ao->neg_upap = !refuse_pap && (passwd[0] != 0 || get_pap_passwd(NULL));
1317 ao->neg_upap = !refuse_pap; //modify by liuchengdeng
1318 ao->neg_chap = (!refuse_chap || !refuse_mschap || !refuse_mschap_v2)
[lingyun@localhost chat]$ cd ..
[lingyun@localhost ppp-2.4.4]$ make
编译成功后可以看到:
lingyun@localhost ppp-2.4.4]$ cd chat
[lingyun@localhost chat]$ ls
chat chat.8 chat.c chat.o Makefile Makefile.linux Makefile.sol2
[lingyun@localhost chat]$ cd ..
[lingyun@localhost ppp-2.4.4]$ cd pppd
[lingyun@localhost pppd]$ ls
auth.c chap_ms.o eui64.c ipxcp.o md4.c plugins spinlock.h upap.c
auth.o chap-new.c eui64.h lcp.c md4.h pppcrypt.c spinlock.o upap.h
cbcp.c chap-new.h fsm.c lcp.h md4.o pppcrypt.h srp-entry.8 upap.o
cbcp.h chap-new.o fsm.h lcp.o md5.c pppcrypt.o srp-entry.c utils.c
ccp.c demand.c fsm.o magic.c md5.h pppd sys-linux.c utils.o
ccp.h demand.o ipcp.c magic.h md5.o pppd.8 sys-linux.o
ccp.o eap.c ipcp.h magic.o multilink.c pppd.h sys-solaris.c
chap-md5.c eap.h ipcp.o main.c multilink.o ppp.pam tdb.c
chap-md5.h eap.o ipv6cp.c main.o options.c sha1.c tdb.h
chap-md5.o ecp.c ipv6cp.h Makefile options.o sha1.h tdb.o
chap_ms.c ecp.h ipxcp.c Makefile.linux patchlevel.h sha1.o tty.c
chap_ms.h ecp.o ipxcp.h Makefile.sol2 pathnames.h spinlock.c tty.o
把编译生成的chat和pppd文件下载到开发板的usr/sbin/目录下如下
[root@root /]# ls usr/sbin/
apm event_button msm_test s3c_adc test
chat gprs-chat my_msm_test s3c_button test_s3c_led
dev_adc ifup-ppp plat_led_test serial
dropbear led_test pppd ssh
三、配置上网相关的脚本
添加默认路由文件:
[root@root /]#mkdir apps/etc/ppp/gprs-chat
[root@root /]# cd etc
[root@root /etc]# vim resolv.conf
nameserver 4.2.2.2
nameserver 8.8.8.8
配置拨号脚本:
[root@root /]# cd usr/sbin/
[root@root sbin]# vim ifup-ppp
#!/bin/sh
# FILE:/usr/sbin/ifup-ppp
# This file used to do PPP dial up.
#--------------------------------------------------
# Function definition here
#--------------------------------------------------
usage()
{
prog=`basename $0`
echo "$prog Usage: $prog [-d /dev/ttyUSB0] [-a apn] [-u username] [-p password] [-v chap/pap] [-i ip
echo ""
echo " This shell script used to do pppd dial up on GPRS/3G modem, if no options gived, it"
echo "will use the default configure file \"$network_cfg_dir/ifcfg-pppXX\". If get options"
echo "in this command, it will use the option from the command line, and be careful the -d"
echo "option must be given to specify the modem device."
echo ""
echo "pppXX: Required, specify the dial up generated PPP device, such as ppp10."
echo "-d: Required, if use command line options, specify the modem TTY device."
echo "-a: Option, APN(Access Point Name) for the SIM card provider."
echo "-u: Option, username for the GPRS login if needed."
echo "-p: Option, password for the GPRS login if needed."
echo "-v: Option, authenticate method, pap or chap."
echo "-i: Option,
echo "Example: ifup-ppp -d /dev/ttyUSB0 -a 3gnet -u uid -p pwd ppp10"
echo ""
echo "Copyright (C) 2011 GuoWenxue
exit
}
#===============================
# Global variable declare =
#===============================
modem=
inf=
apn=
uid=
pwd=
# Configure file
if [ -z "$network_cfg_dir" ]; then
export network_cfg_dir=/apps/etc/network
fi
#===============================
# Shell body start here =
#===============================
if [ $# -lt 1 ] ; then
usage;
elif [ $# -eq 1 ] ; then
inf=$1
conf=ifcfg-$inf
cd $network_cfg_dir
if [ ! -f $conf ]; then
echo "================================================================================="
echo "ERROR: $inf dial up configure file \"$network_cfg_dir/$conf\" not found!"
echo "================================================================================="
echo ""
usage;
exit;
fi
. $conf
modem=$MODEM
apn=$APN
uid=$USERNAME
pwd=$PASSWORD
vrfy=$VERIFY
ipaddr=$IPADDR
cd -
else
while getopts "a:d:u:p:v:hi:" Option
do
case $Option in
d) modem=$OPTARG ;;
i) ipaddr=$OPTARG ;;
a) apn=$OPTARG ;;
u) uid=$OPTARG ;;
p) pwd=$OPTARG ;;
v) vrfy=$OPTARG ;;
h) pwd=$OPTARG; usage ;;
esac
done
shift $(($OPTIND - 1))
inf=$*
fi
if [ -z "$modem" ] ; then
usage;
exit;
fi
if [ ! -c "$modem" ] ; then
echo "ERROR: Modem device $modem doesn't exist!"
exit
fi
inf=$( echo $inf | tr -cd '[0-9]\n' )
# Chat script need these two variable
export APN=$apn
export DIALNUM="*99***1#"
chat_script="/etc/ppp/gprs-chat"
#======================
# The pppd options #
#======================
options="$modem 115200"
if [ -n "$uid" -a -n "pwd" ]; then
options=$options" name $uid"
options=$options" password $pwd"
fi
if [ -n "$inf" ] ; then
options=$options" unit $inf"
fi
if [ "$vrfy" == "chap" ] ; then
options=$options" require-chap"
else
options=$options" require-pap"
fi
# Restart after idle X second
options=$options" idle 86400"
options=$options" refuse-mschap refuse-mschap-v2 refuse-eap"
options=$options" nodefaultroute updetach"
options=$options" debug"
options=$options" lcp-echo-failure 3 lcp-echo-interval 5"
options=$options" ipcp-accept-local ipcp-accept-remote ipcp-restart 50"
options=$options" modem crtscts"
if [ -n "$ipaddr" ] ; then
options=$options" $ipaddr"
fi
# Let the phone figure out all the IP addresses
options=$options" noipdefault"
options=$options" noauth"
# No ppp compression
options=$options" novj noccp novjccomp"
# For sanity, keep a lock on the serial line
options=$options" lock"
#=================================
# PPP dial up command start up #
#=================================
set -x
#chat option should can be: -v -E -V -f
pppd $options connect "/usr/sbin/chat -v -E -f $chat_script"
if [ -d /sys/class/net/ppp$inf ] ; then
ip route add default dev ppp$inf metric 10
#ip route add default dev ppp$inf
/apps/tools/gatewayD > /dev/null 2>&1
fi
以上是我们实验室用的拨号脚本。
当GPRS模块都准备好后(SIM可以工作),直接运行拨号脚本就可以了。
四、拨号上网
[root@root /]# ifup-ppp -d /dev/ttyS1 -a 3gnet ppp10 (/dev/ttyS1 是串口设备文件,3gnet 表示是联通的卡,PPP10创建的网卡名字)
+ pppd /dev/ttyS1 115200 unit 10 require-pap idle 86400 refuse-mschap refuse-mschap-v2 refuse-eap nodefaultroute updetach debug lcp-echo-failure 3 lcp-echo-interval 5 ipcp-accept-local ipcp-accept-remote ipcp-restart 50 modem crtscts noipdefault noauth novj noccp novjccomp lock connect /usr/sbin/chat -v -E -f /etc/ppp/gprs-chat
+ requesting data connection
+ connected
Script /usr/sbin/chat -v -E -f /etc/ppp/gprs-chat finished (pid 824), status = 0x0
Serial connection established.
using channel 4
Using interface ppp10
Connect: ppp10 <--> /dev/ttyS1
sent [LCP ConfReq id=0x1
rcvd [LCP ConfReq id=0x1
sent [LCP ConfAck id=0x1
rcvd [LCP ConfRej id=0x1
sent [LCP ConfReq id=0x2
rcvd [LCP ConfAck id=0x2
sent [LCP EchoReq id=0x0 magic=0x0]
No secret found for PAP login
sent [PAP AuthReq id=0x1 user="root" password=
rcvd [LCP EchoRep id=0x0 magic=0x0]
rcvd [PAP AuthAck id=0x1 "Login OK"]
Remote message: Login OK
PAP authentication succeeded
sent [IPCP ConfReq id=0x1
sent [LCP EchoReq id=0x1 magic=0x0]
rcvd [LCP EchoRep id=0x1 magic=0x0]
sent [LCP EchoReq id=0x2 magic=0x0]
rcvd [LCP EchoRep id=0x2 magic=0x0]
sent [LCP EchoReq id=0x3 magic=0x0]
rcvd [LCP EchoRep id=0x3 magic=0x0]
sent [LCP EchoReq id=0x4 magic=0x0]
rcvd [LCP EchoRep id=0x4 magic=0x0]
sent [LCP EchoReq id=0x5 magic=0x0]
rcvd [LCP EchoRep id=0x5 magic=0x0]
sent [LCP EchoReq id=0x6 magic=0x0]
rcvd [LCP EchoRep id=0x6 magic=0x0]
sent [LCP EchoReq id=0x7 magic=0x0]
rcvd [LCP EchoRep id=0x7 magic=0x0]
sent [LCP EchoReq id=0x8 magic=0x0]
rcvd [LCP EchoRep id=0x8 magic=0x0]
sent [LCP EchoReq id=0x9 magic=0x0]
rcvd [LCP EchoRep id=0x9 magic=0x0]
sent [IPCP ConfReq id=0x1
rcvd [IPCP ConfReq id=0x1
sent [IPCP ConfAck id=0x1
rcvd [IPCP ConfNak id=0x1
sent [IPCP ConfReq id=0x2
sent [LCP EchoReq id=0xa magic=0x0]
rcvd [IPCP ConfAck id=0x2
local IP address 10.15.95.177
remote IP address 192.200.1.21
+ [ -d /sys/class/net/ppp10 ]
+ ip route add default dev ppp10 metric 10
+ /apps/tools/gatewayD
说明成功了
[root@root /]# ifconfig
eth0 Link encap:Ethernet HWaddr 72:93:14:05:0A:A3
inet addr:192.168.1.111 Bcast:192.168.1.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:26449 errors:0 dropped:4 overruns:0 frame:0
TX packets:8597 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:4704472 (4.4 MiB) TX bytes:2261973 (2.1 MiB)
Interrupt:51 Base address:0x4300
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
ppp10 Link encap:Point-to-Point Protocol
inet addr:10.15.95.177 P-t-P:192.200.1.21 Mask:255.255.255.255
UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1500 Metric:1
RX packets:3 errors:0 dropped:0 overruns:0 frame:0
TX packets:4 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:3
RX bytes:30 (30.0 B) TX bytes:40 (40.0 B)
[root@root /]# ping 4.2.2.2
PING 4.2.2.2 (4.2.2.2): 56 data bytes
64 bytes from 4.2.2.2: seq=0 ttl=48 time=897.936 ms
64 bytes from 4.2.2.2: seq=1 ttl=48 time=591.802 ms
64 bytes from 4.2.2.2: seq=2 ttl=48 time=573.460 ms
^C
--- 4.2.2.2 ping statistics ---
4 packets transmitted, 3 packets received, 25% packet loss
round-trip min/avg/max = 573.460/687.732/897.936 ms
[root@root /]# wget ftp://ftp.samba.org/pub/ppp/ppp-2.4.4.tar.gz
Connecting to ftp.samba.org (216.83.154.106:21)
ppp-2.4.4.tar.gz 1% | | 9436 0:04:48 ETA^
(我手机流量有限在这里就停止下载了)