Merge branch 'prepare_for_mbedos511' of ssh://github.com/artokin/mbed-os into rollup-b.1

pull/8763/head
Cruz Monrreal II 2018-11-15 18:26:12 -06:00
commit 49b940c9a7
300 changed files with 8859 additions and 6858 deletions

View File

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

View File

@ -98,7 +98,7 @@ void randLIB_seed_random(void)
/* Spell out expressions so we get known ordering of 4 seed calls */ /* Spell out expressions so we get known ordering of 4 seed calls */
uint64_t s = (uint64_t) arm_random_seed_get() << 32; uint64_t s = (uint64_t) arm_random_seed_get() << 32;
state[0] ^= ( s | arm_random_seed_get()); state[0] ^= (s | arm_random_seed_get());
s = (uint64_t) arm_random_seed_get() << 32; s = (uint64_t) arm_random_seed_get() << 32;
state[1] ^= s | arm_random_seed_get(); state[1] ^= s | arm_random_seed_get();
@ -129,19 +129,19 @@ void randLIB_add_seed(uint64_t seed)
uint8_t randLIB_get_8bit(void) uint8_t randLIB_get_8bit(void)
{ {
uint64_t r = randLIB_get_64bit(); uint64_t r = randLIB_get_64bit();
return (uint8_t) (r >> 56); return (uint8_t)(r >> 56);
} }
uint16_t randLIB_get_16bit(void) uint16_t randLIB_get_16bit(void)
{ {
uint64_t r = randLIB_get_64bit(); uint64_t r = randLIB_get_64bit();
return (uint16_t) (r >> 48); return (uint16_t)(r >> 48);
} }
uint32_t randLIB_get_32bit(void) uint32_t randLIB_get_32bit(void)
{ {
uint64_t r = randLIB_get_64bit(); uint64_t r = randLIB_get_64bit();
return (uint32_t) (r >> 32); return (uint32_t)(r >> 32);
} }

View File

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

View File

@ -6,7 +6,7 @@
#include "CppUTest/TestPlugin.h" #include "CppUTest/TestPlugin.h"
#include "CppUTest/TestRegistry.h" #include "CppUTest/TestRegistry.h"
#include "CppUTestExt/MockSupportPlugin.h" #include "CppUTestExt/MockSupportPlugin.h"
int main(int ac, char** av) int main(int ac, char **av)
{ {
return CommandLineTestRunner::RunAllTests(ac, av); return CommandLineTestRunner::RunAllTests(ac, av);
} }

View File

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

View File

@ -18,9 +18,9 @@ bool test_randLIB_get_8bit()
randLIB_reset(); randLIB_reset();
randLIB_seed_random(); randLIB_seed_random();
uint8_t test = randLIB_get_8bit(); uint8_t test = randLIB_get_8bit();
if( test == 0 ) { if (test == 0) {
test = randLIB_get_8bit(); test = randLIB_get_8bit();
if( test == 0 ) { if (test == 0) {
return false; return false;
} }
} }
@ -32,9 +32,9 @@ bool test_randLIB_get_16bit()
randLIB_reset(); randLIB_reset();
randLIB_seed_random(); randLIB_seed_random();
uint16_t test = randLIB_get_16bit(); uint16_t test = randLIB_get_16bit();
if( test == 0 ) { if (test == 0) {
test = randLIB_get_16bit(); test = randLIB_get_16bit();
if( test == 0 ) { if (test == 0) {
return false; return false;
} }
} }
@ -46,9 +46,9 @@ bool test_randLIB_get_32bit()
randLIB_reset(); randLIB_reset();
randLIB_seed_random(); randLIB_seed_random();
uint32_t test = randLIB_get_32bit(); uint32_t test = randLIB_get_32bit();
if( test == 0 ) { if (test == 0) {
test = randLIB_get_32bit(); test = randLIB_get_32bit();
if( test == 0 ) { if (test == 0) {
return false; return false;
} }
} }
@ -145,7 +145,7 @@ bool test_randLIB_get_n_bytes_random()
uint8_t dat[5]; uint8_t dat[5];
void *ret = randLIB_get_n_bytes_random(dat, 5); void *ret = randLIB_get_n_bytes_random(dat, 5);
if(ret != dat){ if (ret != dat) {
return false; return false;
} }
@ -164,12 +164,12 @@ bool test_randLIB_get_random_in_range()
randLIB_seed_random(); randLIB_seed_random();
uint16_t ret = randLIB_get_random_in_range(2, 2); uint16_t ret = randLIB_get_random_in_range(2, 2);
if( ret != 2 ){ if (ret != 2) {
return false; return false;
} }
ret = randLIB_get_random_in_range(2, 3); ret = randLIB_get_random_in_range(2, 3);
if( ret != 2 && ret != 3){ if (ret != 2 && ret != 3) {
return false; return false;
} }
@ -183,12 +183,12 @@ bool test_randLIB_randomise_base()
randLIB_reset(); randLIB_reset();
randLIB_seed_random(); randLIB_seed_random();
uint32_t ret = randLIB_randomise_base(0,0,0); uint32_t ret = randLIB_randomise_base(0, 0, 0);
if( ret ){ if (ret) {
return false; return false;
} }
ret = randLIB_randomise_base(0xffff0000,0x8888,0x8888); ret = randLIB_randomise_base(0xffff0000, 0x8888, 0x8888);
if( ret != 0xffffffff ){ if (ret != 0xffffffff) {
return false; return false;
} }
return true; return true;

View File

@ -8,17 +8,17 @@ bool allow_open = true;
int __real_open(const char *path, int flags, ...); int __real_open(const char *path, int flags, ...);
int __wrap_open(const char *path, int flags, ...) int __wrap_open(const char *path, int flags, ...)
{ {
if (allow_open) { if (allow_open) {
if (flags & O_CREAT) { if (flags & O_CREAT) {
va_list vl; va_list vl;
va_start(vl,flags); va_start(vl, flags);
mode_t mode = va_arg(vl, mode_t); mode_t mode = va_arg(vl, mode_t);
va_end(vl); va_end(vl);
return __real_open(path, flags, mode); return __real_open(path, flags, mode);
} else { } else {
return __real_open(path, flags); return __real_open(path, flags);
} }
} else { } else {
return -1; return -1;
} }
} }

View File

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

View File

@ -107,6 +107,43 @@ Set the output function, `printf` by default:
mbed_trace_print_function_set(printf) 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 ### 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: 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

@ -180,11 +180,11 @@ extern "C" {
* Initialize trace functionality * Initialize trace functionality
* @return 0 when all success, otherwise non zero * @return 0 when all success, otherwise non zero
*/ */
int mbed_trace_init( void ); int mbed_trace_init(void);
/** /**
* Free trace memory * Free trace memory
*/ */
void mbed_trace_free( void ); void mbed_trace_free(void);
/** /**
* Resize buffers (line / tmp ) sizes * Resize buffers (line / tmp ) sizes
* @param lineLength new maximum length for trace line (0 = do no resize) * @param lineLength new maximum length for trace line (0 = do no resize)
@ -226,7 +226,7 @@ uint8_t mbed_trace_config_get(void);
* char* trace_time(){ return "rtc-time-in-string"; } * char* trace_time(){ return "rtc-time-in-string"; }
* mbed_trace_prefix_function_set( &trace_time ); * mbed_trace_prefix_function_set( &trace_time );
*/ */
void mbed_trace_prefix_function_set( char* (*pref_f)(size_t) ); void mbed_trace_prefix_function_set(char *(*pref_f)(size_t));
/** /**
* Set trace suffix function * Set trace suffix function
* suffix -function return string with null terminated * suffix -function return string with null terminated
@ -235,18 +235,18 @@ void mbed_trace_prefix_function_set( char* (*pref_f)(size_t) );
* char* trace_suffix(){ return " END"; } * char* trace_suffix(){ return " END"; }
* mbed_trace_suffix_function_set( &trace_suffix ); * mbed_trace_suffix_function_set( &trace_suffix );
*/ */
void mbed_trace_suffix_function_set(char* (*suffix_f)(void) ); void mbed_trace_suffix_function_set(char *(*suffix_f)(void));
/** /**
* Set trace print function * Set trace print function
* By default, trace module print using printf() function, * By default, trace module print using printf() function,
* but with this you can write own print function, * but with this you can write own print function,
* for e.g. to other IO device. * for e.g. to other IO device.
*/ */
void mbed_trace_print_function_set( void (*print_f)(const char*) ); void mbed_trace_print_function_set(void (*print_f)(const char *));
/** /**
* Set trace print function for tr_cmdline() * Set trace print function for tr_cmdline()
*/ */
void mbed_trace_cmdprint_function_set( void (*printf)(const char*) ); void mbed_trace_cmdprint_function_set(void (*printf)(const char *));
/** /**
* Set trace mutex wait function * Set trace mutex wait function
* By default, trace calls are not thread safe. * By default, trace calls are not thread safe.
@ -270,10 +270,10 @@ void mbed_trace_mutex_release_function_set(void (*mutex_release_f)(void));
* mbed_trace_exclude_filters_set("mygr"); * mbed_trace_exclude_filters_set("mygr");
* mbed_tracef(TRACE_ACTIVE_LEVEL_DEBUG, "ougr", "This is not printed"); * mbed_tracef(TRACE_ACTIVE_LEVEL_DEBUG, "ougr", "This is not printed");
*/ */
void mbed_trace_exclude_filters_set(char* filters); void mbed_trace_exclude_filters_set(char *filters);
/** get trace exclude filters /** get trace exclude filters
*/ */
const char* mbed_trace_exclude_filters_get(void); const char *mbed_trace_exclude_filters_get(void);
/** /**
* When trace group contains text in filter, * When trace group contains text in filter,
* trace will be printed. * trace will be printed.
@ -282,10 +282,10 @@ const char* mbed_trace_exclude_filters_get(void);
* mbed_tracef(TRACE_ACTIVE_LEVEL_DEBUG, "mygr", "Hi There"); * mbed_tracef(TRACE_ACTIVE_LEVEL_DEBUG, "mygr", "Hi There");
* mbed_tracef(TRACE_ACTIVE_LEVEL_DEBUG, "grp2", "This is not printed"); * mbed_tracef(TRACE_ACTIVE_LEVEL_DEBUG, "grp2", "This is not printed");
*/ */
void mbed_trace_include_filters_set(char* filters); void mbed_trace_include_filters_set(char *filters);
/** get trace include filters /** get trace include filters
*/ */
const char* mbed_trace_include_filters_get(void); const char *mbed_trace_include_filters_get(void);
/** /**
* General trace function * General trace function
* This should be used every time when user want to print out something important thing * This should be used every time when user want to print out something important thing
@ -298,9 +298,9 @@ const char* mbed_trace_include_filters_get(void);
* @param ... variable arguments related to fmt * @param ... variable arguments related to fmt
*/ */
#if defined(__GNUC__) || defined(__CC_ARM) #if defined(__GNUC__) || defined(__CC_ARM)
void mbed_tracef(uint8_t dlevel, const char* grp, const char *fmt, ...) __attribute__ ((__format__(__printf__, 3, 4))); void mbed_tracef(uint8_t dlevel, const char *grp, const char *fmt, ...) __attribute__((__format__(__printf__, 3, 4)));
#else #else
void mbed_tracef(uint8_t dlevel, const char* grp, const char *fmt, ...); void mbed_tracef(uint8_t dlevel, const char *grp, const char *fmt, ...);
#endif #endif
/** /**
* General trace function * General trace function
@ -318,16 +318,16 @@ void mbed_tracef(uint8_t dlevel, const char* grp, const char *fmt, ...);
* @param ap variable arguments list (like vprintf) * @param ap variable arguments list (like vprintf)
*/ */
#if defined(__GNUC__) || defined(__CC_ARM) #if defined(__GNUC__) || defined(__CC_ARM)
void mbed_vtracef(uint8_t dlevel, const char* grp, const char *fmt, va_list ap) __attribute__ ((__format__(__printf__, 3, 0))); void mbed_vtracef(uint8_t dlevel, const char *grp, const char *fmt, va_list ap) __attribute__((__format__(__printf__, 3, 0)));
#else #else
void mbed_vtracef(uint8_t dlevel, const char* grp, const char *fmt, va_list ap); void mbed_vtracef(uint8_t dlevel, const char *grp, const char *fmt, va_list ap);
#endif #endif
/** /**
* Get last trace from buffer * Get last trace from buffer
*/ */
const char* mbed_trace_last(void); const char *mbed_trace_last(void);
#if MBED_CONF_MBED_TRACE_FEA_IPV6 == 1 #if MBED_CONF_MBED_TRACE_FEA_IPV6 == 1
/** /**
* mbed_tracef helping function for convert ipv6 * mbed_tracef helping function for convert ipv6
@ -339,7 +339,7 @@ const char* mbed_trace_last(void);
* @param add_ptr IPv6 Address pointer * @param add_ptr IPv6 Address pointer
* @return temporary buffer where ipv6 is in string format * @return temporary buffer where ipv6 is in string format
*/ */
char* mbed_trace_ipv6(const void *addr_ptr); char *mbed_trace_ipv6(const void *addr_ptr);
/** /**
* mbed_tracef helping function for print ipv6 prefix * mbed_tracef helping function for print ipv6 prefix
* usage e.g. * usage e.g.
@ -350,7 +350,7 @@ char* mbed_trace_ipv6(const void *addr_ptr);
* @param prefix_len prefix length * @param prefix_len prefix length
* @return temporary buffer where ipv6 is in string format * @return temporary buffer where ipv6 is in string format
*/ */
char* mbed_trace_ipv6_prefix(const uint8_t *prefix, uint8_t prefix_len); char *mbed_trace_ipv6_prefix(const uint8_t *prefix, uint8_t prefix_len);
#endif #endif
/** /**
* mbed_tracef helping function for convert hex-array to string. * mbed_tracef helping function for convert hex-array to string.
@ -364,7 +364,7 @@ char* mbed_trace_ipv6_prefix(const uint8_t *prefix, uint8_t prefix_len);
* if array as string not fit to temp buffer, this function write '*' as last character, * if array as string not fit to temp buffer, this function write '*' as last character,
* which indicate that buffer is too small for array. * which indicate that buffer is too small for array.
*/ */
char* mbed_trace_array(const uint8_t* buf, uint16_t len); char *mbed_trace_array(const uint8_t *buf, uint16_t len);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -5,6 +5,12 @@
"help": "Used to globally enable traces.", "help": "Used to globally enable traces.",
"value": null "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": { "fea-ipv6": {
"help": "Used to globally disable ipv6 tracing features.", "help": "Used to globally disable ipv6 tracing features.",
"value": null "value": null

View File

@ -93,7 +93,7 @@
#endif #endif
/** default print function, just redirect str to printf */ /** default print function, just redirect str to printf */
static void mbed_trace_realloc( char **buffer, int *length_ptr, int new_length); static void mbed_trace_realloc(char **buffer, int *length_ptr, int new_length);
static void mbed_trace_default_print(const char *str); static void mbed_trace_default_print(const char *str);
static void mbed_trace_reset_tmp(void); static void mbed_trace_reset_tmp(void);
@ -209,7 +209,7 @@ void mbed_trace_free(void)
m_trace.mutex_release_f = 0; m_trace.mutex_release_f = 0;
m_trace.mutex_lock_count = 0; m_trace.mutex_lock_count = 0;
} }
static void mbed_trace_realloc( char **buffer, int *length_ptr, int new_length) static void mbed_trace_realloc(char **buffer, int *length_ptr, int new_length)
{ {
MBED_TRACE_MEM_FREE(*buffer); MBED_TRACE_MEM_FREE(*buffer);
*buffer = MBED_TRACE_MEM_ALLOC(new_length); *buffer = MBED_TRACE_MEM_ALLOC(new_length);
@ -217,11 +217,11 @@ static void mbed_trace_realloc( char **buffer, int *length_ptr, int new_length)
} }
void mbed_trace_buffer_sizes(int lineLength, int tmpLength) void mbed_trace_buffer_sizes(int lineLength, int tmpLength)
{ {
if( lineLength > 0 ) { if (lineLength > 0) {
mbed_trace_realloc( &(m_trace.line), &m_trace.line_length, lineLength ); mbed_trace_realloc(&(m_trace.line), &m_trace.line_length, lineLength);
} }
if( tmpLength > 0 ) { if (tmpLength > 0) {
mbed_trace_realloc( &(m_trace.tmp_data), &m_trace.tmp_data_length, tmpLength); mbed_trace_realloc(&(m_trace.tmp_data), &m_trace.tmp_data_length, tmpLength);
mbed_trace_reset_tmp(); mbed_trace_reset_tmp();
} }
} }
@ -311,9 +311,9 @@ void mbed_tracef(uint8_t dlevel, const char *grp, const char *fmt, ...)
mbed_vtracef(dlevel, grp, fmt, ap); mbed_vtracef(dlevel, grp, fmt, ap);
va_end(ap); va_end(ap);
} }
void mbed_vtracef(uint8_t dlevel, const char* grp, const char *fmt, va_list ap) void mbed_vtracef(uint8_t dlevel, const char *grp, const char *fmt, va_list ap)
{ {
if ( m_trace.mutex_wait_f ) { if (m_trace.mutex_wait_f) {
m_trace.mutex_wait_f(); m_trace.mutex_wait_f();
m_trace.mutex_lock_count++; m_trace.mutex_lock_count++;
} }
@ -476,7 +476,7 @@ void mbed_vtracef(uint8_t dlevel, const char* grp, const char *fmt, va_list ap)
} }
end: end:
if ( m_trace.mutex_release_f ) { if (m_trace.mutex_release_f) {
// Store the mutex lock count to temp variable so that it won't get // Store the mutex lock count to temp variable so that it won't get
// clobbered during last loop iteration when mutex gets released // clobbered during last loop iteration when mutex gets released
int count = m_trace.mutex_lock_count; int count = m_trace.mutex_lock_count;
@ -507,7 +507,7 @@ const char *mbed_trace_last(void)
char *mbed_trace_ipv6(const void *addr_ptr) char *mbed_trace_ipv6(const void *addr_ptr)
{ {
/** Acquire mutex. It is released before returning from mbed_vtracef. */ /** Acquire mutex. It is released before returning from mbed_vtracef. */
if ( m_trace.mutex_wait_f ) { if (m_trace.mutex_wait_f) {
m_trace.mutex_wait_f(); m_trace.mutex_wait_f();
m_trace.mutex_lock_count++; m_trace.mutex_lock_count++;
} }
@ -528,7 +528,7 @@ char *mbed_trace_ipv6(const void *addr_ptr)
char *mbed_trace_ipv6_prefix(const uint8_t *prefix, uint8_t prefix_len) char *mbed_trace_ipv6_prefix(const uint8_t *prefix, uint8_t prefix_len)
{ {
/** Acquire mutex. It is released before returning from mbed_vtracef. */ /** Acquire mutex. It is released before returning from mbed_vtracef. */
if ( m_trace.mutex_wait_f ) { if (m_trace.mutex_wait_f) {
m_trace.mutex_wait_f(); m_trace.mutex_wait_f();
m_trace.mutex_lock_count++; m_trace.mutex_lock_count++;
} }
@ -551,7 +551,7 @@ char *mbed_trace_ipv6_prefix(const uint8_t *prefix, uint8_t prefix_len)
char *mbed_trace_array(const uint8_t *buf, uint16_t len) char *mbed_trace_array(const uint8_t *buf, uint16_t len)
{ {
/** Acquire mutex. It is released before returning from mbed_vtracef. */ /** Acquire mutex. It is released before returning from mbed_vtracef. */
if ( m_trace.mutex_wait_f ) { if (m_trace.mutex_wait_f) {
m_trace.mutex_wait_f(); m_trace.mutex_wait_f();
m_trace.mutex_lock_count++; m_trace.mutex_lock_count++;
} }
@ -581,7 +581,7 @@ char *mbed_trace_array(const uint8_t *buf, uint16_t len)
wptr += retval; wptr += retval;
} }
if (wptr > str) { if (wptr > str) {
if( overflow ) { if (overflow) {
// replace last character as 'star', // replace last character as 'star',
// which indicate buffer len is not enough // which indicate buffer len is not enough
*(wptr - 1) = '*'; *(wptr - 1) = '*';

View File

@ -30,101 +30,107 @@ static int mutex_release_count = 0;
static bool check_mutex_lock_status = true; static bool check_mutex_lock_status = true;
void my_mutex_wait() void my_mutex_wait()
{ {
mutex_wait_count++; mutex_wait_count++;
} }
void my_mutex_release() void my_mutex_release()
{ {
mutex_release_count++; mutex_release_count++;
} }
char buf[1024]; char buf[1024];
#include <stdio.h> #include <stdio.h>
void myprint(const char* str) void myprint(const char *str)
{ {
if ( check_mutex_lock_status ) { if (check_mutex_lock_status) {
CHECK( (mutex_wait_count - mutex_release_count) > 0 ); CHECK((mutex_wait_count - mutex_release_count) > 0);
} }
strcpy(buf, str); strcpy(buf, str);
} }
TEST_GROUP(trace) TEST_GROUP(trace)
{ {
void setup() void setup() {
{
mbed_trace_init(); mbed_trace_init();
mbed_trace_config_set(TRACE_MODE_PLAIN|TRACE_ACTIVE_LEVEL_ALL); mbed_trace_config_set(TRACE_MODE_PLAIN | TRACE_ACTIVE_LEVEL_ALL);
mbed_trace_print_function_set( myprint ); mbed_trace_print_function_set(myprint);
mbed_trace_mutex_wait_function_set( my_mutex_wait ); mbed_trace_mutex_wait_function_set(my_mutex_wait);
mbed_trace_mutex_release_function_set( my_mutex_release ); 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
CHECK(mutex_wait_count == mutex_release_count); // Check the mutex count with every test mbed_trace_free();
mbed_trace_free(); }
}
}; };
/* Unity test code starts */ /* Unity test code starts */
TEST(trace, MutexNotSet) TEST(trace, MutexNotSet)
{ {
mbed_trace_mutex_wait_function_set( 0 ); mbed_trace_mutex_wait_function_set(0);
mbed_trace_mutex_release_function_set( 0 ); mbed_trace_mutex_release_function_set(0);
int mutex_call_count_at_entry = mutex_wait_count; int mutex_call_count_at_entry = mutex_wait_count;
check_mutex_lock_status = false; check_mutex_lock_status = false;
char expectedStr[] = "Hello hello!"; char expectedStr[] = "Hello hello!";
mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "Hello hello!"); mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "Hello hello!");
STRCMP_EQUAL(expectedStr, buf); STRCMP_EQUAL(expectedStr, buf);
CHECK( mutex_call_count_at_entry == mutex_wait_count ); CHECK(mutex_call_count_at_entry == mutex_wait_count);
CHECK( mutex_call_count_at_entry == mutex_release_count ); CHECK(mutex_call_count_at_entry == mutex_release_count);
mbed_trace_mutex_wait_function_set( my_mutex_wait ); mbed_trace_mutex_wait_function_set(my_mutex_wait);
mbed_trace_mutex_release_function_set( my_mutex_release ); mbed_trace_mutex_release_function_set(my_mutex_release);
check_mutex_lock_status = true; check_mutex_lock_status = true;
} }
TEST(trace, Array) TEST(trace, Array)
{ {
unsigned char longStr[200] = {0x66}; unsigned char longStr[200] = {0x66};
for(int i=0;i<200;i++) {longStr[i] = 0x66; } for (int i = 0; i < 200; i++) {
mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "%s", mbed_trace_array(longStr, 200) ); longStr[i] = 0x66;
}
mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "%s", mbed_trace_array(longStr, 200));
} }
TEST(trace, Null0Array) TEST(trace, Null0Array)
{ {
static const unsigned char array[2] = { 0x23, 0x45 }; static const unsigned char array[2] = { 0x23, 0x45 };
mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "%s", mbed_trace_array(array, 2)); mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "%s", mbed_trace_array(array, 2));
STRCMP_EQUAL("23:45", buf); STRCMP_EQUAL("23:45", buf);
mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "%s", mbed_trace_array(array, 0)); mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "%s", mbed_trace_array(array, 0));
STRCMP_EQUAL("", buf); STRCMP_EQUAL("", buf);
mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "%s", mbed_trace_array(NULL, 0)); mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "%s", mbed_trace_array(NULL, 0));
STRCMP_EQUAL("", buf); STRCMP_EQUAL("", buf);
mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "%s", mbed_trace_array(NULL, 2)); mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "%s", mbed_trace_array(NULL, 2));
STRCMP_EQUAL("<null>", buf); STRCMP_EQUAL("<null>", buf);
} }
TEST(trace, LongString) TEST(trace, LongString)
{ {
char longStr[1000] = {0x36}; char longStr[1000] = {0x36};
for(int i=0;i<999;i++) {longStr[i] = 0x36; } for (int i = 0; i < 999; i++) {
mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "%s", longStr ); longStr[i] = 0x36;
}
mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "%s", longStr);
} }
TEST(trace, TooLong) TEST(trace, TooLong)
{ {
#define TOO_LONG_SIZE 9400 #define TOO_LONG_SIZE 9400
#define TRACE_LINE_SIZE 1024 #define TRACE_LINE_SIZE 1024
char longStr[TOO_LONG_SIZE] = {0}; 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 );
mbed_trace_config_set(TRACE_ACTIVE_LEVEL_ALL);
char shouldStr[TRACE_LINE_SIZE] = "[DBG ][mygr]: "; mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "%s", longStr);
for(int i=14;i<TRACE_LINE_SIZE;i++) { shouldStr[i] = 0x36; }
shouldStr[TRACE_LINE_SIZE-1] = 0; char shouldStr[TRACE_LINE_SIZE] = "[DBG ][mygr]: ";
STRCMP_EQUAL(shouldStr, buf); for (int i = 14; i < TRACE_LINE_SIZE; i++) {
shouldStr[i] = 0x36;
}
shouldStr[TRACE_LINE_SIZE - 1] = 0;
STRCMP_EQUAL(shouldStr, buf);
} }
TEST(trace, BufferResize) TEST(trace, BufferResize)
@ -139,7 +145,7 @@ TEST(trace, BufferResize)
mbed_trace_buffer_sizes(0, 15); mbed_trace_buffer_sizes(0, 15);
STRCMP_EQUAL("30:30:30:30", mbed_trace_array(arr, 4)); STRCMP_EQUAL("30:30:30:30", mbed_trace_array(arr, 4));
const char * expectedStr = "0123456789"; const char *expectedStr = "0123456789";
mbed_trace_buffer_sizes(11, 0); mbed_trace_buffer_sizes(11, 0);
mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "01234567890123456789"); mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "01234567890123456789");
STRCMP_EQUAL(expectedStr, buf); STRCMP_EQUAL(expectedStr, buf);
@ -159,16 +165,16 @@ TEST(trace, PreInitConfiguration)
memset(arr, '0', 20); memset(arr, '0', 20);
mbed_trace_free(); mbed_trace_free();
mbed_trace_config_set(TRACE_MODE_PLAIN|TRACE_ACTIVE_LEVEL_ALL); mbed_trace_config_set(TRACE_MODE_PLAIN | TRACE_ACTIVE_LEVEL_ALL);
mbed_trace_print_function_set( myprint ); mbed_trace_print_function_set(myprint);
mbed_trace_buffer_sizes(11, 10); mbed_trace_buffer_sizes(11, 10);
mbed_trace_mutex_wait_function_set( my_mutex_wait ); mbed_trace_mutex_wait_function_set(my_mutex_wait);
mbed_trace_mutex_release_function_set( my_mutex_release ); mbed_trace_mutex_release_function_set(my_mutex_release);
mbed_trace_init(); mbed_trace_init();
STRCMP_EQUAL("30:30:30*", mbed_trace_array(arr, 20)); STRCMP_EQUAL("30:30:30*", mbed_trace_array(arr, 20));
const char * expectedStr = "0123456789"; const char *expectedStr = "0123456789";
mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "01234567890123456789"); mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "01234567890123456789");
STRCMP_EQUAL(expectedStr, buf); STRCMP_EQUAL(expectedStr, buf);
} }
@ -216,260 +222,268 @@ TEST(trace, ipv6)
TEST(trace, active_level_all_ipv6) TEST(trace, active_level_all_ipv6)
{ {
mbed_trace_config_set(TRACE_ACTIVE_LEVEL_ALL); mbed_trace_config_set(TRACE_ACTIVE_LEVEL_ALL);
uint8_t arr[] = { 0x20, 0x01, 0xd, 0xb8, 0,0,0,0,0,1,0,0,0,0,0,1 }; uint8_t arr[] = { 0x20, 0x01, 0xd, 0xb8, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1 };
ip6tos_stub.output_string = "2001:db8::1:0:0:1"; ip6tos_stub.output_string = "2001:db8::1:0:0:1";
mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "my addr: %s", mbed_trace_ipv6(arr)); mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "my addr: %s", mbed_trace_ipv6(arr));
CHECK(memcmp(ip6tos_stub.input_array, arr, 16) == 0); CHECK(memcmp(ip6tos_stub.input_array, arr, 16) == 0);
STRCMP_EQUAL("[DBG ][mygr]: my addr: 2001:db8::1:0:0:1", buf); STRCMP_EQUAL("[DBG ][mygr]: my addr: 2001:db8::1:0:0:1", buf);
} }
#endif //YOTTA_CFG_MBED_TRACE_FEA_IPV6 #endif //YOTTA_CFG_MBED_TRACE_FEA_IPV6
TEST(trace, config_change) TEST(trace, config_change)
{ {
mbed_trace_config_set(TRACE_MODE_COLOR|TRACE_ACTIVE_LEVEL_ALL); mbed_trace_config_set(TRACE_MODE_COLOR | TRACE_ACTIVE_LEVEL_ALL);
CHECK(mbed_trace_config_get() == TRACE_MODE_COLOR|TRACE_ACTIVE_LEVEL_ALL); CHECK(mbed_trace_config_get() == TRACE_MODE_COLOR | TRACE_ACTIVE_LEVEL_ALL);
mbed_trace_config_set(TRACE_MODE_PLAIN|TRACE_ACTIVE_LEVEL_NONE); mbed_trace_config_set(TRACE_MODE_PLAIN | TRACE_ACTIVE_LEVEL_NONE);
CHECK(mbed_trace_config_get() == TRACE_MODE_PLAIN|TRACE_ACTIVE_LEVEL_NONE); CHECK(mbed_trace_config_get() == TRACE_MODE_PLAIN | TRACE_ACTIVE_LEVEL_NONE);
mbed_trace_config_set(TRACE_MODE_PLAIN|TRACE_ACTIVE_LEVEL_ALL); mbed_trace_config_set(TRACE_MODE_PLAIN | TRACE_ACTIVE_LEVEL_ALL);
CHECK(mbed_trace_config_get() == TRACE_MODE_PLAIN|TRACE_ACTIVE_LEVEL_ALL); CHECK(mbed_trace_config_get() == TRACE_MODE_PLAIN | TRACE_ACTIVE_LEVEL_ALL);
} }
TEST(trace, active_level_all_color) TEST(trace, active_level_all_color)
{ {
mbed_trace_config_set(TRACE_MODE_COLOR|TRACE_ACTIVE_LEVEL_ALL); mbed_trace_config_set(TRACE_MODE_COLOR | TRACE_ACTIVE_LEVEL_ALL);
mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "hello"); // unknown debug level
STRCMP_EQUAL("\x1b[90m[DBG ][mygr]: hello\x1b[0m", buf); mbed_tracef(TRACE_LEVEL_DEBUG + 1, "mygr", "hep");
mbed_tracef(TRACE_LEVEL_INFO, "mygr", "to one"); STRCMP_EQUAL(" hep", buf);
STRCMP_EQUAL("\x1b[39m[INFO][mygr]: to one\x1b[0m", buf); mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "hello");
mbed_tracef(TRACE_LEVEL_WARN, "mygr", "and all"); STRCMP_EQUAL("\x1b[90m[DBG ][mygr]: hello\x1b[0m", buf);
STRCMP_EQUAL("\x1b[33m[WARN][mygr]: and all\x1b[0m", buf); mbed_tracef(TRACE_LEVEL_INFO, "mygr", "to one");
mbed_tracef(TRACE_LEVEL_ERROR, "mygr", "even you"); STRCMP_EQUAL("\x1b[39m[INFO][mygr]: to one\x1b[0m", buf);
STRCMP_EQUAL("\x1b[31m[ERR ][mygr]: even you\x1b[0m", buf); mbed_tracef(TRACE_LEVEL_WARN, "mygr", "and all");
STRCMP_EQUAL("\x1b[33m[WARN][mygr]: and all\x1b[0m", buf);
mbed_tracef(TRACE_LEVEL_ERROR, "mygr", "even you");
STRCMP_EQUAL("\x1b[31m[ERR ][mygr]: even you\x1b[0m", buf);
} }
TEST(trace, change_levels) TEST(trace, change_levels)
{ {
mbed_trace_config_set(TRACE_ACTIVE_LEVEL_DEBUG); mbed_trace_config_set(TRACE_ACTIVE_LEVEL_DEBUG);
mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "hep"); mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "hep");
STRCMP_EQUAL("[DBG ][mygr]: hep", buf); STRCMP_EQUAL("[DBG ][mygr]: hep", buf);
mbed_trace_config_set(TRACE_ACTIVE_LEVEL_DEBUG|TRACE_MODE_PLAIN); mbed_trace_config_set(TRACE_ACTIVE_LEVEL_DEBUG | TRACE_MODE_PLAIN);
mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "hep"); mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "hep");
STRCMP_EQUAL("hep", buf); STRCMP_EQUAL("hep", buf);
mbed_trace_config_set(TRACE_ACTIVE_LEVEL_DEBUG|TRACE_MODE_COLOR); mbed_trace_config_set(TRACE_ACTIVE_LEVEL_DEBUG | TRACE_MODE_COLOR);
mbed_tracef(TRACE_LEVEL_ERROR, "mygr", "hep"); mbed_tracef(TRACE_LEVEL_ERROR, "mygr", "hep");
STRCMP_EQUAL("\x1b[31m[ERR ][mygr]: hep\x1b[0m", buf); STRCMP_EQUAL("\x1b[31m[ERR ][mygr]: hep\x1b[0m", buf);
} }
TEST(trace, active_level_debug) TEST(trace, active_level_debug)
{ {
mbed_trace_config_set(TRACE_ACTIVE_LEVEL_DEBUG); mbed_trace_config_set(TRACE_ACTIVE_LEVEL_DEBUG);
mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "hep"); // unknown debug level
STRCMP_EQUAL("[DBG ][mygr]: hep", buf); mbed_tracef(TRACE_LEVEL_DEBUG + 1, "mygr", "hep");
STRCMP_EQUAL(" hep", buf);
mbed_tracef(TRACE_LEVEL_INFO, "mygr", "test");
STRCMP_EQUAL("[INFO][mygr]: test", buf); mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "hep");
STRCMP_EQUAL("[DBG ][mygr]: hep", buf);
mbed_tracef(TRACE_LEVEL_WARN, "mygr", "hups");
STRCMP_EQUAL("[WARN][mygr]: hups", buf); mbed_tracef(TRACE_LEVEL_INFO, "mygr", "test");
STRCMP_EQUAL("[INFO][mygr]: test", buf);
mbed_tracef(TRACE_LEVEL_ERROR, "mygr", "o'ou");
STRCMP_EQUAL("[ERR ][mygr]: o'ou", buf); mbed_tracef(TRACE_LEVEL_WARN, "mygr", "hups");
STRCMP_EQUAL("[WARN][mygr]: hups", buf);
mbed_tracef(TRACE_LEVEL_ERROR, "mygr", "o'ou");
STRCMP_EQUAL("[ERR ][mygr]: o'ou", buf);
} }
TEST(trace, active_level_info) TEST(trace, active_level_info)
{ {
buf[0] = 0; buf[0] = 0;
mbed_trace_config_set(TRACE_ACTIVE_LEVEL_INFO); mbed_trace_config_set(TRACE_ACTIVE_LEVEL_INFO);
mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "hep"); mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "hep");
STRCMP_EQUAL("", mbed_trace_last()); STRCMP_EQUAL("", mbed_trace_last());
mbed_tracef(TRACE_LEVEL_INFO, "mygr", "test"); mbed_tracef(TRACE_LEVEL_INFO, "mygr", "test");
STRCMP_EQUAL("[INFO][mygr]: test", buf); STRCMP_EQUAL("[INFO][mygr]: test", buf);
mbed_tracef(TRACE_LEVEL_WARN, "mygr", "hups"); mbed_tracef(TRACE_LEVEL_WARN, "mygr", "hups");
STRCMP_EQUAL("[WARN][mygr]: hups", buf); STRCMP_EQUAL("[WARN][mygr]: hups", buf);
mbed_tracef(TRACE_LEVEL_ERROR, "mygr", "o'ou"); mbed_tracef(TRACE_LEVEL_ERROR, "mygr", "o'ou");
STRCMP_EQUAL("[ERR ][mygr]: o'ou", buf); STRCMP_EQUAL("[ERR ][mygr]: o'ou", buf);
} }
TEST(trace, active_level_warn) TEST(trace, active_level_warn)
{ {
mbed_trace_config_set(TRACE_ACTIVE_LEVEL_WARN); mbed_trace_config_set(TRACE_ACTIVE_LEVEL_WARN);
mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "hep"); mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "hep");
STRCMP_EQUAL("", mbed_trace_last()); STRCMP_EQUAL("", mbed_trace_last());
mbed_tracef(TRACE_LEVEL_INFO, "mygr", "test"); mbed_tracef(TRACE_LEVEL_INFO, "mygr", "test");
STRCMP_EQUAL("", mbed_trace_last()); STRCMP_EQUAL("", mbed_trace_last());
mbed_tracef(TRACE_LEVEL_WARN, "mygr", "hups"); mbed_tracef(TRACE_LEVEL_WARN, "mygr", "hups");
STRCMP_EQUAL("[WARN][mygr]: hups", buf); STRCMP_EQUAL("[WARN][mygr]: hups", buf);
mbed_tracef(TRACE_LEVEL_ERROR, "mygr", "o'ou"); mbed_tracef(TRACE_LEVEL_ERROR, "mygr", "o'ou");
STRCMP_EQUAL("[ERR ][mygr]: o'ou", buf); STRCMP_EQUAL("[ERR ][mygr]: o'ou", buf);
} }
TEST(trace, active_level_error) TEST(trace, active_level_error)
{ {
mbed_trace_config_set(TRACE_ACTIVE_LEVEL_ERROR); mbed_trace_config_set(TRACE_ACTIVE_LEVEL_ERROR);
mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "hep"); mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "hep");
STRCMP_EQUAL("", mbed_trace_last()); STRCMP_EQUAL("", mbed_trace_last());
mbed_tracef(TRACE_LEVEL_INFO, "mygr", "test"); mbed_tracef(TRACE_LEVEL_INFO, "mygr", "test");
STRCMP_EQUAL("", mbed_trace_last()); STRCMP_EQUAL("", mbed_trace_last());
mbed_tracef(TRACE_LEVEL_WARN, "mygr", "hups"); mbed_tracef(TRACE_LEVEL_WARN, "mygr", "hups");
STRCMP_EQUAL("", mbed_trace_last()); STRCMP_EQUAL("", mbed_trace_last());
mbed_tracef(TRACE_LEVEL_ERROR, "mygr", "o'ou"); mbed_tracef(TRACE_LEVEL_ERROR, "mygr", "o'ou");
STRCMP_EQUAL("[ERR ][mygr]: o'ou", buf); STRCMP_EQUAL("[ERR ][mygr]: o'ou", buf);
} }
TEST(trace, active_level_none) TEST(trace, active_level_none)
{ {
mbed_trace_config_set(TRACE_ACTIVE_LEVEL_NONE); mbed_trace_config_set(TRACE_ACTIVE_LEVEL_NONE);
mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "hep"); mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "hep");
STRCMP_EQUAL("", mbed_trace_last()); STRCMP_EQUAL("", mbed_trace_last());
mbed_tracef(TRACE_LEVEL_INFO, "mygr", "test"); mbed_tracef(TRACE_LEVEL_INFO, "mygr", "test");
STRCMP_EQUAL("", mbed_trace_last()); STRCMP_EQUAL("", mbed_trace_last());
mbed_tracef(TRACE_LEVEL_WARN, "mygr", "hups"); mbed_tracef(TRACE_LEVEL_WARN, "mygr", "hups");
STRCMP_EQUAL("", mbed_trace_last()); STRCMP_EQUAL("", mbed_trace_last());
mbed_tracef(TRACE_LEVEL_ERROR, "mygr", "o'ou"); mbed_tracef(TRACE_LEVEL_ERROR, "mygr", "o'ou");
STRCMP_EQUAL("", mbed_trace_last()); STRCMP_EQUAL("", mbed_trace_last());
} }
TEST(trace, active_level_all_1) TEST(trace, active_level_all_1)
{ {
mbed_trace_config_set(TRACE_ACTIVE_LEVEL_ALL); mbed_trace_config_set(TRACE_ACTIVE_LEVEL_ALL);
mbed_trace_exclude_filters_set((char*)"mygr"); mbed_trace_exclude_filters_set((char *)"mygr");
mbed_tracef(TRACE_LEVEL_DEBUG, "mygu", "hep"); mbed_tracef(TRACE_LEVEL_DEBUG, "mygu", "hep");
STRCMP_EQUAL("[DBG ][mygu]: hep", buf); STRCMP_EQUAL("[DBG ][mygu]: hep", buf);
mbed_tracef(TRACE_LEVEL_INFO, "mygr", "test"); mbed_tracef(TRACE_LEVEL_INFO, "mygr", "test");
STRCMP_EQUAL("", mbed_trace_last()); STRCMP_EQUAL("", mbed_trace_last());
} }
TEST(trace, active_level_all_2) TEST(trace, active_level_all_2)
{ {
mbed_trace_config_set(TRACE_ACTIVE_LEVEL_ALL); mbed_trace_config_set(TRACE_ACTIVE_LEVEL_ALL);
mbed_trace_exclude_filters_set((char*)"mygr,mygu"); mbed_trace_exclude_filters_set((char *)"mygr,mygu");
mbed_tracef(TRACE_LEVEL_DEBUG, "mygu", "hep"); mbed_tracef(TRACE_LEVEL_DEBUG, "mygu", "hep");
STRCMP_EQUAL("", mbed_trace_last()); STRCMP_EQUAL("", mbed_trace_last());
mbed_tracef(TRACE_LEVEL_INFO, "mygr", "test"); mbed_tracef(TRACE_LEVEL_INFO, "mygr", "test");
STRCMP_EQUAL("", mbed_trace_last()); STRCMP_EQUAL("", mbed_trace_last());
} }
TEST(trace, active_level_all_3) TEST(trace, active_level_all_3)
{ {
mbed_trace_config_set(TRACE_ACTIVE_LEVEL_ALL); mbed_trace_config_set(TRACE_ACTIVE_LEVEL_ALL);
mbed_trace_include_filters_set((char*)"mygr"); mbed_trace_include_filters_set((char *)"mygr");
mbed_tracef(TRACE_LEVEL_DEBUG, "mygu", "hep"); mbed_tracef(TRACE_LEVEL_DEBUG, "mygu", "hep");
STRCMP_EQUAL("", mbed_trace_last()); STRCMP_EQUAL("", mbed_trace_last());
mbed_tracef(TRACE_LEVEL_INFO, "mygr", "test"); mbed_tracef(TRACE_LEVEL_INFO, "mygr", "test");
STRCMP_EQUAL("[INFO][mygr]: test", buf); STRCMP_EQUAL("[INFO][mygr]: test", buf);
} }
TEST(trace, active_level_all_array) TEST(trace, active_level_all_array)
{ {
mbed_trace_config_set(TRACE_ACTIVE_LEVEL_ALL); mbed_trace_config_set(TRACE_ACTIVE_LEVEL_ALL);
uint8_t arr[] = {0x01, 0x02, 0x03}; uint8_t arr[] = {0x01, 0x02, 0x03};
mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "my addr: %s", mbed_trace_array(arr, 3)); mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "my addr: %s", mbed_trace_array(arr, 3));
STRCMP_EQUAL("[DBG ][mygr]: my addr: 01:02:03", buf); STRCMP_EQUAL("[DBG ][mygr]: my addr: 01:02:03", buf);
} }
size_t time_length; size_t time_length;
char trace_prefix_str[] = "[<TIME>]"; char trace_prefix_str[] = "[<TIME>]";
char* trace_prefix(size_t length){ char *trace_prefix(size_t length)
time_length = length; {
return trace_prefix_str; time_length = length;
return trace_prefix_str;
} }
TEST(trace, prefix) TEST(trace, prefix)
{ {
mbed_trace_config_set(TRACE_ACTIVE_LEVEL_ALL); mbed_trace_config_set(TRACE_ACTIVE_LEVEL_ALL);
mbed_trace_prefix_function_set( &trace_prefix ); mbed_trace_prefix_function_set(&trace_prefix);
mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "test %d %d", 1, 2); mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "test %d %d", 1, 2);
STRCMP_EQUAL("[<TIME>][DBG ][mygr]: test 1 2", buf); STRCMP_EQUAL("[<TIME>][DBG ][mygr]: test 1 2", buf);
//TEST_ASSERT_EQUAL_INT(4, time_length); //TEST_ASSERT_EQUAL_INT(4, time_length);
mbed_trace_config_set(TRACE_ACTIVE_LEVEL_ALL|TRACE_MODE_PLAIN); mbed_trace_config_set(TRACE_ACTIVE_LEVEL_ALL | TRACE_MODE_PLAIN);
mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "test"); mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "test");
STRCMP_EQUAL("test", buf); STRCMP_EQUAL("test", buf);
mbed_trace_config_set(TRACE_ACTIVE_LEVEL_ALL|TRACE_MODE_COLOR); mbed_trace_config_set(TRACE_ACTIVE_LEVEL_ALL | TRACE_MODE_COLOR);
mbed_tracef(TRACE_LEVEL_ERROR, "mygr", "test"); mbed_tracef(TRACE_LEVEL_ERROR, "mygr", "test");
STRCMP_EQUAL("\x1b[31m[<TIME>][ERR ][mygr]: test\x1b[0m", buf); STRCMP_EQUAL("\x1b[31m[<TIME>][ERR ][mygr]: test\x1b[0m", buf);
} }
char trace_suffix_str[] = "[END]"; char trace_suffix_str[] = "[END]";
char* trace_suffix() char *trace_suffix()
{ {
return trace_suffix_str; return trace_suffix_str;
} }
TEST(trace, suffix) TEST(trace, suffix)
{ {
mbed_trace_config_set(TRACE_ACTIVE_LEVEL_ALL); mbed_trace_config_set(TRACE_ACTIVE_LEVEL_ALL);
mbed_trace_prefix_function_set( &trace_prefix ); mbed_trace_prefix_function_set(&trace_prefix);
mbed_trace_suffix_function_set( &trace_suffix ); mbed_trace_suffix_function_set(&trace_suffix);
mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "test"); mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "test");
STRCMP_EQUAL("[<TIME>][DBG ][mygr]: test[END]", buf); STRCMP_EQUAL("[<TIME>][DBG ][mygr]: test[END]", buf);
} }
TEST(trace, formatting) TEST(trace, formatting)
{ {
mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "hello %d %d %.1f", 12, 13, 5.5); mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "hello %d %d %.1f", 12, 13, 5.5);
STRCMP_EQUAL("hello 12 13 5.5", buf); STRCMP_EQUAL("hello 12 13 5.5", buf);
mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "hello %d %d %d %d %d %d", 12, 13, 5, 6, 8, 9); mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "hello %d %d %d %d %d %d", 12, 13, 5, 6, 8, 9);
STRCMP_EQUAL("hello 12 13 5 6 8 9", buf); STRCMP_EQUAL("hello 12 13 5 6 8 9", buf);
mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "HOH %d HAH %d %d %d %d %d", 12, 13, 5, 6, 8, 9); mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "HOH %d HAH %d %d %d %d %d", 12, 13, 5, 6, 8, 9);
STRCMP_EQUAL("HOH 12 HAH 13 5 6 8 9", buf); STRCMP_EQUAL("HOH 12 HAH 13 5 6 8 9", buf);
} }
TEST(trace, filters_control) TEST(trace, filters_control)
{ {
mbed_trace_include_filters_set((char*)"hello"); mbed_trace_include_filters_set((char *)"hello");
STRCMP_EQUAL("hello", mbed_trace_include_filters_get()); STRCMP_EQUAL("hello", mbed_trace_include_filters_get());
mbed_trace_include_filters_set(0); mbed_trace_include_filters_set(0);
STRCMP_EQUAL("", mbed_trace_include_filters_get()); STRCMP_EQUAL("", mbed_trace_include_filters_get());
mbed_trace_exclude_filters_set((char*)"hello"); mbed_trace_exclude_filters_set((char *)"hello");
STRCMP_EQUAL("hello", mbed_trace_exclude_filters_get()); STRCMP_EQUAL("hello", mbed_trace_exclude_filters_get());
mbed_trace_exclude_filters_set(0); mbed_trace_exclude_filters_set(0);
STRCMP_EQUAL("", mbed_trace_exclude_filters_get()); STRCMP_EQUAL("", mbed_trace_exclude_filters_get());
} }
TEST(trace, cmd_printer) TEST(trace, cmd_printer)
{ {
buf[0] = 0; buf[0] = 0;
mbed_trace_config_set(TRACE_ACTIVE_LEVEL_ALL); mbed_trace_config_set(TRACE_ACTIVE_LEVEL_ALL);
mbed_tracef(TRACE_LEVEL_CMD, "mygr", "default printer"); mbed_tracef(TRACE_LEVEL_CMD, "mygr", "default printer");
STRCMP_EQUAL("default printer", buf); STRCMP_EQUAL("default printer", buf);
mbed_trace_cmdprint_function_set( myprint ); mbed_trace_cmdprint_function_set(myprint);
mbed_tracef(TRACE_LEVEL_CMD, "mygr", "custom printer"); mbed_tracef(TRACE_LEVEL_CMD, "mygr", "custom printer");
STRCMP_EQUAL("\n", buf); // because there is two print calls, second one add line feeds STRCMP_EQUAL("\n", buf); // because there is two print calls, second one add line feeds
} }
TEST(trace, no_printer) TEST(trace, no_printer)
{ {
mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "hello"); mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "hello");
STRCMP_EQUAL("hello", buf); STRCMP_EQUAL("hello", buf);
mbed_trace_print_function_set(NULL); mbed_trace_print_function_set(NULL);
mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "this shoudnt be printed because printer is missing"); mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "this shoudnt be printed because printer is missing");
STRCMP_EQUAL("hello", buf); STRCMP_EQUAL("hello", buf);

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 * Count bits in a byte
* *
* \param byte byte to inspect * \param value byte to inspect
* *
* \return number of 1-bits in byte * \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 * Count leading zeros in a byte
* *
* \deprecated Use common_count_leading_zeros_8 * \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) * \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 * 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) * \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 * 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; 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) */ /* 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] */ /* [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) */ /* Add bit pairs to make each nibble contain count of bits (0-4) */
count = (count & 0x33) + ((count >> 2) & 0x33); count = (count & 0x33) + ((count >> 2) & 0x33);
/* Final result is sum of nibbles (0-8) */ /* 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; 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 #ifdef __CC_ARM
return byte ? __clz((unsigned int) byte << 24) : 8; return value ? __clz((unsigned int) value << 24) : 8;
#elif defined __GNUC__ #elif defined __GNUC__
return byte ? __builtin_clz((unsigned int) byte << 24) : 8; return value ? __builtin_clz((unsigned int) value << 24) : 8;
#else #else
uint_fast8_t cnt = 0; uint_fast8_t cnt = 0;
if (byte == 0) { if (value == 0) {
return 8; return 8;
} }
if ((byte & 0xF0) == 0) { if ((value & 0xF0) == 0) {
byte <<= 4; value <<= 4;
cnt += 4; cnt += 4;
} }
if ((byte & 0xC0) == 0) { if ((value & 0xC0) == 0) {
byte <<= 2; value <<= 2;
cnt += 2; cnt += 2;
} }
if ((byte & 0x80) == 0) { if ((value & 0x80) == 0) {
cnt += 1; cnt += 1;
} }

View File

@ -82,7 +82,7 @@ extern "C" {
typedef struct ns_list { typedef struct ns_list {
void *first_entry; ///< Pointer to first entry, or NULL if list is empty void *first_entry; ///< Pointer to first entry, or NULL if list is empty
void **last_nextptr; ///< Pointer to last entry's `next` pointer, or void **last_nextptr; ///< Pointer to last entry's `next` pointer, or
///< to head's `first_entry` pointer if list is empty ///< to head's `first_entry` pointer if list is empty
} ns_list_t; } ns_list_t;
/** \brief Declare a list head type /** \brief Declare a list head type

View File

@ -120,7 +120,7 @@ typedef int_fast32_t int_fast24_t;
#if defined __CC_ARM || defined __TASKING__ #if defined __CC_ARM || defined __TASKING__
#define alignas(n) __align(n) #define alignas(n) __align(n)
#define __alignas_is_defined 1 #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> #include <stdalign.h>
#elif defined __GNUC__ #elif defined __GNUC__
#define alignas(n) __attribute__((__aligned__(n))) #define alignas(n) __attribute__((__aligned__(n)))
@ -213,17 +213,17 @@ typedef int_fast32_t int_fast24_t;
# define NS_STATIC_ASSERT(test, str) _Static_assert(test, str); # define NS_STATIC_ASSERT(test, str) _Static_assert(test, str);
# elif defined __GNUC__ && NS_GCC_VERSION >= 40600 && !defined __CC_ARM # elif defined __GNUC__ && NS_GCC_VERSION >= 40600 && !defined __CC_ARM
# ifdef _Static_assert # ifdef _Static_assert
/* /*
* Some versions of glibc cdefs.h (which comes in via <stdint.h> above) * Some versions of glibc cdefs.h (which comes in via <stdint.h> above)
* attempt to define their own _Static_assert (if GCC < 4.6 or * attempt to define their own _Static_assert (if GCC < 4.6 or
* __STRICT_ANSI__) using an extern declaration, which doesn't work in a * __STRICT_ANSI__) using an extern declaration, which doesn't work in a
* struct/union. * struct/union.
* *
* For GCC >= 4.6 and __STRICT_ANSI__, we can do better - just use * For GCC >= 4.6 and __STRICT_ANSI__, we can do better - just use
* the built-in _Static_assert with __extension__. We have to do this, as * the built-in _Static_assert with __extension__. We have to do this, as
* ns_list.h needs to use it in a union. No way to get at it though, without * ns_list.h needs to use it in a union. No way to get at it though, without
* overriding their define. * overriding their define.
*/ */
# undef _Static_assert # undef _Static_assert
# define _Static_assert(x, y) __extension__ _Static_assert(x, y) # define _Static_assert(x, y) __extension__ _Static_assert(x, y)
# endif # endif

View File

@ -43,7 +43,7 @@ uint_fast8_t ip4tos(const void *ip4addr, char *p)
//Append a dot if this is not the last digit //Append a dot if this is not the last digit
if (component < 3) { if (component < 3) {
p[outputPos++] = '.'; p[outputPos++] = '.';
} }
} }
// Return length of generated string, excluding the terminating null character // Return length of generated string, excluding the terminating null character
@ -59,7 +59,7 @@ static void ipv4_itoa(char *string, uint8_t byte)
do { do {
*string++ = '0' + byte % 10; *string++ = '0' + byte % 10;
byte /= 10; byte /= 10;
} while(byte); } while (byte);
//We put the final \0, then go back one step on the last digit for the swap //We put the final \0, then go back one step on the last digit for the swap
*string-- = '\0'; *string-- = '\0';

View File

@ -74,8 +74,7 @@ bool stoip6(const char *ip6addr, size_t len, void *dest)
coloncolon = field_no; coloncolon = field_no;
q++; q++;
len -= 2; len -= 2;
} } else {
else {
len -= 1; 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) 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' // '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; return true;
}
if (c >= '0' && c <= '9') if (c >= '0' && c <= '9') {
return true; return true;
}
return false; return false;
} }

View File

@ -87,8 +87,8 @@ const mem_stat_t *ns_dyn_mem_get_mem_stat(void)
ns_mem_book_t *ns_mem_init(void *heap, ns_mem_heap_size_t h_size, ns_mem_book_t *ns_mem_init(void *heap, ns_mem_heap_size_t h_size,
void (*passed_fptr)(heap_fail_t), void (*passed_fptr)(heap_fail_t),
mem_stat_t *info_ptr) mem_stat_t *info_ptr)
{ {
#ifndef STANDARD_MALLOC #ifndef STANDARD_MALLOC
ns_mem_book_t *book; ns_mem_book_t *book;
@ -108,7 +108,7 @@ ns_mem_book_t *ns_mem_init(void *heap, ns_mem_heap_size_t h_size,
h_size -= (sizeof(ns_mem_word_size_t) - temp_int); h_size -= (sizeof(ns_mem_word_size_t) - temp_int);
} }
book = heap; book = heap;
book->heap_main = (ns_mem_word_size_t *)&(book[1]); // SET Heap Pointer book->heap_main = (ns_mem_word_size_t *) & (book[1]); // SET Heap Pointer
book->heap_size = h_size - sizeof(ns_mem_book_t); //Set Heap Size book->heap_size = h_size - sizeof(ns_mem_book_t); //Set Heap Size
temp_int = (book->heap_size / sizeof(ns_mem_word_size_t)); temp_int = (book->heap_size / sizeof(ns_mem_word_size_t));
temp_int -= 2; temp_int -= 2;
@ -127,7 +127,7 @@ ns_mem_book_t *ns_mem_init(void *heap, ns_mem_heap_size_t h_size,
memset(book->mem_stat_info_ptr, 0, sizeof(mem_stat_t)); memset(book->mem_stat_info_ptr, 0, sizeof(mem_stat_t));
book->mem_stat_info_ptr->heap_sector_size = book->heap_size; book->mem_stat_info_ptr->heap_sector_size = book->heap_size;
} }
book->temporary_alloc_heap_limit = book->heap_size/100 * (100-TEMPORARY_ALLOC_FREE_HEAP_THRESHOLD); book->temporary_alloc_heap_limit = book->heap_size / 100 * (100 - TEMPORARY_ALLOC_FREE_HEAP_THRESHOLD);
#endif #endif
//There really is no support to standard malloc in this library anymore //There really is no support to standard malloc in this library anymore
book->heap_failure_callback = passed_fptr; book->heap_failure_callback = passed_fptr;
@ -154,12 +154,12 @@ int ns_mem_set_temporary_alloc_free_heap_threshold(ns_mem_book_t *book, uint8_t
return -1; return -1;
} }
if (free_heap_amount && free_heap_amount < book->heap_size/2) { if (free_heap_amount && free_heap_amount < book->heap_size / 2) {
heap_limit = book->heap_size - free_heap_amount; heap_limit = book->heap_size - free_heap_amount;
} }
if (!free_heap_amount && free_heap_percentage && free_heap_percentage < 50) { if (!free_heap_amount && free_heap_percentage && free_heap_percentage < 50) {
heap_limit = book->heap_size/100 * (100 - free_heap_percentage); heap_limit = book->heap_size / 100 * (100 - free_heap_percentage);
} }
if (free_heap_amount == 0 && free_heap_percentage == 0) { if (free_heap_amount == 0 && free_heap_percentage == 0) {
@ -215,7 +215,7 @@ static ns_mem_word_size_t convert_allocation_size(ns_mem_book_t *book, ns_mem_bl
heap_failure(book, NS_DYN_MEM_HEAP_SECTOR_UNITIALIZED); heap_failure(book, NS_DYN_MEM_HEAP_SECTOR_UNITIALIZED);
} else if (requested_bytes < 1) { } else if (requested_bytes < 1) {
heap_failure(book, NS_DYN_MEM_ALLOCATE_SIZE_NOT_VALID); heap_failure(book, NS_DYN_MEM_ALLOCATE_SIZE_NOT_VALID);
} else if (requested_bytes > (book->heap_size - 2 * sizeof(ns_mem_word_size_t)) ) { } else if (requested_bytes > (book->heap_size - 2 * sizeof(ns_mem_word_size_t))) {
heap_failure(book, NS_DYN_MEM_ALLOCATE_SIZE_NOT_VALID); heap_failure(book, NS_DYN_MEM_ALLOCATE_SIZE_NOT_VALID);
} }
return (requested_bytes + sizeof(ns_mem_word_size_t) - 1) / sizeof(ns_mem_word_size_t); return (requested_bytes + sizeof(ns_mem_word_size_t) - 1) / sizeof(ns_mem_word_size_t);
@ -266,10 +266,10 @@ static void *ns_mem_internal_alloc(ns_mem_book_t *book, const ns_mem_block_size_
// ns_list_foreach, either forwards or backwards, result to ptr // ns_list_foreach, either forwards or backwards, result to ptr
for (hole_t *cur_hole = direction > 0 ? ns_list_get_first(&book->holes_list) for (hole_t *cur_hole = direction > 0 ? ns_list_get_first(&book->holes_list)
: ns_list_get_last(&book->holes_list); : ns_list_get_last(&book->holes_list);
cur_hole; cur_hole;
cur_hole = direction > 0 ? ns_list_get_next(&book->holes_list, cur_hole) cur_hole = direction > 0 ? ns_list_get_next(&book->holes_list, cur_hole)
: ns_list_get_previous(&book->holes_list, cur_hole) : ns_list_get_previous(&book->holes_list, cur_hole)
) { ) {
ns_mem_word_size_t *p = block_start_from_hole(cur_hole); ns_mem_word_size_t *p = block_start_from_hole(cur_hole);
if (ns_mem_block_validate(p) != 0 || *p >= 0) { if (ns_mem_block_validate(p) != 0 || *p >= 0) {
@ -295,7 +295,7 @@ static void *ns_mem_internal_alloc(ns_mem_book_t *book, const ns_mem_block_size_
ns_mem_word_size_t hole_size = block_data_size - data_size - 2; ns_mem_word_size_t hole_size = block_data_size - data_size - 2;
ns_mem_word_size_t *hole_ptr; ns_mem_word_size_t *hole_ptr;
//There is enough room for a new hole so create it first //There is enough room for a new hole so create it first
if ( direction > 0 ) { if (direction > 0) {
hole_ptr = block_ptr + 1 + data_size + 1; hole_ptr = block_ptr + 1 + data_size + 1;
// Hole will be left at end of area. // Hole will be left at end of area.
// Would like to just replace this block_ptr with new descriptor, but // Would like to just replace this block_ptr with new descriptor, but
@ -324,7 +324,7 @@ static void *ns_mem_internal_alloc(ns_mem_book_t *book, const ns_mem_block_size_
block_ptr[0] = data_size; block_ptr[0] = data_size;
block_ptr[1 + data_size] = data_size; block_ptr[1 + data_size] = data_size;
done: done:
if (book->mem_stat_info_ptr) { if (book->mem_stat_info_ptr) {
if (block_ptr) { if (block_ptr) {
//Update Allocate OK //Update Allocate OK
@ -433,7 +433,7 @@ static void ns_mem_free_and_merge_with_adjacent_blocks(ns_mem_book_t *book, ns_m
} else { } else {
// Didn't find adjacent descriptors, but may still // Didn't find adjacent descriptors, but may still
// be merging with small blocks without descriptors. // be merging with small blocks without descriptors.
if ( merged_data_size >= HOLE_T_SIZE ) { if (merged_data_size >= HOLE_T_SIZE) {
// Locate hole position in list, if we don't already know // Locate hole position in list, if we don't already know
// from merging with the block above. // from merging with the block above.
if (!existing_end) { if (!existing_end) {

View File

@ -60,7 +60,7 @@ static NS_LIST_DEFINE(ns_nvm_request_list, ns_nvm_request_t, link);
*/ */
void ns_nvm_callback_func(platform_nvm_status status, void *args) void ns_nvm_callback_func(platform_nvm_status status, void *args)
{ {
ns_nvm_request_t *ns_nvm_request_ptr = (ns_nvm_request_t*)args; ns_nvm_request_t *ns_nvm_request_ptr = (ns_nvm_request_t *)args;
int client_retval = NS_NVM_OK; int client_retval = NS_NVM_OK;
if (status == PLATFORM_NVM_ERROR) { if (status == PLATFORM_NVM_ERROR) {
@ -69,7 +69,7 @@ void ns_nvm_callback_func(platform_nvm_status status, void *args)
client_retval = NS_NVM_DATA_NOT_FOUND; client_retval = NS_NVM_DATA_NOT_FOUND;
} }
switch(ns_nvm_request_ptr->operation) { switch (ns_nvm_request_ptr->operation) {
case NS_NVM_INIT: case NS_NVM_INIT:
ns_nvm_operation_continue(ns_nvm_request_ptr->original_request, true); ns_nvm_operation_continue(ns_nvm_request_ptr->original_request, true);
ns_dyn_mem_free(ns_nvm_request_ptr); ns_dyn_mem_free(ns_nvm_request_ptr);
@ -185,7 +185,7 @@ static int ns_nvm_operation_continue(ns_nvm_request_t *request, bool free_reques
platform_nvm_status ret = PLATFORM_NVM_OK; platform_nvm_status ret = PLATFORM_NVM_OK;
ns_nvm_operation_in_progress = true; ns_nvm_operation_in_progress = true;
switch(request->operation) { switch (request->operation) {
case NS_NVM_KEY_WRITE: case NS_NVM_KEY_WRITE:
request->operation = NS_NVM_KEY_CREATE; request->operation = NS_NVM_KEY_CREATE;
ret = platform_nvm_key_create(ns_nvm_callback_func, request->client_key_name, *request->buffer_len, 0, request); ret = platform_nvm_key_create(ns_nvm_callback_func, request->client_key_name, *request->buffer_len, 0, request);

View File

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

View File

@ -32,12 +32,12 @@ TEST_GROUP(dynmem)
TEST(dynmem, init) TEST(dynmem, init)
{ {
uint16_t size = 1000; uint16_t size = 1000;
uint8_t *heap = (uint8_t*)malloc(size); uint8_t *heap = (uint8_t *)malloc(size);
CHECK(NULL != heap); CHECK(NULL != heap);
mem_stat_t info; mem_stat_t info;
reset_heap_error(); reset_heap_error();
ns_dyn_mem_init(heap, size, &heap_fail_callback, &info); ns_dyn_mem_init(heap, size, &heap_fail_callback, &info);
CHECK(info.heap_sector_size >= (size-72)); CHECK(info.heap_sector_size >= (size - 72));
CHECK(!heap_have_failed()); CHECK(!heap_have_failed());
CHECK(ns_dyn_mem_get_mem_stat() == &info); CHECK(ns_dyn_mem_get_mem_stat() == &info);
free(heap); free(heap);
@ -46,11 +46,11 @@ TEST(dynmem, init)
TEST(dynmem, different_sizes) TEST(dynmem, different_sizes)
{ {
reset_heap_error(); reset_heap_error();
for (uint16_t size = 1000; size<32768; size++) { for (uint16_t size = 1000; size < 32768; size++) {
mem_stat_t info; mem_stat_t info;
uint8_t *heap = (uint8_t*)malloc(size); uint8_t *heap = (uint8_t *)malloc(size);
ns_dyn_mem_init(heap, size, &heap_fail_callback, &info); ns_dyn_mem_init(heap, size, &heap_fail_callback, &info);
CHECK(info.heap_sector_size >= (size-72)); CHECK(info.heap_sector_size >= (size - 72));
CHECK(!heap_have_failed()); CHECK(!heap_have_failed());
CHECK(ns_dyn_mem_alloc(10)); CHECK(ns_dyn_mem_alloc(10));
free(heap); free(heap);
@ -61,14 +61,15 @@ TEST(dynmem, diff_alignment)
{ {
uint16_t size = 1000; uint16_t size = 1000;
mem_stat_t info; mem_stat_t info;
uint8_t *heap = (uint8_t*)malloc(size); uint8_t *heap = (uint8_t *)malloc(size);
uint8_t *ptr = heap; uint8_t *ptr = heap;
CHECK(NULL != heap); CHECK(NULL != heap);
reset_heap_error(); reset_heap_error();
for (int i=0; i<16; i++) { for (int i = 0; i < 16; i++) {
ptr++; size--; ptr++;
size--;
ns_dyn_mem_init(ptr, size, &heap_fail_callback, &info); ns_dyn_mem_init(ptr, size, &heap_fail_callback, &info);
CHECK(info.heap_sector_size >= (size-72)); CHECK(info.heap_sector_size >= (size - 72));
CHECK(!heap_have_failed()); CHECK(!heap_have_failed());
} }
free(heap); free(heap);
@ -79,7 +80,7 @@ TEST(dynmem, ns_dyn_mem_alloc)
uint16_t size = 1000; uint16_t size = 1000;
mem_stat_t info; mem_stat_t info;
void *p[size]; void *p[size];
uint8_t *heap = (uint8_t*)malloc(size); uint8_t *heap = (uint8_t *)malloc(size);
CHECK(NULL != heap); CHECK(NULL != heap);
reset_heap_error(); reset_heap_error();
ns_dyn_mem_init(heap, size, &heap_fail_callback, &info); ns_dyn_mem_init(heap, size, &heap_fail_callback, &info);
@ -87,17 +88,18 @@ TEST(dynmem, ns_dyn_mem_alloc)
int block = 1; int block = 1;
int i; int i;
for (i=0; i<size; i++) { for (i = 0; i < size; i++) {
p[i] = ns_dyn_mem_alloc(block); p[i] = ns_dyn_mem_alloc(block);
if (!p[i]) if (!p[i]) {
break; break;
}
} }
CHECK(!heap_have_failed()); CHECK(!heap_have_failed());
CHECK(info.heap_alloc_fail_cnt == 1); CHECK(info.heap_alloc_fail_cnt == 1);
CHECK(info.heap_sector_alloc_cnt == i); CHECK(info.heap_sector_alloc_cnt == i);
CHECK(info.heap_sector_allocated_bytes == info.heap_sector_allocated_bytes_max); CHECK(info.heap_sector_allocated_bytes == info.heap_sector_allocated_bytes_max);
for (; i>=0; i--) { for (; i >= 0; i--) {
ns_dyn_mem_free(p[i]); ns_dyn_mem_free(p[i]);
} }
CHECK(!heap_have_failed()); CHECK(!heap_have_failed());
@ -110,7 +112,7 @@ TEST(dynmem, ns_dyn_mem_temporary_alloc)
uint16_t size = 1000; uint16_t size = 1000;
mem_stat_t info; mem_stat_t info;
void *p[size]; void *p[size];
uint8_t *heap = (uint8_t*)malloc(size); uint8_t *heap = (uint8_t *)malloc(size);
CHECK(NULL != heap); CHECK(NULL != heap);
reset_heap_error(); reset_heap_error();
ns_dyn_mem_init(heap, size, &heap_fail_callback, &info); ns_dyn_mem_init(heap, size, &heap_fail_callback, &info);
@ -118,17 +120,18 @@ TEST(dynmem, ns_dyn_mem_temporary_alloc)
int block = 1; int block = 1;
int i; int i;
for (i=0; i<size; i++) { for (i = 0; i < size; i++) {
p[i] = ns_dyn_mem_temporary_alloc(block); p[i] = ns_dyn_mem_temporary_alloc(block);
if (!p[i]) if (!p[i]) {
break; break;
}
} }
CHECK(!heap_have_failed()); CHECK(!heap_have_failed());
CHECK(info.heap_alloc_fail_cnt == 1); CHECK(info.heap_alloc_fail_cnt == 1);
CHECK(info.heap_sector_alloc_cnt == i); CHECK(info.heap_sector_alloc_cnt == i);
CHECK(info.heap_sector_allocated_bytes == info.heap_sector_allocated_bytes_max); CHECK(info.heap_sector_allocated_bytes == info.heap_sector_allocated_bytes_max);
for (; i>=0; i--) { for (; i >= 0; i--) {
ns_dyn_mem_free(p[i]); ns_dyn_mem_free(p[i]);
} }
CHECK(!heap_have_failed()); CHECK(!heap_have_failed());
@ -142,24 +145,24 @@ TEST(dynmem, ns_dyn_mem_temporary_alloc_with_heap_threshold)
mem_stat_t info; mem_stat_t info;
void *p1, *p2; void *p1, *p2;
int ret_val; int ret_val;
uint8_t *heap = (uint8_t*)malloc(size); uint8_t *heap = (uint8_t *)malloc(size);
CHECK(NULL != heap); CHECK(NULL != heap);
reset_heap_error(); reset_heap_error();
ns_dyn_mem_init(heap, size, &heap_fail_callback, &info); ns_dyn_mem_init(heap, size, &heap_fail_callback, &info);
CHECK(!heap_have_failed()); CHECK(!heap_have_failed());
// test1: temporary alloc will fail if there is less than 5% heap free // test1: temporary alloc will fail if there is less than 5% heap free
p1 = ns_dyn_mem_temporary_alloc((size-72)*0.96); p1 = ns_dyn_mem_temporary_alloc((size - 72) * 0.96);
CHECK(!heap_have_failed()); CHECK(!heap_have_failed());
CHECK(p1); CHECK(p1);
p2 = ns_dyn_mem_temporary_alloc((size-72)*0.02); p2 = ns_dyn_mem_temporary_alloc((size - 72) * 0.02);
CHECK(p2 == NULL); CHECK(p2 == NULL);
CHECK(!heap_have_failed()); CHECK(!heap_have_failed());
CHECK(info.heap_alloc_fail_cnt == 1); CHECK(info.heap_alloc_fail_cnt == 1);
// Test2, disable threshold feature and try p2 allocation again // Test2, disable threshold feature and try p2 allocation again
ns_dyn_mem_set_temporary_alloc_free_heap_threshold(0, 0); ns_dyn_mem_set_temporary_alloc_free_heap_threshold(0, 0);
p2 = ns_dyn_mem_temporary_alloc((size-72)*0.02); p2 = ns_dyn_mem_temporary_alloc((size - 72) * 0.02);
CHECK(!heap_have_failed()); CHECK(!heap_have_failed());
CHECK(p2); CHECK(p2);
ns_dyn_mem_free(p1); ns_dyn_mem_free(p1);
@ -169,10 +172,10 @@ TEST(dynmem, ns_dyn_mem_temporary_alloc_with_heap_threshold)
// Test3, enable feature by free heap percentage // Test3, enable feature by free heap percentage
ns_dyn_mem_set_temporary_alloc_free_heap_threshold(40, 0); ns_dyn_mem_set_temporary_alloc_free_heap_threshold(40, 0);
p1 = ns_dyn_mem_temporary_alloc((size-72)*0.65); p1 = ns_dyn_mem_temporary_alloc((size - 72) * 0.65);
CHECK(p1); CHECK(p1);
p2 = ns_dyn_mem_temporary_alloc((size-72)*0.10); p2 = ns_dyn_mem_temporary_alloc((size - 72) * 0.10);
CHECK(p2==NULL); CHECK(p2 == NULL);
ns_dyn_mem_free(p1); ns_dyn_mem_free(p1);
CHECK(!heap_have_failed()); CHECK(!heap_have_failed());
CHECK(info.heap_alloc_fail_cnt == 2); CHECK(info.heap_alloc_fail_cnt == 2);
@ -180,21 +183,21 @@ TEST(dynmem, ns_dyn_mem_temporary_alloc_with_heap_threshold)
// Test4, enable feature by free heap amount // Test4, enable feature by free heap amount
ns_dyn_mem_set_temporary_alloc_free_heap_threshold(0, 200); ns_dyn_mem_set_temporary_alloc_free_heap_threshold(0, 200);
p1 = ns_dyn_mem_temporary_alloc(size-72-100 /*828 bytes */); p1 = ns_dyn_mem_temporary_alloc(size - 72 - 100 /*828 bytes */);
CHECK(p1); CHECK(p1);
p2 = ns_dyn_mem_temporary_alloc(1); p2 = ns_dyn_mem_temporary_alloc(1);
CHECK(p2==NULL); CHECK(p2 == NULL);
ns_dyn_mem_free(p1); ns_dyn_mem_free(p1);
// Test5, illegal API parameters // Test5, illegal API parameters
ret_val = ns_dyn_mem_set_temporary_alloc_free_heap_threshold(0, size/2); ret_val = ns_dyn_mem_set_temporary_alloc_free_heap_threshold(0, size / 2);
CHECK(ret_val==-2); CHECK(ret_val == -2);
ret_val = ns_dyn_mem_set_temporary_alloc_free_heap_threshold(0, size*2); ret_val = ns_dyn_mem_set_temporary_alloc_free_heap_threshold(0, size * 2);
CHECK(ret_val==-2); CHECK(ret_val == -2);
ret_val = ns_dyn_mem_set_temporary_alloc_free_heap_threshold(51, 0); ret_val = ns_dyn_mem_set_temporary_alloc_free_heap_threshold(51, 0);
CHECK(ret_val==-2); CHECK(ret_val == -2);
ret_val = ns_dyn_mem_set_temporary_alloc_free_heap_threshold(255, 0); ret_val = ns_dyn_mem_set_temporary_alloc_free_heap_threshold(255, 0);
CHECK(ret_val==-2); CHECK(ret_val == -2);
CHECK(!heap_have_failed()); CHECK(!heap_have_failed());
CHECK(info.heap_alloc_fail_cnt == 3); CHECK(info.heap_alloc_fail_cnt == 3);
@ -202,20 +205,21 @@ TEST(dynmem, ns_dyn_mem_temporary_alloc_with_heap_threshold)
free(heap); free(heap);
// Test6, feature is disabled if info is not set // Test6, feature is disabled if info is not set
heap = (uint8_t*)malloc(size); heap = (uint8_t *)malloc(size);
CHECK(NULL != heap); CHECK(NULL != heap);
ns_dyn_mem_init(heap, size, &heap_fail_callback, NULL); ns_dyn_mem_init(heap, size, &heap_fail_callback, NULL);
ret_val = ns_dyn_mem_set_temporary_alloc_free_heap_threshold(0, 0); ret_val = ns_dyn_mem_set_temporary_alloc_free_heap_threshold(0, 0);
CHECK(ret_val==-1); CHECK(ret_val == -1);
CHECK(!heap_have_failed()); CHECK(!heap_have_failed());
free(heap); free(heap);
} }
TEST(dynmem, test_both_allocs_with_hole_usage) { TEST(dynmem, test_both_allocs_with_hole_usage)
{
uint16_t size = 112; uint16_t size = 112;
mem_stat_t info; mem_stat_t info;
void *p[size]; void *p[size];
uint8_t *heap = (uint8_t*)malloc(size); uint8_t *heap = (uint8_t *)malloc(size);
CHECK(NULL != heap); CHECK(NULL != heap);
reset_heap_error(); reset_heap_error();
ns_dyn_mem_init(heap, size, &heap_fail_callback, &info); ns_dyn_mem_init(heap, size, &heap_fail_callback, &info);
@ -240,11 +244,12 @@ TEST(dynmem, test_both_allocs_with_hole_usage) {
free(heap); free(heap);
} }
TEST(dynmem, test_temp_alloc_with_skipping_hole) { TEST(dynmem, test_temp_alloc_with_skipping_hole)
{
uint16_t size = 1000; uint16_t size = 1000;
mem_stat_t info; mem_stat_t info;
void *p[size]; void *p[size];
uint8_t *heap = (uint8_t*)malloc(size); uint8_t *heap = (uint8_t *)malloc(size);
CHECK(NULL != heap); CHECK(NULL != heap);
reset_heap_error(); reset_heap_error();
ns_dyn_mem_init(heap, size, &heap_fail_callback, &info); ns_dyn_mem_init(heap, size, &heap_fail_callback, &info);
@ -268,7 +273,7 @@ TEST(dynmem, zero_allocate)
{ {
uint16_t size = 1000; uint16_t size = 1000;
mem_stat_t info; mem_stat_t info;
uint8_t *heap = (uint8_t*)malloc(size); uint8_t *heap = (uint8_t *)malloc(size);
uint8_t *ptr = heap; uint8_t *ptr = heap;
CHECK(NULL != heap); CHECK(NULL != heap);
reset_heap_error(); reset_heap_error();
@ -284,7 +289,7 @@ TEST(dynmem, too_big)
{ {
uint16_t size = 1000; uint16_t size = 1000;
mem_stat_t info; mem_stat_t info;
uint8_t *heap = (uint8_t*)malloc(size); uint8_t *heap = (uint8_t *)malloc(size);
uint8_t *ptr = heap; uint8_t *ptr = heap;
CHECK(NULL != heap); CHECK(NULL != heap);
reset_heap_error(); reset_heap_error();
@ -300,7 +305,7 @@ TEST(dynmem, corrupted_memory)
{ {
uint16_t size = 1000; uint16_t size = 1000;
mem_stat_t info; mem_stat_t info;
uint8_t *heap = (uint8_t*)malloc(size); uint8_t *heap = (uint8_t *)malloc(size);
uint8_t *ptr = heap; uint8_t *ptr = heap;
CHECK(NULL != heap); CHECK(NULL != heap);
reset_heap_error(); reset_heap_error();
@ -315,10 +320,11 @@ TEST(dynmem, corrupted_memory)
free(heap); free(heap);
} }
TEST(dynmem, no_big_enough_sector) { TEST(dynmem, no_big_enough_sector)
{
uint16_t size = 112; uint16_t size = 112;
mem_stat_t info; mem_stat_t info;
uint8_t *heap = (uint8_t*)malloc(size); uint8_t *heap = (uint8_t *)malloc(size);
uint8_t *ptr = heap; uint8_t *ptr = heap;
CHECK(NULL != heap); CHECK(NULL != heap);
reset_heap_error(); reset_heap_error();
@ -342,13 +348,13 @@ TEST(dynmem, diff_sizes)
uint16_t size = 1000; uint16_t size = 1000;
mem_stat_t info; mem_stat_t info;
void *p; void *p;
uint8_t *heap = (uint8_t*)malloc(size); uint8_t *heap = (uint8_t *)malloc(size);
CHECK(NULL != heap); CHECK(NULL != heap);
reset_heap_error(); reset_heap_error();
ns_dyn_mem_init(heap, size, &heap_fail_callback, &info); ns_dyn_mem_init(heap, size, &heap_fail_callback, &info);
CHECK(!heap_have_failed()); CHECK(!heap_have_failed());
int i; int i;
for (i=1; i<(size-72); i++) { for (i = 1; i < (size - 72); i++) {
p = ns_dyn_mem_temporary_alloc(i); p = ns_dyn_mem_temporary_alloc(i);
CHECK(p); CHECK(p);
ns_dyn_mem_free(p); ns_dyn_mem_free(p);
@ -363,7 +369,7 @@ TEST(dynmem, double_free)
{ {
uint16_t size = 1000; uint16_t size = 1000;
mem_stat_t info; mem_stat_t info;
uint8_t *heap = (uint8_t*)malloc(size); uint8_t *heap = (uint8_t *)malloc(size);
void *p; void *p;
CHECK(NULL != heap); CHECK(NULL != heap);
reset_heap_error(); reset_heap_error();
@ -383,13 +389,13 @@ TEST(dynmem, middle_free)
{ {
uint16_t size = 1000; uint16_t size = 1000;
mem_stat_t info; mem_stat_t info;
uint8_t *heap = (uint8_t*)malloc(size); uint8_t *heap = (uint8_t *)malloc(size);
void *p[3]; void *p[3];
CHECK(NULL != heap); CHECK(NULL != heap);
reset_heap_error(); reset_heap_error();
ns_dyn_mem_init(heap, size, &heap_fail_callback, &info); ns_dyn_mem_init(heap, size, &heap_fail_callback, &info);
CHECK(!heap_have_failed()); CHECK(!heap_have_failed());
for (int i=0; i<3; i++) { for (int i = 0; i < 3; i++) {
p[i] = ns_dyn_mem_temporary_alloc(100); p[i] = ns_dyn_mem_temporary_alloc(100);
CHECK(p); CHECK(p);
} }
@ -406,7 +412,7 @@ TEST(dynmem, over_by_one)
{ {
uint16_t size = 1000; uint16_t size = 1000;
mem_stat_t info; mem_stat_t info;
uint8_t *heap = (uint8_t*)malloc(size); uint8_t *heap = (uint8_t *)malloc(size);
uint8_t *p; uint8_t *p;
CHECK(NULL != heap); CHECK(NULL != heap);
reset_heap_error(); reset_heap_error();
@ -425,7 +431,7 @@ TEST(dynmem, not_from_this_heap)
{ {
uint16_t size = 1000; uint16_t size = 1000;
mem_stat_t info; mem_stat_t info;
uint8_t *heap = (uint8_t*)malloc(size); uint8_t *heap = (uint8_t *)malloc(size);
uint8_t *p; uint8_t *p;
CHECK(NULL != heap); CHECK(NULL != heap);
reset_heap_error(); reset_heap_error();
@ -447,7 +453,7 @@ TEST(dynmem, free_on_empty_heap)
{ {
uint16_t size = 1000; uint16_t size = 1000;
mem_stat_t info; mem_stat_t info;
uint8_t *heap = (uint8_t*)malloc(size); uint8_t *heap = (uint8_t *)malloc(size);
uint8_t *p; uint8_t *p;
CHECK(NULL != heap); CHECK(NULL != heap);
reset_heap_error(); reset_heap_error();
@ -463,7 +469,7 @@ TEST(dynmem, not_negative_stats)
{ {
uint16_t size = 1000; uint16_t size = 1000;
mem_stat_t info; mem_stat_t info;
uint8_t *heap = (uint8_t*)malloc(size); uint8_t *heap = (uint8_t *)malloc(size);
void *p; void *p;
CHECK(NULL != heap); CHECK(NULL != heap);
reset_heap_error(); reset_heap_error();
@ -479,7 +485,7 @@ TEST(dynmem, not_negative_stats)
CHECK(info.heap_sector_allocated_bytes >= 16); CHECK(info.heap_sector_allocated_bytes >= 16);
CHECK(info.heap_sector_allocated_bytes < last_value); CHECK(info.heap_sector_allocated_bytes < last_value);
last_value = info.heap_sector_allocated_bytes; last_value = info.heap_sector_allocated_bytes;
for (int i=0; i<10; i++) { for (int i = 0; i < 10; i++) {
p = ns_dyn_mem_alloc(1); p = ns_dyn_mem_alloc(1);
ns_dyn_mem_free(p); ns_dyn_mem_free(p);
} }
@ -487,9 +493,10 @@ TEST(dynmem, not_negative_stats)
free(heap); free(heap);
} }
TEST(dynmem, test_invalid_pointer_freed) { TEST(dynmem, test_invalid_pointer_freed)
{
uint16_t size = 92; uint16_t size = 92;
uint8_t *heap = (uint8_t*)malloc(size); uint8_t *heap = (uint8_t *)malloc(size);
CHECK(NULL != heap); CHECK(NULL != heap);
reset_heap_error(); reset_heap_error();
ns_dyn_mem_init(heap, size, &heap_fail_callback, NULL); ns_dyn_mem_init(heap, size, &heap_fail_callback, NULL);
@ -503,9 +510,10 @@ TEST(dynmem, test_invalid_pointer_freed) {
free(heap); free(heap);
} }
TEST(dynmem, test_merge_corrupted_previous_block) { TEST(dynmem, test_merge_corrupted_previous_block)
{
uint16_t size = 1000; uint16_t size = 1000;
uint8_t *heap = (uint8_t*)malloc(size); uint8_t *heap = (uint8_t *)malloc(size);
uint8_t *p; uint8_t *p;
CHECK(NULL != heap); CHECK(NULL != heap);
reset_heap_error(); reset_heap_error();
@ -524,9 +532,10 @@ TEST(dynmem, test_merge_corrupted_previous_block) {
free(heap); free(heap);
} }
TEST(dynmem, test_free_corrupted_next_block) { TEST(dynmem, test_free_corrupted_next_block)
{
uint16_t size = 1000; uint16_t size = 1000;
uint8_t *heap = (uint8_t*)malloc(size); uint8_t *heap = (uint8_t *)malloc(size);
uint8_t *p; uint8_t *p;
CHECK(NULL != heap); CHECK(NULL != heap);
reset_heap_error(); reset_heap_error();
@ -546,7 +555,8 @@ TEST(dynmem, test_free_corrupted_next_block) {
} }
//NOTE! This test must be last! //NOTE! This test must be last!
TEST(dynmem, uninitialized_test){ TEST(dynmem, uninitialized_test)
{
void *p = ns_dyn_mem_alloc(4); void *p = ns_dyn_mem_alloc(4);
ns_dyn_mem_free(p); ns_dyn_mem_free(p);
CHECK(p == NULL); CHECK(p == NULL);

View File

@ -19,15 +19,18 @@
heap_fail_t current_heap_error; heap_fail_t current_heap_error;
static bool failed; 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; current_heap_error = err;
failed = true;
} }
void reset_heap_error() { void reset_heap_error()
failed = false; {
failed = false;
} }
bool heap_have_failed() { bool heap_have_failed()
return failed; {
return failed;
} }

View File

@ -193,7 +193,7 @@ bool test_ns_nvm_helper_read()
bool test_ns_nvm_helper_delete() bool test_ns_nvm_helper_delete()
{ {
int ret_val; int ret_val;
delete_callback_status = -1; delete_callback_status = -1;
delete_callback_context = NULL; delete_callback_context = NULL;
@ -243,7 +243,7 @@ bool test_ns_nvm_helper_delete()
bool test_ns_nvm_helper_concurrent_requests() bool test_ns_nvm_helper_concurrent_requests()
{ {
int ret_val; int ret_val;
write_callback_status = -1; write_callback_status = -1;
write_callback_context = NULL; write_callback_context = NULL;
@ -252,7 +252,7 @@ bool test_ns_nvm_helper_concurrent_requests()
delete_callback_status = -1; delete_callback_status = -1;
delete_callback_context = NULL; delete_callback_context = NULL;
// read ok // read ok
test_platform_nvm_api_set_retval(PLATFORM_NVM_OK); test_platform_nvm_api_set_retval(PLATFORM_NVM_OK);
nsdynmemlib_stub.returnCounter = 1; nsdynmemlib_stub.returnCounter = 1;
ret_val = ns_nvm_data_read(test_ns_nvm_helper_read_callback, key1, &buf, &buf_len, TEST_NS_NVM_HELPER_CONTEXT1); ret_val = ns_nvm_data_read(test_ns_nvm_helper_read_callback, key1, &buf, &buf_len, TEST_NS_NVM_HELPER_CONTEXT1);
@ -306,7 +306,7 @@ bool test_ns_nvm_helper_concurrent_requests()
bool test_ns_nvm_helper_platform_error() bool test_ns_nvm_helper_platform_error()
{ {
int ret_val; int ret_val;
write_callback_status = -1; write_callback_status = -1;
write_callback_context = NULL; write_callback_context = NULL;
@ -358,7 +358,7 @@ bool test_ns_nvm_helper_platform_error()
bool test_ns_nvm_helper_platform_error_in_write() bool test_ns_nvm_helper_platform_error_in_write()
{ {
int ret_val; int ret_val;
write_callback_status = -1; write_callback_status = -1;
write_callback_context = NULL; write_callback_context = NULL;

View File

@ -106,8 +106,7 @@ TEST(stoip6, InvalidAddresses)
uint8_t ip[16]; uint8_t ip[16];
uint8_t correct[16] = {0}; uint8_t correct[16] = {0};
const char *invalidArray[] = const char *invalidArray[] = {
{
"FFFF:FFFF::FFFF::FFFF", // Two :: "FFFF:FFFF::FFFF::FFFF", // Two ::
"F:F:F:FqF:F:F:F:F", // Non-hex character "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 "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 */ /* 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::1:0:0:1", // 1
"2001:db8:aaaa:bbbb:cccc:dddd:eeee:1", // 2 "2001:db8:aaaa:bbbb:cccc:dddd:eeee:1", // 2
"2001:db8::1", // 3 "2001:db8::1", // 3
@ -139,20 +137,19 @@ 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, 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, 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 }, { 0x20, 0x01, 0xd, 0xb8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
{ 0x20, 0x01, 0xd,0xb8, 0,0,0,0,0,0,0,0, 0,2,0,1 }, { 0x20, 0x01, 0xd, 0xb8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 1 },
{ 0x20, 0x01, 0xd, 0xb8, 0xaa, 0xaa, 0xbb, 0xbb, 0xcc, 0xcc, 0xdd, 0xdd, 0,0, 0x00, 0x01 }, { 0x20, 0x01, 0xd, 0xb8, 0xaa, 0xaa, 0xbb, 0xbb, 0xcc, 0xcc, 0xdd, 0xdd, 0, 0, 0x00, 0x01 },
{ 0x20, 0x01, 0xd, 0xb8, 0,0,0,0,0xaa,0xaa,0,0,0,0,0,1 }, { 0x20, 0x01, 0xd, 0xb8, 0, 0, 0, 0, 0xaa, 0xaa, 0, 0, 0, 0, 0, 1 },
{ 0x20, 0x01, 0,0 ,0,0 ,0,1,0,0,0,0,0,0,0,1 }, { 0x20, 0x01, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1 },
{ 0x20, 0x01, 0,0 ,0,0 ,0,1,0,0,0,0,0,0,0,0 }, { 0x20, 0x01, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0x20, 0x01, 0xd, 0xb8 }, { 0x20, 0x01, 0xd, 0xb8 },
{ 0,0,0,0,0,0,0,0,0xaa,0xaa,0,0,0,0,0,1 }, { 0, 0, 0, 0, 0, 0, 0, 0, 0xaa, 0xaa, 0, 0, 0, 0, 0, 1 },
{ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 }, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
{ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
}; };
char buf[40]; char buf[40];
@ -160,13 +157,11 @@ int i = 0;
TEST_GROUP(stoip6_2) TEST_GROUP(stoip6_2)
{ {
void setUp(void) void setUp(void) {
{
memset(buf, 0, 40); memset(buf, 0, 40);
} }
void tearDown(void) void tearDown(void) {
{
i++; i++;
} }
}; };
@ -240,8 +235,7 @@ TEST(stoip6_2, test_2_12)
/***********************************************************/ /***********************************************************/
/* Third test group for stoip6_prefix */ /* 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:db8::1:0:0:1/64", // 1
"2001::/60", // 2 "2001::/60", // 2
"::1/48", // 3 "::1/48", // 3
@ -254,12 +248,11 @@ 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, 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 { 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 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }, // 3
{ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }, // 4 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, // 4
{ 0x20, 0x02, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2 }, // 5 { 0x20, 0x02, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2 }, // 5
{ 0x20, 0x03, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3 }, // 6 { 0x20, 0x03, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3 }, // 6
{ 0x20, 0x04, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4 }, // 7 { 0x20, 0x04, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4 }, // 7

View File

@ -28,8 +28,8 @@ struct ip6_addresses_and_its_binary_form_t {
{ "2001:db8::2:1", { 0x20, 0x01, 0xd, 0xb8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 1 }}, { "2001:db8::2:1", { 0x20, 0x01, 0xd, 0xb8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 1 }},
{ "2001:db8:aaaa:bbbb:cccc:dddd:0:1", { 0x20, 0x01, 0xd, 0xb8, 0xaa, 0xaa, 0xbb, 0xbb, 0xcc, 0xcc, 0xdd, 0xdd, 0, 0, 0x00, 0x01 }}, { "2001:db8:aaaa:bbbb:cccc:dddd:0:1", { 0x20, 0x01, 0xd, 0xb8, 0xaa, 0xaa, 0xbb, 0xbb, 0xcc, 0xcc, 0xdd, 0xdd, 0, 0, 0x00, 0x01 }},
{ "2001:db8::aaaa:0:0:1", { 0x20, 0x01, 0xd, 0xb8, 0, 0, 0, 0, 0xaa, 0xaa, 0, 0, 0, 0, 0, 1 }}, { "2001:db8::aaaa:0:0:1", { 0x20, 0x01, 0xd, 0xb8, 0, 0, 0, 0, 0xaa, 0xaa, 0, 0, 0, 0, 0, 1 }},
{ "2001:0:0:1::1", { 0x20, 0x01, 0, 0 , 0, 0 , 0, 1, 0, 0, 0, 0, 0, 0, 0, 1 }}, { "2001:0:0:1::1", { 0x20, 0x01, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1 }},
{ "2001:0:0:1::", { 0x20, 0x01, 0, 0 , 0, 0 , 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 }}, { "2001:0:0:1::", { 0x20, 0x01, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 }},
{ "2001:db8::", { 0x20, 0x01, 0xd, 0xb8 }}, { "2001:db8::", { 0x20, 0x01, 0xd, 0xb8 }},
{ "::aaaa:0:0:1", { 0, 0, 0, 0, 0, 0, 0, 0, 0xaa, 0xaa, 0, 0, 0, 0, 0, 1 }}, { "::aaaa:0:0:1", { 0, 0, 0, 0, 0, 0, 0, 0, 0xaa, 0xaa, 0, 0, 0, 0, 0, 1 }},
{ "::1", { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }}, { "::1", { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }},

View File

@ -31,31 +31,25 @@ 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) 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--; nsdynmemlib_stub.returnCounter--;
return malloc(alloc_size); return malloc(alloc_size);
} } else {
else return (nsdynmemlib_stub.expectedPointer);
{
return(nsdynmemlib_stub.expectedPointer);
} }
} }
void *ns_dyn_mem_temporary_alloc(ns_mem_block_size_t alloc_size) 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--; nsdynmemlib_stub.returnCounter--;
return malloc(alloc_size); return malloc(alloc_size);
} } else {
else return (nsdynmemlib_stub.expectedPointer);
{
return(nsdynmemlib_stub.expectedPointer);
} }
} }
void ns_dyn_mem_free(void *block) void ns_dyn_mem_free(void *block)
{ {
free(block); free(block);
} }

View File

@ -24,7 +24,7 @@ extern "C" {
typedef struct { typedef struct {
uint8_t returnCounter; uint8_t returnCounter;
void* expectedPointer; void *expectedPointer;
} nsdynmemlib_stub_data_t; } nsdynmemlib_stub_data_t;
extern nsdynmemlib_stub_data_t nsdynmemlib_stub; extern nsdynmemlib_stub_data_t nsdynmemlib_stub;

View File

@ -40,9 +40,9 @@ extern "C" {
#define COAP_SERVICE_ACCESS_DELETE_ALLOWED 0x08 #define COAP_SERVICE_ACCESS_DELETE_ALLOWED 0x08
// Bits for service options // Bits for service options
#define COAP_SERVICE_OPTIONS_NONE 0x00 #define COAP_SERVICE_OPTIONS_NONE 0x00
#define COAP_SERVICE_OPTIONS_VIRTUAL_SOCKET 0x01 #define COAP_SERVICE_OPTIONS_VIRTUAL_SOCKET 0x01
#define COAP_SERVICE_OPTIONS_SECURE 0x02 #define COAP_SERVICE_OPTIONS_SECURE 0x02
#define COAP_SERVICE_OPTIONS_EPHEMERAL_PORT 0x04 #define COAP_SERVICE_OPTIONS_EPHEMERAL_PORT 0x04
/** Coap interface selected as socket interface */ /** Coap interface selected as socket interface */
#define COAP_SERVICE_OPTIONS_SELECT_SOCKET_IF 0x08 #define COAP_SERVICE_OPTIONS_SELECT_SOCKET_IF 0x08
@ -52,7 +52,7 @@ extern "C" {
#define COAP_SERVICE_OPTIONS_SECURE_BYPASS 0x80 #define COAP_SERVICE_OPTIONS_SECURE_BYPASS 0x80
// Bits for request options // Bits for request options
#define COAP_REQUEST_OPTIONS_NONE 0x00 #define COAP_REQUEST_OPTIONS_NONE 0x00
#define COAP_REQUEST_OPTIONS_ADDRESS_DEFAULT 0x00//!< default is not setting either short or long. #define COAP_REQUEST_OPTIONS_ADDRESS_DEFAULT 0x00//!< default is not setting either short or long.
#define COAP_REQUEST_OPTIONS_ADDRESS_LONG 0x01 #define COAP_REQUEST_OPTIONS_ADDRESS_LONG 0x01
#define COAP_REQUEST_OPTIONS_ADDRESS_SHORT 0x02 #define COAP_REQUEST_OPTIONS_ADDRESS_SHORT 0x02
@ -105,7 +105,7 @@ typedef int coap_service_request_recv_cb(int8_t service_id, uint8_t source_addre
* *
* \return 0 for success / -1 for failure * \return 0 for success / -1 for failure
*/ */
typedef int coap_service_security_start_cb(int8_t service_id, uint8_t address[static 16], uint16_t port, uint8_t* pw, uint8_t *pw_len); typedef int coap_service_security_start_cb(int8_t service_id, uint8_t address[static 16], uint16_t port, uint8_t *pw, uint8_t *pw_len);
/** /**
* \brief CoAP service security done callback * \brief CoAP service security done callback
@ -142,7 +142,7 @@ extern int8_t coap_service_initialize(int8_t interface_id, uint16_t listen_port,
* *
* \param service_id Id number of the current service. * \param service_id Id number of the current service.
*/ */
extern void coap_service_delete( int8_t service_id ); extern void coap_service_delete(int8_t service_id);
/** /**
* \brief Close secure connection * \brief Close secure connection
@ -243,7 +243,7 @@ extern int8_t coap_service_unregister_uri(int8_t service_id, const char *uri);
* \return msg_id Id number of the current message. * \return msg_id Id number of the current message.
*/ */
extern uint16_t coap_service_request_send(int8_t service_id, uint8_t options, const uint8_t destination_addr[static 16], uint16_t destination_port, sn_coap_msg_type_e msg_type, sn_coap_msg_code_e msg_code, const char *uri, extern uint16_t coap_service_request_send(int8_t service_id, uint8_t options, const uint8_t destination_addr[static 16], uint16_t destination_port, 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);
/** /**
* \brief Sends CoAP service response * \brief Sends CoAP service response
@ -261,7 +261,7 @@ extern uint16_t coap_service_request_send(int8_t service_id, uint8_t options, co
* \return -1 For failure * \return -1 For failure
*- 0 For success *- 0 For success
*/ */
extern int8_t coap_service_response_send(int8_t service_id, uint8_t options, sn_coap_hdr_s *request_ptr, sn_coap_msg_code_e message_code, sn_coap_content_format_e content_type, const uint8_t *payload_ptr,uint16_t payload_len); extern int8_t coap_service_response_send(int8_t service_id, uint8_t options, sn_coap_hdr_s *request_ptr, sn_coap_msg_code_e message_code, sn_coap_content_format_e content_type, const uint8_t *payload_ptr, uint16_t payload_len);
/** /**
* \brief Sends CoAP service response * \brief Sends CoAP service response
@ -280,9 +280,7 @@ extern int8_t coap_service_response_send(int8_t service_id, uint8_t options, sn_
* \return -1 For failure * \return -1 For failure
*- 0 For success *- 0 For success
*/ */
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); 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 * \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); 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 * \brief Set DTLS handshake timeout values
* *

View File

@ -32,7 +32,7 @@ typedef enum session_state_e {
SECURE_SESSION_HANDSHAKE_ONGOING = 0, SECURE_SESSION_HANDSHAKE_ONGOING = 0,
SECURE_SESSION_OK, SECURE_SESSION_OK,
SECURE_SESSION_CLOSED SECURE_SESSION_CLOSED
}session_state_t; } session_state_t;
typedef struct internal_socket_s { typedef struct internal_socket_s {
coap_conn_handler_t *parent; coap_conn_handler_t *parent;
@ -64,7 +64,7 @@ static NS_LIST_DEFINE(socket_list, internal_socket_t, link);
static uint8_t max_handshakes = MAX_ONGOING_HANDSHAKES; static uint8_t max_handshakes = MAX_ONGOING_HANDSHAKES;
static uint8_t max_sessions = MAX_SECURE_SESSION_COUNT; static uint8_t max_sessions = MAX_SECURE_SESSION_COUNT;
static void timer_cb(void* param); static void timer_cb(void *param);
static void recv_sckt_msg(void *cb_res); static void recv_sckt_msg(void *cb_res);
#ifdef COAP_SECURITY_AVAILABLE #ifdef COAP_SECURITY_AVAILABLE
@ -132,11 +132,11 @@ static void secure_session_delete(secure_session_t *this)
if (this) { if (this) {
ns_list_remove(&secure_session_list, this); ns_list_remove(&secure_session_list, this);
transactions_delete_all(this->remote_host.address, this->remote_host.identifier); transactions_delete_all(this->remote_host.address, this->remote_host.identifier);
if( this->sec_handler ){ if (this->sec_handler) {
coap_security_destroy(this->sec_handler); coap_security_destroy(this->sec_handler);
this->sec_handler = NULL; this->sec_handler = NULL;
} }
if(this->timer.timer){ if (this->timer.timer) {
eventOS_timeout_cancel(this->timer.timer); eventOS_timeout_cancel(this->timer.timer);
} }
ns_dyn_mem_free(this); ns_dyn_mem_free(this);
@ -160,21 +160,21 @@ static int8_t virtual_socket_id_allocate()
static secure_session_t *secure_session_create(internal_socket_t *parent, const uint8_t *address_ptr, uint16_t port, SecureConnectionMode secure_mode) static secure_session_t *secure_session_create(internal_socket_t *parent, const uint8_t *address_ptr, uint16_t port, SecureConnectionMode secure_mode)
{ {
uint8_t handshakes = 0; uint8_t handshakes = 0;
if(!address_ptr){ if (!address_ptr) {
return NULL; return NULL;
} }
if(max_sessions <= ns_list_count(&secure_session_list)){ if (max_sessions <= ns_list_count(&secure_session_list)) {
// Seek & destroy oldest session where close notify have been sent // Seek & destroy oldest session where close notify have been sent
secure_session_t *to_be_removed = NULL; secure_session_t *to_be_removed = NULL;
ns_list_foreach(secure_session_t, cur_ptr, &secure_session_list) { ns_list_foreach(secure_session_t, cur_ptr, &secure_session_list) {
if(cur_ptr->session_state == SECURE_SESSION_CLOSED){ if (cur_ptr->session_state == SECURE_SESSION_CLOSED) {
if(!to_be_removed || cur_ptr->last_contact_time < to_be_removed->last_contact_time){ if (!to_be_removed || cur_ptr->last_contact_time < to_be_removed->last_contact_time) {
to_be_removed = cur_ptr; to_be_removed = cur_ptr;
} }
} }
} }
if(!to_be_removed){ if (!to_be_removed) {
tr_err("max session count exceeded"); tr_err("max session count exceeded");
return NULL; return NULL;
} }
@ -184,11 +184,11 @@ static secure_session_t *secure_session_create(internal_socket_t *parent, const
// Count for ongoing handshakes // Count for ongoing handshakes
ns_list_foreach(secure_session_t, cur_ptr, &secure_session_list) { ns_list_foreach(secure_session_t, cur_ptr, &secure_session_list) {
if(cur_ptr->session_state == SECURE_SESSION_HANDSHAKE_ONGOING){ if (cur_ptr->session_state == SECURE_SESSION_HANDSHAKE_ONGOING) {
handshakes++; handshakes++;
} }
} }
if(handshakes >= max_handshakes) { if (handshakes >= max_handshakes) {
tr_err("ongoing handshakes exceeded"); tr_err("ongoing handshakes exceeded");
return NULL; return NULL;
} }
@ -201,8 +201,8 @@ static secure_session_t *secure_session_create(internal_socket_t *parent, const
uint8_t timer_id = 1; uint8_t timer_id = 1;
while(secure_session_find_by_timer_id(timer_id)){ while (secure_session_find_by_timer_id(timer_id)) {
if(timer_id == 0xff){ if (timer_id == 0xff) {
ns_dyn_mem_free(this); ns_dyn_mem_free(this);
return NULL; return NULL;
} }
@ -215,8 +215,8 @@ static secure_session_t *secure_session_create(internal_socket_t *parent, const
this->remote_host.identifier = port; this->remote_host.identifier = port;
this->sec_handler = coap_security_create(parent->socket, this->timer.id, this, secure_mode, this->sec_handler = coap_security_create(parent->socket, this->timer.id, this, secure_mode,
&secure_session_sendto, &secure_session_recvfrom, &start_timer, &timer_status); &secure_session_sendto, &secure_session_recvfrom, &start_timer, &timer_status);
if( !this->sec_handler ){ if (!this->sec_handler) {
tr_err("security create failed"); tr_err("security create failed");
ns_dyn_mem_free(this); ns_dyn_mem_free(this);
return NULL; return NULL;
@ -230,11 +230,12 @@ 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 ){ {
if (this) {
ns_list_foreach_safe(secure_session_t, cur_ptr, &secure_session_list) { ns_list_foreach_safe(secure_session_t, cur_ptr, &secure_session_list) {
if( cur_ptr->parent == this ){ if (cur_ptr->parent == this) {
coap_security_send_close_alert( cur_ptr->sec_handler ); coap_security_send_close_alert(cur_ptr->sec_handler);
secure_session_delete(cur_ptr); secure_session_delete(cur_ptr);
} }
} }
@ -245,9 +246,9 @@ static secure_session_t *secure_session_find(internal_socket_t *parent, const ui
{ {
secure_session_t *this = NULL; secure_session_t *this = NULL;
ns_list_foreach(secure_session_t, cur_ptr, &secure_session_list) { ns_list_foreach(secure_session_t, cur_ptr, &secure_session_list) {
if( cur_ptr->sec_handler ){ if (cur_ptr->sec_handler) {
if (cur_ptr->parent == parent && cur_ptr->remote_host.identifier == port && if (cur_ptr->parent == parent && cur_ptr->remote_host.identifier == port &&
memcmp(cur_ptr->remote_host.address, address_ptr, 16) == 0) { memcmp(cur_ptr->remote_host.address, address_ptr, 16) == 0) {
this = cur_ptr; this = cur_ptr;
break; break;
} }
@ -297,13 +298,13 @@ static internal_socket_t *int_socket_create(uint16_t listen_port, bool use_ephem
this->real_socket = real_socket; this->real_socket = real_socket;
this->bypass_link_sec = bypassSec; this->bypass_link_sec = bypassSec;
this->socket = -1; this->socket = -1;
if( real_socket ){ if (real_socket) {
if( use_ephemeral_port ){ //socket_api creates ephemeral port if the one provided is 0 if (use_ephemeral_port) { //socket_api creates ephemeral port if the one provided is 0
listen_port = 0; listen_port = 0;
} }
if( !is_secure ){ if (!is_secure) {
this->socket = socket_open(SOCKET_UDP, listen_port, recv_sckt_msg); this->socket = socket_open(SOCKET_UDP, listen_port, recv_sckt_msg);
}else{ } else {
#ifdef COAP_SECURITY_AVAILABLE #ifdef COAP_SECURITY_AVAILABLE
this->socket = socket_open(SOCKET_UDP, listen_port, secure_recv_sckt_msg); this->socket = socket_open(SOCKET_UDP, listen_port, secure_recv_sckt_msg);
#else #else
@ -311,18 +312,24 @@ static internal_socket_t *int_socket_create(uint16_t listen_port, bool use_ephem
#endif #endif
} }
// Socket create failed // Socket create failed
if(this->socket < 0){ if (this->socket < 0) {
ns_dyn_mem_free(this); ns_dyn_mem_free(this);
return NULL; 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 // 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 // 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) { if (socket_interface_selection > 0) {
// Interface selection requested as socket_interface_selection set // 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)); socket_setsockopt(this->socket, SOCKET_IPPROTO_IPV6, SOCKET_INTERFACE_SELECT, &socket_interface_selection, sizeof(socket_interface_selection));
@ -343,15 +350,15 @@ static void int_socket_delete(internal_socket_t *this)
{ {
if (this) { if (this) {
this->usage_counter--; this->usage_counter--;
if(this->usage_counter == 0){ if (this->usage_counter == 0) {
clear_secure_sessions(this); clear_secure_sessions(this);
socket_close(this->socket); socket_close(this->socket);
ns_list_remove(&socket_list, this); ns_list_remove(&socket_list, this);
if( this->data ){ if (this->data) {
ns_dyn_mem_free(this->data); ns_dyn_mem_free(this->data);
this->data = NULL; this->data = NULL;
} }
if(this->parent){ if (this->parent) {
ns_dyn_mem_free(this->parent); ns_dyn_mem_free(this->parent);
} }
ns_dyn_mem_free(this); ns_dyn_mem_free(this);
@ -363,7 +370,7 @@ static internal_socket_t *int_socket_find_by_socket_id(int8_t id)
{ {
internal_socket_t *this = NULL; internal_socket_t *this = NULL;
ns_list_foreach(internal_socket_t, cur_ptr, &socket_list) { ns_list_foreach(internal_socket_t, cur_ptr, &socket_list) {
if( cur_ptr->socket == id ) { if (cur_ptr->socket == id) {
this = cur_ptr; this = cur_ptr;
break; break;
} }
@ -377,8 +384,8 @@ static internal_socket_t *int_socket_find(uint16_t port, bool is_secure, bool is
internal_socket_t *this = NULL; internal_socket_t *this = NULL;
ns_list_foreach(internal_socket_t, cur_ptr, &socket_list) { ns_list_foreach(internal_socket_t, cur_ptr, &socket_list) {
if( cur_ptr->listen_port == port && cur_ptr->real_socket == is_real_socket && if (cur_ptr->listen_port == port && cur_ptr->real_socket == is_real_socket &&
is_secure == cur_ptr->is_secure /*&& bypass_link_sec == bypassSec*/) { is_secure == cur_ptr->is_secure /*&& bypass_link_sec == bypassSec*/) {
this = cur_ptr; this = cur_ptr;
break; break;
} }
@ -412,7 +419,7 @@ static int send_to_real_socket(int8_t socket_id, const ns_address_t *address, co
cmsg->cmsg_level = SOCKET_IPPROTO_IPV6; cmsg->cmsg_level = SOCKET_IPPROTO_IPV6;
cmsg->cmsg_len = NS_CMSG_LEN(sizeof(ns_in6_pktinfo_t)); cmsg->cmsg_len = NS_CMSG_LEN(sizeof(ns_in6_pktinfo_t));
pktinfo = (ns_in6_pktinfo_t*)NS_CMSG_DATA(cmsg); pktinfo = (ns_in6_pktinfo_t *)NS_CMSG_DATA(cmsg);
pktinfo->ipi6_ifindex = 0; pktinfo->ipi6_ifindex = 0;
memcpy(pktinfo->ipi6_addr, source_address, 16); memcpy(pktinfo->ipi6_addr, source_address, 16);
} }
@ -424,14 +431,15 @@ static int secure_session_sendto(int8_t socket_id, void *handle, const void *buf
{ {
secure_session_t *session = handle; secure_session_t *session = handle;
internal_socket_t *sock = int_socket_find_by_socket_id(socket_id); internal_socket_t *sock = int_socket_find_by_socket_id(socket_id);
if(!sock){ if (!sock) {
return -1; return -1;
} }
if(!sock->real_socket){ if (!sock->real_socket) {
// Send to virtual socket cb // Send to virtual socket cb
int ret = sock->parent->_send_cb(sock->socket, session->remote_host.address, session->remote_host.identifier, buf, len); 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 ret;
}
return len; return len;
} }
@ -457,7 +465,7 @@ static int secure_session_recvfrom(int8_t socket_id, unsigned char *buf, size_t
(void)len; (void)len;
internal_socket_t *sock = int_socket_find_by_socket_id(socket_id); internal_socket_t *sock = int_socket_find_by_socket_id(socket_id);
if (sock->data && sock->data_len > 0) { if (sock->data && sock->data_len > 0) {
memcpy( buf, sock->data, sock->data_len ); memcpy(buf, sock->data, sock->data_len);
int l = sock->data_len; int l = sock->data_len;
ns_dyn_mem_free(sock->data); ns_dyn_mem_free(sock->data);
sock->data = NULL; sock->data = NULL;
@ -477,21 +485,19 @@ static void timer_cb(void *param)
{ {
secure_session_t *sec = param; secure_session_t *sec = param;
if( sec && is_secure_session_valid(sec)){ if (sec && is_secure_session_valid(sec)) {
if(sec->timer.fin_ms > sec->timer.int_ms){ if (sec->timer.fin_ms > sec->timer.int_ms) {
/* Intermediate expiry */ /* Intermediate expiry */
sec->timer.fin_ms -= sec->timer.int_ms; sec->timer.fin_ms -= sec->timer.int_ms;
sec->timer.state = TIMER_STATE_INT_EXPIRY; sec->timer.state = TIMER_STATE_INT_EXPIRY;
int error = coap_security_handler_continue_connecting(sec->sec_handler); int error = coap_security_handler_continue_connecting(sec->sec_handler);
if(MBEDTLS_ERR_SSL_TIMEOUT == error) { if (MBEDTLS_ERR_SSL_TIMEOUT == error) {
//TODO: How do we handle timeouts? //TODO: How do we handle timeouts?
secure_session_delete(sec); secure_session_delete(sec);
} else {
sec->timer.timer = eventOS_timeout_ms(timer_cb, sec->timer.int_ms, (void *)sec);
} }
else{ } else {
sec->timer.timer = eventOS_timeout_ms(timer_cb, sec->timer.int_ms, (void*)sec);
}
}
else{
/* We have counted the number of cycles - finish */ /* We have counted the number of cycles - finish */
eventOS_timeout_cancel(sec->timer.timer); eventOS_timeout_cancel(sec->timer.timer);
sec->timer.fin_ms = 0; sec->timer.fin_ms = 0;
@ -499,7 +505,7 @@ static void timer_cb(void *param)
sec->timer.timer = NULL; sec->timer.timer = NULL;
sec->timer.state = TIMER_STATE_FIN_EXPIRY; sec->timer.state = TIMER_STATE_FIN_EXPIRY;
int error = coap_security_handler_continue_connecting(sec->sec_handler); int error = coap_security_handler_continue_connecting(sec->sec_handler);
if(MBEDTLS_ERR_SSL_TIMEOUT == error) { if (MBEDTLS_ERR_SSL_TIMEOUT == error) {
//TODO: How do we handle timeouts? //TODO: How do we handle timeouts?
secure_session_delete(sec); secure_session_delete(sec);
} }
@ -510,12 +516,12 @@ static void timer_cb(void *param)
static void start_timer(int8_t timer_id, uint32_t int_ms, uint32_t fin_ms) static void start_timer(int8_t timer_id, uint32_t int_ms, uint32_t fin_ms)
{ {
secure_session_t *sec = secure_session_find_by_timer_id(timer_id); secure_session_t *sec = secure_session_find_by_timer_id(timer_id);
if( sec ){ if (sec) {
if ((int_ms > 0) && (fin_ms > 0)) { if ((int_ms > 0) && (fin_ms > 0)) {
sec->timer.int_ms = int_ms; sec->timer.int_ms = int_ms;
sec->timer.fin_ms = fin_ms; sec->timer.fin_ms = fin_ms;
sec->timer.state = TIMER_STATE_NO_EXPIRY; sec->timer.state = TIMER_STATE_NO_EXPIRY;
if(sec->timer.timer){ if (sec->timer.timer) {
eventOS_timeout_cancel(sec->timer.timer); eventOS_timeout_cancel(sec->timer.timer);
} }
sec->timer.timer = eventOS_timeout_ms(timer_cb, int_ms, sec); sec->timer.timer = eventOS_timeout_ms(timer_cb, int_ms, sec);
@ -533,7 +539,7 @@ static void start_timer(int8_t timer_id, uint32_t int_ms, uint32_t fin_ms)
static int timer_status(int8_t timer_id) static int timer_status(int8_t timer_id)
{ {
secure_session_t *sec = secure_session_find_by_timer_id(timer_id); secure_session_t *sec = secure_session_find_by_timer_id(timer_id);
if( sec ){ if (sec) {
return (int)sec->timer.state; return (int)sec->timer.state;
} }
return TIMER_STATE_CANCELLED; return TIMER_STATE_CANCELLED;
@ -577,7 +583,7 @@ static int read_data(socket_callback_t *sckt_data, internal_socket_t *sock, ns_a
while (cmsg) { while (cmsg) {
switch (cmsg->cmsg_type) { switch (cmsg->cmsg_type) {
case SOCKET_IPV6_PKTINFO: case SOCKET_IPV6_PKTINFO:
pkt = (ns_in6_pktinfo_t*)NS_CMSG_DATA(cmsg); pkt = (ns_in6_pktinfo_t *)NS_CMSG_DATA(cmsg);
break; break;
default: default:
break; break;
@ -649,7 +655,7 @@ static void secure_recv_sckt_msg(void *cb_res)
session->last_contact_time = coap_service_get_internal_timer_ticks(); session->last_contact_time = coap_service_get_internal_timer_ticks();
// Start handshake // Start handshake
if (!coap_security_handler_is_started(session->sec_handler)) { if (!coap_security_handler_is_started(session->sec_handler)) {
if(-1 == coap_security_handler_connect_non_blocking(session->sec_handler, true, DTLS, keys, sock->timeout_min, sock->timeout_max)) { if (-1 == coap_security_handler_connect_non_blocking(session->sec_handler, true, DTLS, keys, sock->timeout_min, sock->timeout_max)) {
tr_err("Connection start failed"); tr_err("Connection start failed");
secure_session_delete(session); secure_session_delete(session);
} }
@ -664,22 +670,22 @@ static void secure_recv_sckt_msg(void *cb_res)
eventOS_timeout_cancel(session->timer.timer); eventOS_timeout_cancel(session->timer.timer);
session->timer.timer = NULL; session->timer.timer = NULL;
session->session_state = SECURE_SESSION_OK; session->session_state = SECURE_SESSION_OK;
if( sock->parent->_security_done_cb ){ if (sock->parent->_security_done_cb) {
sock->parent->_security_done_cb(sock->socket, src_address.address, sock->parent->_security_done_cb(sock->socket, src_address.address,
src_address.identifier, src_address.identifier,
(void *)coap_security_handler_keyblock(session->sec_handler)); (void *)coap_security_handler_keyblock(session->sec_handler));
} }
} else if (ret < 0){ } else if (ret < 0) {
// error handling // error handling
// TODO: here we also should clear CoAP retransmission buffer and inform that CoAP request sending is failed. // TODO: here we also should clear CoAP retransmission buffer and inform that CoAP request sending is failed.
secure_session_delete(session); secure_session_delete(session);
} }
//Session valid //Session valid
} else { } else {
unsigned char *data = ns_dyn_mem_temporary_alloc(sock->data_len); unsigned char *data = ns_dyn_mem_temporary_alloc(sock->data_len);
int len = 0; int len = 0;
len = coap_security_handler_read(session->sec_handler, data, sock->data_len); len = coap_security_handler_read(session->sec_handler, data, sock->data_len);
if( len < 0 ){ if (len < 0) {
if (len != MBEDTLS_ERR_SSL_WANT_READ && len != MBEDTLS_ERR_SSL_WANT_WRITE && if (len != MBEDTLS_ERR_SSL_WANT_READ && len != MBEDTLS_ERR_SSL_WANT_WRITE &&
len != MBEDTLS_ERR_SSL_UNEXPECTED_MESSAGE) { len != MBEDTLS_ERR_SSL_UNEXPECTED_MESSAGE) {
secure_session_delete(session); secure_session_delete(session);
@ -715,7 +721,7 @@ static void recv_sckt_msg(void *cb_res)
int coap_connection_handler_virtual_recv(coap_conn_handler_t *handler, uint8_t address[static 16], uint16_t port, uint8_t *data_ptr, uint16_t data_len) int coap_connection_handler_virtual_recv(coap_conn_handler_t *handler, uint8_t address[static 16], uint16_t port, uint8_t *data_ptr, uint16_t data_len)
{ {
if(!handler || !handler->socket) { if (!handler || !handler->socket) {
return -1; return -1;
} }
internal_socket_t *sock = handler->socket; internal_socket_t *sock = handler->socket;
@ -768,16 +774,15 @@ int coap_connection_handler_virtual_recv(coap_conn_handler_t *handler, uint8_t a
if (coap_security_handler_is_started(session->sec_handler)) { if (coap_security_handler_is_started(session->sec_handler)) {
if (session->session_state == SECURE_SESSION_HANDSHAKE_ONGOING) { if (session->session_state == SECURE_SESSION_HANDSHAKE_ONGOING) {
int ret = coap_security_handler_continue_connecting(session->sec_handler); int ret = coap_security_handler_continue_connecting(session->sec_handler);
if(ret == 0){ if (ret == 0) {
session->session_state = SECURE_SESSION_OK; session->session_state = SECURE_SESSION_OK;
if( handler->_security_done_cb ){ if (handler->_security_done_cb) {
handler->_security_done_cb(sock->socket, handler->_security_done_cb(sock->socket,
address, port, address, port,
(void *)coap_security_handler_keyblock(session->sec_handler)); (void *)coap_security_handler_keyblock(session->sec_handler));
} }
return 0; return 0;
} } else if (ret < 0) {
else if (ret < 0) {
// error handling // error handling
// TODO: here we also should clear CoAP retransmission buffer and inform that CoAP request sending is failed. // TODO: here we also should clear CoAP retransmission buffer and inform that CoAP request sending is failed.
secure_session_delete(session); secure_session_delete(session);
@ -819,16 +824,16 @@ int coap_connection_handler_virtual_recv(coap_conn_handler_t *handler, uint8_t a
} }
coap_conn_handler_t *connection_handler_create(receive_from_socket_cb *recv_from_cb, coap_conn_handler_t *connection_handler_create(receive_from_socket_cb *recv_from_cb,
send_to_socket_cb *send_to_cb, send_to_socket_cb *send_to_cb,
get_pw_cb *pw_cb, get_pw_cb *pw_cb,
security_done_cb *done_cb ) security_done_cb *done_cb)
{ {
if(recv_from_cb == NULL) { if (recv_from_cb == NULL) {
return NULL; return NULL;
} }
coap_conn_handler_t *handler = ns_dyn_mem_alloc(sizeof(coap_conn_handler_t)); coap_conn_handler_t *handler = ns_dyn_mem_alloc(sizeof(coap_conn_handler_t));
if(!handler){ if (!handler) {
return NULL; return NULL;
} }
memset(handler, 0, sizeof(coap_conn_handler_t)); memset(handler, 0, sizeof(coap_conn_handler_t));
@ -844,25 +849,25 @@ coap_conn_handler_t *connection_handler_create(receive_from_socket_cb *recv_from
void connection_handler_destroy(coap_conn_handler_t *handler, bool multicast_group_leave) void connection_handler_destroy(coap_conn_handler_t *handler, bool multicast_group_leave)
{ {
if(handler){ if (handler) {
if (multicast_group_leave) { if (multicast_group_leave) {
coap_multicast_group_join_or_leave(handler->socket->socket, SOCKET_IPV6_LEAVE_GROUP, handler->socket_interface_selection); coap_multicast_group_join_or_leave(handler->socket->socket, SOCKET_IPV6_LEAVE_GROUP, handler->socket_interface_selection);
} }
if (handler->security_keys) { if (handler->security_keys) {
ns_dyn_mem_free(handler->security_keys); ns_dyn_mem_free(handler->security_keys);
} }
int_socket_delete(handler->socket); int_socket_delete(handler->socket);
ns_dyn_mem_free(handler); ns_dyn_mem_free(handler);
} }
} }
void connection_handler_close_secure_connection( coap_conn_handler_t *handler, uint8_t destination_addr_ptr[static 16], uint16_t port ) void connection_handler_close_secure_connection(coap_conn_handler_t *handler, uint8_t destination_addr_ptr[static 16], uint16_t port)
{ {
if (handler) { if (handler) {
if (handler->socket && handler->socket->is_secure) { if (handler->socket && handler->socket->is_secure) {
secure_session_t *session = secure_session_find( handler->socket, destination_addr_ptr, port ); secure_session_t *session = secure_session_find(handler->socket, destination_addr_ptr, port);
if (session) { if (session) {
coap_security_send_close_alert( session->sec_handler ); coap_security_send_close_alert(session->sec_handler);
session->session_state = SECURE_SESSION_CLOSED; session->session_state = SECURE_SESSION_CLOSED;
session->last_contact_time = coap_service_get_internal_timer_ticks(); session->last_contact_time = coap_service_get_internal_timer_ticks();
} }
@ -883,7 +888,7 @@ int coap_connection_handler_open_connection(coap_conn_handler_t *handler, uint16
int_socket_delete(handler->socket); int_socket_delete(handler->socket);
} }
internal_socket_t *current = !use_ephemeral_port?int_socket_find(listen_port, is_secure, is_real_socket, bypassSec):NULL; internal_socket_t *current = !use_ephemeral_port ? int_socket_find(listen_port, is_secure, is_real_socket, bypassSec) : NULL;
if (!current) { if (!current) {
handler->socket = int_socket_create(listen_port, use_ephemeral_port, is_secure, is_real_socket, bypassSec, handler->socket_interface_selection, handler->registered_to_multicast); handler->socket = int_socket_create(listen_port, use_ephemeral_port, is_secure, is_real_socket, bypassSec, handler->socket_interface_selection, handler->registered_to_multicast);
if (!handler->socket) { if (!handler->socket) {
@ -918,7 +923,7 @@ int coap_connection_handler_send_data(coap_conn_handler_t *handler, const ns_add
memset(&security_material, 0, sizeof(coap_security_keys_t)); memset(&security_material, 0, sizeof(coap_security_keys_t));
if (!handler->_get_password_cb || 0 != handler->_get_password_cb(handler->socket->socket, (uint8_t*)dest_addr->address, dest_addr->identifier, &security_material)) { if (!handler->_get_password_cb || 0 != handler->_get_password_cb(handler->socket->socket, (uint8_t *)dest_addr->address, dest_addr->identifier, &security_material)) {
return -1; return -1;
} }
@ -932,11 +937,11 @@ int coap_connection_handler_send_data(coap_conn_handler_t *handler, const ns_add
} else if (session->session_state == SECURE_SESSION_OK) { } else if (session->session_state == SECURE_SESSION_OK) {
session->last_contact_time = coap_service_get_internal_timer_ticks(); session->last_contact_time = coap_service_get_internal_timer_ticks();
if (0 > coap_security_handler_send_message(session->sec_handler, data_ptr, data_len )) { if (0 > coap_security_handler_send_message(session->sec_handler, data_ptr, data_len)) {
return -1; return -1;
} }
} }
/* Unsecure */ /* Unsecure */
} else { } else {
/* Virtual socket */ /* Virtual socket */
if (!handler->socket->real_socket && handler->_send_cb) { if (!handler->socket->real_socket && handler->_send_cb) {
@ -964,11 +969,11 @@ int coap_connection_handler_send_data(coap_conn_handler_t *handler, const ns_add
bool coap_connection_handler_socket_belongs_to(coap_conn_handler_t *handler, int8_t socket_id) bool coap_connection_handler_socket_belongs_to(coap_conn_handler_t *handler, int8_t socket_id)
{ {
if( !handler || !handler->socket){ if (!handler || !handler->socket) {
return false; return false;
} }
if( handler->socket->socket == socket_id){ if (handler->socket->socket == socket_id) {
return true; return true;
} }
return false; return false;
@ -976,7 +981,7 @@ bool coap_connection_handler_socket_belongs_to(coap_conn_handler_t *handler, int
int8_t coap_connection_handler_set_timeout(coap_conn_handler_t *handler, uint32_t min, uint32_t max) int8_t coap_connection_handler_set_timeout(coap_conn_handler_t *handler, uint32_t min, uint32_t max)
{ {
if(!handler || !handler->socket){ if (!handler || !handler->socket) {
return -1; return -1;
} }
handler->socket->timeout_max = max; handler->socket->timeout_max = max;
@ -999,19 +1004,19 @@ int8_t coap_connection_handler_handshake_limits_set(uint8_t handshakes_limit, ui
/* No need to call every second - call rather like every minute (SECURE_SESSION_CLEAN_INTERVAL sets this) */ /* No need to call every second - call rather like every minute (SECURE_SESSION_CLEAN_INTERVAL sets this) */
void coap_connection_handler_exec(uint32_t time) void coap_connection_handler_exec(uint32_t time)
{ {
if(ns_list_count(&secure_session_list)){ if (ns_list_count(&secure_session_list)) {
// Seek & destroy old sessions where close notify have been sent // 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->session_state == SECURE_SESSION_CLOSED) {
if((cur_ptr->last_contact_time + CLOSED_SECURE_SESSION_TIMEOUT) <= time){ if ((cur_ptr->last_contact_time + CLOSED_SECURE_SESSION_TIMEOUT) <= time) {
secure_session_delete(cur_ptr); secure_session_delete(cur_ptr);
} }
} else if(cur_ptr->session_state == SECURE_SESSION_OK){ } else if (cur_ptr->session_state == SECURE_SESSION_OK) {
if((cur_ptr->last_contact_time + OPEN_SECURE_SESSION_TIMEOUT) <= time){ if ((cur_ptr->last_contact_time + OPEN_SECURE_SESSION_TIMEOUT) <= time) {
secure_session_delete(cur_ptr); secure_session_delete(cur_ptr);
} }
} else if(cur_ptr->session_state == SECURE_SESSION_HANDSHAKE_ONGOING){ } else if (cur_ptr->session_state == SECURE_SESSION_HANDSHAKE_ONGOING) {
if((cur_ptr->last_contact_time + ONGOING_HANDSHAKE_TIMEOUT) <= time){ if ((cur_ptr->last_contact_time + ONGOING_HANDSHAKE_TIMEOUT) <= time) {
secure_session_delete(cur_ptr); secure_session_delete(cur_ptr);
} }
} }

View File

@ -55,8 +55,8 @@ static coap_transaction_t *transaction_find_client_by_token(uint8_t *token, uint
ns_list_foreach(coap_transaction_t, cur_ptr, &request_list) { ns_list_foreach(coap_transaction_t, cur_ptr, &request_list) {
if ((cur_ptr->token_len == token_len) && (memcmp(cur_ptr->token, token, token_len) == 0) && cur_ptr->client_request) { if ((cur_ptr->token_len == token_len) && (memcmp(cur_ptr->token, token, token_len) == 0) && cur_ptr->client_request) {
this = cur_ptr; this = cur_ptr;
break; break;
} }
} }
return this; return this;
@ -98,6 +98,18 @@ static coap_transaction_t *transaction_find_by_address(uint8_t *address_ptr, uin
return this; 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: */ /* 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 */ /* Number of retransmisisons, each retransmission is 2 * previous retransmisison time */
/* + random factor (max. 1.5) */ /* + 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) 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; coap_transaction_t *this = NULL;
@ -173,7 +200,7 @@ static int8_t coap_rx_function(sn_coap_hdr_s *resp_ptr, sn_nsdl_addr_s *address_
if (!resp_ptr || !address_ptr) { if (!resp_ptr || !address_ptr) {
return -1; return -1;
} }
if(resp_ptr->token_ptr){ if (resp_ptr->token_ptr) {
this = transaction_find_client_by_token(resp_ptr->token_ptr, resp_ptr->token_len, address_ptr->addr_ptr, address_ptr->port); this = transaction_find_client_by_token(resp_ptr->token_ptr, resp_ptr->token_len, address_ptr->addr_ptr, address_ptr->port);
} }
if (!this) { if (!this) {
@ -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 *), 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)) { if ((used_malloc_func_ptr == NULL) || (used_free_func_ptr == NULL) || (used_tx_callback_ptr == NULL)) {
return NULL; return NULL;
@ -209,7 +237,7 @@ coap_msg_handler_t *coap_message_handler_init(void *(*used_malloc_func_ptr)(uint
handle->sn_coap_service_malloc = used_malloc_func_ptr; handle->sn_coap_service_malloc = used_malloc_func_ptr;
handle->coap = sn_coap_protocol_init(used_malloc_func_ptr, used_free_func_ptr, used_tx_callback_ptr, &coap_rx_function); handle->coap = sn_coap_protocol_init(used_malloc_func_ptr, used_free_func_ptr, used_tx_callback_ptr, &coap_rx_function);
if( !handle->coap ){ if (!handle->coap) {
ns_dyn_mem_free(handle); ns_dyn_mem_free(handle);
return NULL; return NULL;
} }
@ -226,12 +254,13 @@ coap_msg_handler_t *coap_message_handler_init(void *(*used_malloc_func_ptr)(uint
return handle; 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 ){ {
if (!handle) {
return -1; return -1;
} }
if( handle->coap ){ if (handle->coap) {
sn_coap_protocol_destroy(handle->coap); sn_coap_protocol_destroy(handle->coap);
} }
@ -258,13 +287,14 @@ 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) coap_transaction_t *coap_message_handler_find_transaction(uint8_t *address_ptr, uint16_t port)
{ {
if( !address_ptr ) if (!address_ptr) {
return NULL; return NULL;
return transaction_find_by_address( address_ptr, port ); }
return transaction_find_by_address(address_ptr, port);
} }
int16_t coap_message_handler_coap_msg_process(coap_msg_handler_t *handle, int8_t socket_id, const uint8_t source_addr_ptr[static 16], uint16_t port, const uint8_t dst_addr_ptr[static 16], int16_t coap_message_handler_coap_msg_process(coap_msg_handler_t *handle, int8_t socket_id, const uint8_t source_addr_ptr[static 16], uint16_t port, const uint8_t dst_addr_ptr[static 16],
uint8_t *data_ptr, uint16_t data_len, int16_t (cb)(int8_t, sn_coap_hdr_s *, coap_transaction_t *)) uint8_t *data_ptr, uint16_t data_len, int16_t (cb)(int8_t, sn_coap_hdr_s *, coap_transaction_t *))
{ {
sn_nsdl_addr_s src_addr; sn_nsdl_addr_s src_addr;
sn_coap_hdr_s *coap_message; sn_coap_hdr_s *coap_message;
@ -317,11 +347,12 @@ int16_t coap_message_handler_coap_msg_process(coap_msg_handler_t *handle, int8_t
} }
if (cb(socket_id, coap_message, transaction_ptr) < 0) { if (cb(socket_id, coap_message, transaction_ptr) < 0) {
// negative return value = message ignored -> delete transaction // negative return value = message ignored -> delete transaction
transaction_delete(transaction_ptr); transaction_delete(transaction_ptr);
} }
goto exit; goto exit;
/* Response received */ /* Response received */
} else { } else {
transaction_delete(transaction_ptr); // transaction_ptr not needed in response
if (coap_message->token_ptr) { if (coap_message->token_ptr) {
this = transaction_find_client_by_token(coap_message->token_ptr, coap_message->token_len, source_addr_ptr, port); this = transaction_find_client_by_token(coap_message->token_ptr, coap_message->token_len, source_addr_ptr, port);
} }
@ -349,8 +380,8 @@ exit:
} }
uint16_t coap_message_handler_request_send(coap_msg_handler_t *handle, int8_t service_id, uint8_t options, const uint8_t destination_addr[static 16], uint16_t coap_message_handler_request_send(coap_msg_handler_t *handle, int8_t service_id, uint8_t options, const uint8_t destination_addr[static 16],
uint16_t destination_port, sn_coap_msg_type_e msg_type, sn_coap_msg_code_e msg_code, const char *uri, 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_message_handler_response_recv *request_response_cb) sn_coap_content_format_e cont_type, const uint8_t *payload_ptr, uint16_t payload_len, coap_message_handler_response_recv *request_response_cb)
{ {
coap_transaction_t *transaction_ptr; coap_transaction_t *transaction_ptr;
sn_coap_hdr_s request; sn_coap_hdr_s request;
@ -385,10 +416,10 @@ uint16_t coap_message_handler_request_send(coap_msg_handler_t *handle, int8_t se
request.uri_path_len = strlen(uri); request.uri_path_len = strlen(uri);
request.content_format = cont_type; request.content_format = cont_type;
do{ do {
randLIB_get_n_bytes_random(token,4); randLIB_get_n_bytes_random(token, 4);
}while(transaction_find_client_by_token(token, 4, destination_addr, destination_port)); } while (transaction_find_client_by_token(token, 4, destination_addr, destination_port));
memcpy(transaction_ptr->token,token,4); memcpy(transaction_ptr->token, token, 4);
transaction_ptr->token_len = 4; transaction_ptr->token_len = 4;
request.token_ptr = transaction_ptr->token; request.token_ptr = transaction_ptr->token;
request.token_len = 4; request.token_len = 4;
@ -400,7 +431,7 @@ uint16_t coap_message_handler_request_send(coap_msg_handler_t *handle, int8_t se
data_len = sn_coap_builder_calc_needed_packet_data_size_2(&request, sn_coap_protocol_get_configured_blockwise_size(handle->coap)); data_len = sn_coap_builder_calc_needed_packet_data_size_2(&request, sn_coap_protocol_get_configured_blockwise_size(handle->coap));
data_ptr = own_alloc(data_len); data_ptr = own_alloc(data_len);
if(data_len > 0 && !data_ptr){ if (data_len > 0 && !data_ptr) {
transaction_delete(transaction_ptr); transaction_delete(transaction_ptr);
return 0; return 0;
} }
@ -423,11 +454,11 @@ uint16_t coap_message_handler_request_send(coap_msg_handler_t *handle, int8_t se
// Free allocated data // Free allocated data
own_free(data_ptr); own_free(data_ptr);
if(request.options_list_ptr) { if (request.options_list_ptr) {
own_free(request.options_list_ptr); own_free(request.options_list_ptr);
} }
if(request_response_cb == NULL){ if (request_response_cb == NULL) {
//No response expected //No response expected
return 0; return 0;
} }
@ -484,7 +515,7 @@ int8_t coap_message_handler_response_send(coap_msg_handler_t *handle, int8_t ser
} }
response = sn_coap_build_response(handle->coap, request_ptr, message_code); response = sn_coap_build_response(handle->coap, request_ptr, message_code);
if( !response ){ if (!response) {
return -1; return -1;
} }
response->payload_len = payload_len; response->payload_len = payload_len;
@ -494,14 +525,14 @@ int8_t coap_message_handler_response_send(coap_msg_handler_t *handle, int8_t ser
ret_val = coap_message_handler_resp_build_and_send(handle, response, transaction_ptr); ret_val = coap_message_handler_resp_build_and_send(handle, response, transaction_ptr);
sn_coap_parser_release_allocated_coap_msg_mem(handle->coap, response); sn_coap_parser_release_allocated_coap_msg_mem(handle->coap, response);
if(ret_val == 0) { if (ret_val == 0) {
transaction_delete(transaction_ptr); transaction_delete(transaction_ptr);
} }
return ret_val; return ret_val;
} }
int8_t coap_message_handler_response_send_by_msg_id(coap_msg_handler_t *handle, 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_message_handler_response_send_by_msg_id(coap_msg_handler_t *handle, 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)
{ {
sn_coap_hdr_s response; sn_coap_hdr_s response;
coap_transaction_t *transaction_ptr; coap_transaction_t *transaction_ptr;
@ -533,7 +564,7 @@ int8_t coap_message_handler_response_send_by_msg_id(coap_msg_handler_t *handle,
} }
ret_val = coap_message_handler_resp_build_and_send(handle, &response, transaction_ptr); ret_val = coap_message_handler_resp_build_and_send(handle, &response, transaction_ptr);
if(ret_val == 0) { if (ret_val == 0) {
transaction_delete(transaction_ptr); transaction_delete(transaction_ptr);
} }
@ -551,6 +582,7 @@ int8_t coap_message_handler_request_delete(coap_msg_handler_t *handle, int8_t se
tr_error("invalid params"); tr_error("invalid params");
return -1; return -1;
} }
sn_coap_protocol_delete_retransmission(handle->coap, msg_id); sn_coap_protocol_delete_retransmission(handle->coap, msg_id);
transaction_ptr = transaction_find_client(msg_id); transaction_ptr = transaction_find_client(msg_id);
@ -558,13 +590,32 @@ int8_t coap_message_handler_request_delete(coap_msg_handler_t *handle, int8_t se
tr_error("response transaction not found"); tr_error("response transaction not found");
return -2; 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); transaction_delete(transaction_ptr);
return 0; 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 ){ 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; return -1;
} }

View File

@ -84,32 +84,33 @@ static const int PSK_SUITES[] = {
#define TRACE_GROUP "CsSh" #define TRACE_GROUP "CsSh"
static void set_timer( void *sec_obj, uint32_t int_ms, uint32_t fin_ms ); static void set_timer(void *sec_obj, uint32_t int_ms, uint32_t fin_ms);
static int get_timer( void *sec_obj ); static int get_timer(void *sec_obj);
int entropy_poll( void *data, unsigned char *output, size_t len, size_t *olen ); int entropy_poll(void *data, unsigned char *output, size_t len, size_t *olen);
//Point these back to M2MConnectionHandler!!! //Point these back to M2MConnectionHandler!!!
int f_send( void *ctx, const unsigned char *buf, size_t len ); int f_send(void *ctx, const unsigned char *buf, size_t len);
int f_recv(void *ctx, 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"; const char *pers = "dtls_client";
#ifdef COAP_SERVICE_PROVIDE_STRONG_ENTROPY_SOURCE #ifdef COAP_SERVICE_PROVIDE_STRONG_ENTROPY_SOURCE
const int entropy_source_type = MBEDTLS_ENTROPY_SOURCE_STRONG; const int entropy_source_type = MBEDTLS_ENTROPY_SOURCE_STRONG;
#else #else
const int entropy_source_type = MBEDTLS_ENTROPY_SOURCE_WEAK; const int entropy_source_type = MBEDTLS_ENTROPY_SOURCE_WEAK;
#endif #endif
mbedtls_ssl_init( &sec->_ssl ); mbedtls_ssl_init(&sec->_ssl);
mbedtls_ssl_config_init( &sec->_conf ); mbedtls_ssl_config_init(&sec->_conf);
mbedtls_ctr_drbg_init( &sec->_ctr_drbg ); mbedtls_ctr_drbg_init(&sec->_ctr_drbg);
mbedtls_entropy_init( &sec->_entropy ); mbedtls_entropy_init(&sec->_entropy);
#if defined(MBEDTLS_X509_CRT_PARSE_C) #if defined(MBEDTLS_X509_CRT_PARSE_C)
mbedtls_x509_crt_init( &sec->_cacert ); mbedtls_x509_crt_init(&sec->_cacert);
mbedtls_x509_crt_init( &sec->_owncert ); mbedtls_x509_crt_init(&sec->_owncert);
mbedtls_pk_init( &sec->_pkey ); mbedtls_pk_init(&sec->_pkey);
#endif #endif
memset(&sec->_cookie, 0, sizeof(simple_cookie_t)); memset(&sec->_cookie, 0, sizeof(simple_cookie_t));
@ -117,15 +118,14 @@ static int coap_security_handler_init(coap_security_t *sec){
sec->_is_started = false; sec->_is_started = false;
if( mbedtls_entropy_add_source( &sec->_entropy, entropy_poll, NULL, if (mbedtls_entropy_add_source(&sec->_entropy, entropy_poll, NULL,
128, entropy_source_type ) < 0 ){ 128, entropy_source_type) < 0) {
return -1; return -1;
} }
if( ( mbedtls_ctr_drbg_seed( &sec->_ctr_drbg, mbedtls_entropy_func, &sec->_entropy, if ((mbedtls_ctr_drbg_seed(&sec->_ctr_drbg, mbedtls_entropy_func, &sec->_entropy,
(const unsigned char *) pers, (const unsigned char *) pers,
strlen( pers ) ) ) != 0 ) strlen(pers))) != 0) {
{
return -1; return -1;
} }
return 0; return 0;
@ -141,31 +141,32 @@ const void *coap_security_handler_keyblock(const coap_security_t *sec)
return sec->_keyblk.value; 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) #if defined(MBEDTLS_X509_CRT_PARSE_C)
mbedtls_x509_crt_free(&sec->_cacert); mbedtls_x509_crt_free(&sec->_cacert);
mbedtls_x509_crt_free(&sec->_owncert); mbedtls_x509_crt_free(&sec->_owncert);
mbedtls_pk_free(&sec->_pkey); mbedtls_pk_free(&sec->_pkey);
#endif #endif
mbedtls_entropy_free( &sec->_entropy ); mbedtls_entropy_free(&sec->_entropy);
mbedtls_ctr_drbg_free( &sec->_ctr_drbg ); mbedtls_ctr_drbg_free(&sec->_ctr_drbg);
mbedtls_ssl_config_free(&sec->_conf); mbedtls_ssl_config_free(&sec->_conf);
mbedtls_ssl_free(&sec->_ssl); mbedtls_ssl_free(&sec->_ssl);
} }
coap_security_t *coap_security_create(int8_t socket_id, int8_t timer_id, void *handle, SecureConnectionMode mode, coap_security_t *coap_security_create(int8_t socket_id, int8_t timer_id, void *handle, SecureConnectionMode mode,
send_cb *socket_cb, send_cb *socket_cb,
receive_cb *receive_data_cb, receive_cb *receive_data_cb,
start_timer_cb *timer_start_cb, start_timer_cb *timer_start_cb,
timer_status_cb *timer_stat_cb) timer_status_cb *timer_stat_cb)
{ {
if (socket_cb == NULL || receive_data_cb == NULL || timer_start_cb == NULL || timer_stat_cb == NULL) { if (socket_cb == NULL || receive_data_cb == NULL || timer_start_cb == NULL || timer_stat_cb == NULL) {
return NULL; return NULL;
} }
coap_security_t *this = ns_dyn_mem_alloc(sizeof(coap_security_t)); coap_security_t *this = ns_dyn_mem_alloc(sizeof(coap_security_t));
if( !this ){ if (!this) {
return NULL; return NULL;
} }
memset(this, 0, sizeof(coap_security_t)); memset(this, 0, sizeof(coap_security_t));
@ -187,8 +188,9 @@ coap_security_t *coap_security_create(int8_t socket_id, int8_t timer_id, void *h
return this; return this;
} }
void coap_security_destroy(coap_security_t *sec){ void coap_security_destroy(coap_security_t *sec)
if( sec ){ {
if (sec) {
coap_security_handler_reset(sec); coap_security_handler_reset(sec);
ns_dyn_mem_free(sec); ns_dyn_mem_free(sec);
sec = NULL; sec = NULL;
@ -259,8 +261,8 @@ static int simple_cookie_check(void *ctx,
(void)ilen; (void)ilen;
if ((p_cookie->len == 0) || if ((p_cookie->len == 0) ||
(clen != p_cookie->len) || (clen != p_cookie->len) ||
(memcmp(cookie, p_cookie->value, p_cookie->len) != 0)) { (memcmp(cookie, p_cookie->value, p_cookie->len) != 0)) {
return -1; /* This is what it is in mbedtls... */ return -1; /* This is what it is in mbedtls... */
} }
return 0; return 0;
@ -290,45 +292,45 @@ static int export_key_block(void *ctx,
} }
#endif #endif
static int coap_security_handler_configure_keys (coap_security_t *sec, coap_security_keys_t keys, bool is_server) static int coap_security_handler_configure_keys(coap_security_t *sec, coap_security_keys_t keys, bool is_server)
{ {
(void) is_server; (void) is_server;
int ret = -1; int ret = -1;
switch( sec->_conn_mode ){ switch (sec->_conn_mode) {
case CERTIFICATE:{ case CERTIFICATE: {
#if defined(MBEDTLS_X509_CRT_PARSE_C) #if defined(MBEDTLS_X509_CRT_PARSE_C)
if( keys._cert && mbedtls_x509_crt_parse( &sec->_owncert, keys._cert, keys._cert_len ) < 0 ){ if (keys._cert && mbedtls_x509_crt_parse(&sec->_owncert, keys._cert, keys._cert_len) < 0) {
break; break;
} }
if( mbedtls_pk_parse_key(&sec->_pkey, keys._priv_key, keys._priv_key_len, NULL, 0) < 0){ if (mbedtls_pk_parse_key(&sec->_pkey, keys._priv_key, keys._priv_key_len, NULL, 0) < 0) {
break; break;
} }
if (0 != mbedtls_ssl_conf_own_cert(&sec->_conf, &sec->_owncert, &sec->_pkey)) { if (0 != mbedtls_ssl_conf_own_cert(&sec->_conf, &sec->_owncert, &sec->_pkey)) {
break; break;
} }
mbedtls_ssl_conf_authmode( &sec->_conf, MBEDTLS_SSL_VERIFY_NONE ); mbedtls_ssl_conf_authmode(&sec->_conf, MBEDTLS_SSL_VERIFY_NONE);
mbedtls_ssl_conf_ca_chain( &sec->_conf, &sec->_owncert, NULL ); mbedtls_ssl_conf_ca_chain(&sec->_conf, &sec->_owncert, NULL);
ret = 0; ret = 0;
#endif #endif
break; break;
} }
case PSK: { case PSK: {
#if defined(MBEDTLS_KEY_EXCHANGE__SOME__PSK_ENABLED) #if defined(MBEDTLS_KEY_EXCHANGE__SOME__PSK_ENABLED)
if( 0 != mbedtls_ssl_conf_psk(&sec->_conf, keys._priv_key, keys._priv_key_len, keys._cert, keys._cert_len) ){ if (0 != mbedtls_ssl_conf_psk(&sec->_conf, keys._priv_key, keys._priv_key_len, keys._cert, keys._cert_len)) {
break; break;
} }
mbedtls_ssl_conf_ciphersuites(&sec->_conf, PSK_SUITES); mbedtls_ssl_conf_ciphersuites(&sec->_conf, PSK_SUITES);
ret = 0; ret = 0;
#endif #endif
break; break;
} }
case ECJPAKE: { case ECJPAKE: {
#if defined(MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED) #if defined(MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED)
if( mbedtls_ssl_set_hs_ecjpake_password(&sec->_ssl, keys._key, keys._key_len) != 0 ){ if (mbedtls_ssl_set_hs_ecjpake_password(&sec->_ssl, keys._key, keys._key_len) != 0) {
return -1; return -1;
} }
mbedtls_ssl_conf_ciphersuites(&sec->_conf, ECJPAKE_SUITES); mbedtls_ssl_conf_ciphersuites(&sec->_conf, ECJPAKE_SUITES);
@ -337,65 +339,62 @@ static int coap_security_handler_configure_keys (coap_security_t *sec, coap_secu
mbedtls_ssl_conf_export_keys_cb(&sec->_conf, mbedtls_ssl_conf_export_keys_cb(&sec->_conf,
export_key_block, export_key_block,
&sec->_keyblk); &sec->_keyblk);
ret = 0; ret = 0;
#endif #endif
break; break;
} }
default: default:
break; break;
} }
return ret; return ret;
} }
int coap_security_handler_connect_non_blocking(coap_security_t *sec, bool is_server, SecureSocketMode sock_mode, coap_security_keys_t keys, uint32_t timeout_min, uint32_t timeout_max) int coap_security_handler_connect_non_blocking(coap_security_t *sec, bool is_server, SecureSocketMode sock_mode, coap_security_keys_t keys, uint32_t timeout_min, uint32_t timeout_max)
{ {
if( !sec ){ if (!sec) {
return -1; return -1;
} }
sec->_is_blocking = false; sec->_is_blocking = false;
int endpoint = MBEDTLS_SSL_IS_CLIENT; int endpoint = MBEDTLS_SSL_IS_CLIENT;
if( is_server ){ if (is_server) {
endpoint = MBEDTLS_SSL_IS_SERVER; endpoint = MBEDTLS_SSL_IS_SERVER;
} }
int mode = MBEDTLS_SSL_TRANSPORT_DATAGRAM; int mode = MBEDTLS_SSL_TRANSPORT_DATAGRAM;
if( sock_mode == TLS ){ if (sock_mode == TLS) {
mode = MBEDTLS_SSL_TRANSPORT_STREAM; mode = MBEDTLS_SSL_TRANSPORT_STREAM;
} }
if( ( mbedtls_ssl_config_defaults( &sec->_conf, if ((mbedtls_ssl_config_defaults(&sec->_conf,
endpoint, endpoint,
mode, 0 ) ) != 0 ) mode, 0)) != 0) {
{
return -1; return -1;
} }
if(!timeout_max && !timeout_min){ if (!timeout_max && !timeout_min) {
mbedtls_ssl_conf_handshake_timeout( &sec->_conf, DTLS_HANDSHAKE_TIMEOUT_MIN, DTLS_HANDSHAKE_TIMEOUT_MAX ); 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_handshake_timeout( &sec->_conf, timeout_min, timeout_max );
} }
mbedtls_ssl_conf_rng( &sec->_conf, mbedtls_ctr_drbg_random, &sec->_ctr_drbg ); 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;
return -1;
} }
mbedtls_ssl_set_bio( &sec->_ssl, sec, mbedtls_ssl_set_bio(&sec->_ssl, sec,
f_send, f_recv, NULL ); f_send, f_recv, NULL);
mbedtls_ssl_set_timer_cb( &sec->_ssl, sec, set_timer, mbedtls_ssl_set_timer_cb(&sec->_ssl, sec, set_timer,
get_timer ); get_timer);
#if defined(MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED) #if defined(MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED)
//TODO: Figure out better way!!! //TODO: Figure out better way!!!
//Password should never be stored in multiple places!!! //Password should never be stored in multiple places!!!
if ((sec->_conn_mode == ECJPAKE) && is_server && keys._key_len > 0){ if ((sec->_conn_mode == ECJPAKE) && is_server && keys._key_len > 0) {
memcpy(sec->_pw, keys._key, keys._key_len); memcpy(sec->_pw, keys._key, keys._key_len);
sec->_pw_len = keys._key_len; sec->_pw_len = keys._key_len;
} }
@ -414,49 +413,49 @@ int coap_security_handler_connect_non_blocking(coap_security_t *sec, bool is_ser
mbedtls_ssl_conf_min_version(&sec->_conf, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3); mbedtls_ssl_conf_min_version(&sec->_conf, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3);
mbedtls_ssl_conf_max_version(&sec->_conf, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3); mbedtls_ssl_conf_max_version(&sec->_conf, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3);
sec->_is_started = true; sec->_is_started = true;
int ret = mbedtls_ssl_handshake_step( &sec->_ssl ); int ret = mbedtls_ssl_handshake_step(&sec->_ssl);
if( ret == 0 ){ if (ret == 0) {
ret = mbedtls_ssl_handshake_step( &sec->_ssl ); ret = mbedtls_ssl_handshake_step(&sec->_ssl);
if( is_server && 0 == ret){ if (is_server && 0 == ret) {
ret = coap_security_handler_continue_connecting( sec ); ret = coap_security_handler_continue_connecting(sec);
} }
} }
if( ret >= 0){ if (ret >= 0) {
ret = 1; ret = 1;
}else{ } else {
ret = -1; ret = -1;
} }
return ret; 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; int ret = -1;
while( ret != MBEDTLS_ERR_SSL_WANT_READ ){ while (ret != MBEDTLS_ERR_SSL_WANT_READ) {
ret = mbedtls_ssl_handshake_step( &sec->_ssl ); ret = mbedtls_ssl_handshake_step(&sec->_ssl);
if( MBEDTLS_ERR_SSL_HELLO_VERIFY_REQUIRED == ret){ if (MBEDTLS_ERR_SSL_HELLO_VERIFY_REQUIRED == ret) {
mbedtls_ssl_session_reset(&sec->_ssl); mbedtls_ssl_session_reset(&sec->_ssl);
#if defined(MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED) #if defined(MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED)
if( mbedtls_ssl_set_hs_ecjpake_password(&sec->_ssl, sec->_pw, sec->_pw_len) != 0 ){ if (mbedtls_ssl_set_hs_ecjpake_password(&sec->_ssl, sec->_pw, sec->_pw_len) != 0) {
return -1; return -1;
} }
#endif #endif
return 1; 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; return ret;
} }
if( sec->_ssl.state == MBEDTLS_SSL_HANDSHAKE_OVER ){ if (sec->_ssl.state == MBEDTLS_SSL_HANDSHAKE_OVER) {
return 0; return 0;
} }
} }
if(ret == MBEDTLS_ERR_SSL_WANT_READ || ret == MBEDTLS_ERR_SSL_WANT_WRITE){ if (ret == MBEDTLS_ERR_SSL_WANT_READ || ret == MBEDTLS_ERR_SSL_WANT_WRITE) {
return 1; return 1;
} }
@ -464,13 +463,15 @@ 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; {
int ret = -1;
if( sec ){ if (sec) {
do ret = mbedtls_ssl_write( &sec->_ssl, (unsigned char *) message, len ); do {
while( ret == MBEDTLS_ERR_SSL_WANT_READ || ret = mbedtls_ssl_write(&sec->_ssl, (unsigned char *) message, len);
ret == MBEDTLS_ERR_SSL_WANT_WRITE ); } while (ret == MBEDTLS_ERR_SSL_WANT_READ ||
ret == MBEDTLS_ERR_SSL_WANT_WRITE);
} }
return ret; //bytes written return ret; //bytes written
@ -478,27 +479,28 @@ int coap_security_handler_send_message(coap_security_t *sec, unsigned char *mess
int coap_security_send_close_alert(coap_security_t *sec) int coap_security_send_close_alert(coap_security_t *sec)
{ {
if( !sec ){ if (!sec) {
return -1; return -1;
} }
if(!mbedtls_ssl_close_notify(&sec->_ssl)){ if (!mbedtls_ssl_close_notify(&sec->_ssl)) {
return 0; return 0;
} }
return -1; 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 ret = -1;
int max_loops = 100; int max_loops = 100;
if( sec && buffer ){ if (sec && buffer) {
memset( buffer, 0, len ); memset(buffer, 0, len);
do { do {
ret = mbedtls_ssl_read( &sec->_ssl, buffer, len ); ret = mbedtls_ssl_read(&sec->_ssl, buffer, len);
} while( (ret == MBEDTLS_ERR_SSL_WANT_READ || } while ((ret == MBEDTLS_ERR_SSL_WANT_READ ||
ret == MBEDTLS_ERR_SSL_WANT_WRITE) ret == MBEDTLS_ERR_SSL_WANT_WRITE)
&& --max_loops); && --max_loops);
} }
return ret; //bytes read return ret; //bytes read
} }
@ -516,8 +518,8 @@ int coap_security_handler_read(coap_security_t *sec, unsigned char* buffer, size
static void set_timer(void *sec_obj, uint32_t int_ms, uint32_t fin_ms) static void set_timer(void *sec_obj, uint32_t int_ms, uint32_t fin_ms)
{ {
coap_security_t *sec = (coap_security_t *)sec_obj; coap_security_t *sec = (coap_security_t *)sec_obj;
if( sec->_start_timer_cb ){ if (sec->_start_timer_cb) {
sec->_start_timer_cb( sec->_timer_id, int_ms, fin_ms); sec->_start_timer_cb(sec->_timer_id, int_ms, fin_ms);
} }
} }
@ -531,41 +533,43 @@ static void set_timer(void *sec_obj, uint32_t int_ms, uint32_t fin_ms)
static int get_timer(void *sec_obj) static int get_timer(void *sec_obj)
{ {
coap_security_t *sec = (coap_security_t *)sec_obj; coap_security_t *sec = (coap_security_t *)sec_obj;
if( sec->_timer_status_cb ){ if (sec->_timer_status_cb) {
return sec->_timer_status_cb(sec->_timer_id); return sec->_timer_status_cb(sec->_timer_id);
} }
return -1; 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; coap_security_t *sec = (coap_security_t *)ctx;
return sec->_send_cb(sec->_socket_id, sec->_handle, buf, len); 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; coap_security_t *sec = (coap_security_t *)ctx;
return sec->_receive_cb(sec->_socket_id, buf, len); return sec->_receive_cb(sec->_socket_id, buf, len);
} }
int entropy_poll( void *ctx, unsigned char *output, size_t len, int entropy_poll(void *ctx, unsigned char *output, size_t len,
size_t *olen ) size_t *olen)
{ {
(void)ctx; (void)ctx;
//TODO: change to more secure random //TODO: change to more secure random
randLIB_seed_random(); randLIB_seed_random();
char *c = (char*)ns_dyn_mem_temporary_alloc(len); char *c = (char *)ns_dyn_mem_temporary_alloc(len);
if( !c ){ if (!c) {
return MBEDTLS_ERR_ENTROPY_SOURCE_FAILED; return MBEDTLS_ERR_ENTROPY_SOURCE_FAILED;
} }
memset(c, 0, len); memset(c, 0, len);
for(uint16_t i=0; i < len; i++){ for (uint16_t i = 0; i < len; i++) {
*(c + i) = (char)randLIB_get_8bit(); *(c + i) = (char)randLIB_get_8bit();
} }
memmove(output, c, len); memmove(output, c, len);
*olen = len; *olen = len;
ns_dyn_mem_free(c); ns_dyn_mem_free(c);
return( 0 ); return (0);
} }
#endif // COAP_SECURITY_AVAILABLE #endif // COAP_SECURITY_AVAILABLE

View File

@ -95,7 +95,7 @@ static coap_service_t *service_find_by_socket(int8_t socket_id)
{ {
coap_service_t *this = NULL; coap_service_t *this = NULL;
ns_list_foreach(coap_service_t, cur_ptr, &instance_list) { ns_list_foreach(coap_service_t, cur_ptr, &instance_list) {
if( coap_connection_handler_socket_belongs_to(cur_ptr->conn_handler, socket_id) ){ if (coap_connection_handler_socket_belongs_to(cur_ptr->conn_handler, socket_id)) {
this = cur_ptr; this = cur_ptr;
break; break;
} }
@ -177,7 +177,7 @@ static uint8_t coap_tx_function(uint8_t *data_ptr, uint16_t data_len, sn_nsdl_ad
dest_addr.type = ADDRESS_IPV6; dest_addr.type = ADDRESS_IPV6;
ret_val = coap_connection_handler_send_data(this->conn_handler, &dest_addr, transaction_ptr->local_address, ret_val = coap_connection_handler_send_data(this->conn_handler, &dest_addr, transaction_ptr->local_address,
data_ptr, data_len, (this->service_options & COAP_SERVICE_OPTIONS_SECURE_BYPASS) == COAP_SERVICE_OPTIONS_SECURE_BYPASS); data_ptr, data_len, (this->service_options & COAP_SERVICE_OPTIONS_SECURE_BYPASS) == COAP_SERVICE_OPTIONS_SECURE_BYPASS);
if (ret_val == 0) { if (ret_val == 0) {
if (!transaction_ptr->data_ptr) { if (!transaction_ptr->data_ptr) {
transaction_ptr->data_ptr = ns_dyn_mem_alloc(data_len); transaction_ptr->data_ptr = ns_dyn_mem_alloc(data_len);
@ -201,9 +201,10 @@ static void service_event_handler(arm_event_s *event)
tr_debug("service tasklet initialised"); tr_debug("service tasklet initialised");
/*initialize coap service and listen socket*/ /*initialize coap service and listen socket*/
} }
if (event->event_type == ARM_LIB_SYSTEM_TIMER_EVENT && event->event_id == COAP_TICK_TIMER) { if (event->event_type == ARM_LIB_SYSTEM_TIMER_EVENT && event->event_id == COAP_TICK_TIMER) {
coap_message_handler_exec(coap_service_handle, coap_ticks++); 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); coap_connection_handler_exec(coap_ticks);
} }
} }
@ -223,7 +224,7 @@ static int16_t coap_msg_process_callback(int8_t socket_id, sn_coap_hdr_s *coap_m
tr_debug("not registered uri %.*s", coap_message->uri_path_len, coap_message->uri_path_ptr); tr_debug("not registered uri %.*s", coap_message->uri_path_len, coap_message->uri_path_ptr);
if (coap_message->msg_type == COAP_MSG_TYPE_CONFIRMABLE) { if (coap_message->msg_type == COAP_MSG_TYPE_CONFIRMABLE) {
coap_message_handler_response_send(coap_service_handle, transaction_ptr->service_id, COAP_SERVICE_OPTIONS_NONE, coap_message, coap_message_handler_response_send(coap_service_handle, transaction_ptr->service_id, COAP_SERVICE_OPTIONS_NONE, coap_message,
COAP_MSG_CODE_RESPONSE_NOT_FOUND, COAP_CT_NONE, NULL, 0); COAP_MSG_CODE_RESPONSE_NOT_FOUND, COAP_CT_NONE, NULL, 0);
return 0; return 0;
} }
return -1; return -1;
@ -233,7 +234,7 @@ static int16_t coap_msg_process_callback(int8_t socket_id, sn_coap_hdr_s *coap_m
if (uri_reg_ptr && uri_reg_ptr->request_recv_cb) { if (uri_reg_ptr && uri_reg_ptr->request_recv_cb) {
tr_debug("Service %d, call request recv cb uri %.*s", this->service_id, coap_message->uri_path_len, coap_message->uri_path_ptr); tr_debug("Service %d, call request recv cb uri %.*s", this->service_id, coap_message->uri_path_len, coap_message->uri_path_ptr);
if ((this->service_options & COAP_SERVICE_OPTIONS_SECURE_BYPASS) == COAP_SERVICE_OPTIONS_SECURE_BYPASS ) {//TODO Add secure bypass option if ((this->service_options & COAP_SERVICE_OPTIONS_SECURE_BYPASS) == COAP_SERVICE_OPTIONS_SECURE_BYPASS) { //TODO Add secure bypass option
// Service has secure bypass active TODO this is not defined in interface // Service has secure bypass active TODO this is not defined in interface
// this check can be removed I think // this check can be removed I think
transaction_ptr->options = COAP_REQUEST_OPTIONS_SECURE_BYPASS; transaction_ptr->options = COAP_REQUEST_OPTIONS_SECURE_BYPASS;
@ -273,7 +274,7 @@ static int virtual_send_cb(int8_t socket_id, const uint8_t address[static 16], u
coap_service_t *this = service_find_by_socket(socket_id); coap_service_t *this = service_find_by_socket(socket_id);
if (this && this->virtual_socket_send_cb) { if (this && this->virtual_socket_send_cb) {
tr_debug("send to virtual socket, service: %d", this->service_id); tr_debug("send to virtual socket, service: %d", this->service_id);
return this->virtual_socket_send_cb(this->service_id, (uint8_t*)address, port, data_ptr, data_len); return this->virtual_socket_send_cb(this->service_id, (uint8_t *)address, port, data_ptr, data_len);
} }
return -1; return -1;
} }
@ -296,7 +297,7 @@ static void sec_done_cb(int8_t socket_id, uint8_t address[static 16], uint16_t p
dest_addr.type = ADDRESS_IPV6; dest_addr.type = ADDRESS_IPV6;
coap_connection_handler_send_data(this->conn_handler, &dest_addr, transaction_ptr->local_address, coap_connection_handler_send_data(this->conn_handler, &dest_addr, transaction_ptr->local_address,
transaction_ptr->data_ptr, transaction_ptr->data_len, (this->service_options & COAP_SERVICE_OPTIONS_SECURE_BYPASS) == COAP_SERVICE_OPTIONS_SECURE_BYPASS); transaction_ptr->data_ptr, transaction_ptr->data_len, (this->service_options & COAP_SERVICE_OPTIONS_SECURE_BYPASS) == COAP_SERVICE_OPTIONS_SECURE_BYPASS);
ns_dyn_mem_free(transaction_ptr->data_ptr); ns_dyn_mem_free(transaction_ptr->data_ptr);
transaction_ptr->data_ptr = NULL; transaction_ptr->data_ptr = NULL;
transaction_ptr->data_len = 0; transaction_ptr->data_len = 0;
@ -338,7 +339,7 @@ static int get_passwd_cb(int8_t socket_id, uint8_t address[static 16], uint16_t
} }
int8_t coap_service_initialize(int8_t interface_id, uint16_t listen_port, uint8_t service_options, int8_t coap_service_initialize(int8_t interface_id, uint16_t listen_port, uint8_t service_options,
coap_service_security_start_cb *start_ptr, coap_service_security_done_cb *coap_security_done_cb) coap_service_security_start_cb *start_ptr, coap_service_security_done_cb *coap_security_done_cb)
{ {
coap_service_t *this = ns_dyn_mem_alloc(sizeof(coap_service_t)); coap_service_t *this = ns_dyn_mem_alloc(sizeof(coap_service_t));
@ -365,7 +366,7 @@ int8_t coap_service_initialize(int8_t interface_id, uint16_t listen_port, uint8_
} }
this->conn_handler = connection_handler_create(recv_cb, virtual_send_cb, get_passwd_cb, sec_done_cb); this->conn_handler = connection_handler_create(recv_cb, virtual_send_cb, get_passwd_cb, sec_done_cb);
if(!this->conn_handler){ if (!this->conn_handler) {
ns_dyn_mem_free(this); ns_dyn_mem_free(this);
return -1; return -1;
} }
@ -378,10 +379,10 @@ int8_t coap_service_initialize(int8_t interface_id, uint16_t listen_port, uint8_
this->conn_handler->registered_to_multicast = this->service_options & COAP_SERVICE_OPTIONS_MULTICAST_JOIN; this->conn_handler->registered_to_multicast = this->service_options & COAP_SERVICE_OPTIONS_MULTICAST_JOIN;
if (0 > coap_connection_handler_open_connection(this->conn_handler, listen_port, if (0 > coap_connection_handler_open_connection(this->conn_handler, listen_port,
(this->service_options & COAP_SERVICE_OPTIONS_EPHEMERAL_PORT), (this->service_options & COAP_SERVICE_OPTIONS_EPHEMERAL_PORT),
(this->service_options & COAP_SERVICE_OPTIONS_SECURE), (this->service_options & COAP_SERVICE_OPTIONS_SECURE),
!(this->service_options & COAP_SERVICE_OPTIONS_VIRTUAL_SOCKET), !(this->service_options & COAP_SERVICE_OPTIONS_VIRTUAL_SOCKET),
(this->service_options & COAP_SERVICE_OPTIONS_SECURE_BYPASS))) { (this->service_options & COAP_SERVICE_OPTIONS_SECURE_BYPASS))) {
ns_dyn_mem_free(this->conn_handler); ns_dyn_mem_free(this->conn_handler);
ns_dyn_mem_free(this); ns_dyn_mem_free(this);
return -1; return -1;
@ -407,7 +408,7 @@ void coap_service_delete(int8_t service_id)
return; return;
} }
if (this->conn_handler){ if (this->conn_handler) {
bool leave_multicast_group = false; bool leave_multicast_group = false;
if (coap_service_can_leave_multicast_group(this->conn_handler)) { if (coap_service_can_leave_multicast_group(this->conn_handler)) {
// This is the last handler joined to multicast group // This is the last handler joined to multicast group
@ -434,7 +435,7 @@ extern void coap_service_close_secure_connection(int8_t service_id, uint8_t dest
if (!this || !destination_addr_ptr) { if (!this || !destination_addr_ptr) {
return; return;
} }
if (this->conn_handler){ if (this->conn_handler) {
connection_handler_close_secure_connection(this->conn_handler, destination_addr_ptr, port); connection_handler_close_secure_connection(this->conn_handler, destination_addr_ptr, port);
} }
} }
@ -475,7 +476,7 @@ int8_t coap_service_register_uri(int8_t service_id, const char *uri, uint8_t all
uri_reg_ptr = uri_registration_find(this, uri, uri_len); uri_reg_ptr = uri_registration_find(this, uri, uri_len);
if (!uri_reg_ptr) { if (!uri_reg_ptr) {
uri_reg_ptr = ns_dyn_mem_alloc(sizeof(uri_registration_t)); uri_reg_ptr = ns_dyn_mem_alloc(sizeof(uri_registration_t));
if( !uri_reg_ptr ){ if (!uri_reg_ptr) {
tr_error("Uri registration failed, OOM"); tr_error("Uri registration failed, OOM");
return -2; return -2;
} }
@ -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, 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! //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? //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); 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); 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); 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,10 +545,15 @@ 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); 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) 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); coap_service_t *this = service_find(service_id);
if(!this){ if (!this) {
return -1; return -1;
} }
@ -576,7 +585,7 @@ uint16_t coap_service_id_find_by_socket(int8_t socket_id)
{ {
coap_service_t *this = service_find_by_socket(socket_id); coap_service_t *this = service_find_by_socket(socket_id);
return this ? this->service_id:0; return this ? this->service_id : 0;
} }
int8_t coap_service_certificate_set(int8_t service_id, const unsigned char *cert, uint16_t cert_len, const unsigned char *priv_key, uint8_t priv_key_len) int8_t coap_service_certificate_set(int8_t service_id, const unsigned char *cert, uint16_t cert_len, const unsigned char *priv_key, uint8_t priv_key_len)

View File

@ -39,7 +39,7 @@ typedef int receive_from_socket_cb(int8_t socket_id, uint8_t src_address[static
typedef int get_pw_cb(int8_t socket_id, uint8_t address[static 16], uint16_t port, coap_security_keys_t *security_ptr); typedef int get_pw_cb(int8_t socket_id, uint8_t address[static 16], uint16_t port, coap_security_keys_t *security_ptr);
typedef void security_done_cb(int8_t socket_id, uint8_t address[static 16], uint16_t port, uint8_t keyblock[static 40]); typedef void security_done_cb(int8_t socket_id, uint8_t address[static 16], uint16_t port, uint8_t keyblock[static 40]);
typedef struct coap_conn_handler_s{ typedef struct coap_conn_handler_s {
struct internal_socket_s *socket; struct internal_socket_s *socket;
coap_security_keys_t *security_keys; coap_security_keys_t *security_keys;
@ -53,13 +53,13 @@ typedef struct coap_conn_handler_s{
} coap_conn_handler_t; } coap_conn_handler_t;
coap_conn_handler_t *connection_handler_create(receive_from_socket_cb *recv_from_cb, coap_conn_handler_t *connection_handler_create(receive_from_socket_cb *recv_from_cb,
send_to_socket_cb *send_to_cb, send_to_socket_cb *send_to_cb,
get_pw_cb *pw_cb, get_pw_cb *pw_cb,
security_done_cb *done_cb); security_done_cb *done_cb);
void connection_handler_destroy( coap_conn_handler_t *handler, bool multicast_group_leave); void connection_handler_destroy(coap_conn_handler_t *handler, bool multicast_group_leave);
void connection_handler_close_secure_connection( coap_conn_handler_t *handler, uint8_t destination_addr_ptr[static 16], uint16_t port ); void connection_handler_close_secure_connection(coap_conn_handler_t *handler, uint8_t destination_addr_ptr[static 16], uint16_t port);
int coap_connection_handler_open_connection(coap_conn_handler_t *handler, uint16_t listen_port, bool use_ephemeral_port, bool is_secure, bool real_socket, bool bypassSec); int coap_connection_handler_open_connection(coap_conn_handler_t *handler, uint16_t listen_port, bool use_ephemeral_port, bool is_secure, bool real_socket, bool bypassSec);

View File

@ -76,7 +76,7 @@ typedef struct coap_transaction {
extern coap_msg_handler_t *coap_message_handler_init(void *(*used_malloc_func_ptr)(uint16_t), void (*used_free_func_ptr)(void *), extern coap_msg_handler_t *coap_message_handler_init(void *(*used_malloc_func_ptr)(uint16_t), void (*used_free_func_ptr)(void *),
uint8_t (*used_tx_callback_ptr)(uint8_t *, uint16_t, sn_nsdl_addr_s *, void *)); uint8_t (*used_tx_callback_ptr)(uint8_t *, uint16_t, sn_nsdl_addr_s *, void *));
extern int8_t coap_message_handler_destroy(coap_msg_handler_t *handle); extern int8_t coap_message_handler_destroy(coap_msg_handler_t *handle);
@ -85,17 +85,19 @@ extern coap_transaction_t *coap_message_handler_transaction_valid(coap_transacti
extern coap_transaction_t *coap_message_handler_find_transaction(uint8_t *address_ptr, uint16_t port); extern coap_transaction_t *coap_message_handler_find_transaction(uint8_t *address_ptr, uint16_t port);
extern int16_t coap_message_handler_coap_msg_process(coap_msg_handler_t *handle, int8_t socket_id, const uint8_t source_addr_ptr[static 16], uint16_t port, const uint8_t dst_addr_ptr[static 16], extern int16_t coap_message_handler_coap_msg_process(coap_msg_handler_t *handle, int8_t socket_id, const uint8_t source_addr_ptr[static 16], uint16_t port, const uint8_t dst_addr_ptr[static 16],
uint8_t *data_ptr, uint16_t data_len, int16_t (cb)(int8_t, sn_coap_hdr_s *, coap_transaction_t *)); uint8_t *data_ptr, uint16_t data_len, int16_t (cb)(int8_t, sn_coap_hdr_s *, coap_transaction_t *));
extern uint16_t coap_message_handler_request_send(coap_msg_handler_t *handle, int8_t service_id, uint8_t options, const uint8_t destination_addr[static 16], extern uint16_t coap_message_handler_request_send(coap_msg_handler_t *handle, int8_t service_id, uint8_t options, const uint8_t destination_addr[static 16],
uint16_t destination_port, sn_coap_msg_type_e msg_type, sn_coap_msg_code_e msg_code, const char *uri, sn_coap_content_format_e cont_type, 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_message_handler_response_recv *request_response_cb); const uint8_t *payload_ptr, uint16_t payload_len, coap_message_handler_response_recv *request_response_cb);
extern int8_t coap_message_handler_response_send(coap_msg_handler_t *handle, int8_t service_id, uint8_t options, sn_coap_hdr_s *request_ptr, sn_coap_msg_code_e message_code, extern int8_t coap_message_handler_response_send(coap_msg_handler_t *handle, int8_t service_id, uint8_t options, sn_coap_hdr_s *request_ptr, sn_coap_msg_code_e message_code,
sn_coap_content_format_e content_type, const uint8_t *payload_ptr, uint16_t payload_len); sn_coap_content_format_e content_type, const uint8_t *payload_ptr, uint16_t payload_len);
extern int8_t coap_message_handler_request_delete(coap_msg_handler_t *handle, int8_t service_id, uint16_t msg_id); extern int8_t coap_message_handler_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 int8_t coap_message_handler_exec(coap_msg_handler_t *handle, uint32_t current_time);
extern void transaction_delete(coap_transaction_t *this); extern void transaction_delete(coap_transaction_t *this);
@ -103,6 +105,6 @@ extern void transaction_delete(coap_transaction_t *this);
extern void transactions_delete_all(uint8_t *address_ptr, uint16_t port); extern void transactions_delete_all(uint8_t *address_ptr, uint16_t port);
extern int8_t coap_message_handler_response_send_by_msg_id(coap_msg_handler_t *handle, int8_t service_id, uint8_t options, uint16_t msg_id, sn_coap_msg_code_e message_code, extern int8_t coap_message_handler_response_send_by_msg_id(coap_msg_handler_t *handle, 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); sn_coap_content_format_e content_type, const uint8_t *payload_ptr, uint16_t payload_len);
#endif #endif

View File

@ -55,13 +55,13 @@ typedef int timer_status_cb(int8_t timer_id);
typedef enum { typedef enum {
DTLS = 0, DTLS = 0,
TLS = 1 TLS = 1
}SecureSocketMode; } SecureSocketMode;
typedef enum { typedef enum {
CERTIFICATE, CERTIFICATE,
PSK, PSK,
ECJPAKE ECJPAKE
}SecureConnectionMode; } SecureConnectionMode;
typedef struct { typedef struct {
SecureConnectionMode mode; SecureConnectionMode mode;
@ -80,11 +80,11 @@ typedef struct coap_security_s coap_security_t;
#ifdef COAP_SECURITY_AVAILABLE #ifdef COAP_SECURITY_AVAILABLE
coap_security_t *coap_security_create(int8_t socket_id, int8_t timer_id, void *handle, coap_security_t *coap_security_create(int8_t socket_id, int8_t timer_id, void *handle,
SecureConnectionMode mode, SecureConnectionMode mode,
send_cb *send_cb, send_cb *send_cb,
receive_cb *receive_cb, receive_cb *receive_cb,
start_timer_cb *start_timer_cb, start_timer_cb *start_timer_cb,
timer_status_cb *timer_status_cb); timer_status_cb *timer_status_cb);
void coap_security_destroy(coap_security_t *sec); void coap_security_destroy(coap_security_t *sec);
@ -96,7 +96,7 @@ int coap_security_handler_send_message(coap_security_t *sec, unsigned char *mess
int coap_security_send_close_alert(coap_security_t *sec); int coap_security_send_close_alert(coap_security_t *sec);
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);
bool coap_security_handler_is_started(const coap_security_t *sec); bool coap_security_handler_is_started(const coap_security_t *sec);

View File

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

View File

@ -19,7 +19,7 @@
#include "CppUTest/TestPlugin.h" #include "CppUTest/TestPlugin.h"
#include "CppUTest/TestRegistry.h" #include "CppUTest/TestRegistry.h"
#include "CppUTestExt/MockSupportPlugin.h" #include "CppUTestExt/MockSupportPlugin.h"
int main(int ac, char** av) int main(int ac, char **av)
{ {
return CommandLineTestRunner::RunAllTests(ac, av); return CommandLineTestRunner::RunAllTests(ac, av);
} }

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() bool test_connection_handler_create()
{ {
coap_security_handler_stub.counter = -1; 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; 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; return false;
}
nsdynmemlib_stub.returnCounter = 1; nsdynmemlib_stub.returnCounter = 1;
coap_conn_handler_t *handler = connection_handler_create(&receive_from_sock_cb, NULL, NULL, NULL); coap_conn_handler_t *handler = connection_handler_create(&receive_from_sock_cb, NULL, NULL, NULL);
if( NULL == handler ) if (NULL == handler) {
return false; return false;
}
ns_dyn_mem_free(handler); ns_dyn_mem_free(handler);
return true; return true;
} }
@ -80,35 +83,42 @@ bool test_coap_connection_handler_open_connection()
nsdynmemlib_stub.returnCounter = 1; nsdynmemlib_stub.returnCounter = 1;
coap_conn_handler_t *handler = connection_handler_create(&receive_from_sock_cb, NULL, NULL, NULL); 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; 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; return false;
}
ns_dyn_mem_free(handler); ns_dyn_mem_free(handler);
nsdynmemlib_stub.returnCounter = 1; nsdynmemlib_stub.returnCounter = 1;
handler = connection_handler_create(&receive_from_sock_cb, &send_to_sock_cb, NULL, NULL); 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; return false;
}
nsdynmemlib_stub.returnCounter = 2; 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; return false;
}
nsdynmemlib_stub.returnCounter = 2; 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; return false;
}
//open second one //open second one
nsdynmemlib_stub.returnCounter = 1; nsdynmemlib_stub.returnCounter = 1;
coap_conn_handler_t *handler2 = connection_handler_create(&receive_from_sock_cb, &send_to_sock_cb, NULL, NULL); coap_conn_handler_t *handler2 = connection_handler_create(&receive_from_sock_cb, &send_to_sock_cb, NULL, NULL);
nsdynmemlib_stub.returnCounter = 2; 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; 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; return false;
}
connection_handler_destroy(handler2, false); connection_handler_destroy(handler2, false);
connection_handler_destroy(handler, false); connection_handler_destroy(handler, false);
@ -118,8 +128,9 @@ bool test_coap_connection_handler_open_connection()
bool test_coap_connection_handler_send_data() bool test_coap_connection_handler_send_data()
{ {
coap_security_handler_stub.counter = -1; 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; return false;
}
ns_address_t addr; ns_address_t addr;
memset(addr.address, 1, 16); memset(addr.address, 1, 16);
@ -128,11 +139,13 @@ bool test_coap_connection_handler_send_data()
nsdynmemlib_stub.returnCounter = 1; nsdynmemlib_stub.returnCounter = 1;
coap_conn_handler_t *handler = connection_handler_create(&receive_from_sock_cb, &send_to_sock_cb, NULL, NULL); coap_conn_handler_t *handler = connection_handler_create(&receive_from_sock_cb, &send_to_sock_cb, NULL, NULL);
nsdynmemlib_stub.returnCounter = 2; 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; 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; return false;
}
connection_handler_destroy(handler, false); connection_handler_destroy(handler, false);
@ -141,14 +154,17 @@ bool test_coap_connection_handler_send_data()
nsdynmemlib_stub.returnCounter = 1; nsdynmemlib_stub.returnCounter = 1;
handler = connection_handler_create(&receive_from_sock_cb, &send_to_sock_cb, NULL, NULL); handler = connection_handler_create(&receive_from_sock_cb, &send_to_sock_cb, NULL, NULL);
nsdynmemlib_stub.returnCounter = 4; 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; 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; 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; return false;
}
connection_handler_destroy(handler, false); connection_handler_destroy(handler, false);
@ -159,23 +175,27 @@ bool test_coap_connection_handler_send_data()
nsdynmemlib_stub.returnCounter = 1; nsdynmemlib_stub.returnCounter = 1;
handler = connection_handler_create(&receive_from_sock_cb, &send_to_sock_cb, NULL, NULL); handler = connection_handler_create(&receive_from_sock_cb, &send_to_sock_cb, NULL, NULL);
nsdynmemlib_stub.returnCounter = 2; 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; 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; return false;
connection_handler_destroy(handler ,false); }
connection_handler_destroy(handler, false);
nsdynmemlib_stub.returnCounter = 1; nsdynmemlib_stub.returnCounter = 1;
handler = connection_handler_create(&receive_from_sock_cb, &send_to_sock_cb, NULL, NULL); handler = connection_handler_create(&receive_from_sock_cb, &send_to_sock_cb, NULL, NULL);
nsdynmemlib_stub.returnCounter = 2; 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; return false;
}
socket_api_stub.int8_value = 7; 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; return false;
}
connection_handler_destroy(handler, false); connection_handler_destroy(handler, false);
//<-- NON SECURE HERE //<-- NON SECURE HERE
@ -188,65 +208,77 @@ bool test_coap_connection_handler_virtual_recv()
coap_security_handler_stub.counter = -1; coap_security_handler_stub.counter = -1;
uint8_t buf[16]; uint8_t buf[16];
memset(&buf, 1, 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; return false;
}
nsdynmemlib_stub.returnCounter = 1; nsdynmemlib_stub.returnCounter = 1;
coap_conn_handler_t *handler = connection_handler_create(&receive_from_sock_cb, &send_to_sock_cb, NULL, NULL); coap_conn_handler_t *handler = connection_handler_create(&receive_from_sock_cb, &send_to_sock_cb, NULL, NULL);
nsdynmemlib_stub.returnCounter = 2; 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; 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; return false;
}
nsdynmemlib_stub.returnCounter = 1; 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; return false;
}
ns_timer_stub.int8_value = 0; ns_timer_stub.int8_value = 0;
nsdynmemlib_stub.returnCounter = 3; 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; return false;
}
//handler->socket->data still in memory //handler->socket->data still in memory
coap_security_handler_stub.sec_obj = coap_security_handler_stub_alloc(); coap_security_handler_stub.sec_obj = coap_security_handler_stub_alloc();
ns_timer_stub.int8_value = -1; ns_timer_stub.int8_value = -1;
nsdynmemlib_stub.returnCounter = 3; 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; return false;
}
ns_timer_stub.int8_value = 0; ns_timer_stub.int8_value = 0;
nsdynmemlib_stub.returnCounter = 3; 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; return false;
}
connection_handler_destroy(handler, false); connection_handler_destroy(handler, false);
nsdynmemlib_stub.returnCounter = 1; 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); 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; 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; return false;
}
nsdynmemlib_stub.returnCounter = 3; 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; return false;
}
nsdynmemlib_stub.returnCounter = 1; nsdynmemlib_stub.returnCounter = 1;
coap_security_handler_stub.int_value = 0; 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; return false;
}
nsdynmemlib_stub.returnCounter = 1; 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; return false;
}
nsdynmemlib_stub.returnCounter = 1; nsdynmemlib_stub.returnCounter = 1;
coap_security_handler_stub.int_value = MBEDTLS_ERR_SSL_PEER_CLOSE_NOTIFY; 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; return false;
}
connection_handler_destroy(handler2, false); connection_handler_destroy(handler2, false);
@ -256,12 +288,14 @@ bool test_coap_connection_handler_virtual_recv()
nsdynmemlib_stub.returnCounter = 1; 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); 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; 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; return false;
}
nsdynmemlib_stub.returnCounter = 3; 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; return false;
}
connection_handler_destroy(handler3, 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() bool test_coap_connection_handler_socket_belongs_to()
{ {
coap_security_handler_stub.counter = -1; 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; return false;
}
socket_api_stub.int8_value = 0; socket_api_stub.int8_value = 0;
nsdynmemlib_stub.returnCounter = 1; nsdynmemlib_stub.returnCounter = 1;
coap_conn_handler_t *handler = connection_handler_create(&receive_from_sock_cb, &send_to_sock_cb, NULL, NULL); coap_conn_handler_t *handler = connection_handler_create(&receive_from_sock_cb, &send_to_sock_cb, NULL, NULL);
nsdynmemlib_stub.returnCounter = 2; 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; return false;
}
if( true != coap_connection_handler_socket_belongs_to(handler, 0) ) if (true != coap_connection_handler_socket_belongs_to(handler, 0)) {
return false; return false;
}
if( false != coap_connection_handler_socket_belongs_to(handler, 3) ) if (false != coap_connection_handler_socket_belongs_to(handler, 3)) {
return false; return false;
}
connection_handler_destroy(handler, false); connection_handler_destroy(handler, false);
nsdynmemlib_stub.returnCounter = 0; nsdynmemlib_stub.returnCounter = 0;
@ -301,8 +339,9 @@ bool test_timer_callbacks()
nsdynmemlib_stub.returnCounter = 1; nsdynmemlib_stub.returnCounter = 1;
coap_conn_handler_t *handler = connection_handler_create(&receive_from_sock_cb, &send_to_sock_cb, NULL, NULL); coap_conn_handler_t *handler = connection_handler_create(&receive_from_sock_cb, &send_to_sock_cb, NULL, NULL);
nsdynmemlib_stub.returnCounter = 2; 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; return false;
}
//handler->socket->data still in memory //handler->socket->data still in memory
coap_security_handler_stub.sec_obj = coap_security_handler_stub_alloc(); coap_security_handler_stub.sec_obj = coap_security_handler_stub_alloc();
@ -310,25 +349,28 @@ bool test_timer_callbacks()
ns_timer_stub.int8_value = 0; ns_timer_stub.int8_value = 0;
nsdynmemlib_stub.returnCounter = 3; nsdynmemlib_stub.returnCounter = 3;
ns_timer_stub.int8_value = 5; 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; return false;
}
//Note next tests will affect ns_timer test (cycle & cycle_count //Note next tests will affect ns_timer test (cycle & cycle_count
if( coap_security_handler_stub.start_timer_cb ){ if (coap_security_handler_stub.start_timer_cb) {
coap_security_handler_stub.start_timer_cb(1, 0, 0); coap_security_handler_stub.start_timer_cb(1, 0, 0);
coap_security_handler_stub.start_timer_cb(1, 1, 2); coap_security_handler_stub.start_timer_cb(1, 1, 2);
} }
if( coap_security_handler_stub.timer_status_cb ){ 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; return false;
}
if( 0 != coap_security_handler_stub.timer_status_cb(1) ) if (0 != coap_security_handler_stub.timer_status_cb(1)) {
return false; return false;
}
} }
if( ns_timer_stub.cb ){ if (ns_timer_stub.cb) {
ns_timer_stub.cb(4, 0); ns_timer_stub.cb(4, 0);
ns_timer_stub.cb(5, 0); ns_timer_stub.cb(5, 0);
@ -360,10 +402,11 @@ bool test_socket_api_callbacks()
nsdynmemlib_stub.returnCounter = 1; nsdynmemlib_stub.returnCounter = 1;
coap_conn_handler_t *handler = connection_handler_create(&receive_from_sock_cb, &send_to_sock_cb, NULL, NULL); coap_conn_handler_t *handler = connection_handler_create(&receive_from_sock_cb, &send_to_sock_cb, NULL, NULL);
nsdynmemlib_stub.returnCounter = 2; 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; return false;
}
if( socket_api_stub.recv_cb ){ if (socket_api_stub.recv_cb) {
sckt_data->event_type = SOCKET_DATA; sckt_data->event_type = SOCKET_DATA;
sckt_data->d_len = 1; sckt_data->d_len = 1;
socket_api_stub.int8_value = -1; socket_api_stub.int8_value = -1;
@ -382,10 +425,11 @@ bool test_socket_api_callbacks()
nsdynmemlib_stub.returnCounter = 1; 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); 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; 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; return false;
}
if( socket_api_stub.recv_cb ){ if (socket_api_stub.recv_cb) {
nsdynmemlib_stub.returnCounter = 1; nsdynmemlib_stub.returnCounter = 1;
socket_api_stub.int8_value = 1; socket_api_stub.int8_value = 1;
sckt_data->socket_id = 1; sckt_data->socket_id = 1;
@ -438,10 +482,11 @@ bool test_security_callbacks()
nsdynmemlib_stub.returnCounter = 1; nsdynmemlib_stub.returnCounter = 1;
coap_conn_handler_t *handler = connection_handler_create(&receive_from_sock_cb, &send_to_sock_cb, NULL, NULL); coap_conn_handler_t *handler = connection_handler_create(&receive_from_sock_cb, &send_to_sock_cb, NULL, NULL);
nsdynmemlib_stub.returnCounter = 2; 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; return false;
}
if( socket_api_stub.recv_cb ){ if (socket_api_stub.recv_cb) {
sckt_data->event_type = SOCKET_DATA; sckt_data->event_type = SOCKET_DATA;
sckt_data->d_len = 1; sckt_data->d_len = 1;
nsdynmemlib_stub.returnCounter = 2; nsdynmemlib_stub.returnCounter = 2;
@ -450,10 +495,10 @@ bool test_security_callbacks()
socket_api_stub.recv_cb(sckt_data); socket_api_stub.recv_cb(sckt_data);
} }
if( coap_security_handler_stub.send_cb ){ if (coap_security_handler_stub.send_cb) {
coap_security_handler_stub.send_cb(0, buf, 22, &buf, 16); coap_security_handler_stub.send_cb(0, buf, 22, &buf, 16);
} }
if( coap_security_handler_stub.receive_cb ){ if (coap_security_handler_stub.receive_cb) {
coap_security_handler_stub.receive_cb(0, &buf, 16); coap_security_handler_stub.receive_cb(0, &buf, 16);
} }

View File

@ -19,12 +19,10 @@
TEST_GROUP(coap_message_handler) 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()); 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) TEST(coap_message_handler, test_coap_message_handler_exec)
{ {
CHECK(test_coap_message_handler_exec()); CHECK(test_coap_message_handler_exec());

View File

@ -19,7 +19,7 @@
#include "CppUTest/TestPlugin.h" #include "CppUTest/TestPlugin.h"
#include "CppUTest/TestRegistry.h" #include "CppUTest/TestRegistry.h"
#include "CppUTestExt/MockSupportPlugin.h" #include "CppUTestExt/MockSupportPlugin.h"
int main(int ac, char** av) int main(int ac, char **av)
{ {
return CommandLineTestRunner::RunAllTests(ac, av); return CommandLineTestRunner::RunAllTests(ac, av);
} }

View File

@ -30,7 +30,7 @@ int transaction_cb = 0;
static void *test_own_alloc(uint16_t size) static void *test_own_alloc(uint16_t size)
{ {
if( retCounter > 0 ){ if (retCounter > 0) {
retCounter--; retCounter--;
return malloc(size); return malloc(size);
} }
@ -49,7 +49,8 @@ static uint8_t coap_tx_function(uint8_t *data_ptr, uint16_t data_len, sn_nsdl_ad
return 0; 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; 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() 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; 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; 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; 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; return false;
}
retCounter = 1; retCounter = 1;
sn_coap_protocol_stub.expectedCoap = NULL; 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; return false;
}
retCounter = 1; retCounter = 1;
sn_coap_protocol_stub.expectedCoap = (struct coap_s*)malloc(sizeof(struct coap_s)); sn_coap_protocol_stub.expectedCoap = (struct coap_s *)malloc(sizeof(struct coap_s));
memset(sn_coap_protocol_stub.expectedCoap, 0, sizeof(struct coap_s)); memset(sn_coap_protocol_stub.expectedCoap, 0, sizeof(struct coap_s));
nsdynmemlib_stub.returnCounter = 1; nsdynmemlib_stub.returnCounter = 1;
coap_msg_handler_t *handle = coap_message_handler_init(&test_own_alloc, &test_own_free, &coap_tx_function); 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; return false;
}
free(sn_coap_protocol_stub.expectedCoap); free(sn_coap_protocol_stub.expectedCoap);
sn_coap_protocol_stub.expectedCoap = NULL; sn_coap_protocol_stub.expectedCoap = NULL;
free(handle); free(handle);
@ -93,16 +100,18 @@ bool test_coap_message_handler_init()
bool test_coap_message_handler_destroy() bool test_coap_message_handler_destroy()
{ {
if( -1 != coap_message_handler_destroy(NULL) ) if (-1 != coap_message_handler_destroy(NULL)) {
return false; return false;
}
retCounter = 1; retCounter = 1;
sn_coap_protocol_stub.expectedCoap = (struct coap_s*)malloc(sizeof(struct coap_s)); sn_coap_protocol_stub.expectedCoap = (struct coap_s *)malloc(sizeof(struct coap_s));
memset(sn_coap_protocol_stub.expectedCoap, 0, sizeof(struct coap_s)); memset(sn_coap_protocol_stub.expectedCoap, 0, sizeof(struct coap_s));
nsdynmemlib_stub.returnCounter = 1; nsdynmemlib_stub.returnCounter = 1;
coap_msg_handler_t *handle = coap_message_handler_init(&test_own_alloc, &test_own_free, &coap_tx_function); 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; return false;
}
free(sn_coap_protocol_stub.expectedCoap); free(sn_coap_protocol_stub.expectedCoap);
return true; return true;
@ -110,10 +119,11 @@ bool test_coap_message_handler_destroy()
bool test_coap_message_handler_find_transaction() 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; return false;
}
retCounter = 1; retCounter = 1;
sn_coap_protocol_stub.expectedCoap = (struct coap_s*)malloc(sizeof(struct coap_s)); sn_coap_protocol_stub.expectedCoap = (struct coap_s *)malloc(sizeof(struct coap_s));
memset(sn_coap_protocol_stub.expectedCoap, 0, sizeof(struct coap_s)); memset(sn_coap_protocol_stub.expectedCoap, 0, sizeof(struct coap_s));
nsdynmemlib_stub.returnCounter = 1; nsdynmemlib_stub.returnCounter = 1;
coap_msg_handler_t *handle = coap_message_handler_init(&test_own_alloc, &test_own_free, &coap_tx_function); coap_msg_handler_t *handle = coap_message_handler_init(&test_own_alloc, &test_own_free, &coap_tx_function);
@ -127,11 +137,13 @@ bool test_coap_message_handler_find_transaction()
sn_coap_builder_stub.expectedUint16 = 1; sn_coap_builder_stub.expectedUint16 = 1;
nsdynmemlib_stub.returnCounter = 3; 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; return false;
}
if( NULL == coap_message_handler_find_transaction(&buf, 24)) if (NULL == coap_message_handler_find_transaction(&buf, 24)) {
return false; return false;
}
free(sn_coap_protocol_stub.expectedCoap); free(sn_coap_protocol_stub.expectedCoap);
sn_coap_protocol_stub.expectedCoap = NULL; sn_coap_protocol_stub.expectedCoap = NULL;
@ -145,27 +157,30 @@ bool test_coap_message_handler_coap_msg_process()
memset(&buf, 1, 16); memset(&buf, 1, 16);
bool ret_val = false; bool ret_val = false;
/*Handler is null*/ /*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; goto exit;
}
retCounter = 1; retCounter = 1;
sn_coap_protocol_stub.expectedCoap = (struct coap_s*)malloc(sizeof(struct coap_s)); sn_coap_protocol_stub.expectedCoap = (struct coap_s *)malloc(sizeof(struct coap_s));
memset(sn_coap_protocol_stub.expectedCoap, 0, sizeof(struct coap_s)); memset(sn_coap_protocol_stub.expectedCoap, 0, sizeof(struct coap_s));
nsdynmemlib_stub.returnCounter = 1; nsdynmemlib_stub.returnCounter = 1;
coap_msg_handler_t *handle = coap_message_handler_init(&test_own_alloc, &test_own_free, &coap_tx_function); coap_msg_handler_t *handle = coap_message_handler_init(&test_own_alloc, &test_own_free, &coap_tx_function);
sn_coap_protocol_stub.expectedHeader = NULL; sn_coap_protocol_stub.expectedHeader = NULL;
/* Coap parse returns 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; goto exit;
}
sn_coap_protocol_stub.expectedHeader = (sn_coap_hdr_s *)malloc(sizeof(sn_coap_hdr_s)); 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)); memset(sn_coap_protocol_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s));
sn_coap_protocol_stub.expectedHeader->coap_status = 66; sn_coap_protocol_stub.expectedHeader->coap_status = 66;
nsdynmemlib_stub.returnCounter = 1; nsdynmemlib_stub.returnCounter = 1;
/* Coap library responds */ /* 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; goto exit;
}
sn_coap_protocol_stub.expectedHeader = (sn_coap_hdr_s *)malloc(sizeof(sn_coap_hdr_s)); 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)); 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; retValue = 0;
/* request received */ /* request received */
nsdynmemlib_stub.returnCounter = 1; 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; goto exit;
}
sn_coap_protocol_stub.expectedHeader = (sn_coap_hdr_s *)malloc(sizeof(sn_coap_hdr_s)); 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)); 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; sn_coap_protocol_stub.expectedHeader->msg_code = 1;
nsdynmemlib_stub.returnCounter = 1; nsdynmemlib_stub.returnCounter = 1;
retValue = -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; goto exit;
}
sn_coap_protocol_stub.expectedHeader = (sn_coap_hdr_s *)malloc(sizeof(sn_coap_hdr_s)); 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)); 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; sn_coap_protocol_stub.expectedHeader->msg_code = 333;
nsdynmemlib_stub.returnCounter = 1; 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; goto exit;
}
sn_coap_protocol_stub.expectedHeader = (sn_coap_hdr_s *)malloc(sizeof(sn_coap_hdr_s)); 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)); 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; sn_coap_builder_stub.expectedUint16 = 1;
nsdynmemlib_stub.returnCounter = 3; 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; goto exit;
}
sn_coap_protocol_stub.expectedHeader->msg_id = 2; 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; goto exit;
}
ret_val = true; ret_val = true;
exit: exit:
@ -226,68 +246,77 @@ exit:
bool test_coap_message_handler_request_send() bool test_coap_message_handler_request_send()
{ {
retCounter = 1; retCounter = 1;
sn_coap_protocol_stub.expectedCoap = (struct coap_s*)malloc(sizeof(struct coap_s)); sn_coap_protocol_stub.expectedCoap = (struct coap_s *)malloc(sizeof(struct coap_s));
memset(sn_coap_protocol_stub.expectedCoap, 0, sizeof(struct coap_s)); memset(sn_coap_protocol_stub.expectedCoap, 0, sizeof(struct coap_s));
nsdynmemlib_stub.returnCounter = 1; nsdynmemlib_stub.returnCounter = 1;
coap_msg_handler_t *handle = coap_message_handler_init(&test_own_alloc, &test_own_free, &coap_tx_function); coap_msg_handler_t *handle = coap_message_handler_init(&test_own_alloc, &test_own_free, &coap_tx_function);
uint8_t buf[16]; uint8_t buf[16];
memset(&buf, 1, 16); memset(&buf, 1, 16);
char uri[3]; char uri[3] = "rs";
uri[0] = "r";
uri[1] = "s"; if (0 != coap_message_handler_request_send(handle, 3, 0, buf, 24, 1, 2, &uri, 4, NULL, 0, NULL)) {
uri[2] = "\0";
if( 0 != coap_message_handler_request_send(handle, 3, 0, buf, 24, 1, 2, &uri, 4, NULL, 0, NULL))
return false; return false;
}
sn_coap_builder_stub.expectedUint16 = 1; sn_coap_builder_stub.expectedUint16 = 1;
nsdynmemlib_stub.returnCounter = 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; return false;
}
sn_coap_builder_stub.expectedUint16 = 1; sn_coap_builder_stub.expectedUint16 = 1;
nsdynmemlib_stub.returnCounter = 3; 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; return false;
}
sn_coap_builder_stub.expectedUint16 = 1; sn_coap_builder_stub.expectedUint16 = 1;
nsdynmemlib_stub.returnCounter = 3; 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; return false;
}
sn_coap_builder_stub.expectedUint16 = 1; sn_coap_builder_stub.expectedUint16 = 1;
nsdynmemlib_stub.returnCounter = 3; 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; return false;
}
/* Clear all transactions */ /* Clear all transactions */
if( 0 != coap_message_handler_exec(handle, 0xffffffff)) if (0 != coap_message_handler_exec(handle, 0xffffffff)) {
return false; return false;
}
sn_coap_protocol_stub.expectedInt16 = -4; sn_coap_protocol_stub.expectedInt16 = -4;
nsdynmemlib_stub.returnCounter = 3; 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; return false;
}
transaction_cb = 0; transaction_cb = 0;
sn_coap_protocol_stub.expectedInt8 = 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; return false;
}
if (transaction_cb != 1) if (transaction_cb != 1) {
return false; return false;
}
sn_coap_protocol_stub.expectedInt16 = -2; sn_coap_protocol_stub.expectedInt16 = -2;
nsdynmemlib_stub.returnCounter = 3; 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; return false;
} }
if (transaction_cb != 1)
transaction_cb = 0;
if (0 != coap_message_handler_exec(handle, 2)) {
return false; return false;
}
if (transaction_cb != 1) {
return false;
}
free(sn_coap_protocol_stub.expectedCoap); free(sn_coap_protocol_stub.expectedCoap);
@ -299,7 +328,7 @@ bool test_coap_message_handler_request_send()
bool test_coap_message_handler_request_delete() bool test_coap_message_handler_request_delete()
{ {
retCounter = 1; retCounter = 1;
sn_coap_protocol_stub.expectedCoap = (struct coap_s*)malloc(sizeof(struct coap_s)); sn_coap_protocol_stub.expectedCoap = (struct coap_s *)malloc(sizeof(struct coap_s));
memset(sn_coap_protocol_stub.expectedCoap, 0, sizeof(struct coap_s)); memset(sn_coap_protocol_stub.expectedCoap, 0, sizeof(struct coap_s));
nsdynmemlib_stub.returnCounter = 1; nsdynmemlib_stub.returnCounter = 1;
coap_msg_handler_t *handle = coap_message_handler_init(&test_own_alloc, &test_own_free, &coap_tx_function); coap_msg_handler_t *handle = coap_message_handler_init(&test_own_alloc, &test_own_free, &coap_tx_function);
@ -310,19 +339,23 @@ bool test_coap_message_handler_request_delete()
uri[0] = "r"; uri[0] = "r";
uri[1] = "s"; uri[1] = "s";
uri[2] = "\0"; 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; return false;
}
if( 0 == coap_message_handler_request_delete(handle, 1, 1)) if (0 == coap_message_handler_request_delete(handle, 1, 1)) {
return false; return false;
}
sn_coap_builder_stub.expectedUint16 = 1; sn_coap_builder_stub.expectedUint16 = 1;
nsdynmemlib_stub.returnCounter = 3; 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; return false;
}
if( 0 != coap_message_handler_request_delete(handle, 1, 2)) if (0 != coap_message_handler_request_delete(handle, 1, 2)) {
return false; return false;
}
free(sn_coap_protocol_stub.expectedCoap); free(sn_coap_protocol_stub.expectedCoap);
sn_coap_protocol_stub.expectedCoap = NULL; sn_coap_protocol_stub.expectedCoap = NULL;
@ -330,21 +363,61 @@ bool test_coap_message_handler_request_delete()
return true; 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() 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; return false;
}
retCounter = 1; retCounter = 1;
sn_coap_protocol_stub.expectedCoap = (struct coap_s*)malloc(sizeof(struct coap_s)); sn_coap_protocol_stub.expectedCoap = (struct coap_s *)malloc(sizeof(struct coap_s));
memset(sn_coap_protocol_stub.expectedCoap, 0, sizeof(struct coap_s)); memset(sn_coap_protocol_stub.expectedCoap, 0, sizeof(struct coap_s));
nsdynmemlib_stub.returnCounter = 1; nsdynmemlib_stub.returnCounter = 1;
coap_msg_handler_t *handle = coap_message_handler_init(&test_own_alloc, &test_own_free, &coap_tx_function); coap_msg_handler_t *handle = coap_message_handler_init(&test_own_alloc, &test_own_free, &coap_tx_function);
sn_coap_hdr_s *header = (sn_coap_hdr_s *)malloc(sizeof(sn_coap_hdr_s)); sn_coap_hdr_s *header = (sn_coap_hdr_s *)malloc(sizeof(sn_coap_hdr_s));
memset(header, 0, 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; return false;
}
uint8_t buf[16]; uint8_t buf[16];
memset(&buf, 1, 16); memset(&buf, 1, 16);
@ -354,30 +427,34 @@ bool test_coap_message_handler_response_send()
uri[2] = "\0"; uri[2] = "\0";
sn_coap_builder_stub.expectedUint16 = 1; sn_coap_builder_stub.expectedUint16 = 1;
nsdynmemlib_stub.returnCounter = 3; 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; return false;
}
header->msg_id = 2; header->msg_id = 2;
sn_coap_builder_stub.expectedUint16 = 2; sn_coap_builder_stub.expectedUint16 = 2;
coap_transaction_t * tx = coap_message_handler_find_transaction(&buf, 24); coap_transaction_t *tx = coap_message_handler_find_transaction(&buf, 24);
if( tx ){ if (tx) {
tx->client_request = false; tx->client_request = false;
} }
sn_coap_builder_stub.expectedHeader = NULL; 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; return false;
}
sn_coap_builder_stub.expectedHeader = (sn_coap_hdr_s *)malloc(sizeof(sn_coap_hdr_s)); 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)); memset(sn_coap_builder_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s));
nsdynmemlib_stub.returnCounter = 0; 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; return false;
}
sn_coap_builder_stub.expectedHeader = (sn_coap_hdr_s *)malloc(sizeof(sn_coap_hdr_s)); 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)); memset(sn_coap_builder_stub.expectedHeader, 0, sizeof(sn_coap_hdr_s));
nsdynmemlib_stub.returnCounter = 1; 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; return false;
}
free(header); free(header);
free(sn_coap_protocol_stub.expectedCoap); free(sn_coap_protocol_stub.expectedCoap);
@ -389,52 +466,62 @@ bool test_coap_message_handler_response_send()
bool test_coap_message_handler_exec() bool test_coap_message_handler_exec()
{ {
/* Null as a parameter */ /* Null as a parameter */
if( -1 != coap_message_handler_exec(NULL, 0)) if (-1 != coap_message_handler_exec(NULL, 0)) {
return false; return false;
}
retCounter = 1; retCounter = 1;
sn_coap_protocol_stub.expectedCoap = (struct coap_s*)malloc(sizeof(struct coap_s)); sn_coap_protocol_stub.expectedCoap = (struct coap_s *)malloc(sizeof(struct coap_s));
memset(sn_coap_protocol_stub.expectedCoap, 0, sizeof(struct coap_s)); memset(sn_coap_protocol_stub.expectedCoap, 0, sizeof(struct coap_s));
nsdynmemlib_stub.returnCounter = 1; nsdynmemlib_stub.returnCounter = 1;
coap_msg_handler_t *handle = coap_message_handler_init(&test_own_alloc, &test_own_free, &coap_tx_function); 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; return false;
}
nsdynmemlib_stub.returnCounter = 1; nsdynmemlib_stub.returnCounter = 1;
coap_transaction_t *transact_ptr = transaction_create(); coap_transaction_t *transact_ptr = transaction_create();
/* Transaction not timed out*/ /* Transaction not timed out*/
if( 0 != coap_message_handler_exec(handle, 0)) if (0 != coap_message_handler_exec(handle, 0)) {
return false; return false;
}
if (transaction_cb != 0) if (transaction_cb != 0) {
return false; return false;
}
/* Timed out, no CB */ /* Timed out, no CB */
if( 0 != coap_message_handler_exec(handle, 300)) if (0 != coap_message_handler_exec(handle, 300)) {
return false; return false;
}
if (transaction_cb != 0) if (transaction_cb != 0) {
return false; return false;
}
nsdynmemlib_stub.returnCounter = 1; nsdynmemlib_stub.returnCounter = 1;
transact_ptr = transaction_create(); transact_ptr = transaction_create();
transact_ptr->resp_cb = transaction_recv_cb; transact_ptr->resp_cb = transaction_recv_cb;
/* Transaction not timed out */ /* Transaction not timed out */
if( 0 != coap_message_handler_exec(handle, 0)) if (0 != coap_message_handler_exec(handle, 0)) {
return false; return false;
}
if (transaction_cb != 0) if (transaction_cb != 0) {
return false; return false;
}
/* Transaction timed out */ /* Transaction timed out */
if( 0 != coap_message_handler_exec(handle, 300)) if (0 != coap_message_handler_exec(handle, 300)) {
return false; return false;
}
if (transaction_cb == 0) if (transaction_cb == 0) {
return false; return false;
}
/* Teardown */ /* Teardown */
free(sn_coap_protocol_stub.expectedCoap); 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_request_send();
bool test_coap_message_handler_response_send(); bool test_coap_message_handler_response_send();
bool test_coap_message_handler_request_delete(); bool test_coap_message_handler_request_delete();
bool test_coap_message_handler_request_delete_by_service_id();
bool test_coap_message_handler_exec(); bool test_coap_message_handler_exec();
#ifdef __cplusplus #ifdef __cplusplus

View File

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

View File

@ -19,7 +19,7 @@
#include "CppUTest/TestPlugin.h" #include "CppUTest/TestPlugin.h"
#include "CppUTest/TestRegistry.h" #include "CppUTest/TestRegistry.h"
#include "CppUTestExt/MockSupportPlugin.h" #include "CppUTestExt/MockSupportPlugin.h"
int main(int ac, char** av) int main(int ac, char **av)
{ {
return CommandLineTestRunner::RunAllTests(ac, av); return CommandLineTestRunner::RunAllTests(ac, av);
} }

View File

@ -43,28 +43,33 @@ static int timer_status_callback(int8_t timer_id)
bool test_thread_security_create() 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; 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; return false;
}
nsdynmemlib_stub.returnCounter = 1; nsdynmemlib_stub.returnCounter = 1;
mbedtls_stub.expected_int = -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; return false;
}
mbedtls_stub.expected_int = 0; mbedtls_stub.expected_int = 0;
nsdynmemlib_stub.returnCounter = 2; nsdynmemlib_stub.returnCounter = 2;
mbedtls_stub.crt_expected_int = -1; 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; return false;
}
nsdynmemlib_stub.returnCounter = 2; nsdynmemlib_stub.returnCounter = 2;
mbedtls_stub.crt_expected_int = 0; 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); 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; return false;
}
coap_security_destroy(handle); coap_security_destroy(handle);
@ -75,9 +80,10 @@ bool test_thread_security_destroy()
{ {
nsdynmemlib_stub.returnCounter = 2; nsdynmemlib_stub.returnCounter = 2;
mbedtls_stub.crt_expected_int = 0; 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); 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; return false;
}
coap_security_destroy(handle); coap_security_destroy(handle);
return true; return true;
@ -87,16 +93,18 @@ bool test_coap_security_handler_connect()
{ {
nsdynmemlib_stub.returnCounter = 2; nsdynmemlib_stub.returnCounter = 2;
mbedtls_stub.crt_expected_int = 0; 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); 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; return false;
}
unsigned char pw = "pwd"; unsigned char pw = "pwd";
coap_security_keys_t keys; coap_security_keys_t keys;
keys._key = &pw; keys._key = &pw;
keys._key_len = 3; 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; return false;
}
mbedtls_stub.useCounter = true; mbedtls_stub.useCounter = true;
mbedtls_stub.counter = 0; mbedtls_stub.counter = 0;
mbedtls_stub.retArray[0] = -1; mbedtls_stub.retArray[0] = -1;
@ -108,19 +116,22 @@ bool test_coap_security_handler_connect()
mbedtls_stub.retArray[6] = -1; mbedtls_stub.retArray[6] = -1;
mbedtls_stub.retArray[7] = -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; return false;
}
mbedtls_stub.counter = 0; mbedtls_stub.counter = 0;
mbedtls_stub.retArray[0] = 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; return false;
}
mbedtls_stub.counter = 0; mbedtls_stub.counter = 0;
// mbedtls_stub.retArray[0] = 0; // mbedtls_stub.retArray[0] = 0;
mbedtls_stub.retArray[1] = 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; return false;
}
simple_cookie_t c; simple_cookie_t c;
memset(&c, 0, sizeof(simple_cookie_t)); 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[0] = 0;
// mbedtls_stub.retArray[1] = 0; // mbedtls_stub.retArray[1] = 0;
mbedtls_stub.retArray[2] = 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; return false;
}
c.len = 8; c.len = 8;
memset(&c.value, 1, 8); memset(&c.value, 1, 8);
@ -145,8 +157,9 @@ bool test_coap_security_handler_connect()
// mbedtls_stub.retArray[1] = 0; // mbedtls_stub.retArray[1] = 0;
// mbedtls_stub.retArray[2] = 0; // mbedtls_stub.retArray[2] = 0;
mbedtls_stub.retArray[3] = 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; return false;
}
mbedtls_stub.counter = 0; mbedtls_stub.counter = 0;
// mbedtls_stub.retArray[0] = 0; // mbedtls_stub.retArray[0] = 0;
@ -154,8 +167,9 @@ bool test_coap_security_handler_connect()
// mbedtls_stub.retArray[2] = 0; // mbedtls_stub.retArray[2] = 0;
// mbedtls_stub.retArray[3] = 0; // mbedtls_stub.retArray[3] = 0;
mbedtls_stub.retArray[4] = 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; return false;
}
mbedtls_stub.counter = 0; mbedtls_stub.counter = 0;
// mbedtls_stub.retArray[0] = 0; // mbedtls_stub.retArray[0] = 0;
@ -165,20 +179,23 @@ bool test_coap_security_handler_connect()
// mbedtls_stub.retArray[4] = 0; // mbedtls_stub.retArray[4] = 0;
mbedtls_stub.retArray[6] = 0; mbedtls_stub.retArray[6] = 0;
mbedtls_stub.retArray[7] = 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; return false;
}
mbedtls_stub.counter = 0; mbedtls_stub.counter = 0;
mbedtls_stub.retArray[5] = MBEDTLS_ERR_SSL_BAD_HS_FINISHED; 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; return false;
}
mbedtls_stub.counter = 0; mbedtls_stub.counter = 0;
mbedtls_stub.retArray[5] = HANDSHAKE_FINISHED_VALUE; 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; return false;
}
coap_security_destroy(handle); coap_security_destroy(handle);
return true; return true;
@ -188,9 +205,10 @@ bool test_coap_security_handler_continue_connecting()
{ {
nsdynmemlib_stub.returnCounter = 2; nsdynmemlib_stub.returnCounter = 2;
mbedtls_stub.crt_expected_int = 0; 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); 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; return false;
}
mbedtls_stub.useCounter = true; mbedtls_stub.useCounter = true;
mbedtls_stub.counter = 0; mbedtls_stub.counter = 0;
@ -198,34 +216,39 @@ bool test_coap_security_handler_continue_connecting()
mbedtls_stub.retArray[1] = -1; mbedtls_stub.retArray[1] = -1;
mbedtls_stub.retArray[2] = -1; mbedtls_stub.retArray[2] = -1;
if( -1 != coap_security_handler_continue_connecting(handle) ) if (-1 != coap_security_handler_continue_connecting(handle)) {
return false; return false;
}
mbedtls_stub.counter = 0; mbedtls_stub.counter = 0;
mbedtls_stub.retArray[0] = MBEDTLS_ERR_SSL_HELLO_VERIFY_REQUIRED; mbedtls_stub.retArray[0] = MBEDTLS_ERR_SSL_HELLO_VERIFY_REQUIRED;
mbedtls_stub.retArray[1] = 0; mbedtls_stub.retArray[1] = 0;
mbedtls_stub.retArray[2] = 0; mbedtls_stub.retArray[2] = 0;
if( 1 != coap_security_handler_continue_connecting(handle) ) if (1 != coap_security_handler_continue_connecting(handle)) {
return false; return false;
}
mbedtls_stub.counter = 0; mbedtls_stub.counter = 0;
mbedtls_stub.retArray[0] = MBEDTLS_ERR_SSL_BAD_HS_FINISHED; 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; return false;
}
mbedtls_stub.counter = 0; mbedtls_stub.counter = 0;
mbedtls_stub.retArray[0] = MBEDTLS_ERR_SSL_WANT_READ; 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; return false;
}
mbedtls_stub.counter = 0; mbedtls_stub.counter = 0;
mbedtls_stub.retArray[0] = HANDSHAKE_FINISHED_VALUE_RETURN_ZERO; 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; return false;
}
coap_security_destroy(handle); coap_security_destroy(handle);
return true; return true;
@ -235,17 +258,20 @@ bool test_coap_security_handler_send_message()
{ {
nsdynmemlib_stub.returnCounter = 2; nsdynmemlib_stub.returnCounter = 2;
mbedtls_stub.crt_expected_int = 0; 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); 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; return false;
}
if( -1 != coap_security_handler_send_message(NULL, NULL, 0)) if (-1 != coap_security_handler_send_message(NULL, NULL, 0)) {
return false; return false;
}
mbedtls_stub.expected_int = 6; mbedtls_stub.expected_int = 6;
unsigned char cbuf[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; return false;
}
coap_security_destroy(handle); coap_security_destroy(handle);
return true; return true;
@ -255,16 +281,19 @@ bool test_thread_security_send_close_alert()
{ {
nsdynmemlib_stub.returnCounter = 2; nsdynmemlib_stub.returnCounter = 2;
mbedtls_stub.crt_expected_int = 0; 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); 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; return false;
}
if( -1 != coap_security_send_close_alert(NULL)) if (-1 != coap_security_send_close_alert(NULL)) {
return false; return false;
}
mbedtls_stub.expected_int = 0; mbedtls_stub.expected_int = 0;
if( 0 != coap_security_send_close_alert(handle)) if (0 != coap_security_send_close_alert(handle)) {
return false; return false;
}
coap_security_destroy(handle); coap_security_destroy(handle);
return true; return true;
@ -274,17 +303,20 @@ bool test_coap_security_handler_read()
{ {
nsdynmemlib_stub.returnCounter = 2; nsdynmemlib_stub.returnCounter = 2;
mbedtls_stub.crt_expected_int = 0; 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); 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; return false;
}
if( -1 != coap_security_handler_read(NULL, NULL, 0)) if (-1 != coap_security_handler_read(NULL, NULL, 0)) {
return false; return false;
}
mbedtls_stub.expected_int = 6; mbedtls_stub.expected_int = 6;
unsigned char cbuf[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; return false;
}
coap_security_destroy(handle); coap_security_destroy(handle);
return true; return true;

View File

@ -19,12 +19,10 @@
TEST_GROUP(coap_service_api) 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()); 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) TEST(coap_service_api, test_coap_service_response_send)
{ {
CHECK(test_coap_service_response_send()); CHECK(test_coap_service_response_send());

View File

@ -19,7 +19,7 @@
#include "CppUTest/TestPlugin.h" #include "CppUTest/TestPlugin.h"
#include "CppUTest/TestRegistry.h" #include "CppUTest/TestRegistry.h"
#include "CppUTestExt/MockSupportPlugin.h" #include "CppUTestExt/MockSupportPlugin.h"
int main(int ac, char** av) int main(int ac, char **av)
{ {
return CommandLineTestRunner::RunAllTests(ac, av); return CommandLineTestRunner::RunAllTests(ac, av);
} }

View File

@ -25,11 +25,12 @@
#include "net_interface.h" #include "net_interface.h"
#include "coap_service_api.c" #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; return 2;
} }
int sec_start_cb(int8_t service_id, uint8_t address[static 16], uint16_t port, uint8_t* pw, uint8_t *pw_len) int sec_start_cb(int8_t service_id, uint8_t address[static 16], uint16_t port, uint8_t *pw, uint8_t *pw_len)
{ {
return 0; return 0;
} }
@ -46,40 +47,45 @@ int virtual_sock_send_cb(int8_t service_id, uint8_t destination_addr_ptr[static
bool test_coap_service_initialize() 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; return false;
}
nsdynmemlib_stub.returnCounter = 1; nsdynmemlib_stub.returnCounter = 1;
thread_conn_handler_stub.handler_obj = NULL; 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; return false;
}
thread_conn_handler_stub.handler_obj = (coap_conn_handler_t*)malloc(sizeof(coap_conn_handler_t)); 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)); memset(thread_conn_handler_stub.handler_obj, 0, sizeof(coap_conn_handler_t));
coap_message_handler_stub.coap_ptr = NULL; coap_message_handler_stub.coap_ptr = NULL;
nsdynmemlib_stub.returnCounter = 1; nsdynmemlib_stub.returnCounter = 1;
thread_conn_handler_stub.int_value = -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; return false;
}
thread_conn_handler_stub.handler_obj = (coap_conn_handler_t*)malloc(sizeof(coap_conn_handler_t)); 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)); memset(thread_conn_handler_stub.handler_obj, 0, sizeof(coap_conn_handler_t));
nsdynmemlib_stub.returnCounter = 1; nsdynmemlib_stub.returnCounter = 1;
thread_conn_handler_stub.int_value = 0; 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; return false;
}
nsdynmemlib_stub.returnCounter = 1; 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; return false;
}
coap_service_delete(2); coap_service_delete(2);
coap_service_delete(1); coap_service_delete(1);
free( thread_conn_handler_stub.handler_obj ); free(thread_conn_handler_stub.handler_obj);
thread_conn_handler_stub.handler_obj = NULL; thread_conn_handler_stub.handler_obj = NULL;
return true; return true;
} }
@ -88,17 +94,18 @@ bool test_coap_service_delete()
{ {
coap_service_delete(1); coap_service_delete(1);
thread_conn_handler_stub.handler_obj = (coap_conn_handler_t*)malloc(sizeof(coap_conn_handler_t)); 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)); memset(thread_conn_handler_stub.handler_obj, 0, sizeof(coap_conn_handler_t));
nsdynmemlib_stub.returnCounter = 1; nsdynmemlib_stub.returnCounter = 1;
coap_message_handler_stub.coap_ptr = NULL; 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; return false;
}
coap_service_delete(1); coap_service_delete(1);
free( thread_conn_handler_stub.handler_obj ); free(thread_conn_handler_stub.handler_obj);
thread_conn_handler_stub.handler_obj = NULL; thread_conn_handler_stub.handler_obj = NULL;
return true; return true;
@ -107,24 +114,27 @@ bool test_coap_service_delete()
bool test_coap_service_virtual_socket_recv() bool test_coap_service_virtual_socket_recv()
{ {
uint8_t buf[16]; 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; return false;
}
thread_conn_handler_stub.handler_obj = (coap_conn_handler_t*)malloc(sizeof(coap_conn_handler_t)); 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)); memset(thread_conn_handler_stub.handler_obj, 0, sizeof(coap_conn_handler_t));
nsdynmemlib_stub.returnCounter = 1; nsdynmemlib_stub.returnCounter = 1;
coap_message_handler_stub.coap_ptr = NULL; 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; return false;
}
thread_conn_handler_stub.int_value = 5; 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; return false;
}
coap_service_delete(1); coap_service_delete(1);
free( thread_conn_handler_stub.handler_obj ); free(thread_conn_handler_stub.handler_obj);
thread_conn_handler_stub.handler_obj = NULL; thread_conn_handler_stub.handler_obj = NULL;
thread_conn_handler_stub.int_value = 0; thread_conn_handler_stub.int_value = 0;
@ -134,23 +144,26 @@ bool test_coap_service_virtual_socket_recv()
bool test_coap_service_virtual_socket_set_cb() 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; return false;
}
thread_conn_handler_stub.handler_obj = (coap_conn_handler_t*)malloc(sizeof(coap_conn_handler_t)); 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)); memset(thread_conn_handler_stub.handler_obj, 0, sizeof(coap_conn_handler_t));
nsdynmemlib_stub.returnCounter = 1; nsdynmemlib_stub.returnCounter = 1;
coap_message_handler_stub.coap_ptr = NULL; 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; return false;
}
if( 0 != coap_service_virtual_socket_set_cb(1, NULL) ) if (0 != coap_service_virtual_socket_set_cb(1, NULL)) {
return false; return false;
}
coap_service_delete(1); coap_service_delete(1);
free( thread_conn_handler_stub.handler_obj ); free(thread_conn_handler_stub.handler_obj);
thread_conn_handler_stub.handler_obj = NULL; thread_conn_handler_stub.handler_obj = NULL;
return true; return true;
@ -158,31 +171,36 @@ bool test_coap_service_virtual_socket_set_cb()
bool test_coap_service_register_uri() 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; return false;
}
thread_conn_handler_stub.handler_obj = (coap_conn_handler_t*)malloc(sizeof(coap_conn_handler_t)); 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)); memset(thread_conn_handler_stub.handler_obj, 0, sizeof(coap_conn_handler_t));
nsdynmemlib_stub.returnCounter = 1; nsdynmemlib_stub.returnCounter = 1;
coap_message_handler_stub.coap_ptr = NULL; 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; 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; return false;
}
nsdynmemlib_stub.returnCounter = 1; 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; return false;
}
nsdynmemlib_stub.returnCounter = 2; 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; return false;
}
coap_service_delete(1); coap_service_delete(1);
free( thread_conn_handler_stub.handler_obj ); free(thread_conn_handler_stub.handler_obj);
thread_conn_handler_stub.handler_obj = NULL; thread_conn_handler_stub.handler_obj = NULL;
return true; return true;
@ -190,31 +208,36 @@ bool test_coap_service_register_uri()
bool test_coap_service_unregister_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; return false;
}
thread_conn_handler_stub.handler_obj = (coap_conn_handler_t*)malloc(sizeof(coap_conn_handler_t)); 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)); memset(thread_conn_handler_stub.handler_obj, 0, sizeof(coap_conn_handler_t));
nsdynmemlib_stub.returnCounter = 1; nsdynmemlib_stub.returnCounter = 1;
coap_message_handler_stub.coap_ptr = NULL; coap_message_handler_stub.coap_ptr = NULL;
thread_conn_handler_stub.int_value = 0; 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; return false;
}
nsdynmemlib_stub.returnCounter = 2; 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; return false;
}
if( -2 != coap_service_unregister_uri(1, "ts") ) if (-2 != coap_service_unregister_uri(1, "ts")) {
return false; return false;
}
if( 0 != coap_service_unregister_uri(1, "as") ) if (0 != coap_service_unregister_uri(1, "as")) {
return false; return false;
}
coap_service_delete(1); coap_service_delete(1);
free( thread_conn_handler_stub.handler_obj ); free(thread_conn_handler_stub.handler_obj);
thread_conn_handler_stub.handler_obj = NULL; thread_conn_handler_stub.handler_obj = NULL;
return true; return true;
@ -224,15 +247,23 @@ bool test_coap_service_request_send()
{ {
uint8_t buf[16]; uint8_t buf[16];
coap_message_handler_stub.uint16_value = 6; 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 false;
}
return true; return true;
} }
bool test_coap_service_request_delete() 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 false;
}
return true;
}
bool test_coap_service_request_delete_by_service_id()
{
coap_service_request_delete_by_service_id(0);
return true; return true;
} }
@ -240,29 +271,33 @@ bool test_coap_service_response_send()
{ {
uint8_t buf[16]; uint8_t buf[16];
coap_message_handler_stub.int8_value = 6; 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 false;
}
return true; return true;
} }
bool test_coap_callbacks() bool test_coap_callbacks()
{ {
thread_conn_handler_stub.handler_obj = (coap_conn_handler_t*)malloc(sizeof(coap_conn_handler_t)); 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)); memset(thread_conn_handler_stub.handler_obj, 0, sizeof(coap_conn_handler_t));
nsdynmemlib_stub.returnCounter = 1; nsdynmemlib_stub.returnCounter = 1;
coap_message_handler_stub.coap_ptr = (coap_msg_handler_t *)malloc(sizeof(coap_msg_handler_t)); 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)); 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; 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; return false;
}
nsdynmemlib_stub.returnCounter = 1; nsdynmemlib_stub.returnCounter = 1;
void *handle = coap_message_handler_stub.coap_ptr->sn_coap_service_malloc(5); void *handle = coap_message_handler_stub.coap_ptr->sn_coap_service_malloc(5);
if( 0 == handle ) if (0 == handle) {
return false; return false;
}
coap_message_handler_stub.coap_ptr->sn_coap_service_free(handle); coap_message_handler_stub.coap_ptr->sn_coap_service_free(handle);
@ -273,34 +308,38 @@ bool test_coap_callbacks()
addr.addr_len = 2; addr.addr_len = 2;
addr.port = 4; addr.port = 4;
addr.addr_ptr = &data; 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; return false;
}
coap_transaction_t *tr = (coap_transaction_t *)malloc(sizeof(coap_transaction_t)); coap_transaction_t *tr = (coap_transaction_t *)malloc(sizeof(coap_transaction_t));
memset(tr, 0, 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; return false;
}
tr->service_id = 1; tr->service_id = 1;
thread_conn_handler_stub.int_value = -2; 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; return false;
}
nsdynmemlib_stub.returnCounter = 1; 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; return false;
}
free(tr->data_ptr); free(tr->data_ptr);
free(tr); free(tr);
coap_service_delete(1); coap_service_delete(1);
free( coap_message_handler_stub.coap_ptr ); free(coap_message_handler_stub.coap_ptr);
coap_message_handler_stub.coap_ptr = NULL; coap_message_handler_stub.coap_ptr = NULL;
coap_service_handle = NULL; coap_service_handle = NULL;
free( thread_conn_handler_stub.handler_obj ); free(thread_conn_handler_stub.handler_obj);
thread_conn_handler_stub.handler_obj = NULL; thread_conn_handler_stub.handler_obj = NULL;
return true; return true;
@ -309,13 +348,14 @@ bool test_coap_callbacks()
#define COAP_TICK_TIMER 0xf1 //MUST BE SAME AS IN coap_service_api.c #define COAP_TICK_TIMER 0xf1 //MUST BE SAME AS IN coap_service_api.c
bool test_eventOS_callbacks() bool test_eventOS_callbacks()
{ {
thread_conn_handler_stub.handler_obj = (coap_conn_handler_t*)malloc(sizeof(coap_conn_handler_t)); 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)); memset(thread_conn_handler_stub.handler_obj, 0, sizeof(coap_conn_handler_t));
nsdynmemlib_stub.returnCounter = 1; 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; return false;
}
if( eventOs_event_stub.event_ptr ){ if (eventOs_event_stub.event_ptr) {
arm_event_s event; arm_event_s event;
event.event_type = ARM_LIB_TASKLET_INIT_EVENT; event.event_type = ARM_LIB_TASKLET_INIT_EVENT;
eventOs_event_stub.event_ptr(&event); eventOs_event_stub.event_ptr(&event);
@ -326,7 +366,7 @@ bool test_eventOS_callbacks()
} }
coap_service_delete(1); coap_service_delete(1);
free( thread_conn_handler_stub.handler_obj ); free(thread_conn_handler_stub.handler_obj);
thread_conn_handler_stub.handler_obj = NULL; thread_conn_handler_stub.handler_obj = NULL;
return true; return true;
} }
@ -334,65 +374,75 @@ bool test_eventOS_callbacks()
bool test_conn_handler_callbacks() bool test_conn_handler_callbacks()
{ {
uint8_t buf[16]; uint8_t buf[16];
thread_conn_handler_stub.handler_obj = (coap_conn_handler_t*)malloc(sizeof(coap_conn_handler_t)); 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)); memset(thread_conn_handler_stub.handler_obj, 0, sizeof(coap_conn_handler_t));
nsdynmemlib_stub.returnCounter = 1; 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; return false;
if( thread_conn_handler_stub.send_to_sock_cb ){
thread_conn_handler_stub.bool_value = true;
coap_service_virtual_socket_set_cb(1, &virtual_sock_send_cb);
if( 2 != thread_conn_handler_stub.send_to_sock_cb(1, buf, 12, NULL, 0))
return false;
thread_conn_handler_stub.bool_value = false;
if( -1 != thread_conn_handler_stub.send_to_sock_cb(1, buf, 12, NULL, 0))
return false;
} }
if( thread_conn_handler_stub.receive_from_sock_cb ){ if (thread_conn_handler_stub.send_to_sock_cb) {
coap_message_handler_stub.int16_value = 2; thread_conn_handler_stub.bool_value = true;
if( -1 != thread_conn_handler_stub.receive_from_sock_cb(1, buf, 12, NULL, NULL, 0)) coap_service_virtual_socket_set_cb(1, &virtual_sock_send_cb);
if (2 != thread_conn_handler_stub.send_to_sock_cb(1, buf, 12, NULL, 0)) {
return false; return false;
}
thread_conn_handler_stub.bool_value = false;
if (-1 != thread_conn_handler_stub.send_to_sock_cb(1, buf, 12, NULL, 0)) {
return false;
}
}
if (thread_conn_handler_stub.receive_from_sock_cb) {
coap_message_handler_stub.int16_value = 2;
if (-1 != thread_conn_handler_stub.receive_from_sock_cb(1, buf, 12, NULL, NULL, 0)) {
return false;
}
nsdynmemlib_stub.returnCounter = 1; nsdynmemlib_stub.returnCounter = 1;
uint8_t * ptr = ns_dyn_mem_alloc(5); uint8_t *ptr = ns_dyn_mem_alloc(5);
memset(ptr, 3, 5); memset(ptr, 3, 5);
nsdynmemlib_stub.returnCounter = 1; 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; return false;
}
ns_dyn_mem_free(ptr); ns_dyn_mem_free(ptr);
coap_message_handler_stub.int16_value = 0; coap_message_handler_stub.int16_value = 0;
//This could be moved to own test function, //This could be moved to own test function,
//but thread_conn_handler_stub.receive_from_sock_cb must be called successfully //but thread_conn_handler_stub.receive_from_sock_cb must be called successfully
if( coap_message_handler_stub.cb ){ 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; return false;
}
sn_coap_hdr_s * coap = (sn_coap_hdr_s *)malloc(sizeof(sn_coap_hdr_s)); sn_coap_hdr_s *coap = (sn_coap_hdr_s *)malloc(sizeof(sn_coap_hdr_s));
memset(coap, 0, sizeof(sn_coap_hdr_s)); memset(coap, 0, sizeof(sn_coap_hdr_s));
uint8_t uri[2] = "as"; uint8_t uri[2] = "as";
coap->uri_path_ptr = &uri; coap->uri_path_ptr = &uri;
coap->uri_path_len=2; 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; return false;
}
thread_conn_handler_stub.bool_value = true; thread_conn_handler_stub.bool_value = true;
nsdynmemlib_stub.returnCounter = 2; 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; return false;
}
if( -1 != coap_message_handler_stub.cb(1, coap, NULL) ) if (-1 != coap_message_handler_stub.cb(1, coap, NULL)) {
return false; return false;
}
coap_transaction_t *tr = (coap_transaction_t *)malloc(sizeof(coap_transaction_t)); coap_transaction_t *tr = (coap_transaction_t *)malloc(sizeof(coap_transaction_t));
memset(tr, 0, 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; return false;
}
free(tr); free(tr);
tr = NULL; tr = NULL;
@ -403,20 +453,22 @@ bool test_conn_handler_callbacks()
} }
} }
if(thread_conn_handler_stub.get_passwd_cb){ if (thread_conn_handler_stub.get_passwd_cb) {
coap_security_keys_t security_ptr; coap_security_keys_t security_ptr;
memset(&security_ptr, 0, sizeof(coap_security_keys_t)); memset(&security_ptr, 0, sizeof(coap_security_keys_t));
nsdynmemlib_stub.returnCounter = 1; nsdynmemlib_stub.returnCounter = 1;
thread_conn_handler_stub.bool_value = true; 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; return false;
}
free(security_ptr._key); free(security_ptr._key);
thread_conn_handler_stub.bool_value = false; 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; return false;
}
} }
if(thread_conn_handler_stub.sec_done_cb){ if (thread_conn_handler_stub.sec_done_cb) {
uint8_t block[40]; uint8_t block[40];
thread_conn_handler_stub.bool_value = true; thread_conn_handler_stub.bool_value = true;
@ -437,7 +489,7 @@ bool test_conn_handler_callbacks()
} }
coap_service_delete(1); coap_service_delete(1);
free( thread_conn_handler_stub.handler_obj ); free(thread_conn_handler_stub.handler_obj);
thread_conn_handler_stub.handler_obj = NULL; thread_conn_handler_stub.handler_obj = NULL;
return true; return true;
@ -451,12 +503,13 @@ bool test_certificate_set()
} }
/* Init service */ /* Init service */
thread_conn_handler_stub.handler_obj = (coap_conn_handler_t*)malloc(sizeof(coap_conn_handler_t)); 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)); memset(thread_conn_handler_stub.handler_obj, 0, sizeof(coap_conn_handler_t));
nsdynmemlib_stub.returnCounter = 1; 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; return false;
}
/* Allocation fails */ /* Allocation fails */
if (-1 != coap_service_certificate_set(1, NULL, 0, NULL, 0)) { if (-1 != coap_service_certificate_set(1, NULL, 0, NULL, 0)) {
@ -485,12 +538,13 @@ bool test_handshake_timeout_set()
} }
/* Init service */ /* Init service */
thread_conn_handler_stub.handler_obj = (coap_conn_handler_t*)malloc(sizeof(coap_conn_handler_t)); 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)); memset(thread_conn_handler_stub.handler_obj, 0, sizeof(coap_conn_handler_t));
nsdynmemlib_stub.returnCounter = 1; 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; return false;
}
/* All OK */ /* All OK */
nsdynmemlib_stub.returnCounter = 1; nsdynmemlib_stub.returnCounter = 1;
@ -515,17 +569,18 @@ bool test_coap_duplcate_msg_buffer_set()
} }
/* Init service */ /* Init service */
thread_conn_handler_stub.handler_obj = (coap_conn_handler_t*)malloc(sizeof(coap_conn_handler_t)); 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)); memset(thread_conn_handler_stub.handler_obj, 0, sizeof(coap_conn_handler_t));
coap_message_handler_stub.coap_ptr = (coap_msg_handler_t *)malloc(sizeof(coap_msg_handler_t)); 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)); memset(coap_message_handler_stub.coap_ptr, 0, sizeof(coap_msg_handler_t));
nsdynmemlib_stub.returnCounter = 1; 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; ret = false;
}
/* All OK */ /* All OK */
if(0 != coap_service_set_duplicate_message_buffer(0, 0)) { if (0 != coap_service_set_duplicate_message_buffer(0, 0)) {
ret = false; ret = false;
} }
@ -554,22 +609,23 @@ bool test_coap_service_if_find_by_socket()
} }
/* Init service */ /* Init service */
thread_conn_handler_stub.handler_obj = (coap_conn_handler_t*)malloc(sizeof(coap_conn_handler_t)); 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)); memset(thread_conn_handler_stub.handler_obj, 0, sizeof(coap_conn_handler_t));
nsdynmemlib_stub.returnCounter = 1; nsdynmemlib_stub.returnCounter = 1;
thread_conn_handler_stub.bool_value = 0; 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; return false;
}
/* No matching service ID - return false */ /* No matching service ID - return false */
if(0 != coap_service_id_find_by_socket(1)) { if (0 != coap_service_id_find_by_socket(1)) {
return false; return false;
} }
thread_conn_handler_stub.bool_value = 1; thread_conn_handler_stub.bool_value = 1;
/* All OK */ /* All OK */
if(1 != coap_service_id_find_by_socket(1)) { if (1 != coap_service_id_find_by_socket(1)) {
return false; return false;
} }

View File

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

View File

@ -34,9 +34,9 @@ int coap_connection_handler_virtual_recv(coap_conn_handler_t *handler, uint8_t a
} }
coap_conn_handler_t *connection_handler_create(int (*recv_cb)(int8_t socket_id, uint8_t src_address[static 16], uint16_t port, const uint8_t dst_address[static 16], unsigned char *, int), coap_conn_handler_t *connection_handler_create(int (*recv_cb)(int8_t socket_id, uint8_t src_address[static 16], uint16_t port, const uint8_t dst_address[static 16], unsigned char *, int),
int (*send_cb)(int8_t socket_id, uint8_t const address[static 16], uint16_t port, const void *, int), int (*send_cb)(int8_t socket_id, uint8_t const address[static 16], uint16_t port, const void *, int),
int (*pw_cb)(int8_t socket_id, uint8_t address[static 16], uint16_t port, coap_security_keys_t *security_ptr), int (*pw_cb)(int8_t socket_id, uint8_t address[static 16], uint16_t port, coap_security_keys_t *security_ptr),
void(*done_cb)(int8_t socket_id, uint8_t address[static 16], uint16_t port, uint8_t keyblock[static KEY_BLOCK_LEN]) ) void(*done_cb)(int8_t socket_id, uint8_t address[static 16], uint16_t port, uint8_t keyblock[static KEY_BLOCK_LEN]))
{ {
thread_conn_handler_stub.send_to_sock_cb = send_cb; thread_conn_handler_stub.send_to_sock_cb = send_cb;
thread_conn_handler_stub.receive_from_sock_cb = recv_cb; thread_conn_handler_stub.receive_from_sock_cb = recv_cb;
@ -45,11 +45,11 @@ coap_conn_handler_t *connection_handler_create(int (*recv_cb)(int8_t socket_id,
return thread_conn_handler_stub.handler_obj; return thread_conn_handler_stub.handler_obj;
} }
void connection_handler_destroy( coap_conn_handler_t *handler, bool multicast_group_leave) void connection_handler_destroy(coap_conn_handler_t *handler, bool multicast_group_leave)
{ {
} }
void connection_handler_close_secure_connection( coap_conn_handler_t *handler, uint8_t destination_addr_ptr[static 16], uint16_t port ) void connection_handler_close_secure_connection(coap_conn_handler_t *handler, uint8_t destination_addr_ptr[static 16], uint16_t port)
{ {
} }

View File

@ -20,9 +20,9 @@
coap_message_handler_stub_def coap_message_handler_stub; coap_message_handler_stub_def coap_message_handler_stub;
coap_msg_handler_t *coap_message_handler_init(void *(*used_malloc_func_ptr)(uint16_t), void (*used_free_func_ptr)(void *), 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(coap_message_handler_stub.coap_ptr){ if (coap_message_handler_stub.coap_ptr) {
coap_message_handler_stub.coap_ptr->sn_coap_service_malloc = used_malloc_func_ptr; coap_message_handler_stub.coap_ptr->sn_coap_service_malloc = used_malloc_func_ptr;
coap_message_handler_stub.coap_ptr->sn_coap_service_free = used_free_func_ptr; coap_message_handler_stub.coap_ptr->sn_coap_service_free = used_free_func_ptr;
coap_message_handler_stub.coap_ptr->sn_coap_tx_callback = used_tx_callback_ptr; coap_message_handler_stub.coap_ptr->sn_coap_tx_callback = used_tx_callback_ptr;
@ -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) int8_t coap_message_handler_destroy(coap_msg_handler_t *handle)
{ {
return coap_message_handler_stub.int8_value; return coap_message_handler_stub.int8_value;
@ -55,20 +56,20 @@ coap_transaction_t *coap_message_handler_find_transaction(uint8_t *address_ptr,
} }
int16_t coap_message_handler_coap_msg_process(coap_msg_handler_t *handle, int8_t socket_id, const uint8_t source_addr_ptr[static 16], uint16_t port, const uint8_t dst_addr_ptr[static 16], int16_t coap_message_handler_coap_msg_process(coap_msg_handler_t *handle, int8_t socket_id, const uint8_t source_addr_ptr[static 16], uint16_t port, const uint8_t dst_addr_ptr[static 16],
uint8_t *data_ptr, uint16_t data_len, int16_t (cb)(int8_t, sn_coap_hdr_s *, coap_transaction_t *)) uint8_t *data_ptr, uint16_t data_len, int16_t (cb)(int8_t, sn_coap_hdr_s *, coap_transaction_t *))
{ {
coap_message_handler_stub.cb = cb; coap_message_handler_stub.cb = cb;
return coap_message_handler_stub.int16_value; return coap_message_handler_stub.int16_value;
} }
uint16_t coap_message_handler_request_send(coap_msg_handler_t *handle, int8_t service_id, uint8_t options, uint16_t coap_message_handler_request_send(coap_msg_handler_t *handle, int8_t service_id, uint8_t options,
const uint8_t destination_addr[static 16], uint16_t destination_port, sn_coap_msg_type_e msg_type, sn_coap_msg_code_e msg_code, 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_message_handler_response_recv *request_response_cb) const char *uri, sn_coap_content_format_e cont_type, const uint8_t *payload_ptr, uint16_t payload_len, coap_message_handler_response_recv *request_response_cb)
{ {
return coap_message_handler_stub.uint16_value; return coap_message_handler_stub.uint16_value;
} }
int8_t coap_message_handler_response_send(coap_msg_handler_t *handle, int8_t service_id, uint8_t options, sn_coap_hdr_s *request_ptr, sn_coap_msg_code_e message_code,sn_coap_content_format_e content_type, const uint8_t *payload_ptr, uint16_t payload_len) int8_t coap_message_handler_response_send(coap_msg_handler_t *handle, int8_t service_id, uint8_t options, sn_coap_hdr_s *request_ptr, sn_coap_msg_code_e message_code, sn_coap_content_format_e content_type, const uint8_t *payload_ptr, uint16_t payload_len)
{ {
return coap_message_handler_stub.int8_value; return coap_message_handler_stub.int8_value;
} }
@ -78,13 +79,18 @@ int8_t coap_message_handler_request_delete(coap_msg_handler_t *handle, int8_t se
return 0; 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) int8_t coap_message_handler_exec(coap_msg_handler_t *handle, uint32_t current_time)
{ {
return coap_message_handler_stub.int8_value; return coap_message_handler_stub.int8_value;
} }
int8_t coap_message_handler_response_send_by_msg_id(coap_msg_handler_t *handle, int8_t service_id, uint8_t options, uint16_t msg_id, sn_coap_msg_code_e message_code, int8_t coap_message_handler_response_send_by_msg_id(coap_msg_handler_t *handle, 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) sn_coap_content_format_e content_type, const uint8_t *payload_ptr, uint16_t payload_len)
{ {
return coap_message_handler_stub.int8_value; return coap_message_handler_stub.int8_value;
} }

View File

@ -30,10 +30,10 @@ struct coap_security_s {
}; };
coap_security_t *coap_security_create(int8_t socket_id, int8_t timer_id, void *handle, SecureConnectionMode mode, coap_security_t *coap_security_create(int8_t socket_id, int8_t timer_id, void *handle, SecureConnectionMode mode,
int (*send_cb)(int8_t socket_id, void *handle, const void *, size_t), int (*send_cb)(int8_t socket_id, void *handle, const void *, size_t),
int (*receive_cb)(int8_t socket_id, unsigned char *, size_t), int (*receive_cb)(int8_t socket_id, unsigned char *, size_t),
void (*start_timer_cb)(int8_t timer_id, uint32_t min, uint32_t fin), void (*start_timer_cb)(int8_t timer_id, uint32_t min, uint32_t fin),
int (*timer_status_cb)(int8_t timer_id)) int (*timer_status_cb)(int8_t timer_id))
{ {
coap_security_handler_stub.send_cb = send_cb; coap_security_handler_stub.send_cb = send_cb;
coap_security_handler_stub.receive_cb = receive_cb; coap_security_handler_stub.receive_cb = receive_cb;
@ -56,7 +56,7 @@ void coap_security_destroy(coap_security_t *sec)
int coap_security_handler_connect_non_blocking(coap_security_t *sec, bool is_server, SecureSocketMode sock_mode, coap_security_keys_t keys, uint32_t timeout_min, uint32_t timeout_max) int coap_security_handler_connect_non_blocking(coap_security_t *sec, bool is_server, SecureSocketMode sock_mode, coap_security_keys_t keys, uint32_t timeout_min, uint32_t timeout_max)
{ {
sec->_is_started = true; sec->_is_started = true;
if( coap_security_handler_stub.counter >= 0){ if (coap_security_handler_stub.counter >= 0) {
return coap_security_handler_stub.values[coap_security_handler_stub.counter--]; return coap_security_handler_stub.values[coap_security_handler_stub.counter--];
} }
return coap_security_handler_stub.int_value; return coap_security_handler_stub.int_value;
@ -64,7 +64,7 @@ int coap_security_handler_connect_non_blocking(coap_security_t *sec, bool is_ser
int coap_security_handler_continue_connecting(coap_security_t *sec) int coap_security_handler_continue_connecting(coap_security_t *sec)
{ {
if( coap_security_handler_stub.counter >= 0){ if (coap_security_handler_stub.counter >= 0) {
return coap_security_handler_stub.values[coap_security_handler_stub.counter--]; return coap_security_handler_stub.values[coap_security_handler_stub.counter--];
} }
@ -74,7 +74,7 @@ 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)
{ {
if( coap_security_handler_stub.counter >= 0){ if (coap_security_handler_stub.counter >= 0) {
return coap_security_handler_stub.values[coap_security_handler_stub.counter--]; return coap_security_handler_stub.values[coap_security_handler_stub.counter--];
} }
return coap_security_handler_stub.int_value; return coap_security_handler_stub.int_value;
@ -82,15 +82,15 @@ int coap_security_handler_send_message(coap_security_t *sec, unsigned char *mess
int coap_security_send_close_alert(coap_security_t *sec) int coap_security_send_close_alert(coap_security_t *sec)
{ {
if( coap_security_handler_stub.counter >= 0){ if (coap_security_handler_stub.counter >= 0) {
return coap_security_handler_stub.values[coap_security_handler_stub.counter--]; return coap_security_handler_stub.values[coap_security_handler_stub.counter--];
} }
return coap_security_handler_stub.int_value; return coap_security_handler_stub.int_value;
} }
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)
{ {
if( coap_security_handler_stub.counter >= 0){ if (coap_security_handler_stub.counter >= 0) {
return coap_security_handler_stub.values[coap_security_handler_stub.counter--]; return coap_security_handler_stub.values[coap_security_handler_stub.counter--];
} }
return coap_security_handler_stub.int_value; return coap_security_handler_stub.int_value;

View File

@ -20,7 +20,7 @@
#include <inttypes.h> #include <inttypes.h>
#include "coap_security_handler.h" #include "coap_security_handler.h"
typedef struct tsh{ typedef struct tsh {
coap_security_t *sec_obj; coap_security_t *sec_obj;
int int_value; int int_value;
int counter; int counter;

View File

@ -33,7 +33,7 @@
coap_msg_handler_t *coap_service_handle = NULL; coap_msg_handler_t *coap_service_handle = NULL;
int8_t coap_service_initialize(int8_t interface_id, uint16_t listen_port, uint8_t service_options, int8_t coap_service_initialize(int8_t interface_id, uint16_t listen_port, uint8_t service_options,
coap_service_security_start_cb *start_ptr, coap_service_security_done_cb *coap_security_done_cb) coap_service_security_start_cb *start_ptr, coap_service_security_done_cb *coap_security_done_cb)
{ {
return 0; return 0;
} }
@ -67,7 +67,7 @@ uint16_t coap_service_request_send(int8_t service_id, uint8_t options, const uin
return 0; return 0;
} }
int8_t coap_service_response_send(int8_t service_id, uint8_t options, sn_coap_hdr_s *request_ptr, sn_coap_msg_code_e message_code, 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 0; return 0;
} }

View File

@ -20,157 +20,179 @@
mbedtls_stub_def mbedtls_stub; mbedtls_stub_def mbedtls_stub;
//From ssl.h //From ssl.h
int mbedtls_ssl_handshake_step( mbedtls_ssl_context *ssl ) int mbedtls_ssl_handshake_step(mbedtls_ssl_context *ssl)
{ {
if( mbedtls_stub.useCounter ){ if (mbedtls_stub.useCounter) {
if( mbedtls_stub.retArray[mbedtls_stub.counter] == HANDSHAKE_FINISHED_VALUE || if (mbedtls_stub.retArray[mbedtls_stub.counter] == HANDSHAKE_FINISHED_VALUE ||
mbedtls_stub.retArray[mbedtls_stub.counter] == HANDSHAKE_FINISHED_VALUE_RETURN_ZERO){ mbedtls_stub.retArray[mbedtls_stub.counter] == HANDSHAKE_FINISHED_VALUE_RETURN_ZERO) {
ssl->state = MBEDTLS_SSL_HANDSHAKE_OVER; 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 0;
}
} }
return mbedtls_stub.retArray[mbedtls_stub.counter++]; return mbedtls_stub.retArray[mbedtls_stub.counter++];
} }
return mbedtls_stub.expected_int; return mbedtls_stub.expected_int;
} }
int mbedtls_ssl_close_notify( mbedtls_ssl_context *a ) int mbedtls_ssl_close_notify(mbedtls_ssl_context *a)
{ {
if( mbedtls_stub.useCounter ){ if (mbedtls_stub.useCounter) {
return mbedtls_stub.retArray[mbedtls_stub.counter++]; return mbedtls_stub.retArray[mbedtls_stub.counter++];
} }
return mbedtls_stub.expected_int; 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_config_init( mbedtls_ssl_config *a ){
}
void mbedtls_ssl_conf_handshake_timeout( mbedtls_ssl_config *a, uint32_t b, uint32_t c)
{ {
} }
void mbedtls_ssl_free( mbedtls_ssl_context *a ){ void mbedtls_ssl_conf_max_version(mbedtls_ssl_config *conf, int major, int minor)
{
} }
int mbedtls_ssl_conf_own_cert( mbedtls_ssl_config *a, void mbedtls_ssl_config_init(mbedtls_ssl_config *a)
{
}
void mbedtls_ssl_conf_handshake_timeout(mbedtls_ssl_config *a, uint32_t b, uint32_t c)
{
}
void mbedtls_ssl_free(mbedtls_ssl_context *a)
{
}
int mbedtls_ssl_conf_own_cert(mbedtls_ssl_config *a,
mbedtls_x509_crt *b, mbedtls_x509_crt *b,
mbedtls_pk_context *c ){ mbedtls_pk_context *c)
if( mbedtls_stub.useCounter ){ {
if (mbedtls_stub.useCounter) {
return mbedtls_stub.retArray[mbedtls_stub.counter++]; return mbedtls_stub.retArray[mbedtls_stub.counter++];
} }
return mbedtls_stub.expected_int; 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, void mbedtls_ssl_conf_ca_chain(mbedtls_ssl_config *a,
mbedtls_x509_crt *b, mbedtls_x509_crt *b,
mbedtls_x509_crl *c ){ mbedtls_x509_crl *c)
{
} }
int mbedtls_ssl_conf_psk( mbedtls_ssl_config *a, int mbedtls_ssl_conf_psk(mbedtls_ssl_config *a,
const unsigned char *b, size_t c, 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 ){ {
if (mbedtls_stub.useCounter) {
return mbedtls_stub.retArray[mbedtls_stub.counter++]; return mbedtls_stub.retArray[mbedtls_stub.counter++];
} }
return mbedtls_stub.expected_int; return mbedtls_stub.expected_int;
} }
int mbedtls_ssl_config_defaults( 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 ){ {
if (mbedtls_stub.useCounter) {
return mbedtls_stub.retArray[mbedtls_stub.counter++]; return mbedtls_stub.retArray[mbedtls_stub.counter++];
} }
return mbedtls_stub.expected_int; return mbedtls_stub.expected_int;
} }
void mbedtls_ssl_conf_rng( mbedtls_ssl_config *a, void mbedtls_ssl_conf_rng(mbedtls_ssl_config *a,
int (*f_rng)(void *, unsigned char *, size_t), int (*f_rng)(void *, unsigned char *, size_t),
void *b ){ void *b)
{
} }
void mbedtls_ssl_conf_ciphersuites( mbedtls_ssl_config *a, void mbedtls_ssl_conf_ciphersuites(mbedtls_ssl_config *a,
const int *b) const int *b)
{ {
} }
int mbedtls_ssl_setup( mbedtls_ssl_context *a, int mbedtls_ssl_setup(mbedtls_ssl_context *a,
const mbedtls_ssl_config *b ){ const mbedtls_ssl_config *b)
if( mbedtls_stub.useCounter ){ {
if (mbedtls_stub.useCounter) {
return mbedtls_stub.retArray[mbedtls_stub.counter++]; return mbedtls_stub.retArray[mbedtls_stub.counter++];
} }
return mbedtls_stub.expected_int; return mbedtls_stub.expected_int;
} }
void mbedtls_ssl_set_bio( mbedtls_ssl_context *ssl, void mbedtls_ssl_set_bio(mbedtls_ssl_context *ssl,
void *p_bio, void *p_bio,
int (*f_send)(void *, const unsigned char *, size_t), int (*f_send)(void *, const unsigned char *, size_t),
int (*f_recv)(void *, 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 (p_bio != NULL) {
f_send( p_bio, NULL, 0 ); if (f_send) {
if( f_recv ) f_send(p_bio, NULL, 0);
f_recv( p_bio, NULL, 0 ); }
if( f_recv_timeout ) if (f_recv) {
f_recv_timeout( p_bio, NULL, 0, 0 ); f_recv(p_bio, NULL, 0);
}
if (f_recv_timeout) {
f_recv_timeout(p_bio, NULL, 0, 0);
}
} }
} }
void mbedtls_ssl_set_timer_cb( mbedtls_ssl_context *a, void mbedtls_ssl_set_timer_cb(mbedtls_ssl_context *a,
void *ctx, void *ctx,
void (*f_set_timer)(void *, uint32_t int_ms, uint32_t fin_ms), 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_set_timer(ctx, 1, 2);
f_get_timer(ctx); f_get_timer(ctx);
if(mbedtls_stub.invalidate_timer){ if (mbedtls_stub.invalidate_timer) {
f_set_timer(ctx, 0, 0); f_set_timer(ctx, 0, 0);
} }
f_get_timer(ctx); f_get_timer(ctx);
} }
int mbedtls_ssl_handshake( mbedtls_ssl_context *ssl ){ int mbedtls_ssl_handshake(mbedtls_ssl_context *ssl)
if( mbedtls_stub.useCounter ){ {
if (mbedtls_stub.useCounter) {
return mbedtls_stub.retArray[mbedtls_stub.counter++]; return mbedtls_stub.retArray[mbedtls_stub.counter++];
} }
return mbedtls_stub.expected_int; 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; 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 ){ {
if (mbedtls_stub.useCounter) {
return mbedtls_stub.retArray[mbedtls_stub.counter++]; return mbedtls_stub.retArray[mbedtls_stub.counter++];
} }
return mbedtls_stub.expected_int; 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 ){ {
if (mbedtls_stub.useCounter) {
return mbedtls_stub.retArray[mbedtls_stub.counter++]; return mbedtls_stub.retArray[mbedtls_stub.counter++];
} }
return mbedtls_stub.expected_int; return mbedtls_stub.expected_int;
@ -179,144 +201,157 @@ int mbedtls_ssl_write( mbedtls_ssl_context *a, const unsigned char *b, size_t c
//From crt_drbg.h //From crt_drbg.h
int mbedtls_ctr_drbg_seed( mbedtls_ctr_drbg_context *a, int mbedtls_ctr_drbg_seed(mbedtls_ctr_drbg_context *a,
int (*f_entropy)(void *, unsigned char *, size_t), int (*f_entropy)(void *, unsigned char *, size_t),
void *b, void *b,
const unsigned char *c, const unsigned char *c,
size_t d ){ size_t d)
{
return mbedtls_stub.crt_expected_int; 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, int mbedtls_ctr_drbg_random_with_add(void *a,
unsigned char *b, size_t c, 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; return mbedtls_stub.crt_expected_int;
} }
int mbedtls_ctr_drbg_random( void *p_rng, 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; return mbedtls_stub.crt_expected_int;
} }
//From x509_crt.h //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 ){ {
if (mbedtls_stub.useCounter) {
return mbedtls_stub.retArray[mbedtls_stub.counter++]; return mbedtls_stub.retArray[mbedtls_stub.counter++];
} }
return mbedtls_stub.expected_int; return mbedtls_stub.expected_int;
} }
//From entropy.h //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 ){ {
if (mbedtls_stub.useCounter) {
return mbedtls_stub.retArray[mbedtls_stub.counter++]; return mbedtls_stub.retArray[mbedtls_stub.counter++];
} }
return mbedtls_stub.expected_int; return mbedtls_stub.expected_int;
} }
int mbedtls_entropy_add_source( mbedtls_entropy_context *a, int mbedtls_entropy_add_source(mbedtls_entropy_context *a,
mbedtls_entropy_f_source_ptr f_source, void *b, mbedtls_entropy_f_source_ptr f_source, void *b,
size_t c, int d ){ size_t c, int d)
{
unsigned char buf[2]; unsigned char buf[2];
size_t len; size_t len;
f_source(NULL, buf, 1, &len); f_source(NULL, buf, 1, &len);
if( mbedtls_stub.useCounter ){ if (mbedtls_stub.useCounter) {
return mbedtls_stub.retArray[mbedtls_stub.counter++]; return mbedtls_stub.retArray[mbedtls_stub.counter++];
} }
return mbedtls_stub.expected_int; return mbedtls_stub.expected_int;
} }
//From pk.h //From pk.h
int mbedtls_pk_parse_key( mbedtls_pk_context *a, int mbedtls_pk_parse_key(mbedtls_pk_context *a,
const unsigned char *b, size_t c, 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 ){ {
if (mbedtls_stub.useCounter) {
return mbedtls_stub.retArray[mbedtls_stub.counter++]; return mbedtls_stub.retArray[mbedtls_stub.counter++];
} }
return mbedtls_stub.expected_int; return mbedtls_stub.expected_int;
} }
void mbedtls_pk_init( mbedtls_pk_context *ctx ) void mbedtls_pk_init(mbedtls_pk_context *ctx)
{ {
} }
void mbedtls_pk_free( mbedtls_pk_context *ctx ) void mbedtls_pk_free(mbedtls_pk_context *ctx)
{ {
} }
void mbedtls_ssl_config_free( mbedtls_ssl_config *a) void mbedtls_ssl_config_free(mbedtls_ssl_config *a)
{ {
} }
int mbedtls_ssl_set_hs_ecjpake_password( mbedtls_ssl_context *ssl, int mbedtls_ssl_set_hs_ecjpake_password(mbedtls_ssl_context *ssl,
const unsigned char *pw, const unsigned char *pw,
size_t pw_len ) size_t pw_len)
{ {
if( mbedtls_stub.useCounter ){ if (mbedtls_stub.useCounter) {
return mbedtls_stub.retArray[mbedtls_stub.counter++]; return mbedtls_stub.retArray[mbedtls_stub.counter++];
} }
return mbedtls_stub.expected_int; return mbedtls_stub.expected_int;
} }
void mbedtls_ssl_conf_dtls_cookies( mbedtls_ssl_config *conf, void mbedtls_ssl_conf_dtls_cookies(mbedtls_ssl_config *conf,
mbedtls_ssl_cookie_write_t *f_cookie_write, mbedtls_ssl_cookie_write_t *f_cookie_write,
mbedtls_ssl_cookie_check_t *f_cookie_check, mbedtls_ssl_cookie_check_t *f_cookie_check,
void *p_cookie ) void *p_cookie)
{ {
if( mbedtls_stub.cookie_obj && f_cookie_check && mbedtls_stub.cookie_len > 0 ){ if (mbedtls_stub.cookie_obj && f_cookie_check && mbedtls_stub.cookie_len > 0) {
f_cookie_check(mbedtls_stub.cookie_obj, &mbedtls_stub.cookie_value, mbedtls_stub.cookie_len, NULL, 0); f_cookie_check(mbedtls_stub.cookie_obj, &mbedtls_stub.cookie_value, mbedtls_stub.cookie_len, NULL, 0);
} }
if( mbedtls_stub.cookie_obj && f_cookie_write && mbedtls_stub.cookie_len > 0 ){ if (mbedtls_stub.cookie_obj && f_cookie_write && mbedtls_stub.cookie_len > 0) {
unsigned char out[16]; unsigned char out[16];
unsigned char *ptr = &out; unsigned char *ptr = &out;
f_cookie_write(mbedtls_stub.cookie_obj, &ptr, ptr+mbedtls_stub.cookie_len, NULL, 0); f_cookie_write(mbedtls_stub.cookie_obj, &ptr, ptr + mbedtls_stub.cookie_len, NULL, 0);
} }
} }
void mbedtls_ssl_conf_export_keys_cb( mbedtls_ssl_config *conf, void mbedtls_ssl_conf_export_keys_cb(mbedtls_ssl_config *conf,
mbedtls_ssl_export_keys_t *f_export_keys, mbedtls_ssl_export_keys_t *f_export_keys,
void *p_export_keys ) void *p_export_keys)
{ {
if( f_export_keys && p_export_keys){ if (f_export_keys && p_export_keys) {
unsigned char value[40]; unsigned char value[40];
memset(&value, 1, 40); memset(&value, 1, 40);
f_export_keys(p_export_keys, &value, "", 0, 0,0); //failure case f_export_keys(p_export_keys, &value, "", 0, 0, 0); //failure case
f_export_keys(p_export_keys, &value, "", 0, 20,0); //success case f_export_keys(p_export_keys, &value, "", 0, 20, 0); //success case
} }
} }
int mbedtls_ssl_session_reset( mbedtls_ssl_context *ssl ) int mbedtls_ssl_session_reset(mbedtls_ssl_context *ssl)
{ {
if( mbedtls_stub.useCounter ){ if (mbedtls_stub.useCounter) {
return mbedtls_stub.retArray[mbedtls_stub.counter++]; return mbedtls_stub.retArray[mbedtls_stub.counter++];
} }
return mbedtls_stub.expected_int; return mbedtls_stub.expected_int;

View File

@ -37,31 +37,25 @@ 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) 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--; nsdynmemlib_stub.returnCounter--;
return malloc(alloc_size); return malloc(alloc_size);
} } else {
else return (nsdynmemlib_stub.expectedPointer);
{
return(nsdynmemlib_stub.expectedPointer);
} }
} }
void *ns_dyn_mem_temporary_alloc(ns_mem_block_size_t alloc_size) 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--; nsdynmemlib_stub.returnCounter--;
return malloc(alloc_size); return malloc(alloc_size);
} } else {
else return (nsdynmemlib_stub.expectedPointer);
{
return(nsdynmemlib_stub.expectedPointer);
} }
} }
void ns_dyn_mem_free(void *block) void ns_dyn_mem_free(void *block)
{ {
free(block); free(block);
} }

View File

@ -25,7 +25,7 @@ extern "C" {
typedef struct { typedef struct {
uint8_t returnCounter; uint8_t returnCounter;
void* expectedPointer; void *expectedPointer;
} nsdynmemlib_stub_data_t; } nsdynmemlib_stub_data_t;
extern nsdynmemlib_stub_data_t nsdynmemlib_stub; extern nsdynmemlib_stub_data_t nsdynmemlib_stub;

View File

@ -48,8 +48,8 @@ uint32_t randLIB_get_32bit(void)
void *randLIB_get_n_bytes_random(void *data_ptr, uint8_t count) void *randLIB_get_n_bytes_random(void *data_ptr, uint8_t count)
{ {
if(data_ptr && count > 0){ if (data_ptr && count > 0) {
*((int*)data_ptr) = counter++%255; *((int *)data_ptr) = counter++ % 255;
} }
return data_ptr; return data_ptr;
} }

View File

@ -49,7 +49,7 @@ struct coap_s *sn_coap_protocol_init(void *(*used_malloc_func_ptr)(uint16_t), vo
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 *),
int8_t (*used_rx_callback_ptr)(sn_coap_hdr_s *, sn_nsdl_addr_s *, void *param)) int8_t (*used_rx_callback_ptr)(sn_coap_hdr_s *, sn_nsdl_addr_s *, void *param))
{ {
if( sn_coap_protocol_stub.expectedCoap ){ if (sn_coap_protocol_stub.expectedCoap) {
sn_coap_protocol_stub.expectedCoap->sn_coap_protocol_free = used_free_func_ptr; sn_coap_protocol_stub.expectedCoap->sn_coap_protocol_free = used_free_func_ptr;
sn_coap_protocol_stub.expectedCoap->sn_coap_protocol_malloc = used_malloc_func_ptr; sn_coap_protocol_stub.expectedCoap->sn_coap_protocol_malloc = used_malloc_func_ptr;
sn_coap_protocol_stub.expectedCoap->sn_coap_rx_callback = used_rx_callback_ptr; sn_coap_protocol_stub.expectedCoap->sn_coap_rx_callback = used_rx_callback_ptr;

View File

@ -22,7 +22,7 @@ const uint8_t ns_in6addr_any[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
int8_t socket_raw_open(void (*passed_fptr)(void *)) int8_t socket_raw_open(void (*passed_fptr)(void *))
{ {
if( socket_api_stub.counter >= 0){ if (socket_api_stub.counter >= 0) {
return socket_api_stub.values[socket_api_stub.counter--]; return socket_api_stub.values[socket_api_stub.counter--];
} }
@ -31,7 +31,7 @@ int8_t socket_raw_open(void (*passed_fptr)(void *))
int8_t socket_open(uint8_t protocol, uint16_t identifier, void (*passed_fptr)(void *)) int8_t socket_open(uint8_t protocol, uint16_t identifier, void (*passed_fptr)(void *))
{ {
socket_api_stub.recv_cb = passed_fptr; socket_api_stub.recv_cb = passed_fptr;
if( socket_api_stub.counter >= 0){ if (socket_api_stub.counter >= 0) {
return socket_api_stub.values[socket_api_stub.counter--]; return socket_api_stub.values[socket_api_stub.counter--];
} }
@ -40,7 +40,7 @@ int8_t socket_open(uint8_t protocol, uint16_t identifier, void (*passed_fptr)(vo
int8_t socket_close(int8_t socket) int8_t socket_close(int8_t socket)
{ {
if( socket_api_stub.counter >= 0){ if (socket_api_stub.counter >= 0) {
return socket_api_stub.values[socket_api_stub.counter--]; return socket_api_stub.values[socket_api_stub.counter--];
} }
@ -48,7 +48,7 @@ int8_t socket_close(int8_t socket)
} }
int8_t socket_listen(int8_t socket, uint8_t backlog) int8_t socket_listen(int8_t socket, uint8_t backlog)
{ {
if( socket_api_stub.counter >= 0){ if (socket_api_stub.counter >= 0) {
return socket_api_stub.values[socket_api_stub.counter--]; return socket_api_stub.values[socket_api_stub.counter--];
} }
@ -56,7 +56,7 @@ int8_t socket_listen(int8_t socket, uint8_t backlog)
} }
int8_t socket_connect(int8_t socket, ns_address_t *address, uint8_t randomly_take_src_number) int8_t socket_connect(int8_t socket, ns_address_t *address, uint8_t randomly_take_src_number)
{ {
if( socket_api_stub.counter >= 0){ if (socket_api_stub.counter >= 0) {
return socket_api_stub.values[socket_api_stub.counter--]; return socket_api_stub.values[socket_api_stub.counter--];
} }
@ -64,7 +64,7 @@ int8_t socket_connect(int8_t socket, ns_address_t *address, uint8_t randomly_tak
} }
int8_t socket_bind(int8_t socket, const ns_address_t *address) int8_t socket_bind(int8_t socket, const ns_address_t *address)
{ {
if( socket_api_stub.counter >= 0){ if (socket_api_stub.counter >= 0) {
return socket_api_stub.values[socket_api_stub.counter--]; return socket_api_stub.values[socket_api_stub.counter--];
} }
@ -73,11 +73,11 @@ int8_t socket_bind(int8_t socket, const ns_address_t *address)
int16_t socket_read(int8_t socket, ns_address_t *address, uint8_t *buffer, uint16_t length) int16_t socket_read(int8_t socket, ns_address_t *address, uint8_t *buffer, uint16_t length)
{ {
if( address ){ if (address) {
memset(&address->address, 0, 16); memset(&address->address, 0, 16);
address->identifier = 0; address->identifier = 0;
} }
if( socket_api_stub.counter >= 0){ if (socket_api_stub.counter >= 0) {
return socket_api_stub.values[socket_api_stub.counter--]; return socket_api_stub.values[socket_api_stub.counter--];
} }
@ -85,7 +85,7 @@ int16_t socket_read(int8_t socket, ns_address_t *address, uint8_t *buffer, uint1
} }
int8_t socket_getpeername(int8_t socket, ns_address_t *address) int8_t socket_getpeername(int8_t socket, ns_address_t *address)
{ {
if( socket_api_stub.counter >= 0){ if (socket_api_stub.counter >= 0) {
return socket_api_stub.values[socket_api_stub.counter--]; return socket_api_stub.values[socket_api_stub.counter--];
} }
@ -93,7 +93,7 @@ int8_t socket_getpeername(int8_t socket, ns_address_t *address)
} }
int8_t socket_setsockopt(int8_t socket, uint8_t level, uint8_t opt_name, const void *opt_value, uint16_t opt_len) int8_t socket_setsockopt(int8_t socket, uint8_t level, uint8_t opt_name, const void *opt_value, uint16_t opt_len)
{ {
if( socket_api_stub.counter >= 0){ if (socket_api_stub.counter >= 0) {
return socket_api_stub.values[socket_api_stub.counter--]; return socket_api_stub.values[socket_api_stub.counter--];
} }
@ -101,7 +101,7 @@ int8_t socket_setsockopt(int8_t socket, uint8_t level, uint8_t opt_name, const v
} }
int8_t socket_getsockopt(int8_t socket, uint8_t level, uint8_t opt_name, void *opt_value, uint16_t *opt_len) int8_t socket_getsockopt(int8_t socket, uint8_t level, uint8_t opt_name, void *opt_value, uint16_t *opt_len)
{ {
if( socket_api_stub.counter >= 0){ if (socket_api_stub.counter >= 0) {
return socket_api_stub.values[socket_api_stub.counter--]; return socket_api_stub.values[socket_api_stub.counter--];
} }
@ -109,7 +109,7 @@ int8_t socket_getsockopt(int8_t socket, uint8_t level, uint8_t opt_name, void *o
} }
int16_t socket_sendmsg(int8_t socket, const ns_msghdr_t *msg, int flags) int16_t socket_sendmsg(int8_t socket, const ns_msghdr_t *msg, int flags)
{ {
if( socket_api_stub.counter >= 0){ if (socket_api_stub.counter >= 0) {
return socket_api_stub.values[socket_api_stub.counter--]; return socket_api_stub.values[socket_api_stub.counter--];
} }

View File

@ -15,7 +15,7 @@
* limitations under the License. * limitations under the License.
*/ */
#include "eventOS_event_timer.h" #include "eventOS_event_timer.h"
// Timeout structure, already typedefed to timeout_t // Timeout structure, already typedefed to timeout_t
struct timeout_entry_t { struct timeout_entry_t {

View File

@ -70,9 +70,9 @@ typedef struct {
uint16_t data_len; /**< Length of data IN. */ uint16_t data_len; /**< Length of data IN. */
const uint8_t *adata_ptr; /**< Pointer to authentication data. */ const uint8_t *adata_ptr; /**< Pointer to authentication data. */
uint16_t adata_len; /**< Length of authentication data. */ uint16_t adata_len; /**< Length of authentication data. */
unsigned ccm_encode_mode:1; /**< Encryption modeAES_CCM_ENCRYPT or AES_CCM_DECRYPT. */ unsigned ccm_encode_mode: 1; /**< Encryption modeAES_CCM_ENCRYPT or AES_CCM_DECRYPT. */
unsigned ccm_sec_level:3; /**< Encryption operation security level 0-7. */ unsigned ccm_sec_level: 3; /**< Encryption operation security level 0-7. */
unsigned ccm_l_param:4; /**< Can be 2 or 3. 2 when NONCE length is 13 and 3 when 12*/ unsigned ccm_l_param: 4; /**< Can be 2 or 3. 2 when NONCE length is 13 and 3 when 12*/
uint8_t mic_len; /**< ccm_sec_init() sets here the length of MIC. */ uint8_t mic_len; /**< ccm_sec_init() sets here the length of MIC. */
uint8_t *mic; /**< Encrypt process writes MIC. Decrypt reads it and compares it with the MIC obtained from data. */ uint8_t *mic; /**< Encrypt process writes MIC. Decrypt reads it and compares it with the MIC obtained from data. */
const uint8_t *key_ptr; /**< Encyption key pointer to 128-bit key. */ const uint8_t *key_ptr; /**< Encyption key pointer to 128-bit key. */

View File

@ -66,10 +66,10 @@
* /enum dhcp_instance_type * /enum dhcp_instance_type
* /brief DHCP instance types. * /brief DHCP instance types.
*/ */
typedef enum dhcp_instance_type typedef enum dhcp_instance_type {
{
DHCP_INSTANCE_CLIENT, DHCP_INSTANCE_CLIENT,
DHCP_INSTANCE_SERVER DHCP_INSTANCE_SERVER,
DHCP_INTANCE_RELAY_AGENT
} dhcp_instance_type_e; } 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); 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. * \brief Deletes a server instance.
* *

View File

@ -42,7 +42,7 @@ typedef struct eth_mac_api_s eth_mac_api_t;
typedef struct eth_data_conf_s { typedef struct eth_data_conf_s {
uint8_t msduHandle; /**< Handle associated with MSDU */ uint8_t msduHandle; /**< Handle associated with MSDU */
uint8_t status; /**< Status of the last transaction */ uint8_t status; /**< Status of the last transaction */
}eth_data_conf_t; } eth_data_conf_t;
/** /**
* \brief Struct eth_data_req_s defines arguments for data request message * \brief Struct eth_data_req_s defines arguments for data request message
@ -67,7 +67,7 @@ typedef struct eth_data_ind_s {
uint16_t etehernet_type; /**< Ethernet type */ uint16_t etehernet_type; /**< Ethernet type */
uint8_t link_quality; /**< Link quality */ uint8_t link_quality; /**< Link quality */
int8_t dbm; /**< measured dBm */ int8_t dbm; /**< measured dBm */
}eth_data_ind_t; } eth_data_ind_t;
/** /**
* @brief Creates ethernet MAC API instance which will use driver given * @brief Creates ethernet MAC API instance which will use driver given
@ -91,21 +91,21 @@ extern int8_t ethernet_mac_destroy(eth_mac_api_t *mac_api);
* @param api API to handle the request * @param api API to handle the request
* @param data Data containing request parameters * @param data Data containing request parameters
*/ */
typedef void eth_mac_data_request(const eth_mac_api_t* api, const eth_data_req_t *data); typedef void eth_mac_data_request(const eth_mac_api_t *api, const eth_data_req_t *data);
/** /**
* @brief data_confirm confirm is called as a response to data_request * @brief data_confirm confirm is called as a response to data_request
* @param api The API which handled the request * @param api The API which handled the request
* @param data Data containing confirm parameters * @param data Data containing confirm parameters
*/ */
typedef void eth_mac_data_confirm(const eth_mac_api_t* api, const eth_data_conf_t *data ); typedef void eth_mac_data_confirm(const eth_mac_api_t *api, const eth_data_conf_t *data);
/** /**
* @brief data_indication Data indication is called when MAC layer has received data * @brief data_indication Data indication is called when MAC layer has received data
* @param api The API which handled the response * @param api The API which handled the response
* @param data Data containing indication parameters * @param data Data containing indication parameters
*/ */
typedef void eth_mac_data_indication(const eth_mac_api_t* api, const eth_data_ind_t *data ); typedef void eth_mac_data_indication(const eth_mac_api_t *api, const eth_data_ind_t *data);
/** /**
* @brief Set 48 bit address from MAC * @brief Set 48 bit address from MAC
@ -113,7 +113,7 @@ typedef void eth_mac_data_indication(const eth_mac_api_t* api, const eth_data_in
* @param mac48 Pointer having mac address to be set * @param mac48 Pointer having mac address to be set
* @return 0 if successful, -1 otherwise * @return 0 if successful, -1 otherwise
*/ */
typedef int8_t eth_mac_mac48_address_set(const eth_mac_api_t* api, const uint8_t *mac48); typedef int8_t eth_mac_mac48_address_set(const eth_mac_api_t *api, const uint8_t *mac48);
/** /**
* @brief Read 48 bit address from MAC * @brief Read 48 bit address from MAC
@ -121,7 +121,7 @@ typedef int8_t eth_mac_mac48_address_set(const eth_mac_api_t* api, const uint8_t
* @param mac48_buf Pointer where mac address can be written * @param mac48_buf Pointer where mac address can be written
* @return 0 if successful, -1 otherwise * @return 0 if successful, -1 otherwise
*/ */
typedef int8_t eth_mac_mac48_address_get(const eth_mac_api_t* api, uint8_t *mac48_buf); typedef int8_t eth_mac_mac48_address_get(const eth_mac_api_t *api, uint8_t *mac48_buf);
/** /**
* @brief Upper layer will call this function, when MAC is taken into use * @brief Upper layer will call this function, when MAC is taken into use
@ -132,7 +132,7 @@ typedef int8_t eth_mac_mac48_address_get(const eth_mac_api_t* api, uint8_t *mac4
* @return 0 if success; -1 if api is NULL or not found * @return 0 if success; -1 if api is NULL or not found
*/ */
typedef int8_t eth_mac_api_initialize(eth_mac_api_t *api, eth_mac_data_confirm *conf_cb, typedef int8_t eth_mac_api_initialize(eth_mac_api_t *api, eth_mac_data_confirm *conf_cb,
eth_mac_data_indication *ind_cb, uint8_t parent_id); eth_mac_data_indication *ind_cb, uint8_t parent_id);
/** /**
* \brief Struct eth_mac_api_s defines functions for two-way communications between ethernet MAC and Upper layer. * \brief Struct eth_mac_api_s defines functions for two-way communications between ethernet MAC and Upper layer.

View File

@ -46,8 +46,7 @@ typedef struct fhss_callback fhss_callback_t;
/** /**
* @brief FHSS states. * @brief FHSS states.
*/ */
typedef enum typedef enum {
{
FHSS_UNSYNCHRONIZED, FHSS_UNSYNCHRONIZED,
FHSS_SYNCHRONIZED, FHSS_SYNCHRONIZED,
} fhss_states; } 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 api FHSS instance.
* @param fhss_state FHSS state (FHSS states are defined by FHSS api). * @param fhss_state FHSS state (FHSS states are defined by FHSS api).
* @param pan_id PAN id of the network FHSS synchronizes with. * @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. * @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); 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. * @brief Change channel.
* @param fhss_api FHSS instance. * @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_tx_queue_size *read_tx_queue_size; /**< Read MAC TX queue size. */
mac_read_mac_address *read_mac_address; /**< Read MAC address. */ mac_read_mac_address *read_mac_address; /**< Read MAC address. */
mac_read_datarate *read_datarate; /**< Read PHY datarate. */ mac_read_datarate *read_datarate; /**< Read PHY datarate. */
mac_read_timestamp *read_timestamp; /**< Read timestamp. */
mac_change_channel *change_channel; /**< Change channel. */ mac_change_channel *change_channel; /**< Change channel. */
mac_send_fhss_frame *send_fhss_frame; /**< Send FHSS frame. */ mac_send_fhss_frame *send_fhss_frame; /**< Send FHSS frame. */
mac_synch_lost_notification *synch_lost_notification; /**< Send notification when FHSS synchronization is lost. */ 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. * @brief WS channel functions.
*/ */
typedef enum typedef enum {
{
/** Fixed channel. */ /** Fixed channel. */
WS_FIXED_CHANNEL, WS_FIXED_CHANNEL,
/** TR51 channel function. */ /** TR51 channel function. */
@ -49,8 +48,7 @@ typedef enum
* \brief Struct fhss_tuning_parameter defines FHSS tuning parameters. * \brief Struct fhss_tuning_parameter defines FHSS tuning parameters.
* All delays are given in microseconds. * 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). */ /** Delay between data pushed to PHY TX function and TX started (Contains CSMA-CA maximum random period). */
uint32_t tx_processing_delay; uint32_t tx_processing_delay;
@ -64,8 +62,7 @@ typedef struct fhss_tuning_parameter
/** /**
* \brief Struct fhss_configuration defines basic configuration of FHSS. * \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*/ /** Tuning parameters can be used to enhance synchronization accuracy*/
fhss_tuning_parameter_t fhss_tuning_parameters; 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. * \brief Struct fhss_ws_configuration defines configuration of WS FHSS.
*/ */
typedef struct fhss_ws_configuration typedef struct fhss_ws_configuration {
{ /** WS unicast channel function. */
/** WS channel function. */ fhss_ws_channel_functions ws_uc_channel_function;
fhss_ws_channel_functions ws_channel_function;
/** WS broadcast channel function. */
fhss_ws_channel_functions ws_bc_channel_function;
/** Broadcast schedule identifier. */ /** Broadcast schedule identifier. */
uint16_t bsi; uint16_t bsi;
@ -111,6 +110,12 @@ typedef struct fhss_ws_configuration
/** Broadcast dwell interval. Range: 15-250 milliseconds. */ /** Broadcast dwell interval. Range: 15-250 milliseconds. */
uint8_t fhss_bc_dwell_interval; uint8_t fhss_bc_dwell_interval;
/** Unicast fixed channel */
uint8_t unicast_fixed_channel;
/** Broadcast fixed channel */
uint8_t broadcast_fixed_channel;
/** Channel mask. */ /** Channel mask. */
uint32_t channel_mask[8]; 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. * \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. * 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 */ /** 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); 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. * \brief Struct fhss_synch_configuration defines the synchronization time configurations.
* Border router application must define and set these configuration for FHSS network. * 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. */ /** Number of broadcast channels. */
uint8_t fhss_number_of_bc_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. * \brief Struct fhss_statistics defines the available FHSS statistics.
*/ */
typedef struct fhss_statistics typedef struct fhss_statistics {
{
/** FHSS synchronization drift compensation (us/channel). */ /** FHSS synchronization drift compensation (us/channel). */
int16_t fhss_drift_compensation; int16_t fhss_drift_compensation;

View File

@ -34,9 +34,10 @@ extern "C" {
* @brief unicast_timing_info Unicast timing/hopping schedule information structure. * @brief unicast_timing_info Unicast timing/hopping schedule information structure.
*/ */
typedef struct unicast_timing_info { typedef struct unicast_timing_info {
unsigned unicast_channel_function:3; /**< Unicast schedule channel function */ unsigned unicast_channel_function: 3; /**< Unicast schedule channel function */
uint8_t unicast_dwell_interval; /**< Unicast dwell interval */ uint8_t unicast_dwell_interval; /**< Unicast dwell interval */
uint16_t unicast_number_of_channels; /**< Unicast number of channels */ 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 */ uint_fast24_t ufsi; /**< Unicast fractional sequence interval */
uint32_t utt_rx_timestamp; /**< UTT-IE reception timestamp */ uint32_t utt_rx_timestamp; /**< UTT-IE reception timestamp */
} unicast_timing_info_t; } unicast_timing_info_t;
@ -45,8 +46,9 @@ typedef struct unicast_timing_info {
* @brief broadcast_timing_info Broadcast timing/hopping schedule information structure. * @brief broadcast_timing_info Broadcast timing/hopping schedule information structure.
*/ */
typedef struct broadcast_timing_info { typedef struct broadcast_timing_info {
unsigned broadcast_channel_function:3; /**< Broadcast schedule channel function */ unsigned broadcast_channel_function: 3; /**< Broadcast schedule channel function */
uint8_t broadcast_dwell_interval; /**< Broadcast dwell interval */ 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_slot; /**< Broadcast slot number */
uint16_t broadcast_schedule_id; /**< Broadcast schedule identifier */ uint16_t broadcast_schedule_id; /**< Broadcast schedule identifier */
uint_fast24_t broadcast_interval_offset; /**< Broadcast interval offset */ 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 fhss_api FHSS instance.
* @param eui64 EUI-64 address of parent. * @param eui64 EUI-64 address of parent.
* @param bc_timing_info Pointer to parent broadcast timing/hopping schedule info. * @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. * @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. * @brief Remove parent which was set by ns_fhss_ws_set_parent function.

View File

@ -95,7 +95,7 @@ typedef struct mac_description_storage_size_s {
typedef enum mac_extended_address_type { typedef enum mac_extended_address_type {
MAC_EXTENDED_READ_ONLY, /** EUID64 which is unique */ MAC_EXTENDED_READ_ONLY, /** EUID64 which is unique */
MAC_EXTENDED_DYNAMIC /** Configured MAC 64-bit address to RAM and Radio */ MAC_EXTENDED_DYNAMIC /** Configured MAC 64-bit address to RAM and Radio */
}mac_extended_address_type; } mac_extended_address_type;
//External MAC functions //External MAC functions
/** /**
@ -113,14 +113,14 @@ typedef enum mac_extended_address_type {
* @param id The identifier of the MLME primitive * @param id The identifier of the MLME primitive
* @param data Primitive specific data (\see mlme.h) * @param data Primitive specific data (\see mlme.h)
*/ */
typedef void mlme_request(const mac_api_t* api, mlme_primitive id, const void *data); typedef void mlme_request(const mac_api_t *api, mlme_primitive id, const void *data);
/** /**
* @brief mcps_request MCPS_DATA request call * @brief mcps_request MCPS_DATA request call
* @param api API to handle the request * @param api API to handle the request
* @param data MCPS-DATA.request specific values * @param data MCPS-DATA.request specific values
*/ */
typedef void mcps_data_request(const mac_api_t* api, const mcps_data_req_t *data); typedef void mcps_data_request(const mac_api_t *api, const mcps_data_req_t *data);
/** /**
* @brief mcps_request MCPS_DATA with IE extions request call * @brief mcps_request MCPS_DATA with IE extions request call
@ -131,14 +131,15 @@ typedef void mcps_data_request(const mac_api_t* api, const mcps_data_req_t *data
* *
* Asynch data request is mac standard extension. asynch_channel_list include channel mask which channel message is requested to send. * Asynch data request is mac standard extension. asynch_channel_list include channel mask which channel message is requested to send.
*/ */
typedef void mcps_data_request_ext(const mac_api_t* api, const mcps_data_req_t *data, const mcps_data_req_ie_list_t *ie_ext, const struct channel_list_s *asynch_channel_list); typedef void mcps_data_request_ext(const mac_api_t *api, const mcps_data_req_t *data, const mcps_data_req_ie_list_t *ie_ext, const struct channel_list_s *asynch_channel_list);
/** /**
* @brief mcps_purge_request MCPS_PURGE request call * @brief mcps_purge_request MCPS_PURGE request call
* @param api API to handle the request * @param api API to handle the request
* @param data MCPS-PURGE.request specific values * @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) //Upper layer specific callback functions (will also be set by Upper layer after mac_api_t has been created and given to it)
@ -147,7 +148,7 @@ typedef void mcps_purge_request(const mac_api_t* api, const mcps_purge_t *data);
* @param api The API which handled the response * @param api The API which handled the response
* @param data MCPS-DATA.confirm specific values * @param data MCPS-DATA.confirm specific values
*/ */
typedef void mcps_data_confirm(const mac_api_t* api, const mcps_data_conf_t *data); typedef void mcps_data_confirm(const mac_api_t *api, const mcps_data_conf_t *data);
/** /**
* @brief mcps_data_confirm_ext MCPS-DATA confirm with Enhanced ACK payload is called as a response to MCPS-DATA request * @brief mcps_data_confirm_ext MCPS-DATA confirm with Enhanced ACK payload is called as a response to MCPS-DATA request
@ -155,14 +156,14 @@ typedef void mcps_data_confirm(const mac_api_t* api, const mcps_data_conf_t *dat
* @param data MCPS-DATA.confirm specific values * @param data MCPS-DATA.confirm specific values
* @param conf_data Possible Confirmation Data * @param conf_data Possible Confirmation Data
*/ */
typedef void mcps_data_confirm_ext(const mac_api_t* api, const mcps_data_conf_t *data, const mcps_data_conf_payload_t *conf_data); typedef void mcps_data_confirm_ext(const mac_api_t *api, const mcps_data_conf_t *data, const mcps_data_conf_payload_t *conf_data);
/** /**
* @brief mcps_data_indication MCPS-DATA indication is called when MAC layer has received data * @brief mcps_data_indication MCPS-DATA indication is called when MAC layer has received data
* @param api The API which handled the response * @param api The API which handled the response
* @param data MCPS-DATA.indication specific values * @param data MCPS-DATA.indication specific values
*/ */
typedef void mcps_data_indication(const mac_api_t* api, const mcps_data_ind_t *data); typedef void mcps_data_indication(const mac_api_t *api, const mcps_data_ind_t *data);
/** /**
* @brief mcps_data_indication MCPS-DATA indication is called when MAC layer has received data * @brief mcps_data_indication MCPS-DATA indication is called when MAC layer has received data
@ -170,7 +171,7 @@ typedef void mcps_data_indication(const mac_api_t* api, const mcps_data_ind_t *d
* @param data MCPS-DATA.indication specific values * @param data MCPS-DATA.indication specific values
* @param ie_ext Information element list * @param ie_ext Information element list
*/ */
typedef void mcps_data_indication_ext(const mac_api_t* api, const mcps_data_ind_t *data, const mcps_data_ie_list_t *ie_ext); typedef void mcps_data_indication_ext(const mac_api_t *api, const mcps_data_ind_t *data, const mcps_data_ie_list_t *ie_ext);
/** /**
* @brief mcps_ack_data_req_ext Callback for request IE elements and payload to enhanced ACK * @brief mcps_ack_data_req_ext Callback for request IE elements and payload to enhanced ACK
@ -179,7 +180,7 @@ typedef void mcps_data_indication_ext(const mac_api_t* api, const mcps_data_ind_
* @param rssi Signal strength for received packet * @param rssi Signal strength for received packet
* @param lqi Link quality to neighbor * @param lqi Link quality to neighbor
*/ */
typedef void mcps_ack_data_req_ext(const mac_api_t* api, mcps_ack_data_payload_t *data, int8_t rssi, uint8_t lqi); typedef void mcps_ack_data_req_ext(const mac_api_t *api, mcps_ack_data_payload_t *data, int8_t rssi, uint8_t lqi);
/** /**
@ -187,7 +188,7 @@ typedef void mcps_ack_data_req_ext(const mac_api_t* api, mcps_ack_data_payload_t
* @param api The API which handled the request * @param api The API which handled the request
* @param data MCPS-PURGE.confirm specific values * @param data MCPS-PURGE.confirm specific values
*/ */
typedef void mcps_purge_confirm( const mac_api_t* api, mcps_purge_conf_t *data ); typedef void mcps_purge_confirm(const mac_api_t *api, mcps_purge_conf_t *data);
/** /**
* @brief mlme_confirm One of the MLME primitive confirm callbacks * @brief mlme_confirm One of the MLME primitive confirm callbacks
@ -195,7 +196,7 @@ typedef void mcps_purge_confirm( const mac_api_t* api, mcps_purge_conf_t *data )
* @param id The identifier of the MLME primitive * @param id The identifier of the MLME primitive
* @param data Primitive specific data (\see mlme.h) * @param data Primitive specific data (\see mlme.h)
*/ */
typedef void mlme_confirm(const mac_api_t* api, mlme_primitive id, const void *data); typedef void mlme_confirm(const mac_api_t *api, mlme_primitive id, const void *data);
/** /**
* @brief mlme_indication One of the * @brief mlme_indication One of the
@ -203,28 +204,28 @@ typedef void mlme_confirm(const mac_api_t* api, mlme_primitive id, const void *d
* @param id The identifier of the MLME primitive * @param id The identifier of the MLME primitive
* @param data Primitive specific data (\see mlme.h) * @param data Primitive specific data (\see mlme.h)
*/ */
typedef void mlme_indication(const mac_api_t* api, mlme_primitive id, const void *data); typedef void mlme_indication(const mac_api_t *api, mlme_primitive id, const void *data);
/** /**
* @brief Set extended address from MAC * @brief Set extended address from MAC
* @param api API to handle the request * @param api API to handle the request
* @param mac64 pointer * @param mac64 pointer
*/ */
typedef int8_t mac_ext_mac64_address_set(const mac_api_t* api, const uint8_t *mac64); typedef int8_t mac_ext_mac64_address_set(const mac_api_t *api, const uint8_t *mac64);
/** /**
* @brief Read extended address from MAC * @brief Read extended address from MAC
* @param api API to handle the request * @param api API to handle the request
* @param mac64_buf Pointer where mac extended address can be written * @param mac64_buf Pointer where mac extended address can be written
*/ */
typedef int8_t mac_ext_mac64_address_get(const mac_api_t* api, mac_extended_address_type type, uint8_t *mac64_buf); typedef int8_t mac_ext_mac64_address_get(const mac_api_t *api, mac_extended_address_type type, uint8_t *mac64_buf);
/** /**
* @brief Read MAC security description storage sizes from MAC * @brief Read MAC security description storage sizes from MAC
* @param api API to handle the request * @param api API to handle the request
* @param buffer Pointer where supported sizes can be written * @param buffer Pointer where supported sizes can be written
*/ */
typedef int8_t mac_storage_decription_sizes_get(const mac_api_t* api, mac_description_storage_size_t *buffer); typedef int8_t mac_storage_decription_sizes_get(const mac_api_t *api, mac_description_storage_size_t *buffer);
/** /**
* @brief mac_api_initialize Initialises MAC layer into use, callbacks must be non-NULL. * @brief mac_api_initialize Initialises MAC layer into use, callbacks must be non-NULL.

View File

@ -61,8 +61,8 @@
* See IEEE standard 802.15.4-2006 (e.g end of table 41) for more details * See IEEE standard 802.15.4-2006 (e.g end of table 41) for more details
*/ */
typedef struct mlme_security_s { typedef struct mlme_security_s {
unsigned SecurityLevel:3; /**< Security level */ unsigned SecurityLevel: 3; /**< Security level */
unsigned KeyIdMode:2; /**< 2-bit value which define key source and ID use case */ unsigned KeyIdMode: 2; /**< 2-bit value which define key source and ID use case */
uint8_t KeyIndex; /**< Key index */ uint8_t KeyIndex; /**< Key index */
uint8_t Keysource[8]; /**< Key source */ uint8_t Keysource[8]; /**< Key source */
} mlme_security_t; } mlme_security_t;
@ -79,7 +79,7 @@ typedef struct mlme_security_s {
*/ */
typedef struct mac_header_IE_s { typedef struct mac_header_IE_s {
uint8_t *content_ptr; /**< Content data */ uint8_t *content_ptr; /**< Content data */
unsigned length:7; /**< Element length 0- 127 */ unsigned length: 7; /**< Element length 0- 127 */
uint8_t id; /**< Element ID */ uint8_t id; /**< Element ID */
} mac_header_IE_t; } mac_header_IE_t;
@ -95,8 +95,8 @@ typedef struct mac_header_IE_s {
*/ */
typedef struct mac_payload_IE_s { typedef struct mac_payload_IE_s {
uint8_t *content_ptr; /**< Content data */ uint8_t *content_ptr; /**< Content data */
unsigned length:11; /**< Element length 0- 2047 */ unsigned length: 11; /**< Element length 0- 2047 */
unsigned id:4; /**< Group ID */ unsigned id: 4; /**< Group ID */
} mac_payload_IE_t; } mac_payload_IE_t;
#endif /* MAC_COMMON_DEFINES_H_ */ #endif /* MAC_COMMON_DEFINES_H_ */

View File

@ -32,18 +32,18 @@
* See IEEE standard 802.15.4-2006 (table 41) for more details * See IEEE standard 802.15.4-2006 (table 41) for more details
*/ */
typedef struct mcps_data_req_s { typedef struct mcps_data_req_s {
unsigned SrcAddrMode:2; /**< Source address mode */ unsigned SrcAddrMode: 2; /**< Source address mode */
unsigned DstAddrMode:2; /**< Destination address mode */ unsigned DstAddrMode: 2; /**< Destination address mode */
uint16_t DstPANId; /**< Destination PAN ID */ uint16_t DstPANId; /**< Destination PAN ID */
uint8_t DstAddr[8]; /**< Destination address */ uint8_t DstAddr[8]; /**< Destination address */
uint16_t msduLength; /**< Service data unit length */ uint16_t msduLength; /**< Service data unit length */
uint8_t *msdu; /**< Service data unit */ uint8_t *msdu; /**< Service data unit */
uint8_t msduHandle; /**< Handle associated with MSDU */ uint8_t msduHandle; /**< Handle associated with MSDU */
bool TxAckReq: 1; /**< Specifies whether ACK is needed or not */ bool TxAckReq: 1; /**< Specifies whether ACK is needed or not */
bool InDirectTx:1; /**< Specifies whether indirect or direct transmission is used */ bool InDirectTx: 1; /**< Specifies whether indirect or direct transmission is used */
bool PendingBit: 1; /**< Specifies whether more fragments are to be sent or not */ bool PendingBit: 1; /**< Specifies whether more fragments are to be sent or not */
bool SeqNumSuppressed:1; /**< True suppress sequence number from frame. This will be only checked when 2015 extension is enabled */ bool SeqNumSuppressed: 1; /**< True suppress sequence number from frame. This will be only checked when 2015 extension is enabled */
bool PanIdSuppressed:1; /**< True suppress PAN-id is done when possible from frame. This will be only checked when 2015 extension is enabled */ bool PanIdSuppressed: 1; /**< True suppress PAN-id is done when possible from frame. This will be only checked when 2015 extension is enabled */
mlme_security_t Key; /**< Security key */ mlme_security_t Key; /**< Security key */
} mcps_data_req_t; } mcps_data_req_t;
@ -82,10 +82,10 @@ typedef struct mcps_data_conf_payload_s {
* See IEEE standard 802.15.4-2006 (table 43) for more details * See IEEE standard 802.15.4-2006 (table 43) for more details
*/ */
typedef struct mcps_data_ind_s { typedef struct mcps_data_ind_s {
unsigned SrcAddrMode:2; /**< 0x00 = no address 0x01 = reserved 0x02 = 16-bit short address 0x03 = 64-bit extended address */ unsigned SrcAddrMode: 2; /**< 0x00 = no address 0x01 = reserved 0x02 = 16-bit short address 0x03 = 64-bit extended address */
uint16_t SrcPANId; /**< Source PAN ID */ uint16_t SrcPANId; /**< Source PAN ID */
uint8_t SrcAddr[8]; /**< Source address */ uint8_t SrcAddr[8]; /**< Source address */
unsigned DstAddrMode:2; /**< Destination address mode */ unsigned DstAddrMode: 2; /**< Destination address mode */
uint16_t DstPANId; /**< Destination PAN ID */ uint16_t DstPANId; /**< Destination PAN ID */
uint8_t DstAddr[8]; /**< Destination address */ uint8_t DstAddr[8]; /**< Destination address */
uint8_t mpduLinkQuality; /**< LQI value measured during reception of the MPDU */ uint8_t mpduLinkQuality; /**< LQI value measured during reception of the MPDU */

View File

@ -32,13 +32,13 @@
* See IEEE standard 802.15.4-2006 (table 55) for more details * See IEEE standard 802.15.4-2006 (table 55) for more details
*/ */
typedef struct mlme_pan_descriptor_s { typedef struct mlme_pan_descriptor_s {
unsigned CoordAddrMode:2; /**<Coordinator address mode MAC_ADDR_MODE_16_BIT or MAC_ADDR_MODE_64_BIT */ unsigned CoordAddrMode: 2; /**<Coordinator address mode MAC_ADDR_MODE_16_BIT or MAC_ADDR_MODE_64_BIT */
uint16_t CoordPANId; /**<PAN-id */ uint16_t CoordPANId; /**<PAN-id */
uint8_t CoordAddress[8]; /**< Coordinator based CoordAddrMode */ uint8_t CoordAddress[8]; /**< Coordinator based CoordAddrMode */
uint8_t LogicalChannel; /**< Pan's Logical channel */ uint8_t LogicalChannel; /**< Pan's Logical channel */
uint8_t ChannelPage; /**< Channel Page*/ uint8_t ChannelPage; /**< Channel Page*/
uint8_t SuperframeSpec[2]; /**< Superframe specification */ uint8_t SuperframeSpec[2]; /**< Superframe specification */
bool GTSPermit:1; /**< true = GTS enabled false = disabled */ bool GTSPermit: 1; /**< true = GTS enabled false = disabled */
uint8_t LinkQuality; /**< Link quality based on received packet to Coordinator 0-0xff */ uint8_t LinkQuality; /**< Link quality based on received packet to Coordinator 0-0xff */
uint32_t Timestamp; /**< Time stamp for received packet */ uint32_t Timestamp; /**< Time stamp for received packet */
uint8_t SecurityFailure; /**< Indicates payload security failure */ uint8_t SecurityFailure; /**< Indicates payload security failure */
@ -60,7 +60,7 @@ typedef enum {
BEACON_REQUEST = 7, /**<Beacon request */ BEACON_REQUEST = 7, /**<Beacon request */
COORDINATOR_REALIGNMENT = 8, /**<Coordinator Realignment (Not supported)*/ COORDINATOR_REALIGNMENT = 8, /**<Coordinator Realignment (Not supported)*/
GTS_REQUEST = 9 /**<GTS request (Not supported)*/ GTS_REQUEST = 9 /**<GTS request (Not supported)*/
//Reserved //Reserved
} mlme_command_type_t; } mlme_command_type_t;
/** /**
@ -80,8 +80,8 @@ typedef enum {
* See IEEE standard 802.15.4-2006 (table 90) for more details * See IEEE standard 802.15.4-2006 (table 90) for more details
*/ */
typedef struct mlme_key_usage_descriptor_s { typedef struct mlme_key_usage_descriptor_s {
unsigned FrameType:3; /**<0 = Beacon Frame, 1 = Data Frame or 3 Command Frame */ unsigned FrameType: 3; /**<0 = Beacon Frame, 1 = Data Frame or 3 Command Frame */
unsigned CommandFrameIdentifier:4; /**< Set this part only when FrameType is 3 */ unsigned CommandFrameIdentifier: 4; /**< Set this part only when FrameType is 3 */
} mlme_key_usage_descriptor_t; } mlme_key_usage_descriptor_t;
/** /**
@ -91,8 +91,8 @@ typedef struct mlme_key_usage_descriptor_s {
*/ */
typedef struct mlme_key_device_descriptor_s { typedef struct mlme_key_device_descriptor_s {
uint8_t DeviceDescriptorHandle; /**< User defined unique ID to key User */ uint8_t DeviceDescriptorHandle; /**< User defined unique ID to key User */
bool UniqueDevice:1; /**< true = Key description is for Key Pair Key usage only, False = group key */ bool UniqueDevice: 1; /**< true = Key description is for Key Pair Key usage only, False = group key */
bool Blacklisted:1; /**< true = Description is black listed, False = valid to use */ bool Blacklisted: 1; /**< true = Description is black listed, False = valid to use */
} mlme_key_device_descriptor_t; } mlme_key_device_descriptor_t;
/** /**
@ -117,10 +117,10 @@ typedef enum {
* See IEEE standard 802.15.4-2006 (table 92) for more details * See IEEE standard 802.15.4-2006 (table 92) for more details
*/ */
typedef struct mlme_security_level_descriptor_s { typedef struct mlme_security_level_descriptor_s {
unsigned FrameType:3; /**<0 = Beacon Frame, 1 = Data Frame or 3 Command Frame */ unsigned FrameType: 3; /**<0 = Beacon Frame, 1 = Data Frame or 3 Command Frame */
unsigned CommandFrameIdentifier:4; /**< Set this part only when FrameType is 3 */ unsigned CommandFrameIdentifier: 4; /**< Set this part only when FrameType is 3 */
unsigned SecurityMinimum:3; /**< Define Minimum acceptable security level for RX */ unsigned SecurityMinimum: 3; /**< Define Minimum acceptable security level for RX */
bool DeviceOverrideSecurityMinimum:1; /**< Set false */ bool DeviceOverrideSecurityMinimum: 1; /**< Set false */
} mlme_security_level_descriptor_t; } mlme_security_level_descriptor_t;
/** /**
@ -133,7 +133,7 @@ typedef struct mlme_device_descriptor_s {
uint16_t ShortAddress; /**< Device 16-bit short address 0xffff means not defined */ uint16_t ShortAddress; /**< Device 16-bit short address 0xffff means not defined */
uint8_t ExtAddress[8]; /**< Device Extended 64-bit address */ uint8_t ExtAddress[8]; /**< Device Extended 64-bit address */
uint32_t FrameCounter; /**< Security Frame counter */ uint32_t FrameCounter; /**< Security Frame counter */
bool Exempt:1; /**< Set false */ bool Exempt: 1; /**< Set false */
} mlme_device_descriptor_t; } mlme_device_descriptor_t;
/** /**
@ -143,7 +143,7 @@ typedef struct mlme_device_descriptor_s {
*/ */
typedef struct mlme_key_id_lookup_descriptor_s { typedef struct mlme_key_id_lookup_descriptor_s {
uint8_t LookupData[9]; /**< Key Lookup data */ uint8_t LookupData[9]; /**< Key Lookup data */
unsigned LookupDataSize:1; /**< Key Lookup data size 0= 5 1 is 9 bytes */ unsigned LookupDataSize: 1; /**< Key Lookup data size 0= 5 1 is 9 bytes */
} mlme_key_id_lookup_descriptor_t; } mlme_key_id_lookup_descriptor_t;
@ -160,7 +160,7 @@ typedef struct mlme_key_descriptor_entry_s {
mlme_key_usage_descriptor_t *KeyUsageList; /**< List of descriptor entries indicating which frame types this key may be used with*/ mlme_key_usage_descriptor_t *KeyUsageList; /**< List of descriptor entries indicating which frame types this key may be used with*/
uint8_t KeyUsageListEntries; /**< Number of entries in KeyUsageList*/ uint8_t KeyUsageListEntries; /**< Number of entries in KeyUsageList*/
uint8_t Key[16]; /**< Actual value of Security key*/ uint8_t Key[16]; /**< Actual value of Security key*/
}mlme_key_descriptor_entry_t; } mlme_key_descriptor_entry_t;
/** /**
* @brief MLME primitive error statuses * @brief MLME primitive error statuses
@ -275,20 +275,20 @@ typedef enum {
* *
* See IEEE standard 802.15.4-2006 (figure 51) for more details * See IEEE standard 802.15.4-2006 (figure 51) for more details
*/ */
typedef struct mlme_beacon_pending_address_spec_s{ typedef struct mlme_beacon_pending_address_spec_s {
unsigned short_address_count:3; /**< Number of short address count */ unsigned short_address_count: 3; /**< Number of short address count */
unsigned extended_address_count:3; /**< Number of extended address count */ unsigned extended_address_count: 3; /**< Number of extended address count */
}mlme_beacon_pending_address_spec_t; } mlme_beacon_pending_address_spec_t;
/** /**
* @brief struct mlme_beacon_gts_spec_t Format of GTS specification field * @brief struct mlme_beacon_gts_spec_t Format of GTS specification field
* *
* See IEEE standard 802.15.4-2006 (figure 48) for more details * See IEEE standard 802.15.4-2006 (figure 48) for more details
*/ */
typedef struct mlme_beacon_gts_spec_s{ typedef struct mlme_beacon_gts_spec_s {
unsigned description_count:3; /**< Number of GTS description count */ unsigned description_count: 3; /**< Number of GTS description count */
unsigned gts_permit:1; /**< 1= GTS request accepted 0= not accepted */ unsigned gts_permit: 1; /**< 1= GTS request accepted 0= not accepted */
}mlme_beacon_gts_spec_t; } mlme_beacon_gts_spec_t;
/** /**
* @brief struct mlme_beacon_ind_t Beacon notify structure * @brief struct mlme_beacon_ind_t Beacon notify structure
@ -311,7 +311,7 @@ typedef struct mlme_beacon_ind_s {
*/ */
typedef struct mlme_scan_s { typedef struct mlme_scan_s {
mac_scan_type_t ScanType; /**< ED=0, active=1, passive=2, orphan=3*/ mac_scan_type_t ScanType; /**< ED=0, active=1, passive=2, orphan=3*/
channel_list_s ScanChannels; /**<bit field, low 27 bits used*/ channel_list_s ScanChannels; /**<bit field, low 27 bits used*/
uint8_t ScanDuration; /**<0-14, scan duration/channel*/ uint8_t ScanDuration; /**<0-14, scan duration/channel*/
uint8_t ChannelPage; /**<0-31*/ uint8_t ChannelPage; /**<0-31*/
mlme_security_t Key; /**< Security parameters for active scan process */ mlme_security_t Key; /**< Security parameters for active scan process */
@ -373,7 +373,7 @@ typedef struct mlme_set_conf_s {
*/ */
typedef struct mlme_scan_conf_s { typedef struct mlme_scan_conf_s {
uint8_t status; /**< status of operation*/ uint8_t status; /**< status of operation*/
unsigned ScanType:2; /**< Finished Scan type*/ unsigned ScanType: 2; /**< Finished Scan type*/
uint8_t ChannelPage; /**< Operated Channel Page*/ uint8_t ChannelPage; /**< Operated Channel Page*/
channel_list_s UnscannedChannels; /**< Channel mask for unscanned channels*/ channel_list_s UnscannedChannels; /**< Channel mask for unscanned channels*/
uint8_t ResultListSize; /**< Result list size*/ uint8_t ResultListSize; /**< Result list size*/
@ -426,9 +426,9 @@ typedef struct mlme_rx_enable_conf_s {
*/ */
typedef struct mlme_comm_status_s { typedef struct mlme_comm_status_s {
uint16_t PANId; /**< Messages Pan-id */ uint16_t PANId; /**< Messages Pan-id */
unsigned SrcAddrMode:2; /**< source address mode: MAC_ADDR_MODE_NONE,MAC_ADDR_MODE_16_BIT or MAC_ADDR_MODE_64_BIT */ unsigned SrcAddrMode: 2; /**< source address mode: MAC_ADDR_MODE_NONE,MAC_ADDR_MODE_16_BIT or MAC_ADDR_MODE_64_BIT */
uint8_t SrcAddr[8]; /**< source address when mode is: MAC_ADDR_MODE_16_BIT or MAC_ADDR_MODE_64_BIT */ uint8_t SrcAddr[8]; /**< source address when mode is: MAC_ADDR_MODE_16_BIT or MAC_ADDR_MODE_64_BIT */
unsigned DstAddrMode:2; /**< destination address mode: MAC_ADDR_MODE_NONE,MAC_ADDR_MODE_16_BIT or MAC_ADDR_MODE_64_BIT */ unsigned DstAddrMode: 2; /**< destination address mode: MAC_ADDR_MODE_NONE,MAC_ADDR_MODE_16_BIT or MAC_ADDR_MODE_64_BIT */
uint8_t DstAddr[8]; /**< Destination address when mode is: MAC_ADDR_MODE_16_BIT or MAC_ADDR_MODE_64_BIT */ uint8_t DstAddr[8]; /**< Destination address when mode is: MAC_ADDR_MODE_16_BIT or MAC_ADDR_MODE_64_BIT */
uint8_t status; /**< Communication status */ uint8_t status; /**< Communication status */
mlme_security_t Key; /**< Messages Security parameters */ mlme_security_t Key; /**< Messages Security parameters */
@ -444,11 +444,11 @@ typedef struct mlme_start_s {
uint8_t LogicalChannel; /**< Operated Logical channel */ uint8_t LogicalChannel; /**< Operated Logical channel */
uint8_t ChannelPage; /**< Operated Logical channel page */ uint8_t ChannelPage; /**< Operated Logical channel page */
uint32_t StartTime; /**< Start time, set 0 */ uint32_t StartTime; /**< Start time, set 0 */
unsigned BeaconOrder:4; /**< Beacon order, set 15 */ unsigned BeaconOrder: 4; /**< Beacon order, set 15 */
unsigned SuperframeOrder:4; /**< Super frame order, set 15 */ unsigned SuperframeOrder: 4; /**< Super frame order, set 15 */
bool PANCoordinator:1; /**< true= Enable beacon response for beacon request, false = disable beacon request responses */ bool PANCoordinator: 1; /**< true= Enable beacon response for beacon request, false = disable beacon request responses */
bool BatteryLifeExtension:1; /**< Set false */ bool BatteryLifeExtension: 1; /**< Set false */
bool CoordRealignment:1; /**< Set false */ bool CoordRealignment: 1; /**< Set false */
mlme_security_t CoordRealignKey; /**< Coordinator Realignment security parameter's (Valid only CoordRealignment = true)*/ mlme_security_t CoordRealignKey; /**< Coordinator Realignment security parameter's (Valid only CoordRealignment = true)*/
mlme_security_t BeaconRealignKey; /**< Beacon realign security parameter's (Valid only CoordRealignment = true)*/ mlme_security_t BeaconRealignKey; /**< Beacon realign security parameter's (Valid only CoordRealignment = true)*/
} mlme_start_t; } mlme_start_t;
@ -483,7 +483,7 @@ typedef struct mlme_sync_loss_s {
* See IEEE standard 802.15.4-2006 (table 76) for more details * See IEEE standard 802.15.4-2006 (table 76) for more details
*/ */
typedef struct mlme_poll_s { typedef struct mlme_poll_s {
unsigned CoordAddrMode:2; /**< coordinator address mode:MAC_ADDR_MODE_16_BIT or MAC_ADDR_MODE_64_BIT */ unsigned CoordAddrMode: 2; /**< coordinator address mode:MAC_ADDR_MODE_16_BIT or MAC_ADDR_MODE_64_BIT */
uint16_t CoordPANId; /**< coordinator Pan-id to coordinator*/ uint16_t CoordPANId; /**< coordinator Pan-id to coordinator*/
uint8_t CoordAddress[8]; /**< coordinator address */ uint8_t CoordAddress[8]; /**< coordinator address */
mlme_security_t Key; /**< Security parameters for Poll request */ mlme_security_t Key; /**< Security parameters for Poll request */

View File

@ -225,20 +225,20 @@ int8_t multicast_mpl_domain_subscribe(int8_t interface_id,
* for more information on parameters. * for more information on parameters.
*/ */
int8_t multicast_mpl_domain_subscribe_with_parameters int8_t multicast_mpl_domain_subscribe_with_parameters
(int8_t interface_id, (int8_t interface_id,
const uint8_t address[16], const uint8_t address[16],
multicast_mpl_seed_id_mode_e seed_id_mode, multicast_mpl_seed_id_mode_e seed_id_mode,
const void *seed_id, const void *seed_id,
bool proactive_forwarding, bool proactive_forwarding,
uint16_t seed_set_entry_lifetime, uint16_t seed_set_entry_lifetime,
uint32_t data_message_imin, uint32_t data_message_imin,
uint32_t data_message_imax, uint32_t data_message_imax,
uint8_t data_message_k, uint8_t data_message_k,
uint8_t data_message_timer_expirations, uint8_t data_message_timer_expirations,
uint32_t control_message_imin, uint32_t control_message_imin,
uint32_t control_message_imax, uint32_t control_message_imax,
uint8_t control_message_k, uint8_t control_message_k,
uint8_t control_message_timer_expirations); uint8_t control_message_timer_expirations);
/** /**
* \brief Unsubscribe from an MPL Domain * \brief Unsubscribe from an MPL Domain

View File

@ -30,7 +30,7 @@ extern "C" {
* \section set-addr Setting short address * \section set-addr Setting short address
* - net_ext_set_short_address_from_app(), Sets up a user-specified short address and enables or disables DAD. * - net_ext_set_short_address_from_app(), Sets up a user-specified short address and enables or disables DAD.
* *
* NOTE: In case of duplication of address and DAD (duplicate address detection) enabled, i.e., DAD=1, the stack * NOTE: In case of duplication of address and DAD (duplicate address detection) enabled, i.e., DAD=1, the stack
* generates a short address dynamically. * generates a short address dynamically.
* *
* - \section reset-addr Resetting short address. * - \section reset-addr Resetting short address.

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); 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_configuration Basic FHSS configuration.
* @param fhss_timer FHSS platform timer interface and configuration. * @param fhss_timer FHSS platform timer interface and configuration.
* @param fhss_statistics FHSS statistics storage.
* @return New FHSS instance if successful, NULL otherwise. * @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); extern fhss_api_t *ns_fhss_ws_create(const fhss_ws_configuration_t *fhss_configuration, const fhss_timer_t *fhss_timer);

View File

@ -166,7 +166,7 @@ typedef enum {
NET_6LOWPAN_ND_WITHOUT_MLE, /**< **UNSUPPORTED** */ NET_6LOWPAN_ND_WITHOUT_MLE, /**< **UNSUPPORTED** */
NET_6LOWPAN_ND_WITH_MLE, /**< 6LoWPAN ND with MLE. */ NET_6LOWPAN_ND_WITH_MLE, /**< 6LoWPAN ND with MLE. */
NET_6LOWPAN_THREAD, /**< 6LoWPAN Thread with MLE attached. */ NET_6LOWPAN_THREAD, /**< 6LoWPAN Thread with MLE attached. */
NET_6LOWPAN_WS , /**< WS. */ NET_6LOWPAN_WS, /**< WS. */
NET_6LOWPAN_ZIGBEE_IP /**< **UNSUPPORTED** */ NET_6LOWPAN_ZIGBEE_IP /**< **UNSUPPORTED** */
} net_6lowpan_mode_extension_e; } net_6lowpan_mode_extension_e;
@ -257,8 +257,7 @@ typedef struct {
} border_router_setup_s; } border_router_setup_s;
/** Channel list */ /** Channel list */
typedef struct channel_list_s typedef struct channel_list_s {
{
channel_page_e channel_page; /**< Channel page */ channel_page_e channel_page; /**< Channel page */
uint32_t channel_mask[8]; /**< Channel mask. Each bit defining one channel */ uint32_t channel_mask[8]; /**< Channel mask. Each bit defining one channel */
} channel_list_s; } channel_list_s;

View File

@ -18,7 +18,7 @@
/** /**
* \file net_load_balance_api.h * \file net_load_balance_api.h
* \brief 6LoWPAN network load balance control API. * \brief 6LoWPAN network load balance control API.
*/ */
#ifndef NET_LOAD_BALANCE_API_H_ #ifndef NET_LOAD_BALANCE_API_H_
#define NET_LOAD_BALANCE_API_H_ #define NET_LOAD_BALANCE_API_H_
@ -87,7 +87,7 @@ int8_t net_load_balance_threshold_set(int8_t interface_id, uint8_t threshold_min
* *
* \return 0 Process OK, -1 Unknown interface ID or parameter fail. * \return 0 Process OK, -1 Unknown interface ID or parameter fail.
*/ */
int8_t net_load_balance_set_max_probability(int8_t interface_id , uint8_t max_p); int8_t net_load_balance_set_max_probability(int8_t interface_id, uint8_t max_p);
/** /**
* \brief Set load balance expected device count and enable automatic network load level update. * \brief Set load balance expected device count and enable automatic network load level update.

View File

@ -211,7 +211,7 @@ extern int8_t pana_server_nvm_client_session_load(uint8_t *nvm_pointer);
* \return -1, Null parameter detect. * \return -1, Null parameter detect.
* *
*/ */
extern int8_t pana_client_nvm_callback_set(pana_client_session_update_cb *nvm_update, pana_client_session_get_cb *nvm_get,uint8_t *nvm_static_buffer); extern int8_t pana_client_nvm_callback_set(pana_client_session_update_cb *nvm_update, pana_client_session_get_cb *nvm_get, uint8_t *nvm_static_buffer);
/** /**
* \brief Clean node persistent data and all PANA client sessions from the stack. * \brief Clean node persistent data and all PANA client sessions from the stack.

View File

@ -438,7 +438,7 @@ typedef int (response_cb)(int8_t interface_id, uint8_t *response_ptr, uint16_t r
* \return 0, Command send OK * \return 0, Command send OK
* \return <0 Command send Fail * \return <0 Command send Fail
*/ */
int thread_test_diagnostic_command_send(int8_t interface_id, uint8_t *address_ptr,const char *uri_ptr, uint8_t request_length, uint8_t *request_ptr, response_cb *resp_cb); int thread_test_diagnostic_command_send(int8_t interface_id, uint8_t *address_ptr, const char *uri_ptr, uint8_t request_length, uint8_t *request_ptr, response_cb *resp_cb);
typedef int (coap_response_cb)(int8_t interface_id, uint8_t message_code, uint8_t message_type, uint8_t *response_ptr, uint16_t response_len); typedef int (coap_response_cb)(int8_t interface_id, uint8_t message_code, uint8_t message_type, uint8_t *response_ptr, uint16_t response_len);

View File

@ -39,8 +39,7 @@ typedef struct ns_mdns_service *ns_mdns_service_t; /**< Service instance */
* \struct ns_mdns_service_param_t * \struct ns_mdns_service_param_t
* \brief Structure for mDNS service parameters * \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 */ const char *service_type; /**< Null-terminated string owned by the caller */
uint16_t service_port; /**< Service Port number */ 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). 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 * \brief SHA-256 context structure
*/ */
typedef struct typedef struct {
{
uint32_t total[2]; /*!< number of bytes processed */ uint32_t total[2]; /*!< number of bytes processed */
uint32_t state[8]; /*!< intermediate digest state */ uint32_t state[8]; /*!< intermediate digest state */
unsigned char buffer[64]; /*!< data block being processed */ unsigned char buffer[64]; /*!< data block being processed */
@ -125,14 +124,14 @@ ns_sha256_context;
* *
* \param ctx SHA-256 context to be initialized * \param ctx SHA-256 context to be initialized
*/ */
void ns_sha256_init( ns_sha256_context *ctx ); void ns_sha256_init(ns_sha256_context *ctx);
/** /**
* \brief Clear SHA-256 context * \brief Clear SHA-256 context
* *
* \param ctx SHA-256 context to be cleared * \param ctx SHA-256 context to be cleared
*/ */
void ns_sha256_free( ns_sha256_context *ctx ); void ns_sha256_free(ns_sha256_context *ctx);
/** /**
* \brief Clone (the state of) a SHA-256 context * \brief Clone (the state of) a SHA-256 context
@ -140,15 +139,15 @@ void ns_sha256_free( ns_sha256_context *ctx );
* \param dst The destination context * \param dst The destination context
* \param src The context to be cloned * \param src The context to be cloned
*/ */
void ns_sha256_clone( ns_sha256_context *dst, void ns_sha256_clone(ns_sha256_context *dst,
const ns_sha256_context *src ); const ns_sha256_context *src);
/** /**
* \brief SHA-256 context setup * \brief SHA-256 context setup
* *
* \param ctx context to be initialized * \param ctx context to be initialized
*/ */
void ns_sha256_starts( ns_sha256_context *ctx ); void ns_sha256_starts(ns_sha256_context *ctx);
/** /**
* \brief SHA-256 process buffer * \brief SHA-256 process buffer
@ -157,8 +156,8 @@ void ns_sha256_starts( ns_sha256_context *ctx );
* \param input buffer holding the data * \param input buffer holding the data
* \param ilen length of the input data * \param ilen length of the input data
*/ */
void ns_sha256_update( ns_sha256_context *ctx, const void *input, void ns_sha256_update(ns_sha256_context *ctx, const void *input,
size_t ilen ); size_t ilen);
/** /**
* \brief SHA-256 final digest * \brief SHA-256 final digest
@ -166,7 +165,7 @@ void ns_sha256_update( ns_sha256_context *ctx, const void *input,
* \param ctx SHA-256 context * \param ctx SHA-256 context
* \param output SHA-256 checksum result * \param output SHA-256 checksum result
*/ */
void ns_sha256_finish( ns_sha256_context *ctx, void *output ); void ns_sha256_finish(ns_sha256_context *ctx, void *output);
/** /**
* \brief SHA-256 final digest * \brief SHA-256 final digest
@ -175,8 +174,8 @@ void ns_sha256_finish( ns_sha256_context *ctx, void *output );
* \param output SHA-256 checksum result * \param output SHA-256 checksum result
* \param obits Number of bits of to output - must be multiple of 32 * \param obits Number of bits of to output - must be multiple of 32
*/ */
void ns_sha256_finish_nbits( ns_sha256_context *ctx, void ns_sha256_finish_nbits(ns_sha256_context *ctx,
void *output, unsigned obits ); void *output, unsigned obits);
/** /**
* \brief Output = SHA-256( input buffer ) * \brief Output = SHA-256( input buffer )
@ -185,8 +184,8 @@ void ns_sha256_finish_nbits( ns_sha256_context *ctx,
* \param ilen length of the input data * \param ilen length of the input data
* \param output SHA-256 checksum result * \param output SHA-256 checksum result
*/ */
void ns_sha256( const void *input, size_t ilen, void ns_sha256(const void *input, size_t ilen,
void *output ); void *output);
/** /**
* \brief Output = SHA-256( input buffer ) * \brief Output = SHA-256( input buffer )
@ -196,8 +195,8 @@ void ns_sha256( const void *input, size_t ilen,
* \param output SHA-256 checksum result * \param output SHA-256 checksum result
* \param obits Number of bits of to output - must be multiple of 32 * \param obits Number of bits of to output - must be multiple of 32
*/ */
void ns_sha256_nbits( const void *input, size_t ilen, void ns_sha256_nbits(const void *input, size_t ilen,
void *output, unsigned obits ); void *output, unsigned obits);
#endif /* NS_USE_EXTERNAL_MBED_TLS */ #endif /* NS_USE_EXTERNAL_MBED_TLS */

View File

@ -125,8 +125,7 @@ typedef struct phy_csma_params {
} phy_csma_params_t; } phy_csma_params_t;
/** PHY modulation scheme */ /** PHY modulation scheme */
typedef enum phy_modulation_e typedef enum phy_modulation_e {
{
M_OFDM, ///< QFDM M_OFDM, ///< QFDM
M_OQPSK, ///< OQPSK M_OQPSK, ///< OQPSK
M_BPSK, ///< BPSK M_BPSK, ///< BPSK
@ -135,8 +134,7 @@ typedef enum phy_modulation_e
} phy_modulation_e; } phy_modulation_e;
/** Channel page numbers */ /** Channel page numbers */
typedef enum typedef enum {
{
CHANNEL_PAGE_0 = 0, ///< Page 0 CHANNEL_PAGE_0 = 0, ///< Page 0
CHANNEL_PAGE_1 = 1, ///< Page 1 CHANNEL_PAGE_1 = 1, ///< Page 1
CHANNEL_PAGE_2 = 2, ///< Page 2 CHANNEL_PAGE_2 = 2, ///< Page 2
@ -149,8 +147,7 @@ typedef enum
} channel_page_e; } channel_page_e;
/** Channel configuration */ /** 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_0_center_frequency; ///< Center frequency
uint32_t channel_spacing; ///< Channel spacing uint32_t channel_spacing; ///< Channel spacing
uint32_t datarate; ///< Data rate uint32_t datarate; ///< Data rate
@ -159,8 +156,7 @@ typedef struct phy_rf_channel_configuration_s
} phy_rf_channel_configuration_s; } phy_rf_channel_configuration_s;
/** Channel page configuration */ /** Channel page configuration */
typedef struct phy_device_channel_page_s typedef struct phy_device_channel_page_s {
{
channel_page_e channel_page; ///< Channel page channel_page_e channel_page; ///< Channel page
const phy_rf_channel_configuration_s *rf_channel_configuration; ///< Pointer to channel configuration const phy_rf_channel_configuration_s *rf_channel_configuration; ///< Pointer to channel configuration
} phy_device_channel_page_s; } phy_device_channel_page_s;
@ -202,7 +198,7 @@ typedef int8_t arm_net_phy_tx_done_fn(int8_t driver_id, uint8_t tx_handle, phy_l
* @param driver_id ID of driver which received data * @param driver_id ID of driver which received data
* @return 0 if success, error otherwise * @return 0 if success, error otherwise
*/ */
typedef int8_t arm_net_virtual_rx_fn(const uint8_t *data_ptr, uint16_t data_len,int8_t driver_id); typedef int8_t arm_net_virtual_rx_fn(const uint8_t *data_ptr, uint16_t data_len, int8_t driver_id);
/** /**
* @brief arm_net_virtual_tx TX callback set by serial MAC. Used to send data. * @brief arm_net_virtual_tx TX callback set by serial MAC. Used to send data.
@ -210,7 +206,7 @@ typedef int8_t arm_net_virtual_rx_fn(const uint8_t *data_ptr, uint16_t data_len,
* @param driver_id Id of the driver to be used. * @param driver_id Id of the driver to be used.
* @return 0 if success, error otherwise * @return 0 if success, error otherwise
*/ */
typedef int8_t arm_net_virtual_tx_fn(const virtual_data_req_t *data_req,int8_t driver_id); typedef int8_t arm_net_virtual_tx_fn(const virtual_data_req_t *data_req, int8_t driver_id);
/** /**
* @brief arm_net_virtual_config Configuration receive callback set by upper layer. Used to receive internal configuration parameters. * @brief arm_net_virtual_config Configuration receive callback set by upper layer. Used to receive internal configuration parameters.
@ -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); typedef int8_t arm_net_virtual_confirmation_rx_fn(int8_t driver_id, const uint8_t *data, uint16_t length);
/** Device driver structure */ /** Device driver structure */
typedef struct phy_device_driver_s typedef struct phy_device_driver_s {
{
phy_link_type_e link_type; /**< Define driver types. */ phy_link_type_e link_type; /**< Define driver types. */
driver_data_request_e data_request_layer; /**< Define interface data OUT protocol. */ 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. */ uint8_t *PHY_MAC; /**< Pointer to 64-bit or 48-bit MAC address. */
@ -251,7 +246,7 @@ typedef struct phy_device_driver_s
uint8_t phy_header_length; /**< Define PHY driver needed header length before PDU. */ uint8_t phy_header_length; /**< Define PHY driver needed header length before PDU. */
int8_t (*state_control)(phy_interface_state_e, uint8_t); /**< Function pointer for control PHY driver state. */ int8_t (*state_control)(phy_interface_state_e, uint8_t); /**< Function pointer for control PHY driver state. */
int8_t (*tx)(uint8_t *, uint16_t, uint8_t, data_protocol_e); /**< Function pointer for PHY driver write operation. */ int8_t (*tx)(uint8_t *, uint16_t, uint8_t, data_protocol_e); /**< Function pointer for PHY driver write operation. */
int8_t (*address_write)(phy_address_type_e , uint8_t *); /**< Function pointer for PHY driver address write. */ int8_t (*address_write)(phy_address_type_e, uint8_t *); /**< Function pointer for PHY driver address write. */
int8_t (*extension)(phy_extension_type_e, uint8_t *); /**< Function pointer for PHY driver extension control. */ int8_t (*extension)(phy_extension_type_e, uint8_t *); /**< Function pointer for PHY driver extension control. */
const phy_device_channel_page_s *phy_channel_pages; /**< Pointer to channel page list */ const phy_device_channel_page_s *phy_channel_pages; /**< Pointer to channel page list */

View File

@ -46,7 +46,7 @@ extern serial_mac_api_t *serial_mac_create(int8_t serial_driver_id);
* @param data Data to be sent * @param data Data to be sent
* @param data_length Length of the data * @param data_length Length of the data
*/ */
typedef int8_t data_request(const serial_mac_api_t* api, const uint8_t *data_ptr, uint16_t data_length); typedef int8_t data_request(const serial_mac_api_t *api, const uint8_t *data_ptr, uint16_t data_length);
/** /**
@ -78,7 +78,7 @@ typedef int8_t serial_mac_virtual_initialize(const serial_mac_api_t *api, int8_t
*/ */
struct serial_mac_api_s { struct serial_mac_api_s {
serial_mac_api_initialize *mac_initialize; /**< Inititilize data callback */ serial_mac_api_initialize *mac_initialize; /**< Inititilize data callback */
serial_mac_virtual_initialize * virtual_initilize; /**< Enable bridge to virtual driver */ serial_mac_virtual_initialize *virtual_initilize; /**< Enable bridge to virtual driver */
data_request *data_request_cb; /**< Data request callback */ data_request *data_request_cb; /**< Data request callback */
data_indication *data_ind_cb; /**< Data indication callback */ data_indication *data_ind_cb; /**< Data indication callback */
}; };

View File

@ -672,7 +672,7 @@ static inline int8_t socket_read_session_address(int8_t socket, ns_address_t *ad
/** \name Protocol levels used for socket_setsockopt. */ /** \name Protocol levels used for socket_setsockopt. */
///@{ ///@{
#define SOCKET_SOL_SOCKET 0 /**< Socket level */ #define SOCKET_SOL_SOCKET 0 /**< Socket level */
#define SOCKET_IPPROTO_IPV6 41 /**< IPv6. */ #define SOCKET_IPPROTO_IPV6 41 /**< IPv6. */
///@} ///@}
/** \name Option names for protocol level SOCKET_SOL_SOCKET. /** \name Option names for protocol level SOCKET_SOL_SOCKET.

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); 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. * 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); 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. * Set the Thread validation interface destination address.
* *

View File

@ -221,7 +221,7 @@ typedef void (thread_network_data_tlv_cb)(int8_t interface_id, uint8_t *network_
* \return 0, Callback function registered successfully. * \return 0, Callback function registered successfully.
* \return <0 when error occurs during registering the callback function. * \return <0 when error occurs during registering the callback function.
*/ */
int thread_border_router_network_data_callback_register(int8_t interface_id, thread_network_data_tlv_cb* nwk_data_cb); int thread_border_router_network_data_callback_register(int8_t interface_id, thread_network_data_tlv_cb *nwk_data_cb);
/** /**
* Find Prefix TLV from the Network Data TLV byte array. * Find Prefix TLV from the Network Data TLV byte array.
@ -236,7 +236,7 @@ int thread_border_router_network_data_callback_register(int8_t interface_id, thr
* \return 0 if TLV is empty or no Prefix TLV found. * \return 0 if TLV is empty or no Prefix TLV found.
* \return negative value indicates error in input parameters. * \return negative value indicates error in input parameters.
*/ */
int thread_border_router_prefix_tlv_find(uint8_t* network_data_tlv, uint16_t network_data_tlv_length, uint8_t** prefix_tlv, bool* stable); int thread_border_router_prefix_tlv_find(uint8_t *network_data_tlv, uint16_t network_data_tlv_length, uint8_t **prefix_tlv, bool *stable);
/** /**
* Find Border router TLV from the Network Data TLV (under Prefix TLV) byte array. * Find Border router TLV from the Network Data TLV (under Prefix TLV) byte array.
@ -251,7 +251,7 @@ int thread_border_router_prefix_tlv_find(uint8_t* network_data_tlv, uint16_t net
* \return 0 if TLV is empty or no TLV found. * \return 0 if TLV is empty or no TLV found.
* \return negative value indicates error in input parameters. * \return negative value indicates error in input parameters.
*/ */
int thread_border_router_tlv_find(uint8_t* prefix_tlv, uint16_t prefix_tlv_length, uint8_t** border_router_tlv, bool* stable); int thread_border_router_tlv_find(uint8_t *prefix_tlv, uint16_t prefix_tlv_length, uint8_t **border_router_tlv, bool *stable);
/** /**
* Find Service TLV from the Network Data TLV byte array. * Find Service TLV from the Network Data TLV byte array.
@ -266,7 +266,7 @@ int thread_border_router_tlv_find(uint8_t* prefix_tlv, uint16_t prefix_tlv_lengt
* \return 0 if TLV is empty or no Service TLV found. * \return 0 if TLV is empty or no Service TLV found.
* \return negative value indicates error in input parameters. * \return negative value indicates error in input parameters.
*/ */
int thread_border_router_service_tlv_find(uint8_t* network_data_tlv, uint16_t network_data_tlv_length, uint8_t** service_tlv, bool* stable); int thread_border_router_service_tlv_find(uint8_t *network_data_tlv, uint16_t network_data_tlv_length, uint8_t **service_tlv, bool *stable);
/** /**
* Find Server TLV from the Network Data TLV (under Service TLV) byte array. * Find Server TLV from the Network Data TLV (under Service TLV) byte array.
@ -281,7 +281,7 @@ int thread_border_router_service_tlv_find(uint8_t* network_data_tlv, uint16_t ne
* \return 0 if TLV is empty or no TLV found. * \return 0 if TLV is empty or no TLV found.
* \return negative value indicates error in input parameters. * \return negative value indicates error in input parameters.
*/ */
int thread_border_router_server_tlv_find(uint8_t* service_tlv, uint16_t service_tlv_length, uint8_t** server_tlv, bool* stable); int thread_border_router_server_tlv_find(uint8_t *service_tlv, uint16_t service_tlv_length, uint8_t **server_tlv, bool *stable);
/** /**
* Determine context ID from the Network Data TLV (under Prefix TLV) byte array. * Determine context ID from the Network Data TLV (under Prefix TLV) byte array.

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 { 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 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. */ uint8_t extented_pan_id[8]; /**< Extended PAN ID. */
uint16_t panId; /**< Network ID. */ uint16_t panId; /**< Network ID. */
uint16_t destination_port; /**<destination port for commissioning*/
uint8_t Protocol_id; /**< Current protocol ID. */ uint8_t Protocol_id; /**< Current protocol ID. */
uint8_t version; /**< Current protocol version. */ uint8_t version; /**< Current protocol version. */
uint8_t rfChannel; /**< Current RF channel. */ uint8_t rfChannel; /**< Current RF channel. */
@ -206,7 +208,7 @@ typedef struct thread_commissioning_link_configuration {
* \param link_ptr Poiner to Commissioning link configuration * \param link_ptr Poiner to Commissioning link configuration
* *
*/ */
typedef void thread_commissioning_native_select_cb(int8_t interface_id, uint8_t count, thread_commissioning_link_configuration_s *link_ptr ); typedef void thread_commissioning_native_select_cb(int8_t interface_id, uint8_t count, thread_commissioning_link_configuration_s *link_ptr);
/** \brief Native commissioner network scan start. /** \brief Native commissioner network scan start.
* *
@ -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); 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 #ifdef __cplusplus
} }
#endif #endif

View File

@ -55,7 +55,8 @@
#define DIAGCOP_TLV_SUPPLY_VOLTAGE 15 /**< Can not reset*/ #define DIAGCOP_TLV_SUPPLY_VOLTAGE 15 /**< Can not reset*/
#define DIAGCOP_TLV_CHILD_TABLE 16 /**< Can not reset*/ #define DIAGCOP_TLV_CHILD_TABLE 16 /**< Can not reset*/
#define DIAGCOP_TLV_CHANNEL_PAGES 17 /**< 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. * \brief Write array TLV.

View File

@ -95,18 +95,18 @@ int thread_management_unregister(int8_t instance_id);
*/ */
typedef int (management_set_response_cb)(int8_t interface_id, management_state_e status); typedef int (management_set_response_cb)(int8_t interface_id, management_state_e status);
/** \brief Set the Thread security policy /** \brief Set the Thread security policy
* *
* \param instance_id The ID of the management session. * \param instance_id The ID of the management session.
* \param options Security policy options: * \param options Security policy options:
* bit 8 Out-of-band commissioning restricted. * bit 8 Out-of-band commissioning restricted.
* bit 7 Native commissioner restricted. * bit 7 Native commissioner restricted.
* \param rotation_time Thread key rotation time in hours. * \param rotation_time Thread key rotation time in hours.
* \param cb_ptr A callback function indicating the result of the operation. Can be NULL if no result code needed. * \param cb_ptr A callback function indicating the result of the operation. Can be NULL if no result code needed.
* *
* \return 0 Success. * \return 0 Success.
* \return <0 Fail. * \return <0 Fail.
*/ */
int thread_management_set_security_policy(int8_t instance_id, uint8_t options, uint16_t rotation_time, management_set_response_cb *cb_ptr); int thread_management_set_security_policy(int8_t instance_id, uint8_t options, uint16_t rotation_time, management_set_response_cb *cb_ptr);
/** \brief Set the steering data /** \brief Set the steering data
@ -179,7 +179,7 @@ int thread_management_get(int8_t instance_id, uint8_t dst_addr[static 16], char
* \param instance_id Instance ID of the management session. * \param instance_id Instance ID of the management session.
* \param dst_addr Destination address, the address of a remote device where it is desired to setup management information. If however, the address is not provided, a request is sent to leader of the network for this purpose. If a native commissioner is being used, the rquest for setting up management information is sent to the Border router. * \param dst_addr Destination address, the address of a remote device where it is desired to setup management information. If however, the address is not provided, a request is sent to leader of the network for this purpose. If a native commissioner is being used, the rquest for setting up management information is sent to the Border router.
* \param uri_ptr The ASCII string for the URI. This string identifies the CoAP URI for the desired resource, for example, /c/ms identifies the the management set information resource. * \param uri_ptr The ASCII string for the URI. This string identifies the CoAP URI for the desired resource, for example, /c/ms identifies the the management set information resource.
* \param data_ptr A pointer to the desired set of TLVs. * \param data_ptr A pointer to the desired set of TLVs.
* \param data_len count of the members (no. of TLVs) in the TLV set. * \param data_len count of the members (no. of TLVs) in the TLV set.
* \param cb_ptr A callback function carrying the result of the operation. * \param cb_ptr A callback function carrying the result of the operation.
* *

View File

@ -303,7 +303,7 @@ bool thread_meshcop_tlv_list_present(const uint8_t *ptr, uint16_t length, const
* *
* \return amount of TLVs present in the buffer. * \return amount of TLVs present in the buffer.
*/ */
uint16_t thread_meshcop_tlv_list_generate(const uint8_t *ptr, uint16_t length,uint8_t *result_ptr, uint16_t *result_len); uint16_t thread_meshcop_tlv_list_generate(const uint8_t *ptr, uint16_t length, uint8_t *result_ptr, uint16_t *result_len);
/** /**
* Remove TLV from list of TLVs. * Remove TLV from list of TLVs.
@ -338,7 +338,7 @@ bool thread_meshcop_tlv_list_type_available(const uint8_t *list_ptr, uint16_t li
* *
* \return The length of the TLV data found and found_tlv updated to point beginning of value field. 0 if TLV is not found. * \return The length of the TLV data found and found_tlv updated to point beginning of value field. 0 if TLV is not found.
*/ */
uint16_t thread_meshcop_tlv_find_next(uint8_t* tlv_ba, uint16_t tlv_ba_length, uint8_t tlv_id, uint8_t** found_tlv); uint16_t thread_meshcop_tlv_find_next(uint8_t *tlv_ba, uint16_t tlv_ba_length, uint8_t tlv_id, uint8_t **found_tlv);
/** /**
* Read 1 byte length TLV. * Read 1 byte length 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) { 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. // non-secure okay if it's for a socket whose security flag is clear.
} } else {
else {
drop_unsecured = 1; drop_unsecured = 1;
} }
} }

View File

@ -74,6 +74,7 @@
#include "6LoWPAN/Fragmentation/cipv6_fragmenter.h" #include "6LoWPAN/Fragmentation/cipv6_fragmenter.h"
#include "Service_Libs/etx/etx.h" #include "Service_Libs/etx/etx.h"
#include "Service_Libs/mac_neighbor_table/mac_neighbor_table.h" #include "Service_Libs/mac_neighbor_table/mac_neighbor_table.h"
#include "6LoWPAN/ws/ws_bootstrap.h"
#define TRACE_GROUP_LOWPAN "6lo" #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->dup_addr_detect_transmits = 0;
cur->ipv6_neighbour_cache.max_ll_len = 2 + 8; cur->ipv6_neighbour_cache.max_ll_len = 2 + 8;
cur->ipv6_neighbour_cache.link_mtu = LOWPAN_MTU; cur->ipv6_neighbour_cache.link_mtu = LOWPAN_MTU;
@ -462,7 +464,7 @@ void protocol_6lowpan_neighbor_priority_update(protocol_interface_info_entry_t *
if (cur->lowpan_info & INTERFACE_NWK_BOOTSRAP_MLE) { if (cur->lowpan_info & INTERFACE_NWK_BOOTSRAP_MLE) {
#ifndef NO_MLE #ifndef NO_MLE
if (removed_priority) { if (removed_priority) {
mle_set_link_priority(cur,removed_priority, false); mle_set_link_priority(cur, removed_priority, false);
} }
if (updated_priority) { if (updated_priority) {
@ -473,7 +475,6 @@ void protocol_6lowpan_neighbor_priority_update(protocol_interface_info_entry_t *
} }
#ifdef HAVE_RPL #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) uint16_t protocol_6lowpan_neighbor_priority_set(int8_t interface_id, addrtype_t addr_type, const uint8_t *addr_ptr)
{ {
@ -483,12 +484,15 @@ uint16_t protocol_6lowpan_neighbor_priority_set(int8_t interface_id, addrtype_t
return 0; return 0;
} }
mac_neighbor_table_entry_t * entry = mac_neighbor_table_address_discover(mac_neighbor_info(cur), addr_ptr + PAN_ID_LEN, addr_type); mac_neighbor_table_entry_t *entry = mac_neighbor_table_address_discover(mac_neighbor_info(cur), addr_ptr + PAN_ID_LEN, addr_type);
if (entry) { if (entry) {
bool new_primary = false;
etx_storage_t *etx_entry = etx_storage_entry_get(interface_id, entry->index); etx_storage_t *etx_entry = etx_storage_entry_get(interface_id, entry->index);
// If primary parent has changed clears priority from previous parent // If primary parent has changed clears priority from previous parent
if (entry->link_role != PRIORITY_PARENT_NEIGHBOUR) { if (entry->link_role != PRIORITY_PARENT_NEIGHBOUR) {
new_primary = true;
protocol_6lowpan_neighbor_priority_clear_all(interface_id, PRIORITY_1ST); protocol_6lowpan_neighbor_priority_clear_all(interface_id, PRIORITY_1ST);
} }
entry->link_role = PRIORITY_PARENT_NEIGHBOUR; 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) { if (etx_entry) {
protocol_stats_update(STATS_ETX_1ST_PARENT, etx_entry->etx >> 4); protocol_stats_update(STATS_ETX_1ST_PARENT, etx_entry->etx >> 4);
} }
if (new_primary) {
ws_primary_parent_update(cur, entry);
}
return 1; return 1;
} else { } else {
return 0; return 0;
@ -516,12 +524,14 @@ uint16_t protocol_6lowpan_neighbor_second_priority_set(int8_t interface_id, addr
return 0; return 0;
} }
mac_neighbor_table_entry_t * entry = mac_neighbor_table_address_discover(mac_neighbor_info(cur), addr_ptr + PAN_ID_LEN, addr_type); mac_neighbor_table_entry_t *entry = mac_neighbor_table_address_discover(mac_neighbor_info(cur), addr_ptr + PAN_ID_LEN, addr_type);
if (entry) { if (entry) {
bool new_secondary = false;
etx_storage_t *etx_entry = etx_storage_entry_get(interface_id, entry->index); etx_storage_t *etx_entry = etx_storage_entry_get(interface_id, entry->index);
// If secondary parent has changed clears priority from previous parent // If secondary parent has changed clears priority from previous parent
if (entry->link_role != SECONDARY_PARENT_NEIGHBOUR) { if (entry->link_role != SECONDARY_PARENT_NEIGHBOUR) {
new_secondary = true;
protocol_6lowpan_neighbor_priority_clear_all(interface_id, PRIORITY_2ND); protocol_6lowpan_neighbor_priority_clear_all(interface_id, PRIORITY_2ND);
} }
entry->link_role = SECONDARY_PARENT_NEIGHBOUR; 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) { if (etx_entry) {
protocol_stats_update(STATS_ETX_2ND_PARENT, etx_entry->etx >> 4); protocol_stats_update(STATS_ETX_2ND_PARENT, etx_entry->etx >> 4);
} }
if (new_secondary) {
ws_secondary_parent_update(cur);
}
return 1; return 1;
} else { } else {
return 0; return 0;
@ -557,7 +570,6 @@ void protocol_6lowpan_neighbor_priority_clear_all(int8_t interface_id, neighbor_
} }
} }
#endif
#endif #endif
#endif #endif
@ -566,7 +578,7 @@ int8_t protocol_6lowpan_neighbor_address_state_synch(protocol_interface_info_ent
{ {
int8_t ret_val = -1; int8_t ret_val = -1;
mac_neighbor_table_entry_t * entry = mac_neighbor_table_address_discover(mac_neighbor_info(cur), eui64, ADDR_802_15_4_LONG); mac_neighbor_table_entry_t *entry = mac_neighbor_table_address_discover(mac_neighbor_info(cur), eui64, ADDR_802_15_4_LONG);
if (entry) { if (entry) {
if (memcmp(iid, ADDR_SHORT_ADR_SUFFIC, 6) == 0) { if (memcmp(iid, ADDR_SHORT_ADR_SUFFIC, 6) == 0) {
iid += 6; iid += 6;
@ -587,7 +599,7 @@ int8_t protocol_6lowpan_neighbor_address_state_synch(protocol_interface_info_ent
int8_t protocol_6lowpan_neighbor_remove(protocol_interface_info_entry_t *cur, uint8_t *address_ptr, addrtype_t type) int8_t protocol_6lowpan_neighbor_remove(protocol_interface_info_entry_t *cur, uint8_t *address_ptr, addrtype_t type)
{ {
mac_neighbor_table_entry_t * entry = mac_neighbor_table_address_discover(mac_neighbor_info(cur), address_ptr, type); mac_neighbor_table_entry_t *entry = mac_neighbor_table_address_discover(mac_neighbor_info(cur), address_ptr, type);
if (entry) { if (entry) {
mac_neighbor_table_neighbor_remove(mac_neighbor_info(cur), entry); mac_neighbor_table_neighbor_remove(mac_neighbor_info(cur), entry);
} }
@ -728,7 +740,7 @@ uint8_t protocol_6lowpan_beacon_join_priority_tx(int8_t interface_id)
int16_t priority = 0; int16_t priority = 0;
#ifdef HAVE_RPL #ifdef HAVE_RPL
if (cur->rpl_domain) { if (cur->rpl_domain) {
priority = protocol_6lowpan_rpl_global_priority_get(); priority = protocol_6lowpan_rpl_global_priority_get();
} }
#endif #endif

View File

@ -92,10 +92,10 @@ static void protocol_6lowpan_bootstrap_rpl_callback(rpl_event_t event, void *han
#endif #endif
static void protocol_6lowpan_mle_purge_neighbors(struct protocol_interface_info_entry *cur_interface, uint8_t entry_count, uint8_t force_priority); static void protocol_6lowpan_mle_purge_neighbors(struct protocol_interface_info_entry *cur_interface, uint8_t entry_count, uint8_t force_priority);
static uint8_t protocol_6lowpan_mle_order_last_entries(int8_t interface_id,mac_neighbor_table_list_t *mac_neigh_table, uint8_t entry_count); static uint8_t protocol_6lowpan_mle_order_last_entries(int8_t interface_id, mac_neighbor_table_list_t *mac_neigh_table, uint8_t entry_count);
static uint8_t protocol_6lowpan_mle_data_allocate(void); static uint8_t protocol_6lowpan_mle_data_allocate(void);
static bool mle_accept_request_cb(int8_t interface_id, uint16_t msgId, bool usedAllRetries); static bool mle_accept_request_cb(int8_t interface_id, uint16_t msgId, bool usedAllRetries);
static void lowpan_comm_status_indication_cb(int8_t if_id, const mlme_comm_status_t* status); static void lowpan_comm_status_indication_cb(int8_t if_id, const mlme_comm_status_t *status);
static void protocol_6lowpan_priority_neighbor_remove(protocol_interface_info_entry_t *cur_interface, mac_neighbor_table_entry_t *cur); static void protocol_6lowpan_priority_neighbor_remove(protocol_interface_info_entry_t *cur_interface, mac_neighbor_table_entry_t *cur);
static void lowpan_neighbor_entry_remove_notify(mac_neighbor_table_entry_t *entry_ptr, void *user_data); static void lowpan_neighbor_entry_remove_notify(mac_neighbor_table_entry_t *entry_ptr, void *user_data);
@ -119,7 +119,7 @@ static void lowpan_bootstrap_pan_control(protocol_interface_info_entry_t *cur, b
start_req.PANCoordinator = bootstrap_ready; start_req.PANCoordinator = bootstrap_ready;
start_req.LogicalChannel = cur->mac_parameters->mac_channel; start_req.LogicalChannel = cur->mac_parameters->mac_channel;
start_req.PANId = cur->mac_parameters->pan_id; start_req.PANId = cur->mac_parameters->pan_id;
cur->mac_api->mlme_req(cur->mac_api, MLME_START , &start_req); cur->mac_api->mlme_req(cur->mac_api, MLME_START, &start_req);
net_load_balance_internal_state_activate(cur, bootstrap_ready); net_load_balance_internal_state_activate(cur, bootstrap_ready);
} }
} }
@ -164,8 +164,8 @@ uint8_t *mle_general_write_timeout(uint8_t *ptr, protocol_interface_info_entry_t
static void protocol_6lowpan_priority_neighbor_remove(protocol_interface_info_entry_t *cur_interface, mac_neighbor_table_entry_t *cur) static void protocol_6lowpan_priority_neighbor_remove(protocol_interface_info_entry_t *cur_interface, mac_neighbor_table_entry_t *cur)
{ {
if (cur->link_role != PRIORITY_PARENT_NEIGHBOUR || if (cur->link_role != PRIORITY_PARENT_NEIGHBOUR ||
!(cur_interface->lowpan_info & INTERFACE_NWK_ACTIVE) || !(cur_interface->lowpan_info & INTERFACE_NWK_ACTIVE) ||
cur_interface->bootsrap_mode == ARM_NWK_BOOTSRAP_MODE_6LoWPAN_BORDER_ROUTER) { cur_interface->bootsrap_mode == ARM_NWK_BOOTSRAP_MODE_6LoWPAN_BORDER_ROUTER) {
return; return;
} }
@ -183,7 +183,7 @@ static void protocol_6lowpan_priority_neighbor_remove(protocol_interface_info_en
memcpy(mac64, ADDR_SHORT_ADR_SUFFIC, 6); memcpy(mac64, ADDR_SHORT_ADR_SUFFIC, 6);
common_write_16_bit(cur->mac16, &mac64[6]); common_write_16_bit(cur->mac16, &mac64[6]);
} else { } else {
memcpy(mac64,cur->mac64 , 8); memcpy(mac64, cur->mac64, 8);
mac64[0] ^= 2; mac64[0] ^= 2;
} }
@ -208,7 +208,7 @@ static bool protocol_6lowpan_challenge_callback(int8_t interface_id, uint16_t ms
memcpy(mac64, ll64_ptr + 8, 8); memcpy(mac64, ll64_ptr + 8, 8);
mac64[0] ^= 2; mac64[0] ^= 2;
mac_neighbor_table_entry_t * neig_info = mac_neighbor_table_address_discover(mac_neighbor_info(cur_interface), mac64, ADDR_802_15_4_LONG); mac_neighbor_table_entry_t *neig_info = mac_neighbor_table_address_discover(mac_neighbor_info(cur_interface), mac64, ADDR_802_15_4_LONG);
if (!neig_info) { if (!neig_info) {
return false;//Why entry is removed before timeout?? return false;//Why entry is removed before timeout??
@ -240,7 +240,7 @@ static bool protocol_6lowpan_host_challenge(protocol_interface_info_entry_t *cur
uint8_t security_level = mle_service_security_level_get(cur->id); uint8_t security_level = mle_service_security_level_get(cur->id);
tr_debug("Link REQUEST"); tr_debug("Link REQUEST");
bufId = mle_service_msg_allocate(cur->id, 32, true,MLE_COMMAND_REQUEST); bufId = mle_service_msg_allocate(cur->id, 32, true, MLE_COMMAND_REQUEST);
if (bufId == 0) { if (bufId == 0) {
return false; return false;
} }
@ -259,7 +259,7 @@ static bool protocol_6lowpan_host_challenge(protocol_interface_info_entry_t *cur
memcpy(ll64, ADDR_LINK_LOCAL_PREFIX, 8); memcpy(ll64, ADDR_LINK_LOCAL_PREFIX, 8);
memcpy(&ll64[8], mac64, 8); memcpy(&ll64[8], mac64, 8);
ll64[8] ^= 2; ll64[8] ^= 2;
if (mle_service_update_length_by_ptr(bufId,ptr)!= 0) { if (mle_service_update_length_by_ptr(bufId, ptr) != 0) {
tr_debug("Buffer overflow at message write"); tr_debug("Buffer overflow at message write");
} }
timeout.retrans_max = 3; timeout.retrans_max = 3;
@ -289,7 +289,7 @@ static bool protocol_6lowpan_router_challenge(protocol_interface_info_entry_t *c
uint8_t security_level = mle_service_security_level_get(cur->id); uint8_t security_level = mle_service_security_level_get(cur->id);
tr_debug("Link REQUEST"); tr_debug("Link REQUEST");
bufId = mle_service_msg_allocate(cur->id, 32, true,MLE_COMMAND_REQUEST); bufId = mle_service_msg_allocate(cur->id, 32, true, MLE_COMMAND_REQUEST);
if (bufId == 0) { if (bufId == 0) {
return false; return false;
} }
@ -305,7 +305,7 @@ static bool protocol_6lowpan_router_challenge(protocol_interface_info_entry_t *c
memcpy(ll64, ADDR_LINK_LOCAL_PREFIX, 8); memcpy(ll64, ADDR_LINK_LOCAL_PREFIX, 8);
memcpy(&ll64[8], mac64, 8); memcpy(&ll64[8], mac64, 8);
ll64[8] ^= 2; ll64[8] ^= 2;
if (mle_service_update_length_by_ptr(bufId,ptr)!= 0) { if (mle_service_update_length_by_ptr(bufId, ptr) != 0) {
tr_debug("Buffer overflow at message write"); tr_debug("Buffer overflow at message write");
} }
timeout.retrans_max = 2; timeout.retrans_max = 2;
@ -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 advert_neigh_cnt;
uint8_t neighb_max; uint8_t neighb_max;
@ -358,9 +359,9 @@ static uint8_t mle_link_quality_tlv_parse(uint8_t *mac64, uint16_t short_address
uint8_t own_addr_match = false; uint8_t own_addr_match = false;
// Searches own address from link quality TLV // Searches own address from link quality TLV
while (data_length >= entry_size ) { while (data_length >= entry_size) {
if (entry_size == 4){ if (entry_size == 4) {
if (common_read_16_bit(ptr + 2) == short_address) { if (common_read_16_bit(ptr + 2) == short_address) {
own_addr_match = true; own_addr_match = true;
} }
@ -408,7 +409,7 @@ static uint8_t *mle_table_set_neighbours(protocol_interface_info_entry_t *cur, u
uint8_t *link_flags_ptr; uint8_t *link_flags_ptr;
mac_neighbor_table_entry_t *first_entry_ptr = NULL; mac_neighbor_table_entry_t *first_entry_ptr = NULL;
mac_neighbor_table_list_t * neigh_list = &cur->mac_parameters->mac_neighbor_table->neighbour_list; mac_neighbor_table_list_t *neigh_list = &cur->mac_parameters->mac_neighbor_table->neighbour_list;
*ptr++ = MLE_TYPE_LINK_QUALITY; *ptr++ = MLE_TYPE_LINK_QUALITY;
len_ptr = ptr++; len_ptr = ptr++;
@ -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); neigh_count_max = mle_advert_neigh_cnt(cur, use_short_address_compression);
bool clean_entries = false; 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)) { if ((cur_entry->connected_device) && (cur_entry->advertisment == false)) {
@ -489,7 +489,7 @@ static int protocol_6lowpan_mle_neigh_advertise(protocol_interface_info_entry_t
* Total = 10 + neighbours * 4 * Total = 10 + neighbours * 4
*/ */
uint16_t neig_cache_size = 40 + 7; uint16_t neig_cache_size = 40 + 7;
uint8_t short_temp[2] = {0xff,0xff}; uint8_t short_temp[2] = {0xff, 0xff};
uint8_t *ptr; uint8_t *ptr;
mle_message_timeout_params_t timeout; mle_message_timeout_params_t timeout;
@ -497,7 +497,7 @@ static int protocol_6lowpan_mle_neigh_advertise(protocol_interface_info_entry_t
return 0; return 0;
} }
if (mac_neighbor_table_address_discover(mac_neighbor_info(cur), short_temp,ADDR_802_15_4_SHORT)) { if (mac_neighbor_table_address_discover(mac_neighbor_info(cur), short_temp, ADDR_802_15_4_SHORT)) {
neig_cache_size += mle_advert_neigh_cnt(cur, false) * 10; neig_cache_size += mle_advert_neigh_cnt(cur, false) * 10;
} else { } else {
neig_cache_size += mle_advert_neigh_cnt(cur, true) << 2; neig_cache_size += mle_advert_neigh_cnt(cur, true) << 2;
@ -515,7 +515,7 @@ static int protocol_6lowpan_mle_neigh_advertise(protocol_interface_info_entry_t
timeout.delay = MLE_NO_DELAY; timeout.delay = MLE_NO_DELAY;
tr_debug("Send MLE Advertisement"); tr_debug("Send MLE Advertisement");
mle_service_set_msg_destination_address(bufId,ADDR_LINK_LOCAL_ALL_ROUTERS); mle_service_set_msg_destination_address(bufId, ADDR_LINK_LOCAL_ALL_ROUTERS);
mle_service_set_msg_timeout_parameters(bufId, &timeout); mle_service_set_msg_timeout_parameters(bufId, &timeout);
ptr = mle_service_get_data_pointer(bufId); ptr = mle_service_get_data_pointer(bufId);
@ -523,7 +523,7 @@ static int protocol_6lowpan_mle_neigh_advertise(protocol_interface_info_entry_t
ptr = mle_tlv_write_mode(ptr, lowpan_mode_get_by_interface_ptr(cur)); ptr = mle_tlv_write_mode(ptr, lowpan_mode_get_by_interface_ptr(cur));
ptr = mle_table_set_neighbours(cur, ptr); ptr = mle_table_set_neighbours(cur, ptr);
if (mle_service_update_length_by_ptr(bufId,ptr)!= 0) { if (mle_service_update_length_by_ptr(bufId, ptr) != 0) {
tr_debug("Buffer overflow at message write"); tr_debug("Buffer overflow at message write");
} }
@ -626,7 +626,7 @@ static uint16_t mle_router_synch(protocol_interface_info_entry_t *cur, const uin
ptr = mle_general_write_timeout(ptr, cur); ptr = mle_general_write_timeout(ptr, cur);
} }
if (destAddress && incoming_idr != 0){ if (destAddress && incoming_idr != 0) {
uint8_t mac64[8]; uint8_t mac64[8];
memcpy(mac64, &destAddress[8], 8); memcpy(mac64, &destAddress[8], 8);
mac64[0] ^= 2; mac64[0] ^= 2;
@ -634,9 +634,9 @@ static uint16_t mle_router_synch(protocol_interface_info_entry_t *cur, const uin
} }
if (destAddress) { if (destAddress) {
mle_service_set_msg_destination_address(bufId,destAddress); mle_service_set_msg_destination_address(bufId, destAddress);
} else { } else {
mle_service_set_msg_destination_address(bufId,ADDR_LINK_LOCAL_ALL_ROUTERS); mle_service_set_msg_destination_address(bufId, ADDR_LINK_LOCAL_ALL_ROUTERS);
} }
if (retrans) { if (retrans) {
@ -657,9 +657,9 @@ static uint16_t mle_router_synch(protocol_interface_info_entry_t *cur, const uin
timeout.delay = delay; timeout.delay = delay;
if (mle_service_update_length_by_ptr(bufId,ptr)!= 0) { if (mle_service_update_length_by_ptr(bufId, ptr) != 0) {
tr_debug("Buffer overflow at message write"); tr_debug("Buffer overflow at message write");
} }
mle_service_set_msg_timeout_parameters(bufId, &timeout); mle_service_set_msg_timeout_parameters(bufId, &timeout);
mle_service_send_message(bufId); mle_service_send_message(bufId);
@ -677,12 +677,12 @@ static int mle_router_accept_request_build(protocol_interface_info_entry_t *cur,
if (type == MLE_COMMAND_ACCEPT) { if (type == MLE_COMMAND_ACCEPT) {
bufId = mle_service_msg_allocate(cur->id, 64, false,type); bufId = mle_service_msg_allocate(cur->id, 64, false, type);
timeout.retrans_max = 0; timeout.retrans_max = 0;
timeout.timeout_init = 0; timeout.timeout_init = 0;
timeout.timeout_max = 0; timeout.timeout_max = 0;
} else { } else {
bufId = mle_service_msg_allocate(cur->id, 64, true,type); bufId = mle_service_msg_allocate(cur->id, 64, true, type);
timeout.retrans_max = 2; timeout.retrans_max = 2;
timeout.timeout_init = 2; timeout.timeout_init = 2;
timeout.timeout_max = 4; timeout.timeout_max = 4;
@ -700,7 +700,7 @@ static int mle_router_accept_request_build(protocol_interface_info_entry_t *cur,
tr_debug("MLE Router Link Request response"); tr_debug("MLE Router Link Request response");
mle_service_set_msg_destination_address(bufId,mle_msg->packet_src_address); mle_service_set_msg_destination_address(bufId, mle_msg->packet_src_address);
uint8_t *ptr = mle_service_get_data_pointer(bufId); uint8_t *ptr = mle_service_get_data_pointer(bufId);
ptr = mle_tlv_write_mode(ptr, lowpan_mode_get_by_interface_ptr(cur)); ptr = mle_tlv_write_mode(ptr, lowpan_mode_get_by_interface_ptr(cur));
@ -719,9 +719,9 @@ static int mle_router_accept_request_build(protocol_interface_info_entry_t *cur,
ptr = mle_tlv_write_link_quality(ptr, incoming_idr, mac64, 0, priority_flag); ptr = mle_tlv_write_link_quality(ptr, incoming_idr, mac64, 0, priority_flag);
ptr = mle_general_write_source_address(ptr, cur); ptr = mle_general_write_source_address(ptr, cur);
if (mle_service_update_length_by_ptr(bufId,ptr)!= 0) { if (mle_service_update_length_by_ptr(bufId, ptr) != 0) {
tr_debug("Buffer overflow at message write"); tr_debug("Buffer overflow at message write");
} }
mle_service_set_msg_timeout_parameters(bufId, &timeout); mle_service_set_msg_timeout_parameters(bufId, &timeout);
if (type == MLE_COMMAND_ACCEPT) { if (type == MLE_COMMAND_ACCEPT) {
@ -995,7 +995,7 @@ static bool mle_6lowpan_neighbor_limit_check(mle_message_t *mle_msg, uint8_t onl
if (mle_msg->message_type == MLE_COMMAND_REQUEST) { if (mle_msg->message_type == MLE_COMMAND_REQUEST) {
mle_tlv_info_t mle_tlv_info; mle_tlv_info_t mle_tlv_info;
if (mle_tlv_option_discover(mle_msg->data_ptr, mle_msg->data_length, MLE_TYPE_LINK_QUALITY, &mle_tlv_info) > 0) { if (mle_tlv_option_discover(mle_msg->data_ptr, mle_msg->data_length, MLE_TYPE_LINK_QUALITY, &mle_tlv_info) > 0) {
link_quality = true; link_quality = true;
} }
} }
@ -1010,7 +1010,7 @@ static bool mle_6lowpan_neighbor_limit_check(mle_message_t *mle_msg, uint8_t onl
} }
uint16_t ignore_prob = randLIB_get_random_in_range(1, uint16_t ignore_prob = randLIB_get_random_in_range(1,
mle_6lowpan_data->nbr_of_neigh_upper_threshold - mle_6lowpan_data->nbr_of_neigh_lower_threshold); mle_6lowpan_data->nbr_of_neigh_upper_threshold - mle_6lowpan_data->nbr_of_neigh_lower_threshold);
if (ignore_prob < (mle_neigh_cnt - mle_6lowpan_data->nbr_of_neigh_lower_threshold)) { if (ignore_prob < (mle_neigh_cnt - mle_6lowpan_data->nbr_of_neigh_lower_threshold)) {
return false; return false;
@ -1041,7 +1041,7 @@ void mle_6lowpan_message_handler(int8_t interface_id, mle_message_t *mle_msg, ml
tr_debug("Link REQ"); tr_debug("Link REQ");
if (!cur->global_address_available) { if (!cur->global_address_available) {
return; return;
} else if (mle_validate_6lowpan_link_request_message(mle_msg->data_ptr, mle_msg->data_length,&mle_challenge) !=0 ) { } else if (mle_validate_6lowpan_link_request_message(mle_msg->data_ptr, mle_msg->data_length, &mle_challenge) != 0) {
return; return;
} }
@ -1057,7 +1057,7 @@ void mle_6lowpan_message_handler(int8_t interface_id, mle_message_t *mle_msg, ml
//Update only old information based on link request //Update only old information based on link request
entry_temp = mac_neighbor_entry_get_by_ll64(mac_neighbor_info(cur), mle_msg->packet_src_address, false, NULL); entry_temp = mac_neighbor_entry_get_by_ll64(mac_neighbor_info(cur), mle_msg->packet_src_address, false, NULL);
if (entry_temp) { if (entry_temp) {
mle_neigh_time_and_mode_update(entry_temp,mle_msg); mle_neigh_time_and_mode_update(entry_temp, mle_msg);
mle_neigh_entry_update_by_mle_tlv_list(interface_id, entry_temp, mle_msg->data_ptr, mle_msg->data_length, cur->mac, own_mac16); mle_neigh_entry_update_by_mle_tlv_list(interface_id, entry_temp, mle_msg->data_ptr, mle_msg->data_length, cur->mac, own_mac16);
mle_neigh_entry_frame_counter_update(entry_temp, mle_msg->data_ptr, mle_msg->data_length, cur, security_headers->KeyIndex); mle_neigh_entry_frame_counter_update(entry_temp, mle_msg->data_ptr, mle_msg->data_length, cur, security_headers->KeyIndex);
} else { } else {
@ -1114,7 +1114,7 @@ void mle_6lowpan_message_handler(int8_t interface_id, mle_message_t *mle_msg, ml
mac_data_poll_protocol_poll_mode_decrement(cur); mac_data_poll_protocol_poll_mode_decrement(cur);
//Read Source address and Challenge //Read Source address and Challenge
mle_neigh_time_and_mode_update(entry_temp,mle_msg); mle_neigh_time_and_mode_update(entry_temp, mle_msg);
if (mle_msg->message_type == MLE_COMMAND_ACCEPT_AND_REQUEST) { if (mle_msg->message_type == MLE_COMMAND_ACCEPT_AND_REQUEST) {
// If no global address set priority (bootstrap ongoing) // If no global address set priority (bootstrap ongoing)
if (!cur->global_address_available) { if (!cur->global_address_available) {
@ -1179,8 +1179,7 @@ void mle_6lowpan_message_handler(int8_t interface_id, mle_message_t *mle_msg, ml
uint8_t link_flags; uint8_t link_flags;
if (mle_tlv_info.tlvLen > 0) { if (mle_tlv_info.tlvLen > 0) {
link_flags = *(mle_tlv_info.dataPtr); 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; drop_advertisment = 0;
} }
@ -1200,7 +1199,7 @@ void mle_6lowpan_message_handler(int8_t interface_id, mle_message_t *mle_msg, ml
} }
//UPDATE //UPDATE
mle_neigh_entry_update_by_mle_tlv_list(cur->id,entry_temp, mle_msg->data_ptr, mle_msg->data_length, cur->mac, own_mac16); mle_neigh_entry_update_by_mle_tlv_list(cur->id, entry_temp, mle_msg->data_ptr, mle_msg->data_length, cur->mac, own_mac16);
mle_neigh_entry_frame_counter_update(entry_temp, mle_msg->data_ptr, mle_msg->data_length, cur, security_headers->KeyIndex); mle_neigh_entry_frame_counter_update(entry_temp, mle_msg->data_ptr, mle_msg->data_length, cur, security_headers->KeyIndex);
if (entry_temp->connected_device) { if (entry_temp->connected_device) {
mac_neighbor_table_neighbor_refresh(mac_neighbor_info(cur), entry_temp, entry_temp->link_lifetime); mac_neighbor_table_neighbor_refresh(mac_neighbor_info(cur), entry_temp, entry_temp->link_lifetime);
@ -1220,13 +1219,13 @@ int8_t arm_6lowpan_mle_service_ready_for_security_init(protocol_interface_info_e
//validate MLE service //validate MLE service
if (!mle_service_interface_registeration_validate(cur->id)) { if (!mle_service_interface_registeration_validate(cur->id)) {
//Register //Register
if (mle_service_interface_register(cur->id,cur, mle_6lowpan_message_handler, cur->mac,8) != 0) { if (mle_service_interface_register(cur->id, cur, mle_6lowpan_message_handler, cur->mac, 8) != 0) {
tr_error("Mle Service init Fail"); tr_error("Mle Service init Fail");
return -1; return -1;
} }
if (mle_6lowpan_data) { if (mle_6lowpan_data) {
if (mle_service_interface_token_bucket_settings_set(cur->id, mle_6lowpan_data->token_bucket_size, if (mle_service_interface_token_bucket_settings_set(cur->id, mle_6lowpan_data->token_bucket_size,
mle_6lowpan_data->token_bucket_rate, mle_6lowpan_data->token_bucket_count) < 0) { mle_6lowpan_data->token_bucket_rate, mle_6lowpan_data->token_bucket_count) < 0) {
return -1; return -1;
} }
mle_service_set_frame_counter_check(true); mle_service_set_frame_counter_check(true);
@ -1312,7 +1311,7 @@ static uint8_t protocol_6lowpan_mle_order_last_entries(int8_t interface_id, mac_
{ {
mac_neighbor_table_entry_t *last; mac_neighbor_table_entry_t *last;
mac_neighbor_table_entry_t *first_ordered = NULL; mac_neighbor_table_entry_t *first_ordered = NULL;
etx_storage_t * etx_last, *etx_cur; etx_storage_t *etx_last, *etx_cur;
uint8_t count = 0; uint8_t count = 0;
do { do {
last = NULL; last = NULL;
@ -1358,7 +1357,7 @@ static uint8_t protocol_6lowpan_mle_order_last_entries(int8_t interface_id, mac_
if (count == entry_count) { if (count == entry_count) {
break; break;
} }
// If no lasts anymore then exits // If no lasts anymore then exits
} else { } else {
break; break;
} }
@ -1393,21 +1392,21 @@ static void lowpan_mle_receive_security_bypass_cb(int8_t interface_id, mle_messa
if (mle_msg->message_type == MLE_COMMAND_REJECT) { if (mle_msg->message_type == MLE_COMMAND_REJECT) {
if ((interface->lowpan_info & (INTERFACE_NWK_BOOTSRAP_ACTIVE | INTERFACE_NWK_BOOTSRAP_PANA_AUTHENTICATION)) != (INTERFACE_NWK_BOOTSRAP_ACTIVE | INTERFACE_NWK_BOOTSRAP_PANA_AUTHENTICATION)) { if ((interface->lowpan_info & (INTERFACE_NWK_BOOTSRAP_ACTIVE | INTERFACE_NWK_BOOTSRAP_PANA_AUTHENTICATION)) != (INTERFACE_NWK_BOOTSRAP_ACTIVE | INTERFACE_NWK_BOOTSRAP_PANA_AUTHENTICATION)) {
return; return;
} }
if (protocol_6lowpan_interface_compare_cordinator_netid(interface, mle_msg->packet_src_address + 8) != 0) { if (protocol_6lowpan_interface_compare_cordinator_netid(interface, mle_msg->packet_src_address + 8) != 0) {
return; return;
} }
if (interface->nwk_bootstrap_state != ER_PANA_AUTH) { if (interface->nwk_bootstrap_state != ER_PANA_AUTH) {
return; return;
} }
//Stop Pana and call ECC //Stop Pana and call ECC
tr_debug("MLE Link reject from cordinator"); tr_debug("MLE Link reject from cordinator");
pana_reset_client_session(); pana_reset_client_session();
bootsrap_next_state_kick(ER_PANA_AUTH_ERROR, interface); bootsrap_next_state_kick(ER_PANA_AUTH_ERROR, interface);
} }
#endif #endif
} }
@ -1416,14 +1415,14 @@ void arm_6lowpan_security_init_ifup(protocol_interface_info_entry_t *cur)
{ {
if (cur->lowpan_info & INTERFACE_NWK_BOOTSRAP_MLE) { if (cur->lowpan_info & INTERFACE_NWK_BOOTSRAP_MLE) {
mle_service_security_init(cur->id, cur->if_lowpan_security_params->security_level,cur->if_lowpan_security_params->mle_security_frame_counter, NULL, protocol_6lowpan_mle_service_security_notify_cb); mle_service_security_init(cur->id, cur->if_lowpan_security_params->security_level, cur->if_lowpan_security_params->mle_security_frame_counter, NULL, protocol_6lowpan_mle_service_security_notify_cb);
switch (cur->if_lowpan_security_params->nwk_security_mode) { switch (cur->if_lowpan_security_params->nwk_security_mode) {
case NET_SEC_MODE_PSK_LINK_SECURITY: case NET_SEC_MODE_PSK_LINK_SECURITY:
mle_service_security_set_security_key(cur->id, cur->if_lowpan_security_params->psk_key_info.security_key, cur->if_lowpan_security_params->psk_key_info.key_id, true); mle_service_security_set_security_key(cur->id, cur->if_lowpan_security_params->psk_key_info.security_key, cur->if_lowpan_security_params->psk_key_info.key_id, true);
mle_service_security_set_frame_counter(cur->id, cur->if_lowpan_security_params->mle_security_frame_counter); mle_service_security_set_frame_counter(cur->id, cur->if_lowpan_security_params->mle_security_frame_counter);
break; break;
case NET_SEC_MODE_PANA_LINK_SECURITY: case NET_SEC_MODE_PANA_LINK_SECURITY:
mle_service_interface_receiver_bypass_handler_update(cur->id, lowpan_mle_receive_security_bypass_cb); mle_service_interface_receiver_bypass_handler_update(cur->id, lowpan_mle_receive_security_bypass_cb);
break; break;
@ -1442,7 +1441,7 @@ void arm_6lowpan_security_init_ifup(protocol_interface_info_entry_t *cur)
case NET_SEC_MODE_PSK_LINK_SECURITY: case NET_SEC_MODE_PSK_LINK_SECURITY:
mac_helper_security_default_key_set(cur, cur->if_lowpan_security_params->psk_key_info.security_key, cur->if_lowpan_security_params->psk_key_info.key_id, MAC_KEY_ID_MODE_IDX); mac_helper_security_default_key_set(cur, cur->if_lowpan_security_params->psk_key_info.security_key, cur->if_lowpan_security_params->psk_key_info.key_id, MAC_KEY_ID_MODE_IDX);
/* fall through */ /* fall through */
default: default:
cur->lowpan_info &= ~INTERFACE_NWK_BOOTSRAP_PANA_AUTHENTICATION; cur->lowpan_info &= ~INTERFACE_NWK_BOOTSRAP_PANA_AUTHENTICATION;
break; break;
@ -1464,7 +1463,7 @@ static int8_t arm_6lowpan_bootstrap_up(protocol_interface_info_entry_t *cur)
if (!mle_service_interface_registeration_validate(cur->id)) { if (!mle_service_interface_registeration_validate(cur->id)) {
//Register //Register
if (mle_service_interface_register(cur->id, cur, mle_6lowpan_message_handler, cur->mac,8) != 0) { if (mle_service_interface_register(cur->id, cur, mle_6lowpan_message_handler, cur->mac, 8) != 0) {
tr_error("Mle Service init Fail"); tr_error("Mle Service init Fail");
return -1; return -1;
} }
@ -1679,7 +1678,7 @@ int8_t arm_6lowpan_bootstarp_bootstrap_set(int8_t interface_id, net_6lowpan_mode
} }
mac_neighbor_info(cur) = mac_neighbor_table_create(buffer.device_decription_table_size, lowpan_neighbor_entry_remove_notify mac_neighbor_info(cur) = mac_neighbor_table_create(buffer.device_decription_table_size, lowpan_neighbor_entry_remove_notify
, lowpan_neighbor_entry_nud_notify, cur); , lowpan_neighbor_entry_nud_notify, cur);
if (!mac_neighbor_info(cur)) { if (!mac_neighbor_info(cur)) {
return -1; return -1;
} }
@ -1719,7 +1718,7 @@ int8_t arm_6lowpan_bootstarp_bootstrap_set(int8_t interface_id, net_6lowpan_mode
return -2; return -2;
#else #else
cur->comm_status_ind_cb = lowpan_comm_status_indication_cb; cur->comm_status_ind_cb = lowpan_comm_status_indication_cb;
if (mle_service_interface_register(cur->id, cur, mle_6lowpan_message_handler, cur->mac,8) != 0) { if (mle_service_interface_register(cur->id, cur, mle_6lowpan_message_handler, cur->mac, 8) != 0) {
tr_error("Mle Service init Fail"); tr_error("Mle Service init Fail");
return -1; return -1;
} }
@ -1736,7 +1735,7 @@ int8_t arm_6lowpan_bootstarp_bootstrap_set(int8_t interface_id, net_6lowpan_mode
if (mle_6lowpan_data) { if (mle_6lowpan_data) {
if (mle_service_interface_token_bucket_settings_set(cur->id, mle_6lowpan_data->token_bucket_size, if (mle_service_interface_token_bucket_settings_set(cur->id, mle_6lowpan_data->token_bucket_size,
mle_6lowpan_data->token_bucket_rate, mle_6lowpan_data->token_bucket_count) < 0) { mle_6lowpan_data->token_bucket_rate, mle_6lowpan_data->token_bucket_count) < 0) {
tr_error("Mle Service tokens set Fail"); tr_error("Mle Service tokens set Fail");
return -1; return -1;
} }
@ -1773,7 +1772,7 @@ int8_t arm_6lowpan_bootstarp_bootstrap_set(int8_t interface_id, net_6lowpan_mode
} }
} }
bootstrap_finish_check: bootstrap_finish_check:
if (ret_val == 0) { if (ret_val == 0) {
/** /**
* Do Thread dealloc * Do Thread dealloc
@ -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) { if (cur->lowpan_info & INTERFACE_NWK_ROUTER_DEVICE) {
//rpl_control_set_domain_on_interface(cur, protocol_6lowpan_rpl_domain, true); //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 #endif
cur->configure_flags |= INTERFACE_BOOTSTRAP_DEFINED; cur->configure_flags |= INTERFACE_BOOTSTRAP_DEFINED;
@ -1965,7 +1964,7 @@ static void protocol_6lowpan_nd_ready(protocol_interface_info_entry_t *cur)
addrtype_t addrType; addrtype_t addrType;
uint8_t tempAddr[8]; uint8_t tempAddr[8];
addrType = mac_helper_coordinator_address_get(cur, tempAddr); addrType = mac_helper_coordinator_address_get(cur, tempAddr);
mac_neighbor_table_entry_t * neig_info = mac_neighbor_table_address_discover(mac_neighbor_info(cur), tempAddr, addrType); mac_neighbor_table_entry_t *neig_info = mac_neighbor_table_address_discover(mac_neighbor_info(cur), tempAddr, addrType);
if (neig_info) { if (neig_info) {
if (neig_info->lifetime > MLE_TABLE_CHALLENGE_TIMER) { if (neig_info->lifetime > MLE_TABLE_CHALLENGE_TIMER) {
@ -1982,7 +1981,7 @@ static void protocol_6lowpan_address_reg_ready(protocol_interface_info_entry_t *
nd_router_t *cur; nd_router_t *cur;
cur = nd_get_object_by_nwk_id(cur_interface->nwk_id); cur = nd_get_object_by_nwk_id(cur_interface->nwk_id);
if(!cur) { if (!cur) {
return; return;
} }
@ -2029,7 +2028,7 @@ void protocol_6lowpan_bootstrap_nd_ready(protocol_interface_info_entry_t *cur_in
} else { } else {
//Here we need to verify address mode //Here we need to verify address mode
tr_debug("Synch MAC16 with parent"); tr_debug("Synch MAC16 with parent");
if (protocol_6lowpan_parent_address_synch(cur_interface, true) != 0 ) { if (protocol_6lowpan_parent_address_synch(cur_interface, true) != 0) {
nwk_bootsrap_state_update(ARM_NWK_NWK_CONNECTION_DOWN, cur_interface); nwk_bootsrap_state_update(ARM_NWK_NWK_CONNECTION_DOWN, cur_interface);
} }
} }
@ -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"); tr_error("RPL Local repair fail-->interface to idle");
nwk_bootsrap_state_update(ARM_NWK_NWK_CONNECTION_DOWN, cur); nwk_bootsrap_state_update(ARM_NWK_NWK_CONNECTION_DOWN, cur);
break; 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 // 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_force_leaf(protocol_6lowpan_rpl_domain, false);
rpl_control_set_domain_on_interface(cur, protocol_6lowpan_rpl_domain, true); 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 // Send unicast DIS to coordinator
nwk_bootstrap_icmp_rpl_dis_coord_msg_tx(cur); nwk_bootstrap_icmp_rpl_dis_coord_msg_tx(cur);
@ -2305,7 +2306,7 @@ static void nwk_6lowpan_bootsrap_pana_authentication_start(protocol_interface_in
static void coordinator_black_list(protocol_interface_info_entry_t *cur) static void coordinator_black_list(protocol_interface_info_entry_t *cur)
{ {
uint8_t coord_pan_address[10]; uint8_t coord_pan_address[10];
addrtype_t cord_adr_type = mac_helper_coordinator_address_get(cur, coord_pan_address +2); addrtype_t cord_adr_type = mac_helper_coordinator_address_get(cur, coord_pan_address + 2);
if (cord_adr_type != ADDR_NONE) { if (cord_adr_type != ADDR_NONE) {
uint16_t pana_id = mac_helper_panid_get(cur); uint16_t pana_id = mac_helper_panid_get(cur);
@ -2321,7 +2322,7 @@ static void coordinator_black_list(protocol_interface_info_entry_t *cur)
static void nwk_6lowpan_network_authentication_fail(protocol_interface_info_entry_t *cur) static void nwk_6lowpan_network_authentication_fail(protocol_interface_info_entry_t *cur)
{ {
nwk_scan_params_t *scan_params = nwk_scan_params_t *scan_params =
&cur->mac_parameters->nwk_scan_params; &cur->mac_parameters->nwk_scan_params;
tr_warn("Pana Auhth er"); tr_warn("Pana Auhth er");
@ -2378,9 +2379,9 @@ static void nwk_protocol_network_key_init_from_pana(protocol_interface_info_entr
mac_helper_security_default_key_set(cur, (key_ptr + 16), cur->pana_sec_info_temp->key_id, MAC_KEY_ID_MODE_IDX); mac_helper_security_default_key_set(cur, (key_ptr + 16), cur->pana_sec_info_temp->key_id, MAC_KEY_ID_MODE_IDX);
//mac_security_interface_link_frame_counter_reset(cur->id); //mac_security_interface_link_frame_counter_reset(cur->id);
mac_helper_default_security_level_set(cur, SEC_ENC_MIC32); mac_helper_default_security_level_set(cur, SEC_ENC_MIC32);
mac_helper_default_security_key_id_mode_set(cur,MAC_KEY_ID_MODE_IDX); mac_helper_default_security_key_id_mode_set(cur, MAC_KEY_ID_MODE_IDX);
//Init MLE Frame counter and key's and security //Init MLE Frame counter and key's and security
mle_service_security_init(cur->id, SEC_ENC_MIC32,cur->if_lowpan_security_params->mle_security_frame_counter, NULL, protocol_6lowpan_mle_service_security_notify_cb); mle_service_security_init(cur->id, SEC_ENC_MIC32, cur->if_lowpan_security_params->mle_security_frame_counter, NULL, protocol_6lowpan_mle_service_security_notify_cb);
mle_service_security_set_security_key(cur->id, key_ptr, cur->pana_sec_info_temp->key_id, true); mle_service_security_set_security_key(cur->id, key_ptr, cur->pana_sec_info_temp->key_id, true);
mle_service_security_set_frame_counter(cur->id, cur->if_lowpan_security_params->mle_security_frame_counter); mle_service_security_set_frame_counter(cur->id, cur->if_lowpan_security_params->mle_security_frame_counter);
} }
@ -2482,7 +2483,7 @@ bool protocol_6lowpan_bootsrap_start(protocol_interface_info_entry_t *interface)
if (interface->if_lowpan_security_params->nwk_security_mode == NET_SEC_MODE_PSK_LINK_SECURITY) { if (interface->if_lowpan_security_params->nwk_security_mode == NET_SEC_MODE_PSK_LINK_SECURITY) {
tr_debug("SET Security Mode"); tr_debug("SET Security Mode");
mac_helper_default_security_level_set(interface, interface->mac_parameters->mac_configured_sec_level); mac_helper_default_security_level_set(interface, interface->mac_parameters->mac_configured_sec_level);
mac_helper_default_security_key_id_mode_set(interface,MAC_KEY_ID_MODE_IDX); mac_helper_default_security_key_id_mode_set(interface, MAC_KEY_ID_MODE_IDX);
} }
//Check first pana and then MLE and else start RS scan pahse //Check first pana and then MLE and else start RS scan pahse
@ -2506,7 +2507,7 @@ bool protocol_6lowpan_bootsrap_start(protocol_interface_info_entry_t *interface)
} }
void protocol_6lowpan_mac_scan_confirm(int8_t if_id, const mlme_scan_conf_t* conf) void protocol_6lowpan_mac_scan_confirm(int8_t if_id, const mlme_scan_conf_t *conf)
{ {
nwk_pan_descriptor_t *result; nwk_pan_descriptor_t *result;
nwk_pan_descriptor_t *best; nwk_pan_descriptor_t *best;
@ -2585,8 +2586,8 @@ void bootstrap_timer_handle(uint16_t ticks)
start_req.BeaconOrder = 0x0f; start_req.BeaconOrder = 0x0f;
start_req.SuperframeOrder = 0x0f; start_req.SuperframeOrder = 0x0f;
start_req.PANCoordinator = 1; start_req.PANCoordinator = 1;
if( cur->mac_api ){ if (cur->mac_api) {
cur->mac_api->mlme_req(cur->mac_api, MLME_START, (void*)&start_req); cur->mac_api->mlme_req(cur->mac_api, MLME_START, (void *)&start_req);
tr_error("Restart MAC"); tr_error("Restart MAC");
} }
} }
@ -2604,7 +2605,7 @@ void protocol_6lowpan_bootstrap(protocol_interface_info_entry_t *cur)
mlme_scan_t req; mlme_scan_t req;
mac_create_scan_request(MAC_ACTIVE_SCAN, &cur->mac_parameters->mac_channel_list, cur->mac_parameters->nwk_scan_params.scan_duration, &req); mac_create_scan_request(MAC_ACTIVE_SCAN, &cur->mac_parameters->mac_channel_list, cur->mac_parameters->nwk_scan_params.scan_duration, &req);
if( cur->mac_api ){ if (cur->mac_api) {
cur->scan_cb = protocol_6lowpan_mac_scan_confirm; cur->scan_cb = protocol_6lowpan_mac_scan_confirm;
cur->mac_parameters->nwk_scan_params.active_scan_active = true; cur->mac_parameters->nwk_scan_params.active_scan_active = true;
if (cur->bootsrap_mode == ARM_NWK_BOOTSRAP_MODE_6LoWPAN_BORDER_ROUTER) { if (cur->bootsrap_mode == ARM_NWK_BOOTSRAP_MODE_6LoWPAN_BORDER_ROUTER) {
@ -2736,7 +2737,7 @@ int protocol_6lowpan_set_ll16(protocol_interface_info_entry_t *cur, uint16_t mac
if_address_entry_t *address_entry; if_address_entry_t *address_entry;
uint8_t address[16]; uint8_t address[16];
memcpy(address, ADDR_LINK_LOCAL_PREFIX, 8); memcpy(address, ADDR_LINK_LOCAL_PREFIX, 8);
memcpy(address + 8, ADDR_SHORT_ADR_SUFFIC , 6); memcpy(address + 8, ADDR_SHORT_ADR_SUFFIC, 6);
common_write_16_bit(mac_short_address, &address[14]); common_write_16_bit(mac_short_address, &address[14]);
address_entry = addr_add(cur, address, 64, ADDR_SOURCE_UNKNOWN, 0xffffffff, 0xffffffff, false); address_entry = addr_add(cur, address, 64, ADDR_SOURCE_UNKNOWN, 0xffffffff, 0xffffffff, false);
@ -2751,10 +2752,10 @@ static void protocol_6lowpan_generate_link_reject(protocol_interface_info_entry_
uint8_t address[16]; uint8_t address[16];
memcpy(address, ADDR_LINK_LOCAL_PREFIX, 8); memcpy(address, ADDR_LINK_LOCAL_PREFIX, 8);
if (status->SrcAddrMode == MAC_ADDR_MODE_16_BIT) { if (status->SrcAddrMode == MAC_ADDR_MODE_16_BIT) {
memcpy(address + 8, ADDR_SHORT_ADR_SUFFIC , 6); memcpy(address + 8, ADDR_SHORT_ADR_SUFFIC, 6);
memcpy(address + 14,status->SrcAddr, 2); memcpy(address + 14, status->SrcAddr, 2);
} else { } else {
memcpy(address + 8,status->SrcAddr, 8); memcpy(address + 8, status->SrcAddr, 8);
address[8] ^= 2; address[8] ^= 2;
} }
if (mac_helper_default_security_level_get(cur)) { if (mac_helper_default_security_level_get(cur)) {
@ -2765,14 +2766,14 @@ static void protocol_6lowpan_generate_link_reject(protocol_interface_info_entry_
} }
static void lowpan_comm_status_indication_cb(int8_t if_id, const mlme_comm_status_t* status) static void lowpan_comm_status_indication_cb(int8_t if_id, const mlme_comm_status_t *status)
{ {
protocol_interface_info_entry_t *cur = protocol_stack_interface_info_get_by_id(if_id); protocol_interface_info_entry_t *cur = protocol_stack_interface_info_get_by_id(if_id);
if (!cur) { if (!cur) {
return; return;
} }
mac_neighbor_table_entry_t * entry_ptr; mac_neighbor_table_entry_t *entry_ptr;
switch (status->status) { switch (status->status) {
case MLME_UNSUPPORTED_SECURITY: case MLME_UNSUPPORTED_SECURITY:

View File

@ -219,7 +219,7 @@ static void reassembly_entry_free(reassembly_interface_t *interface_ptr, reassem
} }
} }
static void reassembly_list_free(reassembly_interface_t *interface_ptr ) static void reassembly_list_free(reassembly_interface_t *interface_ptr)
{ {
ns_list_foreach_safe(reassembly_entry_t, reassembly_entry, &interface_ptr->rx_list) { ns_list_foreach_safe(reassembly_entry_t, reassembly_entry, &interface_ptr->rx_list) {
reassembly_entry_free(interface_ptr, reassembly_entry); reassembly_entry_free(interface_ptr, reassembly_entry);
@ -303,7 +303,7 @@ buffer_t *cipv6_frag_reassembly(int8_t interface_id, buffer_t *buf)
goto resassembly_error; goto resassembly_error;
} }
buffer_t *reassembly_buffer = buffer_get(1 + ((datagram_size+7) & ~7)); buffer_t *reassembly_buffer = buffer_get(1 + ((datagram_size + 7) & ~7));
if (!reassembly_buffer) { if (!reassembly_buffer) {
//Put allocated back to free //Put allocated back to free
reassembly_entry_free(interface_ptr, frag_ptr); reassembly_entry_free(interface_ptr, frag_ptr);
@ -509,14 +509,14 @@ int8_t reassembly_interface_init(int8_t interface_id, uint8_t reassembly_session
return -1; return -1;
} }
memset(interface_ptr, 0 ,sizeof(reassembly_interface_t)); memset(interface_ptr, 0, sizeof(reassembly_interface_t));
interface_ptr->interface_id = interface_id; interface_ptr->interface_id = interface_id;
interface_ptr->timeout = reassembly_timeout; interface_ptr->timeout = reassembly_timeout;
interface_ptr->entry_pointer_buffer = reassemply_ptr; interface_ptr->entry_pointer_buffer = reassemply_ptr;
ns_list_init(&interface_ptr->free_list); ns_list_init(&interface_ptr->free_list);
ns_list_init(&interface_ptr->rx_list); ns_list_init(&interface_ptr->rx_list);
for (uint8_t i=0; i<reassembly_session_limit ; i++) { for (uint8_t i = 0; i < reassembly_session_limit ; i++) {
ns_list_add_to_end(&interface_ptr->free_list, reassemply_ptr); ns_list_add_to_end(&interface_ptr->free_list, reassemply_ptr);
reassemply_ptr++; reassemply_ptr++;
} }

View File

@ -27,7 +27,7 @@
#define TRACE_GROUP "iphc" #define TRACE_GROUP "iphc"
typedef struct iphc_compress_state { typedef struct iphc_compress_state {
const lowpan_context_list_t * const context_list; const lowpan_context_list_t *const context_list;
const uint8_t *in; const uint8_t *in;
uint8_t *out; uint8_t *out;
uint16_t len; uint16_t len;
@ -249,7 +249,7 @@ static bool compress_udp(iphc_compress_state_t *restrict cs)
} }
*ptr++ = NHC_UDP | NHC_UDP_PORT_COMPRESS_BOTH; *ptr++ = NHC_UDP | NHC_UDP_PORT_COMPRESS_BOTH;
*ptr++ = (src_port & 0xF) << 4 | *ptr++ = (src_port & 0xF) << 4 |
(dst_port & 0xF); (dst_port & 0xF);
} else if ((src_port & 0xff00) == 0xf000) { } else if ((src_port & 0xff00) == 0xf000) {
if (cs->out_space < 7) { if (cs->out_space < 7) {
return false; return false;

View File

@ -329,7 +329,7 @@ static bool decompress_addr(const lowpan_context_list_t *context_list, uint8_t *
} }
typedef struct iphc_decompress_state { typedef struct iphc_decompress_state {
const lowpan_context_list_t * const context_list; const lowpan_context_list_t *const context_list;
const uint8_t *in; const uint8_t *in;
const uint8_t *const end; const uint8_t *const end;
uint8_t *out; uint8_t *out;
@ -546,7 +546,7 @@ buffer_t *iphc_decompress(const lowpan_context_list_t *context_list, buffer_t *b
/* Copy compressed header into temporary buffer */ /* Copy compressed header into temporary buffer */
iphc = ns_dyn_mem_temporary_alloc(hc_size); iphc = ns_dyn_mem_temporary_alloc(hc_size);
if (!iphc) { if (!iphc) {
tr_warn("IPHC header alloc fail %d",hc_size); tr_warn("IPHC header alloc fail %d", hc_size);
goto decomp_error; goto decomp_error;
} }
memcpy(iphc, buffer_data_pointer(buf), hc_size); memcpy(iphc, buffer_data_pointer(buf), hc_size);
@ -555,7 +555,7 @@ buffer_t *iphc_decompress(const lowpan_context_list_t *context_list, buffer_t *b
buffer_data_strip_header(buf, hc_size); buffer_data_strip_header(buf, hc_size);
buf = buffer_headroom(buf, ip_size); buf = buffer_headroom(buf, ip_size);
if (!buf) { if (!buf) {
tr_warn("IPHC headroom get fail %d",ip_size); tr_warn("IPHC headroom get fail %d", ip_size);
goto decomp_error; goto decomp_error;
} }
buffer_data_reserve_header(buf, ip_size); buffer_data_reserve_header(buf, ip_size);

View File

@ -31,14 +31,14 @@
#define TRACE_GROUP "BHlr" #define TRACE_GROUP "BHlr"
static mlme_pan_descriptor_t *duplicate_pan_descriptor(const mlme_pan_descriptor_t *desc); static mlme_pan_descriptor_t *duplicate_pan_descriptor(const mlme_pan_descriptor_t *desc);
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);
static uint8_t *beacon_optional_tlv_field_get(uint8_t len, uint8_t *ptr, uint8_t offset, uint8_t type); static uint8_t *beacon_optional_tlv_field_get(uint8_t len, uint8_t *ptr, uint8_t offset, uint8_t type);
static bool beacon_join_priority_tlv_val_get(uint8_t len, uint8_t *ptr, uint8_t offset, uint8_t *join_priority); static bool beacon_join_priority_tlv_val_get(uint8_t len, uint8_t *ptr, uint8_t offset, uint8_t *join_priority);
static bool beacon_join_priority_tlv_val_set(uint8_t len, uint8_t *ptr, uint8_t offset, uint8_t join_priority); static bool beacon_join_priority_tlv_val_set(uint8_t len, uint8_t *ptr, uint8_t offset, uint8_t join_priority);
static bool beacon_join_priority_tlv_add(uint8_t len, uint8_t *ptr, uint8_t offset, uint8_t join_priority); static bool beacon_join_priority_tlv_add(uint8_t len, uint8_t *ptr, uint8_t offset, uint8_t join_priority);
void beacon_received(int8_t if_id, const mlme_beacon_ind_t* data) void beacon_received(int8_t if_id, const mlme_beacon_ind_t *data)
{ {
protocol_interface_info_entry_t *interface = protocol_stack_interface_info_get_by_id(if_id); protocol_interface_info_entry_t *interface = protocol_stack_interface_info_get_by_id(if_id);
if (!interface || !data) { if (!interface || !data) {
@ -52,9 +52,9 @@ void beacon_received(int8_t if_id, const mlme_beacon_ind_t* data)
uint8_t coord_pan_address[10]; uint8_t coord_pan_address[10];
common_write_16_bit(data->PANDescriptor.CoordPANId, coord_pan_address); common_write_16_bit(data->PANDescriptor.CoordPANId, coord_pan_address);
memcpy(coord_pan_address + 2,data->PANDescriptor.CoordAddress, 8 ); memcpy(coord_pan_address + 2, data->PANDescriptor.CoordAddress, 8);
if (data->PANDescriptor.CoordAddrMode == MAC_ADDR_MODE_16_BIT) { if (data->PANDescriptor.CoordAddrMode == MAC_ADDR_MODE_16_BIT) {
memset(coord_pan_address +4, 0, 6); memset(coord_pan_address + 4, 0, 6);
} }
if (pan_cordinator_blacklist_filter(&interface->pan_cordinator_black_list, coord_pan_address)) { if (pan_cordinator_blacklist_filter(&interface->pan_cordinator_black_list, coord_pan_address)) {
@ -108,7 +108,7 @@ void beacon_received(int8_t if_id, const mlme_beacon_ind_t* data)
//Here possible dynamic function API Call //Here possible dynamic function API Call
uint8_t *b_data = ns_dyn_mem_temporary_alloc(data->beacon_data_length); uint8_t *b_data = ns_dyn_mem_temporary_alloc(data->beacon_data_length);
if( !b_data ){ if (!b_data) {
return; return;
} }
uint16_t b_len = data->beacon_data_length; uint16_t b_len = data->beacon_data_length;
@ -119,7 +119,7 @@ void beacon_received(int8_t if_id, const mlme_beacon_ind_t* data)
uint8_t join_priority; uint8_t join_priority;
if (beacon_join_priority_tlv_val_get(b_len, b_data, PLAIN_BEACON_PAYLOAD_SIZE, &join_priority)) { if (beacon_join_priority_tlv_val_get(b_len, b_data, PLAIN_BEACON_PAYLOAD_SIZE, &join_priority)) {
lqi = interface->mac_parameters->beacon_compare_rx_cb_ptr( lqi = interface->mac_parameters->beacon_compare_rx_cb_ptr(
interface->id, join_priority, data->PANDescriptor.LinkQuality); interface->id, join_priority, data->PANDescriptor.LinkQuality);
} }
} }
@ -131,10 +131,10 @@ void beacon_received(int8_t if_id, const mlme_beacon_ind_t* data)
while (cur) { while (cur) {
cur_desc = cur->pan_descriptor; cur_desc = cur->pan_descriptor;
if (cur_desc->LogicalChannel == data->PANDescriptor.LogicalChannel && if (cur_desc->LogicalChannel == data->PANDescriptor.LogicalChannel &&
cur_desc->CoordPANId == data->PANDescriptor.CoordPANId) { cur_desc->CoordPANId == data->PANDescriptor.CoordPANId) {
//Compare address to primary we need to check that we are not storage same parent twice FHSS //Compare address to primary we need to check that we are not storage same parent twice FHSS
if (memcmp(cur_desc->CoordAddress,data->PANDescriptor.CoordAddress , 8) == 0) { if (memcmp(cur_desc->CoordAddress, data->PANDescriptor.CoordAddress, 8) == 0) {
//Update allways better LQI //Update allways better LQI
if (cur_desc->LinkQuality < lqi) { if (cur_desc->LinkQuality < lqi) {
cur_desc->LinkQuality = lqi; cur_desc->LinkQuality = lqi;
@ -154,7 +154,7 @@ void beacon_received(int8_t if_id, const mlme_beacon_ind_t* data)
} }
ns_dyn_mem_free(cur->beacon_payload); ns_dyn_mem_free(cur->beacon_payload);
cur->beacon_payload = temp_payload; cur->beacon_payload = temp_payload;
memcpy(cur->beacon_payload, b_data,b_len); memcpy(cur->beacon_payload, b_data, b_len);
} else { } else {
ns_dyn_mem_free(cur->beacon_payload); ns_dyn_mem_free(cur->beacon_payload);
cur->beacon_payload = NULL; cur->beacon_payload = NULL;
@ -195,7 +195,7 @@ void beacon_received(int8_t if_id, const mlme_beacon_ind_t* data)
} }
new_entry->pan_descriptor = duplicate_pan_descriptor(&data->PANDescriptor); new_entry->pan_descriptor = duplicate_pan_descriptor(&data->PANDescriptor);
if( !new_entry->pan_descriptor ){ if (!new_entry->pan_descriptor) {
ns_dyn_mem_free(new_entry->beacon_payload); ns_dyn_mem_free(new_entry->beacon_payload);
ns_dyn_mem_free(new_entry); ns_dyn_mem_free(new_entry);
return; return;
@ -214,7 +214,7 @@ void beacon_received(int8_t if_id, const mlme_beacon_ind_t* data)
} }
new_entry->pan_descriptor = duplicate_pan_descriptor(&data->PANDescriptor); new_entry->pan_descriptor = duplicate_pan_descriptor(&data->PANDescriptor);
if( !new_entry->pan_descriptor ){ if (!new_entry->pan_descriptor) {
ns_dyn_mem_free(new_entry->beacon_payload); ns_dyn_mem_free(new_entry->beacon_payload);
ns_dyn_mem_free(new_entry); ns_dyn_mem_free(new_entry);
return; return;
@ -256,7 +256,7 @@ static bool beacon_join_priority_tlv_add(uint8_t len, uint8_t *ptr, uint8_t offs
{ {
// Invalid length // Invalid length
if (len < offset + BEACON_OPTION_JOIN_PRIORITY_LEN) { if (len < offset + BEACON_OPTION_JOIN_PRIORITY_LEN) {
return false; return false;
} }
ptr += offset; ptr += offset;
@ -273,7 +273,8 @@ static bool beacon_join_priority_tlv_add(uint8_t len, uint8_t *ptr, uint8_t offs
return true; 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)); nwk_pan_descriptor_t *description = ns_dyn_mem_temporary_alloc(sizeof(nwk_pan_descriptor_t));
if (description) { if (description) {
memset(description, 0, sizeof(nwk_pan_descriptor_t)); memset(description, 0, sizeof(nwk_pan_descriptor_t));
@ -300,7 +301,7 @@ static uint8_t *beacon_optional_tlv_field_get(uint8_t len, uint8_t *ptr, uint8_t
tlv_ptr = ptr + offset + tlvs_len; tlv_ptr = ptr + offset + tlvs_len;
if (*tlv_ptr == BEACON_OPTION_END_DELIMITER) { if (*tlv_ptr == BEACON_OPTION_END_DELIMITER) {
break; break;
// If TLV is found // If TLV is found
} else if (*tlv_ptr >> 4 == type) { } else if (*tlv_ptr >> 4 == type) {
// Validates TLV length // Validates TLV length
if (len >= offset + tlvs_len + 1 + (*tlv_ptr & 0x0F)) { if (len >= offset + tlvs_len + 1 + (*tlv_ptr & 0x0F)) {
@ -320,7 +321,7 @@ static uint8_t *beacon_optional_tlv_field_get(uint8_t len, uint8_t *ptr, uint8_t
static mlme_pan_descriptor_t *duplicate_pan_descriptor(const mlme_pan_descriptor_t *desc) static mlme_pan_descriptor_t *duplicate_pan_descriptor(const mlme_pan_descriptor_t *desc)
{ {
mlme_pan_descriptor_t *ret = ns_dyn_mem_temporary_alloc(sizeof(mlme_pan_descriptor_t)); mlme_pan_descriptor_t *ret = ns_dyn_mem_temporary_alloc(sizeof(mlme_pan_descriptor_t));
if(!ret){ if (!ret) {
return NULL; return NULL;
} }
memset(ret, 0, sizeof(mlme_pan_descriptor_t)); memset(ret, 0, sizeof(mlme_pan_descriptor_t));
@ -407,7 +408,7 @@ void beacon_join_priority_update(int8_t interface_id)
protocol_interface_info_entry_t *interface = protocol_stack_interface_info_get_by_id(interface_id); protocol_interface_info_entry_t *interface = protocol_stack_interface_info_get_by_id(interface_id);
if (!interface || !interface->mac_parameters || if (!interface || !interface->mac_parameters ||
!interface->mac_parameters->beacon_join_priority_tx_cb_ptr) { !interface->mac_parameters->beacon_join_priority_tx_cb_ptr) {
return; return;
} }

View File

@ -38,9 +38,9 @@ void beacon_optional_tlv_fields_skip(uint16_t *len, uint8_t **ptr, uint8_t offse
/* Beacon */ /* Beacon */
int8_t mac_beacon_link_beacon_compare_rx_callback_set(int8_t interface_id, int8_t mac_beacon_link_beacon_compare_rx_callback_set(int8_t interface_id,
beacon_compare_rx_cb *beacon_compare_rx_cb_ptr); beacon_compare_rx_cb *beacon_compare_rx_cb_ptr);
int8_t mac_beacon_link_beacon_join_priority_tx_callback_set(int8_t interface_id, int8_t mac_beacon_link_beacon_join_priority_tx_callback_set(int8_t interface_id,
beacon_join_priority_tx_cb *beacon_join_priority_tx_cb_ptr); beacon_join_priority_tx_cb *beacon_join_priority_tx_cb_ptr);
void beacon_join_priority_update(int8_t interface_id); void beacon_join_priority_update(int8_t interface_id);

View File

@ -94,7 +94,7 @@ static int8_t host_link_configuration(bool rx_on_idle, protocol_interface_info_e
mac_helper_pib_boolean_set(cur, macRxOnWhenIdle, rx_on_idle); mac_helper_pib_boolean_set(cur, macRxOnWhenIdle, rx_on_idle);
if (thread_info(cur)) { if (thread_info(cur)) {
if(rx_on_idle != backUp_bool){ if (rx_on_idle != backUp_bool) {
//If mode have been changed, send child update //If mode have been changed, send child update
thread_bootstrap_child_update_trig(cur); thread_bootstrap_child_update_trig(cur);
} }
@ -229,7 +229,7 @@ void mac_data_poll_disable(struct protocol_interface_info_entry *cur)
void mac_data_poll_enable_check(protocol_interface_info_entry_t *cur) void mac_data_poll_enable_check(protocol_interface_info_entry_t *cur)
{ {
if (!cur || !cur->rfd_poll_info ) { if (!cur || !cur->rfd_poll_info) {
return; return;
} }
@ -252,7 +252,7 @@ int8_t mac_data_poll_host_mode_get(struct protocol_interface_info_entry *cur, ne
void mac_poll_timer_trig(uint32_t poll_time, protocol_interface_info_entry_t *cur) void mac_poll_timer_trig(uint32_t poll_time, protocol_interface_info_entry_t *cur)
{ {
if( !cur ){ if (!cur) {
return; return;
} }
eventOS_event_timer_cancel(cur->id, mac_data_poll_tasklet); eventOS_event_timer_cancel(cur->id, mac_data_poll_tasklet);
@ -262,19 +262,19 @@ void mac_poll_timer_trig(uint32_t poll_time, protocol_interface_info_entry_t *cu
if (poll_time < 20) { if (poll_time < 20) {
arm_event_s event = { arm_event_s event = {
.receiver = mac_data_poll_tasklet, .receiver = mac_data_poll_tasklet,
.sender = mac_data_poll_tasklet, .sender = mac_data_poll_tasklet,
.event_id = cur->id, .event_id = cur->id,
.data_ptr = NULL, .data_ptr = NULL,
.event_type = MAC_DATA_POLL_REQUEST_EVENT, .event_type = MAC_DATA_POLL_REQUEST_EVENT,
.priority = ARM_LIB_MED_PRIORITY_EVENT, .priority = ARM_LIB_MED_PRIORITY_EVENT,
}; };
if (eventOS_event_send(&event) != 0) { if (eventOS_event_send(&event) != 0) {
tr_error("eventOS_event_send() failed"); tr_error("eventOS_event_send() failed");
} }
} else { } else {
if (eventOS_event_timer_request(cur->id, MAC_DATA_POLL_REQUEST_EVENT, mac_data_poll_tasklet, poll_time)!= 0) { if (eventOS_event_timer_request(cur->id, MAC_DATA_POLL_REQUEST_EVENT, mac_data_poll_tasklet, poll_time) != 0) {
tr_error("Poll Timer start Fail"); tr_error("Poll Timer start Fail");
} }
} }
@ -302,13 +302,13 @@ static mac_neighbor_table_entry_t *neighbor_data_poll_referesh(protocol_interfac
void mac_mlme_poll_confirm(protocol_interface_info_entry_t *cur, const mlme_poll_conf_t *confirm) void mac_mlme_poll_confirm(protocol_interface_info_entry_t *cur, const mlme_poll_conf_t *confirm)
{ {
if( !cur || !confirm ){ if (!cur || !confirm) {
return; return;
} }
uint32_t poll_time = 1; uint32_t poll_time = 1;
nwk_rfd_poll_setups_s *rf_ptr = cur->rfd_poll_info; nwk_rfd_poll_setups_s *rf_ptr = cur->rfd_poll_info;
if( !rf_ptr ){ if (!rf_ptr) {
return; return;
} }
@ -344,7 +344,7 @@ void mac_mlme_poll_confirm(protocol_interface_info_entry_t *cur, const mlme_poll
//tr_debug("Parent Poll Fail"); //tr_debug("Parent Poll Fail");
poll_time = 0; poll_time = 0;
rf_ptr->nwk_parent_poll_fail = 0; rf_ptr->nwk_parent_poll_fail = 0;
if( rf_ptr->pollFailCb ){ if (rf_ptr->pollFailCb) {
rf_ptr->pollFailCb(cur->id); rf_ptr->pollFailCb(cur->id);
} }
} else { } else {
@ -392,7 +392,7 @@ static void mac_data_poll_cb_run(int8_t interface_id)
if (cur->mac_api && cur->mac_api->mlme_req) { if (cur->mac_api && cur->mac_api->mlme_req) {
rf_ptr->pollActive = true; rf_ptr->pollActive = true;
cur->mac_api->mlme_req(cur->mac_api, MLME_POLL, (void*) &rf_ptr->poll_req); cur->mac_api->mlme_req(cur->mac_api, MLME_POLL, (void *) &rf_ptr->poll_req);
} else { } else {
tr_error("MAC not registered to interface"); tr_error("MAC not registered to interface");
} }
@ -401,13 +401,13 @@ static void mac_data_poll_cb_run(int8_t interface_id)
int8_t mac_data_poll_host_mode_set(struct protocol_interface_info_entry *cur, net_host_mode_t mode, uint32_t poll_time) int8_t mac_data_poll_host_mode_set(struct protocol_interface_info_entry *cur, net_host_mode_t mode, uint32_t poll_time)
{ {
#ifndef NO_MLE #ifndef NO_MLE
if( !cur){ if (!cur) {
return -1; return -1;
} }
int8_t ret_val = 0; int8_t ret_val = 0;
nwk_rfd_poll_setups_s *rf_ptr = cur->rfd_poll_info; nwk_rfd_poll_setups_s *rf_ptr = cur->rfd_poll_info;
//Check IF Bootsrap Ready and type is Host //Check IF Bootsrap Ready and type is Host
if (!rf_ptr ) { if (!rf_ptr) {
return -1; return -1;
} }
@ -520,7 +520,7 @@ void mac_data_poll_init(struct protocol_interface_info_entry *cur)
nwk_rfd_poll_setups_s *rfd_ptr = cur->rfd_poll_info; nwk_rfd_poll_setups_s *rfd_ptr = cur->rfd_poll_info;
if (!rfd_ptr) { if (!rfd_ptr) {
if (mac_data_poll_tasklet_init() < 0 ) { if (mac_data_poll_tasklet_init() < 0) {
tr_error("Mac data poll tasklet init fail"); tr_error("Mac data poll tasklet init fail");
} else { } else {
rfd_ptr = ns_dyn_mem_alloc(sizeof(nwk_rfd_poll_setups_s)); rfd_ptr = ns_dyn_mem_alloc(sizeof(nwk_rfd_poll_setups_s));

View File

@ -29,7 +29,7 @@
#define TRACE_GROUP "MACh" #define TRACE_GROUP "MACh"
static const uint8_t mac_helper_default_key_source[8] = {0xff,0,0,0,0,0,0,0}; static const uint8_t mac_helper_default_key_source[8] = {0xff, 0, 0, 0, 0, 0, 0, 0};
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);
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);
@ -51,13 +51,13 @@ static int8_t mac_helper_pib_8bit_set(protocol_interface_info_entry_t *interface
break; break;
} }
if (interface->mac_api && interface->mac_api->mlme_req ) { if (interface->mac_api && interface->mac_api->mlme_req) {
mlme_set_t set_req; mlme_set_t set_req;
set_req.attr = attribute; set_req.attr = attribute;
set_req.attr_index = 0; set_req.attr_index = 0;
set_req.value_pointer = &value; set_req.value_pointer = &value;
set_req.value_size = 1; set_req.value_size = 1;
interface->mac_api->mlme_req(interface->mac_api,MLME_SET , &set_req); interface->mac_api->mlme_req(interface->mac_api, MLME_SET, &set_req);
} }
return 0; return 0;
@ -65,7 +65,7 @@ static int8_t mac_helper_pib_8bit_set(protocol_interface_info_entry_t *interface
void mac_create_scan_request(mac_scan_type_t type, channel_list_s *chanlist, uint8_t scan_duration, mlme_scan_t *request) void mac_create_scan_request(mac_scan_type_t type, channel_list_s *chanlist, uint8_t scan_duration, mlme_scan_t *request)
{ {
if( !chanlist || !request ){ if (!chanlist || !request) {
return; return;
} }
@ -93,7 +93,7 @@ nwk_pan_descriptor_t *mac_helper_select_best_lqi(nwk_pan_descriptor_t *list)
void mac_helper_drop_selected_from_the_scanresult(nwk_scan_params_t *scanParams, nwk_pan_descriptor_t *selected) void mac_helper_drop_selected_from_the_scanresult(nwk_scan_params_t *scanParams, nwk_pan_descriptor_t *selected)
{ {
if( !scanParams || !selected ){ if (!scanParams || !selected) {
return; return;
} }
nwk_pan_descriptor_t *cur; nwk_pan_descriptor_t *cur;
@ -122,7 +122,7 @@ void mac_helper_drop_selected_from_the_scanresult(nwk_scan_params_t *scanParams,
void mac_helper_free_scan_confirm(nwk_scan_params_t *params) void mac_helper_free_scan_confirm(nwk_scan_params_t *params)
{ {
if( !params ){ if (!params) {
return; return;
} }
if (params->nwk_scan_res_size) { if (params->nwk_scan_res_size) {
@ -142,7 +142,7 @@ void mac_helper_free_scan_confirm(nwk_scan_params_t *params)
params->nwk_cur_active = mac_helper_free_pan_descriptions(params->nwk_cur_active); params->nwk_cur_active = mac_helper_free_pan_descriptions(params->nwk_cur_active);
} }
nwk_pan_descriptor_t * mac_helper_free_pan_descriptions(nwk_pan_descriptor_t *nwk_cur_active) nwk_pan_descriptor_t *mac_helper_free_pan_descriptions(nwk_pan_descriptor_t *nwk_cur_active)
{ {
if (nwk_cur_active) { if (nwk_cur_active) {
ns_dyn_mem_free(nwk_cur_active->pan_descriptor); ns_dyn_mem_free(nwk_cur_active->pan_descriptor);
@ -154,7 +154,7 @@ nwk_pan_descriptor_t * mac_helper_free_pan_descriptions(nwk_pan_descriptor_t *nw
int8_t mac_helper_nwk_id_filter_set(const uint8_t *nw_id, nwk_filter_params_s *filter) int8_t mac_helper_nwk_id_filter_set(const uint8_t *nw_id, nwk_filter_params_s *filter)
{ {
if( !filter ){ if (!filter) {
return -1; return -1;
} }
int8_t ret_val = 0; int8_t ret_val = 0;
@ -182,7 +182,7 @@ void mac_helper_panid_set(protocol_interface_info_entry_t *interface, uint16_t p
set_req.attr_index = 0; set_req.attr_index = 0;
set_req.value_pointer = &panId; set_req.value_pointer = &panId;
set_req.value_size = 2; set_req.value_size = 2;
interface->mac_api->mlme_req(interface->mac_api,MLME_SET , &set_req); interface->mac_api->mlme_req(interface->mac_api, MLME_SET, &set_req);
} }
void mac_helper_mac16_address_set(protocol_interface_info_entry_t *interface, uint16_t mac16) void mac_helper_mac16_address_set(protocol_interface_info_entry_t *interface, uint16_t mac16)
@ -198,13 +198,13 @@ void mac_helper_mac16_address_set(protocol_interface_info_entry_t *interface, ui
set_req.attr_index = 0; set_req.attr_index = 0;
set_req.value_pointer = &mac16; set_req.value_pointer = &mac16;
set_req.value_size = 2; set_req.value_size = 2;
interface->mac_api->mlme_req(interface->mac_api,MLME_SET , &set_req); interface->mac_api->mlme_req(interface->mac_api, MLME_SET, &set_req);
} }
uint16_t mac_helper_mac16_address_get(const protocol_interface_info_entry_t *interface) uint16_t mac_helper_mac16_address_get(const protocol_interface_info_entry_t *interface)
{ {
uint16_t shortAddress = 0xfffe; uint16_t shortAddress = 0xfffe;
if (interface ) { if (interface) {
shortAddress = interface->mac_parameters->mac_short_address; shortAddress = interface->mac_parameters->mac_short_address;
} }
return shortAddress; return shortAddress;
@ -233,14 +233,14 @@ void mac_helper_set_default_key_source(protocol_interface_info_entry_t *interfac
{ {
mlme_set_t set_req; mlme_set_t set_req;
set_req.attr_index = 0; set_req.attr_index = 0;
set_req.value_pointer = (void*)mac_helper_default_key_source; set_req.value_pointer = (void *)mac_helper_default_key_source;
set_req.value_size = 8; set_req.value_size = 8;
//Set first default key source //Set first default key source
set_req.attr = macDefaultKeySource; set_req.attr = macDefaultKeySource;
interface->mac_api->mlme_req(interface->mac_api,MLME_SET , &set_req); interface->mac_api->mlme_req(interface->mac_api, MLME_SET, &set_req);
//Set first default key source //Set first default key source
set_req.attr = macAutoRequestKeySource; set_req.attr = macAutoRequestKeySource;
interface->mac_api->mlme_req(interface->mac_api,MLME_SET , &set_req); interface->mac_api->mlme_req(interface->mac_api, MLME_SET, &set_req);
} }
@ -252,7 +252,7 @@ void mac_helper_default_security_level_set(protocol_interface_info_entry_t *inte
} else { } else {
security_enabled = false; security_enabled = false;
} }
mac_helper_pib_8bit_set(interface,macAutoRequestSecurityLevel, securityLevel); mac_helper_pib_8bit_set(interface, macAutoRequestSecurityLevel, securityLevel);
mac_helper_pib_boolean_set(interface, macSecurityEnabled, security_enabled); mac_helper_pib_boolean_set(interface, macSecurityEnabled, security_enabled);
} }
@ -264,7 +264,7 @@ uint8_t mac_helper_default_security_level_get(protocol_interface_info_entry_t *i
void mac_helper_default_security_key_id_mode_set(protocol_interface_info_entry_t *interface, uint8_t keyIdMode) void mac_helper_default_security_key_id_mode_set(protocol_interface_info_entry_t *interface, uint8_t keyIdMode)
{ {
mac_helper_pib_8bit_set(interface,macAutoRequestKeyIdMode, keyIdMode); mac_helper_pib_8bit_set(interface, macAutoRequestKeyIdMode, keyIdMode);
} }
uint8_t mac_helper_default_security_key_id_mode_get(protocol_interface_info_entry_t *interface) uint8_t mac_helper_default_security_key_id_mode_get(protocol_interface_info_entry_t *interface)
@ -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_set_t set_req;
mlme_key_id_lookup_descriptor_t lookup_description; mlme_key_id_lookup_descriptor_t lookup_description;
mlme_key_descriptor_entry_t key_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); 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_set_t set_req;
mlme_key_id_lookup_descriptor_t lookup_description; mlme_key_id_lookup_descriptor_t lookup_description;
mlme_key_descriptor_entry_t key_description; mlme_key_descriptor_entry_t key_description;
@ -309,7 +311,7 @@ static void mac_helper_keytable_pairwise_descriptor_set(struct mac_api_s *api, c
memcpy(lookup_description.LookupData, mac64, 8); memcpy(lookup_description.LookupData, mac64, 8);
lookup_description.LookupData[8] = 0; lookup_description.LookupData[8] = 0;
lookup_description.LookupDataSize = 1; lookup_description.LookupDataSize = 1;
tr_debug("Key add %u index %s", attribute_id,trace_array(lookup_description.LookupData, 9)); tr_debug("Key add %u index %s", attribute_id, trace_array(lookup_description.LookupData, 9));
memset(&key_description, 0, sizeof(mlme_key_descriptor_entry_t)); memset(&key_description, 0, sizeof(mlme_key_descriptor_entry_t));
memcpy(key_description.Key, key, 16); memcpy(key_description.Key, key, 16);
key_description.KeyIdLookupList = &lookup_description; key_description.KeyIdLookupList = &lookup_description;
@ -322,7 +324,7 @@ static void mac_helper_keytable_pairwise_descriptor_set(struct mac_api_s *api, c
set_req.value_pointer = &key_description; set_req.value_pointer = &key_description;
set_req.value_size = sizeof(mlme_key_descriptor_entry_t); set_req.value_size = sizeof(mlme_key_descriptor_entry_t);
api->mlme_req(api,MLME_SET , &set_req); api->mlme_req(api, MLME_SET, &set_req);
} }
@ -332,7 +334,7 @@ int8_t mac_helper_security_default_key_set(protocol_interface_info_entry_t *inte
return -1; return -1;
} }
mac_helper_pib_8bit_set(interface,macAutoRequestKeyIndex, id); mac_helper_pib_8bit_set(interface, macAutoRequestKeyIndex, id);
mac_helper_keytable_descriptor_set(interface->mac_api, key, id, interface->mac_parameters->mac_default_key_attribute_id); mac_helper_keytable_descriptor_set(interface->mac_api, key, id, interface->mac_parameters->mac_default_key_attribute_id);
return 0; return 0;
} }
@ -398,12 +400,13 @@ void mac_helper_security_key_swap_next_to_default(protocol_interface_info_entry_
interface->mac_parameters->mac_next_key_index = 0; interface->mac_parameters->mac_next_key_index = 0;
interface->mac_parameters->mac_next_key_attribute_id = prev_attribute; interface->mac_parameters->mac_next_key_attribute_id = prev_attribute;
mac_helper_pib_8bit_set(interface,macAutoRequestKeyIndex, interface->mac_parameters->mac_default_key_index); mac_helper_pib_8bit_set(interface, macAutoRequestKeyIndex, interface->mac_parameters->mac_default_key_index);
} }
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 ) { {
if (interface->mac_api) {
mlme_set_t set_req; mlme_set_t set_req;
mlme_key_descriptor_entry_t key_description; mlme_key_descriptor_entry_t key_description;
memset(&key_description, 0, sizeof(mlme_key_descriptor_entry_t)); memset(&key_description, 0, sizeof(mlme_key_descriptor_entry_t));
@ -413,11 +416,11 @@ void mac_helper_security_key_clean(protocol_interface_info_entry_t *interface) {
set_req.value_pointer = &key_description; set_req.value_pointer = &key_description;
set_req.value_size = sizeof(mlme_key_descriptor_entry_t); set_req.value_size = sizeof(mlme_key_descriptor_entry_t);
set_req.attr_index = interface->mac_parameters->mac_prev_key_attribute_id; set_req.attr_index = interface->mac_parameters->mac_prev_key_attribute_id;
interface->mac_api->mlme_req(interface->mac_api,MLME_SET , &set_req); interface->mac_api->mlme_req(interface->mac_api, MLME_SET, &set_req);
set_req.attr_index = interface->mac_parameters->mac_default_key_attribute_id; set_req.attr_index = interface->mac_parameters->mac_default_key_attribute_id;
interface->mac_api->mlme_req(interface->mac_api,MLME_SET , &set_req); interface->mac_api->mlme_req(interface->mac_api, MLME_SET, &set_req);
set_req.attr_index = interface->mac_parameters->mac_next_key_attribute_id; set_req.attr_index = interface->mac_parameters->mac_next_key_attribute_id;
interface->mac_api->mlme_req(interface->mac_api,MLME_SET , &set_req); interface->mac_api->mlme_req(interface->mac_api, MLME_SET, &set_req);
} }
interface->mac_parameters->mac_prev_key_index = 0; interface->mac_parameters->mac_prev_key_index = 0;
interface->mac_parameters->mac_default_key_index = 0; interface->mac_parameters->mac_default_key_index = 0;
@ -445,7 +448,7 @@ void mac_helper_coordinator_address_set(protocol_interface_info_entry_t *interfa
} }
if (interface->mac_api) { if (interface->mac_api) {
interface->mac_api->mlme_req(interface->mac_api, MLME_SET , &set_req); interface->mac_api->mlme_req(interface->mac_api, MLME_SET, &set_req);
} }
} }
@ -457,10 +460,10 @@ addrtype_t mac_helper_coordinator_address_get(protocol_interface_info_entry_t *i
} }
if (interface->mac_parameters->mac_cordinator_info.cord_adr_mode == MAC_ADDR_MODE_16_BIT) { if (interface->mac_parameters->mac_cordinator_info.cord_adr_mode == MAC_ADDR_MODE_16_BIT) {
memcpy(adr_ptr,interface->mac_parameters->mac_cordinator_info.mac_mlme_coord_address, 2); memcpy(adr_ptr, interface->mac_parameters->mac_cordinator_info.mac_mlme_coord_address, 2);
ret = ADDR_802_15_4_SHORT; ret = ADDR_802_15_4_SHORT;
} else if (interface->mac_parameters->mac_cordinator_info.cord_adr_mode == MAC_ADDR_MODE_64_BIT) { } else if (interface->mac_parameters->mac_cordinator_info.cord_adr_mode == MAC_ADDR_MODE_64_BIT) {
memcpy(adr_ptr,interface->mac_parameters->mac_cordinator_info.mac_mlme_coord_address, 8); memcpy(adr_ptr, interface->mac_parameters->mac_cordinator_info.mac_mlme_coord_address, 8);
ret = ADDR_802_15_4_LONG; ret = ADDR_802_15_4_LONG;
} }
return ret; return ret;
@ -476,7 +479,7 @@ static void mac_helper_beacon_payload_length_set_to_mac(protocol_interface_info_
set_req.attr_index = 0; set_req.attr_index = 0;
set_req.value_pointer = &len; set_req.value_pointer = &len;
set_req.value_size = 1; set_req.value_size = 1;
interface->mac_api->mlme_req(interface->mac_api,MLME_SET , &set_req); interface->mac_api->mlme_req(interface->mac_api, MLME_SET, &set_req);
} }
} }
@ -488,7 +491,7 @@ static void mac_helper_beacon_payload_set_to_mac(protocol_interface_info_entry_t
set_req.attr_index = 0; set_req.attr_index = 0;
set_req.value_pointer = payload; set_req.value_pointer = payload;
set_req.value_size = length; set_req.value_size = length;
interface->mac_api->mlme_req(interface->mac_api,MLME_SET , &set_req); interface->mac_api->mlme_req(interface->mac_api, MLME_SET, &set_req);
} }
} }
@ -501,13 +504,13 @@ uint8_t *mac_helper_beacon_payload_reallocate(protocol_interface_info_entry_t *i
if (len == interface->mac_parameters->mac_beacon_payload_size) { if (len == interface->mac_parameters->mac_beacon_payload_size) {
// no change to size, return the existing buff // no change to size, return the existing buff
//Set allways length to zero for safe beacon payload manipulate //Set allways length to zero for safe beacon payload manipulate
mac_helper_beacon_payload_length_set_to_mac(interface,0); mac_helper_beacon_payload_length_set_to_mac(interface, 0);
return interface->mac_parameters->mac_beacon_payload; return interface->mac_parameters->mac_beacon_payload;
} }
if (len == 0) { if (len == 0) {
//SET MAC beacon payload to length to zero //SET MAC beacon payload to length to zero
mac_helper_beacon_payload_length_set_to_mac(interface,0); mac_helper_beacon_payload_length_set_to_mac(interface, 0);
ns_dyn_mem_free(interface->mac_parameters->mac_beacon_payload); ns_dyn_mem_free(interface->mac_parameters->mac_beacon_payload);
interface->mac_parameters->mac_beacon_payload = NULL; interface->mac_parameters->mac_beacon_payload = NULL;
interface->mac_parameters->mac_beacon_payload_size = 0; interface->mac_parameters->mac_beacon_payload_size = 0;
@ -516,7 +519,7 @@ uint8_t *mac_helper_beacon_payload_reallocate(protocol_interface_info_entry_t *i
tr_debug("mac_helper_beacon_payload_reallocate, old len: %d, new: %d", interface->mac_parameters->mac_beacon_payload_size, len); tr_debug("mac_helper_beacon_payload_reallocate, old len: %d, new: %d", interface->mac_parameters->mac_beacon_payload_size, len);
uint8_t* temp_buff = ns_dyn_mem_alloc(len); uint8_t *temp_buff = ns_dyn_mem_alloc(len);
if (temp_buff == NULL) { if (temp_buff == NULL) {
// no need to proceed, could not allocate more space // no need to proceed, could not allocate more space
@ -524,7 +527,7 @@ uint8_t *mac_helper_beacon_payload_reallocate(protocol_interface_info_entry_t *i
} }
//SET MAC beacon payload to length to zero //SET MAC beacon payload to length to zero
mac_helper_beacon_payload_length_set_to_mac(interface,0); mac_helper_beacon_payload_length_set_to_mac(interface, 0);
// copy data into new buffer before freeing old one // copy data into new buffer before freeing old one
if (interface->mac_parameters->mac_beacon_payload_size > 0) { if (interface->mac_parameters->mac_beacon_payload_size > 0) {
@ -610,7 +613,7 @@ int8_t mac_helper_pib_boolean_set(protocol_interface_info_entry_t *interface, ml
set_req.attr_index = 0; set_req.attr_index = 0;
set_req.value_pointer = &value; set_req.value_pointer = &value;
set_req.value_size = sizeof(bool); set_req.value_size = sizeof(bool);
interface->mac_api->mlme_req(interface->mac_api,MLME_SET , &set_req); interface->mac_api->mlme_req(interface->mac_api, MLME_SET, &set_req);
} }
return 0; return 0;
@ -622,13 +625,13 @@ int8_t mac_helper_mac_channel_set(protocol_interface_info_entry_t *interface, ui
if (interface->mac_parameters->mac_channel != new_channel) { if (interface->mac_parameters->mac_channel != new_channel) {
interface->mac_parameters->mac_channel = new_channel; interface->mac_parameters->mac_channel = new_channel;
if (interface->mac_api && interface->mac_api->mlme_req ) { if (interface->mac_api && interface->mac_api->mlme_req) {
mlme_set_t set_req; mlme_set_t set_req;
set_req.attr = phyCurrentChannel; set_req.attr = phyCurrentChannel;
set_req.attr_index = 0; set_req.attr_index = 0;
set_req.value_pointer = &new_channel; set_req.value_pointer = &new_channel;
set_req.value_size = 1; set_req.value_size = 1;
interface->mac_api->mlme_req(interface->mac_api,MLME_SET , &set_req); interface->mac_api->mlme_req(interface->mac_api, MLME_SET, &set_req);
} }
} }
return 0; return 0;
@ -673,7 +676,7 @@ bool mac_helper_write_our_addr(protocol_interface_info_entry_t *interface, socka
int8_t mac_helper_mac64_set(protocol_interface_info_entry_t *interface, const uint8_t *mac64) int8_t mac_helper_mac64_set(protocol_interface_info_entry_t *interface, const uint8_t *mac64)
{ {
memcpy(interface->mac, mac64, 8); memcpy(interface->mac, mac64, 8);
if (interface->mac_api ) { if (interface->mac_api) {
interface->mac_api->mac64_set(interface->mac_api, mac64); interface->mac_api->mac64_set(interface->mac_api, mac64);
} }
return 0; return 0;
@ -736,7 +739,8 @@ uint_fast8_t mac_helper_frame_overhead(protocol_interface_info_entry_t *cur, con
return length; 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; uint8_t mic_length;
switch (security_level) { switch (security_level) {
case SEC_MIC32: case SEC_MIC32:
@ -761,16 +765,17 @@ static uint8_t mac_helper_security_mic_length_get(uint8_t security_level) {
return mic_length; 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 uint8_t header_length = 5; //Header + 32-bit counter
switch (keyIdmode) { switch (keyIdmode) {
case MAC_KEY_ID_MODE_SRC8_IDX: case MAC_KEY_ID_MODE_SRC8_IDX:
header_length += 4; //64-bit key source first part header_length += 4; //64-bit key source first part
/* fall through */ /* fall through */
case MAC_KEY_ID_MODE_SRC4_IDX: case MAC_KEY_ID_MODE_SRC4_IDX:
header_length += 4; //32-bit key source inline header_length += 4; //32-bit key source inline
/* fall through */ /* fall through */
case MAC_KEY_ID_MODE_IDX: case MAC_KEY_ID_MODE_IDX:
header_length += 1; header_length += 1;
break; break;
@ -826,10 +831,10 @@ void mac_helper_devicetable_remove(mac_api_t *mac_api, uint8_t attribute_index)
set_req.attr = macDeviceTable; set_req.attr = macDeviceTable;
set_req.attr_index = attribute_index; set_req.attr_index = attribute_index;
set_req.value_pointer = (void*)&device_desc; set_req.value_pointer = (void *)&device_desc;
set_req.value_size = sizeof(mlme_device_descriptor_t); set_req.value_size = sizeof(mlme_device_descriptor_t);
tr_debug("unRegister Device"); tr_debug("unRegister Device");
mac_api->mlme_req(mac_api,MLME_SET , &set_req); mac_api->mlme_req(mac_api, MLME_SET, &set_req);
} }
void mac_helper_device_description_write(protocol_interface_info_entry_t *cur, mlme_device_descriptor_t *device_desc, uint8_t *mac64, uint16_t mac16, uint32_t frame_counter, bool exempt) void mac_helper_device_description_write(protocol_interface_info_entry_t *cur, mlme_device_descriptor_t *device_desc, uint8_t *mac64, uint16_t mac16, uint32_t frame_counter, bool exempt)
@ -856,10 +861,10 @@ void mac_helper_devicetable_set(const mlme_device_descriptor_t *device_desc, pro
mlme_set_t set_req; mlme_set_t set_req;
set_req.attr = macDeviceTable; set_req.attr = macDeviceTable;
set_req.attr_index = attribute_index; set_req.attr_index = attribute_index;
set_req.value_pointer = (void*)device_desc; set_req.value_pointer = (void *)device_desc;
set_req.value_size = sizeof(mlme_device_descriptor_t); set_req.value_size = sizeof(mlme_device_descriptor_t);
tr_debug("Register Device"); tr_debug("Register Device");
cur->mac_api->mlme_req(cur->mac_api,MLME_SET , &set_req); cur->mac_api->mlme_req(cur->mac_api, MLME_SET, &set_req);
} }

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