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