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

Commit eb5348ef authored by Aritra Sen's avatar Aritra Sen
Browse files

Create new L2CAP Connection result codes for errors to replace...

Create new L2CAP Connection result codes for errors to replace L2CAP_CONN_OTHER_ERROR with specific errors in the GAP
error callback.

Bug: 263522407
Test: mma -j $(nproc)
Change-Id: If6dd7b3a7826d142cac7bf0a1c29f3d697d95372
parent a2c6b485
Loading
Loading
Loading
Loading
+36 −14
Original line number Diff line number Diff line
@@ -102,20 +102,8 @@
#define L2CAP_PKT_CONTINUE 1
#define L2CAP_PKT_TYPE_SHIFT 12

/* Define the L2CAP connection result codes
*/
typedef enum : uint16_t {
  L2CAP_CONN_OK = 0,
  L2CAP_CONN_PENDING = 1,
  L2CAP_CONN_NO_PSM = 2,
  L2CAP_CONN_SECURITY_BLOCK = 3,
  L2CAP_CONN_NO_RESOURCES = 4,
  L2CAP_CONN_OTHER_ERROR = 5,
  L2CAP_CONN_TIMEOUT = 0xEEEE,
  /* Add a couple of our own for internal use */
  L2CAP_CONN_NO_LINK = 255,
  L2CAP_CONN_CANCEL = 256, /* L2CAP connection cancelled */
} tL2CAP_CONN;
#define L2CAP_CONN_INTERNAL_MASK 0xF000
#define L2CAP_CONN_LE_MASK 0xFF00

/* Define the LE L2CAP Connection Response Result codes
 */
@@ -134,6 +122,40 @@ typedef enum : uint8_t {
  L2CAP_LE_RESULT_INVALID_PARAMETERS = 0x0C
} tL2CAP_LE_RESULT_CODE;

/* Define the L2CAP connection result codes */
typedef enum : uint16_t {
  L2CAP_CONN_OK = 0,
  L2CAP_CONN_PENDING = 1,
  L2CAP_CONN_NO_PSM = 2,
  L2CAP_CONN_SECURITY_BLOCK = 3,
  L2CAP_CONN_NO_RESOURCES = 4,
  L2CAP_CONN_TIMEOUT = 0xEEEE,
  /* Generic L2CAP conn failure reasons */
  L2CAP_CONN_OTHER_ERROR = L2CAP_CONN_INTERNAL_MASK,
  L2CAP_CONN_ACL_CONNECTION_FAILED = L2CAP_CONN_INTERNAL_MASK + 1,
  L2CAP_CONN_CLIENT_SECURITY_CLEARANCE_FAILED = L2CAP_CONN_INTERNAL_MASK + 2,
  L2CAP_CONN_NO_LINK = L2CAP_CONN_INTERNAL_MASK + 3,
  L2CAP_CONN_CANCEL =
      L2CAP_CONN_INTERNAL_MASK + 4, /* L2CAP connection cancelled */
  /* For LE result codes converted to L2CAP conn failure code */
  L2CAP_CONN_INSUFFICIENT_AUTHENTICATION =
      L2CAP_CONN_LE_MASK + L2CAP_LE_RESULT_INSUFFICIENT_AUTHENTICATION,
  L2CAP_CONN_INSUFFICIENT_AUTHORIZATION =
      L2CAP_CONN_LE_MASK + L2CAP_LE_RESULT_INSUFFICIENT_AUTHORIZATION,
  L2CAP_CONN_INSUFFICIENT_ENCRYP_KEY_SIZE =
      L2CAP_CONN_LE_MASK + L2CAP_LE_RESULT_INSUFFICIENT_ENCRYP_KEY_SIZE,
  L2CAP_CONN_INSUFFICIENT_ENCRYP =
      L2CAP_CONN_LE_MASK + L2CAP_LE_RESULT_INSUFFICIENT_ENCRYP,
  L2CAP_CONN_INVALID_SOURCE_CID =
      L2CAP_CONN_LE_MASK + L2CAP_LE_RESULT_INVALID_SOURCE_CID,
  L2CAP_CONN_SOURCE_CID_ALREADY_ALLOCATED =
      L2CAP_CONN_LE_MASK + L2CAP_LE_RESULT_SOURCE_CID_ALREADY_ALLOCATED,
  L2CAP_CONN_UNACCEPTABLE_PARAMETERS =
      L2CAP_CONN_LE_MASK + L2CAP_LE_RESULT_UNACCEPTABLE_PARAMETERS,
  L2CAP_CONN_INVALID_PARAMETERS =
      L2CAP_CONN_LE_MASK + L2CAP_LE_RESULT_INVALID_PARAMETERS,
} tL2CAP_CONN;

inline std::string l2cap_le_result_code_text(
    const tL2CAP_LE_RESULT_CODE& code) {
  switch (code) {
+13 −5
Original line number Diff line number Diff line
@@ -226,7 +226,8 @@ static void l2c_csm_closed(tL2C_CCB* p_ccb, tL2CEVT event, void* p_data) {
        btm_acl_notif_conn_collision(p_ccb->p_lcb->remote_bd_addr);
      } else {
        l2cu_release_ccb(p_ccb);
        (*p_ccb->p_rcb->api.pL2CA_Error_Cb)(local_cid, L2CAP_CONN_OTHER_ERROR);
        (*p_ccb->p_rcb->api.pL2CA_Error_Cb)(local_cid,
                                            L2CAP_CONN_ACL_CONNECTION_FAILED);
        bluetooth::shim::CountCounterMetrics(
            android::bluetooth::CodePathCounterKeyEnum::
                L2CAP_CONNECT_CONFIRM_NEG,
@@ -280,7 +281,8 @@ static void l2c_csm_closed(tL2C_CCB* p_ccb, tL2CEVT event, void* p_data) {

    case L2CEVT_SEC_COMP_NEG: /* something is really bad with security */
      l2cu_release_ccb(p_ccb);
      (*p_ccb->p_rcb->api.pL2CA_Error_Cb)(local_cid, L2CAP_CONN_OTHER_ERROR);
      (*p_ccb->p_rcb->api.pL2CA_Error_Cb)(
          local_cid, L2CAP_CONN_CLIENT_SECURITY_CLEARANCE_FAILED);
      bluetooth::shim::CountCounterMetrics(
          android::bluetooth::CodePathCounterKeyEnum::
              L2CAP_SECURITY_NEG_AT_CSM_CLOSED,
@@ -336,7 +338,7 @@ static void l2c_csm_closed(tL2C_CCB* p_ccb, tL2CEVT event, void* p_data) {

    case L2CEVT_TIMEOUT:
      l2cu_release_ccb(p_ccb);
      (*p_ccb->p_rcb->api.pL2CA_Error_Cb)(local_cid, L2CAP_CONN_OTHER_ERROR);
      (*p_ccb->p_rcb->api.pL2CA_Error_Cb)(local_cid, L2CAP_CONN_TIMEOUT);
      bluetooth::shim::CountCounterMetrics(
          android::bluetooth::CodePathCounterKeyEnum::
              L2CAP_TIMEOUT_AT_CSM_CLOSED,
@@ -440,7 +442,8 @@ static void l2c_csm_orig_w4_sec_comp(tL2C_CCB* p_ccb, tL2CEVT event,
      }

      l2cu_release_ccb(p_ccb);
      (*p_ccb->p_rcb->api.pL2CA_Error_Cb)(local_cid, L2CAP_CONN_OTHER_ERROR);
      (*p_ccb->p_rcb->api.pL2CA_Error_Cb)(
          local_cid, L2CAP_CONN_CLIENT_SECURITY_CLEARANCE_FAILED);
      bluetooth::shim::CountCounterMetrics(
          android::bluetooth::CodePathCounterKeyEnum::
              L2CAP_SECURITY_NEG_AT_W4_SEC,
@@ -706,7 +709,12 @@ static void l2c_csm_w4_l2cap_connect_rsp(tL2C_CCB* p_ccb, tL2CEVT event,
                   << loghex(p_ccb->local_cid)
                   << ", reason=" << loghex(p_ci->l2cap_result);
      l2cu_release_ccb(p_ccb);
      (*p_ccb->p_rcb->api.pL2CA_Error_Cb)(local_cid, L2CAP_CONN_OTHER_ERROR);
      if (p_lcb->transport == BT_TRANSPORT_LE) {
        (*p_ccb->p_rcb->api.pL2CA_Error_Cb)(
            local_cid, le_result_to_l2c_conn(p_ci->l2cap_result));
      } else {
        (*p_ccb->p_rcb->api.pL2CA_Error_Cb)(local_cid, p_ci->l2cap_result);
      }
      bluetooth::shim::CountCounterMetrics(
          android::bluetooth::CodePathCounterKeyEnum::L2CAP_CONNECT_RSP_NEG, 1);
      break;
+1 −0
Original line number Diff line number Diff line
@@ -788,6 +788,7 @@ extern bool l2cu_initialize_fixed_ccb(tL2C_LCB* p_lcb, uint16_t fixed_cid);
extern void l2cu_no_dynamic_ccbs(tL2C_LCB* p_lcb);
extern void l2cu_process_fixed_chnl_resp(tL2C_LCB* p_lcb);
extern bool l2cu_is_ccb_active(tL2C_CCB* p_ccb);
extern uint16_t le_result_to_l2c_conn(uint16_t result);

/* Functions provided for Broadcom Aware
 ***************************************
+33 −0
Original line number Diff line number Diff line
@@ -3449,3 +3449,36 @@ void l2cu_check_channel_congestion(tL2C_CCB* p_ccb) {
 *
 ******************************************************************************/
bool l2cu_is_ccb_active(tL2C_CCB* p_ccb) { return (p_ccb && p_ccb->in_use); }

/*******************************************************************************
 *
 * Function         le_result_to_l2c_conn
 *
 * Description      Connvert an LE result code to L2C connection code.
 *
 * Returns          The converted L2C connection code.
 *
 ******************************************************************************/
uint16_t le_result_to_l2c_conn(uint16_t result) {
  tL2CAP_LE_RESULT_CODE code = (tL2CAP_LE_RESULT_CODE)result;
  switch (code) {
    case L2CAP_LE_RESULT_CONN_OK:
    case L2CAP_LE_RESULT_NO_PSM:
    case L2CAP_LE_RESULT_NO_RESOURCES:
      return code;
    case L2CAP_LE_RESULT_INSUFFICIENT_AUTHENTICATION:
    case L2CAP_LE_RESULT_INSUFFICIENT_AUTHORIZATION:
    case L2CAP_LE_RESULT_INSUFFICIENT_ENCRYP_KEY_SIZE:
    case L2CAP_LE_RESULT_INSUFFICIENT_ENCRYP:
    case L2CAP_LE_RESULT_INVALID_SOURCE_CID:
    case L2CAP_LE_RESULT_SOURCE_CID_ALREADY_ALLOCATED:
    case L2CAP_LE_RESULT_UNACCEPTABLE_PARAMETERS:
    case L2CAP_LE_RESULT_INVALID_PARAMETERS:
      return L2CAP_CONN_LE_MASK | code;
    default:
      if (result < L2CAP_CONN_LE_MASK) {
        return L2CAP_CONN_LE_MASK | code;
      }
      return L2CAP_CONN_OTHER_ERROR;
  }
}
+1 −1
Original line number Diff line number Diff line
@@ -571,7 +571,7 @@ void rfc_on_l2cap_error(uint16_t lcid, uint16_t result) {
  tRFC_MCB* p_mcb = rfc_find_lcid_mcb(lcid);
  if (p_mcb == nullptr) return;

  if (result == L2CAP_CONN_OTHER_ERROR) {
  if (result & L2CAP_CONN_INTERNAL_MASK) {
    /* if peer rejects our connect request but peer's connect request is pending
     */
    if (p_mcb->pending_lcid) {