From eb5aa4ef5901002217429e7325e78d8017d0847c Mon Sep 17 00:00:00 2001 From: Antti Kauppila Date: Mon, 21 Dec 2015 09:47:29 +0200 Subject: [PATCH] New CoAP service + unit tests --- .gitignore | 2 + .../CoAP_Server_unit_test_app.c | 31 - Makefile | 31 +- Makefile.test | 51 ++ coap-service-linux/coap_server_impl.c | 16 - coap-service-mbed/coap_server_impl.c | 16 - coap-service-nanomesh/coap_server_impl.c | 99 --- coap-service/coap_service_api.h | 172 ++--- junit_xsl.xslt | 101 +++ module.json | 3 +- source/coap_connection_handler.c | 679 ++++++++++++++++++ source/coap_message_handler.c | 372 ++++++++++ source/coap_security_handler.c | 396 ++++++++++ source/coap_server.c | 113 --- source/coap_service.c | 177 ----- source/coap_service_api.c | 450 ++++++++++++ source/include/coap_connection_handler.h | 48 ++ source/include/coap_message_handler.h | 67 ++ source/include/coap_security_handler.h | 73 ++ source/include/coap_server.h | 52 -- source/include/coap_server_impl.h | 41 -- test/coap-service/unittest/Makefile | 23 + test/coap-service/unittest/MakefileWorker.mk | 562 +++++++++++++++ .../unittest/coap_connection_handler/Makefile | 23 + .../coap_connection_handlertest.cpp | 62 ++ .../unittest/coap_connection_handler/main.cpp | 15 + .../test_coap_connection_handler.c | 467 ++++++++++++ .../test_coap_connection_handler.h | 36 + .../unittest/coap_message_handler/Makefile | 23 + .../coap_message_handlertest.cpp | 52 ++ .../unittest/coap_message_handler/main.cpp | 15 + .../test_coap_message_handler.c | 298 ++++++++ .../test_coap_message_handler.h | 26 + .../unittest/coap_security_handler/Makefile | 23 + .../coap_security_handlertest.cpp | 55 ++ .../unittest/coap_security_handler/main.cpp | 15 + .../test_coap_security_handler.c | 281 ++++++++ .../test_coap_security_handler.h | 33 + .../unittest/coap_service_api/Makefile | 24 + .../coap_service_api/coap_service_apitest.cpp | 72 ++ .../unittest/coap_service_api/main.cpp | 15 + .../coap_service_api/test_coap_service_api.c | 407 +++++++++++ .../coap_service_api/test_coap_service_api.h | 41 ++ .../unittest/makefile_defines.txt | 42 ++ test/coap-service/unittest/run_tests | 34 + test/coap-service/unittest/run_tests~ | 34 + .../unittest/stub/6lowpan_iphc_stub.c | 93 +++ .../unittest/stub/6lowpan_mesh_stub.c | 74 ++ .../coap-service/unittest/stub/address_stub.c | 230 ++++++ .../coap-service/unittest/stub/address_stub.h | 21 + .../unittest/stub/buffer_dyn_stub.c | 63 ++ .../stub/coap_connection_handler_stub.c | 59 ++ .../stub/coap_connection_handler_stub.h | 32 + .../unittest/stub/coap_message_handler_stub.c | 55 ++ .../unittest/stub/coap_message_handler_stub.h | 29 + .../stub/coap_security_handler_stub.c | 75 ++ .../stub/coap_security_handler_stub.h | 24 + .../unittest/stub/coap_service_api_stub.c | 63 ++ .../unittest/stub/common_functions_stub.c | 116 +++ test/coap-service/unittest/stub/cudp_stub.c | 36 + .../unittest/stub/dhcp_service_api_stub.c | 157 ++++ .../unittest/stub/eventOS_event_stub.c | 21 + .../unittest/stub/eventOS_event_stub.h | 22 + test/coap-service/unittest/stub/icmpv6_stub.c | 141 ++++ .../unittest/stub/iphc_compress_stub.c | 28 + .../unittest/stub/iphc_decompress_stub.c | 23 + .../unittest/stub/ipv6_routing_table_stub.c | 184 +++++ test/coap-service/unittest/stub/ipv6_stub.c | 99 +++ .../unittest/stub/libDHCPv6_server_stub.c | 56 ++ .../unittest/stub/libDHCPv6_stub.c | 212 ++++++ .../unittest/stub/lowpan_context_stub.c | 39 + .../unittest/stub/mac_data_poll_stub.c | 84 +++ .../unittest/stub/mac_mlme_stub.c | 221 ++++++ .../unittest/stub/mac_pairwise_key_stub.c | 78 ++ .../stub/mac_security_interface_stub.c | 106 +++ .../coap-service/unittest/stub/mbedtls_stub.c | 310 ++++++++ .../coap-service/unittest/stub/mbedtls_stub.h | 49 ++ .../unittest/stub/mle_service_stub.c | 220 ++++++ test/coap-service/unittest/stub/mle_stub.c | 342 +++++++++ test/coap-service/unittest/stub/mle_stub.h | 21 + .../coap-service/unittest/stub/mle_tlv_stub.c | 130 ++++ .../unittest/stub/multicast_stub.c | 52 ++ test/coap-service/unittest/stub/nd_proxy.c | 20 + .../unittest/stub/nd_proxy_stub.c | 56 ++ .../unittest/stub/nd_router_object_stub.c | 242 +++++++ .../unittest/stub/neighbor_cache_stub.c | 50 ++ test/coap-service/unittest/stub/net_stub.c | 279 +++++++ .../coap-service/unittest/stub/ns_list_stub.c | 9 + .../unittest/stub/ns_timer_stub.c | 57 ++ .../unittest/stub/ns_timer_stub.h | 19 + test/coap-service/unittest/stub/ns_trace.c | 10 + .../unittest/stub/ns_trace_stub.c | 202 ++++++ .../unittest/stub/nsdynmemLIB_stub.c | 48 ++ .../unittest/stub/nsdynmemLIB_stub.h | 29 + .../stub/protocol_6lowpan_bootstrap_stub.c | 162 +++++ .../stub/protocol_6lowpan_interface_stub.c | 75 ++ .../unittest/stub/protocol_6lowpan_stub.c | 145 ++++ .../unittest/stub/protocol_core_stub.c | 300 ++++++++ .../stub/protocol_interface_driver_stub.c | 14 + .../unittest/stub/protocol_ipv6_stub.c | 169 +++++ .../coap-service/unittest/stub/randLIB_stub.c | 47 ++ .../unittest/stub/routing_table_stub.c | 128 ++++ .../coap-service/unittest/stub/rpl_obj_stub.c | 392 ++++++++++ .../unittest/stub/security_lib_stub.c | 35 + test/coap-service/unittest/stub/shalib_stub.c | 58 ++ .../unittest/stub/sn_coap_builder_stub.c | 55 ++ .../unittest/stub/sn_coap_builder_stub.h | 13 + .../unittest/stub/sn_coap_parser_stub.c | 107 +++ .../unittest/stub/sn_coap_parser_stub.h | 13 + .../unittest/stub/sn_coap_protocol_stub.c | 96 +++ .../unittest/stub/sn_coap_protocol_stub.h | 18 + .../unittest/stub/socket_api_stub.c | 118 +++ .../unittest/stub/socket_api_stub.h | 31 + test/coap-service/unittest/stub/socket_stub.c | 93 +++ test/coap-service/unittest/stub/socket_stub.h | 24 + .../unittest/stub/system_timer_stub.c | 59 ++ test/coap-service/unittest/stub/tcp_stub.c | 56 ++ .../unittest/stub/thread_beacon_stub.c | 65 ++ .../unittest/stub/thread_bootstrap_stub.c | 248 +++++++ .../stub/thread_commissioning_if_stub.c | 67 ++ .../unittest/stub/thread_dhcpv6_client_stub.c | 77 ++ .../unittest/stub/thread_dynamic_reed_stub.c | 32 + .../stub/thread_host_bootstrap_stub.c | 87 +++ .../stub/thread_joiner_application_stub.c | 63 ++ .../stub/thread_management_api_stub.c | 48 ++ .../stub/thread_management_client_stub.c | 59 ++ .../unittest/stub/thread_management_if_stub.c | 305 ++++++++ .../stub/thread_management_server_stub.c | 55 ++ .../unittest/stub/thread_meshcop_lib_stub.c | 47 ++ .../unittest/stub/thread_nd_stub.c | 85 +++ .../stub/thread_network_data_lib_stub.c | 79 ++ .../stub/thread_network_data_storage_stub.c | 287 ++++++++ .../unittest/stub/thread_network_synch_stub.c | 21 + .../stub/thread_router_bootstrap_stub.c | 137 ++++ .../stub/thread_routerid_server_stub.c | 31 + .../unittest/stub/thread_routing_stub.c | 165 +++++ test/coap-service/unittest/stub/thread_stub.c | 373 ++++++++++ .../unittest/stub/thread_test_api_stub.c | 70 ++ .../coap-service/unittest/stub/timeout_stub.c | 15 + xsl_script.sh | 35 + 140 files changed, 14246 insertions(+), 667 deletions(-) delete mode 100644 CoAP_Server_unit_test/CoAP_Server_unit_test_app.c create mode 100644 Makefile.test delete mode 100644 coap-service-linux/coap_server_impl.c delete mode 100644 coap-service-mbed/coap_server_impl.c delete mode 100644 coap-service-nanomesh/coap_server_impl.c create mode 100644 junit_xsl.xslt create mode 100644 source/coap_connection_handler.c create mode 100644 source/coap_message_handler.c create mode 100644 source/coap_security_handler.c delete mode 100644 source/coap_server.c delete mode 100644 source/coap_service.c create mode 100644 source/coap_service_api.c create mode 100644 source/include/coap_connection_handler.h create mode 100644 source/include/coap_message_handler.h create mode 100644 source/include/coap_security_handler.h delete mode 100644 source/include/coap_server.h delete mode 100644 source/include/coap_server_impl.h create mode 100755 test/coap-service/unittest/Makefile create mode 100755 test/coap-service/unittest/MakefileWorker.mk create mode 100644 test/coap-service/unittest/coap_connection_handler/Makefile create mode 100644 test/coap-service/unittest/coap_connection_handler/coap_connection_handlertest.cpp create mode 100644 test/coap-service/unittest/coap_connection_handler/main.cpp create mode 100644 test/coap-service/unittest/coap_connection_handler/test_coap_connection_handler.c create mode 100644 test/coap-service/unittest/coap_connection_handler/test_coap_connection_handler.h create mode 100644 test/coap-service/unittest/coap_message_handler/Makefile create mode 100644 test/coap-service/unittest/coap_message_handler/coap_message_handlertest.cpp create mode 100644 test/coap-service/unittest/coap_message_handler/main.cpp create mode 100644 test/coap-service/unittest/coap_message_handler/test_coap_message_handler.c create mode 100644 test/coap-service/unittest/coap_message_handler/test_coap_message_handler.h create mode 100644 test/coap-service/unittest/coap_security_handler/Makefile create mode 100644 test/coap-service/unittest/coap_security_handler/coap_security_handlertest.cpp create mode 100644 test/coap-service/unittest/coap_security_handler/main.cpp create mode 100644 test/coap-service/unittest/coap_security_handler/test_coap_security_handler.c create mode 100644 test/coap-service/unittest/coap_security_handler/test_coap_security_handler.h create mode 100644 test/coap-service/unittest/coap_service_api/Makefile create mode 100644 test/coap-service/unittest/coap_service_api/coap_service_apitest.cpp create mode 100644 test/coap-service/unittest/coap_service_api/main.cpp create mode 100644 test/coap-service/unittest/coap_service_api/test_coap_service_api.c create mode 100644 test/coap-service/unittest/coap_service_api/test_coap_service_api.h create mode 100755 test/coap-service/unittest/makefile_defines.txt create mode 100755 test/coap-service/unittest/run_tests create mode 100755 test/coap-service/unittest/run_tests~ create mode 100644 test/coap-service/unittest/stub/6lowpan_iphc_stub.c create mode 100644 test/coap-service/unittest/stub/6lowpan_mesh_stub.c create mode 100644 test/coap-service/unittest/stub/address_stub.c create mode 100644 test/coap-service/unittest/stub/address_stub.h create mode 100644 test/coap-service/unittest/stub/buffer_dyn_stub.c create mode 100644 test/coap-service/unittest/stub/coap_connection_handler_stub.c create mode 100644 test/coap-service/unittest/stub/coap_connection_handler_stub.h create mode 100644 test/coap-service/unittest/stub/coap_message_handler_stub.c create mode 100644 test/coap-service/unittest/stub/coap_message_handler_stub.h create mode 100644 test/coap-service/unittest/stub/coap_security_handler_stub.c create mode 100644 test/coap-service/unittest/stub/coap_security_handler_stub.h create mode 100644 test/coap-service/unittest/stub/coap_service_api_stub.c create mode 100644 test/coap-service/unittest/stub/common_functions_stub.c create mode 100644 test/coap-service/unittest/stub/cudp_stub.c create mode 100644 test/coap-service/unittest/stub/dhcp_service_api_stub.c create mode 100644 test/coap-service/unittest/stub/eventOS_event_stub.c create mode 100644 test/coap-service/unittest/stub/eventOS_event_stub.h create mode 100644 test/coap-service/unittest/stub/icmpv6_stub.c create mode 100644 test/coap-service/unittest/stub/iphc_compress_stub.c create mode 100644 test/coap-service/unittest/stub/iphc_decompress_stub.c create mode 100644 test/coap-service/unittest/stub/ipv6_routing_table_stub.c create mode 100644 test/coap-service/unittest/stub/ipv6_stub.c create mode 100644 test/coap-service/unittest/stub/libDHCPv6_server_stub.c create mode 100644 test/coap-service/unittest/stub/libDHCPv6_stub.c create mode 100644 test/coap-service/unittest/stub/lowpan_context_stub.c create mode 100644 test/coap-service/unittest/stub/mac_data_poll_stub.c create mode 100644 test/coap-service/unittest/stub/mac_mlme_stub.c create mode 100644 test/coap-service/unittest/stub/mac_pairwise_key_stub.c create mode 100644 test/coap-service/unittest/stub/mac_security_interface_stub.c create mode 100644 test/coap-service/unittest/stub/mbedtls_stub.c create mode 100644 test/coap-service/unittest/stub/mbedtls_stub.h create mode 100644 test/coap-service/unittest/stub/mle_service_stub.c create mode 100644 test/coap-service/unittest/stub/mle_stub.c create mode 100644 test/coap-service/unittest/stub/mle_stub.h create mode 100644 test/coap-service/unittest/stub/mle_tlv_stub.c create mode 100644 test/coap-service/unittest/stub/multicast_stub.c create mode 100644 test/coap-service/unittest/stub/nd_proxy.c create mode 100644 test/coap-service/unittest/stub/nd_proxy_stub.c create mode 100644 test/coap-service/unittest/stub/nd_router_object_stub.c create mode 100644 test/coap-service/unittest/stub/neighbor_cache_stub.c create mode 100644 test/coap-service/unittest/stub/net_stub.c create mode 100644 test/coap-service/unittest/stub/ns_list_stub.c create mode 100644 test/coap-service/unittest/stub/ns_timer_stub.c create mode 100644 test/coap-service/unittest/stub/ns_timer_stub.h create mode 100644 test/coap-service/unittest/stub/ns_trace.c create mode 100644 test/coap-service/unittest/stub/ns_trace_stub.c create mode 100644 test/coap-service/unittest/stub/nsdynmemLIB_stub.c create mode 100644 test/coap-service/unittest/stub/nsdynmemLIB_stub.h create mode 100644 test/coap-service/unittest/stub/protocol_6lowpan_bootstrap_stub.c create mode 100644 test/coap-service/unittest/stub/protocol_6lowpan_interface_stub.c create mode 100644 test/coap-service/unittest/stub/protocol_6lowpan_stub.c create mode 100644 test/coap-service/unittest/stub/protocol_core_stub.c create mode 100644 test/coap-service/unittest/stub/protocol_interface_driver_stub.c create mode 100644 test/coap-service/unittest/stub/protocol_ipv6_stub.c create mode 100644 test/coap-service/unittest/stub/randLIB_stub.c create mode 100644 test/coap-service/unittest/stub/routing_table_stub.c create mode 100644 test/coap-service/unittest/stub/rpl_obj_stub.c create mode 100644 test/coap-service/unittest/stub/security_lib_stub.c create mode 100644 test/coap-service/unittest/stub/shalib_stub.c create mode 100644 test/coap-service/unittest/stub/sn_coap_builder_stub.c create mode 100644 test/coap-service/unittest/stub/sn_coap_builder_stub.h create mode 100644 test/coap-service/unittest/stub/sn_coap_parser_stub.c create mode 100644 test/coap-service/unittest/stub/sn_coap_parser_stub.h create mode 100644 test/coap-service/unittest/stub/sn_coap_protocol_stub.c create mode 100644 test/coap-service/unittest/stub/sn_coap_protocol_stub.h create mode 100644 test/coap-service/unittest/stub/socket_api_stub.c create mode 100644 test/coap-service/unittest/stub/socket_api_stub.h create mode 100644 test/coap-service/unittest/stub/socket_stub.c create mode 100644 test/coap-service/unittest/stub/socket_stub.h create mode 100644 test/coap-service/unittest/stub/system_timer_stub.c create mode 100644 test/coap-service/unittest/stub/tcp_stub.c create mode 100644 test/coap-service/unittest/stub/thread_beacon_stub.c create mode 100644 test/coap-service/unittest/stub/thread_bootstrap_stub.c create mode 100644 test/coap-service/unittest/stub/thread_commissioning_if_stub.c create mode 100644 test/coap-service/unittest/stub/thread_dhcpv6_client_stub.c create mode 100644 test/coap-service/unittest/stub/thread_dynamic_reed_stub.c create mode 100644 test/coap-service/unittest/stub/thread_host_bootstrap_stub.c create mode 100644 test/coap-service/unittest/stub/thread_joiner_application_stub.c create mode 100644 test/coap-service/unittest/stub/thread_management_api_stub.c create mode 100644 test/coap-service/unittest/stub/thread_management_client_stub.c create mode 100644 test/coap-service/unittest/stub/thread_management_if_stub.c create mode 100644 test/coap-service/unittest/stub/thread_management_server_stub.c create mode 100644 test/coap-service/unittest/stub/thread_meshcop_lib_stub.c create mode 100644 test/coap-service/unittest/stub/thread_nd_stub.c create mode 100644 test/coap-service/unittest/stub/thread_network_data_lib_stub.c create mode 100644 test/coap-service/unittest/stub/thread_network_data_storage_stub.c create mode 100644 test/coap-service/unittest/stub/thread_network_synch_stub.c create mode 100644 test/coap-service/unittest/stub/thread_router_bootstrap_stub.c create mode 100644 test/coap-service/unittest/stub/thread_routerid_server_stub.c create mode 100644 test/coap-service/unittest/stub/thread_routing_stub.c create mode 100644 test/coap-service/unittest/stub/thread_stub.c create mode 100644 test/coap-service/unittest/stub/thread_test_api_stub.c create mode 100644 test/coap-service/unittest/stub/timeout_stub.c create mode 100755 xsl_script.sh diff --git a/.gitignore b/.gitignore index cf68134e08..80fbaf0da9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ *.a *.lib output +lcov +coverage diff --git a/CoAP_Server_unit_test/CoAP_Server_unit_test_app.c b/CoAP_Server_unit_test/CoAP_Server_unit_test_app.c deleted file mode 100644 index f7fd55a825..0000000000 --- a/CoAP_Server_unit_test/CoAP_Server_unit_test_app.c +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (c) 2015 ARM Limited. All rights reserved. - - * SPDX-License-Identifier: Apache-2.0 - * Licensed under the Apache License, Version 2.0 (the License); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#include -#include -#include "ns_types.h" -#include "coap_service_api.h" - -int main(void) { - printf("!!!CoAP Server test!!!"); /* prints !!!Hello World!!! */ - - int8_t service_id = 0; - - service_id = coap_service_initialize(0xff, 666, 0); - - return EXIT_SUCCESS; -} - diff --git a/Makefile b/Makefile index 74eb7ad692..c597dbd06b 100644 --- a/Makefile +++ b/Makefile @@ -20,37 +20,32 @@ # SERVLIB_DIR := ../libService override CFLAGS += -I$(SERVLIB_DIR)/libService/ -#override CFLAGS += -I$(SERVLIB_DIR)/libService/platform/ + +NANOSTACK_DIR := ../nanostack +override CFLAGS += -I$(NANOSTACK_DIR)/nanostack/ NSDLC_DIR := ../nsdl-c override CFLAGS += -I$(NSDLC_DIR)/nsdl-c EVENTLOOP_DIR := ../event-loop override CFLAGS += -I$(EVENTLOOP_DIR)/nanostack-event-loop/ -#override CFLAGS += -I$(EVENTLOOP_DIR)/event-loop/ - -#override CFLAGS += -I../libService/libService/ -#override CFLAGS += -I../nsdl-c/nsdl-c/ -#override CFLAGS += -I../event-loop/nanostack-event-loop/ - -LIB = libcoap-service.a - -SRCS := \ - source/coap_service.c \ - source/coap_server.c \ - coap-service-nanomesh/coap_server_impl.c \ - -override CFLAGS += -DVERSION='"$(VERSION)"' - +MBEDTLS_DIR := ../mbedtls +override CFLAGS += -I$(MBEDTLS_DIR)/configs -I$(MBEDTLS_DIR) -DMBEDTLS_CONFIG_FILE='' -I$(MBEDTLS_DIR)/include COAPSERVICE_DIR := ../coap-service override CFLAGS += -I$(COAPSERVICE_DIR)/coap-service/ override CFLAGS += -I$(COAPSERVICE_DIR)/source/include/ -#override CFLAGS += -Isource/coap-service/source/include/ -#override CFLAGS += -Icoap-service-nanomesh/include/ +LIB = libcoap-service.a +SRCS := \ + source/coap_connection_handler.c \ + source/coap_message_handler.c \ + source/coap_security_handler.c \ + source/coap_service_api.c \ + +override CFLAGS += -DVERSION='"$(VERSION)"' include ../libService/toolchain_rules.mk diff --git a/Makefile.test b/Makefile.test new file mode 100644 index 0000000000..8a1c3063f7 --- /dev/null +++ b/Makefile.test @@ -0,0 +1,51 @@ +# +# Makefile.test for COAP service unit tests +# + +# List of subdirectories to build +TEST_FOLDER := ./test/ +# List of unit test directories for libraries +UNITTESTS := $(sort $(dir $(wildcard $(TEST_FOLDER)*/unittest/*))) +TESTDIRS := $(UNITTESTS:%=build-%) +CLEANTESTDIRS := $(UNITTESTS:%=clean-%) +COVERAGEFILE := ./lcov/coverage.info + +.PHONY: test +test: $(TESTDIRS) + @rm -rf ./lcov + @rm -rf ./coverage + @mkdir -p lcov + @mkdir -p lcov/results + @mkdir coverage + @find ./test -name '*.xml' | xargs cp -t ./lcov/results/ + @rm -f lcov/index.xml + @./xsl_script.sh + @cp junit_xsl.xslt lcov/. + @xsltproc -o lcov/testresults.html lcov/junit_xsl.xslt lcov/index.xml + @rm -f lcov/junit_xsl.xslt + @rm -f lcov/index.xml + @find ./ -name '*.gcno' | xargs cp --backup=numbered -t ./coverage/ + @find ./ -name '*.gcda' | xargs cp --backup=numbered -t ./coverage/ + @gcovr --object-directory ./coverage --exclude-unreachable-branches -e '.*/builds/.*' -e '.*/test/.*' -e '.*/yotta_modules/.*' -e '.*/stub/.*' -x -o ./lcov/gcovr.xml + @lcov -d test/. -c -o $(COVERAGEFILE) + @lcov -q -r $(COVERAGEFILE) "/usr*" -o $(COVERAGEFILE) + @lcov -q -r $(COVERAGEFILE) "/test*" -o $(COVERAGEFILE) + @lcov -q -r $(COVERAGEFILE) "/mbed-client-libservice*" -o $(COVERAGEFILE) + @lcov -q -r $(COVERAGEFILE) "/libService*" -o $(COVERAGEFILE) + @genhtml -q $(COVERAGEFILE) --show-details --output-directory lcov/html + @echo coap-service unit tests built + +$(TESTDIRS): + @make -C $(@:build-%=%) + +$(CLEANDIRS): + @make -C $(@:clean-%=%) clean + +$(CLEANTESTDIRS): + @make -C $(@:clean-%=%) clean + +# Extend default clean rule +clean: clean-extra + +clean-extra: $(CLEANDIRS) \ + $(CLEANTESTDIRS) diff --git a/coap-service-linux/coap_server_impl.c b/coap-service-linux/coap_server_impl.c deleted file mode 100644 index a8c5de2178..0000000000 --- a/coap-service-linux/coap_server_impl.c +++ /dev/null @@ -1,16 +0,0 @@ -/* - * Copyright (c) 2015 ARM Limited. All rights reserved. - - * SPDX-License-Identifier: Apache-2.0 - * Licensed under the Apache License, Version 2.0 (the License); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ diff --git a/coap-service-mbed/coap_server_impl.c b/coap-service-mbed/coap_server_impl.c deleted file mode 100644 index a8c5de2178..0000000000 --- a/coap-service-mbed/coap_server_impl.c +++ /dev/null @@ -1,16 +0,0 @@ -/* - * Copyright (c) 2015 ARM Limited. All rights reserved. - - * SPDX-License-Identifier: Apache-2.0 - * Licensed under the Apache License, Version 2.0 (the License); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ diff --git a/coap-service-nanomesh/coap_server_impl.c b/coap-service-nanomesh/coap_server_impl.c deleted file mode 100644 index 3d7310d87d..0000000000 --- a/coap-service-nanomesh/coap_server_impl.c +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Copyright (c) 2015 ARM Limited. All rights reserved. - - * SPDX-License-Identifier: Apache-2.0 - * Licensed under the Apache License, Version 2.0 (the License); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#include -#include "ns_types.h" -//#include "eventOS_event.h" -//#include "eventOS_scheduler.h" -//#include "eventOS_event_timer.h" -#include "nsdynmemLIB.h" -#include "ns_list.h" -#include "coap_server_impl.h" - -#define COAP_SERVER_SERVICE_TASKLET_INIT 1 -#define COAP_SERVER_SERVICE_TIMER 2 -#define COAP_SERVER_SERVICE_TIMER_ID 1 -#define COAP_TIMER_UPDATE_PERIOD_IN_SECONDS 10 - -static int8_t coap_service_tasklet = -1; - -static int8_t coap_server_service_tasklet_generated(void); -void coap_server_service_tasklet(arm_event_s * event); - -int8_t coap_server_start(void) -{ - int8_t ret_val = -1; - - ret_val = coap_server_service_tasklet_generated(); - - return ret_val; -} - - -static int8_t coap_server_service_tasklet_generated(void) -{ - int8_t ret_val; - - if(coap_service_tasklet == -1) - { - //coap_service_tasklet = eventOS_event_handler_create(&coap_server_service_tasklet,COAP_SERVER_SERVICE_TASKLET_INIT); - ret_val = coap_service_tasklet; - } - - // for unit testing now setted to 1; - ret_val = 1; - - return ret_val; -} - -void coap_server_service_tasklet(arm_event_s * event) -{ - - if(event->event_type == COAP_SERVER_SERVICE_TASKLET_INIT) - { - //We should define periodically timer service!! - //eventOS_event_timer_request(COAP_SERVER_SERVICE_TIMER_ID, COAP_SERVER_SERVICE_TIMER,coap_service_tasklet, (COAP_TIMER_UPDATE_PERIOD_IN_SECONDS *1000)); - } - else if(event->event_type == COAP_SERVER_SERVICE_TIMER) - { - //eventOS_event_timer_request(COAP_SERVER_SERVICE_TIMER_ID, COAP_SERVER_SERVICE_TIMER,coap_service_tasklet, (COAP_TIMER_UPDATE_PERIOD_IN_SECONDS *1000)); - } - -} - -uint16_t socket_open(uint16_t listen_port, coap_service_request_recv_cb *requst_recv_cb) -{ - - return 0; -} - -void *memory_allocation(uint16_t size) -{ - - - if(size) - return malloc(size); - else - return 0; -} - -void memory_free(void* ptr) -{ - - if(ptr) - free(ptr); - -} diff --git a/coap-service/coap_service_api.h b/coap-service/coap_service_api.h index 6c97f00287..98529cc18a 100755 --- a/coap-service/coap_service_api.h +++ b/coap-service/coap_service_api.h @@ -1,18 +1,5 @@ /* * Copyright (c) 2015 ARM Limited. All rights reserved. - - * SPDX-License-Identifier: Apache-2.0 - * Licensed under the Apache License, Version 2.0 (the License); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. */ #ifndef COAP_SERVICE_API_H_ @@ -42,7 +29,10 @@ extern "C" { #define COAP_SERVICE_OPTIONS_NONE 0x00 #define COAP_SERVICE_OPTIONS_VIRTUAL_SOCKET 0x01 #define COAP_SERVICE_OPTIONS_SECURE 0x02 - +#define COAP_SERVICE_OPTIONS_EPHEMERAL_PORT 0x04 +/** Link-layer security bypass option is set*/ +#define COAP_SERVICE_OPTIONS_SECURE_BYPASS 0x80 + // Bits for request options #define COAP_REQUEST_OPTIONS_NONE 0x00 #define COAP_REQUEST_OPTIONS_ADDRESS_DEFAULT 0x00//!< default is not setting either short or long. @@ -51,28 +41,17 @@ extern "C" { #define COAP_REQUEST_OPTIONS_MULTICAST 0x04 //!< indicates that CoAP library support multicasting #define COAP_REQUEST_OPTIONS_SECURE_BYPASS 0x08 - /** - * \brief Initialise server instance. + * \brief Service message response receive callback. * - * Initialise CoAP services for the registered application. + * Function that handles CoAP service message receiving and parsing * - * \param interface_id Informs registered application interface id. This parameter is passed to socket implementation. - * \param listen_port Port that Application wants to use for communicate with coap server. - * \param service_options Options of the current service. + * \param msg_id Id number of the current message. + * \param response_ptr Pointer to CoAP header structure. * - * \return service_id / -1 for failure - */ -int8_t coap_service_initialize(int8_t interface_id, uint16_t listen_port, uint8_t service_options); - -/** - * \brief Service delete - * - * Removes all data related to this instance - * - * \param service_id Id number of the current service. - */ -void coap_service_delete( int8_t service_id ); + * \return 0 for success / -1 for failure + */ +typedef int coap_service_response_recv(int8_t service_id, uint16_t msg_id, sn_coap_hdr_s *response_ptr); /** * \brief CoAP service request callback @@ -91,14 +70,15 @@ typedef int coap_service_request_recv_cb(int8_t service_id, uint8_t source_addre /** * \brief Security service start callback * - * Starts security service handling. + * Starts security service handling and fetches device password. * * \param service_id Id number of the current service. - * \param EUI64 64 bit global identifier + * \param address Address of sender + * \param port Port of the device * - * \return 0 for success / -1 for failure + * \return 0 for success / -1 for failure */ -typedef int coap_service_security_start_cb(int8_t service_id, uint8_t EUI64[static 8]); +typedef int coap_service_security_start_cb(int8_t service_id, uint8_t address[static 16], uint16_t port, uint8_t* pw, uint8_t *pw_len); /** * \brief CoAP service security done callback @@ -106,38 +86,58 @@ typedef int coap_service_security_start_cb(int8_t service_id, uint8_t EUI64[stat * CoAP service security done callback function. * * \param service_id Id number of the current service. - * \param EUI64 64 bit global identifier + * \param address Address of sender * \param keyblock Security key (40 bits) * - * \return 0 for success / -1 for failure + * \return 0 for success / -1 for failure */ -typedef int coap_service_security_done_cb(int8_t service_id, uint8_t EUI64[static 8], uint8_t keyblock[static 40]); - +typedef int coap_service_security_done_cb(int8_t service_id, uint8_t address[static 16], uint8_t keyblock[static 40]); /** - * \brief Security service start callback + * \brief Initialise server instance. * - * Starts security service handling. + * Initialise Thread services for the registered application. * - * \param EUI64 64 bit global identifier - * \param PSKd_ptr Pointer to PSK key. - * \param PSKd_len Lenght of PSK key. + * \param interface_id Informs registered application interface id. This parameter is passed to socket implementation. + * \param listen_port Port that Application wants to use for communicate with coap server. + * \param service_options Options of the current service. + * \param *start_ptr Callback to inform security handling is started and to fetch device password. + * \param *security_done_cb Callback to inform security handling is done. * - * \return 0 for success / -1 for failure + * \return service_id / -1 for failure */ -int coap_service_security_key_set(int8_t service_id, uint8_t EUI64[static 8], uint8_t *PSKd_ptr, uint8_t PSKd_len); +extern int8_t coap_service_initialize(int8_t interface_id, uint16_t listen_port, uint8_t service_options, coap_service_security_start_cb *start_ptr, coap_service_security_done_cb *security_done_cb); /** - * \brief Service message response receive callback. + * \brief Service delete * - * Function that handles CoAP service message receiving and parsing + * Removes all data related to this instance * - * \param msg_id Id number of the current message. - * \param response_ptr Pointer to CoAP header structure. + * \param service_id Id number of the current service. + */ +extern void coap_service_delete( int8_t service_id ); + +/** + * \brief Close secure connection * - * \return 0 for success / -1 for failure - */ -typedef int coap_service_response_recv(int8_t service_id, uint16_t msg_id, sn_coap_hdr_s *response_ptr); + * Closes secure connection (if present), but leaves socket open. + * + * \param service_id Id number of the current service. + */ +extern void coap_service_close_secure_connection(int8_t service_id); + +/** + * \brief Sets password for device + * + * \param service_id Service id + * \param address Device address + * \param port Device port + * \param pw_ptr Pointer to password. + * \param pw_len Lenght of password. + * + * \return 0 for success / -1 for failure + */ +//int coap_service_security_key_set(int8_t service_id, uint8_t address[static 16], uint16_t port, uint8_t *pw_ptr, uint8_t pw_len); /** * \brief Virtual socket sent callback. @@ -150,9 +150,9 @@ typedef int coap_service_response_recv(int8_t service_id, uint16_t msg_id, sn_co * \param *data_ptr Pointer to the data. * \param data_len Lenght of the data. * - * \return 0 for success / -1 for failure + * \return 0 for success / -1 for failure */ -typedef int coap_service_virtual_socket_send_cb(int8_t service_id, uint8_t destination_addr_ptr[static 16], uint16_t port, uint8_t *data_ptr, uint16_t data_len); +typedef int coap_service_virtual_socket_send_cb(int8_t service_id, uint8_t destination_addr_ptr[static 16], uint16_t port, const uint8_t *data_ptr, uint16_t data_len); /** * \brief Virtual socket read. @@ -165,9 +165,9 @@ typedef int coap_service_virtual_socket_send_cb(int8_t service_id, uint8_t desti * \param *data_ptr Pointer to the data * \param data_len Lenght of the data * - * \return 0 for success / -1 for failure + * \return 0 for success / -1 for failure */ -int16_t coap_service_virtual_socket_recv(int8_t service_id, uint8_t source_addr_ptr[static 16], uint16_t port, uint8_t *data_ptr, uint16_t data_len); +extern int16_t coap_service_virtual_socket_recv(int8_t service_id, uint8_t source_addr_ptr[static 16], uint16_t port, uint8_t *data_ptr, uint16_t data_len); /** * \brief Set virtual socket @@ -177,9 +177,9 @@ int16_t coap_service_virtual_socket_recv(int8_t service_id, uint8_t source_addr_ * \param service_id Id number of the current service. * \param *send_method_ptr Callback to coap virtual socket. * - * \return 0 for success / -1 for failure + * \return 0 for success / -1 for failure */ -int16_t coap_service_virtual_socket_set_cb(int8_t service_id, coap_service_virtual_socket_send_cb *send_method_ptr); +extern int16_t coap_service_virtual_socket_set_cb(int8_t service_id, coap_service_virtual_socket_send_cb *send_method_ptr); /** * \brief Register unsecure callback methods to CoAP server @@ -192,9 +192,9 @@ int16_t coap_service_virtual_socket_set_cb(int8_t service_id, coap_service_virtu * \param allowed_method Informs method that is allowed to use (used defines described above). * \param *request_recv_cb CoAP service request receive callback function pointer. * - * \return 0 for success / -1 for failure + * \return 0 for success / -1 for failure */ -int8_t coap_service_register_uri(int8_t service_id, const char *uri, uint8_t allowed_method, coap_service_request_recv_cb *request_recv_cb); +extern int8_t coap_service_register_uri(int8_t service_id, const char *uri, uint8_t allowed_method, coap_service_request_recv_cb *request_recv_cb); /** * \brief Unregister unsecure callback methods to CoAP server @@ -204,41 +204,9 @@ int8_t coap_service_register_uri(int8_t service_id, const char *uri, uint8_t all * \param service_id Id number of the current service. * \param *uri Uri address. * - * \return 0 for success / -1 for failure + * \return 0 for success / -1 for failure */ -int8_t coap_service_unregister_uri(int8_t service_id, const char *uri); - - -/** - * \brief Register secure callback methods to CoAP server. - * - * Register application and informs CoAP services secure registery callback functions. - * - * \param service_id Id number of the current service. - * \param *start_ptr Callback to inform security handling is started. - * \param *security_done_cb Callback to inform security handling is done. - * - * \return -1 for failure - * instance_id For success (is used to identify registery) - * - */ -int8_t coap_service_register_uri_secure_cb_set(int8_t service_id, coap_service_security_start_cb *start_ptr, coap_service_security_done_cb *security_done_cb); - -/** - * \brief Sends CoAP service - * - * Build and sends CoAP service message. - * - * \param service_id Id number of the current service. - * \param options Options defined above. - * \param addr IPv6 address. - * \param destination_port Destination port - * \param request_ptr Pointer to CoAP header structure. - * \param *request_response_cb Callback to inform result of the request. - * - * \return msg_id Id number of the current message. - */ -uint16_t coap_service_send(int8_t service_id, uint8_t options, const uint8_t addr[static 16], uint16_t destination_port, sn_coap_hdr_s *request_ptr, coap_service_response_recv *request_response_cb); +extern int8_t coap_service_unregister_uri(int8_t service_id, const char *uri); /** * \brief Sends CoAP service request @@ -259,8 +227,8 @@ uint16_t coap_service_send(int8_t service_id, uint8_t options, const uint8_t add * * \return msg_id Id number of the current message. */ -uint16_t coap_service_request_send(int8_t service_id, uint8_t options, const uint8_t destination_addr[static 16], uint16_t destination_port, uint8_t msg_type, uint8_t msg_code, const char *uri, - uint8_t cont_type, const uint8_t *payload_ptr, uint16_t payload_len, coap_service_response_recv *request_response_cb); +extern uint16_t coap_service_request_send(int8_t service_id, uint8_t options, const uint8_t destination_addr[static 16], uint16_t destination_port, uint8_t msg_type, uint8_t msg_code, const char *uri, + uint8_t cont_type, const uint8_t *payload_ptr, uint16_t payload_len, coap_service_response_recv *request_response_cb); /** * \brief Sends CoAP service response @@ -268,14 +236,14 @@ uint16_t coap_service_request_send(int8_t service_id, uint8_t options, const uin * Build and sends CoAP service response message. * * \param service_id Id number of the current service. - * \param msg_id Message ID number. + * \param msg_id Message ID number. * \param options Options defined above. * \param response_ptr Pointer to CoAP header structure. * - * \return -1 For failure - *- 0 For success + * \return -1 For failure + *- 0 For success */ -int8_t coap_service_response_send(int8_t service_id, uint8_t options, sn_coap_hdr_s *request_ptr, sn_coap_msg_code_e message_code, int32_t content_type, const uint8_t *payload_ptr,uint16_t payload_len); +extern int8_t coap_service_response_send(int8_t service_id, uint8_t options, sn_coap_hdr_s *request_ptr, sn_coap_msg_code_e message_code, int32_t content_type, const uint8_t *payload_ptr,uint16_t payload_len); #ifdef __cplusplus } diff --git a/junit_xsl.xslt b/junit_xsl.xslt new file mode 100644 index 0000000000..7376b27f26 --- /dev/null +++ b/junit_xsl.xslt @@ -0,0 +1,101 @@ + + + + + + + + + +

+ Unittest report +

+ +

+ + Total tests run + , failures: + + + + + +

+
+ + +

+ +

+ + + + + + + + + + + +
Tests runTests failedOther errors
+
+ + + + + + + + +
Tests namePASS/FAILFailing caseReason
+
+ + + + + + + + + + + PASS + + + + + + + FAIL + + + + + + + + + + + + + + + + FAIL + + + + + + + + + + + + + +
\ No newline at end of file diff --git a/module.json b/module.json index 55f3889686..7c4c0da599 100644 --- a/module.json +++ b/module.json @@ -1,12 +1,11 @@ { "name": "coap-service", - "version": "0.0.11", + "version": "1.0.0", "description": "CoAP Service library", "keywords": [ "coap", "service" ], - "author": "Erno Tormikoski ", "repository": { "url": "git@github.com:ARMmbed/coap-service.git", "type": "git" diff --git a/source/coap_connection_handler.c b/source/coap_connection_handler.c new file mode 100644 index 0000000000..39b5b4402d --- /dev/null +++ b/source/coap_connection_handler.c @@ -0,0 +1,679 @@ +/* + * Copyright (c) 2015 ARM Limited. All rights reserved. + */ + +#include +#include "coap_connection_handler.h" +#include "coap_security_handler.h" +#include "ns_list.h" +#include "ns_trace.h" +#include "nsdynmemLIB.h" +#include "socket_api.h" +#include "net_interface.h" +#include "randLIB.h" +#include "eventOS_callback_timer.h" + +#define TRACE_GROUP "ThCH" + +typedef struct internal_socket_s { + thread_conn_handler_t *parent; + + uint16_t listen_port; + int8_t listen_socket; + + ns_address_t dest_addr; + size_t data_len; + uint8_t *data; + + bool real_socket; + uint8_t usage_counter; + bool is_secure; + + bool bypass_link_sec; + + ns_list_link_t link; +} internal_socket_t; + +static NS_LIST_DEFINE(socket_list, internal_socket_t, link); + +static void timer_cb(int8_t timer_id, uint16_t slots); +#define TIMER_FACTOR 20 /* mbedtls timer in ms, our timer in slots (50us), therefore 20 slots per ms */ +#define TIMER_STATE_CANCELLED -1 /* cancelled */ +#define TIMER_STATE_NO_EXPIRY 0 /* none of the delays is expired */ +#define TIMER_STATE_INT_EXPIRY 1 /* the intermediate delay only is expired */ +#define TIMER_STATE_FIN_EXPIRY 2 /* the final delay is expired */ +typedef struct secure_timer_s { + int8_t id; + int8_t state; + uint8_t cycles; + uint8_t cycle_count; +} secure_timer_t; + +typedef struct secure_session { + thread_security_t *sec_handler; //owned + internal_socket_t *parent; //not owned + + secure_timer_t timer; + + bool secure_done; + ns_list_link_t link; +} secure_session_t; + +static NS_LIST_DEFINE(secure_session_list, secure_session_t, link); +static int send_to_socket(int8_t socket_id, uint8_t *address_ptr, uint16_t port, const unsigned char *buf, size_t len); +static int receive_from_socket(int8_t socket_id, unsigned char *buf, size_t len); +static void start_timer(int8_t timer_id, uint32_t int_ms, uint32_t fin_ms); +static int timer_status(int8_t timer_id); + +static secure_session_t *secure_session_create(internal_socket_t *parent, uint8_t *address_ptr, uint16_t port) +{ + secure_session_t *this = ns_dyn_mem_alloc(sizeof(secure_session_t)); + if (!this || !address_ptr) { + return NULL; + } + memset(this, 0, sizeof(secure_session_t)); + + this->timer.id = eventOS_callback_timer_register(timer_cb); + if (this->timer.id == -1) { + tr_error("tasklet alloc failed"); + ns_dyn_mem_free(this); + return NULL; + } + + this->sec_handler = thread_security_create(parent->listen_socket, this->timer.id, address_ptr, port, &send_to_socket, + &receive_from_socket, &start_timer, &timer_status); + if( !this->sec_handler ){ + ns_dyn_mem_free(this); + return NULL; + } + this->parent = parent; + + this->secure_done = false; + ns_list_add_to_start(&secure_session_list, this); +// hack_save_remote_address(address_ptr, port); //TODO not bad hack + return this; +} + +static void secure_session_delete(secure_session_t *this) +{ + if (this) { + ns_list_remove(&secure_session_list, this); + if( this->sec_handler ){ + thread_security_destroy(this->sec_handler); + this->sec_handler = NULL; + } + ns_dyn_mem_free(this); + this = NULL; + } + + return; +} + +static void clear_secure_sessions(internal_socket_t *this){ + if( this ){ + ns_list_foreach_safe(secure_session_t, cur_ptr, &secure_session_list) { + if( cur_ptr->parent == this ){ + secure_session_delete(cur_ptr); + } + } + } +} + +static secure_session_t *secure_session_find_by_timer_id(int8_t timer_id) +{ + secure_session_t *this = NULL; + ns_list_foreach(secure_session_t, cur_ptr, &secure_session_list) { + if (cur_ptr->timer.id == timer_id) { + this = cur_ptr; + break; + } + } + return this; +} + +static secure_session_t *secure_session_find(internal_socket_t *parent, uint8_t *address_ptr, uint16_t port) +{ + secure_session_t *this = NULL; + ns_list_foreach(secure_session_t, cur_ptr, &secure_session_list) { + if( cur_ptr->sec_handler ){ + if (cur_ptr->parent == parent && cur_ptr->sec_handler->_remote_port == port && + memcmp(cur_ptr->sec_handler->_remote_address, address_ptr, 16) == 0) { + this = cur_ptr; + // hack_save_remote_address(address_ptr, port); + break; + } + } + } + return this; +} + + + +static void recv_sckt_msg(void *cb_res); +static void secure_recv_sckt_msg(void *cb_res); + +static internal_socket_t *int_socket_create(uint16_t listen_port, bool use_ephemeral_port, bool is_secure, bool real_socket, bool bypassSec) +{ + internal_socket_t *this = ns_dyn_mem_alloc(sizeof(internal_socket_t)); + if (!this) { + return NULL; + } + memset(this, 0, sizeof(internal_socket_t)); + + this->data_len = 0; + this->data = NULL; + + this->is_secure = is_secure; + this->usage_counter = 1; + + this->listen_port = listen_port; + this->real_socket = real_socket; + this->bypass_link_sec = bypassSec; + this->listen_socket = -1; + if( real_socket ){ + if( use_ephemeral_port ){ //socket_api creates ephemeral port if the one provided is 0 + listen_port = 0; + } + if( !is_secure ){ + this->listen_socket = socket_open(SOCKET_UDP, listen_port, recv_sckt_msg); + }else{ + this->listen_socket = socket_open(SOCKET_UDP, listen_port, secure_recv_sckt_msg); + } + // XXX API for this? May want to get clever to do recommended first query = 1 hop, retries = whole PAN + socket_setsockopt(this->listen_socket, SOCKET_IPPROTO_IPV6, SOCKET_IPV6_MULTICAST_HOPS, &(const int16_t) { + 16 + }, sizeof(int16_t)); + }else{ + this->listen_socket = -1; + } + + ns_list_add_to_start(&socket_list, this); + return this; +} + +static void int_socket_delete(internal_socket_t *this) +{ + if (this) { + this->usage_counter--; + if(this->usage_counter == 0){ + clear_secure_sessions(this); + ns_list_remove(&socket_list, this); + if( this->data ){ + ns_dyn_mem_free(this->data); + this->data = NULL; + } + ns_dyn_mem_free(this); + this = NULL; + } + } + + return; +} + +static internal_socket_t *int_socket_find_by_socket_id(int8_t id) +{ + internal_socket_t *this = NULL; + ns_list_foreach(internal_socket_t, cur_ptr, &socket_list) { + if( cur_ptr->listen_socket == id ) { + this = cur_ptr; + break; + } + } + return this; +} + +static internal_socket_t *int_socket_find(uint16_t port, bool is_secure, bool is_real_socket, bool bypassSec) +{ + internal_socket_t *this = NULL; + ns_list_foreach(internal_socket_t, cur_ptr, &socket_list) { + if( cur_ptr->listen_port == port && cur_ptr->real_socket == is_real_socket && + is_secure == cur_ptr->is_secure /*&& bypass_link_sec == bypassSec*/) { + this = cur_ptr; + break; + } + } + return this; +} + +static int send_to_socket(int8_t socket_id, uint8_t *address_ptr, uint16_t port, const unsigned char *buf, size_t len) +{ + internal_socket_t *sock = int_socket_find_by_socket_id(socket_id); + if(!sock){ + return -1; + } + if(!sock->real_socket){ + //In this case all clients will have socket_id -1 and socket will not have a real address + //so sock->dest_addr cannot be used here + int ret = sock->parent->_send_cb(sock->listen_socket, address_ptr, port, buf, len); + if( ret < 0 ) + return ret; + return len; + } + + int opt_name = SOCKET_IPV6_PREFER_SRC_6LOWPAN_SHORT; + int8_t securityLinkLayer = 1; + if( sock->bypass_link_sec ){ + securityLinkLayer = 0; + } + socket_setsockopt(sock->listen_socket, SOCKET_IPPROTO_IPV6, SOCKET_IPV6_ADDR_PREFERENCES, &opt_name, sizeof(int)); + socket_setsockopt(sock->listen_socket, SOCKET_IPPROTO_IPV6, SOCKET_LINK_LAYER_SECURITY, &securityLinkLayer, sizeof(int8_t)); + //For some reason socket_sendto returns 0 in success, while other socket impls return number of bytes sent!!! + int ret = socket_sendto(sock->listen_socket, &sock->dest_addr, (unsigned char*)buf, len); + if( ret < 0 ) + return ret; + return len; +} + +static int receive_from_socket(int8_t socket_id, unsigned char *buf, size_t len) +{ + internal_socket_t *sock = int_socket_find_by_socket_id(socket_id); + if( sock->data && sock->data_len > 0 ){ + memcpy( buf, sock->data, sock->data_len ); + int l = sock->data_len; + ns_dyn_mem_free(sock->data); + sock->data = NULL; + sock->data_len = 0; + return l; + } + return MBEDTLS_ERR_SSL_WANT_READ; +} + +/** + * Callback timer. Maybe called in interrupt context + * so keep it simple. + * TODO - might be better to use an event timer in conjunction with + * CoAP tasklet + */ +static void timer_cb(int8_t timer_id, uint16_t slots) +{ + (void)slots; /* No need to look at slots */ + + secure_session_t *sec = secure_session_find_by_timer_id(timer_id); + if( sec ){ + if (++sec->timer.cycle_count == sec->timer.cycles) { + /* We have counted the number of cycles - finish */ + sec->timer.state = TIMER_STATE_FIN_EXPIRY; + /* Stop the timer as we no longer need it */ + (void)eventOS_callback_timer_stop(sec->timer.id); /* We can ignore return; ID is valid */ + int error = coap_security_handler_continue_connecting(sec->sec_handler); + if(MBEDTLS_ERR_SSL_TIMEOUT == error) { + //TODO: How do we handle timeouts? + secure_session_delete(sec); + } + } else { + /* Intermediate expiry */ + sec->timer.state = TIMER_STATE_INT_EXPIRY; + } + } +} + +static void start_timer(int8_t timer_id, uint32_t int_ms, uint32_t fin_ms) +{ + secure_session_t *sec = secure_session_find_by_timer_id(timer_id); + if( sec ){ + if ((int_ms > 0) && (fin_ms > 0)) { + /* Note: as it stands, fin_ms is always 4 * int_ms, so cycles is always 4 but this may change */ + sec->timer.cycles = fin_ms/int_ms; + sec->timer.cycle_count = 0; + sec->timer.state = TIMER_STATE_NO_EXPIRY; + eventOS_callback_timer_start(sec->timer.id, int_ms * TIMER_FACTOR); + } else if (fin_ms == 0) { + /* fin_ms == 0 means cancel the timer */ + sec->timer.state = TIMER_STATE_CANCELLED; + (void)eventOS_callback_timer_stop(sec->timer.id); /* We can ignore return; ID will be valid */ + } + } +} + +static int timer_status(int8_t timer_id) +{ + secure_session_t *sec = secure_session_find_by_timer_id(timer_id); + if( sec ){ + return (int)sec->timer.state; + } + return TIMER_STATE_CANCELLED; +} + +static int read_data(socket_callback_t *sckt_data, internal_socket_t *sock, ns_address_t *src_address) +{ + sock->data_len = 0; + if (sckt_data->event_type == SOCKET_DATA && sckt_data->d_len > 0) { + if( sock->data ){ + ns_dyn_mem_free(sock->data); + sock->data = NULL; + } + sock->data = ns_dyn_mem_temporary_alloc(sckt_data->d_len); + if( !sock->data ){ + sock->data = NULL; + return -1; + } + sock->data_len = socket_read(sckt_data->socket_id, src_address, sock->data, sckt_data->d_len); + } + if( sock->data_len < 1){ + ns_dyn_mem_free(sock->data); + sock->data = NULL; + sock->data_len = 0; + return -1; + } + return 0; +} + +static void secure_recv_sckt_msg(void *cb_res) +{ + socket_callback_t *sckt_data = cb_res; + internal_socket_t *sock = int_socket_find_by_socket_id(sckt_data->socket_id); + ns_address_t src_address; + + if( sock && read_data(sckt_data, sock, &src_address) == 0 ){ + secure_session_t *session = secure_session_find(sock, src_address.address, src_address.identifier); + if( !session ){ + memcpy( sock->dest_addr.address, src_address.address, 16 ); + sock->dest_addr.identifier = src_address.identifier; + sock->dest_addr.type = src_address.type; + session = secure_session_create(sock, src_address.address, src_address.identifier); + } + + if( !session ){ + tr_err("secure_recv_sckt_msg session creation failed - OOM"); + return; + } + if( !session->sec_handler->_is_started ){ + uint8_t *pw = (uint8_t *)ns_dyn_mem_alloc(64); + uint8_t pw_len; + if( sock->parent->_get_password_cb && 0 == sock->parent->_get_password_cb(sock->listen_socket, src_address.address, src_address.identifier, pw, &pw_len)){ + int ret = coap_security_handler_connect(session->sec_handler, true, pw, pw_len); + //TODO: error handling + } + ns_dyn_mem_free(pw); + }else{ + if( !session->secure_done ){ + if( coap_security_handler_continue_connecting(session->sec_handler) == 0){ + session->secure_done = true; + if( sock->parent->_security_done_cb ){ + sock->parent->_security_done_cb(sock->listen_socket, src_address.address, + src_address.identifier, + session->sec_handler->_keyblk.value); + } + } + //TODO: error handling + }else{ + unsigned char *data = ns_dyn_mem_temporary_alloc(sock->data_len); + int len = 0; + len = coap_security_handler_read(session->sec_handler, data, sock->data_len); + if( len < 0 ){ + ns_dyn_mem_free(data); + if( len == MBEDTLS_ERR_SSL_PEER_CLOSE_NOTIFY ){ +// if( sock->parent->sec_conn_closed_cb ){ +// sock->parent->sec_conn_closed_cb(sock->listen_socket); + secure_session_delete( session ); +// } + } + }else{ + if( sock->parent->_recv_cb ){ + sock->parent->_recv_cb(sock->listen_socket, src_address.address, src_address.identifier, data, len); + } + ns_dyn_mem_free(data); + } + } + } + } +} + +static void recv_sckt_msg(void *cb_res) +{ + socket_callback_t *sckt_data = cb_res; + internal_socket_t *sock = int_socket_find_by_socket_id(sckt_data->socket_id); + ns_address_t src_address; + if( sock && read_data(sckt_data, sock, &src_address) == 0 ){ + if( sock->parent->_recv_cb ){ + sock->parent->_recv_cb(sock->listen_socket, src_address.address, src_address.identifier, sock->data, sock->data_len); + } + ns_dyn_mem_free(sock->data); + sock->data = NULL; + } +} + +int coap_connection_handler_virtual_recv(thread_conn_handler_t *handler, uint8_t address[static 16], uint16_t port, uint8_t *data_ptr, uint16_t data_len) +{ + if( !handler || !handler->socket ){ + return -1; + } + internal_socket_t *sock = handler->socket; + sock->data_len = data_len; + if( sock->data ){ + ns_dyn_mem_free(sock->data); + sock->data = NULL; + } + sock->data = ns_dyn_mem_temporary_alloc(data_len); + if( data_len > 0 && !sock->data ){ + return -1; + } + if( data_ptr ){ + memcpy(sock->data, data_ptr, data_len); + }else{ + if( sock->data ){ + ns_dyn_mem_free(sock->data); + sock->data = NULL; + } + } + + if( handler->socket->is_secure ){ + secure_session_t *session = secure_session_find(sock, address, port); + if( !session ){ + session = secure_session_create(sock, address, port); + } + if( !session ){ + tr_err("coap_connection_handler_virtual_recv session creation failed - OOM"); + return -1; + } + if( !session->sec_handler->_is_started ){ + uint8_t *pw = (uint8_t *)ns_dyn_mem_alloc(64); + uint8_t pw_len; + if( sock->parent->_get_password_cb && 0 == sock->parent->_get_password_cb(sock->listen_socket, address, port, pw, &pw_len)){ + int ret = coap_security_handler_connect(session->sec_handler, true, pw, pw_len); + //TODO: error handling + ns_dyn_mem_free(pw); + return 0; + }else{ + ns_dyn_mem_free(pw); + return -1; + } + }else{ + if( !session->secure_done ){ + if( coap_security_handler_continue_connecting(session->sec_handler) == 0){ + session->secure_done = true; + if( handler->_security_done_cb ){ + handler->_security_done_cb(sock->listen_socket, + address, port, + session->sec_handler->_keyblk.value); + } + return 0; + } + //TODO: error handling + }else{ + unsigned char *data = ns_dyn_mem_temporary_alloc(sock->data_len); + int len = 0; + len = coap_security_handler_read(session->sec_handler, data, sock->data_len); + if( len < 0 ){ + ns_dyn_mem_free(data); + if( len == MBEDTLS_ERR_SSL_PEER_CLOSE_NOTIFY ){ +// if( sock->parent->sec_conn_closed_cb ){ +// sock->parent->sec_conn_closed_cb(sock->listen_socket, address, port); + secure_session_delete( session ); + return 0; +// } + } + }else{ + if( sock->parent->_recv_cb ){ + sock->parent->_recv_cb(sock->listen_socket, address, port, data, len); + } + ns_dyn_mem_free(data); + data = NULL; + } + return 0; + } + } + }else{ + if( sock->parent->_recv_cb ){ + sock->parent->_recv_cb(sock->listen_socket, address, port, sock->data, sock->data_len); + } + if( sock->data ){ + ns_dyn_mem_free(sock->data); + sock->data = NULL; + } + return 0; + } + return -1; +} + +thread_conn_handler_t *connection_handler_create(receive_from_socket_cb *recv_from_cb, + send_to_socket_cb *send_to_cb, + get_pw_cb *pw_cb, + security_done_cb *done_cb ) +{ + if( recv_from_cb == NULL ){ + return NULL; + } + + thread_conn_handler_t *handler = ns_dyn_mem_alloc(sizeof(thread_conn_handler_t)); + if(!handler){ + return NULL; + } + memset(handler, 0, sizeof(thread_conn_handler_t)); + handler->socket = NULL; + handler->_recv_cb = recv_from_cb; + handler->_send_cb = send_to_cb; + +// handler->sec_conn_closed_cb = sec_conn_closed_cb; + handler->_get_password_cb = pw_cb; + handler->_security_done_cb = done_cb; + + return handler; +} + +void connection_handler_destroy(thread_conn_handler_t *handler) +{ + if(handler){ + if( handler->socket && handler->socket->is_secure){ + //If nothing is sent, there is no address to find. + //This case is handled in int_socket_delete. + secure_session_t *session = secure_session_find( handler->socket, handler->socket->dest_addr.address, + handler->socket->dest_addr.identifier); + + if( session && handler->socket->usage_counter == 1){ //Last connection + thread_security_send_close_alert( session->sec_handler ); + } + + if( session){ + secure_session_delete(session); + } + } + int_socket_delete(handler->socket); + handler->socket = NULL; + ns_dyn_mem_free(handler); + } +} + +void connection_handler_close_secure_connection( thread_conn_handler_t *handler ) +{ + if(handler){ + if( handler->socket && handler->socket->is_secure){ + secure_session_t *session = secure_session_find( handler->socket, handler->socket->dest_addr.address, + handler->socket->dest_addr.identifier); + if( session ){ + thread_security_send_close_alert( session->sec_handler ); + } + } + } +} + +int coap_connection_handler_open_connection(thread_conn_handler_t *handler, uint16_t listen_port, bool use_ephemeral_port, bool is_secure, bool is_real_socket, bool bypassSec) +{ + if( !handler ){ + return -1; + } + //virtual socket must have send callback + if( !is_real_socket && !handler->_send_cb ){ + return -1; + } + if( handler->socket ){ + int_socket_delete(handler->socket); + } + + internal_socket_t *current = !use_ephemeral_port?int_socket_find(listen_port, is_secure, is_real_socket, bypassSec):NULL; + if(!current){ + handler->socket = int_socket_create(listen_port, use_ephemeral_port, is_secure, is_real_socket, bypassSec); + if( !handler->socket ){ + return -1; + } + handler->socket->parent = handler; + }else{ + current->usage_counter++; + handler->socket = current; + //handler->parent cannot be set here! + //this will be always problematic if 2 or more secure sockets try to share a same port! + } + return 0; +} + +int coap_connection_handler_send_data(thread_conn_handler_t *handler, ns_address_t *dest_addr, uint8_t *data_ptr, uint16_t data_len, bool bypass_link_sec) +{ + if( !handler || !handler->socket || !dest_addr){ + return -1; + } + if(handler->socket->is_secure){ + handler->socket->bypass_link_sec = bypass_link_sec; + memcpy(handler->socket->dest_addr.address, dest_addr->address, 16); + handler->socket->dest_addr.identifier = dest_addr->identifier; + handler->socket->dest_addr.type = dest_addr->type; + secure_session_t *session = secure_session_find( handler->socket, dest_addr->address, dest_addr->identifier); + if( !session ){ + session = secure_session_create(handler->socket, dest_addr->address, dest_addr->identifier); + if( !session ){ + return -1; + } + memcpy( handler->socket->dest_addr.address, dest_addr->address, 16 ); + handler->socket->dest_addr.identifier = dest_addr->identifier; + handler->socket->dest_addr.type = dest_addr->type; + uint8_t *pw = (uint8_t *)ns_dyn_mem_alloc(64); + uint8_t pw_len; + if( handler->_get_password_cb && 0 == handler->_get_password_cb(handler->socket->listen_socket, dest_addr->address, dest_addr->identifier, pw, &pw_len)){ + coap_security_handler_connect(session->sec_handler, false, pw, pw_len); + ns_dyn_mem_free(pw); + return -2; + }else{ + ns_dyn_mem_free(pw); + return -1; + } + }else if( session->secure_done ){ + if( coap_security_handler_send_message(session->sec_handler, data_ptr, data_len ) > 0 ){ + return 0; + } + } + return -1; + }else{ + if( !handler->socket->real_socket && handler->_send_cb){ + return handler->_send_cb((int8_t)handler->socket->listen_socket, dest_addr->address, dest_addr->identifier, data_ptr, data_len); + } + int opt_name = SOCKET_IPV6_PREFER_SRC_6LOWPAN_SHORT; + int8_t securityLinkLayer = 1; + if( bypass_link_sec ){ + securityLinkLayer = 0; + } + socket_setsockopt(handler->socket->listen_socket, SOCKET_IPPROTO_IPV6, SOCKET_IPV6_ADDR_PREFERENCES, &opt_name, sizeof(int)); + socket_setsockopt(handler->socket->listen_socket, SOCKET_IPPROTO_IPV6, SOCKET_LINK_LAYER_SECURITY, &securityLinkLayer, sizeof(int8_t)); + return socket_sendto(handler->socket->listen_socket, dest_addr, data_ptr, data_len); + } +} + +bool coap_connection_handler_socket_belongs_to(thread_conn_handler_t *handler, int8_t socket_id) +{ + if( !handler || !handler->socket){ + return false; + } + + if( handler->socket->listen_socket == socket_id){ + return true; + } + return false; +} diff --git a/source/coap_message_handler.c b/source/coap_message_handler.c new file mode 100644 index 0000000000..19c3981c72 --- /dev/null +++ b/source/coap_message_handler.c @@ -0,0 +1,372 @@ +/* + * Copyright (c) 2015 ARM Limited. All rights reserved. + */ + +#include +#include "nsdynmemLIB.h" +#include "coap_message_handler.h" +#include "sn_coap_protocol.h" +#include "ns_types.h" +#include "ns_list.h" +#include "ns_trace.h" + +#define TRACE_GROUP "CoSA" + +static void *own_alloc(uint16_t size) +{ + if (size) { + return ns_dyn_mem_temporary_alloc(size); + } else { + return 0; + } +} + +static void own_free(void *ptr) +{ + if (ptr) { + ns_dyn_mem_free(ptr); + } +} + +static NS_LIST_DEFINE(request_list, coap_transaction_t, link); + +static coap_transaction_t *transaction_find_client(uint16_t msg_id) +{ + coap_transaction_t *this = NULL; + ns_list_foreach(coap_transaction_t, cur_ptr, &request_list) { + if (cur_ptr->msg_id == msg_id && cur_ptr->client_request) { + this = cur_ptr; + break; + } + } + return this; +} +static coap_transaction_t *transaction_find_server(uint16_t msg_id) +{ + coap_transaction_t *this = NULL; + ns_list_foreach(coap_transaction_t, cur_ptr, &request_list) { + if (cur_ptr->msg_id == msg_id && !cur_ptr->client_request) { + this = cur_ptr; + break; + } + } + return this; +} + +static coap_transaction_t *transaction_find_by_address(uint8_t *address_ptr, uint16_t port) +{ + coap_transaction_t *this = NULL; + ns_list_foreach(coap_transaction_t, cur_ptr, &request_list) { + if (cur_ptr->remote_port == port && memcmp(cur_ptr->remote_address, address_ptr, 16) == 0) { + this = cur_ptr; + break; + } + } + return this; +} + +static coap_transaction_t *transaction_create(void) +{ + coap_transaction_t *this = ns_dyn_mem_alloc(sizeof(coap_transaction_t)); + if (this) { + memset(this, 0, sizeof(coap_transaction_t)); + this->client_request = true;// default to client initiated method + ns_list_add_to_start(&request_list, this); + } + + return this; +} +static void transaction_delete(coap_transaction_t *this) +{ + if (this) { + ns_list_remove(&request_list, this); + ns_dyn_mem_free(this); + } + + return; +} + +static int8_t coap_rx_function(sn_coap_hdr_s *resp_ptr, sn_nsdl_addr_s *address_ptr, void *param) +{ + coap_transaction_t *this; + (void)address_ptr; + (void)param; + tr_warn("transaction was not handled"); + if (!resp_ptr) { + return -1; + } + //TODO: IOTCLT-294 & 295 here. + this = transaction_find_client(resp_ptr->msg_id); + if (this && this->resp_cb) { + this->resp_cb(this->service_id, resp_ptr->msg_id, NULL); + } + transaction_delete(this); + return 0; +} + +static void coap_service_build_content_format(sn_coap_hdr_s *header, sn_coap_content_format_e format); + +coap_msg_handler_t *coap_message_handler_init(void *(*used_malloc_func_ptr)(uint16_t), void (*used_free_func_ptr)(void *), + uint8_t (*used_tx_callback_ptr)(uint8_t *, uint16_t, sn_nsdl_addr_s *, void *)){ + + if ((used_malloc_func_ptr == NULL) || (used_free_func_ptr == NULL) || (used_tx_callback_ptr == NULL)) { + return NULL; + } + + coap_msg_handler_t *handle; + handle = used_malloc_func_ptr(sizeof(coap_msg_handler_t)); + if (handle == NULL) { + return NULL; + } + + memset(handle, 0, sizeof(coap_msg_handler_t)); + + handle->sn_coap_tx_callback = used_tx_callback_ptr; + + handle->sn_coap_service_free = used_free_func_ptr; + handle->sn_coap_service_malloc = used_malloc_func_ptr; + + handle->coap = sn_coap_protocol_init(used_malloc_func_ptr, used_free_func_ptr, used_tx_callback_ptr, &coap_rx_function); + if( !handle->coap ){ + used_free_func_ptr(handle); + return NULL; + } + return handle; +} + +int8_t coap_message_handler_destroy(coap_msg_handler_t *handle){ + if( !handle ){ + return -1; + } + + if( handle->coap ){ + sn_coap_protocol_destroy(handle->coap); + } + + //Destroy transactions + ns_list_foreach_safe(coap_transaction_t, cur_ptr, &request_list) { + ns_list_remove(&request_list, cur_ptr); + ns_dyn_mem_free(cur_ptr); + cur_ptr = NULL; + } + + handle->sn_coap_service_free(handle); + return 0; +} + +coap_transaction_t *coap_message_handler_find_transaction(uint8_t *address_ptr, uint16_t port) +{ + if( !address_ptr ) + return NULL; + return transaction_find_by_address( address_ptr, port ); +} + +int16_t coap_message_handler_coap_msg_process(coap_msg_handler_t *handle, int8_t socket_id, uint8_t source_addr_ptr[static 16], uint16_t port, + uint8_t *data_ptr, uint16_t data_len, int16_t (cb)(int8_t, sn_coap_hdr_s *, coap_transaction_t *)) +{ + if( !cb || !handle ){ + return -1; + } + sn_nsdl_addr_s src_addr; + sn_coap_hdr_s *coap_message; + src_addr.addr_ptr = source_addr_ptr; + src_addr.addr_len = 16; + src_addr.type = SN_NSDL_ADDRESS_TYPE_IPV6; + src_addr.port = port; + + coap_message = sn_coap_protocol_parse(handle->coap, &src_addr, data_len, data_ptr, NULL); + if (coap_message == NULL) { + tr_err("CoAP Parsing failed"); + return -1; + } + tr_debug("CoAP status:%d, type:%d, code:%d, id:%d", coap_message->coap_status, coap_message->msg_type, coap_message->msg_code, coap_message->msg_id); + /* Check, if coap itself sends response, or block receiving is ongoing... */ + if (coap_message->coap_status != COAP_STATUS_OK && coap_message->coap_status != COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED) { + tr_debug("CoAP library responds"); + sn_coap_parser_release_allocated_coap_msg_mem(handle->coap, coap_message); + return -1; + } + if (coap_message->msg_code > 0 && coap_message->msg_code < 32) { + + //TODO Sorry + + coap_transaction_t *transaction_ptr = transaction_create(); + if (transaction_ptr) { + + transaction_ptr->msg_id = coap_message->msg_id; + transaction_ptr->client_request = false;// this is server transaction + memcpy(transaction_ptr->remote_address, source_addr_ptr, 16); + transaction_ptr->remote_port = port; + + int ret = cb(socket_id, coap_message, transaction_ptr); + if (ret != 0) { + tr_debug("Service %d, no response expected", transaction_ptr->service_id); + sn_coap_parser_release_allocated_coap_msg_mem(handle->coap, coap_message); + transaction_delete(transaction_ptr); + return -1; + } + }else{ + //TODO: handle error case + } + } else { + //response find by MSG id + coap_transaction_t *this = transaction_find_client(coap_message->msg_id); + if (!this) { + tr_error("client transaction not found"); + sn_coap_parser_release_allocated_coap_msg_mem(handle->coap, coap_message); + return -1; + } + tr_debug("Service %d, response received", this->service_id); + if (this->resp_cb) { + this->resp_cb(this->service_id, coap_message->msg_id, coap_message); + } + sn_coap_parser_release_allocated_coap_msg_mem(handle->coap, coap_message); + transaction_delete(this); + } + return 0; + +} + +uint16_t coap_message_handler_request_send(coap_msg_handler_t *handle, int8_t service_id, uint8_t options, const uint8_t destination_addr[static 16], + uint16_t destination_port, uint8_t msg_type, uint8_t msg_code, const char *uri, + uint8_t cont_type, const uint8_t *payload_ptr, uint16_t payload_len, coap_message_handler_response_recv *request_response_cb) +{ + coap_transaction_t *transaction_ptr; + sn_coap_hdr_s request; + sn_nsdl_addr_s dst_addr; + uint16_t data_len; + uint8_t *data_ptr; + + tr_debug("Service %d, send CoAP request payload_len %d", service_id, payload_len); + transaction_ptr = transaction_create(); + + if (!uri || !transaction_ptr) { + return 0; + } + + transaction_ptr->service_id = service_id; + transaction_ptr->client_request = true; + transaction_ptr->resp_cb = request_response_cb; + transaction_ptr->options = options; + memcpy(transaction_ptr->remote_address, destination_addr, 16); + transaction_ptr->remote_port = destination_port; + memset(&request, 0, sizeof(request)); + dst_addr.addr_ptr = (uint8_t *) destination_addr; // Cast away const and trust that nsdl doesn't modify... + dst_addr.addr_len = 16; + dst_addr.type = SN_NSDL_ADDRESS_TYPE_IPV6; + dst_addr.port = destination_port; + + request.msg_type = msg_type; + request.msg_code = msg_code; + request.uri_path_ptr = (uint8_t *)uri; + request.uri_path_len = strlen(uri); + coap_service_build_content_format(&request, cont_type); + //TODO: check validity of request.content_type_ptr + + request.payload_len = payload_len; + request.payload_ptr = (uint8_t *) payload_ptr; // Cast away const and trust that nsdl doesn't modify... + data_len = sn_coap_builder_calc_needed_packet_data_size(&request); + data_ptr = own_alloc(data_len); + if(data_len > 0 && !data_ptr){ + own_free(request.content_type_ptr); + transaction_delete(transaction_ptr); + return 0; + } + sn_coap_protocol_build(handle->coap, &dst_addr, data_ptr, &request, transaction_ptr); + transaction_ptr->msg_id = request.msg_id; + handle->sn_coap_tx_callback(data_ptr, data_len, &dst_addr, transaction_ptr); + + // Free allocated data + own_free(request.content_type_ptr); + own_free(data_ptr); + if(request_response_cb == NULL){ + //No response expected + transaction_delete(transaction_ptr); + return 0; + } + return transaction_ptr->msg_id; +} + +//TODO: refactor this to use nsdl +int8_t coap_message_handler_response_send(coap_msg_handler_t *handle, int8_t service_id, uint8_t options, sn_coap_hdr_s *request_ptr, sn_coap_msg_code_e message_code, int32_t content_type, const uint8_t *payload_ptr, uint16_t payload_len) +{ + coap_transaction_t *transaction_ptr; + sn_coap_hdr_s *response; + sn_nsdl_addr_s dst_addr; + uint16_t data_len; + uint8_t *data_ptr; + (void) options; + + tr_debug("Service %d, send CoAP response", service_id); + if (!request_ptr || !handle) { + tr_error("invalid params"); + return -1; + } + + transaction_ptr = transaction_find_server(request_ptr->msg_id); + + if (!transaction_ptr) { + tr_error("response transaction not found"); + return -2; + } + dst_addr.addr_ptr = transaction_ptr->remote_address; + dst_addr.addr_len = 16; + dst_addr.type = SN_NSDL_ADDRESS_TYPE_IPV6; + dst_addr.port = transaction_ptr->remote_port; + + response = sn_coap_build_response(handle->coap, request_ptr, message_code); + if( !response ){ + return -1; + } + response->payload_len = payload_len; + response->payload_ptr = (uint8_t *) payload_ptr; // Cast away const and trust that nsdl doesn't modify... + coap_service_build_content_format(response, content_type); + + data_len = sn_coap_builder_calc_needed_packet_data_size(response); + data_ptr = own_alloc(data_len); + if (data_len > 0 && !data_ptr) { + sn_coap_parser_release_allocated_coap_msg_mem(handle->coap, response); + //TODO deallocate stuff i quess + return -1; + } + sn_coap_protocol_build(handle->coap, &dst_addr, data_ptr, response, transaction_ptr); + sn_coap_parser_release_allocated_coap_msg_mem(handle->coap, response); + handle->sn_coap_tx_callback(data_ptr, data_len, &dst_addr, transaction_ptr); + sn_coap_parser_release_allocated_coap_msg_mem(handle->coap, request_ptr); + transaction_delete(transaction_ptr); + own_free(data_ptr); + return 0; +} + +int8_t coap_message_handler_exec(coap_msg_handler_t *handle, uint32_t current_time){ + if( !handle ){ + return -1; + } + return sn_coap_protocol_exec(handle->coap, current_time); +} + +static void coap_service_build_content_format(sn_coap_hdr_s *header, sn_coap_content_format_e format) +{ + if (format == COAP_CT_NONE) { + return; + } + + /* Always alloc - CoAP library needs a non-NULL pointer to trigger writing + * of a zero-length option, and it will free the pointer later. + */ + header->content_type_ptr = own_alloc(2); + if (!header->content_type_ptr) { + return; + } + + if (format == 0) { /* text/plain */ + header->content_type_len = 0; + } else if (format <= 0xff) { + header->content_type_ptr[0] = format; + header->content_type_len = 1; + } else { + header->content_type_ptr[0] = format >> 8; + header->content_type_ptr[1] = format & 0xff; + header->content_type_len = 2; + } +} diff --git a/source/coap_security_handler.c b/source/coap_security_handler.c new file mode 100644 index 0000000000..fd8a99dadd --- /dev/null +++ b/source/coap_security_handler.c @@ -0,0 +1,396 @@ +/* + * Copyright (c) 2015 ARM Limited. All rights reserved. + */ + +#include +#include +#include + +#include "mbedtls/sha256.h" +#include "mbedtls/error.h" +#include "mbedtls/ssl_cookie.h" +#include "mbedtls/entropy_poll.h" +#include "ns_trace.h" +#include "nsdynmemLIB.h" +#include "coap_connection_handler.h" +#include "coap_security_handler.h" +#include "randLIB.h" +#include "mbedtls/ssl_ciphersuites.h" + + +const static int PSK_SUITES[] = { + MBEDTLS_TLS_ECJPAKE_WITH_AES_128_CCM_8, + 0 +}; + + +static void set_timer( void *sec_obj, uint32_t int_ms, uint32_t fin_ms ); +static int get_timer( void *sec_obj ); + +int entropy_poll( void *data, unsigned char *output, size_t len, size_t *olen ); +//Point these back to M2MConnectionHandler!!! +int f_send( void *ctx, const unsigned char *buf, size_t len ); +int f_recv(void *ctx, unsigned char *buf, size_t len); + +static int coap_security_handler_init(thread_security_t *sec){ + const char *pers = "dtls_client"; + mbedtls_ssl_init( &sec->_ssl ); + mbedtls_ssl_config_init( &sec->_conf ); + mbedtls_ctr_drbg_init( &sec->_ctr_drbg ); + mbedtls_entropy_init( &sec->_entropy ); + + memset(&sec->_cookie, 0, sizeof(simple_cookie_t)); + memset(&sec->_keyblk, 0, sizeof(key_block_t)); + + sec->_is_started = false; + + if( mbedtls_entropy_add_source( &sec->_entropy, entropy_poll, NULL, + 128, 0 ) < 0 ){ + return -1; + } + + if( ( mbedtls_ctr_drbg_seed( &sec->_ctr_drbg, mbedtls_entropy_func, &sec->_entropy, + (const unsigned char *) pers, + strlen( pers ) ) ) != 0 ) + { + return -1; + } + return 0; +} + +static void coap_security_handler_reset(thread_security_t *sec){ + mbedtls_entropy_free( &sec->_entropy ); + mbedtls_ctr_drbg_free( &sec->_ctr_drbg ); + mbedtls_ssl_config_free(&sec->_conf); + mbedtls_ssl_free(&sec->_ssl); +} + + +thread_security_t *thread_security_create(int8_t socket_id, int8_t timer_id, uint8_t *address_ptr, uint16_t port, + send_cb *send_cb, + receive_cb *receive_cb, + start_timer_cb *start_timer_cb, + timer_status_cb *timer_status_cb) +{ + if( !address_ptr || send_cb == NULL || receive_cb == NULL || start_timer_cb == NULL || timer_status_cb == NULL){ + return NULL; + } + thread_security_t *this = ns_dyn_mem_alloc(sizeof(thread_security_t)); + if( !this ){ + return NULL; + } + if( -1 == coap_security_handler_init(this) ){ + ns_dyn_mem_free(this); + return NULL; + } + this->_remote_port = port; + memcpy(this->_remote_address, address_ptr, 16); + this->_socket_id = socket_id; + this->_timer_id = timer_id; + this->_send_cb = send_cb; + this->_receive_cb = receive_cb; + this->_start_timer_cb = start_timer_cb; + this->_timer_status_cb = timer_status_cb; + + return this; +} + +void thread_security_destroy(thread_security_t *sec){ + if( sec ){ + coap_security_handler_reset(sec); + ns_dyn_mem_free(sec); + sec = NULL; + } +} + +/**** Random number functions ****/ + +/** + * Get a random array of bytes. + * Called back by mbedtls when it wants to fill a buffer with random data + * Must return 0 on success. + */ +static int get_random(void *ctx, unsigned char *buf, size_t len) +{ + static int initialised = 0; + uint32_t i; + + (void)ctx; /* No context */ + + if (!initialised) { + randLIB_seed_random(); + initialised = 1; + } + + for (i = 0; i < len; i++) { + buf[i] = (uint8_t)randLIB_get_8bit(); + } + return 0; /* Success */ +} + +/**** Cookie functions ****/ +static int simple_cookie_write(void *ctx, + unsigned char **p, unsigned char *end, + const unsigned char *info, size_t ilen) +{ + //TODO: As per RFC 6347 cookie must be stateless. This is not the case in here! + //This should be fixed if we see that dos attack would be an issue. + //this is proposed solution in RFC: Cookie = HMAC(Secret, Client-IP, Client-Parameters) + //Secret is generated here and oftenly changed to prevent statistical attack + simple_cookie_t *p_cookie = (simple_cookie_t *)ctx; + + /* Not using additional info */ + (void)info; + (void)ilen; + + if ((size_t)(end - *p) < COOKIE_SIMPLE_LEN) { + return MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL; + } + + /* Use a simple random number of length COOKIE_SIMPLE_LEN bytes */ + get_random(NULL, p_cookie->value, COOKIE_SIMPLE_LEN); + memcpy(*p, p_cookie->value, COOKIE_SIMPLE_LEN); + p_cookie->len = COOKIE_SIMPLE_LEN; + *p += COOKIE_SIMPLE_LEN; + return 0; +} + +static int simple_cookie_check(void *ctx, + const unsigned char *cookie, size_t clen, + const unsigned char *info, size_t ilen) +{ + simple_cookie_t *p_cookie = (simple_cookie_t *)ctx; + + /* Not using additional info */ + (void)info; + (void)ilen; + + if ((p_cookie->len == 0) || + (clen != p_cookie->len) || + (memcmp(cookie, p_cookie->value, p_cookie->len) != 0)) { + return -1; /* This is what it is in mbedtls... */ + } + return 0; +} + +/**** Key export function ****/ + +static int export_key_block(void *ctx, + const unsigned char *kb, const unsigned char *mk, + size_t maclen, size_t keylen, size_t ivlen) +{ + key_block_t *p_key_block = (key_block_t *)ctx; + + /* Not using master key */ + (void)mk; + + /* Sanity check MAC and key lengths */ + if ((maclen != 0) || (((2 * keylen) + (2 * ivlen)) != KEY_BLOCK_LEN)) { + return -1; /* Something seriously wrong! */ + } + + /* Copy the key block we are using */ + /* No need to skip over MAC keys, MAC len must be 0 if we are here */ + memcpy(p_key_block->value, kb /* + (2 * maclen)*/, (2 * keylen) + (2 * ivlen)); + return 0; +} + +/**** Timer functions ****/ + +/** + * Set timer function. + * Called back by mbedtls when it wants to set a timer. + * Accepts an intermediate and a final delay in milliseconds + * If the final delay is 0, cancels the running timer. + * TODO - might be better to use an event timer in conjunction with + * CoAP tasklet + */ +static void set_timer(void *sec_obj, uint32_t int_ms, uint32_t fin_ms) +{ + thread_security_t *sec = (thread_security_t *)sec_obj; + if( sec->_start_timer_cb ){ + sec->_start_timer_cb( sec->_timer_id, int_ms, fin_ms); + } +} + +/** + * Get timer function. + * Called back by mbedtls when it wants to set a timer. + * Returns the state of the current timer + * TODO - might be better to use an event timer in conjunction with + * CoAP tasklet + */ +static int get_timer(void *sec_obj) +{ + thread_security_t *sec = (thread_security_t *)sec_obj; + if( sec->_timer_status_cb ){ + return sec->_timer_status_cb(sec->_timer_id); + } + return -1; +} + +int coap_security_handler_connect(thread_security_t *sec, bool is_server, const unsigned char *pw, uint8_t len){ + + if( !sec ){ + return -1; + } + int endpoint = MBEDTLS_SSL_IS_CLIENT; + if( is_server ){ + endpoint = MBEDTLS_SSL_IS_SERVER; + } + + if( ( mbedtls_ssl_config_defaults( &sec->_conf, + endpoint, + MBEDTLS_SSL_TRANSPORT_DATAGRAM, 0 ) ) != 0 ) + { + return -1; + } + + mbedtls_ssl_conf_handshake_timeout( &sec->_conf, 60000, 61000 ); + mbedtls_ssl_conf_rng( &sec->_conf, mbedtls_ctr_drbg_random, &sec->_ctr_drbg ); + //mbedtls_ssl_conf_rng(&sec->_conf, get_random, NULL); + + if( ( mbedtls_ssl_setup( &sec->_ssl, &sec->_conf ) ) != 0 ) + { + return -1; + } + + mbedtls_ssl_set_bio( &sec->_ssl, sec, + f_send, f_recv, NULL ); + + mbedtls_ssl_set_timer_cb( &sec->_ssl, sec, set_timer, + get_timer ); + + //TODO: Figure out better way!!! + //Password should never be stored in multiple places!!! + if( is_server && len > 0){ + memcpy(sec->_pw, pw, len); + sec->_pw_len = len; + } + if( mbedtls_ssl_set_hs_ecjpake_password(&sec->_ssl, pw, len) != 0 ){ + return -1; + } + mbedtls_ssl_conf_ciphersuites(&sec->_conf, PSK_SUITES); + + mbedtls_ssl_conf_dtls_cookies(&sec->_conf, simple_cookie_write, + simple_cookie_check, + &sec->_cookie); + + mbedtls_ssl_conf_export_keys_cb(&sec->_conf, + export_key_block, + &sec->_keyblk); + + sec->_is_started = true; + + int ret = mbedtls_ssl_handshake_step( &sec->_ssl ); + if( ret == 0 ){ + ret = mbedtls_ssl_handshake_step( &sec->_ssl ); + if( is_server && 0 == ret){ + ret = coap_security_handler_continue_connecting( sec ); + } + } + + if( ret >= 0){ + ret = 1; + }else + { + ret = -1; + } + return ret; +} + +int coap_security_handler_continue_connecting(thread_security_t *sec){ + int ret=-1; + while( ret != MBEDTLS_ERR_SSL_WANT_READ ){ + ret = mbedtls_ssl_handshake_step( &sec->_ssl ); + if( MBEDTLS_ERR_SSL_HELLO_VERIFY_REQUIRED == ret){ + mbedtls_ssl_session_reset(&sec->_ssl); + if( mbedtls_ssl_set_hs_ecjpake_password(&sec->_ssl, sec->_pw, sec->_pw_len) != 0 ){ + return -1; + } + return 1; + } + if(MBEDTLS_ERR_SSL_TIMEOUT == ret || + MBEDTLS_ERR_SSL_BAD_HS_SERVER_HELLO == ret || + MBEDTLS_ERR_SSL_BAD_HS_CERTIFICATE == ret || + MBEDTLS_ERR_SSL_BAD_HS_CERTIFICATE_REQUEST == ret || + MBEDTLS_ERR_SSL_BAD_HS_SERVER_KEY_EXCHANGE == ret || + MBEDTLS_ERR_SSL_BAD_HS_SERVER_HELLO_DONE == ret || + MBEDTLS_ERR_SSL_BAD_HS_CHANGE_CIPHER_SPEC == ret || + MBEDTLS_ERR_SSL_BAD_HS_FINISHED == ret) { + return MBEDTLS_ERR_SSL_TIMEOUT; + } + if( sec->_ssl.state == MBEDTLS_SSL_HANDSHAKE_OVER ){ + + return 0; + } + } + return ret; +} + + +int coap_security_handler_send_message(thread_security_t *sec, unsigned char *message, size_t len){ + int ret=-1; + + if( sec ){ + do ret = mbedtls_ssl_write( &sec->_ssl, (unsigned char *) message, len ); + while( ret == MBEDTLS_ERR_SSL_WANT_READ || + ret == MBEDTLS_ERR_SSL_WANT_WRITE ); + } + + return ret; //bytes written +} + +int thread_security_send_close_alert(thread_security_t *sec) +{ + if( !sec ){ + return -1; + } + return mbedtls_ssl_close_notify(&sec->_ssl); + + coap_security_handler_reset(sec); + coap_security_handler_init(sec); +} + +int coap_security_handler_read(thread_security_t *sec, unsigned char* buffer, size_t len){ + int ret=-1; + + if( sec && buffer ){ + memset( buffer, 0, len ); + do ret = mbedtls_ssl_read( &sec->_ssl, buffer, len ); + while( ret == MBEDTLS_ERR_SSL_WANT_READ || + ret == MBEDTLS_ERR_SSL_WANT_WRITE ); + } + + return ret; //bytes read +} + +int f_send( void *ctx, const unsigned char *buf, size_t len){ + thread_security_t *sec = (thread_security_t *)ctx; + return sec->_send_cb(sec->_socket_id, sec->_remote_address, sec->_remote_port, buf, len); +} + +int f_recv(void *ctx, unsigned char *buf, size_t len){ + thread_security_t *sec = (thread_security_t *)ctx; + return sec->_receive_cb(sec->_socket_id, buf, len); +} + +int entropy_poll( void *ctx, unsigned char *output, size_t len, + size_t *olen ) +{ + //TODO: change to more secure random + srand(time(NULL)); + char *c = (char*)ns_dyn_mem_temporary_alloc(len); + if( !c ){ + return MBEDTLS_ERR_ENTROPY_SOURCE_FAILED; + } + memset(c, 0, len); + for(uint16_t i=0; i < len; i++){ + c[i] = rand() % 256; + } + memmove(output, c, len); + *olen = len; + + ns_dyn_mem_free(c); + return( 0 ); +} diff --git a/source/coap_server.c b/source/coap_server.c deleted file mode 100644 index 88f6c142c4..0000000000 --- a/source/coap_server.c +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Copyright (c) 2015 ARM Limited. All rights reserved. - - * SPDX-License-Identifier: Apache-2.0 - * Licensed under the Apache License, Version 2.0 (the License); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -//#include "include/coap_service_api.h" -#include "ns_types.h" -#include "ns_list.h" -#include "coap_server_impl.h" -#include "./include/coap_server.h" - -//typedef NS_LIST_HEAD(coap_service_session_t, link) instance_list_t; -//instance_list_t NS_LIST_NAME_INIT(instance_list); - -//typedef struct sn_coap_hdr_s sn_coap_hdr_s; - -static coap_service_session_t *coap_service_find_by_service(int8_t service_id); - -/* Coap service class handlers*/ - -void coap_server_delete_session(int8_t service_id) -{ - - coap_service_session_t *this = coap_service_find_by_service(service_id); - - if(this) - { - - //ns_list_remove(&instance_list,this); - memory_free(this); - - } - -} - -static coap_service_session_t *coap_service_find_by_service(int8_t service_id) -{ - (void)service_id; - coap_service_session_t *this = NULL; - - /* - ns_list_foreach(coap_service_session_t,cur_ptr, &instance_list) - { - if(cur_ptr->coap_service_id == service_id) - { - this = cur_ptr; - break; - } - } - */ - - return this; -} - - -/* Initialize CoAP server. - * - * TODO - * - * /param interface interface id of this instance. - * - */ -int8_t coap_server_service_init(int8_t interface_id, uint16_t listen_port, uint8_t service_options) -{ - (void)listen_port; - (void)service_options; - int retVal = -1; - int8_t socketInstance; - - // Initialize linked list - //ns_list_init_(instance_list); - - //allocate Socket Service - socketInstance = coap_server_start(); - - if(socketInstance < 0) - retVal = -2; - else - { - - coap_service_session_t *this = memory_allocation(sizeof(coap_service_session_t)); - if(this) - { - this->interface_id = interface_id; -// this->set_response_cb_ptr = NULL; - //ns_list_add_to_start(&instance_list, this); - retVal = 1; - } - return retVal; - - //allocate server - - } - if(socketInstance > 0) - { - coap_service_delete(socketInstance); - } - return retVal; -} - - diff --git a/source/coap_service.c b/source/coap_service.c deleted file mode 100644 index f2e88488e6..0000000000 --- a/source/coap_service.c +++ /dev/null @@ -1,177 +0,0 @@ -/* - * Copyright (c) 2015 ARM Limited. All rights reserved. - - * SPDX-License-Identifier: Apache-2.0 - * Licensed under the Apache License, Version 2.0 (the License); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* - * \file coap_service.c - * \brief Add short description about this file!!! - * - */ - -#include -#include -#include "ns_list.h" -#include "sn_coap_header.h" -#include "coap_service_api.h" -#include "coap_server.h" - -#include - -int8_t coap_service_initialize(int8_t interface_id, uint16_t listen_port, uint8_t service_options) -{ - int8_t retVal = -1; - - retVal = coap_server_service_init(interface_id, listen_port, service_options); - - return retVal; -} - -int8_t coap_service_register_uri(int8_t service_id, const char *uri, uint8_t allowed_method, coap_service_request_recv_cb *request_recv_cb) -{ - (void)service_id; - (void)uri; - (void)allowed_method; - (void)request_recv_cb; - return -1; -} - -int8_t coap_service_unregister_uri(int8_t service_id, const char *uri) -{ - (void)service_id; - (void)uri; - return -1; -} - -uint16_t coap_service_send(int8_t service_id, uint8_t options, const uint8_t addr[static 16], uint16_t destination_port, sn_coap_hdr_s *request_ptr, coap_service_response_recv *request_ptr2) -{ - (void)service_id; - (void)options; - (void)destination_port; - (void)addr; - (void)request_ptr; - (void)request_ptr2; - return 0; -} - -void coap_service_delete( int8_t service_id ) -{ - (void)service_id; -} - -int requst_recv_cb(int8_t service_id, uint8_t source_address[static 16], uint16_t source_port, sn_coap_hdr_s *request_ptr) -{ - (void)service_id; - (void)source_address; - (void)source_port; - (void)request_ptr; - return -1; -} - - -int security_start_ptr(int8_t service_id, uint8_t EUI64[static 8]) -{ - (void)service_id; - (void)EUI64; - return -1; -} - -int security_done_cb(int8_t service_id, uint8_t EUI64[static 8], uint8_t keyblock[static 40]) -{ - (void)service_id; - (void)EUI64; - (void)keyblock; - return -1; -} - -int coap_service_security_key_set(int8_t service_id, uint8_t EUI64[static 8], uint8_t *PSKd_ptr, uint8_t PSKd_len) -{ - (void)service_id; - (void)EUI64; - (void)PSKd_ptr; - (void)PSKd_len; - return -1; -} - -int requst_response_cb(uint16_t msg_id, sn_coap_hdr_s *response_ptr) -{ - (void)msg_id; - (void)response_ptr; - return -1; -} - -int virtual_socket_send(int8_t service_id, uint8_t destination_addr_ptr[static 16], uint16_t port, uint8_t *data_ptr, uint16_t data_len) -{ - (void)service_id; - (void)destination_addr_ptr; - (void)port; - (void)data_ptr; - (void)data_len; - return -1; -} - -int16_t coap_service_virtual_socket_recv(int8_t service_id, uint8_t source_addr_ptr[static 16], uint16_t port, uint8_t *data_ptr, uint16_t data_len) -{ - (void)service_id; - (void)source_addr_ptr; - (void)port; - (void)data_ptr; - (void)data_len; - return -1; -} - -int16_t coap_service_virtual_socket_set_cb(int8_t service_id, coap_service_virtual_socket_send_cb *virtual_socket_send) -{ - (void)service_id; - (void)virtual_socket_send; - return -1; -} - -int8_t coap_service_register_uri_secure_cb_set(int8_t service_id, coap_service_security_start_cb *security_start_ptr, coap_service_security_done_cb *security_done_cb) -{ - (void)service_id; - (void)security_start_ptr; - (void)security_done_cb; - return -1; -} - -uint16_t coap_service_request_send(int8_t service_id, uint8_t options, const uint8_t destination_addr[static 16], uint16_t destination_port, uint8_t msg_type, uint8_t msg_code, const char *uri, - uint8_t cont_type, const uint8_t *payload_ptr, uint16_t payload_len, coap_service_response_recv *request_response_cb) -{ - (void)service_id; - (void)options; - (void)destination_addr; - (void)destination_port; - (void)msg_type; - (void)msg_code; - (void)uri; - (void)cont_type; - (void)payload_ptr; - (void)payload_len; - (void)request_response_cb; - return 0; -} - -int8_t coap_service_response_send(int8_t service_id, uint8_t options, sn_coap_hdr_s *request_ptr, sn_coap_msg_code_e message_code, int32_t content_type, const uint8_t *payload_ptr,uint16_t payload_len) -{ - (void)service_id; - (void)options; - (void)request_ptr; - (void)message_code; - (void)content_type; - (void)payload_ptr; - (void)payload_len; - return -1; -} diff --git a/source/coap_service_api.c b/source/coap_service_api.c new file mode 100644 index 0000000000..444187d923 --- /dev/null +++ b/source/coap_service_api.c @@ -0,0 +1,450 @@ +/* + * Copyright (c) 2015 ARM Limited. All rights reserved. + */ + + + +#include + +#include "ns_types.h" +#include "ns_list.h" +#include "ns_trace.h" +#include "nsdynmemLIB.h" +#include "sn_nsdl.h" +#include "sn_coap_header.h" +#include "coap_service_api.h" +#include "coap_message_handler.h" +#include "eventOS_event.h" +#include "eventOS_scheduler.h" +#include "eventOS_event_timer.h" +#include "common_functions.h" +#include "coap_connection_handler.h" +#include "net_interface.h" + +static int16_t coap_service_coap_msg_process(int8_t socket_id, uint8_t source_addr_ptr[static 16], uint16_t port, uint8_t *data_ptr, uint16_t data_len); +static int16_t coap_msg_process_callback(int8_t socket_id, sn_coap_hdr_s *coap_message, coap_transaction_t *transaction_ptr); + +typedef struct uri_registration { + char *uri_ptr; + uint16_t uri_len; + uint8_t allowed_method; + coap_service_request_recv_cb *request_recv_cb; + ns_list_link_t link; +} uri_registration_t; + +typedef NS_LIST_HEAD(uri_registration_t, link) uri_registration_list_t; + +typedef struct coap_service { + coap_service_security_done_cb *security_done_cb; + coap_service_security_start_cb *security_start_cb; + coap_service_virtual_socket_send_cb *virtual_socket_send_cb; + uri_registration_list_t uri_list; + thread_conn_handler_t *conn_handler; + int8_t interface_id; + int8_t service_id; + int8_t listen_socket; + uint8_t service_options; + ns_list_link_t link; +} coap_service_t; + +#define TRACE_GROUP "ThSA" + +static NS_LIST_DEFINE(instance_list, coap_service_t, link); +static int8_t tasklet_id = -1; +coap_msg_handler_t *coap_service_handle = NULL; +static uint32_t coap_ticks = 1; + +#define COAP_TICK_TIMER 0xf1 + +static uri_registration_t *uri_registration_find(coap_service_t *this, const void *uri_ptr, uint16_t uri_len) +{ + ns_list_foreach(uri_registration_t, cur_ptr, &this->uri_list) { + if (cur_ptr->uri_len == uri_len && memcmp(cur_ptr->uri_ptr, uri_ptr, uri_len) == 0) { + return cur_ptr; + } + } + return NULL; +} +static coap_service_t *service_find(int8_t service_id) +{ + coap_service_t *this = NULL; + ns_list_foreach(coap_service_t, cur_ptr, &instance_list) { + if (cur_ptr->service_id == service_id) { + this = cur_ptr; + break; + } + } + return this; +} + +static coap_service_t *service_find_by_socket(int8_t socket_id) +{ + coap_service_t *this = NULL; + ns_list_foreach(coap_service_t, cur_ptr, &instance_list) { + if( coap_connection_handler_socket_belongs_to(cur_ptr->conn_handler, socket_id) ){ + this = cur_ptr; + break; + } + } + return this; +} + +static coap_service_t *service_find_by_uri(uint8_t socket_id, uint8_t *uri_ptr, uint16_t uri_len) +{ + ns_list_foreach(coap_service_t, cur_ptr, &instance_list) { + if (coap_connection_handler_socket_belongs_to(cur_ptr->conn_handler, socket_id) && uri_registration_find(cur_ptr, uri_ptr, uri_len)) { + return cur_ptr; + } + } + return NULL; +} + + +/** + * Coap handling functions + */ +static void *own_alloc(uint16_t size) +{ + if (size) { + return ns_dyn_mem_temporary_alloc(size); + } else { + return 0; + } +} + +static void own_free(void *ptr) +{ + if (ptr) { + ns_dyn_mem_free(ptr); + } +} + +static uint8_t coap_tx_function(uint8_t *data_ptr, uint16_t data_len, sn_nsdl_addr_s *address_ptr, void *param) +{ + coap_service_t *this; + coap_transaction_t *transaction_ptr = param; + ns_address_t dest_addr; + + if (!transaction_ptr || !data_ptr) { + return 0; + } + + tr_debug("Service %d, CoAP TX Function", transaction_ptr->service_id); + + this = service_find(transaction_ptr->service_id); + if (!this) { + return 0; + } + + memcpy(&(dest_addr.address), address_ptr->addr_ptr, 16); + dest_addr.identifier = address_ptr->port; + dest_addr.type = ADDRESS_IPV6; + + if( -2 == coap_connection_handler_send_data(this->conn_handler, &dest_addr, data_ptr, data_len, (this->service_options & COAP_SERVICE_OPTIONS_SECURE_BYPASS) == COAP_SERVICE_OPTIONS_SECURE_BYPASS) ){ + transaction_ptr->data_ptr = ns_dyn_mem_alloc(data_len); + if (!transaction_ptr->data_ptr) { + tr_debug("coap tx out of memory"); + return 0; + + } + memcpy(transaction_ptr->data_ptr, data_ptr, data_len); + transaction_ptr->data_len = data_len; + } + + return 0; +} + +static void service_event_handler(arm_event_s *event) +{ + if (event->event_type == ARM_LIB_TASKLET_INIT_EVENT) { + tr_debug("service tasklet initialised"); + /*initialize coap service and listen socket*/ + eventOS_event_timer_request((uint8_t)COAP_TICK_TIMER, ARM_LIB_SYSTEM_TIMER_EVENT, tasklet_id, 1000); + } + if (event->event_type == ARM_LIB_SYSTEM_TIMER_EVENT && event->event_id == COAP_TICK_TIMER) { + coap_message_handler_exec(coap_service_handle, coap_ticks++); + eventOS_event_timer_request((uint8_t)COAP_TICK_TIMER, ARM_LIB_SYSTEM_TIMER_EVENT, tasklet_id, 1000); + } +} + +static int16_t coap_msg_process_callback(int8_t socket_id, sn_coap_hdr_s *coap_message, coap_transaction_t *transaction_ptr) +{ + coap_service_t *this; + if( !coap_message ){ + return -1; + } + // Message is request find correct handle + this = service_find_by_uri(socket_id, coap_message->uri_path_ptr, coap_message->uri_path_len); + if (!this) { + tr_warn("not registered uri %.*s", coap_message->uri_path_len, coap_message->uri_path_ptr); + return -1; + } + + uri_registration_t *uri_reg_ptr = uri_registration_find(this, coap_message->uri_path_ptr, coap_message->uri_path_len); + if (transaction_ptr && uri_reg_ptr && uri_reg_ptr->request_recv_cb) { + tr_debug("Service %d, call request recv cb uri %.*s", this->service_id, coap_message->uri_path_len, coap_message->uri_path_ptr); + + if ((this->service_options & COAP_SERVICE_OPTIONS_SECURE_BYPASS) == COAP_SERVICE_OPTIONS_SECURE_BYPASS ) {//TODO Add secure bypass option + // Service has secure bypass active TODO this is not defined in interface + // this check can be removed I think + transaction_ptr->options = COAP_REQUEST_OPTIONS_SECURE_BYPASS; + } + transaction_ptr->service_id = this->service_id; + return uri_reg_ptr->request_recv_cb(this->service_id, transaction_ptr->remote_address, transaction_ptr->remote_port, coap_message); + } + return -1; +} + +static int16_t coap_service_coap_msg_process(int8_t socket_id, uint8_t source_addr_ptr[static 16], uint16_t port, uint8_t *data_ptr, uint16_t data_len) +{ + return coap_message_handler_coap_msg_process( coap_service_handle, socket_id, source_addr_ptr, port, data_ptr, data_len, &coap_msg_process_callback); +} + +static int recv_cb(int8_t socket_id, uint8_t address[static 16], uint16_t port, unsigned char *data, int len) +{ + uint8_t *data_ptr = NULL; + uint16_t data_len = 0; + + data_ptr = own_alloc(len); + + if (!data_ptr || len < 1) { + return -1; + } + memcpy(data_ptr, data, len); + data_len = len; + tr_debug("service recv socket data len %d ", data_len); + + //parse coap message what CoAP to use + int ret = coap_service_coap_msg_process(socket_id, address, port, data_ptr, data_len); + own_free(data_ptr); + return ret; +} + +static int send_cb(int8_t socket_id, uint8_t address[static 16], uint16_t port, const unsigned char *data_ptr, int data_len) +{ + coap_service_t *this = service_find_by_socket(socket_id); + if (this && this->virtual_socket_send_cb) { + tr_debug("send to virtual socket"); + return this->virtual_socket_send_cb(this->service_id, address, port, data_ptr, data_len); + } + return -1; +} + +//static void sec_conn_closed_cb(int8_t socket_id) +//{ +// coap_service_t *this = service_find_by_socket(socket_id); + +// tr_debug("Secure socket was closed by end device"); +//} + +static void sec_done_cb(int8_t socket_id, uint8_t address[static 16], uint16_t port, uint8_t keyblock[static 40]) +{ + //TODO: this is not enough if shared socket. Inform all! + coap_service_t *this = service_find_by_socket(socket_id); + if (this && this->security_done_cb) { // secure done callback + this->security_done_cb(this->service_id, address, keyblock); + } + + //TODO refactor this away. There should be no transaction_ptr(s) before done_cb has been called + //TODO: send all unsend transactions if more than 1 + coap_transaction_t *transaction_ptr = coap_message_handler_find_transaction(address, port); + if (transaction_ptr && transaction_ptr->data_ptr) { + tr_debug("send delayed packet"); + ns_address_t dest_addr; + memcpy(dest_addr.address, address, 16); + dest_addr.identifier = port; + dest_addr.type = ADDRESS_IPV6; + + coap_connection_handler_send_data(this->conn_handler, &dest_addr, transaction_ptr->data_ptr, transaction_ptr->data_len, (this->service_options & COAP_SERVICE_OPTIONS_SECURE_BYPASS) == COAP_SERVICE_OPTIONS_SECURE_BYPASS); + ns_dyn_mem_free(transaction_ptr->data_ptr); + transaction_ptr->data_ptr = NULL; + transaction_ptr->data_len = 0; + //TODO: who deletes transaction incase no response is required + } +} + +static int get_passwd_cb(int8_t socket_id, uint8_t address[static 16], uint16_t port, uint8_t *pw_ptr, uint8_t *pw_len) +{ + coap_service_t *this = service_find_by_socket(socket_id); + if (this && this->security_start_cb) { + return this->security_start_cb(this->service_id, address, port, pw_ptr, pw_len); + } + return -1; +} + +int8_t coap_service_initialize(int8_t interface_id, uint16_t listen_port, uint8_t service_options, + coap_service_security_start_cb *start_ptr, coap_service_security_done_cb *security_done_cb) +{ + coap_service_t *this = ns_dyn_mem_alloc(sizeof(coap_service_t)); + if (!this) { + return -1; + } + memset(this, 0, sizeof(coap_service_t)); + tr_debug("service init interface %d, port %d, options %d", interface_id, listen_port, service_options); + + int8_t id = 1;// get unique id + while (service_find(id) && id < 127) { + id++; + } + this->service_id = id; + this->service_options = service_options; + + this->security_start_cb = start_ptr; + this->security_done_cb = security_done_cb; + + if (tasklet_id == -1) { + tr_debug("service tasklet init"); + tasklet_id = eventOS_event_handler_create(&service_event_handler, ARM_LIB_TASKLET_INIT_EVENT); + } + + this->conn_handler = connection_handler_create(recv_cb, send_cb/*, sec_conn_closed_cb*/, get_passwd_cb, sec_done_cb); + if(!this->conn_handler){ + ns_dyn_mem_free(this); + return -1; + } + coap_connection_handler_open_connection(this->conn_handler, listen_port, ((this->service_options & COAP_SERVICE_OPTIONS_EPHEMERAL_PORT) == COAP_SERVICE_OPTIONS_EPHEMERAL_PORT), + ((this->service_options & COAP_SERVICE_OPTIONS_SECURE) == COAP_SERVICE_OPTIONS_SECURE), + ((this->service_options & COAP_SERVICE_OPTIONS_VIRTUAL_SOCKET) != COAP_SERVICE_OPTIONS_VIRTUAL_SOCKET), + ((this->service_options & COAP_SERVICE_OPTIONS_SECURE_BYPASS) == COAP_SERVICE_OPTIONS_SECURE_BYPASS)); + + if (!coap_service_handle) { + coap_service_handle = coap_message_handler_init(&own_alloc, &own_free, &coap_tx_function); + } + if (!coap_service_handle) { + tr_error("coap service alloc failed"); + //TODO proper handling + } + + ns_list_add_to_start(&instance_list, this); + return id; +} + +void coap_service_delete(int8_t service_id) +{ + coap_service_t *this = service_find(service_id); + if (!this) { + return; + } + + //TODO: There might be an issue with shared sockets, when deleting!! + if (this->conn_handler){ + connection_handler_destroy(this->conn_handler); + this->conn_handler = NULL; + } + + //TODO clear all transactions + ns_list_foreach_safe(uri_registration_t, cur_ptr, &this->uri_list) { + ns_dyn_mem_free(cur_ptr->uri_ptr); + ns_list_remove(&this->uri_list, cur_ptr); + ns_dyn_mem_free(cur_ptr); + } + + ns_list_remove(&instance_list, this); + ns_dyn_mem_free(this); + return; +} + +void coap_service_close_secure_connection(int8_t service_id) +{ + coap_service_t *this = service_find(service_id); + if (!this) { + return; + } + if (this->conn_handler){ + connection_handler_close_secure_connection(this->conn_handler); + } +} + +int16_t coap_service_virtual_socket_recv(int8_t service_id, uint8_t source_addr_ptr[static 16], uint16_t port, uint8_t *data_ptr, uint16_t data_len) +{ + coap_service_t *this = service_find(service_id); + tr_debug("Service %d, virtual socket received", service_id); + if (!this) { + return -1; + } + return coap_connection_handler_virtual_recv(this->conn_handler, source_addr_ptr, port, data_ptr, data_len); +} + +int16_t coap_service_virtual_socket_set_cb(int8_t service_id, coap_service_virtual_socket_send_cb *send_method_ptr) +{ + coap_service_t *this = service_find(service_id); + tr_debug("register virtual socket cb"); + if (!this) { + return -1; + } + this->virtual_socket_send_cb = send_method_ptr; + return 0; +} + +int8_t coap_service_register_uri(int8_t service_id, const char *uri, uint8_t allowed_method, coap_service_request_recv_cb *request_recv_cb) +{ + coap_service_t *this = service_find(service_id); + uri_registration_t *uri_reg_ptr; + char *uri_ptr = NULL; + uint16_t uri_len; + tr_debug("Service %d, Uri registration uri: %s", service_id, uri); + if (!this || !uri) { + return -1; + } + uri_len = strlen(uri); + + uri_reg_ptr = uri_registration_find(this, uri, uri_len); + if (!uri_reg_ptr) { + uri_reg_ptr = ns_dyn_mem_alloc(sizeof(uri_registration_t)); + if( !uri_reg_ptr ){ + tr_error("Uri registration failed, OOM"); + return -2; + } + uri_reg_ptr->uri_ptr = NULL; + } else { + ns_dyn_mem_free(uri_reg_ptr->uri_ptr); + ns_list_remove(&this->uri_list, uri_reg_ptr); + } + + uri_ptr = ns_dyn_mem_alloc(uri_len); + if (!uri_ptr) { + ns_dyn_mem_free(uri_reg_ptr); + tr_error("Uri registration failed, OOM"); + return -2; + } + + uri_reg_ptr->uri_ptr = memcpy(uri_ptr, uri, uri_len); + uri_reg_ptr->uri_len = uri_len; + uri_reg_ptr->request_recv_cb = request_recv_cb; + uri_reg_ptr->allowed_method = allowed_method; + ns_list_add_to_start(&this->uri_list, uri_reg_ptr); + return 0; +} + +int8_t coap_service_unregister_uri(int8_t service_id, const char *uri) +{ + coap_service_t *this = service_find(service_id); + uri_registration_t *uri_reg_ptr; + tr_debug("Service %d, Uri unregistration uri: %s", service_id, uri); + if (!this || !uri) { + return -1; + } + + uri_reg_ptr = uri_registration_find(this, uri, strlen(uri)); + if (!uri_reg_ptr) { + return -2; + } + + ns_dyn_mem_free(uri_reg_ptr->uri_ptr); + ns_list_remove(&this->uri_list, uri_reg_ptr); + ns_dyn_mem_free(uri_reg_ptr); + + return 0; +} + +uint16_t coap_service_request_send(int8_t service_id, uint8_t options, const uint8_t destination_addr[static 16], uint16_t destination_port, uint8_t msg_type, uint8_t msg_code, const char *uri, + uint8_t cont_type, const uint8_t *payload_ptr, uint16_t payload_len, coap_service_response_recv *request_response_cb){ + //TODO: coap_service_response_recv is an ugly cast, this should be refactored away + sn_coap_hdr_s MUST NOT be exposed to users of coap-service! + //Callback would be still needed, but where to store callback? + return coap_message_handler_request_send(coap_service_handle, service_id, options, destination_addr, destination_port, msg_type, msg_code, uri, cont_type, payload_ptr, payload_len, request_response_cb); +} + +int8_t coap_service_response_send(int8_t service_id, uint8_t options, sn_coap_hdr_s *request_ptr, sn_coap_msg_code_e message_code, int32_t content_type, const uint8_t *payload_ptr,uint16_t payload_len){ + return coap_message_handler_response_send(coap_service_handle, service_id, options, request_ptr, message_code, content_type, payload_ptr, payload_len); +} + diff --git a/source/include/coap_connection_handler.h b/source/include/coap_connection_handler.h new file mode 100644 index 0000000000..dd38b6e828 --- /dev/null +++ b/source/include/coap_connection_handler.h @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2015 ARM Limited. All rights reserved. + */ + +#ifndef __COAP_CONNECTION_HANDLER_H__ +#define __COAP_CONNECTION_HANDLER_H__ + +#include +#include +#include +#include "ns_address.h" + +struct internal_socket_s; + +typedef int send_to_socket_cb(int8_t socket_id, uint8_t address[static 16], uint16_t port, const unsigned char *, int); +typedef int receive_from_socket_cb(int8_t socket_id, uint8_t address[static 16], uint16_t port, unsigned char *, int); +typedef int get_pw_cb(int8_t socket_id, uint8_t address[static 16], uint16_t port, uint8_t *pw_ptr, uint8_t *pw_len); +typedef void security_done_cb(int8_t socket_id, uint8_t address[static 16], uint16_t port, uint8_t keyblock[static 40]); + +typedef struct thread_conn_handler_s{ + struct internal_socket_s *socket; + + receive_from_socket_cb *_recv_cb; + send_to_socket_cb *_send_cb; + get_pw_cb *_get_password_cb; + security_done_cb *_security_done_cb; + +} thread_conn_handler_t; + +thread_conn_handler_t *connection_handler_create(receive_from_socket_cb *recv_from_cb, + send_to_socket_cb *send_to_cb, + get_pw_cb *pw_cb, + security_done_cb *done_cb); + +void connection_handler_destroy( thread_conn_handler_t *handler ); + +void connection_handler_close_secure_connection( thread_conn_handler_t *handler ); + +int coap_connection_handler_open_connection(thread_conn_handler_t *handler, uint16_t listen_port, bool use_ephemeral_port, bool is_secure, bool real_socket, bool bypassSec); + +//If returns -2, it means security was started and data was not send +int coap_connection_handler_send_data(thread_conn_handler_t *handler, ns_address_t *dest_addr, uint8_t *data_ptr, uint16_t data_len, bool bypass_link_sec); + +int coap_connection_handler_virtual_recv(thread_conn_handler_t *handler, uint8_t address[static 16], uint16_t port, uint8_t *data_ptr, uint16_t data_len); + +bool coap_connection_handler_socket_belongs_to(thread_conn_handler_t *handler, int8_t socket_id); + +#endif diff --git a/source/include/coap_message_handler.h b/source/include/coap_message_handler.h new file mode 100644 index 0000000000..a7170a9a15 --- /dev/null +++ b/source/include/coap_message_handler.h @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2015 ARM Limited. All rights reserved. + */ + +#ifndef __COAPPI_SERVICE_API_H__ +#define __COAPPI_SERVICE_API_H__ + +#include +#include "sn_coap_header.h" +#include "sn_nsdl.h" +#include "ns_list.h" + +/** + * \brief Service message response receive callback. + * + * Function that handles CoAP service message receiving and parsing + * + * \param msg_id Id number of the current message. + * \param response_ptr Pointer to CoAP header structure. + * + * \return 0 for success / -1 for failure + */ +typedef int coap_message_handler_response_recv(int8_t service_id, uint16_t msg_id, sn_coap_hdr_s *response_ptr); + +typedef struct coap_msg_handler_s { + void *(*sn_coap_service_malloc)(uint16_t); + void (*sn_coap_service_free)(void *); + + uint8_t (*sn_coap_tx_callback)(uint8_t *, uint16_t, sn_nsdl_addr_s *, void *); + + struct coap_s *coap; +} coap_msg_handler_t; + +typedef struct coap_transaction { + uint8_t remote_address[16]; + uint16_t remote_port; + uint16_t msg_id; + int8_t service_id; + uint8_t options; + bool client_request: 1; + uint8_t *data_ptr; + uint16_t data_len; + coap_message_handler_response_recv *resp_cb; + ns_list_link_t link; +} coap_transaction_t; + + +extern coap_msg_handler_t *coap_message_handler_init(void *(*used_malloc_func_ptr)(uint16_t), void (*used_free_func_ptr)(void *), + uint8_t (*used_tx_callback_ptr)(uint8_t *, uint16_t, sn_nsdl_addr_s *, void *)); + +extern int8_t coap_message_handler_destroy(coap_msg_handler_t *handle); + +extern coap_transaction_t *coap_message_handler_find_transaction(uint8_t *address_ptr, uint16_t port); + +extern int16_t coap_message_handler_coap_msg_process(coap_msg_handler_t *handle, int8_t socket_id, uint8_t source_addr_ptr[static 16], uint16_t port, + uint8_t *data_ptr, uint16_t data_len, int16_t (cb)(int8_t, sn_coap_hdr_s *, coap_transaction_t *)); + +extern uint16_t coap_message_handler_request_send(coap_msg_handler_t *handle, int8_t service_id, uint8_t options, const uint8_t destination_addr[static 16], + uint16_t destination_port, uint8_t msg_type, uint8_t msg_code, const char *uri, uint8_t cont_type, + const uint8_t *payload_ptr, uint16_t payload_len, coap_message_handler_response_recv *request_response_cb); + +extern int8_t coap_message_handler_response_send(coap_msg_handler_t *handle, int8_t service_id, uint8_t options, sn_coap_hdr_s *request_ptr, sn_coap_msg_code_e message_code, + int32_t content_type, const uint8_t *payload_ptr, uint16_t payload_len); + +extern int8_t coap_message_handler_exec(coap_msg_handler_t *handle, uint32_t current_time); + +#endif diff --git a/source/include/coap_security_handler.h b/source/include/coap_security_handler.h new file mode 100644 index 0000000000..12e772d25e --- /dev/null +++ b/source/include/coap_security_handler.h @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2015 ARM Limited. All rights reserved. + */ +#ifndef __COAP_SECURITY_HANDLER_H__ +#define __COAP_SECURITY_HANDLER_H__ + +#include +#include +#include +#include "mbedtls/ssl.h" +#include "mbedtls/sha256.h" +#include "mbedtls/entropy.h" +#include "mbedtls/ctr_drbg.h" + +#define COOKIE_SIMPLE_LEN 8 +typedef struct simple_cookie { + unsigned char value[COOKIE_SIMPLE_LEN]; + size_t len; +} simple_cookie_t; + +#define KEY_BLOCK_LEN 40 +typedef struct key_block { + unsigned char value[KEY_BLOCK_LEN]; +} key_block_t; + +typedef int send_cb(int8_t socket_id, uint8_t *address_ptr, uint16_t port, const unsigned char *, size_t); +typedef int receive_cb(int8_t socket_id, unsigned char *, size_t); +typedef void start_timer_cb(int8_t timer_id, uint32_t min, uint32_t fin); +typedef int timer_status_cb(int8_t timer_id); + +typedef struct thread_security_s { + + mbedtls_ssl_config _conf; + mbedtls_ssl_context _ssl; + mbedtls_ctr_drbg_context _ctr_drbg; + mbedtls_entropy_context _entropy; + bool _is_started; + simple_cookie_t _cookie; + key_block_t _keyblk; + + uint8_t _remote_address[16]; + uint16_t _remote_port; + + uint8_t _pw[64]; + uint8_t _pw_len; + + int8_t _socket_id; + int8_t _timer_id; + send_cb *_send_cb; + receive_cb *_receive_cb; + start_timer_cb *_start_timer_cb; + timer_status_cb *_timer_status_cb; +} thread_security_t; + +thread_security_t *thread_security_create(int8_t socket_id, int8_t timer_id, uint8_t *address_ptr, uint16_t port, + send_cb *send_cb, + receive_cb *receive_cb, + start_timer_cb *start_timer_cb, + timer_status_cb *timer_status_cb); + +void thread_security_destroy(thread_security_t *sec); + +int coap_security_handler_connect(thread_security_t *sec, bool is_server, const unsigned char *pw, uint8_t len); + +int coap_security_handler_continue_connecting(thread_security_t *sec); + +int coap_security_handler_send_message(thread_security_t *sec, unsigned char *message, size_t len); + +int thread_security_send_close_alert(thread_security_t *sec); + +int coap_security_handler_read(thread_security_t *sec, unsigned char* buffer, size_t len); + +#endif diff --git a/source/include/coap_server.h b/source/include/coap_server.h deleted file mode 100644 index 1eb0222861..0000000000 --- a/source/include/coap_server.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (c) 2015 ARM Limited. All rights reserved. - - * SPDX-License-Identifier: Apache-2.0 - * Licensed under the Apache License, Version 2.0 (the License); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* - * \file - - * \brief Add short description about this file!!! - * - */ - -#ifndef COAP_SERVER_H_ -#define COAP_SERVER_H_ - -/* Brief explain. - * - * Some explain - * - * /param param_name explain. - * - * /return TODO - */ - -#include "ns_list.h" - -typedef struct -{ - uint8_t remote_address[16]; -// management_set_response_cb *set_response_cb_ptr; -// management_get_response_cb *get_response_cb_ptr; - int8_t interface_id; - int8_t coap_service_id; - ns_list_link_t link; -} coap_service_session_t; - -void coap_server_delete_session(int8_t service_id); - -int8_t coap_server_service_init(int8_t interface_id, uint16_t listen_port, uint8_t service_options); - -#endif /* COAP_SERVER_H_ */ diff --git a/source/include/coap_server_impl.h b/source/include/coap_server_impl.h deleted file mode 100644 index 893c923d50..0000000000 --- a/source/include/coap_server_impl.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) 2015 ARM Limited. All rights reserved. - - * SPDX-License-Identifier: Apache-2.0 - * Licensed under the Apache License, Version 2.0 (the License); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* - * \file - - * \brief Platform specifig implementation file - * - */ - -#ifndef COAP_SERVER_IMPL_H_ -#define COAP_SERVER_IMPL_H_ - -#include "ns_types.h" -#include "eventOS_event.h" -#include "coap_service_api.h" - -int8_t coap_server_start(void); - -void *memory_allocation(uint16_t size); - -void memory_free(void* ptr); - -void coap_server_service_tasklet(arm_event_s * event); - -uint16_t socket_open(uint16_t listen_port, coap_service_request_recv_cb *requst_recv_cb); - -#endif /* COAP_SERVER_IMPL_H_ */ diff --git a/test/coap-service/unittest/Makefile b/test/coap-service/unittest/Makefile new file mode 100755 index 0000000000..4e788fc31f --- /dev/null +++ b/test/coap-service/unittest/Makefile @@ -0,0 +1,23 @@ +#scan for folders having "Makefile" in them and remove 'this' to prevent loop +ifeq ($(OS),Windows_NT) +all: +clean: +else +DIRS := $(filter-out ./, $(sort $(dir $(shell find . -name 'Makefile')))) + +all: + for dir in $(DIRS); do \ + cd $$dir; make gcov; cd ..;\ + done + +clean: + for dir in $(DIRS); do \ + cd $$dir; make clean; cd ..;\ + done + rm -rf stub/*gcov stub/*gcda stubs/*o + rm -rf results/* + rm -rf coverages/* + rm -rf results + rm -rf coverages +endif + diff --git a/test/coap-service/unittest/MakefileWorker.mk b/test/coap-service/unittest/MakefileWorker.mk new file mode 100755 index 0000000000..2096ced036 --- /dev/null +++ b/test/coap-service/unittest/MakefileWorker.mk @@ -0,0 +1,562 @@ +#--------- +# +# MakefileWorker.mk +# +# Include this helper file in your makefile +# It makes +# A static library +# A test executable +# +# See this example for parameter settings +# examples/Makefile +# +#---------- +# Inputs - these variables describe what to build +# +# INCLUDE_DIRS - Directories used to search for include files. +# This generates a -I for each directory +# SRC_DIRS - Directories containing source file to built into the library +# SRC_FILES - Specific source files to build into library. Helpful when not all code +# in a directory can be built for test (hopefully a temporary situation) +# TEST_SRC_DIRS - Directories containing unit test code build into the unit test runner +# These do not go in a library. They are explicitly included in the test runner +# TEST_SRC_FILES - Specific source files to build into the unit test runner +# These do not go in a library. They are explicitly included in the test runner +# MOCKS_SRC_DIRS - Directories containing mock source files to build into the test runner +# These do not go in a library. They are explicitly included in the test runner +#---------- +# You can adjust these variables to influence how to build the test target +# and where to put and name outputs +# See below to determine defaults +# COMPONENT_NAME - the name of the thing being built +# TEST_TARGET - name the test executable. By default it is +# $(COMPONENT_NAME)_tests +# Helpful if you want 1 > make files in the same directory with different +# executables as output. +# CPPUTEST_HOME - where CppUTest home dir found +# TARGET_PLATFORM - Influences how the outputs are generated by modifying the +# CPPUTEST_OBJS_DIR and CPPUTEST_LIB_DIR to use a sub-directory under the +# normal objs and lib directories. Also modifies where to search for the +# CPPUTEST_LIB to link against. +# CPPUTEST_OBJS_DIR - a directory where o and d files go +# CPPUTEST_LIB_DIR - a directory where libs go +# CPPUTEST_ENABLE_DEBUG - build for debug +# CPPUTEST_USE_MEM_LEAK_DETECTION - Links with overridden new and delete +# CPPUTEST_USE_STD_CPP_LIB - Set to N to keep the standard C++ library out +# of the test harness +# CPPUTEST_USE_GCOV - Turn on coverage analysis +# Clean then build with this flag set to Y, then 'make gcov' +# CPPUTEST_MAPFILE - generate a map file +# CPPUTEST_WARNINGFLAGS - overly picky by default +# OTHER_MAKEFILE_TO_INCLUDE - a hook to use this makefile to make +# other targets. Like CSlim, which is part of fitnesse +# CPPUTEST_USE_VPATH - Use Make's VPATH functionality to support user +# specification of source files and directories that aren't below +# the user's Makefile in the directory tree, like: +# SRC_DIRS += ../../lib/foo +# It defaults to N, and shouldn't be necessary except in the above case. +#---------- +# +# Other flags users can initialize to sneak in their settings +# CPPUTEST_CXXFLAGS - flags for the C++ compiler +# CPPUTEST_CPPFLAGS - flags for the C++ AND C preprocessor +# CPPUTEST_CFLAGS - flags for the C complier +# CPPUTEST_LDFLAGS - Linker flags +#---------- + +# Some behavior is weird on some platforms. Need to discover the platform. + +# Platforms +UNAME_OUTPUT = "$(shell uname -a)" +MACOSX_STR = Darwin +MINGW_STR = MINGW +CYGWIN_STR = CYGWIN +LINUX_STR = Linux +SUNOS_STR = SunOS +UNKNWOWN_OS_STR = Unknown + +# Compilers +CC_VERSION_OUTPUT ="$(shell $(CXX) -v 2>&1)" +CLANG_STR = clang +SUNSTUDIO_CXX_STR = SunStudio + +UNAME_OS = $(UNKNWOWN_OS_STR) + +ifeq ($(findstring $(MINGW_STR),$(UNAME_OUTPUT)),$(MINGW_STR)) + UNAME_OS = $(MINGW_STR) +endif + +ifeq ($(findstring $(CYGWIN_STR),$(UNAME_OUTPUT)),$(CYGWIN_STR)) + UNAME_OS = $(CYGWIN_STR) +endif + +ifeq ($(findstring $(LINUX_STR),$(UNAME_OUTPUT)),$(LINUX_STR)) + UNAME_OS = $(LINUX_STR) +endif + +ifeq ($(findstring $(MACOSX_STR),$(UNAME_OUTPUT)),$(MACOSX_STR)) + UNAME_OS = $(MACOSX_STR) +#lion has a problem with the 'v' part of -a + UNAME_OUTPUT = "$(shell uname -pmnrs)" +endif + +ifeq ($(findstring $(SUNOS_STR),$(UNAME_OUTPUT)),$(SUNOS_STR)) + UNAME_OS = $(SUNOS_STR) + + SUNSTUDIO_CXX_ERR_STR = CC -flags +ifeq ($(findstring $(SUNSTUDIO_CXX_ERR_STR),$(CC_VERSION_OUTPUT)),$(SUNSTUDIO_CXX_ERR_STR)) + CC_VERSION_OUTPUT ="$(shell $(CXX) -V 2>&1)" + COMPILER_NAME = $(SUNSTUDIO_CXX_STR) +endif +endif + +ifeq ($(findstring $(CLANG_STR),$(CC_VERSION_OUTPUT)),$(CLANG_STR)) + COMPILER_NAME = $(CLANG_STR) +endif + +#Kludge for mingw, it does not have cc.exe, but gcc.exe will do +ifeq ($(UNAME_OS),$(MINGW_STR)) + CC := gcc +endif + +#And another kludge. Exception handling in gcc 4.6.2 is broken when linking the +# Standard C++ library as a shared library. Unbelievable. +ifeq ($(UNAME_OS),$(MINGW_STR)) + CPPUTEST_LDFLAGS += -static +endif +ifeq ($(UNAME_OS),$(CYGWIN_STR)) + CPPUTEST_LDFLAGS += -static +endif + + +#Kludge for MacOsX gcc compiler on Darwin9 who can't handle pendantic +ifeq ($(UNAME_OS),$(MACOSX_STR)) +ifeq ($(findstring Version 9,$(UNAME_OUTPUT)),Version 9) + CPPUTEST_PEDANTIC_ERRORS = N +endif +endif + +ifndef COMPONENT_NAME + COMPONENT_NAME = name_this_in_the_makefile +endif + +# Debug on by default +ifndef CPPUTEST_ENABLE_DEBUG + CPPUTEST_ENABLE_DEBUG = Y +endif + +# new and delete for memory leak detection on by default +ifndef CPPUTEST_USE_MEM_LEAK_DETECTION + CPPUTEST_USE_MEM_LEAK_DETECTION = Y +endif + +# Use the standard C library +ifndef CPPUTEST_USE_STD_C_LIB + CPPUTEST_USE_STD_C_LIB = Y +endif + +# Use the standard C++ library +ifndef CPPUTEST_USE_STD_CPP_LIB + CPPUTEST_USE_STD_CPP_LIB = Y +endif + +# Use gcov, off by default +ifndef CPPUTEST_USE_GCOV + CPPUTEST_USE_GCOV = N +endif + +ifndef CPPUTEST_PEDANTIC_ERRORS + CPPUTEST_PEDANTIC_ERRORS = Y +endif + +# Default warnings +ifndef CPPUTEST_WARNINGFLAGS + CPPUTEST_WARNINGFLAGS = -Wall -Wextra -Wshadow -Wswitch-default -Wswitch-enum -Wconversion +ifeq ($(CPPUTEST_PEDANTIC_ERRORS), Y) +# CPPUTEST_WARNINGFLAGS += -pedantic-errors + CPPUTEST_WARNINGFLAGS += -pedantic +endif +ifeq ($(UNAME_OS),$(LINUX_STR)) + CPPUTEST_WARNINGFLAGS += -Wsign-conversion +endif + CPPUTEST_CXX_WARNINGFLAGS = -Woverloaded-virtual + CPPUTEST_C_WARNINGFLAGS = -Wstrict-prototypes +endif + +#Wonderful extra compiler warnings with clang +ifeq ($(COMPILER_NAME),$(CLANG_STR)) +# -Wno-disabled-macro-expansion -> Have to disable the macro expansion warning as the operator new overload warns on that. +# -Wno-padded -> I sort-of like this warning but if there is a bool at the end of the class, it seems impossible to remove it! (except by making padding explicit) +# -Wno-global-constructors Wno-exit-time-destructors -> Great warnings, but in CppUTest it is impossible to avoid as the automatic test registration depends on the global ctor and dtor +# -Wno-weak-vtables -> The TEST_GROUP macro declares a class and will automatically inline its methods. Thats ok as they are only in one translation unit. Unfortunately, the warning can't detect that, so it must be disabled. + CPPUTEST_CXX_WARNINGFLAGS += -Weverything -Wno-disabled-macro-expansion -Wno-padded -Wno-global-constructors -Wno-exit-time-destructors -Wno-weak-vtables + CPPUTEST_C_WARNINGFLAGS += -Weverything -Wno-padded +endif + +# Uhm. Maybe put some warning flags for SunStudio here? +ifeq ($(COMPILER_NAME),$(SUNSTUDIO_CXX_STR)) + CPPUTEST_CXX_WARNINGFLAGS = + CPPUTEST_C_WARNINGFLAGS = +endif + +# Default dir for temporary files (d, o) +ifndef CPPUTEST_OBJS_DIR +ifndef TARGET_PLATFORM + CPPUTEST_OBJS_DIR = objs +else + CPPUTEST_OBJS_DIR = objs/$(TARGET_PLATFORM) +endif +endif + +# Default dir for the outout library +ifndef CPPUTEST_LIB_DIR +ifndef TARGET_PLATFORM + CPPUTEST_LIB_DIR = lib +else + CPPUTEST_LIB_DIR = lib/$(TARGET_PLATFORM) +endif +endif + +# No map by default +ifndef CPPUTEST_MAP_FILE + CPPUTEST_MAP_FILE = N +endif + +# No extentions is default +ifndef CPPUTEST_USE_EXTENSIONS + CPPUTEST_USE_EXTENSIONS = N +endif + +# No VPATH is default +ifndef CPPUTEST_USE_VPATH + CPPUTEST_USE_VPATH := N +endif +# Make empty, instead of 'N', for usage in $(if ) conditionals +ifneq ($(CPPUTEST_USE_VPATH), Y) + CPPUTEST_USE_VPATH := +endif + +ifndef TARGET_PLATFORM +#CPPUTEST_LIB_LINK_DIR = $(CPPUTEST_HOME)/lib +CPPUTEST_LIB_LINK_DIR = /usr/lib/x86_64-linux-gnu +else +CPPUTEST_LIB_LINK_DIR = $(CPPUTEST_HOME)/lib/$(TARGET_PLATFORM) +endif + +# -------------------------------------- +# derived flags in the following area +# -------------------------------------- + +# Without the C library, we'll need to disable the C++ library and ... +ifeq ($(CPPUTEST_USE_STD_C_LIB), N) + CPPUTEST_USE_STD_CPP_LIB = N + CPPUTEST_USE_MEM_LEAK_DETECTION = N + CPPUTEST_CPPFLAGS += -DCPPUTEST_STD_C_LIB_DISABLED + CPPUTEST_CPPFLAGS += -nostdinc +endif + +CPPUTEST_CPPFLAGS += -DCPPUTEST_COMPILATION + +ifeq ($(CPPUTEST_USE_MEM_LEAK_DETECTION), N) + CPPUTEST_CPPFLAGS += -DCPPUTEST_MEM_LEAK_DETECTION_DISABLED +else + ifndef CPPUTEST_MEMLEAK_DETECTOR_NEW_MACRO_FILE + CPPUTEST_MEMLEAK_DETECTOR_NEW_MACRO_FILE = -include $(CPPUTEST_HOME)/include/CppUTest/MemoryLeakDetectorNewMacros.h + endif + ifndef CPPUTEST_MEMLEAK_DETECTOR_MALLOC_MACRO_FILE + CPPUTEST_MEMLEAK_DETECTOR_MALLOC_MACRO_FILE = -include $(CPPUTEST_HOME)/include/CppUTest/MemoryLeakDetectorMallocMacros.h + endif +endif + +ifeq ($(CPPUTEST_ENABLE_DEBUG), Y) + CPPUTEST_CXXFLAGS += -g + CPPUTEST_CFLAGS += -g + CPPUTEST_LDFLAGS += -g +endif + +ifeq ($(CPPUTEST_USE_STD_CPP_LIB), N) + CPPUTEST_CPPFLAGS += -DCPPUTEST_STD_CPP_LIB_DISABLED +ifeq ($(CPPUTEST_USE_STD_C_LIB), Y) + CPPUTEST_CXXFLAGS += -nostdinc++ +endif +endif + +ifdef $(GMOCK_HOME) + GTEST_HOME = $(GMOCK_HOME)/gtest + CPPUTEST_CPPFLAGS += -I$(GMOCK_HOME)/include + GMOCK_LIBRARY = $(GMOCK_HOME)/lib/.libs/libgmock.a + LD_LIBRARIES += $(GMOCK_LIBRARY) + CPPUTEST_CPPFLAGS += -DINCLUDE_GTEST_TESTS + CPPUTEST_WARNINGFLAGS = + CPPUTEST_CPPFLAGS += -I$(GTEST_HOME)/include -I$(GTEST_HOME) + GTEST_LIBRARY = $(GTEST_HOME)/lib/.libs/libgtest.a + LD_LIBRARIES += $(GTEST_LIBRARY) +endif + + +ifeq ($(CPPUTEST_USE_GCOV), Y) + CPPUTEST_CXXFLAGS += -fprofile-arcs -ftest-coverage + CPPUTEST_CFLAGS += -fprofile-arcs -ftest-coverage +endif + +CPPUTEST_CXXFLAGS += $(CPPUTEST_WARNINGFLAGS) $(CPPUTEST_CXX_WARNINGFLAGS) +CPPUTEST_CPPFLAGS += $(CPPUTEST_WARNINGFLAGS) +CPPUTEST_CXXFLAGS += $(CPPUTEST_MEMLEAK_DETECTOR_NEW_MACRO_FILE) +CPPUTEST_CPPFLAGS += $(CPPUTEST_MEMLEAK_DETECTOR_MALLOC_MACRO_FILE) +CPPUTEST_CFLAGS += $(CPPUTEST_C_WARNINGFLAGS) + +TARGET_MAP = $(COMPONENT_NAME).map.txt +ifeq ($(CPPUTEST_MAP_FILE), Y) + CPPUTEST_LDFLAGS += -Wl,-map,$(TARGET_MAP) +endif + +# Link with CppUTest lib +CPPUTEST_LIB = $(CPPUTEST_LIB_LINK_DIR)/libCppUTest.a + +ifeq ($(CPPUTEST_USE_EXTENSIONS), Y) +CPPUTEST_LIB += $(CPPUTEST_LIB_LINK_DIR)/libCppUTestExt.a +endif + +ifdef CPPUTEST_STATIC_REALTIME + LD_LIBRARIES += -lrt +endif + +TARGET_LIB = \ + $(CPPUTEST_LIB_DIR)/lib$(COMPONENT_NAME).a + +ifndef TEST_TARGET + ifndef TARGET_PLATFORM + TEST_TARGET = $(COMPONENT_NAME)_tests + else + TEST_TARGET = $(COMPONENT_NAME)_$(TARGET_PLATFORM)_tests + endif +endif + +#Helper Functions +get_src_from_dir = $(wildcard $1/*.cpp) $(wildcard $1/*.cc) $(wildcard $1/*.c) +get_dirs_from_dirspec = $(wildcard $1) +get_src_from_dir_list = $(foreach dir, $1, $(call get_src_from_dir,$(dir))) +__src_to = $(subst .c,$1, $(subst .cc,$1, $(subst .cpp,$1,$(if $(CPPUTEST_USE_VPATH),$(notdir $2),$2)))) +src_to = $(addprefix $(CPPUTEST_OBJS_DIR)/,$(call __src_to,$1,$2)) +src_to_o = $(call src_to,.o,$1) +src_to_d = $(call src_to,.d,$1) +src_to_gcda = $(call src_to,.gcda,$1) +src_to_gcno = $(call src_to,.gcno,$1) +time = $(shell date +%s) +delta_t = $(eval minus, $1, $2) +debug_print_list = $(foreach word,$1,echo " $(word)";) echo; + +#Derived +STUFF_TO_CLEAN += $(TEST_TARGET) $(TEST_TARGET).exe $(TARGET_LIB) $(TARGET_MAP) + +SRC += $(call get_src_from_dir_list, $(SRC_DIRS)) $(SRC_FILES) +OBJ = $(call src_to_o,$(SRC)) + +STUFF_TO_CLEAN += $(OBJ) + +TEST_SRC += $(call get_src_from_dir_list, $(TEST_SRC_DIRS)) $(TEST_SRC_FILES) +TEST_OBJS = $(call src_to_o,$(TEST_SRC)) +STUFF_TO_CLEAN += $(TEST_OBJS) + + +MOCKS_SRC += $(call get_src_from_dir_list, $(MOCKS_SRC_DIRS)) +MOCKS_OBJS = $(call src_to_o,$(MOCKS_SRC)) +STUFF_TO_CLEAN += $(MOCKS_OBJS) + +ALL_SRC = $(SRC) $(TEST_SRC) $(MOCKS_SRC) + +# If we're using VPATH +ifeq ($(CPPUTEST_USE_VPATH), Y) +# gather all the source directories and add them + VPATH += $(sort $(dir $(ALL_SRC))) +# Add the component name to the objs dir path, to differentiate between same-name objects + CPPUTEST_OBJS_DIR := $(addsuffix /$(COMPONENT_NAME),$(CPPUTEST_OBJS_DIR)) +endif + +#Test coverage with gcov +GCOV_OUTPUT = gcov_output.txt +GCOV_REPORT = gcov_report.txt +GCOV_ERROR = gcov_error.txt +GCOV_GCDA_FILES = $(call src_to_gcda, $(ALL_SRC)) +GCOV_GCNO_FILES = $(call src_to_gcno, $(ALL_SRC)) +TEST_OUTPUT = $(TEST_TARGET).txt +STUFF_TO_CLEAN += \ + $(GCOV_OUTPUT)\ + $(GCOV_REPORT)\ + $(GCOV_REPORT).html\ + $(GCOV_ERROR)\ + $(GCOV_GCDA_FILES)\ + $(GCOV_GCNO_FILES)\ + $(TEST_OUTPUT) + +#The gcda files for gcov need to be deleted before each run +#To avoid annoying messages. +GCOV_CLEAN = $(SILENCE)rm -f $(GCOV_GCDA_FILES) $(GCOV_OUTPUT) $(GCOV_REPORT) $(GCOV_ERROR) +RUN_TEST_TARGET = $(SILENCE) $(GCOV_CLEAN) ; echo "Running $(TEST_TARGET)"; ./$(TEST_TARGET) $(CPPUTEST_EXE_FLAGS) -ojunit + +ifeq ($(CPPUTEST_USE_GCOV), Y) + + ifeq ($(COMPILER_NAME),$(CLANG_STR)) + LD_LIBRARIES += --coverage + else + LD_LIBRARIES += -lgcov + endif +endif + + +INCLUDES_DIRS_EXPANDED = $(call get_dirs_from_dirspec, $(INCLUDE_DIRS)) +INCLUDES += $(foreach dir, $(INCLUDES_DIRS_EXPANDED), -I$(dir)) +MOCK_DIRS_EXPANDED = $(call get_dirs_from_dirspec, $(MOCKS_SRC_DIRS)) +INCLUDES += $(foreach dir, $(MOCK_DIRS_EXPANDED), -I$(dir)) + +CPPUTEST_CPPFLAGS += $(INCLUDES) $(CPPUTESTFLAGS) + +DEP_FILES = $(call src_to_d, $(ALL_SRC)) +STUFF_TO_CLEAN += $(DEP_FILES) $(PRODUCTION_CODE_START) $(PRODUCTION_CODE_END) +STUFF_TO_CLEAN += $(STDLIB_CODE_START) $(MAP_FILE) cpputest_*.xml junit_run_output + +# We'll use the CPPUTEST_CFLAGS etc so that you can override AND add to the CppUTest flags +CFLAGS = $(CPPUTEST_CFLAGS) $(CPPUTEST_ADDITIONAL_CFLAGS) +CPPFLAGS = $(CPPUTEST_CPPFLAGS) $(CPPUTEST_ADDITIONAL_CPPFLAGS) +CXXFLAGS = $(CPPUTEST_CXXFLAGS) $(CPPUTEST_ADDITIONAL_CXXFLAGS) +LDFLAGS = $(CPPUTEST_LDFLAGS) $(CPPUTEST_ADDITIONAL_LDFLAGS) + +# Don't consider creating the archive a warning condition that does STDERR output +ARFLAGS := $(ARFLAGS)c + +DEP_FLAGS=-MMD -MP + +# Some macros for programs to be overridden. For some reason, these are not in Make defaults +RANLIB = ranlib + +# Targets + +.PHONY: all +all: start $(TEST_TARGET) + $(RUN_TEST_TARGET) + +.PHONY: start +start: $(TEST_TARGET) + $(SILENCE)START_TIME=$(call time) + +.PHONY: all_no_tests +all_no_tests: $(TEST_TARGET) + +.PHONY: flags +flags: + @echo + @echo "OS ${UNAME_OS}" + @echo "Compile C and C++ source with CPPFLAGS:" + @$(call debug_print_list,$(CPPFLAGS)) + @echo "Compile C++ source with CXXFLAGS:" + @$(call debug_print_list,$(CXXFLAGS)) + @echo "Compile C source with CFLAGS:" + @$(call debug_print_list,$(CFLAGS)) + @echo "Link with LDFLAGS:" + @$(call debug_print_list,$(LDFLAGS)) + @echo "Link with LD_LIBRARIES:" + @$(call debug_print_list,$(LD_LIBRARIES)) + @echo "Create libraries with ARFLAGS:" + @$(call debug_print_list,$(ARFLAGS)) + +TEST_DEPS = $(TEST_OBJS) $(MOCKS_OBJS) $(PRODUCTION_CODE_START) $(TARGET_LIB) $(USER_LIBS) $(PRODUCTION_CODE_END) $(CPPUTEST_LIB) $(STDLIB_CODE_START) +test-deps: $(TEST_DEPS) + +$(TEST_TARGET): $(TEST_DEPS) + @echo Linking $@ + $(SILENCE)$(CXX) -o $@ $^ $(LD_LIBRARIES) $(LDFLAGS) + +$(TARGET_LIB): $(OBJ) + @echo Building archive $@ + $(SILENCE)mkdir -p $(dir $@) + $(SILENCE)$(AR) $(ARFLAGS) $@ $^ + $(SILENCE)$(RANLIB) $@ + +test: $(TEST_TARGET) + $(RUN_TEST_TARGET) | tee $(TEST_OUTPUT) + +vtest: $(TEST_TARGET) + $(RUN_TEST_TARGET) -v | tee $(TEST_OUTPUT) + +$(CPPUTEST_OBJS_DIR)/%.o: %.cc + @echo compiling $(notdir $<) + $(SILENCE)mkdir -p $(dir $@) + $(SILENCE)$(COMPILE.cpp) $(DEP_FLAGS) $(OUTPUT_OPTION) $< + +$(CPPUTEST_OBJS_DIR)/%.o: %.cpp + @echo compiling $(notdir $<) + $(SILENCE)mkdir -p $(dir $@) + $(SILENCE)$(COMPILE.cpp) $(DEP_FLAGS) $(OUTPUT_OPTION) $< + +$(CPPUTEST_OBJS_DIR)/%.o: %.c + @echo compiling $(notdir $<) + $(SILENCE)mkdir -p $(dir $@) + $(SILENCE)$(COMPILE.c) $(DEP_FLAGS) $(OUTPUT_OPTION) $< + +ifneq "$(MAKECMDGOALS)" "clean" +-include $(DEP_FILES) +endif + +.PHONY: clean +clean: + @echo Making clean + $(SILENCE)$(RM) $(STUFF_TO_CLEAN) + $(SILENCE)rm -rf gcov objs #$(CPPUTEST_OBJS_DIR) + $(SILENCE)rm -rf $(CPPUTEST_LIB_DIR) + $(SILENCE)find . -name "*.gcno" | xargs rm -f + $(SILENCE)find . -name "*.gcda" | xargs rm -f + +#realclean gets rid of all gcov, o and d files in the directory tree +#not just the ones made by this makefile +.PHONY: realclean +realclean: clean + $(SILENCE)rm -rf gcov + $(SILENCE)find . -name "*.gdcno" | xargs rm -f + $(SILENCE)find . -name "*.[do]" | xargs rm -f + +gcov: test +ifeq ($(CPPUTEST_USE_VPATH), Y) + $(SILENCE)gcov --object-directory $(CPPUTEST_OBJS_DIR) $(SRC) >> $(GCOV_OUTPUT) 2>> $(GCOV_ERROR) +else + $(SILENCE)for d in $(SRC_DIRS) ; do \ + gcov --object-directory $(CPPUTEST_OBJS_DIR)/$$d $$d/*.c $$d/*.cpp >> $(GCOV_OUTPUT) 2>>$(GCOV_ERROR) ; \ + done + $(SILENCE)for f in $(SRC_FILES) ; do \ + gcov --object-directory $(CPPUTEST_OBJS_DIR)/$$f $$f >> $(GCOV_OUTPUT) 2>>$(GCOV_ERROR) ; \ + done +endif +# $(CPPUTEST_HOME)/scripts/filterGcov.sh $(GCOV_OUTPUT) $(GCOV_ERROR) $(GCOV_REPORT) $(TEST_OUTPUT) + /usr/share/cpputest/scripts/filterGcov.sh $(GCOV_OUTPUT) $(GCOV_ERROR) $(GCOV_REPORT) $(TEST_OUTPUT) + $(SILENCE)cat $(GCOV_REPORT) + $(SILENCE)mkdir -p gcov + $(SILENCE)mv *.gcov gcov + $(SILENCE)mv gcov_* gcov + @echo "See gcov directory for details" + +.PHONEY: format +format: + $(CPPUTEST_HOME)/scripts/reformat.sh $(PROJECT_HOME_DIR) + +.PHONEY: debug +debug: + @echo + @echo "Target Source files:" + @$(call debug_print_list,$(SRC)) + @echo "Target Object files:" + @$(call debug_print_list,$(OBJ)) + @echo "Test Source files:" + @$(call debug_print_list,$(TEST_SRC)) + @echo "Test Object files:" + @$(call debug_print_list,$(TEST_OBJS)) + @echo "Mock Source files:" + @$(call debug_print_list,$(MOCKS_SRC)) + @echo "Mock Object files:" + @$(call debug_print_list,$(MOCKS_OBJS)) + @echo "All Input Dependency files:" + @$(call debug_print_list,$(DEP_FILES)) + @echo Stuff to clean: + @$(call debug_print_list,$(STUFF_TO_CLEAN)) + @echo Includes: + @$(call debug_print_list,$(INCLUDES)) + +-include $(OTHER_MAKEFILE_TO_INCLUDE) diff --git a/test/coap-service/unittest/coap_connection_handler/Makefile b/test/coap-service/unittest/coap_connection_handler/Makefile new file mode 100644 index 0000000000..d934974d1f --- /dev/null +++ b/test/coap-service/unittest/coap_connection_handler/Makefile @@ -0,0 +1,23 @@ +include ../makefile_defines.txt + +COMPONENT_NAME = coap_connection_handler_unit + +#This must be changed manually +SRC_FILES = \ + ../../../../source/coap_connection_handler.c + +TEST_SRC_FILES = \ + main.cpp \ + coap_connection_handlertest.cpp \ + test_coap_connection_handler.c \ + ../stub/ns_trace_stub.c \ + ../stub/ns_list_stub.c \ + ../stub/ns_timer_stub.c \ + ../stub/nsdynmemLIB_stub.c \ + ../stub/socket_api_stub.c \ + ../stub/coap_security_handler_stub.c \ + +include ../MakefileWorker.mk + +CPPUTESTFLAGS += -DFEA_TRACE_SUPPORT + diff --git a/test/coap-service/unittest/coap_connection_handler/coap_connection_handlertest.cpp b/test/coap-service/unittest/coap_connection_handler/coap_connection_handlertest.cpp new file mode 100644 index 0000000000..383d42b6b8 --- /dev/null +++ b/test/coap-service/unittest/coap_connection_handler/coap_connection_handlertest.cpp @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2015 ARM. All rights reserved. + */ +#include "CppUTest/TestHarness.h" +#include "test_coap_connection_handler.h" + +TEST_GROUP(coap_connection_handler) +{ + void setup() + { + } + + void teardown() + { + } +}; + +TEST(coap_connection_handler, test_connection_handler_create) +{ + CHECK(test_connection_handler_create()); +} + +TEST(coap_connection_handler, test_connection_handler_destroy) +{ + CHECK(test_connection_handler_destroy()); +} + +TEST(coap_connection_handler, test_coap_connection_handler_open_connection) +{ + CHECK(test_coap_connection_handler_open_connection()); +} + +TEST(coap_connection_handler, test_coap_connection_handler_send_data) +{ + CHECK(test_coap_connection_handler_send_data()); +} + +TEST(coap_connection_handler, test_coap_connection_handler_virtual_recv) +{ + CHECK(test_coap_connection_handler_virtual_recv()); +} + +TEST(coap_connection_handler, test_coap_connection_handler_socket_belongs_to) +{ + CHECK(test_coap_connection_handler_socket_belongs_to()); +} + +TEST(coap_connection_handler, test_timer_callbacks) +{ + CHECK(test_timer_callbacks()); +} + +TEST(coap_connection_handler, test_socket_api_callbacks) +{ + CHECK(test_socket_api_callbacks()); +} + +TEST(coap_connection_handler, test_security_callbacks) +{ + CHECK(test_security_callbacks()); +} + diff --git a/test/coap-service/unittest/coap_connection_handler/main.cpp b/test/coap-service/unittest/coap_connection_handler/main.cpp new file mode 100644 index 0000000000..c04ec8b369 --- /dev/null +++ b/test/coap-service/unittest/coap_connection_handler/main.cpp @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2015 ARM. All rights reserved. + */ + +#include "CppUTest/CommandLineTestRunner.h" +#include "CppUTest/TestPlugin.h" +#include "CppUTest/TestRegistry.h" +#include "CppUTestExt/MockSupportPlugin.h" +int main(int ac, char** av) +{ + return CommandLineTestRunner::RunAllTests(ac, av); +} + +IMPORT_TEST_GROUP(coap_connection_handler); + diff --git a/test/coap-service/unittest/coap_connection_handler/test_coap_connection_handler.c b/test/coap-service/unittest/coap_connection_handler/test_coap_connection_handler.c new file mode 100644 index 0000000000..8a226d88e8 --- /dev/null +++ b/test/coap-service/unittest/coap_connection_handler/test_coap_connection_handler.c @@ -0,0 +1,467 @@ +/* + * Copyright (c) 2015 ARM. All rights reserved. + */ +#include "test_coap_connection_handler.h" +#include +#include +#include "nsdynmemLIB_stub.h" +#include "mbedtls/ssl.h" +#include "coap_connection_handler.h" +#include "coap_security_handler_stub.h" +#include "ns_timer_stub.h" +#include "socket_api.h" +#include "socket_api_stub.h" +#include "net_interface.h" + +int send_to_sock_cb(int8_t socket_id, uint8_t address, uint16_t port, const unsigned char *a, int b) +{ + return 1; +} + +int receive_from_sock_cb(int8_t socket_id, uint8_t address, uint16_t port, unsigned char *a, int b) +{ + return 1; +} + +int get_passwd_cb(int8_t socket_id, uint8_t address, uint16_t port, uint8_t *pw_ptr, uint8_t *pw_len) +{ + return 0; +} + +void sec_done_cb(int8_t socket_id, uint8_t address[static 16], uint16_t port, uint8_t keyblock[static 40]) +{ + return 1; +} + +bool test_connection_handler_create() +{ + coap_security_handler_stub.counter = -1; + if( NULL != connection_handler_create(NULL, NULL, NULL, NULL) ) + return false; + + if( NULL != connection_handler_create(&receive_from_sock_cb, NULL, NULL, NULL) ) + return false; + + nsdynmemlib_stub.returnCounter = 1; + thread_conn_handler_t *handler = connection_handler_create(&receive_from_sock_cb, NULL, NULL, NULL); + if( NULL == handler ) + return false; + ns_dyn_mem_free(handler); + return true; +} + +bool test_connection_handler_destroy() +{ + coap_security_handler_stub.counter = -1; + nsdynmemlib_stub.returnCounter = 1; + thread_conn_handler_t *handler = connection_handler_create(&receive_from_sock_cb, NULL, NULL, NULL); + + connection_handler_destroy(handler); + return true; +} + +bool test_coap_connection_handler_open_connection() +{ + coap_security_handler_stub.counter = -1; + nsdynmemlib_stub.returnCounter = 1; + thread_conn_handler_t *handler = connection_handler_create(&receive_from_sock_cb, NULL, NULL, NULL); + + if( -1 != coap_connection_handler_open_connection(NULL, 0,false,false,false,false) ) + return false; + + if( -1 != coap_connection_handler_open_connection(handler, 0,false,false,false,false) ) + return false; + + ns_dyn_mem_free(handler); + nsdynmemlib_stub.returnCounter = 1; + handler = connection_handler_create(&receive_from_sock_cb, &send_to_sock_cb, NULL, NULL); + if( -1 != coap_connection_handler_open_connection(handler, 0,true,true,true,false) ) + return false; + + nsdynmemlib_stub.returnCounter = 2; + if( 0 != coap_connection_handler_open_connection(handler, 0,true,true,true,false) ) + return false; + + nsdynmemlib_stub.returnCounter = 1; + if( 0 != coap_connection_handler_open_connection(handler, 22,false,true,true,true) ) + return false; + + //open second one + nsdynmemlib_stub.returnCounter = 1; + thread_conn_handler_t *handler2 = connection_handler_create(&receive_from_sock_cb, &send_to_sock_cb, NULL, NULL); + nsdynmemlib_stub.returnCounter = 1; + if( 0 != coap_connection_handler_open_connection(handler2, 22,false,true,true,true) ) + return false; + + if( 0 != coap_connection_handler_open_connection(handler, 23,false,false,false,false) ) + return false; + + connection_handler_destroy(handler2); + connection_handler_destroy(handler); + return true; +} + +bool test_coap_connection_handler_send_data() +{ + coap_security_handler_stub.counter = -1; + if( -1 != coap_connection_handler_send_data(NULL, NULL, NULL, 0, false)) + return false; + + ns_address_t addr; + memset(addr.address, 1, 16); + addr.identifier = 22; + + nsdynmemlib_stub.returnCounter = 1; + thread_conn_handler_t *handler = connection_handler_create(&receive_from_sock_cb, &send_to_sock_cb, NULL, NULL); + nsdynmemlib_stub.returnCounter = 1; + if( 0 != coap_connection_handler_open_connection(handler, 22,false,true,false,false) ) + return false; + + if( -1 != coap_connection_handler_send_data(handler, &addr, NULL, 0, true)) + return false; + + connection_handler_destroy(handler); + + coap_security_handler_stub.sec_obj = (thread_security_t *)malloc(sizeof(thread_security_t)); + memset(coap_security_handler_stub.sec_obj, 0, sizeof(thread_security_t)); + coap_security_handler_stub.sec_obj->_remote_port = 22; + memset(coap_security_handler_stub.sec_obj->_remote_address, 1, 16 ); + + nsdynmemlib_stub.returnCounter = 1; + handler = connection_handler_create(&receive_from_sock_cb, &send_to_sock_cb, NULL, NULL); + nsdynmemlib_stub.returnCounter = 3; + if( 0 != coap_connection_handler_open_connection(handler, 22,false,true,false,false) ) + return false; + + if( -1 != coap_connection_handler_send_data(handler, &addr, NULL, 0, true)) + return false; + + if( -1 != coap_connection_handler_send_data(handler, &addr, NULL, 0, true)) + return false; + + connection_handler_destroy(handler); + + free(coap_security_handler_stub.sec_obj); + coap_security_handler_stub.sec_obj = NULL; + + //NON SECURE HERE --> + nsdynmemlib_stub.returnCounter = 1; + handler = connection_handler_create(&receive_from_sock_cb, &send_to_sock_cb, NULL, NULL); + nsdynmemlib_stub.returnCounter = 1; + if( 0 != coap_connection_handler_open_connection(handler, 22,false,false,false,false) ) + return false; + + + if( 1 != coap_connection_handler_send_data(handler, &addr, NULL, 0, true)) + return false; + connection_handler_destroy(handler); + + nsdynmemlib_stub.returnCounter = 1; + handler = connection_handler_create(&receive_from_sock_cb, &send_to_sock_cb, NULL, NULL); + nsdynmemlib_stub.returnCounter = 1; + if( 0 != coap_connection_handler_open_connection(handler, 22,false,false,true,false) ) + return false; + + socket_api_stub.int8_value = 7; + if( 7 != coap_connection_handler_send_data(handler, &addr, NULL, 0, true)) + return false; + connection_handler_destroy(handler); + + //<-- NON SECURE HERE + + return true; +} + +bool test_coap_connection_handler_virtual_recv() +{ + coap_security_handler_stub.counter = -1; + uint8_t buf[16]; + memset(&buf, 1, 16); + if( -1 != coap_connection_handler_virtual_recv(NULL,buf, 12, NULL, 0) ) + return false; + + nsdynmemlib_stub.returnCounter = 1; + thread_conn_handler_t *handler = connection_handler_create(&receive_from_sock_cb, &send_to_sock_cb, NULL, NULL); + nsdynmemlib_stub.returnCounter = 1; + if( 0 != coap_connection_handler_open_connection(handler, 22,false,true,true,false) ) + return false; + + if( -1 != coap_connection_handler_virtual_recv(handler,buf, 12, NULL, 0) ) + return false; + + nsdynmemlib_stub.returnCounter = 1; + if( -1 != coap_connection_handler_virtual_recv(handler,buf, 12, NULL, 0) ) + return false; + + ns_timer_stub.int8_value = 0; + nsdynmemlib_stub.returnCounter = 3; + if( -1 != coap_connection_handler_virtual_recv(handler,buf, 12, &buf, 1) ) + return false; + + //handler->socket->data still in memory + coap_security_handler_stub.sec_obj = (thread_security_t *)malloc(sizeof(thread_security_t)); + memset(coap_security_handler_stub.sec_obj, 0, sizeof(thread_security_t)); + coap_security_handler_stub.sec_obj->_remote_port = 55; + memset(coap_security_handler_stub.sec_obj->_remote_address, 4, 16 ); + + ns_timer_stub.int8_value = -1; + nsdynmemlib_stub.returnCounter = 3; + if( -1 != coap_connection_handler_virtual_recv(handler,buf, 12, &buf, 1) ) + return false; + + ns_timer_stub.int8_value = 0; + nsdynmemlib_stub.returnCounter = 3; + if( -1 != coap_connection_handler_virtual_recv(handler,buf, 12, &buf, 1) ) + return false; + + connection_handler_destroy(handler); + + nsdynmemlib_stub.returnCounter = 1; + thread_conn_handler_t *handler2 = connection_handler_create(&receive_from_sock_cb, &send_to_sock_cb, &get_passwd_cb, &sec_done_cb); + nsdynmemlib_stub.returnCounter = 1; + if( 0 != coap_connection_handler_open_connection(handler2, 24,false,true,true,false) ) + return false; + + nsdynmemlib_stub.returnCounter = 3; + if( 0 != coap_connection_handler_virtual_recv(handler2,buf, 12, &buf, 1) ) + return false; + + nsdynmemlib_stub.returnCounter = 1; + coap_security_handler_stub.sec_obj->_remote_port = 12; + memset(coap_security_handler_stub.sec_obj->_remote_address, 1, 16 ); + if( 0 != coap_connection_handler_virtual_recv(handler2,buf, 12, &buf, 1) ) + return false; + + nsdynmemlib_stub.returnCounter = 1; + if( 0 != coap_connection_handler_virtual_recv(handler2,buf, 12, &buf, 1) ) + return false; + + nsdynmemlib_stub.returnCounter = 1; + coap_security_handler_stub.int_value = MBEDTLS_ERR_SSL_PEER_CLOSE_NOTIFY; + if( 0 != coap_connection_handler_virtual_recv(handler2,buf, 12, &buf, 1) ) + return false; + + connection_handler_destroy(handler2); + + free(coap_security_handler_stub.sec_obj); + coap_security_handler_stub.sec_obj = NULL; + + nsdynmemlib_stub.returnCounter = 1; + thread_conn_handler_t *handler3 = connection_handler_create(&receive_from_sock_cb, &send_to_sock_cb, &get_passwd_cb, &sec_done_cb); + nsdynmemlib_stub.returnCounter = 1; + if( 0 != coap_connection_handler_open_connection(handler3, 26,false,false,true,false) ) + return false; + + nsdynmemlib_stub.returnCounter = 3; + if( 0 != coap_connection_handler_virtual_recv(handler3,buf, 12, &buf, 1) ) + return false; + + connection_handler_destroy(handler3); + + return true; +} + +bool test_coap_connection_handler_socket_belongs_to() +{ + coap_security_handler_stub.counter = -1; + if( false != coap_connection_handler_socket_belongs_to(NULL, 2) ) + return false; + + socket_api_stub.int8_value = 0; + nsdynmemlib_stub.returnCounter = 1; + thread_conn_handler_t *handler = connection_handler_create(&receive_from_sock_cb, &send_to_sock_cb, NULL, NULL); + nsdynmemlib_stub.returnCounter = 1; + if( 0 != coap_connection_handler_open_connection(handler, 22,false,true,true,false) ) + return false; + + if( true != coap_connection_handler_socket_belongs_to(handler, 0) ) + return false; + + if( false != coap_connection_handler_socket_belongs_to(handler, 3) ) + return false; + connection_handler_destroy(handler); + + nsdynmemlib_stub.returnCounter = 0; + return true; +} + +bool test_timer_callbacks() +{ + coap_security_handler_stub.counter = -1; + uint8_t buf[16]; + memset(&buf, 1, 16); + + nsdynmemlib_stub.returnCounter = 1; + thread_conn_handler_t *handler = connection_handler_create(&receive_from_sock_cb, &send_to_sock_cb, NULL, NULL); + nsdynmemlib_stub.returnCounter = 1; + if( 0 != coap_connection_handler_open_connection(handler, 22,false,true,true,false) ) + return false; + + //handler->socket->data still in memory + coap_security_handler_stub.sec_obj = (thread_security_t *)malloc(sizeof(thread_security_t)); + memset(coap_security_handler_stub.sec_obj, 0, sizeof(thread_security_t)); + coap_security_handler_stub.sec_obj->_remote_port = 55; + memset(coap_security_handler_stub.sec_obj->_remote_address, 4, 16 ); + coap_security_handler_stub.sec_obj->_timer_id = 5; + + ns_timer_stub.int8_value = 0; + nsdynmemlib_stub.returnCounter = 3; + ns_timer_stub.int8_value = 5; + if( -1 != coap_connection_handler_virtual_recv(handler,buf, 12, &buf, 1) ) + return false; + + //Note next tests will affect ns_timer test (cycle & cycle_count + if( coap_security_handler_stub.start_timer_cb ){ + coap_security_handler_stub.start_timer_cb(5, 0, 0); + + coap_security_handler_stub.start_timer_cb(5, 1, 2); + } + + if( coap_security_handler_stub.timer_status_cb ){ + if( -1 != coap_security_handler_stub.timer_status_cb(4) ) + return false; + + if( 0 != coap_security_handler_stub.timer_status_cb(5) ) + return false; + } + + if( ns_timer_stub.cb ){ + ns_timer_stub.cb(4, 0); + + ns_timer_stub.cb(5, 0); + + coap_security_handler_stub.int_value = MBEDTLS_ERR_SSL_TIMEOUT; + + ns_timer_stub.cb(5, 0); + coap_security_handler_stub.int_value = 0; + } + + connection_handler_destroy(handler); + free(coap_security_handler_stub.sec_obj); + coap_security_handler_stub.sec_obj = NULL; + return true; +} + +bool test_socket_api_callbacks() +{ + coap_security_handler_stub.counter = -1; + uint8_t buf[16]; + memset(&buf, 1, 16); + + socket_callback_t *sckt_data = (socket_callback_t *)malloc(sizeof(socket_callback_t)); + memset(sckt_data, 0, sizeof(socket_callback_t)); + + coap_security_handler_stub.sec_obj = (thread_security_t *)malloc(sizeof(thread_security_t)); + memset(coap_security_handler_stub.sec_obj, 0, sizeof(thread_security_t)); + + socket_api_stub.int8_value = 0; + nsdynmemlib_stub.returnCounter = 1; + thread_conn_handler_t *handler = connection_handler_create(&receive_from_sock_cb, &send_to_sock_cb, NULL, NULL); + nsdynmemlib_stub.returnCounter = 1; + if( 0 != coap_connection_handler_open_connection(handler, 22,false,false,true,false) ) + return false; + + if( socket_api_stub.recv_cb ){ + sckt_data->event_type = SOCKET_DATA; + sckt_data->d_len = 1; + socket_api_stub.int8_value = -1; + socket_api_stub.recv_cb(sckt_data); + + nsdynmemlib_stub.returnCounter = 1; + socket_api_stub.recv_cb(sckt_data); + + nsdynmemlib_stub.returnCounter = 1; + socket_api_stub.int8_value = 1; + socket_api_stub.recv_cb(sckt_data); + } + + connection_handler_destroy(handler); + + nsdynmemlib_stub.returnCounter = 1; + thread_conn_handler_t *handler2 = connection_handler_create(&receive_from_sock_cb, &send_to_sock_cb, &get_passwd_cb, &sec_done_cb); + nsdynmemlib_stub.returnCounter = 1; + if( 0 != coap_connection_handler_open_connection(handler2, 22,false,true,true,false) ) + return false; + + if( socket_api_stub.recv_cb ){ + nsdynmemlib_stub.returnCounter = 1; + socket_api_stub.int8_value = 1; + sckt_data->socket_id = 1; + socket_api_stub.recv_cb(sckt_data); + + nsdynmemlib_stub.returnCounter = 2; + socket_api_stub.int8_value = 1; + sckt_data->socket_id = 1; + socket_api_stub.recv_cb(sckt_data); + + nsdynmemlib_stub.returnCounter = 1; + socket_api_stub.int8_value = 1; + sckt_data->socket_id = 1; + socket_api_stub.recv_cb(sckt_data); + + coap_security_handler_stub.int_value = 4; + nsdynmemlib_stub.returnCounter = 1; + socket_api_stub.int8_value = 1; + sckt_data->socket_id = 1; + socket_api_stub.recv_cb(sckt_data); + + coap_security_handler_stub.int_value = MBEDTLS_ERR_SSL_PEER_CLOSE_NOTIFY; + nsdynmemlib_stub.returnCounter = 1; + socket_api_stub.int8_value = 1; + sckt_data->socket_id = 1; + socket_api_stub.recv_cb(sckt_data); + } + + connection_handler_destroy(handler2); + + free(coap_security_handler_stub.sec_obj); + coap_security_handler_stub.sec_obj = NULL; + + free(sckt_data); + sckt_data = NULL; + return true; +} + +bool test_security_callbacks() +{ + coap_security_handler_stub.counter = -1; + uint8_t buf[16]; + memset(&buf, 1, 16); + + socket_callback_t *sckt_data = (socket_callback_t *)malloc(sizeof(socket_callback_t)); + memset(sckt_data, 0, sizeof(socket_callback_t)); + + coap_security_handler_stub.sec_obj = (thread_security_t *)malloc(sizeof(thread_security_t)); + memset(coap_security_handler_stub.sec_obj, 0, sizeof(thread_security_t)); + + nsdynmemlib_stub.returnCounter = 1; + thread_conn_handler_t *handler = connection_handler_create(&receive_from_sock_cb, &send_to_sock_cb, NULL, NULL); + nsdynmemlib_stub.returnCounter = 1; + if( 0 != coap_connection_handler_open_connection(handler, 22,false,true,true,false) ) + return false; + + if( socket_api_stub.recv_cb ){ + sckt_data->event_type = SOCKET_DATA; + sckt_data->d_len = 1; + nsdynmemlib_stub.returnCounter = 2; + socket_api_stub.int8_value = 1; + sckt_data->socket_id = 0; + socket_api_stub.recv_cb(sckt_data); + } + + if( coap_security_handler_stub.send_cb ){ + coap_security_handler_stub.send_cb(0, buf, 22, &buf, 16); + } + if( coap_security_handler_stub.receive_cb ){ + coap_security_handler_stub.receive_cb(0, &buf, 16); + } + + connection_handler_destroy(handler); + + free(coap_security_handler_stub.sec_obj); + coap_security_handler_stub.sec_obj = NULL; + + free(sckt_data); + sckt_data = NULL; + return true; +} diff --git a/test/coap-service/unittest/coap_connection_handler/test_coap_connection_handler.h b/test/coap-service/unittest/coap_connection_handler/test_coap_connection_handler.h new file mode 100644 index 0000000000..7398a2e276 --- /dev/null +++ b/test/coap-service/unittest/coap_connection_handler/test_coap_connection_handler.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2015 ARM. All rights reserved. + */ +#ifndef TEST_COAP_CONNECTION_HANDLER_H +#define TEST_COAP_CONNECTION_HANDLER_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +bool test_connection_handler_create(); + +bool test_connection_handler_destroy(); + +bool test_coap_connection_handler_open_connection(); + +bool test_coap_connection_handler_send_data(); + +bool test_coap_connection_handler_virtual_recv(); + +bool test_coap_connection_handler_socket_belongs_to(); + +bool test_timer_callbacks(); + +bool test_socket_api_callbacks(); + +bool test_security_callbacks(); + +#ifdef __cplusplus +} +#endif + +#endif // TEST_COAP_CONNECTION_HANDLER_H + diff --git a/test/coap-service/unittest/coap_message_handler/Makefile b/test/coap-service/unittest/coap_message_handler/Makefile new file mode 100644 index 0000000000..8ca92aaf85 --- /dev/null +++ b/test/coap-service/unittest/coap_message_handler/Makefile @@ -0,0 +1,23 @@ +include ../makefile_defines.txt + +COMPONENT_NAME = coap_message_handler_unit + +#This must be changed manually +SRC_FILES = \ + ../../../../source/coap_message_handler.c + +TEST_SRC_FILES = \ + main.cpp \ + coap_message_handlertest.cpp \ + test_coap_message_handler.c \ + ../stub/ns_trace_stub.c \ + ../stub/sn_coap_protocol_stub.c \ + ../stub/sn_coap_parser_stub.c \ + ../stub/sn_coap_builder_stub.c \ + ../stub/nsdynmemLIB_stub.c \ + ../stub/ns_list_stub.c \ + +include ../MakefileWorker.mk + +CPPUTESTFLAGS += -DFEA_TRACE_SUPPORT + diff --git a/test/coap-service/unittest/coap_message_handler/coap_message_handlertest.cpp b/test/coap-service/unittest/coap_message_handler/coap_message_handlertest.cpp new file mode 100644 index 0000000000..e36d92667d --- /dev/null +++ b/test/coap-service/unittest/coap_message_handler/coap_message_handlertest.cpp @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2015 ARM. All rights reserved. + */ +#include "CppUTest/TestHarness.h" +#include "test_coap_message_handler.h" + +TEST_GROUP(coap_message_handler) +{ + void setup() + { + } + + void teardown() + { + } +}; + +TEST(coap_message_handler, test_coap_message_handler_init) +{ + CHECK(test_coap_message_handler_init()); +} + +TEST(coap_message_handler, test_coap_message_handler_destroy) +{ + CHECK(test_coap_message_handler_destroy()); +} + +TEST(coap_message_handler, test_coap_message_handler_find_transaction) +{ + CHECK(test_coap_message_handler_find_transaction()); +} + +TEST(coap_message_handler, test_coap_message_handler_coap_msg_process) +{ + CHECK(test_coap_message_handler_coap_msg_process()); +} + +TEST(coap_message_handler, test_coap_message_handler_request_send) +{ + CHECK(test_coap_message_handler_request_send()); +} + +TEST(coap_message_handler, test_coap_message_handler_response_send) +{ + CHECK(test_coap_message_handler_response_send()); +} + +TEST(coap_message_handler, test_coap_message_handler_exec) +{ + CHECK(test_coap_message_handler_exec()); +} + diff --git a/test/coap-service/unittest/coap_message_handler/main.cpp b/test/coap-service/unittest/coap_message_handler/main.cpp new file mode 100644 index 0000000000..f042e6bdeb --- /dev/null +++ b/test/coap-service/unittest/coap_message_handler/main.cpp @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2015 ARM. All rights reserved. + */ + +#include "CppUTest/CommandLineTestRunner.h" +#include "CppUTest/TestPlugin.h" +#include "CppUTest/TestRegistry.h" +#include "CppUTestExt/MockSupportPlugin.h" +int main(int ac, char** av) +{ + return CommandLineTestRunner::RunAllTests(ac, av); +} + +IMPORT_TEST_GROUP(coap_message_handler); + diff --git a/test/coap-service/unittest/coap_message_handler/test_coap_message_handler.c b/test/coap-service/unittest/coap_message_handler/test_coap_message_handler.c new file mode 100644 index 0000000000..126e05aa68 --- /dev/null +++ b/test/coap-service/unittest/coap_message_handler/test_coap_message_handler.c @@ -0,0 +1,298 @@ +/* + * Copyright (c) 2015 ARM. All rights reserved. + */ +#include "test_coap_message_handler.h" +#include +#include "coap_message_handler.h" +#include "sn_coap_protocol_stub.h" +#include "nsdynmemLIB_stub.h" +#include "sn_coap_builder_stub.h" +#include "sn_coap_parser_stub.h" + +int retCounter = 0; +int retValue = 0; + +static void *own_alloc(uint16_t size) +{ + if( retCounter > 0 ){ + retCounter--; + return malloc(size); + } + return NULL; +} + +static void own_free(void *ptr) +{ + if (ptr) { + free(ptr); + } +} + +static uint8_t coap_tx_function(uint8_t *data_ptr, uint16_t data_len, sn_nsdl_addr_s *address_ptr, void *param) +{ + return 0; +} + +int resp_recv(int8_t service_id, uint16_t msg_id, sn_coap_hdr_s *response_ptr){ + return retValue; +} + +int16_t process_cb(int8_t a, sn_coap_hdr_s *b, coap_transaction_t *c) +{ + +} + +bool test_coap_message_handler_init() +{ + if( NULL != coap_message_handler_init(NULL, NULL, NULL) ) + return false; + if( NULL != coap_message_handler_init(&own_alloc, NULL, NULL) ) + return false; + if( NULL != coap_message_handler_init(&own_alloc, &own_free, NULL) ) + return false; + if( NULL != coap_message_handler_init(&own_alloc, &own_free, &coap_tx_function) ) + return false; + retCounter = 1; + sn_coap_protocol_stub.expectedCoap = NULL; + if( NULL != coap_message_handler_init(&own_alloc, &own_free, &coap_tx_function) ) + return false; + retCounter = 1; + sn_coap_protocol_stub.expectedCoap = (struct coap_s*)malloc(sizeof(struct coap_s)); + memset(sn_coap_protocol_stub.expectedCoap, 0, sizeof(struct coap_s)); + coap_msg_handler_t *handle = coap_message_handler_init(&own_alloc, &own_free, &coap_tx_function); + if( NULL == handle ) + return false; + free(sn_coap_protocol_stub.expectedCoap); + sn_coap_protocol_stub.expectedCoap = NULL; + free(handle); + return true; +} + +bool test_coap_message_handler_destroy() +{ + if( -1 != coap_message_handler_destroy(NULL) ) + return false; + retCounter = 1; + sn_coap_protocol_stub.expectedCoap = (struct coap_s*)malloc(sizeof(struct coap_s)); + memset(sn_coap_protocol_stub.expectedCoap, 0, sizeof(struct coap_s)); + coap_msg_handler_t *handle = coap_message_handler_init(&own_alloc, &own_free, &coap_tx_function); + + if( 0 != coap_message_handler_destroy(handle) ) + return false; + + free(sn_coap_protocol_stub.expectedCoap); + return true; +} + +bool test_coap_message_handler_find_transaction() +{ + if( NULL != coap_message_handler_find_transaction(NULL, 0)) + return false; + retCounter = 1; + sn_coap_protocol_stub.expectedCoap = (struct coap_s*)malloc(sizeof(struct coap_s)); + memset(sn_coap_protocol_stub.expectedCoap, 0, sizeof(struct coap_s)); + coap_msg_handler_t *handle = coap_message_handler_init(&own_alloc, &own_free, &coap_tx_function); + + uint8_t buf[16]; + memset(&buf, 1, 16); + char uri[3]; + uri[0] = "r"; + uri[1] = "s"; + uri[2] = "\0"; + + sn_coap_builder_stub.expectedUint16 = 1; + nsdynmemlib_stub.returnCounter = 3; + if( 2 != coap_message_handler_request_send(handle, 3, 0, buf, 24, 1, 2, &uri, 4, NULL, 0, &resp_recv)) + return false; + + if( NULL == coap_message_handler_find_transaction(&buf, 24)) + return false; + + free(sn_coap_protocol_stub.expectedCoap); + sn_coap_protocol_stub.expectedCoap = NULL; + coap_message_handler_destroy(handle); + return true; +} + +bool test_coap_message_handler_coap_msg_process() +{ + uint8_t buf[16]; + memset(&buf, 1, 16); + if( -1 != coap_message_handler_coap_msg_process(NULL, 0, buf, 22, NULL, 0, NULL)) + return false; + + retCounter = 1; + sn_coap_protocol_stub.expectedCoap = (struct coap_s*)malloc(sizeof(struct coap_s)); + memset(sn_coap_protocol_stub.expectedCoap, 0, sizeof(struct coap_s)); + coap_msg_handler_t *handle = coap_message_handler_init(&own_alloc, &own_free, &coap_tx_function); + + sn_coap_protocol_stub.expectedHeader = NULL; + if( -1 != coap_message_handler_coap_msg_process(handle, 0, buf, 22, NULL, 0, process_cb)) + return false; + + sn_coap_protocol_stub.expectedHeader = (sn_coap_hdr_s *)malloc(sizeof(sn_coap_hdr_s)); + memset(sn_coap_protocol_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); + sn_coap_protocol_stub.expectedHeader->coap_status = 66; + if( -1 != coap_message_handler_coap_msg_process(handle, 0, buf, 22, NULL, 0, process_cb)) + return false; + + sn_coap_protocol_stub.expectedHeader = (sn_coap_hdr_s *)malloc(sizeof(sn_coap_hdr_s)); + memset(sn_coap_protocol_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); + sn_coap_protocol_stub.expectedHeader->coap_status = COAP_STATUS_OK; + sn_coap_protocol_stub.expectedHeader->msg_code = 1; + retValue = -1; + if( 0 != coap_message_handler_coap_msg_process(handle, 0, buf, 22, NULL, 0, process_cb)) + return false; + + nsdynmemlib_stub.returnCounter = 1; + if( -1 != coap_message_handler_coap_msg_process(handle, 0, buf, 22, NULL, 0, process_cb)) + return false; + + sn_coap_protocol_stub.expectedHeader = (sn_coap_hdr_s *)malloc(sizeof(sn_coap_hdr_s)); + memset(sn_coap_protocol_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); + sn_coap_protocol_stub.expectedHeader->coap_status = COAP_STATUS_OK; + sn_coap_protocol_stub.expectedHeader->msg_code = 333; + + if( -1 != coap_message_handler_coap_msg_process(handle, 0, buf, 22, NULL, 0, process_cb)) + return false; + + sn_coap_protocol_stub.expectedHeader = (sn_coap_hdr_s *)malloc(sizeof(sn_coap_hdr_s)); + memset(sn_coap_protocol_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); + sn_coap_protocol_stub.expectedHeader->coap_status = COAP_STATUS_OK; + sn_coap_protocol_stub.expectedHeader->msg_code = 333; + + char uri[3]; + uri[0] = "r"; + uri[1] = "s"; + uri[2] = "\0"; + + sn_coap_builder_stub.expectedUint16 = 1; + nsdynmemlib_stub.returnCounter = 3; + if( 2 != coap_message_handler_request_send(handle, 3, 0, buf, 24, 1, 2, &uri, 4, NULL, 0, &resp_recv)) + return false; + + sn_coap_protocol_stub.expectedHeader->msg_id = 2; + if( 0 != coap_message_handler_coap_msg_process(handle, 0, buf, 22, NULL, 0, process_cb)) + return false; + +// free(sn_coap_protocol_stub.expectedHeader); +// sn_coap_protocol_stub.expectedHeader = NULL; + free(sn_coap_protocol_stub.expectedCoap); + sn_coap_protocol_stub.expectedCoap = NULL; + coap_message_handler_destroy(handle); + return true; +} + +bool test_coap_message_handler_request_send() +{ + retCounter = 1; + sn_coap_protocol_stub.expectedCoap = (struct coap_s*)malloc(sizeof(struct coap_s)); + memset(sn_coap_protocol_stub.expectedCoap, 0, sizeof(struct coap_s)); + coap_msg_handler_t *handle = coap_message_handler_init(&own_alloc, &own_free, &coap_tx_function); + + uint8_t buf[16]; + memset(&buf, 1, 16); + char uri[3]; + uri[0] = "r"; + uri[1] = "s"; + uri[2] = "\0"; + if( 0 != coap_message_handler_request_send(handle, 3, 0, buf, 24, 1, 2, &uri, 4, NULL, 0, NULL)) + return false; + + sn_coap_builder_stub.expectedUint16 = 1; + nsdynmemlib_stub.returnCounter = 1; + if( 0 != coap_message_handler_request_send(handle, 3, 0, buf, 24, 1, 2, &uri, 4, NULL, 0, NULL)) + return false; + + sn_coap_builder_stub.expectedUint16 = 1; + nsdynmemlib_stub.returnCounter = 3; + if( 0 != coap_message_handler_request_send(handle, 3, 0, buf, 24, 1, 2, &uri, 4, NULL, 0, NULL)) + return false; + + sn_coap_builder_stub.expectedUint16 = 1; + nsdynmemlib_stub.returnCounter = 3; + if( 0 != coap_message_handler_request_send(handle, 3, 0, buf, 24, 1, 2, &uri, 4, NULL, 0, NULL)) + return false; + + sn_coap_builder_stub.expectedUint16 = 1; + nsdynmemlib_stub.returnCounter = 3; + if( 2 != coap_message_handler_request_send(handle, 3, 0, buf, 24, 1, 2, &uri, 4, NULL, 0, &resp_recv)) + return false; + + free(sn_coap_protocol_stub.expectedCoap); + sn_coap_protocol_stub.expectedCoap = NULL; + coap_message_handler_destroy(handle); + return true; +} + +bool test_coap_message_handler_response_send() +{ + if( -1 != coap_message_handler_response_send(NULL, 2, 0, NULL, 1,3,NULL, 0)) + return false; + + retCounter = 1; + sn_coap_protocol_stub.expectedCoap = (struct coap_s*)malloc(sizeof(struct coap_s)); + memset(sn_coap_protocol_stub.expectedCoap, 0, sizeof(struct coap_s)); + coap_msg_handler_t *handle = coap_message_handler_init(&own_alloc, &own_free, &coap_tx_function); + sn_coap_hdr_s *header = (sn_coap_hdr_s *)malloc(sizeof(sn_coap_hdr_s)); + memset(header, 0, sizeof(sn_coap_hdr_s)); + + if( -2 != coap_message_handler_response_send(handle, 2, 0, header, 1,3,NULL, 0)) + return false; + + uint8_t buf[16]; + memset(&buf, 1, 16); + char uri[3]; + uri[0] = "r"; + uri[1] = "s"; + uri[2] = "\0"; + sn_coap_builder_stub.expectedUint16 = 1; + nsdynmemlib_stub.returnCounter = 3; + if( 2 != coap_message_handler_request_send(handle, 3, 0, buf, 24, 1, 2, &uri, 4, NULL, 0, &resp_recv)) + return false; + + header->msg_id = 2; + sn_coap_builder_stub.expectedUint16 = 2; + coap_transaction_t * tx = coap_message_handler_find_transaction(&buf, 24); + if( tx ){ + tx->client_request = false; + } + sn_coap_builder_stub.expectedHeader = NULL; + if( -1 != coap_message_handler_response_send(handle, 2, 0, header, 1,3,NULL, 0)) + return false; + + sn_coap_builder_stub.expectedHeader = (sn_coap_hdr_s *)malloc(sizeof(sn_coap_hdr_s)); + memset(sn_coap_builder_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); + nsdynmemlib_stub.returnCounter = 1; + if( -1 != coap_message_handler_response_send(handle, 2, 0, header, 1,3,NULL, 0)) + return false; + + sn_coap_builder_stub.expectedHeader = (sn_coap_hdr_s *)malloc(sizeof(sn_coap_hdr_s)); + memset(sn_coap_builder_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s)); + nsdynmemlib_stub.returnCounter = 2; + if( 0 != coap_message_handler_response_send(handle, 2, 0, header, 1,3,NULL, 0)) + return false; + +// free(header); + free(sn_coap_protocol_stub.expectedCoap); + sn_coap_protocol_stub.expectedCoap = NULL; + coap_message_handler_destroy(handle); + return true; +} + +bool test_coap_message_handler_exec() +{ + if( -1 != coap_message_handler_exec(NULL, 0)) + return false; + retCounter = 1; + sn_coap_protocol_stub.expectedCoap = (struct coap_s*)malloc(sizeof(struct coap_s)); + memset(sn_coap_protocol_stub.expectedCoap, 0, sizeof(struct coap_s)); + coap_msg_handler_t *handle = coap_message_handler_init(&own_alloc, &own_free, &coap_tx_function); + if( 0 != coap_message_handler_exec(handle, 0)) + return false; + + free(sn_coap_protocol_stub.expectedCoap); + sn_coap_protocol_stub.expectedCoap = NULL; + coap_message_handler_destroy(handle); + return true; +} diff --git a/test/coap-service/unittest/coap_message_handler/test_coap_message_handler.h b/test/coap-service/unittest/coap_message_handler/test_coap_message_handler.h new file mode 100644 index 0000000000..2b850a0afa --- /dev/null +++ b/test/coap-service/unittest/coap_message_handler/test_coap_message_handler.h @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2015 ARM. All rights reserved. + */ +#ifndef TEST_COAP_MESSAGE_HANDLER_H +#define TEST_COAP_MESSAGE_HANDLER_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +bool test_coap_message_handler_init(); +bool test_coap_message_handler_destroy(); +bool test_coap_message_handler_find_transaction(); +bool test_coap_message_handler_coap_msg_process(); +bool test_coap_message_handler_request_send(); +bool test_coap_message_handler_response_send(); +bool test_coap_message_handler_exec(); + +#ifdef __cplusplus +} +#endif + +#endif // TEST_COAP_MESSAGE_HANDLER_H + diff --git a/test/coap-service/unittest/coap_security_handler/Makefile b/test/coap-service/unittest/coap_security_handler/Makefile new file mode 100644 index 0000000000..6923474bbd --- /dev/null +++ b/test/coap-service/unittest/coap_security_handler/Makefile @@ -0,0 +1,23 @@ +include ../makefile_defines.txt + +COMPONENT_NAME = coap_security_handler_unit + +#This must be changed manually +SRC_FILES = \ + ../../../../source/coap_security_handler.c + +TEST_SRC_FILES = \ + main.cpp \ + coap_security_handlertest.cpp \ + test_coap_security_handler.c \ + ../stub/ns_trace_stub.c \ + ../stub/ns_list_stub.c \ + ../stub/ns_timer_stub.c \ + ../stub/mbedtls_stub.c \ + ../stub/randLIB_stub.c \ + ../stub/nsdynmemLIB_stub.c \ + +include ../MakefileWorker.mk + +CPPUTESTFLAGS += -DFEA_TRACE_SUPPORT + diff --git a/test/coap-service/unittest/coap_security_handler/coap_security_handlertest.cpp b/test/coap-service/unittest/coap_security_handler/coap_security_handlertest.cpp new file mode 100644 index 0000000000..a649a0fb96 --- /dev/null +++ b/test/coap-service/unittest/coap_security_handler/coap_security_handlertest.cpp @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2015 ARM. All rights reserved. + */ +#include "CppUTest/TestHarness.h" +#include "test_coap_security_handler.h" +#include "mbedtls_stub.h" +#include "nsdynmemLIB_stub.h" + +TEST_GROUP(coap_security_handler) +{ + void setup() + { + nsdynmemlib_stub.returnCounter = 0; + mbedtls_stub.useCounter = false; + } + + void teardown() + { + } +}; + +TEST(coap_security_handler, test_thread_security_create) +{ + CHECK(test_thread_security_create()); +} + +TEST(coap_security_handler, test_thread_security_destroy) +{ + CHECK(test_thread_security_destroy()); +} + +TEST(coap_security_handler, test_coap_security_handler_connect) +{ + CHECK(test_coap_security_handler_connect()); +} + +TEST(coap_security_handler, test_coap_security_handler_continue_connecting) +{ + CHECK(test_coap_security_handler_continue_connecting()); +} + +TEST(coap_security_handler, test_coap_security_handler_send_message) +{ + CHECK(test_coap_security_handler_send_message()); +} + +TEST(coap_security_handler, test_thread_security_send_close_alert) +{ + CHECK(test_thread_security_send_close_alert()); +} + +TEST(coap_security_handler, test_coap_security_handler_read) +{ + CHECK(test_coap_security_handler_read()); +} diff --git a/test/coap-service/unittest/coap_security_handler/main.cpp b/test/coap-service/unittest/coap_security_handler/main.cpp new file mode 100644 index 0000000000..e657503fd1 --- /dev/null +++ b/test/coap-service/unittest/coap_security_handler/main.cpp @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2015 ARM. All rights reserved. + */ + +#include "CppUTest/CommandLineTestRunner.h" +#include "CppUTest/TestPlugin.h" +#include "CppUTest/TestRegistry.h" +#include "CppUTestExt/MockSupportPlugin.h" +int main(int ac, char** av) +{ + return CommandLineTestRunner::RunAllTests(ac, av); +} + +IMPORT_TEST_GROUP(coap_security_handler); + diff --git a/test/coap-service/unittest/coap_security_handler/test_coap_security_handler.c b/test/coap-service/unittest/coap_security_handler/test_coap_security_handler.c new file mode 100644 index 0000000000..7bf1b2c6a0 --- /dev/null +++ b/test/coap-service/unittest/coap_security_handler/test_coap_security_handler.c @@ -0,0 +1,281 @@ +/* + * Copyright (c) 2015 ARM. All rights reserved. + */ +#include "test_coap_security_handler.h" +#include "coap_security_handler.h" +#include +#include "nsdynmemLIB_stub.h" +#include "mbedtls_stub.h" +#include "mbedtls/ssl.h" + +static int send_to_socket(int8_t socket_id, uint8_t *address_ptr, uint16_t port, const unsigned char *buf, size_t len) +{ + +} + +static int receive_from_socket(int8_t socket_id, unsigned char *buf, size_t len) +{ + +} + +static void start_timer_callback(int8_t timer_id, uint32_t int_ms, uint32_t fin_ms) +{ + +} + +static int timer_status_callback(int8_t timer_id) +{ + +} + +bool test_thread_security_create() +{ + uint8_t buf[16]; + if( NULL != thread_security_create(1,2,&buf,12,&send_to_socket, &receive_from_socket, &start_timer_callback, NULL) ) + return false; + + if( NULL != thread_security_create(1,2,&buf,12,&send_to_socket, &receive_from_socket, &start_timer_callback, &timer_status_callback) ) + return false; + + nsdynmemlib_stub.returnCounter = 1; + mbedtls_stub.expected_int = -1; + if( NULL != thread_security_create(1,2,&buf,12,&send_to_socket, &receive_from_socket, &start_timer_callback, &timer_status_callback) ) + return false; + + mbedtls_stub.expected_int = 0; + nsdynmemlib_stub.returnCounter = 2; + mbedtls_stub.crt_expected_int = -1; + if( NULL != thread_security_create(1,2,&buf,12,&send_to_socket, &receive_from_socket, &start_timer_callback, &timer_status_callback) ) + return false; + + nsdynmemlib_stub.returnCounter = 2; + mbedtls_stub.crt_expected_int = 0; + thread_security_t *handle = thread_security_create(1,2,&buf,12,&send_to_socket, &receive_from_socket, &start_timer_callback, &timer_status_callback); + if( NULL == handle ) + return false; + + ns_dyn_mem_free(handle); + + return true; +} + +bool test_thread_security_destroy() +{ + uint8_t buf[16]; + nsdynmemlib_stub.returnCounter = 2; + mbedtls_stub.crt_expected_int = 0; + thread_security_t *handle = thread_security_create(1,2,&buf,12,&send_to_socket, &receive_from_socket, &start_timer_callback, &timer_status_callback); + if( NULL == handle ) + return false; + + thread_security_destroy(handle); + return true; +} + +bool test_coap_security_handler_connect() +{ + uint8_t buf[16]; + nsdynmemlib_stub.returnCounter = 2; + mbedtls_stub.crt_expected_int = 0; + thread_security_t *handle = thread_security_create(1,2,&buf,12,&send_to_socket, &receive_from_socket, &start_timer_callback, &timer_status_callback); + if( NULL == handle ) + return false; + + if( -1 != coap_security_handler_connect(NULL, true, "pwd", 3) ) + return false; + mbedtls_stub.useCounter = true; + mbedtls_stub.counter = 0; + mbedtls_stub.retArray[0] = -1; + mbedtls_stub.retArray[1] = -1; + mbedtls_stub.retArray[2] = -1; + mbedtls_stub.retArray[3] = -1; + mbedtls_stub.retArray[4] = -1; + mbedtls_stub.retArray[5] = MBEDTLS_ERR_SSL_HELLO_VERIFY_REQUIRED; + mbedtls_stub.retArray[6] = -1; + mbedtls_stub.retArray[7] = -1; + + if( -1 != coap_security_handler_connect(handle, true, "pwd", 3) ) + return false; + + mbedtls_stub.counter = 0; + mbedtls_stub.retArray[0] = 0; + if( -1 != coap_security_handler_connect(handle, true, "pwd", 3) ) + return false; + + mbedtls_stub.counter = 0; +// mbedtls_stub.retArray[0] = 0; + mbedtls_stub.retArray[1] = 0; + if( -1 != coap_security_handler_connect(handle, true, "pwd", 3) ) + return false; + + simple_cookie_t c; + mbedtls_stub.cookie_obj = &c; + memset(&mbedtls_stub.cookie_value, 1, 8); + mbedtls_stub.cookie_len = 2; + mbedtls_stub.counter = 0; +// mbedtls_stub.retArray[0] = 0; +// mbedtls_stub.retArray[1] = 0; + mbedtls_stub.retArray[2] = 0; + if( -1 != coap_security_handler_connect(handle, true, "pwd", 3) ) + return false; + + c.len = 8; + memset(&c.value, 1, 8); + mbedtls_stub.cookie_obj = &c; + memset(&mbedtls_stub.cookie_value, 1, 8); + + mbedtls_stub.cookie_len = 8; + mbedtls_stub.counter = 0; +// mbedtls_stub.retArray[0] = 0; +// mbedtls_stub.retArray[1] = 0; +// mbedtls_stub.retArray[2] = 0; + mbedtls_stub.retArray[3] = 0; + if( -1 != coap_security_handler_connect(handle, true, "pwd", 3) ) + return false; + + mbedtls_stub.counter = 0; +// mbedtls_stub.retArray[0] = 0; +// mbedtls_stub.retArray[1] = 0; +// mbedtls_stub.retArray[2] = 0; +// mbedtls_stub.retArray[3] = 0; + mbedtls_stub.retArray[4] = 0; + if( -1 != coap_security_handler_connect(handle, true, "pwd", 3) ) + return false; + + mbedtls_stub.counter = 0; +// mbedtls_stub.retArray[0] = 0; +// mbedtls_stub.retArray[1] = 0; +// mbedtls_stub.retArray[2] = 0; +// mbedtls_stub.retArray[3] = 0; +// mbedtls_stub.retArray[4] = 0; + mbedtls_stub.retArray[6] = 0; + mbedtls_stub.retArray[7] = 0; + if( 1 != coap_security_handler_connect(handle, true, "pwd", 3) ) + return false; + + mbedtls_stub.counter = 0; + mbedtls_stub.retArray[5] = MBEDTLS_ERR_SSL_BAD_HS_FINISHED; + + if( -1 != coap_security_handler_connect(handle, true, "pwd", 3) ) + return false; + + mbedtls_stub.counter = 0; + mbedtls_stub.retArray[5] = HANDSHAKE_FINISHED_VALUE; + + if( 1 != coap_security_handler_connect(handle, true, "pwd", 3) ) + return false; + + thread_security_destroy(handle); + return true; +} + +bool test_coap_security_handler_continue_connecting() +{ + uint8_t buf[16]; + nsdynmemlib_stub.returnCounter = 2; + mbedtls_stub.crt_expected_int = 0; + thread_security_t *handle = thread_security_create(1,2,&buf,12,&send_to_socket, &receive_from_socket, &start_timer_callback, &timer_status_callback); + if( NULL == handle ) + return false; + + mbedtls_stub.useCounter = true; + mbedtls_stub.counter = 0; + mbedtls_stub.retArray[0] = MBEDTLS_ERR_SSL_HELLO_VERIFY_REQUIRED; + mbedtls_stub.retArray[1] = -1; + mbedtls_stub.retArray[2] = -1; + + if( -1 != coap_security_handler_continue_connecting(handle) ) + return false; + + mbedtls_stub.counter = 0; + mbedtls_stub.retArray[0] = MBEDTLS_ERR_SSL_HELLO_VERIFY_REQUIRED; + mbedtls_stub.retArray[1] = 0; + mbedtls_stub.retArray[2] = 0; + + if( 1 != coap_security_handler_continue_connecting(handle) ) + return false; + + mbedtls_stub.counter = 0; + mbedtls_stub.retArray[0] = MBEDTLS_ERR_SSL_BAD_HS_FINISHED; + + if( MBEDTLS_ERR_SSL_TIMEOUT != coap_security_handler_continue_connecting(handle) ) + return false; + + mbedtls_stub.counter = 0; + mbedtls_stub.retArray[0] = MBEDTLS_ERR_SSL_WANT_READ; + + if( MBEDTLS_ERR_SSL_WANT_READ != coap_security_handler_continue_connecting(handle) ) + return false; + + mbedtls_stub.counter = 0; + mbedtls_stub.retArray[0] = HANDSHAKE_FINISHED_VALUE; + + if( 0 != coap_security_handler_continue_connecting(handle) ) + return false; + + thread_security_destroy(handle); + return true; +} + +bool test_coap_security_handler_send_message() +{ + uint8_t buf[16]; + nsdynmemlib_stub.returnCounter = 2; + mbedtls_stub.crt_expected_int = 0; + thread_security_t *handle = thread_security_create(1,2,&buf,12,&send_to_socket, &receive_from_socket, &start_timer_callback, &timer_status_callback); + if( NULL == handle ) + return false; + + if( -1 != coap_security_handler_send_message(NULL, NULL, 0)) + return false; + + mbedtls_stub.expected_int = 6; + unsigned char cbuf[6]; + if( 6 != coap_security_handler_send_message(handle, &cbuf, 6)) + return false; + + thread_security_destroy(handle); + return true; +} + +bool test_thread_security_send_close_alert() +{ + uint8_t buf[16]; + nsdynmemlib_stub.returnCounter = 2; + mbedtls_stub.crt_expected_int = 0; + thread_security_t *handle = thread_security_create(1,2,&buf,12,&send_to_socket, &receive_from_socket, &start_timer_callback, &timer_status_callback); + if( NULL == handle ) + return false; + + if( -1 != thread_security_send_close_alert(NULL)) + return false; + + mbedtls_stub.expected_int = 0; + if( 0 != thread_security_send_close_alert(handle)) + return false; + + thread_security_destroy(handle); + return true; +} + +bool test_coap_security_handler_read() +{ + uint8_t buf[16]; + nsdynmemlib_stub.returnCounter = 2; + mbedtls_stub.crt_expected_int = 0; + thread_security_t *handle = thread_security_create(1,2,&buf,12,&send_to_socket, &receive_from_socket, &start_timer_callback, &timer_status_callback); + if( NULL == handle ) + return false; + + if( -1 != coap_security_handler_read(NULL, NULL, 0)) + return false; + + mbedtls_stub.expected_int = 6; + unsigned char cbuf[6]; + if( 6 != coap_security_handler_read(handle, &cbuf, 6)) + return false; + + thread_security_destroy(handle); + return true; +} + diff --git a/test/coap-service/unittest/coap_security_handler/test_coap_security_handler.h b/test/coap-service/unittest/coap_security_handler/test_coap_security_handler.h new file mode 100644 index 0000000000..d0a4e45380 --- /dev/null +++ b/test/coap-service/unittest/coap_security_handler/test_coap_security_handler.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2015 ARM. All rights reserved. + */ +#ifndef TEST_COAP_SECURITY_HANDLER_H +#define TEST_COAP_SECURITY_HANDLER_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +bool test_thread_security_create(); + +bool test_thread_security_destroy(); + +bool test_coap_security_handler_connect(); + +bool test_coap_security_handler_continue_connecting(); + +bool test_coap_security_handler_send_message(); + +bool test_thread_security_send_close_alert(); + +bool test_coap_security_handler_read(); + +#ifdef __cplusplus +} +#endif + +#endif // TEST_COAP_SECURITY_HANDLER_H + diff --git a/test/coap-service/unittest/coap_service_api/Makefile b/test/coap-service/unittest/coap_service_api/Makefile new file mode 100644 index 0000000000..130b44429f --- /dev/null +++ b/test/coap-service/unittest/coap_service_api/Makefile @@ -0,0 +1,24 @@ +include ../makefile_defines.txt + +COMPONENT_NAME = coap_service_api_unit + +#This must be changed manually +SRC_FILES = \ + ../../../../source/coap_service_api.c + +TEST_SRC_FILES = \ + main.cpp \ + coap_service_apitest.cpp \ + test_coap_service_api.c \ + ../stub/ns_trace_stub.c \ + ../stub/ns_list_stub.c \ + ../stub/system_timer_stub.c \ + ../stub/nsdynmemLIB_stub.c \ + ../stub/eventOS_event_stub.c \ + ../stub/coap_connection_handler_stub.c \ + ../stub/coap_message_handler_stub.c \ + +include ../MakefileWorker.mk + +CPPUTESTFLAGS += -DFEA_TRACE_SUPPORT + diff --git a/test/coap-service/unittest/coap_service_api/coap_service_apitest.cpp b/test/coap-service/unittest/coap_service_api/coap_service_apitest.cpp new file mode 100644 index 0000000000..9054de6313 --- /dev/null +++ b/test/coap-service/unittest/coap_service_api/coap_service_apitest.cpp @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2015 ARM. All rights reserved. + */ +#include "CppUTest/TestHarness.h" +#include "test_coap_service_api.h" + +TEST_GROUP(coap_service_api) +{ + void setup() + { + } + + void teardown() + { + } +}; + +TEST(coap_service_api, test_coap_service_initialize) +{ + CHECK(test_coap_service_initialize()); +} + +TEST(coap_service_api, test_coap_service_delete) +{ + CHECK(test_coap_service_delete()); +} + +TEST(coap_service_api, test_coap_service_virtual_socket_recv) +{ + CHECK(test_coap_service_virtual_socket_recv()); +} + +TEST(coap_service_api, test_coap_service_virtual_socket_set_cb) +{ + CHECK(test_coap_service_virtual_socket_set_cb()); +} + +TEST(coap_service_api, test_coap_service_register_uri) +{ + CHECK(test_coap_service_register_uri()); +} + +TEST(coap_service_api, test_coap_service_unregister_uri) +{ + CHECK(test_coap_service_unregister_uri()); +} + +TEST(coap_service_api, test_coap_service_request_send) +{ + CHECK(test_coap_service_request_send()); +} + +TEST(coap_service_api, test_coap_service_response_send) +{ + CHECK(test_coap_service_response_send()); +} + +TEST(coap_service_api, test_coap_callbacks) +{ + CHECK(test_coap_callbacks()); +} + +TEST(coap_service_api, test_eventOS_callbacks) +{ + CHECK(test_eventOS_callbacks()); +} + +TEST(coap_service_api, test_conn_handler_callbacks) +{ + CHECK(test_conn_handler_callbacks()); +} + diff --git a/test/coap-service/unittest/coap_service_api/main.cpp b/test/coap-service/unittest/coap_service_api/main.cpp new file mode 100644 index 0000000000..e050cec95f --- /dev/null +++ b/test/coap-service/unittest/coap_service_api/main.cpp @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2015 ARM. All rights reserved. + */ + +#include "CppUTest/CommandLineTestRunner.h" +#include "CppUTest/TestPlugin.h" +#include "CppUTest/TestRegistry.h" +#include "CppUTestExt/MockSupportPlugin.h" +int main(int ac, char** av) +{ + return CommandLineTestRunner::RunAllTests(ac, av); +} + +IMPORT_TEST_GROUP(coap_service_api); + diff --git a/test/coap-service/unittest/coap_service_api/test_coap_service_api.c b/test/coap-service/unittest/coap_service_api/test_coap_service_api.c new file mode 100644 index 0000000000..a9130a37a4 --- /dev/null +++ b/test/coap-service/unittest/coap_service_api/test_coap_service_api.c @@ -0,0 +1,407 @@ +/* + * Copyright (c) 2015 ARM. All rights reserved. + */ +#include "test_coap_service_api.h" +#include +#include "coap_service_api.h" +#include "nsdynmemLIB_stub.h" +#include "coap_connection_handler_stub.h" +#include "coap_message_handler_stub.h" +#include "eventOS_event_stub.h" +#include "eventOS_event.h" +#include "net_interface.h" + +int sec_done_cb(int8_t service_id, uint8_t address[static 16], uint8_t keyblock[static 40]){ + return 2; +} + +int sec_start_cb(int8_t service_id, uint8_t address[static 16], uint16_t port, uint8_t* pw, uint8_t *pw_len) +{ + return 2; +} + +int request_recv_cb(int8_t service_id, uint8_t source_address[static 16], uint16_t source_port, sn_coap_hdr_s *request_ptr) +{ + return 2; +} + +int virtual_sock_send_cb(int8_t service_id, uint8_t destination_addr_ptr[static 16], uint16_t port, const uint8_t *data_ptr, uint16_t data_len) +{ + return 2; +} + +bool test_coap_service_initialize() +{ + if( -1 != coap_service_initialize(1, 2, 0, NULL, NULL )) + return false; + + nsdynmemlib_stub.returnCounter = 1; + thread_conn_handler_stub.handler_obj = NULL; + if( -1 != coap_service_initialize(1, 2, 0, NULL, NULL )) + return false; + + thread_conn_handler_stub.handler_obj = (thread_conn_handler_t*)malloc(sizeof(thread_conn_handler_t)); + memset(thread_conn_handler_stub.handler_obj, 0, sizeof(thread_conn_handler_t)); + nsdynmemlib_stub.returnCounter = 1; + coap_message_handler_stub.coap_ptr = NULL; + + if( 1 != coap_service_initialize(1, 2, 0, NULL, NULL )) + return false; + + nsdynmemlib_stub.returnCounter = 1; + if( 2 != coap_service_initialize(3, 4, 0, NULL, NULL )) + return false; + + coap_service_delete(2); + coap_service_delete(1); + + free( thread_conn_handler_stub.handler_obj ); + thread_conn_handler_stub.handler_obj = NULL; + return true; +} + +bool test_coap_service_delete() +{ + coap_service_delete(1); + + thread_conn_handler_stub.handler_obj = (thread_conn_handler_t*)malloc(sizeof(thread_conn_handler_t)); + memset(thread_conn_handler_stub.handler_obj, 0, sizeof(thread_conn_handler_t)); + nsdynmemlib_stub.returnCounter = 1; + coap_message_handler_stub.coap_ptr = NULL; + + if( 1 != coap_service_initialize(1, 2, 0, NULL, NULL )) + return false; + + coap_service_delete(1); + + free( thread_conn_handler_stub.handler_obj ); + thread_conn_handler_stub.handler_obj = NULL; + + return true; +} + +bool test_coap_service_virtual_socket_recv() +{ + uint8_t buf[16]; + if( -1 != coap_service_virtual_socket_recv(1, &buf, 10, NULL, 0) ) + return false; + + thread_conn_handler_stub.handler_obj = (thread_conn_handler_t*)malloc(sizeof(thread_conn_handler_t)); + memset(thread_conn_handler_stub.handler_obj, 0, sizeof(thread_conn_handler_t)); + nsdynmemlib_stub.returnCounter = 1; + coap_message_handler_stub.coap_ptr = NULL; + + if( 1 != coap_service_initialize(1, 2, 0, NULL, NULL )) + return false; + + thread_conn_handler_stub.int_value = 5; + if( 5 != coap_service_virtual_socket_recv(1, &buf, 10, NULL, 0) ) + return false; + + coap_service_delete(1); + + free( thread_conn_handler_stub.handler_obj ); + thread_conn_handler_stub.handler_obj = NULL; + + thread_conn_handler_stub.int_value = 0; + + return true; +} + +bool test_coap_service_virtual_socket_set_cb() +{ + if( -1 != coap_service_virtual_socket_set_cb(1, NULL) ) + return false; + + thread_conn_handler_stub.handler_obj = (thread_conn_handler_t*)malloc(sizeof(thread_conn_handler_t)); + memset(thread_conn_handler_stub.handler_obj, 0, sizeof(thread_conn_handler_t)); + nsdynmemlib_stub.returnCounter = 1; + coap_message_handler_stub.coap_ptr = NULL; + + if( 1 != coap_service_initialize(1, 2, 0, NULL, NULL )) + return false; + + if( 0 != coap_service_virtual_socket_set_cb(1, NULL) ) + return false; + + coap_service_delete(1); + + free( thread_conn_handler_stub.handler_obj ); + thread_conn_handler_stub.handler_obj = NULL; + + return true; +} + +bool test_coap_service_register_uri() +{ + if( -1 != coap_service_register_uri(1, "as", 1, &request_recv_cb)) + return false; + + thread_conn_handler_stub.handler_obj = (thread_conn_handler_t*)malloc(sizeof(thread_conn_handler_t)); + memset(thread_conn_handler_stub.handler_obj, 0, sizeof(thread_conn_handler_t)); + nsdynmemlib_stub.returnCounter = 1; + coap_message_handler_stub.coap_ptr = NULL; + + if( 1 != coap_service_initialize(1, 2, 0, NULL, NULL )) + return false; + + if( -2 != coap_service_register_uri(1, "as", 1, &request_recv_cb) ) + return false; + + nsdynmemlib_stub.returnCounter = 1; + if( -2 != coap_service_register_uri(1, "as", 1, &request_recv_cb) ) + return false; + + nsdynmemlib_stub.returnCounter = 2; + if( 0 != coap_service_register_uri(1, "as", 1, &request_recv_cb) ) + return false; + + coap_service_delete(1); + + free( thread_conn_handler_stub.handler_obj ); + thread_conn_handler_stub.handler_obj = NULL; + + return true; +} + +bool test_coap_service_unregister_uri() +{ + if( -1 != coap_service_unregister_uri(1, "as")) + return false; + + thread_conn_handler_stub.handler_obj = (thread_conn_handler_t*)malloc(sizeof(thread_conn_handler_t)); + memset(thread_conn_handler_stub.handler_obj, 0, sizeof(thread_conn_handler_t)); + nsdynmemlib_stub.returnCounter = 1; + coap_message_handler_stub.coap_ptr = NULL; + + if( 1 != coap_service_initialize(1, 2, 0, NULL, NULL )) + return false; + + nsdynmemlib_stub.returnCounter = 2; + if( 0 != coap_service_register_uri(1, "as", 1, &request_recv_cb) ) + return false; + + if( -2 != coap_service_unregister_uri(1, "ts") ) + return false; + + if( 0 != coap_service_unregister_uri(1, "as") ) + return false; + + coap_service_delete(1); + + free( thread_conn_handler_stub.handler_obj ); + thread_conn_handler_stub.handler_obj = NULL; + + return true; +} + +bool test_coap_service_request_send() +{ + uint8_t buf[16]; + coap_message_handler_stub.uint16_value = 6; + if( 6 != coap_service_request_send(0,0,&buf,0,0,0,NULL, 0,NULL,0,NULL)) + return false; + return true; +} + +bool test_coap_service_response_send() +{ + uint8_t buf[16]; + coap_message_handler_stub.int8_value = 6; + if( 6 != coap_service_response_send(0,0,NULL, 65, 0,NULL, 0)) + return false; + return true; +} + +bool test_coap_callbacks() +{ + thread_conn_handler_stub.handler_obj = (thread_conn_handler_t*)malloc(sizeof(thread_conn_handler_t)); + memset(thread_conn_handler_stub.handler_obj, 0, sizeof(thread_conn_handler_t)); + nsdynmemlib_stub.returnCounter = 1; + coap_message_handler_stub.coap_ptr = (coap_msg_handler_t *)malloc(sizeof(coap_msg_handler_t)); + memset(coap_message_handler_stub.coap_ptr, 0, sizeof(coap_msg_handler_t)); + + if( 1 != coap_service_initialize(1, 2, 0, NULL, NULL )) + return false; + + if( 0 != coap_message_handler_stub.coap_ptr->sn_coap_service_malloc(0)) + return false; + + nsdynmemlib_stub.returnCounter = 1; + void *handle = coap_message_handler_stub.coap_ptr->sn_coap_service_malloc(5); + if( 0 == handle ) + return false; + + coap_message_handler_stub.coap_ptr->sn_coap_service_free(handle); + + //coap_tx_function + uint8_t data[14]; + memset(&data, 3, 14); + sn_nsdl_addr_s addr; + addr.addr_len = 2; + addr.port = 4; + addr.addr_ptr = &data; + if( 0 != coap_message_handler_stub.coap_ptr->sn_coap_tx_callback(NULL, 0, &addr, NULL)) + return false; + + coap_transaction_t *tr = (coap_transaction_t *)malloc(sizeof(coap_transaction_t)); + memset(tr, 0, sizeof(coap_transaction_t)); + + if( 0 != coap_message_handler_stub.coap_ptr->sn_coap_tx_callback(&data, 0, &addr, tr)) + return false; + + tr->service_id = 1; + thread_conn_handler_stub.int_value = -2; + if( 0 != coap_message_handler_stub.coap_ptr->sn_coap_tx_callback(&data, 0, &addr, tr)) + return false; + + nsdynmemlib_stub.returnCounter = 1; + if( 0 != coap_message_handler_stub.coap_ptr->sn_coap_tx_callback(&data, 2, &addr, tr)) + return false; + + free(tr->data_ptr); + free(tr); + + coap_service_delete(1); + + free( coap_message_handler_stub.coap_ptr ); + coap_message_handler_stub.coap_ptr = NULL; + + free( thread_conn_handler_stub.handler_obj ); + thread_conn_handler_stub.handler_obj = NULL; + + return true; +} + +#define COAP_TICK_TIMER 0xf1 //MUST BE SAME AS IN coap_service_api.c +bool test_eventOS_callbacks() +{ + thread_conn_handler_stub.handler_obj = (thread_conn_handler_t*)malloc(sizeof(thread_conn_handler_t)); + memset(thread_conn_handler_stub.handler_obj, 0, sizeof(thread_conn_handler_t)); + nsdynmemlib_stub.returnCounter = 1; + if( 1 != coap_service_initialize(1, 2, 0, NULL, NULL )) + return false; + + if( eventOs_event_stub.event_ptr ){ + arm_event_s event; + event.event_type = ARM_LIB_TASKLET_INIT_EVENT; + eventOs_event_stub.event_ptr(&event); + + event.event_type = ARM_LIB_SYSTEM_TIMER_EVENT; + event.event_id = COAP_TICK_TIMER; + eventOs_event_stub.event_ptr(&event); + } + + coap_service_delete(1); + free( thread_conn_handler_stub.handler_obj ); + thread_conn_handler_stub.handler_obj = NULL; + return true; +} + +bool test_conn_handler_callbacks() +{ + uint8_t buf[16]; + thread_conn_handler_stub.handler_obj = (thread_conn_handler_t*)malloc(sizeof(thread_conn_handler_t)); + memset(thread_conn_handler_stub.handler_obj, 0, sizeof(thread_conn_handler_t)); + nsdynmemlib_stub.returnCounter = 1; + if( 1 != coap_service_initialize(1, 2, COAP_SERVICE_OPTIONS_SECURE_BYPASS, &sec_start_cb, &sec_done_cb )) + return false; + + if( thread_conn_handler_stub.send_to_sock_cb ){ + thread_conn_handler_stub.bool_value = true; + coap_service_virtual_socket_set_cb(1, &virtual_sock_send_cb); + if( 2 != thread_conn_handler_stub.send_to_sock_cb(1, buf, 12, NULL, 0)) + return false; + thread_conn_handler_stub.bool_value = false; + if( -1 != thread_conn_handler_stub.send_to_sock_cb(1, buf, 12, NULL, 0)) + return false; + } + + if( thread_conn_handler_stub.receive_from_sock_cb ){ + coap_message_handler_stub.int16_value = 2; + if( -1 != thread_conn_handler_stub.receive_from_sock_cb(1, buf, 12, NULL, 0)) + return false; + + nsdynmemlib_stub.returnCounter = 1; + uint8_t * ptr = ns_dyn_mem_alloc(5); + memset(ptr, 3, 5); + nsdynmemlib_stub.returnCounter = 1; + if( 2 != thread_conn_handler_stub.receive_from_sock_cb(1, buf, 12, ptr, 5)) + return false; + ns_dyn_mem_free(ptr); + coap_message_handler_stub.int16_value = 0; + + //This could be moved to own test function, + //but thread_conn_handler_stub.receive_from_sock_cb must be called successfully + if( coap_message_handler_stub.cb ){ + if( -1 != coap_message_handler_stub.cb(1, NULL, NULL) ) + return false; + + sn_coap_hdr_s * coap = (sn_coap_hdr_s *)malloc(sizeof(sn_coap_hdr_s)); + memset(coap, 0, sizeof(sn_coap_hdr_s)); + + uint8_t uri[2] = "as"; + coap->uri_path_ptr = &uri; + coap->uri_path_len=2; + + if( -1 != coap_message_handler_stub.cb(1, coap, NULL) ) + return false; + + thread_conn_handler_stub.bool_value = true; + nsdynmemlib_stub.returnCounter = 2; + if( 0 != coap_service_register_uri(1, "as", 1, &request_recv_cb) ) + return false; + + if( -1 != coap_message_handler_stub.cb(1, coap, NULL) ) + return false; + + coap_transaction_t *tr = (coap_transaction_t *)malloc(sizeof(coap_transaction_t)); + memset(tr, 0, sizeof(coap_transaction_t)); + + if( 2 != coap_message_handler_stub.cb(1, coap, tr) ) + return false; + + free(tr); + tr = NULL; + + thread_conn_handler_stub.bool_value = false; + free(coap); + coap = NULL; + } + } + + if(thread_conn_handler_stub.get_passwd_cb){ + thread_conn_handler_stub.bool_value = true; + if( 2 != thread_conn_handler_stub.get_passwd_cb(1, buf, 12, NULL, 0)) + return false; + thread_conn_handler_stub.bool_value = false; + if( -1 != thread_conn_handler_stub.get_passwd_cb(1, buf, 12, NULL, 0)) + return false; + } + + if(thread_conn_handler_stub.sec_done_cb){ + uint8_t block[40]; + thread_conn_handler_stub.bool_value = true; + + coap_transaction_t *tr = (coap_transaction_t *)malloc(sizeof(coap_transaction_t)); + memset(tr, 0, sizeof(coap_transaction_t)); + nsdynmemlib_stub.returnCounter = 1; + tr->data_ptr = ns_dyn_mem_alloc(1); + tr->data_len = 1; + coap_message_handler_stub.coap_tx_ptr = tr; + + thread_conn_handler_stub.sec_done_cb(1, buf, 12, block); + + free(tr); + coap_message_handler_stub.coap_tx_ptr = NULL; + + thread_conn_handler_stub.bool_value = false; + + } + + coap_service_delete(1); + free( thread_conn_handler_stub.handler_obj ); + thread_conn_handler_stub.handler_obj = NULL; + + return true; +} diff --git a/test/coap-service/unittest/coap_service_api/test_coap_service_api.h b/test/coap-service/unittest/coap_service_api/test_coap_service_api.h new file mode 100644 index 0000000000..2897c9a89b --- /dev/null +++ b/test/coap-service/unittest/coap_service_api/test_coap_service_api.h @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2015 ARM. All rights reserved. + */ +#ifndef TEST_COAP_SERVICE_API_H +#define TEST_COAP_SERVICE_API_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +bool test_coap_service_initialize(); + +bool test_coap_service_delete(); + +bool test_coap_service_virtual_socket_recv(); + +bool test_coap_service_virtual_socket_set_cb(); + +bool test_coap_service_register_uri(); + +bool test_coap_service_unregister_uri(); + +bool test_coap_service_request_send(); + +bool test_coap_service_response_send(); + +bool test_coap_callbacks(); + +bool test_eventOS_callbacks(); + +bool test_conn_handler_callbacks(); + + +#ifdef __cplusplus +} +#endif + +#endif // TEST_COAP_SERVICE_API_H + diff --git a/test/coap-service/unittest/makefile_defines.txt b/test/coap-service/unittest/makefile_defines.txt new file mode 100755 index 0000000000..4225393d5c --- /dev/null +++ b/test/coap-service/unittest/makefile_defines.txt @@ -0,0 +1,42 @@ +#--- Inputs ----# +CPPUTEST_HOME = /usr +CPPUTEST_USE_EXTENSIONS = Y +CPPUTEST_USE_VPATH = Y +CPPUTEST_USE_GCOV = Y +CPP_PLATFORM = gcc + +INCLUDE_DIRS =\ + .\ + ../stub\ + ../../../../../nanostack/source/6LoWPAN/Thread/\ + ../../../../../nanostack/source/6LoWPAN/Mesh/\ + ../../../../../nanostack/source/6LoWPAN/RPL/\ + ../../../../../nanostack/source/\ + ../../../../../nanostack/source/Core/include/\ + ../../../../../nanostack/source/Common_Protocols/\ + ../../../../../nanostack/source/Security/Common/\ + ../../../../../nanostack/source/Service_Libs/etx/\ + ../../../../../nanostack/source/MLE/\ + ../../../../../nanostack/nanostack/\ + ../../../../../coap-service/coap-service/\ + ../../../../../coap-service/source/include/\ + ../../../../../libService/libService/\ + ../../../../../libService/exported-libs/mbed-client-libservice/mbed-client-libservice/\ + ../../../../../libService/exported-libs/mbed-client-randlib/mbed-client-randlib/\ + ../../../../../coap-service/coap-service/\ + ../../../../../nsdl-c/nsdl-c/\ + ../../../../../nsdl-c/source/libCoap/src/include/\ + ../../../../../event-loop/nanostack-event-loop/\ + ../../../../../event-loop/source/ \ + ../../../../../mbedtls/include/ \ + ../../../../../mbedtls/include/mbedtls/ \ + /usr/include\ + $(CPPUTEST_HOME)/include\ + +CPPUTESTFLAGS = -D__thumb2__ -w +CPPUTEST_CFLAGS += -std=gnu99 + +#if you need to use -std=c++11 or c++0x you need to uncomment this +#CPPUTESTFLAGS += -DCPPUTEST_STD_CPP_LIB_DISABLED +#CPPUTEST_CXXFLAGS += -std=gnu++0x + diff --git a/test/coap-service/unittest/run_tests b/test/coap-service/unittest/run_tests new file mode 100755 index 0000000000..f34b3b8d05 --- /dev/null +++ b/test/coap-service/unittest/run_tests @@ -0,0 +1,34 @@ +#!/bin/bash +echo +echo Build Coap-service unit tests +echo + +# Remember to add new test folder to Makefile +make clean +make all + +echo +echo Create results +echo +mkdir results +find ./ -name '*.xml' | xargs cp -t ./results/ + +echo +echo Create coverage document +echo +mkdir coverages +cd coverages + +lcov -q -d ../. -c -o app.info +lcov -q -r app.info "/test*" -o app.info +lcov -q -r app.info "/usr*" -o app.info +lcov -q -r app.info "/libService*" -o app.info +genhtml -q --no-branch-coverage app.info +cd .. +echo +echo +echo +echo Have a nice bug hunt! +echo +echo +echo diff --git a/test/coap-service/unittest/run_tests~ b/test/coap-service/unittest/run_tests~ new file mode 100755 index 0000000000..f34b3b8d05 --- /dev/null +++ b/test/coap-service/unittest/run_tests~ @@ -0,0 +1,34 @@ +#!/bin/bash +echo +echo Build Coap-service unit tests +echo + +# Remember to add new test folder to Makefile +make clean +make all + +echo +echo Create results +echo +mkdir results +find ./ -name '*.xml' | xargs cp -t ./results/ + +echo +echo Create coverage document +echo +mkdir coverages +cd coverages + +lcov -q -d ../. -c -o app.info +lcov -q -r app.info "/test*" -o app.info +lcov -q -r app.info "/usr*" -o app.info +lcov -q -r app.info "/libService*" -o app.info +genhtml -q --no-branch-coverage app.info +cd .. +echo +echo +echo +echo Have a nice bug hunt! +echo +echo +echo diff --git a/test/coap-service/unittest/stub/6lowpan_iphc_stub.c b/test/coap-service/unittest/stub/6lowpan_iphc_stub.c new file mode 100644 index 0000000000..062be99b7e --- /dev/null +++ b/test/coap-service/unittest/stub/6lowpan_iphc_stub.c @@ -0,0 +1,93 @@ +/* + * Copyright (c) 2013-2015 ARM Limited. All rights reserved. + */ + +#include "config.h" +#define HAVE_CIPV6 + +#ifdef HAVE_CIPV6 +#include "ns_types.h" +#include "string.h" +#include "ns_trace.h" +#include "Core/include/socket.h" +#include "Common_Protocols/ipv6.h" +#include "Common_Protocols/icmpv6.h" +#include "6LoWPAN/IPHC_Decode/cipv6.h" +#include "6LoWPAN/Fragmentation/cipv6_fragmenter.h" +#include "6LoWPAN/ND/icmp.h" +#include "NWK_INTERFACE/Include/protocol.h" +#include "ipv6_stack/protocol_ipv6.h" +#include "6LoWPAN/IPHC_Decode/cudp.h" +#include "6LoWPAN/IPHC_Decode/iphc_compress.h" +#include "6LoWPAN/IPHC_Decode/iphc_decompress.h" +#include "6LoWPAN/Mesh/mesh.h" +#include "6LoWPAN/Thread/thread.h" + +#ifdef HAVE_RPL +#include "6LoWPAN/RPL/rpl.h" +#include "6LoWPAN/RPL/rpl_obj.h" +#endif + +#define TRACE_GROUP "iphc" + +#include "MulticastTrigle/multicast.h" +#include "6LoWPAN/ND/nd_router_object.h" +#include "6LoWPAN/Bootstraps/protocol_6lowpan.h" +#include "MAC/IEEE802_15_4/mac_indirect_data.h" +#include "MAC/IEEE802_15_4/mac_mlme.h" +#include "nwk_stats_api.h" +#include "NWK_INTERFACE/Include/protocol_stats.h" +#include "common_functions.h" + +typedef struct ip_src_addr_t { + addrtype_t addr_type; /*!< Type of address */ + uint8_t address[8]; /*!< Source or destination address */ +} ip_src_addr_t; + + +NS_LARGE uint8_t ip_hc[2]; +NS_LARGE route_info_entry_t route_info_entry; +NS_LARGE uint8_t flow_len; +NS_LARGE uint8_t flow_ctrl[4]; + +void cipv6_set_next_hop(buffer_t *buf); +uint8_t cipv6_forward_rl_check(void); +buffer_t *cipv6_reallocate_ip_headers(buffer_t *buf, uint8_t type, forward_dest_t dest); + + +buffer_t *cipv6_check_link_layer_length(buffer_t *buf) +{ + return NULL; +} + +void cipv6_set_next_hop(buffer_t *buf) +{ +} + +uint8_t cipv6_forward_rl_check(void) +{ + return 0; +} + +buffer_t *cipv6_reallocate_ip_headers(buffer_t *buf, uint8_t type, forward_dest_t dest) +{ + return NULL; +} + +buffer_t *cipv6_down(buffer_t *buf) +{ + return NULL; +} + +buffer_t *lowpan_down(buffer_t *buf) +{ + return NULL; +} + +buffer_t *cipv6_up(buffer_t *buf) +{ + return NULL; +} + +#endif /* HAVE_CIPV6 */ + diff --git a/test/coap-service/unittest/stub/6lowpan_mesh_stub.c b/test/coap-service/unittest/stub/6lowpan_mesh_stub.c new file mode 100644 index 0000000000..3c83002267 --- /dev/null +++ b/test/coap-service/unittest/stub/6lowpan_mesh_stub.c @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2014-2015 ARM Limited. All rights reserved. + */ + +#include "config.h" +#include +#include "ns_types.h" +#define HAVE_DEBUG 1 +#include "buffer.h" +#include "ns_list.h" +//#include "platform/ns_debug.h" +#include "common_functions.h" +#include "NWK_INTERFACE/Include/protocol.h" +#include "MAC/IEEE802_15_4/mac_mlme.h" +#include "NWK_INTERFACE/Include/protocol_stats.h" +#include "6LoWPAN/IPHC_Decode/cipv6.h" +#include "MAC/IEEE802_15_4/mac_indirect_data.h" +#include "mesh.h" + +void debug(const char *msg) +{ +} + +protocol_interface_info_entry_t *protocol_stack_interface_info_get(nwk_interface_id nwk_id) +{ + return NULL; +} + +extern COMMON_FUNCTIONS_FN uint16_t common_read_16_bit(const uint8_t data_buf[__static 2]); +extern COMMON_FUNCTIONS_FN uint8_t *common_write_16_bit(uint16_t value, uint8_t ptr[__static 2]); +extern COMMON_FUNCTIONS_FN uint8_t *common_write_16_bit_inverse(uint16_t value, uint8_t ptr[__static 2]); + +bool nwk_interface_compare_mac_address(protocol_interface_info_entry_t *cur, uint_fast8_t addrlen, const uint8_t addr[]) +{ + return false; +} + +uint8_t addr_check_broadcast(const address_t addr, addrtype_t addr_type) +{ + return 0; +} + +#ifndef HAVE_DEBUG +uint8_t *buffer_corrupt_check(buffer_t *buf) +{ + return NULL; +} +#endif + +bool mac_mlme_write_our_addr(struct protocol_interface_info_entry *cur, sockaddr_t *sockaddr) +{ +} + +mac_direct_check_res_e mac_indirect_data_check(struct buffer *buf) +{ + mac_direct_check_res_e res = {0}; + return res; +} + +void protocol_stats_update(nwk_stats_type_t type, uint16_t update_val) +{ +} + +#if 0 +buffer_t *buffer_headroom(buffer_t *buf, uint16_t size) +{ + return NULL; +} +#endif + +buffer_t *cipv6_check_link_layer_length(buffer_t *buf) +{ + return NULL; +} diff --git a/test/coap-service/unittest/stub/address_stub.c b/test/coap-service/unittest/stub/address_stub.c new file mode 100644 index 0000000000..b55d9a70b1 --- /dev/null +++ b/test/coap-service/unittest/stub/address_stub.c @@ -0,0 +1,230 @@ +/* + * Copyright (c) 2008, 2010-2015 ARM Limited. All rights reserved. + */ +/** + * \file address.c + * \brief Utility functions concernig addresses + * + * This file contains all the utility functions that can be used to + * check, manipulate etc. addresses. + */ +#include "config.h" +#include "ns_types.h" +#include "ip6string.h" +#include "ns_trace.h" +#include "randLIB.h" +#include "string.h" +#include "nsdynmemLIB.h" +#include "socket_api.h" +#include "NWK_INTERFACE/Include/protocol.h" +#include "Common_Protocols/ipv6.h" +#include "Common_Protocols/icmpv6.h" +#include "6LoWPAN/Thread/thread.h" +#include "common_functions.h" + +#include "address_stub.h" + +#define TRACE_GROUP_ADDRESS "addr" + +#define ADDR_SHORT_MULTICAST_MAX 10 +#define ADDR_MAX_DYNAMIC_MULTICAST_ADDRESSES 100 + +address_stub_def address_stub; + +typedef struct addr_policy_table_entry_t { + uint8_t prefix[16]; + uint8_t prefix_len; + uint8_t precedence; + uint8_t label; + ns_list_link_t link; +} addr_policy_table_entry_t; + +static NS_LIST_DEFINE(addr_policy_table, addr_policy_table_entry_t, link); + +uint32_t addr_preferences_default = SOCKET_IPV6_PREFER_SRC_TMP | SOCKET_IPV6_PREFER_SRC_6LOWPAN_SHORT; + +const uint8_t ADDR_LINK_LOCAL_PREFIX[8] = { 0xfe, 0x80 }; +const uint8_t ADDR_SHORT_ADR_SUFFIC[6] = { 0x00, 0x00, 0x00, 0xff, 0xfe, 0x00}; + +const uint8_t ADDR_MULTICAST_SOLICITED[13] = { 0xff, 0x02, [11] = 0x01, 0xff}; +const uint8_t ADDR_LINK_LOCAL_ALL_NODES[16] = { 0xff, 0x02, [15] = 0x01 }; +const uint8_t ADDR_LINK_LOCAL_ALL_ROUTERS[16] = { 0xff, 0x02, [15] = 0x02 }; +const uint8_t ADDR_MULTICAST_ALL_DHCPV6_SERVER[16] = { 0xff, 0x03, [13] = 0x01, 0x00, 0x03 }; +const uint8_t ADDR_ALL_DHCP_RELAY_AGENTS_AND_SERVERS[16] = { 0xff, 0x02, [13] = 0x01, 0x00, 0x02 }; + +const uint8_t ADDR_MULTICAST_SITEPREFIX[15] = { 0xff, 0x05 }; +const uint8_t ADDR_MULTICAST_SUBPREFIX[15] = { 0xff, 0x03 }; +const uint8_t ADDR_IPV4_MAPPED_PREFIX[12] = { [10] = 0xff, 0xff }; +const uint8_t ADDR_LOOPBACK[16] = { [15] = 1 }; +const uint8_t ADDR_UNSPECIFIED[16] = { 0 }; +#define ADDR_IPV4_COMPATIBLE ADDR_LOOPBACK /* First 96 bits match...*/ + + +uint8_t addr_len_from_type(addrtype_t addr_type) +{ + return 0; +} + +uint8_t addr_check_broadcast(const address_t addr, addrtype_t addr_type) +{ + address_stub.expectedUint8ptr = &addr; + address_stub.expectedUint8 = addr_type; + + return address_stub.returnUint8; +} + +bool addr_is_ipv6_link_local(const uint8_t addr[__static 16]) +{ + return false; +} + +/* Scope(A), as defined in RFC 6724 plus RFC 4007 */ +uint_fast8_t addr_ipv6_scope(const uint8_t addr[__static 16], const protocol_interface_info_entry_t *interface) +{ + return 0; +} + +void address_module_init(void) +{ +} + +void addr_multicast_list_init(void) +{ +} + +uint8_t addr_multicast_list_allocate(const uint8_t *ptr, uint8_t relay_allocate) +{ + return -1; +} + +uint8_t addr_multicast_list_free(const uint8_t *ptr) +{ + return 1; +} + +uint8_t addr_multicast_list_check(const uint8_t *ptr, bool rx_adr, protocol_interface_info_entry_t *cur_interface) +{ + return -1; +} + +int_fast8_t addr_policy_table_add_entry(const uint8_t *prefix, uint8_t len, uint8_t precedence, uint8_t label) +{ + return -1; +} + +int_fast8_t addr_policy_table_delete_entry(const uint8_t *prefix, uint8_t len) +{ + return -1; +} + +void addr_policy_table_print(void) +{ +} + +if_address_entry_t *addr_get_entry(const protocol_interface_info_entry_t *interface, const uint8_t addr[__static 16]) +{ + return NULL; +} + +bool addr_is_assigned_to_interface(const protocol_interface_info_entry_t *interface, const uint8_t addr[__static 16]) +{ + return false; +} + +bool addr_is_tentative_for_interface(const protocol_interface_info_entry_t *interface, const uint8_t addr[__static 16]) +{ + return false; +} + +/* RFC 6724 Default source address selection */ +const uint8_t *addr_select_source(protocol_interface_info_entry_t *interface, const uint8_t dest[__static 16], uint32_t addr_preferences) +{ + return NULL; +} + +const uint8_t *addr_select_with_prefix(protocol_interface_info_entry_t *cur, const uint8_t *prefix, uint8_t prefix_len, uint32_t addr_preferences) +{ + return NULL; +} + +void addr_timer(protocol_interface_info_entry_t *cur, uint_fast16_t ticks) +{ +} + +if_address_entry_t *addr_add(protocol_interface_info_entry_t *cur, const uint8_t address[__static 16], uint_fast8_t prefix_len, if_address_source_t source, uint32_t valid_lifetime, uint32_t preferred_lifetime, bool skip_dad) +{ + return NULL; +} + +int_fast8_t addr_delete(protocol_interface_info_entry_t *cur, const uint8_t address[__static 16]) +{ + return -1; +} + +void addr_delete_matching(protocol_interface_info_entry_t *cur, const uint8_t *prefix, uint8_t prefix_len, if_address_source_t source) +{ +} + +void addr_duplicate_detected(struct protocol_interface_info_entry *interface, const uint8_t addr[__static 16]) +{ +} + +void memswap(uint8_t *restrict a, uint8_t *restrict b, uint_fast8_t len) +{ +} + +bool addr_ipv6_equal(const uint8_t a[__static 16], const uint8_t b[__static 16]) +{ + return false; +} + +bool addr_iid_matches_eui64(const uint8_t iid[__static 8], const uint8_t eui64[__static 8]) +{ + return false; +} + +bool addr_iid_matches_lowpan_short(const uint8_t iid[__static 8], uint16_t short_addr) +{ + return false; +} + +uint8_t *addr_ipv6_write_from_lowpan_short(uint8_t dst[__static 16], const uint8_t prefix[__static 8], uint16_t short_addr) +{ + return NULL; +} + +bool addr_iid_from_outer(uint8_t iid_out[__static 8], const sockaddr_t *addr_in) +{ + return false; +} + + +int addr_interface_set_ll64(protocol_interface_info_entry_t *cur, if_address_callback_fn *cb) +{ + return -1; +} + +int8_t addr_interface_get_ll_address(protocol_interface_info_entry_t *cur, uint8_t *address_ptr, uint8_t address_type) +{ + return -1; +} + +int8_t addr_interface_get_any_gp_address(protocol_interface_info_entry_t *cur, uint8_t *address_ptr, uint8_t address_type) +{ + return -1; +} + +int8_t addr_interface_gp_prefix_compare(protocol_interface_info_entry_t *cur, const uint8_t *prefix) +{ + return -1; +} + +int8_t addr_interface_address_compare(protocol_interface_info_entry_t *cur, const uint8_t *addr) +{ + return -1; +} + +int8_t addr_interface_select_source(protocol_interface_info_entry_t *cur, uint8_t *src_ptr, const uint8_t *dest, uint32_t addr_preferences) +{ + return -1; +} diff --git a/test/coap-service/unittest/stub/address_stub.h b/test/coap-service/unittest/stub/address_stub.h new file mode 100644 index 0000000000..c57bbb6cd8 --- /dev/null +++ b/test/coap-service/unittest/stub/address_stub.h @@ -0,0 +1,21 @@ +#ifndef __ADDRESS_STUB_H__ +#define __ADDRESS_STUB_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct { + uint8_t expectedUint8; + uint16_t expectedUint16; + uint8_t *expectedUint8ptr; + uint8_t returnUint8; +} address_stub_def; + +extern address_stub_def address_stub; + +#ifdef __cplusplus +} +#endif + +#endif // __ADDRESS_STUB_H__ diff --git a/test/coap-service/unittest/stub/buffer_dyn_stub.c b/test/coap-service/unittest/stub/buffer_dyn_stub.c new file mode 100644 index 0000000000..036745dde2 --- /dev/null +++ b/test/coap-service/unittest/stub/buffer_dyn_stub.c @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2011-2015 ARM Limited. All rights reserved. + */ + +#include "config.h" +#include "string.h" +#include "ns_types.h" +#include "nsdynmemLIB.h" +#include "Core/include/address.h" +#include "Core/include/buffer.h" +#include "platform/ns_debug.h" +#include "platform/arm_hal_interrupt.h" +#include "NWK_INTERFACE/Include/protocol_stats.h" +#include "ip_fsc.h" + + +uint8_t *(buffer_corrupt_check)(buffer_t *buf) +{ + return 0; +} + + +buffer_t *buffer_get(uint16_t size) +{ + return NULL; +} + +buffer_t *buffer_headroom(buffer_t *buf, uint16_t size) +{ + return NULL; +} + +buffer_t *buffer_free_route(buffer_t *buf) +{ + return NULL; +} + +buffer_t *buffer_free(buffer_t *buf) +{ + return NULL; +} + +buffer_t *buffer_free_list(buffer_t *b) +{ + return NULL; +} + + +void buffer_data_add(buffer_t *buf, const uint8_t *data_ptr, uint16_t data_len) +{ + return; +} + + +buffer_t *buffer_clone(buffer_t *buf) +{ + return NULL; +} + +uint16_t buffer_ipv6_fcf(const buffer_t *buf, uint8_t next_header) +{ + return 0; +} diff --git a/test/coap-service/unittest/stub/coap_connection_handler_stub.c b/test/coap-service/unittest/stub/coap_connection_handler_stub.c new file mode 100644 index 0000000000..03c2cf8237 --- /dev/null +++ b/test/coap-service/unittest/stub/coap_connection_handler_stub.c @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2015 ARM Limited. All rights reserved. + */ + +#include +#include "coap_connection_handler.h" +#include "coap_security_handler.h" +#include "ns_list.h" +#include "ns_trace.h" +#include "nsdynmemLIB.h" +#include "socket_api.h" +#include "net_interface.h" +#include "randLIB.h" +#include "eventOS_callback_timer.h" +#include "coap_connection_handler_stub.h" + +thread_conn_handler_stub_def thread_conn_handler_stub; + +int coap_connection_handler_virtual_recv(thread_conn_handler_t *handler, uint8_t address[static 16], uint16_t port, uint8_t *data_ptr, uint16_t data_len) +{ + return thread_conn_handler_stub.int_value; +} + +thread_conn_handler_t *connection_handler_create(int (*recv_cb)(int8_t socket_id, uint8_t address[static 16], uint16_t port, unsigned char *, int), + int (*send_cb)(int8_t socket_id, uint8_t address[static 16], uint16_t port, const unsigned char *, int), + int (*pw_cb)(int8_t socket_id, uint8_t address[static 16], uint16_t port, uint8_t *pw_ptr, uint8_t *pw_len), + void(*done_cb)(int8_t socket_id, uint8_t address[static 16], uint16_t port, uint8_t keyblock[static KEY_BLOCK_LEN]) ) +{ + thread_conn_handler_stub.send_to_sock_cb = send_cb; + thread_conn_handler_stub.receive_from_sock_cb = recv_cb; + thread_conn_handler_stub.get_passwd_cb = pw_cb; + thread_conn_handler_stub.sec_done_cb = done_cb; + return thread_conn_handler_stub.handler_obj; +} + +void connection_handler_destroy(thread_conn_handler_t *handler) +{ + +} + +void connection_handler_close_secure_connection( thread_conn_handler_t *handler ) +{ + +} + +int coap_connection_handler_open_connection(thread_conn_handler_t *handler, uint16_t listen_port, bool use_ephemeral_port, bool is_secure, bool is_real_socket, bool bypassSec) +{ + return thread_conn_handler_stub.int_value; +} + +int coap_connection_handler_send_data(thread_conn_handler_t *handler, ns_address_t *dest_addr, uint8_t *data_ptr, uint16_t data_len, bool bypass_link_sec) +{ + return thread_conn_handler_stub.int_value; +} + +bool coap_connection_handler_socket_belongs_to(thread_conn_handler_t *handler, int8_t socket_id) +{ + return thread_conn_handler_stub.bool_value; +} diff --git a/test/coap-service/unittest/stub/coap_connection_handler_stub.h b/test/coap-service/unittest/stub/coap_connection_handler_stub.h new file mode 100644 index 0000000000..1211f2d52e --- /dev/null +++ b/test/coap-service/unittest/stub/coap_connection_handler_stub.h @@ -0,0 +1,32 @@ +#ifndef __COAP_CONNECTION_HANDLER_STUB_H__ +#define __COAP_CONNECTION_HANDLER_STUB_H__ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#include "coap_connection_handler.h" + +typedef struct { + int int_value; + bool bool_value; + thread_conn_handler_t *handler_obj; + + int (*send_to_sock_cb)(int8_t socket_id, uint8_t address[static 16], uint16_t port, const unsigned char *, int); + int (*receive_from_sock_cb)(int8_t socket_id, uint8_t address[static 16], uint16_t port, unsigned char *, int); + int (*get_passwd_cb)(int8_t socket_id, uint8_t address[static 16], uint16_t port, uint8_t *pw_ptr, uint8_t *pw_len); + void (*sec_done_cb)(int8_t socket_id, uint8_t address[static 16], uint16_t port, uint8_t keyblock[static 40]); + +} thread_conn_handler_stub_def; + +extern thread_conn_handler_stub_def thread_conn_handler_stub; + +#ifdef __cplusplus +} +#endif + + +#endif diff --git a/test/coap-service/unittest/stub/coap_message_handler_stub.c b/test/coap-service/unittest/stub/coap_message_handler_stub.c new file mode 100644 index 0000000000..1890237e9f --- /dev/null +++ b/test/coap-service/unittest/stub/coap_message_handler_stub.c @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2015 ARM Limited. All rights reserved. + */ + +#include "coap_message_handler_stub.h" + +coap_message_handler_stub_def coap_message_handler_stub; + +coap_msg_handler_t *coap_message_handler_init(void *(*used_malloc_func_ptr)(uint16_t), void (*used_free_func_ptr)(void *), + uint8_t (*used_tx_callback_ptr)(uint8_t *, uint16_t, sn_nsdl_addr_s *, void *)) +{ + if(coap_message_handler_stub.coap_ptr){ + coap_message_handler_stub.coap_ptr->sn_coap_service_malloc = used_malloc_func_ptr; + coap_message_handler_stub.coap_ptr->sn_coap_service_free = used_free_func_ptr; + coap_message_handler_stub.coap_ptr->sn_coap_tx_callback = used_tx_callback_ptr; + } + return coap_message_handler_stub.coap_ptr; +} + +int8_t coap_message_handler_destroy(coap_msg_handler_t *handle) +{ + return coap_message_handler_stub.int8_value; +} + +coap_transaction_t *coap_message_handler_find_transaction(uint8_t *address_ptr, uint16_t port) +{ + return coap_message_handler_stub.coap_tx_ptr; +} + +int16_t coap_message_handler_coap_msg_process(coap_msg_handler_t *handle, int8_t socket_id, uint8_t source_addr_ptr[static 16], uint16_t port, + uint8_t *data_ptr, uint16_t data_len, int16_t (cb)(int8_t, sn_coap_hdr_s *, coap_transaction_t *)) +{ + coap_message_handler_stub.cb = cb; + return coap_message_handler_stub.int16_value; +} + +uint16_t coap_message_handler_request_send(coap_msg_handler_t *handle, int8_t service_id, uint8_t options, const uint8_t destination_addr[static 16], + uint16_t destination_port, uint8_t msg_type, uint8_t msg_code, const char *uri, uint8_t cont_type, + const uint8_t *payload_ptr, uint16_t payload_len, coap_message_handler_response_recv *request_response_cb) +{ + return coap_message_handler_stub.uint16_value; +} + +int8_t coap_message_handler_response_send(coap_msg_handler_t *handle, int8_t service_id, uint8_t options, sn_coap_hdr_s *request_ptr, sn_coap_msg_code_e message_code, + int32_t content_type, const uint8_t *payload_ptr, uint16_t payload_len) +{ + return coap_message_handler_stub.int8_value; +} + +int8_t coap_message_handler_exec(coap_msg_handler_t *handle, uint32_t current_time) +{ + return coap_message_handler_stub.int8_value; +} + + diff --git a/test/coap-service/unittest/stub/coap_message_handler_stub.h b/test/coap-service/unittest/stub/coap_message_handler_stub.h new file mode 100644 index 0000000000..6e0b74fd55 --- /dev/null +++ b/test/coap-service/unittest/stub/coap_message_handler_stub.h @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2015 ARM Limited. All rights reserved. + */ +#ifndef __COAP_MESSAGE_HANDLER_STUB_H__ +#define __COAP_MESSAGE_HANDLER_STUB_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include "coap_message_handler.h" + +typedef struct { + int8_t int8_value; + int16_t int16_value; + uint16_t uint16_value; + coap_msg_handler_t *coap_ptr; + coap_transaction_t *coap_tx_ptr; + int16_t (*cb)(int8_t, sn_coap_hdr_s *, coap_transaction_t *); +} coap_message_handler_stub_def; + +extern coap_message_handler_stub_def coap_message_handler_stub; + +#ifdef __cplusplus +} +#endif + +#endif // __COAP_MESSAGE_HANDLER_STUB_H__ diff --git a/test/coap-service/unittest/stub/coap_security_handler_stub.c b/test/coap-service/unittest/stub/coap_security_handler_stub.c new file mode 100644 index 0000000000..dd5cb3b69e --- /dev/null +++ b/test/coap-service/unittest/stub/coap_security_handler_stub.c @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2015 ARM Limited. All rights reserved. + */ + +#include +#include +#include +#include "ns_trace.h" +#include "nsdynmemLIB.h" +#include "coap_connection_handler.h" +#include "randLIB.h" +#include "coap_security_handler_stub.h" + +thread_sec_def coap_security_handler_stub; + +thread_security_t *thread_security_create(int8_t socket_id, int8_t timer_id, uint8_t *address_ptr, uint16_t port, + int (*send_cb)(int8_t socket_id, uint8_t *address_ptr, uint16_t port, const unsigned char *, size_t), + int (*receive_cb)(int8_t socket_id, unsigned char *, size_t), + void (*start_timer_cb)(int8_t timer_id, uint32_t min, uint32_t fin), + int (*timer_status_cb)(int8_t timer_id)) +{ + coap_security_handler_stub.send_cb = send_cb; + coap_security_handler_stub.receive_cb = receive_cb; + coap_security_handler_stub.start_timer_cb = start_timer_cb; + coap_security_handler_stub.timer_status_cb = timer_status_cb; + return coap_security_handler_stub.sec_obj; +} + +void thread_security_destroy(thread_security_t *sec) +{ + +} + +int coap_security_handler_connect(thread_security_t *sec, bool is_server, const unsigned char *pw, uint8_t len) +{ + sec->_is_started = true; + if( coap_security_handler_stub.counter >= 0){ + return coap_security_handler_stub.values[coap_security_handler_stub.counter--]; + } + return coap_security_handler_stub.int_value; +} + +int coap_security_handler_continue_connecting(thread_security_t *sec) +{ + if( coap_security_handler_stub.counter >= 0){ + return coap_security_handler_stub.values[coap_security_handler_stub.counter--]; + } + + return coap_security_handler_stub.int_value; +} + + +int coap_security_handler_send_message(thread_security_t *sec, unsigned char *message, size_t len) +{ + if( coap_security_handler_stub.counter >= 0){ + return coap_security_handler_stub.values[coap_security_handler_stub.counter--]; + } + return coap_security_handler_stub.int_value; +} + +int thread_security_send_close_alert(thread_security_t *sec) +{ + if( coap_security_handler_stub.counter >= 0){ + return coap_security_handler_stub.values[coap_security_handler_stub.counter--]; + } + return coap_security_handler_stub.int_value; +} + +int coap_security_handler_read(thread_security_t *sec, unsigned char* buffer, size_t len) +{ + if( coap_security_handler_stub.counter >= 0){ + return coap_security_handler_stub.values[coap_security_handler_stub.counter--]; + } + return coap_security_handler_stub.int_value; +} diff --git a/test/coap-service/unittest/stub/coap_security_handler_stub.h b/test/coap-service/unittest/stub/coap_security_handler_stub.h new file mode 100644 index 0000000000..83a4f7b0b2 --- /dev/null +++ b/test/coap-service/unittest/stub/coap_security_handler_stub.h @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2015 ARM Limited. All rights reserved. + */ +#ifndef __COAP_SECURITY_HANDLER_STUB_H__ +#define __COAP_SECURITY_HANDLER_STUB_H__ + +#include +#include "coap_security_handler.h" + +typedef struct tsh{ + thread_security_t *sec_obj; + int int_value; + int counter; + int values[10]; + + int (*send_cb)(int8_t socket_id, uint8_t *address_ptr, uint16_t port, const unsigned char *, size_t); + int (*receive_cb)(int8_t socket_id, unsigned char *, size_t); + void (*start_timer_cb)(int8_t timer_id, uint32_t min, uint32_t fin); + int (*timer_status_cb)(int8_t timer_id); +} thread_sec_def; + +extern thread_sec_def coap_security_handler_stub; + +#endif //__COAP_SECURITY_HANDLER_STUB_H__ diff --git a/test/coap-service/unittest/stub/coap_service_api_stub.c b/test/coap-service/unittest/stub/coap_service_api_stub.c new file mode 100644 index 0000000000..7b4f372b0c --- /dev/null +++ b/test/coap-service/unittest/stub/coap_service_api_stub.c @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2015 ARM Limited. All rights reserved. + */ + + +#include "config.h" +#ifdef HAVE_THREAD +#include + +#include "ns_types.h" +#include "ns_list.h" +#include "ns_trace.h" +#include "nsdynmemLIB.h" +#include "sn_nsdl.h" +#include "sn_coap_header.h" +#include "coap_service_api.h" +#include "coap_message_handler.h" +#include "eventOS_event.h" +#include "eventOS_scheduler.h" +#include "eventOS_event_timer.h" +#include "common_functions.h" +#include "net_interface.h" + +int8_t coap_service_initialize(int8_t interface_id, uint16_t listen_port, uint8_t service_options, + coap_service_security_start_cb *start_ptr, coap_service_security_done_cb *security_done_cb) +{ + return 0; +} + +void coap_service_delete(int8_t service_id) +{ +} + +int16_t coap_service_virtual_socket_recv(int8_t service_id, uint8_t source_addr_ptr[static 16], uint16_t port, uint8_t *data_ptr, uint16_t data_len) +{ + return 0; +} + +int16_t coap_service_virtual_socket_set_cb(int8_t service_id, coap_service_virtual_socket_send_cb *send_method_ptr) +{ + return 0; +} + +int8_t coap_service_register_uri(int8_t service_id, const char *uri, uint8_t allowed_method, coap_service_request_recv_cb *request_recv_cb) +{ + return 0; +} + +int8_t coap_service_unregister_uri(int8_t service_id, const char *uri) +{ + return 0; +} + +uint16_t coap_service_request_send(int8_t service_id, uint8_t options, const uint8_t destination_addr[static 16], uint16_t destination_port, uint8_t msg_type, uint8_t msg_code, const char *uri, + uint8_t cont_type, const uint8_t *payload_ptr, uint16_t payload_len, coap_message_handler_response_recv *request_response_cb){ + return 0; +} + +int8_t coap_service_response_send(int8_t service_id, uint8_t options, sn_coap_hdr_s *request_ptr, sn_coap_msg_code_e message_code, int32_t content_type, const uint8_t *payload_ptr,uint16_t payload_len){ + return 0; +} + +#endif diff --git a/test/coap-service/unittest/stub/common_functions_stub.c b/test/coap-service/unittest/stub/common_functions_stub.c new file mode 100644 index 0000000000..4e30823ce2 --- /dev/null +++ b/test/coap-service/unittest/stub/common_functions_stub.c @@ -0,0 +1,116 @@ +/* + * Copyright (c) 2014-2015 ARM Limited. All rights reserved. + */ +#include +#include +#include + +#include "ns_types.h" +//#include "common_functions.h" +#define COMMON_FUNCTIONS_FN + +#include + +bool bitsequal(const uint8_t *a, const uint8_t *b, uint_fast8_t bits) +{ + return true; +} + +uint8_t *bitcopy(uint8_t *restrict dst, const uint8_t *restrict src, uint_fast8_t bits) +{ + return NULL; +} + +COMMON_FUNCTIONS_FN uint8_t *common_write_64_bit(uint64_t value, uint8_t ptr[__static 8]) +{ + return NULL; +} + +COMMON_FUNCTIONS_FN uint64_t common_read_64_bit(const uint8_t data_buf[__static 8]) +{ + return 0; +} + +COMMON_FUNCTIONS_FN uint8_t *common_write_32_bit(uint32_t value, uint8_t ptr[__static 4]) +{ + return NULL; +} + +COMMON_FUNCTIONS_FN uint32_t common_read_32_bit(const uint8_t data_buf[__static 4]) +{ + return 0; +} + +COMMON_FUNCTIONS_FN uint8_t *common_write_32_bit_inverse(uint32_t value, uint8_t ptr[__static 4]) +{ + return NULL; +} + +COMMON_FUNCTIONS_FN uint32_t common_read_32_bit_inverse(const uint8_t data_buf[__static 4]) +{ + return 0; +} + +COMMON_FUNCTIONS_FN uint8_t *common_write_24_bit(uint_fast24_t value, uint8_t ptr[__static 3]) +{ + return NULL; +} + +COMMON_FUNCTIONS_FN uint_fast24_t common_read_24_bit(const uint8_t data_buf[__static 3]) +{ + return 0; +} + +COMMON_FUNCTIONS_FN uint8_t *common_write_16_bit(uint16_t value, uint8_t ptr[__static 2]) +{ + return NULL; +} + +COMMON_FUNCTIONS_FN uint16_t common_read_16_bit(const uint8_t data_buf[__static 2]) +{ + return 0; +} + +COMMON_FUNCTIONS_FN uint8_t *common_write_16_bit_inverse(uint16_t value, uint8_t ptr[__static 2]) +{ + return NULL; +} + +COMMON_FUNCTIONS_FN uint_fast8_t common_count_bits(uint8_t byte) +{ + return 0; +} + +COMMON_FUNCTIONS_FN uint_fast8_t common_count_leading_zeros(uint8_t byte) +{ + return 0; +} + +COMMON_FUNCTIONS_FN bool common_serial_number_greater_8(uint8_t s1, uint8_t s2) +{ + return false; +} + +COMMON_FUNCTIONS_FN bool common_serial_number_greater_16(uint16_t s1, uint16_t s2) +{ + return false; +} + +COMMON_FUNCTIONS_FN bool common_serial_number_greater_32(uint32_t s1, uint32_t s2) +{ + return false; +} + +COMMON_FUNCTIONS_FN bool bit_test(const uint8_t *bitset, uint_fast8_t bit) +{ + return false; +} + +COMMON_FUNCTIONS_FN void bit_set(uint8_t *bitset, uint_fast8_t bit) +{ +} + +COMMON_FUNCTIONS_FN void bit_clear(uint8_t *bitset, uint_fast8_t bit) +{ + +} diff --git a/test/coap-service/unittest/stub/cudp_stub.c b/test/coap-service/unittest/stub/cudp_stub.c new file mode 100644 index 0000000000..08f76aa92c --- /dev/null +++ b/test/coap-service/unittest/stub/cudp_stub.c @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2013-2015 ARM Limited. All rights reserved. + */ +/** + * \file cudp.c + * \brief This file contains UDP layer decode, compress. + */ +#include "config.h" +#include "ns_types.h" +//#include "Core/include/address.h" +#include "Core/include/buffer.h" +//#include "string.h" +//#include "Core/include/routing_table.h" +//#include "6LoWPAN/IPHC_Decode/cipv6.h" +//#include "6LoWPAN/IPHC_Decode/cudp.h" +//#include "Common_Protocols/udp.h" +//#include "6LoWPAN/Bootstraps/network_lib.h" +//#include "common_functions.h" + +buffer_t *parse_udp_header(buffer_t *buf) +{ + return NULL; +} + +buffer_t *cudp_compres_header(buffer_t *buf) +{ + return NULL; +} + +buffer_t *cudp_decode_to_full(buffer_t *buf) +{ + return NULL; +} + + + diff --git a/test/coap-service/unittest/stub/dhcp_service_api_stub.c b/test/coap-service/unittest/stub/dhcp_service_api_stub.c new file mode 100644 index 0000000000..7f1637be8e --- /dev/null +++ b/test/coap-service/unittest/stub/dhcp_service_api_stub.c @@ -0,0 +1,157 @@ +/* + * Copyright (c) 2013-2015 ARM Limited. All rights reserved. + */ + +#include +#include +#include +#include "eventOS_event.h" +#include "eventOS_scheduler.h" +#include "eventOS_event_timer.h" +#include "nsdynmemLIB.h" +#include "ns_list.h" +#include "randLIB.h" +#include "socket_api.h" +#include "net_interface.h" +#include "common_functions.h" +#include "libDHCPv6/libDHCPv6.h" +#include "NWK_INTERFACE/Include/protocol.h" // just for protocol_core_monotonic_time + +#include "dhcp_service_api.h" + +#define TRACE_GROUP "dhcp" + +#define MAX_SERVERS 20 + +/* Fixed-point randomisation limits for randlib_randomise_base() - RFC 3315 + * says RAND is uniformly distributed between -0.1 and +0.1 + */ +#define RAND1_LOW 0x7333 // 1 - 0.1; minimum for "1+RAND" +#define RAND1_HIGH 0x8CCD // 1 + 0.1; maximum for "1+RAND" + +typedef struct { + dhcp_service_receive_req_cb *recv_req_cb; + uint16_t instance_id; + int8_t interface_id; + ns_list_link_t link; +} server_instance_t; +typedef NS_LIST_HEAD(server_instance_t, link) server_instance_list_t; + +typedef struct { + ns_address_t addr; + dhcp_service_receive_resp_cb *recv_resp_cb; + uint16_t instance_id; + int8_t interface_id; + int8_t socket; + uint8_t options; + void *client_obj_ptr; + uint32_t msg_tr_id; + uint32_t message_tr_id; + uint32_t first_transmit_time; + uint16_t timeout; + uint16_t timeout_init; + uint16_t timeout_max; + uint8_t retrans_max; + uint8_t retrans; + uint8_t *msg_ptr; + uint16_t msg_len; + ns_list_link_t link; +} msg_tr_t; +typedef NS_LIST_HEAD(msg_tr_t, link) tr_list_t; + +typedef struct { + ns_address_t src_address; + server_instance_list_t srv_list; + tr_list_t tr_list; + int8_t dhcp_server_socket; + int8_t dhcp_client_socket; + int8_t dhcpv6_socket_service_tasklet; +} dhcp_service_class_t; + +#define DHCPV6_SOCKET_SERVICE_TASKLET_INIT 1 +#define DHCPV6_SOCKET_SERVICE_TIMER 2 + +#define DHCPV6_SOCKET_SERVICE_TIMER_ID 1 + +#define DHCPV6_SOCKET_TIMER_UPDATE_PERIOD_IN_MS 100 + +dhcp_service_class_t *dhcp_service = NULL; + +void dhcp_service_send_message(msg_tr_t *msg_tr_ptr); + +void DHCPv6_socket_service_tasklet(arm_event_s *event) +{ +} + +bool dhcp_service_allocate(void) +{ + return false; +} + +msg_tr_t *dhcp_tr_find(uint32_t msg_tr_id) +{ + return NULL; +} + +msg_tr_t *dhcp_tr_create(void) +{ + return NULL; +} + +void dhcp_tr_delete(msg_tr_t *msg_ptr) +{ +} + +void dhcp_tr_set_retry_timers(msg_tr_t *msg_ptr, uint8_t msg_type) +{ +} + +server_instance_t *dhcp_service_client_find(uint16_t instance_id) +{ + return NULL; +} + +void recv_dhcp_server_msg(void *cb_res) +{ +} + +void recv_dhcp_client_msg(void *cb_res) +{ +} + +uint16_t dhcp_service_init(int8_t interface_id, dhcp_service_receive_req_cb *receive_req_cb) +{ + return 0; +} + +void dhcp_service_delete(uint16_t instance) +{ +} + +int dhcp_service_send_resp(uint32_t msg_tr_id, uint8_t options, uint8_t *msg_ptr, uint16_t msg_len) +{ + return 0; +} + +uint32_t dhcp_service_send_req(uint16_t instance_id, uint8_t options, void *ptr, const uint8_t addr[static 16], uint8_t *msg_ptr, uint16_t msg_len, dhcp_service_receive_resp_cb *receive_resp_cb) +{ + return 0; +} + +void dhcp_service_set_retry_timers(uint32_t msg_tr_id, uint16_t timeout_init, uint16_t timeout_max, uint8_t retrans_max) +{ +} + +void dhcp_service_req_remove(uint32_t msg_tr_id) +{ +} + +void dhcp_service_send_message(msg_tr_t *msg_tr_ptr) +{ +} + +bool dhcp_service_timer_tick(uint16_t ticks) +{ + return false; +} + diff --git a/test/coap-service/unittest/stub/eventOS_event_stub.c b/test/coap-service/unittest/stub/eventOS_event_stub.c new file mode 100644 index 0000000000..e70337ebe2 --- /dev/null +++ b/test/coap-service/unittest/stub/eventOS_event_stub.c @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2015 ARM Limited. All rights reserved. + */ + +#include +#include "ns_types.h" +#include "eventOS_event.h" +#include "eventOS_event_stub.h" + +eventOs_event_stub_def eventOs_event_stub; + +int8_t eventOS_event_send(arm_event_s *event) +{ + return eventOs_event_stub.int8_value; +} + +int8_t eventOS_event_handler_create(void (*handler_func_ptr)(arm_event_s *), uint8_t init_event_type) +{ + eventOs_event_stub.event_ptr = handler_func_ptr; + return eventOs_event_stub.int8_value; +} diff --git a/test/coap-service/unittest/stub/eventOS_event_stub.h b/test/coap-service/unittest/stub/eventOS_event_stub.h new file mode 100644 index 0000000000..603fda58af --- /dev/null +++ b/test/coap-service/unittest/stub/eventOS_event_stub.h @@ -0,0 +1,22 @@ +#ifndef __EVENTOS_EVENT_STUB_H__ +#define __EVENTOS_EVENT_STUB_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include "eventOS_event.h" + +typedef struct { + void (*event_ptr)(arm_event_s *); + int8_t int8_value; +} eventOs_event_stub_def; + +extern eventOs_event_stub_def eventOs_event_stub; + +#ifdef __cplusplus +} +#endif + +#endif // __EVENTOS_EVENT_STUB_H__ diff --git a/test/coap-service/unittest/stub/icmpv6_stub.c b/test/coap-service/unittest/stub/icmpv6_stub.c new file mode 100644 index 0000000000..9d567f6c43 --- /dev/null +++ b/test/coap-service/unittest/stub/icmpv6_stub.c @@ -0,0 +1,141 @@ +/* + * Copyright (c) 2013-2015 ARM Limited. All rights reserved. + */ +#include "config.h" +#include "ns_types.h" +#include "string.h" +#include "ns_trace.h" +#include "NWK_INTERFACE/Include/protocol.h" +#ifdef HAVE_RPL +#include "6LoWPAN/RPL/rpl.h" +#endif +#include "6LoWPAN/ND/icmp.h" +#include "Common_Protocols/icmpv6.h" +#include "Common_Protocols/icmpv6_prefix.h" +#include "Common_Protocols/icmpv6_radv.h" +#include "Common_Protocols/ipv6.h" +#include "ipv6_stack/protocol_ipv6.h" +#include "ip_fsc.h" +#include "ipv6_stack/ipv6_routing_table.h" +#ifdef NVM_BORDER_ROUTER +#include "br_list_nvm_api.h" +#endif +#include "Service_Libs/whiteboard/whiteboard.h" +#include "NWK_INTERFACE/Include/protocol_stats.h" +#include "common_functions.h" +#include "6LoWPAN/ND/nd_router_object.h" +#include "6LoWPAN/Bootstraps/protocol_6lowpan.h" + +#define TRACE_GROUP_ICMPTv6 "icmp" + +buffer_t *icmpv6_error(buffer_t *buf, protocol_interface_info_entry_t *cur, uint8_t type, uint8_t code, uint32_t aux) +{ + return NULL; +} + +#ifndef NO_IPV6_PMTUD + +buffer_t *icmpv6_packet_too_big_handler(buffer_t *buf) +{ + return NULL; +} +#endif + +buffer_t *icmpv6_echo_request_handler(buffer_t *buf) +{ + return NULL; +} + +buffer_t *icmpv6_ns_handler(buffer_t *buf) +{ + return NULL; +} + +int icmpv6_slaac_prefix_update(struct protocol_interface_info_entry *cur, uint8_t *prefix_ptr, uint8_t prefix_len, uint32_t valid_lifetime, uint32_t preferred_lifetime) +{ + return 0; +} + +if_address_entry_t *icmpv6_slaac_address_add(protocol_interface_info_entry_t *cur, uint8_t *prefix_ptr, uint8_t prefix_len, uint32_t valid_lifetime, uint32_t preferred_lifetime, bool skip_dad, slaac_src_e slaac_src) +{ + return NULL; +} + +buffer_t *icmpv6_up(buffer_t *buf) +{ + return NULL; +} + +buffer_t *icmpv6_down(buffer_t *buf) +{ + return NULL; +} + +buffer_t *icmpv6_build_rs(protocol_interface_info_entry_t *cur, const uint8_t *dest) +{ + return NULL; +} + +uint8_t *icmpv6_write_icmp_lla(protocol_interface_info_entry_t *cur, uint8_t *dptr, uint8_t icmp_opt) +{ + return NULL; +} + +/* + * Write either an ICMPv6 Prefix Information Option for a Router Advertisement + * (RFC4861+6275), or an RPL Prefix Information Option (RFC6550). + * Same payload, different type/len. + */ +uint8_t *icmpv6_write_prefix_option(const prefix_list_t *prefixes, uint8_t *dptr, uint8_t rpl_prefix, protocol_interface_info_entry_t *cur) +{ + return NULL; +} + +buffer_t *icmpv6_build_ns(protocol_interface_info_entry_t *cur, const uint8_t target_addr[16], const uint8_t *prompting_src_addr, bool unicast, bool unspecified_source, const aro_t *aro) +{ + return NULL; +} + +void icmpv6_build_echo_req(protocol_interface_info_entry_t *cur, const uint8_t target_addr[16]) +{ +} + +buffer_t *icmpv6_build_dad(protocol_interface_info_entry_t *cur, buffer_t *buf, uint8_t type, const uint8_t dest_addr[16], const uint8_t eui64[8], const uint8_t reg_addr[16], uint8_t status, uint16_t lifetime) +{ + return NULL; +} + +buffer_t *icmpv6_build_na(buffer_t *buf, bool solicited, bool override, const uint8_t target[static 16], const aro_t *aro) +{ + return NULL; +} + +buffer_t *icmpv6_na_handler(buffer_t *buf) +{ + return NULL; +} + +buffer_t *icmpv6_build_mld(protocol_interface_info_entry_t *cur, buffer_t *buf, uint8_t type, uint16_t max_response_delay, const uint8_t address[static 16]) +{ + return NULL; +} + +bool icmpv6_options_well_formed(const uint8_t *dptr, uint_fast16_t dlen) +{ + return false; +} + +bool icmpv6_options_well_formed_in_buffer(const buffer_t *buf, uint16_t offset) +{ + return false; +} + +const uint8_t *icmpv6_find_option(const uint8_t *dptr, uint_fast16_t dlen, uint8_t option, uint8_t optlen) +{ + return NULL; +} + +const uint8_t *icmpv6_find_option_in_buffer(const buffer_t *buf, uint_fast16_t offset, uint8_t option, uint8_t optlen) +{ + return NULL; +} diff --git a/test/coap-service/unittest/stub/iphc_compress_stub.c b/test/coap-service/unittest/stub/iphc_compress_stub.c new file mode 100644 index 0000000000..a9d9eba74a --- /dev/null +++ b/test/coap-service/unittest/stub/iphc_compress_stub.c @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2014-2015 ARM Limited. All rights reserved. + */ +#include "ns_list.h" +#include "common_functions.h" +#include "platform/ns_debug.h" +#include "nsdynmemLIB.h" +#include +#include "NWK_INTERFACE/Include/protocol.h" +#include "Common_Protocols/ipv6.h" +#include "6LoWPAN/IPHC_Decode/cipv6.h" + +typedef struct iphc_compress_state { + protocol_interface_info_entry_t *const interface; + const uint8_t *in; + uint8_t *out; + uint16_t len; + uint16_t out_space; + uint16_t consumed; + uint16_t produced; + const uint8_t *outer_src_iid; + const uint8_t *outer_dst_iid; +} iphc_compress_state_t; + +buffer_t *iphc_compress(protocol_interface_info_entry_t *cur, buffer_t *buf, uint16_t hc_space) +{ + return NULL; +} diff --git a/test/coap-service/unittest/stub/iphc_decompress_stub.c b/test/coap-service/unittest/stub/iphc_decompress_stub.c new file mode 100644 index 0000000000..88f14f13f1 --- /dev/null +++ b/test/coap-service/unittest/stub/iphc_decompress_stub.c @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2014-2015 ARM Limited. All rights reserved. + */ +#include "ns_trace.h" +#include "common_functions.h" +#include "nsdynmemLIB.h" +#include +#include "NWK_INTERFACE/Include/protocol.h" +#include "6LoWPAN/IPHC_Decode/cipv6.h" +#include "Common_Protocols/ipv6.h" +#include "6LoWPAN/IPHC_Decode/iphc_decompress.h" + +#define TRACE_GROUP_IPHC_DECOMPRESS "iphc" + +uint8_t iphc_header_scan(buffer_t *buf, uint16_t *uncompressed_size) +{ + return 0; +} + +buffer_t *iphc_decompress(protocol_interface_info_entry_t *cur, buffer_t *buf) +{ + return NULL; +} diff --git a/test/coap-service/unittest/stub/ipv6_routing_table_stub.c b/test/coap-service/unittest/stub/ipv6_routing_table_stub.c new file mode 100644 index 0000000000..1f90b4f455 --- /dev/null +++ b/test/coap-service/unittest/stub/ipv6_routing_table_stub.c @@ -0,0 +1,184 @@ +/* + * Copyright (c) 2012-2015 ARM Limited. All rights reserved. + */ +/* + * ipv6_routing_table.c + * + * Implements IPv6 Neighbour Cache (RFC 4861), Destination Cache (RFC 4861), + * and Routing Table (RFC 4191, incorporating the RFC 4861 Prefix List) + */ +#include "config.h" +#include "ns_types.h" +#include "common_functions.h" +#include "ip6string.h" +#include "randLIB.h" +#include "ns_trace.h" +#include "string.h" +#include "net_interface.h" +#include "Core/include/address.h" +#include "ipv6_stack/ipv6_routing_table.h" +#include "Common_Protocols/icmpv6.h" +#include "ipv6_stack/protocol_ipv6.h" +#include "nsdynmemLIB.h" + +#ifndef HAVE_DEBUG +#define TRACE_LEVEL_DEBUG 0 +#endif +#define TRACE_GROUP "rout" + +#define NCACHE_MAX_LONG_TERM 8 +#define NCACHE_MAX_SHORT_TERM 32 + +#define DCACHE_MAX_LONG_TERM 16 +#define DCACHE_MAX_SHORT_TERM 64 + +#define NCACHE_GC_PERIOD 20 +#define DCACHE_GC_PERIOD 20 + +#define NCACHE_GC_AGE 600 +#define DCACHE_GC_AGE 30 + +void ipv6_router_gone(ipv6_neighbour_cache_t *cache, ipv6_neighbour_t *entry) +{ +} + + +void ipv6_neighbour_cache_init(ipv6_neighbour_cache_t *cache, int8_t interface_id) +{ +} + +void ipv6_neighbour_cache_flush(ipv6_neighbour_cache_t *cache) +{ +} + + +ipv6_neighbour_t *ipv6_neighbour_lookup(ipv6_neighbour_cache_t *cache, const uint8_t *address) +{ + return NULL; +} + +void ipv6_neighbour_entry_remove(ipv6_neighbour_cache_t *cache, ipv6_neighbour_t *entry) +{ +} + +ipv6_neighbour_t *ipv6_neighbour_lookup_or_create(ipv6_neighbour_cache_t *cache, const uint8_t *address/*, bool tentative*/) +{ + return NULL; +} + +ipv6_neighbour_t *ipv6_neighbour_lookup_or_create_by_interface_id(int8_t interface_id, const uint8_t *address/*, bool tentative*/) +{ + return NULL; +} + +ipv6_neighbour_t *ipv6_neighbour_used(ipv6_neighbour_cache_t *cache, ipv6_neighbour_t *entry) +{ + return NULL; +} + +void ipv6_neighbour_invalidate_ll_addr(ipv6_neighbour_cache_t *cache, addrtype_t ll_type, const uint8_t *ll_address) +{ +} + +void ipv6_neighbour_set_state(ipv6_neighbour_cache_t *cache, ipv6_neighbour_t *entry, ip_neighbour_cache_state_t state) +{ +} + +/* Called when LL address information is received other than in an NA (NS source, RS source, RA source, Redirect target) */ +void ipv6_neighbour_entry_update_unsolicited(ipv6_neighbour_cache_t *cache, ipv6_neighbour_t *entry, addrtype_t type, const uint8_t *ll_address/*, bool tentative*/) +{ +} + +ipv6_neighbour_t *ipv6_neighbour_update_unsolicited(ipv6_neighbour_cache_t *cache, const uint8_t *ip_address, addrtype_t type, const uint8_t *ll_address/*, bool tentative*/) +{ + return NULL; +} + +void ipv6_neighbour_update_from_na(ipv6_neighbour_cache_t *cache, ipv6_neighbour_t *entry, uint8_t flags, addrtype_t ll_type, const uint8_t *ll_address) +{ +} + +void ipv6_neighbour_reachability_confirmation(const uint8_t ip_address[__static 16], int8_t interface_id) +{ +} + +void ipv6_neighbour_cache_print(const ipv6_neighbour_cache_t *cache, uint8_t dlevel) +{ +} + + + +void ipv6_neighbour_cache_slow_timer(ipv6_neighbour_cache_t *cache, uint8_t seconds) +{ +} + +void ipv6_neighbour_cache_fast_timer(ipv6_neighbour_cache_t *cache, uint16_t ticks) +{ +} + +void ipv6_destination_cache_print(uint8_t dlevel) +{ +} + +ipv6_destination_t *ipv6_destination_lookup_or_create(const uint8_t *address, int8_t interface_id) +{ + return NULL; +} + +void ipv6_destination_redirect(const uint8_t *dest_addr, const uint8_t *sender_addr, const uint8_t *redirect_addr, int8_t interface_id, addrtype_t ll_type, const uint8_t *ll_address) +{ +} + +void ipv6_destination_release(ipv6_destination_t *dest) +{ +} + +void ipv6_destination_cache_timer(uint8_t seconds) +{ +} + +void ipv6_route_table_print(uint8_t dlevel) +{ +} + +ipv6_route_t *ipv6_route_choose_next_hop(const uint8_t *dest, int8_t interface_id, ipv6_route_predicate_fn_t *predicate) +{ + return NULL; +} + +ipv6_route_t *ipv6_route_lookup_with_info(const uint8_t *prefix, uint8_t prefix_len, int8_t interface_id, const uint8_t *next_hop, ipv6_route_src_t source, void *info, int_fast16_t src_id) +{ + return NULL; +} + +ipv6_route_t *ipv6_route_add(const uint8_t *prefix, uint8_t prefix_len, int8_t interface_id, const uint8_t *next_hop, ipv6_route_src_t source, uint32_t lifetime, int_fast8_t pref) +{ + return NULL; +} + +ipv6_route_t *ipv6_route_add_with_info(const uint8_t *prefix, uint8_t prefix_len, int8_t interface_id, const uint8_t *next_hop, ipv6_route_src_t source, void *info, uint8_t source_id, uint32_t lifetime, int_fast8_t pref) +{ + return NULL; +} + +int_fast8_t ipv6_route_delete(const uint8_t *prefix, uint8_t prefix_len, int8_t interface_id, const uint8_t *next_hop, ipv6_route_src_t source) +{ + return -1; +} + +int_fast8_t ipv6_route_delete_with_info(const uint8_t *prefix, uint8_t prefix_len, int8_t interface_id, const uint8_t *next_hop, ipv6_route_src_t source, void *info, int_fast16_t source_id) +{ + return -1; +} + +void ipv6_route_table_remove_interface(int8_t interface_id) +{ +} + +void ipv6_route_table_remove_info(int8_t interface_id, ipv6_route_src_t source, void *info) +{ +} + +void ipv6_route_table_ttl_update(uint16_t seconds) +{ +} diff --git a/test/coap-service/unittest/stub/ipv6_stub.c b/test/coap-service/unittest/stub/ipv6_stub.c new file mode 100644 index 0000000000..bc8f03714c --- /dev/null +++ b/test/coap-service/unittest/stub/ipv6_stub.c @@ -0,0 +1,99 @@ +/* + * Copyright (c) 2013-2015 ARM Limited. All rights reserved. + */ + +#include "config.h" +#define _HAVE_IPV6 + +#ifdef _HAVE_IPV6 + +#include "ns_types.h" +#include "string.h" +#include "nsdynmemLIB.h" +#include "Core/include/socket.h" +#include "ns_trace.h" +#include "NWK_INTERFACE/Include/protocol.h" +#include "NWK_INTERFACE/Include/protocol_stats.h" +#include "Common_Protocols/ipv6.h" +#include "Common_Protocols/ipv6_fragmentation.h" +#include "ipv6_stack/protocol_ipv6.h" +#include "ipv6_stack/ipv6_routing_table.h" +#include "Common_Protocols/icmpv6.h" +//#include "6LoWPAN/Bootstraps/network_lib.h" +//#include "6LoWPAN/Bootstraps/protocol_6lowpan.h" +#ifdef HAVE_RPL +#include "6LoWPAN/IPHC_Decode/cipv6.h" +#include "6LoWPAN/RPL/rpl.h" +#endif +#ifdef NVM_BORDER_ROUTER +#include "br_list_nvm_api.h" +#endif +#include "Service_Libs/whiteboard/whiteboard.h" +#include "common_functions.h" + +#define TRACE_GROUP_IPv6 "ipv6" + +const uint8_t MC_SITE[16] = {0xff, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfb}; +const uint8_t MC_LOCAL[16] = {0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfb}; + +bool ipv6_new_layers_for_unicast; +bool ipv6_new_layers_for_lowpan_multicast; +bool ipv6_new_layers_for_ethernet_multicast; + +bool ipv6_use_new_layers(buffer_t *buf, bool multicast) +{ + return false; +} + +buffer_routing_info_t *ipv6_buffer_route(buffer_t *buf) +{ + return NULL; +} + +buffer_t *ipv6_down(buffer_t *buf) +{ + return NULL; +} + +buffer_t *ipv6_up(buffer_t *buf) +{ + return NULL; +} + +uint16_t ipv6_header_size_required(buffer_t *buf) +{ + return 0; +} + +uint16_t ipv6_max_unfragmented_payload(buffer_t *buf, uint16_t mtu_limit) +{ + return 0; +} + +uint16_t ipv6_mtu(buffer_t *buf) +{ + return 0; +} + +buffer_t *ipv6_down_new(buffer_t *buf) +{ + return NULL; +} + +buffer_t *ipv6_forwarding_down(buffer_t *buf) +{ + return NULL; +} + +buffer_t *ipv6_consider_forwarding_received_packet(buffer_t *buf, protocol_interface_info_entry_t *cur, const sockaddr_t *ll_src) +{ + return NULL; +} + +buffer_t *ipv6_forwarding_up(buffer_t *buf) +{ + return NULL; +} + +#endif /* _HAVE_IPV6 */ + diff --git a/test/coap-service/unittest/stub/libDHCPv6_server_stub.c b/test/coap-service/unittest/stub/libDHCPv6_server_stub.c new file mode 100644 index 0000000000..1e6b5effce --- /dev/null +++ b/test/coap-service/unittest/stub/libDHCPv6_server_stub.c @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2014-2015 ARM Limited. All rights reserved. + */ + + +#include +#include +#include +#include "libDHCPv6/libDHCPv6_server.h" +#include "libDHCPv6/libDHCPv6.h" +#include "common_functions.h" +#include "platform/ns_debug.h" + +void libdhcpv6_gua_servers_time_update(uint32_t timeUpdateInSeconds) +{ +} + +dhcpv6_gua_server_entry_s *libdhcpv6_server_data_get_by_prefix_and_interfaceid(int8_t interfaceId, const uint8_t *prefixPtr) +{ + return NULL; +} + +dhcpv6_gua_server_entry_s *libdhcpv6_server_data_get_by_prefix_and_socketinstance(uint16_t socketInstance, uint8_t *prefixPtr) +{ + return NULL; +} + + +dhcpv6_gua_server_entry_s *libdhcpv6_gua_server_allocate(uint8_t *prefix, int8_t interfaceId, uint8_t *serverDUID, uint16_t serverDUIDType, dhcp_address_prefer_timeout_cb *prefered_timeout_cb) +{ + return NULL; +} + +void libdhcpv6_gua_server_free_by_prefix_and_interfaceid(uint8_t *prefix, int8_t interfaceId) +{ +} + +void libdhcpv6_gua_server_free_by_interfaceid(int8_t interfaceId) +{ +} + +dhcpv6_alloacted_address_entry_t *libdhcpv6_address_entry_allocate(uint32_t validLifetime) +{ + return NULL; +} + +dhcpv6_alloacted_address_entry_t *libdhcpv6_address_get_from_allocated_list(dhcpv6_gua_server_entry_s *serverInfo, const uint8_t *address) +{ + return NULL; +} + +dhcpv6_alloacted_address_entry_t *libdhcpv6_address_allocated_list_scan(dhcpv6_gua_server_entry_s *serverInfo, uint8_t *linkId, uint16_t linkType, uint32_t iaID, uint32_t T0, uint32_t T1, bool allocateNew) +{ + return NULL; +} + diff --git a/test/coap-service/unittest/stub/libDHCPv6_stub.c b/test/coap-service/unittest/stub/libDHCPv6_stub.c new file mode 100644 index 0000000000..b653563ec6 --- /dev/null +++ b/test/coap-service/unittest/stub/libDHCPv6_stub.c @@ -0,0 +1,212 @@ +/* + * Copyright (c) 2014-2015 ARM Limited. All rights reserved. + */ + +#include "config.h" +#include +#include +#include "common_functions.h" +#include "libDHCPv6/libDHCPv6.h" +#include "randLIB.h" +#include "nsdynmemLIB.h" + + + +uint32_t libdhcpv6_txid_get(void) +{ + return 0; +} + +uint32_t libdhcpv6_renew_time_define(dhcpv6_client_server_data_t *addresInfo) +{ + return 0; +} + +dhcpv6_client_server_data_t *libdhcvp6_nontemporalAddress_server_data_allocate(int8_t interfaceId, uint8_t instanceId, uint8_t *duiId, uint16_t duiLinkType, uint8_t *nonTemporalPrefix, uint8_t *serverIPv6Address) +{ + return NULL; +} + +void libdhcvp6_nontemporalAddress_server_data_free(dhcpv6_client_server_data_t *removedEntry) +{ +} + +dhcpv6_client_server_data_t *libdhcpv6_nonTemporal_entry_get_by_instance(uint8_t instanceId) +{ + return NULL; +} +uint8_t libdhcpv6_nonTemporal_entry_get_unique_instance_id(void) +{ + return 0; +} + +dhcpv6_client_server_data_t *libdhcpv6_nonTemporal_entry_get_by_iaid(uint32_t iaId) +{ + return NULL; +} + +dhcpv6_client_server_data_t *libdhcpv6_nonTemporal_entry_get_by_transactionId(uint32_t txId) +{ + return NULL; +} + +dhcpv6_client_server_data_t *libdhcpv6_nonTemporal_entry_get_by_prefix(int8_t interfaceId, uint8_t *prefix) +{ + return NULL; +} + +uint16_t libdhcpv6_duid_option_size(uint16_t linkType) +{ + return 0; +} + +uint16_t libdhcpv6_client_data_option_size(uint16_t linkType) +{ + return 0; +} + +uint16_t libdhcvp6_request_option_size(uint8_t optionCnt) +{ + return 0; +} + +uint16_t libdhcpv6_non_temporal_address_size(bool addressDefined) +{ + return 0; +} + +int libdhcpv6_message_malformed_check(uint8_t *ptr, uint16_t data_len) +{ + return 0; +} + +uint8_t *libdhcpv6_header_write(uint8_t *ptr, uint8_t msgType, uint32_t transActionId) +{ + return NULL; +} + +uint8_t *libdhcpv6_elapsed_time_option_write(uint8_t *ptr, uint16_t elapsedTime) +{ + return NULL; +} + +uint8_t *libdhcpv6_rapid_commit_option_write(uint8_t *ptr) +{ + return NULL; +} + +uint8_t *libdhcvp6_vendor_specific_option_write(uint8_t *ptr, uint8_t *data, uint16_t dataLength) +{ + return NULL; +} + +uint8_t *libdhcvp6_request_option_write(uint8_t *ptr, uint8_t optionCnt, uint16_t *optionPtr) +{ + return NULL; +} + +uint8_t *libdhcpv6_duid_option_write(uint8_t *ptr, uint16_t duidRole, const dhcp_link_options_params_t *duid) +{ + return NULL; +} + +uint8_t *libdhcpv6_prefix_delegation_info_option_write(uint8_t *ptr, uint32_t iaId) +{ + return NULL; +} + +uint8_t *libdhcpv6_identity_association_option_write(uint8_t *ptr, uint32_t iaID, uint32_t TimerT1, uint32_t TimerT2, bool withAddress) +{ + return NULL; +} + +uint8_t *libdhcpv6_ia_address_option_write(uint8_t *ptr, const uint8_t *addressPtr, uint32_t preferredValidLifeTime, uint32_t validLifeTime) +{ + return NULL; +} + +uint8_t *libdhcpv6_status_code_write(uint8_t *ptr, uint16_t statusCode) +{ + return NULL; +} + +uint8_t *libdhcpv6_client_last_transaction_time_option_write(uint8_t *ptr, uint32_t last_transaction_Time) +{ + return NULL; +} + +int libdhcpv6_message_option_discover(uint8_t *ptr, uint16_t data_len, uint16_t discovered_type, dhcp_options_msg_t *option_info) +{ + return -1; +} + +int libdhcpv6_compare_DUID(dhcp_link_options_params_t *targetId, dhcp_link_options_params_t *parsedId) +{ + return -1; +} + +int libdhcpv6_reply_message_option_validate(dhcp_link_options_params_t *clientId, dhcp_link_options_params_t *serverId, dhcp_ia_non_temporal_params_t *dhcp_ia_non_temporal_params, uint8_t *ptr, uint16_t data_length) +{ + return 0; +} + +int libdhcpv6_advertisment_message_option_validate(dhcp_link_options_params_t *clientId, dhcp_link_options_params_t *serverId, dhcp_ia_non_temporal_params_t *dhcp_ia_non_temporal_params, uint8_t *ptr, uint16_t data_length) +{ + return 0; +} + +int libdhcpv6_renew_message_options_validate(uint8_t *ptr, uint16_t data_length, dhcp_link_options_params_t *clientLinkData, dhcp_link_options_params_t *serverLinkData, dhcp_ia_non_temporal_params_t *dhcp_ia_non_temporal_params) +{ + return 0; +} + +int libdhcpv6_solication_message_options_validate(uint8_t *ptr, uint16_t data_length, dhcp_link_options_params_t *clientLink, dhcp_ia_non_temporal_params_t *dhcp_ia_non_temporal_params) +{ + return 0; +} + +bool libdhcpv6_time_elapsed_option_at_packet(uint8_t *ptr, uint16_t length) +{ + return false; +} + +bool libdhcpv6_rapid_commit_option_at_packet(uint8_t *ptr, uint16_t length) +{ + return false; +} + +int libdhcpv6_get_duid_by_selected_type_id_opt(uint8_t *ptr, uint16_t data_length, uint16_t type , dhcp_link_options_params_t *params) +{ + return -1; +} + +int libdhcpv6_get_IA_address(uint8_t *ptr, uint16_t data_length, dhcp_ia_non_temporal_params_t *params) +{ + return -1; +} + +uint16_t libdhcpv6_address_request_message_len(uint16_t clientLinkType, uint16_t serverLinkType, uint8_t requstOptionCnt) +{ + return 0; +} + +uint16_t libdhcpv6_address_reply_message_len(uint16_t clientLinkType, uint16_t serverLinkType, uint16_t vendorDataLen, bool rapidCommon, bool status) +{ + return 0; +} + +uint8_t *libdhcpv6_generic_nontemporal_address_message_write(uint8_t *ptr, dhcpv6_solication_base_packet_s *packet, dhcpv6_ia_non_temporal_address_s *nonTemporalAddress, dhcp_link_options_params_t *serverLink) +{ + return NULL; +} + +uint8_t *libdhcpv6_reply_message_write(uint8_t *ptr, dhcpv6_reply_packet_s *replyPacket, dhcpv6_ia_non_temporal_address_s *nonTemporalAddress, dhcpv6_vendor_data_packet_s *vendorData) +{ + return NULL; +} + +uint16_t libdhcpv6_solication_message_length(uint16_t clientLinkType, bool addressDefined, uint8_t requestOptionCount) +{ + return 0; +} + diff --git a/test/coap-service/unittest/stub/lowpan_context_stub.c b/test/coap-service/unittest/stub/lowpan_context_stub.c new file mode 100644 index 0000000000..7e20e97e5f --- /dev/null +++ b/test/coap-service/unittest/stub/lowpan_context_stub.c @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2015 ARM Limited. All rights reserved. + */ + +#include "config.h" +#include "string.h" +#include "ns_types.h" +#include "ns_trace.h" +#include "nsdynmemLIB.h" +#include "ns_list.h" +#include "6LoWPAN/IPHC_Decode/lowpan_context.h" +#include "common_functions.h" + +#define TRACE_GROUP_LOWPAN_CONTEXT "lCon" + +lowpan_context_t *lowpan_contex_get_by_id(lowpan_context_list_t *list, uint8_t id) +{ + return NULL; +} + +lowpan_context_t *lowpan_context_get_by_address(lowpan_context_list_t *list, const uint8_t *ipv6Address) +{ + return NULL; +} + + +int_fast8_t lowpan_context_update(lowpan_context_list_t *list, uint8_t cid_flags, uint16_t lifetime, const uint8_t *prefix, uint_fast8_t len) +{ + return 0; +} + +void lowpan_context_list_free(lowpan_context_list_t *list) +{ +} + +void lowpan_context_timer(lowpan_context_list_t *list, uint_fast16_t ticks) +{ +} + diff --git a/test/coap-service/unittest/stub/mac_data_poll_stub.c b/test/coap-service/unittest/stub/mac_data_poll_stub.c new file mode 100644 index 0000000000..c0d561ae91 --- /dev/null +++ b/test/coap-service/unittest/stub/mac_data_poll_stub.c @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2015 ARM Limited. All rights reserved. + */ + +#include +#include "NWK_INTERFACE/Include/protocol.h" +#include "MAC/IEEE802_15_4/mac_data_poll.h" + + + +nwk_rfd_poll_setups_s *mac_data_poll_get_polling_info(struct protocol_interface_info_entry *cur) +{ + return NULL; +} + +void mac_data_poll_polltimer_set(struct protocol_interface_rf_mac_setup *rf_mac_setup, uint32_t slots) +{ + +} + +void mac_data_poll_init_protocol_poll(struct protocol_interface_info_entry *cur, uint8_t set_protocol_poll_active) +{ + +} + +uint32_t mac_data_poll_host_poll_time_max(struct protocol_interface_info_entry *cur) +{ + return 0; +} + +void mac_data_poll_protocol_poll_mode_decrement(struct protocol_interface_info_entry *cur) +{ + +} + +void mac_data_poll_protocol_poll_mode_disable(struct protocol_interface_info_entry *cur, uint8_t re_req) +{ + +} + +void mac_data_poll_enable_check(struct protocol_interface_info_entry *cur) +{ + +} + +int8_t mac_data_poll_host_mode_get(struct protocol_interface_info_entry *cur, net_host_mode_t *mode) +{ + return 0; +} + +void mac_data_poll_poll_done(void *cur, mac_event_t result, uint8_t *addr, addrtype_t type) +{ + +} + +void mac_data_poll_cb_run(struct protocol_interface_info_entry *cur) +{ + +} + +int8_t mac_data_poll_host_mode_set(struct protocol_interface_info_entry *cur, net_host_mode_t mode, uint32_t poll_time) +{ + return 0; +} + +void mac_data_poll_init(struct protocol_interface_info_entry *cur) +{ + +} + +void mac_data_poll_radio_disable_check(struct protocol_interface_info_entry *cur) +{ + +} + +uint32_t mac_data_poll_get_max_sleep_period(struct protocol_interface_info_entry *cur) +{ + return 0; +} + +uint32_t mac_data_poll_host_timeout(protocol_interface_info_entry_t *cur) +{ + return 0; +} diff --git a/test/coap-service/unittest/stub/mac_mlme_stub.c b/test/coap-service/unittest/stub/mac_mlme_stub.c new file mode 100644 index 0000000000..f76075c001 --- /dev/null +++ b/test/coap-service/unittest/stub/mac_mlme_stub.c @@ -0,0 +1,221 @@ +/* + * Copyright (c) 2015 ARM Limited. All rights reserved. + */ + +#include "config.h" +#include +#include "ns_types.h" +#include "eventOS_event.h" +#include "eventOS_scheduler.h" +#include "eventOS_callback_timer.h" +#include "ns_trace.h" +#include "nsdynmemLIB.h" +#include "NWK_INTERFACE/Include/protocol.h" +#include "NWK_INTERFACE/Include/protocol_timer.h" +#include "MAC/IEEE802_15_4/mac_data_interface.h" +#include "MAC/IEEE802_15_4/mac_data_poll.h" +#include "MAC/IEEE802_15_4/mac_indirect_data.h" +#include "MAC/IEEE802_15_4/mac_security_interface.h" +#include "MAC/IEEE802_15_4/mac_mlme.h" +#include "MAC/IEEE802_15_4/mac_timer.h" +#include "platform/arm_hal_interrupt.h" +#include "6LoWPAN/Thread/thread.h" +#include "6LoWPAN/Thread/thread_bootstrap.h" +#include "common_functions.h" + +int8_t mac_mlme_scan_requet(mac_scan_type_t type, protocol_interface_info_entry_t *interface_ptr) +{ + return -1; +} + +void mac_mlme_energy_scan(void (*passed_fptr)(uint8_t *), protocol_interface_info_entry_t *cur) +{ +} + +int8_t mac_mlme_active_scan_req(struct protocol_interface_info_entry *cur, channel_list_s *scan_list, void (*passed_fptr)(uint8_t *)) +{ + return -1; +} + +void mac_mlme_active_scan(void (*passed_fptr)(uint8_t *), protocol_interface_info_entry_t *cur) +{ +} + +void mac_mlme_free_scan_confirm(nwk_scan_params_s *params) +{ +} + + +void mac_mlme_start_req(mlme_start_t *s, protocol_interface_info_entry_t *cur) +{ +} + +void mac_mlme_cmd_frame_handle(buffer_t *buf) +{ +} + +void mac_mlme_active_scan_response_timer_start(void *interface) +{ +} + +void mac_mlme_timers_disbale(protocol_interface_rf_mac_setup_s *rf_ptr) +{ +} + +void mac_mlme_message_handler(arm_event_s *event) +{ +} + +void mac_mlme_event_cb(uint8_t event) +{ +} + +void mac_mlme_timer_cb(int8_t timer_id, uint16_t slots) +{ +} + +void mac_mlme_free_sacn_temporary_data(protocol_interface_rf_mac_setup_s *rf_mac_setup) +{ +} + +nwk_pan_descriptor_t *mac_mlme_free_pan_descriptions(nwk_pan_descriptor_t *nwk_cur_active) +{ + return NULL; +} + +int mac_mlme_data_base_allocate(protocol_interface_info_entry_t *entry) +{ + return -1; +} + +int8_t mac_mlme_nwk_id_filter_set(const uint8_t *nw_id, nwk_filter_params_s *filter) +{ + return -1; +} + +uint8_t mac_mlme_set_new_sqn(protocol_interface_rf_mac_setup_s *rf_setup) +{ + return 0; +} + +int8_t mac_mlme_set_panid(protocol_interface_info_entry_t *cur, uint16_t pan_id) +{ + return -1; +} + +int8_t mac_mlme_set_mac16(protocol_interface_info_entry_t *cur, uint16_t mac16) +{ + return -1; +} + +int8_t mac_mlme_reset_mac16(protocol_interface_info_entry_t *cur) +{ + return -1; +} + +void mac_mlme_write_mac64(protocol_interface_info_entry_t *cur, uint8_t *addrPtr) +{ +} + +bool mac_mlme_write_mac16(struct protocol_interface_rf_mac_setup *rf_setup, uint8_t *addrPtr) +{ + return false; +} + +bool mac_mlme_write_panid(struct protocol_interface_rf_mac_setup *rf_setup, uint8_t *addrPtr) +{ + return false; +} + +uint16_t mac_mlme_get_panid(protocol_interface_rf_mac_setup_s *rf_setup) +{ + return 0; +} + +uint16_t mac_mlme_get_mac16(protocol_interface_rf_mac_setup_s *rf_setup) +{ + return 0; +} + +void mac_mlme_soft_set_mac16(protocol_interface_rf_mac_setup_s *rf_setup, uint16_t shotAddress) +{ +} + +bool mac_mlme_write_our_addr(struct protocol_interface_info_entry *cur, sockaddr_t *sockaddr) +{ + return false; +} + + +void mac_mlme_write_mac64_by_interface_type(nwk_interface_id nwk_id, uint8_t *addrPtr) +{ +} + +int mac_mlme_beacon_notify(nwk_pan_descriptor_t *description, struct nwk_scan_params *scan_params) +{ +} + +uint8_t *mac_mlme_beacon_payload_allocate(protocol_interface_rf_mac_setup_s *rf_mac_setup, uint8_t len) +{ + return 0; +} + +uint8_t *mac_mlme_beacon_palyaod_ptr_get(protocol_interface_rf_mac_setup_s *rf_mac_setup) +{ + return NULL; +} + +nwk_pan_descriptor_t *mac_mlme_select_best_lqi(nwk_pan_descriptor_t *list) +{ + return NULL; +} + +void mac_mlme_drop_selected_from_the_scanresult(nwk_scan_params_s *scanParams, nwk_pan_descriptor_t *selected) +{ +} + +void mac_mlme_scan_confirmation_handle(mlme_scan_conf_t *r, protocol_interface_info_entry_t *cur_interface) +{ +} + +void mac_mlme_mac_halt(protocol_interface_info_entry_t *cur) +{ +} + +void mac_mle_mac_radio_enable(protocol_interface_info_entry_t *cur) +{ +} + +void mac_mlme_mac_wake_up(protocol_interface_info_entry_t *cur) +{ +} + + +int8_t mac_mlme_rf_disable(protocol_interface_info_entry_t *cur) +{ + return -1; +} + +void mac_mlme_rf_receiver_enable(protocol_interface_info_entry_t *cur) +{ +} + +int8_t mac_mlme_rf_channel_set(protocol_interface_info_entry_t *cur, uint8_t new_channel) +{ + return -1; +} + +int8_t mac_mlme_set_cordinator_address(protocol_interface_rf_mac_setup_s *rf_mac_setup, addrtype_t adr_type, uint8_t *adr_ptr) +{ + return -1; +} + +int8_t mac_mlme_get_cordinator_address(protocol_interface_rf_mac_setup_s *rf_mac_setup, addrtype_t *adr_type, uint8_t *adr_ptr) +{ + return -1; +} + +nwk_scan_params_s *mac_mlme_get_scan_params(protocol_interface_info_entry_t *interface) +{ + return NULL; +} diff --git a/test/coap-service/unittest/stub/mac_pairwise_key_stub.c b/test/coap-service/unittest/stub/mac_pairwise_key_stub.c new file mode 100644 index 0000000000..692320310d --- /dev/null +++ b/test/coap-service/unittest/stub/mac_pairwise_key_stub.c @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2015 ARM Limited. All rights reserved. + */ + + +#include "config.h" +#include +#include "ns_types.h" +#include "ns_trace.h" +#include "nsdynmemLIB.h" +#include "Core/include/address.h" +#include "MAC/IEEE802_15_4/mac_pairwise_key.h" + +#define TRACE_GROUP "mPKe" + +typedef NS_LIST_HEAD(mac_pairwise_key_entry_t, link) mac_pairwise_key_list_t; + +typedef struct mac_pairwise_interface_entry { + int8_t interfaceId; + mac_pairwise_key_list_t keyList; + ns_list_link_t link; /*!< List link entry */ +} mac_pairwise_interface_entry_t; + +mac_pairwise_interface_entry_t *mac_pairwise_key_list_allocate(int8_t interfaceId) +{ + return NULL; +} + +mac_pairwise_key_entry_t *mac_pairwise_key_entry_allocate(const uint8_t *eui64) +{ + return NULL; +} + +mac_pairwise_key_entry_t *mac_pairwise_key_entry_get(mac_pairwise_key_list_t *list, const uint8_t *eui64, bool Allocate) +{ + return NULL; +} + +mac_pairwise_interface_entry_t *mac_pairwise_key_main_class(int8_t interfaceId, bool Allocate) +{ + return NULL; +} + + + +int mac_pairwise_key_add(int8_t interface_id, uint32_t valid_life_time, const uint8_t eui64[static 8], const uint8_t key[static 16]) +{ + return 0; + +} + +int mac_pairwise_key_del(int8_t interface_id, const uint8_t eui64[static 8]) +{ + return 0; +} + + +int mac_pairwise_key_flush_list(int8_t interface_id) +{ + return 0; +} + + +mac_pairwise_key_entry_t *mac_pairwise_key_get_key(int8_t interface_id, const uint8_t *address, uint16_t panId, uint8_t addressType) +{ + return NULL; +} + +bool mac_pairwise_key_framecounter_validation(mac_pairwise_key_entry_t *keyEntry, uint32_t frameCounter) +{ + return false; +} + +void mac_pairwise_key_framecounter_update(mac_pairwise_key_entry_t *keyEntry, uint32_t frameCounter) +{ +} + + diff --git a/test/coap-service/unittest/stub/mac_security_interface_stub.c b/test/coap-service/unittest/stub/mac_security_interface_stub.c new file mode 100644 index 0000000000..0fab0aaa85 --- /dev/null +++ b/test/coap-service/unittest/stub/mac_security_interface_stub.c @@ -0,0 +1,106 @@ +/* + * Copyright (c) 2015 ARM Limited. All rights reserved. + */ + +#include "config.h" +#include "ns_types.h" +#include "eventOS_event.h" +#include "string.h" +#include "ns_trace.h" +#include "NWK_INTERFACE/Include/protocol.h" +#include "ccmLIB.h" +#include "MAC/IEEE802_15_4/mac_security_interface.h" +#include "NWK_INTERFACE/Include/protocol_stats.h" +#include "common_functions.h" +#include "6LoWPAN/Thread/thread.h" +#include "6LoWPAN/Thread/thread_management_internal.h" +#ifndef NO_MLE +#include "MLE/mle.h" +#endif + +#define TRACE_GROUP_MAC_SECURITY "mSec" + +int8_t mac_security_interface_link_frame_counter_reset(int8_t interface_id) +{ + return -1; +} + +int8_t mac_security_interface_link_security_level_set(int8_t interface_id , uint8_t sec_level) +{ + return -1; +} +uint8_t mac_security_interface_link_security_level_get_by_ptr(int8_t interface_id) +{ + return 0; +} + +int8_t mac_security_interface_link_frame_conter_read(int8_t interface_id, uint32_t *seq_ptr, uint8_t update_to_next) +{ + return -1; +} + +int8_t mac_securityinterface_trig_pending_key(int8_t interface_id) +{ + return -1; +} + +uint8_t *mac_security_interface_link_security_key_get_by_id(int8_t interface_id, uint8_t key_id) +{ + return NULL; +} + +int8_t mac_security_interface_key_update_trig(int8_t interface_id) +{ + return -1; +} + +int8_t mac_security_interface_mac_key_update(int8_t interface_id, uint8_t *key, uint8_t id, bool primary, uint8_t auth_cnt) +{ + return -1; +} + +uint8_t mac_security_interface_security_aux_header_len(int8_t interface_id) +{ + return 0; +} + +uint8_t mac_security_interface_current_security_key_id_get(int8_t interface_id) +{ + return 0; +} + +int8_t mac_security_interface_security_key_reset(int8_t interface_id) +{ + return -1; +} + +uint8_t mac_security_interface_aux_security_header_size(uint8_t keyIdMode) +{ + return 0; +} + +void mac_security_interface_aux_ccm_nonce_set(uint8_t *noncePtr, uint8_t *mac64, uint32_t securityFrameCounter, uint8_t securityLevel) +{ +} + +uint8_t *mac_security_interface_aux_security_header_write(uint8_t *ptr, const mac_aux_security_header_t *auxHeader) +{ + return NULL; +} + +/* Compare two security levels, as per 802.15.4-2011 7.4.1.1 */ +/* Returns true if sec1 is at least as secure as sec2 */ +bool mac_security_interface_security_level_compare(uint8_t sec1, uint8_t sec2) +{ + return false; +} + +buffer_t *mac_security_interface_aux_header_parse(buffer_t *b, mac_aux_security_header_t *auxSecHeader) +{ + return NULL; +} + +uint8_t mac_security_interface_link_security_level_get(int8_t interface_id) +{ + return 0; +} diff --git a/test/coap-service/unittest/stub/mbedtls_stub.c b/test/coap-service/unittest/stub/mbedtls_stub.c new file mode 100644 index 0000000000..ab5afa27ba --- /dev/null +++ b/test/coap-service/unittest/stub/mbedtls_stub.c @@ -0,0 +1,310 @@ +/* + * Copyright (c) 2015 ARM Limited. All rights reserved. + * SPDX-License-Identifier: Apache-2.0 + * Licensed under the Apache License, Version 2.0 (the License); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "mbedtls_stub.h" + +mbedtls_stub_def mbedtls_stub; + +//From ssl.h +int mbedtls_ssl_handshake_step( mbedtls_ssl_context *ssl ) +{ + if( mbedtls_stub.useCounter ){ + if( mbedtls_stub.retArray[mbedtls_stub.counter] == HANDSHAKE_FINISHED_VALUE){ + ssl->state = MBEDTLS_SSL_HANDSHAKE_OVER; + } + return mbedtls_stub.retArray[mbedtls_stub.counter++]; + } + return mbedtls_stub.expected_int; +} + +int mbedtls_ssl_close_notify( mbedtls_ssl_context *a ) +{ + if( mbedtls_stub.useCounter ){ + return mbedtls_stub.retArray[mbedtls_stub.counter++]; + } + return mbedtls_stub.expected_int; +} + +void mbedtls_ssl_init( mbedtls_ssl_context *a ){ + +} + +void mbedtls_ssl_config_init( mbedtls_ssl_config *a ){ + +} + +void mbedtls_ssl_conf_handshake_timeout( mbedtls_ssl_config *a, uint32_t b, uint32_t c) +{ + +} + +void mbedtls_ssl_free( mbedtls_ssl_context *a ){ + +} + +int mbedtls_ssl_conf_own_cert( mbedtls_ssl_config *a, + mbedtls_x509_crt *b, + mbedtls_pk_context *c ){ + if( mbedtls_stub.useCounter ){ + return mbedtls_stub.retArray[mbedtls_stub.counter++]; + } + return mbedtls_stub.expected_int; +} + +void mbedtls_ssl_conf_authmode( mbedtls_ssl_config *a, int c ){ + +} + +void mbedtls_ssl_conf_ca_chain( mbedtls_ssl_config *a, + mbedtls_x509_crt *b, + mbedtls_x509_crl *c ){ + +} + +int mbedtls_ssl_conf_psk( mbedtls_ssl_config *a, + const unsigned char *b, size_t c, + const unsigned char *d, size_t e ){ + if( mbedtls_stub.useCounter ){ + return mbedtls_stub.retArray[mbedtls_stub.counter++]; + } + return mbedtls_stub.expected_int; +} + +int mbedtls_ssl_config_defaults( mbedtls_ssl_config *a, + int b, int c, int d){ + if( mbedtls_stub.useCounter ){ + return mbedtls_stub.retArray[mbedtls_stub.counter++]; + } + return mbedtls_stub.expected_int; +} + +void mbedtls_ssl_conf_rng( mbedtls_ssl_config *a, + int (*f_rng)(void *, unsigned char *, size_t), + void *b ){ + +} + +void mbedtls_ssl_conf_ciphersuites( mbedtls_ssl_config *a, + const int *b) +{ + +} + +int mbedtls_ssl_setup( mbedtls_ssl_context *a, + const mbedtls_ssl_config *b ){ + if( mbedtls_stub.useCounter ){ + return mbedtls_stub.retArray[mbedtls_stub.counter++]; + } + return mbedtls_stub.expected_int; +} + +void mbedtls_ssl_set_bio( mbedtls_ssl_context *ssl, + void *p_bio, + int (*f_send)(void *, const unsigned char *, size_t), + int (*f_recv)(void *, unsigned char *, size_t), + int (*f_recv_timeout)(void *, unsigned char *, size_t, uint32_t) ){ + if( p_bio != NULL ){ + if( f_send ) + f_send( p_bio, NULL, 0 ); + if( f_recv ) + f_recv( p_bio, NULL, 0 ); + if( f_recv_timeout ) + f_recv_timeout( p_bio, NULL, 0, 0 ); + } +} + +void mbedtls_ssl_set_timer_cb( mbedtls_ssl_context *a, + void *ctx, + void (*f_set_timer)(void *, uint32_t int_ms, uint32_t fin_ms), + int (*f_get_timer)(void *) ){ + f_set_timer(ctx, 1, 2); + f_get_timer(ctx); + if(mbedtls_stub.invalidate_timer){ + f_set_timer(ctx, 0, 0); + } + f_get_timer(ctx); +} + +int mbedtls_ssl_handshake( mbedtls_ssl_context *ssl ){ + if( mbedtls_stub.useCounter ){ + return mbedtls_stub.retArray[mbedtls_stub.counter++]; + } + return mbedtls_stub.expected_int; +} + +uint32_t mbedtls_ssl_get_verify_result( const mbedtls_ssl_context *a ){ + return mbedtls_stub.uint32_value; +} + +int mbedtls_ssl_read( mbedtls_ssl_context *a, unsigned char *b, size_t c){ + if( mbedtls_stub.useCounter ){ + return mbedtls_stub.retArray[mbedtls_stub.counter++]; + } + return mbedtls_stub.expected_int; +} + +int mbedtls_ssl_write( mbedtls_ssl_context *a, const unsigned char *b, size_t c ){ + if( mbedtls_stub.useCounter ){ + return mbedtls_stub.retArray[mbedtls_stub.counter++]; + } + return mbedtls_stub.expected_int; +} + + + +//From crt_drbg.h +int mbedtls_ctr_drbg_seed( mbedtls_ctr_drbg_context *a, + int (*f_entropy)(void *, unsigned char *, size_t), + void *b, + const unsigned char *c, + size_t d ){ + return mbedtls_stub.crt_expected_int; +} + +void mbedtls_ctr_drbg_init( mbedtls_ctr_drbg_context *a ){ + +} + +void mbedtls_ctr_drbg_free( mbedtls_ctr_drbg_context *a ){ + +} + +int mbedtls_ctr_drbg_random_with_add( void *a, + unsigned char *b, size_t c, + const unsigned char *d, size_t e ){ + return mbedtls_stub.crt_expected_int; +} + +int mbedtls_ctr_drbg_random( void *p_rng, + unsigned char *output, size_t output_len ){ + return mbedtls_stub.crt_expected_int; +} + +//From x509_crt.h +void mbedtls_x509_crt_init( mbedtls_x509_crt *a ){ + +} + +void mbedtls_x509_crt_free( mbedtls_x509_crt *a ){ + +} + +int mbedtls_x509_crt_parse( mbedtls_x509_crt *a, const unsigned char *b, size_t c ){ + if( mbedtls_stub.useCounter ){ + return mbedtls_stub.retArray[mbedtls_stub.counter++]; + } + return mbedtls_stub.expected_int; +} + +//From entropy.h +void mbedtls_entropy_init( mbedtls_entropy_context *a ){ + +} + +void mbedtls_entropy_free( mbedtls_entropy_context *ctx ){ + +} + +int mbedtls_entropy_func( void *a, unsigned char *b, size_t c ){ + if( mbedtls_stub.useCounter ){ + return mbedtls_stub.retArray[mbedtls_stub.counter++]; + } + return mbedtls_stub.expected_int; +} + +int mbedtls_entropy_add_source( mbedtls_entropy_context *a, + mbedtls_entropy_f_source_ptr f_source, void *b, + size_t c, int d ){ + unsigned char buf[2]; + size_t len; + f_source(NULL, buf, 1, &len); + + if( mbedtls_stub.useCounter ){ + return mbedtls_stub.retArray[mbedtls_stub.counter++]; + } + return mbedtls_stub.expected_int; +} + +//From pk.h +int mbedtls_pk_parse_key( mbedtls_pk_context *a, + const unsigned char *b, size_t c, + const unsigned char *d, size_t e ){ + if( mbedtls_stub.useCounter ){ + return mbedtls_stub.retArray[mbedtls_stub.counter++]; + } + return mbedtls_stub.expected_int; +} + +void mbedtls_pk_init( mbedtls_pk_context *ctx ) +{ + +} + +void mbedtls_pk_free( mbedtls_pk_context *ctx ) +{ + +} + +void mbedtls_ssl_config_free( mbedtls_ssl_config *a) +{ + +} + +int mbedtls_ssl_set_hs_ecjpake_password( mbedtls_ssl_context *ssl, + const unsigned char *pw, + size_t pw_len ) +{ + if( mbedtls_stub.useCounter ){ + return mbedtls_stub.retArray[mbedtls_stub.counter++]; + } + return mbedtls_stub.expected_int; +} + +void mbedtls_ssl_conf_dtls_cookies( mbedtls_ssl_config *conf, + mbedtls_ssl_cookie_write_t *f_cookie_write, + mbedtls_ssl_cookie_check_t *f_cookie_check, + void *p_cookie ) +{ + if( mbedtls_stub.cookie_obj && f_cookie_check && mbedtls_stub.cookie_len > 0 ){ + f_cookie_check(mbedtls_stub.cookie_obj, &mbedtls_stub.cookie_value, mbedtls_stub.cookie_len, NULL, 0); + } + if( mbedtls_stub.cookie_obj && f_cookie_write && mbedtls_stub.cookie_len > 0 ){ + unsigned char out[16]; + unsigned char *ptr = &out; + f_cookie_write(mbedtls_stub.cookie_obj, &ptr, ptr+mbedtls_stub.cookie_len, NULL, 0); + } +} + +void mbedtls_ssl_conf_export_keys_cb( mbedtls_ssl_config *conf, + mbedtls_ssl_export_keys_t *f_export_keys, + void *p_export_keys ) +{ + if( f_export_keys && p_export_keys){ + unsigned char value[40]; + memset(&value, 1, 40); + f_export_keys(p_export_keys, &value, "", 0, 0,0); //failure case + + f_export_keys(p_export_keys, &value, "", 0, 20,0); //success case + } +} + +int mbedtls_ssl_session_reset( mbedtls_ssl_context *ssl ) +{ + if( mbedtls_stub.useCounter ){ + return mbedtls_stub.retArray[mbedtls_stub.counter++]; + } + return mbedtls_stub.expected_int; +} diff --git a/test/coap-service/unittest/stub/mbedtls_stub.h b/test/coap-service/unittest/stub/mbedtls_stub.h new file mode 100644 index 0000000000..a0afdd3dda --- /dev/null +++ b/test/coap-service/unittest/stub/mbedtls_stub.h @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2015 ARM Limited. All rights reserved. + * SPDX-License-Identifier: Apache-2.0 + * Licensed under the Apache License, Version 2.0 (the License); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef MBEDTLS_STUB_H +#define MBEDTLS_STUB_H + +#define MBEDTLS_SSL_EXPORT_KEYS + +#include +#include +#include "mbedtls/ssl.h" +#include "mbedtls/ctr_drbg.h" +#include "mbedtls/x509_crt.h" +#include "mbedtls/sha256.h" +#include "mbedtls/entropy.h" +#include "mbedtls/pk.h" + + + +#define HANDSHAKE_FINISHED_VALUE 8888 + +typedef struct { + int crt_expected_int; + bool useCounter; + int counter; + int retArray[20]; + int expected_int; + uint32_t uint32_value; + bool invalidate_timer; + void *cookie_obj; + unsigned char cookie_value[8]; + size_t cookie_len; +} mbedtls_stub_def; + +extern mbedtls_stub_def mbedtls_stub; + +#endif // MBEDTLS_STUB_H diff --git a/test/coap-service/unittest/stub/mle_service_stub.c b/test/coap-service/unittest/stub/mle_service_stub.c new file mode 100644 index 0000000000..0e516a4082 --- /dev/null +++ b/test/coap-service/unittest/stub/mle_service_stub.c @@ -0,0 +1,220 @@ +/* + * Copyright (c) 2015 ARM Limited. All rights reserved. + */ + +#include "config.h" +#include +#include +#include "ns_trace.h" +#include "eventOS_event.h" +#include "eventOS_scheduler.h" +#include "eventOS_event_timer.h" +#include "nsdynmemLIB.h" +#include "ns_list.h" +#include "randLIB.h" +#include "socket_api.h" +#include "Core/include/socket.h" +#include "net_interface.h" +#include "common_functions.h" +#include "NWK_INTERFACE/Include/protocol.h" // just for protocol_core_monotonic_time +#include "MAC/IEEE802_15_4/mac_security_interface.h" +#include "Service_Libs/mle_service/mle_service_api.h" +#include "Service_Libs/mle_service/mle_service_security.h" +#include "Service_Libs/mle_service/mle_service_buffer.h" +#include "Service_Libs/mle_service/mle_service_interface.h" +#include "MLE/mle.h" +#include "MLE/mle_tlv.h" + +#define TRACE_GROUP "mleS" + +/* Fixed-point randomisation limits for randlib_randomise_base() - RFC 3315 + * says RAND is uniformly distributed between -0.1 and +0.1 + */ +#define MLE_RAND_LOW 0x7333 // 1 - 0.1; minimum for "1+RAND" +#define MLE_RAND_HIGH 0x8CCD // 1 + 0.1; maximum for "1+RAND" + +typedef struct { + int8_t mle_socket; + int8_t mle_socket_service_tasklet; + uint8_t mle_adata[46]; + uint8_t mle_adata_length; +} mle_service_class_t; + + + +/** + * MLE service transaction timeout and retry handling + */ +bool mle_service_timer_tick(uint16_t ticks) +{ + return false; + +} + +int mle_service_interface_register(int8_t interface_id, mle_service_receive_cb *receive_cb, uint8_t *mac64, uint8_t challengeLength) +{ + return 0; +} + +bool mle_service_interface_registeration_validate(int8_t interface_id) +{ + return false; +} + + +int mle_service_interface_receiver_handler_update(int8_t interface_id, mle_service_receive_cb *receive_cb) +{ + return 0; +} + +void mle_service_interface_unregister(int8_t interface_id) +{ +} + +void mle_service_interface_tx_queue_clean(int8_t interface_id) +{ +} + +uint16_t mle_service_msg_allocate(int8_t interface_id, uint16_t data_length, bool challengeAllocate, uint8_t type) +{ + return 0; +} + +uint8_t * mle_service_get_data_pointer(uint16_t msgId) +{ + return NULL; +} + +uint8_t * mle_service_get_payload_start_point(uint16_t msgId) +{ + return NULL; +} + +uint16_t mle_service_get_payload_length(uint16_t msgId) +{ + return 0; +} + +int mle_service_update_length(uint16_t msgId, uint16_t tail_length) +{ + return 0; +} + +int mle_service_update_length_by_ptr(uint16_t msgId, uint8_t *data_end_ptr) +{ + return 0; +} + +int mle_service_msg_update_security_params(uint16_t msgId, uint8_t security_level, uint8_t key_id_mode, uint32_t keysequence) +{ + return 0; +} + +int mle_service_set_packet_callback(uint16_t msgId, mle_service_message_timeout_cb *cb) +{ + return 0; +} + +int mle_service_set_msg_response_true(uint16_t msgId) +{ + return 0; +} + +uint8_t * mle_service_get_msg_destination_address_pointer(uint16_t msgId) +{ + return 0; +} + +int mle_service_set_msg_destination_address(uint16_t msgId, const uint8_t *dstAddress) +{ + return 0; +} + +int mle_service_msg_free(uint16_t msgId) +{ + return 0; +} + +bool mle_service_transaction_buffer_get_for_response(uint8_t *responseData, uint8_t length, uint16_t *msgId) +{ + return false; +} + +int mle_service_message_tail_get(uint16_t msgId, uint16_t tail_length) +{ + return 0; +} + +int mle_service_set_msg_timeout_parameters(uint16_t msgId, mle_message_timeout_params_t *timeout_params) +{ + return 0; +} + +int mle_service_send_message(uint16_t msgId) +{ + return 0; +} + +int mle_service_security_init(int8_t interfaceId, uint8_t security_level, uint32_t security_frame_counter, mle_service_key_request_by_counter_cb * key_counter_req, mle_service_security_notify_cb *notify) +{ + return 0; +} + +bool mle_service_security_set_frame_counter(int8_t interfaceId, uint32_t frame_counter) +{ + return false; +} + +uint8_t * mle_service_security_default_key_get(int8_t interfaceId) +{ + return 0; +} + +uint8_t mle_service_security_default_key_id_get(int8_t interfaceId) +{ + return 0; +} + +uint8_t * mle_service_security_next_key_get(int8_t interfaceId) +{ + return 0; +} + +uint8_t mle_service_security_next_key_id_get(int8_t interfaceId) +{ + return 0; +} + +uint8_t mle_service_security_level_get(int8_t interfaceId) +{ + return 0; +} + +bool mle_service_security_key_trig(int8_t interfaceId, uint8_t keyId) +{ + return false; + +} + +bool mle_service_security_set_security_key(int8_t interfaceId, uint8_t * security_key, uint8_t keyId, bool primary) +{ + return false; +} + + +int mle_service_reject_message_build(int8_t interfaceId, uint8_t *dstIpv6) +{ + + uint16_t buf_id = mle_service_msg_allocate(interfaceId, 32, false, MLE_COMMAND_REJECT); + if (buf_id == 0) { + return -1; + } + tr_debug("MLE Reject MSG Build"); + //SET Destination address + mle_service_set_msg_destination_address(buf_id, dstIpv6); + mle_service_send_message(buf_id); + + return 0; + + +} diff --git a/test/coap-service/unittest/stub/mle_stub.c b/test/coap-service/unittest/stub/mle_stub.c new file mode 100644 index 0000000000..3abf044d58 --- /dev/null +++ b/test/coap-service/unittest/stub/mle_stub.c @@ -0,0 +1,342 @@ +/* + * Copyright (c) 2013-2015 ARM Limited. All rights reserved. + */ + +#include "config.h" +#include "MLE/mle.h" + +#ifndef NO_MLE + +#include "ns_types.h" +#include "eventOS_event.h" +#include "eventOS_event_timer.h" +#include "socket_api.h" +#include "Core/include/socket.h" +#include "nsdynmemLIB.h" +#include "ns_trace.h" +#include "string.h" +#include "NWK_INTERFACE/Include/protocol.h" +#include "Common_Protocols/udp.h" +#include "MAC/IEEE802_15_4/mac_security_interface.h" +#include "MAC/IEEE802_15_4/mac_data_poll.h" +#include "MAC/IEEE802_15_4/mac_mlme.h" +#include "shalib.h" +#include "randLIB.h" +#ifdef NVM_BORDER_ROUTER +#include "br_list_nvm_api.h" +#endif +#include "6LoWPAN/Thread/thread_network_data_storage.h" +#include "6LoWPAN/Thread/thread_routing.h" +#include "thread_management_if.h" +#include "6LoWPAN/Thread/thread_management_internal.h" +#include "6LoWPAN/Thread/thread.h" +#include "6LoWPAN/Thread/thread_nd.h" +#include "6LoWPAN/Thread/thread_bootstrap.h" +#include "6LoWPAN/Thread/thread_joiner_application.h" +#include +#include "6LoWPAN/Bootstraps/protocol_6lowpan.h" +#include "6LoWPAN/Bootstraps/protocol_6lowpan_bootstrap.h" +#include "platform/arm_hal_interrupt.h" +#include "platform/topo_trace.h" +#include "common_functions.h" +#include "MLE/mle_tlv.h" +#include "NWK_INTERFACE/Include/protocol_timer.h" +#include "Common_Protocols/ipv6.h" + +#include "mle_stub.h" + +#define MLE_UNICAST_CHALLENGE_TIMEOUT 20 + +#define TRACE_GROUP "mle" + +mle_stub_def mle_stub; + +typedef enum { + ARM_MLE_INIT = 0, + ARM_MLE_TTL_TIMER +} arm_mle_event_id_e; + + +/** + * Generic Type/Length beader, no value + */ +typedef struct { + uint8_t type; + uint8_t length; +} mle_tlv_tl; + +/** + * Source address structure + */ +typedef struct { + uint8_t type; + uint8_t length; + uint8_t src_address[2]; +} mle_tlv_src_address_s; + +/** + * Mode structure + */ +typedef struct { + uint8_t type; + uint8_t length; + uint8_t mode; +} mle_tlv_mode_s; + +/** + * Timeout structure + */ +typedef struct { + uint8_t type; + uint8_t length; + uint8_t timeout; +} mle_tlv_timeout_s; + +/** + * Link layer frame counter structure + */ +typedef struct { + uint8_t type; + uint8_t length; + uint8_t ll_frm_counter[4]; +} mle_tlv_ll_frame_counter_s; + +/** + * MLE frame counter structure + */ +typedef struct { + uint8_t type; + uint8_t length; + uint8_t mle_frm_counter[4]; +} mle_tlv_mle_frame_counter_s; + +typedef union { + uint8_t *u8ptr; + mle_tlv_tl *tl; + mle_tlv_src_address_s *src_address; + mle_tlv_mode_s *mode; + mle_tlv_timeout_s *timeout; + mle_tlv_ll_frame_counter_s *ll_frm_counter; + mle_tlv_mle_frame_counter_s *mle_frm_counter; +} tlv_value_ptr_u; + +void mle_table_ttl(uint16_t ticks, protocol_interface_info_entry_t *cur_interface); + +NS_LARGE uint8_t mle_update_timer = 0; + +typedef struct { + uint8_t queu_update_event; + uint8_t active_params; + uint16_t pan_id; /*!< PAN-ID */ + uint32_t pan_time; + uint8_t channel; /*!< Channel */ + uint32_t chan_time; + uint8_t allow_join; /*!< Permit Join */ + uint32_t allow_time; + uint8_t *beacon_payload; + uint8_t beacon_payload_len; + uint32_t beacon_payload_delay; +} mle_nwk_param_t; + +/* removes child id when becoming router*/ +int thread_clear_child_id_by_address(protocol_interface_info_entry_t *cur, mle_neigh_table_entry_t *entry_temp); + +void mle_entry_rm(mle_neigh_table_entry_t *entry); + +#ifdef NVM_BORDER_ROUTER +uint16_t (*mle_nvm_storage_cb)(br_nvm_update_process_t) = 0; + +int8_t mle_nvm_callback_set(uint16_t (*passed_fptr)(br_nvm_update_process_t), uint8_t *nvm_static_buffer) +{ +} + + +int8_t mle_entry_store_from_nvm(const uint8_t *nvm_data) +{ + return -1; +} + + +void mle_nvm_update(mle_neigh_table_entry_t *entry, br_nvm_update_process_t event) +{ +} + +#endif + +void mle_set_max_allow_join_time(uint16_t new_max_allow_join_time) +{ +} + +int8_t arm_mle_prepare_update(int8_t nwk_id, uint8_t type, uint32_t time, uint16_t value) +{ + return 0; +} + +int8_t arm_mle_update_beacon_payload(int8_t nwk_id, uint8_t *optional_fields_data, uint8_t optional_fields_len, uint32_t delay) +{ + return 0; +} + +uint8_t mle_update_process(uint8_t event) +{ + return 0; +} + +void mle_init(void) +{ +} + +void mle_event_handler(arm_event_s *event) +{ +} + +void protocol_core_mle_init(void) +{ +} + +void mle_entry_frame_counter_update(mle_neigh_table_entry_t *entry_temp, uint32_t counter, uint8_t keyId) +{ + +} +uint8_t mle_mode_get_by_interface_ptr(protocol_interface_info_entry_t *cur) +{ + return 0; +} + +uint8_t mle_challenge(uint8_t *addr, protocol_interface_info_entry_t *cur) +{ + return 1; +} + +int mle_child_update_generation(uint8_t *parentAddress, struct protocol_interface_info_entry *cur, uint8_t mode) +{ + return 0; +} + +int8_t mle_host_link_configuration(bool rx_on_idle, protocol_interface_info_entry_t *cur) +{ + return -1; +} + +uint8_t mle_router_synch(protocol_interface_info_entry_t *cur, const uint8_t *destAddress) +{ + return 1; +} + +uint8_t mle_neigh_advertise(protocol_interface_info_entry_t *cur) +{ + return 1; +} + +uint8_t mle_reed_advertise (protocol_interface_info_entry_t *cur) +{ + return 0; +} + +int mle_attach_parent_request_build(protocol_interface_info_entry_t *cur, uint8_t scanMask) +{ + return -1; +} + + +uint8_t *mle_linkquality_write(uint8_t *buffer) +{ + return NULL; +} + +int mle_attach_parent_response_build(protocol_interface_info_entry_t *cur, sockaddr_t *dstAddress, uint8_t *challenge, uint8_t chalLen, uint8_t linkMargin) +{ + return -1; +} +void mle_network_data_push_to_sleep_child(protocol_interface_info_entry_t *cur, bool stableDataUpdate) +{ +} + +void mle_multicast_push_to_sleep_child(protocol_interface_info_entry_t *cur, buffer_t *buf) +{ + +} + +int mle_network_data_propagation(protocol_interface_info_entry_t *cur, uint8_t *childUnicastAddress, bool fullList) +{ +} + +void mle_entry_timeout_update(mle_neigh_table_entry_t *entry_temp, uint32_t timeout_tlv) +{ +} + +void mle_neigh_entry_update_by_mle_tlv_list(mle_neigh_table_entry_t *entry_temp, uint8_t *tlv_ptr, uint16_t tlv_length, uint8_t lqi, uint8_t keyId) +{ +} + +uint8_t mle_indirect_check(const uint8_t *ptr, addrtype_t type) +{ + return 0; +} + +static mle_neigh_table_entry_t *mle_entry_scan_long(const uint8_t *address) +{ + return NULL; +} + +static mle_neigh_table_entry_t *mle_entry_scan_short(uint16_t address) +{ + return NULL; +} + +void mle_key_synch_request(mle_neigh_table_entry_t *info) +{ +} + +mle_neigh_table_entry_t *mle_table_rpl_advert(void) +{ + return NULL; +} + +void mle_entry_rm(mle_neigh_table_entry_t *entry) +{ +} + +void mle_table_ttl(uint16_t ticks, protocol_interface_info_entry_t *cur_interface) +{ +} + +mle_neigh_table_entry_t *mle_refresh_entry_timeout(int8_t interfaceId, const uint8_t *addressPtr, addrtype_t addressType, bool dataPollConfirmation) +{ + return NULL; +} + +mle_neigh_table_entry_t *mle_entry_get_by_link_address(const uint8_t *address, addrtype_t type) +{ + mle_stub.expectedUint8ptr = address; + mle_stub.expectedUint8 = type; + + return mle_stub.mle_neigh_table_entry_ptr; +} + +mle_neigh_table_list_t *mle_list_get(void) +{ + return NULL; +} + +uint8_t mle_thread_end_device_synch_to_router(protocol_interface_info_entry_t *cur, uint8_t *router_ll64) +{ + return 0; +} + +uint8_t mle_thread_end_device_synch(protocol_interface_info_entry_t *cur) +{ + return 0; +} + +uint8_t *mle_general_write_source_address(uint8_t *ptr, protocol_interface_info_entry_t *cur) +{ + return 0; +} + +void mle_tables_frame_counter_state_reset_for_nw_key(uint8_t keyId) +{ + +} + +#endif /* NO_MLE */ diff --git a/test/coap-service/unittest/stub/mle_stub.h b/test/coap-service/unittest/stub/mle_stub.h new file mode 100644 index 0000000000..d096aa9842 --- /dev/null +++ b/test/coap-service/unittest/stub/mle_stub.h @@ -0,0 +1,21 @@ +#ifndef __MLE_STUB_H__ +#define __MLE_STUB_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct { + uint8_t expectedUint8; + uint16_t expectedUint16; + uint8_t *expectedUint8ptr; + mle_neigh_table_entry_t *mle_neigh_table_entry_ptr; +} mle_stub_def; + +extern mle_stub_def mle_stub; + +#ifdef __cplusplus +} +#endif + +#endif // __MLE_STUB_H__ diff --git a/test/coap-service/unittest/stub/mle_tlv_stub.c b/test/coap-service/unittest/stub/mle_tlv_stub.c new file mode 100644 index 0000000000..23bb990ad9 --- /dev/null +++ b/test/coap-service/unittest/stub/mle_tlv_stub.c @@ -0,0 +1,130 @@ +/* + * Copyright (c) 2014-2015 ARM Limited. All rights reserved. + */ +#include "config.h" +#include "platform/ns_debug.h" +#include "string.h" +#include "MLE/mle.h" +#include "MLE/mle_tlv.h" +#include "common_functions.h" + +int mle_message_malformed_check(uint8_t *ptr, uint16_t data_len) +{ + return 0; +} + +int mle_tlv_option_discover(uint8_t *ptr, uint16_t data_len, mle_tlv_type_t discovered_type, mle_tlv_info_t *option_info) +{ + return -1; +} + +int mle_validate_advertisment_message(uint8_t *ptr, uint16_t data_len) +{ + return 0; +} + +int mle_validate_router_link_accept_request_message(uint8_t *ptr, uint16_t data_len) +{ + return 0; +} + +int mle_validate_router_link_accept_message(uint8_t *ptr, uint16_t data_len) +{ + return 0; +} + +bool mle_tlv_type_requested(uint8_t reqType, uint8_t *ptr, uint16_t data_len) +{ + return false; +} + +bool mle_tlv_read_8_bit_tlv(mle_tlv_type_t reqType, uint8_t *ptr, uint16_t data_len, uint8_t *buffer) +{ + return false; +} + +bool mle_tlv_read_16_bit_tlv(mle_tlv_type_t reqType, uint8_t *ptr, uint16_t data_len, uint16_t *buffer) +{ + return false; +} + +bool mle_tlv_read_32_bit_tlv(mle_tlv_type_t reqType, uint8_t *ptr, uint16_t data_len, uint32_t *buffer) +{ + return false; +} + +bool mle_tlv_read_tlv(mle_tlv_type_t reqType, uint8_t *ptr, uint16_t data_len, mle_tlv_info_t *tlv_info) +{ + return false; +} + +int mle_validate_child_keep_alive_message(uint8_t *ptr, uint16_t data_len) +{ + return 0; +} + +int mle_validate_child_update_message(uint8_t *ptr, uint16_t data_len) +{ + return 0; +} + +uint8_t *mle_tlv_write_response(uint8_t *ptr, uint8_t *response_ptr, uint8_t responseLen) +{ + return NULL; +} + +uint8_t *mle_tlv_write_source_address(uint8_t *ptr, uint16_t shortAddress) +{ + return NULL; +} + +uint8_t *mle_tlv_write_short_address(uint8_t *ptr, uint16_t shortAddress) +{ + return NULL; +} + +uint8_t *mle_tlv_write_mode(uint8_t *ptr, uint8_t mode) +{ + return NULL; +} + +uint8_t *mle_tlv_write_timeout(uint8_t *ptr, uint32_t timeOut) +{ + return NULL; +} + +uint8_t *mle_tlv_write_holdtime(uint8_t *ptr, uint16_t holdTime) +{ + return NULL; +} + +uint8_t *mle_tlv_write_challenge(uint8_t *ptr, uint8_t *challengePtr, uint8_t challenLen) +{ + return NULL; +} + +uint8_t *mle_tlv_write_link_layer_framecount(uint8_t *ptr, uint32_t frameCount) +{ + return NULL; +} + +uint8_t *mle_tlv_write_scan_mask(uint8_t *ptr, uint8_t scanMask) +{ + return NULL; +} + +uint8_t *mle_tlv_req_tlv(uint8_t *ptr, uint8_t *mle_req_tlv_list, uint8_t req_list_len) +{ + return NULL; +} +uint8_t *mle_tlv_rssi_tlv(uint8_t *ptr, uint8_t linkMargin) +{ + return NULL; +} + +uint8_t *mle_tlv_write_version(uint8_t *ptr, uint16_t version) +{ + return NULL; +} + + diff --git a/test/coap-service/unittest/stub/multicast_stub.c b/test/coap-service/unittest/stub/multicast_stub.c new file mode 100644 index 0000000000..8080088303 --- /dev/null +++ b/test/coap-service/unittest/stub/multicast_stub.c @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2013-2015 ARM Limited. All rights reserved. + */ +#include "config.h" +#include "ns_types.h" +#include "eventOS_event.h" +#include "nsdynmemLIB.h" +#include "ns_trace.h" +#include "Core/include/socket.h" +#include "string.h" +#include "NWK_INTERFACE/Include/protocol.h" +#include "Common_Protocols/ipv6.h" +#include "MulticastTrigle/multicast.h" +#include "MAC/IEEE802_15_4/mac_mlme.h" +#include "6LoWPAN/Bootstraps/network_lib.h" +#include "common_functions.h" +#include "NWK_INTERFACE/Include/protocol_timer.h" + +void multicast_push(buffer_t *buf) +{ + +} + +void multicast_init(void) +{ + +} + +void multicast_handle_time_event(uint16_t ticksUpdate) +{ + +} + +int multicast_sleepy_unicast_address_register(uint8_t * multicast_address, multicast_forward_to_sleepy *handler) +{ + return 0; +} + +void multicast_set_parameters(uint8_t i_min, uint8_t i_max, uint8_t k, uint8_t timer_expirations, uint8_t window_expiration) +{ + +} + +uint8_t multicast_add_address(const uint8_t *address_ptr, uint8_t use_trickle) +{ + return 0; +} + +uint8_t multicast_free_address(uint8_t *address_ptr) +{ + return 0; +} diff --git a/test/coap-service/unittest/stub/nd_proxy.c b/test/coap-service/unittest/stub/nd_proxy.c new file mode 100644 index 0000000000..b4986c0224 --- /dev/null +++ b/test/coap-service/unittest/stub/nd_proxy.c @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2013-2015 ARM Limited. All rights reserved. + */ +#include "config.h" +#include "ns_types.h" + +int nd_proxy_downstream_interface_unregister(int8_t interface_id) +{ + return 0; +} + +bool nd_proxy_enabled_for_upstream(int8_t interface_id) +{ + return false; +} + +bool nd_proxy_upstream_route_onlink(int8_t downstream_id, uint8_t *address) +{ + return false; +} diff --git a/test/coap-service/unittest/stub/nd_proxy_stub.c b/test/coap-service/unittest/stub/nd_proxy_stub.c new file mode 100644 index 0000000000..e87d3e2fc9 --- /dev/null +++ b/test/coap-service/unittest/stub/nd_proxy_stub.c @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2015 ARM. All rights reserved. + */ + +#include "config.h" +#ifdef HAVE_ND_PROXY +#include "ns_types.h" +#include "common_functions.h" +#include "ns_trace.h" +#include "string.h" +#include "nsdynmemLIB.h" +#include "ns_list.h" +#include "Service_Libs/nd_proxy/nd_proxy.h" + + +int nd_proxy_downstream_interface_register(int8_t interface_id, nd_proxy_req_cb *nd_proxy_req, bridge_state_update_cb * bridge_state_update) +{ + return 0; +} + +int nd_proxy_downstream_interface_unregister(int8_t interface_id) +{ + return 0; +} + +int nd_proxy_upstream_interface_register(int8_t interface_id, nd_proxy_req_cb *route_validation_req) +{ + return 0; +} + +int nd_proxy_upstream_interface_unregister(int8_t interface_id) +{ + return 0; +} + +bool nd_proxy_enabled_for_downstream(int8_t interface_id) +{ + return false; +} + +bool nd_proxy_enabled_for_upstream(int8_t interface_id) +{ + return false; +} + +bool nd_proxy_target_address_validation(int8_t upstream_id, uint8_t *address, int8_t *downstream_id_ptr) +{ + return false; +} + +bool nd_proxy_upstream_route_onlink(int8_t downstream_id, uint8_t *address) +{ + return false; +} +#endif /* HAVE_ND_PROXY */ + diff --git a/test/coap-service/unittest/stub/nd_router_object_stub.c b/test/coap-service/unittest/stub/nd_router_object_stub.c new file mode 100644 index 0000000000..5ddeb9acdd --- /dev/null +++ b/test/coap-service/unittest/stub/nd_router_object_stub.c @@ -0,0 +1,242 @@ +/* + * Copyright (c) 2013-2015 ARM Limited. All rights reserved. + */ +#include "config.h" +#include "ns_types.h" +#include "string.h" +#include "nsdynmemLIB.h" +#include "ns_trace.h" +#include "NWK_INTERFACE/Include/protocol.h" +#include "MAC/IEEE802_15_4/mac_data_poll.h" +#include "MAC/IEEE802_15_4/mac_mlme.h" +#include "Common_Protocols/icmpv6.h" +#include "Common_Protocols/icmpv6_prefix.h" +#include "Common_Protocols/icmpv6_radv.h" +#include "randLIB.h" +#ifdef HAVE_RPL +#include "6LoWPAN/RPL/rpl.h" +#include "6LoWPAN/RPL/rpl_obj.h" +#else +/* This sort of thing should be handled in rpl.h itself */ +#define rpl_object_poisons() 0 +#endif +#include "6LoWPAN/IPHC_Decode/cipv6.h" +#include "6LoWPAN/ND/nd_router_object.h" +#include "6LoWPAN/Bootstraps/network_lib.h" +#include "6LoWPAN/Bootstraps/protocol_6lowpan.h" +#include "6LoWPAN/Bootstraps/protocol_6lowpan_bootstrap.h" +#ifdef WHITEBOARD +#ifdef NVM_BORDER_ROUTER +#include "br_list_nvm_api.h" +#endif +#include "Service_Libs/whiteboard/whiteboard.h" +#endif +#include "common_functions.h" + +#define TRACE_GROUP_LOWPAN_ND "loND" + +void icmp_nd_router_object_release(nd_router_t *router_object); +uint8_t icmp_nd_router_prefix_ttl_update(nd_router_t *nd_router_object, protocol_interface_info_entry_t *cur_interface); + +uint8_t nd_rs_build(nd_router_t *cur, protocol_interface_info_entry_t *cur_interface); +bool icmp_nd_compare_to_def_next_hop(nd_router_next_hop *hop, sockaddr_t *adr); +void icmp_nd_router_context_ttl_update(nd_router_t *nd_router_object); +extern void nd_border_router_setup_refresh(nwk_interface_id id, bool fresh_abro); + +uint8_t nd_base_tick = 1; + +int8_t nd_set_br(nd_router_t *br) +{ + return -1; +} + +bool nd_object_active(void) +{ + return false; +} + +void icmp_nd_routers_init(void) +{ +} + + +void icmp_nd_set_nd_def_router_address(uint8_t *ptr, nd_router_t *cur) +{ + +} + +void nd_ns_trig(nd_router_t *router_object, protocol_interface_info_entry_t *cur) +{ + +} + +void nd_router_base_init(nd_router_t *new_entry) +{ + +} + +nd_router_t *icmp_nd_router_object_get(const uint8_t *border_router, nwk_interface_id nwk_id) +{ + return NULL; +} + +void icmp_nd_router_object_reset(nd_router_t *router_object) +{ + +} + +int8_t icmp_nd_router_prefix_proxy_update(uint8_t *dptr, nd_router_setup_t *nd_router_object) +{ + return -1; +} + +uint8_t icmp_nd_router_prefix_valid(nd_router_t *nd_router_object) +{ + return 0; +} + +uint8_t icmp_nd_router_prefix_ttl_update(nd_router_t *nd_router_object, protocol_interface_info_entry_t *cur_interface) +{ + return 0; +} + +int8_t icmp_nd_router_prefix_update(uint8_t *dptr, nd_router_t *nd_router_object, protocol_interface_info_entry_t *cur_interface) +{ + return 0; +} + +void icmp_nd_router_context_ttl_update(nd_router_t *nd_router_object) +{ + +} + +int8_t icmp_nd_router_context_update(const uint8_t *dptr, nd_router_t *router_object) +{ + return -1; +} + +void icmp_nd_router_object_release(nd_router_t *router_object) +{ +} + + +void icmp_nd_border_router_release(nd_router_t *router_object) +{ +} + + + +void gp_address_list_free(gp_ipv6_address_list_t *list) +{ +} + +void icmp_nd_prefixs_parse(buffer_t *buf, nd_router_t *nd_router_object, protocol_interface_info_entry_t *cur_interface) +{ + +} + + +void icmp_nd_set_next_hop(nd_router_next_hop *hop, sockaddr_t *adr) +{ + +} + +bool icmp_nd_compare_to_def_next_hop(nd_router_next_hop *hop, sockaddr_t *adr) +{ + return false; +} + +uint8_t nd_rs_build(nd_router_t *cur, protocol_interface_info_entry_t *cur_interface) +{ + return 0; +} + +uint8_t nd_ns_build(nd_router_t *cur, protocol_interface_info_entry_t *cur_interface, uint8_t *address_ptr) +{ + return 0; +} + +buffer_t *nd_dar_parse(buffer_t *buf, protocol_interface_info_entry_t *cur_interface) +{ + return NULL; +} + +bool nd_ns_aro_handler(protocol_interface_info_entry_t *cur_interface, const uint8_t *aro_opt, const uint8_t *slla_opt, const uint8_t *src_addr, aro_t *aro_out) +{ + return false; +} + +buffer_t *nd_dac_handler(buffer_t *buf, protocol_interface_info_entry_t *cur) +{ + return NULL; +} + +static void nd_ns_forward_timer_reset(uint8_t *root_adr) +{ + +} + +bool nd_ra_process_abro(protocol_interface_info_entry_t *cur, buffer_t *buf, const uint8_t *dptr, uint8_t ra_flags, uint16_t router_lifetime) +{ + return false; +} + +void nd_ra_process_lowpan_context_option(protocol_interface_info_entry_t *cur, const uint8_t *opt) +{ +} + +void nd_ra_build_by_abro(const uint8_t *abro, const uint8_t *dest, protocol_interface_info_entry_t *cur_interface) +{ +} + +void nd_trigger_ras_from_rs(const uint8_t *unicast_adr, protocol_interface_info_entry_t *cur_interface) +{ +} + +void nd_na_aro_handler(protocol_interface_info_entry_t *cur_interface, const uint8_t *dptr, const uint8_t *dst_addr) +{ +} + +void gp_address_add_to_end(gp_ipv6_address_list_t *list, const uint8_t address[__static 16]) +{ +} + +void nd_object_timer(struct protocol_interface_info_entry *cur_interface, uint16_t ticks_update) +{ +} + +ipv6_ra_timing_t *nd_ra_timing(const uint8_t abro[16]) +{ + return NULL; +} + +uint32_t nd_object_time_to_next_nd_reg(void) +{ + return 0; +} + + +void nd_object_timer_balance(uint16_t sleep_time, protocol_interface_info_entry_t *cur_interface) +{ +} + +uint8_t nd_prefix_dst_check(uint8_t *ptr) +{ + return 0; +} + +int8_t nd_parent_loose_indcate(uint8_t *neighbor_address, protocol_interface_info_entry_t *cur_interface) +{ + return -1; +} + +nd_router_t *nd_get_object_by_nwk_id(nwk_interface_id nwk_id) +{ + return NULL; +} + +nd_router_t *nd_get_pana_address(void) +{ + return NULL; +} + diff --git a/test/coap-service/unittest/stub/neighbor_cache_stub.c b/test/coap-service/unittest/stub/neighbor_cache_stub.c new file mode 100644 index 0000000000..5b32a124f3 --- /dev/null +++ b/test/coap-service/unittest/stub/neighbor_cache_stub.c @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2014-2015 ARM Limited. All rights reserved. + */ +#include "config.h" +#include "ns_types.h" +#include "common_functions.h" +#include "platform/ns_debug.h" +#include "string.h" +#include "nsdynmemLIB.h" +#include "Service_Libs/Neighbor_cache/neighbor_table_definition.h" + +void neighbor_cache_init(neigh_cache_s *neigh_cache) +{ +} + +int neighbor_cache_flush(neigh_cache_s *neigh_cache) +{ + return 0; +} + + +neigh_cache_entry_s *neighbor_cache_entry_get(neigh_cache_s *neigh_cache, neighbor_address_type_e address_type, const void *address_ptr) +{ + return NULL; +} + +neigh_cache_entry_s *neighbor_cache_entry_create(neigh_cache_s *neigh_cache, const uint8_t address_ptr[8]) +{ + return NULL; +} + +int8_t neighbor_cache_entry_delete(neigh_cache_s *neigh_cache, neighbor_address_type_e address_type, const void *address_ptr) +{ + return 0; +} + +neigh_cache_entry_s *neighbor_cache_entry_delete_by_entry_pointer(neigh_cache_s *neigh_cache, neigh_cache_entry_s *entry) +{ + return NULL; +} + +int neighbor_cache_ttl_update(neigh_cache_s *neigh_cache, uint16_t ticks) +{ + return 0; +} + +neigh_cache_entry_s *neighbor_cache_entry_get_timed_out(neigh_cache_s *neigh_cache) +{ + return NULL; +} diff --git a/test/coap-service/unittest/stub/net_stub.c b/test/coap-service/unittest/stub/net_stub.c new file mode 100644 index 0000000000..7f6ba92a79 --- /dev/null +++ b/test/coap-service/unittest/stub/net_stub.c @@ -0,0 +1,279 @@ +/* + * Copyright (c) 2014-2015 ARM Limited. All rights reserved. + */ +/** + * \file net.c + * \brief Network API for library model + * + * The network API functions for library model + */ +#include "config.h" +#include "ns_types.h" +#include "eventOS_scheduler.h" +#include "string.h" +#include "ns_trace.h" +#include "socket_api.h" +#include "nsdynmemLIB.h" +#include "NWK_INTERFACE/Include/protocol.h" +#include "NWK_INTERFACE/Include/protocol_interface_driver.h" +#ifdef HAVE_RPL +#include "6LoWPAN/RPL/rpl.h" +#endif +#include "ccmLIB.h" +#include "MAC/IEEE802_15_4/mac_data_interface.h" +#include "MAC/IEEE802_15_4/mac_security_interface.h" +#include "MAC/IEEE802_15_4/mac_data_poll.h" +#include "MAC/IEEE802_15_4/mac_mlme.h" +#include "6LoWPAN/Bootstraps/network_lib.h" +#include "6LoWPAN/Bootstraps/protocol_6lowpan.h" +#include "6LoWPAN/Bootstraps/protocol_6lowpan_bootstrap.h" +#include "6LoWPAN/ND/nd_router_object.h" +#ifndef NO_MLE +#include "MLE/mle.h" +#endif + +#ifdef ECC +#include "libX509_V3.h" +#include "ecc.h" +#endif +#include "platform/arm_hal_interrupt.h" +#include "common_functions.h" +#include "MulticastTrigle/multicast.h" +#ifdef NVM_BORDER_ROUTER +#include "br_list_nvm_api.h" +#endif +#include "Service_Libs/whiteboard/whiteboard.h" +#include "net_pana_parameters_api.h" +#ifdef PANA +#include "Security/PANA/pana.h" +#include "Security/PANA/pana_internal_api.h" +#endif +#include "nwk_stats_api.h" +#include "NWK_INTERFACE/Include/protocol_stats.h" +#include "Security/Common/sec_lib_definitions.h" +#include "ipv6_stack/protocol_ipv6.h" +#include "ipv6_stack/ipv6_routing_table.h" +#include "net_thread_test.h" +#include "6LoWPAN/Thread/thread.h" +#include "6LoWPAN/Thread/thread_routing.h" +#include "BorderRouter/border_router.h" + +int8_t arm_network_processor_up(protocol_interface_info_entry_t *cur) +{ + return 0; +} + +int8_t arm_net_energy_scan(int8_t interface_id, channel_list_s *scan_list, void (*passed_fptr)(uint8_t *), uint8_t energy_tresshold) +{ + return 0; +} + +int8_t arm_net_nwk_scan(int8_t interface_id, channel_list_s *scan_list, void (*passed_fptr)(uint8_t *), uint8_t scan_level) +{ + return 0; +} + +nwk_pan_descriptor_t *arm_net_get_scanned_nwk_list(int8_t interface_id) +{ + return NULL; +} + +uint16_t arm_net_get_nwk_pan_id_filter(int8_t nwk_interface_id) +{ + return 0; +} + +int8_t arm_nwk_param_read(int8_t interface_id, link_layer_setups_s *network_params) +{ + return 0; +} + +int8_t arm_nwk_mac_address_read(int8_t interface_id, link_layer_address_s *mac_params) +{ + return 0; +} + +int8_t arm_nwk_nd_address_read(int8_t interface_id, network_layer_address_s *nd_params) +{ + return 0; +} + +int16_t arm_net_get_current_channel(int8_t nwk_interface_id) +{ + return 0; +} + +void arm_net_host_enter_sleep_state_set(int8_t nwk_interface_id, uint8_t state) +{ +} + + +void net_get_version_information(uint8_t *ptr) +{ +} + +int8_t arm_nwk_6lowpan_gp_address_mode(int8_t nwk_interface_id, net_6lowpan_gp_address_mode_e mode, uint16_t short_address_base, uint8_t define_new_short_address_at_DAD) +{ + return 0; +} + +int8_t arm_net_address_get(int8_t nwk_interface_id, net_address_t addr_id, uint8_t *address) +{ + return 0; +} + +int8_t arm_net_interface_address_list_size(int8_t nwk_interface_id, uint16_t *address_count) +{ + return 0; +} + +int8_t arm_net_address_list_get(int8_t nwk_interface_id, uint8_t address_buf_size, uint8_t *address_buffer, int *writed_address_count) +{ + return 0; +} + +int8_t arm_nwk_interface_init(net_interface_type_e type, uint8_t phy_driver_id, char *interface_name_ptr) +{ + return 0; +} + +int8_t arm_nwk_interface_network_driver_set(int8_t nwk_interface_id, int8_t tun_driver_id, channel_list_s *nwk_channel_list, network_driver_setup_s *link_setup) +{ + return 0; +} + +int8_t arm_nwk_interface_up(int8_t nwk_interface_id) +{ + return 0; +} + +int8_t arm_nwk_interface_down(int8_t nwk_interface_id) +{ + return 0; +} + +int8_t arm_pana_client_key_pull(int8_t nwk_interface_id) +{ + return 0; +} + +int8_t arm_nwk_link_layer_security_mode(int8_t nwk_interface_id, net_6lowpan_link_layer_sec_mode_e mode, uint8_t sec_level, net_link_layer_psk_security_info_s *psk_key_info) +{ + return 0; +} + +int8_t arm_network_certificate_chain_set(arm_certificate_chain_entry_s *chain_info) +{ + return 0; +} + +int8_t arm_network_key_get(int8_t interface_id, ns_keys_t *key) +{ + return 0; +} + +int8_t arm_pana_server_library_init(int8_t nwk_interface_id, net_tls_cipher_e cipher_mode, uint8_t *key_material, uint32_t time_period_before_activate_key) +{ + return 0; +} + +int8_t arm_pana_activate_new_key(int8_t nwk_interface_id) +{ + return 0; +} + +int8_t arm_pana_server_key_update(int8_t nwk_interface_id, uint8_t *network_key_material) +{ + return 0; +} + +int8_t net_pana_parameter_set(const pana_lib_parameters_s *parameter_ptr) +{ + return 0; +} + +int8_t net_pana_parameter_read(pana_lib_parameters_s *parameter_ptr) +{ + return 0; +} + + +int8_t arm_pana_client_library_init(int8_t nwk_interface_id, net_tls_cipher_e cipher_mode, uint32_t psk_key_id) +{ + return 0; +} + + +int8_t arm_nwk_interface_configure_ipv6_bootstrap_set(int8_t nwk_interface_id, net_ipv6_mode_e bootstrap_mode, uint8_t *ipv6_prefix_pointer) +{ + return 0; +} + +int8_t arm_nwk_interface_configure_6lowpan_bootstrap_set(int8_t nwk_interface_id, net_6lowpan_mode_e bootstrap_mode, net_6lowpan_mode_extension_e net_6lowpan_mode_extension) +{ + return 0; +} + + +int8_t arm_nwk_6lowpan_link_scan_parameter_set(int8_t nwk_interface_id, uint8_t scan_time) +{ + return 0; +} + +int8_t arm_nwk_6lowpan_link_panid_filter_for_nwk_scan(int8_t nwk_interface_id, uint16_t pan_id_filter) +{ + return 0; +} + +int8_t arm_nwk_6lowpan_link_nwk_id_filter_for_nwk_scan(int8_t nwk_interface_id, const uint8_t *nwk_id_filter) +{ + return 0; +} + +int8_t arm_nwk_6lowpan_link_protocol_id_filter_for_nwk_scan(int8_t nwk_interface_id, uint8_t protocol_ID) +{ + return 0; +} + +int8_t net_init_core(void) +{ + return 0; +} + +int8_t arm_nwk_host_mode_set(int8_t nwk_interface_id, net_host_mode_t mode, uint32_t poll_time) +{ + return 0; +} + +int8_t arm_nwk_host_mode_get(int8_t nwk_interface_id, net_host_mode_t *mode) +{ + return 0; +} + +int8_t net_nvm_data_clean(int8_t interface_id) +{ + return 0; +} + +int8_t net_nvm_data_load(uint8_t *data_buffer, int8_t interface_id) +{ + return 0; +} + +int8_t net_pana_client_session_nvm_data_load(uint8_t *data_buffer, uint8_t *session_address, int8_t interface_id) +{ + return 0; +} + +int8_t net_read_persistent_data(uint8_t *data_buffer, int8_t interface_id) +{ + return 0; +} + +void arm_print_routing_table(void) +{ +} + +void arm_ncache_flush(void) +{ +} diff --git a/test/coap-service/unittest/stub/ns_list_stub.c b/test/coap-service/unittest/stub/ns_list_stub.c new file mode 100644 index 0000000000..2283f0f909 --- /dev/null +++ b/test/coap-service/unittest/stub/ns_list_stub.c @@ -0,0 +1,9 @@ +/* + * Copyright (c) 2015 ARM Limited. All rights reserved. + */ + +#define NS_LIST_FN extern + +#include "ns_list.h" + + diff --git a/test/coap-service/unittest/stub/ns_timer_stub.c b/test/coap-service/unittest/stub/ns_timer_stub.c new file mode 100644 index 0000000000..40ba9fd692 --- /dev/null +++ b/test/coap-service/unittest/stub/ns_timer_stub.c @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2014-2015 ARM Limited. All rights reserved. + * SPDX-License-Identifier: Apache-2.0 + * Licensed under the Apache License, Version 2.0 (the License); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "ns_types.h" +#include "ns_list.h" +#include "ns_timer.h" +#include "ns_timer_stub.h" +#include "eventOS_callback_timer.h" +#include "platform/arm_hal_interrupt.h" +#include "platform/arm_hal_timer.h" +#include "nsdynmemLIB.h" + +ns_timer_stub_def ns_timer_stub; + +int8_t ns_timer_init(void) +{ + return ns_timer_stub.int8_value; +} + +int8_t eventOS_callback_timer_register(void (*timer_interrupt_handler)(int8_t, uint16_t)) +{ + ns_timer_stub.cb = timer_interrupt_handler; + return ns_timer_stub.int8_value; +} + +int8_t eventOS_callback_timer_unregister(int8_t ns_timer_id) +{ + return ns_timer_stub.int8_value; +} + + +int8_t ns_timer_sleep(void) +{ + return ns_timer_stub.int8_value; +} + +int8_t eventOS_callback_timer_start(int8_t ns_timer_id, uint16_t slots) +{ + return ns_timer_stub.int8_value; +} + +int8_t eventOS_callback_timer_stop(int8_t ns_timer_id) +{ + return ns_timer_stub.int8_value; +} diff --git a/test/coap-service/unittest/stub/ns_timer_stub.h b/test/coap-service/unittest/stub/ns_timer_stub.h new file mode 100644 index 0000000000..5f970d793a --- /dev/null +++ b/test/coap-service/unittest/stub/ns_timer_stub.h @@ -0,0 +1,19 @@ +#ifndef __NS_TIMER_STUB_H__ +#define __NS_TIMER_STUB_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct { + int8_t int8_value; + void (*cb)(int8_t, uint16_t); +} ns_timer_stub_def; + +extern ns_timer_stub_def ns_timer_stub; + +#ifdef __cplusplus +} +#endif + +#endif // __NS_TIMER_STUB_H__ diff --git a/test/coap-service/unittest/stub/ns_trace.c b/test/coap-service/unittest/stub/ns_trace.c new file mode 100644 index 0000000000..7e0737f8e9 --- /dev/null +++ b/test/coap-service/unittest/stub/ns_trace.c @@ -0,0 +1,10 @@ +/* + * Copyright (c) 2013-2015 ARM Limited. All rights reserved. + */ +#include "config.h" +#include "ns_types.h" +void tracef(uint8_t dlevel, const char *grp, const char *fmt, ...) +{ + +} + diff --git a/test/coap-service/unittest/stub/ns_trace_stub.c b/test/coap-service/unittest/stub/ns_trace_stub.c new file mode 100644 index 0000000000..1c45fd401e --- /dev/null +++ b/test/coap-service/unittest/stub/ns_trace_stub.c @@ -0,0 +1,202 @@ +/* + * Copyright (c) 2014-2015 ARM Limited. All rights reserved. + */ +#include +#include +#include +#include + +#include "ns_trace.h" +#include "ip6string.h" +#include "common_functions.h" + +#if defined(_WIN32) || defined(__unix__) || defined(__unix) || defined(unix) +#ifndef MEM_ALLOC +#define MEM_ALLOC malloc +#endif +#ifndef MEM_FREE +#define MEM_FREE free +#endif +#else +#include "nsdynmemLIB.h" +#ifndef MEM_ALLOC +#define MEM_ALLOC ns_dyn_mem_alloc +#endif +#ifndef MEM_FREE +#define MEM_FREE ns_dyn_mem_free +#endif +#endif + +#define VT100_COLOR_ERROR "\x1b[31m" +#define VT100_COLOR_WARN "\x1b[33m" +#define VT100_COLOR_INFO "\x1b[39m" +#define VT100_COLOR_DEBUG "\x1b[90m" + +/** default max trace line size in bytes */ +#define DEFAULT_TRACE_LINE_LENGTH 1024 +/** default max temporary buffer size in bytes, used in + trace_ipv6, trace_array and trace_strn */ +#define DEFAULT_TRACE_TMP_LINE_LEN 128 +/** default max filters (include/exclude) length in bytes */ +#define DEFAULT_TRACE_FILTER_LENGTH 24 + +static void default_print(const char *str); + +typedef struct { + /** trace configuration bits */ + uint8_t trace_config; + /** exclude filters list, related group name */ + char *filters_exclude; + /** include filters list, related group name */ + char *filters_include; + /** Filters length */ + int filters_length; + /** trace line */ + char *line; + /** trace line length */ + int line_length; + /** temporary data */ + char *tmp_data; + /** temporary data array length */ + int tmp_data_length; + /** temporary data pointer */ + char *tmp_data_ptr; + + /** prefix function, which can be used to put time to the trace line */ + char *(*prefix_f)(size_t); + /** suffix function, which can be used to some string to the end of trace line */ + char *(*suffix_f)(void); + /** print out function. Can be redirect to flash for example. */ + void (*printf)(const char *); + /** print out function for TRACE_LEVEL_CMD */ + void (*cmd_printf)(const char *); +} trace_s; + +static trace_s m_trace = { + .filters_exclude = 0, + .filters_include = 0, + .line = 0, + .tmp_data = 0, + .prefix_f = 0, + .suffix_f = 0, + .printf = 0, + .cmd_printf = 0 +}; + +int trace_init(void) +{ + return 0; +} +void trace_free(void) +{ + +} + +void set_trace_config(uint8_t config) +{ + +} +uint8_t get_trace_config(void) +{ + return 0; +} +void set_trace_prefix_function(char *(*pref_f)(size_t)) +{ +} + +void set_trace_suffix_function(char *(*suffix_f)(void)) +{ +} + +void set_trace_print_function(void (*printf)(const char *)) +{ +} + +void set_trace_cmdprint_function(void (*printf)(const char *)) +{ +} + +void set_trace_exclude_filters(char *filters) +{ +} +const char *get_trace_exclude_filters(void) +{ + return NULL; +} + +const char *get_trace_include_filters(void) +{ + return NULL; +} + +void set_trace_include_filters(char *filters) +{ +} + +static int8_t trace_skip(int8_t dlevel, const char *grp) +{ + return 0; +} + +static void default_print(const char *str) +{ +} + +void tracef(uint8_t dlevel, const char *grp, const char *fmt, ...) +{ + +} +const char *trace_last(void) +{ + return ""; +} + +/* Helping functions */ +#define tmp_data_left() m_trace.tmp_data_length-(m_trace.tmp_data_ptr-m_trace.tmp_data) +char *trace_ipv6(const void *addr_ptr) +{ + return ""; +} + +char *trace_ipv6_prefix(const uint8_t *prefix, uint8_t prefix_len) +{ + return ""; +} + +char *trace_array(const uint8_t *buf, uint16_t len) +{ + return ""; +} + +// rest of debug print functions will be obsolete and will be overridden with new trace interface.. +void debugf(const char *fmt, ...) +{ +} + +void debug(const char *s) +{ +} + +void debug_put(char c) +{ +} + +void debug_hex(uint8_t x) +{ +} + +void debug_int(int i) +{ +} + +void printf_array(const void *buf , uint16_t len) +{ +} + +void printf_ipv6_address(const void *addr_ptr) +{ +} + +void printf_string(const void *ptr, uint16_t len) +{ +} diff --git a/test/coap-service/unittest/stub/nsdynmemLIB_stub.c b/test/coap-service/unittest/stub/nsdynmemLIB_stub.c new file mode 100644 index 0000000000..092c798bcb --- /dev/null +++ b/test/coap-service/unittest/stub/nsdynmemLIB_stub.c @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2014-2015 ARM Limited. All rights reserved. + */ +#include "nsdynmemLIB_stub.h" +#include +#include +#include +#include "platform/arm_hal_interrupt.h" +#ifdef STANDARD_MALLOC +#include +#endif + +nsdynmemlib_stub_data_t nsdynmemlib_stub; + +void ns_dyn_mem_init(uint8_t *heap, uint16_t h_size, void (*passed_fptr)(heap_fail_t), mem_stat_t *info_ptr) +{ +} + +void *ns_dyn_mem_alloc(int16_t alloc_size) +{ + if (nsdynmemlib_stub.returnCounter > 0) + { + nsdynmemlib_stub.returnCounter--; + return malloc(alloc_size); + } + else + { + return(nsdynmemlib_stub.expectedPointer); + } +} + +void *ns_dyn_mem_temporary_alloc(int16_t alloc_size) +{ + if (nsdynmemlib_stub.returnCounter > 0) + { + nsdynmemlib_stub.returnCounter--; + return malloc(alloc_size); + } + else + { + return(nsdynmemlib_stub.expectedPointer); + } +} + +void ns_dyn_mem_free(void *block) +{ + free(block); +} diff --git a/test/coap-service/unittest/stub/nsdynmemLIB_stub.h b/test/coap-service/unittest/stub/nsdynmemLIB_stub.h new file mode 100644 index 0000000000..d0838b038e --- /dev/null +++ b/test/coap-service/unittest/stub/nsdynmemLIB_stub.h @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2015 ARM Limited. All rights reserved. + */ +#ifndef __NSDYNMEMLIB_STUB_H__ +#define __NSDYNMEMLIB_STUB_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "stdint.h" + +typedef struct { + uint8_t returnCounter; + void* expectedPointer; +} nsdynmemlib_stub_data_t; + +extern nsdynmemlib_stub_data_t nsdynmemlib_stub; + + +void *ns_dyn_mem_alloc(int16_t alloc_size); +void *ns_dyn_mem_temporary_alloc(int16_t alloc_size); +void ns_dyn_mem_free(void *block); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/test/coap-service/unittest/stub/protocol_6lowpan_bootstrap_stub.c b/test/coap-service/unittest/stub/protocol_6lowpan_bootstrap_stub.c new file mode 100644 index 0000000000..6d5fa59e22 --- /dev/null +++ b/test/coap-service/unittest/stub/protocol_6lowpan_bootstrap_stub.c @@ -0,0 +1,162 @@ +/* + * Copyright (c) 2015 ARM Limited. All rights reserved. + */ + +/* + * \file protocol_6lowpan_bootstrap.c + * + */ +#include "config.h" +#include "string.h" +#include "ns_types.h" +#include "ns_trace.h" +#include "nsdynmemLIB.h" +#include "NWK_INTERFACE/Include/protocol.h" +#include "Common_Protocols/icmpv6.h" +#include "Common_Protocols/icmpv6_radv.h" +#include "Common_Protocols/udp.h" +#include "6LoWPAN/Bootstraps/network_lib.h" +#include "6LoWPAN/Bootstraps/protocol_6lowpan.h" +#include "6LoWPAN/Bootstraps/protocol_6lowpan_interface.h" +#include "MAC/IEEE802_15_4/mac_security_interface.h" +#include "MAC/IEEE802_15_4/mac_data_poll.h" +#include "MAC/IEEE802_15_4/mac_mlme.h" +#ifdef HAVE_RPL +#include "6LoWPAN/RPL/rpl.h" +#include "6LoWPAN/RPL/rpl_obj.h" +#else +/* This sort of thing should be handled in rpl.h itself */ +#define rpl_object_poisons() 0 +#endif +#ifndef NO_MLE +#include "MLE/mle.h" +//#include "MLE/mle_challenge_data.h" +#endif +#ifdef ECC +#include "libX509_V3.h" +#include "ecc.h" +#endif +#ifndef NO_TCP +#ifndef NO_TLS +#include "ccmLIB.h" +#include "shalib.h" +#include "Security/TLS/tls_lib.h" +#include "Security/Common/sec_lib.h" +#include "net_nvm_api.h" +#include "Security/PANA/pana.h" +#include "Security/PANA/pana_internal_api.h" +#endif +#include "Common_Protocols/tcp.h" +#endif +#include "6LoWPAN/ND/nd_router_object.h" +#include "common_functions.h" + +#define TRACE_GROUP_LOWPAN_BOOT "6Bo" + +int8_t arm_6lowpan_bootsrap_down(protocol_interface_info_entry_t *cur) +{ + return -1; +} + +int8_t arm_6lowpan_bootstrap_up(protocol_interface_info_entry_t *cur) +{ + return -1; +} + +void arm_6lowpan_bootstrap_init(protocol_interface_info_entry_t *cur) +{ +} + +void nwk_6lowpan_router_scan_state(protocol_interface_info_entry_t *cur) +{ +} + +void nwk_6lowpan_bootstrap_ready(protocol_interface_info_entry_t *cur) +{ +} + +void protocol_6lowpan_rpl_external_advertisment(protocol_interface_info_entry_t *cur_interface , rpl_dodag_t *cur) +{ +} + +void protocol_6lowpan_link_advertise_handle(nd_router_t *cur, protocol_interface_info_entry_t *cur_interface, uint16_t tick) +{ +} + +uint8_t nwk_bootstrap_icmp_rpl_dis_msg_tx(protocol_interface_info_entry_t *cur) +{ + return 0; +} + +void protocol_6lowpan_bootstrap_nd_ready(protocol_interface_info_entry_t *cur_interface, nd_router_t *cur) +{ +} + +void nwk_6lowpan_rpl_router_discover(protocol_interface_info_entry_t *cur) +{ +} + +void nwk_6lowpan_rpl_router_result_check(protocol_interface_info_entry_t *cur) +{ +} + + +void nwk_6lowpan_nd_address_registartion_ready(protocol_interface_info_entry_t *cur) +{ +} + +#ifdef PANA +void nwk_6lowpan_pana_key_pull(protocol_interface_info_entry_t *cur) +{ +} +#endif + +#ifndef NO_MLE + +#ifdef PANA +void nwk_6lowpan_bootsrap_pana_authentication_cb(bool processSuccesfully, protocol_interface_info_entry_t *cur) +{ + +} + +#endif + +#endif + +void nwk_6lowpan_network_authentication_fail(protocol_interface_info_entry_t *cur) +{ +} + +void nwk_6lowpan_network_authentication_done(protocol_interface_info_entry_t *cur) +{ +} + +void protocol_6lowpan_mac_scan_confirm(uint8_t *data) +{ +} + +void protocol_6lowpan_bootstrap(protocol_interface_info_entry_t *cur) +{ +} + +void protocol_6lowpan_mac_clean_mac16(protocol_interface_info_entry_t *interface) +{ +} + +void protocol_6lowpan_nd_borderrouter_connection_down(protocol_interface_info_entry_t *interface) +{ +} + +void protocol_6lowpan_bootstrap_re_start(protocol_interface_info_entry_t *interface) +{ +} + +uint8_t *protocol_6lowpan_nd_border_router_address_get(nwk_interface_id nwk_id) +{ + return NULL; +} + +uint8_t protocol_6lowpan_rf_link_scalability_from_lqi(uint8_t lqi) +{ + return 0; +} diff --git a/test/coap-service/unittest/stub/protocol_6lowpan_interface_stub.c b/test/coap-service/unittest/stub/protocol_6lowpan_interface_stub.c new file mode 100644 index 0000000000..88b1b0e753 --- /dev/null +++ b/test/coap-service/unittest/stub/protocol_6lowpan_interface_stub.c @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2015 ARM Limited. All rights reserved. + */ + +/* + * \file protocol_6lowpan_interface.c + * \brief Add short description about this file!!! + * + */ +#include "config.h" +#include "string.h" +#include "ns_types.h" +#include "eventOS_event.h" +#include "eventOS_scheduler.h" +#include "ns_trace.h" +#include "nsdynmemLIB.h" +#include "NWK_INTERFACE/Include/protocol.h" +#include "Common_Protocols/udp.h" +#include "6LoWPAN/ND/icmp.h" +#include "Common_Protocols/ipv6.h" +#include "Common_Protocols/icmpv6.h" +#include "Common_Protocols/icmpv6_radv.h" +#include "Core/include/routing_table.h" +#include "6LoWPAN/Bootstraps/network_lib.h" +#include "6LoWPAN/Bootstraps/protocol_6lowpan.h" +#include "6LoWPAN/Bootstraps/protocol_6lowpan_bootstrap.h" +#include "MAC/IEEE802_15_4/mac_security_interface.h" +#include "MAC/IEEE802_15_4/mac_mlme.h" +#ifdef HAVE_RPL +#include "6LoWPAN/RPL/rpl.h" +#include "6LoWPAN/RPL/rpl_obj.h" +#endif +#include "6LoWPAN/IPHC_Decode/cipv6.h" +#include "6LoWPAN/Fragmentation/cipv6_fragmenter.h" +#ifndef NO_MLE +#include "MLE/mle.h" +//#include "MLE/mle_challenge_data.h" +#endif +#include "6LoWPAN/Mesh/mesh.h" +#include "6LoWPAN/Thread/thread.h" +#ifdef ECC +#include "libX509_V3.h" +#include "ecc.h" +#endif +#ifndef NO_TCP +#ifndef NO_TLS +#include "ccmLIB.h" +#include "shalib.h" +#include "Security/TLS/tls_lib.h" +#include "Security/Common/sec_lib.h" +#include "net_nvm_api.h" +#include "Security/PANA/pana.h" +#include "Security/PANA/pana_internal_api.h" +#endif +#include "Common_Protocols/tcp.h" +#endif +#include "MulticastTrigle/multicast.h" +#include "NAP/nap_config.h" +#include "NWK_INTERFACE/Include/protocol_interface_driver.h" + +#include "6LoWPAN/ND/nd_router_object.h" +#include "platform/arm_hal_interrupt.h" +#include "common_functions.h" +#include "NWK_INTERFACE/Include/protocol_interface_driver.h" + + +int8_t nwk_6lowpan_up(protocol_interface_info_entry_t *cur) +{ + return 0; +} + +int8_t nwk_6lowpan_down(protocol_interface_info_entry_t *cur) +{ + return 0; +} diff --git a/test/coap-service/unittest/stub/protocol_6lowpan_stub.c b/test/coap-service/unittest/stub/protocol_6lowpan_stub.c new file mode 100644 index 0000000000..6b4c7348f6 --- /dev/null +++ b/test/coap-service/unittest/stub/protocol_6lowpan_stub.c @@ -0,0 +1,145 @@ +/* + * Copyright (c) 2013-2015 ARM Limited. All rights reserved. + */ + +#include "config.h" +#include "string.h" +#include "ns_types.h" +#include "eventOS_event.h" +#include "eventOS_scheduler.h" +#include "ns_trace.h" +#include "nsdynmemLIB.h" +#include "Core/include/socket.h" +#include "NWK_INTERFACE/Include/protocol.h" +#include "Common_Protocols/udp.h" +#include "Common_Protocols/ipv6.h" +#include "Common_Protocols/icmpv6.h" +#include "6LoWPAN/Bootstraps/protocol_6lowpan.h" +#include "MAC/IEEE802_15_4/mac_data_interface.h" +#include "MAC/IEEE802_15_4/mac_mlme.h" +#ifdef HAVE_RPL +#include "6LoWPAN/RPL/rpl.h" +#include "6LoWPAN/RPL/rpl_obj.h" +#else +/* This sort of thing should be handled in rpl.h itself */ +#define rpl_object_poisons() 0 +#endif +#include "6LoWPAN/IPHC_Decode/cipv6.h" +#include "6LoWPAN/Fragmentation/cipv6_fragmenter.h" +#ifndef NO_MLE +#include "MLE/mle.h" +//#include "MLE/mle_challenge_data.h" +#endif +#include "6LoWPAN/Mesh/mesh.h" +#include "6LoWPAN/Thread/thread.h" +#ifdef ECC +#include "libX509_V3.h" +#include "ecc.h" +#endif +#ifndef NO_TCP +#ifndef NO_TLS +#include "ccmLIB.h" +#include "shalib.h" +#include "Security/TLS/tls_lib.h" +#include "Security/Common/sec_lib.h" +#include "net_nvm_api.h" +#include "Security/PANA/pana.h" +#include "Security/PANA/pana_internal_api.h" +#endif +#include "Common_Protocols/tcp.h" +#endif +#include "NAP/nap_config.h" +#include "randLIB.h" +#include "6LoWPAN/ND/nd_router_object.h" +#include "common_functions.h" +#include "NWK_INTERFACE/Include/protocol_interface_driver.h" + +#define TRACE_GROUP_LOWPAN "6lo" +#ifdef NO_TCP +buffer_t *tcp_up(buffer_t *buf); +buffer_t *tcp_down(buffer_t *buf); + +buffer_t *tcp_up(buffer_t *buf) +{ + return buffer_free(buf); +} +buffer_t *tcp_down(buffer_t *buf) +{ + return buffer_free(buf); +} +#endif + +#ifdef NO_TLS +#define sec_timer_handle() +#endif + +void protocol_init(void) +{ +} + +void protocol_6lowpan_stack(buffer_t *b) +{ +} + +uint8_t protocol_6lowpan_llao_write(protocol_interface_info_entry_t *cur, uint8_t *opt_out, uint8_t opt_type) +{ + return 0; +} + +uint8_t protocol_6lowpan_llao_parse(protocol_interface_info_entry_t *cur, const uint8_t *opt_in, sockaddr_t *ll_addr_out) +{ + return 0; +} + +void protocol_6lowpan_register_handlers(protocol_interface_info_entry_t *cur) +{ +} + +void protocol_6lowpan_release_short_link_address_from_neighcache(protocol_interface_info_entry_t *cur, uint16_t shortAddress) +{ +} + +void protocol_6lowpan_release_long_link_address_from_neighcache(protocol_interface_info_entry_t *cur, uint8_t *mac64) +{ +} + +void protocol_6lowpan_priority_neigh_rm_callback(uint8_t *nwk_suffic, protocol_interface_info_entry_t *cur) +{ +} + +void protocol_6lowpan_neighbor_priority_update(protocol_interface_info_entry_t *cur, uint8_t *removed_priority, uint8_t *updated_priority) +{ +} + +int8_t protocol_6lowpan_neighbor_address_state_synch(protocol_interface_info_entry_t *cur, const uint8_t eui64[8], const uint8_t iid[8]) +{ + return 0; +} + +int8_t protocol_6lowpan_neighbor_remove(protocol_interface_info_entry_t *cur, uint8_t *address_ptr, addrtype_t type) +{ + return 0; +} + +int8_t protocol_6lowpan_neighbor_address_validate(route_info_entry_t *info, protocol_interface_info_entry_t *cur) +{ + return 0; +} + +void protocol_6lowpan_allocate_mac16(protocol_interface_info_entry_t *cur) +{ +} + +void protocol_6lowpan_interface_common_init(protocol_interface_info_entry_t *cur) +{ +} + +int8_t protocol_6lowpan_interface_compare_cordinator_netid(protocol_interface_info_entry_t *cur, uint8_t *adr_ptr) +{ + return 0; +} + +int8_t protocol_6lowpan_interface_get_link_local_cordinator_address(protocol_interface_info_entry_t *cur, uint8_t *adr_ptr) +{ + return 0; +} diff --git a/test/coap-service/unittest/stub/protocol_core_stub.c b/test/coap-service/unittest/stub/protocol_core_stub.c new file mode 100644 index 0000000000..cd2279a8a4 --- /dev/null +++ b/test/coap-service/unittest/stub/protocol_core_stub.c @@ -0,0 +1,300 @@ +/* + * Copyright (c) 2014-2015 ARM Limited. All rights reserved. + */ + +#include "config.h" +#include "string.h" +#include "ns_types.h" +#include "eventOS_event.h" +#include "eventOS_scheduler.h" +#include "eventOS_callback_timer.h" +#include "ns_trace.h" +#include "nsdynmemLIB.h" +#include "Core/include/socket.h" +#include "NWK_INTERFACE/Include/protocol.h" +#include "NWK_INTERFACE/Include/protocol_timer.h" +#include "NWK_INTERFACE/Include/protocol_interface_driver.h" +#include "MAC/IEEE802_15_4/mac_data_interface.h" +#include "MAC/IEEE802_15_4/mac_data_poll.h" +#include "MAC/IEEE802_15_4/mac_mlme.h" +#include "platform/arm_hal_interrupt.h" +#include "6LoWPAN/Fragmentation/cipv6_fragmenter.h" +#ifndef NO_MLE +#include "MLE/mle.h" +#endif +#include "6LoWPAN/Bootstraps/protocol_6lowpan.h" +#include "6LoWPAN/Bootstraps/protocol_6lowpan_bootstrap.h" +#include "NWK_INTERFACE/Include/protocol_stats.h" +#include "NWK_INTERFACE/Include/protocol_timer.h" +#include "common_functions.h" +#include "randLIB.h" +#include "platform/arm_hal_phy.h" +#include "platform/arm_hal_interrupt.h" +#ifdef ECC +#include "libX509_V3.h" +#include "ecc.h" +#endif +#ifndef NO_TLS +#include "shalib.h" +#include "Security/TLS/tls_lib.h" +#include "Security/Common/sec_lib.h" +#include "net_nvm_api.h" +#include "net_pana_parameters_api.h" +#include "Security/PANA/pana.h" +#include "Security/PANA/pana_internal_api.h" +#else +#define sec_timer_handle() +#endif +#include "Common_Protocols/ipv6.h" +#include "Common_Protocols/ipv6_fragmentation.h" +#include "Common_Protocols/icmpv6_radv.h" +#include "Common_Protocols/udp.h" +#include "6LoWPAN/ND/nd_router_object.h" +#include "6LoWPAN/RPL/rpl_definition.h" +#ifdef HAVE_RPL +#include "6LoWPAN/RPL/rpl.h" +#include "6LoWPAN/RPL/rpl_obj.h" +#endif +#include "NAP/nap_config.h" +#include "libDHCPv6/libDHCPv6.h" +#include "6LoWPAN/Thread/thread.h" +#include "6LoWPAN/Thread/thread_bootstrap.h" +#include "6LoWPAN/Thread/thread_routing.h" +#include "6LoWPAN/Thread/thread_management_internal.h" +#ifdef IPV6_STACK +#include "ipv6_stack/protocol_ipv6.h" +#endif +#ifdef WHITEBOARD +#ifdef NVM_BORDER_ROUTER +#include "br_list_nvm_api.h" +#endif +#include "Service_Libs/whiteboard/whiteboard.h" +#endif + +#include "MulticastTrigle/multicast.h" + +static protocol_interface_info_entry_t stub_protocol_interface_info_entry; + +#define TRACE_GROUP_CORE "core" + +#ifndef SEC_LIB_X_100MS_COUNTER +#define SEC_LIB_X_100MS_COUNTER 1 +#endif +uint32_t protocol_core_monotonic_time; + +typedef struct { + uint8_t core_timer_ticks; + uint8_t core_timer_event; + uint16_t core_security_ticks_counter; + uint8_t nd_ttl_timer; +} lowpan_core_timer_structures_s; + +void core_timer_event_handle(uint16_t ticksUpdate); + +#ifndef IPV6_STACK +#define ipv6_core_timer_event_handle(x,y) +#define ipv6_core_slow_timer_event_handle(x) +#endif + +uint32_t event_idle_dummy(uint8_t result, uint32_t s_time) +{ + return 0; +} + + +int8_t protocol_read_tasklet_id(void) +{ + return -1; +} + +uint8_t check_power_state(uint8_t mode) +{ + return 0; +} + + +void set_power_state(uint8_t mode) +{ +} + +void clear_power_state(uint8_t mode) +{ +} + +protocol_interface_info_entry_t *nwk_interface_get_pointer_by_timer_id(int8_t id, arm_nwk_timer_id_e type) +{ + return NULL; +} + +void timer_ifs_interrupt(int8_t timer_id, uint16_t slots) +{ +} + +void protocol_root_tasklet(arm_event_s *event) +{ +} +void protocol_core_security_tick_update(uint16_t tick_update) +{ +} + +void nwk_bootsrap_timer(protocol_interface_info_entry_t *cur) +{ +} + +uint8_t nwk_border_router_active(nwk_interface_id nwk_id) +{ + return 0; +} + +void core_timer_event_handle(uint16_t ticksUpdate) +{ +} + +void protocol_core_cb(uint16_t ticksUpdate) +{ +} + + +void protocol_core_init(void) +{ +} + +void protocol_core_interface_info_reset(protocol_interface_info_entry_t *entry) +{ +} + +void bootsrap_next_state_kick(icmp_state_t new_state, protocol_interface_info_entry_t *cur) +{ +} + +uint32_t protocol_stack_interface_set_reachable_time(protocol_interface_info_entry_t *cur, uint32_t base_reachable_time) +{ + return 0; +} +protocol_interface_info_entry_t *nwk_interface_get_ipv6_ptr(void) +{ + return NULL; +} + +void nwk_interface_print_neigh_cache(uint8_t dlevel) +{ +} + +void nwk_interface_flush_neigh_cache(void) +{ +} + +void ipv6_prefix_on_link_update(uint8_t *address) +{ +} + +void ipv6_prefix_on_link_remove(uint8_t *address) +{ +} + +protocol_interface_info_entry_t *protocol_stack_interface_info_get(nwk_interface_id nwk_id) +{ + return &stub_protocol_interface_info_entry; +} + +protocol_interface_info_entry_t *protocol_stack_interface_info_get_by_id(int8_t nwk_id) +{ + return NULL; +} + +protocol_interface_info_entry_t *protocol_stack_interface_info_get_by_bootstrap_id(int8_t id) +{ + return NULL; +} + +protocol_interface_info_entry_t *protocol_stack_interface_info_get_by_device_id(int8_t nwk_id) +{ + return NULL; +} + +protocol_interface_info_entry_t *protocol_stack_interface_info_get_by_tun_device_id(int8_t nwk_id) +{ + return NULL; +} + + + +protocol_interface_info_entry_t *protocol_stack_interface_sleep_possibility(void) +{ + return NULL; +} + +uint8_t nwk_bootsrap_ready(protocol_interface_info_entry_t *cur) +{ + return 0; +} + +int8_t nwk_interface_MAC_MTU_allocate(protocol_interface_info_entry_t *cur) +{ + return 0; +} + +protocol_interface_info_entry_t *protocol_stack_interface_generate(nwk_interface_id nwk_id, int8_t driver_id) +{ + return NULL; +} + +void nwk_interface_link_layer_key_synch_lost_check(protocol_interface_info_entry_t *cur, uint8_t key_id) +{ +} + +bool nwk_interface_compare_mac_address(protocol_interface_info_entry_t *cur, uint_fast8_t addrlen, const uint8_t *addr) +{ + return 0; +} + +int nwk_lowpan_routing_check(buffer_t *buf) +{ + return 0; +} + +int8_t nwk_interface_solication_address_check(protocol_interface_info_entry_t *cur_interface, const uint8_t address_ptr[__static 16]) +{ + return 0; +} + +int protocol_stack_interface_check_prefix_extension_support(int8_t nwk_id, uint8_t *prefix) +{ + return -1; +} + +void protocol_stack_pointer_clear(nwk_interface_id if_id) +{ +} + +int8_t protocol_stack_pointer_check(nwk_interface_id if_id) +{ + return 0; +} + +uint8_t protocol_too_busy(void) +{ + return 0; +} + +void protocol_push(buffer_t *buf) +{ +} + +void nwk_bootsrap_state_update(arm_nwk_interface_status_type_e posted_event, protocol_interface_info_entry_t *cur) +{ +} + +void net_bootsrap_cb_run(uint8_t event) +{ +} + +void protocol_core_dhcpv6_allocated_address_remove(protocol_interface_info_entry_t *cur, uint8_t *guaPrefix) +{ +} + +int8_t protcol_interface_address_compare(protocol_interface_info_entry_t *cur, const uint8_t *addr) +{ + return -1; +} + diff --git a/test/coap-service/unittest/stub/protocol_interface_driver_stub.c b/test/coap-service/unittest/stub/protocol_interface_driver_stub.c new file mode 100644 index 0000000000..9e1177c53c --- /dev/null +++ b/test/coap-service/unittest/stub/protocol_interface_driver_stub.c @@ -0,0 +1,14 @@ +/* + * Copyright (c) 2014-2015 ARM Limited. All rights reserved. + */ +#include "config.h" +#include "string.h" +#include "ns_types.h" +#include "NWK_INTERFACE/Include/protocol.h" +#include "NWK_INTERFACE/Include/protocol_interface_driver.h" +#include "nsdynmemLIB.h" + +arm_device_driver_list_s *arm_net_phy_driver_pointer(int8_t id) +{ + return NULL; +} diff --git a/test/coap-service/unittest/stub/protocol_ipv6_stub.c b/test/coap-service/unittest/stub/protocol_ipv6_stub.c new file mode 100644 index 0000000000..33328130ce --- /dev/null +++ b/test/coap-service/unittest/stub/protocol_ipv6_stub.c @@ -0,0 +1,169 @@ +/* + * Copyright (c) 2012-2015 ARM Limited. All rights reserved. + */ +#include "config.h" +#include "string.h" +#include "ns_types.h" +#include "ns_list.h" +#include "ns_trace.h" +#include "nsdynmemLIB.h" +#include "Core/include/socket.h" +#include "NWK_INTERFACE/Include/protocol.h" +#include "Common_Protocols/ipv6.h" +#include "6LoWPAN/ND/icmp.h" +#include "Common_Protocols/icmpv6.h" +#include "Common_Protocols/ipv6_resolution.h" +#include "Common_Protocols/icmpv6_prefix.h" +#include "Common_Protocols/icmpv6_radv.h" +#include "Common_Protocols/udp.h" +#ifndef NO_TLS +#ifdef ECC +#include "libX509_V3.h" +#include "ecc.h" +#endif +#include "shalib.h" +#include "Security/TLS/tls_lib.h" +#include "Security/Common/sec_lib.h" +#endif + +#include "6LoWPAN/ND/nd_router_object.h" // for gp_address_ functions - better place? +#include "ipv6_stack/ipv6_routing_table.h" +#include "ipv6_stack/protocol_ipv6.h" +#ifndef NO_TCP +#include "Common_Protocols/tcp.h" +#endif +#ifdef NVM_BORDER_ROUTER +#include "br_list_nvm_api.h" +#endif +#include "Service_Libs/whiteboard/whiteboard.h" +#include "platform/arm_hal_interrupt.h" +#include "common_functions.h" +#include "randLIB.h" + +typedef struct ipv6_interface_prefix_on_link_t { + uint8_t prefix[16]; /*!< destination address */ + uint8_t prefix_len; + uint32_t prefix_valid_ttl; + ns_list_link_t link; +} ipv6_interface_prefix_on_link_t; + +typedef struct ipv6_interface_route_on_link_t { + uint8_t prefix[16]; /*!< destination address */ + uint8_t prefix_len; + uint8_t routePrefer; + uint32_t prefix_valid_ttl; + ns_list_link_t link; +} ipv6_interface_route_on_link_t; + +#define WB_UPDATE_PERIOD_SECONDS 23 + +#define ROUTER_SOL_MAX_COUNTER 4 + +#define TRACE_GROUP_PROTOCOL_IPv6 "ip6s" + +int ipv6_generate_static_gp_setup(protocol_interface_info_entry_t *cur) +{ + return -1; +} + +int ipv6_generate_ula_prefix(protocol_interface_info_entry_t *cur) +{ + return -1; +} + +int ipv6_prefix_router_flag_activate(uint8_t *ipv6_address) +{ + return -1; +} + +buffer_t *ethernet_header_build_push(buffer_t *buf, uint16_t ethernet_type, int8_t *status) +{ + return NULL; +} + +buffer_t *ethernet_down(buffer_t *buf) +{ + return NULL; +} + +void ipv6_stack_prefix_on_link_update(protocol_interface_info_entry_t *cur, uint8_t *address) +{ +} + +void ipv6_stack_route_advert_update(uint8_t *address, uint8_t prefixLength, uint8_t routePrefer) +{ +} + +void ipv6_stack_prefix_on_link_remove(protocol_interface_info_entry_t *cur, uint8_t *address) +{ +} + +void ipv6_stack_route_advert_remove(uint8_t *address, uint8_t prefixLength) +{ +} + +void ipv6_prefix_online_list_free(void) +{ +} + +void ipv6_rote_advert_list_free(void) +{ +} + +void ipv6_core_slow_timer_event_handle(struct protocol_interface_info_entry *cur) +{ +} + +void ipv6_core_timer_event_handle(protocol_interface_info_entry_t *cur, const uint8_t event) +{ +} + +int ipv6_prefix_register(uint8_t *prefix_64, uint32_t lifetime, uint32_t prefer_lifetime) +{ + return -1; +} + + +int8_t ipv6_interface_up(protocol_interface_info_entry_t *cur) +{ + return -1; +} + +int8_t ipv6_interface_down(protocol_interface_info_entry_t *cur) +{ + return -1; +} + + +#ifdef RADV_TX +void ipv6_nd_ra_advert(protocol_interface_info_entry_t *cur, const uint8_t *dest) +{ +} +#endif + +void ipv6_interface_resolve_send_ns(ipv6_neighbour_cache_t *cache, ipv6_neighbour_t *entry, bool unicast, uint_fast8_t seq) +{ +} + + + +void ipv6_trigger_resolve_query(protocol_interface_info_entry_t *cur_interface, buffer_t *buf, ipv6_neighbour_t *n) +{ +} + +void ipv6_send_queued(ipv6_neighbour_t *entry) +{ +} + +void ipv6_interface_resolution_failed(ipv6_neighbour_cache_t *cache, ipv6_neighbour_t *entry) +{ +} + +ipv6_neighbour_cache_t *ipv6_neighbour_cache_by_interface_id(int8_t interface_id) +{ + return NULL; +} + +void ipv6_interface_slaac_handler(protocol_interface_info_entry_t *cur, uint8_t *slaacPrefix, uint8_t prefixLen, uint32_t validLifeTime, uint32_t preferredLifeTime) +{ +} diff --git a/test/coap-service/unittest/stub/randLIB_stub.c b/test/coap-service/unittest/stub/randLIB_stub.c new file mode 100644 index 0000000000..ac55243027 --- /dev/null +++ b/test/coap-service/unittest/stub/randLIB_stub.c @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2014-2015 ARM Limited. All rights reserved. + */ +#include +#include +#include +#include +#include "randLIB.h" +#include "platform/arm_hal_random.h" + +#if ((RAND_MAX+1) & RAND_MAX) != 0 +#error "RAND_MAX isn't 2^n-1 :(" +#endif + +void randLIB_seed_random(void) +{ +} + +uint8_t randLIB_get_8bit(void) +{ + return 0; +} + +uint16_t randLIB_get_16bit(void) +{ + return 0; +} + +uint32_t randLIB_get_32bit(void) +{ + return 0; +} + +int8_t randLIB_get_n_bytes_random(uint8_t *data_ptr, uint8_t eight_bit_boundary) +{ + return 0; +} + +uint16_t randLIB_get_random_in_range(uint16_t min, uint16_t max) +{ + return 0; +} + +uint32_t randLIB_randomise_base(uint32_t base, uint16_t min_factor, uint16_t max_factor) +{ + return 0; +} diff --git a/test/coap-service/unittest/stub/routing_table_stub.c b/test/coap-service/unittest/stub/routing_table_stub.c new file mode 100644 index 0000000000..345b73625a --- /dev/null +++ b/test/coap-service/unittest/stub/routing_table_stub.c @@ -0,0 +1,128 @@ +/* + * Copyright (c) 2011-2015 ARM Limited. All rights reserved. + */ +#include "config.h" +#include "ns_types.h" +#include "ns_trace.h" +#include "string.h" +#include "Core/include/address.h" +#include "Core/include/buffer.h" +#include "Core/include/socket.h" +#include "Core/include/routing_table.h" +#include "nsdynmemLIB.h" +#include "Common_Protocols/ipv6.h" +#ifdef NVM_BORDER_ROUTER +#include "br_list_nvm_api.h" +#endif +#include "common_functions.h" + +#define TRACE_GROUP_ROUTING_TABLE "crou" + +#if ADDRESS_SIZE == 8 +#if MAX_HOP_CNT > 30 +#error "DO not set MAX_HOP_CNT over 30 reason by 8-bit size resolution" +#endif +#endif + +source_route_t *get_generated_src_route(void) +{ + return NULL; +} + +#ifdef NVM_BORDER_ROUTER +uint16_t (*route_nvm_storage_cb)(br_nvm_update_process_t) = 0; + +int8_t route_nvm_callback_set(uint16_t (*passed_fptr)(br_nvm_update_process_t), uint8_t *nvm_static_buffer) +{ + return -1; +} + +int8_t route_entry_store_from_nvm(const uint8_t *nvm_data) +{ + return -1; +} + +#endif +void route_nvm_update(route_table_entry_t *entry) +{ +} + +void route_nvm_remove(route_table_entry_t *entry) +{ +} + +void gen_route_del(route_table_entry_t *cur) +{ +} + +uint8_t gen_source_route(route_info_entry_t *info) +{ + return 0; +} + +uint8_t *gen_source_route_set(uint8_t *ptr) +{ + return NULL; +} + +route_table_entry_t *gen_route_entry_get(const uint8_t address[16]) +{ + return NULL; +} + +route_table_entry_t *gen_route_entry_get_by_iid(const uint8_t address[8]) +{ + return NULL; +} + +void gen_routing_table_init(void) +{ +} + +route_table_entry_t *gen_table_update(const uint8_t addr[16]) +{ + return NULL; +} + + +int8_t gen_source_route_allocate(uint8_t alloc) +{ + return -1; +} + + + +int8_t gen_route_exist_check(const uint8_t ipv6_address_ptr[16]) +{ + return -1; +} + + + +void gen_route_detect(route_info_entry_t *info, uint8_t forward_info) +{ +} + + +void gen_routing_ttl_update(uint8_t id) +{ +} + +void gen_routing_ttl_set_low_by_repair(uint8_t id) +{ +} + +void gen_route_remove_by_rpl_instance(uint8_t id) +{ +} + + +void gen_neighbor_ttl_update(uint8_t ttl) +{ +} + +void routing_table_print(void) +{ +} + + diff --git a/test/coap-service/unittest/stub/rpl_obj_stub.c b/test/coap-service/unittest/stub/rpl_obj_stub.c new file mode 100644 index 0000000000..95acfc9b39 --- /dev/null +++ b/test/coap-service/unittest/stub/rpl_obj_stub.c @@ -0,0 +1,392 @@ +/* + * Copyright (c) 2013-2015 ARM Limited. All rights reserved. + */ +#include "config.h" +#include +#include "ns_types.h" + +#ifdef HAVE_RPL +#include "nsdynmemLIB.h" +#include "NWK_INTERFACE/Include/protocol.h" +#include "ns_trace.h" +#include "ip6string.h" +#include "Core/include/routing_table.h" +#include "6LoWPAN/IPHC_Decode/cipv6.h" +#include "Common_Protocols/icmpv6.h" +#include "Common_Protocols/icmpv6_prefix.h" +#include "6LoWPAN/RPL/rpl.h" +#include "6LoWPAN/RPL/rpl_obj.h" +#include "net_rpl.h" +#include "6LoWPAN/ND/nd_router_object.h" +#include "6LoWPAN/Bootstraps/network_lib.h" +#include "6LoWPAN/Bootstraps/protocol_6lowpan.h" +#include "6LoWPAN/Bootstraps/protocol_6lowpan_bootstrap.h" +#include "randLIB.h" +#include "nwk_stats_api.h" +#include "NWK_INTERFACE/Include/protocol_stats.h" +#ifdef IPV6_STACK +#include "Common_Protocols/ipv6.h" +#endif +#ifdef NVM_BORDER_ROUTER +#include "br_list_nvm_api.h" +#endif + +#include "common_functions.h" + +#define TRACE_GROUP_RPL_OBJ "rplo" + +const uint8_t ADDR_LINK_LOCAL_ALL_RPL_NODES[16] = { 0xff, 0x02, [15] = 0x1a }; + +void rpl_dodag_base_init(rpl_dodag_t *new_entry); + +int8_t rpl_prefix_update(uint8_t *dptr, rpl_dodag_t *rpl_object); +static void rpl_route_list_free(route_list_t *list); +void rpl_object_release(rpl_dodag_t *router_object); +void rpl_router_object_reset(rpl_dodag_t *router_object); +//uint8_t rpl_metric_parse(buffer_t *buf); +void rpl_dodag_config_update(uint8_t *dptr, dodag_config_t *dodag_conf); +rpl_dodag_t *icmp_rpl_router_object_get(uint8_t *dodag_id, uint8_t instance_id, uint16_t rank); +rpl_dodag_t *icmp_rpl_router_object_get_by_intance(uint8_t instance_id); +uint8_t rpl_dis_build(rpl_dodag_t *cur); +uint8_t rpl_dio_tx(rpl_dodag_t *cur, uint8_t *address , protocol_interface_info_entry_t *cur_interface); +uint8_t rpl_dao_tx(rpl_dodag_t *cur, protocol_interface_info_entry_t *cur_interface); +void rpl_set_trigle_timer(rpl_dodag_t *cur , uint8_t active); +void rpl_unicast_response_allocate(rpl_dodag_t *router, uint8_t *address); +void rpl_object_print(void); +void rpl_obj_update_rank_hop(rpl_dodag_t *temp); +int8_t rpl_route_prefix_update(uint8_t len, const uint8_t *dptr, uint8_t instance_id); +void rpl_route_prefix_remove_by_rpl_instance(uint8_t id); +rpl_dodag_t *rpl_root_get_by_intance_id(uint8_t instace_id); + +#ifdef NVM_BORDER_ROUTER + +uint16_t (*rpl_nvm_storage_cb)(br_rpl_nvm_update_process_t) = 0; + +int8_t rpl_nvm_callback_set(uint16_t (*passed_fptr)(br_rpl_nvm_update_process_t), uint8_t *nvm_static_buffer) +{ + return -1; +} + +int8_t rpl_nvm_base_reload(const uint8_t *nvm_data, int8_t interface_id) +{ + return -1; +} + +int8_t rpl_prefix_store_from_nvm(const uint8_t *nvm_data, uint8_t instance_id) +{ + return -1; +} + +int8_t rpl_route_store_from_nvm(const uint8_t *nvm_data, uint8_t instance_id) +{ + return -1; +} + + + +#endif + +int8_t rpl_root_dodag_poiso_ready(uint8_t instace_id) +{ + return -1; +} + +int8_t arm_nwk_6lowpan_rpl_dodag_dao_trig(int8_t nwk_interface_id) +{ + return -1; +} + +int8_t arm_nwk_6lowpan_rpl_dodag_version_increment(int8_t nwk_interface_id) +{ + return -1; +} + +uint8_t rpl_routers_active(void) +{ + return 0; +} + +int8_t rpl_root_active(rpl_dodag_t *compare_ptr) +{ + return -1; +} + +int8_t arm_nwk_6lowpan_rpl_dodag_start(int8_t interface_id) +{ + return -1; +} + +int8_t arm_nwk_6lowpan_rpl_dodag_init(int8_t interface_id, const uint8_t *dodag_id, const dodag_config_t *config, uint8_t instace_id, uint8_t flags) +{ + return -1; +} + +int8_t rpl_root_setup_refresh(uint8_t instance_id) +{ + return -1; +} + +rpl_dodag_t *rpl_root_get_by_intance_id(uint8_t instance_id) +{ + return NULL; +} + +int8_t arm_nwk_6lowpan_rpl_dodag_poison(int8_t nwk_interface_id) +{ + return -1; +} + +int8_t arm_nwk_6lowpan_rpl_dodag_remove(int8_t interface_id) +{ + return -1; +} + + +void rpl_routers_init(void) +{ +} + +void rpl_obj_change_parent(rpl_dodag_t *temp) +{ +} + +void rpl_obj_update_rank_hop(rpl_dodag_t *temp) +{ +} + + +void rpl_obj_dao_trig(rpl_dodag_t *cur) +{ +} + +void rpl_object_release(rpl_dodag_t *router_object) +{ +} + +void rpl_router_object_reset(rpl_dodag_t *router_object) +{ +} + +rpl_dodag_t *icmp_rpl_router_object_get_by_intance(uint8_t instance_id) +{ + return NULL; +} + +void rpl_dodag_base_init(rpl_dodag_t *new_entry) +{ +} + +rpl_dodag_t *icmp_rpl_router_object_get(uint8_t *dodag_id, uint8_t instance_id, uint16_t rank) +{ + return NULL; +} + +void rpl_unicast_response_allocate(rpl_dodag_t *router, uint8_t *address) +{ +} + +void rpl_dis_handler(buffer_t *buf, bool multicast_dst) +{ +} + +buffer_t *rpl_dao_parse(buffer_t *buf) +{ + return NULL; +} + +void rpl_dao_ack_parse(uint8_t *dptr, uint16_t length, nwk_interface_id nwk_id) +{ +} + +void rpl_dio_parse(buffer_t *buf) +{ +} + +int8_t arm_nwk_6lowpan_rpl_dodag_prefix_update(int8_t nwk_interface_id, uint8_t *prefix_ptr, uint8_t prefix_len, uint8_t flags, uint32_t lifetime) +{ + return -1; +} + +int8_t rpl_prefix_update(uint8_t *dptr, rpl_dodag_t *rpl_object) +{ + return -1; +} + + +int8_t arm_nwk_6lowpan_rpl_dodag_route_update(int8_t nwk_interface_id, uint8_t *route_ptr, uint8_t prefix_len, uint8_t flags, uint32_t lifetime) +{ + return -1; +} + +rpl_dodag_t *rpl_route_longest_matches_prefix(const uint8_t *address) +{ + return NULL; +} + +void rpl_route_prefix_remove_by_rpl_instance(uint8_t id) +{ +} + +int8_t rpl_route_prefix_update(uint8_t len, const uint8_t *dptr, uint8_t instance_id) +{ + return -1; +} + +route_entry_t *rpl_root_route_update(const uint8_t *dptr, rpl_dodag_proxy_t *rpl_object) +{ + return NULL; +} + +void rpl_dodag_config_update(uint8_t *dptr, dodag_config_t *dodag_conf) +{ +} + +uint8_t rpl_dodag_object_heared(void) +{ + return 0; +} + +void rpl_dodag_root_dao_repair(void) +{ +} + + +rpl_dodag_t *rpl_dodag_root_get(nwk_interface_id nwk_id) +{ + return NULL; +} + +uint8_t rpl_dodag_cnt(void) +{ + return 0; +} + +void rpl_dodag_dao_external_timer_trig(void) +{ +} + +void rpl_router_prefix_ttl_update(rpl_dodag_t *router_object) +{ +} + +void rpl_route_prefix_route_ttl_update(uint8_t intance_id) +{ + +} + +uint16_t rpl_route_prefix_route_length(uint8_t intance_id) +{ + return 0; +} + +uint8_t *rpl_route_prefix_route_set(uint8_t *dptr , uint8_t intance_id) +{ + return NULL; +} + +void rpl_object_timer_second_update(nwk_interface_id nwk_id) +{ + +} + +void rpl_object_timer(uint8_t ticks, protocol_interface_info_entry_t *cur_interface) +{ + +} + +uint8_t rpl_object_poisons(void) +{ + return 0; +} + +void rpl_object_timer_balance(uint16_t sleep_time) +{ + +} + +uint8_t rpl_dis_build(rpl_dodag_t *cur) +{ + return 0; +} + + +uint8_t rpl_dao_tx(rpl_dodag_t *cur, protocol_interface_info_entry_t *cur_interface) +{ + return 0; +} + +uint8_t rpl_poison_req(rpl_dodag_t *cur) +{ + return 0; +} + +uint8_t rpl_host_dao_tx(rpl_dodag_t *cur, uint8_t *adr_ptr, uint8_t short_address_type) +{ + return 0; +} + +void rpl_set_trigle_timer(rpl_dodag_t *cur , uint8_t active) +{ +} + +//extern void get_suffics(uint8_t *ptr); +uint8_t rpl_dio_tx(rpl_dodag_t *cur, uint8_t *address , protocol_interface_info_entry_t *cur_interface) +{ + return 0; +} + + +uint8_t rpl_routeloop_check(rpl_loopdetect_t *loop) +{ + return 0; +} + +rpl_dodag_t *rpl_route(const uint8_t *addr, uint8_t id/*, route_info_entry_t * response*/) +{ + return NULL; +} + +rpl_dodag_t *rpl_route_by_prefix(const uint8_t *addr, bool root_is_valid) +{ + return NULL; +} + +uint8_t rpl_prefix_adr_valid_check(uint8_t *addr) +{ + return 0; +} + +uint8_t rpl_get_router_address(uint8_t *addr) +{ + return 0; +} + +uint8_t rpl_compare_parent(uint8_t *addr, rpl_dodag_t **response) +{ + return 0; +} + +void rpl_parent_remove(uint8_t *addr, protocol_interface_info_entry_t *cur_interface) +{ +} + +void rpl_object_print(void) +{ +} + +uint8_t rpl_instance_list_read(uint8_t *cache_ptr, uint8_t cache_size) +{ + return 0; +} + +uint8_t rpl_read_dodag_info(rpl_dodag_info_t *dodag_ptr, uint8_t instance_id) +{ + return 0; +} + +bool rpl_root_rank(rpl_dodag_t *cur) +{ + return false; +} + +#endif diff --git a/test/coap-service/unittest/stub/security_lib_stub.c b/test/coap-service/unittest/stub/security_lib_stub.c new file mode 100644 index 0000000000..ec78c0e316 --- /dev/null +++ b/test/coap-service/unittest/stub/security_lib_stub.c @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2013-2015 ARM Limited. All rights reserved. + */ +#include "config.h" +#include "ns_types.h" +#include "ns_trace.h" +#include "string.h" +#include "eventOS_event.h" +#include "ccmLIB.h" +#include "nsdynmemLIB.h" +#include "Core/include/socket.h" +#include "NWK_INTERFACE/Include/protocol.h" +#include "shalib.h" +#include "randLIB.h" +#ifdef ECC +#include "libX509_V3.h" +#include "ecc.h" +#endif +#include "Security/TLS/tls_lib.h" +#include "Security/Common/sec_lib.h" +#include "net_nvm_api.h" +#include "Security/PANA/pana_nvm.h" +#include "Security/PANA/pana.h" +#include "Security/PANA/pana_internal_api.h" +#include "common_functions.h" + +sec_suite_t *sec_suite_tls_session_get_by_socket_address(sockaddr_t *add, uint8_t request_by_server, int8_t socket_id) +{ + return NULL; +} + +int8_t sec_suite_set_chipher_suite_list(int8_t socket_id, uint8_t security_suites) +{ + return -1; +} diff --git a/test/coap-service/unittest/stub/shalib_stub.c b/test/coap-service/unittest/stub/shalib_stub.c new file mode 100644 index 0000000000..7aa1b9e39a --- /dev/null +++ b/test/coap-service/unittest/stub/shalib_stub.c @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2015 ARM Limited. All rights reserved. + */ + +#include +#include "shalib.h" + +void SHALIB_init_sha256(void) +{ + +} + +void SHALIB_push_data_sha256(uint8_t *data, uint16_t len) +{ + +} + +void SHALIB_finish_sha256(uint8_t *buffer, uint8_t len) +{ + +} + +void SHALIB_SHA256_HASH(uint8_t *data_ptr, uint16_t data_len, uint8_t *buffer) +{ + +} + + +void sha_resume_regs(sha256_temp_t *ptr) +{ + +} + +void sha_save_regs(sha256_temp_t *ptr) +{ + +} + +void SHALIB_init_HMAC(uint8_t *secret, uint8_t sec_len) +{ + +} + +void SHALIB_finish_HMAC(uint8_t *buffer, uint8_t len) +{ + +} + +prf_sec_param_t *shalib_prf_param_get(void) +{ + return NULL; +} + +void shalib_prf_calc(void) +{ + +} + diff --git a/test/coap-service/unittest/stub/sn_coap_builder_stub.c b/test/coap-service/unittest/stub/sn_coap_builder_stub.c new file mode 100644 index 0000000000..38e5288283 --- /dev/null +++ b/test/coap-service/unittest/stub/sn_coap_builder_stub.c @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2011-2015 ARM Limited. All rights reserved. + * SPDX-License-Identifier: Apache-2.0 + * Licensed under the Apache License, Version 2.0 (the License); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * \file sn_coap_builder.c + * + * \brief CoAP Message builder + * + * Functionality: Builds CoAP message + * + */ + +/* * * * * * * * * * * * * * */ +/* * * * INCLUDE FILES * * * */ +/* * * * * * * * * * * * * * */ + +#include "ns_types.h" +#include "sn_coap_header.h" +#include "sn_coap_builder_stub.h" + +sn_coap_builder_stub_def sn_coap_builder_stub; + +sn_coap_hdr_s *sn_coap_build_response(struct coap_s *handle, sn_coap_hdr_s *coap_packet_ptr, uint8_t msg_code) +{ + return sn_coap_builder_stub.expectedHeader; +} + +int16_t sn_coap_builder(uint8_t *dst_packet_data_ptr, sn_coap_hdr_s *src_coap_msg_ptr) +{ + return sn_coap_builder_stub.expectedInt16; +} + +uint16_t sn_coap_builder_calc_needed_packet_data_size(sn_coap_hdr_s *src_coap_msg_ptr) +{ + return sn_coap_builder_stub.expectedUint16; +} + +int16_t sn_coap_builder_options_build_add_zero_length_option(uint8_t **dst_packet_data_pptr, uint8_t option_length, uint8_t option_exist, sn_coap_option_numbers_e option_number) +{ + return sn_coap_builder_stub.expectedInt16; +} + diff --git a/test/coap-service/unittest/stub/sn_coap_builder_stub.h b/test/coap-service/unittest/stub/sn_coap_builder_stub.h new file mode 100644 index 0000000000..6ca30584d2 --- /dev/null +++ b/test/coap-service/unittest/stub/sn_coap_builder_stub.h @@ -0,0 +1,13 @@ + +#ifndef __SN_COAP_BUILDER_STUB_H__ +#define __SN_COAP_BUILDER_STUB_H__ + +typedef struct { + int16_t expectedInt16; + uint16_t expectedUint16; + sn_coap_hdr_s *expectedHeader; +} sn_coap_builder_stub_def; + +extern sn_coap_builder_stub_def sn_coap_builder_stub; + +#endif //__SN_COAP_BUILDER_STUB_H__ diff --git a/test/coap-service/unittest/stub/sn_coap_parser_stub.c b/test/coap-service/unittest/stub/sn_coap_parser_stub.c new file mode 100644 index 0000000000..6d9e73383b --- /dev/null +++ b/test/coap-service/unittest/stub/sn_coap_parser_stub.c @@ -0,0 +1,107 @@ +/* + * Copyright (c) 2011-2015 ARM Limited. All rights reserved. + * SPDX-License-Identifier: Apache-2.0 + * Licensed under the Apache License, Version 2.0 (the License); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + *\file sn_coap_parser.c + * + * \brief CoAP Header parser + * + * Functionality: Parses CoAP Header + * + */ + +#include "ns_types.h" +#include "sn_nsdl.h" +#include "sn_coap_protocol.h" +#include "sn_coap_parser_stub.h" + +sn_coap_parser_def sn_coap_parser_stub; + +sn_coap_hdr_s *sn_coap_parser(struct coap_s *handle, uint16_t packet_data_len, uint8_t *packet_data_ptr, coap_version_e *coap_version_ptr) +{ + return sn_coap_parser_stub.expectedHeader; +} + +void sn_coap_parser_release_allocated_coap_msg_mem(struct coap_s *handle, sn_coap_hdr_s *freed_coap_msg_ptr) +{ + if (freed_coap_msg_ptr != NULL) { + if (freed_coap_msg_ptr->uri_path_ptr != NULL) { + free(freed_coap_msg_ptr->uri_path_ptr); + } + + if (freed_coap_msg_ptr->token_ptr != NULL) { + free(freed_coap_msg_ptr->token_ptr); + } + + if (freed_coap_msg_ptr->content_type_ptr != NULL) { + free(freed_coap_msg_ptr->content_type_ptr); + } + + if (freed_coap_msg_ptr->options_list_ptr != NULL) { + if (freed_coap_msg_ptr->options_list_ptr->max_age_ptr != NULL) { + free(freed_coap_msg_ptr->options_list_ptr->max_age_ptr); + } + + if (freed_coap_msg_ptr->options_list_ptr->proxy_uri_ptr != NULL) { + free(freed_coap_msg_ptr->options_list_ptr->proxy_uri_ptr); + } + + if (freed_coap_msg_ptr->options_list_ptr->etag_ptr != NULL) { + free(freed_coap_msg_ptr->options_list_ptr->etag_ptr); + } + + if (freed_coap_msg_ptr->options_list_ptr->uri_host_ptr != NULL) { + free(freed_coap_msg_ptr->options_list_ptr->uri_host_ptr); + } + + if (freed_coap_msg_ptr->options_list_ptr->location_path_ptr != NULL) { + free(freed_coap_msg_ptr->options_list_ptr->location_path_ptr); + } + + if (freed_coap_msg_ptr->options_list_ptr->uri_port_ptr != NULL) { + free(freed_coap_msg_ptr->options_list_ptr->uri_port_ptr); + } + + if (freed_coap_msg_ptr->options_list_ptr->location_query_ptr != NULL) { + free(freed_coap_msg_ptr->options_list_ptr->location_query_ptr); + } + + if (freed_coap_msg_ptr->options_list_ptr->observe_ptr != NULL) { + free(freed_coap_msg_ptr->options_list_ptr->observe_ptr); + } + + if (freed_coap_msg_ptr->options_list_ptr->uri_query_ptr != NULL) { + free(freed_coap_msg_ptr->options_list_ptr->uri_query_ptr); + } + + if (freed_coap_msg_ptr->options_list_ptr->block2_ptr != NULL) { + free(freed_coap_msg_ptr->options_list_ptr->block2_ptr); + } + + if (freed_coap_msg_ptr->options_list_ptr->block1_ptr != NULL) { + free(freed_coap_msg_ptr->options_list_ptr->block1_ptr); + } + if (freed_coap_msg_ptr->options_list_ptr->accept_ptr != NULL) { + free(freed_coap_msg_ptr->options_list_ptr->accept_ptr); + } + + free(freed_coap_msg_ptr->options_list_ptr); + } + + free(freed_coap_msg_ptr); + freed_coap_msg_ptr = NULL; + } +} diff --git a/test/coap-service/unittest/stub/sn_coap_parser_stub.h b/test/coap-service/unittest/stub/sn_coap_parser_stub.h new file mode 100644 index 0000000000..eb6f13b162 --- /dev/null +++ b/test/coap-service/unittest/stub/sn_coap_parser_stub.h @@ -0,0 +1,13 @@ + +#ifndef __SN_COAP_PARSER_STUB_H__ +#define __SN_COAP_PARSER_STUB_H__ + +#include "sn_coap_header.h" + +typedef struct { + sn_coap_hdr_s *expectedHeader; +} sn_coap_parser_def; + +extern sn_coap_parser_def sn_coap_parser_stub; + +#endif //__SN_COAP_PARSER_STUB_H__ diff --git a/test/coap-service/unittest/stub/sn_coap_protocol_stub.c b/test/coap-service/unittest/stub/sn_coap_protocol_stub.c new file mode 100644 index 0000000000..6687e41142 --- /dev/null +++ b/test/coap-service/unittest/stub/sn_coap_protocol_stub.c @@ -0,0 +1,96 @@ +/* + * Copyright (c) 2011-2015 ARM. All rights reserved. + */ + + +#include +#include /* For libary malloc() */ +#include /* For memset() and memcpy() */ +#ifdef __linux__ +#include +#endif + +#include "ns_types.h" +#include "sn_nsdl.h" +#include "sn_coap_protocol.h" +#include "sn_coap_header_internal.h" +#include "sn_coap_protocol_internal.h" +#include "sn_coap_protocol_stub.h" + +uint16_t sn_coap_block_data_size = 0; + +uint8_t sn_coap_resending_queue_msgs = 0; +uint8_t sn_coap_resending_queue_bytes = 0; +uint8_t sn_coap_resending_count = 0; +uint8_t sn_coap_resending_intervall = 0; + +uint8_t sn_coap_duplication_buffer_size = 0; + +sn_coap_protocol_stub_def sn_coap_protocol_stub; + +int8_t sn_coap_protocol_destroy(struct coap_s *handle) +{ + return sn_coap_protocol_stub.expectedInt8; +} + +struct coap_s *sn_coap_protocol_init(void *(*used_malloc_func_ptr)(uint16_t), void (*used_free_func_ptr)(void *), + uint8_t (*used_tx_callback_ptr)(uint8_t *, uint16_t, sn_nsdl_addr_s *, void *), + int8_t (*used_rx_callback_ptr)(sn_coap_hdr_s *, sn_nsdl_addr_s *, void *param)) +{ + if( sn_coap_protocol_stub.expectedCoap ){ + sn_coap_protocol_stub.expectedCoap->sn_coap_protocol_free = used_free_func_ptr; + sn_coap_protocol_stub.expectedCoap->sn_coap_protocol_malloc = used_malloc_func_ptr; + sn_coap_protocol_stub.expectedCoap->sn_coap_rx_callback = used_rx_callback_ptr; + sn_coap_protocol_stub.expectedCoap->sn_coap_tx_callback = used_tx_callback_ptr; + } + return sn_coap_protocol_stub.expectedCoap; +} + +int8_t sn_coap_protocol_set_block_size(uint16_t block_size) +{ + return sn_coap_protocol_stub.expectedInt8; +} + +int8_t sn_coap_protocol_set_duplicate_buffer_size(uint8_t message_count) +{ + return sn_coap_protocol_stub.expectedInt8; +} + +int8_t sn_coap_protocol_set_retransmission_parameters(uint8_t resending_count, uint8_t resending_intervall) +{ + return sn_coap_protocol_stub.expectedInt8; +} + +int8_t sn_coap_protocol_set_retransmission_buffer(uint8_t buffer_size_messages, uint16_t buffer_size_bytes) +{ + return sn_coap_protocol_stub.expectedInt8; +} + +void sn_coap_protocol_clear_retransmission_buffer(struct coap_s *handle) +{ +} + + +int16_t sn_coap_protocol_build(struct coap_s *handle, sn_nsdl_addr_s *dst_addr_ptr, + uint8_t *dst_packet_data_ptr, sn_coap_hdr_s *src_coap_msg_ptr, void *param) +{ + //TODO: check if needed here + src_coap_msg_ptr->msg_id = 2; + return sn_coap_protocol_stub.expectedInt16; +} + +sn_coap_hdr_s *sn_coap_protocol_parse(struct coap_s *handle, sn_nsdl_addr_s *src_addr_ptr, uint16_t packet_data_len, uint8_t *packet_data_ptr, void *param) +{ + return sn_coap_protocol_stub.expectedHeader; +} + +int8_t sn_coap_protocol_exec(struct coap_s *handle, uint32_t current_time) +{ + return sn_coap_protocol_stub.expectedInt8; +} + +coap_send_msg_s *sn_coap_protocol_allocate_mem_for_msg(struct coap_s *handle, sn_nsdl_addr_s *dst_addr_ptr, uint16_t packet_data_len) +{ + return sn_coap_protocol_stub.expectedSendMsg; +} + diff --git a/test/coap-service/unittest/stub/sn_coap_protocol_stub.h b/test/coap-service/unittest/stub/sn_coap_protocol_stub.h new file mode 100644 index 0000000000..73f10d6987 --- /dev/null +++ b/test/coap-service/unittest/stub/sn_coap_protocol_stub.h @@ -0,0 +1,18 @@ + +#ifndef __SN_COAP_PROTOCOL_STUB_H__ +#define __SN_COAP_PROTOCOL_STUB_H__ + +#include "sn_coap_header_internal.h" +#include "sn_coap_protocol_internal.h" + +typedef struct { + int8_t expectedInt8; + int16_t expectedInt16; + struct coap_s *expectedCoap; + sn_coap_hdr_s *expectedHeader; + coap_send_msg_s *expectedSendMsg; +} sn_coap_protocol_stub_def; + +extern sn_coap_protocol_stub_def sn_coap_protocol_stub; + +#endif //__SN_COAP_PROTOCOL_STUB_H__ diff --git a/test/coap-service/unittest/stub/socket_api_stub.c b/test/coap-service/unittest/stub/socket_api_stub.c new file mode 100644 index 0000000000..62304deb1b --- /dev/null +++ b/test/coap-service/unittest/stub/socket_api_stub.c @@ -0,0 +1,118 @@ +/* + * Copyright (c) 2015 ARM Limited. All rights reserved. + */ +#include "socket_api.h" +#include "socket_api_stub.h" + +socket_api_stub_data_t socket_api_stub; + +int8_t socket_raw_open(void (*passed_fptr)(void *)) +{ + if( socket_api_stub.counter >= 0){ + return socket_api_stub.values[socket_api_stub.counter--]; + } + + return socket_api_stub.int8_value; +} +int8_t socket_open(uint8_t protocol, uint16_t identifier, void (*passed_fptr)(void *)) +{ + socket_api_stub.recv_cb = passed_fptr; + if( socket_api_stub.counter >= 0){ + return socket_api_stub.values[socket_api_stub.counter--]; + } + + return socket_api_stub.int8_value; +} + +int8_t socket_free(int8_t socket) +{ + if( socket_api_stub.counter >= 0){ + return socket_api_stub.values[socket_api_stub.counter--]; + } + + return socket_api_stub.int8_value; +} +int8_t socket_listen(int8_t socket) +{ + if( socket_api_stub.counter >= 0){ + return socket_api_stub.values[socket_api_stub.counter--]; + } + + return socket_api_stub.int8_value; +} +int8_t socket_connect(int8_t socket, ns_address_t *address, uint8_t randomly_take_src_number) +{ + if( socket_api_stub.counter >= 0){ + return socket_api_stub.values[socket_api_stub.counter--]; + } + + return socket_api_stub.int8_value; +} +int8_t socket_bind(int8_t socket, const ns_address_t *address) +{ + if( socket_api_stub.counter >= 0){ + return socket_api_stub.values[socket_api_stub.counter--]; + } + + return socket_api_stub.int8_value; +} +int8_t socket_close(int8_t socket, ns_address_t *address) +{ + if( socket_api_stub.counter >= 0){ + return socket_api_stub.values[socket_api_stub.counter--]; + } + + return socket_api_stub.int8_value; +} +int8_t socket_send(int8_t socket, uint8_t *buffer, uint16_t length) +{ + if( socket_api_stub.counter >= 0){ + return socket_api_stub.values[socket_api_stub.counter--]; + } + + return socket_api_stub.int8_value; +} +int16_t socket_read(int8_t socket, ns_address_t *address, uint8_t *buffer, uint16_t length) +{ + if( address ){ + memset(&address->address, 0, 16); + address->identifier = 0; + } + if( socket_api_stub.counter >= 0){ + return socket_api_stub.values[socket_api_stub.counter--]; + } + + return socket_api_stub.int8_value; +} +int8_t socket_sendto(int8_t socket, ns_address_t *address, uint8_t *buffer, uint16_t length) +{ + if( socket_api_stub.counter >= 0){ + return socket_api_stub.values[socket_api_stub.counter--]; + } + + return socket_api_stub.int8_value; +} +int8_t socket_read_session_address(int8_t socket, ns_address_t *address) +{ + if( socket_api_stub.counter >= 0){ + return socket_api_stub.values[socket_api_stub.counter--]; + } + + return socket_api_stub.int8_value; +} +int8_t socket_setsockopt(int8_t socket, uint8_t level, uint8_t opt_name, const void *opt_value, uint16_t opt_len) +{ + if( socket_api_stub.counter >= 0){ + return socket_api_stub.values[socket_api_stub.counter--]; + } + + return socket_api_stub.int8_value; +} +int8_t socket_getsockopt(int8_t socket, uint8_t level, uint8_t opt_name, void *opt_value, uint16_t *opt_len) +{ + if( socket_api_stub.counter >= 0){ + return socket_api_stub.values[socket_api_stub.counter--]; + } + + return socket_api_stub.int8_value; +} diff --git a/test/coap-service/unittest/stub/socket_api_stub.h b/test/coap-service/unittest/stub/socket_api_stub.h new file mode 100644 index 0000000000..195d5eb86f --- /dev/null +++ b/test/coap-service/unittest/stub/socket_api_stub.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2015 ARM Limited. All rights reserved. + */ +#ifndef __SOCKET_API_STUB_H__ +#define __SOCKET_API_STUB_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "stdint.h" + +typedef struct { + void (*recv_cb)(void *); + int8_t int8_value; + int counter; + int values[10]; +} socket_api_stub_data_t; + +extern socket_api_stub_data_t socket_api_stub; + +#ifdef __cplusplus +} +#endif + +#endif //__SOCKET_API_STUB_H__ + + + + + diff --git a/test/coap-service/unittest/stub/socket_stub.c b/test/coap-service/unittest/stub/socket_stub.c new file mode 100644 index 0000000000..f67c261bde --- /dev/null +++ b/test/coap-service/unittest/stub/socket_stub.c @@ -0,0 +1,93 @@ +/* + * Copyright (c) 2015 ARM Limited. All rights reserved. + */ +#include +#include +#include "socket.h" +#include "ns_error_types.h" +#include "buffer.h" +#include "socket.h" +#include "sec_lib_definitions.h" +#include "tcp.h" +#include "socket_stub.h" + +NS_LARGE socket_t socket_instance[SOCKETS_MAX] = {0}; +socket_stub_data_t socket_stub_data = { + 0, // socket_id + eOK // err code +}; + +inet_pcb_t inet_pcb[SOCKETS_MAX]; + +static buffer_t stub_socket_buffer = {0}; + +socket_stub_data_t *socket_stub_get_test_data(void) +{ + socket_stub_clear_sockets(); + socket_stub_data.socket_id = 0; + socket_stub_data.err = eOK; + return &socket_stub_data; +} + +void socket_stub_clear_sockets() +{ + int i; + for (i = 0; i < SOCKETS_MAX; i++) { + memset(&socket_instance[i], 0, sizeof(socket_t)); + memset(&inet_pcb[i], 0, sizeof(inet_pcb_t)); + } +} + +void socket_init(void) +{ +} + +error_t socket_release(int8_t sid) +{ + return socket_stub_data.err; +} + +error_t socket_port_validate(uint16_t port, uint8_t socket_type) +{ + return socket_stub_data.err; +} + +error_t socket_create(int8_t *sid, uint16_t port, uint8_t type, void (*passed_fptr)(void *), uint8_t buffer_type) +{ + if (eOK == socket_stub_data.err) { + *sid = socket_stub_data.socket_id; + socket_instance[socket_stub_data.socket_id].type = type; + socket_instance[socket_stub_data.socket_id].fptr = passed_fptr; + socket_instance[socket_stub_data.socket_id].inet_pcb = &inet_pcb[socket_stub_data.socket_id]; + } + return socket_stub_data.err; +} + +int8_t socket_buffer_sendto(int8_t sid, buffer_t *buf) +{ + return 0; +} + +buffer_t *socket_buffer_read(int8_t sid) +{ + return &stub_socket_buffer; +} + +void *socket_event_session_read(int8_t sid) +{ + return NULL; +} + +void socket_set_buffer_hop_limit(int8_t sid, buffer_t *buf) +{ +} + +struct protocol_interface_info_entry *socket_interface_determine(int8_t socket_id, buffer_t *buf) { + return NULL; +} + +buffer_t *socket_tx_buffer_check(buffer_t *buf, uint8_t status) +{ + return NULL; +} + diff --git a/test/coap-service/unittest/stub/socket_stub.h b/test/coap-service/unittest/stub/socket_stub.h new file mode 100644 index 0000000000..f5ce0e2b36 --- /dev/null +++ b/test/coap-service/unittest/stub/socket_stub.h @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2015 ARM Limited. All rights reserved. + */ +#ifndef __SOCKET_STUB_H__ +#define __SOCKET_STUB_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "stdint.h" + +typedef struct { + uint8_t socket_id; // socket id returned when socket created + error_t err; // socket error returned by the socket call +} socket_stub_data_t; + +socket_stub_data_t *socket_stub_get_test_data(void); + +#ifdef __cplusplus +} +#endif + +#endif //__SOCKET_STUB_H__ diff --git a/test/coap-service/unittest/stub/system_timer_stub.c b/test/coap-service/unittest/stub/system_timer_stub.c new file mode 100644 index 0000000000..2cb47185d9 --- /dev/null +++ b/test/coap-service/unittest/stub/system_timer_stub.c @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2014-2015 ARM Limited. All rights reserved. + */ +#include "ns_types.h" +#include "timer_sys.h" +#include "platform/arm_hal_interrupt.h" +#include "platform/ns_debug.h" +#include "ns_timer.h" +#include "nsdynmemLIB.h" +#include "eventOS_event.h" +#include "eventOS_callback_timer.h" + +#ifndef ST_MAX +#define ST_MAX 6 +#endif + +#define TIMER_SYS_TICK_PERIOD 100 + +void timer_sys_init(void) +{ +} + +void timer_sys_disable(void) +{ + +} + +int8_t timer_sys_wakeup(void) +{ + return 0; +} + +uint32_t timer_get_runtime_ticks(void) // only used in dev_stats_internal.c +{ + return 0; +} + + + +int8_t eventOS_event_timer_request(uint8_t snmessage, uint8_t event_type, int8_t tasklet_id, uint32_t time) +{ + return -1; +} + +int8_t eventOS_event_timer_cancel(uint8_t snmessage, int8_t tasklet_id) +{ + return -1; +} + + +uint32_t eventOS_event_timer_shortest_active_timer(void) +{ + return 0; +} + +void system_timer_tick_update(uint32_t ticks) +{ +} + diff --git a/test/coap-service/unittest/stub/tcp_stub.c b/test/coap-service/unittest/stub/tcp_stub.c new file mode 100644 index 0000000000..7b29a331a6 --- /dev/null +++ b/test/coap-service/unittest/stub/tcp_stub.c @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2015 ARM Limited. All rights reserved. + */ +#include +#include +#include "net_interface.h" +#include "buffer.h" +#include "sec_lib_definitions.h" +#include "tcp.h" + +static tcp_session_t stub_tcp_session; + +void tcp_segment_init(tcp_session_t *tcp_info, buffer_t *buf) +{ +} + +tcp_error tcp_close(tcp_session_t *tcp_session, uint8_t close_tls) +{ + return TCP_ERROR_NO_ERROR; +} + +tcp_session_t *tcp_session_ptr_allocate(uint8_t socket_id) +{ + + return &stub_tcp_session; +} + +tcp_session_t *tcp_session_ptr_get(sockaddr_t *addr_ptr, uint8_t socket_id) +{ + return &stub_tcp_session; +} + +int8_t tcp_session_removed(tcp_session_t *cur) +{ + return 0; +} + +tcp_error tcp_socket_connect(tcp_session_t *tcp_session, sockaddr_t *dst_addr) +{ + return TCP_ERROR_NO_ERROR; +} + +int8_t tcp_socket_tx_check(tcp_session_t *tcp_info) +{ + return 0; +} + +buffer_t *tcp_tls_encrypt(buffer_t *buf, uint8_t socket_id) +{ + return NULL; +} + +tcp_error tcp_socket_close(tcp_session_t *tcp_session) { + return TCP_ERROR_NO_ERROR; +} + diff --git a/test/coap-service/unittest/stub/thread_beacon_stub.c b/test/coap-service/unittest/stub/thread_beacon_stub.c new file mode 100644 index 0000000000..374e479a3c --- /dev/null +++ b/test/coap-service/unittest/stub/thread_beacon_stub.c @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2015 ARM. All rights reserved. + */ + +#include "config.h" + +#include "thread_beacon.h" +#include "thread_config.h" +#include "common_functions.h" +#include "thread_meshcop_lib.h" +#include +#include "ns_trace.h" +/*service lib includes */ +#include "Service_Libs/utils/crc.h" +#define TRACE_GROUP "Tbcn" + +#define THREAD_BEACON_VERSION_SHIFT 4 +#define THREAD_BEACON_JOINING_PERMITTED_BIT 0x01 +#define THREAD_BEACON_NATIVE_COMMISSIONER_BIT 0x08 + +int thread_beacon_get_protocol(uint8_t *data_ptr, uint8_t data_len) +{ + return 0; +} +int thread_beacon_get_protocol_version(uint8_t *data_ptr, uint8_t data_len) +{ + return 0; +} +uint16_t thread_beacon_get_joiner_port(uint8_t *data_ptr, uint8_t data_len) +{ + return 0; +} + +uint16_t thread_beacon_get_commissioning_port(uint8_t *data_ptr, uint8_t data_len) +{ + return 0; +} +bool thread_beacon_native_commissioning_allowed(uint8_t *data_ptr, uint8_t data_len) +{ + return false; +} +bool thread_beacon_joining_permitted(uint8_t *data_ptr, uint8_t data_len) +{ + return false; +} + +int thread_beacon_get_name(uint8_t *data_ptr, uint8_t data_len, uint8_t *result_ptr) +{ + return 16; +} +int thread_beacon_get_xpanid(uint8_t *data_ptr, uint8_t data_len, uint8_t *result_ptr) +{ + return 8; +} +uint8_t *thread_beacon_get_steering_data(uint8_t *data_ptr, uint8_t data_len,uint8_t *result_length) +{ + return NULL; +} + + +uint8_t *thread_beacon_calculate_bloom_filter(uint8_t *bloom_filter_ptr,uint8_t bloom_filter_length, uint8_t *joiner_id_ptr, int joiner_id_length) +{ + return NULL; +} + diff --git a/test/coap-service/unittest/stub/thread_bootstrap_stub.c b/test/coap-service/unittest/stub/thread_bootstrap_stub.c new file mode 100644 index 0000000000..0d9ea54bea --- /dev/null +++ b/test/coap-service/unittest/stub/thread_bootstrap_stub.c @@ -0,0 +1,248 @@ +/* + * Copyright (c) 2014-2015 ARM Limited. All rights reserved. + */ + +/* + * \file thread_bootstrap.c + * \brief Add short description about this file!!! + * + */ +#include "config.h" +#include +#include +#include +#include "eventOS_event.h" +#include "eventOS_event_timer.h" +#include "randLIB.h" +#include "common_functions.h" +#include "NWK_INTERFACE/Include/protocol.h" +#include "net_thread_test.h" +#include "libDHCPv6/libDHCPv6.h" +#include "libDHCPv6/libDHCPv6_server.h" +#include "ns_trace.h" +#include "6LoWPAN/Bootstraps/protocol_6lowpan.h" +#include "6LoWPAN/Thread/thread.h" +#include "6LoWPAN/Thread/thread_routing.h" +#include "6LoWPAN/Thread/thread_nd.h" +#include "6LoWPAN/Thread/thread_bootstrap.h" +#include "6LoWPAN/Thread/thread_routerid_server.h" +#include "6LoWPAN/Thread/thread_management_internal.h" +#include "6LoWPAN/Thread/thread_dynamic_reed.h" +#include "6LoWPAN/Thread/thread_joiner_application.h" +#include "MAC/IEEE802_15_4/mac_data_interface.h" +#include "MAC/IEEE802_15_4/mac_security_interface.h" +#include "MAC/IEEE802_15_4/mac_data_poll.h" +#include "MAC/IEEE802_15_4/mac_mlme.h" +#include "thread_management_if.h" +#include "Common_Protocols/ipv6.h" +#include "Common_Protocols/icmpv6.h" +#include "Common_Protocols/icmpv6_radv.h" +#include "MLE/mle.h" +#include "dhcp_service_api.h" +#include "thread_dhcpv6_client.h" + + +#define TRACE_GROUP "thbs" + +void threa_ula_address_generate_and_push_to_stack(protocol_interface_info_entry_t *cur); +int thread_bootstrap_reset(protocol_interface_info_entry_t *cur); +static void thread_mle_challenge_trig(int8_t interface_id, uint8_t *LinkId); + +void thread_bootstrap_attached_active_router(protocol_interface_info_entry_t *cur); +void thread_attach_router_id_request(protocol_interface_info_entry_t *cur); +void thread_bootstrap_attached_finish(protocol_interface_info_entry_t *cur); +void thread_bootstrap_child_id_handler(protocol_interface_info_entry_t *cur); +void thread_attach_router_id_release_done(protocol_interface_info_entry_t *cur); +void thread_attach_router_id_release(protocol_interface_info_entry_t *cur); + +int8_t nwk_thread_host_control(protocol_interface_info_entry_t *cur, net_host_mode_t mode) +{ + return 0; +} + +int thread_link_configuration_activate(protocol_interface_info_entry_t *cur, link_configuration_s *linkConfiguration) +{ + return 0; +} + +void thread_interface_init(protocol_interface_info_entry_t *cur) +{ +} + +void thread_tasklet(arm_event_s *event) +{ +} + +int thread_bootstrap_tasklet_init(protocol_interface_info_entry_t *cur) +{ + return 0; +} + +void thread_clean_old_16_bit_address_based_addresses(protocol_interface_info_entry_t *cur) +{ +} + + +void thread_bootstrap_ready(protocol_interface_info_entry_t *cur) +{ +} + +int thread_leader_configure_init(protocol_interface_info_entry_t *cur) +{ + return 0; +} + +int thread_bootstrap_attach_start(int8_t nwk_interface_id, thread_bootsrap_state_type_e state) +{ + return 0; +} + +void thread_bootstrap_leader_data_free(thread_info_t *thread_info, int8_t bootstrap) +{ +} + +void thread_bootsrap_generate_thread_partitition(int8_t interface_id, bool newPartition) +{ +} + +void thread_bootstrap_generate_leader_and_link(int8_t interface_id) +{ +} + +void thread_bootstrap_connection_error(int8_t interface_id, nwk_connect_error_types errorType, uint8_t *LinkId) +{ +} + +void thread_bootsrap_router_id_cb(int8_t interface_id, uint8_t *ml16_address, uint8_t router_id, const uint8_t *router_mask_ptr) +{ +} + +void thread_interface_up(protocol_interface_info_entry_t *cur) +{ +} + +int thread_bootstrap_reset(protocol_interface_info_entry_t *cur) +{ + return 0; +} + +void thread_network_attach_start(protocol_interface_info_entry_t *cur) +{ +} + +void threa_ula_address_generate_and_push_to_stack(protocol_interface_info_entry_t *cur) +{ +} + +void thread_bootstrap_attached_ready(protocol_interface_info_entry_t *cur) +{ +} + +void thread_bootstrap_attached_downgrade_router(protocol_interface_info_entry_t *cur) +{ +} + +void thread_bootstrap_attched_upgrade_reed(protocol_interface_info_entry_t *cur) +{ +} + +void thread_bootstrap_attched_active_router(protocol_interface_info_entry_t *cur) +{ +} + +void thread_bootstrap_router_id_release_ready(protocol_interface_info_entry_t *cur) +{ +} + +void thread_bootstrap_router_id_get_fail(protocol_interface_info_entry_t *cur) +{ +} + +int8_t thread_bootstrap_child_id_request(protocol_interface_info_entry_t *cur) +{ + return 0; +} + +void thread_bootstrap_child_id_handler(protocol_interface_info_entry_t *cur) +{ +} + +void thread_bootstrap_attached_active_router(protocol_interface_info_entry_t *cur) +{ +} + +void thread_bootstrap_attached_finish(protocol_interface_info_entry_t *cur) +{ +} + +void thread_attach_router_id_release(protocol_interface_info_entry_t *cur) +{ +} + + +void thread_attach_router_id_release_done(protocol_interface_info_entry_t *cur) +{ +} + +void thread_attach_router_id_request(protocol_interface_info_entry_t *cur) +{ +} + +bool thread_bootstrap_trig_reed_upgrade(protocol_interface_info_entry_t *cur) +{ + return false; +} + +bool thread_bootstrap_trig_router_downgrade(protocol_interface_info_entry_t *cur) +{ + return false; +} + +void thread_parent_scan(protocol_interface_info_entry_t *cur) +{ +} + +int thread_set_link_for_commission(protocol_interface_info_entry_t *interface, nwk_pan_descriptor_t *best) +{ + return 0; +} + +void thread_mac_active_scan_response(uint8_t *data) +{ +} + +void thread_bootstrap_state_machine(protocol_interface_info_entry_t *cur) +{ +} + +void thread_bootstrap_stop(protocol_interface_info_entry_t *cur) +{ +} + +void thread_bootstrap_address_register(protocol_interface_info_entry_t *cur) +{ +} + +void thread_bootstrap_child_update_trig(protocol_interface_info_entry_t *cur) +{ +} + +void thread_bootstrap_global_leader_data(thread_info_t *thread_info) +{ + +} + +bool thread_tlv_request(int8_t interface_id, uint8_t *address, uint8_t *req_tlv, uint8_t req_len) +{ + return false; +} + +int thread_router_mle_advertise(struct protocol_interface_info_entry *cur) +{ + return 0; +} + +uint8_t *thread_leader_data_tlv_write(uint8_t *ptr, struct thread_leader_data_s *leader_data) +{ + return NULL; +} diff --git a/test/coap-service/unittest/stub/thread_commissioning_if_stub.c b/test/coap-service/unittest/stub/thread_commissioning_if_stub.c new file mode 100644 index 0000000000..b89aedd1d3 --- /dev/null +++ b/test/coap-service/unittest/stub/thread_commissioning_if_stub.c @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2014-2015 ARM Limited. All rights reserved. + */ +#include "ns_types.h" +#include +#include +#include +#include +#include "ns_trace.h" +#include "Core/include/buffer.h" +#include "common_functions.h" +#include "NWK_INTERFACE/Include/protocol.h" +#include "6LoWPAN/Thread/thread.h" +#include "6LoWPAN/Thread/thread_management_internal.h" +#include "6LoWPAN/Thread/thread_joiner_application.h" +#include "MAC/IEEE802_15_4/mac_pairwise_key.h" +#include "MAC/IEEE802_15_4/mac_security_interface.h" + +#include "net_interface.h" // TODO remove when fixing properly +#include "thread_commissioning_if.h" +#include "randLIB.h" + +#define TRACE_GROUP "thrC" + +int thread_commissioning_if_steering_data_set(int8_t interface_id, uint8_t *buf_ptr, uint16_t length) +{ + return 0; +} + +int thread_commissioning_if_register(int8_t interface_id, uint8_t border_router_address[static 16], uint8_t *commissioner_id_ptr, uint16_t commissioner_id_len, uint16_t *session_id) +{ + return 0; +} + +bool thread_commissioning_if_session_refresh(int8_t interface_id, uint16_t session_id) +{ + return true; +} + +int thread_commissioning_if_pairwise_key_add(int8_t interface_id, uint32_t valid_life_time, uint8_t eui64[8], uint8_t key[16]) +{ + return 0; +} + +int thread_commissioning_if_pairwise_key_delete_all(int8_t interface_id) +{ + return 0; +} + +int thread_commissioning_if_border_router_locator_get(int8_t interface_id, uint8_t *address_ptr) +{ + return 0; +} + +int thread_commissioning_if_enable_security(int8_t interface_id) +{ + return 0; +} + +char* thread_commissioning_if_commissioner_id_get(int8_t interface_id) +{ + return NULL; +} +bool thread_commissioning_if_unregister(int8_t interface_id, uint16_t session_id) +{ + return true; +} diff --git a/test/coap-service/unittest/stub/thread_dhcpv6_client_stub.c b/test/coap-service/unittest/stub/thread_dhcpv6_client_stub.c new file mode 100644 index 0000000000..c0c0d26a8b --- /dev/null +++ b/test/coap-service/unittest/stub/thread_dhcpv6_client_stub.c @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2013-2015 ARM Limited. All rights reserved. + */ + +#include +#include +#include +#include "nsdynmemLIB.h" +#include "ns_list.h" +#include "common_functions.h" + + +#include "dhcp_service_api.h" +#include "thread_dhcpv6_client.h" +#include "libDHCPv6/libDHCPv6.h" +#include "NWK_INTERFACE/Include/protocol.h" +#include "6LoWPAN/Thread/thread.h" +#include "6LoWPAN/Thread/thread_bootstrap.h" + + +typedef struct { + thread_dhcp_client_global_adress_cb *global_address_cb; + uint16_t service_instance; + uint8_t libDhcp_instance; + int8_t interface; +} thread_dhcp_client_class_t; + +thread_dhcp_client_class_t dhcp_client; + +extern uint8_t *dhcpv6_vendor_code_parse_thread_router_id(uint8_t *ptr, uint16_t data_length); +void thread_dhcpv6_client_set_address(int8_t interface_id, dhcpv6_client_server_data_t *srv_data_ptr); + + +void thread_dhcp_client_init(int8_t interface) +{ +} + +void thread_dhcp_client_delete(int8_t interface) +{ +} + +void thread_dhcpv6_client_send_error_cb(dhcpv6_client_server_data_t *srv_data_ptr) +{ +} + + +/* solication responce received for either global address or routter id assignment */ +int dhcp_solicit_resp_cb(uint16_t instance_id, void *ptr, uint8_t msg_name, uint8_t *msg_ptr, uint16_t msg_len) +{ + return 0; +} + +int thread_dhcp_client_get_global_address(int8_t interface, uint8_t dhcp_addr[__static 16], uint8_t prefix[__static 16], uint8_t mac64[__static 8], thread_dhcp_client_global_adress_cb *error_cb) +{ + return 0; +} + +void thread_dhcp_client_global_address_renew(int8_t interface) +{ +} + +void thread_dhcp_client_global_address_delete(int8_t interface, uint8_t dhcp_addr[static 16], uint8_t prefix[static 16]) +{ +} + +void thread_dhcpv6_renew(protocol_interface_info_entry_t *interface, if_address_entry_t *addr, if_address_callback_t reason) +{ +} + +void thread_dhcpv6_client_set_address(int8_t interface_id, dhcpv6_client_server_data_t *srv_data_ptr) +{ +} + +uint8_t *dhcpv6_vendor_code_parse_thread_router_id(uint8_t *ptr, uint16_t data_length) +{ + return NULL; +} diff --git a/test/coap-service/unittest/stub/thread_dynamic_reed_stub.c b/test/coap-service/unittest/stub/thread_dynamic_reed_stub.c new file mode 100644 index 0000000000..7b18368432 --- /dev/null +++ b/test/coap-service/unittest/stub/thread_dynamic_reed_stub.c @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2015 ARM Limited. All rights reserved. + */ + +/* + * \file thread_dynamic_reed.c + * + */ +#include "config.h" +#include "string.h" +#include "ns_types.h" +#include "ns_trace.h" +#include "6LoWPAN/Thread/thread_dynamic_reed.h" + +bool thread_dynamic_reed_upgrade(uint8_t activeRouterCnt, uint8_t routerUpgradeThreshold) +{ + return false; +} + +bool thread_dynamic_reed_downgrade(uint8_t childCount, uint8_t goodLinkCount, uint8_t activeRouterCnt, bool possibleDefaultRouter, uint8_t routerDowngradeThreshold, uint8_t minNeighborsThreshold) +{ + return false; +} + +void thread_dynamic_reed_initialize(thread_router_select_t *routerSelect) +{ +} + +uint32_t thread_dynamic_reed_timeout_calculate(thread_router_select_t *routerSelect) +{ + return 0; +} diff --git a/test/coap-service/unittest/stub/thread_host_bootstrap_stub.c b/test/coap-service/unittest/stub/thread_host_bootstrap_stub.c new file mode 100644 index 0000000000..ae639a379f --- /dev/null +++ b/test/coap-service/unittest/stub/thread_host_bootstrap_stub.c @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2015 ARM Limited. All rights reserved. + */ + +/* + * \file thread_host_bootstrap.c + * \brief Add short description about this file!!! + * + */ + +#include "config.h" +#include +#include +#include +#include "eventOS_event.h" +#include "eventOS_event_timer.h" +#include "randLIB.h" +#include "shalib.h" +#include "common_functions.h" +#include "NWK_INTERFACE/Include/protocol.h" +#include "net_thread_test.h" +#include "ns_trace.h" +#include "6LoWPAN/Bootstraps/protocol_6lowpan.h" +#include "6LoWPAN/Thread/thread.h" +#include "6LoWPAN/Thread/thread_routing.h" +#include "6LoWPAN/Thread/thread_nd.h" +#include "6LoWPAN/Thread/thread_bootstrap.h" +#include "6LoWPAN/Thread/thread_host_bootstrap.h" +#include "6LoWPAN/Thread/thread_management_internal.h" +#include "6LoWPAN/Thread/thread_network_synch.h" +#include "6LoWPAN/Thread/thread_joiner_application.h" +#include "6LoWPAN/Thread/thread_management_internal.h" +#include "6LoWPAN/Thread/thread_management_client.h" +#include "6LoWPAN/Thread/thread_network_data_lib.h" +#include "MAC/IEEE802_15_4/mac_data_interface.h" +#include "MAC/IEEE802_15_4/mac_data_poll.h" +#include "MAC/IEEE802_15_4/mac_security_interface.h" +#include "MAC/IEEE802_15_4/mac_data_poll.h" +#include "MAC/IEEE802_15_4/mac_mlme.h" +#include "thread_management_if.h" +#include "Common_Protocols/ipv6.h" +#include "MLE/mle.h" +#include "MLE/mle_tlv.h" +#include "thread_config.h" +#include "Service_Libs/mle_service/mle_service_api.h" + +#define TRACE_GROUP "tebs" + + + +void thread_child_set_default_route(protocol_interface_info_entry_t *cur) +{ + +} + +void thread_network_attach_start(protocol_interface_info_entry_t *cur) +{ + +} + + +void thread_bootstrap_end_device_synch_finish(protocol_interface_info_entry_t *cur) +{ + +} + + +void thread_mle_parent_discover_receive_cb(int8_t interface_id, mle_message_t *mle_msg, mac_aux_security_header_t *security_headers) +{ + +} + +void thread_mle_connected_host_receive_cb(int8_t interface_id, mle_message_t *mle_msg, mac_aux_security_header_t *security_headers) +{ + +} + + +void thread_endevice_synch_start(protocol_interface_info_entry_t *cur) +{ +} + +int8_t thread_bootstrap_child_update(protocol_interface_info_entry_t *cur) +{ + return 0; +} + diff --git a/test/coap-service/unittest/stub/thread_joiner_application_stub.c b/test/coap-service/unittest/stub/thread_joiner_application_stub.c new file mode 100644 index 0000000000..4e122a3c11 --- /dev/null +++ b/test/coap-service/unittest/stub/thread_joiner_application_stub.c @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2014-2015 ARM Limited. All rights reserved. + */ + + +#include +#include "ns_list.h" +#include "ns_trace.h" +#include "nsdynmemLIB.h" +#include "common_functions.h" +#include "thread_tmfcop_lib.h" +#include "shalib.h" + +#include "thread_management_if.h" +#include "thread_config.h" +#include "thread_meshcop_lib.h" +#include "thread_commissioning_if.h" +#include "thread_joiner_application.h" + +#define TRACE_GROUP TRACE_GROUP_THREAD_JOINER_APPLICATION + +link_configuration_s *link_configuration_create(void) +{ + return NULL; +} + +void link_configuration_delete(link_configuration_s *this) +{ +} + +void link_configuration_copy(link_configuration_s *this, link_configuration_s *configuration_ptr) +{ +} + +int thread_joiner_application_init(int8_t interface_id, device_configuration_s *device_configuration_ptr, struct link_configuration *static_configuration_ptr) +{ + return 0; +} + +void thread_joiner_application_deinit(int8_t interface_id) +{ +} + +link_configuration_s *thread_joiner_application_get_config(int8_t interface_id) +{ + return NULL; +} + +int joiner_application_security_done_cb(int8_t service_id, uint8_t IID[8], uint8_t keyblock[40]) +{ + return 0; +} + +int thread_joiner_application_finalisation_cb(int8_t service_id, uint16_t msg_id, sn_coap_hdr_s *response_ptr) +{ + return 0; +} + +int thread_joiner_application_commission_start(int8_t interface_id, uint8_t parent_address[16], uint16_t port, uint16_t panid, uint8_t xpanid[8], uint8_t channel, thread_joiner_application_commission_done_cb *done_cb) +{ + return 0; +} + diff --git a/test/coap-service/unittest/stub/thread_management_api_stub.c b/test/coap-service/unittest/stub/thread_management_api_stub.c new file mode 100644 index 0000000000..87800d801a --- /dev/null +++ b/test/coap-service/unittest/stub/thread_management_api_stub.c @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2015 ARM Limited. All rights reserved. + */ + +#include +#include "thread_management_api.h" +#include "ns_types.h" +#include "sn_coap_header.h" + +int thread_management_recv_set_response_cb(int8_t service_id, uint16_t msg_id, sn_coap_hdr_s *response_ptr) +{ + return 0; +} + +int thread_management_recv_get_response_cb(int8_t service_id, uint16_t msg_id, sn_coap_hdr_s *response_ptr) +{ + return 0; +} + +int thread_management_register(int8_t interface_id) +{ + return 0; +} + +int thread_management_unregister(int8_t interface_id) +{ + return 0; +} + +int thread_management_set_security_policy(int8_t interface_id, uint8_t options, uint16_t rotation_time, management_set_response_cb *cb_ptr) +{ + return 0; +} + +int thread_management_set_steering_data(int8_t interface_id, uint8_t *steering_data_ptr, uint8_t steering_data_len, management_set_response_cb *cb_ptr) +{ + return 0; +} + +int thread_management_set_commissioning_data_timestamp(int8_t interface_id, uint64_t time, management_set_response_cb *cb_ptr) +{ + return 0; +} + +int thread_management_get(int8_t instance_id, uint8_t *fields_ptr, uint8_t fields_count, uint8_t dst_addr[static 16], management_get_response_cb *cb_ptr) +{ + return 0; +} diff --git a/test/coap-service/unittest/stub/thread_management_client_stub.c b/test/coap-service/unittest/stub/thread_management_client_stub.c new file mode 100644 index 0000000000..be78b503ec --- /dev/null +++ b/test/coap-service/unittest/stub/thread_management_client_stub.c @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2014-2015 ARM Limited. All rights reserved. + */ + + +#include +#include "ns_list.h" +#include "ns_trace.h" +#include "nsdynmemLIB.h" +#include "thread_tmfcop_lib.h" + +#include "thread_config.h" +#include "thread_management_if.h" +#include "6LoWPAN/Thread/thread_management_client.h" + +#define TRACE_GROUP TRACE_GROUP_THREAD_MANAGEMENT_CLIENT + +typedef struct thread_management { + thread_management_client_router_id_cb *router_id_cb_ptr; + thread_management_client_network_data_set_cb *network_data_set_cb_ptr; + int8_t interface_id; + int8_t coap_service_id; + ns_list_link_t link; +} thread_management_t; + + +void thread_management_client_init(int8_t interface_id) +{ +} + +void thread_management_client_delete(int8_t interface_id) +{ +} + +int thread_management_client_router_id_get(int8_t interface_id, uint8_t mac[8], uint16_t router_id, thread_management_client_router_id_cb *id_cb) +{ + return 0; +} + +int thread_management_client_router_id_release(int8_t interface_id, uint8_t mac[8], uint16_t router_id, thread_management_client_router_id_cb *id_cb) +{ + return 0; +} + +int thread_management_client_network_data_register(int8_t interface_id, uint8_t *data_ptr, uint16_t data_len, thread_management_client_network_data_set_cb *set_cb) +{ + return 0; +} + +int8_t thread_management_query_network_parameters(int8_t interface_id, uint8_t *dst_address) +{ + return 0; +} + +int8_t thread_management_send_set_network_parameters(int8_t interface_id) +{ + return 0; +} + diff --git a/test/coap-service/unittest/stub/thread_management_if_stub.c b/test/coap-service/unittest/stub/thread_management_if_stub.c new file mode 100644 index 0000000000..c328ec49d4 --- /dev/null +++ b/test/coap-service/unittest/stub/thread_management_if_stub.c @@ -0,0 +1,305 @@ +/* + * Copyright (c) 2014-2015 ARM Limited. All rights reserved. + */ +#include +#include +#include "ns_types.h" +#include +//#include "eventOS_event.h" +#include +#include +#include "ns_trace.h" +#include "Core/include/buffer.h" +#include "common_functions.h" +#include "NWK_INTERFACE/Include/protocol.h" +#include "6LoWPAN/Thread/thread.h" +#include "6LoWPAN/Thread/thread_bootstrap.h" +#include "6LoWPAN/Thread/thread_routing.h" +#include "6LoWPAN/Thread/thread_network_data_lib.h" +#include "6LoWPAN/Thread/thread_network_data_storage.h" +#include "6LoWPAN/Thread/thread_nd.h" +#include "6LoWPAN/Thread/thread_dhcpv6_client.h" +#include "6LoWPAN/Thread/thread_routerid_server.h" +#include "6LoWPAN/Thread/thread_management_internal.h" +#include "6LoWPAN/Thread/thread_joiner_application.h" +#include "MLE/mle.h" +#include "thread_management_if.h" +//#include "thread_tmf_data_if.h" +#include "thread_commissioning_if.h" +#include "shalib.h" +#include "Common_Protocols/icmpv6.h" +#include "libDHCPv6/libDHCPv6.h" +#include "libDHCPv6/libDHCPv6_server.h" +#include "DHCPv6_Server/DHCPv6_server_service.h" +#include "MAC/IEEE802_15_4/mac_security_interface.h" + +void arm_thread_private_ula_prefix_set(protocol_interface_info_entry_t *cur, const uint8_t *ula_prefix) +{ +} + +int thread_tmf_service_commision_request(int8_t commissioning_handler_id, int8_t interfaceId, uint8_t *parentLLAddressPtr) +{ + return 0; +} + +int thread_tmf_service_commision_relay_control(int8_t interfaceId, int8_t commissioning_handler_id, uint8_t *borderRouterLocator, bool enableService) +{ + return 0; +} + +int thread_management_router_select_threshold_values_set( + int8_t interface_id, + uint8_t upGradeThreshold, + uint8_t downGradeThreshold) +{ + return 0; +} + +int thread_management_node_init( + int8_t interface_id, + channel_list_s *channel_list, + device_configuration_s *device_configuration, + link_configuration_s *static_configuration) +{ + return 0; +} + + +int thread_management_get_ml16_address(int8_t interface_id, uint8_t *address_ptr) +{ + return 0; +} + +int thread_management_get_ml_prefix(int8_t interface_id, uint8_t *prefix_ptr) +{ + return 0; +} + +int thread_management_get_ml_prefix_112(int8_t interface_id, uint8_t *prefix_ptr) +{ + return 0; +} + +int thread_management_get_leader_address(int8_t interface_id, uint8_t *address_ptr) +{ + return 0; +} + +link_configuration_s *thread_management_configuration_get(int8_t interface_id) +{ + return NULL; +} + +int thread_management_security_material_set(int8_t nwk_interface_id, bool enableSecurity, uint8_t *thrMasterKey, uint32_t thrKeySequenceCounter, uint32_t thrKeyRotation) +{ + return 0; +} + +int thread_commision_data_handler(uint8_t *thrMasterKey, uint32_t thrKeySequenceCounter, uint32_t thrKeyRotation, uint8_t *meshLocalPrefix) +{ + return 0; +} + +int thread_management_commission_data_set(int8_t nwk_interface_id) +{ + return 0; +} + +int thread_management_joiner_attach_start(int8_t nwk_interface_id) +{ + return 0; +} + +uint8_t *thread_management_key_request(int8_t nwk_interface_id, uint8_t keyId, bool linkLayerKey) +{ + return NULL; +} + +uint8_t *thread_management_key_request_with_sequence(int8_t nwk_interface_id, uint8_t keyId, uint32_t keySequnce) +{ + return NULL; +} + +void thread_management_key_synch_req(int8_t nwk_interface_id, uint32_t keySequnce, bool acceptAnyCounter) +{ +} + +void thread_history_key_material_push(thread_info_t *thread_info, uint8_t *macKeyPtr, uint8_t *mleKeyPtr, uint8_t keyId) +{ +} + +void thread_security_trig_pending_key(protocol_interface_info_entry_t *cur) +{ +} + +void thread_security_next_key_generate(protocol_interface_info_entry_t *cur, uint8_t *masterKey, uint32_t keySequence) +{ +} + +int thread_management_increment_key_sequence_counter(int8_t nwk_interface_id) +{ + return 0; +} + +int thread_management_key_sequence_counter_update(int8_t nwk_interface_id, uint32_t thrKeySequenceCounter) +{ + return 0; +} + +int thread_management_add_route(int8_t interface_id, uint8_t *route_prefix_ptr, uint8_t prefix_length, bool stable_service) +{ + return 0; +} + +int thread_management_del_route(int8_t interface_id, uint8_t *route_prefix_ptr, uint8_t prefix_length) +{ + return 0; + +} + +int thread_management_add_dhcpv6_server(int8_t interface_id, uint8_t *prefix_ptr, uint8_t prefix_length, bool stable_service) +{ + return 0; +} + +int thread_management_del_dhcpv6_server(int8_t interface_id, uint8_t *prefix_ptr, uint8_t prefix_length) +{ + return 0; +} + +int thread_management_add_contexts(int8_t interface_id, uint8_t *prefix_ptr, uint8_t prefix_length, uint8_t cid, bool compress_supported) +{ + return 0; +} + +int thread_management_read_leader_ula(int8_t interface_id, uint8_t *address_buffer) +{ + return 0; +} + +int thread_management_if_beacon_payload_generate(protocol_interface_info_entry_t *cur, const link_configuration_s *linkConfiguration) +{ + return 0; +} + +int thread_management_network_data_tlv_push(protocol_interface_info_entry_t *cur, uint8_t *data_pointer, uint8_t length) +{ + return 0; +} + +int thread_management_network_data_analyze_trig(protocol_interface_info_entry_t *cur) +{ + return 0; +} + +int thread_management_network_data_register(int8_t interface_id, uint8_t *network_data_ptr, uint8_t *network_data_length, uint16_t routerId) +{ + return 0; +} + +int thread_management_publish_local_services(int8_t interface_id) +{ + return 0; +} + +int thread_management_delete_local_services(int8_t interface_id) +{ + return 0; +} + +int thread_management_remove_router_by_id(int8_t interface_id, uint8_t routerId) +{ + return 0; +} + +int thread_management_print_network_data(int8_t interface_id) +{ + return 0; +} + +int thread_on_mesh_slaac_server_add(int8_t interface_id, uint8_t *prefix_ptr, uint8_t prefix_length, bool stableData) +{ + return 0; +} + +int thread_on_mesh_slaac_delete(int8_t interface_id, uint8_t *prefix_ptr, uint8_t prefix_length) +{ + return 0; +} + +int thread_dhcpv6_server_add(int8_t interface_id, uint8_t *prefix_ptr, uint32_t max_client_cnt, bool stableData) +{ + return 0; +} + +int thread_dhcpv6_server_set_lifetime(int8_t interface_id, uint8_t *prefix_ptr, uint32_t valid_lifetime) +{ + return 0; +} + +int thread_dhcpv6_server_set_max_client(int8_t interface_id, uint8_t *prefix_ptr, uint32_t max_client_count) +{ + return 0; +} + +int thread_dhcpv6_server_set_anonymous_addressing(int8_t interface_id, uint8_t *prefix_ptr, bool anonymous) +{ + return 0; +} + +int thread_dhcpv6_server_delete(int8_t interface_id, uint8_t *prefix_ptr) +{ + return 0; +} + +uint16_t thread_management_get_my_sht_addr(int8_t interface_id) +{ + return 0; +} + +int thread_management_get_my_iid16(int8_t interface_id, uint8_t *iidPtr) +{ + return 0; +} + +int thread_management_get_my_ml_prefix(int8_t interface_id, uint8_t *prefix) +{ + return 0; +} + +/* Get my mesh local prefix /112 */ +int thread_management_get_my_ml_prefix_112(int8_t interface_id, uint8_t *prefix) +{ + return 0; +} + +int thread_management_get_my_ml16(int8_t interface_id, uint8_t *addressPtr) +{ + return 0; +} + + +int thread_management_get_current_keysequence(int8_t interface_id, uint32_t *sequencePtr) +{ + return 0; +} + +int thread_management_native_commissioner_get_connection_info(int8_t interface_id, uint8_t *address_ptr, uint16_t *port, uint8_t *PSKc_ptr) +{ + return 0; +} + +void thread_key_get(uint8_t *key, uint8_t *key_material_buf, uint32_t key_sequence_counter) +{ + +} + +int thread_management_key_sets_calc(protocol_interface_info_entry_t *cur, link_configuration_s *linkConfiguration, uint32_t thrKeySequenceCounter) +{ + return 0; +} + +void thread_security_update_from_mac(protocol_interface_info_entry_t *cur) +{ + +} diff --git a/test/coap-service/unittest/stub/thread_management_server_stub.c b/test/coap-service/unittest/stub/thread_management_server_stub.c new file mode 100644 index 0000000000..7e6b3d3b4d --- /dev/null +++ b/test/coap-service/unittest/stub/thread_management_server_stub.c @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2014-2015 ARM Limited. All rights reserved. + */ + + +#include "config.h" +#include +#include +#include +#include +#include "nsdynmemLIB.h" +#include "common_functions.h" +#include "6LoWPAN/Thread/thread_management_server.h" + +#define TRACE_GROUP "TMFs" + +#include "net_interface.h" +#include "socket_api.h" +#include "thread_config.h" +#include "thread_tmfcop_lib.h" +#include "thread_meshcop_lib.h" +#include "thread_management_if.h" +#include "thread_commissioning_if.h" +//#include "thread_tmf_data_if.h" + +int thread_management_server_init(int8_t interface_id, uint8_t *PSKd_ptr, uint8_t PSKd_len) +{ + return 0; +} + +void thread_management_server_delete(int8_t interface_id) +{ +} + +int thread_management_server_leader_init(int8_t interface_id, thread_management_server_rid_assign_cb *assign_cb, thread_management_server_rid_release_cb *release_cb) +{ + return 0; +} + +void thread_management_server_leader_deinit(int8_t interface_id) +{ +} + +void joiner_router_recv_commission_msg(void *cb_res) +{ +} + +int thread_management_server_joiner_router_init(int8_t interface_id, uint16_t *joiner_port) +{ + return 0; +} + +void thread_management_server_joiner_router_deinit(int8_t interface_id) +{ +} diff --git a/test/coap-service/unittest/stub/thread_meshcop_lib_stub.c b/test/coap-service/unittest/stub/thread_meshcop_lib_stub.c new file mode 100644 index 0000000000..853814e2a5 --- /dev/null +++ b/test/coap-service/unittest/stub/thread_meshcop_lib_stub.c @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2015 ARM Limited. All rights reserved. + */ + +#include "thread_meshcop_lib.h" +#include "common_functions.h" +#include + +uint8_t *thread_meshcop_tlv_data_write(uint8_t *ptr, uint8_t type, uint16_t length, const uint8_t *data) +{ + return NULL; +} + +uint8_t *thread_meshcop_tlv_data_write_uint8(uint8_t *ptr, uint8_t type, uint8_t data) +{ + return NULL; +} + +uint8_t *thread_meshcop_tlv_data_write_uint16(uint8_t *ptr, uint8_t type, uint16_t data) +{ + return NULL; +} +uint8_t *thread_meshcop_tlv_data_write_uint32(uint8_t *ptr, uint8_t type, uint32_t data) +{ + return NULL; +} + +uint16_t thread_meshcop_tlv_find(const uint8_t *ptr, uint16_t length, uint8_t type, uint8_t **result_ptr) +{ + return 0; + +} + +uint8_t thread_meshcop_tlv_data_get_uint8(const uint8_t *ptr, uint16_t length, uint8_t type, uint8_t *data_ptr) +{ + return 0; +} + +uint8_t thread_meshcop_tlv_data_get_uint16(const uint8_t *ptr, uint16_t length, uint8_t type, uint16_t *data_ptr) +{ + return 0; +} + +uint8_t thread_meshcop_tlv_data_get_uint32(const uint8_t *ptr, uint16_t length, uint8_t type, uint32_t *data_ptr) +{ + return 0; +} diff --git a/test/coap-service/unittest/stub/thread_nd_stub.c b/test/coap-service/unittest/stub/thread_nd_stub.c new file mode 100644 index 0000000000..cdf674edfb --- /dev/null +++ b/test/coap-service/unittest/stub/thread_nd_stub.c @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2014-2015 ARM Limited. All rights reserved. + */ + +/* + * \file thread_nd.c + * \brief Add short description about this file!!! + * + */ + +#include "config.h" +#include +#include +#include +#include "eventOS_event.h" +#include "common_functions.h" +#include "socket_api.h" +#include "Core/include/socket.h" +#include "NWK_INTERFACE/Include/protocol.h" +#include "Common_Protocols/ipv6.h" +#include "6LoWPAN/Bootstraps/protocol_6lowpan.h" +#include "net_thread_test.h" +#include "libDHCPv6/libDHCPv6.h" +#include "randLIB.h" +#include "ns_trace.h" +#include "6LoWPAN/Thread/thread.h" +#include "6LoWPAN/Thread/thread_routing.h" +#include "6LoWPAN/Thread/thread_nd.h" +#include "6LoWPAN/Thread/thread_resolution_client.h" +#include "6LoWPAN/Thread/thread_resolution_server.h" +#include "Common_Protocols/icmpv6.h" +#include "MLE/mle.h" +#include "dhcp_service_api.h" + +#define TRACE_GROUP "thdn" + +static thread_resolution_server_addr_query_cb thread_nd_address_query_lookup; + +void thread_nd_service_delete(int8_t interfaceId) +{ +} + +int thread_nd_service_activate(int8_t interfaceId) +{ + return 0; +} + +int thread_nd_service_disable(int8_t interfaceId) +{ + return 0; +} + +bool thread_nd_ns_transmit(protocol_interface_info_entry_t *cur, ipv6_neighbour_t *entry, bool unicast, uint8_t seq) +{ + return false; +} + +void thread_nd_flush_neighbour_cache_for_short_addr(protocol_interface_info_entry_t *cur, uint16_t flushee, bool children) +{ +} + +buffer_t *thread_nd_snoop(protocol_interface_info_entry_t *cur, buffer_t *buf, const sockaddr_t *ll_src, bool *bounce) +{ + return NULL; +} + +buffer_t *thread_nd_special_forwarding(protocol_interface_info_entry_t *cur, buffer_t *buf, const sockaddr_t *ll_src, bool *bounce) +{ + return NULL; +} + +buffer_t *thread_nd_icmp_handler(protocol_interface_info_entry_t *cur, buffer_t *buf, bool *bounce) +{ + return NULL; +} + +int thread_nd_address_registration(protocol_interface_info_entry_t *cur, const uint8_t *ipv6Address, uint16_t mac16, uint16_t panId, const uint8_t *mac64) +{ + return 0; +} + +int thread_nd_map_anycast_address(protocol_interface_info_entry_t *cur, uint16_t *addr16) +{ + return -1; +} diff --git a/test/coap-service/unittest/stub/thread_network_data_lib_stub.c b/test/coap-service/unittest/stub/thread_network_data_lib_stub.c new file mode 100644 index 0000000000..af9431b4b2 --- /dev/null +++ b/test/coap-service/unittest/stub/thread_network_data_lib_stub.c @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2014-2015 ARM Limited. All rights reserved. + */ +/* + * \file thread_network_data_lib.c + * \brief Add short description about this file!!! + * + */ +#include +#include +#include +#include "NWK_INTERFACE/Include/protocol.h" +#include "6LoWPAN/Thread/thread_network_data_lib.h" +#include "common_functions.h" +#include "ns_trace.h" + +#define TRACE_GROUP "tndl" + +uint8_t prefixBits_to_bytes(uint8_t prefixLenInBits) +{ + return 0; +} + +int thread_network_data_malformed_check(uint8_t *network_data_ptr, uint8_t network_data_length) +{ + return 0; +} + +int thread_network_data_sub_tlv_malformed_check(uint8_t *network_data_ptr, uint8_t network_data_length) +{ + return 0; +} + + +uint8_t *thread_nd_commission_data_write_steering_data(uint8_t *ptr, const uint8_t *steeringData, uint8_t length) +{ + return NULL; +} + +uint8_t *thread_nd_commission_data_write_commissioner_id(uint8_t *ptr, char *commissioner_id_ptr) +{ + return NULL; +} + +uint8_t *thread_nd_commission_data_write_security_policy(uint8_t *ptr, uint8_t policy) +{ + return NULL; +} + +uint8_t *thread_nd_commission_data_write_timestamp(uint8_t *ptr, uint8_t *timestamp, uint16_t tick) +{ + return NULL; +} + +uint8_t *thread_nd_commission_data_write_session_id(uint8_t *ptr, uint16_t id) +{ + return NULL; +} + +uint8_t *thread_nd_commission_data_write_network_name(uint8_t *ptr, uint8_t *name) +{ + return NULL; +} + +uint8_t *thread_nd_commission_data_write_border_router_locator(uint8_t *ptr, uint8_t *locatorML16) +{ + return NULL; +} + +uint8_t *thread_nd_commission_data_write_commissioning_credentials(uint8_t *ptr, char *crendentials, uint8_t length) +{ + return NULL; +} + +uint8_t *thread_nd_network_data_write_border_router_or_router_info(uint8_t *ptr, uint16_t routerId, uint8_t flags, bool reservedBytes) +{ + return NULL; +} + diff --git a/test/coap-service/unittest/stub/thread_network_data_storage_stub.c b/test/coap-service/unittest/stub/thread_network_data_storage_stub.c new file mode 100644 index 0000000000..7bb9bab4bf --- /dev/null +++ b/test/coap-service/unittest/stub/thread_network_data_storage_stub.c @@ -0,0 +1,287 @@ +/* + * Copyright (c) 2014-2015 ARM Limited. All rights reserved. + */ + +/* + * \file thread_network_data_storage.c + * \brief Add short description about this file!!! + * + */ + +#include +#include +#include +#include "NWK_INTERFACE/Include/protocol.h" +#include "common_functions.h" +#include "ns_trace.h" +#include "ip6string.h" +#include "6LoWPAN/Thread/thread.h" +#include "6LoWPAN/Thread/thread_network_data_lib.h" +#include "6LoWPAN/Thread/thread_network_data_storage.h" +#include "6LoWPAN/Thread/thread_dhcpv6_client.h" +#include "libDHCPv6/libDHCPv6_server.h" +#include "DHCPv6_Server/DHCPv6_server_service.h" + +#define TRACE_GROUP "thrd" + +void thread_nd_network_data_print(thread_network_data_cache_entry_t *networkData, uint16_t routerId) +{ +} + +uint8_t thread_nd_server_external_route_list_size(thread_network_server_data_list_t *list, bool stable) +{ + return 0; +} + +uint8_t thread_nd_border_routerserver_list_size(thread_network_server_data_list_t *list, bool stable) +{ + return 0; +} + +uint8_t thread_nd_context_list_size(thread_data_context_list_t *list, bool stable) +{ + return 0; +} + +uint8_t *thread_nd_context_list_write(thread_data_context_list_t *list, uint8_t *dataPtr, bool stableData) +{ + return NULL; +} + +uint8_t *thread_nd_server_list_write(thread_network_server_data_list_t *list, uint8_t *dataPtr, uint8_t type, bool stable) +{ + return NULL; +} + +uint8_t thread_nd_prefix_based_on_list_entry_size(thread_network_service_entry_t *entry, bool fullList) +{ + return 0; +} + +int thread_nd_local_data_length_updated(thread_network_data_cache_entry_t *networkDataList) +{ + return 0; +} + + +thread_network_local_data_entry_t *thread_local_service_list_allocate(thread_prefix_tlv_t *prefixTlv) +{ + return NULL; +} + +thread_network_service_entry_t *thread_prefix_service_list_allocate(thread_prefix_tlv_t *prefixTlv) +{ + return NULL; +} + +thread_network_server_data_entry_t *thread_server_list_allocate(thread_border_router_tlv_entry_t *service) +{ + return NULL; +} + +thread_network_data_context_entry_t *thread_context_service_list_allocate(uint8_t contextLength, uint8_t cid, bool compersioEnabled) +{ + return NULL; +} + +int thread_nd_verify_contex_id_is_free(thread_network_data_cache_entry_t *list, uint8_t *prefixPtr, thread_network_local_data_context_entry_t *context) +{ + return 0; +} + +thread_network_local_data_entry_t *thread_get_local_prefix_entry(thread_network_local_data_list_t *list, thread_prefix_tlv_t *prefixTlv) +{ + return NULL; +} + +thread_network_local_data_entry_t *thread_get_local_prefix_list(thread_network_local_data_list_t *list, thread_prefix_tlv_t *prefixTlv) +{ + return NULL; +} + +thread_network_service_entry_t *thread_get_main_prefix_entry(thread_network_servive_list_t *list, thread_prefix_tlv_t *prefixTlv) +{ + return NULL; +} + +thread_network_service_entry_t *thread_get_main_prefix_list(thread_network_servive_list_t *list, thread_prefix_tlv_t *prefixTlv) +{ + return NULL; +} + +thread_network_server_data_entry_t *thread_search_server_list(thread_network_server_data_list_t *list, uint8_t routerId) +{ + return NULL; +} + +thread_network_server_data_entry_t *thread_get_server_list(thread_network_server_data_list_t *list, thread_border_router_tlv_entry_t *service) +{ + return NULL; +} + + +uint8_t thread_get_context_id_by_length(thread_data_context_list_t *list, uint8_t contextLength) +{ + return 0; +} + +thread_network_data_context_entry_t *thread_get_context_by_id(thread_data_context_list_t *list, uint8_t cid) +{ + return NULL; +} + +thread_network_data_context_entry_t *thread_get_main_context_list(thread_data_context_list_t *list, thread_network_local_data_context_entry_t *context) +{ + return NULL; +} + +void thread_server_list_free(thread_network_server_data_list_t *listPtr) +{ +} + +int threah_server_context_delete_mark(thread_data_context_list_t *listPtr) +{ + return 0; +} + +int threah_server_data_delete_mark_by_router_id(thread_network_server_data_list_t *listPtr, uint16_t routerID, bool subSet) +{ + return 0; +} + +int threah_server_context_clean(thread_network_data_cache_entry_t *cachePtr, thread_data_context_list_t *listPtr, thread_network_service_entry_t *prefixEntry) +{ + return 0; +} + + +void threah_server_data_clean_by_router_id(thread_network_data_cache_entry_t *cachePtr, thread_network_server_data_list_t *listPtr, thread_network_service_entry_t *prefixEntry, bool routeInfo, protocol_interface_info_entry_t *curInterface) +{ +} + +void thread_context_service_list_free(thread_data_context_list_t *listPtr) +{ +} +void thread_network_data_base_init(thread_network_data_cache_entry_t *cachePtr) +{ +} + +void thread_network_local_server_data_base_init(thread_network_local_data_cache_entry_t *cachePtr) +{ +} + +void thread_network_data_router_id_mark_delete(thread_network_data_cache_entry_t *cachePtr, uint16_t routerID, bool subSet) +{ +} + +void thread_network_data_router_id_free(thread_network_data_cache_entry_t *cachePtr, bool subSet, protocol_interface_info_entry_t *curInterface) +{ +} + +void thread_network_data_context_re_use_timer_update(thread_network_data_cache_entry_t *cachePtr, uint32_t ticks) +{ + +} + +void thread_network_data_free_and_clean(thread_network_data_cache_entry_t *cachePtr) +{ +} + +void thread_network_local_data_free_and_clean(thread_network_local_data_cache_entry_t *cachePtr, int8_t interface_id) +{ +} + +int thread_nd_local_list_add_route(thread_network_data_cache_entry_t *networkDataList, thread_prefix_tlv_t *prefixTlv, thread_border_router_tlv_entry_t *route) +{ + return 0; +} + +int thread_nd_local_list_add_on_mesh_prefix(thread_network_data_cache_entry_t *networkDataList, thread_prefix_tlv_t *prefixTlv, thread_border_router_tlv_entry_t *service) +{ + return 0; +} + +int thread_nd_local_list_del_on_mesh_server(thread_network_data_cache_entry_t *networkDataList, thread_prefix_tlv_t *prefixTlv, thread_border_router_tlv_entry_t *service) +{ + return 0; +} + +int thread_local_server_list_add_on_mesh_server(thread_network_local_data_cache_entry_t *networkDataList, thread_prefix_tlv_t *prefixTlv, thread_border_router_tlv_entry_t *service) +{ + return 0; +} + +int thread_local_server_list_del_on_mesh_server(thread_network_local_data_cache_entry_t *networkDataList, thread_prefix_tlv_t *prefixTlv, bool slaacService) +{ + return 0; +} + +int thread_local_server_add_route(thread_network_local_data_cache_entry_t *networkDataList, thread_prefix_tlv_t *prefixTlv, thread_border_router_tlv_entry_t *route) +{ + return 0; +} + +int thread_local_server_del_route(thread_network_local_data_cache_entry_t *networkDataList, thread_prefix_tlv_t *prefixTlv) +{ + return 0; +} + +uint8_t thread_nd_context_id_allocate(thread_network_data_cache_entry_t *networkDataList, thread_network_local_data_cache_entry_t *localDataList, uint8_t *prefixPtr, uint8_t prefixLength) +{ + return 0; +} + +int thread_nd_local_list_add_contexts(thread_network_data_cache_entry_t *networkDataList, thread_prefix_tlv_t *prefixTlv, thread_network_local_data_context_entry_t *context) +{ + return 0; +} + +uint8_t thread_server_prefix_length(thread_network_local_data_entry_t *cur) +{ + return 0; +} + +uint16_t thread_nd_own_service_list_data_size(thread_network_local_data_cache_entry_t *serverDataList) +{ + return 0; +} + +uint8_t * thread_nd_own_service_list_data_write(thread_network_local_data_cache_entry_t *serverDataList, uint8_t *ptr, uint16_t routerID) +{ + return NULL; +} + +uint16_t thread_nd_data_size(thread_network_data_cache_entry_t *networkDataList, bool fullList) +{ + return 0; +} + +int thread_nd_commission_data_len_update(thread_network_data_cache_entry_t *networkDataList, link_configuration_s *linkConfiguration, thread_commissioner_t *registered_commissioner) +{ + return 0; +} + +uint8_t thread_nd_commission_data_length_size(link_configuration_s *linkConfiguration, thread_commissioner_t *registered_commissioner) +{ + return 0; +} + +uint8_t *thread_nd_commission_data_write(uint8_t *ptr, link_configuration_s *linkConfiguration, thread_commissioner_t *registered_commissioner) +{ + return NULL; +} + +bool thread_check_network_data_prefix_stable_boolean(thread_network_service_entry_t *dataList) +{ + return false; +} + +uint8_t *thread_nd_generate_from_local_data_list(thread_network_data_cache_entry_t *networkDataList, link_configuration_s *linkConfiguration, thread_commissioner_t *registered_commissioner, uint8_t *ptr, bool fullList) +{ + return NULL; +} + +uint8_t *thread_nd_generate_from_local_data_list_to_sleepy_child(thread_network_data_cache_entry_t *networkDataList, struct link_configuration *linkConfiguration, struct thread_commissioner *registered_commissioner, uint8_t *ptr, bool fullList) +{ + return NULL; +} diff --git a/test/coap-service/unittest/stub/thread_network_synch_stub.c b/test/coap-service/unittest/stub/thread_network_synch_stub.c new file mode 100644 index 0000000000..0d15993ac5 --- /dev/null +++ b/test/coap-service/unittest/stub/thread_network_synch_stub.c @@ -0,0 +1,21 @@ +#include + +int thread_network_synch_data_store(int8_t interface_id) +{ + return 0; +} + +int thread_network_synch_start(int8_t interface_id) +{ + return 0; +} + +int thread_network_synch_data_free(int8_t interface_id) +{ + return 0; +} + +uint16_t thread_network_synch_get_strored_mac16(int8_t interface_id) +{ + return 0; +} diff --git a/test/coap-service/unittest/stub/thread_router_bootstrap_stub.c b/test/coap-service/unittest/stub/thread_router_bootstrap_stub.c new file mode 100644 index 0000000000..0cb9f81eed --- /dev/null +++ b/test/coap-service/unittest/stub/thread_router_bootstrap_stub.c @@ -0,0 +1,137 @@ +/* + * Copyright (c) 2015 ARM Limited. All rights reserved. + */ + +/* + * \file thread_router_bootstrap.c + * \brief Add short description about this file!!! + * + */ +#include "config.h" +#include +#include +#include +#include "eventOS_event.h" +#include "eventOS_event_timer.h" +#include "randLIB.h" +#include "shalib.h" +#include "common_functions.h" +#include "NWK_INTERFACE/Include/protocol.h" +#include "MulticastTrigle/multicast.h" +#include "net_thread_test.h" +#include "ns_trace.h" +#include "6LoWPAN/Bootstraps/protocol_6lowpan.h" +#include "6LoWPAN/Thread/thread.h" +#include "6LoWPAN/Thread/thread_routing.h" +#include "6LoWPAN/Thread/thread_nd.h" +#include "6LoWPAN/Thread/thread_bootstrap.h" +#include "6LoWPAN/Thread/thread_router_bootstrap.h" +#include "6LoWPAN/Thread/thread_routerid_server.h" +#include "6LoWPAN/Thread/thread_management_internal.h" +#include "6LoWPAN/Thread/thread_network_synch.h" +#include "6LoWPAN/Thread/thread_dynamic_reed.h" +#include "6LoWPAN/Thread/thread_joiner_application.h" +#include "6LoWPAN/Thread/thread_management_client.h" +#include "6LoWPAN/Thread/thread_management_server.h" +#include "6LoWPAN/Thread/thread_beacon.h" +#include "6LoWPAN/Thread/thread_network_data_lib.h" +#include "MAC/IEEE802_15_4/mac_data_interface.h" +#include "MAC/IEEE802_15_4/mac_data_poll.h" +#include "MAC/IEEE802_15_4/mac_security_interface.h" +#include "MAC/IEEE802_15_4/mac_data_poll.h" +#include "MAC/IEEE802_15_4/mac_mlme.h" +#include "thread_management_if.h" +#include "Common_Protocols/ipv6.h" +#include "Common_Protocols/icmpv6.h" +#include "Common_Protocols/icmpv6_radv.h" +#include "MLE/mle.h" +#include "MLE/mle_tlv.h" +#include "thread_config.h" +#include "multicast_api.h" +#include "Service_Libs/nd_proxy/nd_proxy.h" +#include "Service_Libs/mle_service/mle_service_api.h" +#include "thread_dhcpv6_client.h" + +#define TRACE_GROUP "trbs" + +int thread_router_mle_advertise(protocol_interface_info_entry_t *cur) +{ + return 0; +} + +int thread_reed_advertise (protocol_interface_info_entry_t *cur) +{ + return 0; +} + +void thread_set_meshlocal_route(protocol_interface_info_entry_t *cur) +{ +} + +uint8_t *thread_write_route_option(protocol_interface_info_entry_t *cur, uint8_t *ptr) +{ + return 0; +} + + +void thread_multicast_forward_to_child(void *buf) +{ +} + +void thread_attach_router_id_request(protocol_interface_info_entry_t *cur) +{ +} + +void thread_bootstrap_child_id_handler(protocol_interface_info_entry_t *cur) +{ +} + +void thread_mle_connected_reed_receive_cb(int8_t interface_id, mle_message_t *mle_msg, mac_aux_security_header_t *security_headers) +{ +} + + +void thread_reed_synch_start(protocol_interface_info_entry_t *cur) +{ +} + +bool thread_bootstrap_trig_router_downgrade(protocol_interface_info_entry_t *cur) +{ + return false; +} + +bool thread_bootstrap_trig_reed_upgrade(protocol_interface_info_entry_t *cur) +{ + return false; +} + +void thread_bootstrap_child_id_reject(protocol_interface_info_entry_t *cur) +{ +} + +void thread_bootstrap_attached_active_router(protocol_interface_info_entry_t *cur) +{ +} + +void thread_bootstrap_router_synch_finish(protocol_interface_info_entry_t *cur) +{ +} + +void thread_bootsrap_generate_thread_partitition(int8_t interface_id, bool newPartition) +{ +} + +void thread_attach_router_id_release(protocol_interface_info_entry_t *cur) +{ +} + +void thread_bootstrap_leader_data_free(thread_info_t *thread_info, int8_t bootstrap) +{ +} + +void thread_bootstrap_global_leader_data(thread_info_t *thread_info) +{ + +} + + diff --git a/test/coap-service/unittest/stub/thread_routerid_server_stub.c b/test/coap-service/unittest/stub/thread_routerid_server_stub.c new file mode 100644 index 0000000000..bc5271a62f --- /dev/null +++ b/test/coap-service/unittest/stub/thread_routerid_server_stub.c @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2014-2015 ARM Limited. All rights reserved. + */ + +/** + * \file thread_routerid_server.c + * + */ +#include "config.h" +#include +#include +#include +#include "common_functions.h" +#include "libDHCPv6/libDHCPv6.h" +#include "randLIB.h" +#include "nsdynmemLIB.h" +#include "NWK_INTERFACE/Include/protocol.h" +#include "6LoWPAN/Thread/thread.h" +#include "6LoWPAN/Thread/thread_routerid_server.h" + +#define TRACE_GROUP "thid" + +int thread_routerid_assign_cb(int8_t interface_id, const uint8_t mac[8], uint8_t router_id_mask_out[9], uint16_t *router_id) +{ + return -1; +} + +int thread_routerid_release_cb(int8_t interface_id, uint8_t mac[8], uint16_t router_id) +{ + return -1; +} diff --git a/test/coap-service/unittest/stub/thread_routing_stub.c b/test/coap-service/unittest/stub/thread_routing_stub.c new file mode 100644 index 0000000000..de96783a1f --- /dev/null +++ b/test/coap-service/unittest/stub/thread_routing_stub.c @@ -0,0 +1,165 @@ +/* + * Copyright (c) 2014-2015 ARM Limited. All rights reserved. + */ + +#include "config.h" +#include +#include +#include +#include + +#ifndef UINT_FAST4_MAX +typedef uint_fast8_t uint_fast4_t; +#define UINT_FAST4_MAX UINT_FAST8_MAX +#endif + +#define THREAD_ROUTING_FN extern + +#include +#include "ns_trace.h" +#include "common_functions.h" +#include "NWK_INTERFACE/Include/protocol.h" +#include "MLE/mle.h" +#include "6LoWPAN/Mesh/mesh.h" +#include "6LoWPAN/Thread/thread.h" +#include "6LoWPAN/Thread/thread_nd.h" +#include "6LoWPAN/Thread/thread_routing.h" + +#define TRACE_GROUP "trou" + +/* MLE Route Data bit assignments (draft-kelsey-thread-routing-00) */ +#define ROUTE_DATA_OUT_MASK 0xC0 +#define ROUTE_DATA_OUT_SHIFT 6 +#define ROUTE_DATA_IN_MASK 0x30 +#define ROUTE_DATA_IN_SHIFT 4 +#define ROUTE_DATA_COST_MASK 0x0F + +#define MAX_ROUTE_COST 0x0F + +typedef uint_fast4_t route_cost_t; +#define THREAD_COST_INFINITE 0 + +#define MAX_LINK_AGE 100*10 /* 100 seconds */ + +#define LINK_AGE_STATIC 0xFFFF /* Magic number to indicate "never expire" */ + + +bool router_id_sequence_is_greater(const thread_routing_info_t *routing, uint8_t seq) +{ + return false; +} + +#define LINK_QUALITY_HYSTERESIS (1 << THREAD_LINK_MARGIN_SCALING) /* 1dB */ + +thread_link_quality_t link_margin_to_quality(thread_link_margin_t margin) +{ + return QUALITY_BAD; +} + +bool thread_i_am_router(const protocol_interface_info_entry_t *cur) +{ + return false; +} + +void thread_routing_update_id_set(protocol_interface_info_entry_t *cur, uint8_t seq, const uint8_t *id_mask) +{ +} + +int_fast8_t thread_routing_update_link_margin(protocol_interface_info_entry_t *cur, + uint16_t sender, + uint8_t link_margin_db, + uint8_t outgoing_link_margin_db) +{ + return 0; +} + +int_fast8_t thread_routing_add_link(protocol_interface_info_entry_t *cur, + uint16_t sender, uint8_t link_margin_db, + uint8_t id_seq, + const uint8_t *id_mask, + const uint8_t *route_data, + bool is_static) +{ + return 0; +} + +int_fast8_t thread_routing_remove_link(protocol_interface_info_entry_t *cur, + uint16_t sender) +{ + return 0; +} + +uint8_t thread_routing_get_route_data_size(protocol_interface_info_entry_t *cur) +{ + return 0; +} + +uint_fast8_t thread_routing_cost_get_by_router_id(thread_routing_info_t *routing , uint8_t routerId) +{ + return 0; +} + +void thread_routing_get_mask_by_current_data(thread_routing_info_t *routing, uint8_t *id_mask) +{ +} + +int_fast8_t thread_routing_get_route_data(protocol_interface_info_entry_t *cur, + uint8_t *id_seq, + uint8_t *id_mask, + uint8_t *data, + uint8_t *len_out) +{ + return 0; +} + +void thread_routing_init(thread_routing_info_t *routing) +{ +} + +void thread_routing_free(thread_routing_info_t *routing) +{ +} + +void thread_routing_activate(thread_routing_info_t *routing) +{ +} + +void thread_routing_deactivate(thread_routing_info_t *routing) +{ +} + +/* ticks is in 100ms units, I think */ +/* Return true if we want to send an MLE advertisement */ +bool thread_routing_timer(thread_info_t *thread, uint8_t ticks) +{ + return false; +} + +void thread_routing_set_mesh_callbacks(protocol_interface_info_entry_t *cur) +{ +} + +uint_fast8_t thread_routing_count_neighbours_with_quality_or_better(thread_routing_info_t *routing, thread_link_quality_t quality) +{ + return 0; +} + +uint_fast8_t thread_routing_count_active_routers(thread_routing_info_t *routing) +{ + return 0; +} + +uint_fast8_t thread_routing_count_active_routers_from_mask(const uint8_t *id_mask) +{ + return 0; +} + +uint_fast8_t thread_routing_sum_rx_path_cost_and_link_cost(uint8_t inMargim, uint8_t outMargin, uint8_t pathCost) +{ + return 0; +} + +void thread_routing_reset(thread_routing_info_t *routing) +{ + +} diff --git a/test/coap-service/unittest/stub/thread_stub.c b/test/coap-service/unittest/stub/thread_stub.c new file mode 100644 index 0000000000..49a3c7cf93 --- /dev/null +++ b/test/coap-service/unittest/stub/thread_stub.c @@ -0,0 +1,373 @@ +/* + * Copyright (c) 2014-2015 ARM Limited. All rights reserved. + */ +#include "config.h" +#include +#include +#include +#include "eventOS_event.h" +#include "randLIB.h" +#include "common_functions.h" + +#include "NWK_INTERFACE/Include/protocol.h" +#include "net_thread_test.h" +#include "libDHCPv6/libDHCPv6.h" +#include "libDHCPv6/libDHCPv6_server.h" +#include "ns_trace.h" +#include "6LoWPAN/Bootstraps/protocol_6lowpan.h" +#include "6LoWPAN/Bootstraps/protocol_6lowpan_interface.h" +#include "6LoWPAN/Thread/thread.h" +#include "6LoWPAN/Thread/thread_routing.h" +#include "6LoWPAN/Thread/thread_dhcpv6_client.h" +#include "6LoWPAN/Thread/thread_bootstrap.h" +#include "6LoWPAN/Thread/thread_nd.h" +#include "6LoWPAN/Thread/thread_network_data_lib.h" +#include "6LoWPAN/Thread/thread_joiner_application.h" +#include "Common_Protocols/ipv6.h" +#include "Common_Protocols/icmpv6.h" +#include "MLE/mle.h" +#include "MLE/mle_tlv.h" + +#define TRACE_GROUP "thrd" + +#define ID_MASK_UPDATE_MIN (10 * 10) /* 1 minute */ +#define LEADER_DATA_UPDATE_MIN (10 * 10) /* 10 seconds */ + +void thread_leader_private_data_clean(thread_leader_info_t *private); +thread_leader_data_t *thread_leader_data_generate(void); +thread_leader_info_t *thread_allocate_and_init_leader_private_data(void); +thread_parent_info_t *thread_parent_data_allocate(thread_info_t *info); +int thread_leader_router_id_deallocate(const uint8_t *eui64, protocol_interface_info_entry_t *cur); + +int thread_proxy_state_update(int8_t caller_interface_id , int8_t handler_interface_id, bool status) +{ + +} + +void thread_anycast_address_policy_update(const uint8_t *meshLocalPrefix, bool addPolicy) +{ + +} + +int8_t thread_bootstrap_up(protocol_interface_info_entry_t *cur) +{ + return -1; +} + +int8_t thread_bootstrap_down(protocol_interface_info_entry_t *cur) +{ + return -1; +} + +int thread_leader_data_base_allocate(protocol_interface_info_entry_t *cur) +{ + return 0; +} + +bool thread_addr_is_mesh_local(const uint8_t *addr, const protocol_interface_info_entry_t *cur) +{ + return false; +} + +bool thread_addr_is_mesh_local_16(const uint8_t *addr, const protocol_interface_info_entry_t *cur) +{ + return false; +} + +bool thread_addr_is_mesh_local_64(const uint8_t *addr, const protocol_interface_info_entry_t *cur) +{ + return false; +} + +void thread_leader_data_initialize(thread_leader_data_t *leader_data, uint8_t routerId) +{ +} + +void thread_leader_private_routemask_init(thread_leader_info_t *leader_info) +{ +} + +void thread_leader_private_routemask_init_by_last_partition(thread_leader_info_t *leader_info, uint8_t *lastValidRouteMask, uint8_t leaderId) +{ +} + +void thread_router_child_info_init(thread_child_info_t *child_info) +{ +} + +bool thread_leader_data_parse(uint8_t *ptr, uint16_t dataLength, thread_leader_data_t *leaderDataBuf) +{ + return false; +} + +bool thread_connectivity_tlv_parse(uint8_t *ptr, uint16_t dataLength, thread_connectivity_t *connectivityTlv) +{ + return false; +} + + + +thread_leader_data_t *thread_leader_data_generate(void) +{ + return NULL; +} + +thread_leader_data_t *thread_leader_data_allocate(thread_info_t *info) +{ + return NULL; +} + +thread_parent_info_t *thread_parent_data_allocate(thread_info_t *info) +{ + return NULL; +} + +int thread_leader_ul16_address_get(thread_info_t *thread_info, uint8_t *address_ptr) +{ + return -1; +} + +void thread_leader_setup_delete(link_configuration_s *leader_setup_ptr) +{ +} + +bool thread_leader_commissioner_create(thread_info_t *thread_info) +{ + return false; +} + +void thread_leader_commissioner_free(thread_info_t *thread_info) +{ +} + + +void thread_data_base_init(thread_info_t *thread_info, int8_t interfaceId) +{ +} + + +int thread_info_allocate_and_init(protocol_interface_info_entry_t *cur) +{ + return -1; +} + +void thread_child_info_free(thread_info_t *thread_info) +{ +} + +void thread_info_deallocate(protocol_interface_info_entry_t *cur) +{ +} + +int thread_leader_route_mask_update(thread_leader_info_t *info, uint8_t router_id, bool setActive) +{ + return -1; +} + +/* Called by thread_routing.c as a result of updates to routing table - allows + * leader to monitor a router being available (having a finite route cost). + */ +void thread_leader_router_state_changed(thread_leader_info_t *info, uint8_t router_id, bool available, int8_t interface_id) +{ +} + +int thread_validate_own_routeid_from_new_mask(const uint8_t *master_router_id_mask, uint8_t router_id) +{ + return -1; +} + + + + +void thread_leader_allocate_router_id_by_allocated_id(thread_leader_info_t *info, uint8_t router_id, const uint8_t *eui64) +{ +} + +int thread_generate_leasequery(int8_t interfaceID, uint8_t *addressRequested) +{ + return -1; +} + +thread_leader_info_t *thread_allocate_and_init_leader_private_data(void) +{ + return NULL; +} + +thread_child_info_t *thread_router_child_info_allocate_and_init(void) +{ + return NULL; +} + + + +void thread_child_id_request_info_init(thread_pending_child_id_req_t *child_info) +{ +} + +thread_pending_child_id_req_t *thread_child_id_request_allocate(void) +{ + return NULL; +} + +void thread_child_id_request_entry_clean(protocol_interface_info_entry_t *cur) +{ +} + +thread_pending_child_id_req_t *thread_child_id_request_entry_get(protocol_interface_info_entry_t *cur, uint8_t *euid64) +{ + return NULL; +} + +thread_pending_child_id_req_t *thread_child_id_request_entry_get_from_the_list(protocol_interface_info_entry_t *cur) +{ + return NULL; +} + +void thread_child_id_request_entry_remove(protocol_interface_info_entry_t *cur, thread_pending_child_id_req_t *entry) +{ +} + +int thread_init(protocol_interface_info_entry_t *cur) +{ + return 0; +} + +int thread_route_tlv_push(protocol_interface_info_entry_t *cur, uint8_t *route_tlv, uint8_t route_len, uint8_t linkMargin, uint16_t shortAddress) +{ + return 0; +} + +void thread_leader_update_id_set(protocol_interface_info_entry_t *cur) +{ +} + +int thread_routerid_request_handler(int8_t interfaceId, const uint8_t *clientId, thread_router_id_response_t *router_id_response, bool reNew) +{ + return -1; +} + + +int thread_routerid_release_handler(int8_t interfaceId, uint8_t *clientId) +{ + return -1; +} + +void thread_leader_router_id_valid_lifetime_update(protocol_interface_info_entry_t *cur, uint32_t tickUpdate) +{ +} + +int thread_leader_router_id_deallocate(const uint8_t *eui64, protocol_interface_info_entry_t *cur) +{ + return -1; +} + +int thread_leader_router_id_allocate(const uint8_t *eui64, protocol_interface_info_entry_t *cur, thread_router_id_response_t *reponse, bool renew) +{ + return -1; +} + +int thread_discover_mode_active(protocol_interface_info_entry_t *cur) +{ + return -1; +} + +int thread_attach_mode_active(protocol_interface_info_entry_t *cur) +{ + return -1; +} + +int thread_attach_ready(protocol_interface_info_entry_t *cur) +{ + return -1; +} + +bool thread_attach_active_router(protocol_interface_info_entry_t *cur) +{ + return -1; +} + +int thread_router_ready(protocol_interface_info_entry_t *cur) +{ + return -1; +} + +bool thread_scan_mask_validation(protocol_interface_info_entry_t *cur, uint8_t mask) +{ + return false; +} + +int thread_route_ready_to_leader(protocol_interface_info_entry_t *cur) +{ + return -1; +} + +void thread_leader_private_data_clean(thread_leader_info_t *pr) +{ +} + +bool thread_route_possible_add(thread_attach_device_mode_e threadMode) +{ + return false; +} + +bool thread_on_mesh_route_possible_add(thread_attach_device_mode_e threadMode) +{ + return false; +} + +bool thread_on_mesh_address_valid(thread_network_server_data_entry_t *curRoute) +{ + return false; +} + +void thread_dhcp_client_gua_error_cb(int8_t interface, uint8_t dhcp_addr[static 16], uint8_t prefix[static 16], bool register_status) +{ +} + + +void thread_network_data_service_learn(protocol_interface_info_entry_t *cur) +{ +} + +void thread_seconds_timer(protocol_interface_info_entry_t *cur, uint32_t ticks) +{ +} + +void thread_timer(protocol_interface_info_entry_t *cur, uint8_t ticks) +{ +} + +void thread_network_data_update(protocol_interface_info_entry_t *cur) +{ +} + +bool thread_insist_that_mesh_isnt_a_link(const protocol_interface_info_entry_t *cur) +{ + return false; +} + +/* If it's a 16-bit src address, only pass it if it's on the list */ +bool thread_test_addr_filter(const buffer_t *buf, const protocol_interface_info_entry_t *cur) +{ + return false; +} + +uint8_t *thread_beacon_create_payload(const link_configuration_s *leader_link_setup,thread_commissioner_t *registered_commissioner, uint8_t *return_length) +{ + return NULL; +} + +uint8_t thread_beacon_indication(uint8_t *ptr, uint8_t len, protocol_interface_info_entry_t *cur) +{ + return 0; +} + +void thread_network_data_request_disable_trig(protocol_interface_info_entry_t *cur) +{ + +} + +void thread_network_data_request_trig(protocol_interface_info_entry_t *cur, uint8_t *requestDstAddress, bool delaydTrig) +{ + +} diff --git a/test/coap-service/unittest/stub/thread_test_api_stub.c b/test/coap-service/unittest/stub/thread_test_api_stub.c new file mode 100644 index 0000000000..d3672a5ae2 --- /dev/null +++ b/test/coap-service/unittest/stub/thread_test_api_stub.c @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2014-2015 ARM Limited. All rights reserved. + */ +#include "config.h" +#include +#include +#include +#include + +#include "ns_trace.h" +#include "common_functions.h" +#include "NWK_INTERFACE/Include/protocol.h" +#include "6LoWPAN/Thread/thread.h" +#include "6LoWPAN/Thread/thread_routing.h" +#include "MAC/IEEE802_15_4/mac_security_interface.h" + +#define TRACE_GROUP "tapi" + +int_fast8_t arm_nwk_6lowpan_thread_test_router_id_push( + int8_t interface_id, + const uint8_t *euid64, + uint8_t router_id) +{ + return 0; +} + +int_fast8_t arm_nwk_6lowpan_thread_test_add_neighbour( + int8_t interface_id, + uint16_t neighbour_short_addr, + uint_fast8_t link_margin_db, + uint8_t id_sequence, + const uint8_t *id_mask, + const uint8_t *route_data) +{ + return 0; +} + +int_fast8_t arm_nwk_6lowpan_thread_test_remove_neighbour( + int8_t interface_id, + uint16_t neighbour_short_addr) +{ + return 0; + +} + +int_fast8_t arm_nwk_6lowpan_thread_test_set_addr_filter( + int8_t interface_id, + uint8_t num_short_addrs, + const uint16_t valid_short_addrs[num_short_addrs], + uint8_t num_long_addrs, + const uint8_t valid_long_addrs[num_long_addrs][8]) +{ + return 0; +} + +int_fast8_t arm_nwk_6lowpan_thread_adjust_link_margins( + int8_t interface_id, + int8_t adjustment) +{ + return 0; +} + +void arm_nwk_6lowpan_thread_test_print_routing_database(int8_t interface_id) +{ +} + +int8_t arm_nwk_key_update_trig(int8_t interface_id) +{ + return 0; +} diff --git a/test/coap-service/unittest/stub/timeout_stub.c b/test/coap-service/unittest/stub/timeout_stub.c new file mode 100644 index 0000000000..7738efe05e --- /dev/null +++ b/test/coap-service/unittest/stub/timeout_stub.c @@ -0,0 +1,15 @@ +//todo:is this right place, or should this be located to event-loop modules stubs? + + +#include "ns_types.h" +#include "eventOS_event_timer.h" + +timeout_t *eventOS_timeout_ms(void (*callback)(void *), uint32_t ms, void *arg) +{ + return NULL; +} + +void eventOS_timeout_cancel(timeout_t *t) +{ + +} diff --git a/xsl_script.sh b/xsl_script.sh new file mode 100755 index 0000000000..d5320b42b8 --- /dev/null +++ b/xsl_script.sh @@ -0,0 +1,35 @@ +#!/bin/bash + +# Copyright (c) 2015 ARM Limited. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 +# Licensed under the Apache License, Version 2.0 (the License); you may +# not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# * http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an AS IS BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +echo +echo "Creating report" +echo + +echo ' + +' >> lcov/index.xml + +for f in lcov/results/*.xml +do +name=${f##*/} +echo ''>> lcov/index.xml +done + +echo '' >> lcov/index.xml + +echo +echo "Report created to lcov/index.xml (outputs html)" +echo \ No newline at end of file