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

Commit 8e4cf089 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge changes Icba988d3,Ia8874c80,I36da3481,Ica4914f5

* changes:
  Add test SetSupervisorTimeoutOnConnectionSuccess
  Fully encapsulate tBTM_SEC_DEV_REC::is_originator
  Use tBTM_SEC_DEV_REC::IsLocallyInitiated
  Add API tBTM_SEC_DEV_REC::IsLocallyInitiated
parents 932366b5 92df2036
Loading
Loading
Loading
Loading
+8 −8
Original line number Diff line number Diff line
@@ -3699,7 +3699,7 @@ void btm_sec_disconnected(uint16_t handle, tHCI_STATUS reason) {

    // This is for chips that don't support being in connected and advertising
    // state at same time.
    if (!p_dev_rec->is_originator) {
    if (!p_dev_rec->IsLocallyInitiated()) {
      btm_ble_advertiser_notify_terminated_legacy(HCI_SUCCESS, handle);
    }
  } else {
@@ -4091,7 +4091,7 @@ void btm_sec_pin_code_request(uint8_t* p_event) {
           /*  the only thing we can do here is to shut it up.  Normally we will
              be originator */
           /*  for keyboard bonding */
           || (!p_dev_rec->is_originator &&
           || (!p_dev_rec->IsLocallyInitiated() &&
               ((p_dev_rec->dev_class[1] & BTM_COD_MAJOR_CLASS_MASK) ==
                BTM_COD_MAJOR_PERIPHERAL) &&
               (p_dev_rec->dev_class[2] & BTM_COD_MINOR_KEYBOARD))) {
@@ -4207,12 +4207,12 @@ tBTM_STATUS btm_sec_execute_procedure(tBTM_SEC_DEV_REC* p_dev_rec) {
  /* If connection is not authenticated and authentication is required */
  /* start authentication and return PENDING to the caller */
  if ((((!(p_dev_rec->sec_flags & BTM_SEC_AUTHENTICATED)) &&
        ((p_dev_rec->is_originator &&
        ((p_dev_rec->IsLocallyInitiated() &&
          (p_dev_rec->security_required & BTM_SEC_OUT_AUTHENTICATE)) ||
         (!p_dev_rec->is_originator &&
         (!p_dev_rec->IsLocallyInitiated() &&
          (p_dev_rec->security_required & BTM_SEC_IN_AUTHENTICATE)))) ||
       (!(p_dev_rec->sec_flags & BTM_SEC_16_DIGIT_PIN_AUTHED) &&
        (!p_dev_rec->is_originator &&
        (!p_dev_rec->IsLocallyInitiated() &&
         (p_dev_rec->security_required & BTM_SEC_IN_MIN_16_DIGIT_PIN)))) &&
      (p_dev_rec->hci_handle != HCI_INVALID_HANDLE)) {
    /*
@@ -4237,7 +4237,7 @@ tBTM_STATUS btm_sec_execute_procedure(tBTM_SEC_DEV_REC* p_dev_rec) {
     */
    if ((p_dev_rec->sec_flags & BTM_SEC_LINK_KEY_KNOWN) &&
        (!(p_dev_rec->sec_flags & BTM_SEC_16_DIGIT_PIN_AUTHED) &&
         (!p_dev_rec->is_originator &&
         (!p_dev_rec->IsLocallyInitiated() &&
          (p_dev_rec->security_required & BTM_SEC_IN_MIN_16_DIGIT_PIN)))) {
      p_dev_rec->sec_flags &=
          ~(BTM_SEC_LINK_KEY_KNOWN | BTM_SEC_LINK_KEY_AUTHED |
@@ -4251,9 +4251,9 @@ tBTM_STATUS btm_sec_execute_procedure(tBTM_SEC_DEV_REC* p_dev_rec) {
  /* If connection is not encrypted and encryption is required */
  /* start encryption and return PENDING to the caller */
  if (!(p_dev_rec->sec_flags & BTM_SEC_ENCRYPTED) &&
      ((p_dev_rec->is_originator &&
      ((p_dev_rec->IsLocallyInitiated() &&
        (p_dev_rec->security_required & BTM_SEC_OUT_ENCRYPT)) ||
       (!p_dev_rec->is_originator &&
       (!p_dev_rec->IsLocallyInitiated() &&
        (p_dev_rec->security_required & BTM_SEC_IN_ENCRYPT))) &&
      (p_dev_rec->hci_handle != HCI_INVALID_HANDLE)) {
    BTM_TRACE_EVENT("Security Manager: Start encryption");
+18 −0
Original line number Diff line number Diff line
@@ -309,7 +309,25 @@ struct tBTM_SEC_DEV_REC {
    return sec_state == BTM_SEC_STATE_DISCONNECTING_BOTH;
  }

 private:
  bool is_originator;         /* true if device is originating connection */
  friend tBTM_STATUS BTM_SetEncryption(const RawAddress& bd_addr,
                                       tBT_TRANSPORT transport,
                                       tBTM_SEC_CALLBACK* p_callback,
                                       void* p_ref_data,
                                       tBTM_BLE_SEC_ACT sec_act);
  friend tBTM_STATUS btm_sec_l2cap_access_req_by_requirement(
      const RawAddress& bd_addr, uint16_t security_required, bool is_originator,
      tBTM_SEC_CALLBACK* p_callback, void* p_ref_data);
  friend tBTM_STATUS btm_sec_mx_access_request(const RawAddress& bd_addr,
                                               bool is_originator,
                                               uint16_t security_required,
                                               tBTM_SEC_CALLBACK* p_callback,
                                               void* p_ref_data);

 public:
  bool IsLocallyInitiated() const { return is_originator; }

  bool role_central;          /* true if current mode is central     */
  uint16_t security_required; /* Security required for connection   */
  bool link_key_not_sent; /* link key notification has not been sent waiting for
+24 −0
Original line number Diff line number Diff line
@@ -129,4 +129,28 @@ TEST_F(StackBtmTest, NoInformClientOnConnectionFail) {
  get_btm_client_interface().lifecycle.btm_free();
}

TEST_F(StackBtmTest, SetSupervisiorTimeoutOnConnectionSuccess) {
  MOCK_bluetooth_shim_is_gd_acl_enabled_ = true;

  get_btm_client_interface().lifecycle.btm_init();

  RawAddress bda({0x11, 0x22, 0x33, 0x44, 0x55, 0x66});

  get_btm_client_interface().link_controller.BTM_SetDefaultLinkSuperTout(
      0x1234);

  btm_acl_connected(bda, 2, HCI_SUCCESS, false);
  btm_acl_role_changed(HCI_SUCCESS, bda, HCI_ROLE_CENTRAL);

  ASSERT_EQ(static_cast<size_t>(1),
            mock_function_count_map.count("btsnd_hcic_write_link_super_tout"));
  uint16_t timeout;
  ASSERT_EQ(BTM_SUCCESS,
            get_btm_client_interface().link_controller.BTM_GetLinkSuperTout(
                bda, &timeout));
  ASSERT_EQ(0x1234, timeout);

  get_btm_client_interface().lifecycle.btm_free();
}

}  // namespace