600字范文,内容丰富有趣,生活中的好帮手!
600字范文 > linux GPRS模块拨号上网

linux GPRS模块拨号上网

时间:2022-07-13 19:34:27

相关推荐

linux GPRS模块拨号上网

使用GPRS模块拨号上网之前需要一直pppd和chat

首先配置内核中的ppp选项,

Makemenuconfig

Devicedirver--->Networkdevice

│ │*** 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)

[guanlei@centos6GPRS]$tar-xzfppp-2.4.4.tar.gz

[guanlei@centos6GPRS]$ls

ppp-2.4.4ppp-2.4.4.tar.gz

[guanlei@centos6GPRS]$cdppp-2.4.4

[guanlei@centos6ppp-2.4.4]$ls

Changes-2.3configureFAQmodulespppdumpREADME.cbcpREADME.MPPEREADME.pppoescripts

chatcontribincludePLUGINSpppstatsREADME.eap-srpREADME.MSCHAP80README.pwfdSETUP

commonetc.ppplinuxpppdREADMEREADME.linuxREADME.MSCHAP81README.sol2solaris

[guanlei@centos6ppp-2.4.4]$./configure

ConfiguringforLinux

CreatingMakefiles.

Makefile<=linux/Makefile.top

pppd/Makefile<=pppd/Makefile.linux

pppstats/Makefile<=pppstats/Makefile.linux

chat/Makefile<=chat/Makefile.linux

pppdump/Makefile<=pppdump/Makefile.linux

pppd/plugins/Makefile<=pppd/plugins/Makefile.linux

pppd/plugins/rp-pppoe/Makefile<=pppd/plugins/rp-pppoe/Makefile.linux

pppd/plugins/radius/Makefile<=pppd/plugins/radius/Makefile.linux

pppd/plugins/pppoatm/Makefile<=pppd/plugins/pppoatm/Makefile.linux

[guanlei@centos6ppp-2.4.4]$ls

Changes-2.3contriblinuxpppdREADME.cbcpREADME.MSCHAP80README.sol2

chatetc.pppMakefilepppdumpREADME.eap-srpREADME.MSCHAP81scripts

commonFAQmodulespppstatsREADME.linuxREADME.pppoeSETUP

configureincludePLUGINSREADMEREADME.MPPEREADME.pwfdsolaris

[guanlei@centos6ppp-2.4.4]$cdchat/

[guanlei@centos6chat]$ls

chat.8chat.cMakefileMakefile.linuxMakefile.sol2

[guanlei@centos6chat]$vimchat.c

[guanlei@centos6chat]$vimMakefile

[guanlei@centos6chat]$cd../pppd

[guanlei@centos6pppd]$vimauth.c

[guanlei@centos6pppd]$vimMakefile

CC=/opt/buildroot-.08/arm920t/usr/bin/arm-linux-gcc#addbyguanlei.1.21

[guanlei@centos6ppp-2.4.4]$make

过程省略。。。。

[guanlei@centos6ppp-2.4.4]$cdchat/

[guanlei@centos6chat]$ls

hat.oMakefileMakefile.linuxMakefile.sol2

[guanlei@centos6chat]$filechat

chat:ELF32-bitLSBexecutable,ARM,version1(SYSV),dynamicallylinked(usessharedlibs),notstripped

[guanlei@centos6pppd]$filepppd

pppd:ELF32-bitLSBexecutable,ARM,version1(SYSV),dynamicallylinked(usessharedlibs),notstripped

把生成的pppd 和chat 下载到自己的s3c2440开发板上,放在/usr/sbin中

使用gprs上网的时候需要如下几个脚本

一:编写gprs脚本为PPP连接指定了连接使用的设备、使用的控制字符传输速率、指定了硬件加速、溢出控制等。

#/etc/ppp/peers/gprs

#Usage:root>pppdcallgprs

#setseriral

/dev/ttyS1

#setbaudrate

115200

#setflowdate

nocrtscts

#加上参数-v告诉chat命令将其所有的输出/入拷贝到系统记录里(通常是#/var/log/messages)。-t6指定了执行chat该命令的时间为6s。chat脚本的位置可以位##于/etc/目录下,也可以位于/var下,这个可以更加需要灵活设置。

connect'/usr/sbin/chat-v-f/etc/ppp/chat/gprs-connect-chat'

#setdebug,sendmessageto/var/log/messages

debug

#Tokeeppppdontheterminal

nodetach

#hide-password

#Acceptthepeer'sideaofourlocalIPaddress

ipcp-accept-local

#Acceptthepeer'sideaofits(remote)IPaddress

ipcp-accept-remote

#dialupconnetionasthedefaultroute

defaultroute

usepeerdns

Noipdefault

具体查看的话,man8pppd

二,CHAT脚本

一个简单的chat脚本有下面的结构:

""AT

OKATDTdialnumber

CONNECT""

1)MODEM期望空字符串。这句话的意思直接理解就是MODEM不管收到什么字符串,先发出字符串AT;

2)期望收到“OK”字符串,然后发送字符串“ATDTdialnumber”

3)如果收到“CONNECT”,就不再发送,认为数据链路已建立连接。

4)如果需要进行超时控制,就可以加入如下字段:

TIMEOUT10

5)如果要增加对特殊情况的处理,就加入下面字段:

ABORTBUSY

ABORTNOANSWER

ABORTRINGING

意思是:如果收到字符串“BUSY”、“NOANSWER”、“RINGING”就退出执行。

编写自己的chat脚本

>vigprs-connect-chat

#/etc/ppp/gprs-connect-chat

#Copyright(c)guanlei995318056@

#Thisissecondpartofthepppdialscript.Itwillperformtheconnection

#

ABORT'BUSY'

ABORT'NOANSWER'

ABORT'NOCARRIER'

ABORT'NODIALTONE'

ABORT'ERROR'

ABORT'\nRING\r\n\r\nRING\r'

TIMEOUT20

''\rAT

#setapn

OKAT+CGDCONT=1,"IP","cmnet"

#拨号上网

OKATDT*99***1#

SAY"+requestingdataconnection\n"

CONNECT''

SAY"+connected\n"

开始测试:

>:ifconfigeth0down

>:ifconfig

要程序一直在后台运行,如果在前台运行的话,没办法ping,不能测试到底能不能上网

>:pppdcallgprs&

>:+requestingdataconnection

+connected

Serialconnectionestablished.

usingchannel2

iUsinginterfaceppp0

Connect:ppp0<-->/dev/ttyS1

fconfsent[LCPConfReqid=0x1<asyncmap0x0><magic0xf9216d0><pcomp><accomp>]

rcvd[LCPConfReqid=0x1<asyncmap0xa0000><authpap>]

sent[LCPConfAckid=0x1<asyncmap0xa0000><authpap>]

rcvd[LCPConfRejid=0x1<magic0xf9216d0><pcomp><accomp>]

sent[LCPConfReqid=0x2<asyncmap0x0>]

rcvd[LCPConfAckid=0x2<asyncmap0x0>]

NosecretfoundforPAPlogin

sent[PAPAuthReqid=0x1user="guanlei"password=<hidden>]

rcvd[PAPAuthAckid=0x1"LoginOK"]

Remotemessage:LoginOK

PAPauthenticationsucceeded

sent[CCPConfReqid=0x1<deflate15><deflate(old#)15><bsdv115>]

sent[IPCPConfReqid=0x1<compressVJ0f01><addr0.0.0.0><ms-dns10.0.0.0><ms-dns30.0.0.0>]

rcvd[LCPProtRejid=0x280fd0101000f1a0478001804780015032f]

Protocol-Rejectfor'CompressionControlProtocol'(0x80fd)received

consent[IPCPConfReqid=0x1<compressVJ0f01><addr0.0.0.0><ms-dns10.0.0.0><ms-dns30.0.0.0>]

rcvd[IPCPConfReqid=0x1<addr192.200.1.21>]

sent[IPCPConfAckid=0x1<addr192.200.1.21>]

rcvd[IPCPConfRejid=0x1<compressVJ0f01>]

sent[IPCPConfReqid=0x2<addr0.0.0.0><ms-dns10.0.0.0><ms-dns30.0.0.0>]

rcvd[IPCPConfNakid=0x2<addr10.110.1.110><ms-dns1211.137.58.20><ms-dns3211.137.64.163>]

sent[IPCPConfReqid=0x3<addr10.110.1.110><ms-dns1211.137.58.20><ms-dns3211.137.64.163>]

rcvd[IPCPConfAckid=0x3<addr10.110.1.110><ms-dns1211.137.58.20><ms-dns3211.137.64.163>]

localIPaddress10.110.1.110

remoteIPaddress192.200.1.21

primaryDNSaddress211.137.58.20

secondaryDNSaddress211.137.64.163

>:ifconfig

ppp0Linkencap:Point-to-PointProtocol

inetaddr:10.110.1.110P-t-P:192.200.1.21Mask:255.255.255.255

UPPOINTOPOINTRUNNINGNOARPMULTICASTMTU:1500Metric:1

RXpackets:4errors:0dropped:0overruns:0frame:0

TXpackets:6errors:0dropped:0overruns:0carrier:0

collisions:0txqueuelen:3

RXbytes:64(64.0B)TXbytes:125(125.0B)

>:

(103.235.46.39):56databytes

64bytesfrom103.235.46.39:seq=0ttl=48time=555.719ms

64bytesfrom103.235.46.39:seq=1ttl=48time=273.481ms

---pingstatistics---

3packetstransmitted,2packetsreceived,33%packetloss

round-tripmin/avg/max=273.481/414.600/555.719ms

>:ifconfig

ppp0Linkencap:Point-to-PointProtocol

inetaddr:10.110.1.110P-t-P:192.200.1.21Mask:255.255.255.255

UPPOINTOPOINTRUNNINGNOARPMULTICASTMTU:1500Metric:1

RXpackets:10errors:0dropped:0overruns:0frame:0

TXpackets:12errors:0dropped:0overruns:0carrier:0

collisions:0txqueuelen:3

RXbytes:686(686.0B)TXbytes:557(557.0B)

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。