xref: /nrf52832-nimble/packages/NimBLE-latest/nimble/host/src/ble_hs_hci_priv.h (revision 042d53a763ad75cb1465103098bb88c245d95138)
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_HS_HCI_PRIV_
21 #define H_BLE_HS_HCI_PRIV_
22 
23 #include "nimble/hci_common.h"
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27 
28 struct ble_hs_conn;
29 struct os_mbuf;
30 
31 #define BLE_HS_HCI_LE_FEAT_ENCRYPTION                   (0x00000001)
32 #define BLE_HS_HCI_LE_FEAT_CONN_PARAM_REQUEST           (0x00000002)
33 #define BLE_HS_HCI_LE_FEAT_EXT_REJECT                   (0x00000004)
34 #define BLE_HS_HCI_LE_FEAT_SLAVE_FEAT_EXCHANGE          (0x00000008)
35 #define BLE_HS_HCI_LE_FEAT_PING                         (0x00000010)
36 #define BLE_HS_HCI_LE_FEAT_DATA_PACKET_LENGTH_EXT       (0x00000020)
37 #define BLE_HS_HCI_LE_FEAT_LL_PRIVACY                   (0x00000040)
38 #define BLE_HS_HCI_LE_FEAT_EXT_SCANNER_FILTER_POLICIES  (0x00000080)
39 #define BLE_HS_HCI_LE_FEAT_2M_PHY                       (0x00000100)
40 #define BLE_HS_HCI_LE_FEAT_STABLE_MOD_INDEX_TX          (0x00000200)
41 #define BLE_HS_HCI_LE_FEAT_STABLE_MOD_INDEX_RX          (0x00000400)
42 #define BLE_HS_HCI_LE_FEAT_CODED_PHY                    (0x00000800)
43 #define BLE_HS_HCI_LE_FEAT_EXT_ADV                      (0x00001000)
44 #define BLE_HS_HCI_LE_FEAT_PERIODIC_ADV                 (0x00002000)
45 #define BLE_HS_HCI_LE_FEAT_CSA2                         (0x00004000)
46 #define BLE_HS_HCI_LE_FEAT_POWER_CLASS_1                (0x00008000)
47 #define BLE_HS_HCI_LE_FEAT_MIN_NUM_USED_CHAN            (0x00010000)
48 
49 struct ble_hs_hci_ack {
50     int bha_status;         /* A BLE_HS_E<...> error; NOT a naked HCI code. */
51     uint8_t *bha_params;
52     int bha_params_len;
53     uint16_t bha_opcode;
54     uint8_t bha_hci_handle;
55 };
56 
57 #if MYNEWT_VAL(BLE_EXT_ADV)
58 struct ble_hs_hci_ext_scan_param {
59     uint8_t scan_type;
60     uint16_t scan_itvl;
61     uint16_t scan_window;
62 };
63 
64 struct ble_hs_hci_ext_conn_params {
65     uint16_t scan_itvl;
66     uint16_t scan_window;
67     uint16_t conn_itvl;
68     uint16_t conn_windows;
69 };
70 #endif
71 
72 extern uint16_t ble_hs_hci_avail_pkts;
73 
74 int ble_hs_hci_cmd_tx(uint16_t opcode, void *cmd, uint8_t cmd_len,
75                       void *evt_buf, uint8_t evt_buf_len,
76                       uint8_t *out_evt_buf_len);
77 int ble_hs_hci_cmd_tx_empty_ack(uint16_t opcode, void *cmd, uint8_t cmd_len);
78 void ble_hs_hci_rx_ack(uint8_t *ack_ev);
79 void ble_hs_hci_init(void);
80 
81 void ble_hs_hci_set_le_supported_feat(uint32_t feat);
82 uint32_t ble_hs_hci_get_le_supported_feat(void);
83 void ble_hs_hci_set_hci_version(uint8_t hci_version);
84 uint8_t ble_hs_hci_get_hci_version(void);
85 
86 #if MYNEWT_VAL(BLE_HS_PHONY_HCI_ACKS)
87 typedef int ble_hs_hci_phony_ack_fn(uint8_t *ack, int ack_buf_len);
88 void ble_hs_hci_set_phony_ack_cb(ble_hs_hci_phony_ack_fn *cb);
89 #endif
90 
91 int ble_hs_hci_util_read_adv_tx_pwr(int8_t *out_pwr);
92 int ble_hs_hci_util_rand(void *dst, int len);
93 int ble_hs_hci_util_read_rssi(uint16_t conn_handle, int8_t *out_rssi);
94 int ble_hs_hci_util_set_random_addr(const uint8_t *addr);
95 int ble_hs_hci_util_set_data_len(uint16_t conn_handle, uint16_t tx_octets,
96                                  uint16_t tx_time);
97 int ble_hs_hci_util_data_hdr_strip(struct os_mbuf *om,
98                                    struct hci_data_hdr *out_hdr);
99 int ble_hs_hci_evt_process(uint8_t *data);
100 
101 void ble_hs_hci_cmd_write_hdr(uint8_t ogf, uint16_t ocf, uint8_t len,
102                               void *buf);
103 int ble_hs_hci_cmd_send_buf(uint16_t opcode, void *buf, uint8_t buf_len);
104 void ble_hs_hci_cmd_build_set_event_mask(uint64_t event_mask,
105                                          uint8_t *dst, int dst_len);
106 void ble_hs_hci_cmd_build_set_event_mask2(uint64_t event_mask, uint8_t *dst,
107                                           int dst_len);
108 void ble_hs_hci_cmd_build_disconnect(uint16_t handle, uint8_t reason,
109                                      uint8_t *dst, int dst_len);
110 void ble_hs_hci_cmd_build_read_rssi(uint16_t handle, uint8_t *dst,
111                                     int dst_len);
112 void ble_hs_hci_cmd_build_le_set_host_chan_class(const uint8_t *chan_map,
113                                                  uint8_t *dst, int dst_len);
114 void ble_hs_hci_cmd_build_le_read_chan_map(uint16_t conn_handle,
115                                            uint8_t *dst, int dst_len);
116 int ble_hs_hci_cmd_build_le_set_scan_rsp_data(const uint8_t *data, uint8_t len,
117                                               uint8_t *dst, int dst_len);
118 int ble_hs_hci_cmd_build_le_set_adv_data(const uint8_t *data, uint8_t len,
119                                          uint8_t *dst, int dst_len);
120 int ble_hs_hci_cmd_build_le_set_adv_params(const struct hci_adv_params *adv,
121                                            uint8_t *dst, int dst_len);
122 void ble_hs_hci_cmd_build_le_set_event_mask(uint64_t event_mask,
123                                             uint8_t *dst, int dst_len);
124 int ble_hs_hci_cmd_le_read_buffer_size(void);
125 void ble_hs_hci_cmd_build_le_set_adv_enable(uint8_t enable, uint8_t *dst,
126                                             int dst_len);
127 int ble_hs_hci_cmd_le_set_adv_enable(uint8_t enable);
128 int ble_hs_hci_cmd_build_le_set_scan_params(uint8_t scan_type,
129                                             uint16_t scan_itvl,
130                                             uint16_t scan_window,
131                                             uint8_t own_addr_type,
132                                             uint8_t filter_policy,
133                                             uint8_t *dst, int dst_len);
134 void ble_hs_hci_cmd_build_le_set_scan_enable(uint8_t enable,
135                                              uint8_t filter_dups,
136                                              uint8_t *dst, uint8_t dst_len);
137 int ble_hs_hci_cmd_le_set_scan_enable(uint8_t enable, uint8_t filter_dups);
138 int ble_hs_hci_cmd_build_le_create_connection(
139     const struct hci_create_conn *hcc, uint8_t *cmd, int cmd_len);
140 int ble_hs_hci_cmd_build_le_add_to_whitelist(const uint8_t *addr,
141                                              uint8_t addr_type,
142                                              uint8_t *dst, int dst_len);
143 int ble_hs_hci_cmd_reset(void);
144 int ble_hs_hci_cmd_tx_set_ctlr_to_host_fc(uint8_t fc_enable);
145 int ble_hs_hci_cmd_tx_host_buf_size(const struct hci_host_buf_size *cmd);
146 int ble_hs_hci_cmd_build_host_num_comp_pkts_entry(
147     const struct hci_host_num_comp_pkts_entry *entry,
148     uint8_t *dst, int dst_len);
149 int ble_hs_hci_cmd_read_adv_pwr(void);
150 int ble_hs_hci_cmd_le_create_conn_cancel(void);
151 int ble_hs_hci_cmd_build_le_conn_update(const struct hci_conn_update *hcu,
152                                         uint8_t *dst, int dst_len);
153 int ble_hs_hci_cmd_le_conn_update(const struct hci_conn_update *hcu);
154 void ble_hs_hci_cmd_build_le_lt_key_req_reply(
155     const struct hci_lt_key_req_reply *hkr, uint8_t *dst, int dst_len);
156 void ble_hs_hci_cmd_build_le_lt_key_req_neg_reply(uint16_t conn_handle,
157                                                   uint8_t *dst, int dst_len);
158 void ble_hs_hci_cmd_build_le_conn_param_reply(
159     const struct hci_conn_param_reply *hcr, uint8_t *dst, int dst_len);
160 int ble_hs_hci_cmd_le_conn_param_reply(const struct hci_conn_param_reply *hcr);
161 void ble_hs_hci_cmd_build_le_conn_param_neg_reply(
162     const struct hci_conn_param_neg_reply *hcn, uint8_t *dst, int dst_len);
163 int ble_hs_hci_cmd_le_conn_param_neg_reply(
164     const struct hci_conn_param_neg_reply *hcn);
165 void ble_hs_hci_cmd_build_le_start_encrypt(const struct hci_start_encrypt *cmd,
166                                            uint8_t *dst, int dst_len);
167 int ble_hs_hci_set_buf_sz(uint16_t pktlen, uint16_t max_pkts);
168 void ble_hs_hci_add_avail_pkts(uint16_t delta);
169 
170 uint16_t ble_hs_hci_util_handle_pb_bc_join(uint16_t handle, uint8_t pb,
171                                            uint8_t bc);
172 
173 int ble_hs_hci_acl_tx_now(struct ble_hs_conn *conn, struct os_mbuf **om);
174 int ble_hs_hci_acl_tx(struct ble_hs_conn *conn, struct os_mbuf **om);
175 
176 int ble_hs_hci_cmd_build_set_data_len(uint16_t connection_handle,
177                                       uint16_t tx_octets, uint16_t tx_time,
178                                       uint8_t *dst, int dst_len);
179 int ble_hs_hci_cmd_build_add_to_resolv_list(
180     const struct hci_add_dev_to_resolving_list *padd,
181     uint8_t *dst, int dst_len);
182 int ble_hs_hci_cmd_build_remove_from_resolv_list(
183     uint8_t addr_type, const uint8_t *addr, uint8_t *dst, int dst_len);
184 int ble_hs_hci_cmd_build_read_peer_resolv_addr(
185     uint8_t peer_identity_addr_type, const uint8_t *peer_identity_addr,
186     uint8_t *dst, int dst_len);
187 int ble_hs_hci_cmd_build_read_lcl_resolv_addr(
188     uint8_t local_identity_addr_type, const uint8_t *local_identity_addr,
189     uint8_t *dst, int dst_len);
190 int ble_hs_hci_cmd_build_set_addr_res_en(
191     uint8_t enable, uint8_t *dst, int dst_len);
192 int ble_hs_hci_cmd_build_set_resolv_priv_addr_timeout(
193     uint16_t timeout, uint8_t *dst, int dst_len);
194 int ble_hs_hci_cmd_build_set_random_addr(const uint8_t *addr,
195                                          uint8_t *dst, int dst_len);
196 
197 #if MYNEWT_VAL(BLE_EXT_ADV)
198 int ble_hs_hci_cmd_build_le_set_ext_scan_params(uint8_t own_addr_type,
199                                                uint8_t filter_policy,
200                                                uint8_t phy_mask,
201                                                uint8_t phy_count,
202                                                struct ble_hs_hci_ext_scan_param *params[],
203                                                uint8_t *dst, uint16_t dst_len);
204 
205 int ble_hs_hci_cmd_build_le_set_ext_scan_enable(uint8_t enable,
206                                                 uint8_t filter_dups,
207                                                 uint16_t duration,
208                                                 uint16_t period,
209                                                 uint8_t *dst, uint16_t dst_len);
210 
211 int ble_hs_hci_cmd_build_le_ext_create_conn(const struct hci_ext_create_conn *hcc,
212                                             uint8_t *cmd, int cmd_len);
213 
214 int
215 ble_hs_hci_cmd_build_le_ext_adv_set_random_addr(uint8_t handle,
216                                                 const uint8_t *addr,
217                                                 uint8_t *cmd, int cmd_len);
218 
219 int
220 ble_hs_hci_cmd_build_le_ext_adv_data(uint8_t handle, uint8_t operation,
221                                      uint8_t frag_pref, struct os_mbuf *data,
222                                      uint8_t data_len,
223                                      uint8_t *cmd, int cmd_len);
224 
225 int
226 ble_hs_hci_cmd_build_le_ext_adv_enable(uint8_t enable, uint8_t sets_num,
227                                        const struct hci_ext_adv_set *sets,
228                                        uint8_t *cmd, int cmd_len);
229 
230 int
231 ble_hs_hci_cmd_build_le_ext_adv_params(uint8_t handle,
232                                        const struct hci_ext_adv_params *params,
233                                        uint8_t *cmd, int cmd_len);
234 
235 int
236 ble_hs_hci_cmd_build_le_ext_adv_remove(uint8_t handle,
237                                        uint8_t *cmd, int cmd_len);
238 #endif
239 
240 int ble_hs_hci_cmd_build_le_enh_recv_test(uint8_t rx_chan, uint8_t phy,
241                                           uint8_t mod_idx,
242                                           uint8_t *dst, uint16_t dst_len);
243 
244 int ble_hs_hci_cmd_build_le_enh_trans_test(uint8_t tx_chan,
245                                            uint8_t test_data_len,
246                                            uint8_t packet_payload_idx,
247                                            uint8_t phy,
248                                            uint8_t *dst, uint16_t dst_len);
249 
250 int ble_hs_hci_cmd_build_le_set_priv_mode(const uint8_t *addr, uint8_t addr_type,
251                                           uint8_t priv_mode, uint8_t *dst,
252                                           uint16_t dst_len);
253 
254 int ble_hs_hci_cmd_build_le_read_phy(uint16_t conn_handle, uint8_t *dst,
255                                      int dst_len);
256 
257 int ble_hs_hci_cmd_build_le_set_default_phy(uint8_t tx_phys_mask,
258                                             uint8_t rx_phys_mask,
259                                             uint8_t *dst, int dst_len);
260 
261 int ble_hs_hci_cmd_build_le_set_phy(uint16_t conn_handle, uint8_t tx_phys_mask,
262                                     uint8_t rx_phys_mask, uint16_t phy_opts,
263                                     uint8_t *dst, int dst_len);
264 
265 #if MYNEWT_VAL(BLE_EXT_ADV)
266 #endif
267 
268 int ble_hs_hci_cmd_build_le_read_remote_feat(uint16_t handle, uint8_t *dst,
269                                                                  int dst_len);
270 #ifdef __cplusplus
271 }
272 #endif
273 
274 #endif
275