我是靠谱客的博主 耍酷帆布鞋,最近开发中收集的这篇文章主要介绍实现4G模块EC20在linux系统下的拨号上网,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

前言:

为了方便查看博客,特意申请了一个公众号,附上二维码,有兴趣的朋友可以关注,和我一起讨论学习,一起享受技术,一起成长。

在这里插入图片描述


1.实验目的:

实现4G模块EC20在linux系统下的拨号上网(Linux最小系统)

2.实验平台:

迅为4412开发板。EC20带有UART和USB接口,向linux内核添加4G模块的驱动和PPP协议的支持,然后编译内核并下载到开发板。

3.实验流程:

(1)驱动实现:主要就是模块的 USB VID和PID,这个我是把模块插到开发板上,使用lsusb得到:

这里写图片描述

a.把它加到Linux源码的drivers/usb/serial/option.c文件里,

#define EC20_VID 0x1E0E
#define EC20_PID 0x9001

b.在 option_ids 列表中增加
{ USB_DEVICE(EC20_VID, EC20_PID)},

c.make menuconfig 配置:

USB相关:

[] Device Drivers →
[
] USB Support →
[] USB Serial Converter support →
[
] USB driver for GSM and CDMA modems

PPP相关:(和PPP相关的,我都选上了)

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

d.保存退出,执行make

在arch/arm/boot目录下得到zImage文件,烧写到开发板

4.调试
a.插上模块,在/dev/目录下可以看到映射出来的虚拟串口,证明驱动已经起作用了

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-d0xCwkKF-1593829234355)(https://img-blog.csdn.net/20170109184925432?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvd3d0MTg4MTE3MDc5NzE=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)]

b.用at指令测试
先执行:cat /dev/ttyUSB2 & (后台将AT测试口打开)

这里写图片描述

下面测试:发送AT,返回OK,模块响应

这里写图片描述

测试信号强度:发送AT_CSQ,返回的信号正常

这里写图片描述

c.拨号

1.拨号上网脚本wcdma:

#/etc/ppp/peers/wcdma
# Usage:root>pppd call wcdma
# Hide password in debug messages
hide-password
# The phone is not required to authenticate
noauth
# The chat script (be sure to edit that file,too!)
connect '/usr/sbin/chat -s -v -f /etc/ppp/peers/wcdma-chat-connect'  #制定了要使用的chat脚本的位置。加上参数-v 告诉 chat命令将其所有的输出/入拷贝到系统记录里(通常是 /var/log/messages)。
# The close script(be sure to edit that file,too!)
disconnect '/usr/sbin/chat -s -v -f /etc/ppp/peers/wcdma-chat-disconnect'
# Debug info from pppd
debug	#加入调试信息
# Serial Device to which the HSPDA phone is connected
/dev/ttyUSB3	#指定连接使用的设备
# Serial port line speed
115200	#设置连接使用的控制字符传输速率
# If you want to use the HSDPA link as your gateway
defaultroute #使用默认线路
# pppd must not propose any IP address to the peer
noipdefault #不使用默认IP就可以加入参数noipdefault
# No ppp compression
novj
novjccomp
noccp
ipcp-accept-local #要求peer也就是isp给自己分配动态的IP地址
ipcp-accept-remote
local
# For sanity, keep a lock on the serial line
lock  #则创建一个锁定文件,其他程序在发现存在这个文件后,就能得知相应的串口已经被使用。
dump
# Keep pppd attached to the terminal
# Comment this to get daemon mode pppd
nodetach
user 
password 
# Hardware flow control
crtscts  #告诉ppp使用modem的硬件流量控制
remotename 3gppp
ipparam 3gppp
# Ask the peer for up to 2 DNS server addresses
usepeerdns #使用服务器端协商的DNS

2.chat脚本 (wcdma-chat-connect)

ABORT "BUSY"
ABORT "NO CARRIER"
ABORT "NO DIALTONE"
ABORT "ERROR"
ABORT "NO ANSWER"
TIMEOUT 120
"" AT
OK rATZ
# Connection to the network
OK  rAT+CGDCONT=1,"IP","3gnet",,0,0
# Dial the number
OK-AT-OK ATDT*99#
CONNECT dc

3.断开连接(wcdma-chat-disconnect)

ABORT "ERROR"
ABORT "NO DIALTONE"
SAY "NSending break to the modemn"
""k"
""+++ATH"
SAY "nGood bayn"

将以上三个脚本放到/etc/ppp/peers 目录下

d.与拨号相关的chat 和 pppd 命令
通过下载ppp源码编译得到(见我的SIM7100C的拨号上网),我直接拿过来用了,没问题。

e.执行pppd call wcdma & 后台运行拨号
现象:(拨号成功反馈的信息)

[root@iTOP-4412]# pppd call wcdma &
[2]-  Done(8)                    pppd call wcdma
[root@iTOP-4412]# pppd options in effect:
debug           # (from /etc/ppp/peers/wcdma)
nodetach                # (from /etc/ppp/peers/wcdma)
dump            # (from /etc/ppp/peers/wcdma)
noauth          # (from /etc/ppp/peers/wcdma)
user password           # (from /etc/ppp/peers/wcdma)
remotename 3gppp                # (from /etc/ppp/peers/wcdma)
/dev/ttyUSB3            # (from /etc/ppp/peers/wcdma)
115200          # (from /etc/ppp/peers/wcdma)
lock            # (from /etc/ppp/peers/wcdma)
connect /usr/sbin/chat -s -v -f /etc/ppp/peers/wcdma-chat-connect               # (from /etc/ppp/peers/wc[ 1940.106179] option_instat_callback: line=1423(status OK).161, 32, 0, 3, 2

disconnect /usr/sbin/chat -s -v -f /etc/ppp/peers/wcdma-chat-disconnect         # (from /etc/ppp/peers/wcdma)
crtscts         # (from /etc/ppp/peers/wcdma)
local           # (from /etc/ppp/peers/wcdma)
hide-password           # (from /etc/ppp/peers/wcdma)
novj            # (from /etc/ppp/peers/wcdma)
novjccomp               # (from /etc/ppp/[ 1940.138165] option_instat_callback: line=1423(status OK).161, 32, 0, 3, 2
peers/wcdma)
ipcp-accept-local               # (from /etc/ppp/peers/wcdma)
ipcp-accept-remote              # (from /etc/ppp/peers/wcdma)
ipparam 3gppp           # (from /etc/ppp/peers/wcdma)
noipdefault             # (from /etc/ppp/peers/wcdma)
defaultroute            # (from /etc/ppp/peers/wcdma)
usepeerdns              # (from /etc/ppp/peers/wcdma)
n[ 1940.170197] option_instat_callback: line=1423(status OK).161, 32, 0, 3, 2
occp            # (from /etc/ppp/peers/wcdma)
abort on (BUSY)
abort on (NO CARRIER)
abort on (NO DIALTONE)
abort on (ERROR)
abort on (NO ANSWER)
timeout set to 120 seconds
send (AT^M)
expect (OK)
AT^M^M
OK
 -- got it

send (^MATZ^M)
expect (OK)
^M
ATZ^M^M
OK
 -- got it

send (^MAT+CGDCONT=1,"IP","3gnet",,0,0^M)
[ 1940.234165] option_instat_callback: line=1423(status OK).161, 32, 0, 3, 2
[ 1940.266165] option_instat_callback: line=1423(status OK).161, 32, 0, 3, 2
expect (OK)
^M
AT+CGDCONT=1,"IP","3gnet",,0,0^M^M
OK
 -- got it

send (ATDT*99#^M)
[ 1940.586185] option_instat_callback: line=1423(status OK).161, 32, 0, 3, 2
expect (CONNECT)
^M
ATDT*99#^M^M
CONNECT
 -- got it

send (d)[ 1940.682171] option_instat_callback: line=1423(status OK).161, 32, 0, 3, 2
[ 1940.714162] option_instat_callback: line=1423(status OK).161, 32, 0, 3, 2
Script /usr/sbin/chat -s -v -f /etc/ppp/peers/wcdma-chat-connect finished (pid 18383), status = 0x0
Serial connection established.
using channel 2
Using interface ppp0
Connect: ppp0 <--> /dev/ttyUSB3
sent [LCP ConfReq id=0x1 <asyncmap 0x0> <magic 0x41dfbd79> <pcomp> <accomp>]
rcvd [LCP ConfReq id=0x3 <asyncmap 0x0> <auth chap MD5> <magic 0x4579c9d9> <pcomp> <accomp>]
No auth is possible
sent [LCP ConfRej id=0x3 <auth chap MD5>]
rcvd [LCP ConfAck id=0x1 <asyncmap 0x0> <magic 0x41dfbd79> <pcomp> <accomp>]
rcvd [LCP ConfReq id=0x4 <asyncmap 0x0> <magic 0x4579c9d9> <pcomp> <accomp>]
sent [LCP ConfAck id=0x4 <asyncmap 0x0> <magic 0x4579c9d9> <pcomp> <accomp>]
sent [IPCP ConfReq id=0x1 <addr 0.0.0.0> <ms-dns1 0.0.0.0> <ms-dns2 0.0.0.0>]
rcvd [LCP DiscReq id=0x5 magic=0x4579c9d9]
rcvd [IPCP ConfReq id=0x2]
sent [IPCP ConfNak id=0x2 <addr 0.0.0.0>]
rcvd [IPCP ConfNak id=0x1 <addr 10.50.224.88> <ms-dns1 123.123.123.123> <ms-dns2 123.123.123.124>]
sent [IPCP ConfReq id=0x2 <addr 10.50.224.88> <ms-dns1 123.123.123.123> <ms-dns2 123.123.123.124>]
rcvd [IPCP ConfReq id=0x3]
sent [IPCP ConfAck id=0x3]
rcvd [IPCP ConfAck id=0x2 <addr 10.50.224.88> <ms-dns1 123.123.123.123> <ms-dns2 123.123.123.124>]
Could not determine remote IP address: defaulting to 10.64.64.64
not replacing existing default route via 192.168.1.1
local  IP address 10.50.224.88
remote IP address 10.64.64.64
primary   DNS address 123.123.123.123
secondary DNS address 123.123.123.124

f.[root@iTOP-4412]# ifconfig (查看网络IP)

这里写图片描述

g.下面要ping 通IP和域名还需相关设置(这部分也见SIM7100C在Linux的拨号上网,配置是一样的)。

到此,Linux下的拨号测试就成功了。

参考:
SIM7100C拨号

原文地址:
(http://wentao1213.com/2016/11/26/itop4412-EC20-linux-PPP/)

最后

以上就是耍酷帆布鞋为你收集整理的实现4G模块EC20在linux系统下的拨号上网的全部内容,希望文章能够帮你解决实现4G模块EC20在linux系统下的拨号上网所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(48)

评论列表共有 0 条评论

立即
投稿
返回
顶部