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_acl_init
55 ** Description This function is called at BTM startup to initialize
59 *******************************************************************************/
60 void btm_acl_init (void)
62 BTM_TRACE_DEBUG ("btm_acl_init");
63 #if 0 /* cleared in btm_init; put back in if called from anywhere else! */
64 memset (&btm_cb.acl_db, 0, sizeof (btm_cb.acl_db));
65 #if RFCOMM_INCLUDED == TRUE
66 memset (btm_cb.btm_scn, 0, BTM_MAX_SCN); /* Initialize the SCN usage to FALSE */
68 btm_cb.btm_def_link_policy = 0;
69 #if (defined(BTM_BUSY_LEVEL_CHANGE_INCLUDED) && BTM_BUSY_LEVEL_CHANGE_INCLUDED == TRUE)
70 btm_cb.p_bl_changed_cb = NULL;
72 btm_cb.p_acl_changed_cb = NULL;
76 /* Initialize nonzero defaults */
77 btm_cb.btm_def_link_super_tout = HCI_DEFAULT_INACT_TOUT;
78 btm_cb.acl_disc_reason = 0xff ;
81 /*******************************************************************************
83 ** Function btm_bda_to_acl
85 ** Description This function returns the FIRST acl_db entry for the passed BDA.
87 ** Parameters bda : BD address of the remote device
88 ** transport : Physical transport used for ACL connection (BR/EDR or LE)
90 ** Returns Returns pointer to the ACL DB for the requested BDA if found.
93 *******************************************************************************/
94 tACL_CONN *btm_bda_to_acl (BD_ADDR bda, tBT_TRANSPORT transport)
96 tACL_CONN *p = &btm_cb.acl_db[0];
100 for (xx = 0; xx < MAX_L2CAP_LINKS; xx++, p++)
102 if ((p->in_use) && (!memcmp (p->remote_addr, bda, BD_ADDR_LEN))
103 #if BLE_INCLUDED == TRUE
104 && p->transport == transport
108 BTM_TRACE_DEBUG ("btm_bda_to_acl found");
114 /* If here, no BD Addr found */
115 return((tACL_CONN *)NULL);
118 /*******************************************************************************
120 ** Function btm_handle_to_acl_index
122 ** Description This function returns the FIRST acl_db entry for the passed hci_handle.
124 ** Returns index to the acl_db or MAX_L2CAP_LINKS.
126 *******************************************************************************/
127 UINT8 btm_handle_to_acl_index (UINT16 hci_handle)
129 tACL_CONN *p = &btm_cb.acl_db[0];
131 BTM_TRACE_DEBUG ("btm_handle_to_acl_index");
132 for (xx = 0; xx < MAX_L2CAP_LINKS; xx++, p++)
134 if ((p->in_use) && (p->hci_handle == hci_handle))
140 /* If here, no BD Addr found */
144 #if BLE_PRIVACY_SPT == TRUE
145 /*******************************************************************************
147 ** Function btm_ble_get_acl_remote_addr
149 ** Description This function reads the active remote address used for the
152 ** Returns success return TRUE, otherwise FALSE.
154 *******************************************************************************/
155 BOOLEAN btm_ble_get_acl_remote_addr(tBTM_SEC_DEV_REC *p_dev_rec, BD_ADDR conn_addr,
156 tBLE_ADDR_TYPE *p_addr_type)
158 #if BLE_INCLUDED == TRUE
161 if (p_dev_rec == NULL)
163 BTM_TRACE_ERROR("btm_ble_get_acl_remote_addr can not find device with matching address");
167 switch (p_dev_rec->ble.active_addr_type)
169 case BTM_BLE_ADDR_PSEUDO:
170 memcpy(conn_addr, p_dev_rec->bd_addr, BD_ADDR_LEN);
171 * p_addr_type = p_dev_rec->ble.ble_addr_type;
174 case BTM_BLE_ADDR_RRA:
175 memcpy(conn_addr, p_dev_rec->ble.cur_rand_addr, BD_ADDR_LEN);
176 * p_addr_type = BLE_ADDR_RANDOM;
179 case BTM_BLE_ADDR_STATIC:
180 memcpy(conn_addr, p_dev_rec->ble.static_addr, BD_ADDR_LEN);
181 * p_addr_type = p_dev_rec->ble.static_addr_type;
185 BTM_TRACE_ERROR("Unknown active address: %d", p_dev_rec->ble.active_addr_type);
199 /*******************************************************************************
201 ** Function btm_acl_created
203 ** Description This function is called by L2CAP when an ACL connection
208 *******************************************************************************/
209 void btm_acl_created (BD_ADDR bda, DEV_CLASS dc, BD_NAME bdn,
210 UINT16 hci_handle, UINT8 link_role, tBT_TRANSPORT transport)
212 tBTM_SEC_DEV_REC *p_dev_rec = NULL;
217 BTM_TRACE_DEBUG ("btm_acl_created hci_handle=%d link_role=%d transport=%d",
218 hci_handle,link_role, transport);
219 /* Ensure we don't have duplicates */
220 p = btm_bda_to_acl(bda, transport);
221 if (p != (tACL_CONN *)NULL)
223 p->hci_handle = hci_handle;
224 p->link_role = link_role;
225 #if BLE_INCLUDED == TRUE
226 p->transport = transport;
228 BTM_TRACE_DEBUG ("Duplicate btm_acl_created: RemBdAddr: %02x%02x%02x%02x%02x%02x",
229 bda[0], bda[1], bda[2], bda[3], bda[4], bda[5]);
230 BTM_SetLinkPolicy(p->remote_addr, &btm_cb.btm_def_link_policy);
234 /* Allocate acl_db entry */
235 for (xx = 0, p = &btm_cb.acl_db[0]; xx < MAX_L2CAP_LINKS; xx++, p++)
240 p->hci_handle = hci_handle;
241 p->link_role = link_role;
242 p->link_up_issued = FALSE;
244 #if BLE_INCLUDED == TRUE
245 p->transport = transport;
246 if (transport == BT_TRANSPORT_LE)
248 #if BLE_PRIVACY_SPT == TRUE
249 if (btm_cb.ble_ctr_cb.privacy)
251 p->conn_addr_type = btm_cb.ble_ctr_cb.addr_mgnt_cb.own_addr_type;
252 memcpy(p->conn_addr, btm_cb.ble_ctr_cb.addr_mgnt_cb.private_addr, BD_ADDR_LEN);
257 p->conn_addr_type = BLE_ADDR_PUBLIC;
258 BTM_GetLocalDeviceAddr(p->conn_addr);
262 p->restore_pkt_types = 0; /* Only exists while SCO is active */
263 p->switch_role_state = BTM_ACL_SWKEY_STATE_IDLE;
265 #if BTM_PWR_MGR_INCLUDED == FALSE
266 p->mode = BTM_ACL_MODE_NORMAL;
269 #endif /* BTM_PWR_MGR_INCLUDED == FALSE */
271 memcpy (p->remote_addr, bda, BD_ADDR_LEN);
274 memcpy (p->remote_dc, dc, DEV_CLASS_LEN);
277 memcpy (p->remote_name, bdn, BTM_MAX_REM_BD_NAME_LEN);
279 /* if BR/EDR do something more */
280 if (transport == BT_TRANSPORT_BR_EDR)
282 btsnd_hcic_read_rmt_clk_offset (p->hci_handle);
283 btsnd_hcic_rmt_ver_req (p->hci_handle);
285 p_dev_rec = btm_find_dev_by_handle (hci_handle);
287 #if (BLE_INCLUDED == TRUE)
290 BTM_TRACE_DEBUG ("device_type=0x%x", p_dev_rec->device_type);
294 if (p_dev_rec && !(transport == BT_TRANSPORT_LE))
296 /* If remote features already known, copy them and continue connection setup */
297 if ((p_dev_rec->num_read_pages) &&
298 (p_dev_rec->num_read_pages <= (HCI_EXT_FEATURES_PAGE_MAX + 1)) /* sanity check */)
300 memcpy (p->peer_lmp_features, p_dev_rec->features,
301 (HCI_FEATURE_BYTES_PER_PAGE * p_dev_rec->num_read_pages));
302 p->num_read_pages = p_dev_rec->num_read_pages;
304 if (BTM_SEC_MODE_SP == btm_cb.security_mode
305 && HCI_SSP_HOST_SUPPORTED(p_dev_rec->features[HCI_EXT_FEATURES_PAGE_1])
306 && HCI_SIMPLE_PAIRING_SUPPORTED(p_dev_rec->features[HCI_EXT_FEATURES_PAGE_0]))
308 p_dev_rec->sm4 = BTM_SM4_TRUE;
312 p_dev_rec->sm4 |= BTM_SM4_KNOWN;
315 btm_establish_continue (p);
320 #if (BLE_INCLUDED == TRUE)
321 /* If here, features are not known yet */
322 if (p_dev_rec && transport == BT_TRANSPORT_LE)
324 #if BLE_PRIVACY_SPT == TRUE
325 btm_ble_get_acl_remote_addr (p_dev_rec, p->active_remote_addr,
326 &p->active_remote_addr_type);
329 if (HCI_LE_SLAVE_INIT_FEAT_EXC_SUPPORTED(btm_cb.devcb.local_le_features)
330 || link_role == HCI_ROLE_MASTER)
332 btsnd_hcic_ble_read_remote_feat(p->hci_handle);
336 btm_establish_continue(p);
342 btm_read_remote_features (p->hci_handle);
345 /* read page 1 - on rmt feature event for buffer reasons */
352 /*******************************************************************************
354 ** Function btm_acl_report_role_change
356 ** Description This function is called when the local device is deemed
357 ** to be down. It notifies L2CAP of the failure.
361 *******************************************************************************/
362 void btm_acl_report_role_change (UINT8 hci_status, BD_ADDR bda)
364 tBTM_ROLE_SWITCH_CMPL ref_data;
365 BTM_TRACE_DEBUG ("btm_acl_report_role_change");
366 if (btm_cb.devcb.p_switch_role_cb
367 && (bda && (0 == memcmp(btm_cb.devcb.switch_role_ref_data.remote_bd_addr, bda, BD_ADDR_LEN))))
369 memcpy (&ref_data, &btm_cb.devcb.switch_role_ref_data, sizeof(tBTM_ROLE_SWITCH_CMPL));
370 ref_data.hci_status = hci_status;
371 (*btm_cb.devcb.p_switch_role_cb)(&ref_data);
372 memset (&btm_cb.devcb.switch_role_ref_data, 0, sizeof(tBTM_ROLE_SWITCH_CMPL));
373 btm_cb.devcb.p_switch_role_cb = NULL;
377 /*******************************************************************************
379 ** Function btm_acl_removed
381 ** Description This function is called by L2CAP when an ACL connection
382 ** is removed. Since only L2CAP creates ACL links, we use
383 ** the L2CAP link index as our index into the control blocks.
387 *******************************************************************************/
388 void btm_acl_removed (BD_ADDR bda, tBT_TRANSPORT transport)
391 #if (defined(BTM_BUSY_LEVEL_CHANGE_INCLUDED) && BTM_BUSY_LEVEL_CHANGE_INCLUDED == TRUE)
392 tBTM_BL_EVENT_DATA evt_data;
394 #if (defined BLE_INCLUDED && BLE_INCLUDED == TRUE)
395 tBTM_SEC_DEV_REC *p_dev_rec=NULL;
398 BTM_TRACE_DEBUG ("btm_acl_removed");
399 p = btm_bda_to_acl(bda, transport);
400 if (p != (tACL_CONN *)NULL)
404 /* if the disconnected channel has a pending role switch, clear it now */
405 btm_acl_report_role_change(HCI_ERR_NO_CONNECTION, bda);
407 /* Only notify if link up has had a chance to be issued */
408 if (p->link_up_issued)
410 p->link_up_issued = FALSE;
412 /* If anyone cares, tell him database changed */
413 #if (defined(BTM_BUSY_LEVEL_CHANGE_INCLUDED) && BTM_BUSY_LEVEL_CHANGE_INCLUDED == TRUE)
414 if (btm_cb.p_bl_changed_cb)
416 evt_data.event = BTM_BL_DISCN_EVT;
417 evt_data.discn.p_bda = bda;
418 #if BLE_INCLUDED == TRUE
419 evt_data.discn.handle = p->hci_handle;
420 evt_data.discn.transport = p->transport;
422 (*btm_cb.p_bl_changed_cb)(&evt_data);
425 btm_acl_update_busy_level (BTM_BLI_ACL_DOWN_EVT);
427 if (btm_cb.p_acl_changed_cb)
428 #if BLE_INCLUDED == TRUE
429 (*btm_cb.p_acl_changed_cb) (bda, NULL, NULL, NULL, FALSE, p->hci_handle, p->transport);
431 (*btm_cb.p_acl_changed_cb) (bda, NULL, NULL, NULL, FALSE);
436 #if (defined BLE_INCLUDED && BLE_INCLUDED == TRUE)
438 BTM_TRACE_DEBUG ("acl hci_handle=%d transport=%d connectable_mode=0x%0x link_role=%d",
441 btm_cb.ble_ctr_cb.inq_var.connectable_mode,
444 p_dev_rec = btm_find_dev(bda);
447 BTM_TRACE_DEBUG("before update p_dev_rec->sec_flags=0x%x", p_dev_rec->sec_flags);
448 if (p->transport == BT_TRANSPORT_LE)
450 BTM_TRACE_DEBUG("LE link down");
451 p_dev_rec->sec_flags &= ~(BTM_SEC_LE_ENCRYPTED | BTM_SEC_ROLE_SWITCHED);
452 if ( (p_dev_rec->sec_flags & BTM_SEC_LE_LINK_KEY_KNOWN) == 0)
454 BTM_TRACE_DEBUG("Not Bonded");
455 p_dev_rec->sec_flags &= ~(BTM_SEC_LE_LINK_KEY_AUTHED | BTM_SEC_LE_AUTHENTICATED);
459 BTM_TRACE_DEBUG("Bonded");
464 BTM_TRACE_DEBUG("Bletooth link down");
465 p_dev_rec->sec_flags &= ~(BTM_SEC_AUTHORIZED | BTM_SEC_AUTHENTICATED
466 | BTM_SEC_ENCRYPTED | BTM_SEC_ROLE_SWITCHED);
468 BTM_TRACE_DEBUG("after update p_dev_rec->sec_flags=0x%x", p_dev_rec->sec_flags);
472 BTM_TRACE_ERROR("Device not found");
482 /*******************************************************************************
484 ** Function btm_acl_device_down
486 ** Description This function is called when the local device is deemed
487 ** to be down. It notifies L2CAP of the failure.
491 *******************************************************************************/
492 void btm_acl_device_down (void)
494 tACL_CONN *p = &btm_cb.acl_db[0];
496 BTM_TRACE_DEBUG ("btm_acl_device_down");
497 for (xx = 0; xx < MAX_L2CAP_LINKS; xx++, p++)
501 BTM_TRACE_DEBUG ("hci_handle=%d HCI_ERR_HW_FAILURE ",p->hci_handle );
502 l2c_link_hci_disc_comp (p->hci_handle, HCI_ERR_HW_FAILURE);
507 #if (defined(BTM_BUSY_LEVEL_CHANGE_INCLUDED) && BTM_BUSY_LEVEL_CHANGE_INCLUDED == TRUE)
508 /*******************************************************************************
510 ** Function btm_acl_update_busy_level
512 ** Description This function is called to update the busy level of the system
517 *******************************************************************************/
518 void btm_acl_update_busy_level (tBTM_BLI_EVENT event)
520 tBTM_BL_UPDATE_DATA evt;
522 BTM_TRACE_DEBUG ("btm_acl_update_busy_level");
523 BOOLEAN old_inquiry_state = btm_cb.is_inquiry;
526 case BTM_BLI_ACL_UP_EVT:
527 BTM_TRACE_DEBUG ("BTM_BLI_ACL_UP_EVT");
530 case BTM_BLI_ACL_DOWN_EVT:
534 BTM_TRACE_DEBUG ("BTM_BLI_ACL_DOWN_EVT", btm_cb.num_acl);
538 BTM_TRACE_ERROR ("BTM_BLI_ACL_DOWN_EVT issued, but num_acl already zero !!!");
541 case BTM_BLI_PAGE_EVT:
542 BTM_TRACE_DEBUG ("BTM_BLI_PAGE_EVT");
543 btm_cb.is_paging = TRUE;
544 evt.busy_level_flags= BTM_BL_PAGING_STARTED;
546 case BTM_BLI_PAGE_DONE_EVT:
547 BTM_TRACE_DEBUG ("BTM_BLI_PAGE_DONE_EVT");
548 btm_cb.is_paging = FALSE;
549 evt.busy_level_flags = BTM_BL_PAGING_COMPLETE;
551 case BTM_BLI_INQ_EVT:
552 BTM_TRACE_DEBUG ("BTM_BLI_INQ_EVT");
553 btm_cb.is_inquiry = TRUE;
554 evt.busy_level_flags = BTM_BL_INQUIRY_STARTED;
556 case BTM_BLI_INQ_CANCEL_EVT:
557 BTM_TRACE_DEBUG ("BTM_BLI_INQ_CANCEL_EVT");
558 btm_cb.is_inquiry = FALSE;
559 evt.busy_level_flags = BTM_BL_INQUIRY_CANCELLED;
561 case BTM_BLI_INQ_DONE_EVT:
562 BTM_TRACE_DEBUG ("BTM_BLI_INQ_DONE_EVT");
563 btm_cb.is_inquiry = FALSE;
564 evt.busy_level_flags = BTM_BL_INQUIRY_COMPLETE;
568 if (btm_cb.is_paging || btm_cb.is_inquiry)
571 busy_level = (UINT8)btm_cb.num_acl;
573 if ((busy_level != btm_cb.busy_level) ||(old_inquiry_state != btm_cb.is_inquiry))
575 evt.event = BTM_BL_UPDATE_EVT;
576 evt.busy_level = busy_level;
577 btm_cb.busy_level = busy_level;
578 if (btm_cb.p_bl_changed_cb && (btm_cb.bl_evt_mask & BTM_BL_UPDATE_MASK))
580 (*btm_cb.p_bl_changed_cb)((tBTM_BL_EVENT_DATA *)&evt);
587 /*******************************************************************************
589 ** Function BTM_GetRole
591 ** Description This function is called to get the role of the local device
592 ** for the ACL connection with the specified remote device
594 ** Returns BTM_SUCCESS if connection exists.
595 ** BTM_UNKNOWN_ADDR if no active link with bd addr specified
597 *******************************************************************************/
598 tBTM_STATUS BTM_GetRole (BD_ADDR remote_bd_addr, UINT8 *p_role)
601 BTM_TRACE_DEBUG ("BTM_GetRole");
602 if ((p = btm_bda_to_acl(remote_bd_addr, BT_TRANSPORT_BR_EDR)) == NULL)
604 *p_role = BTM_ROLE_UNDEFINED;
605 return(BTM_UNKNOWN_ADDR);
608 /* Get the current role */
609 *p_role = p->link_role;
614 /*******************************************************************************
616 ** Function BTM_SwitchRole
618 ** Description This function is called to switch role between master and
619 ** slave. If role is already set it will do nothing. If the
620 ** command was initiated, the callback function is called upon
623 ** Returns BTM_SUCCESS if already in specified role.
624 ** BTM_CMD_STARTED if command issued to controller.
625 ** BTM_NO_RESOURCES if couldn't allocate memory to issue command
626 ** BTM_UNKNOWN_ADDR if no active link with bd addr specified
627 ** BTM_MODE_UNSUPPORTED if local device does not support role switching
628 ** BTM_BUSY if the previous command is not completed
630 *******************************************************************************/
631 tBTM_STATUS BTM_SwitchRole (BD_ADDR remote_bd_addr, UINT8 new_role, tBTM_CMPL_CB *p_cb)
634 tBTM_SEC_DEV_REC *p_dev_rec = NULL;
635 #if BTM_SCO_INCLUDED == TRUE
636 BOOLEAN is_sco_active;
638 #if BTM_PWR_MGR_INCLUDED == TRUE
640 tBTM_PM_MODE pwr_mode;
641 tBTM_PM_PWR_MD settings;
643 #if (BT_USE_TRACES == TRUE)
646 BTM_TRACE_API ("BTM_SwitchRole BDA: %02x-%02x-%02x-%02x-%02x-%02x",
647 remote_bd_addr[0], remote_bd_addr[1], remote_bd_addr[2],
648 remote_bd_addr[3], remote_bd_addr[4], remote_bd_addr[5]);
650 /* Make sure the local device supports switching */
651 if (!(HCI_SWITCH_SUPPORTED(btm_cb.devcb.local_lmp_features[HCI_EXT_FEATURES_PAGE_0])))
652 return(BTM_MODE_UNSUPPORTED);
654 if (btm_cb.devcb.p_switch_role_cb && p_cb)
656 #if (BT_USE_TRACES == TRUE)
657 p_bda = btm_cb.devcb.switch_role_ref_data.remote_bd_addr;
658 BTM_TRACE_DEBUG ("Role switch on other device is in progress 0x%02x%02x%02x%02x%02x%02x",
659 p_bda[0], p_bda[1], p_bda[2],
660 p_bda[3], p_bda[4], p_bda[5]);
665 if ((p = btm_bda_to_acl(remote_bd_addr, BT_TRANSPORT_BR_EDR)) == NULL)
666 return(BTM_UNKNOWN_ADDR);
668 /* Finished if already in desired role */
669 if (p->link_role == new_role)
672 #if BTM_SCO_INCLUDED == TRUE
673 /* Check if there is any SCO Active on this BD Address */
674 is_sco_active = btm_is_sco_active_by_bdaddr(remote_bd_addr);
676 if (is_sco_active == TRUE)
677 return(BTM_NO_RESOURCES);
680 /* Ignore role switch request if the previous request was not completed */
681 if (p->switch_role_state != BTM_ACL_SWKEY_STATE_IDLE)
683 BTM_TRACE_DEBUG ("BTM_SwitchRole busy: %d",
684 p->switch_role_state);
688 /* Cannot switch role while parked or sniffing */
689 #if BTM_PWR_MGR_INCLUDED == FALSE
690 if (p->mode == HCI_MODE_PARK)
692 if (!btsnd_hcic_exit_park_mode (p->hci_handle))
693 return(BTM_NO_RESOURCES);
695 p->switch_role_state = BTM_ACL_SWKEY_STATE_MODE_CHANGE;
697 else if (p->mode == HCI_MODE_SNIFF)
699 if (!btsnd_hcic_exit_sniff_mode (p->hci_handle))
700 return(BTM_NO_RESOURCES);
702 p->switch_role_state = BTM_ACL_SWKEY_STATE_MODE_CHANGE;
704 #else /* power manager is in use */
706 if ((status = BTM_ReadPowerMode(p->remote_addr, &pwr_mode)) != BTM_SUCCESS)
709 /* Wake up the link if in sniff or park before attempting switch */
710 if (pwr_mode == BTM_PM_MD_PARK || pwr_mode == BTM_PM_MD_SNIFF)
712 memset( (void*)&settings, 0, sizeof(settings));
713 settings.mode = BTM_PM_MD_ACTIVE;
714 status = BTM_SetPowerMode (BTM_PM_SET_ONLY_ID, p->remote_addr, &settings);
715 if (status != BTM_CMD_STARTED)
716 return(BTM_WRONG_MODE);
718 p->switch_role_state = BTM_ACL_SWKEY_STATE_MODE_CHANGE;
721 /* some devices do not support switch while encryption is on */
724 p_dev_rec = btm_find_dev (remote_bd_addr);
725 if ((p_dev_rec != NULL)
726 && ((p_dev_rec->sec_flags & BTM_SEC_ENCRYPTED) != 0)
727 && !BTM_EPR_AVAILABLE(p))
729 /* bypass turning off encryption if change link key is already doing it */
730 if (p->encrypt_state != BTM_ACL_ENCRYPT_STATE_ENCRYPT_OFF)
732 if (!btsnd_hcic_set_conn_encrypt (p->hci_handle, FALSE))
733 return(BTM_NO_RESOURCES);
735 p->encrypt_state = BTM_ACL_ENCRYPT_STATE_ENCRYPT_OFF;
738 p->switch_role_state = BTM_ACL_SWKEY_STATE_ENCRYPTION_OFF;
742 if (!btsnd_hcic_switch_role (remote_bd_addr, new_role))
743 return(BTM_NO_RESOURCES);
745 p->switch_role_state = BTM_ACL_SWKEY_STATE_IN_PROGRESS;
747 #if BTM_DISC_DURING_RS == TRUE
749 p_dev_rec->rs_disc_pending = BTM_SEC_RS_PENDING;
754 /* Initialize return structure in case request fails */
757 memcpy (btm_cb.devcb.switch_role_ref_data.remote_bd_addr, remote_bd_addr,
759 btm_cb.devcb.switch_role_ref_data.role = new_role;
760 /* initialized to an error code */
761 btm_cb.devcb.switch_role_ref_data.hci_status = HCI_ERR_UNSUPPORTED_VALUE;
762 btm_cb.devcb.p_switch_role_cb = p_cb;
764 return(BTM_CMD_STARTED);
767 /*******************************************************************************
769 ** Function BTM_ChangeLinkKey
771 ** Description This function is called to change the link key of the
774 ** Returns BTM_CMD_STARTED if command issued to controller.
775 ** BTM_NO_RESOURCES if couldn't allocate memory to issue command
776 ** BTM_UNKNOWN_ADDR if no active link with bd addr specified
777 ** BTM_BUSY if the previous command is not completed
779 *******************************************************************************/
780 tBTM_STATUS BTM_ChangeLinkKey (BD_ADDR remote_bd_addr, tBTM_CMPL_CB *p_cb)
783 tBTM_SEC_DEV_REC *p_dev_rec = NULL;
784 #if BTM_PWR_MGR_INCLUDED == TRUE
786 tBTM_PM_MODE pwr_mode;
787 tBTM_PM_PWR_MD settings;
789 BTM_TRACE_DEBUG ("BTM_ChangeLinkKey");
790 if ((p = btm_bda_to_acl(remote_bd_addr, BT_TRANSPORT_BR_EDR)) == NULL)
791 return(BTM_UNKNOWN_ADDR);
793 /* Ignore change link key request if the previsous request has not completed */
794 if (p->change_key_state != BTM_ACL_SWKEY_STATE_IDLE)
796 BTM_TRACE_DEBUG ("Link key change request declined since the previous request"
797 " for this device has not completed ");
801 memset (&btm_cb.devcb.chg_link_key_ref_data, 0, sizeof(tBTM_CHANGE_KEY_CMPL));
803 /* Cannot change key while parked */
804 #if BTM_PWR_MGR_INCLUDED == FALSE
805 if (p->mode == HCI_MODE_PARK)
807 if (!btsnd_hcic_exit_park_mode (p->hci_handle))
808 return(BTM_NO_RESOURCES);
810 p->change_key_state = BTM_ACL_SWKEY_STATE_MODE_CHANGE;
812 #else /* power manager is in use */
815 if ((status = BTM_ReadPowerMode(p->remote_addr, &pwr_mode)) != BTM_SUCCESS)
818 /* Wake up the link if in park before attempting to change link keys */
819 if (pwr_mode == BTM_PM_MD_PARK)
821 memset( (void*)&settings, 0, sizeof(settings));
822 settings.mode = BTM_PM_MD_ACTIVE;
823 status = BTM_SetPowerMode (BTM_PM_SET_ONLY_ID, p->remote_addr, &settings);
824 if (status != BTM_CMD_STARTED)
825 return(BTM_WRONG_MODE);
827 p->change_key_state = BTM_ACL_SWKEY_STATE_MODE_CHANGE;
830 /* some devices do not support change of link key while encryption is on */
831 else if (((p_dev_rec = btm_find_dev (remote_bd_addr)) != NULL)
832 && ((p_dev_rec->sec_flags & BTM_SEC_ENCRYPTED) != 0) && !BTM_EPR_AVAILABLE(p))
834 /* bypass turning off encryption if switch role is already doing it */
835 if (p->encrypt_state != BTM_ACL_ENCRYPT_STATE_ENCRYPT_OFF)
837 if (!btsnd_hcic_set_conn_encrypt (p->hci_handle, FALSE))
838 return(BTM_NO_RESOURCES);
840 p->encrypt_state = BTM_ACL_ENCRYPT_STATE_ENCRYPT_OFF;
843 p->change_key_state = BTM_ACL_SWKEY_STATE_ENCRYPTION_OFF;
845 else /* Ok to initiate change of link key */
847 if (!btsnd_hcic_change_link_key (p->hci_handle))
848 return(BTM_NO_RESOURCES);
850 p->change_key_state = BTM_ACL_SWKEY_STATE_IN_PROGRESS;
853 /* Initialize return structure in case request fails */
854 memcpy (btm_cb.devcb.chg_link_key_ref_data.remote_bd_addr, remote_bd_addr,
856 btm_cb.devcb.p_chg_link_key_cb = p_cb;
857 return(BTM_CMD_STARTED);
860 /*******************************************************************************
862 ** Function btm_acl_link_key_change
864 ** Description This function is called to when a change link key event
867 *******************************************************************************/
868 void btm_acl_link_key_change (UINT16 handle, UINT8 status)
870 tBTM_CHANGE_KEY_CMPL *p_data;
873 BTM_TRACE_DEBUG ("btm_acl_link_key_change");
874 /* Look up the connection by handle and set the current mode */
875 xx = btm_handle_to_acl_index(handle);
877 /* don't assume that we can never get a bad hci_handle */
878 if (xx >= MAX_L2CAP_LINKS)
881 p_data = &btm_cb.devcb.chg_link_key_ref_data;
882 p = &btm_cb.acl_db[xx];
883 p_data->hci_status = status;
885 /* if switching state is switching we need to turn encryption on */
886 /* if idle, we did not change encryption */
887 if (p->change_key_state == BTM_ACL_SWKEY_STATE_SWITCHING)
889 /* Make sure there's not also a role switch going on before re-enabling */
890 if (p->switch_role_state != BTM_ACL_SWKEY_STATE_SWITCHING)
892 if (btsnd_hcic_set_conn_encrypt (p->hci_handle, TRUE))
894 p->encrypt_state = BTM_ACL_ENCRYPT_STATE_ENCRYPT_ON;
895 p->change_key_state = BTM_ACL_SWKEY_STATE_ENCRYPTION_ON;
899 else /* Set the state and wait for change link key */
901 p->change_key_state = BTM_ACL_SWKEY_STATE_ENCRYPTION_ON;
906 /* Set the switch_role_state to IDLE since the reply received from HCI */
907 /* regardless of its result either success or failed. */
908 if (p->change_key_state == BTM_ACL_SWKEY_STATE_IN_PROGRESS)
910 p->change_key_state = BTM_ACL_SWKEY_STATE_IDLE;
911 p->encrypt_state = BTM_ACL_ENCRYPT_STATE_IDLE;
914 if (btm_cb.devcb.p_chg_link_key_cb)
916 (*btm_cb.devcb.p_chg_link_key_cb)((void *)p_data);
917 btm_cb.devcb.p_chg_link_key_cb = NULL;
920 BTM_TRACE_ERROR("Change Link Key Complete Event: Handle 0x%02x, HCI Status 0x%02x",
921 handle, p_data->hci_status);
924 /*******************************************************************************
926 ** Function btm_acl_encrypt_change
928 ** Description This function is when encryption of the connection is
929 ** completed by the LM. Checks to see if a role switch or
930 ** change of link key was active and initiates or continues
931 ** process if needed.
935 *******************************************************************************/
936 void btm_acl_encrypt_change (UINT16 handle, UINT8 status, UINT8 encr_enable)
940 tBTM_SEC_DEV_REC *p_dev_rec;
941 #if (defined(BTM_BUSY_LEVEL_CHANGE_INCLUDED) && BTM_BUSY_LEVEL_CHANGE_INCLUDED == TRUE)
942 tBTM_BL_ROLE_CHG_DATA evt;
945 BTM_TRACE_DEBUG ("btm_acl_encrypt_change handle=%d status=%d encr_enabl=%d",
946 handle, status, encr_enable);
947 xx = btm_handle_to_acl_index(handle);
948 /* don't assume that we can never get a bad hci_handle */
949 if (xx < MAX_L2CAP_LINKS)
950 p = &btm_cb.acl_db[xx];
954 /* Process Role Switch if active */
955 if (p->switch_role_state == BTM_ACL_SWKEY_STATE_ENCRYPTION_OFF)
957 /* if encryption turn off failed we still will try to switch role */
960 p->switch_role_state = BTM_ACL_SWKEY_STATE_IDLE;
961 p->encrypt_state = BTM_ACL_ENCRYPT_STATE_IDLE;
965 p->switch_role_state = BTM_ACL_SWKEY_STATE_SWITCHING;
966 p->encrypt_state = BTM_ACL_ENCRYPT_STATE_TEMP_FUNC;
969 if (!btsnd_hcic_switch_role (p->remote_addr, (UINT8)!p->link_role))
971 p->switch_role_state = BTM_ACL_SWKEY_STATE_IDLE;
972 p->encrypt_state = BTM_ACL_ENCRYPT_STATE_IDLE;
973 btm_acl_report_role_change(btm_cb.devcb.switch_role_ref_data.hci_status, p->remote_addr);
975 #if BTM_DISC_DURING_RS == TRUE
978 if ((p_dev_rec = btm_find_dev (p->remote_addr)) != NULL)
979 p_dev_rec->rs_disc_pending = BTM_SEC_RS_PENDING;
984 /* Finished enabling Encryption after role switch */
985 else if (p->switch_role_state == BTM_ACL_SWKEY_STATE_ENCRYPTION_ON)
987 p->switch_role_state = BTM_ACL_SWKEY_STATE_IDLE;
988 p->encrypt_state = BTM_ACL_ENCRYPT_STATE_IDLE;
989 btm_acl_report_role_change(btm_cb.devcb.switch_role_ref_data.hci_status, p->remote_addr);
991 #if (defined(BTM_BUSY_LEVEL_CHANGE_INCLUDED) && BTM_BUSY_LEVEL_CHANGE_INCLUDED == TRUE)
992 /* if role change event is registered, report it now */
993 if (btm_cb.p_bl_changed_cb && (btm_cb.bl_evt_mask & BTM_BL_ROLE_CHG_MASK))
995 evt.event = BTM_BL_ROLE_CHG_EVT;
996 evt.new_role = btm_cb.devcb.switch_role_ref_data.role;
997 evt.p_bda = btm_cb.devcb.switch_role_ref_data.remote_bd_addr;
998 evt.hci_status = btm_cb.devcb.switch_role_ref_data.hci_status;
999 (*btm_cb.p_bl_changed_cb)((tBTM_BL_EVENT_DATA *)&evt);
1001 BTM_TRACE_DEBUG("Role Switch Event: new_role 0x%02x, HCI Status 0x%02x, rs_st:%d",
1002 evt.new_role, evt.hci_status, p->switch_role_state);
1006 #if BTM_DISC_DURING_RS == TRUE
1007 /* If a disconnect is pending, issue it now that role switch has completed */
1008 if ((p_dev_rec = btm_find_dev (p->remote_addr)) != NULL)
1010 if (p_dev_rec->rs_disc_pending == BTM_SEC_DISC_PENDING)
1012 BTM_TRACE_WARNING("btm_acl_encrypt_change -> Issuing delayed HCI_Disconnect!!!");
1013 btsnd_hcic_disconnect(p_dev_rec->hci_handle, HCI_ERR_PEER_USER);
1015 BTM_TRACE_ERROR("btm_acl_encrypt_change: tBTM_SEC_DEV:0x%x rs_disc_pending=%d",
1016 (UINT32)p_dev_rec, p_dev_rec->rs_disc_pending);
1017 p_dev_rec->rs_disc_pending = BTM_SEC_RS_NOT_PENDING; /* reset flag */
1023 /* Process Change Link Key if active */
1024 if (p->change_key_state == BTM_ACL_SWKEY_STATE_ENCRYPTION_OFF)
1026 /* if encryption turn off failed we still will try to change link key */
1029 p->change_key_state = BTM_ACL_SWKEY_STATE_IDLE;
1030 p->encrypt_state = BTM_ACL_ENCRYPT_STATE_IDLE;
1034 p->encrypt_state = BTM_ACL_ENCRYPT_STATE_TEMP_FUNC;
1035 p->change_key_state = BTM_ACL_SWKEY_STATE_SWITCHING;
1038 if (!btsnd_hcic_change_link_key (p->hci_handle))
1040 p->encrypt_state = BTM_ACL_ENCRYPT_STATE_IDLE;
1041 p->change_key_state = BTM_ACL_SWKEY_STATE_IDLE;
1042 if (btm_cb.devcb.p_chg_link_key_cb)
1044 (*btm_cb.devcb.p_chg_link_key_cb)(&btm_cb.devcb.chg_link_key_ref_data);
1045 btm_cb.devcb.p_chg_link_key_cb = NULL;
1049 /* Finished enabling Encryption after changing link key */
1050 else if (p->change_key_state == BTM_ACL_SWKEY_STATE_ENCRYPTION_ON)
1052 p->encrypt_state = BTM_ACL_ENCRYPT_STATE_IDLE;
1053 p->change_key_state = BTM_ACL_SWKEY_STATE_IDLE;
1054 if (btm_cb.devcb.p_chg_link_key_cb)
1056 (*btm_cb.devcb.p_chg_link_key_cb)(&btm_cb.devcb.chg_link_key_ref_data);
1057 btm_cb.devcb.p_chg_link_key_cb = NULL;
1061 /*******************************************************************************
1063 ** Function BTM_SetLinkPolicy
1065 ** Description Create and send HCI "Write Policy Set" command
1067 ** Returns status of the operation
1069 *******************************************************************************/
1070 tBTM_STATUS BTM_SetLinkPolicy (BD_ADDR remote_bda, UINT16 *settings)
1073 UINT8 *localFeatures = BTM_ReadLocalFeatures();
1074 BTM_TRACE_DEBUG ("BTM_SetLinkPolicy");
1075 /* BTM_TRACE_API ("BTM_SetLinkPolicy: requested settings: 0x%04x", *settings ); */
1077 /* First, check if hold mode is supported */
1078 if (*settings != HCI_DISABLE_ALL_LM_MODES)
1080 if ( (*settings & HCI_ENABLE_MASTER_SLAVE_SWITCH) && (!HCI_SWITCH_SUPPORTED(localFeatures)) )
1082 *settings &= (~HCI_ENABLE_MASTER_SLAVE_SWITCH);
1083 BTM_TRACE_API ("BTM_SetLinkPolicy switch not supported (settings: 0x%04x)", *settings );
1085 if ( (*settings & HCI_ENABLE_HOLD_MODE) && (!HCI_HOLD_MODE_SUPPORTED(localFeatures)) )
1087 *settings &= (~HCI_ENABLE_HOLD_MODE);
1088 BTM_TRACE_API ("BTM_SetLinkPolicy hold not supported (settings: 0x%04x)", *settings );
1090 if ( (*settings & HCI_ENABLE_SNIFF_MODE) && (!HCI_SNIFF_MODE_SUPPORTED(localFeatures)) )
1092 *settings &= (~HCI_ENABLE_SNIFF_MODE);
1093 BTM_TRACE_API ("BTM_SetLinkPolicy sniff not supported (settings: 0x%04x)", *settings );
1095 if ( (*settings & HCI_ENABLE_PARK_MODE) && (!HCI_PARK_MODE_SUPPORTED(localFeatures)) )
1097 *settings &= (~HCI_ENABLE_PARK_MODE);
1098 BTM_TRACE_API ("BTM_SetLinkPolicy park not supported (settings: 0x%04x)", *settings );
1102 if ((p = btm_bda_to_acl(remote_bda, BT_TRANSPORT_BR_EDR)) != NULL)
1103 return(btsnd_hcic_write_policy_set (p->hci_handle, *settings) ? BTM_CMD_STARTED : BTM_NO_RESOURCES);
1105 /* If here, no BD Addr found */
1106 return(BTM_UNKNOWN_ADDR);
1109 /*******************************************************************************
1111 ** Function BTM_SetDefaultLinkPolicy
1113 ** Description Set the default value for HCI "Write Policy Set" command
1114 ** to use when an ACL link is created.
1118 *******************************************************************************/
1119 void BTM_SetDefaultLinkPolicy (UINT16 settings)
1121 UINT8 *localFeatures = BTM_ReadLocalFeatures();
1123 BTM_TRACE_DEBUG("BTM_SetDefaultLinkPolicy setting:0x%04x", settings);
1125 if((settings & HCI_ENABLE_MASTER_SLAVE_SWITCH) && (!HCI_SWITCH_SUPPORTED(localFeatures)))
1127 settings &= ~HCI_ENABLE_MASTER_SLAVE_SWITCH;
1128 BTM_TRACE_DEBUG("BTM_SetDefaultLinkPolicy switch not supported (settings: 0x%04x)", settings);
1130 if ((settings & HCI_ENABLE_HOLD_MODE) && (!HCI_HOLD_MODE_SUPPORTED(localFeatures)))
1132 settings &= ~HCI_ENABLE_HOLD_MODE;
1133 BTM_TRACE_DEBUG("BTM_SetDefaultLinkPolicy hold not supported (settings: 0x%04x)", settings);
1135 if ((settings & HCI_ENABLE_SNIFF_MODE) && (!HCI_SNIFF_MODE_SUPPORTED(localFeatures)))
1137 settings &= ~HCI_ENABLE_SNIFF_MODE;
1138 BTM_TRACE_DEBUG("BTM_SetDefaultLinkPolicy sniff not supported (settings: 0x%04x)", settings);
1140 if ((settings & HCI_ENABLE_PARK_MODE) && (!HCI_PARK_MODE_SUPPORTED(localFeatures)))
1142 settings &= ~HCI_ENABLE_PARK_MODE;
1143 BTM_TRACE_DEBUG("BTM_SetDefaultLinkPolicy park not supported (settings: 0x%04x)", settings);
1145 BTM_TRACE_DEBUG("Set DefaultLinkPolicy:0x%04x", settings);
1147 btm_cb.btm_def_link_policy = settings;
1149 /* Set the default Link Policy of the controller */
1150 btsnd_hcic_write_def_policy_set(settings);
1154 /*******************************************************************************
1156 ** Function BTM_ReadLinkPolicy
1158 ** Description This function is called to read the link policy settings.
1159 ** The address of link policy results are returned in the callback.
1160 ** (tBTM_LNK_POLICY_RESULTS)
1162 ** Returns status of the operation
1164 *******************************************************************************/
1165 tBTM_STATUS BTM_ReadLinkPolicy (BD_ADDR remote_bda, tBTM_CMPL_CB *p_cb)
1169 BTM_TRACE_API ("BTM_ReadLinkPolicy: RemBdAddr: %02x%02x%02x%02x%02x%02x",
1170 remote_bda[0], remote_bda[1], remote_bda[2],
1171 remote_bda[3], remote_bda[4], remote_bda[5]);
1173 /* If someone already waiting on the version, do not allow another */
1174 if (btm_cb.devcb.p_rlinkp_cmpl_cb)
1177 p = btm_bda_to_acl(remote_bda, BT_TRANSPORT_BR_EDR);
1178 if (p != (tACL_CONN *)NULL)
1180 btu_start_timer (&btm_cb.devcb.rlinkp_timer, BTU_TTYPE_BTM_ACL, BTM_DEV_REPLY_TIMEOUT);
1181 btm_cb.devcb.p_rlinkp_cmpl_cb = p_cb;
1183 if (!btsnd_hcic_read_policy_set (p->hci_handle))
1185 btu_stop_timer (&btm_cb.devcb.rlinkp_timer);
1186 btm_cb.devcb.p_rlinkp_cmpl_cb = NULL;
1187 return(BTM_NO_RESOURCES);
1190 return(BTM_CMD_STARTED);
1193 /* If here, no BD Addr found */
1194 return(BTM_UNKNOWN_ADDR);
1198 /*******************************************************************************
1200 ** Function btm_read_link_policy_complete
1202 ** Description This function is called when the command complete message
1203 ** is received from the HCI for the read local link policy request.
1207 *******************************************************************************/
1208 void btm_read_link_policy_complete (UINT8 *p)
1210 tBTM_CMPL_CB *p_cb = btm_cb.devcb.p_rlinkp_cmpl_cb;
1211 tBTM_LNK_POLICY_RESULTS lnkpol;
1213 tACL_CONN *p_acl_cb = &btm_cb.acl_db[0];
1215 BTM_TRACE_DEBUG ("btm_read_link_policy_complete");
1216 btu_stop_timer (&btm_cb.devcb.rlinkp_timer);
1218 /* If there was a callback address for read local version, call it */
1219 btm_cb.devcb.p_rlinkp_cmpl_cb = NULL;
1223 STREAM_TO_UINT8 (lnkpol.hci_status, p);
1225 if (lnkpol.hci_status == HCI_SUCCESS)
1227 lnkpol.status = BTM_SUCCESS;
1229 STREAM_TO_UINT16 (handle, p);
1231 STREAM_TO_UINT16 (lnkpol.settings, p);
1233 /* Search through the list of active channels for the correct BD Addr */
1234 for (index = 0; index < MAX_L2CAP_LINKS; index++, p_acl_cb++)
1236 if ((p_acl_cb->in_use) && (handle == p_acl_cb->hci_handle))
1238 memcpy (lnkpol.rem_bda, p_acl_cb->remote_addr, BD_ADDR_LEN);
1244 lnkpol.status = BTM_ERR_PROCESSING;
1251 /*******************************************************************************
1253 ** Function btm_read_remote_version_complete
1255 ** Description This function is called when the command complete message
1256 ** is received from the HCI for the remote version info.
1260 *******************************************************************************/
1261 void btm_read_remote_version_complete (UINT8 *p)
1263 tACL_CONN *p_acl_cb = &btm_cb.acl_db[0];
1267 BTM_TRACE_DEBUG ("btm_read_remote_version_complete");
1268 STREAM_TO_UINT8 (status, p);
1269 if (status == HCI_SUCCESS)
1271 STREAM_TO_UINT16 (handle, p);
1273 /* Look up the connection by handle and copy features */
1274 for (xx = 0; xx < MAX_L2CAP_LINKS; xx++, p_acl_cb++)
1276 if ((p_acl_cb->in_use) && (p_acl_cb->hci_handle == handle))
1278 STREAM_TO_UINT8 (p_acl_cb->lmp_version, p);
1279 STREAM_TO_UINT16 (p_acl_cb->manufacturer, p);
1280 STREAM_TO_UINT16 (p_acl_cb->lmp_subversion, p);
1288 /*******************************************************************************
1290 ** Function btm_process_remote_ext_features
1292 ** Description Local function called to process all extended features pages
1293 ** read from a remote device.
1297 *******************************************************************************/
1298 void btm_process_remote_ext_features (tACL_CONN *p_acl_cb, UINT8 num_read_pages)
1300 UINT16 handle = p_acl_cb->hci_handle;
1301 tBTM_SEC_DEV_REC *p_dev_rec = btm_find_dev_by_handle (handle);
1304 BTM_TRACE_DEBUG ("btm_process_remote_ext_features");
1306 /* Make sure we have the record to save remote features information */
1307 if (p_dev_rec == NULL)
1309 /* Get a new device; might be doing dedicated bonding */
1310 p_dev_rec = btm_find_or_alloc_dev (p_acl_cb->remote_addr);
1313 p_acl_cb->num_read_pages = num_read_pages;
1314 p_dev_rec->num_read_pages = num_read_pages;
1316 /* Process the pages one by one */
1317 for (page_idx = 0; page_idx < num_read_pages; page_idx++)
1319 btm_process_remote_ext_features_page (p_acl_cb, p_dev_rec, page_idx);
1324 /*******************************************************************************
1326 ** Function btm_process_remote_ext_features_page
1328 ** Description Local function called to process the information located
1329 ** in the specific extended features page read from a remote device.
1333 *******************************************************************************/
1334 void btm_process_remote_ext_features_page (tACL_CONN *p_acl_cb, tBTM_SEC_DEV_REC *p_dev_rec,
1340 handle = p_acl_cb->hci_handle;
1342 memcpy (p_dev_rec->features[page_idx], p_acl_cb->peer_lmp_features[page_idx],
1343 HCI_FEATURE_BYTES_PER_PAGE);
1347 /* Extended (Legacy) Page 0 */
1348 case HCI_EXT_FEATURES_PAGE_0:
1349 /* Page 0 indicates Controller support for SSP */
1350 if (btm_cb.security_mode < BTM_SEC_MODE_SP ||
1351 !HCI_SIMPLE_PAIRING_SUPPORTED(p_dev_rec->features[HCI_EXT_FEATURES_PAGE_0]))
1353 req_pend = (p_dev_rec->sm4 & BTM_SM4_REQ_PEND);
1354 p_dev_rec->sm4 = BTM_SM4_KNOWN;
1357 l2cu_resubmit_pending_sec_req (p_dev_rec->bd_addr);
1362 /* Extended Page 1 */
1363 case HCI_EXT_FEATURES_PAGE_1:
1364 /* Page 1 indicates Host support for SSP and SC */
1365 req_pend = (p_dev_rec->sm4 & BTM_SM4_REQ_PEND);
1367 if (btm_cb.security_mode == BTM_SEC_MODE_SP
1368 && HCI_SSP_HOST_SUPPORTED(p_dev_rec->features[HCI_EXT_FEATURES_PAGE_1])
1369 && HCI_SIMPLE_PAIRING_SUPPORTED(p_dev_rec->features[HCI_EXT_FEATURES_PAGE_0]))
1371 p_dev_rec->sm4 = BTM_SM4_TRUE;
1375 p_dev_rec->sm4 = BTM_SM4_KNOWN;
1378 BTM_TRACE_API ("ext_features_complt page_num:%d f[0]:x%02x, sm4:%x, pend:%d",
1379 HCI_EXT_FEATURES_PAGE_1, *(p_dev_rec->features[HCI_EXT_FEATURES_PAGE_1]),
1380 p_dev_rec->sm4, req_pend);
1383 l2cu_resubmit_pending_sec_req (p_dev_rec->bd_addr);
1387 /* Extended Page 2 */
1388 case HCI_EXT_FEATURES_PAGE_2:
1389 /* Page 2 indicates Ping support*/
1393 BTM_TRACE_ERROR("btm_process_remote_ext_features_page page=%d unexpected", page_idx);
1399 /*******************************************************************************
1401 ** Function btm_read_remote_features
1403 ** Description Local function called to send a read remote supported features/
1404 ** remote extended features page[0].
1408 *******************************************************************************/
1409 void btm_read_remote_features (UINT16 handle)
1412 tACL_CONN *p_acl_cb;
1414 BTM_TRACE_DEBUG("btm_read_remote_features() handle: %d", handle);
1416 if ((acl_idx = btm_handle_to_acl_index(handle)) >= MAX_L2CAP_LINKS)
1418 BTM_TRACE_ERROR("btm_read_remote_features handle=%d invalid", handle);
1422 p_acl_cb = &btm_cb.acl_db[acl_idx];
1423 p_acl_cb->num_read_pages = 0;
1424 memset (p_acl_cb->peer_lmp_features, 0, sizeof(p_acl_cb->peer_lmp_features));
1426 /* first send read remote supported features HCI command */
1427 /* because we don't know whether the remote support extended feature command */
1428 btsnd_hcic_rmt_features_req (handle);
1432 /*******************************************************************************
1434 ** Function btm_read_remote_ext_features
1436 ** Description Local function called to send a read remote extended features
1440 *******************************************************************************/
1441 void btm_read_remote_ext_features (UINT16 handle, UINT8 page_number)
1443 BTM_TRACE_DEBUG("btm_read_remote_ext_features() handle: %d page: %d", handle, page_number);
1445 btsnd_hcic_rmt_ext_features(handle, page_number);
1449 /*******************************************************************************
1451 ** Function btm_read_remote_features_complete
1453 ** Description This function is called when the remote supported features
1454 ** complete event is received from the HCI.
1458 *******************************************************************************/
1459 void btm_read_remote_features_complete (UINT8 *p)
1461 tACL_CONN *p_acl_cb;
1466 BTM_TRACE_DEBUG ("btm_read_remote_features_complete");
1467 STREAM_TO_UINT8 (status, p);
1469 if (status != HCI_SUCCESS)
1471 BTM_TRACE_ERROR ("btm_read_remote_features_complete failed (status 0x%02x)", status);
1475 STREAM_TO_UINT16 (handle, p);
1477 if ((acl_idx = btm_handle_to_acl_index(handle)) >= MAX_L2CAP_LINKS)
1479 BTM_TRACE_ERROR("btm_read_remote_features_complete handle=%d invalid", handle);
1483 p_acl_cb = &btm_cb.acl_db[acl_idx];
1485 /* Copy the received features page */
1486 STREAM_TO_ARRAY(p_acl_cb->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0], p,
1487 HCI_FEATURE_BYTES_PER_PAGE);
1489 if ((HCI_LMP_EXTENDED_SUPPORTED(p_acl_cb->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0])) &&
1490 (HCI_READ_REMOTE_EXT_FEATURES_SUPPORTED(btm_cb.devcb.supported_cmds)))
1492 /* if the remote controller has extended features and local controller supports
1493 ** HCI_Read_Remote_Extended_Features command then start reading these feature starting
1494 ** with extended features page 1 */
1495 BTM_TRACE_DEBUG ("Start reading remote extended features");
1496 btm_read_remote_ext_features(handle, HCI_EXT_FEATURES_PAGE_1);
1500 /* Remote controller has no extended features. Process remote controller supported features
1501 (features page HCI_EXT_FEATURES_PAGE_0). */
1502 btm_process_remote_ext_features (p_acl_cb, 1);
1504 /* Continue with HCI connection establishment */
1505 btm_establish_continue (p_acl_cb);
1508 /*******************************************************************************
1510 ** Function btm_read_remote_ext_features_complete
1512 ** Description This function is called when the remote extended features
1513 ** complete event is received from the HCI.
1517 *******************************************************************************/
1518 void btm_read_remote_ext_features_complete (UINT8 *p)
1520 tACL_CONN *p_acl_cb;
1521 UINT8 status, page_num, max_page;
1525 BTM_TRACE_DEBUG ("btm_read_remote_ext_features_complete");
1527 STREAM_TO_UINT8 (status, p);
1528 STREAM_TO_UINT16 (handle, p);
1529 STREAM_TO_UINT8 (page_num, p);
1530 STREAM_TO_UINT8 (max_page, p);
1532 /* Validate parameters */
1533 if ((acl_idx = btm_handle_to_acl_index(handle)) >= MAX_L2CAP_LINKS)
1535 BTM_TRACE_ERROR("btm_read_remote_ext_features_complete handle=%d invalid", handle);
1539 if (max_page > HCI_EXT_FEATURES_PAGE_MAX)
1541 BTM_TRACE_ERROR("btm_read_remote_ext_features_complete page=%d unknown", max_page);
1545 p_acl_cb = &btm_cb.acl_db[acl_idx];
1547 /* Copy the received features page */
1548 STREAM_TO_ARRAY(p_acl_cb->peer_lmp_features[page_num], p, HCI_FEATURE_BYTES_PER_PAGE);
1550 /* If there is the next remote features page and
1551 * we have space to keep this page data - read this page */
1552 if ((page_num < max_page) && (page_num < HCI_EXT_FEATURES_PAGE_MAX))
1555 BTM_TRACE_DEBUG("BTM reads next remote extended features page (%d)", page_num);
1556 btm_read_remote_ext_features (handle, page_num);
1560 /* Reading of remote feature pages is complete */
1561 BTM_TRACE_DEBUG("BTM reached last remote extended features page (%d)", page_num);
1563 /* Process the pages */
1564 btm_process_remote_ext_features (p_acl_cb, (UINT8) (page_num + 1));
1566 /* Continue with HCI connection establishment */
1567 btm_establish_continue (p_acl_cb);
1570 /*******************************************************************************
1572 ** Function btm_read_remote_ext_features_failed
1574 ** Description This function is called when the remote extended features
1575 ** complete event returns a failed status.
1579 *******************************************************************************/
1580 void btm_read_remote_ext_features_failed (UINT8 status, UINT16 handle)
1582 tACL_CONN *p_acl_cb;
1585 BTM_TRACE_WARNING ("btm_read_remote_ext_features_failed (status 0x%02x) for handle %d",
1588 if ((acl_idx = btm_handle_to_acl_index(handle)) >= MAX_L2CAP_LINKS)
1590 BTM_TRACE_ERROR("btm_read_remote_ext_features_failed handle=%d invalid", handle);
1594 p_acl_cb = &btm_cb.acl_db[acl_idx];
1596 /* Process supported features only */
1597 btm_process_remote_ext_features (p_acl_cb, 1);
1599 /* Continue HCI connection establishment */
1600 btm_establish_continue (p_acl_cb);
1603 /*******************************************************************************
1605 ** Function btm_establish_continue
1607 ** Description This function is called when the command complete message
1608 ** is received from the HCI for the read local link policy request.
1612 *******************************************************************************/
1613 void btm_establish_continue (tACL_CONN *p_acl_cb)
1615 #if (defined(BTM_BUSY_LEVEL_CHANGE_INCLUDED) && BTM_BUSY_LEVEL_CHANGE_INCLUDED == TRUE)
1616 tBTM_BL_EVENT_DATA evt_data;
1618 BTM_TRACE_DEBUG ("btm_establish_continue");
1619 #if (!defined(BTM_BYPASS_EXTRA_ACL_SETUP) || BTM_BYPASS_EXTRA_ACL_SETUP == FALSE)
1620 #if (defined BLE_INCLUDED && BLE_INCLUDED == TRUE)
1621 if (p_acl_cb->transport == BT_TRANSPORT_BR_EDR)
1624 /* For now there are a some devices that do not like sending */
1625 /* commands events and data at the same time. */
1626 /* Set the packet types to the default allowed by the device */
1627 btm_set_packet_types (p_acl_cb, btm_cb.btm_acl_pkt_types_supported);
1629 if (btm_cb.btm_def_link_policy)
1630 BTM_SetLinkPolicy (p_acl_cb->remote_addr, &btm_cb.btm_def_link_policy);
1633 p_acl_cb->link_up_issued = TRUE;
1635 /* If anyone cares, tell him database changed */
1636 #if (defined(BTM_BUSY_LEVEL_CHANGE_INCLUDED) && BTM_BUSY_LEVEL_CHANGE_INCLUDED == TRUE)
1637 if (btm_cb.p_bl_changed_cb)
1639 evt_data.event = BTM_BL_CONN_EVT;
1640 evt_data.conn.p_bda = p_acl_cb->remote_addr;
1641 evt_data.conn.p_bdn = p_acl_cb->remote_name;
1642 evt_data.conn.p_dc = p_acl_cb->remote_dc;
1643 evt_data.conn.p_features = p_acl_cb->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0];
1644 #if BLE_INCLUDED == TRUE
1645 evt_data.conn.handle = p_acl_cb->hci_handle;
1646 evt_data.conn.transport = p_acl_cb->transport;
1649 (*btm_cb.p_bl_changed_cb)(&evt_data);
1651 btm_acl_update_busy_level (BTM_BLI_ACL_UP_EVT);
1653 if (btm_cb.p_acl_changed_cb)
1654 #if BLE_INCLUDED == TRUE
1655 (*btm_cb.p_acl_changed_cb) (p_acl_cb->remote_addr,
1656 p_acl_cb->remote_dc,
1657 p_acl_cb->remote_name,
1658 p_acl_cb->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0],
1660 p_acl_cb->hci_handle,
1661 p_acl_cb->transport);
1663 (*btm_cb.p_acl_changed_cb) (p_acl_cb->remote_addr,
1664 p_acl_cb->remote_dc,
1665 p_acl_cb->remote_name,
1666 p_acl_cb->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0],
1675 /*******************************************************************************
1677 ** Function BTM_SetDefaultLinkSuperTout
1679 ** Description Set the default value for HCI "Write Link Supervision Timeout"
1680 ** command to use when an ACL link is created.
1684 *******************************************************************************/
1685 void BTM_SetDefaultLinkSuperTout (UINT16 timeout)
1687 BTM_TRACE_DEBUG ("BTM_SetDefaultLinkSuperTout");
1688 btm_cb.btm_def_link_super_tout = timeout;
1691 /*******************************************************************************
1693 ** Function BTM_GetLinkSuperTout
1695 ** Description Read the link supervision timeout value of the connection
1697 ** Returns status of the operation
1699 *******************************************************************************/
1700 tBTM_STATUS BTM_GetLinkSuperTout (BD_ADDR remote_bda, UINT16 *p_timeout)
1702 tACL_CONN *p = btm_bda_to_acl(remote_bda, BT_TRANSPORT_BR_EDR);
1704 BTM_TRACE_DEBUG ("BTM_GetLinkSuperTout");
1705 if (p != (tACL_CONN *)NULL)
1707 *p_timeout = p->link_super_tout;
1708 return(BTM_SUCCESS);
1710 /* If here, no BD Addr found */
1711 return(BTM_UNKNOWN_ADDR);
1715 /*******************************************************************************
1717 ** Function BTM_SetLinkSuperTout
1719 ** Description Create and send HCI "Write Link Supervision Timeout" command
1721 ** Returns status of the operation
1723 *******************************************************************************/
1724 tBTM_STATUS BTM_SetLinkSuperTout (BD_ADDR remote_bda, UINT16 timeout)
1726 tACL_CONN *p = btm_bda_to_acl(remote_bda, BT_TRANSPORT_BR_EDR);
1728 BTM_TRACE_DEBUG ("BTM_SetLinkSuperTout");
1729 if (p != (tACL_CONN *)NULL)
1731 p->link_super_tout = timeout;
1733 /* Only send if current role is Master; 2.0 spec requires this */
1734 if (p->link_role == BTM_ROLE_MASTER)
1736 if (!btsnd_hcic_write_link_super_tout (LOCAL_BR_EDR_CONTROLLER_ID,
1737 p->hci_handle, timeout))
1738 return(BTM_NO_RESOURCES);
1740 return(BTM_CMD_STARTED);
1743 return(BTM_SUCCESS);
1746 /* If here, no BD Addr found */
1747 return(BTM_UNKNOWN_ADDR);
1750 /*******************************************************************************
1752 ** Function BTM_RegForLstoEvt
1754 ** Description register for the HCI "Link Supervision Timeout Change" event
1758 *******************************************************************************/
1759 void BTM_RegForLstoEvt (tBTM_LSTO_CBACK *p_cback)
1761 BTM_TRACE_DEBUG ("BTM_RegForLstoEvt");
1762 btm_cb.p_lsto_cback = p_cback;
1765 /*******************************************************************************
1767 ** Function btm_proc_lsto_evt
1769 ** Description process the HCI "Link Supervision Timeout Change" event
1773 *******************************************************************************/
1774 void btm_proc_lsto_evt(UINT16 handle, UINT16 timeout)
1778 BTM_TRACE_DEBUG ("btm_proc_lsto_evt");
1779 if (btm_cb.p_lsto_cback)
1781 /* Look up the connection by handle and set the current mode */
1782 xx = btm_handle_to_acl_index(handle);
1784 /* don't assume that we can never get a bad hci_handle */
1785 if (xx < MAX_L2CAP_LINKS)
1787 (*btm_cb.p_lsto_cback)(btm_cb.acl_db[xx].remote_addr, timeout);
1792 #if BTM_PWR_MGR_INCLUDED == FALSE
1793 /*******************************************************************************
1795 ** Function BTM_SetHoldMode
1797 ** Description This function is called to set a connection into hold mode.
1798 ** A check is made if the connection is in sniff or park mode,
1799 ** and if yes, the hold mode is ignored.
1801 ** Returns status of the operation
1803 *******************************************************************************/
1804 tBTM_STATUS BTM_SetHoldMode (BD_ADDR remote_bda, UINT16 min_interval, UINT16 max_interval)
1808 BTM_TRACE_DEBUG ("BTM_SetHoldMode");
1809 /* First, check if hold mode is supported */
1810 if (!HCI_HOLD_MODE_SUPPORTED(BTM_ReadLocalFeatures()))
1811 return(BTM_MODE_UNSUPPORTED);
1813 p = btm_bda_to_acl(remote_bda, BT_TRANSPORT_BR_EDR);
1814 if (p != (tACL_CONN *)NULL)
1816 /* If the connection is in park or sniff mode, forget about holding it */
1817 if (p->mode != BTM_ACL_MODE_NORMAL)
1818 return(BTM_SUCCESS);
1820 if (!btsnd_hcic_hold_mode (p->hci_handle, max_interval, min_interval))
1821 return(BTM_NO_RESOURCES);
1823 return(BTM_CMD_STARTED);
1826 /* If here, no BD Addr found */
1827 return(BTM_UNKNOWN_ADDR);
1831 /*******************************************************************************
1833 ** Function BTM_SetSniffMode
1835 ** Description This function is called to set a connection into sniff mode.
1836 ** A check is made if the connection is already in sniff or park
1837 ** mode, and if yes, the sniff mode is ignored.
1839 ** Returns status of the operation
1841 *******************************************************************************/
1842 tBTM_STATUS BTM_SetSniffMode (BD_ADDR remote_bda, UINT16 min_period, UINT16 max_period,
1843 UINT16 attempt, UINT16 timeout)
1846 BTM_TRACE_DEBUG ("BTM_SetSniffMode");
1847 /* First, check if sniff mode is supported */
1848 if (!HCI_SNIFF_MODE_SUPPORTED(BTM_ReadLocalFeatures()))
1849 return(BTM_MODE_UNSUPPORTED);
1851 p = btm_bda_to_acl(remote_bda, BT_TRANSPORT_BR_EDR);
1852 if (p != (tACL_CONN *)NULL)
1854 /* If the connection is in park mode, forget about sniffing it */
1855 if (p->mode != BTM_ACL_MODE_NORMAL)
1856 return(BTM_WRONG_MODE);
1858 if (!btsnd_hcic_sniff_mode (p->hci_handle, max_period,
1859 min_period, attempt, timeout))
1860 return(BTM_NO_RESOURCES);
1862 return(BTM_CMD_STARTED);
1865 /* If here, no BD Addr found */
1866 return(BTM_UNKNOWN_ADDR);
1872 /*******************************************************************************
1874 ** Function BTM_CancelSniffMode
1876 ** Description This function is called to put a connection out of sniff mode.
1877 ** A check is made if the connection is already in sniff mode,
1878 ** and if not, the cancel sniff mode is ignored.
1880 ** Returns status of the operation
1882 *******************************************************************************/
1883 tBTM_STATUS BTM_CancelSniffMode (BD_ADDR remote_bda)
1885 tACL_CONN *p = btm_bda_to_acl(remote_bda, BT_TRANSPORT_BR_EDR);
1886 BTM_TRACE_DEBUG ("BTM_CancelSniffMode ");
1887 if (p == (tACL_CONN *)NULL)
1888 return(BTM_UNKNOWN_ADDR);
1890 /* If the connection is not in sniff mode, cannot cancel */
1891 if (p->mode != BTM_ACL_MODE_SNIFF)
1892 return(BTM_WRONG_MODE);
1894 if (!btsnd_hcic_exit_sniff_mode (p->hci_handle))
1895 return(BTM_NO_RESOURCES);
1897 return(BTM_CMD_STARTED);
1901 /*******************************************************************************
1903 ** Function BTM_SetParkMode
1905 ** Description This function is called to set a connection into park mode.
1906 ** A check is made if the connection is already in sniff or park
1907 ** mode, and if yes, the park mode is ignored.
1909 ** Returns status of the operation
1911 *******************************************************************************/
1912 tBTM_STATUS BTM_SetParkMode (BD_ADDR remote_bda, UINT16 beacon_min_period, UINT16 beacon_max_period)
1916 BTM_TRACE_DEBUG ("BTM_SetParkMode");
1917 /* First, check if park mode is supported */
1918 if (!HCI_PARK_MODE_SUPPORTED(BTM_ReadLocalFeatures()))
1919 return(BTM_MODE_UNSUPPORTED);
1921 p = btm_bda_to_acl(remote_bda, BT_TRANSPORT_BR_EDR);
1922 if (p != (tACL_CONN *)NULL)
1924 /* If the connection is in sniff mode, forget about parking it */
1925 if (p->mode != BTM_ACL_MODE_NORMAL)
1926 return(BTM_WRONG_MODE);
1928 /* no park mode if SCO exists -- CR#1982, 1.1 errata 1124
1929 command status event should be returned /w error code 0x0C "Command Disallowed"
1932 if (!btsnd_hcic_park_mode (p->hci_handle,
1933 beacon_max_period, beacon_min_period))
1934 return(BTM_NO_RESOURCES);
1936 return(BTM_CMD_STARTED);
1939 /* If here, no BD Addr found */
1940 return(BTM_UNKNOWN_ADDR);
1943 /*******************************************************************************
1945 ** Function BTM_CancelParkMode
1947 ** Description This function is called to put a connection out of park mode.
1948 ** A check is made if the connection is already in park mode,
1949 ** and if not, the cancel sniff mode is ignored.
1951 ** Returns status of the operation
1953 *******************************************************************************/
1954 tBTM_STATUS BTM_CancelParkMode (BD_ADDR remote_bda)
1958 BTM_TRACE_DEBUG ("BTM_CancelParkMode");
1959 p = btm_bda_to_acl(remote_bda, BT_TRANSPORT_BR_EDR);
1960 if (p != (tACL_CONN *)NULL)
1962 /* If the connection is not in park mode, cannot cancel */
1963 if (p->mode != BTM_ACL_MODE_PARK)
1964 return(BTM_WRONG_MODE);
1966 if (!btsnd_hcic_exit_park_mode (p->hci_handle))
1967 return(BTM_NO_RESOURCES);
1969 return(BTM_CMD_STARTED);
1972 /* If here, no BD Addr found */
1973 return(BTM_UNKNOWN_ADDR);
1975 #endif /* BTM_PWR_MGR_INCLUDED == FALSE */
1978 /*******************************************************************************
1980 ** Function BTM_SetPacketTypes
1982 ** Description This function is set the packet types used for a specific
1985 ** Returns status of the operation
1987 *******************************************************************************/
1988 tBTM_STATUS BTM_SetPacketTypes (BD_ADDR remote_bda, UINT16 pkt_types)
1991 BTM_TRACE_DEBUG ("BTM_SetPacketTypes");
1993 if ((p = btm_bda_to_acl(remote_bda, BT_TRANSPORT_BR_EDR)) != NULL)
1994 return(btm_set_packet_types (p, pkt_types));
1996 /* If here, no BD Addr found */
1997 return(BTM_UNKNOWN_ADDR);
2001 /*******************************************************************************
2003 ** Function BTM_ReadPacketTypes
2005 ** Description This function is set the packet types used for a specific
2008 ** Returns packet types supported for the connection, or 0 if no BD address
2010 *******************************************************************************/
2011 UINT16 BTM_ReadPacketTypes (BD_ADDR remote_bda)
2015 BTM_TRACE_DEBUG ("BTM_ReadPacketTypes");
2016 p = btm_bda_to_acl(remote_bda, BT_TRANSPORT_BR_EDR);
2017 if (p != (tACL_CONN *)NULL)
2019 return(p->pkt_types_mask);
2022 /* If here, no BD Addr found */
2027 /*******************************************************************************
2029 ** Function BTM_ReadAclMode
2031 ** Description This returns the current mode for a specific
2034 ** Input Param remote_bda - device address of desired ACL connection
2036 ** Output Param p_mode - address where the current mode is copied into.
2037 ** BTM_ACL_MODE_NORMAL
2038 ** BTM_ACL_MODE_HOLD
2039 ** BTM_ACL_MODE_SNIFF
2040 ** BTM_ACL_MODE_PARK
2041 ** (valid only if return code is BTM_SUCCESS)
2043 ** Returns BTM_SUCCESS if successful,
2044 ** BTM_UNKNOWN_ADDR if bd addr is not active or bad
2046 *******************************************************************************/
2047 #if BTM_PWR_MGR_INCLUDED == FALSE
2048 tBTM_STATUS BTM_ReadAclMode (BD_ADDR remote_bda, UINT8 *p_mode)
2052 BTM_TRACE_API ("BTM_ReadAclMode: RemBdAddr: %02x%02x%02x%02x%02x%02x",
2053 remote_bda[0], remote_bda[1], remote_bda[2],
2054 remote_bda[3], remote_bda[4], remote_bda[5]);
2056 p = btm_bda_to_acl(remote_bda, BT_TRANSPORT_BR_EDR);
2057 if (p != (tACL_CONN *)NULL)
2060 return(BTM_SUCCESS);
2063 /* If here, no BD Addr found */
2064 return(BTM_UNKNOWN_ADDR);
2066 #endif /* BTM_PWR_MGR_INCLUDED == FALSE */
2068 /*******************************************************************************
2070 ** Function BTM_ReadClockOffset
2072 ** Description This returns the clock offset for a specific
2075 ** Input Param remote_bda - device address of desired ACL connection
2077 ** Returns clock-offset or 0 if unknown
2079 *******************************************************************************/
2080 UINT16 BTM_ReadClockOffset (BD_ADDR remote_bda)
2084 BTM_TRACE_API ("BTM_ReadClockOffset: RemBdAddr: %02x%02x%02x%02x%02x%02x",
2085 remote_bda[0], remote_bda[1], remote_bda[2],
2086 remote_bda[3], remote_bda[4], remote_bda[5]);
2088 if ( (p = btm_bda_to_acl(remote_bda, BT_TRANSPORT_BR_EDR)) != NULL)
2089 return(p->clock_offset);
2091 /* If here, no BD Addr found */
2095 /*******************************************************************************
2097 ** Function BTM_IsAclConnectionUp
2099 ** Description This function is called to check if an ACL connection exists
2100 ** to a specific remote BD Address.
2102 ** Returns TRUE if connection is up, else FALSE.
2104 *******************************************************************************/
2105 BOOLEAN BTM_IsAclConnectionUp (BD_ADDR remote_bda, tBT_TRANSPORT transport)
2109 BTM_TRACE_API ("BTM_IsAclConnectionUp: RemBdAddr: %02x%02x%02x%02x%02x%02x",
2110 remote_bda[0], remote_bda[1], remote_bda[2],
2111 remote_bda[3], remote_bda[4], remote_bda[5]);
2113 p = btm_bda_to_acl(remote_bda, transport);
2114 if (p != (tACL_CONN *)NULL)
2119 /* If here, no BD Addr found */
2123 /*******************************************************************************
2125 ** Function BTM_GetNumAclLinks
2127 ** Description This function is called to count the number of
2128 ** ACL links that are active.
2130 ** Returns UINT16 Number of active ACL links
2132 *******************************************************************************/
2133 UINT16 BTM_GetNumAclLinks (void)
2135 #if (defined(BTM_BUSY_LEVEL_CHANGE_INCLUDED) && BTM_BUSY_LEVEL_CHANGE_INCLUDED == TRUE)
2136 return(UINT16)btm_cb.num_acl;
2138 tACL_CONN *p = &btm_cb.acl_db[0];
2140 BTM_TRACE_DEBUG ("BTM_GetNumAclLinks");
2141 for (xx = yy = 0; xx < MAX_L2CAP_LINKS; xx++, p++)
2151 /*******************************************************************************
2153 ** Function btm_get_acl_disc_reason_code
2155 ** Description This function is called to get the disconnection reason code
2156 ** returned by the HCI at disconnection complete event.
2158 ** Returns TRUE if connection is up, else FALSE.
2160 *******************************************************************************/
2161 UINT16 btm_get_acl_disc_reason_code (void)
2163 UINT8 res = btm_cb.acl_disc_reason;
2164 BTM_TRACE_DEBUG ("btm_get_acl_disc_reason_code");
2169 /*******************************************************************************
2171 ** Function BTM_GetHCIConnHandle
2173 ** Description This function is called to get the handle for an ACL connection
2174 ** to a specific remote BD Address.
2176 ** Returns the handle of the connection, or 0xFFFF if none.
2178 *******************************************************************************/
2179 UINT16 BTM_GetHCIConnHandle (BD_ADDR remote_bda, tBT_TRANSPORT transport)
2182 BTM_TRACE_DEBUG ("BTM_GetHCIConnHandle");
2183 p = btm_bda_to_acl(remote_bda, transport);
2184 if (p != (tACL_CONN *)NULL)
2186 return(p->hci_handle);
2189 /* If here, no BD Addr found */
2193 #if BTM_PWR_MGR_INCLUDED == FALSE
2194 /*******************************************************************************
2196 ** Function btm_process_mode_change
2198 ** Description This function is called when an HCI mode change event occurs.
2200 ** Input Parms hci_status - status of the event (HCI_SUCCESS if no errors)
2201 ** hci_handle - connection handle associated with the change
2202 ** mode - HCI_MODE_ACTIVE, HCI_MODE_HOLD, HCI_MODE_SNIFF, or HCI_MODE_PARK
2203 ** interval - number of baseband slots (meaning depends on mode)
2207 *******************************************************************************/
2208 void btm_process_mode_change (UINT8 hci_status, UINT16 hci_handle, UINT8 mode, UINT16 interval)
2212 BTM_TRACE_DEBUG ("btm_process_mode_change");
2213 if (hci_status != HCI_SUCCESS)
2215 BTM_TRACE_WARNING ("BTM: HCI Mode Change Error Status: 0x%02x", hci_status);
2218 /* Look up the connection by handle and set the current mode */
2219 xx = btm_handle_to_acl_index(hci_handle);
2221 /* don't assume that we can never get a bad hci_handle */
2222 if (xx >= MAX_L2CAP_LINKS)
2225 p = &btm_cb.acl_db[xx];
2227 /* If status is not success mode does not mean anything */
2228 if (hci_status == HCI_SUCCESS)
2231 /* If mode change was because of an active role switch or change link key */
2232 btm_cont_rswitch_or_chglinkkey(p, btm_find_dev(p->remote_addr), hci_status);
2234 #endif /* BTM_PWR_MGR_INCLUDED == FALSE */
2236 /*******************************************************************************
2238 ** Function btm_process_clk_off_comp_evt
2240 ** Description This function is called when clock offset command completes.
2242 ** Input Parms hci_handle - connection handle associated with the change
2247 *******************************************************************************/
2248 void btm_process_clk_off_comp_evt (UINT16 hci_handle, UINT16 clock_offset)
2251 BTM_TRACE_DEBUG ("btm_process_clk_off_comp_evt");
2252 /* Look up the connection by handle and set the current mode */
2253 if ((xx = btm_handle_to_acl_index(hci_handle)) < MAX_L2CAP_LINKS)
2254 btm_cb.acl_db[xx].clock_offset = clock_offset;
2257 /*******************************************************************************
2259 ** Function btm_acl_role_changed
2261 ** Description This function is called whan a link's master/slave role change
2262 ** event or command status event (with error) is received.
2263 ** It updates the link control block, and calls
2264 ** the registered callback with status and role (if registered).
2268 *******************************************************************************/
2269 void btm_acl_role_changed (UINT8 hci_status, BD_ADDR bd_addr, UINT8 new_role)
2271 UINT8 *p_bda = (bd_addr) ? bd_addr :
2272 btm_cb.devcb.switch_role_ref_data.remote_bd_addr;
2273 tACL_CONN *p = btm_bda_to_acl(p_bda, BT_TRANSPORT_BR_EDR);
2274 tBTM_ROLE_SWITCH_CMPL *p_data = &btm_cb.devcb.switch_role_ref_data;
2275 tBTM_SEC_DEV_REC *p_dev_rec;
2276 #if (defined(BTM_BUSY_LEVEL_CHANGE_INCLUDED) && BTM_BUSY_LEVEL_CHANGE_INCLUDED == TRUE)
2277 tBTM_BL_ROLE_CHG_DATA evt;
2280 BTM_TRACE_DEBUG ("btm_acl_role_changed");
2281 /* Ignore any stray events */
2284 /* it could be a failure */
2285 if (hci_status != HCI_SUCCESS)
2286 btm_acl_report_role_change(hci_status, bd_addr);
2290 p_data->hci_status = hci_status;
2292 if (hci_status == HCI_SUCCESS)
2294 p_data->role = new_role;
2295 memcpy(p_data->remote_bd_addr, p_bda, BD_ADDR_LEN);
2297 /* Update cached value */
2298 p->link_role = new_role;
2300 /* Reload LSTO: link supervision timeout is reset in the LM after a role switch */
2301 if (new_role == BTM_ROLE_MASTER)
2303 BTM_SetLinkSuperTout (p->remote_addr, p->link_super_tout);
2308 /* so the BTM_BL_ROLE_CHG_EVT uses the old role */
2309 new_role = p->link_role;
2312 /* Check if any SCO req is pending for role change */
2313 btm_sco_chk_pend_rolechange (p->hci_handle);
2315 /* if switching state is switching we need to turn encryption on */
2316 /* if idle, we did not change encryption */
2317 if (p->switch_role_state == BTM_ACL_SWKEY_STATE_SWITCHING)
2319 /* Make sure there's not also a change link key going on before re-enabling */
2320 if (p->change_key_state != BTM_ACL_SWKEY_STATE_SWITCHING)
2322 if (btsnd_hcic_set_conn_encrypt (p->hci_handle, TRUE))
2324 p->encrypt_state = BTM_ACL_ENCRYPT_STATE_ENCRYPT_ON;
2325 p->switch_role_state = BTM_ACL_SWKEY_STATE_ENCRYPTION_ON;
2329 else /* Set the state and wait for change link key */
2331 p->switch_role_state = BTM_ACL_SWKEY_STATE_ENCRYPTION_ON;
2336 /* Set the switch_role_state to IDLE since the reply received from HCI */
2337 /* regardless of its result either success or failed. */
2338 if (p->switch_role_state == BTM_ACL_SWKEY_STATE_IN_PROGRESS)
2340 p->switch_role_state = BTM_ACL_SWKEY_STATE_IDLE;
2341 p->encrypt_state = BTM_ACL_ENCRYPT_STATE_IDLE;
2344 /* if role switch complete is needed, report it now */
2345 btm_acl_report_role_change(hci_status, bd_addr);
2347 #if (defined(BTM_BUSY_LEVEL_CHANGE_INCLUDED) && BTM_BUSY_LEVEL_CHANGE_INCLUDED == TRUE)
2348 /* if role change event is registered, report it now */
2349 if (btm_cb.p_bl_changed_cb && (btm_cb.bl_evt_mask & BTM_BL_ROLE_CHG_MASK))
2351 evt.event = BTM_BL_ROLE_CHG_EVT;
2352 evt.new_role = new_role;
2354 evt.hci_status = hci_status;
2355 (*btm_cb.p_bl_changed_cb)((tBTM_BL_EVENT_DATA *)&evt);
2358 BTM_TRACE_DEBUG("Role Switch Event: new_role 0x%02x, HCI Status 0x%02x, rs_st:%d",
2359 p_data->role, p_data->hci_status, p->switch_role_state);
2362 #if BTM_DISC_DURING_RS == TRUE
2363 /* If a disconnect is pending, issue it now that role switch has completed */
2364 if ((p_dev_rec = btm_find_dev (p_bda)) != NULL)
2366 if (p_dev_rec->rs_disc_pending == BTM_SEC_DISC_PENDING)
2368 BTM_TRACE_WARNING("btm_acl_role_changed -> Issuing delayed HCI_Disconnect!!!");
2369 btsnd_hcic_disconnect(p_dev_rec->hci_handle, HCI_ERR_PEER_USER);
2371 BTM_TRACE_ERROR("tBTM_SEC_DEV:0x%x rs_disc_pending=%d",
2372 (UINT32)p_dev_rec, p_dev_rec->rs_disc_pending);
2373 p_dev_rec->rs_disc_pending = BTM_SEC_RS_NOT_PENDING; /* reset flag */
2380 #if (RFCOMM_INCLUDED==TRUE)
2381 /*******************************************************************************
2383 ** Function BTM_AllocateSCN
2385 ** Description Look through the Server Channel Numbers for a free one.
2387 ** Returns Allocated SCN number or 0 if none.
2389 *******************************************************************************/
2391 UINT8 BTM_AllocateSCN(void)
2394 BTM_TRACE_DEBUG ("BTM_AllocateSCN");
2396 // stack reserves scn 1 for HFP, HSP we still do the correct way
2397 for (x = 1; x < BTM_MAX_SCN; x++)
2399 if (!btm_cb.btm_scn[x])
2401 btm_cb.btm_scn[x] = TRUE;
2406 return(0); /* No free ports */
2409 /*******************************************************************************
2411 ** Function BTM_TryAllocateSCN
2413 ** Description Try to allocate a fixed server channel
2415 ** Returns Returns TRUE if server channel was available
2417 *******************************************************************************/
2419 BOOLEAN BTM_TryAllocateSCN(UINT8 scn)
2423 /* Make sure we don't exceed max port range.
2424 * Stack reserves scn 1 for HFP, HSP we still do the correct way.
2426 if ( (scn>=BTM_MAX_SCN) || (scn == 1) )
2429 /* check if this port is available */
2430 if (!btm_cb.btm_scn[scn-1])
2432 btm_cb.btm_scn[scn-1] = TRUE;
2436 return (FALSE); /* Port was busy */
2439 /*******************************************************************************
2441 ** Function BTM_FreeSCN
2443 ** Description Free the specified SCN.
2445 ** Returns TRUE or FALSE
2447 *******************************************************************************/
2448 BOOLEAN BTM_FreeSCN(UINT8 scn)
2450 BTM_TRACE_DEBUG ("BTM_FreeSCN ");
2451 if (scn <= BTM_MAX_SCN)
2453 btm_cb.btm_scn[scn-1] = FALSE;
2457 return(FALSE); /* Illegal SCN passed in */
2462 /* Make dummy functions for the RPC to link against */
2463 UINT8 BTM_AllocateSCN(void)
2468 BOOLEAN BTM_FreeSCN(UINT8 scn)
2476 /*******************************************************************************
2478 ** Function btm_acl_timeout
2480 ** Description This function is called when a timer list entry expires.
2484 *******************************************************************************/
2485 void btm_acl_timeout (TIMER_LIST_ENT *p_tle)
2487 UINT32 timer_type = p_tle->param;
2489 BTM_TRACE_DEBUG ("btm_acl_timeout");
2490 if (timer_type == TT_DEV_RLNKP)
2492 tBTM_CMPL_CB *p_cb = btm_cb.devcb.p_rlinkp_cmpl_cb;
2493 tBTM_LNK_POLICY_RESULTS lnkpol;
2495 lnkpol.status = BTM_ERR_PROCESSING;
2496 lnkpol.settings = 0;
2498 btm_cb.devcb.p_rlinkp_cmpl_cb = NULL;
2505 /*******************************************************************************
2507 ** Function btm_set_packet_types
2509 ** Description This function sets the packet types used for a specific
2510 ** ACL connection. It is called internally by btm_acl_created
2511 ** or by an application/profile by BTM_SetPacketTypes.
2513 ** Returns status of the operation
2515 *******************************************************************************/
2516 tBTM_STATUS btm_set_packet_types (tACL_CONN *p, UINT16 pkt_types)
2518 UINT16 temp_pkt_types;
2519 BTM_TRACE_DEBUG ("btm_set_packet_types");
2520 /* Save in the ACL control blocks, types that we support */
2521 temp_pkt_types = (pkt_types & BTM_ACL_SUPPORTED_PKTS_MASK &
2522 btm_cb.btm_acl_pkt_types_supported);
2524 /* OR in any exception packet types if at least 2.0 version of spec */
2525 if (btm_cb.devcb.local_version.hci_version >= HCI_PROTO_VERSION_2_0)
2527 temp_pkt_types |= ((pkt_types & BTM_ACL_EXCEPTION_PKTS_MASK) |
2528 (btm_cb.btm_acl_pkt_types_supported & BTM_ACL_EXCEPTION_PKTS_MASK));
2532 temp_pkt_types &= (~BTM_ACL_EXCEPTION_PKTS_MASK);
2535 /* Exclude packet types not supported by the peer */
2536 btm_acl_chk_peer_pkt_type_support (p, &temp_pkt_types);
2538 BTM_TRACE_DEBUG ("SetPacketType Mask -> 0x%04x", temp_pkt_types);
2540 if (!btsnd_hcic_change_conn_type (p->hci_handle, temp_pkt_types))
2542 return(BTM_NO_RESOURCES);
2545 p->pkt_types_mask = temp_pkt_types;
2547 return(BTM_CMD_STARTED);
2550 /*******************************************************************************
2552 ** Function btm_get_max_packet_size
2554 ** Returns Returns maximum packet size that can be used for current
2555 ** connection, 0 if connection is not established
2557 *******************************************************************************/
2558 UINT16 btm_get_max_packet_size (BD_ADDR addr)
2560 tACL_CONN *p = btm_bda_to_acl(addr, BT_TRANSPORT_BR_EDR);
2561 UINT16 pkt_types = 0;
2562 UINT16 pkt_size = 0;
2563 BTM_TRACE_DEBUG ("btm_get_max_packet_size");
2566 pkt_types = p->pkt_types_mask;
2570 /* Special case for when info for the local device is requested */
2571 if (memcmp (btm_cb.devcb.local_addr, addr, BD_ADDR_LEN) == 0)
2573 pkt_types = btm_cb.btm_acl_pkt_types_supported;
2579 if (!(pkt_types & BTM_ACL_PKT_TYPES_MASK_NO_3_DH5))
2580 pkt_size = HCI_EDR3_DH5_PACKET_SIZE;
2581 else if (!(pkt_types & BTM_ACL_PKT_TYPES_MASK_NO_2_DH5))
2582 pkt_size = HCI_EDR2_DH5_PACKET_SIZE;
2583 else if (!(pkt_types & BTM_ACL_PKT_TYPES_MASK_NO_3_DH3))
2584 pkt_size = HCI_EDR3_DH3_PACKET_SIZE;
2585 else if (pkt_types & BTM_ACL_PKT_TYPES_MASK_DH5)
2586 pkt_size = HCI_DH5_PACKET_SIZE;
2587 else if (!(pkt_types & BTM_ACL_PKT_TYPES_MASK_NO_2_DH3))
2588 pkt_size = HCI_EDR2_DH3_PACKET_SIZE;
2589 else if (pkt_types & BTM_ACL_PKT_TYPES_MASK_DM5)
2590 pkt_size = HCI_DM5_PACKET_SIZE;
2591 else if (pkt_types & BTM_ACL_PKT_TYPES_MASK_DH3)
2592 pkt_size = HCI_DH3_PACKET_SIZE;
2593 else if (pkt_types & BTM_ACL_PKT_TYPES_MASK_DM3)
2594 pkt_size = HCI_DM3_PACKET_SIZE;
2595 else if (!(pkt_types & BTM_ACL_PKT_TYPES_MASK_NO_3_DH1))
2596 pkt_size = HCI_EDR3_DH1_PACKET_SIZE;
2597 else if (!(pkt_types & BTM_ACL_PKT_TYPES_MASK_NO_2_DH1))
2598 pkt_size = HCI_EDR2_DH1_PACKET_SIZE;
2599 else if (pkt_types & BTM_ACL_PKT_TYPES_MASK_DH1)
2600 pkt_size = HCI_DH1_PACKET_SIZE;
2601 else if (pkt_types & BTM_ACL_PKT_TYPES_MASK_DM1)
2602 pkt_size = HCI_DM1_PACKET_SIZE;
2608 /*******************************************************************************
2610 ** Function BTM_ReadRemoteVersion
2612 ** Returns If connected report peer device info
2614 *******************************************************************************/
2615 tBTM_STATUS BTM_ReadRemoteVersion (BD_ADDR addr, UINT8 *lmp_version,
2616 UINT16 *manufacturer, UINT16 *lmp_sub_version)
2618 tACL_CONN *p = btm_bda_to_acl(addr, BT_TRANSPORT_BR_EDR);
2619 BTM_TRACE_DEBUG ("BTM_ReadRemoteVersion");
2621 return(BTM_UNKNOWN_ADDR);
2624 *lmp_version = p->lmp_version;
2627 *manufacturer = p->manufacturer;
2629 if (lmp_sub_version)
2630 *lmp_sub_version = p->lmp_subversion;
2632 return(BTM_SUCCESS);
2635 /*******************************************************************************
2637 ** Function BTM_ReadRemoteFeatures
2639 ** Returns pointer to the remote supported features mask (8 bytes)
2641 *******************************************************************************/
2642 UINT8 *BTM_ReadRemoteFeatures (BD_ADDR addr)
2644 tACL_CONN *p = btm_bda_to_acl(addr, BT_TRANSPORT_BR_EDR);
2645 BTM_TRACE_DEBUG ("BTM_ReadRemoteFeatures");
2651 return(p->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0]);
2654 /*******************************************************************************
2656 ** Function BTM_ReadRemoteExtendedFeatures
2658 ** Returns pointer to the remote extended features mask (8 bytes)
2659 ** or NULL if bad page
2661 *******************************************************************************/
2662 UINT8 *BTM_ReadRemoteExtendedFeatures (BD_ADDR addr, UINT8 page_number)
2664 tACL_CONN *p = btm_bda_to_acl(addr, BT_TRANSPORT_BR_EDR);
2665 BTM_TRACE_DEBUG ("BTM_ReadRemoteExtendedFeatures");
2671 if (page_number > HCI_EXT_FEATURES_PAGE_MAX)
2673 BTM_TRACE_ERROR("Warning: BTM_ReadRemoteExtendedFeatures page %d unknown", page_number);
2677 return(p->peer_lmp_features[page_number]);
2680 /*******************************************************************************
2682 ** Function BTM_ReadNumberRemoteFeaturesPages
2684 ** Returns number of features pages read from the remote device.
2686 *******************************************************************************/
2687 UINT8 BTM_ReadNumberRemoteFeaturesPages (BD_ADDR addr)
2689 tACL_CONN *p = btm_bda_to_acl(addr, BT_TRANSPORT_BR_EDR);
2690 BTM_TRACE_DEBUG ("BTM_ReadNumberRemoteFeaturesPages");
2696 return(p->num_read_pages);
2699 /*******************************************************************************
2701 ** Function BTM_ReadAllRemoteFeatures
2703 ** Returns pointer to all features of the remote (24 bytes).
2705 *******************************************************************************/
2706 UINT8 *BTM_ReadAllRemoteFeatures (BD_ADDR addr)
2708 tACL_CONN *p = btm_bda_to_acl(addr, BT_TRANSPORT_BR_EDR);
2709 BTM_TRACE_DEBUG ("BTM_ReadAllRemoteFeatures");
2715 return(p->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0]);
2718 /*******************************************************************************
2720 ** Function BTM_RegBusyLevelNotif
2722 ** Description This function is called to register a callback to receive
2723 ** busy level change events.
2725 ** Returns BTM_SUCCESS if successfully registered, otherwise error
2727 *******************************************************************************/
2728 #if (defined(BTM_BUSY_LEVEL_CHANGE_INCLUDED) && BTM_BUSY_LEVEL_CHANGE_INCLUDED == TRUE)
2729 tBTM_STATUS BTM_RegBusyLevelNotif (tBTM_BL_CHANGE_CB *p_cb, UINT8 *p_level,
2730 tBTM_BL_EVENT_MASK evt_mask)
2732 BTM_TRACE_DEBUG ("BTM_RegBusyLevelNotif");
2734 *p_level = btm_cb.busy_level;
2736 btm_cb.bl_evt_mask = evt_mask;
2739 btm_cb.p_bl_changed_cb = NULL;
2740 else if (btm_cb.p_bl_changed_cb)
2743 btm_cb.p_bl_changed_cb = p_cb;
2745 return(BTM_SUCCESS);
2748 /*******************************************************************************
2750 ** Function BTM_AclRegisterForChanges
2752 ** Returns This function is called to register a callback for when the
2753 ** ACL database changes, i.e. new entry or entry deleted.
2755 *******************************************************************************/
2756 tBTM_STATUS BTM_AclRegisterForChanges (tBTM_ACL_DB_CHANGE_CB *p_cb)
2758 BTM_TRACE_DEBUG ("BTM_AclRegisterForChanges");
2760 btm_cb.p_acl_changed_cb = NULL;
2761 else if (btm_cb.p_acl_changed_cb)
2764 btm_cb.p_acl_changed_cb = p_cb;
2766 return(BTM_SUCCESS);
2770 /*******************************************************************************
2772 ** Function BTM_SetQoS
2774 ** Description This function is called to setup QoS
2776 ** Returns status of the operation
2778 *******************************************************************************/
2779 tBTM_STATUS BTM_SetQoS (BD_ADDR bd, FLOW_SPEC *p_flow, tBTM_CMPL_CB *p_cb)
2781 tACL_CONN *p = &btm_cb.acl_db[0];
2783 BTM_TRACE_API ("BTM_SetQoS: BdAddr: %02x%02x%02x%02x%02x%02x",
2784 bd[0], bd[1], bd[2],
2785 bd[3], bd[4], bd[5]);
2787 /* If someone already waiting on the version, do not allow another */
2788 if (btm_cb.devcb.p_qossu_cmpl_cb)
2791 if ( (p = btm_bda_to_acl(bd, BT_TRANSPORT_BR_EDR)) != NULL)
2793 btu_start_timer (&btm_cb.devcb.qossu_timer, BTU_TTYPE_BTM_ACL, BTM_DEV_REPLY_TIMEOUT);
2794 btm_cb.devcb.p_qossu_cmpl_cb = p_cb;
2796 if (!btsnd_hcic_qos_setup (p->hci_handle, p_flow->qos_flags, p_flow->service_type,
2797 p_flow->token_rate, p_flow->peak_bandwidth,
2798 p_flow->latency,p_flow->delay_variation))
2800 btm_cb.devcb.p_qossu_cmpl_cb = NULL;
2801 btu_stop_timer(&btm_cb.devcb.qossu_timer);
2802 return(BTM_NO_RESOURCES);
2805 return(BTM_CMD_STARTED);
2808 /* If here, no BD Addr found */
2809 return(BTM_UNKNOWN_ADDR);
2812 /*******************************************************************************
2814 ** Function btm_qos_setup_complete
2816 ** Description This function is called when the command complete message
2817 ** is received from the HCI for the qos setup request.
2821 *******************************************************************************/
2822 void btm_qos_setup_complete (UINT8 status, UINT16 handle, FLOW_SPEC *p_flow)
2824 tBTM_CMPL_CB *p_cb = btm_cb.devcb.p_qossu_cmpl_cb;
2825 tBTM_QOS_SETUP_CMPL qossu;
2826 BTM_TRACE_DEBUG ("btm_qos_setup_complete");
2827 btu_stop_timer (&btm_cb.devcb.qossu_timer);
2829 btm_cb.devcb.p_qossu_cmpl_cb = NULL;
2833 memset(&qossu, 0, sizeof(tBTM_QOS_SETUP_CMPL));
2834 qossu.status = status;
2835 qossu.handle = handle;
2838 qossu.flow.qos_flags = p_flow->qos_flags;
2839 qossu.flow.service_type = p_flow->service_type;
2840 qossu.flow.token_rate = p_flow->token_rate;
2841 qossu.flow.peak_bandwidth = p_flow->peak_bandwidth;
2842 qossu.flow.latency = p_flow->latency;
2843 qossu.flow.delay_variation = p_flow->delay_variation;
2845 BTM_TRACE_DEBUG ("BTM: p_flow->delay_variation: 0x%02x",
2846 qossu.flow.delay_variation);
2852 /*******************************************************************************
2854 ** Function BTM_ReadRSSI
2856 ** Description This function is called to read the link policy settings.
2857 ** The address of link policy results are returned in the callback.
2858 ** (tBTM_RSSI_RESULTS)
2860 ** Returns BTM_CMD_STARTED if successfully initiated or error code
2862 *******************************************************************************/
2863 tBTM_STATUS BTM_ReadRSSI (BD_ADDR remote_bda, tBTM_CMPL_CB *p_cb)
2866 tBT_TRANSPORT transport = BT_TRANSPORT_BR_EDR;
2867 #if BLE_INCLUDED == TRUE
2868 tBT_DEVICE_TYPE dev_type;
2869 tBLE_ADDR_TYPE addr_type;
2871 BTM_TRACE_API ("BTM_ReadRSSI: RemBdAddr: %02x%02x%02x%02x%02x%02x",
2872 remote_bda[0], remote_bda[1], remote_bda[2],
2873 remote_bda[3], remote_bda[4], remote_bda[5]);
2875 /* If someone already waiting on the version, do not allow another */
2876 if (btm_cb.devcb.p_rssi_cmpl_cb)
2879 #if BLE_INCLUDED == TRUE
2880 BTM_ReadDevInfo(remote_bda, &dev_type, &addr_type);
2881 if (dev_type == BT_DEVICE_TYPE_BLE)
2882 transport = BT_TRANSPORT_LE;
2885 p = btm_bda_to_acl(remote_bda, transport);
2886 if (p != (tACL_CONN *)NULL)
2888 btu_start_timer (&btm_cb.devcb.rssi_timer, BTU_TTYPE_BTM_ACL,
2889 BTM_DEV_REPLY_TIMEOUT);
2891 btm_cb.devcb.p_rssi_cmpl_cb = p_cb;
2893 if (!btsnd_hcic_read_rssi (p->hci_handle))
2895 btm_cb.devcb.p_rssi_cmpl_cb = NULL;
2896 btu_stop_timer (&btm_cb.devcb.rssi_timer);
2897 return(BTM_NO_RESOURCES);
2900 return(BTM_CMD_STARTED);
2903 /* If here, no BD Addr found */
2904 return(BTM_UNKNOWN_ADDR);
2907 /*******************************************************************************
2909 ** Function BTM_ReadLinkQuality
2911 ** Description This function is called to read the link qulaity.
2912 ** The value of the link quality is returned in the callback.
2913 ** (tBTM_LINK_QUALITY_RESULTS)
2915 ** Returns BTM_CMD_STARTED if successfully initiated or error code
2917 *******************************************************************************/
2918 tBTM_STATUS BTM_ReadLinkQuality (BD_ADDR remote_bda, tBTM_CMPL_CB *p_cb)
2922 BTM_TRACE_API ("BTM_ReadLinkQuality: RemBdAddr: %02x%02x%02x%02x%02x%02x",
2923 remote_bda[0], remote_bda[1], remote_bda[2],
2924 remote_bda[3], remote_bda[4], remote_bda[5]);
2926 /* If someone already waiting on the version, do not allow another */
2927 if (btm_cb.devcb.p_lnk_qual_cmpl_cb)
2930 p = btm_bda_to_acl(remote_bda, BT_TRANSPORT_BR_EDR);
2931 if (p != (tACL_CONN *)NULL)
2933 btu_start_timer (&btm_cb.devcb.lnk_quality_timer, BTU_TTYPE_BTM_ACL,
2934 BTM_DEV_REPLY_TIMEOUT);
2935 btm_cb.devcb.p_lnk_qual_cmpl_cb = p_cb;
2937 if (!btsnd_hcic_get_link_quality (p->hci_handle))
2939 btu_stop_timer (&btm_cb.devcb.lnk_quality_timer);
2940 btm_cb.devcb.p_lnk_qual_cmpl_cb = NULL;
2941 return(BTM_NO_RESOURCES);
2944 return(BTM_CMD_STARTED);
2947 /* If here, no BD Addr found */
2948 return(BTM_UNKNOWN_ADDR);
2951 /*******************************************************************************
2953 ** Function BTM_ReadTxPower
2955 ** Description This function is called to read the current
2956 ** TX power of the connection. The tx power level results
2957 ** are returned in the callback.
2958 ** (tBTM_RSSI_RESULTS)
2960 ** Returns BTM_CMD_STARTED if successfully initiated or error code
2962 *******************************************************************************/
2963 tBTM_STATUS BTM_ReadTxPower (BD_ADDR remote_bda, tBT_TRANSPORT transport, tBTM_CMPL_CB *p_cb)
2967 #define BTM_READ_RSSI_TYPE_CUR 0x00
2968 #define BTM_READ_RSSI_TYPE_MAX 0X01
2970 BTM_TRACE_API ("BTM_ReadTxPower: RemBdAddr: %02x%02x%02x%02x%02x%02x",
2971 remote_bda[0], remote_bda[1], remote_bda[2],
2972 remote_bda[3], remote_bda[4], remote_bda[5]);
2974 /* If someone already waiting on the version, do not allow another */
2975 if (btm_cb.devcb.p_tx_power_cmpl_cb)
2978 p = btm_bda_to_acl(remote_bda, transport);
2979 if (p != (tACL_CONN *)NULL)
2981 btu_start_timer (&btm_cb.devcb.tx_power_timer, BTU_TTYPE_BTM_ACL,
2982 BTM_DEV_REPLY_TIMEOUT);
2984 btm_cb.devcb.p_tx_power_cmpl_cb = p_cb;
2986 #if BLE_INCLUDED == TRUE
2987 if (p->transport == BT_TRANSPORT_LE)
2989 memcpy(btm_cb.devcb.read_tx_pwr_addr, remote_bda, BD_ADDR_LEN);
2990 ret = btsnd_hcic_ble_read_adv_chnl_tx_power();
2995 ret = btsnd_hcic_read_tx_power (p->hci_handle, BTM_READ_RSSI_TYPE_CUR);
2999 btm_cb.devcb.p_tx_power_cmpl_cb = NULL;
3000 btu_stop_timer (&btm_cb.devcb.tx_power_timer);
3001 return(BTM_NO_RESOURCES);
3004 return(BTM_CMD_STARTED);
3007 /* If here, no BD Addr found */
3008 return (BTM_UNKNOWN_ADDR);
3010 /*******************************************************************************
3012 ** Function btm_read_tx_power_complete
3014 ** Description This function is called when the command complete message
3015 ** is received from the HCI for the read tx power request.
3019 *******************************************************************************/
3020 void btm_read_tx_power_complete (UINT8 *p, BOOLEAN is_ble)
3022 tBTM_CMPL_CB *p_cb = btm_cb.devcb.p_tx_power_cmpl_cb;
3023 tBTM_TX_POWER_RESULTS results;
3025 tACL_CONN *p_acl_cb = &btm_cb.acl_db[0];
3027 BTM_TRACE_DEBUG ("btm_read_tx_power_complete");
3028 btu_stop_timer (&btm_cb.devcb.tx_power_timer);
3030 /* If there was a callback registered for read rssi, call it */
3031 btm_cb.devcb.p_tx_power_cmpl_cb = NULL;
3035 STREAM_TO_UINT8 (results.hci_status, p);
3037 if (results.hci_status == HCI_SUCCESS)
3039 results.status = BTM_SUCCESS;
3043 STREAM_TO_UINT16 (handle, p);
3044 STREAM_TO_UINT8 (results.tx_power, p);
3046 /* Search through the list of active channels for the correct BD Addr */
3047 for (index = 0; index < MAX_L2CAP_LINKS; index++, p_acl_cb++)
3049 if ((p_acl_cb->in_use) && (handle == p_acl_cb->hci_handle))
3051 memcpy (results.rem_bda, p_acl_cb->remote_addr, BD_ADDR_LEN);
3056 #if BLE_INCLUDED == TRUE
3059 STREAM_TO_UINT8 (results.tx_power, p);
3060 memcpy(results.rem_bda, btm_cb.devcb.read_tx_pwr_addr, BD_ADDR_LEN);
3063 BTM_TRACE_DEBUG ("BTM TX power Complete: tx_power %d, hci status 0x%02x",
3064 results.tx_power, results.hci_status);
3067 results.status = BTM_ERR_PROCESSING;
3073 /*******************************************************************************
3075 ** Function btm_read_rssi_complete
3077 ** Description This function is called when the command complete message
3078 ** is received from the HCI for the read rssi request.
3082 *******************************************************************************/
3083 void btm_read_rssi_complete (UINT8 *p)
3085 tBTM_CMPL_CB *p_cb = btm_cb.devcb.p_rssi_cmpl_cb;
3086 tBTM_RSSI_RESULTS results;
3088 tACL_CONN *p_acl_cb = &btm_cb.acl_db[0];
3090 BTM_TRACE_DEBUG ("btm_read_rssi_complete");
3091 btu_stop_timer (&btm_cb.devcb.rssi_timer);
3093 /* If there was a callback registered for read rssi, call it */
3094 btm_cb.devcb.p_rssi_cmpl_cb = NULL;
3098 STREAM_TO_UINT8 (results.hci_status, p);
3100 if (results.hci_status == HCI_SUCCESS)
3102 results.status = BTM_SUCCESS;
3104 STREAM_TO_UINT16 (handle, p);
3106 STREAM_TO_UINT8 (results.rssi, p);
3107 BTM_TRACE_DEBUG ("BTM RSSI Complete: rssi %d, hci status 0x%02x",
3108 results.rssi, results.hci_status);
3110 /* Search through the list of active channels for the correct BD Addr */
3111 for (index = 0; index < MAX_L2CAP_LINKS; index++, p_acl_cb++)
3113 if ((p_acl_cb->in_use) && (handle == p_acl_cb->hci_handle))
3115 memcpy (results.rem_bda, p_acl_cb->remote_addr, BD_ADDR_LEN);
3121 results.status = BTM_ERR_PROCESSING;
3127 /*******************************************************************************
3129 ** Function btm_read_link_quality_complete
3131 ** Description This function is called when the command complete message
3132 ** is received from the HCI for the read link quality.
3136 *******************************************************************************/
3137 void btm_read_link_quality_complete (UINT8 *p)
3139 tBTM_CMPL_CB *p_cb = btm_cb.devcb.p_lnk_qual_cmpl_cb;
3140 tBTM_LINK_QUALITY_RESULTS results;
3142 tACL_CONN *p_acl_cb = &btm_cb.acl_db[0];
3144 BTM_TRACE_DEBUG ("btm_read_link_quality_complete");
3145 btu_stop_timer (&btm_cb.devcb.lnk_quality_timer);
3147 /* If there was a callback registered for read rssi, call it */
3148 btm_cb.devcb.p_lnk_qual_cmpl_cb = NULL;
3152 STREAM_TO_UINT8 (results.hci_status, p);
3154 if (results.hci_status == HCI_SUCCESS)
3156 results.status = BTM_SUCCESS;
3158 STREAM_TO_UINT16 (handle, p);
3160 STREAM_TO_UINT8 (results.link_quality, p);
3161 BTM_TRACE_DEBUG ("BTM Link Quality Complete: Link Quality %d, hci status 0x%02x",
3162 results.link_quality, results.hci_status);
3164 /* Search through the list of active channels for the correct BD Addr */
3165 for (index = 0; index < MAX_L2CAP_LINKS; index++, p_acl_cb++)
3167 if ((p_acl_cb->in_use) && (handle == p_acl_cb->hci_handle))
3169 memcpy (results.rem_bda, p_acl_cb->remote_addr, BD_ADDR_LEN);
3175 results.status = BTM_ERR_PROCESSING;
3181 /*******************************************************************************
3183 ** Function btm_remove_acl
3185 ** Description This function is called to disconnect an ACL connection
3187 ** Returns BTM_SUCCESS if successfully initiated, otherwise BTM_NO_RESOURCES.
3189 *******************************************************************************/
3190 tBTM_STATUS btm_remove_acl (BD_ADDR bd_addr, tBT_TRANSPORT transport)
3192 UINT16 hci_handle = BTM_GetHCIConnHandle(bd_addr, transport);
3193 tBTM_STATUS status = BTM_SUCCESS;
3195 BTM_TRACE_DEBUG ("btm_remove_acl");
3196 #if BTM_DISC_DURING_RS == TRUE
3197 tBTM_SEC_DEV_REC *p_dev_rec = btm_find_dev (bd_addr);
3199 /* Role Switch is pending, postpone until completed */
3200 if (p_dev_rec && (p_dev_rec->rs_disc_pending == BTM_SEC_RS_PENDING))
3202 p_dev_rec->rs_disc_pending = BTM_SEC_DISC_PENDING;
3204 else /* otherwise can disconnect right away */
3207 if (hci_handle != 0xFFFF && p_dev_rec &&
3208 p_dev_rec->sec_state!= BTM_SEC_STATE_DISCONNECTING)
3210 if (!btsnd_hcic_disconnect (hci_handle, HCI_ERR_PEER_USER))
3211 status = BTM_NO_RESOURCES;
3214 status = BTM_UNKNOWN_ADDR;
3221 /*******************************************************************************
3223 ** Function BTM_SetTraceLevel
3225 ** Description This function sets the trace level for BTM. If called with
3226 ** a value of 0xFF, it simply returns the current trace level.
3228 ** Returns The new or current trace level
3230 *******************************************************************************/
3231 UINT8 BTM_SetTraceLevel (UINT8 new_level)
3233 BTM_TRACE_DEBUG ("BTM_SetTraceLevel");
3234 if (new_level != 0xFF)
3235 btm_cb.trace_level = new_level;
3237 return(btm_cb.trace_level);
3240 /*******************************************************************************
3242 ** Function btm_cont_rswitch_or_chglinkkey
3244 ** Description This function is called to continue processing an active
3245 ** role switch or change of link key procedure. It first
3246 ** disables encryption if enabled and EPR is not supported
3250 *******************************************************************************/
3251 void btm_cont_rswitch_or_chglinkkey (tACL_CONN *p, tBTM_SEC_DEV_REC *p_dev_rec,
3254 BOOLEAN sw_ok = TRUE;
3255 BOOLEAN chlk_ok = TRUE;
3256 BTM_TRACE_DEBUG ("btm_cont_rswitch_or_chglinkkey ");
3257 /* Check to see if encryption needs to be turned off if pending
3258 change of link key or role switch */
3259 if (p->switch_role_state == BTM_ACL_SWKEY_STATE_MODE_CHANGE ||
3260 p->change_key_state == BTM_ACL_SWKEY_STATE_MODE_CHANGE)
3262 /* Must turn off Encryption first if necessary */
3263 /* Some devices do not support switch or change of link key while encryption is on */
3264 if (p_dev_rec != NULL && ((p_dev_rec->sec_flags & BTM_SEC_ENCRYPTED) != 0)
3265 && !BTM_EPR_AVAILABLE(p))
3267 if (btsnd_hcic_set_conn_encrypt (p->hci_handle, FALSE))
3269 p->encrypt_state = BTM_ACL_ENCRYPT_STATE_ENCRYPT_OFF;
3270 if (p->switch_role_state == BTM_ACL_SWKEY_STATE_MODE_CHANGE)
3271 p->switch_role_state = BTM_ACL_SWKEY_STATE_ENCRYPTION_OFF;
3273 if (p->change_key_state == BTM_ACL_SWKEY_STATE_MODE_CHANGE)
3274 p->change_key_state = BTM_ACL_SWKEY_STATE_ENCRYPTION_OFF;
3278 /* Error occurred; set states back to Idle */
3279 if (p->switch_role_state == BTM_ACL_SWKEY_STATE_MODE_CHANGE)
3282 if (p->change_key_state == BTM_ACL_SWKEY_STATE_MODE_CHANGE)
3286 else /* Encryption not used or EPR supported, continue with switch
3287 and/or change of link key */
3289 if (p->switch_role_state == BTM_ACL_SWKEY_STATE_MODE_CHANGE)
3291 p->switch_role_state = BTM_ACL_SWKEY_STATE_IN_PROGRESS;
3292 #if BTM_DISC_DURING_RS == TRUE
3294 p_dev_rec->rs_disc_pending = BTM_SEC_RS_PENDING;
3296 sw_ok = btsnd_hcic_switch_role (p->remote_addr, (UINT8)!p->link_role);
3299 if (p->change_key_state == BTM_ACL_SWKEY_STATE_MODE_CHANGE)
3301 p->switch_role_state = BTM_ACL_SWKEY_STATE_IN_PROGRESS;
3302 chlk_ok = btsnd_hcic_change_link_key (p->hci_handle);
3308 p->switch_role_state = BTM_ACL_SWKEY_STATE_IDLE;
3309 btm_acl_report_role_change(hci_status, p->remote_addr);
3314 p->change_key_state = BTM_ACL_SWKEY_STATE_IDLE;
3315 if (btm_cb.devcb.p_chg_link_key_cb)
3317 btm_cb.devcb.chg_link_key_ref_data.hci_status = hci_status;
3318 (*btm_cb.devcb.p_chg_link_key_cb)(&btm_cb.devcb.chg_link_key_ref_data);
3319 btm_cb.devcb.p_chg_link_key_cb = NULL;
3325 /*******************************************************************************
3327 ** Function btm_acl_resubmit_page
3329 ** Description send pending page request
3331 *******************************************************************************/
3332 void btm_acl_resubmit_page (void)
3334 tBTM_SEC_DEV_REC *p_dev_rec;
3338 BTM_TRACE_DEBUG ("btm_acl_resubmit_page");
3339 /* If there were other page request schedule can start the next one */
3340 if ((p_buf = (BT_HDR *)GKI_dequeue (&btm_cb.page_queue)) != NULL)
3342 /* skip 3 (2 bytes opcode and 1 byte len) to get to the bd_addr
3343 * for both create_conn and rmt_name */
3344 pp = (UINT8 *)(p_buf + 1) + p_buf->offset + 3;
3346 STREAM_TO_BDADDR (bda, pp);
3348 p_dev_rec = btm_find_or_alloc_dev (bda);
3350 memcpy (btm_cb.connecting_bda, p_dev_rec->bd_addr, BD_ADDR_LEN);
3351 memcpy (btm_cb.connecting_dc, p_dev_rec->dev_class, DEV_CLASS_LEN);
3353 btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p_buf);
3356 btm_cb.paging = FALSE;
3359 /*******************************************************************************
3361 ** Function btm_acl_reset_paging
3363 ** Description set paging to FALSE and free the page queue - called at hci_reset
3365 *******************************************************************************/
3366 void btm_acl_reset_paging (void)
3369 BTM_TRACE_DEBUG ("btm_acl_reset_paging");
3370 /* If we sent reset we are definitely not paging any more */
3371 while ((p = (BT_HDR *)GKI_dequeue(&btm_cb.page_queue)) != NULL)
3374 btm_cb.paging = FALSE;
3377 /*******************************************************************************
3379 ** Function btm_acl_set_discing
3381 ** Description set discing to the given value
3383 *******************************************************************************/
3384 void btm_acl_set_discing (BOOLEAN discing)
3386 BTM_TRACE_DEBUG ("btm_acl_set_discing");
3387 btm_cb.discing = discing;
3390 /*******************************************************************************
3392 ** Function btm_acl_paging
3394 ** Description send a paging command or queue it in btm_cb
3396 *******************************************************************************/
3397 void btm_acl_paging (BT_HDR *p, BD_ADDR bda)
3399 tBTM_SEC_DEV_REC *p_dev_rec;
3401 BTM_TRACE_DEBUG ("btm_acl_paging discing:%d, paging:%d BDA: %06x%06x",
3402 btm_cb.discing, btm_cb.paging,
3403 (bda[0]<<16) + (bda[1]<<8) + bda[2], (bda[3]<<16) + (bda[4] << 8) + bda[5]);
3406 btm_cb.paging = TRUE;
3407 GKI_enqueue (&btm_cb.page_queue, p);
3411 if (!BTM_ACL_IS_CONNECTED (bda))
3413 BTM_TRACE_DEBUG ("connecting_bda: %06x%06x",
3414 (btm_cb.connecting_bda[0]<<16) + (btm_cb.connecting_bda[1]<<8) +
3415 btm_cb.connecting_bda[2],
3416 (btm_cb.connecting_bda[3]<<16) + (btm_cb.connecting_bda[4] << 8) +
3417 btm_cb.connecting_bda[5]);
3418 if (btm_cb.paging &&
3419 memcmp (bda, btm_cb.connecting_bda, BD_ADDR_LEN) != 0)
3421 GKI_enqueue (&btm_cb.page_queue, p);
3425 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);
3432 btm_cb.paging = TRUE;
3434 else /* ACL is already up */
3436 btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p);
3441 /*******************************************************************************
3443 ** Function btm_acl_notif_conn_collision
3445 ** Description Send connection collision event to upper layer if registered
3447 ** Returns TRUE if sent out to upper layer,
3448 ** FALSE if BTM_BUSY_LEVEL_CHANGE_INCLUDED == FALSE, or no one
3449 ** needs the notification.
3451 ** Note: Function only used if BTM_BUSY_LEVEL_CHANGE_INCLUDED == TRUE
3453 *******************************************************************************/
3454 BOOLEAN btm_acl_notif_conn_collision (BD_ADDR bda)
3456 #if (BTM_BUSY_LEVEL_CHANGE_INCLUDED == TRUE)
3457 tBTM_BL_EVENT_DATA evt_data;
3459 /* Report possible collision to the upper layer. */
3460 if (btm_cb.p_bl_changed_cb)
3462 BTM_TRACE_DEBUG ("btm_acl_notif_conn_collision: RemBdAddr: %02x%02x%02x%02x%02x%02x",
3463 bda[0], bda[1], bda[2], bda[3], bda[4], bda[5]);
3465 evt_data.event = BTM_BL_COLLISION_EVT;
3466 evt_data.conn.p_bda = bda;
3468 #if BLE_INCLUDED == TRUE
3469 evt_data.conn.transport = BT_TRANSPORT_BR_EDR;
3470 evt_data.conn.handle = BTM_INVALID_HCI_HANDLE;
3472 (*btm_cb.p_bl_changed_cb)(&evt_data);
3483 /*******************************************************************************
3485 ** Function btm_acl_chk_peer_pkt_type_support
3487 ** Description Check if peer supports requested packets
3489 *******************************************************************************/
3490 void btm_acl_chk_peer_pkt_type_support (tACL_CONN *p, UINT16 *p_pkt_type)
3492 /* 3 and 5 slot packets? */
3493 if (!HCI_3_SLOT_PACKETS_SUPPORTED(p->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0]))
3494 *p_pkt_type &= ~(BTM_ACL_PKT_TYPES_MASK_DH3 +BTM_ACL_PKT_TYPES_MASK_DM3);
3496 if (!HCI_5_SLOT_PACKETS_SUPPORTED(p->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0]))
3497 *p_pkt_type &= ~(BTM_ACL_PKT_TYPES_MASK_DH5 + BTM_ACL_PKT_TYPES_MASK_DM5);
3499 /* If HCI version > 2.0, then also check EDR packet types */
3500 if (btm_cb.devcb.local_version.hci_version >= HCI_PROTO_VERSION_2_0)
3502 /* 2 and 3 MPS support? */
3503 if (!HCI_EDR_ACL_2MPS_SUPPORTED(p->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0]))
3504 /* Not supported. Add 'not_supported' mask for all 2MPS packet types */
3505 *p_pkt_type |= (BTM_ACL_PKT_TYPES_MASK_NO_2_DH1 + BTM_ACL_PKT_TYPES_MASK_NO_2_DH3 +
3506 BTM_ACL_PKT_TYPES_MASK_NO_2_DH5);
3508 if (!HCI_EDR_ACL_3MPS_SUPPORTED(p->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0]))
3509 /* Not supported. Add 'not_supported' mask for all 3MPS packet types */
3510 *p_pkt_type |= (BTM_ACL_PKT_TYPES_MASK_NO_3_DH1 + BTM_ACL_PKT_TYPES_MASK_NO_3_DH3 +
3511 BTM_ACL_PKT_TYPES_MASK_NO_3_DH5);
3513 /* EDR 3 and 5 slot support? */
3514 if (HCI_EDR_ACL_2MPS_SUPPORTED(p->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0])
3515 || HCI_EDR_ACL_3MPS_SUPPORTED(p->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0]))
3517 if (!HCI_3_SLOT_EDR_ACL_SUPPORTED(p->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0]))
3518 /* Not supported. Add 'not_supported' mask for all 3-slot EDR packet types */
3519 *p_pkt_type |= (BTM_ACL_PKT_TYPES_MASK_NO_2_DH3 + BTM_ACL_PKT_TYPES_MASK_NO_3_DH3);
3521 if (!HCI_5_SLOT_EDR_ACL_SUPPORTED(p->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0]))
3522 /* Not supported. Add 'not_supported' mask for all 5-slot EDR packet types */
3523 *p_pkt_type |= (BTM_ACL_PKT_TYPES_MASK_NO_2_DH5 + BTM_ACL_PKT_TYPES_MASK_NO_3_DH5);