mesh_util.c
1 /* 2 * Copyright (c) 2017 Nordic Semiconductor ASA 3 * Copyright (c) 2016 Vinayak Kariappa Chettimada 4 * Copyright (c) 2015-2016 Intel Corporation 5 * 6 * SPDX-License-Identifier: Apache-2.0 7 */ 8 9 #include <string.h> 10 11 #include "mesh_types.h" 12 #include "mesh_util.h" 13 14 const char *bt_hex(const void *buf, size_t len) 15 { 16 static const char hex[] = "0123456789abcdef"; 17 static char hexbufs[2][129]; 18 static u8_t curbuf; 19 const u8_t *b = buf; 20 char *str = NULL; 21 int i; 22 23 str = hexbufs[curbuf++]; 24 curbuf %= ARRAY_SIZE(hexbufs); 25 26 len = MIN(len, (sizeof(hexbufs[0]) - 1) / 2); 27 28 for (i = 0; i < len; i++) { 29 str[i * 2] = hex[b[i] >> 4]; 30 str[i * 2 + 1] = hex[b[i] & 0xf]; 31 } 32 33 str[i * 2] = '\0'; 34 35 return str; 36 } 37 38 void mem_rcopy(u8_t *dst, u8_t const *src, u16_t len) 39 { 40 src += len; 41 while (len--) { 42 *dst++ = *--src; 43 } 44 }