Skip to content

Nanostack release for Mbed OS 5.11 #8647

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 22 commits into from
Nov 16, 2018
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
66620a2
Merge commit '0ca91df5905111270a6ec1343be5c726c97fe571' into mbedos511
Nov 5, 2018
0ca91df
Squashed 'features/frameworks/nanostack-libservice/' changes from 5eb…
Nov 5, 2018
7fab5ab
Squashed 'features/frameworks/mbed-trace/' changes from 6df2572..9eaf0d1
Nov 5, 2018
d7e2bd3
Merge commit '7fab5abace6aa9d6fc6c335fa6fcab15a108d646' into mbedos511
Nov 5, 2018
3c37456
Merge commit '6a6dc452aa482a87421de660b3c57590cd43d6fa' into mbedos511
Nov 5, 2018
6a6dc45
Squashed 'features/nanostack/coap-service/' changes from cbe656a..bc3…
Nov 5, 2018
ef39a19
Merge commit '6dd01c679db4deb0a4a2c55832f3abe7b19bc51b' into mbedos511
Nov 5, 2018
6dd01c6
Squashed 'features/nanostack/sal-stack-nanostack/' changes from 2535a…
Nov 5, 2018
2457efc
Remove sal-stack-nanostack-eventloop
Nov 9, 2018
623607c
Squashed 'features/nanostack/sal-stack-nanostack-eventloop/' content …
Nov 9, 2018
9e661a9
Merge commit '623607c9da4ccd5cc1d3d75ff185b3f8d29a473b' as 'features/…
Nov 9, 2018
72fc5fa
Remove mbed-client-randlib
Nov 9, 2018
5d162a0
Squashed 'features/frameworks/mbed-client-randlib/' content from comm…
Nov 9, 2018
ce2ecd5
Merge commit '5d162a08ffd383c97b49e35f3065fcd4638ac87c' as 'features/…
Nov 9, 2018
1374a5e
Squashed 'features/frameworks/mbed-trace/' changes from 9eaf0d1..7a1bd34
Nov 9, 2018
9a13e9d
Merge commit '1374a5e5e6775dd6db9533075f25b3112c984b22' into mbedos511
Nov 9, 2018
e6a851f
Squashed 'features/nanostack/coap-service/' changes from bc331ca..c45…
Nov 9, 2018
e1ef0e4
Merge commit 'e6a851f0a7310462f5f65e9f7955f9fdc71b84f0' into mbedos511
Nov 9, 2018
661681f
Squashed 'features/frameworks/nanostack-libservice/' changes from bb5…
Nov 10, 2018
923ce13
Merge commit '661681f65c3fb61aec2e4605bef0fc075cc8cb0d' into mbedos511
Nov 10, 2018
7781856
Squashed 'features/nanostack/sal-stack-nanostack/' changes from ccd30…
Nov 10, 2018
d879422
Merge commit '77818568c6d9389ef1eb82e40ebfbbf26626c9d3' into mbedos511
Nov 10, 2018
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
37 changes: 37 additions & 0 deletions features/frameworks/mbed-trace/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,43 @@ Set the output function, `printf` by default:
mbed_trace_print_function_set(printf)
```

### Tracing level

Run time tracing level is set using `mbed_trace_set_config()` function. Possible levels and examples how to set them is presented below.

```c
//mbed_trace_config_set(TRACE_ACTIVE_LEVEL_ALL);
//mbed_trace_config_set(TRACE_ACTIVE_LEVEL_DEBUG); // (same as ALL)
mbed_trace_config_set(TRACE_ACTIVE_LEVEL_INFO);
//mbed_trace_config_set(TRACE_ACTIVE_LEVEL_WARN);
//mbed_trace_config_set(TRACE_ACTIVE_LEVEL_ERROR);
//mbed_trace_config_set(TRACE_ACTIVE_LEVEL_CMD);
//mbed_trace_config_set(TRACE_ACTIVE_LEVEL_NONE);
```

Build time optimization can be done with `MBED_TRACE_MAX_LEVEL` definition. Setting max level to `TRACE_LEVEL_DEBUG` includes all traces to the build. Setting max level to `TRACE_LEVEL_INFO` includes all but `tr_debug()` traces to the build. Other maximum tracing levels follow the same behavior and no messages above the selected level are included in the build.

```c
#define MBED_TRACE_MAX_LEVEL TRACE_LEVEL_DEBUG
#define MBED_TRACE_MAX_LEVEL TRACE_LEVEL_INFO
#define MBED_TRACE_MAX_LEVEL TRACE_LEVEL_WARN
#define MBED_TRACE_MAX_LEVEL TRACE_LEVEL_ERROR
#define MBED_TRACE_MAX_LEVEL TRACE_LEVEL_CMD
```

In Mbed OS, the build time maximum tracing level can be set through `mbed_app.json` as shown below.

```
{
"target_overrides":{
"*":{
"mbed-trace.enable": true,
"mbed-trace.max-level": "TRACE_LEVEL_INFO"
}
}
}
```

### Helping functions

The purpose of the helping functions is to provide simple conversions, for example from an array to C string, so that you can print everything to single trace line. They must be called inside the actual trace calls, for example:
Expand Down
6 changes: 6 additions & 0 deletions features/frameworks/mbed-trace/mbed_lib.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
"help": "Used to globally enable traces.",
"value": null
},
"max-level": {
"help": "This flag is used to optimize the code size. For example, setting trace optimization level to TRACE_LEVEL_INFO will define all tr_debug() macros empty, which reduces the binary size. The possible optimization levels are TRACE_LEVEL_DEBUG, TRACE_LEVEL_INFO, TRACE_LEVEL_WARN, TRACE_LEVEL_ERROR and TRACE_LEVEL_CMD. To set the output tracing level, please use mbed_trace_config_set(TRACE_ACTIVE_LEVEL_INFO). The possible tracing levels for mbed_trace_config_set() are TRACE_ACTIVE_LEVEL_ALL, TRACE_ACTIVE_LEVEL_DEBUG (same as ALL), TRACE_ACTIVE_LEVEL_INFO, TRACE_ACTIVE_LEVEL_WARN, TRACE_ACTIVE_LEVEL_ERROR, TRACE_ACTIVE_LEVEL_CMD and TRACE_LEVEL_NONE.",
"value": null,
"macro_name": "MBED_TRACE_MAX_LEVEL"

},
"fea-ipv6": {
"help": "Used to globally disable ipv6 tracing features.",
"value": null
Expand Down
7 changes: 7 additions & 0 deletions features/frameworks/mbed-trace/test/Test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,9 @@ TEST(trace, config_change)
TEST(trace, active_level_all_color)
{
mbed_trace_config_set(TRACE_MODE_COLOR|TRACE_ACTIVE_LEVEL_ALL);
// unknown debug level
mbed_tracef(TRACE_LEVEL_DEBUG+1, "mygr", "hep");
STRCMP_EQUAL(" hep", buf);
mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "hello");
STRCMP_EQUAL("\x1b[90m[DBG ][mygr]: hello\x1b[0m", buf);
mbed_tracef(TRACE_LEVEL_INFO, "mygr", "to one");
Expand Down Expand Up @@ -268,6 +271,10 @@ TEST(trace, change_levels)
TEST(trace, active_level_debug)
{
mbed_trace_config_set(TRACE_ACTIVE_LEVEL_DEBUG);

// unknown debug level
mbed_tracef(TRACE_LEVEL_DEBUG+1, "mygr", "hep");
STRCMP_EQUAL(" hep", buf);

mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "hep");
STRCMP_EQUAL("[DBG ][mygr]: hep", buf);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,31 +186,31 @@ NS_INLINE uint16_t common_read_16_bit_inverse(const uint8_t data_buf[__static 2]
/*
* Count bits in a byte
*
* \param byte byte to inspect
* \param value byte to inspect
*
* \return number of 1-bits in byte
*/
NS_INLINE uint_fast8_t common_count_bits(uint8_t byte);
NS_INLINE uint_fast8_t common_count_bits(uint8_t value);

/*
* Count leading zeros in a byte
*
* \deprecated Use common_count_leading_zeros_8
*
* \param byte byte to inspect
* \param value byte to inspect
*
* \return number of leading zeros in byte (0-8)
*/
NS_INLINE uint_fast8_t common_count_leading_zeros(uint8_t byte);
NS_INLINE uint_fast8_t common_count_leading_zeros(uint8_t value);

/*
* Count leading zeros in a byte
*
* \param byte byte to inspect
* \param value byte to inspect
*
* \return number of leading zeros in byte (0-8)
*/
NS_INLINE uint_fast8_t common_count_leading_zeros_8(uint8_t byte);
NS_INLINE uint_fast8_t common_count_leading_zeros_8(uint8_t value);

/*
* Count leading zeros in a 16-bit value
Expand Down Expand Up @@ -490,43 +490,43 @@ COMMON_FUNCTIONS_FN uint16_t common_read_16_bit_inverse(const uint8_t data_buf[_
return temp_16;
}

COMMON_FUNCTIONS_FN uint_fast8_t common_count_bits(uint8_t byte)
COMMON_FUNCTIONS_FN uint_fast8_t common_count_bits(uint8_t value)
{
/* First step sets each bit pair to be count of bits (00,01,10) */
/* [00-00 = 00, 01-00 = 01, 10-01 = 01, 11-01 = 10] */
uint_fast8_t count = byte - ((byte >> 1) & 0x55);
uint_fast8_t count = value - ((value >> 1) & 0x55);
/* Add bit pairs to make each nibble contain count of bits (0-4) */
count = (count & 0x33) + ((count >> 2) & 0x33);
/* Final result is sum of nibbles (0-8) */
count = (count >> 4) + (count & 0x0F);
return count;
}

COMMON_FUNCTIONS_FN uint_fast8_t common_count_leading_zeros(uint8_t byte)
COMMON_FUNCTIONS_FN uint_fast8_t common_count_leading_zeros(uint8_t value)
{
return common_count_leading_zeros_8(byte);
return common_count_leading_zeros_8(value);
}

COMMON_FUNCTIONS_FN uint_fast8_t common_count_leading_zeros_8(uint8_t byte)
COMMON_FUNCTIONS_FN uint_fast8_t common_count_leading_zeros_8(uint8_t value)
{
#ifdef __CC_ARM
return byte ? __clz((unsigned int) byte << 24) : 8;
return value ? __clz((unsigned int) value << 24) : 8;
#elif defined __GNUC__
return byte ? __builtin_clz((unsigned int) byte << 24) : 8;
return value ? __builtin_clz((unsigned int) value << 24) : 8;
#else
uint_fast8_t cnt = 0;
if (byte == 0) {
if (value == 0) {
return 8;
}
if ((byte & 0xF0) == 0) {
byte <<= 4;
if ((value & 0xF0) == 0) {
value <<= 4;
cnt += 4;
}
if ((byte & 0xC0) == 0) {
byte <<= 2;
if ((value & 0xC0) == 0) {
value <<= 2;
cnt += 2;
}
if ((byte & 0x80) == 0) {
if ((value & 0x80) == 0) {
cnt += 1;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ typedef int_fast32_t int_fast24_t;
#if defined __CC_ARM || defined __TASKING__
#define alignas(n) __align(n)
#define __alignas_is_defined 1
#elif (__STDC_VERSION__ >= 201112L) || (defined __cplusplus && __cplusplus >= 201103L)
#elif (defined __STDC_VERSION__ && __STDC_VERSION__ >= 201112L) || (defined __cplusplus && __cplusplus >= 201103L)
#include <stdalign.h>
#elif defined __GNUC__
#define alignas(n) __attribute__((__aligned__(n)))
Expand Down
11 changes: 9 additions & 2 deletions features/nanostack/coap-service/coap-service/coap_service_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,6 @@ extern int8_t coap_service_response_send(int8_t service_id, uint8_t options, sn_
*/
extern int8_t coap_service_response_send_by_msg_id(int8_t service_id, uint8_t options, uint16_t msg_id, 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
*
Expand All @@ -297,6 +295,15 @@ extern int8_t coap_service_response_send_by_msg_id(int8_t service_id, uint8_t op
*/
extern int8_t coap_service_request_delete(int8_t service_id, uint16_t msg_id);

/**
* \brief Delete CoAP requests from service id
*
* Removes pending CoAP requests from service specified by service_id.
*
* \param service_id Id number of the current service.
*/
extern void coap_service_request_delete_by_service_id(int8_t service_id);

/**
* \brief Set DTLS handshake timeout values
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1001,7 +1001,7 @@ void coap_connection_handler_exec(uint32_t time)
{
if(ns_list_count(&secure_session_list)){
// Seek & destroy old sessions where close notify have been sent
ns_list_foreach(secure_session_t, cur_ptr, &secure_session_list) {
ns_list_foreach_safe(secure_session_t, cur_ptr, &secure_session_list) {
if(cur_ptr->session_state == SECURE_SESSION_CLOSED) {
if((cur_ptr->last_contact_time + CLOSED_SECURE_SESSION_TIMEOUT) <= time){
secure_session_delete(cur_ptr);
Expand Down
47 changes: 47 additions & 0 deletions features/nanostack/coap-service/source/coap_message_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,18 @@ static coap_transaction_t *transaction_find_by_address(uint8_t *address_ptr, uin
return this;
}

static coap_transaction_t *transaction_find_by_service_id(int8_t service_id)
{
coap_transaction_t *this = NULL;
ns_list_foreach(coap_transaction_t, cur_ptr, &request_list) {
if (cur_ptr->service_id == service_id) {
this = cur_ptr;
break;
}
}
return this;
}

/* retransmission valid time is calculated to be max. time that CoAP message sending can take: */
/* Number of retransmisisons, each retransmission is 2 * previous retransmisison time */
/* + random factor (max. 1.5) */
Expand Down Expand Up @@ -160,6 +172,21 @@ void transactions_delete_all(uint8_t *address_ptr, uint16_t port)
}
}

static void transactions_delete_all_by_service_id(int8_t service_id)
{
coap_transaction_t *transaction = transaction_find_by_service_id(service_id);

while (transaction) {
ns_list_remove(&request_list, transaction);
if (transaction->resp_cb) {
transaction->resp_cb(transaction->service_id, transaction->remote_address, transaction->remote_port, NULL);
}
sn_coap_protocol_delete_retransmission(coap_service_handle->coap, transaction->msg_id);
transaction_free(transaction);
transaction = transaction_find_by_service_id(service_id);
}
}

static int8_t coap_rx_function(sn_coap_hdr_s *resp_ptr, sn_nsdl_addr_s *address_ptr, void *param)
{
coap_transaction_t *this = NULL;
Expand Down Expand Up @@ -322,6 +349,7 @@ int16_t coap_message_handler_coap_msg_process(coap_msg_handler_t *handle, int8_t
goto exit;
/* Response received */
} else {
transaction_delete(transaction_ptr); // transaction_ptr not needed in response
if (coap_message->token_ptr) {
this = transaction_find_client_by_token(coap_message->token_ptr, coap_message->token_len, source_addr_ptr, port);
}
Expand Down Expand Up @@ -551,17 +579,36 @@ int8_t coap_message_handler_request_delete(coap_msg_handler_t *handle, int8_t se
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;
}

if (transaction_ptr->resp_cb) {
transaction_ptr->resp_cb(transaction_ptr->service_id, transaction_ptr->remote_address, transaction_ptr->remote_port, NULL);
}
transaction_delete(transaction_ptr);
return 0;
}

int8_t coap_message_handler_request_delete_by_service_id(coap_msg_handler_t *handle, int8_t service_id)
{
tr_debug("Service %d, delete all CoAP requests", service_id);

if (!handle) {
tr_error("invalid params");
return -1;
}

transactions_delete_all_by_service_id(service_id);

return 0;
}

int8_t coap_message_handler_exec(coap_msg_handler_t *handle, uint32_t current_time){

if( !handle ){
Expand Down
8 changes: 7 additions & 1 deletion features/nanostack/coap-service/source/coap_service_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,10 @@ static void service_event_handler(arm_event_s *event)
tr_debug("service tasklet initialised");
/*initialize coap service and listen socket*/
}

if (event->event_type == ARM_LIB_SYSTEM_TIMER_EVENT && event->event_id == COAP_TICK_TIMER) {
coap_message_handler_exec(coap_service_handle, coap_ticks++);
if(coap_ticks && !coap_ticks % SECURE_SESSION_CLEAN_INTERVAL){
if(coap_ticks && !(coap_ticks % SECURE_SESSION_CLEAN_INTERVAL)){
coap_connection_handler_exec(coap_ticks);
}
}
Expand Down Expand Up @@ -541,6 +542,11 @@ 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);
}

void coap_service_request_delete_by_service_id(int8_t service_id)
{
coap_message_handler_request_delete_by_service_id(coap_service_handle, service_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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ extern int8_t coap_message_handler_response_send(coap_msg_handler_t *handle, int

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_request_delete_by_service_id(coap_msg_handler_t *handle, int8_t service_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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ 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_request_delete_by_service_id)
{
CHECK(test_coap_message_handler_request_delete_by_service_id());
}

TEST(coap_message_handler, test_coap_message_handler_exec)
{
CHECK(test_coap_message_handler_exec());
Expand Down
Loading