1 /** @file
2  *  @brief Custom monitor protocol logging over UART
3  */
4 
5 /*
6  * Copyright (c) 2016 Intel Corporation
7  *
8  * SPDX-License-Identifier: Apache-2.0
9  */
10 
11 #if defined(CONFIG_BT_DEBUG_MONITOR)
12 
13 #define BT_MONITOR_NEW_INDEX	0
14 #define BT_MONITOR_DEL_INDEX	1
15 #define BT_MONITOR_COMMAND_PKT	2
16 #define BT_MONITOR_EVENT_PKT	3
17 #define BT_MONITOR_ACL_TX_PKT	4
18 #define BT_MONITOR_ACL_RX_PKT	5
19 #define BT_MONITOR_SCO_TX_PKT	6
20 #define BT_MONITOR_SCO_RX_PKT	7
21 #define BT_MONITOR_OPEN_INDEX	8
22 #define BT_MONITOR_CLOSE_INDEX	9
23 #define BT_MONITOR_INDEX_INFO	10
24 #define BT_MONITOR_VENDOR_DIAG	11
25 #define BT_MONITOR_SYSTEM_NOTE	12
26 #define BT_MONITOR_USER_LOGGING	13
27 #define BT_MONITOR_NOP		255
28 
29 #define BT_MONITOR_TYPE_PRIMARY	0
30 #define BT_MONITOR_TYPE_AMP	1
31 
32 /* Extended header types */
33 #define BT_MONITOR_COMMAND_DROPS 1
34 #define BT_MONITOR_EVENT_DROPS   2
35 #define BT_MONITOR_ACL_RX_DROPS  3
36 #define BT_MONITOR_ACL_TX_DROPS  4
37 #define BT_MONITOR_SCO_RX_DROPS  5
38 #define BT_MONITOR_SCO_TX_DROPS  6
39 #define BT_MONITOR_OTHER_DROPS   7
40 #define BT_MONITOR_TS32          8
41 
42 #define BT_MONITOR_BASE_HDR_LEN  6
43 
44 #if defined(CONFIG_BT_BREDR)
45 #define BT_MONITOR_EXT_HDR_MAX 19
46 #else
47 #define BT_MONITOR_EXT_HDR_MAX 15
48 #endif
49 
50 struct bt_monitor_hdr {
51 	u16_t  data_len;
52 	u16_t  opcode;
53 	u8_t   flags;
54 	u8_t   hdr_len;
55 
56 	u8_t   ext[BT_MONITOR_EXT_HDR_MAX];
57 } __packed;
58 
59 struct bt_monitor_ts32 {
60 	u8_t   type;
61 	bt_u32_t  ts32;
62 } __packed;
63 
64 struct bt_monitor_new_index {
65 	u8_t  type;
66 	u8_t  bus;
67 	u8_t  bdaddr[6];
68 	char  name[8];
69 } __packed;
70 
71 struct bt_monitor_user_logging {
72 	u8_t  priority;
73 	u8_t  ident_len;
74 } __packed;
75 
bt_monitor_opcode(struct net_buf * buf)76 static inline u8_t bt_monitor_opcode(struct net_buf *buf)
77 {
78 	switch (bt_buf_get_type(buf)) {
79 	case BT_BUF_CMD:
80 		return BT_MONITOR_COMMAND_PKT;
81 	case BT_BUF_EVT:
82 		return BT_MONITOR_EVENT_PKT;
83 	case BT_BUF_ACL_OUT:
84 		return BT_MONITOR_ACL_TX_PKT;
85 	case BT_BUF_ACL_IN:
86 		return BT_MONITOR_ACL_RX_PKT;
87 	default:
88 		return BT_MONITOR_NOP;
89 	}
90 }
91 
92 void bt_monitor_send(u16_t opcode, const void *data, size_t len);
93 
94 void bt_monitor_new_index(u8_t type, u8_t bus, bt_addr_t *addr,
95 			  const char *name);
96 
97 #else /* !CONFIG_BT_DEBUG_MONITOR */
98 
99 #define bt_monitor_send(opcode, data, len)
100 #define bt_monitor_new_index(type, bus, addr, name)
101 
102 #endif
103