Home | History | Annotate | Download | only in hcic
      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 "bt_target.h"
     27 #include "gki.h"
     28 #include "hcidefs.h"
     29 #include "hcimsgs.h"
     30 #include "hcidefs.h"
     31 #include "btu.h"
     32 
     33 #include <stddef.h>
     34 #include <string.h>
     35 
     36 #if (defined BLE_INCLUDED) && (BLE_INCLUDED == TRUE)
     37 
     38 BOOLEAN btsnd_hcic_ble_set_evt_mask (BT_EVENT_MASK event_mask)
     39 {
     40     BT_HDR *p;
     41     UINT8 *pp;
     42 
     43     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_SET_EVENT_MASK)) == NULL)
     44         return (FALSE);
     45 
     46     pp = (UINT8 *)(p + 1);
     47 
     48     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_SET_EVENT_MASK;
     49     p->offset = 0;
     50 
     51     UINT16_TO_STREAM (pp, HCI_BLE_SET_EVENT_MASK);
     52     UINT8_TO_STREAM  (pp, HCIC_PARAM_SIZE_SET_EVENT_MASK);
     53     ARRAY8_TO_STREAM (pp, event_mask);
     54 
     55     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID,  p);
     56     return (TRUE);
     57 }
     58 
     59 
     60 BOOLEAN btsnd_hcic_ble_read_buffer_size (void)
     61 {
     62     BT_HDR *p;
     63     UINT8 *pp;
     64 
     65     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_READ_CMD)) == NULL)
     66         return (FALSE);
     67 
     68     pp = (UINT8 *)(p + 1);
     69 
     70     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_READ_CMD;
     71     p->offset = 0;
     72 
     73     UINT16_TO_STREAM (pp, HCI_BLE_READ_BUFFER_SIZE);
     74     UINT8_TO_STREAM  (pp,  HCIC_PARAM_SIZE_READ_CMD);
     75 
     76     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID,  p);
     77     return (TRUE);
     78 }
     79 
     80 BOOLEAN btsnd_hcic_ble_read_local_spt_feat (void)
     81 {
     82     BT_HDR *p;
     83     UINT8 *pp;
     84 
     85     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_READ_CMD)) == NULL)
     86         return (FALSE);
     87 
     88     pp = (UINT8 *)(p + 1);
     89 
     90     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_READ_CMD;
     91     p->offset = 0;
     92 
     93     UINT16_TO_STREAM (pp, HCI_BLE_READ_LOCAL_SPT_FEAT);
     94     UINT8_TO_STREAM  (pp, HCIC_PARAM_SIZE_READ_CMD);
     95 
     96     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID,  p);
     97     return (TRUE);
     98 }
     99 
    100 BOOLEAN btsnd_hcic_ble_set_local_used_feat (UINT8 feat_set[8])
    101 {
    102     BT_HDR *p;
    103     UINT8 *pp;
    104 
    105     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_SET_USED_FEAT_CMD)) == NULL)
    106         return (FALSE);
    107 
    108     pp = (UINT8 *)(p + 1);
    109 
    110     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_SET_USED_FEAT_CMD;
    111     p->offset = 0;
    112 
    113     UINT16_TO_STREAM (pp, HCI_BLE_WRITE_LOCAL_SPT_FEAT);
    114     ARRAY_TO_STREAM (pp, feat_set, HCIC_PARAM_SIZE_SET_USED_FEAT_CMD);
    115 
    116     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID,  p);
    117     return (TRUE);
    118 }
    119 
    120 BOOLEAN btsnd_hcic_ble_set_random_addr (BD_ADDR random_bda)
    121 {
    122     BT_HDR *p;
    123     UINT8 *pp;
    124 
    125     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_WRITE_RANDOM_ADDR_CMD)) == NULL)
    126         return (FALSE);
    127 
    128     pp = (UINT8 *)(p + 1);
    129 
    130     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_WRITE_RANDOM_ADDR_CMD;
    131     p->offset = 0;
    132 
    133     UINT16_TO_STREAM (pp, HCI_BLE_WRITE_RANDOM_ADDR);
    134     UINT8_TO_STREAM  (pp,  HCIC_PARAM_SIZE_WRITE_RANDOM_ADDR_CMD);
    135 
    136     BDADDR_TO_STREAM (pp, random_bda);
    137 
    138     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID,  p);
    139     return (TRUE);
    140 }
    141 
    142 BOOLEAN btsnd_hcic_ble_write_adv_params (UINT16 adv_int_min, UINT16 adv_int_max,
    143                                        UINT8 adv_type, UINT8 addr_type_own,
    144                                        UINT8 addr_type_dir, BD_ADDR direct_bda,
    145                                        UINT8 channel_map, UINT8 scan_filter_policy)
    146 {
    147     BT_HDR *p;
    148     UINT8 *pp;
    149 
    150     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_BLE_WRITE_ADV_PARAMS)) == NULL)
    151         return (FALSE);
    152 
    153     pp = (UINT8 *)(p + 1);
    154 
    155     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_WRITE_ADV_PARAMS ;
    156     p->offset = 0;
    157 
    158     UINT16_TO_STREAM (pp, HCI_BLE_WRITE_ADV_PARAMS);
    159     UINT8_TO_STREAM  (pp, HCIC_PARAM_SIZE_BLE_WRITE_ADV_PARAMS );
    160 
    161     UINT16_TO_STREAM (pp, adv_int_min);
    162     UINT16_TO_STREAM (pp, adv_int_max);
    163     UINT8_TO_STREAM (pp, adv_type);
    164     UINT8_TO_STREAM (pp, addr_type_own);
    165     UINT8_TO_STREAM (pp, addr_type_dir);
    166     BDADDR_TO_STREAM (pp, direct_bda);
    167     UINT8_TO_STREAM (pp, channel_map);
    168     UINT8_TO_STREAM (pp, scan_filter_policy);
    169 
    170     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID,  p);
    171     return (TRUE);
    172 }
    173 BOOLEAN btsnd_hcic_ble_read_adv_chnl_tx_power (void)
    174 {
    175     BT_HDR *p;
    176     UINT8 *pp;
    177 
    178     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_READ_CMD)) == NULL)
    179         return (FALSE);
    180 
    181     pp = (UINT8 *)(p + 1);
    182 
    183     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_READ_CMD;
    184     p->offset = 0;
    185 
    186     UINT16_TO_STREAM (pp, HCI_BLE_READ_ADV_CHNL_TX_POWER);
    187     UINT8_TO_STREAM  (pp, HCIC_PARAM_SIZE_READ_CMD);
    188 
    189     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID,  p);
    190     return (TRUE);
    191 
    192 }
    193 
    194 BOOLEAN btsnd_hcic_ble_set_adv_data (UINT8 data_len, UINT8 *p_data)
    195 {
    196     BT_HDR *p;
    197     UINT8 *pp;
    198 
    199     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_BLE_WRITE_ADV_DATA + 1)) == NULL)
    200         return (FALSE);
    201 
    202     pp = (UINT8 *)(p + 1);
    203 
    204     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_WRITE_ADV_DATA + 1;
    205     p->offset = 0;
    206 
    207     UINT16_TO_STREAM (pp, HCI_BLE_WRITE_ADV_DATA);
    208     UINT8_TO_STREAM  (pp, HCIC_PARAM_SIZE_BLE_WRITE_ADV_DATA + 1);
    209 
    210     memset(pp, 0, HCIC_PARAM_SIZE_BLE_WRITE_ADV_DATA);
    211 
    212     if (p_data != NULL && data_len > 0)
    213     {
    214         if (data_len > HCIC_PARAM_SIZE_BLE_WRITE_ADV_DATA)
    215             data_len = HCIC_PARAM_SIZE_BLE_WRITE_ADV_DATA;
    216 
    217         UINT8_TO_STREAM (pp, data_len);
    218 
    219         ARRAY_TO_STREAM (pp, p_data, data_len);
    220     }
    221     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID,  p);
    222 
    223     return (TRUE);
    224 }
    225 BOOLEAN btsnd_hcic_ble_set_scan_rsp_data (UINT8 data_len, UINT8 *p_scan_rsp)
    226 {
    227     BT_HDR *p;
    228     UINT8 *pp;
    229 
    230     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_BLE_WRITE_SCAN_RSP + 1)) == NULL)
    231         return (FALSE);
    232 
    233     pp = (UINT8 *)(p + 1);
    234 
    235     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_WRITE_SCAN_RSP + 1;
    236     p->offset = 0;
    237 
    238     UINT16_TO_STREAM (pp, HCI_BLE_WRITE_SCAN_RSP_DATA);
    239     UINT8_TO_STREAM  (pp, HCIC_PARAM_SIZE_BLE_WRITE_SCAN_RSP + 1);
    240 
    241     memset(pp, 0, HCIC_PARAM_SIZE_BLE_WRITE_SCAN_RSP);
    242 
    243     if (p_scan_rsp != NULL && data_len > 0)
    244     {
    245 
    246         if (data_len > HCIC_PARAM_SIZE_BLE_WRITE_SCAN_RSP )
    247             data_len = HCIC_PARAM_SIZE_BLE_WRITE_SCAN_RSP;
    248 
    249         UINT8_TO_STREAM (pp, data_len);
    250 
    251         ARRAY_TO_STREAM (pp, p_scan_rsp, data_len);
    252     }
    253 
    254     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID,  p);
    255 
    256     return (TRUE);
    257 }
    258 
    259 BOOLEAN btsnd_hcic_ble_set_adv_enable (UINT8 adv_enable)
    260 {
    261     BT_HDR *p;
    262     UINT8 *pp;
    263 
    264     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_WRITE_ADV_ENABLE)) == NULL)
    265         return (FALSE);
    266 
    267     pp = (UINT8 *)(p + 1);
    268 
    269     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_WRITE_ADV_ENABLE;
    270     p->offset = 0;
    271 
    272     UINT16_TO_STREAM (pp, HCI_BLE_WRITE_ADV_ENABLE);
    273     UINT8_TO_STREAM  (pp, HCIC_PARAM_SIZE_WRITE_ADV_ENABLE);
    274 
    275     UINT8_TO_STREAM (pp, adv_enable);
    276 
    277     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID,  p);
    278     return (TRUE);
    279 }
    280 BOOLEAN btsnd_hcic_ble_set_scan_params (UINT8 scan_type,
    281                                           UINT16 scan_int, UINT16 scan_win,
    282                                           UINT8 addr_type_own, UINT8 scan_filter_policy)
    283 {
    284     BT_HDR *p;
    285     UINT8 *pp;
    286 
    287     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_BLE_WRITE_SCAN_PARAM)) == NULL)
    288         return (FALSE);
    289 
    290     pp = (UINT8 *)(p + 1);
    291 
    292     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_WRITE_SCAN_PARAM;
    293     p->offset = 0;
    294 
    295     UINT16_TO_STREAM (pp, HCI_BLE_WRITE_SCAN_PARAMS);
    296     UINT8_TO_STREAM  (pp, HCIC_PARAM_SIZE_BLE_WRITE_SCAN_PARAM);
    297 
    298     UINT8_TO_STREAM (pp, scan_type);
    299     UINT16_TO_STREAM (pp, scan_int);
    300     UINT16_TO_STREAM (pp, scan_win);
    301     UINT8_TO_STREAM (pp, addr_type_own);
    302     UINT8_TO_STREAM (pp, scan_filter_policy);
    303 
    304     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID,  p);
    305     return (TRUE);
    306 }
    307 
    308 BOOLEAN btsnd_hcic_ble_set_scan_enable (UINT8 scan_enable, UINT8 duplicate)
    309 {
    310     BT_HDR *p;
    311     UINT8 *pp;
    312 
    313     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_BLE_WRITE_SCAN_ENABLE)) == NULL)
    314         return (FALSE);
    315 
    316     pp = (UINT8 *)(p + 1);
    317 
    318     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_WRITE_SCAN_ENABLE;
    319     p->offset = 0;
    320 
    321     UINT16_TO_STREAM (pp, HCI_BLE_WRITE_SCAN_ENABLE);
    322     UINT8_TO_STREAM  (pp, HCIC_PARAM_SIZE_BLE_WRITE_SCAN_ENABLE);
    323 
    324     UINT8_TO_STREAM (pp, scan_enable);
    325     UINT8_TO_STREAM (pp, duplicate);
    326 
    327     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID,  p);
    328     return (TRUE);
    329 }
    330 
    331 /* link layer connection management commands */
    332 BOOLEAN btsnd_hcic_ble_create_ll_conn (UINT16 scan_int, UINT16 scan_win,
    333                                        UINT8 init_filter_policy,
    334                                        UINT8 addr_type_peer, BD_ADDR bda_peer,
    335                                        UINT8 addr_type_own,
    336                                        UINT16 conn_int_min, UINT16 conn_int_max,
    337                                        UINT16 conn_latency, UINT16 conn_timeout,
    338                                        UINT16 min_ce_len, UINT16 max_ce_len)
    339 {
    340     BT_HDR *p;
    341     UINT8 *pp;
    342 
    343     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_BLE_CREATE_LL_CONN)) == NULL)
    344         return (FALSE);
    345 
    346     pp = (UINT8 *)(p + 1);
    347 
    348     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_CREATE_LL_CONN;
    349     p->offset = 0;
    350 
    351     UINT16_TO_STREAM (pp, HCI_BLE_CREATE_LL_CONN);
    352     UINT8_TO_STREAM  (pp, HCIC_PARAM_SIZE_BLE_CREATE_LL_CONN);
    353 
    354     UINT16_TO_STREAM (pp, scan_int);
    355     UINT16_TO_STREAM (pp, scan_win);
    356     UINT8_TO_STREAM (pp, init_filter_policy);
    357 
    358     UINT8_TO_STREAM (pp, addr_type_peer);
    359     BDADDR_TO_STREAM (pp, bda_peer);
    360     UINT8_TO_STREAM (pp, addr_type_own);
    361 
    362     UINT16_TO_STREAM (pp, conn_int_min);
    363     UINT16_TO_STREAM (pp, conn_int_max);
    364     UINT16_TO_STREAM (pp, conn_latency);
    365     UINT16_TO_STREAM (pp, conn_timeout);
    366 
    367     UINT16_TO_STREAM (pp, min_ce_len);
    368     UINT16_TO_STREAM (pp, max_ce_len);
    369 
    370     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID,  p);
    371     return (TRUE);
    372 }
    373 
    374 BOOLEAN btsnd_hcic_ble_create_conn_cancel (void)
    375 {
    376     BT_HDR *p;
    377     UINT8 *pp;
    378 
    379     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_BLE_CREATE_CONN_CANCEL)) == NULL)
    380         return (FALSE);
    381 
    382     pp = (UINT8 *)(p + 1);
    383 
    384     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_CREATE_CONN_CANCEL;
    385     p->offset = 0;
    386 
    387     UINT16_TO_STREAM (pp, HCI_BLE_CREATE_CONN_CANCEL);
    388     UINT8_TO_STREAM  (pp, HCIC_PARAM_SIZE_BLE_CREATE_CONN_CANCEL);
    389 
    390     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID,  p);
    391     return (TRUE);
    392 }
    393 
    394 BOOLEAN btsnd_hcic_ble_read_white_list_size (void)
    395 {
    396     BT_HDR *p;
    397     UINT8 *pp;
    398 
    399     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_READ_CMD)) == NULL)
    400         return (FALSE);
    401 
    402     pp = (UINT8 *)(p + 1);
    403 
    404     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_READ_CMD;
    405     p->offset = 0;
    406 
    407     UINT16_TO_STREAM (pp, HCI_BLE_READ_WHITE_LIST_SIZE);
    408     UINT8_TO_STREAM  (pp,  HCIC_PARAM_SIZE_READ_CMD);
    409 
    410     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID,  p);
    411     return (TRUE);
    412 }
    413 
    414 BOOLEAN btsnd_hcic_ble_clear_white_list (void)
    415 {
    416     BT_HDR *p;
    417     UINT8 *pp;
    418 
    419     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_CLEAR_WHITE_LIST)) == NULL)
    420         return (FALSE);
    421 
    422     pp = (UINT8 *)(p + 1);
    423 
    424     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_CLEAR_WHITE_LIST;
    425     p->offset = 0;
    426 
    427     UINT16_TO_STREAM (pp, HCI_BLE_CLEAR_WHITE_LIST);
    428     UINT8_TO_STREAM  (pp, HCIC_PARAM_SIZE_CLEAR_WHITE_LIST);
    429 
    430     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID,  p);
    431     return (TRUE);
    432 }
    433 
    434 BOOLEAN btsnd_hcic_ble_add_white_list (UINT8 addr_type, BD_ADDR bda)
    435 {
    436     BT_HDR *p;
    437     UINT8 *pp;
    438 
    439     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_ADD_WHITE_LIST)) == NULL)
    440         return (FALSE);
    441 
    442     pp = (UINT8 *)(p + 1);
    443 
    444     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_ADD_WHITE_LIST;
    445     p->offset = 0;
    446 
    447     UINT16_TO_STREAM (pp, HCI_BLE_ADD_WHITE_LIST);
    448     UINT8_TO_STREAM  (pp, HCIC_PARAM_SIZE_ADD_WHITE_LIST);
    449 
    450     UINT8_TO_STREAM (pp, addr_type);
    451     BDADDR_TO_STREAM (pp, bda);
    452 
    453     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID,  p);
    454     return (TRUE);
    455 }
    456 
    457 BOOLEAN btsnd_hcic_ble_remove_from_white_list (UINT8 addr_type, BD_ADDR bda)
    458 {
    459     BT_HDR *p;
    460     UINT8 *pp;
    461 
    462     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_REMOVE_WHITE_LIST)) == NULL)
    463         return (FALSE);
    464 
    465     pp = (UINT8 *)(p + 1);
    466 
    467     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_REMOVE_WHITE_LIST;
    468     p->offset = 0;
    469 
    470     UINT16_TO_STREAM (pp, HCI_BLE_REMOVE_WHITE_LIST);
    471     UINT8_TO_STREAM  (pp, HCIC_PARAM_SIZE_REMOVE_WHITE_LIST);
    472 
    473     UINT8_TO_STREAM (pp, addr_type);
    474     BDADDR_TO_STREAM (pp, bda);
    475 
    476     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID,  p);
    477     return (TRUE);
    478 }
    479 
    480 BOOLEAN btsnd_hcic_ble_upd_ll_conn_params (UINT16 handle,
    481                                            UINT16 conn_int_min, UINT16 conn_int_max,
    482                                            UINT16 conn_latency, UINT16 conn_timeout,
    483                                            UINT16 min_ce_len, UINT16 max_ce_len)
    484 {
    485     BT_HDR *p;
    486     UINT8 *pp;
    487 
    488     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_BLE_UPD_LL_CONN_PARAMS)) == NULL)
    489         return (FALSE);
    490 
    491     pp = (UINT8 *)(p + 1);
    492 
    493     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_UPD_LL_CONN_PARAMS;
    494     p->offset = 0;
    495 
    496     UINT16_TO_STREAM (pp, HCI_BLE_UPD_LL_CONN_PARAMS);
    497     UINT8_TO_STREAM  (pp, HCIC_PARAM_SIZE_BLE_UPD_LL_CONN_PARAMS);
    498 
    499     UINT16_TO_STREAM (pp, handle);
    500 
    501     UINT16_TO_STREAM (pp, conn_int_min);
    502     UINT16_TO_STREAM (pp, conn_int_max);
    503     UINT16_TO_STREAM (pp, conn_latency);
    504     UINT16_TO_STREAM (pp, conn_timeout);
    505     UINT16_TO_STREAM (pp, min_ce_len);
    506     UINT16_TO_STREAM (pp, max_ce_len);
    507 
    508     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID,  p);
    509     return (TRUE);
    510 }
    511 
    512 BOOLEAN btsnd_hcic_ble_set_host_chnl_class (UINT8  chnl_map[HCIC_BLE_CHNL_MAP_SIZE])
    513 {
    514     BT_HDR *p;
    515     UINT8 *pp;
    516 
    517     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_SET_HOST_CHNL_CLASS)) == NULL)
    518         return (FALSE);
    519 
    520     pp = (UINT8 *)(p + 1);
    521 
    522     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_SET_HOST_CHNL_CLASS;
    523     p->offset = 0;
    524 
    525     UINT16_TO_STREAM (pp, HCI_BLE_SET_HOST_CHNL_CLASS);
    526     UINT8_TO_STREAM  (pp, HCIC_PARAM_SIZE_SET_HOST_CHNL_CLASS);
    527 
    528     ARRAY_TO_STREAM (pp, chnl_map, HCIC_BLE_CHNL_MAP_SIZE);
    529 
    530     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID,  p);
    531     return (TRUE);
    532 }
    533 
    534 BOOLEAN btsnd_hcic_ble_read_chnl_map (UINT16 handle)
    535 {
    536     BT_HDR *p;
    537     UINT8 *pp;
    538 
    539     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_READ_CHNL_MAP)) == NULL)
    540         return (FALSE);
    541 
    542     pp = (UINT8 *)(p + 1);
    543 
    544     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_READ_CHNL_MAP;
    545     p->offset = 0;
    546 
    547     UINT16_TO_STREAM (pp, HCI_BLE_READ_CHNL_MAP);
    548     UINT8_TO_STREAM  (pp, HCIC_PARAM_SIZE_READ_CHNL_MAP);
    549 
    550     UINT16_TO_STREAM (pp, handle);
    551 
    552     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID,  p);
    553     return (TRUE);
    554 }
    555 
    556 BOOLEAN btsnd_hcic_ble_read_remote_feat (UINT16 handle)
    557 {
    558     BT_HDR *p;
    559     UINT8 *pp;
    560 
    561     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_BLE_READ_REMOTE_FEAT)) == NULL)
    562         return (FALSE);
    563 
    564     pp = (UINT8 *)(p + 1);
    565 
    566     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_READ_REMOTE_FEAT;
    567     p->offset = 0;
    568 
    569     UINT16_TO_STREAM (pp, HCI_BLE_READ_REMOTE_FEAT);
    570     UINT8_TO_STREAM  (pp, HCIC_PARAM_SIZE_BLE_READ_REMOTE_FEAT);
    571 
    572     UINT16_TO_STREAM (pp, handle);
    573 
    574     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID,  p);
    575     return (TRUE);
    576 }
    577 
    578 /* security management commands */
    579 BOOLEAN btsnd_hcic_ble_encrypt (UINT8 *key, UINT8 key_len,
    580                                 UINT8 *plain_text, UINT8 pt_len,
    581                                 void *p_cmd_cplt_cback)
    582 {
    583     BT_HDR *p;
    584     UINT8 *pp;
    585 
    586     if ((p = HCI_GET_CMD_BUF(sizeof(BT_HDR) + sizeof (void *) +
    587                             HCIC_PARAM_SIZE_BLE_ENCRYPT)) == NULL)
    588         return (FALSE);
    589 
    590     pp = (UINT8 *)(p + 1);
    591 
    592     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_ENCRYPT;
    593     p->offset = sizeof(void *);
    594 
    595     *((void **)pp) = p_cmd_cplt_cback;  /* Store command complete callback in buffer */
    596     pp += sizeof(void *);               /* Skip over callback pointer */
    597 
    598 
    599     UINT16_TO_STREAM (pp, HCI_BLE_ENCRYPT);
    600     UINT8_TO_STREAM  (pp, HCIC_PARAM_SIZE_BLE_ENCRYPT);
    601 
    602     memset(pp, 0, HCIC_PARAM_SIZE_BLE_ENCRYPT);
    603 
    604     if (key_len > HCIC_BLE_ENCRYT_KEY_SIZE) key_len = HCIC_BLE_ENCRYT_KEY_SIZE;
    605     if (pt_len > HCIC_BLE_ENCRYT_KEY_SIZE) pt_len = HCIC_BLE_ENCRYT_KEY_SIZE;
    606 
    607     ARRAY_TO_STREAM (pp, key, key_len);
    608     pp += (HCIC_BLE_ENCRYT_KEY_SIZE - key_len);
    609     ARRAY_TO_STREAM (pp, plain_text, pt_len);
    610 
    611     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID,  p);
    612     return (TRUE);
    613 }
    614 
    615 BOOLEAN btsnd_hcic_ble_rand (void *p_cmd_cplt_cback)
    616 {
    617     BT_HDR *p;
    618     UINT8 *pp;
    619 
    620     if ((p = HCI_GET_CMD_BUF(sizeof(BT_HDR) + sizeof (void *) +
    621                         HCIC_PARAM_SIZE_BLE_RAND)) == NULL)
    622         return (FALSE);
    623 
    624     pp = (UINT8 *)(p + 1);
    625 
    626     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_RAND;
    627     p->offset = sizeof(void *);
    628 
    629     *((void **)pp) = p_cmd_cplt_cback;  /* Store command complete callback in buffer */
    630     pp += sizeof(void *);               /* Skip over callback pointer */
    631 
    632     UINT16_TO_STREAM (pp, HCI_BLE_RAND);
    633     UINT8_TO_STREAM  (pp, HCIC_PARAM_SIZE_BLE_RAND);
    634 
    635     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID,  p);
    636     return (TRUE);
    637 }
    638 
    639 BOOLEAN btsnd_hcic_ble_start_enc (UINT16 handle, UINT8 rand[HCIC_BLE_RAND_DI_SIZE],
    640                                 UINT16 ediv, UINT8 ltk[HCIC_BLE_ENCRYT_KEY_SIZE])
    641 {
    642     BT_HDR *p;
    643     UINT8 *pp;
    644 
    645     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_BLE_START_ENC)) == NULL)
    646         return (FALSE);
    647 
    648     pp = (UINT8 *)(p + 1);
    649 
    650     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_START_ENC;
    651     p->offset = 0;
    652 
    653     UINT16_TO_STREAM (pp, HCI_BLE_START_ENC);
    654     UINT8_TO_STREAM  (pp, HCIC_PARAM_SIZE_BLE_START_ENC);
    655 
    656     UINT16_TO_STREAM (pp, handle);
    657     ARRAY_TO_STREAM (pp, rand, HCIC_BLE_RAND_DI_SIZE);
    658     UINT16_TO_STREAM (pp, ediv);
    659     ARRAY_TO_STREAM (pp, ltk, HCIC_BLE_ENCRYT_KEY_SIZE);
    660 
    661     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID,  p);
    662     return (TRUE);
    663 }
    664 
    665 BOOLEAN btsnd_hcic_ble_ltk_req_reply (UINT16 handle, UINT8 ltk[HCIC_BLE_ENCRYT_KEY_SIZE])
    666 {
    667     BT_HDR *p;
    668     UINT8 *pp;
    669 
    670     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_LTK_REQ_REPLY)) == NULL)
    671         return (FALSE);
    672 
    673     pp = (UINT8 *)(p + 1);
    674 
    675     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_LTK_REQ_REPLY;
    676     p->offset = 0;
    677 
    678     UINT16_TO_STREAM (pp, HCI_BLE_LTK_REQ_REPLY);
    679     UINT8_TO_STREAM  (pp, HCIC_PARAM_SIZE_LTK_REQ_REPLY);
    680 
    681     UINT16_TO_STREAM (pp, handle);
    682     ARRAY_TO_STREAM (pp, ltk, HCIC_BLE_ENCRYT_KEY_SIZE);
    683 
    684     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID,  p);
    685     return (TRUE);
    686 }
    687 
    688 BOOLEAN btsnd_hcic_ble_ltk_req_neg_reply (UINT16 handle)
    689 {
    690     BT_HDR *p;
    691     UINT8 *pp;
    692 
    693     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_LTK_REQ_NEG_REPLY)) == NULL)
    694         return (FALSE);
    695 
    696     pp = (UINT8 *)(p + 1);
    697 
    698     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_LTK_REQ_NEG_REPLY;
    699     p->offset = 0;
    700 
    701     UINT16_TO_STREAM (pp, HCI_BLE_LTK_REQ_NEG_REPLY);
    702     UINT8_TO_STREAM  (pp, HCIC_PARAM_SIZE_LTK_REQ_NEG_REPLY);
    703 
    704     UINT16_TO_STREAM (pp, handle);
    705 
    706     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID,  p);
    707     return (TRUE);
    708 }
    709 
    710 BOOLEAN btsnd_hcic_ble_read_supported_states (void)
    711 {
    712     BT_HDR *p;
    713     UINT8 *pp;
    714 
    715     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_READ_CMD)) == NULL)
    716         return (FALSE);
    717 
    718     pp = (UINT8 *)(p + 1);
    719 
    720     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_READ_CMD;
    721     p->offset = 0;
    722 
    723     UINT16_TO_STREAM (pp, HCI_BLE_READ_SUPPORTED_STATES);
    724     UINT8_TO_STREAM  (pp, HCIC_PARAM_SIZE_READ_CMD);
    725 
    726     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID,  p);
    727     return (TRUE);
    728 }
    729 
    730 BOOLEAN btsnd_hcic_ble_receiver_test(UINT8 rx_freq)
    731 {
    732     BT_HDR *p;
    733     UINT8 *pp;
    734 
    735     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_WRITE_PARAM1)) == NULL)
    736         return (FALSE);
    737 
    738     pp = (UINT8 *)(p + 1);
    739 
    740     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_WRITE_PARAM1;
    741     p->offset = 0;
    742 
    743     UINT16_TO_STREAM (pp, HCI_BLE_RECEIVER_TEST);
    744     UINT8_TO_STREAM  (pp, HCIC_PARAM_SIZE_WRITE_PARAM1);
    745 
    746     UINT8_TO_STREAM (pp, rx_freq);
    747 
    748     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID,  p);
    749     return (TRUE);
    750 }
    751 
    752 BOOLEAN btsnd_hcic_ble_transmitter_test(UINT8 tx_freq, UINT8 test_data_len, UINT8 payload)
    753 {
    754     BT_HDR *p;
    755     UINT8 *pp;
    756 
    757     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_WRITE_PARAM3)) == NULL)
    758         return (FALSE);
    759 
    760     pp = (UINT8 *)(p + 1);
    761 
    762     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_WRITE_PARAM3;
    763     p->offset = 0;
    764 
    765     UINT16_TO_STREAM (pp, HCI_BLE_TRANSMITTER_TEST);
    766     UINT8_TO_STREAM  (pp, HCIC_PARAM_SIZE_WRITE_PARAM3);
    767 
    768     UINT8_TO_STREAM (pp, tx_freq);
    769     UINT8_TO_STREAM (pp, test_data_len);
    770     UINT8_TO_STREAM (pp, payload);
    771 
    772     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID,  p);
    773     return (TRUE);
    774 }
    775 
    776 BOOLEAN btsnd_hcic_ble_test_end(void)
    777 {
    778     BT_HDR *p;
    779     UINT8 *pp;
    780 
    781     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_READ_CMD)) == NULL)
    782         return (FALSE);
    783 
    784     pp = (UINT8 *)(p + 1);
    785 
    786     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_READ_CMD;
    787     p->offset = 0;
    788 
    789     UINT16_TO_STREAM (pp, HCI_BLE_TEST_END);
    790     UINT8_TO_STREAM  (pp, HCIC_PARAM_SIZE_READ_CMD);
    791 
    792     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID,  p);
    793     return (TRUE);
    794 }
    795 
    796 BOOLEAN btsnd_hcic_ble_read_host_supported (void)
    797 {
    798     BT_HDR *p;
    799     UINT8 *pp;
    800 
    801     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_READ_CMD)) == NULL)
    802         return (FALSE);
    803 
    804     pp = (UINT8 *)(p + 1);
    805 
    806     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_READ_CMD;
    807     p->offset = 0;
    808 
    809     UINT16_TO_STREAM (pp, HCI_READ_LE_HOST_SUPPORTED);
    810     UINT8_TO_STREAM  (pp, HCIC_PARAM_SIZE_READ_CMD);
    811 
    812     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID,  p);
    813     return (TRUE);
    814 }
    815 
    816 BOOLEAN btsnd_hcic_ble_write_host_supported (UINT8 le_host_spt, UINT8 simul_le_host_spt)
    817 {
    818     BT_HDR *p;
    819     UINT8 *pp;
    820 
    821     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_WRITE_LE_HOST_SUPPORTED)) == NULL)
    822         return (FALSE);
    823 
    824     pp = (UINT8 *)(p + 1);
    825 
    826     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_WRITE_LE_HOST_SUPPORTED;
    827     p->offset = 0;
    828 
    829     UINT16_TO_STREAM (pp, HCI_WRITE_LE_HOST_SUPPORTED);
    830     UINT8_TO_STREAM  (pp, HCIC_PARAM_SIZE_WRITE_LE_HOST_SUPPORTED);
    831 	UINT8_TO_STREAM  (pp, le_host_spt);
    832 	UINT8_TO_STREAM  (pp, simul_le_host_spt);
    833 
    834     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID,  p);
    835     return (TRUE);
    836 }
    837 
    838 #if (defined BLE_LLT_INCLUDED) && (BLE_LLT_INCLUDED == TRUE)
    839 
    840 BOOLEAN btsnd_hcic_ble_rc_param_req_reply(  UINT16 handle,
    841                                             UINT16 conn_int_min, UINT16 conn_int_max,
    842                                             UINT16 conn_latency, UINT16 conn_timeout,
    843                                             UINT16 min_ce_len, UINT16 max_ce_len  )
    844 {
    845     BT_HDR *p;
    846     UINT8 *pp;
    847 
    848     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_BLE_RC_PARAM_REQ_REPLY)) == NULL)
    849         return (FALSE);
    850 
    851     pp = (UINT8 *)(p + 1);
    852 
    853     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_RC_PARAM_REQ_REPLY;
    854     p->offset = 0;
    855 
    856     UINT16_TO_STREAM (pp, HCI_BLE_RC_PARAM_REQ_REPLY);
    857     UINT8_TO_STREAM  (pp, HCIC_PARAM_SIZE_BLE_RC_PARAM_REQ_REPLY);
    858 
    859     UINT16_TO_STREAM (pp, handle);
    860     UINT16_TO_STREAM (pp, conn_int_min);
    861     UINT16_TO_STREAM (pp, conn_int_max);
    862     UINT16_TO_STREAM (pp, conn_latency);
    863     UINT16_TO_STREAM (pp, conn_timeout);
    864     UINT16_TO_STREAM (pp, min_ce_len);
    865     UINT16_TO_STREAM (pp, max_ce_len);
    866 
    867     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID,  p);
    868     return (TRUE);
    869 }
    870 
    871 BOOLEAN btsnd_hcic_ble_rc_param_req_neg_reply(UINT16 handle, UINT8 reason)
    872 {
    873     BT_HDR *p;
    874     UINT8 *pp;
    875 
    876     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_BLE_RC_PARAM_REQ_NEG_REPLY)) == NULL)
    877         return (FALSE);
    878 
    879     pp = (UINT8 *)(p + 1);
    880 
    881     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_RC_PARAM_REQ_NEG_REPLY;
    882     p->offset = 0;
    883 
    884     UINT16_TO_STREAM (pp, HCI_BLE_RC_PARAM_REQ_NEG_REPLY);
    885     UINT8_TO_STREAM  (pp, HCIC_PARAM_SIZE_BLE_RC_PARAM_REQ_NEG_REPLY);
    886 
    887     UINT16_TO_STREAM (pp, handle);
    888     UINT8_TO_STREAM (pp, reason);
    889 
    890     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID,  p);
    891     return (TRUE);
    892 }
    893 #endif
    894 
    895 #endif
    896 
    897