The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
Jakub Pawlowski | 5b790fe | 2017-09-18 09:00:20 -0700 | [diff] [blame] | 3 | * Copyright 1999-2012 Broadcom Corporation |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 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 | |
Pavlin Radoslavov | 258c253 | 2015-09-27 20:59:05 -0700 | [diff] [blame] | 26 | #include "bt_common.h" |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 27 | #include "bt_target.h" |
| 28 | #include "btu.h" |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 29 | #include "hcidefs.h" |
| 30 | #include "hcimsgs.h" |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 31 | |
Jakub Pawlowski | 0c68323 | 2017-02-24 09:49:59 -0800 | [diff] [blame] | 32 | #include <base/bind.h> |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 33 | #include <stddef.h> |
| 34 | #include <string.h> |
| 35 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 36 | void btsnd_hcic_ble_set_local_used_feat(uint8_t feat_set[8]) { |
| 37 | BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); |
| 38 | uint8_t* pp = (uint8_t*)(p + 1); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 39 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 40 | p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_SET_USED_FEAT_CMD; |
| 41 | p->offset = 0; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 42 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 43 | UINT16_TO_STREAM(pp, HCI_BLE_WRITE_LOCAL_SPT_FEAT); |
| 44 | ARRAY_TO_STREAM(pp, feat_set, HCIC_PARAM_SIZE_SET_USED_FEAT_CMD); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 45 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 46 | btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 47 | } |
| 48 | |
Jakub Pawlowski | a484a88 | 2017-06-24 17:30:18 -0700 | [diff] [blame] | 49 | void btsnd_hcic_ble_set_random_addr(const RawAddress& random_bda) { |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 50 | BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); |
| 51 | uint8_t* pp = (uint8_t*)(p + 1); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 52 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 53 | p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_WRITE_RANDOM_ADDR_CMD; |
| 54 | p->offset = 0; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 55 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 56 | UINT16_TO_STREAM(pp, HCI_BLE_WRITE_RANDOM_ADDR); |
| 57 | UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_WRITE_RANDOM_ADDR_CMD); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 58 | |
Jakub Pawlowski | b8a477e | 2017-06-16 15:16:15 -0700 | [diff] [blame] | 59 | BDADDR_TO_STREAM(pp, random_bda); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 60 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 61 | btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 62 | } |
| 63 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 64 | void btsnd_hcic_ble_write_adv_params(uint16_t adv_int_min, uint16_t adv_int_max, |
| 65 | uint8_t adv_type, uint8_t addr_type_own, |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 66 | uint8_t addr_type_dir, |
Jakub Pawlowski | a484a88 | 2017-06-24 17:30:18 -0700 | [diff] [blame] | 67 | const RawAddress& direct_bda, |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 68 | uint8_t channel_map, |
| 69 | uint8_t adv_filter_policy) { |
| 70 | BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); |
| 71 | uint8_t* pp = (uint8_t*)(p + 1); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 72 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 73 | p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_WRITE_ADV_PARAMS; |
| 74 | p->offset = 0; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 75 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 76 | UINT16_TO_STREAM(pp, HCI_BLE_WRITE_ADV_PARAMS); |
| 77 | UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_BLE_WRITE_ADV_PARAMS); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 78 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 79 | UINT16_TO_STREAM(pp, adv_int_min); |
| 80 | UINT16_TO_STREAM(pp, adv_int_max); |
| 81 | UINT8_TO_STREAM(pp, adv_type); |
| 82 | UINT8_TO_STREAM(pp, addr_type_own); |
| 83 | UINT8_TO_STREAM(pp, addr_type_dir); |
Jakub Pawlowski | b8a477e | 2017-06-16 15:16:15 -0700 | [diff] [blame] | 84 | BDADDR_TO_STREAM(pp, direct_bda); |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 85 | UINT8_TO_STREAM(pp, channel_map); |
| 86 | UINT8_TO_STREAM(pp, adv_filter_policy); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 87 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 88 | btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 89 | } |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 90 | void btsnd_hcic_ble_read_adv_chnl_tx_power(void) { |
| 91 | BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); |
| 92 | uint8_t* pp = (uint8_t*)(p + 1); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 93 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 94 | p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_READ_CMD; |
| 95 | p->offset = 0; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 96 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 97 | UINT16_TO_STREAM(pp, HCI_BLE_READ_ADV_CHNL_TX_POWER); |
| 98 | UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_READ_CMD); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 99 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 100 | btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 101 | } |
| 102 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 103 | void btsnd_hcic_ble_set_adv_data(uint8_t data_len, uint8_t* p_data) { |
| 104 | BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); |
| 105 | uint8_t* pp = (uint8_t*)(p + 1); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 106 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 107 | p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_WRITE_ADV_DATA + 1; |
| 108 | p->offset = 0; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 109 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 110 | UINT16_TO_STREAM(pp, HCI_BLE_WRITE_ADV_DATA); |
| 111 | UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_BLE_WRITE_ADV_DATA + 1); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 112 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 113 | memset(pp, 0, HCIC_PARAM_SIZE_BLE_WRITE_ADV_DATA); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 114 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 115 | if (p_data != NULL && data_len > 0) { |
| 116 | if (data_len > HCIC_PARAM_SIZE_BLE_WRITE_ADV_DATA) |
| 117 | data_len = HCIC_PARAM_SIZE_BLE_WRITE_ADV_DATA; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 118 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 119 | UINT8_TO_STREAM(pp, data_len); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 120 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 121 | ARRAY_TO_STREAM(pp, p_data, data_len); |
| 122 | } |
| 123 | btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 124 | } |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 125 | void btsnd_hcic_ble_set_scan_rsp_data(uint8_t data_len, uint8_t* p_scan_rsp) { |
| 126 | BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); |
| 127 | uint8_t* pp = (uint8_t*)(p + 1); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 128 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 129 | p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_WRITE_SCAN_RSP + 1; |
| 130 | p->offset = 0; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 131 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 132 | UINT16_TO_STREAM(pp, HCI_BLE_WRITE_SCAN_RSP_DATA); |
| 133 | UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_BLE_WRITE_SCAN_RSP + 1); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 134 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 135 | memset(pp, 0, HCIC_PARAM_SIZE_BLE_WRITE_SCAN_RSP); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 136 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 137 | if (p_scan_rsp != NULL && data_len > 0) { |
| 138 | if (data_len > HCIC_PARAM_SIZE_BLE_WRITE_SCAN_RSP) |
| 139 | data_len = HCIC_PARAM_SIZE_BLE_WRITE_SCAN_RSP; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 140 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 141 | UINT8_TO_STREAM(pp, data_len); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 142 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 143 | ARRAY_TO_STREAM(pp, p_scan_rsp, data_len); |
| 144 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 145 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 146 | btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 147 | } |
| 148 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 149 | void btsnd_hcic_ble_set_adv_enable(uint8_t adv_enable) { |
| 150 | BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); |
| 151 | uint8_t* pp = (uint8_t*)(p + 1); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 152 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 153 | p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_WRITE_ADV_ENABLE; |
| 154 | p->offset = 0; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 155 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 156 | UINT16_TO_STREAM(pp, HCI_BLE_WRITE_ADV_ENABLE); |
| 157 | UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_WRITE_ADV_ENABLE); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 158 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 159 | UINT8_TO_STREAM(pp, adv_enable); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 160 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 161 | btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 162 | } |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 163 | void btsnd_hcic_ble_set_scan_params(uint8_t scan_type, uint16_t scan_int, |
| 164 | uint16_t scan_win, uint8_t addr_type_own, |
| 165 | uint8_t scan_filter_policy) { |
| 166 | BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); |
| 167 | uint8_t* pp = (uint8_t*)(p + 1); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 168 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 169 | p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_WRITE_SCAN_PARAM; |
| 170 | p->offset = 0; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 171 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 172 | UINT16_TO_STREAM(pp, HCI_BLE_WRITE_SCAN_PARAMS); |
| 173 | UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_BLE_WRITE_SCAN_PARAM); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 174 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 175 | UINT8_TO_STREAM(pp, scan_type); |
| 176 | UINT16_TO_STREAM(pp, scan_int); |
| 177 | UINT16_TO_STREAM(pp, scan_win); |
| 178 | UINT8_TO_STREAM(pp, addr_type_own); |
| 179 | UINT8_TO_STREAM(pp, scan_filter_policy); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 180 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 181 | btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 182 | } |
| 183 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 184 | void btsnd_hcic_ble_set_scan_enable(uint8_t scan_enable, uint8_t duplicate) { |
| 185 | BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); |
| 186 | uint8_t* pp = (uint8_t*)(p + 1); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 187 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 188 | p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_WRITE_SCAN_ENABLE; |
| 189 | p->offset = 0; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 190 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 191 | UINT16_TO_STREAM(pp, HCI_BLE_WRITE_SCAN_ENABLE); |
| 192 | UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_BLE_WRITE_SCAN_ENABLE); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 193 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 194 | UINT8_TO_STREAM(pp, scan_enable); |
| 195 | UINT8_TO_STREAM(pp, duplicate); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 196 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 197 | btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 198 | } |
| 199 | |
| 200 | /* link layer connection management commands */ |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 201 | void btsnd_hcic_ble_create_ll_conn( |
| 202 | uint16_t scan_int, uint16_t scan_win, uint8_t init_filter_policy, |
Jakub Pawlowski | a484a88 | 2017-06-24 17:30:18 -0700 | [diff] [blame] | 203 | uint8_t addr_type_peer, const RawAddress& bda_peer, uint8_t addr_type_own, |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 204 | uint16_t conn_int_min, uint16_t conn_int_max, uint16_t conn_latency, |
| 205 | uint16_t conn_timeout, uint16_t min_ce_len, uint16_t max_ce_len) { |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 206 | BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); |
| 207 | uint8_t* pp = (uint8_t*)(p + 1); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 208 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 209 | p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_CREATE_LL_CONN; |
| 210 | p->offset = 0; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 211 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 212 | UINT16_TO_STREAM(pp, HCI_BLE_CREATE_LL_CONN); |
| 213 | UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_BLE_CREATE_LL_CONN); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 214 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 215 | UINT16_TO_STREAM(pp, scan_int); |
| 216 | UINT16_TO_STREAM(pp, scan_win); |
| 217 | UINT8_TO_STREAM(pp, init_filter_policy); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 218 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 219 | UINT8_TO_STREAM(pp, addr_type_peer); |
Jakub Pawlowski | b8a477e | 2017-06-16 15:16:15 -0700 | [diff] [blame] | 220 | BDADDR_TO_STREAM(pp, bda_peer); |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 221 | UINT8_TO_STREAM(pp, addr_type_own); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 222 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 223 | UINT16_TO_STREAM(pp, conn_int_min); |
| 224 | UINT16_TO_STREAM(pp, conn_int_max); |
| 225 | UINT16_TO_STREAM(pp, conn_latency); |
| 226 | UINT16_TO_STREAM(pp, conn_timeout); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 227 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 228 | UINT16_TO_STREAM(pp, min_ce_len); |
| 229 | UINT16_TO_STREAM(pp, max_ce_len); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 230 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 231 | btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 232 | } |
| 233 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 234 | void btsnd_hcic_ble_create_conn_cancel(void) { |
| 235 | BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); |
| 236 | uint8_t* pp = (uint8_t*)(p + 1); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 237 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 238 | p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_CREATE_CONN_CANCEL; |
| 239 | p->offset = 0; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 240 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 241 | UINT16_TO_STREAM(pp, HCI_BLE_CREATE_CONN_CANCEL); |
| 242 | UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_BLE_CREATE_CONN_CANCEL); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 243 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 244 | btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 245 | } |
| 246 | |
Jakub Pawlowski | 553e88b | 2018-10-30 22:49:30 +0100 | [diff] [blame] | 247 | void btsnd_hcic_ble_clear_white_list( |
| 248 | base::OnceCallback<void(uint8_t*, uint16_t)> cb) { |
| 249 | btu_hcif_send_cmd_with_cb(FROM_HERE, HCI_BLE_CLEAR_WHITE_LIST, nullptr, 0, |
| 250 | std::move(cb)); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 251 | } |
| 252 | |
Jakub Pawlowski | 553e88b | 2018-10-30 22:49:30 +0100 | [diff] [blame] | 253 | void btsnd_hcic_ble_add_white_list( |
| 254 | uint8_t addr_type, const RawAddress& bda, |
| 255 | base::OnceCallback<void(uint8_t*, uint16_t)> cb) { |
| 256 | uint8_t param[HCIC_PARAM_SIZE_ADD_WHITE_LIST]; |
| 257 | uint8_t* pp = param; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 258 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 259 | UINT8_TO_STREAM(pp, addr_type); |
| 260 | BDADDR_TO_STREAM(pp, bda); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 261 | |
Jakub Pawlowski | 553e88b | 2018-10-30 22:49:30 +0100 | [diff] [blame] | 262 | btu_hcif_send_cmd_with_cb(FROM_HERE, HCI_BLE_ADD_WHITE_LIST, param, |
| 263 | HCIC_PARAM_SIZE_ADD_WHITE_LIST, std::move(cb)); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 264 | } |
| 265 | |
Jakub Pawlowski | 553e88b | 2018-10-30 22:49:30 +0100 | [diff] [blame] | 266 | void btsnd_hcic_ble_remove_from_white_list( |
| 267 | uint8_t addr_type, const RawAddress& bda, |
| 268 | base::OnceCallback<void(uint8_t*, uint16_t)> cb) { |
| 269 | uint8_t param[HCIC_PARAM_SIZE_REMOVE_WHITE_LIST]; |
| 270 | uint8_t* pp = param; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 271 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 272 | UINT8_TO_STREAM(pp, addr_type); |
| 273 | BDADDR_TO_STREAM(pp, bda); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 274 | |
Jakub Pawlowski | 553e88b | 2018-10-30 22:49:30 +0100 | [diff] [blame] | 275 | btu_hcif_send_cmd_with_cb(FROM_HERE, HCI_BLE_REMOVE_WHITE_LIST, param, |
| 276 | HCIC_PARAM_SIZE_REMOVE_WHITE_LIST, std::move(cb)); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 277 | } |
| 278 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 279 | void btsnd_hcic_ble_upd_ll_conn_params(uint16_t handle, uint16_t conn_int_min, |
| 280 | uint16_t conn_int_max, |
| 281 | uint16_t conn_latency, |
| 282 | uint16_t conn_timeout, |
| 283 | uint16_t min_ce_len, |
| 284 | uint16_t max_ce_len) { |
| 285 | BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); |
| 286 | uint8_t* pp = (uint8_t*)(p + 1); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 287 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 288 | p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_UPD_LL_CONN_PARAMS; |
| 289 | p->offset = 0; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 290 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 291 | UINT16_TO_STREAM(pp, HCI_BLE_UPD_LL_CONN_PARAMS); |
| 292 | UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_BLE_UPD_LL_CONN_PARAMS); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 293 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 294 | UINT16_TO_STREAM(pp, handle); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 295 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 296 | UINT16_TO_STREAM(pp, conn_int_min); |
| 297 | UINT16_TO_STREAM(pp, conn_int_max); |
| 298 | UINT16_TO_STREAM(pp, conn_latency); |
| 299 | UINT16_TO_STREAM(pp, conn_timeout); |
| 300 | UINT16_TO_STREAM(pp, min_ce_len); |
| 301 | UINT16_TO_STREAM(pp, max_ce_len); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 302 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 303 | btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 304 | } |
| 305 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 306 | void btsnd_hcic_ble_set_host_chnl_class( |
| 307 | uint8_t chnl_map[HCIC_BLE_CHNL_MAP_SIZE]) { |
| 308 | BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); |
| 309 | uint8_t* pp = (uint8_t*)(p + 1); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 310 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 311 | p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_SET_HOST_CHNL_CLASS; |
| 312 | p->offset = 0; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 313 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 314 | UINT16_TO_STREAM(pp, HCI_BLE_SET_HOST_CHNL_CLASS); |
| 315 | UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_SET_HOST_CHNL_CLASS); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 316 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 317 | ARRAY_TO_STREAM(pp, chnl_map, HCIC_BLE_CHNL_MAP_SIZE); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 318 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 319 | btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 320 | } |
| 321 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 322 | void btsnd_hcic_ble_read_chnl_map(uint16_t handle) { |
| 323 | BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); |
| 324 | uint8_t* pp = (uint8_t*)(p + 1); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 325 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 326 | p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_READ_CHNL_MAP; |
| 327 | p->offset = 0; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 328 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 329 | UINT16_TO_STREAM(pp, HCI_BLE_READ_CHNL_MAP); |
| 330 | UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_READ_CHNL_MAP); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 331 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 332 | UINT16_TO_STREAM(pp, handle); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 333 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 334 | btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 335 | } |
| 336 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 337 | void btsnd_hcic_ble_read_remote_feat(uint16_t handle) { |
| 338 | BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); |
| 339 | uint8_t* pp = (uint8_t*)(p + 1); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 340 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 341 | p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_READ_REMOTE_FEAT; |
| 342 | p->offset = 0; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 343 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 344 | UINT16_TO_STREAM(pp, HCI_BLE_READ_REMOTE_FEAT); |
| 345 | UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_BLE_READ_REMOTE_FEAT); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 346 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 347 | UINT16_TO_STREAM(pp, handle); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 348 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 349 | btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 350 | } |
| 351 | |
| 352 | /* security management commands */ |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 353 | void btsnd_hcic_ble_encrypt(uint8_t* key, uint8_t key_len, uint8_t* plain_text, |
| 354 | uint8_t pt_len, void* p_cmd_cplt_cback) { |
| 355 | BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); |
| 356 | uint8_t* pp = (uint8_t*)(p + 1); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 357 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 358 | p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_ENCRYPT; |
| 359 | p->offset = sizeof(void*); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 360 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 361 | *((void**)pp) = |
| 362 | p_cmd_cplt_cback; /* Store command complete callback in buffer */ |
| 363 | pp += sizeof(void*); /* Skip over callback pointer */ |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 364 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 365 | UINT16_TO_STREAM(pp, HCI_BLE_ENCRYPT); |
| 366 | UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_BLE_ENCRYPT); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 367 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 368 | memset(pp, 0, HCIC_PARAM_SIZE_BLE_ENCRYPT); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 369 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 370 | if (key_len > HCIC_BLE_ENCRYT_KEY_SIZE) key_len = HCIC_BLE_ENCRYT_KEY_SIZE; |
| 371 | if (pt_len > HCIC_BLE_ENCRYT_KEY_SIZE) pt_len = HCIC_BLE_ENCRYT_KEY_SIZE; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 372 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 373 | ARRAY_TO_STREAM(pp, key, key_len); |
| 374 | pp += (HCIC_BLE_ENCRYT_KEY_SIZE - key_len); |
| 375 | ARRAY_TO_STREAM(pp, plain_text, pt_len); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 376 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 377 | btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 378 | } |
| 379 | |
Jakub Pawlowski | 0c68323 | 2017-02-24 09:49:59 -0800 | [diff] [blame] | 380 | void btsnd_hcic_ble_rand(base::Callback<void(BT_OCTET8)> cb) { |
| 381 | btu_hcif_send_cmd_with_cb(FROM_HERE, HCI_BLE_RAND, nullptr, 0, |
| 382 | base::Bind( |
| 383 | [](base::Callback<void(BT_OCTET8)> cb, |
| 384 | uint8_t* param, uint16_t param_len) { |
| 385 | CHECK(param[0] == 0) |
| 386 | << "LE Rand return status must be zero"; |
| 387 | cb.Run(param + 1 /* skip status */); |
| 388 | }, |
| 389 | std::move(cb))); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 390 | } |
| 391 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 392 | void btsnd_hcic_ble_start_enc(uint16_t handle, |
| 393 | uint8_t rand[HCIC_BLE_RAND_DI_SIZE], |
Jakub Pawlowski | ae57211 | 2018-06-14 17:40:34 -0700 | [diff] [blame] | 394 | uint16_t ediv, const Octet16& ltk) { |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 395 | BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); |
| 396 | uint8_t* pp = (uint8_t*)(p + 1); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 397 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 398 | p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_START_ENC; |
| 399 | p->offset = 0; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 400 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 401 | UINT16_TO_STREAM(pp, HCI_BLE_START_ENC); |
| 402 | UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_BLE_START_ENC); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 403 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 404 | UINT16_TO_STREAM(pp, handle); |
| 405 | ARRAY_TO_STREAM(pp, rand, HCIC_BLE_RAND_DI_SIZE); |
| 406 | UINT16_TO_STREAM(pp, ediv); |
Jakub Pawlowski | ae57211 | 2018-06-14 17:40:34 -0700 | [diff] [blame] | 407 | ARRAY_TO_STREAM(pp, ltk.data(), HCIC_BLE_ENCRYT_KEY_SIZE); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 408 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 409 | btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 410 | } |
| 411 | |
Jakub Pawlowski | ae57211 | 2018-06-14 17:40:34 -0700 | [diff] [blame] | 412 | void btsnd_hcic_ble_ltk_req_reply(uint16_t handle, const Octet16& ltk) { |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 413 | BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); |
| 414 | uint8_t* pp = (uint8_t*)(p + 1); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 415 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 416 | p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_LTK_REQ_REPLY; |
| 417 | p->offset = 0; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 418 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 419 | UINT16_TO_STREAM(pp, HCI_BLE_LTK_REQ_REPLY); |
| 420 | UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_LTK_REQ_REPLY); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 421 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 422 | UINT16_TO_STREAM(pp, handle); |
Jakub Pawlowski | ae57211 | 2018-06-14 17:40:34 -0700 | [diff] [blame] | 423 | ARRAY_TO_STREAM(pp, ltk.data(), HCIC_BLE_ENCRYT_KEY_SIZE); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 424 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 425 | btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 426 | } |
| 427 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 428 | void btsnd_hcic_ble_ltk_req_neg_reply(uint16_t handle) { |
| 429 | BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); |
| 430 | uint8_t* pp = (uint8_t*)(p + 1); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 431 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 432 | p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_LTK_REQ_NEG_REPLY; |
| 433 | p->offset = 0; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 434 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 435 | UINT16_TO_STREAM(pp, HCI_BLE_LTK_REQ_NEG_REPLY); |
| 436 | UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_LTK_REQ_NEG_REPLY); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 437 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 438 | UINT16_TO_STREAM(pp, handle); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 439 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 440 | btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 441 | } |
| 442 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 443 | void btsnd_hcic_ble_receiver_test(uint8_t rx_freq) { |
| 444 | BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); |
| 445 | uint8_t* pp = (uint8_t*)(p + 1); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 446 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 447 | p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_WRITE_PARAM1; |
| 448 | p->offset = 0; |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 449 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 450 | UINT16_TO_STREAM(pp, HCI_BLE_RECEIVER_TEST); |
| 451 | UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_WRITE_PARAM1); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 452 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 453 | UINT8_TO_STREAM(pp, rx_freq); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 454 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 455 | btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 456 | } |
| 457 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 458 | void btsnd_hcic_ble_transmitter_test(uint8_t tx_freq, uint8_t test_data_len, |
| 459 | uint8_t payload) { |
| 460 | BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); |
| 461 | uint8_t* pp = (uint8_t*)(p + 1); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 462 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 463 | p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_WRITE_PARAM3; |
| 464 | p->offset = 0; |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 465 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 466 | UINT16_TO_STREAM(pp, HCI_BLE_TRANSMITTER_TEST); |
| 467 | UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_WRITE_PARAM3); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 468 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 469 | UINT8_TO_STREAM(pp, tx_freq); |
| 470 | UINT8_TO_STREAM(pp, test_data_len); |
| 471 | UINT8_TO_STREAM(pp, payload); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 472 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 473 | btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 474 | } |
| 475 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 476 | void btsnd_hcic_ble_test_end(void) { |
| 477 | BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); |
| 478 | uint8_t* pp = (uint8_t*)(p + 1); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 479 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 480 | p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_READ_CMD; |
| 481 | p->offset = 0; |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 482 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 483 | UINT16_TO_STREAM(pp, HCI_BLE_TEST_END); |
| 484 | UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_READ_CMD); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 485 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 486 | btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 487 | } |
| 488 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 489 | void btsnd_hcic_ble_read_host_supported(void) { |
| 490 | BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); |
| 491 | uint8_t* pp = (uint8_t*)(p + 1); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 492 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 493 | p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_READ_CMD; |
| 494 | p->offset = 0; |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 495 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 496 | UINT16_TO_STREAM(pp, HCI_READ_LE_HOST_SUPPORT); |
| 497 | UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_READ_CMD); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 498 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 499 | btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 500 | } |
| 501 | |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 502 | #if (BLE_LLT_INCLUDED == TRUE) |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 503 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 504 | void btsnd_hcic_ble_rc_param_req_reply(uint16_t handle, uint16_t conn_int_min, |
| 505 | uint16_t conn_int_max, |
| 506 | uint16_t conn_latency, |
| 507 | uint16_t conn_timeout, |
| 508 | uint16_t min_ce_len, |
| 509 | uint16_t max_ce_len) { |
| 510 | BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); |
| 511 | uint8_t* pp = (uint8_t*)(p + 1); |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 512 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 513 | p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_RC_PARAM_REQ_REPLY; |
| 514 | p->offset = 0; |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 515 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 516 | UINT16_TO_STREAM(pp, HCI_BLE_RC_PARAM_REQ_REPLY); |
| 517 | UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_BLE_RC_PARAM_REQ_REPLY); |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 518 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 519 | UINT16_TO_STREAM(pp, handle); |
| 520 | UINT16_TO_STREAM(pp, conn_int_min); |
| 521 | UINT16_TO_STREAM(pp, conn_int_max); |
| 522 | UINT16_TO_STREAM(pp, conn_latency); |
| 523 | UINT16_TO_STREAM(pp, conn_timeout); |
| 524 | UINT16_TO_STREAM(pp, min_ce_len); |
| 525 | UINT16_TO_STREAM(pp, max_ce_len); |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 526 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 527 | btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 528 | } |
| 529 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 530 | void btsnd_hcic_ble_rc_param_req_neg_reply(uint16_t handle, uint8_t reason) { |
| 531 | BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); |
| 532 | uint8_t* pp = (uint8_t*)(p + 1); |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 533 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 534 | p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_RC_PARAM_REQ_NEG_REPLY; |
| 535 | p->offset = 0; |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 536 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 537 | UINT16_TO_STREAM(pp, HCI_BLE_RC_PARAM_REQ_NEG_REPLY); |
| 538 | UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_BLE_RC_PARAM_REQ_NEG_REPLY); |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 539 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 540 | UINT16_TO_STREAM(pp, handle); |
| 541 | UINT8_TO_STREAM(pp, reason); |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 542 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 543 | btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 544 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 545 | #endif |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 546 | |
Jakub Pawlowski | ae57211 | 2018-06-14 17:40:34 -0700 | [diff] [blame] | 547 | void btsnd_hcic_ble_add_device_resolving_list(uint8_t addr_type_peer, |
| 548 | const RawAddress& bda_peer, |
| 549 | const Octet16& irk_peer, |
| 550 | const Octet16& irk_local) { |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 551 | BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); |
| 552 | uint8_t* pp = (uint8_t*)(p + 1); |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 553 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 554 | p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_ADD_DEV_RESOLVING_LIST; |
| 555 | p->offset = 0; |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 556 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 557 | UINT16_TO_STREAM(pp, HCI_BLE_ADD_DEV_RESOLVING_LIST); |
| 558 | UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_BLE_ADD_DEV_RESOLVING_LIST); |
| 559 | UINT8_TO_STREAM(pp, addr_type_peer); |
Jakub Pawlowski | b8a477e | 2017-06-16 15:16:15 -0700 | [diff] [blame] | 560 | BDADDR_TO_STREAM(pp, bda_peer); |
Jakub Pawlowski | ae57211 | 2018-06-14 17:40:34 -0700 | [diff] [blame] | 561 | ARRAY_TO_STREAM(pp, irk_peer.data(), HCIC_BLE_ENCRYT_KEY_SIZE); |
| 562 | ARRAY_TO_STREAM(pp, irk_local.data(), HCIC_BLE_ENCRYT_KEY_SIZE); |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 563 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 564 | btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 565 | } |
| 566 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 567 | void btsnd_hcic_ble_rm_device_resolving_list(uint8_t addr_type_peer, |
Jakub Pawlowski | a484a88 | 2017-06-24 17:30:18 -0700 | [diff] [blame] | 568 | const RawAddress& bda_peer) { |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 569 | BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); |
| 570 | uint8_t* pp = (uint8_t*)(p + 1); |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 571 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 572 | p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_RM_DEV_RESOLVING_LIST; |
| 573 | p->offset = 0; |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 574 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 575 | UINT16_TO_STREAM(pp, HCI_BLE_RM_DEV_RESOLVING_LIST); |
| 576 | UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_BLE_RM_DEV_RESOLVING_LIST); |
| 577 | UINT8_TO_STREAM(pp, addr_type_peer); |
Jakub Pawlowski | b8a477e | 2017-06-16 15:16:15 -0700 | [diff] [blame] | 578 | BDADDR_TO_STREAM(pp, bda_peer); |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 579 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 580 | btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 581 | } |
| 582 | |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 583 | void btsnd_hcic_ble_set_privacy_mode(uint8_t addr_type_peer, |
Jakub Pawlowski | a484a88 | 2017-06-24 17:30:18 -0700 | [diff] [blame] | 584 | const RawAddress& bda_peer, |
Jakub Pawlowski | f6db7cb | 2017-04-07 06:19:50 -0700 | [diff] [blame] | 585 | uint8_t privacy_type) { |
| 586 | BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); |
| 587 | uint8_t* pp = (uint8_t*)(p + 1); |
| 588 | |
| 589 | p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_SET_PRIVACY_MODE; |
| 590 | p->offset = 0; |
| 591 | |
| 592 | UINT16_TO_STREAM(pp, HCI_BLE_SET_PRIVACY_MODE); |
| 593 | UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_BLE_SET_PRIVACY_MODE); |
| 594 | UINT8_TO_STREAM(pp, addr_type_peer); |
Jakub Pawlowski | b8a477e | 2017-06-16 15:16:15 -0700 | [diff] [blame] | 595 | BDADDR_TO_STREAM(pp, bda_peer); |
Jakub Pawlowski | f6db7cb | 2017-04-07 06:19:50 -0700 | [diff] [blame] | 596 | UINT8_TO_STREAM(pp, privacy_type); |
| 597 | |
| 598 | btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); |
| 599 | } |
| 600 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 601 | void btsnd_hcic_ble_clear_resolving_list(void) { |
| 602 | BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); |
| 603 | uint8_t* pp = (uint8_t*)(p + 1); |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 604 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 605 | p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_CLEAR_RESOLVING_LIST; |
| 606 | p->offset = 0; |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 607 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 608 | UINT16_TO_STREAM(pp, HCI_BLE_CLEAR_RESOLVING_LIST); |
| 609 | UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_BLE_CLEAR_RESOLVING_LIST); |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 610 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 611 | btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 612 | } |
| 613 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 614 | void btsnd_hcic_ble_read_resolvable_addr_peer(uint8_t addr_type_peer, |
Jakub Pawlowski | a484a88 | 2017-06-24 17:30:18 -0700 | [diff] [blame] | 615 | const RawAddress& bda_peer) { |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 616 | BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); |
| 617 | uint8_t* pp = (uint8_t*)(p + 1); |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 618 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 619 | p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_READ_RESOLVABLE_ADDR_PEER; |
| 620 | p->offset = 0; |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 621 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 622 | UINT16_TO_STREAM(pp, HCI_BLE_READ_RESOLVABLE_ADDR_PEER); |
| 623 | UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_BLE_READ_RESOLVABLE_ADDR_PEER); |
| 624 | UINT8_TO_STREAM(pp, addr_type_peer); |
Jakub Pawlowski | b8a477e | 2017-06-16 15:16:15 -0700 | [diff] [blame] | 625 | BDADDR_TO_STREAM(pp, bda_peer); |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 626 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 627 | btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 628 | } |
| 629 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 630 | void btsnd_hcic_ble_read_resolvable_addr_local(uint8_t addr_type_peer, |
Jakub Pawlowski | a484a88 | 2017-06-24 17:30:18 -0700 | [diff] [blame] | 631 | const RawAddress& bda_peer) { |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 632 | BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); |
| 633 | uint8_t* pp = (uint8_t*)(p + 1); |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 634 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 635 | p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_READ_RESOLVABLE_ADDR_LOCAL; |
| 636 | p->offset = 0; |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 637 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 638 | UINT16_TO_STREAM(pp, HCI_BLE_READ_RESOLVABLE_ADDR_LOCAL); |
| 639 | UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_BLE_READ_RESOLVABLE_ADDR_LOCAL); |
| 640 | UINT8_TO_STREAM(pp, addr_type_peer); |
| 641 | BDADDR_TO_STREAM(pp, bda_peer); |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 642 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 643 | btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 644 | } |
| 645 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 646 | void btsnd_hcic_ble_set_addr_resolution_enable(uint8_t addr_resolution_enable) { |
| 647 | BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); |
| 648 | uint8_t* pp = (uint8_t*)(p + 1); |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 649 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 650 | p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_SET_ADDR_RESOLUTION_ENABLE; |
| 651 | p->offset = 0; |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 652 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 653 | UINT16_TO_STREAM(pp, HCI_BLE_SET_ADDR_RESOLUTION_ENABLE); |
| 654 | UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_BLE_SET_ADDR_RESOLUTION_ENABLE); |
| 655 | UINT8_TO_STREAM(pp, addr_resolution_enable); |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 656 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 657 | btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 658 | } |
| 659 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 660 | void btsnd_hcic_ble_set_rand_priv_addr_timeout(uint16_t rpa_timout) { |
| 661 | BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); |
| 662 | uint8_t* pp = (uint8_t*)(p + 1); |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 663 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 664 | p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_SET_RAND_PRIV_ADDR_TIMOUT; |
| 665 | p->offset = 0; |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 666 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 667 | UINT16_TO_STREAM(pp, HCI_BLE_SET_RAND_PRIV_ADDR_TIMOUT); |
| 668 | UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_BLE_SET_RAND_PRIV_ADDR_TIMOUT); |
| 669 | UINT16_TO_STREAM(pp, rpa_timout); |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 670 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 671 | btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 672 | } |
| 673 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 674 | void btsnd_hcic_ble_set_data_length(uint16_t conn_handle, uint16_t tx_octets, |
| 675 | uint16_t tx_time) { |
| 676 | BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); |
| 677 | uint8_t* pp = (uint8_t*)(p + 1); |
Priti Aghera | 636d671 | 2014-12-18 13:55:48 -0800 | [diff] [blame] | 678 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 679 | p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_SET_DATA_LENGTH; |
| 680 | p->offset = 0; |
Priti Aghera | 636d671 | 2014-12-18 13:55:48 -0800 | [diff] [blame] | 681 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 682 | UINT16_TO_STREAM(pp, HCI_BLE_SET_DATA_LENGTH); |
| 683 | UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_BLE_SET_DATA_LENGTH); |
Priti Aghera | 636d671 | 2014-12-18 13:55:48 -0800 | [diff] [blame] | 684 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 685 | UINT16_TO_STREAM(pp, conn_handle); |
| 686 | UINT16_TO_STREAM(pp, tx_octets); |
| 687 | UINT16_TO_STREAM(pp, tx_time); |
Priti Aghera | 636d671 | 2014-12-18 13:55:48 -0800 | [diff] [blame] | 688 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 689 | btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); |
Priti Aghera | 636d671 | 2014-12-18 13:55:48 -0800 | [diff] [blame] | 690 | } |
Jakub Pawlowski | 9df2a55 | 2016-12-02 11:34:06 -0800 | [diff] [blame] | 691 | |
Avish Shah | 5a475e7 | 2017-04-13 17:15:20 +0530 | [diff] [blame] | 692 | void btsnd_hcic_ble_enh_rx_test(uint8_t rx_chan, uint8_t phy, |
| 693 | uint8_t mod_index) { |
| 694 | BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); |
| 695 | uint8_t* pp = (uint8_t*)(p + 1); |
| 696 | |
| 697 | p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_ENH_RX_TEST; |
| 698 | p->offset = 0; |
| 699 | |
| 700 | UINT16_TO_STREAM(pp, HCI_BLE_ENH_RECEIVER_TEST); |
| 701 | UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_BLE_ENH_RX_TEST); |
| 702 | |
| 703 | UINT8_TO_STREAM(pp, rx_chan); |
| 704 | UINT8_TO_STREAM(pp, phy); |
| 705 | UINT8_TO_STREAM(pp, mod_index); |
| 706 | |
| 707 | btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); |
| 708 | } |
| 709 | |
| 710 | void btsnd_hcic_ble_enh_tx_test(uint8_t tx_chan, uint8_t data_len, |
| 711 | uint8_t payload, uint8_t phy) { |
| 712 | BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); |
| 713 | uint8_t* pp = (uint8_t*)(p + 1); |
| 714 | |
| 715 | p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_ENH_TX_TEST; |
| 716 | p->offset = 0; |
| 717 | |
| 718 | UINT16_TO_STREAM(pp, HCI_BLE_ENH_TRANSMITTER_TEST); |
| 719 | UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_BLE_ENH_TX_TEST); |
| 720 | UINT8_TO_STREAM(pp, tx_chan); |
| 721 | UINT8_TO_STREAM(pp, data_len); |
| 722 | UINT8_TO_STREAM(pp, payload); |
| 723 | UINT8_TO_STREAM(pp, phy); |
| 724 | |
| 725 | btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); |
| 726 | } |
| 727 | |
Jakub Pawlowski | 9df2a55 | 2016-12-02 11:34:06 -0800 | [diff] [blame] | 728 | void btsnd_hcic_ble_set_extended_scan_params(uint8_t own_address_type, |
| 729 | uint8_t scanning_filter_policy, |
| 730 | uint8_t scanning_phys, |
| 731 | scanning_phy_cfg* phy_cfg) { |
| 732 | BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); |
| 733 | uint8_t* pp = (uint8_t*)(p + 1); |
| 734 | |
Jakub Pawlowski | 42300f2 | 2017-02-10 15:17:52 -0800 | [diff] [blame] | 735 | int phy_cnt = |
| 736 | std::bitset<std::numeric_limits<uint8_t>::digits>(scanning_phys).count(); |
| 737 | |
| 738 | uint16_t param_len = 3 + (5 * phy_cnt); |
Reddy Praveen | 0c86aad | 2017-01-13 16:57:37 +0530 | [diff] [blame] | 739 | p->len = HCIC_PREAMBLE_SIZE + param_len; |
Jakub Pawlowski | 9df2a55 | 2016-12-02 11:34:06 -0800 | [diff] [blame] | 740 | p->offset = 0; |
| 741 | |
| 742 | UINT16_TO_STREAM(pp, HCI_LE_SET_EXTENDED_SCAN_PARAMETERS); |
| 743 | UINT8_TO_STREAM(pp, param_len); |
| 744 | |
| 745 | UINT8_TO_STREAM(pp, own_address_type); |
| 746 | UINT8_TO_STREAM(pp, scanning_filter_policy); |
| 747 | UINT8_TO_STREAM(pp, scanning_phys); |
| 748 | |
Jakub Pawlowski | 42300f2 | 2017-02-10 15:17:52 -0800 | [diff] [blame] | 749 | for (int i = 0; i < phy_cnt; i++) { |
Jakub Pawlowski | 9df2a55 | 2016-12-02 11:34:06 -0800 | [diff] [blame] | 750 | UINT8_TO_STREAM(pp, phy_cfg[i].scan_type); |
| 751 | UINT16_TO_STREAM(pp, phy_cfg[i].scan_int); |
| 752 | UINT16_TO_STREAM(pp, phy_cfg[i].scan_win); |
| 753 | } |
| 754 | |
| 755 | btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); |
| 756 | } |
| 757 | |
| 758 | void btsnd_hcic_ble_set_extended_scan_enable(uint8_t enable, |
| 759 | uint8_t filter_duplicates, |
| 760 | uint16_t duration, |
| 761 | uint16_t period) { |
| 762 | BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); |
| 763 | uint8_t* pp = (uint8_t*)(p + 1); |
| 764 | |
| 765 | const int param_len = 6; |
| 766 | p->len = HCIC_PREAMBLE_SIZE + param_len; |
| 767 | p->offset = 0; |
| 768 | |
| 769 | UINT16_TO_STREAM(pp, HCI_LE_SET_EXTENDED_SCAN_ENABLE); |
| 770 | UINT8_TO_STREAM(pp, param_len); |
| 771 | |
| 772 | UINT8_TO_STREAM(pp, enable); |
| 773 | UINT8_TO_STREAM(pp, filter_duplicates); |
| 774 | UINT16_TO_STREAM(pp, duration); |
| 775 | UINT16_TO_STREAM(pp, period); |
| 776 | |
| 777 | btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); |
| 778 | } |
Jakub Pawlowski | 93df860 | 2017-02-15 08:35:30 -0800 | [diff] [blame] | 779 | |
| 780 | void btsnd_hcic_ble_ext_create_conn(uint8_t init_filter_policy, |
| 781 | uint8_t addr_type_own, |
Jakub Pawlowski | b8a477e | 2017-06-16 15:16:15 -0700 | [diff] [blame] | 782 | uint8_t addr_type_peer, |
Jakub Pawlowski | a484a88 | 2017-06-24 17:30:18 -0700 | [diff] [blame] | 783 | const RawAddress& bda_peer, |
Jakub Pawlowski | 93df860 | 2017-02-15 08:35:30 -0800 | [diff] [blame] | 784 | uint8_t initiating_phys, |
| 785 | EXT_CONN_PHY_CFG* phy_cfg) { |
| 786 | BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); |
| 787 | uint8_t* pp = (uint8_t*)(p + 1); |
| 788 | |
| 789 | int phy_cnt = |
| 790 | std::bitset<std::numeric_limits<uint8_t>::digits>(initiating_phys) |
| 791 | .count(); |
| 792 | |
| 793 | /* param_len = initial_params + size_per_channel * num_of_channels */ |
| 794 | uint8_t param_len = 10 + (16 * phy_cnt); |
| 795 | |
| 796 | p->len = HCIC_PREAMBLE_SIZE + param_len; |
| 797 | p->offset = 0; |
| 798 | |
| 799 | UINT16_TO_STREAM(pp, HCI_LE_EXTENDED_CREATE_CONNECTION); |
| 800 | UINT8_TO_STREAM(pp, param_len); |
| 801 | |
| 802 | UINT8_TO_STREAM(pp, init_filter_policy); |
| 803 | UINT8_TO_STREAM(pp, addr_type_own); |
| 804 | UINT8_TO_STREAM(pp, addr_type_peer); |
| 805 | BDADDR_TO_STREAM(pp, bda_peer); |
| 806 | |
| 807 | UINT8_TO_STREAM(pp, initiating_phys); |
| 808 | |
| 809 | for (int i = 0; i < phy_cnt; i++) { |
| 810 | UINT16_TO_STREAM(pp, phy_cfg[i].scan_int); |
| 811 | UINT16_TO_STREAM(pp, phy_cfg[i].scan_win); |
| 812 | UINT16_TO_STREAM(pp, phy_cfg[i].conn_int_min); |
| 813 | UINT16_TO_STREAM(pp, phy_cfg[i].conn_int_max); |
| 814 | UINT16_TO_STREAM(pp, phy_cfg[i].conn_latency); |
| 815 | UINT16_TO_STREAM(pp, phy_cfg[i].sup_timeout); |
| 816 | UINT16_TO_STREAM(pp, phy_cfg[i].min_ce_len); |
| 817 | UINT16_TO_STREAM(pp, phy_cfg[i].max_ce_len); |
| 818 | } |
| 819 | |
| 820 | btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); |
| 821 | } |