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