科创园

科创园地,分享技术知识,为科技助力发展,贡献一己之力。
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

CWMP开源代码研究9——git代码工程

Posted on 2017-03-20 18:09  科创园  阅读(941)  评论(0编辑  收藏  举报

声明:原创作品,涉及的开源程序代码学习和研究,严禁用于商业目的。 如有任何问题,欢迎和我交流:408797506@qq.com(微信:408797506)

 

 相关视频学习链接:

 

B站视频链接TR069协议与商业应用

 

腾讯课堂视频链接TR069协议与商业应用

 

github工程代码已不再更新维护,有需要最新资料和源码的,可以留言。下面操作仅供参考!

一. 环境
1.GNU/Linux Centos6.5操作系统(x86)
2.gcc

二. 下载代码

不再提供下载地址


三. 依赖包的安装
1. expat-2.1.0
1)进入目录
  cd dependence_pkt/expat-2.1.0/

2)创建安装的路径名tmp

  mkdir tmp
3) 配置安装路径到tmp
  ./configure  --prefix=$PWD/tmp(如果是本地linux系统,只需要./configure)
4) 安装
  make;make install
5)拷贝tmp目录下相应的文件到需要的位置

(比如我的环境:cp tmp/include/expat* /usr/local/include/ -rf; cp tmp/lib/libexpat.so.1.6.0 /usr/local/lib/ -rf;ln -sf /usr/local/lib/libexpat.so.1.6.0 /usr/local/lib/libexpat.so

2. curl-7.21.4

这里介绍源码包安装的方式,也可以使用apt-get install 或者yum install命令在线安装。

因为curl的安装包依赖于openssl以及在CWMP中要用到SSL证书的HTTPS安全方式,所以提前先安装上openssl
1)下载安装包openssl-1.0.2.tar.gz,路径http://distfiles.macports.org/openssl/
2)解压
  tar -xvf openssl-1.0.2.tar.gz
3) 进入目录
  cd openssl-1.0.2;mkdir tmp;mkdir tmp/openssl
4) 配置安装路径和配置文件路径
  ./config shared --prefix=$PWD/tmp --openssldir=$PWD/tmp/openssl(如果是本地linux系统,只需要./config shared)
5)安装
  make;make install
6) 拷贝tmp目录下相应的文件到需要的位置(参考前面)

安装curl

1)进入目录
  cd dependence_pkt/curl-7.21.4/

2)创建安装的路径名tmp 

  mkdir tmp
3) 配置安装路径到tmp
  ./configure --without-ssl  --prefix=$PWD/tmp(如果是本地linux系统,只需要./configure)
4) 安装
  make;make install
5)拷贝tmp目录下相应的文件到需要的位置

(比如我的环境:cp tmp/include/curl /usr/local/include/ -rf; cp tmp/lib/libcurl.so.4.2.0 /usr/local/lib/;ln -sf /usr/local/lib/libcurl.so.4.2.0 /usr/local/lib/libcurl.so

四. 编译并安装

阅读Makefile,从中可以看出分步安装的步骤所执行的make命令:1. make uci 2. make uci_install 3. make device 4. make device_install 5. make cwmp_install(只提供x86的执行程序)

 1 ~/git_DataModel# cat Makefile
 2 include Makefile.inc
 3 
 4 #CFLAGS += -D_GNU_SOURCE
 5 CFLAGS += -I $(shell pwd)/include
 6 
 7 LDFLAGS += -luci -lcurl 
 8 
 9 export CFLAGS LDFLAGS
10 
11 TARGET := device.so
12 
13 obj-y += src/
14 
15 uci :
16         #############1. make uci.so #####################
17         make -C  $(shell pwd)/uci-0.1/
18 
19 uci_install :
20         #############2. install uci library and include and bin files #####################
21         cp $(shell pwd)/uci-0.1/libuci.so.0.1 /usr/lib/libuci.so.0.1
22         ln -sf /usr/lib/libuci.so.0.1 /usr/lib/libuci.so
23         cp $(shell pwd)/uci-0.1/uci.h $(shell pwd)/uci-0.1/uci_config.h $(shell pwd)/uci-0.1/uci_internal.h /usr/include/
24         cp $(shell pwd)/uci-0.1/uci /usr/bin/
25 device : 
26         #############3. make device.so #####################
27         make -C $(shell pwd)/ -f $(TOPDIR)/Makefile.build
28         $(CC) -o $(TARGET) -shared -fPIC built-in.o $(LDFLAGS)
29 
30 device_install:
31         #######4. install device library and config  for tr069 running test ##################
32         cp etc_config/* /etc/config/ -rf
33         cp device.so /usr/lib/
34 cwmp_install:
35         #######5. install cwmp core ##################
36         cp cwmp_x86/cwmp /usr/bin/ -rf
37         cp tr069.sh /sbin/tr069 -rf
38 
39 .PHONY: clean
40 clean:
41         rm -f $(shell find -name "*.o")
42         rm -f $(shell find -name "*.d")
43         rm -f $(TARGET)
44         make clean -C $(shell pwd)/uci-0.1/
45 
46 .PHONY: distclean
47 distclean:
48         ##########1. clear device and uci make #################
49         rm -f $(shell find -name "*.o")
50         rm -f $(shell find -name "*.d")
51         rm -f $(TARGET)
52         make clean -C $(shell pwd)/uci-0.1/
53         ##########2. remove uci install #################
54         rm -rf /usr/lib/libuci.so.0.1 /usr/lib/libuci.so
55         rm -rf /usr/include/uci_internal.h /usr/include/uci_config.h  /usr/include/uci.h
56         rm -rf /usr/bin/uci
57         ##########3. remove device install #################
58         rm -rf /etc/config/*
59         rm -rf /usr/lib/device.so
60         ##########4. remove cwmp core install #################
61         rm -rf /usr/bin/cwmp

 此外,在git_DataModel目录下可以看到我已经写好了安装的脚本

 1 ~/git_DataModel# cat build_debug.sh 
 2 #!/bin/sh
 3 make uci
 4 make uci_install
 5 make device
 6 make device_install
 7 make cwmp_install
 8 #cp tr069.sh /sbin/tr069 -rf
 9 
10 #make clean
11 #make distclean

五. 卸载

执行make distclean清除所有编译和安装程序

六. 测试

程序启动命令:cwmp -F /etc/config/cwmpd.conf & 

或者使用脚本 tr069 start命令开启测试程序

查看log的方法:tail -f /tmp/cwmp.log

1 2017-03-20 17:30:44.121 [DBUG] [Device] [device.c:get_param_by_name()] [0755] name=InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection.1.ExternalIPAddress
2 2017-03-20 17:30:44.122 [ERRO] [EB-MIG] [WANIPConnection.c:CpeGetWANIPConnection_ExternalIPAddress()] [0494] TODO.............support yourself WAN interface ip addr
3 2017-03-20 17:30:44.122 [DBUG] [Event] [event.c:event_loop()] [1221] WAN IP=192.168.20.12
4 2017-03-20 17:30:47.142 [DBUG] [Event] [event.c:event_loop()] [1287] resp=200
5 2017-03-20 17:30:47.143 [INFO] [Event] [event.c:event_loop()] [1318] recv=<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:cwmp="urn:dslforum-org:cwmp-1-0"><SOAP-ENV:Header><cwmp:ID SOAP-ENV:mustUnderstand="1">-36640</cwmp:ID></SOAP-ENV:Header><SOAP-ENV:Body SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><cwmp:GetParameterValues><ParameterNames SOAP-ENC:arrayType="xsd:string[1]"><string xsi:type="xsd:string">InternetGatewayDevice.ObjTest.5.TestEnabled</string></ParameterNames></cwmp:GetParameterValues></SOAP-ENV:Body></SOAP-ENV:Envelope>

 从log看到错误的一行:[ERRO] [EB-MIG] [WANIPConnection.c:CpeGetWANIPConnection_ExternalIPAddress()] [0494] TODO.............support yourself WAN interface ip addr

意味着你需要根据自己的实际网卡地址修改WAN侧(设备或者CPE)的ip地址。

七. 根据实际网卡地址修改CPE地址

修改配置文件option cpe_ipaddr '192.168.20.12'

 1 git_DataModel/etc_config# vi /etc/config/cpeagent 
 2 
 3 config cpeagent tr069
 4         option acsurl 'http://192.168.4.11:9090/ACS-server/ACS'
 5         option cpeport '25100'
 6         option cpe_ipaddr '192.168.20.12'
 7         option auth '0'
 8         option cpeauth_user 'test'
 9         option cpeauth_pass 'test'
10         option acsauth_user 'test'
11         option acsauth_pass 'test'
12         option enable '1'
13         option acs_status '0'
14         option inform_status '0'
15         option bs_status '0'
16         option cwmp_status '0'
17 
18 config cpeagent managementserver
19         option PeriodicInformEnable '1'
20         option PeriodicInformInterval '43200'
21         option PeriodicInformTime '1323903137'
22 
23 config cpeagent inform
24         option bootstarp '1'

. 交叉编译

  git工程只提供了X86平台的代码或者程序。参考上述步骤,应该很容易移植成功。
 
如需交叉编译或者其他平台的移植,请提供交叉编译工具链,我会把编译后的cwmp 协议栈的程序发给你。