1 /* Copyright (c) 2022 Nordic Semiconductor ASA
2  * SPDX-License-Identifier: Apache-2.0
3  */
4 
5 /* Helper for printk parameters to convert from binary to hex.
6  * We declare multiple buffers so the helper can be used multiple times
7  * in a single printk call.
8  */
9 
10 #include <stddef.h>
11 
12 #include <zephyr/bluetooth/bluetooth.h>
13 #include <zephyr/bluetooth/hci.h>
14 #include <zephyr/bluetooth/uuid.h>
15 #include <zephyr/kernel.h>
16 #include <zephyr/sys/util.h>
17 #include <zephyr/types.h>
18 
bt_hex(const void * buf,size_t len)19 const char *bt_hex(const void *buf, size_t len)
20 {
21 	static const char hex[] = "0123456789abcdef";
22 	static char str[129];
23 	const uint8_t *b = buf;
24 	size_t i;
25 
26 	len = MIN(len, (sizeof(str) - 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 
bt_addr_str(const bt_addr_t * addr)38 const char *bt_addr_str(const bt_addr_t *addr)
39 {
40 	static char str[BT_ADDR_STR_LEN];
41 
42 	bt_addr_to_str(addr, str, sizeof(str));
43 
44 	return str;
45 }
46 
bt_addr_le_str(const bt_addr_le_t * addr)47 const char *bt_addr_le_str(const bt_addr_le_t *addr)
48 {
49 	static char str[BT_ADDR_LE_STR_LEN];
50 
51 	bt_addr_le_to_str(addr, str, sizeof(str));
52 
53 	return str;
54 }
55 
bt_uuid_str(const struct bt_uuid * uuid)56 const char *bt_uuid_str(const struct bt_uuid *uuid)
57 {
58 	static char str[BT_UUID_STR_LEN];
59 
60 	bt_uuid_to_str(uuid, str, sizeof(str));
61 
62 	return str;
63 }
64