The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
| 3 | * Copyright (C) 1999-2012 Broadcom Corporation |
| 4 | * |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at: |
| 8 | * |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | * |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | * |
| 17 | ******************************************************************************/ |
| 18 | |
| 19 | /****************************************************************************** |
| 20 | * |
| 21 | * This file contains functions for BLE whitelist operation. |
| 22 | * |
| 23 | ******************************************************************************/ |
| 24 | |
| 25 | #include <string.h> |
| 26 | |
| 27 | #include "bt_types.h" |
| 28 | #include "btu.h" |
| 29 | #include "btm_int.h" |
| 30 | #include "l2c_int.h" |
| 31 | #include "hcimsgs.h" |
Mike J. Chen | 5cd8bff | 2014-01-31 18:16:59 -0800 | [diff] [blame] | 32 | #include "bt_utils.h" |
Satya Calloji | 0943c10 | 2014-05-12 09:13:02 -0700 | [diff] [blame] | 33 | #if (defined BLE_VND_INCLUDED && BLE_VND_INCLUDED == TRUE) |
| 34 | #include "vendor_ble.h" |
| 35 | #endif |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 36 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 37 | #ifndef BTM_BLE_SCAN_PARAM_TOUT |
| 38 | #define BTM_BLE_SCAN_PARAM_TOUT 50 /* 50 seconds */ |
| 39 | #endif |
| 40 | |
| 41 | #if (BLE_INCLUDED == TRUE) |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 42 | |
| 43 | static void btm_suspend_wl_activity(tBTM_BLE_WL_STATE wl_state); |
| 44 | static void btm_resume_wl_activity(tBTM_BLE_WL_STATE wl_state); |
| 45 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 46 | /******************************************************************************* |
| 47 | ** |
| 48 | ** Function btm_update_scanner_filter_policy |
| 49 | ** |
| 50 | ** Description This function update the filter policy of scnner or advertiser. |
| 51 | *******************************************************************************/ |
| 52 | void btm_update_scanner_filter_policy(tBTM_BLE_SFP scan_policy) |
| 53 | { |
| 54 | tBTM_BLE_INQ_CB *p_inq = &btm_cb.ble_ctr_cb.inq_var; |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 55 | BTM_TRACE_EVENT ("btm_update_scanner_filter_policy"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 56 | |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 57 | p_inq->sfp = scan_policy; |
| 58 | p_inq->scan_type = (p_inq->scan_type == BTM_BLE_SCAN_MODE_NONE) ? BTM_BLE_SCAN_MODE_ACTI: p_inq->scan_type; |
| 59 | |
| 60 | btsnd_hcic_ble_set_scan_params (p_inq->scan_type, |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 61 | (UINT16)(!p_inq->scan_interval ? BTM_BLE_GAP_DISC_SCAN_INT : p_inq->scan_interval), |
| 62 | (UINT16)(!p_inq->scan_window ? BTM_BLE_GAP_DISC_SCAN_WIN : p_inq->scan_window), |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 63 | btm_cb.ble_ctr_cb.addr_mgnt_cb.own_addr_type, |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 64 | scan_policy); |
| 65 | } |
| 66 | /******************************************************************************* |
| 67 | ** |
Andre Eisenbach | 6975b4d | 2013-08-05 16:55:38 -0700 | [diff] [blame] | 68 | ** Function btm_add_dev_to_controller |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 69 | ** |
Andre Eisenbach | 6975b4d | 2013-08-05 16:55:38 -0700 | [diff] [blame] | 70 | ** Description This function load the device into controller white list |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 71 | *******************************************************************************/ |
Andre Eisenbach | 6975b4d | 2013-08-05 16:55:38 -0700 | [diff] [blame] | 72 | BOOLEAN btm_add_dev_to_controller (BOOLEAN to_add, BD_ADDR bd_addr, UINT8 attr) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 73 | { |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 74 | tBTM_SEC_DEV_REC *p_dev_rec = btm_find_dev (bd_addr); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 75 | tBLE_ADDR_TYPE addr_type = BLE_ADDR_PUBLIC; |
Andre Eisenbach | 6975b4d | 2013-08-05 16:55:38 -0700 | [diff] [blame] | 76 | BOOLEAN started = FALSE; |
| 77 | BD_ADDR dummy_bda = {0}; |
| 78 | tBT_DEVICE_TYPE dev_type; |
Mike J. Chen | 5cd8bff | 2014-01-31 18:16:59 -0800 | [diff] [blame] | 79 | UNUSED(attr); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 80 | |
| 81 | if (p_dev_rec != NULL && |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 82 | p_dev_rec->device_type == BT_DEVICE_TYPE_BLE) |
| 83 | { |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 84 | |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 85 | if (to_add) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 86 | { |
Andre Eisenbach | 6975b4d | 2013-08-05 16:55:38 -0700 | [diff] [blame] | 87 | if (p_dev_rec->ble.ble_addr_type == BLE_ADDR_PUBLIC || !BTM_BLE_IS_RESOLVE_BDA(bd_addr)) |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 88 | { |
Satya Calloji | 0943c10 | 2014-05-12 09:13:02 -0700 | [diff] [blame] | 89 | #if (defined BLE_PRIVACY_SPT && BLE_PRIVACY_SPT == TRUE) |
| 90 | /* add device into IRK list */ |
| 91 | btm_ble_vendor_irk_list_load_dev(p_dev_rec); |
| 92 | #endif |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 93 | started = btsnd_hcic_ble_add_white_list (p_dev_rec->ble.ble_addr_type, bd_addr); |
| 94 | } |
| 95 | if (memcmp(p_dev_rec->ble.static_addr, bd_addr, BD_ADDR_LEN) != 0 && |
| 96 | memcmp(p_dev_rec->ble.static_addr, dummy_bda, BD_ADDR_LEN) != 0) |
| 97 | { |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 98 | started = btsnd_hcic_ble_add_white_list (p_dev_rec->ble.static_addr_type, |
| 99 | p_dev_rec->ble.static_addr); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 100 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 101 | } |
| 102 | else |
| 103 | { |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 104 | if (p_dev_rec->ble.ble_addr_type == BLE_ADDR_PUBLIC || !BTM_BLE_IS_RESOLVE_BDA(bd_addr)) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 105 | { |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 106 | started = btsnd_hcic_ble_remove_from_white_list (p_dev_rec->ble.ble_addr_type, bd_addr); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 107 | } |
Andre Eisenbach | 6975b4d | 2013-08-05 16:55:38 -0700 | [diff] [blame] | 108 | if (memcmp(p_dev_rec->ble.static_addr, dummy_bda, BD_ADDR_LEN) != 0 && |
| 109 | memcmp(p_dev_rec->ble.static_addr, bd_addr, BD_ADDR_LEN) != 0) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 110 | { |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 111 | started = btsnd_hcic_ble_remove_from_white_list (p_dev_rec->ble.static_addr_type, p_dev_rec->ble.static_addr); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 112 | } |
| 113 | } |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 114 | } /* if not a known device, shall we add it? */ |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 115 | else |
| 116 | { |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 117 | BTM_ReadDevInfo(bd_addr, &dev_type, &addr_type); |
Andre Eisenbach | 6975b4d | 2013-08-05 16:55:38 -0700 | [diff] [blame] | 118 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 119 | if (to_add) |
| 120 | started = btsnd_hcic_ble_add_white_list (addr_type, bd_addr); |
| 121 | else |
| 122 | started = btsnd_hcic_ble_remove_from_white_list (addr_type, bd_addr); |
| 123 | } |
| 124 | |
Andre Eisenbach | 6975b4d | 2013-08-05 16:55:38 -0700 | [diff] [blame] | 125 | return started; |
| 126 | |
| 127 | } |
| 128 | /******************************************************************************* |
| 129 | ** |
| 130 | ** Function btm_execute_wl_dev_operation |
| 131 | ** |
| 132 | ** Description execute the pending whitelist device operation(loading or removing) |
| 133 | *******************************************************************************/ |
| 134 | BOOLEAN btm_execute_wl_dev_operation(void) |
| 135 | { |
| 136 | tBTM_BLE_WL_OP *p_dev_op = btm_cb.ble_ctr_cb.wl_op_q; |
| 137 | UINT8 i = 0; |
| 138 | BOOLEAN rt = TRUE; |
| 139 | |
| 140 | for (i = 0; i < BTM_BLE_MAX_BG_CONN_DEV_NUM && rt; i ++, p_dev_op ++) |
| 141 | { |
| 142 | if (p_dev_op->in_use) |
| 143 | { |
| 144 | rt = btm_add_dev_to_controller(p_dev_op->to_add, p_dev_op->bd_addr, p_dev_op->attr); |
| 145 | memset(p_dev_op, 0, sizeof(tBTM_BLE_WL_OP)); |
| 146 | } |
| 147 | else |
| 148 | break; |
| 149 | } |
| 150 | return rt; |
| 151 | } |
| 152 | /******************************************************************************* |
| 153 | ** |
| 154 | ** Function btm_enq_wl_dev_operation |
| 155 | ** |
| 156 | ** Description enqueue the pending whitelist device operation(loading or removing). |
| 157 | *******************************************************************************/ |
| 158 | void btm_enq_wl_dev_operation(BOOLEAN to_add, BD_ADDR bd_addr, UINT8 attr) |
| 159 | { |
| 160 | tBTM_BLE_WL_OP *p_dev_op = btm_cb.ble_ctr_cb.wl_op_q; |
| 161 | UINT8 i = 0; |
| 162 | |
| 163 | for (i = 0; i < BTM_BLE_MAX_BG_CONN_DEV_NUM; i ++, p_dev_op ++) |
| 164 | { |
| 165 | if (p_dev_op->in_use && !memcmp(p_dev_op->bd_addr, bd_addr, BD_ADDR_LEN)) |
| 166 | { |
| 167 | p_dev_op->to_add = to_add; |
| 168 | p_dev_op->attr = attr; |
| 169 | return; |
| 170 | } |
| 171 | else if (!p_dev_op->in_use) |
| 172 | break; |
| 173 | } |
| 174 | if (i != BTM_BLE_MAX_BG_CONN_DEV_NUM) |
| 175 | { |
| 176 | p_dev_op->in_use = TRUE; |
| 177 | p_dev_op->to_add = to_add; |
| 178 | p_dev_op->attr = attr; |
| 179 | memcpy(p_dev_op->bd_addr, bd_addr, BD_ADDR_LEN); |
| 180 | } |
| 181 | else |
| 182 | { |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 183 | BTM_TRACE_ERROR("max pending WL operation reached, discard"); |
Andre Eisenbach | 6975b4d | 2013-08-05 16:55:38 -0700 | [diff] [blame] | 184 | } |
| 185 | return; |
| 186 | } |
| 187 | /******************************************************************************* |
| 188 | ** |
| 189 | ** Function btm_update_dev_to_white_list |
| 190 | ** |
| 191 | ** Description This function adds a device into white list. |
| 192 | *******************************************************************************/ |
| 193 | BOOLEAN btm_update_dev_to_white_list(BOOLEAN to_add, BD_ADDR bd_addr, UINT8 attr) |
| 194 | { |
| 195 | /* look up the sec device record, and find the address */ |
| 196 | tBTM_BLE_CB *p_cb = &btm_cb.ble_ctr_cb; |
| 197 | BOOLEAN started = FALSE; |
| 198 | UINT8 wl_state = p_cb->wl_state; |
| 199 | |
| 200 | if ((to_add && p_cb->num_empty_filter == 0) || |
| 201 | (!to_add && p_cb->num_empty_filter == p_cb->max_filter_entries)) |
| 202 | { |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 203 | BTM_TRACE_ERROR("WL full or empty, unable to update to WL. num_entry available: %d", |
Andre Eisenbach | 6975b4d | 2013-08-05 16:55:38 -0700 | [diff] [blame] | 204 | p_cb->num_empty_filter); |
| 205 | return started; |
| 206 | } |
| 207 | |
| 208 | btm_suspend_wl_activity(wl_state); |
| 209 | |
| 210 | /* enq pending WL device operation */ |
| 211 | btm_enq_wl_dev_operation(to_add, bd_addr, attr); |
| 212 | |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 213 | btm_resume_wl_activity(wl_state); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 214 | |
| 215 | return started; |
| 216 | } |
| 217 | /******************************************************************************* |
| 218 | ** |
| 219 | ** Function btm_ble_clear_white_list |
| 220 | ** |
| 221 | ** Description This function clears the white list. |
| 222 | *******************************************************************************/ |
| 223 | void btm_ble_clear_white_list (void) |
| 224 | { |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 225 | BTM_TRACE_EVENT ("btm_ble_clear_white_list"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 226 | btsnd_hcic_ble_clear_white_list(); |
| 227 | } |
| 228 | |
| 229 | /******************************************************************************* |
| 230 | ** |
| 231 | ** Function btm_ble_clear_white_list_complete |
| 232 | ** |
| 233 | ** Description This function clears the white list complete. |
| 234 | *******************************************************************************/ |
| 235 | void btm_ble_clear_white_list_complete(UINT8 *p_data, UINT16 evt_len) |
| 236 | { |
| 237 | tBTM_BLE_CB *p_cb = &btm_cb.ble_ctr_cb; |
| 238 | UINT8 status; |
Mike J. Chen | 5cd8bff | 2014-01-31 18:16:59 -0800 | [diff] [blame] | 239 | UNUSED(evt_len); |
| 240 | |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 241 | BTM_TRACE_EVENT ("btm_ble_clear_white_list_complete"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 242 | STREAM_TO_UINT8 (status, p_data); |
| 243 | |
| 244 | if (status == HCI_SUCCESS) |
| 245 | p_cb->num_empty_filter = p_cb->max_filter_entries; |
| 246 | |
| 247 | } |
| 248 | /******************************************************************************* |
| 249 | ** |
| 250 | ** Function btm_ble_add_2_white_list_complete |
| 251 | ** |
| 252 | ** Description This function read the current white list size. |
| 253 | *******************************************************************************/ |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 254 | void btm_ble_add_2_white_list_complete(UINT8 status) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 255 | { |
| 256 | tBTM_BLE_CB *p_cb = &btm_cb.ble_ctr_cb; |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 257 | BTM_TRACE_EVENT ("btm_ble_add_2_white_list_complete"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 258 | |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 259 | if (status == HCI_SUCCESS) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 260 | { |
| 261 | p_cb->num_empty_filter --; |
| 262 | } |
| 263 | } |
| 264 | /******************************************************************************* |
| 265 | ** |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 266 | ** Function btm_ble_remove_from_white_list_complete |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 267 | ** |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 268 | ** Description This function remove the white list element complete. |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 269 | *******************************************************************************/ |
| 270 | void btm_ble_remove_from_white_list_complete(UINT8 *p, UINT16 evt_len) |
| 271 | { |
| 272 | tBTM_BLE_CB *p_cb = &btm_cb.ble_ctr_cb; |
Mike J. Chen | 5cd8bff | 2014-01-31 18:16:59 -0800 | [diff] [blame] | 273 | UNUSED(evt_len); |
| 274 | |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 275 | BTM_TRACE_EVENT ("btm_ble_remove_from_white_list_complete"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 276 | if (*p == HCI_SUCCESS) |
| 277 | { |
| 278 | p_cb->num_empty_filter ++; |
| 279 | } |
| 280 | } |
| 281 | /******************************************************************************* |
| 282 | ** |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 283 | ** Function btm_ble_count_unconn_dev_in_whitelist |
| 284 | ** |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 285 | ** Description This function find the number of un-connected background device |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 286 | *******************************************************************************/ |
| 287 | UINT8 btm_ble_count_unconn_dev_in_whitelist(void) |
| 288 | { |
| 289 | tBTM_BLE_CB *p_cb = &btm_cb.ble_ctr_cb; |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 290 | UINT8 i, count = 0; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 291 | |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 292 | for (i = 0; i < BTM_BLE_MAX_BG_CONN_DEV_NUM; i ++) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 293 | { |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 294 | if (p_cb->bg_dev_list[i].in_use && |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 295 | !BTM_IsAclConnectionUp(p_cb->bg_dev_list[i].bd_addr, BT_TRANSPORT_LE)) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 296 | { |
| 297 | count ++; |
| 298 | } |
| 299 | } |
| 300 | return count; |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 301 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 302 | } |
| 303 | /******************************************************************************* |
| 304 | ** |
| 305 | ** Function btm_update_bg_conn_list |
| 306 | ** |
| 307 | ** Description This function update the local background connection device list. |
| 308 | *******************************************************************************/ |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 309 | BOOLEAN btm_update_bg_conn_list(BOOLEAN to_add, BD_ADDR bd_addr, UINT8 *p_attr_tag) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 310 | { |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 311 | tBTM_BLE_CB *p_cb = &btm_cb.ble_ctr_cb; |
| 312 | tBTM_LE_BG_CONN_DEV *p_bg_dev = &p_cb->bg_dev_list[0], *p_next, *p_cur; |
| 313 | UINT8 i, j; |
| 314 | BOOLEAN ret = FALSE; |
Mike J. Chen | 5cd8bff | 2014-01-31 18:16:59 -0800 | [diff] [blame] | 315 | UNUSED(p_attr_tag); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 316 | |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 317 | BTM_TRACE_EVENT ("btm_update_bg_conn_list"); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 318 | |
| 319 | if ((to_add && (p_cb->bg_dev_num == BTM_BLE_MAX_BG_CONN_DEV_NUM || p_cb->num_empty_filter == 0))) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 320 | { |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 321 | BTM_TRACE_DEBUG("num_empty_filter = %d", p_cb->num_empty_filter); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 322 | return ret; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 323 | } |
| 324 | |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 325 | for (i = 0; i < BTM_BLE_MAX_BG_CONN_DEV_NUM; i ++, p_bg_dev ++) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 326 | { |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 327 | if (p_bg_dev->in_use && memcmp(p_bg_dev->bd_addr, bd_addr, BD_ADDR_LEN) == 0) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 328 | { |
Andre Eisenbach | 6975b4d | 2013-08-05 16:55:38 -0700 | [diff] [blame] | 329 | if (!to_add) |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 330 | { |
| 331 | memset(p_bg_dev, 0, sizeof(tBTM_LE_BG_CONN_DEV)); |
| 332 | p_cb->bg_dev_num --; |
| 333 | p_cur = p_bg_dev; |
| 334 | p_next = p_bg_dev + 1; |
| 335 | for (j = i + 1 ;j < BTM_BLE_MAX_BG_CONN_DEV_NUM && p_next->in_use ; j ++, p_cur ++, p_next ++ ) |
| 336 | memcpy(p_cur, p_next, sizeof(tBTM_LE_BG_CONN_DEV)); |
| 337 | } |
| 338 | ret = TRUE; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 339 | break; |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 340 | } |
| 341 | else if (!p_bg_dev->in_use && to_add) |
| 342 | { |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 343 | BTM_TRACE_DEBUG("add new WL entry in bg_dev_list"); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 344 | |
| 345 | memcpy(p_bg_dev->bd_addr, bd_addr, BD_ADDR_LEN); |
| 346 | p_bg_dev->in_use = TRUE; |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 347 | p_cb->bg_dev_num ++; |
| 348 | |
| 349 | ret = TRUE; |
| 350 | break; |
| 351 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 352 | } |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 353 | |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 354 | |
| 355 | return ret; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 356 | } |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 357 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 358 | /******************************************************************************* |
| 359 | ** |
| 360 | ** Function btm_ble_start_auto_conn |
| 361 | ** |
| 362 | ** Description This function is to start/stop auto connection procedure. |
| 363 | ** |
| 364 | ** Parameters start: TRUE to start; FALSE to stop. |
| 365 | ** |
| 366 | ** Returns void |
| 367 | ** |
| 368 | *******************************************************************************/ |
| 369 | BOOLEAN btm_ble_start_auto_conn(BOOLEAN start) |
| 370 | { |
| 371 | tBTM_BLE_CB *p_cb = &btm_cb.ble_ctr_cb; |
| 372 | BD_ADDR dummy_bda = {0}; |
| 373 | BOOLEAN exec = TRUE; |
| 374 | UINT16 scan_int, scan_win; |
| 375 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 376 | if (start) |
| 377 | { |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 378 | if ((p_cb->conn_state == BLE_CONN_IDLE && btm_ble_count_unconn_dev_in_whitelist() > 0) |
| 379 | && btm_ble_topology_check(BTM_BLE_STATE_INIT)) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 380 | { |
Andre Eisenbach | 6975b4d | 2013-08-05 16:55:38 -0700 | [diff] [blame] | 381 | btm_execute_wl_dev_operation(); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 382 | |
| 383 | scan_int = (p_cb->scan_int == BTM_BLE_CONN_PARAM_UNDEF) ? BTM_BLE_SCAN_SLOW_INT_1 : p_cb->scan_int; |
| 384 | scan_win = (p_cb->scan_win == BTM_BLE_CONN_PARAM_UNDEF) ? BTM_BLE_SCAN_SLOW_WIN_1 : p_cb->scan_win; |
| 385 | |
| 386 | if (!btsnd_hcic_ble_create_ll_conn (scan_int, /* UINT16 scan_int */ |
| 387 | scan_win, /* UINT16 scan_win */ |
| 388 | 0x01, /* UINT8 white_list */ |
| 389 | BLE_ADDR_PUBLIC, /* UINT8 addr_type_peer */ |
| 390 | dummy_bda, /* BD_ADDR bda_peer */ |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 391 | p_cb->addr_mgnt_cb.own_addr_type, |
| 392 | /* UINT8 addr_type_own, |
| 393 | not allow random address for central */ |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 394 | BTM_BLE_CONN_INT_MIN_DEF, /* UINT16 conn_int_min */ |
| 395 | BTM_BLE_CONN_INT_MAX_DEF, /* UINT16 conn_int_max */ |
| 396 | BTM_BLE_CONN_SLAVE_LATENCY_DEF, /* UINT16 conn_latency */ |
| 397 | BTM_BLE_CONN_TIMEOUT_DEF, /* UINT16 conn_timeout */ |
| 398 | 0, /* UINT16 min_len */ |
| 399 | 0)) /* UINT16 max_len */ |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 400 | { |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 401 | /* start auto connection failed */ |
| 402 | exec = FALSE; |
| 403 | } |
| 404 | else |
| 405 | { |
Andre Eisenbach | 6975b4d | 2013-08-05 16:55:38 -0700 | [diff] [blame] | 406 | btm_ble_set_conn_st (BLE_BG_CONN); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 407 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 408 | } |
| 409 | } |
| 410 | else |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 411 | { |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 412 | exec = FALSE; |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 413 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 414 | } |
| 415 | else |
| 416 | { |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 417 | if (p_cb->conn_state == BLE_BG_CONN) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 418 | { |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 419 | btsnd_hcic_ble_create_conn_cancel(); |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 420 | btm_ble_set_conn_st (BLE_CONN_CANCEL); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 421 | |
Satya Calloji | 0943c10 | 2014-05-12 09:13:02 -0700 | [diff] [blame] | 422 | #if (defined BLE_VND_INCLUDED && BLE_VND_INCLUDED == TRUE) |
| 423 | #if (defined BLE_PRIVACY_SPT && BLE_PRIVACY_SPT == TRUE) |
| 424 | btm_ble_vendor_disable_irk_list(); |
| 425 | #endif |
| 426 | #endif |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 427 | } |
| 428 | else |
| 429 | { |
| 430 | #if 0 |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 431 | BTM_TRACE_ERROR("conn_st = %d, not in auto conn state, can not stop.", p_cb->conn_state); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 432 | exec = FALSE; |
| 433 | #endif |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 434 | } |
| 435 | } |
| 436 | return exec; |
| 437 | } |
| 438 | |
| 439 | /******************************************************************************* |
| 440 | ** |
| 441 | ** Function btm_ble_start_select_conn |
| 442 | ** |
| 443 | ** Description This function is to start/stop selective connection procedure. |
| 444 | ** |
| 445 | ** Parameters start: TRUE to start; FALSE to stop. |
| 446 | ** p_select_cback: callback function to return application |
| 447 | ** selection. |
| 448 | ** |
| 449 | ** Returns BOOLEAN: selective connectino procedure is started. |
| 450 | ** |
| 451 | *******************************************************************************/ |
| 452 | BOOLEAN btm_ble_start_select_conn(BOOLEAN start,tBTM_BLE_SEL_CBACK *p_select_cback) |
| 453 | { |
| 454 | tBTM_BLE_CB *p_cb = &btm_cb.ble_ctr_cb; |
| 455 | UINT16 scan_int, scan_win; |
| 456 | |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 457 | BTM_TRACE_EVENT ("btm_ble_start_select_conn"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 458 | |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 459 | scan_int = (p_cb->scan_int == BTM_BLE_CONN_PARAM_UNDEF) ? BTM_BLE_SCAN_FAST_INT : p_cb->scan_int; |
| 460 | scan_win = (p_cb->scan_win == BTM_BLE_CONN_PARAM_UNDEF) ? BTM_BLE_SCAN_FAST_WIN : p_cb->scan_win; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 461 | |
| 462 | if (start) |
| 463 | { |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 464 | if (!BTM_BLE_IS_SCAN_ACTIVE(p_cb->scan_activity)) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 465 | { |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 466 | if (p_select_cback != NULL) |
| 467 | btm_cb.ble_ctr_cb.p_select_cback = p_select_cback; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 468 | |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 469 | btm_execute_wl_dev_operation(); |
| 470 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 471 | btm_update_scanner_filter_policy(SP_ADV_WL); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 472 | btm_cb.ble_ctr_cb.inq_var.scan_type = BTM_BLE_SCAN_MODE_PASS; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 473 | |
| 474 | if (!btsnd_hcic_ble_set_scan_params(BTM_BLE_SCAN_MODE_PASS, /* use passive scan by default */ |
| 475 | scan_int, /* scan interval */ |
| 476 | scan_win, /* scan window */ |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 477 | p_cb->addr_mgnt_cb.own_addr_type, |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 478 | SP_ADV_WL) /* process advertising packets only from devices in the White List */ |
| 479 | ) |
| 480 | return FALSE; |
| 481 | |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 482 | if (!btm_ble_topology_check(BTM_BLE_STATE_PASSIVE_SCAN)) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 483 | { |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 484 | BTM_TRACE_ERROR("peripheral device cannot initiate passive scan for a selective connection"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 485 | return FALSE; |
| 486 | } |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 487 | else if (p_cb->bg_dev_num > 0 && btm_ble_count_unconn_dev_in_whitelist() > 0 ) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 488 | { |
| 489 | |
| 490 | if (!btsnd_hcic_ble_set_scan_enable(TRUE, TRUE)) /* duplicate filtering enabled */ |
| 491 | return FALSE; |
| 492 | |
| 493 | /* mark up inquiry status flag */ |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 494 | p_cb->scan_activity |= BTM_LE_SELECT_CONN_ACTIVE; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 495 | } |
| 496 | } |
| 497 | else |
| 498 | { |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 499 | BTM_TRACE_ERROR("scan active, can not start selective connection procedure"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 500 | return FALSE; |
| 501 | } |
| 502 | } |
| 503 | else /* disable selective connection mode */ |
| 504 | { |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 505 | p_cb->scan_activity &= ~BTM_LE_SELECT_CONN_ACTIVE; |
| 506 | p_cb->p_select_cback = NULL; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 507 | |
Satya Calloji | 0943c10 | 2014-05-12 09:13:02 -0700 | [diff] [blame] | 508 | #if (defined BLE_PRIVACY_SPT && BLE_PRIVACY_SPT == TRUE) |
| 509 | #if (defined BLE_VND_INCLUDED && BLE_VND_INCLUDED == TRUE) |
| 510 | btm_ble_vendor_disable_irk_list(); |
| 511 | #endif |
| 512 | #endif |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 513 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 514 | /* stop scanning */ |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 515 | if (!BTM_BLE_IS_SCAN_ACTIVE(p_cb->scan_activity)) |
| 516 | btm_ble_stop_scan(); /* duplicate filtering enabled */ |
Andre Eisenbach | 6975b4d | 2013-08-05 16:55:38 -0700 | [diff] [blame] | 517 | btm_update_scanner_filter_policy(SP_ADV_ALL); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 518 | } |
| 519 | return TRUE; |
| 520 | } |
| 521 | /******************************************************************************* |
| 522 | ** |
| 523 | ** Function btm_ble_initiate_select_conn |
| 524 | ** |
| 525 | ** Description This function is to start/stop selective connection procedure. |
| 526 | ** |
| 527 | ** Parameters start: TRUE to start; FALSE to stop. |
| 528 | ** p_select_cback: callback function to return application |
| 529 | ** selection. |
| 530 | ** |
| 531 | ** Returns BOOLEAN: selective connectino procedure is started. |
| 532 | ** |
| 533 | *******************************************************************************/ |
| 534 | void btm_ble_initiate_select_conn(BD_ADDR bda) |
| 535 | { |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 536 | BTM_TRACE_EVENT ("btm_ble_initiate_select_conn"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 537 | |
| 538 | /* use direct connection procedure to initiate connection */ |
| 539 | if (!L2CA_ConnectFixedChnl(L2CAP_ATT_CID, bda)) |
| 540 | { |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 541 | BTM_TRACE_ERROR("btm_ble_initiate_select_conn failed"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 542 | } |
| 543 | } |
| 544 | /******************************************************************************* |
| 545 | ** |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 546 | ** Function btm_ble_suspend_bg_conn |
| 547 | ** |
| 548 | ** Description This function is to suspend an active background connection |
| 549 | ** procedure. |
| 550 | ** |
| 551 | ** Parameters none. |
| 552 | ** |
| 553 | ** Returns none. |
| 554 | ** |
| 555 | *******************************************************************************/ |
| 556 | void btm_ble_suspend_bg_conn(void) |
| 557 | { |
| 558 | tBTM_BLE_CB *p_cb = &btm_cb.ble_ctr_cb; |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 559 | BTM_TRACE_EVENT ("btm_ble_suspend_bg_conn"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 560 | |
| 561 | if (p_cb->bg_conn_type == BTM_BLE_CONN_AUTO) |
| 562 | { |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 563 | btm_ble_start_auto_conn(FALSE); |
| 564 | } |
| 565 | else if (p_cb->bg_conn_type == BTM_BLE_CONN_SELECTIVE) |
| 566 | { |
| 567 | btm_ble_start_select_conn(FALSE, NULL); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 568 | } |
| 569 | } |
| 570 | /******************************************************************************* |
| 571 | ** |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 572 | ** Function btm_suspend_wl_activity |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 573 | ** |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 574 | ** Description This function is to suspend white list related activity |
| 575 | ** |
| 576 | ** Returns none. |
| 577 | ** |
| 578 | *******************************************************************************/ |
| 579 | static void btm_suspend_wl_activity(tBTM_BLE_WL_STATE wl_state) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 580 | { |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 581 | if (wl_state & BTM_BLE_WL_INIT) |
| 582 | { |
| 583 | btm_ble_start_auto_conn(FALSE); |
| 584 | } |
| 585 | if (wl_state & BTM_BLE_WL_SCAN) |
| 586 | { |
| 587 | btm_ble_start_select_conn(FALSE, NULL); |
| 588 | } |
| 589 | if (wl_state & BTM_BLE_WL_ADV) |
| 590 | { |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 591 | btm_ble_stop_adv(); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 592 | } |
| 593 | |
| 594 | } |
| 595 | /******************************************************************************* |
| 596 | ** |
| 597 | ** Function btm_resume_wl_activity |
| 598 | ** |
| 599 | ** Description This function is to resume white list related activity |
| 600 | ** |
| 601 | ** Returns none. |
| 602 | ** |
| 603 | *******************************************************************************/ |
| 604 | static void btm_resume_wl_activity(tBTM_BLE_WL_STATE wl_state) |
| 605 | { |
| 606 | btm_ble_resume_bg_conn(); |
| 607 | |
| 608 | if (wl_state & BTM_BLE_WL_ADV) |
| 609 | { |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 610 | btm_ble_start_adv(); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 611 | } |
| 612 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 613 | } |
| 614 | /******************************************************************************* |
| 615 | ** |
| 616 | ** Function btm_ble_resume_bg_conn |
| 617 | ** |
| 618 | ** Description This function is to resume a background auto connection |
| 619 | ** procedure. |
| 620 | ** |
| 621 | ** Parameters none. |
| 622 | ** |
| 623 | ** Returns none. |
| 624 | ** |
| 625 | *******************************************************************************/ |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 626 | BOOLEAN btm_ble_resume_bg_conn(void) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 627 | { |
| 628 | tBTM_BLE_CB *p_cb = &btm_cb.ble_ctr_cb; |
| 629 | BOOLEAN ret = FALSE; |
| 630 | |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 631 | if (p_cb->bg_conn_type != BTM_BLE_CONN_NONE) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 632 | { |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 633 | if (p_cb->bg_conn_type == BTM_BLE_CONN_AUTO) |
| 634 | ret = btm_ble_start_auto_conn(TRUE); |
| 635 | |
| 636 | if (p_cb->bg_conn_type == BTM_BLE_CONN_SELECTIVE) |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 637 | ret = btm_ble_start_select_conn(TRUE, btm_cb.ble_ctr_cb.p_select_cback); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 638 | } |
| 639 | |
| 640 | return ret; |
| 641 | } |
| 642 | /******************************************************************************* |
| 643 | ** |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 644 | ** Function btm_ble_get_conn_st |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 645 | ** |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 646 | ** Description This function get BLE connection state |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 647 | ** |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 648 | ** Returns connection state |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 649 | ** |
| 650 | *******************************************************************************/ |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 651 | tBTM_BLE_CONN_ST btm_ble_get_conn_st(void) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 652 | { |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 653 | return btm_cb.ble_ctr_cb.conn_state; |
| 654 | } |
| 655 | /******************************************************************************* |
| 656 | ** |
| 657 | ** Function btm_ble_set_conn_st |
| 658 | ** |
| 659 | ** Description This function set BLE connection state |
| 660 | ** |
| 661 | ** Returns None. |
| 662 | ** |
| 663 | *******************************************************************************/ |
| 664 | void btm_ble_set_conn_st(tBTM_BLE_CONN_ST new_st) |
| 665 | { |
| 666 | btm_cb.ble_ctr_cb.conn_state = new_st; |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 667 | if (new_st == BLE_BG_CONN || new_st == BLE_DIR_CONN) |
| 668 | btm_ble_set_topology_mask(BTM_BLE_STATE_INIT_BIT); |
| 669 | else |
| 670 | btm_ble_clear_topology_mask(BTM_BLE_STATE_INIT_BIT); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 671 | } |
| 672 | |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 673 | /******************************************************************************* |
| 674 | ** |
| 675 | ** Function btm_ble_enqueue_direct_conn_req |
| 676 | ** |
| 677 | ** Description This function enqueue the direct connection request |
| 678 | ** |
| 679 | ** Returns None. |
| 680 | ** |
| 681 | *******************************************************************************/ |
| 682 | void btm_ble_enqueue_direct_conn_req(void *p_param) |
| 683 | { |
| 684 | tBTM_BLE_CONN_REQ *p = (tBTM_BLE_CONN_REQ *)GKI_getbuf(sizeof(tBTM_BLE_CONN_REQ)); |
| 685 | |
| 686 | p->p_param = p_param; |
| 687 | |
| 688 | GKI_enqueue (&btm_cb.ble_ctr_cb.conn_pending_q, p); |
| 689 | } |
| 690 | /******************************************************************************* |
| 691 | ** |
| 692 | ** Function btm_send_pending_direct_conn |
| 693 | ** |
| 694 | ** Description This function send the pending direct connection request in queue |
| 695 | ** |
| 696 | ** Returns TRUE if started, FALSE otherwise |
| 697 | ** |
| 698 | *******************************************************************************/ |
| 699 | BOOLEAN btm_send_pending_direct_conn(void ) |
| 700 | { |
| 701 | tBTM_BLE_CONN_REQ *p_req; |
| 702 | BOOLEAN rt = FALSE; |
| 703 | |
| 704 | if ( btm_cb.ble_ctr_cb.conn_pending_q.count ) |
| 705 | { |
| 706 | p_req = (tBTM_BLE_CONN_REQ*)GKI_dequeue (&btm_cb.ble_ctr_cb.conn_pending_q); |
| 707 | |
| 708 | rt = l2cble_init_direct_conn((tL2C_LCB *)(p_req->p_param)); |
| 709 | |
| 710 | GKI_freebuf((void *)p_req); |
| 711 | } |
| 712 | |
| 713 | return rt; |
| 714 | } |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 715 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 716 | #endif |
| 717 | |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 718 | |