1 /******************************************************************************
2 *
3 * Copyright 1999-2012 Broadcom Corporation
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at:
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 ******************************************************************************/
18
19 /******************************************************************************
20 *
21 * This file contains function of the HCIC unit to format and send HCI
22 * commands.
23 *
24 ******************************************************************************/
25
26 #include "bt_common.h"
27 #include "bt_target.h"
28 #include "btu.h"
29 #include "hcidefs.h"
30 #include "hcimsgs.h"
31
32 #include <bitset>
33
34 #include <base/bind.h>
35 #include <stddef.h>
36 #include <string.h>
37
38 /*******************************************************************************
39 * BLE Commands
40 * Note: "local_controller_id" is for transport, not counted in HCI
41 * message size
42 ******************************************************************************/
43 #define HCIC_BLE_RAND_DI_SIZE 8
44 #define HCIC_BLE_IRK_SIZE 16
45
46 #define HCIC_PARAM_SIZE_SET_USED_FEAT_CMD 8
47 #define HCIC_PARAM_SIZE_WRITE_RANDOM_ADDR_CMD 6
48 #define HCIC_PARAM_SIZE_BLE_WRITE_ADV_PARAMS 15
49 #define HCIC_PARAM_SIZE_BLE_WRITE_SCAN_RSP 31
50 #define HCIC_PARAM_SIZE_WRITE_ADV_ENABLE 1
51 #define HCIC_PARAM_SIZE_BLE_WRITE_SCAN_PARAM 7
52 #define HCIC_PARAM_SIZE_BLE_WRITE_SCAN_ENABLE 2
53 #define HCIC_PARAM_SIZE_BLE_CREATE_LL_CONN 25
54 #define HCIC_PARAM_SIZE_BLE_CREATE_CONN_CANCEL 0
55 #define HCIC_PARAM_SIZE_CLEAR_ACCEPTLIST 0
56 #define HCIC_PARAM_SIZE_ADD_ACCEPTLIST 7
57 #define HCIC_PARAM_SIZE_REMOVE_ACCEPTLIST 7
58 #define HCIC_PARAM_SIZE_BLE_UPD_LL_CONN_PARAMS 14
59 #define HCIC_PARAM_SIZE_SET_HOST_CHNL_CLASS 5
60 #define HCIC_PARAM_SIZE_READ_CHNL_MAP 2
61 #define HCIC_PARAM_SIZE_BLE_READ_REMOTE_FEAT 2
62 #define HCIC_PARAM_SIZE_BLE_ENCRYPT 32
63 #define HCIC_PARAM_SIZE_WRITE_LE_HOST_SUPPORTED 2
64
65 #define HCIC_BLE_RAND_DI_SIZE 8
66 #define HCIC_BLE_ENCRYPT_KEY_SIZE 16
67 #define HCIC_PARAM_SIZE_BLE_START_ENC \
68 (4 + HCIC_BLE_RAND_DI_SIZE + HCIC_BLE_ENCRYPT_KEY_SIZE)
69 #define HCIC_PARAM_SIZE_LTK_REQ_REPLY (2 + HCIC_BLE_ENCRYPT_KEY_SIZE)
70 #define HCIC_PARAM_SIZE_LTK_REQ_NEG_REPLY 2
71 #define HCIC_BLE_CHNL_MAP_SIZE 5
72 #define HCIC_PARAM_SIZE_BLE_WRITE_ADV_DATA 31
73
74 #define HCIC_PARAM_SIZE_BLE_ADD_DEV_RESOLVING_LIST (7 + HCIC_BLE_IRK_SIZE * 2)
75 #define HCIC_PARAM_SIZE_BLE_RM_DEV_RESOLVING_LIST 7
76 #define HCIC_PARAM_SIZE_BLE_SET_PRIVACY_MODE 8
77 #define HCIC_PARAM_SIZE_BLE_CLEAR_RESOLVING_LIST 0
78 #define HCIC_PARAM_SIZE_BLE_READ_RESOLVING_LIST_SIZE 0
79 #define HCIC_PARAM_SIZE_BLE_READ_RESOLVABLE_ADDR_PEER 7
80 #define HCIC_PARAM_SIZE_BLE_READ_RESOLVABLE_ADDR_LOCAL 7
81 #define HCIC_PARAM_SIZE_BLE_SET_ADDR_RESOLUTION_ENABLE 1
82 #define HCIC_PARAM_SIZE_BLE_SET_RAND_PRIV_ADDR_TIMOUT 2
83
84 #define HCIC_PARAM_SIZE_BLE_READ_PHY 2
85 #define HCIC_PARAM_SIZE_BLE_SET_DEFAULT_PHY 3
86 #define HCIC_PARAM_SIZE_BLE_SET_PHY 7
87 #define HCIC_PARAM_SIZE_BLE_ENH_RX_TEST 3
88 #define HCIC_PARAM_SIZE_BLE_ENH_TX_TEST 4
89
90 #define HCIC_PARAM_SIZE_BLE_SET_DATA_LENGTH 6
91 #define HCIC_PARAM_SIZE_BLE_WRITE_EXTENDED_SCAN_PARAM 11
92
93 #define HCIC_PARAM_SIZE_BLE_RC_PARAM_REQ_REPLY 14
94 #define HCIC_PARAM_SIZE_BLE_RC_PARAM_REQ_NEG_REPLY 3
95
96 #define HCIC_PARAM_SIZE_PERIODIC_ADVERTISING_CREATE_SYNC 14
97 #define HCIC_PARAM_SIZE_PERIODIC_ADVERTISING_CREATE_SYNC_CANCEL 0
98 #define HCIC_PARAM_SIZE_PERIODIC_ADVERTISING_TERMINATE_SYNC 2
99 #define HCIC_PARAM_SIZE_ADD_DEVICE_TO_PERIODIC_ADVERTISER_LIST 8
100 #define HCIC_PARAM_SIZE_REMOVE_DEVICE_FROM_PERIODIC_ADVERTISER_LIST 8
101 #define HCIC_PARAM_SIZE_CLEAR_PERIODIC_ADVERTISER_LIST 0
102 #define HCIC_PARAM_SIZE_READ_PERIODIC_ADVERTISER_LIST_SIZE 0
103 #define HCIC_PARAM_SIZE_SET_PERIODIC_ADVERTISING_RECEIVE_ENABLE 3
104 #define HCIC_PARAM_SIZE_PERIODIC_ADVERTISING_SYNC_TRANSFER 6
105 #define HCIC_PARAM_SIZE_PERIODIC_ADVERTISING_SET_INFO_TRANSFER 5
106 #define HCIC_PARAM_SIZE_SET_PERIODIC_ADVERTISING_SYNC_TRANSFER_PARAMS 8
107 #define HCIC_PARAM_SIZE_SET_DEFAULT_PERIODIC_ADVERTISING_SYNC_TRANSFER_PARAMS 8
108
btsnd_hcic_ble_set_local_used_feat(uint8_t feat_set[8])109 void btsnd_hcic_ble_set_local_used_feat(uint8_t feat_set[8]) {
110 BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
111 uint8_t* pp = (uint8_t*)(p + 1);
112
113 p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_SET_USED_FEAT_CMD;
114 p->offset = 0;
115
116 UINT16_TO_STREAM(pp, HCI_BLE_WRITE_LOCAL_SPT_FEAT);
117 ARRAY_TO_STREAM(pp, feat_set, HCIC_PARAM_SIZE_SET_USED_FEAT_CMD);
118
119 btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
120 }
121
btsnd_hcic_ble_set_random_addr(const RawAddress & random_bda)122 void btsnd_hcic_ble_set_random_addr(const RawAddress& random_bda) {
123 BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
124 uint8_t* pp = (uint8_t*)(p + 1);
125
126 p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_WRITE_RANDOM_ADDR_CMD;
127 p->offset = 0;
128
129 UINT16_TO_STREAM(pp, HCI_BLE_WRITE_RANDOM_ADDR);
130 UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_WRITE_RANDOM_ADDR_CMD);
131
132 BDADDR_TO_STREAM(pp, random_bda);
133
134 btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
135 }
136
btsnd_hcic_ble_write_adv_params(uint16_t adv_int_min,uint16_t adv_int_max,uint8_t adv_type,uint8_t addr_type_own,uint8_t addr_type_dir,const RawAddress & direct_bda,uint8_t channel_map,uint8_t adv_filter_policy)137 void btsnd_hcic_ble_write_adv_params(uint16_t adv_int_min, uint16_t adv_int_max,
138 uint8_t adv_type, uint8_t addr_type_own,
139 uint8_t addr_type_dir,
140 const RawAddress& direct_bda,
141 uint8_t channel_map,
142 uint8_t adv_filter_policy) {
143 BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
144 uint8_t* pp = (uint8_t*)(p + 1);
145
146 p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_WRITE_ADV_PARAMS;
147 p->offset = 0;
148
149 UINT16_TO_STREAM(pp, HCI_BLE_WRITE_ADV_PARAMS);
150 UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_BLE_WRITE_ADV_PARAMS);
151
152 UINT16_TO_STREAM(pp, adv_int_min);
153 UINT16_TO_STREAM(pp, adv_int_max);
154 UINT8_TO_STREAM(pp, adv_type);
155 UINT8_TO_STREAM(pp, addr_type_own);
156 UINT8_TO_STREAM(pp, addr_type_dir);
157 BDADDR_TO_STREAM(pp, direct_bda);
158 UINT8_TO_STREAM(pp, channel_map);
159 UINT8_TO_STREAM(pp, adv_filter_policy);
160
161 btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
162 }
btsnd_hcic_ble_read_adv_chnl_tx_power(void)163 void btsnd_hcic_ble_read_adv_chnl_tx_power(void) {
164 BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
165 uint8_t* pp = (uint8_t*)(p + 1);
166
167 p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_READ_CMD;
168 p->offset = 0;
169
170 UINT16_TO_STREAM(pp, HCI_BLE_READ_ADV_CHNL_TX_POWER);
171 UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_READ_CMD);
172
173 btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
174 }
175
btsnd_hcic_ble_set_adv_data(uint8_t data_len,uint8_t * p_data)176 void btsnd_hcic_ble_set_adv_data(uint8_t data_len, uint8_t* p_data) {
177 BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
178 uint8_t* pp = (uint8_t*)(p + 1);
179
180 p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_WRITE_ADV_DATA + 1;
181 p->offset = 0;
182
183 UINT16_TO_STREAM(pp, HCI_BLE_WRITE_ADV_DATA);
184 UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_BLE_WRITE_ADV_DATA + 1);
185
186 memset(pp, 0, HCIC_PARAM_SIZE_BLE_WRITE_ADV_DATA);
187
188 if (p_data != NULL && data_len > 0) {
189 if (data_len > HCIC_PARAM_SIZE_BLE_WRITE_ADV_DATA)
190 data_len = HCIC_PARAM_SIZE_BLE_WRITE_ADV_DATA;
191
192 UINT8_TO_STREAM(pp, data_len);
193
194 ARRAY_TO_STREAM(pp, p_data, data_len);
195 }
196 btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
197 }
btsnd_hcic_ble_set_scan_rsp_data(uint8_t data_len,uint8_t * p_scan_rsp)198 void btsnd_hcic_ble_set_scan_rsp_data(uint8_t data_len, uint8_t* p_scan_rsp) {
199 BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
200 uint8_t* pp = (uint8_t*)(p + 1);
201
202 p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_WRITE_SCAN_RSP + 1;
203 p->offset = 0;
204
205 UINT16_TO_STREAM(pp, HCI_BLE_WRITE_SCAN_RSP_DATA);
206 UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_BLE_WRITE_SCAN_RSP + 1);
207
208 memset(pp, 0, HCIC_PARAM_SIZE_BLE_WRITE_SCAN_RSP);
209
210 if (p_scan_rsp != NULL && data_len > 0) {
211 if (data_len > HCIC_PARAM_SIZE_BLE_WRITE_SCAN_RSP)
212 data_len = HCIC_PARAM_SIZE_BLE_WRITE_SCAN_RSP;
213
214 UINT8_TO_STREAM(pp, data_len);
215
216 ARRAY_TO_STREAM(pp, p_scan_rsp, data_len);
217 }
218
219 btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
220 }
221
btsnd_hcic_ble_set_adv_enable(uint8_t adv_enable)222 void btsnd_hcic_ble_set_adv_enable(uint8_t adv_enable) {
223 BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
224 uint8_t* pp = (uint8_t*)(p + 1);
225
226 p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_WRITE_ADV_ENABLE;
227 p->offset = 0;
228
229 UINT16_TO_STREAM(pp, HCI_BLE_WRITE_ADV_ENABLE);
230 UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_WRITE_ADV_ENABLE);
231
232 UINT8_TO_STREAM(pp, adv_enable);
233
234 btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
235 }
btsnd_hcic_ble_set_scan_params(uint8_t scan_type,uint16_t scan_int,uint16_t scan_win,uint8_t addr_type_own,uint8_t scan_filter_policy)236 void btsnd_hcic_ble_set_scan_params(uint8_t scan_type, uint16_t scan_int,
237 uint16_t scan_win, uint8_t addr_type_own,
238 uint8_t scan_filter_policy) {
239 BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
240 uint8_t* pp = (uint8_t*)(p + 1);
241
242 p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_WRITE_SCAN_PARAM;
243 p->offset = 0;
244
245 UINT16_TO_STREAM(pp, HCI_BLE_WRITE_SCAN_PARAMS);
246 UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_BLE_WRITE_SCAN_PARAM);
247
248 UINT8_TO_STREAM(pp, scan_type);
249 UINT16_TO_STREAM(pp, scan_int);
250 UINT16_TO_STREAM(pp, scan_win);
251 UINT8_TO_STREAM(pp, addr_type_own);
252 UINT8_TO_STREAM(pp, scan_filter_policy);
253
254 btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
255 }
256
btsnd_hcic_ble_set_scan_enable(uint8_t scan_enable,uint8_t duplicate)257 void btsnd_hcic_ble_set_scan_enable(uint8_t scan_enable, uint8_t duplicate) {
258 BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
259 uint8_t* pp = (uint8_t*)(p + 1);
260
261 p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_WRITE_SCAN_ENABLE;
262 p->offset = 0;
263
264 UINT16_TO_STREAM(pp, HCI_BLE_WRITE_SCAN_ENABLE);
265 UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_BLE_WRITE_SCAN_ENABLE);
266
267 UINT8_TO_STREAM(pp, scan_enable);
268 UINT8_TO_STREAM(pp, duplicate);
269
270 btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
271 }
272
273 /* link layer connection management commands */
btsnd_hcic_ble_create_ll_conn(uint16_t scan_int,uint16_t scan_win,uint8_t init_filter_policy,uint8_t addr_type_peer,const RawAddress & bda_peer,uint8_t addr_type_own,uint16_t conn_int_min,uint16_t conn_int_max,uint16_t conn_latency,uint16_t conn_timeout,uint16_t min_ce_len,uint16_t max_ce_len)274 void btsnd_hcic_ble_create_ll_conn(
275 uint16_t scan_int, uint16_t scan_win, uint8_t init_filter_policy,
276 uint8_t addr_type_peer, const RawAddress& bda_peer, uint8_t addr_type_own,
277 uint16_t conn_int_min, uint16_t conn_int_max, uint16_t conn_latency,
278 uint16_t conn_timeout, uint16_t min_ce_len, uint16_t max_ce_len) {
279 BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
280 uint8_t* pp = (uint8_t*)(p + 1);
281
282 p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_CREATE_LL_CONN;
283 p->offset = 0;
284
285 UINT16_TO_STREAM(pp, HCI_BLE_CREATE_LL_CONN);
286 UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_BLE_CREATE_LL_CONN);
287
288 UINT16_TO_STREAM(pp, scan_int);
289 UINT16_TO_STREAM(pp, scan_win);
290 UINT8_TO_STREAM(pp, init_filter_policy);
291
292 UINT8_TO_STREAM(pp, addr_type_peer);
293 BDADDR_TO_STREAM(pp, bda_peer);
294 UINT8_TO_STREAM(pp, addr_type_own);
295
296 UINT16_TO_STREAM(pp, conn_int_min);
297 UINT16_TO_STREAM(pp, conn_int_max);
298 UINT16_TO_STREAM(pp, conn_latency);
299 UINT16_TO_STREAM(pp, conn_timeout);
300
301 UINT16_TO_STREAM(pp, min_ce_len);
302 UINT16_TO_STREAM(pp, max_ce_len);
303
304 btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
305 }
306
btsnd_hcic_ble_create_conn_cancel(void)307 void btsnd_hcic_ble_create_conn_cancel(void) {
308 BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
309 uint8_t* pp = (uint8_t*)(p + 1);
310
311 p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_CREATE_CONN_CANCEL;
312 p->offset = 0;
313
314 UINT16_TO_STREAM(pp, HCI_BLE_CREATE_CONN_CANCEL);
315 UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_BLE_CREATE_CONN_CANCEL);
316
317 btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
318 }
319
btsnd_hcic_ble_clear_acceptlist(base::OnceCallback<void (uint8_t *,uint16_t)> cb)320 void btsnd_hcic_ble_clear_acceptlist(
321 base::OnceCallback<void(uint8_t*, uint16_t)> cb) {
322 btu_hcif_send_cmd_with_cb(FROM_HERE, HCI_BLE_CLEAR_ACCEPTLIST, nullptr, 0,
323 std::move(cb));
324 }
325
btsnd_hcic_ble_add_acceptlist(uint8_t addr_type,const RawAddress & bda,base::OnceCallback<void (uint8_t *,uint16_t)> cb)326 void btsnd_hcic_ble_add_acceptlist(
327 uint8_t addr_type, const RawAddress& bda,
328 base::OnceCallback<void(uint8_t*, uint16_t)> cb) {
329 uint8_t param[HCIC_PARAM_SIZE_ADD_ACCEPTLIST];
330 uint8_t* pp = param;
331
332 UINT8_TO_STREAM(pp, addr_type);
333 BDADDR_TO_STREAM(pp, bda);
334
335 btu_hcif_send_cmd_with_cb(FROM_HERE, HCI_BLE_ADD_ACCEPTLIST, param,
336 HCIC_PARAM_SIZE_ADD_ACCEPTLIST, std::move(cb));
337 }
338
btsnd_hcic_ble_remove_from_acceptlist(uint8_t addr_type,const RawAddress & bda,base::OnceCallback<void (uint8_t *,uint16_t)> cb)339 void btsnd_hcic_ble_remove_from_acceptlist(
340 uint8_t addr_type, const RawAddress& bda,
341 base::OnceCallback<void(uint8_t*, uint16_t)> cb) {
342 uint8_t param[HCIC_PARAM_SIZE_REMOVE_ACCEPTLIST];
343 uint8_t* pp = param;
344
345 UINT8_TO_STREAM(pp, addr_type);
346 BDADDR_TO_STREAM(pp, bda);
347
348 btu_hcif_send_cmd_with_cb(FROM_HERE, HCI_BLE_REMOVE_ACCEPTLIST, param,
349 HCIC_PARAM_SIZE_REMOVE_ACCEPTLIST, std::move(cb));
350 }
351
btsnd_hcic_ble_upd_ll_conn_params(uint16_t handle,uint16_t conn_int_min,uint16_t conn_int_max,uint16_t conn_latency,uint16_t conn_timeout,uint16_t min_ce_len,uint16_t max_ce_len)352 void btsnd_hcic_ble_upd_ll_conn_params(uint16_t handle, uint16_t conn_int_min,
353 uint16_t conn_int_max,
354 uint16_t conn_latency,
355 uint16_t conn_timeout,
356 uint16_t min_ce_len,
357 uint16_t max_ce_len) {
358 BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
359 uint8_t* pp = (uint8_t*)(p + 1);
360
361 p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_UPD_LL_CONN_PARAMS;
362 p->offset = 0;
363
364 UINT16_TO_STREAM(pp, HCI_BLE_UPD_LL_CONN_PARAMS);
365 UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_BLE_UPD_LL_CONN_PARAMS);
366
367 UINT16_TO_STREAM(pp, handle);
368
369 UINT16_TO_STREAM(pp, conn_int_min);
370 UINT16_TO_STREAM(pp, conn_int_max);
371 UINT16_TO_STREAM(pp, conn_latency);
372 UINT16_TO_STREAM(pp, conn_timeout);
373 UINT16_TO_STREAM(pp, min_ce_len);
374 UINT16_TO_STREAM(pp, max_ce_len);
375
376 btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
377 }
378
btsnd_hcic_ble_set_host_chnl_class(uint8_t chnl_map[HCIC_BLE_CHNL_MAP_SIZE])379 void btsnd_hcic_ble_set_host_chnl_class(
380 uint8_t chnl_map[HCIC_BLE_CHNL_MAP_SIZE]) {
381 BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
382 uint8_t* pp = (uint8_t*)(p + 1);
383
384 p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_SET_HOST_CHNL_CLASS;
385 p->offset = 0;
386
387 UINT16_TO_STREAM(pp, HCI_BLE_SET_HOST_CHNL_CLASS);
388 UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_SET_HOST_CHNL_CLASS);
389
390 ARRAY_TO_STREAM(pp, chnl_map, HCIC_BLE_CHNL_MAP_SIZE);
391
392 btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
393 }
394
btsnd_hcic_ble_read_chnl_map(uint16_t handle)395 void btsnd_hcic_ble_read_chnl_map(uint16_t handle) {
396 BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
397 uint8_t* pp = (uint8_t*)(p + 1);
398
399 p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_READ_CHNL_MAP;
400 p->offset = 0;
401
402 UINT16_TO_STREAM(pp, HCI_BLE_READ_CHNL_MAP);
403 UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_READ_CHNL_MAP);
404
405 UINT16_TO_STREAM(pp, handle);
406
407 btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
408 }
409
btsnd_hcic_ble_read_remote_feat(uint16_t handle)410 void btsnd_hcic_ble_read_remote_feat(uint16_t handle) {
411 BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
412 uint8_t* pp = (uint8_t*)(p + 1);
413
414 p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_READ_REMOTE_FEAT;
415 p->offset = 0;
416
417 UINT16_TO_STREAM(pp, HCI_BLE_READ_REMOTE_FEAT);
418 UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_BLE_READ_REMOTE_FEAT);
419
420 UINT16_TO_STREAM(pp, handle);
421
422 btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
423 }
424
425 /* security management commands */
btsnd_hcic_ble_encrypt(uint8_t * key,uint8_t key_len,uint8_t * plain_text,uint8_t pt_len,void * p_cmd_cplt_cback)426 void btsnd_hcic_ble_encrypt(uint8_t* key, uint8_t key_len, uint8_t* plain_text,
427 uint8_t pt_len, void* p_cmd_cplt_cback) {
428 BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
429 uint8_t* pp = (uint8_t*)(p + 1);
430
431 p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_ENCRYPT;
432 p->offset = sizeof(void*);
433
434 *((void**)pp) =
435 p_cmd_cplt_cback; /* Store command complete callback in buffer */
436 pp += sizeof(void*); /* Skip over callback pointer */
437
438 UINT16_TO_STREAM(pp, HCI_BLE_ENCRYPT);
439 UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_BLE_ENCRYPT);
440
441 memset(pp, 0, HCIC_PARAM_SIZE_BLE_ENCRYPT);
442
443 if (key_len > HCIC_BLE_ENCRYPT_KEY_SIZE) key_len = HCIC_BLE_ENCRYPT_KEY_SIZE;
444 if (pt_len > HCIC_BLE_ENCRYPT_KEY_SIZE) pt_len = HCIC_BLE_ENCRYPT_KEY_SIZE;
445
446 ARRAY_TO_STREAM(pp, key, key_len);
447 pp += (HCIC_BLE_ENCRYPT_KEY_SIZE - key_len);
448 ARRAY_TO_STREAM(pp, plain_text, pt_len);
449
450 btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
451 }
452
btsnd_hcic_ble_rand(base::Callback<void (BT_OCTET8)> cb)453 void btsnd_hcic_ble_rand(base::Callback<void(BT_OCTET8)> cb) {
454 btu_hcif_send_cmd_with_cb(FROM_HERE, HCI_BLE_RAND, nullptr, 0,
455 base::Bind(
456 [](base::Callback<void(BT_OCTET8)> cb,
457 uint8_t* param, uint16_t param_len) {
458 CHECK(param[0] == 0)
459 << "LE Rand return status must be zero";
460 cb.Run(param + 1 /* skip status */);
461 },
462 std::move(cb)));
463 }
464
btsnd_hcic_ble_start_enc(uint16_t handle,uint8_t rand[HCIC_BLE_RAND_DI_SIZE],uint16_t ediv,const Octet16 & ltk)465 void btsnd_hcic_ble_start_enc(uint16_t handle,
466 uint8_t rand[HCIC_BLE_RAND_DI_SIZE],
467 uint16_t ediv, const Octet16& ltk) {
468 BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
469 uint8_t* pp = (uint8_t*)(p + 1);
470
471 p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_START_ENC;
472 p->offset = 0;
473
474 UINT16_TO_STREAM(pp, HCI_BLE_START_ENC);
475 UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_BLE_START_ENC);
476
477 UINT16_TO_STREAM(pp, handle);
478 ARRAY_TO_STREAM(pp, rand, HCIC_BLE_RAND_DI_SIZE);
479 UINT16_TO_STREAM(pp, ediv);
480 ARRAY_TO_STREAM(pp, ltk.data(), HCIC_BLE_ENCRYPT_KEY_SIZE);
481
482 btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
483 }
484
btsnd_hcic_ble_ltk_req_reply(uint16_t handle,const Octet16 & ltk)485 void btsnd_hcic_ble_ltk_req_reply(uint16_t handle, const Octet16& ltk) {
486 BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
487 uint8_t* pp = (uint8_t*)(p + 1);
488
489 p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_LTK_REQ_REPLY;
490 p->offset = 0;
491
492 UINT16_TO_STREAM(pp, HCI_BLE_LTK_REQ_REPLY);
493 UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_LTK_REQ_REPLY);
494
495 UINT16_TO_STREAM(pp, handle);
496 ARRAY_TO_STREAM(pp, ltk.data(), HCIC_BLE_ENCRYPT_KEY_SIZE);
497
498 btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
499 }
500
btsnd_hcic_ble_ltk_req_neg_reply(uint16_t handle)501 void btsnd_hcic_ble_ltk_req_neg_reply(uint16_t handle) {
502 BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
503 uint8_t* pp = (uint8_t*)(p + 1);
504
505 p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_LTK_REQ_NEG_REPLY;
506 p->offset = 0;
507
508 UINT16_TO_STREAM(pp, HCI_BLE_LTK_REQ_NEG_REPLY);
509 UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_LTK_REQ_NEG_REPLY);
510
511 UINT16_TO_STREAM(pp, handle);
512
513 btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
514 }
515
btsnd_hcic_ble_receiver_test(uint8_t rx_freq)516 void btsnd_hcic_ble_receiver_test(uint8_t rx_freq) {
517 BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
518 uint8_t* pp = (uint8_t*)(p + 1);
519
520 p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_WRITE_PARAM1;
521 p->offset = 0;
522
523 UINT16_TO_STREAM(pp, HCI_BLE_RECEIVER_TEST);
524 UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_WRITE_PARAM1);
525
526 UINT8_TO_STREAM(pp, rx_freq);
527
528 btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
529 }
530
btsnd_hcic_ble_transmitter_test(uint8_t tx_freq,uint8_t test_data_len,uint8_t payload)531 void btsnd_hcic_ble_transmitter_test(uint8_t tx_freq, uint8_t test_data_len,
532 uint8_t payload) {
533 BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
534 uint8_t* pp = (uint8_t*)(p + 1);
535
536 p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_WRITE_PARAM3;
537 p->offset = 0;
538
539 UINT16_TO_STREAM(pp, HCI_BLE_TRANSMITTER_TEST);
540 UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_WRITE_PARAM3);
541
542 UINT8_TO_STREAM(pp, tx_freq);
543 UINT8_TO_STREAM(pp, test_data_len);
544 UINT8_TO_STREAM(pp, payload);
545
546 btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
547 }
548
btsnd_hcic_ble_test_end(void)549 void btsnd_hcic_ble_test_end(void) {
550 BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
551 uint8_t* pp = (uint8_t*)(p + 1);
552
553 p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_READ_CMD;
554 p->offset = 0;
555
556 UINT16_TO_STREAM(pp, HCI_BLE_TEST_END);
557 UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_READ_CMD);
558
559 btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
560 }
561
btsnd_hcic_ble_read_host_supported(void)562 void btsnd_hcic_ble_read_host_supported(void) {
563 BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
564 uint8_t* pp = (uint8_t*)(p + 1);
565
566 p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_READ_CMD;
567 p->offset = 0;
568
569 UINT16_TO_STREAM(pp, HCI_READ_LE_HOST_SUPPORT);
570 UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_READ_CMD);
571
572 btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
573 }
574
btsnd_hcic_ble_rc_param_req_reply(uint16_t handle,uint16_t conn_int_min,uint16_t conn_int_max,uint16_t conn_latency,uint16_t conn_timeout,uint16_t min_ce_len,uint16_t max_ce_len)575 void btsnd_hcic_ble_rc_param_req_reply(uint16_t handle, uint16_t conn_int_min,
576 uint16_t conn_int_max,
577 uint16_t conn_latency,
578 uint16_t conn_timeout,
579 uint16_t min_ce_len,
580 uint16_t max_ce_len) {
581 BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
582 uint8_t* pp = (uint8_t*)(p + 1);
583
584 p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_RC_PARAM_REQ_REPLY;
585 p->offset = 0;
586
587 UINT16_TO_STREAM(pp, HCI_BLE_RC_PARAM_REQ_REPLY);
588 UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_BLE_RC_PARAM_REQ_REPLY);
589
590 UINT16_TO_STREAM(pp, handle);
591 UINT16_TO_STREAM(pp, conn_int_min);
592 UINT16_TO_STREAM(pp, conn_int_max);
593 UINT16_TO_STREAM(pp, conn_latency);
594 UINT16_TO_STREAM(pp, conn_timeout);
595 UINT16_TO_STREAM(pp, min_ce_len);
596 UINT16_TO_STREAM(pp, max_ce_len);
597
598 btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
599 }
600
btsnd_hcic_ble_rc_param_req_neg_reply(uint16_t handle,uint8_t reason)601 void btsnd_hcic_ble_rc_param_req_neg_reply(uint16_t handle, uint8_t reason) {
602 BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
603 uint8_t* pp = (uint8_t*)(p + 1);
604
605 p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_RC_PARAM_REQ_NEG_REPLY;
606 p->offset = 0;
607
608 UINT16_TO_STREAM(pp, HCI_BLE_RC_PARAM_REQ_NEG_REPLY);
609 UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_BLE_RC_PARAM_REQ_NEG_REPLY);
610
611 UINT16_TO_STREAM(pp, handle);
612 UINT8_TO_STREAM(pp, reason);
613
614 btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
615 }
616
btsnd_hcic_ble_add_device_resolving_list(uint8_t addr_type_peer,const RawAddress & bda_peer,const Octet16 & irk_peer,const Octet16 & irk_local)617 void btsnd_hcic_ble_add_device_resolving_list(uint8_t addr_type_peer,
618 const RawAddress& bda_peer,
619 const Octet16& irk_peer,
620 const Octet16& irk_local) {
621 BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
622 uint8_t* pp = (uint8_t*)(p + 1);
623
624 p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_ADD_DEV_RESOLVING_LIST;
625 p->offset = 0;
626
627 UINT16_TO_STREAM(pp, HCI_BLE_ADD_DEV_RESOLVING_LIST);
628 UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_BLE_ADD_DEV_RESOLVING_LIST);
629 UINT8_TO_STREAM(pp, addr_type_peer);
630 BDADDR_TO_STREAM(pp, bda_peer);
631 ARRAY_TO_STREAM(pp, irk_peer.data(), HCIC_BLE_ENCRYPT_KEY_SIZE);
632 ARRAY_TO_STREAM(pp, irk_local.data(), HCIC_BLE_ENCRYPT_KEY_SIZE);
633
634 btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
635 }
636
btsnd_hcic_ble_rm_device_resolving_list(uint8_t addr_type_peer,const RawAddress & bda_peer)637 void btsnd_hcic_ble_rm_device_resolving_list(uint8_t addr_type_peer,
638 const RawAddress& bda_peer) {
639 BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
640 uint8_t* pp = (uint8_t*)(p + 1);
641
642 p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_RM_DEV_RESOLVING_LIST;
643 p->offset = 0;
644
645 UINT16_TO_STREAM(pp, HCI_BLE_RM_DEV_RESOLVING_LIST);
646 UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_BLE_RM_DEV_RESOLVING_LIST);
647 UINT8_TO_STREAM(pp, addr_type_peer);
648 BDADDR_TO_STREAM(pp, bda_peer);
649
650 btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
651 }
652
btsnd_hcic_ble_set_privacy_mode(uint8_t addr_type_peer,const RawAddress & bda_peer,uint8_t privacy_type)653 void btsnd_hcic_ble_set_privacy_mode(uint8_t addr_type_peer,
654 const RawAddress& bda_peer,
655 uint8_t privacy_type) {
656 BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
657 uint8_t* pp = (uint8_t*)(p + 1);
658
659 p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_SET_PRIVACY_MODE;
660 p->offset = 0;
661
662 UINT16_TO_STREAM(pp, HCI_BLE_SET_PRIVACY_MODE);
663 UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_BLE_SET_PRIVACY_MODE);
664 UINT8_TO_STREAM(pp, addr_type_peer);
665 BDADDR_TO_STREAM(pp, bda_peer);
666 UINT8_TO_STREAM(pp, privacy_type);
667
668 btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
669 }
670
btsnd_hcic_ble_clear_resolving_list(void)671 void btsnd_hcic_ble_clear_resolving_list(void) {
672 BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
673 uint8_t* pp = (uint8_t*)(p + 1);
674
675 p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_CLEAR_RESOLVING_LIST;
676 p->offset = 0;
677
678 UINT16_TO_STREAM(pp, HCI_BLE_CLEAR_RESOLVING_LIST);
679 UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_BLE_CLEAR_RESOLVING_LIST);
680
681 btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
682 }
683
btsnd_hcic_ble_read_resolvable_addr_peer(uint8_t addr_type_peer,const RawAddress & bda_peer)684 void btsnd_hcic_ble_read_resolvable_addr_peer(uint8_t addr_type_peer,
685 const RawAddress& bda_peer) {
686 BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
687 uint8_t* pp = (uint8_t*)(p + 1);
688
689 p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_READ_RESOLVABLE_ADDR_PEER;
690 p->offset = 0;
691
692 UINT16_TO_STREAM(pp, HCI_BLE_READ_RESOLVABLE_ADDR_PEER);
693 UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_BLE_READ_RESOLVABLE_ADDR_PEER);
694 UINT8_TO_STREAM(pp, addr_type_peer);
695 BDADDR_TO_STREAM(pp, bda_peer);
696
697 btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
698 }
699
btsnd_hcic_ble_read_resolvable_addr_local(uint8_t addr_type_peer,const RawAddress & bda_peer)700 void btsnd_hcic_ble_read_resolvable_addr_local(uint8_t addr_type_peer,
701 const RawAddress& bda_peer) {
702 BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
703 uint8_t* pp = (uint8_t*)(p + 1);
704
705 p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_READ_RESOLVABLE_ADDR_LOCAL;
706 p->offset = 0;
707
708 UINT16_TO_STREAM(pp, HCI_BLE_READ_RESOLVABLE_ADDR_LOCAL);
709 UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_BLE_READ_RESOLVABLE_ADDR_LOCAL);
710 UINT8_TO_STREAM(pp, addr_type_peer);
711 BDADDR_TO_STREAM(pp, bda_peer);
712
713 btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
714 }
715
btsnd_hcic_ble_set_addr_resolution_enable(uint8_t addr_resolution_enable)716 void btsnd_hcic_ble_set_addr_resolution_enable(uint8_t addr_resolution_enable) {
717 BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
718 uint8_t* pp = (uint8_t*)(p + 1);
719
720 p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_SET_ADDR_RESOLUTION_ENABLE;
721 p->offset = 0;
722
723 UINT16_TO_STREAM(pp, HCI_BLE_SET_ADDR_RESOLUTION_ENABLE);
724 UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_BLE_SET_ADDR_RESOLUTION_ENABLE);
725 UINT8_TO_STREAM(pp, addr_resolution_enable);
726
727 btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
728 }
729
btsnd_hcic_ble_set_rand_priv_addr_timeout(uint16_t rpa_timout)730 void btsnd_hcic_ble_set_rand_priv_addr_timeout(uint16_t rpa_timout) {
731 BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
732 uint8_t* pp = (uint8_t*)(p + 1);
733
734 p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_SET_RAND_PRIV_ADDR_TIMOUT;
735 p->offset = 0;
736
737 UINT16_TO_STREAM(pp, HCI_BLE_SET_RAND_PRIV_ADDR_TIMOUT);
738 UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_BLE_SET_RAND_PRIV_ADDR_TIMOUT);
739 UINT16_TO_STREAM(pp, rpa_timout);
740
741 btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
742 }
743
btsnd_hcic_ble_set_data_length(uint16_t conn_handle,uint16_t tx_octets,uint16_t tx_time)744 void btsnd_hcic_ble_set_data_length(uint16_t conn_handle, uint16_t tx_octets,
745 uint16_t tx_time) {
746 BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
747 uint8_t* pp = (uint8_t*)(p + 1);
748
749 p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_SET_DATA_LENGTH;
750 p->offset = 0;
751
752 UINT16_TO_STREAM(pp, HCI_BLE_SET_DATA_LENGTH);
753 UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_BLE_SET_DATA_LENGTH);
754
755 UINT16_TO_STREAM(pp, conn_handle);
756 UINT16_TO_STREAM(pp, tx_octets);
757 UINT16_TO_STREAM(pp, tx_time);
758
759 btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
760 }
761
btsnd_hcic_ble_enh_rx_test(uint8_t rx_chan,uint8_t phy,uint8_t mod_index)762 void btsnd_hcic_ble_enh_rx_test(uint8_t rx_chan, uint8_t phy,
763 uint8_t mod_index) {
764 BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
765 uint8_t* pp = (uint8_t*)(p + 1);
766
767 p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_ENH_RX_TEST;
768 p->offset = 0;
769
770 UINT16_TO_STREAM(pp, HCI_BLE_ENH_RECEIVER_TEST);
771 UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_BLE_ENH_RX_TEST);
772
773 UINT8_TO_STREAM(pp, rx_chan);
774 UINT8_TO_STREAM(pp, phy);
775 UINT8_TO_STREAM(pp, mod_index);
776
777 btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
778 }
779
btsnd_hcic_ble_enh_tx_test(uint8_t tx_chan,uint8_t data_len,uint8_t payload,uint8_t phy)780 void btsnd_hcic_ble_enh_tx_test(uint8_t tx_chan, uint8_t data_len,
781 uint8_t payload, uint8_t phy) {
782 BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
783 uint8_t* pp = (uint8_t*)(p + 1);
784
785 p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_ENH_TX_TEST;
786 p->offset = 0;
787
788 UINT16_TO_STREAM(pp, HCI_BLE_ENH_TRANSMITTER_TEST);
789 UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_BLE_ENH_TX_TEST);
790 UINT8_TO_STREAM(pp, tx_chan);
791 UINT8_TO_STREAM(pp, data_len);
792 UINT8_TO_STREAM(pp, payload);
793 UINT8_TO_STREAM(pp, phy);
794
795 btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
796 }
797
btsnd_hcic_ble_set_extended_scan_params(uint8_t own_address_type,uint8_t scanning_filter_policy,uint8_t scanning_phys,scanning_phy_cfg * phy_cfg)798 void btsnd_hcic_ble_set_extended_scan_params(uint8_t own_address_type,
799 uint8_t scanning_filter_policy,
800 uint8_t scanning_phys,
801 scanning_phy_cfg* phy_cfg) {
802 BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
803 uint8_t* pp = (uint8_t*)(p + 1);
804
805 int phy_cnt =
806 std::bitset<std::numeric_limits<uint8_t>::digits>(scanning_phys).count();
807
808 uint16_t param_len = 3 + (5 * phy_cnt);
809 p->len = HCIC_PREAMBLE_SIZE + param_len;
810 p->offset = 0;
811
812 UINT16_TO_STREAM(pp, HCI_LE_SET_EXTENDED_SCAN_PARAMETERS);
813 UINT8_TO_STREAM(pp, param_len);
814
815 UINT8_TO_STREAM(pp, own_address_type);
816 UINT8_TO_STREAM(pp, scanning_filter_policy);
817 UINT8_TO_STREAM(pp, scanning_phys);
818
819 for (int i = 0; i < phy_cnt; i++) {
820 UINT8_TO_STREAM(pp, phy_cfg[i].scan_type);
821 UINT16_TO_STREAM(pp, phy_cfg[i].scan_int);
822 UINT16_TO_STREAM(pp, phy_cfg[i].scan_win);
823 }
824
825 btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
826 }
827
btsnd_hcic_ble_set_extended_scan_enable(uint8_t enable,uint8_t filter_duplicates,uint16_t duration,uint16_t period)828 void btsnd_hcic_ble_set_extended_scan_enable(uint8_t enable,
829 uint8_t filter_duplicates,
830 uint16_t duration,
831 uint16_t period) {
832 BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
833 uint8_t* pp = (uint8_t*)(p + 1);
834
835 const int param_len = 6;
836 p->len = HCIC_PREAMBLE_SIZE + param_len;
837 p->offset = 0;
838
839 UINT16_TO_STREAM(pp, HCI_LE_SET_EXTENDED_SCAN_ENABLE);
840 UINT8_TO_STREAM(pp, param_len);
841
842 UINT8_TO_STREAM(pp, enable);
843 UINT8_TO_STREAM(pp, filter_duplicates);
844 UINT16_TO_STREAM(pp, duration);
845 UINT16_TO_STREAM(pp, period);
846
847 btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
848 }
849
btsnd_hcic_ble_ext_create_conn(uint8_t init_filter_policy,uint8_t addr_type_own,uint8_t addr_type_peer,const RawAddress & bda_peer,uint8_t initiating_phys,EXT_CONN_PHY_CFG * phy_cfg)850 void btsnd_hcic_ble_ext_create_conn(uint8_t init_filter_policy,
851 uint8_t addr_type_own,
852 uint8_t addr_type_peer,
853 const RawAddress& bda_peer,
854 uint8_t initiating_phys,
855 EXT_CONN_PHY_CFG* phy_cfg) {
856 BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
857 uint8_t* pp = (uint8_t*)(p + 1);
858
859 int phy_cnt =
860 std::bitset<std::numeric_limits<uint8_t>::digits>(initiating_phys)
861 .count();
862
863 /* param_len = initial_params + size_per_channel * num_of_channels */
864 uint8_t param_len = 10 + (16 * phy_cnt);
865
866 p->len = HCIC_PREAMBLE_SIZE + param_len;
867 p->offset = 0;
868
869 UINT16_TO_STREAM(pp, HCI_LE_EXTENDED_CREATE_CONNECTION);
870 UINT8_TO_STREAM(pp, param_len);
871
872 UINT8_TO_STREAM(pp, init_filter_policy);
873 UINT8_TO_STREAM(pp, addr_type_own);
874 UINT8_TO_STREAM(pp, addr_type_peer);
875 BDADDR_TO_STREAM(pp, bda_peer);
876
877 UINT8_TO_STREAM(pp, initiating_phys);
878
879 for (int i = 0; i < phy_cnt; i++) {
880 UINT16_TO_STREAM(pp, phy_cfg[i].scan_int);
881 UINT16_TO_STREAM(pp, phy_cfg[i].scan_win);
882 UINT16_TO_STREAM(pp, phy_cfg[i].conn_int_min);
883 UINT16_TO_STREAM(pp, phy_cfg[i].conn_int_max);
884 UINT16_TO_STREAM(pp, phy_cfg[i].conn_latency);
885 UINT16_TO_STREAM(pp, phy_cfg[i].sup_timeout);
886 UINT16_TO_STREAM(pp, phy_cfg[i].min_ce_len);
887 UINT16_TO_STREAM(pp, phy_cfg[i].max_ce_len);
888 }
889
890 btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
891 }
892
btsnd_hcic_read_iso_tx_sync(uint16_t iso_handle,base::OnceCallback<void (uint8_t *,uint16_t)> cb)893 void btsnd_hcic_read_iso_tx_sync(
894 uint16_t iso_handle, base::OnceCallback<void(uint8_t*, uint16_t)> cb) {
895 const int params_len = 2;
896 uint8_t param[params_len];
897 uint8_t* pp = param;
898
899 UINT16_TO_STREAM(pp, iso_handle);
900
901 btu_hcif_send_cmd_with_cb(FROM_HERE, HCI_LE_READ_ISO_TX_SYNC, param,
902 params_len, std::move(cb));
903 }
904
btsnd_hcic_set_cig_params(uint8_t cig_id,uint32_t sdu_itv_mtos,uint32_t sdu_itv_stom,uint8_t sca,uint8_t packing,uint8_t framing,uint16_t max_trans_lat_stom,uint16_t max_trans_lat_mtos,uint8_t cis_cnt,const EXT_CIS_CFG * cis_cfg,base::OnceCallback<void (uint8_t *,uint16_t)> cb)905 void btsnd_hcic_set_cig_params(
906 uint8_t cig_id, uint32_t sdu_itv_mtos, uint32_t sdu_itv_stom, uint8_t sca,
907 uint8_t packing, uint8_t framing, uint16_t max_trans_lat_stom,
908 uint16_t max_trans_lat_mtos, uint8_t cis_cnt, const EXT_CIS_CFG* cis_cfg,
909 base::OnceCallback<void(uint8_t*, uint16_t)> cb) {
910 const int params_len = 15 + cis_cnt * 9;
911 uint8_t param[params_len];
912 uint8_t* pp = param;
913
914 UINT8_TO_STREAM(pp, cig_id);
915 UINT24_TO_STREAM(pp, sdu_itv_mtos);
916 UINT24_TO_STREAM(pp, sdu_itv_stom);
917 UINT8_TO_STREAM(pp, sca);
918 UINT8_TO_STREAM(pp, packing);
919 UINT8_TO_STREAM(pp, framing);
920 UINT16_TO_STREAM(pp, max_trans_lat_mtos);
921 UINT16_TO_STREAM(pp, max_trans_lat_stom);
922 UINT8_TO_STREAM(pp, cis_cnt);
923
924 for (int i = 0; i < cis_cnt; i++) {
925 UINT8_TO_STREAM(pp, cis_cfg[i].cis_id);
926 UINT16_TO_STREAM(pp, cis_cfg[i].max_sdu_size_mtos);
927 UINT16_TO_STREAM(pp, cis_cfg[i].max_sdu_size_stom);
928 UINT8_TO_STREAM(pp, cis_cfg[i].phy_mtos);
929 UINT8_TO_STREAM(pp, cis_cfg[i].phy_stom);
930 UINT8_TO_STREAM(pp, cis_cfg[i].rtn_mtos);
931 UINT8_TO_STREAM(pp, cis_cfg[i].rtn_stom);
932 }
933
934 btu_hcif_send_cmd_with_cb(FROM_HERE, HCI_LE_SET_CIG_PARAMS, param, params_len,
935 std::move(cb));
936 }
937
btsnd_hcic_create_cis(uint8_t num_cis,const EXT_CIS_CREATE_CFG * cis_cfg,base::OnceCallback<void (uint8_t *,uint16_t)> cb)938 void btsnd_hcic_create_cis(uint8_t num_cis, const EXT_CIS_CREATE_CFG* cis_cfg,
939 base::OnceCallback<void(uint8_t*, uint16_t)> cb) {
940 const int params_len = 1 + num_cis * 4;
941 uint8_t param[params_len];
942 uint8_t* pp = param;
943
944 UINT8_TO_STREAM(pp, num_cis);
945
946 for (int i = 0; i < num_cis; i++) {
947 UINT16_TO_STREAM(pp, cis_cfg[i].cis_conn_handle);
948 UINT16_TO_STREAM(pp, cis_cfg[i].acl_conn_handle);
949 }
950
951 btu_hcif_send_cmd_with_cb(FROM_HERE, HCI_LE_CREATE_CIS, param, params_len,
952 std::move(cb));
953 }
954
btsnd_hcic_remove_cig(uint8_t cig_id,base::OnceCallback<void (uint8_t *,uint16_t)> cb)955 void btsnd_hcic_remove_cig(uint8_t cig_id,
956 base::OnceCallback<void(uint8_t*, uint16_t)> cb) {
957 const int params_len = 1;
958 uint8_t param[params_len];
959 uint8_t* pp = param;
960
961 UINT8_TO_STREAM(pp, cig_id);
962
963 btu_hcif_send_cmd_with_cb(FROM_HERE, HCI_LE_REMOVE_CIG, param, params_len,
964 std::move(cb));
965 }
966
btsnd_hcic_accept_cis_req(uint16_t conn_handle)967 void btsnd_hcic_accept_cis_req(uint16_t conn_handle) {
968 BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
969 uint8_t* pp = (uint8_t*)(p + 1);
970
971 const int param_len = 2;
972 p->len = HCIC_PREAMBLE_SIZE + param_len;
973 p->offset = 0;
974
975 UINT16_TO_STREAM(pp, HCI_LE_ACCEPT_CIS_REQ);
976 UINT8_TO_STREAM(pp, param_len);
977
978 UINT16_TO_STREAM(pp, conn_handle);
979
980 btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
981 }
982
btsnd_hcic_rej_cis_req(uint16_t conn_handle,uint8_t reason,base::OnceCallback<void (uint8_t *,uint16_t)> cb)983 void btsnd_hcic_rej_cis_req(uint16_t conn_handle, uint8_t reason,
984 base::OnceCallback<void(uint8_t*, uint16_t)> cb) {
985 const int params_len = 3;
986 uint8_t param[params_len];
987 uint8_t* pp = param;
988
989 UINT16_TO_STREAM(pp, conn_handle);
990 UINT8_TO_STREAM(pp, reason);
991
992 btu_hcif_send_cmd_with_cb(FROM_HERE, HCI_LE_REJ_CIS_REQ, param, params_len,
993 std::move(cb));
994 }
995
btsnd_hcic_req_peer_sca(uint16_t conn_handle)996 void btsnd_hcic_req_peer_sca(uint16_t conn_handle) {
997 BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
998 uint8_t* pp = (uint8_t*)(p + 1);
999
1000 const int param_len = 2;
1001 p->len = HCIC_PREAMBLE_SIZE + param_len;
1002 p->offset = 0;
1003
1004 UINT16_TO_STREAM(pp, HCI_LE_REQ_PEER_SCA);
1005 UINT8_TO_STREAM(pp, param_len);
1006 UINT16_TO_STREAM(pp, conn_handle);
1007
1008 btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
1009 }
1010
btsnd_hcic_create_big(uint8_t big_handle,uint8_t adv_handle,uint8_t num_bis,uint32_t sdu_itv,uint16_t max_sdu_size,uint16_t transport_latency,uint8_t rtn,uint8_t phy,uint8_t packing,uint8_t framing,uint8_t enc,std::array<uint8_t,16> bcst_code)1011 void btsnd_hcic_create_big(uint8_t big_handle, uint8_t adv_handle,
1012 uint8_t num_bis, uint32_t sdu_itv,
1013 uint16_t max_sdu_size, uint16_t transport_latency,
1014 uint8_t rtn, uint8_t phy, uint8_t packing,
1015 uint8_t framing, uint8_t enc,
1016 std::array<uint8_t, 16> bcst_code) {
1017 BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
1018 uint8_t* pp = (uint8_t*)(p + 1);
1019
1020 const int param_len = 31;
1021 p->len = HCIC_PREAMBLE_SIZE + param_len;
1022 p->offset = 0;
1023
1024 UINT16_TO_STREAM(pp, HCI_LE_CREATE_BIG);
1025 UINT8_TO_STREAM(pp, param_len);
1026
1027 UINT8_TO_STREAM(pp, big_handle);
1028 UINT8_TO_STREAM(pp, adv_handle);
1029 UINT8_TO_STREAM(pp, num_bis);
1030 UINT24_TO_STREAM(pp, sdu_itv);
1031 UINT16_TO_STREAM(pp, max_sdu_size);
1032 UINT16_TO_STREAM(pp, transport_latency);
1033 UINT8_TO_STREAM(pp, rtn);
1034 UINT8_TO_STREAM(pp, phy);
1035 UINT8_TO_STREAM(pp, packing);
1036 UINT8_TO_STREAM(pp, framing);
1037 UINT8_TO_STREAM(pp, enc);
1038
1039 uint8_t* buf_ptr = bcst_code.data();
1040 ARRAY_TO_STREAM(pp, buf_ptr, 16);
1041
1042 btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
1043 }
1044
btsnd_hcic_term_big(uint8_t big_handle,uint8_t reason)1045 void btsnd_hcic_term_big(uint8_t big_handle, uint8_t reason) {
1046 BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
1047 uint8_t* pp = (uint8_t*)(p + 1);
1048
1049 const int param_len = 2;
1050 p->len = HCIC_PREAMBLE_SIZE + param_len;
1051 p->offset = 0;
1052
1053 UINT16_TO_STREAM(pp, HCI_LE_TERM_BIG);
1054 UINT8_TO_STREAM(pp, param_len);
1055
1056 UINT8_TO_STREAM(pp, big_handle);
1057 UINT8_TO_STREAM(pp, reason);
1058
1059 btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
1060 }
1061
btsnd_hcic_big_create_sync(uint8_t big_handle,uint16_t sync_handle,uint8_t enc,std::array<uint8_t,16> bcst_code,uint8_t mse,uint16_t big_sync_timeout,std::vector<uint8_t> bis)1062 void btsnd_hcic_big_create_sync(uint8_t big_handle, uint16_t sync_handle,
1063 uint8_t enc, std::array<uint8_t, 16> bcst_code,
1064 uint8_t mse, uint16_t big_sync_timeout,
1065 std::vector<uint8_t> bis) {
1066 BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
1067 uint8_t* pp = (uint8_t*)(p + 1);
1068 uint8_t num_bis = bis.size();
1069
1070 const int param_len = 24 + num_bis;
1071 p->len = HCIC_PREAMBLE_SIZE + param_len;
1072 p->offset = 0;
1073
1074 UINT16_TO_STREAM(pp, HCI_LE_BIG_CREATE_SYNC);
1075 UINT8_TO_STREAM(pp, param_len);
1076
1077 UINT8_TO_STREAM(pp, big_handle);
1078 UINT16_TO_STREAM(pp, sync_handle);
1079 UINT8_TO_STREAM(pp, enc);
1080
1081 uint8_t* buf_ptr = bcst_code.data();
1082 ARRAY_TO_STREAM(pp, buf_ptr, 16);
1083
1084 UINT8_TO_STREAM(pp, mse);
1085 UINT16_TO_STREAM(pp, big_sync_timeout);
1086 UINT8_TO_STREAM(pp, num_bis);
1087
1088 for (int i = 0; i < num_bis; i++) {
1089 UINT8_TO_STREAM(pp, bis[i]);
1090 }
1091
1092 btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
1093 }
1094
btsnd_hcic_big_term_sync(uint8_t big_handle,base::OnceCallback<void (uint8_t *,uint16_t)> cb)1095 void btsnd_hcic_big_term_sync(uint8_t big_handle,
1096 base::OnceCallback<void(uint8_t*, uint16_t)> cb) {
1097 const int params_len = 1;
1098 uint8_t param[params_len];
1099 uint8_t* pp = param;
1100
1101 UINT8_TO_STREAM(pp, big_handle);
1102
1103 btu_hcif_send_cmd_with_cb(FROM_HERE, HCI_LE_BIG_TERM_SYNC, param, params_len,
1104 std::move(cb));
1105 }
1106
btsnd_hcic_setup_iso_data_path(uint16_t iso_handle,uint8_t data_path_dir,uint8_t data_path_id,uint8_t codec_id_format,uint16_t codec_id_company,uint16_t codec_id_vendor,uint32_t controller_delay,std::vector<uint8_t> codec_conf,base::OnceCallback<void (uint8_t *,uint16_t)> cb)1107 void btsnd_hcic_setup_iso_data_path(
1108 uint16_t iso_handle, uint8_t data_path_dir, uint8_t data_path_id,
1109 uint8_t codec_id_format, uint16_t codec_id_company,
1110 uint16_t codec_id_vendor, uint32_t controller_delay,
1111 std::vector<uint8_t> codec_conf,
1112 base::OnceCallback<void(uint8_t*, uint16_t)> cb) {
1113 const int params_len = 13 + codec_conf.size();
1114 uint8_t param[params_len];
1115 uint8_t* pp = param;
1116
1117 UINT16_TO_STREAM(pp, iso_handle);
1118 UINT8_TO_STREAM(pp, data_path_dir);
1119 UINT8_TO_STREAM(pp, data_path_id);
1120 UINT8_TO_STREAM(pp, codec_id_format);
1121 UINT16_TO_STREAM(pp, codec_id_company);
1122 UINT16_TO_STREAM(pp, codec_id_vendor);
1123 UINT24_TO_STREAM(pp, controller_delay);
1124 UINT8_TO_STREAM(pp, codec_conf.size());
1125 ARRAY_TO_STREAM(pp, codec_conf.data(), static_cast<int>(codec_conf.size()));
1126
1127 btu_hcif_send_cmd_with_cb(FROM_HERE, HCI_LE_SETUP_ISO_DATA_PATH, param,
1128 params_len, std::move(cb));
1129 }
1130
btsnd_hcic_remove_iso_data_path(uint16_t iso_handle,uint8_t data_path_dir,base::OnceCallback<void (uint8_t *,uint16_t)> cb)1131 void btsnd_hcic_remove_iso_data_path(
1132 uint16_t iso_handle, uint8_t data_path_dir,
1133 base::OnceCallback<void(uint8_t*, uint16_t)> cb) {
1134 const int params_len = 3;
1135 uint8_t param[params_len];
1136 uint8_t* pp = param;
1137
1138 UINT16_TO_STREAM(pp, iso_handle);
1139 UINT8_TO_STREAM(pp, data_path_dir);
1140
1141 btu_hcif_send_cmd_with_cb(FROM_HERE, HCI_LE_REMOVE_ISO_DATA_PATH, param,
1142 params_len, std::move(cb));
1143 }
1144
btsnd_hcic_read_iso_link_quality(uint16_t iso_handle,base::OnceCallback<void (uint8_t *,uint16_t)> cb)1145 void btsnd_hcic_read_iso_link_quality(
1146 uint16_t iso_handle, base::OnceCallback<void(uint8_t*, uint16_t)> cb) {
1147 const int params_len = 2;
1148 uint8_t param[params_len];
1149 uint8_t* pp = param;
1150
1151 UINT16_TO_STREAM(pp, iso_handle);
1152
1153 btu_hcif_send_cmd_with_cb(FROM_HERE, HCI_LE_READ_ISO_LINK_QUALITY, param,
1154 params_len, std::move(cb));
1155 }
1156
btsnd_hcic_ble_periodic_advertising_create_sync(uint8_t options,uint8_t adv_sid,uint8_t adv_addr_type,const RawAddress & adv_addr,uint16_t skip_num,uint16_t sync_timeout,uint8_t sync_cte_type)1157 void btsnd_hcic_ble_periodic_advertising_create_sync(
1158 uint8_t options, uint8_t adv_sid, uint8_t adv_addr_type,
1159 const RawAddress& adv_addr, uint16_t skip_num, uint16_t sync_timeout,
1160 uint8_t sync_cte_type) {
1161 BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
1162 uint8_t* pp = (uint8_t*)(p + 1);
1163
1164 p->len =
1165 HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_PERIODIC_ADVERTISING_CREATE_SYNC;
1166 p->offset = 0;
1167
1168 UINT16_TO_STREAM(pp, HCI_BLE_PERIODIC_ADVERTISING_CREATE_SYNC);
1169 UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_PERIODIC_ADVERTISING_CREATE_SYNC);
1170 UINT8_TO_STREAM(pp, options);
1171 UINT8_TO_STREAM(pp, adv_sid);
1172 UINT8_TO_STREAM(pp, adv_addr_type);
1173 BDADDR_TO_STREAM(pp, adv_addr);
1174 UINT16_TO_STREAM(pp, skip_num);
1175 UINT16_TO_STREAM(pp, sync_timeout);
1176 UINT8_TO_STREAM(pp, sync_cte_type);
1177
1178 btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
1179 }
1180
btsnd_hcic_ble_periodic_advertising_create_sync_cancel(base::OnceCallback<void (uint8_t *,uint16_t)> cb)1181 void btsnd_hcic_ble_periodic_advertising_create_sync_cancel(
1182 base::OnceCallback<void(uint8_t*, uint16_t)> cb) {
1183 btu_hcif_send_cmd_with_cb(
1184 FROM_HERE, HCI_BLE_PERIODIC_ADVERTISING_CREATE_SYNC_CANCEL, nullptr,
1185 HCIC_PARAM_SIZE_PERIODIC_ADVERTISING_CREATE_SYNC_CANCEL, std::move(cb));
1186 }
1187
btsnd_hcic_ble_periodic_advertising_terminate_sync(uint16_t sync_handle,base::OnceCallback<void (uint8_t *,uint16_t)> cb)1188 void btsnd_hcic_ble_periodic_advertising_terminate_sync(
1189 uint16_t sync_handle, base::OnceCallback<void(uint8_t*, uint16_t)> cb) {
1190 uint8_t param[HCIC_PARAM_SIZE_PERIODIC_ADVERTISING_TERMINATE_SYNC];
1191 uint8_t* pp = param;
1192
1193 UINT16_TO_STREAM(pp, sync_handle);
1194
1195 btu_hcif_send_cmd_with_cb(
1196 FROM_HERE, HCI_BLE_PERIODIC_ADVERTISING_TERMINATE_SYNC, param,
1197 HCIC_PARAM_SIZE_PERIODIC_ADVERTISING_TERMINATE_SYNC, std::move(cb));
1198 }
1199
btsnd_hci_ble_add_device_to_periodic_advertiser_list(uint8_t adv_addr_type,const RawAddress & adv_addr,uint8_t adv_sid,base::OnceCallback<void (uint8_t *,uint16_t)> cb)1200 void btsnd_hci_ble_add_device_to_periodic_advertiser_list(
1201 uint8_t adv_addr_type, const RawAddress& adv_addr, uint8_t adv_sid,
1202 base::OnceCallback<void(uint8_t*, uint16_t)> cb) {
1203 uint8_t param[HCIC_PARAM_SIZE_ADD_DEVICE_TO_PERIODIC_ADVERTISER_LIST];
1204 uint8_t* pp = param;
1205
1206 UINT8_TO_STREAM(pp, adv_addr_type);
1207 BDADDR_TO_STREAM(pp, adv_addr);
1208 UINT8_TO_STREAM(pp, adv_sid);
1209
1210 btu_hcif_send_cmd_with_cb(
1211 FROM_HERE, HCI_BLE_ADD_DEVICE_TO_PERIODIC_ADVERTISER_LIST, param,
1212 HCIC_PARAM_SIZE_ADD_DEVICE_TO_PERIODIC_ADVERTISER_LIST, std::move(cb));
1213 }
1214
btsnd_hci_ble_remove_device_from_periodic_advertiser_list(uint8_t adv_addr_type,const RawAddress & adv_addr,uint8_t adv_sid,base::OnceCallback<void (uint8_t *,uint16_t)> cb)1215 void btsnd_hci_ble_remove_device_from_periodic_advertiser_list(
1216 uint8_t adv_addr_type, const RawAddress& adv_addr, uint8_t adv_sid,
1217 base::OnceCallback<void(uint8_t*, uint16_t)> cb) {
1218 uint8_t param[HCIC_PARAM_SIZE_REMOVE_DEVICE_FROM_PERIODIC_ADVERTISER_LIST];
1219 uint8_t* pp = param;
1220
1221 UINT8_TO_STREAM(pp, adv_addr_type);
1222 BDADDR_TO_STREAM(pp, adv_addr);
1223 UINT8_TO_STREAM(pp, adv_sid);
1224
1225 btu_hcif_send_cmd_with_cb(
1226 FROM_HERE, HCI_BLE_REMOVE_DEVICE_FROM_PERIODIC_ADVERTISER_LIST, param,
1227 HCIC_PARAM_SIZE_REMOVE_DEVICE_FROM_PERIODIC_ADVERTISER_LIST,
1228 std::move(cb));
1229 }
1230
btsnd_hci_ble_clear_periodic_advertiser_list(base::OnceCallback<void (uint8_t *,uint16_t)> cb)1231 void btsnd_hci_ble_clear_periodic_advertiser_list(
1232 base::OnceCallback<void(uint8_t*, uint16_t)> cb) {
1233 btu_hcif_send_cmd_with_cb(
1234 FROM_HERE, HCI_BLE_CLEAR_PERIODIC_ADVERTISER_LIST, nullptr,
1235 HCIC_PARAM_SIZE_CLEAR_PERIODIC_ADVERTISER_LIST, std::move(cb));
1236 }
1237
btsnd_hci_ble_read_periodic_advertiser_list_size(base::OnceCallback<void (uint8_t *,uint16_t)> cb)1238 void btsnd_hci_ble_read_periodic_advertiser_list_size(
1239 base::OnceCallback<void(uint8_t*, uint16_t)> cb) {
1240 btu_hcif_send_cmd_with_cb(
1241 FROM_HERE, HCI_BLE_READ_PERIODIC_ADVERTISER_LIST_SIZE, nullptr,
1242 HCIC_PARAM_SIZE_READ_PERIODIC_ADVERTISER_LIST_SIZE, std::move(cb));
1243 }
1244
btsnd_hcic_ble_set_periodic_advertising_receive_enable(uint16_t sync_handle,bool enable,base::OnceCallback<void (uint8_t *,uint16_t)> cb)1245 void btsnd_hcic_ble_set_periodic_advertising_receive_enable(
1246 uint16_t sync_handle, bool enable,
1247 base::OnceCallback<void(uint8_t*, uint16_t)> cb) {
1248 uint8_t param[HCIC_PARAM_SIZE_SET_PERIODIC_ADVERTISING_RECEIVE_ENABLE];
1249 uint8_t* pp = param;
1250
1251 UINT16_TO_STREAM(pp, sync_handle);
1252 UINT8_TO_STREAM(pp, (enable ? 0x01 : 0x00));
1253
1254 btu_hcif_send_cmd_with_cb(
1255 FROM_HERE, HCI_LE_SET_PERIODIC_ADVERTISING_RECEIVE_ENABLE, param,
1256 HCIC_PARAM_SIZE_SET_PERIODIC_ADVERTISING_RECEIVE_ENABLE, std::move(cb));
1257 }
1258
btsnd_hcic_ble_periodic_advertising_sync_transfer(uint16_t conn_handle,uint16_t service_data,uint16_t sync_handle,base::OnceCallback<void (uint8_t *,uint16_t)> cb)1259 void btsnd_hcic_ble_periodic_advertising_sync_transfer(
1260 uint16_t conn_handle, uint16_t service_data, uint16_t sync_handle,
1261 base::OnceCallback<void(uint8_t*, uint16_t)> cb) {
1262 uint8_t param[HCIC_PARAM_SIZE_PERIODIC_ADVERTISING_SYNC_TRANSFER];
1263 uint8_t* pp = param;
1264
1265 UINT16_TO_STREAM(pp, conn_handle);
1266 UINT16_TO_STREAM(pp, service_data);
1267 UINT16_TO_STREAM(pp, sync_handle);
1268
1269 btu_hcif_send_cmd_with_cb(
1270 FROM_HERE, HCI_LE_PERIODIC_ADVERTISING_SYNC_TRANSFER, param,
1271 HCIC_PARAM_SIZE_PERIODIC_ADVERTISING_SYNC_TRANSFER, std::move(cb));
1272 }
1273
btsnd_hcic_ble_periodic_advertising_set_info_transfer(uint16_t conn_handle,uint16_t service_data,uint8_t adv_handle,base::OnceCallback<void (uint8_t *,uint16_t)> cb)1274 void btsnd_hcic_ble_periodic_advertising_set_info_transfer(
1275 uint16_t conn_handle, uint16_t service_data, uint8_t adv_handle,
1276 base::OnceCallback<void(uint8_t*, uint16_t)> cb) {
1277 uint8_t param[HCIC_PARAM_SIZE_PERIODIC_ADVERTISING_SET_INFO_TRANSFER];
1278 uint8_t* pp = param;
1279
1280 UINT16_TO_STREAM(pp, conn_handle);
1281 UINT16_TO_STREAM(pp, service_data);
1282 UINT8_TO_STREAM(pp, adv_handle);
1283
1284 btu_hcif_send_cmd_with_cb(
1285 FROM_HERE, HCI_LE_PERIODIC_ADVERTISING_SET_INFO_TRANSFER, param,
1286 HCIC_PARAM_SIZE_PERIODIC_ADVERTISING_SET_INFO_TRANSFER, std::move(cb));
1287 }
1288
btsnd_hcic_ble_set_periodic_advertising_sync_transfer_params(uint16_t conn_handle,uint8_t mode,uint16_t skip,uint16_t sync_timeout,uint8_t cte_type,base::OnceCallback<void (uint8_t *,uint16_t)> cb)1289 void btsnd_hcic_ble_set_periodic_advertising_sync_transfer_params(
1290 uint16_t conn_handle, uint8_t mode, uint16_t skip, uint16_t sync_timeout,
1291 uint8_t cte_type, base::OnceCallback<void(uint8_t*, uint16_t)> cb) {
1292 uint8_t param[HCIC_PARAM_SIZE_SET_PERIODIC_ADVERTISING_SYNC_TRANSFER_PARAMS];
1293 uint8_t* pp = param;
1294
1295 UINT16_TO_STREAM(pp, conn_handle);
1296 UINT8_TO_STREAM(pp, mode);
1297 UINT16_TO_STREAM(pp, skip);
1298 UINT16_TO_STREAM(pp, sync_timeout);
1299 UINT8_TO_STREAM(pp, cte_type);
1300
1301 btu_hcif_send_cmd_with_cb(
1302 FROM_HERE, HCI_LE_SET_PERIODIC_ADVERTISING_SYNC_TRANSFER_PARAM, param,
1303 HCIC_PARAM_SIZE_SET_PERIODIC_ADVERTISING_SYNC_TRANSFER_PARAMS,
1304 std::move(cb));
1305 }
1306
btsnd_hcic_ble_set_default_periodic_advertising_sync_transfer_params(uint16_t conn_handle,uint8_t mode,uint16_t skip,uint16_t sync_timeout,uint8_t cte_type,base::OnceCallback<void (uint8_t *,uint16_t)> cb)1307 void btsnd_hcic_ble_set_default_periodic_advertising_sync_transfer_params(
1308 uint16_t conn_handle, uint8_t mode, uint16_t skip, uint16_t sync_timeout,
1309 uint8_t cte_type, base::OnceCallback<void(uint8_t*, uint16_t)> cb) {
1310 uint8_t param
1311 [HCIC_PARAM_SIZE_SET_DEFAULT_PERIODIC_ADVERTISING_SYNC_TRANSFER_PARAMS];
1312 uint8_t* pp = param;
1313
1314 UINT16_TO_STREAM(pp, conn_handle);
1315 UINT8_TO_STREAM(pp, mode);
1316 UINT16_TO_STREAM(pp, skip);
1317 UINT16_TO_STREAM(pp, sync_timeout);
1318 UINT8_TO_STREAM(pp, cte_type);
1319
1320 btu_hcif_send_cmd_with_cb(
1321 FROM_HERE, HCI_LE_SET_DEFAULT_PERIODIC_ADVERTISING_SYNC_TRANSFER_PARAM,
1322 param,
1323 HCIC_PARAM_SIZE_SET_DEFAULT_PERIODIC_ADVERTISING_SYNC_TRANSFER_PARAMS,
1324 std::move(cb));
1325 }
1326