实现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/目录下可以看到映射出来的虚拟串口,证明驱动已经起作用了

这里写图片描述

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 \d\c

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

ABORT "ERROR"
ABORT "NO DIALTONE"
SAY "\NSending break to the modem\n"
""\k"
""+++ATH"
SAY "\nGood bay\n"

将以上三个脚本放到/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下的拨号测试就成功了。

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值