Realize 4G module PPP dial-up Internet access on ARM-LINUX platform
Serial dial
#1. Decompress the ppp package, cross-compile
#tar -xzvf ppp-2.4.5.tar.gz
#cd ./ppp-2.4.5
#./config
#make CC=arm-linux-gcc
kernel configuration
Device Drivers —>Network device support—> <*> PPP (point-to-point protocol) support
ppp install
Copy the cross-compiled pppd and chat applications to /usr/sbin/ under the development platform. Copy the ppp and chatscripts folders to the /etc/ directory under the development platform.
PPP configuration
Modify the configuration file /etc/ppp/peers/provider
#example configuration for a dialup connection authenticated with PAP or CHAP
#
# This is the default configuration used by pon(1) and poff(1).
# See the manual page pppd(8) for information on all the options.
# MUST CHANGE: replace myusername@realm with the PPP login name given to
# your by your provider.
# There should be a matching entry with the password in /etc/ppp/pap-secrets
# and/or /etc/ppp/chap-secrets.
#user "myusername@realm"
# Serial device to which the modem is connected.
# ttyname 串口端口,若非以”/“开头,则会自动补充”/dev/“
/dev/ttyS6
#/dev/ttyUSB2
#NO硬件流控
nocrtscts
# 前台运行
nodetach
# speed 串口波特率
# Speed of the serial line.
#115200
9600
#hide-password
remotename cmnet
ipparam cmnet
debug
user "cmnet"
0.0.0.0:0.0.0.0
local
lock
dump
# Assumes that your IP address is allocated dynamically by the ISP.
# 由ISP提供IP
noipdefault
# Try to get the name server addresses from the ISP.
usepeerdns
# Use this connection as the default route.
#defaultroute
# Makes pppd "dial again" when the connection is lost.
persist
# Do not ask the remote to authenticate.
noauth
Modify the dial script /etc/chatscripts/pap
#you can use this script unmodified to connect to sites which allow
# authentication via PAP, CHAP and similar protocols.
# This script can be shared among different pppd peer configurations.
# To use it, add something like this to your /etc/ppp/peers/ file:
#
# connect "/usr/sbin/chat -v -f /etc/chatscripts/pap -T PHONE-NUMBER"
# user YOUR-USERNAME-IN-PAP-SECRETS
# noauth
# Uncomment the following line to see the connect speed.
# It will be logged to stderr or to the file specified with the -r chat option.
#REPORT CONNECT
TIMEOUT 15
ABORT "BUSY"
ABORT "DELAYED"
ABORT "ERROR"
ABORT "NO DIALTONE"
ABORT "NO CARRIER"
TIMEOUT 40
'' AT
OK AT+CSQ
# s模块APN设置报错,默认接入CMNET,注释掉此命令
#OK AT+CGDCONT=1,"IP","CMNET"
OK ATDT*99#
CONNECT
Modify pap permissions
chmod +x /etc/chatscripts/pap
Serial communication test
Open two terminals
cat /dev/ttyS*
another terminal sends AT command
echo “AT” > /dev/ttyS*
You can cat to AT OK, the communication is successful. If the communication fails, please use the default baud rate of the module.
Serial dial
pppd call provider &
# pppd call provider &
pppd options in effect:
debug # (from /etc/ppp/peers/provider)
nodetach # (from /etc/ppp/peers/provider)
persist # (from /etc/ppp/peers/provider)
dump # (from /etc/ppp/peers/provider)
noauth # (from /etc/ppp/peers/provider)
user cmnet # (from /etc/ppp/peers/provider)
remotename cmnet # (from /etc/ppp/peers/provider)
/dev/ttyUSB2 # (from /etc/ppp/peers/provider)
9600 # (from /etc/ppp/peers/provider)
lock # (from /etc/ppp/peers/provider)
connect /usr/sbin/chat -s -v -f /etc/chatscripts/pap # (from /etc/ppp/peers/provider)
nocrtscts # (from /etc/ppp/peers/provider)
local # (from /etc/ppp/peers/provider)
asyncmap 0 # (from /etc/ppp/options)
lcp-echo-failure 4 # (from /etc/ppp/options)
lcp-echo-interval 30 # (from /etc/ppp/options)
hide-password # (from /etc/ppp/options)
ipparam cmnet # (from /etc/ppp/peers/provider)
noipdefault # (from /etc/ppp/peers/provider)
usepeerdns # (from /etc/ppp/peers/provider)
: # (from /etc/ppp/peers/provider)
noipx # (from /etc/ppp/options)
timeout set to 15 seconds
abort on (BUSY)
abort on (DELAYED)
abort on (ERROR)
abort on (NO DIALTONE)
abort on (NO CARRIER)
timeout set to 40 seconds
send (AT^M)
expect (OK)
AT^M^M
OK
-- got it
send (AT+CSQ^M)
expect (OK)
^M
AT+CSQ^M^M
+CSQ: 25,99^M
OK
-- got it
send (ATDT*99#^M)
expect (CONNECT)
^M
ATDT*99#^M^M
CONNECT
-- got it
Script /usr/sbin/chat -s -v -f /etc/chatscripts/pap finished (pid 1448), status = 0x0
Serial connection established.
using channel 1
Using interface ppp0
Connect: ppp0 <--> /dev/ttyUSB2
sent [LCP ConfReq id=0x1 <asyncmap 0x0> <magic 0xdb90a4ab> <pcomp> <accomp>]
rcvd [LCP ConfReq id=0x0 <asyncmap 0x0> <auth pap> <magic 0xc1e41549> <pcomp> <accomp>]
No auth is possible
sent [LCP ConfRej id=0x0 <auth pap>]
rcvd [LCP ConfAck id=0x1 <asyncmap 0x0> <magic 0xdb90a4ab> <pcomp> <accomp>]
rcvd [LCP ConfReq id=0x1 <asyncmap 0x0> <magic 0xc1e41549> <pcomp> <accomp>]
sent [LCP ConfAck id=0x1 <asyncmap 0x0> <magic 0xc1e41549> <pcomp> <accomp>]
sent [LCP EchoReq id=0x0 magic=0xdb90a4ab]
sent [CCP ConfReq id=0x1 <deflate 15> <deflate(old#) 15> <bsd v1 15>]
sent [IPCP ConfReq id=0x1 <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=0x2 magic=0xc1e41549]
rcvd [LCP EchoRep id=0x0 magic=0xc1e41549 db 90 a4 ab]
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 <addr 10.0.0.1>]
sent [IPCP ConfAck id=0x0 <addr 10.0.0.1>]
rcvd [IPCP ConfRej id=0x1 <compress VJ 0f 01>]
sent [IPCP ConfReq id=0x2 <addr 0.0.0.0> <ms-dns1 0.0.0.0> <ms-dns2 0.0.0.0>]
rcvd [IPCP ConfNak id=0x2 <addr 100.109.117.176> <ms-dns1 211.136.17.107> <ms-dns2 211.136.20.203>]
sent [IPCP ConfReq id=0x3 <addr 100.109.117.176> <ms-dns1 211.136.17.107> <ms-dns2 211.136.20.203>]
rcvd [IPCP ConfAck id=0x3 <addr 100.109.117.176> <ms-dns1 211.136.17.107> <ms-dns2 211.136.20.203>]
local IP address 100.109.117.176
remote IP address 10.0.0.1
primary DNS address 211.136.17.107
secondary DNS address 211.136.20.203
Script /etc/ppp/ip-up started (pid 1453)
Script /etc/ppp/ip-up finished (pid 1453), status = 0x0
#ifconfig
# ifconfig
docker0 Link encap:Ethernet HWaddr 02:42:28:F3:6C:11
inet addr:172.17.0.1 Bcast:172.17.255.255 Mask:255.255.0.0
UP BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
eth0 Link encap:Ethernet HWaddr FE:C4:84:AF:B7:CE
inet addr:192.168.0.2 Bcast:192.168.0.255 Mask:255.255.255.0
inet6 addr: fe80::fcc4:84ff:feaf:b7ce/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:628 errors:0 dropped:0 overruns:0 frame:0
TX packets:466 errors:4 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:57929 (56.5 KiB) TX bytes:78074 (76.2 KiB)
Interrupt:117
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
ppp0 Link encap:Point-to-Point Protocol
inet addr:100.109.117.176 P-t-P:10.0.0.1 Mask:255.255.255.255
UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1500 Metric:1
RX packets:4 errors:0 dropped:0 overruns:0 frame:0
TX packets:5 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:3
RX bytes:64 (64.0 B) TX bytes:97 (97.0 B)
You can see the ppp0 network card
Add routing
#route add default dev ppp0
networking test
#ping 8.8.8.8
PING 8.8.8.8 (8.8.8.8): 56 data bytes
64 bytes from 8.8.8.8: seq=0 ttl=50 time=44.137 ms
64 bytes from 8.8.8.8: seq=1 ttl=50 time=41.198 ms
64 bytes from 8.8.8.8: seq=2 ttl=50 time=47.619 ms
64 bytes from 8.8.8.8: seq=3 ttl=50 time=40.627 ms
64 bytes from 8.8.8.8: seq=4 ttl=50 time=46.058 ms
If the ping domain name fails, please add DNS
From /etc/ppp/resolv.conf, you can view the DNS "nameserver 211.136.17.107" of the current operator, and add DNS "nameserver 211.136.17.107 # ppp0" to /etc/resolv.conf . Redial, done.
USB dial
View 4G module
ls /dev/ttyUSB*
/dev/ttyUSB0 /dev/ttyUSB1 /dev/ttyUSB2 /dev/ttyUSB3
It can be seen that the module driver is loaded successfully, and 4 ttyUSB devices are enumerated. Check the module manual:
ttyUSB0 dedicated data service port
ttyUSB1 GPS
ttyUSB2 AT command port
ttyUSB3 diagnostic port
Modify the configuration file /etc/ppp/peers/provider
/dev/ttyS6
#/dev/ttyUSB2
change into
#/dev/ttyS6
/dev/ttyUSB2
Dial-up test
The dial-up and network configuration part is the same as the serial port dial-up.
If ls /dev/ttyUSB* cannot see the device, you can execute lsusb
# lsusb
Bus 002 Device 003: ID 2949:7401
Bus 002 Device 001: ID 1d6b:0002
Bus 004 Device 001: ID 1d6b:0001
Check the module manual, the VID and PID are 2949:7401, you can see that the module has been recognized.
Manually add U-to-serial driver:
sudo echo 2949 7401 > /sys/bus/usb-serial/drivers/option1/new_id
At this point, re-ls /dev/ttyUSB* to see the device. If the device restarts, you need to manually add the U-to-serial driver again.
dial
Subsequent steps are the same as serial dial-up.