Android学习——移植tr069程序到Android平台
Posted 京月飞鸿
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Android学习——移植tr069程序到Android平台相关的知识,希望对你有一定的参考价值。
原创作品,转载请注明出处,严禁非法转载。如有错误,请留言!
email:40879506@qq.com
声明:本系列涉及的开源程序代码学习和研究,严禁用于商业目的。 如有任何问题,欢迎和我交流。(企鹅号:408797506)
淘宝店:https://shop484606081.taobao.com
本篇用到的代码下载路径:http://download.csdn.net/detail/eryunyong/9798889
Github维护:https://github.com/eryunyong/git_android_DataModel
代码结构说明:
core目录是tr069程序的协议栈部分代码编译出来的可执行档案(不开源)。
etc_config目录是cwmp程序执行用到的配置和测试数据。
include和src目录是DataModel数据部分的源码。
dep_packet.rar是依赖包的压缩文件(包括libcurl,libexpat,libuci)。
Makefile和Makefile.build是用于编译DataModel产生设备相关的device.so文件
一. 环境
1.编译环境GNU/Linux Centos6.5操作系统
2.NDK交叉编译工具链arm-linux-androideabi-gcc-4.8 (参考前一篇:Android学习——NDK交叉编译)
二. 依赖包的安装
在我提供的csdn的下载路径里,可以看到我已经把相关的依赖程序编译并安装到了tmp目录下。可以直接把需要的动态库so放到安卓环境里。
如果一直看我的CWMP开源代码研究的系列文章,那么这些依赖安装也就很简单了。开源的程序用到的是libcurl, libexpat。libuci的测试程序是我重写了(前文已介绍),移植到安卓平台又出现了新的问题。
三. libuci测试程序
在移植libuci的程序过程出现如下类似错误:
caused by cannot locate symbol "glob" referenced by libuci.so
原因是在Android平台下并没有glob库。所以我在网上找到了glob.c和glob.h文件放在了libuci的源码程序里进行编译。
四. 程序的几处修改
1.cwmp程序运行的配置
由于安卓系统的目录结构和linux不一样,安卓提供给用户空间的操作数据一般放在/system/目录下
[file] log=/system/etc/config/log1.conf device=/system/etc/config/device.xml attr=/system/usr/data/attr.conf event=/system/usr/data/event1.conf [cwmp] retry_count=3 notify_interval=30 [stun] port=50001 retry_count=3 timeout=2 timewait=30
2.device.so路径变化
在device.xml中定义了设备库存放路径为
1 ........
2 </obj>
3 </obj>
4 </trf>
5
6 <devlib name="/system/lib/device.so"></devlib>
7 <cwmpenable name="dev_cwmp_enable"/>
8 <init name="dev_init"></init>
9 <bootstrap name="dev_bootstrap"></bootstrap>
10 ......
3.Log的文件存储路径
1 [conf] 2 path=/system/usr/data 3 name=cwmp.log 4 enable=1 5 level=7 6 size=500000
程序启动的时候,可以追踪/system/usr/data/cwmp.log文件查看log信息输出。
4.测试数据存储路径变化
在uci.h文件里改变了数据存储的路径,以便于我们进行测试
#define UCI_CONFDIR "/system/usr/config" #define UCI_BASEDIR "/system/etc/config" #define UCI_SAVEDIR "/system/tmp/.uci"
同理,在device.so的程序里也要修改对应的路径:
cpeutil.h头文件内容:
#define UCI_ROOT_DEFAULT "/system/etc/config"
#define UCI_USER_ROOT "/system/usr/config
5.cwmp程序
1. 新增了debug调试的模块(可选)
五. 在Android4.4的AVD环境里测试
1.准备好动态库
把编译好的动态库libcurl.so, libexpat.so, libuci.so,device.so拷贝到安卓系统的/system/lib目录下。所有代码开源!!!
2.准备好CWMP程序
把已经编译好的cwmp协议栈的核心程序放置到安卓系统的/system/bin目录下,并赋予可执行权限。cwmp程序代码不开源,仅提供可执行档案!
3.准备好配置文件和测试数据部分
把源码包里面的etc_config目录下的文件全部拷贝到安卓系统的/system/etc/config/目录下(如果不存在就创建相应的目录)。并创建相应的配置或者数据存储的目录,比如/system/usr/data,/system/usr/config/
4.运行程序
执行命令:cwmp -F /system/etc/config/cwmp.conf
可以看到程序在Android4.4的模拟机上运行结果如下:
5.查看log
1 2017-03-30 03:17:30.682 [INFO] [CWMP] [cwmp.c:cwmp_proc()] [0241] cwmp version 1.0.0 2 2017-03-30 03:17:30.691 [DBUG] [Device] [device.c:init_cpe()] [1071] filename=/system/etc/config/device.xml 3 2017-03-30 03:17:30.715 [DBUG] [Device] [device.c:parse_buf()] [0344] parse_buf end 4 2017-03-30 03:17:30.716 [DBUG] [Device] [device.c:init_dev_func()] [0370] device library=/system/lib/device.so 5 2017-03-30 03:17:30.739 [DBUG] [Device] [device.c:init_dev_func()] [0387] wanparamname_func=dev_get_wanparam_name 6 2017-03-30 03:17:30.740 [DBUG] [Device] [device.c:init_dev_func()] [0399] bootstrap_func=dev_bootstrap 7 2017-03-30 03:17:30.748 [DBUG] [Device] [device.c:init_dev_func()] [0448] init_func=dev_init 8 2017-03-30 03:17:30.821 [DBUG] [Device] [device.c:init_dev_func()] [0469] reboot_func=dev_reboot 9 2017-03-30 03:17:30.821 [DBUG] [Device] [device.c:init_dev_func()] [0486] factoryreset_func=dev_factoryreset 10 2017-03-30 03:17:30.821 [DBUG] [Device] [device.c:init_dev_func()] [0503] download_func=dev_download 11 2017-03-30 03:17:30.822 [DBUG] [Device] [device.c:init_dev_func()] [0520] upload_func=dev_upload 12 2017-03-30 03:17:30.822 [DBUG] [Device] [device.c:init_dev_func()] [0556] debug_func=dev_debug 13 2017-03-30 03:17:30.822 [DBUG] [Device] [device.c:init_dev_func()] [0573] cwmpeanble_func=dev_cwmp_enable 14 2017-03-30 03:17:30.822 [DBUG] [Device] [device.c:init_dev_func()] [0590] dyninform func=dev_dyninform 15 2017-03-30 03:17:30.822 [DBUG] [Device] [device.c:init_dev_func()] [0607] auth_func=dev_get_auth 16 2017-03-30 03:17:30.823 [DBUG] [Device] [device.c:init_dev_func()] [0624] listenport_func=dev_get_listenport 17 2017-03-30 03:17:30.825 [INFO] [EB-MIG] [low_level_func.c:dev_get_listenport()] [0668] get devlistenport 18 2017-03-30 03:17:30.826 [DBUG] [Device] [device.c:init_dev_func()] [0647] port=25100 19 2017-03-30 03:17:30.827 [DBUG] [Device] [device.c:init_dev_func()] [0654] func_set_acs_status=dev_set_acs_status 20 2017-03-30 03:17:30.827 [DBUG] [Device] [device.c:init_dev_func()] [0671] func_set_cwmp_status=dev_set_cwmp_status 21 2017-03-30 03:17:30.827 [DBUG] [Device] [device.c:init_dev_func()] [0688] func_url_dns_resolve=dev_url_dns_resolve 22 2017-03-30 03:17:30.827 [DBUG] [Device] [device.c:init_dev_func()] [0719] init_dev_func end 23 2017-03-30 03:17:30.828 [DBUG] [Device] [device.c:get_full_param_name()] [1175] fullname=InternetGatewayDevice.ObjTest 24 2017-03-30 03:17:30.828 [DBUG] [Device] [device.c:init_multi_obj()] [0743] init_multi_obj refresh params=InternetGatewayDevice.ObjTest 25 2017-03-30 03:17:30.835 [DBUG] [Device] [device.c:get_full_param_name()] [1175] fullname=InternetGatewayDevice.WANDevice 26 2017-03-30 03:17:30.835 [DBUG] [Device] [device.c:init_multi_obj()] [0743] init_multi_obj refresh params=InternetGatewayDevice.WANDevice 27 2017-03-30 03:17:30.836 [DBUG] [EB-MIG] [WANDevice.c:CpeRefreshWANDevice()] [0042] TRF_Refresh_WANDevice begin 28 2017-03-30 03:17:30.853 [DBUG] [EB-MIG] [WANDevice.c:CpeRefreshWANDevice()] [0060] TRF_Refresh_WANDevice end 29 2017-03-30 03:17:30.853 [DBUG] [Device] [device.c:get_full_param_name()] [1175] fullname=InternetGatewayDevice.WANDevice.0.WANConnectionDevice 30 2017-03-30 03:17:30.853 [DBUG] [Device] [device.c:init_multi_obj()] [0743] init_multi_obj refresh params=InternetGatewayDevice.WANDevice.0.WANConnectionDevice 31 2017-03-30 03:17:30.854 [DBUG] [Device] [device.c:get_full_param_name()] [1175] fullname=InternetGatewayDevice.WANDevice.0.WANConnectionDevice.0.WANIPConnection 32 2017-03-30 03:17:30.854 [DBUG] [Device] [device.c:init_multi_obj()] [0743] init_multi_obj refresh params=InternetGatewayDevice.WANDevice.0.WANConnectionDevice.0.WANIPConnection 33 2017-03-30 03:17:30.855 [DBUG] [Device] [device.c:get_full_param_name()] [1175] fullname=InternetGatewayDevice.WANDevice.1.WANConnectionDevice 34 2017-03-30 03:17:30.855 [DBUG] [Device] [device.c:init_multi_obj()] [0743] init_multi_obj refresh params=InternetGatewayDevice.WANDevice.1.WANConnectionDevice 35 2017-03-30 03:17:30.859 [DBUG] [Device] [device.c:get_full_param_name()] [1175] fullname=InternetGatewayDevice.WANDevice.1.WANConnectionDevice.0.WANIPConnection 36 2017-03-30 03:17:30.859 [DBUG] [Device] [device.c:init_multi_obj()] [0743] init_multi_obj refresh params=InternetGatewayDevice.WANDevice.1.WANConnectionDevice.0.WANIPConnection 37 2017-03-30 03:17:30.862 [DBUG] [Device] [device.c:get_full_param_name()] [1175] fullname=InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection 38 2017-03-30 03:17:30.863 [DBUG] [Device] [device.c:init_multi_obj()] [0743] init_multi_obj refresh params=InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection 39 2017-03-30 03:17:30.865 [INFO] [Device] [device.c:init_attr()] [0891] could not get count from /system/usr/data/attr.conf 40 2017-03-30 03:17:30.872 [INFO] [CWMP] [cwmp.c:cwmp_proc()] [0266] cwmp is enabled 41 2017-03-30 03:17:30.873 [INFO] [CWMP] [cwmp.c:cwmp_proc()] [0269] ============start listen acs================ 42 2017-03-30 03:17:30.873 [INFO] [HTTPSERVER] [acs_req_conn.c:init_acs_req_conn()] [0373] init_acs_req_conn begin 43 2017-03-30 03:17:30.874 [INFO] [HTTPSERVER] [acs_req_conn.c:init_acs_req_conn()] [0415] init_acs_req_conn end 44 2017-03-30 03:17:30.874 [INFO] [NOTIFY] [notify_watch.c:init_notify_watch()] [0261] init_notify_watch begin 45 2017-03-30 03:17:30.874 [INFO] [NOTIFY] [notify_watch.c:init_notify_watch()] [0301] init_notify_watch end 46 2017-03-30 03:17:30.874 [INFO] [PERIODIC] [periodic_inform.c:init_periodic()] [0196] init_periodic begin 47 2017-03-30 03:17:30.875 [INFO] [PERIODIC] [periodic_inform.c:init_periodic()] [0236] init_periodic end 48 2017-03-30 03:17:30.875 [INFO] [TASK] [task.c:init_task()] [0447] init_stun begin 49 2017-03-30 03:17:30.875 [INFO] [TASK] [task.c:init_task()] [0486] init_task end 50 2017-03-30 03:17:30.876 [INFO] [Event] [event.c:init_event()] [0181] bootstrap_flag = 0 51 2017-03-30 03:17:30.876 [DBUG] [Event] [event.c:init_event()] [0192] reboot_flag=0, key= 52 2017-03-30 03:17:30.876 [DBUG] [Event] [event.c:event_set()] [0276] event_set begin, index=1, value=1 53 2017-03-30 03:17:30.877 [DBUG] [Event] [event.c:event_set()] [0287] event_set end 54 2017-03-30 03:17:30.877 [INFO] [Event] [event.c:init_event()] [0202] download_flag 0 55 2017-03-30 03:17:30.877 [DBUG] [Event] [event.c:event_loop()] [1072] wait for informing acs 56 2017-03-30 03:17:30.886 [DBUG] [Device] [device.c:get_param_by_name()] [0772] name=InternetGatewayDevice.ManagementServer.PeriodicInformEnable 57 2017-03-30 03:17:30.888 [DBUG] [Device] [device.c:get_param_by_name()] [0772] name=InternetGatewayDevice.ManagementServer.PeriodicInformInterval 58 2017-03-30 03:17:30.890 [DBUG] [Device] [device.c:get_param_by_name()] [0772] name=InternetGatewayDevice.ManagementServer.PeriodicInformTime 59 2017-03-30 03:17:30.892 [DBUG] [PERIODIC] [periodic_inform.c:periodic_loop()] [0142] PeriodicInformTime=2011-12-14T17:52:17 60 2017-03-30 03:17:30.893 [ERRO] [PERIODIC] [periodic_inform.c:periodic_loop()] [0148] InternetGatewayDevice.ManagementServer.PeriodicInformTime is invalid tm 61 2017-03-30 03:17:30.893 [DBUG] [PERIODIC] [periodic_inform.c:periodic_loop()] [0153] wait_tm=43200 62 2017-03-30 03:17:30.893 [DBUG] [NOTIFY] [notify_watch.c:notify_watch()] [0134] monitor parameter value change 63 2017-03-30 03:17:30.894 [INFO] [HTTPSERVER] [acs_req_conn.c:conn_req_ser()] [0316] acs listen port = 25100 64 2017-03-30 03:17:30.905 [INFO] [util] [util.c:socket_tcp_server()] [0110] socket_tcp_server end 65 2017-03-30 03:17:30.896 [DBUG] [Event] [event.c:event_loop()] [1082] begin to inform acs 66 2017-03-30 03:17:30.906 [DBUG] [Event] [event.c:event_loop()] [1109] status=IDLE 67 2017-03-30 03:17:30.906 [DBUG] [Event] [event.c:event_loop()] [1119] status=INIT 68 2017-03-30 03:17:30.907 [DBUG] [Device] [device.c:get_param_by_name()] [0772] name=InternetGatewayDevice.ManagementServer.Username 69 2017-03-30 03:17:30.909 [DBUG] [Device] [device.c:get_param_by_name()] [0772] name=InternetGatewayDevice.ManagementServer.Password 70 2017-03-30 03:17:30.911 [DBUG] [Event] [event.c:http_init_curl()] [0505] acs usrname=test, passwd=test 71 2017-03-30 03:17:30.912 [DBUG] [Device] [device.c:get_param_by_name()] [0772] name=InternetGatewayDevice.ManagementServer.URL 72 2017-03-30 03:17:30.917 [ERRO] [NOTIFY] [notify_watch.c:notify_watch()] [0240] Select error, interval=30! 73 2017-03-30 03:17:30.924 [DBUG] [Event] [event.c:event_loop()] [1141] acs url=http://192.168.4.11:9090/ACS-server/ACS 74 2017-03-30 03:17:30.925 [DBUG] [EB-MIG] [low_level_func.c:dev_url_dns_resolve()] [0603] ACS domain name=192.168.4.11 75 2017-03-30 03:17:30.925 [INFO] [EB-MIG] [low_level_func.c:dev_url_dns_resolve()] [0615] Already IP address. 76 2017-03-30 03:17:30.925 [DBUG] [Device] [device.c:get_param_by_name()] [0772] name=InternetGatewayDevice.DeviceInfo.Manufacturer 77 2017-03-30 03:17:30.926 [DBUG] [Device] [device.c:get_param_by_name()] [0772] name=InternetGatewayDevice.DeviceInfo.ManufacturerOUI 78 2017-03-30 03:17:30.927 [DBUG] [Device] [device.c:get_param_by_name()] [0772] name=InternetGatewayDevice.DeviceInfo.ProductClass 79 2017-03-30 03:17:30.929 [DBUG] [Device] [device.c:get_param_by_name()] [0772] name=InternetGatewayDevice.DeviceInfo.SerialNumber 80 2017-03-30 03:17:30.930 [DBUG] [Device] [device.c:get_param_by_name()] [0772] name=InternetGatewayDevice.Time.CurrentLocalTime 81 2017-03-30 03:17:30.930 [DBUG] [Device] [device.c:get_param_by_name()] [0772] name=InternetGatewayDevice.DeviceSummary 82 2017-03-30 03:17:30.930 [DBUG] [Device] [device.c:get_param_by_name()] [0772] name=InternetGatewayDevice.DeviceSummary 83 2017-03-30 03:17:30.931 [DBUG] [Device] [device.c:get_param_by_name()] [0772] name=InternetGatewayDevice.DeviceInfo.SpecVersion 84 2017-03-30 03:17:30.931 [DBUG] [Device] [device.c:get_param_by_name()] [0772] name=InternetGatewayDevice.DeviceInfo.SpecVersion 85 2017-03-30 03:17:30.931 [DBUG] [Device] [device.c:get_param_by_name()] [0772] name=InternetGatewayDevice.DeviceInfo.HardwareVersion 86 2017-03-30 03:17:30.932 [DBUG] [Device] [device.c:get_param_by_name()] [0772] name=InternetGatewayDevice.DeviceInfo.HardwareVersion 87 2017-03-30 03:17:30.932 [DBUG] [Device] [device.c:get_param_by_name()] [0772] name=InternetGatewayDevice.DeviceInfo.SoftwareVersion 88 2017-03-30 03:17:30.935 [DBUG] [Device] [device.c:get_param_by_name()] [0772] name=InternetGatewayDevice.DeviceInfo.SoftwareVersion 89 2017-03-30 03:17:30.936 [DBUG] [Device] [device.c:get_param_by_name()] [0772] name=InternetGatewayDevice.DeviceInfo.ProvisioningCode 90 2017-03-30 03:17:30.937 [DBUG] [Device] [device.c:get_param_by_name()] [0772] name=InternetGatewayDevice.DeviceInfo.ProvisioningCode 91 2017-03-30 03:17:30.937 [DBUG] [Device] [device.c:get_param_by_name()] [0772] name=InternetGatewayDevice.ManagementServer.ConnectionRequestURL 92 2017-03-30 03:17:30.941 [ERRO] [EB-MIG] [ManagementServer.c:CpeGetManagementServerConnectionRequestURL()] [0035] ============Andy debug: CpeGetManagementServerConnectionRequestURL debugip= 192.168.20.38. 93 2017-03-30 03:17:30.943 [ERRO] [EB-MIG] [ManagementServer.c:CpeGetManagementServerConnectionRequestURL()] [0059] ============Andy debug: CpeGetManagementServerConnectionRequestURL *value = http://192.168.20.38:25100. 94 2017-03-30 03:17:30.944 [DBUG] [Device] [device.c:get_param_by_name()] [0772] name=InternetGatewayDevice.ManagementServer.ConnectionRequestURL 95 2017-03-以上是关于Android学习——移植tr069程序到Android平台的主要内容,如果未能解决你的问题,请参考以下文章