Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions features/FEATURE_COMMON_PAL/mbed-trace/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -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
*
Expand Down Expand Up @@ -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

Expand All @@ -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.
*
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -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>
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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>
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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 ){
Expand Down
Original file line number Diff line number Diff line change
@@ -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>
Expand Down
Loading