diff --git a/.gitignore b/.gitignore index 9965252..bd4668c 100644 --- a/.gitignore +++ b/.gitignore @@ -39,3 +39,7 @@ missing *.gcda /icwmpd /Makefile +CMakeCache.txt +CMakeFiles/ +cmake_install.cmake +install_manifest.txt diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index eb14f1c..bb0a2a1 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -6,7 +6,7 @@ variables: DEBUG: 'TRUE' COMMON_IMAGE: "iopsys/code-analysis:0.27" RUN_CPPCHECK: "cppcheck --enable=all --error-exitcode=1 -D_GNU_SOURCE --suppress=unusedFunction -i ./test/ --inline-suppr" - SOURCE_FOLDER: "." + SOURCE_FOLDER: "./src" CWMP_WORKER_PROCESSES: 1 NBI_WORKER_PROCESSES: 1 FS_WORKER_PROCESSES: 1 diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..b18575b --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,44 @@ +cmake_minimum_required(VERSION 3.0) + +PROJECT(icwmp C) + +ADD_DEFINITIONS(-Wall -Wextra -Werror -Wformat) +ADD_DEFINITIONS(-D_GNU_SOURCE) + +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -I${PROJECT_SOURCE_DIR}") + +OPTION(WITH_WOLFSSL "build with lib wolfssl" OFF) +OPTION(WITH_OPENSSL "build with lib openssl" OFF) +OPTION(WITH_MBEDTLS "build with lib mbedtls" OFF) + +IF(NOT WITH_WOLFSSL AND NOT WITH_OPENSSL AND NOT WITH_MBEDTLS) + MESSAGE(FATAL_ERROR "You must enable one of the SSL libraries: {'WOLFSSL','OPENSSL','MBEDTLS'}") +ENDIF() + +FILE(GLOB ICWMP_SOURCES ${PROJECT_SOURCE_DIR}/src/*.c) + +IF(WITH_WOLFSSL) + SET(SSL_LIBS wolfssl) + SET(SSL_LIBS crypto) + add_compile_definitions(LWOLFSSL) +ENDIF(WITH_WOLFSSL) + +IF(WITH_OPENSSL) + SET(SSL_LIBS ssl) + SET(SSL_LIBS crypto) + add_compile_definitions(LOPENSSL) +ENDIF(WITH_OPENSSL) + +IF(WITH_MBEDTLS) + SET(SSL_LIBS mbedtls) + SET(SSL_LIBS mbedcrypto) + add_compile_definitions(LMBEDTLS) +ENDIF(WITH_MBEDTLS) + +ADD_EXECUTABLE(icwmpd ${ICWMP_SOURCES}) + +TARGET_LINK_LIBRARIES(icwmpd pthread z m json-c uci ubox ubus blobmsg_json curl mxml ${SSL_LIBS} ${CRYPTO_LIBS}) + +INSTALL(FILES icwmpd DESTINATION usr/sbin) + +INSTALL(DIRECTORY DESTINATION etc/icwmpd) diff --git a/Makefile.am b/Makefile.am deleted file mode 100644 index b411dde..0000000 --- a/Makefile.am +++ /dev/null @@ -1,68 +0,0 @@ -MAINTAINERCLEANFILES = Makefile.in - -CWMP_VERSION = 3.0.1 - -bin_PROGRAMS = icwmpd - -icwmpd_SOURCES = \ - ./src/common.c \ - ./src/log.c \ - ./src/cwmp_uci.c \ - ./src/config.c \ - ./src/session.c \ - ./src/backupSession.c \ - ./src/digauth.c \ - ./src/event.c \ - ./src/http.c \ - ./src/ubus_utils.c \ - ./src/datamodel_interface.c \ - ./src/cwmp_cli.c \ - ./src/notifications.c \ - ./src/cwmp_zlib.c \ - ./src/cwmp_du_state.c \ - ./src/download.c \ - ./src/upload.c \ - ./src/sched_inform.c \ - ./src/xml.c \ - ./src/rpc.c \ - ./src/diagnostic.c \ - ./src/reboot.c \ - ./src/heartbeat.c \ - ./src/cwmp.c \ - ./src/ssl_utils.c - -icwmpd_CFLAGS = \ - $(AM_CFLAGS) \ - $(LIBUCI_CFLAGS) \ - $(LIBUBOX_CFLAGS) \ - $(LIBUBUS_CFLAGS) \ - $(LIBCURL_CFLAGS) \ - -Wall -Wextra -Werror \ - -Wformat - -icwmpd_LDFLAGS = \ - $(AM_LDFLAGS) \ - $(LIBUCI_LDFLAGS) \ - $(LIBUBOX_LDFLAGS) \ - $(LIBUBUS_LDFLAGS) \ - $(LIBCURL_LDFLAGS) \ - -lmxml - -icwmpd_LDADD = \ - $(AM_LIBS) \ - $(LIBUCI_LIBS) \ - $(LIBUBOX_LIBS) \ - $(LIBUBUS_LIBS) \ - $(LIBCURL_LIBS) \ - $(LIBPTHREAD_LIBS) \ - $(LCRYPTO_LIBS) \ - $(LSSL_LIBS) \ - $(LIBJSON_LIBS) \ - $(LBLOBMSG_LIBS) \ - $(LIBZ_LIBS) \ - $(LIBM_LIBS) - -icwmpd_CFLAGS+=-DCWMP_VERSION=\"$(CWMP_VERSION)\" -icwmpd_LDFLAGS+=-DCWMP_VERSION=\"$(CWMP_VERSION)\" - -icwmpd_CFLAGS+=-I.. diff --git a/configure.ac b/configure.ac deleted file mode 100644 index 30bd834..0000000 --- a/configure.ac +++ /dev/null @@ -1,125 +0,0 @@ -AC_INIT([icwmp], [1.0], [dev@iopsys.eu]) -AM_INIT_AUTOMAKE -AC_CONFIG_SRCDIR([src/cwmp.c]) - -AM_INIT_AUTOMAKE([-Wall -Werror foreign subdir-objects]) - -# additional options - -AC_ARG_ENABLE(acs, [AS_HELP_STRING([--enable-acs], - [specify which ACS is going to be used; there are some optimizations available for HDM and Fusion ACS (default --enable-acs=multi]))],, - [AC_DEFINE(ACS_MULTI)]) - -AS_IF([test "x$enable_acs" = "xhdm"], [AC_DEFINE(ACS_HDM)]) -AS_IF([test "x$enable_acs" = "xfusion"], [AC_DEFINE(ACS_FUSION)]) -AS_IF([test "x$enable_acs" = "xmulti"], [AC_DEFINE(ACS_MULTI)]) -AS_IF([test "x$enable_acs" = "xyes"], [AC_DEFINE(ACS_MULTI)]) -AS_IF([test "x$enable_acs" = "xno"], [AC_DEFINE(ACS_MULTI)]) - -AC_ARG_ENABLE(libopenssl, [AS_HELP_STRING([--enable-libopenssl], [enable libopenssl feature])], AC_DEFINE(LOPENSSL)) -AM_CONDITIONAL([LOPENSSL],[test "x$enable_libopenssl" = "xyes"]) - -AC_ARG_ENABLE(libwolfssl, [AS_HELP_STRING([--enable-libwolfssl], [enable libwolfssl feature])], AC_DEFINE(LWOLFSSL)) -AM_CONDITIONAL([LWOLFSSL],[test "x$enable_libwolfssl" = "xyes"]) - -AC_ARG_ENABLE(libmbedtls, [AS_HELP_STRING([--enable-libmbedtls], [enable libmbedtls feature])], AC_DEFINE(LMBEDTLS)) -AM_CONDITIONAL([LMBEDTLS],[test "x$enable_libmbedtls" = "xyes"]) - -# checks for programs -AC_PROG_CC -AM_PROG_CC_C_O -LT_INIT -AC_ENABLE_SHARED - -# checks for libraries -LIBPTHREAD_LIBS='-lpthread' -AC_SUBST([LIBPTHREAD_LIBS]) - -# checks for libraries -LIBZ_LIBS='-lz' -AC_SUBST([LIBZ_LIBS]) - -LIBM_LIBS='-lm' -AC_SUBST([LIBM_LIBS]) -LIBJSON_LIBS='-ljson-c' -AC_SUBST([LIBJSON_LIBS]) - -AC_ARG_WITH([uci-include-path], - [AS_HELP_STRING([--with-uci-include-path], - [location of the uci library headers])], - [LIBUCI_CFLAGS="-I$withval"]) -AC_SUBST([LIBUCI_CFLAGS]) - -AC_ARG_WITH([uci-lib-path], - [AS_HELP_STRING([--with-uci-lib-path], [location of the uci library])], [LIBUCI_LDFLAGS="-L$withval"]) -AC_SUBST([LIBUCI_LDFLAGS]) - -LIBUCI_LIBS='-luci' -AC_SUBST([LIBUCI_LIBS]) - -AC_ARG_WITH([libubox-include-path], - [AS_HELP_STRING([--with-libubox-include-path], - [location of the libubox library headers])], - [LIBUBOX_CFLAGS="-I$withval"]) -AC_SUBST([LIBUBOX_CFLAGS]) - -AC_ARG_WITH([libubox-lib-path], - [AS_HELP_STRING([--with-libubox-lib-path], [location of the libubox library])], [LIBUBOX_LDFLAGS="-L$withval"]) -AC_SUBST([LIBUBOX_LDFLAGS]) - -LIBUBOX_LIBS='-lubox' -AC_SUBST([LIBUBOX_LIBS]) - -AC_ARG_WITH([libubus-include-path], - [AS_HELP_STRING([--with-libubus-include-path], - [location of the libubus library headers])], - [LIBUBUS_CFLAGS="-I$withval"]) -AC_SUBST([LIBUBUS_CFLAGS]) - -AC_ARG_WITH([libubus-lib-path], - [AS_HELP_STRING([--with-libubus-lib-path], [location of the libubus library])], [LIBUBOX_LDFLAGS="-L$withval"]) -AC_SUBST([LIBUBUS_LDFLAGS]) - -LIBUBUS_LIBS='-lubus' -AC_SUBST([LIBUBUS_LIBS]) - -LBLOBMSG_LIBS='-lblobmsg_json' -AC_SUBST([LBLOBMSG_LIBS]) - -AM_COND_IF([LWOLFSSL], [ - LSSL_LIBS='-lwolfssl' - AC_SUBST([LSSL_LIBS]) - AC_SUBST([LCRYPTO_LIBS]) -]) - -AM_COND_IF([LOPENSSL], [ - LSSL_LIBS='-lssl' - LCRYPTO_LIBS='-lcrypto' - AC_SUBST([LSSL_LIBS]) - AC_SUBST([LCRYPTO_LIBS]) -]) - -AM_COND_IF([LMBEDTLS], [ - LSSL_LIBS='-lmbedtls' - LCRYPTO_LIBS='-lmbedcrypto' - AC_SUBST([LSSL_LIBS]) - AC_SUBST([LCRYPTO_LIBS]) -]) - - PKG_CHECK_MODULES(LIBCURL, [libcurl]) - AC_SUBST(LIBCURL_CFLAGS) - AC_SUBST(LIBCURL_LDFLAGS) - AC_SUBST(LIBCURL_LIBS) - -# checks for header files -AC_CHECK_HEADERS([stdlib.h string.h]) - -# checks for typedefs, structures, and compiler characteristics -AC_TYPE_UINT8_T - -# Makefiles -AC_CONFIG_FILES([ -Makefile -]) - -AC_OUTPUT diff --git a/gitlab-ci/shared.sh b/gitlab-ci/shared.sh index 3b8b8c1..c09bf23 100644 --- a/gitlab-ci/shared.sh +++ b/gitlab-ci/shared.sh @@ -99,17 +99,18 @@ function check_cwmp_status() function clean_icwmp() { - if [ -f Makefile ]; then - exec_cmd make maintainer-clean - exec_cmd make -C test/cmocka clean - find -name '*.gcda' -exec rm {} -fv \; - find -name '*.gcno' -exec rm {} -fv \; - find -name '*.gcov' -exec rm {} -fv \; - find -name '*.deps' -exec rm {} -rfv \; - find -name '*.so' -exec rm {} -fv \; - rm -f *.o *.log *.xml vgcore.* firmware_v1.0.bin - rm -rf report + if [ -d build ]; then + rm -rf build fi + + exec_cmd make -C test/cmocka clean + find -name '*.gcda' -exec rm {} -fv \; + find -name '*.gcno' -exec rm {} -fv \; + find -name '*.gcov' -exec rm {} -fv \; + find -name '*.deps' -exec rm {} -rfv \; + find -name '*.so' -exec rm {} -fv \; + rm -f *.o *.log *.xml vgcore.* firmware_v1.0.bin + rm -rf report } function build_icwmp() @@ -121,10 +122,15 @@ function build_icwmp() clean_icwmp # compile icwmp - autoreconf -i >/dev/null 2>&1 - ./configure CFLAGS="$COV_CFLAGS" LDFLAGS="$COV_LDFLAGS" --enable-acs=multi --enable-debug --enable-libopenssl >/dev/null 2>&1 - make CFLAGS="$COV_CFLAGS" LDFLAGS="$COV_LDFLAGS" - check_ret $? + mkdir -p build + cd build + cmake ../ -DCMAKE_C_FLAGS="$COV_CFLAGS " -DCMAKE_EXE_LINKER_FLAGS="$COV_LDFLAGS" -DWITH_OPENSSL=ON -DCMAKE_INSTALL_PREFIX=/ + exec_cmd make + + echo "installing icwmpd binary" + exec_cmd cp icwmpd ../ + exec_cmd make install + cd .. } function install_uspd() diff --git a/src/common.c b/src/common.c index 52f6473..8e1f334 100755 --- a/src/common.c +++ b/src/common.c @@ -22,11 +22,6 @@ #include "ubus_utils.h" #include "log.h" - -#ifndef CWMP_REVISION -#define CWMP_REVISION "8.2.10" -#endif - char *commandKey = NULL; bool thread_end = false; long int flashsize = 256000000; @@ -91,18 +86,8 @@ static void show_help(void) printf("Usage: icwmpd [OPTIONS]\n"); printf(" -b, --boot-event (CWMP daemon) Start CWMP with BOOT event\n"); printf(" -g, --get-rpc-methods (CWMP daemon) Start CWMP with GetRPCMethods request to ACS\n"); - printf(" -c, --cli CWMP CLI\n"); + printf(" -c, --cli CWMP CLI\n"); printf(" -h, --help Display this help text\n"); - printf(" -v, --version Display the version\n"); -} - -static void show_version() -{ -#ifndef CWMP_REVISION - fprintf(stdout, "\nVersion: %s\n\n", CWMP_VERSION); -#else - fprintf(stdout, "\nVersion: %s revision %s\n\n", CWMP_VERSION, CWMP_REVISION); -#endif } int global_env_init(int argc, char **argv, struct env *env) @@ -114,7 +99,6 @@ int global_env_init(int argc, char **argv, struct env *env) case 'b': env->boot = CWMP_START_BOOT; break; - case 'g': env->periodic = CWMP_START_PERIODIC; break; @@ -124,10 +108,6 @@ int global_env_init(int argc, char **argv, struct env *env) case 'h': show_help(); exit(0); - - case 'v': - show_version(); - exit(0); } } return CWMP_OK; diff --git a/src/common.h b/src/common.h index 5ed900b..81337cf 100644 --- a/src/common.h +++ b/src/common.h @@ -18,10 +18,6 @@ #include #include -#ifndef CWMP_VERSION -#define CWMP_VERSION "3.0.0" -#endif - #ifndef FREE #define FREE(x) do { if(x) {free(x); x = NULL;} } while (0) #endif diff --git a/src/http.c b/src/http.c index e51b307..5172223 100644 --- a/src/http.c +++ b/src/http.c @@ -207,19 +207,17 @@ int icwmp_http_send_message(struct cwmp *cwmp, char *msg_out, int msg_out_len, c http_c.header_list = curl_slist_append(http_c.header_list, "User-Agent: iopsys-cwmp"); if (!http_c.header_list) return -1; + http_c.header_list = curl_slist_append(http_c.header_list, "Content-Type: text/xml"); if (!http_c.header_list) return -1; -#ifdef ACS_FUSION - http_c.header_list = curl_slist_append(http_c.header_list, "Expect:"); - if (!http_c.header_list) - return -1; -#endif /* ACS_FUSION */ + if (cwmp->conf.http_disable_100continue) { http_c.header_list = curl_slist_append(http_c.header_list, "Expect:"); if (!http_c.header_list) return -1; } + http_set_connection_options(cwmp); http_set_security_options(cwmp); http_set_header_list_options(cwmp); diff --git a/test/cmocka/Makefile b/test/cmocka/Makefile index 2537146..778e50e 100644 --- a/test/cmocka/Makefile +++ b/test/cmocka/Makefile @@ -1,16 +1,14 @@ -include ../../Makefile.am LIB_LDFLAGS:= -luci -lblobmsg_json -lubox\ -ljson-c -lubus -lpthread -lcurl\ -lcrypto -lmxml -LIB_CFLAGS:= -fPIC -I../../src/ -DLOPENSSL -g -O0 +LIB_CFLAGS:= -fPIC -I../../ -DLOPENSSL -g -O0 UNIT_TESTS:= icwmp_unit_testd VALGRIND = /usr/bin/valgrind --xml=yes --xml-file=memory-report.xml --leak-check=full --show-reachable=yes --show-leak-kinds=all --errors-for-leak-kinds=all - -ICWMP_SOURCES=$(patsubst ./src/%.c, ../../src/%.c, $(icwmpd_SOURCES)) -ICWMP_OBJS=$(patsubst ../../src/%.c, %.o, $(ICWMP_SOURCES)) + +ICWMP_OBJS=$(patsubst ../../src/%.c, %.o, $(wildcard ../../src/*.c)) TEST_SRCS = $(wildcard *.c) TEST_OBJS = $(TEST_SRCS:=.o)