1 /* hci_vs.h - Bluetooth Host Control Interface Vendor Specific definitions */
2 
3 /*
4  * Copyright (c) 2017-2018 Nordic Semiconductor ASA
5  * Copyright (c) 2015-2016 Intel Corporation
6  *
7  * SPDX-License-Identifier: Apache-2.0
8  */
9 #ifndef ZEPHYR_INCLUDE_BLUETOOTH_HCI_VS_H_
10 #define ZEPHYR_INCLUDE_BLUETOOTH_HCI_VS_H_
11 
12 #include <stdint.h>
13 
14 #include <zephyr/bluetooth/hci.h>
15 
16 #ifdef __cplusplus
17 extern "C" {
18 #endif
19 
20 #define BT_VS_CMD_BIT_VERSION                       0
21 #define BT_VS_CMD_BIT_SUP_CMD                       1
22 #define BT_VS_CMD_BIT_SUP_FEAT                      2
23 #define BT_VS_CMD_BIT_SET_EVT_MASK                  3
24 #define BT_VS_CMD_BIT_RESET                         4
25 #define BT_VS_CMD_BIT_WRITE_BDADDR                  5
26 #define BT_VS_CMD_BIT_SET_TRACE_ENABLE              6
27 #define BT_VS_CMD_BIT_READ_BUILD_INFO               7
28 #define BT_VS_CMD_BIT_READ_STATIC_ADDRS             8
29 #define BT_VS_CMD_BIT_READ_KEY_ROOTS                9
30 #define BT_VS_CMD_BIT_READ_CHIP_TEMP               10
31 #define BT_VS_CMD_BIT_READ_HOST_STACK_CMD          11
32 #define BT_VS_CMD_BIT_SET_SCAN_REP_ENABLE          12
33 #define BT_VS_CMD_BIT_WRITE_TX_POWER               13
34 #define BT_VS_CMD_BIT_READ_TX_POWER                14
35 
36 #define BT_VS_CMD_SUP_FEAT(cmd)                 BT_LE_FEAT_TEST(cmd, \
37 						BT_VS_CMD_BIT_SUP_FEAT)
38 #define BT_VS_CMD_READ_STATIC_ADDRS(cmd)        BT_LE_FEAT_TEST(cmd, \
39 						BT_VS_CMD_BIT_READ_STATIC_ADDRS)
40 #define BT_VS_CMD_READ_KEY_ROOTS(cmd)           BT_LE_FEAT_TEST(cmd, \
41 						BT_VS_CMD_BIT_READ_KEY_ROOTS)
42 
43 #define BT_HCI_VS_HW_PLAT_INTEL                 0x0001
44 #define BT_HCI_VS_HW_PLAT_NORDIC                0x0002
45 #define BT_HCI_VS_HW_PLAT_NXP                   0x0003
46 
47 #define BT_HCI_VS_HW_VAR_NORDIC_NRF51X          0x0001
48 #define BT_HCI_VS_HW_VAR_NORDIC_NRF52X          0x0002
49 #define BT_HCI_VS_HW_VAR_NORDIC_NRF53X          0x0003
50 
51 #define BT_HCI_VS_FW_VAR_STANDARD_CTLR          0x0001
52 #define BT_HCI_VS_FW_VAR_VS_CTLR                0x0002
53 #define BT_HCI_VS_FW_VAR_FW_LOADER              0x0003
54 #define BT_HCI_VS_FW_VAR_RESCUE_IMG             0x0004
55 #define BT_HCI_OP_VS_READ_VERSION_INFO		BT_OP(BT_OGF_VS, 0x0001)
56 struct bt_hci_rp_vs_read_version_info {
57 	uint8_t  status;
58 	uint16_t hw_platform;
59 	uint16_t hw_variant;
60 	uint8_t  fw_variant;
61 	uint8_t  fw_version;
62 	uint16_t fw_revision;
63 	uint32_t fw_build;
64 } __packed;
65 
66 #define BT_HCI_OP_VS_READ_SUPPORTED_COMMANDS	BT_OP(BT_OGF_VS, 0x0002)
67 struct bt_hci_rp_vs_read_supported_commands {
68 	uint8_t  status;
69 	uint8_t  commands[64];
70 } __packed;
71 
72 #define BT_HCI_OP_VS_READ_SUPPORTED_FEATURES	BT_OP(BT_OGF_VS, 0x0003)
73 struct bt_hci_rp_vs_read_supported_features {
74 	uint8_t  status;
75 	uint8_t  features[8];
76 } __packed;
77 
78 #define BT_HCI_OP_VS_SET_EVENT_MASK             BT_OP(BT_OGF_VS, 0x0004)
79 struct bt_hci_cp_vs_set_event_mask {
80 	uint8_t  event_mask[8];
81 } __packed;
82 
83 #define BT_HCI_VS_RESET_SOFT                    0x00
84 #define BT_HCI_VS_RESET_HARD                    0x01
85 #define BT_HCI_OP_VS_RESET                      BT_OP(BT_OGF_VS, 0x0005)
86 struct bt_hci_cp_vs_reset {
87 	uint8_t  type;
88 } __packed;
89 
90 #define BT_HCI_OP_VS_WRITE_BD_ADDR              BT_OP(BT_OGF_VS, 0x0006)
91 struct bt_hci_cp_vs_write_bd_addr {
92 	bt_addr_t bdaddr;
93 } __packed;
94 
95 #define BT_HCI_VS_TRACE_DISABLED                0x00
96 #define BT_HCI_VS_TRACE_ENABLED                 0x01
97 
98 #define BT_HCI_VS_TRACE_HCI_EVTS                0x00
99 #define BT_HCI_VS_TRACE_VDC                     0x01
100 #define BT_HCI_OP_VS_SET_TRACE_ENABLE           BT_OP(BT_OGF_VS, 0x0007)
101 struct bt_hci_cp_vs_set_trace_enable {
102 	uint8_t  enable;
103 	uint8_t  type;
104 } __packed;
105 
106 #define BT_HCI_OP_VS_READ_BUILD_INFO            BT_OP(BT_OGF_VS, 0x0008)
107 struct bt_hci_rp_vs_read_build_info {
108 	uint8_t  status;
109 	uint8_t  info[0];
110 } __packed;
111 
112 struct bt_hci_vs_static_addr {
113 	bt_addr_t bdaddr;
114 	uint8_t      ir[16];
115 } __packed;
116 
117 #define BT_HCI_OP_VS_READ_STATIC_ADDRS          BT_OP(BT_OGF_VS, 0x0009)
118 struct bt_hci_rp_vs_read_static_addrs {
119 	uint8_t   status;
120 	uint8_t   num_addrs;
121 	struct bt_hci_vs_static_addr a[0];
122 } __packed;
123 
124 #define BT_HCI_OP_VS_READ_KEY_HIERARCHY_ROOTS   BT_OP(BT_OGF_VS, 0x000a)
125 struct bt_hci_rp_vs_read_key_hierarchy_roots {
126 	uint8_t  status;
127 	uint8_t  ir[16];
128 	uint8_t  er[16];
129 } __packed;
130 
131 #define BT_HCI_OP_VS_READ_CHIP_TEMP             BT_OP(BT_OGF_VS, 0x000b)
132 struct bt_hci_rp_vs_read_chip_temp {
133 	uint8_t  status;
134 	int8_t  temps;
135 } __packed;
136 
137 struct bt_hci_vs_cmd {
138 	uint16_t vendor_id;
139 	uint16_t opcode_base;
140 } __packed;
141 
142 #define BT_HCI_VS_VID_ANDROID                   0x0001
143 #define BT_HCI_VS_VID_MICROSOFT                 0x0002
144 #define BT_HCI_OP_VS_READ_HOST_STACK_CMDS       BT_OP(BT_OGF_VS, 0x000c)
145 struct bt_hci_rp_vs_read_host_stack_cmds {
146 	uint8_t   status;
147 	uint8_t   num_cmds;
148 	struct bt_hci_vs_cmd c[0];
149 } __packed;
150 
151 #define BT_HCI_VS_SCAN_REQ_REPORTS_DISABLED     0x00
152 #define BT_HCI_VS_SCAN_REQ_REPORTS_ENABLED      0x01
153 #define BT_HCI_OP_VS_SET_SCAN_REQ_REPORTS       BT_OP(BT_OGF_VS, 0x000d)
154 struct bt_hci_cp_vs_set_scan_req_reports {
155 	uint8_t  enable;
156 } __packed;
157 
158 #define BT_HCI_VS_LL_HANDLE_TYPE_ADV       0x00
159 #define BT_HCI_VS_LL_HANDLE_TYPE_SCAN      0x01
160 #define BT_HCI_VS_LL_HANDLE_TYPE_CONN      0x02
161 #define BT_HCI_VS_LL_TX_POWER_LEVEL_NO_PREF     0x7F
162 #define BT_HCI_OP_VS_WRITE_TX_POWER_LEVEL       BT_OP(BT_OGF_VS, 0x000e)
163 struct bt_hci_cp_vs_write_tx_power_level {
164 	uint8_t  handle_type;
165 	uint16_t handle;
166 	int8_t  tx_power_level;
167 } __packed;
168 
169 struct bt_hci_rp_vs_write_tx_power_level {
170 	uint8_t  status;
171 	uint8_t  handle_type;
172 	uint16_t handle;
173 	int8_t  selected_tx_power;
174 } __packed;
175 
176 #define BT_HCI_OP_VS_READ_TX_POWER_LEVEL        BT_OP(BT_OGF_VS, 0x000f)
177 struct bt_hci_cp_vs_read_tx_power_level {
178 	uint8_t  handle_type;
179 	uint16_t handle;
180 } __packed;
181 
182 struct bt_hci_rp_vs_read_tx_power_level {
183 	uint8_t  status;
184 	uint8_t  handle_type;
185 	uint16_t handle;
186 	int8_t  tx_power_level;
187 } __packed;
188 
189 #define BT_HCI_OP_VS_READ_USB_TRANSPORT_MODE    BT_OP(BT_OGF_VS, 0x0010)
190 
191 struct bt_hci_rp_vs_read_usb_transport_mode {
192 	uint8_t  status;
193 	uint8_t  num_supported_modes;
194 	uint8_t  supported_mode[0];
195 } __packed;
196 
197 #define BT_HCI_VS_USB_H2_MODE                  0x00
198 #define BT_HCI_VS_USB_H4_MODE                  0x01
199 
200 #define BT_HCI_OP_VS_SET_USB_TRANSPORT_MODE    BT_OP(BT_OGF_VS, 0x0011)
201 
202 struct bt_hci_cp_vs_set_usb_transport_mode {
203 	uint8_t  mode;
204 } __packed;
205 
206 #define BT_HCI_OP_VS_SET_MIN_NUM_USED_CHANS    BT_OP(BT_OGF_VS, 0x0012)
207 
208 struct bt_hci_cp_vs_set_min_num_used_chans {
209 	uint16_t handle;
210 	uint8_t  phys;
211 	uint8_t  min_used_chans;
212 } __packed;
213 
214 /* Events */
215 
216 struct bt_hci_evt_vs {
217 	uint8_t  subevent;
218 } __packed;
219 
220 #define BT_HCI_EVT_VS_FATAL_ERROR              0x02
221 
222 #define BT_HCI_EVT_VS_ERROR_DATA_TYPE_STACK_FRAME   0x01
223 #define BT_HCI_EVT_VS_ERROR_DATA_TYPE_CTRL_ASSERT   0x02
224 #define BT_HCI_EVT_VS_ERROR_DATA_TYPE_TRACE         0x03
225 struct bt_hci_vs_fata_error_cpu_data_cortex_m {
226 	uint32_t a1;
227 	uint32_t a2;
228 	uint32_t a3;
229 	uint32_t a4;
230 	uint32_t ip;
231 	uint32_t lr;
232 	uint32_t xpsr;
233 } __packed;
234 #define BT_HCI_EVT_VS_ERROR_CPU_TYPE_CORTEX_M  0x01
235 struct bt_hci_vs_fatal_error_stack_frame {
236 	uint32_t reason;
237 	uint8_t cpu_type;
238 	uint8_t cpu_data[0];
239 } __packed;
240 
241 struct bt_hci_evt_vs_fatal_error_trace_data {
242 	uint64_t pc;
243 	uint8_t err_info[0];
244 } __packed;
245 
246 struct bt_hci_evt_vs_fatal_error {
247 	uint8_t type;
248 	uint8_t data[0];
249 } __packed;
250 
251 #define BT_HCI_VS_TRACE_LMP_TX                 0x01
252 #define BT_HCI_VS_TRACE_LMP_RX                 0x02
253 #define BT_HCI_VS_TRACE_LLCP_TX                0x03
254 #define BT_HCI_VS_TRACE_LLCP_RX                0x04
255 #define BT_HCI_VS_TRACE_LE_CONN_IND            0x05
256 #define BT_HCI_EVT_VS_TRACE_INFO               0x03
257 struct bt_hci_evt_vs_trace_info {
258 	uint8_t  type;
259 	uint8_t  data[0];
260 } __packed;
261 
262 #define BT_HCI_EVT_VS_SCAN_REQ_RX              0x04
263 struct bt_hci_evt_vs_scan_req_rx {
264 	bt_addr_le_t addr;
265 	int8_t         rssi;
266 } __packed;
267 
268 struct bt_hci_le_iq_sample16 {
269 	int16_t i;
270 	int16_t q;
271 } __packed;
272 
273 #define BT_HCI_EVT_VS_LE_CONNECTIONLESS_IQ_REPORT 0x5
274 #define BT_HCI_VS_LE_CTE_REPORT_NO_VALID_SAMPLE   0x8000
275 struct bt_hci_evt_vs_le_connectionless_iq_report {
276 	uint16_t sync_handle;
277 	uint8_t chan_idx;
278 	int16_t rssi;
279 	uint8_t rssi_ant_id;
280 	uint8_t cte_type;
281 	uint8_t slot_durations;
282 	uint8_t packet_status;
283 	uint16_t per_evt_counter;
284 	uint8_t sample_count;
285 	struct bt_hci_le_iq_sample16 sample[0];
286 } __packed;
287 
288 #define BT_HCI_EVT_VS_LE_CONNECTION_IQ_REPORT 0x6
289 struct bt_hci_evt_vs_le_connection_iq_report {
290 	uint16_t conn_handle;
291 	uint8_t rx_phy;
292 	uint8_t data_chan_idx;
293 	int16_t rssi;
294 	uint8_t rssi_ant_id;
295 	uint8_t cte_type;
296 	uint8_t slot_durations;
297 	uint8_t packet_status;
298 	uint16_t conn_evt_counter;
299 	uint8_t sample_count;
300 	struct bt_hci_le_iq_sample16 sample[0];
301 } __packed;
302 
303 /* Event mask bits */
304 
305 #define BT_EVT_MASK_VS_FATAL_ERROR             BT_EVT_BIT(1)
306 #define BT_EVT_MASK_VS_TRACE_INFO              BT_EVT_BIT(2)
307 #define BT_EVT_MASK_VS_SCAN_REQ_RX             BT_EVT_BIT(3)
308 #define BT_EVT_MASK_VS_LE_CONNECTIONLESS_IQ_REPORT BT_EVT_BIT(4)
309 #define BT_EVT_MASK_VS_LE_CONNECTION_IQ_REPORT	   BT_EVT_BIT(5)
310 
311 #define DEFAULT_VS_EVT_MASK                                                                        \
312 	BT_EVT_MASK_VS_FATAL_ERROR | BT_EVT_MASK_VS_TRACE_INFO | BT_EVT_MASK_VS_SCAN_REQ_RX |      \
313 		BT_EVT_MASK_VS_LE_CONNECTIONLESS_IQ_REPORT |                                       \
314 		BT_EVT_MASK_VS_LE_CONNECTION_IQ_REPORT
315 
316 /* Mesh HCI commands */
317 #define BT_HCI_MESH_REVISION                   0x01
318 
319 #define BT_HCI_OP_VS_MESH                      BT_OP(BT_OGF_VS, 0x0042)
320 #define BT_HCI_MESH_EVT_PREFIX                 0xF0
321 
322 struct bt_hci_cp_mesh {
323 	uint8_t         opcode;
324 } __packed;
325 
326 #define BT_HCI_OC_MESH_GET_OPTS                0x00
327 struct bt_hci_rp_mesh_get_opts {
328 	uint8_t      status;
329 	uint8_t      opcode;
330 	uint8_t      revision;
331 	uint8_t      ch_map;
332 	int8_t      min_tx_power;
333 	int8_t      max_tx_power;
334 	uint8_t      max_scan_filter;
335 	uint8_t      max_filter_pattern;
336 	uint8_t      max_adv_slot;
337 	uint8_t      max_tx_window;
338 	uint8_t      evt_prefix_len;
339 	uint8_t      evt_prefix;
340 } __packed;
341 
342 #define BT_HCI_MESH_PATTERN_LEN_MAX            0x0f
343 
344 #define BT_HCI_OC_MESH_SET_SCAN_FILTER         0x01
345 struct bt_hci_mesh_pattern {
346 	uint8_t pattern_len;
347 	uint8_t pattern[0];
348 } __packed;
349 
350 struct bt_hci_cp_mesh_set_scan_filter {
351 	uint8_t      scan_filter;
352 	uint8_t      filter_dup;
353 	uint8_t      num_patterns;
354 	struct    bt_hci_mesh_pattern patterns[0];
355 } __packed;
356 struct bt_hci_rp_mesh_set_scan_filter {
357 	uint8_t      status;
358 	uint8_t      opcode;
359 	uint8_t      scan_filter;
360 } __packed;
361 
362 #define BT_HCI_OC_MESH_ADVERTISE               0x02
363 struct bt_hci_cp_mesh_advertise {
364 	uint8_t      adv_slot;
365 	uint8_t      own_addr_type;
366 	bt_addr_t random_addr;
367 	uint8_t      ch_map;
368 	int8_t      tx_power;
369 	uint8_t      min_tx_delay;
370 	uint8_t      max_tx_delay;
371 	uint8_t      retx_count;
372 	uint8_t      retx_interval;
373 	uint8_t      scan_delay;
374 	uint16_t     scan_duration;
375 	uint8_t      scan_filter;
376 	uint8_t      data_len;
377 	uint8_t      data[31];
378 } __packed;
379 struct bt_hci_rp_mesh_advertise {
380 	uint8_t      status;
381 	uint8_t      opcode;
382 	uint8_t      adv_slot;
383 } __packed;
384 
385 #define BT_HCI_OC_MESH_ADVERTISE_TIMED         0x03
386 struct bt_hci_cp_mesh_advertise_timed {
387 	uint8_t      adv_slot;
388 	uint8_t      own_addr_type;
389 	bt_addr_t random_addr;
390 	uint8_t      ch_map;
391 	int8_t      tx_power;
392 	uint8_t      retx_count;
393 	uint8_t      retx_interval;
394 	uint32_t     instant;
395 	uint16_t     tx_delay;
396 	uint16_t     tx_window;
397 	uint8_t      data_len;
398 	uint8_t      data[31];
399 } __packed;
400 struct bt_hci_rp_mesh_advertise_timed {
401 	uint8_t      status;
402 	uint8_t      opcode;
403 	uint8_t      adv_slot;
404 } __packed;
405 
406 #define BT_HCI_OC_MESH_ADVERTISE_CANCEL        0x04
407 struct bt_hci_cp_mesh_advertise_cancel {
408 	uint8_t      adv_slot;
409 } __packed;
410 struct bt_hci_rp_mesh_advertise_cancel {
411 	uint8_t      status;
412 	uint8_t      opcode;
413 	uint8_t      adv_slot;
414 } __packed;
415 
416 #define BT_HCI_OC_MESH_SET_SCANNING            0x05
417 struct bt_hci_cp_mesh_set_scanning {
418 	uint8_t      enable;
419 	uint8_t      ch_map;
420 	uint8_t      scan_filter;
421 } __packed;
422 struct bt_hci_rp_mesh_set_scanning {
423 	uint8_t      status;
424 	uint8_t      opcode;
425 } __packed;
426 
427 /* Events */
428 struct bt_hci_evt_mesh {
429 	uint8_t  prefix;
430 	uint8_t  subevent;
431 } __packed;
432 
433 #define BT_HCI_EVT_MESH_ADV_COMPLETE           0x00
434 struct bt_hci_evt_mesh_adv_complete {
435 	uint8_t         adv_slot;
436 } __packed;
437 
438 #define BT_HCI_EVT_MESH_SCANNING_REPORT        0x01
439 struct bt_hci_evt_mesh_scan_report {
440 	bt_addr_le_t addr;
441 	uint8_t         chan;
442 	int8_t         rssi;
443 	uint32_t        instant;
444 	uint8_t         data_len;
445 	uint8_t         data[0];
446 } __packed;
447 struct bt_hci_evt_mesh_scanning_report {
448 	uint8_t num_reports;
449 	struct bt_hci_evt_mesh_scan_report reports[0];
450 } __packed;
451 
452 struct net_buf *hci_vs_err_stack_frame(unsigned int reason, const z_arch_esf_t *esf);
453 struct net_buf *hci_vs_err_trace(const char *file, uint32_t line, uint64_t pc);
454 struct net_buf *hci_vs_err_assert(const char *file, uint32_t line);
455 
456 #ifdef __cplusplus
457 }
458 #endif
459 
460 #endif /* ZEPHYR_INCLUDE_BLUETOOTH_HCI_VS_H_ */
461