免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2359 | 回复: 2
打印 上一主题 下一主题

嵌入式linux下通过ppp拨号gprs [复制链接]

论坛徽章:
1
技术图书徽章
日期:2013-10-29 15:46:41
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-12-21 08:41 |只看该作者 |倒序浏览
1. 加入内核支持:
Device Drivers -> Network device support->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


2. 下载ppp
wget -c ftp://ftp.samba.org/pub/ppp/ppp-2.4.5.tar.gz

3. 交叉编译
# ./configure
# make CC=arm-linux-gcc

4. 将目录下pppd chat pppdump pppstats下可执行程序pppd, chat, pppdump, pppstats拷贝到开发板/usr/sbin目录下

5. mkdir /etc/ppp; mkdir /etc/ppp/peers
然后建立如下4个文件:
1)/etc/ppp/peers/gprs
/dev/s3c2410_serial1
115200
nocrtscts ##important! 一定要注意这里,开发板与PC机不同,没有硬件流控,导致我chat总是没有回应,折腾了一上午才发现!
nodetach   ##去掉该项,拨号就在后台运行。
noauth
usepeerdns
noipdefault
ipcp-accept-local
ipcp-accept-remote
defaultroute
user itlanger
connect '/usr/sbin/chat -s -v -f /etc/ppp/chat-gprs-connect'

2) /etc/ppp/chat-gprs-connect
TIMEOUT 5
ECHO ON
ABORT '\nBUSY\r'
ABORT '\nERROR\r'
ABORT '\nNO ANSWER\r'
ABORT '\nNO CARRIER\r'
ABORT '\nNO DIALTONE\r'

TIMEOUT 5
'' AT
OK ATE0

TIMEOUT 60
SAY "Press CTRL-C to break the connection process.\n"
OK AT+CGREG=1
OK AT+CGATT=1
OK 'AT+CGDCONT=1,"IP","CMNET"'
OK AT+CGQMIN=1,0,0,0,0,31
OK AT+CGACT=1,1
OK ATDT*99***1#

TIMEOUT 60
SAY "Waiting for connect...\n"
CONNECT ''
SAY "Connect Success!\n"

3) /etc/ppp/pap-secrets
itlanger        *       ''

4) /etc/ppp/chap-secrets
itlanger        *       ''


6. 进行拨号连接:
[root@srp-arm /]# /usr/sbin/pppd call gprs
timeout set to 5 seconds
abort on (\nBUSY\r)
abort on (\nERROR\r)
abort on (\nNO ANSWER\r)
abort on (\nNO CARRIER\r)
abort on (\nNO DIALTONE\r)
timeout set to 5 seconds
send (AT^M)
expect (OK)

^M
OKOK
-- got it

send (ATE0^M)
timeout set to 60 seconds
Press CTRL-C to break the connection process.
expect (OK)

^M

^M
OKOK
-- got it

send (AT+CGREG=1^M)
expect (OK)

^M

^M
OKOK
-- got it

send (AT+CGATT=1^M)
expect (OK)

^M

^M
OKOK
-- got it

send (AT+CGDCONT=1,"IP","CMNET"^M)
expect (OK)

^M

^M
OKOK
-- got it

send (AT+CGQMIN=1,0,0,0,0,31^M)
expect (OK)

^M

^M
OKOK
-- got it

send (AT+CGACT=1,1^M)
expect (OK)

^M

^M
OKOK
-- got it

send (ATDT*99***1#^M)
timeout set to 60 seconds
Waiting for connect...
expect (CONNECT)

^M

^M
CONNECTCONNECT
-- got it

send (^M)
Connect Success!

Serial connection established.
Using interface ppp0
Connect: ppp0 <--> /dev/s3c2410_serial1
Warning - secret file /etc/ppp/pap-secrets has world and/or group access
Warning - secret file /etc/ppp/chap-secrets has world and/or group access
CHAP authentication succeeded
CHAP authentication succeeded
not replacing existing default route via 192.168.0.1
local IP address 10.24.19.4
remote IP address 192.168.254.254
primary   DNS address 211.137.160.5
secondary DNS address 211.136.17.107



7. 解决问题:
1)解决出现的警告:
Warning - secret file /etc/ppp/pap-secrets has world and/or group access
Warning - secret file /etc/ppp/chap-secrets has world and/or group access
只要去掉这两个文件的权限即可:
chmod 600 /etc/ppp/*-secrets

2) 后台拨号:
去掉gprs文件中的nodetach
并且 mkdir /var/log

3)关闭ppp连接
在控制终端中用CTRL-C就可以断开连接
在后台可以用如下脚本文件实现: /etc/ppp/ppp-off
#!/bin/sh

if [ -r /var/run/ppp0.pid ]; then
   kill -INT `cat /var/run/ppp0.pid`
fi

if [ ! "$?" = "0" ]; then
    rm -f /var/run/ppp0.pid
        echo "ERROR: close ppp0 failed!"
        exit 1
fi
              
echo "SUCCESS: ppp0 was closed!"
exit 0


8. 发现使用ppp拨号后,就再也不用AT指令建立socket连接了,方便多了。
哈哈。。。

论坛徽章:
0
2 [报告]
发表于 2012-04-16 16:25 |只看该作者
学习下!!

论坛徽章:
0
3 [报告]
发表于 2012-04-18 10:42 |只看该作者
mark~~~
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP