• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements.  See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership.  The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License.  You may obtain a copy of the License at
9  *
10  *  http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied.  See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  */
19 
20 #ifndef H_BLE_HCI_COMMON_
21 #define H_BLE_HCI_COMMON_
22 
23 #include "ble.h"
24 
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28 
29 #define BLE_HCI_MAX_DATA_LEN (MYNEWT_VAL(BLE_HCI_EVT_BUF_SIZE) - \
30                               sizeof(struct ble_hci_ev))
31 
32 /* Generic command header */
33 struct ble_hci_cmd {
34     uint8_t  hci_type; // preserved for vhci transfering;
35     uint16_t opcode;
36     uint8_t  length;
37     uint8_t  data[0];
38 } __attribute__((packed));
39 
40 /* Generic event header */
41 struct ble_hci_ev {
42     uint8_t opcode;
43     uint8_t length;
44     uint8_t  data[0];
45 } __attribute__((packed));
46 
47 #define BLE_HCI_OPCODE_NOP                  (0)
48 
49 /* Set opcode based on OCF and OGF */
50 #define BLE_HCI_OP(ogf, ocf)            ((ocf) | ((ogf) << 10))
51 
52 /* Get the OGF and OCF from the opcode in the command */
53 #define BLE_HCI_OGF(opcode)                 (((opcode) >> 10) & 0x003F)
54 #define BLE_HCI_OCF(opcode)                 ((opcode) & 0x03FF)
55 
56 /* Opcode Group definitions (note: 0x07 not defined in spec) */
57 #define BLE_HCI_OGF_LINK_CTRL               (0x01)
58 #define BLE_HCI_OGF_LINK_POLICY             (0x02)
59 #define BLE_HCI_OGF_CTLR_BASEBAND           (0x03)
60 #define BLE_HCI_OGF_INFO_PARAMS             (0x04)
61 #define BLE_HCI_OGF_STATUS_PARAMS           (0x05)
62 #define BLE_HCI_OGF_TESTING                 (0x06)
63 #define BLE_HCI_OGF_LE                      (0x08)
64 #define BLE_HCI_OGF_VENDOR                  (0x3F)
65 
66 /*
67  * Number of LE commands. NOTE: this is really just used to size the array
68  * containing the lengths of the LE commands.
69  */
70 #define BLE_HCI_NUM_LE_CMDS                 (79)
71 
72 /* List of OCF for Link Control commands (OGF=0x01) */
73 #define BLE_HCI_OCF_DISCONNECT_CMD          (0x0006)
74 struct ble_hci_lc_disconnect_cp {
75     uint16_t conn_handle;
76     uint8_t  reason;
77 } __attribute__((packed));
78 
79 #define BLE_HCI_OCF_RD_REM_VER_INFO         (0x001D)
80 struct ble_hci_rd_rem_ver_info_cp {
81     uint16_t conn_handle;
82 } __attribute__((packed));
83 
84 /* List of OCF for Controller and Baseband commands (OGF=0x03) */
85 #define BLE_HCI_OCF_CB_SET_EVENT_MASK       (0x0001)
86 struct ble_hci_cb_set_event_mask_cp {
87     uint64_t event_mask;
88 } __attribute__((packed));
89 
90 #define BLE_HCI_OCF_CB_RESET                (0x0003)
91 
92 #define BLE_HCI_OCF_CB_READ_TX_PWR          (0x002D)
93 struct ble_hci_cb_read_tx_pwr_cp {
94     uint16_t conn_handle;
95     uint8_t  type;
96 } __attribute__((packed));
97 
98 struct ble_hci_cb_read_tx_pwr_rp {
99     uint16_t conn_handle;
100     int8_t   tx_level;
101 } __attribute__((packed));
102 
103 #define BLE_HCI_OCF_CB_SET_CTLR_TO_HOST_FC  (0x0031)
104 struct ble_hci_cb_ctlr_to_host_fc_cp {
105     uint8_t enable;
106 } __attribute__((packed));
107 
108 #define BLE_HCI_OCF_CB_HOST_BUF_SIZE        (0x0033)
109 struct ble_hci_cb_host_buf_size_cp {
110     uint16_t acl_data_len;
111     uint16_t sco_data_len;
112     uint16_t acl_num;
113     uint16_t sco_num;
114 } __attribute__((packed));
115 
116 #define BLE_HCI_OCF_CB_HOST_NUM_COMP_PKTS   (0x0035)
117 struct  ble_hci_cb_host_num_comp_pkts_entry {
118     uint16_t handle;
119     uint16_t count;
120 } __attribute__((packed));
121 struct ble_hci_cb_host_num_comp_pkts_cp {
122     uint8_t handles;
123     struct ble_hci_cb_host_num_comp_pkts_entry h[0];
124 } __attribute__((packed));
125 
126 #define BLE_HCI_OCF_CB_SET_EVENT_MASK2      (0x0063)
127 struct ble_hci_cb_set_event_mask2_cp {
128     uint64_t event_mask2;
129 } __attribute__((packed));
130 
131 #define BLE_HCI_OCF_CB_RD_AUTH_PYLD_TMO     (0x007B)
132 struct ble_hci_cb_rd_auth_pyld_tmo_cp {
133     uint16_t conn_handle;
134 } __attribute__((packed));
135 struct ble_hci_cb_rd_auth_pyld_tmo_rp {
136     uint16_t conn_handle;
137     uint16_t tmo;
138 } __attribute__((packed));
139 
140 #define BLE_HCI_OCF_CB_WR_AUTH_PYLD_TMO     (0x007C)
141 struct ble_hci_cb_wr_auth_pyld_tmo_cp {
142     uint16_t conn_handle;
143     uint16_t tmo;
144 } __attribute__((packed));
145 struct ble_hci_cb_wr_auth_pyld_tmo_rp {
146     uint16_t conn_handle;
147 } __attribute__((packed));
148 
149 /* List of OCF for Info Param commands (OGF=0x04) */
150 #define BLE_HCI_OCF_IP_RD_LOCAL_VER         (0x0001)
151 struct ble_hci_ip_rd_local_ver_rp {
152     uint8_t  hci_ver;
153     uint16_t hci_rev;
154     uint8_t  lmp_ver;
155     uint16_t manufacturer;
156     uint16_t lmp_subver;
157 } __attribute__((packed));
158 
159 #define BLE_HCI_OCF_IP_RD_LOC_SUPP_CMD      (0x0002)
160 struct ble_hci_ip_rd_loc_supp_cmd_rp {
161     uint8_t commands[64];
162 } __attribute__((packed));
163 
164 #define BLE_HCI_OCF_IP_RD_LOC_SUPP_FEAT     (0x0003)
165 struct ble_hci_ip_rd_loc_supp_feat_rp {
166     uint64_t features;
167 } __attribute__((packed));
168 
169 #define BLE_HCI_OCF_IP_RD_BUF_SIZE          (0x0005)
170 struct ble_hci_ip_rd_buf_size_rp {
171     uint16_t acl_data_len;
172     uint8_t  sco_data_len;
173     uint16_t acl_num;
174     uint16_t sco_num;
175 } __attribute__((packed));
176 
177 #define BLE_HCI_OCF_IP_RD_BD_ADDR           (0x0009)
178 struct ble_hci_ip_rd_bd_addr_rp {
179     uint8_t addr[6];
180 } __attribute__((packed));
181 
182 /* List of OCF for Status parameters commands (OGF = 0x05) */
183 #define BLE_HCI_OCF_RD_RSSI                 (0x0005)
184 struct ble_hci_rd_rssi_cp {
185     uint16_t handle;
186 } __attribute__((packed));
187 struct ble_hci_rd_rssi_rp {
188     uint16_t handle;
189     int8_t   rssi;
190 } __attribute__((packed));
191 
192 /* List of OCF for LE commands (OGF = 0x08) */
193 #define BLE_HCI_OCF_LE_SET_EVENT_MASK               (0x0001)
194 struct ble_hci_le_set_event_mask_cp {
195     uint64_t event_mask;
196 } __attribute__((packed));
197 
198 #define BLE_HCI_OCF_LE_RD_BUF_SIZE                  (0x0002)
199 struct ble_hci_le_rd_buf_size_rp {
200     uint16_t data_len;
201     uint8_t  data_packets;
202 } __attribute__((packed));
203 
204 #define BLE_HCI_OCF_LE_RD_LOC_SUPP_FEAT             (0x0003)
205 struct ble_hci_le_rd_loc_supp_feat_rp {
206     uint64_t features;
207 } __attribute__((packed));
208 
209 /* NOTE: 0x0004 is intentionally left undefined */
210 #define BLE_HCI_OCF_LE_SET_RAND_ADDR                (0x0005)
211 struct ble_hci_le_set_rand_addr_cp {
212     uint8_t addr[6];
213 } __attribute__((packed));
214 
215 #define BLE_HCI_OCF_LE_SET_ADV_PARAMS               (0x0006)
216 struct ble_hci_le_set_adv_params_cp {
217     uint16_t min_interval;
218     uint16_t max_interval;
219     uint8_t type;
220     uint8_t own_addr_type;
221     uint8_t peer_addr_type;
222     uint8_t peer_addr[6];
223     uint8_t chan_map;
224     uint8_t filter_policy;
225 } __attribute__((packed));
226 
227 #define BLE_HCI_OCF_LE_RD_ADV_CHAN_TXPWR            (0x0007)
228 struct ble_hci_le_rd_adv_chan_txpwr_rp {
229     int8_t power_level;
230 } __attribute__((packed));
231 
232 #define BLE_HCI_OCF_LE_SET_ADV_DATA                 (0x0008)
233 #define BLE_HCI_MAX_ADV_DATA_LEN                    (31)
234 struct ble_hci_le_set_adv_data_cp {
235     uint8_t adv_data_len;
236     uint8_t adv_data[BLE_HCI_MAX_ADV_DATA_LEN];
237 } __attribute__((packed));
238 
239 #define BLE_HCI_OCF_LE_SET_SCAN_RSP_DATA            (0x0009)
240 #define BLE_HCI_MAX_SCAN_RSP_DATA_LEN               (31)
241 struct ble_hci_le_set_scan_rsp_data_cp {
242     uint8_t scan_rsp_len;
243     uint8_t scan_rsp[BLE_HCI_MAX_SCAN_RSP_DATA_LEN];
244 } __attribute__((packed));
245 
246 #define BLE_HCI_OCF_LE_SET_ADV_ENABLE               (0x000A)
247 struct ble_hci_le_set_adv_enable_cp {
248     uint8_t enable;
249 } __attribute__((packed));
250 
251 #define BLE_HCI_OCF_LE_SET_SCAN_PARAMS              (0x000B)
252 struct ble_hci_le_set_scan_params_cp {
253     uint8_t  scan_type;
254     uint16_t scan_itvl;
255     uint16_t scan_window;
256     uint8_t  own_addr_type;
257     uint8_t  filter_policy;
258 } __attribute__((packed));
259 
260 #define BLE_HCI_OCF_LE_SET_SCAN_ENABLE              (0x000C)
261 struct ble_hci_le_set_scan_enable_cp {
262     uint8_t enable;
263     uint8_t filter_duplicates;
264 } __attribute__((packed));
265 
266 #define BLE_HCI_OCF_LE_CREATE_CONN                  (0x000D)
267 struct ble_hci_le_create_conn_cp {
268     uint16_t scan_itvl;
269     uint16_t scan_window;
270     uint8_t  filter_policy;
271     uint8_t  peer_addr_type;
272     uint8_t  peer_addr[6];
273     uint8_t  own_addr_type;
274     uint16_t min_conn_itvl;
275     uint16_t max_conn_itvl;
276     uint16_t conn_latency;
277     uint16_t tmo;
278     uint16_t min_ce;
279     uint16_t max_ce;
280 } __attribute__((packed));
281 
282 #define BLE_HCI_OCF_LE_CREATE_CONN_CANCEL           (0x000E)
283 
284 #define BLE_HCI_OCF_LE_RD_WHITE_LIST_SIZE           (0x000F)
285 struct ble_hci_le_rd_white_list_rp {
286     uint8_t size;
287 } __attribute__((packed));
288 
289 #define BLE_HCI_OCF_LE_CLEAR_WHITE_LIST             (0x0010)
290 
291 #define BLE_HCI_OCF_LE_ADD_WHITE_LIST               (0x0011)
292 struct ble_hci_le_add_whte_list_cp {
293     uint8_t addr_type;
294     uint8_t addr[6];
295 } __attribute__((packed));
296 
297 #define BLE_HCI_OCF_LE_RMV_WHITE_LIST               (0x0012)
298 struct ble_hci_le_rmv_white_list_cp {
299     uint8_t addr_type;
300     uint8_t addr[6];
301 } __attribute__((packed));
302 
303 #define BLE_HCI_OCF_LE_CONN_UPDATE                  (0x0013)
304 struct ble_hci_le_conn_update_cp {
305     uint16_t conn_handle;
306     uint16_t conn_itvl_min;
307     uint16_t conn_itvl_max;
308     uint16_t conn_latency;
309     uint16_t supervision_timeout;
310     uint16_t min_ce_len;
311     uint16_t max_ce_len;
312 } __attribute__((packed));
313 
314 #define BLE_HCI_OCF_LE_SET_HOST_CHAN_CLASS          (0x0014)
315 struct ble_hci_le_set_host_chan_class_cp {
316     uint8_t chan_map[5];
317 } __attribute__((packed));
318 
319 #define BLE_HCI_OCF_LE_RD_CHAN_MAP                  (0x0015)
320 struct ble_hci_le_rd_chan_map_cp {
321     uint16_t conn_handle;
322 } __attribute__((packed));
323 struct ble_hci_le_rd_chan_map_rp {
324     uint16_t conn_handle;
325     uint8_t chan_map[5];
326 } __attribute__((packed));
327 
328 #define BLE_HCI_OCF_LE_RD_REM_FEAT                  (0x0016)
329 struct ble_hci_le_rd_rem_feat_cp {
330     uint16_t conn_handle;
331 } __attribute__((packed));
332 
333 #define BLE_HCI_OCF_LE_ENCRYPT                      (0x0017)
334 struct ble_hci_le_encrypt_cp {
335     uint8_t key[16];
336     uint8_t data[16];
337 } __attribute__((packed));
338 struct ble_hci_le_encrypt_rp {
339     uint8_t data[16];
340 } __attribute__((packed));
341 
342 #define BLE_HCI_OCF_LE_RAND                         (0x0018)
343 struct ble_hci_le_rand_rp {
344     uint64_t random_number;
345 } __attribute__((packed));
346 
347 #define BLE_HCI_OCF_LE_START_ENCRYPT                (0x0019)
348 struct ble_hci_le_start_encrypt_cp {
349     uint16_t conn_handle;
350     uint64_t rand;
351     uint16_t div;
352     uint8_t  ltk[16];
353 } __attribute__((packed));
354 
355 #define BLE_HCI_OCF_LE_LT_KEY_REQ_REPLY             (0x001A)
356 struct ble_hci_le_lt_key_req_reply_cp {
357     uint16_t conn_handle;
358     uint8_t  ltk[16];
359 } __attribute__((packed));
360 struct ble_hci_le_lt_key_req_reply_rp {
361     uint16_t conn_handle;
362 } __attribute__((packed));
363 
364 #define BLE_HCI_OCF_LE_LT_KEY_REQ_NEG_REPLY         (0x001B)
365 struct ble_hci_le_lt_key_req_neg_reply_cp {
366     uint16_t conn_handle;
367 } __attribute__((packed));
368 struct ble_hci_le_lt_key_req_neg_reply_rp {
369     uint16_t conn_handle;
370 } __attribute__((packed));
371 
372 #define BLE_HCI_OCF_LE_RD_SUPP_STATES               (0x001C)
373 struct ble_hci_le_rd_supp_states_rp {
374     uint64_t states;
375 } __attribute__((packed));
376 
377 #define BLE_HCI_OCF_LE_RX_TEST                      (0x001D)
378 struct ble_hci_le_rx_test_cp {
379     uint8_t rx_chan;
380 } __attribute__((packed));
381 
382 #define BLE_HCI_OCF_LE_TX_TEST                      (0x001E)
383 struct ble_hci_le_tx_test_cp {
384     uint8_t tx_chan;
385     uint8_t test_data_len;
386     uint8_t payload;
387 } __attribute__((packed));
388 #if MYNEWT_VAL(BLE_LL_DTM_EXTENSIONS)
389 struct ble_hci_le_tx_test_ext_cp {
390     uint8_t tx_chan;
391     uint8_t test_data_len;
392     uint8_t payload;
393     uint16_t interval;
394     uint16_t pkt_count;
395 } __attribute__((packed));
396 #endif
397 
398 #define BLE_HCI_OCF_LE_TEST_END                     (0x001F)
399 struct ble_hci_le_test_end_rp {
400     uint16_t num_packets;
401 } __attribute__((packed));
402 
403 #define BLE_HCI_OCF_LE_REM_CONN_PARAM_RR            (0x0020)
404 struct ble_hci_le_rem_conn_param_rr_cp {
405     uint16_t conn_handle;
406     uint16_t conn_itvl_min;
407     uint16_t conn_itvl_max;
408     uint16_t conn_latency;
409     uint16_t supervision_timeout;
410     uint16_t min_ce;
411     uint16_t max_ce;
412 } __attribute__((packed));
413 struct ble_hci_le_rem_conn_param_rr_rp {
414     uint16_t conn_handle;
415 } __attribute__((packed));
416 
417 #define BLE_HCI_OCF_LE_REM_CONN_PARAM_NRR           (0x0021)
418 struct ble_hci_le_rem_conn_params_nrr_cp {
419     uint16_t conn_handle;
420     uint8_t  reason;
421 } __attribute__((packed));
422 struct ble_hci_le_rem_conn_params_nrr_rp {
423     uint16_t conn_handle;
424 } __attribute__((packed));
425 
426 #define BLE_HCI_OCF_LE_SET_DATA_LEN                 (0x0022)
427 struct ble_hci_le_set_data_len_cp {
428     uint16_t conn_handle;
429     uint16_t tx_octets;
430     uint16_t tx_time;
431 } __attribute__((packed));
432 struct ble_hci_le_set_data_len_rp {
433     uint16_t conn_handle;
434 } __attribute__((packed));
435 
436 #define BLE_HCI_OCF_LE_RD_SUGG_DEF_DATA_LEN         (0x0023)
437 struct ble_hci_le_rd_sugg_def_data_len_rp {
438     uint16_t max_tx_octets;
439     uint16_t max_tx_time;
440 } __attribute__((packed));
441 
442 #define BLE_HCI_OCF_LE_WR_SUGG_DEF_DATA_LEN         (0x0024)
443 struct ble_hci_le_wr_sugg_def_data_len_cp {
444     uint16_t max_tx_octets;
445     uint16_t max_tx_time;
446 } __attribute__((packed));
447 
448 #define BLE_HCI_OCF_LE_RD_P256_PUBKEY               (0x0025)
449 
450 #define BLE_HCI_OCF_LE_GEN_DHKEY                    (0x0026)
451 struct ble_hci_le_gen_dhkey_cp {
452     uint8_t pkey[64];
453 } __attribute__((packed));
454 
455 #define BLE_HCI_OCF_LE_ADD_RESOLV_LIST              (0x0027)
456 struct ble_hci_le_add_resolv_list_cp {
457     uint8_t peer_addr_type;
458     uint8_t peer_id_addr[6];
459     uint8_t peer_irk[16];
460     uint8_t local_irk[16];
461 } __attribute__((packed));
462 
463 #define BLE_HCI_OCF_LE_RMV_RESOLV_LIST              (0x0028)
464 struct ble_hci_le_rmv_resolve_list_cp {
465     uint8_t peer_addr_type;
466     uint8_t peer_id_addr[6];
467 } __attribute__((packed));
468 
469 #define BLE_HCI_OCF_LE_CLR_RESOLV_LIST              (0x0029)
470 
471 #define BLE_HCI_OCF_LE_RD_RESOLV_LIST_SIZE          (0x002A)
472 struct ble_hci_le_rd_resolv_list_size_rp {
473     uint8_t size;
474 } __attribute__((packed));
475 
476 #define BLE_HCI_OCF_LE_RD_PEER_RESOLV_ADDR          (0x002B)
477 struct ble_hci_le_rd_peer_recolv_addr_cp {
478     uint8_t peer_addr_type;
479     uint8_t peer_id_addr[6];
480 } __attribute__((packed));
481 struct ble_hci_le_rd_peer_recolv_addr_rp {
482     uint8_t rpa[6];
483 } __attribute__((packed));
484 
485 #define BLE_HCI_OCF_LE_RD_LOCAL_RESOLV_ADDR         (0x002C)
486 struct ble_hci_le_rd_local_recolv_addr_cp {
487     uint8_t peer_addr_type;
488     uint8_t peer_id_addr[6];
489 } __attribute__((packed));
490 struct ble_hci_le_rd_local_recolv_addr_rp {
491     uint8_t rpa[6];
492 } __attribute__((packed));
493 
494 #define BLE_HCI_OCF_LE_SET_ADDR_RES_EN              (0x002D)
495 struct ble_hci_le_set_addr_res_en_cp {
496     uint8_t enable;
497 } __attribute__((packed));
498 
499 #define BLE_HCI_OCF_LE_SET_RPA_TMO                  (0x002E)
500 struct ble_hci_le_set_rpa_tmo_cp {
501     uint16_t rpa_timeout;
502 } __attribute__((packed));
503 
504 #define BLE_HCI_OCF_LE_RD_MAX_DATA_LEN              (0x002F)
505 struct ble_hci_le_rd_max_data_len_rp {
506     uint16_t max_tx_octests;
507     uint16_t max_tx_time;
508     uint16_t max_rx_octests;
509     uint16_t max_rx_time;
510 } __attribute__((packed));
511 
512 #define BLE_HCI_OCF_LE_RD_PHY                       (0x0030)
513 struct ble_hci_le_rd_phy_cp {
514     uint16_t conn_handle;
515 } __attribute__((packed));
516 struct ble_hci_le_rd_phy_rp {
517     uint16_t conn_handle;
518     uint8_t tx_phy;
519     uint8_t rx_phy;
520 } __attribute__((packed));
521 
522 #define BLE_HCI_OCF_LE_SET_DEFAULT_PHY              (0x0031)
523 struct ble_hci_le_set_default_phy_cp {
524     uint8_t all_phys;
525     uint8_t tx_phys;
526     uint8_t rx_phys;
527 } __attribute__((packed));
528 
529 #define BLE_HCI_OCF_LE_SET_PHY                      (0x0032)
530 struct ble_hci_le_set_phy_cp {
531     uint16_t conn_handle;
532     uint8_t all_phys;
533     uint8_t tx_phys;
534     uint8_t rx_phys;
535     uint16_t phy_options;
536 } __attribute__((packed));
537 
538 #define BLE_HCI_OCF_LE_RX_TEST_V2                  (0x0033)
539 struct ble_hci_le_rx_test_v2_cp {
540     uint8_t rx_chan;
541     uint8_t phy;
542     uint8_t index;
543 } __attribute__((packed));
544 
545 #define BLE_HCI_OCF_LE_TX_TEST_V2                  (0x0034)
546 struct ble_hci_le_tx_test_v2_cp {
547     uint8_t tx_chan;
548     uint8_t test_data_len;
549     uint8_t payload;
550     uint8_t phy;
551 } __attribute__((packed));
552 #if MYNEWT_VAL(BLE_LL_DTM_EXTENSIONS)
553 struct ble_hci_le_tx_test_v2_ext_cp {
554     uint8_t tx_chan;
555     uint8_t test_data_len;
556     uint8_t payload;
557     uint8_t phy;
558     uint16_t interval;
559     uint16_t pkt_count;
560 } __attribute__((packed));
561 #endif
562 
563 #define BLE_HCI_OCF_LE_SET_ADV_SET_RND_ADDR         (0x0035)
564 struct ble_hci_le_set_adv_set_rnd_addr_cp {
565     uint8_t adv_handle;
566     uint8_t addr[6];
567 } __attribute__((packed));
568 
569 #define BLE_HCI_OCF_LE_SET_EXT_ADV_PARAM            (0x0036)
570 struct ble_hci_le_set_ext_adv_params_cp {
571     uint8_t  adv_handle;
572     uint16_t props;
573     uint8_t  pri_itvl_min[3];
574     uint8_t  pri_itvl_max[3];
575     uint8_t pri_chan_map;
576     uint8_t own_addr_type;
577     uint8_t peer_addr_type;
578     uint8_t peer_addr[6];
579     uint8_t filter_policy;
580     int8_t tx_power;
581     uint8_t pri_phy;
582     uint8_t sec_max_skip;
583     uint8_t sec_phy;
584     uint8_t sid;
585     uint8_t scan_req_notif;
586 } __attribute__((packed));
587 struct ble_hci_le_set_ext_adv_params_rp {
588     int8_t  tx_power;
589 } __attribute__((packed));
590 
591 #define BLE_HCI_OCF_LE_SET_EXT_ADV_DATA             (0x0037)
592 struct ble_hci_le_set_ext_adv_data_cp {
593     uint8_t adv_handle;
594     uint8_t operation;
595     uint8_t fragment_pref;
596     uint8_t adv_data_len;
597     uint8_t adv_data[0];
598 } __attribute__((packed));
599 
600 #define BLE_HCI_OCF_LE_SET_EXT_SCAN_RSP_DATA        (0x0038)
601 struct ble_hci_le_set_ext_scan_rsp_data_cp {
602     uint8_t adv_handle;
603     uint8_t operation;
604     uint8_t fragment_pref;
605     uint8_t scan_rsp_len;
606     uint8_t scan_rsp[0];
607 } __attribute__((packed));
608 
609 #define BLE_HCI_OCF_LE_SET_EXT_ADV_ENABLE           (0x0039)
610 struct adv_set {
611     uint8_t adv_handle;
612     uint16_t duration;
613     uint8_t max_events;
614 } __attribute__((packed));
615 struct ble_hci_le_set_ext_adv_enable_cp {
616     uint8_t enable;
617     uint8_t num_sets;
618     struct adv_set sets[0];
619 } __attribute__((packed));
620 
621 #define BLE_HCI_OCF_LE_RD_MAX_ADV_DATA_LEN          (0x003A)
622 struct ble_hci_le_rd_max_adv_data_len_rp {
623     uint16_t max_adv_data_len;
624 } __attribute__((packed));
625 
626 #define BLE_HCI_OCF_LE_RD_NUM_OF_ADV_SETS           (0x003B)
627 struct ble_hci_le_rd_num_of_adv_sets_rp {
628     uint8_t num_sets;
629 } __attribute__((packed));
630 
631 #define BLE_HCI_OCF_LE_REMOVE_ADV_SET               (0x003C)
632 struct ble_hci_le_remove_adv_set_cp {
633     uint8_t adv_handle;
634 } __attribute__((packed));
635 
636 #define BLE_HCI_OCF_LE_CLEAR_ADV_SETS               (0x003D)
637 
638 #define BLE_HCI_OCF_LE_SET_PERIODIC_ADV_PARAMS      (0x003E)
639 struct ble_hci_le_set_periodic_adv_params_cp {
640     uint8_t adv_handle;
641     uint16_t min_itvl;
642     uint16_t max_itvl;
643     uint16_t props;
644 } __attribute__((packed));
645 
646 #define BLE_HCI_OCF_LE_SET_PERIODIC_ADV_DATA        (0x003F)
647 struct ble_hci_le_set_periodic_adv_data_cp {
648     uint8_t adv_handle;
649     uint8_t operation;
650     uint8_t adv_data_len;
651     uint8_t adv_data[0];
652 } __attribute__((packed));
653 
654 #define BLE_HCI_OCF_LE_SET_PERIODIC_ADV_ENABLE      (0x0040)
655 struct ble_hci_le_set_periodic_adv_enable_cp {
656     uint8_t enable;
657     uint8_t adv_handle;
658 } __attribute__((packed));
659 
660 #define BLE_HCI_OCF_LE_SET_EXT_SCAN_PARAM           (0x0041)
661 struct scan_params {
662     uint8_t  type;
663     uint16_t itvl;
664     uint16_t window;
665 } __attribute__((packed));
666 struct ble_hci_le_set_ext_scan_params_cp {
667     uint8_t own_addr_type;
668     uint8_t filter_policy;
669     uint8_t phys;
670     struct scan_params scans[0];
671 } __attribute__((packed));
672 
673 #define BLE_HCI_OCF_LE_SET_EXT_SCAN_ENABLE          (0x0042)
674 struct ble_hci_le_set_ext_scan_enable_cp {
675     uint8_t  enable;
676     uint8_t  filter_dup;
677     uint16_t duration;
678     uint16_t period;
679 } __attribute__((packed));
680 
681 #define BLE_HCI_OCF_LE_EXT_CREATE_CONN              (0x0043)
682 struct conn_params {
683     uint16_t scan_itvl;
684     uint16_t scan_window;
685     uint16_t conn_min_itvl;
686     uint16_t conn_max_itvl;
687     uint16_t conn_latency;
688     uint16_t supervision_timeout;
689     uint16_t min_ce;
690     uint16_t max_ce;
691 } __attribute__((packed));
692 struct ble_hci_le_ext_create_conn_cp {
693     uint8_t filter_policy;
694     uint8_t own_addr_type;
695     uint8_t peer_addr_type;
696     uint8_t peer_addr[6];
697     uint8_t init_phy_mask;
698     struct conn_params conn_params[0];
699 } __attribute__((packed));
700 
701 #define BLE_HCI_LE_PERIODIC_ADV_CREATE_SYNC_OPT_FILTER      0x01
702 #define BLE_HCI_LE_PERIODIC_ADV_CREATE_SYNC_OPT_DISABLED    0x02
703 
704 #define BLE_HCI_OCF_LE_PERIODIC_ADV_CREATE_SYNC          (0x0044)
705 struct ble_hci_le_periodic_adv_create_sync_cp {
706     uint8_t  options;
707     uint8_t  sid;
708     uint8_t  peer_addr_type;
709     uint8_t  peer_addr[6];
710     uint16_t skip;
711     uint16_t sync_timeout;
712     uint8_t  sync_cte_type;
713 } __attribute__((packed));
714 
715 #define BLE_HCI_OCF_LE_PERIODIC_ADV_CREATE_SYNC_CANCEL   (0x0045)
716 
717 #define BLE_HCI_OCF_LE_PERIODIC_ADV_TERM_SYNC            (0x0046)
718 struct ble_hci_le_periodic_adv_term_sync_cp {
719     uint16_t sync_handle;
720 } __attribute__((packed));
721 
722 #define BLE_HCI_OCF_LE_ADD_DEV_TO_PERIODIC_ADV_LIST      (0x0047)
723 struct ble_hci_le_add_dev_to_periodic_adv_list_cp {
724     uint8_t peer_addr_type;
725     uint8_t peer_addr[6];
726     uint8_t sid;
727 } __attribute__((packed));
728 
729 #define BLE_HCI_OCF_LE_REM_DEV_FROM_PERIODIC_ADV_LIST    (0x0048)
730 struct ble_hci_le_rem_dev_from_periodic_adv_list_cp {
731     uint8_t peer_addr_type;
732     uint8_t peer_addr[6];
733     uint8_t sid;
734 } __attribute__((packed));
735 
736 #define BLE_HCI_OCF_LE_CLEAR_PERIODIC_ADV_LIST           (0x0049)
737 
738 #define BLE_HCI_OCF_LE_RD_PERIODIC_ADV_LIST_SIZE         (0x004A)
739 struct ble_hci_le_rd_periodic_adv_list_size_rp {
740     uint8_t list_size;
741 } __attribute__((packed));
742 
743 #define BLE_HCI_OCF_LE_RD_TRANSMIT_POWER            (0x004B)
744 struct ble_hci_le_rd_transmit_power_rp {
745     int8_t min_tx_power;
746     int8_t max_tx_power;
747 } __attribute__((packed));
748 
749 #define BLE_HCI_OCF_LE_RD_RF_PATH_COMPENSATION      (0x004C)
750 struct ble_hci_le_rd_rf_path_compensation_rp {
751     int16_t tx_path_compensation;
752     int16_t rx_path_compensation;
753 } __attribute__((packed));
754 
755 #define BLE_HCI_OCF_LE_WR_RF_PATH_COMPENSATION      (0x004D)
756 struct ble_hci_le_wr_rf_path_compensation_cp {
757     int16_t tx_path_compensation;
758     int16_t rx_path_compensation;
759 } __attribute__((packed));
760 
761 #define BLE_HCI_OCF_LE_SET_PRIVACY_MODE             (0x004E)
762 struct ble_hci_le_set_privacy_mode_cp {
763     uint8_t peer_id_addr_type;
764     uint8_t peer_id_addr[6];
765     uint8_t mode;
766 } __attribute__((packed));
767 
768 #define BLE_HCI_OCF_LE_RX_TEST_V3                        (0x004F)
769 #define BLE_HCI_OCF_LE_TX_TEST_V3                        (0x0050)
770 #define BLE_HCI_OCF_LE_SET_CONNLESS_CTE_TX_PARAMS        (0x0051)
771 #define BLE_HCI_OCF_LE_SET_CONNLESS_CTE_TX_ENABLE        (0x0052)
772 #define BLE_HCI_OCF_LE_SET_CONNLESS_IQ_SAMPLING_ENABLE   (0x0053)
773 #define BLE_HCI_OCF_LE_SET_CONN_CTE_RX_PARAMS            (0x0054)
774 #define BLE_HCI_OCF_LE_SET_CONN_CTE_TX_PARAMS            (0x0055)
775 #define BLE_HCI_OCF_LE_SET_CONN_CTE_REQ_ENABLE           (0x0056)
776 #define BLE_HCI_OCF_LE_SET_CONN_CTE_RESP_ENABLE          (0x0057)
777 #define BLE_HCI_OCF_LE_RD_ANTENNA_INFO                   (0x0058)
778 
779 #define BLE_HCI_OCF_LE_PERIODIC_ADV_RECEIVE_ENABLE       (0x0059)
780 struct ble_hci_le_periodic_adv_receive_enable_cp {
781     uint16_t sync_handle;
782     uint8_t enable;
783 } __attribute__((packed));
784 
785 #define BLE_HCI_OCF_LE_PERIODIC_ADV_SYNC_TRANSFER        (0x005A)
786 struct ble_hci_le_periodic_adv_sync_transfer_cp {
787     uint16_t conn_handle;
788     uint16_t service_data;
789     uint16_t sync_handle;
790 } __attribute__((packed));
791 struct ble_hci_le_periodic_adv_sync_transfer_rp {
792     uint16_t conn_handle;
793 } __attribute__((packed));
794 
795 #define BLE_HCI_OCF_LE_PERIODIC_ADV_SET_INFO_TRANSFER    (0x005B)
796 struct ble_hci_le_periodic_adv_set_info_transfer_cp {
797     uint16_t conn_handle;
798     uint16_t service_data;
799     uint8_t adv_handle;
800 } __attribute__((packed));
801 struct ble_hci_le_periodic_adv_set_info_transfer_rp {
802     uint16_t conn_handle;
803 } __attribute__((packed));
804 
805 #define BLE_HCI_OCF_LE_PERIODIC_ADV_SYNC_TRANSFER_PARAMS (0x005C)
806 struct ble_hci_le_periodic_adv_sync_transfer_params_cp {
807     uint16_t conn_handle;
808     uint8_t  mode;
809     uint16_t skip;
810     uint16_t sync_timeout;
811     uint8_t  sync_cte_type;
812 } __attribute__((packed));
813 struct ble_hci_le_periodic_adv_sync_transfer_params_rp {
814     uint16_t conn_handle;
815 } __attribute__((packed));
816 
817 #define BLE_HCI_OCF_LE_SET_DEFAULT_SYNC_TRANSFER_PARAMS  (0x005D)
818 struct ble_hci_le_set_default_periodic_sync_transfer_params_cp {
819     uint8_t  mode;
820     uint16_t skip;
821     uint16_t sync_timeout;
822     uint8_t  sync_cte_type;
823 } __attribute__((packed));
824 
825 #define BLE_HCI_OCF_LE_GENERATE_DHKEY_V2                 (0x005E)
826 #define BLE_HCI_OCF_LE_MODIFY_SCA                        (0x005F)
827 
828 #define BLE_HCI_OCF_LE_SET_HOST_FEAT                     (0x0074)
829 struct ble_hci_le_set_host_feat_cp {
830     uint8_t bit_num;
831     uint8_t val;
832 } __attribute__((packed));
833 
834 /* Command Specific Definitions */
835 /* --- Set controller to host flow control (OGF 0x03, OCF 0x0031) --- */
836 #define BLE_HCI_CTLR_TO_HOST_FC_OFF         (0)
837 #define BLE_HCI_CTLR_TO_HOST_FC_ACL         (1)
838 #define BLE_HCI_CTLR_TO_HOST_FC_SYNC        (2)
839 #define BLE_HCI_CTLR_TO_HOST_FC_BOTH        (3)
840 
841 /* --- LE set advertising parameters (OCF 0x0006) */
842 /* Advertising types */
843 #define BLE_HCI_ADV_TYPE_ADV_IND            (0)
844 #define BLE_HCI_ADV_TYPE_ADV_DIRECT_IND_HD  (1)
845 #define BLE_HCI_ADV_TYPE_ADV_SCAN_IND       (2)
846 #define BLE_HCI_ADV_TYPE_ADV_NONCONN_IND    (3)
847 #define BLE_HCI_ADV_TYPE_ADV_DIRECT_IND_LD  (4)
848 #define BLE_HCI_ADV_TYPE_MAX                (4)
849 
850 #define BLE_HCI_ADV_CONN_MASK               (0x0001)
851 #define BLE_HCI_ADV_SCAN_MASK               (0x0002)
852 #define BLE_HCI_ADV_DIRECT_MASK             (0x0004)
853 #define BLE_HCI_ADV_SCAN_RSP_MASK           (0x0008)
854 #define BLE_HCI_ADV_LEGACY_MASK             (0x0010)
855 
856 #define BLE_HCI_ADV_DATA_STATUS_COMPLETE    (0x0000)
857 #define BLE_HCI_ADV_DATA_STATUS_INCOMPLETE  (0x0020)
858 #define BLE_HCI_ADV_DATA_STATUS_TRUNCATED   (0x0040)
859 #define BLE_HCI_ADV_DATA_STATUS_MASK        (0x0060)
860 
861 /* Own address types */
862 #define BLE_HCI_ADV_OWN_ADDR_PUBLIC         (0)
863 #define BLE_HCI_ADV_OWN_ADDR_RANDOM         (1)
864 #define BLE_HCI_ADV_OWN_ADDR_PRIV_PUB       (2)
865 #define BLE_HCI_ADV_OWN_ADDR_PRIV_RAND      (3)
866 #define BLE_HCI_ADV_OWN_ADDR_MAX            (3)
867 
868 /* Advertisement peer address Type */
869 #define BLE_HCI_ADV_PEER_ADDR_PUBLIC        (0)
870 #define BLE_HCI_ADV_PEER_ADDR_RANDOM        (1)
871 #define BLE_HCI_ADV_PEER_ADDR_MAX           (1)
872 
873 /* --- LE advertising channel tx power (OCF 0x0007) */
874 #define BLE_HCI_ADV_CHAN_TXPWR_MIN             (-20)
875 #define BLE_HCI_ADV_CHAN_TXPWR_MAX             (10)
876 
877 /* --- LE set scan enable (OCF 0x000c) */
878 
879 /* Connect peer address type */
880 #define BLE_HCI_CONN_PEER_ADDR_PUBLIC        (0)
881 #define BLE_HCI_CONN_PEER_ADDR_RANDOM        (1)
882 #define BLE_HCI_CONN_PEER_ADDR_PUBLIC_IDENT  (2)
883 #define BLE_HCI_CONN_PEER_ADDR_RANDOM_IDENT  (3)
884 #define BLE_HCI_CONN_PEER_ADDR_MAX           (3)
885 
886 /*
887  * Advertising filter policy
888  *
889  * Determines how an advertiser filters scan and connection requests.
890  *
891  *  NONE: no filtering (default value). No whitelist used.
892  *  SCAN: process all connection requests but only scans from white list.
893  *  CONN: process all scan request but only connection requests from white list
894  *  BOTH: ignore all scan and connection requests unless in white list.
895  */
896 #define BLE_HCI_ADV_FILT_NONE               (0)
897 #define BLE_HCI_ADV_FILT_SCAN               (1)
898 #define BLE_HCI_ADV_FILT_CONN               (2)
899 #define BLE_HCI_ADV_FILT_BOTH               (3)
900 #define BLE_HCI_ADV_FILT_MAX                (3)
901 
902 #define BLE_HCI_ADV_FILT_DEF                (BLE_HCI_ADV_FILT_NONE)
903 
904 /* Advertising interval */
905 #define BLE_HCI_ADV_ITVL                    (625)           /* usecs */
906 #define BLE_HCI_ADV_ITVL_MIN                (32)            /* units */
907 #define BLE_HCI_ADV_ITVL_MAX                (16384)         /* units */
908 #define BLE_HCI_ADV_ITVL_NONCONN_MIN        (160)           /* units */
909 
910 #define BLE_HCI_ADV_ITVL_DEF                (0x800)         /* 1.28 seconds */
911 #define BLE_HCI_ADV_CHANMASK_DEF            (0x7)           /* all channels */
912 
913 /* Set scan parameters */
914 #define BLE_HCI_SCAN_TYPE_PASSIVE           (0)
915 #define BLE_HCI_SCAN_TYPE_ACTIVE            (1)
916 
917 /* Scan interval and scan window timing */
918 #define BLE_HCI_SCAN_ITVL                   (625)           /* usecs */
919 #define BLE_HCI_SCAN_ITVL_MIN               (4)             /* units */
920 #define BLE_HCI_SCAN_ITVL_MAX               (16384)         /* units */
921 #define BLE_HCI_SCAN_ITVL_DEF               (16)            /* units */
922 #define BLE_HCI_SCAN_WINDOW_MIN             (4)             /* units */
923 #define BLE_HCI_SCAN_WINDOW_MAX             (16384)         /* units */
924 #define BLE_HCI_SCAN_WINDOW_DEF             (16)            /* units */
925 
926 /*
927  * Scanning filter policy
928  *  NO_WL:
929  *      Scanner processes all advertising packets (white list not used) except
930  *      directed, connectable advertising packets not sent to the scanner.
931  *  USE_WL:
932  *      Scanner processes advertisements from white list only. A connectable,
933  *      directed advertisment is ignored unless it contains scanners address.
934  *  NO_WL_INITA:
935  *      Scanner process all advertising packets (white list not used). A
936  *      connectable, directed advertisement shall not be ignored if the InitA
937  *      is a resolvable private address.
938  *  USE_WL_INITA:
939  *      Scanner process advertisements from white list only. A connectable,
940  *      directed advertisement shall not be ignored if the InitA is a
941  *      resolvable private address.
942  */
943 #define BLE_HCI_SCAN_FILT_NO_WL             (0)
944 #define BLE_HCI_SCAN_FILT_USE_WL            (1)
945 #define BLE_HCI_SCAN_FILT_NO_WL_INITA       (2)
946 #define BLE_HCI_SCAN_FILT_USE_WL_INITA      (3)
947 #define BLE_HCI_SCAN_FILT_MAX               (3)
948 
949 /* Whitelist commands */
950 #define BLE_HCI_ADD_WHITE_LIST_LEN          (7)
951 #define BLE_HCI_RMV_WHITE_LIST_LEN          (7)
952 
953 /* Create Connection */
954 #define BLE_HCI_CREATE_CONN_LEN             (25)
955 #define BLE_HCI_CONN_ITVL                   (1250)  /* usecs */
956 #define BLE_HCI_CONN_FILT_NO_WL             (0)
957 #define BLE_HCI_CONN_FILT_USE_WL            (1)
958 #define BLE_HCI_CONN_FILT_MAX               (1)
959 #define BLE_HCI_CONN_ITVL_MIN               (0x0006)
960 #define BLE_HCI_CONN_ITVL_MAX               (0x0c80)
961 #define BLE_HCI_CONN_LATENCY_MIN            (0x0000)
962 #define BLE_HCI_CONN_LATENCY_MAX            (0x01f3)
963 #define BLE_HCI_CONN_SPVN_TIMEOUT_MIN       (0x000a)
964 #define BLE_HCI_CONN_SPVN_TIMEOUT_MAX       (0x0c80)
965 #define BLE_HCI_CONN_SPVN_TMO_UNITS         (10)    /* msecs */
966 #define BLE_HCI_INITIATOR_FILT_POLICY_MAX   (1)
967 
968 /* Peer Address Type */
969 #define BLE_HCI_CONN_PEER_ADDR_PUBLIC       (0)
970 #define BLE_HCI_CONN_PEER_ADDR_RANDOM       (1)
971 #define BLE_HCI_CONN_PEER_ADDR_PUB_ID       (2)
972 #define BLE_HCI_CONN_PEER_ADDR_RAND_ID      (3)
973 #define BLE_HCI_CONN_PEER_ADDR_MAX          (3)
974 
975 /* --- LE set data length (OCF 0x0022) */
976 #define BLE_HCI_SET_DATALEN_TX_OCTETS_MIN   (0x001b)
977 #define BLE_HCI_SET_DATALEN_TX_OCTETS_MAX   (0x00fb)
978 #define BLE_HCI_SET_DATALEN_TX_TIME_MIN     (0x0148)
979 #define BLE_HCI_SET_DATALEN_TX_TIME_MAX     (0x4290)
980 
981 /* --- LE read maximum default PHY (OCF 0x0030) */
982 #define BLE_HCI_LE_PHY_1M                   (1)
983 #define BLE_HCI_LE_PHY_2M                   (2)
984 #define BLE_HCI_LE_PHY_CODED                (3)
985 
986 /* --- LE set default PHY (OCF 0x0031) */
987 #define BLE_HCI_LE_PHY_NO_TX_PREF_MASK              (0x01)
988 #define BLE_HCI_LE_PHY_NO_RX_PREF_MASK              (0x02)
989 #define BLE_HCI_LE_PHY_1M_PREF_MASK                 (0x01)
990 #define BLE_HCI_LE_PHY_2M_PREF_MASK                 (0x02)
991 #define BLE_HCI_LE_PHY_CODED_PREF_MASK              (0x04)
992 
993 #define BLE_HCI_LE_PHY_PREF_MASK_ALL                \
994     (BLE_HCI_LE_PHY_1M_PREF_MASK | BLE_HCI_LE_PHY_2M_PREF_MASK |  \
995      BLE_HCI_LE_PHY_CODED_PREF_MASK)
996 
997 /* --- LE set PHY (OCF 0x0032) */
998 #define BLE_HCI_LE_PHY_CODED_ANY                    (0x0000)
999 #define BLE_HCI_LE_PHY_CODED_S2_PREF                (0x0001)
1000 #define BLE_HCI_LE_PHY_CODED_S8_PREF                (0x0002)
1001 
1002 /* --- LE enhanced receiver test (OCF 0x0033) */
1003 #define BLE_HCI_LE_PHY_1M                           (1)
1004 #define BLE_HCI_LE_PHY_2M                           (2)
1005 #define BLE_HCI_LE_PHY_CODED                        (3)
1006 
1007 /* --- LE enhanced transmitter test (OCF 0x0034) */
1008 #define BLE_HCI_LE_PHY_CODED_S8                     (3)
1009 #define BLE_HCI_LE_PHY_CODED_S2                     (4)
1010 
1011 /* --- LE set extended advertising parameters (OCF 0x0036) */
1012 #define BLE_HCI_LE_SET_EXT_ADV_PROP_CONNECTABLE     (0x0001)
1013 #define BLE_HCI_LE_SET_EXT_ADV_PROP_SCANNABLE       (0x0002)
1014 #define BLE_HCI_LE_SET_EXT_ADV_PROP_DIRECTED        (0x0004)
1015 #define BLE_HCI_LE_SET_EXT_ADV_PROP_HD_DIRECTED     (0x0008)
1016 #define BLE_HCI_LE_SET_EXT_ADV_PROP_LEGACY          (0x0010)
1017 #define BLE_HCI_LE_SET_EXT_ADV_PROP_ANON_ADV        (0x0020)
1018 #define BLE_HCI_LE_SET_EXT_ADV_PROP_INC_TX_PWR      (0x0040)
1019 #define BLE_HCI_LE_SET_EXT_ADV_PROP_MASK            (0x7F)
1020 
1021 #define BLE_HCI_LE_SET_EXT_ADV_PROP_LEGACY_IND      (0x0013)
1022 #define BLE_HCI_LE_SET_EXT_ADV_PROP_LEGACY_LD_DIR   (0x0015)
1023 #define BLE_HCI_LE_SET_EXT_ADV_PROP_LEGACY_HD_DIR   (0x001d)
1024 #define BLE_HCI_LE_SET_EXT_ADV_PROP_LEGACY_SCAN     (0x0012)
1025 #define BLE_HCI_LE_SET_EXT_ADV_PROP_LEGACY_NONCONN  (0x0010)
1026 
1027 /* --- LE set extended advertising data (OCF 0x0037) */
1028 #define BLE_HCI_MAX_EXT_ADV_DATA_LEN                (251)
1029 
1030 #define BLE_HCI_LE_SET_DATA_OPER_INT        (0)
1031 #define BLE_HCI_LE_SET_DATA_OPER_FIRST      (1)
1032 #define BLE_HCI_LE_SET_DATA_OPER_LAST       (2)
1033 #define BLE_HCI_LE_SET_DATA_OPER_COMPLETE   (3)
1034 #define BLE_HCI_LE_SET_DATA_OPER_UNCHANGED  (4)
1035 
1036 /* --- LE set extended scan response data (OCF 0x0038) */
1037 #define BLE_HCI_MAX_EXT_SCAN_RSP_DATA_LEN           (251)
1038 
1039 /* --- LE set periodic advertising parameters (OCF 0x003E) */
1040 #define BLE_HCI_LE_SET_PERIODIC_ADV_PROP_INC_TX_PWR (0x0040)
1041 #define BLE_HCI_LE_SET_PERIODIC_ADV_PROP_MASK       (0x0040)
1042 
1043 /* --- LE set periodic advertising data (OCF 0x003F) */
1044 #define BLE_HCI_MAX_PERIODIC_ADV_DATA_LEN                (252)
1045 
1046 /* --- LE remove device from periodic advertising list (OCF 0x0048) */
1047 #define BLE_HCI_PERIODIC_DATA_STATUS_COMPLETE   0x00
1048 #define BLE_HCI_PERIODIC_DATA_STATUS_INCOMPLETE 0x01
1049 #define BLE_HCI_PERIODIC_DATA_STATUS_TRUNCATED  0x02
1050 
1051 /* --- LE set privacy mode (OCF 0x004E) */
1052 #define BLE_HCI_PRIVACY_NETWORK                     (0)
1053 #define BLE_HCI_PRIVACY_DEVICE                      (1)
1054 
1055 /* Event Codes */
1056 #define BLE_HCI_EVCODE_INQUIRY_CMP          (0x01)
1057 #define BLE_HCI_EVCODE_INQUIRY_RESULT       (0x02)
1058 #define BLE_HCI_EVCODE_CONN_DONE            (0x03)
1059 #define BLE_HCI_EVCODE_CONN_REQUEST         (0x04)
1060 #define BLE_HCI_EVCODE_DISCONN_CMP          (0x05)
1061 struct ble_hci_ev_disconn_cmp {
1062     uint8_t status;
1063     uint16_t conn_handle;
1064     uint8_t reason;
1065 } __attribute__((packed));
1066 
1067 #define BLE_HCI_EVCODE_AUTH_CMP             (0x06)
1068 #define BLE_HCI_EVCODE_REM_NAME_REQ_CMP     (0x07)
1069 
1070 #define BLE_HCI_EVCODE_ENCRYPT_CHG          (0x08)
1071 struct ble_hci_ev_enrypt_chg {
1072     uint8_t status;
1073     uint16_t connection_handle;
1074     uint8_t enabled;
1075 } __attribute__((packed));
1076 
1077 #define BLE_HCI_EVCODE_CHG_LINK_KEY_CMP     (0x09)
1078 #define BLE_HCI_EVCODE_MASTER_LINK_KEY_CMP  (0x0A)
1079 #define BLE_HCI_EVCODE_RD_REM_SUPP_FEAT_CMP (0x0B)
1080 #define BLE_HCI_EVCODE_RD_REM_VER_INFO_CMP  (0x0C)
1081 struct ble_hci_ev_rd_rem_ver_info_cmp {
1082     uint8_t  status;
1083     uint16_t conn_handle;
1084     uint8_t  version;
1085     uint16_t manufacturer;
1086     uint16_t subversion;
1087 } __attribute__((packed));
1088 
1089 #define BLE_HCI_EVCODE_QOS_SETUP_CMP        (0x0D)
1090 
1091 #define BLE_HCI_EVCODE_COMMAND_COMPLETE     (0x0E)
1092 struct ble_hci_ev_command_complete {
1093     uint8_t  num_packets;
1094     uint16_t opcode;
1095     uint8_t  status;
1096     uint8_t  return_params[0];
1097 } __attribute__((packed));
1098 /* NOP is exception and has no return parameters */
1099 struct ble_hci_ev_command_complete_nop {
1100     uint8_t  num_packets;
1101     uint16_t opcode;
1102 } __attribute__((packed));
1103 
1104 #define BLE_HCI_EVCODE_COMMAND_STATUS       (0x0F)
1105 struct ble_hci_ev_command_status {
1106     uint8_t status;
1107     uint8_t  num_packets;
1108     uint16_t opcode;
1109 } __attribute__((packed));
1110 
1111 #define BLE_HCI_EVCODE_HW_ERROR             (0x10)
1112 struct ble_hci_ev_hw_error {
1113     uint8_t hw_code;
1114 } __attribute__((packed));
1115 
1116 #define BLE_HCI_EVCODE_NUM_COMP_PKTS        (0x13)
1117 struct comp_pkt {
1118     uint16_t handle;
1119     uint16_t packets;
1120 } __attribute__((packed));;
1121 struct ble_hci_ev_num_comp_pkts {
1122     uint8_t count;
1123     struct comp_pkt completed[0];
1124 } __attribute__((packed));
1125 
1126 #define BLE_HCI_EVCODE_MODE_CHANGE          (0x14)
1127 #define BLE_HCI_EVCODE_RETURN_LINK_KEYS     (0x15)
1128 #define BLE_HCI_EVCODE_PIN_CODE_REQ         (0x16)
1129 #define BLE_HCI_EVCODE_LINK_KEY_REQ         (0x17)
1130 #define BLE_HCI_EVCODE_LINK_KEY_NOTIFY      (0x18)
1131 #define BLE_HCI_EVCODE_LOOPBACK_CMD         (0x19)
1132 
1133 #define BLE_HCI_EVCODE_DATA_BUF_OVERFLOW    (0x1A)
1134 struct ble_hci_ev_data_buf_overflow {
1135     uint8_t link_type;
1136 } __attribute__((packed));
1137 
1138 #define BLE_HCI_EVCODE_MAX_SLOTS_CHG        (0x1B)
1139 #define BLE_HCI_EVCODE_READ_CLK_OFF_COMP    (0x1C)
1140 #define BLE_HCI_EVCODE_CONN_PKT_TYPE_CHG    (0x1D)
1141 #define BLE_HCI_EVCODE_QOS_VIOLATION        (0x1E)
1142 /* NOTE: 0x1F not defined */
1143 #define BLE_HCI_EVCODE_PSR_MODE_CHG         (0x20)
1144 #define BLE_HCI_EVCODE_FLOW_SPEC_COMP       (0x21)
1145 #define BLE_HCI_EVCODE_INQ_RESULT_RSSI      (0x22)
1146 #define BLE_HCI_EVCODE_READ_REM_EXT_FEAT    (0x23)
1147 /* NOTE: 0x24 - 0x2B not defined */
1148 #define BLE_HCI_EVCODE_SYNCH_CONN_COMP      (0x2C)
1149 #define BLE_HCI_EVCODE_SYNCH_CONN_CHG       (0x2D)
1150 #define BLE_HCI_EVCODE_SNIFF_SUBRATING      (0x2E)
1151 #define BLE_HCI_EVCODE_EXT_INQ_RESULT       (0x2F)
1152 
1153 #define BLE_HCI_EVCODE_ENC_KEY_REFRESH      (0x30)
1154 struct ble_hci_ev_enc_key_refresh {
1155     uint8_t status;
1156     uint16_t conn_handle;
1157 } __attribute__((packed));
1158 
1159 #define BLE_HCI_EVOCDE_IO_CAP_REQ           (0x31)
1160 #define BLE_HCI_EVCODE_IO_CAP_RSP           (0x32)
1161 #define BLE_HCI_EVCODE_USER_CONFIRM_REQ     (0x33)
1162 #define BLE_HCI_EVCODE_PASSKEY_REQ          (0x34)
1163 #define BLE_HCI_EVCODE_REM_OOB_DATA_REQ     (0x35)
1164 #define BLE_HCI_EVCODE_SIMPLE_PAIR_COMP     (0x36)
1165 /* NOTE: 0x37 not defined */
1166 #define BLE_HCI_EVCODE_LNK_SPVN_TMO_CHG     (0x38)
1167 #define BLE_HCI_EVCODE_ENH_FLUSH_COMP       (0x39)
1168 #define BLE_HCI_EVCODE_USER_PASSKEY_NOTIFY  (0x3B)
1169 #define BLE_HCI_EVCODE_KEYPRESS_NOTIFY      (0x3C)
1170 #define BLE_HCI_EVCODE_REM_HOST_SUPP_FEAT   (0x3D)
1171 
1172 #define BLE_HCI_EVCODE_LE_META              (0x3E)
1173 struct ble_hci_ev_le_meta {
1174     uint8_t subevent;
1175     uint8_t data[0];
1176 } __attribute__((packed));
1177 
1178 /* NOTE: 0x3F not defined */
1179 #define BLE_HCI_EVCODE_PHYS_LINK_COMP       (0x40)
1180 #define BLE_HCI_EVCODE_CHAN_SELECTED        (0x41)
1181 #define BLE_HCI_EVCODE_DISCONN_PHYS_LINK    (0x42)
1182 #define BLE_HCI_EVCODE_PHYS_LINK_LOSS_EARLY (0x43)
1183 #define BLE_HCI_EVCODE_PHYS_LINK_RECOVERY   (0x44)
1184 #define BLE_HCI_EVCODE_LOGICAL_LINK_COMP    (0x45)
1185 #define BLE_HCI_EVCODE_DISCONN_LOGICAL_LINK (0x46)
1186 #define BLE_HCI_EVCODE_FLOW_SPEC_MODE_COMP  (0x47)
1187 #define BLE_HCI_EVCODE_NUM_COMP_DATA_BLKS   (0x48)
1188 #define BLE_HCI_EVCODE_AMP_START_TEST       (0x49)
1189 #define BLE_HCI_EVOCDE_AMP_TEST_END         (0x4A)
1190 #define BLE_HCI_EVOCDE_AMP_RCVR_REPORT      (0x4B)
1191 #define BLE_HCI_EVCODE_SHORT_RANGE_MODE_CHG (0x4C)
1192 #define BLE_HCI_EVCODE_AMP_STATUS_CHG       (0x4D)
1193 #define BLE_HCI_EVCODE_TRIG_CLK_CAPTURE     (0x4E)
1194 #define BLE_HCI_EVCODE_SYNCH_TRAIN_COMP     (0x4F)
1195 #define BLE_HCI_EVCODE_SYNCH_TRAIN_RCVD     (0x50)
1196 #define BLE_HCI_EVCODE_SLAVE_BCAST_RX       (0x51)
1197 #define BLE_HCI_EVCODE_SLAVE_BCAST_TMO      (0x52)
1198 #define BLE_HCI_EVCODE_TRUNC_PAGE_COMP      (0x53)
1199 #define BLE_HCI_EVCODE_SLAVE_PAGE_RSP_TMO   (0x54)
1200 #define BLE_HCI_EVCODE_SLAVE_BCAST_CHAN_MAP (0x55)
1201 #define BLE_HCI_EVCODE_INQ_RSP_NOTIFY       (0x56)
1202 
1203 #define BLE_HCI_EVCODE_AUTH_PYLD_TMO        (0x57)
1204 struct ble_hci_ev_auth_pyld_tmo {
1205     uint16_t conn_handle;
1206 } __attribute__((packed));
1207 
1208 #define BLE_HCI_EVCODE_SAM_STATUS_CHG       (0x58)
1209 
1210 #define BLE_HCI_EVCODE_VENDOR_DEBUG         (0xFF)
1211 struct ble_hci_ev_vendor_debug {
1212     uint8_t id;
1213     uint8_t data[0];
1214 } __attribute__((packed));
1215 
1216 /* LE sub-event codes */
1217 #define BLE_HCI_LE_SUBEV_CONN_COMPLETE          (0x01)
1218 struct ble_hci_ev_le_subev_conn_complete {
1219     uint8_t  subev_code;
1220     uint8_t  status;
1221     uint16_t conn_handle;
1222     uint8_t  role;
1223     uint8_t  peer_addr_type;
1224     uint8_t  peer_addr[6];
1225     uint16_t conn_itvl;
1226     uint16_t conn_latency;
1227     uint16_t supervision_timeout;
1228     uint8_t  mca;
1229 } __attribute__((packed));
1230 
1231 #define BLE_HCI_LE_SUBEV_ADV_RPT                (0x02)
1232 struct adv_report {
1233     uint8_t type;
1234     uint8_t addr_type;
1235     uint8_t addr[6];
1236     uint8_t data_len;
1237     uint8_t data[0];
1238 } __attribute__((packed));
1239 struct ble_hci_ev_le_subev_adv_rpt {
1240     uint8_t  subev_code;
1241     uint8_t  num_reports;
1242     struct adv_report reports[0];
1243 } __attribute__((packed));
1244 
1245 #define BLE_HCI_LE_SUBEV_CONN_UPD_COMPLETE      (0x03)
1246 struct ble_hci_ev_le_subev_conn_upd_complete {
1247     uint8_t  subev_code;
1248     uint8_t  status;
1249     uint16_t conn_handle;
1250     uint16_t conn_itvl;
1251     uint16_t conn_latency;
1252     uint16_t supervision_timeout;
1253 } __attribute__((packed));
1254 
1255 #define BLE_HCI_LE_SUBEV_RD_REM_USED_FEAT       (0x04)
1256 struct ble_hci_ev_le_subev_rd_rem_used_feat {
1257     uint8_t  subev_code;
1258     uint8_t  status;
1259     uint16_t conn_handle;
1260     uint8_t features[8];
1261 } __attribute__((packed));
1262 
1263 #define BLE_HCI_LE_SUBEV_LT_KEY_REQ             (0x05)
1264 struct ble_hci_ev_le_subev_lt_key_req {
1265     uint8_t  subev_code;
1266     uint16_t conn_handle;
1267     uint64_t rand;
1268     uint16_t div;
1269 } __attribute__((packed));
1270 
1271 #define BLE_HCI_LE_SUBEV_REM_CONN_PARM_REQ      (0x06)
1272 struct ble_hci_ev_le_subev_rem_conn_param_req {
1273     uint8_t  subev_code;
1274     uint16_t conn_handle;
1275     uint16_t min_interval;
1276     uint16_t max_interval;
1277     uint16_t latency;
1278     uint16_t timeout;
1279 } __attribute__((packed));
1280 
1281 #define BLE_HCI_LE_SUBEV_DATA_LEN_CHG           (0x07)
1282 struct ble_hci_ev_le_subev_data_len_chg {
1283     uint8_t  subev_code;
1284     uint16_t conn_handle;
1285     uint16_t max_tx_octets;
1286     uint16_t max_tx_time;
1287     uint16_t max_rx_octets;
1288     uint16_t max_rx_time;
1289 } __attribute__((packed));
1290 
1291 #define BLE_HCI_LE_SUBEV_RD_LOC_P256_PUBKEY     (0x08)
1292 struct ble_hci_ev_le_subev_rd_loc_p256_pubkey {
1293     uint8_t subev_code;
1294     uint8_t status;
1295     uint8_t public_key[64];
1296 } __attribute__((packed));
1297 
1298 #define BLE_HCI_LE_SUBEV_GEN_DHKEY_COMPLETE     (0x09)
1299 struct ble_hci_ev_le_subev_gen_dhkey_complete {
1300     uint8_t subev_code;
1301     uint8_t status;
1302     uint8_t dh_key[32];
1303 } __attribute__((packed));
1304 
1305 #define BLE_HCI_LE_SUBEV_ENH_CONN_COMPLETE      (0x0A)
1306 struct ble_hci_ev_le_subev_enh_conn_complete {
1307     uint8_t  subev_code;
1308     uint8_t  status;
1309     uint16_t conn_handle;
1310     uint8_t  role;
1311     uint8_t  peer_addr_type;
1312     uint8_t  peer_addr[6];
1313     uint8_t  local_rpa[6];
1314     uint8_t  peer_rpa[6];
1315     uint16_t conn_itvl;
1316     uint16_t conn_latency;
1317     uint16_t supervision_timeout;
1318     uint8_t  mca;
1319 } __attribute__((packed));
1320 
1321 #define BLE_HCI_LE_SUBEV_DIRECT_ADV_RPT         (0x0B)
1322 struct dir_adv_report {
1323     uint8_t type;
1324     uint8_t addr_type;
1325     uint8_t addr[6];
1326     uint8_t dir_addr_type;
1327     uint8_t dir_addr[6];
1328     int8_t  rssi;
1329 } __attribute__((packed));
1330 struct ble_hci_ev_le_subev_direct_adv_rpt {
1331     uint8_t subev_code;
1332     uint8_t num_reports;
1333     struct dir_adv_report reports[0];
1334 } __attribute__((packed));
1335 
1336 #define BLE_HCI_LE_SUBEV_PHY_UPDATE_COMPLETE    (0x0C)
1337 struct ble_hci_ev_le_subev_phy_update_complete {
1338     uint8_t  subev_code;
1339     uint8_t  status;
1340     uint16_t conn_handle;
1341     uint8_t  tx_phy;
1342     uint8_t  rx_phy;
1343 } __attribute__((packed));
1344 
1345 #define BLE_HCI_LE_SUBEV_EXT_ADV_RPT            (0x0D)
1346 struct ext_adv_report {
1347     uint16_t  evt_type;
1348     uint8_t  addr_type;
1349     uint8_t  addr[6];
1350     uint8_t  pri_phy;
1351     uint8_t  sec_phy;
1352     uint8_t  sid;
1353     int8_t   tx_power;
1354     int8_t   rssi;
1355     uint16_t periodic_itvl;
1356     uint8_t  dir_addr_type;
1357     uint8_t  dir_addr[6];
1358     uint8_t  data_len;
1359     uint8_t  data[0];
1360 } __attribute__((packed));
1361 struct ble_hci_ev_le_subev_ext_adv_rpt {
1362     uint8_t subev_code;
1363     uint8_t num_reports;
1364     struct ext_adv_report reports[0];
1365 } __attribute__((packed));
1366 
1367 #define BLE_HCI_LE_SUBEV_PERIODIC_ADV_SYNC_ESTAB     (0x0E)
1368 struct ble_hci_ev_le_subev_periodic_adv_sync_estab {
1369     uint8_t  subev_code;
1370     uint8_t  status;
1371     uint16_t sync_handle;
1372     uint8_t  sid;
1373     uint8_t  peer_addr_type;
1374     uint8_t  peer_addr[6];
1375     uint8_t  phy;
1376     uint16_t interval;
1377     uint8_t  aca;
1378 } __attribute__((packed));
1379 
1380 #define BLE_HCI_LE_SUBEV_PERIODIC_ADV_RPT            (0x0F)
1381 struct ble_hci_ev_le_subev_periodic_adv_rpt {
1382     uint8_t  subev_code;
1383     uint16_t sync_handle;
1384     int8_t   tx_power;
1385     int8_t   rssi;
1386     uint8_t  cte_type;
1387     uint8_t  data_status;
1388     uint8_t  data_len;
1389     uint8_t  data[0];
1390 } __attribute__((packed));
1391 
1392 #define BLE_HCI_LE_SUBEV_PERIODIC_ADV_SYNC_LOST      (0x10)
1393 struct ble_hci_ev_le_subev_periodic_adv_sync_lost {
1394     uint8_t  subev_code;
1395     uint16_t sync_handle;
1396 } __attribute__((packed));
1397 
1398 #define BLE_HCI_LE_SUBEV_SCAN_TIMEOUT           (0x11)
1399 struct ble_hci_ev_le_subev_scan_timeout {
1400     uint8_t  subev_code;
1401 } __attribute__((packed));
1402 
1403 #define BLE_HCI_LE_SUBEV_ADV_SET_TERMINATED     (0x12)
1404 struct ble_hci_ev_le_subev_adv_set_terminated {
1405     uint8_t  subev_code;
1406     uint8_t  status;
1407     uint8_t  adv_handle;
1408     uint16_t conn_handle;
1409     uint8_t  num_events;
1410 } __attribute__((packed));
1411 
1412 #define BLE_HCI_LE_SUBEV_SCAN_REQ_RCVD          (0x13)
1413 struct ble_hci_ev_le_subev_scan_req_rcvd {
1414     uint8_t subev_code;
1415     uint8_t adv_handle;
1416     uint8_t peer_addr_type;
1417     uint8_t peer_addr[6];
1418 } __attribute__((packed));
1419 
1420 #define BLE_HCI_LE_SUBEV_CHAN_SEL_ALG           (0x14)
1421 struct ble_hci_ev_le_subev_chan_sel_alg {
1422     uint8_t  subev_code;
1423     uint16_t conn_handle;
1424     uint8_t  csa;
1425 } __attribute__((packed));
1426 
1427 #define BLE_HCI_LE_SUBEV_CONNLESS_IQ_RPT        (0x15)
1428 #define BLE_HCI_LE_SUBEV_CONN_IQ_RPT            (0x16)
1429 #define BLE_HCI_LE_SUBEV_CTE_REQ_FAILED         (0x17)
1430 
1431 #define BLE_HCI_LE_SUBEV_PERIODIC_ADV_SYNC_TRANSFER   (0x18)
1432 struct ble_hci_ev_le_subev_periodic_adv_sync_transfer {
1433     uint8_t  subev_code;
1434     uint8_t  status;
1435     uint16_t conn_handle;
1436     uint16_t service_data;
1437     uint16_t sync_handle;
1438     uint8_t  sid;
1439     uint8_t  peer_addr_type;
1440     uint8_t  peer_addr[6];
1441     uint8_t  phy;
1442     uint16_t interval;
1443     uint8_t  aca;
1444 } __attribute__((packed));
1445 
1446 /* Data buffer overflow event */
1447 #define BLE_HCI_EVENT_ACL_BUF_OVERFLOW      (0x01)
1448 
1449 /* Advertising report */
1450 #define BLE_HCI_ADV_RPT_EVTYPE_ADV_IND      (0)
1451 #define BLE_HCI_ADV_RPT_EVTYPE_DIR_IND      (1)
1452 #define BLE_HCI_ADV_RPT_EVTYPE_SCAN_IND     (2)
1453 #define BLE_HCI_ADV_RPT_EVTYPE_NONCONN_IND  (3)
1454 #define BLE_HCI_ADV_RPT_EVTYPE_SCAN_RSP     (4)
1455 
1456 /* Bluetooth 5, Vol 2, Part E, 7.7.65.13 */
1457 #define BLE_HCI_LEGACY_ADV_EVTYPE_ADV_IND                 (0x13)
1458 #define BLE_HCI_LEGACY_ADV_EVTYPE_ADV_DIRECT_IND          (0x15)
1459 #define BLE_HCI_LEGACY_ADV_EVTYPE_ADV_SCAN_IND            (0x12)
1460 #define BLE_HCI_LEGACY_ADV_EVTYPE_ADV_NONCON_IND          (0x10)
1461 #define BLE_HCI_LEGACY_ADV_EVTYPE_SCAN_RSP_ADV_IND        (0x1b)
1462 #define BLE_HCI_LEGACY_ADV_EVTYPE_SCAN_RSP_ADV_SCAN_IND   (0x1a)
1463 
1464 /* LE connection complete event (sub event 0x01) */
1465 #define BLE_HCI_LE_CONN_COMPLETE_ROLE_MASTER    (0x00)
1466 #define BLE_HCI_LE_CONN_COMPLETE_ROLE_SLAVE     (0x01)
1467 
1468 /* Maximum valid connection handle value */
1469 #define BLE_HCI_LE_CONN_HANDLE_MAX              (0x0eff)
1470 
1471 /* LE advertising report event. (sub event 0x02) */
1472 #define BLE_HCI_LE_ADV_RPT_NUM_RPTS_MIN     (1)
1473 #define BLE_HCI_LE_ADV_RPT_NUM_RPTS_MAX     (0x19)
1474 
1475 /* Bluetooth Assigned numbers for version information. */
1476 #define BLE_HCI_VER_BCS_1_0b                (0)
1477 #define BLE_HCI_VER_BCS_1_1                 (1)
1478 #define BLE_HCI_VER_BCS_1_2                 (2)
1479 #define BLE_HCI_VER_BCS_2_0_EDR             (3)
1480 #define BLE_HCI_VER_BCS_2_1_EDR             (4)
1481 #define BLE_HCI_VER_BCS_3_0_HCS             (5)
1482 #define BLE_HCI_VER_BCS_4_0                 (6)
1483 #define BLE_HCI_VER_BCS_4_1                 (7)
1484 #define BLE_HCI_VER_BCS_4_2                 (8)
1485 #define BLE_HCI_VER_BCS_5_0                 (9)
1486 #define BLE_HCI_VER_BCS_5_1                 (10)
1487 #define BLE_HCI_VER_BCS_5_2                 (11)
1488 
1489 #define BLE_LMP_VER_BCS_1_0b                (0)
1490 #define BLE_LMP_VER_BCS_1_1                 (1)
1491 #define BLE_LMP_VER_BCS_1_2                 (2)
1492 #define BLE_LMP_VER_BCS_2_0_EDR             (3)
1493 #define BLE_LMP_VER_BCS_2_1_EDR             (4)
1494 #define BLE_LMP_VER_BCS_3_0_HCS             (5)
1495 #define BLE_LMP_VER_BCS_4_0                 (6)
1496 #define BLE_LMP_VER_BCS_4_1                 (7)
1497 #define BLE_LMP_VER_BCS_4_2                 (8)
1498 #define BLE_LMP_VER_BCS_5_0                 (9)
1499 #define BLE_LMP_VER_BCS_5_1                 (10)
1500 #define BLE_LMP_VER_BCS_5_2                 (11)
1501 
1502 /* selected HCI and LMP version */
1503 #if MYNEWT_VAL(BLE_VERSION) == 50
1504 #define BLE_HCI_VER_BCS BLE_HCI_VER_BCS_5_0
1505 #define BLE_LMP_VER_BCS BLE_LMP_VER_BCS_5_0
1506 #elif MYNEWT_VAL(BLE_VERSION) == 51
1507 #define BLE_HCI_VER_BCS BLE_HCI_VER_BCS_5_1
1508 #define BLE_LMP_VER_BCS BLE_LMP_VER_BCS_5_1
1509 #elif MYNEWT_VAL(BLE_VERSION) == 52
1510 #define BLE_HCI_VER_BCS BLE_HCI_VER_BCS_5_2
1511 #define BLE_LMP_VER_BCS BLE_LMP_VER_BCS_5_2
1512 
1513 #endif
1514 
1515 #define BLE_HCI_DATA_HDR_SZ                 4
1516 #define BLE_HCI_DATA_HANDLE(handle_pb_bc)   (((handle_pb_bc) & 0x0fff) >> 0)
1517 #define BLE_HCI_DATA_PB(handle_pb_bc)       (((handle_pb_bc) & 0x3000) >> 12)
1518 #define BLE_HCI_DATA_BC(handle_pb_bc)       (((handle_pb_bc) & 0xc000) >> 14)
1519 
1520 struct hci_data_hdr {
1521     uint16_t hdh_handle_pb_bc;
1522     uint16_t hdh_len;
1523 };
1524 
1525 #define BLE_HCI_PB_FIRST_NON_FLUSH          0
1526 #define BLE_HCI_PB_MIDDLE                   1
1527 #define BLE_HCI_PB_FIRST_FLUSH              2
1528 #define BLE_HCI_PB_FULL                     3
1529 
1530 #ifdef __cplusplus
1531 }
1532 #endif
1533 
1534 #endif /* H_BLE_HCI_COMMON_ */
1535