mirror of https://github.com/ARMmbed/mbed-os.git
New CoAP service + unit tests
parent
11461a7195
commit
eb5aa4ef59
|
@ -1,3 +1,5 @@
|
||||||
*.a
|
*.a
|
||||||
*.lib
|
*.lib
|
||||||
output
|
output
|
||||||
|
lcov
|
||||||
|
coverage
|
||||||
|
|
|
@ -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 <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#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;
|
|
||||||
}
|
|
||||||
|
|
31
Makefile
31
Makefile
|
@ -20,37 +20,32 @@
|
||||||
#
|
#
|
||||||
SERVLIB_DIR := ../libService
|
SERVLIB_DIR := ../libService
|
||||||
override CFLAGS += -I$(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
|
NSDLC_DIR := ../nsdl-c
|
||||||
override CFLAGS += -I$(NSDLC_DIR)/nsdl-c
|
override CFLAGS += -I$(NSDLC_DIR)/nsdl-c
|
||||||
|
|
||||||
EVENTLOOP_DIR := ../event-loop
|
EVENTLOOP_DIR := ../event-loop
|
||||||
override CFLAGS += -I$(EVENTLOOP_DIR)/nanostack-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='<config-thread.h>' -I$(MBEDTLS_DIR)/include
|
||||||
|
|
||||||
COAPSERVICE_DIR := ../coap-service
|
COAPSERVICE_DIR := ../coap-service
|
||||||
override CFLAGS += -I$(COAPSERVICE_DIR)/coap-service/
|
override CFLAGS += -I$(COAPSERVICE_DIR)/coap-service/
|
||||||
override CFLAGS += -I$(COAPSERVICE_DIR)/source/include/
|
override CFLAGS += -I$(COAPSERVICE_DIR)/source/include/
|
||||||
|
|
||||||
#override CFLAGS += -Isource/coap-service/source/include/
|
LIB = libcoap-service.a
|
||||||
#override CFLAGS += -Icoap-service-nanomesh/include/
|
|
||||||
|
|
||||||
|
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
|
include ../libService/toolchain_rules.mk
|
||||||
|
|
||||||
|
|
|
@ -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)
|
|
@ -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.
|
|
||||||
*/
|
|
|
@ -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.
|
|
||||||
*/
|
|
|
@ -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 <stdlib.h>
|
|
||||||
#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);
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,18 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2015 ARM Limited. All rights reserved.
|
* 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_
|
#ifndef COAP_SERVICE_API_H_
|
||||||
|
@ -42,6 +29,9 @@ extern "C" {
|
||||||
#define COAP_SERVICE_OPTIONS_NONE 0x00
|
#define COAP_SERVICE_OPTIONS_NONE 0x00
|
||||||
#define COAP_SERVICE_OPTIONS_VIRTUAL_SOCKET 0x01
|
#define COAP_SERVICE_OPTIONS_VIRTUAL_SOCKET 0x01
|
||||||
#define COAP_SERVICE_OPTIONS_SECURE 0x02
|
#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
|
// Bits for request options
|
||||||
#define COAP_REQUEST_OPTIONS_NONE 0x00
|
#define COAP_REQUEST_OPTIONS_NONE 0x00
|
||||||
|
@ -51,28 +41,17 @@ extern "C" {
|
||||||
#define COAP_REQUEST_OPTIONS_MULTICAST 0x04 //!< indicates that CoAP library support multicasting
|
#define COAP_REQUEST_OPTIONS_MULTICAST 0x04 //!< indicates that CoAP library support multicasting
|
||||||
#define COAP_REQUEST_OPTIONS_SECURE_BYPASS 0x08
|
#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 msg_id Id number of the current message.
|
||||||
* \param listen_port Port that Application wants to use for communicate with coap server.
|
* \param response_ptr Pointer to CoAP header structure.
|
||||||
* \param service_options Options of the current service.
|
|
||||||
*
|
*
|
||||||
* \return service_id / -1 for failure
|
* \return 0 for success / -1 for failure
|
||||||
*/
|
*/
|
||||||
int8_t coap_service_initialize(int8_t interface_id, uint16_t listen_port, uint8_t service_options);
|
typedef int coap_service_response_recv(int8_t service_id, uint16_t msg_id, sn_coap_hdr_s *response_ptr);
|
||||||
|
|
||||||
/**
|
|
||||||
* \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 );
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief CoAP service request callback
|
* \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
|
* \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 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
|
* \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.
|
* CoAP service security done callback function.
|
||||||
*
|
*
|
||||||
* \param service_id Id number of the current service.
|
* \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)
|
* \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 interface_id Informs registered application interface id. This parameter is passed to socket implementation.
|
||||||
* \param PSKd_ptr Pointer to PSK key.
|
* \param listen_port Port that Application wants to use for communicate with coap server.
|
||||||
* \param PSKd_len Lenght of PSK key.
|
* \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 service_id / -1 for failure
|
||||||
|
*/
|
||||||
|
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 delete
|
||||||
|
*
|
||||||
|
* Removes all data related to this instance
|
||||||
|
*
|
||||||
|
* \param service_id Id number of the current service.
|
||||||
|
*/
|
||||||
|
extern void coap_service_delete( int8_t service_id );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Close secure connection
|
||||||
|
*
|
||||||
|
* 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
|
* \return 0 for success / -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);
|
//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 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_service_response_recv(int8_t service_id, uint16_t msg_id, sn_coap_hdr_s *response_ptr);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Virtual socket sent callback.
|
* \brief Virtual socket sent callback.
|
||||||
|
@ -152,7 +152,7 @@ typedef int coap_service_response_recv(int8_t service_id, uint16_t msg_id, sn_co
|
||||||
*
|
*
|
||||||
* \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.
|
* \brief Virtual socket read.
|
||||||
|
@ -167,7 +167,7 @@ typedef int coap_service_virtual_socket_send_cb(int8_t service_id, uint8_t desti
|
||||||
*
|
*
|
||||||
* \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
|
* \brief Set virtual socket
|
||||||
|
@ -179,7 +179,7 @@ int16_t coap_service_virtual_socket_recv(int8_t service_id, uint8_t source_addr_
|
||||||
*
|
*
|
||||||
* \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
|
* \brief Register unsecure callback methods to CoAP server
|
||||||
|
@ -194,7 +194,7 @@ int16_t coap_service_virtual_socket_set_cb(int8_t service_id, coap_service_virtu
|
||||||
*
|
*
|
||||||
* \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
|
* \brief Unregister unsecure callback methods to CoAP server
|
||||||
|
@ -206,39 +206,7 @@ int8_t coap_service_register_uri(int8_t service_id, const char *uri, uint8_t all
|
||||||
*
|
*
|
||||||
* \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);
|
extern 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);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Sends CoAP service request
|
* \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.
|
* \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,
|
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);
|
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
|
* \brief Sends CoAP service response
|
||||||
|
@ -275,7 +243,7 @@ uint16_t coap_service_request_send(int8_t service_id, uint8_t options, const uin
|
||||||
* \return -1 For failure
|
* \return -1 For failure
|
||||||
*- 0 For success
|
*- 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
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,101 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
|
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
|
||||||
|
|
||||||
|
<xsl:output encoding="UTF-8" indent="yes" method="html"/>
|
||||||
|
<xsl:strip-space elements="*"/>
|
||||||
|
|
||||||
|
<xsl:variable name="list"
|
||||||
|
select="document('index.xml')/list" />
|
||||||
|
|
||||||
|
<xsl:template match="/">
|
||||||
|
<h1>
|
||||||
|
Unittest report
|
||||||
|
</h1>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<b>
|
||||||
|
Total tests run <xsl:value-of select="sum(document($list/entry/@name)/testsuite/@tests)"/>
|
||||||
|
, failures: <xsl:value-of select="sum(document($list/entry/@name)/testsuite/@failures) + sum(document($list/entry/@name)/testsuite/@errors)"/>
|
||||||
|
</b>
|
||||||
|
|
||||||
|
<xsl:for-each select="document($list/entry/@name)" >
|
||||||
|
<xsl:apply-templates select="testsuite"/>
|
||||||
|
</xsl:for-each>
|
||||||
|
</p>
|
||||||
|
</xsl:template>
|
||||||
|
|
||||||
|
<xsl:template match="testsuite">
|
||||||
|
<h2>
|
||||||
|
<xsl:value-of select="@name" />
|
||||||
|
</h2>
|
||||||
|
<table border="1" cellSpacing="0" cellPadding="10" >
|
||||||
|
<tr>
|
||||||
|
<th>Tests run</th>
|
||||||
|
<th>Tests failed</th>
|
||||||
|
<th>Other errors</th>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td><xsl:value-of select="@tests"/></td>
|
||||||
|
<td><xsl:value-of select="@failures"/></td>
|
||||||
|
<td><xsl:value-of select="@errors"/></td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
<br/>
|
||||||
|
<table border="1" cellSpacing="0" cellPadding="10" >
|
||||||
|
<tr>
|
||||||
|
<th>Tests name</th>
|
||||||
|
<th>PASS/FAIL</th>
|
||||||
|
<th>Failing case</th>
|
||||||
|
<th>Reason</th>
|
||||||
|
</tr>
|
||||||
|
<xsl:apply-templates select="testcase"/>
|
||||||
|
</table>
|
||||||
|
</xsl:template>
|
||||||
|
|
||||||
|
<xsl:template match="testcase">
|
||||||
|
<xsl:choose>
|
||||||
|
<xsl:when test="failure">
|
||||||
|
<tr><td><font color="#FF0000"><xsl:value-of select="@name" /></font></td><xsl:apply-templates select="failure"/></tr>
|
||||||
|
</xsl:when>
|
||||||
|
<xsl:when test="error">
|
||||||
|
<tr><td><font color="#FF0000"><xsl:value-of select="@name" /></font></td><xsl:apply-templates select="error"/></tr>
|
||||||
|
</xsl:when>
|
||||||
|
<xsl:otherwise>
|
||||||
|
<tr><td><xsl:value-of select="@name" /></td><td><font color="#00FF00">PASS</font></td><td></td><td></td></tr>
|
||||||
|
</xsl:otherwise>
|
||||||
|
</xsl:choose>
|
||||||
|
</xsl:template>
|
||||||
|
|
||||||
|
<xsl:template match="failure">
|
||||||
|
<td>
|
||||||
|
<b><font color="#FF0000">FAIL</font></b>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<font color="#ff0000">
|
||||||
|
<xsl:value-of select="@message" />
|
||||||
|
</font>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<font color="#ff0000">
|
||||||
|
<xsl:value-of select="@type" />
|
||||||
|
</font>
|
||||||
|
</td>
|
||||||
|
</xsl:template>
|
||||||
|
|
||||||
|
<xsl:template match="error">
|
||||||
|
<td>
|
||||||
|
<b><font color="#FF0000">FAIL</font></b>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<font color="#ff0000">
|
||||||
|
<xsl:value-of select="@message" />
|
||||||
|
</font>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<font color="#ff0000">
|
||||||
|
<xsl:value-of select="@type" />
|
||||||
|
</font>
|
||||||
|
</td>
|
||||||
|
</xsl:template>
|
||||||
|
|
||||||
|
</xsl:stylesheet>
|
|
@ -1,12 +1,11 @@
|
||||||
{
|
{
|
||||||
"name": "coap-service",
|
"name": "coap-service",
|
||||||
"version": "0.0.11",
|
"version": "1.0.0",
|
||||||
"description": "CoAP Service library",
|
"description": "CoAP Service library",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"coap",
|
"coap",
|
||||||
"service"
|
"service"
|
||||||
],
|
],
|
||||||
"author": "Erno Tormikoski <erno.tormikoski@arm.com>",
|
|
||||||
"repository": {
|
"repository": {
|
||||||
"url": "git@github.com:ARMmbed/coap-service.git",
|
"url": "git@github.com:ARMmbed/coap-service.git",
|
||||||
"type": "git"
|
"type": "git"
|
||||||
|
|
|
@ -0,0 +1,679 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2015 ARM Limited. All rights reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
#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;
|
||||||
|
}
|
|
@ -0,0 +1,372 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2015 ARM Limited. All rights reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
#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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,396 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2015 ARM Limited. All rights reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
#include <time.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#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 );
|
||||||
|
}
|
|
@ -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;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
|
@ -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 <string.h>
|
|
||||||
#include <ns_types.h>
|
|
||||||
#include "ns_list.h"
|
|
||||||
#include "sn_coap_header.h"
|
|
||||||
#include "coap_service_api.h"
|
|
||||||
#include "coap_server.h"
|
|
||||||
|
|
||||||
#include <ns_trace.h>
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
|
@ -0,0 +1,450 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2015 ARM Limited. All rights reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#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);
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,48 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2015 ARM Limited. All rights reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __COAP_CONNECTION_HANDLER_H__
|
||||||
|
#define __COAP_CONNECTION_HANDLER_H__
|
||||||
|
|
||||||
|
#include <inttypes.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#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
|
|
@ -0,0 +1,67 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2015 ARM Limited. All rights reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __COAPPI_SERVICE_API_H__
|
||||||
|
#define __COAPPI_SERVICE_API_H__
|
||||||
|
|
||||||
|
#include <inttypes.h>
|
||||||
|
#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
|
|
@ -0,0 +1,73 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2015 ARM Limited. All rights reserved.
|
||||||
|
*/
|
||||||
|
#ifndef __COAP_SECURITY_HANDLER_H__
|
||||||
|
#define __COAP_SECURITY_HANDLER_H__
|
||||||
|
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <inttypes.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#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
|
|
@ -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_ */
|
|
|
@ -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_ */
|
|
|
@ -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
|
||||||
|
|
|
@ -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)
|
|
@ -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
|
||||||
|
|
|
@ -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());
|
||||||
|
}
|
||||||
|
|
|
@ -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);
|
||||||
|
|
|
@ -0,0 +1,467 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2015 ARM. All rights reserved.
|
||||||
|
*/
|
||||||
|
#include "test_coap_connection_handler.h"
|
||||||
|
#include <string.h>
|
||||||
|
#include <inttypes.h>
|
||||||
|
#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;
|
||||||
|
}
|
|
@ -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 <stdbool.h>
|
||||||
|
|
||||||
|
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
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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());
|
||||||
|
}
|
||||||
|
|
|
@ -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);
|
||||||
|
|
|
@ -0,0 +1,298 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2015 ARM. All rights reserved.
|
||||||
|
*/
|
||||||
|
#include "test_coap_message_handler.h"
|
||||||
|
#include <string.h>
|
||||||
|
#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;
|
||||||
|
}
|
|
@ -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 <stdbool.h>
|
||||||
|
|
||||||
|
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
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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());
|
||||||
|
}
|
|
@ -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);
|
||||||
|
|
|
@ -0,0 +1,281 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2015 ARM. All rights reserved.
|
||||||
|
*/
|
||||||
|
#include "test_coap_security_handler.h"
|
||||||
|
#include "coap_security_handler.h"
|
||||||
|
#include <string.h>
|
||||||
|
#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;
|
||||||
|
}
|
||||||
|
|
|
@ -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 <stdbool.h>
|
||||||
|
#include <inttypes.h>
|
||||||
|
|
||||||
|
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
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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());
|
||||||
|
}
|
||||||
|
|
|
@ -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);
|
||||||
|
|
|
@ -0,0 +1,407 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2015 ARM. All rights reserved.
|
||||||
|
*/
|
||||||
|
#include "test_coap_service_api.h"
|
||||||
|
#include <string.h>
|
||||||
|
#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;
|
||||||
|
}
|
|
@ -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 <stdbool.h>
|
||||||
|
|
||||||
|
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
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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
|
|
@ -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
|
|
@ -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 */
|
||||||
|
|
|
@ -0,0 +1,74 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2014-2015 ARM Limited. All rights reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
#include <string.h>
|
||||||
|
#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;
|
||||||
|
}
|
|
@ -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;
|
||||||
|
}
|
|
@ -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__
|
|
@ -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;
|
||||||
|
}
|
|
@ -0,0 +1,59 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2015 ARM Limited. All rights reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
#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;
|
||||||
|
}
|
|
@ -0,0 +1,32 @@
|
||||||
|
#ifndef __COAP_CONNECTION_HANDLER_STUB_H__
|
||||||
|
#define __COAP_CONNECTION_HANDLER_STUB_H__
|
||||||
|
|
||||||
|
#include <inttypes.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
#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
|
|
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -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 <inttypes.h>
|
||||||
|
#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__
|
|
@ -0,0 +1,75 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2015 ARM Limited. All rights reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
#include <time.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#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;
|
||||||
|
}
|
|
@ -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 <inttypes.h>
|
||||||
|
#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__
|
|
@ -0,0 +1,63 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2015 ARM Limited. All rights reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
#ifdef HAVE_THREAD
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#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
|
|
@ -0,0 +1,116 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2014-2015 ARM Limited. All rights reserved.
|
||||||
|
*/
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <inttypes.h>
|
||||||
|
|
||||||
|
#include "ns_types.h"
|
||||||
|
//#include "common_functions.h"
|
||||||
|
#define COMMON_FUNCTIONS_FN
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
|
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,157 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2013-2015 ARM Limited. All rights reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
#include <ns_types.h>
|
||||||
|
#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 "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;
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,21 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2015 ARM Limited. All rights reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
#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;
|
||||||
|
}
|
|
@ -0,0 +1,22 @@
|
||||||
|
#ifndef __EVENTOS_EVENT_STUB_H__
|
||||||
|
#define __EVENTOS_EVENT_STUB_H__
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <inttypes.h>
|
||||||
|
#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__
|
|
@ -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;
|
||||||
|
}
|
|
@ -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 <string.h>
|
||||||
|
#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;
|
||||||
|
}
|
|
@ -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 <string.h>
|
||||||
|
#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;
|
||||||
|
}
|
|
@ -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)
|
||||||
|
{
|
||||||
|
}
|
|
@ -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 */
|
||||||
|
|
|
@ -0,0 +1,56 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2014-2015 ARM Limited. All rights reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
#include <ns_types.h>
|
||||||
|
#include <nsdynmemLIB.h>
|
||||||
|
#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;
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,212 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2014-2015 ARM Limited. All rights reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
#include <string.h>
|
||||||
|
#include <ns_types.h>
|
||||||
|
#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;
|
||||||
|
}
|
||||||
|
|
|
@ -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)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,84 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2015 ARM Limited. All rights reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <inttypes.h>
|
||||||
|
#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;
|
||||||
|
}
|
|
@ -0,0 +1,221 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 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 "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;
|
||||||
|
}
|
|
@ -0,0 +1,78 @@
|
||||||
|
/*
|
||||||
|
* 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 "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)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
|
@ -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;
|
||||||
|
}
|
|
@ -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 <inttypes.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#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
|
|
@ -0,0 +1,220 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2015 ARM Limited. All rights reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
#include <string.h>
|
||||||
|
#include <ns_types.h>
|
||||||
|
#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;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -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 <net_thread_test.h>
|
||||||
|
#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 */
|
|
@ -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__
|
|
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
|
@ -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;
|
||||||
|
}
|
|
@ -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 */
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
|
@ -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)
|
||||||
|
{
|
||||||
|
}
|
|
@ -0,0 +1,9 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2015 ARM Limited. All rights reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define NS_LIST_FN extern
|
||||||
|
|
||||||
|
#include "ns_list.h"
|
||||||
|
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
|
@ -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__
|
|
@ -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, ...)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,202 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2014-2015 ARM Limited. All rights reserved.
|
||||||
|
*/
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#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)
|
||||||
|
{
|
||||||
|
}
|
|
@ -0,0 +1,48 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2014-2015 ARM Limited. All rights reserved.
|
||||||
|
*/
|
||||||
|
#include "nsdynmemLIB_stub.h"
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <nsdynmemLIB.h>
|
||||||
|
#include "platform/arm_hal_interrupt.h"
|
||||||
|
#ifdef STANDARD_MALLOC
|
||||||
|
#include <stdlib.h>
|
||||||
|
#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);
|
||||||
|
}
|
|
@ -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
|
|
@ -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;
|
||||||
|
}
|
|
@ -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;
|
||||||
|
}
|
|
@ -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;
|
||||||
|
}
|
|
@ -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;
|
||||||
|
}
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
|
@ -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)
|
||||||
|
{
|
||||||
|
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue