Merge pull request #8763 from cmonr/rollup-b.1

Rollup PR: Retest CI-troubled PRs target for 5.11 v2
pull/8767/head
Martin Kojtal 2018-11-16 09:15:56 +00:00 committed by GitHub
commit 8a2044b5fc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
393 changed files with 9937 additions and 7697 deletions

View File

@ -16,6 +16,7 @@ hal/storage_abstraction
TESTS/mbed_hal/trng/pithy
features/nanostack/coap-service
features/nanostack/sal-stack-nanostack
features/nanostack/targets
rtos/TARGET_CORTEX/rtx5
TESTS/mbed_hal/trng/pithy
targets

View File

@ -132,7 +132,9 @@ matrix:
- git diff --name-only $TRAVIS_BRANCH | grep '.*\.\(h\|c\|hpp\|cpp\)' | fgrep -v -f .astyleignore | xargs -n 100 -I {} bash -c "astyle -n --options=.astylerc \"{}\"" > astyle-files-changed.out;
if [ $(cat astyle-files-changed.out | grep Formatted | wc -l) -ne 0 ]; then
git --no-pager diff;
echo "Please fix style issues as shown above";
echo "";
echo "AStyle check failed, please fix style issues as shown above";
(exit 1);
else
echo "Coding style check OK";
fi
@ -155,7 +157,6 @@ matrix:
STATUSM="$STATUSM ($(python -c "print '%+d' % ($CURR-$PREV)") files)"
fi
- bash -c "$STATUS" success "$STATUSM"
- env:
- NAME=events
- EVENTS=events

View File

@ -215,6 +215,10 @@ void exp_cb()
TEST_F(Test_LoRaMac, set_device_class)
{
object->set_device_class(CLASS_B, exp_cb);
my_phy phy;
object->bind_phy(phy);
object->set_device_class(CLASS_C, exp_cb);
}
TEST_F(Test_LoRaMac, setup_link_check_request)

View File

@ -26,7 +26,8 @@ class stubInternetSocket : public InternetSocket {
protected:
nsapi_error_t return_value;
public:
stubInternetSocket() {
stubInternetSocket()
{
return_value = 0;
}
virtual nsapi_error_t connect(const SocketAddress &address)

View File

@ -26,7 +26,8 @@ public:
std::list<nsapi_error_t> return_values;
nsapi_error_t return_value;
NetworkStackstub() {
NetworkStackstub()
{
return_value = 0;
}

View File

@ -121,7 +121,10 @@ public:
/** Desctruct QSPIFBlockDevie
*/
~QSPIFBlockDevice() {deinit();}
~QSPIFBlockDevice()
{
deinit();
}
/** Read blocks from a block device
*

View File

@ -266,8 +266,11 @@ public:
* }
* @endcode
*/
// AStyle ignore, not handling correctly below
// *INDENT-OFF*
template <typename T, typename R, typename ...Args>
int call(T *obj, R (T::*method)(Args ...args), Args ...args);
// *INDENT-ON*
/** Calls an event on the queue after a specified delay
*
@ -346,8 +349,11 @@ public:
* }
* @endcode
*/
// AStyle ignore, not handling correctly below
// *INDENT-OFF*
template <typename T, typename R, typename ...Args>
int call_in(int ms, T *obj, R (T::*method)(Args ...args), Args ...args);
// *INDENT-ON*
/** Calls an event on the queue periodically
*
@ -440,8 +446,11 @@ public:
* }
* @endcode
*/
// AStyle ignore, not handling correctly below
// *INDENT-OFF*
template <typename T, typename R, typename ...Args>
int call_every(int ms, T *obj, R (T::*method)(Args ...args), Args ...args);
// *INDENT-ON*
/** Creates an event bound to the event queue
*
@ -483,8 +492,11 @@ public:
* }
* @endcode
*/
// AStyle ignore, not handling correctly below
// *INDENT-OFF*
template <typename R, typename ...BoundArgs, typename ...Args>
Event<void(Args...)> event(R (*func)(BoundArgs...), Args ...args);
// *INDENT-ON*
/** Creates an event bound to the event queue
*
@ -528,8 +540,11 @@ public:
* }
* @endcode
*/
// AStyle ignore, not handling correctly below
// *INDENT-OFF*
template <typename T, typename R, typename ...BoundArgs, typename ...ContextArgs, typename ...Args>
Event<void(Args...)> event(T *obj, R (T::*method)(BoundArgs..., Args...), ContextArgs ...context_args);
// *INDENT-ON*
/** Creates an event bound to the event queue
*

View File

@ -0,0 +1 @@
test/*

View File

@ -11,6 +11,7 @@ INCLUDE_DIRS =\
../../../..\
../../../../source\
../../../../mbed-client-randlib\
../../../../../../../libService/libService\
/usr/include\
$(CPPUTEST_HOME)/include\

View File

@ -6,12 +6,10 @@
TEST_GROUP(randLIB)
{
void setup()
{
void setup() {
}
void teardown()
{
void teardown() {
}
};

View File

@ -1,7 +1,8 @@
/*
* Copyright (c) 2016, ARM Limited, All Rights Reserved
*/
#include "random_stub.h"
#include "ns_types.h"
static uint32_t seed_value = 4;
static bool seed_inc = false;

View File

@ -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:

View File

@ -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

View File

@ -48,8 +48,7 @@ void myprint(const char* str)
}
TEST_GROUP(trace)
{
void setup()
{
void setup() {
mbed_trace_init();
mbed_trace_config_set(TRACE_MODE_PLAIN | TRACE_ACTIVE_LEVEL_ALL);
@ -57,8 +56,7 @@ TEST_GROUP(trace)
mbed_trace_mutex_wait_function_set(my_mutex_wait);
mbed_trace_mutex_release_function_set(my_mutex_release);
}
void teardown()
{
void teardown() {
CHECK(mutex_wait_count == mutex_release_count); // Check the mutex count with every test
mbed_trace_free();
}
@ -87,7 +85,9 @@ TEST(trace, MutexNotSet)
TEST(trace, Array)
{
unsigned char longStr[200] = {0x66};
for(int i=0;i<200;i++) {longStr[i] = 0x66; }
for (int i = 0; i < 200; i++) {
longStr[i] = 0x66;
}
mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "%s", mbed_trace_array(longStr, 200));
}
@ -107,7 +107,9 @@ TEST(trace, Null0Array)
TEST(trace, LongString)
{
char longStr[1000] = {0x36};
for(int i=0;i<999;i++) {longStr[i] = 0x36; }
for (int i = 0; i < 999; i++) {
longStr[i] = 0x36;
}
mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "%s", longStr);
}
@ -116,13 +118,17 @@ TEST(trace, TooLong)
#define TOO_LONG_SIZE 9400
#define TRACE_LINE_SIZE 1024
char longStr[TOO_LONG_SIZE] = {0};
for(int i=0;i<TOO_LONG_SIZE;i++) { longStr[i] = 0x36; }
for (int i = 0; i < TOO_LONG_SIZE; i++) {
longStr[i] = 0x36;
}
mbed_trace_config_set(TRACE_ACTIVE_LEVEL_ALL);
mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "%s", longStr);
char shouldStr[TRACE_LINE_SIZE] = "[DBG ][mygr]: ";
for(int i=14;i<TRACE_LINE_SIZE;i++) { shouldStr[i] = 0x36; }
for (int i = 14; i < TRACE_LINE_SIZE; i++) {
shouldStr[i] = 0x36;
}
shouldStr[TRACE_LINE_SIZE - 1] = 0;
STRCMP_EQUAL(shouldStr, buf);
}
@ -239,6 +245,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");
@ -269,6 +278,10 @@ 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);
@ -396,7 +409,8 @@ TEST(trace, active_level_all_array)
size_t time_length;
char trace_prefix_str[] = "[<TIME>]";
char* trace_prefix(size_t length){
char *trace_prefix(size_t length)
{
time_length = length;
return trace_prefix_str;
}

View File

@ -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
@ -490,11 +490,11 @@ 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) */
@ -502,31 +502,31 @@ COMMON_FUNCTIONS_FN uint_fast8_t common_count_bits(uint8_t byte)
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;
}

View File

@ -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)))

View File

@ -74,8 +74,7 @@ bool stoip6(const char *ip6addr, size_t len, void *dest)
coloncolon = field_no;
q++;
len -= 2;
}
else {
} else {
len -= 1;
}
}
@ -150,11 +149,13 @@ int stoip6_prefix(const char *ip6addr, void *dest, int_fast16_t *prefix_len_out)
static bool is_hex(char c)
{
// 'A' (0x41) and 'a' (0x61) are mapped in the ASCII table in such a way that masking the 0x20 bit turn 'a' in 'A'
if ((c & ~0x20) >= 'A' && (c & ~0x20) <= 'F')
if ((c & ~0x20) >= 'A' && (c & ~0x20) <= 'F') {
return true;
}
if (c >= '0' && c <= '9')
if (c >= '0' && c <= '9') {
return true;
}
return false;
}

View File

@ -64,8 +64,7 @@ TEST(ip6tos, ip6_prefix_tos_func)
/***********************************************************/
/* Second test group for the old tests that were once lost */
const char string_addr[][40] =
{
const char string_addr[][40] = {
"2001:db8::1:0:0:1", // 1
"2001:db8:aaaa:bbbb:cccc:dddd:eeee:1", // 2
"2001:db8::1", // 3
@ -81,8 +80,7 @@ const char string_addr[][40] =
};
const uint8_t hex_addr[][16] =
{
const uint8_t hex_addr[][16] = {
{ 0x20, 0x01, 0xd, 0xb8, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1 },
{ 0x20, 0x01, 0xd, 0xb8, 0xaa, 0xaa, 0xbb, 0xbb, 0xcc, 0xcc, 0xdd, 0xdd, 0xee, 0xee, 0x00, 0x01 },
{ 0x20, 0x01, 0xd, 0xb8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
@ -102,13 +100,11 @@ int i = 0;
TEST_GROUP(ip6tos_2)
{
void setUp(void)
{
void setUp(void) {
memset(buf, 0, 40);
}
void tearDown(void)
{
void tearDown(void) {
i++;
}
};

View File

@ -66,7 +66,8 @@ TEST(dynmem, diff_alignment)
CHECK(NULL != heap);
reset_heap_error();
for (int i = 0; i < 16; i++) {
ptr++; size--;
ptr++;
size--;
ns_dyn_mem_init(ptr, size, &heap_fail_callback, &info);
CHECK(info.heap_sector_size >= (size - 72));
CHECK(!heap_have_failed());
@ -89,9 +90,10 @@ TEST(dynmem, ns_dyn_mem_alloc)
int i;
for (i = 0; i < size; i++) {
p[i] = ns_dyn_mem_alloc(block);
if (!p[i])
if (!p[i]) {
break;
}
}
CHECK(!heap_have_failed());
CHECK(info.heap_alloc_fail_cnt == 1);
CHECK(info.heap_sector_alloc_cnt == i);
@ -120,9 +122,10 @@ TEST(dynmem, ns_dyn_mem_temporary_alloc)
int i;
for (i = 0; i < size; i++) {
p[i] = ns_dyn_mem_temporary_alloc(block);
if (!p[i])
if (!p[i]) {
break;
}
}
CHECK(!heap_have_failed());
CHECK(info.heap_alloc_fail_cnt == 1);
CHECK(info.heap_sector_alloc_cnt == i);
@ -211,7 +214,8 @@ TEST(dynmem, ns_dyn_mem_temporary_alloc_with_heap_threshold)
free(heap);
}
TEST(dynmem, test_both_allocs_with_hole_usage) {
TEST(dynmem, test_both_allocs_with_hole_usage)
{
uint16_t size = 112;
mem_stat_t info;
void *p[size];
@ -240,7 +244,8 @@ TEST(dynmem, test_both_allocs_with_hole_usage) {
free(heap);
}
TEST(dynmem, test_temp_alloc_with_skipping_hole) {
TEST(dynmem, test_temp_alloc_with_skipping_hole)
{
uint16_t size = 1000;
mem_stat_t info;
void *p[size];
@ -315,7 +320,8 @@ TEST(dynmem, corrupted_memory)
free(heap);
}
TEST(dynmem, no_big_enough_sector) {
TEST(dynmem, no_big_enough_sector)
{
uint16_t size = 112;
mem_stat_t info;
uint8_t *heap = (uint8_t *)malloc(size);
@ -487,7 +493,8 @@ TEST(dynmem, not_negative_stats)
free(heap);
}
TEST(dynmem, test_invalid_pointer_freed) {
TEST(dynmem, test_invalid_pointer_freed)
{
uint16_t size = 92;
uint8_t *heap = (uint8_t *)malloc(size);
CHECK(NULL != heap);
@ -503,7 +510,8 @@ TEST(dynmem, test_invalid_pointer_freed) {
free(heap);
}
TEST(dynmem, test_merge_corrupted_previous_block) {
TEST(dynmem, test_merge_corrupted_previous_block)
{
uint16_t size = 1000;
uint8_t *heap = (uint8_t *)malloc(size);
uint8_t *p;
@ -524,7 +532,8 @@ TEST(dynmem, test_merge_corrupted_previous_block) {
free(heap);
}
TEST(dynmem, test_free_corrupted_next_block) {
TEST(dynmem, test_free_corrupted_next_block)
{
uint16_t size = 1000;
uint8_t *heap = (uint8_t *)malloc(size);
uint8_t *p;
@ -546,7 +555,8 @@ TEST(dynmem, test_free_corrupted_next_block) {
}
//NOTE! This test must be last!
TEST(dynmem, uninitialized_test){
TEST(dynmem, uninitialized_test)
{
void *p = ns_dyn_mem_alloc(4);
ns_dyn_mem_free(p);
CHECK(p == NULL);

View File

@ -19,15 +19,18 @@
heap_fail_t current_heap_error;
static bool failed;
void heap_fail_callback(heap_fail_t err) {
void heap_fail_callback(heap_fail_t err)
{
current_heap_error = err;
failed = true;
}
void reset_heap_error() {
void reset_heap_error()
{
failed = false;
}
bool heap_have_failed() {
bool heap_have_failed()
{
return failed;
}

View File

@ -106,8 +106,7 @@ TEST(stoip6, InvalidAddresses)
uint8_t ip[16];
uint8_t correct[16] = {0};
const char *invalidArray[] =
{
const char *invalidArray[] = {
"FFFF:FFFF::FFFF::FFFF", // Two ::
"F:F:F:FqF:F:F:F:F", // Non-hex character
"F:F:F:FFFFF:F:F:F:F" // >4 hex characters in a segment
@ -122,8 +121,7 @@ TEST(stoip6, InvalidAddresses)
/***********************************************************/
/* Second test group for the old tests that were once lost */
const char string_addr[][40] =
{
const char string_addr[][40] = {
"2001:db8::1:0:0:1", // 1
"2001:db8:aaaa:bbbb:cccc:dddd:eeee:1", // 2
"2001:db8::1", // 3
@ -139,8 +137,7 @@ const char string_addr[][40] =
};
const uint8_t hex_addr[][16] =
{
const uint8_t hex_addr[][16] = {
{ 0x20, 0x01, 0xd, 0xb8, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1 },
{ 0x20, 0x01, 0xd, 0xb8, 0xaa, 0xaa, 0xbb, 0xbb, 0xcc, 0xcc, 0xdd, 0xdd, 0xee, 0xee, 0x00, 0x01 },
{ 0x20, 0x01, 0xd, 0xb8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
@ -160,13 +157,11 @@ int i = 0;
TEST_GROUP(stoip6_2)
{
void setUp(void)
{
void setUp(void) {
memset(buf, 0, 40);
}
void tearDown(void)
{
void tearDown(void) {
i++;
}
};
@ -240,8 +235,7 @@ TEST(stoip6_2, test_2_12)
/***********************************************************/
/* Third test group for stoip6_prefix */
const char string_prefix_addr[][40] =
{
const char string_prefix_addr[][40] = {
"2001:db8::1:0:0:1/64", // 1
"2001::/60", // 2
"::1/48", // 3
@ -254,8 +248,7 @@ const char string_prefix_addr[][40] =
};
const uint8_t hex_prefix_addr[][16] =
{
const uint8_t hex_prefix_addr[][16] = {
{ 0x20, 0x01, 0xd, 0xb8, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1 }, // 1
{ 0x20, 0x01, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, // 2
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }, // 3

View File

@ -31,26 +31,20 @@ void ns_dyn_mem_init(void *heap, ns_mem_heap_size_t h_size, void (*passed_fptr)(
void *ns_dyn_mem_alloc(ns_mem_block_size_t alloc_size)
{
if (nsdynmemlib_stub.returnCounter > 0)
{
if (nsdynmemlib_stub.returnCounter > 0) {
nsdynmemlib_stub.returnCounter--;
return malloc(alloc_size);
}
else
{
} else {
return (nsdynmemlib_stub.expectedPointer);
}
}
void *ns_dyn_mem_temporary_alloc(ns_mem_block_size_t alloc_size)
{
if (nsdynmemlib_stub.returnCounter > 0)
{
if (nsdynmemlib_stub.returnCounter > 0) {
nsdynmemlib_stub.returnCounter--;
return malloc(alloc_size);
}
else
{
} else {
return (nsdynmemlib_stub.expectedPointer);
}
}

View File

@ -294,6 +294,15 @@ void tearDown(void);
#define TEST_ASSERT_DOUBLE_IS_NOT_NAN_MESSAGE(actual, message) UNITY_TEST_ASSERT_DOUBLE_IS_NOT_NAN((actual), __LINE__, (message))
#define TEST_ASSERT_DOUBLE_IS_NOT_DETERMINATE_MESSAGE(actual, message) UNITY_TEST_ASSERT_DOUBLE_IS_NOT_DETERMINATE((actual), __LINE__, (message))
/*-------------------------------------------------------
* Error code checking
*-------------------------------------------------------*/
// Use these to check whether error code equals what we expect.
// Only display error code (without other information)
#define TEST_ASSERT_EQUAL_ERROR_CODE(expected, actual) TEST_ASSERT_EQUAL(MBED_GET_ERROR_CODE(expected), MBED_GET_ERROR_CODE(actual))
#define TEST_ASSERT_EQUAL_ERROR_CODE_MESSAGE(expected, actual, message) TEST_ASSERT_EQUAL_MESSAGE(MBED_GET_ERROR_CODE(expected), MBED_GET_ERROR_CODE(actual))
/*-------------------------------------------------------
* Test skipping
*-------------------------------------------------------*/

View File

@ -310,6 +310,7 @@ int16_t LoRaWANStack::handle_tx(const uint8_t port, const uint8_t *data,
if (_link_check_requested) {
_loramac.setup_link_check_request();
}
_qos_cnt = 1;
lorawan_status_t status;

View File

@ -80,7 +80,8 @@ LoRaMac::LoRaMac()
_can_cancel_tx(true),
_continuous_rx2_window_open(false),
_device_class(CLASS_A),
_prev_qos_level(LORAWAN_DEFAULT_QOS)
_prev_qos_level(LORAWAN_DEFAULT_QOS),
_demod_ongoing(false)
{
memset(&_params, 0, sizeof(_params));
_params.keys.dev_eui = NULL;
@ -99,7 +100,6 @@ LoRaMac::LoRaMac()
_params.rx_buffer_len = 0;
_params.ul_frame_counter = 0;
_params.dl_frame_counter = 0;
_params.is_ul_frame_counter_fixed = false;
_params.is_rx_window_enabled = true;
_params.adr_ack_counter = 0;
_params.is_node_ack_requested = false;
@ -166,16 +166,13 @@ void LoRaMac::post_process_mcps_req()
_params.is_node_ack_requested = false;
_mcps_confirmation.ack_received = false;
_mcps_indication.is_ack_recvd = false;
if (_params.is_ul_frame_counter_fixed == false) {
_params.ul_frame_counter++;
_params.adr_ack_counter++;
}
} else {
_mcps_confirmation.status = LORAMAC_EVENT_INFO_STATUS_ERROR;
}
} else {
//UNCONFIRMED or PROPRIETARY
if (_params.is_ul_frame_counter_fixed == false) {
_params.ul_frame_counter++;
_params.adr_ack_counter++;
if (_params.sys_params.nb_trans > 1) {
@ -183,7 +180,6 @@ void LoRaMac::post_process_mcps_req()
}
}
}
}
void LoRaMac::post_process_mcps_ind()
{
@ -650,8 +646,8 @@ void LoRaMac::on_radio_tx_done(lorawan_time_t timestamp)
if ((_mcps_confirmation.req_type == MCPS_UNCONFIRMED)
&& (_params.sys_params.nb_trans > 1)) {
//MBED_ASSERT(_params.ul_nb_rep_counter <= _params.sys_params.nb_trans);
_params.ul_nb_rep_counter++;
MBED_ASSERT(_params.ul_nb_rep_counter <= _params.sys_params.nb_trans);
}
if (_params.is_rx_window_enabled == true) {
@ -696,6 +692,7 @@ void LoRaMac::on_radio_tx_done(lorawan_time_t timestamp)
void LoRaMac::on_radio_rx_done(const uint8_t *const payload, uint16_t size,
int16_t rssi, int8_t snr)
{
_demod_ongoing = false;
if (_device_class == CLASS_C && !_continuous_rx2_window_open) {
_lora_time.stop(_rx2_closure_timer_for_class_c);
open_rx2_window();
@ -765,6 +762,7 @@ void LoRaMac::on_radio_tx_timeout(void)
void LoRaMac::on_radio_rx_timeout(bool is_timeout)
{
_demod_ongoing = false;
if (_device_class == CLASS_A) {
_lora_phy->put_radio_to_sleep();
}
@ -887,6 +885,7 @@ void LoRaMac::on_backoff_timer_expiry(void)
void LoRaMac::open_rx1_window(void)
{
Lock lock(*this);
_demod_ongoing = true;
_continuous_rx2_window_open = false;
_lora_time.stop(_params.timers.rx_window1_timer);
_params.rx_slot = RX_SLOT_WIN_1;
@ -912,6 +911,10 @@ void LoRaMac::open_rx1_window(void)
void LoRaMac::open_rx2_window()
{
if (_demod_ongoing) {
tr_info("RX1 Demodulation ongoing, skip RX2 window opening");
return;
}
Lock lock(*this);
_continuous_rx2_window_open = true;
_lora_time.stop(_params.timers.rx_window2_timer);
@ -1243,6 +1246,8 @@ void LoRaMac::reset_mac_parameters(void)
}
_params.channel = 0;
_params.last_channel_idx = _params.channel;
_demod_ongoing = false;
}
uint8_t LoRaMac::get_default_tx_datarate()

View File

@ -696,6 +696,8 @@ private:
device_class_t _device_class;
uint8_t _prev_qos_level;
bool _demod_ongoing;
};
#endif // MBED_LORAWAN_MAC_H__

View File

@ -1127,12 +1127,6 @@ typedef struct {
*/
bool is_repeater_supported;
/*!
* IsPacketCounterFixed enables the MIC field tests by fixing the
* ul_frame_counter value
*/
bool is_ul_frame_counter_fixed;
/*!
* Used for test purposes. Disables the opening of the reception windows.
*/

View File

@ -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
*
@ -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
*

View File

@ -230,7 +230,8 @@ static secure_session_t *secure_session_create(internal_socket_t *parent, const
}
static void clear_secure_sessions(internal_socket_t *this){
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) {
@ -316,13 +317,19 @@ static internal_socket_t *int_socket_create(uint16_t listen_port, bool use_ephem
return NULL;
}
socket_setsockopt(this->socket, SOCKET_IPPROTO_IPV6, SOCKET_LINK_LAYER_SECURITY, &(const int8_t) {bypassSec ? 0 : 1}, sizeof(int8_t));
socket_setsockopt(this->socket, SOCKET_IPPROTO_IPV6, SOCKET_LINK_LAYER_SECURITY, &(const int8_t) {
bypassSec ? 0 : 1
}, sizeof(int8_t));
// XXX API for this? May want to get clever to do recommended first query = 1 hop, retries = whole PAN
socket_setsockopt(this->socket, SOCKET_IPPROTO_IPV6, SOCKET_IPV6_MULTICAST_HOPS, &(const int16_t) {16}, sizeof(int16_t));
socket_setsockopt(this->socket, SOCKET_IPPROTO_IPV6, SOCKET_IPV6_MULTICAST_HOPS, &(const int16_t) {
16
}, sizeof(int16_t));
// Set socket option to receive packet info
socket_setsockopt(this->socket, SOCKET_IPPROTO_IPV6, SOCKET_IPV6_RECVPKTINFO, &(const bool) {1}, sizeof(bool));
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));
@ -430,8 +437,9 @@ static int secure_session_sendto(int8_t socket_id, void *handle, const void *buf
if (!sock->real_socket) {
// Send to virtual socket cb
int ret = sock->parent->_send_cb(sock->socket, session->remote_host.address, session->remote_host.identifier, buf, len);
if( ret < 0 )
if (ret < 0) {
return ret;
}
return len;
}
@ -486,12 +494,10 @@ static void timer_cb(void *param)
if (MBEDTLS_ERR_SSL_TIMEOUT == error) {
//TODO: How do we handle timeouts?
secure_session_delete(sec);
}
else{
} else {
sec->timer.timer = eventOS_timeout_ms(timer_cb, sec->timer.int_ms, (void *)sec);
}
}
else{
} else {
/* We have counted the number of cycles - finish */
eventOS_timeout_cancel(sec->timer.timer);
sec->timer.fin_ms = 0;
@ -776,8 +782,7 @@ int coap_connection_handler_virtual_recv(coap_conn_handler_t *handler, uint8_t a
(void *)coap_security_handler_keyblock(session->sec_handler));
}
return 0;
}
else if (ret < 0) {
} else if (ret < 0) {
// error handling
// TODO: here we also should clear CoAP retransmission buffer and inform that CoAP request sending is failed.
secure_session_delete(session);
@ -1001,7 +1006,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);

View File

@ -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) */
@ -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;
@ -189,7 +216,8 @@ static int8_t coap_rx_function(sn_coap_hdr_s *resp_ptr, sn_nsdl_addr_s *address_
}
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 *)){
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;
@ -226,7 +254,8 @@ coap_msg_handler_t *coap_message_handler_init(void *(*used_malloc_func_ptr)(uint
return handle;
}
int8_t coap_message_handler_destroy(coap_msg_handler_t *handle){
int8_t coap_message_handler_destroy(coap_msg_handler_t *handle)
{
if (!handle) {
return -1;
}
@ -258,8 +287,9 @@ coap_transaction_t *coap_message_handler_transaction_valid(coap_transaction_t *t
coap_transaction_t *coap_message_handler_find_transaction(uint8_t *address_ptr, uint16_t port)
{
if( !address_ptr )
if (!address_ptr) {
return NULL;
}
return transaction_find_by_address(address_ptr, port);
}
@ -322,6 +352,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);
}
@ -551,6 +582,7 @@ 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);
@ -558,11 +590,30 @@ int8_t coap_message_handler_request_delete(coap_msg_handler_t *handle, int8_t se
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_exec(coap_msg_handler_t *handle, uint32_t current_time){
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) {
return -1;

View File

@ -93,7 +93,8 @@ int entropy_poll( void *data, unsigned char *output, size_t len, size_t *olen );
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(coap_security_t *sec){
static int coap_security_handler_init(coap_security_t *sec)
{
const char *pers = "dtls_client";
#ifdef COAP_SERVICE_PROVIDE_STRONG_ENTROPY_SOURCE
const int entropy_source_type = MBEDTLS_ENTROPY_SOURCE_STRONG;
@ -124,8 +125,7 @@ static int coap_security_handler_init(coap_security_t *sec){
if ((mbedtls_ctr_drbg_seed(&sec->_ctr_drbg, mbedtls_entropy_func, &sec->_entropy,
(const unsigned char *) pers,
strlen( pers ) ) ) != 0 )
{
strlen(pers))) != 0) {
return -1;
}
return 0;
@ -141,7 +141,8 @@ const void *coap_security_handler_keyblock(const coap_security_t *sec)
return sec->_keyblk.value;
}
static void coap_security_handler_reset(coap_security_t *sec){
static void coap_security_handler_reset(coap_security_t *sec)
{
#if defined(MBEDTLS_X509_CRT_PARSE_C)
mbedtls_x509_crt_free(&sec->_cacert);
mbedtls_x509_crt_free(&sec->_owncert);
@ -187,7 +188,8 @@ coap_security_t *coap_security_create(int8_t socket_id, int8_t timer_id, void *h
return this;
}
void coap_security_destroy(coap_security_t *sec){
void coap_security_destroy(coap_security_t *sec)
{
if (sec) {
coap_security_handler_reset(sec);
ns_dyn_mem_free(sec);
@ -367,22 +369,19 @@ int coap_security_handler_connect_non_blocking(coap_security_t *sec, bool is_ser
if ((mbedtls_ssl_config_defaults(&sec->_conf,
endpoint,
mode, 0 ) ) != 0 )
{
mode, 0)) != 0) {
return -1;
}
if (!timeout_max && !timeout_min) {
mbedtls_ssl_conf_handshake_timeout(&sec->_conf, DTLS_HANDSHAKE_TIMEOUT_MIN, DTLS_HANDSHAKE_TIMEOUT_MAX);
}
else{
} else {
mbedtls_ssl_conf_handshake_timeout(&sec->_conf, timeout_min, timeout_max);
}
mbedtls_ssl_conf_rng(&sec->_conf, mbedtls_ctr_drbg_random, &sec->_ctr_drbg);
if( ( mbedtls_ssl_setup( &sec->_ssl, &sec->_conf ) ) != 0 )
{
if ((mbedtls_ssl_setup(&sec->_ssl, &sec->_conf)) != 0) {
return -1;
}
@ -433,7 +432,8 @@ int coap_security_handler_connect_non_blocking(coap_security_t *sec, bool is_ser
return ret;
}
int coap_security_handler_continue_connecting(coap_security_t *sec){
int coap_security_handler_continue_connecting(coap_security_t *sec)
{
int ret = -1;
while (ret != MBEDTLS_ERR_SSL_WANT_READ) {
@ -446,8 +446,7 @@ int coap_security_handler_continue_connecting(coap_security_t *sec){
}
#endif
return 1;
}
else if(ret && (ret != MBEDTLS_ERR_SSL_WANT_READ && ret != MBEDTLS_ERR_SSL_WANT_WRITE)){
} else if (ret && (ret != MBEDTLS_ERR_SSL_WANT_READ && ret != MBEDTLS_ERR_SSL_WANT_WRITE)) {
return ret;
}
@ -464,12 +463,14 @@ int coap_security_handler_continue_connecting(coap_security_t *sec){
}
int coap_security_handler_send_message(coap_security_t *sec, unsigned char *message, size_t len){
int coap_security_handler_send_message(coap_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 ||
do {
ret = mbedtls_ssl_write(&sec->_ssl, (unsigned char *) message, len);
} while (ret == MBEDTLS_ERR_SSL_WANT_READ ||
ret == MBEDTLS_ERR_SSL_WANT_WRITE);
}
@ -488,7 +489,8 @@ int coap_security_send_close_alert(coap_security_t *sec)
return -1;
}
int coap_security_handler_read(coap_security_t *sec, unsigned char* buffer, size_t len){
int coap_security_handler_read(coap_security_t *sec, unsigned char *buffer, size_t len)
{
int ret = -1;
int max_loops = 100;
@ -537,12 +539,14 @@ static int get_timer(void *sec_obj)
return -1;
}
int f_send( void *ctx, const unsigned char *buf, size_t len){
int f_send(void *ctx, const unsigned char *buf, size_t len)
{
coap_security_t *sec = (coap_security_t *)ctx;
return sec->_send_cb(sec->_socket_id, sec->_handle, buf, len);
}
int f_recv(void *ctx, unsigned char *buf, size_t len){
int f_recv(void *ctx, unsigned char *buf, size_t len)
{
coap_security_t *sec = (coap_security_t *)ctx;
return sec->_receive_cb(sec->_socket_id, buf, len);
}

View File

@ -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);
}
}
@ -522,17 +523,20 @@ int8_t coap_service_unregister_uri(int8_t service_id, const char *uri)
}
uint16_t coap_service_request_send(int8_t service_id, uint8_t options, const uint8_t destination_addr[static 16], uint16_t destination_port, sn_coap_msg_type_e msg_type, sn_coap_msg_code_e msg_code, const char *uri,
sn_coap_content_format_e cont_type, const uint8_t *payload_ptr, uint16_t payload_len, coap_service_response_recv *request_response_cb){
sn_coap_content_format_e 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, sn_coap_content_format_e content_type, const uint8_t *payload_ptr,uint16_t payload_len){
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)
{
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_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) {
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)
{
return coap_message_handler_response_send_by_msg_id(coap_service_handle, service_id, options, msg_id, message_code, content_type, payload_ptr, payload_len);
}
@ -541,6 +545,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);

View File

@ -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);

View File

@ -19,12 +19,10 @@
TEST_GROUP(coap_connection_handler)
{
void setup()
{
void setup() {
}
void teardown()
{
void teardown() {
}
};

View File

@ -50,16 +50,19 @@ void sec_done_cb_test(int8_t socket_id, uint8_t address[static 16], uint16_t por
bool test_connection_handler_create()
{
coap_security_handler_stub.counter = -1;
if( NULL != connection_handler_create(NULL, NULL, NULL, NULL) )
if (NULL != connection_handler_create(NULL, NULL, NULL, NULL)) {
return false;
}
if( NULL != connection_handler_create(&receive_from_sock_cb, NULL, NULL, NULL) )
if (NULL != connection_handler_create(&receive_from_sock_cb, NULL, NULL, NULL)) {
return false;
}
nsdynmemlib_stub.returnCounter = 1;
coap_conn_handler_t *handler = connection_handler_create(&receive_from_sock_cb, NULL, NULL, NULL);
if( NULL == handler )
if (NULL == handler) {
return false;
}
ns_dyn_mem_free(handler);
return true;
}
@ -80,35 +83,42 @@ bool test_coap_connection_handler_open_connection()
nsdynmemlib_stub.returnCounter = 1;
coap_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) )
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) )
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) )
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) )
if (0 != 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, 22,false,true,true,true) )
if (0 != coap_connection_handler_open_connection(handler, 22, false, true, true, true)) {
return false;
}
//open second one
nsdynmemlib_stub.returnCounter = 1;
coap_conn_handler_t *handler2 = connection_handler_create(&receive_from_sock_cb, &send_to_sock_cb, NULL, NULL);
nsdynmemlib_stub.returnCounter = 2;
if( 0 != coap_connection_handler_open_connection(handler2, 22,false,true,true,true) )
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) )
if (0 != coap_connection_handler_open_connection(handler, 23, false, false, false, false)) {
return false;
}
connection_handler_destroy(handler2, false);
connection_handler_destroy(handler, false);
@ -118,8 +128,9 @@ bool test_coap_connection_handler_open_connection()
bool test_coap_connection_handler_send_data()
{
coap_security_handler_stub.counter = -1;
if( -1 != coap_connection_handler_send_data(NULL, NULL, ns_in6addr_any, NULL, 0, false))
if (-1 != coap_connection_handler_send_data(NULL, NULL, ns_in6addr_any, NULL, 0, false)) {
return false;
}
ns_address_t addr;
memset(addr.address, 1, 16);
@ -128,11 +139,13 @@ bool test_coap_connection_handler_send_data()
nsdynmemlib_stub.returnCounter = 1;
coap_conn_handler_t *handler = connection_handler_create(&receive_from_sock_cb, &send_to_sock_cb, NULL, NULL);
nsdynmemlib_stub.returnCounter = 2;
if( 0 != coap_connection_handler_open_connection(handler, 22,false,true,false,false) )
if (0 != coap_connection_handler_open_connection(handler, 22, false, true, false, false)) {
return false;
}
if( -1 != coap_connection_handler_send_data(handler, &addr, ns_in6addr_any, NULL, 0, true))
if (-1 != coap_connection_handler_send_data(handler, &addr, ns_in6addr_any, NULL, 0, true)) {
return false;
}
connection_handler_destroy(handler, false);
@ -141,14 +154,17 @@ bool test_coap_connection_handler_send_data()
nsdynmemlib_stub.returnCounter = 1;
handler = connection_handler_create(&receive_from_sock_cb, &send_to_sock_cb, NULL, NULL);
nsdynmemlib_stub.returnCounter = 4;
if( 0 != coap_connection_handler_open_connection(handler, 22,false,true,false,false) )
if (0 != coap_connection_handler_open_connection(handler, 22, false, true, false, false)) {
return false;
}
if( -1 != coap_connection_handler_send_data(handler, &addr, ns_in6addr_any, NULL, 0, true))
if (-1 != coap_connection_handler_send_data(handler, &addr, ns_in6addr_any, NULL, 0, true)) {
return false;
}
if( -1 != coap_connection_handler_send_data(handler, &addr, ns_in6addr_any, NULL, 0, true))
if (-1 != coap_connection_handler_send_data(handler, &addr, ns_in6addr_any, NULL, 0, true)) {
return false;
}
connection_handler_destroy(handler, false);
@ -159,23 +175,27 @@ bool test_coap_connection_handler_send_data()
nsdynmemlib_stub.returnCounter = 1;
handler = connection_handler_create(&receive_from_sock_cb, &send_to_sock_cb, NULL, NULL);
nsdynmemlib_stub.returnCounter = 2;
if( 0 != coap_connection_handler_open_connection(handler, 22,false,false,false,false) )
if (0 != coap_connection_handler_open_connection(handler, 22, false, false, false, false)) {
return false;
}
if( 1 != coap_connection_handler_send_data(handler, &addr, ns_in6addr_any, NULL, 0, true))
if (1 != coap_connection_handler_send_data(handler, &addr, ns_in6addr_any, NULL, 0, true)) {
return false;
}
connection_handler_destroy(handler, false);
nsdynmemlib_stub.returnCounter = 1;
handler = connection_handler_create(&receive_from_sock_cb, &send_to_sock_cb, NULL, NULL);
nsdynmemlib_stub.returnCounter = 2;
if( 0 != coap_connection_handler_open_connection(handler, 22,false,false,true,false) )
if (0 != coap_connection_handler_open_connection(handler, 22, false, false, true, false)) {
return false;
}
socket_api_stub.int8_value = 7;
if( 1 != coap_connection_handler_send_data(handler, &addr, ns_in6addr_any, NULL, 0, true))
if (1 != coap_connection_handler_send_data(handler, &addr, ns_in6addr_any, NULL, 0, true)) {
return false;
}
connection_handler_destroy(handler, false);
//<-- NON SECURE HERE
@ -188,65 +208,77 @@ 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) )
if (-1 != coap_connection_handler_virtual_recv(NULL, buf, 12, NULL, 0)) {
return false;
}
nsdynmemlib_stub.returnCounter = 1;
coap_conn_handler_t *handler = connection_handler_create(&receive_from_sock_cb, &send_to_sock_cb, NULL, NULL);
nsdynmemlib_stub.returnCounter = 2;
if( 0 != coap_connection_handler_open_connection(handler, 22,false,true,true,false) )
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) )
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) )
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) )
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 = coap_security_handler_stub_alloc();
ns_timer_stub.int8_value = -1;
nsdynmemlib_stub.returnCounter = 3;
if( -1 != coap_connection_handler_virtual_recv(handler,buf, 12, &buf, 1) )
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) )
if (-1 != coap_connection_handler_virtual_recv(handler, buf, 12, &buf, 1)) {
return false;
}
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_test);
nsdynmemlib_stub.returnCounter = 2;
if( 0 != coap_connection_handler_open_connection(handler2, 24,false,true,true,false) )
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) )
if (0 != coap_connection_handler_virtual_recv(handler2, buf, 12, &buf, 1)) {
return false;
}
nsdynmemlib_stub.returnCounter = 1;
coap_security_handler_stub.int_value = 0;
if( 0 != coap_connection_handler_virtual_recv(handler2,buf, 12, &buf, 1) )
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) )
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) )
if (0 != coap_connection_handler_virtual_recv(handler2, buf, 12, &buf, 1)) {
return false;
}
connection_handler_destroy(handler2, false);
@ -256,12 +288,14 @@ bool test_coap_connection_handler_virtual_recv()
nsdynmemlib_stub.returnCounter = 1;
coap_conn_handler_t *handler3 = connection_handler_create(&receive_from_sock_cb, &send_to_sock_cb, &get_passwd_cb, &sec_done_cb_test);
nsdynmemlib_stub.returnCounter = 2;
if( 0 != coap_connection_handler_open_connection(handler3, 26,false,false,true,false) )
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) )
if (0 != coap_connection_handler_virtual_recv(handler3, buf, 12, &buf, 1)) {
return false;
}
connection_handler_destroy(handler3, false);
@ -271,21 +305,25 @@ bool test_coap_connection_handler_virtual_recv()
bool test_coap_connection_handler_socket_belongs_to()
{
coap_security_handler_stub.counter = -1;
if( false != coap_connection_handler_socket_belongs_to(NULL, 2) )
if (false != coap_connection_handler_socket_belongs_to(NULL, 2)) {
return false;
}
socket_api_stub.int8_value = 0;
nsdynmemlib_stub.returnCounter = 1;
coap_conn_handler_t *handler = connection_handler_create(&receive_from_sock_cb, &send_to_sock_cb, NULL, NULL);
nsdynmemlib_stub.returnCounter = 2;
if( 0 != coap_connection_handler_open_connection(handler, 22,false,true,true,false) )
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) )
if (true != coap_connection_handler_socket_belongs_to(handler, 0)) {
return false;
}
if( false != coap_connection_handler_socket_belongs_to(handler, 3) )
if (false != coap_connection_handler_socket_belongs_to(handler, 3)) {
return false;
}
connection_handler_destroy(handler, false);
nsdynmemlib_stub.returnCounter = 0;
@ -301,8 +339,9 @@ bool test_timer_callbacks()
nsdynmemlib_stub.returnCounter = 1;
coap_conn_handler_t *handler = connection_handler_create(&receive_from_sock_cb, &send_to_sock_cb, NULL, NULL);
nsdynmemlib_stub.returnCounter = 2;
if( 0 != coap_connection_handler_open_connection(handler, 22,false,true,true,false) )
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 = coap_security_handler_stub_alloc();
@ -310,8 +349,9 @@ bool test_timer_callbacks()
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) )
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) {
@ -321,12 +361,14 @@ bool test_timer_callbacks()
}
if (coap_security_handler_stub.timer_status_cb) {
if( -1 != coap_security_handler_stub.timer_status_cb(4) )
if (-1 != coap_security_handler_stub.timer_status_cb(4)) {
return false;
}
if( 0 != coap_security_handler_stub.timer_status_cb(1) )
if (0 != coap_security_handler_stub.timer_status_cb(1)) {
return false;
}
}
if (ns_timer_stub.cb) {
ns_timer_stub.cb(4, 0);
@ -360,8 +402,9 @@ bool test_socket_api_callbacks()
nsdynmemlib_stub.returnCounter = 1;
coap_conn_handler_t *handler = connection_handler_create(&receive_from_sock_cb, &send_to_sock_cb, NULL, NULL);
nsdynmemlib_stub.returnCounter = 2;
if( 0 != coap_connection_handler_open_connection(handler, 22,false,false,true,false) )
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;
@ -382,8 +425,9 @@ bool test_socket_api_callbacks()
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_test);
nsdynmemlib_stub.returnCounter = 2;
if( 0 != coap_connection_handler_open_connection(handler2, 22,false,true,true,false) )
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;
@ -438,8 +482,9 @@ bool test_security_callbacks()
nsdynmemlib_stub.returnCounter = 1;
coap_conn_handler_t *handler = connection_handler_create(&receive_from_sock_cb, &send_to_sock_cb, NULL, NULL);
nsdynmemlib_stub.returnCounter = 2;
if( 0 != coap_connection_handler_open_connection(handler, 22,false,true,true,false) )
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;

View File

@ -19,12 +19,10 @@
TEST_GROUP(coap_message_handler)
{
void setup()
{
void setup() {
}
void teardown()
{
void teardown() {
}
};
@ -63,6 +61,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());

View File

@ -49,7 +49,8 @@ static uint8_t coap_tx_function(uint8_t *data_ptr, uint16_t data_len, sn_nsdl_ad
return 0;
}
int resp_recv(int8_t service_id, uint16_t msg_id, sn_coap_hdr_s *response_ptr){
int resp_recv(int8_t service_id, uint16_t msg_id, sn_coap_hdr_s *response_ptr)
{
return retValue;
}
@ -66,25 +67,31 @@ static int transaction_recv_cb(int8_t service_id, uint8_t source_address[static
bool test_coap_message_handler_init()
{
if( NULL != coap_message_handler_init(NULL, NULL, NULL) )
if (NULL != coap_message_handler_init(NULL, NULL, NULL)) {
return false;
if( NULL != coap_message_handler_init(&test_own_alloc, NULL, NULL) )
}
if (NULL != coap_message_handler_init(&test_own_alloc, NULL, NULL)) {
return false;
if( NULL != coap_message_handler_init(&test_own_alloc, &test_own_free, NULL) )
}
if (NULL != coap_message_handler_init(&test_own_alloc, &test_own_free, NULL)) {
return false;
if( NULL != coap_message_handler_init(&test_own_alloc, &test_own_free, &coap_tx_function) )
}
if (NULL != coap_message_handler_init(&test_own_alloc, &test_own_free, &coap_tx_function)) {
return false;
}
retCounter = 1;
sn_coap_protocol_stub.expectedCoap = NULL;
if( NULL != coap_message_handler_init(&test_own_alloc, &test_own_free, &coap_tx_function) )
if (NULL != coap_message_handler_init(&test_own_alloc, &test_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));
nsdynmemlib_stub.returnCounter = 1;
coap_msg_handler_t *handle = coap_message_handler_init(&test_own_alloc, &test_own_free, &coap_tx_function);
if( NULL == handle )
if (NULL == handle) {
return false;
}
free(sn_coap_protocol_stub.expectedCoap);
sn_coap_protocol_stub.expectedCoap = NULL;
free(handle);
@ -93,16 +100,18 @@ bool test_coap_message_handler_init()
bool test_coap_message_handler_destroy()
{
if( -1 != coap_message_handler_destroy(NULL) )
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));
nsdynmemlib_stub.returnCounter = 1;
coap_msg_handler_t *handle = coap_message_handler_init(&test_own_alloc, &test_own_free, &coap_tx_function);
if( 0 != coap_message_handler_destroy(handle) )
if (0 != coap_message_handler_destroy(handle)) {
return false;
}
free(sn_coap_protocol_stub.expectedCoap);
return true;
@ -110,8 +119,9 @@ bool test_coap_message_handler_destroy()
bool test_coap_message_handler_find_transaction()
{
if( NULL != coap_message_handler_find_transaction(NULL, 0))
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));
@ -127,11 +137,13 @@ bool test_coap_message_handler_find_transaction()
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))
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))
if (NULL == coap_message_handler_find_transaction(&buf, 24)) {
return false;
}
free(sn_coap_protocol_stub.expectedCoap);
sn_coap_protocol_stub.expectedCoap = NULL;
@ -145,8 +157,9 @@ bool test_coap_message_handler_coap_msg_process()
memset(&buf, 1, 16);
bool ret_val = false;
/*Handler is null*/
if( -1 != coap_message_handler_coap_msg_process(NULL, 0, buf, 22, ns_in6addr_any, NULL, 0, NULL))
if (-1 != coap_message_handler_coap_msg_process(NULL, 0, buf, 22, ns_in6addr_any, NULL, 0, NULL)) {
goto exit;
}
retCounter = 1;
sn_coap_protocol_stub.expectedCoap = (struct coap_s *)malloc(sizeof(struct coap_s));
@ -156,16 +169,18 @@ bool test_coap_message_handler_coap_msg_process()
sn_coap_protocol_stub.expectedHeader = NULL;
/* Coap parse returns null */
if( -1 != coap_message_handler_coap_msg_process(handle, 0, buf, 22, ns_in6addr_any, NULL, 0, process_cb))
if (-1 != coap_message_handler_coap_msg_process(handle, 0, buf, 22, ns_in6addr_any, NULL, 0, process_cb)) {
goto exit;
}
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;
nsdynmemlib_stub.returnCounter = 1;
/* Coap library responds */
if( -1 != coap_message_handler_coap_msg_process(handle, 0, buf, 22, ns_in6addr_any, NULL, 0, process_cb))
if (-1 != coap_message_handler_coap_msg_process(handle, 0, buf, 22, ns_in6addr_any, NULL, 0, process_cb)) {
goto exit;
}
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));
@ -174,8 +189,9 @@ bool test_coap_message_handler_coap_msg_process()
retValue = 0;
/* request received */
nsdynmemlib_stub.returnCounter = 1;
if( 0 != coap_message_handler_coap_msg_process(handle, 0, buf, 22, ns_in6addr_any, NULL, 0, process_cb))
if (0 != coap_message_handler_coap_msg_process(handle, 0, buf, 22, ns_in6addr_any, NULL, 0, process_cb)) {
goto exit;
}
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));
@ -183,8 +199,9 @@ bool test_coap_message_handler_coap_msg_process()
sn_coap_protocol_stub.expectedHeader->msg_code = 1;
nsdynmemlib_stub.returnCounter = 1;
retValue = -1;
if( 0 != coap_message_handler_coap_msg_process(handle, 0, buf, 22, ns_in6addr_any, NULL, 0, process_cb))
if (0 != coap_message_handler_coap_msg_process(handle, 0, buf, 22, ns_in6addr_any, NULL, 0, process_cb)) {
goto exit;
}
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));
@ -192,8 +209,9 @@ bool test_coap_message_handler_coap_msg_process()
sn_coap_protocol_stub.expectedHeader->msg_code = 333;
nsdynmemlib_stub.returnCounter = 1;
if( -1 != coap_message_handler_coap_msg_process(handle, 0, buf, 22, ns_in6addr_any, NULL, 0, process_cb))
if (-1 != coap_message_handler_coap_msg_process(handle, 0, buf, 22, ns_in6addr_any, NULL, 0, process_cb)) {
goto exit;
}
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));
@ -207,13 +225,15 @@ bool test_coap_message_handler_coap_msg_process()
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))
if (2 != coap_message_handler_request_send(handle, 3, 0, buf, 24, 1, 2, &uri, 4, NULL, 0, &resp_recv)) {
goto exit;
}
sn_coap_protocol_stub.expectedHeader->msg_id = 2;
if( -1 != coap_message_handler_coap_msg_process(handle, 0, buf, 22, ns_in6addr_any, NULL, 0, process_cb))
if (-1 != coap_message_handler_coap_msg_process(handle, 0, buf, 22, ns_in6addr_any, NULL, 0, process_cb)) {
goto exit;
}
ret_val = true;
exit:
@ -233,61 +253,70 @@ bool test_coap_message_handler_request_send()
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))
char uri[3] = "rs";
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))
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))
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))
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))
if (2 != coap_message_handler_request_send(handle, 3, 0, buf, 24, 1, 2, &uri, 4, NULL, 0, &resp_recv)) {
return false;
}
/* Clear all transactions */
if( 0 != coap_message_handler_exec(handle, 0xffffffff))
if (0 != coap_message_handler_exec(handle, 0xffffffff)) {
return false;
}
sn_coap_protocol_stub.expectedInt16 = -4;
nsdynmemlib_stub.returnCounter = 3;
if( 2 != coap_message_handler_request_send(handle, 3, 0, buf, 24, 1, 2, &uri, 4, NULL, 0, &transaction_recv_cb))
if (2 != coap_message_handler_request_send(handle, 3, 0, buf, 24, 1, 2, &uri, 4, NULL, 0, &transaction_recv_cb)) {
return false;
}
transaction_cb = 0;
sn_coap_protocol_stub.expectedInt8 = 0;
if( 0 != coap_message_handler_exec(handle, 12))
if (0 != coap_message_handler_exec(handle, 12)) {
return false;
}
if (transaction_cb != 1)
if (transaction_cb != 1) {
return false;
}
sn_coap_protocol_stub.expectedInt16 = -2;
nsdynmemlib_stub.returnCounter = 3;
if( 2 != coap_message_handler_request_send(handle, 3, 0, buf, 24, 1, 2, &uri, 4, NULL, 0, &transaction_recv_cb))
if (2 != coap_message_handler_request_send(handle, 3, 0, buf, 24, 1, 2, &uri, 4, NULL, 0, &transaction_recv_cb)) {
return false;
}
transaction_cb = 0;
if (0 != coap_message_handler_exec(handle, 2)) {
return false;
}
if (transaction_cb != 1)
if (transaction_cb != 1) {
return false;
}
free(sn_coap_protocol_stub.expectedCoap);
@ -310,19 +339,23 @@ bool test_coap_message_handler_request_delete()
uri[0] = "r";
uri[1] = "s";
uri[2] = "\0";
if( 0 == coap_message_handler_request_delete(NULL, 1, 1))
if (0 == coap_message_handler_request_delete(NULL, 1, 1)) {
return false;
}
if( 0 == coap_message_handler_request_delete(handle, 1, 1))
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))
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))
if (0 != coap_message_handler_request_delete(handle, 1, 2)) {
return false;
}
free(sn_coap_protocol_stub.expectedCoap);
sn_coap_protocol_stub.expectedCoap = NULL;
@ -330,10 +363,49 @@ bool test_coap_message_handler_request_delete()
return true;
}
bool test_coap_message_handler_request_delete_by_service_id()
{
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));
nsdynmemlib_stub.returnCounter = 1;
coap_msg_handler_t *handle = coap_message_handler_init(&test_own_alloc, &test_own_free, &coap_tx_function);
coap_service_handle = handle;
uint8_t buf[16];
memset(&buf, 1, 16);
char uri[3] = "rs";
if (0 == coap_message_handler_request_delete_by_service_id(NULL, 1)) {
return false;
}
if (0 != coap_message_handler_request_delete_by_service_id(handle, 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_by_service_id(handle, 3)) {
return false;
}
free(sn_coap_protocol_stub.expectedCoap);
sn_coap_protocol_stub.expectedCoap = NULL;
coap_message_handler_destroy(handle);
coap_service_handle = NULL;
return true;
}
bool test_coap_message_handler_response_send()
{
if( -1 != coap_message_handler_response_send(NULL, 2, 0, NULL, 1,3,NULL, 0))
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));
@ -343,8 +415,9 @@ bool test_coap_message_handler_response_send()
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))
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);
@ -354,8 +427,9 @@ bool test_coap_message_handler_response_send()
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))
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;
@ -364,20 +438,23 @@ bool test_coap_message_handler_response_send()
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))
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 = 0;
if( -1 != coap_message_handler_response_send(handle, 2, 0, header, 1,3,NULL, 0))
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( 0 != coap_message_handler_response_send(handle, 2, 0, header, 1,3,NULL, 0))
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);
@ -389,8 +466,9 @@ bool test_coap_message_handler_response_send()
bool test_coap_message_handler_exec()
{
/* Null as a parameter */
if( -1 != coap_message_handler_exec(NULL, 0))
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));
@ -398,43 +476,52 @@ bool test_coap_message_handler_exec()
nsdynmemlib_stub.returnCounter = 1;
coap_msg_handler_t *handle = coap_message_handler_init(&test_own_alloc, &test_own_free, &coap_tx_function);
if( 0 != coap_message_handler_exec(handle, 0))
if (0 != coap_message_handler_exec(handle, 0)) {
return false;
}
nsdynmemlib_stub.returnCounter = 1;
coap_transaction_t *transact_ptr = transaction_create();
/* Transaction not timed out*/
if( 0 != coap_message_handler_exec(handle, 0))
if (0 != coap_message_handler_exec(handle, 0)) {
return false;
}
if (transaction_cb != 0)
if (transaction_cb != 0) {
return false;
}
/* Timed out, no CB */
if( 0 != coap_message_handler_exec(handle, 300))
if (0 != coap_message_handler_exec(handle, 300)) {
return false;
}
if (transaction_cb != 0)
if (transaction_cb != 0) {
return false;
}
nsdynmemlib_stub.returnCounter = 1;
transact_ptr = transaction_create();
transact_ptr->resp_cb = transaction_recv_cb;
/* Transaction not timed out */
if( 0 != coap_message_handler_exec(handle, 0))
if (0 != coap_message_handler_exec(handle, 0)) {
return false;
}
if (transaction_cb != 0)
if (transaction_cb != 0) {
return false;
}
/* Transaction timed out */
if( 0 != coap_message_handler_exec(handle, 300))
if (0 != coap_message_handler_exec(handle, 300)) {
return false;
}
if (transaction_cb == 0)
if (transaction_cb == 0) {
return false;
}
/* Teardown */
free(sn_coap_protocol_stub.expectedCoap);

View File

@ -30,6 +30,7 @@ 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_request_delete_by_service_id();
bool test_coap_message_handler_exec();
#ifdef __cplusplus

View File

@ -21,14 +21,12 @@
TEST_GROUP(coap_security_handler)
{
void setup()
{
void setup() {
nsdynmemlib_stub.returnCounter = 0;
mbedtls_stub.useCounter = false;
}
void teardown()
{
void teardown() {
}
};

View File

@ -43,28 +43,33 @@ static int timer_status_callback(int8_t timer_id)
bool test_thread_security_create()
{
if( NULL != coap_security_create(1,2,NULL,ECJPAKE,&send_to_socket, &receive_from_socket, &start_timer_callback, NULL) )
if (NULL != coap_security_create(1, 2, NULL, ECJPAKE, &send_to_socket, &receive_from_socket, &start_timer_callback, NULL)) {
return false;
}
if( NULL != coap_security_create(1,2,NULL,ECJPAKE,&send_to_socket, &receive_from_socket, &start_timer_callback, &timer_status_callback) )
if (NULL != coap_security_create(1, 2, NULL, ECJPAKE, &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 != coap_security_create(1,2,NULL,ECJPAKE,&send_to_socket, &receive_from_socket, &start_timer_callback, &timer_status_callback) )
if (NULL != coap_security_create(1, 2, NULL, ECJPAKE, &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 != coap_security_create(1,2,NULL,ECJPAKE,&send_to_socket, &receive_from_socket, &start_timer_callback, &timer_status_callback) )
if (NULL != coap_security_create(1, 2, NULL, ECJPAKE, &send_to_socket, &receive_from_socket, &start_timer_callback, &timer_status_callback)) {
return false;
}
nsdynmemlib_stub.returnCounter = 2;
mbedtls_stub.crt_expected_int = 0;
coap_security_t *handle = coap_security_create(1, 2, NULL, ECJPAKE, &send_to_socket, &receive_from_socket, &start_timer_callback, &timer_status_callback);
if( NULL == handle )
if (NULL == handle) {
return false;
}
coap_security_destroy(handle);
@ -76,8 +81,9 @@ bool test_thread_security_destroy()
nsdynmemlib_stub.returnCounter = 2;
mbedtls_stub.crt_expected_int = 0;
coap_security_t *handle = coap_security_create(1, 2, NULL, ECJPAKE, &send_to_socket, &receive_from_socket, &start_timer_callback, &timer_status_callback);
if( NULL == handle )
if (NULL == handle) {
return false;
}
coap_security_destroy(handle);
return true;
@ -88,15 +94,17 @@ bool test_coap_security_handler_connect()
nsdynmemlib_stub.returnCounter = 2;
mbedtls_stub.crt_expected_int = 0;
coap_security_t *handle = coap_security_create(1, 2, NULL, ECJPAKE, &send_to_socket, &receive_from_socket, &start_timer_callback, &timer_status_callback);
if( NULL == handle )
if (NULL == handle) {
return false;
}
unsigned char pw = "pwd";
coap_security_keys_t keys;
keys._key = &pw;
keys._key_len = 3;
if( -1 != coap_security_handler_connect_non_blocking(NULL, true, DTLS, keys, 0, 1) )
if (-1 != coap_security_handler_connect_non_blocking(NULL, true, DTLS, keys, 0, 1)) {
return false;
}
mbedtls_stub.useCounter = true;
mbedtls_stub.counter = 0;
mbedtls_stub.retArray[0] = -1;
@ -108,19 +116,22 @@ bool test_coap_security_handler_connect()
mbedtls_stub.retArray[6] = -1;
mbedtls_stub.retArray[7] = -1;
if( -1 != coap_security_handler_connect_non_blocking(handle, true, DTLS, keys, 0, 1) )
if (-1 != coap_security_handler_connect_non_blocking(handle, true, DTLS, keys, 0, 1)) {
return false;
}
mbedtls_stub.counter = 0;
mbedtls_stub.retArray[0] = 0;
if( -1 != coap_security_handler_connect_non_blocking(handle, true, DTLS, keys, 0, 1) )
if (-1 != coap_security_handler_connect_non_blocking(handle, true, DTLS, keys, 0, 1)) {
return false;
}
mbedtls_stub.counter = 0;
// mbedtls_stub.retArray[0] = 0;
mbedtls_stub.retArray[1] = 0;
if( -1 != coap_security_handler_connect_non_blocking(handle, true, DTLS, keys, 0, 1) )
if (-1 != coap_security_handler_connect_non_blocking(handle, true, DTLS, keys, 0, 1)) {
return false;
}
simple_cookie_t c;
memset(&c, 0, sizeof(simple_cookie_t));
@ -131,8 +142,9 @@ bool test_coap_security_handler_connect()
// mbedtls_stub.retArray[0] = 0;
// mbedtls_stub.retArray[1] = 0;
mbedtls_stub.retArray[2] = 0;
if( -1 != coap_security_handler_connect_non_blocking(handle, true, DTLS, keys, 0, 1) )
if (-1 != coap_security_handler_connect_non_blocking(handle, true, DTLS, keys, 0, 1)) {
return false;
}
c.len = 8;
memset(&c.value, 1, 8);
@ -145,8 +157,9 @@ bool test_coap_security_handler_connect()
// mbedtls_stub.retArray[1] = 0;
// mbedtls_stub.retArray[2] = 0;
mbedtls_stub.retArray[3] = 0;
if( -1 != coap_security_handler_connect_non_blocking(handle, true, DTLS, keys, 0, 1) )
if (-1 != coap_security_handler_connect_non_blocking(handle, true, DTLS, keys, 0, 1)) {
return false;
}
mbedtls_stub.counter = 0;
// mbedtls_stub.retArray[0] = 0;
@ -154,8 +167,9 @@ bool test_coap_security_handler_connect()
// mbedtls_stub.retArray[2] = 0;
// mbedtls_stub.retArray[3] = 0;
mbedtls_stub.retArray[4] = 0;
if( -1 != coap_security_handler_connect_non_blocking(handle, true, DTLS, keys, 0, 1) )
if (-1 != coap_security_handler_connect_non_blocking(handle, true, DTLS, keys, 0, 1)) {
return false;
}
mbedtls_stub.counter = 0;
// mbedtls_stub.retArray[0] = 0;
@ -165,20 +179,23 @@ bool test_coap_security_handler_connect()
// mbedtls_stub.retArray[4] = 0;
mbedtls_stub.retArray[6] = 0;
mbedtls_stub.retArray[7] = 0;
if( 1 != coap_security_handler_connect_non_blocking(handle, true, DTLS, keys, 0, 1) )
if (1 != coap_security_handler_connect_non_blocking(handle, true, DTLS, keys, 0, 1)) {
return false;
}
mbedtls_stub.counter = 0;
mbedtls_stub.retArray[5] = MBEDTLS_ERR_SSL_BAD_HS_FINISHED;
if( -1 != coap_security_handler_connect_non_blocking(handle, true, DTLS, keys, 0, 1) )
if (-1 != coap_security_handler_connect_non_blocking(handle, true, DTLS, keys, 0, 1)) {
return false;
}
mbedtls_stub.counter = 0;
mbedtls_stub.retArray[5] = HANDSHAKE_FINISHED_VALUE;
if( 1 != coap_security_handler_connect_non_blocking(handle, true, DTLS, keys, 0, 1) )
if (1 != coap_security_handler_connect_non_blocking(handle, true, DTLS, keys, 0, 1)) {
return false;
}
coap_security_destroy(handle);
return true;
@ -189,8 +206,9 @@ bool test_coap_security_handler_continue_connecting()
nsdynmemlib_stub.returnCounter = 2;
mbedtls_stub.crt_expected_int = 0;
coap_security_t *handle = coap_security_create(1, 2, NULL, ECJPAKE, &send_to_socket, &receive_from_socket, &start_timer_callback, &timer_status_callback);
if( NULL == handle )
if (NULL == handle) {
return false;
}
mbedtls_stub.useCounter = true;
mbedtls_stub.counter = 0;
@ -198,34 +216,39 @@ bool test_coap_security_handler_continue_connecting()
mbedtls_stub.retArray[1] = -1;
mbedtls_stub.retArray[2] = -1;
if( -1 != coap_security_handler_continue_connecting(handle) )
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) )
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_BAD_HS_FINISHED != coap_security_handler_continue_connecting(handle) )
if (MBEDTLS_ERR_SSL_BAD_HS_FINISHED != coap_security_handler_continue_connecting(handle)) {
return false;
}
mbedtls_stub.counter = 0;
mbedtls_stub.retArray[0] = MBEDTLS_ERR_SSL_WANT_READ;
if( 1 != coap_security_handler_continue_connecting(handle) )
if (1 != coap_security_handler_continue_connecting(handle)) {
return false;
}
mbedtls_stub.counter = 0;
mbedtls_stub.retArray[0] = HANDSHAKE_FINISHED_VALUE_RETURN_ZERO;
if( 0 != coap_security_handler_continue_connecting(handle) )
if (0 != coap_security_handler_continue_connecting(handle)) {
return false;
}
coap_security_destroy(handle);
return true;
@ -236,16 +259,19 @@ bool test_coap_security_handler_send_message()
nsdynmemlib_stub.returnCounter = 2;
mbedtls_stub.crt_expected_int = 0;
coap_security_t *handle = coap_security_create(1, 2, NULL, ECJPAKE, &send_to_socket, &receive_from_socket, &start_timer_callback, &timer_status_callback);
if( NULL == handle )
if (NULL == handle) {
return false;
}
if( -1 != coap_security_handler_send_message(NULL, NULL, 0))
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))
if (6 != coap_security_handler_send_message(handle, &cbuf, 6)) {
return false;
}
coap_security_destroy(handle);
return true;
@ -256,15 +282,18 @@ bool test_thread_security_send_close_alert()
nsdynmemlib_stub.returnCounter = 2;
mbedtls_stub.crt_expected_int = 0;
coap_security_t *handle = coap_security_create(1, 2, NULL, ECJPAKE, &send_to_socket, &receive_from_socket, &start_timer_callback, &timer_status_callback);
if( NULL == handle )
if (NULL == handle) {
return false;
}
if( -1 != coap_security_send_close_alert(NULL))
if (-1 != coap_security_send_close_alert(NULL)) {
return false;
}
mbedtls_stub.expected_int = 0;
if( 0 != coap_security_send_close_alert(handle))
if (0 != coap_security_send_close_alert(handle)) {
return false;
}
coap_security_destroy(handle);
return true;
@ -275,16 +304,19 @@ bool test_coap_security_handler_read()
nsdynmemlib_stub.returnCounter = 2;
mbedtls_stub.crt_expected_int = 0;
coap_security_t *handle = coap_security_create(1, 2, NULL, ECJPAKE, &send_to_socket, &receive_from_socket, &start_timer_callback, &timer_status_callback);
if( NULL == handle )
if (NULL == handle) {
return false;
}
if( -1 != coap_security_handler_read(NULL, NULL, 0))
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))
if (6 != coap_security_handler_read(handle, &cbuf, 6)) {
return false;
}
coap_security_destroy(handle);
return true;

View File

@ -19,12 +19,10 @@
TEST_GROUP(coap_service_api)
{
void setup()
{
void setup() {
}
void teardown()
{
void teardown() {
}
};
@ -68,6 +66,11 @@ TEST(coap_service_api, test_coap_service_request_delete)
CHECK(test_coap_service_request_delete());
}
TEST(coap_service_api, test_coap_service_request_delete_by_service_id)
{
CHECK(test_coap_service_request_delete_by_service_id());
}
TEST(coap_service_api, test_coap_service_response_send)
{
CHECK(test_coap_service_response_send());

View File

@ -25,7 +25,8 @@
#include "net_interface.h"
#include "coap_service_api.c"
int sec_done_cb_test(int8_t service_id, uint8_t address[static 16], uint8_t keyblock[static 40]){
int sec_done_cb_test(int8_t service_id, uint8_t address[static 16], uint8_t keyblock[static 40])
{
return 2;
}
@ -46,14 +47,16 @@ int virtual_sock_send_cb(int8_t service_id, uint8_t destination_addr_ptr[static
bool test_coap_service_initialize()
{
if( -1 != coap_service_initialize(1, 2, 0, NULL, NULL ))
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 ))
if (-1 != coap_service_initialize(1, 2, 0, NULL, NULL)) {
return false;
}
thread_conn_handler_stub.handler_obj = (coap_conn_handler_t *)malloc(sizeof(coap_conn_handler_t));
memset(thread_conn_handler_stub.handler_obj, 0, sizeof(coap_conn_handler_t));
@ -61,20 +64,23 @@ bool test_coap_service_initialize()
nsdynmemlib_stub.returnCounter = 1;
thread_conn_handler_stub.int_value = -1;
if( -1 != coap_service_initialize(1, 2, 0, NULL, NULL ))
if (-1 != coap_service_initialize(1, 2, 0, NULL, NULL)) {
return false;
}
thread_conn_handler_stub.handler_obj = (coap_conn_handler_t *)malloc(sizeof(coap_conn_handler_t));
memset(thread_conn_handler_stub.handler_obj, 0, sizeof(coap_conn_handler_t));
nsdynmemlib_stub.returnCounter = 1;
thread_conn_handler_stub.int_value = 0;
if( 1 != coap_service_initialize(1, 2, 0, NULL, 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 ))
if (2 != coap_service_initialize(3, 4, 0, NULL, NULL)) {
return false;
}
coap_service_delete(2);
coap_service_delete(1);
@ -93,8 +99,9 @@ bool test_coap_service_delete()
nsdynmemlib_stub.returnCounter = 1;
coap_message_handler_stub.coap_ptr = NULL;
if( 1 != coap_service_initialize(1, 2, 0, NULL, NULL ))
if (1 != coap_service_initialize(1, 2, 0, NULL, NULL)) {
return false;
}
coap_service_delete(1);
@ -107,20 +114,23 @@ bool test_coap_service_delete()
bool test_coap_service_virtual_socket_recv()
{
uint8_t buf[16];
if( -1 != coap_service_virtual_socket_recv(1, &buf, 10, NULL, 0) )
if (-1 != coap_service_virtual_socket_recv(1, &buf, 10, NULL, 0)) {
return false;
}
thread_conn_handler_stub.handler_obj = (coap_conn_handler_t *)malloc(sizeof(coap_conn_handler_t));
memset(thread_conn_handler_stub.handler_obj, 0, sizeof(coap_conn_handler_t));
nsdynmemlib_stub.returnCounter = 1;
coap_message_handler_stub.coap_ptr = NULL;
if( 1 != coap_service_initialize(1, 2, 0, NULL, 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) )
if (5 != coap_service_virtual_socket_recv(1, &buf, 10, NULL, 0)) {
return false;
}
coap_service_delete(1);
@ -134,19 +144,22 @@ bool test_coap_service_virtual_socket_recv()
bool test_coap_service_virtual_socket_set_cb()
{
if( -1 != coap_service_virtual_socket_set_cb(1, NULL) )
if (-1 != coap_service_virtual_socket_set_cb(1, NULL)) {
return false;
}
thread_conn_handler_stub.handler_obj = (coap_conn_handler_t *)malloc(sizeof(coap_conn_handler_t));
memset(thread_conn_handler_stub.handler_obj, 0, sizeof(coap_conn_handler_t));
nsdynmemlib_stub.returnCounter = 1;
coap_message_handler_stub.coap_ptr = NULL;
if( 1 != coap_service_initialize(1, 2, 0, NULL, NULL ))
if (1 != coap_service_initialize(1, 2, 0, NULL, NULL)) {
return false;
}
if( 0 != coap_service_virtual_socket_set_cb(1, NULL) )
if (0 != coap_service_virtual_socket_set_cb(1, NULL)) {
return false;
}
coap_service_delete(1);
@ -158,27 +171,32 @@ bool test_coap_service_virtual_socket_set_cb()
bool test_coap_service_register_uri()
{
if( -1 != coap_service_register_uri(1, "as", 1, &request_recv_cb))
if (-1 != coap_service_register_uri(1, "as", 1, &request_recv_cb)) {
return false;
}
thread_conn_handler_stub.handler_obj = (coap_conn_handler_t *)malloc(sizeof(coap_conn_handler_t));
memset(thread_conn_handler_stub.handler_obj, 0, sizeof(coap_conn_handler_t));
nsdynmemlib_stub.returnCounter = 1;
coap_message_handler_stub.coap_ptr = NULL;
if( 1 != coap_service_initialize(1, 2, 0, NULL, 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) )
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) )
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) )
if (0 != coap_service_register_uri(1, "as", 1, &request_recv_cb)) {
return false;
}
coap_service_delete(1);
@ -190,8 +208,9 @@ bool test_coap_service_register_uri()
bool test_coap_service_unregister_uri()
{
if( -1 != coap_service_unregister_uri(1, "as"))
if (-1 != coap_service_unregister_uri(1, "as")) {
return false;
}
thread_conn_handler_stub.handler_obj = (coap_conn_handler_t *)malloc(sizeof(coap_conn_handler_t));
memset(thread_conn_handler_stub.handler_obj, 0, sizeof(coap_conn_handler_t));
@ -199,18 +218,22 @@ bool test_coap_service_unregister_uri()
coap_message_handler_stub.coap_ptr = NULL;
thread_conn_handler_stub.int_value = 0;
if( 1 != coap_service_initialize(1, 2, 0, NULL, 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) )
if (0 != coap_service_register_uri(1, "as", 1, &request_recv_cb)) {
return false;
}
if( -2 != coap_service_unregister_uri(1, "ts") )
if (-2 != coap_service_unregister_uri(1, "ts")) {
return false;
}
if( 0 != coap_service_unregister_uri(1, "as") )
if (0 != coap_service_unregister_uri(1, "as")) {
return false;
}
coap_service_delete(1);
@ -224,15 +247,23 @@ 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))
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_request_delete()
{
if( 0 != coap_service_request_delete(NULL,0))
if (0 != coap_service_request_delete(NULL, 0)) {
return false;
}
return true;
}
bool test_coap_service_request_delete_by_service_id()
{
coap_service_request_delete_by_service_id(0);
return true;
}
@ -240,8 +271,9 @@ 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))
if (6 != coap_service_response_send(0, 0, NULL, 65, 0, NULL, 0)) {
return false;
}
return true;
}
@ -253,16 +285,19 @@ bool test_coap_callbacks()
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 ))
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))
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 )
if (0 == handle) {
return false;
}
coap_message_handler_stub.coap_ptr->sn_coap_service_free(handle);
@ -273,23 +308,27 @@ bool test_coap_callbacks()
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))
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))
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))
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))
if (0 != coap_message_handler_stub.coap_ptr->sn_coap_tx_callback(&data, 2, &addr, tr)) {
return false;
}
free(tr->data_ptr);
free(tr);
@ -312,8 +351,9 @@ bool test_eventOS_callbacks()
thread_conn_handler_stub.handler_obj = (coap_conn_handler_t *)malloc(sizeof(coap_conn_handler_t));
memset(thread_conn_handler_stub.handler_obj, 0, sizeof(coap_conn_handler_t));
nsdynmemlib_stub.returnCounter = 1;
if( 1 != coap_service_initialize(1, 2, 0, NULL, NULL ))
if (1 != coap_service_initialize(1, 2, 0, NULL, NULL)) {
return false;
}
if (eventOs_event_stub.event_ptr) {
arm_event_s event;
@ -337,38 +377,44 @@ bool test_conn_handler_callbacks()
thread_conn_handler_stub.handler_obj = (coap_conn_handler_t *)malloc(sizeof(coap_conn_handler_t));
memset(thread_conn_handler_stub.handler_obj, 0, sizeof(coap_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_test ))
if (1 != coap_service_initialize(1, 2, COAP_SERVICE_OPTIONS_SECURE_BYPASS, &sec_start_cb, &sec_done_cb_test)) {
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))
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))
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, NULL, 0))
if (-1 != thread_conn_handler_stub.receive_from_sock_cb(1, buf, 12, NULL, 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, NULL, ptr, 5))
if (2 != thread_conn_handler_stub.receive_from_sock_cb(1, buf, 12, NULL, 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) )
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));
@ -377,22 +423,26 @@ bool test_conn_handler_callbacks()
coap->uri_path_ptr = &uri;
coap->uri_path_len = 2;
if( -1 != coap_message_handler_stub.cb(1, coap, NULL) )
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) )
if (0 != coap_service_register_uri(1, "as", 1, &request_recv_cb)) {
return false;
}
if( -1 != coap_message_handler_stub.cb(1, coap, NULL) )
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) )
if (2 != coap_message_handler_stub.cb(1, coap, tr)) {
return false;
}
free(tr);
tr = NULL;
@ -408,13 +458,15 @@ bool test_conn_handler_callbacks()
memset(&security_ptr, 0, sizeof(coap_security_keys_t));
nsdynmemlib_stub.returnCounter = 1;
thread_conn_handler_stub.bool_value = true;
if( 0 != thread_conn_handler_stub.get_passwd_cb(1, buf, 12, &security_ptr))
if (0 != thread_conn_handler_stub.get_passwd_cb(1, buf, 12, &security_ptr)) {
return false;
}
free(security_ptr._key);
thread_conn_handler_stub.bool_value = false;
if( -1 != thread_conn_handler_stub.get_passwd_cb(1, buf, 12, NULL))
if (-1 != thread_conn_handler_stub.get_passwd_cb(1, buf, 12, NULL)) {
return false;
}
}
if (thread_conn_handler_stub.sec_done_cb) {
uint8_t block[40];
@ -455,8 +507,9 @@ bool test_certificate_set()
memset(thread_conn_handler_stub.handler_obj, 0, sizeof(coap_conn_handler_t));
nsdynmemlib_stub.returnCounter = 1;
if( 1 != coap_service_initialize(1, 2, 0, NULL, NULL ))
if (1 != coap_service_initialize(1, 2, 0, NULL, NULL)) {
return false;
}
/* Allocation fails */
if (-1 != coap_service_certificate_set(1, NULL, 0, NULL, 0)) {
@ -489,8 +542,9 @@ bool test_handshake_timeout_set()
memset(thread_conn_handler_stub.handler_obj, 0, sizeof(coap_conn_handler_t));
nsdynmemlib_stub.returnCounter = 1;
if( 1 != coap_service_initialize(1, 2, 0, NULL, NULL ))
if (1 != coap_service_initialize(1, 2, 0, NULL, NULL)) {
return false;
}
/* All OK */
nsdynmemlib_stub.returnCounter = 1;
@ -521,8 +575,9 @@ bool test_coap_duplcate_msg_buffer_set()
memset(coap_message_handler_stub.coap_ptr, 0, sizeof(coap_msg_handler_t));
nsdynmemlib_stub.returnCounter = 1;
if( 1 != coap_service_initialize(1, 2, 0, NULL, NULL ))
if (1 != coap_service_initialize(1, 2, 0, NULL, NULL)) {
ret = false;
}
/* All OK */
if (0 != coap_service_set_duplicate_message_buffer(0, 0)) {
@ -559,8 +614,9 @@ bool test_coap_service_if_find_by_socket()
nsdynmemlib_stub.returnCounter = 1;
thread_conn_handler_stub.bool_value = 0;
if( 1 != coap_service_initialize(1, 2, 0, NULL, NULL ))
if (1 != coap_service_initialize(1, 2, 0, NULL, NULL)) {
return false;
}
/* No matching service ID - return false */
if (0 != coap_service_id_find_by_socket(1)) {

View File

@ -39,6 +39,8 @@ bool test_coap_service_request_send();
bool test_coap_service_request_delete();
bool test_coap_service_request_delete_by_service_id();
bool test_coap_service_response_send();
bool test_coap_callbacks();

View File

@ -39,6 +39,7 @@ void transactions_delete_all(uint8_t *address_ptr, uint16_t port)
{
}
int8_t coap_message_handler_destroy(coap_msg_handler_t *handle)
{
return coap_message_handler_stub.int8_value;
@ -78,6 +79,11 @@ int8_t coap_message_handler_request_delete(coap_msg_handler_t *handle, int8_t se
return 0;
}
int8_t coap_message_handler_request_delete_by_service_id(coap_msg_handler_t *handle, int8_t service_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

@ -28,9 +28,10 @@ int mbedtls_ssl_handshake_step( mbedtls_ssl_context *ssl )
mbedtls_stub.retArray[mbedtls_stub.counter] == HANDSHAKE_FINISHED_VALUE_RETURN_ZERO) {
ssl->state = MBEDTLS_SSL_HANDSHAKE_OVER;
if(mbedtls_stub.retArray[mbedtls_stub.counter] == HANDSHAKE_FINISHED_VALUE_RETURN_ZERO)
if (mbedtls_stub.retArray[mbedtls_stub.counter] == HANDSHAKE_FINISHED_VALUE_RETURN_ZERO) {
return 0;
}
}
return mbedtls_stub.retArray[mbedtls_stub.counter++];
}
return mbedtls_stub.expected_int;
@ -44,18 +45,22 @@ int mbedtls_ssl_close_notify( mbedtls_ssl_context *a )
return mbedtls_stub.expected_int;
}
void mbedtls_ssl_init( mbedtls_ssl_context *a ){
void mbedtls_ssl_init(mbedtls_ssl_context *a)
{
}
void mbedtls_ssl_conf_min_version( mbedtls_ssl_config *conf, int major, int minor ){
void mbedtls_ssl_conf_min_version(mbedtls_ssl_config *conf, int major, int minor)
{
}
void mbedtls_ssl_conf_max_version( mbedtls_ssl_config *conf, int major, int minor ){
void mbedtls_ssl_conf_max_version(mbedtls_ssl_config *conf, int major, int minor)
{
}
void mbedtls_ssl_config_init( mbedtls_ssl_config *a ){
void mbedtls_ssl_config_init(mbedtls_ssl_config *a)
{
}
@ -64,32 +69,37 @@ void mbedtls_ssl_conf_handshake_timeout( mbedtls_ssl_config *a, uint32_t b, uint
}
void mbedtls_ssl_free( mbedtls_ssl_context *a ){
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 ){
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_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 ){
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 ){
const unsigned char *d, size_t e)
{
if (mbedtls_stub.useCounter) {
return mbedtls_stub.retArray[mbedtls_stub.counter++];
}
@ -97,7 +107,8 @@ int mbedtls_ssl_conf_psk( mbedtls_ssl_config *a,
}
int mbedtls_ssl_config_defaults(mbedtls_ssl_config *a,
int b, int c, int d){
int b, int c, int d)
{
if (mbedtls_stub.useCounter) {
return mbedtls_stub.retArray[mbedtls_stub.counter++];
}
@ -106,7 +117,8 @@ int mbedtls_ssl_config_defaults( mbedtls_ssl_config *a,
void mbedtls_ssl_conf_rng(mbedtls_ssl_config *a,
int (*f_rng)(void *, unsigned char *, size_t),
void *b ){
void *b)
{
}
@ -117,7 +129,8 @@ void mbedtls_ssl_conf_ciphersuites( mbedtls_ssl_config *a,
}
int mbedtls_ssl_setup(mbedtls_ssl_context *a,
const mbedtls_ssl_config *b ){
const mbedtls_ssl_config *b)
{
if (mbedtls_stub.useCounter) {
return mbedtls_stub.retArray[mbedtls_stub.counter++];
}
@ -128,21 +141,26 @@ 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) ){
int (*f_recv_timeout)(void *, unsigned char *, size_t, uint32_t))
{
if (p_bio != NULL) {
if( f_send )
if (f_send) {
f_send(p_bio, NULL, 0);
if( f_recv )
}
if (f_recv) {
f_recv(p_bio, NULL, 0);
if( f_recv_timeout )
}
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 *) ){
int (*f_get_timer)(void *))
{
f_set_timer(ctx, 1, 2);
f_get_timer(ctx);
if (mbedtls_stub.invalidate_timer) {
@ -151,25 +169,29 @@ void mbedtls_ssl_set_timer_cb( mbedtls_ssl_context *a,
f_get_timer(ctx);
}
int mbedtls_ssl_handshake( mbedtls_ssl_context *ssl ){
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 ){
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){
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 ){
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++];
}
@ -183,39 +205,47 @@ 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 ){
size_t d)
{
return mbedtls_stub.crt_expected_int;
}
void mbedtls_ctr_drbg_init( mbedtls_ctr_drbg_context *a ){
void mbedtls_ctr_drbg_init(mbedtls_ctr_drbg_context *a)
{
}
void mbedtls_ctr_drbg_free( 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 ){
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 ){
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_init(mbedtls_x509_crt *a)
{
}
void mbedtls_x509_crt_free( 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 ){
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++];
}
@ -223,15 +253,18 @@ int mbedtls_x509_crt_parse( mbedtls_x509_crt *a, const unsigned char *b, size_t
}
//From entropy.h
void mbedtls_entropy_init( mbedtls_entropy_context *a ){
void mbedtls_entropy_init(mbedtls_entropy_context *a)
{
}
void mbedtls_entropy_free( mbedtls_entropy_context *ctx ){
void mbedtls_entropy_free(mbedtls_entropy_context *ctx)
{
}
int mbedtls_entropy_func( void *a, unsigned char *b, size_t c ){
int mbedtls_entropy_func(void *a, unsigned char *b, size_t c)
{
if (mbedtls_stub.useCounter) {
return mbedtls_stub.retArray[mbedtls_stub.counter++];
}
@ -240,7 +273,8 @@ int mbedtls_entropy_func( void *a, unsigned char *b, size_t c ){
int mbedtls_entropy_add_source(mbedtls_entropy_context *a,
mbedtls_entropy_f_source_ptr f_source, void *b,
size_t c, int d ){
size_t c, int d)
{
unsigned char buf[2];
size_t len;
f_source(NULL, buf, 1, &len);
@ -254,7 +288,8 @@ int mbedtls_entropy_add_source( mbedtls_entropy_context *a,
//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 ){
const unsigned char *d, size_t e)
{
if (mbedtls_stub.useCounter) {
return mbedtls_stub.retArray[mbedtls_stub.counter++];
}

View File

@ -37,26 +37,20 @@ void ns_dyn_mem_init(void *heap, ns_mem_heap_size_t h_size, void (*passed_fptr)(
void *ns_dyn_mem_alloc(ns_mem_block_size_t alloc_size)
{
if (nsdynmemlib_stub.returnCounter > 0)
{
if (nsdynmemlib_stub.returnCounter > 0) {
nsdynmemlib_stub.returnCounter--;
return malloc(alloc_size);
}
else
{
} else {
return (nsdynmemlib_stub.expectedPointer);
}
}
void *ns_dyn_mem_temporary_alloc(ns_mem_block_size_t alloc_size)
{
if (nsdynmemlib_stub.returnCounter > 0)
{
if (nsdynmemlib_stub.returnCounter > 0) {
nsdynmemlib_stub.returnCounter--;
return malloc(alloc_size);
}
else
{
} else {
return (nsdynmemlib_stub.expectedPointer);
}
}

View File

@ -32,7 +32,10 @@ public:
virtual void attach(mbed::Callback<void(nsapi_event_t, intptr_t)> status_cb);
virtual nsapi_connection_status_t get_connection_status() const;
void get_mac_address(uint8_t *buf) const { interface_phy.get_mac_address(buf); }
void get_mac_address(uint8_t *buf) const
{
interface_phy.get_mac_address(buf);
}
/**
* \brief Callback from C-layer
@ -40,15 +43,24 @@ public:
* */
void network_handler(mesh_connection_status_t status);
int8_t get_interface_id() const { return interface_id; }
int8_t get_driver_id() const { return _device_id; }
int8_t get_interface_id() const
{
return interface_id;
}
int8_t get_driver_id() const
{
return _device_id;
}
private:
NanostackPhy &interface_phy;
protected:
Interface(NanostackPhy &phy);
virtual nsapi_error_t register_phy();
NanostackPhy &get_phy() const { return interface_phy; }
NanostackPhy &get_phy() const
{
return interface_phy;
}
int8_t interface_id;
int8_t _device_id;
rtos::Semaphore connect_semaphore;
@ -62,7 +74,10 @@ protected:
class Nanostack::MeshInterface : public Nanostack::Interface {
protected:
MeshInterface(NanostackRfPhy &phy) : Interface(phy) { }
NanostackRfPhy &get_phy() const { return static_cast<NanostackRfPhy &>(Interface::get_phy()); }
NanostackRfPhy &get_phy() const
{
return static_cast<NanostackRfPhy &>(Interface::get_phy());
}
};
@ -116,12 +131,18 @@ public:
/** Get the interface ID
/return Interface identifier
*/
int8_t get_interface_id() const { return _interface->get_interface_id(); }
int8_t get_interface_id() const
{
return _interface->get_interface_id();
}
protected:
InterfaceNanostack();
virtual Nanostack *get_stack(void);
Nanostack::Interface *get_interface() const { return _interface; }
Nanostack::Interface *get_interface() const
{
return _interface;
}
virtual nsapi_error_t do_initialize() = 0;
Nanostack::Interface *_interface;
@ -147,7 +168,10 @@ public:
protected:
MeshInterfaceNanostack() : _phy(NULL) { }
MeshInterfaceNanostack(NanostackRfPhy *phy) : _phy(phy) { }
Nanostack::MeshInterface *get_interface() const { return static_cast<Nanostack::MeshInterface *>(_interface); }
Nanostack::MeshInterface *get_interface() const
{
return static_cast<Nanostack::MeshInterface *>(_interface);
}
NanostackRfPhy *_phy;
};

View File

@ -35,7 +35,10 @@ private:
EthernetInterface(NanostackEthernetPhy &phy) : Interface(phy) {}
nsapi_error_t initialize();
protected:
NanostackEthernetPhy &get_phy() const { return static_cast<NanostackEthernetPhy &>(Interface::get_phy()); }
NanostackEthernetPhy &get_phy() const
{
return static_cast<NanostackEthernetPhy &>(Interface::get_phy());
}
};
/** Ethernet interface for Nanostack.
@ -50,7 +53,10 @@ public:
nsapi_error_t initialize(NanostackEthernetPhy *phy);
protected:
Nanostack::EthernetInterface *get_interface() const { return static_cast<Nanostack::EthernetInterface *>(_interface); }
Nanostack::EthernetInterface *get_interface() const
{
return static_cast<Nanostack::EthernetInterface *>(_interface);
}
virtual nsapi_error_t do_initialize();
};

View File

@ -8,8 +8,7 @@
#include "ns_trace.h"
#define TRACE_GROUP "nslp"
class Nanostack::LoWPANNDInterface : public Nanostack::MeshInterface
{
class Nanostack::LoWPANNDInterface : public Nanostack::MeshInterface {
public:
virtual nsapi_error_t bringup(bool dhcp, const char *ip,
const char *netmask, const char *gw,

View File

@ -8,8 +8,7 @@
#include "arm_hal_phy.h"
#include "EMAC.h"
class EMACPhy : public NanostackEthernetPhy
{
class EMACPhy : public NanostackEthernetPhy {
public:
EMACPhy(NanostackMemoryManager &mem, EMAC &m);
virtual int8_t phy_register();

View File

@ -19,8 +19,7 @@
#include "mbed_assert.h"
#include "NanostackMemoryManager.h"
struct ns_stack_mem_t
{
struct ns_stack_mem_t {
ns_stack_mem_t *next;
void *payload;
uint32_t len;

View File

@ -7,8 +7,7 @@
#include "ns_trace.h"
#define TRACE_GROUP "nsth"
class Nanostack::ThreadInterface : public Nanostack::MeshInterface
{
class Nanostack::ThreadInterface : public Nanostack::MeshInterface {
public:
virtual nsapi_error_t bringup(bool dhcp, const char *ip,
const char *netmask, const char *gw,

View File

@ -197,10 +197,11 @@ static void enet_tasklet_poll_network_status(void *param)
}
} else {
if (tasklet_data_ptr->connection_status != MESH_DISCONNECTED &&
tasklet_data_ptr->connection_status != MESH_BOOTSTRAP_STARTED)
tasklet_data_ptr->connection_status != MESH_BOOTSTRAP_STARTED) {
enet_tasklet_network_state_changed(MESH_DISCONNECTED);
}
}
}
/*
* \brief Configure and establish network connection

View File

@ -246,12 +246,14 @@ void thread_tasklet_poll_network_status(void *param)
}
} else {
if (thread_tasklet_data_ptr->connection_status != MESH_DISCONNECTED &&
thread_tasklet_data_ptr->connection_status != MESH_BOOTSTRAP_STARTED)
thread_tasklet_data_ptr->connection_status != MESH_BOOTSTRAP_STARTED) {
thread_tasklet_network_state_changed(MESH_DISCONNECTED);
}
}
}
void read_link_configuration() {
void read_link_configuration()
{
thread_tasklet_data_ptr->link_config.panId = MBED_CONF_MBED_MESH_API_THREAD_CONFIG_PANID;
TRACE_DETAIL("PANID %x", thread_tasklet_data_ptr->link_config.panId);
@ -305,8 +307,7 @@ void thread_tasklet_configure_and_connect_to_network(void)
if (MBED_CONF_MBED_MESH_API_THREAD_DEVICE_TYPE == MESH_DEVICE_TYPE_THREAD_MINIMAL_END_DEVICE) {
thread_tasklet_data_ptr->operating_mode = NET_6LOWPAN_HOST;
}
else if (MBED_CONF_MBED_MESH_API_THREAD_DEVICE_TYPE == MESH_DEVICE_TYPE_THREAD_SLEEPY_END_DEVICE) {
} else if (MBED_CONF_MBED_MESH_API_THREAD_DEVICE_TYPE == MESH_DEVICE_TYPE_THREAD_SLEEPY_END_DEVICE) {
thread_tasklet_data_ptr->operating_mode = NET_6LOWPAN_SLEEPY_HOST;
} else {
thread_tasklet_data_ptr->operating_mode = NET_6LOWPAN_ROUTER;

View File

@ -36,8 +36,7 @@ static const fhss_api_t *fhss_active_handle = NULL;
static EventQueue *equeue;
#endif
struct fhss_timeout_s
{
struct fhss_timeout_s {
void (*fhss_timer_callback)(const fhss_api_t *fhss_api, uint16_t);
uint32_t start_time;
uint32_t stop_time;

View File

@ -229,8 +229,7 @@ static int nvm_fsm_update(cs_context_t *cs_context)
int ret_val = 0;
tr_debug("nvm_fsm_update() state=%d", (int)cs_context->state);
switch (cs_context->state)
{
switch (cs_context->state) {
case NVM_STATE_UNINIT_DONE:
cs_context->client_cb(cs_context->client_status, cs_context->client_context);
cs_context->state = NVM_STATE_NONE;

View File

@ -22,8 +22,7 @@ uint8_t buf[100];
uint16_t buf_len;
uint16_t data_len;
typedef struct
{
typedef struct {
platform_nvm_status status;
void *ctx;
} test_platform_nvm_api_callback_t;

View File

@ -101,8 +101,7 @@ static int32_t test_cfstore_write(ARM_CFSTORE_HANDLE hkey, const char* data, ARM
return cfstore_stub.write_ret_val;
}
ARM_CFSTORE_DRIVER cfstore_driver =
{
ARM_CFSTORE_DRIVER cfstore_driver = {
.Close = test_cfstore_close,
.Create = test_cfstore_create,
.Delete = test_cfstore_delete,

View File

@ -17,26 +17,20 @@ void ns_dyn_mem_init(uint8_t *heap, uint16_t h_size, void (*passed_fptr)(heap_fa
void *ns_dyn_mem_alloc(int16_t alloc_size)
{
if (nsdynmemlib_stub.returnCounter > 0)
{
if (nsdynmemlib_stub.returnCounter > 0) {
nsdynmemlib_stub.returnCounter--;
return malloc(alloc_size);
}
else
{
} else {
return (nsdynmemlib_stub.expectedPointer);
}
}
void *ns_dyn_mem_temporary_alloc(int16_t alloc_size)
{
if (nsdynmemlib_stub.returnCounter > 0)
{
if (nsdynmemlib_stub.returnCounter > 0) {
nsdynmemlib_stub.returnCounter--;
return malloc(alloc_size);
}
else
{
} else {
return (nsdynmemlib_stub.expectedPointer);
}
}

View File

@ -19,7 +19,8 @@ void eventOS_timeout_cancel(timeout_t *t)
}
void test_eventOS_timeout_trigger() {
void test_eventOS_timeout_trigger()
{
test_callback(test_args);
}

View File

@ -69,7 +69,10 @@ public:
bool open(void);
int accept(NanostackSocket *accepted_socket, ns_address_t *addr);
void close(void);
bool closed(void) {return SOCKET_MODE_CLOSED == mode;}
bool closed(void)
{
return SOCKET_MODE_CLOSED == mode;
}
bool is_connecting(void);
void set_connecting(ns_address_t *addr);
bool is_connected(void);
@ -106,11 +109,16 @@ static NanostackSocket * socket_tbl[NS_INTERFACE_SOCKETS_MAX];
nsapi_error_t map_mesh_error(mesh_error_t err)
{
switch (err) {
case MESH_ERROR_NONE: return 0;
case MESH_ERROR_MEMORY: return NSAPI_ERROR_NO_MEMORY;
case MESH_ERROR_PARAM: return NSAPI_ERROR_UNSUPPORTED;
case MESH_ERROR_STATE: return NSAPI_ERROR_DEVICE_ERROR;
default: return NSAPI_ERROR_DEVICE_ERROR;
case MESH_ERROR_NONE:
return 0;
case MESH_ERROR_MEMORY:
return NSAPI_ERROR_NO_MEMORY;
case MESH_ERROR_PARAM:
return NSAPI_ERROR_UNSUPPORTED;
case MESH_ERROR_STATE:
return NSAPI_ERROR_DEVICE_ERROR;
default:
return NSAPI_ERROR_DEVICE_ERROR;
}
}
@ -142,10 +150,12 @@ static int8_t find_interface_by_address(const uint8_t target_addr[16])
return -1;
}
void* NanostackSocket::operator new(std::size_t sz) {
void *NanostackSocket::operator new (std::size_t sz)
{
return MALLOC(sz);
}
void NanostackSocket::operator delete(void* ptr) {
void NanostackSocket::operator delete (void *ptr)
{
FREE(ptr);
}
@ -296,7 +306,8 @@ void NanostackSocket::signal_event()
}
}
void NanostackSocket::socket_callback(void *cb) {
void NanostackSocket::socket_callback(void *cb)
{
nanostack_assert_locked();
socket_callback_t *sock_cb = (socket_callback_t *) cb;
@ -979,7 +990,8 @@ void Nanostack::socket_attach(void *handle, void (*callback)(void *), void *id)
tr_debug("socket_attach(socket=%p) sock_id=%d", socket, socket->socket_id);
}
Nanostack &Nanostack::get_instance() {
Nanostack &Nanostack::get_instance()
{
static Nanostack nanostack;
return nanostack;
}
@ -989,7 +1001,8 @@ Nanostack &Nanostack::get_instance() {
#define NANOSTACK 0x99119911
#if MBED_CONF_NSAPI_DEFAULT_STACK == NANOSTACK
#undef NANOSTACK
OnboardNetworkStack &OnboardNetworkStack::get_default_instance() {
OnboardNetworkStack &OnboardNetworkStack::get_default_instance()
{
return Nanostack::get_instance();
}
#endif

View File

@ -27,11 +27,13 @@
class NanostackLockGuard {
public:
NanostackLockGuard() {
NanostackLockGuard()
{
eventOS_scheduler_mutex_wait();
}
~NanostackLockGuard() {
~NanostackLockGuard()
{
eventOS_scheduler_mutex_release();
}

View File

@ -48,12 +48,18 @@ public:
* @return Device driver ID or a negative error
* code on failure
*/
virtual int8_t phy_register() { return rf_register();}
virtual int8_t phy_register()
{
return rf_register();
}
/** Unregister this physical interface
*
*/
virtual void unregister() { rf_unregister(); }
virtual void unregister()
{
rf_unregister();
}
};
#endif /* NANOSTACK_RF_PHY_H_ */

View File

@ -78,14 +78,16 @@ static timeout_t *eventOS_timeout_at_(void (*callback)(void *), void *arg, uint3
.data_ptr = timeout
};
if (period)
if (period) {
storage = eventOS_event_timer_request_every(&event, period);
else
} else {
storage = eventOS_event_timer_request_at(&event, at);
}
timeout->event = storage;
if (storage)
if (storage) {
return timeout;
}
FAIL:
ns_dyn_mem_free(timeout);
return NULL;
@ -103,8 +105,9 @@ timeout_t *eventOS_timeout_every_ms(void (*callback)(void *), uint32_t every, vo
void eventOS_timeout_cancel(timeout_t *t)
{
if (!t)
if (!t) {
return;
}
eventOS_cancel(t->event);

View File

@ -66,10 +66,10 @@
* /enum dhcp_instance_type
* /brief DHCP instance types.
*/
typedef enum dhcp_instance_type
{
typedef enum dhcp_instance_type {
DHCP_INSTANCE_CLIENT,
DHCP_INSTANCE_SERVER
DHCP_INSTANCE_SERVER,
DHCP_INTANCE_RELAY_AGENT
} dhcp_instance_type_e;
/**
@ -124,6 +124,16 @@ typedef int (dhcp_service_receive_resp_cb)(uint16_t instance_id, void *ptr, uint
uint16_t dhcp_service_init(int8_t interface_id, dhcp_instance_type_e instance_type, dhcp_service_receive_req_cb *receive_req_cb);
/**
* \brief Enable DHCPv6 Relay Agent to server.
*
*
* \param instance The instance ID of the registered server.
* \param server_address global server IPv6 address
*/
void dhcp_service_relay_instance_enable(uint16_t instance, uint8_t *server_address);
/**
* \brief Deletes a server instance.
*

View File

@ -46,8 +46,7 @@ typedef struct fhss_callback fhss_callback_t;
/**
* @brief FHSS states.
*/
typedef enum
{
typedef enum {
FHSS_UNSYNCHRONIZED,
FHSS_SYNCHRONIZED,
} fhss_states;
@ -132,8 +131,9 @@ typedef bool fhss_data_tx_fail(const fhss_api_t *api, uint8_t handle, int frame_
* @param api FHSS instance.
* @param fhss_state FHSS state (FHSS states are defined by FHSS api).
* @param pan_id PAN id of the network FHSS synchronizes with.
* @return -1 when failed, otherwise current MAC channel.
*/
typedef void fhss_synch_state_set(const fhss_api_t *api, fhss_states fhss_state, uint16_t pan_id);
typedef int16_t fhss_synch_state_set(const fhss_api_t *api, fhss_states fhss_state, uint16_t pan_id);
/**
* @brief Read timestamp.
@ -215,6 +215,13 @@ typedef int mac_read_mac_address(const fhss_api_t *fhss_api, uint8_t *mac_addres
*/
typedef uint32_t mac_read_datarate(const fhss_api_t *fhss_api);
/**
* @brief Read 32-bit timestamp.
* @param fhss_api FHSS instance.
* @return Timestamp.
*/
typedef uint32_t mac_read_timestamp(const fhss_api_t *fhss_api);
/**
* @brief Change channel.
* @param fhss_api FHSS instance.
@ -287,6 +294,7 @@ struct fhss_callback {
mac_read_tx_queue_size *read_tx_queue_size; /**< Read MAC TX queue size. */
mac_read_mac_address *read_mac_address; /**< Read MAC address. */
mac_read_datarate *read_datarate; /**< Read PHY datarate. */
mac_read_timestamp *read_timestamp; /**< Read timestamp. */
mac_change_channel *change_channel; /**< Change channel. */
mac_send_fhss_frame *send_fhss_frame; /**< Send FHSS frame. */
mac_synch_lost_notification *synch_lost_notification; /**< Send notification when FHSS synchronization is lost. */

View File

@ -33,8 +33,7 @@ extern "C" {
/**
* @brief WS channel functions.
*/
typedef enum
{
typedef enum {
/** Fixed channel. */
WS_FIXED_CHANNEL,
/** TR51 channel function. */
@ -49,8 +48,7 @@ typedef enum
* \brief Struct fhss_tuning_parameter defines FHSS tuning parameters.
* All delays are given in microseconds.
*/
typedef struct fhss_tuning_parameter
{
typedef struct fhss_tuning_parameter {
/** Delay between data pushed to PHY TX function and TX started (Contains CSMA-CA maximum random period). */
uint32_t tx_processing_delay;
@ -64,8 +62,7 @@ typedef struct fhss_tuning_parameter
/**
* \brief Struct fhss_configuration defines basic configuration of FHSS.
*/
typedef struct fhss_configuration
{
typedef struct fhss_configuration {
/** Tuning parameters can be used to enhance synchronization accuracy*/
fhss_tuning_parameter_t fhss_tuning_parameters;
@ -94,10 +91,12 @@ typedef int32_t fhss_vendor_defined_cf(const fhss_api_t *api, uint16_t slot, uin
/**
* \brief Struct fhss_ws_configuration defines configuration of WS FHSS.
*/
typedef struct fhss_ws_configuration
{
/** WS channel function. */
fhss_ws_channel_functions ws_channel_function;
typedef struct fhss_ws_configuration {
/** WS unicast channel function. */
fhss_ws_channel_functions ws_uc_channel_function;
/** WS broadcast channel function. */
fhss_ws_channel_functions ws_bc_channel_function;
/** Broadcast schedule identifier. */
uint16_t bsi;
@ -111,6 +110,12 @@ typedef struct fhss_ws_configuration
/** Broadcast dwell interval. Range: 15-250 milliseconds. */
uint8_t fhss_bc_dwell_interval;
/** Unicast fixed channel */
uint8_t unicast_fixed_channel;
/** Broadcast fixed channel */
uint8_t broadcast_fixed_channel;
/** Channel mask. */
uint32_t channel_mask[8];
@ -123,8 +128,7 @@ typedef struct fhss_ws_configuration
* \brief Struct fhss_timer defines interface between FHSS and FHSS platform timer.
* Application must implement FHSS timer driver which is then used by FHSS with this interface.
*/
typedef struct fhss_timer
{
typedef struct fhss_timer {
/** Start timeout (1us). Timer must support multiple simultaneous timeouts */
int (*fhss_timer_start)(uint32_t, void (*fhss_timer_callback)(const fhss_api_t *fhss_api, uint16_t), const fhss_api_t *fhss_api);
@ -145,8 +149,7 @@ typedef struct fhss_timer
* \brief Struct fhss_synch_configuration defines the synchronization time configurations.
* Border router application must define and set these configuration for FHSS network.
*/
typedef struct fhss_synch_configuration
{
typedef struct fhss_synch_configuration {
/** Number of broadcast channels. */
uint8_t fhss_number_of_bc_channels;
@ -165,8 +168,7 @@ typedef struct fhss_synch_configuration
/**
* \brief Struct fhss_statistics defines the available FHSS statistics.
*/
typedef struct fhss_statistics
{
typedef struct fhss_statistics {
/** FHSS synchronization drift compensation (us/channel). */
int16_t fhss_drift_compensation;

View File

@ -37,6 +37,7 @@ typedef struct unicast_timing_info {
unsigned unicast_channel_function: 3; /**< Unicast schedule channel function */
uint8_t unicast_dwell_interval; /**< Unicast dwell interval */
uint16_t unicast_number_of_channels; /**< Unicast number of channels */
uint16_t fixed_channel; /**< Unicast fixed channel*/
uint_fast24_t ufsi; /**< Unicast fractional sequence interval */
uint32_t utt_rx_timestamp; /**< UTT-IE reception timestamp */
} unicast_timing_info_t;
@ -47,6 +48,7 @@ typedef struct unicast_timing_info {
typedef struct broadcast_timing_info {
unsigned broadcast_channel_function: 3; /**< Broadcast schedule channel function */
uint8_t broadcast_dwell_interval; /**< Broadcast dwell interval */
uint16_t fixed_channel; /**< Broadcast fixed channel*/
uint16_t broadcast_slot; /**< Broadcast slot number */
uint16_t broadcast_schedule_id; /**< Broadcast schedule identifier */
uint_fast24_t broadcast_interval_offset; /**< Broadcast interval offset */
@ -78,9 +80,10 @@ typedef fhss_ws_neighbor_timing_info_t *fhss_get_neighbor_info(const fhss_api_t
* @param fhss_api FHSS instance.
* @param eui64 EUI-64 address of parent.
* @param bc_timing_info Pointer to parent broadcast timing/hopping schedule info.
* @param force_synch If false, synchronization is done only if minimum (internal) synchronization interval is exceed.
* @return 0 on success, -1 on fail.
*/
extern int ns_fhss_ws_set_parent(const fhss_api_t *fhss_api, const uint8_t eui64[8], const broadcast_timing_info_t *bc_timing_info);
extern int ns_fhss_ws_set_parent(const fhss_api_t *fhss_api, const uint8_t eui64[8], const broadcast_timing_info_t *bc_timing_info, const bool force_synch);
/**
* @brief Remove parent which was set by ns_fhss_ws_set_parent function.

View File

@ -137,8 +137,9 @@ typedef void mcps_data_request_ext(const mac_api_t* api, const mcps_data_req_t *
* @brief mcps_purge_request MCPS_PURGE request call
* @param api API to handle the request
* @param data MCPS-PURGE.request specific values
* @return 0 in case of success, non-zero otherwise
*/
typedef void mcps_purge_request(const mac_api_t* api, const mcps_purge_t *data);
typedef uint8_t mcps_purge_request(const mac_api_t *api, const mcps_purge_t *data);
//Upper layer specific callback functions (will also be set by Upper layer after mac_api_t has been created and given to it)

View File

@ -39,10 +39,9 @@ extern "C" {
extern fhss_api_t *ns_fhss_create(const fhss_configuration_t *fhss_configuration, const fhss_timer_t *fhss_timer, fhss_statistics_t *fhss_statistics);
/**
* @brief TODO: description.
* @brief Creates FHSS WS API instance which will be registered to software MAC.
* @param fhss_configuration Basic FHSS configuration.
* @param fhss_timer FHSS platform timer interface and configuration.
* @param fhss_statistics FHSS statistics storage.
* @return New FHSS instance if successful, NULL otherwise.
*/
extern fhss_api_t *ns_fhss_ws_create(const fhss_ws_configuration_t *fhss_configuration, const fhss_timer_t *fhss_timer);

View File

@ -257,8 +257,7 @@ typedef struct {
} border_router_setup_s;
/** Channel list */
typedef struct channel_list_s
{
typedef struct channel_list_s {
channel_page_e channel_page; /**< Channel page */
uint32_t channel_mask[8]; /**< Channel mask. Each bit defining one channel */
} channel_list_s;

View File

@ -39,8 +39,7 @@ typedef struct ns_mdns_service *ns_mdns_service_t; /**< Service instance */
* \struct ns_mdns_service_param_t
* \brief Structure for mDNS service parameters
*/
typedef struct ns_mdns_service_param
{
typedef struct ns_mdns_service_param {
const char *service_type; /**< Null-terminated string owned by the caller */
uint16_t service_port; /**< Service Port number */
const uint8_t *(*service_get_txt)(void); /**< Call-back function, which returns a pointer to the service TXT record (null-terminated).

View File

@ -112,8 +112,7 @@ static inline void ns_sha256_nbits(const void *input, size_t ilen, void *output,
/**
* \brief SHA-256 context structure
*/
typedef struct
{
typedef struct {
uint32_t total[2]; /*!< number of bytes processed */
uint32_t state[8]; /*!< intermediate digest state */
unsigned char buffer[64]; /*!< data block being processed */

View File

@ -125,8 +125,7 @@ typedef struct phy_csma_params {
} phy_csma_params_t;
/** PHY modulation scheme */
typedef enum phy_modulation_e
{
typedef enum phy_modulation_e {
M_OFDM, ///< QFDM
M_OQPSK, ///< OQPSK
M_BPSK, ///< BPSK
@ -135,8 +134,7 @@ typedef enum phy_modulation_e
} phy_modulation_e;
/** Channel page numbers */
typedef enum
{
typedef enum {
CHANNEL_PAGE_0 = 0, ///< Page 0
CHANNEL_PAGE_1 = 1, ///< Page 1
CHANNEL_PAGE_2 = 2, ///< Page 2
@ -149,8 +147,7 @@ typedef enum
} channel_page_e;
/** Channel configuration */
typedef struct phy_rf_channel_configuration_s
{
typedef struct phy_rf_channel_configuration_s {
uint32_t channel_0_center_frequency; ///< Center frequency
uint32_t channel_spacing; ///< Channel spacing
uint32_t datarate; ///< Data rate
@ -159,8 +156,7 @@ typedef struct phy_rf_channel_configuration_s
} phy_rf_channel_configuration_s;
/** Channel page configuration */
typedef struct phy_device_channel_page_s
{
typedef struct phy_device_channel_page_s {
channel_page_e channel_page; ///< Channel page
const phy_rf_channel_configuration_s *rf_channel_configuration; ///< Pointer to channel configuration
} phy_device_channel_page_s;
@ -240,8 +236,7 @@ typedef int8_t arm_net_virtual_config_tx_fn(int8_t driver_id, const uint8_t *dat
typedef int8_t arm_net_virtual_confirmation_rx_fn(int8_t driver_id, const uint8_t *data, uint16_t length);
/** Device driver structure */
typedef struct phy_device_driver_s
{
typedef struct phy_device_driver_s {
phy_link_type_e link_type; /**< Define driver types. */
driver_data_request_e data_request_layer; /**< Define interface data OUT protocol. */
uint8_t *PHY_MAC; /**< Pointer to 64-bit or 48-bit MAC address. */

View File

@ -75,6 +75,7 @@ int thread_bbr_start(int8_t interface_id, int8_t backbone_interface_id);
*
*/
int thread_bbr_timeout_set(int8_t interface_id, uint32_t timeout_a, uint32_t timeout_b, uint32_t delay);
/**
* Set prefix to be used as combining multiple thread networks on backbone.
*
@ -89,6 +90,20 @@ int thread_bbr_timeout_set(int8_t interface_id, uint32_t timeout_a, uint32_t tim
*/
int thread_bbr_prefix_set(int8_t interface_id, uint8_t *prefix);
/**
* Set sequence number to be used by bbr
*
* update sequence number value
*
* \param interface_id interface ID of the Thread network.
* \param sequence_number value that needs to be set on bbr
*
* \return 0 on success
* \return <0 in case of errors
*
*/
int thread_bbr_sequence_number_set(int8_t interface_id, uint8_t sequence_number);
/**
* Set the Thread validation interface destination address.
*

View File

@ -189,8 +189,10 @@ void *thread_commission_device_get_next(void *ptr, int8_t interface_id, bool *sh
typedef struct thread_commissioning_link_configuration {
uint8_t name[16]; /**< Name of the Thread network. utf8 string nul terminated if shorter than 16. */
uint8_t destination_address[16]; /**<Border router destination address*/
uint8_t extented_pan_id[8]; /**< Extended PAN ID. */
uint16_t panId; /**< Network ID. */
uint16_t destination_port; /**<destination port for commissioning*/
uint8_t Protocol_id; /**< Current protocol ID. */
uint8_t version; /**< Current protocol version. */
uint8_t rfChannel; /**< Current RF channel. */
@ -271,6 +273,18 @@ int thread_commissioning_native_commissioner_get_connection_info(int8_t interfac
*/
int8_t thread_commissioning_get_management_id(int8_t interface_id);
/**
* \brief Attach native commissioner to destination address and port.
*
* \param interface_id Network interface ID.
* \param destination_address Destination address pointer.
* \param destination_port Commissioning port.
*
* \return 0 attach OK.
* \return < 0 fail.
*/
int thread_commissioning_attach(int8_t interface_id, uint8_t *destination_address, uint16_t destination_port);
#ifdef __cplusplus
}
#endif

View File

@ -55,7 +55,8 @@
#define DIAGCOP_TLV_SUPPLY_VOLTAGE 15 /**< Can not reset*/
#define DIAGCOP_TLV_CHILD_TABLE 16 /**< Can not reset*/
#define DIAGCOP_TLV_CHANNEL_PAGES 17 /**< Can not reset*/
#define DIAGCOP_TLV_TYPE_LIST 18 /**< List type*/
#define DIAGCOP_TLV_TYPE_LIST 18 /**< Cannot reset*/
#define DIAGCOP_TLV_MAX_CHILD_TIMEOUT 19 /**< Cannot reset*/
/**
* \brief Write array TLV.

View File

@ -131,8 +131,7 @@ buffer_t *nwk_udp_rx_security_check(buffer_t *buf)
}
if (buf->socket && buf->socket->inet_pcb->link_layer_security == 0) {
// non-secure okay if it's for a socket whose security flag is clear.
}
else {
} else {
drop_unsecured = 1;
}
}

View File

@ -74,6 +74,7 @@
#include "6LoWPAN/Fragmentation/cipv6_fragmenter.h"
#include "Service_Libs/etx/etx.h"
#include "Service_Libs/mac_neighbor_table/mac_neighbor_table.h"
#include "6LoWPAN/ws/ws_bootstrap.h"
#define TRACE_GROUP_LOWPAN "6lo"
@ -365,7 +366,8 @@ void protocol_6lowpan_router_init(protocol_interface_info_entry_t *cur)
}
void protocol_6lowpan_configure_core(protocol_interface_info_entry_t *cur) {
void protocol_6lowpan_configure_core(protocol_interface_info_entry_t *cur)
{
cur->dup_addr_detect_transmits = 0;
cur->ipv6_neighbour_cache.max_ll_len = 2 + 8;
cur->ipv6_neighbour_cache.link_mtu = LOWPAN_MTU;
@ -473,7 +475,6 @@ void protocol_6lowpan_neighbor_priority_update(protocol_interface_info_entry_t *
}
#ifdef HAVE_RPL
#ifndef NO_MLE
uint16_t protocol_6lowpan_neighbor_priority_set(int8_t interface_id, addrtype_t addr_type, const uint8_t *addr_ptr)
{
@ -486,9 +487,12 @@ uint16_t protocol_6lowpan_neighbor_priority_set(int8_t interface_id, addrtype_t
mac_neighbor_table_entry_t *entry = mac_neighbor_table_address_discover(mac_neighbor_info(cur), addr_ptr + PAN_ID_LEN, addr_type);
if (entry) {
bool new_primary = false;
etx_storage_t *etx_entry = etx_storage_entry_get(interface_id, entry->index);
// If primary parent has changed clears priority from previous parent
if (entry->link_role != PRIORITY_PARENT_NEIGHBOUR) {
new_primary = true;
protocol_6lowpan_neighbor_priority_clear_all(interface_id, PRIORITY_1ST);
}
entry->link_role = PRIORITY_PARENT_NEIGHBOUR;
@ -501,6 +505,10 @@ uint16_t protocol_6lowpan_neighbor_priority_set(int8_t interface_id, addrtype_t
if (etx_entry) {
protocol_stats_update(STATS_ETX_1ST_PARENT, etx_entry->etx >> 4);
}
if (new_primary) {
ws_primary_parent_update(cur, entry);
}
return 1;
} else {
return 0;
@ -519,9 +527,11 @@ uint16_t protocol_6lowpan_neighbor_second_priority_set(int8_t interface_id, addr
mac_neighbor_table_entry_t *entry = mac_neighbor_table_address_discover(mac_neighbor_info(cur), addr_ptr + PAN_ID_LEN, addr_type);
if (entry) {
bool new_secondary = false;
etx_storage_t *etx_entry = etx_storage_entry_get(interface_id, entry->index);
// If secondary parent has changed clears priority from previous parent
if (entry->link_role != SECONDARY_PARENT_NEIGHBOUR) {
new_secondary = true;
protocol_6lowpan_neighbor_priority_clear_all(interface_id, PRIORITY_2ND);
}
entry->link_role = SECONDARY_PARENT_NEIGHBOUR;
@ -529,6 +539,9 @@ uint16_t protocol_6lowpan_neighbor_second_priority_set(int8_t interface_id, addr
if (etx_entry) {
protocol_stats_update(STATS_ETX_2ND_PARENT, etx_entry->etx >> 4);
}
if (new_secondary) {
ws_secondary_parent_update(cur);
}
return 1;
} else {
return 0;
@ -557,7 +570,6 @@ void protocol_6lowpan_neighbor_priority_clear_all(int8_t interface_id, neighbor_
}
}
#endif
#endif
#endif

View File

@ -322,7 +322,8 @@ static bool protocol_6lowpan_router_challenge(protocol_interface_info_entry_t *c
}
static uint8_t mle_advert_neigh_cnt(protocol_interface_info_entry_t *cur_interface, bool short_adr) {
static uint8_t mle_advert_neigh_cnt(protocol_interface_info_entry_t *cur_interface, bool short_adr)
{
uint8_t advert_neigh_cnt;
uint8_t neighb_max;
@ -428,8 +429,7 @@ static uint8_t *mle_table_set_neighbours(protocol_interface_info_entry_t *cur, u
neigh_count_max = mle_advert_neigh_cnt(cur, use_short_address_compression);
bool clean_entries = false;
ns_list_foreach(mac_neighbor_table_entry_t, cur_entry, neigh_list)
{
ns_list_foreach(mac_neighbor_table_entry_t, cur_entry, neigh_list) {
if ((cur_entry->connected_device) && (cur_entry->advertisment == false)) {
@ -1179,8 +1179,7 @@ void mle_6lowpan_message_handler(int8_t interface_id, mle_message_t *mle_msg, ml
uint8_t link_flags;
if (mle_tlv_info.tlvLen > 0) {
link_flags = *(mle_tlv_info.dataPtr);
if (mle_link_quality_tlv_parse(cur->mac,mac_helper_mac16_address_get(cur) , mle_tlv_info.dataPtr, mle_tlv_info.tlvLen, NULL, NULL))
{
if (mle_link_quality_tlv_parse(cur->mac, mac_helper_mac16_address_get(cur), mle_tlv_info.dataPtr, mle_tlv_info.tlvLen, NULL, NULL)) {
drop_advertisment = 0;
}
@ -1786,7 +1785,7 @@ int8_t arm_6lowpan_bootstarp_bootstrap_set(int8_t interface_id, net_6lowpan_mode
*/
if (cur->lowpan_info & INTERFACE_NWK_ROUTER_DEVICE) {
//rpl_control_set_domain_on_interface(cur, protocol_6lowpan_rpl_domain, true);
//rpl_control_set_callback(protocol_6lowpan_rpl_domain, protocol_6lowpan_bootstrap_rpl_callback, cur);
//rpl_control_set_callback(protocol_6lowpan_rpl_domain, protocol_6lowpan_bootstrap_rpl_callback, NULL, cur);
}
#endif
cur->configure_flags |= INTERFACE_BOOTSTRAP_DEFINED;
@ -2073,6 +2072,8 @@ static void protocol_6lowpan_bootstrap_rpl_callback(rpl_event_t event, void *han
tr_error("RPL Local repair fail-->interface to idle");
nwk_bootsrap_state_update(ARM_NWK_NWK_CONNECTION_DOWN, cur);
break;
default:
break;
}
}
@ -2179,7 +2180,7 @@ void nwk_6lowpan_nd_address_registartion_ready(protocol_interface_info_entry_t *
// arm_nwk_6lowpan_rpl_dodag_poison from a previous connection may have left force_leaf set
rpl_control_force_leaf(protocol_6lowpan_rpl_domain, false);
rpl_control_set_domain_on_interface(cur, protocol_6lowpan_rpl_domain, true);
rpl_control_set_callback(protocol_6lowpan_rpl_domain, protocol_6lowpan_bootstrap_rpl_callback, cur);
rpl_control_set_callback(protocol_6lowpan_rpl_domain, protocol_6lowpan_bootstrap_rpl_callback, NULL, cur);
}
// Send unicast DIS to coordinator
nwk_bootstrap_icmp_rpl_dis_coord_msg_tx(cur);

View File

@ -273,7 +273,8 @@ static bool beacon_join_priority_tlv_add(uint8_t len, uint8_t *ptr, uint8_t offs
return true;
}
static nwk_pan_descriptor_t * get_local_description(uint16_t payload_length, uint8_t *payload_ptr) {
static nwk_pan_descriptor_t *get_local_description(uint16_t payload_length, uint8_t *payload_ptr)
{
nwk_pan_descriptor_t *description = ns_dyn_mem_temporary_alloc(sizeof(nwk_pan_descriptor_t));
if (description) {
memset(description, 0, sizeof(nwk_pan_descriptor_t));

View File

@ -280,7 +280,8 @@ static void mac_helper_key_lookup_set(mlme_key_id_lookup_descriptor_t *lookup, u
}
static void mac_helper_keytable_descriptor_set(struct mac_api_s *api, const uint8_t *key, uint8_t id, uint8_t attribute_id) {
static void mac_helper_keytable_descriptor_set(struct mac_api_s *api, const uint8_t *key, uint8_t id, uint8_t attribute_id)
{
mlme_set_t set_req;
mlme_key_id_lookup_descriptor_t lookup_description;
mlme_key_descriptor_entry_t key_description;
@ -301,7 +302,8 @@ static void mac_helper_keytable_descriptor_set(struct mac_api_s *api, const uint
api->mlme_req(api, MLME_SET, &set_req);
}
static void mac_helper_keytable_pairwise_descriptor_set(struct mac_api_s *api, const uint8_t *key, const uint8_t *mac64, uint8_t attribute_id) {
static void mac_helper_keytable_pairwise_descriptor_set(struct mac_api_s *api, const uint8_t *key, const uint8_t *mac64, uint8_t attribute_id)
{
mlme_set_t set_req;
mlme_key_id_lookup_descriptor_t lookup_description;
mlme_key_descriptor_entry_t key_description;
@ -402,7 +404,8 @@ void mac_helper_security_key_swap_next_to_default(protocol_interface_info_entry_
}
void mac_helper_security_key_clean(protocol_interface_info_entry_t *interface) {
void mac_helper_security_key_clean(protocol_interface_info_entry_t *interface)
{
if (interface->mac_api) {
mlme_set_t set_req;
mlme_key_descriptor_entry_t key_description;
@ -736,7 +739,8 @@ uint_fast8_t mac_helper_frame_overhead(protocol_interface_info_entry_t *cur, con
return length;
}
static uint8_t mac_helper_security_mic_length_get(uint8_t security_level) {
static uint8_t mac_helper_security_mic_length_get(uint8_t security_level)
{
uint8_t mic_length;
switch (security_level) {
case SEC_MIC32:
@ -761,7 +765,8 @@ static uint8_t mac_helper_security_mic_length_get(uint8_t security_level) {
return mic_length;
}
static uint8_t mac_helper_header_security_aux_header_length(uint8_t keyIdmode) {
static uint8_t mac_helper_header_security_aux_header_length(uint8_t keyIdmode)
{
uint8_t header_length = 5; //Header + 32-bit counter
switch (keyIdmode) {

View File

@ -76,7 +76,8 @@ static mac_pairwise_interface_entry_t *mac_pairwise_key_list_allocate(uint8_t li
return newEntry;
}
static bool mac_pairwise_key_deacriptro_attribute_get(mac_pairwise_interface_entry_t *main_list, uint8_t key_attribute) {
static bool mac_pairwise_key_deacriptro_attribute_get(mac_pairwise_interface_entry_t *main_list, uint8_t key_attribute)
{
mac_pairwise_key_info_t *key_table = main_list->mac_pairwise_key_table;
for (uint8_t i = 0; i < main_list->key_table_size; i++) {
if (key_table->key_decriptor_attribute == key_attribute) {
@ -88,7 +89,8 @@ static bool mac_pairwise_key_deacriptro_attribute_get(mac_pairwise_interface_ent
return true;
}
mac_pairwise_key_info_t *mac_pairwise_key_info_get(mac_pairwise_interface_entry_t *main_list, uint8_t device_id) {
mac_pairwise_key_info_t *mac_pairwise_key_info_get(mac_pairwise_interface_entry_t *main_list, uint8_t device_id)
{
mac_pairwise_key_info_t *key_table = main_list->mac_pairwise_key_table;
for (uint8_t i = 0; i < main_list->key_table_size; i++) {
if (key_table->device_descriptor_attribute == device_id) {
@ -118,7 +120,8 @@ mac_pairwise_key_info_t *mac_pairwise_key_info_get(mac_pairwise_interface_entry_
return new_entry;
}
static bool mac_pairwise_key_info_delete(mac_pairwise_interface_entry_t *main_list, uint8_t device_id, uint8_t *key_attribute) {
static bool mac_pairwise_key_info_delete(mac_pairwise_interface_entry_t *main_list, uint8_t device_id, uint8_t *key_attribute)
{
bool removed_entry = false;
mac_pairwise_key_info_t *cur = main_list->mac_pairwise_key_table;
@ -170,7 +173,8 @@ static mac_pairwise_interface_entry_t *mac_pairwise_key_main_class(uint8_t key_l
}
static void mac_pairwise_key_list_free(protocol_interface_info_entry_t *interface, mac_pairwise_interface_entry_t *main_list) {
static void mac_pairwise_key_list_free(protocol_interface_info_entry_t *interface, mac_pairwise_interface_entry_t *main_list)
{
//Delete mle entries & Keys
mac_neighbor_table_entry_t *cur_entry;
mac_pairwise_key_info_t *cur = main_list->mac_pairwise_key_table;

View File

@ -38,7 +38,8 @@
#define TRACE_GROUP "MRsH"
static void mac_mlme_device_table_confirmation_handle(protocol_interface_info_entry_t *info_entry, mlme_get_conf_t *confirmation) {
static void mac_mlme_device_table_confirmation_handle(protocol_interface_info_entry_t *info_entry, mlme_get_conf_t *confirmation)
{
if (confirmation->value_size != sizeof(mlme_device_descriptor_t)) {
return;
}
@ -71,7 +72,8 @@ static void mac_mlme_device_table_confirmation_handle(protocol_interface_info_en
}
}
static void mac_mlme_frame_counter_confirmation_handle(protocol_interface_info_entry_t *info_entry, mlme_get_conf_t *confirmation) {
static void mac_mlme_frame_counter_confirmation_handle(protocol_interface_info_entry_t *info_entry, mlme_get_conf_t *confirmation)
{
if (confirmation->value_size != 4) {
return;
}
@ -79,7 +81,8 @@ static void mac_mlme_frame_counter_confirmation_handle(protocol_interface_info_e
info_entry->mac_parameters->security_frame_counter = *temp_ptr;
}
static void mac_mlme_get_confirmation_handler(protocol_interface_info_entry_t *info_entry, mlme_get_conf_t *confirmation) {
static void mac_mlme_get_confirmation_handler(protocol_interface_info_entry_t *info_entry, mlme_get_conf_t *confirmation)
{
if (!confirmation) {
return;

View File

@ -39,9 +39,10 @@ typedef void mpx_data_request(const mpx_api_t *api, const struct mcps_data_req_s
* @param api API to handle the request
* @param purge MCPS-purge request
* @param user_id MPX user ID
* @return 0 if purge requst was OK, non-zero otherwise
*
*/
typedef void mpx_data_purge_request(const mpx_api_t *api, struct mcps_purge_s *purge, uint16_t user_id);
typedef uint8_t mpx_data_purge_request(const mpx_api_t *api, struct mcps_purge_s *purge, uint16_t user_id);
/**
* @brief mpx_data_confirm MPX-DATA confirm is called as a response to MPX-DATA request

View File

@ -720,8 +720,7 @@ void nd_ns_build(nd_router_t *cur, protocol_interface_info_entry_t *cur_interfac
return;
}
memcpy(router, route->info.next_hop_addr, 16);
}
else
} else
#endif
{
icmp_nd_set_nd_def_router_address(router, cur);
@ -873,8 +872,7 @@ static void nd_update_registration(protocol_interface_info_entry_t *cur_interfac
void nd_remove_registration(protocol_interface_info_entry_t *cur_interface, addrtype_t ll_type, const uint8_t *ll_address)
{
ns_list_foreach_safe(ipv6_neighbour_t, cur, &cur_interface->ipv6_neighbour_cache.list)
{
ns_list_foreach_safe(ipv6_neighbour_t, cur, &cur_interface->ipv6_neighbour_cache.list) {
if ((cur->type == IP_NEIGHBOUR_REGISTERED
|| cur->type == IP_NEIGHBOUR_TENTATIVE)
&& ipv6_neighbour_ll_addr_match(cur, ll_type, ll_address)) {
@ -1094,10 +1092,8 @@ bool nd_ra_process_abro(protocol_interface_info_entry_t *cur, buffer_t *buf, con
dptr += 4;
//If Border Router boot is state
if(cur->border_router_setup)
{
if(memcmp(dptr, cur->border_router_setup->border_router_gp_adr, 16) == 0)
{
if (cur->border_router_setup) {
if (memcmp(dptr, cur->border_router_setup->border_router_gp_adr, 16) == 0) {
if (cur->border_router_setup->initActive) {
//save New Context
if (common_serial_number_greater_32(abro_ver_num, cur->border_router_setup->nd_border_router_configure->abro_version_num)) {
@ -1163,8 +1159,7 @@ bool nd_ra_process_abro(protocol_interface_info_entry_t *cur, buffer_t *buf, con
uptodate = true;
//uprouter_info=1;
if(diff_update >= 0x00010000)
{
if (diff_update >= 0x00010000) {
tr_debug("Border Router Boot Trig NS");
router->trig_address_reg = true;
} else {
@ -1258,8 +1253,7 @@ bool nd_ra_process_abro(protocol_interface_info_entry_t *cur, buffer_t *buf, con
}
}
if(uptodate)
{
if (uptodate) {
router->abro_version_num = abro_ver_num;
router->life_time = router_lifetime;
}
@ -1536,8 +1530,7 @@ static uint8_t nd_router_ready_timer(nd_router_t *cur, protocol_interface_info_e
mac_data_poll_init_protocol_poll(cur_interface);
}
nd_router_bootstrap_timer(cur, cur_interface, 1);
}
else { /* ND_BR_READY */
} else { /* ND_BR_READY */
nd_border_router_setup_refresh(cur->nwk_id, true);
tr_debug("ND BR refresh ABRO");
cur->nd_re_validate = (cur->life_time / 4) * 3;

View File

@ -40,12 +40,16 @@
#include "common_functions.h"
#include "thread_border_router_api.h"
#include "thread_bbr_api.h"
#include "net_ipv6_api.h"
#include "NWK_INTERFACE/Include/protocol.h"
#include "Common_Protocols/ipv6_constants.h"
#include "DHCPv6_Server/DHCPv6_server_service.h"
#include "6LoWPAN/Thread/thread_dhcpv6_server.h"
#include "thread_management_if.h"
#include "6LoWPAN/Thread/thread_config.h"
#include "6LoWPAN/Thread/thread_constants.h"
#include "6LoWPAN/Thread/thread_common.h"
#include "6LoWPAN/Thread/thread_bootstrap.h"
#include "6LoWPAN/Thread/thread_joiner_application.h"
#include "6LoWPAN/Thread/thread_extension.h"
#include "6LoWPAN/Thread/thread_extension_bbr.h"
@ -96,7 +100,6 @@ typedef struct {
#define RFC6106_DNS_SEARCH_LIST_OPTION 31
static NS_LIST_DEFINE(bbr_instance_list, thread_bbr_t, link);
static thread_bbr_t *thread_bbr_find_by_interface(int8_t interface_id)
{
thread_bbr_t *this = NULL;
@ -221,8 +224,9 @@ static int thread_border_router_relay_receive_cb(int8_t service_id, uint8_t sour
(void) source_port;
tr_debug("border router relay receive");
thci_trace("brCommissionerDataRelayedOutbound");
if (!this)
if (!this) {
return -1;
}
coap_service_request_send(this->br_service_id, COAP_REQUEST_OPTIONS_NONE, this->commissioner_address, this->commissioner_port,
COAP_MSG_TYPE_NON_CONFIRMABLE, COAP_MSG_CODE_REQUEST_POST, THREAD_URI_RELAY_RECEIVE, COAP_CT_OCTET_STREAM, request_ptr->payload_ptr, request_ptr->payload_len, NULL);
@ -579,7 +583,7 @@ static void thread_bbr_network_data_send(thread_bbr_t *this, uint8_t prefix[8],
// delete old prefix
memset(this->bbr_prefix, 0, 8);
// create new prefix
if (DHCPv6_server_service_init(this->interface_id, prefix, eui64, DHCPV6_DUID_HARDWARE_EUI64_TYPE) != 0) {
if (thread_dhcp6_server_init(this->interface_id, prefix, eui64, THREAD_MIN_PREFIX_LIFETIME) != 0) {
tr_warn("DHCP server alloc fail");
// set 20 seconds delay before next process
this->br_delay_timer = 20;
@ -587,8 +591,6 @@ static void thread_bbr_network_data_send(thread_bbr_t *this, uint8_t prefix[8],
}
memcpy(this->bbr_prefix, prefix, 8);
DHCPv6_server_service_set_address_validlifetime(this->interface_id, this->bbr_prefix, THREAD_MIN_PREFIX_LIFETIME);
br_info.P_default_route = true;
br_info.P_dhcp = true;
br_info.P_on_mesh = true;
@ -724,7 +726,7 @@ static bool thread_bbr_activated(thread_bbr_t *this, uint32_t seconds)
return true;
}
if (cur->thread_info->routerIdReqCoapID) {
if (cur->thread_info->routerIdRequested) {
// Router id reguest pending we need to wait for response
return false;
}
@ -978,18 +980,18 @@ int thread_bbr_nd_entry_add (int8_t interface_id, const uint8_t *addr_data_ptr,
int thread_bbr_dua_entry_add(int8_t interface_id, const uint8_t *addr_data_ptr, uint32_t lifetime, const uint8_t *mleid_ptr)
{
thread_bbr_t *this = thread_bbr_find_by_interface(interface_id);
thread_pbbr_dua_info_t *map;
if (!this || this->backbone_interface_id < 0) {
return -1;
}
thread_pbbr_dua_info_t *map = ns_dyn_mem_alloc(sizeof(thread_pbbr_dua_info_t));
ipv6_route_t *route = ipv6_route_lookup_with_info(addr_data_ptr, 128, interface_id, NULL, ROUTE_THREAD_PROXIED_DUA_HOST, NULL, 0);
if (!route) {
map = ns_dyn_mem_alloc(sizeof(thread_pbbr_dua_info_t));
if (!map) {
goto error;
}
memcpy(map->mleid_ptr, mleid_ptr, 8);
map->last_contact_time = protocol_core_monotonic_time;
// We are using route info field to store BBR MLEID map
ipv6_route_t *route = ipv6_route_add_with_info(addr_data_ptr, 128, interface_id, NULL, ROUTE_THREAD_PROXIED_DUA_HOST, map, 0, lifetime, 0);
route = ipv6_route_add_with_info(addr_data_ptr, 128, interface_id, NULL, ROUTE_THREAD_PROXIED_DUA_HOST, map, 0, lifetime, 0);
if (!route) {
// Direct route to host allows ND proxying to work
ns_dyn_mem_free(map);
@ -997,6 +999,12 @@ int thread_bbr_dua_entry_add (int8_t interface_id, const uint8_t *addr_data_ptr,
}
// Route info autofreed
route->info_autofree = true;
}
map = route->info.info;
memcpy(map->mleid_ptr, mleid_ptr, 8);
map->last_contact_time = protocol_core_monotonic_time;
route->info.info = map;
// send NA
thread_bbr_na_send(this->backbone_interface_id, addr_data_ptr);
@ -1006,15 +1014,6 @@ error:
return -2;
}
struct ipv6_route *thread_bbr_dua_entry_find(int8_t interface_id, const uint8_t *addr_data_ptr) {
ipv6_route_t *route = ipv6_route_choose_next_hop(addr_data_ptr, interface_id, NULL);
if (!route || route->prefix_len < 128 || !route->on_link || route->info.source != ROUTE_THREAD_PROXIED_DUA_HOST ) {
//Not found
return NULL;
}
return route;
}
int thread_bbr_proxy_state_update(int8_t caller_interface_id, int8_t handler_interface_id, bool status)
{
protocol_interface_info_entry_t *cur = protocol_stack_interface_info_get_by_id(handler_interface_id);
@ -1099,7 +1098,11 @@ int thread_bbr_start(int8_t interface_id, int8_t backbone_interface_id)
// By default multicast forwarding is not enabled as it causes multicast loops
multicast_fwd_set_forwarding(this->interface_id, false);
// Adjust BBR neighbor and destination cache size
arm_nwk_ipv6_max_cache_entries(THREAD_BBR_IPV6_DESTINATION_CACHE_SIZE);
thread_extension_bbr_init(interface_id, backbone_interface_id);
return 0;
#else
return -1;
@ -1131,6 +1134,17 @@ int thread_bbr_prefix_set(int8_t interface_id, uint8_t *prefix)
#endif // HAVE_THREAD_BORDER_ROUTER
}
int thread_bbr_sequence_number_set(int8_t interface_id, uint8_t sequence_number)
{
(void) interface_id;
(void) sequence_number;
#ifdef HAVE_THREAD_BORDER_ROUTER
return thread_extension_bbr_sequence_number_set(interface_id, sequence_number);
#else
return -1;
#endif // HAVE_THREAD_BORDER_ROUTER
}
int thread_bbr_validation_interface_address_set(int8_t interface_id, const uint8_t *addr_ptr, uint16_t port)
{
(void) interface_id;

View File

@ -67,7 +67,6 @@ void thread_bbr_seconds_timer(int8_t interface_id, uint32_t tics);
*/
int thread_bbr_commissioner_proxy_service_update(int8_t interface_id);
#else
#define thread_bbr_init(interface_id, external_commisssioner_port)
#define thread_bbr_delete(interface_id)
@ -118,12 +117,6 @@ int thread_bbr_dua_entry_add (int8_t interface_id, const uint8_t *addr_data_ptr,
*/
int thread_bbr_na_send(int8_t interface_id, const uint8_t target[static 16]);
/**
* \brief Find if bbr has dua entry
*
* \param interface_id addr_data_ptr
*/
struct ipv6_route *thread_bbr_dua_entry_find(int8_t interface_id, const uint8_t *addr_data_ptr);
#else
#define thread_bbr_proxy_state_update(caller_interface_id , handler_interface_id, status) (NULL)
@ -131,7 +124,6 @@ struct ipv6_route *thread_bbr_dua_entry_find(int8_t interface_id, const uint8_t
#define thread_bbr_network_data_update_notify(cur)
#define thread_bbr_nd_entry_add(interface_id, addr_data_ptr, lifetime, info) (0)
#define thread_bbr_dua_entry_add(interface_id, addr_data_ptr, lifetime, mleid_ptr) (0)
#define thread_bbr_dua_entry_find(interface_id, addr_data_ptr) (NULL)
#define thread_bbr_na_send(interface_id, target) (0)
#endif //HAVE_THREAD_BORDER_ROUTER

View File

@ -86,7 +86,7 @@
#include "MPL/mpl.h"
#include "MLE/mle.h"
#include "MLE/mle_tlv.h"
#include "thread_dhcpv6_client.h"
#include "DHCPv6_client/dhcpv6_client_api.h"
#include "thread_config.h"
#include "thread_meshcop_lib.h"
#include "multicast_api.h"
@ -136,8 +136,6 @@ static void thread_neighbor_remove(mac_neighbor_table_entry_t *entry_ptr, void *
static bool thread_neighbor_entry_nud_notify(mac_neighbor_table_entry_t *entry_ptr, void *user_data)
{
// Sleepy host
protocol_interface_info_entry_t *cur_interface = user_data;
if (thread_am_router(cur_interface)) {
@ -298,8 +296,7 @@ bool thread_bootstrap_request_network_data(protocol_interface_info_entry_t *cur,
tr_debug("Learn new Network Data");
requestNetworkdata = true;
thread_partition_info_update(cur, leaderData);
}
else if (common_serial_number_greater_8(leaderData->dataVersion, leaderInfo->dataVersion)) {
} else if (common_serial_number_greater_8(leaderData->dataVersion, leaderInfo->dataVersion)) {
requestNetworkdata = true;
} else if (common_serial_number_greater_8(leaderData->stableDataVersion, leaderInfo->stableDataVersion)) {
@ -324,8 +321,7 @@ static int thread_router_check_previous_partition_info(protocol_interface_info_e
(routeTlv->dataPtr[0] == cur->thread_info->previous_partition_info.idSequence)) {
//drop the advertisement from previuos partition
return 1;
}
else {
} else {
//do not drop the advertisement
return 0;
}
@ -676,8 +672,6 @@ static void thread_bootstrap_ml_address_update(protocol_interface_info_entry_t *
// Generate new ML64 address
thread_generate_ml64_address(cur);
// Generate new domain address
thread_extension_address_generate(cur);
// Register multicast addresses
thread_bootstrap_all_nodes_multicast_register(cur);
@ -698,8 +692,6 @@ int thread_configuration_thread_activate(protocol_interface_info_entry_t *cur, l
//Define Default Contexts
lowpan_context_update(&cur->lowpan_contexts, LOWPAN_CONTEXT_C, 0xFFFF, linkConfiguration->mesh_local_ula_prefix, 64, true);
thread_extension_activate(cur);
thread_extension_bbr_route_update(cur);
blacklist_clear();
@ -800,8 +792,9 @@ int thread_bootstrap_announce_send(protocol_interface_info_entry_t *cur, uint8_t
}
static void thread_announce_ntf_cb(void *arg)
{
if(!arg)
if (!arg) {
return;
}
protocol_interface_info_entry_t *cur = arg;
cur->thread_info->announcement_info->timer = NULL;
thread_bootsrap_event_trig(THREAD_ANNOUNCE_ACTIVE, cur->bootStrapId, ARM_LIB_HIGH_PRIORITY_EVENT);
@ -876,16 +869,14 @@ void thread_bootstrap_temporary_attach(protocol_interface_info_entry_t *cur, uin
thread_bootstrap_reset_restart(cur->id);
}
static const trickle_params_t thread_mpl_data_trickle_params =
{
static const trickle_params_t thread_mpl_data_trickle_params = {
.Imin = 1, /* 50ms */
.Imax = 2, /* 100ms */
.k = 0,
.TimerExpirations = 2 /* MPL core knows to suppress to 0 for non-routers */
};
static const trickle_params_t thread_mpl_control_trickle_params =
{
static const trickle_params_t thread_mpl_control_trickle_params = {
.Imin = 11,
.Imax = 5 * 60 * 20,
.k = 0,
@ -896,7 +887,7 @@ void thread_interface_init(protocol_interface_info_entry_t *cur)
{
thread_discovery_reset(cur->id);
thread_routing_set_mesh_callbacks(cur);
thread_dhcp_client_init(cur->id);
dhcp_client_init(cur->id);
thread_management_client_init(cur->id);
thread_address_registration_init();
cur->mpl_seed_id_mode = MULTICAST_MPL_SEED_ID_MAC_SHORT;
@ -1069,9 +1060,7 @@ void thread_tasklet(arm_event_s *event)
case THREAD_CHILD_UPDATE:
tr_debug_extra("Thread SM THREAD_CHILD_UPDATE");
if (thread_info(cur)->thread_endnode_parent) {
thread_host_bootstrap_child_update(cur, cur->thread_info->thread_endnode_parent->mac64);
}
break;
case THREAD_ANNOUNCE_ACTIVE: {
tr_debug_extra("Thread SM THREAD_ANNOUNCE_ACTIVE");
@ -1178,6 +1167,10 @@ void thread_bootstrap_ready(protocol_interface_info_entry_t *cur)
thread_leader_service_generate_network_data(cur);
}
if (thread_addresses_needs_to_be_registered(cur)) {
thread_info(cur)->childUpdateReqTimer = 1;
}
cur->bootsrap_state_machine_cnt = 0;
mac_data_poll_protocol_poll_mode_decrement(cur);
}
@ -1194,6 +1187,31 @@ void thread_neighbor_list_clean(struct protocol_interface_info_entry *cur)
}
}
void thread_reed_fed_neighbour_links_clean(struct protocol_interface_info_entry *cur)
{
mac_neighbor_table_list_t *mac_table_list = &mac_neighbor_info(cur)->neighbour_list;
if (thread_i_am_router(cur)) {
return;
}
if (thread_info(cur)->thread_device_mode == THREAD_DEVICE_MODE_END_DEVICE ||
thread_info(cur)->thread_device_mode == THREAD_DEVICE_MODE_SLEEPY_END_DEVICE) {
return;
}
if (!thread_info(cur)->thread_endnode_parent) {
return;
}
ns_list_foreach_safe(mac_neighbor_table_entry_t, cur_entry, mac_table_list) {
// do not remove parent entry
if (memcmp(cur_entry->mac64, thread_info(cur)->thread_endnode_parent->mac64, 8) != 0) {
tr_debug("Free short addr: %x", cur_entry->mac16);
mac_neighbor_table_neighbor_remove(mac_neighbor_info(cur), cur_entry);
}
}
}
void thread_clean_old_16_bit_address_based_addresses(protocol_interface_info_entry_t *cur)
{
uint8_t static_address[16];
@ -1271,7 +1289,9 @@ static void thread_bootsrap_network_discovery_failure(int8_t interface_id)
}
//TODO we should send 3 in burst of 0.1 - 0.6 seconds and then do the exponential backup of 5s -- 80s
uint32_t backof_delay = cur->nwk_nd_re_scan_count * 2;
if (backof_delay > 600) backof_delay = 600; //TODO test this and check guess this is 100ms ticks
if (backof_delay > 600) {
backof_delay = 600; //TODO test this and check guess this is 100ms ticks
}
tr_debug("Continue network scan");
cur->nwk_bootstrap_state = ER_ACTIVE_SCAN;
@ -1284,8 +1304,7 @@ static void thread_bootstrap_generate_leader_and_link(protocol_interface_info_en
tr_debug("ReAttach Fail - retry");
thread_bootstrap_attach_start(cur->id, THREAD_REATTACH);
cur->thread_info->thread_attached_state = THREAD_STATE_REATTACH_RETRY;
}
else if (cur->thread_info->thread_attached_state == THREAD_STATE_REATTACH_RETRY) {
} else if (cur->thread_info->thread_attached_state == THREAD_STATE_REATTACH_RETRY) {
tr_warn("ReAttach Fail");
thread_bootstrap_attach_start(cur->id, THREAD_ANY_ATTACH);
} else {
@ -1316,15 +1335,15 @@ static int8_t thread_bootstrap_attempt_attach_with_pending_set(protocol_interfac
thread_joiner_application_old_config_activate(cur->id);
thread_joiner_application_old_config_delete(cur->id);
thread_joiner_application_pending_config_enable(cur->id, 20000);
}
else {
} else {
thread_joiner_pending_config_activate(cur->id);
}
return 0;
}
static void thread_bootstrap_orphan_scan_ready_cb(struct protocol_interface_info_entry *cur_interface, announce_discovery_response_t *discover_response) {
static void thread_bootstrap_orphan_scan_ready_cb(struct protocol_interface_info_entry *cur_interface, announce_discovery_response_t *discover_response)
{
if (!discover_response) {
thread_bootstrap_orphan_scan_start(cur_interface);
@ -1428,8 +1447,7 @@ void thread_bootstrap_connection_error(int8_t interface_id, nwk_connect_error_ty
} else {
thread_bootstrap_generate_leader_and_link(cur);
}
}
else {
} else {
thread_bootstrap_orphan_scan_start(cur);
}
break;
@ -1612,7 +1630,6 @@ void thread_bootstrap_routing_activate(protocol_interface_info_entry_t *cur)
if (cur->thread_info->thread_device_mode == THREAD_DEVICE_MODE_FULL_END_DEVICE ||
cur->thread_info->thread_device_mode == THREAD_DEVICE_MODE_ROUTER) {
thread_meshlocal_route_set(cur);
thread_extension_route_set(cur);
// FEDs and routers (REEDs) perform their own address resolution
thread_nd_service_activate(cur->id);
} else {
@ -1627,7 +1644,7 @@ void thread_bootstrap_attached_finish(protocol_interface_info_entry_t *cur)
cur->lowpan_info |= INTERFACE_NWK_BOOTSRAP_ADDRESS_REGISTER_READY;
cur->lowpan_info &= ~INTERFACE_NWK_ROUTER_DEVICE;
cur->bootsrap_state_machine_cnt = 10;
cur->thread_info->routerIdReqCoapID = 0;
cur->thread_info->routerIdRequested = false;
cur->thread_info->networkDataRequested = false;
clear_power_state(ICMP_ACTIVE);
@ -1644,8 +1661,6 @@ void thread_bootstrap_attached_finish(protocol_interface_info_entry_t *cur)
thread_generate_ml16_address(cur);
//GENERATE ML-EID64
thread_generate_ml64_address(cur);
// Generate new domain address
thread_extension_address_generate(cur);
thread_bootstrap_routing_activate(cur);
thread_bootstrap_network_data_update(cur);
// After successful attach if there is announcement info present, send announcement back to previous channel
@ -1791,10 +1806,8 @@ static int compare_steering_and_joiner_bloom(uint8_t *steering_bloom, uint8_t *j
int loop_iterator;
tr_debug("joiner bloom : %s", trace_array(joiner_bloom, steering_tlv_length));
tr_debug("steering bloom : %s", trace_array(steering_bloom, steering_tlv_length));
for (loop_iterator = 0; loop_iterator < steering_tlv_length; loop_iterator++)
{
if ((joiner_bloom[loop_iterator] != (joiner_bloom[loop_iterator] & steering_bloom[loop_iterator])))
{
for (loop_iterator = 0; loop_iterator < steering_tlv_length; loop_iterator++) {
if ((joiner_bloom[loop_iterator] != (joiner_bloom[loop_iterator] & steering_bloom[loop_iterator]))) {
thci_trace("joinerDiscoveryFailedFiltered");
return 0;
}
@ -1823,8 +1836,7 @@ static void thread_dhcp_client_gua_error_cb(int8_t interface, uint8_t dhcp_addr[
tr_warn("Address Get fail: %s from: %s", trace_ipv6(prefix), trace_ipv6(dhcp_addr));
if (prefix && dhcp_addr) {
tr_debug("Delete Current Server data");
thread_dhcp_client_global_address_delete(interface, dhcp_addr, prefix);
//TODO shuold we try again or select new Server
dhcp_client_global_address_delete(interface, dhcp_addr, prefix);
}
}
}
@ -1964,6 +1976,10 @@ void thread_discover_native_commissioner_response(protocol_interface_info_entry_
config_ptr[n].rfChannel = cur_class->channel;
memcpy(config_ptr[n].name, cur_class->network_name, 16);
memcpy(config_ptr[n].extented_pan_id, cur_class->extented_pan_id, 8);
memcpy(config_ptr[n].destination_address, ADDR_LINK_LOCAL_PREFIX, 8);
memcpy(&config_ptr[n].destination_address[8], cur_class->extented_mac, 8);
config_ptr[n].destination_address[8] ^= 2;
config_ptr[n].destination_port = cur_class->commissioner_port;
n++;
}
@ -2023,7 +2039,7 @@ void thread_discover_native_commissioner_response(protocol_interface_info_entry_
interface->lowpan_info |= INTERFACE_NWK_BOOTSRAP_ADDRESS_REGISTER_READY;
interface->lowpan_info &= ~INTERFACE_NWK_ROUTER_DEVICE;
interface->thread_info->routerIdReqCoapID = 0;
interface->thread_info->routerIdRequested = false;
interface->thread_info->networkDataRequested = false;
interface->bootsrap_state_machine_cnt = 10;
@ -2128,6 +2144,12 @@ static bool thread_bootstrap_sync_after_reset_start(protocol_interface_info_entr
uint16_t my_short_address;
uint8_t parent_mac64[8];
// link sync is allowed only once in bootstrap start and we might get here in other cases also
if (!cur->thread_info->link_sync_allowed) {
return false;
}
cur->thread_info->link_sync_allowed = false;
int link_info_err = thread_nvm_store_link_info_get(parent_mac64, &my_short_address);
if (link_info_err != THREAD_NVM_FILE_SUCCESS) {
tr_warning("thread_nvm_store_link_info_get returned %d", link_info_err);
@ -2278,7 +2300,7 @@ void thread_bootstrap_stop(protocol_interface_info_entry_t *cur)
thread_leader_service_leader_data_free(cur->thread_info);
thread_bootstrap_all_nodes_multicast_unregister(cur);
thread_data_base_init(cur->thread_info, cur->id);
thread_dhcp_client_delete(cur->id);
dhcp_client_delete(cur->id);
thread_nd_service_delete(cur->id);
thread_child_id_request_entry_clean(cur);
thread_registered_mcast_addr_entry_clean(cur);
@ -2356,6 +2378,7 @@ static int thread_nd_prefix_context_allocate(protocol_interface_info_entry_t *cu
if (cid == 16) {
return -1;
}
context.cid = cid;
context.compression = true;
context.stableData = stableData;
@ -2499,6 +2522,7 @@ int thread_bootstrap_network_data_process(protocol_interface_info_entry_t *cur,
genericService.P_slaac = ((flags >> THREAD_P_SLAAC_BIT_MOVE) & 1);
genericService.P_on_mesh = ((flags >> THREAD_P_ON_MESH_BIT_MOVE) & 1);
genericService.P_nd_dns = ((flags >> THREAD_P_ND_DNS_BIT_MOVE) & 1);
genericService.P_res1 = ((flags >> THREAD_P_ND_RES_BIT_MOVE) & 1);
if (thread_nd_local_list_add_on_mesh_prefix(networkDataStorage, &prefixTlv, &genericService) == 0) {
if (networkDataStorage->stableUpdatePushed || networkDataStorage->temporaryUpdatePushed) {
if (!genericService.P_slaac) {
@ -2525,7 +2549,7 @@ int thread_bootstrap_network_data_process(protocol_interface_info_entry_t *cur,
memcpy(&addr[8], ADDR_SHORT_ADR_SUFFIC, 6);
common_write_16_bit(genericService.routerID, &addr[14]);
tr_debug("Delete DHCPv6 given address");
thread_dhcp_client_global_address_delete(cur->id, addr, prefixTlv.Prefix);
dhcp_client_global_address_delete(cur->id, addr, prefixTlv.Prefix);
}
}
@ -2581,9 +2605,9 @@ int thread_bootstrap_network_data_process(protocol_interface_info_entry_t *cur,
length -= subLength;
data_changed = thread_commission_data_tlv_parse(cur, type, subLength, dptr);
if (data_changed < 0)
if (data_changed < 0) {
tr_debug("Fail");
else {
} else {
if (data_changed == 1) {
update_data = true;
tr_debug("Changed");
@ -2702,6 +2726,8 @@ int thread_bootstrap_network_data_activate(protocol_interface_info_entry_t *cur)
thread_border_router_network_data_update_notify(cur);
thread_bbr_network_data_update_notify(cur);
thread_maintenance_timer_set(cur, THREAD_MAINTENANCE_TIMER_INTERVAL);
return 0;
}
@ -2744,7 +2770,6 @@ int thread_bootstrap_network_data_save(protocol_interface_info_entry_t *cur, thr
return 0;
}
void thread_bootstrap_network_prefixes_process(protocol_interface_info_entry_t *cur)
{
// Route prefix is variable-length, so need to zero pad for ip6tos
@ -2794,6 +2819,8 @@ void thread_bootstrap_network_prefixes_process(protocol_interface_info_entry_t *
if (curBorderRouter->P_dhcp && weHostService && nd_proxy_enabled_for_upstream(cur->id) && nd_proxy_upstream_route_onlink(cur->id, curPrefix->servicesPrefix)) {
// don't add
tr_debug("Suppressing onlink %s for proxy", trace_ipv6_prefix(curPrefix->servicesPrefix, curPrefix->servicesPrefixLen));
} else if (curBorderRouter->P_res1) {
ipv6_route_add(curPrefix->servicesPrefix, curPrefix->servicesPrefixLen, cur->id, NULL, ROUTE_THREAD_PROXIED_DUA_HOST, 0xffffffff, 0);
} else {
//add
tr_debug("Adding onlink %s", trace_ipv6_prefix(curPrefix->servicesPrefix, curPrefix->servicesPrefixLen));
@ -2818,8 +2845,8 @@ void thread_bootstrap_network_prefixes_process(protocol_interface_info_entry_t *
if (!thread_dhcpv6_address_entry_available(curPrefix->servicesPrefix, &cur->ip_addresses)) {
thread_addr_write_mesh_local_16(addr, curBorderRouter->routerID, cur->thread_info);
/* Do not allow multiple DHCP solicits from one prefix => delete previous */
thread_dhcp_client_global_address_delete(cur->id, NULL, curPrefix->servicesPrefix);
if (thread_dhcp_client_get_global_address(cur->id, addr, curPrefix->servicesPrefix, cur->mac, thread_dhcp_client_gua_error_cb) == 0) {
dhcp_client_global_address_delete(cur->id, NULL, curPrefix->servicesPrefix);
if (dhcp_client_get_global_address(cur->id, addr, curPrefix->servicesPrefix, cur->mac, thread_dhcp_client_gua_error_cb) == 0) {
tr_debug("GP Address Requested");
}
}
@ -2839,6 +2866,10 @@ void thread_bootstrap_network_prefixes_process(protocol_interface_info_entry_t *
icmpv6_slaac_address_add(cur, curPrefix->servicesPrefix, curPrefix->servicesPrefixLen, 0xffffffff, 0xffffffff, true, SLAAC_IID_DEFAULT);
}
}
// generate address based on res1 bit
if (curBorderRouter->P_res1) {
thread_extension_dua_address_generate(cur, curPrefix->servicesPrefix, 64);
}
} // for each borderRouterList
@ -2913,8 +2944,7 @@ void thread_bootstrap_dynamic_configuration_save(protocol_interface_info_entry_t
uint32_t mle_frame_counter = mle_service_security_get_frame_counter(cur->id);
if (linkConfiguration) {
thread_nvm_store_fast_data_check_and_write(mac_frame_counter, mle_frame_counter, linkConfiguration->key_sequence);
}
else {
} else {
thread_nvm_store_frame_counters_check_and_write(mac_frame_counter, mle_frame_counter);
}
}

View File

@ -106,6 +106,9 @@ void thread_general_mle_receive_cb(int8_t interface_id, mle_message_t *mle_msg,
void thread_bootstrap_ready(struct protocol_interface_info_entry *cur);
int thread_bootstrap_reset(struct protocol_interface_info_entry *cur);
void thread_neighbor_list_clean(struct protocol_interface_info_entry *cur);
/* Function to remove linked neighbours for REEDs and FEDs */
void thread_reed_fed_neighbour_links_clean(struct protocol_interface_info_entry *cur);
bool thread_bootstrap_request_network_data(struct protocol_interface_info_entry *cur, struct thread_leader_data_s *leaderData, uint16_t short_address);
bool thread_check_is_this_my_parent(struct protocol_interface_info_entry *cur, struct mac_neighbor_table_entry *entry_temp);
void thread_clean_old_16_bit_address_based_addresses(struct protocol_interface_info_entry *cur);
@ -191,7 +194,6 @@ int thread_bootstrap_announce_send(protocol_interface_info_entry_t *cur, uint8_t
void thread_bootstrap_announcement_start(protocol_interface_info_entry_t *cur, uint8_t channel_page, uint16_t channel, uint8_t count, uint16_t period);
void thread_bootstrap_temporary_attach(protocol_interface_info_entry_t *cur, uint8_t channel_page, uint16_t channel, uint16_t panid, uint64_t timestamp);
#else
#define thread_interface_up(cur) ((void) 0)
#define thread_bootstrap_state_machine(cur) ((void)0)

View File

@ -42,6 +42,7 @@
#include "NWK_INTERFACE/Include/protocol.h"
#include "6LoWPAN/Thread/thread_config.h"
#include "6LoWPAN/Thread/thread_common.h"
#include "6LoWPAN/Thread/thread_extension_bbr.h"
#include "6LoWPAN/Thread/thread_network_data_lib.h"
#include "6LoWPAN/Thread/thread_network_data_storage.h"
#include "6LoWPAN/Thread/thread_management_client.h"
@ -591,6 +592,15 @@ void thread_border_router_network_data_update_notify(protocol_interface_info_ent
thread_border_router_network_data_appl_callback(cur);
}
void thread_border_router_old_partition_data_clean(int8_t interface_id)
{
thread_border_router_t *this = thread_border_router_find_by_interface(interface_id);
if (this) {
coap_service_request_delete_by_service_id(this->coap_service_id);
}
thread_extension_bbr_old_partition_data_clean(interface_id);
}
#endif // HAVE_THREAD_ROUTER
/*External APIs*/
@ -837,7 +847,6 @@ int thread_border_router_dns_search_list_option_set(int8_t interface_id, uint8_t
static void thread_tmf_client_network_data_set_cb(int8_t interface_id, int8_t status, uint8_t *data_ptr, uint16_t data_len)
{
protocol_interface_info_entry_t *cur;
(void) status;
(void) data_len;
(void) data_ptr;
@ -846,7 +855,7 @@ static void thread_tmf_client_network_data_set_cb(int8_t interface_id, int8_t st
return;
}
cur->thread_info->localServerDataBase.publish_active = false;
cur->thread_info->localServerDataBase.publish_coap_req_id = 0;
tr_debug("BR a/sd response status: %s, addr: %x", status ? "Fail" : "OK", cur->thread_info->localServerDataBase.registered_rloc16);
@ -855,10 +864,12 @@ static void thread_tmf_client_network_data_set_cb(int8_t interface_id, int8_t st
thread_border_router_publish(cur->id);
}
// always update RLOC to new one. If COAP response fails then resubmit timer will trigger new a/sd
if (status == 0) {
// If request was successful, then update RLOC to new one.
cur->thread_info->localServerDataBase.registered_rloc16 = mac_helper_mac16_address_get(cur);
cur->thread_info->localServerDataBase.release_old_address = false;
}
}
#endif
int thread_border_router_publish(int8_t interface_id)
@ -884,21 +895,20 @@ int thread_border_router_publish(int8_t interface_id)
rloc16 = mac_helper_mac16_address_get(cur);
tr_debug("Border router old: %x, new: %x", cur->thread_info->localServerDataBase.registered_rloc16, rloc16);
if (cur->thread_info->localServerDataBase.publish_active) {
if (cur->thread_info->localServerDataBase.publish_coap_req_id) {
if (rloc16 != cur->thread_info->localServerDataBase.registered_rloc16) {
/*
* Device short address has changed, cancel previous a/sd and a/as requests
* Device short address has changed, cancel previous a/sd requests
* and start resubmit timer
* */
tr_debug("address changed, kill pending reuqests");
thread_management_client_pending_coap_request_kill(cur->id);
tr_debug("RLOC changed, kill pending a/sd request");
thread_management_client_coap_message_delete(cur->id, cur->thread_info->localServerDataBase.publish_coap_req_id);
thread_border_router_resubmit_timer_set(interface_id, 5);
return 0;
} else {
cur->thread_info->localServerDataBase.publish_pending = true;
tr_debug("Activate pending status for publish");
return 0;
}
return 0;
}
//Allocate Memory for Data
@ -926,8 +936,10 @@ int thread_border_router_publish(int8_t interface_id)
if (payload_ptr) {
ns_dyn_mem_free(payload_ptr);
}
if (ret_val == 0) {
cur->thread_info->localServerDataBase.publish_active = true;
if (ret_val > 0) {
// a/sd request successful, save coap request id
cur->thread_info->localServerDataBase.publish_coap_req_id = (uint16_t)ret_val;
ret_val = 0 ;
}
thread_border_router_resubmit_timer_set(interface_id, -1);

View File

@ -85,6 +85,14 @@ void thread_border_router_network_data_appl_callback(protocol_interface_info_ent
*
*/
void thread_border_router_network_data_update_notify(protocol_interface_info_entry_t *cur);
/**
* \brief Clear data related to old partition.
*
* \param interface_id Network interface ID.
*/
void thread_border_router_old_partition_data_clean(int8_t interface_id);
#else
#define thread_border_router_init(interface_id)
#define thread_border_router_delete(interface_id)
@ -92,6 +100,7 @@ void thread_border_router_network_data_update_notify(protocol_interface_info_ent
#define thread_border_router_resubmit_timer_set(interface_id, seconds)
#define thread_border_router_network_data_appl_callback(cur)
#define thread_border_router_network_data_update_notify(cur)
#define thread_border_router_old_partition_data_clean(interface_id)
#endif
#endif /* THREAD_BORDER_ROUTER_API_INTERNAL_H_ */

View File

@ -35,6 +35,7 @@
#include "ns_list.h"
#include "ns_trace.h"
#include "nsdynmemLIB.h"
#include "randLIB.h"
#include "common_functions.h"
#include "ns_sha256.h"
@ -74,6 +75,8 @@ typedef NS_LIST_HEAD(device_t, link) device_list_t;
typedef struct commissioner_entry {
device_list_t device_list;
uint8_t destination_address[16];
uint8_t final_dest_address[16]; // Relay message final destination
uint8_t leader_address[16]; // leader ALOC for contacting the leader
uint8_t PSKc_ptr[16];
thread_commissioning_status_cb *status_cb_ptr;
uint16_t destination_port;
@ -82,7 +85,8 @@ typedef struct commissioner_entry {
int8_t interface_id;
int8_t coap_service_id;
int8_t coap_secure_service_id;
int8_t coap_virtual_service_id;
int8_t coap_secure_virtual_service_id;
int8_t coap_udp_proxy_service_id;
bool registered: 1;
bool native_commissioner: 1;
@ -167,7 +171,7 @@ static commissioner_t *commissioner_find_by_service(int8_t service_id)
{
commissioner_t *this = NULL;
ns_list_foreach(commissioner_t, cur_ptr, &instance_list) {
if (cur_ptr->coap_service_id == service_id || cur_ptr->coap_virtual_service_id == service_id || cur_ptr->coap_secure_service_id == service_id) {
if (cur_ptr->coap_service_id == service_id || cur_ptr->coap_secure_virtual_service_id == service_id || cur_ptr->coap_secure_service_id == service_id || cur_ptr->coap_udp_proxy_service_id == service_id) {
this = cur_ptr;
break;
}
@ -237,12 +241,46 @@ static int commission_finalisation_resp_send(int8_t coap_service_id, device_t *d
* Callback functions
*/
static int thread_commissioning_active_get_cb(int8_t service_id, uint8_t source_address[static 16], uint16_t source_port, sn_coap_hdr_s *response_ptr)
{
commissioner_t *this = commissioner_find_by_service(service_id);
commissioning_state_e state = COMMISSIONING_STATE_REJECT;// Default is accept if we get error it is rejected
uint8_t *ptr;
uint16_t len;
(void) source_address;
(void) source_port;
/* Transaction failed */
if (!response_ptr) {
return -1;
}
tr_debug("management get response from comm module");
if (!this) {
return -2;
}
if ((len = thread_meshcop_tlv_find(response_ptr->payload_ptr, response_ptr->payload_len, MESHCOP_TLV_NETWORK_MESH_LOCAL_ULA, &ptr)) > 0) {
state = COMMISSIONING_STATE_ACCEPT;
tr_debug(" TLV ml prefix=%s\r\n", trace_array(ptr, len));
memcpy(this->leader_address, ptr, 8);
memcpy(this->leader_address + 8, ADDR_SHORT_ADR_SUFFIC, 6);
common_write_16_bit(0xfc00, this->leader_address + 14);
}
if (this->status_cb_ptr) {
this->status_cb_ptr(this->interface_id, this->session_id, state);
}
return 0;
}
static int commissioning_leader_petition_recv_cb(int8_t service_id, uint8_t source_address[static 16], uint16_t source_port, sn_coap_hdr_s *response_ptr)
{
commissioner_t *this = commissioner_find_by_service(service_id);
commissioning_state_e state = COMMISSIONING_STATE_REJECT;
uint16_t session_id = 0;
uint8_t *ptr;
uint8_t *ptr = NULL;
char *uri_ptr = THREAD_URI_ACTIVE_GET;
(void) source_address;
(void) source_port;
@ -267,6 +305,16 @@ static int commissioning_leader_petition_recv_cb(int8_t service_id, uint8_t sour
}
tr_debug("petition response session_id: %d state:%d", session_id, state);
// if registered and native commissioner send ACTIVE_GET to BBR to get mesh parameters
// if not native set leader ALOC from stack
if (this->native_commissioner) {
coap_service_request_send(service_id, COAP_REQUEST_OPTIONS_NONE, this->destination_address, this->destination_port,
COAP_MSG_TYPE_CONFIRMABLE, COAP_MSG_CODE_REQUEST_POST, uri_ptr, COAP_CT_OCTET_STREAM, NULL, 0, thread_commissioning_active_get_cb);
return 0;
} else {
thread_management_get_leader_aloc(this->interface_id, this->leader_address);
}
user_response:
if (state == COMMISSIONING_STATE_REJECT) {
thci_trace("commissionerPetitionRejected");
@ -376,25 +424,65 @@ static int commission_dataset_changed_notify_recv_cb(int8_t service_id, uint8_t
(void)source_port;
tr_debug("Dataset changed - notification received from: %s", trace_ipv6(source_address));
commissioner_t *this = commissioner_find_by_service(service_id);
if (!this) {
return -1;
}
coap_service_request_send(service_id, COAP_REQUEST_OPTIONS_NONE, this->destination_address, this->destination_port,
COAP_MSG_TYPE_CONFIRMABLE, COAP_MSG_CODE_REQUEST_POST, THREAD_URI_ACTIVE_GET, COAP_CT_OCTET_STREAM, NULL, 0, thread_commissioning_active_get_cb);
coap_service_response_send(service_id, COAP_REQUEST_OPTIONS_NONE, request_ptr, COAP_MSG_CODE_RESPONSE_CHANGED, COAP_CT_NONE, NULL, 0);
return 0;
}
static int thread_commission_udp_proxy_receive_cb(int8_t service_id, uint8_t source_address[static 16], uint16_t source_port, sn_coap_hdr_s *request_ptr)
{
tr_debug("Recv UDP_RX.ntf");
commissioner_t *this = commissioner_find_by_service(service_id);
uint8_t *udp_encapsulation_ptr, *udp_tmf_ptr;
uint16_t udp_encapsulation_len, udp_tmf_len;
uint8_t *ipv6_addr_ptr;
uint16_t ipv6_addr_len;
uint16_t dest_port;
(void) source_port;
if (!this || !source_address || !request_ptr) {
return -1; // goto error response
}
udp_encapsulation_len = thread_meshcop_tlv_find(request_ptr->payload_ptr, request_ptr->payload_len, MESHCOP_TLV_UDP_ENCAPSULATION, &udp_encapsulation_ptr);
ipv6_addr_len = thread_meshcop_tlv_find(request_ptr->payload_ptr, request_ptr->payload_len, MESHCOP_TLV_IPV6_ADDRESS, &ipv6_addr_ptr);
if (udp_encapsulation_len == 0 || ipv6_addr_len < 16) {
tr_warn("Corrupted UDP_RX.ntf received (%d, %d)", udp_encapsulation_len, ipv6_addr_len);
return -1;
}
dest_port = common_read_16_bit(udp_encapsulation_ptr + 2);
udp_tmf_len = udp_encapsulation_len - 4;
udp_tmf_ptr = udp_encapsulation_ptr + 4;
tr_debug("UDP_RX tmf: %s", trace_array(udp_tmf_ptr, udp_tmf_len));
coap_service_virtual_socket_recv(this->coap_udp_proxy_service_id, ipv6_addr_ptr, dest_port, udp_tmf_ptr, udp_tmf_len);
return -1; // no response sent
}
static uint8_t *bloom_filter_calculate(uint8_t *bloom_filter_ptr, device_list_t device_list, int *steering_tlv_max_length)
{
memset(bloom_filter_ptr, 0, *steering_tlv_max_length);
ns_list_foreach(device_t, cur_ptr, &device_list)
{
if (memcmp(cur_ptr->EUI64, any_device, 8) != 0)
{
ns_list_foreach(device_t, cur_ptr, &device_list) {
if (memcmp(cur_ptr->EUI64, any_device, 8) != 0) {
tr_debug("eui64 used on commissioning side = %s", trace_array(cur_ptr->EUI64, 8));
cur_ptr->IID[0] |= 2; //Changed IID to MAC extended address for bloom filter calculation
thread_beacon_calculate_bloom_filter(bloom_filter_ptr, *steering_tlv_max_length, cur_ptr->IID, 8);
cur_ptr->IID[0] &= ~2;//Restore IID
}
else
{
} else {
bloom_filter_ptr[0] = 0xff;
*steering_tlv_max_length = 1;
break;
@ -403,6 +491,35 @@ static uint8_t *bloom_filter_calculate(uint8_t *bloom_filter_ptr,device_list_t d
return bloom_filter_ptr;
}
static int thread_commissioner_set_steering_data(commissioner_t *this, uint16_t session_id, uint8_t *steering_data_ptr, uint8_t steering_data_len)
{
uint8_t payload[24];/* 4 + 16 + 4*/
uint8_t *ptr;
int8_t coap_service_id;
if (!this || steering_data_len > 16) {
return -1;
}
ptr = payload;
ptr = thread_meshcop_tlv_data_write(ptr, MESHCOP_TLV_STEERING_DATA, steering_data_len, steering_data_ptr);
ptr = thread_meshcop_tlv_data_write_uint16(ptr, MESHCOP_TLV_COMMISSIONER_SESSION_ID, session_id);
tr_debug("thread commissioner set steering data %s", trace_array(steering_data_ptr, steering_data_len));
memcpy(this->final_dest_address, this->leader_address, 16);
//default uri for thread version 1.1
char *uri = THREAD_URI_COMMISSIONER_SET;
if (this->native_commissioner) {
coap_service_id = this->coap_udp_proxy_service_id;
} else {
coap_service_id = this->coap_service_id;
}
coap_service_request_send(coap_service_id, COAP_REQUEST_OPTIONS_NONE, this->destination_address, this->destination_port,
COAP_MSG_TYPE_CONFIRMABLE, COAP_MSG_CODE_REQUEST_POST, uri, COAP_CT_OCTET_STREAM, payload, ptr - payload, NULL);
return 0;
}
static int commission_steering_data_update(commissioner_t *this)
{
@ -414,7 +531,7 @@ static int commission_steering_data_update(commissioner_t *this)
//bloom filter calculation function call
bloom_filter_calculate(bloom_filter_ptr, this->device_list, &steering_tlv_length);
tr_debug("Steering bloom set :%s", trace_array(bloom_filter_ptr, 16));
ret = thread_management_set_steering_data(this->management_instance, this->session_id,bloom_filter_ptr, steering_tlv_length, NULL);
ret = thread_commissioner_set_steering_data(this, this->session_id, bloom_filter_ptr, steering_tlv_length);
if (ret) {
tr_warn("Steering data set failed %d", ret);
return -1;
@ -475,7 +592,7 @@ static int commission_relay_rx_recv_cb(int8_t service_id, uint8_t source_address
tr_warn("catching device for iid:%s", trace_array(&joiner_address[8], 8));
}
device_ptr->joiner_router_rloc = joiner_router_rloc;
coap_service_virtual_socket_recv(this->coap_virtual_service_id, joiner_address, joiner_port, udp_ptr, udp_len);
coap_service_virtual_socket_recv(this->coap_secure_virtual_service_id, joiner_address, joiner_port, udp_ptr, udp_len);
return -1; // no response sent
}
@ -616,20 +733,55 @@ static int commissioner_br_security_done_cb(int8_t service_id, uint8_t address[1
return 0;
}
static int thread_commissioning_remote_addr_set(commissioner_t *this)
static int thread_commission_udp_proxy_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)
{
if (0 == thread_management_get_leader_address(this->interface_id, this->destination_address)) {
tr_debug("on-mesh commissioner");
this->destination_port = THREAD_MANAGEMENT_PORT;
this->native_commissioner = false;
} else if (0 == thread_commissioning_native_commissioner_get_connection_info(this->interface_id,
this->destination_address, &this->destination_port)) {
tr_debug("native commissioner");
this->native_commissioner = true;
} else {
tr_error("No remote address");
(void) port;
uint8_t *payload_ptr;
uint8_t *ptr;
uint16_t payload_len;
uint16_t source_port;
commissioner_t *this = commissioner_find_by_service(service_id);
if (!this) {
return -1;
}
tr_debug("UDP_TX.ntf tmf: %s", trace_array(data_ptr, data_len));
if (!this || !destination_addr_ptr || !data_ptr) {
return -1;
}
payload_len = 2 + THREAD_IPV6_ADDRESS_TLV_LENGTH + 4 + 4 + data_len; // MESHCOP_TLV_IPV6_ADDRESS + MESHCOP_TLV_UDP_ENCAPSULATION
payload_ptr = ns_dyn_mem_alloc(payload_len);
if (!payload_ptr) {
return -3;
}
ptr = payload_ptr;
tr_debug("br_address %s final dest_address %s and port %d", trace_ipv6(this->destination_address),
trace_ipv6(this->final_dest_address), this->destination_port);
/* MESHCOP_TLV_IPV6_ADDRESS */
ptr = thread_meshcop_tlv_data_write(ptr, MESHCOP_TLV_IPV6_ADDRESS, THREAD_IPV6_ADDRESS_TLV_LENGTH, this->final_dest_address);
/* MESHCOP_TLV_UDP_ENCAPSULATION */
*ptr++ = MESHCOP_TLV_UDP_ENCAPSULATION;
*ptr++ = 0xff;
ptr = common_write_16_bit(2 + 2 + data_len, ptr); // length (Port x 2 + TMF message)
source_port = randLIB_get_16bit(); // ephemeral port, 16-bit number
ptr = common_write_16_bit(source_port, ptr); // source port,
ptr = common_write_16_bit(THREAD_MANAGEMENT_PORT, ptr); // destination port
memcpy(ptr, data_ptr, data_len);
ptr += data_len;
/* Send UDP_TX.ntf */
coap_service_request_send(this->coap_secure_service_id, COAP_REQUEST_OPTIONS_NONE, this->destination_address, this->destination_port,
COAP_MSG_TYPE_NON_CONFIRMABLE, COAP_MSG_CODE_REQUEST_POST, THREAD_URI_UDP_TRANSMIT_NOTIFICATION, COAP_CT_OCTET_STREAM, payload_ptr, ptr - payload_ptr, NULL);
ns_dyn_mem_free(payload_ptr);
return 0;
}
@ -638,16 +790,17 @@ Public api functions
*/
int thread_commissioning_register(int8_t interface_id, uint8_t PSKc[static 16])
{
if (commissioner_find(interface_id)) {
return -1;
commissioner_t *this = commissioner_find(interface_id);
if (!this) {
this = commissioner_create(interface_id);
}
commissioner_t *this = commissioner_create(interface_id);
if (!this) {
return -2;
}
memcpy(this->PSKc_ptr, PSKc, 16);
this->management_instance = thread_management_register(interface_id);
if (this->registered) {
return 0;
}
this->coap_service_id = coap_service_initialize(this->interface_id, THREAD_MANAGEMENT_PORT, COAP_SERVICE_OPTIONS_NONE, NULL, NULL);
coap_service_register_uri(this->coap_service_id, THREAD_URI_RELAY_RECEIVE, COAP_SERVICE_ACCESS_POST_ALLOWED, commission_relay_rx_recv_cb);
coap_service_register_uri(this->coap_service_id, THREAD_URI_JOINER_APPLICATION_REQUEST, COAP_SERVICE_ACCESS_POST_ALLOWED, commission_application_provision_req_recv_cb);
@ -655,10 +808,15 @@ int thread_commissioning_register(int8_t interface_id, uint8_t PSKc[static 16])
this->coap_secure_service_id = coap_service_initialize(this->interface_id, THREAD_COMMISSIONING_PORT, COAP_SERVICE_OPTIONS_SECURE | COAP_SERVICE_OPTIONS_SECURE_BYPASS, commissioner_br_security_start_cb, commissioner_br_security_done_cb);
coap_service_register_uri(this->coap_secure_service_id, THREAD_URI_RELAY_RECEIVE, COAP_SERVICE_ACCESS_POST_ALLOWED, commission_relay_rx_recv_cb);
coap_service_register_uri(this->coap_secure_service_id, THREAD_URI_UDP_RECVEIVE_NOTIFICATION, COAP_SERVICE_ACCESS_POST_ALLOWED, thread_commission_udp_proxy_receive_cb);
this->coap_secure_virtual_service_id = coap_service_initialize(this->interface_id, THREAD_MANAGEMENT_PORT, COAP_SERVICE_OPTIONS_SECURE | COAP_SERVICE_OPTIONS_VIRTUAL_SOCKET, joiner_commissioner_security_start_cb, commissioning_security_done_cb);
coap_service_register_uri(this->coap_secure_virtual_service_id, THREAD_URI_JOINER_FINALIZATION, COAP_SERVICE_ACCESS_POST_ALLOWED, commission_finalisation_req_recv_cb);
coap_service_virtual_socket_set_cb(this->coap_secure_virtual_service_id, commission_virtual_socket_send_cb);
this->coap_udp_proxy_service_id = coap_service_initialize(this->interface_id, THREAD_MANAGEMENT_PORT, COAP_SERVICE_OPTIONS_VIRTUAL_SOCKET, NULL, NULL);
coap_service_virtual_socket_set_cb(this->coap_udp_proxy_service_id, thread_commission_udp_proxy_virtual_socket_send_cb);
this->coap_virtual_service_id = coap_service_initialize(this->interface_id, THREAD_MANAGEMENT_PORT, COAP_SERVICE_OPTIONS_SECURE | COAP_SERVICE_OPTIONS_VIRTUAL_SOCKET, joiner_commissioner_security_start_cb, commissioning_security_done_cb);
coap_service_register_uri(this->coap_virtual_service_id, THREAD_URI_JOINER_FINALIZATION, COAP_SERVICE_ACCESS_POST_ALLOWED, commission_finalisation_req_recv_cb);
coap_service_virtual_socket_set_cb(this->coap_virtual_service_id, commission_virtual_socket_send_cb);
return 0;
}
@ -672,11 +830,11 @@ int thread_commissioning_unregister(int8_t interface_id)
// Unregister the commissioner
thread_commissioning_petition_keep_alive(this->interface_id, COMMISSIONING_STATE_REJECT);
}
thread_management_unregister(this->management_instance);
coap_service_delete(this->coap_service_id);
coap_service_delete(this->coap_secure_service_id);
coap_service_delete(this->coap_virtual_service_id);
coap_service_delete(this->coap_secure_virtual_service_id);
coap_service_delete(this->coap_udp_proxy_service_id);
commissioner_delete(this);
return 0;
@ -690,7 +848,6 @@ int thread_commissioning_petition_start(int8_t interface_id, char *commissioner_
uint8_t service_id;
uint8_t *ptr;
char *uri_ptr;
this = commissioner_find(interface_id);
if (!this) {
@ -705,16 +862,14 @@ int thread_commissioning_petition_start(int8_t interface_id, char *commissioner_
return -3;
}
if (thread_commissioning_remote_addr_set(this)) {
return -4;
}
if (this->native_commissioner) {
uri_ptr = THREAD_URI_COMMISSIONER_PETITION;
service_id = this->coap_secure_service_id;
} else {
uri_ptr = THREAD_URI_LEADER_PETITION;
service_id = this->coap_service_id;
thread_management_get_leader_aloc(this->interface_id, this->destination_address);
this->destination_port = THREAD_MANAGEMENT_PORT;
}
this->status_cb_ptr = status_cb_ptr;
@ -747,16 +902,13 @@ int thread_commissioning_petition_keep_alive(int8_t interface_id, commissioning_
return -1;
}
if (thread_commissioning_remote_addr_set(this)) {
return -4;
}
if (this->native_commissioner) {
uri_ptr = THREAD_URI_COMMISSIONER_KEEP_ALIVE;
service_id = this->coap_secure_service_id;
} else {
uri_ptr = THREAD_URI_LEADER_KEEP_ALIVE;
service_id = this->coap_service_id;
thread_management_get_leader_aloc(this->interface_id, this->destination_address);
}
ptr = payload;
@ -858,15 +1010,39 @@ void *thread_commission_device_get_next(void *ptr, int8_t interface_id, bool *sh
} else {
cur_ptr = (device_t *)ns_list_get_next(&this->device_list, cur_ptr);
}
if(!cur_ptr) return NULL;
if(short_eui64) *short_eui64 = cur_ptr->short_eui64;
if(EUI64) memcpy(EUI64, cur_ptr->EUI64, 8);
if(PSKd) memcpy(PSKd, cur_ptr->PSKd, 32);
if(PSKd_len) *PSKd_len = cur_ptr->PSKd_len;
if (!cur_ptr) {
return NULL;
}
if (short_eui64) {
*short_eui64 = cur_ptr->short_eui64;
}
if (EUI64) {
memcpy(EUI64, cur_ptr->EUI64, 8);
}
if (PSKd) {
memcpy(PSKd, cur_ptr->PSKd, 32);
}
if (PSKd_len) {
*PSKd_len = cur_ptr->PSKd_len;
}
return cur_ptr;
}
int thread_commissioning_attach(int8_t interface_id, uint8_t *destination_address, uint16_t destination_port)
{
tr_debug("start ethernet commissioner attach");
commissioner_t *this = commissioner_find(interface_id);
if (!this) {
return -1;
}
memcpy(this->destination_address, destination_address, 16);
this->destination_port = destination_port;
this->native_commissioner = true;
return 0;
}
int thread_commissioning_native_commissioner_start(int8_t interface_id, thread_commissioning_native_select_cb *cb_ptr)
{
protocol_interface_info_entry_t *cur;
@ -909,6 +1085,18 @@ int thread_commissioning_native_commissioner_connect(int8_t interface_id, thread
return -2;
}
*cur->thread_info->native_commissioner_link = *link_ptr;
commissioner_t *this = commissioner_find(interface_id);
if (!this) {
this = commissioner_create(interface_id);
}
if (!this) {
return -3;
}
this->native_commissioner = true;
memcpy(this->destination_address, link_ptr->destination_address, 16);
this->destination_port = link_ptr->destination_port;
//TODO check that we are scanning for networks and reset backup timers
return 0;
@ -916,22 +1104,15 @@ int thread_commissioning_native_commissioner_connect(int8_t interface_id, thread
int thread_commissioning_native_commissioner_get_connection_info(int8_t interface_id, uint8_t *address_ptr, uint16_t *port)
{
protocol_interface_info_entry_t *cur;
cur = protocol_stack_interface_info_get_by_id(interface_id);
commissioner_t *this = commissioner_find(interface_id);
tr_debug("get native connection info");
if(!cur || !cur->thread_info) {
if (!this) {
return -1;
}
if (thread_attach_ready(cur) != 0) {
return -2;
}
if (protocol_6lowpan_interface_get_link_local_cordinator_address(cur, address_ptr) != 0) {
return -1;
}
if (port) {
*port = cur->thread_info->native_commissioner_port;
}
memcpy(address_ptr, this->destination_address, 16);
*port = this->destination_port;
return 0;
}
@ -947,7 +1128,8 @@ int8_t thread_commissioning_get_management_id(int8_t interface_id)
#else
int thread_commissioning_register(int8_t interface_id, uint8_t PSKc[static 16]) {
int thread_commissioning_register(int8_t interface_id, uint8_t PSKc[static 16])
{
(void)interface_id;
(void)PSKc;
return -1;
@ -1002,33 +1184,46 @@ int thread_commissioning_petition_start(int8_t interface_id, char *commissioner_
return -1;
}
int thread_commissioning_native_commissioner_get_connection_info(int8_t interface_id, uint8_t *address_ptr, uint16_t *port) {
int thread_commissioning_native_commissioner_get_connection_info(int8_t interface_id, uint8_t *address_ptr, uint16_t *port)
{
(void)interface_id;
(void)address_ptr;
(void)port;
return -1;
}
int8_t thread_commissioning_get_management_id(int8_t interface_id) {
int8_t thread_commissioning_get_management_id(int8_t interface_id)
{
(void)interface_id;
return -1;
}
int thread_commissioning_native_commissioner_start(int8_t interface_id, thread_commissioning_native_select_cb *cb_ptr) {
int thread_commissioning_native_commissioner_start(int8_t interface_id, thread_commissioning_native_select_cb *cb_ptr)
{
(void)interface_id;
(void)cb_ptr;
return -1;
}
int thread_commissioning_native_commissioner_stop(int8_t interface_id) {
int thread_commissioning_native_commissioner_stop(int8_t interface_id)
{
(void)interface_id;
return -1;
}
int thread_commissioning_native_commissioner_connect(int8_t interface_id, thread_commissioning_link_configuration_s *link_ptr) {
int thread_commissioning_native_commissioner_connect(int8_t interface_id, thread_commissioning_link_configuration_s *link_ptr)
{
(void)interface_id;
(void)link_ptr;
return -1;
}
int thread_commissioning_attach(int8_t interface_id, uint8_t *destination_address, uint16_t destination_port)
{
(void)interface_id;
(void)destination_address;
(void)destination_port;
return -1;
}
#endif

View File

@ -44,9 +44,11 @@
#include "6LoWPAN/Bootstraps/protocol_6lowpan_interface.h"
#include "6LoWPAN/Thread/thread_common.h"
#include "6LoWPAN/Thread/thread_beacon.h"
#include "6LoWPAN/Thread/thread_diagnostic.h"
#include "6LoWPAN/Thread/thread_extension_bbr.h"
#include "6LoWPAN/Thread/thread_leader_service.h"
#include "6LoWPAN/Thread/thread_routing.h"
#include "6LoWPAN/Thread/thread_dhcpv6_client.h"
#include "DHCPv6_client/dhcpv6_client_api.h"
#include "6LoWPAN/Thread/thread_discovery.h"
#include "6LoWPAN/Thread/thread_bootstrap.h"
#include "6LoWPAN/Thread/thread_router_bootstrap.h"
@ -60,6 +62,7 @@
#include "6LoWPAN/Thread/thread_management_internal.h"
#include "6LoWPAN/Thread/thread_management_client.h"
#include "6LoWPAN/Thread/thread_management_server.h"
#include "6LoWPAN/Thread/thread_resolution_server.h"
#include "6LoWPAN/Thread/thread_resolution_client.h"
#include "6LoWPAN/Thread/thread_address_registration_client.h"
#include "6LoWPAN/Thread/thread_resolution_client.h"
@ -226,6 +229,7 @@ int8_t thread_bootstrap_up(protocol_interface_info_entry_t *cur)
ret_val = nwk_6lowpan_up(cur);
cur->nwk_nd_re_scan_count = 0;
cur->thread_info->link_sync_allowed = true;
return ret_val;
}
@ -258,9 +262,11 @@ int8_t thread_bootstrap_down(protocol_interface_info_entry_t *cur)
thread_leader_mleid_rloc_map_to_nvm_write(cur);
thread_bootstrap_stop(cur);
mle_service_interface_unregister(cur->id);
thread_diagnostic_delete(cur->id); // delete before thread_management_server_delete as they share same coap_service id
thread_management_client_delete(cur->id); // delete before thread_management_server_delete as they share same coap_service id
thread_nd_service_disable(cur->id); // delete before thread_management_server_delete as they share same coap_service id
thread_management_server_delete(cur->id);
thread_joiner_application_deinit(cur->id);
thread_management_client_delete(cur->id);
//free network Data
thread_network_data_free_and_clean(&cur->thread_info->networkDataStorage);
//free local also here
@ -451,7 +457,7 @@ void thread_data_base_init(thread_info_t *thread_info, int8_t interfaceId)
thread_leader_commissioner_create(thread_info);
thread_info->rfc6775 = false;
thread_info->threadPrivatePrefixInfo.ulaValid = false;
thread_info->routerIdReqCoapID = 0;
thread_info->routerIdRequested = false;
thread_info->networkDataRequested = false;
thread_info->proactive_an_timer = 0;
@ -905,6 +911,7 @@ static void thread_child_update_req_timer(protocol_interface_info_entry_t *cur,
if (cur->thread_info->childUpdateReqTimer == -1) {
return;
}
if (cur->thread_info->childUpdateReqTimer > seconds) {
cur->thread_info->childUpdateReqTimer -= seconds;
} else {
@ -945,6 +952,20 @@ static void thread_key_switch_timer(protocol_interface_info_entry_t *cur, uint16
}
}
static void thread_maintenance_timer(protocol_interface_info_entry_t *cur, uint32_t seconds)
{
if (thread_info(cur)->thread_maintenance_timer) {
if (thread_info(cur)->thread_maintenance_timer > seconds) {
thread_info(cur)->thread_maintenance_timer -= seconds;
return;
}
}
thread_info(cur)->thread_maintenance_timer = THREAD_MAINTENANCE_TIMER_INTERVAL ;
thread_bootstrap_network_data_activate(cur);
}
void thread_seconds_timer(protocol_interface_info_entry_t *cur, uint32_t ticks)
{
uint8_t leader_address[16];
@ -1003,6 +1024,7 @@ void thread_seconds_timer(protocol_interface_info_entry_t *cur, uint32_t ticks)
}
thread_router_bootstrap_timer(cur, ticks);
thread_maintenance_timer(cur, ticks);
thread_border_router_seconds_timer(cur->id, ticks);
thread_bbr_seconds_timer(cur->id, ticks);
thread_lowpower_timer(cur, ticks);
@ -1201,7 +1223,8 @@ uint8_t *thread_route_option_write(protocol_interface_info_entry_t *cur, uint8_t
ptr, /* ptr to ID sequence (1 byte) */
ptr + 1, /* ptr to ID mask (MLE_ROUTE_ID_MASK_SIZE bytes) */
ptr + MLE_ROUTE_MIN_OPTION_LEN, /* ptr to router table data */
len_ptr) != 0) /* ptr to length */ { /* 0 -> SUCCESS */
len_ptr) != 0) { /* ptr to length */
/* 0 -> SUCCESS */
/* Point to beginning of buffer again */
ptr = saved_ptr;
} else {
@ -1720,9 +1743,104 @@ uint8_t *thread_leader_data_tlv_write(uint8_t *ptr, protocol_interface_info_entr
return ptr;
}
bool thread_addresses_needs_to_be_registered(protocol_interface_info_entry_t *cur)
{
lowpan_context_t *ctx;
uint8_t thread_realm_local_mcast_addr[16];
uint8_t thread_ll_unicast_prefix_based_mcast_addr[16];
if (thread_info(cur)->thread_device_mode != THREAD_DEVICE_MODE_SLEEPY_END_DEVICE &&
thread_info(cur)->thread_device_mode != THREAD_DEVICE_MODE_END_DEVICE) {
// No address registration for others than MED or SED
return false;
}
// check for addresses
ns_list_foreach(if_address_entry_t, e, &cur->ip_addresses) {
if (addr_ipv6_scope(e->address, cur) == IPV6_SCOPE_GLOBAL || (addr_ipv6_scope(e->address, cur) == IPV6_SCOPE_REALM_LOCAL
&& !thread_addr_is_mesh_local_16(e->address, cur))) {
ctx = lowpan_context_get_by_address(&cur->lowpan_contexts, e->address);
if (!ctx) {
return true;
}
if (ctx->cid != 0) {
return true;
}
}
}
// check for multicast groups
thread_bootstrap_all_nodes_address_generate(thread_realm_local_mcast_addr, cur->thread_info->threadPrivatePrefixInfo.ulaPrefix, IPV6_SCOPE_REALM_LOCAL);
thread_bootstrap_all_nodes_address_generate(thread_ll_unicast_prefix_based_mcast_addr, cur->thread_info->threadPrivatePrefixInfo.ulaPrefix, IPV6_SCOPE_LINK_LOCAL);
ns_list_foreach(if_group_entry_t, entry, &cur->ip_groups) {
if (!memcmp((entry->group), ADDR_MULTICAST_SOLICITED, 13)) {
/* Skip solicited node multicast address */
continue;
}
if (addr_ipv6_equal(entry->group, thread_realm_local_mcast_addr)) {
/* Skip well-known realm-local all Thread nodes multicast address */
continue;
}
if (addr_ipv6_equal(entry->group, thread_ll_unicast_prefix_based_mcast_addr)) {
/* Skip well-known link-local all Thread nodes multicast address */
continue;
}
if (addr_ipv6_equal(entry->group, ADDR_ALL_MPL_FORWARDERS)) {
/* Skip All MPL Forwarders address */
continue;
}
if (addr_ipv6_equal(entry->group, ADDR_REALM_LOCAL_ALL_NODES)) {
/* Skip Mesh local all nodes */
continue;
}
if (addr_ipv6_equal(entry->group, ADDR_REALM_LOCAL_ALL_ROUTERS)) {
/* Skip Mesh local all routers */
continue;
}
return true;
}
return false;
}
uint8_t *thread_ml_address_tlv_write(uint8_t *ptr, protocol_interface_info_entry_t *cur)
{
lowpan_context_t *ctx;
uint8_t *address_len_ptr;
if (thread_info(cur)->thread_device_mode != THREAD_DEVICE_MODE_SLEEPY_END_DEVICE &&
thread_info(cur)->thread_device_mode != THREAD_DEVICE_MODE_END_DEVICE) {
// No address registration for others than MED or SED
return ptr;
}
*ptr++ = MLE_TYPE_ADDRESS_REGISTRATION;
address_len_ptr = ptr++;
*address_len_ptr = 0;
ns_list_foreach(if_address_entry_t, e, &cur->ip_addresses) {
if (*address_len_ptr > 148) {
// Maximum length of address registrations
continue;
}
if (!thread_addr_is_mesh_local_16(e->address, cur)) {
ctx = lowpan_context_get_by_address(&cur->lowpan_contexts, e->address);
if (ctx && ctx->cid == 0) {
//Write TLV to list
*ptr++ = (ctx->cid | 0x80);
memcpy(ptr, e->address + 8, 8);
ptr += 8;
*address_len_ptr += 9;
}
}
}
return ptr;
}
uint8_t *thread_address_registration_tlv_write(uint8_t *ptr, protocol_interface_info_entry_t *cur)
{
uint8_t thread_realm_local_mcast_addr[16];
uint8_t thread_ll_unicast_prefix_based_mcast_addr[16];
lowpan_context_t *ctx;
uint8_t *address_len_ptr;
@ -1738,7 +1856,6 @@ uint8_t *thread_address_registration_tlv_write(uint8_t *ptr, protocol_interface_
// Register all global addressess
ns_list_foreach(if_address_entry_t, e, &cur->ip_addresses) {
if (*address_len_ptr > 148) {
// Maximum length of address registrations
continue;
@ -1762,23 +1879,26 @@ uint8_t *thread_address_registration_tlv_write(uint8_t *ptr, protocol_interface_
}
/* Registers multicast addresses to the parent */
thread_bootstrap_all_nodes_address_generate(thread_realm_local_mcast_addr, cur->thread_info->threadPrivatePrefixInfo.ulaPrefix, 3);
ns_list_foreach(if_group_entry_t, entry, &cur->ip_groups)
{
thread_bootstrap_all_nodes_address_generate(thread_realm_local_mcast_addr, cur->thread_info->threadPrivatePrefixInfo.ulaPrefix, IPV6_SCOPE_REALM_LOCAL);
thread_bootstrap_all_nodes_address_generate(thread_ll_unicast_prefix_based_mcast_addr, cur->thread_info->threadPrivatePrefixInfo.ulaPrefix, IPV6_SCOPE_LINK_LOCAL);
ns_list_foreach(if_group_entry_t, entry, &cur->ip_groups) {
if (*address_len_ptr > 148) {
// Maximum length of address registrations
continue;
}
if (addr_ipv6_multicast_scope(entry->group) < IPV6_SCOPE_REALM_LOCAL) {
/* Skip Link Local multicast address */
if (!memcmp((entry->group), ADDR_MULTICAST_SOLICITED, 13)) {
/* Skip solicited node multicast address */
continue;
}
if (addr_ipv6_equal(entry->group, thread_realm_local_mcast_addr)) {
/* Skip well-known realm-local all Thread nodes multicast address */
continue;
}
if (addr_ipv6_equal(entry->group, thread_ll_unicast_prefix_based_mcast_addr)) {
/* Skip well-known link-local all Thread nodes multicast address */
continue;
}
if (addr_ipv6_equal(entry->group, ADDR_ALL_MPL_FORWARDERS)) {
/* Skip All MPL Forwarders address */
continue;
@ -1899,14 +2019,17 @@ void thread_reset_neighbour_info(protocol_interface_info_entry_t *cur, mac_neigh
uint8_t thread_get_router_count_from_route_tlv(mle_tlv_info_t *routeTlv)
{
if (!routeTlv)
if (!routeTlv) {
return 0;
}
if (routeTlv->tlvLen < (MLE_ROUTE_ID_MASK_SIZE + 1))
if (routeTlv->tlvLen < (MLE_ROUTE_ID_MASK_SIZE + 1)) {
return 0;
}
if (!routeTlv->dataPtr)
if (!routeTlv->dataPtr) {
return 0;
}
return routeTlv->tlvLen - MLE_ROUTE_ID_MASK_SIZE - 1;
}
@ -1935,9 +2058,35 @@ static void thread_address_notification_cb(struct protocol_interface_info_entry
}
}
static bool thread_mcast_should_register_address(struct protocol_interface_info_entry *cur, uint8_t *addr)
{
uint8_t thread_realm_local_mcast_addr[16];
uint8_t thread_ll_unicast_prefix_based_mcast_addr[16];
if (addr_ipv6_multicast_scope(addr) < IPV6_SCOPE_LINK_LOCAL) {
return false;
}
if (memcmp(addr, ADDR_MULTICAST_SOLICITED, 13) == 0) {
return false;
}
if (memcmp(addr, ADDR_LINK_LOCAL_ALL_NODES, 16) == 0) {
return false;
}
if (memcmp(addr, ADDR_LINK_LOCAL_ALL_ROUTERS, 16) == 0) {
return false;
}
thread_bootstrap_all_nodes_address_generate(thread_realm_local_mcast_addr, cur->thread_info->threadPrivatePrefixInfo.ulaPrefix, IPV6_SCOPE_REALM_LOCAL);
if (memcmp(addr, thread_realm_local_mcast_addr, 16) == 0) {
return false;
}
thread_bootstrap_all_nodes_address_generate(thread_ll_unicast_prefix_based_mcast_addr, cur->thread_info->threadPrivatePrefixInfo.ulaPrefix, IPV6_SCOPE_LINK_LOCAL);
if (memcmp(addr, thread_ll_unicast_prefix_based_mcast_addr, 16) == 0) {
return false;
}
return true;
}
void thread_mcast_group_change(struct protocol_interface_info_entry *interface, if_group_entry_t *group, bool addr_added)
{
if (thread_attach_ready(interface) != 0) {
return;
}
@ -1946,7 +2095,7 @@ void thread_mcast_group_change(struct protocol_interface_info_entry *interface,
if (thread_bootstrap_should_register_address(interface)) {
/* Trigger Child Update Request only if MTD child's multicast address change */
if (addr_ipv6_multicast_scope(group->group) > IPV6_SCOPE_LINK_LOCAL) {
if (thread_mcast_should_register_address(interface, group->group)) {
interface->thread_info->childUpdateReqTimer = 1;
}
} else {
@ -1956,10 +2105,16 @@ void thread_mcast_group_change(struct protocol_interface_info_entry *interface,
}
}
static void thread_old_partition_data_clean(int8_t interface_id)
{
thread_management_client_old_partition_data_clean(interface_id);
thread_border_router_old_partition_data_clean(interface_id);
}
void thread_partition_data_purge(protocol_interface_info_entry_t *cur)
{
/* Partition has been changed. Wipe out data related to old partition */
thread_management_client_pending_coap_request_kill(cur->id);
thread_old_partition_data_clean(cur->id);
/* Reset previous routing information */
thread_routing_reset(&cur->thread_info->routing);
@ -1967,6 +2122,9 @@ void thread_partition_data_purge(protocol_interface_info_entry_t *cur)
/* Flush address cache */
ipv6_neighbour_cache_flush(&cur->ipv6_neighbour_cache);
/* Remove linked neighbours for REEDs and FEDs */
thread_reed_fed_neighbour_links_clean(cur);
}
bool thread_partition_match(protocol_interface_info_entry_t *cur, thread_leader_data_t *leaderData)
@ -1997,5 +2155,10 @@ void thread_neighbor_communication_update(protocol_interface_info_entry_t *cur,
thread_neighbor_last_communication_time_update(&cur->thread_info->neighbor_class, neighbor_attribute_index);
}
void thread_maintenance_timer_set(protocol_interface_info_entry_t *cur, uint16_t delay)
{
thread_info(cur)->thread_maintenance_timer = delay;
}
#endif

View File

@ -309,10 +309,10 @@ typedef struct thread_info_s {
uint16_t routerShortAddress;
uint16_t reedJitterTimer;
uint16_t reedMergeAdvTimer;
uint16_t routerIdReqCoapID; // COAP msg id of RouterID request
int16_t childUpdateReqTimer;
uint16_t childUpdateReqMsgId;
uint16_t proactive_an_timer;
uint16_t thread_maintenance_timer;
//uint8_t lastValidRouteMask[8];
int8_t interface_id; //Thread Interface ID
uint8_t version;
@ -322,11 +322,13 @@ typedef struct thread_info_s {
bool rfc6775: 1;
bool requestFullNetworkData: 1;
bool leaderCab: 1;
bool routerIdRequested: 1;
bool releaseRouterId: 1;
bool networkSynch: 1;
bool networkDataRequested: 1;
bool end_device_link_synch: 1;
bool router_mc_addrs_registered: 1;
bool link_sync_allowed: 1;
bool leader_synced: 1; // flag used by leader after restart
} thread_info_t;
@ -397,6 +399,11 @@ void thread_child_mcast_entries_remove(protocol_interface_info_entry_t *cur, con
uint8_t thread_leader_data_tlv_size(protocol_interface_info_entry_t *cur);
uint8_t *thread_leader_data_tlv_write(uint8_t *ptr, protocol_interface_info_entry_t *cur);
uint8_t *thread_address_registration_tlv_write(uint8_t *ptr, protocol_interface_info_entry_t *cur);
// returns true if SED/MED needs to register additional address to parent
bool thread_addresses_needs_to_be_registered(protocol_interface_info_entry_t *cur);
// write mesh local address tlv
uint8_t *thread_ml_address_tlv_write(uint8_t *ptr, protocol_interface_info_entry_t *cur);
int thread_link_reject_send(protocol_interface_info_entry_t *interface, const uint8_t *ll64);
thread_leader_info_t *thread_allocate_and_init_leader_private_data(void);
thread_route_cost_t thread_link_quality_to_cost(thread_link_quality_e quality);
@ -441,6 +448,7 @@ bool thread_partition_match(protocol_interface_info_entry_t *cur, thread_leader_
void thread_partition_info_update(protocol_interface_info_entry_t *cur, thread_leader_data_t *leaderData);
void thread_neighbor_communication_update(protocol_interface_info_entry_t *cur, uint8_t neighbor_attribute_index);
bool thread_stable_context_check(protocol_interface_info_entry_t *cur, buffer_t *buf);
void thread_maintenance_timer_set(protocol_interface_info_entry_t *cur, uint16_t delay);
#else // HAVE_THREAD
NS_DUMMY_DEFINITIONS_OK

View File

@ -326,6 +326,17 @@
*/
#define THREAD_BBR_ROUTER_ID_REQUEST_STATUS THREAD_COAP_STATUS_TLV_HAVE_CHILD_ID_REQUEST
/*
* Number of destination and neighbor cache entries assuming 250 thread devices (worst case) connecting to cloud service.
* Six entries reserved for backbone devices.
*/
#define THREAD_BBR_IPV6_DESTINATION_CACHE_SIZE 256
/*
* Timeout to solicit address from DHCP if previous request fails.
*/
#define THREAD_MAINTENANCE_TIMER_INTERVAL 300
/**
* Build time flag to enable THCI special traces for test harness purposes
*/

View File

@ -145,6 +145,7 @@
#define THREAD_DEFAULT_KEY_SWITCH_GUARD_TIME 624 // Hours
#define THREAD_DEFAULT_KEY_ROTATION 672 // Hours
#define THREAD_COMMISSIONER_KEEP_ALIVE_INTERVAL 50000 // Default thread commissioner keep-alive message interval (milliseconds)
#define THREAD_DELAY_JOIN_ENT 50 // Minimum delay for Joiner router before sending joiner entrust (milliseconds)
#define THREAD_FAILED_CHILD_TRANSMISSIONS 4
#define THREAD_FAILED_ROUTER_TRANSMISSIONS 4

View File

@ -1,98 +0,0 @@
/*
* Copyright (c) 2014-2015, 2017, Arm Limited and affiliates.
* SPDX-License-Identifier: BSD-3-Clause
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holder nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef SOURCE_6LOWPAN_THREAD_THREAD_DHCPV6_CLIENT_H_
#define SOURCE_6LOWPAN_THREAD_THREAD_DHCPV6_CLIENT_H_
#include <ns_types.h>
/* Thread DHCP client implementation.
*
* Responsibilities of this module are:
* - send router id address request and receive new router address and inform it to thread bootstrap.
* - handle Global address queries and refresh inside thread network.
*
*/
/* Initialize dhcp thread dhcp client.
*
* This instance needs to bee initialized once for each thread network interface.
* if only one thread instance is supported this is needed to call only once.
*
* /param interface interface id of this thread instance.
*
*/
void thread_dhcp_client_init(int8_t interface);
/* Delete dhcp thread dhcp client.
*
* When this is called all addressed assigned by this module are removed from stack.
*/
void thread_dhcp_client_delete(int8_t interface);
/* Global address handler.
*
* This module updates the addresses from dhcp server and sets them in stack.
* this module makes refresh of address when needed.
*
*/
/* give dhcp server and prefix for global address assignment
*
* /param interface interface where address is got
* /param dhcp_addr dhcp server ML16 address where address is registered.
* /param prefix dhcp server ML16 address where address is registered.
* /param mac64 64 bit mac address for identifieng client.
* /param error_cb error callback that is called if address cannot be created or becomes invalid.
* /param register_status true if address registered.
*
*/
typedef void (thread_dhcp_client_global_adress_cb)(int8_t interface, uint8_t dhcp_addr[static 16], uint8_t prefix[static 16], bool register_status);
int thread_dhcp_client_get_global_address(int8_t interface, uint8_t dhcp_addr[static 16], uint8_t prefix[static 16], uint8_t mac64[static 8], thread_dhcp_client_global_adress_cb *error_cb);
/* Renew all leased adddresses might be used when short address changes
*
* /param interface interface where address is got
*/
void thread_dhcp_client_global_address_renew(int8_t interface);
/* Delete address from device
* if prefix is NULL all are deleted
*
* /param interface interface where address is got
* /param prefix dhcp server ML16 address where address is registered.
*
*/
void thread_dhcp_client_global_address_delete(int8_t interface, uint8_t dhcp_addr[static 16], uint8_t prefix[static 16]);
#endif /* SOURCE_6LOWPAN_THREAD_THREAD_DHCPV6_CLIENT_H_ */

View File

@ -0,0 +1,114 @@
/*
* Copyright (c) 2018, Arm Limited and affiliates.
* SPDX-License-Identifier: BSD-3-Clause
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holder nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include "nsconfig.h"
#if defined(HAVE_THREAD) && defined(HAVE_DHCPV6_SERVER)
#include <string.h>
#include <ns_types.h>
#include "eventOS_event.h"
#include "eventOS_event_timer.h"
#include "common_functions.h"
#include "ns_trace.h"
#include "NWK_INTERFACE/Include/protocol.h"
#include "ipv6_stack/protocol_ipv6.h"
#include "Common_Protocols/ipv6_constants.h"
#include "Common_Protocols/ipv6.h"
#include "DHCPv6_Server/DHCPv6_server_service.h"
#include "6LoWPAN/Thread/thread_bbr_api_internal.h"
#define TRACE_GROUP "thds"
static void thread_service_remove_GUA_from_neighcache(protocol_interface_info_entry_t *cur, uint8_t *targetAddress)
{
ipv6_neighbour_t *neighbour_entry;
neighbour_entry = ipv6_neighbour_lookup(&cur->ipv6_neighbour_cache, targetAddress);
if (neighbour_entry) {
tr_debug("Remove from neigh Cache: %s", tr_ipv6(targetAddress));
ipv6_neighbour_entry_remove(&cur->ipv6_neighbour_cache, neighbour_entry);
}
}
static void thread_dhcp_address_prefer_remove_cb(int8_t interfaceId, uint8_t *targetAddress, void *prefix_info)
{
protocol_interface_info_entry_t *curPtr = protocol_stack_interface_info_get_by_id(interfaceId);
if (!curPtr) {
return;
}
if (!targetAddress) {
//Clear All targets routes
ipv6_route_table_remove_info(interfaceId, ROUTE_THREAD_PROXIED_HOST, prefix_info);
} else {
tr_debug("Address Preferred Timeout");
ipv6_route_delete(targetAddress, 128, interfaceId, NULL, ROUTE_THREAD_PROXIED_HOST);
thread_service_remove_GUA_from_neighcache(curPtr, targetAddress);
}
}
static bool thread_dhcp_address_add_cb(int8_t interfaceId, dhcp_address_cache_update_t *address_info, void *route_src)
{
protocol_interface_info_entry_t *curPtr = protocol_stack_interface_info_get_by_id(interfaceId);
if (!curPtr) {
return false;
}
// If this is solicit from existing address, flush ND cache.
if (address_info->allocatedNewAddress) {
// coverity[returned_null] for ignoring protocol_stack_interface_info_get_by_id NULL return
thread_service_remove_GUA_from_neighcache(curPtr, address_info->allocatedAddress);
}
if (thread_bbr_nd_entry_add(interfaceId, address_info->allocatedAddress, address_info->validLifeTime, route_src) == -1) {
// No nanostack BBR present we will put entry for application implemented BBR
ipv6_route_t *route = ipv6_route_add_with_info(address_info->allocatedAddress, 128, interfaceId, NULL, ROUTE_THREAD_PROXIED_HOST, route_src, 0, address_info->validLifeTime, 0);
if (!route) {
return false;
}
}
return true;
}
int thread_dhcp6_server_init(int8_t interface_id, uint8_t prefix[8], uint8_t eui64[8], uint32_t validLifeTimne)
{
if (DHCPv6_server_service_init(interface_id, prefix, eui64, DHCPV6_DUID_HARDWARE_EUI64_TYPE) != 0) {
return -1;
}
//Register Callbacks
DHCPv6_server_service_callback_set(interface_id, prefix, thread_dhcp_address_prefer_remove_cb, thread_dhcp_address_add_cb);
//SET Timeout
DHCPv6_server_service_set_address_validlifetime(interface_id, prefix, validLifeTimne);
return 0;
}
#endif

View File

@ -0,0 +1,39 @@
/*
* Copyright (c) 2018, Arm Limited and affiliates.
* SPDX-License-Identifier: BSD-3-Clause
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holder nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef THREAD_DHCPV6_SERVER_H_
#define THREAD_DHCPV6_SERVER_H_
#if defined(HAVE_THREAD) && defined(HAVE_DHCPV6_SERVER)
int thread_dhcp6_server_init(int8_t interface_id, uint8_t prefix[8], uint8_t eui64[8], uint32_t validLifeTimne);
#else
#define thread_dhcp6_server_init(interface_id, prefix, eui64, validLifeTimne) (-1)
#endif
#endif /* THREAD_DHCPV6_SERVER_H_ */

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