嵌入式Linux利用ppp实现4G模块联网
https://blog.csdn.net/qq361294382/article/details/52136126
https://blog.csdn.net/qq361294382/article/details/52136126
之前做项目时需要用到SIM7100模块,便快速了解下ppp拨号,实现了功能,但是功能虽然实现了,却依然有许多疑问,这段时间有点时间,打算更加详细的研究下。
编译ppp2.4.5
下载:官方地址
编译:
#1.解压ppp程序包
tar -xzvf ppp-2.4.5.tar.gz
#2.进入并生成Makefile
cd ./ppp-2.4.5
./config
#3.指定交差编译工具make
make CC=arm-linux-gcc
1
2
3
4
5
6
7
配置内核
Device Drivers --->Network device support---> <*> PPP (point-to-point protocol) support
1
ppp安装
以上编译过程将会生成pppd、pppdump、pppstats、chat四个运行程序,将他们复制到开发平台下的/usr/sbin/中。
chat:调制解调器的自动对话脚本,Chat程序定义了一个计算机和调制解调器之间对话交流,其主要目的是用来在本地PPPD和远端PPPD程序之间建立连接(简单说就是与4G模块进行AT命令交互的流程表,最终实现与ISP运营商的连接)。
pppd:点对点协议守护进程,其功能为实现ppp策略性的内容,包括所有鉴权、压缩/解压和加密/解密等扩展功能的控制协议。
pppdump:将使用pppd记录选项编写的文件转换为人类可读的格式。
pppstats:显示PPP连线状态。pppstats(point to point protocol status)。
拨号流程简图
脚本配置
在开发平台上建立两个文件夹,并拷贝ppp.2.4.5文件夹中的chap-secrets、pap-secrets脚本至/etc/ppp文件夹。
mkdir /etc/ppp
mkdir /etc/ppp/peers
cp ./chap-secrets ./pap-secrets /etc/ppp
# 顺便创建一下ip-up、ip-down脚本
1
2
3
4
pppd配置文件介绍
pppd的参数略多啊,具体可以自己man一下或者点击这里查看。
这里我介绍下我用的,配置文件名称暂定为“gprs”
# /etc/ppp/peers/gprs
# This is pppd script for China Mobile, used SIMCOM SIM7100C Module
# Usage: root>pppd call gprs
# Interface should be used is the interface which connects physics interface of SIM7100C Module
# ttyname 串口端口,若非以”/“开头,则会自动补充”/dev/“
/dev/ttyUSB3
# speed 串口波特率
115200
#硬件流控
crtscts
# 调制解调器模式
modem
# 无需身份验证
noauth
# 不要求使用chap授权
refuse-chap
# 不要求使用mschap授权
refuse-mschap
# 不要求使用mschap-v2授权
refuse-mschap-v2
# 调试模式 pppd将以可读形式记录发送或接收的所有控制数据包的内容
debug
# 前台运行
nodetach
#hide-password
# 向ISP请求2个dns服务器地址。这两个地址将以DNS1与DNS2两个环境变量传送到/etc/ppp/ip-up脚本中,并且将环境变USEPEERDNS量置为1
usepeerdns
# 禁用本地ip,由ISP提供
noipdefault
# 添加ISP网关至路由表,作为默认路由
defaultroute
# 用户名
user "cmnet"
0.0.0.0:0.0.0.0
#ipcp-accept-local
#ipcp-accept-remote
# 使能一下两个选项可以实现ppp掉线自动重播
# lcp连接失败尝试次数
lcp-echo-failure 6
# lcp echo发送间隔
lcp-echo-interval 10
# 禁用压缩控制协议ccp
#noccp
# 禁用Van Jacobson格式的tcp/ip报头
#novj
#novjccomp
# 连接终止后不要退出,而是重新尝试连接,连接次数收到maxfail限制
persist
# 连接最大尝试次数,0无限制
#maxfail
# 启动ppp协议前,进行硬件拨号
connect '/usr/sbin/chat -s -v -f /etc/ppp/gprs-connect-chat'
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
chat脚本
chat脚本主要用来通过AT命令完成4G模块的拨号过程,关于其选项含义可以man一下或者点击这里查看,下面先介绍下其语法:
chat最主要语法就是“期望-发送”,直白点说就是,我期望收到[某某AT响应],若收到,则发送[某某AT命令]。
chat还有个常用的关键词为ABORT,这个关键词用于判断何时终止脚本,在AT交互过程中,模块发生错误,并且输出一些错误信息时,ABORT可根据设定的词,停止当前脚本。
以下脚本命名为“gprs-connect-chat”
#Chat script for China Mobile, used SIMCOM sim7100 TD module.
# 设置响应超时
TIMEOUT 15
# 若接收到“DELAYED”、“BUSY”、“ERROR”、“NO DIALTONE”、“NO CARRIER”,则退出脚本
ABORT "DELAYED"
ABORT "BUSY"
ABORT "ERROR"
ABORT "NO DIALTONE"
ABORT "NO CARRIER"
# 无期望,直接发送AT字符串
'' AT
# 以下内容可以根据自己模块提供的AT命令手册查询含义
OK ATS0=0
OK ATE0V1
# 设置APN,移动、联通、电信各不相同,见文末表格
OK AT+CGDCONT=1,"IP","CMNET"
# 拨号开启GPRS服务,号码移动、联通、电信各不相同,见文末表格
OK ATD*99***1#
#期望收到CONNECT
CONNECT
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
ip-up脚本
之前的脚本如果没有问题,正常的话运行 pppd call gprs 就可以拨号成功,并且ifconfig后可以查看到ppp0这个网卡。但是如果你在拨号之前已经启用了以太网eth0,此时指定使用ppp0网卡ping指定ip或域名ping -I ppp0 www.baidu.com 并不能成功,原因有两个,一个是路由表中的默认网关是之前eth0生成的,一个是默认的dns服务器地址有问题。
解决默认网关问题
在pppd脚本中使能了defaultroute后,pppd会在拨号成功后向路由表中添加一条默认网关信息,但是因为之前已经有一条默认网关了,于是添加失败,默认网关依然是之前eth设置的,因此在pppd call gprs之前我们应该先route del default来删除默认路由(最好写个脚本来实现删除默认路由–拨号等一系列操作)。
解决dns问题
在pppd脚本中使能了usepeerdns后,pppd会在拨号成功后,在/etc/ppp下生成resolv.conf,这是ISP运营商提供的dns,我们应该将拷贝或者连接到/etc目录下,当然这件事就可以交给ip-up来做。
ip-up脚本:
#!/bin/bash
#ip-up
dns_file="/etc/resolv.conf"
rm "$dns_file"
ln /etc/ppp/resolv.conf "$dns_file"
1
2
3
4
5
6
ip-down脚本
按照ppp拨号过程中打印信息可以发现,在退出pppd进程时,会调用/etc/ppp/ip-down。因此删除默认网关,恢复dns就交由ip-down脚本做了。
#!/bin/bash
#ip-down
#set -vx
dns_file="/etc/resolv.conf"
rm $dns_file
cat > "$dns_file" <<EOF
# auto create by ip-down
nameserver 114.114.114.114
nameserver 8.8.8.8
EOF
chmod 755 "$dns_file"
/etc/init.d/networking restart
echo "Set dns for eth0"
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
调试信息
运行pppd call gprs后成功拨号的调试打印信息:
timeout set to 15 seconds
abort on (DELAYED)
abort on (BUSY)
abort on (ERROR)
abort on (NO DIALTONE)
abort on (NO CARRIER)
timeout set to 15 seconds
send (^MAT^M)
expect (OK)
^M
OK
-- got it
send (ATS0=0^M)
expect (OK)
^M
^M
OK
-- got it
send (ATE0V1^M)
expect (OK)
^M
^M
OK
-- got it
send (AT+CGDCONT=1,"IP","CMNET"^M)
expect (OK)
^M
^M
OK
-- got it
send (ATD*99***1#^M)
expect (CONNECT)
^M
^M
CONNECT
-- got it
Script /usr/sbin/chat -s -v -f /etc/ppp/gprs-connect-chat finished (pid 21001), status = 0x0
Serial connection established.
using channel 19
Using interface ppp0
Connect: ppp0 <--> /dev/ttyUSB3
Warning - secret file /etc/ppp/pap-secrets has world and/or group access
sent [LCP ConfReq id=0x4 <asyncmap 0x0> <magic 0xc2c88df0> <pcomp> <accomp>]
rcvd [LCP ConfReq id=0x60 <asyncmap 0x0> <auth chap MD5> <magic 0x5742a3f6> <pcomp> <accomp>]
No auth is possible
sent [LCP ConfRej id=0x60 <auth chap MD5>]
rcvd [LCP ConfAck id=0x4 <asyncmap 0x0> <magic 0xc2c88df0> <pcomp> <accomp>]
rcvd [LCP ConfReq id=0x61 <asyncmap 0x0> <magic 0x5742a3f6> <pcomp> <accomp>]
sent [LCP ConfAck id=0x61 <asyncmap 0x0> <magic 0x5742a3f6> <pcomp> <accomp>]
sent [LCP EchoReq id=0x0 magic=0xc2c88df0]
sent [CCP ConfReq id=0x2 <deflate 15> <deflate(old#) 15> <bsd v1 15>]
sent [IPCP ConfReq id=0x4 <compress VJ 0f 01> <addr 0.0.0.0> <ms-dns1 0.0.0.0> <ms-dns2 0.0.0.0>]
rcvd [LCP DiscReq id=0x62 magic=0x5742a3f6]
rcvd [LCP EchoRep id=0x0 magic=0x5742a3f6 c2 c8 8d f0]
rcvd [LCP ProtRej id=0x63 80 fd 01 02 00 0f 1a 04 78 00 18 04 78 00 15 03 2f]
Protocol-Reject for 'Compression Control Protocol' (0x80fd) received
rcvd [IPCP ConfReq id=0x2e]
sent [IPCP ConfNak id=0x2e <addr 0.0.0.0>]
rcvd [IPCP ConfRej id=0x4 <compress VJ 0f 01>]
sent [IPCP ConfReq id=0x5 <addr 0.0.0.0> <ms-dns1 0.0.0.0> <ms-dns2 0.0.0.0>]
rcvd [IPCP ConfReq id=0x2f]
sent [IPCP ConfAck id=0x2f]
rcvd [IPCP ConfNak id=0x5 <addr 10.149.99.154> <ms-dns1 211.136.17.107> <ms-dns2 211.136.20.203>]
sent [IPCP ConfReq id=0x6 <addr 10.149.99.154> <ms-dns1 211.136.17.107> <ms-dns2 211.136.20.203>]
rcvd [IPCP ConfAck id=0x6 <addr 10.149.99.154> <ms-dns1 211.136.17.107> <ms-dns2 211.136.20.203>]
Could not determine remote IP address: defaulting to 10.64.64.64
local IP address 10.149.99.154
remote IP address 10.64.64.64
primary DNS address 211.136.17.107
secondary DNS address 211.136.20.203
Script /etc/ppp/ip-up started (pid 21008)
Script /etc/ppp/ip-up finished (pid 21008), status = 0x0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
以下为设置了断线重拨(lcp-echo-failure、lcp-echo-interval)后的打印信息:
No response to 6 echo-requests # 6次echo未收到ISP回应,自动重拨。
Serial link appears to be disconnected.
Connect time 719.4 minutes.
Sent 0 bytes, received 0 bytes.
Script /etc/ppp/ip-down started (pid 29547) # 调用了 /etc/ppp/ip-down 但是我脚本的未运行
sent [LCP TermReq id=0x5 "Peer not responding"]
Script /etc/ppp/ip-down finished (pid 29547), status = 0x0
sent [LCP TermReq id=0x6 "Peer not responding"]
Connection terminated.
Modem hangup
timeout set to 15 seconds
abort on (DELAYED)
abort on (BUSY)
abort on (ERROR)
abort on (NO DIALTONE)
abort on (NO CARRIER)
timeout set to 15 seconds
send (^MAT^M)
expect (OK)
^M
OK
-- got it
send (ATS0=0^M)
expect (OK)
^M
^M
OK
-- got it
send (ATE0V1^M)
expect (OK)
^M
^M
OK
-- got it
send (AT+CGDCONT=1,"IP","CMNET"^M)
expect (OK)
^M
^M
OK
-- got it
send (ATD*99***1#^M)
expect (CONNECT)
^M
^M
CONNECT
-- got it
Script /usr/sbin/chat -s -v -f /etc/ppp/gprs-connect-chat finished (pid 29664), status = 0x0
Serial connection established.
using channel 20
Using interface ppp0
Connect: ppp0 <--> /dev/ttyUSB3
Warning - secret file /etc/ppp/pap-secrets has world and/or group access
sent [LCP ConfReq id=0x7 <asyncmap 0x0> <magic 0xf8a6761> <pcomp> <accomp>]
rcvd [LCP ConfReq id=0x64 <asyncmap 0x0> <auth chap MD5> <magic 0x59d5de84> <pcomp> <accomp>]
No auth is possible
sent [LCP ConfRej id=0x64 <auth chap MD5>]
rcvd [LCP ConfAck id=0x7 <asyncmap 0x0> <magic 0xf8a6761> <pcomp> <accomp>]
rcvd [LCP ConfReq id=0x65 <asyncmap 0x0> <magic 0x59d5de84> <pcomp> <accomp>]
sent [LCP ConfAck id=0x65 <asyncmap 0x0> <magic 0x59d5de84> <pcomp> <accomp>]
sent [LCP EchoReq id=0x0 magic=0xf8a6761]
sent [CCP ConfReq id=0x3 <deflate 15> <deflate(old#) 15> <bsd v1 15>]
sent [IPCP ConfReq id=0x7 <compress VJ 0f 01> <addr 0.0.0.0> <ms-dns1 0.0.0.0> <ms-dns2 0.0.0.0>]
rcvd [LCP DiscReq id=0x66 magic=0x59d5de84]
rcvd [LCP EchoRep id=0x0 magic=0x59d5de84 0f 8a 67 61]
rcvd [LCP ProtRej id=0x67 80 fd 01 03 00 0f 1a 04 78 00 18 04 78 00 15 03 2f]
Protocol-Reject for 'Compression Control Protocol' (0x80fd) received
rcvd [IPCP ConfReq id=0x30]
sent [IPCP ConfNak id=0x30 <addr 0.0.0.0>]
rcvd [IPCP ConfRej id=0x7 <compress VJ 0f 01>]
sent [IPCP ConfReq id=0x8 <addr 0.0.0.0> <ms-dns1 0.0.0.0> <ms-dns2 0.0.0.0>]
rcvd [IPCP ConfReq id=0x31]
sent [IPCP ConfAck id=0x31]
rcvd [IPCP ConfNak id=0x8 <addr 10.42.72.220> <ms-dns1 211.136.17.107> <ms-dns2 211.136.20.203>]
sent [IPCP ConfReq id=0x9 <addr 10.42.72.220> <ms-dns1 211.136.17.107> <ms-dns2 211.136.20.203>]
rcvd [IPCP ConfAck id=0x9 <addr 10.42.72.220> <ms-dns1 211.136.17.107> <ms-dns2 211.136.20.203>]
Could not determine remote IP address: defaulting to 10.64.64.64
local IP address 10.42.72.220
remote IP address 10.64.64.64
primary DNS address 211.136.17.107
secondary DNS address 211.136.20.203
Script /etc/ppp/ip-up started (pid 29675)
Script /etc/ppp/ip-up finished (pid 29675), status = 0x0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
三大运营商拨号设置
运营商(ISP) APN 拨号号码 账号 密码
中国联通WCDMA 3GNET *99# 空 空
中国电信CDMA 空 #777 ctnet@mycdma.cn vnet.mobi
中国移动TD-SCDMA CMNET 981# 空 空
中国移动GPRS/EGDE CMNET 99**1# 空 空
---------------------
作者:VesaMount
来源:CSDN
原文:https://blog.csdn.net/vesamount/article/details/83240506
版权声明:本文为博主原创文章,转载请附上博文链接!
嵌入式Linux利用ppp实现4G模块联网的更多相关文章
- 嵌入式Linux系统---ppp拨号,4G模块上网【转】
本文转载自:http://blog.csdn.net/qq562029186/article/details/65438553 4G模块PPP拨号上网 方法1 所需文件: xxx-chat-conne ...
- 嵌入式Linux利用Wifi搭建无线服务器(物联网实践之无线网关)
在 http://www.cnblogs.com/heat-man/p/4564539.html中,在嵌入式Linux开发板上我们从最底层实现了一个智能家居的远程控制系统,然而采取的是用网线连接到交换 ...
- 迅为嵌入式4412平台兼容3G/4G模块的安卓开发板
安卓开发板特点说明: 1. 配备16G固态硬盘EMMC存储 2. 64位双通道2GB内存 三星S5M8767电源管理 板载高精度GPS模块 CAN,RS-485等工业接口 板载WIFI蓝牙模块,陀螺仪 ...
- (转) 嵌入式 Linux 利用 udev 实现自动检测挂载U盘
本文链接:https://blog.csdn.net/cfl927096306/article/details/95180940 udev配置文件是/etc/udev/udev.conf,也许长这样: ...
- linux下ppp拨号无线上网
linux下用ppp上网需要两个程序:pppd和chat.ubuntu自带pppd和chat,可以使用man查看具体使用方法. 典型的ppp拨号需要准备几个文件: 1. pppd脚本. 2. chat ...
- 龙尚3G、4G模块嵌入式Linux系统使用说明【转】
本文转载自;http://blog.csdn.net/zqixiao_09/article/details/52506812 驱动部分: 1.kernle/drivers/usb/serial/opt ...
- 关于PPP拨号 和 AT指令实现GPRS模块联网的疑问
以下内容摘抄自互联网: ppp拨号 与 at命令的疑问 GPRS模块在Linux平台上ppp拨号上网总结与心得 以PPP拨号实现GPRS与因特网的数据通信的具体实现流程 问: 我刚接触GPRS,了解A ...
- Linux开源模块迁移概述暨交叉编译跨平台移植总结--从《嵌入式Linux驱动模板简洁和工程实践》
本文摘录<嵌入式Linux驱动模板简洁和工程实践>一本书"开发和调试技术". Linux强大的是,有那么多的开源项目可以使用.通常非常需要可以通过寻找相关的源模块被定义 ...
- 在ARM-linux上实现4G模块PPP拨号上网【转】
本文转载自:http://blog.csdn.net/zqixiao_09/article/details/52540887 在ARM平台上实现4G模块的PPP拨号上网,参考网上的资料和自己的理解,从 ...
随机推荐
- 《基于SIRS模型的行人过街违章传播研究》
My Focus: 行人违章过街 这一行为的传播与控制 Behavior definition in this paper: 人在生活中表现出来的生活态度及具体的生活方式 Title: Researc ...
- objcopy使用
objcopy - copy and translate object files:用于二进制文件的拷贝和翻译(转化) objcopy的man文件如下所示: objcopy [-F bfdname|- ...
- simulate_click
#!/bin/bashlet actual_x=104+144*$[$2-1]let actual_y=945+144*$[$1-1]adb shell input tap ${actual_x} $ ...
- Go语言核心36讲(Go语言进阶技术十三)--学习笔记
19 | 错误处理(上) 提到 Go 语言中的错误处理,我们其实已经在前面接触过几次了. 比如,我们声明过error类型的变量err,也调用过errors包中的New函数. 我们说过error类型其实 ...
- 重新整理 .net core 实践篇——— filter[四十四]
前言 简单介绍一下filter 正文 filter 的种类,微软文档中写道: 每种筛选器类型都在筛选器管道中的不同阶段执行: 授权筛选器最先运行,用于确定是否已针对请求为用户授权. 如果请求未获授权, ...
- Redis监控调研
1 调研目的 主要的目的是想调研各大云平台有关Redis监控功能的实现,但是最后我发现各大云平台提供的监控功能都比较基础,比如我想看诸如访问频率较高的HotKey.占用内存较大的Bigkey等指标,它 ...
- [转]技术往事:改变世界的TCP/IP协议
原文链接 : http://www.52im.net/thread-520-1-1.html 1.前言 作为应用层开发人员,接触最多的网络协议通常都是传输层的TCP(与之同处一层的另一个重要协议是UD ...
- k8s入坑之路(8)kube-proxy详解
kube-proxy 每台机器上都运行一个 kube-proxy 服务,它监听 API server 中 service 和 endpoint 的变化情况,并通过 iptables 等来为服务配置负载 ...
- APP自动化之Hybrid自动化解决方案(七)
基于UIAutomator+ChromeDriver模式(UIAutomator安卓原生引擎) 原理:native(原生)部分使用UIAutomator,webview部分使用ChromeDriver ...
- 2020 天翼杯 部分wp
天翼杯 呜呜呜呜 是我太菜了 Web APItest 源码 const express = require("express"); const cors = require(&qu ...