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_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_ISO_TX_PKT 18
28 #define BT_MONITOR_ISO_RX_PKT 19
29 #define BT_MONITOR_NOP 255
30
31 #define BT_MONITOR_TYPE_PRIMARY 0
32 #define BT_MONITOR_TYPE_AMP 1
33
34 /* Extended header types */
35 #define BT_MONITOR_COMMAND_DROPS 1
36 #define BT_MONITOR_EVENT_DROPS 2
37 #define BT_MONITOR_ACL_RX_DROPS 3
38 #define BT_MONITOR_ACL_TX_DROPS 4
39 #define BT_MONITOR_SCO_RX_DROPS 5
40 #define BT_MONITOR_SCO_TX_DROPS 6
41 #define BT_MONITOR_OTHER_DROPS 7
42 #define BT_MONITOR_TS32 8
43
44 #define BT_MONITOR_BASE_HDR_LEN 6
45
46 #if defined(CONFIG_BT_BREDR)
47 #define BT_MONITOR_EXT_HDR_MAX 19
48 #else
49 #define BT_MONITOR_EXT_HDR_MAX 15
50 #endif
51
52 struct bt_monitor_hdr {
53 uint16_t data_len;
54 uint16_t opcode;
55 uint8_t flags;
56 uint8_t hdr_len;
57
58 uint8_t ext[BT_MONITOR_EXT_HDR_MAX];
59 } __packed;
60
61 struct bt_monitor_ts32 {
62 uint8_t type;
63 uint32_t ts32;
64 } __packed;
65
66 struct bt_monitor_new_index {
67 uint8_t type;
68 uint8_t bus;
69 uint8_t bdaddr[6];
70 char name[8];
71 } __packed;
72
73 struct bt_monitor_user_logging {
74 uint8_t priority;
75 uint8_t ident_len;
76 } __packed;
77
bt_monitor_opcode(struct net_buf * buf)78 static inline uint8_t bt_monitor_opcode(struct net_buf *buf)
79 {
80 switch (bt_buf_get_type(buf)) {
81 case BT_BUF_CMD:
82 return BT_MONITOR_COMMAND_PKT;
83 case BT_BUF_EVT:
84 return BT_MONITOR_EVENT_PKT;
85 case BT_BUF_ACL_OUT:
86 return BT_MONITOR_ACL_TX_PKT;
87 case BT_BUF_ACL_IN:
88 return BT_MONITOR_ACL_RX_PKT;
89 case BT_BUF_ISO_OUT:
90 return BT_MONITOR_ISO_TX_PKT;
91 case BT_BUF_ISO_IN:
92 return BT_MONITOR_ISO_RX_PKT;
93 default:
94 return BT_MONITOR_NOP;
95 }
96 }
97
98 void bt_monitor_send(uint16_t opcode, const void *data, size_t len);
99
100 void bt_monitor_new_index(uint8_t type, uint8_t bus, const bt_addr_t *addr,
101 const char *name);
102
103 #else /* !CONFIG_BT_MONITOR */
104
105 #define bt_monitor_send(opcode, data, len)
106 #define bt_monitor_new_index(type, bus, addr, name)
107
108 #endif
109