标签:
一:编辑Linux内核,使其支持PPP拨号上网
[hulu@centos6 linux-3.0]$ make menuconfig
Device dirver --->Network device
*** CAIF transport drivers ***
<*> PPP (point-to-point protocol) support
[*] PPP multilink support (EXPERIMENTAL)
[*] PPP filtering
<*> PPP support for async serial ports
<*> PPP support for sync tty ports
<*> PPP Deflate compression
<*> PPP BSD-Compress compression
<*> PPP MPPE compression (encryption) (EXPERIMENTAL)
<*> PPP over Ethernet (EXPERIMENTAL)
二:编译ppp-2.4.4.tar.gz
下载ppp-2.4.4.tar.gz
http://download.csdn.net/detail/zhyustar/1531748
[hulu@centos6 ~]$ mkdir GPRS
[hulu@centos6 ~]$ cd GPRS
[hulu@centos6 GPRS]$ tar -xzf ppp-2.4.4.tar.gz
[hulu@centos6 GPRS]$ ls
ppp-2.4.4 ppp-2.4.4.tar.gz
[hulu@centos6 GPRS]$ cd ppp-2.4.4
[hulu@centos6 ppp-2.4.4]$ ls
[hulu@centos6 ppp-2.4.4]$ ./configure
[hulu@centos6 ppp-2.4.4]$ cd chat/
[hulu@centos6 chat]$ ls
chat.8 chat.c Makefile Makefile.linux Makefile.sol2[hulu@centos6 chat]$ vim chat.c
[hulu@centos6 chat]$ vim Makefile
[hulu@centos6 chat]$ cd ../pppd[hulu@centos6 pppd]$ vim auth.c
[hulu@centos6 pppd]$ vim Makefile
[hulu@centos6 ppp-2.4.4]$ make[hulu@centos6 ppp-2.4.4]$ cd chat
[hulu@centos6 chat]$ ls
chat chat.8 chat.c chat.o Makefile Makefile.linux Makefile.sol2[hulu@centos6 chat]$ file chat
chat: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), not stripped[hulu@centos6 pppd]$ file pppd
pppd: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), not stripped
把生成的pppd 和chat 下载到自己的开发板上,放在/usr/sbin中,并修改权限
如:chmod 777 chat
三:制作脚本文件
gprs模块ppp拨号上网的时候需要如下几个配置文件:
<1> /etc/ppp/peers/gprs
<2>/etc/ppp/chat-gprs-connect
默认情况在开发板的/etc/ppp/目录下建立文件gprs-connect-chat,它是在ppp底层会话的时候给chat进程的参数,每行是一个“期望/发送”的组合序列。
一个简单的chat脚本有下面的结构:
“” AT
OK ATDT dialnumber
CONNECT “”
1) MODEM期望空字符串。这句话的意思直接理解就是MODEM不管收到什么字符串,先发出字符串AT;
2) 期望收到“OK”字符串,然后发送字符串“ATDT dialnumber”
3) 如果收到“CONNECT”,就不再发送,认为数据链路已建立连接。
4)如果需要进行超时控制,就可以加入如下字段:
TIMEOUT 10
5)如果要增加对特殊情况的处理,就加入下面字段:
ABORT BUSY
ABORT NO ANSWER
ABORT RINGING
意思是:如果收到字符串“BUSY”、“NO ANSWER”、“RINGING”就退出执行。
编写chat脚本如下:以下都是在开发板上操作
~>cd /etc
~>mkdir ppp
~>cd ppp
~>vi gprs-connect-chat
#/etc/ppp/gprs-connect-chat
#Copyright (c) 2016 hulu luhu918@gmail.com
# This is second part of the ppp dial script. It will perform the connection
ABORT ‘BUSY‘
ABORT ‘NO ANSWER‘
ABORT ‘NO CARRIER‘
ABORT ‘NO DIALTONE‘
ABORT ‘ERROR‘
ABORT ‘\nRING\r\n\r\nRING\r‘
‘‘ \rAT
OK ATE0
SAY "Press CTRL-C to break the connection process.\n"
OK ‘AT+CGDCONT=1,"IP","3GNET"‘ //isp接入网关为中国联通的3GNET
OK ATDT*99# //这里要改成自己的运营商号码。。我的这个号码是联通的
#拨号上网
SAY "Waiting for connect...\n"
CONNECT ‘‘
SAY "Connect Success!\n"
编写gprs配置文件:
它的作用是给pppd进程提供配置参数(详见man 8 pppd的输出内容,如果出现问题这个将是非常重要的参考页),内容如下:
~>mkdir peers
~>cd peers
~>vi gprs
#/etc/ppp/peers/gprs
# Usage: root>pppd call gprs
#set seriral
/dev/ttyS1
# set baudrate
115200
# set flowdate 可能你的串口是需要crtscts,硬件流控的,这是由你的串口决定的,一般嵌入式系统的串口没有带硬件流控,也不需要就加nocrtscts
nocrtscts
#set debug ,send message to /var/log/messages
debug
#To keep pppd on the terminal
nodetach
# Accept the peer‘s idea of our local IP address
ipcp-accept-local
# Accept the peer‘s idea of its (remote) IP address
ipcp-accept-remote
#dial up connetion as the default route
defaultroute
usepeerdns
Noipdefault
user hulu
connect ‘/usr/sbin/chat -s -v -f /etc/ppp/chat-gprs-connect‘
pppd调用chat会话进程接入对端isp,启动对端的pppd,然后本地pppd与对端的pppd一起进行协商网络参数和chap/pap认证,成功后,再进行ncp层的ip的分配。
四:在开发板上测试ppp拨号
要用ping,你需要将eth0即网口给禁用掉,这样ping才会通过ppp0端口寻找路由连接外网
~>ifconfig eth0 down
~>pppd call gprs & //&是后台执行的意思。。只有这条后台执行。。我们才能在前台检测是否上网
如果出现ping得通4.2.2.2,却png不通www.baidu.com,那就是DNS的问题
解决办法:
你可能需要将/etc/ppp/resolv.conf(内容被新获得的dns取代)内容拷贝到/etc/resolv.conf中或者做一个到/etc/resolv.conf的链接
也可以直接编辑/etc/resolv.conf
~>vi /etc/resolv.conf
nameserver 4.2.2.2
nameserver 8.8.8.8
~>ifconfig
至此关于sim900GPRS模块ppp拨号上网成功实现,各位读友们有问题直接私聊我!!
标签:
原文地址:http://blog.csdn.net/hulu_arm/article/details/51010696