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 <base/functional/bind.h>
27 #include <bluetooth/log.h>
28 #include <stddef.h>
29 #include <string.h>
30 
31 #include <bitset>
32 
33 #include "hcidefs.h"
34 #include "hcimsgs.h"
35 #include "internal_include/bt_target.h"
36 #include "osi/include/allocator.h"
37 #include "stack/include/bt_hdr.h"
38 #include "stack/include/bt_octets.h"
39 #include "stack/include/bt_types.h"
40 #include "stack/include/btu_hcif.h"
41 #include "types/raw_address.h"
42 
43 /*******************************************************************************
44  * BLE Commands
45  *      Note: "local_controller_id" is for transport, not counted in HCI
46  *             message size
47  ******************************************************************************/
48 #define HCIC_BLE_RAND_DI_SIZE 8
49 #define HCIC_BLE_IRK_SIZE 16
50 
51 #define HCIC_PARAM_SIZE_SET_USED_FEAT_CMD 8
52 #define HCIC_PARAM_SIZE_WRITE_RANDOM_ADDR_CMD 6
53 #define HCIC_PARAM_SIZE_BLE_WRITE_ADV_PARAMS 15
54 #define HCIC_PARAM_SIZE_BLE_WRITE_SCAN_RSP 31
55 #define HCIC_PARAM_SIZE_WRITE_ADV_ENABLE 1
56 #define HCIC_PARAM_SIZE_BLE_WRITE_SCAN_PARAM 7
57 #define HCIC_PARAM_SIZE_BLE_WRITE_SCAN_ENABLE 2
58 #define HCIC_PARAM_SIZE_BLE_CREATE_LL_CONN 25
59 #define HCIC_PARAM_SIZE_BLE_CREATE_CONN_CANCEL 0
60 #define HCIC_PARAM_SIZE_CLEAR_ACCEPTLIST 0
61 #define HCIC_PARAM_SIZE_ADD_ACCEPTLIST 7
62 #define HCIC_PARAM_SIZE_REMOVE_ACCEPTLIST 7
63 #define HCIC_PARAM_SIZE_BLE_UPD_LL_CONN_PARAMS 14
64 #define HCIC_PARAM_SIZE_SET_HOST_CHNL_CLASS 5
65 #define HCIC_PARAM_SIZE_READ_CHNL_MAP 2
66 #define HCIC_PARAM_SIZE_BLE_READ_REMOTE_FEAT 2
67 #define HCIC_PARAM_SIZE_BLE_ENCRYPT 32
68 #define HCIC_PARAM_SIZE_WRITE_LE_HOST_SUPPORTED 2
69 
70 #define HCIC_BLE_RAND_DI_SIZE 8
71 #define HCIC_BLE_ENCRYPT_KEY_SIZE 16
72 #define HCIC_PARAM_SIZE_BLE_START_ENC (4 + HCIC_BLE_RAND_DI_SIZE + HCIC_BLE_ENCRYPT_KEY_SIZE)
73 #define HCIC_PARAM_SIZE_LTK_REQ_REPLY (2 + HCIC_BLE_ENCRYPT_KEY_SIZE)
74 #define HCIC_PARAM_SIZE_LTK_REQ_NEG_REPLY 2
75 #define HCIC_BLE_CHNL_MAP_SIZE 5
76 #define HCIC_PARAM_SIZE_BLE_WRITE_ADV_DATA 31
77 
78 #define HCIC_PARAM_SIZE_BLE_ADD_DEV_RESOLVING_LIST (7 + HCIC_BLE_IRK_SIZE * 2)
79 #define HCIC_PARAM_SIZE_BLE_RM_DEV_RESOLVING_LIST 7
80 #define HCIC_PARAM_SIZE_BLE_SET_PRIVACY_MODE 8
81 #define HCIC_PARAM_SIZE_BLE_CLEAR_RESOLVING_LIST 0
82 #define HCIC_PARAM_SIZE_BLE_READ_RESOLVING_LIST_SIZE 0
83 #define HCIC_PARAM_SIZE_BLE_READ_RESOLVABLE_ADDR_PEER 7
84 #define HCIC_PARAM_SIZE_BLE_READ_RESOLVABLE_ADDR_LOCAL 7
85 #define HCIC_PARAM_SIZE_BLE_SET_ADDR_RESOLUTION_ENABLE 1
86 #define HCIC_PARAM_SIZE_BLE_SET_RAND_PRIV_ADDR_TIMEOUT 2
87 
88 #define HCIC_PARAM_SIZE_BLE_READ_PHY 2
89 #define HCIC_PARAM_SIZE_BLE_SET_DEFAULT_PHY 3
90 #define HCIC_PARAM_SIZE_BLE_SET_PHY 7
91 #define HCIC_PARAM_SIZE_BLE_ENH_RX_TEST 3
92 #define HCIC_PARAM_SIZE_BLE_ENH_TX_TEST 4
93 
94 #define HCIC_PARAM_SIZE_BLE_SET_DATA_LENGTH 6
95 #define HCIC_PARAM_SIZE_BLE_WRITE_EXTENDED_SCAN_PARAM 11
96 
97 #define HCIC_PARAM_SIZE_BLE_RC_PARAM_REQ_REPLY 14
98 #define HCIC_PARAM_SIZE_BLE_RC_PARAM_REQ_NEG_REPLY 3
99 
100 #define HCIC_PARAM_SIZE_PERIODIC_ADVERTISING_CREATE_SYNC 14
101 #define HCIC_PARAM_SIZE_PERIODIC_ADVERTISING_CREATE_SYNC_CANCEL 0
102 #define HCIC_PARAM_SIZE_PERIODIC_ADVERTISING_TERMINATE_SYNC 2
103 #define HCIC_PARAM_SIZE_ADD_DEVICE_TO_PERIODIC_ADVERTISER_LIST 8
104 #define HCIC_PARAM_SIZE_REMOVE_DEVICE_FROM_PERIODIC_ADVERTISER_LIST 8
105 #define HCIC_PARAM_SIZE_CLEAR_PERIODIC_ADVERTISER_LIST 0
106 #define HCIC_PARAM_SIZE_READ_PERIODIC_ADVERTISER_LIST_SIZE 0
107 #define HCIC_PARAM_SIZE_SET_PERIODIC_ADVERTISING_RECEIVE_ENABLE 3
108 #define HCIC_PARAM_SIZE_PERIODIC_ADVERTISING_SYNC_TRANSFER 6
109 #define HCIC_PARAM_SIZE_PERIODIC_ADVERTISING_SET_INFO_TRANSFER 5
110 #define HCIC_PARAM_SIZE_SET_PERIODIC_ADVERTISING_SYNC_TRANSFER_PARAMS 8
111 #define HCIC_PARAM_SIZE_SET_DEFAULT_PERIODIC_ADVERTISING_SYNC_TRANSFER_PARAMS 8
112 
btsnd_hcic_ble_write_adv_params(uint16_t adv_int_min,uint16_t adv_int_max,uint8_t adv_type,tBLE_ADDR_TYPE addr_type_own,tBLE_ADDR_TYPE addr_type_dir,const RawAddress & direct_bda,uint8_t channel_map,uint8_t adv_filter_policy)113 void btsnd_hcic_ble_write_adv_params(uint16_t adv_int_min, uint16_t adv_int_max, uint8_t adv_type,
114                                      tBLE_ADDR_TYPE addr_type_own, tBLE_ADDR_TYPE addr_type_dir,
115                                      const RawAddress& direct_bda, uint8_t channel_map,
116                                      uint8_t adv_filter_policy) {
117   BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
118   uint8_t* pp = (uint8_t*)(p + 1);
119 
120   p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_WRITE_ADV_PARAMS;
121   p->offset = 0;
122 
123   UINT16_TO_STREAM(pp, HCI_BLE_WRITE_ADV_PARAMS);
124   UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_BLE_WRITE_ADV_PARAMS);
125 
126   UINT16_TO_STREAM(pp, adv_int_min);
127   UINT16_TO_STREAM(pp, adv_int_max);
128   UINT8_TO_STREAM(pp, adv_type);
129   UINT8_TO_STREAM(pp, addr_type_own);
130   UINT8_TO_STREAM(pp, addr_type_dir);
131   BDADDR_TO_STREAM(pp, direct_bda);
132   UINT8_TO_STREAM(pp, channel_map);
133   UINT8_TO_STREAM(pp, adv_filter_policy);
134 
135   btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
136 }
btsnd_hcic_ble_read_adv_chnl_tx_power(void)137 void btsnd_hcic_ble_read_adv_chnl_tx_power(void) {
138   BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
139   uint8_t* pp = (uint8_t*)(p + 1);
140 
141   p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_READ_CMD;
142   p->offset = 0;
143 
144   UINT16_TO_STREAM(pp, HCI_BLE_READ_ADV_CHNL_TX_POWER);
145   UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_READ_CMD);
146 
147   btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
148 }
149 
btsnd_hcic_ble_set_adv_data(uint8_t data_len,uint8_t * p_data)150 void btsnd_hcic_ble_set_adv_data(uint8_t data_len, uint8_t* p_data) {
151   BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
152   uint8_t* pp = (uint8_t*)(p + 1);
153 
154   p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_WRITE_ADV_DATA + 1;
155   p->offset = 0;
156 
157   UINT16_TO_STREAM(pp, HCI_BLE_WRITE_ADV_DATA);
158   UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_BLE_WRITE_ADV_DATA + 1);
159 
160   memset(pp, 0, HCIC_PARAM_SIZE_BLE_WRITE_ADV_DATA);
161 
162   if (p_data != NULL && data_len > 0) {
163     if (data_len > HCIC_PARAM_SIZE_BLE_WRITE_ADV_DATA) {
164       data_len = HCIC_PARAM_SIZE_BLE_WRITE_ADV_DATA;
165     }
166 
167     UINT8_TO_STREAM(pp, data_len);
168 
169     ARRAY_TO_STREAM(pp, p_data, data_len);
170   }
171   btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
172 }
173 
btsnd_hcic_ble_set_adv_enable(uint8_t adv_enable)174 void btsnd_hcic_ble_set_adv_enable(uint8_t adv_enable) {
175   BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
176   uint8_t* pp = (uint8_t*)(p + 1);
177 
178   p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_WRITE_ADV_ENABLE;
179   p->offset = 0;
180 
181   UINT16_TO_STREAM(pp, HCI_BLE_WRITE_ADV_ENABLE);
182   UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_WRITE_ADV_ENABLE);
183 
184   UINT8_TO_STREAM(pp, adv_enable);
185 
186   btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
187 }
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)188 void btsnd_hcic_ble_set_scan_params(uint8_t scan_type, uint16_t scan_int, uint16_t scan_win,
189                                     uint8_t addr_type_own, uint8_t scan_filter_policy) {
190   BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
191   uint8_t* pp = (uint8_t*)(p + 1);
192 
193   p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_WRITE_SCAN_PARAM;
194   p->offset = 0;
195 
196   UINT16_TO_STREAM(pp, HCI_BLE_WRITE_SCAN_PARAMS);
197   UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_BLE_WRITE_SCAN_PARAM);
198 
199   UINT8_TO_STREAM(pp, scan_type);
200   UINT16_TO_STREAM(pp, scan_int);
201   UINT16_TO_STREAM(pp, scan_win);
202   UINT8_TO_STREAM(pp, addr_type_own);
203   UINT8_TO_STREAM(pp, scan_filter_policy);
204 
205   btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
206 }
207 
btsnd_hcic_ble_set_scan_enable(uint8_t scan_enable,uint8_t duplicate)208 void btsnd_hcic_ble_set_scan_enable(uint8_t scan_enable, uint8_t duplicate) {
209   BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
210   uint8_t* pp = (uint8_t*)(p + 1);
211 
212   p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_WRITE_SCAN_ENABLE;
213   p->offset = 0;
214 
215   UINT16_TO_STREAM(pp, HCI_BLE_WRITE_SCAN_ENABLE);
216   UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_BLE_WRITE_SCAN_ENABLE);
217 
218   UINT8_TO_STREAM(pp, scan_enable);
219   UINT8_TO_STREAM(pp, duplicate);
220 
221   btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
222 }
223 
btsnd_hcic_ble_read_remote_feat(uint16_t handle)224 void btsnd_hcic_ble_read_remote_feat(uint16_t handle) {
225   BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
226   uint8_t* pp = (uint8_t*)(p + 1);
227 
228   p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_READ_REMOTE_FEAT;
229   p->offset = 0;
230 
231   UINT16_TO_STREAM(pp, HCI_BLE_READ_REMOTE_FEAT);
232   UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_BLE_READ_REMOTE_FEAT);
233 
234   UINT16_TO_STREAM(pp, handle);
235 
236   btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
237 }
238 
btsnd_hcic_ble_rand(base::Callback<void (BT_OCTET8)> cb)239 void btsnd_hcic_ble_rand(base::Callback<void(BT_OCTET8)> cb) {
240   btu_hcif_send_cmd_with_cb(
241           FROM_HERE, HCI_BLE_RAND, nullptr, 0,
242           base::Bind(
243                   [](base::Callback<void(BT_OCTET8)> cb, uint8_t* param, uint16_t /* param_len */) {
244                     bluetooth::log::assert_that(param[0] == 0,
245                                                 "LE Rand return status must be zero");
246                     cb.Run(param + 1 /* skip status */);
247                   },
248                   std::move(cb)));
249 }
250 
btsnd_hcic_ble_start_enc(uint16_t handle,uint8_t rand[HCIC_BLE_RAND_DI_SIZE],uint16_t ediv,const Octet16 & ltk)251 void btsnd_hcic_ble_start_enc(uint16_t handle, uint8_t rand[HCIC_BLE_RAND_DI_SIZE], uint16_t ediv,
252                               const Octet16& ltk) {
253   BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
254   uint8_t* pp = (uint8_t*)(p + 1);
255 
256   p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_START_ENC;
257   p->offset = 0;
258 
259   UINT16_TO_STREAM(pp, HCI_BLE_START_ENC);
260   UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_BLE_START_ENC);
261 
262   UINT16_TO_STREAM(pp, handle);
263   ARRAY_TO_STREAM(pp, rand, HCIC_BLE_RAND_DI_SIZE);
264   UINT16_TO_STREAM(pp, ediv);
265   ARRAY_TO_STREAM(pp, ltk.data(), HCIC_BLE_ENCRYPT_KEY_SIZE);
266 
267   btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
268 }
269 
btsnd_hcic_ble_ltk_req_reply(uint16_t handle,const Octet16 & ltk)270 void btsnd_hcic_ble_ltk_req_reply(uint16_t handle, const Octet16& ltk) {
271   BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
272   uint8_t* pp = (uint8_t*)(p + 1);
273 
274   p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_LTK_REQ_REPLY;
275   p->offset = 0;
276 
277   UINT16_TO_STREAM(pp, HCI_BLE_LTK_REQ_REPLY);
278   UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_LTK_REQ_REPLY);
279 
280   UINT16_TO_STREAM(pp, handle);
281   ARRAY_TO_STREAM(pp, ltk.data(), HCIC_BLE_ENCRYPT_KEY_SIZE);
282 
283   btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
284 }
285 
btsnd_hcic_ble_ltk_req_neg_reply(uint16_t handle)286 void btsnd_hcic_ble_ltk_req_neg_reply(uint16_t handle) {
287   BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
288   uint8_t* pp = (uint8_t*)(p + 1);
289 
290   p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_LTK_REQ_NEG_REPLY;
291   p->offset = 0;
292 
293   UINT16_TO_STREAM(pp, HCI_BLE_LTK_REQ_NEG_REPLY);
294   UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_LTK_REQ_NEG_REPLY);
295 
296   UINT16_TO_STREAM(pp, handle);
297 
298   btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
299 }
300 
btsnd_hcic_ble_receiver_test(uint8_t rx_freq)301 void btsnd_hcic_ble_receiver_test(uint8_t rx_freq) {
302   BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
303   uint8_t* pp = (uint8_t*)(p + 1);
304 
305   p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_WRITE_PARAM1;
306   p->offset = 0;
307 
308   UINT16_TO_STREAM(pp, HCI_BLE_RECEIVER_TEST);
309   UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_WRITE_PARAM1);
310 
311   UINT8_TO_STREAM(pp, rx_freq);
312 
313   btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
314 }
315 
btsnd_hcic_ble_transmitter_test(uint8_t tx_freq,uint8_t test_data_len,uint8_t payload)316 void btsnd_hcic_ble_transmitter_test(uint8_t tx_freq, uint8_t test_data_len, uint8_t payload) {
317   BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
318   uint8_t* pp = (uint8_t*)(p + 1);
319 
320   p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_WRITE_PARAM3;
321   p->offset = 0;
322 
323   UINT16_TO_STREAM(pp, HCI_BLE_TRANSMITTER_TEST);
324   UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_WRITE_PARAM3);
325 
326   UINT8_TO_STREAM(pp, tx_freq);
327   UINT8_TO_STREAM(pp, test_data_len);
328   UINT8_TO_STREAM(pp, payload);
329 
330   btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
331 }
332 
btsnd_hcic_ble_test_end(void)333 void btsnd_hcic_ble_test_end(void) {
334   BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
335   uint8_t* pp = (uint8_t*)(p + 1);
336 
337   p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_READ_CMD;
338   p->offset = 0;
339 
340   UINT16_TO_STREAM(pp, HCI_BLE_TEST_END);
341   UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_READ_CMD);
342 
343   btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
344 }
345 
btsnd_hcic_ble_read_resolvable_addr_peer(uint8_t addr_type_peer,const RawAddress & bda_peer)346 void btsnd_hcic_ble_read_resolvable_addr_peer(uint8_t addr_type_peer, const RawAddress& bda_peer) {
347   BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
348   uint8_t* pp = (uint8_t*)(p + 1);
349 
350   p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_READ_RESOLVABLE_ADDR_PEER;
351   p->offset = 0;
352 
353   UINT16_TO_STREAM(pp, HCI_BLE_READ_RESOLVABLE_ADDR_PEER);
354   UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_BLE_READ_RESOLVABLE_ADDR_PEER);
355   UINT8_TO_STREAM(pp, addr_type_peer);
356   BDADDR_TO_STREAM(pp, bda_peer);
357 
358   btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
359 }
360 
btsnd_hcic_ble_set_rand_priv_addr_timeout(uint16_t rpa_timeout)361 void btsnd_hcic_ble_set_rand_priv_addr_timeout(uint16_t rpa_timeout) {
362   BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
363   uint8_t* pp = (uint8_t*)(p + 1);
364 
365   p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_SET_RAND_PRIV_ADDR_TIMEOUT;
366   p->offset = 0;
367 
368   UINT16_TO_STREAM(pp, HCI_BLE_SET_RAND_PRIV_ADDR_TIMEOUT);
369   UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_BLE_SET_RAND_PRIV_ADDR_TIMEOUT);
370   UINT16_TO_STREAM(pp, rpa_timeout);
371 
372   btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
373 }
374 
btsnd_hcic_ble_set_data_length(uint16_t conn_handle,uint16_t tx_octets,uint16_t tx_time)375 void btsnd_hcic_ble_set_data_length(uint16_t conn_handle, uint16_t tx_octets, uint16_t tx_time) {
376   BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
377   uint8_t* pp = (uint8_t*)(p + 1);
378 
379   p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_SET_DATA_LENGTH;
380   p->offset = 0;
381 
382   UINT16_TO_STREAM(pp, HCI_BLE_SET_DATA_LENGTH);
383   UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_BLE_SET_DATA_LENGTH);
384 
385   UINT16_TO_STREAM(pp, conn_handle);
386   UINT16_TO_STREAM(pp, tx_octets);
387   UINT16_TO_STREAM(pp, tx_time);
388 
389   btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
390 }
391 
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)392 void btsnd_hcic_ble_set_extended_scan_params(uint8_t own_address_type,
393                                              uint8_t scanning_filter_policy, uint8_t scanning_phys,
394                                              scanning_phy_cfg* phy_cfg) {
395   BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
396   uint8_t* pp = (uint8_t*)(p + 1);
397 
398   int phy_cnt = std::bitset<std::numeric_limits<uint8_t>::digits>(scanning_phys).count();
399 
400   uint16_t param_len = 3 + (5 * phy_cnt);
401   p->len = HCIC_PREAMBLE_SIZE + param_len;
402   p->offset = 0;
403 
404   UINT16_TO_STREAM(pp, HCI_LE_SET_EXTENDED_SCAN_PARAMETERS);
405   UINT8_TO_STREAM(pp, param_len);
406 
407   UINT8_TO_STREAM(pp, own_address_type);
408   UINT8_TO_STREAM(pp, scanning_filter_policy);
409   UINT8_TO_STREAM(pp, scanning_phys);
410 
411   for (int i = 0; i < phy_cnt; i++) {
412     UINT8_TO_STREAM(pp, phy_cfg[i].scan_type);
413     UINT16_TO_STREAM(pp, phy_cfg[i].scan_int);
414     UINT16_TO_STREAM(pp, phy_cfg[i].scan_win);
415   }
416 
417   btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
418 }
419 
btsnd_hcic_ble_set_extended_scan_enable(uint8_t enable,uint8_t filter_duplicates,uint16_t duration,uint16_t period)420 void btsnd_hcic_ble_set_extended_scan_enable(uint8_t enable, uint8_t filter_duplicates,
421                                              uint16_t duration, uint16_t period) {
422   BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
423   uint8_t* pp = (uint8_t*)(p + 1);
424 
425   const int param_len = 6;
426   p->len = HCIC_PREAMBLE_SIZE + param_len;
427   p->offset = 0;
428 
429   UINT16_TO_STREAM(pp, HCI_LE_SET_EXTENDED_SCAN_ENABLE);
430   UINT8_TO_STREAM(pp, param_len);
431 
432   UINT8_TO_STREAM(pp, enable);
433   UINT8_TO_STREAM(pp, filter_duplicates);
434   UINT16_TO_STREAM(pp, duration);
435   UINT16_TO_STREAM(pp, period);
436 
437   btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
438 }
439 
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)440 void btsnd_hcic_set_cig_params(uint8_t cig_id, uint32_t sdu_itv_mtos, uint32_t sdu_itv_stom,
441                                uint8_t sca, uint8_t packing, uint8_t framing,
442                                uint16_t max_trans_lat_stom, uint16_t max_trans_lat_mtos,
443                                uint8_t cis_cnt, const EXT_CIS_CFG* cis_cfg,
444                                base::OnceCallback<void(uint8_t*, uint16_t)> cb) {
445   const int params_len = 15 + cis_cnt * 9;
446   uint8_t param[params_len];
447   uint8_t* pp = param;
448 
449   UINT8_TO_STREAM(pp, cig_id);
450   UINT24_TO_STREAM(pp, sdu_itv_mtos);
451   UINT24_TO_STREAM(pp, sdu_itv_stom);
452   UINT8_TO_STREAM(pp, sca);
453   UINT8_TO_STREAM(pp, packing);
454   UINT8_TO_STREAM(pp, framing);
455   UINT16_TO_STREAM(pp, max_trans_lat_mtos);
456   UINT16_TO_STREAM(pp, max_trans_lat_stom);
457   UINT8_TO_STREAM(pp, cis_cnt);
458 
459   for (int i = 0; i < cis_cnt; i++) {
460     UINT8_TO_STREAM(pp, cis_cfg[i].cis_id);
461     UINT16_TO_STREAM(pp, cis_cfg[i].max_sdu_size_mtos);
462     UINT16_TO_STREAM(pp, cis_cfg[i].max_sdu_size_stom);
463     UINT8_TO_STREAM(pp, cis_cfg[i].phy_mtos);
464     UINT8_TO_STREAM(pp, cis_cfg[i].phy_stom);
465     UINT8_TO_STREAM(pp, cis_cfg[i].rtn_mtos);
466     UINT8_TO_STREAM(pp, cis_cfg[i].rtn_stom);
467   }
468 
469   btu_hcif_send_cmd_with_cb(FROM_HERE, HCI_LE_SET_CIG_PARAMS, param, params_len, std::move(cb));
470 }
471 
btsnd_hcic_create_cis(uint8_t num_cis,const EXT_CIS_CREATE_CFG * cis_cfg,base::OnceCallback<void (uint8_t *,uint16_t)> cb)472 void btsnd_hcic_create_cis(uint8_t num_cis, const EXT_CIS_CREATE_CFG* cis_cfg,
473                            base::OnceCallback<void(uint8_t*, uint16_t)> cb) {
474   const int params_len = 1 + num_cis * 4;
475   uint8_t param[params_len];
476   uint8_t* pp = param;
477 
478   UINT8_TO_STREAM(pp, num_cis);
479 
480   for (int i = 0; i < num_cis; i++) {
481     UINT16_TO_STREAM(pp, cis_cfg[i].cis_conn_handle);
482     UINT16_TO_STREAM(pp, cis_cfg[i].acl_conn_handle);
483   }
484 
485   btu_hcif_send_cmd_with_cb(FROM_HERE, HCI_LE_CREATE_CIS, param, params_len, std::move(cb));
486 }
487 
btsnd_hcic_remove_cig(uint8_t cig_id,base::OnceCallback<void (uint8_t *,uint16_t)> cb)488 void btsnd_hcic_remove_cig(uint8_t cig_id, base::OnceCallback<void(uint8_t*, uint16_t)> cb) {
489   const int params_len = 1;
490   uint8_t param[params_len];
491   uint8_t* pp = param;
492 
493   UINT8_TO_STREAM(pp, cig_id);
494 
495   btu_hcif_send_cmd_with_cb(FROM_HERE, HCI_LE_REMOVE_CIG, param, params_len, std::move(cb));
496 }
497 
btsnd_hcic_req_peer_sca(uint16_t conn_handle)498 void btsnd_hcic_req_peer_sca(uint16_t conn_handle) {
499   BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
500   uint8_t* pp = (uint8_t*)(p + 1);
501 
502   const int param_len = 2;
503   p->len = HCIC_PREAMBLE_SIZE + param_len;
504   p->offset = 0;
505 
506   UINT16_TO_STREAM(pp, HCI_LE_REQ_PEER_SCA);
507   UINT8_TO_STREAM(pp, param_len);
508   UINT16_TO_STREAM(pp, conn_handle);
509 
510   btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
511 }
512 
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)513 void btsnd_hcic_create_big(uint8_t big_handle, uint8_t adv_handle, uint8_t num_bis,
514                            uint32_t sdu_itv, uint16_t max_sdu_size, uint16_t transport_latency,
515                            uint8_t rtn, uint8_t phy, uint8_t packing, uint8_t framing, uint8_t enc,
516                            std::array<uint8_t, 16> bcst_code) {
517   BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
518   uint8_t* pp = (uint8_t*)(p + 1);
519 
520   const int param_len = 31;
521   p->len = HCIC_PREAMBLE_SIZE + param_len;
522   p->offset = 0;
523 
524   UINT16_TO_STREAM(pp, HCI_LE_CREATE_BIG);
525   UINT8_TO_STREAM(pp, param_len);
526 
527   UINT8_TO_STREAM(pp, big_handle);
528   UINT8_TO_STREAM(pp, adv_handle);
529   UINT8_TO_STREAM(pp, num_bis);
530   UINT24_TO_STREAM(pp, sdu_itv);
531   UINT16_TO_STREAM(pp, max_sdu_size);
532   UINT16_TO_STREAM(pp, transport_latency);
533   UINT8_TO_STREAM(pp, rtn);
534   UINT8_TO_STREAM(pp, phy);
535   UINT8_TO_STREAM(pp, packing);
536   UINT8_TO_STREAM(pp, framing);
537   UINT8_TO_STREAM(pp, enc);
538 
539   uint8_t* buf_ptr = bcst_code.data();
540   ARRAY_TO_STREAM(pp, buf_ptr, 16);
541 
542   btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
543 }
544 
btsnd_hcic_term_big(uint8_t big_handle,uint8_t reason)545 void btsnd_hcic_term_big(uint8_t big_handle, uint8_t reason) {
546   BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
547   uint8_t* pp = (uint8_t*)(p + 1);
548 
549   const int param_len = 2;
550   p->len = HCIC_PREAMBLE_SIZE + param_len;
551   p->offset = 0;
552 
553   UINT16_TO_STREAM(pp, HCI_LE_TERM_BIG);
554   UINT8_TO_STREAM(pp, param_len);
555 
556   UINT8_TO_STREAM(pp, big_handle);
557   UINT8_TO_STREAM(pp, reason);
558 
559   btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
560 }
561 
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)562 void btsnd_hcic_setup_iso_data_path(uint16_t iso_handle, uint8_t data_path_dir,
563                                     uint8_t data_path_id, uint8_t codec_id_format,
564                                     uint16_t codec_id_company, uint16_t codec_id_vendor,
565                                     uint32_t controller_delay, std::vector<uint8_t> codec_conf,
566                                     base::OnceCallback<void(uint8_t*, uint16_t)> cb) {
567   const int params_len = 13 + codec_conf.size();
568   uint8_t param[params_len];
569   uint8_t* pp = param;
570 
571   UINT16_TO_STREAM(pp, iso_handle);
572   UINT8_TO_STREAM(pp, data_path_dir);
573   UINT8_TO_STREAM(pp, data_path_id);
574   UINT8_TO_STREAM(pp, codec_id_format);
575   UINT16_TO_STREAM(pp, codec_id_company);
576   UINT16_TO_STREAM(pp, codec_id_vendor);
577   UINT24_TO_STREAM(pp, controller_delay);
578   UINT8_TO_STREAM(pp, codec_conf.size());
579   ARRAY_TO_STREAM(pp, codec_conf.data(), static_cast<int>(codec_conf.size()));
580 
581   btu_hcif_send_cmd_with_cb(FROM_HERE, HCI_LE_SETUP_ISO_DATA_PATH, param, params_len,
582                             std::move(cb));
583 }
584 
btsnd_hcic_remove_iso_data_path(uint16_t iso_handle,uint8_t data_path_dir,base::OnceCallback<void (uint8_t *,uint16_t)> cb)585 void btsnd_hcic_remove_iso_data_path(uint16_t iso_handle, uint8_t data_path_dir,
586                                      base::OnceCallback<void(uint8_t*, uint16_t)> cb) {
587   const int params_len = 3;
588   uint8_t param[params_len];
589   uint8_t* pp = param;
590 
591   UINT16_TO_STREAM(pp, iso_handle);
592   UINT8_TO_STREAM(pp, data_path_dir);
593 
594   btu_hcif_send_cmd_with_cb(FROM_HERE, HCI_LE_REMOVE_ISO_DATA_PATH, param, params_len,
595                             std::move(cb));
596 }
597 
btsnd_hcic_read_iso_link_quality(uint16_t iso_handle,base::OnceCallback<void (uint8_t *,uint16_t)> cb)598 void btsnd_hcic_read_iso_link_quality(uint16_t iso_handle,
599                                       base::OnceCallback<void(uint8_t*, uint16_t)> cb) {
600   const int params_len = 2;
601   uint8_t param[params_len];
602   uint8_t* pp = param;
603 
604   UINT16_TO_STREAM(pp, iso_handle);
605 
606   btu_hcif_send_cmd_with_cb(FROM_HERE, HCI_LE_READ_ISO_LINK_QUALITY, param, params_len,
607                             std::move(cb));
608 }
609 
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)610 void btsnd_hcic_ble_periodic_advertising_create_sync(uint8_t options, uint8_t adv_sid,
611                                                      uint8_t adv_addr_type,
612                                                      const RawAddress& adv_addr, uint16_t skip_num,
613                                                      uint16_t sync_timeout, uint8_t sync_cte_type) {
614   BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
615   uint8_t* pp = (uint8_t*)(p + 1);
616 
617   p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_PERIODIC_ADVERTISING_CREATE_SYNC;
618   p->offset = 0;
619 
620   UINT16_TO_STREAM(pp, HCI_BLE_PERIODIC_ADVERTISING_CREATE_SYNC);
621   UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_PERIODIC_ADVERTISING_CREATE_SYNC);
622   UINT8_TO_STREAM(pp, options);
623   UINT8_TO_STREAM(pp, adv_sid);
624   UINT8_TO_STREAM(pp, adv_addr_type);
625   BDADDR_TO_STREAM(pp, adv_addr);
626   UINT16_TO_STREAM(pp, skip_num);
627   UINT16_TO_STREAM(pp, sync_timeout);
628   UINT8_TO_STREAM(pp, sync_cte_type);
629 
630   btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
631 }
632 
btsnd_hcic_ble_periodic_advertising_create_sync_cancel(base::OnceCallback<void (uint8_t *,uint16_t)> cb)633 void btsnd_hcic_ble_periodic_advertising_create_sync_cancel(
634         base::OnceCallback<void(uint8_t*, uint16_t)> cb) {
635   btu_hcif_send_cmd_with_cb(FROM_HERE, HCI_BLE_PERIODIC_ADVERTISING_CREATE_SYNC_CANCEL, nullptr,
636                             HCIC_PARAM_SIZE_PERIODIC_ADVERTISING_CREATE_SYNC_CANCEL, std::move(cb));
637 }
638 
btsnd_hcic_ble_periodic_advertising_terminate_sync(uint16_t sync_handle,base::OnceCallback<void (uint8_t *,uint16_t)> cb)639 void btsnd_hcic_ble_periodic_advertising_terminate_sync(
640         uint16_t sync_handle, base::OnceCallback<void(uint8_t*, uint16_t)> cb) {
641   uint8_t param[HCIC_PARAM_SIZE_PERIODIC_ADVERTISING_TERMINATE_SYNC];
642   uint8_t* pp = param;
643 
644   UINT16_TO_STREAM(pp, sync_handle);
645 
646   btu_hcif_send_cmd_with_cb(FROM_HERE, HCI_BLE_PERIODIC_ADVERTISING_TERMINATE_SYNC, param,
647                             HCIC_PARAM_SIZE_PERIODIC_ADVERTISING_TERMINATE_SYNC, std::move(cb));
648 }
649 
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)650 void btsnd_hci_ble_add_device_to_periodic_advertiser_list(
651         uint8_t adv_addr_type, const RawAddress& adv_addr, uint8_t adv_sid,
652         base::OnceCallback<void(uint8_t*, uint16_t)> cb) {
653   uint8_t param[HCIC_PARAM_SIZE_ADD_DEVICE_TO_PERIODIC_ADVERTISER_LIST];
654   uint8_t* pp = param;
655 
656   UINT8_TO_STREAM(pp, adv_addr_type);
657   BDADDR_TO_STREAM(pp, adv_addr);
658   UINT8_TO_STREAM(pp, adv_sid);
659 
660   btu_hcif_send_cmd_with_cb(FROM_HERE, HCI_BLE_ADD_DEVICE_TO_PERIODIC_ADVERTISER_LIST, param,
661                             HCIC_PARAM_SIZE_ADD_DEVICE_TO_PERIODIC_ADVERTISER_LIST, std::move(cb));
662 }
663 
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)664 void btsnd_hci_ble_remove_device_from_periodic_advertiser_list(
665         uint8_t adv_addr_type, const RawAddress& adv_addr, uint8_t adv_sid,
666         base::OnceCallback<void(uint8_t*, uint16_t)> cb) {
667   uint8_t param[HCIC_PARAM_SIZE_REMOVE_DEVICE_FROM_PERIODIC_ADVERTISER_LIST];
668   uint8_t* pp = param;
669 
670   UINT8_TO_STREAM(pp, adv_addr_type);
671   BDADDR_TO_STREAM(pp, adv_addr);
672   UINT8_TO_STREAM(pp, adv_sid);
673 
674   btu_hcif_send_cmd_with_cb(FROM_HERE, HCI_BLE_REMOVE_DEVICE_FROM_PERIODIC_ADVERTISER_LIST, param,
675                             HCIC_PARAM_SIZE_REMOVE_DEVICE_FROM_PERIODIC_ADVERTISER_LIST,
676                             std::move(cb));
677 }
678 
btsnd_hci_ble_clear_periodic_advertiser_list(base::OnceCallback<void (uint8_t *,uint16_t)> cb)679 void btsnd_hci_ble_clear_periodic_advertiser_list(base::OnceCallback<void(uint8_t*, uint16_t)> cb) {
680   btu_hcif_send_cmd_with_cb(FROM_HERE, HCI_BLE_CLEAR_PERIODIC_ADVERTISER_LIST, nullptr,
681                             HCIC_PARAM_SIZE_CLEAR_PERIODIC_ADVERTISER_LIST, std::move(cb));
682 }
683 
btsnd_hcic_ble_set_periodic_advertising_receive_enable(uint16_t sync_handle,bool enable,base::OnceCallback<void (uint8_t *,uint16_t)> cb)684 void btsnd_hcic_ble_set_periodic_advertising_receive_enable(
685         uint16_t sync_handle, bool enable, base::OnceCallback<void(uint8_t*, uint16_t)> cb) {
686   uint8_t param[HCIC_PARAM_SIZE_SET_PERIODIC_ADVERTISING_RECEIVE_ENABLE];
687   uint8_t* pp = param;
688 
689   UINT16_TO_STREAM(pp, sync_handle);
690   UINT8_TO_STREAM(pp, (enable ? 0x01 : 0x00));
691 
692   btu_hcif_send_cmd_with_cb(FROM_HERE, HCI_LE_SET_PERIODIC_ADVERTISING_RECEIVE_ENABLE, param,
693                             HCIC_PARAM_SIZE_SET_PERIODIC_ADVERTISING_RECEIVE_ENABLE, std::move(cb));
694 }
695 
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)696 void btsnd_hcic_ble_periodic_advertising_sync_transfer(
697         uint16_t conn_handle, uint16_t service_data, uint16_t sync_handle,
698         base::OnceCallback<void(uint8_t*, uint16_t)> cb) {
699   uint8_t param[HCIC_PARAM_SIZE_PERIODIC_ADVERTISING_SYNC_TRANSFER];
700   uint8_t* pp = param;
701 
702   UINT16_TO_STREAM(pp, conn_handle);
703   UINT16_TO_STREAM(pp, service_data);
704   UINT16_TO_STREAM(pp, sync_handle);
705 
706   btu_hcif_send_cmd_with_cb(FROM_HERE, HCI_LE_PERIODIC_ADVERTISING_SYNC_TRANSFER, param,
707                             HCIC_PARAM_SIZE_PERIODIC_ADVERTISING_SYNC_TRANSFER, std::move(cb));
708 }
709 
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)710 void btsnd_hcic_ble_periodic_advertising_set_info_transfer(
711         uint16_t conn_handle, uint16_t service_data, uint8_t adv_handle,
712         base::OnceCallback<void(uint8_t*, uint16_t)> cb) {
713   uint8_t param[HCIC_PARAM_SIZE_PERIODIC_ADVERTISING_SET_INFO_TRANSFER];
714   uint8_t* pp = param;
715 
716   UINT16_TO_STREAM(pp, conn_handle);
717   UINT16_TO_STREAM(pp, service_data);
718   UINT8_TO_STREAM(pp, adv_handle);
719 
720   btu_hcif_send_cmd_with_cb(FROM_HERE, HCI_LE_PERIODIC_ADVERTISING_SET_INFO_TRANSFER, param,
721                             HCIC_PARAM_SIZE_PERIODIC_ADVERTISING_SET_INFO_TRANSFER, std::move(cb));
722 }
723 
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)724 void btsnd_hcic_ble_set_periodic_advertising_sync_transfer_params(
725         uint16_t conn_handle, uint8_t mode, uint16_t skip, uint16_t sync_timeout, uint8_t cte_type,
726         base::OnceCallback<void(uint8_t*, uint16_t)> cb) {
727   uint8_t param[HCIC_PARAM_SIZE_SET_PERIODIC_ADVERTISING_SYNC_TRANSFER_PARAMS];
728   uint8_t* pp = param;
729 
730   UINT16_TO_STREAM(pp, conn_handle);
731   UINT8_TO_STREAM(pp, mode);
732   UINT16_TO_STREAM(pp, skip);
733   UINT16_TO_STREAM(pp, sync_timeout);
734   UINT8_TO_STREAM(pp, cte_type);
735 
736   btu_hcif_send_cmd_with_cb(FROM_HERE, HCI_LE_SET_PERIODIC_ADVERTISING_SYNC_TRANSFER_PARAM, param,
737                             HCIC_PARAM_SIZE_SET_PERIODIC_ADVERTISING_SYNC_TRANSFER_PARAMS,
738                             std::move(cb));
739 }
740 
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)741 void btsnd_hcic_ble_set_default_periodic_advertising_sync_transfer_params(
742         uint16_t conn_handle, uint8_t mode, uint16_t skip, uint16_t sync_timeout, uint8_t cte_type,
743         base::OnceCallback<void(uint8_t*, uint16_t)> cb) {
744   uint8_t param[HCIC_PARAM_SIZE_SET_DEFAULT_PERIODIC_ADVERTISING_SYNC_TRANSFER_PARAMS];
745   uint8_t* pp = param;
746 
747   UINT16_TO_STREAM(pp, conn_handle);
748   UINT8_TO_STREAM(pp, mode);
749   UINT16_TO_STREAM(pp, skip);
750   UINT16_TO_STREAM(pp, sync_timeout);
751   UINT8_TO_STREAM(pp, cte_type);
752 
753   btu_hcif_send_cmd_with_cb(
754           FROM_HERE, HCI_LE_SET_DEFAULT_PERIODIC_ADVERTISING_SYNC_TRANSFER_PARAM, param,
755           HCIC_PARAM_SIZE_SET_DEFAULT_PERIODIC_ADVERTISING_SYNC_TRANSFER_PARAMS, std::move(cb));
756 }
757