天天看點

linux GPRS子產品撥号上網

使用GPRS子產品撥号上網之前需要一直pppd和chat

首先配置核心中的ppp選項,

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) 

[[email protected] GPRS]$ tar -xzf ppp-2.4.4.tar.gz 

[[email protected] GPRS]$ ls

ppp-2.4.4  ppp-2.4.4.tar.gz

[[email protected] GPRS]$ cd ppp-2.4.4

[[email protected] ppp-2.4.4]$ ls

Changes-2.3  configure  FAQ      modules  pppdump   README.cbcp     README.MPPE      README.pppoe  scripts

chat         contrib    include  PLUGINS  pppstats  README.eap-srp  README.MSCHAP80  README.pwfd   SETUP

common       etc.ppp    linux    pppd     README    README.linux    README.MSCHAP81  README.sol2   solaris

[[email protected] ppp-2.4.4]$  ./configure

Configuring for Linux

Creating Makefiles.

  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

[[email protected] ppp-2.4.4]$ ls

Changes-2.3  contrib  linux     pppd      README.cbcp     README.MSCHAP80  README.sol2

chat         etc.ppp  Makefile  pppdump   README.eap-srp  README.MSCHAP81  scripts

common       FAQ      modules   pppstats  README.linux    README.pppoe     SETUP

configure    include  PLUGINS   README    README.MPPE     README.pwfd      solaris

[[email protected] ppp-2.4.4]$ cd chat/

[[email protected] chat]$ ls

chat.8  chat.c  Makefile  Makefile.linux  Makefile.sol2

[[email protected] chat]$ vim chat.c 

linux GPRS子產品撥号上網

[[email protected] chat]$ vim Makefile

linux GPRS子產品撥号上網

[[email protected] chat]$ cd ../pppd

[[email protected] pppd]$ vim auth.c 

linux GPRS子產品撥号上網

[[email protected] pppd]$ vim Makefile

 CC =/opt/buildroot-2012.08/arm920t/usr/bin/arm-linux-gcc#add by guanlei 2016.1.21 

linux GPRS子產品撥号上網

[[email protected] ppp-2.4.4]$ make

過程省略。。。。

[[email protected] ppp-2.4.4]$ cd chat/

[[email protected] chat]$ ls

chat  chat.8  chat.c  chat.o  Makefile  Makefile.linux  Makefile.sol2

[[email protected] chat]$ file chat

chat: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), not stripped

[[email protected] pppd]$ file pppd

pppd: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), not stripped

 把生成的pppd 和chat 下載下傳到自己的s3c2440開發闆上,放在/usr/sbin中

使用gprs上網的時候需要如下幾個腳本 

一:編寫gprs腳本為PPP連接配接指定了連接配接使用的裝置、使用的控制字元傳輸速率、指定了硬體加速、溢出控制等。

#/etc/ppp/peers/gprs

# Usage: root>pppd call gprs

#set seriral

/dev/ttyS1

# set baudrate

115200

# set flowdate

nocrtscts

#加上參數-v 告訴 chat指令将其所有的輸出/入拷貝到系統記錄裡(通常是 #/var/log/messages)。-t 6 指定了執行chat該指令的時間為6s。chat腳本的位置可以位##于/etc/目錄下,也可以位于/var下,這個可以更加需要靈活設定。

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

#set debug ,send message to /var/log/messages

debug

#To keep pppd on the terminal

nodetach

#hide-password

# 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

具體檢視的話,man 8 pppd

二, 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腳本

>vi gprs-connect-chat

#/etc/ppp/gprs-connect-chat

#Copyright (c) 2016 guanlei [email protected]

# 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'

    TIMEOUT         20

''               \rAT

#set  apn

OK              AT+CGDCONT=1,"IP","cmnet"

    # 撥号上網

    OK              ATDT*99***1#

    SAY             " + requesting data connection\n"

    CONNECT         ''

    SAY             " + connected\n"

linux GPRS子產品撥号上網

開始測試:

>: ifconfig eth0 down

>: ifconfig

要程式一直在背景運作,如果在前台運作的話,沒辦法ping,不能測試到底能不能上網

>: pppd call gprs &

>:  + requesting data connection

 + connected

Serial connection established.

using channel 2

iUsing interface ppp0

Connect: ppp0 <--> /dev/ttyS1

fconfsent [LCP ConfReq id=0x1 <asyncmap 0x0> <magic 0xf9216d0> <pcomp> <accomp>]

rcvd [LCP ConfReq id=0x1 <asyncmap 0xa0000> <auth pap>]

sent [LCP ConfAck id=0x1 <asyncmap 0xa0000> <auth pap>]

rcvd [LCP ConfRej id=0x1 <magic 0xf9216d0> <pcomp> <accomp>]

sent [LCP ConfReq id=0x2 <asyncmap 0x0>]

rcvd [LCP ConfAck id=0x2 <asyncmap 0x0>]

No secret found for PAP login

sent [PAP AuthReq id=0x1 user="guanlei" password=<hidden>]

rcvd [PAP AuthAck id=0x1 "Login OK"]

Remote message: Login OK

PAP authentication succeeded

sent [CCP ConfReq id=0x1 <deflate 15> <deflate(old#) 15> <bsd v1 15>]

sent [IPCP ConfReq id=0x1 <compress VJ 0f 01> <addr 0.0.0.0> <ms-dns1 0.0.0.0> <ms-dns3 0.0.0.0>]

rcvd [LCP ProtRej id=0x2 80 fd 01 01 00 0f 1a 04 78 00 18 04 78 00 15 03 2f]

Protocol-Reject for 'Compression Control Protocol' (0x80fd) received

consent [IPCP ConfReq id=0x1 <compress VJ 0f 01> <addr 0.0.0.0> <ms-dns1 0.0.0.0> <ms-dns3 0.0.0.0>]

rcvd [IPCP ConfReq id=0x1 <addr 192.200.1.21>]

sent [IPCP ConfAck id=0x1 <addr 192.200.1.21>]

rcvd [IPCP ConfRej id=0x1 <compress VJ 0f 01>]

sent [IPCP ConfReq id=0x2 <addr 0.0.0.0> <ms-dns1 0.0.0.0> <ms-dns3 0.0.0.0>]

rcvd [IPCP ConfNak id=0x2 <addr 10.110.1.110> <ms-dns1 211.137.58.20> <ms-dns3 211.137.64.163>]

sent [IPCP ConfReq id=0x3 <addr 10.110.1.110> <ms-dns1 211.137.58.20> <ms-dns3 211.137.64.163>]

rcvd [IPCP ConfAck id=0x3 <addr 10.110.1.110> <ms-dns1 211.137.58.20> <ms-dns3 211.137.64.163>]

local  IP address 10.110.1.110

remote IP address 192.200.1.21

primary   DNS address 211.137.58.20

secondary DNS address 211.137.64.163

>: ifconfig

ppp0      Link encap:Point-to-Point Protocol  

          inet addr:10.110.1.110  P-t-P:192.200.1.21  Mask:255.255.255.255

          UP POINTOPOINT RUNNING NOARP MULTICAST  MTU:1500  Metric:1

          RX packets:4 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:64 (64.0 B)  TX bytes:125 (125.0 B)

>: ping www.baidu.com

PING www.baidu.com (103.235.46.39): 56 data bytes

64 bytes from 103.235.46.39: seq=0 ttl=48 time=555.719 ms

64 bytes from 103.235.46.39: seq=1 ttl=48 time=273.481 ms

--- www.baidu.com ping statistics ---

3 packets transmitted, 2 packets received, 33% packet loss

round-trip min/avg/max = 273.481/414.600/555.719 ms

>: ifconfig

ppp0      Link encap:Point-to-Point Protocol  

          inet addr:10.110.1.110  P-t-P:192.200.1.21  Mask:255.255.255.255

          UP POINTOPOINT RUNNING NOARP MULTICAST  MTU:1500  Metric:1

          RX packets:10 errors:0 dropped:0 overruns:0 frame:0

          TX packets:12 errors:0 dropped:0 overruns:0 carrier:0

          collisions:0 txqueuelen:3 

          RX bytes:686 (686.0 B)  TX bytes:557 (557.0 B)

繼續閱讀