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 | |
Mudumba Ananth | 899b771 | 2015-01-30 02:33:02 -0800 | [diff] [blame] | 19 | /***************************************************************************** |
| 20 | ** |
| 21 | ** Name: btm_acl.c |
| 22 | ** |
| 23 | ** Description: This file contains functions that handle ACL connections. |
| 24 | ** This includes operations such as hold and sniff modes, |
| 25 | ** supported packet types. |
| 26 | ** |
| 27 | ** This module contains both internal and external (API) |
| 28 | ** functions. External (API) functions are distinguishable |
| 29 | ** by their names beginning with uppercase BTM. |
| 30 | ** |
| 31 | ** |
| 32 | ******************************************************************************/ |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 33 | |
| 34 | #include <stdlib.h> |
| 35 | #include <string.h> |
| 36 | #include <stdio.h> |
| 37 | #include <stddef.h> |
| 38 | |
| 39 | #include "bt_types.h" |
| 40 | #include "bt_target.h" |
Chris Manton | 79ecab5 | 2014-10-31 14:54:51 -0700 | [diff] [blame] | 41 | #include "device/include/controller.h" |
Pavlin Radoslavov | 258c253 | 2015-09-27 20:59:05 -0700 | [diff] [blame] | 42 | #include "bt_common.h" |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 43 | #include "hcimsgs.h" |
| 44 | #include "btu.h" |
| 45 | #include "btm_api.h" |
| 46 | #include "btm_int.h" |
| 47 | #include "l2c_int.h" |
| 48 | #include "hcidefs.h" |
Mike J. Chen | 5be3cb0 | 2014-04-01 12:52:09 -0700 | [diff] [blame] | 49 | #include "bt_utils.h" |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 50 | |
Pavlin Radoslavov | 78bcff7 | 2015-12-04 17:36:34 -0800 | [diff] [blame] | 51 | |
| 52 | extern fixed_queue_t *btu_general_alarm_queue; |
| 53 | |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 54 | static void btm_read_remote_features (uint16_t handle); |
| 55 | static void btm_read_remote_ext_features (uint16_t handle, uint8_t page_number); |
| 56 | static void btm_process_remote_ext_features (tACL_CONN *p_acl_cb, uint8_t num_read_pages); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 57 | |
Pavlin Radoslavov | 78bcff7 | 2015-12-04 17:36:34 -0800 | [diff] [blame] | 58 | /* 3 seconds timeout waiting for responses */ |
| 59 | #define BTM_DEV_REPLY_TIMEOUT_MS (3 * 1000) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 60 | |
| 61 | /******************************************************************************* |
| 62 | ** |
| 63 | ** Function btm_acl_init |
| 64 | ** |
| 65 | ** Description This function is called at BTM startup to initialize |
| 66 | ** |
| 67 | ** Returns void |
| 68 | ** |
| 69 | *******************************************************************************/ |
| 70 | void btm_acl_init (void) |
| 71 | { |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 72 | BTM_TRACE_DEBUG ("btm_acl_init"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 73 | #if 0 /* cleared in btm_init; put back in if called from anywhere else! */ |
| 74 | memset (&btm_cb.acl_db, 0, sizeof (btm_cb.acl_db)); |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 75 | memset (btm_cb.btm_scn, 0, BTM_MAX_SCN); /* Initialize the SCN usage to false */ |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 76 | btm_cb.btm_def_link_policy = 0; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 77 | btm_cb.p_bl_changed_cb = NULL; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 78 | #endif |
| 79 | |
| 80 | /* Initialize nonzero defaults */ |
| 81 | btm_cb.btm_def_link_super_tout = HCI_DEFAULT_INACT_TOUT; |
| 82 | btm_cb.acl_disc_reason = 0xff ; |
| 83 | } |
| 84 | |
| 85 | /******************************************************************************* |
| 86 | ** |
| 87 | ** Function btm_bda_to_acl |
| 88 | ** |
| 89 | ** Description This function returns the FIRST acl_db entry for the passed BDA. |
| 90 | ** |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 91 | ** Parameters bda : BD address of the remote device |
| 92 | ** transport : Physical transport used for ACL connection (BR/EDR or LE) |
| 93 | ** |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 94 | ** Returns Returns pointer to the ACL DB for the requested BDA if found. |
| 95 | ** NULL if not found. |
| 96 | ** |
| 97 | *******************************************************************************/ |
Jakub Pawlowski | 063ca02 | 2016-04-25 10:43:02 -0700 | [diff] [blame] | 98 | tACL_CONN *btm_bda_to_acl (const BD_ADDR bda, tBT_TRANSPORT transport) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 99 | { |
| 100 | tACL_CONN *p = &btm_cb.acl_db[0]; |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 101 | uint16_t xx; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 102 | if (bda) |
| 103 | { |
| 104 | for (xx = 0; xx < MAX_L2CAP_LINKS; xx++, p++) |
| 105 | { |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 106 | if ((p->in_use) && (!memcmp (p->remote_addr, bda, BD_ADDR_LEN)) |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 107 | #if (BLE_INCLUDED == TRUE) |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 108 | && p->transport == transport |
| 109 | #endif |
| 110 | ) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 111 | { |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 112 | BTM_TRACE_DEBUG ("btm_bda_to_acl found"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 113 | return(p); |
| 114 | } |
| 115 | } |
| 116 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 117 | |
| 118 | /* If here, no BD Addr found */ |
| 119 | return((tACL_CONN *)NULL); |
| 120 | } |
| 121 | |
| 122 | /******************************************************************************* |
| 123 | ** |
| 124 | ** Function btm_handle_to_acl_index |
| 125 | ** |
| 126 | ** Description This function returns the FIRST acl_db entry for the passed hci_handle. |
| 127 | ** |
| 128 | ** Returns index to the acl_db or MAX_L2CAP_LINKS. |
| 129 | ** |
| 130 | *******************************************************************************/ |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 131 | uint8_t btm_handle_to_acl_index (uint16_t hci_handle) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 132 | { |
| 133 | tACL_CONN *p = &btm_cb.acl_db[0]; |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 134 | uint8_t xx; |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 135 | BTM_TRACE_DEBUG ("btm_handle_to_acl_index"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 136 | for (xx = 0; xx < MAX_L2CAP_LINKS; xx++, p++) |
| 137 | { |
| 138 | if ((p->in_use) && (p->hci_handle == hci_handle)) |
| 139 | { |
| 140 | break; |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | /* If here, no BD Addr found */ |
| 145 | return(xx); |
| 146 | } |
Zhihai Xu | 8b35b3f | 2014-03-11 15:01:45 -0700 | [diff] [blame] | 147 | |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 148 | #if (BLE_PRIVACY_SPT == TRUE) |
Zhihai Xu | 8b35b3f | 2014-03-11 15:01:45 -0700 | [diff] [blame] | 149 | /******************************************************************************* |
| 150 | ** |
| 151 | ** Function btm_ble_get_acl_remote_addr |
| 152 | ** |
| 153 | ** Description This function reads the active remote address used for the |
| 154 | ** connection. |
| 155 | ** |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 156 | ** Returns success return true, otherwise false. |
Zhihai Xu | 8b35b3f | 2014-03-11 15:01:45 -0700 | [diff] [blame] | 157 | ** |
| 158 | *******************************************************************************/ |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 159 | bool btm_ble_get_acl_remote_addr(tBTM_SEC_DEV_REC *p_dev_rec, BD_ADDR conn_addr, |
Zhihai Xu | 8b35b3f | 2014-03-11 15:01:45 -0700 | [diff] [blame] | 160 | tBLE_ADDR_TYPE *p_addr_type) |
| 161 | { |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 162 | #if (BLE_INCLUDED == TRUE) |
| 163 | bool st = true; |
Zhihai Xu | 8b35b3f | 2014-03-11 15:01:45 -0700 | [diff] [blame] | 164 | |
| 165 | if (p_dev_rec == NULL) |
| 166 | { |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 167 | BTM_TRACE_ERROR("btm_ble_get_acl_remote_addr can not find device with matching address"); |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 168 | return false; |
Zhihai Xu | 8b35b3f | 2014-03-11 15:01:45 -0700 | [diff] [blame] | 169 | } |
| 170 | |
| 171 | switch (p_dev_rec->ble.active_addr_type) |
| 172 | { |
| 173 | case BTM_BLE_ADDR_PSEUDO: |
| 174 | memcpy(conn_addr, p_dev_rec->bd_addr, BD_ADDR_LEN); |
| 175 | * p_addr_type = p_dev_rec->ble.ble_addr_type; |
| 176 | break; |
| 177 | |
| 178 | case BTM_BLE_ADDR_RRA: |
| 179 | memcpy(conn_addr, p_dev_rec->ble.cur_rand_addr, BD_ADDR_LEN); |
| 180 | * p_addr_type = BLE_ADDR_RANDOM; |
| 181 | break; |
| 182 | |
| 183 | case BTM_BLE_ADDR_STATIC: |
| 184 | memcpy(conn_addr, p_dev_rec->ble.static_addr, BD_ADDR_LEN); |
| 185 | * p_addr_type = p_dev_rec->ble.static_addr_type; |
| 186 | break; |
| 187 | |
| 188 | default: |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 189 | BTM_TRACE_ERROR("Unknown active address: %d", p_dev_rec->ble.active_addr_type); |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 190 | st = false; |
Zhihai Xu | 8b35b3f | 2014-03-11 15:01:45 -0700 | [diff] [blame] | 191 | break; |
| 192 | } |
| 193 | |
| 194 | return st; |
| 195 | #else |
Mike J. Chen | 5be3cb0 | 2014-04-01 12:52:09 -0700 | [diff] [blame] | 196 | UNUSED(p_dev_rec); |
| 197 | UNUSED(conn_addr); |
| 198 | UNUSED(p_addr_type); |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 199 | return false; |
Zhihai Xu | 8b35b3f | 2014-03-11 15:01:45 -0700 | [diff] [blame] | 200 | #endif |
| 201 | } |
| 202 | #endif |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 203 | /******************************************************************************* |
| 204 | ** |
| 205 | ** Function btm_acl_created |
| 206 | ** |
| 207 | ** Description This function is called by L2CAP when an ACL connection |
| 208 | ** is created. |
| 209 | ** |
| 210 | ** Returns void |
| 211 | ** |
| 212 | *******************************************************************************/ |
| 213 | void btm_acl_created (BD_ADDR bda, DEV_CLASS dc, BD_NAME bdn, |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 214 | uint16_t hci_handle, uint8_t link_role, tBT_TRANSPORT transport) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 215 | { |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 216 | tBTM_SEC_DEV_REC *p_dev_rec = NULL; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 217 | tACL_CONN *p; |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 218 | uint8_t xx; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 219 | |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 220 | BTM_TRACE_DEBUG ("btm_acl_created hci_handle=%d link_role=%d transport=%d", |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 221 | hci_handle,link_role, transport); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 222 | /* Ensure we don't have duplicates */ |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 223 | p = btm_bda_to_acl(bda, transport); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 224 | if (p != (tACL_CONN *)NULL) |
| 225 | { |
| 226 | p->hci_handle = hci_handle; |
| 227 | p->link_role = link_role; |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 228 | #if (BLE_INCLUDED == TRUE) |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 229 | p->transport = transport; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 230 | #endif |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 231 | BTM_TRACE_DEBUG ("Duplicate btm_acl_created: RemBdAddr: %02x%02x%02x%02x%02x%02x", |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 232 | bda[0], bda[1], bda[2], bda[3], bda[4], bda[5]); |
| 233 | BTM_SetLinkPolicy(p->remote_addr, &btm_cb.btm_def_link_policy); |
| 234 | return; |
| 235 | } |
| 236 | |
| 237 | /* Allocate acl_db entry */ |
| 238 | for (xx = 0, p = &btm_cb.acl_db[0]; xx < MAX_L2CAP_LINKS; xx++, p++) |
| 239 | { |
| 240 | if (!p->in_use) |
| 241 | { |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 242 | p->in_use = true; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 243 | p->hci_handle = hci_handle; |
| 244 | p->link_role = link_role; |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 245 | p->link_up_issued = false; |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 246 | memcpy (p->remote_addr, bda, BD_ADDR_LEN); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 247 | |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 248 | #if (BLE_INCLUDED == TRUE) |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 249 | p->transport = transport; |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 250 | #if (BLE_PRIVACY_SPT == TRUE) |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 251 | if (transport == BT_TRANSPORT_LE) |
| 252 | btm_ble_refresh_local_resolvable_private_addr(bda, |
| 253 | btm_cb.ble_ctr_cb.addr_mgnt_cb.private_addr); |
Andre Eisenbach | 4609a03 | 2015-04-23 22:19:59 -0700 | [diff] [blame] | 254 | #else |
| 255 | p->conn_addr_type = BLE_ADDR_PUBLIC; |
| 256 | memcpy(p->conn_addr, &controller_get_interface()->get_address()->address, BD_ADDR_LEN); |
| 257 | |
Priti Aghera | 817eec2 | 2014-08-12 14:31:28 -0700 | [diff] [blame] | 258 | #endif |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 259 | #endif |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 260 | p->switch_role_state = BTM_ACL_SWKEY_STATE_IDLE; |
| 261 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 262 | btm_pm_sm_alloc(xx); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 263 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 264 | |
| 265 | if (dc) |
| 266 | memcpy (p->remote_dc, dc, DEV_CLASS_LEN); |
| 267 | |
| 268 | if (bdn) |
| 269 | memcpy (p->remote_name, bdn, BTM_MAX_REM_BD_NAME_LEN); |
| 270 | |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 271 | /* if BR/EDR do something more */ |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 272 | if (transport == BT_TRANSPORT_BR_EDR) |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 273 | { |
| 274 | btsnd_hcic_read_rmt_clk_offset (p->hci_handle); |
Andre Eisenbach | 284ff6b | 2015-10-29 15:48:06 -0700 | [diff] [blame] | 275 | btsnd_hcic_rmt_ver_req (p->hci_handle); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 276 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 277 | p_dev_rec = btm_find_dev_by_handle (hci_handle); |
| 278 | |
| 279 | #if (BLE_INCLUDED == TRUE) |
| 280 | if (p_dev_rec ) |
| 281 | { |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 282 | BTM_TRACE_DEBUG ("device_type=0x%x", p_dev_rec->device_type); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 283 | } |
| 284 | #endif |
| 285 | |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 286 | if (p_dev_rec && !(transport == BT_TRANSPORT_LE)) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 287 | { |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 288 | /* If remote features already known, copy them and continue connection setup */ |
| 289 | if ((p_dev_rec->num_read_pages) && |
Mudumba Ananth | 899b771 | 2015-01-30 02:33:02 -0800 | [diff] [blame] | 290 | (p_dev_rec->num_read_pages <= (HCI_EXT_FEATURES_PAGE_MAX + 1))) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 291 | { |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 292 | memcpy (p->peer_lmp_features, p_dev_rec->features, |
| 293 | (HCI_FEATURE_BYTES_PER_PAGE * p_dev_rec->num_read_pages)); |
| 294 | 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] | 295 | |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 296 | const uint8_t req_pend = (p_dev_rec->sm4 & BTM_SM4_REQ_PEND); |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 297 | |
Mudumba Ananth | 899b771 | 2015-01-30 02:33:02 -0800 | [diff] [blame] | 298 | /* Store the Peer Security Capabilites (in SM4 and rmt_sec_caps) */ |
| 299 | btm_sec_set_peer_sec_caps(p, p_dev_rec); |
| 300 | |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 301 | BTM_TRACE_API("%s: pend:%d", __func__, req_pend); |
Mudumba Ananth | 899b771 | 2015-01-30 02:33:02 -0800 | [diff] [blame] | 302 | if (req_pend) |
| 303 | { |
| 304 | /* Request for remaining Security Features (if any) */ |
| 305 | l2cu_resubmit_pending_sec_req (p_dev_rec->bd_addr); |
| 306 | } |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 307 | btm_establish_continue (p); |
| 308 | return; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 309 | } |
| 310 | } |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 311 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 312 | #if (BLE_INCLUDED == TRUE) |
| 313 | /* If here, features are not known yet */ |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 314 | if (p_dev_rec && transport == BT_TRANSPORT_LE) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 315 | { |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 316 | #if (BLE_PRIVACY_SPT == TRUE) |
Zhihai Xu | 8b35b3f | 2014-03-11 15:01:45 -0700 | [diff] [blame] | 317 | btm_ble_get_acl_remote_addr (p_dev_rec, p->active_remote_addr, |
| 318 | &p->active_remote_addr_type); |
| 319 | #endif |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 320 | |
Zach Johnson | 30e5806 | 2014-09-26 21:14:34 -0700 | [diff] [blame] | 321 | if (HCI_LE_SLAVE_INIT_FEAT_EXC_SUPPORTED(controller_get_interface()->get_features_ble()->as_array) |
Priti Aghera | 9c29d08 | 2014-09-02 15:41:56 -0700 | [diff] [blame] | 322 | || link_role == HCI_ROLE_MASTER) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 323 | { |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 324 | btsnd_hcic_ble_read_remote_feat(p->hci_handle); |
| 325 | } |
Priti Aghera | 9c29d08 | 2014-09-02 15:41:56 -0700 | [diff] [blame] | 326 | else |
Prerepa Viswanadham | 7ae2515 | 2014-09-10 17:08:11 -0700 | [diff] [blame] | 327 | { |
| 328 | btm_establish_continue(p); |
| 329 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 330 | } |
| 331 | else |
| 332 | #endif |
| 333 | { |
Matthew Xie | c2bb2c1 | 2013-04-09 11:26:08 -0700 | [diff] [blame] | 334 | btm_read_remote_features (p->hci_handle); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 335 | } |
| 336 | |
| 337 | /* read page 1 - on rmt feature event for buffer reasons */ |
| 338 | return; |
| 339 | } |
| 340 | } |
| 341 | } |
| 342 | |
| 343 | |
| 344 | /******************************************************************************* |
| 345 | ** |
| 346 | ** Function btm_acl_report_role_change |
| 347 | ** |
| 348 | ** Description This function is called when the local device is deemed |
| 349 | ** to be down. It notifies L2CAP of the failure. |
| 350 | ** |
| 351 | ** Returns void |
| 352 | ** |
| 353 | *******************************************************************************/ |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 354 | void btm_acl_report_role_change (uint8_t hci_status, BD_ADDR bda) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 355 | { |
| 356 | tBTM_ROLE_SWITCH_CMPL ref_data; |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 357 | BTM_TRACE_DEBUG ("btm_acl_report_role_change"); |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 358 | if (btm_cb.devcb.p_switch_role_cb |
| 359 | && (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] | 360 | { |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 361 | 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] | 362 | ref_data.hci_status = hci_status; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 363 | (*btm_cb.devcb.p_switch_role_cb)(&ref_data); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 364 | 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] | 365 | btm_cb.devcb.p_switch_role_cb = NULL; |
| 366 | } |
| 367 | } |
| 368 | |
| 369 | /******************************************************************************* |
| 370 | ** |
| 371 | ** Function btm_acl_removed |
| 372 | ** |
| 373 | ** Description This function is called by L2CAP when an ACL connection |
| 374 | ** is removed. Since only L2CAP creates ACL links, we use |
| 375 | ** the L2CAP link index as our index into the control blocks. |
| 376 | ** |
| 377 | ** Returns void |
| 378 | ** |
| 379 | *******************************************************************************/ |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 380 | void btm_acl_removed (BD_ADDR bda, tBT_TRANSPORT transport) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 381 | { |
| 382 | tACL_CONN *p; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 383 | tBTM_BL_EVENT_DATA evt_data; |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 384 | #if (BLE_INCLUDED == TRUE) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 385 | tBTM_SEC_DEV_REC *p_dev_rec=NULL; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 386 | #endif |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 387 | BTM_TRACE_DEBUG ("btm_acl_removed"); |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 388 | p = btm_bda_to_acl(bda, transport); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 389 | if (p != (tACL_CONN *)NULL) |
| 390 | { |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 391 | p->in_use = false; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 392 | |
| 393 | /* if the disconnected channel has a pending role switch, clear it now */ |
| 394 | btm_acl_report_role_change(HCI_ERR_NO_CONNECTION, bda); |
| 395 | |
| 396 | /* Only notify if link up has had a chance to be issued */ |
| 397 | if (p->link_up_issued) |
| 398 | { |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 399 | p->link_up_issued = false; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 400 | |
| 401 | /* If anyone cares, tell him database changed */ |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 402 | if (btm_cb.p_bl_changed_cb) |
| 403 | { |
| 404 | evt_data.event = BTM_BL_DISCN_EVT; |
| 405 | evt_data.discn.p_bda = bda; |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 406 | #if (BLE_INCLUDED == TRUE) |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 407 | evt_data.discn.handle = p->hci_handle; |
| 408 | evt_data.discn.transport = p->transport; |
| 409 | #endif |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 410 | (*btm_cb.p_bl_changed_cb)(&evt_data); |
| 411 | } |
| 412 | |
| 413 | btm_acl_update_busy_level (BTM_BLI_ACL_DOWN_EVT); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 414 | } |
| 415 | |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 416 | #if (BLE_INCLUDED == TRUE) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 417 | |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 418 | BTM_TRACE_DEBUG ("acl hci_handle=%d transport=%d connectable_mode=0x%0x link_role=%d", |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 419 | p->hci_handle, |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 420 | p->transport, |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 421 | btm_cb.ble_ctr_cb.inq_var.connectable_mode, |
| 422 | p->link_role); |
| 423 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 424 | p_dev_rec = btm_find_dev(bda); |
| 425 | if ( p_dev_rec) |
| 426 | { |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 427 | BTM_TRACE_DEBUG("before update p_dev_rec->sec_flags=0x%x", p_dev_rec->sec_flags); |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 428 | if (p->transport == BT_TRANSPORT_LE) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 429 | { |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 430 | BTM_TRACE_DEBUG("LE link down"); |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 431 | p_dev_rec->sec_flags &= ~(BTM_SEC_LE_ENCRYPTED | BTM_SEC_ROLE_SWITCHED); |
| 432 | if ( (p_dev_rec->sec_flags & BTM_SEC_LE_LINK_KEY_KNOWN) == 0) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 433 | { |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 434 | BTM_TRACE_DEBUG("Not Bonded"); |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 435 | p_dev_rec->sec_flags &= ~(BTM_SEC_LE_LINK_KEY_AUTHED | BTM_SEC_LE_AUTHENTICATED); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 436 | } |
| 437 | else |
| 438 | { |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 439 | BTM_TRACE_DEBUG("Bonded"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 440 | } |
| 441 | } |
| 442 | else |
| 443 | { |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 444 | BTM_TRACE_DEBUG("Bletooth link down"); |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 445 | p_dev_rec->sec_flags &= ~(BTM_SEC_AUTHORIZED | BTM_SEC_AUTHENTICATED |
| 446 | | BTM_SEC_ENCRYPTED | BTM_SEC_ROLE_SWITCHED); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 447 | } |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 448 | BTM_TRACE_DEBUG("after update p_dev_rec->sec_flags=0x%x", p_dev_rec->sec_flags); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 449 | } |
| 450 | else |
| 451 | { |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 452 | BTM_TRACE_ERROR("Device not found"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 453 | |
| 454 | } |
| 455 | #endif |
| 456 | |
Srinu Jella | 8f76635 | 2015-07-03 15:31:11 +0530 | [diff] [blame] | 457 | /* Clear the ACL connection data */ |
| 458 | memset(p, 0, sizeof(tACL_CONN)); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 459 | } |
| 460 | } |
| 461 | |
| 462 | |
| 463 | /******************************************************************************* |
| 464 | ** |
| 465 | ** Function btm_acl_device_down |
| 466 | ** |
| 467 | ** Description This function is called when the local device is deemed |
| 468 | ** to be down. It notifies L2CAP of the failure. |
| 469 | ** |
| 470 | ** Returns void |
| 471 | ** |
| 472 | *******************************************************************************/ |
| 473 | void btm_acl_device_down (void) |
| 474 | { |
| 475 | tACL_CONN *p = &btm_cb.acl_db[0]; |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 476 | uint16_t xx; |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 477 | BTM_TRACE_DEBUG ("btm_acl_device_down"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 478 | for (xx = 0; xx < MAX_L2CAP_LINKS; xx++, p++) |
| 479 | { |
| 480 | if (p->in_use) |
| 481 | { |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 482 | BTM_TRACE_DEBUG ("hci_handle=%d HCI_ERR_HW_FAILURE ",p->hci_handle ); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 483 | l2c_link_hci_disc_comp (p->hci_handle, HCI_ERR_HW_FAILURE); |
| 484 | } |
| 485 | } |
| 486 | } |
| 487 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 488 | /******************************************************************************* |
| 489 | ** |
| 490 | ** Function btm_acl_update_busy_level |
| 491 | ** |
| 492 | ** Description This function is called to update the busy level of the system |
| 493 | ** . |
| 494 | ** |
| 495 | ** Returns void |
| 496 | ** |
| 497 | *******************************************************************************/ |
| 498 | void btm_acl_update_busy_level (tBTM_BLI_EVENT event) |
| 499 | { |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 500 | bool old_inquiry_state = btm_cb.is_inquiry; |
Sharvil Nanavati | 73e73fa | 2016-04-10 17:29:11 -0700 | [diff] [blame] | 501 | tBTM_BL_UPDATE_DATA evt; |
| 502 | evt.busy_level_flags = 0; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 503 | switch (event) |
| 504 | { |
| 505 | case BTM_BLI_ACL_UP_EVT: |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 506 | BTM_TRACE_DEBUG ("BTM_BLI_ACL_UP_EVT"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 507 | break; |
| 508 | case BTM_BLI_ACL_DOWN_EVT: |
Andre Eisenbach | f4c4b78 | 2015-03-19 15:15:05 -0700 | [diff] [blame] | 509 | BTM_TRACE_DEBUG ("BTM_BLI_ACL_DOWN_EVT"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 510 | break; |
| 511 | case BTM_BLI_PAGE_EVT: |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 512 | BTM_TRACE_DEBUG ("BTM_BLI_PAGE_EVT"); |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 513 | btm_cb.is_paging = true; |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 514 | evt.busy_level_flags= BTM_BL_PAGING_STARTED; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 515 | break; |
| 516 | case BTM_BLI_PAGE_DONE_EVT: |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 517 | BTM_TRACE_DEBUG ("BTM_BLI_PAGE_DONE_EVT"); |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 518 | btm_cb.is_paging = false; |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 519 | evt.busy_level_flags = BTM_BL_PAGING_COMPLETE; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 520 | break; |
| 521 | case BTM_BLI_INQ_EVT: |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 522 | BTM_TRACE_DEBUG ("BTM_BLI_INQ_EVT"); |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 523 | btm_cb.is_inquiry = true; |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 524 | evt.busy_level_flags = BTM_BL_INQUIRY_STARTED; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 525 | break; |
| 526 | case BTM_BLI_INQ_CANCEL_EVT: |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 527 | BTM_TRACE_DEBUG ("BTM_BLI_INQ_CANCEL_EVT"); |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 528 | btm_cb.is_inquiry = false; |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 529 | evt.busy_level_flags = BTM_BL_INQUIRY_CANCELLED; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 530 | break; |
| 531 | case BTM_BLI_INQ_DONE_EVT: |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 532 | BTM_TRACE_DEBUG ("BTM_BLI_INQ_DONE_EVT"); |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 533 | btm_cb.is_inquiry = false; |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 534 | evt.busy_level_flags = BTM_BL_INQUIRY_COMPLETE; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 535 | break; |
| 536 | } |
| 537 | |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 538 | uint8_t busy_level; |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 539 | if (btm_cb.is_paging || btm_cb.is_inquiry) |
| 540 | busy_level = 10; |
| 541 | else |
Andre Eisenbach | f4c4b78 | 2015-03-19 15:15:05 -0700 | [diff] [blame] | 542 | busy_level = BTM_GetNumAclLinks(); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 543 | |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 544 | if ((busy_level != btm_cb.busy_level) ||(old_inquiry_state != btm_cb.is_inquiry)) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 545 | { |
| 546 | evt.event = BTM_BL_UPDATE_EVT; |
| 547 | evt.busy_level = busy_level; |
| 548 | btm_cb.busy_level = busy_level; |
| 549 | if (btm_cb.p_bl_changed_cb && (btm_cb.bl_evt_mask & BTM_BL_UPDATE_MASK)) |
| 550 | { |
| 551 | (*btm_cb.p_bl_changed_cb)((tBTM_BL_EVENT_DATA *)&evt); |
| 552 | } |
| 553 | } |
| 554 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 555 | |
| 556 | /******************************************************************************* |
| 557 | ** |
| 558 | ** Function BTM_GetRole |
| 559 | ** |
| 560 | ** Description This function is called to get the role of the local device |
| 561 | ** for the ACL connection with the specified remote device |
| 562 | ** |
| 563 | ** Returns BTM_SUCCESS if connection exists. |
| 564 | ** BTM_UNKNOWN_ADDR if no active link with bd addr specified |
| 565 | ** |
| 566 | *******************************************************************************/ |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 567 | tBTM_STATUS BTM_GetRole (BD_ADDR remote_bd_addr, uint8_t *p_role) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 568 | { |
| 569 | tACL_CONN *p; |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 570 | BTM_TRACE_DEBUG ("BTM_GetRole"); |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 571 | if ((p = btm_bda_to_acl(remote_bd_addr, BT_TRANSPORT_BR_EDR)) == NULL) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 572 | { |
| 573 | *p_role = BTM_ROLE_UNDEFINED; |
| 574 | return(BTM_UNKNOWN_ADDR); |
| 575 | } |
| 576 | |
| 577 | /* Get the current role */ |
| 578 | *p_role = p->link_role; |
| 579 | return(BTM_SUCCESS); |
| 580 | } |
| 581 | |
| 582 | |
| 583 | /******************************************************************************* |
| 584 | ** |
| 585 | ** Function BTM_SwitchRole |
| 586 | ** |
| 587 | ** Description This function is called to switch role between master and |
| 588 | ** slave. If role is already set it will do nothing. If the |
| 589 | ** command was initiated, the callback function is called upon |
| 590 | ** completion. |
| 591 | ** |
| 592 | ** Returns BTM_SUCCESS if already in specified role. |
| 593 | ** BTM_CMD_STARTED if command issued to controller. |
| 594 | ** BTM_NO_RESOURCES if couldn't allocate memory to issue command |
| 595 | ** BTM_UNKNOWN_ADDR if no active link with bd addr specified |
| 596 | ** BTM_MODE_UNSUPPORTED if local device does not support role switching |
| 597 | ** BTM_BUSY if the previous command is not completed |
| 598 | ** |
| 599 | *******************************************************************************/ |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 600 | tBTM_STATUS BTM_SwitchRole (BD_ADDR remote_bd_addr, uint8_t new_role, tBTM_CMPL_CB *p_cb) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 601 | { |
| 602 | tACL_CONN *p; |
| 603 | tBTM_SEC_DEV_REC *p_dev_rec = NULL; |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 604 | #if (BTM_SCO_INCLUDED == TRUE) |
| 605 | bool is_sco_active; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 606 | #endif |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 607 | tBTM_STATUS status; |
| 608 | tBTM_PM_MODE pwr_mode; |
| 609 | tBTM_PM_PWR_MD settings; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 610 | #if (BT_USE_TRACES == TRUE) |
| 611 | BD_ADDR_PTR p_bda; |
| 612 | #endif |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 613 | BTM_TRACE_API ("BTM_SwitchRole BDA: %02x-%02x-%02x-%02x-%02x-%02x", |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 614 | remote_bd_addr[0], remote_bd_addr[1], remote_bd_addr[2], |
| 615 | remote_bd_addr[3], remote_bd_addr[4], remote_bd_addr[5]); |
| 616 | |
| 617 | /* Make sure the local device supports switching */ |
Zach Johnson | 30e5806 | 2014-09-26 21:14:34 -0700 | [diff] [blame] | 618 | if (!controller_get_interface()->supports_master_slave_role_switch()) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 619 | return(BTM_MODE_UNSUPPORTED); |
| 620 | |
| 621 | if (btm_cb.devcb.p_switch_role_cb && p_cb) |
| 622 | { |
| 623 | #if (BT_USE_TRACES == TRUE) |
| 624 | p_bda = btm_cb.devcb.switch_role_ref_data.remote_bd_addr; |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 625 | BTM_TRACE_DEBUG ("Role switch on other device is in progress 0x%02x%02x%02x%02x%02x%02x", |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 626 | p_bda[0], p_bda[1], p_bda[2], |
| 627 | p_bda[3], p_bda[4], p_bda[5]); |
| 628 | #endif |
| 629 | return(BTM_BUSY); |
| 630 | } |
| 631 | |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 632 | if ((p = btm_bda_to_acl(remote_bd_addr, BT_TRANSPORT_BR_EDR)) == NULL) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 633 | return(BTM_UNKNOWN_ADDR); |
| 634 | |
| 635 | /* Finished if already in desired role */ |
| 636 | if (p->link_role == new_role) |
| 637 | return(BTM_SUCCESS); |
| 638 | |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 639 | #if (BTM_SCO_INCLUDED == TRUE) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 640 | /* Check if there is any SCO Active on this BD Address */ |
| 641 | is_sco_active = btm_is_sco_active_by_bdaddr(remote_bd_addr); |
| 642 | |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 643 | if (is_sco_active == true) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 644 | return(BTM_NO_RESOURCES); |
| 645 | #endif |
| 646 | |
| 647 | /* Ignore role switch request if the previous request was not completed */ |
| 648 | if (p->switch_role_state != BTM_ACL_SWKEY_STATE_IDLE) |
| 649 | { |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 650 | BTM_TRACE_DEBUG ("BTM_SwitchRole busy: %d", |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 651 | p->switch_role_state); |
| 652 | return(BTM_BUSY); |
| 653 | } |
| 654 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 655 | if ((status = BTM_ReadPowerMode(p->remote_addr, &pwr_mode)) != BTM_SUCCESS) |
| 656 | return(status); |
| 657 | |
| 658 | /* Wake up the link if in sniff or park before attempting switch */ |
| 659 | if (pwr_mode == BTM_PM_MD_PARK || pwr_mode == BTM_PM_MD_SNIFF) |
| 660 | { |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 661 | memset( (void*)&settings, 0, sizeof(settings)); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 662 | settings.mode = BTM_PM_MD_ACTIVE; |
| 663 | status = BTM_SetPowerMode (BTM_PM_SET_ONLY_ID, p->remote_addr, &settings); |
| 664 | if (status != BTM_CMD_STARTED) |
| 665 | return(BTM_WRONG_MODE); |
| 666 | |
| 667 | p->switch_role_state = BTM_ACL_SWKEY_STATE_MODE_CHANGE; |
| 668 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 669 | /* some devices do not support switch while encryption is on */ |
| 670 | else |
| 671 | { |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 672 | p_dev_rec = btm_find_dev (remote_bd_addr); |
| 673 | if ((p_dev_rec != NULL) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 674 | && ((p_dev_rec->sec_flags & BTM_SEC_ENCRYPTED) != 0) |
| 675 | && !BTM_EPR_AVAILABLE(p)) |
| 676 | { |
| 677 | /* bypass turning off encryption if change link key is already doing it */ |
| 678 | if (p->encrypt_state != BTM_ACL_ENCRYPT_STATE_ENCRYPT_OFF) |
| 679 | { |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 680 | if (!btsnd_hcic_set_conn_encrypt (p->hci_handle, false)) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 681 | return(BTM_NO_RESOURCES); |
| 682 | else |
| 683 | p->encrypt_state = BTM_ACL_ENCRYPT_STATE_ENCRYPT_OFF; |
| 684 | } |
| 685 | |
| 686 | p->switch_role_state = BTM_ACL_SWKEY_STATE_ENCRYPTION_OFF; |
| 687 | } |
| 688 | else |
| 689 | { |
| 690 | if (!btsnd_hcic_switch_role (remote_bd_addr, new_role)) |
| 691 | return(BTM_NO_RESOURCES); |
| 692 | |
| 693 | p->switch_role_state = BTM_ACL_SWKEY_STATE_IN_PROGRESS; |
| 694 | |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 695 | #if (BTM_DISC_DURING_RS == TRUE) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 696 | if (p_dev_rec) |
| 697 | p_dev_rec->rs_disc_pending = BTM_SEC_RS_PENDING; |
| 698 | #endif |
| 699 | } |
| 700 | } |
| 701 | |
| 702 | /* Initialize return structure in case request fails */ |
| 703 | if (p_cb) |
| 704 | { |
| 705 | memcpy (btm_cb.devcb.switch_role_ref_data.remote_bd_addr, remote_bd_addr, |
| 706 | BD_ADDR_LEN); |
| 707 | btm_cb.devcb.switch_role_ref_data.role = new_role; |
| 708 | /* initialized to an error code */ |
| 709 | btm_cb.devcb.switch_role_ref_data.hci_status = HCI_ERR_UNSUPPORTED_VALUE; |
| 710 | btm_cb.devcb.p_switch_role_cb = p_cb; |
| 711 | } |
| 712 | return(BTM_CMD_STARTED); |
| 713 | } |
| 714 | |
| 715 | /******************************************************************************* |
| 716 | ** |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 717 | ** Function btm_acl_encrypt_change |
| 718 | ** |
| 719 | ** Description This function is when encryption of the connection is |
| 720 | ** completed by the LM. Checks to see if a role switch or |
| 721 | ** change of link key was active and initiates or continues |
| 722 | ** process if needed. |
| 723 | ** |
| 724 | ** Returns void |
| 725 | ** |
| 726 | *******************************************************************************/ |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 727 | void btm_acl_encrypt_change (uint16_t handle, uint8_t status, uint8_t encr_enable) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 728 | { |
| 729 | tACL_CONN *p; |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 730 | uint8_t xx; |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 731 | tBTM_SEC_DEV_REC *p_dev_rec; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 732 | tBTM_BL_ROLE_CHG_DATA evt; |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 733 | |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 734 | BTM_TRACE_DEBUG ("btm_acl_encrypt_change handle=%d status=%d encr_enabl=%d", |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 735 | handle, status, encr_enable); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 736 | xx = btm_handle_to_acl_index(handle); |
| 737 | /* don't assume that we can never get a bad hci_handle */ |
| 738 | if (xx < MAX_L2CAP_LINKS) |
| 739 | p = &btm_cb.acl_db[xx]; |
| 740 | else |
| 741 | return; |
| 742 | |
| 743 | /* Process Role Switch if active */ |
| 744 | if (p->switch_role_state == BTM_ACL_SWKEY_STATE_ENCRYPTION_OFF) |
| 745 | { |
| 746 | /* if encryption turn off failed we still will try to switch role */ |
| 747 | if (encr_enable) |
| 748 | { |
| 749 | p->switch_role_state = BTM_ACL_SWKEY_STATE_IDLE; |
| 750 | p->encrypt_state = BTM_ACL_ENCRYPT_STATE_IDLE; |
| 751 | } |
| 752 | else |
| 753 | { |
| 754 | p->switch_role_state = BTM_ACL_SWKEY_STATE_SWITCHING; |
| 755 | p->encrypt_state = BTM_ACL_ENCRYPT_STATE_TEMP_FUNC; |
| 756 | } |
| 757 | |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 758 | if (!btsnd_hcic_switch_role (p->remote_addr, (uint8_t)!p->link_role)) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 759 | { |
| 760 | p->switch_role_state = BTM_ACL_SWKEY_STATE_IDLE; |
| 761 | p->encrypt_state = BTM_ACL_ENCRYPT_STATE_IDLE; |
| 762 | btm_acl_report_role_change(btm_cb.devcb.switch_role_ref_data.hci_status, p->remote_addr); |
| 763 | } |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 764 | #if (BTM_DISC_DURING_RS == TRUE) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 765 | else |
| 766 | { |
| 767 | if ((p_dev_rec = btm_find_dev (p->remote_addr)) != NULL) |
| 768 | p_dev_rec->rs_disc_pending = BTM_SEC_RS_PENDING; |
| 769 | } |
| 770 | #endif |
| 771 | |
| 772 | } |
| 773 | /* Finished enabling Encryption after role switch */ |
| 774 | else if (p->switch_role_state == BTM_ACL_SWKEY_STATE_ENCRYPTION_ON) |
| 775 | { |
| 776 | p->switch_role_state = BTM_ACL_SWKEY_STATE_IDLE; |
| 777 | p->encrypt_state = BTM_ACL_ENCRYPT_STATE_IDLE; |
| 778 | btm_acl_report_role_change(btm_cb.devcb.switch_role_ref_data.hci_status, p->remote_addr); |
| 779 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 780 | /* if role change event is registered, report it now */ |
| 781 | if (btm_cb.p_bl_changed_cb && (btm_cb.bl_evt_mask & BTM_BL_ROLE_CHG_MASK)) |
| 782 | { |
| 783 | evt.event = BTM_BL_ROLE_CHG_EVT; |
| 784 | evt.new_role = btm_cb.devcb.switch_role_ref_data.role; |
| 785 | evt.p_bda = btm_cb.devcb.switch_role_ref_data.remote_bd_addr; |
| 786 | evt.hci_status = btm_cb.devcb.switch_role_ref_data.hci_status; |
| 787 | (*btm_cb.p_bl_changed_cb)((tBTM_BL_EVENT_DATA *)&evt); |
| 788 | |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 789 | BTM_TRACE_DEBUG("Role Switch Event: new_role 0x%02x, HCI Status 0x%02x, rs_st:%d", |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 790 | evt.new_role, evt.hci_status, p->switch_role_state); |
| 791 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 792 | |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 793 | #if (BTM_DISC_DURING_RS == TRUE) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 794 | /* If a disconnect is pending, issue it now that role switch has completed */ |
| 795 | if ((p_dev_rec = btm_find_dev (p->remote_addr)) != NULL) |
| 796 | { |
| 797 | if (p_dev_rec->rs_disc_pending == BTM_SEC_DISC_PENDING) |
| 798 | { |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 799 | BTM_TRACE_WARNING("btm_acl_encrypt_change -> Issuing delayed HCI_Disconnect!!!"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 800 | btsnd_hcic_disconnect(p_dev_rec->hci_handle, HCI_ERR_PEER_USER); |
| 801 | } |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 802 | BTM_TRACE_ERROR("btm_acl_encrypt_change: tBTM_SEC_DEV:0x%x rs_disc_pending=%d", |
Arman Uguray | bb95452 | 2015-06-02 21:11:07 -0700 | [diff] [blame] | 803 | PTR_TO_UINT(p_dev_rec), p_dev_rec->rs_disc_pending); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 804 | p_dev_rec->rs_disc_pending = BTM_SEC_RS_NOT_PENDING; /* reset flag */ |
| 805 | } |
| 806 | #endif |
| 807 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 808 | } |
| 809 | /******************************************************************************* |
| 810 | ** |
| 811 | ** Function BTM_SetLinkPolicy |
| 812 | ** |
| 813 | ** Description Create and send HCI "Write Policy Set" command |
| 814 | ** |
| 815 | ** Returns status of the operation |
| 816 | ** |
| 817 | *******************************************************************************/ |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 818 | tBTM_STATUS BTM_SetLinkPolicy (BD_ADDR remote_bda, uint16_t *settings) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 819 | { |
| 820 | tACL_CONN *p; |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 821 | uint8_t *localFeatures = BTM_ReadLocalFeatures(); |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 822 | BTM_TRACE_DEBUG ("BTM_SetLinkPolicy"); |
| 823 | /* BTM_TRACE_API ("BTM_SetLinkPolicy: requested settings: 0x%04x", *settings ); */ |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 824 | |
| 825 | /* First, check if hold mode is supported */ |
| 826 | if (*settings != HCI_DISABLE_ALL_LM_MODES) |
| 827 | { |
| 828 | if ( (*settings & HCI_ENABLE_MASTER_SLAVE_SWITCH) && (!HCI_SWITCH_SUPPORTED(localFeatures)) ) |
| 829 | { |
| 830 | *settings &= (~HCI_ENABLE_MASTER_SLAVE_SWITCH); |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 831 | BTM_TRACE_API ("BTM_SetLinkPolicy switch not supported (settings: 0x%04x)", *settings ); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 832 | } |
| 833 | if ( (*settings & HCI_ENABLE_HOLD_MODE) && (!HCI_HOLD_MODE_SUPPORTED(localFeatures)) ) |
| 834 | { |
| 835 | *settings &= (~HCI_ENABLE_HOLD_MODE); |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 836 | BTM_TRACE_API ("BTM_SetLinkPolicy hold not supported (settings: 0x%04x)", *settings ); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 837 | } |
| 838 | if ( (*settings & HCI_ENABLE_SNIFF_MODE) && (!HCI_SNIFF_MODE_SUPPORTED(localFeatures)) ) |
| 839 | { |
| 840 | *settings &= (~HCI_ENABLE_SNIFF_MODE); |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 841 | BTM_TRACE_API ("BTM_SetLinkPolicy sniff not supported (settings: 0x%04x)", *settings ); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 842 | } |
| 843 | if ( (*settings & HCI_ENABLE_PARK_MODE) && (!HCI_PARK_MODE_SUPPORTED(localFeatures)) ) |
| 844 | { |
| 845 | *settings &= (~HCI_ENABLE_PARK_MODE); |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 846 | BTM_TRACE_API ("BTM_SetLinkPolicy park not supported (settings: 0x%04x)", *settings ); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 847 | } |
| 848 | } |
| 849 | |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 850 | if ((p = btm_bda_to_acl(remote_bda, BT_TRANSPORT_BR_EDR)) != NULL) |
| 851 | return(btsnd_hcic_write_policy_set (p->hci_handle, *settings) ? BTM_CMD_STARTED : BTM_NO_RESOURCES); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 852 | |
| 853 | /* If here, no BD Addr found */ |
| 854 | return(BTM_UNKNOWN_ADDR); |
| 855 | } |
| 856 | |
| 857 | /******************************************************************************* |
| 858 | ** |
| 859 | ** Function BTM_SetDefaultLinkPolicy |
| 860 | ** |
| 861 | ** Description Set the default value for HCI "Write Policy Set" command |
| 862 | ** to use when an ACL link is created. |
| 863 | ** |
| 864 | ** Returns void |
| 865 | ** |
| 866 | *******************************************************************************/ |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 867 | void BTM_SetDefaultLinkPolicy (uint16_t settings) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 868 | { |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 869 | uint8_t *localFeatures = BTM_ReadLocalFeatures(); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 870 | |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 871 | BTM_TRACE_DEBUG("BTM_SetDefaultLinkPolicy setting:0x%04x", settings); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 872 | |
| 873 | if((settings & HCI_ENABLE_MASTER_SLAVE_SWITCH) && (!HCI_SWITCH_SUPPORTED(localFeatures))) |
| 874 | { |
| 875 | settings &= ~HCI_ENABLE_MASTER_SLAVE_SWITCH; |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 876 | BTM_TRACE_DEBUG("BTM_SetDefaultLinkPolicy switch not supported (settings: 0x%04x)", settings); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 877 | } |
| 878 | if ((settings & HCI_ENABLE_HOLD_MODE) && (!HCI_HOLD_MODE_SUPPORTED(localFeatures))) |
| 879 | { |
| 880 | settings &= ~HCI_ENABLE_HOLD_MODE; |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 881 | BTM_TRACE_DEBUG("BTM_SetDefaultLinkPolicy hold not supported (settings: 0x%04x)", settings); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 882 | } |
| 883 | if ((settings & HCI_ENABLE_SNIFF_MODE) && (!HCI_SNIFF_MODE_SUPPORTED(localFeatures))) |
| 884 | { |
| 885 | settings &= ~HCI_ENABLE_SNIFF_MODE; |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 886 | BTM_TRACE_DEBUG("BTM_SetDefaultLinkPolicy sniff not supported (settings: 0x%04x)", settings); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 887 | } |
| 888 | if ((settings & HCI_ENABLE_PARK_MODE) && (!HCI_PARK_MODE_SUPPORTED(localFeatures))) |
| 889 | { |
| 890 | settings &= ~HCI_ENABLE_PARK_MODE; |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 891 | BTM_TRACE_DEBUG("BTM_SetDefaultLinkPolicy park not supported (settings: 0x%04x)", settings); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 892 | } |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 893 | BTM_TRACE_DEBUG("Set DefaultLinkPolicy:0x%04x", settings); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 894 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 895 | btm_cb.btm_def_link_policy = settings; |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 896 | |
| 897 | /* Set the default Link Policy of the controller */ |
| 898 | btsnd_hcic_write_def_policy_set(settings); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 899 | } |
| 900 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 901 | /******************************************************************************* |
| 902 | ** |
| 903 | ** Function btm_read_remote_version_complete |
| 904 | ** |
| 905 | ** Description This function is called when the command complete message |
| 906 | ** is received from the HCI for the remote version info. |
| 907 | ** |
| 908 | ** Returns void |
| 909 | ** |
| 910 | *******************************************************************************/ |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 911 | void btm_read_remote_version_complete (uint8_t *p) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 912 | { |
| 913 | tACL_CONN *p_acl_cb = &btm_cb.acl_db[0]; |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 914 | uint8_t status; |
| 915 | uint16_t handle; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 916 | int xx; |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 917 | BTM_TRACE_DEBUG ("btm_read_remote_version_complete"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 918 | |
Andre Eisenbach | 284ff6b | 2015-10-29 15:48:06 -0700 | [diff] [blame] | 919 | STREAM_TO_UINT8 (status, p); |
| 920 | STREAM_TO_UINT16 (handle, p); |
| 921 | |
| 922 | /* Look up the connection by handle and copy features */ |
| 923 | for (xx = 0; xx < MAX_L2CAP_LINKS; xx++, p_acl_cb++) |
| 924 | { |
| 925 | if ((p_acl_cb->in_use) && (p_acl_cb->hci_handle == handle)) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 926 | { |
Andre Eisenbach | 284ff6b | 2015-10-29 15:48:06 -0700 | [diff] [blame] | 927 | if (status == HCI_SUCCESS) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 928 | { |
| 929 | STREAM_TO_UINT8 (p_acl_cb->lmp_version, p); |
| 930 | STREAM_TO_UINT16 (p_acl_cb->manufacturer, p); |
| 931 | STREAM_TO_UINT16 (p_acl_cb->lmp_subversion, p); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 932 | } |
Andre Eisenbach | 284ff6b | 2015-10-29 15:48:06 -0700 | [diff] [blame] | 933 | |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 934 | #if (BLE_INCLUDED == TRUE) |
Andre Eisenbach | 284ff6b | 2015-10-29 15:48:06 -0700 | [diff] [blame] | 935 | if (p_acl_cb->transport == BT_TRANSPORT_LE) |
| 936 | l2cble_notify_le_connection (p_acl_cb->remote_addr); |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 937 | #endif // (defined(BLE_INCLUDED) && (BLE_INCLUDED == true)) |
Andre Eisenbach | 284ff6b | 2015-10-29 15:48:06 -0700 | [diff] [blame] | 938 | break; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 939 | } |
| 940 | } |
| 941 | } |
| 942 | |
| 943 | |
| 944 | /******************************************************************************* |
| 945 | ** |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 946 | ** Function btm_process_remote_ext_features |
| 947 | ** |
| 948 | ** Description Local function called to process all extended features pages |
| 949 | ** read from a remote device. |
| 950 | ** |
| 951 | ** Returns void |
| 952 | ** |
| 953 | *******************************************************************************/ |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 954 | void btm_process_remote_ext_features (tACL_CONN *p_acl_cb, uint8_t num_read_pages) |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 955 | { |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 956 | uint16_t handle = p_acl_cb->hci_handle; |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 957 | tBTM_SEC_DEV_REC *p_dev_rec = btm_find_dev_by_handle (handle); |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 958 | uint8_t page_idx; |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 959 | |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 960 | BTM_TRACE_DEBUG ("btm_process_remote_ext_features"); |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 961 | |
| 962 | /* Make sure we have the record to save remote features information */ |
| 963 | if (p_dev_rec == NULL) |
| 964 | { |
| 965 | /* Get a new device; might be doing dedicated bonding */ |
| 966 | p_dev_rec = btm_find_or_alloc_dev (p_acl_cb->remote_addr); |
| 967 | } |
| 968 | |
| 969 | p_acl_cb->num_read_pages = num_read_pages; |
| 970 | p_dev_rec->num_read_pages = num_read_pages; |
| 971 | |
Mudumba Ananth | 899b771 | 2015-01-30 02:33:02 -0800 | [diff] [blame] | 972 | /* Move the pages to placeholder */ |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 973 | for (page_idx = 0; page_idx < num_read_pages; page_idx++) |
| 974 | { |
Mudumba Ananth | 899b771 | 2015-01-30 02:33:02 -0800 | [diff] [blame] | 975 | if (page_idx > HCI_EXT_FEATURES_PAGE_MAX) |
| 976 | { |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 977 | BTM_TRACE_ERROR("%s: page=%d unexpected", __func__, page_idx); |
Mudumba Ananth | 899b771 | 2015-01-30 02:33:02 -0800 | [diff] [blame] | 978 | break; |
| 979 | } |
| 980 | memcpy (p_dev_rec->features[page_idx], p_acl_cb->peer_lmp_features[page_idx], |
| 981 | HCI_FEATURE_BYTES_PER_PAGE); |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 982 | } |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 983 | |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 984 | const uint8_t req_pend = (p_dev_rec->sm4 & BTM_SM4_REQ_PEND); |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 985 | |
Mudumba Ananth | 899b771 | 2015-01-30 02:33:02 -0800 | [diff] [blame] | 986 | /* Store the Peer Security Capabilites (in SM4 and rmt_sec_caps) */ |
| 987 | btm_sec_set_peer_sec_caps(p_acl_cb, p_dev_rec); |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 988 | |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 989 | BTM_TRACE_API("%s: pend:%d", __func__, req_pend); |
Mudumba Ananth | 899b771 | 2015-01-30 02:33:02 -0800 | [diff] [blame] | 990 | if (req_pend) |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 991 | { |
Mudumba Ananth | 899b771 | 2015-01-30 02:33:02 -0800 | [diff] [blame] | 992 | /* Request for remaining Security Features (if any) */ |
| 993 | l2cu_resubmit_pending_sec_req (p_dev_rec->bd_addr); |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 994 | } |
| 995 | } |
| 996 | |
| 997 | |
| 998 | /******************************************************************************* |
| 999 | ** |
| 1000 | ** Function btm_read_remote_features |
| 1001 | ** |
| 1002 | ** Description Local function called to send a read remote supported features/ |
| 1003 | ** remote extended features page[0]. |
| 1004 | ** |
| 1005 | ** Returns void |
| 1006 | ** |
| 1007 | *******************************************************************************/ |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 1008 | void btm_read_remote_features (uint16_t handle) |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 1009 | { |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 1010 | uint8_t acl_idx; |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 1011 | tACL_CONN *p_acl_cb; |
| 1012 | |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1013 | BTM_TRACE_DEBUG("btm_read_remote_features() handle: %d", handle); |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 1014 | |
| 1015 | if ((acl_idx = btm_handle_to_acl_index(handle)) >= MAX_L2CAP_LINKS) |
| 1016 | { |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1017 | BTM_TRACE_ERROR("btm_read_remote_features handle=%d invalid", handle); |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 1018 | return; |
| 1019 | } |
| 1020 | |
| 1021 | p_acl_cb = &btm_cb.acl_db[acl_idx]; |
| 1022 | p_acl_cb->num_read_pages = 0; |
| 1023 | memset (p_acl_cb->peer_lmp_features, 0, sizeof(p_acl_cb->peer_lmp_features)); |
| 1024 | |
Zhihai Xu | 24c0f58 | 2013-04-16 17:58:43 -0700 | [diff] [blame] | 1025 | /* first send read remote supported features HCI command */ |
| 1026 | /* because we don't know whether the remote support extended feature command */ |
| 1027 | btsnd_hcic_rmt_features_req (handle); |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 1028 | } |
| 1029 | |
| 1030 | |
| 1031 | /******************************************************************************* |
| 1032 | ** |
| 1033 | ** Function btm_read_remote_ext_features |
| 1034 | ** |
| 1035 | ** Description Local function called to send a read remote extended features |
| 1036 | ** |
| 1037 | ** Returns void |
| 1038 | ** |
| 1039 | *******************************************************************************/ |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 1040 | void btm_read_remote_ext_features (uint16_t handle, uint8_t page_number) |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 1041 | { |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1042 | BTM_TRACE_DEBUG("btm_read_remote_ext_features() handle: %d page: %d", handle, page_number); |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 1043 | |
| 1044 | btsnd_hcic_rmt_ext_features(handle, page_number); |
| 1045 | } |
| 1046 | |
| 1047 | |
| 1048 | /******************************************************************************* |
| 1049 | ** |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1050 | ** Function btm_read_remote_features_complete |
| 1051 | ** |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 1052 | ** 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] | 1053 | ** complete event is received from the HCI. |
| 1054 | ** |
| 1055 | ** Returns void |
| 1056 | ** |
| 1057 | *******************************************************************************/ |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 1058 | void btm_read_remote_features_complete (uint8_t *p) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1059 | { |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 1060 | tACL_CONN *p_acl_cb; |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 1061 | uint8_t status; |
| 1062 | uint16_t handle; |
| 1063 | uint8_t acl_idx; |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 1064 | |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1065 | BTM_TRACE_DEBUG ("btm_read_remote_features_complete"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1066 | STREAM_TO_UINT8 (status, p); |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 1067 | |
| 1068 | if (status != HCI_SUCCESS) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1069 | { |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1070 | BTM_TRACE_ERROR ("btm_read_remote_features_complete failed (status 0x%02x)", status); |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 1071 | return; |
| 1072 | } |
| 1073 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1074 | STREAM_TO_UINT16 (handle, p); |
| 1075 | |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 1076 | 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] | 1077 | { |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1078 | BTM_TRACE_ERROR("btm_read_remote_features_complete handle=%d invalid", handle); |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 1079 | return; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1080 | } |
| 1081 | |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 1082 | p_acl_cb = &btm_cb.acl_db[acl_idx]; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1083 | |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 1084 | /* Copy the received features page */ |
| 1085 | STREAM_TO_ARRAY(p_acl_cb->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0], p, |
| 1086 | HCI_FEATURE_BYTES_PER_PAGE); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1087 | |
Ganesh Ganapathi Batta | 9d140a9 | 2013-04-11 16:13:14 -0700 | [diff] [blame] | 1088 | if ((HCI_LMP_EXTENDED_SUPPORTED(p_acl_cb->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0])) && |
Zach Johnson | 30e5806 | 2014-09-26 21:14:34 -0700 | [diff] [blame] | 1089 | (controller_get_interface()->supports_reading_remote_extended_features())) |
Ganesh Ganapathi Batta | 9d140a9 | 2013-04-11 16:13:14 -0700 | [diff] [blame] | 1090 | { |
| 1091 | /* if the remote controller has extended features and local controller supports |
| 1092 | ** HCI_Read_Remote_Extended_Features command then start reading these feature starting |
| 1093 | ** with extended features page 1 */ |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1094 | BTM_TRACE_DEBUG ("Start reading remote extended features"); |
Ganesh Ganapathi Batta | 9d140a9 | 2013-04-11 16:13:14 -0700 | [diff] [blame] | 1095 | btm_read_remote_ext_features(handle, HCI_EXT_FEATURES_PAGE_1); |
| 1096 | return; |
| 1097 | } |
| 1098 | |
| 1099 | /* Remote controller has no extended features. Process remote controller supported features |
| 1100 | (features page HCI_EXT_FEATURES_PAGE_0). */ |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 1101 | btm_process_remote_ext_features (p_acl_cb, 1); |
| 1102 | |
| 1103 | /* Continue with HCI connection establishment */ |
| 1104 | btm_establish_continue (p_acl_cb); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1105 | } |
| 1106 | |
| 1107 | /******************************************************************************* |
| 1108 | ** |
| 1109 | ** Function btm_read_remote_ext_features_complete |
| 1110 | ** |
| 1111 | ** Description This function is called when the remote extended features |
| 1112 | ** complete event is received from the HCI. |
| 1113 | ** |
| 1114 | ** Returns void |
| 1115 | ** |
| 1116 | *******************************************************************************/ |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 1117 | void btm_read_remote_ext_features_complete (uint8_t *p) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1118 | { |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 1119 | tACL_CONN *p_acl_cb; |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 1120 | uint8_t page_num, max_page; |
| 1121 | uint16_t handle; |
| 1122 | uint8_t acl_idx; |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 1123 | |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1124 | BTM_TRACE_DEBUG ("btm_read_remote_ext_features_complete"); |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 1125 | |
Sharvil Nanavati | f1c764f | 2015-02-23 17:31:48 -0800 | [diff] [blame] | 1126 | ++p; |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 1127 | STREAM_TO_UINT16 (handle, p); |
| 1128 | STREAM_TO_UINT8 (page_num, p); |
| 1129 | STREAM_TO_UINT8 (max_page, p); |
| 1130 | |
| 1131 | /* Validate parameters */ |
| 1132 | if ((acl_idx = btm_handle_to_acl_index(handle)) >= MAX_L2CAP_LINKS) |
| 1133 | { |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1134 | BTM_TRACE_ERROR("btm_read_remote_ext_features_complete handle=%d invalid", handle); |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 1135 | return; |
| 1136 | } |
| 1137 | |
| 1138 | if (max_page > HCI_EXT_FEATURES_PAGE_MAX) |
| 1139 | { |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1140 | BTM_TRACE_ERROR("btm_read_remote_ext_features_complete page=%d unknown", max_page); |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 1141 | return; |
| 1142 | } |
| 1143 | |
| 1144 | p_acl_cb = &btm_cb.acl_db[acl_idx]; |
| 1145 | |
| 1146 | /* Copy the received features page */ |
| 1147 | STREAM_TO_ARRAY(p_acl_cb->peer_lmp_features[page_num], p, HCI_FEATURE_BYTES_PER_PAGE); |
| 1148 | |
| 1149 | /* If there is the next remote features page and |
| 1150 | * we have space to keep this page data - read this page */ |
| 1151 | if ((page_num < max_page) && (page_num < HCI_EXT_FEATURES_PAGE_MAX)) |
| 1152 | { |
| 1153 | page_num++; |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1154 | BTM_TRACE_DEBUG("BTM reads next remote extended features page (%d)", page_num); |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 1155 | btm_read_remote_ext_features (handle, page_num); |
| 1156 | return; |
| 1157 | } |
| 1158 | |
| 1159 | /* Reading of remote feature pages is complete */ |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1160 | BTM_TRACE_DEBUG("BTM reached last remote extended features page (%d)", page_num); |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 1161 | |
| 1162 | /* Process the pages */ |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 1163 | btm_process_remote_ext_features (p_acl_cb, (uint8_t) (page_num + 1)); |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 1164 | |
| 1165 | /* Continue with HCI connection establishment */ |
| 1166 | btm_establish_continue (p_acl_cb); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1167 | } |
| 1168 | |
| 1169 | /******************************************************************************* |
| 1170 | ** |
| 1171 | ** Function btm_read_remote_ext_features_failed |
| 1172 | ** |
| 1173 | ** Description This function is called when the remote extended features |
| 1174 | ** complete event returns a failed status. |
| 1175 | ** |
| 1176 | ** Returns void |
| 1177 | ** |
| 1178 | *******************************************************************************/ |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 1179 | void btm_read_remote_ext_features_failed (uint8_t status, uint16_t handle) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1180 | { |
Ganesh Ganapathi Batta | 9d140a9 | 2013-04-11 16:13:14 -0700 | [diff] [blame] | 1181 | tACL_CONN *p_acl_cb; |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 1182 | uint8_t acl_idx; |
Ganesh Ganapathi Batta | 9d140a9 | 2013-04-11 16:13:14 -0700 | [diff] [blame] | 1183 | |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1184 | BTM_TRACE_WARNING ("btm_read_remote_ext_features_failed (status 0x%02x) for handle %d", |
Ganesh Ganapathi Batta | 9d140a9 | 2013-04-11 16:13:14 -0700 | [diff] [blame] | 1185 | status, handle); |
| 1186 | |
| 1187 | if ((acl_idx = btm_handle_to_acl_index(handle)) >= MAX_L2CAP_LINKS) |
| 1188 | { |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1189 | BTM_TRACE_ERROR("btm_read_remote_ext_features_failed handle=%d invalid", handle); |
Ganesh Ganapathi Batta | 9d140a9 | 2013-04-11 16:13:14 -0700 | [diff] [blame] | 1190 | return; |
| 1191 | } |
| 1192 | |
| 1193 | p_acl_cb = &btm_cb.acl_db[acl_idx]; |
| 1194 | |
| 1195 | /* Process supported features only */ |
| 1196 | btm_process_remote_ext_features (p_acl_cb, 1); |
| 1197 | |
| 1198 | /* Continue HCI connection establishment */ |
| 1199 | btm_establish_continue (p_acl_cb); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1200 | } |
| 1201 | |
| 1202 | /******************************************************************************* |
| 1203 | ** |
| 1204 | ** Function btm_establish_continue |
| 1205 | ** |
| 1206 | ** Description This function is called when the command complete message |
| 1207 | ** is received from the HCI for the read local link policy request. |
| 1208 | ** |
| 1209 | ** Returns void |
| 1210 | ** |
| 1211 | *******************************************************************************/ |
Priti Aghera | 9c29d08 | 2014-09-02 15:41:56 -0700 | [diff] [blame] | 1212 | void btm_establish_continue (tACL_CONN *p_acl_cb) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1213 | { |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1214 | tBTM_BL_EVENT_DATA evt_data; |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1215 | BTM_TRACE_DEBUG ("btm_establish_continue"); |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 1216 | #if (BTM_BYPASS_EXTRA_ACL_SETUP == FALSE) |
| 1217 | #if (BLE_INCLUDED == TRUE) |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1218 | if (p_acl_cb->transport == BT_TRANSPORT_BR_EDR) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1219 | #endif |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1220 | { |
| 1221 | /* For now there are a some devices that do not like sending */ |
| 1222 | /* commands events and data at the same time. */ |
| 1223 | /* Set the packet types to the default allowed by the device */ |
| 1224 | btm_set_packet_types (p_acl_cb, btm_cb.btm_acl_pkt_types_supported); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1225 | |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1226 | if (btm_cb.btm_def_link_policy) |
| 1227 | BTM_SetLinkPolicy (p_acl_cb->remote_addr, &btm_cb.btm_def_link_policy); |
| 1228 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1229 | #endif |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 1230 | p_acl_cb->link_up_issued = true; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1231 | |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1232 | /* If anyone cares, tell him database changed */ |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1233 | if (btm_cb.p_bl_changed_cb) |
| 1234 | { |
| 1235 | evt_data.event = BTM_BL_CONN_EVT; |
| 1236 | evt_data.conn.p_bda = p_acl_cb->remote_addr; |
| 1237 | evt_data.conn.p_bdn = p_acl_cb->remote_name; |
| 1238 | evt_data.conn.p_dc = p_acl_cb->remote_dc; |
| 1239 | evt_data.conn.p_features = p_acl_cb->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0]; |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 1240 | #if (BLE_INCLUDED == TRUE) |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1241 | evt_data.conn.handle = p_acl_cb->hci_handle; |
| 1242 | evt_data.conn.transport = p_acl_cb->transport; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1243 | #endif |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1244 | |
| 1245 | (*btm_cb.p_bl_changed_cb)(&evt_data); |
| 1246 | } |
| 1247 | btm_acl_update_busy_level (BTM_BLI_ACL_UP_EVT); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1248 | } |
| 1249 | |
| 1250 | |
| 1251 | /******************************************************************************* |
| 1252 | ** |
| 1253 | ** Function BTM_SetDefaultLinkSuperTout |
| 1254 | ** |
| 1255 | ** Description Set the default value for HCI "Write Link Supervision Timeout" |
| 1256 | ** command to use when an ACL link is created. |
| 1257 | ** |
| 1258 | ** Returns void |
| 1259 | ** |
| 1260 | *******************************************************************************/ |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 1261 | void BTM_SetDefaultLinkSuperTout (uint16_t timeout) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1262 | { |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1263 | BTM_TRACE_DEBUG ("BTM_SetDefaultLinkSuperTout"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1264 | btm_cb.btm_def_link_super_tout = timeout; |
| 1265 | } |
| 1266 | |
| 1267 | /******************************************************************************* |
| 1268 | ** |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1269 | ** Function BTM_GetLinkSuperTout |
| 1270 | ** |
| 1271 | ** Description Read the link supervision timeout value of the connection |
| 1272 | ** |
| 1273 | ** Returns status of the operation |
| 1274 | ** |
| 1275 | *******************************************************************************/ |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 1276 | tBTM_STATUS BTM_GetLinkSuperTout (BD_ADDR remote_bda, uint16_t *p_timeout) |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1277 | { |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1278 | tACL_CONN *p = btm_bda_to_acl(remote_bda, BT_TRANSPORT_BR_EDR); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1279 | |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1280 | BTM_TRACE_DEBUG ("BTM_GetLinkSuperTout"); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1281 | if (p != (tACL_CONN *)NULL) |
| 1282 | { |
| 1283 | *p_timeout = p->link_super_tout; |
| 1284 | return(BTM_SUCCESS); |
| 1285 | } |
| 1286 | /* If here, no BD Addr found */ |
| 1287 | return(BTM_UNKNOWN_ADDR); |
| 1288 | } |
| 1289 | |
| 1290 | |
| 1291 | /******************************************************************************* |
| 1292 | ** |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1293 | ** Function BTM_SetLinkSuperTout |
| 1294 | ** |
| 1295 | ** Description Create and send HCI "Write Link Supervision Timeout" command |
| 1296 | ** |
| 1297 | ** Returns status of the operation |
| 1298 | ** |
| 1299 | *******************************************************************************/ |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 1300 | tBTM_STATUS BTM_SetLinkSuperTout (BD_ADDR remote_bda, uint16_t timeout) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1301 | { |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1302 | tACL_CONN *p = btm_bda_to_acl(remote_bda, BT_TRANSPORT_BR_EDR); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1303 | |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1304 | BTM_TRACE_DEBUG ("BTM_SetLinkSuperTout"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1305 | if (p != (tACL_CONN *)NULL) |
| 1306 | { |
| 1307 | p->link_super_tout = timeout; |
| 1308 | |
| 1309 | /* Only send if current role is Master; 2.0 spec requires this */ |
| 1310 | if (p->link_role == BTM_ROLE_MASTER) |
| 1311 | { |
| 1312 | if (!btsnd_hcic_write_link_super_tout (LOCAL_BR_EDR_CONTROLLER_ID, |
| 1313 | p->hci_handle, timeout)) |
| 1314 | return(BTM_NO_RESOURCES); |
| 1315 | |
| 1316 | return(BTM_CMD_STARTED); |
| 1317 | } |
| 1318 | else |
| 1319 | return(BTM_SUCCESS); |
| 1320 | } |
| 1321 | |
| 1322 | /* If here, no BD Addr found */ |
| 1323 | return(BTM_UNKNOWN_ADDR); |
| 1324 | } |
| 1325 | |
| 1326 | /******************************************************************************* |
| 1327 | ** |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1328 | ** Function BTM_IsAclConnectionUp |
| 1329 | ** |
| 1330 | ** Description This function is called to check if an ACL connection exists |
| 1331 | ** to a specific remote BD Address. |
| 1332 | ** |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 1333 | ** Returns true if connection is up, else false. |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1334 | ** |
| 1335 | *******************************************************************************/ |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 1336 | bool BTM_IsAclConnectionUp (BD_ADDR remote_bda, tBT_TRANSPORT transport) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1337 | { |
| 1338 | tACL_CONN *p; |
| 1339 | |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1340 | BTM_TRACE_API ("BTM_IsAclConnectionUp: RemBdAddr: %02x%02x%02x%02x%02x%02x", |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1341 | remote_bda[0], remote_bda[1], remote_bda[2], |
| 1342 | remote_bda[3], remote_bda[4], remote_bda[5]); |
| 1343 | |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1344 | p = btm_bda_to_acl(remote_bda, transport); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1345 | if (p != (tACL_CONN *)NULL) |
| 1346 | { |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 1347 | return(true); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1348 | } |
| 1349 | |
| 1350 | /* If here, no BD Addr found */ |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 1351 | return(false); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1352 | } |
| 1353 | |
| 1354 | /******************************************************************************* |
| 1355 | ** |
| 1356 | ** Function BTM_GetNumAclLinks |
| 1357 | ** |
| 1358 | ** Description This function is called to count the number of |
| 1359 | ** ACL links that are active. |
| 1360 | ** |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 1361 | ** Returns uint16_t Number of active ACL links |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1362 | ** |
| 1363 | *******************************************************************************/ |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 1364 | uint16_t BTM_GetNumAclLinks (void) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1365 | { |
Andre Eisenbach | f4c4b78 | 2015-03-19 15:15:05 -0700 | [diff] [blame] | 1366 | uint16_t num_acl = 0; |
| 1367 | |
| 1368 | for (uint16_t i = 0; i < MAX_L2CAP_LINKS; ++i) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1369 | { |
Andre Eisenbach | f4c4b78 | 2015-03-19 15:15:05 -0700 | [diff] [blame] | 1370 | if (btm_cb.acl_db[i].in_use) |
| 1371 | ++num_acl; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1372 | } |
| 1373 | |
Andre Eisenbach | f4c4b78 | 2015-03-19 15:15:05 -0700 | [diff] [blame] | 1374 | return num_acl; |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1375 | } |
| 1376 | |
| 1377 | /******************************************************************************* |
| 1378 | ** |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1379 | ** Function btm_get_acl_disc_reason_code |
| 1380 | ** |
| 1381 | ** Description This function is called to get the disconnection reason code |
| 1382 | ** returned by the HCI at disconnection complete event. |
| 1383 | ** |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 1384 | ** Returns true if connection is up, else false. |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1385 | ** |
| 1386 | *******************************************************************************/ |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 1387 | uint16_t btm_get_acl_disc_reason_code (void) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1388 | { |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 1389 | uint8_t res = btm_cb.acl_disc_reason; |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1390 | BTM_TRACE_DEBUG ("btm_get_acl_disc_reason_code"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1391 | return(res); |
| 1392 | } |
| 1393 | |
| 1394 | |
| 1395 | /******************************************************************************* |
| 1396 | ** |
| 1397 | ** Function BTM_GetHCIConnHandle |
| 1398 | ** |
| 1399 | ** Description This function is called to get the handle for an ACL connection |
| 1400 | ** to a specific remote BD Address. |
| 1401 | ** |
| 1402 | ** Returns the handle of the connection, or 0xFFFF if none. |
| 1403 | ** |
| 1404 | *******************************************************************************/ |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 1405 | uint16_t BTM_GetHCIConnHandle (BD_ADDR remote_bda, tBT_TRANSPORT transport) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1406 | { |
| 1407 | tACL_CONN *p; |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1408 | BTM_TRACE_DEBUG ("BTM_GetHCIConnHandle"); |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1409 | p = btm_bda_to_acl(remote_bda, transport); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1410 | if (p != (tACL_CONN *)NULL) |
| 1411 | { |
| 1412 | return(p->hci_handle); |
| 1413 | } |
| 1414 | |
| 1415 | /* If here, no BD Addr found */ |
| 1416 | return(0xFFFF); |
| 1417 | } |
| 1418 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1419 | /******************************************************************************* |
| 1420 | ** |
| 1421 | ** Function btm_process_clk_off_comp_evt |
| 1422 | ** |
| 1423 | ** Description This function is called when clock offset command completes. |
| 1424 | ** |
| 1425 | ** Input Parms hci_handle - connection handle associated with the change |
| 1426 | ** clock offset |
| 1427 | ** |
| 1428 | ** Returns void |
| 1429 | ** |
| 1430 | *******************************************************************************/ |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 1431 | void btm_process_clk_off_comp_evt (uint16_t hci_handle, uint16_t clock_offset) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1432 | { |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 1433 | uint8_t xx; |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1434 | BTM_TRACE_DEBUG ("btm_process_clk_off_comp_evt"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1435 | /* Look up the connection by handle and set the current mode */ |
| 1436 | if ((xx = btm_handle_to_acl_index(hci_handle)) < MAX_L2CAP_LINKS) |
| 1437 | btm_cb.acl_db[xx].clock_offset = clock_offset; |
| 1438 | } |
| 1439 | |
| 1440 | /******************************************************************************* |
| 1441 | ** |
| 1442 | ** Function btm_acl_role_changed |
| 1443 | ** |
| 1444 | ** Description This function is called whan a link's master/slave role change |
| 1445 | ** event or command status event (with error) is received. |
| 1446 | ** It updates the link control block, and calls |
| 1447 | ** the registered callback with status and role (if registered). |
| 1448 | ** |
| 1449 | ** Returns void |
| 1450 | ** |
| 1451 | *******************************************************************************/ |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 1452 | void btm_acl_role_changed (uint8_t hci_status, BD_ADDR bd_addr, uint8_t new_role) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1453 | { |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 1454 | uint8_t *p_bda = (bd_addr) ? bd_addr : |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 1455 | btm_cb.devcb.switch_role_ref_data.remote_bd_addr; |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1456 | tACL_CONN *p = btm_bda_to_acl(p_bda, BT_TRANSPORT_BR_EDR); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1457 | 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] | 1458 | tBTM_SEC_DEV_REC *p_dev_rec; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1459 | tBTM_BL_ROLE_CHG_DATA evt; |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1460 | |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1461 | BTM_TRACE_DEBUG ("btm_acl_role_changed"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1462 | /* Ignore any stray events */ |
| 1463 | if (p == NULL) |
| 1464 | { |
| 1465 | /* it could be a failure */ |
| 1466 | if (hci_status != HCI_SUCCESS) |
| 1467 | btm_acl_report_role_change(hci_status, bd_addr); |
| 1468 | return; |
| 1469 | } |
| 1470 | |
| 1471 | p_data->hci_status = hci_status; |
| 1472 | |
| 1473 | if (hci_status == HCI_SUCCESS) |
| 1474 | { |
| 1475 | p_data->role = new_role; |
| 1476 | memcpy(p_data->remote_bd_addr, p_bda, BD_ADDR_LEN); |
| 1477 | |
| 1478 | /* Update cached value */ |
| 1479 | p->link_role = new_role; |
Andre Eisenbach | 1fbddc8 | 2014-10-10 09:11:27 -0700 | [diff] [blame] | 1480 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1481 | /* Reload LSTO: link supervision timeout is reset in the LM after a role switch */ |
| 1482 | if (new_role == BTM_ROLE_MASTER) |
| 1483 | { |
| 1484 | BTM_SetLinkSuperTout (p->remote_addr, p->link_super_tout); |
| 1485 | } |
| 1486 | } |
| 1487 | else |
| 1488 | { |
| 1489 | /* so the BTM_BL_ROLE_CHG_EVT uses the old role */ |
| 1490 | new_role = p->link_role; |
| 1491 | } |
| 1492 | |
| 1493 | /* Check if any SCO req is pending for role change */ |
| 1494 | btm_sco_chk_pend_rolechange (p->hci_handle); |
| 1495 | |
| 1496 | /* if switching state is switching we need to turn encryption on */ |
| 1497 | /* if idle, we did not change encryption */ |
| 1498 | if (p->switch_role_state == BTM_ACL_SWKEY_STATE_SWITCHING) |
| 1499 | { |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 1500 | if (btsnd_hcic_set_conn_encrypt (p->hci_handle, true)) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1501 | { |
Zach Johnson | e7faae6 | 2014-10-27 17:23:49 -0700 | [diff] [blame] | 1502 | p->encrypt_state = BTM_ACL_ENCRYPT_STATE_ENCRYPT_ON; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1503 | p->switch_role_state = BTM_ACL_SWKEY_STATE_ENCRYPTION_ON; |
| 1504 | return; |
| 1505 | } |
| 1506 | } |
| 1507 | |
| 1508 | /* Set the switch_role_state to IDLE since the reply received from HCI */ |
| 1509 | /* regardless of its result either success or failed. */ |
| 1510 | if (p->switch_role_state == BTM_ACL_SWKEY_STATE_IN_PROGRESS) |
| 1511 | { |
| 1512 | p->switch_role_state = BTM_ACL_SWKEY_STATE_IDLE; |
| 1513 | p->encrypt_state = BTM_ACL_ENCRYPT_STATE_IDLE; |
| 1514 | } |
| 1515 | |
| 1516 | /* if role switch complete is needed, report it now */ |
| 1517 | btm_acl_report_role_change(hci_status, bd_addr); |
| 1518 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1519 | /* if role change event is registered, report it now */ |
| 1520 | if (btm_cb.p_bl_changed_cb && (btm_cb.bl_evt_mask & BTM_BL_ROLE_CHG_MASK)) |
| 1521 | { |
| 1522 | evt.event = BTM_BL_ROLE_CHG_EVT; |
| 1523 | evt.new_role = new_role; |
| 1524 | evt.p_bda = p_bda; |
| 1525 | evt.hci_status = hci_status; |
| 1526 | (*btm_cb.p_bl_changed_cb)((tBTM_BL_EVENT_DATA *)&evt); |
| 1527 | } |
| 1528 | |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1529 | BTM_TRACE_DEBUG("Role Switch Event: new_role 0x%02x, HCI Status 0x%02x, rs_st:%d", |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1530 | p_data->role, p_data->hci_status, p->switch_role_state); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1531 | |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 1532 | #if (BTM_DISC_DURING_RS == TRUE) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1533 | /* If a disconnect is pending, issue it now that role switch has completed */ |
| 1534 | if ((p_dev_rec = btm_find_dev (p_bda)) != NULL) |
| 1535 | { |
| 1536 | if (p_dev_rec->rs_disc_pending == BTM_SEC_DISC_PENDING) |
| 1537 | { |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1538 | BTM_TRACE_WARNING("btm_acl_role_changed -> Issuing delayed HCI_Disconnect!!!"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1539 | btsnd_hcic_disconnect(p_dev_rec->hci_handle, HCI_ERR_PEER_USER); |
| 1540 | } |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1541 | BTM_TRACE_ERROR("tBTM_SEC_DEV:0x%x rs_disc_pending=%d", |
Arman Uguray | bb95452 | 2015-06-02 21:11:07 -0700 | [diff] [blame] | 1542 | PTR_TO_UINT(p_dev_rec), p_dev_rec->rs_disc_pending); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1543 | p_dev_rec->rs_disc_pending = BTM_SEC_RS_NOT_PENDING; /* reset flag */ |
| 1544 | } |
| 1545 | |
| 1546 | #endif |
| 1547 | |
| 1548 | } |
| 1549 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1550 | /******************************************************************************* |
| 1551 | ** |
| 1552 | ** Function BTM_AllocateSCN |
| 1553 | ** |
| 1554 | ** Description Look through the Server Channel Numbers for a free one. |
| 1555 | ** |
| 1556 | ** Returns Allocated SCN number or 0 if none. |
| 1557 | ** |
| 1558 | *******************************************************************************/ |
| 1559 | |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 1560 | uint8_t BTM_AllocateSCN(void) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1561 | { |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 1562 | uint8_t x; |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1563 | BTM_TRACE_DEBUG ("BTM_AllocateSCN"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1564 | |
| 1565 | // stack reserves scn 1 for HFP, HSP we still do the correct way |
| 1566 | for (x = 1; x < BTM_MAX_SCN; x++) |
| 1567 | { |
| 1568 | if (!btm_cb.btm_scn[x]) |
| 1569 | { |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 1570 | btm_cb.btm_scn[x] = true; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1571 | return(x+1); |
| 1572 | } |
| 1573 | } |
| 1574 | |
| 1575 | return(0); /* No free ports */ |
| 1576 | } |
| 1577 | |
| 1578 | /******************************************************************************* |
| 1579 | ** |
| 1580 | ** Function BTM_TryAllocateSCN |
| 1581 | ** |
| 1582 | ** Description Try to allocate a fixed server channel |
| 1583 | ** |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 1584 | ** Returns Returns true if server channel was available |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1585 | ** |
| 1586 | *******************************************************************************/ |
| 1587 | |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 1588 | bool BTM_TryAllocateSCN(uint8_t scn) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1589 | { |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1590 | /* Make sure we don't exceed max port range. |
| 1591 | * Stack reserves scn 1 for HFP, HSP we still do the correct way. |
| 1592 | */ |
| 1593 | if ( (scn>=BTM_MAX_SCN) || (scn == 1) ) |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 1594 | return false; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1595 | |
| 1596 | /* check if this port is available */ |
| 1597 | if (!btm_cb.btm_scn[scn-1]) |
| 1598 | { |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 1599 | btm_cb.btm_scn[scn-1] = true; |
| 1600 | return true; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1601 | } |
| 1602 | |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 1603 | return (false); /* Port was busy */ |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1604 | } |
| 1605 | |
| 1606 | /******************************************************************************* |
| 1607 | ** |
| 1608 | ** Function BTM_FreeSCN |
| 1609 | ** |
| 1610 | ** Description Free the specified SCN. |
| 1611 | ** |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 1612 | ** Returns true or false |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1613 | ** |
| 1614 | *******************************************************************************/ |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 1615 | bool BTM_FreeSCN(uint8_t scn) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1616 | { |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1617 | BTM_TRACE_DEBUG ("BTM_FreeSCN "); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1618 | if (scn <= BTM_MAX_SCN) |
| 1619 | { |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 1620 | btm_cb.btm_scn[scn-1] = false; |
| 1621 | return(true); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1622 | } |
| 1623 | else |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 1624 | return(false); /* Illegal SCN passed in */ |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1625 | } |
| 1626 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1627 | /******************************************************************************* |
| 1628 | ** |
| 1629 | ** Function btm_set_packet_types |
| 1630 | ** |
| 1631 | ** Description This function sets the packet types used for a specific |
| 1632 | ** ACL connection. It is called internally by btm_acl_created |
| 1633 | ** or by an application/profile by BTM_SetPacketTypes. |
| 1634 | ** |
| 1635 | ** Returns status of the operation |
| 1636 | ** |
| 1637 | *******************************************************************************/ |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 1638 | tBTM_STATUS btm_set_packet_types (tACL_CONN *p, uint16_t pkt_types) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1639 | { |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 1640 | uint16_t temp_pkt_types; |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1641 | BTM_TRACE_DEBUG ("btm_set_packet_types"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1642 | /* Save in the ACL control blocks, types that we support */ |
| 1643 | temp_pkt_types = (pkt_types & BTM_ACL_SUPPORTED_PKTS_MASK & |
| 1644 | btm_cb.btm_acl_pkt_types_supported); |
| 1645 | |
| 1646 | /* OR in any exception packet types if at least 2.0 version of spec */ |
Zach Johnson | 5fc4be1 | 2014-09-29 14:03:20 -0700 | [diff] [blame] | 1647 | temp_pkt_types |= ((pkt_types & BTM_ACL_EXCEPTION_PKTS_MASK) | |
| 1648 | (btm_cb.btm_acl_pkt_types_supported & BTM_ACL_EXCEPTION_PKTS_MASK)); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1649 | |
| 1650 | /* Exclude packet types not supported by the peer */ |
| 1651 | btm_acl_chk_peer_pkt_type_support (p, &temp_pkt_types); |
| 1652 | |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1653 | BTM_TRACE_DEBUG ("SetPacketType Mask -> 0x%04x", temp_pkt_types); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1654 | |
| 1655 | if (!btsnd_hcic_change_conn_type (p->hci_handle, temp_pkt_types)) |
| 1656 | { |
| 1657 | return(BTM_NO_RESOURCES); |
| 1658 | } |
| 1659 | |
| 1660 | p->pkt_types_mask = temp_pkt_types; |
| 1661 | |
| 1662 | return(BTM_CMD_STARTED); |
| 1663 | } |
| 1664 | |
| 1665 | /******************************************************************************* |
| 1666 | ** |
| 1667 | ** Function btm_get_max_packet_size |
| 1668 | ** |
| 1669 | ** Returns Returns maximum packet size that can be used for current |
| 1670 | ** connection, 0 if connection is not established |
| 1671 | ** |
| 1672 | *******************************************************************************/ |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 1673 | uint16_t btm_get_max_packet_size (BD_ADDR addr) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1674 | { |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1675 | tACL_CONN *p = btm_bda_to_acl(addr, BT_TRANSPORT_BR_EDR); |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 1676 | uint16_t pkt_types = 0; |
| 1677 | uint16_t pkt_size = 0; |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1678 | BTM_TRACE_DEBUG ("btm_get_max_packet_size"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1679 | if (p != NULL) |
| 1680 | { |
| 1681 | pkt_types = p->pkt_types_mask; |
| 1682 | } |
| 1683 | else |
| 1684 | { |
| 1685 | /* Special case for when info for the local device is requested */ |
Zach Johnson | 30e5806 | 2014-09-26 21:14:34 -0700 | [diff] [blame] | 1686 | if (memcmp (controller_get_interface()->get_address(), addr, BD_ADDR_LEN) == 0) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1687 | { |
| 1688 | pkt_types = btm_cb.btm_acl_pkt_types_supported; |
| 1689 | } |
| 1690 | } |
| 1691 | |
| 1692 | if (pkt_types) |
| 1693 | { |
| 1694 | if (!(pkt_types & BTM_ACL_PKT_TYPES_MASK_NO_3_DH5)) |
| 1695 | pkt_size = HCI_EDR3_DH5_PACKET_SIZE; |
| 1696 | else if (!(pkt_types & BTM_ACL_PKT_TYPES_MASK_NO_2_DH5)) |
| 1697 | pkt_size = HCI_EDR2_DH5_PACKET_SIZE; |
| 1698 | else if (!(pkt_types & BTM_ACL_PKT_TYPES_MASK_NO_3_DH3)) |
| 1699 | pkt_size = HCI_EDR3_DH3_PACKET_SIZE; |
| 1700 | else if (pkt_types & BTM_ACL_PKT_TYPES_MASK_DH5) |
| 1701 | pkt_size = HCI_DH5_PACKET_SIZE; |
| 1702 | else if (!(pkt_types & BTM_ACL_PKT_TYPES_MASK_NO_2_DH3)) |
| 1703 | pkt_size = HCI_EDR2_DH3_PACKET_SIZE; |
| 1704 | else if (pkt_types & BTM_ACL_PKT_TYPES_MASK_DM5) |
| 1705 | pkt_size = HCI_DM5_PACKET_SIZE; |
| 1706 | else if (pkt_types & BTM_ACL_PKT_TYPES_MASK_DH3) |
| 1707 | pkt_size = HCI_DH3_PACKET_SIZE; |
| 1708 | else if (pkt_types & BTM_ACL_PKT_TYPES_MASK_DM3) |
| 1709 | pkt_size = HCI_DM3_PACKET_SIZE; |
| 1710 | else if (!(pkt_types & BTM_ACL_PKT_TYPES_MASK_NO_3_DH1)) |
| 1711 | pkt_size = HCI_EDR3_DH1_PACKET_SIZE; |
| 1712 | else if (!(pkt_types & BTM_ACL_PKT_TYPES_MASK_NO_2_DH1)) |
| 1713 | pkt_size = HCI_EDR2_DH1_PACKET_SIZE; |
| 1714 | else if (pkt_types & BTM_ACL_PKT_TYPES_MASK_DH1) |
| 1715 | pkt_size = HCI_DH1_PACKET_SIZE; |
| 1716 | else if (pkt_types & BTM_ACL_PKT_TYPES_MASK_DM1) |
| 1717 | pkt_size = HCI_DM1_PACKET_SIZE; |
| 1718 | } |
| 1719 | |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1720 | return(pkt_size); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1721 | } |
| 1722 | |
| 1723 | /******************************************************************************* |
| 1724 | ** |
| 1725 | ** Function BTM_ReadRemoteVersion |
| 1726 | ** |
| 1727 | ** Returns If connected report peer device info |
| 1728 | ** |
| 1729 | *******************************************************************************/ |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 1730 | tBTM_STATUS BTM_ReadRemoteVersion (BD_ADDR addr, uint8_t *lmp_version, |
| 1731 | uint16_t *manufacturer, uint16_t *lmp_sub_version) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1732 | { |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1733 | tACL_CONN *p = btm_bda_to_acl(addr, BT_TRANSPORT_BR_EDR); |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1734 | BTM_TRACE_DEBUG ("BTM_ReadRemoteVersion"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1735 | if (p == NULL) |
| 1736 | return(BTM_UNKNOWN_ADDR); |
| 1737 | |
| 1738 | if (lmp_version) |
| 1739 | *lmp_version = p->lmp_version; |
| 1740 | |
| 1741 | if (manufacturer) |
| 1742 | *manufacturer = p->manufacturer; |
| 1743 | |
| 1744 | if (lmp_sub_version) |
| 1745 | *lmp_sub_version = p->lmp_subversion; |
| 1746 | |
| 1747 | return(BTM_SUCCESS); |
| 1748 | } |
| 1749 | |
| 1750 | /******************************************************************************* |
| 1751 | ** |
| 1752 | ** Function BTM_ReadRemoteFeatures |
| 1753 | ** |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 1754 | ** 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] | 1755 | ** |
| 1756 | *******************************************************************************/ |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 1757 | uint8_t *BTM_ReadRemoteFeatures (BD_ADDR addr) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1758 | { |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1759 | tACL_CONN *p = btm_bda_to_acl(addr, BT_TRANSPORT_BR_EDR); |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1760 | BTM_TRACE_DEBUG ("BTM_ReadRemoteFeatures"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1761 | if (p == NULL) |
| 1762 | { |
| 1763 | return(NULL); |
| 1764 | } |
| 1765 | |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 1766 | return(p->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0]); |
| 1767 | } |
| 1768 | |
| 1769 | /******************************************************************************* |
| 1770 | ** |
| 1771 | ** Function BTM_ReadRemoteExtendedFeatures |
| 1772 | ** |
| 1773 | ** Returns pointer to the remote extended features mask (8 bytes) |
| 1774 | ** or NULL if bad page |
| 1775 | ** |
| 1776 | *******************************************************************************/ |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 1777 | uint8_t *BTM_ReadRemoteExtendedFeatures (BD_ADDR addr, uint8_t page_number) |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 1778 | { |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1779 | tACL_CONN *p = btm_bda_to_acl(addr, BT_TRANSPORT_BR_EDR); |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1780 | BTM_TRACE_DEBUG ("BTM_ReadRemoteExtendedFeatures"); |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 1781 | if (p == NULL) |
| 1782 | { |
| 1783 | return(NULL); |
| 1784 | } |
| 1785 | |
| 1786 | if (page_number > HCI_EXT_FEATURES_PAGE_MAX) |
| 1787 | { |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1788 | BTM_TRACE_ERROR("Warning: BTM_ReadRemoteExtendedFeatures page %d unknown", page_number); |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 1789 | return NULL; |
| 1790 | } |
| 1791 | |
| 1792 | return(p->peer_lmp_features[page_number]); |
| 1793 | } |
| 1794 | |
| 1795 | /******************************************************************************* |
| 1796 | ** |
| 1797 | ** Function BTM_ReadNumberRemoteFeaturesPages |
| 1798 | ** |
| 1799 | ** Returns number of features pages read from the remote device. |
| 1800 | ** |
| 1801 | *******************************************************************************/ |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 1802 | uint8_t BTM_ReadNumberRemoteFeaturesPages (BD_ADDR addr) |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 1803 | { |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1804 | tACL_CONN *p = btm_bda_to_acl(addr, BT_TRANSPORT_BR_EDR); |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1805 | BTM_TRACE_DEBUG ("BTM_ReadNumberRemoteFeaturesPages"); |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 1806 | if (p == NULL) |
| 1807 | { |
| 1808 | return(0); |
| 1809 | } |
| 1810 | |
| 1811 | return(p->num_read_pages); |
| 1812 | } |
| 1813 | |
| 1814 | /******************************************************************************* |
| 1815 | ** |
| 1816 | ** Function BTM_ReadAllRemoteFeatures |
| 1817 | ** |
| 1818 | ** Returns pointer to all features of the remote (24 bytes). |
| 1819 | ** |
| 1820 | *******************************************************************************/ |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 1821 | uint8_t *BTM_ReadAllRemoteFeatures (BD_ADDR addr) |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 1822 | { |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1823 | tACL_CONN *p = btm_bda_to_acl(addr, BT_TRANSPORT_BR_EDR); |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1824 | BTM_TRACE_DEBUG ("BTM_ReadAllRemoteFeatures"); |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 1825 | if (p == NULL) |
| 1826 | { |
| 1827 | return(NULL); |
| 1828 | } |
| 1829 | |
| 1830 | 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] | 1831 | } |
| 1832 | |
| 1833 | /******************************************************************************* |
| 1834 | ** |
| 1835 | ** Function BTM_RegBusyLevelNotif |
| 1836 | ** |
| 1837 | ** Description This function is called to register a callback to receive |
| 1838 | ** busy level change events. |
| 1839 | ** |
| 1840 | ** Returns BTM_SUCCESS if successfully registered, otherwise error |
| 1841 | ** |
| 1842 | *******************************************************************************/ |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 1843 | tBTM_STATUS BTM_RegBusyLevelNotif (tBTM_BL_CHANGE_CB *p_cb, uint8_t *p_level, |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1844 | tBTM_BL_EVENT_MASK evt_mask) |
| 1845 | { |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1846 | BTM_TRACE_DEBUG ("BTM_RegBusyLevelNotif"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1847 | if (p_level) |
| 1848 | *p_level = btm_cb.busy_level; |
| 1849 | |
| 1850 | btm_cb.bl_evt_mask = evt_mask; |
| 1851 | |
| 1852 | if (!p_cb) |
| 1853 | btm_cb.p_bl_changed_cb = NULL; |
| 1854 | else if (btm_cb.p_bl_changed_cb) |
| 1855 | return(BTM_BUSY); |
| 1856 | else |
| 1857 | btm_cb.p_bl_changed_cb = p_cb; |
| 1858 | |
| 1859 | return(BTM_SUCCESS); |
| 1860 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1861 | |
| 1862 | /******************************************************************************* |
| 1863 | ** |
| 1864 | ** Function BTM_SetQoS |
| 1865 | ** |
| 1866 | ** Description This function is called to setup QoS |
| 1867 | ** |
| 1868 | ** Returns status of the operation |
| 1869 | ** |
| 1870 | *******************************************************************************/ |
| 1871 | tBTM_STATUS BTM_SetQoS (BD_ADDR bd, FLOW_SPEC *p_flow, tBTM_CMPL_CB *p_cb) |
| 1872 | { |
| 1873 | tACL_CONN *p = &btm_cb.acl_db[0]; |
| 1874 | |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1875 | BTM_TRACE_API ("BTM_SetQoS: BdAddr: %02x%02x%02x%02x%02x%02x", |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1876 | bd[0], bd[1], bd[2], |
| 1877 | bd[3], bd[4], bd[5]); |
| 1878 | |
| 1879 | /* If someone already waiting on the version, do not allow another */ |
Pavlin Radoslavov | 78bcff7 | 2015-12-04 17:36:34 -0800 | [diff] [blame] | 1880 | if (btm_cb.devcb.p_qos_setup_cmpl_cb) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1881 | return(BTM_BUSY); |
| 1882 | |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1883 | if ( (p = btm_bda_to_acl(bd, BT_TRANSPORT_BR_EDR)) != NULL) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1884 | { |
Pavlin Radoslavov | 78bcff7 | 2015-12-04 17:36:34 -0800 | [diff] [blame] | 1885 | btm_cb.devcb.p_qos_setup_cmpl_cb = p_cb; |
| 1886 | alarm_set_on_queue(btm_cb.devcb.qos_setup_timer, |
| 1887 | BTM_DEV_REPLY_TIMEOUT_MS, |
| 1888 | btm_qos_setup_timeout, NULL, |
| 1889 | btu_general_alarm_queue); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1890 | |
| 1891 | 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] | 1892 | p_flow->token_rate, p_flow->peak_bandwidth, |
| 1893 | p_flow->latency,p_flow->delay_variation)) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1894 | { |
Pavlin Radoslavov | 78bcff7 | 2015-12-04 17:36:34 -0800 | [diff] [blame] | 1895 | btm_cb.devcb.p_qos_setup_cmpl_cb = NULL; |
| 1896 | alarm_cancel(btm_cb.devcb.qos_setup_timer); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1897 | return(BTM_NO_RESOURCES); |
| 1898 | } |
| 1899 | else |
| 1900 | return(BTM_CMD_STARTED); |
| 1901 | } |
| 1902 | |
| 1903 | /* If here, no BD Addr found */ |
| 1904 | return(BTM_UNKNOWN_ADDR); |
| 1905 | } |
| 1906 | |
| 1907 | /******************************************************************************* |
| 1908 | ** |
Pavlin Radoslavov | 78bcff7 | 2015-12-04 17:36:34 -0800 | [diff] [blame] | 1909 | ** Function btm_qos_setup_timeout |
| 1910 | ** |
| 1911 | ** Description Callback when QoS setup times out. |
| 1912 | ** |
| 1913 | ** Returns void |
| 1914 | ** |
| 1915 | *******************************************************************************/ |
| 1916 | void btm_qos_setup_timeout(UNUSED_ATTR void *data) |
| 1917 | { |
| 1918 | tBTM_CMPL_CB *p_cb = btm_cb.devcb.p_qos_setup_cmpl_cb; |
| 1919 | btm_cb.devcb.p_qos_setup_cmpl_cb = NULL; |
| 1920 | if (p_cb) |
| 1921 | (*p_cb)((void *) NULL); |
| 1922 | } |
| 1923 | |
| 1924 | /******************************************************************************* |
| 1925 | ** |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1926 | ** Function btm_qos_setup_complete |
| 1927 | ** |
| 1928 | ** Description This function is called when the command complete message |
| 1929 | ** is received from the HCI for the qos setup request. |
| 1930 | ** |
| 1931 | ** Returns void |
| 1932 | ** |
| 1933 | *******************************************************************************/ |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 1934 | void btm_qos_setup_complete(uint8_t status, uint16_t handle, FLOW_SPEC *p_flow) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1935 | { |
Pavlin Radoslavov | 78bcff7 | 2015-12-04 17:36:34 -0800 | [diff] [blame] | 1936 | tBTM_CMPL_CB *p_cb = btm_cb.devcb.p_qos_setup_cmpl_cb; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1937 | tBTM_QOS_SETUP_CMPL qossu; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1938 | |
Pavlin Radoslavov | 78bcff7 | 2015-12-04 17:36:34 -0800 | [diff] [blame] | 1939 | BTM_TRACE_DEBUG("%s", __func__); |
| 1940 | alarm_cancel(btm_cb.devcb.qos_setup_timer); |
| 1941 | btm_cb.devcb.p_qos_setup_cmpl_cb = NULL; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1942 | |
Pavlin Radoslavov | 78bcff7 | 2015-12-04 17:36:34 -0800 | [diff] [blame] | 1943 | /* If there was a registered callback, call it */ |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1944 | if (p_cb) |
| 1945 | { |
| 1946 | memset(&qossu, 0, sizeof(tBTM_QOS_SETUP_CMPL)); |
| 1947 | qossu.status = status; |
| 1948 | qossu.handle = handle; |
| 1949 | if (p_flow != NULL) |
| 1950 | { |
| 1951 | qossu.flow.qos_flags = p_flow->qos_flags; |
| 1952 | qossu.flow.service_type = p_flow->service_type; |
| 1953 | qossu.flow.token_rate = p_flow->token_rate; |
| 1954 | qossu.flow.peak_bandwidth = p_flow->peak_bandwidth; |
| 1955 | qossu.flow.latency = p_flow->latency; |
| 1956 | qossu.flow.delay_variation = p_flow->delay_variation; |
| 1957 | } |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1958 | BTM_TRACE_DEBUG ("BTM: p_flow->delay_variation: 0x%02x", |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1959 | qossu.flow.delay_variation); |
| 1960 | (*p_cb)(&qossu); |
| 1961 | } |
| 1962 | } |
| 1963 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1964 | /******************************************************************************* |
| 1965 | ** |
| 1966 | ** Function BTM_ReadRSSI |
| 1967 | ** |
| 1968 | ** Description This function is called to read the link policy settings. |
| 1969 | ** The address of link policy results are returned in the callback. |
| 1970 | ** (tBTM_RSSI_RESULTS) |
| 1971 | ** |
| 1972 | ** Returns BTM_CMD_STARTED if successfully initiated or error code |
| 1973 | ** |
| 1974 | *******************************************************************************/ |
Jakub Pawlowski | 063ca02 | 2016-04-25 10:43:02 -0700 | [diff] [blame] | 1975 | tBTM_STATUS BTM_ReadRSSI (const BD_ADDR remote_bda, tBTM_CMPL_CB *p_cb) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1976 | { |
| 1977 | tACL_CONN *p; |
Thomas.TT_Lin | 29bfd63 | 2014-08-26 14:38:27 +0800 | [diff] [blame] | 1978 | tBT_TRANSPORT transport = BT_TRANSPORT_BR_EDR; |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 1979 | #if (BLE_INCLUDED == TRUE) |
Thomas.TT_Lin | 29bfd63 | 2014-08-26 14:38:27 +0800 | [diff] [blame] | 1980 | tBT_DEVICE_TYPE dev_type; |
| 1981 | tBLE_ADDR_TYPE addr_type; |
| 1982 | #endif |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1983 | BTM_TRACE_API ("BTM_ReadRSSI: RemBdAddr: %02x%02x%02x%02x%02x%02x", |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1984 | remote_bda[0], remote_bda[1], remote_bda[2], |
| 1985 | remote_bda[3], remote_bda[4], remote_bda[5]); |
| 1986 | |
| 1987 | /* If someone already waiting on the version, do not allow another */ |
| 1988 | if (btm_cb.devcb.p_rssi_cmpl_cb) |
| 1989 | return(BTM_BUSY); |
| 1990 | |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 1991 | #if (BLE_INCLUDED == TRUE) |
Thomas.TT_Lin | 29bfd63 | 2014-08-26 14:38:27 +0800 | [diff] [blame] | 1992 | BTM_ReadDevInfo(remote_bda, &dev_type, &addr_type); |
| 1993 | if (dev_type == BT_DEVICE_TYPE_BLE) |
| 1994 | transport = BT_TRANSPORT_LE; |
| 1995 | #endif |
| 1996 | |
| 1997 | p = btm_bda_to_acl(remote_bda, transport); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1998 | if (p != (tACL_CONN *)NULL) |
| 1999 | { |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2000 | btm_cb.devcb.p_rssi_cmpl_cb = p_cb; |
Pavlin Radoslavov | 78bcff7 | 2015-12-04 17:36:34 -0800 | [diff] [blame] | 2001 | alarm_set_on_queue(btm_cb.devcb.read_rssi_timer, |
| 2002 | BTM_DEV_REPLY_TIMEOUT_MS, btm_read_rssi_timeout, |
| 2003 | NULL, btu_general_alarm_queue); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2004 | |
| 2005 | if (!btsnd_hcic_read_rssi (p->hci_handle)) |
| 2006 | { |
| 2007 | btm_cb.devcb.p_rssi_cmpl_cb = NULL; |
Pavlin Radoslavov | 78bcff7 | 2015-12-04 17:36:34 -0800 | [diff] [blame] | 2008 | alarm_cancel(btm_cb.devcb.read_rssi_timer); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2009 | return(BTM_NO_RESOURCES); |
| 2010 | } |
| 2011 | else |
| 2012 | return(BTM_CMD_STARTED); |
| 2013 | } |
| 2014 | |
| 2015 | /* If here, no BD Addr found */ |
| 2016 | return(BTM_UNKNOWN_ADDR); |
| 2017 | } |
| 2018 | |
| 2019 | /******************************************************************************* |
| 2020 | ** |
| 2021 | ** Function BTM_ReadLinkQuality |
| 2022 | ** |
| 2023 | ** Description This function is called to read the link qulaity. |
| 2024 | ** The value of the link quality is returned in the callback. |
| 2025 | ** (tBTM_LINK_QUALITY_RESULTS) |
| 2026 | ** |
| 2027 | ** Returns BTM_CMD_STARTED if successfully initiated or error code |
| 2028 | ** |
| 2029 | *******************************************************************************/ |
| 2030 | tBTM_STATUS BTM_ReadLinkQuality (BD_ADDR remote_bda, tBTM_CMPL_CB *p_cb) |
| 2031 | { |
| 2032 | tACL_CONN *p; |
| 2033 | |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 2034 | BTM_TRACE_API ("BTM_ReadLinkQuality: RemBdAddr: %02x%02x%02x%02x%02x%02x", |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2035 | remote_bda[0], remote_bda[1], remote_bda[2], |
| 2036 | remote_bda[3], remote_bda[4], remote_bda[5]); |
| 2037 | |
| 2038 | /* If someone already waiting on the version, do not allow another */ |
Pavlin Radoslavov | 78bcff7 | 2015-12-04 17:36:34 -0800 | [diff] [blame] | 2039 | if (btm_cb.devcb.p_link_qual_cmpl_cb) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2040 | return(BTM_BUSY); |
| 2041 | |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2042 | p = btm_bda_to_acl(remote_bda, BT_TRANSPORT_BR_EDR); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2043 | if (p != (tACL_CONN *)NULL) |
| 2044 | { |
Pavlin Radoslavov | 78bcff7 | 2015-12-04 17:36:34 -0800 | [diff] [blame] | 2045 | btm_cb.devcb.p_link_qual_cmpl_cb = p_cb; |
| 2046 | alarm_set_on_queue(btm_cb.devcb.read_link_quality_timer, |
| 2047 | BTM_DEV_REPLY_TIMEOUT_MS, |
| 2048 | btm_read_link_quality_timeout, NULL, |
| 2049 | btu_general_alarm_queue); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2050 | |
| 2051 | if (!btsnd_hcic_get_link_quality (p->hci_handle)) |
| 2052 | { |
Pavlin Radoslavov | 78bcff7 | 2015-12-04 17:36:34 -0800 | [diff] [blame] | 2053 | btm_cb.devcb.p_link_qual_cmpl_cb = NULL; |
| 2054 | alarm_cancel(btm_cb.devcb.read_link_quality_timer); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2055 | return(BTM_NO_RESOURCES); |
| 2056 | } |
| 2057 | else |
| 2058 | return(BTM_CMD_STARTED); |
| 2059 | } |
| 2060 | |
| 2061 | /* If here, no BD Addr found */ |
| 2062 | return(BTM_UNKNOWN_ADDR); |
| 2063 | } |
| 2064 | |
| 2065 | /******************************************************************************* |
| 2066 | ** |
| 2067 | ** Function BTM_ReadTxPower |
| 2068 | ** |
| 2069 | ** Description This function is called to read the current |
| 2070 | ** TX power of the connection. The tx power level results |
| 2071 | ** are returned in the callback. |
| 2072 | ** (tBTM_RSSI_RESULTS) |
| 2073 | ** |
| 2074 | ** Returns BTM_CMD_STARTED if successfully initiated or error code |
| 2075 | ** |
| 2076 | *******************************************************************************/ |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2077 | tBTM_STATUS BTM_ReadTxPower (BD_ADDR remote_bda, tBT_TRANSPORT transport, tBTM_CMPL_CB *p_cb) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2078 | { |
| 2079 | tACL_CONN *p; |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 2080 | bool ret; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2081 | #define BTM_READ_RSSI_TYPE_CUR 0x00 |
| 2082 | #define BTM_READ_RSSI_TYPE_MAX 0X01 |
| 2083 | |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 2084 | BTM_TRACE_API ("BTM_ReadTxPower: RemBdAddr: %02x%02x%02x%02x%02x%02x", |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2085 | remote_bda[0], remote_bda[1], remote_bda[2], |
| 2086 | remote_bda[3], remote_bda[4], remote_bda[5]); |
| 2087 | |
| 2088 | /* If someone already waiting on the version, do not allow another */ |
| 2089 | if (btm_cb.devcb.p_tx_power_cmpl_cb) |
| 2090 | return(BTM_BUSY); |
| 2091 | |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2092 | p = btm_bda_to_acl(remote_bda, transport); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2093 | if (p != (tACL_CONN *)NULL) |
| 2094 | { |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2095 | btm_cb.devcb.p_tx_power_cmpl_cb = p_cb; |
Pavlin Radoslavov | 78bcff7 | 2015-12-04 17:36:34 -0800 | [diff] [blame] | 2096 | alarm_set_on_queue(btm_cb.devcb.read_tx_power_timer, |
| 2097 | BTM_DEV_REPLY_TIMEOUT_MS, |
| 2098 | btm_read_tx_power_timeout, NULL, |
| 2099 | btu_general_alarm_queue); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2100 | |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 2101 | #if (BLE_INCLUDED == TRUE) |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2102 | if (p->transport == BT_TRANSPORT_LE) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2103 | { |
| 2104 | memcpy(btm_cb.devcb.read_tx_pwr_addr, remote_bda, BD_ADDR_LEN); |
| 2105 | ret = btsnd_hcic_ble_read_adv_chnl_tx_power(); |
| 2106 | } |
| 2107 | else |
| 2108 | #endif |
| 2109 | { |
| 2110 | ret = btsnd_hcic_read_tx_power (p->hci_handle, BTM_READ_RSSI_TYPE_CUR); |
| 2111 | } |
| 2112 | if (!ret) |
| 2113 | { |
| 2114 | btm_cb.devcb.p_tx_power_cmpl_cb = NULL; |
Pavlin Radoslavov | 78bcff7 | 2015-12-04 17:36:34 -0800 | [diff] [blame] | 2115 | alarm_cancel(btm_cb.devcb.read_tx_power_timer); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2116 | return(BTM_NO_RESOURCES); |
| 2117 | } |
| 2118 | else |
| 2119 | return(BTM_CMD_STARTED); |
| 2120 | } |
| 2121 | |
| 2122 | /* If here, no BD Addr found */ |
| 2123 | return (BTM_UNKNOWN_ADDR); |
| 2124 | } |
Pavlin Radoslavov | 78bcff7 | 2015-12-04 17:36:34 -0800 | [diff] [blame] | 2125 | |
| 2126 | /******************************************************************************* |
| 2127 | ** |
| 2128 | ** Function btm_read_tx_power_timeout |
| 2129 | ** |
| 2130 | ** Description Callback when reading the tx power times out. |
| 2131 | ** |
| 2132 | ** Returns void |
| 2133 | ** |
| 2134 | *******************************************************************************/ |
| 2135 | void btm_read_tx_power_timeout(UNUSED_ATTR void *data) |
| 2136 | { |
| 2137 | tBTM_CMPL_CB *p_cb = btm_cb.devcb.p_tx_power_cmpl_cb; |
| 2138 | btm_cb.devcb.p_tx_power_cmpl_cb = NULL; |
| 2139 | if (p_cb) |
| 2140 | (*p_cb)((void *) NULL); |
| 2141 | } |
| 2142 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2143 | /******************************************************************************* |
| 2144 | ** |
| 2145 | ** Function btm_read_tx_power_complete |
| 2146 | ** |
| 2147 | ** Description This function is called when the command complete message |
| 2148 | ** is received from the HCI for the read tx power request. |
| 2149 | ** |
| 2150 | ** Returns void |
| 2151 | ** |
| 2152 | *******************************************************************************/ |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 2153 | void btm_read_tx_power_complete(uint8_t *p, bool is_ble) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2154 | { |
| 2155 | tBTM_CMPL_CB *p_cb = btm_cb.devcb.p_tx_power_cmpl_cb; |
| 2156 | tBTM_TX_POWER_RESULTS results; |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 2157 | uint16_t handle; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2158 | tACL_CONN *p_acl_cb = &btm_cb.acl_db[0]; |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 2159 | uint16_t index; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2160 | |
Pavlin Radoslavov | 78bcff7 | 2015-12-04 17:36:34 -0800 | [diff] [blame] | 2161 | BTM_TRACE_DEBUG("%s", __func__); |
| 2162 | alarm_cancel(btm_cb.devcb.read_tx_power_timer); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2163 | btm_cb.devcb.p_tx_power_cmpl_cb = NULL; |
| 2164 | |
Pavlin Radoslavov | 78bcff7 | 2015-12-04 17:36:34 -0800 | [diff] [blame] | 2165 | /* If there was a registered callback, call it */ |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2166 | if (p_cb) |
| 2167 | { |
| 2168 | STREAM_TO_UINT8 (results.hci_status, p); |
| 2169 | |
| 2170 | if (results.hci_status == HCI_SUCCESS) |
| 2171 | { |
| 2172 | results.status = BTM_SUCCESS; |
| 2173 | |
| 2174 | if (!is_ble) |
| 2175 | { |
| 2176 | STREAM_TO_UINT16 (handle, p); |
| 2177 | STREAM_TO_UINT8 (results.tx_power, p); |
| 2178 | |
| 2179 | /* Search through the list of active channels for the correct BD Addr */ |
| 2180 | for (index = 0; index < MAX_L2CAP_LINKS; index++, p_acl_cb++) |
| 2181 | { |
| 2182 | if ((p_acl_cb->in_use) && (handle == p_acl_cb->hci_handle)) |
| 2183 | { |
| 2184 | memcpy (results.rem_bda, p_acl_cb->remote_addr, BD_ADDR_LEN); |
| 2185 | break; |
| 2186 | } |
| 2187 | } |
| 2188 | } |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 2189 | #if (BLE_INCLUDED == TRUE) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2190 | else |
| 2191 | { |
| 2192 | STREAM_TO_UINT8 (results.tx_power, p); |
| 2193 | memcpy(results.rem_bda, btm_cb.devcb.read_tx_pwr_addr, BD_ADDR_LEN); |
| 2194 | } |
| 2195 | #endif |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 2196 | BTM_TRACE_DEBUG ("BTM TX power Complete: tx_power %d, hci status 0x%02x", |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2197 | results.tx_power, results.hci_status); |
| 2198 | } |
| 2199 | else |
| 2200 | results.status = BTM_ERR_PROCESSING; |
| 2201 | |
| 2202 | (*p_cb)(&results); |
| 2203 | } |
| 2204 | } |
| 2205 | |
| 2206 | /******************************************************************************* |
| 2207 | ** |
Pavlin Radoslavov | 78bcff7 | 2015-12-04 17:36:34 -0800 | [diff] [blame] | 2208 | ** Function btm_read_rssi_timeout |
| 2209 | ** |
| 2210 | ** Description Callback when reading the RSSI times out. |
| 2211 | ** |
| 2212 | ** Returns void |
| 2213 | ** |
| 2214 | *******************************************************************************/ |
| 2215 | void btm_read_rssi_timeout(UNUSED_ATTR void *data) |
| 2216 | { |
| 2217 | tBTM_CMPL_CB *p_cb = btm_cb.devcb.p_rssi_cmpl_cb; |
| 2218 | btm_cb.devcb.p_rssi_cmpl_cb = NULL; |
| 2219 | if (p_cb) |
| 2220 | (*p_cb)((void *) NULL); |
| 2221 | } |
| 2222 | |
| 2223 | /******************************************************************************* |
| 2224 | ** |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2225 | ** Function btm_read_rssi_complete |
| 2226 | ** |
| 2227 | ** Description This function is called when the command complete message |
| 2228 | ** is received from the HCI for the read rssi request. |
| 2229 | ** |
| 2230 | ** Returns void |
| 2231 | ** |
| 2232 | *******************************************************************************/ |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 2233 | void btm_read_rssi_complete (uint8_t *p) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2234 | { |
| 2235 | tBTM_CMPL_CB *p_cb = btm_cb.devcb.p_rssi_cmpl_cb; |
| 2236 | tBTM_RSSI_RESULTS results; |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 2237 | uint16_t handle; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2238 | tACL_CONN *p_acl_cb = &btm_cb.acl_db[0]; |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 2239 | uint16_t index; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2240 | |
Pavlin Radoslavov | 78bcff7 | 2015-12-04 17:36:34 -0800 | [diff] [blame] | 2241 | BTM_TRACE_DEBUG("%s", __func__); |
| 2242 | alarm_cancel(btm_cb.devcb.read_rssi_timer); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2243 | btm_cb.devcb.p_rssi_cmpl_cb = NULL; |
| 2244 | |
Pavlin Radoslavov | 78bcff7 | 2015-12-04 17:36:34 -0800 | [diff] [blame] | 2245 | /* If there was a registered callback, call it */ |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2246 | if (p_cb) |
| 2247 | { |
| 2248 | STREAM_TO_UINT8 (results.hci_status, p); |
| 2249 | |
| 2250 | if (results.hci_status == HCI_SUCCESS) |
| 2251 | { |
| 2252 | results.status = BTM_SUCCESS; |
| 2253 | |
| 2254 | STREAM_TO_UINT16 (handle, p); |
| 2255 | |
| 2256 | STREAM_TO_UINT8 (results.rssi, p); |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 2257 | BTM_TRACE_DEBUG ("BTM RSSI Complete: rssi %d, hci status 0x%02x", |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2258 | results.rssi, results.hci_status); |
| 2259 | |
| 2260 | /* Search through the list of active channels for the correct BD Addr */ |
| 2261 | for (index = 0; index < MAX_L2CAP_LINKS; index++, p_acl_cb++) |
| 2262 | { |
| 2263 | if ((p_acl_cb->in_use) && (handle == p_acl_cb->hci_handle)) |
| 2264 | { |
| 2265 | memcpy (results.rem_bda, p_acl_cb->remote_addr, BD_ADDR_LEN); |
| 2266 | break; |
| 2267 | } |
| 2268 | } |
| 2269 | } |
| 2270 | else |
| 2271 | results.status = BTM_ERR_PROCESSING; |
| 2272 | |
| 2273 | (*p_cb)(&results); |
| 2274 | } |
| 2275 | } |
| 2276 | |
| 2277 | /******************************************************************************* |
| 2278 | ** |
Pavlin Radoslavov | 78bcff7 | 2015-12-04 17:36:34 -0800 | [diff] [blame] | 2279 | ** Function btm_read_link_quality_timeout |
| 2280 | ** |
| 2281 | ** Description Callback when reading the link quality times out. |
| 2282 | ** |
| 2283 | ** Returns void |
| 2284 | ** |
| 2285 | *******************************************************************************/ |
| 2286 | void btm_read_link_quality_timeout(UNUSED_ATTR void *data) |
| 2287 | { |
| 2288 | tBTM_CMPL_CB *p_cb = btm_cb.devcb.p_link_qual_cmpl_cb; |
| 2289 | btm_cb.devcb.p_link_qual_cmpl_cb = NULL; |
| 2290 | if (p_cb) |
| 2291 | (*p_cb)((void *) NULL); |
| 2292 | } |
| 2293 | |
| 2294 | /******************************************************************************* |
| 2295 | ** |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2296 | ** Function btm_read_link_quality_complete |
| 2297 | ** |
| 2298 | ** Description This function is called when the command complete message |
| 2299 | ** is received from the HCI for the read link quality. |
| 2300 | ** |
| 2301 | ** Returns void |
| 2302 | ** |
| 2303 | *******************************************************************************/ |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 2304 | void btm_read_link_quality_complete(uint8_t *p) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2305 | { |
Pavlin Radoslavov | 78bcff7 | 2015-12-04 17:36:34 -0800 | [diff] [blame] | 2306 | tBTM_CMPL_CB *p_cb = btm_cb.devcb.p_link_qual_cmpl_cb; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2307 | tBTM_LINK_QUALITY_RESULTS results; |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 2308 | uint16_t handle; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2309 | tACL_CONN *p_acl_cb = &btm_cb.acl_db[0]; |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 2310 | uint16_t index; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2311 | |
Pavlin Radoslavov | 78bcff7 | 2015-12-04 17:36:34 -0800 | [diff] [blame] | 2312 | BTM_TRACE_DEBUG("%s", __func__); |
| 2313 | alarm_cancel(btm_cb.devcb.read_link_quality_timer); |
| 2314 | btm_cb.devcb.p_link_qual_cmpl_cb = NULL; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2315 | |
Pavlin Radoslavov | 78bcff7 | 2015-12-04 17:36:34 -0800 | [diff] [blame] | 2316 | /* If there was a registered callback, call it */ |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2317 | if (p_cb) |
| 2318 | { |
| 2319 | STREAM_TO_UINT8 (results.hci_status, p); |
| 2320 | |
| 2321 | if (results.hci_status == HCI_SUCCESS) |
| 2322 | { |
| 2323 | results.status = BTM_SUCCESS; |
| 2324 | |
| 2325 | STREAM_TO_UINT16 (handle, p); |
| 2326 | |
| 2327 | STREAM_TO_UINT8 (results.link_quality, p); |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 2328 | BTM_TRACE_DEBUG ("BTM Link Quality Complete: Link Quality %d, hci status 0x%02x", |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2329 | results.link_quality, results.hci_status); |
| 2330 | |
| 2331 | /* Search through the list of active channels for the correct BD Addr */ |
| 2332 | for (index = 0; index < MAX_L2CAP_LINKS; index++, p_acl_cb++) |
| 2333 | { |
| 2334 | if ((p_acl_cb->in_use) && (handle == p_acl_cb->hci_handle)) |
| 2335 | { |
| 2336 | memcpy (results.rem_bda, p_acl_cb->remote_addr, BD_ADDR_LEN); |
| 2337 | break; |
| 2338 | } |
| 2339 | } |
| 2340 | } |
| 2341 | else |
| 2342 | results.status = BTM_ERR_PROCESSING; |
| 2343 | |
| 2344 | (*p_cb)(&results); |
| 2345 | } |
| 2346 | } |
| 2347 | |
| 2348 | /******************************************************************************* |
| 2349 | ** |
| 2350 | ** Function btm_remove_acl |
| 2351 | ** |
| 2352 | ** Description This function is called to disconnect an ACL connection |
| 2353 | ** |
| 2354 | ** Returns BTM_SUCCESS if successfully initiated, otherwise BTM_NO_RESOURCES. |
| 2355 | ** |
| 2356 | *******************************************************************************/ |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2357 | tBTM_STATUS btm_remove_acl (BD_ADDR bd_addr, tBT_TRANSPORT transport) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2358 | { |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 2359 | uint16_t hci_handle = BTM_GetHCIConnHandle(bd_addr, transport); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2360 | tBTM_STATUS status = BTM_SUCCESS; |
| 2361 | |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 2362 | BTM_TRACE_DEBUG ("btm_remove_acl"); |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 2363 | #if (BTM_DISC_DURING_RS == TRUE) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2364 | tBTM_SEC_DEV_REC *p_dev_rec = btm_find_dev (bd_addr); |
| 2365 | |
| 2366 | /* Role Switch is pending, postpone until completed */ |
| 2367 | if (p_dev_rec && (p_dev_rec->rs_disc_pending == BTM_SEC_RS_PENDING)) |
| 2368 | { |
| 2369 | p_dev_rec->rs_disc_pending = BTM_SEC_DISC_PENDING; |
| 2370 | } |
| 2371 | else /* otherwise can disconnect right away */ |
| 2372 | #endif |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2373 | { |
Hemant Gupta | 831423e | 2014-01-08 12:42:13 +0530 | [diff] [blame] | 2374 | if (hci_handle != 0xFFFF && p_dev_rec && |
| 2375 | p_dev_rec->sec_state!= BTM_SEC_STATE_DISCONNECTING) |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 2376 | { |
| 2377 | if (!btsnd_hcic_disconnect (hci_handle, HCI_ERR_PEER_USER)) |
| 2378 | status = BTM_NO_RESOURCES; |
| 2379 | } |
| 2380 | else |
| 2381 | status = BTM_UNKNOWN_ADDR; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2382 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2383 | |
| 2384 | return status; |
| 2385 | } |
| 2386 | |
| 2387 | |
| 2388 | /******************************************************************************* |
| 2389 | ** |
| 2390 | ** Function BTM_SetTraceLevel |
| 2391 | ** |
| 2392 | ** Description This function sets the trace level for BTM. If called with |
| 2393 | ** a value of 0xFF, it simply returns the current trace level. |
| 2394 | ** |
| 2395 | ** Returns The new or current trace level |
| 2396 | ** |
| 2397 | *******************************************************************************/ |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 2398 | uint8_t BTM_SetTraceLevel (uint8_t new_level) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2399 | { |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 2400 | BTM_TRACE_DEBUG ("BTM_SetTraceLevel"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2401 | if (new_level != 0xFF) |
| 2402 | btm_cb.trace_level = new_level; |
| 2403 | |
| 2404 | return(btm_cb.trace_level); |
| 2405 | } |
| 2406 | |
| 2407 | /******************************************************************************* |
| 2408 | ** |
Zach Johnson | e7faae6 | 2014-10-27 17:23:49 -0700 | [diff] [blame] | 2409 | ** Function btm_cont_rswitch |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2410 | ** |
| 2411 | ** Description This function is called to continue processing an active |
Zach Johnson | e7faae6 | 2014-10-27 17:23:49 -0700 | [diff] [blame] | 2412 | ** role switch. It first disables encryption if enabled and |
| 2413 | ** EPR is not supported |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2414 | ** |
| 2415 | ** Returns void |
| 2416 | ** |
| 2417 | *******************************************************************************/ |
Zach Johnson | e7faae6 | 2014-10-27 17:23:49 -0700 | [diff] [blame] | 2418 | void btm_cont_rswitch (tACL_CONN *p, tBTM_SEC_DEV_REC *p_dev_rec, |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 2419 | uint8_t hci_status) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2420 | { |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 2421 | bool sw_ok = true; |
Zach Johnson | e7faae6 | 2014-10-27 17:23:49 -0700 | [diff] [blame] | 2422 | BTM_TRACE_DEBUG ("btm_cont_rswitch"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2423 | /* Check to see if encryption needs to be turned off if pending |
| 2424 | change of link key or role switch */ |
Zach Johnson | e7faae6 | 2014-10-27 17:23:49 -0700 | [diff] [blame] | 2425 | if (p->switch_role_state == BTM_ACL_SWKEY_STATE_MODE_CHANGE) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2426 | { |
| 2427 | /* Must turn off Encryption first if necessary */ |
| 2428 | /* Some devices do not support switch or change of link key while encryption is on */ |
| 2429 | if (p_dev_rec != NULL && ((p_dev_rec->sec_flags & BTM_SEC_ENCRYPTED) != 0) |
| 2430 | && !BTM_EPR_AVAILABLE(p)) |
| 2431 | { |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 2432 | if (btsnd_hcic_set_conn_encrypt (p->hci_handle, false)) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2433 | { |
| 2434 | p->encrypt_state = BTM_ACL_ENCRYPT_STATE_ENCRYPT_OFF; |
| 2435 | if (p->switch_role_state == BTM_ACL_SWKEY_STATE_MODE_CHANGE) |
| 2436 | p->switch_role_state = BTM_ACL_SWKEY_STATE_ENCRYPTION_OFF; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2437 | } |
| 2438 | else |
| 2439 | { |
| 2440 | /* Error occurred; set states back to Idle */ |
| 2441 | if (p->switch_role_state == BTM_ACL_SWKEY_STATE_MODE_CHANGE) |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 2442 | sw_ok = false; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2443 | } |
| 2444 | } |
| 2445 | else /* Encryption not used or EPR supported, continue with switch |
| 2446 | and/or change of link key */ |
| 2447 | { |
| 2448 | if (p->switch_role_state == BTM_ACL_SWKEY_STATE_MODE_CHANGE) |
| 2449 | { |
| 2450 | p->switch_role_state = BTM_ACL_SWKEY_STATE_IN_PROGRESS; |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 2451 | #if (BTM_DISC_DURING_RS == TRUE) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2452 | if (p_dev_rec) |
| 2453 | p_dev_rec->rs_disc_pending = BTM_SEC_RS_PENDING; |
| 2454 | #endif |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 2455 | sw_ok = btsnd_hcic_switch_role (p->remote_addr, (uint8_t)!p->link_role); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2456 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2457 | } |
| 2458 | |
| 2459 | if (!sw_ok) |
| 2460 | { |
| 2461 | p->switch_role_state = BTM_ACL_SWKEY_STATE_IDLE; |
| 2462 | btm_acl_report_role_change(hci_status, p->remote_addr); |
| 2463 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2464 | } |
| 2465 | } |
| 2466 | |
| 2467 | /******************************************************************************* |
| 2468 | ** |
| 2469 | ** Function btm_acl_resubmit_page |
| 2470 | ** |
| 2471 | ** Description send pending page request |
| 2472 | ** |
| 2473 | *******************************************************************************/ |
| 2474 | void btm_acl_resubmit_page (void) |
| 2475 | { |
| 2476 | tBTM_SEC_DEV_REC *p_dev_rec; |
| 2477 | BT_HDR *p_buf; |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 2478 | uint8_t *pp; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2479 | BD_ADDR bda; |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 2480 | BTM_TRACE_DEBUG ("btm_acl_resubmit_page"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2481 | /* If there were other page request schedule can start the next one */ |
Pavlin Radoslavov | 1a3844f | 2015-09-25 11:21:15 -0700 | [diff] [blame] | 2482 | if ((p_buf = (BT_HDR *)fixed_queue_try_dequeue(btm_cb.page_queue)) != NULL) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2483 | { |
| 2484 | /* skip 3 (2 bytes opcode and 1 byte len) to get to the bd_addr |
| 2485 | * for both create_conn and rmt_name */ |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 2486 | pp = (uint8_t *)(p_buf + 1) + p_buf->offset + 3; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2487 | |
| 2488 | STREAM_TO_BDADDR (bda, pp); |
| 2489 | |
| 2490 | p_dev_rec = btm_find_or_alloc_dev (bda); |
| 2491 | |
| 2492 | memcpy (btm_cb.connecting_bda, p_dev_rec->bd_addr, BD_ADDR_LEN); |
| 2493 | memcpy (btm_cb.connecting_dc, p_dev_rec->dev_class, DEV_CLASS_LEN); |
| 2494 | |
| 2495 | btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p_buf); |
| 2496 | } |
| 2497 | else |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 2498 | btm_cb.paging = false; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2499 | } |
| 2500 | |
| 2501 | /******************************************************************************* |
| 2502 | ** |
| 2503 | ** Function btm_acl_reset_paging |
| 2504 | ** |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 2505 | ** Description set paging to false and free the page queue - called at hci_reset |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2506 | ** |
| 2507 | *******************************************************************************/ |
| 2508 | void btm_acl_reset_paging (void) |
| 2509 | { |
| 2510 | BT_HDR *p; |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 2511 | BTM_TRACE_DEBUG ("btm_acl_reset_paging"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2512 | /* If we sent reset we are definitely not paging any more */ |
Pavlin Radoslavov | 1a3844f | 2015-09-25 11:21:15 -0700 | [diff] [blame] | 2513 | while ((p = (BT_HDR *)fixed_queue_try_dequeue(btm_cb.page_queue)) != NULL) |
Pavlin Radoslavov | cceb430 | 2016-02-05 13:54:43 -0800 | [diff] [blame] | 2514 | osi_free(p); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2515 | |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 2516 | btm_cb.paging = false; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2517 | } |
| 2518 | |
| 2519 | /******************************************************************************* |
| 2520 | ** |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2521 | ** Function btm_acl_paging |
| 2522 | ** |
| 2523 | ** Description send a paging command or queue it in btm_cb |
| 2524 | ** |
| 2525 | *******************************************************************************/ |
| 2526 | void btm_acl_paging (BT_HDR *p, BD_ADDR bda) |
| 2527 | { |
| 2528 | tBTM_SEC_DEV_REC *p_dev_rec; |
| 2529 | |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 2530 | BTM_TRACE_DEBUG ("btm_acl_paging discing:%d, paging:%d BDA: %06x%06x", |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2531 | btm_cb.discing, btm_cb.paging, |
| 2532 | (bda[0]<<16) + (bda[1]<<8) + bda[2], (bda[3]<<16) + (bda[4] << 8) + bda[5]); |
| 2533 | if (btm_cb.discing) |
| 2534 | { |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 2535 | btm_cb.paging = true; |
Pavlin Radoslavov | 1a3844f | 2015-09-25 11:21:15 -0700 | [diff] [blame] | 2536 | fixed_queue_enqueue(btm_cb.page_queue, p); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2537 | } |
| 2538 | else |
| 2539 | { |
| 2540 | if (!BTM_ACL_IS_CONNECTED (bda)) |
| 2541 | { |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 2542 | BTM_TRACE_DEBUG ("connecting_bda: %06x%06x", |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 2543 | (btm_cb.connecting_bda[0]<<16) + (btm_cb.connecting_bda[1]<<8) + |
| 2544 | btm_cb.connecting_bda[2], |
| 2545 | (btm_cb.connecting_bda[3]<<16) + (btm_cb.connecting_bda[4] << 8) + |
| 2546 | btm_cb.connecting_bda[5]); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2547 | if (btm_cb.paging && |
| 2548 | memcmp (bda, btm_cb.connecting_bda, BD_ADDR_LEN) != 0) |
| 2549 | { |
Pavlin Radoslavov | 1a3844f | 2015-09-25 11:21:15 -0700 | [diff] [blame] | 2550 | fixed_queue_enqueue(btm_cb.page_queue, p); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2551 | } |
| 2552 | else |
| 2553 | { |
| 2554 | p_dev_rec = btm_find_or_alloc_dev (bda); |
| 2555 | memcpy (btm_cb.connecting_bda, p_dev_rec->bd_addr, BD_ADDR_LEN); |
| 2556 | memcpy (btm_cb.connecting_dc, p_dev_rec->dev_class, DEV_CLASS_LEN); |
| 2557 | |
| 2558 | btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p); |
| 2559 | } |
| 2560 | |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 2561 | btm_cb.paging = true; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2562 | } |
| 2563 | else /* ACL is already up */ |
| 2564 | { |
| 2565 | btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p); |
| 2566 | } |
| 2567 | } |
| 2568 | } |
| 2569 | |
| 2570 | /******************************************************************************* |
| 2571 | ** |
| 2572 | ** Function btm_acl_notif_conn_collision |
| 2573 | ** |
| 2574 | ** Description Send connection collision event to upper layer if registered |
| 2575 | ** |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 2576 | ** Returns true if sent out to upper layer, |
| 2577 | ** false if no one needs the notification. |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2578 | ** |
| 2579 | *******************************************************************************/ |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 2580 | bool btm_acl_notif_conn_collision (BD_ADDR bda) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2581 | { |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2582 | tBTM_BL_EVENT_DATA evt_data; |
| 2583 | |
| 2584 | /* Report possible collision to the upper layer. */ |
| 2585 | if (btm_cb.p_bl_changed_cb) |
| 2586 | { |
Sharvil Nanavati | 5344d6d | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 2587 | BTM_TRACE_DEBUG ("btm_acl_notif_conn_collision: RemBdAddr: %02x%02x%02x%02x%02x%02x", |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2588 | bda[0], bda[1], bda[2], bda[3], bda[4], bda[5]); |
| 2589 | |
| 2590 | evt_data.event = BTM_BL_COLLISION_EVT; |
| 2591 | evt_data.conn.p_bda = bda; |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2592 | |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 2593 | #if (BLE_INCLUDED == TRUE) |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2594 | evt_data.conn.transport = BT_TRANSPORT_BR_EDR; |
| 2595 | evt_data.conn.handle = BTM_INVALID_HCI_HANDLE; |
| 2596 | #endif |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2597 | (*btm_cb.p_bl_changed_cb)(&evt_data); |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 2598 | return true; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2599 | } |
| 2600 | else |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 2601 | return false; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2602 | } |
| 2603 | |
| 2604 | |
| 2605 | /******************************************************************************* |
| 2606 | ** |
| 2607 | ** Function btm_acl_chk_peer_pkt_type_support |
| 2608 | ** |
| 2609 | ** Description Check if peer supports requested packets |
| 2610 | ** |
| 2611 | *******************************************************************************/ |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 2612 | void btm_acl_chk_peer_pkt_type_support (tACL_CONN *p, uint16_t *p_pkt_type) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2613 | { |
| 2614 | /* 3 and 5 slot packets? */ |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 2615 | 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] | 2616 | *p_pkt_type &= ~(BTM_ACL_PKT_TYPES_MASK_DH3 +BTM_ACL_PKT_TYPES_MASK_DM3); |
| 2617 | |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 2618 | 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] | 2619 | *p_pkt_type &= ~(BTM_ACL_PKT_TYPES_MASK_DH5 + BTM_ACL_PKT_TYPES_MASK_DM5); |
| 2620 | |
Zach Johnson | 5fc4be1 | 2014-09-29 14:03:20 -0700 | [diff] [blame] | 2621 | /* 2 and 3 MPS support? */ |
| 2622 | if (!HCI_EDR_ACL_2MPS_SUPPORTED(p->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0])) |
| 2623 | /* Not supported. Add 'not_supported' mask for all 2MPS packet types */ |
| 2624 | *p_pkt_type |= (BTM_ACL_PKT_TYPES_MASK_NO_2_DH1 + BTM_ACL_PKT_TYPES_MASK_NO_2_DH3 + |
| 2625 | BTM_ACL_PKT_TYPES_MASK_NO_2_DH5); |
| 2626 | |
| 2627 | if (!HCI_EDR_ACL_3MPS_SUPPORTED(p->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0])) |
| 2628 | /* Not supported. Add 'not_supported' mask for all 3MPS packet types */ |
| 2629 | *p_pkt_type |= (BTM_ACL_PKT_TYPES_MASK_NO_3_DH1 + BTM_ACL_PKT_TYPES_MASK_NO_3_DH3 + |
| 2630 | BTM_ACL_PKT_TYPES_MASK_NO_3_DH5); |
| 2631 | |
| 2632 | /* EDR 3 and 5 slot support? */ |
| 2633 | if (HCI_EDR_ACL_2MPS_SUPPORTED(p->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0]) |
| 2634 | || 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] | 2635 | { |
Zach Johnson | 5fc4be1 | 2014-09-29 14:03:20 -0700 | [diff] [blame] | 2636 | if (!HCI_3_SLOT_EDR_ACL_SUPPORTED(p->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0])) |
| 2637 | /* Not supported. Add 'not_supported' mask for all 3-slot EDR packet types */ |
| 2638 | *p_pkt_type |= (BTM_ACL_PKT_TYPES_MASK_NO_2_DH3 + BTM_ACL_PKT_TYPES_MASK_NO_3_DH3); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2639 | |
Zach Johnson | 5fc4be1 | 2014-09-29 14:03:20 -0700 | [diff] [blame] | 2640 | if (!HCI_5_SLOT_EDR_ACL_SUPPORTED(p->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0])) |
| 2641 | /* Not supported. Add 'not_supported' mask for all 5-slot EDR packet types */ |
| 2642 | *p_pkt_type |= (BTM_ACL_PKT_TYPES_MASK_NO_2_DH5 + BTM_ACL_PKT_TYPES_MASK_NO_3_DH5); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2643 | } |
| 2644 | } |