Merge pull request #4960 from artokin/master

Nanostack update for mbed-os-5.6
pull/4964/merge
Jimmy Brisson 2017-08-29 13:46:47 -05:00 committed by GitHub
commit 4978a08ae2
162 changed files with 1468 additions and 463 deletions

View File

@ -52,6 +52,7 @@ The purpose of the library is to provide a light, simple and general tracing sol
* With yotta: set `YOTTA_CFG_MBED_TRACE_FEA_IPV6 = 0`.
* With mbed OS 5: set `MBED_CONF_MBED_TRACE_FEA_IPV6 = 0`.
* If thread safety is needed, configure the wait and release callback functions before initialization to enable the protection. Usually, this needs to be done only once in the application's lifetime.
* If [helping functions](#helping-functions) are used the mutex must be **recursive** (counting) so it can be acquired from a single thread repeatedly.
* Call the trace initialization (`mbed_trace_init`) once before using any other APIs. It allocates the trace buffer and initializes the internal variables.
* Define `TRACE_GROUP` in your source code (not in the header!) to use traces. It is a 1-4 characters long char-array (for example `#define TRACE_GROUP "APPL"`). This will be printed on every trace line.

View File

@ -14,9 +14,12 @@
"nanostack-event-loop"
],
"dependencies": {
"nanostack-libservice": "^3.0.0",
"mbed-6lowpan-eventloop-adaptor": "^1.0.0",
"minar": "^1.0.0"
"nanostack-libservice": "ARMmbed/nanostack-libservice#master"
},
"targetDependencies": {}
"targetDependencies": {
"mbed": {
"mbed-6lowpan-eventloop-adaptor": "^1.0.0",
"minar": "^1.0.0"
}
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015-2016 ARM Limited. All Rights Reserved.
* Copyright (c) 2015-2017 ARM Limited. All Rights Reserved.
*
* SPDX-License-Identifier: Apache-2.0
*
@ -45,6 +45,10 @@ extern "C" {
#define COAP_SERVICE_OPTIONS_VIRTUAL_SOCKET 0x01
#define COAP_SERVICE_OPTIONS_SECURE 0x02
#define COAP_SERVICE_OPTIONS_EPHEMERAL_PORT 0x04
/** Coap interface selected as socket interface */
#define COAP_SERVICE_OPTIONS_SELECT_SOCKET_IF 0x08
/** Register to COAP multicast groups */
#define COAP_SERVICE_OPTIONS_MULTICAST_JOIN 0x10
/** Link-layer security bypass option is set*/
#define COAP_SERVICE_OPTIONS_SECURE_BYPASS 0x80
@ -56,6 +60,10 @@ extern "C" {
#define COAP_REQUEST_OPTIONS_MULTICAST 0x04 //!< indicates that CoAP library support multicasting
#define COAP_REQUEST_OPTIONS_SECURE_BYPASS 0x08
extern const uint8_t COAP_MULTICAST_ADDR_LINK_LOCAL[16]; //!< ff02::fd, COAP link local multicast address
extern const uint8_t COAP_MULTICAST_ADDR_ADMIN_LOCAL[16]; //!< ff03::fd, COAP admin-local multicast address
extern const uint8_t COAP_MULTICAST_ADDR_SITE_LOCAL[16]; //!> ff05::fd, COAP site-local multicast address
/**
* \brief Service message response receive callback.
*
@ -262,7 +270,45 @@ extern uint16_t coap_service_request_send(int8_t service_id, uint8_t options, co
*/
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, sn_coap_content_format_e content_type, const uint8_t *payload_ptr,uint16_t payload_len);
/**
* \brief Delete CoAP request transaction
*
* Removes pending CoAP transaction from service.
*
* \param service_id Id number of the current service.
* \param msg_id Message ID number.
*
* \return -1 For failure
*- 0 For success
*/
extern int8_t coap_service_request_delete(int8_t service_id, uint16_t msg_id);
/**
* \brief Set DTLS handshake timeout values
*
* Configures the DTLS handshake timeout values.
*
* \param service_id Id number of the current service.
* \param min Initial timeout value.
* \param max Maximum value of timeout.
*
* \return -1 For failure
*- 0 For success
*/
extern int8_t coap_service_set_handshake_timeout(int8_t service_id, uint32_t min, uint32_t max);
/**
* \brief Set CoAP duplication message buffer size
*
* Configures the CoAP duplication message buffer size.
*
* \param service_id Id number of the current service.
* \param size Buffer size (messages)
*
* \return -1 For failure
*- 0 For success
*/
extern int8_t coap_service_set_duplicate_message_buffer(int8_t service_id, uint8_t size);
#ifdef __cplusplus
}
#endif

View File

@ -1,5 +1,5 @@
#!/bin/bash
# Copyright (c) 2015 ARM Limited. All rights reserved.
# Copyright (c) 2015-2017 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.

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015-2016 ARM Limited. All Rights Reserved.
* Copyright (c) 2015-2017 ARM Limited. All Rights Reserved.
*/
#include <string.h>
@ -42,6 +42,10 @@ typedef struct internal_socket_s {
ns_list_link_t link;
} internal_socket_t;
const uint8_t COAP_MULTICAST_ADDR_LINK_LOCAL[16] = { 0xff, 0x02, [15] = 0xfd }; // ff02::fd, COAP link-local multicast (rfc7390)
const uint8_t COAP_MULTICAST_ADDR_ADMIN_LOCAL[16] = { 0xff, 0x03, [15] = 0xfd }; // ff02::fd, COAP admin-local multicast (rfc7390)
const uint8_t COAP_MULTICAST_ADDR_SITE_LOCAL[16] = { 0xff, 0x05, [15] = 0xfd }; // ff05::fd, COAP site-local multicast (rfc7390)
static NS_LIST_DEFINE(socket_list, internal_socket_t, link);
static void timer_cb(void* param);
@ -99,7 +103,6 @@ static secure_session_t *secure_session_find_by_timer_id(int8_t timer_id)
static bool is_secure_session_valid(secure_session_t *session)
{
secure_session_t *this = NULL;
ns_list_foreach(secure_session_t, cur_ptr, &secure_session_list) {
if (cur_ptr == session) {
return true;
@ -222,9 +225,32 @@ static secure_session_t *secure_session_find(internal_socket_t *parent, const ui
return this;
}
static internal_socket_t *int_socket_create(uint16_t listen_port, bool use_ephemeral_port, bool is_secure, bool real_socket, bool bypassSec)
static void coap_multicast_group_join_or_leave(int8_t socket_id, uint8_t opt_name, int8_t interface_id)
{
ns_ipv6_mreq_t ns_ipv6_mreq;
int8_t ret_val;
// Join or leave COAP multicast groups
ns_ipv6_mreq.ipv6mr_interface = interface_id;
memcpy(ns_ipv6_mreq.ipv6mr_multiaddr, COAP_MULTICAST_ADDR_LINK_LOCAL, 16);
ret_val = socket_setsockopt(socket_id, SOCKET_IPPROTO_IPV6, opt_name, &ns_ipv6_mreq, sizeof(ns_ipv6_mreq));
memcpy(ns_ipv6_mreq.ipv6mr_multiaddr, COAP_MULTICAST_ADDR_ADMIN_LOCAL, 16);
ret_val |= socket_setsockopt(socket_id, SOCKET_IPPROTO_IPV6, opt_name, &ns_ipv6_mreq, sizeof(ns_ipv6_mreq));
memcpy(ns_ipv6_mreq.ipv6mr_multiaddr, COAP_MULTICAST_ADDR_SITE_LOCAL, 16);
ret_val |= socket_setsockopt(socket_id, SOCKET_IPPROTO_IPV6, opt_name, &ns_ipv6_mreq, sizeof(ns_ipv6_mreq));
if (ret_val) {
tr_error("Multicast group access failed, err=%d, name=%d", ret_val, opt_name);
}
}
static internal_socket_t *int_socket_create(uint16_t listen_port, bool use_ephemeral_port, bool is_secure, bool real_socket, bool bypassSec, int8_t socket_interface_selection, bool multicast_registration)
{
internal_socket_t *this = ns_dyn_mem_alloc(sizeof(internal_socket_t));
if (!this) {
return NULL;
}
@ -266,7 +292,14 @@ static internal_socket_t *int_socket_create(uint16_t listen_port, bool use_ephem
// Set socket option to receive packet info
socket_setsockopt(this->socket, SOCKET_IPPROTO_IPV6, SOCKET_IPV6_RECVPKTINFO, &(const bool) {1}, sizeof(bool));
if (socket_interface_selection > 0) {
// Interface selection requested as socket_interface_selection set
socket_setsockopt(this->socket, SOCKET_IPPROTO_IPV6, SOCKET_INTERFACE_SELECT, &socket_interface_selection, sizeof(socket_interface_selection));
}
if (multicast_registration) {
coap_multicast_group_join_or_leave(this->socket, SOCKET_IPV6_JOIN_GROUP, socket_interface_selection);
}
} else {
this->socket = virtual_socket_id_allocate();
}
@ -773,9 +806,13 @@ coap_conn_handler_t *connection_handler_create(receive_from_socket_cb *recv_from
return handler;
}
void connection_handler_destroy(coap_conn_handler_t *handler)
void connection_handler_destroy(coap_conn_handler_t *handler, bool multicast_group_leave)
{
if(handler){
if (multicast_group_leave) {
coap_multicast_group_join_or_leave(handler->socket->socket, SOCKET_IPV6_LEAVE_GROUP, handler->socket_interface_selection);
}
int_socket_delete(handler->socket);
ns_dyn_mem_free(handler);
}
@ -810,7 +847,7 @@ int coap_connection_handler_open_connection(coap_conn_handler_t *handler, uint16
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);
handler->socket = int_socket_create(listen_port, use_ephemeral_port, is_secure, is_real_socket, bypassSec, handler->socket_interface_selection, handler->registered_to_multicast);
if (!handler->socket) {
return -1;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015-2016 ARM Limited. All Rights Reserved.
* Copyright (c) 2015-2017 ARM Limited. All Rights Reserved.
*/
#include <string.h>
@ -57,6 +57,18 @@ static coap_transaction_t *transaction_find_server(uint16_t msg_id)
return this;
}
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_by_address(uint8_t *address_ptr, uint16_t port)
{
coap_transaction_t *this = NULL;
@ -168,6 +180,10 @@ coap_msg_handler_t *coap_message_handler_init(void *(*used_malloc_func_ptr)(uint
used_free_func_ptr(handle);
return NULL;
}
/* Set default buffer size for CoAP duplicate message detection */
sn_coap_protocol_set_duplicate_buffer_size(handle->coap, DUPLICATE_MESSAGE_BUFFER_SIZE);
return handle;
}
@ -391,6 +407,28 @@ int8_t coap_message_handler_response_send(coap_msg_handler_t *handle, int8_t ser
return 0;
}
int8_t coap_message_handler_request_delete(coap_msg_handler_t *handle, int8_t service_id, uint16_t msg_id)
{
coap_transaction_t *transaction_ptr;
(void)service_id;
tr_debug("Service %d, delete CoAP request %d", service_id, msg_id);
if (!handle) {
tr_error("invalid params");
return -1;
}
sn_coap_protocol_delete_retransmission(handle->coap, msg_id);
transaction_ptr = transaction_find_client(msg_id);
if (!transaction_ptr) {
tr_error("response transaction not found");
return -2;
}
transaction_delete(transaction_ptr);
return 0;
}
int8_t coap_message_handler_exec(coap_msg_handler_t *handle, uint32_t current_time){
if( !handle ){

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015-2016 ARM Limited. All Rights Reserved.
* Copyright (c) 2015-2017 ARM Limited. All Rights Reserved.
*/
#include <string.h>

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015-2016 ARM Limited. All Rights Reserved.
* Copyright (c) 2015-2017 ARM Limited. All Rights Reserved.
*/
@ -21,6 +21,7 @@
#include "net_interface.h"
#include "coap_service_api_internal.h"
#include "coap_message_handler.h"
#include "mbed-coap/sn_coap_protocol.h"
static int16_t coap_msg_process_callback(int8_t socket_id, sn_coap_hdr_s *coap_message, coap_transaction_t *transaction_ptr);
@ -99,6 +100,27 @@ static coap_service_t *service_find_by_uri(uint8_t socket_id, uint8_t *uri_ptr,
return NULL;
}
static bool coap_service_can_leave_multicast_group(coap_conn_handler_t *conn_handler)
{
int mc_count = 0;
bool current_handler_joined_to_mc_group = false;
ns_list_foreach(coap_service_t, cur_ptr, &instance_list) {
if (cur_ptr->conn_handler && cur_ptr->conn_handler->registered_to_multicast) {
if (conn_handler == cur_ptr->conn_handler) {
current_handler_joined_to_mc_group = true;
}
mc_count ++;
}
}
if (mc_count == 1 && current_handler_joined_to_mc_group) {
// current handler is the only one joined to multicast group
return true;
}
return false;
}
/**
* Coap handling functions
@ -280,9 +302,8 @@ static int get_passwd_cb(int8_t socket_id, uint8_t address[static 16], uint16_t
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 *coap_security_done_cb)
{
(void) interface_id;
coap_service_t *this = ns_dyn_mem_alloc(sizeof(coap_service_t));
if (!this) {
return -1;
}
@ -293,6 +314,7 @@ int8_t coap_service_initialize(int8_t interface_id, uint16_t listen_port, uint8_
while (service_find(id) && id < 127) {
id++;
}
this->interface_id = interface_id;
this->service_id = id;
this->service_options = service_options;
@ -310,10 +332,18 @@ int8_t coap_service_initialize(int8_t interface_id, uint16_t listen_port, uint8_
return -1;
}
if (0 > 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))){
this->conn_handler->socket_interface_selection = 0; // zero is illegal interface ID
if (this->service_options & COAP_SERVICE_OPTIONS_SELECT_SOCKET_IF) {
this->conn_handler->socket_interface_selection = this->interface_id;
}
this->conn_handler->registered_to_multicast = this->service_options & COAP_SERVICE_OPTIONS_MULTICAST_JOIN;
if (0 > coap_connection_handler_open_connection(this->conn_handler, listen_port,
(this->service_options & COAP_SERVICE_OPTIONS_EPHEMERAL_PORT),
(this->service_options & COAP_SERVICE_OPTIONS_SECURE),
!(this->service_options & COAP_SERVICE_OPTIONS_VIRTUAL_SOCKET),
(this->service_options & COAP_SERVICE_OPTIONS_SECURE_BYPASS))) {
ns_dyn_mem_free(this->conn_handler);
ns_dyn_mem_free(this);
return -1;
@ -340,7 +370,12 @@ void coap_service_delete(int8_t service_id)
}
if (this->conn_handler){
connection_handler_destroy(this->conn_handler);
bool leave_multicast_group = false;
if (coap_service_can_leave_multicast_group(this->conn_handler)) {
// This is the last handler joined to multicast group
leave_multicast_group = true;
}
connection_handler_destroy(this->conn_handler, leave_multicast_group);
}
//TODO clear all transactions
@ -459,6 +494,11 @@ int8_t coap_service_response_send(int8_t service_id, uint8_t options, sn_coap_hd
return coap_message_handler_response_send(coap_service_handle, service_id, options, request_ptr, message_code, content_type, payload_ptr, payload_len);
}
int8_t coap_service_request_delete(int8_t service_id, uint16_t msg_id)
{
return coap_message_handler_request_delete(coap_service_handle, service_id, msg_id);
}
int8_t coap_service_set_handshake_timeout(int8_t service_id, uint32_t min, uint32_t max)
{
coap_service_t *this = service_find(service_id);
@ -469,6 +509,17 @@ int8_t coap_service_set_handshake_timeout(int8_t service_id, uint32_t min, uint3
return coap_connection_handler_set_timeout(this->conn_handler, min, max);
}
int8_t coap_service_set_duplicate_message_buffer(int8_t service_id, uint8_t size)
{
(void) service_id;
if (!coap_service_handle) {
return -1;
}
return sn_coap_protocol_set_duplicate_buffer_size(coap_service_handle->coap, size);
}
uint32_t coap_service_get_internal_timer_ticks(void)
{
return coap_ticks;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015 ARM Limited. All Rights Reserved.
* Copyright (c) 2015-2017 ARM Limited. All Rights Reserved.
*
* SPDX-License-Identifier: Apache-2.0
*
@ -44,6 +44,8 @@ typedef struct coap_conn_handler_s{
send_to_socket_cb *_send_cb;
get_pw_cb *_get_password_cb;
security_done_cb *_security_done_cb;
int8_t socket_interface_selection;
bool registered_to_multicast;
} coap_conn_handler_t;
coap_conn_handler_t *connection_handler_create(receive_from_socket_cb *recv_from_cb,
@ -51,7 +53,7 @@ coap_conn_handler_t *connection_handler_create(receive_from_socket_cb *recv_from
get_pw_cb *pw_cb,
security_done_cb *done_cb);
void connection_handler_destroy( coap_conn_handler_t *handler );
void connection_handler_destroy( coap_conn_handler_t *handler, bool multicast_group_leave);
void connection_handler_close_secure_connection( coap_conn_handler_t *handler, uint8_t destination_addr_ptr[static 16], uint16_t port );

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015-2016 ARM Limited. All Rights Reserved.
* Copyright (c) 2015-2017 ARM Limited. All Rights Reserved.
*
* SPDX-License-Identifier: Apache-2.0
*
@ -24,6 +24,8 @@
#include "ns_list.h"
#define TRANSACTION_LIFETIME 180
/* Default value for CoAP duplicate message buffer (0 = disabled) */
#define DUPLICATE_MESSAGE_BUFFER_SIZE 0
/**
* \brief Service message response receive callback.
@ -83,6 +85,8 @@ extern uint16_t coap_message_handler_request_send(coap_msg_handler_t *handle, in
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,
sn_coap_content_format_e content_type, const uint8_t *payload_ptr, uint16_t payload_len);
extern int8_t coap_message_handler_request_delete(coap_msg_handler_t *handle, int8_t service_id, uint16_t msg_id);
extern int8_t coap_message_handler_exec(coap_msg_handler_t *handle, uint32_t current_time);
extern void transaction_delete(coap_transaction_t *this);

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015-2016 ARM Limited. All Rights Reserved.
* Copyright (c) 2015-2017 ARM Limited. All Rights Reserved.
*
* SPDX-License-Identifier: Apache-2.0
*

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015 ARM. All rights reserved.
* Copyright (c) 2015-2017 ARM. All rights reserved.
*/
#include "CppUTest/TestHarness.h"
#include "test_coap_connection_handler.h"

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015 ARM. All rights reserved.
* Copyright (c) 2015-2017 ARM. All rights reserved.
*/
#include "CppUTest/CommandLineTestRunner.h"

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015-2016 ARM Limited. All Rights Reserved.
* Copyright (c) 2015-2017 ARM Limited. All Rights Reserved.
*/
#include "test_coap_connection_handler.h"
#include <string.h>
@ -57,7 +57,7 @@ bool test_connection_handler_destroy()
nsdynmemlib_stub.returnCounter = 1;
coap_conn_handler_t *handler = connection_handler_create(&receive_from_sock_cb, NULL, NULL, NULL);
connection_handler_destroy(handler);
connection_handler_destroy(handler, false);
return true;
}
@ -97,8 +97,8 @@ bool test_coap_connection_handler_open_connection()
if( 0 != coap_connection_handler_open_connection(handler, 23,false,false,false,false) )
return false;
connection_handler_destroy(handler2);
connection_handler_destroy(handler);
connection_handler_destroy(handler2, false);
connection_handler_destroy(handler, false);
return true;
}
@ -121,7 +121,7 @@ bool test_coap_connection_handler_send_data()
if( -1 != coap_connection_handler_send_data(handler, &addr, ns_in6addr_any, NULL, 0, true))
return false;
connection_handler_destroy(handler);
connection_handler_destroy(handler, false);
coap_security_handler_stub.sec_obj = coap_security_handler_stub_alloc();
@ -137,7 +137,7 @@ bool test_coap_connection_handler_send_data()
if( -1 != coap_connection_handler_send_data(handler, &addr, ns_in6addr_any, NULL, 0, true))
return false;
connection_handler_destroy(handler);
connection_handler_destroy(handler, false);
free(coap_security_handler_stub.sec_obj);
coap_security_handler_stub.sec_obj = NULL;
@ -152,7 +152,7 @@ bool test_coap_connection_handler_send_data()
if( 1 != coap_connection_handler_send_data(handler, &addr, ns_in6addr_any, NULL, 0, true))
return false;
connection_handler_destroy(handler);
connection_handler_destroy(handler ,false);
nsdynmemlib_stub.returnCounter = 1;
handler = connection_handler_create(&receive_from_sock_cb, &send_to_sock_cb, NULL, NULL);
@ -163,7 +163,7 @@ bool test_coap_connection_handler_send_data()
socket_api_stub.int8_value = 7;
if( 7 != coap_connection_handler_send_data(handler, &addr, ns_in6addr_any, NULL, 0, true))
return false;
connection_handler_destroy(handler);
connection_handler_destroy(handler, false);
//<-- NON SECURE HERE
@ -209,7 +209,7 @@ bool test_coap_connection_handler_virtual_recv()
if( -1 != coap_connection_handler_virtual_recv(handler,buf, 12, &buf, 1) )
return false;
connection_handler_destroy(handler);
connection_handler_destroy(handler, false);
nsdynmemlib_stub.returnCounter = 1;
coap_conn_handler_t *handler2 = connection_handler_create(&receive_from_sock_cb, &send_to_sock_cb, &get_passwd_cb, &sec_done_cb);
@ -235,7 +235,7 @@ bool test_coap_connection_handler_virtual_recv()
if( 0 != coap_connection_handler_virtual_recv(handler2,buf, 12, &buf, 1) )
return false;
connection_handler_destroy(handler2);
connection_handler_destroy(handler2, false);
free(coap_security_handler_stub.sec_obj);
coap_security_handler_stub.sec_obj = NULL;
@ -250,7 +250,7 @@ bool test_coap_connection_handler_virtual_recv()
if( 0 != coap_connection_handler_virtual_recv(handler3,buf, 12, &buf, 1) )
return false;
connection_handler_destroy(handler3);
connection_handler_destroy(handler3, false);
return true;
}
@ -273,7 +273,7 @@ bool test_coap_connection_handler_socket_belongs_to()
if( false != coap_connection_handler_socket_belongs_to(handler, 3) )
return false;
connection_handler_destroy(handler);
connection_handler_destroy(handler, false);
nsdynmemlib_stub.returnCounter = 0;
return true;
@ -326,7 +326,7 @@ bool test_timer_callbacks()
coap_security_handler_stub.int_value = 0;
}
connection_handler_destroy(handler);
connection_handler_destroy(handler, false);
free(coap_security_handler_stub.sec_obj);
coap_security_handler_stub.sec_obj = NULL;
return true;
@ -364,7 +364,7 @@ bool test_socket_api_callbacks()
socket_api_stub.recv_cb(sckt_data);
}
connection_handler_destroy(handler);
connection_handler_destroy(handler, false);
nsdynmemlib_stub.returnCounter = 1;
coap_conn_handler_t *handler2 = connection_handler_create(&receive_from_sock_cb, &send_to_sock_cb, &get_passwd_cb, &sec_done_cb);
@ -401,7 +401,7 @@ bool test_socket_api_callbacks()
socket_api_stub.recv_cb(sckt_data);
}
connection_handler_destroy(handler2);
connection_handler_destroy(handler2, false);
free(coap_security_handler_stub.sec_obj);
coap_security_handler_stub.sec_obj = NULL;
@ -444,7 +444,7 @@ bool test_security_callbacks()
coap_security_handler_stub.receive_cb(0, &buf, 16);
}
connection_handler_destroy(handler);
connection_handler_destroy(handler, false);
free(coap_security_handler_stub.sec_obj);
coap_security_handler_stub.sec_obj = NULL;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015 ARM Limited. All Rights Reserved.
* Copyright (c) 2015-2017 ARM Limited. All Rights Reserved.
*
* SPDX-License-Identifier: Apache-2.0
*

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015 ARM. All rights reserved.
* Copyright (c) 2015-2017 ARM. All rights reserved.
*/
#include "CppUTest/TestHarness.h"
#include "test_coap_message_handler.h"
@ -45,8 +45,14 @@ 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_request_delete)
{
CHECK(test_coap_message_handler_request_delete());
}
TEST(coap_message_handler, test_coap_message_handler_exec)
{
CHECK(test_coap_message_handler_exec());
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015 ARM. All rights reserved.
* Copyright (c) 2015-2017 ARM. All rights reserved.
*/
#include "CppUTest/CommandLineTestRunner.h"

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015 ARM Limited. All Rights Reserved.
* Copyright (c) 2015-2017 ARM Limited. All Rights Reserved.
*/
#include "test_coap_message_handler.h"
#include <string.h>
@ -229,6 +229,39 @@ bool test_coap_message_handler_request_send()
return true;
}
bool test_coap_message_handler_request_delete()
{
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_delete(NULL, 1, 1))
return false;
if( 0 == coap_message_handler_request_delete(handle, 1, 1))
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;
if( 0 != coap_message_handler_request_delete(handle, 1, 2))
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))

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015 ARM Limited. All Rights Reserved.
* Copyright (c) 2015-2017 ARM Limited. All Rights Reserved.
*
* SPDX-License-Identifier: Apache-2.0
*
@ -30,6 +30,7 @@ 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_request_delete();
bool test_coap_message_handler_exec();
#ifdef __cplusplus

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015 ARM. All rights reserved.
* Copyright (c) 2015-2017 ARM. All rights reserved.
*/
#include "CppUTest/TestHarness.h"
#include "test_coap_security_handler.h"

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015 ARM. All rights reserved.
* Copyright (c) 2015-2017 ARM. All rights reserved.
*/
#include "CppUTest/CommandLineTestRunner.h"

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015-2016 ARM Limited. All Rights Reserved.
* Copyright (c) 2015-2017 ARM Limited. All Rights Reserved.
*/
#include "test_coap_security_handler.h"
#include "coap_security_handler.h"

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015 ARM Limited. All Rights Reserved.
* Copyright (c) 2015-2017 ARM Limited. All Rights Reserved.
*
* SPDX-License-Identifier: Apache-2.0
*

View File

@ -17,7 +17,8 @@ TEST_SRC_FILES = \
../stub/eventOS_event_stub.c \
../stub/coap_connection_handler_stub.c \
../stub/coap_message_handler_stub.c \
../stub/common_functions_stub.c
../stub/common_functions_stub.c \
../stub/sn_coap_protocol_stub.c
include ../MakefileWorker.mk

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015 ARM. All rights reserved.
* Copyright (c) 2015-2017 ARM. All rights reserved.
*/
#include "CppUTest/TestHarness.h"
#include "test_coap_service_api.h"
@ -50,6 +50,11 @@ TEST(coap_service_api, test_coap_service_request_send)
CHECK(test_coap_service_request_send());
}
TEST(coap_service_api, test_coap_service_request_delete)
{
CHECK(test_coap_service_request_delete());
}
TEST(coap_service_api, test_coap_service_response_send)
{
CHECK(test_coap_service_response_send());

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015 ARM. All rights reserved.
* Copyright (c) 2015-2017 ARM. All rights reserved.
*/
#include "CppUTest/CommandLineTestRunner.h"

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015 ARM Limited. All Rights Reserved.
* Copyright (c) 2015-2017 ARM Limited. All Rights Reserved.
*/
#include "test_coap_service_api.h"
#include <string.h>
@ -215,6 +215,13 @@ bool test_coap_service_request_send()
return true;
}
bool test_coap_service_request_delete()
{
if( 0 != coap_service_request_delete(NULL,0))
return false;
return true;
}
bool test_coap_service_response_send()
{
uint8_t buf[16];

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015 ARM Limited. All Rights Reserved.
* Copyright (c) 2015-2017 ARM Limited. All Rights Reserved.
*
* SPDX-License-Identifier: Apache-2.0
*
@ -38,6 +38,8 @@ bool test_coap_service_unregister_uri();
bool test_coap_service_request_send();
bool test_coap_service_request_delete();
bool test_coap_service_response_send();
bool test_coap_callbacks();

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015 ARM Limited. All Rights Reserved.
* Copyright (c) 2015-2017 ARM Limited. All Rights Reserved.
*/
#include <string.h>
@ -32,7 +32,7 @@ coap_conn_handler_t *connection_handler_create(int (*recv_cb)(int8_t socket_id,
return thread_conn_handler_stub.handler_obj;
}
void connection_handler_destroy(coap_conn_handler_t *handler)
void connection_handler_destroy( coap_conn_handler_t *handler, bool multicast_group_leave)
{
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015 ARM Limited. All Rights Reserved.
* Copyright (c) 2015-2017 ARM Limited. All Rights Reserved.
*
* SPDX-License-Identifier: Apache-2.0
*

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015-2016 ARM Limited. All Rights Reserved.
* Copyright (c) 2015-2017 ARM Limited. All Rights Reserved.
*/
#include "coap_message_handler_stub.h"
@ -60,6 +60,11 @@ int8_t coap_message_handler_response_send(coap_msg_handler_t *handle, int8_t ser
return coap_message_handler_stub.int8_value;
}
int8_t coap_message_handler_request_delete(coap_msg_handler_t *handle, int8_t service_id, uint16_t msg_id)
{
return 0;
}
int8_t coap_message_handler_exec(coap_msg_handler_t *handle, uint32_t current_time)
{
return coap_message_handler_stub.int8_value;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015 ARM Limited. All Rights Reserved.
* Copyright (c) 2015-2017 ARM Limited. All Rights Reserved.
*
* SPDX-License-Identifier: Apache-2.0
*

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015-2016 ARM Limited. All Rights Reserved.
* Copyright (c) 2015-2017 ARM Limited. All Rights Reserved.
*/
#include <string.h>

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015-2016 ARM Limited. All Rights Reserved.
* Copyright (c) 2015-2017 ARM Limited. All Rights Reserved.
*
* SPDX-License-Identifier: Apache-2.0
*

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015-2016 ARM Limited. All Rights Reserved.
* Copyright (c) 2015-2017 ARM Limited. All Rights Reserved.
*/
#include <string.h>

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015 ARM Limited. All Rights Reserved.
* Copyright (c) 2015-2017 ARM Limited. All Rights Reserved.
*/
#include <string.h>

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015 ARM Limited. All Rights Reserved.
* Copyright (c) 2015-2017 ARM Limited. All Rights Reserved.
*
* SPDX-License-Identifier: Apache-2.0
*

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2014-2015 ARM Limited. All rights reserved.
* Copyright (c) 2014-2017 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.

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015 ARM Limited. All Rights Reserved.
* Copyright (c) 2015-2017 ARM Limited. All Rights Reserved.
*/
#include "mbedtls_stub.h"

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015 ARM Limited. All Rights Reserved.
* Copyright (c) 2015-2017 ARM Limited. All Rights Reserved.
*
* SPDX-License-Identifier: Apache-2.0
*

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015 ARM Limited. All Rights Reserved.
* Copyright (c) 2015-2017 ARM Limited. All Rights Reserved.
*/
#define NS_LIST_FN extern

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2014-2015 ARM Limited. All Rights Reserved.
* Copyright (c) 2014-2017 ARM Limited. All Rights Reserved.
*/
#include "ns_types.h"
#include "ns_list.h"

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015 ARM Limited. All Rights Reserved.
* Copyright (c) 2015-2017 ARM Limited. All Rights Reserved.
*
* SPDX-License-Identifier: Apache-2.0
*

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2014-2015 ARM Limited. All Rights Reserved.
* Copyright (c) 2014-2017 ARM Limited. All Rights Reserved.
*/
#include "nsdynmemLIB_stub.h"
#include <stdint.h>
@ -10,11 +10,19 @@
nsdynmemlib_stub_data_t nsdynmemlib_stub;
#if NSDYNMEMLIB_API_VERSION < 2
typedef int16_t ns_mem_block_size_t;
typedef int16_t ns_mem_heap_size_t;
void ns_dyn_mem_init(uint8_t *heap, uint16_t h_size, void (*passed_fptr)(heap_fail_t), mem_stat_t *info_ptr)
{
}
#else
void ns_dyn_mem_init(void *heap, uint16_t h_size, void (*passed_fptr)(heap_fail_t), mem_stat_t *info_ptr)
{
}
#endif
void *ns_dyn_mem_alloc(int16_t alloc_size)
void *ns_dyn_mem_alloc(ns_mem_block_size_t alloc_size)
{
if (nsdynmemlib_stub.returnCounter > 0)
{
@ -27,7 +35,7 @@ void *ns_dyn_mem_alloc(int16_t alloc_size)
}
}
void *ns_dyn_mem_temporary_alloc(int16_t alloc_size)
void *ns_dyn_mem_temporary_alloc(ns_mem_block_size_t alloc_size)
{
if (nsdynmemlib_stub.returnCounter > 0)
{

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015 ARM Limited. All Rights Reserved.
* Copyright (c) 2015-2017 ARM Limited. All Rights Reserved.
*
* SPDX-License-Identifier: Apache-2.0
*
@ -31,11 +31,6 @@ typedef struct {
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

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2014-2015 ARM Limited. All Rights Reserved.
* Copyright (c) 2014-2017 ARM Limited. All Rights Reserved.
*/
#include <stdint.h>
#include <stdlib.h>

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2011-2015 ARM Limited. All Rights Reserved.
* Copyright (c) 2011-2017 ARM Limited. All Rights Reserved.
*/
/**

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015 ARM Limited. All Rights Reserved.
* Copyright (c) 2015-2017 ARM Limited. All Rights Reserved.
*
* SPDX-License-Identifier: Apache-2.0
*

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2011-2015 ARM Limited. All Rights Reserved.
* Copyright (c) 2011-2017 ARM Limited. All Rights Reserved.
*/
/**

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015 ARM Limited. All Rights Reserved.
* Copyright (c) 2015-2017 ARM Limited. All Rights Reserved.
*
* SPDX-License-Identifier: Apache-2.0
*

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2011-2015 ARM Limited. All Rights Reserved.
* Copyright (c) 2011-2017 ARM Limited. All Rights Reserved.
*/

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015 ARM Limited. All Rights Reserved.
* Copyright (c) 2015-2017 ARM Limited. All Rights Reserved.
*
* SPDX-License-Identifier: Apache-2.0
*

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015 ARM Limited. All Rights Reserved.
* Copyright (c) 2015-2017 ARM Limited. All Rights Reserved.
*/
#include "socket_api.h"
#include "socket_api_stub.h"

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015 ARM Limited. All Rights Reserved.
* Copyright (c) 2015-2017 ARM Limited. All Rights Reserved.
*
* SPDX-License-Identifier: Apache-2.0
*

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2014-2015 ARM Limited. All Rights Reserved.
* Copyright (c) 2014-2017 ARM Limited. All Rights Reserved.
*/
#include "ns_types.h"
#include "timer_sys.h"

View File

@ -1,6 +1,6 @@
#!/bin/bash
# Copyright (c) 2015 ARM Limited. All rights reserved.
# Copyright (c) 2015-2017 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.

View File

@ -45,4 +45,6 @@ The reference manual contains several chapters; you can read them in sequence, b
14. [**Load balancing API**](17_API_load_balancer.md):Read this to familiarize yourself with the Load balancing API
15. [**Warm restart**](18_warm_restart.md):Read this to familiarize yourself with the Warm restart feature

View File

@ -462,3 +462,73 @@ Parameter|Description
<dd>0 Success.</dd>
<dd>-1 Failure.</dd>
</dl>
```
int8_t net_nvm_data_clean
(
int8_t interface_id
);
```
Parameter|Description
---------|-----------
`interface_id`|The 6LoWPAN interface ID.
<dl>
<dt>Return value:</dt>
<dd>0 Success.</dd>
<dd>-1 Failure.</dd>
</dl>
```
int8_t net_nvm_wpan_params_storage_enable
(
int8_t interface_id,
wpan_params_updated *nvm_update_cb,
wpan_params_get *nvm_get_cb
);
```
Parameter|Description
---------|-----------
`interface_id`|The 6LoWPAN interface ID.
<dl>
<dt>Return value:</dt>
<dd>0 Success.</dd>
<dd>-1 Failure.</dd>
<dd>-2 OOM Failure.</dd>
</dl>
```
int8_t net_nvm_wpan_params_storage_reset
(
int8_t interface_id
);
```
Parameter|Description
---------|-----------
`interface_id`|The 6LoWPAN interface ID.
<dl>
<dt>Return value:</dt>
<dd>0 Success.</dd>
<dd>-1 Failure.</dd>
</dl>
```
int8_t net_nvm_wpan_params_storage_disable
(
int8_t interface_id
);
```
Parameter|Description
---------|-----------
`interface_id`|The 6LoWPAN interface ID.
<dl>
<dt>Return value:</dt>
<dd>0 Success.</dd>
<dd>-1 Failure.</dd>
</dl>

View File

@ -89,7 +89,7 @@ Event type|Description
`SOCKET_TX_FAIL`|Socket data send failed.
`SOCKET_CONNECT_CLOSED`|TCP connection closed.
`SOCKET_CONNECTION_RESET`|TCP connection reset.
`SOCKET_NO_ROUTER`|No route available to destination.
`SOCKET_NO_ROUTE`|No route available to destination.
`SOCKET_TX_DONE`|TX process done (one per datagram, or if stream will be called each time some data acknowledged)
`SOCKET_NO_RAM `|If no RAM is present.
`SOCKET_CONNECTION_PROBLEM`|If TCP is suffering a connection problem (a soft event, it continues to retry).
@ -103,7 +103,7 @@ An example parsing socket event:
static uint8_t rx_buffer[APP_SOCK_RX_SIZE];
void main_receive
(SOCKET_NO_ROUTER
(SOCKET_NO_ROUTE
void *cb
)
{

View File

@ -12,6 +12,7 @@ This chapter describes the functions of the network control layer. It contains t
- [_RPL structures and definitions API_](#rpl-structures-and-definitions-api)
- [_RPL root configuration API_](#rpl-root-configuration-api)
- [_NET address retrieval API_](#net-address-retrieval-api)
- [_IPv6 API_](#ipv6-api)
- [_MLE router and host lifetime configuration API_](#mle-router-and-host-lifetime-configuration-api)
- [_MLE neighbor limits configuration API_](#mle-neighbor-limits-configuration-api)
- [_MLE token bucket configuration API_](#mle-token-bucket-configuration-api)
@ -223,19 +224,19 @@ typedef enum
### Channel hopping mode
Two hopping modes:
There are two hopping modes:
- Single channel (non-hopping)
* After the network scan, the node changes to the channel from which it found the best available network.
- FHSS
- Single channel (non-hopping).
* After the network scan, the node changes to the channel with the best available network.
- FHSS.
* Frequency hopping mode.
* After the network scan, the node synchronizes to the best available network and starts continuous channel hopping using a predefined channel list.
By default, the 6LoWPAN stack uses the single channel mode.
To enable the FHSS mode, FHSS instance must be created, configured and registered to software MAC instance.
To enable the FHSS mode, you need to create, configure and register a FHSS instance to the software MAC instance.
Create FHSS instance and set basic configuration using:
To create a FHSS instance and set the basic configuration, use:
```
fhss_api_t *ns_fhss_create
@ -246,34 +247,34 @@ fhss_api_t *ns_fhss_create
)
```
Application developer must implement FHSS platform timer functions as described below. FHSS timer uses 1us resolution if not reduced by resolution divider.
An application developer must implement the FHSS platform timer functions as described below. The FHSS timer uses 1us resolution if not reduced by the resolution divider.
Member|Description
------|-----------
`fhss_timer_start` | FHSS timer start platform function.
`fhss_timer_stop` | FHSS timer stop platform function.
`fhss_get_remaining_slots` | FHSS timer get remaining slots platform function.
`fhss_get_timestamp` | FHSS timer timestamp (since initialization of driver).
`fhss_get_timestamp` | FHSS timer timestamp read.
`fhss_resolution_divider` | FHSS timer resolution divider.
FHSS basic configuration is described below.
The basic configuration for FHSS:
Member|Description
------|-----------
`fhss_tuning_parameters` | Tuning parameters to enhance synchronization accuracy.
`fhss_max_synch_interval` | Maximum used interval for requesting synchronization info from FHSS parent device.
`fhss_max_synch_interval` | Maximum interval for requesting synchronization info from a FHSS parent device.
`fhss_number_of_channel_retries` | Number of channel retries.
`channel_mask` | Channel mask.
Some platform-specific tuning parameters can be provided:
You can provide platform-specific tuning parameters:
Parameter|Description
---------|-----------
`tx_processing_delay` | Delay between data pushed to PHY TX function and TX started (Contains CSMA-CA maximum random period).
`tx_processing_delay` | Delay between data pushed to PHY TX function and TX started (contains CSMA-CA maximum random period).
`rx_processing_delay` | Delay between TX done (by transmitter) and received data pushed to MAC (by receiver).
`ack_processing_delay` | Delay between TX done (by transmitter) and Ack transmission started (by receiver).
`ack_processing_delay` | Delay between TX done (by transmitter) and ACK transmission started (by receiver).
FHSS synchronization configuration is always given from the border router using the `ns_fhss_configuration_set` function. The endpoint learns the configuration from the received synchronization message.
The FHSS synchronization configuration is always given from the border router using the `ns_fhss_configuration_set` function. The endpoint learns the configuration from the received synchronization message.
```
int ns_fhss_configuration_set
@ -282,7 +283,7 @@ int ns_fhss_configuration_set
const fhss_synch_configuration_t *fhss_synch_configuration
)
```
Synchronization configuration is described below:
Synchronization configuration:
Member|Description
------|-----------
@ -291,7 +292,7 @@ Member|Description
`fhss_superframe_length` | Superframe dwell time (us).
`fhss_number_of_superframes` | Number of superframes per channel.
Register created FHSS instance to software MAC instance using `ns_sw_mac_fhss_register` function:
To register the created FHSS instance to software MAC instance, use the `ns_sw_mac_fhss_register` function:
```
int ns_sw_mac_fhss_register
(
@ -300,24 +301,24 @@ int ns_sw_mac_fhss_register
)
```
FHSS implements following API which is used by higher layer (software MAC):
FHSS implements the following API used by the higher layer (software MAC):
Member|Description
------|-----------
`fhss_is_broadcast_channel` | Checks if current channel is broadcast channel.
`fhss_use_broadcast_queue` | Checks if broadcast queue must be used instead of unicast queue.
`fhss_tx_handle` | Set destination channel and write synchronization info.
`fhss_is_broadcast_channel` | Checks if the current channel is a broadcast channel.
`fhss_use_broadcast_queue` | Checks if a broadcast queue must be used instead of a unicast queue.
`fhss_tx_handle` | Set the destination channel and write synchronization info.
`fhss_check_tx_conditions` | Check TX permission.
`fhss_receive_frame` | Notification of received FHSS synch or synch request frame.
`fhss_data_tx_done` | Data TX done callback.
`fhss_data_tx_fail` | Data TX or CCA failed callback.
`fhss_synch_state_set` | Change synchronization state.
`fhss_read_timestamp` | Read timestamp.
`fhss_get_retry_period` | Get retransmission period.
`fhss_synch_state_set` | Change the synchronization state.
`fhss_read_timestamp` | Read the timestamp.
`fhss_get_retry_period` | Get the retransmission period.
`fhss_init_callbacks` | Initialize MAC functions.
Software MAC implements following callbacks to serve requests from FHSS:
The software MAC implements the following callbacks to serve requests from FHSS:
Member|Description
------|-----------
@ -326,12 +327,12 @@ Member|Description
`mac_read_datarate` | Read PHY datarate.
`mac_change_channel` | Change channel.
`mac_send_fhss_frame` | Send FHSS frame.
`mac_synch_lost_notification` | Send notification when FHSS synchronization is lost.
`mac_synch_lost_notification` | Send a notification when FHSS synchronization is lost.
`mac_tx_poll` | Poll TX queue.
`mac_broadcast_notify` | Broadcast channel notification from FHSS.
`mac_read_coordinator_mac_address` | Read coordinator MAC address.
`mac_read_coordinator_mac_address` | Read the coordinator MAC address.
To disable FHSS, instance can be deleted using `ns_fhss_delete` function.
To disable FHSS, you can delete an instance using the `ns_fhss_delete` function.
```
int ns_fhss_delete
(
@ -646,6 +647,8 @@ All configuration calls (such as channel selection) must be performed before cal
### IPv6 bootstrap configure
#### IPv6 bootstrap configuration
To configure the IPv6 bootstrap:
```
@ -660,7 +663,7 @@ int8_t arm_nwk_interface_configure_ipv6_bootstrap_set
Parameter|Description
---------|-----------
`interface_id`|The network interface ID.
`bootstrap_mode`|Values to start the bootstrap mode:<br>
`bootstrap_mode`|Values to start the bootstrap mode.
`NET_IPV6_BOOTSTRAP_STATIC`|The application defines the IPv6 prefix.
`ipv6_prefix_pointer`|A pointer to a 64-bit IPv6 prefix.
@ -672,9 +675,34 @@ Parameter|Description
The `arm_nwk_interface_up()` function call starts the stack bootstrap process and performs neighbour discovery.
#### Accept Router Advertisements
You can change the setting when an interface is created. If you change the setting you must do it before the bootstrap is started.
```
int8_t arm_nwk_interface_accept_ipv6_ra
(
int8_t interface_id,
net_ipv6_accept_ra_e accept_ra
)
```
Parameter|Description
---------|-----------
`interface_id`|The network interface ID.
`accept_ra`|Router Advertisements handling mode:<br>`NET_IPV6_RA_ACCEPT_IF_AUTONOMOUS` Accept Router Advertisements when using autonomous IPv6 address allocation. Ignore when using a static address. This is the default value for the setting.<br>`NET_IPV6_RA_ACCEPT_ALWAYS` Accept Router Advertisements always, even when using static IPv6 address allocation.
<dl>
<dt>Return value</dt>
<dd>>=0 Setting done.</dd>
<dd><0 Failed (for example an invalid interface ID).</dd>
</dl>
### Security mode for RF link layer
To set a security mode for the link layer of a configured network interface:
To set the security mode for the link layer of a configured network interface:
```
int8_t arm_nwk_link_layer_security_mode
@ -689,7 +717,7 @@ int8_t arm_nwk_link_layer_security_mode
Parameter|Description
---------|-----------
`interface_id`|The network interface ID.
`mode`|Defines the security mode for the link layer:<br>`NET_SEC_MODE_NO_SECURITY`, security is disabled.<br>`NET_SEC_MODE_PSK_LINK_SECURITY`, security is enabled with selected mode and PSK key info.<br>`NET_SEC_MODE_PANA_LINK_SECURITY`, link layer keys are defined by the PANA authentication server.
`mode`|Defines the security mode for the link layer:<br>`NET_SEC_MODE_NO_SECURITY`, security is disabled.<br>`NET_SEC_MODE_PSK_LINK_SECURITY`, security is enabled with selected mode and PSK key info.<br>`NET_SEC_MODE_PANA_LINK_SECURITY`, PANA authentication server defines the link layer keys.
`sec_level`|Supported values are 1 to 7. This parameter is only checked when the mode is `NET_SEC_MODE_PSK_LINK_SECURITY`.
`psk_key_info`|A pointer to PSK key material: key and key ID. This parameter is only checked when the mode is `NET_SEC_MODE_PSK_LINK_SECURITY`.

View File

@ -0,0 +1,59 @@
The warm restart feature
========================
This chapter describes the functionality of the warm restart feature. It contains the following sections:
- [_Application configuration_](#application-configuration)
- [_mbed TLS configuration_](#mbed-tls-configuration)
## Application configuration
This section describes the functionalities needed to enable load balancing from an application.
### NVM storage
To use the warm restart feature, your device needs to have non-volatile memory (NVM) available. The security parameters are stored into it, so a secure storage should be used when possible. The application must control the data storing intervals. If you are using a flash drive, you should save scarsely to ensure a long lifetime for it.
### WPAN & PANA configuration
To understand how to configure WPAN & PANA to receive security parameters, refer to [Network Definition APIs](09_API_network_def.md). Basically, you need to register callback functions for both to receive security paramaeters whenever they change.
<span class="notes">**Note:** WPAN parameters change very often. Make sure to store them regularly.</span>
To register WPAN callbacks, use the following function:
```
net_nvm_wpan_params_storage_enable
```
To register PANA callbacks, use one of the following functions (based on the type of device):
```
pana_client_nvm_callback_set
pana_server_nvm_callback_set
```
## mbed TLS configuration
This section describes the needed configuration for mbed TLS to use the warm restart feature.
<span class="notes">**Note:** The server side must support mbed TLS session caching for warm restart to work. There is no extra logic needed even if the server does not support session caching (full handshake is performed every time).</span>
Every device initially "cold starts", meaning that a full handshake is performed with server. After the full handshake, the session parameters can be fetched by calling:
```
mbedtls_ssl_get_session (See mbedtls/ssl.h for details)
```
When the SSL session details are known, call the function:
```
mbedtls_ssl_set_session (See mbedtls/ssl.h for details),
```
Finally, to enable "session id" based SSL resume, call:
```
mbedtls_ssl_handshake_step,
```

View File

@ -1,41 +1,107 @@
# Device Driver API
The 6LoWPAN stack uses Device Driver API to communicate with different physical layer drivers. The 6LoWPAN stack supports different device types for PHY layer and special cases where raw IPv6 datagrams are forwarded to a driver.
The driver must first be registered with the 6LoWPAN stack using the `phy_device_driver_s` structure defined in section [_PHY device driver register_](#phy-device-driver-register). This structure defines all the functions that a stack uses in calling a device driver. When the device driver must call the driver API from the stack, it uses the ID number received in the registration phase to distinct between different devices. The following sections define the contents of the driver structures and API interfaces that the driver can use.
The driver must first be registered with the 6LoWPAN stack using the `phy_device_driver_s` structure defined in section [_PHY device driver register_](#phy-device-driver-register). This structure defines all the functions that the stack uses when calling a device driver. When the device driver must call the driver API from the stack, it uses the ID number received in the registration phase to distinct between different devices. The following sections define the contents of the driver structures and API interfaces that the driver can use.
See Doxygen documentation for the latest [Device Drive API](https://docs.mbed.com/docs/arm-ipv66lowpan-stack/en/latest/api/arm__hal__phy_8h.html)
See Doxygen documentation for the latest [Device Drive API](https://docs.mbed.com/docs/arm-ipv66lowpan-stack/en/latest/api/arm__hal__phy_8h.html).
## Providing RF driver for Mbed OS applications
For Mbed OS 5, the RF driver implements the `NanostackRfPhy` API. `MeshInterfaceNanostack` requires the driver object to be provided when initializing.
![NanostackRfPhy](img/NanostackRfPhy.png)
Applications use only `LoWPANNDInterface`, `ThreadInterface` or `NanostackEthernetInterface`
directly to set up the network and provide a driver. The rest of the classes provide an abstration
between Nanostack and the socket layers of Mbed OS.
See [NanostackRfPhy.h](https://github.com/ARMmbed/mbed-os/blob/master/features/nanostack/FEATURE_NANOSTACK/nanostack-interface/NanostackRfPhy.h) for an up-to-date header file and API.
### How to create a new RF driver
The following steps describe how you can create a new RF driver.
The following steps describe how you can create a new RF driver:
1. Read through the section [_Example RF driver_](#example-rf-driver). You can use this example code as your starting point.
2. Fill in the actual transceiver-specific parts of the RF driver.
1. Fill in the actual transceiver-specific parts of the RF driver.
3. Register the driver to the 6LoWPAN stack on your application. You can use the example node applications with your driver.
1. Register the driver to the 6LoWPAN stack on your application. You can use the example node applications with your driver.
4. Create a MAC that is suitable for your purpose (802.15.4, Ethernet or serial).
1. Create a MAC that is suitable for your purpose (802.15.4, Ethernet or serial).
5. Configure the interface. See instructions in section _How to configure a network interface_ of the chapter [_6LoWPAN stack Initialisation_](07_API_initialize.md#how-to-configure-a-network-interface).
1. Configure the interface. See instructions in the chapter [_6LoWPAN stack Initialisation_](07_API_initialize.md#how-to-configure-a-network-interface).
6. Check with a RF sniffer tool that you can see RF packets transmitted when you start your device. The 6LoWPAN bootstrap should start with IEEE 802.15.4 Beacon Request packets.
1. Implement the `NanostackRfPhy` API.
1. Check with a RF sniffer tool that you can see RF packets transmitted when you start your device. The 6LoWPAN bootstrap should start with IEEE 802.15.4 Beacon Request packets.
#### Worker thread for Mbed OS
Nanostack's interfaces use mutexes for protecting the access from multiple threads. In Mbed OS, the mutex cannot be used
from an interrupt. The same applies to all APIs that have internal locking and multithread support. Therefore, each driver must implement their own worker thread to handle the interrupt requests.
![Worker Thread](img/worker_thread.png)
Example: Use worked thread and signals from an interrupt
```
// Signals from interrupt routines
#define SIG_RADIO 1
#define SIG_TIMER 2
// Worker thread
Thread irq_thread;
// Interrupt routines
static void rf_interrupt(void)
{
irq_thread.signal_set(SIG_RADIO);
}
static void rf_timer_signal(void)
{
irq_thread.signal_set(SIG_TIMER);
}
// Worker thread
void rf_worker_thread(void)
{
for (;;) {
osEvent event = irq_thread.signal_wait(0);
if (event.status != osEventSignal) {
continue;
}
if (event.value.signals & SIG_RADIO) {
rf_process_irq();
}
if (event.value.signals & SIG_TIMER) {
rf_process_timer();
}
}
}
...
// Somewhere in the initialization code
irq_thread.start(rf_if_irq_task);
```
### RF driver states
_Figure 11-1_ below shows the basic states of the RF driver.
The following describes the basic states in more detail:
The basic states in more detail:
State|Description
-----|-----------
`DOWN`|This is the initial state of the driver. The radio is not used in this state.
`RX ACTIVE`|In this state, the driver has the radio turned on and it can receive a packet or ACK from the radio. The driver can also go from this state to the TX ACTIVE state to transmit a packet.
`RX ACTIVE`|In this state, the driver has the radio turned on and it can receive a packet or ACK from the radio. The driver can also go from this state to the `TX ACTIVE` state to transmit a packet.
`TX ACTIVE`|In this state, the driver will try to start a transmission:<br>1. It must first check that it is not currently busy doing something else.<br>2. It must check that the channel is free.<br>3. Finally, it can try to transmit the packet.
`SNIFFER`|This mode can be implemented to enable using the device as a packet sniffer. In this state, the RX is always on and the received packets are sent to the application layer but nothing is transmitted back.
`ED SCAN`|This mode can be implemented to enable using energy scan. It enables scanning the energy from channels one by one and nothing else.
`ED SCAN`|This mode can be implemented to enable energy scan. It enables scanning the energy from channels one by one and nothing else.
`ANY STATE`|This state represents all the states in the state machine.
<span class="notes">**Note**: The driver [initialization and registration](#phy-device-driver-register) using the function `arm_net_phy_register` must be performed before the driver is functional.</span>
@ -84,7 +150,7 @@ To register a PHY driver to the stack:
int8_t arm_net_phy_register(phy_device_driver_s *phy_driver);
```
See: [Doxygen](https://docs.mbed.com/docs/arm-ipv66lowpan-stack/en/latest/api/arm__hal__phy_8h.html#aff06eaa736d3784c956dc6eda9f27419) for description.
See the [Doxygen](https://docs.mbed.com/docs/arm-ipv66lowpan-stack/en/latest/api/arm__hal__phy_8h.html#aff06eaa736d3784c956dc6eda9f27419) for the description.
### PHY data RX API

Binary file not shown.

After

Width:  |  Height:  |  Size: 52 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

Some files were not shown because too many files have changed in this diff Show More