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