我们知道,网络的发展也嵌入到了移动通信当中。那么对于在一些移动设备上加入一些设置,就需要嵌入式的操作。那么这里我们就来讲解一下,基于嵌入式Linux下GPRS上网方案中,Linux内核的PPP 设置。
硬/软件环境
基于S3C2410的嵌入式系统,COM1连接PC,COM2连接SIM300 GPRS模块。该系统运行在Linux 2.6.14操作系统下,使用ppp套件通过SIM300进行PPP拨号。
让Linux内核支持PPP
进入Linux内核目录,执行#make menuconfig Network Device Support à <*> PPP (point-to-point protocol) support [*] PPP multilink support <*> PPP support for async serial ports <*> PPP support for sync tty ports <*> SLIP (serial line) support [*] CSLIP compressed headersppp套件安装
? 下载ppp:ftp://ftp.samba.org/pub/ppp ×最新版本为2.4.4 ? 将ppp-2.4.4.tar.gz解压至目录 ×这里默认ppp源码目录为$(PPP) #tar zxvf ppp-2.4.4.tar.gz ? 然后交叉编译ppp: #cd $(PPP) #./configure #make CC=/usr/local/arm/3.4.1/bin/arm-linux-gcc ×这里指定交叉编译器 ? 将ppp套件安装至嵌入式系统中: ×这里默认可执行文件在嵌入式系统下的目录为$(EMB_BIN) #cp $(PPP)/chat/chat $(EMB_BIN) #cp $(PPP)/pppd/pppd $(EMB_BIN) #cp $(PPP)/pppdump/pppdump $(EMB_BIN) #cp $(PPP)/pppstats/pppstats $(EMB_BIN) ×这里默认嵌入式系统的etc目录为$(EMB_ETC) #mkdir $(EMB_ETC)/ppp #cp $(PPP)/etc.ppp/* $(EMB_ETC)/pppppp套件配置
$(EMB_BIN)/dial-on.sh (GPRS启动脚本)
#!/bin/sh
#define dial_on function dial_on() { #test if pppd is running pppd_stat=`ifconfig|grep ppp|wc -l|cut -b 7-7` if [ $pppd_stat -gt 0 ] then echo "ppp connection's already started." else #close ethernet interface ifconfig eth0 down #ppp start pppd modem /dev/ttyS1 57600 nocrtscts lock connect "chat -v -f /etc/ppp/gprs-connect" user "" noauth debug defaultroute # pppd配置说明: # ttyS1:连接GPRS模块SIM300的串口 # 57600:GPRS的拨号速率 # nocrtscts:无流控 # lock:锁定设备 # connect “chat –v –f /etc/ppp/gprs-connect”:GPRS连接脚本文件 # user “”:用户名,这里是无 # noauth:无需认证 # debug:输出调试信息 # defaultroute:此拨号连接作为默认路由 echo "ppp is starting..." fi }
#dial on gprs dial_on
#wait for ppp's init sleep 5
pppd_stat=`ifconfig|grep ppp|wc -l|cut -b 7-7` if [ $pppd_stat -eq 0 ] then echo "trying 2nd time to call ppp" dial_on sleep 5 fi
pppd_stat=`ifconfig|grep ppp|wc -l|cut -b 7-7` if [ $pppd_stat -eq 0 ] then echo "pppd error!" echo "please check pppd's config files" fi
#open ethernet interface ifconfig eth0 up
#end
$(EMB_BIN)/dial-off.sh (关闭GPRS连接脚本)
#!/bin/sh
#get pppd's pid pid=`pidof pppd`
#if pppd process is running if [ -n $pid ] then #kill pppd kill $pid #open the ethernet interface ifconfig eth0 up echo "ppp connection is closed." else echo "ppp connection isn't existed." fi
#end
$(EMB_ETC)/ppp/gprs-connect (GPRS连接配置文件)
#GPRS连接超时设置 TIMEOUT 60 #若MODEM遇到BUSY、ERROR、NO CARRIER等信息时,停止拨号 ABORT "BUSY" ABORT "ERROR" ABORT "NO CARRIER" #外送“AT”指令 '' AT #当得到“OK”回应时,外送AT+CGDCONT=1,"IP","CMNET"命令 "OK" "AT+CGDCONT=1,/042IP/042,/042CMNET/042" #当得到“OK”回应时,外送ATDT*99***1#命令 "OK" "ATDT*99***1#" #当得到“CONNECT”回应时,拨号结束,程序退出 "CONNECT"
$(EMB_ETC)/ppp/pap-secrets (GPRS认证配置文件)
# Secrets for authentication using PAP # client server secret IP addresses '' * '' *
Linux内核PPP设置说明
(1) 还需要在$(EMB_ETC)/ppp目录下创建指向$(EMB_ETC)/resolv.conf的链接,用于指定PPP连接的DNS。
(2) 在ppp连接时,需要关闭eth连接。在脚本中已经设置好了,首先关闭eth连接,然后进行ppp连接,在ppp连接完成时,再开启eth连接。
(3) 最好在系统中开启syslogd进程,这样在/var/log/messages文件中会记录GPRS进行拨号的DEBUG信息,便于调试。
(4) 运行拨号脚本后,可以使用#ifconfig查看PPP连接信息。
我们知道,网络的发展也嵌入到了移动通信当中。那么对于在一些移动设备上加入一些设置,就需要嵌入式的操作。那么这里我们就来讲解一下,基于嵌入式Linux下GPRS上网方案中,Linux内核的PPP 设置。
硬/软件环境
基于S3C2410的嵌入式系统,COM1连接PC,COM2连接SIM300 GPRS模块。该系统运行在Linux 2.6.14操作系统下,使用ppp套件通过SIM300进行PPP拨号。
让Linux内核支持PPP
进入Linux内核目录,执行#make menuconfig Network Device Support à <*> PPP (point-to-point protocol) support [*] PPP multilink support <*> PPP support for async serial ports <*> PPP support for sync tty ports <*> SLIP (serial line) support [*] CSLIP compressed headersppp套件安装
? 下载ppp:ftp://ftp.samba.org/pub/ppp ×最新版本为2.4.4 ? 将ppp-2.4.4.tar.gz解压至目录 ×这里默认ppp源码目录为$(PPP) #tar zxvf ppp-2.4.4.tar.gz ? 然后交叉编译ppp: #cd $(PPP) #./configure #make CC=/usr/local/arm/3.4.1/bin/arm-linux-gcc ×这里指定交叉编译器 ? 将ppp套件安装至嵌入式系统中: ×这里默认可执行文件在嵌入式系统下的目录为$(EMB_BIN) #cp $(PPP)/chat/chat $(EMB_BIN) #cp $(PPP)/pppd/pppd $(EMB_BIN) #cp $(PPP)/pppdump/pppdump $(EMB_BIN) #cp $(PPP)/pppstats/pppstats $(EMB_BIN) ×这里默认嵌入式系统的etc目录为$(EMB_ETC) #mkdir $(EMB_ETC)/ppp #cp $(PPP)/etc.ppp/* $(EMB_ETC)/ppp
在之前的《Linux内核PPP套件设置 》一文中,我们已经讲解了相关的一些PPP 套件设置操作。那么这里,我们依据前文的一些内容,再来详细讲解一下arm上成功实现ppp拨号脚本的过程。
arm上成功实现ppp拨号脚本
ppp-on:
#!/bin/sh pppd modem -d -detach lock /dev/ttySAC0 19200 kdebug 4 file /etc/ppp/options crtscts noipdefault netmask 255.255.255.0 defaultroute connect /etc/ppp/chat-scriptppp-off:
#!/bin/sh ###################################################################### # # Determine the device to be terminated. # if [ "$1" = "" ]; then DEVICE = ppp0 else DEVICE =$1 fi ###################################################################### # # If the ppp0 pid file is present then the program is running. Stop it. if [ -r /var/run/$DEVICE.pid ]; then kill -INT `cat /var/run/$DEVICE.pid` # # If the kill did not work then there is no process running for this # pid. It may also mean that the lock file will be left. You may wish # to delete the lock file at the same time. if [ ! "$?" = "0" ]; then rm -f /var/run/$DEVICE.pid echo "ERROR: Removed stale pid file" exit 1 fi # # Success. Let pppd clean up its own junk. echo "PPP link to $DEVICE terminated." exit 0 fi # # The ppp process is not running for ppp0 echo "ERROR: PPP link is not active on $DEVICE" exit 1chat-script:
#!/bin/sh exec chat -v / TIMEOUT 5 / ABORT "BUSY" / ABORT "ERROR" / ABORT "NO CARRIER" / '' /rAT / OK 'AT+ CGDCONT = 1 ,"IP","CMNET"' / OK 'ATDT*99***1#' / CONNECT '' /设置DNS的resove.conf:
nameserver 211.136.20.203 nameserver 211.136.17.107到此,arm ppp拨号脚本就设置好了。那么希望本文的代码展示,能够让大家对此有所了解。
1. 内核配置支持pppd拨号:
make menuconfig
Device Drivers->
->Network Device Support->
<*> PPP (point-to-point protocol) support [*] PPP multilink support <*> PPP support for async serial ports <*> PPP support for sync tty ports <*> SLIP (serial line) support[*] CSLIP compressed headers
第一部分内核:其实这部分准确的来说应该是内核的配置,因为要使用pppoe,首先要内核选项的支持,我用的是linux 2.6.16的内核版本。需要在 -> Device Drivers -> Network device support -> PPP (point-to-point protocol) 中,选中所有ppp选项。一些老版本的内核可能还需要加上Universal TUN/TAP device driver support的选项(和ppp同级的)。
第二部分pppd:这部分相对来说还是很简单的,只需要下载ppp-2.4.1-ppp-2.4.4中的任一版本即可。解压,在终端中 输入./configure,然后执行make CC=arm-linux-gcc。进入pppd目录下将已经编译好的pppd文件拷贝至开发板端的文件系统的/usr/sbin目录下,这里有一个测试 pppd移植正确与否的判断,在版子上输入pppd,看是否有乱码出来,如果有乱码,恭喜这一步ok了。
第三部分pppoe:类似pppd的交叉编译,先下载rp-pppoe开发包,最好用3.7或3.8版本。进入src目录,先执 行./configure,然后对src下生产的Makefile文件进行修改,替换makefile 中的所有gcc为arm-linux-gcc,ar为arm-linux-ar,对src目录下的libevent目录下的Makefile也作此修改, 两个makefile改完之后,依次执行make,make install,把在pc主机下的/usr/sbin目录下生产的关于pppoe的所有文件(pppoe,pppoe-server,pppoe- sniff,pppoe-relay,pppoe-setup, pppoe-start,pppoe-stop,pppoe-status,pppoe-connect)拷贝到开发板的/usr/sbin目录下。
开发板端的配置:接好网线后,直接输入pppoe-setup,安装提示输入你的信息,在dns那儿可以暂时选择server(这会使 接下来ping的时候只能用ip ping不能直接跟网址,如果你知道你所在网络的接入商的dns的话就填进入),防火墙我是选的0,ok,如果这个时候就使用pppoe-start开始 连接的话,很大情况下你会得到timeout的提示,那我们该怎么做呢?需要在dev目录下创建一个pts的文件夹,进入pts,创建节点mknod 0 c 136 0; mknod 1 c 136 1。每次链接都需要建立,蛮麻烦的吧,所以还是把这几条指令写进启动脚本吧。相信这样的话,一般您都会得到一个connect信息。
正事说完,谈谈我碰到的那个“意外”吧!我那个意外不是刚才提到的pts文件夹,还是可恶的学校宽带,宿舍宽带是使用pppoe的,至 少我是这么认为的(因为在创建连接的时候的确是选择pppoe的),但是事实上不是的,的确宿舍宽带也不是dsl的,我傻愣愣的每天都拿着开发板到宿舍去 调试,结果得到一大堆莫名其妙的错误,连google大仙都无法解决,比如:
Connect: ppp0 <--> /dev/pts/0 Warning - secret file /etc/ppp/pap-secrets has world and/or group accespppoe: read (asyncReadFromPPP): s Warning - secret file /etc/ppp/pap-secrets has world and/or group access Remote message: Limit Users Err PAP authentication failed Connection terminated. pppoe: read (asyncReadFromPPP): Session 11215: Input/output error
LCP: timeout sending Config-Requests Connection terminated. 还 害我浪费N多时间穿梭在实验室和宿舍中,35度的南京天可不是一般的郁闷。呵呵,最好一怒之下决心一定要在实验室建一个pppoe服务器,建好pppoe 服务器一连,原来我的arm pppoe移植已经ok,只是学校网络的关系让我两天都在苦思冥想一个根本就不存在的伪命题。
事实上建pppoe服务器是很简单的,非常适合工作场所没有adsl拨号的环境,下一个raspppoe的软件就可以了。贴一下步骤:
1.下载RASPPPOE( 0.99版)
2.安装RASPPPOE协议
本地连接-->属性-->常规-->安装-->协议-->添加-->从磁盘安装-->浏览-->“找到 自己RASPPOE所在的目录下的那个winpppoe.inf” -->打开-->继续……………即可
3.新建拨入的链接
新建连接向导-->选择高级连接-->接受传入的连接-->选择你的网卡(如果不安装PPPOE协议这里就看不到网卡)-->不 允许虚拟专用连接(其实都无所谓,如果你需要建立vpn服务器的话自然不能选这个)-->选择允许拨入的用户(这个用户列表就是本机的用户列表,你 可以在管理工具,计算机管理,用户和组来设置)-->在网络软件这一步选中Internet协议,设置指定的IP地址池,用于给拨入用户分配IP
4.有条件的话可以找另一台机器测试下PPPoE拨号是否成功(建立新连接-->连接到Internet-->手动设置我 的连接-->用要求用户名密码的宽带连接来连接-->然后一直下一步就可以了;建立成功后运行新建的这个连接,在属性框中的常规选项卡填入服 务器的IP地址,确定后即可用允许的那个用户名和密码来拨入,之后在dos-shell下用ipconfig 就可以看到新连接所获得的IP地址)
注意:这个验证的PPPOR拨号是服务器、客户机在同一个VLAN里面完成的,因为PPPOE请求是二层广播。
接下来配置文件
在网上常见的有三种方式: 1.使用智能的ppp拨号软件wvdial: 参考案例:本博客的《使用wvdial启动ppp协议拨号上网》 http://blog.chinaunix.net/u2/76263/showart_1227064.html 2.使用3个脚本的方式:即ppp-on,ppp-on-dialer,ppp-off 参考文档:linux-ppp-howto ( http://www.dcaccess.net/welcome/linux/PPP-HOWTO.html )、howto hook up ppp ( http://www.theory.physics.ubc.ca/ppp-linux.html ) 以及网上很多成功的案例 注:以上两种方式各有自己的优缺点,第一种方式智能稳定,他不需要chat程序,使用集成的wvdial工具包直接连接ISP,安全稳定,可以断线自动重 拨。第二方式,使用chat程序,但是很多的参数需要自己去配置,虽然比较灵活,但是如果遇到了拨号错误以后,你若不清ppp协议拨号实现的具体机制和每 个参数的含义,你就会很吃力,也许运气好的时候,你运行的环境正好和本地的移动isp配置吻合,恭喜你能上网了,但是你遗憾的是没有学到东西,想了解 ppp机制的朋友,可以试试第2种方式,在了解大体了解ppp协议的前提下,观察思考/var/log/messages中的信息。 3.使用命令pppd call somescript的方式: 参考案例: http://blog.csdn.net/bouillisy/archive/2005/07/27/436203.aspx 我使用就是该方式,下面列出ppp拨号相关配置文件并作适当的解释; 注 意:我使用的gprs模块是HUAWEI GTM900A/B两种,不同的模块的内部设置有差异,所以配置文件中的某些参数配置有差异,另外还有自身的pc机或者arm开发板的环境以及所处的地点 的信号,移动ISP都有关,在出现问题的时候要考虑这些潜在的可能因素。错误排查的过程是个枯燥难受的过程,但是反过来去看,这个过程之后会收获很多。 默 认情况在/etc/ppp/目录下建立文件gprs-connect-chat,内容如下(每个参数解释在ppp-howto中有详细解释。它是在ppp 底层会话的时候给chat进程的参数每行是一个“期望/发送”的组合序列。当出现一些经典的错误如: "LCP: timeout sending Config-Requests" ,"serial line is not 8 bit clean...",“serial line is looped back”等,去参看方式2提到的两个文档,或者google。注意,为什么不能确切地给出解决的方式,原因是打印出来的同一个错误信息,我称之为现象, 同一现象可能是由很多种原因造成的,需要自己实地排查。) #/etc/ppp/gprs-connect-chat TIMEOUT 15 ABORT '/nBUSY/r' ABORT '/nNO ANSWER/r' ABORT '/nRINGING/r/n/r/nRINGING/r' #'' AT #'OK-+++/c-OK' ATH0 TIMEOUT 40 '' /rAT OK ATS0=0 #这些都是标准的at命令,建议查看随模块的at命令手册 OK ATE0V1 OK AT+CGDCONT=1,"IP","CMNET" #设置isp接入网关为中国移动的cmnet,如果你想 获得更多访问资源的话 OK ATDT*99***1# #中国移动gprs的接入号吗 CONNECT '' +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 建立文件/etc/ppp/peers/gprs,它的作用是给pppd进程提供配置参数(详见man 8 pppd的输出内容,如果出现问题这个将是非常重要的参考页),内容如下: #/etc/ppp/peers/gprs # Usage: root>pppd call gprs /dev/s3c2410_serial1 #改成自己的端口名 115200 #改成自己串口波特率 nocrtscts #可能你的串口是需要crtscts,硬件流控的,这是由你的串口决定的,一般嵌入式系统的串口没有带硬件流控,也不需要就加nocrtscts modem #这个参数使得pppd进程将等待模块发回的CD (Carrier Detect)信号,与local真好相反 #noauth debug #把调试信息输出到/var/log/messages,在调试成功后去掉它,以减少垃圾的产生。 nodetach #hide-password usepeerdns #以下的3个参数一般不可少 noipdefault defaultroute user smsong #设置接入的用户名,在chap-secrets或者pap-secets中使用 0.0.0.0:0.0.0.0 #本地和远端的ip都设为0使得接入的isp分配本地的ip地址 ipcp-accept-local #要求peer也就是isp给自己非配动态的IP地址 #ipcp-accept-remote #lcp-echo-failure 12 #lcp-echo-interval 3 noccp #不需要压缩控制协议,有可能对端不需要,根据自己的isp的情况 #novj #novjccomp persist #保证在连接断开的情况下不退出,并尝试重新打开连接 connect '/usr/sbin/chat -s -v -f /etc/ppp/gprs-connect-chat' #pppd调用chat会话进程接入对端isp,启动对端的pppd,然后本地pppd与对端的pppd一起进行协 #商网络参数和chap/pap认证,成功后,再进行ncp层的ip的分配。 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ #/etc/ppp/chap-secets # Secrets for authentication using CHAP # client server secret IP addresses ####### redhat-config-network will overwrite this part!!! (begin) ########## ####### redhat-config-network will overwrite this part!!! (end) ############ smsong * 123456 * 有点地区的GPRS可能使用pap方式认证接入用户,所以在同一级目录下,创建pap-secets文件,内容与chap-secets类似有4项的内容第2和第4项一般不限制就用*(星号)代表。反正要你在/etc/ppp/下放着这两个文件就好。 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 在建立了ppp0连接以后可以使用ctrl+c或者下面的脚本程序ppp-off断开ppp连接 #/etc/ppp/ppp-off #!/bin/sh ###################################################################### # # Determine the device to be terminated. # if [ "$1" = "" ]; then DEVICE=ppp0 else DEVICE=$1 fi ###################################################################### # # If the ppp0 pid file is present then the program is running. Stop it. if [ -r /var/run/$DEVICE.pid ]; then kill -INT `cat /var/run/$DEVICE.pid` # # If the kill did not work then there is no process running for this # pid. It may also mean that the lock file will be left. You may wish # to delete the lock file at the same time. if [ ! "$?" = "0" ]; then rm -f /var/run/$DEVICE.pid echo "ERROR: Removed stale pid file" exit 1 fi # # Success. Let pppd clean up its own junk. echo "PPP link to $DEVICE terminated." exit 0 fi # # The ppp process is not running for ppp0 echo "ERROR: PPP link is not active on $DEVICE" exit 1 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 做好上面的配置以后,输入pppd call gprs命令,注意如果你的gprs这个文件不在/etc/ppp/peers/目录下,在给出标注路径给pppd [root@localhost ppp_scripts]# pppd call gprs timeout set to 15 seconds abort on (/nBUSY/r) abort on (/nNO ANSWER/r) abort on (/nRINGING/r/n/r/nRINGING/r) timeout set to 40 seconds send (^MAT^M^M) expect (OK) ^M^M OK -- got it send (ATS0=0^M^M) expect (OK) ^M AT^M OK -- got it send (ATE0V1^M^M) expect (OK) ^M ^M^M OK -- got it send (AT+CGDCONT=1,"IP","CMNET"^M^M) expect (OK) ^M ATS0=0^M^M OK -- got it send (ATDT*99***1#^M^M) expect (CONNECT) ^M ^M^M OK^M ATE0V1^M^M OK^M ^M OK^M ^M OK^M ^M OK^M ^M CONNECT -- got it send (^M) Serial connection established. using channel 20 Using interface ppp0 Connect: ppp0 /dev/ttyS0 Warning - secret file /etc/ppp/pap-secrets has world and/or group access sent [LCP ConfReq id=0x1 ] rcvd [LCP ConfRej id=0x1 ] sent [LCP ConfReq id=0x2 ] rcvd [LCP ConfAck id=0x2 ] rcvd [LCP ConfReq id=0x1 ] sent [LCP ConfAck id=0x1 ] rcvd [CHAP Challenge id=0x1 , name = ""] Warning - secret file /etc/ppp/chap-secrets has world and/or group access sent [CHAP Response id=0x1 , name = "smsong"] rcvd [CHAP Success id=0x1 ""] CHAP authentication succeeded CHAP authentication succeeded sent [CCP ConfReq id=0x1 ] sent [IPCP ConfReq id=0x1 ] rcvd [LCP ProtRej id=0x1 80 fd 01 01 00 0c 1a 04 78 00 18 04 78 00] Protocol-Reject for 'Compression Control Protocol' (0x80fd) received rcvd [IPCP ConfReq id=0x1] sent [IPCP ConfNak id=0x1 ] rcvd [IPCP ConfRej id=0x1 ] sent [IPCP ConfReq id=0x2 ] rcvd [IPCP ConfReq id=0x2] sent [IPCP ConfAck id=0x2] rcvd [IPCP ConfNak id=0x2 ] sent [IPCP ConfReq id=0x3 ] rcvd [IPCP ConfAck id=0x3 ] Could not determine remote IP address: defaulting to 10.64.64.64 local IP address 10.144.202.159 remote IP address 10.64.64.64 primary DNS address 211.138.200.69 secondary DNS address 211.103.13.101 Script /etc/ppp/ip-up started (pid 4578) Script /etc/ppp/ip-up finished (pid 4578), status = 0x0 使用ctrl+c可以断开连接,这样一般不太好测试是不是连接上了(遇有开发不上的控制台只有一个的原因),可以去掉/etc/ppp /peers/gprs文件中的nodetach参数,要用ping,你需要将eth0即网口给禁用掉,这样ping才会通过ppp0端口寻找路由连接外 网。 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 可以用命令tail -f /var/log/messages看到日志: Mar 20 20:55:55 localhost pppd[4557]: pppd 2.4.4 started by root, uid 0 Mar 20 20:55:56 localhost chat[4558]: timeout set to 15 seconds Mar 20 20:55:56 localhost chat[4558]: abort on (/nBUSY/r) Mar 20 20:55:56 localhost chat[4558]: abort on (/nNO ANSWER/r) Mar 20 20:55:56 localhost chat[4558]: abort on (/nRINGING/r/n/r/nRINGING/r) Mar 20 20:55:56 localhost chat[4558]: timeout set to 40 seconds Mar 20 20:55:56 localhost chat[4558]: send (^MAT^M^M) Mar 20 20:55:56 localhost chat[4558]: expect (OK) Mar 20 20:55:56 localhost chat[4558]: ^M^M Mar 20 20:55:56 localhost chat[4558]: OK Mar 20 20:55:56 localhost chat[4558]: -- got it Mar 20 20:55:56 localhost chat[4558]: send (ATS0=0^M^M) Mar 20 20:55:56 localhost chat[4558]: expect (OK) Mar 20 20:55:56 localhost chat[4558]: ^M Mar 20 20:55:56 localhost chat[4558]: AT^M Mar 20 20:55:56 localhost chat[4558]: OK Mar 20 20:55:56 localhost chat[4558]: -- got it Mar 20 20:55:56 localhost chat[4558]: send (ATE0V1^M^M) Mar 20 20:55:56 localhost chat[4558]: expect (OK) Mar 20 20:55:56 localhost chat[4558]: ^M Mar 20 20:55:56 localhost chat[4558]: ^M^M Mar 20 20:55:56 localhost chat[4558]: OK Mar 20 20:55:56 localhost chat[4558]: -- got it Mar 20 20:55:56 localhost chat[4558]: send (AT+CGDCONT=1,"IP","CMNET"^M^M) Mar 20 20:55:57 localhost chat[4558]: expect (OK) Mar 20 20:55:57 localhost chat[4558]: ^M Mar 20 20:55:57 localhost chat[4558]: ATS0=0^M^M Mar 20 20:55:57 localhost chat[4558]: OK Mar 20 20:55:57 localhost chat[4558]: -- got it Mar 20 20:55:57 localhost chat[4558]: send (ATDT*99***1#^M^M) Mar 20 20:55:57 localhost chat[4558]: expect (CONNECT) Mar 20 20:55:57 localhost chat[4558]: ^M Mar 20 20:55:57 localhost chat[4558]: ^M^M Mar 20 20:55:57 localhost chat[4558]: OK^M Mar 20 20:55:57 localhost chat[4558]: ATE0V1^M^M Mar 20 20:55:57 localhost chat[4558]: OK^M Mar 20 20:55:57 localhost chat[4558]: ^M Mar 20 20:55:57 localhost chat[4558]: OK^M Mar 20 20:55:57 localhost chat[4558]: ^M Mar 20 20:55:57 localhost chat[4558]: OK^M Mar 20 20:55:57 localhost chat[4558]: ^M Mar 20 20:55:57 localhost chat[4558]: OK^M Mar 20 20:55:57 localhost chat[4558]: ^M Mar 20 20:55:57 localhost chat[4558]: CONNECT Mar 20 20:55:57 localhost chat[4558]: -- got it Mar 20 20:55:57 localhost chat[4558]: send (^M) Mar 20 20:55:57 localhost pppd[4557]: Serial connection established. Mar 20 20:55:57 localhost pppd[4557]: Using interface ppp0 Mar 20 20:55:57 localhost pppd[4557]: Connect: ppp0 /dev/ttyS0 Mar 20 20:55:58 localhost pppd[4557]: Warning - secret file /etc/ppp/pap-secrets has world and/or group access Mar 20 20:56:00 localhost pppd[4557]: Warning - secret file /etc/ppp/chap-secrets has world and/or group access Mar 20 20:56:00 localhost pppd[4557]: CHAP authentication succeeded Mar 20 20:56:00 localhost pppd[4557]: CHAP authentication succeeded Mar 20 20:56:01 localhost kernel: PPP Deflate Compression module registered Mar 20 20:56:02 localhost pppd[4557]: Could not determine remote IP address: defaulting to 10.64.64.64 Mar 20 20:56:02 localhost pppd[4557]: local IP address 10.144.202.159 Mar 20 20:56:02 localhost pppd[4557]: remote IP address 10.64.64.64 Mar 20 20:56:02 localhost pppd[4557]: primary DNS address 211.138.200.69 Mar 20 20:56:02 localhost pppd[4557]: secondary DNS address 211.103.13.101 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ [root@localhost ~]# ifconfig eth0 Link encap:Ethernet HWaddr 00:0A:EB:91:3B:C4 UP BROADCAST MULTICAST MTU:1500 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:1000 RX bytes:0 (0.0 b) TX bytes:0 (0.0 b) Interrupt:209 Base address:0x4000 lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:16436 Metric:1 RX packets:1240 errors:0 dropped:0 overruns:0 frame:0 TX packets:1240 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:2039094 (1.9 MiB) TX bytes:2039094 (1.9 MiB) ppp0 Link encap:Point-to-Point Protocol inet addr:10.144.202.159 P-t-P:10.64.64.64 Mask:255.255.255.255 UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1500 Metric:1 RX packets:5 errors:0 dropped:0 overruns:0 frame:0 TX packets:6 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:3 RX bytes:62 (62.0 b) TX bytes:98 (98.0 b) [root@localhost ~]# ifconfig eth0 down 禁用以太网接口eth0,使得不和ppp0接口使用时候的路由冲突 [root@localhost ~]# ping 211.136.20.203 PING 211.136.20.203 (211.136.20.203) 56(84) bytes of data. 64 bytes from 211.136.20.203: icmp_seq=1 ttl=247 time=3379 ms 64 bytes from 211.136.20.203: icmp_seq=2 ttl=247 time=2388 ms 64 bytes from 211.136.20.203: icmp_seq=3 ttl=247 time=2892 ms 64 bytes from 211.136.20.203: icmp_seq=4 ttl=247 time=1952 ms 64 bytes from 211.136.20.203: icmp_seq=5 ttl=247 time=1692 ms 64 bytes from 211.136.20.203: icmp_seq=6 ttl=247 time=2112 ms 64 bytes from 211.136.20.203: icmp_seq=7 ttl=247 time=1492 ms 64 bytes from 211.136.20.203: icmp_seq=8 ttl=247 time=1472 ms --- 211.136.20.203 ping statistics --- 9 packets transmitted, 8 received, 11% packet loss, time 7999ms rtt min/avg/max/mdev = 1472.094/2172.525/3379.568/638.150 ms, pipe 4 这个时候如果你只能ping纯的ip地址,而不能解析域名,这个时候你可能需要将/etc/ppp/resolv.conf(内容被新获得的 dns取代)内容拷贝到/etc/resolv.conf中或者做一个到/etc/resolv.conf的链接。这样就可以ping域名和在浏览器中打 开网页啦。 [root@localhost ~]# ping www.baidu.com PING www.a.shifen.com (202.108.22.5) 56(84) bytes of data. 64 bytes from 202.108.22.5: icmp_seq=1 ttl=50 time=3142 ms 64 bytes from 202.108.22.5: icmp_seq=2 ttl=50 time=3348 ms 64 bytes from 202.108.22.5: icmp_seq=3 ttl=50 time=2796 ms 64 bytes from 202.108.22.5: icmp_seq=4 ttl=50 time=3632 ms 64 bytes from 202.108.22.5: icmp_seq=5 ttl=50 time=1936 ms 64 bytes from 202.108.22.5: icmp_seq=7 ttl=50 time=909 ms 64 bytes from 202.108.22.5: icmp_seq=6 ttl=50 time=1951 ms 64 bytes from 202.108.22.5: icmp_seq=8 ttl=50 time=2839 ms 64 bytes from 202.108.22.5: icmp_seq=9 ttl=50 time=1984 ms 64 bytes from 202.108.22.5: icmp_seq=10 ttl=50 time=2404 ms 64 bytes from 202.108.22.5: icmp_seq=11 ttl=50 time=1417 ms --- www.a.shifen.com ping statistics --- 12 packets transmitted, 11 received, 8% packet loss, time 13806ms rtt min/avg/max/mdev = 909.082/2396.720/3632.981/803.194 ms, pipe 4 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 另 外,如果你希望一开机就可以自动拨号上网,只要在自己的开机启动脚本(我的开发板上是/etc/init.d/rcS,在pc上有好几个如:/etc /rc.local文件,做链接到cd /etc/rcN.d,N的选择看运行的级别)里面加上如下的语句,注意这个脚本里面的可执行程序给出的必须是据对路径,因为刚开机嘛,整个机子的环境变 量还没有设置好。 还有不要在新加入的命令后面加&使得其变成后台进程,它会周期性执行,会出错! 添加的几条shell语句如下: /etc/ppp/rmlock #简单的一个判断并删除无效的串口的lock文件,保证成功拨号 /usr/bin/pppd call gprs #自动拨号 /usr/bin/sleep 20 #给它20s的拨号时间,看你的模块拨通的情况了。 /bin/qtopia & #这个是原来脚本里面有的,把它的顺序安排在这个位置,是为了在看到qt界面启 #动以后,真好gprs拨号已经建立号,也就可以上网了。 /sbin/ifconfig eth0 down #顺便开机禁用eth0网口 注:rmlock文件 #/etc/ppp/rmlock file #!/bin/sh if [ -f /var/lock/LCK..s3c2410_serial1 ]; then /bin/rm -f /var/lock/LCK..s3c2410_serial1 fi 如何解决pppd 运行的段错误: 当你手动中断ppp链接次数过多后,可能回出现pppd运行的段错误, The suggestion from debian bug report solves this problem. It is pretty straightforward: Simply delete /var/run/pppd.tdb file (in my system, it is /var/run/pppd2.tdb). 总结:根据自己的环境和喜好选用其中一种拨号方式,wvdial的方式移植到arm开发板的时候,交叉编译的时候出错很多,可以试试,相对比较 麻烦,而其它运行需要wvstreams的库的支持,占用空间大。第2中方式最常用,但是出错的可能性比较大,原因使其比较灵活,第3中跟第2中方式类 似。在出错的时候可以到google上搜索同样的错误现象,参考并修改自己的参数,再分析尝试,只要坚持到底,才会真有收获!当时你要没有什么时间了也不 想学习ppp的内部拨号机制,建议用windows把,那个封装的很好。稳定可靠!呵呵 祝:ppp&linux拨号的朋友好运!