在ARM平台上实现4G模块的PPP拨号上网,参考网上的资料和自己的理解,从一无所知到开发完成花了一周多。最后看到ARM板ping通www.baidu.com时甚是高兴,现将此过程整理如下。当然,除此之外要做的工作还有很多。
4G模块使用的SIMTECH
的SIM7100C,SIM7100C带有UART和USB接口,在考虑速度上我们使用USB接口和ARM进行通信。所以向linux内核添加3G模块的驱动(USB转串口驱动)和PPP协议的支持,然后编译内核并下载到开发板。
1.
编译内核
◇ 大容量存储驱动
> Device Drivers >
USB support
make
ARCH=arm menuconfig配置USB驱动:
USB Mass Storage support
[*] USB Mass Storage verbose debug
Realtek Card Reader support
[*] Realtek Card Reader autosuspend support
Datafab Compact Flash Reader support
◇ USB驱动
> Device Drivers >
USB support
Inventra Highspeed Dual Role Controller (TI, ADI,
...)
MUSB Mode Selection (Dual Role
mode) --->
Platform Glue Layer (TI DSPS platforms) --->
MUSB DMA mode (Disable DMA (always use PIO)) --->
USB Serial Converter support --->
[*] USBGeneric Serial
Driver
USBdriver for GSM and CDMA
modems
◇ PPP驱动
> Device Drivers >
Network device support
PPP (point-to-point protocol)
support
PPP BSD-Compress
compression
PPP Deflate
compression
[*] PPP
filtering
PPP MPPE compression
(encryption)
[*] PPP multilink
support
PPP over
Ethernet
PPP support for async serial ports
PPP support for sync tty
ports
SLIP (serial line)
support
[*] CSLIP
compressed headers
2.
交叉编译libusb
下载usblib库和libusb-compat
root@zhaoxc-VBox:/opt/usb-tools/libusb-1.0.20#
mkdir install
configure: error: "udev support requested but libudev
not installed"(解决:添加--disable-udev)
root@zhaoxc-VBox:/opt/usb-tools/libusb-1.0.20#
./configure
--host=arm-none-linux-gnueabi
--prefix=/opt/usb-tools/libusb-1.0.20/install
--disable-udev
root@zhaoxc-VBox:/opt/usb-tools/libusb-1.0.20#
make
root@zhaoxc-VBox:/opt/usb-tools/libusb-1.0.20#
make install
root@zhaoxc-VBox:/opt/usb-tools/libusb-1.0.20#
export
PKG_CONFIG_PATH=/opt/usb-tools/libusb-1.0.20/install/lib/pkgconfig:$PKG_CONFIG_PATH
root@zhaoxc-VBox:/opt/usb-tools/libusb-1.0.20#
echo
$PKG_CONFIG_PATH
编译libusb-compat:
root@zhaoxc-VBox:/opt/usb-tools/libusb-compat-0.1.5#
./configure
--host=arm-none-linux-gnueabi
--prefix=/opt/usb-tools/libusb-compat-0.1.5/install
root@zhaoxc-VBox:/opt/usb-tools/libusb-compat-0.1.5#
make
root@zhaoxc-VBox:/opt/usb-tools/libusb-compat-0.1.5#
make install
将生成的libusb-1.0.20和libusb-compat-0.1.5下的库文件复制到ARM板上的linux的/lib下面即可。
3.
交叉编译4G模块驱动
交叉编译GobiSerial.c(ARCH=arm
CC=arm-none-linux-gnueabi-gcc),得到GobiSerial.ko。复制到ARM板安装驱动
#insmod GobiSerial.ko
4.
查看驱动运行状况
插上4G模块,虚拟出6个ttyUSB,它们分别是:
root@am335x-evm:/#
ls
/dev/ttyUSB*
/dev/ttyUSB0 /dev/ttyUSB1 /dev/ttyUSB2 /dev/ttyUSB3 /dev/ttyUSB4 /dev/ttyUSB5
1)
/dev/ttyUSB0-diag port for output developing
messages
2)
/dev/ttyUSB1- NMEA port for GPS NMEA data output
3)
/dev/ttyUSB2-AT port for AT commands
4)
/dev/ttyUSB3-Modem port for ppp-dial
5)
/dev/ttyUSB4-audio port
6)
/dev/ttyUSB5-Virtual Net card
插上U盘,提示设备运行:
[75097.986054] usb 2-1: New USB device found,
idVendor=058f, idProduct=6387
[75097.993167] usb 2-1: New USB device strings:
Mfr=1, Product=2, SerialNumber=3
[75098.000689] usb 2-1: Product: Mass
Storage
[75098.004995] usb 2-1: Manufacturer:
Generic
[75098.009342] usb 2-1: SerialNumber:
AC3DF2EE
[75098.024341] usb-storage 2-1:1.0: USB Mass
Storage device detected
[75098.049922] scsi0 : usb-storage
2-1:1.0
lsusb命令查看结果:
Bus
001 Device 002: ID 1e0e:9001
Bus
002 Device 002: ID 058f:6387
Bus
001 Device 001: ID 1d6b:0002
Bus
002 Device 001: ID 1d6b:0002
5.
交叉编译PPP
6.
拨号脚本设置
root@am335x-evm:/etc/ppp#
vi gprs-connect-chat
#Chat
script for China Mobile, used SIMCOM sim4100 TD
module.
TIMEOUT 15
ABORT
"DELAYED"
ABORT
"BUSY"
ABORT
"ERROR"
ABORT
"NO DIALTONE"
ABORT
"NO CARRIER"
TIMEOUT 40
''
\rAT
OK
ATS0=0
OK
ATE0V1
OK
AT+CGDCONT=1,"IP","CMNET"
OK
AT+CGEQREQ=1,2,128,384,,,0,,,,,,
OK
ATDT*99*1#
CONNECT
root@am335x-evm:/etc/ppp/peers# vi
gprsdial
#/etc/ppp/peers/gprsdial
#
This is pppd script for China Mobile, used SIMCOM SIM7100
Module
#
Usage: root>pppd call gprs
#Interface should be used is the interface which
connects physics interface of S
/dev/ttyUSB3
115200
crtscts
modem
#noauth
debug
nodetach
#hide-password
usepeerdns
noipdefault
defaultroute
user
"cmnet"
0.0.0.0:0.0.0.0
#ipcp-accept-local
#ipcp-accept-remote
#lcp-echo-failure 12
#lcp-echo-interval 3
#noccp
#novj
#novjccomp
#persist
connect '/usr/sbin/chat -s -v -f
/etc/ppp/gprs-connect-chat'
#disconnect '/bin/chat -v -f
/etc/ppp/gprs-disconnect-chat'
6.
拨号
root@am335x-evm: pppd call
gprsdial
6.
测试
拨号之后进行测试,发现可以ping通ip但是无法ping通域名。这需要设置/etc/resolv.conf来添加DNS解析服务器的地址
文件/etc/resolv.conf配置DNS客户,它包含了主机的域名搜索顺序和DNS服务器的地址,每一行应包含一个关键字和一个或多个的由空格隔开的参数。下面是一个例子文件:
domain
test.com
search
www.test.com test.com
nameserver 202.96.128.86
nameserver 202.96.128.166
nameserver #定义DNS服务器的IP地址
domain #定义本地域名
search #定义域名的搜索列表
sortlist #对返回的域名进行排序
主要是nameserver关键字,如果没指定nameserver就找不到DNS服务器,其它关键字是可选的。
我这里只设置了两个DNS,如下:
ameserver 114.114.114.114
nameserver 8.8.8.8
参考文档:
How to use the SIM7100
module in Linux.pdf
------------------------------------------我是分割线---------------------------------------------
2016.11.25对以上部分脚本进行了补充注释,更方便理解【作者:从入门到放弃】
PPP协议的三组件包括PPP协议的封装方式、LCP协议和NCP协议。拨号成功需要一个建立过程,需要拨号双方根据协议规则进行的多个交互过程。
拨号配置的注释如下:
#/etc/ppp/peers/gprsdial
# This is pppd script for China
Mobile, used SIMCOM SIM7100 Module
# Usage: root>pppd call
gprs
#Interface should be used is the
interface which connects physics interface of SIM7100
Module.
/dev/ttyUSB3 //Modem port for ppp-dial
115200 //通信波特率
crtscts //接口带硬件流控
modem //使用数据机控制线路。这个选项是默认的。硬体流控,pppd将等待CD信号。
#noauth //不需要对方验证自己
debug //把调试信息输出到/var/log/messages
nodetach //不后台运行,默认是后台运行的
#hide-password //写log内容时不包括密码字符串,这个参数是默认的
usepeerdns //选中这个选项,从对方请求两个DNS地址.
对方提供的地址传给文件/etc/ppp/ip-up中的环境变量DNS1和DNS2,将环境变量USEPEERDNS设置成1.
而且pppd将创建一个文件/etc/ppp/resolv.conf
file,其中一个或两个服务器行包括由对方提供的地址。
noipdefault //关闭在没有指定本地IP位址时所进行的预设动作,这是用来由从主机名称决定(如果可能的话)本地IP位址。加上这个选项的话,彼端将必须在进行IPCP协商时(除非在指令行或在选项档中明确地指定它)提供本地的IP地址。
defaultroute //当 IPCP 协商完全成功时,
增加一个预设递送路径到系统的递送表,将彼端当作闸道器使用。这个项目在 ppp 连线中断後会移除。
user "cmnet" //设置由对方验证本地系统的用户名。
0.0.0.0:0.0.0.0
#ipcp-accept-local
//加上这个选项的话,pppd将会接受彼端对於本地IP位址的意见,即使本地的IP位址已经在某个选项中指定。
#ipcp-accept-remote
//加上这个选项的话,pppd将会接受彼端对於它的IP位址的意见,即使远端的IP位址已经在某个选项中指定。
#lcp-echo-failure 12
//如果有给这个选项,那麽如果传送n个LCP回应要求没有接收到有效的LCP回应回覆的话pppd将会推测彼端是死掉的。如果发生这种情形,pppd将会终结该连线。这个选项的使用要求一个非零的lcp-echo-interval参数值。这个选项可以用在硬体数据机控制线路无法使用的情况下当实际连线被中断之後(e.g.,数据机已经挂断)终结
pppd的执行。
#lcp-echo-interval 3
//如果有给这个选项,pppd每秒将会送出一个LCP回应要求(echo-request)封包(frame)给彼端。在Linux系统下,回应要求在n秒内没有从彼端接收到封包时会被送出。一般彼端应该以传送一个回应回覆(echo-reply)来反应该回应要求。这个选项可以与lcp-echo-failure选项一起使用来侦测不再连线的彼端。
#noccp //关闭压缩控制协议协商。若对方有漏洞会被来自PPPD的压缩控制协议协商请求干扰的情况下,需要设置该选项。
#novj //选中这个选项,将关闭双方的Van
Jacobson形式TCP/IP报文头压缩
#novjccomp //选中这个选项,将关闭Van
Jacobson形式TCP/IP报文头压缩中的连接ID压缩。Pppd将忽略来自Van
Jacobson形式压缩TCP/IP报文头中的连接ID字节,也不要求对方这样作。
#persist //连接中断后不退出,而是重新打开连接。
connect '/usr/sbin/chat -s -v -f
/etc/ppp/gprs-connect-chat' //[博文作者:从入门到放弃]
#disconnect '/bin/chat -v -f
/etc/ppp/gprs-disconnect-chat'
正常拨号的过程打印输出:
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 40
seconds
send (^MAT^M)
expect (OK)
AT^M^M
OK
-- got
it
send (ATS0=0^M)
expect (OK)
^M
ATS0=0^M^M
OK
-- got
it
send (ATE0V1^M)
expect (OK)
^M
ATE0V1^M^M
OK
-- got
it
send
(AT+CGDCONT=1,"IP","CMNET"^M)
expect (OK)
^M
^M
OK
-- got
it
send
(AT+CGEQREQ=1,2,128,384,,,0,,,,,,^M)
expect (OK)
^M
^M
OK
-- got
it
send (ATDT*99*1#^M)
expect (CONNECT)
^M
^M
CONNECT
-- got
it
Script /usr/sbin/chat -s -v -f
/etc/ppp/gprs-connect-chat finished (pid 1633), status =
0x0
Serial connection
established.
using channel 1
Using interface ppp0
Connect: ppp0
/dev/ttyUSB3
Warning - secret file
/etc/ppp/pap-secrets has world and/or group access
sent [LCP ConfReq id=0x1
]
rcvd [LCP ConfReq id=0x0
]
No auth is possible
sent [LCP ConfRej id=0x0
]
rcvd [LCP ConfAck id=0x1
]
rcvd [LCP ConfReq id=0x1
]
sent [LCP ConfAck id=0x1
]
sent [CCP ConfReq id=0x1
]
sent [IPCP ConfReq id=0x1
]
rcvd [LCP DiscReq id=0x2
magic=0x451b7dc9]
rcvd [LCP ProtRej id=0x3 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
rcvd [IPCP ConfReq
id=0x0]
sent [IPCP ConfNak id=0x0
]
rcvd [IPCP ConfRej id=0x1
]
sent [IPCP ConfReq id=0x2
]
rcvd [IPCP ConfReq
id=0x1]
sent [IPCP ConfAck
id=0x1]
rcvd [IPCP ConfNak id=0x2
]
sent [IPCP ConfReq id=0x3
]
rcvd [IPCP ConfAck id=0x3
]
Could not determine remote IP
address: defaulting to 10.64.64.64
local IP
address 10.19.25.49
remote IP address
10.64.64.64
primary DNS
address 211.136.112.50
secondary DNS address
211.136.150.66
Script /etc/ppp/ip-up started
(pid 1639)
Script /etc/ppp/ip-up finished
(pid 1639), status = 0xff