1 /******************************************************************************
3 * Copyright (C) 2000-2012 Broadcom Corporation
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:
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 ******************************************************************************/
19 /******************************************************************************
21 * This file contains functions that handle ACL connections. This includes
22 * operations such as hold and sniff modes, supported packet types.
24 ******************************************************************************/
32 #include "bt_target.h"
43 static void btm_read_remote_features (UINT16 handle);
44 static void btm_read_remote_ext_features (UINT16 handle, UINT8 page_number);
45 static void btm_process_remote_ext_features_page (tACL_CONN *p_acl_cb, tBTM_SEC_DEV_REC *p_dev_rec,
47 static void btm_process_remote_ext_features (tACL_CONN *p_acl_cb, UINT8 num_read_pages);
49 #define BTM_DEV_REPLY_TIMEOUT 3 /* 3 second timeout waiting for responses */
51 /*******************************************************************************
53 ** Function btm_save_remote_device_role
55 ** Description This function is to save remote device role
59 *******************************************************************************/
60 static void btm_save_remote_device_role(BD_ADDR bd_addr, UINT8 role)
63 if (role == BTM_ROLE_UNDEFINED) return;
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]))) {
72 if (i < BTM_ROLE_DEVICE_NUM) {
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]);
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;
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]);
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;
97 /*******************************************************************************
99 ** Function btm_acl_init
101 ** Description This function is called at BTM startup to initialize
105 *******************************************************************************/
106 void btm_acl_init (void)
108 BTM_TRACE_DEBUG ("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 */
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;
118 btm_cb.p_acl_changed_cb = NULL;
122 /* Initialize nonzero defaults */
123 btm_cb.btm_def_link_super_tout = HCI_DEFAULT_INACT_TOUT;
124 btm_cb.acl_disc_reason = 0xff ;
127 /*******************************************************************************
129 ** Function btm_bda_to_acl
131 ** Description This function returns the FIRST acl_db entry for the passed BDA.
133 ** Parameters bda : BD address of the remote device
134 ** transport : Physical transport used for ACL connection (BR/EDR or LE)
136 ** Returns Returns pointer to the ACL DB for the requested BDA if found.
137 ** NULL if not found.
139 *******************************************************************************/
140 tACL_CONN *btm_bda_to_acl (BD_ADDR bda, tBT_TRANSPORT transport)
142 tACL_CONN *p = &btm_cb.acl_db[0];
146 for (xx = 0; xx < MAX_L2CAP_LINKS; xx++, p++)
148 if ((p->in_use) && (!memcmp (p->remote_addr, bda, BD_ADDR_LEN))
149 #if BLE_INCLUDED == TRUE
150 && p->transport == transport
154 BTM_TRACE_DEBUG ("btm_bda_to_acl found");
160 /* If here, no BD Addr found */
161 return((tACL_CONN *)NULL);
164 /*******************************************************************************
166 ** Function btm_handle_to_acl_index
168 ** Description This function returns the FIRST acl_db entry for the passed hci_handle.
170 ** Returns index to the acl_db or MAX_L2CAP_LINKS.
172 *******************************************************************************/
173 UINT8 btm_handle_to_acl_index (UINT16 hci_handle)
175 tACL_CONN *p = &btm_cb.acl_db[0];
177 BTM_TRACE_DEBUG ("btm_handle_to_acl_index");
178 for (xx = 0; xx < MAX_L2CAP_LINKS; xx++, p++)
180 if ((p->in_use) && (p->hci_handle == hci_handle))
186 /* If here, no BD Addr found */
190 #if BLE_PRIVACY_SPT == TRUE
191 /*******************************************************************************
193 ** Function btm_ble_get_acl_remote_addr
195 ** Description This function reads the active remote address used for the
198 ** Returns success return TRUE, otherwise FALSE.
200 *******************************************************************************/
201 BOOLEAN btm_ble_get_acl_remote_addr(tBTM_SEC_DEV_REC *p_dev_rec, BD_ADDR conn_addr,
202 tBLE_ADDR_TYPE *p_addr_type)
204 #if BLE_INCLUDED == TRUE
207 if (p_dev_rec == NULL)
209 BTM_TRACE_ERROR("btm_ble_get_acl_remote_addr can not find device with matching address");
213 switch (p_dev_rec->ble.active_addr_type)
215 case BTM_BLE_ADDR_PSEUDO:
216 memcpy(conn_addr, p_dev_rec->bd_addr, BD_ADDR_LEN);
217 * p_addr_type = p_dev_rec->ble.ble_addr_type;
220 case BTM_BLE_ADDR_RRA:
221 memcpy(conn_addr, p_dev_rec->ble.cur_rand_addr, BD_ADDR_LEN);
222 * p_addr_type = BLE_ADDR_RANDOM;
225 case BTM_BLE_ADDR_STATIC:
226 memcpy(conn_addr, p_dev_rec->ble.static_addr, BD_ADDR_LEN);
227 * p_addr_type = p_dev_rec->ble.static_addr_type;
231 BTM_TRACE_ERROR("Unknown active address: %d", p_dev_rec->ble.active_addr_type);
245 /*******************************************************************************
247 ** Function btm_acl_created
249 ** Description This function is called by L2CAP when an ACL connection
254 *******************************************************************************/
255 void btm_acl_created (BD_ADDR bda, DEV_CLASS dc, BD_NAME bdn,
256 UINT16 hci_handle, UINT8 link_role, tBT_TRANSPORT transport)
258 tBTM_SEC_DEV_REC *p_dev_rec = NULL;
263 BTM_TRACE_DEBUG ("btm_acl_created hci_handle=%d link_role=%d transport=%d",
264 hci_handle,link_role, transport);
265 /* Ensure we don't have duplicates */
266 p = btm_bda_to_acl(bda, transport);
267 if (p != (tACL_CONN *)NULL)
269 p->hci_handle = hci_handle;
270 p->link_role = link_role;
271 btm_save_remote_device_role(bda, link_role);
272 #if BLE_INCLUDED == TRUE
273 p->transport = transport;
275 BTM_TRACE_DEBUG ("Duplicate btm_acl_created: RemBdAddr: %02x%02x%02x%02x%02x%02x",
276 bda[0], bda[1], bda[2], bda[3], bda[4], bda[5]);
277 BTM_SetLinkPolicy(p->remote_addr, &btm_cb.btm_def_link_policy);
281 /* Allocate acl_db entry */
282 for (xx = 0, p = &btm_cb.acl_db[0]; xx < MAX_L2CAP_LINKS; xx++, p++)
287 p->hci_handle = hci_handle;
288 p->link_role = link_role;
289 btm_save_remote_device_role(bda, link_role);
290 p->link_up_issued = FALSE;
292 #if BLE_INCLUDED == TRUE
293 p->transport = transport;
294 if (transport == BT_TRANSPORT_LE)
296 #if BLE_PRIVACY_SPT == TRUE
297 if (btm_cb.ble_ctr_cb.privacy)
299 p->conn_addr_type = btm_cb.ble_ctr_cb.addr_mgnt_cb.own_addr_type;
300 memcpy(p->conn_addr, btm_cb.ble_ctr_cb.addr_mgnt_cb.private_addr, BD_ADDR_LEN);
305 p->conn_addr_type = BLE_ADDR_PUBLIC;
306 BTM_GetLocalDeviceAddr(p->conn_addr);
310 p->restore_pkt_types = 0; /* Only exists while SCO is active */
311 p->switch_role_state = BTM_ACL_SWKEY_STATE_IDLE;
313 #if BTM_PWR_MGR_INCLUDED == FALSE
314 p->mode = BTM_ACL_MODE_NORMAL;
317 #endif /* BTM_PWR_MGR_INCLUDED == FALSE */
319 memcpy (p->remote_addr, bda, BD_ADDR_LEN);
322 memcpy (p->remote_dc, dc, DEV_CLASS_LEN);
325 memcpy (p->remote_name, bdn, BTM_MAX_REM_BD_NAME_LEN);
327 /* if BR/EDR do something more */
328 if (transport == BT_TRANSPORT_BR_EDR)
330 btsnd_hcic_read_rmt_clk_offset (p->hci_handle);
331 btsnd_hcic_rmt_ver_req (p->hci_handle);
333 p_dev_rec = btm_find_dev_by_handle (hci_handle);
335 #if (BLE_INCLUDED == TRUE)
338 BTM_TRACE_DEBUG ("device_type=0x%x", p_dev_rec->device_type);
342 if (p_dev_rec && !(transport == BT_TRANSPORT_LE))
344 /* If remote features already known, copy them and continue connection setup */
345 if ((p_dev_rec->num_read_pages) &&
346 (p_dev_rec->num_read_pages <= (HCI_EXT_FEATURES_PAGE_MAX + 1)) /* sanity check */)
348 memcpy (p->peer_lmp_features, p_dev_rec->features,
349 (HCI_FEATURE_BYTES_PER_PAGE * p_dev_rec->num_read_pages));
350 p->num_read_pages = p_dev_rec->num_read_pages;
352 if (BTM_SEC_MODE_SP == btm_cb.security_mode
353 && HCI_SSP_HOST_SUPPORTED(p_dev_rec->features[HCI_EXT_FEATURES_PAGE_1])
354 && HCI_SIMPLE_PAIRING_SUPPORTED(p_dev_rec->features[HCI_EXT_FEATURES_PAGE_0]))
356 p_dev_rec->sm4 = BTM_SM4_TRUE;
360 p_dev_rec->sm4 |= BTM_SM4_KNOWN;
363 btm_establish_continue (p);
368 #if (BLE_INCLUDED == TRUE)
369 /* If here, features are not known yet */
370 if (p_dev_rec && transport == BT_TRANSPORT_LE)
372 #if BLE_PRIVACY_SPT == TRUE
373 btm_ble_get_acl_remote_addr (p_dev_rec, p->active_remote_addr,
374 &p->active_remote_addr_type);
377 if (HCI_LE_SLAVE_INIT_FEAT_EXC_SUPPORTED(btm_cb.devcb.local_le_features)
378 || link_role == HCI_ROLE_MASTER)
380 btsnd_hcic_ble_read_remote_feat(p->hci_handle);
384 btm_establish_continue(p);
390 btm_read_remote_features (p->hci_handle);
393 /* read page 1 - on rmt feature event for buffer reasons */
400 /*******************************************************************************
402 ** Function btm_acl_report_role_change
404 ** Description This function is called when the local device is deemed
405 ** to be down. It notifies L2CAP of the failure.
409 *******************************************************************************/
410 void btm_acl_report_role_change (UINT8 hci_status, BD_ADDR bda)
412 tBTM_ROLE_SWITCH_CMPL ref_data;
413 BTM_TRACE_DEBUG ("btm_acl_report_role_change");
414 if (btm_cb.devcb.p_switch_role_cb
415 && (bda && (0 == memcmp(btm_cb.devcb.switch_role_ref_data.remote_bd_addr, bda, BD_ADDR_LEN))))
417 memcpy (&ref_data, &btm_cb.devcb.switch_role_ref_data, sizeof(tBTM_ROLE_SWITCH_CMPL));
418 ref_data.hci_status = hci_status;
419 (*btm_cb.devcb.p_switch_role_cb)(&ref_data);
420 memset (&btm_cb.devcb.switch_role_ref_data, 0, sizeof(tBTM_ROLE_SWITCH_CMPL));
421 btm_cb.devcb.p_switch_role_cb = NULL;
425 /*******************************************************************************
427 ** Function btm_acl_removed
429 ** Description This function is called by L2CAP when an ACL connection
430 ** is removed. Since only L2CAP creates ACL links, we use
431 ** the L2CAP link index as our index into the control blocks.
435 *******************************************************************************/
436 void btm_acl_removed (BD_ADDR bda, tBT_TRANSPORT transport)
439 #if (defined(BTM_BUSY_LEVEL_CHANGE_INCLUDED) && BTM_BUSY_LEVEL_CHANGE_INCLUDED == TRUE)
440 tBTM_BL_EVENT_DATA evt_data;
442 #if (defined BLE_INCLUDED && BLE_INCLUDED == TRUE)
443 tBTM_SEC_DEV_REC *p_dev_rec=NULL;
446 BTM_TRACE_DEBUG ("btm_acl_removed");
447 p = btm_bda_to_acl(bda, transport);
448 if (p != (tACL_CONN *)NULL)
452 /* if the disconnected channel has a pending role switch, clear it now */
453 btm_acl_report_role_change(HCI_ERR_NO_CONNECTION, bda);
455 /* Only notify if link up has had a chance to be issued */
456 if (p->link_up_issued)
458 p->link_up_issued = FALSE;
460 /* If anyone cares, tell him database changed */
461 #if (defined(BTM_BUSY_LEVEL_CHANGE_INCLUDED) && BTM_BUSY_LEVEL_CHANGE_INCLUDED == TRUE)
462 if (btm_cb.p_bl_changed_cb)
464 evt_data.event = BTM_BL_DISCN_EVT;
465 evt_data.discn.p_bda = bda;
466 #if BLE_INCLUDED == TRUE
467 evt_data.discn.handle = p->hci_handle;
468 evt_data.discn.transport = p->transport;
470 (*btm_cb.p_bl_changed_cb)(&evt_data);
473 btm_acl_update_busy_level (BTM_BLI_ACL_DOWN_EVT);
475 if (btm_cb.p_acl_changed_cb)
476 #if BLE_INCLUDED == TRUE
477 (*btm_cb.p_acl_changed_cb) (bda, NULL, NULL, NULL, FALSE, p->hci_handle, p->transport);
479 (*btm_cb.p_acl_changed_cb) (bda, NULL, NULL, NULL, FALSE);
484 #if (defined BLE_INCLUDED && BLE_INCLUDED == TRUE)
486 BTM_TRACE_DEBUG ("acl hci_handle=%d transport=%d connectable_mode=0x%0x link_role=%d",
489 btm_cb.ble_ctr_cb.inq_var.connectable_mode,
492 p_dev_rec = btm_find_dev(bda);
495 BTM_TRACE_DEBUG("before update p_dev_rec->sec_flags=0x%x", p_dev_rec->sec_flags);
496 if (p->transport == BT_TRANSPORT_LE)
498 BTM_TRACE_DEBUG("LE link down");
499 p_dev_rec->sec_flags &= ~(BTM_SEC_LE_ENCRYPTED | BTM_SEC_ROLE_SWITCHED);
500 if ( (p_dev_rec->sec_flags & BTM_SEC_LE_LINK_KEY_KNOWN) == 0)
502 BTM_TRACE_DEBUG("Not Bonded");
503 p_dev_rec->sec_flags &= ~(BTM_SEC_LE_LINK_KEY_AUTHED | BTM_SEC_LE_AUTHENTICATED);
507 BTM_TRACE_DEBUG("Bonded");
512 BTM_TRACE_DEBUG("Bletooth link down");
513 p_dev_rec->sec_flags &= ~(BTM_SEC_AUTHORIZED | BTM_SEC_AUTHENTICATED
514 | BTM_SEC_ENCRYPTED | BTM_SEC_ROLE_SWITCHED);
516 BTM_TRACE_DEBUG("after update p_dev_rec->sec_flags=0x%x", p_dev_rec->sec_flags);
520 BTM_TRACE_ERROR("Device not found");
530 /*******************************************************************************
532 ** Function btm_acl_device_down
534 ** Description This function is called when the local device is deemed
535 ** to be down. It notifies L2CAP of the failure.
539 *******************************************************************************/
540 void btm_acl_device_down (void)
542 tACL_CONN *p = &btm_cb.acl_db[0];
544 BTM_TRACE_DEBUG ("btm_acl_device_down");
545 for (xx = 0; xx < MAX_L2CAP_LINKS; xx++, p++)
549 BTM_TRACE_DEBUG ("hci_handle=%d HCI_ERR_HW_FAILURE ",p->hci_handle );
550 l2c_link_hci_disc_comp (p->hci_handle, HCI_ERR_HW_FAILURE);
555 #if (defined(BTM_BUSY_LEVEL_CHANGE_INCLUDED) && BTM_BUSY_LEVEL_CHANGE_INCLUDED == TRUE)
556 /*******************************************************************************
558 ** Function btm_acl_update_busy_level
560 ** Description This function is called to update the busy level of the system
565 *******************************************************************************/
566 void btm_acl_update_busy_level (tBTM_BLI_EVENT event)
568 tBTM_BL_UPDATE_DATA evt;
570 BTM_TRACE_DEBUG ("btm_acl_update_busy_level");
571 BOOLEAN old_inquiry_state = btm_cb.is_inquiry;
574 case BTM_BLI_ACL_UP_EVT:
575 BTM_TRACE_DEBUG ("BTM_BLI_ACL_UP_EVT");
578 case BTM_BLI_ACL_DOWN_EVT:
582 BTM_TRACE_DEBUG ("BTM_BLI_ACL_DOWN_EVT", btm_cb.num_acl);
586 BTM_TRACE_ERROR ("BTM_BLI_ACL_DOWN_EVT issued, but num_acl already zero !!!");
589 case BTM_BLI_PAGE_EVT:
590 BTM_TRACE_DEBUG ("BTM_BLI_PAGE_EVT");
591 btm_cb.is_paging = TRUE;
592 evt.busy_level_flags= BTM_BL_PAGING_STARTED;
594 case BTM_BLI_PAGE_DONE_EVT:
595 BTM_TRACE_DEBUG ("BTM_BLI_PAGE_DONE_EVT");
596 btm_cb.is_paging = FALSE;
597 evt.busy_level_flags = BTM_BL_PAGING_COMPLETE;
599 case BTM_BLI_INQ_EVT:
600 BTM_TRACE_DEBUG ("BTM_BLI_INQ_EVT");
601 btm_cb.is_inquiry = TRUE;
602 evt.busy_level_flags = BTM_BL_INQUIRY_STARTED;
604 case BTM_BLI_INQ_CANCEL_EVT:
605 BTM_TRACE_DEBUG ("BTM_BLI_INQ_CANCEL_EVT");
606 btm_cb.is_inquiry = FALSE;
607 evt.busy_level_flags = BTM_BL_INQUIRY_CANCELLED;
609 case BTM_BLI_INQ_DONE_EVT:
610 BTM_TRACE_DEBUG ("BTM_BLI_INQ_DONE_EVT");
611 btm_cb.is_inquiry = FALSE;
612 evt.busy_level_flags = BTM_BL_INQUIRY_COMPLETE;
616 if (btm_cb.is_paging || btm_cb.is_inquiry)
619 busy_level = (UINT8)btm_cb.num_acl;
621 if ((busy_level != btm_cb.busy_level) ||(old_inquiry_state != btm_cb.is_inquiry))
623 evt.event = BTM_BL_UPDATE_EVT;
624 evt.busy_level = busy_level;
625 btm_cb.busy_level = busy_level;
626 if (btm_cb.p_bl_changed_cb && (btm_cb.bl_evt_mask & BTM_BL_UPDATE_MASK))
628 (*btm_cb.p_bl_changed_cb)((tBTM_BL_EVENT_DATA *)&evt);
635 /*******************************************************************************
637 ** Function BTM_GetRole
639 ** Description This function is called to get the role of the local device
640 ** for the ACL connection with the specified remote device
642 ** Returns BTM_SUCCESS if connection exists.
643 ** BTM_UNKNOWN_ADDR if no active link with bd addr specified
645 *******************************************************************************/
646 tBTM_STATUS BTM_GetRole (BD_ADDR remote_bd_addr, UINT8 *p_role)
649 BTM_TRACE_DEBUG ("BTM_GetRole");
650 if ((p = btm_bda_to_acl(remote_bd_addr, BT_TRANSPORT_BR_EDR)) == NULL)
652 *p_role = BTM_ROLE_UNDEFINED;
653 return(BTM_UNKNOWN_ADDR);
656 /* Get the current role */
657 *p_role = p->link_role;
662 /*******************************************************************************
664 ** Function BTM_SwitchRole
666 ** Description This function is called to switch role between master and
667 ** slave. If role is already set it will do nothing. If the
668 ** command was initiated, the callback function is called upon
671 ** Returns BTM_SUCCESS if already in specified role.
672 ** BTM_CMD_STARTED if command issued to controller.
673 ** BTM_NO_RESOURCES if couldn't allocate memory to issue command
674 ** BTM_UNKNOWN_ADDR if no active link with bd addr specified
675 ** BTM_MODE_UNSUPPORTED if local device does not support role switching
676 ** BTM_BUSY if the previous command is not completed
678 *******************************************************************************/
679 tBTM_STATUS BTM_SwitchRole (BD_ADDR remote_bd_addr, UINT8 new_role, tBTM_CMPL_CB *p_cb)
682 tBTM_SEC_DEV_REC *p_dev_rec = NULL;
683 #if BTM_SCO_INCLUDED == TRUE
684 BOOLEAN is_sco_active;
686 #if BTM_PWR_MGR_INCLUDED == TRUE
688 tBTM_PM_MODE pwr_mode;
689 tBTM_PM_PWR_MD settings;
691 #if (BT_USE_TRACES == TRUE)
694 BTM_TRACE_API ("BTM_SwitchRole BDA: %02x-%02x-%02x-%02x-%02x-%02x",
695 remote_bd_addr[0], remote_bd_addr[1], remote_bd_addr[2],
696 remote_bd_addr[3], remote_bd_addr[4], remote_bd_addr[5]);
698 /* Make sure the local device supports switching */
699 if (!(HCI_SWITCH_SUPPORTED(btm_cb.devcb.local_lmp_features[HCI_EXT_FEATURES_PAGE_0])))
700 return(BTM_MODE_UNSUPPORTED);
702 if (btm_cb.devcb.p_switch_role_cb && p_cb)
704 #if (BT_USE_TRACES == TRUE)
705 p_bda = btm_cb.devcb.switch_role_ref_data.remote_bd_addr;
706 BTM_TRACE_DEBUG ("Role switch on other device is in progress 0x%02x%02x%02x%02x%02x%02x",
707 p_bda[0], p_bda[1], p_bda[2],
708 p_bda[3], p_bda[4], p_bda[5]);
713 if ((p = btm_bda_to_acl(remote_bd_addr, BT_TRANSPORT_BR_EDR)) == NULL)
714 return(BTM_UNKNOWN_ADDR);
716 /* Finished if already in desired role */
717 if (p->link_role == new_role)
720 #if BTM_SCO_INCLUDED == TRUE
721 /* Check if there is any SCO Active on this BD Address */
722 is_sco_active = btm_is_sco_active_by_bdaddr(remote_bd_addr);
724 if (is_sco_active == TRUE)
725 return(BTM_NO_RESOURCES);
728 /* Ignore role switch request if the previous request was not completed */
729 if (p->switch_role_state != BTM_ACL_SWKEY_STATE_IDLE)
731 BTM_TRACE_DEBUG ("BTM_SwitchRole busy: %d",
732 p->switch_role_state);
736 /* Cannot switch role while parked or sniffing */
737 #if BTM_PWR_MGR_INCLUDED == FALSE
738 if (p->mode == HCI_MODE_PARK)
740 if (!btsnd_hcic_exit_park_mode (p->hci_handle))
741 return(BTM_NO_RESOURCES);
743 p->switch_role_state = BTM_ACL_SWKEY_STATE_MODE_CHANGE;
745 else if (p->mode == HCI_MODE_SNIFF)
747 if (!btsnd_hcic_exit_sniff_mode (p->hci_handle))
748 return(BTM_NO_RESOURCES);
750 p->switch_role_state = BTM_ACL_SWKEY_STATE_MODE_CHANGE;
752 #else /* power manager is in use */
754 if ((status = BTM_ReadPowerMode(p->remote_addr, &pwr_mode)) != BTM_SUCCESS)
757 /* Wake up the link if in sniff or park before attempting switch */
758 if (pwr_mode == BTM_PM_MD_PARK || pwr_mode == BTM_PM_MD_SNIFF)
760 memset( (void*)&settings, 0, sizeof(settings));
761 settings.mode = BTM_PM_MD_ACTIVE;
762 status = BTM_SetPowerMode (BTM_PM_SET_ONLY_ID, p->remote_addr, &settings);
763 if (status != BTM_CMD_STARTED)
764 return(BTM_WRONG_MODE);
766 p->switch_role_state = BTM_ACL_SWKEY_STATE_MODE_CHANGE;
769 /* some devices do not support switch while encryption is on */
772 p_dev_rec = btm_find_dev (remote_bd_addr);
773 if ((p_dev_rec != NULL)
774 && ((p_dev_rec->sec_flags & BTM_SEC_ENCRYPTED) != 0)
775 && !BTM_EPR_AVAILABLE(p))
777 /* bypass turning off encryption if change link key is already doing it */
778 if (p->encrypt_state != BTM_ACL_ENCRYPT_STATE_ENCRYPT_OFF)
780 if (!btsnd_hcic_set_conn_encrypt (p->hci_handle, FALSE))
781 return(BTM_NO_RESOURCES);
783 p->encrypt_state = BTM_ACL_ENCRYPT_STATE_ENCRYPT_OFF;
786 p->switch_role_state = BTM_ACL_SWKEY_STATE_ENCRYPTION_OFF;
790 if (!btsnd_hcic_switch_role (remote_bd_addr, new_role))
791 return(BTM_NO_RESOURCES);
793 p->switch_role_state = BTM_ACL_SWKEY_STATE_IN_PROGRESS;
795 #if BTM_DISC_DURING_RS == TRUE
797 p_dev_rec->rs_disc_pending = BTM_SEC_RS_PENDING;
802 /* Initialize return structure in case request fails */
805 memcpy (btm_cb.devcb.switch_role_ref_data.remote_bd_addr, remote_bd_addr,
807 btm_cb.devcb.switch_role_ref_data.role = new_role;
808 /* initialized to an error code */
809 btm_cb.devcb.switch_role_ref_data.hci_status = HCI_ERR_UNSUPPORTED_VALUE;
810 btm_cb.devcb.p_switch_role_cb = p_cb;
812 return(BTM_CMD_STARTED);
815 /*******************************************************************************
817 ** Function BTM_ChangeLinkKey
819 ** Description This function is called to change the link key of the
822 ** Returns BTM_CMD_STARTED if command issued to controller.
823 ** BTM_NO_RESOURCES if couldn't allocate memory to issue command
824 ** BTM_UNKNOWN_ADDR if no active link with bd addr specified
825 ** BTM_BUSY if the previous command is not completed
827 *******************************************************************************/
828 tBTM_STATUS BTM_ChangeLinkKey (BD_ADDR remote_bd_addr, tBTM_CMPL_CB *p_cb)
831 tBTM_SEC_DEV_REC *p_dev_rec = NULL;
832 #if BTM_PWR_MGR_INCLUDED == TRUE
834 tBTM_PM_MODE pwr_mode;
835 tBTM_PM_PWR_MD settings;
837 BTM_TRACE_DEBUG ("BTM_ChangeLinkKey");
838 if ((p = btm_bda_to_acl(remote_bd_addr, BT_TRANSPORT_BR_EDR)) == NULL)
839 return(BTM_UNKNOWN_ADDR);
841 /* Ignore change link key request if the previsous request has not completed */
842 if (p->change_key_state != BTM_ACL_SWKEY_STATE_IDLE)
844 BTM_TRACE_DEBUG ("Link key change request declined since the previous request"
845 " for this device has not completed ");
849 memset (&btm_cb.devcb.chg_link_key_ref_data, 0, sizeof(tBTM_CHANGE_KEY_CMPL));
851 /* Cannot change key while parked */
852 #if BTM_PWR_MGR_INCLUDED == FALSE
853 if (p->mode == HCI_MODE_PARK)
855 if (!btsnd_hcic_exit_park_mode (p->hci_handle))
856 return(BTM_NO_RESOURCES);
858 p->change_key_state = BTM_ACL_SWKEY_STATE_MODE_CHANGE;
860 #else /* power manager is in use */
863 if ((status = BTM_ReadPowerMode(p->remote_addr, &pwr_mode)) != BTM_SUCCESS)
866 /* Wake up the link if in park before attempting to change link keys */
867 if (pwr_mode == BTM_PM_MD_PARK)
869 memset( (void*)&settings, 0, sizeof(settings));
870 settings.mode = BTM_PM_MD_ACTIVE;
871 status = BTM_SetPowerMode (BTM_PM_SET_ONLY_ID, p->remote_addr, &settings);
872 if (status != BTM_CMD_STARTED)
873 return(BTM_WRONG_MODE);
875 p->change_key_state = BTM_ACL_SWKEY_STATE_MODE_CHANGE;
878 /* some devices do not support change of link key while encryption is on */
879 else if (((p_dev_rec = btm_find_dev (remote_bd_addr)) != NULL)
880 && ((p_dev_rec->sec_flags & BTM_SEC_ENCRYPTED) != 0) && !BTM_EPR_AVAILABLE(p))
882 /* bypass turning off encryption if switch role is already doing it */
883 if (p->encrypt_state != BTM_ACL_ENCRYPT_STATE_ENCRYPT_OFF)
885 if (!btsnd_hcic_set_conn_encrypt (p->hci_handle, FALSE))
886 return(BTM_NO_RESOURCES);
888 p->encrypt_state = BTM_ACL_ENCRYPT_STATE_ENCRYPT_OFF;
891 p->change_key_state = BTM_ACL_SWKEY_STATE_ENCRYPTION_OFF;
893 else /* Ok to initiate change of link key */
895 if (!btsnd_hcic_change_link_key (p->hci_handle))
896 return(BTM_NO_RESOURCES);
898 p->change_key_state = BTM_ACL_SWKEY_STATE_IN_PROGRESS;
901 /* Initialize return structure in case request fails */
902 memcpy (btm_cb.devcb.chg_link_key_ref_data.remote_bd_addr, remote_bd_addr,
904 btm_cb.devcb.p_chg_link_key_cb = p_cb;
905 return(BTM_CMD_STARTED);
908 /*******************************************************************************
910 ** Function btm_acl_link_key_change
912 ** Description This function is called to when a change link key event
915 *******************************************************************************/
916 void btm_acl_link_key_change (UINT16 handle, UINT8 status)
918 tBTM_CHANGE_KEY_CMPL *p_data;
921 BTM_TRACE_DEBUG ("btm_acl_link_key_change");
922 /* Look up the connection by handle and set the current mode */
923 xx = btm_handle_to_acl_index(handle);
925 /* don't assume that we can never get a bad hci_handle */
926 if (xx >= MAX_L2CAP_LINKS)
929 p_data = &btm_cb.devcb.chg_link_key_ref_data;
930 p = &btm_cb.acl_db[xx];
931 p_data->hci_status = status;
933 /* if switching state is switching we need to turn encryption on */
934 /* if idle, we did not change encryption */
935 if (p->change_key_state == BTM_ACL_SWKEY_STATE_SWITCHING)
937 /* Make sure there's not also a role switch going on before re-enabling */
938 if (p->switch_role_state != BTM_ACL_SWKEY_STATE_SWITCHING)
940 if (btsnd_hcic_set_conn_encrypt (p->hci_handle, TRUE))
942 p->encrypt_state = BTM_ACL_ENCRYPT_STATE_ENCRYPT_ON;
943 p->change_key_state = BTM_ACL_SWKEY_STATE_ENCRYPTION_ON;
947 else /* Set the state and wait for change link key */
949 p->change_key_state = BTM_ACL_SWKEY_STATE_ENCRYPTION_ON;
954 /* Set the switch_role_state to IDLE since the reply received from HCI */
955 /* regardless of its result either success or failed. */
956 if (p->change_key_state == BTM_ACL_SWKEY_STATE_IN_PROGRESS)
958 p->change_key_state = BTM_ACL_SWKEY_STATE_IDLE;
959 p->encrypt_state = BTM_ACL_ENCRYPT_STATE_IDLE;
962 if (btm_cb.devcb.p_chg_link_key_cb)
964 (*btm_cb.devcb.p_chg_link_key_cb)((void *)p_data);
965 btm_cb.devcb.p_chg_link_key_cb = NULL;
968 BTM_TRACE_ERROR("Change Link Key Complete Event: Handle 0x%02x, HCI Status 0x%02x",
969 handle, p_data->hci_status);
972 /*******************************************************************************
974 ** Function btm_acl_encrypt_change
976 ** Description This function is when encryption of the connection is
977 ** completed by the LM. Checks to see if a role switch or
978 ** change of link key was active and initiates or continues
979 ** process if needed.
983 *******************************************************************************/
984 void btm_acl_encrypt_change (UINT16 handle, UINT8 status, UINT8 encr_enable)
988 tBTM_SEC_DEV_REC *p_dev_rec;
989 #if (defined(BTM_BUSY_LEVEL_CHANGE_INCLUDED) && BTM_BUSY_LEVEL_CHANGE_INCLUDED == TRUE)
990 tBTM_BL_ROLE_CHG_DATA evt;
993 BTM_TRACE_DEBUG ("btm_acl_encrypt_change handle=%d status=%d encr_enabl=%d",
994 handle, status, encr_enable);
995 xx = btm_handle_to_acl_index(handle);
996 /* don't assume that we can never get a bad hci_handle */
997 if (xx < MAX_L2CAP_LINKS)
998 p = &btm_cb.acl_db[xx];
1002 /* Process Role Switch if active */
1003 if (p->switch_role_state == BTM_ACL_SWKEY_STATE_ENCRYPTION_OFF)
1005 /* if encryption turn off failed we still will try to switch role */
1008 p->switch_role_state = BTM_ACL_SWKEY_STATE_IDLE;
1009 p->encrypt_state = BTM_ACL_ENCRYPT_STATE_IDLE;
1013 p->switch_role_state = BTM_ACL_SWKEY_STATE_SWITCHING;
1014 p->encrypt_state = BTM_ACL_ENCRYPT_STATE_TEMP_FUNC;
1017 if (!btsnd_hcic_switch_role (p->remote_addr, (UINT8)!p->link_role))
1019 p->switch_role_state = BTM_ACL_SWKEY_STATE_IDLE;
1020 p->encrypt_state = BTM_ACL_ENCRYPT_STATE_IDLE;
1021 btm_acl_report_role_change(btm_cb.devcb.switch_role_ref_data.hci_status, p->remote_addr);
1023 #if BTM_DISC_DURING_RS == TRUE
1026 if ((p_dev_rec = btm_find_dev (p->remote_addr)) != NULL)
1027 p_dev_rec->rs_disc_pending = BTM_SEC_RS_PENDING;
1032 /* Finished enabling Encryption after role switch */
1033 else if (p->switch_role_state == BTM_ACL_SWKEY_STATE_ENCRYPTION_ON)
1035 p->switch_role_state = BTM_ACL_SWKEY_STATE_IDLE;
1036 p->encrypt_state = BTM_ACL_ENCRYPT_STATE_IDLE;
1037 btm_acl_report_role_change(btm_cb.devcb.switch_role_ref_data.hci_status, p->remote_addr);
1039 #if (defined(BTM_BUSY_LEVEL_CHANGE_INCLUDED) && BTM_BUSY_LEVEL_CHANGE_INCLUDED == TRUE)
1040 /* if role change event is registered, report it now */
1041 if (btm_cb.p_bl_changed_cb && (btm_cb.bl_evt_mask & BTM_BL_ROLE_CHG_MASK))
1043 evt.event = BTM_BL_ROLE_CHG_EVT;
1044 evt.new_role = btm_cb.devcb.switch_role_ref_data.role;
1045 evt.p_bda = btm_cb.devcb.switch_role_ref_data.remote_bd_addr;
1046 evt.hci_status = btm_cb.devcb.switch_role_ref_data.hci_status;
1047 (*btm_cb.p_bl_changed_cb)((tBTM_BL_EVENT_DATA *)&evt);
1049 BTM_TRACE_DEBUG("Role Switch Event: new_role 0x%02x, HCI Status 0x%02x, rs_st:%d",
1050 evt.new_role, evt.hci_status, p->switch_role_state);
1054 #if BTM_DISC_DURING_RS == TRUE
1055 /* If a disconnect is pending, issue it now that role switch has completed */
1056 if ((p_dev_rec = btm_find_dev (p->remote_addr)) != NULL)
1058 if (p_dev_rec->rs_disc_pending == BTM_SEC_DISC_PENDING)
1060 BTM_TRACE_WARNING("btm_acl_encrypt_change -> Issuing delayed HCI_Disconnect!!!");
1061 btsnd_hcic_disconnect(p_dev_rec->hci_handle, HCI_ERR_PEER_USER);
1063 BTM_TRACE_ERROR("btm_acl_encrypt_change: tBTM_SEC_DEV:0x%x rs_disc_pending=%d",
1064 (UINT32)p_dev_rec, p_dev_rec->rs_disc_pending);
1065 p_dev_rec->rs_disc_pending = BTM_SEC_RS_NOT_PENDING; /* reset flag */
1071 /* Process Change Link Key if active */
1072 if (p->change_key_state == BTM_ACL_SWKEY_STATE_ENCRYPTION_OFF)
1074 /* if encryption turn off failed we still will try to change link key */
1077 p->change_key_state = BTM_ACL_SWKEY_STATE_IDLE;
1078 p->encrypt_state = BTM_ACL_ENCRYPT_STATE_IDLE;
1082 p->encrypt_state = BTM_ACL_ENCRYPT_STATE_TEMP_FUNC;
1083 p->change_key_state = BTM_ACL_SWKEY_STATE_SWITCHING;
1086 if (!btsnd_hcic_change_link_key (p->hci_handle))
1088 p->encrypt_state = BTM_ACL_ENCRYPT_STATE_IDLE;
1089 p->change_key_state = BTM_ACL_SWKEY_STATE_IDLE;
1090 if (btm_cb.devcb.p_chg_link_key_cb)
1092 (*btm_cb.devcb.p_chg_link_key_cb)(&btm_cb.devcb.chg_link_key_ref_data);
1093 btm_cb.devcb.p_chg_link_key_cb = NULL;
1097 /* Finished enabling Encryption after changing link key */
1098 else if (p->change_key_state == BTM_ACL_SWKEY_STATE_ENCRYPTION_ON)
1100 p->encrypt_state = BTM_ACL_ENCRYPT_STATE_IDLE;
1101 p->change_key_state = BTM_ACL_SWKEY_STATE_IDLE;
1102 if (btm_cb.devcb.p_chg_link_key_cb)
1104 (*btm_cb.devcb.p_chg_link_key_cb)(&btm_cb.devcb.chg_link_key_ref_data);
1105 btm_cb.devcb.p_chg_link_key_cb = NULL;
1109 /*******************************************************************************
1111 ** Function BTM_SetLinkPolicy
1113 ** Description Create and send HCI "Write Policy Set" command
1115 ** Returns status of the operation
1117 *******************************************************************************/
1118 tBTM_STATUS BTM_SetLinkPolicy (BD_ADDR remote_bda, UINT16 *settings)
1121 UINT8 *localFeatures = BTM_ReadLocalFeatures();
1122 BTM_TRACE_DEBUG ("BTM_SetLinkPolicy");
1123 /* BTM_TRACE_API ("BTM_SetLinkPolicy: requested settings: 0x%04x", *settings ); */
1125 /* First, check if hold mode is supported */
1126 if (*settings != HCI_DISABLE_ALL_LM_MODES)
1128 if ( (*settings & HCI_ENABLE_MASTER_SLAVE_SWITCH) && (!HCI_SWITCH_SUPPORTED(localFeatures)) )
1130 *settings &= (~HCI_ENABLE_MASTER_SLAVE_SWITCH);
1131 BTM_TRACE_API ("BTM_SetLinkPolicy switch not supported (settings: 0x%04x)", *settings );
1133 if ( (*settings & HCI_ENABLE_HOLD_MODE) && (!HCI_HOLD_MODE_SUPPORTED(localFeatures)) )
1135 *settings &= (~HCI_ENABLE_HOLD_MODE);
1136 BTM_TRACE_API ("BTM_SetLinkPolicy hold not supported (settings: 0x%04x)", *settings );
1138 if ( (*settings & HCI_ENABLE_SNIFF_MODE) && (!HCI_SNIFF_MODE_SUPPORTED(localFeatures)) )
1140 *settings &= (~HCI_ENABLE_SNIFF_MODE);
1141 BTM_TRACE_API ("BTM_SetLinkPolicy sniff not supported (settings: 0x%04x)", *settings );
1143 if ( (*settings & HCI_ENABLE_PARK_MODE) && (!HCI_PARK_MODE_SUPPORTED(localFeatures)) )
1145 *settings &= (~HCI_ENABLE_PARK_MODE);
1146 BTM_TRACE_API ("BTM_SetLinkPolicy park not supported (settings: 0x%04x)", *settings );
1150 if ((p = btm_bda_to_acl(remote_bda, BT_TRANSPORT_BR_EDR)) != NULL)
1151 return(btsnd_hcic_write_policy_set (p->hci_handle, *settings) ? BTM_CMD_STARTED : BTM_NO_RESOURCES);
1153 /* If here, no BD Addr found */
1154 return(BTM_UNKNOWN_ADDR);
1157 /*******************************************************************************
1159 ** Function BTM_SetDefaultLinkPolicy
1161 ** Description Set the default value for HCI "Write Policy Set" command
1162 ** to use when an ACL link is created.
1166 *******************************************************************************/
1167 void BTM_SetDefaultLinkPolicy (UINT16 settings)
1169 UINT8 *localFeatures = BTM_ReadLocalFeatures();
1171 BTM_TRACE_DEBUG("BTM_SetDefaultLinkPolicy setting:0x%04x", settings);
1173 if((settings & HCI_ENABLE_MASTER_SLAVE_SWITCH) && (!HCI_SWITCH_SUPPORTED(localFeatures)))
1175 settings &= ~HCI_ENABLE_MASTER_SLAVE_SWITCH;
1176 BTM_TRACE_DEBUG("BTM_SetDefaultLinkPolicy switch not supported (settings: 0x%04x)", settings);
1178 if ((settings & HCI_ENABLE_HOLD_MODE) && (!HCI_HOLD_MODE_SUPPORTED(localFeatures)))
1180 settings &= ~HCI_ENABLE_HOLD_MODE;
1181 BTM_TRACE_DEBUG("BTM_SetDefaultLinkPolicy hold not supported (settings: 0x%04x)", settings);
1183 if ((settings & HCI_ENABLE_SNIFF_MODE) && (!HCI_SNIFF_MODE_SUPPORTED(localFeatures)))
1185 settings &= ~HCI_ENABLE_SNIFF_MODE;
1186 BTM_TRACE_DEBUG("BTM_SetDefaultLinkPolicy sniff not supported (settings: 0x%04x)", settings);
1188 if ((settings & HCI_ENABLE_PARK_MODE) && (!HCI_PARK_MODE_SUPPORTED(localFeatures)))
1190 settings &= ~HCI_ENABLE_PARK_MODE;
1191 BTM_TRACE_DEBUG("BTM_SetDefaultLinkPolicy park not supported (settings: 0x%04x)", settings);
1193 BTM_TRACE_DEBUG("Set DefaultLinkPolicy:0x%04x", settings);
1195 btm_cb.btm_def_link_policy = settings;
1197 /* Set the default Link Policy of the controller */
1198 btsnd_hcic_write_def_policy_set(settings);
1202 /*******************************************************************************
1204 ** Function BTM_ReadLinkPolicy
1206 ** Description This function is called to read the link policy settings.
1207 ** The address of link policy results are returned in the callback.
1208 ** (tBTM_LNK_POLICY_RESULTS)
1210 ** Returns status of the operation
1212 *******************************************************************************/
1213 tBTM_STATUS BTM_ReadLinkPolicy (BD_ADDR remote_bda, tBTM_CMPL_CB *p_cb)
1217 BTM_TRACE_API ("BTM_ReadLinkPolicy: RemBdAddr: %02x%02x%02x%02x%02x%02x",
1218 remote_bda[0], remote_bda[1], remote_bda[2],
1219 remote_bda[3], remote_bda[4], remote_bda[5]);
1221 /* If someone already waiting on the version, do not allow another */
1222 if (btm_cb.devcb.p_rlinkp_cmpl_cb)
1225 p = btm_bda_to_acl(remote_bda, BT_TRANSPORT_BR_EDR);
1226 if (p != (tACL_CONN *)NULL)
1228 btu_start_timer (&btm_cb.devcb.rlinkp_timer, BTU_TTYPE_BTM_ACL, BTM_DEV_REPLY_TIMEOUT);
1229 btm_cb.devcb.p_rlinkp_cmpl_cb = p_cb;
1231 if (!btsnd_hcic_read_policy_set (p->hci_handle))
1233 btu_stop_timer (&btm_cb.devcb.rlinkp_timer);
1234 btm_cb.devcb.p_rlinkp_cmpl_cb = NULL;
1235 return(BTM_NO_RESOURCES);
1238 return(BTM_CMD_STARTED);
1241 /* If here, no BD Addr found */
1242 return(BTM_UNKNOWN_ADDR);
1246 /*******************************************************************************
1248 ** Function btm_read_link_policy_complete
1250 ** Description This function is called when the command complete message
1251 ** is received from the HCI for the read local link policy request.
1255 *******************************************************************************/
1256 void btm_read_link_policy_complete (UINT8 *p)
1258 tBTM_CMPL_CB *p_cb = btm_cb.devcb.p_rlinkp_cmpl_cb;
1259 tBTM_LNK_POLICY_RESULTS lnkpol;
1261 tACL_CONN *p_acl_cb = &btm_cb.acl_db[0];
1263 BTM_TRACE_DEBUG ("btm_read_link_policy_complete");
1264 btu_stop_timer (&btm_cb.devcb.rlinkp_timer);
1266 /* If there was a callback address for read local version, call it */
1267 btm_cb.devcb.p_rlinkp_cmpl_cb = NULL;
1271 STREAM_TO_UINT8 (lnkpol.hci_status, p);
1273 if (lnkpol.hci_status == HCI_SUCCESS)
1275 lnkpol.status = BTM_SUCCESS;
1277 STREAM_TO_UINT16 (handle, p);
1279 STREAM_TO_UINT16 (lnkpol.settings, p);
1281 /* Search through the list of active channels for the correct BD Addr */
1282 for (index = 0; index < MAX_L2CAP_LINKS; index++, p_acl_cb++)
1284 if ((p_acl_cb->in_use) && (handle == p_acl_cb->hci_handle))
1286 memcpy (lnkpol.rem_bda, p_acl_cb->remote_addr, BD_ADDR_LEN);
1292 lnkpol.status = BTM_ERR_PROCESSING;
1299 /*******************************************************************************
1301 ** Function btm_read_remote_version_complete
1303 ** Description This function is called when the command complete message
1304 ** is received from the HCI for the remote version info.
1308 *******************************************************************************/
1309 void btm_read_remote_version_complete (UINT8 *p)
1311 tACL_CONN *p_acl_cb = &btm_cb.acl_db[0];
1315 BTM_TRACE_DEBUG ("btm_read_remote_version_complete");
1316 STREAM_TO_UINT8 (status, p);
1317 if (status == HCI_SUCCESS)
1319 STREAM_TO_UINT16 (handle, p);
1321 /* Look up the connection by handle and copy features */
1322 for (xx = 0; xx < MAX_L2CAP_LINKS; xx++, p_acl_cb++)
1324 if ((p_acl_cb->in_use) && (p_acl_cb->hci_handle == handle))
1326 STREAM_TO_UINT8 (p_acl_cb->lmp_version, p);
1327 STREAM_TO_UINT16 (p_acl_cb->manufacturer, p);
1328 STREAM_TO_UINT16 (p_acl_cb->lmp_subversion, p);
1336 /*******************************************************************************
1338 ** Function btm_process_remote_ext_features
1340 ** Description Local function called to process all extended features pages
1341 ** read from a remote device.
1345 *******************************************************************************/
1346 void btm_process_remote_ext_features (tACL_CONN *p_acl_cb, UINT8 num_read_pages)
1348 UINT16 handle = p_acl_cb->hci_handle;
1349 tBTM_SEC_DEV_REC *p_dev_rec = btm_find_dev_by_handle (handle);
1352 BTM_TRACE_DEBUG ("btm_process_remote_ext_features");
1354 /* Make sure we have the record to save remote features information */
1355 if (p_dev_rec == NULL)
1357 /* Get a new device; might be doing dedicated bonding */
1358 p_dev_rec = btm_find_or_alloc_dev (p_acl_cb->remote_addr);
1361 p_acl_cb->num_read_pages = num_read_pages;
1362 p_dev_rec->num_read_pages = num_read_pages;
1364 /* Process the pages one by one */
1365 for (page_idx = 0; page_idx < num_read_pages; page_idx++)
1367 btm_process_remote_ext_features_page (p_acl_cb, p_dev_rec, page_idx);
1372 /*******************************************************************************
1374 ** Function btm_process_remote_ext_features_page
1376 ** Description Local function called to process the information located
1377 ** in the specific extended features page read from a remote device.
1381 *******************************************************************************/
1382 void btm_process_remote_ext_features_page (tACL_CONN *p_acl_cb, tBTM_SEC_DEV_REC *p_dev_rec,
1388 handle = p_acl_cb->hci_handle;
1390 memcpy (p_dev_rec->features[page_idx], p_acl_cb->peer_lmp_features[page_idx],
1391 HCI_FEATURE_BYTES_PER_PAGE);
1395 /* Extended (Legacy) Page 0 */
1396 case HCI_EXT_FEATURES_PAGE_0:
1397 /* Page 0 indicates Controller support for SSP */
1398 if (btm_cb.security_mode < BTM_SEC_MODE_SP ||
1399 !HCI_SIMPLE_PAIRING_SUPPORTED(p_dev_rec->features[HCI_EXT_FEATURES_PAGE_0]))
1401 req_pend = (p_dev_rec->sm4 & BTM_SM4_REQ_PEND);
1402 p_dev_rec->sm4 = BTM_SM4_KNOWN;
1405 l2cu_resubmit_pending_sec_req (p_dev_rec->bd_addr);
1410 /* Extended Page 1 */
1411 case HCI_EXT_FEATURES_PAGE_1:
1412 /* Page 1 indicates Host support for SSP and SC */
1413 req_pend = (p_dev_rec->sm4 & BTM_SM4_REQ_PEND);
1415 if (btm_cb.security_mode == BTM_SEC_MODE_SP
1416 && HCI_SSP_HOST_SUPPORTED(p_dev_rec->features[HCI_EXT_FEATURES_PAGE_1])
1417 && HCI_SIMPLE_PAIRING_SUPPORTED(p_dev_rec->features[HCI_EXT_FEATURES_PAGE_0]))
1419 p_dev_rec->sm4 = BTM_SM4_TRUE;
1423 p_dev_rec->sm4 = BTM_SM4_KNOWN;
1426 BTM_TRACE_API ("ext_features_complt page_num:%d f[0]:x%02x, sm4:%x, pend:%d",
1427 HCI_EXT_FEATURES_PAGE_1, *(p_dev_rec->features[HCI_EXT_FEATURES_PAGE_1]),
1428 p_dev_rec->sm4, req_pend);
1431 l2cu_resubmit_pending_sec_req (p_dev_rec->bd_addr);
1435 /* Extended Page 2 */
1436 case HCI_EXT_FEATURES_PAGE_2:
1437 /* Page 2 indicates Ping support*/
1441 BTM_TRACE_ERROR("btm_process_remote_ext_features_page page=%d unexpected", page_idx);
1447 /*******************************************************************************
1449 ** Function btm_read_remote_features
1451 ** Description Local function called to send a read remote supported features/
1452 ** remote extended features page[0].
1456 *******************************************************************************/
1457 void btm_read_remote_features (UINT16 handle)
1460 tACL_CONN *p_acl_cb;
1462 BTM_TRACE_DEBUG("btm_read_remote_features() handle: %d", handle);
1464 if ((acl_idx = btm_handle_to_acl_index(handle)) >= MAX_L2CAP_LINKS)
1466 BTM_TRACE_ERROR("btm_read_remote_features handle=%d invalid", handle);
1470 p_acl_cb = &btm_cb.acl_db[acl_idx];
1471 p_acl_cb->num_read_pages = 0;
1472 memset (p_acl_cb->peer_lmp_features, 0, sizeof(p_acl_cb->peer_lmp_features));
1474 /* first send read remote supported features HCI command */
1475 /* because we don't know whether the remote support extended feature command */
1476 btsnd_hcic_rmt_features_req (handle);
1480 /*******************************************************************************
1482 ** Function btm_read_remote_ext_features
1484 ** Description Local function called to send a read remote extended features
1488 *******************************************************************************/
1489 void btm_read_remote_ext_features (UINT16 handle, UINT8 page_number)
1491 BTM_TRACE_DEBUG("btm_read_remote_ext_features() handle: %d page: %d", handle, page_number);
1493 btsnd_hcic_rmt_ext_features(handle, page_number);
1497 /*******************************************************************************
1499 ** Function btm_read_remote_features_complete
1501 ** Description This function is called when the remote supported features
1502 ** complete event is received from the HCI.
1506 *******************************************************************************/
1507 void btm_read_remote_features_complete (UINT8 *p)
1509 tACL_CONN *p_acl_cb;
1514 BTM_TRACE_DEBUG ("btm_read_remote_features_complete");
1515 STREAM_TO_UINT8 (status, p);
1517 if (status != HCI_SUCCESS)
1519 BTM_TRACE_ERROR ("btm_read_remote_features_complete failed (status 0x%02x)", status);
1523 STREAM_TO_UINT16 (handle, p);
1525 if ((acl_idx = btm_handle_to_acl_index(handle)) >= MAX_L2CAP_LINKS)
1527 BTM_TRACE_ERROR("btm_read_remote_features_complete handle=%d invalid", handle);
1531 p_acl_cb = &btm_cb.acl_db[acl_idx];
1533 /* Copy the received features page */
1534 STREAM_TO_ARRAY(p_acl_cb->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0], p,
1535 HCI_FEATURE_BYTES_PER_PAGE);
1537 if ((HCI_LMP_EXTENDED_SUPPORTED(p_acl_cb->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0])) &&
1538 (HCI_READ_REMOTE_EXT_FEATURES_SUPPORTED(btm_cb.devcb.supported_cmds)))
1540 /* if the remote controller has extended features and local controller supports
1541 ** HCI_Read_Remote_Extended_Features command then start reading these feature starting
1542 ** with extended features page 1 */
1543 BTM_TRACE_DEBUG ("Start reading remote extended features");
1544 btm_read_remote_ext_features(handle, HCI_EXT_FEATURES_PAGE_1);
1548 /* Remote controller has no extended features. Process remote controller supported features
1549 (features page HCI_EXT_FEATURES_PAGE_0). */
1550 btm_process_remote_ext_features (p_acl_cb, 1);
1552 /* Continue with HCI connection establishment */
1553 btm_establish_continue (p_acl_cb);
1556 /*******************************************************************************
1558 ** Function btm_read_remote_ext_features_complete
1560 ** Description This function is called when the remote extended features
1561 ** complete event is received from the HCI.
1565 *******************************************************************************/
1566 void btm_read_remote_ext_features_complete (UINT8 *p)
1568 tACL_CONN *p_acl_cb;
1569 UINT8 status, page_num, max_page;
1573 BTM_TRACE_DEBUG ("btm_read_remote_ext_features_complete");
1575 STREAM_TO_UINT8 (status, p);
1576 STREAM_TO_UINT16 (handle, p);
1577 STREAM_TO_UINT8 (page_num, p);
1578 STREAM_TO_UINT8 (max_page, p);
1580 /* Validate parameters */
1581 if ((acl_idx = btm_handle_to_acl_index(handle)) >= MAX_L2CAP_LINKS)
1583 BTM_TRACE_ERROR("btm_read_remote_ext_features_complete handle=%d invalid", handle);
1587 if (max_page > HCI_EXT_FEATURES_PAGE_MAX)
1589 BTM_TRACE_ERROR("btm_read_remote_ext_features_complete page=%d unknown", max_page);
1593 p_acl_cb = &btm_cb.acl_db[acl_idx];
1595 /* Copy the received features page */
1596 STREAM_TO_ARRAY(p_acl_cb->peer_lmp_features[page_num], p, HCI_FEATURE_BYTES_PER_PAGE);
1598 /* If there is the next remote features page and
1599 * we have space to keep this page data - read this page */
1600 if ((page_num < max_page) && (page_num < HCI_EXT_FEATURES_PAGE_MAX))
1603 BTM_TRACE_DEBUG("BTM reads next remote extended features page (%d)", page_num);
1604 btm_read_remote_ext_features (handle, page_num);
1608 /* Reading of remote feature pages is complete */
1609 BTM_TRACE_DEBUG("BTM reached last remote extended features page (%d)", page_num);
1611 /* Process the pages */
1612 btm_process_remote_ext_features (p_acl_cb, (UINT8) (page_num + 1));
1614 /* Continue with HCI connection establishment */
1615 btm_establish_continue (p_acl_cb);
1618 /*******************************************************************************
1620 ** Function btm_read_remote_ext_features_failed
1622 ** Description This function is called when the remote extended features
1623 ** complete event returns a failed status.
1627 *******************************************************************************/
1628 void btm_read_remote_ext_features_failed (UINT8 status, UINT16 handle)
1630 tACL_CONN *p_acl_cb;
1633 BTM_TRACE_WARNING ("btm_read_remote_ext_features_failed (status 0x%02x) for handle %d",
1636 if ((acl_idx = btm_handle_to_acl_index(handle)) >= MAX_L2CAP_LINKS)
1638 BTM_TRACE_ERROR("btm_read_remote_ext_features_failed handle=%d invalid", handle);
1642 p_acl_cb = &btm_cb.acl_db[acl_idx];
1644 /* Process supported features only */
1645 btm_process_remote_ext_features (p_acl_cb, 1);
1647 /* Continue HCI connection establishment */
1648 btm_establish_continue (p_acl_cb);
1651 /*******************************************************************************
1653 ** Function btm_establish_continue
1655 ** Description This function is called when the command complete message
1656 ** is received from the HCI for the read local link policy request.
1660 *******************************************************************************/
1661 void btm_establish_continue (tACL_CONN *p_acl_cb)
1663 #if (defined(BTM_BUSY_LEVEL_CHANGE_INCLUDED) && BTM_BUSY_LEVEL_CHANGE_INCLUDED == TRUE)
1664 tBTM_BL_EVENT_DATA evt_data;
1666 BTM_TRACE_DEBUG ("btm_establish_continue");
1667 #if (!defined(BTM_BYPASS_EXTRA_ACL_SETUP) || BTM_BYPASS_EXTRA_ACL_SETUP == FALSE)
1668 #if (defined BLE_INCLUDED && BLE_INCLUDED == TRUE)
1669 if (p_acl_cb->transport == BT_TRANSPORT_BR_EDR)
1672 /* For now there are a some devices that do not like sending */
1673 /* commands events and data at the same time. */
1674 /* Set the packet types to the default allowed by the device */
1675 btm_set_packet_types (p_acl_cb, btm_cb.btm_acl_pkt_types_supported);
1677 if (btm_cb.btm_def_link_policy)
1678 BTM_SetLinkPolicy (p_acl_cb->remote_addr, &btm_cb.btm_def_link_policy);
1681 p_acl_cb->link_up_issued = TRUE;
1683 /* If anyone cares, tell him database changed */
1684 #if (defined(BTM_BUSY_LEVEL_CHANGE_INCLUDED) && BTM_BUSY_LEVEL_CHANGE_INCLUDED == TRUE)
1685 if (btm_cb.p_bl_changed_cb)
1687 evt_data.event = BTM_BL_CONN_EVT;
1688 evt_data.conn.p_bda = p_acl_cb->remote_addr;
1689 evt_data.conn.p_bdn = p_acl_cb->remote_name;
1690 evt_data.conn.p_dc = p_acl_cb->remote_dc;
1691 evt_data.conn.p_features = p_acl_cb->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0];
1692 #if BLE_INCLUDED == TRUE
1693 evt_data.conn.handle = p_acl_cb->hci_handle;
1694 evt_data.conn.transport = p_acl_cb->transport;
1697 (*btm_cb.p_bl_changed_cb)(&evt_data);
1699 btm_acl_update_busy_level (BTM_BLI_ACL_UP_EVT);
1701 if (btm_cb.p_acl_changed_cb)
1702 #if BLE_INCLUDED == TRUE
1703 (*btm_cb.p_acl_changed_cb) (p_acl_cb->remote_addr,
1704 p_acl_cb->remote_dc,
1705 p_acl_cb->remote_name,
1706 p_acl_cb->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0],
1708 p_acl_cb->hci_handle,
1709 p_acl_cb->transport);
1711 (*btm_cb.p_acl_changed_cb) (p_acl_cb->remote_addr,
1712 p_acl_cb->remote_dc,
1713 p_acl_cb->remote_name,
1714 p_acl_cb->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0],
1723 /*******************************************************************************
1725 ** Function BTM_SetDefaultLinkSuperTout
1727 ** Description Set the default value for HCI "Write Link Supervision Timeout"
1728 ** command to use when an ACL link is created.
1732 *******************************************************************************/
1733 void BTM_SetDefaultLinkSuperTout (UINT16 timeout)
1735 BTM_TRACE_DEBUG ("BTM_SetDefaultLinkSuperTout");
1736 btm_cb.btm_def_link_super_tout = timeout;
1739 /*******************************************************************************
1741 ** Function BTM_GetLinkSuperTout
1743 ** Description Read the link supervision timeout value of the connection
1745 ** Returns status of the operation
1747 *******************************************************************************/
1748 tBTM_STATUS BTM_GetLinkSuperTout (BD_ADDR remote_bda, UINT16 *p_timeout)
1750 tACL_CONN *p = btm_bda_to_acl(remote_bda, BT_TRANSPORT_BR_EDR);
1752 BTM_TRACE_DEBUG ("BTM_GetLinkSuperTout");
1753 if (p != (tACL_CONN *)NULL)
1755 *p_timeout = p->link_super_tout;
1756 return(BTM_SUCCESS);
1758 /* If here, no BD Addr found */
1759 return(BTM_UNKNOWN_ADDR);
1763 /*******************************************************************************
1765 ** Function BTM_SetLinkSuperTout
1767 ** Description Create and send HCI "Write Link Supervision Timeout" command
1769 ** Returns status of the operation
1771 *******************************************************************************/
1772 tBTM_STATUS BTM_SetLinkSuperTout (BD_ADDR remote_bda, UINT16 timeout)
1774 tACL_CONN *p = btm_bda_to_acl(remote_bda, BT_TRANSPORT_BR_EDR);
1776 BTM_TRACE_DEBUG ("BTM_SetLinkSuperTout");
1777 if (p != (tACL_CONN *)NULL)
1779 p->link_super_tout = timeout;
1781 /* Only send if current role is Master; 2.0 spec requires this */
1782 if (p->link_role == BTM_ROLE_MASTER)
1784 if (!btsnd_hcic_write_link_super_tout (LOCAL_BR_EDR_CONTROLLER_ID,
1785 p->hci_handle, timeout))
1786 return(BTM_NO_RESOURCES);
1788 return(BTM_CMD_STARTED);
1791 return(BTM_SUCCESS);
1794 /* If here, no BD Addr found */
1795 return(BTM_UNKNOWN_ADDR);
1798 /*******************************************************************************
1800 ** Function BTM_RegForLstoEvt
1802 ** Description register for the HCI "Link Supervision Timeout Change" event
1806 *******************************************************************************/
1807 void BTM_RegForLstoEvt (tBTM_LSTO_CBACK *p_cback)
1809 BTM_TRACE_DEBUG ("BTM_RegForLstoEvt");
1810 btm_cb.p_lsto_cback = p_cback;
1813 /*******************************************************************************
1815 ** Function btm_proc_lsto_evt
1817 ** Description process the HCI "Link Supervision Timeout Change" event
1821 *******************************************************************************/
1822 void btm_proc_lsto_evt(UINT16 handle, UINT16 timeout)
1826 BTM_TRACE_DEBUG ("btm_proc_lsto_evt");
1827 if (btm_cb.p_lsto_cback)
1829 /* Look up the connection by handle and set the current mode */
1830 xx = btm_handle_to_acl_index(handle);
1832 /* don't assume that we can never get a bad hci_handle */
1833 if (xx < MAX_L2CAP_LINKS)
1835 (*btm_cb.p_lsto_cback)(btm_cb.acl_db[xx].remote_addr, timeout);
1840 #if BTM_PWR_MGR_INCLUDED == FALSE
1841 /*******************************************************************************
1843 ** Function BTM_SetHoldMode
1845 ** Description This function is called to set a connection into hold mode.
1846 ** A check is made if the connection is in sniff or park mode,
1847 ** and if yes, the hold mode is ignored.
1849 ** Returns status of the operation
1851 *******************************************************************************/
1852 tBTM_STATUS BTM_SetHoldMode (BD_ADDR remote_bda, UINT16 min_interval, UINT16 max_interval)
1856 BTM_TRACE_DEBUG ("BTM_SetHoldMode");
1857 /* First, check if hold mode is supported */
1858 if (!HCI_HOLD_MODE_SUPPORTED(BTM_ReadLocalFeatures()))
1859 return(BTM_MODE_UNSUPPORTED);
1861 p = btm_bda_to_acl(remote_bda, BT_TRANSPORT_BR_EDR);
1862 if (p != (tACL_CONN *)NULL)
1864 /* If the connection is in park or sniff mode, forget about holding it */
1865 if (p->mode != BTM_ACL_MODE_NORMAL)
1866 return(BTM_SUCCESS);
1868 if (!btsnd_hcic_hold_mode (p->hci_handle, max_interval, min_interval))
1869 return(BTM_NO_RESOURCES);
1871 return(BTM_CMD_STARTED);
1874 /* If here, no BD Addr found */
1875 return(BTM_UNKNOWN_ADDR);
1879 /*******************************************************************************
1881 ** Function BTM_SetSniffMode
1883 ** Description This function is called to set a connection into sniff mode.
1884 ** A check is made if the connection is already in sniff or park
1885 ** mode, and if yes, the sniff mode is ignored.
1887 ** Returns status of the operation
1889 *******************************************************************************/
1890 tBTM_STATUS BTM_SetSniffMode (BD_ADDR remote_bda, UINT16 min_period, UINT16 max_period,
1891 UINT16 attempt, UINT16 timeout)
1894 BTM_TRACE_DEBUG ("BTM_SetSniffMode");
1895 /* First, check if sniff mode is supported */
1896 if (!HCI_SNIFF_MODE_SUPPORTED(BTM_ReadLocalFeatures()))
1897 return(BTM_MODE_UNSUPPORTED);
1899 p = btm_bda_to_acl(remote_bda, BT_TRANSPORT_BR_EDR);
1900 if (p != (tACL_CONN *)NULL)
1902 /* If the connection is in park mode, forget about sniffing it */
1903 if (p->mode != BTM_ACL_MODE_NORMAL)
1904 return(BTM_WRONG_MODE);
1906 if (!btsnd_hcic_sniff_mode (p->hci_handle, max_period,
1907 min_period, attempt, timeout))
1908 return(BTM_NO_RESOURCES);
1910 return(BTM_CMD_STARTED);
1913 /* If here, no BD Addr found */
1914 return(BTM_UNKNOWN_ADDR);
1920 /*******************************************************************************
1922 ** Function BTM_CancelSniffMode
1924 ** Description This function is called to put a connection out of sniff mode.
1925 ** A check is made if the connection is already in sniff mode,
1926 ** and if not, the cancel sniff mode is ignored.
1928 ** Returns status of the operation
1930 *******************************************************************************/
1931 tBTM_STATUS BTM_CancelSniffMode (BD_ADDR remote_bda)
1933 tACL_CONN *p = btm_bda_to_acl(remote_bda, BT_TRANSPORT_BR_EDR);
1934 BTM_TRACE_DEBUG ("BTM_CancelSniffMode ");
1935 if (p == (tACL_CONN *)NULL)
1936 return(BTM_UNKNOWN_ADDR);
1938 /* If the connection is not in sniff mode, cannot cancel */
1939 if (p->mode != BTM_ACL_MODE_SNIFF)
1940 return(BTM_WRONG_MODE);
1942 if (!btsnd_hcic_exit_sniff_mode (p->hci_handle))
1943 return(BTM_NO_RESOURCES);
1945 return(BTM_CMD_STARTED);
1949 /*******************************************************************************
1951 ** Function BTM_SetParkMode
1953 ** Description This function is called to set a connection into park mode.
1954 ** A check is made if the connection is already in sniff or park
1955 ** mode, and if yes, the park mode is ignored.
1957 ** Returns status of the operation
1959 *******************************************************************************/
1960 tBTM_STATUS BTM_SetParkMode (BD_ADDR remote_bda, UINT16 beacon_min_period, UINT16 beacon_max_period)
1964 BTM_TRACE_DEBUG ("BTM_SetParkMode");
1965 /* First, check if park mode is supported */
1966 if (!HCI_PARK_MODE_SUPPORTED(BTM_ReadLocalFeatures()))
1967 return(BTM_MODE_UNSUPPORTED);
1969 p = btm_bda_to_acl(remote_bda, BT_TRANSPORT_BR_EDR);
1970 if (p != (tACL_CONN *)NULL)
1972 /* If the connection is in sniff mode, forget about parking it */
1973 if (p->mode != BTM_ACL_MODE_NORMAL)
1974 return(BTM_WRONG_MODE);
1976 /* no park mode if SCO exists -- CR#1982, 1.1 errata 1124
1977 command status event should be returned /w error code 0x0C "Command Disallowed"
1980 if (!btsnd_hcic_park_mode (p->hci_handle,
1981 beacon_max_period, beacon_min_period))
1982 return(BTM_NO_RESOURCES);
1984 return(BTM_CMD_STARTED);
1987 /* If here, no BD Addr found */
1988 return(BTM_UNKNOWN_ADDR);
1991 /*******************************************************************************
1993 ** Function BTM_CancelParkMode
1995 ** Description This function is called to put a connection out of park mode.
1996 ** A check is made if the connection is already in park mode,
1997 ** and if not, the cancel sniff mode is ignored.
1999 ** Returns status of the operation
2001 *******************************************************************************/
2002 tBTM_STATUS BTM_CancelParkMode (BD_ADDR remote_bda)
2006 BTM_TRACE_DEBUG ("BTM_CancelParkMode");
2007 p = btm_bda_to_acl(remote_bda, BT_TRANSPORT_BR_EDR);
2008 if (p != (tACL_CONN *)NULL)
2010 /* If the connection is not in park mode, cannot cancel */
2011 if (p->mode != BTM_ACL_MODE_PARK)
2012 return(BTM_WRONG_MODE);
2014 if (!btsnd_hcic_exit_park_mode (p->hci_handle))
2015 return(BTM_NO_RESOURCES);
2017 return(BTM_CMD_STARTED);
2020 /* If here, no BD Addr found */
2021 return(BTM_UNKNOWN_ADDR);
2023 #endif /* BTM_PWR_MGR_INCLUDED == FALSE */
2026 /*******************************************************************************
2028 ** Function BTM_SetPacketTypes
2030 ** Description This function is set the packet types used for a specific
2033 ** Returns status of the operation
2035 *******************************************************************************/
2036 tBTM_STATUS BTM_SetPacketTypes (BD_ADDR remote_bda, UINT16 pkt_types)
2039 BTM_TRACE_DEBUG ("BTM_SetPacketTypes");
2041 if ((p = btm_bda_to_acl(remote_bda, BT_TRANSPORT_BR_EDR)) != NULL)
2042 return(btm_set_packet_types (p, pkt_types));
2044 /* If here, no BD Addr found */
2045 return(BTM_UNKNOWN_ADDR);
2049 /*******************************************************************************
2051 ** Function BTM_ReadPacketTypes
2053 ** Description This function is set the packet types used for a specific
2056 ** Returns packet types supported for the connection, or 0 if no BD address
2058 *******************************************************************************/
2059 UINT16 BTM_ReadPacketTypes (BD_ADDR remote_bda)
2063 BTM_TRACE_DEBUG ("BTM_ReadPacketTypes");
2064 p = btm_bda_to_acl(remote_bda, BT_TRANSPORT_BR_EDR);
2065 if (p != (tACL_CONN *)NULL)
2067 return(p->pkt_types_mask);
2070 /* If here, no BD Addr found */
2075 /*******************************************************************************
2077 ** Function BTM_ReadAclMode
2079 ** Description This returns the current mode for a specific
2082 ** Input Param remote_bda - device address of desired ACL connection
2084 ** Output Param p_mode - address where the current mode is copied into.
2085 ** BTM_ACL_MODE_NORMAL
2086 ** BTM_ACL_MODE_HOLD
2087 ** BTM_ACL_MODE_SNIFF
2088 ** BTM_ACL_MODE_PARK
2089 ** (valid only if return code is BTM_SUCCESS)
2091 ** Returns BTM_SUCCESS if successful,
2092 ** BTM_UNKNOWN_ADDR if bd addr is not active or bad
2094 *******************************************************************************/
2095 #if BTM_PWR_MGR_INCLUDED == FALSE
2096 tBTM_STATUS BTM_ReadAclMode (BD_ADDR remote_bda, UINT8 *p_mode)
2100 BTM_TRACE_API ("BTM_ReadAclMode: RemBdAddr: %02x%02x%02x%02x%02x%02x",
2101 remote_bda[0], remote_bda[1], remote_bda[2],
2102 remote_bda[3], remote_bda[4], remote_bda[5]);
2104 p = btm_bda_to_acl(remote_bda, BT_TRANSPORT_BR_EDR);
2105 if (p != (tACL_CONN *)NULL)
2108 return(BTM_SUCCESS);
2111 /* If here, no BD Addr found */
2112 return(BTM_UNKNOWN_ADDR);
2114 #endif /* BTM_PWR_MGR_INCLUDED == FALSE */
2116 /*******************************************************************************
2118 ** Function BTM_ReadClockOffset
2120 ** Description This returns the clock offset for a specific
2123 ** Input Param remote_bda - device address of desired ACL connection
2125 ** Returns clock-offset or 0 if unknown
2127 *******************************************************************************/
2128 UINT16 BTM_ReadClockOffset (BD_ADDR remote_bda)
2132 BTM_TRACE_API ("BTM_ReadClockOffset: RemBdAddr: %02x%02x%02x%02x%02x%02x",
2133 remote_bda[0], remote_bda[1], remote_bda[2],
2134 remote_bda[3], remote_bda[4], remote_bda[5]);
2136 if ( (p = btm_bda_to_acl(remote_bda, BT_TRANSPORT_BR_EDR)) != NULL)
2137 return(p->clock_offset);
2139 /* If here, no BD Addr found */
2143 /*******************************************************************************
2145 ** Function BTM_IsAclConnectionUp
2147 ** Description This function is called to check if an ACL connection exists
2148 ** to a specific remote BD Address.
2150 ** Returns TRUE if connection is up, else FALSE.
2152 *******************************************************************************/
2153 BOOLEAN BTM_IsAclConnectionUp (BD_ADDR remote_bda, tBT_TRANSPORT transport)
2157 BTM_TRACE_API ("BTM_IsAclConnectionUp: RemBdAddr: %02x%02x%02x%02x%02x%02x",
2158 remote_bda[0], remote_bda[1], remote_bda[2],
2159 remote_bda[3], remote_bda[4], remote_bda[5]);
2161 p = btm_bda_to_acl(remote_bda, transport);
2162 if (p != (tACL_CONN *)NULL)
2167 /* If here, no BD Addr found */
2171 /*******************************************************************************
2173 ** Function BTM_GetNumAclLinks
2175 ** Description This function is called to count the number of
2176 ** ACL links that are active.
2178 ** Returns UINT16 Number of active ACL links
2180 *******************************************************************************/
2181 UINT16 BTM_GetNumAclLinks (void)
2183 #if (defined(BTM_BUSY_LEVEL_CHANGE_INCLUDED) && BTM_BUSY_LEVEL_CHANGE_INCLUDED == TRUE)
2184 return(UINT16)btm_cb.num_acl;
2186 tACL_CONN *p = &btm_cb.acl_db[0];
2188 BTM_TRACE_DEBUG ("BTM_GetNumAclLinks");
2189 for (xx = yy = 0; xx < MAX_L2CAP_LINKS; xx++, p++)
2199 /*******************************************************************************
2201 ** Function BTM_GetNumLeLinks
2203 ** Description This function is called to count the number of
2204 ** LE ACL links that are active.
2206 ** Returns UINT16 Number of active LE links
2208 *******************************************************************************/
2209 UINT16 BTM_GetNumLeLinks (void)
2213 #if BLE_INCLUDED == TRUE
2214 tACL_CONN *p = &btm_cb.acl_db[0];
2216 BTM_TRACE_DEBUG ("BTM_GetNumLeLinks");
2217 for (xx = yy = 0; xx < MAX_L2CAP_LINKS; xx++, p++)
2219 if ((p->in_use) &&(p->transport == BT_TRANSPORT_LE))
2227 /*******************************************************************************
2229 ** Function btm_get_acl_disc_reason_code
2231 ** Description This function is called to get the disconnection reason code
2232 ** returned by the HCI at disconnection complete event.
2234 ** Returns TRUE if connection is up, else FALSE.
2236 *******************************************************************************/
2237 UINT16 btm_get_acl_disc_reason_code (void)
2239 UINT8 res = btm_cb.acl_disc_reason;
2240 BTM_TRACE_DEBUG ("btm_get_acl_disc_reason_code");
2245 /*******************************************************************************
2247 ** Function BTM_GetHCIConnHandle
2249 ** Description This function is called to get the handle for an ACL connection
2250 ** to a specific remote BD Address.
2252 ** Returns the handle of the connection, or 0xFFFF if none.
2254 *******************************************************************************/
2255 UINT16 BTM_GetHCIConnHandle (BD_ADDR remote_bda, tBT_TRANSPORT transport)
2258 BTM_TRACE_DEBUG ("BTM_GetHCIConnHandle");
2259 p = btm_bda_to_acl(remote_bda, transport);
2260 if (p != (tACL_CONN *)NULL)
2262 return(p->hci_handle);
2265 /* If here, no BD Addr found */
2269 #if BTM_PWR_MGR_INCLUDED == FALSE
2270 /*******************************************************************************
2272 ** Function btm_process_mode_change
2274 ** Description This function is called when an HCI mode change event occurs.
2276 ** Input Parms hci_status - status of the event (HCI_SUCCESS if no errors)
2277 ** hci_handle - connection handle associated with the change
2278 ** mode - HCI_MODE_ACTIVE, HCI_MODE_HOLD, HCI_MODE_SNIFF, or HCI_MODE_PARK
2279 ** interval - number of baseband slots (meaning depends on mode)
2283 *******************************************************************************/
2284 void btm_process_mode_change (UINT8 hci_status, UINT16 hci_handle, UINT8 mode, UINT16 interval)
2288 BTM_TRACE_DEBUG ("btm_process_mode_change");
2289 if (hci_status != HCI_SUCCESS)
2291 BTM_TRACE_WARNING ("BTM: HCI Mode Change Error Status: 0x%02x", hci_status);
2294 /* Look up the connection by handle and set the current mode */
2295 xx = btm_handle_to_acl_index(hci_handle);
2297 /* don't assume that we can never get a bad hci_handle */
2298 if (xx >= MAX_L2CAP_LINKS)
2301 p = &btm_cb.acl_db[xx];
2303 /* If status is not success mode does not mean anything */
2304 if (hci_status == HCI_SUCCESS)
2307 /* If mode change was because of an active role switch or change link key */
2308 btm_cont_rswitch_or_chglinkkey(p, btm_find_dev(p->remote_addr), hci_status);
2310 #endif /* BTM_PWR_MGR_INCLUDED == FALSE */
2312 /*******************************************************************************
2314 ** Function btm_process_clk_off_comp_evt
2316 ** Description This function is called when clock offset command completes.
2318 ** Input Parms hci_handle - connection handle associated with the change
2323 *******************************************************************************/
2324 void btm_process_clk_off_comp_evt (UINT16 hci_handle, UINT16 clock_offset)
2327 BTM_TRACE_DEBUG ("btm_process_clk_off_comp_evt");
2328 /* Look up the connection by handle and set the current mode */
2329 if ((xx = btm_handle_to_acl_index(hci_handle)) < MAX_L2CAP_LINKS)
2330 btm_cb.acl_db[xx].clock_offset = clock_offset;
2333 /*******************************************************************************
2335 ** Function btm_acl_role_changed
2337 ** Description This function is called whan a link's master/slave role change
2338 ** event or command status event (with error) is received.
2339 ** It updates the link control block, and calls
2340 ** the registered callback with status and role (if registered).
2344 *******************************************************************************/
2345 void btm_acl_role_changed (UINT8 hci_status, BD_ADDR bd_addr, UINT8 new_role)
2347 UINT8 *p_bda = (bd_addr) ? bd_addr :
2348 btm_cb.devcb.switch_role_ref_data.remote_bd_addr;
2349 tACL_CONN *p = btm_bda_to_acl(p_bda, BT_TRANSPORT_BR_EDR);
2350 tBTM_ROLE_SWITCH_CMPL *p_data = &btm_cb.devcb.switch_role_ref_data;
2351 tBTM_SEC_DEV_REC *p_dev_rec;
2352 #if (defined(BTM_BUSY_LEVEL_CHANGE_INCLUDED) && BTM_BUSY_LEVEL_CHANGE_INCLUDED == TRUE)
2353 tBTM_BL_ROLE_CHG_DATA evt;
2356 BTM_TRACE_DEBUG ("btm_acl_role_changed");
2357 /* Ignore any stray events */
2360 /* it could be a failure */
2361 if (hci_status != HCI_SUCCESS)
2362 btm_acl_report_role_change(hci_status, bd_addr);
2366 p_data->hci_status = hci_status;
2368 if (hci_status == HCI_SUCCESS)
2370 p_data->role = new_role;
2371 memcpy(p_data->remote_bd_addr, p_bda, BD_ADDR_LEN);
2373 /* Update cached value */
2374 p->link_role = new_role;
2375 btm_save_remote_device_role(p_bda, new_role);
2376 /* Reload LSTO: link supervision timeout is reset in the LM after a role switch */
2377 if (new_role == BTM_ROLE_MASTER)
2379 BTM_SetLinkSuperTout (p->remote_addr, p->link_super_tout);
2384 /* so the BTM_BL_ROLE_CHG_EVT uses the old role */
2385 new_role = p->link_role;
2388 /* Check if any SCO req is pending for role change */
2389 btm_sco_chk_pend_rolechange (p->hci_handle);
2391 /* if switching state is switching we need to turn encryption on */
2392 /* if idle, we did not change encryption */
2393 if (p->switch_role_state == BTM_ACL_SWKEY_STATE_SWITCHING)
2395 /* Make sure there's not also a change link key going on before re-enabling */
2396 if (p->change_key_state != BTM_ACL_SWKEY_STATE_SWITCHING)
2398 if (btsnd_hcic_set_conn_encrypt (p->hci_handle, TRUE))
2400 p->encrypt_state = BTM_ACL_ENCRYPT_STATE_ENCRYPT_ON;
2401 p->switch_role_state = BTM_ACL_SWKEY_STATE_ENCRYPTION_ON;
2405 else /* Set the state and wait for change link key */
2407 p->switch_role_state = BTM_ACL_SWKEY_STATE_ENCRYPTION_ON;
2412 /* Set the switch_role_state to IDLE since the reply received from HCI */
2413 /* regardless of its result either success or failed. */
2414 if (p->switch_role_state == BTM_ACL_SWKEY_STATE_IN_PROGRESS)
2416 p->switch_role_state = BTM_ACL_SWKEY_STATE_IDLE;
2417 p->encrypt_state = BTM_ACL_ENCRYPT_STATE_IDLE;
2420 /* if role switch complete is needed, report it now */
2421 btm_acl_report_role_change(hci_status, bd_addr);
2423 #if (defined(BTM_BUSY_LEVEL_CHANGE_INCLUDED) && BTM_BUSY_LEVEL_CHANGE_INCLUDED == TRUE)
2424 /* if role change event is registered, report it now */
2425 if (btm_cb.p_bl_changed_cb && (btm_cb.bl_evt_mask & BTM_BL_ROLE_CHG_MASK))
2427 evt.event = BTM_BL_ROLE_CHG_EVT;
2428 evt.new_role = new_role;
2430 evt.hci_status = hci_status;
2431 (*btm_cb.p_bl_changed_cb)((tBTM_BL_EVENT_DATA *)&evt);
2434 BTM_TRACE_DEBUG("Role Switch Event: new_role 0x%02x, HCI Status 0x%02x, rs_st:%d",
2435 p_data->role, p_data->hci_status, p->switch_role_state);
2438 #if BTM_DISC_DURING_RS == TRUE
2439 /* If a disconnect is pending, issue it now that role switch has completed */
2440 if ((p_dev_rec = btm_find_dev (p_bda)) != NULL)
2442 if (p_dev_rec->rs_disc_pending == BTM_SEC_DISC_PENDING)
2444 BTM_TRACE_WARNING("btm_acl_role_changed -> Issuing delayed HCI_Disconnect!!!");
2445 btsnd_hcic_disconnect(p_dev_rec->hci_handle, HCI_ERR_PEER_USER);
2447 BTM_TRACE_ERROR("tBTM_SEC_DEV:0x%x rs_disc_pending=%d",
2448 (UINT32)p_dev_rec, p_dev_rec->rs_disc_pending);
2449 p_dev_rec->rs_disc_pending = BTM_SEC_RS_NOT_PENDING; /* reset flag */
2456 #if (RFCOMM_INCLUDED==TRUE)
2457 /*******************************************************************************
2459 ** Function BTM_AllocateSCN
2461 ** Description Look through the Server Channel Numbers for a free one.
2463 ** Returns Allocated SCN number or 0 if none.
2465 *******************************************************************************/
2467 UINT8 BTM_AllocateSCN(void)
2470 BTM_TRACE_DEBUG ("BTM_AllocateSCN");
2472 // stack reserves scn 1 for HFP, HSP we still do the correct way
2473 for (x = 1; x < BTM_MAX_SCN; x++)
2475 if (!btm_cb.btm_scn[x])
2477 btm_cb.btm_scn[x] = TRUE;
2482 return(0); /* No free ports */
2485 /*******************************************************************************
2487 ** Function BTM_TryAllocateSCN
2489 ** Description Try to allocate a fixed server channel
2491 ** Returns Returns TRUE if server channel was available
2493 *******************************************************************************/
2495 BOOLEAN BTM_TryAllocateSCN(UINT8 scn)
2499 /* Make sure we don't exceed max port range.
2500 * Stack reserves scn 1 for HFP, HSP we still do the correct way.
2502 if ( (scn>=BTM_MAX_SCN) || (scn == 1) )
2505 /* check if this port is available */
2506 if (!btm_cb.btm_scn[scn-1])
2508 btm_cb.btm_scn[scn-1] = TRUE;
2512 return (FALSE); /* Port was busy */
2515 /*******************************************************************************
2517 ** Function BTM_FreeSCN
2519 ** Description Free the specified SCN.
2521 ** Returns TRUE or FALSE
2523 *******************************************************************************/
2524 BOOLEAN BTM_FreeSCN(UINT8 scn)
2526 BTM_TRACE_DEBUG ("BTM_FreeSCN ");
2527 if (scn <= BTM_MAX_SCN)
2529 btm_cb.btm_scn[scn-1] = FALSE;
2533 return(FALSE); /* Illegal SCN passed in */
2538 /* Make dummy functions for the RPC to link against */
2539 UINT8 BTM_AllocateSCN(void)
2544 BOOLEAN BTM_FreeSCN(UINT8 scn)
2552 /*******************************************************************************
2554 ** Function btm_acl_timeout
2556 ** Description This function is called when a timer list entry expires.
2560 *******************************************************************************/
2561 void btm_acl_timeout (TIMER_LIST_ENT *p_tle)
2563 UINT32 timer_type = p_tle->param;
2565 BTM_TRACE_DEBUG ("btm_acl_timeout");
2566 if (timer_type == TT_DEV_RLNKP)
2568 tBTM_CMPL_CB *p_cb = btm_cb.devcb.p_rlinkp_cmpl_cb;
2569 tBTM_LNK_POLICY_RESULTS lnkpol;
2571 lnkpol.status = BTM_ERR_PROCESSING;
2572 lnkpol.settings = 0;
2574 btm_cb.devcb.p_rlinkp_cmpl_cb = NULL;
2581 /*******************************************************************************
2583 ** Function btm_set_packet_types
2585 ** Description This function sets the packet types used for a specific
2586 ** ACL connection. It is called internally by btm_acl_created
2587 ** or by an application/profile by BTM_SetPacketTypes.
2589 ** Returns status of the operation
2591 *******************************************************************************/
2592 tBTM_STATUS btm_set_packet_types (tACL_CONN *p, UINT16 pkt_types)
2594 UINT16 temp_pkt_types;
2595 BTM_TRACE_DEBUG ("btm_set_packet_types");
2596 /* Save in the ACL control blocks, types that we support */
2597 temp_pkt_types = (pkt_types & BTM_ACL_SUPPORTED_PKTS_MASK &
2598 btm_cb.btm_acl_pkt_types_supported);
2600 /* OR in any exception packet types if at least 2.0 version of spec */
2601 if (btm_cb.devcb.local_version.hci_version >= HCI_PROTO_VERSION_2_0)
2603 temp_pkt_types |= ((pkt_types & BTM_ACL_EXCEPTION_PKTS_MASK) |
2604 (btm_cb.btm_acl_pkt_types_supported & BTM_ACL_EXCEPTION_PKTS_MASK));
2608 temp_pkt_types &= (~BTM_ACL_EXCEPTION_PKTS_MASK);
2611 /* Exclude packet types not supported by the peer */
2612 btm_acl_chk_peer_pkt_type_support (p, &temp_pkt_types);
2614 BTM_TRACE_DEBUG ("SetPacketType Mask -> 0x%04x", temp_pkt_types);
2616 if (!btsnd_hcic_change_conn_type (p->hci_handle, temp_pkt_types))
2618 return(BTM_NO_RESOURCES);
2621 p->pkt_types_mask = temp_pkt_types;
2623 return(BTM_CMD_STARTED);
2626 /*******************************************************************************
2628 ** Function btm_get_max_packet_size
2630 ** Returns Returns maximum packet size that can be used for current
2631 ** connection, 0 if connection is not established
2633 *******************************************************************************/
2634 UINT16 btm_get_max_packet_size (BD_ADDR addr)
2636 tACL_CONN *p = btm_bda_to_acl(addr, BT_TRANSPORT_BR_EDR);
2637 UINT16 pkt_types = 0;
2638 UINT16 pkt_size = 0;
2639 BTM_TRACE_DEBUG ("btm_get_max_packet_size");
2642 pkt_types = p->pkt_types_mask;
2646 /* Special case for when info for the local device is requested */
2647 if (memcmp (btm_cb.devcb.local_addr, addr, BD_ADDR_LEN) == 0)
2649 pkt_types = btm_cb.btm_acl_pkt_types_supported;
2655 if (!(pkt_types & BTM_ACL_PKT_TYPES_MASK_NO_3_DH5))
2656 pkt_size = HCI_EDR3_DH5_PACKET_SIZE;
2657 else if (!(pkt_types & BTM_ACL_PKT_TYPES_MASK_NO_2_DH5))
2658 pkt_size = HCI_EDR2_DH5_PACKET_SIZE;
2659 else if (!(pkt_types & BTM_ACL_PKT_TYPES_MASK_NO_3_DH3))
2660 pkt_size = HCI_EDR3_DH3_PACKET_SIZE;
2661 else if (pkt_types & BTM_ACL_PKT_TYPES_MASK_DH5)
2662 pkt_size = HCI_DH5_PACKET_SIZE;
2663 else if (!(pkt_types & BTM_ACL_PKT_TYPES_MASK_NO_2_DH3))
2664 pkt_size = HCI_EDR2_DH3_PACKET_SIZE;
2665 else if (pkt_types & BTM_ACL_PKT_TYPES_MASK_DM5)
2666 pkt_size = HCI_DM5_PACKET_SIZE;
2667 else if (pkt_types & BTM_ACL_PKT_TYPES_MASK_DH3)
2668 pkt_size = HCI_DH3_PACKET_SIZE;
2669 else if (pkt_types & BTM_ACL_PKT_TYPES_MASK_DM3)
2670 pkt_size = HCI_DM3_PACKET_SIZE;
2671 else if (!(pkt_types & BTM_ACL_PKT_TYPES_MASK_NO_3_DH1))
2672 pkt_size = HCI_EDR3_DH1_PACKET_SIZE;
2673 else if (!(pkt_types & BTM_ACL_PKT_TYPES_MASK_NO_2_DH1))
2674 pkt_size = HCI_EDR2_DH1_PACKET_SIZE;
2675 else if (pkt_types & BTM_ACL_PKT_TYPES_MASK_DH1)
2676 pkt_size = HCI_DH1_PACKET_SIZE;
2677 else if (pkt_types & BTM_ACL_PKT_TYPES_MASK_DM1)
2678 pkt_size = HCI_DM1_PACKET_SIZE;
2684 /*******************************************************************************
2686 ** Function BTM_ReadRemoteVersion
2688 ** Returns If connected report peer device info
2690 *******************************************************************************/
2691 tBTM_STATUS BTM_ReadRemoteVersion (BD_ADDR addr, UINT8 *lmp_version,
2692 UINT16 *manufacturer, UINT16 *lmp_sub_version)
2694 tACL_CONN *p = btm_bda_to_acl(addr, BT_TRANSPORT_BR_EDR);
2695 BTM_TRACE_DEBUG ("BTM_ReadRemoteVersion");
2697 return(BTM_UNKNOWN_ADDR);
2700 *lmp_version = p->lmp_version;
2703 *manufacturer = p->manufacturer;
2705 if (lmp_sub_version)
2706 *lmp_sub_version = p->lmp_subversion;
2708 return(BTM_SUCCESS);
2711 /*******************************************************************************
2713 ** Function BTM_ReadRemoteFeatures
2715 ** Returns pointer to the remote supported features mask (8 bytes)
2717 *******************************************************************************/
2718 UINT8 *BTM_ReadRemoteFeatures (BD_ADDR addr)
2720 tACL_CONN *p = btm_bda_to_acl(addr, BT_TRANSPORT_BR_EDR);
2721 BTM_TRACE_DEBUG ("BTM_ReadRemoteFeatures");
2727 return(p->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0]);
2730 /*******************************************************************************
2732 ** Function BTM_ReadRemoteExtendedFeatures
2734 ** Returns pointer to the remote extended features mask (8 bytes)
2735 ** or NULL if bad page
2737 *******************************************************************************/
2738 UINT8 *BTM_ReadRemoteExtendedFeatures (BD_ADDR addr, UINT8 page_number)
2740 tACL_CONN *p = btm_bda_to_acl(addr, BT_TRANSPORT_BR_EDR);
2741 BTM_TRACE_DEBUG ("BTM_ReadRemoteExtendedFeatures");
2747 if (page_number > HCI_EXT_FEATURES_PAGE_MAX)
2749 BTM_TRACE_ERROR("Warning: BTM_ReadRemoteExtendedFeatures page %d unknown", page_number);
2753 return(p->peer_lmp_features[page_number]);
2756 /*******************************************************************************
2758 ** Function BTM_ReadNumberRemoteFeaturesPages
2760 ** Returns number of features pages read from the remote device.
2762 *******************************************************************************/
2763 UINT8 BTM_ReadNumberRemoteFeaturesPages (BD_ADDR addr)
2765 tACL_CONN *p = btm_bda_to_acl(addr, BT_TRANSPORT_BR_EDR);
2766 BTM_TRACE_DEBUG ("BTM_ReadNumberRemoteFeaturesPages");
2772 return(p->num_read_pages);
2775 /*******************************************************************************
2777 ** Function BTM_ReadAllRemoteFeatures
2779 ** Returns pointer to all features of the remote (24 bytes).
2781 *******************************************************************************/
2782 UINT8 *BTM_ReadAllRemoteFeatures (BD_ADDR addr)
2784 tACL_CONN *p = btm_bda_to_acl(addr, BT_TRANSPORT_BR_EDR);
2785 BTM_TRACE_DEBUG ("BTM_ReadAllRemoteFeatures");
2791 return(p->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0]);
2794 /*******************************************************************************
2796 ** Function BTM_RegBusyLevelNotif
2798 ** Description This function is called to register a callback to receive
2799 ** busy level change events.
2801 ** Returns BTM_SUCCESS if successfully registered, otherwise error
2803 *******************************************************************************/
2804 #if (defined(BTM_BUSY_LEVEL_CHANGE_INCLUDED) && BTM_BUSY_LEVEL_CHANGE_INCLUDED == TRUE)
2805 tBTM_STATUS BTM_RegBusyLevelNotif (tBTM_BL_CHANGE_CB *p_cb, UINT8 *p_level,
2806 tBTM_BL_EVENT_MASK evt_mask)
2808 BTM_TRACE_DEBUG ("BTM_RegBusyLevelNotif");
2810 *p_level = btm_cb.busy_level;
2812 btm_cb.bl_evt_mask = evt_mask;
2815 btm_cb.p_bl_changed_cb = NULL;
2816 else if (btm_cb.p_bl_changed_cb)
2819 btm_cb.p_bl_changed_cb = p_cb;
2821 return(BTM_SUCCESS);
2824 /*******************************************************************************
2826 ** Function BTM_AclRegisterForChanges
2828 ** Returns This function is called to register a callback for when the
2829 ** ACL database changes, i.e. new entry or entry deleted.
2831 *******************************************************************************/
2832 tBTM_STATUS BTM_AclRegisterForChanges (tBTM_ACL_DB_CHANGE_CB *p_cb)
2834 BTM_TRACE_DEBUG ("BTM_AclRegisterForChanges");
2836 btm_cb.p_acl_changed_cb = NULL;
2837 else if (btm_cb.p_acl_changed_cb)
2840 btm_cb.p_acl_changed_cb = p_cb;
2842 return(BTM_SUCCESS);
2846 /*******************************************************************************
2848 ** Function BTM_SetQoS
2850 ** Description This function is called to setup QoS
2852 ** Returns status of the operation
2854 *******************************************************************************/
2855 tBTM_STATUS BTM_SetQoS (BD_ADDR bd, FLOW_SPEC *p_flow, tBTM_CMPL_CB *p_cb)
2857 tACL_CONN *p = &btm_cb.acl_db[0];
2859 BTM_TRACE_API ("BTM_SetQoS: BdAddr: %02x%02x%02x%02x%02x%02x",
2860 bd[0], bd[1], bd[2],
2861 bd[3], bd[4], bd[5]);
2863 /* If someone already waiting on the version, do not allow another */
2864 if (btm_cb.devcb.p_qossu_cmpl_cb)
2867 if ( (p = btm_bda_to_acl(bd, BT_TRANSPORT_BR_EDR)) != NULL)
2869 btu_start_timer (&btm_cb.devcb.qossu_timer, BTU_TTYPE_BTM_ACL, BTM_DEV_REPLY_TIMEOUT);
2870 btm_cb.devcb.p_qossu_cmpl_cb = p_cb;
2872 if (!btsnd_hcic_qos_setup (p->hci_handle, p_flow->qos_flags, p_flow->service_type,
2873 p_flow->token_rate, p_flow->peak_bandwidth,
2874 p_flow->latency,p_flow->delay_variation))
2876 btm_cb.devcb.p_qossu_cmpl_cb = NULL;
2877 btu_stop_timer(&btm_cb.devcb.qossu_timer);
2878 return(BTM_NO_RESOURCES);
2881 return(BTM_CMD_STARTED);
2884 /* If here, no BD Addr found */
2885 return(BTM_UNKNOWN_ADDR);
2888 /*******************************************************************************
2890 ** Function btm_qos_setup_complete
2892 ** Description This function is called when the command complete message
2893 ** is received from the HCI for the qos setup request.
2897 *******************************************************************************/
2898 void btm_qos_setup_complete (UINT8 status, UINT16 handle, FLOW_SPEC *p_flow)
2900 tBTM_CMPL_CB *p_cb = btm_cb.devcb.p_qossu_cmpl_cb;
2901 tBTM_QOS_SETUP_CMPL qossu;
2902 BTM_TRACE_DEBUG ("btm_qos_setup_complete");
2903 btu_stop_timer (&btm_cb.devcb.qossu_timer);
2905 btm_cb.devcb.p_qossu_cmpl_cb = NULL;
2909 memset(&qossu, 0, sizeof(tBTM_QOS_SETUP_CMPL));
2910 qossu.status = status;
2911 qossu.handle = handle;
2914 qossu.flow.qos_flags = p_flow->qos_flags;
2915 qossu.flow.service_type = p_flow->service_type;
2916 qossu.flow.token_rate = p_flow->token_rate;
2917 qossu.flow.peak_bandwidth = p_flow->peak_bandwidth;
2918 qossu.flow.latency = p_flow->latency;
2919 qossu.flow.delay_variation = p_flow->delay_variation;
2921 BTM_TRACE_DEBUG ("BTM: p_flow->delay_variation: 0x%02x",
2922 qossu.flow.delay_variation);
2928 /*******************************************************************************
2930 ** Function BTM_ReadRSSI
2932 ** Description This function is called to read the link policy settings.
2933 ** The address of link policy results are returned in the callback.
2934 ** (tBTM_RSSI_RESULTS)
2936 ** Returns BTM_CMD_STARTED if successfully initiated or error code
2938 *******************************************************************************/
2939 tBTM_STATUS BTM_ReadRSSI (BD_ADDR remote_bda, tBTM_CMPL_CB *p_cb)
2942 tBT_TRANSPORT transport = BT_TRANSPORT_BR_EDR;
2943 #if BLE_INCLUDED == TRUE
2944 tBT_DEVICE_TYPE dev_type;
2945 tBLE_ADDR_TYPE addr_type;
2947 BTM_TRACE_API ("BTM_ReadRSSI: RemBdAddr: %02x%02x%02x%02x%02x%02x",
2948 remote_bda[0], remote_bda[1], remote_bda[2],
2949 remote_bda[3], remote_bda[4], remote_bda[5]);
2951 /* If someone already waiting on the version, do not allow another */
2952 if (btm_cb.devcb.p_rssi_cmpl_cb)
2955 #if BLE_INCLUDED == TRUE
2956 BTM_ReadDevInfo(remote_bda, &dev_type, &addr_type);
2957 if (dev_type == BT_DEVICE_TYPE_BLE)
2958 transport = BT_TRANSPORT_LE;
2961 p = btm_bda_to_acl(remote_bda, transport);
2962 if (p != (tACL_CONN *)NULL)
2964 btu_start_timer (&btm_cb.devcb.rssi_timer, BTU_TTYPE_BTM_ACL,
2965 BTM_DEV_REPLY_TIMEOUT);
2967 btm_cb.devcb.p_rssi_cmpl_cb = p_cb;
2969 if (!btsnd_hcic_read_rssi (p->hci_handle))
2971 btm_cb.devcb.p_rssi_cmpl_cb = NULL;
2972 btu_stop_timer (&btm_cb.devcb.rssi_timer);
2973 return(BTM_NO_RESOURCES);
2976 return(BTM_CMD_STARTED);
2979 /* If here, no BD Addr found */
2980 return(BTM_UNKNOWN_ADDR);
2983 /*******************************************************************************
2985 ** Function BTM_ReadLinkQuality
2987 ** Description This function is called to read the link qulaity.
2988 ** The value of the link quality is returned in the callback.
2989 ** (tBTM_LINK_QUALITY_RESULTS)
2991 ** Returns BTM_CMD_STARTED if successfully initiated or error code
2993 *******************************************************************************/
2994 tBTM_STATUS BTM_ReadLinkQuality (BD_ADDR remote_bda, tBTM_CMPL_CB *p_cb)
2998 BTM_TRACE_API ("BTM_ReadLinkQuality: RemBdAddr: %02x%02x%02x%02x%02x%02x",
2999 remote_bda[0], remote_bda[1], remote_bda[2],
3000 remote_bda[3], remote_bda[4], remote_bda[5]);
3002 /* If someone already waiting on the version, do not allow another */
3003 if (btm_cb.devcb.p_lnk_qual_cmpl_cb)
3006 p = btm_bda_to_acl(remote_bda, BT_TRANSPORT_BR_EDR);
3007 if (p != (tACL_CONN *)NULL)
3009 btu_start_timer (&btm_cb.devcb.lnk_quality_timer, BTU_TTYPE_BTM_ACL,
3010 BTM_DEV_REPLY_TIMEOUT);
3011 btm_cb.devcb.p_lnk_qual_cmpl_cb = p_cb;
3013 if (!btsnd_hcic_get_link_quality (p->hci_handle))
3015 btu_stop_timer (&btm_cb.devcb.lnk_quality_timer);
3016 btm_cb.devcb.p_lnk_qual_cmpl_cb = NULL;
3017 return(BTM_NO_RESOURCES);
3020 return(BTM_CMD_STARTED);
3023 /* If here, no BD Addr found */
3024 return(BTM_UNKNOWN_ADDR);
3027 /*******************************************************************************
3029 ** Function BTM_ReadTxPower
3031 ** Description This function is called to read the current
3032 ** TX power of the connection. The tx power level results
3033 ** are returned in the callback.
3034 ** (tBTM_RSSI_RESULTS)
3036 ** Returns BTM_CMD_STARTED if successfully initiated or error code
3038 *******************************************************************************/
3039 tBTM_STATUS BTM_ReadTxPower (BD_ADDR remote_bda, tBT_TRANSPORT transport, tBTM_CMPL_CB *p_cb)
3043 #define BTM_READ_RSSI_TYPE_CUR 0x00
3044 #define BTM_READ_RSSI_TYPE_MAX 0X01
3046 BTM_TRACE_API ("BTM_ReadTxPower: RemBdAddr: %02x%02x%02x%02x%02x%02x",
3047 remote_bda[0], remote_bda[1], remote_bda[2],
3048 remote_bda[3], remote_bda[4], remote_bda[5]);
3050 /* If someone already waiting on the version, do not allow another */
3051 if (btm_cb.devcb.p_tx_power_cmpl_cb)
3054 p = btm_bda_to_acl(remote_bda, transport);
3055 if (p != (tACL_CONN *)NULL)
3057 btu_start_timer (&btm_cb.devcb.tx_power_timer, BTU_TTYPE_BTM_ACL,
3058 BTM_DEV_REPLY_TIMEOUT);
3060 btm_cb.devcb.p_tx_power_cmpl_cb = p_cb;
3062 #if BLE_INCLUDED == TRUE
3063 if (p->transport == BT_TRANSPORT_LE)
3065 memcpy(btm_cb.devcb.read_tx_pwr_addr, remote_bda, BD_ADDR_LEN);
3066 ret = btsnd_hcic_ble_read_adv_chnl_tx_power();
3071 ret = btsnd_hcic_read_tx_power (p->hci_handle, BTM_READ_RSSI_TYPE_CUR);
3075 btm_cb.devcb.p_tx_power_cmpl_cb = NULL;
3076 btu_stop_timer (&btm_cb.devcb.tx_power_timer);
3077 return(BTM_NO_RESOURCES);
3080 return(BTM_CMD_STARTED);
3083 /* If here, no BD Addr found */
3084 return (BTM_UNKNOWN_ADDR);
3086 /*******************************************************************************
3088 ** Function btm_read_tx_power_complete
3090 ** Description This function is called when the command complete message
3091 ** is received from the HCI for the read tx power request.
3095 *******************************************************************************/
3096 void btm_read_tx_power_complete (UINT8 *p, BOOLEAN is_ble)
3098 tBTM_CMPL_CB *p_cb = btm_cb.devcb.p_tx_power_cmpl_cb;
3099 tBTM_TX_POWER_RESULTS results;
3101 tACL_CONN *p_acl_cb = &btm_cb.acl_db[0];
3103 BTM_TRACE_DEBUG ("btm_read_tx_power_complete");
3104 btu_stop_timer (&btm_cb.devcb.tx_power_timer);
3106 /* If there was a callback registered for read rssi, call it */
3107 btm_cb.devcb.p_tx_power_cmpl_cb = NULL;
3111 STREAM_TO_UINT8 (results.hci_status, p);
3113 if (results.hci_status == HCI_SUCCESS)
3115 results.status = BTM_SUCCESS;
3119 STREAM_TO_UINT16 (handle, p);
3120 STREAM_TO_UINT8 (results.tx_power, p);
3122 /* Search through the list of active channels for the correct BD Addr */
3123 for (index = 0; index < MAX_L2CAP_LINKS; index++, p_acl_cb++)
3125 if ((p_acl_cb->in_use) && (handle == p_acl_cb->hci_handle))
3127 memcpy (results.rem_bda, p_acl_cb->remote_addr, BD_ADDR_LEN);
3132 #if BLE_INCLUDED == TRUE
3135 STREAM_TO_UINT8 (results.tx_power, p);
3136 memcpy(results.rem_bda, btm_cb.devcb.read_tx_pwr_addr, BD_ADDR_LEN);
3139 BTM_TRACE_DEBUG ("BTM TX power Complete: tx_power %d, hci status 0x%02x",
3140 results.tx_power, results.hci_status);
3143 results.status = BTM_ERR_PROCESSING;
3149 /*******************************************************************************
3151 ** Function btm_read_rssi_complete
3153 ** Description This function is called when the command complete message
3154 ** is received from the HCI for the read rssi request.
3158 *******************************************************************************/
3159 void btm_read_rssi_complete (UINT8 *p)
3161 tBTM_CMPL_CB *p_cb = btm_cb.devcb.p_rssi_cmpl_cb;
3162 tBTM_RSSI_RESULTS results;
3164 tACL_CONN *p_acl_cb = &btm_cb.acl_db[0];
3166 BTM_TRACE_DEBUG ("btm_read_rssi_complete");
3167 btu_stop_timer (&btm_cb.devcb.rssi_timer);
3169 /* If there was a callback registered for read rssi, call it */
3170 btm_cb.devcb.p_rssi_cmpl_cb = NULL;
3174 STREAM_TO_UINT8 (results.hci_status, p);
3176 if (results.hci_status == HCI_SUCCESS)
3178 results.status = BTM_SUCCESS;
3180 STREAM_TO_UINT16 (handle, p);
3182 STREAM_TO_UINT8 (results.rssi, p);
3183 BTM_TRACE_DEBUG ("BTM RSSI Complete: rssi %d, hci status 0x%02x",
3184 results.rssi, results.hci_status);
3186 /* Search through the list of active channels for the correct BD Addr */
3187 for (index = 0; index < MAX_L2CAP_LINKS; index++, p_acl_cb++)
3189 if ((p_acl_cb->in_use) && (handle == p_acl_cb->hci_handle))
3191 memcpy (results.rem_bda, p_acl_cb->remote_addr, BD_ADDR_LEN);
3197 results.status = BTM_ERR_PROCESSING;
3203 /*******************************************************************************
3205 ** Function btm_read_link_quality_complete
3207 ** Description This function is called when the command complete message
3208 ** is received from the HCI for the read link quality.
3212 *******************************************************************************/
3213 void btm_read_link_quality_complete (UINT8 *p)
3215 tBTM_CMPL_CB *p_cb = btm_cb.devcb.p_lnk_qual_cmpl_cb;
3216 tBTM_LINK_QUALITY_RESULTS results;
3218 tACL_CONN *p_acl_cb = &btm_cb.acl_db[0];
3220 BTM_TRACE_DEBUG ("btm_read_link_quality_complete");
3221 btu_stop_timer (&btm_cb.devcb.lnk_quality_timer);
3223 /* If there was a callback registered for read rssi, call it */
3224 btm_cb.devcb.p_lnk_qual_cmpl_cb = NULL;
3228 STREAM_TO_UINT8 (results.hci_status, p);
3230 if (results.hci_status == HCI_SUCCESS)
3232 results.status = BTM_SUCCESS;
3234 STREAM_TO_UINT16 (handle, p);
3236 STREAM_TO_UINT8 (results.link_quality, p);
3237 BTM_TRACE_DEBUG ("BTM Link Quality Complete: Link Quality %d, hci status 0x%02x",
3238 results.link_quality, results.hci_status);
3240 /* Search through the list of active channels for the correct BD Addr */
3241 for (index = 0; index < MAX_L2CAP_LINKS; index++, p_acl_cb++)
3243 if ((p_acl_cb->in_use) && (handle == p_acl_cb->hci_handle))
3245 memcpy (results.rem_bda, p_acl_cb->remote_addr, BD_ADDR_LEN);
3251 results.status = BTM_ERR_PROCESSING;
3257 /*******************************************************************************
3259 ** Function btm_remove_acl
3261 ** Description This function is called to disconnect an ACL connection
3263 ** Returns BTM_SUCCESS if successfully initiated, otherwise BTM_NO_RESOURCES.
3265 *******************************************************************************/
3266 tBTM_STATUS btm_remove_acl (BD_ADDR bd_addr, tBT_TRANSPORT transport)
3268 UINT16 hci_handle = BTM_GetHCIConnHandle(bd_addr, transport);
3269 tBTM_STATUS status = BTM_SUCCESS;
3271 BTM_TRACE_DEBUG ("btm_remove_acl");
3272 #if BTM_DISC_DURING_RS == TRUE
3273 tBTM_SEC_DEV_REC *p_dev_rec = btm_find_dev (bd_addr);
3275 /* Role Switch is pending, postpone until completed */
3276 if (p_dev_rec && (p_dev_rec->rs_disc_pending == BTM_SEC_RS_PENDING))
3278 p_dev_rec->rs_disc_pending = BTM_SEC_DISC_PENDING;
3280 else /* otherwise can disconnect right away */
3283 if (hci_handle != 0xFFFF && p_dev_rec &&
3284 p_dev_rec->sec_state!= BTM_SEC_STATE_DISCONNECTING)
3286 if (!btsnd_hcic_disconnect (hci_handle, HCI_ERR_PEER_USER))
3287 status = BTM_NO_RESOURCES;
3290 status = BTM_UNKNOWN_ADDR;
3297 /*******************************************************************************
3299 ** Function BTM_SetTraceLevel
3301 ** Description This function sets the trace level for BTM. If called with
3302 ** a value of 0xFF, it simply returns the current trace level.
3304 ** Returns The new or current trace level
3306 *******************************************************************************/
3307 UINT8 BTM_SetTraceLevel (UINT8 new_level)
3309 BTM_TRACE_DEBUG ("BTM_SetTraceLevel");
3310 if (new_level != 0xFF)
3311 btm_cb.trace_level = new_level;
3313 return(btm_cb.trace_level);
3316 /*******************************************************************************
3318 ** Function btm_cont_rswitch_or_chglinkkey
3320 ** Description This function is called to continue processing an active
3321 ** role switch or change of link key procedure. It first
3322 ** disables encryption if enabled and EPR is not supported
3326 *******************************************************************************/
3327 void btm_cont_rswitch_or_chglinkkey (tACL_CONN *p, tBTM_SEC_DEV_REC *p_dev_rec,
3330 BOOLEAN sw_ok = TRUE;
3331 BOOLEAN chlk_ok = TRUE;
3332 BTM_TRACE_DEBUG ("btm_cont_rswitch_or_chglinkkey ");
3333 /* Check to see if encryption needs to be turned off if pending
3334 change of link key or role switch */
3335 if (p->switch_role_state == BTM_ACL_SWKEY_STATE_MODE_CHANGE ||
3336 p->change_key_state == BTM_ACL_SWKEY_STATE_MODE_CHANGE)
3338 /* Must turn off Encryption first if necessary */
3339 /* Some devices do not support switch or change of link key while encryption is on */
3340 if (p_dev_rec != NULL && ((p_dev_rec->sec_flags & BTM_SEC_ENCRYPTED) != 0)
3341 && !BTM_EPR_AVAILABLE(p))
3343 if (btsnd_hcic_set_conn_encrypt (p->hci_handle, FALSE))
3345 p->encrypt_state = BTM_ACL_ENCRYPT_STATE_ENCRYPT_OFF;
3346 if (p->switch_role_state == BTM_ACL_SWKEY_STATE_MODE_CHANGE)
3347 p->switch_role_state = BTM_ACL_SWKEY_STATE_ENCRYPTION_OFF;
3349 if (p->change_key_state == BTM_ACL_SWKEY_STATE_MODE_CHANGE)
3350 p->change_key_state = BTM_ACL_SWKEY_STATE_ENCRYPTION_OFF;
3354 /* Error occurred; set states back to Idle */
3355 if (p->switch_role_state == BTM_ACL_SWKEY_STATE_MODE_CHANGE)
3358 if (p->change_key_state == BTM_ACL_SWKEY_STATE_MODE_CHANGE)
3362 else /* Encryption not used or EPR supported, continue with switch
3363 and/or change of link key */
3365 if (p->switch_role_state == BTM_ACL_SWKEY_STATE_MODE_CHANGE)
3367 p->switch_role_state = BTM_ACL_SWKEY_STATE_IN_PROGRESS;
3368 #if BTM_DISC_DURING_RS == TRUE
3370 p_dev_rec->rs_disc_pending = BTM_SEC_RS_PENDING;
3372 sw_ok = btsnd_hcic_switch_role (p->remote_addr, (UINT8)!p->link_role);
3375 if (p->change_key_state == BTM_ACL_SWKEY_STATE_MODE_CHANGE)
3377 p->switch_role_state = BTM_ACL_SWKEY_STATE_IN_PROGRESS;
3378 chlk_ok = btsnd_hcic_change_link_key (p->hci_handle);
3384 p->switch_role_state = BTM_ACL_SWKEY_STATE_IDLE;
3385 btm_acl_report_role_change(hci_status, p->remote_addr);
3390 p->change_key_state = BTM_ACL_SWKEY_STATE_IDLE;
3391 if (btm_cb.devcb.p_chg_link_key_cb)
3393 btm_cb.devcb.chg_link_key_ref_data.hci_status = hci_status;
3394 (*btm_cb.devcb.p_chg_link_key_cb)(&btm_cb.devcb.chg_link_key_ref_data);
3395 btm_cb.devcb.p_chg_link_key_cb = NULL;
3401 /*******************************************************************************
3403 ** Function btm_acl_resubmit_page
3405 ** Description send pending page request
3407 *******************************************************************************/
3408 void btm_acl_resubmit_page (void)
3410 tBTM_SEC_DEV_REC *p_dev_rec;
3414 BTM_TRACE_DEBUG ("btm_acl_resubmit_page");
3415 /* If there were other page request schedule can start the next one */
3416 if ((p_buf = (BT_HDR *)GKI_dequeue (&btm_cb.page_queue)) != NULL)
3418 /* skip 3 (2 bytes opcode and 1 byte len) to get to the bd_addr
3419 * for both create_conn and rmt_name */
3420 pp = (UINT8 *)(p_buf + 1) + p_buf->offset + 3;
3422 STREAM_TO_BDADDR (bda, pp);
3424 p_dev_rec = btm_find_or_alloc_dev (bda);
3426 memcpy (btm_cb.connecting_bda, p_dev_rec->bd_addr, BD_ADDR_LEN);
3427 memcpy (btm_cb.connecting_dc, p_dev_rec->dev_class, DEV_CLASS_LEN);
3429 btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p_buf);
3432 btm_cb.paging = FALSE;
3435 /*******************************************************************************
3437 ** Function btm_acl_reset_paging
3439 ** Description set paging to FALSE and free the page queue - called at hci_reset
3441 *******************************************************************************/
3442 void btm_acl_reset_paging (void)
3445 BTM_TRACE_DEBUG ("btm_acl_reset_paging");
3446 /* If we sent reset we are definitely not paging any more */
3447 while ((p = (BT_HDR *)GKI_dequeue(&btm_cb.page_queue)) != NULL)
3450 btm_cb.paging = FALSE;
3453 /*******************************************************************************
3455 ** Function btm_acl_set_discing
3457 ** Description set discing to the given value
3459 *******************************************************************************/
3460 void btm_acl_set_discing (BOOLEAN discing)
3462 BTM_TRACE_DEBUG ("btm_acl_set_discing");
3463 btm_cb.discing = discing;
3466 /*******************************************************************************
3468 ** Function btm_acl_paging
3470 ** Description send a paging command or queue it in btm_cb
3472 *******************************************************************************/
3473 void btm_acl_paging (BT_HDR *p, BD_ADDR bda)
3475 tBTM_SEC_DEV_REC *p_dev_rec;
3477 BTM_TRACE_DEBUG ("btm_acl_paging discing:%d, paging:%d BDA: %06x%06x",
3478 btm_cb.discing, btm_cb.paging,
3479 (bda[0]<<16) + (bda[1]<<8) + bda[2], (bda[3]<<16) + (bda[4] << 8) + bda[5]);
3482 btm_cb.paging = TRUE;
3483 GKI_enqueue (&btm_cb.page_queue, p);
3487 if (!BTM_ACL_IS_CONNECTED (bda))
3489 BTM_TRACE_DEBUG ("connecting_bda: %06x%06x",
3490 (btm_cb.connecting_bda[0]<<16) + (btm_cb.connecting_bda[1]<<8) +
3491 btm_cb.connecting_bda[2],
3492 (btm_cb.connecting_bda[3]<<16) + (btm_cb.connecting_bda[4] << 8) +
3493 btm_cb.connecting_bda[5]);
3494 if (btm_cb.paging &&
3495 memcmp (bda, btm_cb.connecting_bda, BD_ADDR_LEN) != 0)
3497 GKI_enqueue (&btm_cb.page_queue, p);
3501 p_dev_rec = btm_find_or_alloc_dev (bda);
3502 memcpy (btm_cb.connecting_bda, p_dev_rec->bd_addr, BD_ADDR_LEN);
3503 memcpy (btm_cb.connecting_dc, p_dev_rec->dev_class, DEV_CLASS_LEN);
3505 btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p);
3508 btm_cb.paging = TRUE;
3510 else /* ACL is already up */
3512 btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p);
3517 /*******************************************************************************
3519 ** Function btm_acl_notif_conn_collision
3521 ** Description Send connection collision event to upper layer if registered
3523 ** Returns TRUE if sent out to upper layer,
3524 ** FALSE if BTM_BUSY_LEVEL_CHANGE_INCLUDED == FALSE, or no one
3525 ** needs the notification.
3527 ** Note: Function only used if BTM_BUSY_LEVEL_CHANGE_INCLUDED == TRUE
3529 *******************************************************************************/
3530 BOOLEAN btm_acl_notif_conn_collision (BD_ADDR bda)
3532 #if (BTM_BUSY_LEVEL_CHANGE_INCLUDED == TRUE)
3533 tBTM_BL_EVENT_DATA evt_data;
3535 /* Report possible collision to the upper layer. */
3536 if (btm_cb.p_bl_changed_cb)
3538 BTM_TRACE_DEBUG ("btm_acl_notif_conn_collision: RemBdAddr: %02x%02x%02x%02x%02x%02x",
3539 bda[0], bda[1], bda[2], bda[3], bda[4], bda[5]);
3541 evt_data.event = BTM_BL_COLLISION_EVT;
3542 evt_data.conn.p_bda = bda;
3544 #if BLE_INCLUDED == TRUE
3545 evt_data.conn.transport = BT_TRANSPORT_BR_EDR;
3546 evt_data.conn.handle = BTM_INVALID_HCI_HANDLE;
3548 (*btm_cb.p_bl_changed_cb)(&evt_data);
3559 /*******************************************************************************
3561 ** Function btm_acl_chk_peer_pkt_type_support
3563 ** Description Check if peer supports requested packets
3565 *******************************************************************************/
3566 void btm_acl_chk_peer_pkt_type_support (tACL_CONN *p, UINT16 *p_pkt_type)
3568 /* 3 and 5 slot packets? */
3569 if (!HCI_3_SLOT_PACKETS_SUPPORTED(p->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0]))
3570 *p_pkt_type &= ~(BTM_ACL_PKT_TYPES_MASK_DH3 +BTM_ACL_PKT_TYPES_MASK_DM3);
3572 if (!HCI_5_SLOT_PACKETS_SUPPORTED(p->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0]))
3573 *p_pkt_type &= ~(BTM_ACL_PKT_TYPES_MASK_DH5 + BTM_ACL_PKT_TYPES_MASK_DM5);
3575 /* If HCI version > 2.0, then also check EDR packet types */
3576 if (btm_cb.devcb.local_version.hci_version >= HCI_PROTO_VERSION_2_0)
3578 /* 2 and 3 MPS support? */
3579 if (!HCI_EDR_ACL_2MPS_SUPPORTED(p->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0]))
3580 /* Not supported. Add 'not_supported' mask for all 2MPS packet types */
3581 *p_pkt_type |= (BTM_ACL_PKT_TYPES_MASK_NO_2_DH1 + BTM_ACL_PKT_TYPES_MASK_NO_2_DH3 +
3582 BTM_ACL_PKT_TYPES_MASK_NO_2_DH5);
3584 if (!HCI_EDR_ACL_3MPS_SUPPORTED(p->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0]))
3585 /* Not supported. Add 'not_supported' mask for all 3MPS packet types */
3586 *p_pkt_type |= (BTM_ACL_PKT_TYPES_MASK_NO_3_DH1 + BTM_ACL_PKT_TYPES_MASK_NO_3_DH3 +
3587 BTM_ACL_PKT_TYPES_MASK_NO_3_DH5);
3589 /* EDR 3 and 5 slot support? */
3590 if (HCI_EDR_ACL_2MPS_SUPPORTED(p->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0])
3591 || HCI_EDR_ACL_3MPS_SUPPORTED(p->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0]))
3593 if (!HCI_3_SLOT_EDR_ACL_SUPPORTED(p->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0]))
3594 /* Not supported. Add 'not_supported' mask for all 3-slot EDR packet types */
3595 *p_pkt_type |= (BTM_ACL_PKT_TYPES_MASK_NO_2_DH3 + BTM_ACL_PKT_TYPES_MASK_NO_3_DH3);
3597 if (!HCI_5_SLOT_EDR_ACL_SUPPORTED(p->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0]))
3598 /* Not supported. Add 'not_supported' mask for all 5-slot EDR packet types */
3599 *p_pkt_type |= (BTM_ACL_PKT_TYPES_MASK_NO_2_DH5 + BTM_ACL_PKT_TYPES_MASK_NO_3_DH5);