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"
33 #include "controller.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 btm_cb.p_bl_changed_cb = NULL;
72 /* Initialize nonzero defaults */
73 btm_cb.btm_def_link_super_tout = HCI_DEFAULT_INACT_TOUT;
74 btm_cb.acl_disc_reason = 0xff ;
77 /*******************************************************************************
79 ** Function btm_bda_to_acl
81 ** Description This function returns the FIRST acl_db entry for the passed BDA.
83 ** Parameters bda : BD address of the remote device
84 ** transport : Physical transport used for ACL connection (BR/EDR or LE)
86 ** Returns Returns pointer to the ACL DB for the requested BDA if found.
89 *******************************************************************************/
90 tACL_CONN *btm_bda_to_acl (BD_ADDR bda, tBT_TRANSPORT transport)
92 tACL_CONN *p = &btm_cb.acl_db[0];
96 for (xx = 0; xx < MAX_L2CAP_LINKS; xx++, p++)
98 if ((p->in_use) && (!memcmp (p->remote_addr, bda, BD_ADDR_LEN))
99 #if BLE_INCLUDED == TRUE
100 && p->transport == transport
104 BTM_TRACE_DEBUG ("btm_bda_to_acl found");
110 /* If here, no BD Addr found */
111 return((tACL_CONN *)NULL);
114 /*******************************************************************************
116 ** Function btm_handle_to_acl_index
118 ** Description This function returns the FIRST acl_db entry for the passed hci_handle.
120 ** Returns index to the acl_db or MAX_L2CAP_LINKS.
122 *******************************************************************************/
123 UINT8 btm_handle_to_acl_index (UINT16 hci_handle)
125 tACL_CONN *p = &btm_cb.acl_db[0];
127 BTM_TRACE_DEBUG ("btm_handle_to_acl_index");
128 for (xx = 0; xx < MAX_L2CAP_LINKS; xx++, p++)
130 if ((p->in_use) && (p->hci_handle == hci_handle))
136 /* If here, no BD Addr found */
140 #if BLE_PRIVACY_SPT == TRUE
141 /*******************************************************************************
143 ** Function btm_ble_get_acl_remote_addr
145 ** Description This function reads the active remote address used for the
148 ** Returns success return TRUE, otherwise FALSE.
150 *******************************************************************************/
151 BOOLEAN btm_ble_get_acl_remote_addr(tBTM_SEC_DEV_REC *p_dev_rec, BD_ADDR conn_addr,
152 tBLE_ADDR_TYPE *p_addr_type)
154 #if BLE_INCLUDED == TRUE
157 if (p_dev_rec == NULL)
159 BTM_TRACE_ERROR("btm_ble_get_acl_remote_addr can not find device with matching address");
163 switch (p_dev_rec->ble.active_addr_type)
165 case BTM_BLE_ADDR_PSEUDO:
166 memcpy(conn_addr, p_dev_rec->bd_addr, BD_ADDR_LEN);
167 * p_addr_type = p_dev_rec->ble.ble_addr_type;
170 case BTM_BLE_ADDR_RRA:
171 memcpy(conn_addr, p_dev_rec->ble.cur_rand_addr, BD_ADDR_LEN);
172 * p_addr_type = BLE_ADDR_RANDOM;
175 case BTM_BLE_ADDR_STATIC:
176 memcpy(conn_addr, p_dev_rec->ble.static_addr, BD_ADDR_LEN);
177 * p_addr_type = p_dev_rec->ble.static_addr_type;
181 BTM_TRACE_ERROR("Unknown active address: %d", p_dev_rec->ble.active_addr_type);
195 /*******************************************************************************
197 ** Function btm_acl_created
199 ** Description This function is called by L2CAP when an ACL connection
204 *******************************************************************************/
205 void btm_acl_created (BD_ADDR bda, DEV_CLASS dc, BD_NAME bdn,
206 UINT16 hci_handle, UINT8 link_role, tBT_TRANSPORT transport)
208 tBTM_SEC_DEV_REC *p_dev_rec = NULL;
213 BTM_TRACE_DEBUG ("btm_acl_created hci_handle=%d link_role=%d transport=%d",
214 hci_handle,link_role, transport);
215 /* Ensure we don't have duplicates */
216 p = btm_bda_to_acl(bda, transport);
217 if (p != (tACL_CONN *)NULL)
219 p->hci_handle = hci_handle;
220 p->link_role = link_role;
221 #if BLE_INCLUDED == TRUE
222 p->transport = transport;
224 BTM_TRACE_DEBUG ("Duplicate btm_acl_created: RemBdAddr: %02x%02x%02x%02x%02x%02x",
225 bda[0], bda[1], bda[2], bda[3], bda[4], bda[5]);
226 BTM_SetLinkPolicy(p->remote_addr, &btm_cb.btm_def_link_policy);
230 /* Allocate acl_db entry */
231 for (xx = 0, p = &btm_cb.acl_db[0]; xx < MAX_L2CAP_LINKS; xx++, p++)
236 p->hci_handle = hci_handle;
237 p->link_role = link_role;
238 p->link_up_issued = FALSE;
240 #if BLE_INCLUDED == TRUE
241 p->transport = transport;
242 if (transport == BT_TRANSPORT_LE)
244 #if BLE_PRIVACY_SPT == TRUE
245 if (btm_cb.ble_ctr_cb.privacy)
247 p->conn_addr_type = btm_cb.ble_ctr_cb.addr_mgnt_cb.own_addr_type;
248 memcpy(p->conn_addr, btm_cb.ble_ctr_cb.addr_mgnt_cb.private_addr, BD_ADDR_LEN);
253 p->conn_addr_type = BLE_ADDR_PUBLIC;
254 memcpy(p->conn_addr, controller_get_interface()->get_address()->address, BD_ADDR_LEN);
258 p->switch_role_state = BTM_ACL_SWKEY_STATE_IDLE;
262 memcpy (p->remote_addr, bda, BD_ADDR_LEN);
265 memcpy (p->remote_dc, dc, DEV_CLASS_LEN);
268 memcpy (p->remote_name, bdn, BTM_MAX_REM_BD_NAME_LEN);
270 /* if BR/EDR do something more */
271 if (transport == BT_TRANSPORT_BR_EDR)
273 btsnd_hcic_read_rmt_clk_offset (p->hci_handle);
274 btsnd_hcic_rmt_ver_req (p->hci_handle);
276 p_dev_rec = btm_find_dev_by_handle (hci_handle);
278 #if (BLE_INCLUDED == TRUE)
281 BTM_TRACE_DEBUG ("device_type=0x%x", p_dev_rec->device_type);
285 if (p_dev_rec && !(transport == BT_TRANSPORT_LE))
287 /* If remote features already known, copy them and continue connection setup */
288 if ((p_dev_rec->num_read_pages) &&
289 (p_dev_rec->num_read_pages <= (HCI_EXT_FEATURES_PAGE_MAX + 1)) /* sanity check */)
291 memcpy (p->peer_lmp_features, p_dev_rec->features,
292 (HCI_FEATURE_BYTES_PER_PAGE * p_dev_rec->num_read_pages));
293 p->num_read_pages = p_dev_rec->num_read_pages;
295 if (BTM_SEC_MODE_SP == btm_cb.security_mode
296 && HCI_SSP_HOST_SUPPORTED(p_dev_rec->features[HCI_EXT_FEATURES_PAGE_1])
297 && HCI_SIMPLE_PAIRING_SUPPORTED(p_dev_rec->features[HCI_EXT_FEATURES_PAGE_0]))
299 p_dev_rec->sm4 = BTM_SM4_TRUE;
303 p_dev_rec->sm4 |= BTM_SM4_KNOWN;
306 btm_establish_continue (p);
311 #if (BLE_INCLUDED == TRUE)
312 /* If here, features are not known yet */
313 if (p_dev_rec && transport == BT_TRANSPORT_LE)
315 #if BLE_PRIVACY_SPT == TRUE
316 btm_ble_get_acl_remote_addr (p_dev_rec, p->active_remote_addr,
317 &p->active_remote_addr_type);
320 if (HCI_LE_SLAVE_INIT_FEAT_EXC_SUPPORTED(controller_get_interface()->get_features_ble()->as_array)
321 || link_role == HCI_ROLE_MASTER)
323 btsnd_hcic_ble_read_remote_feat(p->hci_handle);
327 btm_establish_continue(p);
333 btm_read_remote_features (p->hci_handle);
336 /* read page 1 - on rmt feature event for buffer reasons */
343 /*******************************************************************************
345 ** Function btm_acl_report_role_change
347 ** Description This function is called when the local device is deemed
348 ** to be down. It notifies L2CAP of the failure.
352 *******************************************************************************/
353 void btm_acl_report_role_change (UINT8 hci_status, BD_ADDR bda)
355 tBTM_ROLE_SWITCH_CMPL ref_data;
356 BTM_TRACE_DEBUG ("btm_acl_report_role_change");
357 if (btm_cb.devcb.p_switch_role_cb
358 && (bda && (0 == memcmp(btm_cb.devcb.switch_role_ref_data.remote_bd_addr, bda, BD_ADDR_LEN))))
360 memcpy (&ref_data, &btm_cb.devcb.switch_role_ref_data, sizeof(tBTM_ROLE_SWITCH_CMPL));
361 ref_data.hci_status = hci_status;
362 (*btm_cb.devcb.p_switch_role_cb)(&ref_data);
363 memset (&btm_cb.devcb.switch_role_ref_data, 0, sizeof(tBTM_ROLE_SWITCH_CMPL));
364 btm_cb.devcb.p_switch_role_cb = NULL;
368 /*******************************************************************************
370 ** Function btm_acl_removed
372 ** Description This function is called by L2CAP when an ACL connection
373 ** is removed. Since only L2CAP creates ACL links, we use
374 ** the L2CAP link index as our index into the control blocks.
378 *******************************************************************************/
379 void btm_acl_removed (BD_ADDR bda, tBT_TRANSPORT transport)
382 tBTM_BL_EVENT_DATA evt_data;
383 #if (defined BLE_INCLUDED && BLE_INCLUDED == TRUE)
384 tBTM_SEC_DEV_REC *p_dev_rec=NULL;
386 BTM_TRACE_DEBUG ("btm_acl_removed");
387 p = btm_bda_to_acl(bda, transport);
388 if (p != (tACL_CONN *)NULL)
392 /* if the disconnected channel has a pending role switch, clear it now */
393 btm_acl_report_role_change(HCI_ERR_NO_CONNECTION, bda);
395 /* Only notify if link up has had a chance to be issued */
396 if (p->link_up_issued)
398 p->link_up_issued = FALSE;
400 /* If anyone cares, tell him database changed */
401 if (btm_cb.p_bl_changed_cb)
403 evt_data.event = BTM_BL_DISCN_EVT;
404 evt_data.discn.p_bda = bda;
405 #if BLE_INCLUDED == TRUE
406 evt_data.discn.handle = p->hci_handle;
407 evt_data.discn.transport = p->transport;
409 (*btm_cb.p_bl_changed_cb)(&evt_data);
412 btm_acl_update_busy_level (BTM_BLI_ACL_DOWN_EVT);
415 #if (defined BLE_INCLUDED && BLE_INCLUDED == TRUE)
417 BTM_TRACE_DEBUG ("acl hci_handle=%d transport=%d connectable_mode=0x%0x link_role=%d",
420 btm_cb.ble_ctr_cb.inq_var.connectable_mode,
423 p_dev_rec = btm_find_dev(bda);
426 BTM_TRACE_DEBUG("before update p_dev_rec->sec_flags=0x%x", p_dev_rec->sec_flags);
427 if (p->transport == BT_TRANSPORT_LE)
429 BTM_TRACE_DEBUG("LE link down");
430 p_dev_rec->sec_flags &= ~(BTM_SEC_LE_ENCRYPTED | BTM_SEC_ROLE_SWITCHED);
431 if ( (p_dev_rec->sec_flags & BTM_SEC_LE_LINK_KEY_KNOWN) == 0)
433 BTM_TRACE_DEBUG("Not Bonded");
434 p_dev_rec->sec_flags &= ~(BTM_SEC_LE_LINK_KEY_AUTHED | BTM_SEC_LE_AUTHENTICATED);
438 BTM_TRACE_DEBUG("Bonded");
443 BTM_TRACE_DEBUG("Bletooth link down");
444 p_dev_rec->sec_flags &= ~(BTM_SEC_AUTHORIZED | BTM_SEC_AUTHENTICATED
445 | BTM_SEC_ENCRYPTED | BTM_SEC_ROLE_SWITCHED);
447 BTM_TRACE_DEBUG("after update p_dev_rec->sec_flags=0x%x", p_dev_rec->sec_flags);
451 BTM_TRACE_ERROR("Device not found");
461 /*******************************************************************************
463 ** Function btm_acl_device_down
465 ** Description This function is called when the local device is deemed
466 ** to be down. It notifies L2CAP of the failure.
470 *******************************************************************************/
471 void btm_acl_device_down (void)
473 tACL_CONN *p = &btm_cb.acl_db[0];
475 BTM_TRACE_DEBUG ("btm_acl_device_down");
476 for (xx = 0; xx < MAX_L2CAP_LINKS; xx++, p++)
480 BTM_TRACE_DEBUG ("hci_handle=%d HCI_ERR_HW_FAILURE ",p->hci_handle );
481 l2c_link_hci_disc_comp (p->hci_handle, HCI_ERR_HW_FAILURE);
486 /*******************************************************************************
488 ** Function btm_acl_update_busy_level
490 ** Description This function is called to update the busy level of the system
495 *******************************************************************************/
496 void btm_acl_update_busy_level (tBTM_BLI_EVENT event)
498 tBTM_BL_UPDATE_DATA evt;
500 BTM_TRACE_DEBUG ("btm_acl_update_busy_level");
501 BOOLEAN old_inquiry_state = btm_cb.is_inquiry;
504 case BTM_BLI_ACL_UP_EVT:
505 BTM_TRACE_DEBUG ("BTM_BLI_ACL_UP_EVT");
508 case BTM_BLI_ACL_DOWN_EVT:
512 BTM_TRACE_DEBUG ("BTM_BLI_ACL_DOWN_EVT", btm_cb.num_acl);
516 BTM_TRACE_ERROR ("BTM_BLI_ACL_DOWN_EVT issued, but num_acl already zero !!!");
519 case BTM_BLI_PAGE_EVT:
520 BTM_TRACE_DEBUG ("BTM_BLI_PAGE_EVT");
521 btm_cb.is_paging = TRUE;
522 evt.busy_level_flags= BTM_BL_PAGING_STARTED;
524 case BTM_BLI_PAGE_DONE_EVT:
525 BTM_TRACE_DEBUG ("BTM_BLI_PAGE_DONE_EVT");
526 btm_cb.is_paging = FALSE;
527 evt.busy_level_flags = BTM_BL_PAGING_COMPLETE;
529 case BTM_BLI_INQ_EVT:
530 BTM_TRACE_DEBUG ("BTM_BLI_INQ_EVT");
531 btm_cb.is_inquiry = TRUE;
532 evt.busy_level_flags = BTM_BL_INQUIRY_STARTED;
534 case BTM_BLI_INQ_CANCEL_EVT:
535 BTM_TRACE_DEBUG ("BTM_BLI_INQ_CANCEL_EVT");
536 btm_cb.is_inquiry = FALSE;
537 evt.busy_level_flags = BTM_BL_INQUIRY_CANCELLED;
539 case BTM_BLI_INQ_DONE_EVT:
540 BTM_TRACE_DEBUG ("BTM_BLI_INQ_DONE_EVT");
541 btm_cb.is_inquiry = FALSE;
542 evt.busy_level_flags = BTM_BL_INQUIRY_COMPLETE;
546 if (btm_cb.is_paging || btm_cb.is_inquiry)
549 busy_level = (UINT8)btm_cb.num_acl;
551 if ((busy_level != btm_cb.busy_level) ||(old_inquiry_state != btm_cb.is_inquiry))
553 evt.event = BTM_BL_UPDATE_EVT;
554 evt.busy_level = busy_level;
555 btm_cb.busy_level = busy_level;
556 if (btm_cb.p_bl_changed_cb && (btm_cb.bl_evt_mask & BTM_BL_UPDATE_MASK))
558 (*btm_cb.p_bl_changed_cb)((tBTM_BL_EVENT_DATA *)&evt);
563 /*******************************************************************************
565 ** Function BTM_GetRole
567 ** Description This function is called to get the role of the local device
568 ** for the ACL connection with the specified remote device
570 ** Returns BTM_SUCCESS if connection exists.
571 ** BTM_UNKNOWN_ADDR if no active link with bd addr specified
573 *******************************************************************************/
574 tBTM_STATUS BTM_GetRole (BD_ADDR remote_bd_addr, UINT8 *p_role)
577 BTM_TRACE_DEBUG ("BTM_GetRole");
578 if ((p = btm_bda_to_acl(remote_bd_addr, BT_TRANSPORT_BR_EDR)) == NULL)
580 *p_role = BTM_ROLE_UNDEFINED;
581 return(BTM_UNKNOWN_ADDR);
584 /* Get the current role */
585 *p_role = p->link_role;
590 /*******************************************************************************
592 ** Function BTM_SwitchRole
594 ** Description This function is called to switch role between master and
595 ** slave. If role is already set it will do nothing. If the
596 ** command was initiated, the callback function is called upon
599 ** Returns BTM_SUCCESS if already in specified role.
600 ** BTM_CMD_STARTED if command issued to controller.
601 ** BTM_NO_RESOURCES if couldn't allocate memory to issue command
602 ** BTM_UNKNOWN_ADDR if no active link with bd addr specified
603 ** BTM_MODE_UNSUPPORTED if local device does not support role switching
604 ** BTM_BUSY if the previous command is not completed
606 *******************************************************************************/
607 tBTM_STATUS BTM_SwitchRole (BD_ADDR remote_bd_addr, UINT8 new_role, tBTM_CMPL_CB *p_cb)
610 tBTM_SEC_DEV_REC *p_dev_rec = NULL;
611 #if BTM_SCO_INCLUDED == TRUE
612 BOOLEAN is_sco_active;
615 tBTM_PM_MODE pwr_mode;
616 tBTM_PM_PWR_MD settings;
617 #if (BT_USE_TRACES == TRUE)
620 BTM_TRACE_API ("BTM_SwitchRole BDA: %02x-%02x-%02x-%02x-%02x-%02x",
621 remote_bd_addr[0], remote_bd_addr[1], remote_bd_addr[2],
622 remote_bd_addr[3], remote_bd_addr[4], remote_bd_addr[5]);
624 /* Make sure the local device supports switching */
625 if (!controller_get_interface()->supports_master_slave_role_switch())
626 return(BTM_MODE_UNSUPPORTED);
628 if (btm_cb.devcb.p_switch_role_cb && p_cb)
630 #if (BT_USE_TRACES == TRUE)
631 p_bda = btm_cb.devcb.switch_role_ref_data.remote_bd_addr;
632 BTM_TRACE_DEBUG ("Role switch on other device is in progress 0x%02x%02x%02x%02x%02x%02x",
633 p_bda[0], p_bda[1], p_bda[2],
634 p_bda[3], p_bda[4], p_bda[5]);
639 if ((p = btm_bda_to_acl(remote_bd_addr, BT_TRANSPORT_BR_EDR)) == NULL)
640 return(BTM_UNKNOWN_ADDR);
642 /* Finished if already in desired role */
643 if (p->link_role == new_role)
646 #if BTM_SCO_INCLUDED == TRUE
647 /* Check if there is any SCO Active on this BD Address */
648 is_sco_active = btm_is_sco_active_by_bdaddr(remote_bd_addr);
650 if (is_sco_active == TRUE)
651 return(BTM_NO_RESOURCES);
654 /* Ignore role switch request if the previous request was not completed */
655 if (p->switch_role_state != BTM_ACL_SWKEY_STATE_IDLE)
657 BTM_TRACE_DEBUG ("BTM_SwitchRole busy: %d",
658 p->switch_role_state);
662 if ((status = BTM_ReadPowerMode(p->remote_addr, &pwr_mode)) != BTM_SUCCESS)
665 /* Wake up the link if in sniff or park before attempting switch */
666 if (pwr_mode == BTM_PM_MD_PARK || pwr_mode == BTM_PM_MD_SNIFF)
668 memset( (void*)&settings, 0, sizeof(settings));
669 settings.mode = BTM_PM_MD_ACTIVE;
670 status = BTM_SetPowerMode (BTM_PM_SET_ONLY_ID, p->remote_addr, &settings);
671 if (status != BTM_CMD_STARTED)
672 return(BTM_WRONG_MODE);
674 p->switch_role_state = BTM_ACL_SWKEY_STATE_MODE_CHANGE;
676 /* some devices do not support switch while encryption is on */
679 p_dev_rec = btm_find_dev (remote_bd_addr);
680 if ((p_dev_rec != NULL)
681 && ((p_dev_rec->sec_flags & BTM_SEC_ENCRYPTED) != 0)
682 && !BTM_EPR_AVAILABLE(p))
684 /* bypass turning off encryption if change link key is already doing it */
685 if (p->encrypt_state != BTM_ACL_ENCRYPT_STATE_ENCRYPT_OFF)
687 if (!btsnd_hcic_set_conn_encrypt (p->hci_handle, FALSE))
688 return(BTM_NO_RESOURCES);
690 p->encrypt_state = BTM_ACL_ENCRYPT_STATE_ENCRYPT_OFF;
693 p->switch_role_state = BTM_ACL_SWKEY_STATE_ENCRYPTION_OFF;
697 if (!btsnd_hcic_switch_role (remote_bd_addr, new_role))
698 return(BTM_NO_RESOURCES);
700 p->switch_role_state = BTM_ACL_SWKEY_STATE_IN_PROGRESS;
702 #if BTM_DISC_DURING_RS == TRUE
704 p_dev_rec->rs_disc_pending = BTM_SEC_RS_PENDING;
709 /* Initialize return structure in case request fails */
712 memcpy (btm_cb.devcb.switch_role_ref_data.remote_bd_addr, remote_bd_addr,
714 btm_cb.devcb.switch_role_ref_data.role = new_role;
715 /* initialized to an error code */
716 btm_cb.devcb.switch_role_ref_data.hci_status = HCI_ERR_UNSUPPORTED_VALUE;
717 btm_cb.devcb.p_switch_role_cb = p_cb;
719 return(BTM_CMD_STARTED);
722 /*******************************************************************************
724 ** Function btm_acl_encrypt_change
726 ** Description This function is when encryption of the connection is
727 ** completed by the LM. Checks to see if a role switch or
728 ** change of link key was active and initiates or continues
729 ** process if needed.
733 *******************************************************************************/
734 void btm_acl_encrypt_change (UINT16 handle, UINT8 status, UINT8 encr_enable)
738 tBTM_SEC_DEV_REC *p_dev_rec;
739 tBTM_BL_ROLE_CHG_DATA evt;
741 BTM_TRACE_DEBUG ("btm_acl_encrypt_change handle=%d status=%d encr_enabl=%d",
742 handle, status, encr_enable);
743 xx = btm_handle_to_acl_index(handle);
744 /* don't assume that we can never get a bad hci_handle */
745 if (xx < MAX_L2CAP_LINKS)
746 p = &btm_cb.acl_db[xx];
750 /* Process Role Switch if active */
751 if (p->switch_role_state == BTM_ACL_SWKEY_STATE_ENCRYPTION_OFF)
753 /* if encryption turn off failed we still will try to switch role */
756 p->switch_role_state = BTM_ACL_SWKEY_STATE_IDLE;
757 p->encrypt_state = BTM_ACL_ENCRYPT_STATE_IDLE;
761 p->switch_role_state = BTM_ACL_SWKEY_STATE_SWITCHING;
762 p->encrypt_state = BTM_ACL_ENCRYPT_STATE_TEMP_FUNC;
765 if (!btsnd_hcic_switch_role (p->remote_addr, (UINT8)!p->link_role))
767 p->switch_role_state = BTM_ACL_SWKEY_STATE_IDLE;
768 p->encrypt_state = BTM_ACL_ENCRYPT_STATE_IDLE;
769 btm_acl_report_role_change(btm_cb.devcb.switch_role_ref_data.hci_status, p->remote_addr);
771 #if BTM_DISC_DURING_RS == TRUE
774 if ((p_dev_rec = btm_find_dev (p->remote_addr)) != NULL)
775 p_dev_rec->rs_disc_pending = BTM_SEC_RS_PENDING;
780 /* Finished enabling Encryption after role switch */
781 else if (p->switch_role_state == BTM_ACL_SWKEY_STATE_ENCRYPTION_ON)
783 p->switch_role_state = BTM_ACL_SWKEY_STATE_IDLE;
784 p->encrypt_state = BTM_ACL_ENCRYPT_STATE_IDLE;
785 btm_acl_report_role_change(btm_cb.devcb.switch_role_ref_data.hci_status, p->remote_addr);
787 /* if role change event is registered, report it now */
788 if (btm_cb.p_bl_changed_cb && (btm_cb.bl_evt_mask & BTM_BL_ROLE_CHG_MASK))
790 evt.event = BTM_BL_ROLE_CHG_EVT;
791 evt.new_role = btm_cb.devcb.switch_role_ref_data.role;
792 evt.p_bda = btm_cb.devcb.switch_role_ref_data.remote_bd_addr;
793 evt.hci_status = btm_cb.devcb.switch_role_ref_data.hci_status;
794 (*btm_cb.p_bl_changed_cb)((tBTM_BL_EVENT_DATA *)&evt);
796 BTM_TRACE_DEBUG("Role Switch Event: new_role 0x%02x, HCI Status 0x%02x, rs_st:%d",
797 evt.new_role, evt.hci_status, p->switch_role_state);
800 #if BTM_DISC_DURING_RS == TRUE
801 /* If a disconnect is pending, issue it now that role switch has completed */
802 if ((p_dev_rec = btm_find_dev (p->remote_addr)) != NULL)
804 if (p_dev_rec->rs_disc_pending == BTM_SEC_DISC_PENDING)
806 BTM_TRACE_WARNING("btm_acl_encrypt_change -> Issuing delayed HCI_Disconnect!!!");
807 btsnd_hcic_disconnect(p_dev_rec->hci_handle, HCI_ERR_PEER_USER);
809 BTM_TRACE_ERROR("btm_acl_encrypt_change: tBTM_SEC_DEV:0x%x rs_disc_pending=%d",
810 (UINT32)p_dev_rec, p_dev_rec->rs_disc_pending);
811 p_dev_rec->rs_disc_pending = BTM_SEC_RS_NOT_PENDING; /* reset flag */
816 /*******************************************************************************
818 ** Function BTM_SetLinkPolicy
820 ** Description Create and send HCI "Write Policy Set" command
822 ** Returns status of the operation
824 *******************************************************************************/
825 tBTM_STATUS BTM_SetLinkPolicy (BD_ADDR remote_bda, UINT16 *settings)
828 UINT8 *localFeatures = BTM_ReadLocalFeatures();
829 BTM_TRACE_DEBUG ("BTM_SetLinkPolicy");
830 /* BTM_TRACE_API ("BTM_SetLinkPolicy: requested settings: 0x%04x", *settings ); */
832 /* First, check if hold mode is supported */
833 if (*settings != HCI_DISABLE_ALL_LM_MODES)
835 if ( (*settings & HCI_ENABLE_MASTER_SLAVE_SWITCH) && (!HCI_SWITCH_SUPPORTED(localFeatures)) )
837 *settings &= (~HCI_ENABLE_MASTER_SLAVE_SWITCH);
838 BTM_TRACE_API ("BTM_SetLinkPolicy switch not supported (settings: 0x%04x)", *settings );
840 if ( (*settings & HCI_ENABLE_HOLD_MODE) && (!HCI_HOLD_MODE_SUPPORTED(localFeatures)) )
842 *settings &= (~HCI_ENABLE_HOLD_MODE);
843 BTM_TRACE_API ("BTM_SetLinkPolicy hold not supported (settings: 0x%04x)", *settings );
845 if ( (*settings & HCI_ENABLE_SNIFF_MODE) && (!HCI_SNIFF_MODE_SUPPORTED(localFeatures)) )
847 *settings &= (~HCI_ENABLE_SNIFF_MODE);
848 BTM_TRACE_API ("BTM_SetLinkPolicy sniff not supported (settings: 0x%04x)", *settings );
850 if ( (*settings & HCI_ENABLE_PARK_MODE) && (!HCI_PARK_MODE_SUPPORTED(localFeatures)) )
852 *settings &= (~HCI_ENABLE_PARK_MODE);
853 BTM_TRACE_API ("BTM_SetLinkPolicy park not supported (settings: 0x%04x)", *settings );
857 if ((p = btm_bda_to_acl(remote_bda, BT_TRANSPORT_BR_EDR)) != NULL)
858 return(btsnd_hcic_write_policy_set (p->hci_handle, *settings) ? BTM_CMD_STARTED : BTM_NO_RESOURCES);
860 /* If here, no BD Addr found */
861 return(BTM_UNKNOWN_ADDR);
864 /*******************************************************************************
866 ** Function BTM_SetDefaultLinkPolicy
868 ** Description Set the default value for HCI "Write Policy Set" command
869 ** to use when an ACL link is created.
873 *******************************************************************************/
874 void BTM_SetDefaultLinkPolicy (UINT16 settings)
876 UINT8 *localFeatures = BTM_ReadLocalFeatures();
878 BTM_TRACE_DEBUG("BTM_SetDefaultLinkPolicy setting:0x%04x", settings);
880 if((settings & HCI_ENABLE_MASTER_SLAVE_SWITCH) && (!HCI_SWITCH_SUPPORTED(localFeatures)))
882 settings &= ~HCI_ENABLE_MASTER_SLAVE_SWITCH;
883 BTM_TRACE_DEBUG("BTM_SetDefaultLinkPolicy switch not supported (settings: 0x%04x)", settings);
885 if ((settings & HCI_ENABLE_HOLD_MODE) && (!HCI_HOLD_MODE_SUPPORTED(localFeatures)))
887 settings &= ~HCI_ENABLE_HOLD_MODE;
888 BTM_TRACE_DEBUG("BTM_SetDefaultLinkPolicy hold not supported (settings: 0x%04x)", settings);
890 if ((settings & HCI_ENABLE_SNIFF_MODE) && (!HCI_SNIFF_MODE_SUPPORTED(localFeatures)))
892 settings &= ~HCI_ENABLE_SNIFF_MODE;
893 BTM_TRACE_DEBUG("BTM_SetDefaultLinkPolicy sniff not supported (settings: 0x%04x)", settings);
895 if ((settings & HCI_ENABLE_PARK_MODE) && (!HCI_PARK_MODE_SUPPORTED(localFeatures)))
897 settings &= ~HCI_ENABLE_PARK_MODE;
898 BTM_TRACE_DEBUG("BTM_SetDefaultLinkPolicy park not supported (settings: 0x%04x)", settings);
900 BTM_TRACE_DEBUG("Set DefaultLinkPolicy:0x%04x", settings);
902 btm_cb.btm_def_link_policy = settings;
904 /* Set the default Link Policy of the controller */
905 btsnd_hcic_write_def_policy_set(settings);
909 /*******************************************************************************
911 ** Function BTM_ReadLinkPolicy
913 ** Description This function is called to read the link policy settings.
914 ** The address of link policy results are returned in the callback.
915 ** (tBTM_LNK_POLICY_RESULTS)
917 ** Returns status of the operation
919 *******************************************************************************/
920 tBTM_STATUS BTM_ReadLinkPolicy (BD_ADDR remote_bda, tBTM_CMPL_CB *p_cb)
924 BTM_TRACE_API ("BTM_ReadLinkPolicy: RemBdAddr: %02x%02x%02x%02x%02x%02x",
925 remote_bda[0], remote_bda[1], remote_bda[2],
926 remote_bda[3], remote_bda[4], remote_bda[5]);
928 /* If someone already waiting on the version, do not allow another */
929 if (btm_cb.devcb.p_rlinkp_cmpl_cb)
932 p = btm_bda_to_acl(remote_bda, BT_TRANSPORT_BR_EDR);
933 if (p != (tACL_CONN *)NULL)
935 btu_start_timer (&btm_cb.devcb.rlinkp_timer, BTU_TTYPE_BTM_ACL, BTM_DEV_REPLY_TIMEOUT);
936 btm_cb.devcb.p_rlinkp_cmpl_cb = p_cb;
938 if (!btsnd_hcic_read_policy_set (p->hci_handle))
940 btu_stop_timer (&btm_cb.devcb.rlinkp_timer);
941 btm_cb.devcb.p_rlinkp_cmpl_cb = NULL;
942 return(BTM_NO_RESOURCES);
945 return(BTM_CMD_STARTED);
948 /* If here, no BD Addr found */
949 return(BTM_UNKNOWN_ADDR);
953 /*******************************************************************************
955 ** Function btm_read_link_policy_complete
957 ** Description This function is called when the command complete message
958 ** is received from the HCI for the read local link policy request.
962 *******************************************************************************/
963 void btm_read_link_policy_complete (UINT8 *p)
965 tBTM_CMPL_CB *p_cb = btm_cb.devcb.p_rlinkp_cmpl_cb;
966 tBTM_LNK_POLICY_RESULTS lnkpol;
968 tACL_CONN *p_acl_cb = &btm_cb.acl_db[0];
970 BTM_TRACE_DEBUG ("btm_read_link_policy_complete");
971 btu_stop_timer (&btm_cb.devcb.rlinkp_timer);
973 /* If there was a callback address for read local version, call it */
974 btm_cb.devcb.p_rlinkp_cmpl_cb = NULL;
978 STREAM_TO_UINT8 (lnkpol.hci_status, p);
980 if (lnkpol.hci_status == HCI_SUCCESS)
982 lnkpol.status = BTM_SUCCESS;
984 STREAM_TO_UINT16 (handle, p);
986 STREAM_TO_UINT16 (lnkpol.settings, p);
988 /* Search through the list of active channels for the correct BD Addr */
989 for (index = 0; index < MAX_L2CAP_LINKS; index++, p_acl_cb++)
991 if ((p_acl_cb->in_use) && (handle == p_acl_cb->hci_handle))
993 memcpy (lnkpol.rem_bda, p_acl_cb->remote_addr, BD_ADDR_LEN);
999 lnkpol.status = BTM_ERR_PROCESSING;
1006 /*******************************************************************************
1008 ** Function btm_read_remote_version_complete
1010 ** Description This function is called when the command complete message
1011 ** is received from the HCI for the remote version info.
1015 *******************************************************************************/
1016 void btm_read_remote_version_complete (UINT8 *p)
1018 tACL_CONN *p_acl_cb = &btm_cb.acl_db[0];
1022 BTM_TRACE_DEBUG ("btm_read_remote_version_complete");
1023 STREAM_TO_UINT8 (status, p);
1024 if (status == HCI_SUCCESS)
1026 STREAM_TO_UINT16 (handle, p);
1028 /* Look up the connection by handle and copy features */
1029 for (xx = 0; xx < MAX_L2CAP_LINKS; xx++, p_acl_cb++)
1031 if ((p_acl_cb->in_use) && (p_acl_cb->hci_handle == handle))
1033 STREAM_TO_UINT8 (p_acl_cb->lmp_version, p);
1034 STREAM_TO_UINT16 (p_acl_cb->manufacturer, p);
1035 STREAM_TO_UINT16 (p_acl_cb->lmp_subversion, p);
1043 /*******************************************************************************
1045 ** Function btm_process_remote_ext_features
1047 ** Description Local function called to process all extended features pages
1048 ** read from a remote device.
1052 *******************************************************************************/
1053 void btm_process_remote_ext_features (tACL_CONN *p_acl_cb, UINT8 num_read_pages)
1055 UINT16 handle = p_acl_cb->hci_handle;
1056 tBTM_SEC_DEV_REC *p_dev_rec = btm_find_dev_by_handle (handle);
1059 BTM_TRACE_DEBUG ("btm_process_remote_ext_features");
1061 /* Make sure we have the record to save remote features information */
1062 if (p_dev_rec == NULL)
1064 /* Get a new device; might be doing dedicated bonding */
1065 p_dev_rec = btm_find_or_alloc_dev (p_acl_cb->remote_addr);
1068 p_acl_cb->num_read_pages = num_read_pages;
1069 p_dev_rec->num_read_pages = num_read_pages;
1071 /* Process the pages one by one */
1072 for (page_idx = 0; page_idx < num_read_pages; page_idx++)
1074 btm_process_remote_ext_features_page (p_acl_cb, p_dev_rec, page_idx);
1079 /*******************************************************************************
1081 ** Function btm_process_remote_ext_features_page
1083 ** Description Local function called to process the information located
1084 ** in the specific extended features page read from a remote device.
1088 *******************************************************************************/
1089 void btm_process_remote_ext_features_page (tACL_CONN *p_acl_cb, tBTM_SEC_DEV_REC *p_dev_rec,
1094 memcpy (p_dev_rec->features[page_idx], p_acl_cb->peer_lmp_features[page_idx],
1095 HCI_FEATURE_BYTES_PER_PAGE);
1099 /* Extended (Legacy) Page 0 */
1100 case HCI_EXT_FEATURES_PAGE_0:
1101 /* Page 0 indicates Controller support for SSP */
1102 if (btm_cb.security_mode < BTM_SEC_MODE_SP ||
1103 !HCI_SIMPLE_PAIRING_SUPPORTED(p_dev_rec->features[HCI_EXT_FEATURES_PAGE_0]))
1105 req_pend = (p_dev_rec->sm4 & BTM_SM4_REQ_PEND);
1106 p_dev_rec->sm4 = BTM_SM4_KNOWN;
1109 l2cu_resubmit_pending_sec_req (p_dev_rec->bd_addr);
1114 /* Extended Page 1 */
1115 case HCI_EXT_FEATURES_PAGE_1:
1116 /* Page 1 indicates Host support for SSP and SC */
1117 req_pend = (p_dev_rec->sm4 & BTM_SM4_REQ_PEND);
1119 if (btm_cb.security_mode == BTM_SEC_MODE_SP
1120 && HCI_SSP_HOST_SUPPORTED(p_dev_rec->features[HCI_EXT_FEATURES_PAGE_1])
1121 && HCI_SIMPLE_PAIRING_SUPPORTED(p_dev_rec->features[HCI_EXT_FEATURES_PAGE_0]))
1123 p_dev_rec->sm4 = BTM_SM4_TRUE;
1127 p_dev_rec->sm4 = BTM_SM4_KNOWN;
1130 BTM_TRACE_API ("ext_features_complt page_num:%d f[0]:x%02x, sm4:%x, pend:%d",
1131 HCI_EXT_FEATURES_PAGE_1, *(p_dev_rec->features[HCI_EXT_FEATURES_PAGE_1]),
1132 p_dev_rec->sm4, req_pend);
1135 l2cu_resubmit_pending_sec_req (p_dev_rec->bd_addr);
1139 /* Extended Page 2 */
1140 case HCI_EXT_FEATURES_PAGE_2:
1141 /* Page 2 indicates Ping support*/
1145 BTM_TRACE_ERROR("btm_process_remote_ext_features_page page=%d unexpected", page_idx);
1151 /*******************************************************************************
1153 ** Function btm_read_remote_features
1155 ** Description Local function called to send a read remote supported features/
1156 ** remote extended features page[0].
1160 *******************************************************************************/
1161 void btm_read_remote_features (UINT16 handle)
1164 tACL_CONN *p_acl_cb;
1166 BTM_TRACE_DEBUG("btm_read_remote_features() handle: %d", handle);
1168 if ((acl_idx = btm_handle_to_acl_index(handle)) >= MAX_L2CAP_LINKS)
1170 BTM_TRACE_ERROR("btm_read_remote_features handle=%d invalid", handle);
1174 p_acl_cb = &btm_cb.acl_db[acl_idx];
1175 p_acl_cb->num_read_pages = 0;
1176 memset (p_acl_cb->peer_lmp_features, 0, sizeof(p_acl_cb->peer_lmp_features));
1178 /* first send read remote supported features HCI command */
1179 /* because we don't know whether the remote support extended feature command */
1180 btsnd_hcic_rmt_features_req (handle);
1184 /*******************************************************************************
1186 ** Function btm_read_remote_ext_features
1188 ** Description Local function called to send a read remote extended features
1192 *******************************************************************************/
1193 void btm_read_remote_ext_features (UINT16 handle, UINT8 page_number)
1195 BTM_TRACE_DEBUG("btm_read_remote_ext_features() handle: %d page: %d", handle, page_number);
1197 btsnd_hcic_rmt_ext_features(handle, page_number);
1201 /*******************************************************************************
1203 ** Function btm_read_remote_features_complete
1205 ** Description This function is called when the remote supported features
1206 ** complete event is received from the HCI.
1210 *******************************************************************************/
1211 void btm_read_remote_features_complete (UINT8 *p)
1213 tACL_CONN *p_acl_cb;
1218 BTM_TRACE_DEBUG ("btm_read_remote_features_complete");
1219 STREAM_TO_UINT8 (status, p);
1221 if (status != HCI_SUCCESS)
1223 BTM_TRACE_ERROR ("btm_read_remote_features_complete failed (status 0x%02x)", status);
1227 STREAM_TO_UINT16 (handle, p);
1229 if ((acl_idx = btm_handle_to_acl_index(handle)) >= MAX_L2CAP_LINKS)
1231 BTM_TRACE_ERROR("btm_read_remote_features_complete handle=%d invalid", handle);
1235 p_acl_cb = &btm_cb.acl_db[acl_idx];
1237 /* Copy the received features page */
1238 STREAM_TO_ARRAY(p_acl_cb->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0], p,
1239 HCI_FEATURE_BYTES_PER_PAGE);
1241 if ((HCI_LMP_EXTENDED_SUPPORTED(p_acl_cb->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0])) &&
1242 (controller_get_interface()->supports_reading_remote_extended_features()))
1244 /* if the remote controller has extended features and local controller supports
1245 ** HCI_Read_Remote_Extended_Features command then start reading these feature starting
1246 ** with extended features page 1 */
1247 BTM_TRACE_DEBUG ("Start reading remote extended features");
1248 btm_read_remote_ext_features(handle, HCI_EXT_FEATURES_PAGE_1);
1252 /* Remote controller has no extended features. Process remote controller supported features
1253 (features page HCI_EXT_FEATURES_PAGE_0). */
1254 btm_process_remote_ext_features (p_acl_cb, 1);
1256 /* Continue with HCI connection establishment */
1257 btm_establish_continue (p_acl_cb);
1260 /*******************************************************************************
1262 ** Function btm_read_remote_ext_features_complete
1264 ** Description This function is called when the remote extended features
1265 ** complete event is received from the HCI.
1269 *******************************************************************************/
1270 void btm_read_remote_ext_features_complete (UINT8 *p)
1272 tACL_CONN *p_acl_cb;
1273 UINT8 page_num, max_page;
1277 BTM_TRACE_DEBUG ("btm_read_remote_ext_features_complete");
1280 STREAM_TO_UINT16 (handle, p);
1281 STREAM_TO_UINT8 (page_num, p);
1282 STREAM_TO_UINT8 (max_page, p);
1284 /* Validate parameters */
1285 if ((acl_idx = btm_handle_to_acl_index(handle)) >= MAX_L2CAP_LINKS)
1287 BTM_TRACE_ERROR("btm_read_remote_ext_features_complete handle=%d invalid", handle);
1291 if (max_page > HCI_EXT_FEATURES_PAGE_MAX)
1293 BTM_TRACE_ERROR("btm_read_remote_ext_features_complete page=%d unknown", max_page);
1297 p_acl_cb = &btm_cb.acl_db[acl_idx];
1299 /* Copy the received features page */
1300 STREAM_TO_ARRAY(p_acl_cb->peer_lmp_features[page_num], p, HCI_FEATURE_BYTES_PER_PAGE);
1302 /* If there is the next remote features page and
1303 * we have space to keep this page data - read this page */
1304 if ((page_num < max_page) && (page_num < HCI_EXT_FEATURES_PAGE_MAX))
1307 BTM_TRACE_DEBUG("BTM reads next remote extended features page (%d)", page_num);
1308 btm_read_remote_ext_features (handle, page_num);
1312 /* Reading of remote feature pages is complete */
1313 BTM_TRACE_DEBUG("BTM reached last remote extended features page (%d)", page_num);
1315 /* Process the pages */
1316 btm_process_remote_ext_features (p_acl_cb, (UINT8) (page_num + 1));
1318 /* Continue with HCI connection establishment */
1319 btm_establish_continue (p_acl_cb);
1322 /*******************************************************************************
1324 ** Function btm_read_remote_ext_features_failed
1326 ** Description This function is called when the remote extended features
1327 ** complete event returns a failed status.
1331 *******************************************************************************/
1332 void btm_read_remote_ext_features_failed (UINT8 status, UINT16 handle)
1334 tACL_CONN *p_acl_cb;
1337 BTM_TRACE_WARNING ("btm_read_remote_ext_features_failed (status 0x%02x) for handle %d",
1340 if ((acl_idx = btm_handle_to_acl_index(handle)) >= MAX_L2CAP_LINKS)
1342 BTM_TRACE_ERROR("btm_read_remote_ext_features_failed handle=%d invalid", handle);
1346 p_acl_cb = &btm_cb.acl_db[acl_idx];
1348 /* Process supported features only */
1349 btm_process_remote_ext_features (p_acl_cb, 1);
1351 /* Continue HCI connection establishment */
1352 btm_establish_continue (p_acl_cb);
1355 /*******************************************************************************
1357 ** Function btm_establish_continue
1359 ** Description This function is called when the command complete message
1360 ** is received from the HCI for the read local link policy request.
1364 *******************************************************************************/
1365 void btm_establish_continue (tACL_CONN *p_acl_cb)
1367 tBTM_BL_EVENT_DATA evt_data;
1368 BTM_TRACE_DEBUG ("btm_establish_continue");
1369 #if (!defined(BTM_BYPASS_EXTRA_ACL_SETUP) || BTM_BYPASS_EXTRA_ACL_SETUP == FALSE)
1370 #if (defined BLE_INCLUDED && BLE_INCLUDED == TRUE)
1371 if (p_acl_cb->transport == BT_TRANSPORT_BR_EDR)
1374 /* For now there are a some devices that do not like sending */
1375 /* commands events and data at the same time. */
1376 /* Set the packet types to the default allowed by the device */
1377 btm_set_packet_types (p_acl_cb, btm_cb.btm_acl_pkt_types_supported);
1379 if (btm_cb.btm_def_link_policy)
1380 BTM_SetLinkPolicy (p_acl_cb->remote_addr, &btm_cb.btm_def_link_policy);
1383 p_acl_cb->link_up_issued = TRUE;
1385 /* If anyone cares, tell him database changed */
1386 if (btm_cb.p_bl_changed_cb)
1388 evt_data.event = BTM_BL_CONN_EVT;
1389 evt_data.conn.p_bda = p_acl_cb->remote_addr;
1390 evt_data.conn.p_bdn = p_acl_cb->remote_name;
1391 evt_data.conn.p_dc = p_acl_cb->remote_dc;
1392 evt_data.conn.p_features = p_acl_cb->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0];
1393 #if BLE_INCLUDED == TRUE
1394 evt_data.conn.handle = p_acl_cb->hci_handle;
1395 evt_data.conn.transport = p_acl_cb->transport;
1398 (*btm_cb.p_bl_changed_cb)(&evt_data);
1400 btm_acl_update_busy_level (BTM_BLI_ACL_UP_EVT);
1404 /*******************************************************************************
1406 ** Function BTM_SetDefaultLinkSuperTout
1408 ** Description Set the default value for HCI "Write Link Supervision Timeout"
1409 ** command to use when an ACL link is created.
1413 *******************************************************************************/
1414 void BTM_SetDefaultLinkSuperTout (UINT16 timeout)
1416 BTM_TRACE_DEBUG ("BTM_SetDefaultLinkSuperTout");
1417 btm_cb.btm_def_link_super_tout = timeout;
1420 /*******************************************************************************
1422 ** Function BTM_GetLinkSuperTout
1424 ** Description Read the link supervision timeout value of the connection
1426 ** Returns status of the operation
1428 *******************************************************************************/
1429 tBTM_STATUS BTM_GetLinkSuperTout (BD_ADDR remote_bda, UINT16 *p_timeout)
1431 tACL_CONN *p = btm_bda_to_acl(remote_bda, BT_TRANSPORT_BR_EDR);
1433 BTM_TRACE_DEBUG ("BTM_GetLinkSuperTout");
1434 if (p != (tACL_CONN *)NULL)
1436 *p_timeout = p->link_super_tout;
1437 return(BTM_SUCCESS);
1439 /* If here, no BD Addr found */
1440 return(BTM_UNKNOWN_ADDR);
1444 /*******************************************************************************
1446 ** Function BTM_SetLinkSuperTout
1448 ** Description Create and send HCI "Write Link Supervision Timeout" command
1450 ** Returns status of the operation
1452 *******************************************************************************/
1453 tBTM_STATUS BTM_SetLinkSuperTout (BD_ADDR remote_bda, UINT16 timeout)
1455 tACL_CONN *p = btm_bda_to_acl(remote_bda, BT_TRANSPORT_BR_EDR);
1457 BTM_TRACE_DEBUG ("BTM_SetLinkSuperTout");
1458 if (p != (tACL_CONN *)NULL)
1460 p->link_super_tout = timeout;
1462 /* Only send if current role is Master; 2.0 spec requires this */
1463 if (p->link_role == BTM_ROLE_MASTER)
1465 if (!btsnd_hcic_write_link_super_tout (LOCAL_BR_EDR_CONTROLLER_ID,
1466 p->hci_handle, timeout))
1467 return(BTM_NO_RESOURCES);
1469 return(BTM_CMD_STARTED);
1472 return(BTM_SUCCESS);
1475 /* If here, no BD Addr found */
1476 return(BTM_UNKNOWN_ADDR);
1479 /*******************************************************************************
1481 ** Function BTM_RegForLstoEvt
1483 ** Description register for the HCI "Link Supervision Timeout Change" event
1487 *******************************************************************************/
1488 void BTM_RegForLstoEvt (tBTM_LSTO_CBACK *p_cback)
1490 BTM_TRACE_DEBUG ("BTM_RegForLstoEvt");
1491 btm_cb.p_lsto_cback = p_cback;
1494 /*******************************************************************************
1496 ** Function btm_proc_lsto_evt
1498 ** Description process the HCI "Link Supervision Timeout Change" event
1502 *******************************************************************************/
1503 void btm_proc_lsto_evt(UINT16 handle, UINT16 timeout)
1507 BTM_TRACE_DEBUG ("btm_proc_lsto_evt");
1508 if (btm_cb.p_lsto_cback)
1510 /* Look up the connection by handle and set the current mode */
1511 xx = btm_handle_to_acl_index(handle);
1513 /* don't assume that we can never get a bad hci_handle */
1514 if (xx < MAX_L2CAP_LINKS)
1516 (*btm_cb.p_lsto_cback)(btm_cb.acl_db[xx].remote_addr, timeout);
1521 /*******************************************************************************
1523 ** Function BTM_SetPacketTypes
1525 ** Description This function is set the packet types used for a specific
1528 ** Returns status of the operation
1530 *******************************************************************************/
1531 tBTM_STATUS BTM_SetPacketTypes (BD_ADDR remote_bda, UINT16 pkt_types)
1534 BTM_TRACE_DEBUG ("BTM_SetPacketTypes");
1536 if ((p = btm_bda_to_acl(remote_bda, BT_TRANSPORT_BR_EDR)) != NULL)
1537 return(btm_set_packet_types (p, pkt_types));
1539 /* If here, no BD Addr found */
1540 return(BTM_UNKNOWN_ADDR);
1544 /*******************************************************************************
1546 ** Function BTM_ReadPacketTypes
1548 ** Description This function is set the packet types used for a specific
1551 ** Returns packet types supported for the connection, or 0 if no BD address
1553 *******************************************************************************/
1554 UINT16 BTM_ReadPacketTypes (BD_ADDR remote_bda)
1558 BTM_TRACE_DEBUG ("BTM_ReadPacketTypes");
1559 p = btm_bda_to_acl(remote_bda, BT_TRANSPORT_BR_EDR);
1560 if (p != (tACL_CONN *)NULL)
1562 return(p->pkt_types_mask);
1565 /* If here, no BD Addr found */
1569 /*******************************************************************************
1571 ** Function BTM_ReadClockOffset
1573 ** Description This returns the clock offset for a specific
1576 ** Input Param remote_bda - device address of desired ACL connection
1578 ** Returns clock-offset or 0 if unknown
1580 *******************************************************************************/
1581 UINT16 BTM_ReadClockOffset (BD_ADDR remote_bda)
1585 BTM_TRACE_API ("BTM_ReadClockOffset: RemBdAddr: %02x%02x%02x%02x%02x%02x",
1586 remote_bda[0], remote_bda[1], remote_bda[2],
1587 remote_bda[3], remote_bda[4], remote_bda[5]);
1589 if ( (p = btm_bda_to_acl(remote_bda, BT_TRANSPORT_BR_EDR)) != NULL)
1590 return(p->clock_offset);
1592 /* If here, no BD Addr found */
1596 /*******************************************************************************
1598 ** Function BTM_IsAclConnectionUp
1600 ** Description This function is called to check if an ACL connection exists
1601 ** to a specific remote BD Address.
1603 ** Returns TRUE if connection is up, else FALSE.
1605 *******************************************************************************/
1606 BOOLEAN BTM_IsAclConnectionUp (BD_ADDR remote_bda, tBT_TRANSPORT transport)
1610 BTM_TRACE_API ("BTM_IsAclConnectionUp: RemBdAddr: %02x%02x%02x%02x%02x%02x",
1611 remote_bda[0], remote_bda[1], remote_bda[2],
1612 remote_bda[3], remote_bda[4], remote_bda[5]);
1614 p = btm_bda_to_acl(remote_bda, transport);
1615 if (p != (tACL_CONN *)NULL)
1620 /* If here, no BD Addr found */
1624 /*******************************************************************************
1626 ** Function BTM_GetNumAclLinks
1628 ** Description This function is called to count the number of
1629 ** ACL links that are active.
1631 ** Returns UINT16 Number of active ACL links
1633 *******************************************************************************/
1634 UINT16 BTM_GetNumAclLinks (void)
1636 return(UINT16)btm_cb.num_acl;
1639 /*******************************************************************************
1641 ** Function btm_get_acl_disc_reason_code
1643 ** Description This function is called to get the disconnection reason code
1644 ** returned by the HCI at disconnection complete event.
1646 ** Returns TRUE if connection is up, else FALSE.
1648 *******************************************************************************/
1649 UINT16 btm_get_acl_disc_reason_code (void)
1651 UINT8 res = btm_cb.acl_disc_reason;
1652 BTM_TRACE_DEBUG ("btm_get_acl_disc_reason_code");
1657 /*******************************************************************************
1659 ** Function BTM_GetHCIConnHandle
1661 ** Description This function is called to get the handle for an ACL connection
1662 ** to a specific remote BD Address.
1664 ** Returns the handle of the connection, or 0xFFFF if none.
1666 *******************************************************************************/
1667 UINT16 BTM_GetHCIConnHandle (BD_ADDR remote_bda, tBT_TRANSPORT transport)
1670 BTM_TRACE_DEBUG ("BTM_GetHCIConnHandle");
1671 p = btm_bda_to_acl(remote_bda, transport);
1672 if (p != (tACL_CONN *)NULL)
1674 return(p->hci_handle);
1677 /* If here, no BD Addr found */
1681 /*******************************************************************************
1683 ** Function btm_process_clk_off_comp_evt
1685 ** Description This function is called when clock offset command completes.
1687 ** Input Parms hci_handle - connection handle associated with the change
1692 *******************************************************************************/
1693 void btm_process_clk_off_comp_evt (UINT16 hci_handle, UINT16 clock_offset)
1696 BTM_TRACE_DEBUG ("btm_process_clk_off_comp_evt");
1697 /* Look up the connection by handle and set the current mode */
1698 if ((xx = btm_handle_to_acl_index(hci_handle)) < MAX_L2CAP_LINKS)
1699 btm_cb.acl_db[xx].clock_offset = clock_offset;
1702 /*******************************************************************************
1704 ** Function btm_acl_role_changed
1706 ** Description This function is called whan a link's master/slave role change
1707 ** event or command status event (with error) is received.
1708 ** It updates the link control block, and calls
1709 ** the registered callback with status and role (if registered).
1713 *******************************************************************************/
1714 void btm_acl_role_changed (UINT8 hci_status, BD_ADDR bd_addr, UINT8 new_role)
1716 UINT8 *p_bda = (bd_addr) ? bd_addr :
1717 btm_cb.devcb.switch_role_ref_data.remote_bd_addr;
1718 tACL_CONN *p = btm_bda_to_acl(p_bda, BT_TRANSPORT_BR_EDR);
1719 tBTM_ROLE_SWITCH_CMPL *p_data = &btm_cb.devcb.switch_role_ref_data;
1720 tBTM_SEC_DEV_REC *p_dev_rec;
1721 tBTM_BL_ROLE_CHG_DATA evt;
1723 BTM_TRACE_DEBUG ("btm_acl_role_changed");
1724 /* Ignore any stray events */
1727 /* it could be a failure */
1728 if (hci_status != HCI_SUCCESS)
1729 btm_acl_report_role_change(hci_status, bd_addr);
1733 p_data->hci_status = hci_status;
1735 if (hci_status == HCI_SUCCESS)
1737 p_data->role = new_role;
1738 memcpy(p_data->remote_bd_addr, p_bda, BD_ADDR_LEN);
1740 /* Update cached value */
1741 p->link_role = new_role;
1743 /* Reload LSTO: link supervision timeout is reset in the LM after a role switch */
1744 if (new_role == BTM_ROLE_MASTER)
1746 BTM_SetLinkSuperTout (p->remote_addr, p->link_super_tout);
1751 /* so the BTM_BL_ROLE_CHG_EVT uses the old role */
1752 new_role = p->link_role;
1755 /* Check if any SCO req is pending for role change */
1756 btm_sco_chk_pend_rolechange (p->hci_handle);
1758 /* if switching state is switching we need to turn encryption on */
1759 /* if idle, we did not change encryption */
1760 if (p->switch_role_state == BTM_ACL_SWKEY_STATE_SWITCHING)
1762 if (btsnd_hcic_set_conn_encrypt (p->hci_handle, TRUE))
1764 p->encrypt_state = BTM_ACL_ENCRYPT_STATE_ENCRYPT_ON;
1765 p->switch_role_state = BTM_ACL_SWKEY_STATE_ENCRYPTION_ON;
1770 /* Set the switch_role_state to IDLE since the reply received from HCI */
1771 /* regardless of its result either success or failed. */
1772 if (p->switch_role_state == BTM_ACL_SWKEY_STATE_IN_PROGRESS)
1774 p->switch_role_state = BTM_ACL_SWKEY_STATE_IDLE;
1775 p->encrypt_state = BTM_ACL_ENCRYPT_STATE_IDLE;
1778 /* if role switch complete is needed, report it now */
1779 btm_acl_report_role_change(hci_status, bd_addr);
1781 /* if role change event is registered, report it now */
1782 if (btm_cb.p_bl_changed_cb && (btm_cb.bl_evt_mask & BTM_BL_ROLE_CHG_MASK))
1784 evt.event = BTM_BL_ROLE_CHG_EVT;
1785 evt.new_role = new_role;
1787 evt.hci_status = hci_status;
1788 (*btm_cb.p_bl_changed_cb)((tBTM_BL_EVENT_DATA *)&evt);
1791 BTM_TRACE_DEBUG("Role Switch Event: new_role 0x%02x, HCI Status 0x%02x, rs_st:%d",
1792 p_data->role, p_data->hci_status, p->switch_role_state);
1794 #if BTM_DISC_DURING_RS == TRUE
1795 /* If a disconnect is pending, issue it now that role switch has completed */
1796 if ((p_dev_rec = btm_find_dev (p_bda)) != NULL)
1798 if (p_dev_rec->rs_disc_pending == BTM_SEC_DISC_PENDING)
1800 BTM_TRACE_WARNING("btm_acl_role_changed -> Issuing delayed HCI_Disconnect!!!");
1801 btsnd_hcic_disconnect(p_dev_rec->hci_handle, HCI_ERR_PEER_USER);
1803 BTM_TRACE_ERROR("tBTM_SEC_DEV:0x%x rs_disc_pending=%d",
1804 (UINT32)p_dev_rec, p_dev_rec->rs_disc_pending);
1805 p_dev_rec->rs_disc_pending = BTM_SEC_RS_NOT_PENDING; /* reset flag */
1812 #if (RFCOMM_INCLUDED==TRUE)
1813 /*******************************************************************************
1815 ** Function BTM_AllocateSCN
1817 ** Description Look through the Server Channel Numbers for a free one.
1819 ** Returns Allocated SCN number or 0 if none.
1821 *******************************************************************************/
1823 UINT8 BTM_AllocateSCN(void)
1826 BTM_TRACE_DEBUG ("BTM_AllocateSCN");
1828 // stack reserves scn 1 for HFP, HSP we still do the correct way
1829 for (x = 1; x < BTM_MAX_SCN; x++)
1831 if (!btm_cb.btm_scn[x])
1833 btm_cb.btm_scn[x] = TRUE;
1838 return(0); /* No free ports */
1841 /*******************************************************************************
1843 ** Function BTM_TryAllocateSCN
1845 ** Description Try to allocate a fixed server channel
1847 ** Returns Returns TRUE if server channel was available
1849 *******************************************************************************/
1851 BOOLEAN BTM_TryAllocateSCN(UINT8 scn)
1855 /* Make sure we don't exceed max port range.
1856 * Stack reserves scn 1 for HFP, HSP we still do the correct way.
1858 if ( (scn>=BTM_MAX_SCN) || (scn == 1) )
1861 /* check if this port is available */
1862 if (!btm_cb.btm_scn[scn-1])
1864 btm_cb.btm_scn[scn-1] = TRUE;
1868 return (FALSE); /* Port was busy */
1871 /*******************************************************************************
1873 ** Function BTM_FreeSCN
1875 ** Description Free the specified SCN.
1877 ** Returns TRUE or FALSE
1879 *******************************************************************************/
1880 BOOLEAN BTM_FreeSCN(UINT8 scn)
1882 BTM_TRACE_DEBUG ("BTM_FreeSCN ");
1883 if (scn <= BTM_MAX_SCN)
1885 btm_cb.btm_scn[scn-1] = FALSE;
1889 return(FALSE); /* Illegal SCN passed in */
1894 /* Make dummy functions for the RPC to link against */
1895 UINT8 BTM_AllocateSCN(void)
1900 BOOLEAN BTM_FreeSCN(UINT8 scn)
1908 /*******************************************************************************
1910 ** Function btm_acl_timeout
1912 ** Description This function is called when a timer list entry expires.
1916 *******************************************************************************/
1917 void btm_acl_timeout (TIMER_LIST_ENT *p_tle)
1919 UINT32 timer_type = p_tle->param;
1921 BTM_TRACE_DEBUG ("btm_acl_timeout");
1922 if (timer_type == TT_DEV_RLNKP)
1924 tBTM_CMPL_CB *p_cb = btm_cb.devcb.p_rlinkp_cmpl_cb;
1925 tBTM_LNK_POLICY_RESULTS lnkpol;
1927 lnkpol.status = BTM_ERR_PROCESSING;
1928 lnkpol.settings = 0;
1930 btm_cb.devcb.p_rlinkp_cmpl_cb = NULL;
1937 /*******************************************************************************
1939 ** Function btm_set_packet_types
1941 ** Description This function sets the packet types used for a specific
1942 ** ACL connection. It is called internally by btm_acl_created
1943 ** or by an application/profile by BTM_SetPacketTypes.
1945 ** Returns status of the operation
1947 *******************************************************************************/
1948 tBTM_STATUS btm_set_packet_types (tACL_CONN *p, UINT16 pkt_types)
1950 UINT16 temp_pkt_types;
1951 BTM_TRACE_DEBUG ("btm_set_packet_types");
1952 /* Save in the ACL control blocks, types that we support */
1953 temp_pkt_types = (pkt_types & BTM_ACL_SUPPORTED_PKTS_MASK &
1954 btm_cb.btm_acl_pkt_types_supported);
1956 /* OR in any exception packet types if at least 2.0 version of spec */
1957 temp_pkt_types |= ((pkt_types & BTM_ACL_EXCEPTION_PKTS_MASK) |
1958 (btm_cb.btm_acl_pkt_types_supported & BTM_ACL_EXCEPTION_PKTS_MASK));
1960 /* Exclude packet types not supported by the peer */
1961 btm_acl_chk_peer_pkt_type_support (p, &temp_pkt_types);
1963 BTM_TRACE_DEBUG ("SetPacketType Mask -> 0x%04x", temp_pkt_types);
1965 if (!btsnd_hcic_change_conn_type (p->hci_handle, temp_pkt_types))
1967 return(BTM_NO_RESOURCES);
1970 p->pkt_types_mask = temp_pkt_types;
1972 return(BTM_CMD_STARTED);
1975 /*******************************************************************************
1977 ** Function btm_get_max_packet_size
1979 ** Returns Returns maximum packet size that can be used for current
1980 ** connection, 0 if connection is not established
1982 *******************************************************************************/
1983 UINT16 btm_get_max_packet_size (BD_ADDR addr)
1985 tACL_CONN *p = btm_bda_to_acl(addr, BT_TRANSPORT_BR_EDR);
1986 UINT16 pkt_types = 0;
1987 UINT16 pkt_size = 0;
1988 BTM_TRACE_DEBUG ("btm_get_max_packet_size");
1991 pkt_types = p->pkt_types_mask;
1995 /* Special case for when info for the local device is requested */
1996 if (memcmp (controller_get_interface()->get_address(), addr, BD_ADDR_LEN) == 0)
1998 pkt_types = btm_cb.btm_acl_pkt_types_supported;
2004 if (!(pkt_types & BTM_ACL_PKT_TYPES_MASK_NO_3_DH5))
2005 pkt_size = HCI_EDR3_DH5_PACKET_SIZE;
2006 else if (!(pkt_types & BTM_ACL_PKT_TYPES_MASK_NO_2_DH5))
2007 pkt_size = HCI_EDR2_DH5_PACKET_SIZE;
2008 else if (!(pkt_types & BTM_ACL_PKT_TYPES_MASK_NO_3_DH3))
2009 pkt_size = HCI_EDR3_DH3_PACKET_SIZE;
2010 else if (pkt_types & BTM_ACL_PKT_TYPES_MASK_DH5)
2011 pkt_size = HCI_DH5_PACKET_SIZE;
2012 else if (!(pkt_types & BTM_ACL_PKT_TYPES_MASK_NO_2_DH3))
2013 pkt_size = HCI_EDR2_DH3_PACKET_SIZE;
2014 else if (pkt_types & BTM_ACL_PKT_TYPES_MASK_DM5)
2015 pkt_size = HCI_DM5_PACKET_SIZE;
2016 else if (pkt_types & BTM_ACL_PKT_TYPES_MASK_DH3)
2017 pkt_size = HCI_DH3_PACKET_SIZE;
2018 else if (pkt_types & BTM_ACL_PKT_TYPES_MASK_DM3)
2019 pkt_size = HCI_DM3_PACKET_SIZE;
2020 else if (!(pkt_types & BTM_ACL_PKT_TYPES_MASK_NO_3_DH1))
2021 pkt_size = HCI_EDR3_DH1_PACKET_SIZE;
2022 else if (!(pkt_types & BTM_ACL_PKT_TYPES_MASK_NO_2_DH1))
2023 pkt_size = HCI_EDR2_DH1_PACKET_SIZE;
2024 else if (pkt_types & BTM_ACL_PKT_TYPES_MASK_DH1)
2025 pkt_size = HCI_DH1_PACKET_SIZE;
2026 else if (pkt_types & BTM_ACL_PKT_TYPES_MASK_DM1)
2027 pkt_size = HCI_DM1_PACKET_SIZE;
2033 /*******************************************************************************
2035 ** Function BTM_ReadRemoteVersion
2037 ** Returns If connected report peer device info
2039 *******************************************************************************/
2040 tBTM_STATUS BTM_ReadRemoteVersion (BD_ADDR addr, UINT8 *lmp_version,
2041 UINT16 *manufacturer, UINT16 *lmp_sub_version)
2043 tACL_CONN *p = btm_bda_to_acl(addr, BT_TRANSPORT_BR_EDR);
2044 BTM_TRACE_DEBUG ("BTM_ReadRemoteVersion");
2046 return(BTM_UNKNOWN_ADDR);
2049 *lmp_version = p->lmp_version;
2052 *manufacturer = p->manufacturer;
2054 if (lmp_sub_version)
2055 *lmp_sub_version = p->lmp_subversion;
2057 return(BTM_SUCCESS);
2060 /*******************************************************************************
2062 ** Function BTM_ReadRemoteFeatures
2064 ** Returns pointer to the remote supported features mask (8 bytes)
2066 *******************************************************************************/
2067 UINT8 *BTM_ReadRemoteFeatures (BD_ADDR addr)
2069 tACL_CONN *p = btm_bda_to_acl(addr, BT_TRANSPORT_BR_EDR);
2070 BTM_TRACE_DEBUG ("BTM_ReadRemoteFeatures");
2076 return(p->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0]);
2079 /*******************************************************************************
2081 ** Function BTM_ReadRemoteExtendedFeatures
2083 ** Returns pointer to the remote extended features mask (8 bytes)
2084 ** or NULL if bad page
2086 *******************************************************************************/
2087 UINT8 *BTM_ReadRemoteExtendedFeatures (BD_ADDR addr, UINT8 page_number)
2089 tACL_CONN *p = btm_bda_to_acl(addr, BT_TRANSPORT_BR_EDR);
2090 BTM_TRACE_DEBUG ("BTM_ReadRemoteExtendedFeatures");
2096 if (page_number > HCI_EXT_FEATURES_PAGE_MAX)
2098 BTM_TRACE_ERROR("Warning: BTM_ReadRemoteExtendedFeatures page %d unknown", page_number);
2102 return(p->peer_lmp_features[page_number]);
2105 /*******************************************************************************
2107 ** Function BTM_ReadNumberRemoteFeaturesPages
2109 ** Returns number of features pages read from the remote device.
2111 *******************************************************************************/
2112 UINT8 BTM_ReadNumberRemoteFeaturesPages (BD_ADDR addr)
2114 tACL_CONN *p = btm_bda_to_acl(addr, BT_TRANSPORT_BR_EDR);
2115 BTM_TRACE_DEBUG ("BTM_ReadNumberRemoteFeaturesPages");
2121 return(p->num_read_pages);
2124 /*******************************************************************************
2126 ** Function BTM_ReadAllRemoteFeatures
2128 ** Returns pointer to all features of the remote (24 bytes).
2130 *******************************************************************************/
2131 UINT8 *BTM_ReadAllRemoteFeatures (BD_ADDR addr)
2133 tACL_CONN *p = btm_bda_to_acl(addr, BT_TRANSPORT_BR_EDR);
2134 BTM_TRACE_DEBUG ("BTM_ReadAllRemoteFeatures");
2140 return(p->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0]);
2143 /*******************************************************************************
2145 ** Function BTM_RegBusyLevelNotif
2147 ** Description This function is called to register a callback to receive
2148 ** busy level change events.
2150 ** Returns BTM_SUCCESS if successfully registered, otherwise error
2152 *******************************************************************************/
2153 tBTM_STATUS BTM_RegBusyLevelNotif (tBTM_BL_CHANGE_CB *p_cb, UINT8 *p_level,
2154 tBTM_BL_EVENT_MASK evt_mask)
2156 BTM_TRACE_DEBUG ("BTM_RegBusyLevelNotif");
2158 *p_level = btm_cb.busy_level;
2160 btm_cb.bl_evt_mask = evt_mask;
2163 btm_cb.p_bl_changed_cb = NULL;
2164 else if (btm_cb.p_bl_changed_cb)
2167 btm_cb.p_bl_changed_cb = p_cb;
2169 return(BTM_SUCCESS);
2172 /*******************************************************************************
2174 ** Function BTM_SetQoS
2176 ** Description This function is called to setup QoS
2178 ** Returns status of the operation
2180 *******************************************************************************/
2181 tBTM_STATUS BTM_SetQoS (BD_ADDR bd, FLOW_SPEC *p_flow, tBTM_CMPL_CB *p_cb)
2183 tACL_CONN *p = &btm_cb.acl_db[0];
2185 BTM_TRACE_API ("BTM_SetQoS: BdAddr: %02x%02x%02x%02x%02x%02x",
2186 bd[0], bd[1], bd[2],
2187 bd[3], bd[4], bd[5]);
2189 /* If someone already waiting on the version, do not allow another */
2190 if (btm_cb.devcb.p_qossu_cmpl_cb)
2193 if ( (p = btm_bda_to_acl(bd, BT_TRANSPORT_BR_EDR)) != NULL)
2195 btu_start_timer (&btm_cb.devcb.qossu_timer, BTU_TTYPE_BTM_ACL, BTM_DEV_REPLY_TIMEOUT);
2196 btm_cb.devcb.p_qossu_cmpl_cb = p_cb;
2198 if (!btsnd_hcic_qos_setup (p->hci_handle, p_flow->qos_flags, p_flow->service_type,
2199 p_flow->token_rate, p_flow->peak_bandwidth,
2200 p_flow->latency,p_flow->delay_variation))
2202 btm_cb.devcb.p_qossu_cmpl_cb = NULL;
2203 btu_stop_timer(&btm_cb.devcb.qossu_timer);
2204 return(BTM_NO_RESOURCES);
2207 return(BTM_CMD_STARTED);
2210 /* If here, no BD Addr found */
2211 return(BTM_UNKNOWN_ADDR);
2214 /*******************************************************************************
2216 ** Function btm_qos_setup_complete
2218 ** Description This function is called when the command complete message
2219 ** is received from the HCI for the qos setup request.
2223 *******************************************************************************/
2224 void btm_qos_setup_complete (UINT8 status, UINT16 handle, FLOW_SPEC *p_flow)
2226 tBTM_CMPL_CB *p_cb = btm_cb.devcb.p_qossu_cmpl_cb;
2227 tBTM_QOS_SETUP_CMPL qossu;
2228 BTM_TRACE_DEBUG ("btm_qos_setup_complete");
2229 btu_stop_timer (&btm_cb.devcb.qossu_timer);
2231 btm_cb.devcb.p_qossu_cmpl_cb = NULL;
2235 memset(&qossu, 0, sizeof(tBTM_QOS_SETUP_CMPL));
2236 qossu.status = status;
2237 qossu.handle = handle;
2240 qossu.flow.qos_flags = p_flow->qos_flags;
2241 qossu.flow.service_type = p_flow->service_type;
2242 qossu.flow.token_rate = p_flow->token_rate;
2243 qossu.flow.peak_bandwidth = p_flow->peak_bandwidth;
2244 qossu.flow.latency = p_flow->latency;
2245 qossu.flow.delay_variation = p_flow->delay_variation;
2247 BTM_TRACE_DEBUG ("BTM: p_flow->delay_variation: 0x%02x",
2248 qossu.flow.delay_variation);
2254 /*******************************************************************************
2256 ** Function BTM_ReadRSSI
2258 ** Description This function is called to read the link policy settings.
2259 ** The address of link policy results are returned in the callback.
2260 ** (tBTM_RSSI_RESULTS)
2262 ** Returns BTM_CMD_STARTED if successfully initiated or error code
2264 *******************************************************************************/
2265 tBTM_STATUS BTM_ReadRSSI (BD_ADDR remote_bda, tBTM_CMPL_CB *p_cb)
2268 tBT_TRANSPORT transport = BT_TRANSPORT_BR_EDR;
2269 #if BLE_INCLUDED == TRUE
2270 tBT_DEVICE_TYPE dev_type;
2271 tBLE_ADDR_TYPE addr_type;
2273 BTM_TRACE_API ("BTM_ReadRSSI: RemBdAddr: %02x%02x%02x%02x%02x%02x",
2274 remote_bda[0], remote_bda[1], remote_bda[2],
2275 remote_bda[3], remote_bda[4], remote_bda[5]);
2277 /* If someone already waiting on the version, do not allow another */
2278 if (btm_cb.devcb.p_rssi_cmpl_cb)
2281 #if BLE_INCLUDED == TRUE
2282 BTM_ReadDevInfo(remote_bda, &dev_type, &addr_type);
2283 if (dev_type == BT_DEVICE_TYPE_BLE)
2284 transport = BT_TRANSPORT_LE;
2287 p = btm_bda_to_acl(remote_bda, transport);
2288 if (p != (tACL_CONN *)NULL)
2290 btu_start_timer (&btm_cb.devcb.rssi_timer, BTU_TTYPE_BTM_ACL,
2291 BTM_DEV_REPLY_TIMEOUT);
2293 btm_cb.devcb.p_rssi_cmpl_cb = p_cb;
2295 if (!btsnd_hcic_read_rssi (p->hci_handle))
2297 btm_cb.devcb.p_rssi_cmpl_cb = NULL;
2298 btu_stop_timer (&btm_cb.devcb.rssi_timer);
2299 return(BTM_NO_RESOURCES);
2302 return(BTM_CMD_STARTED);
2305 /* If here, no BD Addr found */
2306 return(BTM_UNKNOWN_ADDR);
2309 /*******************************************************************************
2311 ** Function BTM_ReadLinkQuality
2313 ** Description This function is called to read the link qulaity.
2314 ** The value of the link quality is returned in the callback.
2315 ** (tBTM_LINK_QUALITY_RESULTS)
2317 ** Returns BTM_CMD_STARTED if successfully initiated or error code
2319 *******************************************************************************/
2320 tBTM_STATUS BTM_ReadLinkQuality (BD_ADDR remote_bda, tBTM_CMPL_CB *p_cb)
2324 BTM_TRACE_API ("BTM_ReadLinkQuality: RemBdAddr: %02x%02x%02x%02x%02x%02x",
2325 remote_bda[0], remote_bda[1], remote_bda[2],
2326 remote_bda[3], remote_bda[4], remote_bda[5]);
2328 /* If someone already waiting on the version, do not allow another */
2329 if (btm_cb.devcb.p_lnk_qual_cmpl_cb)
2332 p = btm_bda_to_acl(remote_bda, BT_TRANSPORT_BR_EDR);
2333 if (p != (tACL_CONN *)NULL)
2335 btu_start_timer (&btm_cb.devcb.lnk_quality_timer, BTU_TTYPE_BTM_ACL,
2336 BTM_DEV_REPLY_TIMEOUT);
2337 btm_cb.devcb.p_lnk_qual_cmpl_cb = p_cb;
2339 if (!btsnd_hcic_get_link_quality (p->hci_handle))
2341 btu_stop_timer (&btm_cb.devcb.lnk_quality_timer);
2342 btm_cb.devcb.p_lnk_qual_cmpl_cb = NULL;
2343 return(BTM_NO_RESOURCES);
2346 return(BTM_CMD_STARTED);
2349 /* If here, no BD Addr found */
2350 return(BTM_UNKNOWN_ADDR);
2353 /*******************************************************************************
2355 ** Function BTM_ReadTxPower
2357 ** Description This function is called to read the current
2358 ** TX power of the connection. The tx power level results
2359 ** are returned in the callback.
2360 ** (tBTM_RSSI_RESULTS)
2362 ** Returns BTM_CMD_STARTED if successfully initiated or error code
2364 *******************************************************************************/
2365 tBTM_STATUS BTM_ReadTxPower (BD_ADDR remote_bda, tBT_TRANSPORT transport, tBTM_CMPL_CB *p_cb)
2369 #define BTM_READ_RSSI_TYPE_CUR 0x00
2370 #define BTM_READ_RSSI_TYPE_MAX 0X01
2372 BTM_TRACE_API ("BTM_ReadTxPower: RemBdAddr: %02x%02x%02x%02x%02x%02x",
2373 remote_bda[0], remote_bda[1], remote_bda[2],
2374 remote_bda[3], remote_bda[4], remote_bda[5]);
2376 /* If someone already waiting on the version, do not allow another */
2377 if (btm_cb.devcb.p_tx_power_cmpl_cb)
2380 p = btm_bda_to_acl(remote_bda, transport);
2381 if (p != (tACL_CONN *)NULL)
2383 btu_start_timer (&btm_cb.devcb.tx_power_timer, BTU_TTYPE_BTM_ACL,
2384 BTM_DEV_REPLY_TIMEOUT);
2386 btm_cb.devcb.p_tx_power_cmpl_cb = p_cb;
2388 #if BLE_INCLUDED == TRUE
2389 if (p->transport == BT_TRANSPORT_LE)
2391 memcpy(btm_cb.devcb.read_tx_pwr_addr, remote_bda, BD_ADDR_LEN);
2392 ret = btsnd_hcic_ble_read_adv_chnl_tx_power();
2397 ret = btsnd_hcic_read_tx_power (p->hci_handle, BTM_READ_RSSI_TYPE_CUR);
2401 btm_cb.devcb.p_tx_power_cmpl_cb = NULL;
2402 btu_stop_timer (&btm_cb.devcb.tx_power_timer);
2403 return(BTM_NO_RESOURCES);
2406 return(BTM_CMD_STARTED);
2409 /* If here, no BD Addr found */
2410 return (BTM_UNKNOWN_ADDR);
2412 /*******************************************************************************
2414 ** Function btm_read_tx_power_complete
2416 ** Description This function is called when the command complete message
2417 ** is received from the HCI for the read tx power request.
2421 *******************************************************************************/
2422 void btm_read_tx_power_complete (UINT8 *p, BOOLEAN is_ble)
2424 tBTM_CMPL_CB *p_cb = btm_cb.devcb.p_tx_power_cmpl_cb;
2425 tBTM_TX_POWER_RESULTS results;
2427 tACL_CONN *p_acl_cb = &btm_cb.acl_db[0];
2429 BTM_TRACE_DEBUG ("btm_read_tx_power_complete");
2430 btu_stop_timer (&btm_cb.devcb.tx_power_timer);
2432 /* If there was a callback registered for read rssi, call it */
2433 btm_cb.devcb.p_tx_power_cmpl_cb = NULL;
2437 STREAM_TO_UINT8 (results.hci_status, p);
2439 if (results.hci_status == HCI_SUCCESS)
2441 results.status = BTM_SUCCESS;
2445 STREAM_TO_UINT16 (handle, p);
2446 STREAM_TO_UINT8 (results.tx_power, p);
2448 /* Search through the list of active channels for the correct BD Addr */
2449 for (index = 0; index < MAX_L2CAP_LINKS; index++, p_acl_cb++)
2451 if ((p_acl_cb->in_use) && (handle == p_acl_cb->hci_handle))
2453 memcpy (results.rem_bda, p_acl_cb->remote_addr, BD_ADDR_LEN);
2458 #if BLE_INCLUDED == TRUE
2461 STREAM_TO_UINT8 (results.tx_power, p);
2462 memcpy(results.rem_bda, btm_cb.devcb.read_tx_pwr_addr, BD_ADDR_LEN);
2465 BTM_TRACE_DEBUG ("BTM TX power Complete: tx_power %d, hci status 0x%02x",
2466 results.tx_power, results.hci_status);
2469 results.status = BTM_ERR_PROCESSING;
2475 /*******************************************************************************
2477 ** Function btm_read_rssi_complete
2479 ** Description This function is called when the command complete message
2480 ** is received from the HCI for the read rssi request.
2484 *******************************************************************************/
2485 void btm_read_rssi_complete (UINT8 *p)
2487 tBTM_CMPL_CB *p_cb = btm_cb.devcb.p_rssi_cmpl_cb;
2488 tBTM_RSSI_RESULTS results;
2490 tACL_CONN *p_acl_cb = &btm_cb.acl_db[0];
2492 BTM_TRACE_DEBUG ("btm_read_rssi_complete");
2493 btu_stop_timer (&btm_cb.devcb.rssi_timer);
2495 /* If there was a callback registered for read rssi, call it */
2496 btm_cb.devcb.p_rssi_cmpl_cb = NULL;
2500 STREAM_TO_UINT8 (results.hci_status, p);
2502 if (results.hci_status == HCI_SUCCESS)
2504 results.status = BTM_SUCCESS;
2506 STREAM_TO_UINT16 (handle, p);
2508 STREAM_TO_UINT8 (results.rssi, p);
2509 BTM_TRACE_DEBUG ("BTM RSSI Complete: rssi %d, hci status 0x%02x",
2510 results.rssi, results.hci_status);
2512 /* Search through the list of active channels for the correct BD Addr */
2513 for (index = 0; index < MAX_L2CAP_LINKS; index++, p_acl_cb++)
2515 if ((p_acl_cb->in_use) && (handle == p_acl_cb->hci_handle))
2517 memcpy (results.rem_bda, p_acl_cb->remote_addr, BD_ADDR_LEN);
2523 results.status = BTM_ERR_PROCESSING;
2529 /*******************************************************************************
2531 ** Function btm_read_link_quality_complete
2533 ** Description This function is called when the command complete message
2534 ** is received from the HCI for the read link quality.
2538 *******************************************************************************/
2539 void btm_read_link_quality_complete (UINT8 *p)
2541 tBTM_CMPL_CB *p_cb = btm_cb.devcb.p_lnk_qual_cmpl_cb;
2542 tBTM_LINK_QUALITY_RESULTS results;
2544 tACL_CONN *p_acl_cb = &btm_cb.acl_db[0];
2546 BTM_TRACE_DEBUG ("btm_read_link_quality_complete");
2547 btu_stop_timer (&btm_cb.devcb.lnk_quality_timer);
2549 /* If there was a callback registered for read rssi, call it */
2550 btm_cb.devcb.p_lnk_qual_cmpl_cb = NULL;
2554 STREAM_TO_UINT8 (results.hci_status, p);
2556 if (results.hci_status == HCI_SUCCESS)
2558 results.status = BTM_SUCCESS;
2560 STREAM_TO_UINT16 (handle, p);
2562 STREAM_TO_UINT8 (results.link_quality, p);
2563 BTM_TRACE_DEBUG ("BTM Link Quality Complete: Link Quality %d, hci status 0x%02x",
2564 results.link_quality, results.hci_status);
2566 /* Search through the list of active channels for the correct BD Addr */
2567 for (index = 0; index < MAX_L2CAP_LINKS; index++, p_acl_cb++)
2569 if ((p_acl_cb->in_use) && (handle == p_acl_cb->hci_handle))
2571 memcpy (results.rem_bda, p_acl_cb->remote_addr, BD_ADDR_LEN);
2577 results.status = BTM_ERR_PROCESSING;
2583 /*******************************************************************************
2585 ** Function btm_remove_acl
2587 ** Description This function is called to disconnect an ACL connection
2589 ** Returns BTM_SUCCESS if successfully initiated, otherwise BTM_NO_RESOURCES.
2591 *******************************************************************************/
2592 tBTM_STATUS btm_remove_acl (BD_ADDR bd_addr, tBT_TRANSPORT transport)
2594 UINT16 hci_handle = BTM_GetHCIConnHandle(bd_addr, transport);
2595 tBTM_STATUS status = BTM_SUCCESS;
2597 BTM_TRACE_DEBUG ("btm_remove_acl");
2598 #if BTM_DISC_DURING_RS == TRUE
2599 tBTM_SEC_DEV_REC *p_dev_rec = btm_find_dev (bd_addr);
2601 /* Role Switch is pending, postpone until completed */
2602 if (p_dev_rec && (p_dev_rec->rs_disc_pending == BTM_SEC_RS_PENDING))
2604 p_dev_rec->rs_disc_pending = BTM_SEC_DISC_PENDING;
2606 else /* otherwise can disconnect right away */
2609 if (hci_handle != 0xFFFF && p_dev_rec &&
2610 p_dev_rec->sec_state!= BTM_SEC_STATE_DISCONNECTING)
2612 if (!btsnd_hcic_disconnect (hci_handle, HCI_ERR_PEER_USER))
2613 status = BTM_NO_RESOURCES;
2616 status = BTM_UNKNOWN_ADDR;
2623 /*******************************************************************************
2625 ** Function BTM_SetTraceLevel
2627 ** Description This function sets the trace level for BTM. If called with
2628 ** a value of 0xFF, it simply returns the current trace level.
2630 ** Returns The new or current trace level
2632 *******************************************************************************/
2633 UINT8 BTM_SetTraceLevel (UINT8 new_level)
2635 BTM_TRACE_DEBUG ("BTM_SetTraceLevel");
2636 if (new_level != 0xFF)
2637 btm_cb.trace_level = new_level;
2639 return(btm_cb.trace_level);
2642 /*******************************************************************************
2644 ** Function btm_cont_rswitch
2646 ** Description This function is called to continue processing an active
2647 ** role switch. It first disables encryption if enabled and
2648 ** EPR is not supported
2652 *******************************************************************************/
2653 void btm_cont_rswitch (tACL_CONN *p, tBTM_SEC_DEV_REC *p_dev_rec,
2656 BOOLEAN sw_ok = TRUE;
2657 BTM_TRACE_DEBUG ("btm_cont_rswitch");
2658 /* Check to see if encryption needs to be turned off if pending
2659 change of link key or role switch */
2660 if (p->switch_role_state == BTM_ACL_SWKEY_STATE_MODE_CHANGE)
2662 /* Must turn off Encryption first if necessary */
2663 /* Some devices do not support switch or change of link key while encryption is on */
2664 if (p_dev_rec != NULL && ((p_dev_rec->sec_flags & BTM_SEC_ENCRYPTED) != 0)
2665 && !BTM_EPR_AVAILABLE(p))
2667 if (btsnd_hcic_set_conn_encrypt (p->hci_handle, FALSE))
2669 p->encrypt_state = BTM_ACL_ENCRYPT_STATE_ENCRYPT_OFF;
2670 if (p->switch_role_state == BTM_ACL_SWKEY_STATE_MODE_CHANGE)
2671 p->switch_role_state = BTM_ACL_SWKEY_STATE_ENCRYPTION_OFF;
2675 /* Error occurred; set states back to Idle */
2676 if (p->switch_role_state == BTM_ACL_SWKEY_STATE_MODE_CHANGE)
2680 else /* Encryption not used or EPR supported, continue with switch
2681 and/or change of link key */
2683 if (p->switch_role_state == BTM_ACL_SWKEY_STATE_MODE_CHANGE)
2685 p->switch_role_state = BTM_ACL_SWKEY_STATE_IN_PROGRESS;
2686 #if BTM_DISC_DURING_RS == TRUE
2688 p_dev_rec->rs_disc_pending = BTM_SEC_RS_PENDING;
2690 sw_ok = btsnd_hcic_switch_role (p->remote_addr, (UINT8)!p->link_role);
2696 p->switch_role_state = BTM_ACL_SWKEY_STATE_IDLE;
2697 btm_acl_report_role_change(hci_status, p->remote_addr);
2702 /*******************************************************************************
2704 ** Function btm_acl_resubmit_page
2706 ** Description send pending page request
2708 *******************************************************************************/
2709 void btm_acl_resubmit_page (void)
2711 tBTM_SEC_DEV_REC *p_dev_rec;
2715 BTM_TRACE_DEBUG ("btm_acl_resubmit_page");
2716 /* If there were other page request schedule can start the next one */
2717 if ((p_buf = (BT_HDR *)GKI_dequeue (&btm_cb.page_queue)) != NULL)
2719 /* skip 3 (2 bytes opcode and 1 byte len) to get to the bd_addr
2720 * for both create_conn and rmt_name */
2721 pp = (UINT8 *)(p_buf + 1) + p_buf->offset + 3;
2723 STREAM_TO_BDADDR (bda, pp);
2725 p_dev_rec = btm_find_or_alloc_dev (bda);
2727 memcpy (btm_cb.connecting_bda, p_dev_rec->bd_addr, BD_ADDR_LEN);
2728 memcpy (btm_cb.connecting_dc, p_dev_rec->dev_class, DEV_CLASS_LEN);
2730 btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p_buf);
2733 btm_cb.paging = FALSE;
2736 /*******************************************************************************
2738 ** Function btm_acl_reset_paging
2740 ** Description set paging to FALSE and free the page queue - called at hci_reset
2742 *******************************************************************************/
2743 void btm_acl_reset_paging (void)
2746 BTM_TRACE_DEBUG ("btm_acl_reset_paging");
2747 /* If we sent reset we are definitely not paging any more */
2748 while ((p = (BT_HDR *)GKI_dequeue(&btm_cb.page_queue)) != NULL)
2751 btm_cb.paging = FALSE;
2754 /*******************************************************************************
2756 ** Function btm_acl_set_discing
2758 ** Description set discing to the given value
2760 *******************************************************************************/
2761 void btm_acl_set_discing (BOOLEAN discing)
2763 BTM_TRACE_DEBUG ("btm_acl_set_discing");
2764 btm_cb.discing = discing;
2767 /*******************************************************************************
2769 ** Function btm_acl_paging
2771 ** Description send a paging command or queue it in btm_cb
2773 *******************************************************************************/
2774 void btm_acl_paging (BT_HDR *p, BD_ADDR bda)
2776 tBTM_SEC_DEV_REC *p_dev_rec;
2778 BTM_TRACE_DEBUG ("btm_acl_paging discing:%d, paging:%d BDA: %06x%06x",
2779 btm_cb.discing, btm_cb.paging,
2780 (bda[0]<<16) + (bda[1]<<8) + bda[2], (bda[3]<<16) + (bda[4] << 8) + bda[5]);
2783 btm_cb.paging = TRUE;
2784 GKI_enqueue (&btm_cb.page_queue, p);
2788 if (!BTM_ACL_IS_CONNECTED (bda))
2790 BTM_TRACE_DEBUG ("connecting_bda: %06x%06x",
2791 (btm_cb.connecting_bda[0]<<16) + (btm_cb.connecting_bda[1]<<8) +
2792 btm_cb.connecting_bda[2],
2793 (btm_cb.connecting_bda[3]<<16) + (btm_cb.connecting_bda[4] << 8) +
2794 btm_cb.connecting_bda[5]);
2795 if (btm_cb.paging &&
2796 memcmp (bda, btm_cb.connecting_bda, BD_ADDR_LEN) != 0)
2798 GKI_enqueue (&btm_cb.page_queue, p);
2802 p_dev_rec = btm_find_or_alloc_dev (bda);
2803 memcpy (btm_cb.connecting_bda, p_dev_rec->bd_addr, BD_ADDR_LEN);
2804 memcpy (btm_cb.connecting_dc, p_dev_rec->dev_class, DEV_CLASS_LEN);
2806 btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p);
2809 btm_cb.paging = TRUE;
2811 else /* ACL is already up */
2813 btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p);
2818 /*******************************************************************************
2820 ** Function btm_acl_notif_conn_collision
2822 ** Description Send connection collision event to upper layer if registered
2824 ** Returns TRUE if sent out to upper layer,
2825 ** FALSE if no one needs the notification.
2827 *******************************************************************************/
2828 BOOLEAN btm_acl_notif_conn_collision (BD_ADDR bda)
2830 tBTM_BL_EVENT_DATA evt_data;
2832 /* Report possible collision to the upper layer. */
2833 if (btm_cb.p_bl_changed_cb)
2835 BTM_TRACE_DEBUG ("btm_acl_notif_conn_collision: RemBdAddr: %02x%02x%02x%02x%02x%02x",
2836 bda[0], bda[1], bda[2], bda[3], bda[4], bda[5]);
2838 evt_data.event = BTM_BL_COLLISION_EVT;
2839 evt_data.conn.p_bda = bda;
2841 #if BLE_INCLUDED == TRUE
2842 evt_data.conn.transport = BT_TRANSPORT_BR_EDR;
2843 evt_data.conn.handle = BTM_INVALID_HCI_HANDLE;
2845 (*btm_cb.p_bl_changed_cb)(&evt_data);
2853 /*******************************************************************************
2855 ** Function btm_acl_chk_peer_pkt_type_support
2857 ** Description Check if peer supports requested packets
2859 *******************************************************************************/
2860 void btm_acl_chk_peer_pkt_type_support (tACL_CONN *p, UINT16 *p_pkt_type)
2862 /* 3 and 5 slot packets? */
2863 if (!HCI_3_SLOT_PACKETS_SUPPORTED(p->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0]))
2864 *p_pkt_type &= ~(BTM_ACL_PKT_TYPES_MASK_DH3 +BTM_ACL_PKT_TYPES_MASK_DM3);
2866 if (!HCI_5_SLOT_PACKETS_SUPPORTED(p->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0]))
2867 *p_pkt_type &= ~(BTM_ACL_PKT_TYPES_MASK_DH5 + BTM_ACL_PKT_TYPES_MASK_DM5);
2869 /* 2 and 3 MPS support? */
2870 if (!HCI_EDR_ACL_2MPS_SUPPORTED(p->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0]))
2871 /* Not supported. Add 'not_supported' mask for all 2MPS packet types */
2872 *p_pkt_type |= (BTM_ACL_PKT_TYPES_MASK_NO_2_DH1 + BTM_ACL_PKT_TYPES_MASK_NO_2_DH3 +
2873 BTM_ACL_PKT_TYPES_MASK_NO_2_DH5);
2875 if (!HCI_EDR_ACL_3MPS_SUPPORTED(p->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0]))
2876 /* Not supported. Add 'not_supported' mask for all 3MPS packet types */
2877 *p_pkt_type |= (BTM_ACL_PKT_TYPES_MASK_NO_3_DH1 + BTM_ACL_PKT_TYPES_MASK_NO_3_DH3 +
2878 BTM_ACL_PKT_TYPES_MASK_NO_3_DH5);
2880 /* EDR 3 and 5 slot support? */
2881 if (HCI_EDR_ACL_2MPS_SUPPORTED(p->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0])
2882 || HCI_EDR_ACL_3MPS_SUPPORTED(p->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0]))
2884 if (!HCI_3_SLOT_EDR_ACL_SUPPORTED(p->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0]))
2885 /* Not supported. Add 'not_supported' mask for all 3-slot EDR packet types */
2886 *p_pkt_type |= (BTM_ACL_PKT_TYPES_MASK_NO_2_DH3 + BTM_ACL_PKT_TYPES_MASK_NO_3_DH3);
2888 if (!HCI_5_SLOT_EDR_ACL_SUPPORTED(p->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0]))
2889 /* Not supported. Add 'not_supported' mask for all 5-slot EDR packet types */
2890 *p_pkt_type |= (BTM_ACL_PKT_TYPES_MASK_NO_2_DH5 + BTM_ACL_PKT_TYPES_MASK_NO_3_DH5);