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

Commit 78fd96c9 authored by Zach Johnson's avatar Zach Johnson Committed by Gerrit Code Review
Browse files

Merge changes I9b116e04,Ib00d354a,I96e58238,Icd4f61ae,Ibd713dd5, ...

* changes:
  Move some acl specific setup from devctl to btm_acl
  Remove last vestiges of link_policy from dm
  Associate role management with ACL, not device management
  Remove BTA_DM_LINK_POLICY_SETTINGS & friends
  Encapsulate all default policy setting inside ACL
  Make sniff mode blocking/unblocking look like role switch
  Remove l2cu_get_conn_role
  L2CA_SetDesireRole literally changes nothing
  L2CAP_DESIRED_LINK_ROLE is always "master"
  Don't use L2CA_SetDesireRole to set policy
parents ebcb0f54 209ed09a
Loading
Loading
Loading
Loading
+9 −14
Original line number Diff line number Diff line
@@ -55,6 +55,7 @@
#endif
#include "btif/include/btif_av.h"
#include "btif/include/btif_hf.h"
#include "stack/include/acl_api.h"

/*****************************************************************************
 *  Constants
@@ -845,12 +846,7 @@ void bta_av_do_disc_a2dp(tBTA_AV_SCB* p_scb, tBTA_AV_DATA* p_data) {
  }

  if (bta_av_cb.features & BTA_AV_FEAT_MASTER) {
    L2CA_SetDesireRole(L2CAP_ROLE_DISALLOW_SWITCH);

    if (bta_av_cb.audio_open_cnt == 1) {
      /* there's already an A2DP connection. do not allow switch */
      BTA_dm_block_role_switch();
    }
    BTM_default_block_role_switch();
  }
  /* store peer addr other parameters */
  bta_av_save_addr(p_scb, p_data->api_open.bd_addr);
@@ -1871,7 +1867,7 @@ void bta_av_do_start(tBTA_AV_SCB* p_scb, tBTA_AV_DATA* p_data) {
   * It would not hurt us, if the peer device wants us to be master */
  if ((BTM_GetRole(p_scb->PeerAddress(), &cur_role) == BTM_SUCCESS) &&
      (cur_role == HCI_ROLE_MASTER)) {
    BTA_dm_block_role_switch_for(p_scb->PeerAddress());
    BTM_block_role_switch_for(p_scb->PeerAddress());
  }

  if (p_scb->started) {
@@ -1942,7 +1938,7 @@ void bta_av_str_stopped(tBTA_AV_SCB* p_scb, tBTA_AV_DATA* p_data) {
  bta_sys_idle(BTA_ID_AV, bta_av_cb.audio_open_cnt, p_scb->PeerAddress());
  if ((bta_av_cb.features & BTA_AV_FEAT_MASTER) == 0 ||
      bta_av_cb.audio_open_cnt == 1) {
    BTA_dm_unblock_role_switch_for(p_scb->PeerAddress());
    BTM_unblock_role_switch_for(p_scb->PeerAddress());
  }

  if (p_scb->co_started) {
@@ -2376,7 +2372,7 @@ void bta_av_start_ok(tBTA_AV_SCB* p_scb, tBTA_AV_DATA* p_data) {
       * master */
      if ((BTM_GetRole(p_scb->PeerAddress(), &cur_role) == BTM_SUCCESS) &&
          (cur_role == HCI_ROLE_MASTER)) {
        BTA_dm_block_role_switch_for(p_scb->PeerAddress());
        BTM_block_role_switch_for(p_scb->PeerAddress());
      }
    }

@@ -2439,7 +2435,7 @@ void bta_av_start_failed(tBTA_AV_SCB* p_scb, UNUSED_ATTR tBTA_AV_DATA* p_data) {
    notify_start_failed(p_scb);
  }

  BTA_dm_unblock_role_switch_for(p_scb->PeerAddress());
  BTM_unblock_role_switch_for(p_scb->PeerAddress());
  p_scb->sco_suspend = false;
}

@@ -2463,11 +2459,10 @@ void bta_av_str_closed(tBTA_AV_SCB* p_scb, tBTA_AV_DATA* p_data) {

  if ((bta_av_cb.features & BTA_AV_FEAT_MASTER) == 0 ||
      bta_av_cb.audio_open_cnt == 1) {
    BTA_dm_unblock_role_switch_for(p_scb->PeerAddress());
    BTM_unblock_role_switch_for(p_scb->PeerAddress());
  }
  if (bta_av_cb.audio_open_cnt <= 1) {
    /* last connection - restore the allow switch flag */
    L2CA_SetDesireRole(L2CAP_ROLE_ALLOW_SWITCH);
    BTM_default_unblock_role_switch();
  }

  if (p_scb->open_status != BTA_AV_SUCCESS) {
@@ -2575,7 +2570,7 @@ void bta_av_suspend_cfm(tBTA_AV_SCB* p_scb, tBTA_AV_DATA* p_data) {
  bta_sys_idle(BTA_ID_AV, bta_av_cb.audio_open_cnt, p_scb->PeerAddress());
  if ((bta_av_cb.features & BTA_AV_FEAT_MASTER) == 0 ||
      bta_av_cb.audio_open_cnt == 1) {
    BTA_dm_unblock_role_switch_for(p_scb->PeerAddress());
    BTM_unblock_role_switch_for(p_scb->PeerAddress());
  }

  /* in case that we received suspend_ind, we may need to call co_stop here */
+2 −1
Original line number Diff line number Diff line
@@ -40,6 +40,7 @@
#include "osi/include/log.h"
#include "osi/include/osi.h"
#include "osi/include/properties.h"
#include "stack/include/acl_api.h"
#include "utl.h"

#if (BTA_AR_INCLUDED == TRUE)
@@ -1270,7 +1271,7 @@ void bta_av_conn_chg(tBTA_AV_DATA* p_data) {
    if (p_cb->audio_open_cnt == 1) {
      /* one audio channel goes down and there's one audio channel remains open.
       * restore the switch role in default link policy */
      BTA_dm_unblock_role_switch();
      BTM_default_unblock_role_switch();
      bta_av_restore_switch();
    }
    if (p_cb->audio_open_cnt) {
+4 −4
Original line number Diff line number Diff line
@@ -921,7 +921,7 @@ void bta_av_restore_switch(void) {
    mask = BTA_AV_HNDL_TO_MSK(i);
    if (p_cb->conn_audio == mask) {
      if (p_cb->p_scb[i]) {
        BTA_dm_unblock_role_switch_for(p_cb->p_scb[i]->PeerAddress());
        BTM_unblock_role_switch_for(p_cb->p_scb[i]->PeerAddress());
      }
      break;
    }
@@ -974,7 +974,7 @@ static void bta_av_sys_rs_cback(UNUSED_ATTR tBTA_SYS_CONN_STATUS status,
  if ((HCI_SUCCESS != app_id) &&
      (BTM_GetRole(peer_addr, &cur_role) == BTM_SUCCESS) &&
      (cur_role == HCI_ROLE_SLAVE)) {
    BTA_dm_unblock_role_switch_for(peer_addr);
    BTM_unblock_role_switch_for(peer_addr);
  }

  /* if BTA_AvOpen() was called for other device, which caused the role switch
@@ -1100,7 +1100,7 @@ bool bta_av_switch_if_needed(tBTA_AV_SCB* p_scb) {
       */
      if (HCI_ROLE_MASTER != role) {
        if (bta_av_cb.features & BTA_AV_FEAT_MASTER)
          BTA_dm_block_role_switch_for(p_scbi->PeerAddress());
          BTM_block_role_switch_for(p_scbi->PeerAddress());
        if (BTM_CMD_STARTED !=
            BTM_SwitchRole(p_scbi->PeerAddress(), HCI_ROLE_MASTER)) {
          /* can not switch role on SCBI
@@ -1144,7 +1144,7 @@ bool bta_av_link_role_ok(tBTA_AV_SCB* p_scb, uint8_t bits) {
        (A2DP_BitsSet(bta_av_cb.conn_audio) > bits ||
         (bta_av_cb.features & BTA_AV_FEAT_MASTER))) {
      if (bta_av_cb.features & BTA_AV_FEAT_MASTER)
        BTA_dm_block_role_switch_for(p_scb->PeerAddress());
        BTM_block_role_switch_for(p_scb->PeerAddress());

      tBTM_STATUS status =
          BTM_SwitchRole(p_scb->PeerAddress(), HCI_ROLE_MASTER);
+2 −53
Original line number Diff line number Diff line
@@ -806,34 +806,6 @@ void bta_dm_pin_reply(std::unique_ptr<tBTA_DM_API_PIN_REPLY> msg) {
  }
}

void BTA_dm_unblock_role_switch_for(const RawAddress& peer_addr) {
  auto p_dev = bta_dm_find_peer_device(peer_addr);
  if (!p_dev) {
    return;
  }
  p_dev->link_policy |= HCI_ENABLE_MASTER_SLAVE_SWITCH;
  BTM_SetLinkPolicy(p_dev->peer_bdaddr, &(p_dev->link_policy));
}

void BTA_dm_block_role_switch_for(const RawAddress& peer_addr) {
  auto p_dev = bta_dm_find_peer_device(peer_addr);
  if (!p_dev) {
    return;
  }
  p_dev->link_policy &= (~HCI_ENABLE_MASTER_SLAVE_SWITCH);
  BTM_SetLinkPolicy(p_dev->peer_bdaddr, &(p_dev->link_policy));
}

void BTA_dm_unblock_role_switch() {
  BTM_SetDefaultLinkPolicy(btm_cb.acl_cb_.btm_def_link_policy |
                           HCI_ENABLE_MASTER_SLAVE_SWITCH);
}

void BTA_dm_block_role_switch() {
  BTM_SetDefaultLinkPolicy(btm_cb.acl_cb_.btm_def_link_policy &
                           ~HCI_ENABLE_MASTER_SLAVE_SWITCH);
}

/** Send the user confirm request reply in response to a request from BTM */
void bta_dm_confirm(const RawAddress& bd_addr, bool accept) {
  BTM_ConfirmReqReply(accept ? BTM_SUCCESS : BTM_NOT_AUTHORIZED, bd_addr);
@@ -2525,7 +2497,7 @@ static void handle_role_change(const RawAddress& bd_addr, uint8_t new_role,
    }

    if (need_policy_change) {
      BTA_dm_block_role_switch_for(p_dev->peer_bdaddr);
      BTM_block_role_switch_for(p_dev->peer_bdaddr);
    }
  } else {
    /* there's AV no activity on this link and role switch happened
@@ -2556,7 +2528,6 @@ static tBTA_DM_PEER_DEVICE* allocate_device_for(const RawAddress& bd_addr,
    auto device =
        &bta_dm_cb.device_list.peer_device[bta_dm_cb.device_list.count];
    device->peer_bdaddr = bd_addr;
    device->link_policy = btm_cb.acl_cb_.btm_def_link_policy;
    bta_dm_cb.device_list.count++;
    device->conn_handle = handle;
    if (transport == BT_TRANSPORT_LE) {
@@ -2716,7 +2687,7 @@ static void bta_dm_check_av() {
        /* make master and take away the role switch policy */
        BTM_SwitchRole(p_dev->peer_bdaddr, HCI_ROLE_MASTER);
        /* else either already master or can not switch for some reasons */
        BTA_dm_block_role_switch_for(p_dev->peer_bdaddr);
        BTM_block_role_switch_for(p_dev->peer_bdaddr);
        break;
      }
    }
@@ -2886,28 +2857,13 @@ static void bta_dm_remove_sec_dev_entry(const RawAddress& remote_bd_addr) {
 ******************************************************************************/
static void bta_dm_adjust_roles(bool delay_role_switch) {
  uint8_t i;
  bool set_master_role = false;
  uint8_t br_count =
      bta_dm_cb.device_list.count - bta_dm_cb.device_list.le_count;
  if (br_count) {
    /* the configuration is no scatternet
     * or AV connection exists and there are more than one ACL link */
    if ((p_bta_dm_rm_cfg[0].cfg == BTA_DM_NO_SCATTERNET) ||
        (bta_dm_cb.cur_av_count && br_count > 1)) {
      L2CA_SetDesireRole(HCI_ROLE_MASTER);
      set_master_role = true;
    }

    for (i = 0; i < bta_dm_cb.device_list.count; i++) {
      if (bta_dm_cb.device_list.peer_device[i].conn_state == BTA_DM_CONNECTED &&
          bta_dm_cb.device_list.peer_device[i].transport ==
              BT_TRANSPORT_BR_EDR) {
        if (!set_master_role &&
            (bta_dm_cb.device_list.peer_device[i].pref_role != BTA_ANY_ROLE) &&
            (p_bta_dm_rm_cfg[0].cfg == BTA_DM_PARTIAL_SCATTERNET)) {
          L2CA_SetDesireRole(HCI_ROLE_MASTER);
          set_master_role = true;
        }

        if ((bta_dm_cb.device_list.peer_device[i].pref_role ==
             BTA_MASTER_ROLE_ONLY) ||
@@ -2934,13 +2890,6 @@ static void bta_dm_adjust_roles(bool delay_role_switch) {
        }
      }
    }

    if (!set_master_role) {
      L2CA_SetDesireRole(L2CAP_DESIRED_LINK_ROLE);
    }

  } else {
    L2CA_SetDesireRole(L2CAP_DESIRED_LINK_ROLE);
  }
}

+0 −8
Original line number Diff line number Diff line
@@ -32,12 +32,6 @@
#include "bta_jv_api.h"
#include "bta_sys.h"

#ifndef BTA_DM_LINK_POLICY_SETTINGS
#define BTA_DM_LINK_POLICY_SETTINGS                        \
  (HCI_ENABLE_MASTER_SLAVE_SWITCH | HCI_ENABLE_HOLD_MODE | \
   HCI_ENABLE_SNIFF_MODE | HCI_ENABLE_PARK_MODE)
#endif

/* page timeout in 625uS */
#ifndef BTA_DM_PAGE_TIMEOUT
#define BTA_DM_PAGE_TIMEOUT 8192
@@ -64,8 +58,6 @@
const tBTA_DM_CFG bta_dm_cfg = {
    /* mobile phone COD */
    BTA_DM_COD,
    /* link policy settings */
    BTA_DM_LINK_POLICY_SETTINGS,
    /* page timeout in 625uS */
    BTA_DM_PAGE_TIMEOUT,
    /* link supervision timeout in 625uS*/
Loading