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

Commit e38812c4 authored by Chris Manton's avatar Chris Manton
Browse files

Consolidate exits stack/acl/btm_acl::hci_start_role_switch_to_central

Also add role switch into hci interface

Towards readable code

Bug: 163134718
Tag: #refactor
Test: gd/cert/run --host

Change-Id: Icd473efe6ee8c6e0032dd5f5d4d4ed2880537ba1
parent 66631de9
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -34,6 +34,9 @@
#include "stack/include/hci_error_code.h"
#include "stack/include/hcidefs.h"

void btsnd_hcic_switch_role(const RawAddress& bd_addr,
                            uint8_t role);  // TODO remove

bt_status_t do_in_main_thread(const base::Location& from_here,
                              base::OnceClosure task);

@@ -211,7 +214,8 @@ void bluetooth::shim::btm_pm_on_mode_change(tHCI_STATUS status, uint16_t handle,
      } else {
        p_acl->set_switch_role_in_progress();
        p_acl->rs_disc_pending = BTM_SEC_RS_PENDING;
        btsnd_hcic_switch_role(p_acl->remote_addr, HCI_ROLE_CENTRAL);
        bluetooth::legacy::hci::GetInterface().StartRoleSwitch(
            p_acl->remote_addr, HCI_ROLE_CENTRAL);
      }
    }
  }
+10 −9
Original line number Diff line number Diff line
@@ -180,6 +180,13 @@ static void hci_btsnd_hcic_disconnect(tACL_CONN& p_acl, tHCI_STATUS reason) {
  }
}

static void hci_start_role_switch_to_central(tACL_CONN& p_acl) {
  GetLegacyHciInterface().StartRoleSwitch(
      p_acl.remote_addr, static_cast<uint8_t>(HCI_ROLE_CENTRAL));
  p_acl.set_switch_role_in_progress();
  p_acl.rs_disc_pending = BTM_SEC_RS_PENDING;
}

/* 3 seconds timeout waiting for responses */
#define BTM_DEV_REPLY_TIMEOUT_MS (3 * 1000)

@@ -577,9 +584,7 @@ tBTM_STATUS BTM_SwitchRoleToCentral(const RawAddress& remote_bd_addr) {
      p_acl->set_encryption_off();
      p_acl->set_switch_role_encryption_off();
    } else {
      btsnd_hcic_switch_role(remote_bd_addr, HCI_ROLE_CENTRAL);
      p_acl->set_switch_role_in_progress();
      p_acl->rs_disc_pending = BTM_SEC_RS_PENDING;
      hci_start_role_switch_to_central(*p_acl);
    }
  }

@@ -618,9 +623,7 @@ void btm_acl_encrypt_change(uint16_t handle, uint8_t status,
      p->set_encryption_switching();
      p->set_switch_role_switching();
    }

    btsnd_hcic_switch_role(p->remote_addr, HCI_ROLE_CENTRAL);
    p->rs_disc_pending = BTM_SEC_RS_PENDING;
    hci_start_role_switch_to_central(*p);
  }
  /* Finished enabling Encryption after role switch */
  else if (p->is_switch_role_encryption_on()) {
@@ -2176,9 +2179,7 @@ void btm_cont_rswitch_from_handle(uint16_t hci_handle) {
              and/or change of link key */
    {
      if (p->is_switch_role_mode_change()) {
        p->set_switch_role_in_progress();
        p->rs_disc_pending = BTM_SEC_RS_PENDING;
        btsnd_hcic_switch_role(p->remote_addr, HCI_ROLE_CENTRAL);
        hci_start_role_switch_to_central(*p);
      }
    }
  }
+2 −1
Original line number Diff line number Diff line
@@ -598,7 +598,7 @@ void btsnd_hcic_qos_setup(uint16_t handle, uint8_t flags, uint8_t service_type,
  btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
}

void btsnd_hcic_switch_role(const RawAddress& bd_addr, uint8_t role) {
static void btsnd_hcic_switch_role(const RawAddress& bd_addr, uint8_t role) {
  BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
  uint8_t* pp = (uint8_t*)(p + 1);

@@ -1433,6 +1433,7 @@ void btsnd_hcic_vendor_spec_cmd(void* buffer, uint16_t opcode, uint8_t len,

bluetooth::legacy::hci::Interface interface_ = {
    .Disconnect = btsnd_hcic_disconnect,
    .StartRoleSwitch = btsnd_hcic_switch_role,
};

const bluetooth::legacy::hci::Interface&
+1 −3
Original line number Diff line number Diff line
@@ -86,6 +86,7 @@ namespace legacy {
namespace hci {
struct Interface {
  void (*Disconnect)(uint16_t handle, uint8_t reason);
  void (*StartRoleSwitch)(const RawAddress& bd_addr, uint8_t role);
};
const Interface& GetInterface();
}  // namespace hci
@@ -329,9 +330,6 @@ extern void btsnd_hcic_qos_setup(uint16_t handle, uint8_t flags,
#define HCI_QOS_DELAY_VAR_OFF 16
/* QoS Setup */

/* Switch Role Request */
extern void btsnd_hcic_switch_role(const RawAddress& bd_addr, uint8_t role);

#define HCIC_PARAM_SIZE_SWITCH_ROLE 7

#define HCI_SWITCH_BD_ADDR_OFF 0
+1 −0
Original line number Diff line number Diff line
@@ -296,6 +296,7 @@ void btsnd_hcic_write_voice_settings(uint16_t flags) {

bluetooth::legacy::hci::Interface interface_ = {
    .Disconnect = btsnd_hcic_disconnect,
    .StartRoleSwitch = btsnd_hcic_switch_role,
};

const bluetooth::legacy::hci::Interface&