Nanostack Border Router is a generic mbed border router implementation that provides the 6LoWPAN ND or Thread border router initialization logic.

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers borderrouter_helpers.c Source File

borderrouter_helpers.c

00001 /*
00002  * Copyright (c) 2016 ARM Limited. All rights reserved.
00003  */
00004 
00005 #include <string.h>
00006 #include <stdlib.h>
00007 #include <stdio.h>
00008 #include <ctype.h>
00009 #include "ip6string.h"
00010 #include "ns_types.h"
00011 #include "common_functions.h"
00012 #include "ns_trace.h"
00013 #include "nsdynmemLIB.h"
00014 #define TRACE_GROUP "app"
00015 
00016 static char tmp_print_buffer[128] = {0};
00017 
00018 char *print_ipv6(const void *addr_ptr)
00019 {
00020     ip6tos(addr_ptr, tmp_print_buffer);
00021     return tmp_print_buffer;
00022 }
00023 
00024 char *print_ipv6_prefix(const uint8_t *prefix, uint8_t prefix_len)
00025 {
00026     char *str = tmp_print_buffer;
00027     int retval;
00028     char tmp[40];
00029     uint8_t addr[16] = {0};
00030 
00031     if (prefix_len != 0) {
00032         if (prefix == NULL || prefix_len > 128) {
00033             return "<err>";
00034         }
00035         bitcopy(addr, prefix, prefix_len);
00036     }
00037 
00038     ip6tos(addr, tmp);
00039     retval = snprintf(str, 128, "%s/%u", tmp, prefix_len);
00040     if (retval <= 0) {
00041         return "";
00042     }
00043     return str;
00044 }
00045 
00046 void print_memory_stats(void)
00047 {
00048     const mem_stat_t *heap_info = ns_dyn_mem_get_mem_stat();
00049     if (heap_info) {
00050         tr_info(
00051             "Heap size: %lu, Reserved: %lu, Reserved max: %lu, Alloc fail: %lu"
00052             , (unsigned long)heap_info->heap_sector_size
00053             , (unsigned long)heap_info->heap_sector_allocated_bytes
00054             , (unsigned long)heap_info->heap_sector_allocated_bytes_max
00055             , (unsigned long)heap_info->heap_alloc_fail_cnt);
00056     }
00057 }
00058