Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c227d4a0 authored by Josh Wu's avatar Josh Wu
Browse files

BTM: Add btm_sec_role_changed()

* Extend role_changed callback to btm_sec to handle role-related flow
* Set encryption after role changed

Tag: #refactor
Test: gd/cert/run
Bug: 198755234
Change-Id: Iedbacb645fb9648392806e695a60b02624d46b89
parent 7e21d4cb
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -1450,6 +1450,7 @@ void StackAclBtmAcl::btm_acl_role_changed(tHCI_STATUS hci_status,
  }

  BTA_dm_report_role_change(bd_addr, new_role, hci_status);
  btm_sec_role_changed(hci_status, bd_addr, new_role);

  /* If a disconnect is pending, issue it now that role switch has completed */
  if (p_acl->rs_disc_pending == BTM_SEC_DISC_PENDING) {
+14 −0
Original line number Diff line number Diff line
@@ -3807,6 +3807,20 @@ void btm_sec_disconnected(uint16_t handle, tHCI_REASON reason,
  }
}

void btm_sec_role_changed(tHCI_STATUS hci_status, const RawAddress& bd_addr,
                          tHCI_ROLE new_role) {
  tBTM_SEC_DEV_REC* p_dev_rec = btm_find_dev(bd_addr);

  if (p_dev_rec == nullptr || hci_status != HCI_SUCCESS) {
    return;
  }
  if (new_role == HCI_ROLE_CENTRAL && btm_dev_authenticated(p_dev_rec) &&
      !btm_dev_encrypted(p_dev_rec)) {
    BTM_SetEncryption(p_dev_rec->bd_addr, BT_TRANSPORT_BR_EDR, NULL, NULL,
                      BTM_BLE_SEC_NONE);
  }
}

/** This function is called when a new connection link key is generated */
void btm_sec_link_key_notification(const RawAddress& p_bda,
                                   const Octet16& link_key, uint8_t key_type) {
+13 −0
Original line number Diff line number Diff line
@@ -647,6 +647,19 @@ tBTM_STATUS btm_sec_disconnect(uint16_t handle, tHCI_STATUS reason,
void btm_sec_disconnected(uint16_t handle, tHCI_STATUS reason,
                          std::string comment);

/*******************************************************************************
 *
 * Function         btm_sec_role_changed
 *
 * Description      This function is called when receiving an HCI role change
 *                  event
 *
 * Returns          void
 *
 ******************************************************************************/
void btm_sec_role_changed(tHCI_STATUS hci_status, const RawAddress& bd_addr,
                          tHCI_ROLE new_role);

/** This function is called when a new connection link key is generated */
void btm_sec_link_key_notification(const RawAddress& p_bda,
                                   const Octet16& link_key, uint8_t key_type);