diff --git a/features/FEATURE_COMMON_PAL/nanostack-libservice/Makefile b/features/FEATURE_COMMON_PAL/nanostack-libservice/Makefile new file mode 100644 index 00000000000..24fd3418e93 --- /dev/null +++ b/features/FEATURE_COMMON_PAL/nanostack-libservice/Makefile @@ -0,0 +1,13 @@ +SRCS := \ +source/IPv6_fcf_lib/ip_fsc.c \ +source/libBits/common_functions.c \ +source/libip6string/ip6tos.c \ +source/libip6string/stoip6.c \ +source/libList/ns_list.c \ +source/nsdynmemLIB/nsdynmemLIB.c \ +source/nvmHelper/ns_nvm_helper.c \ + +LIB := libservice.a +EXPORT_HEADERS := mbed-client-libservice + +include ../exported_rules.mk diff --git a/features/FEATURE_COMMON_PAL/nanostack-libservice/mbed-client-libservice/common_functions.h b/features/FEATURE_COMMON_PAL/nanostack-libservice/mbed-client-libservice/common_functions.h index 77c52a5ab19..5caf17353b2 100644 --- a/features/FEATURE_COMMON_PAL/nanostack-libservice/mbed-client-libservice/common_functions.h +++ b/features/FEATURE_COMMON_PAL/nanostack-libservice/mbed-client-libservice/common_functions.h @@ -172,12 +172,41 @@ NS_INLINE uint_fast8_t common_count_bits(uint8_t byte); /* * Count leading zeros in a byte * + * \deprecated Use common_count_leading_zeros_8 + * * \param byte byte to inspect * * \return number of leading zeros in byte (0-8) */ NS_INLINE uint_fast8_t common_count_leading_zeros(uint8_t byte); +/* + * Count leading zeros in a byte + * + * \param byte byte to inspect + * + * \return number of leading zeros in byte (0-8) + */ +NS_INLINE uint_fast8_t common_count_leading_zeros_8(uint8_t byte); + +/* + * Count leading zeros in a 16-bit value + * + * \param value value to inspect + * + * \return number of leading zeros in byte (0-16) + */ +NS_INLINE uint_fast8_t common_count_leading_zeros_16(uint16_t value); + +/* + * Count leading zeros in a 32-bit value + * + * \param value value to inspect + * + * \return number of leading zeros in byte (0-32) + */ +NS_INLINE uint_fast8_t common_count_leading_zeros_32(uint32_t value); + /* * Compare 8-bit serial numbers * @@ -434,6 +463,11 @@ COMMON_FUNCTIONS_FN uint_fast8_t common_count_bits(uint8_t byte) } COMMON_FUNCTIONS_FN uint_fast8_t common_count_leading_zeros(uint8_t byte) +{ + return common_count_leading_zeros_8(byte); +} + +COMMON_FUNCTIONS_FN uint_fast8_t common_count_leading_zeros_8(uint8_t byte) { #ifdef __CC_ARM return byte ? __clz((unsigned int) byte << 24) : 8; @@ -460,6 +494,72 @@ COMMON_FUNCTIONS_FN uint_fast8_t common_count_leading_zeros(uint8_t byte) #endif } +COMMON_FUNCTIONS_FN uint_fast8_t common_count_leading_zeros_16(uint16_t value) +{ +#ifdef __CC_ARM + return value ? __clz((unsigned int) value << 16) : 16; +#elif defined __GNUC__ + return value ? __builtin_clz((unsigned int) value << 16) : 16; +#else + uint_fast8_t cnt = 0; + if (value == 0) { + return 16; + } + if ((value & 0xFF00) == 0) { + value <<= 8; + cnt += 8; + } + if ((value & 0xF000) == 0) { + value <<= 4; + cnt += 4; + } + if ((value & 0xC000) == 0) { + value <<= 2; + cnt += 2; + } + if ((value & 0x8000) == 0) { + cnt += 1; + } + + return cnt; +#endif +} + +COMMON_FUNCTIONS_FN uint_fast8_t common_count_leading_zeros_32(uint32_t value) +{ +#ifdef __CC_ARM + return __clz(value); +#elif defined __GNUC__ + return value ? __builtin_clz(value) : 32; +#else + uint_fast8_t cnt = 0; + if (value == 0) { + return 32; + } + if ((value & 0xFFFF0000) == 0) { + value <<= 16; + cnt += 16; + } + if ((value & 0xFF000000) == 0) { + value <<= 8; + cnt += 8; + } + if ((value & 0xF0000000) == 0) { + value <<= 4; + cnt += 4; + } + if ((value & 0xC0000000) == 0) { + value <<= 2; + cnt += 2; + } + if ((value & 0x80000000) == 0) { + cnt += 1; + } + + return cnt; +#endif +} + COMMON_FUNCTIONS_FN bool common_serial_number_greater_8(uint8_t s1, uint8_t s2) { return (s1 > s2 && s1 - s2 < UINT8_C(0x80)) || (s1 < s2 && s2 - s1 > UINT8_C(0x80)); diff --git a/features/FEATURE_COMMON_PAL/nanostack-libservice/mbed-client-libservice/ip6string.h b/features/FEATURE_COMMON_PAL/nanostack-libservice/mbed-client-libservice/ip6string.h index e54469ed794..bf1f339c763 100644 --- a/features/FEATURE_COMMON_PAL/nanostack-libservice/mbed-client-libservice/ip6string.h +++ b/features/FEATURE_COMMON_PAL/nanostack-libservice/mbed-client-libservice/ip6string.h @@ -20,6 +20,9 @@ extern "C" { #endif #include "ns_types.h" + +#define MAX_IPV6_STRING_LEN_WITH_TRAILING_NULL 40 + /** * Print binary IPv6 address to a string. * diff --git a/features/FEATURE_COMMON_PAL/nanostack-libservice/mbed-client-libservice/ns_trace.h b/features/FEATURE_COMMON_PAL/nanostack-libservice/mbed-client-libservice/ns_trace.h index 517e8858ff2..206e2399827 100644 --- a/features/FEATURE_COMMON_PAL/nanostack-libservice/mbed-client-libservice/ns_trace.h +++ b/features/FEATURE_COMMON_PAL/nanostack-libservice/mbed-client-libservice/ns_trace.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 ARM Limited. All rights reserved. + * Copyright (c) 2015-2017 ARM Limited. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * Licensed under the Apache License, Version 2.0 (the License); you may * not use this file except in compliance with the License. @@ -16,38 +16,13 @@ /** * \file ns_trace.h - * Trace interface for NanoStack library as well as application. - * This file provide simple but flexible way to handle software traces. - * Trace library are abstract layer, which use stdout (printf) by default, - * but outputs can be easily redirect to custom function, for example to - * store traces to memory or other interfaces. + * Trace interface abstraction for NanoStack library as well as application. * - * usage example: - * \code(main.c:) - * #include "ns_trace.h" - * #define TRACE_GROUP "main" - * - * int main(void){ - * trace_init(); // initialize trace library - * tr_debug("this is debug msg"); //print debug message to stdout: "[DBG] - * tr_err("this is error msg"); - * tr_warn("this is warning msg"); - * tr_info("this is info msg"); - * return 0; - * } - * \endcode + * Actual used trace library is mbed-trace. For usage details check mbed_trace.h. * */ #ifndef NS_TRACE_H_ #define NS_TRACE_H_ -#include "ns_types.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define NS_TRACE_USE_MBED_TRACE -#if defined(NS_TRACE_USE_MBED_TRACE) #if defined(HAVE_DEBUG) && !defined(FEA_TRACE_SUPPORT) #define FEA_TRACE_SUPPORT @@ -55,333 +30,4 @@ extern "C" { #include "mbed-trace/mbed_trace.h" - -/* Convert libTrace calls to mbed-trace calls */ -#define trace_init() mbed_trace_init() -#define trace_free() mbed_trace_free() -#define set_trace_config(config) mbed_trace_config_set(config) -#define get_trace_config() mbed_trace_config_get() -#define set_trace_prefix_function(pref_f) mbed_trace_prefix_function_set(pref_f) -#define set_trace_suffix_function(suffix_f) mbed_trace_suffix_function_set(suffix_f) -#define set_trace_print_function(print_f) mbed_trace_print_function_set(print_f) -#define set_trace_cmdprint_function(printf) mbed_trace_cmdprint_function_set(printf) -#define set_trace_exclude_filters(filters) mbed_trace_exclude_filters_set(filters) -#define set_trace_include_filters(filters) mbed_trace_include_filters_set(filters) -#define get_trace_exclude_filters() mbed_trace_exclude_filters_get() -#define get_trace_include_filters() mbed_trace_include_filters_get() -#define trace_last() mbed_trace_last() - - -/* Definitions for the old functions with no equivalents in mbed-trace. These work without any special init. - * */ -#if defined(FEA_TRACE_SUPPORT) || defined(HAVE_DEBUG) || (defined(YOTTA_CFG) && !defined(NDEBUG)) /*backward compatible*/ -#if defined __GNUC__ || defined __CC_ARM -/** obsolete function */ -void debugf(const char *fmt, ...) __attribute__ ((__format__(__printf__, 1, 2))); //!< obsolete function -void debug(const char *s); //!< obsolete function -void debug_put(char c); //!< obsolete function -void debug_hex(uint8_t x); //!< obsolete function -void debug_int(int i); //!< obsolete function -void printf_array(const void *buf, uint16_t len); //!< obsolete function -void printf_string(const void *buf, uint16_t len); //!< obsolete function -void printf_ipv6_address(const void *addr); //!< obsolete function -#else //__GNUC__ || __CC_ARM -//obsolete functions: -void debugf(const char *fmt, ...); -void debug(const char *s); -void debug_put(char c); -void debug_hex(uint8_t x); -void debug_int(int i); -void printf_array(const void *buf, uint16_t len); -void printf_string(const void *buf, uint16_t len); -void printf_ipv6_address(const void *addr); -#endif -#else /*FEA_TRACE_SUPPORT*/ -// trace functionality not supported -//obsolete -#define debugf(...) ((void) 0) -#define debug(s) ((void) 0) -#define debug_put(c) ((void) 0) -#define debug_hex(x) ((void) 0) -#define debug_int(i) ((void) 0) -#define printf_array(buf, len) ((void) 0) -#define printf_string(buf, len) ((void) 0) -#define printf_ipv6_address(addr) ((void) 0) - -#endif /*FEA_TRACE_SUPPORT*/ - -#else /* NS_TRACE_USE_MBED_TRACE */ - -/** 3 upper bits are trace modes related, - and 5 lower bits are trace level configuration */ - -/** Config mask */ -#define TRACE_MASK_CONFIG 0xE0 -/** Trace level mask */ -#define TRACE_MASK_LEVEL 0x1F - -/** plain trace data instead of "headers" */ -#define TRACE_MODE_PLAIN 0x80 -/** color mode */ -#define TRACE_MODE_COLOR 0x40 -/** Use print CR before trace line */ -#define TRACE_CARRIAGE_RETURN 0x20 - -/** used to activate all trace levels */ -#define TRACE_ACTIVE_LEVEL_ALL 0x1F -/** print all traces same as above */ -#define TRACE_ACTIVE_LEVEL_DEBUG 0x1f -/** print info,warn and error traces */ -#define TRACE_ACTIVE_LEVEL_INFO 0x0f -/** print warn and error traces */ -#define TRACE_ACTIVE_LEVEL_WARN 0x07 -/** print only error trace */ -#define TRACE_ACTIVE_LEVEL_ERROR 0x03 -/** print only cmd line data */ -#define TRACE_ACTIVE_LEVEL_CMD 0x01 -/** trace nothing */ -#define TRACE_ACTIVE_LEVEL_NONE 0x00 - -/** this print is some deep information for debug purpose */ -#define TRACE_LEVEL_DEBUG 0x10 -/** Info print, for general purpose prints */ -#define TRACE_LEVEL_INFO 0x08 -/** warning prints, which shouldn't causes any huge problems */ -#define TRACE_LEVEL_WARN 0x04 -/** Error prints, which causes probably problems, e.g. out of mem. */ -#define TRACE_LEVEL_ERROR 0x02 -/** special level for cmdline. Behaviours like "plain mode" */ -#define TRACE_LEVEL_CMD 0x01 - -//usage macros: -#define tr_info(...) tracef(TRACE_LEVEL_INFO, TRACE_GROUP, __VA_ARGS__) //!< Print info message -#define tr_debug(...) tracef(TRACE_LEVEL_DEBUG, TRACE_GROUP, __VA_ARGS__) //!< Print debug message -#define tr_warning(...) tracef(TRACE_LEVEL_WARN, TRACE_GROUP, __VA_ARGS__) //!< Print warning message -#define tr_warn(...) tracef(TRACE_LEVEL_WARN, TRACE_GROUP, __VA_ARGS__) //!< Alternative warning message -#define tr_error(...) tracef(TRACE_LEVEL_ERROR, TRACE_GROUP, __VA_ARGS__) //!< Print Error Message -#define tr_err(...) tracef(TRACE_LEVEL_ERROR, TRACE_GROUP, __VA_ARGS__) //!< Alternative error message -#define tr_cmdline(...) tracef(TRACE_LEVEL_CMD, TRACE_GROUP, __VA_ARGS__) //!< Special print for cmdline. See more from TRACE_LEVEL_CMD -level - -/** Possible to skip all traces in compile time */ -#if defined(FEA_TRACE_SUPPORT) || defined(HAVE_DEBUG) || (defined(YOTTA_CFG) && !defined(NDEBUG)) /*backward compatible*/ - -#if defined __GNUC__ || defined __CC_ARM -/** - * Initialize trace functionality. This method must be called from application process. - * @return 0 when all success, otherwise non zero - */ -int trace_init( void ); -/** - * Free trace memory. This method must be called from application process. - */ -void trace_free( void ); -/** - * Set trace configurations - * Possible parameters: - * - * TRACE_MODE_COLOR - * TRACE_MODE_PLAIN (this exclude color mode) - * TRACE_CARRIAGE_RETURN (print CR before trace line) - * - * TRACE_ACTIVE_LEVEL_ALL - to activate all trace levels - * or TRACE_ACTIVE_LEVEL_DEBUG (alternative) - * TRACE_ACTIVE_LEVEL_INFO - * TRACE_ACTIVE_LEVEL_WARN - * TRACE_ACTIVE_LEVEL_ERROR - * TRACE_ACTIVE_LEVEL_CMD - * TRACE_LEVEL_NONE - to deactivate all traces - * - * @param config Byte size Bit-mask. Bits are descripted above. - * usage e.g. - * @code - * set_trace_config( TRACE_ACTIVE_LEVEL_ALL|TRACE_MODE_COLOR ); - * @endcode - */ -void set_trace_config(uint8_t config); -/** get trace configurations - * @return trace configuration byte - */ -uint8_t get_trace_config(void); -/** - * Set trace prefix function - * pref_f -function return string with null terminated - * Can be used for e.g. time string - * e.g. - * char* trace_time(){ return "rtc-time-in-string"; } - * set_trace_prefix_function( &trace_time ); - */ -void set_trace_prefix_function( char* (*pref_f)(size_t) ); -/** - * Set trace suffix function - * suffix -function return string with null terminated - * Can be used for e.g. time string - * e.g. - * char* trace_suffix(){ return " END"; } - * set_trace_suffix_function( &trace_suffix ); - */ -void set_trace_suffix_function(char* (*suffix_f)(void) ); -/** - * Set trace print function - * By default, trace module print using printf() function, - * but with this you can write own print function, - * for e.g. to other IO device. - */ -void set_trace_print_function( void (*print_f)(const char*) ); -/** - * Set trace print function for tr_cmdline() - */ -void set_trace_cmdprint_function( void (*printf)(const char*) ); -/** - * When trace group contains text in filters, - * trace print will be ignored. - * e.g.: - * set_trace_exclude_filters("mygr"); - * tracef(TRACE_ACTIVE_LEVEL_DEBUG, "ougr", "This is not printed"); - */ -void set_trace_exclude_filters(char* filters); -/** get trace exclude filters - */ -const char* get_trace_exclude_filters(void); -/** - * When trace group contains text in filter, - * trace will be printed. - * e.g.: - * set_trace_include_filters("mygr"); - * tracef(TRACE_ACTIVE_LEVEL_DEBUG, "mygr", "Hi There"); - * tracef(TRACE_ACTIVE_LEVEL_DEBUG, "grp2", "This is not printed"); - */ -void set_trace_include_filters(char* filters); -/** get trace include filters - */ -const char* get_trace_include_filters(void); -/** - * General trace function - * This should be used every time when user want to print out something important thing - * Usage e.g. - * tracef( TRACE_LEVEL_INFO, "mygr", "Hello world!"); - * - * @param dlevel debug level - * @param grp trace group - * @param fmt trace format (like printf) - * @param ... variable arguments related to fmt - */ -void tracef(uint8_t dlevel, const char* grp, const char *fmt, ...) __attribute__ ((__format__(__printf__, 3, 4))); -/** - * Get last trace from buffer - */ -const char* trace_last(void); -/** - * tracef helping function for convert ipv6 - * table to human readable string. - * usage e.g. - * char ipv6[16] = {...}; // ! array length is 16 bytes ! - * tracef(TRACE_LEVEL_INFO, "mygr", "ipv6 addr: %s", trace_ipv6(ipv6)); - * - * @param add_ptr IPv6 Address pointer - * @return temporary buffer where ipv6 is in string format - */ -char* trace_ipv6(const void *addr_ptr); -/** - * tracef helping function for print ipv6 prefix - * usage e.g. - * char ipv6[16] = {...}; // ! array length is 16 bytes ! - * tracef(TRACE_LEVEL_INFO, "mygr", "ipv6 addr: %s", trace_ipv6_prefix(ipv6, 4)); - * - * @param prefix IPv6 Address pointer - * @param prefix_len prefix length - * @return temporary buffer where ipv6 is in string format - */ -char* trace_ipv6_prefix(const uint8_t *prefix, uint8_t prefix_len); -/** - * tracef helping function for convert hex-array to string. - * usage e.g. - * char myarr[] = {0x10, 0x20}; - * tracef(TRACE_LEVEL_INFO, "mygr", "arr: %s", trace_array(myarr, 2)); - * - * @param buf hex array pointer - * @param len buffer length - * @return temporary buffer where string copied - */ -char* trace_array(const uint8_t* buf, uint16_t len); - - -/* - * obsolete - only because of backward compatible reason - * As soon as all these functions are replaced by new tracef() function, these can be removed. - */ - -/** obsolete function */ -void debugf(const char *fmt, ...) __attribute__ ((__format__(__printf__, 1, 2))); //!< obsolete function -void debug(const char *s); //!< obsolete function -void debug_put(char c); //!< obsolete function -void debug_hex(uint8_t x); //!< obsolete function -void debug_int(int i); //!< obsolete function -void printf_array(const void *buf, uint16_t len); //!< obsolete function -void printf_string(const void *buf, uint16_t len); //!< obsolete function -void printf_ipv6_address(const void *addr); //!< obsolete function - -#else //__GNUC__ || __CC_ARM -int trace_init( void ); -void trace_free( void ); -void set_trace_config(uint8_t config); -void set_trace_prefix_function( char* (*pref_f)(size_t) ); -void set_trace_print_function( void (*print_f)(const char*) ); -void set_trace_cmdprint_function( void (*printf)(const char*) ); -void set_trace_exclude_filters(char* filters); -const char* get_trace_exclude_filters(void); -void set_trace_include_filters(char* filters); -const char* get_trace_include_filters(void); -void tracef(uint8_t dlevel, const char* grp, const char *fmt, ...); -char* trace_ipv6(const void *addr_ptr); -char* trace_array(const uint8_t* buf, uint16_t len); -char* trace_ipv6_prefix(const uint8_t *prefix, uint8_t prefix_len); - -//obsolete functions: -void debugf(const char *fmt, ...); -void debug(const char *s); -void debug_put(char c); -void debug_hex(uint8_t x); -void debug_int(int i); -void printf_array(const void *buf, uint16_t len); -void printf_string(const void *buf, uint16_t len); -void printf_ipv6_address(const void *addr); - -#endif - - -#else /*FEA_TRACE_SUPPORT*/ - -// trace functionality not supported -#define trace_init(...) ((int) 0) -#define trace_free(...) ((void) 0) -#define set_trace_config(...) ((void) 0) -#define set_trace_prefix_function(...) ((void) 0) -#define set_trace_print_function(...) ((void) 0) -#define set_trace_cmdprint_function(...) ((void) 0) -#define set_trace_exclude_filters(...) ((void) 0) -#define set_trace_include_filters(...) ((void) 0) -#define get_trace_exclude_filters(...) ((const char*) 0) -#define get_trace_include_filters(...) ((const char*) 0) - -#define tracef(...) ((void) 0) -#define trace_ipv6(...) ((char*) 0) -#define trace_array(...) ((char*) 0) -#define trace_ipv6_prefix(...) ((char*) 0) - -//obsolete -#define debugf(...) ((void) 0) -#define debug(s) ((void) 0) -#define debug_put(c) ((void) 0) -#define debug_hex(x) ((void) 0) -#define debug_int(i) ((void) 0) -#define printf_array(buf, len) ((void) 0) -#define printf_string(buf, len) ((void) 0) -#define printf_ipv6_address(addr) ((void) 0) - -#endif /*FEA_TRACE_SUPPORT*/ -#endif /* NS_TRACE_USE_MBED_TRACE */ - -#ifdef __cplusplus -} -#endif #endif /* NS_TRACE_H_ */ diff --git a/features/FEATURE_COMMON_PAL/nanostack-libservice/mbed-client-libservice/ns_types.h b/features/FEATURE_COMMON_PAL/nanostack-libservice/mbed-client-libservice/ns_types.h index b89ea4b818d..61b31f3dc06 100644 --- a/features/FEATURE_COMMON_PAL/nanostack-libservice/mbed-client-libservice/ns_types.h +++ b/features/FEATURE_COMMON_PAL/nanostack-libservice/mbed-client-libservice/ns_types.h @@ -62,7 +62,7 @@ * to use them, as they could exist and be more efficient than 32-bit on 8-bit * systems...) */ -#ifndef UINT24_LEAST_MAX +#ifndef UINT_LEAST24_MAX typedef uint_least32_t uint_least24_t; #define UINT_LEAST24_MAX UINT_LEAST32_MAX #define UINT24_C(x) UINT32_C(x) @@ -72,16 +72,16 @@ typedef uint_least32_t uint_least24_t; #define PRIXLEAST24 PRIXLEAST32 #endif -#ifndef INT24_LEAST_MAX +#ifndef INT_LEAST24_MAX typedef int_least32_t int_least24_t; -#define INT24_LEAST_MIN INT_LEAST32_MIN -#define INT24_LEAST_MAX INT_LEAST32_MAX +#define INT_LEAST24_MIN INT_LEAST32_MIN +#define INT_LEAST24_MAX INT_LEAST32_MAX #define INT24_C(x) INT32_C(x) #define PRIdLEAST24 PRIdLEAST32 #define PRIiLEAST24 PRIiLEAST32 #endif -#ifndef UINT24_FAST_MAX +#ifndef UINT_FAST24_MAX typedef uint_fast32_t uint_fast24_t; #define UINT_FAST24_MAX UINT_FAST32_MAX #define PRIoFAST24 PRIoFAST32 @@ -90,7 +90,7 @@ typedef uint_fast32_t uint_fast24_t; #define PRIXFAST24 PRIXFAST32 #endif -#ifndef INT24_FAST_MAX +#ifndef INT_FAST24_MAX typedef int_fast32_t int_fast24_t; #define INT_FAST24_MIN INT_FAST32_MIN #define INT_FAST24_MAX INT_FAST32_MAX diff --git a/features/FEATURE_COMMON_PAL/nanostack-libservice/source/libTrace/ns_trace.c b/features/FEATURE_COMMON_PAL/nanostack-libservice/source/libTrace/ns_trace.c deleted file mode 100644 index 750d9be2c44..00000000000 --- a/features/FEATURE_COMMON_PAL/nanostack-libservice/source/libTrace/ns_trace.c +++ /dev/null @@ -1,552 +0,0 @@ -/* - * Copyright (c) 2014-2015 ARM Limited. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 - * Licensed under the Apache License, Version 2.0 (the License); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#include -#include -#include -#include - -#define HAVE_DEBUG 1 - -#include "ns_trace.h" -#include "ip6string.h" -#include "common_functions.h" - -#if defined(_WIN32) || defined(__unix__) || defined(__unix) || defined(unix) || (defined(YOTTA_CFG) && !defined(NDEBUG)) -//NOTE! It is not allowed to use this MEM_ALLOC/MEM_FREE from interrupt context. -#ifndef MEM_ALLOC -#define MEM_ALLOC malloc -#endif -#ifndef MEM_FREE -#define MEM_FREE free -#endif -#else -#include "nsdynmemLIB.h" -#ifndef MEM_ALLOC -#define MEM_ALLOC ns_dyn_mem_alloc -#endif -#ifndef MEM_FREE -#define MEM_FREE ns_dyn_mem_free -#endif -#endif - -#ifndef NS_TRACE_USE_MBED_TRACE - -#define VT100_COLOR_ERROR "\x1b[31m" -#define VT100_COLOR_WARN "\x1b[33m" -#define VT100_COLOR_INFO "\x1b[39m" -#define VT100_COLOR_DEBUG "\x1b[90m" - -/** default max trace line size in bytes */ -#define DEFAULT_TRACE_LINE_LENGTH 1024 -/** default max temporary buffer size in bytes, used in - trace_ipv6, trace_array and trace_strn */ -#define DEFAULT_TRACE_TMP_LINE_LEN 512 -/** default max filters (include/exclude) length in bytes */ -#define DEFAULT_TRACE_FILTER_LENGTH 24 - -/** default print function, just redirect str to printf */ -static void default_print(const char *str); - -typedef struct { - /** trace configuration bits */ - uint8_t trace_config; - /** exclude filters list, related group name */ - char *filters_exclude; - /** include filters list, related group name */ - char *filters_include; - /** Filters length */ - int filters_length; - /** trace line */ - char *line; - /** trace line length */ - int line_length; - /** temporary data */ - char *tmp_data; - /** temporary data array length */ - int tmp_data_length; - /** temporary data pointer */ - char *tmp_data_ptr; - - /** prefix function, which can be used to put time to the trace line */ - char *(*prefix_f)(size_t); - /** suffix function, which can be used to some string to the end of trace line */ - char *(*suffix_f)(void); - /** print out function. Can be redirect to flash for example. */ - void (*printf)(const char *); - /** print out function for TRACE_LEVEL_CMD */ - void (*cmd_printf)(const char *); -} trace_s; - -static trace_s m_trace = { - .filters_exclude = 0, - .filters_include = 0, - .line = 0, - .tmp_data = 0, - .prefix_f = 0, - .suffix_f = 0, - .printf = 0, - .cmd_printf = 0 -}; - -int trace_init(void) -{ - m_trace.trace_config = TRACE_MODE_COLOR | TRACE_ACTIVE_LEVEL_ALL | TRACE_CARRIAGE_RETURN; - m_trace.line_length = DEFAULT_TRACE_LINE_LENGTH; - if (m_trace.line == NULL) { - m_trace.line = MEM_ALLOC(m_trace.line_length); - } - m_trace.tmp_data_length = DEFAULT_TRACE_TMP_LINE_LEN; - if (m_trace.tmp_data == NULL) { - m_trace.tmp_data = MEM_ALLOC(m_trace.tmp_data_length); - } - m_trace.tmp_data_ptr = m_trace.tmp_data; - m_trace.filters_length = DEFAULT_TRACE_FILTER_LENGTH; - if (m_trace.filters_exclude == NULL) { - m_trace.filters_exclude = MEM_ALLOC(m_trace.filters_length); - } - if (m_trace.filters_include == NULL) { - m_trace.filters_include = MEM_ALLOC(m_trace.filters_length); - } - - if (m_trace.line == NULL || - m_trace.tmp_data == NULL || - m_trace.filters_exclude == NULL || - m_trace.filters_include == NULL) { - //memory allocation fail - trace_free(); - return -1; - } - memset(m_trace.tmp_data, 0, m_trace.tmp_data_length); - memset(m_trace.filters_exclude, 0, m_trace.filters_length); - memset(m_trace.filters_include, 0, m_trace.filters_length); - memset(m_trace.line, 0, m_trace.line_length); - - m_trace.prefix_f = 0; - m_trace.suffix_f = 0; - m_trace.printf = default_print; - m_trace.cmd_printf = 0; - - return 0; -} -void trace_free(void) -{ - MEM_FREE(m_trace.line); - m_trace.line_length = 0; - m_trace.line = 0; - MEM_FREE(m_trace.tmp_data); - m_trace.tmp_data = 0; - m_trace.tmp_data_ptr = 0; - MEM_FREE(m_trace.filters_exclude); - m_trace.filters_exclude = 0; - MEM_FREE(m_trace.filters_include); - m_trace.filters_include = 0; - m_trace.filters_length = 0; -} -/** @TODO do we need dynamically change trace buffer sizes ? -// reconfigure trace buffer sizes -void set_trace_buffer_sizes(int lineLength, int tmpLength) -{ - REALLOC( m_trace.line, dataLength ); - REALLOC( m_trace.tmp_data, tmpLength); - m_trace.tmp_data_length = tmpLength; -} -*/ -void set_trace_config(uint8_t config) -{ - m_trace.trace_config = config; -} -uint8_t get_trace_config(void) -{ - return m_trace.trace_config; -} -void set_trace_prefix_function(char *(*pref_f)(size_t)) -{ - m_trace.prefix_f = pref_f; -} -void set_trace_suffix_function(char *(*suffix_f)(void)) -{ - m_trace.suffix_f = suffix_f; -} -void set_trace_print_function(void (*printf)(const char *)) -{ - m_trace.printf = printf; -} -void set_trace_cmdprint_function(void (*printf)(const char *)) -{ - m_trace.cmd_printf = printf; -} -void set_trace_exclude_filters(char *filters) -{ - if (filters) { - (void)strncpy(m_trace.filters_exclude, filters, m_trace.filters_length); - } else { - m_trace.filters_exclude[0] = 0; - } -} -const char *get_trace_exclude_filters(void) -{ - return m_trace.filters_exclude; -} -const char *get_trace_include_filters(void) -{ - return m_trace.filters_include; -} -void set_trace_include_filters(char *filters) -{ - if (filters) { - (void)strncpy(m_trace.filters_include, filters, m_trace.filters_length); - } else { - m_trace.filters_include[0] = 0; - } -} -static int8_t trace_skip(int8_t dlevel, const char *grp) -{ - if (dlevel >= 0 && grp != 0) { - // filter debug prints only when dlevel is >0 and grp is given - - /// @TODO this could be much better.. - if (m_trace.filters_exclude[0] != '\0' && - strstr(m_trace.filters_exclude, grp) != 0) { - //grp was in exclude list - return 1; - } - if (m_trace.filters_include[0] != '\0' && - strstr(m_trace.filters_include, grp) == 0) { - //grp was in include list - return 1; - } - } - return 0; -} -static void default_print(const char *str) -{ - puts(str); -} -void tracef(uint8_t dlevel, const char *grp, const char *fmt, ...) -{ - if (m_trace.line == NULL) { - // Quite likely the trace_init() has not been called yet, - // but it is better to just shut up instead of crashing with - // null pointer dereference. - m_trace.tmp_data_ptr = m_trace.tmp_data; - return; - } - - m_trace.line[0] = 0; //by default trace is empty - if (trace_skip(dlevel, grp) || fmt == 0 || grp == 0) { - m_trace.tmp_data_ptr = m_trace.tmp_data; - return; - } - if ((m_trace.trace_config & TRACE_MASK_LEVEL) & dlevel) { - bool color = (m_trace.trace_config & TRACE_MODE_COLOR) != 0; - bool plain = (m_trace.trace_config & TRACE_MODE_PLAIN) != 0; - bool cr = (m_trace.trace_config & TRACE_CARRIAGE_RETURN) != 0; - //printf("CFG: 0x%02x, plain: %i, color: %i, cr: %i\n", m_trace.trace_config, plain, color, cr); - - int retval = 0, bLeft = m_trace.line_length; - char *ptr = m_trace.line; - if (plain == true || dlevel == TRACE_LEVEL_CMD) { - va_list ap; - va_start(ap, fmt); - //add trace data - retval = vsnprintf(ptr, bLeft, fmt, ap); - va_end(ap); - if (dlevel == TRACE_LEVEL_CMD && m_trace.cmd_printf) { - m_trace.cmd_printf(m_trace.line); - m_trace.cmd_printf("\n"); - } else { - //print out whole data - m_trace.printf(m_trace.line); - } - } else { - if (color) { - if (cr) { - retval = snprintf(ptr, bLeft, "\r\x1b[2K"); - if (retval >= bLeft) { - retval = 0; - } - if (retval > 0) { - ptr += retval; - bLeft -= retval; - } - } - if (bLeft > 0) { - //include color in ANSI/VT100 escape code - switch (dlevel) { - case (TRACE_LEVEL_ERROR): - retval = snprintf(ptr, bLeft, "%s", VT100_COLOR_ERROR); - break; - case (TRACE_LEVEL_WARN): - retval = snprintf(ptr, bLeft, "%s", VT100_COLOR_WARN); - break; - case (TRACE_LEVEL_INFO): - retval = snprintf(ptr, bLeft, "%s", VT100_COLOR_INFO); - break; - case (TRACE_LEVEL_DEBUG): - retval = snprintf(ptr, bLeft, "%s", VT100_COLOR_DEBUG); - break; - default: - color = 0; //avoid unneeded color-terminate code - retval = 0; - break; - } - if (retval >= bLeft) { - retval = 0; - } - if (retval > 0 && color) { - ptr += retval; - bLeft -= retval; - } - } - - } - if (bLeft > 0 && m_trace.prefix_f) { - va_list ap; - va_start(ap, fmt); - //find out length of body - size_t sz = 0; - sz = vsnprintf(NULL, 0, fmt, ap) + retval + (retval ? 4 : 0); - //add prefix string - retval = snprintf(ptr, bLeft, "%s", m_trace.prefix_f(sz)); - if (retval >= bLeft) { - retval = 0; - } - if (retval > 0) { - ptr += retval; - bLeft -= retval; - } - va_end(ap); - } - if (bLeft > 0) { - //add group tag - switch (dlevel) { - case (TRACE_LEVEL_ERROR): - retval = snprintf(ptr, bLeft, "[ERR ][%-4s]: ", grp); - break; - case (TRACE_LEVEL_WARN): - retval = snprintf(ptr, bLeft, "[WARN][%-4s]: ", grp); - break; - case (TRACE_LEVEL_INFO): - retval = snprintf(ptr, bLeft, "[INFO][%-4s]: ", grp); - break; - case (TRACE_LEVEL_DEBUG): - retval = snprintf(ptr, bLeft, "[DBG ][%-4s]: ", grp); - break; - default: - retval = snprintf(ptr, bLeft, " "); - break; - } - if (retval >= bLeft) { - retval = 0; - } - if (retval > 0) { - ptr += retval; - bLeft -= retval; - } - } - if (retval > 0 && bLeft > 0) { - va_list ap; - va_start(ap, fmt); - //add trace text - retval = vsnprintf(ptr, bLeft, fmt, ap); - if (retval >= bLeft) { - retval = 0; - } - if (retval > 0) { - ptr += retval; - bLeft -= retval; - } - va_end(ap); - } - - if (retval > 0 && bLeft > 0 && m_trace.suffix_f) { - //add suffix string - retval = snprintf(ptr, bLeft, "%s", m_trace.suffix_f()); - if (retval >= bLeft) { - retval = 0; - } - if (retval > 0) { - ptr += retval; - bLeft -= retval; - } - } - - if (retval > 0 && bLeft > 0 && color) { - //add zero color VT100 when color mode - retval = snprintf(ptr, bLeft, "\x1b[0m"); - if (retval >= bLeft) { - retval = 0; - } - if (retval > 0) { - ptr += retval; - bLeft -= retval; - } - } - //print out whole data - m_trace.printf(m_trace.line); - } - //return tmp data pointer back to the beginning - } - m_trace.tmp_data_ptr = m_trace.tmp_data; -} -const char *trace_last(void) -{ - return m_trace.line; -} -/* Helping functions */ -#define tmp_data_left() m_trace.tmp_data_length-(m_trace.tmp_data_ptr-m_trace.tmp_data) -char *trace_ipv6(const void *addr_ptr) -{ - char *str = m_trace.tmp_data_ptr; - if (str == NULL) { - return ""; - } - if (tmp_data_left() < 41) { - return ""; - } - if (addr_ptr == NULL) { - return ""; - } - str[0] = 0; - ip6tos(addr_ptr, str); - m_trace.tmp_data_ptr += strlen(str) + 1; - return str; -} -char *trace_ipv6_prefix(const uint8_t *prefix, uint8_t prefix_len) -{ - char *str = m_trace.tmp_data_ptr; - int retval, bLeft = tmp_data_left(); - char tmp[40]; - uint8_t addr[16] = {0}; - - if (str == NULL) { - return ""; - } - if (bLeft < 40 + 1 + 3 + 1) {// "ipv6 addr" + "/" + "128" + nul - return ""; - } - - if (prefix_len != 0) { - if (prefix == NULL || prefix_len > 128) { - return ""; - } - bitcopy(addr, prefix, prefix_len); - } - - ip6tos(addr, tmp); - retval = snprintf(str, bLeft, "%s/%u", tmp, prefix_len); - if (retval <= 0 || retval > bLeft) { - return ""; - } - - m_trace.tmp_data_ptr += retval + 1; - return str; -} -char *trace_array(const uint8_t *buf, uint16_t len) -{ - int i, retval, bLeft = tmp_data_left(); - char *str, *wptr; - str = m_trace.tmp_data_ptr; - if (str == NULL || bLeft == 0) { - return ""; - } - if (buf == NULL) { - return ""; - } - if (!bLeft) { - return ""; - } - wptr = str; - wptr[0] = 0; - const uint8_t *ptr = buf; - char overflow = 0; - for (i = 0; i < len; i++) { - if (bLeft <= 3) { - overflow = 1; - break; - } - retval = snprintf(wptr, bLeft, "%02x:", *ptr++); - if (retval <= 0 || retval > bLeft) { - break; - } - bLeft -= retval; - wptr += retval; - } - if (wptr > str) { - if( overflow ) { - // replace last character as 'star', - // which indicate buffer len is not enough - *(wptr - 1) = '*'; - } else { - //null to replace last ':' character - *(wptr - 1) = 0; - } - } - m_trace.tmp_data_ptr = wptr; - return str; -} -#endif /* NS_TRACE_USE_MBED_TRACE */ - -// rest of debug print functions will be obsolete and will be overridden with new trace interface.. -void debugf(const char *fmt, ...) -{ - va_list ap; - va_start(ap, fmt); - vprintf(fmt, ap); - va_end(ap); -} - -void debug(const char *s) -{ - fputs(s, stdout); -} - -void debug_put(char c) -{ - putchar(c); -} - -void debug_hex(uint8_t x) -{ - printf("%02x", x); -} -void debug_int(int i) -{ - printf("%d", i); -} -void printf_array(const void *buf , uint16_t len) -{ - int i; - const uint8_t *ptr = buf; - for (i = 0; i < len; i++) { - if (i && (0 == i % 16)) { - putchar('\n'); - } - printf("%02x:", *ptr++); - - } - putchar('\n'); -} -void printf_ipv6_address(const void *addr_ptr) -{ - char buf[40] = {0}; - ip6tos(addr_ptr, buf); - printf("%s\n", buf); -} -void printf_string(const void *ptr, uint16_t len) -{ - printf("%.*s\n", len, (const char *)ptr); -} diff --git a/features/FEATURE_COMMON_PAL/nanostack-libservice/source/libip6string/stoip6.c b/features/FEATURE_COMMON_PAL/nanostack-libservice/source/libip6string/stoip6.c index 1bdf58fe21a..8e6f705a546 100644 --- a/features/FEATURE_COMMON_PAL/nanostack-libservice/source/libip6string/stoip6.c +++ b/features/FEATURE_COMMON_PAL/nanostack-libservice/source/libip6string/stoip6.c @@ -41,7 +41,7 @@ void stoip6(const char *ip6addr, size_t len, void *dest) } // First go forward the string, until end, noting :: position if any - for (field_no = 0, p = ip6addr; (len > (p - ip6addr)) && *p && field_no < 8; p = q + 1) { + for (field_no = 0, p = ip6addr; (len > (size_t)(p - ip6addr)) && *p && field_no < 8; p = q + 1) { q = p; // Seek for ':' or end while (*q && (*q != ':')) { @@ -51,7 +51,7 @@ void stoip6(const char *ip6addr, size_t len, void *dest) addr = common_write_16_bit(hex(p), addr); field_no++; //Check if we reached "::" - if ((len > (q - ip6addr)) && *q && (q[0] == ':') && (q[1] == ':')) { + if ((len > (size_t)(q - ip6addr)) && *q && (q[0] == ':') && (q[1] == ':')) { coloncolon = field_no; q++; } diff --git a/features/FEATURE_COMMON_PAL/nanostack-libservice/source/nsdynmemLIB/nsdynmemLIB.c b/features/FEATURE_COMMON_PAL/nanostack-libservice/source/nsdynmemLIB/nsdynmemLIB.c index 9f41e347966..32218d7dfe8 100644 --- a/features/FEATURE_COMMON_PAL/nanostack-libservice/source/nsdynmemLIB/nsdynmemLIB.c +++ b/features/FEATURE_COMMON_PAL/nanostack-libservice/source/nsdynmemLIB/nsdynmemLIB.c @@ -144,7 +144,7 @@ static int convert_allocation_size(int16_t requested_bytes) heap_failure(NS_DYN_MEM_HEAP_SECTOR_UNITIALIZED); } else if (requested_bytes < 1) { heap_failure(NS_DYN_MEM_ALLOCATE_SIZE_NOT_VALID); - } else if (requested_bytes > (heap_size - 2 * sizeof(int)) ) { + } else if ((size_t)requested_bytes > (heap_size - 2 * sizeof(int)) ) { heap_failure(NS_DYN_MEM_ALLOCATE_SIZE_NOT_VALID); } return (requested_bytes + sizeof(int) - 1) / sizeof(int); @@ -153,8 +153,7 @@ static int convert_allocation_size(int16_t requested_bytes) // Checks that block length indicators are valid // Block has format: Size of data area [1 word] | data area [abs(size) words]| Size of data area [1 word] // If Size is negative it means area is unallocated -// For direction, use 1 for direction up and -1 for down -static int8_t ns_block_validate(int *block_start, int direction) +static int8_t ns_block_validate(int *block_start) { int8_t ret_val = -1; int *end = block_start; @@ -188,7 +187,7 @@ static void *ns_dyn_mem_internal_alloc(const int16_t alloc_size, int direction) : ns_list_get_previous(&holes_list, cur_hole) ) { int *p = block_start_from_hole(cur_hole); - if (ns_block_validate(p, direction) != 0 || *p >= 0) { + if (ns_block_validate(p) != 0 || *p >= 0) { //Validation failed, or this supposed hole has positive (allocated) size heap_failure(NS_DYN_MEM_HEAP_SECTOR_CORRUPTED); break; @@ -204,7 +203,7 @@ static void *ns_dyn_mem_internal_alloc(const int16_t alloc_size, int direction) goto done; } - int block_data_size = -*block_ptr; + size_t block_data_size = -*block_ptr; if (block_data_size >= (data_size + 2 + HOLE_T_SIZE)) { int hole_size = block_data_size - data_size - 2; int *hole_ptr; @@ -274,7 +273,7 @@ void *ns_dyn_mem_temporary_alloc(int16_t alloc_size) } #ifndef STANDARD_MALLOC -static void ns_free_and_merge_with_adjacent_blocks(int *cur_block, int data_size) +static void ns_free_and_merge_with_adjacent_blocks(int * const cur_block, int data_size) { // Theory of operation: Block is always in form | Len | Data | Len | // So we need to check length of previous (if current not heap start) @@ -286,32 +285,37 @@ static void ns_free_and_merge_with_adjacent_blocks(int *cur_block, int data_size int *start = cur_block; int *end = cur_block + data_size + 1; //invalidate current block - *cur_block = -data_size; + *start = -data_size; *end = -data_size; - int merged_data_size = data_size; - - if (cur_block != heap_main) { - cur_block--; - if (*cur_block < 0) { - merged_data_size += (2 - *cur_block); - start -= (2 - *cur_block); - if (-*start >= HOLE_T_SIZE) { + size_t merged_data_size = data_size; + + if (start != heap_main) { + if (*(start - 1) < 0) { + int *block_end = start - 1; + size_t block_size = 1 + (-*block_end) + 1; + merged_data_size += block_size; + start -= block_size; + if (*start != *block_end) { + heap_failure(NS_DYN_MEM_HEAP_SECTOR_CORRUPTED); + } + if (block_size >= 1 + HOLE_T_SIZE + 1) { existing_start = hole_from_block_start(start); } } - cur_block++; } if (end != heap_main_end) { - end++; - if (*end < 0) { - merged_data_size += (2 - *end); - if (-*end >= HOLE_T_SIZE) { - existing_end = hole_from_block_start(end); + if (*(end + 1) < 0) { + int *block_start = end + 1; + size_t block_size = 1 + (-*block_start) + 1; + merged_data_size += block_size; + end += block_size; + if (*end != *block_start) { + heap_failure(NS_DYN_MEM_HEAP_SECTOR_CORRUPTED); + } + if (block_size >= 1 + HOLE_T_SIZE + 1) { + existing_end = hole_from_block_start(block_start); } - end += (1 - *end); - }else{ - end--; } } @@ -382,7 +386,7 @@ void ns_dyn_mem_free(void *block) } else if ((ptr + size) >= heap_main_end) { heap_failure(NS_DYN_MEM_POINTER_NOT_VALID); } else { - if (ns_block_validate(ptr, 1) != 0) { + if (ns_block_validate(ptr) != 0) { heap_failure(NS_DYN_MEM_HEAP_SECTOR_CORRUPTED); } else { ns_free_and_merge_with_adjacent_blocks(ptr, size); diff --git a/features/FEATURE_COMMON_PAL/nanostack-libservice/source/nvmHelper/ns_nvm_helper.c b/features/FEATURE_COMMON_PAL/nanostack-libservice/source/nvmHelper/ns_nvm_helper.c index 75cf77ae19b..c7671e9172d 100644 --- a/features/FEATURE_COMMON_PAL/nanostack-libservice/source/nvmHelper/ns_nvm_helper.c +++ b/features/FEATURE_COMMON_PAL/nanostack-libservice/source/nvmHelper/ns_nvm_helper.c @@ -5,8 +5,6 @@ #include #include #include -#define HAVE_DEBUG -#include "ns_trace.h" #include "ns_list.h" #include "platform/arm_hal_nvm.h" #include "ns_nvm_helper.h" @@ -93,7 +91,6 @@ int ns_nvm_key_delete(ns_nvm_callback *callback, const char *key_name, void *con if (!callback || !key_name) { return NS_NVM_ERROR; } - tr_debug("ns_nvm_key_delete() key=%s, ctx=%p", key_name, context); ns_nvm_request_t *ns_nvm_request_ptr = ns_nvm_create_request(callback, context, key_name, NULL, NULL, NS_NVM_KEY_DELETE); return ns_nvm_operation_start(ns_nvm_request_ptr); } @@ -103,7 +100,6 @@ int ns_nvm_data_read(ns_nvm_callback *callback, const char *key_name, uint8_t *b if (!callback || !key_name || !buf || !buf_len) { return NS_NVM_ERROR; } - tr_debug("ns_nvm_data_read() key=%s, len=%d, ctx=%p", key_name, (int)*buf_len, context); ns_nvm_request_t *ns_nvm_request_ptr = ns_nvm_create_request(callback, context, key_name, buf, buf_len, NS_NVM_KEY_READ); return ns_nvm_operation_start(ns_nvm_request_ptr); } @@ -113,7 +109,6 @@ int ns_nvm_data_write(ns_nvm_callback *callback, const char *key_name, uint8_t * if (!callback || !key_name || !buf || !buf_len) { return NS_NVM_ERROR; } - tr_debug("ns_nvm_data_write() key=%s, len=%d, ctx=%p", key_name, (int)*buf_len, context); ns_nvm_request_t *ns_nvm_request_ptr = ns_nvm_create_request(callback, context, key_name, buf, buf_len, NS_NVM_KEY_WRITE); return ns_nvm_operation_start(ns_nvm_request_ptr); } diff --git a/features/FEATURE_COMMON_PAL/nanostack-libservice/test/libService/unittest/Makefile b/features/FEATURE_COMMON_PAL/nanostack-libservice/test/libService/unittest/Makefile new file mode 100755 index 00000000000..b353517548f --- /dev/null +++ b/features/FEATURE_COMMON_PAL/nanostack-libservice/test/libService/unittest/Makefile @@ -0,0 +1,23 @@ +#scan for folders having "Makefile" in them and remove 'this' to prevent loop +ifeq ($(OS),Windows_NT) +all: +clean: +else +DIRS := $(filter-out ./, $(sort $(dir $(shell find . -name 'Makefile')))) + +all: + for dir in $(DIRS); do \ + cd $$dir; make gcov; cd ..;\ + done + +clean: + for dir in $(DIRS); do \ + cd $$dir; make clean; cd ..;\ + done + rm -rf ../source/*gcov ../source/*gcda ../source/*o + rm -rf stubs/*gcov stubs/*gcda stubs/*o + rm -rf results/* + rm -rf coverages/* + rm -rf results + rm -rf coverages +endif diff --git a/features/FEATURE_COMMON_PAL/nanostack-libservice/test/libService/unittest/MakefileWorker.mk b/features/FEATURE_COMMON_PAL/nanostack-libservice/test/libService/unittest/MakefileWorker.mk old mode 100644 new mode 100755 diff --git a/features/FEATURE_COMMON_PAL/nanostack-libservice/test/libService/unittest/ip6tos/Makefile b/features/FEATURE_COMMON_PAL/nanostack-libservice/test/libService/unittest/ip6tos/Makefile new file mode 100644 index 00000000000..7ec8277d7cf --- /dev/null +++ b/features/FEATURE_COMMON_PAL/nanostack-libservice/test/libService/unittest/ip6tos/Makefile @@ -0,0 +1,21 @@ +include ../makefile_defines.txt + +COMPONENT_NAME = ip6tos_unit +SRC_FILES = \ + ../../../../source/libip6string/ip6tos.c + +TEST_SRC_FILES = \ + main.cpp \ + ip6tos_test.cpp \ + ../../../../source/libBits/common_functions.c +# ../stubs/some_stub.c \ + +# XXX: without this, the CppUTest complains for memory leak even without one. +# The funny thing is that the CppUTest does not find the memory leak on +# this app when there actually is one. +CPPUTEST_USE_MEM_LEAK_DETECTION = N + +include ../MakefileWorker.mk + +CPPUTESTFLAGS += -DFEA_TRACE_SUPPORT + diff --git a/features/FEATURE_COMMON_PAL/nanostack-libservice/test/libService/unittest/libTrace/libtracetest.cpp b/features/FEATURE_COMMON_PAL/nanostack-libservice/test/libService/unittest/libTrace/libtracetest.cpp deleted file mode 100644 index 604080b8bde..00000000000 --- a/features/FEATURE_COMMON_PAL/nanostack-libservice/test/libService/unittest/libTrace/libtracetest.cpp +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2015 ARM Limited. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 - * Licensed under the Apache License, Version 2.0 (the License); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -//CppUTest includes should be after your and system includes -#include "CppUTest/TestHarness.h" -#include "test_libtrace.h" - -TEST_GROUP(LibTrace) -{ - Test_LibTrace *lib_trace; - - void setup() { - lib_trace = new Test_LibTrace(); - } - - void teardown() { - delete lib_trace; - } -}; - -TEST(LibTrace, Create) -{ - CHECK(lib_trace != NULL); -} - -TEST(LibTrace, test_libTrace_tracef) -{ - lib_trace->test_libTrace_tracef(); -} - -TEST(LibTrace, test_libTrace_trace_ipv6_prefix) -{ - lib_trace->test_libTrace_trace_ipv6_prefix(); -} diff --git a/features/FEATURE_COMMON_PAL/nanostack-libservice/test/libService/unittest/libTrace/main.cpp b/features/FEATURE_COMMON_PAL/nanostack-libservice/test/libService/unittest/libTrace/main.cpp deleted file mode 100644 index cd7ce87ce1b..00000000000 --- a/features/FEATURE_COMMON_PAL/nanostack-libservice/test/libService/unittest/libTrace/main.cpp +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (c) 2015 ARM Limited. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 - * Licensed under the Apache License, Version 2.0 (the License); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#include "CppUTest/CommandLineTestRunner.h" -#include "CppUTest/TestPlugin.h" -#include "CppUTest/TestRegistry.h" -#include "CppUTestExt/MockSupportPlugin.h" -int main(int ac, char **av) -{ - return CommandLineTestRunner::RunAllTests(ac, av); -} - -IMPORT_TEST_GROUP(LibTrace); diff --git a/features/FEATURE_COMMON_PAL/nanostack-libservice/test/libService/unittest/libTrace/test_libtrace.cpp b/features/FEATURE_COMMON_PAL/nanostack-libservice/test/libService/unittest/libTrace/test_libtrace.cpp deleted file mode 100644 index 62f6bdbbe01..00000000000 --- a/features/FEATURE_COMMON_PAL/nanostack-libservice/test/libService/unittest/libTrace/test_libtrace.cpp +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright (c) 2015 ARM Limited. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 - * Licensed under the Apache License, Version 2.0 (the License); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#include "CppUTest/TestHarness.h" -#include "test_libtrace.h" -#include -#include "ip6tos_stub.h" - -char buf[1024]; - -static void myprint(const char *str) -{ - strcpy(buf, str); -} - -Test_LibTrace::Test_LibTrace() -{ - trace_init(); - set_trace_print_function(myprint); -} - -Test_LibTrace::~Test_LibTrace() -{ - trace_free(); -} - -void Test_LibTrace::test_libTrace_tracef() -{ - set_trace_config(TRACE_MODE_PLAIN | TRACE_ACTIVE_LEVEL_ALL); - - memset(buf, 0, 1024); - unsigned char longStr[1000] = {0x76}; - tracef(TRACE_LEVEL_DEBUG, "mygr", "%s", trace_array(longStr, 1000)); - CHECK(buf[0] == '7'); - - memset(buf, 0, 1024); - const char longStr2[200] = {0x36}; - tracef(TRACE_LEVEL_DEBUG, "mygr", longStr2); - CHECK(buf[0] == '6'); - - -} - -void Test_LibTrace::test_libTrace_trace_ipv6_prefix() -{ - memset(buf, 0, 1024); - uint8_t prefix[] = { 0x14, 0x6e, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00 }; - int prefix_len = 64; - ip6tos_stub.c = '7'; - ip6tos_stub.h = false; - char *str = trace_ipv6_prefix(prefix, prefix_len); - SimpleString ss(str); - - CHECK("/64" == ss); - - ip6tos_stub.h = true; - char *str2 = trace_ipv6_prefix(prefix, prefix_len); - SimpleString ss2(str2); - - CHECK("7/64" == ss2); -} diff --git a/features/FEATURE_COMMON_PAL/nanostack-libservice/test/libService/unittest/libTrace/test_libtrace.h b/features/FEATURE_COMMON_PAL/nanostack-libservice/test/libService/unittest/libTrace/test_libtrace.h deleted file mode 100644 index 3ad1fadf82b..00000000000 --- a/features/FEATURE_COMMON_PAL/nanostack-libservice/test/libService/unittest/libTrace/test_libtrace.h +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2015 ARM Limited. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 - * Licensed under the Apache License, Version 2.0 (the License); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#ifndef TEST_LIB_TRACE_H -#define TEST_LIB_TRACE_H - -#include "ns_trace.h" - -class Test_LibTrace -{ -public: - Test_LibTrace(); - - virtual ~Test_LibTrace(); - - void test_libTrace_tracef(); - - void test_libTrace_trace_ipv6_prefix(); -}; - -#endif // TEST_LIB_TRACE_H diff --git a/features/FEATURE_COMMON_PAL/nanostack-libservice/test/libService/unittest/makefile_defines.txt b/features/FEATURE_COMMON_PAL/nanostack-libservice/test/libService/unittest/makefile_defines.txt old mode 100644 new mode 100755 index 93f467ca1ee..46410f7762c --- a/features/FEATURE_COMMON_PAL/nanostack-libservice/test/libService/unittest/makefile_defines.txt +++ b/features/FEATURE_COMMON_PAL/nanostack-libservice/test/libService/unittest/makefile_defines.txt @@ -1,4 +1,5 @@ #--- Inputs ----# +MBED_TRACE_HOME = ../../../../../mbed-trace CPPUTEST_HOME = /usr CPPUTEST_USE_EXTENSIONS = Y CPPUTEST_USE_VPATH = Y @@ -11,6 +12,7 @@ INCLUDE_DIRS =\ ../../../..\ ../../../../source\ ../../../../mbed-client-libservice\ + $(MBED_TRACE_HOME)\ /usr/include\ $(CPPUTEST_HOME)/include\ diff --git a/features/FEATURE_COMMON_PAL/nanostack-libservice/test/libService/unittest/nsdynmem/Makefile b/features/FEATURE_COMMON_PAL/nanostack-libservice/test/libService/unittest/nsdynmem/Makefile new file mode 100644 index 00000000000..8178c5d5158 --- /dev/null +++ b/features/FEATURE_COMMON_PAL/nanostack-libservice/test/libService/unittest/nsdynmem/Makefile @@ -0,0 +1,25 @@ +include ../makefile_defines.txt + +COMPONENT_NAME = dynmem_unit +SRC_FILES = \ + ../../../../source/nsdynmemLIB/nsdynmemLIB.c + +TEST_SRC_FILES = \ + main.cpp \ + dynmemtest.cpp \ + error_callback.c \ + ../stubs/platform_critical.c \ + ../stubs/ns_list_stub.c + +# ../../../../source/libBits/common_functions.c +# ../stubs/some_stub.c \ + +# XXX: without this, the CppUTest complains for memory leak even without one. +# The funny thing is that the CppUTest does not find the memory leak on +# this app when there actually is one. +CPPUTEST_USE_MEM_LEAK_DETECTION = Y + +include ../MakefileWorker.mk + +CPPUTESTFLAGS += -DFEA_TRACE_SUPPORT + diff --git a/features/FEATURE_COMMON_PAL/nanostack-libservice/test/libService/unittest/nsdynmem/dynmemtest.cpp b/features/FEATURE_COMMON_PAL/nanostack-libservice/test/libService/unittest/nsdynmem/dynmemtest.cpp index dfb0c57ed19..bb978904da7 100644 --- a/features/FEATURE_COMMON_PAL/nanostack-libservice/test/libService/unittest/nsdynmem/dynmemtest.cpp +++ b/features/FEATURE_COMMON_PAL/nanostack-libservice/test/libService/unittest/nsdynmem/dynmemtest.cpp @@ -384,7 +384,6 @@ TEST(dynmem, free_on_empty_heap) free(heap); } - TEST(dynmem, not_negative_stats) { uint16_t size = 1000; @@ -429,6 +428,48 @@ TEST(dynmem, test_invalid_pointer_freed) { free(heap); } +TEST(dynmem, test_merge_corrupted_previous_block) { + uint16_t size = 1000; + uint8_t *heap = (uint8_t*)malloc(size); + uint8_t *p; + CHECK(NULL != heap); + reset_heap_error(); + ns_dyn_mem_init(heap, size, &heap_fail_callback, NULL); + CHECK(!heap_have_failed()); + + int *ptr = (int *)ns_dyn_mem_alloc(4); + int *ptr2 = (int *)ns_dyn_mem_alloc(4); + ns_dyn_mem_free(ptr); + ptr = ptr2 - 2; + *ptr = -2; + ns_dyn_mem_free(ptr2); + + CHECK(NS_DYN_MEM_HEAP_SECTOR_CORRUPTED == current_heap_error); + + free(heap); +} + +TEST(dynmem, test_free_corrupted_next_block) { + uint16_t size = 1000; + uint8_t *heap = (uint8_t*)malloc(size); + uint8_t *p; + CHECK(NULL != heap); + reset_heap_error(); + ns_dyn_mem_init(heap, size, &heap_fail_callback, NULL); + CHECK(!heap_have_failed()); + + int *ptr = (int *)ns_dyn_mem_temporary_alloc(4); + int *ptr2 = (int *)ns_dyn_mem_temporary_alloc(4); + ns_dyn_mem_free(ptr); + ptr = ptr2 + 2; + *ptr = -2; + ns_dyn_mem_free(ptr2); + + CHECK(NS_DYN_MEM_HEAP_SECTOR_CORRUPTED == current_heap_error); + + free(heap); +} + //NOTE! This test must be last! TEST(dynmem, uninitialized_test){ ns_dyn_mem_alloc(4); diff --git a/features/FEATURE_COMMON_PAL/nanostack-libservice/test/libService/unittest/nsnvmhelper/Makefile b/features/FEATURE_COMMON_PAL/nanostack-libservice/test/libService/unittest/nsnvmhelper/Makefile new file mode 100644 index 00000000000..f931a090c97 --- /dev/null +++ b/features/FEATURE_COMMON_PAL/nanostack-libservice/test/libService/unittest/nsnvmhelper/Makefile @@ -0,0 +1,18 @@ +include ../makefile_defines.txt + +COMPONENT_NAME = ns_nvm_helper_unit + +SRC_FILES = ../../../../source/nvmHelper/ns_nvm_helper.c + +TEST_SRC_FILES = main.cpp \ + nsnvmhelpertest.cpp \ + test_ns_nvm_helper.c \ + ../stubs/platform_nvm_stub.c \ + ../stubs/nsdynmemLIB_stub.c \ + ../stubs/mbed_trace_stub.c \ + ../stubs/ns_list_stub.c + +include ../MakefileWorker.mk + +CPPUTESTFLAGS += -DFEA_TRACE_SUPPORT + diff --git a/features/FEATURE_COMMON_PAL/nanostack-libservice/test/libService/unittest/run_tests b/features/FEATURE_COMMON_PAL/nanostack-libservice/test/libService/unittest/run_tests old mode 100644 new mode 100755 diff --git a/features/FEATURE_COMMON_PAL/nanostack-libservice/test/libService/unittest/stoip6/Makefile b/features/FEATURE_COMMON_PAL/nanostack-libservice/test/libService/unittest/stoip6/Makefile new file mode 100644 index 00000000000..68964c0d40d --- /dev/null +++ b/features/FEATURE_COMMON_PAL/nanostack-libservice/test/libService/unittest/stoip6/Makefile @@ -0,0 +1,21 @@ +include ../makefile_defines.txt + +COMPONENT_NAME = stoip6_unit +SRC_FILES = \ + ../../../../source/libip6string/stoip6.c + +TEST_SRC_FILES = \ + main.cpp \ + stoip6test.cpp \ + ../../../../source/libBits/common_functions.c +# ../stubs/some_stub.c \ + +# XXX: without this, the CppUTest complains for memory leak even without one. +# The funny thing is that the CppUTest does not find the memory leak on +# this app when there actually is one. +CPPUTEST_USE_MEM_LEAK_DETECTION = N + +include ../MakefileWorker.mk + +CPPUTESTFLAGS += -DFEA_TRACE_SUPPORT + diff --git a/features/FEATURE_COMMON_PAL/nanostack-libservice/test/libService/unittest/stubs/mbed_trace_stub.c b/features/FEATURE_COMMON_PAL/nanostack-libservice/test/libService/unittest/stubs/mbed_trace_stub.c new file mode 100644 index 00000000000..d3458b22235 --- /dev/null +++ b/features/FEATURE_COMMON_PAL/nanostack-libservice/test/libService/unittest/stubs/mbed_trace_stub.c @@ -0,0 +1,119 @@ +/* + * Copyright (c) 2014-2017 ARM Limited. All rights reserved. + * SPDX-License-Identifier: Apache-2.0 + * Licensed under the Apache License, Version 2.0 (the License); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include +#include +#include +#include + +#ifndef YOTTA_CFG_MBED_TRACE +#define YOTTA_CFG_MBED_TRACE 1 +#define YOTTA_CFG_MBED_TRACE_FEA_IPV6 1 +#endif + +#include "mbed-trace/mbed_trace.h" +#if YOTTA_CFG_MBED_TRACE_FEA_IPV6 == 1 +#include "mbed-client-libservice/ip6string.h" +#include "mbed-client-libservice/common_functions.h" +#endif + + +int mbed_trace_init(void) +{ + return 0; +} +void mbed_trace_free(void) +{ +} + +void mbed_trace_buffer_sizes(int lineLength, int tmpLength) +{ +} + +void mbed_trace_config_set(uint8_t config) +{ +} + +uint8_t mbed_trace_config_get(void) +{ + return 0; +} + +void mbed_trace_prefix_function_set(char *(*pref_f)(size_t)) +{ +} + +void mbed_trace_suffix_function_set(char *(*suffix_f)(void)) +{ +} + +void mbed_trace_print_function_set(void (*printf)(const char *)) +{ +} + +void mbed_trace_cmdprint_function_set(void (*printf)(const char *)) +{ +} + +void mbed_trace_exclude_filters_set(char *filters) +{ + +} + +const char *mbed_trace_exclude_filters_get(void) +{ + return NULL; +} + +const char *mbed_trace_include_filters_get(void) +{ + return NULL; +} + +void mbed_trace_include_filters_set(char *filters) +{ + +} + +void mbed_tracef(uint8_t dlevel, const char *grp, const char *fmt, ...) +{ +} + +void mbed_vtracef(uint8_t dlevel, const char *grp, const char *fmt, va_list ap) +{ +} + +const char *mbed_trace_last(void) +{ + return NULL; +} + +/* Helping functions */ +#if YOTTA_CFG_MBED_TRACE_FEA_IPV6 == 1 +char *mbed_trace_ipv6(const void *addr_ptr) +{ + return NULL; +} + +char *mbed_trace_ipv6_prefix(const uint8_t *prefix, uint8_t prefix_len) +{ + return NULL; +} +#endif //YOTTA_CFG_MBED_TRACE_FEA_IPV6 + +char *mbed_trace_array(const uint8_t *buf, uint16_t len) +{ + return NULL; +} diff --git a/features/FEATURE_COMMON_PAL/nanostack-libservice/test/libService/unittest/stubs/ns_trace_stub.c b/features/FEATURE_COMMON_PAL/nanostack-libservice/test/libService/unittest/stubs/ns_trace_stub.c deleted file mode 100644 index 1c45fd401e3..00000000000 --- a/features/FEATURE_COMMON_PAL/nanostack-libservice/test/libService/unittest/stubs/ns_trace_stub.c +++ /dev/null @@ -1,202 +0,0 @@ -/* - * Copyright (c) 2014-2015 ARM Limited. All rights reserved. - */ -#include -#include -#include -#include - -#include "ns_trace.h" -#include "ip6string.h" -#include "common_functions.h" - -#if defined(_WIN32) || defined(__unix__) || defined(__unix) || defined(unix) -#ifndef MEM_ALLOC -#define MEM_ALLOC malloc -#endif -#ifndef MEM_FREE -#define MEM_FREE free -#endif -#else -#include "nsdynmemLIB.h" -#ifndef MEM_ALLOC -#define MEM_ALLOC ns_dyn_mem_alloc -#endif -#ifndef MEM_FREE -#define MEM_FREE ns_dyn_mem_free -#endif -#endif - -#define VT100_COLOR_ERROR "\x1b[31m" -#define VT100_COLOR_WARN "\x1b[33m" -#define VT100_COLOR_INFO "\x1b[39m" -#define VT100_COLOR_DEBUG "\x1b[90m" - -/** default max trace line size in bytes */ -#define DEFAULT_TRACE_LINE_LENGTH 1024 -/** default max temporary buffer size in bytes, used in - trace_ipv6, trace_array and trace_strn */ -#define DEFAULT_TRACE_TMP_LINE_LEN 128 -/** default max filters (include/exclude) length in bytes */ -#define DEFAULT_TRACE_FILTER_LENGTH 24 - -static void default_print(const char *str); - -typedef struct { - /** trace configuration bits */ - uint8_t trace_config; - /** exclude filters list, related group name */ - char *filters_exclude; - /** include filters list, related group name */ - char *filters_include; - /** Filters length */ - int filters_length; - /** trace line */ - char *line; - /** trace line length */ - int line_length; - /** temporary data */ - char *tmp_data; - /** temporary data array length */ - int tmp_data_length; - /** temporary data pointer */ - char *tmp_data_ptr; - - /** prefix function, which can be used to put time to the trace line */ - char *(*prefix_f)(size_t); - /** suffix function, which can be used to some string to the end of trace line */ - char *(*suffix_f)(void); - /** print out function. Can be redirect to flash for example. */ - void (*printf)(const char *); - /** print out function for TRACE_LEVEL_CMD */ - void (*cmd_printf)(const char *); -} trace_s; - -static trace_s m_trace = { - .filters_exclude = 0, - .filters_include = 0, - .line = 0, - .tmp_data = 0, - .prefix_f = 0, - .suffix_f = 0, - .printf = 0, - .cmd_printf = 0 -}; - -int trace_init(void) -{ - return 0; -} -void trace_free(void) -{ - -} - -void set_trace_config(uint8_t config) -{ - -} -uint8_t get_trace_config(void) -{ - return 0; -} -void set_trace_prefix_function(char *(*pref_f)(size_t)) -{ -} - -void set_trace_suffix_function(char *(*suffix_f)(void)) -{ -} - -void set_trace_print_function(void (*printf)(const char *)) -{ -} - -void set_trace_cmdprint_function(void (*printf)(const char *)) -{ -} - -void set_trace_exclude_filters(char *filters) -{ -} -const char *get_trace_exclude_filters(void) -{ - return NULL; -} - -const char *get_trace_include_filters(void) -{ - return NULL; -} - -void set_trace_include_filters(char *filters) -{ -} - -static int8_t trace_skip(int8_t dlevel, const char *grp) -{ - return 0; -} - -static void default_print(const char *str) -{ -} - -void tracef(uint8_t dlevel, const char *grp, const char *fmt, ...) -{ - -} -const char *trace_last(void) -{ - return ""; -} - -/* Helping functions */ -#define tmp_data_left() m_trace.tmp_data_length-(m_trace.tmp_data_ptr-m_trace.tmp_data) -char *trace_ipv6(const void *addr_ptr) -{ - return ""; -} - -char *trace_ipv6_prefix(const uint8_t *prefix, uint8_t prefix_len) -{ - return ""; -} - -char *trace_array(const uint8_t *buf, uint16_t len) -{ - return ""; -} - -// rest of debug print functions will be obsolete and will be overridden with new trace interface.. -void debugf(const char *fmt, ...) -{ -} - -void debug(const char *s) -{ -} - -void debug_put(char c) -{ -} - -void debug_hex(uint8_t x) -{ -} - -void debug_int(int i) -{ -} - -void printf_array(const void *buf , uint16_t len) -{ -} - -void printf_ipv6_address(const void *addr_ptr) -{ -} - -void printf_string(const void *ptr, uint16_t len) -{ -}