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

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

Simplify stack/l2cap/l2c_utils::l2cu_create_conn_br_edr

Towards proper interfaces

Bug: 163134718
Tag: #refactor
Test: compile & verify basic functions working
Change-Id: I7eb89883f5289bc89692e26c6f290f42f609009c
parent e2d5fdec
Loading
Loading
Loading
Loading
+34 −41
Original line number Original line Diff line number Diff line
@@ -2039,36 +2039,32 @@ bool l2cu_create_conn_le(tL2C_LCB* p_lcb, uint8_t initiating_phys) {
  return (l2cble_create_conn(p_lcb));
  return (l2cble_create_conn(p_lcb));
}
}


/* This function initiates an acl connection to a Classic device via HCI.
/* This function initiates an acl connection to a Classic device via HCI. */
 * Returns true on success, false otherwise. */
void l2cu_create_conn_br_edr(tL2C_LCB* p_lcb) {
void l2cu_create_conn_br_edr(tL2C_LCB* p_lcb) {
  int xx;
  const bool controller_supports_role_switch =
  tL2C_LCB* p_lcb_cur = &l2cb.lcb_pool[0];
      controller_get_interface()->supports_role_switch();
  bool is_sco_active;
  const controller_t* controller = controller_get_interface();


  /* If there is a connection where we perform as a slave, try to switch roles
  /* While creating a new classic connection, check check all the other
     for this connection */
   * active connections where we are not SCO nor master.
  for (xx = 0, p_lcb_cur = &l2cb.lcb_pool[0]; xx < MAX_L2CAP_LINKS;
   * If our controller supports role switching, try switching
       xx++, p_lcb_cur++) {
   * roles back to MASTER on those connections.
   */
  tL2C_LCB* p_lcb_cur = &l2cb.lcb_pool[0];
  for (uint8_t xx = 0; xx < MAX_L2CAP_LINKS; xx++, p_lcb_cur++) {
    if (p_lcb_cur == p_lcb) continue;
    if (p_lcb_cur == p_lcb) continue;

    if (!p_lcb_cur->in_use) continue;
    if ((p_lcb_cur->in_use) && (p_lcb_cur->IsLinkRoleSlave())) {
    if (BTM_IsScoActiveByBdaddr(p_lcb_cur->remote_bd_addr)) {
      L2CAP_TRACE_DEBUG("%s Master slave switch not allowed when SCO active",
                        __func__);
      continue;
    }
    if (p_lcb->IsLinkRoleMaster()) continue;
    /* The LMP_switch_req shall be sent only if the ACL logical transport
    /* The LMP_switch_req shall be sent only if the ACL logical transport
       is in active mode, when encryption is disabled, and all synchronous
       is in active mode, when encryption is disabled, and all synchronous
       logical transports on the same physical link are disabled." */
       logical transports on the same physical link are disabled." */


      /* Check if there is any SCO Active on this BD Address */
      is_sco_active = BTM_IsScoActiveByBdaddr(p_lcb_cur->remote_bd_addr);

      L2CAP_TRACE_API(
          "l2cu_create_conn - BTM_IsScoActiveByBdaddr() is_sco_active = %s",
          (is_sco_active) ? "true" : "false");

      if (is_sco_active)
        continue; /* No Master Slave switch not allowed when SCO Active */
    /*4_1_TODO check  if btm_cb.devcb.local_features to be used instead */
    /*4_1_TODO check  if btm_cb.devcb.local_features to be used instead */
      if (controller->supports_role_switch()) {
    if (controller_supports_role_switch) {
      /* mark this lcb waiting for switch to be completed and
      /* mark this lcb waiting for switch to be completed and
         start switch on the other one */
         start switch on the other one */
      p_lcb->link_state = LST_CONNECTING_WAIT_SWITCH;
      p_lcb->link_state = LST_CONNECTING_WAIT_SWITCH;
@@ -2083,10 +2079,7 @@ void l2cu_create_conn_br_edr(tL2C_LCB* p_lcb) {
      }
      }
    }
    }
  }
  }
  }

  p_lcb->link_state = LST_CONNECTING;
  p_lcb->link_state = LST_CONNECTING;

  l2cu_create_conn_after_switch(p_lcb);
  l2cu_create_conn_after_switch(p_lcb);
}
}