Linux嵌入式中PPP和PPP-ON脚本的编写


在Linux嵌入式中,我们可以来完成GPRS脚本的编写。其中涉及了PPP的内容。这篇文章中,我们就讲解了如何在Liod平台上进行ppp拨号,实现GPRS上网的知识。首先我们来看一下硬件平台:亿道Liod平台基于PXA270)。操作系统:嵌入式Linux。

第一步:如果内核不支持ppp拨号,则要重新编译内核,添加对ppp的支持

  1. <*> PPP (point-to-point protocol) support                 
  2. [*]    PPP multilink support (EXPERIMENTAL)                  
  3. <*>    PPP support for async serial ports                    
  4. <*>    PPP support for sync tty ports                       
  5. <*>    PPP Deflate compression                               
  6. <*>    PPP BSD-Compress compression  

然后重新烧写新生成的内核映象!
   
第二步:下载ppp-2.4.1源码包,交叉编译生成拨号所需的pppd和chat这两个程序.

源代码下载网址: ftp://ftp.samba.org/pub/ppp/ 解压源代码包,进入目录,进行交叉编译,这里所用的交叉编译器是arm-linux-gcc(version 3.3.2)

  1. #cd /root/gprs/ppp-2.4.1  
  2. #./configure  
  3. #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脚本具体要修改的内容如下:

  1.      TELEPHONE=*99***1#      # The telephone number for the connection  
  2.      ACCOUNT=                       # The account name for logon (as in 'George   
  3. Burns')  
  4.      PASSWORD=                    # The password for this account (and 'Gracie A  
  5. llen')  
  6.      LOCAL_IP=0.0.0.0             # Local IP address if known. Dynamic = 0.0.0.0  
  7.  
  8.      REMOTE_IP=0.0.0.0          # Remote IP address if desired. Normally 0.0.0.0  
  9.  
  10.      NETMASK=255.255.255.0 # The proper netmask if needed  
  11.  
  12. # Export them so that they will be available at 'ppp-on-dialer' time.  
  13. export TELEPHONE ACCOUNT     
  14. DIALER_SCRIPT=/mnt/cf/pppdial/ppp-on-dialer  
  15.  
  16. # Initiate the connection  
  17.  
  18. exec /mnt/cf/pppdial/pppd debug lock nocrtscts   /dev/ttyS1 19200 \  
  19. asyncmap 20A0000 escape FF kdebug 0 $LOCAL_IP:$REMOTE_IP \  
  20. noipdefault netmask $NETMASK defaultroute connect $DIALER_SCRIPT usepeerdns 

2.修改ppp-on-dialer脚本:

  1. #!/bin/sh  
  2. #  
  3. # This is part 2 of the ppp-on script. It will perform the connection  
  4. # protocol for the desired connection.  
  5. #  
  6. exec /sbin/chat -v       \  
  7. TIMEOUT   5     \  
  8. ABORT   '\nBUSY\r'    \  
  9. ABORT   '\nNO ANSWER\r'    \  
  10. ABORT   '\nRINGING\r\n\r\nRINGING\r' \  
  11.          ''   AT+CGDCONT=1,IP,CMNET          \  
  12.          'OK'             AT     \  
  13. 'OK-+++\c-OK' ATH0     \  
  14. TIMEOUT   30     \  
  15. OK   ATDT$TELEPHONE    \  
  16. CONNECT   

3.在Liod板上/etc/ppp/resolv.conf文件中加上

  1. nameserver 211.136.20.203  
  2. nameserver 211.136.18.171 

第四步:连接gprs

gprs模块通过串口连接到板子上的蓝牙串口(/dev/ttyS1),因为Liod板的FFUART用来做调试串口了,即使通过telnet登录Liod,而将串口0腾出来用来连接GPRS模块,拨号也会失败.因为从串口0会输出调试信息,对拨号过程造成干扰.

关闭默认网络设备: ifconfig eth0 down

pppd拨号:   ./ppp-on

(注意:一定要先关闭闭eth0再拨号,否则即使拨号能得到IP地址,也会因为路由错误而访问不了外网)

相关内容