The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
Wei Wang | a6ce775 | 2014-05-20 06:30:32 +0000 | [diff] [blame] | 3 | * Copyright (C) 2008-2014 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 functions for BLE GAP. |
| 22 | * |
| 23 | ******************************************************************************/ |
| 24 | |
Marie Janssen | 49a8670 | 2015-07-08 11:48:57 -0700 | [diff] [blame] | 25 | #define LOG_TAG "bt_btm_ble" |
| 26 | |
Jakub Pawlowski | 0c68323 | 2017-02-24 09:49:59 -0800 | [diff] [blame] | 27 | #include <base/bind.h> |
Jakub Pawlowski | 119f32a | 2017-02-16 11:56:56 -0800 | [diff] [blame] | 28 | #include <base/callback.h> |
Jakub Pawlowski | 0595ca0 | 2017-02-07 12:15:06 -0800 | [diff] [blame] | 29 | #include <base/strings/string_number_conversions.h> |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 30 | #include <stddef.h> |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 31 | #include <stdio.h> |
| 32 | #include <string.h> |
Jakub Pawlowski | 0595ca0 | 2017-02-07 12:15:06 -0800 | [diff] [blame] | 33 | #include <list> |
| 34 | #include <vector> |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 35 | |
| 36 | #include "bt_types.h" |
Mike J. Chen | 5cd8bff | 2014-01-31 18:16:59 -0800 | [diff] [blame] | 37 | #include "bt_utils.h" |
Wei Wang | 21015a4 | 2014-10-03 10:58:03 -0700 | [diff] [blame] | 38 | #include "btm_ble_api.h" |
Marie Janssen | 49a8670 | 2015-07-08 11:48:57 -0700 | [diff] [blame] | 39 | #include "btm_int.h" |
Wei Wang | 21015a4 | 2014-10-03 10:58:03 -0700 | [diff] [blame] | 40 | #include "btu.h" |
Chris Manton | 79ecab5 | 2014-10-31 14:54:51 -0700 | [diff] [blame] | 41 | #include "device/include/controller.h" |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 42 | #include "gap_api.h" |
Marie Janssen | 49a8670 | 2015-07-08 11:48:57 -0700 | [diff] [blame] | 43 | #include "hcimsgs.h" |
Myles Watson | d7ffd64 | 2016-10-27 10:27:36 -0700 | [diff] [blame] | 44 | #include "osi/include/osi.h" |
Prerepa Viswanadham | 16fe082 | 2014-08-07 11:38:06 -0700 | [diff] [blame] | 45 | |
Jakub Pawlowski | 103b2c4 | 2017-04-28 14:59:46 -0700 | [diff] [blame] | 46 | #include "advertise_data_parser.h" |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 47 | #include "btm_ble_int.h" |
Marie Janssen | 49a8670 | 2015-07-08 11:48:57 -0700 | [diff] [blame] | 48 | #include "gatt_int.h" |
| 49 | #include "gattdefs.h" |
| 50 | #include "l2c_int.h" |
Sharvil Nanavati | 4480276 | 2014-12-23 23:08:58 -0800 | [diff] [blame] | 51 | #include "osi/include/log.h" |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 52 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 53 | #define BTM_BLE_NAME_SHORT 0x01 |
| 54 | #define BTM_BLE_NAME_CMPL 0x02 |
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 | #define BTM_BLE_FILTER_TARGET_UNKNOWN 0xff |
| 57 | #define BTM_BLE_POLICY_UNKNOWN 0xff |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 58 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 59 | #define BTM_EXT_BLE_RMT_NAME_TIMEOUT_MS (30 * 1000) |
| 60 | #define MIN_ADV_LENGTH 2 |
Satya Calloji | 935324a | 2015-03-31 13:24:32 -0700 | [diff] [blame] | 61 | #define BTM_VSC_CHIP_CAPABILITY_RSP_LEN_L_RELEASE 9 |
| 62 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 63 | extern fixed_queue_t* btu_general_alarm_queue; |
Pavlin Radoslavov | 78bcff7 | 2015-12-04 17:36:34 -0800 | [diff] [blame] | 64 | |
Jakub Pawlowski | 0595ca0 | 2017-02-07 12:15:06 -0800 | [diff] [blame] | 65 | namespace { |
| 66 | |
| 67 | class AdvertisingCache { |
| 68 | public: |
| 69 | /* Set the data to |data| for device |addr_type, addr| */ |
Jakub Pawlowski | a484a88 | 2017-06-24 17:30:18 -0700 | [diff] [blame] | 70 | const std::vector<uint8_t>& Set(uint8_t addr_type, const RawAddress& addr, |
Jakub Pawlowski | 0595ca0 | 2017-02-07 12:15:06 -0800 | [diff] [blame] | 71 | std::vector<uint8_t> data) { |
| 72 | auto it = Find(addr_type, addr); |
| 73 | if (it != items.end()) { |
| 74 | it->data = std::move(data); |
| 75 | return it->data; |
| 76 | } |
| 77 | |
| 78 | if (items.size() > cache_max) { |
| 79 | items.pop_back(); |
| 80 | } |
| 81 | |
| 82 | items.emplace_front(addr_type, addr, std::move(data)); |
| 83 | return items.front().data; |
| 84 | } |
| 85 | |
| 86 | /* Append |data| for device |addr_type, addr| */ |
Jakub Pawlowski | a484a88 | 2017-06-24 17:30:18 -0700 | [diff] [blame] | 87 | const std::vector<uint8_t>& Append(uint8_t addr_type, const RawAddress& addr, |
Jakub Pawlowski | 0595ca0 | 2017-02-07 12:15:06 -0800 | [diff] [blame] | 88 | std::vector<uint8_t> data) { |
| 89 | auto it = Find(addr_type, addr); |
| 90 | if (it != items.end()) { |
| 91 | it->data.insert(it->data.end(), data.begin(), data.end()); |
| 92 | return it->data; |
| 93 | } |
| 94 | |
| 95 | if (items.size() > cache_max) { |
| 96 | items.pop_back(); |
| 97 | } |
| 98 | |
| 99 | items.emplace_front(addr_type, addr, std::move(data)); |
| 100 | return items.front().data; |
| 101 | } |
| 102 | |
| 103 | /* Clear data for device |addr_type, addr| */ |
Jakub Pawlowski | a484a88 | 2017-06-24 17:30:18 -0700 | [diff] [blame] | 104 | void Clear(uint8_t addr_type, const RawAddress& addr) { |
Jakub Pawlowski | 0595ca0 | 2017-02-07 12:15:06 -0800 | [diff] [blame] | 105 | auto it = Find(addr_type, addr); |
| 106 | if (it != items.end()) { |
| 107 | items.erase(it); |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | private: |
| 112 | struct Item { |
| 113 | uint8_t addr_type; |
Jakub Pawlowski | a484a88 | 2017-06-24 17:30:18 -0700 | [diff] [blame] | 114 | RawAddress addr; |
Jakub Pawlowski | 0595ca0 | 2017-02-07 12:15:06 -0800 | [diff] [blame] | 115 | std::vector<uint8_t> data; |
| 116 | |
Jakub Pawlowski | a484a88 | 2017-06-24 17:30:18 -0700 | [diff] [blame] | 117 | Item(uint8_t addr_type, const RawAddress& addr, std::vector<uint8_t> data) |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 118 | : addr_type(addr_type), addr(addr), data(data) {} |
Jakub Pawlowski | 0595ca0 | 2017-02-07 12:15:06 -0800 | [diff] [blame] | 119 | }; |
| 120 | |
Jakub Pawlowski | a484a88 | 2017-06-24 17:30:18 -0700 | [diff] [blame] | 121 | std::list<Item>::iterator Find(uint8_t addr_type, const RawAddress& addr) { |
Jakub Pawlowski | 0595ca0 | 2017-02-07 12:15:06 -0800 | [diff] [blame] | 122 | for (auto it = items.begin(); it != items.end(); it++) { |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 123 | if (it->addr_type == addr_type && it->addr == addr) { |
Jakub Pawlowski | 0595ca0 | 2017-02-07 12:15:06 -0800 | [diff] [blame] | 124 | return it; |
| 125 | } |
| 126 | } |
| 127 | return items.end(); |
| 128 | } |
| 129 | |
| 130 | /* we keep maximum 7 devices in the cache */ |
| 131 | const size_t cache_max = 7; |
| 132 | std::list<Item> items; |
| 133 | }; |
| 134 | |
| 135 | /* Devices in this cache are waiting for eiter scan response, or chained packets |
| 136 | * on secondary channel */ |
| 137 | AdvertisingCache cache; |
| 138 | |
| 139 | } // namespace |
| 140 | |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 141 | #if (BLE_VND_INCLUDED == TRUE) |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 142 | static tBTM_BLE_CTRL_FEATURES_CBACK* p_ctrl_le_feature_rd_cmpl_cback = NULL; |
Bernhard Rosenkränzer | 104e3f2 | 2014-11-12 21:53:08 +0100 | [diff] [blame] | 143 | #endif |
Ganesh Ganapathi Batta | 8d41691 | 2014-05-30 16:28:00 -0700 | [diff] [blame] | 144 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 145 | /******************************************************************************* |
Myles Watson | ee96a3c | 2016-11-23 14:49:54 -0800 | [diff] [blame] | 146 | * Local functions |
| 147 | ******************************************************************************/ |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 148 | static void btm_ble_update_adv_flag(uint8_t flag); |
Jakub Pawlowski | 7de0f9b | 2017-01-27 08:06:20 -0800 | [diff] [blame] | 149 | static void btm_ble_process_adv_pkt_cont( |
Jakub Pawlowski | a484a88 | 2017-06-24 17:30:18 -0700 | [diff] [blame] | 150 | uint16_t evt_type, uint8_t addr_type, const RawAddress& bda, |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 151 | uint8_t primary_phy, uint8_t secondary_phy, uint8_t advertising_sid, |
| 152 | int8_t tx_power, int8_t rssi, uint16_t periodic_adv_int, uint8_t data_len, |
| 153 | uint8_t* data); |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 154 | static uint8_t btm_set_conn_mode_adv_init_addr(tBTM_BLE_INQ_CB* p_cb, |
Jakub Pawlowski | a484a88 | 2017-06-24 17:30:18 -0700 | [diff] [blame] | 155 | RawAddress& p_peer_addr_ptr, |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 156 | tBLE_ADDR_TYPE* p_peer_addr_type, |
| 157 | tBLE_ADDR_TYPE* p_own_addr_type); |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 158 | static void btm_ble_stop_observe(void); |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 159 | static void btm_ble_fast_adv_timer_timeout(void* data); |
Pavlin Radoslavov | 78bcff7 | 2015-12-04 17:36:34 -0800 | [diff] [blame] | 160 | static void btm_ble_start_slow_adv(void); |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 161 | static void btm_ble_inquiry_timer_gap_limited_discovery_timeout(void* data); |
| 162 | static void btm_ble_inquiry_timer_timeout(void* data); |
| 163 | static void btm_ble_observer_timer_timeout(void* data); |
Pavlin Radoslavov | 78bcff7 | 2015-12-04 17:36:34 -0800 | [diff] [blame] | 164 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 165 | #define BTM_BLE_INQ_RESULT 0x01 |
| 166 | #define BTM_BLE_OBS_RESULT 0x02 |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 167 | |
Jakub Pawlowski | d64bf4f | 2017-01-27 05:53:07 -0800 | [diff] [blame] | 168 | bool ble_evt_type_is_connectable(uint16_t evt_type) { |
| 169 | return evt_type & (1 << BLE_EVT_CONNECTABLE_BIT); |
| 170 | } |
| 171 | |
| 172 | bool ble_evt_type_is_scannable(uint16_t evt_type) { |
| 173 | return evt_type & (1 << BLE_EVT_SCANNABLE_BIT); |
| 174 | } |
| 175 | |
| 176 | bool ble_evt_type_is_directed(uint16_t evt_type) { |
| 177 | return evt_type & (1 << BLE_EVT_DIRECTED_BIT); |
| 178 | } |
| 179 | |
| 180 | bool ble_evt_type_is_scan_resp(uint16_t evt_type) { |
| 181 | return evt_type & (1 << BLE_EVT_SCAN_RESPONSE_BIT); |
| 182 | } |
| 183 | |
| 184 | bool ble_evt_type_is_legacy(uint16_t evt_type) { |
| 185 | return evt_type & (1 << BLE_EVT_LEGACY_BIT); |
| 186 | } |
| 187 | |
Jakub Pawlowski | 0595ca0 | 2017-02-07 12:15:06 -0800 | [diff] [blame] | 188 | uint8_t ble_evt_type_data_status(uint16_t evt_type) { |
| 189 | return (evt_type >> 5) & 3; |
| 190 | } |
| 191 | |
Jakub Pawlowski | 5e43c80 | 2017-06-26 17:22:35 -0700 | [diff] [blame] | 192 | constexpr uint8_t UNSUPPORTED = 255; |
| 193 | |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 194 | /* LE states combo bit to check */ |
Jakub Pawlowski | 5e43c80 | 2017-06-26 17:22:35 -0700 | [diff] [blame] | 195 | const uint8_t btm_le_state_combo_tbl[BTM_BLE_STATE_MAX][BTM_BLE_STATE_MAX] = { |
| 196 | { |
| 197 | /* single state support */ |
| 198 | HCI_LE_STATES_CONN_ADV_BIT, /* conn_adv */ |
| 199 | HCI_LE_STATES_INIT_BIT, /* init */ |
| 200 | HCI_LE_STATES_INIT_BIT, /* master */ |
| 201 | HCI_LE_STATES_SLAVE_BIT, /* slave */ |
| 202 | UNSUPPORTED, /* todo: lo du dir adv, not covered ? */ |
| 203 | HCI_LE_STATES_HI_DUTY_DIR_ADV_BIT, /* hi duty dir adv */ |
| 204 | HCI_LE_STATES_NON_CONN_ADV_BIT, /* non connectable adv */ |
| 205 | HCI_LE_STATES_PASS_SCAN_BIT, /* passive scan */ |
| 206 | HCI_LE_STATES_ACTIVE_SCAN_BIT, /* active scan */ |
| 207 | HCI_LE_STATES_SCAN_ADV_BIT /* scanable adv */ |
| 208 | }, |
| 209 | { |
| 210 | /* conn_adv =0 */ |
| 211 | UNSUPPORTED, /* conn_adv */ |
| 212 | HCI_LE_STATES_CONN_ADV_INIT_BIT, /* init: 32 */ |
| 213 | HCI_LE_STATES_CONN_ADV_MASTER_BIT, /* master: 35 */ |
| 214 | HCI_LE_STATES_CONN_ADV_SLAVE_BIT, /* slave: 38,*/ |
| 215 | UNSUPPORTED, /* lo du dir adv */ |
| 216 | UNSUPPORTED, /* hi duty dir adv */ |
| 217 | UNSUPPORTED, /* non connectable adv */ |
| 218 | HCI_LE_STATES_CONN_ADV_PASS_SCAN_BIT, /* passive scan */ |
| 219 | HCI_LE_STATES_CONN_ADV_ACTIVE_SCAN_BIT, /* active scan */ |
| 220 | UNSUPPORTED /* scanable adv */ |
| 221 | }, |
| 222 | { |
| 223 | /* init */ |
| 224 | HCI_LE_STATES_CONN_ADV_INIT_BIT, /* conn_adv: 32 */ |
| 225 | UNSUPPORTED, /* init */ |
| 226 | HCI_LE_STATES_INIT_MASTER_BIT, /* master 28 */ |
| 227 | HCI_LE_STATES_INIT_MASTER_SLAVE_BIT, /* slave 41 */ |
| 228 | HCI_LE_STATES_LO_DUTY_DIR_ADV_INIT_BIT, /* lo du dir adv 34 */ |
| 229 | HCI_LE_STATES_HI_DUTY_DIR_ADV_INIT_BIT, /* hi duty dir adv 33 */ |
| 230 | HCI_LE_STATES_NON_CONN_INIT_BIT, /* non connectable adv */ |
| 231 | HCI_LE_STATES_PASS_SCAN_INIT_BIT, /* passive scan */ |
| 232 | HCI_LE_STATES_ACTIVE_SCAN_INIT_BIT, /* active scan */ |
| 233 | HCI_LE_STATES_SCAN_ADV_INIT_BIT /* scanable adv */ |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 234 | |
Jakub Pawlowski | 5e43c80 | 2017-06-26 17:22:35 -0700 | [diff] [blame] | 235 | }, |
| 236 | { |
| 237 | /* master */ |
| 238 | HCI_LE_STATES_CONN_ADV_MASTER_BIT, /* conn_adv: 35 */ |
| 239 | HCI_LE_STATES_INIT_MASTER_BIT, /* init 28 */ |
| 240 | HCI_LE_STATES_INIT_MASTER_BIT, /* master 28 */ |
| 241 | HCI_LE_STATES_CONN_ADV_INIT_BIT, /* slave: 32 */ |
| 242 | HCI_LE_STATES_LO_DUTY_DIR_ADV_MASTER_BIT, /* lo duty cycle adv 37 */ |
| 243 | HCI_LE_STATES_HI_DUTY_DIR_ADV_MASTER_BIT, /* hi duty cycle adv 36 */ |
| 244 | HCI_LE_STATES_NON_CONN_ADV_MASTER_BIT, /* non connectable adv*/ |
| 245 | HCI_LE_STATES_PASS_SCAN_MASTER_BIT, /* passive scan */ |
| 246 | HCI_LE_STATES_ACTIVE_SCAN_MASTER_BIT, /* active scan */ |
| 247 | HCI_LE_STATES_SCAN_ADV_MASTER_BIT /* scanable adv */ |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 248 | |
Jakub Pawlowski | 5e43c80 | 2017-06-26 17:22:35 -0700 | [diff] [blame] | 249 | }, |
| 250 | { |
| 251 | /* slave */ |
| 252 | HCI_LE_STATES_CONN_ADV_SLAVE_BIT, /* conn_adv: 38,*/ |
| 253 | HCI_LE_STATES_INIT_MASTER_SLAVE_BIT, /* init 41 */ |
| 254 | HCI_LE_STATES_INIT_MASTER_SLAVE_BIT, /* master 41 */ |
| 255 | HCI_LE_STATES_CONN_ADV_SLAVE_BIT, /* slave: 38,*/ |
| 256 | HCI_LE_STATES_LO_DUTY_DIR_ADV_SLAVE_BIT, /* lo duty cycle adv 40 */ |
| 257 | HCI_LE_STATES_HI_DUTY_DIR_ADV_SLAVE_BIT, /* hi duty cycle adv 39 */ |
| 258 | HCI_LE_STATES_NON_CONN_ADV_SLAVE_BIT, /* non connectable adv */ |
| 259 | HCI_LE_STATES_PASS_SCAN_SLAVE_BIT, /* passive scan */ |
| 260 | HCI_LE_STATES_ACTIVE_SCAN_SLAVE_BIT, /* active scan */ |
| 261 | HCI_LE_STATES_SCAN_ADV_SLAVE_BIT /* scanable adv */ |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 262 | |
Jakub Pawlowski | 5e43c80 | 2017-06-26 17:22:35 -0700 | [diff] [blame] | 263 | }, |
| 264 | { |
| 265 | /* lo duty cycle adv */ |
| 266 | UNSUPPORTED, /* conn_adv: 38,*/ |
| 267 | HCI_LE_STATES_LO_DUTY_DIR_ADV_INIT_BIT, /* init 34 */ |
| 268 | HCI_LE_STATES_LO_DUTY_DIR_ADV_MASTER_BIT, /* master 37 */ |
| 269 | HCI_LE_STATES_LO_DUTY_DIR_ADV_SLAVE_BIT, /* slave: 40 */ |
| 270 | UNSUPPORTED, /* lo duty cycle adv 40 */ |
| 271 | UNSUPPORTED, /* hi duty cycle adv 39 */ |
| 272 | UNSUPPORTED, /* non connectable adv */ |
| 273 | UNSUPPORTED, /* TODO: passive scan, not covered? */ |
| 274 | UNSUPPORTED, /* TODO: active scan, not covered? */ |
| 275 | UNSUPPORTED /* scanable adv */ |
| 276 | }, |
| 277 | { |
| 278 | /* hi duty cycle adv */ |
| 279 | UNSUPPORTED, /* conn_adv: 38,*/ |
| 280 | HCI_LE_STATES_HI_DUTY_DIR_ADV_INIT_BIT, /* init 33 */ |
| 281 | HCI_LE_STATES_HI_DUTY_DIR_ADV_MASTER_BIT, /* master 36 */ |
| 282 | HCI_LE_STATES_HI_DUTY_DIR_ADV_SLAVE_BIT, /* slave: 39*/ |
| 283 | UNSUPPORTED, /* lo duty cycle adv 40 */ |
| 284 | UNSUPPORTED, /* hi duty cycle adv 39 */ |
| 285 | UNSUPPORTED, /* non connectable adv */ |
| 286 | HCI_LE_STATES_HI_DUTY_DIR_ADV_PASS_SCAN_BIT, /* passive scan */ |
| 287 | HCI_LE_STATES_HI_DUTY_DIR_ADV_ACTIVE_SCAN_BIT, /* active scan */ |
| 288 | UNSUPPORTED /* scanable adv */ |
| 289 | }, |
| 290 | { |
| 291 | /* non connectable adv */ |
| 292 | UNSUPPORTED, /* conn_adv: */ |
| 293 | HCI_LE_STATES_NON_CONN_INIT_BIT, /* init */ |
| 294 | HCI_LE_STATES_NON_CONN_ADV_MASTER_BIT, /* master */ |
| 295 | HCI_LE_STATES_NON_CONN_ADV_SLAVE_BIT, /* slave: */ |
| 296 | UNSUPPORTED, /* lo duty cycle adv */ |
| 297 | UNSUPPORTED, /* hi duty cycle adv */ |
| 298 | UNSUPPORTED, /* non connectable adv */ |
| 299 | HCI_LE_STATES_NON_CONN_ADV_PASS_SCAN_BIT, /* passive scan */ |
| 300 | HCI_LE_STATES_NON_CONN_ADV_ACTIVE_SCAN_BIT, /* active scan */ |
| 301 | UNSUPPORTED /* scanable adv */ |
| 302 | }, |
| 303 | { |
| 304 | /* passive scan */ |
| 305 | HCI_LE_STATES_CONN_ADV_PASS_SCAN_BIT, /* conn_adv: */ |
| 306 | HCI_LE_STATES_PASS_SCAN_INIT_BIT, /* init */ |
| 307 | HCI_LE_STATES_PASS_SCAN_MASTER_BIT, /* master */ |
| 308 | HCI_LE_STATES_PASS_SCAN_SLAVE_BIT, /* slave: */ |
| 309 | UNSUPPORTED, /* lo duty cycle adv */ |
| 310 | HCI_LE_STATES_HI_DUTY_DIR_ADV_PASS_SCAN_BIT, /* hi duty cycle adv */ |
| 311 | HCI_LE_STATES_NON_CONN_ADV_PASS_SCAN_BIT, /* non connectable adv */ |
| 312 | UNSUPPORTED, /* passive scan */ |
| 313 | UNSUPPORTED, /* active scan */ |
| 314 | HCI_LE_STATES_SCAN_ADV_PASS_SCAN_BIT /* scanable adv */ |
| 315 | }, |
| 316 | { |
| 317 | /* active scan */ |
| 318 | HCI_LE_STATES_CONN_ADV_ACTIVE_SCAN_BIT, /* conn_adv: */ |
| 319 | HCI_LE_STATES_ACTIVE_SCAN_INIT_BIT, /* init */ |
| 320 | HCI_LE_STATES_ACTIVE_SCAN_MASTER_BIT, /* master */ |
| 321 | HCI_LE_STATES_ACTIVE_SCAN_SLAVE_BIT, /* slave: */ |
| 322 | UNSUPPORTED, /* lo duty cycle adv */ |
| 323 | HCI_LE_STATES_HI_DUTY_DIR_ADV_ACTIVE_SCAN_BIT, /* hi duty cycle adv */ |
| 324 | HCI_LE_STATES_NON_CONN_ADV_ACTIVE_SCAN_BIT, /* non connectable adv */ |
| 325 | UNSUPPORTED, /* TODO: passive scan */ |
| 326 | UNSUPPORTED, /* TODO: active scan */ |
| 327 | HCI_LE_STATES_SCAN_ADV_ACTIVE_SCAN_BIT /* scanable adv */ |
| 328 | }, |
| 329 | { |
| 330 | /* scanable adv */ |
| 331 | UNSUPPORTED, /* conn_adv: */ |
| 332 | HCI_LE_STATES_SCAN_ADV_INIT_BIT, /* init */ |
| 333 | HCI_LE_STATES_SCAN_ADV_MASTER_BIT, /* master */ |
| 334 | HCI_LE_STATES_SCAN_ADV_SLAVE_BIT, /* slave: */ |
| 335 | UNSUPPORTED, /* lo duty cycle adv */ |
| 336 | UNSUPPORTED, /* hi duty cycle adv */ |
| 337 | UNSUPPORTED, /* non connectable adv */ |
| 338 | HCI_LE_STATES_SCAN_ADV_PASS_SCAN_BIT, /* passive scan */ |
| 339 | HCI_LE_STATES_SCAN_ADV_ACTIVE_SCAN_BIT, /* active scan */ |
| 340 | UNSUPPORTED /* scanable adv */ |
| 341 | }}; |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 342 | |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 343 | /* check LE combo state supported */ |
Jakub Pawlowski | 5e43c80 | 2017-06-26 17:22:35 -0700 | [diff] [blame] | 344 | inline bool BTM_LE_STATES_SUPPORTED(const uint8_t* x, uint8_t bit_num) { |
| 345 | uint8_t mask = 1 << (bit_num % 8); |
| 346 | uint8_t offset = bit_num / 8; |
| 347 | return ((x)[offset] & mask); |
| 348 | } |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 349 | |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 350 | /******************************************************************************* |
Myles Watson | ee96a3c | 2016-11-23 14:49:54 -0800 | [diff] [blame] | 351 | * |
| 352 | * Function BTM_BleUpdateAdvFilterPolicy |
| 353 | * |
| 354 | * Description This function update the filter policy of advertiser. |
| 355 | * |
| 356 | * Parameter adv_policy: advertising filter policy |
| 357 | * |
| 358 | * Return void |
| 359 | ******************************************************************************/ |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 360 | void BTM_BleUpdateAdvFilterPolicy(tBTM_BLE_AFP adv_policy) { |
| 361 | tBTM_BLE_INQ_CB* p_cb = &btm_cb.ble_ctr_cb.inq_var; |
| 362 | tBLE_ADDR_TYPE init_addr_type = BLE_ADDR_PUBLIC; |
Jakub Pawlowski | b707f44 | 2017-07-03 15:39:36 -0700 | [diff] [blame^] | 363 | RawAddress adv_address = RawAddress::kEmpty; |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 364 | uint8_t adv_mode = p_cb->adv_mode; |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 365 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 366 | BTM_TRACE_EVENT("BTM_BleUpdateAdvFilterPolicy"); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 367 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 368 | if (!controller_get_interface()->supports_ble()) return; |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 369 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 370 | if (p_cb->afp != adv_policy) { |
| 371 | p_cb->afp = adv_policy; |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 372 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 373 | /* if adv active, stop and restart */ |
| 374 | btm_ble_stop_adv(); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 375 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 376 | if (p_cb->connectable_mode & BTM_BLE_CONNECTABLE) |
| 377 | p_cb->evt_type = btm_set_conn_mode_adv_init_addr( |
Jakub Pawlowski | b707f44 | 2017-07-03 15:39:36 -0700 | [diff] [blame^] | 378 | p_cb, adv_address, &init_addr_type, &p_cb->adv_addr_type); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 379 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 380 | btsnd_hcic_ble_write_adv_params( |
| 381 | (uint16_t)(p_cb->adv_interval_min ? p_cb->adv_interval_min |
| 382 | : BTM_BLE_GAP_ADV_SLOW_INT), |
| 383 | (uint16_t)(p_cb->adv_interval_max ? p_cb->adv_interval_max |
| 384 | : BTM_BLE_GAP_ADV_SLOW_INT), |
Jakub Pawlowski | b707f44 | 2017-07-03 15:39:36 -0700 | [diff] [blame^] | 385 | p_cb->evt_type, p_cb->adv_addr_type, init_addr_type, adv_address, |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 386 | p_cb->adv_chnl_map, p_cb->afp); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 387 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 388 | if (adv_mode == BTM_BLE_ADV_ENABLE) btm_ble_start_adv(); |
| 389 | } |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 390 | } |
Satya Calloji | 935324a | 2015-03-31 13:24:32 -0700 | [diff] [blame] | 391 | |
| 392 | /******************************************************************************* |
Myles Watson | ee96a3c | 2016-11-23 14:49:54 -0800 | [diff] [blame] | 393 | * |
Myles Watson | ee96a3c | 2016-11-23 14:49:54 -0800 | [diff] [blame] | 394 | * Function BTM_BleObserve |
| 395 | * |
| 396 | * Description This procedure keep the device listening for advertising |
| 397 | * events from a broadcast device. |
| 398 | * |
| 399 | * Parameters start: start or stop observe. |
| 400 | * white_list: use white list in observer mode or not. |
| 401 | * |
| 402 | * Returns void |
| 403 | * |
| 404 | ******************************************************************************/ |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 405 | tBTM_STATUS BTM_BleObserve(bool start, uint8_t duration, |
| 406 | tBTM_INQ_RESULTS_CB* p_results_cb, |
| 407 | tBTM_CMPL_CB* p_cmpl_cb) { |
| 408 | tBTM_BLE_INQ_CB* p_inq = &btm_cb.ble_ctr_cb.inq_var; |
| 409 | tBTM_STATUS status = BTM_WRONG_MODE; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 410 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 411 | uint32_t scan_interval = |
| 412 | !p_inq->scan_interval ? BTM_BLE_GAP_DISC_SCAN_INT : p_inq->scan_interval; |
| 413 | uint32_t scan_window = |
| 414 | !p_inq->scan_window ? BTM_BLE_GAP_DISC_SCAN_WIN : p_inq->scan_window; |
Satya Calloji | 935324a | 2015-03-31 13:24:32 -0700 | [diff] [blame] | 415 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 416 | BTM_TRACE_EVENT("%s : scan_type:%d, %d, %d", __func__, |
| 417 | btm_cb.btm_inq_vars.scan_type, p_inq->scan_interval, |
| 418 | p_inq->scan_window); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 419 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 420 | if (!controller_get_interface()->supports_ble()) return BTM_ILLEGAL_VALUE; |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 421 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 422 | if (start) { |
| 423 | /* shared inquiry database, do not allow observe if any inquiry is active */ |
| 424 | if (BTM_BLE_IS_OBS_ACTIVE(btm_cb.ble_ctr_cb.scan_activity)) { |
| 425 | BTM_TRACE_ERROR("%s Observe Already Active", __func__); |
| 426 | return status; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 427 | } |
| 428 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 429 | btm_cb.ble_ctr_cb.p_obs_results_cb = p_results_cb; |
| 430 | btm_cb.ble_ctr_cb.p_obs_cmpl_cb = p_cmpl_cb; |
| 431 | status = BTM_CMD_STARTED; |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 432 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 433 | /* scan is not started */ |
| 434 | if (!BTM_BLE_IS_SCAN_ACTIVE(btm_cb.ble_ctr_cb.scan_activity)) { |
| 435 | /* allow config of scan type */ |
| 436 | p_inq->scan_type = (p_inq->scan_type == BTM_BLE_SCAN_MODE_NONE) |
| 437 | ? BTM_BLE_SCAN_MODE_ACTI |
| 438 | : p_inq->scan_type; |
| 439 | /* assume observe always not using white list */ |
| 440 | #if (defined BLE_PRIVACY_SPT && BLE_PRIVACY_SPT == true) |
| 441 | /* enable resolving list */ |
| 442 | btm_ble_enable_resolving_list_for_platform(BTM_BLE_RL_SCAN); |
| 443 | #endif |
| 444 | |
Jakub Pawlowski | defbb91 | 2017-02-10 15:24:00 -0800 | [diff] [blame] | 445 | btm_send_hci_set_scan_params( |
| 446 | p_inq->scan_type, (uint16_t)scan_interval, (uint16_t)scan_window, |
| 447 | btm_cb.ble_ctr_cb.addr_mgnt_cb.own_addr_type, BTM_BLE_DEFAULT_SFP); |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 448 | |
| 449 | p_inq->scan_duplicate_filter = BTM_BLE_DUPLICATE_DISABLE; |
| 450 | status = btm_ble_start_scan(); |
| 451 | } |
| 452 | |
| 453 | if (status == BTM_CMD_STARTED) { |
| 454 | btm_cb.ble_ctr_cb.scan_activity |= BTM_LE_OBSERVE_ACTIVE; |
| 455 | if (duration != 0) { |
| 456 | /* start observer timer */ |
| 457 | period_ms_t duration_ms = duration * 1000; |
| 458 | alarm_set_on_queue(btm_cb.ble_ctr_cb.observer_timer, duration_ms, |
| 459 | btm_ble_observer_timer_timeout, NULL, |
| 460 | btu_general_alarm_queue); |
| 461 | } |
| 462 | } |
| 463 | } else if (BTM_BLE_IS_OBS_ACTIVE(btm_cb.ble_ctr_cb.scan_activity)) { |
| 464 | status = BTM_CMD_STARTED; |
| 465 | btm_ble_stop_observe(); |
| 466 | } else { |
| 467 | BTM_TRACE_ERROR("%s Observe not active", __func__); |
| 468 | } |
| 469 | |
| 470 | return status; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 471 | } |
| 472 | |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 473 | #if (BLE_VND_INCLUDED == TRUE) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 474 | /******************************************************************************* |
Myles Watson | ee96a3c | 2016-11-23 14:49:54 -0800 | [diff] [blame] | 475 | * |
| 476 | * Function btm_vsc_brcm_features_complete |
| 477 | * |
| 478 | * Description Command Complete callback for HCI_BLE_VENDOR_CAP_OCF |
| 479 | * |
| 480 | * Returns void |
| 481 | * |
| 482 | ******************************************************************************/ |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 483 | static void btm_ble_vendor_capability_vsc_cmpl_cback( |
| 484 | tBTM_VSC_CMPL* p_vcs_cplt_params) { |
| 485 | uint8_t status = 0xFF; |
| 486 | uint8_t* p; |
Ganesh Ganapathi Batta | 8d41691 | 2014-05-30 16:28:00 -0700 | [diff] [blame] | 487 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 488 | BTM_TRACE_DEBUG("%s", __func__); |
Ganesh Ganapathi Batta | 8d41691 | 2014-05-30 16:28:00 -0700 | [diff] [blame] | 489 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 490 | /* Check status of command complete event */ |
| 491 | if ((p_vcs_cplt_params->opcode == HCI_BLE_VENDOR_CAP_OCF) && |
| 492 | (p_vcs_cplt_params->param_len > 0)) { |
| 493 | p = p_vcs_cplt_params->p_param_buf; |
| 494 | STREAM_TO_UINT8(status, p); |
| 495 | } |
| 496 | |
| 497 | if (status == HCI_SUCCESS) { |
| 498 | STREAM_TO_UINT8(btm_cb.cmn_ble_vsc_cb.adv_inst_max, p); |
| 499 | STREAM_TO_UINT8(btm_cb.cmn_ble_vsc_cb.rpa_offloading, p); |
| 500 | STREAM_TO_UINT16(btm_cb.cmn_ble_vsc_cb.tot_scan_results_strg, p); |
| 501 | STREAM_TO_UINT8(btm_cb.cmn_ble_vsc_cb.max_irk_list_sz, p); |
| 502 | STREAM_TO_UINT8(btm_cb.cmn_ble_vsc_cb.filter_support, p); |
| 503 | STREAM_TO_UINT8(btm_cb.cmn_ble_vsc_cb.max_filter, p); |
| 504 | STREAM_TO_UINT8(btm_cb.cmn_ble_vsc_cb.energy_support, p); |
| 505 | |
| 506 | if (p_vcs_cplt_params->param_len > |
| 507 | BTM_VSC_CHIP_CAPABILITY_RSP_LEN_L_RELEASE) { |
| 508 | STREAM_TO_UINT16(btm_cb.cmn_ble_vsc_cb.version_supported, p); |
| 509 | } else { |
| 510 | btm_cb.cmn_ble_vsc_cb.version_supported = |
| 511 | BTM_VSC_CHIP_CAPABILITY_L_VERSION; |
Wei Wang | a6ce775 | 2014-05-20 06:30:32 +0000 | [diff] [blame] | 512 | } |
| 513 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 514 | if (btm_cb.cmn_ble_vsc_cb.version_supported >= |
| 515 | BTM_VSC_CHIP_CAPABILITY_M_VERSION) { |
| 516 | STREAM_TO_UINT16(btm_cb.cmn_ble_vsc_cb.total_trackable_advertisers, p); |
| 517 | STREAM_TO_UINT16(btm_cb.cmn_ble_vsc_cb.extended_scan_support, p); |
| 518 | STREAM_TO_UINT16(btm_cb.cmn_ble_vsc_cb.debug_logging_supported, p); |
Wei Wang | a6ce775 | 2014-05-20 06:30:32 +0000 | [diff] [blame] | 519 | } |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 520 | btm_cb.cmn_ble_vsc_cb.values_read = true; |
| 521 | } |
Satya Calloji | c4e2596 | 2014-05-10 23:46:24 -0700 | [diff] [blame] | 522 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 523 | BTM_TRACE_DEBUG( |
| 524 | "%s: stat=%d, irk=%d, ADV ins:%d, rpa=%d, ener=%d, ext_scan=%d", __func__, |
| 525 | status, btm_cb.cmn_ble_vsc_cb.max_irk_list_sz, |
| 526 | btm_cb.cmn_ble_vsc_cb.adv_inst_max, btm_cb.cmn_ble_vsc_cb.rpa_offloading, |
| 527 | btm_cb.cmn_ble_vsc_cb.energy_support, |
| 528 | btm_cb.cmn_ble_vsc_cb.extended_scan_support); |
Prerepa Viswanadham | 16fe082 | 2014-08-07 11:38:06 -0700 | [diff] [blame] | 529 | |
Jakub Pawlowski | 2255250 | 2016-12-22 03:13:00 -0800 | [diff] [blame] | 530 | btm_ble_adv_init(); |
Prerepa Viswanadham | 16fe082 | 2014-08-07 11:38:06 -0700 | [diff] [blame] | 531 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 532 | if (btm_cb.cmn_ble_vsc_cb.max_filter > 0) btm_ble_adv_filter_init(); |
Satya Calloji | d5aa247 | 2014-09-23 18:27:09 -0700 | [diff] [blame] | 533 | |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 534 | #if (BLE_PRIVACY_SPT == TRUE) |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 535 | /* VS capability included and non-4.2 device */ |
| 536 | if (btm_cb.cmn_ble_vsc_cb.max_irk_list_sz > 0 && |
| 537 | controller_get_interface()->get_ble_resolving_list_max_size() == 0) |
| 538 | btm_ble_resolving_list_init(btm_cb.cmn_ble_vsc_cb.max_irk_list_sz); |
| 539 | #endif /* (BLE_PRIVACY_SPT == TRUE) */ |
Prerepa Viswanadham | 16fe082 | 2014-08-07 11:38:06 -0700 | [diff] [blame] | 540 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 541 | if (btm_cb.cmn_ble_vsc_cb.tot_scan_results_strg > 0) btm_ble_batchscan_init(); |
Ganesh Ganapathi Batta | 8d41691 | 2014-05-30 16:28:00 -0700 | [diff] [blame] | 542 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 543 | if (p_ctrl_le_feature_rd_cmpl_cback != NULL) |
| 544 | p_ctrl_le_feature_rd_cmpl_cback(status); |
Satya Calloji | 935324a | 2015-03-31 13:24:32 -0700 | [diff] [blame] | 545 | } |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 546 | #endif /* (BLE_VND_INCLUDED == TRUE) */ |
Wei Wang | a6ce775 | 2014-05-20 06:30:32 +0000 | [diff] [blame] | 547 | |
| 548 | /******************************************************************************* |
Myles Watson | ee96a3c | 2016-11-23 14:49:54 -0800 | [diff] [blame] | 549 | * |
| 550 | * Function BTM_BleGetVendorCapabilities |
| 551 | * |
| 552 | * Description This function reads local LE features |
| 553 | * |
| 554 | * Parameters p_cmn_vsc_cb : Locala LE capability structure |
| 555 | * |
| 556 | * Returns void |
| 557 | * |
| 558 | ******************************************************************************/ |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 559 | extern void BTM_BleGetVendorCapabilities(tBTM_BLE_VSC_CB* p_cmn_vsc_cb) { |
| 560 | BTM_TRACE_DEBUG("BTM_BleGetVendorCapabilities"); |
Ganesh Ganapathi Batta | 8d41691 | 2014-05-30 16:28:00 -0700 | [diff] [blame] | 561 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 562 | if (NULL != p_cmn_vsc_cb) { |
| 563 | *p_cmn_vsc_cb = btm_cb.cmn_ble_vsc_cb; |
| 564 | } |
Ganesh Ganapathi Batta | 8d41691 | 2014-05-30 16:28:00 -0700 | [diff] [blame] | 565 | } |
| 566 | |
| 567 | /****************************************************************************** |
Myles Watson | ee96a3c | 2016-11-23 14:49:54 -0800 | [diff] [blame] | 568 | * |
| 569 | * Function BTM_BleReadControllerFeatures |
| 570 | * |
| 571 | * Description Reads BLE specific controller features |
| 572 | * |
Myles Watson | 9ca0709 | 2016-11-28 16:41:53 -0800 | [diff] [blame] | 573 | * Parameters: tBTM_BLE_CTRL_FEATURES_CBACK : Callback to notify when |
| 574 | * features are read |
Myles Watson | ee96a3c | 2016-11-23 14:49:54 -0800 | [diff] [blame] | 575 | * |
| 576 | * Returns void |
| 577 | * |
| 578 | ******************************************************************************/ |
Myles Watson | d628a06 | 2016-10-27 10:02:37 -0700 | [diff] [blame] | 579 | #if (BLE_VND_INCLUDED == TRUE) |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 580 | extern void BTM_BleReadControllerFeatures( |
| 581 | tBTM_BLE_CTRL_FEATURES_CBACK* p_vsc_cback) { |
| 582 | if (true == btm_cb.cmn_ble_vsc_cb.values_read) return; |
Satya Calloji | 3f24f46 | 2014-09-16 22:44:43 -0700 | [diff] [blame] | 583 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 584 | BTM_TRACE_DEBUG("BTM_BleReadControllerFeatures"); |
Ganesh Ganapathi Batta | 8d41691 | 2014-05-30 16:28:00 -0700 | [diff] [blame] | 585 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 586 | p_ctrl_le_feature_rd_cmpl_cback = p_vsc_cback; |
| 587 | BTM_VendorSpecificCommand(HCI_BLE_VENDOR_CAP_OCF, 0, NULL, |
| 588 | btm_ble_vendor_capability_vsc_cmpl_cback); |
Wei Wang | a6ce775 | 2014-05-20 06:30:32 +0000 | [diff] [blame] | 589 | } |
Myles Watson | d628a06 | 2016-10-27 10:02:37 -0700 | [diff] [blame] | 590 | #else |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 591 | extern void BTM_BleReadControllerFeatures( |
| 592 | UNUSED_ATTR tBTM_BLE_CTRL_FEATURES_CBACK* p_vsc_cback) {} |
Myles Watson | d628a06 | 2016-10-27 10:02:37 -0700 | [diff] [blame] | 593 | #endif |
Wei Wang | a6ce775 | 2014-05-20 06:30:32 +0000 | [diff] [blame] | 594 | |
| 595 | /******************************************************************************* |
Myles Watson | ee96a3c | 2016-11-23 14:49:54 -0800 | [diff] [blame] | 596 | * |
| 597 | * Function BTM_BleEnableMixedPrivacyMode |
| 598 | * |
| 599 | * Description This function is called to enabled Mixed mode if privacy 1.2 |
| 600 | * is applicable in controller. |
| 601 | * |
| 602 | * Parameters mixed_on: mixed mode to be used or not. |
| 603 | * |
| 604 | * Returns void |
| 605 | * |
| 606 | ******************************************************************************/ |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 607 | void BTM_BleEnableMixedPrivacyMode(bool mixed_on) { |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 608 | #if (BLE_PRIVACY_SPT == TRUE) |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 609 | btm_cb.ble_ctr_cb.mixed_mode = mixed_on; |
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 | /* TODO: send VSC to enabled mixed mode */ |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 612 | #endif |
| 613 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 614 | |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 615 | /******************************************************************************* |
Myles Watson | ee96a3c | 2016-11-23 14:49:54 -0800 | [diff] [blame] | 616 | * |
| 617 | * Function BTM_BleConfigPrivacy |
| 618 | * |
| 619 | * Description This function is called to enable or disable the privacy in |
| 620 | * LE channel of the local device. |
| 621 | * |
| 622 | * Parameters privacy_mode: privacy mode on or off. |
| 623 | * |
| 624 | * Returns bool privacy mode set success; otherwise failed. |
| 625 | * |
| 626 | ******************************************************************************/ |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 627 | bool BTM_BleConfigPrivacy(bool privacy_mode) { |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 628 | #if (BLE_PRIVACY_SPT == TRUE) |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 629 | tBTM_BLE_CB* p_cb = &btm_cb.ble_ctr_cb; |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 630 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 631 | BTM_TRACE_EVENT("%s", __func__); |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 632 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 633 | /* if LE is not supported, return error */ |
| 634 | if (!controller_get_interface()->supports_ble()) return false; |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 635 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 636 | uint8_t addr_resolution = 0; |
| 637 | if (!privacy_mode) /* if privacy disabled, always use public address */ |
| 638 | { |
| 639 | p_cb->addr_mgnt_cb.own_addr_type = BLE_ADDR_PUBLIC; |
| 640 | p_cb->privacy_mode = BTM_PRIVACY_NONE; |
| 641 | } else /* privacy is turned on*/ |
| 642 | { |
| 643 | /* always set host random address, used when privacy 1.1 or priavcy 1.2 is |
| 644 | * disabled */ |
| 645 | p_cb->addr_mgnt_cb.own_addr_type = BLE_ADDR_RANDOM; |
Jakub Pawlowski | 0c68323 | 2017-02-24 09:49:59 -0800 | [diff] [blame] | 646 | btm_gen_resolvable_private_addr(base::Bind(&btm_gen_resolve_paddr_low)); |
Prerepa Viswanadham | 16fe082 | 2014-08-07 11:38:06 -0700 | [diff] [blame] | 647 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 648 | /* 4.2 controller only allow privacy 1.2 or mixed mode, resolvable private |
| 649 | * address in controller */ |
| 650 | if (controller_get_interface()->supports_ble_privacy()) { |
| 651 | addr_resolution = 1; |
| 652 | /* check vendor specific capability */ |
| 653 | p_cb->privacy_mode = |
| 654 | btm_cb.ble_ctr_cb.mixed_mode ? BTM_PRIVACY_MIXED : BTM_PRIVACY_1_2; |
| 655 | } else /* 4.1/4.0 controller */ |
| 656 | p_cb->privacy_mode = BTM_PRIVACY_1_1; |
| 657 | } |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 658 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 659 | GAP_BleAttrDBUpdate(GATT_UUID_GAP_CENTRAL_ADDR_RESOL, |
| 660 | (tGAP_BLE_ATTR_VALUE*)&addr_resolution); |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 661 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 662 | return true; |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 663 | #else |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 664 | return false; |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 665 | #endif |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 666 | } |
| 667 | |
Ganesh Ganapathi Batta | 8d41691 | 2014-05-30 16:28:00 -0700 | [diff] [blame] | 668 | /******************************************************************************* |
Myles Watson | ee96a3c | 2016-11-23 14:49:54 -0800 | [diff] [blame] | 669 | * |
| 670 | * Function BTM_BleMaxMultiAdvInstanceCount |
| 671 | * |
Myles Watson | 9ca0709 | 2016-11-28 16:41:53 -0800 | [diff] [blame] | 672 | * Description Returns max number of multi adv instances supported by |
| 673 | * controller |
Myles Watson | ee96a3c | 2016-11-23 14:49:54 -0800 | [diff] [blame] | 674 | * |
| 675 | * Returns Max multi adv instance count |
| 676 | * |
| 677 | ******************************************************************************/ |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 678 | extern uint8_t BTM_BleMaxMultiAdvInstanceCount(void) { |
| 679 | return btm_cb.cmn_ble_vsc_cb.adv_inst_max < BTM_BLE_MULTI_ADV_MAX |
| 680 | ? btm_cb.cmn_ble_vsc_cb.adv_inst_max |
| 681 | : BTM_BLE_MULTI_ADV_MAX; |
Prerepa Viswanadham | 16fe082 | 2014-08-07 11:38:06 -0700 | [diff] [blame] | 682 | } |
| 683 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 684 | /******************************************************************************* |
Myles Watson | ee96a3c | 2016-11-23 14:49:54 -0800 | [diff] [blame] | 685 | * |
| 686 | * Function BTM_BleLocalPrivacyEnabled |
| 687 | * |
| 688 | * Description Checks if local device supports private address |
| 689 | * |
| 690 | * Returns Return true if local privacy is enabled else false |
| 691 | * |
| 692 | ******************************************************************************/ |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 693 | bool BTM_BleLocalPrivacyEnabled(void) { |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 694 | #if (BLE_PRIVACY_SPT == TRUE) |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 695 | return (btm_cb.ble_ctr_cb.privacy_mode != BTM_PRIVACY_NONE); |
Sharvil Nanavati | 2611263 | 2014-06-07 00:56:14 -0700 | [diff] [blame] | 696 | #else |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 697 | return false; |
Sharvil Nanavati | 2611263 | 2014-06-07 00:56:14 -0700 | [diff] [blame] | 698 | #endif |
| 699 | } |
| 700 | |
Jakub Pawlowski | 83211b0 | 2016-12-07 11:25:15 -0800 | [diff] [blame] | 701 | /** |
| 702 | * Set BLE connectable mode to auto connect |
| 703 | */ |
| 704 | void BTM_BleStartAutoConn() { |
| 705 | BTM_TRACE_EVENT("%s", __func__); |
| 706 | if (!controller_get_interface()->supports_ble()) return; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 707 | |
Jakub Pawlowski | 83211b0 | 2016-12-07 11:25:15 -0800 | [diff] [blame] | 708 | if (btm_cb.ble_ctr_cb.bg_conn_type != BTM_BLE_CONN_AUTO) { |
| 709 | btm_ble_start_auto_conn(true); |
| 710 | btm_cb.ble_ctr_cb.bg_conn_type = BTM_BLE_CONN_AUTO; |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 711 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 712 | } |
| 713 | |
| 714 | /******************************************************************************* |
Myles Watson | ee96a3c | 2016-11-23 14:49:54 -0800 | [diff] [blame] | 715 | * |
| 716 | * Function BTM_BleClearBgConnDev |
| 717 | * |
| 718 | * Description This function is called to clear the whitelist, |
| 719 | * end any pending whitelist connections, |
Jakub Pawlowski | 5e43c80 | 2017-06-26 17:22:35 -0700 | [diff] [blame] | 720 | * and reset the local bg device list. |
Myles Watson | ee96a3c | 2016-11-23 14:49:54 -0800 | [diff] [blame] | 721 | * |
| 722 | * Parameters void |
| 723 | * |
| 724 | * Returns void |
| 725 | * |
| 726 | ******************************************************************************/ |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 727 | void BTM_BleClearBgConnDev(void) { |
| 728 | btm_ble_start_auto_conn(false); |
| 729 | btm_ble_clear_white_list(); |
| 730 | gatt_reset_bgdev_list(); |
Nitin Arora | 021e17a | 2014-01-29 19:18:39 -0800 | [diff] [blame] | 731 | } |
| 732 | |
| 733 | /******************************************************************************* |
Myles Watson | ee96a3c | 2016-11-23 14:49:54 -0800 | [diff] [blame] | 734 | * |
| 735 | * Function BTM_BleUpdateBgConnDev |
| 736 | * |
| 737 | * Description This function is called to add or remove a device into/from |
| 738 | * background connection procedure. The background connection |
Jakub Pawlowski | 5e43c80 | 2017-06-26 17:22:35 -0700 | [diff] [blame] | 739 | * procedure is decided by the background connection type, it |
| 740 | * can be auto connection, or selective connection. |
Myles Watson | ee96a3c | 2016-11-23 14:49:54 -0800 | [diff] [blame] | 741 | * |
| 742 | * Parameters add_remove: true to add; false to remove. |
| 743 | * remote_bda: device address to add/remove. |
| 744 | * |
| 745 | * Returns void |
| 746 | * |
| 747 | ******************************************************************************/ |
Jakub Pawlowski | a484a88 | 2017-06-24 17:30:18 -0700 | [diff] [blame] | 748 | bool BTM_BleUpdateBgConnDev(bool add_remove, const RawAddress& remote_bda) { |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 749 | BTM_TRACE_EVENT("%s() add=%d", __func__, add_remove); |
| 750 | return btm_update_dev_to_white_list(add_remove, remote_bda); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 751 | } |
| 752 | |
| 753 | /******************************************************************************* |
Myles Watson | ee96a3c | 2016-11-23 14:49:54 -0800 | [diff] [blame] | 754 | * |
| 755 | * Function BTM_BleSetConnectableMode |
| 756 | * |
| 757 | * Description This function is called to set BLE connectable mode for a |
| 758 | * peripheral device. |
| 759 | * |
Myles Watson | 9ca0709 | 2016-11-28 16:41:53 -0800 | [diff] [blame] | 760 | * Parameters conn_mode: directed connectable mode, or non-directed. It |
| 761 | * can be BTM_BLE_CONNECT_EVT, |
| 762 | * BTM_BLE_CONNECT_DIR_EVT or |
Myles Watson | ee96a3c | 2016-11-23 14:49:54 -0800 | [diff] [blame] | 763 | * BTM_BLE_CONNECT_LO_DUTY_DIR_EVT |
| 764 | * |
| 765 | * Returns BTM_ILLEGAL_VALUE if controller does not support BLE. |
| 766 | * BTM_SUCCESS is status set successfully; otherwise failure. |
| 767 | * |
| 768 | ******************************************************************************/ |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 769 | tBTM_STATUS BTM_BleSetConnectableMode(tBTM_BLE_CONN_MODE connectable_mode) { |
| 770 | tBTM_BLE_INQ_CB* p_cb = &btm_cb.ble_ctr_cb.inq_var; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 771 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 772 | BTM_TRACE_EVENT("%s connectable_mode = %d ", __func__, connectable_mode); |
| 773 | if (!controller_get_interface()->supports_ble()) return BTM_ILLEGAL_VALUE; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 774 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 775 | p_cb->directed_conn = connectable_mode; |
| 776 | return btm_ble_set_connectability(p_cb->connectable_mode); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 777 | } |
| 778 | |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 779 | #if (BLE_PRIVACY_SPT == TRUE) |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 780 | static bool is_resolving_list_bit_set(void* data, void* context) { |
| 781 | tBTM_SEC_DEV_REC* p_dev_rec = static_cast<tBTM_SEC_DEV_REC*>(data); |
Jakub Pawlowski | cac784d | 2016-02-01 11:53:36 -0800 | [diff] [blame] | 782 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 783 | if ((p_dev_rec->ble.in_controller_list & BTM_RESOLVING_LIST_BIT) != 0) |
| 784 | return false; |
Jakub Pawlowski | cac784d | 2016-02-01 11:53:36 -0800 | [diff] [blame] | 785 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 786 | return true; |
Jakub Pawlowski | cac784d | 2016-02-01 11:53:36 -0800 | [diff] [blame] | 787 | } |
Pavlin Radoslavov | a9ea43b | 2016-02-15 11:47:37 -0800 | [diff] [blame] | 788 | #endif |
Jakub Pawlowski | cac784d | 2016-02-01 11:53:36 -0800 | [diff] [blame] | 789 | |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 790 | /******************************************************************************* |
Myles Watson | ee96a3c | 2016-11-23 14:49:54 -0800 | [diff] [blame] | 791 | * |
| 792 | * Function btm_set_conn_mode_adv_init_addr |
| 793 | * |
Myles Watson | 9ca0709 | 2016-11-28 16:41:53 -0800 | [diff] [blame] | 794 | * Description set initator address type and local address type based on |
| 795 | * adv mode. |
Myles Watson | ee96a3c | 2016-11-23 14:49:54 -0800 | [diff] [blame] | 796 | * |
| 797 | * |
| 798 | ******************************************************************************/ |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 799 | static uint8_t btm_set_conn_mode_adv_init_addr( |
Jakub Pawlowski | a484a88 | 2017-06-24 17:30:18 -0700 | [diff] [blame] | 800 | tBTM_BLE_INQ_CB* p_cb, RawAddress& p_peer_addr_ptr, |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 801 | tBLE_ADDR_TYPE* p_peer_addr_type, tBLE_ADDR_TYPE* p_own_addr_type) { |
| 802 | uint8_t evt_type; |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 803 | #if (BLE_PRIVACY_SPT == TRUE) |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 804 | tBTM_SEC_DEV_REC* p_dev_rec; |
Pavlin Radoslavov | a9ea43b | 2016-02-15 11:47:37 -0800 | [diff] [blame] | 805 | #endif |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 806 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 807 | evt_type = |
| 808 | (p_cb->connectable_mode == BTM_BLE_NON_CONNECTABLE) |
| 809 | ? ((p_cb->scan_rsp) ? BTM_BLE_DISCOVER_EVT : BTM_BLE_NON_CONNECT_EVT) |
| 810 | : BTM_BLE_CONNECT_EVT; |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 811 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 812 | if (evt_type == BTM_BLE_CONNECT_EVT) { |
| 813 | evt_type = p_cb->directed_conn; |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 814 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 815 | if (p_cb->directed_conn == BTM_BLE_CONNECT_DIR_EVT || |
| 816 | p_cb->directed_conn == BTM_BLE_CONNECT_LO_DUTY_DIR_EVT) { |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 817 | #if (BLE_PRIVACY_SPT == TRUE) |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 818 | /* for privacy 1.2, convert peer address as static, own address set as ID |
| 819 | * addr */ |
| 820 | if (btm_cb.ble_ctr_cb.privacy_mode == BTM_PRIVACY_1_2 || |
| 821 | btm_cb.ble_ctr_cb.privacy_mode == BTM_PRIVACY_MIXED) { |
| 822 | /* only do so for bonded device */ |
Jakub Pawlowski | 78b81c6 | 2017-06-16 13:55:52 -0700 | [diff] [blame] | 823 | if ((p_dev_rec = btm_find_or_alloc_dev(p_cb->direct_bda.bda)) != NULL && |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 824 | p_dev_rec->ble.in_controller_list & BTM_RESOLVING_LIST_BIT) { |
| 825 | btm_ble_enable_resolving_list(BTM_BLE_RL_ADV); |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 826 | p_peer_addr_ptr = p_dev_rec->ble.static_addr; |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 827 | *p_peer_addr_type = p_dev_rec->ble.static_addr_type; |
| 828 | *p_own_addr_type = BLE_ADDR_RANDOM_ID; |
| 829 | return evt_type; |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 830 | } |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 831 | /* otherwise fall though as normal directed adv */ |
| 832 | else { |
| 833 | btm_ble_disable_resolving_list(BTM_BLE_RL_ADV, true); |
Jakub Pawlowski | cac784d | 2016-02-01 11:53:36 -0800 | [diff] [blame] | 834 | } |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 835 | } |
| 836 | #endif |
| 837 | /* direct adv mode does not have privacy, if privacy is not enabled */ |
| 838 | *p_peer_addr_type = p_cb->direct_bda.type; |
Jakub Pawlowski | 78b81c6 | 2017-06-16 13:55:52 -0700 | [diff] [blame] | 839 | p_peer_addr_ptr = p_cb->direct_bda.bda; |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 840 | return evt_type; |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 841 | } |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 842 | } |
| 843 | |
| 844 | /* undirect adv mode or non-connectable mode*/ |
| 845 | #if (BLE_PRIVACY_SPT == TRUE) |
| 846 | /* when privacy 1.2 privacy only mode is used, or mixed mode */ |
| 847 | if ((btm_cb.ble_ctr_cb.privacy_mode == BTM_PRIVACY_1_2 && |
| 848 | p_cb->afp != AP_SCAN_CONN_ALL) || |
| 849 | btm_cb.ble_ctr_cb.privacy_mode == BTM_PRIVACY_MIXED) { |
| 850 | list_node_t* n = |
| 851 | list_foreach(btm_cb.sec_dev_rec, is_resolving_list_bit_set, NULL); |
| 852 | if (n) { |
| 853 | /* if enhanced privacy is required, set Identity address and matching IRK |
| 854 | * peer */ |
| 855 | tBTM_SEC_DEV_REC* p_dev_rec = |
| 856 | static_cast<tBTM_SEC_DEV_REC*>(list_node(n)); |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 857 | p_peer_addr_ptr = p_dev_rec->ble.static_addr; |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 858 | *p_peer_addr_type = p_dev_rec->ble.static_addr_type; |
| 859 | |
| 860 | *p_own_addr_type = BLE_ADDR_RANDOM_ID; |
| 861 | } else { |
| 862 | /* resolving list is empty, not enabled */ |
| 863 | *p_own_addr_type = BLE_ADDR_RANDOM; |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 864 | } |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 865 | } |
| 866 | /* privacy 1.1, or privacy 1.2, general discoverable/connectable mode, disable |
| 867 | privacy in */ |
| 868 | /* controller fall back to host based privacy */ |
| 869 | else if (btm_cb.ble_ctr_cb.privacy_mode != BTM_PRIVACY_NONE) { |
| 870 | *p_own_addr_type = BLE_ADDR_RANDOM; |
| 871 | } |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 872 | #endif |
| 873 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 874 | /* if no privacy,do not set any peer address,*/ |
| 875 | /* local address type go by global privacy setting */ |
| 876 | return evt_type; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 877 | } |
| 878 | |
| 879 | /******************************************************************************* |
Myles Watson | ee96a3c | 2016-11-23 14:49:54 -0800 | [diff] [blame] | 880 | * |
| 881 | * Function BTM_BleSetAdvParams |
| 882 | * |
| 883 | * Description This function is called to set advertising parameters. |
| 884 | * |
| 885 | * Parameters adv_int_min: minimum advertising interval |
| 886 | * adv_int_max: maximum advertising interval |
| 887 | * p_dir_bda: connectable direct initiator's LE device address |
| 888 | * chnl_map: advertising channel map. |
| 889 | * |
| 890 | * Returns void |
| 891 | * |
| 892 | ******************************************************************************/ |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 893 | tBTM_STATUS BTM_BleSetAdvParams(uint16_t adv_int_min, uint16_t adv_int_max, |
Jakub Pawlowski | a484a88 | 2017-06-24 17:30:18 -0700 | [diff] [blame] | 894 | const RawAddress& p_dir_bda, |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 895 | tBTM_BLE_ADV_CHNL_MAP chnl_map) { |
| 896 | tBTM_LE_RANDOM_CB* p_addr_cb = &btm_cb.ble_ctr_cb.addr_mgnt_cb; |
| 897 | tBTM_BLE_INQ_CB* p_cb = &btm_cb.ble_ctr_cb.inq_var; |
| 898 | tBTM_STATUS status = BTM_SUCCESS; |
Jakub Pawlowski | b707f44 | 2017-07-03 15:39:36 -0700 | [diff] [blame^] | 899 | RawAddress address = RawAddress::kEmpty; |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 900 | tBLE_ADDR_TYPE init_addr_type = BLE_ADDR_PUBLIC; |
| 901 | tBLE_ADDR_TYPE own_addr_type = p_addr_cb->own_addr_type; |
| 902 | uint8_t adv_mode = p_cb->adv_mode; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 903 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 904 | BTM_TRACE_EVENT("BTM_BleSetAdvParams"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 905 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 906 | if (!controller_get_interface()->supports_ble()) return BTM_ILLEGAL_VALUE; |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 907 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 908 | if (!BTM_BLE_ISVALID_PARAM(adv_int_min, BTM_BLE_ADV_INT_MIN, |
| 909 | BTM_BLE_ADV_INT_MAX) || |
| 910 | !BTM_BLE_ISVALID_PARAM(adv_int_max, BTM_BLE_ADV_INT_MIN, |
| 911 | BTM_BLE_ADV_INT_MAX)) { |
| 912 | return BTM_ILLEGAL_VALUE; |
| 913 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 914 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 915 | p_cb->adv_interval_min = adv_int_min; |
| 916 | p_cb->adv_interval_max = adv_int_max; |
| 917 | p_cb->adv_chnl_map = chnl_map; |
Jakub Pawlowski | 78b81c6 | 2017-06-16 13:55:52 -0700 | [diff] [blame] | 918 | p_cb->direct_bda.bda = p_dir_bda; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 919 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 920 | BTM_TRACE_EVENT("update params for an active adv"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 921 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 922 | btm_ble_stop_adv(); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 923 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 924 | p_cb->evt_type = btm_set_conn_mode_adv_init_addr( |
Jakub Pawlowski | b707f44 | 2017-07-03 15:39:36 -0700 | [diff] [blame^] | 925 | p_cb, address, &init_addr_type, &own_addr_type); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 926 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 927 | /* update adv params */ |
| 928 | btsnd_hcic_ble_write_adv_params( |
| 929 | p_cb->adv_interval_min, p_cb->adv_interval_max, p_cb->evt_type, |
Jakub Pawlowski | b707f44 | 2017-07-03 15:39:36 -0700 | [diff] [blame^] | 930 | own_addr_type, init_addr_type, address, p_cb->adv_chnl_map, p_cb->afp); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 931 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 932 | if (adv_mode == BTM_BLE_ADV_ENABLE) btm_ble_start_adv(); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 933 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 934 | return status; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 935 | } |
| 936 | |
Jakub Pawlowski | 119f32a | 2017-02-16 11:56:56 -0800 | [diff] [blame] | 937 | /** |
| 938 | * This function is called to set scan parameters. |cb| is called with operation |
| 939 | * status |
| 940 | **/ |
| 941 | void BTM_BleSetScanParams(uint32_t scan_interval, uint32_t scan_window, |
| 942 | tBLE_SCAN_MODE scan_mode, |
| 943 | base::Callback<void(uint8_t)> cb) { |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 944 | tBTM_BLE_INQ_CB* p_cb = &btm_cb.ble_ctr_cb.inq_var; |
| 945 | uint32_t max_scan_interval; |
| 946 | uint32_t max_scan_window; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 947 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 948 | BTM_TRACE_EVENT("%s", __func__); |
| 949 | if (!controller_get_interface()->supports_ble()) return; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 950 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 951 | /* If not supporting extended scan support, use the older range for checking |
| 952 | */ |
| 953 | if (btm_cb.cmn_ble_vsc_cb.extended_scan_support == 0) { |
| 954 | max_scan_interval = BTM_BLE_SCAN_INT_MAX; |
| 955 | max_scan_window = BTM_BLE_SCAN_WIN_MAX; |
| 956 | } else { |
| 957 | /* If supporting extended scan support, use the new extended range for |
| 958 | * checking */ |
| 959 | max_scan_interval = BTM_BLE_EXT_SCAN_INT_MAX; |
| 960 | max_scan_window = BTM_BLE_EXT_SCAN_WIN_MAX; |
| 961 | } |
Satya Calloji | 935324a | 2015-03-31 13:24:32 -0700 | [diff] [blame] | 962 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 963 | if (BTM_BLE_ISVALID_PARAM(scan_interval, BTM_BLE_SCAN_INT_MIN, |
| 964 | max_scan_interval) && |
| 965 | BTM_BLE_ISVALID_PARAM(scan_window, BTM_BLE_SCAN_WIN_MIN, |
| 966 | max_scan_window) && |
| 967 | (scan_mode == BTM_BLE_SCAN_MODE_ACTI || |
| 968 | scan_mode == BTM_BLE_SCAN_MODE_PASS)) { |
| 969 | p_cb->scan_type = scan_mode; |
| 970 | p_cb->scan_interval = scan_interval; |
| 971 | p_cb->scan_window = scan_window; |
Satya Calloji | 935324a | 2015-03-31 13:24:32 -0700 | [diff] [blame] | 972 | |
Jakub Pawlowski | 119f32a | 2017-02-16 11:56:56 -0800 | [diff] [blame] | 973 | cb.Run(BTM_SUCCESS); |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 974 | } else { |
Jakub Pawlowski | 119f32a | 2017-02-16 11:56:56 -0800 | [diff] [blame] | 975 | cb.Run(BTM_ILLEGAL_VALUE); |
Satya Calloji | 935324a | 2015-03-31 13:24:32 -0700 | [diff] [blame] | 976 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 977 | BTM_TRACE_ERROR("Illegal params: scan_interval = %d scan_window = %d", |
| 978 | scan_interval, scan_window); |
| 979 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 980 | } |
| 981 | |
| 982 | /******************************************************************************* |
Myles Watson | ee96a3c | 2016-11-23 14:49:54 -0800 | [diff] [blame] | 983 | * |
| 984 | * Function BTM_BleWriteScanRsp |
| 985 | * |
| 986 | * Description This function is called to write LE scan response. |
| 987 | * |
| 988 | * Parameters: p_scan_rsp: scan response information. |
| 989 | * |
| 990 | * Returns void |
| 991 | * |
| 992 | ******************************************************************************/ |
Jakub Pawlowski | 9eaf776 | 2016-10-04 19:30:09 -0700 | [diff] [blame] | 993 | void BTM_BleWriteScanRsp(uint8_t* data, uint8_t length, |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 994 | tBTM_BLE_ADV_DATA_CMPL_CBACK* p_adv_data_cback) { |
| 995 | BTM_TRACE_EVENT("%s: length: %d", __func__, length); |
| 996 | if (!controller_get_interface()->supports_ble()) { |
| 997 | p_adv_data_cback(BTM_ILLEGAL_VALUE); |
| 998 | return; |
| 999 | } |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 1000 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1001 | btsnd_hcic_ble_set_scan_rsp_data(length, data); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1002 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1003 | if (length != 0) |
| 1004 | btm_cb.ble_ctr_cb.inq_var.scan_rsp = true; |
| 1005 | else |
| 1006 | btm_cb.ble_ctr_cb.inq_var.scan_rsp = false; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1007 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1008 | p_adv_data_cback(BTM_SUCCESS); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1009 | } |
| 1010 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1011 | /******************************************************************************* |
Myles Watson | ee96a3c | 2016-11-23 14:49:54 -0800 | [diff] [blame] | 1012 | * |
| 1013 | * Function BTM__BLEReadDiscoverability |
| 1014 | * |
Myles Watson | 9ca0709 | 2016-11-28 16:41:53 -0800 | [diff] [blame] | 1015 | * Description This function is called to read the current LE |
| 1016 | * discoverability mode of the device. |
Myles Watson | ee96a3c | 2016-11-23 14:49:54 -0800 | [diff] [blame] | 1017 | * |
| 1018 | * Returns BTM_BLE_NON_DISCOVERABLE ,BTM_BLE_LIMITED_DISCOVERABLE or |
| 1019 | * BTM_BLE_GENRAL_DISCOVERABLE |
| 1020 | * |
| 1021 | ******************************************************************************/ |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1022 | uint16_t BTM_BleReadDiscoverability() { |
| 1023 | BTM_TRACE_API("%s", __func__); |
VenkatRaghavan VijayaRaghavan | 76356ae | 2015-04-21 11:32:29 -0700 | [diff] [blame] | 1024 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1025 | return (btm_cb.ble_ctr_cb.inq_var.discoverable_mode); |
VenkatRaghavan VijayaRaghavan | 76356ae | 2015-04-21 11:32:29 -0700 | [diff] [blame] | 1026 | } |
| 1027 | |
| 1028 | /******************************************************************************* |
Myles Watson | ee96a3c | 2016-11-23 14:49:54 -0800 | [diff] [blame] | 1029 | * |
| 1030 | * Function BTM__BLEReadConnectability |
| 1031 | * |
Myles Watson | 9ca0709 | 2016-11-28 16:41:53 -0800 | [diff] [blame] | 1032 | * Description This function is called to read the current LE |
| 1033 | * connectability mode of the device. |
Myles Watson | ee96a3c | 2016-11-23 14:49:54 -0800 | [diff] [blame] | 1034 | * |
| 1035 | * Returns BTM_BLE_NON_CONNECTABLE or BTM_BLE_CONNECTABLE |
| 1036 | * |
| 1037 | ******************************************************************************/ |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1038 | uint16_t BTM_BleReadConnectability() { |
| 1039 | BTM_TRACE_API("%s", __func__); |
VenkatRaghavan VijayaRaghavan | 76356ae | 2015-04-21 11:32:29 -0700 | [diff] [blame] | 1040 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1041 | return (btm_cb.ble_ctr_cb.inq_var.connectable_mode); |
VenkatRaghavan VijayaRaghavan | 76356ae | 2015-04-21 11:32:29 -0700 | [diff] [blame] | 1042 | } |
| 1043 | |
| 1044 | /******************************************************************************* |
Myles Watson | ee96a3c | 2016-11-23 14:49:54 -0800 | [diff] [blame] | 1045 | * |
| 1046 | * Function btm_ble_select_adv_interval |
| 1047 | * |
| 1048 | * Description select adv interval based on device mode |
| 1049 | * |
| 1050 | * Returns void |
| 1051 | * |
| 1052 | ******************************************************************************/ |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1053 | void btm_ble_select_adv_interval(tBTM_BLE_INQ_CB* p_cb, uint8_t evt_type, |
| 1054 | uint16_t* p_adv_int_min, |
| 1055 | uint16_t* p_adv_int_max) { |
| 1056 | if (p_cb->adv_interval_min && p_cb->adv_interval_max) { |
| 1057 | *p_adv_int_min = p_cb->adv_interval_min; |
| 1058 | *p_adv_int_max = p_cb->adv_interval_max; |
| 1059 | } else { |
| 1060 | switch (evt_type) { |
| 1061 | case BTM_BLE_CONNECT_EVT: |
| 1062 | case BTM_BLE_CONNECT_LO_DUTY_DIR_EVT: |
| 1063 | *p_adv_int_min = *p_adv_int_max = BTM_BLE_GAP_ADV_FAST_INT_1; |
| 1064 | break; |
| 1065 | |
| 1066 | case BTM_BLE_NON_CONNECT_EVT: |
| 1067 | case BTM_BLE_DISCOVER_EVT: |
| 1068 | *p_adv_int_min = *p_adv_int_max = BTM_BLE_GAP_ADV_FAST_INT_2; |
| 1069 | break; |
| 1070 | |
| 1071 | /* connectable directed event */ |
| 1072 | case BTM_BLE_CONNECT_DIR_EVT: |
| 1073 | *p_adv_int_min = BTM_BLE_GAP_ADV_DIR_MIN_INT; |
| 1074 | *p_adv_int_max = BTM_BLE_GAP_ADV_DIR_MAX_INT; |
| 1075 | break; |
| 1076 | |
| 1077 | default: |
| 1078 | *p_adv_int_min = *p_adv_int_max = BTM_BLE_GAP_ADV_SLOW_INT; |
| 1079 | break; |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1080 | } |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1081 | } |
| 1082 | return; |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1083 | } |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 1084 | |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1085 | /******************************************************************************* |
Myles Watson | ee96a3c | 2016-11-23 14:49:54 -0800 | [diff] [blame] | 1086 | * |
| 1087 | * Function btm_ble_update_dmt_flag_bits |
| 1088 | * |
Myles Watson | 9ca0709 | 2016-11-28 16:41:53 -0800 | [diff] [blame] | 1089 | * Description Obtain updated adv flag value based on connect and |
| 1090 | * discoverability mode. Also, setup DMT support value in the |
| 1091 | * flag based on whether the controller supports both LE and |
| 1092 | * BR/EDR. |
Myles Watson | ee96a3c | 2016-11-23 14:49:54 -0800 | [diff] [blame] | 1093 | * |
| 1094 | * Parameters: flag_value (Input / Output) - flag value |
| 1095 | * connect_mode (Input) - Connect mode value |
| 1096 | * disc_mode (Input) - discoverability mode |
| 1097 | * |
| 1098 | * Returns void |
| 1099 | * |
| 1100 | ******************************************************************************/ |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1101 | void btm_ble_update_dmt_flag_bits(uint8_t* adv_flag_value, |
| 1102 | const uint16_t connect_mode, |
| 1103 | const uint16_t disc_mode) { |
| 1104 | /* BR/EDR non-discoverable , non-connectable */ |
| 1105 | if ((disc_mode & BTM_DISCOVERABLE_MASK) == 0 && |
| 1106 | (connect_mode & BTM_CONNECTABLE_MASK) == 0) |
| 1107 | *adv_flag_value |= BTM_BLE_BREDR_NOT_SPT; |
| 1108 | else |
| 1109 | *adv_flag_value &= ~BTM_BLE_BREDR_NOT_SPT; |
Satya Calloji | 7cf7da9 | 2015-02-05 13:12:15 -0800 | [diff] [blame] | 1110 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1111 | /* if local controller support, mark both controller and host support in flag |
| 1112 | */ |
| 1113 | if (controller_get_interface()->supports_simultaneous_le_bredr()) |
| 1114 | *adv_flag_value |= (BTM_BLE_DMT_CONTROLLER_SPT | BTM_BLE_DMT_HOST_SPT); |
| 1115 | else |
| 1116 | *adv_flag_value &= ~(BTM_BLE_DMT_CONTROLLER_SPT | BTM_BLE_DMT_HOST_SPT); |
Satya Calloji | 7cf7da9 | 2015-02-05 13:12:15 -0800 | [diff] [blame] | 1117 | } |
| 1118 | |
| 1119 | /******************************************************************************* |
Myles Watson | ee96a3c | 2016-11-23 14:49:54 -0800 | [diff] [blame] | 1120 | * |
| 1121 | * Function btm_ble_set_adv_flag |
| 1122 | * |
| 1123 | * Description Set adv flag in adv data. |
| 1124 | * |
| 1125 | * Parameters: connect_mode (Input)- Connect mode value |
| 1126 | * disc_mode (Input) - discoverability mode |
| 1127 | * |
| 1128 | * Returns void |
| 1129 | * |
| 1130 | ******************************************************************************/ |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1131 | void btm_ble_set_adv_flag(uint16_t connect_mode, uint16_t disc_mode) { |
| 1132 | uint8_t flag = 0, old_flag = 0; |
| 1133 | tBTM_BLE_LOCAL_ADV_DATA* p_adv_data = &btm_cb.ble_ctr_cb.inq_var.adv_data; |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1134 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1135 | if (p_adv_data->p_flags != NULL) flag = old_flag = *(p_adv_data->p_flags); |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1136 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1137 | btm_ble_update_dmt_flag_bits(&flag, connect_mode, disc_mode); |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1138 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1139 | LOG_DEBUG(LOG_TAG, "disc_mode %04x", disc_mode); |
| 1140 | /* update discoverable flag */ |
| 1141 | if (disc_mode & BTM_BLE_LIMITED_DISCOVERABLE) { |
| 1142 | flag &= ~BTM_BLE_GEN_DISC_FLAG; |
| 1143 | flag |= BTM_BLE_LIMIT_DISC_FLAG; |
| 1144 | } else if (disc_mode & BTM_BLE_GENERAL_DISCOVERABLE) { |
| 1145 | flag |= BTM_BLE_GEN_DISC_FLAG; |
| 1146 | flag &= ~BTM_BLE_LIMIT_DISC_FLAG; |
| 1147 | } else /* remove all discoverable flags */ |
| 1148 | { |
| 1149 | flag &= ~(BTM_BLE_LIMIT_DISC_FLAG | BTM_BLE_GEN_DISC_FLAG); |
| 1150 | } |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1151 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1152 | if (flag != old_flag) { |
| 1153 | btm_ble_update_adv_flag(flag); |
| 1154 | } |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1155 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1156 | /******************************************************************************* |
Myles Watson | ee96a3c | 2016-11-23 14:49:54 -0800 | [diff] [blame] | 1157 | * |
| 1158 | * Function btm_ble_set_discoverability |
| 1159 | * |
| 1160 | * Description This function is called to set BLE discoverable mode. |
| 1161 | * |
| 1162 | * Parameters: combined_mode: discoverability mode. |
| 1163 | * |
| 1164 | * Returns BTM_SUCCESS is status set successfully; otherwise failure. |
| 1165 | * |
| 1166 | ******************************************************************************/ |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1167 | tBTM_STATUS btm_ble_set_discoverability(uint16_t combined_mode) { |
| 1168 | tBTM_LE_RANDOM_CB* p_addr_cb = &btm_cb.ble_ctr_cb.addr_mgnt_cb; |
| 1169 | tBTM_BLE_INQ_CB* p_cb = &btm_cb.ble_ctr_cb.inq_var; |
| 1170 | uint16_t mode = (combined_mode & BTM_BLE_DISCOVERABLE_MASK); |
| 1171 | uint8_t new_mode = BTM_BLE_ADV_ENABLE; |
| 1172 | uint8_t evt_type; |
| 1173 | tBTM_STATUS status = BTM_SUCCESS; |
Jakub Pawlowski | b707f44 | 2017-07-03 15:39:36 -0700 | [diff] [blame^] | 1174 | RawAddress address = RawAddress::kEmpty; |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1175 | tBLE_ADDR_TYPE init_addr_type = BLE_ADDR_PUBLIC, |
| 1176 | own_addr_type = p_addr_cb->own_addr_type; |
| 1177 | uint16_t adv_int_min, adv_int_max; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1178 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1179 | BTM_TRACE_EVENT("%s mode=0x%0x combined_mode=0x%x", __func__, mode, |
| 1180 | combined_mode); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1181 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1182 | /*** Check mode parameter ***/ |
| 1183 | if (mode > BTM_BLE_MAX_DISCOVERABLE) return (BTM_ILLEGAL_VALUE); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1184 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1185 | p_cb->discoverable_mode = mode; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1186 | |
Jakub Pawlowski | b707f44 | 2017-07-03 15:39:36 -0700 | [diff] [blame^] | 1187 | evt_type = btm_set_conn_mode_adv_init_addr(p_cb, address, &init_addr_type, |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1188 | &own_addr_type); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1189 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1190 | if (p_cb->connectable_mode == BTM_BLE_NON_CONNECTABLE && |
| 1191 | mode == BTM_BLE_NON_DISCOVERABLE) |
| 1192 | new_mode = BTM_BLE_ADV_DISABLE; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1193 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1194 | btm_ble_select_adv_interval(p_cb, evt_type, &adv_int_min, &adv_int_max); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1195 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1196 | alarm_cancel(p_cb->fast_adv_timer); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1197 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1198 | /* update adv params if start advertising */ |
| 1199 | BTM_TRACE_EVENT("evt_type=0x%x p-cb->evt_type=0x%x ", evt_type, |
| 1200 | p_cb->evt_type); |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1201 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1202 | if (new_mode == BTM_BLE_ADV_ENABLE) { |
| 1203 | btm_ble_set_adv_flag(btm_cb.btm_inq_vars.connectable_mode, combined_mode); |
| 1204 | |
| 1205 | if (evt_type != p_cb->evt_type || p_cb->adv_addr_type != own_addr_type || |
| 1206 | !p_cb->fast_adv_on) { |
| 1207 | btm_ble_stop_adv(); |
| 1208 | |
| 1209 | /* update adv params */ |
| 1210 | btsnd_hcic_ble_write_adv_params(adv_int_min, adv_int_max, evt_type, |
Jakub Pawlowski | b707f44 | 2017-07-03 15:39:36 -0700 | [diff] [blame^] | 1211 | own_addr_type, init_addr_type, address, |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1212 | p_cb->adv_chnl_map, p_cb->afp); |
| 1213 | p_cb->evt_type = evt_type; |
| 1214 | p_cb->adv_addr_type = own_addr_type; |
| 1215 | } |
| 1216 | } |
| 1217 | |
| 1218 | if (status == BTM_SUCCESS && p_cb->adv_mode != new_mode) { |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 1219 | if (new_mode == BTM_BLE_ADV_ENABLE) |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1220 | status = btm_ble_start_adv(); |
Satya Calloji | 70b9598 | 2015-04-23 23:39:49 -0700 | [diff] [blame] | 1221 | else |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1222 | status = btm_ble_stop_adv(); |
| 1223 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1224 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1225 | if (p_cb->adv_mode == BTM_BLE_ADV_ENABLE) { |
| 1226 | p_cb->fast_adv_on = true; |
| 1227 | /* start initial GAP mode adv timer */ |
| 1228 | alarm_set_on_queue(p_cb->fast_adv_timer, BTM_BLE_GAP_FAST_ADV_TIMEOUT_MS, |
| 1229 | btm_ble_fast_adv_timer_timeout, NULL, |
| 1230 | btu_general_alarm_queue); |
| 1231 | } else { |
| 1232 | #if (BLE_PRIVACY_SPT == TRUE) |
| 1233 | btm_ble_disable_resolving_list(BTM_BLE_RL_ADV, true); |
| 1234 | #endif |
| 1235 | } |
| 1236 | |
| 1237 | /* set up stop advertising timer */ |
| 1238 | if (status == BTM_SUCCESS && mode == BTM_BLE_LIMITED_DISCOVERABLE) { |
| 1239 | BTM_TRACE_EVENT("start timer for limited disc mode duration=%d ms", |
| 1240 | BTM_BLE_GAP_LIM_TIMEOUT_MS); |
| 1241 | /* start Tgap(lim_timeout) */ |
| 1242 | alarm_set_on_queue(p_cb->inquiry_timer, BTM_BLE_GAP_LIM_TIMEOUT_MS, |
| 1243 | btm_ble_inquiry_timer_gap_limited_discovery_timeout, |
| 1244 | NULL, btu_general_alarm_queue); |
| 1245 | } |
| 1246 | return status; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1247 | } |
| 1248 | |
| 1249 | /******************************************************************************* |
Myles Watson | ee96a3c | 2016-11-23 14:49:54 -0800 | [diff] [blame] | 1250 | * |
| 1251 | * Function btm_ble_set_connectability |
| 1252 | * |
| 1253 | * Description This function is called to set BLE connectability mode. |
| 1254 | * |
| 1255 | * Parameters: combined_mode: connectability mode. |
| 1256 | * |
| 1257 | * Returns BTM_SUCCESS is status set successfully; otherwise failure. |
| 1258 | * |
| 1259 | ******************************************************************************/ |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1260 | tBTM_STATUS btm_ble_set_connectability(uint16_t combined_mode) { |
| 1261 | tBTM_LE_RANDOM_CB* p_addr_cb = &btm_cb.ble_ctr_cb.addr_mgnt_cb; |
| 1262 | tBTM_BLE_INQ_CB* p_cb = &btm_cb.ble_ctr_cb.inq_var; |
| 1263 | uint16_t mode = (combined_mode & BTM_BLE_CONNECTABLE_MASK); |
| 1264 | uint8_t new_mode = BTM_BLE_ADV_ENABLE; |
| 1265 | uint8_t evt_type; |
| 1266 | tBTM_STATUS status = BTM_SUCCESS; |
Jakub Pawlowski | b707f44 | 2017-07-03 15:39:36 -0700 | [diff] [blame^] | 1267 | RawAddress address = RawAddress::kEmpty; |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1268 | tBLE_ADDR_TYPE peer_addr_type = BLE_ADDR_PUBLIC, |
| 1269 | own_addr_type = p_addr_cb->own_addr_type; |
| 1270 | uint16_t adv_int_min, adv_int_max; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1271 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1272 | BTM_TRACE_EVENT("%s mode=0x%0x combined_mode=0x%x", __func__, mode, |
| 1273 | combined_mode); |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1274 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1275 | /*** Check mode parameter ***/ |
| 1276 | if (mode > BTM_BLE_MAX_CONNECTABLE) return (BTM_ILLEGAL_VALUE); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1277 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1278 | p_cb->connectable_mode = mode; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1279 | |
Jakub Pawlowski | b707f44 | 2017-07-03 15:39:36 -0700 | [diff] [blame^] | 1280 | evt_type = btm_set_conn_mode_adv_init_addr(p_cb, address, &peer_addr_type, |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1281 | &own_addr_type); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1282 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1283 | if (mode == BTM_BLE_NON_CONNECTABLE && |
| 1284 | p_cb->discoverable_mode == BTM_BLE_NON_DISCOVERABLE) |
| 1285 | new_mode = BTM_BLE_ADV_DISABLE; |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1286 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1287 | btm_ble_select_adv_interval(p_cb, evt_type, &adv_int_min, &adv_int_max); |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1288 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1289 | alarm_cancel(p_cb->fast_adv_timer); |
| 1290 | /* update adv params if needed */ |
| 1291 | if (new_mode == BTM_BLE_ADV_ENABLE) { |
| 1292 | btm_ble_set_adv_flag(combined_mode, btm_cb.btm_inq_vars.discoverable_mode); |
| 1293 | if (p_cb->evt_type != evt_type || |
| 1294 | p_cb->adv_addr_type != p_addr_cb->own_addr_type || !p_cb->fast_adv_on) { |
| 1295 | btm_ble_stop_adv(); |
| 1296 | |
| 1297 | btsnd_hcic_ble_write_adv_params(adv_int_min, adv_int_max, evt_type, |
Jakub Pawlowski | b707f44 | 2017-07-03 15:39:36 -0700 | [diff] [blame^] | 1298 | own_addr_type, peer_addr_type, address, |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1299 | p_cb->adv_chnl_map, p_cb->afp); |
| 1300 | p_cb->evt_type = evt_type; |
| 1301 | p_cb->adv_addr_type = own_addr_type; |
| 1302 | } |
| 1303 | } |
| 1304 | |
| 1305 | /* update advertising mode */ |
| 1306 | if (status == BTM_SUCCESS && new_mode != p_cb->adv_mode) { |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 1307 | if (new_mode == BTM_BLE_ADV_ENABLE) |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1308 | status = btm_ble_start_adv(); |
Satya Calloji | 70b9598 | 2015-04-23 23:39:49 -0700 | [diff] [blame] | 1309 | else |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1310 | status = btm_ble_stop_adv(); |
| 1311 | } |
| 1312 | |
| 1313 | if (p_cb->adv_mode == BTM_BLE_ADV_ENABLE) { |
| 1314 | p_cb->fast_adv_on = true; |
| 1315 | /* start initial GAP mode adv timer */ |
| 1316 | alarm_set_on_queue(p_cb->fast_adv_timer, BTM_BLE_GAP_FAST_ADV_TIMEOUT_MS, |
| 1317 | btm_ble_fast_adv_timer_timeout, NULL, |
| 1318 | btu_general_alarm_queue); |
| 1319 | } else { |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 1320 | #if (BLE_PRIVACY_SPT == TRUE) |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1321 | btm_ble_disable_resolving_list(BTM_BLE_RL_ADV, true); |
Andre Eisenbach | a021a12 | 2015-05-20 23:55:13 -0700 | [diff] [blame] | 1322 | #endif |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1323 | } |
| 1324 | return status; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1325 | } |
| 1326 | |
Jakub Pawlowski | 9df2a55 | 2016-12-02 11:34:06 -0800 | [diff] [blame] | 1327 | void btm_send_hci_scan_enable(uint8_t enable, uint8_t filter_duplicates) { |
| 1328 | if (controller_get_interface()->supports_ble_extended_advertising()) { |
| 1329 | btsnd_hcic_ble_set_extended_scan_enable(enable, filter_duplicates, 0x0000, |
| 1330 | 0x0000); |
| 1331 | } else { |
| 1332 | btsnd_hcic_ble_set_scan_enable(enable, filter_duplicates); |
| 1333 | } |
| 1334 | } |
| 1335 | |
| 1336 | void btm_send_hci_set_scan_params(uint8_t scan_type, uint16_t scan_int, |
| 1337 | uint16_t scan_win, uint8_t addr_type_own, |
| 1338 | uint8_t scan_filter_policy) { |
| 1339 | if (controller_get_interface()->supports_ble_extended_advertising()) { |
| 1340 | scanning_phy_cfg phy_cfg; |
| 1341 | phy_cfg.scan_type = scan_type; |
| 1342 | phy_cfg.scan_int = scan_int; |
| 1343 | phy_cfg.scan_win = scan_win; |
| 1344 | |
| 1345 | btsnd_hcic_ble_set_extended_scan_params(addr_type_own, scan_filter_policy, |
| 1346 | 1, &phy_cfg); |
| 1347 | } else { |
| 1348 | btsnd_hcic_ble_set_scan_params(scan_type, scan_int, scan_win, addr_type_own, |
| 1349 | scan_filter_policy); |
| 1350 | } |
| 1351 | } |
| 1352 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1353 | /******************************************************************************* |
Myles Watson | ee96a3c | 2016-11-23 14:49:54 -0800 | [diff] [blame] | 1354 | * |
| 1355 | * Function btm_ble_start_inquiry |
| 1356 | * |
| 1357 | * Description This function is called to start BLE inquiry procedure. |
Myles Watson | 9ca0709 | 2016-11-28 16:41:53 -0800 | [diff] [blame] | 1358 | * If the duration is zero, the periodic inquiry mode is |
| 1359 | * cancelled. |
Myles Watson | ee96a3c | 2016-11-23 14:49:54 -0800 | [diff] [blame] | 1360 | * |
| 1361 | * Parameters: mode - GENERAL or LIMITED inquiry |
| 1362 | * p_inq_params - pointer to the BLE inquiry parameter. |
Myles Watson | 9ca0709 | 2016-11-28 16:41:53 -0800 | [diff] [blame] | 1363 | * p_results_cb - callback returning pointer to results |
| 1364 | * (tBTM_INQ_RESULTS) |
Myles Watson | ee96a3c | 2016-11-23 14:49:54 -0800 | [diff] [blame] | 1365 | * p_cmpl_cb - callback indicating the end of an inquiry |
| 1366 | * |
| 1367 | * |
| 1368 | * |
| 1369 | * Returns BTM_CMD_STARTED if successfully started |
| 1370 | * BTM_NO_RESOURCES if could not allocate a message buffer |
| 1371 | * BTM_BUSY - if an inquiry is already active |
| 1372 | * |
| 1373 | ******************************************************************************/ |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1374 | tBTM_STATUS btm_ble_start_inquiry(uint8_t mode, uint8_t duration) { |
| 1375 | tBTM_STATUS status = BTM_CMD_STARTED; |
| 1376 | tBTM_BLE_CB* p_ble_cb = &btm_cb.ble_ctr_cb; |
| 1377 | tBTM_INQUIRY_VAR_ST* p_inq = &btm_cb.btm_inq_vars; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1378 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1379 | BTM_TRACE_DEBUG("btm_ble_start_inquiry: mode = %02x inq_active = 0x%02x", |
| 1380 | mode, btm_cb.btm_inq_vars.inq_active); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1381 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1382 | /* if selective connection is active, or inquiry is already active, reject it |
| 1383 | */ |
Jakub Pawlowski | 83211b0 | 2016-12-07 11:25:15 -0800 | [diff] [blame] | 1384 | if (BTM_BLE_IS_INQ_ACTIVE(p_ble_cb->scan_activity)) { |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1385 | BTM_TRACE_ERROR("LE Inquiry is active, can not start inquiry"); |
| 1386 | return (BTM_BUSY); |
| 1387 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1388 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1389 | if (!BTM_BLE_IS_SCAN_ACTIVE(p_ble_cb->scan_activity)) { |
Jakub Pawlowski | 9df2a55 | 2016-12-02 11:34:06 -0800 | [diff] [blame] | 1390 | btm_send_hci_set_scan_params( |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1391 | BTM_BLE_SCAN_MODE_ACTI, BTM_BLE_LOW_LATENCY_SCAN_INT, |
| 1392 | BTM_BLE_LOW_LATENCY_SCAN_WIN, |
| 1393 | btm_cb.ble_ctr_cb.addr_mgnt_cb.own_addr_type, SP_ADV_ALL); |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 1394 | #if (BLE_PRIVACY_SPT == TRUE) |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1395 | /* enable IRK list */ |
| 1396 | btm_ble_enable_resolving_list_for_platform(BTM_BLE_RL_SCAN); |
Wei Wang | ed534e3 | 2014-05-20 06:30:13 +0000 | [diff] [blame] | 1397 | #endif |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1398 | p_ble_cb->inq_var.scan_duplicate_filter = BTM_BLE_DUPLICATE_DISABLE; |
| 1399 | status = btm_ble_start_scan(); |
| 1400 | } else if ((p_ble_cb->inq_var.scan_interval != |
| 1401 | BTM_BLE_LOW_LATENCY_SCAN_INT) || |
| 1402 | (p_ble_cb->inq_var.scan_window != BTM_BLE_LOW_LATENCY_SCAN_WIN)) { |
| 1403 | BTM_TRACE_DEBUG("%s, restart LE scan with low latency scan params", |
| 1404 | __func__); |
Jakub Pawlowski | 9df2a55 | 2016-12-02 11:34:06 -0800 | [diff] [blame] | 1405 | btm_send_hci_scan_enable(BTM_BLE_SCAN_DISABLE, BTM_BLE_DUPLICATE_ENABLE); |
| 1406 | btm_send_hci_set_scan_params( |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1407 | BTM_BLE_SCAN_MODE_ACTI, BTM_BLE_LOW_LATENCY_SCAN_INT, |
| 1408 | BTM_BLE_LOW_LATENCY_SCAN_WIN, |
| 1409 | btm_cb.ble_ctr_cb.addr_mgnt_cb.own_addr_type, SP_ADV_ALL); |
Jakub Pawlowski | 9df2a55 | 2016-12-02 11:34:06 -0800 | [diff] [blame] | 1410 | btm_send_hci_scan_enable(BTM_BLE_SCAN_ENABLE, BTM_BLE_DUPLICATE_DISABLE); |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1411 | } |
| 1412 | |
| 1413 | if (status == BTM_CMD_STARTED) { |
| 1414 | p_inq->inq_active |= mode; |
| 1415 | p_ble_cb->scan_activity |= mode; |
| 1416 | |
| 1417 | BTM_TRACE_DEBUG("btm_ble_start_inquiry inq_active = 0x%02x", |
| 1418 | p_inq->inq_active); |
| 1419 | |
| 1420 | if (duration != 0) { |
| 1421 | /* start inquiry timer */ |
| 1422 | period_ms_t duration_ms = duration * 1000; |
| 1423 | alarm_set_on_queue(p_ble_cb->inq_var.inquiry_timer, duration_ms, |
| 1424 | btm_ble_inquiry_timer_timeout, NULL, |
| 1425 | btu_general_alarm_queue); |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1426 | } |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1427 | } |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1428 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1429 | return status; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1430 | } |
| 1431 | |
| 1432 | /******************************************************************************* |
Myles Watson | ee96a3c | 2016-11-23 14:49:54 -0800 | [diff] [blame] | 1433 | * |
| 1434 | * Function btm_ble_read_remote_name_cmpl |
| 1435 | * |
| 1436 | * Description This function is called when BLE remote name is received. |
| 1437 | * |
| 1438 | * Returns void |
| 1439 | * |
| 1440 | ******************************************************************************/ |
Jakub Pawlowski | a484a88 | 2017-06-24 17:30:18 -0700 | [diff] [blame] | 1441 | void btm_ble_read_remote_name_cmpl(bool status, const RawAddress& bda, |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 1442 | uint16_t length, char* p_name) { |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1443 | uint8_t hci_status = HCI_SUCCESS; |
| 1444 | BD_NAME bd_name; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1445 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1446 | memset(bd_name, 0, (BD_NAME_LEN + 1)); |
| 1447 | if (length > BD_NAME_LEN) { |
| 1448 | length = BD_NAME_LEN; |
| 1449 | } |
| 1450 | memcpy((uint8_t*)bd_name, p_name, length); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1451 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1452 | if ((!status) || (length == 0)) { |
| 1453 | hci_status = HCI_ERR_HOST_TIMEOUT; |
| 1454 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1455 | |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 1456 | btm_process_remote_name(&bda, bd_name, length + 1, hci_status); |
| 1457 | btm_sec_rmt_name_request_complete(&bda, (uint8_t*)p_name, hci_status); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1458 | } |
| 1459 | |
| 1460 | /******************************************************************************* |
Myles Watson | ee96a3c | 2016-11-23 14:49:54 -0800 | [diff] [blame] | 1461 | * |
| 1462 | * Function btm_ble_read_remote_name |
| 1463 | * |
| 1464 | * Description This function read remote LE device name using GATT read |
| 1465 | * procedure. |
| 1466 | * |
| 1467 | * Parameters: None. |
| 1468 | * |
| 1469 | * Returns void |
| 1470 | * |
| 1471 | ******************************************************************************/ |
Jakub Pawlowski | a484a88 | 2017-06-24 17:30:18 -0700 | [diff] [blame] | 1472 | tBTM_STATUS btm_ble_read_remote_name(const RawAddress& remote_bda, |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 1473 | tBTM_CMPL_CB* p_cb) { |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1474 | tBTM_INQUIRY_VAR_ST* p_inq = &btm_cb.btm_inq_vars; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1475 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1476 | if (!controller_get_interface()->supports_ble()) return BTM_ERR_PROCESSING; |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 1477 | |
Jack He | 8bf2285 | 2017-02-16 03:06:15 -0500 | [diff] [blame] | 1478 | tINQ_DB_ENT* p_i = btm_inq_db_find(remote_bda); |
| 1479 | if (p_i && !ble_evt_type_is_connectable(p_i->inq_info.results.ble_evt_type)) { |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1480 | BTM_TRACE_DEBUG("name request to non-connectable device failed."); |
| 1481 | return BTM_ERR_PROCESSING; |
| 1482 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1483 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1484 | /* read remote device name using GATT procedure */ |
| 1485 | if (p_inq->remname_active) return BTM_BUSY; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1486 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1487 | if (!GAP_BleReadPeerDevName(remote_bda, btm_ble_read_remote_name_cmpl)) |
| 1488 | return BTM_BUSY; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1489 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1490 | p_inq->p_remname_cmpl_cb = p_cb; |
| 1491 | p_inq->remname_active = true; |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 1492 | p_inq->remname_bda = remote_bda; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1493 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1494 | alarm_set_on_queue(p_inq->remote_name_timer, BTM_EXT_BLE_RMT_NAME_TIMEOUT_MS, |
| 1495 | btm_inq_remote_name_timer_timeout, NULL, |
| 1496 | btu_general_alarm_queue); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1497 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1498 | return BTM_CMD_STARTED; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1499 | } |
| 1500 | |
| 1501 | /******************************************************************************* |
Myles Watson | ee96a3c | 2016-11-23 14:49:54 -0800 | [diff] [blame] | 1502 | * |
| 1503 | * Function btm_ble_cancel_remote_name |
| 1504 | * |
| 1505 | * Description This function cancel read remote LE device name. |
| 1506 | * |
| 1507 | * Parameters: None. |
| 1508 | * |
| 1509 | * Returns void |
| 1510 | * |
| 1511 | ******************************************************************************/ |
Jakub Pawlowski | a484a88 | 2017-06-24 17:30:18 -0700 | [diff] [blame] | 1512 | bool btm_ble_cancel_remote_name(const RawAddress& remote_bda) { |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1513 | tBTM_INQUIRY_VAR_ST* p_inq = &btm_cb.btm_inq_vars; |
| 1514 | bool status; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1515 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1516 | status = GAP_BleCancelReadPeerDevName(remote_bda); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1517 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1518 | p_inq->remname_active = false; |
Jakub Pawlowski | b707f44 | 2017-07-03 15:39:36 -0700 | [diff] [blame^] | 1519 | p_inq->remname_bda = RawAddress::kEmpty; |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1520 | alarm_cancel(p_inq->remote_name_timer); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1521 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1522 | return status; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1523 | } |
| 1524 | |
| 1525 | /******************************************************************************* |
Myles Watson | ee96a3c | 2016-11-23 14:49:54 -0800 | [diff] [blame] | 1526 | * |
| 1527 | * Function btm_ble_update_adv_flag |
| 1528 | * |
Myles Watson | 9ca0709 | 2016-11-28 16:41:53 -0800 | [diff] [blame] | 1529 | * Description This function update the limited discoverable flag in the |
| 1530 | * adv data. |
Myles Watson | ee96a3c | 2016-11-23 14:49:54 -0800 | [diff] [blame] | 1531 | * |
| 1532 | * Parameters: None. |
| 1533 | * |
| 1534 | * Returns void |
| 1535 | * |
| 1536 | ******************************************************************************/ |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1537 | static void btm_ble_update_adv_flag(uint8_t flag) { |
| 1538 | tBTM_BLE_LOCAL_ADV_DATA* p_adv_data = &btm_cb.ble_ctr_cb.inq_var.adv_data; |
| 1539 | uint8_t* p; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1540 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1541 | BTM_TRACE_DEBUG("btm_ble_update_adv_flag new=0x%x", flag); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1542 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1543 | if (p_adv_data->p_flags != NULL) { |
| 1544 | BTM_TRACE_DEBUG("btm_ble_update_adv_flag old=0x%x", *p_adv_data->p_flags); |
| 1545 | *p_adv_data->p_flags = flag; |
| 1546 | } else /* no FLAGS in ADV data*/ |
| 1547 | { |
| 1548 | p = (p_adv_data->p_pad == NULL) ? p_adv_data->ad_data : p_adv_data->p_pad; |
| 1549 | /* need 3 bytes space to stuff in the flags, if not */ |
| 1550 | /* erase all written data, just for flags */ |
| 1551 | if ((BTM_BLE_AD_DATA_LEN - (p - p_adv_data->ad_data)) < 3) { |
| 1552 | p = p_adv_data->p_pad = p_adv_data->ad_data; |
| 1553 | memset(p_adv_data->ad_data, 0, BTM_BLE_AD_DATA_LEN); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1554 | } |
| 1555 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1556 | *p++ = 2; |
| 1557 | *p++ = BTM_BLE_AD_TYPE_FLAG; |
| 1558 | p_adv_data->p_flags = p; |
| 1559 | *p++ = flag; |
| 1560 | p_adv_data->p_pad = p; |
| 1561 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1562 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1563 | btsnd_hcic_ble_set_adv_data( |
| 1564 | (uint8_t)(p_adv_data->p_pad - p_adv_data->ad_data), p_adv_data->ad_data); |
| 1565 | p_adv_data->data_mask |= BTM_BLE_AD_BIT_FLAGS; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1566 | } |
| 1567 | |
Jakub Pawlowski | d64bf4f | 2017-01-27 05:53:07 -0800 | [diff] [blame] | 1568 | /** |
Jakub Pawlowski | d64bf4f | 2017-01-27 05:53:07 -0800 | [diff] [blame] | 1569 | * Check ADV flag to make sure device is discoverable and match the search |
| 1570 | * condition |
| 1571 | */ |
Jakub Pawlowski | a484a88 | 2017-06-24 17:30:18 -0700 | [diff] [blame] | 1572 | uint8_t btm_ble_is_discoverable(const RawAddress& bda, |
Jakub Pawlowski | 0595ca0 | 2017-02-07 12:15:06 -0800 | [diff] [blame] | 1573 | std::vector<uint8_t> const& adv_data) { |
| 1574 | uint8_t flag = 0, rt = 0; |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1575 | uint8_t data_len; |
| 1576 | tBTM_INQ_PARMS* p_cond = &btm_cb.btm_inq_vars.inqparms; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1577 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1578 | /* for observer, always "discoverable */ |
| 1579 | if (BTM_BLE_IS_OBS_ACTIVE(btm_cb.ble_ctr_cb.scan_activity)) |
| 1580 | rt |= BTM_BLE_OBS_RESULT; |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1581 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1582 | /* does not match filter condition */ |
| 1583 | if (p_cond->filter_cond_type == BTM_FILTER_COND_BD_ADDR && |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 1584 | bda != p_cond->filter_cond.bdaddr_cond) { |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1585 | BTM_TRACE_DEBUG("BD ADDR does not meet filter condition"); |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1586 | return rt; |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1587 | } |
| 1588 | |
Jakub Pawlowski | 0595ca0 | 2017-02-07 12:15:06 -0800 | [diff] [blame] | 1589 | if (!adv_data.empty()) { |
Jakub Pawlowski | 103b2c4 | 2017-04-28 14:59:46 -0700 | [diff] [blame] | 1590 | const uint8_t* p_flag = AdvertiseDataParser::GetFieldByType( |
| 1591 | adv_data, BTM_BLE_AD_TYPE_FLAG, &data_len); |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1592 | if (p_flag != NULL) { |
| 1593 | flag = *p_flag; |
| 1594 | |
| 1595 | if ((btm_cb.btm_inq_vars.inq_active & BTM_BLE_GENERAL_INQUIRY) && |
| 1596 | (flag & (BTM_BLE_LIMIT_DISC_FLAG | BTM_BLE_GEN_DISC_FLAG)) != 0) { |
| 1597 | BTM_TRACE_DEBUG("Find Generable Discoverable device"); |
| 1598 | rt |= BTM_BLE_INQ_RESULT; |
| 1599 | } |
| 1600 | |
| 1601 | else if (btm_cb.btm_inq_vars.inq_active & BTM_BLE_LIMITED_INQUIRY && |
| 1602 | (flag & BTM_BLE_LIMIT_DISC_FLAG) != 0) { |
| 1603 | BTM_TRACE_DEBUG("Find limited discoverable device"); |
| 1604 | rt |= BTM_BLE_INQ_RESULT; |
| 1605 | } |
| 1606 | } |
| 1607 | } |
| 1608 | return rt; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1609 | } |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1610 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1611 | static void btm_ble_appearance_to_cod(uint16_t appearance, uint8_t* dev_class) { |
| 1612 | dev_class[0] = 0; |
Adam Hampson | e6c7450 | 2014-05-30 15:07:08 -0700 | [diff] [blame] | 1613 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1614 | switch (appearance) { |
| 1615 | case BTM_BLE_APPEARANCE_GENERIC_PHONE: |
| 1616 | dev_class[1] = BTM_COD_MAJOR_PHONE; |
| 1617 | dev_class[2] = BTM_COD_MINOR_UNCLASSIFIED; |
| 1618 | break; |
| 1619 | case BTM_BLE_APPEARANCE_GENERIC_COMPUTER: |
| 1620 | dev_class[1] = BTM_COD_MAJOR_COMPUTER; |
| 1621 | dev_class[2] = BTM_COD_MINOR_UNCLASSIFIED; |
| 1622 | break; |
| 1623 | case BTM_BLE_APPEARANCE_GENERIC_REMOTE: |
| 1624 | dev_class[1] = BTM_COD_MAJOR_PERIPHERAL; |
| 1625 | dev_class[2] = BTM_COD_MINOR_REMOTE_CONTROL; |
| 1626 | break; |
| 1627 | case BTM_BLE_APPEARANCE_GENERIC_THERMOMETER: |
| 1628 | case BTM_BLE_APPEARANCE_THERMOMETER_EAR: |
| 1629 | dev_class[1] = BTM_COD_MAJOR_HEALTH; |
| 1630 | dev_class[2] = BTM_COD_MINOR_THERMOMETER; |
| 1631 | break; |
| 1632 | case BTM_BLE_APPEARANCE_GENERIC_HEART_RATE: |
| 1633 | case BTM_BLE_APPEARANCE_HEART_RATE_BELT: |
| 1634 | dev_class[1] = BTM_COD_MAJOR_HEALTH; |
| 1635 | dev_class[2] = BTM_COD_MINOR_HEART_PULSE_MONITOR; |
| 1636 | break; |
| 1637 | case BTM_BLE_APPEARANCE_GENERIC_BLOOD_PRESSURE: |
| 1638 | case BTM_BLE_APPEARANCE_BLOOD_PRESSURE_ARM: |
| 1639 | case BTM_BLE_APPEARANCE_BLOOD_PRESSURE_WRIST: |
| 1640 | dev_class[1] = BTM_COD_MAJOR_HEALTH; |
| 1641 | dev_class[2] = BTM_COD_MINOR_BLOOD_MONITOR; |
| 1642 | break; |
| 1643 | case BTM_BLE_APPEARANCE_GENERIC_PULSE_OXIMETER: |
| 1644 | case BTM_BLE_APPEARANCE_PULSE_OXIMETER_FINGERTIP: |
| 1645 | case BTM_BLE_APPEARANCE_PULSE_OXIMETER_WRIST: |
| 1646 | dev_class[1] = BTM_COD_MAJOR_HEALTH; |
| 1647 | dev_class[2] = BTM_COD_MINOR_PULSE_OXIMETER; |
| 1648 | break; |
| 1649 | case BTM_BLE_APPEARANCE_GENERIC_GLUCOSE: |
| 1650 | dev_class[1] = BTM_COD_MAJOR_HEALTH; |
| 1651 | dev_class[2] = BTM_COD_MINOR_GLUCOSE_METER; |
| 1652 | break; |
| 1653 | case BTM_BLE_APPEARANCE_GENERIC_WEIGHT: |
| 1654 | dev_class[1] = BTM_COD_MAJOR_HEALTH; |
| 1655 | dev_class[2] = BTM_COD_MINOR_WEIGHING_SCALE; |
| 1656 | break; |
| 1657 | case BTM_BLE_APPEARANCE_GENERIC_WALKING: |
| 1658 | case BTM_BLE_APPEARANCE_WALKING_IN_SHOE: |
| 1659 | case BTM_BLE_APPEARANCE_WALKING_ON_SHOE: |
| 1660 | case BTM_BLE_APPEARANCE_WALKING_ON_HIP: |
| 1661 | dev_class[1] = BTM_COD_MAJOR_HEALTH; |
| 1662 | dev_class[2] = BTM_COD_MINOR_STEP_COUNTER; |
| 1663 | break; |
| 1664 | case BTM_BLE_APPEARANCE_GENERIC_WATCH: |
| 1665 | case BTM_BLE_APPEARANCE_SPORTS_WATCH: |
| 1666 | dev_class[1] = BTM_COD_MAJOR_WEARABLE; |
| 1667 | dev_class[2] = BTM_COD_MINOR_WRIST_WATCH; |
| 1668 | break; |
| 1669 | case BTM_BLE_APPEARANCE_GENERIC_EYEGLASSES: |
| 1670 | dev_class[1] = BTM_COD_MAJOR_WEARABLE; |
| 1671 | dev_class[2] = BTM_COD_MINOR_GLASSES; |
| 1672 | break; |
| 1673 | case BTM_BLE_APPEARANCE_GENERIC_DISPLAY: |
| 1674 | dev_class[1] = BTM_COD_MAJOR_IMAGING; |
| 1675 | dev_class[2] = BTM_COD_MINOR_DISPLAY; |
| 1676 | break; |
| 1677 | case BTM_BLE_APPEARANCE_GENERIC_MEDIA_PLAYER: |
| 1678 | dev_class[1] = BTM_COD_MAJOR_AUDIO; |
| 1679 | dev_class[2] = BTM_COD_MINOR_UNCLASSIFIED; |
| 1680 | break; |
| 1681 | case BTM_BLE_APPEARANCE_GENERIC_BARCODE_SCANNER: |
| 1682 | case BTM_BLE_APPEARANCE_HID_BARCODE_SCANNER: |
| 1683 | case BTM_BLE_APPEARANCE_GENERIC_HID: |
| 1684 | dev_class[1] = BTM_COD_MAJOR_PERIPHERAL; |
| 1685 | dev_class[2] = BTM_COD_MINOR_UNCLASSIFIED; |
| 1686 | break; |
| 1687 | case BTM_BLE_APPEARANCE_HID_KEYBOARD: |
| 1688 | dev_class[1] = BTM_COD_MAJOR_PERIPHERAL; |
| 1689 | dev_class[2] = BTM_COD_MINOR_KEYBOARD; |
| 1690 | break; |
| 1691 | case BTM_BLE_APPEARANCE_HID_MOUSE: |
| 1692 | dev_class[1] = BTM_COD_MAJOR_PERIPHERAL; |
| 1693 | dev_class[2] = BTM_COD_MINOR_POINTING; |
| 1694 | break; |
| 1695 | case BTM_BLE_APPEARANCE_HID_JOYSTICK: |
| 1696 | dev_class[1] = BTM_COD_MAJOR_PERIPHERAL; |
| 1697 | dev_class[2] = BTM_COD_MINOR_JOYSTICK; |
| 1698 | break; |
| 1699 | case BTM_BLE_APPEARANCE_HID_GAMEPAD: |
| 1700 | dev_class[1] = BTM_COD_MAJOR_PERIPHERAL; |
| 1701 | dev_class[2] = BTM_COD_MINOR_GAMEPAD; |
| 1702 | break; |
| 1703 | case BTM_BLE_APPEARANCE_HID_DIGITIZER_TABLET: |
| 1704 | dev_class[1] = BTM_COD_MAJOR_PERIPHERAL; |
| 1705 | dev_class[2] = BTM_COD_MINOR_DIGITIZING_TABLET; |
| 1706 | break; |
| 1707 | case BTM_BLE_APPEARANCE_HID_CARD_READER: |
| 1708 | dev_class[1] = BTM_COD_MAJOR_PERIPHERAL; |
| 1709 | dev_class[2] = BTM_COD_MINOR_CARD_READER; |
| 1710 | break; |
| 1711 | case BTM_BLE_APPEARANCE_HID_DIGITAL_PEN: |
| 1712 | dev_class[1] = BTM_COD_MAJOR_PERIPHERAL; |
| 1713 | dev_class[2] = BTM_COD_MINOR_DIGITAL_PAN; |
| 1714 | break; |
| 1715 | case BTM_BLE_APPEARANCE_UKNOWN: |
| 1716 | case BTM_BLE_APPEARANCE_GENERIC_CLOCK: |
| 1717 | case BTM_BLE_APPEARANCE_GENERIC_TAG: |
| 1718 | case BTM_BLE_APPEARANCE_GENERIC_KEYRING: |
| 1719 | case BTM_BLE_APPEARANCE_GENERIC_CYCLING: |
| 1720 | case BTM_BLE_APPEARANCE_CYCLING_COMPUTER: |
| 1721 | case BTM_BLE_APPEARANCE_CYCLING_SPEED: |
| 1722 | case BTM_BLE_APPEARANCE_CYCLING_CADENCE: |
| 1723 | case BTM_BLE_APPEARANCE_CYCLING_POWER: |
| 1724 | case BTM_BLE_APPEARANCE_CYCLING_SPEED_CADENCE: |
| 1725 | case BTM_BLE_APPEARANCE_GENERIC_OUTDOOR_SPORTS: |
| 1726 | case BTM_BLE_APPEARANCE_OUTDOOR_SPORTS_LOCATION: |
| 1727 | case BTM_BLE_APPEARANCE_OUTDOOR_SPORTS_LOCATION_AND_NAV: |
| 1728 | case BTM_BLE_APPEARANCE_OUTDOOR_SPORTS_LOCATION_POD: |
| 1729 | case BTM_BLE_APPEARANCE_OUTDOOR_SPORTS_LOCATION_POD_AND_NAV: |
| 1730 | default: |
| 1731 | dev_class[1] = BTM_COD_MAJOR_UNCLASSIFIED; |
| 1732 | dev_class[2] = BTM_COD_MINOR_UNCLASSIFIED; |
| 1733 | }; |
Adam Hampson | e6c7450 | 2014-05-30 15:07:08 -0700 | [diff] [blame] | 1734 | } |
| 1735 | |
Jakub Pawlowski | d64bf4f | 2017-01-27 05:53:07 -0800 | [diff] [blame] | 1736 | /** |
| 1737 | * Update adv packet information into inquiry result. |
| 1738 | */ |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 1739 | void btm_ble_update_inq_result(tINQ_DB_ENT* p_i, uint8_t addr_type, |
Jakub Pawlowski | a484a88 | 2017-06-24 17:30:18 -0700 | [diff] [blame] | 1740 | const RawAddress& bda, uint16_t evt_type, |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 1741 | uint8_t primary_phy, uint8_t secondary_phy, |
| 1742 | uint8_t advertising_sid, int8_t tx_power, |
| 1743 | int8_t rssi, uint16_t periodic_adv_int, |
Jakub Pawlowski | 0595ca0 | 2017-02-07 12:15:06 -0800 | [diff] [blame] | 1744 | std::vector<uint8_t> const& data) { |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1745 | tBTM_INQ_RESULTS* p_cur = &p_i->inq_info.results; |
| 1746 | uint8_t len; |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1747 | tBTM_INQUIRY_VAR_ST* p_inq = &btm_cb.btm_inq_vars; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1748 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1749 | /* Save the info */ |
| 1750 | p_cur->inq_result_type = BTM_INQ_RESULT_BLE; |
| 1751 | p_cur->ble_addr_type = addr_type; |
| 1752 | p_cur->rssi = rssi; |
Jakub Pawlowski | 7de0f9b | 2017-01-27 08:06:20 -0800 | [diff] [blame] | 1753 | p_cur->ble_primary_phy = primary_phy; |
| 1754 | p_cur->ble_secondary_phy = secondary_phy; |
| 1755 | p_cur->ble_advertising_sid = advertising_sid; |
| 1756 | p_cur->ble_tx_power = tx_power; |
| 1757 | p_cur->ble_periodic_adv_int = periodic_adv_int; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1758 | |
Jakub Pawlowski | d64bf4f | 2017-01-27 05:53:07 -0800 | [diff] [blame] | 1759 | if (btm_cb.ble_ctr_cb.inq_var.scan_type == BTM_BLE_SCAN_MODE_ACTI && |
| 1760 | ble_evt_type_is_scannable(evt_type) && |
| 1761 | !ble_evt_type_is_scan_resp(evt_type)) { |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1762 | p_i->scan_rsp = false; |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1763 | } else |
| 1764 | p_i->scan_rsp = true; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1765 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1766 | if (p_i->inq_count != p_inq->inq_counter) |
| 1767 | p_cur->device_type = BT_DEVICE_TYPE_BLE; |
| 1768 | else |
| 1769 | p_cur->device_type |= BT_DEVICE_TYPE_BLE; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1770 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1771 | if (evt_type != BTM_BLE_SCAN_RSP_EVT) p_cur->ble_evt_type = evt_type; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1772 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1773 | p_i->inq_count = p_inq->inq_counter; /* Mark entry for current inquiry */ |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1774 | |
Jakub Pawlowski | 0595ca0 | 2017-02-07 12:15:06 -0800 | [diff] [blame] | 1775 | if (!data.empty()) { |
Jakub Pawlowski | 103b2c4 | 2017-04-28 14:59:46 -0700 | [diff] [blame] | 1776 | const uint8_t* p_flag = |
| 1777 | AdvertiseDataParser::GetFieldByType(data, BTM_BLE_AD_TYPE_FLAG, &len); |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1778 | if (p_flag != NULL) p_cur->flag = *p_flag; |
| 1779 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1780 | |
Jakub Pawlowski | 0595ca0 | 2017-02-07 12:15:06 -0800 | [diff] [blame] | 1781 | if (!data.empty()) { |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1782 | /* Check to see the BLE device has the Appearance UUID in the advertising |
| 1783 | * data. If it does |
| 1784 | * then try to convert the appearance value to a class of device value |
| 1785 | * Bluedroid can use. |
| 1786 | * Otherwise fall back to trying to infer if it is a HID device based on the |
| 1787 | * service class. |
| 1788 | */ |
Jakub Pawlowski | 103b2c4 | 2017-04-28 14:59:46 -0700 | [diff] [blame] | 1789 | const uint8_t* p_uuid16 = AdvertiseDataParser::GetFieldByType( |
| 1790 | data, BTM_BLE_AD_TYPE_APPEARANCE, &len); |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1791 | if (p_uuid16 && len == 2) { |
| 1792 | btm_ble_appearance_to_cod((uint16_t)p_uuid16[0] | (p_uuid16[1] << 8), |
| 1793 | p_cur->dev_class); |
| 1794 | } else { |
Jakub Pawlowski | 103b2c4 | 2017-04-28 14:59:46 -0700 | [diff] [blame] | 1795 | p_uuid16 = AdvertiseDataParser::GetFieldByType( |
| 1796 | data, BTM_BLE_AD_TYPE_16SRV_CMPL, &len); |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1797 | if (p_uuid16 != NULL) { |
| 1798 | uint8_t i; |
| 1799 | for (i = 0; i + 2 <= len; i = i + 2) { |
| 1800 | /* if this BLE device support HID over LE, set HID Major in class of |
| 1801 | * device */ |
| 1802 | if ((p_uuid16[i] | (p_uuid16[i + 1] << 8)) == UUID_SERVCLASS_LE_HID) { |
| 1803 | p_cur->dev_class[0] = 0; |
| 1804 | p_cur->dev_class[1] = BTM_COD_MAJOR_PERIPHERAL; |
| 1805 | p_cur->dev_class[2] = 0; |
| 1806 | break; |
| 1807 | } |
Adam Hampson | e6c7450 | 2014-05-30 15:07:08 -0700 | [diff] [blame] | 1808 | } |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1809 | } |
Zhihai Xu | 1237ee3 | 2013-11-26 18:18:29 -0800 | [diff] [blame] | 1810 | } |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1811 | } |
Zhihai Xu | 1237ee3 | 2013-11-26 18:18:29 -0800 | [diff] [blame] | 1812 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1813 | /* if BR/EDR not supported is not set, assume is a DUMO device */ |
| 1814 | if ((p_cur->flag & BTM_BLE_BREDR_NOT_SPT) == 0 && |
Jakub Pawlowski | d64bf4f | 2017-01-27 05:53:07 -0800 | [diff] [blame] | 1815 | !ble_evt_type_is_directed(evt_type)) { |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1816 | if (p_cur->ble_addr_type != BLE_ADDR_RANDOM) { |
| 1817 | BTM_TRACE_DEBUG("BR/EDR NOT support bit not set, treat as DUMO"); |
| 1818 | p_cur->device_type |= BT_DEVICE_TYPE_DUMO; |
| 1819 | } else { |
| 1820 | BTM_TRACE_DEBUG("Random address, treating device as LE only"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1821 | } |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1822 | } else { |
| 1823 | BTM_TRACE_DEBUG("BR/EDR NOT SUPPORT bit set, LE only device"); |
| 1824 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1825 | } |
| 1826 | |
| 1827 | /******************************************************************************* |
Myles Watson | ee96a3c | 2016-11-23 14:49:54 -0800 | [diff] [blame] | 1828 | * |
| 1829 | * Function btm_clear_all_pending_le_entry |
| 1830 | * |
| 1831 | * Description This function is called to clear all LE pending entry in |
| 1832 | * inquiry database. |
| 1833 | * |
| 1834 | * Returns void |
| 1835 | * |
| 1836 | ******************************************************************************/ |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1837 | void btm_clear_all_pending_le_entry(void) { |
| 1838 | uint16_t xx; |
| 1839 | tINQ_DB_ENT* p_ent = btm_cb.btm_inq_vars.inq_db; |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 1840 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1841 | for (xx = 0; xx < BTM_INQ_DB_SIZE; xx++, p_ent++) { |
| 1842 | /* mark all pending LE entry as unused if an LE only device has scan |
| 1843 | * response outstanding */ |
| 1844 | if ((p_ent->in_use) && |
| 1845 | (p_ent->inq_info.results.device_type == BT_DEVICE_TYPE_BLE) && |
| 1846 | !p_ent->scan_rsp) |
| 1847 | p_ent->in_use = false; |
| 1848 | } |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 1849 | } |
| 1850 | |
Jakub Pawlowski | a484a88 | 2017-06-24 17:30:18 -0700 | [diff] [blame] | 1851 | void btm_ble_process_adv_addr(RawAddress& bda, uint8_t addr_type) { |
Jakub Pawlowski | 801db30 | 2016-12-12 16:22:56 -0800 | [diff] [blame] | 1852 | #if (BLE_PRIVACY_SPT == TRUE) |
| 1853 | /* map address to security record */ |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 1854 | bool match = btm_identity_addr_to_random_pseudo(&bda, &addr_type, false); |
Jakub Pawlowski | 801db30 | 2016-12-12 16:22:56 -0800 | [diff] [blame] | 1855 | |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 1856 | VLOG(1) << __func__ << ": bda=" << bda; |
Jakub Pawlowski | 801db30 | 2016-12-12 16:22:56 -0800 | [diff] [blame] | 1857 | /* always do RRA resolution on host */ |
| 1858 | if (!match && BTM_BLE_IS_RESOLVE_BDA(bda)) { |
| 1859 | tBTM_SEC_DEV_REC* match_rec = btm_ble_resolve_random_addr(bda); |
| 1860 | if (match_rec) { |
| 1861 | match_rec->ble.active_addr_type = BTM_BLE_ADDR_RRA; |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 1862 | match_rec->ble.cur_rand_addr = bda; |
Jakub Pawlowski | 801db30 | 2016-12-12 16:22:56 -0800 | [diff] [blame] | 1863 | |
| 1864 | if (btm_ble_init_pseudo_addr(match_rec, bda)) { |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 1865 | bda = match_rec->bd_addr; |
Jakub Pawlowski | 801db30 | 2016-12-12 16:22:56 -0800 | [diff] [blame] | 1866 | } else { |
| 1867 | // Assign the original address to be the current report address |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 1868 | bda = match_rec->ble.pseudo_addr; |
Jakub Pawlowski | 801db30 | 2016-12-12 16:22:56 -0800 | [diff] [blame] | 1869 | } |
| 1870 | } |
| 1871 | } |
| 1872 | #endif |
| 1873 | } |
| 1874 | |
| 1875 | /** |
| 1876 | * This function is called when extended advertising report event is received . |
| 1877 | * It updates the inquiry database. If the inquiry database is full, the oldest |
| 1878 | * entry is discarded. |
| 1879 | */ |
| 1880 | void btm_ble_process_ext_adv_pkt(uint8_t data_len, uint8_t* data) { |
Jakub Pawlowski | a484a88 | 2017-06-24 17:30:18 -0700 | [diff] [blame] | 1881 | RawAddress bda, direct_address; |
Jakub Pawlowski | 801db30 | 2016-12-12 16:22:56 -0800 | [diff] [blame] | 1882 | uint8_t* p = data; |
| 1883 | uint8_t addr_type, num_reports, pkt_data_len, primary_phy, secondary_phy, |
| 1884 | advertising_sid; |
| 1885 | int8_t rssi, tx_power; |
| 1886 | uint16_t event_type, periodic_adv_int, direct_address_type; |
| 1887 | |
| 1888 | /* Only process the results if the inquiry is still active */ |
| 1889 | if (!BTM_BLE_IS_SCAN_ACTIVE(btm_cb.ble_ctr_cb.scan_activity)) return; |
| 1890 | |
| 1891 | /* Extract the number of reports in this event. */ |
| 1892 | STREAM_TO_UINT8(num_reports, p); |
| 1893 | |
| 1894 | while (num_reports--) { |
| 1895 | if (p > data + data_len) { |
| 1896 | // TODO(jpawlowski): we should crash the stack here |
| 1897 | BTM_TRACE_ERROR( |
| 1898 | "Malformed LE Extended Advertising Report Event from controller - " |
| 1899 | "can't loop the data"); |
| 1900 | return; |
| 1901 | } |
| 1902 | |
| 1903 | /* Extract inquiry results */ |
| 1904 | STREAM_TO_UINT16(event_type, p); |
| 1905 | STREAM_TO_UINT8(addr_type, p); |
Jakub Pawlowski | b8a477e | 2017-06-16 15:16:15 -0700 | [diff] [blame] | 1906 | STREAM_TO_BDADDR(bda, p); |
Jakub Pawlowski | 801db30 | 2016-12-12 16:22:56 -0800 | [diff] [blame] | 1907 | STREAM_TO_UINT8(primary_phy, p); |
| 1908 | STREAM_TO_UINT8(secondary_phy, p); |
| 1909 | STREAM_TO_UINT8(advertising_sid, p); |
| 1910 | STREAM_TO_INT8(tx_power, p); |
| 1911 | STREAM_TO_INT8(rssi, p); |
| 1912 | STREAM_TO_UINT16(periodic_adv_int, p); |
| 1913 | STREAM_TO_UINT8(direct_address_type, p); |
Jakub Pawlowski | b8a477e | 2017-06-16 15:16:15 -0700 | [diff] [blame] | 1914 | STREAM_TO_BDADDR(direct_address, p); |
Jakub Pawlowski | 801db30 | 2016-12-12 16:22:56 -0800 | [diff] [blame] | 1915 | STREAM_TO_UINT8(pkt_data_len, p); |
| 1916 | |
| 1917 | uint8_t* pkt_data = p; |
| 1918 | p += pkt_data_len; /* Advance to the the next packet*/ |
| 1919 | |
| 1920 | if (rssi >= 21 && rssi <= 126) { |
| 1921 | BTM_TRACE_ERROR("%s: bad rssi value in advertising report: ", __func__, |
| 1922 | pkt_data_len, rssi); |
| 1923 | } |
| 1924 | |
Jakub Pawlowski | 801db30 | 2016-12-12 16:22:56 -0800 | [diff] [blame] | 1925 | btm_ble_process_adv_addr(bda, addr_type); |
Jakub Pawlowski | 7de0f9b | 2017-01-27 08:06:20 -0800 | [diff] [blame] | 1926 | btm_ble_process_adv_pkt_cont(event_type, addr_type, bda, primary_phy, |
| 1927 | secondary_phy, advertising_sid, tx_power, rssi, |
| 1928 | periodic_adv_int, pkt_data_len, pkt_data); |
Jakub Pawlowski | 801db30 | 2016-12-12 16:22:56 -0800 | [diff] [blame] | 1929 | } |
| 1930 | } |
| 1931 | |
| 1932 | /** |
| 1933 | * This function is called when advertising report event is received. It updates |
| 1934 | * the inquiry database. If the inquiry database is full, the oldest entry is |
| 1935 | * discarded. |
| 1936 | */ |
Jakub Pawlowski | 9e30056 | 2016-12-07 10:54:44 -0800 | [diff] [blame] | 1937 | void btm_ble_process_adv_pkt(uint8_t data_len, uint8_t* data) { |
Jakub Pawlowski | a484a88 | 2017-06-24 17:30:18 -0700 | [diff] [blame] | 1938 | RawAddress bda; |
Jakub Pawlowski | 9e30056 | 2016-12-07 10:54:44 -0800 | [diff] [blame] | 1939 | uint8_t* p = data; |
Jakub Pawlowski | d64bf4f | 2017-01-27 05:53:07 -0800 | [diff] [blame] | 1940 | uint8_t legacy_evt_type, addr_type, num_reports, pkt_data_len; |
Jakub Pawlowski | 9e30056 | 2016-12-07 10:54:44 -0800 | [diff] [blame] | 1941 | int8_t rssi; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1942 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1943 | /* Only process the results if the inquiry is still active */ |
| 1944 | if (!BTM_BLE_IS_SCAN_ACTIVE(btm_cb.ble_ctr_cb.scan_activity)) return; |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 1945 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1946 | /* Extract the number of reports in this event. */ |
| 1947 | STREAM_TO_UINT8(num_reports, p); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1948 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1949 | while (num_reports--) { |
Jakub Pawlowski | 9e30056 | 2016-12-07 10:54:44 -0800 | [diff] [blame] | 1950 | if (p > data + data_len) { |
| 1951 | // TODO(jpawlowski): we should crash the stack here |
| 1952 | BTM_TRACE_ERROR("Malformed LE Advertising Report Event from controller"); |
| 1953 | return; |
| 1954 | } |
| 1955 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1956 | /* Extract inquiry results */ |
Jakub Pawlowski | d64bf4f | 2017-01-27 05:53:07 -0800 | [diff] [blame] | 1957 | STREAM_TO_UINT8(legacy_evt_type, p); |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1958 | STREAM_TO_UINT8(addr_type, p); |
Jakub Pawlowski | b8a477e | 2017-06-16 15:16:15 -0700 | [diff] [blame] | 1959 | STREAM_TO_BDADDR(bda, p); |
Jakub Pawlowski | 9e30056 | 2016-12-07 10:54:44 -0800 | [diff] [blame] | 1960 | STREAM_TO_UINT8(pkt_data_len, p); |
| 1961 | |
| 1962 | uint8_t* pkt_data = p; |
| 1963 | p += pkt_data_len; /* Advance to the the rssi byte */ |
| 1964 | |
| 1965 | STREAM_TO_INT8(rssi, p); |
| 1966 | |
| 1967 | if (rssi >= 21 && rssi <= 126) { |
| 1968 | BTM_TRACE_ERROR("%s: bad rssi value in advertising report: ", __func__, |
| 1969 | pkt_data_len, rssi); |
| 1970 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1971 | |
Jakub Pawlowski | 801db30 | 2016-12-12 16:22:56 -0800 | [diff] [blame] | 1972 | btm_ble_process_adv_addr(bda, addr_type); |
Jakub Pawlowski | 9462c5d | 2016-12-06 15:40:58 -0800 | [diff] [blame] | 1973 | |
Jakub Pawlowski | d64bf4f | 2017-01-27 05:53:07 -0800 | [diff] [blame] | 1974 | uint16_t event_type; |
| 1975 | if (legacy_evt_type == 0x00) { // ADV_IND; |
| 1976 | event_type = 0x0013; |
| 1977 | } else if (legacy_evt_type == 0x01) { // ADV_DIRECT_IND; |
| 1978 | event_type = 0x0015; |
| 1979 | } else if (legacy_evt_type == 0x02) { // ADV_SCAN_IND; |
| 1980 | event_type = 0x0012; |
| 1981 | } else if (legacy_evt_type == 0x03) { // ADV_NONCONN_IND; |
| 1982 | event_type = 0x0010; |
| 1983 | } else if (legacy_evt_type == 0x04) { // SCAN_RSP; |
| 1984 | // We can't distinguish between "SCAN_RSP to an ADV_IND", and "SCAN_RSP to |
| 1985 | // an ADV_SCAN_IND", so always return "SCAN_RSP to an ADV_IND" |
| 1986 | event_type = 0x001B; |
| 1987 | } else { |
| 1988 | BTM_TRACE_ERROR( |
| 1989 | "Malformed LE Advertising Report Event - unsupported " |
| 1990 | "legacy_event_type 0x%02x", |
| 1991 | legacy_evt_type); |
| 1992 | return; |
| 1993 | } |
| 1994 | |
Jakub Pawlowski | 7de0f9b | 2017-01-27 08:06:20 -0800 | [diff] [blame] | 1995 | btm_ble_process_adv_pkt_cont( |
| 1996 | event_type, addr_type, bda, PHY_LE_1M, PHY_LE_NO_PACKET, NO_ADI_PRESENT, |
| 1997 | TX_POWER_NOT_PRESENT, rssi, 0x00 /* no periodic adv */, pkt_data_len, |
| 1998 | pkt_data); |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 1999 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2000 | } |
| 2001 | |
Jakub Pawlowski | d64bf4f | 2017-01-27 05:53:07 -0800 | [diff] [blame] | 2002 | /** |
| 2003 | * This function is called after random address resolution is done, and proceed |
| 2004 | * to process adv packet. |
| 2005 | */ |
Jakub Pawlowski | 7de0f9b | 2017-01-27 08:06:20 -0800 | [diff] [blame] | 2006 | static void btm_ble_process_adv_pkt_cont( |
Jakub Pawlowski | a484a88 | 2017-06-24 17:30:18 -0700 | [diff] [blame] | 2007 | uint16_t evt_type, uint8_t addr_type, const RawAddress& bda, |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 2008 | uint8_t primary_phy, uint8_t secondary_phy, uint8_t advertising_sid, |
| 2009 | int8_t tx_power, int8_t rssi, uint16_t periodic_adv_int, uint8_t data_len, |
| 2010 | uint8_t* data) { |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 2011 | tBTM_INQUIRY_VAR_ST* p_inq = &btm_cb.btm_inq_vars; |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 2012 | bool update = true; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2013 | |
Jakub Pawlowski | 0595ca0 | 2017-02-07 12:15:06 -0800 | [diff] [blame] | 2014 | std::vector<uint8_t> tmp; |
| 2015 | if (data_len != 0) tmp.insert(tmp.begin(), data, data + data_len); |
| 2016 | |
| 2017 | bool is_scannable = ble_evt_type_is_scannable(evt_type); |
| 2018 | bool is_scan_resp = ble_evt_type_is_scan_resp(evt_type); |
| 2019 | |
| 2020 | // We might have send scan request to this device before, but didn't get the |
| 2021 | // response. In such case make sure data is put at start, not appended to |
| 2022 | // already existing data. |
| 2023 | bool is_start = |
| 2024 | ble_evt_type_is_legacy(evt_type) && is_scannable && !is_scan_resp; |
| 2025 | std::vector<uint8_t> const& adv_data = |
| 2026 | is_start ? cache.Set(addr_type, bda, std::move(tmp)) |
| 2027 | : cache.Append(addr_type, bda, std::move(tmp)); |
| 2028 | |
| 2029 | bool data_complete = (ble_evt_type_data_status(evt_type) != 0x01); |
| 2030 | |
| 2031 | if (!data_complete) { |
| 2032 | // If we didn't receive whole adv data yet, don't report the device. |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 2033 | DVLOG(1) << "Data not complete yet, waiting for more " << bda; |
Jakub Pawlowski | 0595ca0 | 2017-02-07 12:15:06 -0800 | [diff] [blame] | 2034 | return; |
| 2035 | } |
| 2036 | |
| 2037 | bool is_active_scan = |
| 2038 | btm_cb.ble_ctr_cb.inq_var.scan_type == BTM_BLE_SCAN_MODE_ACTI; |
| 2039 | if (is_active_scan && is_scannable && !is_scan_resp) { |
| 2040 | // If we didn't receive scan response yet, don't report the device. |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 2041 | DVLOG(1) << " Waiting for scan response " << bda; |
Jakub Pawlowski | 0595ca0 | 2017-02-07 12:15:06 -0800 | [diff] [blame] | 2042 | return; |
| 2043 | } |
| 2044 | |
Jakub Pawlowski | 103b2c4 | 2017-04-28 14:59:46 -0700 | [diff] [blame] | 2045 | if (!AdvertiseDataParser::IsValid(adv_data)) { |
| 2046 | DVLOG(1) << __func__ << "Dropping bad advertisement packet: " |
| 2047 | << base::HexEncode(adv_data.data(), adv_data.size()); |
| 2048 | return; |
| 2049 | } |
| 2050 | |
Jakub Pawlowski | 0595ca0 | 2017-02-07 12:15:06 -0800 | [diff] [blame] | 2051 | tINQ_DB_ENT* p_i = btm_inq_db_find(bda); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2052 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 2053 | /* Check if this address has already been processed for this inquiry */ |
| 2054 | if (btm_inq_find_bdaddr(bda)) { |
| 2055 | /* never been report as an LE device */ |
| 2056 | if (p_i && (!(p_i->inq_info.results.device_type & BT_DEVICE_TYPE_BLE) || |
| 2057 | /* scan repsonse to be updated */ |
| 2058 | (!p_i->scan_rsp))) { |
| 2059 | update = true; |
| 2060 | } else if (BTM_BLE_IS_OBS_ACTIVE(btm_cb.ble_ctr_cb.scan_activity)) { |
| 2061 | update = false; |
| 2062 | } else { |
| 2063 | /* if yes, skip it */ |
| 2064 | return; /* assumption: one result per event */ |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2065 | } |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 2066 | } |
| 2067 | /* If existing entry, use that, else get a new one (possibly reusing the |
| 2068 | * oldest) */ |
| 2069 | if (p_i == NULL) { |
| 2070 | p_i = btm_inq_db_new(bda); |
| 2071 | if (p_i != NULL) { |
| 2072 | p_inq->inq_cmpl_info.num_resp++; |
| 2073 | } else |
| 2074 | return; |
| 2075 | } else if (p_i->inq_count != |
| 2076 | p_inq->inq_counter) /* first time seen in this inquiry */ |
| 2077 | { |
| 2078 | p_inq->inq_cmpl_info.num_resp++; |
| 2079 | } |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2080 | |
Jakub Pawlowski | 0595ca0 | 2017-02-07 12:15:06 -0800 | [diff] [blame] | 2081 | /* update the LE device information in inquiry database */ |
| 2082 | btm_ble_update_inq_result(p_i, addr_type, bda, evt_type, primary_phy, |
| 2083 | secondary_phy, advertising_sid, tx_power, rssi, |
| 2084 | periodic_adv_int, adv_data); |
| 2085 | |
| 2086 | uint8_t result = btm_ble_is_discoverable(bda, adv_data); |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 2087 | if (result == 0) { |
Jakub Pawlowski | 0595ca0 | 2017-02-07 12:15:06 -0800 | [diff] [blame] | 2088 | cache.Clear(addr_type, bda); |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 2089 | LOG_WARN(LOG_TAG, |
Jakub Pawlowski | 9e30056 | 2016-12-07 10:54:44 -0800 | [diff] [blame] | 2090 | "%s device no longer discoverable, discarding advertising packet", |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 2091 | __func__); |
| 2092 | return; |
| 2093 | } |
Jakub Pawlowski | 0595ca0 | 2017-02-07 12:15:06 -0800 | [diff] [blame] | 2094 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 2095 | if (!update) result &= ~BTM_BLE_INQ_RESULT; |
| 2096 | /* If the number of responses found and limited, issue a cancel inquiry */ |
| 2097 | if (p_inq->inqparms.max_resps && |
| 2098 | p_inq->inq_cmpl_info.num_resp == p_inq->inqparms.max_resps) { |
| 2099 | /* new device */ |
| 2100 | if (p_i == NULL || |
| 2101 | /* assume a DUMO device, BR/EDR inquiry is always active */ |
| 2102 | (p_i && |
| 2103 | (p_i->inq_info.results.device_type & BT_DEVICE_TYPE_BLE) == |
| 2104 | BT_DEVICE_TYPE_BLE && |
| 2105 | p_i->scan_rsp)) { |
| 2106 | BTM_TRACE_WARNING( |
| 2107 | "INQ RES: Extra Response Received...cancelling inquiry.."); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2108 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 2109 | /* if is non-periodic inquiry active, cancel now */ |
| 2110 | if ((p_inq->inq_active & BTM_BR_INQ_ACTIVE_MASK) != 0 && |
| 2111 | (p_inq->inq_active & BTM_PERIODIC_INQUIRY_ACTIVE) == 0) |
| 2112 | btsnd_hcic_inq_cancel(); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2113 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 2114 | btm_ble_stop_inquiry(); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2115 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 2116 | btm_acl_update_busy_level(BTM_BLI_INQ_DONE_EVT); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2117 | } |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 2118 | } |
Jakub Pawlowski | 83211b0 | 2016-12-07 11:25:15 -0800 | [diff] [blame] | 2119 | |
Jakub Pawlowski | 7de0f9b | 2017-01-27 08:06:20 -0800 | [diff] [blame] | 2120 | tBTM_INQ_RESULTS_CB* p_inq_results_cb = p_inq->p_inq_results_cb; |
Jakub Pawlowski | 83211b0 | 2016-12-07 11:25:15 -0800 | [diff] [blame] | 2121 | if (p_inq_results_cb && (result & BTM_BLE_INQ_RESULT)) { |
| 2122 | (p_inq_results_cb)((tBTM_INQ_RESULTS*)&p_i->inq_info.results, |
Jakub Pawlowski | 0595ca0 | 2017-02-07 12:15:06 -0800 | [diff] [blame] | 2123 | const_cast<uint8_t*>(adv_data.data()), adv_data.size()); |
Jakub Pawlowski | 83211b0 | 2016-12-07 11:25:15 -0800 | [diff] [blame] | 2124 | } |
Jakub Pawlowski | d64bf4f | 2017-01-27 05:53:07 -0800 | [diff] [blame] | 2125 | |
| 2126 | tBTM_INQ_RESULTS_CB* p_obs_results_cb = btm_cb.ble_ctr_cb.p_obs_results_cb; |
Jakub Pawlowski | 83211b0 | 2016-12-07 11:25:15 -0800 | [diff] [blame] | 2127 | if (p_obs_results_cb && (result & BTM_BLE_OBS_RESULT)) { |
| 2128 | (p_obs_results_cb)((tBTM_INQ_RESULTS*)&p_i->inq_info.results, |
Jakub Pawlowski | 0595ca0 | 2017-02-07 12:15:06 -0800 | [diff] [blame] | 2129 | const_cast<uint8_t*>(adv_data.data()), adv_data.size()); |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 2130 | } |
Jakub Pawlowski | 0595ca0 | 2017-02-07 12:15:06 -0800 | [diff] [blame] | 2131 | |
| 2132 | cache.Clear(addr_type, bda); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2133 | } |
| 2134 | |
Jakub Pawlowski | eafd45d | 2017-03-22 19:00:47 -0700 | [diff] [blame] | 2135 | void btm_ble_process_phy_update_pkt(uint8_t len, uint8_t* data) { |
| 2136 | uint8_t status, tx_phy, rx_phy; |
| 2137 | uint16_t handle; |
| 2138 | |
| 2139 | LOG_ASSERT(len == 5); |
| 2140 | uint8_t* p = data; |
| 2141 | STREAM_TO_UINT8(status, p); |
| 2142 | STREAM_TO_UINT16(handle, p); |
| 2143 | handle = handle & 0x0FFF; |
| 2144 | STREAM_TO_UINT8(tx_phy, p); |
| 2145 | STREAM_TO_UINT8(rx_phy, p); |
| 2146 | |
| 2147 | tBTM_SEC_DEV_REC* p_dev_rec = btm_find_dev_by_handle(handle); |
| 2148 | if (!p_dev_rec) { |
| 2149 | BTM_TRACE_WARNING("%s: No Device Found!", __func__); |
| 2150 | return; |
| 2151 | } |
| 2152 | |
| 2153 | tGATT_TCB* p_tcb = |
| 2154 | gatt_find_tcb_by_addr(p_dev_rec->ble.pseudo_addr, BT_TRANSPORT_LE); |
| 2155 | if (p_tcb == NULL) return; |
| 2156 | |
| 2157 | gatt_notify_phy_updated(p_tcb, tx_phy, rx_phy, status); |
| 2158 | } |
| 2159 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2160 | /******************************************************************************* |
Myles Watson | ee96a3c | 2016-11-23 14:49:54 -0800 | [diff] [blame] | 2161 | * |
| 2162 | * Function btm_ble_start_scan |
| 2163 | * |
| 2164 | * Description Start the BLE scan. |
| 2165 | * |
| 2166 | * Returns void |
| 2167 | * |
| 2168 | ******************************************************************************/ |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 2169 | tBTM_STATUS btm_ble_start_scan(void) { |
| 2170 | tBTM_BLE_INQ_CB* p_inq = &btm_cb.ble_ctr_cb.inq_var; |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 2171 | /* start scan, disable duplicate filtering */ |
Jakub Pawlowski | 9df2a55 | 2016-12-02 11:34:06 -0800 | [diff] [blame] | 2172 | btm_send_hci_scan_enable(BTM_BLE_SCAN_ENABLE, p_inq->scan_duplicate_filter); |
Jakub Pawlowski | b6ab9b3 | 2016-10-10 09:35:13 -0700 | [diff] [blame] | 2173 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 2174 | if (p_inq->scan_type == BTM_BLE_SCAN_MODE_ACTI) |
| 2175 | btm_ble_set_topology_mask(BTM_BLE_STATE_ACTIVE_SCAN_BIT); |
| 2176 | else |
| 2177 | btm_ble_set_topology_mask(BTM_BLE_STATE_PASSIVE_SCAN_BIT); |
Jakub Pawlowski | b6ab9b3 | 2016-10-10 09:35:13 -0700 | [diff] [blame] | 2178 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 2179 | return BTM_CMD_STARTED; |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2180 | } |
| 2181 | |
| 2182 | /******************************************************************************* |
Myles Watson | ee96a3c | 2016-11-23 14:49:54 -0800 | [diff] [blame] | 2183 | * |
| 2184 | * Function btm_ble_stop_scan |
| 2185 | * |
| 2186 | * Description Stop the BLE scan. |
| 2187 | * |
| 2188 | * Returns void |
| 2189 | * |
| 2190 | ******************************************************************************/ |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 2191 | void btm_ble_stop_scan(void) { |
| 2192 | BTM_TRACE_EVENT("btm_ble_stop_scan "); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2193 | |
Jakub Pawlowski | 4d05ea5 | 2017-02-23 13:55:02 -0800 | [diff] [blame] | 2194 | if (btm_cb.ble_ctr_cb.inq_var.scan_type == BTM_BLE_SCAN_MODE_ACTI) |
| 2195 | btm_ble_clear_topology_mask(BTM_BLE_STATE_ACTIVE_SCAN_BIT); |
| 2196 | else |
| 2197 | btm_ble_clear_topology_mask(BTM_BLE_STATE_PASSIVE_SCAN_BIT); |
| 2198 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 2199 | /* Clear the inquiry callback if set */ |
| 2200 | btm_cb.ble_ctr_cb.inq_var.scan_type = BTM_BLE_SCAN_MODE_NONE; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2201 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 2202 | /* stop discovery now */ |
Jakub Pawlowski | 9df2a55 | 2016-12-02 11:34:06 -0800 | [diff] [blame] | 2203 | btm_send_hci_scan_enable(BTM_BLE_SCAN_DISABLE, BTM_BLE_DUPLICATE_ENABLE); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2204 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 2205 | btm_update_scanner_filter_policy(SP_ADV_ALL); |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2206 | } |
| 2207 | /******************************************************************************* |
Myles Watson | ee96a3c | 2016-11-23 14:49:54 -0800 | [diff] [blame] | 2208 | * |
| 2209 | * Function btm_ble_stop_inquiry |
| 2210 | * |
| 2211 | * Description Stop the BLE Inquiry. |
| 2212 | * |
| 2213 | * Returns void |
| 2214 | * |
| 2215 | ******************************************************************************/ |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 2216 | void btm_ble_stop_inquiry(void) { |
| 2217 | tBTM_INQUIRY_VAR_ST* p_inq = &btm_cb.btm_inq_vars; |
| 2218 | tBTM_BLE_CB* p_ble_cb = &btm_cb.ble_ctr_cb; |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2219 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 2220 | alarm_cancel(p_ble_cb->inq_var.inquiry_timer); |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2221 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 2222 | p_ble_cb->scan_activity &= ~BTM_BLE_INQUIRY_MASK; |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2223 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 2224 | /* If no more scan activity, stop LE scan now */ |
| 2225 | if (!BTM_BLE_IS_SCAN_ACTIVE(p_ble_cb->scan_activity)) |
| 2226 | btm_ble_stop_scan(); |
| 2227 | else if ((p_ble_cb->inq_var.scan_interval != BTM_BLE_LOW_LATENCY_SCAN_INT) || |
| 2228 | (p_ble_cb->inq_var.scan_window != BTM_BLE_LOW_LATENCY_SCAN_WIN)) { |
| 2229 | BTM_TRACE_DEBUG("%s: setting default params for ongoing observe", __func__); |
| 2230 | btm_ble_stop_scan(); |
| 2231 | btm_ble_start_scan(); |
| 2232 | } |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2233 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 2234 | /* If we have a callback registered for inquiry complete, call it */ |
| 2235 | BTM_TRACE_DEBUG("BTM Inq Compl Callback: status 0x%02x, num results %d", |
| 2236 | p_inq->inq_cmpl_info.status, p_inq->inq_cmpl_info.num_resp); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2237 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 2238 | btm_process_inq_complete( |
| 2239 | HCI_SUCCESS, (uint8_t)(p_inq->inqparms.mode & BTM_BLE_INQUIRY_MASK)); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2240 | } |
| 2241 | |
| 2242 | /******************************************************************************* |
Myles Watson | ee96a3c | 2016-11-23 14:49:54 -0800 | [diff] [blame] | 2243 | * |
| 2244 | * Function btm_ble_stop_observe |
| 2245 | * |
| 2246 | * Description Stop the BLE Observe. |
| 2247 | * |
| 2248 | * Returns void |
| 2249 | * |
| 2250 | ******************************************************************************/ |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 2251 | static void btm_ble_stop_observe(void) { |
| 2252 | tBTM_BLE_CB* p_ble_cb = &btm_cb.ble_ctr_cb; |
| 2253 | tBTM_CMPL_CB* p_obs_cb = p_ble_cb->p_obs_cmpl_cb; |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2254 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 2255 | alarm_cancel(p_ble_cb->observer_timer); |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2256 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 2257 | p_ble_cb->scan_activity &= ~BTM_LE_OBSERVE_ACTIVE; |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2258 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 2259 | p_ble_cb->p_obs_results_cb = NULL; |
| 2260 | p_ble_cb->p_obs_cmpl_cb = NULL; |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2261 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 2262 | if (!BTM_BLE_IS_SCAN_ACTIVE(p_ble_cb->scan_activity)) btm_ble_stop_scan(); |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2263 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 2264 | if (p_obs_cb) |
| 2265 | (p_obs_cb)((tBTM_INQUIRY_CMPL*)&btm_cb.btm_inq_vars.inq_cmpl_info); |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2266 | } |
| 2267 | /******************************************************************************* |
Myles Watson | ee96a3c | 2016-11-23 14:49:54 -0800 | [diff] [blame] | 2268 | * |
| 2269 | * Function btm_ble_adv_states_operation |
| 2270 | * |
| 2271 | * Description Set or clear adv states in topology mask |
| 2272 | * |
| 2273 | * Returns operation status. true if sucessful, false otherwise. |
| 2274 | * |
| 2275 | ******************************************************************************/ |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 2276 | typedef bool(BTM_TOPOLOGY_FUNC_PTR)(tBTM_BLE_STATE_MASK); |
| 2277 | static bool btm_ble_adv_states_operation(BTM_TOPOLOGY_FUNC_PTR* p_handler, |
| 2278 | uint8_t adv_evt) { |
| 2279 | bool rt = false; |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2280 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 2281 | switch (adv_evt) { |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2282 | case BTM_BLE_CONNECT_EVT: |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 2283 | rt = (*p_handler)(BTM_BLE_STATE_CONN_ADV_BIT); |
| 2284 | break; |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2285 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 2286 | case BTM_BLE_NON_CONNECT_EVT: |
| 2287 | rt = (*p_handler)(BTM_BLE_STATE_NON_CONN_ADV_BIT); |
| 2288 | break; |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2289 | case BTM_BLE_CONNECT_DIR_EVT: |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 2290 | rt = (*p_handler)(BTM_BLE_STATE_HI_DUTY_DIR_ADV_BIT); |
| 2291 | break; |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2292 | |
| 2293 | case BTM_BLE_DISCOVER_EVT: |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 2294 | rt = (*p_handler)(BTM_BLE_STATE_SCAN_ADV_BIT); |
| 2295 | break; |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2296 | |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 2297 | case BTM_BLE_CONNECT_LO_DUTY_DIR_EVT: |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 2298 | rt = (*p_handler)(BTM_BLE_STATE_LO_DUTY_DIR_ADV_BIT); |
| 2299 | break; |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 2300 | |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2301 | default: |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 2302 | BTM_TRACE_ERROR("unknown adv event : %d", adv_evt); |
| 2303 | break; |
| 2304 | } |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2305 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 2306 | return rt; |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2307 | } |
| 2308 | |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2309 | /******************************************************************************* |
Myles Watson | ee96a3c | 2016-11-23 14:49:54 -0800 | [diff] [blame] | 2310 | * |
| 2311 | * Function btm_ble_start_adv |
| 2312 | * |
| 2313 | * Description start the BLE advertising. |
| 2314 | * |
| 2315 | * Returns void |
| 2316 | * |
| 2317 | ******************************************************************************/ |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 2318 | tBTM_STATUS btm_ble_start_adv(void) { |
| 2319 | tBTM_BLE_INQ_CB* p_cb = &btm_cb.ble_ctr_cb.inq_var; |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 2320 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 2321 | if (!btm_ble_adv_states_operation(btm_ble_topology_check, p_cb->evt_type)) |
| 2322 | return BTM_WRONG_MODE; |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2323 | |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 2324 | #if (BLE_PRIVACY_SPT == TRUE) |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 2325 | /* To relax resolving list, always have resolving list enabled, unless |
| 2326 | * directed adv */ |
| 2327 | if (p_cb->evt_type != BTM_BLE_CONNECT_LO_DUTY_DIR_EVT && |
| 2328 | p_cb->evt_type != BTM_BLE_CONNECT_DIR_EVT) |
| 2329 | /* enable resolving list is desired */ |
| 2330 | btm_ble_enable_resolving_list_for_platform(BTM_BLE_RL_ADV); |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 2331 | #endif |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2332 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 2333 | btsnd_hcic_ble_set_adv_enable(BTM_BLE_ADV_ENABLE); |
| 2334 | p_cb->adv_mode = BTM_BLE_ADV_ENABLE; |
| 2335 | btm_ble_adv_states_operation(btm_ble_set_topology_mask, p_cb->evt_type); |
| 2336 | return BTM_SUCCESS; |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 2337 | } |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 2338 | |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 2339 | /******************************************************************************* |
Myles Watson | ee96a3c | 2016-11-23 14:49:54 -0800 | [diff] [blame] | 2340 | * |
| 2341 | * Function btm_ble_stop_adv |
| 2342 | * |
| 2343 | * Description Stop the BLE advertising. |
| 2344 | * |
| 2345 | * Returns void |
| 2346 | * |
| 2347 | ******************************************************************************/ |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 2348 | tBTM_STATUS btm_ble_stop_adv(void) { |
| 2349 | tBTM_BLE_INQ_CB* p_cb = &btm_cb.ble_ctr_cb.inq_var; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2350 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 2351 | if (p_cb->adv_mode == BTM_BLE_ADV_ENABLE) { |
| 2352 | btsnd_hcic_ble_set_adv_enable(BTM_BLE_ADV_DISABLE); |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2353 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 2354 | p_cb->fast_adv_on = false; |
| 2355 | p_cb->adv_mode = BTM_BLE_ADV_DISABLE; |
Jakub Pawlowski | b6ab9b3 | 2016-10-10 09:35:13 -0700 | [diff] [blame] | 2356 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 2357 | /* clear all adv states */ |
| 2358 | btm_ble_clear_topology_mask(BTM_BLE_STATE_ALL_ADV_MASK); |
| 2359 | } |
| 2360 | return BTM_SUCCESS; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2361 | } |
| 2362 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 2363 | static void btm_ble_fast_adv_timer_timeout(UNUSED_ATTR void* data) { |
| 2364 | /* fast adv is completed, fall back to slow adv interval */ |
| 2365 | btm_ble_start_slow_adv(); |
Pavlin Radoslavov | 78bcff7 | 2015-12-04 17:36:34 -0800 | [diff] [blame] | 2366 | } |
| 2367 | |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2368 | /******************************************************************************* |
Myles Watson | ee96a3c | 2016-11-23 14:49:54 -0800 | [diff] [blame] | 2369 | * |
| 2370 | * Function btm_ble_start_slow_adv |
| 2371 | * |
| 2372 | * Description Restart adv with slow adv interval |
| 2373 | * |
| 2374 | * Returns void |
| 2375 | * |
| 2376 | ******************************************************************************/ |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 2377 | static void btm_ble_start_slow_adv(void) { |
| 2378 | tBTM_BLE_INQ_CB* p_cb = &btm_cb.ble_ctr_cb.inq_var; |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2379 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 2380 | if (p_cb->adv_mode == BTM_BLE_ADV_ENABLE) { |
| 2381 | tBTM_LE_RANDOM_CB* p_addr_cb = &btm_cb.ble_ctr_cb.addr_mgnt_cb; |
Jakub Pawlowski | b707f44 | 2017-07-03 15:39:36 -0700 | [diff] [blame^] | 2382 | RawAddress address = RawAddress::kEmpty; |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 2383 | tBLE_ADDR_TYPE init_addr_type = BLE_ADDR_PUBLIC; |
| 2384 | tBLE_ADDR_TYPE own_addr_type = p_addr_cb->own_addr_type; |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 2385 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 2386 | btm_ble_stop_adv(); |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2387 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 2388 | p_cb->evt_type = btm_set_conn_mode_adv_init_addr( |
Jakub Pawlowski | b707f44 | 2017-07-03 15:39:36 -0700 | [diff] [blame^] | 2389 | p_cb, address, &init_addr_type, &own_addr_type); |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 2390 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 2391 | /* slow adv mode never goes into directed adv */ |
Jakub Pawlowski | b707f44 | 2017-07-03 15:39:36 -0700 | [diff] [blame^] | 2392 | btsnd_hcic_ble_write_adv_params( |
| 2393 | BTM_BLE_GAP_ADV_SLOW_INT, BTM_BLE_GAP_ADV_SLOW_INT, p_cb->evt_type, |
| 2394 | own_addr_type, init_addr_type, address, p_cb->adv_chnl_map, p_cb->afp); |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2395 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 2396 | btm_ble_start_adv(); |
| 2397 | } |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2398 | } |
Pavlin Radoslavov | 78bcff7 | 2015-12-04 17:36:34 -0800 | [diff] [blame] | 2399 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 2400 | static void btm_ble_inquiry_timer_gap_limited_discovery_timeout( |
| 2401 | UNUSED_ATTR void* data) { |
| 2402 | /* lim_timeout expired, limited discovery should exit now */ |
| 2403 | btm_cb.btm_inq_vars.discoverable_mode &= ~BTM_BLE_LIMITED_DISCOVERABLE; |
| 2404 | btm_ble_set_adv_flag(btm_cb.btm_inq_vars.connectable_mode, |
| 2405 | btm_cb.btm_inq_vars.discoverable_mode); |
Pavlin Radoslavov | 78bcff7 | 2015-12-04 17:36:34 -0800 | [diff] [blame] | 2406 | } |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2407 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 2408 | static void btm_ble_inquiry_timer_timeout(UNUSED_ATTR void* data) { |
| 2409 | btm_ble_stop_inquiry(); |
Pavlin Radoslavov | 78bcff7 | 2015-12-04 17:36:34 -0800 | [diff] [blame] | 2410 | } |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2411 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 2412 | static void btm_ble_observer_timer_timeout(UNUSED_ATTR void* data) { |
| 2413 | btm_ble_stop_observe(); |
Pavlin Radoslavov | 78bcff7 | 2015-12-04 17:36:34 -0800 | [diff] [blame] | 2414 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2415 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 2416 | void btm_ble_refresh_raddr_timer_timeout(UNUSED_ATTR void* data) { |
| 2417 | if (btm_cb.ble_ctr_cb.addr_mgnt_cb.own_addr_type == BLE_ADDR_RANDOM) { |
| 2418 | /* refresh the random addr */ |
Jakub Pawlowski | 0c68323 | 2017-02-24 09:49:59 -0800 | [diff] [blame] | 2419 | btm_gen_resolvable_private_addr(base::Bind(&btm_gen_resolve_paddr_low)); |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 2420 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2421 | } |
| 2422 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2423 | /******************************************************************************* |
Myles Watson | ee96a3c | 2016-11-23 14:49:54 -0800 | [diff] [blame] | 2424 | * |
| 2425 | * Function btm_ble_read_remote_features_complete |
| 2426 | * |
| 2427 | * Description This function is called when the command complete message |
Myles Watson | 9ca0709 | 2016-11-28 16:41:53 -0800 | [diff] [blame] | 2428 | * is received from the HCI for the read LE remote feature |
| 2429 | * supported complete event. |
Myles Watson | ee96a3c | 2016-11-23 14:49:54 -0800 | [diff] [blame] | 2430 | * |
| 2431 | * Returns void |
| 2432 | * |
| 2433 | ******************************************************************************/ |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 2434 | void btm_ble_read_remote_features_complete(uint8_t* p) { |
Nagarjuna Kristam | 86d5b56 | 2016-12-13 14:30:45 +0530 | [diff] [blame] | 2435 | BTM_TRACE_EVENT("%s", __func__); |
| 2436 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 2437 | uint16_t handle; |
| 2438 | uint8_t status; |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 2439 | STREAM_TO_UINT8(status, p); |
Nagarjuna Kristam | 86d5b56 | 2016-12-13 14:30:45 +0530 | [diff] [blame] | 2440 | STREAM_TO_UINT16(handle, p); |
| 2441 | handle = handle & 0x0FFF; // only 12 bits meaningful |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 2442 | |
Nagarjuna Kristam | 86d5b56 | 2016-12-13 14:30:45 +0530 | [diff] [blame] | 2443 | if (status != HCI_SUCCESS) { |
Jakub Pawlowski | 341b6db | 2017-04-24 06:34:11 -0700 | [diff] [blame] | 2444 | BTM_TRACE_ERROR("%s: failed for handle: 0x%04d, status 0x%02x", __func__, |
| 2445 | handle, status); |
| 2446 | if (status != HCI_ERR_UNSUPPORTED_REM_FEATURE) return; |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 2447 | } |
Nagarjuna Kristam | 86d5b56 | 2016-12-13 14:30:45 +0530 | [diff] [blame] | 2448 | |
| 2449 | int idx = btm_handle_to_acl_index(handle); |
| 2450 | if (idx == MAX_L2CAP_LINKS) { |
| 2451 | BTM_TRACE_ERROR("%s: can't find acl for handle: 0x%04d", __func__, handle); |
| 2452 | return; |
| 2453 | } |
| 2454 | |
Jakub Pawlowski | 341b6db | 2017-04-24 06:34:11 -0700 | [diff] [blame] | 2455 | if (status == HCI_SUCCESS) { |
| 2456 | STREAM_TO_ARRAY(btm_cb.acl_db[idx].peer_le_features, p, BD_FEATURES_LEN); |
| 2457 | } |
Nagarjuna Kristam | 86d5b56 | 2016-12-13 14:30:45 +0530 | [diff] [blame] | 2458 | |
| 2459 | btsnd_hcic_rmt_ver_req(handle); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2460 | } |
| 2461 | |
| 2462 | /******************************************************************************* |
Myles Watson | ee96a3c | 2016-11-23 14:49:54 -0800 | [diff] [blame] | 2463 | * |
| 2464 | * Function btm_ble_write_adv_enable_complete |
| 2465 | * |
| 2466 | * Description This function process the write adv enable command complete. |
| 2467 | * |
| 2468 | * Returns void |
| 2469 | * |
| 2470 | ******************************************************************************/ |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 2471 | void btm_ble_write_adv_enable_complete(uint8_t* p) { |
| 2472 | tBTM_BLE_INQ_CB* p_cb = &btm_cb.ble_ctr_cb.inq_var; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2473 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 2474 | /* if write adv enable/disbale not succeed */ |
| 2475 | if (*p != HCI_SUCCESS) { |
| 2476 | /* toggle back the adv mode */ |
| 2477 | p_cb->adv_mode = !p_cb->adv_mode; |
| 2478 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2479 | } |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 2480 | |
| 2481 | /******************************************************************************* |
Myles Watson | ee96a3c | 2016-11-23 14:49:54 -0800 | [diff] [blame] | 2482 | * |
| 2483 | * Function btm_ble_dir_adv_tout |
| 2484 | * |
| 2485 | * Description when directed adv time out |
| 2486 | * |
| 2487 | * Returns void |
| 2488 | * |
| 2489 | ******************************************************************************/ |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 2490 | void btm_ble_dir_adv_tout(void) { |
| 2491 | btm_cb.ble_ctr_cb.inq_var.adv_mode = BTM_BLE_ADV_DISABLE; |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 2492 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 2493 | /* make device fall back into undirected adv mode by default */ |
| 2494 | btm_cb.ble_ctr_cb.inq_var.directed_conn = false; |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 2495 | } |
| 2496 | |
| 2497 | /******************************************************************************* |
Myles Watson | ee96a3c | 2016-11-23 14:49:54 -0800 | [diff] [blame] | 2498 | * |
| 2499 | * Function btm_ble_set_topology_mask |
| 2500 | * |
| 2501 | * Description set BLE topology mask |
| 2502 | * |
| 2503 | * Returns true is request is allowed, false otherwise. |
| 2504 | * |
| 2505 | ******************************************************************************/ |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 2506 | bool btm_ble_set_topology_mask(tBTM_BLE_STATE_MASK request_state_mask) { |
| 2507 | request_state_mask &= BTM_BLE_STATE_ALL_MASK; |
| 2508 | btm_cb.ble_ctr_cb.cur_states |= (request_state_mask & BTM_BLE_STATE_ALL_MASK); |
| 2509 | return true; |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 2510 | } |
| 2511 | |
| 2512 | /******************************************************************************* |
Myles Watson | ee96a3c | 2016-11-23 14:49:54 -0800 | [diff] [blame] | 2513 | * |
| 2514 | * Function btm_ble_clear_topology_mask |
| 2515 | * |
| 2516 | * Description Clear BLE topology bit mask |
| 2517 | * |
| 2518 | * Returns true is request is allowed, false otherwise. |
| 2519 | * |
| 2520 | ******************************************************************************/ |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 2521 | bool btm_ble_clear_topology_mask(tBTM_BLE_STATE_MASK request_state_mask) { |
| 2522 | request_state_mask &= BTM_BLE_STATE_ALL_MASK; |
| 2523 | btm_cb.ble_ctr_cb.cur_states &= ~request_state_mask; |
| 2524 | return true; |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 2525 | } |
| 2526 | |
| 2527 | /******************************************************************************* |
Myles Watson | ee96a3c | 2016-11-23 14:49:54 -0800 | [diff] [blame] | 2528 | * |
| 2529 | * Function btm_ble_update_link_topology_mask |
| 2530 | * |
| 2531 | * Description This function update the link topology mask |
| 2532 | * |
| 2533 | * Returns void |
| 2534 | * |
| 2535 | ******************************************************************************/ |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 2536 | void btm_ble_update_link_topology_mask(uint8_t link_role, bool increase) { |
| 2537 | btm_ble_clear_topology_mask(BTM_BLE_STATE_ALL_CONN_MASK); |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 2538 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 2539 | if (increase) |
| 2540 | btm_cb.ble_ctr_cb.link_count[link_role]++; |
| 2541 | else if (btm_cb.ble_ctr_cb.link_count[link_role] > 0) |
| 2542 | btm_cb.ble_ctr_cb.link_count[link_role]--; |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 2543 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 2544 | if (btm_cb.ble_ctr_cb.link_count[HCI_ROLE_MASTER]) |
| 2545 | btm_ble_set_topology_mask(BTM_BLE_STATE_MASTER_BIT); |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 2546 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 2547 | if (btm_cb.ble_ctr_cb.link_count[HCI_ROLE_SLAVE]) |
| 2548 | btm_ble_set_topology_mask(BTM_BLE_STATE_SLAVE_BIT); |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 2549 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 2550 | if (link_role == HCI_ROLE_SLAVE && increase) { |
| 2551 | btm_cb.ble_ctr_cb.inq_var.adv_mode = BTM_BLE_ADV_DISABLE; |
| 2552 | /* make device fall back into undirected adv mode by default */ |
| 2553 | btm_cb.ble_ctr_cb.inq_var.directed_conn = BTM_BLE_CONNECT_EVT; |
| 2554 | /* clear all adv states */ |
| 2555 | btm_ble_clear_topology_mask(BTM_BLE_STATE_ALL_ADV_MASK); |
| 2556 | } |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 2557 | } |
| 2558 | |
| 2559 | /******************************************************************************* |
Myles Watson | ee96a3c | 2016-11-23 14:49:54 -0800 | [diff] [blame] | 2560 | * |
| 2561 | * Function btm_ble_update_mode_operation |
| 2562 | * |
Myles Watson | 9ca0709 | 2016-11-28 16:41:53 -0800 | [diff] [blame] | 2563 | * Description This function update the GAP role operation when a link |
| 2564 | * status is updated. |
Myles Watson | ee96a3c | 2016-11-23 14:49:54 -0800 | [diff] [blame] | 2565 | * |
| 2566 | * Returns void |
| 2567 | * |
| 2568 | ******************************************************************************/ |
Jakub Pawlowski | a484a88 | 2017-06-24 17:30:18 -0700 | [diff] [blame] | 2569 | void btm_ble_update_mode_operation(uint8_t link_role, const RawAddress* bd_addr, |
| 2570 | uint8_t status) { |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 2571 | if (status == HCI_ERR_DIRECTED_ADVERTISING_TIMEOUT) { |
| 2572 | btm_cb.ble_ctr_cb.inq_var.adv_mode = BTM_BLE_ADV_DISABLE; |
| 2573 | /* make device fall back into undirected adv mode by default */ |
| 2574 | btm_cb.ble_ctr_cb.inq_var.directed_conn = BTM_BLE_CONNECT_EVT; |
| 2575 | /* clear all adv states */ |
| 2576 | btm_ble_clear_topology_mask(BTM_BLE_STATE_ALL_ADV_MASK); |
| 2577 | } |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 2578 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 2579 | if (btm_cb.ble_ctr_cb.inq_var.connectable_mode == BTM_BLE_CONNECTABLE) { |
| 2580 | btm_ble_set_connectability(btm_cb.btm_inq_vars.connectable_mode | |
| 2581 | btm_cb.ble_ctr_cb.inq_var.connectable_mode); |
| 2582 | } |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 2583 | |
Emil Lenngren | 8451ad0 | 2016-12-19 19:21:19 +0000 | [diff] [blame] | 2584 | /* in case of disconnected, we must cancel bgconn and restart |
| 2585 | in order to add back device to white list in order to reconnect */ |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 2586 | btm_ble_bgconn_cancel_if_disconnected(*bd_addr); |
Emil Lenngren | 8451ad0 | 2016-12-19 19:21:19 +0000 | [diff] [blame] | 2587 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 2588 | /* when no connection is attempted, and controller is not rejecting last |
| 2589 | request |
| 2590 | due to resource limitation, start next direct connection or background |
| 2591 | connection |
| 2592 | now in order */ |
| 2593 | if (btm_ble_get_conn_st() == BLE_CONN_IDLE && |
| 2594 | status != HCI_ERR_HOST_REJECT_RESOURCES && |
Emil Lenngren | af7f49c | 2016-12-12 18:47:12 +0000 | [diff] [blame] | 2595 | status != HCI_ERR_MAX_NUM_OF_CONNECTIONS && |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 2596 | !btm_send_pending_direct_conn()) { |
| 2597 | btm_ble_resume_bg_conn(); |
| 2598 | } |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 2599 | } |
| 2600 | |
| 2601 | /******************************************************************************* |
Myles Watson | ee96a3c | 2016-11-23 14:49:54 -0800 | [diff] [blame] | 2602 | * |
| 2603 | * Function btm_ble_init |
| 2604 | * |
| 2605 | * Description Initialize the control block variable values. |
| 2606 | * |
| 2607 | * Returns void |
| 2608 | * |
| 2609 | ******************************************************************************/ |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 2610 | void btm_ble_init(void) { |
| 2611 | tBTM_BLE_CB* p_cb = &btm_cb.ble_ctr_cb; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2612 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 2613 | BTM_TRACE_DEBUG("%s", __func__); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2614 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 2615 | alarm_free(p_cb->observer_timer); |
| 2616 | alarm_free(p_cb->inq_var.fast_adv_timer); |
| 2617 | memset(p_cb, 0, sizeof(tBTM_BLE_CB)); |
| 2618 | memset(&(btm_cb.cmn_ble_vsc_cb), 0, sizeof(tBTM_BLE_VSC_CB)); |
| 2619 | btm_cb.cmn_ble_vsc_cb.values_read = false; |
Pavlin Radoslavov | 78bcff7 | 2015-12-04 17:36:34 -0800 | [diff] [blame] | 2620 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 2621 | p_cb->observer_timer = alarm_new("btm_ble.observer_timer"); |
| 2622 | p_cb->cur_states = 0; |
| 2623 | p_cb->conn_pending_q = fixed_queue_new(SIZE_MAX); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2624 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 2625 | p_cb->inq_var.adv_mode = BTM_BLE_ADV_DISABLE; |
| 2626 | p_cb->inq_var.scan_type = BTM_BLE_SCAN_MODE_NONE; |
| 2627 | p_cb->inq_var.adv_chnl_map = BTM_BLE_DEFAULT_ADV_CHNL_MAP; |
| 2628 | p_cb->inq_var.afp = BTM_BLE_DEFAULT_AFP; |
| 2629 | p_cb->inq_var.sfp = BTM_BLE_DEFAULT_SFP; |
| 2630 | p_cb->inq_var.connectable_mode = BTM_BLE_NON_CONNECTABLE; |
| 2631 | p_cb->inq_var.discoverable_mode = BTM_BLE_NON_DISCOVERABLE; |
| 2632 | p_cb->inq_var.fast_adv_timer = alarm_new("btm_ble_inq.fast_adv_timer"); |
| 2633 | p_cb->inq_var.inquiry_timer = alarm_new("btm_ble_inq.inquiry_timer"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2634 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 2635 | /* for background connection, reset connection params to be undefined */ |
| 2636 | p_cb->scan_int = p_cb->scan_win = BTM_BLE_SCAN_PARAM_UNDEF; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2637 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 2638 | p_cb->inq_var.evt_type = BTM_BLE_NON_CONNECT_EVT; |
Satya Calloji | c4e2596 | 2014-05-10 23:46:24 -0700 | [diff] [blame] | 2639 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 2640 | p_cb->addr_mgnt_cb.refresh_raddr_timer = |
| 2641 | alarm_new("btm_ble_addr.refresh_raddr_timer"); |
Pavlin Radoslavov | 78bcff7 | 2015-12-04 17:36:34 -0800 | [diff] [blame] | 2642 | |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 2643 | #if (BLE_VND_INCLUDED == FALSE) |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 2644 | btm_ble_adv_filter_init(); |
Satya Calloji | 1a9247a | 2014-06-05 13:15:15 -0700 | [diff] [blame] | 2645 | #endif |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2646 | } |
| 2647 | |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2648 | /******************************************************************************* |
Myles Watson | ee96a3c | 2016-11-23 14:49:54 -0800 | [diff] [blame] | 2649 | * |
| 2650 | * Function btm_ble_topology_check |
| 2651 | * |
Myles Watson | 9ca0709 | 2016-11-28 16:41:53 -0800 | [diff] [blame] | 2652 | * Description check to see requested state is supported. One state check |
| 2653 | * at a time is supported |
Myles Watson | ee96a3c | 2016-11-23 14:49:54 -0800 | [diff] [blame] | 2654 | * |
| 2655 | * Returns true is request is allowed, false otherwise. |
| 2656 | * |
| 2657 | ******************************************************************************/ |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 2658 | bool btm_ble_topology_check(tBTM_BLE_STATE_MASK request_state_mask) { |
| 2659 | bool rt = false; |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2660 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 2661 | uint8_t state_offset = 0; |
| 2662 | uint16_t cur_states = btm_cb.ble_ctr_cb.cur_states; |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 2663 | uint8_t request_state = 0; |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2664 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 2665 | /* check only one bit is set and within valid range */ |
| 2666 | if (request_state_mask == BTM_BLE_STATE_INVALID || |
| 2667 | request_state_mask > BTM_BLE_STATE_SCAN_ADV_BIT || |
| 2668 | (request_state_mask & (request_state_mask - 1)) != 0) { |
| 2669 | BTM_TRACE_ERROR("illegal state requested: %d", request_state_mask); |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2670 | return rt; |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 2671 | } |
| 2672 | |
| 2673 | while (request_state_mask) { |
| 2674 | request_state_mask >>= 1; |
| 2675 | request_state++; |
| 2676 | } |
| 2677 | |
| 2678 | /* check if the requested state is supported or not */ |
Jakub Pawlowski | 5e43c80 | 2017-06-26 17:22:35 -0700 | [diff] [blame] | 2679 | uint8_t bit_num = btm_le_state_combo_tbl[0][request_state - 1]; |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 2680 | const uint8_t* ble_supported_states = |
| 2681 | controller_get_interface()->get_ble_supported_states(); |
| 2682 | |
Jakub Pawlowski | 5e43c80 | 2017-06-26 17:22:35 -0700 | [diff] [blame] | 2683 | if (!BTM_LE_STATES_SUPPORTED(ble_supported_states, bit_num)) { |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 2684 | BTM_TRACE_ERROR("state requested not supported: %d", request_state); |
| 2685 | return rt; |
| 2686 | } |
| 2687 | |
| 2688 | rt = true; |
| 2689 | /* make sure currently active states are all supported in conjunction with the |
Jakub Pawlowski | 5e43c80 | 2017-06-26 17:22:35 -0700 | [diff] [blame] | 2690 | requested state. If the bit in table is UNSUPPORTED, the combination is not |
| 2691 | supported */ |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 2692 | while (cur_states != 0) { |
| 2693 | if (cur_states & 0x01) { |
Jakub Pawlowski | 5e43c80 | 2017-06-26 17:22:35 -0700 | [diff] [blame] | 2694 | uint8_t bit_num = btm_le_state_combo_tbl[request_state][state_offset]; |
| 2695 | if (bit_num != UNSUPPORTED) { |
| 2696 | if (!BTM_LE_STATES_SUPPORTED(ble_supported_states, bit_num)) { |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 2697 | rt = false; |
| 2698 | break; |
| 2699 | } |
| 2700 | } |
| 2701 | } |
| 2702 | cur_states >>= 1; |
| 2703 | state_offset++; |
| 2704 | } |
| 2705 | return rt; |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2706 | } |