1 /******************************************************************************
2  *
3  *  Copyright (C) 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 "common/bt_target.h"
27 #include "osi/allocator.h"
28 #include "stack/hcidefs.h"
29 #include "stack/hcimsgs.h"
30 #include "stack/hcidefs.h"
31 #include "stack/btu.h"
32 
33 #include <stddef.h>
34 #include <string.h>
35 
36 #if (BLE_50_FEATURE_SUPPORT == TRUE)
37 static BlE_SYNC ble_sync_info;
38 
btsnd_hcic_ble_sync_sem_init(void)39 void btsnd_hcic_ble_sync_sem_init(void)
40 {
41     ble_sync_info.opcode = 0;
42     osi_sem_new(&ble_sync_info.sync_sem, 1, 0);
43 }
44 
btsnd_hcic_ble_sync_sem_deinit(void)45 void btsnd_hcic_ble_sync_sem_deinit(void)
46 {
47     ble_sync_info.opcode = 0;
48     osi_sem_free(&ble_sync_info.sync_sem);
49 }
50 
btsnd_hcic_ble_get_sync_info(void)51 BlE_SYNC *btsnd_hcic_ble_get_sync_info(void)
52 {
53     return &ble_sync_info;
54 }
55 
btsnd_hcic_ble_get_status(void)56 uint8_t btsnd_hcic_ble_get_status(void)
57 {
58     return ble_sync_info.status;
59 }
60 
btsnd_hci_ble_set_status(UINT8 hci_status)61 void btsnd_hci_ble_set_status(UINT8 hci_status)
62 {
63     ble_sync_info.status = hci_status;
64     return;
65 }
66 #endif // #if (BLE_50_FEATURE_SUPPORT == TRUE)
67 
68 #if (defined BLE_INCLUDED) && (BLE_INCLUDED == TRUE)
69 
btsnd_hcic_ble_set_local_used_feat(UINT8 feat_set[8])70 BOOLEAN btsnd_hcic_ble_set_local_used_feat (UINT8 feat_set[8])
71 {
72     BT_HDR *p;
73     UINT8 *pp;
74 
75     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_SET_USED_FEAT_CMD)) == NULL) {
76         return (FALSE);
77     }
78 
79     pp = (UINT8 *)(p + 1);
80 
81     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_SET_USED_FEAT_CMD;
82     p->offset = 0;
83 
84     UINT16_TO_STREAM (pp, HCI_BLE_WRITE_LOCAL_SPT_FEAT);
85     ARRAY_TO_STREAM (pp, feat_set, HCIC_PARAM_SIZE_SET_USED_FEAT_CMD);
86 
87     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID,  p);
88     return (TRUE);
89 }
90 
btsnd_hcic_ble_set_random_addr(BD_ADDR random_bda)91 BOOLEAN btsnd_hcic_ble_set_random_addr (BD_ADDR random_bda)
92 {
93     BT_HDR *p;
94     UINT8 *pp;
95 
96     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_WRITE_RANDOM_ADDR_CMD)) == NULL) {
97         return (FALSE);
98     }
99 
100     pp = (UINT8 *)(p + 1);
101 
102     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_WRITE_RANDOM_ADDR_CMD;
103     p->offset = 0;
104 
105     UINT16_TO_STREAM (pp, HCI_BLE_WRITE_RANDOM_ADDR);
106     UINT8_TO_STREAM  (pp,  HCIC_PARAM_SIZE_WRITE_RANDOM_ADDR_CMD);
107 
108     BDADDR_TO_STREAM (pp, random_bda);
109 
110     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID,  p);
111     return (TRUE);
112 }
113 
btsnd_hcic_ble_write_adv_params(UINT16 adv_int_min,UINT16 adv_int_max,UINT8 adv_type,UINT8 addr_type_own,UINT8 addr_type_dir,BD_ADDR direct_bda,UINT8 channel_map,UINT8 adv_filter_policy)114 BOOLEAN btsnd_hcic_ble_write_adv_params (UINT16 adv_int_min, UINT16 adv_int_max,
115         UINT8 adv_type, UINT8 addr_type_own,
116         UINT8 addr_type_dir, BD_ADDR direct_bda,
117         UINT8 channel_map, UINT8 adv_filter_policy)
118 {
119     BT_HDR *p;
120     UINT8 *pp;
121     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_BLE_WRITE_ADV_PARAMS)) == NULL) {
122         return (FALSE);
123     }
124 
125     pp = (UINT8 *)(p + 1);
126 
127     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_WRITE_ADV_PARAMS ;
128     p->offset = 0;
129 
130     UINT16_TO_STREAM (pp, HCI_BLE_WRITE_ADV_PARAMS);
131     UINT8_TO_STREAM  (pp, HCIC_PARAM_SIZE_BLE_WRITE_ADV_PARAMS );
132 
133     UINT16_TO_STREAM (pp, adv_int_min);
134     UINT16_TO_STREAM (pp, adv_int_max);
135     UINT8_TO_STREAM (pp, adv_type);
136     UINT8_TO_STREAM (pp, addr_type_own);
137     UINT8_TO_STREAM (pp, addr_type_dir);
138     BDADDR_TO_STREAM (pp, direct_bda);
139     UINT8_TO_STREAM (pp, channel_map);
140     UINT8_TO_STREAM (pp, adv_filter_policy);
141 
142     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID,  p);
143     return (TRUE);
144 }
btsnd_hcic_ble_read_adv_chnl_tx_power(void)145 BOOLEAN btsnd_hcic_ble_read_adv_chnl_tx_power (void)
146 {
147     BT_HDR *p;
148     UINT8 *pp;
149 
150     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_READ_CMD)) == NULL) {
151         return (FALSE);
152     }
153 
154     pp = (UINT8 *)(p + 1);
155 
156     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_READ_CMD;
157     p->offset = 0;
158 
159     UINT16_TO_STREAM (pp, HCI_BLE_READ_ADV_CHNL_TX_POWER);
160     UINT8_TO_STREAM  (pp, HCIC_PARAM_SIZE_READ_CMD);
161 
162     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID,  p);
163     return (TRUE);
164 
165 }
166 
btsnd_hcic_ble_set_adv_data(UINT8 data_len,UINT8 * p_data)167 BOOLEAN btsnd_hcic_ble_set_adv_data (UINT8 data_len, UINT8 *p_data)
168 {
169     BT_HDR *p;
170     UINT8 *pp;
171 
172     for (int i = 0; i < data_len; i++) {
173         HCI_TRACE_DEBUG("p_data[%d] = %x\n", i, p_data[i]);
174     }
175 
176     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_BLE_WRITE_ADV_DATA + 1)) == NULL) {
177         return (FALSE);
178     }
179 
180     pp = (UINT8 *)(p + 1);
181 
182     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_WRITE_ADV_DATA + 1;
183     p->offset = 0;
184 
185     UINT16_TO_STREAM (pp, HCI_BLE_WRITE_ADV_DATA);
186     UINT8_TO_STREAM  (pp, HCIC_PARAM_SIZE_BLE_WRITE_ADV_DATA + 1);
187 
188     memset(pp, 0, HCIC_PARAM_SIZE_BLE_WRITE_ADV_DATA);
189 
190     if (p_data != NULL && data_len > 0) {
191         if (data_len > HCIC_PARAM_SIZE_BLE_WRITE_ADV_DATA) {
192             data_len = HCIC_PARAM_SIZE_BLE_WRITE_ADV_DATA;
193             HCI_TRACE_WARNING("Data length exceeds 31 bytes, only the first 31 bytes are used.\n");
194         }
195 
196         UINT8_TO_STREAM (pp, data_len);
197 
198         ARRAY_TO_STREAM (pp, p_data, data_len);
199     }
200     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID,  p);
201 
202     return (TRUE);
203 }
btsnd_hcic_ble_set_scan_rsp_data(UINT8 data_len,UINT8 * p_scan_rsp)204 BOOLEAN btsnd_hcic_ble_set_scan_rsp_data (UINT8 data_len, UINT8 *p_scan_rsp)
205 {
206     BT_HDR *p;
207     UINT8 *pp;
208 
209     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_BLE_WRITE_SCAN_RSP + 1)) == NULL) {
210         return (FALSE);
211     }
212 
213     pp = (UINT8 *)(p + 1);
214 
215     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_WRITE_SCAN_RSP + 1;
216     p->offset = 0;
217 
218     UINT16_TO_STREAM (pp, HCI_BLE_WRITE_SCAN_RSP_DATA);
219     UINT8_TO_STREAM  (pp, HCIC_PARAM_SIZE_BLE_WRITE_SCAN_RSP + 1);
220 
221     memset(pp, 0, HCIC_PARAM_SIZE_BLE_WRITE_SCAN_RSP);
222 
223     if (p_scan_rsp != NULL && data_len > 0) {
224 
225         if (data_len > HCIC_PARAM_SIZE_BLE_WRITE_SCAN_RSP ) {
226             data_len = HCIC_PARAM_SIZE_BLE_WRITE_SCAN_RSP;
227             HCI_TRACE_WARNING("Data length exceeds 31 bytes, only the first 31 bytes are used.\n");
228         }
229 
230         UINT8_TO_STREAM (pp, data_len);
231 
232         ARRAY_TO_STREAM (pp, p_scan_rsp, data_len);
233     }
234 
235     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID,  p);
236 
237     return (TRUE);
238 }
239 
btsnd_hcic_ble_set_adv_enable(UINT8 adv_enable)240 BOOLEAN btsnd_hcic_ble_set_adv_enable (UINT8 adv_enable)
241 {
242     BT_HDR *p;
243     UINT8 *pp;
244 
245     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_WRITE_ADV_ENABLE)) == NULL) {
246         return (FALSE);
247     }
248 
249     pp = (UINT8 *)(p + 1);
250 
251     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_WRITE_ADV_ENABLE;
252     p->offset = 0;
253 
254     UINT16_TO_STREAM (pp, HCI_BLE_WRITE_ADV_ENABLE);
255     UINT8_TO_STREAM  (pp, HCIC_PARAM_SIZE_WRITE_ADV_ENABLE);
256 
257     UINT8_TO_STREAM (pp, adv_enable);
258 
259     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID,  p);
260     return (TRUE);
261 }
btsnd_hcic_ble_set_scan_params(UINT8 scan_type,UINT16 scan_int,UINT16 scan_win,UINT8 addr_type_own,UINT8 scan_filter_policy)262 BOOLEAN btsnd_hcic_ble_set_scan_params (UINT8 scan_type,
263                                         UINT16 scan_int, UINT16 scan_win,
264                                         UINT8 addr_type_own, UINT8 scan_filter_policy)
265 {
266     BT_HDR *p;
267     UINT8 *pp;
268 
269     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_BLE_WRITE_SCAN_PARAM)) == NULL) {
270         return (FALSE);
271     }
272 
273     pp = (UINT8 *)(p + 1);
274 
275     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_WRITE_SCAN_PARAM;
276     p->offset = 0;
277 
278     UINT16_TO_STREAM (pp, HCI_BLE_WRITE_SCAN_PARAMS);
279     UINT8_TO_STREAM  (pp, HCIC_PARAM_SIZE_BLE_WRITE_SCAN_PARAM);
280 
281     UINT8_TO_STREAM (pp, scan_type);
282     UINT16_TO_STREAM (pp, scan_int);
283     UINT16_TO_STREAM (pp, scan_win);
284     UINT8_TO_STREAM (pp, addr_type_own);
285     UINT8_TO_STREAM (pp, scan_filter_policy);
286 
287     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID,  p);
288     return (TRUE);
289 }
290 
btsnd_hcic_ble_set_scan_enable(UINT8 scan_enable,UINT8 duplicate)291 BOOLEAN btsnd_hcic_ble_set_scan_enable (UINT8 scan_enable, UINT8 duplicate)
292 {
293     BT_HDR *p;
294     UINT8 *pp;
295 
296     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_BLE_WRITE_SCAN_ENABLE)) == NULL) {
297         return (FALSE);
298     }
299 
300     pp = (UINT8 *)(p + 1);
301 
302     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_WRITE_SCAN_ENABLE;
303     p->offset = 0;
304 
305     UINT16_TO_STREAM (pp, HCI_BLE_WRITE_SCAN_ENABLE);
306     UINT8_TO_STREAM  (pp, HCIC_PARAM_SIZE_BLE_WRITE_SCAN_ENABLE);
307 
308     UINT8_TO_STREAM (pp, scan_enable);
309     UINT8_TO_STREAM (pp, duplicate);
310 
311     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID,  p);
312     return (TRUE);
313 }
314 
315 /* link layer connection management commands */
btsnd_hcic_ble_create_ll_conn(UINT16 scan_int,UINT16 scan_win,UINT8 init_filter_policy,UINT8 addr_type_peer,BD_ADDR bda_peer,UINT8 addr_type_own,UINT16 conn_int_min,UINT16 conn_int_max,UINT16 conn_latency,UINT16 conn_timeout,UINT16 min_ce_len,UINT16 max_ce_len)316 BOOLEAN btsnd_hcic_ble_create_ll_conn (UINT16 scan_int, UINT16 scan_win,
317                                        UINT8 init_filter_policy,
318                                        UINT8 addr_type_peer, BD_ADDR bda_peer,
319                                        UINT8 addr_type_own,
320                                        UINT16 conn_int_min, UINT16 conn_int_max,
321                                        UINT16 conn_latency, UINT16 conn_timeout,
322                                        UINT16 min_ce_len, UINT16 max_ce_len)
323 {
324     BT_HDR *p;
325     UINT8 *pp;
326 
327     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_BLE_CREATE_LL_CONN)) == NULL) {
328         return (FALSE);
329     }
330 
331     pp = (UINT8 *)(p + 1);
332 
333     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_CREATE_LL_CONN;
334     p->offset = 0;
335 
336     UINT16_TO_STREAM (pp, HCI_BLE_CREATE_LL_CONN);
337     UINT8_TO_STREAM  (pp, HCIC_PARAM_SIZE_BLE_CREATE_LL_CONN);
338 
339     UINT16_TO_STREAM (pp, scan_int);
340     UINT16_TO_STREAM (pp, scan_win);
341     UINT8_TO_STREAM (pp, init_filter_policy);
342 
343     UINT8_TO_STREAM (pp, addr_type_peer);
344     BDADDR_TO_STREAM (pp, bda_peer);
345     UINT8_TO_STREAM (pp, addr_type_own);
346 
347     UINT16_TO_STREAM (pp, conn_int_min);
348     UINT16_TO_STREAM (pp, conn_int_max);
349     UINT16_TO_STREAM (pp, conn_latency);
350     UINT16_TO_STREAM (pp, conn_timeout);
351 
352     UINT16_TO_STREAM (pp, min_ce_len);
353     UINT16_TO_STREAM (pp, max_ce_len);
354 
355     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID,  p);
356     return (TRUE);
357 }
358 
btsnd_hcic_ble_create_conn_cancel(void)359 BOOLEAN btsnd_hcic_ble_create_conn_cancel (void)
360 {
361     BT_HDR *p;
362     UINT8 *pp;
363 
364     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_BLE_CREATE_CONN_CANCEL)) == NULL) {
365         return (FALSE);
366     }
367 
368     pp = (UINT8 *)(p + 1);
369 
370     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_CREATE_CONN_CANCEL;
371     p->offset = 0;
372 
373     UINT16_TO_STREAM (pp, HCI_BLE_CREATE_CONN_CANCEL);
374     UINT8_TO_STREAM  (pp, HCIC_PARAM_SIZE_BLE_CREATE_CONN_CANCEL);
375 
376     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID,  p);
377     return (TRUE);
378 }
379 
btsnd_hcic_ble_clear_white_list(void)380 BOOLEAN btsnd_hcic_ble_clear_white_list (void)
381 {
382     BT_HDR *p;
383     UINT8 *pp;
384 
385     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_CLEAR_WHITE_LIST)) == NULL) {
386         return (FALSE);
387     }
388 
389     pp = (UINT8 *)(p + 1);
390 
391     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_CLEAR_WHITE_LIST;
392     p->offset = 0;
393 
394     UINT16_TO_STREAM (pp, HCI_BLE_CLEAR_WHITE_LIST);
395     UINT8_TO_STREAM  (pp, HCIC_PARAM_SIZE_CLEAR_WHITE_LIST);
396 
397     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID,  p);
398     return (TRUE);
399 }
400 
btsnd_hcic_ble_add_white_list(UINT8 addr_type,BD_ADDR bda)401 BOOLEAN btsnd_hcic_ble_add_white_list (UINT8 addr_type, BD_ADDR bda)
402 {
403     BT_HDR *p;
404     UINT8 *pp;
405 
406     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_ADD_WHITE_LIST)) == NULL) {
407         return (FALSE);
408     }
409 
410     pp = (UINT8 *)(p + 1);
411 
412     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_ADD_WHITE_LIST;
413     p->offset = 0;
414 
415     UINT16_TO_STREAM (pp, HCI_BLE_ADD_WHITE_LIST);
416     UINT8_TO_STREAM  (pp, HCIC_PARAM_SIZE_ADD_WHITE_LIST);
417 
418     UINT8_TO_STREAM (pp, addr_type);
419     BDADDR_TO_STREAM (pp, bda);
420 
421     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID,  p);
422     return (TRUE);
423 }
424 
btsnd_hcic_ble_remove_from_white_list(UINT8 addr_type,BD_ADDR bda)425 BOOLEAN btsnd_hcic_ble_remove_from_white_list (UINT8 addr_type, BD_ADDR bda)
426 {
427     BT_HDR *p;
428     UINT8 *pp;
429 
430     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_REMOVE_WHITE_LIST)) == NULL) {
431         return (FALSE);
432     }
433 
434     pp = (UINT8 *)(p + 1);
435 
436     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_REMOVE_WHITE_LIST;
437     p->offset = 0;
438 
439     UINT16_TO_STREAM (pp, HCI_BLE_REMOVE_WHITE_LIST);
440     UINT8_TO_STREAM  (pp, HCIC_PARAM_SIZE_REMOVE_WHITE_LIST);
441 
442     UINT8_TO_STREAM (pp, addr_type);
443     BDADDR_TO_STREAM (pp, bda);
444 
445     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID,  p);
446     return (TRUE);
447 }
448 
btsnd_hcic_ble_upd_ll_conn_params(UINT16 handle,UINT16 conn_int_min,UINT16 conn_int_max,UINT16 conn_latency,UINT16 conn_timeout,UINT16 min_ce_len,UINT16 max_ce_len)449 BOOLEAN btsnd_hcic_ble_upd_ll_conn_params (UINT16 handle,
450         UINT16 conn_int_min, UINT16 conn_int_max,
451         UINT16 conn_latency, UINT16 conn_timeout,
452         UINT16 min_ce_len, UINT16 max_ce_len)
453 {
454     BT_HDR *p;
455     UINT8 *pp;
456 
457     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_BLE_UPD_LL_CONN_PARAMS)) == NULL) {
458         return (FALSE);
459     }
460 
461     pp = (UINT8 *)(p + 1);
462 
463     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_UPD_LL_CONN_PARAMS;
464     p->offset = 0;
465 
466     UINT16_TO_STREAM (pp, HCI_BLE_UPD_LL_CONN_PARAMS);
467     UINT8_TO_STREAM  (pp, HCIC_PARAM_SIZE_BLE_UPD_LL_CONN_PARAMS);
468 
469     UINT16_TO_STREAM (pp, handle);
470 
471     UINT16_TO_STREAM (pp, conn_int_min);
472     UINT16_TO_STREAM (pp, conn_int_max);
473     UINT16_TO_STREAM (pp, conn_latency);
474     UINT16_TO_STREAM (pp, conn_timeout);
475     UINT16_TO_STREAM (pp, min_ce_len);
476     UINT16_TO_STREAM (pp, max_ce_len);
477 
478     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID,  p);
479     return (TRUE);
480 }
481 
btsnd_hcic_ble_set_host_chnl_class(UINT8 chnl_map[HCIC_BLE_CHNL_MAP_SIZE])482 BOOLEAN btsnd_hcic_ble_set_host_chnl_class (UINT8  chnl_map[HCIC_BLE_CHNL_MAP_SIZE])
483 {
484     BT_HDR *p;
485     UINT8 *pp;
486 
487     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_SET_HOST_CHNL_CLASS)) == NULL) {
488         return (FALSE);
489     }
490 
491     pp = (UINT8 *)(p + 1);
492 
493     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_SET_HOST_CHNL_CLASS;
494     p->offset = 0;
495 
496     UINT16_TO_STREAM (pp, HCI_BLE_SET_HOST_CHNL_CLASS);
497     UINT8_TO_STREAM  (pp, HCIC_PARAM_SIZE_SET_HOST_CHNL_CLASS);
498 
499     ARRAY_TO_STREAM (pp, chnl_map, HCIC_BLE_CHNL_MAP_SIZE);
500 
501     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID,  p);
502     return (TRUE);
503 }
504 
btsnd_hcic_ble_read_chnl_map(UINT16 handle)505 BOOLEAN btsnd_hcic_ble_read_chnl_map (UINT16 handle)
506 {
507     BT_HDR *p;
508     UINT8 *pp;
509 
510     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_READ_CHNL_MAP)) == NULL) {
511         return (FALSE);
512     }
513 
514     pp = (UINT8 *)(p + 1);
515 
516     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_READ_CHNL_MAP;
517     p->offset = 0;
518 
519     UINT16_TO_STREAM (pp, HCI_BLE_READ_CHNL_MAP);
520     UINT8_TO_STREAM  (pp, HCIC_PARAM_SIZE_READ_CHNL_MAP);
521 
522     UINT16_TO_STREAM (pp, handle);
523 
524     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID,  p);
525     return (TRUE);
526 }
527 
btsnd_hcic_ble_read_remote_feat(UINT16 handle)528 BOOLEAN btsnd_hcic_ble_read_remote_feat (UINT16 handle)
529 {
530     BT_HDR *p;
531     UINT8 *pp;
532 
533     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_BLE_READ_REMOTE_FEAT)) == NULL) {
534         return (FALSE);
535     }
536 
537     pp = (UINT8 *)(p + 1);
538 
539     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_READ_REMOTE_FEAT;
540     p->offset = 0;
541 
542     UINT16_TO_STREAM (pp, HCI_BLE_READ_REMOTE_FEAT);
543     UINT8_TO_STREAM  (pp, HCIC_PARAM_SIZE_BLE_READ_REMOTE_FEAT);
544 
545     UINT16_TO_STREAM (pp, handle);
546 
547     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID,  p);
548     return (TRUE);
549 }
550 
551 /* security management commands */
btsnd_hcic_ble_encrypt(UINT8 * key,UINT8 key_len,UINT8 * plain_text,UINT8 pt_len,void * p_cmd_cplt_cback)552 BOOLEAN btsnd_hcic_ble_encrypt (UINT8 *key, UINT8 key_len,
553                                 UINT8 *plain_text, UINT8 pt_len,
554                                 void *p_cmd_cplt_cback)
555 {
556     BT_HDR *p;
557     UINT8 *pp;
558 
559     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_BLE_ENCRYPT)) == NULL) {
560         return (FALSE);
561     }
562 
563     pp = (UINT8 *)(p + 1);
564 
565     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_ENCRYPT;
566     p->offset = 0;
567 
568     hci_cmd_metadata_t *metadata = HCI_GET_CMD_METAMSG(p);
569     metadata->context = p_cmd_cplt_cback;
570 
571     UINT16_TO_STREAM (pp, HCI_BLE_ENCRYPT);
572     UINT8_TO_STREAM  (pp, HCIC_PARAM_SIZE_BLE_ENCRYPT);
573 
574     memset(pp, 0, HCIC_PARAM_SIZE_BLE_ENCRYPT);
575 
576     if (key_len > HCIC_BLE_ENCRYT_KEY_SIZE) {
577         key_len = HCIC_BLE_ENCRYT_KEY_SIZE;
578     }
579     if (pt_len > HCIC_BLE_ENCRYT_KEY_SIZE) {
580         pt_len = HCIC_BLE_ENCRYT_KEY_SIZE;
581     }
582 
583     ARRAY_TO_STREAM (pp, key, key_len);
584     pp += (HCIC_BLE_ENCRYT_KEY_SIZE - key_len);
585     ARRAY_TO_STREAM (pp, plain_text, pt_len);
586 
587     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID,  p);
588     return (TRUE);
589 }
590 
btsnd_hcic_ble_rand(void * p_cmd_cplt_cback)591 BOOLEAN btsnd_hcic_ble_rand (void *p_cmd_cplt_cback)
592 {
593     BT_HDR *p;
594     UINT8 *pp;
595 
596     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_BLE_RAND)) == NULL) {
597         return (FALSE);
598     }
599 
600     pp = (UINT8 *)(p + 1);
601 
602     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_RAND;
603     p->offset = 0;
604 
605     hci_cmd_metadata_t *metadata = HCI_GET_CMD_METAMSG(p);
606     metadata->context = p_cmd_cplt_cback;
607 
608     UINT16_TO_STREAM (pp, HCI_BLE_RAND);
609     UINT8_TO_STREAM  (pp, HCIC_PARAM_SIZE_BLE_RAND);
610 
611     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID,  p);
612     return (TRUE);
613 }
614 
btsnd_hcic_ble_start_enc(UINT16 handle,UINT8 rand[HCIC_BLE_RAND_DI_SIZE],UINT16 ediv,UINT8 ltk[HCIC_BLE_ENCRYT_KEY_SIZE])615 BOOLEAN btsnd_hcic_ble_start_enc (UINT16 handle, UINT8 rand[HCIC_BLE_RAND_DI_SIZE],
616                                   UINT16 ediv, UINT8 ltk[HCIC_BLE_ENCRYT_KEY_SIZE])
617 {
618     BT_HDR *p;
619     UINT8 *pp;
620 
621     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_BLE_START_ENC)) == NULL) {
622         return (FALSE);
623     }
624 
625     pp = (UINT8 *)(p + 1);
626 
627     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_START_ENC;
628     p->offset = 0;
629 
630     UINT16_TO_STREAM (pp, HCI_BLE_START_ENC);
631     UINT8_TO_STREAM  (pp, HCIC_PARAM_SIZE_BLE_START_ENC);
632 
633     UINT16_TO_STREAM (pp, handle);
634     ARRAY_TO_STREAM (pp, rand, HCIC_BLE_RAND_DI_SIZE);
635     UINT16_TO_STREAM (pp, ediv);
636     ARRAY_TO_STREAM (pp, ltk, HCIC_BLE_ENCRYT_KEY_SIZE);
637 
638     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID,  p);
639     return (TRUE);
640 }
641 
btsnd_hcic_ble_ltk_req_reply(UINT16 handle,UINT8 ltk[HCIC_BLE_ENCRYT_KEY_SIZE])642 BOOLEAN btsnd_hcic_ble_ltk_req_reply (UINT16 handle, UINT8 ltk[HCIC_BLE_ENCRYT_KEY_SIZE])
643 {
644     BT_HDR *p;
645     UINT8 *pp;
646 
647     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_LTK_REQ_REPLY)) == NULL) {
648         return (FALSE);
649     }
650 
651     pp = (UINT8 *)(p + 1);
652 
653     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_LTK_REQ_REPLY;
654     p->offset = 0;
655 
656     UINT16_TO_STREAM (pp, HCI_BLE_LTK_REQ_REPLY);
657     UINT8_TO_STREAM  (pp, HCIC_PARAM_SIZE_LTK_REQ_REPLY);
658 
659     UINT16_TO_STREAM (pp, handle);
660     ARRAY_TO_STREAM (pp, ltk, HCIC_BLE_ENCRYT_KEY_SIZE);
661 
662     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID,  p);
663     return (TRUE);
664 }
665 
btsnd_hcic_ble_ltk_req_neg_reply(UINT16 handle)666 BOOLEAN btsnd_hcic_ble_ltk_req_neg_reply (UINT16 handle)
667 {
668     BT_HDR *p;
669     UINT8 *pp;
670 
671     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_LTK_REQ_NEG_REPLY)) == NULL) {
672         return (FALSE);
673     }
674 
675     pp = (UINT8 *)(p + 1);
676 
677     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_LTK_REQ_NEG_REPLY;
678     p->offset = 0;
679 
680     UINT16_TO_STREAM (pp, HCI_BLE_LTK_REQ_NEG_REPLY);
681     UINT8_TO_STREAM  (pp, HCIC_PARAM_SIZE_LTK_REQ_NEG_REPLY);
682 
683     UINT16_TO_STREAM (pp, handle);
684 
685     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID,  p);
686     return (TRUE);
687 }
688 
btsnd_hcic_ble_receiver_test(UINT8 rx_freq)689 BOOLEAN btsnd_hcic_ble_receiver_test(UINT8 rx_freq)
690 {
691     BT_HDR *p;
692     UINT8 *pp;
693 
694     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_WRITE_PARAM1)) == NULL) {
695         return (FALSE);
696     }
697 
698     pp = (UINT8 *)(p + 1);
699 
700     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_WRITE_PARAM1;
701     p->offset = 0;
702 
703     UINT16_TO_STREAM (pp, HCI_BLE_RECEIVER_TEST);
704     UINT8_TO_STREAM  (pp, HCIC_PARAM_SIZE_WRITE_PARAM1);
705 
706     UINT8_TO_STREAM (pp, rx_freq);
707 
708     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID,  p);
709     return (TRUE);
710 }
711 
btsnd_hcic_ble_transmitter_test(UINT8 tx_freq,UINT8 test_data_len,UINT8 payload)712 BOOLEAN btsnd_hcic_ble_transmitter_test(UINT8 tx_freq, UINT8 test_data_len, UINT8 payload)
713 {
714     BT_HDR *p;
715     UINT8 *pp;
716 
717     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_WRITE_PARAM3)) == NULL) {
718         return (FALSE);
719     }
720 
721     pp = (UINT8 *)(p + 1);
722 
723     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_WRITE_PARAM3;
724     p->offset = 0;
725 
726     UINT16_TO_STREAM (pp, HCI_BLE_TRANSMITTER_TEST);
727     UINT8_TO_STREAM  (pp, HCIC_PARAM_SIZE_WRITE_PARAM3);
728 
729     UINT8_TO_STREAM (pp, tx_freq);
730     UINT8_TO_STREAM (pp, test_data_len);
731     UINT8_TO_STREAM (pp, payload);
732 
733     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID,  p);
734     return (TRUE);
735 }
736 
btsnd_hcic_ble_test_end(void)737 BOOLEAN btsnd_hcic_ble_test_end(void)
738 {
739     BT_HDR *p;
740     UINT8 *pp;
741 
742     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_READ_CMD)) == NULL) {
743         return (FALSE);
744     }
745 
746     pp = (UINT8 *)(p + 1);
747 
748     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_READ_CMD;
749     p->offset = 0;
750 
751     UINT16_TO_STREAM (pp, HCI_BLE_TEST_END);
752     UINT8_TO_STREAM  (pp, HCIC_PARAM_SIZE_READ_CMD);
753 
754     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID,  p);
755     return (TRUE);
756 }
757 
btsnd_hcic_ble_read_host_supported(void)758 BOOLEAN btsnd_hcic_ble_read_host_supported (void)
759 {
760     BT_HDR *p;
761     UINT8 *pp;
762 
763     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_READ_CMD)) == NULL) {
764         return (FALSE);
765     }
766 
767     pp = (UINT8 *)(p + 1);
768 
769     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_READ_CMD;
770     p->offset = 0;
771 
772     UINT16_TO_STREAM (pp, HCI_READ_LE_HOST_SUPPORT);
773     UINT8_TO_STREAM  (pp, HCIC_PARAM_SIZE_READ_CMD);
774 
775     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID,  p);
776     return (TRUE);
777 }
778 
779 #if (defined BLE_LLT_INCLUDED) && (BLE_LLT_INCLUDED == TRUE)
780 
btsnd_hcic_ble_rc_param_req_reply(UINT16 handle,UINT16 conn_int_min,UINT16 conn_int_max,UINT16 conn_latency,UINT16 conn_timeout,UINT16 min_ce_len,UINT16 max_ce_len)781 BOOLEAN btsnd_hcic_ble_rc_param_req_reply(  UINT16 handle,
782         UINT16 conn_int_min, UINT16 conn_int_max,
783         UINT16 conn_latency, UINT16 conn_timeout,
784         UINT16 min_ce_len, UINT16 max_ce_len  )
785 {
786     BT_HDR *p;
787     UINT8 *pp;
788 
789     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_BLE_RC_PARAM_REQ_REPLY)) == NULL) {
790         return (FALSE);
791     }
792 
793     pp = (UINT8 *)(p + 1);
794 
795     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_RC_PARAM_REQ_REPLY;
796     p->offset = 0;
797 
798     UINT16_TO_STREAM (pp, HCI_BLE_RC_PARAM_REQ_REPLY);
799     UINT8_TO_STREAM  (pp, HCIC_PARAM_SIZE_BLE_RC_PARAM_REQ_REPLY);
800 
801     UINT16_TO_STREAM (pp, handle);
802     UINT16_TO_STREAM (pp, conn_int_min);
803     UINT16_TO_STREAM (pp, conn_int_max);
804     UINT16_TO_STREAM (pp, conn_latency);
805     UINT16_TO_STREAM (pp, conn_timeout);
806     UINT16_TO_STREAM (pp, min_ce_len);
807     UINT16_TO_STREAM (pp, max_ce_len);
808 
809     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID,  p);
810     return (TRUE);
811 }
812 
btsnd_hcic_ble_rc_param_req_neg_reply(UINT16 handle,UINT8 reason)813 BOOLEAN btsnd_hcic_ble_rc_param_req_neg_reply(UINT16 handle, UINT8 reason)
814 {
815     BT_HDR *p;
816     UINT8 *pp;
817 
818     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_BLE_RC_PARAM_REQ_NEG_REPLY)) == NULL) {
819         return (FALSE);
820     }
821 
822     pp = (UINT8 *)(p + 1);
823 
824     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_RC_PARAM_REQ_NEG_REPLY;
825     p->offset = 0;
826 
827     UINT16_TO_STREAM (pp, HCI_BLE_RC_PARAM_REQ_NEG_REPLY);
828     UINT8_TO_STREAM  (pp, HCIC_PARAM_SIZE_BLE_RC_PARAM_REQ_NEG_REPLY);
829 
830     UINT16_TO_STREAM (pp, handle);
831     UINT8_TO_STREAM (pp, reason);
832 
833     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID,  p);
834     return (TRUE);
835 }
836 #endif
837 
btsnd_hcic_ble_add_device_resolving_list(UINT8 addr_type_peer,BD_ADDR bda_peer,UINT8 irk_peer[HCIC_BLE_IRK_SIZE],UINT8 irk_local[HCIC_BLE_IRK_SIZE])838 BOOLEAN btsnd_hcic_ble_add_device_resolving_list (UINT8 addr_type_peer, BD_ADDR bda_peer,
839         UINT8 irk_peer[HCIC_BLE_IRK_SIZE],
840         UINT8 irk_local[HCIC_BLE_IRK_SIZE])
841 {
842     BT_HDR *p;
843     UINT8 *pp;
844 
845     if ((p = HCI_GET_CMD_BUF (HCIC_PARAM_SIZE_BLE_ADD_DEV_RESOLVING_LIST)) == NULL) {
846         return (FALSE);
847     }
848 
849     pp = (UINT8 *)(p + 1);
850 
851     p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_ADD_DEV_RESOLVING_LIST;
852     p->offset = 0;
853 
854     UINT16_TO_STREAM (pp, HCI_BLE_ADD_DEV_RESOLVING_LIST);
855     UINT8_TO_STREAM (pp, HCIC_PARAM_SIZE_BLE_ADD_DEV_RESOLVING_LIST);
856     UINT8_TO_STREAM (pp, addr_type_peer);
857     BDADDR_TO_STREAM (pp, bda_peer);
858     ARRAY_TO_STREAM (pp, irk_peer, HCIC_BLE_ENCRYT_KEY_SIZE);
859     ARRAY_TO_STREAM (pp, irk_local, HCIC_BLE_ENCRYT_KEY_SIZE);
860 
861     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p);
862 
863     return (TRUE);
864 }
865 
btsnd_hcic_ble_rm_device_resolving_list(UINT8 addr_type_peer,BD_ADDR bda_peer)866 BOOLEAN btsnd_hcic_ble_rm_device_resolving_list (UINT8 addr_type_peer, BD_ADDR bda_peer)
867 {
868     BT_HDR *p;
869     UINT8 *pp;
870 
871     if ((p = HCI_GET_CMD_BUF (HCIC_PARAM_SIZE_BLE_RM_DEV_RESOLVING_LIST)) == NULL) {
872         return (FALSE);
873     }
874 
875     pp = (UINT8 *)(p + 1);
876 
877     p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_RM_DEV_RESOLVING_LIST;
878     p->offset = 0;
879 
880     UINT16_TO_STREAM (pp, HCI_BLE_RM_DEV_RESOLVING_LIST);
881     UINT8_TO_STREAM (pp, HCIC_PARAM_SIZE_BLE_RM_DEV_RESOLVING_LIST);
882     UINT8_TO_STREAM (pp, addr_type_peer);
883     BDADDR_TO_STREAM (pp, bda_peer);
884 
885     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p);
886 
887     return (TRUE);
888 }
889 
btsnd_hcic_ble_clear_resolving_list(void)890 BOOLEAN btsnd_hcic_ble_clear_resolving_list (void)
891 {
892     BT_HDR *p;
893     UINT8 *pp;
894 
895     if ((p = HCI_GET_CMD_BUF (HCIC_PARAM_SIZE_BLE_CLEAR_RESOLVING_LIST)) == NULL) {
896         return (FALSE);
897     }
898 
899     pp = (UINT8 *)(p + 1);
900 
901     p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_CLEAR_RESOLVING_LIST;
902     p->offset = 0;
903 
904     UINT16_TO_STREAM (pp, HCI_BLE_CLEAR_RESOLVING_LIST);
905     UINT8_TO_STREAM (pp, HCIC_PARAM_SIZE_BLE_CLEAR_RESOLVING_LIST);
906 
907     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p);
908 
909     return (TRUE);
910 }
911 
btsnd_hcic_ble_read_resolvable_addr_peer(UINT8 addr_type_peer,BD_ADDR bda_peer)912 BOOLEAN btsnd_hcic_ble_read_resolvable_addr_peer (UINT8 addr_type_peer, BD_ADDR bda_peer)
913 {
914     BT_HDR *p;
915     UINT8 *pp;
916 
917     if ((p = HCI_GET_CMD_BUF (HCIC_PARAM_SIZE_BLE_READ_RESOLVABLE_ADDR_PEER)) == NULL) {
918         return (FALSE);
919     }
920 
921     pp = (UINT8 *)(p + 1);
922 
923     p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_READ_RESOLVABLE_ADDR_PEER;
924     p->offset = 0;
925 
926     UINT16_TO_STREAM (pp, HCI_BLE_READ_RESOLVABLE_ADDR_PEER);
927     UINT8_TO_STREAM (pp, HCIC_PARAM_SIZE_BLE_READ_RESOLVABLE_ADDR_PEER);
928     UINT8_TO_STREAM (pp, addr_type_peer);
929     BDADDR_TO_STREAM (pp, bda_peer);
930 
931     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p);
932 
933     return (TRUE);
934 }
935 
btsnd_hcic_ble_read_resolvable_addr_local(UINT8 addr_type_peer,BD_ADDR bda_peer)936 BOOLEAN btsnd_hcic_ble_read_resolvable_addr_local (UINT8 addr_type_peer, BD_ADDR bda_peer)
937 {
938     BT_HDR *p;
939     UINT8 *pp;
940 
941     if ((p = HCI_GET_CMD_BUF (HCIC_PARAM_SIZE_BLE_READ_RESOLVABLE_ADDR_LOCAL)) == NULL) {
942         return (FALSE);
943     }
944 
945     pp = (UINT8 *)(p + 1);
946 
947     p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_READ_RESOLVABLE_ADDR_LOCAL;
948     p->offset = 0;
949 
950     UINT16_TO_STREAM (pp, HCI_BLE_READ_RESOLVABLE_ADDR_LOCAL);
951     UINT8_TO_STREAM (pp, HCIC_PARAM_SIZE_BLE_READ_RESOLVABLE_ADDR_LOCAL);
952     UINT8_TO_STREAM (pp, addr_type_peer);
953     BDADDR_TO_STREAM (pp, bda_peer);
954 
955     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p);
956 
957     return (TRUE);
958 }
959 
btsnd_hcic_ble_set_addr_resolution_enable(UINT8 addr_resolution_enable)960 BOOLEAN btsnd_hcic_ble_set_addr_resolution_enable (UINT8 addr_resolution_enable)
961 {
962     BT_HDR *p;
963     UINT8 *pp;
964 
965     if ((p = HCI_GET_CMD_BUF (HCIC_PARAM_SIZE_BLE_SET_ADDR_RESOLUTION_ENABLE)) == NULL) {
966         return (FALSE);
967     }
968 
969     pp = (UINT8 *)(p + 1);
970 
971     p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_SET_ADDR_RESOLUTION_ENABLE;
972     p->offset = 0;
973 
974     UINT16_TO_STREAM (pp, HCI_BLE_SET_ADDR_RESOLUTION_ENABLE);
975     UINT8_TO_STREAM (pp, HCIC_PARAM_SIZE_BLE_SET_ADDR_RESOLUTION_ENABLE);
976     UINT8_TO_STREAM (pp, addr_resolution_enable);
977 
978     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p);
979 
980     return (TRUE);
981 }
982 
btsnd_hcic_ble_set_rand_priv_addr_timeout(UINT16 rpa_timout)983 BOOLEAN btsnd_hcic_ble_set_rand_priv_addr_timeout (UINT16 rpa_timout)
984 {
985     BT_HDR *p;
986     UINT8 *pp;
987 
988     if ((p = HCI_GET_CMD_BUF (HCIC_PARAM_SIZE_BLE_SET_RAND_PRIV_ADDR_TIMOUT)) == NULL) {
989         return (FALSE);
990     }
991 
992     pp = (UINT8 *)(p + 1);
993 
994     p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_SET_RAND_PRIV_ADDR_TIMOUT;
995     p->offset = 0;
996 
997     UINT16_TO_STREAM (pp, HCI_BLE_SET_RAND_PRIV_ADDR_TIMOUT);
998     UINT8_TO_STREAM (pp, HCIC_PARAM_SIZE_BLE_SET_RAND_PRIV_ADDR_TIMOUT);
999     UINT16_TO_STREAM (pp, rpa_timout);
1000 
1001     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p);
1002 
1003     return (TRUE);
1004 }
1005 
btsnd_hcic_ble_set_data_length(UINT16 conn_handle,UINT16 tx_octets,UINT16 tx_time)1006 BOOLEAN btsnd_hcic_ble_set_data_length(UINT16 conn_handle, UINT16 tx_octets, UINT16 tx_time)
1007 {
1008     BT_HDR *p;
1009     UINT8 *pp;
1010 
1011     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_BLE_SET_DATA_LENGTH)) == NULL) {
1012         return FALSE;
1013     }
1014 
1015     pp = p->data;
1016 
1017     p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_SET_DATA_LENGTH;
1018     p->offset = 0;
1019 
1020     UINT16_TO_STREAM(pp, HCI_BLE_SET_DATA_LENGTH);
1021     UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_BLE_SET_DATA_LENGTH);
1022 
1023     UINT16_TO_STREAM(pp, conn_handle);
1024     UINT16_TO_STREAM(pp, tx_octets);
1025     UINT16_TO_STREAM(pp, tx_time);
1026 
1027     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p);
1028     return TRUE;
1029 }
1030 
btsnd_hcic_ble_update_adv_report_flow_control(UINT16 num,BT_HDR * static_buf)1031 BOOLEAN btsnd_hcic_ble_update_adv_report_flow_control (UINT16 num, BT_HDR *static_buf)
1032 {
1033     BT_HDR *p;
1034     UINT8 *pp;
1035 
1036     if (static_buf != NULL) {
1037         p = static_buf;
1038     } else {
1039         if ((p = HCI_GET_CMD_BUF (HCIC_PARAM_SIZE_BLE_UPDATE_ADV_FLOW_CONTROL)) == NULL) {
1040             return (FALSE);
1041         }
1042     }
1043 
1044     hci_cmd_metadata_t *metadata = HCI_GET_CMD_METAMSG(p);
1045     metadata->flags_src = HCI_CMD_MSG_F_SRC_NOACK;
1046     if (static_buf == p) {
1047         assert(metadata->command_free_cb != NULL);
1048     }
1049     p->layer_specific = HCI_CMD_BUF_TYPE_METADATA;
1050 
1051     pp = (UINT8 *)(p + 1);
1052 
1053     p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_UPDATE_ADV_FLOW_CONTROL;
1054     p->offset = 0;
1055 
1056     UINT16_TO_STREAM (pp, HCI_VENDOR_BLE_ADV_REPORT_FLOW_CONTROL);
1057     UINT8_TO_STREAM (pp, HCIC_PARAM_SIZE_BLE_UPDATE_ADV_FLOW_CONTROL);
1058     UINT16_TO_STREAM (pp, num);
1059 
1060     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p);
1061     return TRUE;
1062 }
1063 
btsnd_hcic_ble_set_channels(BLE_CHANNELS channels)1064 BOOLEAN btsnd_hcic_ble_set_channels (BLE_CHANNELS channels)
1065 {
1066     BT_HDR *p;
1067     UINT8 *pp;
1068 
1069     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_BLE_SET_CHANNELS)) == NULL) {
1070         return (FALSE);
1071     }
1072 
1073     pp = (UINT8 *)(p + 1);
1074 
1075     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_SET_CHANNELS;
1076     p->offset = 0;
1077 
1078     UINT16_TO_STREAM (pp, HCI_BLE_SET_HOST_CHNL_CLASS);
1079     UINT8_TO_STREAM  (pp, HCIC_PARAM_SIZE_BLE_SET_CHANNELS);
1080 
1081     ARRAY_TO_STREAM  (pp, channels, HCIC_PARAM_SIZE_BLE_SET_CHANNELS);
1082 
1083     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID,  p);
1084     return (TRUE);
1085 }
1086 
1087 #define HCIC_BLE_CMD_CREATED(p, pp, size) do{\
1088     if ((p = HCI_GET_CMD_BUF(size)) == NULL) { \
1089         return FALSE; \
1090     } \
1091     pp = p->data; \
1092     p->len = HCIC_PREAMBLE_SIZE + size;\
1093     p->offset = 0; \
1094 } while(0)
1095 
1096 #if (BLE_50_FEATURE_SUPPORT == TRUE)
1097 
btsnd_hcic_ble_read_phy(UINT16 conn_handle)1098 BOOLEAN btsnd_hcic_ble_read_phy(UINT16 conn_handle)
1099 {
1100     BT_HDR *p;
1101     UINT8 *pp;
1102 
1103     HCI_TRACE_EVENT("%s, conn_handle = %d", __func__, conn_handle);
1104     HCIC_BLE_CMD_CREATED(p, pp, HCIC_PARAM_SIZE_BLE_READ_PHY);
1105 
1106     UINT16_TO_STREAM(pp, HCI_BLE_READ_PHY);
1107     UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_BLE_READ_PHY);
1108     UINT16_TO_STREAM(pp, conn_handle);
1109 
1110     btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
1111     return TRUE;
1112 }
1113 
btsnd_hcic_ble_set_prefered_default_phy(UINT8 all_phys,UINT8 tx_phys,UINT8 rx_phys)1114 UINT8 btsnd_hcic_ble_set_prefered_default_phy(UINT8 all_phys,
1115                                                               UINT8 tx_phys,
1116                                                               UINT8 rx_phys)
1117 {
1118     BT_HDR *p;
1119     UINT8 *pp;
1120 
1121     HCI_TRACE_EVENT("%s, all_phys = %d, tx_phys = %d, rx_phys = %d", __func__, all_phys, tx_phys, rx_phys);
1122     HCIC_BLE_CMD_CREATED(p, pp, HCIC_PARAM_SIZE_BLE_SET_DEF_PHY);
1123 
1124     UINT16_TO_STREAM(pp, HCI_BLE_SET_DEFAULT_PHY);
1125     UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_BLE_SET_DEF_PHY);
1126 
1127     UINT8_TO_STREAM(pp, all_phys);
1128     UINT8_TO_STREAM(pp, tx_phys);
1129     UINT8_TO_STREAM(pp, rx_phys);
1130 
1131     return btu_hcif_send_cmd_sync(LOCAL_BR_EDR_CONTROLLER_ID, p);
1132 }
1133 
btsnd_hcic_ble_set_phy(UINT16 conn_handle,UINT8 all_phys,UINT8 tx_phys,UINT8 rx_phys,UINT16 phy_options)1134 BOOLEAN btsnd_hcic_ble_set_phy(UINT16 conn_handle,
1135                                            UINT8 all_phys, UINT8 tx_phys,
1136                                            UINT8 rx_phys, UINT16 phy_options)
1137 {
1138     BT_HDR *p;
1139     UINT8 *pp;
1140     HCI_TRACE_EVENT("%s, conn_handle = %d, all_phys = %d, tx_phys = %d, rx_phys = %d, phy_options = %d", __func__,
1141         conn_handle, all_phys, tx_phys, rx_phys, phy_options);
1142     HCIC_BLE_CMD_CREATED(p, pp, HCIC_PARAM_SIZE_BLE_SET_PHY);
1143 
1144     UINT16_TO_STREAM(pp, HCI_BLE_SET_PHY);
1145     UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_BLE_SET_PHY);
1146     UINT16_TO_STREAM(pp, conn_handle);
1147     UINT8_TO_STREAM(pp, all_phys);
1148     UINT8_TO_STREAM(pp, tx_phys);
1149     UINT8_TO_STREAM(pp, rx_phys);
1150     UINT16_TO_STREAM(pp, phy_options);
1151 
1152     btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
1153     return TRUE;
1154 }
1155 
btsnd_hcic_ble_enhand_rx_test(UINT8 rx_channel,UINT8 phy,UINT8 modulation_idx)1156 UINT8 btsnd_hcic_ble_enhand_rx_test(UINT8 rx_channel, UINT8 phy,
1157                                                          UINT8 modulation_idx)
1158 {
1159     BT_HDR *p;
1160     UINT8 *pp;
1161 
1162     HCI_TRACE_EVENT("%s, rx_channel = %d, phy = %d, modulation_idx = %d", __func__,
1163         rx_channel, phy, modulation_idx);
1164     HCIC_BLE_CMD_CREATED(p, pp, HCIC_PARAM_SIZE_ENH_RX_TEST);
1165 
1166     UINT16_TO_STREAM(pp, HCI_BLE_ENH_RX_TEST);
1167     UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_ENH_RX_TEST);
1168     UINT8_TO_STREAM(pp, rx_channel);
1169     UINT8_TO_STREAM(pp, phy);
1170     UINT8_TO_STREAM(pp, modulation_idx);
1171 
1172     return btu_hcif_send_cmd_sync(LOCAL_BR_EDR_CONTROLLER_ID, p);
1173 }
1174 
btsnd_hcic_ble_enhand_tx_test(UINT8 tx_channel,UINT8 len,UINT8 packect,UINT8 phy)1175 UINT8 btsnd_hcic_ble_enhand_tx_test(UINT8 tx_channel, UINT8 len,
1176                                                          UINT8 packect,
1177                                                          UINT8 phy)
1178 {
1179     BT_HDR *p;
1180     UINT8 *pp;
1181 
1182     HCI_TRACE_EVENT("%s, tx_channel = %d, len = %d, packect = %d, phy = %d", __func__,
1183             tx_channel, len, packect, phy);
1184 
1185     HCIC_BLE_CMD_CREATED(p, pp, HCIC_PARAM_SIZE_ENH_TX_TEST);
1186 
1187     UINT16_TO_STREAM(pp, HCI_BLE_ENH_TX_TEST);
1188     UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_ENH_TX_TEST);
1189     UINT8_TO_STREAM(pp, tx_channel);
1190     UINT8_TO_STREAM(pp, len);
1191     UINT8_TO_STREAM(pp, packect);
1192     UINT8_TO_STREAM(pp, phy);
1193 
1194     return btu_hcif_send_cmd_sync(LOCAL_BR_EDR_CONTROLLER_ID, p);
1195 }
1196 
btsnd_hcic_ble_set_extend_rand_address(UINT8 adv_handle,BD_ADDR rand_addr)1197 UINT8 btsnd_hcic_ble_set_extend_rand_address(UINT8 adv_handle, BD_ADDR rand_addr)
1198 {
1199     BT_HDR *p;
1200     UINT8 *pp;
1201     HCI_TRACE_EVENT("%s, adv_handle = %d", __func__, adv_handle);
1202 
1203     HCIC_BLE_CMD_CREATED(p, pp, HCIC_PARAM_SIZE_EXT_RAND_ADDR);
1204 
1205     UINT16_TO_STREAM (pp, HCI_BLE_SET_ADV_RAND_ADDR);
1206     UINT8_TO_STREAM  (pp,  HCIC_PARAM_SIZE_EXT_RAND_ADDR);
1207     UINT8_TO_STREAM(pp, adv_handle);
1208     BDADDR_TO_STREAM (pp, rand_addr);
1209 
1210     return btu_hcif_send_cmd_sync (LOCAL_BR_EDR_CONTROLLER_ID, p);
1211 
1212 }
1213 
btsnd_hcic_ble_set_ext_adv_params(UINT8 adv_handle,UINT16 properties,UINT32 interval_min,UINT32 interval_max,UINT8 channel_map,UINT8 own_addr_type,UINT8 peer_addr_type,BD_ADDR peer_addr,UINT8 adv_filter_policy,INT8 adv_tx_power,UINT8 primary_adv_phy,UINT8 secondary_adv_max_skip,UINT8 secondary_adv_phy,UINT8 adv_sid,UINT8 scan_req_ntf_enable)1214 UINT8 btsnd_hcic_ble_set_ext_adv_params(UINT8 adv_handle, UINT16 properties, UINT32 interval_min,
1215                                           UINT32 interval_max, UINT8 channel_map, UINT8 own_addr_type,
1216                                           UINT8 peer_addr_type, BD_ADDR peer_addr,
1217                                           UINT8 adv_filter_policy, INT8 adv_tx_power,
1218                                           UINT8 primary_adv_phy, UINT8 secondary_adv_max_skip,
1219                                           UINT8 secondary_adv_phy,
1220                                           UINT8 adv_sid, UINT8 scan_req_ntf_enable)
1221 {
1222     BT_HDR *p;
1223     UINT8 *pp;
1224 
1225 
1226     HCI_TRACE_EVENT("%s, adv_handle = %d, properties = %d, interval_min = %d, interval_max = %d, channel_map = %d,\n\
1227                      own_addr_type = %d, peer_addr_type = %d, adv_filter_policy = %d,\n\
1228                      adv_tx_power = %d, primary_adv_phy = %d, secondary_adv_max_skip = %d, secondary_adv_phy = %d,\n\
1229                      adv_sid = %d, scan_req_ntf_enable = %d", __func__, adv_handle, properties, interval_min, interval_max,
1230                      channel_map, own_addr_type, peer_addr_type, adv_filter_policy, adv_tx_power,
1231                      primary_adv_phy, secondary_adv_max_skip, secondary_adv_phy, adv_sid, scan_req_ntf_enable);
1232 
1233     HCIC_BLE_CMD_CREATED(p, pp, HCIC_PARAM_SIZE_EXT_ADV_SET_PARAMS);
1234 
1235     UINT16_TO_STREAM(pp, HCI_BLE_SET_EXT_ADV_PARAM);
1236     UINT8_TO_STREAM(pp,  HCIC_PARAM_SIZE_EXT_ADV_SET_PARAMS);
1237 
1238     UINT8_TO_STREAM(pp, adv_handle);
1239     UINT16_TO_STREAM(pp, properties);
1240     UINT24_TO_STREAM(pp, interval_min);
1241     UINT24_TO_STREAM(pp, interval_max);
1242     UINT8_TO_STREAM(pp, channel_map);
1243     UINT8_TO_STREAM(pp, own_addr_type);
1244     UINT8_TO_STREAM(pp, peer_addr_type);
1245     BDADDR_TO_STREAM (pp, peer_addr);
1246     UINT8_TO_STREAM(pp, adv_filter_policy);
1247     INT8_TO_STREAM(pp, adv_tx_power);
1248     UINT8_TO_STREAM(pp, primary_adv_phy);
1249     UINT8_TO_STREAM(pp, secondary_adv_max_skip);
1250     UINT8_TO_STREAM(pp, secondary_adv_phy);
1251     UINT8_TO_STREAM(pp, adv_sid);
1252     UINT8_TO_STREAM(pp, scan_req_ntf_enable);
1253 
1254     return btu_hcif_send_cmd_sync (LOCAL_BR_EDR_CONTROLLER_ID, p);
1255 }
1256 
1257 bool ext_adv_flag = false;
1258 
btsnd_hcic_ble_set_ext_adv_data(UINT8 adv_handle,UINT8 operation,UINT8 fragment_prefrence,UINT8 data_len,UINT8 * p_data)1259 UINT8 btsnd_hcic_ble_set_ext_adv_data(UINT8 adv_handle,
1260                                       UINT8 operation, UINT8 fragment_prefrence,
1261                                       UINT8 data_len, UINT8 *p_data)
1262 {
1263     BT_HDR *p;
1264     UINT8 *pp;
1265     HCI_TRACE_EVENT("%s, adv_handle = %d, operation = %d, fragment_prefrence = %d,\
1266                      data_len = %d", __func__, adv_handle, operation, fragment_prefrence, data_len);
1267     ext_adv_flag = true;
1268 
1269     HCIC_BLE_CMD_CREATED(p, pp,  data_len + 4);
1270     UINT16_TO_STREAM(pp, HCI_BLE_SET_EXT_ADV_DATA);
1271     UINT8_TO_STREAM(pp, data_len + 4);
1272     UINT8_TO_STREAM(pp, adv_handle);
1273     UINT8_TO_STREAM(pp, operation);
1274     UINT8_TO_STREAM(pp, fragment_prefrence);
1275 
1276     if (p_data != NULL && data_len > 0) {
1277         if (data_len > HCIC_PARAM_SIZE_EXT_ADV_WRITE_DATA) {
1278             data_len = HCIC_PARAM_SIZE_EXT_ADV_WRITE_DATA;
1279         }
1280 
1281         UINT8_TO_STREAM (pp, data_len);
1282 
1283         ARRAY_TO_STREAM (pp, p_data, data_len);
1284     } else {
1285         return FALSE;
1286     }
1287     uint8_t status = btu_hcif_send_cmd_sync (LOCAL_BR_EDR_CONTROLLER_ID, p);
1288     return status;
1289 
1290 }
1291 
btsnd_hcic_ble_set_ext_adv_scan_rsp_data(UINT8 adv_handle,UINT8 operation,UINT8 fragment_prefrence,UINT8 data_len,UINT8 * p_data)1292 UINT8 btsnd_hcic_ble_set_ext_adv_scan_rsp_data(UINT8 adv_handle,
1293                                                           UINT8 operation, UINT8 fragment_prefrence,
1294                                                           UINT8 data_len, UINT8 *p_data)
1295 {
1296     BT_HDR *p;
1297     UINT8 *pp;
1298 
1299     HCI_TRACE_EVENT("%s, adv_handle = %d, operation = %d, fragment_prefrence = %d,\n\
1300                      data_len = %d", __func__, adv_handle, operation, fragment_prefrence, data_len);
1301 
1302     HCIC_BLE_CMD_CREATED(p, pp,  data_len + 4);
1303 
1304     UINT16_TO_STREAM(pp, HCI_BLE_SET_EXT_SCAN_RSP_DATA);
1305     UINT8_TO_STREAM(pp, data_len + 4);
1306     UINT8_TO_STREAM(pp, adv_handle);
1307     UINT8_TO_STREAM(pp, operation);
1308     UINT8_TO_STREAM(pp, fragment_prefrence);
1309 
1310     memset(pp, 0, data_len);
1311 
1312     if (p_data != NULL && data_len > 0) {
1313         if (data_len > HCIC_PARAM_SIZE_EXT_ADV_WRITE_DATA) {
1314             data_len = HCIC_PARAM_SIZE_EXT_ADV_WRITE_DATA;
1315         }
1316 
1317         UINT8_TO_STREAM (pp, data_len);
1318 
1319         ARRAY_TO_STREAM (pp, p_data, data_len);
1320     } else {
1321         return FALSE;
1322     }
1323 
1324     return btu_hcif_send_cmd_sync (LOCAL_BR_EDR_CONTROLLER_ID, p);
1325 
1326 }
1327 
btsnd_hcic_ble_ext_adv_enable(UINT8 enable,UINT8 num_of_sets,UINT8 * adv_handle,UINT16 * duration,UINT8 * max_adv_evt)1328 UINT8 btsnd_hcic_ble_ext_adv_enable(UINT8 enable, UINT8 num_of_sets, UINT8 *adv_handle,
1329                                                        UINT16 *duration, UINT8 *max_adv_evt)
1330 {
1331     BT_HDR *p;
1332     UINT8 *pp;
1333     UINT8 ext_adv_size = num_of_sets*4 + 2;
1334     HCIC_BLE_CMD_CREATED(p, pp,  ext_adv_size);
1335 
1336     HCI_TRACE_EVENT("%s, enable = %d, num_of_sets = %d", __func__, enable, num_of_sets);
1337 
1338     for (int k = 0; k < num_of_sets; k++) {
1339         HCI_TRACE_EVENT("adv_handle[%d] = %d, duration[%d] = %d, max_adv_evt[%d] = %d", k, adv_handle[k],
1340             k, duration[k], k, max_adv_evt[k]);
1341     }
1342 
1343     UINT16_TO_STREAM(pp, HCI_BLE_SET_EXT_ADV_ENABLE);
1344     UINT8_TO_STREAM(pp, ext_adv_size);
1345     UINT8_TO_STREAM(pp, enable);
1346     UINT8_TO_STREAM(pp, num_of_sets);
1347 
1348     for (int i = 0; i < num_of_sets; i++) {
1349         UINT8_TO_STREAM(pp, adv_handle[i]);
1350         UINT16_TO_STREAM(pp, duration[i]);
1351         UINT8_TO_STREAM(pp, max_adv_evt[i]);
1352     }
1353 
1354     return btu_hcif_send_cmd_sync (LOCAL_BR_EDR_CONTROLLER_ID, p);
1355 }
1356 
btsnd_hcic_ble_read_max_adv_len(void)1357 UINT8 btsnd_hcic_ble_read_max_adv_len(void)
1358 {
1359     BT_HDR *p;
1360     UINT8 *pp;
1361     HCI_TRACE_EVENT("%s", __func__);
1362 
1363     HCIC_BLE_CMD_CREATED(p, pp,  HCIC_PARAM_SIZE_READ_MAX_ADV_SIZE + 1);
1364 
1365     UINT16_TO_STREAM(pp, HCI_BLE_RD_MAX_ADV_DATA_LEN);
1366     UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_READ_MAX_ADV_SIZE);
1367 
1368     return btu_hcif_send_cmd_sync (LOCAL_BR_EDR_CONTROLLER_ID, p);
1369 }
1370 
btsnd_hcic_ble_read_num_support_adv_set(void)1371 UINT8 btsnd_hcic_ble_read_num_support_adv_set(void)
1372 {
1373     BT_HDR *p;
1374     UINT8 *pp;
1375     HCI_TRACE_EVENT("%s", __func__);
1376 
1377     HCIC_BLE_CMD_CREATED(p, pp,  HCIC_PARAM_SIZE_NUM_SUPPORT_ADV_SET + 1);
1378 
1379     UINT16_TO_STREAM(pp, HCI_BLE_RD_NUM_OF_ADV_SETS);
1380     UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_NUM_SUPPORT_ADV_SET);
1381 
1382     return btu_hcif_send_cmd_sync (LOCAL_BR_EDR_CONTROLLER_ID, p);
1383 }
1384 
btsnd_hcic_ble_remove_adv_set(UINT8 adv_handle)1385 UINT8 btsnd_hcic_ble_remove_adv_set(UINT8 adv_handle)
1386 {
1387     BT_HDR *p;
1388     UINT8 *pp;
1389     HCI_TRACE_EVENT("%s, adv_handle = %d", __func__, adv_handle);
1390 
1391     HCIC_BLE_CMD_CREATED(p, pp,  HCIC_PARAM_SIZE_REMOVE_ADV_SET + 1);
1392 
1393     UINT16_TO_STREAM(pp, HCI_BLE_REMOVE_ADV_SET);
1394     UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_REMOVE_ADV_SET);
1395     UINT8_TO_STREAM(pp, adv_handle);
1396 
1397     return btu_hcif_send_cmd_sync(LOCAL_BR_EDR_CONTROLLER_ID, p);
1398 }
1399 
btsnd_hcic_ble_clear_adv_set(void)1400 UINT8 btsnd_hcic_ble_clear_adv_set(void)
1401 {
1402     BT_HDR *p;
1403     UINT8 *pp;
1404     HCI_TRACE_EVENT("%s", __func__);
1405 
1406     HCIC_BLE_CMD_CREATED(p, pp,  HCIC_PARAM_SIZE_CLEAR_ADV_SET + 1);
1407 
1408     UINT16_TO_STREAM(pp, HCI_BLE_CLEAR_ADV_SETS);
1409     UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_CLEAR_ADV_SET);
1410 
1411     return btu_hcif_send_cmd_sync(LOCAL_BR_EDR_CONTROLLER_ID, p);
1412 
1413 }
1414 
btsnd_hcic_ble_set_periodic_adv_params(UINT8 adv_handle,UINT16 interval_min,UINT16 interval_max,UINT8 propertics)1415 UINT8 btsnd_hcic_ble_set_periodic_adv_params(UINT8 adv_handle,
1416                                                                      UINT16 interval_min,
1417                                                                      UINT16 interval_max,
1418                                                                      UINT8 propertics)
1419 {
1420     BT_HDR *p;
1421     UINT8 *pp;
1422     HCI_TRACE_EVENT("%s, adv_handle = %d, interval_min = %d, interval_max = %d, propertics = %d",
1423                    __func__, adv_handle, interval_min, interval_max, propertics);
1424 
1425     HCIC_BLE_CMD_CREATED(p, pp,  HCIC_PARAM_SIZE_SET_PERIODIC_ADV_PARAMS);
1426 
1427     UINT16_TO_STREAM(pp, HCI_BLE_SET_PERIOD_ADV_PARAMS);
1428     UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_SET_PERIODIC_ADV_PARAMS);
1429 
1430     UINT8_TO_STREAM(pp, adv_handle);
1431     UINT16_TO_STREAM(pp, interval_min);
1432     UINT16_TO_STREAM(pp, interval_max);
1433     UINT16_TO_STREAM(pp, propertics);
1434 
1435     return btu_hcif_send_cmd_sync(LOCAL_BR_EDR_CONTROLLER_ID, p);
1436 
1437 }
1438 
btsnd_hcic_ble_set_periodic_adv_data(UINT8 adv_handle,UINT8 operation,UINT8 len,UINT8 * p_data)1439 UINT8 btsnd_hcic_ble_set_periodic_adv_data(UINT8 adv_handle,
1440                                                                   UINT8 operation,
1441                                                                   UINT8 len,
1442                                                                   UINT8 *p_data)
1443 {
1444     BT_HDR *p;
1445     UINT8 *pp;
1446     HCI_TRACE_EVENT("%s, adv_handle = %d, operation = %d, len = %d",
1447                        __func__, adv_handle, operation, len);
1448 
1449     HCIC_BLE_CMD_CREATED(p, pp,  len + 3);
1450 
1451     UINT16_TO_STREAM(pp, HCI_BLE_SET_PERIOD_ADV_DATA);
1452     UINT8_TO_STREAM(pp, len + 3);
1453     UINT8_TO_STREAM(pp, adv_handle);
1454     UINT8_TO_STREAM(pp, operation);
1455 
1456     //memset(pp, 0, len);
1457 
1458     if (p_data != NULL && len > 0) {
1459         if (len > HCIC_PARAM_SIZE_WRITE_PERIODIC_ADV_DATA) {
1460             len = HCIC_PARAM_SIZE_WRITE_PERIODIC_ADV_DATA;
1461         }
1462 
1463         UINT8_TO_STREAM (pp, len);
1464 
1465         ARRAY_TO_STREAM (pp, p_data, len);
1466     } else {
1467         return FALSE;
1468     }
1469 
1470     return btu_hcif_send_cmd_sync(LOCAL_BR_EDR_CONTROLLER_ID, p);
1471 
1472 }
1473 
btsnd_hcic_ble_periodic_adv_enable(UINT8 enable,UINT8 adv_handle)1474 UINT8 btsnd_hcic_ble_periodic_adv_enable(UINT8 enable, UINT8 adv_handle)
1475 {
1476     BT_HDR *p;
1477     UINT8 *pp;
1478     HCI_TRACE_EVENT("%s, enable = %d, adv_handle = %d",
1479                            __func__, enable, adv_handle);
1480 
1481     HCIC_BLE_CMD_CREATED(p, pp,  HCIC_PARAM_SIZE_PERIODIC_ADV_ENABLE);
1482 
1483     UINT16_TO_STREAM(pp, HCI_BLE_SET_PERIOD_ADV_ENABLE);
1484     UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_PERIODIC_ADV_ENABLE);
1485     UINT8_TO_STREAM(pp, enable);
1486     UINT8_TO_STREAM(pp, adv_handle);
1487 
1488     return btu_hcif_send_cmd_sync(LOCAL_BR_EDR_CONTROLLER_ID, p);
1489 
1490 }
1491 
btsnd_hcic_ble_set_ext_scan_params(UINT8 own_addr_type,UINT8 filter_policy,UINT8 phy_mask,UINT8 phy_count,tHCI_EXT_SCAN_PARAMS * params)1492 UINT8 btsnd_hcic_ble_set_ext_scan_params(UINT8 own_addr_type, UINT8 filter_policy,
1493                                                                UINT8 phy_mask, UINT8 phy_count,
1494                                                                tHCI_EXT_SCAN_PARAMS *params)
1495 {
1496     BT_HDR *p;
1497     UINT8 *pp;
1498     HCI_TRACE_EVENT("%s, own_addr_type = %d, filter_policy = %d, phy_mask = %d, phy_count = %d",
1499                            __func__, own_addr_type, filter_policy, phy_mask, phy_count);
1500     UINT8 params_size = HCIC_PARAM_SIZE_SET_EXT_SCAN_PARAMS + phy_count*5;
1501 
1502     HCIC_BLE_CMD_CREATED(p, pp,  params_size);
1503 
1504     UINT16_TO_STREAM(pp, HCI_BLE_SET_EXT_SCAN_PARAMS);
1505     UINT8_TO_STREAM(pp, params_size);
1506     UINT8_TO_STREAM(pp, own_addr_type);
1507     UINT8_TO_STREAM(pp, filter_policy);
1508     UINT8_TO_STREAM(pp, phy_mask);
1509 
1510     for (int i = 0; i < phy_count; i++) {
1511         UINT8_TO_STREAM(pp, params[i].scan_type);
1512         UINT16_TO_STREAM(pp, params[i].scan_interval);
1513         UINT16_TO_STREAM(pp, params[i].scan_window);
1514     }
1515 
1516     return btu_hcif_send_cmd_sync(LOCAL_BR_EDR_CONTROLLER_ID, p);
1517 
1518 }
1519 
btsnd_hcic_ble_ext_scan_enable(UINT8 enable,UINT8 filter_dups,UINT16 duration,UINT16 period)1520 UINT8 btsnd_hcic_ble_ext_scan_enable(UINT8 enable, UINT8 filter_dups,
1521                                                          UINT16 duration, UINT16 period)
1522 {
1523     BT_HDR *p;
1524     UINT8 *pp;
1525     HCI_TRACE_EVENT("%s, enable = %d, filter_dups = %d, duration = %d, period = %d",
1526                                __func__, enable, filter_dups, duration, period);
1527 
1528     HCIC_BLE_CMD_CREATED(p, pp,  HCIC_PARAM_SIZE_EXT_SCAN_ENABLE);
1529 
1530     UINT16_TO_STREAM(pp, HCI_BLE_SET_EXT_SCAN_ENABLE);
1531     UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_EXT_SCAN_ENABLE);
1532     UINT8_TO_STREAM(pp, enable);
1533     UINT8_TO_STREAM(pp, filter_dups);
1534     UINT16_TO_STREAM(pp, duration);
1535     UINT16_TO_STREAM(pp, period);
1536 
1537     return btu_hcif_send_cmd_sync(LOCAL_BR_EDR_CONTROLLER_ID, p);
1538 }
1539 
btsnd_hcic_ble_create_ext_conn(tHCI_CreatExtConn * p_conn)1540 BOOLEAN btsnd_hcic_ble_create_ext_conn(tHCI_CreatExtConn *p_conn)
1541 {
1542     BT_HDR *p;
1543     UINT8 *pp;
1544     tHCI_ExtConnParams *params;
1545     HCI_TRACE_EVENT("%s", __func__);
1546     uint8_t size = HCIC_PARAM_SIZE_EXT_CONN_CREATE_BASE;
1547 
1548     if (p_conn->init_phy_mask & 0x01) {
1549         size += sizeof(tHCI_ExtConnParams);
1550     }
1551 
1552     if (p_conn->init_phy_mask & 0x02) {
1553         size += sizeof(tHCI_ExtConnParams);
1554     }
1555 
1556     if (p_conn->init_phy_mask & 0x04) {
1557         size += sizeof(tHCI_ExtConnParams);
1558     }
1559 
1560     HCIC_BLE_CMD_CREATED(p, pp,  size);
1561 
1562     UINT16_TO_STREAM(pp, HCI_BLE_EXT_CREATE_CONN);
1563     UINT8_TO_STREAM(pp, size);
1564     UINT8_TO_STREAM(pp, p_conn->filter_policy);
1565     UINT8_TO_STREAM(pp, p_conn->own_addr_type);
1566     UINT8_TO_STREAM(pp, p_conn->peer_addr_type);
1567     BDADDR_TO_STREAM(pp, p_conn->peer_addr);
1568     UINT8_TO_STREAM(pp, p_conn->init_phy_mask);
1569 
1570     if (p_conn->init_phy_mask & 0x01) {
1571         params = &p_conn->params[0];
1572         UINT16_TO_STREAM(pp, params->scan_interval);
1573         UINT16_TO_STREAM(pp, params->scan_window);
1574         UINT16_TO_STREAM(pp, params->conn_interval_min);
1575         UINT16_TO_STREAM(pp, params->conn_interval_max);
1576         UINT16_TO_STREAM(pp, params->conn_latency);
1577         UINT16_TO_STREAM(pp, params->sup_timeout);
1578         UINT16_TO_STREAM(pp, BLE_CE_LEN_MIN);
1579         UINT16_TO_STREAM(pp, BLE_CE_LEN_MIN);
1580     }
1581 
1582     if (p_conn->init_phy_mask & 0x02) {
1583         params = &p_conn->params[1];
1584         UINT16_TO_STREAM(pp, params->scan_interval);
1585         UINT16_TO_STREAM(pp, params->scan_window);
1586         UINT16_TO_STREAM(pp, params->conn_interval_min);
1587         UINT16_TO_STREAM(pp, params->conn_interval_max);
1588         UINT16_TO_STREAM(pp, params->conn_latency);
1589         UINT16_TO_STREAM(pp, params->sup_timeout);
1590         UINT16_TO_STREAM(pp, BLE_CE_LEN_MIN);
1591         UINT16_TO_STREAM(pp, BLE_CE_LEN_MIN);
1592     }
1593 
1594     if (p_conn->init_phy_mask & 0x04) {
1595         params = &p_conn->params[2];
1596         UINT16_TO_STREAM(pp, params->scan_interval);
1597         UINT16_TO_STREAM(pp, params->scan_window);
1598         UINT16_TO_STREAM(pp, params->conn_interval_min);
1599         UINT16_TO_STREAM(pp, params->conn_interval_max);
1600         UINT16_TO_STREAM(pp, params->conn_latency);
1601         UINT16_TO_STREAM(pp, params->sup_timeout);
1602         UINT16_TO_STREAM(pp, BLE_CE_LEN_MIN);
1603         UINT16_TO_STREAM(pp, BLE_CE_LEN_MIN);
1604     }
1605 
1606     btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
1607     return TRUE;
1608 
1609 }
1610 
btsnd_hcic_ble_periodic_adv_create_sync(UINT8 filter_policy,UINT8 adv_sid,UINT8 adv_addr_type,BD_ADDR adv_addr,UINT16 sync_timeout,UINT8 unused)1611 BOOLEAN btsnd_hcic_ble_periodic_adv_create_sync(UINT8 filter_policy, UINT8 adv_sid,
1612                                                                        UINT8 adv_addr_type, BD_ADDR adv_addr,
1613                                                                        UINT16 sync_timeout, UINT8 unused)
1614 {
1615     BT_HDR *p;
1616     UINT8 *pp;
1617     HCI_TRACE_EVENT("%s, filter_policy = %d, adv_sid = %d, adv_addr_type = %d, sync_timeout = %d, unused = %d",
1618                                    __func__, filter_policy, adv_sid, adv_addr_type, sync_timeout, unused);
1619 
1620     HCI_TRACE_EVENT("addr %02x %02x %02x %02x %02x %02x", adv_addr[0], adv_addr[1], adv_addr[2], adv_addr[3], adv_addr[4], adv_addr[5]);
1621     uint16_t skip = 0;
1622     HCIC_BLE_CMD_CREATED(p, pp,  HCIC_PARAM_SIZE_PERIODIC_ADV_CREATE_SYNC + 2);
1623 
1624     UINT16_TO_STREAM(pp, HCI_BLE_PERIOD_ADV_CREATE_SYNC);
1625     UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_PERIODIC_ADV_CREATE_SYNC + 2);
1626     UINT8_TO_STREAM(pp, filter_policy);
1627     UINT8_TO_STREAM(pp, adv_sid);
1628     UINT8_TO_STREAM(pp, adv_addr_type);
1629     BDADDR_TO_STREAM(pp, adv_addr);
1630     UINT16_TO_STREAM(pp, skip);
1631     UINT16_TO_STREAM(pp, sync_timeout);
1632     UINT8_TO_STREAM(pp, unused);
1633 
1634     btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
1635     return TRUE;
1636 }
1637 
btsnd_hcic_ble_periodic_adv_create_sync_cancel(void)1638 UINT8 btsnd_hcic_ble_periodic_adv_create_sync_cancel(void)
1639 {
1640     BT_HDR *p;
1641     UINT8 *pp;
1642     HCI_TRACE_EVENT("%s", __func__);
1643 
1644     HCIC_BLE_CMD_CREATED(p, pp,  HCIC_PARAM_SIZE_PERIODIC_ADV_CREATE_SYNC_CANCEL);
1645 
1646     UINT16_TO_STREAM(pp, HCI_BLE_PERIOD_ADV_CREATE_SYNC_CANCEL);
1647     UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_PERIODIC_ADV_CREATE_SYNC_CANCEL);
1648 
1649     return btu_hcif_send_cmd_sync(LOCAL_BR_EDR_CONTROLLER_ID, p);
1650 }
1651 
btsnd_hcic_ble_periodic_adv_term_sync(UINT16 sync_handle)1652 UINT8 btsnd_hcic_ble_periodic_adv_term_sync(UINT16 sync_handle)
1653 {
1654     BT_HDR *p;
1655     UINT8 *pp;
1656     HCI_TRACE_EVENT("%s, sync_handle = %d", __func__, sync_handle);
1657 
1658     HCIC_BLE_CMD_CREATED(p, pp,  HCIC_PARAM_SIZE_PERIODIC_ADV_TERM_SYNC);
1659 
1660     UINT16_TO_STREAM(pp, HCI_BLE_PERIOD_ADV_TERM_SYNC);
1661     UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_PERIODIC_ADV_TERM_SYNC);
1662 
1663     UINT16_TO_STREAM(pp, sync_handle);
1664 
1665     return btu_hcif_send_cmd_sync(LOCAL_BR_EDR_CONTROLLER_ID, p);
1666 }
1667 
btsnd_hcic_ble_add_dev_to_periodic_adv_list(UINT8 adv_addr_type,BD_ADDR adv_addr,UINT8 adv_sid)1668 UINT8 btsnd_hcic_ble_add_dev_to_periodic_adv_list(UINT8 adv_addr_type, BD_ADDR adv_addr,
1669                                                                              UINT8 adv_sid)
1670 {
1671     BT_HDR *p;
1672     UINT8 *pp;
1673     HCI_TRACE_EVENT("%s, adv_addr_type = %d, adv_sid = %d", __func__, adv_addr_type, adv_sid);
1674     esp_log_buffer_hex_internal("addr", adv_addr, sizeof(BD_ADDR), ESP_LOG_WARN);
1675 
1676     HCIC_BLE_CMD_CREATED(p, pp,  HCIC_PARAM_SIZE_ADD_DEV_TO_PERIODIC_ADV_LIST);
1677 
1678     UINT16_TO_STREAM(pp, HCI_BLE_ADV_DEV_TO_PERIOD_ADV_LIST);
1679     UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_ADD_DEV_TO_PERIODIC_ADV_LIST);
1680     UINT8_TO_STREAM(pp, adv_addr_type);
1681     BDADDR_TO_STREAM(pp, adv_addr);
1682     UINT8_TO_STREAM(pp, adv_sid);
1683 
1684     return btu_hcif_send_cmd_sync(LOCAL_BR_EDR_CONTROLLER_ID, p);
1685 }
1686 
btsnd_hcic_ble_rm_dev_from_periodic_adv_list(UINT8 adv_addr_type,BD_ADDR adv_addr,UINT8 adv_sid)1687 UINT8 btsnd_hcic_ble_rm_dev_from_periodic_adv_list(UINT8 adv_addr_type, BD_ADDR adv_addr,
1688                                                                              UINT8 adv_sid)
1689 {
1690     BT_HDR *p;
1691     UINT8 *pp;
1692     HCI_TRACE_EVENT("%s, adv_addr_type = %d, adv_sid = %d", __func__, adv_addr_type, adv_sid);
1693     esp_log_buffer_hex_internal("addr", adv_addr, sizeof(BD_ADDR), ESP_LOG_WARN);
1694 
1695     HCIC_BLE_CMD_CREATED(p, pp,  HCIC_PARAM_SIZE_RM_DEV_FROM_PERIODIC_ADV_LIST);
1696 
1697     UINT16_TO_STREAM(pp, HCI_BLE_REMOVE_DEV_FROM_PERIOD_ADV_LIST);
1698     UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_RM_DEV_FROM_PERIODIC_ADV_LIST);
1699     UINT8_TO_STREAM(pp, adv_addr_type);
1700     BDADDR_TO_STREAM(pp, adv_addr);
1701     UINT8_TO_STREAM(pp, adv_sid);
1702 
1703     return btu_hcif_send_cmd_sync(LOCAL_BR_EDR_CONTROLLER_ID, p);
1704 
1705 }
1706 
btsnd_hcic_ble_clear_periodic_adv_list(void)1707 UINT8 btsnd_hcic_ble_clear_periodic_adv_list(void)
1708 {
1709     BT_HDR *p;
1710     UINT8 *pp;
1711     HCI_TRACE_EVENT("%s", __func__);
1712 
1713     HCIC_BLE_CMD_CREATED(p, pp,  HCIC_PARAM_SIZE_CLEAR_PERIODIC_ADV_LIST);
1714 
1715     UINT16_TO_STREAM(pp, HCI_BLE_CLEAR_PERIOD_ADV_LIST);
1716     UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_CLEAR_PERIODIC_ADV_LIST);
1717 
1718     return btu_hcif_send_cmd_sync(LOCAL_BR_EDR_CONTROLLER_ID, p);
1719 }
1720 
btsnd_hcic_ble_read_periodic_adv_list_size(void)1721 UINT8 btsnd_hcic_ble_read_periodic_adv_list_size(void)
1722 {
1723     BT_HDR *p;
1724     UINT8 *pp;
1725     HCI_TRACE_EVENT("%s", __func__);
1726 
1727     HCIC_BLE_CMD_CREATED(p, pp,  HCIC_PARAM_SIZE_READ_PERIODIC_ADV_LIST);
1728 
1729     UINT16_TO_STREAM(pp, HCI_BLE_RD_PERIOD_ADV_LIST_SIZE);
1730     UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_READ_PERIODIC_ADV_LIST);
1731 
1732     return btu_hcif_send_cmd_sync(LOCAL_BR_EDR_CONTROLLER_ID, p);
1733 }
1734 
btsnd_hcic_ble_read_trans_power(void)1735 UINT8 btsnd_hcic_ble_read_trans_power(void)
1736 {
1737     BT_HDR *p;
1738     UINT8 *pp;
1739     HCI_TRACE_EVENT("%s", __func__);
1740 
1741     HCIC_BLE_CMD_CREATED(p, pp,  HCIC_PARAM_SIZE_READ_TRANS_POWER);
1742 
1743     UINT16_TO_STREAM(pp, HCI_BLE_RD_TRANSMIT_POWER);
1744     UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_READ_TRANS_POWER);
1745 
1746     return btu_hcif_send_cmd_sync(LOCAL_BR_EDR_CONTROLLER_ID, p);
1747 }
1748 
btsnd_hcic_ble_read_rf_path_compensation(void)1749 UINT8 btsnd_hcic_ble_read_rf_path_compensation(void)
1750 {
1751     BT_HDR *p;
1752     UINT8 *pp;
1753     HCI_TRACE_EVENT("%s", __func__);
1754 
1755     HCIC_BLE_CMD_CREATED(p, pp,  HCIC_PARAM_SIZE_READ_RF_PATH_COMPENSATION);
1756 
1757     UINT16_TO_STREAM(pp, HCI_BLE_RD_RF_PATH_COMPENSATION);
1758     UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_READ_RF_PATH_COMPENSATION);
1759 
1760     return btu_hcif_send_cmd_sync(LOCAL_BR_EDR_CONTROLLER_ID, p);
1761 }
1762 
btsnd_hcic_ble_write_rf_path_compensation(UINT16 rf_tx_path,UINT16 rf_rx_path)1763 UINT8 btsnd_hcic_ble_write_rf_path_compensation(UINT16 rf_tx_path, UINT16 rf_rx_path)
1764 {
1765     BT_HDR *p;
1766     UINT8 *pp;
1767     HCI_TRACE_EVENT("%s, rf_tx_path = %d, rf_rx_path = %d", __func__, rf_tx_path, rf_rx_path);
1768 
1769     HCIC_BLE_CMD_CREATED(p, pp, HCIC_PARAM_SIZE_WRITE_RF_PATH_COMPENSATION);
1770 
1771     pp = (UINT8 *)(p + 1);
1772 
1773     p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_WRITE_RF_PATH_COMPENSATION;
1774     p->offset = 0;
1775 
1776     UINT16_TO_STREAM(pp, HCI_BLE_WR_RF_PATH_COMPENSATION);
1777     UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_WRITE_RF_PATH_COMPENSATION);
1778 
1779     UINT16_TO_STREAM(pp, rf_tx_path);
1780     UINT16_TO_STREAM(pp, rf_tx_path);
1781 
1782     return btu_hcif_send_cmd_sync(LOCAL_BR_EDR_CONTROLLER_ID, p);
1783 }
1784 #endif // #if (BLE_50_FEATURE_SUPPORT == TRUE)
1785 
1786 #if (BLE_FEAT_PERIODIC_ADV_SYNC_TRANSFER == TRUE)
btsnd_hcic_ble_set_periodic_adv_recv_enable(UINT16 sync_handle,UINT8 enable)1787 UINT8 btsnd_hcic_ble_set_periodic_adv_recv_enable(UINT16 sync_handle, UINT8 enable)
1788 {
1789     BT_HDR *p;
1790     UINT8 *pp;
1791 
1792     HCIC_BLE_CMD_CREATED(p, pp, 3);
1793 
1794     pp = (UINT8 *)(p + 1);
1795 
1796     UINT16_TO_STREAM(pp, HCI_BLE_SET_PERIOD_ADV_RECV_ENABLE);
1797     UINT8_TO_STREAM(pp, 3);
1798 
1799     UINT16_TO_STREAM(pp, sync_handle);
1800     UINT8_TO_STREAM(pp, enable);
1801 
1802     return btu_hcif_send_cmd_sync(LOCAL_BR_EDR_CONTROLLER_ID, p);
1803 }
1804 
btsnd_hcic_ble_periodic_adv_sync_trans(UINT16 conn_handle,UINT16 service_data,UINT16 sync_handle)1805 UINT8 btsnd_hcic_ble_periodic_adv_sync_trans(UINT16 conn_handle, UINT16 service_data, UINT16 sync_handle)
1806 {
1807     BT_HDR *p;
1808     UINT8 *pp;
1809 
1810     HCIC_BLE_CMD_CREATED(p, pp, 6);
1811 
1812     pp = (UINT8 *)(p + 1);
1813 
1814     UINT16_TO_STREAM(pp, HCI_BLE_PERIOD_ADV_SYNC_TRANS);
1815     UINT8_TO_STREAM(pp, 6);
1816 
1817     UINT16_TO_STREAM(pp, conn_handle);
1818     UINT16_TO_STREAM(pp, service_data);
1819     UINT16_TO_STREAM(pp, sync_handle);
1820 
1821     return btu_hcif_send_cmd_sync(LOCAL_BR_EDR_CONTROLLER_ID, p);
1822 }
1823 
btsnd_hcic_ble_periodic_adv_set_info_trans(UINT16 conn_handle,UINT16 service_data,UINT8 adv_handle)1824 UINT8 btsnd_hcic_ble_periodic_adv_set_info_trans(UINT16 conn_handle, UINT16 service_data, UINT8 adv_handle)
1825 {
1826     BT_HDR *p;
1827     UINT8 *pp;
1828 
1829     HCI_TRACE_DEBUG("%s conn handle %x, adv handle %x", __func__, conn_handle, adv_handle);
1830 
1831     HCIC_BLE_CMD_CREATED(p, pp, 5);
1832 
1833     pp = (UINT8 *)(p + 1);
1834 
1835     UINT16_TO_STREAM(pp, HCI_BLE_PERIOD_ADV_SET_INFO_TRANS);
1836     UINT8_TO_STREAM(pp, 5);
1837 
1838     UINT16_TO_STREAM(pp, conn_handle);
1839     UINT16_TO_STREAM(pp, service_data);
1840     UINT8_TO_STREAM(pp, adv_handle);
1841 
1842     return btu_hcif_send_cmd_sync(LOCAL_BR_EDR_CONTROLLER_ID, p);
1843 }
1844 
btsnd_hcic_ble_set_periodic_adv_sync_trans_params(UINT16 conn_handle,UINT8 mode,UINT16 skip,UINT16 sync_timeout,UINT8 cte_type)1845 UINT8 btsnd_hcic_ble_set_periodic_adv_sync_trans_params(UINT16 conn_handle, UINT8 mode, UINT16 skip, UINT16 sync_timeout, UINT8 cte_type)
1846 {
1847     BT_HDR *p;
1848     UINT8 *pp;
1849 
1850     HCI_TRACE_DEBUG("%s conn handle %x, mode %x, sync timeout %x", __func__, conn_handle, mode, sync_timeout);
1851 
1852     HCIC_BLE_CMD_CREATED(p, pp, 8);
1853 
1854     pp = (UINT8 *)(p + 1);
1855 
1856     UINT16_TO_STREAM(pp, HCI_BLE_SET_PERIOD_ADV_SYNC_TRANS_PARAMS);
1857     UINT8_TO_STREAM(pp, 8);
1858 
1859     UINT16_TO_STREAM(pp, conn_handle);
1860     UINT8_TO_STREAM(pp, mode);
1861     UINT16_TO_STREAM(pp, skip);
1862     UINT16_TO_STREAM(pp, sync_timeout);
1863     UINT8_TO_STREAM(pp, cte_type);
1864 
1865     return btu_hcif_send_cmd_sync(LOCAL_BR_EDR_CONTROLLER_ID, p);
1866 }
1867 #endif // #if (BLE_FEAT_PERIODIC_ADV_SYNC_TRANSFER == TRUE)
1868 #endif
1869