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