The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
| 3 | * Copyright (C) 2000-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 that handle ACL connections. This includes |
| 22 | * operations such as hold and sniff modes, supported packet types. |
| 23 | * |
| 24 | ******************************************************************************/ |
| 25 | |
| 26 | #include <stdlib.h> |
| 27 | #include <string.h> |
| 28 | #include <stdio.h> |
| 29 | #include <stddef.h> |
| 30 | |
| 31 | #include "bt_types.h" |
| 32 | #include "bt_target.h" |
| 33 | #include "gki.h" |
| 34 | #include "hcimsgs.h" |
| 35 | #include "btu.h" |
| 36 | #include "btm_api.h" |
| 37 | #include "btm_int.h" |
| 38 | #include "l2c_int.h" |
| 39 | #include "hcidefs.h" |
Mike J. Chen | 23b252c | 2014-01-31 15:27:49 -0800 | [diff] [blame] | 40 | #include "bd.h" |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 41 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 42 | static void btm_establish_continue (tACL_CONN *p_acl_cb); |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 43 | static void btm_read_remote_features (UINT16 handle); |
| 44 | static void btm_read_remote_ext_features (UINT16 handle, UINT8 page_number); |
| 45 | static void btm_process_remote_ext_features_page (tACL_CONN *p_acl_cb, tBTM_SEC_DEV_REC *p_dev_rec, |
| 46 | UINT8 page_idx); |
| 47 | static void btm_process_remote_ext_features (tACL_CONN *p_acl_cb, UINT8 num_read_pages); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 48 | |
| 49 | #define BTM_DEV_REPLY_TIMEOUT 3 /* 3 second timeout waiting for responses */ |
| 50 | |
| 51 | /******************************************************************************* |
| 52 | ** |
Zhihai Xu | a934f01 | 2013-10-07 15:11:22 -0700 | [diff] [blame] | 53 | ** Function btm_save_remote_device_role |
| 54 | ** |
| 55 | ** Description This function is to save remote device role |
| 56 | ** |
| 57 | ** Returns void |
| 58 | ** |
| 59 | *******************************************************************************/ |
| 60 | static void btm_save_remote_device_role(BD_ADDR bd_addr, UINT8 role) |
| 61 | { |
| 62 | UINT8 i, j; |
| 63 | if (role == BTM_ROLE_UNDEFINED) return; |
| 64 | |
| 65 | for (i = 0; i < BTM_ROLE_DEVICE_NUM; i++) { |
| 66 | if ((btm_cb.previous_connected_role[i] != BTM_ROLE_UNDEFINED) && |
| 67 | (!bdcmp(bd_addr, btm_cb.previous_connected_remote_addr[i]))) { |
| 68 | break; |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | if (i < BTM_ROLE_DEVICE_NUM) { |
| 73 | UINT8 end; |
| 74 | if (i < btm_cb.front) { |
| 75 | for (j = i; j > 0; j--) { |
| 76 | bdcpy(btm_cb.previous_connected_remote_addr[j], |
| 77 | btm_cb.previous_connected_remote_addr[j-1]); |
| 78 | } |
| 79 | bdcpy(btm_cb.previous_connected_remote_addr[0], |
| 80 | btm_cb.previous_connected_remote_addr[BTM_ROLE_DEVICE_NUM-1]); |
| 81 | end = BTM_ROLE_DEVICE_NUM-1; |
| 82 | } else { |
| 83 | end = i; |
| 84 | } |
| 85 | |
| 86 | for (j = end; j > btm_cb.front; j--) { |
| 87 | bdcpy(btm_cb.previous_connected_remote_addr[j], |
| 88 | btm_cb.previous_connected_remote_addr[j-1]); |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | bdcpy(btm_cb.previous_connected_remote_addr[btm_cb.front], bd_addr); |
| 93 | btm_cb.previous_connected_role[btm_cb.front] = role; |
| 94 | btm_cb.front = (btm_cb.front + 1) % BTM_ROLE_DEVICE_NUM; |
| 95 | } |
| 96 | |
| 97 | /******************************************************************************* |
| 98 | ** |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 99 | ** Function btm_acl_init |
| 100 | ** |
| 101 | ** Description This function is called at BTM startup to initialize |
| 102 | ** |
| 103 | ** Returns void |
| 104 | ** |
| 105 | *******************************************************************************/ |
| 106 | void btm_acl_init (void) |
| 107 | { |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 108 | BTM_TRACE_DEBUG ("btm_acl_init"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 109 | #if 0 /* cleared in btm_init; put back in if called from anywhere else! */ |
| 110 | memset (&btm_cb.acl_db, 0, sizeof (btm_cb.acl_db)); |
| 111 | #if RFCOMM_INCLUDED == TRUE |
| 112 | memset (btm_cb.btm_scn, 0, BTM_MAX_SCN); /* Initialize the SCN usage to FALSE */ |
| 113 | #endif |
| 114 | btm_cb.btm_def_link_policy = 0; |
| 115 | #if (defined(BTM_BUSY_LEVEL_CHANGE_INCLUDED) && BTM_BUSY_LEVEL_CHANGE_INCLUDED == TRUE) |
| 116 | btm_cb.p_bl_changed_cb = NULL; |
| 117 | #else |
| 118 | btm_cb.p_acl_changed_cb = NULL; |
| 119 | #endif |
| 120 | #endif |
| 121 | |
| 122 | /* Initialize nonzero defaults */ |
| 123 | btm_cb.btm_def_link_super_tout = HCI_DEFAULT_INACT_TOUT; |
| 124 | btm_cb.acl_disc_reason = 0xff ; |
| 125 | } |
| 126 | |
| 127 | /******************************************************************************* |
| 128 | ** |
| 129 | ** Function btm_bda_to_acl |
| 130 | ** |
| 131 | ** Description This function returns the FIRST acl_db entry for the passed BDA. |
| 132 | ** |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 133 | ** Parameters bda : BD address of the remote device |
| 134 | ** transport : Physical transport used for ACL connection (BR/EDR or LE) |
| 135 | ** |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 136 | ** Returns Returns pointer to the ACL DB for the requested BDA if found. |
| 137 | ** NULL if not found. |
| 138 | ** |
| 139 | *******************************************************************************/ |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 140 | tACL_CONN *btm_bda_to_acl (BD_ADDR bda, tBT_TRANSPORT transport) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 141 | { |
| 142 | tACL_CONN *p = &btm_cb.acl_db[0]; |
| 143 | UINT16 xx; |
| 144 | if (bda) |
| 145 | { |
| 146 | for (xx = 0; xx < MAX_L2CAP_LINKS; xx++, p++) |
| 147 | { |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 148 | if ((p->in_use) && (!memcmp (p->remote_addr, bda, BD_ADDR_LEN)) |
| 149 | #if BLE_INCLUDED == TRUE |
| 150 | && p->transport == transport |
| 151 | #endif |
| 152 | ) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 153 | { |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 154 | BTM_TRACE_DEBUG ("btm_bda_to_acl found"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 155 | return(p); |
| 156 | } |
| 157 | } |
| 158 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 159 | |
| 160 | /* If here, no BD Addr found */ |
| 161 | return((tACL_CONN *)NULL); |
| 162 | } |
| 163 | |
| 164 | /******************************************************************************* |
| 165 | ** |
| 166 | ** Function btm_handle_to_acl_index |
| 167 | ** |
| 168 | ** Description This function returns the FIRST acl_db entry for the passed hci_handle. |
| 169 | ** |
| 170 | ** Returns index to the acl_db or MAX_L2CAP_LINKS. |
| 171 | ** |
| 172 | *******************************************************************************/ |
| 173 | UINT8 btm_handle_to_acl_index (UINT16 hci_handle) |
| 174 | { |
| 175 | tACL_CONN *p = &btm_cb.acl_db[0]; |
| 176 | UINT8 xx; |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 177 | BTM_TRACE_DEBUG ("btm_handle_to_acl_index"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 178 | for (xx = 0; xx < MAX_L2CAP_LINKS; xx++, p++) |
| 179 | { |
| 180 | if ((p->in_use) && (p->hci_handle == hci_handle)) |
| 181 | { |
| 182 | break; |
| 183 | } |
| 184 | } |
| 185 | |
| 186 | /* If here, no BD Addr found */ |
| 187 | return(xx); |
| 188 | } |
Zhihai Xu | 6f908b2 | 2014-03-11 15:01:45 -0700 | [diff] [blame] | 189 | |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 190 | #if BLE_PRIVACY_SPT == TRUE |
Zhihai Xu | 6f908b2 | 2014-03-11 15:01:45 -0700 | [diff] [blame] | 191 | /******************************************************************************* |
| 192 | ** |
| 193 | ** Function btm_ble_get_acl_remote_addr |
| 194 | ** |
| 195 | ** Description This function reads the active remote address used for the |
| 196 | ** connection. |
| 197 | ** |
| 198 | ** Returns success return TRUE, otherwise FALSE. |
| 199 | ** |
| 200 | *******************************************************************************/ |
| 201 | BOOLEAN btm_ble_get_acl_remote_addr(tBTM_SEC_DEV_REC *p_dev_rec, BD_ADDR conn_addr, |
| 202 | tBLE_ADDR_TYPE *p_addr_type) |
| 203 | { |
| 204 | #if BLE_INCLUDED == TRUE |
| 205 | BOOLEAN st = TRUE; |
| 206 | |
| 207 | if (p_dev_rec == NULL) |
| 208 | { |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 209 | BTM_TRACE_ERROR("btm_ble_get_acl_remote_addr can not find device with matching address"); |
Zhihai Xu | 6f908b2 | 2014-03-11 15:01:45 -0700 | [diff] [blame] | 210 | return FALSE; |
| 211 | } |
| 212 | |
| 213 | switch (p_dev_rec->ble.active_addr_type) |
| 214 | { |
| 215 | case BTM_BLE_ADDR_PSEUDO: |
| 216 | memcpy(conn_addr, p_dev_rec->bd_addr, BD_ADDR_LEN); |
| 217 | * p_addr_type = p_dev_rec->ble.ble_addr_type; |
| 218 | break; |
| 219 | |
| 220 | case BTM_BLE_ADDR_RRA: |
| 221 | memcpy(conn_addr, p_dev_rec->ble.cur_rand_addr, BD_ADDR_LEN); |
| 222 | * p_addr_type = BLE_ADDR_RANDOM; |
| 223 | break; |
| 224 | |
| 225 | case BTM_BLE_ADDR_STATIC: |
| 226 | memcpy(conn_addr, p_dev_rec->ble.static_addr, BD_ADDR_LEN); |
| 227 | * p_addr_type = p_dev_rec->ble.static_addr_type; |
| 228 | break; |
| 229 | |
| 230 | default: |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 231 | BTM_TRACE_ERROR("Unknown active address: %d", p_dev_rec->ble.active_addr_type); |
Zhihai Xu | 6f908b2 | 2014-03-11 15:01:45 -0700 | [diff] [blame] | 232 | st = FALSE; |
| 233 | break; |
| 234 | } |
| 235 | |
| 236 | return st; |
| 237 | #else |
| 238 | return FALSE; |
| 239 | #endif |
| 240 | } |
| 241 | #endif |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 242 | /******************************************************************************* |
| 243 | ** |
| 244 | ** Function btm_acl_created |
| 245 | ** |
| 246 | ** Description This function is called by L2CAP when an ACL connection |
| 247 | ** is created. |
| 248 | ** |
| 249 | ** Returns void |
| 250 | ** |
| 251 | *******************************************************************************/ |
| 252 | void btm_acl_created (BD_ADDR bda, DEV_CLASS dc, BD_NAME bdn, |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 253 | UINT16 hci_handle, UINT8 link_role, tBT_TRANSPORT transport) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 254 | { |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 255 | tBTM_SEC_DEV_REC *p_dev_rec = NULL; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 256 | UINT8 yy; |
| 257 | tACL_CONN *p; |
| 258 | UINT8 xx; |
| 259 | |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 260 | BTM_TRACE_DEBUG ("btm_acl_created hci_handle=%d link_role=%d transport=%d", |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 261 | hci_handle,link_role, transport); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 262 | /* Ensure we don't have duplicates */ |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 263 | p = btm_bda_to_acl(bda, transport); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 264 | if (p != (tACL_CONN *)NULL) |
| 265 | { |
| 266 | p->hci_handle = hci_handle; |
| 267 | p->link_role = link_role; |
Zhihai Xu | a934f01 | 2013-10-07 15:11:22 -0700 | [diff] [blame] | 268 | btm_save_remote_device_role(bda, link_role); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 269 | #if BLE_INCLUDED == TRUE |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 270 | p->transport = transport; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 271 | #endif |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 272 | BTM_TRACE_DEBUG ("Duplicate btm_acl_created: RemBdAddr: %02x%02x%02x%02x%02x%02x", |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 273 | bda[0], bda[1], bda[2], bda[3], bda[4], bda[5]); |
| 274 | BTM_SetLinkPolicy(p->remote_addr, &btm_cb.btm_def_link_policy); |
| 275 | return; |
| 276 | } |
| 277 | |
| 278 | /* Allocate acl_db entry */ |
| 279 | for (xx = 0, p = &btm_cb.acl_db[0]; xx < MAX_L2CAP_LINKS; xx++, p++) |
| 280 | { |
| 281 | if (!p->in_use) |
| 282 | { |
| 283 | p->in_use = TRUE; |
| 284 | p->hci_handle = hci_handle; |
| 285 | p->link_role = link_role; |
Zhihai Xu | a934f01 | 2013-10-07 15:11:22 -0700 | [diff] [blame] | 286 | btm_save_remote_device_role(bda, link_role); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 287 | p->link_up_issued = FALSE; |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 288 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 289 | #if BLE_INCLUDED == TRUE |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 290 | p->transport = transport; |
| 291 | if (transport == BT_TRANSPORT_LE) |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 292 | { |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 293 | #if ( BLE_PRIVACY_SPT == TRUE ) |
| 294 | /*allow central device to use random address for now by skipping the role check */ |
| 295 | if (btm_cb.ble_ctr_cb.privacy /* && p->link_role == HCI_ROLE_SLAVE */) |
| 296 | { |
| 297 | p->conn_addr_type = btm_cb.ble_ctr_cb.addr_mgnt_cb.own_addr_type; |
| 298 | memcpy(p->conn_addr, btm_cb.ble_ctr_cb.addr_mgnt_cb.private_addr, BD_ADDR_LEN); |
| 299 | } |
| 300 | else |
| 301 | #endif |
| 302 | { |
| 303 | p->conn_addr_type = BLE_ADDR_PUBLIC; |
| 304 | BTM_GetLocalDeviceAddr(p->conn_addr); |
| 305 | } |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 306 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 307 | #endif |
| 308 | p->restore_pkt_types = 0; /* Only exists while SCO is active */ |
| 309 | p->switch_role_state = BTM_ACL_SWKEY_STATE_IDLE; |
| 310 | |
| 311 | #if BTM_PWR_MGR_INCLUDED == FALSE |
| 312 | p->mode = BTM_ACL_MODE_NORMAL; |
| 313 | #else |
| 314 | btm_pm_sm_alloc(xx); |
| 315 | #endif /* BTM_PWR_MGR_INCLUDED == FALSE */ |
| 316 | |
| 317 | memcpy (p->remote_addr, bda, BD_ADDR_LEN); |
| 318 | |
| 319 | if (dc) |
| 320 | memcpy (p->remote_dc, dc, DEV_CLASS_LEN); |
| 321 | |
| 322 | if (bdn) |
| 323 | memcpy (p->remote_name, bdn, BTM_MAX_REM_BD_NAME_LEN); |
| 324 | |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 325 | /* if BR/EDR do something more */ |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 326 | if (transport == BT_TRANSPORT_BR_EDR) |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 327 | { |
| 328 | btsnd_hcic_read_rmt_clk_offset (p->hci_handle); |
| 329 | btsnd_hcic_rmt_ver_req (p->hci_handle); |
| 330 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 331 | p_dev_rec = btm_find_dev_by_handle (hci_handle); |
| 332 | |
| 333 | #if (BLE_INCLUDED == TRUE) |
| 334 | if (p_dev_rec ) |
| 335 | { |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 336 | BTM_TRACE_DEBUG ("device_type=0x%x", p_dev_rec->device_type); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 337 | } |
| 338 | #endif |
| 339 | |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 340 | if (p_dev_rec && !(transport == BT_TRANSPORT_LE)) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 341 | { |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 342 | /* If remote features already known, copy them and continue connection setup */ |
| 343 | if ((p_dev_rec->num_read_pages) && |
| 344 | (p_dev_rec->num_read_pages <= (HCI_EXT_FEATURES_PAGE_MAX + 1)) /* sanity check */) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 345 | { |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 346 | memcpy (p->peer_lmp_features, p_dev_rec->features, |
| 347 | (HCI_FEATURE_BYTES_PER_PAGE * p_dev_rec->num_read_pages)); |
| 348 | p->num_read_pages = p_dev_rec->num_read_pages; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 349 | |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 350 | if (BTM_SEC_MODE_SP == btm_cb.security_mode |
| 351 | && HCI_SSP_HOST_SUPPORTED(p_dev_rec->features[HCI_EXT_FEATURES_PAGE_1]) |
| 352 | && HCI_SIMPLE_PAIRING_SUPPORTED(p_dev_rec->features[HCI_EXT_FEATURES_PAGE_0])) |
| 353 | { |
| 354 | p_dev_rec->sm4 = BTM_SM4_TRUE; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 355 | } |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 356 | else |
| 357 | { |
| 358 | p_dev_rec->sm4 |= BTM_SM4_KNOWN; |
| 359 | } |
| 360 | |
| 361 | btm_establish_continue (p); |
| 362 | return; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 363 | } |
| 364 | } |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 365 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 366 | #if (BLE_INCLUDED == TRUE) |
| 367 | /* If here, features are not known yet */ |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 368 | if (p_dev_rec && transport == BT_TRANSPORT_LE) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 369 | { |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 370 | #if BLE_PRIVACY_SPT == TRUE |
Zhihai Xu | 6f908b2 | 2014-03-11 15:01:45 -0700 | [diff] [blame] | 371 | btm_ble_get_acl_remote_addr (p_dev_rec, p->active_remote_addr, |
| 372 | &p->active_remote_addr_type); |
| 373 | #endif |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 374 | btm_establish_continue(p); |
| 375 | |
Sunny Kapdi | 7a5c591 | 2013-08-13 19:43:49 -0700 | [diff] [blame] | 376 | #if (!defined(BTA_SKIP_BLE_READ_REMOTE_FEAT) || BTA_SKIP_BLE_READ_REMOTE_FEAT == FALSE) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 377 | if (link_role == HCI_ROLE_MASTER) |
| 378 | { |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 379 | btsnd_hcic_ble_read_remote_feat(p->hci_handle); |
| 380 | } |
Sunny Kapdi | 7a5c591 | 2013-08-13 19:43:49 -0700 | [diff] [blame] | 381 | #endif |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 382 | } |
| 383 | else |
| 384 | #endif |
| 385 | { |
Matthew Xie | c2bb2c1 | 2013-04-09 11:26:08 -0700 | [diff] [blame] | 386 | btm_read_remote_features (p->hci_handle); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 387 | } |
| 388 | |
| 389 | /* read page 1 - on rmt feature event for buffer reasons */ |
| 390 | return; |
| 391 | } |
| 392 | } |
| 393 | } |
| 394 | |
| 395 | |
| 396 | /******************************************************************************* |
| 397 | ** |
| 398 | ** Function btm_acl_report_role_change |
| 399 | ** |
| 400 | ** Description This function is called when the local device is deemed |
| 401 | ** to be down. It notifies L2CAP of the failure. |
| 402 | ** |
| 403 | ** Returns void |
| 404 | ** |
| 405 | *******************************************************************************/ |
| 406 | void btm_acl_report_role_change (UINT8 hci_status, BD_ADDR bda) |
| 407 | { |
| 408 | tBTM_ROLE_SWITCH_CMPL ref_data; |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 409 | BTM_TRACE_DEBUG ("btm_acl_report_role_change"); |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 410 | if (btm_cb.devcb.p_switch_role_cb |
| 411 | && (bda && (0 == memcmp(btm_cb.devcb.switch_role_ref_data.remote_bd_addr, bda, BD_ADDR_LEN)))) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 412 | { |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 413 | memcpy (&ref_data, &btm_cb.devcb.switch_role_ref_data, sizeof(tBTM_ROLE_SWITCH_CMPL)); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 414 | ref_data.hci_status = hci_status; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 415 | (*btm_cb.devcb.p_switch_role_cb)(&ref_data); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 416 | memset (&btm_cb.devcb.switch_role_ref_data, 0, sizeof(tBTM_ROLE_SWITCH_CMPL)); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 417 | btm_cb.devcb.p_switch_role_cb = NULL; |
| 418 | } |
| 419 | } |
| 420 | |
| 421 | /******************************************************************************* |
| 422 | ** |
| 423 | ** Function btm_acl_removed |
| 424 | ** |
| 425 | ** Description This function is called by L2CAP when an ACL connection |
| 426 | ** is removed. Since only L2CAP creates ACL links, we use |
| 427 | ** the L2CAP link index as our index into the control blocks. |
| 428 | ** |
| 429 | ** Returns void |
| 430 | ** |
| 431 | *******************************************************************************/ |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 432 | void btm_acl_removed (BD_ADDR bda, tBT_TRANSPORT transport) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 433 | { |
| 434 | tACL_CONN *p; |
| 435 | #if (defined(BTM_BUSY_LEVEL_CHANGE_INCLUDED) && BTM_BUSY_LEVEL_CHANGE_INCLUDED == TRUE) |
| 436 | tBTM_BL_EVENT_DATA evt_data; |
| 437 | #endif |
| 438 | #if (defined BLE_INCLUDED && BLE_INCLUDED == TRUE) |
| 439 | tBTM_SEC_DEV_REC *p_dev_rec=NULL; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 440 | #endif |
| 441 | |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 442 | BTM_TRACE_DEBUG ("btm_acl_removed"); |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 443 | p = btm_bda_to_acl(bda, transport); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 444 | if (p != (tACL_CONN *)NULL) |
| 445 | { |
| 446 | p->in_use = FALSE; |
| 447 | |
| 448 | /* if the disconnected channel has a pending role switch, clear it now */ |
| 449 | btm_acl_report_role_change(HCI_ERR_NO_CONNECTION, bda); |
| 450 | |
| 451 | /* Only notify if link up has had a chance to be issued */ |
| 452 | if (p->link_up_issued) |
| 453 | { |
| 454 | p->link_up_issued = FALSE; |
| 455 | |
| 456 | /* If anyone cares, tell him database changed */ |
| 457 | #if (defined(BTM_BUSY_LEVEL_CHANGE_INCLUDED) && BTM_BUSY_LEVEL_CHANGE_INCLUDED == TRUE) |
| 458 | if (btm_cb.p_bl_changed_cb) |
| 459 | { |
| 460 | evt_data.event = BTM_BL_DISCN_EVT; |
| 461 | evt_data.discn.p_bda = bda; |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 462 | #if BLE_INCLUDED == TRUE |
| 463 | evt_data.discn.handle = p->hci_handle; |
| 464 | evt_data.discn.transport = p->transport; |
| 465 | #endif |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 466 | (*btm_cb.p_bl_changed_cb)(&evt_data); |
| 467 | } |
| 468 | |
| 469 | btm_acl_update_busy_level (BTM_BLI_ACL_DOWN_EVT); |
| 470 | #else |
| 471 | if (btm_cb.p_acl_changed_cb) |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 472 | #if BLE_INCLUDED == TRUE |
| 473 | (*btm_cb.p_acl_changed_cb) (bda, NULL, NULL, NULL, FALSE, p->hci_handle, p->transport); |
| 474 | #else |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 475 | (*btm_cb.p_acl_changed_cb) (bda, NULL, NULL, NULL, FALSE); |
| 476 | #endif |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 477 | #endif |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 478 | } |
| 479 | |
| 480 | #if (defined BLE_INCLUDED && BLE_INCLUDED == TRUE) |
| 481 | |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 482 | BTM_TRACE_DEBUG ("acl hci_handle=%d transport=%d connectable_mode=0x%0x link_role=%d", |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 483 | p->hci_handle, |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 484 | p->transport, |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 485 | btm_cb.ble_ctr_cb.inq_var.connectable_mode, |
| 486 | p->link_role); |
| 487 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 488 | p_dev_rec = btm_find_dev(bda); |
| 489 | if ( p_dev_rec) |
| 490 | { |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 491 | BTM_TRACE_DEBUG("before update p_dev_rec->sec_flags=0x%x", p_dev_rec->sec_flags); |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 492 | if (p->transport == BT_TRANSPORT_LE) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 493 | { |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 494 | BTM_TRACE_DEBUG("LE link down"); |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 495 | p_dev_rec->sec_flags &= ~(BTM_SEC_LE_ENCRYPTED | BTM_SEC_ROLE_SWITCHED); |
| 496 | if ( (p_dev_rec->sec_flags & BTM_SEC_LE_LINK_KEY_KNOWN) == 0) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 497 | { |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 498 | BTM_TRACE_DEBUG("Not Bonded"); |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 499 | p_dev_rec->sec_flags &= ~(BTM_SEC_LE_LINK_KEY_AUTHED | BTM_SEC_LE_AUTHENTICATED); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 500 | } |
| 501 | else |
| 502 | { |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 503 | BTM_TRACE_DEBUG("Bonded"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 504 | } |
| 505 | } |
| 506 | else |
| 507 | { |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 508 | BTM_TRACE_DEBUG("Bletooth link down"); |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 509 | p_dev_rec->sec_flags &= ~(BTM_SEC_AUTHORIZED | BTM_SEC_AUTHENTICATED |
| 510 | | BTM_SEC_ENCRYPTED | BTM_SEC_ROLE_SWITCHED); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 511 | } |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 512 | BTM_TRACE_DEBUG("after update p_dev_rec->sec_flags=0x%x", p_dev_rec->sec_flags); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 513 | } |
| 514 | else |
| 515 | { |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 516 | BTM_TRACE_ERROR("Device not found"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 517 | |
| 518 | } |
| 519 | #endif |
| 520 | |
| 521 | return; |
| 522 | } |
| 523 | } |
| 524 | |
| 525 | |
| 526 | /******************************************************************************* |
| 527 | ** |
| 528 | ** Function btm_acl_device_down |
| 529 | ** |
| 530 | ** Description This function is called when the local device is deemed |
| 531 | ** to be down. It notifies L2CAP of the failure. |
| 532 | ** |
| 533 | ** Returns void |
| 534 | ** |
| 535 | *******************************************************************************/ |
| 536 | void btm_acl_device_down (void) |
| 537 | { |
| 538 | tACL_CONN *p = &btm_cb.acl_db[0]; |
| 539 | UINT16 xx; |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 540 | BTM_TRACE_DEBUG ("btm_acl_device_down"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 541 | for (xx = 0; xx < MAX_L2CAP_LINKS; xx++, p++) |
| 542 | { |
| 543 | if (p->in_use) |
| 544 | { |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 545 | BTM_TRACE_DEBUG ("hci_handle=%d HCI_ERR_HW_FAILURE ",p->hci_handle ); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 546 | l2c_link_hci_disc_comp (p->hci_handle, HCI_ERR_HW_FAILURE); |
| 547 | } |
| 548 | } |
| 549 | } |
| 550 | |
| 551 | #if (defined(BTM_BUSY_LEVEL_CHANGE_INCLUDED) && BTM_BUSY_LEVEL_CHANGE_INCLUDED == TRUE) |
| 552 | /******************************************************************************* |
| 553 | ** |
| 554 | ** Function btm_acl_update_busy_level |
| 555 | ** |
| 556 | ** Description This function is called to update the busy level of the system |
| 557 | ** . |
| 558 | ** |
| 559 | ** Returns void |
| 560 | ** |
| 561 | *******************************************************************************/ |
| 562 | void btm_acl_update_busy_level (tBTM_BLI_EVENT event) |
| 563 | { |
| 564 | tBTM_BL_UPDATE_DATA evt; |
| 565 | UINT8 busy_level; |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 566 | BTM_TRACE_DEBUG ("btm_acl_update_busy_level"); |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 567 | BOOLEAN old_inquiry_state = btm_cb.is_inquiry; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 568 | switch (event) |
| 569 | { |
| 570 | case BTM_BLI_ACL_UP_EVT: |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 571 | BTM_TRACE_DEBUG ("BTM_BLI_ACL_UP_EVT"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 572 | btm_cb.num_acl++; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 573 | break; |
| 574 | case BTM_BLI_ACL_DOWN_EVT: |
| 575 | if (btm_cb.num_acl) |
| 576 | { |
| 577 | btm_cb.num_acl--; |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 578 | BTM_TRACE_DEBUG ("BTM_BLI_ACL_DOWN_EVT", btm_cb.num_acl); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 579 | } |
| 580 | else |
| 581 | { |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 582 | BTM_TRACE_ERROR ("BTM_BLI_ACL_DOWN_EVT issued, but num_acl already zero !!!"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 583 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 584 | break; |
| 585 | case BTM_BLI_PAGE_EVT: |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 586 | BTM_TRACE_DEBUG ("BTM_BLI_PAGE_EVT"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 587 | btm_cb.is_paging = TRUE; |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 588 | evt.busy_level_flags= BTM_BL_PAGING_STARTED; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 589 | break; |
| 590 | case BTM_BLI_PAGE_DONE_EVT: |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 591 | BTM_TRACE_DEBUG ("BTM_BLI_PAGE_DONE_EVT"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 592 | btm_cb.is_paging = FALSE; |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 593 | evt.busy_level_flags = BTM_BL_PAGING_COMPLETE; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 594 | break; |
| 595 | case BTM_BLI_INQ_EVT: |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 596 | BTM_TRACE_DEBUG ("BTM_BLI_INQ_EVT"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 597 | btm_cb.is_inquiry = TRUE; |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 598 | evt.busy_level_flags = BTM_BL_INQUIRY_STARTED; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 599 | break; |
| 600 | case BTM_BLI_INQ_CANCEL_EVT: |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 601 | BTM_TRACE_DEBUG ("BTM_BLI_INQ_CANCEL_EVT"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 602 | btm_cb.is_inquiry = FALSE; |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 603 | evt.busy_level_flags = BTM_BL_INQUIRY_CANCELLED; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 604 | break; |
| 605 | case BTM_BLI_INQ_DONE_EVT: |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 606 | BTM_TRACE_DEBUG ("BTM_BLI_INQ_DONE_EVT"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 607 | btm_cb.is_inquiry = FALSE; |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 608 | evt.busy_level_flags = BTM_BL_INQUIRY_COMPLETE; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 609 | break; |
| 610 | } |
| 611 | |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 612 | if (btm_cb.is_paging || btm_cb.is_inquiry) |
| 613 | busy_level = 10; |
| 614 | else |
| 615 | busy_level = (UINT8)btm_cb.num_acl; |
| 616 | |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 617 | if ((busy_level != btm_cb.busy_level) ||(old_inquiry_state != btm_cb.is_inquiry)) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 618 | { |
| 619 | evt.event = BTM_BL_UPDATE_EVT; |
| 620 | evt.busy_level = busy_level; |
| 621 | btm_cb.busy_level = busy_level; |
| 622 | if (btm_cb.p_bl_changed_cb && (btm_cb.bl_evt_mask & BTM_BL_UPDATE_MASK)) |
| 623 | { |
| 624 | (*btm_cb.p_bl_changed_cb)((tBTM_BL_EVENT_DATA *)&evt); |
| 625 | } |
| 626 | } |
| 627 | } |
| 628 | #endif |
| 629 | |
| 630 | |
| 631 | /******************************************************************************* |
| 632 | ** |
| 633 | ** Function BTM_GetRole |
| 634 | ** |
| 635 | ** Description This function is called to get the role of the local device |
| 636 | ** for the ACL connection with the specified remote device |
| 637 | ** |
| 638 | ** Returns BTM_SUCCESS if connection exists. |
| 639 | ** BTM_UNKNOWN_ADDR if no active link with bd addr specified |
| 640 | ** |
| 641 | *******************************************************************************/ |
| 642 | tBTM_STATUS BTM_GetRole (BD_ADDR remote_bd_addr, UINT8 *p_role) |
| 643 | { |
| 644 | tACL_CONN *p; |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 645 | BTM_TRACE_DEBUG ("BTM_GetRole"); |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 646 | if ((p = btm_bda_to_acl(remote_bd_addr, BT_TRANSPORT_BR_EDR)) == NULL) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 647 | { |
| 648 | *p_role = BTM_ROLE_UNDEFINED; |
| 649 | return(BTM_UNKNOWN_ADDR); |
| 650 | } |
| 651 | |
| 652 | /* Get the current role */ |
| 653 | *p_role = p->link_role; |
| 654 | return(BTM_SUCCESS); |
| 655 | } |
| 656 | |
| 657 | |
| 658 | /******************************************************************************* |
| 659 | ** |
| 660 | ** Function BTM_SwitchRole |
| 661 | ** |
| 662 | ** Description This function is called to switch role between master and |
| 663 | ** slave. If role is already set it will do nothing. If the |
| 664 | ** command was initiated, the callback function is called upon |
| 665 | ** completion. |
| 666 | ** |
| 667 | ** Returns BTM_SUCCESS if already in specified role. |
| 668 | ** BTM_CMD_STARTED if command issued to controller. |
| 669 | ** BTM_NO_RESOURCES if couldn't allocate memory to issue command |
| 670 | ** BTM_UNKNOWN_ADDR if no active link with bd addr specified |
| 671 | ** BTM_MODE_UNSUPPORTED if local device does not support role switching |
| 672 | ** BTM_BUSY if the previous command is not completed |
| 673 | ** |
| 674 | *******************************************************************************/ |
| 675 | tBTM_STATUS BTM_SwitchRole (BD_ADDR remote_bd_addr, UINT8 new_role, tBTM_CMPL_CB *p_cb) |
| 676 | { |
| 677 | tACL_CONN *p; |
| 678 | tBTM_SEC_DEV_REC *p_dev_rec = NULL; |
| 679 | #if BTM_SCO_INCLUDED == TRUE |
| 680 | BOOLEAN is_sco_active; |
| 681 | #endif |
| 682 | #if BTM_PWR_MGR_INCLUDED == TRUE |
| 683 | tBTM_STATUS status; |
| 684 | tBTM_PM_MODE pwr_mode; |
| 685 | tBTM_PM_PWR_MD settings; |
| 686 | #endif |
| 687 | #if (BT_USE_TRACES == TRUE) |
| 688 | BD_ADDR_PTR p_bda; |
| 689 | #endif |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 690 | BTM_TRACE_API ("BTM_SwitchRole BDA: %02x-%02x-%02x-%02x-%02x-%02x", |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 691 | remote_bd_addr[0], remote_bd_addr[1], remote_bd_addr[2], |
| 692 | remote_bd_addr[3], remote_bd_addr[4], remote_bd_addr[5]); |
| 693 | |
| 694 | /* Make sure the local device supports switching */ |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 695 | if (!(HCI_SWITCH_SUPPORTED(btm_cb.devcb.local_lmp_features[HCI_EXT_FEATURES_PAGE_0]))) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 696 | return(BTM_MODE_UNSUPPORTED); |
| 697 | |
| 698 | if (btm_cb.devcb.p_switch_role_cb && p_cb) |
| 699 | { |
| 700 | #if (BT_USE_TRACES == TRUE) |
| 701 | p_bda = btm_cb.devcb.switch_role_ref_data.remote_bd_addr; |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 702 | BTM_TRACE_DEBUG ("Role switch on other device is in progress 0x%02x%02x%02x%02x%02x%02x", |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 703 | p_bda[0], p_bda[1], p_bda[2], |
| 704 | p_bda[3], p_bda[4], p_bda[5]); |
| 705 | #endif |
| 706 | return(BTM_BUSY); |
| 707 | } |
| 708 | |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 709 | if ((p = btm_bda_to_acl(remote_bd_addr, BT_TRANSPORT_BR_EDR)) == NULL) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 710 | return(BTM_UNKNOWN_ADDR); |
| 711 | |
| 712 | /* Finished if already in desired role */ |
| 713 | if (p->link_role == new_role) |
| 714 | return(BTM_SUCCESS); |
| 715 | |
| 716 | #if BTM_SCO_INCLUDED == TRUE |
| 717 | /* Check if there is any SCO Active on this BD Address */ |
| 718 | is_sco_active = btm_is_sco_active_by_bdaddr(remote_bd_addr); |
| 719 | |
| 720 | if (is_sco_active == TRUE) |
| 721 | return(BTM_NO_RESOURCES); |
| 722 | #endif |
| 723 | |
| 724 | /* Ignore role switch request if the previous request was not completed */ |
| 725 | if (p->switch_role_state != BTM_ACL_SWKEY_STATE_IDLE) |
| 726 | { |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 727 | BTM_TRACE_DEBUG ("BTM_SwitchRole busy: %d", |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 728 | p->switch_role_state); |
| 729 | return(BTM_BUSY); |
| 730 | } |
| 731 | |
| 732 | /* Cannot switch role while parked or sniffing */ |
| 733 | #if BTM_PWR_MGR_INCLUDED == FALSE |
| 734 | if (p->mode == HCI_MODE_PARK) |
| 735 | { |
| 736 | if (!btsnd_hcic_exit_park_mode (p->hci_handle)) |
| 737 | return(BTM_NO_RESOURCES); |
| 738 | |
| 739 | p->switch_role_state = BTM_ACL_SWKEY_STATE_MODE_CHANGE; |
| 740 | } |
| 741 | else if (p->mode == HCI_MODE_SNIFF) |
| 742 | { |
| 743 | if (!btsnd_hcic_exit_sniff_mode (p->hci_handle)) |
| 744 | return(BTM_NO_RESOURCES); |
| 745 | |
| 746 | p->switch_role_state = BTM_ACL_SWKEY_STATE_MODE_CHANGE; |
| 747 | } |
| 748 | #else /* power manager is in use */ |
| 749 | |
| 750 | if ((status = BTM_ReadPowerMode(p->remote_addr, &pwr_mode)) != BTM_SUCCESS) |
| 751 | return(status); |
| 752 | |
| 753 | /* Wake up the link if in sniff or park before attempting switch */ |
| 754 | if (pwr_mode == BTM_PM_MD_PARK || pwr_mode == BTM_PM_MD_SNIFF) |
| 755 | { |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 756 | memset( (void*)&settings, 0, sizeof(settings)); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 757 | settings.mode = BTM_PM_MD_ACTIVE; |
| 758 | status = BTM_SetPowerMode (BTM_PM_SET_ONLY_ID, p->remote_addr, &settings); |
| 759 | if (status != BTM_CMD_STARTED) |
| 760 | return(BTM_WRONG_MODE); |
| 761 | |
| 762 | p->switch_role_state = BTM_ACL_SWKEY_STATE_MODE_CHANGE; |
| 763 | } |
| 764 | #endif |
| 765 | /* some devices do not support switch while encryption is on */ |
| 766 | else |
| 767 | { |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 768 | p_dev_rec = btm_find_dev (remote_bd_addr); |
| 769 | if ((p_dev_rec != NULL) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 770 | && ((p_dev_rec->sec_flags & BTM_SEC_ENCRYPTED) != 0) |
| 771 | && !BTM_EPR_AVAILABLE(p)) |
| 772 | { |
| 773 | /* bypass turning off encryption if change link key is already doing it */ |
| 774 | if (p->encrypt_state != BTM_ACL_ENCRYPT_STATE_ENCRYPT_OFF) |
| 775 | { |
| 776 | if (!btsnd_hcic_set_conn_encrypt (p->hci_handle, FALSE)) |
| 777 | return(BTM_NO_RESOURCES); |
| 778 | else |
| 779 | p->encrypt_state = BTM_ACL_ENCRYPT_STATE_ENCRYPT_OFF; |
| 780 | } |
| 781 | |
| 782 | p->switch_role_state = BTM_ACL_SWKEY_STATE_ENCRYPTION_OFF; |
| 783 | } |
| 784 | else |
| 785 | { |
| 786 | if (!btsnd_hcic_switch_role (remote_bd_addr, new_role)) |
| 787 | return(BTM_NO_RESOURCES); |
| 788 | |
| 789 | p->switch_role_state = BTM_ACL_SWKEY_STATE_IN_PROGRESS; |
| 790 | |
| 791 | #if BTM_DISC_DURING_RS == TRUE |
| 792 | if (p_dev_rec) |
| 793 | p_dev_rec->rs_disc_pending = BTM_SEC_RS_PENDING; |
| 794 | #endif |
| 795 | } |
| 796 | } |
| 797 | |
| 798 | /* Initialize return structure in case request fails */ |
| 799 | if (p_cb) |
| 800 | { |
| 801 | memcpy (btm_cb.devcb.switch_role_ref_data.remote_bd_addr, remote_bd_addr, |
| 802 | BD_ADDR_LEN); |
| 803 | btm_cb.devcb.switch_role_ref_data.role = new_role; |
| 804 | /* initialized to an error code */ |
| 805 | btm_cb.devcb.switch_role_ref_data.hci_status = HCI_ERR_UNSUPPORTED_VALUE; |
| 806 | btm_cb.devcb.p_switch_role_cb = p_cb; |
| 807 | } |
| 808 | return(BTM_CMD_STARTED); |
| 809 | } |
| 810 | |
| 811 | /******************************************************************************* |
| 812 | ** |
| 813 | ** Function BTM_ChangeLinkKey |
| 814 | ** |
| 815 | ** Description This function is called to change the link key of the |
| 816 | ** connection. |
| 817 | ** |
| 818 | ** Returns BTM_CMD_STARTED if command issued to controller. |
| 819 | ** BTM_NO_RESOURCES if couldn't allocate memory to issue command |
| 820 | ** BTM_UNKNOWN_ADDR if no active link with bd addr specified |
| 821 | ** BTM_BUSY if the previous command is not completed |
| 822 | ** |
| 823 | *******************************************************************************/ |
| 824 | tBTM_STATUS BTM_ChangeLinkKey (BD_ADDR remote_bd_addr, tBTM_CMPL_CB *p_cb) |
| 825 | { |
| 826 | tACL_CONN *p; |
| 827 | tBTM_SEC_DEV_REC *p_dev_rec = NULL; |
| 828 | #if BTM_PWR_MGR_INCLUDED == TRUE |
| 829 | tBTM_STATUS status; |
| 830 | tBTM_PM_MODE pwr_mode; |
| 831 | tBTM_PM_PWR_MD settings; |
| 832 | #endif |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 833 | BTM_TRACE_DEBUG ("BTM_ChangeLinkKey"); |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 834 | if ((p = btm_bda_to_acl(remote_bd_addr, BT_TRANSPORT_BR_EDR)) == NULL) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 835 | return(BTM_UNKNOWN_ADDR); |
| 836 | |
| 837 | /* Ignore change link key request if the previsous request has not completed */ |
| 838 | if (p->change_key_state != BTM_ACL_SWKEY_STATE_IDLE) |
| 839 | { |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 840 | BTM_TRACE_DEBUG ("Link key change request declined since the previous request" |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 841 | " for this device has not completed "); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 842 | return(BTM_BUSY); |
| 843 | } |
| 844 | |
| 845 | memset (&btm_cb.devcb.chg_link_key_ref_data, 0, sizeof(tBTM_CHANGE_KEY_CMPL)); |
| 846 | |
| 847 | /* Cannot change key while parked */ |
| 848 | #if BTM_PWR_MGR_INCLUDED == FALSE |
| 849 | if (p->mode == HCI_MODE_PARK) |
| 850 | { |
| 851 | if (!btsnd_hcic_exit_park_mode (p->hci_handle)) |
| 852 | return(BTM_NO_RESOURCES); |
| 853 | |
| 854 | p->change_key_state = BTM_ACL_SWKEY_STATE_MODE_CHANGE; |
| 855 | } |
| 856 | #else /* power manager is in use */ |
| 857 | |
| 858 | |
| 859 | if ((status = BTM_ReadPowerMode(p->remote_addr, &pwr_mode)) != BTM_SUCCESS) |
| 860 | return(status); |
| 861 | |
| 862 | /* Wake up the link if in park before attempting to change link keys */ |
| 863 | if (pwr_mode == BTM_PM_MD_PARK) |
| 864 | { |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 865 | memset( (void*)&settings, 0, sizeof(settings)); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 866 | settings.mode = BTM_PM_MD_ACTIVE; |
| 867 | status = BTM_SetPowerMode (BTM_PM_SET_ONLY_ID, p->remote_addr, &settings); |
| 868 | if (status != BTM_CMD_STARTED) |
| 869 | return(BTM_WRONG_MODE); |
| 870 | |
| 871 | p->change_key_state = BTM_ACL_SWKEY_STATE_MODE_CHANGE; |
| 872 | } |
| 873 | #endif |
| 874 | /* some devices do not support change of link key while encryption is on */ |
| 875 | else if (((p_dev_rec = btm_find_dev (remote_bd_addr)) != NULL) |
| 876 | && ((p_dev_rec->sec_flags & BTM_SEC_ENCRYPTED) != 0) && !BTM_EPR_AVAILABLE(p)) |
| 877 | { |
| 878 | /* bypass turning off encryption if switch role is already doing it */ |
| 879 | if (p->encrypt_state != BTM_ACL_ENCRYPT_STATE_ENCRYPT_OFF) |
| 880 | { |
| 881 | if (!btsnd_hcic_set_conn_encrypt (p->hci_handle, FALSE)) |
| 882 | return(BTM_NO_RESOURCES); |
| 883 | else |
| 884 | p->encrypt_state = BTM_ACL_ENCRYPT_STATE_ENCRYPT_OFF; |
| 885 | } |
| 886 | |
| 887 | p->change_key_state = BTM_ACL_SWKEY_STATE_ENCRYPTION_OFF; |
| 888 | } |
| 889 | else /* Ok to initiate change of link key */ |
| 890 | { |
| 891 | if (!btsnd_hcic_change_link_key (p->hci_handle)) |
| 892 | return(BTM_NO_RESOURCES); |
| 893 | |
| 894 | p->change_key_state = BTM_ACL_SWKEY_STATE_IN_PROGRESS; |
| 895 | } |
| 896 | |
| 897 | /* Initialize return structure in case request fails */ |
| 898 | memcpy (btm_cb.devcb.chg_link_key_ref_data.remote_bd_addr, remote_bd_addr, |
| 899 | BD_ADDR_LEN); |
| 900 | btm_cb.devcb.p_chg_link_key_cb = p_cb; |
| 901 | return(BTM_CMD_STARTED); |
| 902 | } |
| 903 | |
| 904 | /******************************************************************************* |
| 905 | ** |
| 906 | ** Function btm_acl_link_key_change |
| 907 | ** |
| 908 | ** Description This function is called to when a change link key event |
| 909 | ** is received. |
| 910 | ** |
| 911 | *******************************************************************************/ |
| 912 | void btm_acl_link_key_change (UINT16 handle, UINT8 status) |
| 913 | { |
| 914 | tBTM_CHANGE_KEY_CMPL *p_data; |
| 915 | tACL_CONN *p; |
| 916 | UINT8 xx; |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 917 | BTM_TRACE_DEBUG ("btm_acl_link_key_change"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 918 | /* Look up the connection by handle and set the current mode */ |
| 919 | xx = btm_handle_to_acl_index(handle); |
| 920 | |
| 921 | /* don't assume that we can never get a bad hci_handle */ |
| 922 | if (xx >= MAX_L2CAP_LINKS) |
| 923 | return; |
| 924 | |
| 925 | p_data = &btm_cb.devcb.chg_link_key_ref_data; |
| 926 | p = &btm_cb.acl_db[xx]; |
| 927 | p_data->hci_status = status; |
| 928 | |
| 929 | /* if switching state is switching we need to turn encryption on */ |
| 930 | /* if idle, we did not change encryption */ |
| 931 | if (p->change_key_state == BTM_ACL_SWKEY_STATE_SWITCHING) |
| 932 | { |
| 933 | /* Make sure there's not also a role switch going on before re-enabling */ |
| 934 | if (p->switch_role_state != BTM_ACL_SWKEY_STATE_SWITCHING) |
| 935 | { |
| 936 | if (btsnd_hcic_set_conn_encrypt (p->hci_handle, TRUE)) |
| 937 | { |
| 938 | p->encrypt_state = BTM_ACL_ENCRYPT_STATE_ENCRYPT_ON; |
| 939 | p->change_key_state = BTM_ACL_SWKEY_STATE_ENCRYPTION_ON; |
| 940 | return; |
| 941 | } |
| 942 | } |
| 943 | else /* Set the state and wait for change link key */ |
| 944 | { |
| 945 | p->change_key_state = BTM_ACL_SWKEY_STATE_ENCRYPTION_ON; |
| 946 | return; |
| 947 | } |
| 948 | } |
| 949 | |
| 950 | /* Set the switch_role_state to IDLE since the reply received from HCI */ |
| 951 | /* regardless of its result either success or failed. */ |
| 952 | if (p->change_key_state == BTM_ACL_SWKEY_STATE_IN_PROGRESS) |
| 953 | { |
| 954 | p->change_key_state = BTM_ACL_SWKEY_STATE_IDLE; |
| 955 | p->encrypt_state = BTM_ACL_ENCRYPT_STATE_IDLE; |
| 956 | } |
| 957 | |
| 958 | if (btm_cb.devcb.p_chg_link_key_cb) |
| 959 | { |
| 960 | (*btm_cb.devcb.p_chg_link_key_cb)((void *)p_data); |
| 961 | btm_cb.devcb.p_chg_link_key_cb = NULL; |
| 962 | } |
| 963 | |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 964 | BTM_TRACE_ERROR("Change Link Key Complete Event: Handle 0x%02x, HCI Status 0x%02x", |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 965 | handle, p_data->hci_status); |
| 966 | } |
| 967 | |
| 968 | /******************************************************************************* |
| 969 | ** |
| 970 | ** Function btm_acl_encrypt_change |
| 971 | ** |
| 972 | ** Description This function is when encryption of the connection is |
| 973 | ** completed by the LM. Checks to see if a role switch or |
| 974 | ** change of link key was active and initiates or continues |
| 975 | ** process if needed. |
| 976 | ** |
| 977 | ** Returns void |
| 978 | ** |
| 979 | *******************************************************************************/ |
| 980 | void btm_acl_encrypt_change (UINT16 handle, UINT8 status, UINT8 encr_enable) |
| 981 | { |
| 982 | tACL_CONN *p; |
| 983 | UINT8 xx; |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 984 | tBTM_SEC_DEV_REC *p_dev_rec; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 985 | #if (defined(BTM_BUSY_LEVEL_CHANGE_INCLUDED) && BTM_BUSY_LEVEL_CHANGE_INCLUDED == TRUE) |
| 986 | tBTM_BL_ROLE_CHG_DATA evt; |
| 987 | #endif |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 988 | |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 989 | BTM_TRACE_DEBUG ("btm_acl_encrypt_change handle=%d status=%d encr_enabl=%d", |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 990 | handle, status, encr_enable); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 991 | xx = btm_handle_to_acl_index(handle); |
| 992 | /* don't assume that we can never get a bad hci_handle */ |
| 993 | if (xx < MAX_L2CAP_LINKS) |
| 994 | p = &btm_cb.acl_db[xx]; |
| 995 | else |
| 996 | return; |
| 997 | |
| 998 | /* Process Role Switch if active */ |
| 999 | if (p->switch_role_state == BTM_ACL_SWKEY_STATE_ENCRYPTION_OFF) |
| 1000 | { |
| 1001 | /* if encryption turn off failed we still will try to switch role */ |
| 1002 | if (encr_enable) |
| 1003 | { |
| 1004 | p->switch_role_state = BTM_ACL_SWKEY_STATE_IDLE; |
| 1005 | p->encrypt_state = BTM_ACL_ENCRYPT_STATE_IDLE; |
| 1006 | } |
| 1007 | else |
| 1008 | { |
| 1009 | p->switch_role_state = BTM_ACL_SWKEY_STATE_SWITCHING; |
| 1010 | p->encrypt_state = BTM_ACL_ENCRYPT_STATE_TEMP_FUNC; |
| 1011 | } |
| 1012 | |
| 1013 | if (!btsnd_hcic_switch_role (p->remote_addr, (UINT8)!p->link_role)) |
| 1014 | { |
| 1015 | p->switch_role_state = BTM_ACL_SWKEY_STATE_IDLE; |
| 1016 | p->encrypt_state = BTM_ACL_ENCRYPT_STATE_IDLE; |
| 1017 | btm_acl_report_role_change(btm_cb.devcb.switch_role_ref_data.hci_status, p->remote_addr); |
| 1018 | } |
| 1019 | #if BTM_DISC_DURING_RS == TRUE |
| 1020 | else |
| 1021 | { |
| 1022 | if ((p_dev_rec = btm_find_dev (p->remote_addr)) != NULL) |
| 1023 | p_dev_rec->rs_disc_pending = BTM_SEC_RS_PENDING; |
| 1024 | } |
| 1025 | #endif |
| 1026 | |
| 1027 | } |
| 1028 | /* Finished enabling Encryption after role switch */ |
| 1029 | else if (p->switch_role_state == BTM_ACL_SWKEY_STATE_ENCRYPTION_ON) |
| 1030 | { |
| 1031 | p->switch_role_state = BTM_ACL_SWKEY_STATE_IDLE; |
| 1032 | p->encrypt_state = BTM_ACL_ENCRYPT_STATE_IDLE; |
| 1033 | btm_acl_report_role_change(btm_cb.devcb.switch_role_ref_data.hci_status, p->remote_addr); |
| 1034 | |
| 1035 | #if (defined(BTM_BUSY_LEVEL_CHANGE_INCLUDED) && BTM_BUSY_LEVEL_CHANGE_INCLUDED == TRUE) |
| 1036 | /* if role change event is registered, report it now */ |
| 1037 | if (btm_cb.p_bl_changed_cb && (btm_cb.bl_evt_mask & BTM_BL_ROLE_CHG_MASK)) |
| 1038 | { |
| 1039 | evt.event = BTM_BL_ROLE_CHG_EVT; |
| 1040 | evt.new_role = btm_cb.devcb.switch_role_ref_data.role; |
| 1041 | evt.p_bda = btm_cb.devcb.switch_role_ref_data.remote_bd_addr; |
| 1042 | evt.hci_status = btm_cb.devcb.switch_role_ref_data.hci_status; |
| 1043 | (*btm_cb.p_bl_changed_cb)((tBTM_BL_EVENT_DATA *)&evt); |
| 1044 | |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1045 | BTM_TRACE_DEBUG("Role Switch Event: new_role 0x%02x, HCI Status 0x%02x, rs_st:%d", |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1046 | evt.new_role, evt.hci_status, p->switch_role_state); |
| 1047 | } |
| 1048 | #endif |
| 1049 | |
| 1050 | #if BTM_DISC_DURING_RS == TRUE |
| 1051 | /* If a disconnect is pending, issue it now that role switch has completed */ |
| 1052 | if ((p_dev_rec = btm_find_dev (p->remote_addr)) != NULL) |
| 1053 | { |
| 1054 | if (p_dev_rec->rs_disc_pending == BTM_SEC_DISC_PENDING) |
| 1055 | { |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1056 | BTM_TRACE_WARNING("btm_acl_encrypt_change -> Issuing delayed HCI_Disconnect!!!"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1057 | btsnd_hcic_disconnect(p_dev_rec->hci_handle, HCI_ERR_PEER_USER); |
| 1058 | } |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1059 | BTM_TRACE_ERROR("btm_acl_encrypt_change: tBTM_SEC_DEV:0x%x rs_disc_pending=%d", |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1060 | (UINT32)p_dev_rec, p_dev_rec->rs_disc_pending); |
| 1061 | p_dev_rec->rs_disc_pending = BTM_SEC_RS_NOT_PENDING; /* reset flag */ |
| 1062 | } |
| 1063 | #endif |
| 1064 | } |
| 1065 | |
| 1066 | |
| 1067 | /* Process Change Link Key if active */ |
| 1068 | if (p->change_key_state == BTM_ACL_SWKEY_STATE_ENCRYPTION_OFF) |
| 1069 | { |
| 1070 | /* if encryption turn off failed we still will try to change link key */ |
| 1071 | if (encr_enable) |
| 1072 | { |
| 1073 | p->change_key_state = BTM_ACL_SWKEY_STATE_IDLE; |
| 1074 | p->encrypt_state = BTM_ACL_ENCRYPT_STATE_IDLE; |
| 1075 | } |
| 1076 | else |
| 1077 | { |
| 1078 | p->encrypt_state = BTM_ACL_ENCRYPT_STATE_TEMP_FUNC; |
| 1079 | p->change_key_state = BTM_ACL_SWKEY_STATE_SWITCHING; |
| 1080 | } |
| 1081 | |
| 1082 | if (!btsnd_hcic_change_link_key (p->hci_handle)) |
| 1083 | { |
| 1084 | p->encrypt_state = BTM_ACL_ENCRYPT_STATE_IDLE; |
| 1085 | p->change_key_state = BTM_ACL_SWKEY_STATE_IDLE; |
| 1086 | if (btm_cb.devcb.p_chg_link_key_cb) |
| 1087 | { |
| 1088 | (*btm_cb.devcb.p_chg_link_key_cb)(&btm_cb.devcb.chg_link_key_ref_data); |
| 1089 | btm_cb.devcb.p_chg_link_key_cb = NULL; |
| 1090 | } |
| 1091 | } |
| 1092 | } |
| 1093 | /* Finished enabling Encryption after changing link key */ |
| 1094 | else if (p->change_key_state == BTM_ACL_SWKEY_STATE_ENCRYPTION_ON) |
| 1095 | { |
| 1096 | p->encrypt_state = BTM_ACL_ENCRYPT_STATE_IDLE; |
| 1097 | p->change_key_state = BTM_ACL_SWKEY_STATE_IDLE; |
| 1098 | if (btm_cb.devcb.p_chg_link_key_cb) |
| 1099 | { |
| 1100 | (*btm_cb.devcb.p_chg_link_key_cb)(&btm_cb.devcb.chg_link_key_ref_data); |
| 1101 | btm_cb.devcb.p_chg_link_key_cb = NULL; |
| 1102 | } |
| 1103 | } |
| 1104 | } |
| 1105 | /******************************************************************************* |
| 1106 | ** |
| 1107 | ** Function BTM_SetLinkPolicy |
| 1108 | ** |
| 1109 | ** Description Create and send HCI "Write Policy Set" command |
| 1110 | ** |
| 1111 | ** Returns status of the operation |
| 1112 | ** |
| 1113 | *******************************************************************************/ |
| 1114 | tBTM_STATUS BTM_SetLinkPolicy (BD_ADDR remote_bda, UINT16 *settings) |
| 1115 | { |
| 1116 | tACL_CONN *p; |
| 1117 | UINT8 *localFeatures = BTM_ReadLocalFeatures(); |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1118 | BTM_TRACE_DEBUG ("BTM_SetLinkPolicy"); |
| 1119 | /* BTM_TRACE_API ("BTM_SetLinkPolicy: requested settings: 0x%04x", *settings ); */ |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1120 | |
| 1121 | /* First, check if hold mode is supported */ |
| 1122 | if (*settings != HCI_DISABLE_ALL_LM_MODES) |
| 1123 | { |
| 1124 | if ( (*settings & HCI_ENABLE_MASTER_SLAVE_SWITCH) && (!HCI_SWITCH_SUPPORTED(localFeatures)) ) |
| 1125 | { |
| 1126 | *settings &= (~HCI_ENABLE_MASTER_SLAVE_SWITCH); |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1127 | BTM_TRACE_API ("BTM_SetLinkPolicy switch not supported (settings: 0x%04x)", *settings ); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1128 | } |
| 1129 | if ( (*settings & HCI_ENABLE_HOLD_MODE) && (!HCI_HOLD_MODE_SUPPORTED(localFeatures)) ) |
| 1130 | { |
| 1131 | *settings &= (~HCI_ENABLE_HOLD_MODE); |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1132 | BTM_TRACE_API ("BTM_SetLinkPolicy hold not supported (settings: 0x%04x)", *settings ); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1133 | } |
| 1134 | if ( (*settings & HCI_ENABLE_SNIFF_MODE) && (!HCI_SNIFF_MODE_SUPPORTED(localFeatures)) ) |
| 1135 | { |
| 1136 | *settings &= (~HCI_ENABLE_SNIFF_MODE); |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1137 | BTM_TRACE_API ("BTM_SetLinkPolicy sniff not supported (settings: 0x%04x)", *settings ); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1138 | } |
| 1139 | if ( (*settings & HCI_ENABLE_PARK_MODE) && (!HCI_PARK_MODE_SUPPORTED(localFeatures)) ) |
| 1140 | { |
| 1141 | *settings &= (~HCI_ENABLE_PARK_MODE); |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1142 | BTM_TRACE_API ("BTM_SetLinkPolicy park not supported (settings: 0x%04x)", *settings ); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1143 | } |
| 1144 | } |
| 1145 | |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1146 | if ((p = btm_bda_to_acl(remote_bda, BT_TRANSPORT_BR_EDR)) != NULL) |
| 1147 | return(btsnd_hcic_write_policy_set (p->hci_handle, *settings) ? BTM_CMD_STARTED : BTM_NO_RESOURCES); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1148 | |
| 1149 | /* If here, no BD Addr found */ |
| 1150 | return(BTM_UNKNOWN_ADDR); |
| 1151 | } |
| 1152 | |
| 1153 | /******************************************************************************* |
| 1154 | ** |
| 1155 | ** Function BTM_SetDefaultLinkPolicy |
| 1156 | ** |
| 1157 | ** Description Set the default value for HCI "Write Policy Set" command |
| 1158 | ** to use when an ACL link is created. |
| 1159 | ** |
| 1160 | ** Returns void |
| 1161 | ** |
| 1162 | *******************************************************************************/ |
| 1163 | void BTM_SetDefaultLinkPolicy (UINT16 settings) |
| 1164 | { |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1165 | UINT8 *localFeatures = BTM_ReadLocalFeatures(); |
| 1166 | |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1167 | BTM_TRACE_DEBUG("BTM_SetDefaultLinkPolicy setting:0x%04x", settings); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1168 | |
| 1169 | if((settings & HCI_ENABLE_MASTER_SLAVE_SWITCH) && (!HCI_SWITCH_SUPPORTED(localFeatures))) |
| 1170 | { |
| 1171 | settings &= ~HCI_ENABLE_MASTER_SLAVE_SWITCH; |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1172 | BTM_TRACE_DEBUG("BTM_SetDefaultLinkPolicy switch not supported (settings: 0x%04x)", settings); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1173 | } |
| 1174 | if ((settings & HCI_ENABLE_HOLD_MODE) && (!HCI_HOLD_MODE_SUPPORTED(localFeatures))) |
| 1175 | { |
| 1176 | settings &= ~HCI_ENABLE_HOLD_MODE; |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1177 | BTM_TRACE_DEBUG("BTM_SetDefaultLinkPolicy hold not supported (settings: 0x%04x)", settings); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1178 | } |
| 1179 | if ((settings & HCI_ENABLE_SNIFF_MODE) && (!HCI_SNIFF_MODE_SUPPORTED(localFeatures))) |
| 1180 | { |
| 1181 | settings &= ~HCI_ENABLE_SNIFF_MODE; |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1182 | BTM_TRACE_DEBUG("BTM_SetDefaultLinkPolicy sniff not supported (settings: 0x%04x)", settings); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1183 | } |
| 1184 | if ((settings & HCI_ENABLE_PARK_MODE) && (!HCI_PARK_MODE_SUPPORTED(localFeatures))) |
| 1185 | { |
| 1186 | settings &= ~HCI_ENABLE_PARK_MODE; |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1187 | BTM_TRACE_DEBUG("BTM_SetDefaultLinkPolicy park not supported (settings: 0x%04x)", settings); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1188 | } |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1189 | BTM_TRACE_DEBUG("Set DefaultLinkPolicy:0x%04x", settings); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1190 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1191 | btm_cb.btm_def_link_policy = settings; |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1192 | |
| 1193 | /* Set the default Link Policy of the controller */ |
| 1194 | btsnd_hcic_write_def_policy_set(settings); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1195 | } |
| 1196 | |
| 1197 | |
| 1198 | /******************************************************************************* |
| 1199 | ** |
| 1200 | ** Function BTM_ReadLinkPolicy |
| 1201 | ** |
| 1202 | ** Description This function is called to read the link policy settings. |
| 1203 | ** The address of link policy results are returned in the callback. |
| 1204 | ** (tBTM_LNK_POLICY_RESULTS) |
| 1205 | ** |
| 1206 | ** Returns status of the operation |
| 1207 | ** |
| 1208 | *******************************************************************************/ |
| 1209 | tBTM_STATUS BTM_ReadLinkPolicy (BD_ADDR remote_bda, tBTM_CMPL_CB *p_cb) |
| 1210 | { |
| 1211 | tACL_CONN *p; |
| 1212 | |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1213 | BTM_TRACE_API ("BTM_ReadLinkPolicy: RemBdAddr: %02x%02x%02x%02x%02x%02x", |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1214 | remote_bda[0], remote_bda[1], remote_bda[2], |
| 1215 | remote_bda[3], remote_bda[4], remote_bda[5]); |
| 1216 | |
| 1217 | /* If someone already waiting on the version, do not allow another */ |
| 1218 | if (btm_cb.devcb.p_rlinkp_cmpl_cb) |
| 1219 | return(BTM_BUSY); |
| 1220 | |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1221 | p = btm_bda_to_acl(remote_bda, BT_TRANSPORT_BR_EDR); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1222 | if (p != (tACL_CONN *)NULL) |
| 1223 | { |
| 1224 | btu_start_timer (&btm_cb.devcb.rlinkp_timer, BTU_TTYPE_BTM_ACL, BTM_DEV_REPLY_TIMEOUT); |
| 1225 | btm_cb.devcb.p_rlinkp_cmpl_cb = p_cb; |
| 1226 | |
| 1227 | if (!btsnd_hcic_read_policy_set (p->hci_handle)) |
| 1228 | { |
| 1229 | btu_stop_timer (&btm_cb.devcb.rlinkp_timer); |
| 1230 | btm_cb.devcb.p_rlinkp_cmpl_cb = NULL; |
| 1231 | return(BTM_NO_RESOURCES); |
| 1232 | } |
| 1233 | |
| 1234 | return(BTM_CMD_STARTED); |
| 1235 | } |
| 1236 | |
| 1237 | /* If here, no BD Addr found */ |
| 1238 | return(BTM_UNKNOWN_ADDR); |
| 1239 | } |
| 1240 | |
| 1241 | |
| 1242 | /******************************************************************************* |
| 1243 | ** |
| 1244 | ** Function btm_read_link_policy_complete |
| 1245 | ** |
| 1246 | ** Description This function is called when the command complete message |
| 1247 | ** is received from the HCI for the read local link policy request. |
| 1248 | ** |
| 1249 | ** Returns void |
| 1250 | ** |
| 1251 | *******************************************************************************/ |
| 1252 | void btm_read_link_policy_complete (UINT8 *p) |
| 1253 | { |
| 1254 | tBTM_CMPL_CB *p_cb = btm_cb.devcb.p_rlinkp_cmpl_cb; |
| 1255 | tBTM_LNK_POLICY_RESULTS lnkpol; |
| 1256 | UINT16 handle; |
| 1257 | tACL_CONN *p_acl_cb = &btm_cb.acl_db[0]; |
| 1258 | UINT16 index; |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1259 | BTM_TRACE_DEBUG ("btm_read_link_policy_complete"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1260 | btu_stop_timer (&btm_cb.devcb.rlinkp_timer); |
| 1261 | |
| 1262 | /* If there was a callback address for read local version, call it */ |
| 1263 | btm_cb.devcb.p_rlinkp_cmpl_cb = NULL; |
| 1264 | |
| 1265 | if (p_cb) |
| 1266 | { |
| 1267 | STREAM_TO_UINT8 (lnkpol.hci_status, p); |
| 1268 | |
| 1269 | if (lnkpol.hci_status == HCI_SUCCESS) |
| 1270 | { |
| 1271 | lnkpol.status = BTM_SUCCESS; |
| 1272 | |
| 1273 | STREAM_TO_UINT16 (handle, p); |
| 1274 | |
| 1275 | STREAM_TO_UINT16 (lnkpol.settings, p); |
| 1276 | |
| 1277 | /* Search through the list of active channels for the correct BD Addr */ |
| 1278 | for (index = 0; index < MAX_L2CAP_LINKS; index++, p_acl_cb++) |
| 1279 | { |
| 1280 | if ((p_acl_cb->in_use) && (handle == p_acl_cb->hci_handle)) |
| 1281 | { |
| 1282 | memcpy (lnkpol.rem_bda, p_acl_cb->remote_addr, BD_ADDR_LEN); |
| 1283 | break; |
| 1284 | } |
| 1285 | } |
| 1286 | } |
| 1287 | else |
| 1288 | lnkpol.status = BTM_ERR_PROCESSING; |
| 1289 | |
| 1290 | (*p_cb)(&lnkpol); |
| 1291 | } |
| 1292 | } |
| 1293 | |
| 1294 | |
| 1295 | /******************************************************************************* |
| 1296 | ** |
| 1297 | ** Function btm_read_remote_version_complete |
| 1298 | ** |
| 1299 | ** Description This function is called when the command complete message |
| 1300 | ** is received from the HCI for the remote version info. |
| 1301 | ** |
| 1302 | ** Returns void |
| 1303 | ** |
| 1304 | *******************************************************************************/ |
| 1305 | void btm_read_remote_version_complete (UINT8 *p) |
| 1306 | { |
| 1307 | tACL_CONN *p_acl_cb = &btm_cb.acl_db[0]; |
| 1308 | UINT8 status; |
| 1309 | UINT16 handle; |
| 1310 | int xx; |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1311 | BTM_TRACE_DEBUG ("btm_read_remote_version_complete"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1312 | STREAM_TO_UINT8 (status, p); |
| 1313 | if (status == HCI_SUCCESS) |
| 1314 | { |
| 1315 | STREAM_TO_UINT16 (handle, p); |
| 1316 | |
| 1317 | /* Look up the connection by handle and copy features */ |
| 1318 | for (xx = 0; xx < MAX_L2CAP_LINKS; xx++, p_acl_cb++) |
| 1319 | { |
| 1320 | if ((p_acl_cb->in_use) && (p_acl_cb->hci_handle == handle)) |
| 1321 | { |
| 1322 | STREAM_TO_UINT8 (p_acl_cb->lmp_version, p); |
| 1323 | STREAM_TO_UINT16 (p_acl_cb->manufacturer, p); |
| 1324 | STREAM_TO_UINT16 (p_acl_cb->lmp_subversion, p); |
| 1325 | break; |
| 1326 | } |
| 1327 | } |
| 1328 | } |
| 1329 | } |
| 1330 | |
| 1331 | |
| 1332 | /******************************************************************************* |
| 1333 | ** |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 1334 | ** Function btm_process_remote_ext_features |
| 1335 | ** |
| 1336 | ** Description Local function called to process all extended features pages |
| 1337 | ** read from a remote device. |
| 1338 | ** |
| 1339 | ** Returns void |
| 1340 | ** |
| 1341 | *******************************************************************************/ |
| 1342 | void btm_process_remote_ext_features (tACL_CONN *p_acl_cb, UINT8 num_read_pages) |
| 1343 | { |
| 1344 | UINT16 handle = p_acl_cb->hci_handle; |
| 1345 | tBTM_SEC_DEV_REC *p_dev_rec = btm_find_dev_by_handle (handle); |
| 1346 | UINT8 page_idx; |
| 1347 | |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1348 | BTM_TRACE_DEBUG ("btm_process_remote_ext_features"); |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 1349 | |
| 1350 | /* Make sure we have the record to save remote features information */ |
| 1351 | if (p_dev_rec == NULL) |
| 1352 | { |
| 1353 | /* Get a new device; might be doing dedicated bonding */ |
| 1354 | p_dev_rec = btm_find_or_alloc_dev (p_acl_cb->remote_addr); |
| 1355 | } |
| 1356 | |
| 1357 | p_acl_cb->num_read_pages = num_read_pages; |
| 1358 | p_dev_rec->num_read_pages = num_read_pages; |
| 1359 | |
| 1360 | /* Process the pages one by one */ |
| 1361 | for (page_idx = 0; page_idx < num_read_pages; page_idx++) |
| 1362 | { |
| 1363 | btm_process_remote_ext_features_page (p_acl_cb, p_dev_rec, page_idx); |
| 1364 | } |
| 1365 | } |
| 1366 | |
| 1367 | |
| 1368 | /******************************************************************************* |
| 1369 | ** |
| 1370 | ** Function btm_process_remote_ext_features_page |
| 1371 | ** |
| 1372 | ** Description Local function called to process the information located |
| 1373 | ** in the specific extended features page read from a remote device. |
| 1374 | ** |
| 1375 | ** Returns void |
| 1376 | ** |
| 1377 | *******************************************************************************/ |
| 1378 | void btm_process_remote_ext_features_page (tACL_CONN *p_acl_cb, tBTM_SEC_DEV_REC *p_dev_rec, |
| 1379 | UINT8 page_idx) |
| 1380 | { |
| 1381 | UINT16 handle; |
| 1382 | UINT8 req_pend; |
| 1383 | |
| 1384 | handle = p_acl_cb->hci_handle; |
| 1385 | |
| 1386 | memcpy (p_dev_rec->features[page_idx], p_acl_cb->peer_lmp_features[page_idx], |
| 1387 | HCI_FEATURE_BYTES_PER_PAGE); |
| 1388 | |
| 1389 | switch (page_idx) |
| 1390 | { |
| 1391 | /* Extended (Legacy) Page 0 */ |
| 1392 | case HCI_EXT_FEATURES_PAGE_0: |
| 1393 | /* Page 0 indicates Controller support for SSP */ |
| 1394 | if (btm_cb.security_mode < BTM_SEC_MODE_SP || |
| 1395 | !HCI_SIMPLE_PAIRING_SUPPORTED(p_dev_rec->features[HCI_EXT_FEATURES_PAGE_0])) |
| 1396 | { |
| 1397 | req_pend = (p_dev_rec->sm4 & BTM_SM4_REQ_PEND); |
| 1398 | p_dev_rec->sm4 = BTM_SM4_KNOWN; |
| 1399 | if (req_pend) |
| 1400 | { |
| 1401 | l2cu_resubmit_pending_sec_req (p_dev_rec->bd_addr); |
| 1402 | } |
| 1403 | } |
| 1404 | break; |
| 1405 | |
| 1406 | /* Extended Page 1 */ |
| 1407 | case HCI_EXT_FEATURES_PAGE_1: |
| 1408 | /* Page 1 indicates Host support for SSP and SC */ |
| 1409 | req_pend = (p_dev_rec->sm4 & BTM_SM4_REQ_PEND); |
| 1410 | |
| 1411 | if (btm_cb.security_mode == BTM_SEC_MODE_SP |
| 1412 | && HCI_SSP_HOST_SUPPORTED(p_dev_rec->features[HCI_EXT_FEATURES_PAGE_1]) |
| 1413 | && HCI_SIMPLE_PAIRING_SUPPORTED(p_dev_rec->features[HCI_EXT_FEATURES_PAGE_0])) |
| 1414 | { |
| 1415 | p_dev_rec->sm4 = BTM_SM4_TRUE; |
| 1416 | } |
| 1417 | else |
| 1418 | { |
| 1419 | p_dev_rec->sm4 = BTM_SM4_KNOWN; |
| 1420 | } |
| 1421 | |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1422 | BTM_TRACE_API ("ext_features_complt page_num:%d f[0]:x%02x, sm4:%x, pend:%d", |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 1423 | HCI_EXT_FEATURES_PAGE_1, *(p_dev_rec->features[HCI_EXT_FEATURES_PAGE_1]), |
| 1424 | p_dev_rec->sm4, req_pend); |
| 1425 | |
| 1426 | if (req_pend) |
| 1427 | l2cu_resubmit_pending_sec_req (p_dev_rec->bd_addr); |
| 1428 | |
| 1429 | break; |
| 1430 | |
| 1431 | /* Extended Page 2 */ |
| 1432 | case HCI_EXT_FEATURES_PAGE_2: |
| 1433 | /* Page 2 indicates Ping support*/ |
| 1434 | break; |
| 1435 | |
| 1436 | default: |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1437 | BTM_TRACE_ERROR("btm_process_remote_ext_features_page page=%d unexpected", page_idx); |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 1438 | break; |
| 1439 | } |
| 1440 | } |
| 1441 | |
| 1442 | |
| 1443 | /******************************************************************************* |
| 1444 | ** |
| 1445 | ** Function btm_read_remote_features |
| 1446 | ** |
| 1447 | ** Description Local function called to send a read remote supported features/ |
| 1448 | ** remote extended features page[0]. |
| 1449 | ** |
| 1450 | ** Returns void |
| 1451 | ** |
| 1452 | *******************************************************************************/ |
| 1453 | void btm_read_remote_features (UINT16 handle) |
| 1454 | { |
| 1455 | UINT8 acl_idx; |
| 1456 | tACL_CONN *p_acl_cb; |
| 1457 | |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1458 | BTM_TRACE_DEBUG("btm_read_remote_features() handle: %d", handle); |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 1459 | |
| 1460 | if ((acl_idx = btm_handle_to_acl_index(handle)) >= MAX_L2CAP_LINKS) |
| 1461 | { |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1462 | BTM_TRACE_ERROR("btm_read_remote_features handle=%d invalid", handle); |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 1463 | return; |
| 1464 | } |
| 1465 | |
| 1466 | p_acl_cb = &btm_cb.acl_db[acl_idx]; |
| 1467 | p_acl_cb->num_read_pages = 0; |
| 1468 | memset (p_acl_cb->peer_lmp_features, 0, sizeof(p_acl_cb->peer_lmp_features)); |
| 1469 | |
Zhihai Xu | 24c0f58 | 2013-04-16 17:58:43 -0700 | [diff] [blame] | 1470 | /* first send read remote supported features HCI command */ |
| 1471 | /* because we don't know whether the remote support extended feature command */ |
| 1472 | btsnd_hcic_rmt_features_req (handle); |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 1473 | } |
| 1474 | |
| 1475 | |
| 1476 | /******************************************************************************* |
| 1477 | ** |
| 1478 | ** Function btm_read_remote_ext_features |
| 1479 | ** |
| 1480 | ** Description Local function called to send a read remote extended features |
| 1481 | ** |
| 1482 | ** Returns void |
| 1483 | ** |
| 1484 | *******************************************************************************/ |
| 1485 | void btm_read_remote_ext_features (UINT16 handle, UINT8 page_number) |
| 1486 | { |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1487 | BTM_TRACE_DEBUG("btm_read_remote_ext_features() handle: %d page: %d", handle, page_number); |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 1488 | |
| 1489 | btsnd_hcic_rmt_ext_features(handle, page_number); |
| 1490 | } |
| 1491 | |
| 1492 | |
| 1493 | /******************************************************************************* |
| 1494 | ** |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1495 | ** Function btm_read_remote_features_complete |
| 1496 | ** |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 1497 | ** Description This function is called when the remote supported features |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1498 | ** complete event is received from the HCI. |
| 1499 | ** |
| 1500 | ** Returns void |
| 1501 | ** |
| 1502 | *******************************************************************************/ |
| 1503 | void btm_read_remote_features_complete (UINT8 *p) |
| 1504 | { |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 1505 | tACL_CONN *p_acl_cb; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1506 | UINT8 status; |
| 1507 | UINT16 handle; |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 1508 | UINT8 acl_idx; |
| 1509 | |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1510 | BTM_TRACE_DEBUG ("btm_read_remote_features_complete"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1511 | STREAM_TO_UINT8 (status, p); |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 1512 | |
| 1513 | if (status != HCI_SUCCESS) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1514 | { |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1515 | BTM_TRACE_ERROR ("btm_read_remote_features_complete failed (status 0x%02x)", status); |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 1516 | return; |
| 1517 | } |
| 1518 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1519 | STREAM_TO_UINT16 (handle, p); |
| 1520 | |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 1521 | if ((acl_idx = btm_handle_to_acl_index(handle)) >= MAX_L2CAP_LINKS) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1522 | { |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1523 | BTM_TRACE_ERROR("btm_read_remote_features_complete handle=%d invalid", handle); |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 1524 | return; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1525 | } |
| 1526 | |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 1527 | p_acl_cb = &btm_cb.acl_db[acl_idx]; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1528 | |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 1529 | /* Copy the received features page */ |
| 1530 | STREAM_TO_ARRAY(p_acl_cb->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0], p, |
| 1531 | HCI_FEATURE_BYTES_PER_PAGE); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1532 | |
Ganesh Ganapathi Batta | 9d140a9 | 2013-04-11 16:13:14 -0700 | [diff] [blame] | 1533 | if ((HCI_LMP_EXTENDED_SUPPORTED(p_acl_cb->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0])) && |
| 1534 | (HCI_READ_REMOTE_EXT_FEATURES_SUPPORTED(btm_cb.devcb.supported_cmds))) |
| 1535 | { |
| 1536 | /* if the remote controller has extended features and local controller supports |
| 1537 | ** HCI_Read_Remote_Extended_Features command then start reading these feature starting |
| 1538 | ** with extended features page 1 */ |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1539 | BTM_TRACE_DEBUG ("Start reading remote extended features"); |
Ganesh Ganapathi Batta | 9d140a9 | 2013-04-11 16:13:14 -0700 | [diff] [blame] | 1540 | btm_read_remote_ext_features(handle, HCI_EXT_FEATURES_PAGE_1); |
| 1541 | return; |
| 1542 | } |
| 1543 | |
| 1544 | /* Remote controller has no extended features. Process remote controller supported features |
| 1545 | (features page HCI_EXT_FEATURES_PAGE_0). */ |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 1546 | btm_process_remote_ext_features (p_acl_cb, 1); |
| 1547 | |
| 1548 | /* Continue with HCI connection establishment */ |
| 1549 | btm_establish_continue (p_acl_cb); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1550 | } |
| 1551 | |
| 1552 | /******************************************************************************* |
| 1553 | ** |
| 1554 | ** Function btm_read_remote_ext_features_complete |
| 1555 | ** |
| 1556 | ** Description This function is called when the remote extended features |
| 1557 | ** complete event is received from the HCI. |
| 1558 | ** |
| 1559 | ** Returns void |
| 1560 | ** |
| 1561 | *******************************************************************************/ |
| 1562 | void btm_read_remote_ext_features_complete (UINT8 *p) |
| 1563 | { |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 1564 | tACL_CONN *p_acl_cb; |
| 1565 | UINT8 status, page_num, max_page; |
| 1566 | UINT16 handle; |
| 1567 | UINT8 acl_idx; |
| 1568 | |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1569 | BTM_TRACE_DEBUG ("btm_read_remote_ext_features_complete"); |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 1570 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1571 | STREAM_TO_UINT8 (status, p); |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 1572 | STREAM_TO_UINT16 (handle, p); |
| 1573 | STREAM_TO_UINT8 (page_num, p); |
| 1574 | STREAM_TO_UINT8 (max_page, p); |
| 1575 | |
| 1576 | /* Validate parameters */ |
| 1577 | if ((acl_idx = btm_handle_to_acl_index(handle)) >= MAX_L2CAP_LINKS) |
| 1578 | { |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1579 | BTM_TRACE_ERROR("btm_read_remote_ext_features_complete handle=%d invalid", handle); |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 1580 | return; |
| 1581 | } |
| 1582 | |
| 1583 | if (max_page > HCI_EXT_FEATURES_PAGE_MAX) |
| 1584 | { |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1585 | BTM_TRACE_ERROR("btm_read_remote_ext_features_complete page=%d unknown", max_page); |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 1586 | return; |
| 1587 | } |
| 1588 | |
| 1589 | p_acl_cb = &btm_cb.acl_db[acl_idx]; |
| 1590 | |
| 1591 | /* Copy the received features page */ |
| 1592 | STREAM_TO_ARRAY(p_acl_cb->peer_lmp_features[page_num], p, HCI_FEATURE_BYTES_PER_PAGE); |
| 1593 | |
| 1594 | /* If there is the next remote features page and |
| 1595 | * we have space to keep this page data - read this page */ |
| 1596 | if ((page_num < max_page) && (page_num < HCI_EXT_FEATURES_PAGE_MAX)) |
| 1597 | { |
| 1598 | page_num++; |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1599 | BTM_TRACE_DEBUG("BTM reads next remote extended features page (%d)", page_num); |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 1600 | btm_read_remote_ext_features (handle, page_num); |
| 1601 | return; |
| 1602 | } |
| 1603 | |
| 1604 | /* Reading of remote feature pages is complete */ |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1605 | BTM_TRACE_DEBUG("BTM reached last remote extended features page (%d)", page_num); |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 1606 | |
| 1607 | /* Process the pages */ |
| 1608 | btm_process_remote_ext_features (p_acl_cb, (UINT8) (page_num + 1)); |
| 1609 | |
| 1610 | /* Continue with HCI connection establishment */ |
| 1611 | btm_establish_continue (p_acl_cb); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1612 | } |
| 1613 | |
| 1614 | /******************************************************************************* |
| 1615 | ** |
| 1616 | ** Function btm_read_remote_ext_features_failed |
| 1617 | ** |
| 1618 | ** Description This function is called when the remote extended features |
| 1619 | ** complete event returns a failed status. |
| 1620 | ** |
| 1621 | ** Returns void |
| 1622 | ** |
| 1623 | *******************************************************************************/ |
Ganesh Ganapathi Batta | 9d140a9 | 2013-04-11 16:13:14 -0700 | [diff] [blame] | 1624 | void btm_read_remote_ext_features_failed (UINT8 status, UINT16 handle) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1625 | { |
Ganesh Ganapathi Batta | 9d140a9 | 2013-04-11 16:13:14 -0700 | [diff] [blame] | 1626 | tACL_CONN *p_acl_cb; |
| 1627 | UINT8 acl_idx; |
| 1628 | |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1629 | BTM_TRACE_WARNING ("btm_read_remote_ext_features_failed (status 0x%02x) for handle %d", |
Ganesh Ganapathi Batta | 9d140a9 | 2013-04-11 16:13:14 -0700 | [diff] [blame] | 1630 | status, handle); |
| 1631 | |
| 1632 | if ((acl_idx = btm_handle_to_acl_index(handle)) >= MAX_L2CAP_LINKS) |
| 1633 | { |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1634 | BTM_TRACE_ERROR("btm_read_remote_ext_features_failed handle=%d invalid", handle); |
Ganesh Ganapathi Batta | 9d140a9 | 2013-04-11 16:13:14 -0700 | [diff] [blame] | 1635 | return; |
| 1636 | } |
| 1637 | |
| 1638 | p_acl_cb = &btm_cb.acl_db[acl_idx]; |
| 1639 | |
| 1640 | /* Process supported features only */ |
| 1641 | btm_process_remote_ext_features (p_acl_cb, 1); |
| 1642 | |
| 1643 | /* Continue HCI connection establishment */ |
| 1644 | btm_establish_continue (p_acl_cb); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1645 | } |
| 1646 | |
| 1647 | /******************************************************************************* |
| 1648 | ** |
| 1649 | ** Function btm_establish_continue |
| 1650 | ** |
| 1651 | ** Description This function is called when the command complete message |
| 1652 | ** is received from the HCI for the read local link policy request. |
| 1653 | ** |
| 1654 | ** Returns void |
| 1655 | ** |
| 1656 | *******************************************************************************/ |
| 1657 | static void btm_establish_continue (tACL_CONN *p_acl_cb) |
| 1658 | { |
| 1659 | #if (defined(BTM_BUSY_LEVEL_CHANGE_INCLUDED) && BTM_BUSY_LEVEL_CHANGE_INCLUDED == TRUE) |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1660 | tBTM_BL_EVENT_DATA evt_data; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1661 | #endif |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1662 | BTM_TRACE_DEBUG ("btm_establish_continue"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1663 | #if (!defined(BTM_BYPASS_EXTRA_ACL_SETUP) || BTM_BYPASS_EXTRA_ACL_SETUP == FALSE) |
| 1664 | #if (defined BLE_INCLUDED && BLE_INCLUDED == TRUE) |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1665 | if (p_acl_cb->transport == BT_TRANSPORT_BR_EDR) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1666 | #endif |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1667 | { |
| 1668 | /* For now there are a some devices that do not like sending */ |
| 1669 | /* commands events and data at the same time. */ |
| 1670 | /* Set the packet types to the default allowed by the device */ |
| 1671 | btm_set_packet_types (p_acl_cb, btm_cb.btm_acl_pkt_types_supported); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1672 | |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1673 | if (btm_cb.btm_def_link_policy) |
| 1674 | BTM_SetLinkPolicy (p_acl_cb->remote_addr, &btm_cb.btm_def_link_policy); |
| 1675 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1676 | #endif |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1677 | p_acl_cb->link_up_issued = TRUE; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1678 | |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1679 | /* If anyone cares, tell him database changed */ |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1680 | #if (defined(BTM_BUSY_LEVEL_CHANGE_INCLUDED) && BTM_BUSY_LEVEL_CHANGE_INCLUDED == TRUE) |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1681 | if (btm_cb.p_bl_changed_cb) |
| 1682 | { |
| 1683 | evt_data.event = BTM_BL_CONN_EVT; |
| 1684 | evt_data.conn.p_bda = p_acl_cb->remote_addr; |
| 1685 | evt_data.conn.p_bdn = p_acl_cb->remote_name; |
| 1686 | evt_data.conn.p_dc = p_acl_cb->remote_dc; |
| 1687 | evt_data.conn.p_features = p_acl_cb->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0]; |
| 1688 | #if BLE_INCLUDED == TRUE |
| 1689 | evt_data.conn.handle = p_acl_cb->hci_handle; |
| 1690 | evt_data.conn.transport = p_acl_cb->transport; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1691 | #endif |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1692 | |
| 1693 | (*btm_cb.p_bl_changed_cb)(&evt_data); |
| 1694 | } |
| 1695 | btm_acl_update_busy_level (BTM_BLI_ACL_UP_EVT); |
| 1696 | #else |
| 1697 | if (btm_cb.p_acl_changed_cb) |
| 1698 | #if BLE_INCLUDED == TRUE |
| 1699 | (*btm_cb.p_acl_changed_cb) (p_acl_cb->remote_addr, |
| 1700 | p_acl_cb->remote_dc, |
| 1701 | p_acl_cb->remote_name, |
| 1702 | p_acl_cb->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0], |
| 1703 | TRUE, |
| 1704 | p_acl_cb->hci_handle, |
| 1705 | p_acl_cb->transport); |
| 1706 | #else |
| 1707 | (*btm_cb.p_acl_changed_cb) (p_acl_cb->remote_addr, |
| 1708 | p_acl_cb->remote_dc, |
| 1709 | p_acl_cb->remote_name, |
| 1710 | p_acl_cb->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0], |
| 1711 | TRUE); |
| 1712 | #endif |
| 1713 | |
| 1714 | #endif |
| 1715 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1716 | } |
| 1717 | |
| 1718 | |
| 1719 | /******************************************************************************* |
| 1720 | ** |
| 1721 | ** Function BTM_SetDefaultLinkSuperTout |
| 1722 | ** |
| 1723 | ** Description Set the default value for HCI "Write Link Supervision Timeout" |
| 1724 | ** command to use when an ACL link is created. |
| 1725 | ** |
| 1726 | ** Returns void |
| 1727 | ** |
| 1728 | *******************************************************************************/ |
| 1729 | void BTM_SetDefaultLinkSuperTout (UINT16 timeout) |
| 1730 | { |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1731 | BTM_TRACE_DEBUG ("BTM_SetDefaultLinkSuperTout"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1732 | btm_cb.btm_def_link_super_tout = timeout; |
| 1733 | } |
| 1734 | |
| 1735 | /******************************************************************************* |
| 1736 | ** |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1737 | ** Function BTM_GetLinkSuperTout |
| 1738 | ** |
| 1739 | ** Description Read the link supervision timeout value of the connection |
| 1740 | ** |
| 1741 | ** Returns status of the operation |
| 1742 | ** |
| 1743 | *******************************************************************************/ |
| 1744 | tBTM_STATUS BTM_GetLinkSuperTout (BD_ADDR remote_bda, UINT16 *p_timeout) |
| 1745 | { |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1746 | tACL_CONN *p = btm_bda_to_acl(remote_bda, BT_TRANSPORT_BR_EDR); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1747 | |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1748 | BTM_TRACE_DEBUG ("BTM_GetLinkSuperTout"); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1749 | if (p != (tACL_CONN *)NULL) |
| 1750 | { |
| 1751 | *p_timeout = p->link_super_tout; |
| 1752 | return(BTM_SUCCESS); |
| 1753 | } |
| 1754 | /* If here, no BD Addr found */ |
| 1755 | return(BTM_UNKNOWN_ADDR); |
| 1756 | } |
| 1757 | |
| 1758 | |
| 1759 | /******************************************************************************* |
| 1760 | ** |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1761 | ** Function BTM_SetLinkSuperTout |
| 1762 | ** |
| 1763 | ** Description Create and send HCI "Write Link Supervision Timeout" command |
| 1764 | ** |
| 1765 | ** Returns status of the operation |
| 1766 | ** |
| 1767 | *******************************************************************************/ |
| 1768 | tBTM_STATUS BTM_SetLinkSuperTout (BD_ADDR remote_bda, UINT16 timeout) |
| 1769 | { |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1770 | tACL_CONN *p = btm_bda_to_acl(remote_bda, BT_TRANSPORT_BR_EDR); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1771 | |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1772 | BTM_TRACE_DEBUG ("BTM_SetLinkSuperTout"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1773 | if (p != (tACL_CONN *)NULL) |
| 1774 | { |
| 1775 | p->link_super_tout = timeout; |
| 1776 | |
| 1777 | /* Only send if current role is Master; 2.0 spec requires this */ |
| 1778 | if (p->link_role == BTM_ROLE_MASTER) |
| 1779 | { |
| 1780 | if (!btsnd_hcic_write_link_super_tout (LOCAL_BR_EDR_CONTROLLER_ID, |
| 1781 | p->hci_handle, timeout)) |
| 1782 | return(BTM_NO_RESOURCES); |
| 1783 | |
| 1784 | return(BTM_CMD_STARTED); |
| 1785 | } |
| 1786 | else |
| 1787 | return(BTM_SUCCESS); |
| 1788 | } |
| 1789 | |
| 1790 | /* If here, no BD Addr found */ |
| 1791 | return(BTM_UNKNOWN_ADDR); |
| 1792 | } |
| 1793 | |
| 1794 | /******************************************************************************* |
| 1795 | ** |
| 1796 | ** Function BTM_RegForLstoEvt |
| 1797 | ** |
| 1798 | ** Description register for the HCI "Link Supervision Timeout Change" event |
| 1799 | ** |
| 1800 | ** Returns void |
| 1801 | ** |
| 1802 | *******************************************************************************/ |
| 1803 | void BTM_RegForLstoEvt (tBTM_LSTO_CBACK *p_cback) |
| 1804 | { |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1805 | BTM_TRACE_DEBUG ("BTM_RegForLstoEvt"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1806 | btm_cb.p_lsto_cback = p_cback; |
| 1807 | } |
| 1808 | |
| 1809 | /******************************************************************************* |
| 1810 | ** |
| 1811 | ** Function btm_proc_lsto_evt |
| 1812 | ** |
| 1813 | ** Description process the HCI "Link Supervision Timeout Change" event |
| 1814 | ** |
| 1815 | ** Returns void |
| 1816 | ** |
| 1817 | *******************************************************************************/ |
| 1818 | void btm_proc_lsto_evt(UINT16 handle, UINT16 timeout) |
| 1819 | { |
| 1820 | UINT8 xx; |
| 1821 | |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1822 | BTM_TRACE_DEBUG ("btm_proc_lsto_evt"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1823 | if (btm_cb.p_lsto_cback) |
| 1824 | { |
| 1825 | /* Look up the connection by handle and set the current mode */ |
| 1826 | xx = btm_handle_to_acl_index(handle); |
| 1827 | |
| 1828 | /* don't assume that we can never get a bad hci_handle */ |
| 1829 | if (xx < MAX_L2CAP_LINKS) |
| 1830 | { |
| 1831 | (*btm_cb.p_lsto_cback)(btm_cb.acl_db[xx].remote_addr, timeout); |
| 1832 | } |
| 1833 | } |
| 1834 | } |
| 1835 | |
| 1836 | #if BTM_PWR_MGR_INCLUDED == FALSE |
| 1837 | /******************************************************************************* |
| 1838 | ** |
| 1839 | ** Function BTM_SetHoldMode |
| 1840 | ** |
| 1841 | ** Description This function is called to set a connection into hold mode. |
| 1842 | ** A check is made if the connection is in sniff or park mode, |
| 1843 | ** and if yes, the hold mode is ignored. |
| 1844 | ** |
| 1845 | ** Returns status of the operation |
| 1846 | ** |
| 1847 | *******************************************************************************/ |
| 1848 | tBTM_STATUS BTM_SetHoldMode (BD_ADDR remote_bda, UINT16 min_interval, UINT16 max_interval) |
| 1849 | { |
| 1850 | tACL_CONN *p; |
| 1851 | |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1852 | BTM_TRACE_DEBUG ("BTM_SetHoldMode"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1853 | /* First, check if hold mode is supported */ |
| 1854 | if (!HCI_HOLD_MODE_SUPPORTED(BTM_ReadLocalFeatures())) |
| 1855 | return(BTM_MODE_UNSUPPORTED); |
| 1856 | |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1857 | p = btm_bda_to_acl(remote_bda, BT_TRANSPORT_BR_EDR); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1858 | if (p != (tACL_CONN *)NULL) |
| 1859 | { |
| 1860 | /* If the connection is in park or sniff mode, forget about holding it */ |
| 1861 | if (p->mode != BTM_ACL_MODE_NORMAL) |
| 1862 | return(BTM_SUCCESS); |
| 1863 | |
| 1864 | if (!btsnd_hcic_hold_mode (p->hci_handle, max_interval, min_interval)) |
| 1865 | return(BTM_NO_RESOURCES); |
| 1866 | |
| 1867 | return(BTM_CMD_STARTED); |
| 1868 | } |
| 1869 | |
| 1870 | /* If here, no BD Addr found */ |
| 1871 | return(BTM_UNKNOWN_ADDR); |
| 1872 | } |
| 1873 | |
| 1874 | |
| 1875 | /******************************************************************************* |
| 1876 | ** |
| 1877 | ** Function BTM_SetSniffMode |
| 1878 | ** |
| 1879 | ** Description This function is called to set a connection into sniff mode. |
| 1880 | ** A check is made if the connection is already in sniff or park |
| 1881 | ** mode, and if yes, the sniff mode is ignored. |
| 1882 | ** |
| 1883 | ** Returns status of the operation |
| 1884 | ** |
| 1885 | *******************************************************************************/ |
| 1886 | tBTM_STATUS BTM_SetSniffMode (BD_ADDR remote_bda, UINT16 min_period, UINT16 max_period, |
| 1887 | UINT16 attempt, UINT16 timeout) |
| 1888 | { |
| 1889 | tACL_CONN *p; |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1890 | BTM_TRACE_DEBUG ("BTM_SetSniffMode"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1891 | /* First, check if sniff mode is supported */ |
| 1892 | if (!HCI_SNIFF_MODE_SUPPORTED(BTM_ReadLocalFeatures())) |
| 1893 | return(BTM_MODE_UNSUPPORTED); |
| 1894 | |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1895 | p = btm_bda_to_acl(remote_bda, BT_TRANSPORT_BR_EDR); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1896 | if (p != (tACL_CONN *)NULL) |
| 1897 | { |
| 1898 | /* If the connection is in park mode, forget about sniffing it */ |
| 1899 | if (p->mode != BTM_ACL_MODE_NORMAL) |
| 1900 | return(BTM_WRONG_MODE); |
| 1901 | |
| 1902 | if (!btsnd_hcic_sniff_mode (p->hci_handle, max_period, |
| 1903 | min_period, attempt, timeout)) |
| 1904 | return(BTM_NO_RESOURCES); |
| 1905 | |
| 1906 | return(BTM_CMD_STARTED); |
| 1907 | } |
| 1908 | |
| 1909 | /* If here, no BD Addr found */ |
| 1910 | return(BTM_UNKNOWN_ADDR); |
| 1911 | } |
| 1912 | |
| 1913 | |
| 1914 | |
| 1915 | |
| 1916 | /******************************************************************************* |
| 1917 | ** |
| 1918 | ** Function BTM_CancelSniffMode |
| 1919 | ** |
| 1920 | ** Description This function is called to put a connection out of sniff mode. |
| 1921 | ** A check is made if the connection is already in sniff mode, |
| 1922 | ** and if not, the cancel sniff mode is ignored. |
| 1923 | ** |
| 1924 | ** Returns status of the operation |
| 1925 | ** |
| 1926 | *******************************************************************************/ |
| 1927 | tBTM_STATUS BTM_CancelSniffMode (BD_ADDR remote_bda) |
| 1928 | { |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1929 | tACL_CONN *p = btm_bda_to_acl(remote_bda, BT_TRANSPORT_BR_EDR); |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1930 | BTM_TRACE_DEBUG ("BTM_CancelSniffMode "); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1931 | if (p == (tACL_CONN *)NULL) |
| 1932 | return(BTM_UNKNOWN_ADDR); |
| 1933 | |
| 1934 | /* If the connection is not in sniff mode, cannot cancel */ |
| 1935 | if (p->mode != BTM_ACL_MODE_SNIFF) |
| 1936 | return(BTM_WRONG_MODE); |
| 1937 | |
| 1938 | if (!btsnd_hcic_exit_sniff_mode (p->hci_handle)) |
| 1939 | return(BTM_NO_RESOURCES); |
| 1940 | |
| 1941 | return(BTM_CMD_STARTED); |
| 1942 | } |
| 1943 | |
| 1944 | |
| 1945 | /******************************************************************************* |
| 1946 | ** |
| 1947 | ** Function BTM_SetParkMode |
| 1948 | ** |
| 1949 | ** Description This function is called to set a connection into park mode. |
| 1950 | ** A check is made if the connection is already in sniff or park |
| 1951 | ** mode, and if yes, the park mode is ignored. |
| 1952 | ** |
| 1953 | ** Returns status of the operation |
| 1954 | ** |
| 1955 | *******************************************************************************/ |
| 1956 | tBTM_STATUS BTM_SetParkMode (BD_ADDR remote_bda, UINT16 beacon_min_period, UINT16 beacon_max_period) |
| 1957 | { |
| 1958 | tACL_CONN *p; |
| 1959 | |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1960 | BTM_TRACE_DEBUG ("BTM_SetParkMode"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1961 | /* First, check if park mode is supported */ |
| 1962 | if (!HCI_PARK_MODE_SUPPORTED(BTM_ReadLocalFeatures())) |
| 1963 | return(BTM_MODE_UNSUPPORTED); |
| 1964 | |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1965 | p = btm_bda_to_acl(remote_bda, BT_TRANSPORT_BR_EDR); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1966 | if (p != (tACL_CONN *)NULL) |
| 1967 | { |
| 1968 | /* If the connection is in sniff mode, forget about parking it */ |
| 1969 | if (p->mode != BTM_ACL_MODE_NORMAL) |
| 1970 | return(BTM_WRONG_MODE); |
| 1971 | |
| 1972 | /* no park mode if SCO exists -- CR#1982, 1.1 errata 1124 |
| 1973 | command status event should be returned /w error code 0x0C "Command Disallowed" |
| 1974 | Let LM do this. |
| 1975 | */ |
| 1976 | if (!btsnd_hcic_park_mode (p->hci_handle, |
| 1977 | beacon_max_period, beacon_min_period)) |
| 1978 | return(BTM_NO_RESOURCES); |
| 1979 | |
| 1980 | return(BTM_CMD_STARTED); |
| 1981 | } |
| 1982 | |
| 1983 | /* If here, no BD Addr found */ |
| 1984 | return(BTM_UNKNOWN_ADDR); |
| 1985 | } |
| 1986 | |
| 1987 | /******************************************************************************* |
| 1988 | ** |
| 1989 | ** Function BTM_CancelParkMode |
| 1990 | ** |
| 1991 | ** Description This function is called to put a connection out of park mode. |
| 1992 | ** A check is made if the connection is already in park mode, |
| 1993 | ** and if not, the cancel sniff mode is ignored. |
| 1994 | ** |
| 1995 | ** Returns status of the operation |
| 1996 | ** |
| 1997 | *******************************************************************************/ |
| 1998 | tBTM_STATUS BTM_CancelParkMode (BD_ADDR remote_bda) |
| 1999 | { |
| 2000 | tACL_CONN *p; |
| 2001 | |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 2002 | BTM_TRACE_DEBUG ("BTM_CancelParkMode"); |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2003 | p = btm_bda_to_acl(remote_bda, BT_TRANSPORT_BR_EDR); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2004 | if (p != (tACL_CONN *)NULL) |
| 2005 | { |
| 2006 | /* If the connection is not in park mode, cannot cancel */ |
| 2007 | if (p->mode != BTM_ACL_MODE_PARK) |
| 2008 | return(BTM_WRONG_MODE); |
| 2009 | |
| 2010 | if (!btsnd_hcic_exit_park_mode (p->hci_handle)) |
| 2011 | return(BTM_NO_RESOURCES); |
| 2012 | |
| 2013 | return(BTM_CMD_STARTED); |
| 2014 | } |
| 2015 | |
| 2016 | /* If here, no BD Addr found */ |
| 2017 | return(BTM_UNKNOWN_ADDR); |
| 2018 | } |
| 2019 | #endif /* BTM_PWR_MGR_INCLUDED == FALSE */ |
| 2020 | |
| 2021 | |
| 2022 | /******************************************************************************* |
| 2023 | ** |
| 2024 | ** Function BTM_SetPacketTypes |
| 2025 | ** |
| 2026 | ** Description This function is set the packet types used for a specific |
| 2027 | ** ACL connection, |
| 2028 | ** |
| 2029 | ** Returns status of the operation |
| 2030 | ** |
| 2031 | *******************************************************************************/ |
| 2032 | tBTM_STATUS BTM_SetPacketTypes (BD_ADDR remote_bda, UINT16 pkt_types) |
| 2033 | { |
| 2034 | tACL_CONN *p; |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 2035 | BTM_TRACE_DEBUG ("BTM_SetPacketTypes"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2036 | |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2037 | if ((p = btm_bda_to_acl(remote_bda, BT_TRANSPORT_BR_EDR)) != NULL) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2038 | return(btm_set_packet_types (p, pkt_types)); |
| 2039 | |
| 2040 | /* If here, no BD Addr found */ |
| 2041 | return(BTM_UNKNOWN_ADDR); |
| 2042 | } |
| 2043 | |
| 2044 | |
| 2045 | /******************************************************************************* |
| 2046 | ** |
| 2047 | ** Function BTM_ReadPacketTypes |
| 2048 | ** |
| 2049 | ** Description This function is set the packet types used for a specific |
| 2050 | ** ACL connection, |
| 2051 | ** |
| 2052 | ** Returns packet types supported for the connection, or 0 if no BD address |
| 2053 | ** |
| 2054 | *******************************************************************************/ |
| 2055 | UINT16 BTM_ReadPacketTypes (BD_ADDR remote_bda) |
| 2056 | { |
| 2057 | tACL_CONN *p; |
| 2058 | |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 2059 | BTM_TRACE_DEBUG ("BTM_ReadPacketTypes"); |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2060 | p = btm_bda_to_acl(remote_bda, BT_TRANSPORT_BR_EDR); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2061 | if (p != (tACL_CONN *)NULL) |
| 2062 | { |
| 2063 | return(p->pkt_types_mask); |
| 2064 | } |
| 2065 | |
| 2066 | /* If here, no BD Addr found */ |
| 2067 | return(0); |
| 2068 | } |
| 2069 | |
| 2070 | |
| 2071 | /******************************************************************************* |
| 2072 | ** |
| 2073 | ** Function BTM_ReadAclMode |
| 2074 | ** |
| 2075 | ** Description This returns the current mode for a specific |
| 2076 | ** ACL connection. |
| 2077 | ** |
| 2078 | ** Input Param remote_bda - device address of desired ACL connection |
| 2079 | ** |
| 2080 | ** Output Param p_mode - address where the current mode is copied into. |
| 2081 | ** BTM_ACL_MODE_NORMAL |
| 2082 | ** BTM_ACL_MODE_HOLD |
| 2083 | ** BTM_ACL_MODE_SNIFF |
| 2084 | ** BTM_ACL_MODE_PARK |
| 2085 | ** (valid only if return code is BTM_SUCCESS) |
| 2086 | ** |
| 2087 | ** Returns BTM_SUCCESS if successful, |
| 2088 | ** BTM_UNKNOWN_ADDR if bd addr is not active or bad |
| 2089 | ** |
| 2090 | *******************************************************************************/ |
| 2091 | #if BTM_PWR_MGR_INCLUDED == FALSE |
| 2092 | tBTM_STATUS BTM_ReadAclMode (BD_ADDR remote_bda, UINT8 *p_mode) |
| 2093 | { |
| 2094 | tACL_CONN *p; |
| 2095 | |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 2096 | BTM_TRACE_API ("BTM_ReadAclMode: RemBdAddr: %02x%02x%02x%02x%02x%02x", |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2097 | remote_bda[0], remote_bda[1], remote_bda[2], |
| 2098 | remote_bda[3], remote_bda[4], remote_bda[5]); |
| 2099 | |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2100 | p = btm_bda_to_acl(remote_bda, BT_TRANSPORT_BR_EDR); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2101 | if (p != (tACL_CONN *)NULL) |
| 2102 | { |
| 2103 | *p_mode = p->mode; |
| 2104 | return(BTM_SUCCESS); |
| 2105 | } |
| 2106 | |
| 2107 | /* If here, no BD Addr found */ |
| 2108 | return(BTM_UNKNOWN_ADDR); |
| 2109 | } |
| 2110 | #endif /* BTM_PWR_MGR_INCLUDED == FALSE */ |
| 2111 | |
| 2112 | /******************************************************************************* |
| 2113 | ** |
| 2114 | ** Function BTM_ReadClockOffset |
| 2115 | ** |
| 2116 | ** Description This returns the clock offset for a specific |
| 2117 | ** ACL connection. |
| 2118 | ** |
| 2119 | ** Input Param remote_bda - device address of desired ACL connection |
| 2120 | ** |
| 2121 | ** Returns clock-offset or 0 if unknown |
| 2122 | ** |
| 2123 | *******************************************************************************/ |
| 2124 | UINT16 BTM_ReadClockOffset (BD_ADDR remote_bda) |
| 2125 | { |
| 2126 | tACL_CONN *p; |
| 2127 | |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 2128 | BTM_TRACE_API ("BTM_ReadClockOffset: RemBdAddr: %02x%02x%02x%02x%02x%02x", |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2129 | remote_bda[0], remote_bda[1], remote_bda[2], |
| 2130 | remote_bda[3], remote_bda[4], remote_bda[5]); |
| 2131 | |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2132 | if ( (p = btm_bda_to_acl(remote_bda, BT_TRANSPORT_BR_EDR)) != NULL) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2133 | return(p->clock_offset); |
| 2134 | |
| 2135 | /* If here, no BD Addr found */ |
| 2136 | return(0); |
| 2137 | } |
| 2138 | |
| 2139 | /******************************************************************************* |
| 2140 | ** |
| 2141 | ** Function BTM_IsAclConnectionUp |
| 2142 | ** |
| 2143 | ** Description This function is called to check if an ACL connection exists |
| 2144 | ** to a specific remote BD Address. |
| 2145 | ** |
| 2146 | ** Returns TRUE if connection is up, else FALSE. |
| 2147 | ** |
| 2148 | *******************************************************************************/ |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2149 | BOOLEAN BTM_IsAclConnectionUp (BD_ADDR remote_bda, tBT_TRANSPORT transport) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2150 | { |
| 2151 | tACL_CONN *p; |
| 2152 | |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 2153 | BTM_TRACE_API ("BTM_IsAclConnectionUp: RemBdAddr: %02x%02x%02x%02x%02x%02x", |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2154 | remote_bda[0], remote_bda[1], remote_bda[2], |
| 2155 | remote_bda[3], remote_bda[4], remote_bda[5]); |
| 2156 | |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2157 | p = btm_bda_to_acl(remote_bda, transport); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2158 | if (p != (tACL_CONN *)NULL) |
| 2159 | { |
| 2160 | return(TRUE); |
| 2161 | } |
| 2162 | |
| 2163 | /* If here, no BD Addr found */ |
| 2164 | return(FALSE); |
| 2165 | } |
| 2166 | |
| 2167 | /******************************************************************************* |
| 2168 | ** |
| 2169 | ** Function BTM_GetNumAclLinks |
| 2170 | ** |
| 2171 | ** Description This function is called to count the number of |
| 2172 | ** ACL links that are active. |
| 2173 | ** |
| 2174 | ** Returns UINT16 Number of active ACL links |
| 2175 | ** |
| 2176 | *******************************************************************************/ |
| 2177 | UINT16 BTM_GetNumAclLinks (void) |
| 2178 | { |
| 2179 | #if (defined(BTM_BUSY_LEVEL_CHANGE_INCLUDED) && BTM_BUSY_LEVEL_CHANGE_INCLUDED == TRUE) |
| 2180 | return(UINT16)btm_cb.num_acl; |
| 2181 | #else |
| 2182 | tACL_CONN *p = &btm_cb.acl_db[0]; |
| 2183 | UINT16 xx, yy; |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 2184 | BTM_TRACE_DEBUG ("BTM_GetNumAclLinks"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2185 | for (xx = yy = 0; xx < MAX_L2CAP_LINKS; xx++, p++) |
| 2186 | { |
| 2187 | if (p->in_use) |
| 2188 | yy++; |
| 2189 | } |
| 2190 | |
| 2191 | return(yy); |
| 2192 | #endif |
| 2193 | } |
| 2194 | |
| 2195 | /******************************************************************************* |
| 2196 | ** |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2197 | ** Function BTM_GetNumLeLinks |
| 2198 | ** |
| 2199 | ** Description This function is called to count the number of |
| 2200 | ** LE ACL links that are active. |
| 2201 | ** |
| 2202 | ** Returns UINT16 Number of active LE links |
| 2203 | ** |
| 2204 | *******************************************************************************/ |
| 2205 | UINT16 BTM_GetNumLeLinks (void) |
| 2206 | { |
| 2207 | UINT16 yy = 0; |
| 2208 | |
| 2209 | #if BLE_INCLUDED == TRUE |
| 2210 | tACL_CONN *p = &btm_cb.acl_db[0]; |
| 2211 | UINT16 xx; |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 2212 | BTM_TRACE_DEBUG ("BTM_GetNumLeLinks"); |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2213 | for (xx = yy = 0; xx < MAX_L2CAP_LINKS; xx++, p++) |
| 2214 | { |
| 2215 | if ((p->in_use) &&(p->transport == BT_TRANSPORT_LE)) |
| 2216 | yy++; |
| 2217 | } |
| 2218 | #endif |
| 2219 | |
| 2220 | return(yy); |
| 2221 | } |
| 2222 | |
| 2223 | /******************************************************************************* |
| 2224 | ** |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2225 | ** Function btm_get_acl_disc_reason_code |
| 2226 | ** |
| 2227 | ** Description This function is called to get the disconnection reason code |
| 2228 | ** returned by the HCI at disconnection complete event. |
| 2229 | ** |
| 2230 | ** Returns TRUE if connection is up, else FALSE. |
| 2231 | ** |
| 2232 | *******************************************************************************/ |
| 2233 | UINT16 btm_get_acl_disc_reason_code (void) |
| 2234 | { |
| 2235 | UINT8 res = btm_cb.acl_disc_reason; |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 2236 | BTM_TRACE_DEBUG ("btm_get_acl_disc_reason_code"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2237 | return(res); |
| 2238 | } |
| 2239 | |
| 2240 | |
| 2241 | /******************************************************************************* |
| 2242 | ** |
| 2243 | ** Function BTM_GetHCIConnHandle |
| 2244 | ** |
| 2245 | ** Description This function is called to get the handle for an ACL connection |
| 2246 | ** to a specific remote BD Address. |
| 2247 | ** |
| 2248 | ** Returns the handle of the connection, or 0xFFFF if none. |
| 2249 | ** |
| 2250 | *******************************************************************************/ |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2251 | UINT16 BTM_GetHCIConnHandle (BD_ADDR remote_bda, tBT_TRANSPORT transport) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2252 | { |
| 2253 | tACL_CONN *p; |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 2254 | BTM_TRACE_DEBUG ("BTM_GetHCIConnHandle"); |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2255 | p = btm_bda_to_acl(remote_bda, transport); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2256 | if (p != (tACL_CONN *)NULL) |
| 2257 | { |
| 2258 | return(p->hci_handle); |
| 2259 | } |
| 2260 | |
| 2261 | /* If here, no BD Addr found */ |
| 2262 | return(0xFFFF); |
| 2263 | } |
| 2264 | |
| 2265 | #if BTM_PWR_MGR_INCLUDED == FALSE |
| 2266 | /******************************************************************************* |
| 2267 | ** |
| 2268 | ** Function btm_process_mode_change |
| 2269 | ** |
| 2270 | ** Description This function is called when an HCI mode change event occurs. |
| 2271 | ** |
| 2272 | ** Input Parms hci_status - status of the event (HCI_SUCCESS if no errors) |
| 2273 | ** hci_handle - connection handle associated with the change |
| 2274 | ** mode - HCI_MODE_ACTIVE, HCI_MODE_HOLD, HCI_MODE_SNIFF, or HCI_MODE_PARK |
| 2275 | ** interval - number of baseband slots (meaning depends on mode) |
| 2276 | ** |
| 2277 | ** Returns void |
| 2278 | ** |
| 2279 | *******************************************************************************/ |
| 2280 | void btm_process_mode_change (UINT8 hci_status, UINT16 hci_handle, UINT8 mode, UINT16 interval) |
| 2281 | { |
| 2282 | tACL_CONN *p; |
| 2283 | UINT8 xx; |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 2284 | BTM_TRACE_DEBUG ("btm_process_mode_change"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2285 | if (hci_status != HCI_SUCCESS) |
| 2286 | { |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 2287 | BTM_TRACE_WARNING ("BTM: HCI Mode Change Error Status: 0x%02x", hci_status); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2288 | } |
| 2289 | |
| 2290 | /* Look up the connection by handle and set the current mode */ |
| 2291 | xx = btm_handle_to_acl_index(hci_handle); |
| 2292 | |
| 2293 | /* don't assume that we can never get a bad hci_handle */ |
| 2294 | if (xx >= MAX_L2CAP_LINKS) |
| 2295 | return; |
| 2296 | |
| 2297 | p = &btm_cb.acl_db[xx]; |
| 2298 | |
| 2299 | /* If status is not success mode does not mean anything */ |
| 2300 | if (hci_status == HCI_SUCCESS) |
| 2301 | p->mode = mode; |
| 2302 | |
| 2303 | /* If mode change was because of an active role switch or change link key */ |
| 2304 | btm_cont_rswitch_or_chglinkkey(p, btm_find_dev(p->remote_addr), hci_status); |
| 2305 | } |
| 2306 | #endif /* BTM_PWR_MGR_INCLUDED == FALSE */ |
| 2307 | |
| 2308 | /******************************************************************************* |
| 2309 | ** |
| 2310 | ** Function btm_process_clk_off_comp_evt |
| 2311 | ** |
| 2312 | ** Description This function is called when clock offset command completes. |
| 2313 | ** |
| 2314 | ** Input Parms hci_handle - connection handle associated with the change |
| 2315 | ** clock offset |
| 2316 | ** |
| 2317 | ** Returns void |
| 2318 | ** |
| 2319 | *******************************************************************************/ |
| 2320 | void btm_process_clk_off_comp_evt (UINT16 hci_handle, UINT16 clock_offset) |
| 2321 | { |
| 2322 | UINT8 xx; |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 2323 | BTM_TRACE_DEBUG ("btm_process_clk_off_comp_evt"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2324 | /* Look up the connection by handle and set the current mode */ |
| 2325 | if ((xx = btm_handle_to_acl_index(hci_handle)) < MAX_L2CAP_LINKS) |
| 2326 | btm_cb.acl_db[xx].clock_offset = clock_offset; |
| 2327 | } |
| 2328 | |
| 2329 | /******************************************************************************* |
| 2330 | ** |
| 2331 | ** Function btm_acl_role_changed |
| 2332 | ** |
| 2333 | ** Description This function is called whan a link's master/slave role change |
| 2334 | ** event or command status event (with error) is received. |
| 2335 | ** It updates the link control block, and calls |
| 2336 | ** the registered callback with status and role (if registered). |
| 2337 | ** |
| 2338 | ** Returns void |
| 2339 | ** |
| 2340 | *******************************************************************************/ |
| 2341 | void btm_acl_role_changed (UINT8 hci_status, BD_ADDR bd_addr, UINT8 new_role) |
| 2342 | { |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 2343 | UINT8 *p_bda = (bd_addr) ? bd_addr : |
| 2344 | btm_cb.devcb.switch_role_ref_data.remote_bd_addr; |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2345 | tACL_CONN *p = btm_bda_to_acl(p_bda, BT_TRANSPORT_BR_EDR); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2346 | tBTM_ROLE_SWITCH_CMPL *p_data = &btm_cb.devcb.switch_role_ref_data; |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 2347 | tBTM_SEC_DEV_REC *p_dev_rec; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2348 | #if (defined(BTM_BUSY_LEVEL_CHANGE_INCLUDED) && BTM_BUSY_LEVEL_CHANGE_INCLUDED == TRUE) |
| 2349 | tBTM_BL_ROLE_CHG_DATA evt; |
| 2350 | #endif |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 2351 | |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 2352 | BTM_TRACE_DEBUG ("btm_acl_role_changed"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2353 | /* Ignore any stray events */ |
| 2354 | if (p == NULL) |
| 2355 | { |
| 2356 | /* it could be a failure */ |
| 2357 | if (hci_status != HCI_SUCCESS) |
| 2358 | btm_acl_report_role_change(hci_status, bd_addr); |
| 2359 | return; |
| 2360 | } |
| 2361 | |
| 2362 | p_data->hci_status = hci_status; |
| 2363 | |
| 2364 | if (hci_status == HCI_SUCCESS) |
| 2365 | { |
| 2366 | p_data->role = new_role; |
| 2367 | memcpy(p_data->remote_bd_addr, p_bda, BD_ADDR_LEN); |
| 2368 | |
| 2369 | /* Update cached value */ |
| 2370 | p->link_role = new_role; |
Zhihai Xu | a934f01 | 2013-10-07 15:11:22 -0700 | [diff] [blame] | 2371 | btm_save_remote_device_role(p_bda, new_role); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2372 | /* Reload LSTO: link supervision timeout is reset in the LM after a role switch */ |
| 2373 | if (new_role == BTM_ROLE_MASTER) |
| 2374 | { |
| 2375 | BTM_SetLinkSuperTout (p->remote_addr, p->link_super_tout); |
| 2376 | } |
| 2377 | } |
| 2378 | else |
| 2379 | { |
| 2380 | /* so the BTM_BL_ROLE_CHG_EVT uses the old role */ |
| 2381 | new_role = p->link_role; |
| 2382 | } |
| 2383 | |
| 2384 | /* Check if any SCO req is pending for role change */ |
| 2385 | btm_sco_chk_pend_rolechange (p->hci_handle); |
| 2386 | |
| 2387 | /* if switching state is switching we need to turn encryption on */ |
| 2388 | /* if idle, we did not change encryption */ |
| 2389 | if (p->switch_role_state == BTM_ACL_SWKEY_STATE_SWITCHING) |
| 2390 | { |
| 2391 | /* Make sure there's not also a change link key going on before re-enabling */ |
| 2392 | if (p->change_key_state != BTM_ACL_SWKEY_STATE_SWITCHING) |
| 2393 | { |
| 2394 | if (btsnd_hcic_set_conn_encrypt (p->hci_handle, TRUE)) |
| 2395 | { |
| 2396 | p->encrypt_state = BTM_ACL_ENCRYPT_STATE_ENCRYPT_ON; |
| 2397 | p->switch_role_state = BTM_ACL_SWKEY_STATE_ENCRYPTION_ON; |
| 2398 | return; |
| 2399 | } |
| 2400 | } |
| 2401 | else /* Set the state and wait for change link key */ |
| 2402 | { |
| 2403 | p->switch_role_state = BTM_ACL_SWKEY_STATE_ENCRYPTION_ON; |
| 2404 | return; |
| 2405 | } |
| 2406 | } |
| 2407 | |
| 2408 | /* Set the switch_role_state to IDLE since the reply received from HCI */ |
| 2409 | /* regardless of its result either success or failed. */ |
| 2410 | if (p->switch_role_state == BTM_ACL_SWKEY_STATE_IN_PROGRESS) |
| 2411 | { |
| 2412 | p->switch_role_state = BTM_ACL_SWKEY_STATE_IDLE; |
| 2413 | p->encrypt_state = BTM_ACL_ENCRYPT_STATE_IDLE; |
| 2414 | } |
| 2415 | |
| 2416 | /* if role switch complete is needed, report it now */ |
| 2417 | btm_acl_report_role_change(hci_status, bd_addr); |
| 2418 | |
| 2419 | #if (defined(BTM_BUSY_LEVEL_CHANGE_INCLUDED) && BTM_BUSY_LEVEL_CHANGE_INCLUDED == TRUE) |
| 2420 | /* if role change event is registered, report it now */ |
| 2421 | if (btm_cb.p_bl_changed_cb && (btm_cb.bl_evt_mask & BTM_BL_ROLE_CHG_MASK)) |
| 2422 | { |
| 2423 | evt.event = BTM_BL_ROLE_CHG_EVT; |
| 2424 | evt.new_role = new_role; |
| 2425 | evt.p_bda = p_bda; |
| 2426 | evt.hci_status = hci_status; |
| 2427 | (*btm_cb.p_bl_changed_cb)((tBTM_BL_EVENT_DATA *)&evt); |
| 2428 | } |
| 2429 | |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 2430 | BTM_TRACE_DEBUG("Role Switch Event: new_role 0x%02x, HCI Status 0x%02x, rs_st:%d", |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2431 | p_data->role, p_data->hci_status, p->switch_role_state); |
| 2432 | #endif |
| 2433 | |
| 2434 | #if BTM_DISC_DURING_RS == TRUE |
| 2435 | /* If a disconnect is pending, issue it now that role switch has completed */ |
| 2436 | if ((p_dev_rec = btm_find_dev (p_bda)) != NULL) |
| 2437 | { |
| 2438 | if (p_dev_rec->rs_disc_pending == BTM_SEC_DISC_PENDING) |
| 2439 | { |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 2440 | BTM_TRACE_WARNING("btm_acl_role_changed -> Issuing delayed HCI_Disconnect!!!"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2441 | btsnd_hcic_disconnect(p_dev_rec->hci_handle, HCI_ERR_PEER_USER); |
| 2442 | } |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 2443 | BTM_TRACE_ERROR("tBTM_SEC_DEV:0x%x rs_disc_pending=%d", |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 2444 | (UINT32)p_dev_rec, p_dev_rec->rs_disc_pending); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2445 | p_dev_rec->rs_disc_pending = BTM_SEC_RS_NOT_PENDING; /* reset flag */ |
| 2446 | } |
| 2447 | |
| 2448 | #endif |
| 2449 | |
| 2450 | } |
| 2451 | |
| 2452 | #if (RFCOMM_INCLUDED==TRUE) |
| 2453 | /******************************************************************************* |
| 2454 | ** |
| 2455 | ** Function BTM_AllocateSCN |
| 2456 | ** |
| 2457 | ** Description Look through the Server Channel Numbers for a free one. |
| 2458 | ** |
| 2459 | ** Returns Allocated SCN number or 0 if none. |
| 2460 | ** |
| 2461 | *******************************************************************************/ |
| 2462 | |
| 2463 | UINT8 BTM_AllocateSCN(void) |
| 2464 | { |
| 2465 | UINT8 x; |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 2466 | BTM_TRACE_DEBUG ("BTM_AllocateSCN"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2467 | |
| 2468 | // stack reserves scn 1 for HFP, HSP we still do the correct way |
| 2469 | for (x = 1; x < BTM_MAX_SCN; x++) |
| 2470 | { |
| 2471 | if (!btm_cb.btm_scn[x]) |
| 2472 | { |
| 2473 | btm_cb.btm_scn[x] = TRUE; |
| 2474 | return(x+1); |
| 2475 | } |
| 2476 | } |
| 2477 | |
| 2478 | return(0); /* No free ports */ |
| 2479 | } |
| 2480 | |
| 2481 | /******************************************************************************* |
| 2482 | ** |
| 2483 | ** Function BTM_TryAllocateSCN |
| 2484 | ** |
| 2485 | ** Description Try to allocate a fixed server channel |
| 2486 | ** |
| 2487 | ** Returns Returns TRUE if server channel was available |
| 2488 | ** |
| 2489 | *******************************************************************************/ |
| 2490 | |
| 2491 | BOOLEAN BTM_TryAllocateSCN(UINT8 scn) |
| 2492 | { |
| 2493 | UINT8 x; |
| 2494 | |
| 2495 | /* Make sure we don't exceed max port range. |
| 2496 | * Stack reserves scn 1 for HFP, HSP we still do the correct way. |
| 2497 | */ |
| 2498 | if ( (scn>=BTM_MAX_SCN) || (scn == 1) ) |
| 2499 | return FALSE; |
| 2500 | |
| 2501 | /* check if this port is available */ |
| 2502 | if (!btm_cb.btm_scn[scn-1]) |
| 2503 | { |
| 2504 | btm_cb.btm_scn[scn-1] = TRUE; |
| 2505 | return TRUE; |
| 2506 | } |
| 2507 | |
| 2508 | return (FALSE); /* Port was busy */ |
| 2509 | } |
| 2510 | |
| 2511 | /******************************************************************************* |
| 2512 | ** |
| 2513 | ** Function BTM_FreeSCN |
| 2514 | ** |
| 2515 | ** Description Free the specified SCN. |
| 2516 | ** |
| 2517 | ** Returns TRUE or FALSE |
| 2518 | ** |
| 2519 | *******************************************************************************/ |
| 2520 | BOOLEAN BTM_FreeSCN(UINT8 scn) |
| 2521 | { |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 2522 | BTM_TRACE_DEBUG ("BTM_FreeSCN "); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2523 | if (scn <= BTM_MAX_SCN) |
| 2524 | { |
| 2525 | btm_cb.btm_scn[scn-1] = FALSE; |
| 2526 | return(TRUE); |
| 2527 | } |
| 2528 | else |
| 2529 | return(FALSE); /* Illegal SCN passed in */ |
| 2530 | } |
| 2531 | |
| 2532 | #else |
| 2533 | |
| 2534 | /* Make dummy functions for the RPC to link against */ |
| 2535 | UINT8 BTM_AllocateSCN(void) |
| 2536 | { |
| 2537 | return(0); |
| 2538 | } |
| 2539 | |
| 2540 | BOOLEAN BTM_FreeSCN(UINT8 scn) |
| 2541 | { |
| 2542 | return(FALSE); |
| 2543 | } |
| 2544 | |
| 2545 | #endif |
| 2546 | |
| 2547 | |
| 2548 | /******************************************************************************* |
| 2549 | ** |
| 2550 | ** Function btm_acl_timeout |
| 2551 | ** |
| 2552 | ** Description This function is called when a timer list entry expires. |
| 2553 | ** |
| 2554 | ** Returns void |
| 2555 | ** |
| 2556 | *******************************************************************************/ |
| 2557 | void btm_acl_timeout (TIMER_LIST_ENT *p_tle) |
| 2558 | { |
| 2559 | UINT32 timer_type = p_tle->param; |
| 2560 | |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 2561 | BTM_TRACE_DEBUG ("btm_acl_timeout"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2562 | if (timer_type == TT_DEV_RLNKP) |
| 2563 | { |
| 2564 | tBTM_CMPL_CB *p_cb = btm_cb.devcb.p_rlinkp_cmpl_cb; |
| 2565 | tBTM_LNK_POLICY_RESULTS lnkpol; |
| 2566 | |
| 2567 | lnkpol.status = BTM_ERR_PROCESSING; |
| 2568 | lnkpol.settings = 0; |
| 2569 | |
| 2570 | btm_cb.devcb.p_rlinkp_cmpl_cb = NULL; |
| 2571 | |
| 2572 | if (p_cb) |
| 2573 | (*p_cb)(&lnkpol); |
| 2574 | } |
| 2575 | } |
| 2576 | |
| 2577 | /******************************************************************************* |
| 2578 | ** |
| 2579 | ** Function btm_set_packet_types |
| 2580 | ** |
| 2581 | ** Description This function sets the packet types used for a specific |
| 2582 | ** ACL connection. It is called internally by btm_acl_created |
| 2583 | ** or by an application/profile by BTM_SetPacketTypes. |
| 2584 | ** |
| 2585 | ** Returns status of the operation |
| 2586 | ** |
| 2587 | *******************************************************************************/ |
| 2588 | tBTM_STATUS btm_set_packet_types (tACL_CONN *p, UINT16 pkt_types) |
| 2589 | { |
| 2590 | UINT16 temp_pkt_types; |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 2591 | BTM_TRACE_DEBUG ("btm_set_packet_types"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2592 | /* Save in the ACL control blocks, types that we support */ |
| 2593 | temp_pkt_types = (pkt_types & BTM_ACL_SUPPORTED_PKTS_MASK & |
| 2594 | btm_cb.btm_acl_pkt_types_supported); |
| 2595 | |
| 2596 | /* OR in any exception packet types if at least 2.0 version of spec */ |
| 2597 | if (btm_cb.devcb.local_version.hci_version >= HCI_PROTO_VERSION_2_0) |
| 2598 | { |
| 2599 | temp_pkt_types |= ((pkt_types & BTM_ACL_EXCEPTION_PKTS_MASK) | |
| 2600 | (btm_cb.btm_acl_pkt_types_supported & BTM_ACL_EXCEPTION_PKTS_MASK)); |
| 2601 | } |
| 2602 | else |
| 2603 | { |
| 2604 | temp_pkt_types &= (~BTM_ACL_EXCEPTION_PKTS_MASK); |
| 2605 | } |
| 2606 | |
| 2607 | /* Exclude packet types not supported by the peer */ |
| 2608 | btm_acl_chk_peer_pkt_type_support (p, &temp_pkt_types); |
| 2609 | |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 2610 | BTM_TRACE_DEBUG ("SetPacketType Mask -> 0x%04x", temp_pkt_types); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2611 | |
| 2612 | if (!btsnd_hcic_change_conn_type (p->hci_handle, temp_pkt_types)) |
| 2613 | { |
| 2614 | return(BTM_NO_RESOURCES); |
| 2615 | } |
| 2616 | |
| 2617 | p->pkt_types_mask = temp_pkt_types; |
| 2618 | |
| 2619 | return(BTM_CMD_STARTED); |
| 2620 | } |
| 2621 | |
| 2622 | /******************************************************************************* |
| 2623 | ** |
| 2624 | ** Function btm_get_max_packet_size |
| 2625 | ** |
| 2626 | ** Returns Returns maximum packet size that can be used for current |
| 2627 | ** connection, 0 if connection is not established |
| 2628 | ** |
| 2629 | *******************************************************************************/ |
| 2630 | UINT16 btm_get_max_packet_size (BD_ADDR addr) |
| 2631 | { |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2632 | tACL_CONN *p = btm_bda_to_acl(addr, BT_TRANSPORT_BR_EDR); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2633 | UINT16 pkt_types = 0; |
| 2634 | UINT16 pkt_size = 0; |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 2635 | BTM_TRACE_DEBUG ("btm_get_max_packet_size"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2636 | if (p != NULL) |
| 2637 | { |
| 2638 | pkt_types = p->pkt_types_mask; |
| 2639 | } |
| 2640 | else |
| 2641 | { |
| 2642 | /* Special case for when info for the local device is requested */ |
| 2643 | if (memcmp (btm_cb.devcb.local_addr, addr, BD_ADDR_LEN) == 0) |
| 2644 | { |
| 2645 | pkt_types = btm_cb.btm_acl_pkt_types_supported; |
| 2646 | } |
| 2647 | } |
| 2648 | |
| 2649 | if (pkt_types) |
| 2650 | { |
| 2651 | if (!(pkt_types & BTM_ACL_PKT_TYPES_MASK_NO_3_DH5)) |
| 2652 | pkt_size = HCI_EDR3_DH5_PACKET_SIZE; |
| 2653 | else if (!(pkt_types & BTM_ACL_PKT_TYPES_MASK_NO_2_DH5)) |
| 2654 | pkt_size = HCI_EDR2_DH5_PACKET_SIZE; |
| 2655 | else if (!(pkt_types & BTM_ACL_PKT_TYPES_MASK_NO_3_DH3)) |
| 2656 | pkt_size = HCI_EDR3_DH3_PACKET_SIZE; |
| 2657 | else if (pkt_types & BTM_ACL_PKT_TYPES_MASK_DH5) |
| 2658 | pkt_size = HCI_DH5_PACKET_SIZE; |
| 2659 | else if (!(pkt_types & BTM_ACL_PKT_TYPES_MASK_NO_2_DH3)) |
| 2660 | pkt_size = HCI_EDR2_DH3_PACKET_SIZE; |
| 2661 | else if (pkt_types & BTM_ACL_PKT_TYPES_MASK_DM5) |
| 2662 | pkt_size = HCI_DM5_PACKET_SIZE; |
| 2663 | else if (pkt_types & BTM_ACL_PKT_TYPES_MASK_DH3) |
| 2664 | pkt_size = HCI_DH3_PACKET_SIZE; |
| 2665 | else if (pkt_types & BTM_ACL_PKT_TYPES_MASK_DM3) |
| 2666 | pkt_size = HCI_DM3_PACKET_SIZE; |
| 2667 | else if (!(pkt_types & BTM_ACL_PKT_TYPES_MASK_NO_3_DH1)) |
| 2668 | pkt_size = HCI_EDR3_DH1_PACKET_SIZE; |
| 2669 | else if (!(pkt_types & BTM_ACL_PKT_TYPES_MASK_NO_2_DH1)) |
| 2670 | pkt_size = HCI_EDR2_DH1_PACKET_SIZE; |
| 2671 | else if (pkt_types & BTM_ACL_PKT_TYPES_MASK_DH1) |
| 2672 | pkt_size = HCI_DH1_PACKET_SIZE; |
| 2673 | else if (pkt_types & BTM_ACL_PKT_TYPES_MASK_DM1) |
| 2674 | pkt_size = HCI_DM1_PACKET_SIZE; |
| 2675 | } |
| 2676 | |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 2677 | return(pkt_size); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2678 | } |
| 2679 | |
| 2680 | /******************************************************************************* |
| 2681 | ** |
| 2682 | ** Function BTM_ReadRemoteVersion |
| 2683 | ** |
| 2684 | ** Returns If connected report peer device info |
| 2685 | ** |
| 2686 | *******************************************************************************/ |
| 2687 | tBTM_STATUS BTM_ReadRemoteVersion (BD_ADDR addr, UINT8 *lmp_version, |
| 2688 | UINT16 *manufacturer, UINT16 *lmp_sub_version) |
| 2689 | { |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2690 | tACL_CONN *p = btm_bda_to_acl(addr, BT_TRANSPORT_BR_EDR); |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 2691 | BTM_TRACE_DEBUG ("BTM_ReadRemoteVersion"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2692 | if (p == NULL) |
| 2693 | return(BTM_UNKNOWN_ADDR); |
| 2694 | |
| 2695 | if (lmp_version) |
| 2696 | *lmp_version = p->lmp_version; |
| 2697 | |
| 2698 | if (manufacturer) |
| 2699 | *manufacturer = p->manufacturer; |
| 2700 | |
| 2701 | if (lmp_sub_version) |
| 2702 | *lmp_sub_version = p->lmp_subversion; |
| 2703 | |
| 2704 | return(BTM_SUCCESS); |
| 2705 | } |
| 2706 | |
| 2707 | /******************************************************************************* |
| 2708 | ** |
| 2709 | ** Function BTM_ReadRemoteFeatures |
| 2710 | ** |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 2711 | ** Returns pointer to the remote supported features mask (8 bytes) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2712 | ** |
| 2713 | *******************************************************************************/ |
| 2714 | UINT8 *BTM_ReadRemoteFeatures (BD_ADDR addr) |
| 2715 | { |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2716 | tACL_CONN *p = btm_bda_to_acl(addr, BT_TRANSPORT_BR_EDR); |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 2717 | BTM_TRACE_DEBUG ("BTM_ReadRemoteFeatures"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2718 | if (p == NULL) |
| 2719 | { |
| 2720 | return(NULL); |
| 2721 | } |
| 2722 | |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 2723 | return(p->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0]); |
| 2724 | } |
| 2725 | |
| 2726 | /******************************************************************************* |
| 2727 | ** |
| 2728 | ** Function BTM_ReadRemoteExtendedFeatures |
| 2729 | ** |
| 2730 | ** Returns pointer to the remote extended features mask (8 bytes) |
| 2731 | ** or NULL if bad page |
| 2732 | ** |
| 2733 | *******************************************************************************/ |
| 2734 | UINT8 *BTM_ReadRemoteExtendedFeatures (BD_ADDR addr, UINT8 page_number) |
| 2735 | { |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2736 | tACL_CONN *p = btm_bda_to_acl(addr, BT_TRANSPORT_BR_EDR); |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 2737 | BTM_TRACE_DEBUG ("BTM_ReadRemoteExtendedFeatures"); |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 2738 | if (p == NULL) |
| 2739 | { |
| 2740 | return(NULL); |
| 2741 | } |
| 2742 | |
| 2743 | if (page_number > HCI_EXT_FEATURES_PAGE_MAX) |
| 2744 | { |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 2745 | BTM_TRACE_ERROR("Warning: BTM_ReadRemoteExtendedFeatures page %d unknown", page_number); |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 2746 | return NULL; |
| 2747 | } |
| 2748 | |
| 2749 | return(p->peer_lmp_features[page_number]); |
| 2750 | } |
| 2751 | |
| 2752 | /******************************************************************************* |
| 2753 | ** |
| 2754 | ** Function BTM_ReadNumberRemoteFeaturesPages |
| 2755 | ** |
| 2756 | ** Returns number of features pages read from the remote device. |
| 2757 | ** |
| 2758 | *******************************************************************************/ |
| 2759 | UINT8 BTM_ReadNumberRemoteFeaturesPages (BD_ADDR addr) |
| 2760 | { |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2761 | tACL_CONN *p = btm_bda_to_acl(addr, BT_TRANSPORT_BR_EDR); |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 2762 | BTM_TRACE_DEBUG ("BTM_ReadNumberRemoteFeaturesPages"); |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 2763 | if (p == NULL) |
| 2764 | { |
| 2765 | return(0); |
| 2766 | } |
| 2767 | |
| 2768 | return(p->num_read_pages); |
| 2769 | } |
| 2770 | |
| 2771 | /******************************************************************************* |
| 2772 | ** |
| 2773 | ** Function BTM_ReadAllRemoteFeatures |
| 2774 | ** |
| 2775 | ** Returns pointer to all features of the remote (24 bytes). |
| 2776 | ** |
| 2777 | *******************************************************************************/ |
| 2778 | UINT8 *BTM_ReadAllRemoteFeatures (BD_ADDR addr) |
| 2779 | { |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2780 | tACL_CONN *p = btm_bda_to_acl(addr, BT_TRANSPORT_BR_EDR); |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 2781 | BTM_TRACE_DEBUG ("BTM_ReadAllRemoteFeatures"); |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 2782 | if (p == NULL) |
| 2783 | { |
| 2784 | return(NULL); |
| 2785 | } |
| 2786 | |
| 2787 | return(p->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0]); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2788 | } |
| 2789 | |
| 2790 | /******************************************************************************* |
| 2791 | ** |
| 2792 | ** Function BTM_RegBusyLevelNotif |
| 2793 | ** |
| 2794 | ** Description This function is called to register a callback to receive |
| 2795 | ** busy level change events. |
| 2796 | ** |
| 2797 | ** Returns BTM_SUCCESS if successfully registered, otherwise error |
| 2798 | ** |
| 2799 | *******************************************************************************/ |
| 2800 | #if (defined(BTM_BUSY_LEVEL_CHANGE_INCLUDED) && BTM_BUSY_LEVEL_CHANGE_INCLUDED == TRUE) |
| 2801 | tBTM_STATUS BTM_RegBusyLevelNotif (tBTM_BL_CHANGE_CB *p_cb, UINT8 *p_level, |
| 2802 | tBTM_BL_EVENT_MASK evt_mask) |
| 2803 | { |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 2804 | BTM_TRACE_DEBUG ("BTM_RegBusyLevelNotif"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2805 | if (p_level) |
| 2806 | *p_level = btm_cb.busy_level; |
| 2807 | |
| 2808 | btm_cb.bl_evt_mask = evt_mask; |
| 2809 | |
| 2810 | if (!p_cb) |
| 2811 | btm_cb.p_bl_changed_cb = NULL; |
| 2812 | else if (btm_cb.p_bl_changed_cb) |
| 2813 | return(BTM_BUSY); |
| 2814 | else |
| 2815 | btm_cb.p_bl_changed_cb = p_cb; |
| 2816 | |
| 2817 | return(BTM_SUCCESS); |
| 2818 | } |
| 2819 | #else |
| 2820 | /******************************************************************************* |
| 2821 | ** |
| 2822 | ** Function BTM_AclRegisterForChanges |
| 2823 | ** |
| 2824 | ** Returns This function is called to register a callback for when the |
| 2825 | ** ACL database changes, i.e. new entry or entry deleted. |
| 2826 | ** |
| 2827 | *******************************************************************************/ |
| 2828 | tBTM_STATUS BTM_AclRegisterForChanges (tBTM_ACL_DB_CHANGE_CB *p_cb) |
| 2829 | { |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 2830 | BTM_TRACE_DEBUG ("BTM_AclRegisterForChanges"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2831 | if (!p_cb) |
| 2832 | btm_cb.p_acl_changed_cb = NULL; |
| 2833 | else if (btm_cb.p_acl_changed_cb) |
| 2834 | return(BTM_BUSY); |
| 2835 | else |
| 2836 | btm_cb.p_acl_changed_cb = p_cb; |
| 2837 | |
| 2838 | return(BTM_SUCCESS); |
| 2839 | } |
| 2840 | #endif |
| 2841 | |
| 2842 | /******************************************************************************* |
| 2843 | ** |
| 2844 | ** Function BTM_SetQoS |
| 2845 | ** |
| 2846 | ** Description This function is called to setup QoS |
| 2847 | ** |
| 2848 | ** Returns status of the operation |
| 2849 | ** |
| 2850 | *******************************************************************************/ |
| 2851 | tBTM_STATUS BTM_SetQoS (BD_ADDR bd, FLOW_SPEC *p_flow, tBTM_CMPL_CB *p_cb) |
| 2852 | { |
| 2853 | tACL_CONN *p = &btm_cb.acl_db[0]; |
| 2854 | |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 2855 | BTM_TRACE_API ("BTM_SetQoS: BdAddr: %02x%02x%02x%02x%02x%02x", |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2856 | bd[0], bd[1], bd[2], |
| 2857 | bd[3], bd[4], bd[5]); |
| 2858 | |
| 2859 | /* If someone already waiting on the version, do not allow another */ |
| 2860 | if (btm_cb.devcb.p_qossu_cmpl_cb) |
| 2861 | return(BTM_BUSY); |
| 2862 | |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2863 | if ( (p = btm_bda_to_acl(bd, BT_TRANSPORT_BR_EDR)) != NULL) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2864 | { |
| 2865 | btu_start_timer (&btm_cb.devcb.qossu_timer, BTU_TTYPE_BTM_ACL, BTM_DEV_REPLY_TIMEOUT); |
| 2866 | btm_cb.devcb.p_qossu_cmpl_cb = p_cb; |
| 2867 | |
| 2868 | if (!btsnd_hcic_qos_setup (p->hci_handle, p_flow->qos_flags, p_flow->service_type, |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 2869 | p_flow->token_rate, p_flow->peak_bandwidth, |
| 2870 | p_flow->latency,p_flow->delay_variation)) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2871 | { |
| 2872 | btm_cb.devcb.p_qossu_cmpl_cb = NULL; |
| 2873 | btu_stop_timer(&btm_cb.devcb.qossu_timer); |
| 2874 | return(BTM_NO_RESOURCES); |
| 2875 | } |
| 2876 | else |
| 2877 | return(BTM_CMD_STARTED); |
| 2878 | } |
| 2879 | |
| 2880 | /* If here, no BD Addr found */ |
| 2881 | return(BTM_UNKNOWN_ADDR); |
| 2882 | } |
| 2883 | |
| 2884 | /******************************************************************************* |
| 2885 | ** |
| 2886 | ** Function btm_qos_setup_complete |
| 2887 | ** |
| 2888 | ** Description This function is called when the command complete message |
| 2889 | ** is received from the HCI for the qos setup request. |
| 2890 | ** |
| 2891 | ** Returns void |
| 2892 | ** |
| 2893 | *******************************************************************************/ |
| 2894 | void btm_qos_setup_complete (UINT8 status, UINT16 handle, FLOW_SPEC *p_flow) |
| 2895 | { |
| 2896 | tBTM_CMPL_CB *p_cb = btm_cb.devcb.p_qossu_cmpl_cb; |
| 2897 | tBTM_QOS_SETUP_CMPL qossu; |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 2898 | BTM_TRACE_DEBUG ("btm_qos_setup_complete"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2899 | btu_stop_timer (&btm_cb.devcb.qossu_timer); |
| 2900 | |
| 2901 | btm_cb.devcb.p_qossu_cmpl_cb = NULL; |
| 2902 | |
| 2903 | if (p_cb) |
| 2904 | { |
| 2905 | memset(&qossu, 0, sizeof(tBTM_QOS_SETUP_CMPL)); |
| 2906 | qossu.status = status; |
| 2907 | qossu.handle = handle; |
| 2908 | if (p_flow != NULL) |
| 2909 | { |
| 2910 | qossu.flow.qos_flags = p_flow->qos_flags; |
| 2911 | qossu.flow.service_type = p_flow->service_type; |
| 2912 | qossu.flow.token_rate = p_flow->token_rate; |
| 2913 | qossu.flow.peak_bandwidth = p_flow->peak_bandwidth; |
| 2914 | qossu.flow.latency = p_flow->latency; |
| 2915 | qossu.flow.delay_variation = p_flow->delay_variation; |
| 2916 | } |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 2917 | BTM_TRACE_DEBUG ("BTM: p_flow->delay_variation: 0x%02x", |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2918 | qossu.flow.delay_variation); |
| 2919 | (*p_cb)(&qossu); |
| 2920 | } |
| 2921 | } |
| 2922 | |
| 2923 | |
| 2924 | /******************************************************************************* |
| 2925 | ** |
| 2926 | ** Function BTM_ReadRSSI |
| 2927 | ** |
| 2928 | ** Description This function is called to read the link policy settings. |
| 2929 | ** The address of link policy results are returned in the callback. |
| 2930 | ** (tBTM_RSSI_RESULTS) |
| 2931 | ** |
| 2932 | ** Returns BTM_CMD_STARTED if successfully initiated or error code |
| 2933 | ** |
| 2934 | *******************************************************************************/ |
| 2935 | tBTM_STATUS BTM_ReadRSSI (BD_ADDR remote_bda, tBTM_CMPL_CB *p_cb) |
| 2936 | { |
| 2937 | tACL_CONN *p; |
| 2938 | |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 2939 | BTM_TRACE_API ("BTM_ReadRSSI: RemBdAddr: %02x%02x%02x%02x%02x%02x", |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2940 | remote_bda[0], remote_bda[1], remote_bda[2], |
| 2941 | remote_bda[3], remote_bda[4], remote_bda[5]); |
| 2942 | |
| 2943 | /* If someone already waiting on the version, do not allow another */ |
| 2944 | if (btm_cb.devcb.p_rssi_cmpl_cb) |
| 2945 | return(BTM_BUSY); |
| 2946 | |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2947 | p = btm_bda_to_acl(remote_bda, BT_TRANSPORT_BR_EDR); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2948 | if (p != (tACL_CONN *)NULL) |
| 2949 | { |
| 2950 | btu_start_timer (&btm_cb.devcb.rssi_timer, BTU_TTYPE_BTM_ACL, |
| 2951 | BTM_DEV_REPLY_TIMEOUT); |
| 2952 | |
| 2953 | btm_cb.devcb.p_rssi_cmpl_cb = p_cb; |
| 2954 | |
| 2955 | if (!btsnd_hcic_read_rssi (p->hci_handle)) |
| 2956 | { |
| 2957 | btm_cb.devcb.p_rssi_cmpl_cb = NULL; |
| 2958 | btu_stop_timer (&btm_cb.devcb.rssi_timer); |
| 2959 | return(BTM_NO_RESOURCES); |
| 2960 | } |
| 2961 | else |
| 2962 | return(BTM_CMD_STARTED); |
| 2963 | } |
| 2964 | |
| 2965 | /* If here, no BD Addr found */ |
| 2966 | return(BTM_UNKNOWN_ADDR); |
| 2967 | } |
| 2968 | |
| 2969 | /******************************************************************************* |
| 2970 | ** |
| 2971 | ** Function BTM_ReadLinkQuality |
| 2972 | ** |
| 2973 | ** Description This function is called to read the link qulaity. |
| 2974 | ** The value of the link quality is returned in the callback. |
| 2975 | ** (tBTM_LINK_QUALITY_RESULTS) |
| 2976 | ** |
| 2977 | ** Returns BTM_CMD_STARTED if successfully initiated or error code |
| 2978 | ** |
| 2979 | *******************************************************************************/ |
| 2980 | tBTM_STATUS BTM_ReadLinkQuality (BD_ADDR remote_bda, tBTM_CMPL_CB *p_cb) |
| 2981 | { |
| 2982 | tACL_CONN *p; |
| 2983 | |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 2984 | BTM_TRACE_API ("BTM_ReadLinkQuality: RemBdAddr: %02x%02x%02x%02x%02x%02x", |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2985 | remote_bda[0], remote_bda[1], remote_bda[2], |
| 2986 | remote_bda[3], remote_bda[4], remote_bda[5]); |
| 2987 | |
| 2988 | /* If someone already waiting on the version, do not allow another */ |
| 2989 | if (btm_cb.devcb.p_lnk_qual_cmpl_cb) |
| 2990 | return(BTM_BUSY); |
| 2991 | |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2992 | p = btm_bda_to_acl(remote_bda, BT_TRANSPORT_BR_EDR); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2993 | if (p != (tACL_CONN *)NULL) |
| 2994 | { |
| 2995 | btu_start_timer (&btm_cb.devcb.lnk_quality_timer, BTU_TTYPE_BTM_ACL, |
| 2996 | BTM_DEV_REPLY_TIMEOUT); |
| 2997 | btm_cb.devcb.p_lnk_qual_cmpl_cb = p_cb; |
| 2998 | |
| 2999 | if (!btsnd_hcic_get_link_quality (p->hci_handle)) |
| 3000 | { |
| 3001 | btu_stop_timer (&btm_cb.devcb.lnk_quality_timer); |
| 3002 | btm_cb.devcb.p_lnk_qual_cmpl_cb = NULL; |
| 3003 | return(BTM_NO_RESOURCES); |
| 3004 | } |
| 3005 | else |
| 3006 | return(BTM_CMD_STARTED); |
| 3007 | } |
| 3008 | |
| 3009 | /* If here, no BD Addr found */ |
| 3010 | return(BTM_UNKNOWN_ADDR); |
| 3011 | } |
| 3012 | |
| 3013 | /******************************************************************************* |
| 3014 | ** |
| 3015 | ** Function BTM_ReadTxPower |
| 3016 | ** |
| 3017 | ** Description This function is called to read the current |
| 3018 | ** TX power of the connection. The tx power level results |
| 3019 | ** are returned in the callback. |
| 3020 | ** (tBTM_RSSI_RESULTS) |
| 3021 | ** |
| 3022 | ** Returns BTM_CMD_STARTED if successfully initiated or error code |
| 3023 | ** |
| 3024 | *******************************************************************************/ |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 3025 | tBTM_STATUS BTM_ReadTxPower (BD_ADDR remote_bda, tBT_TRANSPORT transport, tBTM_CMPL_CB *p_cb) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3026 | { |
| 3027 | tACL_CONN *p; |
| 3028 | BOOLEAN ret; |
| 3029 | #define BTM_READ_RSSI_TYPE_CUR 0x00 |
| 3030 | #define BTM_READ_RSSI_TYPE_MAX 0X01 |
| 3031 | |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 3032 | BTM_TRACE_API ("BTM_ReadTxPower: RemBdAddr: %02x%02x%02x%02x%02x%02x", |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3033 | remote_bda[0], remote_bda[1], remote_bda[2], |
| 3034 | remote_bda[3], remote_bda[4], remote_bda[5]); |
| 3035 | |
| 3036 | /* If someone already waiting on the version, do not allow another */ |
| 3037 | if (btm_cb.devcb.p_tx_power_cmpl_cb) |
| 3038 | return(BTM_BUSY); |
| 3039 | |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 3040 | p = btm_bda_to_acl(remote_bda, transport); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3041 | if (p != (tACL_CONN *)NULL) |
| 3042 | { |
| 3043 | btu_start_timer (&btm_cb.devcb.tx_power_timer, BTU_TTYPE_BTM_ACL, |
| 3044 | BTM_DEV_REPLY_TIMEOUT); |
| 3045 | |
| 3046 | btm_cb.devcb.p_tx_power_cmpl_cb = p_cb; |
| 3047 | |
| 3048 | #if BLE_INCLUDED == TRUE |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 3049 | if (p->transport == BT_TRANSPORT_LE) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3050 | { |
| 3051 | memcpy(btm_cb.devcb.read_tx_pwr_addr, remote_bda, BD_ADDR_LEN); |
| 3052 | ret = btsnd_hcic_ble_read_adv_chnl_tx_power(); |
| 3053 | } |
| 3054 | else |
| 3055 | #endif |
| 3056 | { |
| 3057 | ret = btsnd_hcic_read_tx_power (p->hci_handle, BTM_READ_RSSI_TYPE_CUR); |
| 3058 | } |
| 3059 | if (!ret) |
| 3060 | { |
| 3061 | btm_cb.devcb.p_tx_power_cmpl_cb = NULL; |
| 3062 | btu_stop_timer (&btm_cb.devcb.tx_power_timer); |
| 3063 | return(BTM_NO_RESOURCES); |
| 3064 | } |
| 3065 | else |
| 3066 | return(BTM_CMD_STARTED); |
| 3067 | } |
| 3068 | |
| 3069 | /* If here, no BD Addr found */ |
| 3070 | return (BTM_UNKNOWN_ADDR); |
| 3071 | } |
| 3072 | /******************************************************************************* |
| 3073 | ** |
| 3074 | ** Function btm_read_tx_power_complete |
| 3075 | ** |
| 3076 | ** Description This function is called when the command complete message |
| 3077 | ** is received from the HCI for the read tx power request. |
| 3078 | ** |
| 3079 | ** Returns void |
| 3080 | ** |
| 3081 | *******************************************************************************/ |
| 3082 | void btm_read_tx_power_complete (UINT8 *p, BOOLEAN is_ble) |
| 3083 | { |
| 3084 | tBTM_CMPL_CB *p_cb = btm_cb.devcb.p_tx_power_cmpl_cb; |
| 3085 | tBTM_TX_POWER_RESULTS results; |
| 3086 | UINT16 handle; |
| 3087 | tACL_CONN *p_acl_cb = &btm_cb.acl_db[0]; |
| 3088 | UINT16 index; |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 3089 | BTM_TRACE_DEBUG ("btm_read_tx_power_complete"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3090 | btu_stop_timer (&btm_cb.devcb.tx_power_timer); |
| 3091 | |
| 3092 | /* If there was a callback registered for read rssi, call it */ |
| 3093 | btm_cb.devcb.p_tx_power_cmpl_cb = NULL; |
| 3094 | |
| 3095 | if (p_cb) |
| 3096 | { |
| 3097 | STREAM_TO_UINT8 (results.hci_status, p); |
| 3098 | |
| 3099 | if (results.hci_status == HCI_SUCCESS) |
| 3100 | { |
| 3101 | results.status = BTM_SUCCESS; |
| 3102 | |
| 3103 | if (!is_ble) |
| 3104 | { |
| 3105 | STREAM_TO_UINT16 (handle, p); |
| 3106 | STREAM_TO_UINT8 (results.tx_power, p); |
| 3107 | |
| 3108 | /* Search through the list of active channels for the correct BD Addr */ |
| 3109 | for (index = 0; index < MAX_L2CAP_LINKS; index++, p_acl_cb++) |
| 3110 | { |
| 3111 | if ((p_acl_cb->in_use) && (handle == p_acl_cb->hci_handle)) |
| 3112 | { |
| 3113 | memcpy (results.rem_bda, p_acl_cb->remote_addr, BD_ADDR_LEN); |
| 3114 | break; |
| 3115 | } |
| 3116 | } |
| 3117 | } |
| 3118 | #if BLE_INCLUDED == TRUE |
| 3119 | else |
| 3120 | { |
| 3121 | STREAM_TO_UINT8 (results.tx_power, p); |
| 3122 | memcpy(results.rem_bda, btm_cb.devcb.read_tx_pwr_addr, BD_ADDR_LEN); |
| 3123 | } |
| 3124 | #endif |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 3125 | BTM_TRACE_DEBUG ("BTM TX power Complete: tx_power %d, hci status 0x%02x", |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3126 | results.tx_power, results.hci_status); |
| 3127 | } |
| 3128 | else |
| 3129 | results.status = BTM_ERR_PROCESSING; |
| 3130 | |
| 3131 | (*p_cb)(&results); |
| 3132 | } |
| 3133 | } |
| 3134 | |
| 3135 | /******************************************************************************* |
| 3136 | ** |
| 3137 | ** Function btm_read_rssi_complete |
| 3138 | ** |
| 3139 | ** Description This function is called when the command complete message |
| 3140 | ** is received from the HCI for the read rssi request. |
| 3141 | ** |
| 3142 | ** Returns void |
| 3143 | ** |
| 3144 | *******************************************************************************/ |
| 3145 | void btm_read_rssi_complete (UINT8 *p) |
| 3146 | { |
| 3147 | tBTM_CMPL_CB *p_cb = btm_cb.devcb.p_rssi_cmpl_cb; |
| 3148 | tBTM_RSSI_RESULTS results; |
| 3149 | UINT16 handle; |
| 3150 | tACL_CONN *p_acl_cb = &btm_cb.acl_db[0]; |
| 3151 | UINT16 index; |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 3152 | BTM_TRACE_DEBUG ("btm_read_rssi_complete"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3153 | btu_stop_timer (&btm_cb.devcb.rssi_timer); |
| 3154 | |
| 3155 | /* If there was a callback registered for read rssi, call it */ |
| 3156 | btm_cb.devcb.p_rssi_cmpl_cb = NULL; |
| 3157 | |
| 3158 | if (p_cb) |
| 3159 | { |
| 3160 | STREAM_TO_UINT8 (results.hci_status, p); |
| 3161 | |
| 3162 | if (results.hci_status == HCI_SUCCESS) |
| 3163 | { |
| 3164 | results.status = BTM_SUCCESS; |
| 3165 | |
| 3166 | STREAM_TO_UINT16 (handle, p); |
| 3167 | |
| 3168 | STREAM_TO_UINT8 (results.rssi, p); |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 3169 | BTM_TRACE_DEBUG ("BTM RSSI Complete: rssi %d, hci status 0x%02x", |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3170 | results.rssi, results.hci_status); |
| 3171 | |
| 3172 | /* Search through the list of active channels for the correct BD Addr */ |
| 3173 | for (index = 0; index < MAX_L2CAP_LINKS; index++, p_acl_cb++) |
| 3174 | { |
| 3175 | if ((p_acl_cb->in_use) && (handle == p_acl_cb->hci_handle)) |
| 3176 | { |
| 3177 | memcpy (results.rem_bda, p_acl_cb->remote_addr, BD_ADDR_LEN); |
| 3178 | break; |
| 3179 | } |
| 3180 | } |
| 3181 | } |
| 3182 | else |
| 3183 | results.status = BTM_ERR_PROCESSING; |
| 3184 | |
| 3185 | (*p_cb)(&results); |
| 3186 | } |
| 3187 | } |
| 3188 | |
| 3189 | /******************************************************************************* |
| 3190 | ** |
| 3191 | ** Function btm_read_link_quality_complete |
| 3192 | ** |
| 3193 | ** Description This function is called when the command complete message |
| 3194 | ** is received from the HCI for the read link quality. |
| 3195 | ** |
| 3196 | ** Returns void |
| 3197 | ** |
| 3198 | *******************************************************************************/ |
| 3199 | void btm_read_link_quality_complete (UINT8 *p) |
| 3200 | { |
| 3201 | tBTM_CMPL_CB *p_cb = btm_cb.devcb.p_lnk_qual_cmpl_cb; |
| 3202 | tBTM_LINK_QUALITY_RESULTS results; |
| 3203 | UINT16 handle; |
| 3204 | tACL_CONN *p_acl_cb = &btm_cb.acl_db[0]; |
| 3205 | UINT16 index; |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 3206 | BTM_TRACE_DEBUG ("btm_read_link_quality_complete"); |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 3207 | btu_stop_timer (&btm_cb.devcb.lnk_quality_timer); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3208 | |
| 3209 | /* If there was a callback registered for read rssi, call it */ |
| 3210 | btm_cb.devcb.p_lnk_qual_cmpl_cb = NULL; |
| 3211 | |
| 3212 | if (p_cb) |
| 3213 | { |
| 3214 | STREAM_TO_UINT8 (results.hci_status, p); |
| 3215 | |
| 3216 | if (results.hci_status == HCI_SUCCESS) |
| 3217 | { |
| 3218 | results.status = BTM_SUCCESS; |
| 3219 | |
| 3220 | STREAM_TO_UINT16 (handle, p); |
| 3221 | |
| 3222 | STREAM_TO_UINT8 (results.link_quality, p); |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 3223 | BTM_TRACE_DEBUG ("BTM Link Quality Complete: Link Quality %d, hci status 0x%02x", |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3224 | results.link_quality, results.hci_status); |
| 3225 | |
| 3226 | /* Search through the list of active channels for the correct BD Addr */ |
| 3227 | for (index = 0; index < MAX_L2CAP_LINKS; index++, p_acl_cb++) |
| 3228 | { |
| 3229 | if ((p_acl_cb->in_use) && (handle == p_acl_cb->hci_handle)) |
| 3230 | { |
| 3231 | memcpy (results.rem_bda, p_acl_cb->remote_addr, BD_ADDR_LEN); |
| 3232 | break; |
| 3233 | } |
| 3234 | } |
| 3235 | } |
| 3236 | else |
| 3237 | results.status = BTM_ERR_PROCESSING; |
| 3238 | |
| 3239 | (*p_cb)(&results); |
| 3240 | } |
| 3241 | } |
| 3242 | |
| 3243 | /******************************************************************************* |
| 3244 | ** |
| 3245 | ** Function btm_remove_acl |
| 3246 | ** |
| 3247 | ** Description This function is called to disconnect an ACL connection |
| 3248 | ** |
| 3249 | ** Returns BTM_SUCCESS if successfully initiated, otherwise BTM_NO_RESOURCES. |
| 3250 | ** |
| 3251 | *******************************************************************************/ |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 3252 | tBTM_STATUS btm_remove_acl (BD_ADDR bd_addr, tBT_TRANSPORT transport) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3253 | { |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 3254 | UINT16 hci_handle = BTM_GetHCIConnHandle(bd_addr, transport); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3255 | tBTM_STATUS status = BTM_SUCCESS; |
| 3256 | |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 3257 | BTM_TRACE_DEBUG ("btm_remove_acl"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3258 | #if BTM_DISC_DURING_RS == TRUE |
| 3259 | tBTM_SEC_DEV_REC *p_dev_rec = btm_find_dev (bd_addr); |
| 3260 | |
| 3261 | /* Role Switch is pending, postpone until completed */ |
| 3262 | if (p_dev_rec && (p_dev_rec->rs_disc_pending == BTM_SEC_RS_PENDING)) |
| 3263 | { |
| 3264 | p_dev_rec->rs_disc_pending = BTM_SEC_DISC_PENDING; |
| 3265 | } |
| 3266 | else /* otherwise can disconnect right away */ |
| 3267 | #endif |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3268 | { |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 3269 | if (hci_handle != 0xFFFF) |
| 3270 | { |
| 3271 | if (!btsnd_hcic_disconnect (hci_handle, HCI_ERR_PEER_USER)) |
| 3272 | status = BTM_NO_RESOURCES; |
| 3273 | } |
| 3274 | else |
| 3275 | status = BTM_UNKNOWN_ADDR; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3276 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3277 | |
| 3278 | return status; |
| 3279 | } |
| 3280 | |
| 3281 | |
| 3282 | /******************************************************************************* |
| 3283 | ** |
| 3284 | ** Function BTM_SetTraceLevel |
| 3285 | ** |
| 3286 | ** Description This function sets the trace level for BTM. If called with |
| 3287 | ** a value of 0xFF, it simply returns the current trace level. |
| 3288 | ** |
| 3289 | ** Returns The new or current trace level |
| 3290 | ** |
| 3291 | *******************************************************************************/ |
| 3292 | UINT8 BTM_SetTraceLevel (UINT8 new_level) |
| 3293 | { |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 3294 | BTM_TRACE_DEBUG ("BTM_SetTraceLevel"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3295 | if (new_level != 0xFF) |
| 3296 | btm_cb.trace_level = new_level; |
| 3297 | |
| 3298 | return(btm_cb.trace_level); |
| 3299 | } |
| 3300 | |
| 3301 | /******************************************************************************* |
| 3302 | ** |
| 3303 | ** Function btm_cont_rswitch_or_chglinkkey |
| 3304 | ** |
| 3305 | ** Description This function is called to continue processing an active |
| 3306 | ** role switch or change of link key procedure. It first |
| 3307 | ** disables encryption if enabled and EPR is not supported |
| 3308 | ** |
| 3309 | ** Returns void |
| 3310 | ** |
| 3311 | *******************************************************************************/ |
| 3312 | void btm_cont_rswitch_or_chglinkkey (tACL_CONN *p, tBTM_SEC_DEV_REC *p_dev_rec, |
| 3313 | UINT8 hci_status) |
| 3314 | { |
| 3315 | BOOLEAN sw_ok = TRUE; |
| 3316 | BOOLEAN chlk_ok = TRUE; |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 3317 | BTM_TRACE_DEBUG ("btm_cont_rswitch_or_chglinkkey "); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3318 | /* Check to see if encryption needs to be turned off if pending |
| 3319 | change of link key or role switch */ |
| 3320 | if (p->switch_role_state == BTM_ACL_SWKEY_STATE_MODE_CHANGE || |
| 3321 | p->change_key_state == BTM_ACL_SWKEY_STATE_MODE_CHANGE) |
| 3322 | { |
| 3323 | /* Must turn off Encryption first if necessary */ |
| 3324 | /* Some devices do not support switch or change of link key while encryption is on */ |
| 3325 | if (p_dev_rec != NULL && ((p_dev_rec->sec_flags & BTM_SEC_ENCRYPTED) != 0) |
| 3326 | && !BTM_EPR_AVAILABLE(p)) |
| 3327 | { |
| 3328 | if (btsnd_hcic_set_conn_encrypt (p->hci_handle, FALSE)) |
| 3329 | { |
| 3330 | p->encrypt_state = BTM_ACL_ENCRYPT_STATE_ENCRYPT_OFF; |
| 3331 | if (p->switch_role_state == BTM_ACL_SWKEY_STATE_MODE_CHANGE) |
| 3332 | p->switch_role_state = BTM_ACL_SWKEY_STATE_ENCRYPTION_OFF; |
| 3333 | |
| 3334 | if (p->change_key_state == BTM_ACL_SWKEY_STATE_MODE_CHANGE) |
| 3335 | p->change_key_state = BTM_ACL_SWKEY_STATE_ENCRYPTION_OFF; |
| 3336 | } |
| 3337 | else |
| 3338 | { |
| 3339 | /* Error occurred; set states back to Idle */ |
| 3340 | if (p->switch_role_state == BTM_ACL_SWKEY_STATE_MODE_CHANGE) |
| 3341 | sw_ok = FALSE; |
| 3342 | |
| 3343 | if (p->change_key_state == BTM_ACL_SWKEY_STATE_MODE_CHANGE) |
| 3344 | chlk_ok = FALSE; |
| 3345 | } |
| 3346 | } |
| 3347 | else /* Encryption not used or EPR supported, continue with switch |
| 3348 | and/or change of link key */ |
| 3349 | { |
| 3350 | if (p->switch_role_state == BTM_ACL_SWKEY_STATE_MODE_CHANGE) |
| 3351 | { |
| 3352 | p->switch_role_state = BTM_ACL_SWKEY_STATE_IN_PROGRESS; |
| 3353 | #if BTM_DISC_DURING_RS == TRUE |
| 3354 | if (p_dev_rec) |
| 3355 | p_dev_rec->rs_disc_pending = BTM_SEC_RS_PENDING; |
| 3356 | #endif |
| 3357 | sw_ok = btsnd_hcic_switch_role (p->remote_addr, (UINT8)!p->link_role); |
| 3358 | } |
| 3359 | |
| 3360 | if (p->change_key_state == BTM_ACL_SWKEY_STATE_MODE_CHANGE) |
| 3361 | { |
| 3362 | p->switch_role_state = BTM_ACL_SWKEY_STATE_IN_PROGRESS; |
| 3363 | chlk_ok = btsnd_hcic_change_link_key (p->hci_handle); |
| 3364 | } |
| 3365 | } |
| 3366 | |
| 3367 | if (!sw_ok) |
| 3368 | { |
| 3369 | p->switch_role_state = BTM_ACL_SWKEY_STATE_IDLE; |
| 3370 | btm_acl_report_role_change(hci_status, p->remote_addr); |
| 3371 | } |
| 3372 | |
| 3373 | if (!chlk_ok) |
| 3374 | { |
| 3375 | p->change_key_state = BTM_ACL_SWKEY_STATE_IDLE; |
| 3376 | if (btm_cb.devcb.p_chg_link_key_cb) |
| 3377 | { |
| 3378 | btm_cb.devcb.chg_link_key_ref_data.hci_status = hci_status; |
| 3379 | (*btm_cb.devcb.p_chg_link_key_cb)(&btm_cb.devcb.chg_link_key_ref_data); |
| 3380 | btm_cb.devcb.p_chg_link_key_cb = NULL; |
| 3381 | } |
| 3382 | } |
| 3383 | } |
| 3384 | } |
| 3385 | |
| 3386 | /******************************************************************************* |
| 3387 | ** |
| 3388 | ** Function btm_acl_resubmit_page |
| 3389 | ** |
| 3390 | ** Description send pending page request |
| 3391 | ** |
| 3392 | *******************************************************************************/ |
| 3393 | void btm_acl_resubmit_page (void) |
| 3394 | { |
| 3395 | tBTM_SEC_DEV_REC *p_dev_rec; |
| 3396 | BT_HDR *p_buf; |
| 3397 | UINT8 *pp; |
| 3398 | BD_ADDR bda; |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 3399 | BTM_TRACE_DEBUG ("btm_acl_resubmit_page"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3400 | /* If there were other page request schedule can start the next one */ |
| 3401 | if ((p_buf = (BT_HDR *)GKI_dequeue (&btm_cb.page_queue)) != NULL) |
| 3402 | { |
| 3403 | /* skip 3 (2 bytes opcode and 1 byte len) to get to the bd_addr |
| 3404 | * for both create_conn and rmt_name */ |
| 3405 | pp = (UINT8 *)(p_buf + 1) + p_buf->offset + 3; |
| 3406 | |
| 3407 | STREAM_TO_BDADDR (bda, pp); |
| 3408 | |
| 3409 | p_dev_rec = btm_find_or_alloc_dev (bda); |
| 3410 | |
| 3411 | memcpy (btm_cb.connecting_bda, p_dev_rec->bd_addr, BD_ADDR_LEN); |
| 3412 | memcpy (btm_cb.connecting_dc, p_dev_rec->dev_class, DEV_CLASS_LEN); |
| 3413 | |
| 3414 | btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p_buf); |
| 3415 | } |
| 3416 | else |
| 3417 | btm_cb.paging = FALSE; |
| 3418 | } |
| 3419 | |
| 3420 | /******************************************************************************* |
| 3421 | ** |
| 3422 | ** Function btm_acl_reset_paging |
| 3423 | ** |
| 3424 | ** Description set paging to FALSE and free the page queue - called at hci_reset |
| 3425 | ** |
| 3426 | *******************************************************************************/ |
| 3427 | void btm_acl_reset_paging (void) |
| 3428 | { |
| 3429 | BT_HDR *p; |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 3430 | BTM_TRACE_DEBUG ("btm_acl_reset_paging"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3431 | /* If we sent reset we are definitely not paging any more */ |
| 3432 | while ((p = (BT_HDR *)GKI_dequeue(&btm_cb.page_queue)) != NULL) |
| 3433 | GKI_freebuf (p); |
| 3434 | |
| 3435 | btm_cb.paging = FALSE; |
| 3436 | } |
| 3437 | |
| 3438 | /******************************************************************************* |
| 3439 | ** |
| 3440 | ** Function btm_acl_set_discing |
| 3441 | ** |
| 3442 | ** Description set discing to the given value |
| 3443 | ** |
| 3444 | *******************************************************************************/ |
| 3445 | void btm_acl_set_discing (BOOLEAN discing) |
| 3446 | { |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 3447 | BTM_TRACE_DEBUG ("btm_acl_set_discing"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3448 | btm_cb.discing = discing; |
| 3449 | } |
| 3450 | |
| 3451 | /******************************************************************************* |
| 3452 | ** |
| 3453 | ** Function btm_acl_paging |
| 3454 | ** |
| 3455 | ** Description send a paging command or queue it in btm_cb |
| 3456 | ** |
| 3457 | *******************************************************************************/ |
| 3458 | void btm_acl_paging (BT_HDR *p, BD_ADDR bda) |
| 3459 | { |
| 3460 | tBTM_SEC_DEV_REC *p_dev_rec; |
| 3461 | |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 3462 | BTM_TRACE_DEBUG ("btm_acl_paging discing:%d, paging:%d BDA: %06x%06x", |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3463 | btm_cb.discing, btm_cb.paging, |
| 3464 | (bda[0]<<16) + (bda[1]<<8) + bda[2], (bda[3]<<16) + (bda[4] << 8) + bda[5]); |
| 3465 | if (btm_cb.discing) |
| 3466 | { |
| 3467 | btm_cb.paging = TRUE; |
| 3468 | GKI_enqueue (&btm_cb.page_queue, p); |
| 3469 | } |
| 3470 | else |
| 3471 | { |
| 3472 | if (!BTM_ACL_IS_CONNECTED (bda)) |
| 3473 | { |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 3474 | BTM_TRACE_DEBUG ("connecting_bda: %06x%06x", |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 3475 | (btm_cb.connecting_bda[0]<<16) + (btm_cb.connecting_bda[1]<<8) + |
| 3476 | btm_cb.connecting_bda[2], |
| 3477 | (btm_cb.connecting_bda[3]<<16) + (btm_cb.connecting_bda[4] << 8) + |
| 3478 | btm_cb.connecting_bda[5]); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3479 | if (btm_cb.paging && |
| 3480 | memcmp (bda, btm_cb.connecting_bda, BD_ADDR_LEN) != 0) |
| 3481 | { |
| 3482 | GKI_enqueue (&btm_cb.page_queue, p); |
| 3483 | } |
| 3484 | else |
| 3485 | { |
| 3486 | p_dev_rec = btm_find_or_alloc_dev (bda); |
| 3487 | memcpy (btm_cb.connecting_bda, p_dev_rec->bd_addr, BD_ADDR_LEN); |
| 3488 | memcpy (btm_cb.connecting_dc, p_dev_rec->dev_class, DEV_CLASS_LEN); |
| 3489 | |
| 3490 | btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p); |
| 3491 | } |
| 3492 | |
| 3493 | btm_cb.paging = TRUE; |
| 3494 | } |
| 3495 | else /* ACL is already up */ |
| 3496 | { |
| 3497 | btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p); |
| 3498 | } |
| 3499 | } |
| 3500 | } |
| 3501 | |
| 3502 | /******************************************************************************* |
| 3503 | ** |
| 3504 | ** Function btm_acl_notif_conn_collision |
| 3505 | ** |
| 3506 | ** Description Send connection collision event to upper layer if registered |
| 3507 | ** |
| 3508 | ** Returns TRUE if sent out to upper layer, |
| 3509 | ** FALSE if BTM_BUSY_LEVEL_CHANGE_INCLUDED == FALSE, or no one |
| 3510 | ** needs the notification. |
| 3511 | ** |
| 3512 | ** Note: Function only used if BTM_BUSY_LEVEL_CHANGE_INCLUDED == TRUE |
| 3513 | ** |
| 3514 | *******************************************************************************/ |
| 3515 | BOOLEAN btm_acl_notif_conn_collision (BD_ADDR bda) |
| 3516 | { |
| 3517 | #if (BTM_BUSY_LEVEL_CHANGE_INCLUDED == TRUE) |
| 3518 | tBTM_BL_EVENT_DATA evt_data; |
| 3519 | |
| 3520 | /* Report possible collision to the upper layer. */ |
| 3521 | if (btm_cb.p_bl_changed_cb) |
| 3522 | { |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 3523 | BTM_TRACE_DEBUG ("btm_acl_notif_conn_collision: RemBdAddr: %02x%02x%02x%02x%02x%02x", |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3524 | bda[0], bda[1], bda[2], bda[3], bda[4], bda[5]); |
| 3525 | |
| 3526 | evt_data.event = BTM_BL_COLLISION_EVT; |
| 3527 | evt_data.conn.p_bda = bda; |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 3528 | |
| 3529 | #if BLE_INCLUDED == TRUE |
| 3530 | evt_data.conn.transport = BT_TRANSPORT_BR_EDR; |
| 3531 | evt_data.conn.handle = BTM_INVALID_HCI_HANDLE; |
| 3532 | #endif |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3533 | (*btm_cb.p_bl_changed_cb)(&evt_data); |
| 3534 | return TRUE; |
| 3535 | } |
| 3536 | else |
| 3537 | return FALSE; |
| 3538 | #else |
| 3539 | return FALSE; |
| 3540 | #endif |
| 3541 | } |
| 3542 | |
| 3543 | |
| 3544 | /******************************************************************************* |
| 3545 | ** |
| 3546 | ** Function btm_acl_chk_peer_pkt_type_support |
| 3547 | ** |
| 3548 | ** Description Check if peer supports requested packets |
| 3549 | ** |
| 3550 | *******************************************************************************/ |
| 3551 | void btm_acl_chk_peer_pkt_type_support (tACL_CONN *p, UINT16 *p_pkt_type) |
| 3552 | { |
| 3553 | /* 3 and 5 slot packets? */ |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 3554 | if (!HCI_3_SLOT_PACKETS_SUPPORTED(p->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0])) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3555 | *p_pkt_type &= ~(BTM_ACL_PKT_TYPES_MASK_DH3 +BTM_ACL_PKT_TYPES_MASK_DM3); |
| 3556 | |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 3557 | if (!HCI_5_SLOT_PACKETS_SUPPORTED(p->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0])) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3558 | *p_pkt_type &= ~(BTM_ACL_PKT_TYPES_MASK_DH5 + BTM_ACL_PKT_TYPES_MASK_DM5); |
| 3559 | |
| 3560 | /* If HCI version > 2.0, then also check EDR packet types */ |
| 3561 | if (btm_cb.devcb.local_version.hci_version >= HCI_PROTO_VERSION_2_0) |
| 3562 | { |
| 3563 | /* 2 and 3 MPS support? */ |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 3564 | if (!HCI_EDR_ACL_2MPS_SUPPORTED(p->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0])) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3565 | /* Not supported. Add 'not_supported' mask for all 2MPS packet types */ |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 3566 | *p_pkt_type |= (BTM_ACL_PKT_TYPES_MASK_NO_2_DH1 + BTM_ACL_PKT_TYPES_MASK_NO_2_DH3 + |
| 3567 | BTM_ACL_PKT_TYPES_MASK_NO_2_DH5); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3568 | |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 3569 | if (!HCI_EDR_ACL_3MPS_SUPPORTED(p->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0])) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3570 | /* Not supported. Add 'not_supported' mask for all 3MPS packet types */ |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 3571 | *p_pkt_type |= (BTM_ACL_PKT_TYPES_MASK_NO_3_DH1 + BTM_ACL_PKT_TYPES_MASK_NO_3_DH3 + |
| 3572 | BTM_ACL_PKT_TYPES_MASK_NO_3_DH5); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3573 | |
| 3574 | /* EDR 3 and 5 slot support? */ |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 3575 | if (HCI_EDR_ACL_2MPS_SUPPORTED(p->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0]) |
| 3576 | || HCI_EDR_ACL_3MPS_SUPPORTED(p->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0])) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3577 | { |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 3578 | if (!HCI_3_SLOT_EDR_ACL_SUPPORTED(p->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0])) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3579 | /* Not supported. Add 'not_supported' mask for all 3-slot EDR packet types */ |
| 3580 | *p_pkt_type |= (BTM_ACL_PKT_TYPES_MASK_NO_2_DH3 + BTM_ACL_PKT_TYPES_MASK_NO_3_DH3); |
| 3581 | |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 3582 | if (!HCI_5_SLOT_EDR_ACL_SUPPORTED(p->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0])) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3583 | /* Not supported. Add 'not_supported' mask for all 5-slot EDR packet types */ |
| 3584 | *p_pkt_type |= (BTM_ACL_PKT_TYPES_MASK_NO_2_DH5 + BTM_ACL_PKT_TYPES_MASK_NO_3_DH5); |
| 3585 | } |
| 3586 | } |
| 3587 | } |