在Linux嵌入式中,我们可以来完成GPRS脚本的编写。其中涉及了PPP的内容。这篇文章中,我们就讲解了如何在Liod平台上进行ppp拨号,实现GPRS上网的知识。首先我们来看一下硬件平台:亿道Liod平台(基于PXA270)。操作系统:嵌入式Linux。
第一步:如果内核不支持ppp拨号,则要重新编译内核,添加对ppp的支持
- <*> 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
然后重新烧写新生成的内核映象!
第二步:下载ppp-2.4.1源码包,交叉编译生成拨号所需的pppd和chat这两个程序.
源代码下载网址: ftp://ftp.samba.org/pub/ppp/ 解压源代码包,进入目录,进行交叉编译,这里所用的交叉编译器是arm-linux-gcc(version 3.3.2)
- #cd /root/gprs/ppp-2.4.1
- #./configure
- #make CC=arm-linux-gcc
拨号所用到的程序就是/root/gprs/ppp-2.4.1/pppd/下的pppd,和/root/gprs/ppp-2.4.1/chat/下的chat程序为了调试方便,我在CF卡上新建一个目录pppdial,将pppd和chat这两个程序拷贝到此目录下!
第三步:配置拨号脚本:
将 /root/gprs/ppp-2.4.1/scripts/下的ppp-on,ppp-on-dialer,ppp-off这三个脚本拷贝到/mnt/cf/pppdial/下,然后修改脚本:
1.ppp-on脚本具体要修改的内容如下:
- TELEPHONE=*99***1# # The telephone number for the connection
- ACCOUNT= # The account name for logon (as in 'George
- Burns')
- PASSWORD= # The password for this account (and 'Gracie A
- llen')
- LOCAL_IP=0.0.0.0 # Local IP address if known. Dynamic = 0.0.0.0
- REMOTE_IP=0.0.0.0 # Remote IP address if desired. Normally 0.0.0.0
- NETMASK=255.255.255.0 # The proper netmask if needed
- # Export them so that they will be available at 'ppp-on-dialer' time.
- export TELEPHONE ACCOUNT
- DIALER_SCRIPT=/mnt/cf/pppdial/ppp-on-dialer
- # Initiate the connection
- exec /mnt/cf/pppdial/pppd debug lock nocrtscts /dev/ttyS1 19200 \
- asyncmap 20A0000 escape FF kdebug 0 $LOCAL_IP:$REMOTE_IP \
- noipdefault netmask $NETMASK defaultroute connect $DIALER_SCRIPT usepeerdns
2.修改ppp-on-dialer脚本:
- #!/bin/sh
- #
- # This is part 2 of the ppp-on script. It will perform the connection
- # protocol for the desired connection.
- #
- exec /sbin/chat -v \
- TIMEOUT 5 \
- ABORT '\nBUSY\r' \
- ABORT '\nNO ANSWER\r' \
- ABORT '\nRINGING\r\n\r\nRINGING\r' \
- '' AT+CGDCONT=1,IP,CMNET \
- 'OK' AT \
- 'OK-+++\c-OK' ATH0 \
- TIMEOUT 30 \
- OK ATDT$TELEPHONE \
- CONNECT
3.在Liod板上/etc/ppp/resolv.conf文件中加上
- nameserver 211.136.20.203
- nameserver 211.136.18.171
第四步:连接gprs
gprs模块通过串口连接到板子上的蓝牙串口(/dev/ttyS1),因为Liod板的FFUART用来做调试串口了,即使通过telnet登录Liod,而将串口0腾出来用来连接GPRS模块,拨号也会失败.因为从串口0会输出调试信息,对拨号过程造成干扰.
关闭默认网络设备: ifconfig eth0 down
pppd拨号: ./ppp-on
(注意:一定要先关闭闭eth0再拨号,否则即使拨号能得到IP地址,也会因为路由错误而访问不了外网)