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

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

注意:因代码已更新不再维护,git源码不再提供下载功能,如需最新源码请与我联系。

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

二. 下载代码

git  clone https://github.com/eryunyong/DataModel.git
三. 依赖包的安装
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的执行程序)

~/git_DataModel# cat Makefile
include Makefile.inc

#CFLAGS += -D_GNU_SOURCE
CFLAGS += -I $(shell pwd)/include

LDFLAGS += -luci -lcurl

export CFLAGS LDFLAGS

TARGET := device.so

obj-y += src/

uci :
        #############1. make uci.so #####################
        make -C  $(shell pwd)/uci-0.1/

uci_install :
        #############2. install uci library and include and bin files #####################
        cp $(shell pwd)/uci-0.1/libuci.so.0.1 /usr/lib/libuci.so.0.1
        ln -sf /usr/lib/libuci.so.0.1 /usr/lib/libuci.so
        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/
        cp $(shell pwd)/uci-0.1/uci /usr/bin/
device :
        #############3. make device.so #####################
        make -C $(shell pwd)/ -f $(TOPDIR)/Makefile.build
        $(CC) -o $(TARGET) -shared -fPIC built-in.o $(LDFLAGS)

device_install:
        #######4. install device library and config  for tr069 running test ##################
        cp etc_config/* /etc/config/ -rf
        cp device.so /usr/lib/
cwmp_install:
        #######5. install cwmp core ##################
        cp cwmp_x86/cwmp /usr/bin/ -rf
        cp tr069.sh /sbin/tr069 -rf

.PHONY: clean
clean:
        rm -f $(shell find -name "*.o")
        rm -f $(shell find -name "*.d")
        rm -f $(TARGET)
        make clean -C $(shell pwd)/uci-0.1/

.PHONY: distclean
distclean:
        ##########1. clear device and uci make #################
        rm -f $(shell find -name "*.o")
        rm -f $(shell find -name "*.d")
        rm -f $(TARGET)
        make clean -C $(shell pwd)/uci-0.1/
        ##########2. remove uci install #################
        rm -rf /usr/lib/libuci.so.0.1 /usr/lib/libuci.so
        rm -rf /usr/include/uci_internal.h /usr/include/uci_config.h  /usr/include/uci.h
        rm -rf /usr/bin/uci
        ##########3. remove device install #################
        rm -rf /etc/config/*
        rm -rf /usr/lib/device.so
        ##########4. remove cwmp core install #################
        rm -rf /usr/bin/cwmp

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

~/git_DataModel# cat build_debug.sh
#!/bin/sh
make uci
make uci_install
make device
make device_install
make cwmp_install
#cp tr069.sh /sbin/tr069 -rf

#make clean
#make distclean

五. 卸载

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

六. 测试

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

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

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

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
2017-03-20 17:30:44.122 [ERRO] [EB-MIG] [WANIPConnection.c:CpeGetWANIPConnection_ExternalIPAddress()] [0494] TODO.............support yourself WAN interface ip addr
2017-03-20 17:30:44.122 [DBUG] [Event] [event.c:event_loop()] [1221] WAN IP=192.168.20.12
2017-03-20 17:30:47.142 [DBUG] [Event] [event.c:event_loop()] [1287] resp=200
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>

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

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

修改配置文件option cpe_ipaddr '192.168.20.12'

git_DataModel/etc_config# vi /etc/config/cpeagent

config cpeagent tr069
        option acsurl 'http://192.168.4.11:9090/ACS-server/ACS'
        option cpeport '25100'
        option cpe_ipaddr '192.168.20.12'
        option auth '0'
        option cpeauth_user 'test'
        option cpeauth_pass 'test'
        option acsauth_user 'test'
        option acsauth_pass 'test'
        option enable '1'
        option acs_status '0'
        option inform_status '0'
        option bs_status '0'
        option cwmp_status '0'

config cpeagent managementserver
        option PeriodicInformEnable '1'
        option PeriodicInformInterval '43200'
        option PeriodicInformTime '1323903137'

config cpeagent inform
        option bootstarp '1'

八. 交叉编译

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

kcyuan

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值