| The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
| 3 | * Copyright (C) 2009-2012 Broadcom Corporation |
| 4 | * |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at: |
| 8 | * |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | * |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | * |
| 17 | ******************************************************************************/ |
| 18 | |
| 19 | /****************************************************************************** |
| 20 | * |
| 21 | * this file contains functions relating to BLE management. |
| 22 | * |
| 23 | ******************************************************************************/ |
| 24 | |
| 25 | #include <string.h> |
| 26 | #include "bt_target.h" |
| Mike J. Chen | 5cd8bff | 2014-01-31 18:16:59 -0800 | [diff] [blame] | 27 | #include "bt_utils.h" |
| The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 28 | #include "l2cdefs.h" |
| 29 | #include "l2c_int.h" |
| 30 | #include "btu.h" |
| 31 | #include "btm_int.h" |
| 32 | #include "hcimsgs.h" |
| Chris Manton | 79ecab5 | 2014-10-31 14:54:51 -0700 | [diff] [blame] | 33 | #include "device/include/controller.h" |
| Nitin Arora | 36ad41b | 2015-06-10 17:10:57 -0700 | [diff] [blame] | 34 | #include "stack_config.h" |
| The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 35 | |
| 36 | #if (BLE_INCLUDED == TRUE) |
| Pavlin Radoslavov | 78bcff7 | 2015-12-04 17:36:34 -0800 | [diff] [blame] | 37 | |
| 38 | extern fixed_queue_t *btu_general_alarm_queue; |
| 39 | |
| Chaojing Sun | 97e75b7 | 2014-10-07 17:07:05 -0700 | [diff] [blame] | 40 | static void l2cble_start_conn_update (tL2C_LCB *p_lcb); |
| Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 41 | |
| The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 42 | /******************************************************************************* |
| 43 | ** |
| 44 | ** Function L2CA_CancelBleConnectReq |
| 45 | ** |
| 46 | ** Description Cancel a pending connection attempt to a BLE device. |
| 47 | ** |
| 48 | ** Parameters: BD Address of remote |
| 49 | ** |
| 50 | ** Return value: TRUE if connection was cancelled |
| 51 | ** |
| 52 | *******************************************************************************/ |
| 53 | BOOLEAN L2CA_CancelBleConnectReq (BD_ADDR rem_bda) |
| 54 | { |
| 55 | tL2C_LCB *p_lcb; |
| 56 | |
| 57 | /* There can be only one BLE connection request outstanding at a time */ |
| Andre Eisenbach | 6975b4d | 2013-08-05 16:55:38 -0700 | [diff] [blame] | 58 | if (btm_ble_get_conn_st() == BLE_CONN_IDLE) |
| The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 59 | { |
| Sharvil Nanavati | a51c9d9 | 2014-05-04 01:08:21 -0700 | [diff] [blame] | 60 | L2CAP_TRACE_WARNING ("L2CA_CancelBleConnectReq - no connection pending"); |
| The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 61 | return(FALSE); |
| 62 | } |
| 63 | |
| 64 | if (memcmp (rem_bda, l2cb.ble_connecting_bda, BD_ADDR_LEN)) |
| 65 | { |
| Sharvil Nanavati | a51c9d9 | 2014-05-04 01:08:21 -0700 | [diff] [blame] | 66 | L2CAP_TRACE_WARNING ("L2CA_CancelBleConnectReq - different BDA Connecting: %08x%04x Cancel: %08x%04x", |
| The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 67 | (l2cb.ble_connecting_bda[0]<<24)+(l2cb.ble_connecting_bda[1]<<16)+(l2cb.ble_connecting_bda[2]<<8)+l2cb.ble_connecting_bda[3], |
| 68 | (l2cb.ble_connecting_bda[4]<<8)+l2cb.ble_connecting_bda[5], |
| 69 | (rem_bda[0]<<24)+(rem_bda[1]<<16)+(rem_bda[2]<<8)+rem_bda[3], (rem_bda[4]<<8)+rem_bda[5]); |
| 70 | |
| 71 | return(FALSE); |
| 72 | } |
| 73 | |
| 74 | if (btsnd_hcic_ble_create_conn_cancel()) |
| 75 | { |
| Nitin Arora | 6564ea6 | 2014-11-19 14:24:08 -0800 | [diff] [blame] | 76 | p_lcb = l2cu_find_lcb_by_bd_addr(rem_bda, BT_TRANSPORT_LE); |
| 77 | /* Do not remove lcb if an LE link is already up as a peripheral */ |
| 78 | if (p_lcb != NULL && |
| 79 | !(p_lcb->link_role == HCI_ROLE_SLAVE && BTM_ACL_IS_CONNECTED(rem_bda))) |
| The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 80 | { |
| 81 | p_lcb->disc_reason = L2CAP_CONN_CANCEL; |
| 82 | l2cu_release_lcb (p_lcb); |
| 83 | } |
| Andre Eisenbach | 6975b4d | 2013-08-05 16:55:38 -0700 | [diff] [blame] | 84 | /* update state to be cancel, wait for connection cancel complete */ |
| 85 | btm_ble_set_conn_st (BLE_CONN_CANCEL); |
| The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 86 | |
| 87 | return(TRUE); |
| 88 | } |
| 89 | else |
| 90 | return(FALSE); |
| 91 | } |
| 92 | |
| Zhihai Xu | 15d0a0c | 2013-12-17 20:33:09 -0800 | [diff] [blame] | 93 | /******************************************************************************* |
| 94 | ** |
| The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 95 | ** Function L2CA_UpdateBleConnParams |
| 96 | ** |
| 97 | ** Description Update BLE connection parameters. |
| 98 | ** |
| 99 | ** Parameters: BD Address of remote |
| 100 | ** |
| 101 | ** Return value: TRUE if update started |
| 102 | ** |
| 103 | *******************************************************************************/ |
| Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 104 | BOOLEAN L2CA_UpdateBleConnParams (BD_ADDR rem_bda, UINT16 min_int, UINT16 max_int, |
| 105 | UINT16 latency, UINT16 timeout) |
| The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 106 | { |
| Andre Eisenbach | 01a069a | 2014-12-16 16:18:10 -0800 | [diff] [blame] | 107 | tL2C_LCB *p_lcb; |
| 108 | tACL_CONN *p_acl_cb = btm_bda_to_acl(rem_bda, BT_TRANSPORT_LE); |
| The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 109 | |
| Andre Eisenbach | 01a069a | 2014-12-16 16:18:10 -0800 | [diff] [blame] | 110 | /* See if we have a link control block for the remote device */ |
| 111 | p_lcb = l2cu_find_lcb_by_bd_addr (rem_bda, BT_TRANSPORT_LE); |
| The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 112 | |
| Andre Eisenbach | 01a069a | 2014-12-16 16:18:10 -0800 | [diff] [blame] | 113 | /* If we don't have one, create one and accept the connection. */ |
| 114 | if (!p_lcb || !p_acl_cb) |
| 115 | { |
| 116 | L2CAP_TRACE_WARNING ("L2CA_UpdateBleConnParams - unknown BD_ADDR %08x%04x", |
| 117 | (rem_bda[0]<<24)+(rem_bda[1]<<16)+(rem_bda[2]<<8)+rem_bda[3], |
| 118 | (rem_bda[4]<<8)+rem_bda[5]); |
| 119 | return(FALSE); |
| 120 | } |
| The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 121 | |
| Andre Eisenbach | 01a069a | 2014-12-16 16:18:10 -0800 | [diff] [blame] | 122 | if (p_lcb->transport != BT_TRANSPORT_LE) |
| 123 | { |
| 124 | L2CAP_TRACE_WARNING ("L2CA_UpdateBleConnParams - BD_ADDR %08x%04x not LE", |
| 125 | (rem_bda[0]<<24)+(rem_bda[1]<<16)+(rem_bda[2]<<8)+rem_bda[3], |
| 126 | (rem_bda[4]<<8)+rem_bda[5]); |
| 127 | return(FALSE); |
| 128 | } |
| Chaojing Sun | 97e75b7 | 2014-10-07 17:07:05 -0700 | [diff] [blame] | 129 | |
| Andre Eisenbach | 01a069a | 2014-12-16 16:18:10 -0800 | [diff] [blame] | 130 | p_lcb->min_interval = min_int; |
| 131 | p_lcb->max_interval = max_int; |
| 132 | p_lcb->latency = latency; |
| 133 | p_lcb->timeout = timeout; |
| 134 | p_lcb->conn_update_mask |= L2C_BLE_NEW_CONN_PARAM; |
| Chaojing Sun | 97e75b7 | 2014-10-07 17:07:05 -0700 | [diff] [blame] | 135 | |
| Andre Eisenbach | 01a069a | 2014-12-16 16:18:10 -0800 | [diff] [blame] | 136 | l2cble_start_conn_update(p_lcb); |
| The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 137 | |
| Andre Eisenbach | 01a069a | 2014-12-16 16:18:10 -0800 | [diff] [blame] | 138 | return(TRUE); |
| The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | |
| 142 | /******************************************************************************* |
| 143 | ** |
| 144 | ** Function L2CA_EnableUpdateBleConnParams |
| 145 | ** |
| 146 | ** Description Enable or disable update based on the request from the peer |
| 147 | ** |
| 148 | ** Parameters: BD Address of remote |
| 149 | ** |
| 150 | ** Return value: TRUE if update started |
| 151 | ** |
| 152 | *******************************************************************************/ |
| 153 | BOOLEAN L2CA_EnableUpdateBleConnParams (BD_ADDR rem_bda, BOOLEAN enable) |
| 154 | { |
| Nitin Arora | 36ad41b | 2015-06-10 17:10:57 -0700 | [diff] [blame] | 155 | if (stack_config_get_interface()->get_pts_conn_updates_disabled()) |
| 156 | return false; |
| 157 | |
| The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 158 | tL2C_LCB *p_lcb; |
| 159 | |
| 160 | /* See if we have a link control block for the remote device */ |
| Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 161 | p_lcb = l2cu_find_lcb_by_bd_addr (rem_bda, BT_TRANSPORT_LE); |
| The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 162 | |
| The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 163 | if (!p_lcb) |
| 164 | { |
| Sharvil Nanavati | a51c9d9 | 2014-05-04 01:08:21 -0700 | [diff] [blame] | 165 | L2CAP_TRACE_WARNING ("L2CA_EnableUpdateBleConnParams - unknown BD_ADDR %08x%04x", |
| Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 166 | (rem_bda[0]<<24)+(rem_bda[1]<<16)+(rem_bda[2]<<8)+rem_bda[3], |
| 167 | (rem_bda[4]<<8)+rem_bda[5]); |
| The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 168 | return (FALSE); |
| 169 | } |
| 170 | |
| Sharvil Nanavati | a51c9d9 | 2014-05-04 01:08:21 -0700 | [diff] [blame] | 171 | L2CAP_TRACE_API ("%s - BD_ADDR %08x%04x enable %d current upd state 0x%02x",__FUNCTION__, |
| Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 172 | (rem_bda[0]<<24)+(rem_bda[1]<<16)+(rem_bda[2]<<8)+rem_bda[3], |
| 173 | (rem_bda[4]<<8)+rem_bda[5], enable, p_lcb->conn_update_mask); |
| The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 174 | |
| Andre Eisenbach | 01a069a | 2014-12-16 16:18:10 -0800 | [diff] [blame] | 175 | if (p_lcb->transport != BT_TRANSPORT_LE) |
| The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 176 | { |
| Andre Eisenbach | 01a069a | 2014-12-16 16:18:10 -0800 | [diff] [blame] | 177 | L2CAP_TRACE_WARNING ("%s - BD_ADDR %08x%04x not LE (link role %d)", __FUNCTION__, |
| Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 178 | (rem_bda[0]<<24)+(rem_bda[1]<<16)+(rem_bda[2]<<8)+rem_bda[3], |
| 179 | (rem_bda[4]<<8)+rem_bda[5], p_lcb->link_role); |
| The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 180 | return (FALSE); |
| 181 | } |
| 182 | |
| 183 | if (enable) |
| Chaojing Sun | 97e75b7 | 2014-10-07 17:07:05 -0700 | [diff] [blame] | 184 | p_lcb->conn_update_mask &= ~L2C_BLE_CONN_UPDATE_DISABLE; |
| 185 | else |
| 186 | p_lcb->conn_update_mask |= L2C_BLE_CONN_UPDATE_DISABLE; |
| The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 187 | |
| Chaojing Sun | 97e75b7 | 2014-10-07 17:07:05 -0700 | [diff] [blame] | 188 | l2cble_start_conn_update(p_lcb); |
| Zhihai Xu | 15d0a0c | 2013-12-17 20:33:09 -0800 | [diff] [blame] | 189 | |
| The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 190 | return (TRUE); |
| 191 | } |
| 192 | |
| Zhihai Xu | 15d0a0c | 2013-12-17 20:33:09 -0800 | [diff] [blame] | 193 | |
| 194 | /******************************************************************************* |
| 195 | ** |
| The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 196 | ** Function L2CA_GetBleConnRole |
| 197 | ** |
| 198 | ** Description This function returns the connection role. |
| 199 | ** |
| 200 | ** Returns link role. |
| 201 | ** |
| 202 | *******************************************************************************/ |
| 203 | UINT8 L2CA_GetBleConnRole (BD_ADDR bd_addr) |
| 204 | { |
| 205 | UINT8 role = HCI_ROLE_UNKNOWN; |
| 206 | |
| 207 | tL2C_LCB *p_lcb; |
| 208 | |
| Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 209 | if ((p_lcb = l2cu_find_lcb_by_bd_addr (bd_addr, BT_TRANSPORT_LE)) != NULL) |
| The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 210 | role = p_lcb->link_role; |
| 211 | |
| 212 | return role; |
| 213 | } |
| 214 | /******************************************************************************* |
| 215 | ** |
| 216 | ** Function L2CA_GetDisconnectReason |
| 217 | ** |
| 218 | ** Description This function returns the disconnect reason code. |
| 219 | ** |
| 220 | ** Returns disconnect reason |
| 221 | ** |
| 222 | *******************************************************************************/ |
| Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 223 | UINT16 L2CA_GetDisconnectReason (BD_ADDR remote_bda, tBT_TRANSPORT transport) |
| The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 224 | { |
| 225 | tL2C_LCB *p_lcb; |
| 226 | UINT16 reason = 0; |
| 227 | |
| Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 228 | if ((p_lcb = l2cu_find_lcb_by_bd_addr (remote_bda, transport)) != NULL) |
| The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 229 | reason = p_lcb->disc_reason; |
| 230 | |
| Sharvil Nanavati | a51c9d9 | 2014-05-04 01:08:21 -0700 | [diff] [blame] | 231 | L2CAP_TRACE_DEBUG ("L2CA_GetDisconnectReason=%d ",reason); |
| The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 232 | |
| 233 | return reason; |
| 234 | } |
| 235 | |
| Jakub Pawlowski | 9376f77 | 2016-05-10 16:43:41 -0700 | [diff] [blame] | 236 | void l2cble_use_preferred_conn_params(BD_ADDR bda) { |
| 237 | tL2C_LCB *p_lcb = l2cu_find_lcb_by_bd_addr (bda, BT_TRANSPORT_LE); |
| 238 | tBTM_SEC_DEV_REC *p_dev_rec = btm_find_or_alloc_dev (bda); |
| 239 | |
| 240 | /* If there are any preferred connection parameters, set them now */ |
| 241 | if ( (p_dev_rec->conn_params.min_conn_int >= BTM_BLE_CONN_INT_MIN ) && |
| 242 | (p_dev_rec->conn_params.min_conn_int <= BTM_BLE_CONN_INT_MAX ) && |
| 243 | (p_dev_rec->conn_params.max_conn_int >= BTM_BLE_CONN_INT_MIN ) && |
| 244 | (p_dev_rec->conn_params.max_conn_int <= BTM_BLE_CONN_INT_MAX ) && |
| 245 | (p_dev_rec->conn_params.slave_latency <= BTM_BLE_CONN_LATENCY_MAX ) && |
| 246 | (p_dev_rec->conn_params.supervision_tout >= BTM_BLE_CONN_SUP_TOUT_MIN) && |
| 247 | (p_dev_rec->conn_params.supervision_tout <= BTM_BLE_CONN_SUP_TOUT_MAX) && |
| 248 | ((p_lcb->min_interval < p_dev_rec->conn_params.min_conn_int && |
| 249 | p_dev_rec->conn_params.min_conn_int != BTM_BLE_CONN_PARAM_UNDEF) || |
| 250 | (p_lcb->min_interval > p_dev_rec->conn_params.max_conn_int) || |
| 251 | (p_lcb->latency > p_dev_rec->conn_params.slave_latency) || |
| 252 | (p_lcb->timeout > p_dev_rec->conn_params.supervision_tout))) |
| 253 | { |
| 254 | L2CAP_TRACE_DEBUG ("%s: HANDLE=%d min_conn_int=%d max_conn_int=%d slave_latency=%d supervision_tout=%d", __func__, |
| 255 | p_lcb->handle, p_dev_rec->conn_params.min_conn_int, p_dev_rec->conn_params.max_conn_int, |
| 256 | p_dev_rec->conn_params.slave_latency, p_dev_rec->conn_params.supervision_tout); |
| 257 | |
| 258 | p_lcb->min_interval = p_dev_rec->conn_params.min_conn_int; |
| 259 | p_lcb->max_interval = p_dev_rec->conn_params.max_conn_int; |
| 260 | p_lcb->timeout = p_dev_rec->conn_params.supervision_tout; |
| 261 | p_lcb->latency = p_dev_rec->conn_params.slave_latency; |
| 262 | |
| 263 | btsnd_hcic_ble_upd_ll_conn_params (p_lcb->handle, |
| 264 | p_dev_rec->conn_params.min_conn_int, |
| 265 | p_dev_rec->conn_params.max_conn_int, |
| 266 | p_dev_rec->conn_params.slave_latency, |
| 267 | p_dev_rec->conn_params.supervision_tout, |
| 268 | 0, 0); |
| 269 | } |
| 270 | } |
| 271 | |
| The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 272 | /******************************************************************************* |
| 273 | ** |
| Priti Aghera | 9c29d08 | 2014-09-02 15:41:56 -0700 | [diff] [blame] | 274 | ** Function l2cble_notify_le_connection |
| 275 | ** |
| 276 | ** Description This function notifiy the l2cap connection to the app layer |
| 277 | ** |
| 278 | ** Returns none |
| 279 | ** |
| 280 | *******************************************************************************/ |
| 281 | void l2cble_notify_le_connection (BD_ADDR bda) |
| 282 | { |
| 283 | tL2C_LCB *p_lcb = l2cu_find_lcb_by_bd_addr (bda, BT_TRANSPORT_LE); |
| Prerepa Viswanadham | 7ae2515 | 2014-09-10 17:08:11 -0700 | [diff] [blame] | 284 | tACL_CONN *p_acl = btm_bda_to_acl(bda, BT_TRANSPORT_LE) ; |
| Navin Kochar | 6721232 | 2016-03-09 23:11:53 +0530 | [diff] [blame] | 285 | tL2C_CCB *p_ccb; |
| Priti Aghera | 9c29d08 | 2014-09-02 15:41:56 -0700 | [diff] [blame] | 286 | |
| Prerepa Viswanadham | 7ae2515 | 2014-09-10 17:08:11 -0700 | [diff] [blame] | 287 | if (p_lcb != NULL && p_acl != NULL && p_lcb->link_state != LST_CONNECTED) |
| 288 | { |
| 289 | /* update link status */ |
| 290 | btm_establish_continue(p_acl); |
| 291 | /* update l2cap link status and send callback */ |
| 292 | p_lcb->link_state = LST_CONNECTED; |
| Priti Aghera | 9c29d08 | 2014-09-02 15:41:56 -0700 | [diff] [blame] | 293 | l2cu_process_fixed_chnl_resp (p_lcb); |
| Prerepa Viswanadham | 7ae2515 | 2014-09-10 17:08:11 -0700 | [diff] [blame] | 294 | } |
| Navin Kochar | 6721232 | 2016-03-09 23:11:53 +0530 | [diff] [blame] | 295 | |
| 296 | /* For all channels, send the event through their FSMs */ |
| 297 | for (p_ccb = p_lcb->ccb_queue.p_first_ccb; p_ccb; p_ccb = p_ccb->p_next_ccb) |
| 298 | { |
| 299 | if (p_ccb->chnl_state == CST_CLOSED) |
| 300 | l2c_csm_execute (p_ccb, L2CEVT_LP_CONNECT_CFM, NULL); |
| 301 | } |
| Jakub Pawlowski | 9376f77 | 2016-05-10 16:43:41 -0700 | [diff] [blame] | 302 | |
| 303 | l2cble_use_preferred_conn_params(bda); |
| Priti Aghera | 9c29d08 | 2014-09-02 15:41:56 -0700 | [diff] [blame] | 304 | } |
| 305 | |
| 306 | /******************************************************************************* |
| 307 | ** |
| The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 308 | ** Function l2cble_scanner_conn_comp |
| 309 | ** |
| 310 | ** Description This function is called when an HCI Connection Complete |
| 311 | ** event is received while we are a scanner (so we are master). |
| 312 | ** |
| 313 | ** Returns void |
| 314 | ** |
| 315 | *******************************************************************************/ |
| Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 316 | void l2cble_scanner_conn_comp (UINT16 handle, BD_ADDR bda, tBLE_ADDR_TYPE type, |
| 317 | UINT16 conn_interval, UINT16 conn_latency, UINT16 conn_timeout) |
| The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 318 | { |
| 319 | tL2C_LCB *p_lcb; |
| 320 | tBTM_SEC_DEV_REC *p_dev_rec = btm_find_or_alloc_dev (bda); |
| 321 | |
| Sharvil Nanavati | a51c9d9 | 2014-05-04 01:08:21 -0700 | [diff] [blame] | 322 | L2CAP_TRACE_DEBUG ("l2cble_scanner_conn_comp: HANDLE=%d addr_type=%d conn_interval=%d slave_latency=%d supervision_tout=%d", |
| The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 323 | handle, type, conn_interval, conn_latency, conn_timeout); |
| 324 | |
| 325 | l2cb.is_ble_connecting = FALSE; |
| 326 | |
| The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 327 | /* See if we have a link control block for the remote device */ |
| Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 328 | p_lcb = l2cu_find_lcb_by_bd_addr (bda, BT_TRANSPORT_LE); |
| The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 329 | |
| 330 | /* If we don't have one, create one. this is auto connection complete. */ |
| 331 | if (!p_lcb) |
| 332 | { |
| Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 333 | p_lcb = l2cu_allocate_lcb (bda, FALSE, BT_TRANSPORT_LE); |
| The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 334 | if (!p_lcb) |
| 335 | { |
| 336 | btm_sec_disconnect (handle, HCI_ERR_NO_CONNECTION); |
| Sharvil Nanavati | a51c9d9 | 2014-05-04 01:08:21 -0700 | [diff] [blame] | 337 | L2CAP_TRACE_ERROR ("l2cble_scanner_conn_comp - failed to allocate LCB"); |
| The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 338 | return; |
| 339 | } |
| 340 | else |
| 341 | { |
| 342 | if (!l2cu_initialize_fixed_ccb (p_lcb, L2CAP_ATT_CID, &l2cb.fixed_reg[L2CAP_ATT_CID - L2CAP_FIRST_FIXED_CHNL].fixed_chnl_opts)) |
| 343 | { |
| 344 | btm_sec_disconnect (handle, HCI_ERR_NO_CONNECTION); |
| Sharvil Nanavati | a51c9d9 | 2014-05-04 01:08:21 -0700 | [diff] [blame] | 345 | L2CAP_TRACE_WARNING ("l2cble_scanner_conn_comp - LCB but no CCB"); |
| The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 346 | return ; |
| 347 | } |
| 348 | } |
| 349 | } |
| 350 | else if (p_lcb->link_state != LST_CONNECTING) |
| 351 | { |
| Sharvil Nanavati | a51c9d9 | 2014-05-04 01:08:21 -0700 | [diff] [blame] | 352 | L2CAP_TRACE_ERROR ("L2CAP got BLE scanner conn_comp in bad state: %d", p_lcb->link_state); |
| The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 353 | return; |
| 354 | } |
| Pavlin Radoslavov | 78bcff7 | 2015-12-04 17:36:34 -0800 | [diff] [blame] | 355 | alarm_cancel(p_lcb->l2c_lcb_timer); |
| The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 356 | |
| 357 | /* Save the handle */ |
| 358 | p_lcb->handle = handle; |
| 359 | |
| 360 | /* Connected OK. Change state to connected, we were scanning so we are master */ |
| The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 361 | p_lcb->link_role = HCI_ROLE_MASTER; |
| Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 362 | p_lcb->transport = BT_TRANSPORT_LE; |
| The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 363 | |
| Andre Eisenbach | 01a069a | 2014-12-16 16:18:10 -0800 | [diff] [blame] | 364 | /* update link parameter, set slave link as non-spec default upon link up */ |
| 365 | p_lcb->min_interval = p_lcb->max_interval = conn_interval; |
| 366 | p_lcb->timeout = conn_timeout; |
| 367 | p_lcb->latency = conn_latency; |
| 368 | p_lcb->conn_update_mask = L2C_BLE_NOT_DEFAULT_PARAM; |
| 369 | |
| Jakub Pawlowski | 272c971 | 2016-05-10 13:29:59 -0700 | [diff] [blame] | 370 | /* Tell BTM Acl management about the link */ |
| 371 | btm_acl_created (bda, NULL, p_dev_rec->sec_bd_name, handle, p_lcb->link_role, BT_TRANSPORT_LE); |
| 372 | |
| 373 | p_lcb->peer_chnl_mask[0] = L2CAP_FIXED_CHNL_ATT_BIT | L2CAP_FIXED_CHNL_BLE_SIG_BIT | L2CAP_FIXED_CHNL_SMP_BIT; |
| 374 | |
| 375 | btm_ble_set_conn_st(BLE_CONN_IDLE); |
| 376 | |
| 377 | #if BLE_PRIVACY_SPT == TRUE |
| 378 | btm_ble_disable_resolving_list(BTM_BLE_RL_INIT, TRUE); |
| 379 | #endif |
| The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 380 | } |
| 381 | |
| 382 | |
| 383 | /******************************************************************************* |
| 384 | ** |
| 385 | ** Function l2cble_advertiser_conn_comp |
| 386 | ** |
| 387 | ** Description This function is called when an HCI Connection Complete |
| 388 | ** event is received while we are an advertiser (so we are slave). |
| 389 | ** |
| 390 | ** Returns void |
| 391 | ** |
| 392 | *******************************************************************************/ |
| 393 | void l2cble_advertiser_conn_comp (UINT16 handle, BD_ADDR bda, tBLE_ADDR_TYPE type, |
| 394 | UINT16 conn_interval, UINT16 conn_latency, UINT16 conn_timeout) |
| 395 | { |
| 396 | tL2C_LCB *p_lcb; |
| 397 | tBTM_SEC_DEV_REC *p_dev_rec; |
| Mike J. Chen | 5cd8bff | 2014-01-31 18:16:59 -0800 | [diff] [blame] | 398 | UNUSED(type); |
| 399 | UNUSED(conn_interval); |
| 400 | UNUSED(conn_latency); |
| 401 | UNUSED(conn_timeout); |
| The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 402 | |
| 403 | /* See if we have a link control block for the remote device */ |
| Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 404 | p_lcb = l2cu_find_lcb_by_bd_addr (bda, BT_TRANSPORT_LE); |
| The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 405 | |
| 406 | /* If we don't have one, create one and accept the connection. */ |
| 407 | if (!p_lcb) |
| 408 | { |
| Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 409 | p_lcb = l2cu_allocate_lcb (bda, FALSE, BT_TRANSPORT_LE); |
| The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 410 | if (!p_lcb) |
| 411 | { |
| 412 | btm_sec_disconnect (handle, HCI_ERR_NO_CONNECTION); |
| Sharvil Nanavati | a51c9d9 | 2014-05-04 01:08:21 -0700 | [diff] [blame] | 413 | L2CAP_TRACE_ERROR ("l2cble_advertiser_conn_comp - failed to allocate LCB"); |
| The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 414 | return; |
| 415 | } |
| 416 | else |
| 417 | { |
| 418 | if (!l2cu_initialize_fixed_ccb (p_lcb, L2CAP_ATT_CID, &l2cb.fixed_reg[L2CAP_ATT_CID - L2CAP_FIRST_FIXED_CHNL].fixed_chnl_opts)) |
| 419 | { |
| 420 | btm_sec_disconnect (handle, HCI_ERR_NO_CONNECTION); |
| Sharvil Nanavati | a51c9d9 | 2014-05-04 01:08:21 -0700 | [diff] [blame] | 421 | L2CAP_TRACE_WARNING ("l2cble_scanner_conn_comp - LCB but no CCB"); |
| The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 422 | return ; |
| 423 | } |
| 424 | } |
| 425 | } |
| 426 | |
| 427 | /* Save the handle */ |
| 428 | p_lcb->handle = handle; |
| 429 | |
| 430 | /* Connected OK. Change state to connected, we were advertising, so we are slave */ |
| The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 431 | p_lcb->link_role = HCI_ROLE_SLAVE; |
| Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 432 | p_lcb->transport = BT_TRANSPORT_LE; |
| The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 433 | |
| Andre Eisenbach | 01a069a | 2014-12-16 16:18:10 -0800 | [diff] [blame] | 434 | /* update link parameter, set slave link as non-spec default upon link up */ |
| 435 | p_lcb->min_interval = p_lcb->max_interval = conn_interval; |
| 436 | p_lcb->timeout = conn_timeout; |
| 437 | p_lcb->latency = conn_latency; |
| 438 | p_lcb->conn_update_mask = L2C_BLE_NOT_DEFAULT_PARAM; |
| 439 | |
| The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 440 | /* Tell BTM Acl management about the link */ |
| 441 | p_dev_rec = btm_find_or_alloc_dev (bda); |
| 442 | |
| Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 443 | btm_acl_created (bda, NULL, p_dev_rec->sec_bd_name, handle, p_lcb->link_role, BT_TRANSPORT_LE); |
| The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 444 | |
| Andre Eisenbach | a021a12 | 2015-05-20 23:55:13 -0700 | [diff] [blame] | 445 | #if BLE_PRIVACY_SPT == TRUE |
| Satya Calloji | 70b9598 | 2015-04-23 23:39:49 -0700 | [diff] [blame] | 446 | btm_ble_disable_resolving_list(BTM_BLE_RL_ADV, TRUE); |
| Andre Eisenbach | a021a12 | 2015-05-20 23:55:13 -0700 | [diff] [blame] | 447 | #endif |
| Satya Calloji | 70b9598 | 2015-04-23 23:39:49 -0700 | [diff] [blame] | 448 | |
| The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 449 | p_lcb->peer_chnl_mask[0] = L2CAP_FIXED_CHNL_ATT_BIT | L2CAP_FIXED_CHNL_BLE_SIG_BIT | L2CAP_FIXED_CHNL_SMP_BIT; |
| 450 | |
| Zach Johnson | 30e5806 | 2014-09-26 21:14:34 -0700 | [diff] [blame] | 451 | 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] | 452 | { |
| Prerepa Viswanadham | 7ae2515 | 2014-09-10 17:08:11 -0700 | [diff] [blame] | 453 | p_lcb->link_state = LST_CONNECTED; |
| Priti Aghera | 9c29d08 | 2014-09-02 15:41:56 -0700 | [diff] [blame] | 454 | l2cu_process_fixed_chnl_resp (p_lcb); |
| 455 | } |
| Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 456 | |
| 457 | /* when adv and initiating are both active, cancel the direct connection */ |
| 458 | if (l2cb.is_ble_connecting && memcmp(bda, l2cb.ble_connecting_bda, BD_ADDR_LEN) == 0) |
| 459 | { |
| 460 | L2CA_CancelBleConnectReq(bda); |
| 461 | } |
| The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 462 | } |
| 463 | |
| 464 | /******************************************************************************* |
| 465 | ** |
| 466 | ** Function l2cble_conn_comp |
| 467 | ** |
| 468 | ** Description This function is called when an HCI Connection Complete |
| 469 | ** event is received. |
| 470 | ** |
| 471 | ** Returns void |
| 472 | ** |
| 473 | *******************************************************************************/ |
| 474 | void l2cble_conn_comp(UINT16 handle, UINT8 role, BD_ADDR bda, tBLE_ADDR_TYPE type, |
| 475 | UINT16 conn_interval, UINT16 conn_latency, UINT16 conn_timeout) |
| 476 | { |
| Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 477 | btm_ble_update_link_topology_mask(role, TRUE); |
| 478 | |
| The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 479 | if (role == HCI_ROLE_MASTER) |
| 480 | { |
| 481 | l2cble_scanner_conn_comp(handle, bda, type, conn_interval, conn_latency, conn_timeout); |
| 482 | } |
| 483 | else |
| 484 | { |
| 485 | l2cble_advertiser_conn_comp(handle, bda, type, conn_interval, conn_latency, conn_timeout); |
| 486 | } |
| 487 | } |
| Chaojing Sun | 97e75b7 | 2014-10-07 17:07:05 -0700 | [diff] [blame] | 488 | |
| 489 | /******************************************************************************* |
| 490 | ** |
| 491 | ** Function l2cble_start_conn_update |
| 492 | ** |
| 493 | ** Description start BLE connection parameter update process based on status |
| 494 | ** |
| 495 | ** Parameters: lcb : l2cap link control block |
| 496 | ** |
| 497 | ** Return value: none |
| 498 | ** |
| 499 | *******************************************************************************/ |
| 500 | static void l2cble_start_conn_update (tL2C_LCB *p_lcb) |
| 501 | { |
| Andre Eisenbach | 01a069a | 2014-12-16 16:18:10 -0800 | [diff] [blame] | 502 | UINT16 min_conn_int, max_conn_int, slave_latency, supervision_tout; |
| Andre Eisenbach | 01a069a | 2014-12-16 16:18:10 -0800 | [diff] [blame] | 503 | tACL_CONN *p_acl_cb = btm_bda_to_acl(p_lcb->remote_bd_addr, BT_TRANSPORT_LE); |
| Chaojing Sun | 97e75b7 | 2014-10-07 17:07:05 -0700 | [diff] [blame] | 504 | |
| Arman Uguray | cab5fc1 | 2015-06-02 14:56:45 -0700 | [diff] [blame] | 505 | // TODO(armansito): The return value of this call wasn't being used but the |
| 506 | // logic of this function might be depending on its side effects. We should |
| 507 | // verify if this call is needed at all and remove it otherwise. |
| 508 | btm_find_or_alloc_dev(p_lcb->remote_bd_addr); |
| 509 | |
| Chaojing Sun | 97e75b7 | 2014-10-07 17:07:05 -0700 | [diff] [blame] | 510 | if (p_lcb->conn_update_mask & L2C_BLE_UPDATE_PENDING) return; |
| 511 | |
| 512 | if (p_lcb->conn_update_mask & L2C_BLE_CONN_UPDATE_DISABLE) |
| 513 | { |
| 514 | /* application requests to disable parameters update. |
| 515 | If parameters are already updated, lets set them |
| 516 | up to what has been requested during connection establishement */ |
| Andre Eisenbach | 01a069a | 2014-12-16 16:18:10 -0800 | [diff] [blame] | 517 | if (p_lcb->conn_update_mask & L2C_BLE_NOT_DEFAULT_PARAM && |
| 518 | /* current connection interval is greater than default min */ |
| 519 | p_lcb->min_interval > BTM_BLE_CONN_INT_MIN) |
| Chaojing Sun | 97e75b7 | 2014-10-07 17:07:05 -0700 | [diff] [blame] | 520 | { |
| Andre Eisenbach | 01a069a | 2014-12-16 16:18:10 -0800 | [diff] [blame] | 521 | /* use 7.5 ms as fast connection parameter, 0 slave latency */ |
| 522 | min_conn_int = max_conn_int = BTM_BLE_CONN_INT_MIN; |
| 523 | slave_latency = BTM_BLE_CONN_SLAVE_LATENCY_DEF; |
| 524 | supervision_tout = BTM_BLE_CONN_TIMEOUT_DEF; |
| 525 | |
| 526 | /* if both side 4.1, or we are master device, send HCI command */ |
| 527 | if (p_lcb->link_role == HCI_ROLE_MASTER |
| 528 | #if (defined BLE_LLT_INCLUDED) && (BLE_LLT_INCLUDED == TRUE) |
| Zach Johnson | 30e5806 | 2014-09-26 21:14:34 -0700 | [diff] [blame] | 529 | || (HCI_LE_CONN_PARAM_REQ_SUPPORTED(controller_get_interface()->get_features_ble()->as_array) && |
| Andre Eisenbach | 01a069a | 2014-12-16 16:18:10 -0800 | [diff] [blame] | 530 | HCI_LE_CONN_PARAM_REQ_SUPPORTED(p_acl_cb->peer_le_features)) |
| 531 | #endif |
| 532 | ) |
| 533 | { |
| 534 | btsnd_hcic_ble_upd_ll_conn_params(p_lcb->handle, min_conn_int, max_conn_int, |
| 535 | slave_latency, supervision_tout, 0, 0); |
| 536 | p_lcb->conn_update_mask |= L2C_BLE_UPDATE_PENDING; |
| 537 | } |
| 538 | else |
| 539 | { |
| 540 | l2cu_send_peer_ble_par_req (p_lcb, min_conn_int, max_conn_int, slave_latency, supervision_tout); |
| 541 | } |
| Chaojing Sun | 97e75b7 | 2014-10-07 17:07:05 -0700 | [diff] [blame] | 542 | p_lcb->conn_update_mask &= ~L2C_BLE_NOT_DEFAULT_PARAM; |
| Andre Eisenbach | 01a069a | 2014-12-16 16:18:10 -0800 | [diff] [blame] | 543 | p_lcb->conn_update_mask |= L2C_BLE_NEW_CONN_PARAM; |
| 544 | } |
| Chaojing Sun | 97e75b7 | 2014-10-07 17:07:05 -0700 | [diff] [blame] | 545 | } |
| 546 | else |
| 547 | { |
| 548 | /* application allows to do update, if we were delaying one do it now */ |
| 549 | if (p_lcb->conn_update_mask & L2C_BLE_NEW_CONN_PARAM) |
| 550 | { |
| Andre Eisenbach | 01a069a | 2014-12-16 16:18:10 -0800 | [diff] [blame] | 551 | /* if both side 4.1, or we are master device, send HCI command */ |
| 552 | if (p_lcb->link_role == HCI_ROLE_MASTER |
| 553 | #if (defined BLE_LLT_INCLUDED) && (BLE_LLT_INCLUDED == TRUE) |
| Zach Johnson | 30e5806 | 2014-09-26 21:14:34 -0700 | [diff] [blame] | 554 | || (HCI_LE_CONN_PARAM_REQ_SUPPORTED(controller_get_interface()->get_features_ble()->as_array) && |
| Andre Eisenbach | 01a069a | 2014-12-16 16:18:10 -0800 | [diff] [blame] | 555 | HCI_LE_CONN_PARAM_REQ_SUPPORTED(p_acl_cb->peer_le_features)) |
| 556 | #endif |
| 557 | ) |
| 558 | { |
| 559 | btsnd_hcic_ble_upd_ll_conn_params(p_lcb->handle, p_lcb->min_interval, |
| 560 | p_lcb->max_interval, p_lcb->latency, p_lcb->timeout, 0, 0); |
| 561 | p_lcb->conn_update_mask |= L2C_BLE_UPDATE_PENDING; |
| 562 | } |
| 563 | else |
| 564 | { |
| 565 | l2cu_send_peer_ble_par_req (p_lcb, p_lcb->min_interval, p_lcb->max_interval, |
| 566 | p_lcb->latency, p_lcb->timeout); |
| 567 | } |
| Chaojing Sun | 97e75b7 | 2014-10-07 17:07:05 -0700 | [diff] [blame] | 568 | p_lcb->conn_update_mask &= ~L2C_BLE_NEW_CONN_PARAM; |
| Andre Eisenbach | 01a069a | 2014-12-16 16:18:10 -0800 | [diff] [blame] | 569 | p_lcb->conn_update_mask |= L2C_BLE_NOT_DEFAULT_PARAM; |
| Chaojing Sun | 97e75b7 | 2014-10-07 17:07:05 -0700 | [diff] [blame] | 570 | } |
| 571 | } |
| 572 | } |
| 573 | |
| 574 | /******************************************************************************* |
| 575 | ** |
| 576 | ** Function l2cble_process_conn_update_evt |
| 577 | ** |
| 578 | ** Description This function enables the connection update request from remote |
| 579 | ** after a successful connection update response is received. |
| 580 | ** |
| 581 | ** Returns void |
| 582 | ** |
| 583 | *******************************************************************************/ |
| 584 | void l2cble_process_conn_update_evt (UINT16 handle, UINT8 status) |
| 585 | { |
| 586 | tL2C_LCB *p_lcb; |
| 587 | |
| 588 | L2CAP_TRACE_DEBUG("l2cble_process_conn_update_evt"); |
| 589 | |
| 590 | /* See if we have a link control block for the remote device */ |
| 591 | p_lcb = l2cu_find_lcb_by_handle(handle); |
| 592 | if (!p_lcb) |
| 593 | { |
| 594 | L2CAP_TRACE_WARNING("l2cble_process_conn_update_evt: Invalid handle: %d", handle); |
| 595 | return; |
| 596 | } |
| 597 | |
| 598 | p_lcb->conn_update_mask &= ~L2C_BLE_UPDATE_PENDING; |
| 599 | |
| 600 | if (status != HCI_SUCCESS) |
| 601 | { |
| 602 | L2CAP_TRACE_WARNING("l2cble_process_conn_update_evt: Error status: %d", status); |
| 603 | } |
| 604 | |
| 605 | l2cble_start_conn_update(p_lcb); |
| 606 | |
| 607 | L2CAP_TRACE_DEBUG("l2cble_process_conn_update_evt: conn_update_mask=%d", p_lcb->conn_update_mask); |
| 608 | } |
| The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 609 | /******************************************************************************* |
| 610 | ** |
| 611 | ** Function l2cble_process_sig_cmd |
| 612 | ** |
| 613 | ** Description This function is called when a signalling packet is received |
| 614 | ** on the BLE signalling CID |
| 615 | ** |
| 616 | ** Returns void |
| 617 | ** |
| 618 | *******************************************************************************/ |
| 619 | void l2cble_process_sig_cmd (tL2C_LCB *p_lcb, UINT8 *p, UINT16 pkt_len) |
| 620 | { |
| 621 | UINT8 *p_pkt_end; |
| 622 | UINT8 cmd_code, id; |
| Sharvil Nanavati | f1c764f | 2015-02-23 17:31:48 -0800 | [diff] [blame] | 623 | UINT16 cmd_len; |
| The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 624 | UINT16 min_interval, max_interval, latency, timeout; |
| Navin Kochar | 6721232 | 2016-03-09 23:11:53 +0530 | [diff] [blame] | 625 | tL2C_CONN_INFO con_info; |
| 626 | UINT16 lcid = 0, rcid = 0, mtu = 0, mps = 0, initial_credit = 0; |
| 627 | tL2C_CCB *p_ccb = NULL, *temp_p_ccb = NULL; |
| 628 | tL2C_RCB *p_rcb; |
| 629 | UINT16 credit; |
| The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 630 | p_pkt_end = p + pkt_len; |
| 631 | |
| 632 | STREAM_TO_UINT8 (cmd_code, p); |
| 633 | STREAM_TO_UINT8 (id, p); |
| 634 | STREAM_TO_UINT16 (cmd_len, p); |
| 635 | |
| 636 | /* Check command length does not exceed packet length */ |
| 637 | if ((p + cmd_len) > p_pkt_end) |
| 638 | { |
| Sharvil Nanavati | a51c9d9 | 2014-05-04 01:08:21 -0700 | [diff] [blame] | 639 | L2CAP_TRACE_WARNING ("L2CAP - LE - format error, pkt_len: %d cmd_len: %d code: %d", pkt_len, cmd_len, cmd_code); |
| The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 640 | return; |
| 641 | } |
| 642 | |
| 643 | switch (cmd_code) |
| 644 | { |
| 645 | case L2CAP_CMD_REJECT: |
| Sharvil Nanavati | f1c764f | 2015-02-23 17:31:48 -0800 | [diff] [blame] | 646 | p += 2; |
| The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 647 | break; |
| Venkata Jagadeesh | d35bb40 | 2016-05-27 15:36:20 +0530 | [diff] [blame] | 648 | |
| The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 649 | case L2CAP_CMD_ECHO_REQ: |
| Venkata Jagadeesh | d35bb40 | 2016-05-27 15:36:20 +0530 | [diff] [blame] | 650 | case L2CAP_CMD_ECHO_RSP: |
| 651 | case L2CAP_CMD_INFO_RSP: |
| The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 652 | case L2CAP_CMD_INFO_REQ: |
| 653 | l2cu_send_peer_cmd_reject (p_lcb, L2CAP_CMD_REJ_NOT_UNDERSTOOD, id, 0, 0); |
| 654 | break; |
| 655 | |
| 656 | case L2CAP_CMD_BLE_UPDATE_REQ: |
| 657 | STREAM_TO_UINT16 (min_interval, p); /* 0x0006 - 0x0C80 */ |
| 658 | STREAM_TO_UINT16 (max_interval, p); /* 0x0006 - 0x0C80 */ |
| 659 | STREAM_TO_UINT16 (latency, p); /* 0x0000 - 0x03E8 */ |
| 660 | STREAM_TO_UINT16 (timeout, p); /* 0x000A - 0x0C80 */ |
| 661 | /* If we are a master, the slave wants to update the parameters */ |
| 662 | if (p_lcb->link_role == HCI_ROLE_MASTER) |
| 663 | { |
| Andre Eisenbach | 71334dc | 2015-07-10 00:37:45 -0700 | [diff] [blame] | 664 | if (min_interval < BTM_BLE_CONN_INT_MIN_LIMIT) |
| 665 | min_interval = BTM_BLE_CONN_INT_MIN_LIMIT; |
| 666 | |
| Eri Kasamatsu | 3bd286a | 2015-11-09 14:40:02 +0900 | [diff] [blame] | 667 | // While this could result in connection parameters that fall |
| 668 | // outside fo the range requested, this will allow the connection |
| 669 | // to remain established. |
| 670 | // In other words, this is a workaround for certain peripherals. |
| 671 | if (max_interval < BTM_BLE_CONN_INT_MIN_LIMIT) |
| 672 | max_interval = BTM_BLE_CONN_INT_MIN_LIMIT; |
| 673 | |
| Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 674 | if (min_interval < BTM_BLE_CONN_INT_MIN || min_interval > BTM_BLE_CONN_INT_MAX || |
| 675 | max_interval < BTM_BLE_CONN_INT_MIN || max_interval > BTM_BLE_CONN_INT_MAX || |
| 676 | latency > BTM_BLE_CONN_LATENCY_MAX || |
| The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 677 | /*(timeout >= max_interval && latency > (timeout * 10/(max_interval * 1.25) - 1)) ||*/ |
| Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 678 | timeout < BTM_BLE_CONN_SUP_TOUT_MIN || timeout > BTM_BLE_CONN_SUP_TOUT_MAX || |
| The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 679 | max_interval < min_interval) |
| 680 | { |
| Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 681 | l2cu_send_peer_ble_par_rsp (p_lcb, L2CAP_CFG_UNACCEPTABLE_PARAMS, id); |
| The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 682 | } |
| 683 | else |
| 684 | { |
| 685 | |
| 686 | l2cu_send_peer_ble_par_rsp (p_lcb, L2CAP_CFG_OK, id); |
| 687 | |
| Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 688 | p_lcb->min_interval = min_interval; |
| 689 | p_lcb->max_interval = max_interval; |
| 690 | p_lcb->latency = latency; |
| 691 | p_lcb->timeout = timeout; |
| Chaojing Sun | 97e75b7 | 2014-10-07 17:07:05 -0700 | [diff] [blame] | 692 | p_lcb->conn_update_mask |= L2C_BLE_NEW_CONN_PARAM; |
| Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 693 | |
| Chaojing Sun | 97e75b7 | 2014-10-07 17:07:05 -0700 | [diff] [blame] | 694 | l2cble_start_conn_update(p_lcb); |
| The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 695 | } |
| 696 | } |
| 697 | else |
| 698 | l2cu_send_peer_cmd_reject (p_lcb, L2CAP_CMD_REJ_NOT_UNDERSTOOD, id, 0, 0); |
| 699 | break; |
| 700 | |
| 701 | case L2CAP_CMD_BLE_UPDATE_RSP: |
| Sharvil Nanavati | f1c764f | 2015-02-23 17:31:48 -0800 | [diff] [blame] | 702 | p += 2; |
| The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 703 | break; |
| 704 | |
| Navin Kochar | 6721232 | 2016-03-09 23:11:53 +0530 | [diff] [blame] | 705 | case L2CAP_CMD_BLE_CREDIT_BASED_CONN_REQ: |
| 706 | STREAM_TO_UINT16 (con_info.psm, p); |
| 707 | STREAM_TO_UINT16 (rcid, p); |
| 708 | STREAM_TO_UINT16 (mtu, p); |
| 709 | STREAM_TO_UINT16 (mps, p); |
| 710 | STREAM_TO_UINT16 (initial_credit, p); |
| 711 | |
| 712 | L2CAP_TRACE_DEBUG ("Recv L2CAP_CMD_BLE_CREDIT_BASED_CONN_REQ with " |
| 713 | "mtu = %d, " |
| 714 | "mps = %d, " |
| 715 | "initial credit = %d", mtu, mps, initial_credit); |
| 716 | |
| 717 | if ((p_rcb = l2cu_find_ble_rcb_by_psm (con_info.psm)) == NULL) |
| 718 | { |
| 719 | L2CAP_TRACE_WARNING ("L2CAP - rcvd conn req for unknown PSM: 0x%04x", con_info.psm); |
| 720 | l2cu_reject_ble_connection (p_lcb, id, L2CAP_LE_NO_PSM); |
| 721 | break; |
| 722 | } |
| 723 | else |
| 724 | { |
| 725 | if (!p_rcb->api.pL2CA_ConnectInd_Cb) |
| 726 | { |
| 727 | L2CAP_TRACE_WARNING ("L2CAP - rcvd conn req for outgoing-only connection PSM: %d", con_info.psm); |
| 728 | l2cu_reject_ble_connection (p_lcb, id, L2CAP_CONN_NO_PSM); |
| 729 | break; |
| 730 | } |
| 731 | } |
| 732 | |
| 733 | /* Allocate a ccb for this.*/ |
| 734 | if ((p_ccb = l2cu_allocate_ccb (p_lcb, 0)) == NULL) |
| 735 | { |
| 736 | L2CAP_TRACE_ERROR ("L2CAP - unable to allocate CCB"); |
| 737 | l2cu_reject_ble_connection (p_lcb, id, L2CAP_CONN_NO_RESOURCES); |
| 738 | break; |
| 739 | } |
| 740 | |
| 741 | /* validate the parameters */ |
| 742 | if (mtu < L2CAP_LE_MIN_MTU || mps < L2CAP_LE_MIN_MPS || mps > L2CAP_LE_MAX_MPS) |
| 743 | { |
| 744 | L2CAP_TRACE_ERROR ("L2CAP don't like the params"); |
| 745 | l2cu_reject_ble_connection (p_lcb, id, L2CAP_CONN_NO_RESOURCES); |
| 746 | break; |
| 747 | } |
| 748 | |
| 749 | p_ccb->remote_id = id; |
| 750 | p_ccb->p_rcb = p_rcb; |
| 751 | p_ccb->remote_cid = rcid; |
| 752 | |
| 753 | p_ccb->peer_conn_cfg.mtu = mtu; |
| 754 | p_ccb->peer_conn_cfg.mps = mps; |
| 755 | p_ccb->peer_conn_cfg.credits = initial_credit; |
| 756 | |
| 757 | p_ccb->tx_mps = mps; |
| 758 | p_ccb->ble_sdu = NULL; |
| 759 | p_ccb->ble_sdu_length = 0; |
| 760 | p_ccb->is_first_seg = TRUE; |
| 761 | p_ccb->peer_cfg.fcr.mode = L2CAP_FCR_LE_COC_MODE; |
| 762 | |
| 763 | l2c_csm_execute(p_ccb, L2CEVT_L2CAP_CONNECT_REQ, &con_info); |
| 764 | break; |
| 765 | |
| 766 | case L2CAP_CMD_BLE_CREDIT_BASED_CONN_RES: |
| 767 | L2CAP_TRACE_DEBUG ("Recv L2CAP_CMD_BLE_CREDIT_BASED_CONN_RES"); |
| 768 | /* For all channels, see whose identifier matches this id */ |
| 769 | for (temp_p_ccb = p_lcb->ccb_queue.p_first_ccb; temp_p_ccb; temp_p_ccb = temp_p_ccb->p_next_ccb) |
| 770 | { |
| 771 | if (temp_p_ccb->local_id == id) |
| 772 | { |
| 773 | p_ccb = temp_p_ccb; |
| 774 | break; |
| 775 | } |
| 776 | } |
| 777 | if (p_ccb) |
| 778 | { |
| 779 | L2CAP_TRACE_DEBUG ("I remember the connection req"); |
| 780 | STREAM_TO_UINT16 (p_ccb->remote_cid, p); |
| 781 | STREAM_TO_UINT16 (p_ccb->peer_conn_cfg.mtu, p); |
| 782 | STREAM_TO_UINT16 (p_ccb->peer_conn_cfg.mps, p); |
| 783 | STREAM_TO_UINT16 (p_ccb->peer_conn_cfg.credits, p); |
| 784 | STREAM_TO_UINT16 (con_info.l2cap_result, p); |
| 785 | con_info.remote_cid = p_ccb->remote_cid; |
| 786 | |
| 787 | L2CAP_TRACE_DEBUG ("remote_cid = %d, " |
| 788 | "mtu = %d, " |
| 789 | "mps = %d, " |
| 790 | "initial_credit = %d, " |
| 791 | "con_info.l2cap_result = %d", |
| 792 | p_ccb->remote_cid, p_ccb->peer_conn_cfg.mtu, p_ccb->peer_conn_cfg.mps, |
| 793 | p_ccb->peer_conn_cfg.credits, con_info.l2cap_result); |
| 794 | |
| 795 | /* validate the parameters */ |
| 796 | if (p_ccb->peer_conn_cfg.mtu < L2CAP_LE_MIN_MTU || |
| 797 | p_ccb->peer_conn_cfg.mps < L2CAP_LE_MIN_MPS || |
| 798 | p_ccb->peer_conn_cfg.mps > L2CAP_LE_MAX_MPS) |
| 799 | { |
| 800 | L2CAP_TRACE_ERROR ("L2CAP don't like the params"); |
| 801 | con_info.l2cap_result = L2CAP_LE_NO_RESOURCES; |
| 802 | l2c_csm_execute(p_ccb, L2CEVT_L2CAP_CONNECT_RSP_NEG, &con_info); |
| 803 | break; |
| 804 | } |
| 805 | |
| 806 | p_ccb->tx_mps = p_ccb->peer_conn_cfg.mps; |
| 807 | p_ccb->ble_sdu = NULL; |
| 808 | p_ccb->ble_sdu_length = 0; |
| 809 | p_ccb->is_first_seg = TRUE; |
| 810 | p_ccb->peer_cfg.fcr.mode = L2CAP_FCR_LE_COC_MODE; |
| 811 | |
| 812 | if (con_info.l2cap_result == L2CAP_LE_CONN_OK) |
| 813 | l2c_csm_execute(p_ccb, L2CEVT_L2CAP_CONNECT_RSP, &con_info); |
| 814 | else |
| 815 | l2c_csm_execute(p_ccb, L2CEVT_L2CAP_CONNECT_RSP_NEG, &con_info); |
| 816 | } |
| 817 | else |
| 818 | { |
| 819 | L2CAP_TRACE_DEBUG ("I DO NOT remember the connection req"); |
| 820 | con_info.l2cap_result = L2CAP_LE_INVALID_SOURCE_CID; |
| 821 | l2c_csm_execute(p_ccb, L2CEVT_L2CAP_CONNECT_RSP_NEG, &con_info); |
| 822 | } |
| 823 | break; |
| 824 | |
| 825 | case L2CAP_CMD_BLE_FLOW_CTRL_CREDIT: |
| 826 | STREAM_TO_UINT16(lcid, p); |
| 827 | if((p_ccb = l2cu_find_ccb_by_remote_cid(p_lcb, lcid)) == NULL) |
| 828 | { |
| 829 | L2CAP_TRACE_DEBUG ("%s Credit received for unknown channel id %d", __func__, lcid); |
| 830 | break; |
| 831 | } |
| 832 | |
| 833 | STREAM_TO_UINT16(credit ,p); |
| 834 | l2c_csm_execute(p_ccb, L2CEVT_L2CAP_RECV_FLOW_CONTROL_CREDIT, &credit); |
| 835 | L2CAP_TRACE_DEBUG ("%s Credit received", __func__); |
| 836 | break; |
| 837 | |
| 838 | case L2CAP_CMD_DISC_REQ: |
| 839 | STREAM_TO_UINT16 (lcid, p); |
| 840 | STREAM_TO_UINT16 (rcid, p); |
| 841 | |
| 842 | if ((p_ccb = l2cu_find_ccb_by_cid (p_lcb, lcid)) != NULL) |
| 843 | { |
| 844 | if (p_ccb->remote_cid == rcid) |
| 845 | { |
| 846 | p_ccb->remote_id = id; |
| 847 | l2c_csm_execute (p_ccb, L2CEVT_L2CAP_DISCONNECT_REQ, NULL); |
| 848 | } |
| 849 | } |
| 850 | else |
| 851 | l2cu_send_peer_disc_rsp (p_lcb, id, lcid, rcid); |
| 852 | |
| 853 | break; |
| 854 | |
| 855 | case L2CAP_CMD_DISC_RSP: |
| 856 | STREAM_TO_UINT16 (rcid, p); |
| 857 | STREAM_TO_UINT16 (lcid, p); |
| 858 | |
| 859 | if ((p_ccb = l2cu_find_ccb_by_cid (p_lcb, lcid)) != NULL) |
| 860 | { |
| 861 | if ((p_ccb->remote_cid == rcid) && (p_ccb->local_id == id)) |
| 862 | l2c_csm_execute (p_ccb, L2CEVT_L2CAP_DISCONNECT_RSP, NULL); |
| 863 | } |
| 864 | break; |
| 865 | |
| The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 866 | default: |
| Sharvil Nanavati | a51c9d9 | 2014-05-04 01:08:21 -0700 | [diff] [blame] | 867 | L2CAP_TRACE_WARNING ("L2CAP - LE - unknown cmd code: %d", cmd_code); |
| The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 868 | l2cu_send_peer_cmd_reject (p_lcb, L2CAP_CMD_REJ_NOT_UNDERSTOOD, id, 0, 0); |
| Navin Kochar | 6721232 | 2016-03-09 23:11:53 +0530 | [diff] [blame] | 869 | break; |
| The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 870 | } |
| 871 | } |
| 872 | |
| The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 873 | /******************************************************************************* |
| 874 | ** |
| Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 875 | ** Function l2cble_init_direct_conn |
| 876 | ** |
| 877 | ** Description This function is to initate a direct connection |
| 878 | ** |
| 879 | ** Returns TRUE connection initiated, FALSE otherwise. |
| 880 | ** |
| 881 | *******************************************************************************/ |
| 882 | BOOLEAN l2cble_init_direct_conn (tL2C_LCB *p_lcb) |
| 883 | { |
| Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 884 | tBTM_SEC_DEV_REC *p_dev_rec = btm_find_or_alloc_dev (p_lcb->remote_bd_addr); |
| 885 | tBTM_BLE_CB *p_cb = &btm_cb.ble_ctr_cb; |
| 886 | UINT16 scan_int; |
| 887 | UINT16 scan_win; |
| 888 | BD_ADDR peer_addr; |
| 889 | UINT8 peer_addr_type = BLE_ADDR_PUBLIC; |
| 890 | UINT8 own_addr_type = BLE_ADDR_PUBLIC; |
| Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 891 | |
| 892 | /* There can be only one BLE connection request outstanding at a time */ |
| 893 | if (p_dev_rec == NULL) |
| 894 | { |
| Sharvil Nanavati | a51c9d9 | 2014-05-04 01:08:21 -0700 | [diff] [blame] | 895 | L2CAP_TRACE_WARNING ("unknown device, can not initate connection"); |
| Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 896 | return(FALSE); |
| 897 | } |
| 898 | |
| Satya Calloji | 70b9598 | 2015-04-23 23:39:49 -0700 | [diff] [blame] | 899 | scan_int = (p_cb->scan_int == BTM_BLE_SCAN_PARAM_UNDEF) ? BTM_BLE_SCAN_FAST_INT : p_cb->scan_int; |
| 900 | scan_win = (p_cb->scan_win == BTM_BLE_SCAN_PARAM_UNDEF) ? BTM_BLE_SCAN_FAST_WIN : p_cb->scan_win; |
| Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 901 | |
| Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 902 | peer_addr_type = p_lcb->ble_addr_type; |
| 903 | memcpy(peer_addr, p_lcb->remote_bd_addr, BD_ADDR_LEN); |
| Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 904 | |
| Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 905 | #if ( (defined BLE_PRIVACY_SPT) && (BLE_PRIVACY_SPT == TRUE)) |
| 906 | own_addr_type = btm_cb.ble_ctr_cb.privacy_mode ? BLE_ADDR_RANDOM : BLE_ADDR_PUBLIC; |
| 907 | if (p_dev_rec->ble.in_controller_list & BTM_RESOLVING_LIST_BIT) |
| Zhihai Xu | 8b35b3f | 2014-03-11 15:01:45 -0700 | [diff] [blame] | 908 | { |
| Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 909 | if (btm_cb.ble_ctr_cb.privacy_mode >= BTM_PRIVACY_1_2) |
| 910 | own_addr_type |= BLE_ADDR_TYPE_ID_BIT; |
| 911 | |
| Satya Calloji | 70b9598 | 2015-04-23 23:39:49 -0700 | [diff] [blame] | 912 | btm_ble_enable_resolving_list(BTM_BLE_RL_INIT); |
| Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 913 | btm_random_pseudo_to_identity_addr(peer_addr, &peer_addr_type); |
| Sharvil Nanavati | 0fa8cd4 | 2015-08-10 13:00:06 -0700 | [diff] [blame] | 914 | } else { |
| Satya Calloji | 70b9598 | 2015-04-23 23:39:49 -0700 | [diff] [blame] | 915 | btm_ble_disable_resolving_list(BTM_BLE_RL_INIT, TRUE); |
| Sharvil Nanavati | 0fa8cd4 | 2015-08-10 13:00:06 -0700 | [diff] [blame] | 916 | |
| 917 | // If we have a current RPA, use that instead. |
| 918 | if (!bdaddr_is_empty((const bt_bdaddr_t *)p_dev_rec->ble.cur_rand_addr)) { |
| 919 | memcpy(peer_addr, p_dev_rec->ble.cur_rand_addr, BD_ADDR_LEN); |
| 920 | } |
| 921 | } |
| Zhihai Xu | 8b35b3f | 2014-03-11 15:01:45 -0700 | [diff] [blame] | 922 | #endif |
| 923 | |
| Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 924 | if (!btm_ble_topology_check(BTM_BLE_STATE_INIT)) |
| 925 | { |
| 926 | l2cu_release_lcb (p_lcb); |
| Sharvil Nanavati | a51c9d9 | 2014-05-04 01:08:21 -0700 | [diff] [blame] | 927 | L2CAP_TRACE_ERROR("initate direct connection fail, topology limitation"); |
| Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 928 | return FALSE; |
| 929 | } |
| Wei Wang | ed534e3 | 2014-05-20 06:30:13 +0000 | [diff] [blame] | 930 | |
| Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 931 | if (!btsnd_hcic_ble_create_ll_conn (scan_int,/* UINT16 scan_int */ |
| 932 | scan_win, /* UINT16 scan_win */ |
| 933 | FALSE, /* UINT8 white_list */ |
| Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 934 | peer_addr_type, /* UINT8 addr_type_peer */ |
| 935 | peer_addr, /* BD_ADDR bda_peer */ |
| Andre Eisenbach | 6975b4d | 2013-08-05 16:55:38 -0700 | [diff] [blame] | 936 | own_addr_type, /* UINT8 addr_type_own */ |
| Zhihai Xu | 3dc5945 | 2013-10-25 16:47:49 -0700 | [diff] [blame] | 937 | (UINT16) ((p_dev_rec->conn_params.min_conn_int != BTM_BLE_CONN_PARAM_UNDEF) ? |
| Andre Eisenbach | 01a069a | 2014-12-16 16:18:10 -0800 | [diff] [blame] | 938 | p_dev_rec->conn_params.min_conn_int : BTM_BLE_CONN_INT_MIN_DEF), /* UINT16 conn_int_min */ |
| Zhihai Xu | 3dc5945 | 2013-10-25 16:47:49 -0700 | [diff] [blame] | 939 | (UINT16) ((p_dev_rec->conn_params.max_conn_int != BTM_BLE_CONN_PARAM_UNDEF) ? |
| Andre Eisenbach | 01a069a | 2014-12-16 16:18:10 -0800 | [diff] [blame] | 940 | p_dev_rec->conn_params.max_conn_int : BTM_BLE_CONN_INT_MAX_DEF), /* UINT16 conn_int_max */ |
| Zhihai Xu | 3dc5945 | 2013-10-25 16:47:49 -0700 | [diff] [blame] | 941 | (UINT16) ((p_dev_rec->conn_params.slave_latency != BTM_BLE_CONN_PARAM_UNDEF) ? |
| Steve Paik | 9c07b33 | 2014-06-19 15:50:46 -0700 | [diff] [blame] | 942 | p_dev_rec->conn_params.slave_latency : BTM_BLE_CONN_SLAVE_LATENCY_DEF), /* UINT16 conn_latency */ |
| Zhihai Xu | 3dc5945 | 2013-10-25 16:47:49 -0700 | [diff] [blame] | 943 | (UINT16) ((p_dev_rec->conn_params.supervision_tout != BTM_BLE_CONN_PARAM_UNDEF) ? |
| Steve Paik | 9c07b33 | 2014-06-19 15:50:46 -0700 | [diff] [blame] | 944 | p_dev_rec->conn_params.supervision_tout : BTM_BLE_CONN_TIMEOUT_DEF), /* conn_timeout */ |
| Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 945 | 0, /* UINT16 min_len */ |
| 946 | 0)) /* UINT16 max_len */ |
| 947 | { |
| 948 | l2cu_release_lcb (p_lcb); |
| Sharvil Nanavati | a51c9d9 | 2014-05-04 01:08:21 -0700 | [diff] [blame] | 949 | L2CAP_TRACE_ERROR("initate direct connection fail, no resources"); |
| Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 950 | return (FALSE); |
| 951 | } |
| 952 | else |
| 953 | { |
| 954 | p_lcb->link_state = LST_CONNECTING; |
| Andre Eisenbach | 6975b4d | 2013-08-05 16:55:38 -0700 | [diff] [blame] | 955 | l2cb.is_ble_connecting = TRUE; |
| Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 956 | memcpy (l2cb.ble_connecting_bda, p_lcb->remote_bd_addr, BD_ADDR_LEN); |
| Pavlin Radoslavov | 78bcff7 | 2015-12-04 17:36:34 -0800 | [diff] [blame] | 957 | alarm_set_on_queue(p_lcb->l2c_lcb_timer, |
| 958 | L2CAP_BLE_LINK_CONNECT_TIMEOUT_MS, |
| 959 | l2c_lcb_timer_timeout, p_lcb, |
| 960 | btu_general_alarm_queue); |
| Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 961 | btm_ble_set_conn_st (BLE_DIR_CONN); |
| 962 | |
| 963 | return (TRUE); |
| 964 | } |
| 965 | } |
| 966 | |
| 967 | /******************************************************************************* |
| 968 | ** |
| The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 969 | ** Function l2cble_create_conn |
| 970 | ** |
| 971 | ** Description This function initiates an acl connection via HCI |
| 972 | ** |
| 973 | ** Returns TRUE if successful, FALSE if connection not started. |
| 974 | ** |
| 975 | *******************************************************************************/ |
| 976 | BOOLEAN l2cble_create_conn (tL2C_LCB *p_lcb) |
| 977 | { |
| Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 978 | tBTM_BLE_CONN_ST conn_st = btm_ble_get_conn_st(); |
| 979 | BOOLEAN rt = FALSE; |
| The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 980 | |
| 981 | /* There can be only one BLE connection request outstanding at a time */ |
| Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 982 | if (conn_st == BLE_CONN_IDLE) |
| The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 983 | { |
| Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 984 | rt = l2cble_init_direct_conn(p_lcb); |
| The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 985 | } |
| 986 | else |
| Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 987 | { |
| Sharvil Nanavati | a51c9d9 | 2014-05-04 01:08:21 -0700 | [diff] [blame] | 988 | L2CAP_TRACE_WARNING ("L2CAP - LE - cannot start new connection at conn st: %d", conn_st); |
| The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 989 | |
| Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 990 | btm_ble_enqueue_direct_conn_req(p_lcb); |
| 991 | |
| 992 | if (conn_st == BLE_BG_CONN) |
| 993 | btm_ble_suspend_bg_conn(); |
| 994 | |
| 995 | rt = TRUE; |
| 996 | } |
| 997 | return rt; |
| The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 998 | } |
| 999 | |
| 1000 | /******************************************************************************* |
| 1001 | ** |
| 1002 | ** Function l2c_link_processs_ble_num_bufs |
| 1003 | ** |
| 1004 | ** Description This function is called when a "controller buffer size" |
| 1005 | ** event is first received from the controller. It updates |
| 1006 | ** the L2CAP values. |
| 1007 | ** |
| 1008 | ** Returns void |
| 1009 | ** |
| 1010 | *******************************************************************************/ |
| 1011 | void l2c_link_processs_ble_num_bufs (UINT16 num_lm_ble_bufs) |
| 1012 | { |
| Andre Eisenbach | 0082e02 | 2013-04-03 13:56:05 -0700 | [diff] [blame] | 1013 | if (num_lm_ble_bufs == 0) |
| Andre Eisenbach | 12c3f49 | 2013-04-24 16:02:04 -0700 | [diff] [blame] | 1014 | { |
| 1015 | num_lm_ble_bufs = L2C_DEF_NUM_BLE_BUF_SHARED; |
| 1016 | l2cb.num_lm_acl_bufs -= L2C_DEF_NUM_BLE_BUF_SHARED; |
| 1017 | } |
| 1018 | |
| The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1019 | l2cb.num_lm_ble_bufs = l2cb.controller_le_xmit_window = num_lm_ble_bufs; |
| 1020 | } |
| 1021 | |
| Mudumba Ananth | 92ac2d8 | 2014-07-11 00:05:54 -0700 | [diff] [blame] | 1022 | /******************************************************************************* |
| 1023 | ** |
| 1024 | ** Function l2c_ble_link_adjust_allocation |
| 1025 | ** |
| 1026 | ** Description This function is called when a link is created or removed |
| 1027 | ** to calculate the amount of packets each link may send to |
| 1028 | ** the HCI without an ack coming back. |
| 1029 | ** |
| 1030 | ** Currently, this is a simple allocation, dividing the |
| 1031 | ** number of Controller Packets by the number of links. In |
| 1032 | ** the future, QOS configuration should be examined. |
| 1033 | ** |
| 1034 | ** Returns void |
| 1035 | ** |
| 1036 | *******************************************************************************/ |
| 1037 | void l2c_ble_link_adjust_allocation (void) |
| 1038 | { |
| 1039 | UINT16 qq, yy, qq_remainder; |
| 1040 | tL2C_LCB *p_lcb; |
| 1041 | UINT16 hi_quota, low_quota; |
| 1042 | UINT16 num_lowpri_links = 0; |
| 1043 | UINT16 num_hipri_links = 0; |
| 1044 | UINT16 controller_xmit_quota = l2cb.num_lm_ble_bufs; |
| 1045 | UINT16 high_pri_link_quota = L2CAP_HIGH_PRI_MIN_XMIT_QUOTA_A; |
| 1046 | |
| 1047 | /* If no links active, reset buffer quotas and controller buffers */ |
| 1048 | if (l2cb.num_ble_links_active == 0) |
| 1049 | { |
| 1050 | l2cb.controller_le_xmit_window = l2cb.num_lm_ble_bufs; |
| 1051 | l2cb.ble_round_robin_quota = l2cb.ble_round_robin_unacked = 0; |
| 1052 | return; |
| 1053 | } |
| 1054 | |
| 1055 | /* First, count the links */ |
| 1056 | for (yy = 0, p_lcb = &l2cb.lcb_pool[0]; yy < MAX_L2CAP_LINKS; yy++, p_lcb++) |
| 1057 | { |
| 1058 | if (p_lcb->in_use && p_lcb->transport == BT_TRANSPORT_LE) |
| 1059 | { |
| 1060 | if (p_lcb->acl_priority == L2CAP_PRIORITY_HIGH) |
| 1061 | num_hipri_links++; |
| 1062 | else |
| 1063 | num_lowpri_links++; |
| 1064 | } |
| 1065 | } |
| 1066 | |
| 1067 | /* now adjust high priority link quota */ |
| 1068 | low_quota = num_lowpri_links ? 1 : 0; |
| 1069 | while ( (num_hipri_links * high_pri_link_quota + low_quota) > controller_xmit_quota ) |
| 1070 | high_pri_link_quota--; |
| 1071 | |
| 1072 | |
| 1073 | /* Work out the xmit quota and buffer quota high and low priorities */ |
| 1074 | hi_quota = num_hipri_links * high_pri_link_quota; |
| 1075 | low_quota = (hi_quota < controller_xmit_quota) ? controller_xmit_quota - hi_quota : 1; |
| 1076 | |
| 1077 | /* Work out and save the HCI xmit quota for each low priority link */ |
| 1078 | |
| 1079 | /* If each low priority link cannot have at least one buffer */ |
| 1080 | if (num_lowpri_links > low_quota) |
| 1081 | { |
| 1082 | l2cb.ble_round_robin_quota = low_quota; |
| Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 1083 | qq = qq_remainder = 0; |
| Mudumba Ananth | 92ac2d8 | 2014-07-11 00:05:54 -0700 | [diff] [blame] | 1084 | } |
| 1085 | /* If each low priority link can have at least one buffer */ |
| 1086 | else if (num_lowpri_links > 0) |
| 1087 | { |
| 1088 | l2cb.ble_round_robin_quota = 0; |
| 1089 | l2cb.ble_round_robin_unacked = 0; |
| 1090 | qq = low_quota / num_lowpri_links; |
| 1091 | qq_remainder = low_quota % num_lowpri_links; |
| 1092 | } |
| 1093 | /* If no low priority link */ |
| 1094 | else |
| 1095 | { |
| 1096 | l2cb.ble_round_robin_quota = 0; |
| 1097 | l2cb.ble_round_robin_unacked = 0; |
| Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 1098 | qq = qq_remainder = 0; |
| Mudumba Ananth | 92ac2d8 | 2014-07-11 00:05:54 -0700 | [diff] [blame] | 1099 | } |
| 1100 | L2CAP_TRACE_EVENT ("l2c_ble_link_adjust_allocation num_hipri: %u num_lowpri: %u low_quota: %u round_robin_quota: %u qq: %u", |
| 1101 | num_hipri_links, num_lowpri_links, low_quota, |
| 1102 | l2cb.ble_round_robin_quota, qq); |
| 1103 | |
| 1104 | /* Now, assign the quotas to each link */ |
| 1105 | for (yy = 0, p_lcb = &l2cb.lcb_pool[0]; yy < MAX_L2CAP_LINKS; yy++, p_lcb++) |
| 1106 | { |
| 1107 | if (p_lcb->in_use && p_lcb->transport == BT_TRANSPORT_LE) |
| 1108 | { |
| 1109 | if (p_lcb->acl_priority == L2CAP_PRIORITY_HIGH) |
| 1110 | { |
| 1111 | p_lcb->link_xmit_quota = high_pri_link_quota; |
| 1112 | } |
| 1113 | else |
| 1114 | { |
| 1115 | /* Safety check in case we switched to round-robin with something outstanding */ |
| 1116 | /* if sent_not_acked is added into round_robin_unacked then don't add it again */ |
| 1117 | /* l2cap keeps updating sent_not_acked for exiting from round robin */ |
| 1118 | if (( p_lcb->link_xmit_quota > 0 )&&( qq == 0 )) |
| 1119 | l2cb.ble_round_robin_unacked += p_lcb->sent_not_acked; |
| 1120 | |
| 1121 | p_lcb->link_xmit_quota = qq; |
| 1122 | if (qq_remainder > 0) |
| 1123 | { |
| 1124 | p_lcb->link_xmit_quota++; |
| 1125 | qq_remainder--; |
| 1126 | } |
| 1127 | } |
| 1128 | |
| 1129 | L2CAP_TRACE_EVENT("l2c_ble_link_adjust_allocation LCB %d Priority: %d XmitQuota: %d", |
| 1130 | yy, p_lcb->acl_priority, p_lcb->link_xmit_quota); |
| 1131 | |
| 1132 | L2CAP_TRACE_EVENT(" SentNotAcked: %d RRUnacked: %d", |
| 1133 | p_lcb->sent_not_acked, l2cb.round_robin_unacked); |
| 1134 | |
| 1135 | /* There is a special case where we have readjusted the link quotas and */ |
| 1136 | /* this link may have sent anything but some other link sent packets so */ |
| 1137 | /* so we may need a timer to kick off this link's transmissions. */ |
| 1138 | if ( (p_lcb->link_state == LST_CONNECTED) |
| Chris Manton | 6c303ae | 2014-08-04 22:03:39 -0700 | [diff] [blame] | 1139 | && (!list_is_empty(p_lcb->link_xmit_data_q)) |
| Pavlin Radoslavov | 78bcff7 | 2015-12-04 17:36:34 -0800 | [diff] [blame] | 1140 | && (p_lcb->sent_not_acked < p_lcb->link_xmit_quota) ) { |
| 1141 | alarm_set_on_queue(p_lcb->l2c_lcb_timer, |
| 1142 | L2CAP_LINK_FLOW_CONTROL_TIMEOUT_MS, |
| 1143 | l2c_lcb_timer_timeout, p_lcb, |
| 1144 | btu_general_alarm_queue); |
| 1145 | } |
| Mudumba Ananth | 92ac2d8 | 2014-07-11 00:05:54 -0700 | [diff] [blame] | 1146 | } |
| 1147 | } |
| 1148 | } |
| 1149 | |
| Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1150 | #if (defined BLE_LLT_INCLUDED) && (BLE_LLT_INCLUDED == TRUE) |
| 1151 | /******************************************************************************* |
| 1152 | ** |
| 1153 | ** Function l2cble_process_rc_param_request_evt |
| 1154 | ** |
| 1155 | ** Description process LE Remote Connection Parameter Request Event. |
| 1156 | ** |
| 1157 | ** Returns void |
| 1158 | ** |
| 1159 | *******************************************************************************/ |
| 1160 | void l2cble_process_rc_param_request_evt(UINT16 handle, UINT16 int_min, UINT16 int_max, |
| 1161 | UINT16 latency, UINT16 timeout) |
| 1162 | { |
| 1163 | tL2C_LCB *p_lcb = l2cu_find_lcb_by_handle (handle); |
| 1164 | |
| 1165 | if (p_lcb != NULL) |
| 1166 | { |
| 1167 | p_lcb->min_interval = int_min; |
| 1168 | p_lcb->max_interval = int_max; |
| 1169 | p_lcb->latency = latency; |
| 1170 | p_lcb->timeout = timeout; |
| Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1171 | |
| Chaojing Sun | 97e75b7 | 2014-10-07 17:07:05 -0700 | [diff] [blame] | 1172 | /* if update is enabled, always accept connection parameter update */ |
| 1173 | if ((p_lcb->conn_update_mask & L2C_BLE_CONN_UPDATE_DISABLE) == 0) |
| Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1174 | { |
| 1175 | btsnd_hcic_ble_rc_param_req_reply(handle, int_min, int_max, latency, timeout, 0, 0); |
| 1176 | } |
| 1177 | else |
| 1178 | { |
| Sharvil Nanavati | a51c9d9 | 2014-05-04 01:08:21 -0700 | [diff] [blame] | 1179 | L2CAP_TRACE_EVENT ("L2CAP - LE - update currently disabled"); |
| Andre Eisenbach | 01a069a | 2014-12-16 16:18:10 -0800 | [diff] [blame] | 1180 | p_lcb->conn_update_mask |= L2C_BLE_NEW_CONN_PARAM; |
| Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1181 | btsnd_hcic_ble_rc_param_req_neg_reply (handle,HCI_ERR_UNACCEPT_CONN_INTERVAL); |
| 1182 | } |
| 1183 | |
| 1184 | } |
| 1185 | else |
| 1186 | { |
| Sharvil Nanavati | a51c9d9 | 2014-05-04 01:08:21 -0700 | [diff] [blame] | 1187 | L2CAP_TRACE_WARNING("No link to update connection parameter") |
| Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1188 | } |
| 1189 | } |
| 1190 | #endif |
| 1191 | |
| Priti Aghera | 636d671 | 2014-12-18 13:55:48 -0800 | [diff] [blame] | 1192 | /******************************************************************************* |
| 1193 | ** |
| 1194 | ** Function l2cble_update_data_length |
| 1195 | ** |
| 1196 | ** Description This function update link tx data length if applicable |
| 1197 | ** |
| 1198 | ** Returns void |
| 1199 | ** |
| 1200 | *******************************************************************************/ |
| 1201 | void l2cble_update_data_length(tL2C_LCB *p_lcb) |
| 1202 | { |
| 1203 | UINT16 tx_mtu = 0; |
| 1204 | UINT16 i = 0; |
| 1205 | |
| 1206 | L2CAP_TRACE_DEBUG("%s", __FUNCTION__); |
| 1207 | |
| 1208 | /* See if we have a link control block for the connection */ |
| 1209 | if (p_lcb == NULL) |
| 1210 | return; |
| 1211 | |
| 1212 | for (i = 0; i < L2CAP_NUM_FIXED_CHNLS; i++) |
| 1213 | { |
| 1214 | if (i + L2CAP_FIRST_FIXED_CHNL != L2CAP_BLE_SIGNALLING_CID) |
| 1215 | { |
| 1216 | if ((p_lcb->p_fixed_ccbs[i] != NULL) && |
| 1217 | (tx_mtu < (p_lcb->p_fixed_ccbs[i]->tx_data_len + L2CAP_PKT_OVERHEAD))) |
| 1218 | tx_mtu = p_lcb->p_fixed_ccbs[i]->tx_data_len + L2CAP_PKT_OVERHEAD; |
| 1219 | } |
| 1220 | } |
| 1221 | |
| 1222 | if (tx_mtu > BTM_BLE_DATA_SIZE_MAX) |
| 1223 | tx_mtu = BTM_BLE_DATA_SIZE_MAX; |
| 1224 | |
| 1225 | /* update TX data length if changed */ |
| 1226 | if (p_lcb->tx_data_len != tx_mtu) |
| 1227 | BTM_SetBleDataLength(p_lcb->remote_bd_addr, tx_mtu); |
| 1228 | |
| 1229 | } |
| 1230 | |
| 1231 | /******************************************************************************* |
| 1232 | ** |
| 1233 | ** Function l2cble_process_data_length_change_evt |
| 1234 | ** |
| 1235 | ** Description This function process the data length change event |
| 1236 | ** |
| 1237 | ** Returns void |
| 1238 | ** |
| 1239 | *******************************************************************************/ |
| 1240 | void l2cble_process_data_length_change_event(UINT16 handle, UINT16 tx_data_len, UINT16 rx_data_len) |
| 1241 | { |
| 1242 | tL2C_LCB *p_lcb = l2cu_find_lcb_by_handle(handle); |
| 1243 | |
| 1244 | L2CAP_TRACE_DEBUG("%s TX data len = %d", __FUNCTION__, tx_data_len); |
| 1245 | if (p_lcb == NULL) |
| 1246 | return; |
| 1247 | |
| 1248 | if (tx_data_len > 0) |
| 1249 | p_lcb->tx_data_len = tx_data_len; |
| 1250 | |
| 1251 | /* ignore rx_data len for now */ |
| 1252 | } |
| 1253 | |
| 1254 | /******************************************************************************* |
| 1255 | ** |
| 1256 | ** Function l2cble_set_fixed_channel_tx_data_length |
| 1257 | ** |
| 1258 | ** Description This function update max fixed channel tx data length if applicable |
| 1259 | ** |
| 1260 | ** Returns void |
| 1261 | ** |
| 1262 | *******************************************************************************/ |
| 1263 | void l2cble_set_fixed_channel_tx_data_length(BD_ADDR remote_bda, UINT16 fix_cid, UINT16 tx_mtu) |
| 1264 | { |
| 1265 | tL2C_LCB *p_lcb = l2cu_find_lcb_by_bd_addr(remote_bda, BT_TRANSPORT_LE); |
| 1266 | UINT16 cid = fix_cid - L2CAP_FIRST_FIXED_CHNL; |
| 1267 | |
| 1268 | L2CAP_TRACE_DEBUG("%s TX MTU = %d", __FUNCTION__, tx_mtu); |
| 1269 | |
| 1270 | if (!controller_get_interface()->supports_ble_packet_extension()) |
| 1271 | { |
| 1272 | L2CAP_TRACE_WARNING("%s, request not supported", __FUNCTION__); |
| 1273 | return; |
| 1274 | } |
| 1275 | |
| 1276 | /* See if we have a link control block for the connection */ |
| 1277 | if (p_lcb == NULL) |
| 1278 | return; |
| 1279 | |
| 1280 | if (p_lcb->p_fixed_ccbs[cid] != NULL) |
| 1281 | { |
| 1282 | if (tx_mtu > BTM_BLE_DATA_SIZE_MAX) |
| 1283 | tx_mtu = BTM_BLE_DATA_SIZE_MAX; |
| 1284 | |
| 1285 | p_lcb->p_fixed_ccbs[cid]->tx_data_len = tx_mtu; |
| 1286 | } |
| 1287 | |
| 1288 | l2cble_update_data_length(p_lcb); |
| 1289 | } |
| Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1290 | |
| Navin Kochar | 6721232 | 2016-03-09 23:11:53 +0530 | [diff] [blame] | 1291 | /******************************************************************************* |
| 1292 | ** |
| 1293 | ** Function l2cble_credit_based_conn_req |
| 1294 | ** |
| 1295 | ** Description This function sends LE Credit Based Connection Request for |
| 1296 | ** LE connection oriented channels. |
| 1297 | ** |
| 1298 | ** Returns void |
| 1299 | ** |
| 1300 | *******************************************************************************/ |
| 1301 | void l2cble_credit_based_conn_req (tL2C_CCB *p_ccb) |
| 1302 | { |
| 1303 | if (!p_ccb) |
| 1304 | return; |
| 1305 | |
| 1306 | if (p_ccb->p_lcb && p_ccb->p_lcb->transport != BT_TRANSPORT_LE) |
| 1307 | { |
| 1308 | L2CAP_TRACE_WARNING ("LE link doesn't exist"); |
| 1309 | return; |
| 1310 | } |
| 1311 | |
| 1312 | l2cu_send_peer_ble_credit_based_conn_req (p_ccb); |
| 1313 | return; |
| 1314 | } |
| 1315 | |
| 1316 | /******************************************************************************* |
| 1317 | ** |
| 1318 | ** Function l2cble_credit_based_conn_res |
| 1319 | ** |
| 1320 | ** Description This function sends LE Credit Based Connection Response for |
| 1321 | ** LE connection oriented channels. |
| 1322 | ** |
| 1323 | ** Returns void |
| 1324 | ** |
| 1325 | *******************************************************************************/ |
| 1326 | void l2cble_credit_based_conn_res (tL2C_CCB *p_ccb, UINT16 result) |
| 1327 | { |
| 1328 | if (!p_ccb) |
| 1329 | return; |
| 1330 | |
| 1331 | if (p_ccb->p_lcb && p_ccb->p_lcb->transport != BT_TRANSPORT_LE) |
| 1332 | { |
| 1333 | L2CAP_TRACE_WARNING ("LE link doesn't exist"); |
| 1334 | return; |
| 1335 | } |
| 1336 | |
| 1337 | l2cu_send_peer_ble_credit_based_conn_res (p_ccb, result); |
| 1338 | return; |
| 1339 | } |
| 1340 | |
| 1341 | /******************************************************************************* |
| 1342 | ** |
| 1343 | ** Function l2cble_send_flow_control_credit |
| 1344 | ** |
| 1345 | ** Description This function sends flow control credits for |
| 1346 | ** LE connection oriented channels. |
| 1347 | ** |
| 1348 | ** Returns void |
| 1349 | ** |
| 1350 | *******************************************************************************/ |
| 1351 | void l2cble_send_flow_control_credit(tL2C_CCB *p_ccb, UINT16 credit_value) |
| 1352 | { |
| 1353 | if (!p_ccb) |
| 1354 | return; |
| 1355 | |
| 1356 | if (p_ccb->p_lcb && p_ccb->p_lcb->transport != BT_TRANSPORT_LE) |
| 1357 | { |
| 1358 | L2CAP_TRACE_WARNING ("LE link doesn't exist"); |
| 1359 | return; |
| 1360 | } |
| 1361 | |
| 1362 | l2cu_send_peer_ble_flow_control_credit(p_ccb, credit_value); |
| 1363 | return; |
| 1364 | |
| 1365 | } |
| 1366 | |
| 1367 | /******************************************************************************* |
| 1368 | ** |
| 1369 | ** Function l2cble_send_peer_disc_req |
| 1370 | ** |
| 1371 | ** Description This function sends disconnect request |
| 1372 | ** to the peer LE device |
| 1373 | ** |
| 1374 | ** Returns void |
| 1375 | ** |
| 1376 | *******************************************************************************/ |
| 1377 | void l2cble_send_peer_disc_req(tL2C_CCB *p_ccb) |
| 1378 | { |
| 1379 | L2CAP_TRACE_DEBUG ("%s",__func__); |
| 1380 | if (!p_ccb) |
| 1381 | return; |
| 1382 | |
| 1383 | if (p_ccb->p_lcb && p_ccb->p_lcb->transport != BT_TRANSPORT_LE) |
| 1384 | { |
| 1385 | L2CAP_TRACE_WARNING ("LE link doesn't exist"); |
| 1386 | return; |
| 1387 | } |
| 1388 | |
| 1389 | l2cu_send_peer_ble_credit_based_disconn_req(p_ccb); |
| 1390 | return; |
| 1391 | } |
| 1392 | |
| 1393 | /******************************************************************************* |
| 1394 | ** |
| 1395 | ** Function l2cble_sec_comp |
| 1396 | ** |
| 1397 | ** Description This function is called when security procedure for an LE COC |
| 1398 | ** link is done |
| 1399 | ** |
| 1400 | ** Returns void |
| 1401 | ** |
| 1402 | *******************************************************************************/ |
| 1403 | void l2cble_sec_comp(BD_ADDR p_bda, tBT_TRANSPORT transport, void *p_ref_data, UINT8 status) |
| 1404 | { |
| 1405 | tL2C_LCB *p_lcb = l2cu_find_lcb_by_bd_addr(p_bda, BT_TRANSPORT_LE); |
| 1406 | tL2CAP_SEC_DATA *p_buf = NULL; |
| 1407 | UINT8 sec_flag; |
| 1408 | UINT8 sec_act; |
| 1409 | |
| 1410 | if (!p_lcb) |
| 1411 | { |
| 1412 | L2CAP_TRACE_WARNING ("%s security complete for unknown device", __func__); |
| 1413 | return; |
| 1414 | } |
| 1415 | |
| 1416 | sec_act = p_lcb->sec_act; |
| 1417 | p_lcb->sec_act = 0; |
| 1418 | |
| 1419 | if (!fixed_queue_is_empty(p_lcb->le_sec_pending_q)) |
| 1420 | { |
| 1421 | p_buf = (tL2CAP_SEC_DATA*) fixed_queue_dequeue(p_lcb->le_sec_pending_q); |
| 1422 | if (!p_buf) |
| 1423 | { |
| 1424 | L2CAP_TRACE_WARNING ("%s Security complete for request not initiated from L2CAP", |
| 1425 | __func__); |
| 1426 | return; |
| 1427 | } |
| 1428 | |
| 1429 | if (status != BTM_SUCCESS) |
| 1430 | { |
| 1431 | (*(p_buf->p_callback))(p_bda, BT_TRANSPORT_LE, p_buf->p_ref_data, status); |
| 1432 | } |
| 1433 | else |
| 1434 | { |
| 1435 | if (sec_act == BTM_SEC_ENCRYPT_MITM) |
| 1436 | { |
| 1437 | BTM_GetSecurityFlagsByTransport(p_bda, &sec_flag, transport); |
| 1438 | if (sec_flag & BTM_SEC_FLAG_LKEY_AUTHED) |
| 1439 | (*(p_buf->p_callback))(p_bda, BT_TRANSPORT_LE, p_buf->p_ref_data, status); |
| 1440 | else |
| 1441 | { |
| 1442 | L2CAP_TRACE_DEBUG ("%s MITM Protection Not present", __func__); |
| 1443 | (*(p_buf->p_callback))(p_bda, BT_TRANSPORT_LE, p_buf->p_ref_data, |
| 1444 | BTM_FAILED_ON_SECURITY); |
| 1445 | } |
| 1446 | } |
| 1447 | else |
| 1448 | { |
| 1449 | L2CAP_TRACE_DEBUG ("%s MITM Protection not required sec_act = %d", |
| 1450 | __func__, p_lcb->sec_act); |
| 1451 | |
| 1452 | (*(p_buf->p_callback))(p_bda, BT_TRANSPORT_LE, p_buf->p_ref_data, status); |
| 1453 | } |
| 1454 | } |
| 1455 | } |
| 1456 | else |
| 1457 | { |
| 1458 | L2CAP_TRACE_WARNING ("%s Security complete for request not initiated from L2CAP", __func__); |
| 1459 | return; |
| 1460 | } |
| 1461 | osi_free(p_buf); |
| 1462 | |
| 1463 | while (!fixed_queue_is_empty(p_lcb->le_sec_pending_q)) |
| 1464 | { |
| 1465 | p_buf = (tL2CAP_SEC_DATA*) fixed_queue_dequeue(p_lcb->le_sec_pending_q); |
| 1466 | |
| 1467 | if (status != BTM_SUCCESS) |
| 1468 | (*(p_buf->p_callback))(p_bda, BT_TRANSPORT_LE, p_buf->p_ref_data, status); |
| 1469 | else |
| 1470 | l2ble_sec_access_req(p_bda, p_buf->psm, p_buf->is_originator, |
| 1471 | p_buf->p_callback, p_buf->p_ref_data); |
| 1472 | |
| 1473 | osi_free(p_buf); |
| 1474 | } |
| 1475 | } |
| 1476 | |
| 1477 | /******************************************************************************* |
| 1478 | ** |
| 1479 | ** Function l2ble_sec_access_req |
| 1480 | ** |
| 1481 | ** Description This function is called by LE COC link to meet the |
| 1482 | ** security requirement for the link |
| 1483 | ** |
| 1484 | ** Returns TRUE - security procedures are started |
| 1485 | ** FALSE - failure |
| 1486 | ** |
| 1487 | *******************************************************************************/ |
| 1488 | BOOLEAN l2ble_sec_access_req(BD_ADDR bd_addr, UINT16 psm, BOOLEAN is_originator, tL2CAP_SEC_CBACK *p_callback, void *p_ref_data) |
| 1489 | { |
| 1490 | L2CAP_TRACE_DEBUG ("%s", __func__); |
| 1491 | BOOLEAN status; |
| 1492 | tL2C_LCB *p_lcb = NULL; |
| 1493 | |
| 1494 | if (!p_callback) |
| 1495 | { |
| 1496 | L2CAP_TRACE_ERROR("%s No callback function", __func__); |
| 1497 | return FALSE; |
| 1498 | } |
| 1499 | |
| 1500 | p_lcb = l2cu_find_lcb_by_bd_addr(bd_addr, BT_TRANSPORT_LE); |
| 1501 | |
| 1502 | if (!p_lcb) |
| 1503 | { |
| 1504 | L2CAP_TRACE_ERROR ("%s Security check for unknown device", __func__); |
| 1505 | p_callback(bd_addr, BT_TRANSPORT_LE, p_ref_data, BTM_UNKNOWN_ADDR); |
| 1506 | return FALSE; |
| 1507 | } |
| 1508 | |
| 1509 | tL2CAP_SEC_DATA *p_buf = (tL2CAP_SEC_DATA*) osi_malloc((UINT16)sizeof(tL2CAP_SEC_DATA)); |
| 1510 | if (!p_buf) |
| 1511 | { |
| 1512 | p_callback(bd_addr, BT_TRANSPORT_LE, p_ref_data, BTM_NO_RESOURCES); |
| 1513 | return FALSE; |
| 1514 | } |
| 1515 | |
| 1516 | p_buf->psm = psm; |
| 1517 | p_buf->is_originator = is_originator; |
| 1518 | p_buf->p_callback = p_callback; |
| 1519 | p_buf->p_ref_data = p_ref_data; |
| 1520 | fixed_queue_enqueue(p_lcb->le_sec_pending_q, p_buf); |
| 1521 | status = btm_ble_start_sec_check(bd_addr, psm, is_originator, &l2cble_sec_comp, p_ref_data); |
| 1522 | |
| 1523 | return status; |
| 1524 | } |
| The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1525 | #endif /* (BLE_INCLUDED == TRUE) */ |