ppp-2.4.4移植以及EM770W拨号全过程

Published: 31 Dec 2013 Category: linux

好久没写博客了,时间一下子到了2013年的最后一天,那就写一篇吧!刚好工作中遇到一个问题,我觉得值得写个blog记录一下!

由于工作中需要在ARM平台上(海思3520D)用到3G拨号上网,所以今儿准备尽量把3G拨号搞定!

准备工作:

软件:ppp-2.4.4.tar.gz、SUSE 10.1、交叉编译工具链等

硬件:华为3G模块(EM770W)

EM770W.png

下面就介绍整个编译过程:

1.解压ppp-2.4.4.tar.gz:tar -zxvf ppp-2.4.4.tar.gz
2.配置:cd ppp-2.4.4 && ./configure

linux-geek:/home/Hi3520D_SDK_V1.0.2.0/osdrv/tools/board_tools/ppp-2.4.4 # ./configure 
Configuring for Linux
Creating Makefiles.
Makefile <= linux/Makefile.top
pppd/Makefile <= pppd/Makefile.linux
pppstats/Makefile <= pppstats/Makefile.linux
chat/Makefile <= chat/Makefile.linux
pppdump/Makefile <= pppdump/Makefile.linux
pppd/plugins/Makefile <= pppd/plugins/Makefile.linux
pppd/plugins/rp-pppoe/Makefile <= pppd/plugins/rp-pppoe/Makefile.linux
pppd/plugins/radius/Makefile <= pppd/plugins/radius/Makefile.linux
pppd/plugins/pppoatm/Makefile <= pppd/plugins/pppoatm/Makefile.linux
linux-geek:/home/Hi3520D_SDK_V1.0.2.0/osdrv/tools/board_tools/ppp-2.4.4 #    

3.编译:make CC=arm-hisiv200-linux-gcc,不出意外,会遇到这个错误:

options.c:59: fatal error: pcap.h: No such file or directory
compilation terminated.
make[1]: *** [options.o] Error 1
make[1]: Leaving directory `/home/Hi3520D_SDK_V1.0.2.0/osdrv/tools/board_tools/ppp-2.4.4/pppd'
make: *** [all] Error 2
linux-geek:/home/Hi3520D_SDK_V1.0.2.0/osdrv/tools/board_tools/ppp-2.4.4 # 

4.排查错误:我们来看看option.c 59行是个什么东西,

vim pppd/options.c +59
58 #ifdef PPP_FILTER
59 #include <pcap.h>
60 /*
61  * There have been 3 or 4 different names for this in libpcap CVS, but
62  * this seems to be what they have settled on...
63  * For older versions of libpcap, use DLT_PPP - but that means
64  * we lose the inbound and outbound qualifiers.
65  */
66 #ifndef DLT_PPP_PPPD
67 #ifdef DLT_PPP_WITHDIRECTION
68 #define DLT_PPP_PPPD    DLT_PPP_WITHDIRECTION
69 #else
70 #define DLT_PPP_PPPD    DLT_PPP
71 #endif
72 #endif
73 #endif /* PPP_FILTER */

原来是PPP过滤功能。我们先找一下哪儿定义了“PPP_FILTER”

linux-geek:/home/Hi3520D_SDK_V1.0.2.0/osdrv/tools/board_tools/ppp-2.4.4 # grep PPP_FILTER -Rn *
include/net/if_ppp.h:132:#ifdef PPP_FILTER
include/net/if_ppp.h:135:#endif /* PPP_FILTER */
pppd/Makefile:174:CFLAGS  += -DPPP_FILTER
pppd/auth.c:863:#ifdef PPP_FILTER
pppd/demand.c:46:#ifdef PPP_FILTER
pppd/demand.c:102:#ifdef PPP_FILTER
pppd/demand.c:343:#ifdef PPP_FILTER
pppd/pppd.8:221:was configured to include PPP filtering support (CONFIG_PPP_FILTER).
pppd/pppd.8:865:kernel was configured to include PPP filtering support (CONFIG_PPP_FILTER).
pppd/pppd.h:338:#ifdef PPP_FILTER
pppd/pppd.h:661:#ifdef PPP_FILTER
pppd/options.c:58:#ifdef PPP_FILTER
pppd/options.c:73:#endif /* PPP_FILTER */
pppd/options.c:133:#ifdef PPP_FILTER
pppd/options.c:161:#ifdef PPP_FILTER
pppd/options.c:303:#ifdef PPP_FILTER
pppd/options.c:1450:#ifdef PPP_FILTER
pppd/sys-linux.c:138:#ifdef PPP_FILTER
pppd/sys-linux.c:141:#endif /* PPP_FILTER */
pppd/sys-linux.c:1292:#ifdef PPP_FILTER
pppd/sys-linux.c:1317:#endif /* PPP_FILTER */
pppd/Makefile.linux:174:CFLAGS  += -DPPP_FILTER
linux-geek:/home/Hi3520D_SDK_V1.0.2.0/osdrv/tools/board_tools/ppp-2.4.4 #  

从上面我们可以看到

pppd/Makefile:174:CFLAGS  += -DPPP_FILTER  

原来是Makefile里面定义了,对于我的应用可以不使用PPP_FILTER功能,于是一不做二不休,直接把它注释掉:

171 ifdef FILTER
172 ifneq ($(wildcard /usr/include/pcap-bpf.h),)
173 #LIBS    += -lpcap
174 #CFLAGS  += -DPPP_FILTER
175 endif
176 endif

之后再编译应该就可以了!注意:编译前,先make clean一下,清理一下上次编译的垃圾文件。

5.实现开发板拨号成功:

拷贝pppd/pppd chat/chat到开发板上的/usr/sbin目录下,运行相应的拨号脚本,应该就可以成功了。

[/root]$ pppd connect 'chat -v "" "AT" "" "AT+CGDCONT=1,\"IP\",\"3GNET\"" "" "AT
DT*99# CONNECT"' /dev/ttyUSB0 115200 nodetach nocrtscts debug usepeerdns default
route &
[/root]$ Serial connection established.
using channel 1
Using interface ppp0
Connect: ppp0 <--> /dev/ttyUSB0
sent [LCP ConfReq id=0x1 <asyncmap 0x0> <magic 0x4cb33965> <pcomp> <accomp>]
rcvd [LCP ConfReq id=0x0 <asyncmap 0x0> <auth chap MD5> <magic 0x1461203> <pcomp> <accomp>]
No auth is possible
sent [LCP ConfRej id=0x0 <auth chap MD5>]
rcvd [LCP ConfAck id=0x1 <asyncmap 0x0> <magic 0x4cb33965> <pcomp> <accomp>]
rcvd [LCP ConfReq id=0x1 <asyncmap 0x0> <magic 0x1461203> <pcomp> <accomp>]
sent [LCP ConfAck id=0x1 <asyncmap 0x0> <magic 0x1461203> <pcomp> <accomp>]
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-dns3 0.0.0.0>]
rcvd [LCP DiscReq id=0x2 magic=0x1461203]
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 ConfNak id=0x1 <ms-dns1 10.11.12.13> <ms-dns3 10.11.12.14> <ms-wins 10.11.12.13> <ms-wins 10.11.12.14>]
sent [IPCP ConfReq id=0x2 <compress VJ 0f 01> <addr 0.0.0.0> <ms-dns1 10.11.12.13> <ms-dns3 10.11.12.14>]
rcvd [IPCP ConfNak id=0x2 <ms-dns1 10.11.12.13> <ms-dns3 10.11.12.14> <ms-wins 10.11.12.13> <ms-wins 10.11.12.14>]
sent [IPCP ConfReq id=0x3 <compress VJ 0f 01> <addr 0.0.0.0> <ms-dns1 10.11.12.13> <ms-dns3 10.11.12.14>]
rcvd [IPCP ConfReq id=0x0]
sent [IPCP ConfNak id=0x0 <addr 0.0.0.0>]
rcvd [IPCP ConfRej id=0x3 <compress VJ 0f 01>]
sent [IPCP ConfReq id=0x4 <addr 0.0.0.0> <ms-dns1 10.11.12.13> <ms-dns3 10.11.12.14>]
rcvd [IPCP ConfReq id=0x1]
sent [IPCP ConfAck id=0x1]
rcvd [IPCP ConfNak id=0x4 <addr 10.21.249.203> <ms-dns1 221.6.4.66> <ms-dns3 58.240.57.33>]
sent [IPCP ConfReq id=0x5 <addr 10.21.249.203> <ms-dns1 221.6.4.66> <ms-dns3 58.240.57.33>]
rcvd [IPCP ConfAck id=0x5 <addr 10.21.249.203> <ms-dns1 221.6.4.66> <ms-dns3 58.240.57.33>]
Could not determine remote IP address: defaulting to 10.64.64.64
Failed to create /etc/ppp/resolv.conf: No such file or directory
local  IP address 10.21.249.203
remote IP address 10.64.64.64
primary   DNS address 221.6.4.66
secondary DNS address 58.240.57.33

当然,要想实现PPP拨号功能,linux内核里面相应的配置需要选上,包括PPP和3G模块驱动两个地方。

PPP:

EM770W.png

3G模块驱动:

ppp-driver0.png

ppp-driver1.png

如果,出现识别不了3G模块的问题,八成是模块的PID和VID没有包含在drivers/usb/serial/option.c的结构体里面,具体的请自己google!