Arm Linux编译PPP软件包-4G模块联网测试

4 篇文章 0 订阅

一、开发环境

硬件:nuc980
ubuntu:22.04.03
ppp软件包:ppp-2.4.4.tar.gz

在这里插入图片描述
ppp软件包下载地址
https://download.samba.org/pub/ppp/

拨号流程如图:
在这里插入图片描述

二、nuc980内核配置

Device Drivers → Network device support   →  PPP (point-to-point protocol) support

在这里插入图片描述

保存,重新编译。

三、交叉编译

将下载的 ppp-2.4.4.tar.gz 软件包拷贝到 Ubuntu 下,并解压。

解压指令:
tar -xvf ppp-2.4.4.tar.gz

解压完成得到 ppp-2.4.4 目录,进入该目录。
在这里插入图片描述
生成配置文件:

./configure

在这里插入图片描述
编译,指定交叉编译的工具链:

make CC=arm-linux-gcc

在这里插入图片描述

编译完成,编译完成后,分别在 chat、pppd、pppdump、pppstats 四个目录下生成 chat、pppd、pppdump、pppstats 可执行文件,用于后面的 4G 模块联网测试。
在这里插入图片描述
在这里插入图片描述

四、过程

将目录下pppd 、chat 、pppdump 、pppstats下可执行程序pppd, chat, pppdump, pppstats拷贝到开发板 /usr/sbin 目录下
在这里插入图片描述

pppd:点对点协议守护进程,其功能为实现ppp策略性的内容,包括所有鉴权、压缩/解压和加密/解密等扩展功能的控制协议。
pppdump:将使用pppd记录选项编写的文件转换为人类可读的格式。
pppstats:显示PPP连线状态。pppstats(point to point protocol status)。
chat:调制解调器的自动对话脚本,Chat程序定义了一个计算机和调制解调器之间对话交流,其主要目的是用来在本地PPPD和远端PPPD程序之间建立连接(简单说就是与4G模块进行AT命令交互的流程表,最终实现与ISP运营商的连接)。

启动开发板,进入 /etc 目录 ,查看该目录下是否有 ppp 目录 和ppp/peers 目录。没有则创建,指令如下:

	mkdir /etc/ppp
	mkdir /etc/ppp/peers

在这里插入图片描述
进入 /etc/ppp/peers 目录下,创建4g-ppp文件

vi /etc/ppp/peers/4g-ppp

退出保存,即可船舰4g-ppp文件
参考 quectel-ppp 文件

# /etc/ppp/peers/quectel-pppd
# Usage:root>pppd call quectel-pppd
#Modem path, like /dev/ttyUSB3,/dev/ttyACM0, depend on your module, default path is /dev/ttyUSB3
/dev/ttyUSB3 115200
#Insert the username and password for authentication, default user and password are test
user "" password ""
# The chat script, customize your APN in this file
connect 'chat -s -v -f /etc/ppp/peers/quectel-chat-connect'
# The close script
disconnect 'chat -s -v -f /etc/ppp/peers/quectel-chat-disconnect'
# Hide password in debug messages
hide-password
# The phone is not required to authenticate
noauth
# Debug info from pppd
debug
# If you want to use the HSDPA link as your gateway
defaultroute
# pppd must not propose any IP address to the peer
noipdefault
# No ppp compression
novj
novjccomp
noccp
ipcp-accept-local
ipcp-accept-remote
local
# For sanity, keep a lock on the serial line
lock
modem
dump
nodetach
# Hardware flow control
nocrtscts
remotename 3gppp
ipparam 3gppp
ipcp-max-failure 30
# Ask the peer for up to 2 DNS server addresses
usepeerdns

4g-ppp文件 内容如下:

# /etc/ppp/peers/4g-ppp
# Usage:root>pppd call 4g-ppp

/dev/ttyS2 115200		# ttyname 串口端口,若非以”/“开头,则会自动补充”/dev/“  波特率:115200
crtscts					# 硬件流控(注意,如果没有流控就不要开,否则会导致chat总是没有回应)
user "test" password "123456"	
hide-password
noauth					# 无需身份验证
debug					# 调试模式 pppd将以可读形式记录发送或接收的所有控制数据包的内容
defaultroute			# 添加ISP网关至路由表,作为默认路由
noipdefault				# 启用本地ip,由ISP提供
novj					# 启用Van  Jacobson格式的tcp/ip报头
novjccomp			
noccp
ipcp-accept-local
ipcp-accept-remote
local
lock
modem
dump
nodetach				# 前台运行
remotename 3gppp
ipparam 3gppp

# 使能一下两个选项可以实现ppp掉线自动重播
lcp-echo-failure 6		# lcp连接失败尝试次数
lcp-echo-interval 10	# lcp echo发送间隔

persist					# 连接终止后不要退出,而是重新尝试连接,连接次数收到maxfail限制
ipcp-max-failure 30

# 向ISP请求2个dns服务器地址。这两个地址将以DNS1与DNS2两个环境变量传送到/etc/ppp/ip-up脚本中,
# 并且将环境变USEPEERDNS量置为1
usepeerdns

# 断开连接
disconnect 'chat -s -v -f /etc/ppp/peers/4g-chat-disconnect'
# 启动ppp协议前,进行硬件拨号
connect 'chat -s -v -f /etc/ppp/peers/4g-chat-connect'


参考quectel-chat-connect 文件内容 如下:


# /etc/ppp/peers/quectel-chat-connect
ABORT "BUSY"
ABORT "NO CARRIER"
ABORT "NO DIALTONE"
ABORT "ERROR"
ABORT "NO ANSWER"
TIMEOUT 30
"" AT
OK ATE0
OK ATI;+CSUB;+CSQ;+CPIN?;+COPS?;+CGREG?;&D2
# Insert the APN provided by your network operator, default apn is 3gnet
OK AT+CGDCONT=1,"IP","INTERNET.IOT",,0,0
#OK AT+CGDCONT=1,"IP","CMNET",,0,0
OK ATD*99#
CONNECT

创建 4g-chat-connect 文件

vi /etc/ppp/peers/4g-chat-connect

内容如下:

# /etc/ppp/peers/4g-chat-connect
ABORT "BUSY"
ABORT "NO CARRIER"
ABORT "NO DIALTONE"
ABORT "ERROR"
ABORT "NO ANSWER"
TIMEOUT 30
"" AT
OK ATE0
OK ATI;+CSUB;+CSQ;+CPIN?;+COPS?;+CGREG?;&D2
# Insert the APN provided by your network operator, default apn is 3gnet
OK AT+CGDCONT=1,"IP","3gnet",,0,0
OK ATD*99#
CONNECT


参考quectel-chat-disconnect 文件


# /etc/ppp/peers/quectel-chat-disconnect
ABORT "ERROR"
ABORT "NO DIALTONE"
SAY "\nSending break to the modem\n"
""  +++
""  +++
""  +++
SAY "\nGoodbay\n"

创建 4g-chat-disconnect 文件

vi /etc/ppp/peers/4g-chat-disconnect

内容如下:

# /etc/ppp/peers/quectel-chat-disconnect
ABORT "ERROR"
ABORT "NO DIALTONE"
SAY "\nSending break to the modem\n"
""  +++
""  +++
""  +++
SAY "\nGoodbay\n"


拷贝ppp-2.4.5/scripts/下的ip-down.local.add、ip-up.local.add,然后把名字改一下,改成ip-up、ip-down,文件拷贝地址 /etc/ppp 。
在这里插入图片描述
在这里插入图片描述

ip-down 内容如下


# ip-down
# This sample code shows you one way to modify your setup to allow automatic
# configuration of your resolv.conf for peer supplied DNS addresses when using
# the `usepeerdns' option.
#
# In my case I just added this to my /etc/ppp/ip-down.local script. You may need to
# create an executable script if one does not exist.
#
# Nick Walker (nickwalker@email.com)
#

if [ -n "$USEPEERDNS" -a -f /etc/ppp/resolv.conf ]; then
        if [ -f /etc/ppp/resolv.prev ]; then
                cp -f /etc/ppp/resolv.prev /etc/resolv.conf
        else
                rm -f /etc/resolv.conf
        fi
fi

ip-up 内容如下


# ip-up
# This sample code shows you one way to modify your setup to allow automatic
# configuration of your resolv.conf for peer supplied DNS addresses when using
# the `usepeerdns' option.
#
# In my case I just added this to my /etc/ppp/ip-up.local script. You may need to
# create an executable script if one does not exist.
#
# Nick Walker (nickwalker@email.com)
#

if [ -n "$USEPEERDNS" -a -f /etc/ppp/resolv.conf ]; then
        rm -f /etc/ppp/resolv.prev
        if [ -f /etc/resolv.conf ]; then
                cp /etc/resolv.conf /etc/ppp/resolv.prev
                grep domain /etc/ppp/resolv.prev > /etc/resolv.conf
                grep search /etc/ppp/resolv.prev >> /etc/resolv.conf
                cat /etc/ppp/resolv.conf >> /etc/resolv.conf
        else
                cp /etc/ppp/resolv.conf /etc
        fi
fi

或者

启动开发板,进入 /etc 目录 ,查看该目录下是否有 ppp 目录 和ppp/peers 目录。没有则创建,指令如下:

	mkdir /etc/ppp
	mkdir /etc/ppp/peers

将编译的 chat、pppd、pppdump、pppstats 四个可执行文件拷贝到 /etc/ppp 目录下。然后在/etc/ppp 目录下创建 pap-secrets文件

vi pap-secrets

内容如下:

# Secrets for authentication using PAP
# client 	server 	secret 		IP addresses
card		* 		card		*

在 4G 信号在通信时候有一个密码的比对,密码对了就可以通信了。上面显示用户是 user,密码是 pwd 。

进入 peers 文件,创建 wcdma,写入内容如下:

hide-password
noauth
connect '/etc/ppp/chat -s -v -f /etc/ppp/peers/wcdma-chat-connect'
disconnect '/etc/ppp/chat -s -v -f /etc/ppp/peers/wcdma-chat-disconnect'
debug
/dev/ttyS2
115200
defaultroute
noipdefault
novj
novjccomp
noccp
ipcp-accept-local
ipcp-accept-remote
local
lock
dump
nodetach
user "card" 
password "card" 
crtscts
remotename 3gppp
ipparam 3gppp
usepeerdns

需要注意的是使用/dev/ttyS2 设备节点文件,“user “card””和“password “card””对应了 pap-secrets 文件中的用户名和密码。

# /etc/ppp/peers/wcdma
 
# Usage: sudo pppd call wcdma
 
# 连接调试时隐藏密码
hide-password
 
# 该手机不需要身份验证
noauth
 
# 用于呼叫控制脚本
connect '/etc/ppp/chat -s -v -f /etc/ppp/peers/wcdma-chat-connect'
 
# 断开连接脚本
disconnect '/etc/ppp/chat -s -v -f /etc/ppp/peers/wcdma-chat-disconnect'
 
# 调试信息,pppd将以可读的形式记录所有发送或接收的控制数据包的内容
debug
 
# 4G模块对应的串口设备名称
/dev/ttyS4
 
# 串口波特率
115200
 
# 使用默认路由,IPCP协商成功后,在系统路由表中添加一条缺省路由,使用对等体作为网关。当PPP连接断开时,删除此表项。
defaultroute
 
# 不使用默认IP:当没有指定本地IP地址时禁用默认行为,这是为了从主机名确定(如果可能)本地IP地址。
noipdefault
 
# 不使用PPP压缩
novj
novjccomp
noccp

#使用该选项,pppd将接受对等体对我们本地IP地址的想法,即使本地IP地址在选项中指定
ipcp-accept-local

#通过该选项,pppd将接受对等体对其(远端)IP地址的想法,即使远端IP地址在选项中指定
ipcp-accept-remote

#不要使用调制解调器控制线
local
 
# 指定pppd应该为串行设备创建一个锁文件,以确保对该设备的独占访问,其他程序在发现这个文件后,就能得知相应的串口已经被使用。
lock

#使用转储选项,pppd将打印所有已设置的选项值
dump
 
# 保持pppd连接到终端。在pppd程序需要放到后台运行时,最好不要该选项
nodetach
 
# 用户名 密码
#user ctnet@mycdma.cn
user  "card" 
#password vnet.mobi
password "card" 
#电信需要用户名和密码,移动、联通拨号不需要,下文给出不同运营商的配置
 
# 硬件流量控制
crtscts

#将用于身份验证的远程系统的假定名称设置为name
remotename 3gppp

#为ip-up、ip-pre-up和ip-down脚本提供额外参数。如果提供了这个选项,提供的字符串将作为这些脚本的第6个参数提供
ipparam 3gppp
 
# 向对端请求最多2个DNS服务器地址
usepeerdns

创建 wcdma-chat-connect,写入内容如下:


ABORT "BUSY"
ABORT "NO CARRIER"
ABORT "NO DIALTONE"
ABORT "ERROR"
ABORT "NO ANSWER"
TIMEOUT 120
"" AT
OK \rATZ
#联通
OK \rAT+CGDCONT=1,"IP","3gnet",,0,0
OK-AT-OK ATDT*99#
#移动
#OK \rAT+CGDCONT=1,"IP","cmnet",,0,0
#OK-AT-OK ATDT*99***1#
# 电信
#OK \rAT+CGDCONT=1,"IP",""
#OK-AT-OK ATDT#777
CONNECT \d\c

这里的
OK \rAT+CGDCONT=1,“IP”,“3gnet”,0,0
OK-AT-OK ATDT*99#
这两句话会根据移动、联通或者是电信而变化,这里用的是联通 4G。

# 连续5秒,收到以下字符,则退出执行
# 进行超时控制,增加对特殊情况的处理,加入下面字段
TIMEOUT 5  
ABORT   "BUSY"
ABORT   "ERROR"
ABORT   "NO ANSWER"
ABORT   "NO CARRTER"
ABORT   "NO DIALTONE"
 
#一个chat脚本都是由字符串对来组成的。前面的字符串都是期望获取的串,紧跟的是发送的字符串
# 例如 ""AT,不管收到什么字符串,先发出字符串AT
#      OK \rATZ,发送ATZ,希望收到的是OK
""AT
OK \rATZ
 
# 建立连接,电信为空,下文给出各运营商配置
OK \rAT+CGDCONT=1,"IP",""
 
# 拨号,#777是电信的拨号号码
OK-AT-OK ATDT#777
CONNECT \d\c

各运营商拨号上网设置:
在这里插入图片描述
在这里插入图片描述
 一般情况下,中国移动的拨号串为 *99***1# ,中国电信的拨号串为 #777 ,中国联通的拨号串为 *99# 。  

创建 wcdma-chat-disconnect,写入内容如下:


ABORT "ERROR"
ABORT "NO DIALTONE"
SAY "INSending break to the modem\n"

""\k"

""+++ATH"

SAY "\nGood bye\n"

ABORT "ERROR"
ABORT "NO DIALTONE"
SAY "\NSending break to the modem\n"
 
""\k"
#挂断电话
""+++ATH"
SAY "\nGood bye !\n"

或者 推荐 使用合宙官方提供的脚本,脚本如下:
/etc/ppp/peers/air-ppp
(请修改示例中设备名/dev/ttyUSB1为实际设备名)

debug
nodetach
dump
/dev/ttyUSB1
115200
nolock
nocrtscts
modem
hide-password
novj
novjccomp
ipcp-accept-local
ipcp-accept-remote
noipdefault
usepeerdns
noccp
connect 'chat -s -v -f /etc/ppp/peers/air-chat-connect'
disconnect 'chat -s -v -f /etc/ppp/peers/air-chat-disconnect'

/etc/ppp/peers/air-chat-connect

# (示例中默认使用ATD*99#激活第一路承载,如需使用第五路承载请修改为ATD*99***5#)
ABORT "NO CARRIER"
ABORT "NO DIALTONE"
ABORT "NO ANSWER"
ABORT "BUSY"
ABORT "Username/Password Incorrect"
""      AT
OK-+++-OK ATH0
OK      AT+CREG?
OK      AT+CPIN?
OK      AT+CESQ
OK      ATD*99#
CONNECT ""

/etc/ppp/peers/air-chat-disconnect

ABORT "ERROR"
ABORT "NO DIALTONE"
SAY "\nSending break to the modem\n"
"" "\K"
"" "+++ATH0"
SAY "\nGood bay\n"

五、测试

进行拨号连接,执行以下命令:

pppd call 4g-ppp &

也可以自己写个4g_up.sh脚本运行:

#!/bin/bash

pppd call 4g-ppp &

如果按照第二种过程设置的,则需要在 /etc/ppp 目录下输入指令:

./pppd call wcdma &

遇到的问题

Can't create lock file /var/lock/LCK..ttyS2: No such file or directory

解决:
按照提示,查看 /var 目录下是否存在此文件夹,如果没有则需要在 /var 目录下创建 lock 文件夹 。

测试合宙官方提供的脚本
通过pppd拨号了

cd /etc/ppp/peers
pppd call air-ppp

在这里插入图片描述

拨号成功后,需要为新建的ppp0网卡配置route

route add default ppp0

在这里插入图片描述

参考:
https://blog.csdn.net/pjwshuai/article/details/124533452
https://blog.csdn.net/weixin_45121946/article/details/107284629
https://doc.openluat.com/wiki/29?wiki_page_id=3664
https://doc.openluat.com/wiki/6?wiki_page_id=81

  • 23
    点赞
  • 21
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
编译 `arm-linux-gnueabih-gdb` 和 `arm-linux-gnueabih-gdbserver` 的步骤如下: 1. 下载 GNU 工具链 - 从官网下载源代码:https://ftp.gnu.org/gnu/binutils/binutils-2.36.tar.gz - 解压缩源代码:`tar -zxvf binutils-2.36.tar.gz` 2. 配置交叉编译环境变量 - `export CC=arm-linux-gnueabihf-gcc` - `export CXX=arm-linux-gnueabihf-g++` - `export AR=arm-linux-gnueabihf-ar` - `export AS=arm-linux-gnueabihf-as` - `export LD=arm-linux-gnueabihf-ld` - `export RANLIB=arm-linux-gnueabihf-ranlib` 3. 配置和编译 `binutils` - 进入源代码目录:`cd binutils-2.36` - 创建编译目录:`mkdir build && cd build` - 配置交叉编译环境:`../configure --host=arm-linux-gnueabihf --target=arm-linux-gnueabihf --prefix=/usr/local/arm-linux-gnueabihf` - 编译:`make` - 安装:`make install` 4. 配置和编译 `gdb` - 下载 GDB 源代码:https://ftp.gnu.org/gnu/gdb/gdb-10.1.tar.gz - 解压缩源代码:`tar -zxvf gdb-10.1.tar.gz` - 进入源代码目录:`cd gdb-10.1` - 创建编译目录:`mkdir build && cd build` - 配置交叉编译环境:`../configure --host=arm-linux-gnueabihf --target=arm-linux-gnueabihf --prefix=/usr/local/arm-linux-gnueabihf` - 编译:`make` - 安装:`make install` 5. 配置和编译 `gdbserver` - 下载 GDB 源代码:https://ftp.gnu.org/gnu/gdb/gdb-10.1.tar.gz - 解压缩源代码:`tar -zxvf gdb-10.1.tar.gz` - 进入源代码目录:`cd gdb-10.1/gdb/gdbserver` - 创建编译目录:`mkdir build && cd build` - 配置交叉编译环境:`export CC=arm-linux-gnueabihf-gcc` - 配置编译选项:`../configure --host=arm-linux-gnueabihf --target=arm-linux-gnueabihf --prefix=/usr/local/arm-linux-gnueabihf` - 编译:`make` - 安装:`make install` 注意:以上步骤仅供参考,实际操作时可能会因为环境和版本差异而有所不同。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值