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

Commit 51762924 authored by Zach Johnson's avatar Zach Johnson
Browse files

Don't use L2CA_SetDesireRole to set policy

duplicates state already in bta_dm

there can only be one

Bug: 159815595
Tag: #refactor
Test: compile & verify basic functions working
Change-Id: Ic3d7789f83eb892a85968df0266de94a128cfe3d
parent a56e06ec
Loading
Loading
Loading
Loading
+2 −3
Original line number Diff line number Diff line
@@ -845,7 +845,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);
    BTA_dm_block_role_switch();

    if (bta_av_cb.audio_open_cnt == 1) {
      /* there's already an A2DP connection. do not allow switch */
@@ -2466,8 +2466,7 @@ void bta_av_str_closed(tBTA_AV_SCB* p_scb, tBTA_AV_DATA* p_data) {
    BTA_dm_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);
    BTA_dm_unblock_role_switch();
  }

  if (p_scb->open_status != BTA_AV_SUCCESS) {
+0 −15
Original line number Diff line number Diff line
@@ -924,10 +924,6 @@ void bta_jv_l2cap_connect(int32_t type, tBTA_SEC sec_mask, tBTA_JV_ROLE role,
  cfg.mtu_present = true;
  cfg.mtu = rx_mtu;

  /* TODO: DM role manager
  L2CA_SetDesireRole(role);
  */

  uint8_t sec_id = bta_jv_alloc_sec_id();
  tBTA_JV_L2CAP_CL_INIT evt_data;
  evt_data.sec_id = sec_id;
@@ -1081,10 +1077,6 @@ void bta_jv_l2cap_start_server(int32_t type, tBTA_SEC sec_mask,
    cfg.mtu = 0;
  }

  /* TODO DM role manager
  L2CA_SetDesireRole(role);
  */

  uint8_t sec_id = bta_jv_alloc_sec_id();
  uint16_t max_mps = 0xffff;  // Let GAP_ConnOpen set the max_mps.
  /* PSM checking is not required for LE COC */
@@ -1331,10 +1323,6 @@ void bta_jv_rfcomm_connect(tBTA_SEC sec_mask, tBTA_JV_ROLE role,
  uint32_t event_mask = BTA_JV_RFC_EV_MASK;
  tPORT_STATE port_state;

  /* TODO DM role manager
  L2CA_SetDesireRole(role);
  */

  uint8_t sec_id = bta_jv_alloc_sec_id();

  tBTA_JV_RFCOMM_CL_INIT evt_data;
@@ -1645,9 +1633,6 @@ void bta_jv_rfcomm_start_server(tBTA_SEC sec_mask, tBTA_JV_ROLE role,
  tBTA_JV_PCB* p_pcb;
  tBTA_JV_RFCOMM_START evt_data;

  /* TODO DM role manager
  L2CA_SetDesireRole(role);
  */
  memset(&evt_data, 0, sizeof(evt_data));
  evt_data.status = BTA_JV_FAILURE;
  VLOG(2) << __func__ << ": sec id in use=" << get_sec_id_used()
+0 −10
Original line number Diff line number Diff line
@@ -81,12 +81,6 @@ typedef uint8_t tL2CAP_CHNL_DATA_RATE;
#define L2CAP_FLUSH_CHANS_ALL 0xffff
#define L2CAP_FLUSH_CHANS_GET 0x0000

/* set this bit to allow switch at create conn */
#define L2CAP_ROLE_ALLOW_SWITCH 0x80
/* set this bit to disallow switch at create conn */
#define L2CAP_ROLE_DISALLOW_SWITCH 0x40
#define L2CAP_ROLE_CHECK_SWITCH 0xC0

/* Values for 'allowed_modes' field passed in structure tL2CAP_ERTM_INFO
 */
#define L2CAP_FCR_CHAN_OPT_BASIC (1 << L2CAP_FCR_BASIC_MODE)
@@ -637,10 +631,6 @@ extern uint8_t L2CA_SetTraceLevel(uint8_t trace_level);
 * Function     L2CA_SetDesireRole
 *
 * Description  This function sets the desire role for L2CAP.
 *              If the new role is L2CAP_ROLE_ALLOW_SWITCH, allow switch on
 *              HciCreateConnection.
 *              If the new role is L2CAP_ROLE_DISALLOW_SWITCH, do not allow
 *              switch on HciCreateConnection.
 *
 *              If the new role is a valid role (HCI_ROLE_MASTER or
 *              HCI_ROLE_SLAVE), the desire role is set to the new value.
+2 −18
Original line number Diff line number Diff line
@@ -1129,10 +1129,6 @@ uint8_t L2CA_SetTraceLevel(uint8_t new_level) {
 * Function     L2CA_SetDesireRole
 *
 * Description  This function sets the desire role for L2CAP.
 *              If the new role is L2CAP_ROLE_ALLOW_SWITCH, allow switch on
 *              HciCreateConnection.
 *              If the new role is L2CAP_ROLE_DISALLOW_SWITCH, do not allow
 *              switch on HciCreateConnection.
 *
 *              If the new role is a valid role (HCI_ROLE_MASTER or
 *              HCI_ROLE_SLAVE), the desire role is set to the new value.
@@ -1146,20 +1142,8 @@ uint8_t L2CA_SetDesireRole(uint8_t new_role) {
    return bluetooth::shim::L2CA_SetDesireRole(new_role);
  }

  L2CAP_TRACE_API("L2CA_SetDesireRole() new:x%x, disallow_switch:%d", new_role,
                  l2cb.disallow_switch);
  L2CAP_TRACE_API("L2CA_SetDesireRole() new:x%x", new_role);

  if (L2CAP_ROLE_CHECK_SWITCH != (L2CAP_ROLE_CHECK_SWITCH & new_role)) {
    /* do not process the allow_switch when both bits are set */
    if (new_role & L2CAP_ROLE_ALLOW_SWITCH) {
      l2cb.disallow_switch = false;
    }
    if (new_role & L2CAP_ROLE_DISALLOW_SWITCH) {
      l2cb.disallow_switch = true;
    }
  }

  if (new_role == HCI_ROLE_MASTER || new_role == HCI_ROLE_SLAVE)
  l2cb.desire_role = new_role;

  return (l2cb.desire_role);
+4 −2
Original line number Diff line number Diff line
@@ -2151,13 +2151,15 @@ void l2cu_create_conn_after_switch(tL2C_LCB* p_lcb) {
  uint8_t no_hi_prio_chs = l2cu_get_num_hi_priority();
  const controller_t* controller = controller_get_interface();

  bool disallow_switch = (btm_cb.acl_cb_.btm_def_link_policy &
                          HCI_ENABLE_MASTER_SLAVE_SWITCH) == 0;
  L2CAP_TRACE_DEBUG(
      "l2cu_create_conn_after_switch :%d num_acl:%d no_hi: %d is_bonding:%d",
      l2cb.disallow_switch, num_acl, no_hi_prio_chs, p_lcb->is_bonding);
      disallow_switch, num_acl, no_hi_prio_chs, p_lcb->is_bonding);
  /* FW team says that we can participant in 4 piconets
   * typically 3 piconet + 1 for scanning.
   * We can enhance the code to count the number of piconets later. */
  if (((!l2cb.disallow_switch && (num_acl < 3)) ||
  if (((!disallow_switch && (num_acl < 3)) ||
       (p_lcb->is_bonding && (no_hi_prio_chs == 0))) &&
      controller->supports_role_switch())
    allow_switch = HCI_CR_CONN_ALLOW_SWITCH;