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