———————————————————————————————————————

主机操作系统:Centos 6.7
交叉编译器环境:arm-linux-gcc-4.5.4 
开发板平台: FL2440 
Linux内核版本: linux-3.0 
开发模块: SIM900 GPRS
———————————————————————

开发提醒:在开发gprs模块ppp拨号上网之前需满足fl2440开发版能正常加载linux内核及文件系统,并且开发板的串口已经使能,同时需准备一张开通gprs流量的sim卡。

一:GPRS介绍 

GSM模块,是将GSM射频芯片、基带处理芯片、存储器、功放器件等集成在一块线路板上,具有独立的操作系统、GSM射频处理、基带处理并提供标准接口的功能模块。GSM模块根据其提供的数据传输速率又可以分为GPRS模块、EDGE模块和纯短信模块。短信模块只支持语音和短信服务。GPRS,可说是GSM的延续。它经常被描述成“2.5G”,也就是说这项技术位于第二代(2G)和第三代(3G)移动通讯技术之间。GPRS的传输速率从56K到114Kbps不等,理论速度最高达171k。相对于GSM的9.6kbps的访问速度而言,GPRS拥有更快的访问数据通信速度,GPRS技术还具有在任何时间、任何地点都能实现连接,永远在线、按流量计费等特点。EDGE技术进一步提升了数据传输的速率到384K-473K,被称为”2.75G”,数据传输速率更2倍于GPRS。目前,国内的GSM网络普遍具有GPRS通讯功能,移动和联通的网络都支持GPRS,EDGE在部分省市实现了网络覆盖。 
GPRS模块,是具有GPRS数据传输功能的GSM模块。GPRS模块就是一个精简版的手机,集成GSM通信的主要功能于一块电路板上,具有发送短消息、通话、数据传输等功能。GPRS模块相当于手机的核心部分,如果增加键盘和屏幕就是一个完整的手机。普通电脑或者单片机可以通过RS232串口与GPRS模块相连,通过AT指令控制GPRS模块实现各种基于GSM的通信功能。 
GPRS模块区别于传统的纯短信模块,两者都是GSM模块,但是短信模块只能收发短信和语音通讯,而GPRS模块还具有GPRS数据传输功能。” 

由于GPRS,串口都是设备,难道就不需要再在linux内核中使能驱动吗?是这样的,在一开始内核中就已经对串口驱动进行了使能,而GPRS模块中有GPRS模块的驱动,这个模块通过自身的串口不断的发送数据开发板需要做的就是读取然后处理就够了。


串口线将 GPRS模块的串口和开发板的串口连接起来(我连接的是开发的第二个串口(ttys1),因为第一个串口连接PC了(ttys0)),然后将可以使用的手机SIM卡插入 GPRS模块的卡槽;然后启动开发板,接通GPRS模块的电源,然后按下GPRS模块的SW1,让SIM开始工作,搜索网络这时发光二极管D3会闪烁。

二:编辑Linux内核,使其支持PPP拨号上网

[leiyuxing@centos6 linux-3.0]$ make menuconfig

Generic Driver Options --->
--- Network device support
*** 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 

[leiyuxing@centos6 ~]$ mkdir GPRS

[leiyuxing@centos6 ~]$ cd GPRS/

[leiyuxing@centos6 GPRS]$ tar -xzf ppp-2.4.4.tar.gz

[leiyuxing@centos6 GPRS]$ ls

ppp-2.4.4 ppp-2.4.4.tar.gz

[leiyuxing@centos6 GPRS]$ cd ppp-2.4.4

[leiyuxing@centos6 ppp-2.4.4]$ ls

Changes-2.3 etc.ppp PLUGINS README.cbcp README.MSCHAP81 SETUP

chat FAQ pppd README.eap-srp README.pppoe solaris

common include pppdump README.linux README.pwfd

configure linux pppstats README.MPPE README.sol2

contrib modules README README.MSCHAP80 scripts

[leiyuxing@centos6 ppp-2.4.4]$ ./configure

[leiyuxing@centos6 ppp-2.4.4]$ cd chat/

[leiyuxing@centos6 chat]$ ls

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



[leiyuxing@centos6 chat]$ vim chat.c

 

1168       if (timeout_next) {
1169 timeout_next = 0;
1170 s=clean(s,0); /* add by leiyuxing */
1171 timeout = atoi(s);
1172
1173 free(s); /* add by leiyuxing */
1174 if (timeout <= 0)
1175 timeout = DEFAULT_CHAT_TIMEOUT;
[leiyuxing@centos6 chat]$ vim Makefile
INSTALL= install
CC=/opt/buildroot-2012.08/arm920t/usr/bin/arm-linux-gcc /* add by leiyuxing */

all: chat

chat: chat.o
$(CC) -static -o chat chat.o /* add by leiyuxing */
$(CC) -o chat chat.o

 

[leiyuxing@centos6 chat]$ cd ../pppd

[leiyuxing@centos6 pppd]$ vim auth.c

1315 hadchap = -1;

1316 ao->neg_upap = !refuse_pap /* && (passwd[0] != 0 || get_pap_passwd(NULL))*/; /* add by leiyuxing */

1317 ao->neg_chap = (!refuse_chap || !refuse_mschap || !refuse_mschap_v2)

[leiyuxing@centos6 pppd]$ vim Makefile
33 CC =/opt/buildroot-2012.08/arm920t/usr/bin/arm-linux-gcc     /* add by leiyuxing */
34 #
35 COPTS = -O2 -pipe -Wall -g


42 # Don't use MSLANMAN unless you really know what you're doing.
43 #MSLANMAN=y
44 # Uncomment the next line to include support for MPPE. CHAPMS (above) must
45 # also be enabled. Also, edit plugins/radius/Makefile.linux.
46 #MPPE=y /* add by leiyuxing */
47
48 # Uncomment the next line to include support for PPP packet filtering.
49 # This requires that the libpcap library and headers be installed
50 # and that the kernel driver support PPP packet filtering.
51 #FILTER=y /* add by leiyuxing */
52
53 # Uncomment the next line to enable multilink PPP (enabled by default)
54 # Linux distributions: Please leave multilink ENABLED in your builds
55 # of pppd!
56 #HAVE_MULTILINK=y /* add by leiyuxing */
57
58 # Uncomment the next line to enable the TDB database (enabled by default.)
59 # If you enable multilink, then TDB is automatically enabled also.
60 # Linux distributions: Please leave TDB ENABLED in your builds.
61 USE_TDB=y
62
63 HAS_SHADOW=y
64 #USE_PAM=y
65 #HAVE_INET6=y
66
67 # Enable plugins
68 #PLUGIN=y /* add by leiyuxing */
[leiyuxing@centos6 pppd]$ cd ..

[leiyuxing@centos6 ppp-2.4.4]$ make

[leiyuxing@centos6 ppp-2.4.4]$ cd chat

[leiyuxing@centos6 chat]$ ls

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

[leiyuxing@centos6 chat]$ file chat

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

[leiyuxing@centos6 ppp-2.4.4]$ cd pppd

[leiyuxing@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 leiyuxing 674116231@qq.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'
TIMEOUT 20
'' \rAT

#set apn

OK 'AT+CGDCONT=1,"IP","CMNET"'//isp接入网关为中国移动的CMNET
OK ATDT*99***1# //这里要改成自己的运营商号码。。我的这个号码是移动的
#拨号上网
SAY "Waiting for connect...\n"
CONNECT ''
SAY "Connect Success!\n"

 

 

 

sim900芯片—GPRS模块ppp拨号上网_GPRS模块ppp拨号上网

编写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
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 leiyuxing

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

pppd调用chat会话进程接入对端isp,启动对端的pppd,然后本地pppd与对端的pppd一起进行协商网络参数和chap/pap认证,成功后,再进行ncp层的ip的分配。

 

五:在开发板上测试ppp拨号 要用ping,你需要将eth0即网口给禁用掉,这样ping才会通过ppp0端口寻找路由连接外网

>:ifconfig eth0 down 

>:pppd call gprs & //&是后台执行的意思。。只有这条后台执行。。我们才能在前台检测是否上网

>: abort on (BUSY)

abort on (NO ANSWER)

abort on (NO CARRIER)

abort on (NO DIALTONE)

abort on (ERROR)

abort on (\nRING\r\n\r\nRING\r)

send (^MAT^M)

expect (OK)

^MAT^M^M

OK

-- got it



send (ATE0^M)

Press CTRL-C to break the connection process.

expect (OK)

^M

ATE0^M^M

OK

-- got it



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

expect (OK)

^M

^M

OK

-- got it



send (ATDT*99***1#^M)

Waiting for connect...

expect (CONNECT)

^M

^M

CONNECT

-- got it



send (^M)

Connect Success!

Serial connection established.

using channel 1

Using interface ppp0

Connect: ppp0 <--> /dev/ttyS1

sent [LCP ConfReq id=0x1 <asyncmap 0x0> <magic 0xfc77d667> <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 0xfc77d667> <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="root" 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

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 [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.112.83.171> <ms-dns1 211.137.58.20> <ms-dns3 211.137.64.163>]

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

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

local IP address 10.112.83.171

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.112.83.171 P-t-P:192.200.1.21 Mask:255.255.255.255

UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1500 Metric:1

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

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

collisions:0 txqueuelen:3

RX bytes:1647 (1.6 KiB) TX bytes:205 (205.0 B)

>: ping 4.2.2.2

PING 4.2.2.2 (4.2.2.2): 56 data bytes

64 bytes from 4.2.2.2: seq=0 ttl=51 time=717.738 ms

64 bytes from 4.2.2.2: seq=1 ttl=51 time=714.215 ms

64 bytes from 4.2.2.2: seq=2 ttl=51 time=600.230 ms

64 bytes from 4.2.2.2: seq=3 ttl=51 time=467.385 ms

64 bytes from 4.2.2.2: seq=4 ttl=51 time=473.149 ms



--- 4.2.2.2 ping statistics ---

5 packets transmitted, 5 packets received, 0% packet loss

round-trip min/avg/max = 467.385/594.543/717.738 ms

>: ping www.baidu.com

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

64 bytes from 111.13.100.92: seq=0 ttl=53 time=296.256 ms

64 bytes from 111.13.100.92: seq=1 ttl=53 time=276.666 ms

64 bytes from 111.13.100.92: seq=2 ttl=53 time=910.095 ms

64 bytes from 111.13.100.92: seq=3 ttl=53 time=389.250 ms

64 bytes from 111.13.100.92: seq=4 ttl=53 time=280.073 ms



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

5 packets transmitted, 5 packets received, 0% packet loss

round-trip min/avg/max = 276.666/430.468/910.095 ms

 如果出现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

至此关于sim900GPRS模块ppp拨号上网成功实现!

 

遇到的问题:

问题一:

>: pppd call gprs &
-sh: pppd: Permission denied

我给PPPd赋予了权限为什么还是说我没权限

解决方法:

在PC上查看

[leiyuxing@centos6 pppd]$ file pppd
pppd: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.18, not stripped

不是ARM版的要用交叉编译器编译,我错把源码包拷过去,只需交叉编译器编译后的工具

如下显示才是正确的:

[leiyuxing@centos6 pppd]$ file pppd

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