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

Commit 97ed603c authored by Aritra Sen's avatar Aritra Sen
Browse files

Capture the L2CAP error code from the GAP event data and propate it to the JV...

Capture the L2CAP error code from the GAP event data and propate it to the JV L2CAP socket callback.

Bug: 263522407
Test: mma -j $(nproc)
Change-Id: I5deaee65855afdc8311f1b5f3540c71ae4fefdf7
parent 1faef345
Loading
Loading
Loading
Loading
+22 −0
Original line number Diff line number Diff line
@@ -47,6 +47,25 @@
typedef uint8_t tBTA_JV_STATUS;
#define BTA_JV_INTERNAL_ERR (-1) /* internal error. */

/* L2CAP errors from underlying layers propagated via callbacks. */
#define BTA_JV_L2CAP_REASON_EMPTY 0
#define BTA_JV_L2CAP_REASON_UNKNOWN 1
#define BTA_JV_L2CAP_REASON_ACL_FAILURE 2
#define BTA_JV_L2CAP_REASON_CL_SEC_FAILURE 3
#define BTA_JV_L2CAP_REASON_INSUFFICIENT_AUTHENTICATION 4
#define BTA_JV_L2CAP_REASON_INSUFFICIENT_AUTHORIZATION 5
#define BTA_JV_L2CAP_REASON_INSUFFICIENT_ENCRYP_KEY_SIZE 6
#define BTA_JV_L2CAP_REASON_INSUFFICIENT_ENCRYP 7
#define BTA_JV_L2CAP_REASON_INVALID_SOURCE_CID 8
#define BTA_JV_L2CAP_REASON_SOURCE_CID_ALREADY_ALLOCATED 9
#define BTA_JV_L2CAP_REASON_UNACCEPTABLE_PARAMETERS 10
#define BTA_JV_L2CAP_REASON_INVALID_PARAMETERS 11
#define BTA_JV_L2CAP_REASON_NO_RESOURCES 12
#define BTA_JV_L2CAP_REASON_NO_PSM 13
#define BTA_JV_L2CAP_REASON_TIMEOUT 14

typedef uint8_t tBTA_JV_L2CAP_REASON;

#define BTA_JV_MAX_UUIDS SDP_MAX_UUID_FILTERS
#define BTA_JV_MAX_ATTRS SDP_MAX_ATTR_FILTERS
#define BTA_JV_MAX_SDP_REC SDP_MAX_RECORDS
@@ -208,6 +227,9 @@ typedef struct {
  tBTA_JV_STATUS status; /* Whether the operation succeeded or failed. */
  uint32_t handle;       /* The connection handle */
  bool async;            /* false, if local initiates disconnect */
  /* Reason that triggered the L2CAP connection close callback.
  Used when L2CAP close callback was triggered due to a GAP error. */
  tBTA_JV_L2CAP_REASON reason;
} tBTA_JV_L2CAP_CLOSE;

/* data associated with BTA_JV_L2CAP_START_EVT */
+49 −0
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@
#include "stack/include/avdt_api.h"  // AVDT_PSM
#include "stack/include/bt_hdr.h"
#include "stack/include/gap_api.h"
#include "stack/include/l2cdefs.h"
#include "stack/include/port_api.h"
#include "stack/include/sdp_api.h"
#include "types/bluetooth/uuid.h"
@@ -147,6 +148,53 @@ static void bta_jv_free_sec_id(uint8_t* p_sec_id) {
  }
}

/*******************************************************************************
 *
 * Function     bta_jv_from_gap_l2cap_err
 *
 * Description  Convert the L2CAP error result propagated from GAP to BTA JV
 *              L2CAP close reason code.
 *
 * Params      l2cap_result: The L2CAP result propagated from GAP error.
 *
 * Returns     Appropriate l2cap error reason value
 *             or BTA_JV_L2CAP_REASON_UNKNOWN if reason isn't defined yet.
 *
 ******************************************************************************/
static tBTA_JV_L2CAP_REASON bta_jv_from_gap_l2cap_err(uint16_t l2cap_result) {
  switch (l2cap_result) {
    case L2CAP_CONN_ACL_CONNECTION_FAILED:
      return BTA_JV_L2CAP_REASON_ACL_FAILURE;
    case L2CAP_CONN_CLIENT_SECURITY_CLEARANCE_FAILED:
      return BTA_JV_L2CAP_REASON_CL_SEC_FAILURE;
    case L2CAP_CONN_INSUFFICIENT_AUTHENTICATION:
      return BTA_JV_L2CAP_REASON_INSUFFICIENT_AUTHENTICATION;
    case L2CAP_CONN_INSUFFICIENT_AUTHORIZATION:
      return BTA_JV_L2CAP_REASON_INSUFFICIENT_AUTHORIZATION;
    case L2CAP_CONN_INSUFFICIENT_ENCRYP_KEY_SIZE:
      return BTA_JV_L2CAP_REASON_INSUFFICIENT_ENCRYP_KEY_SIZE;
    case L2CAP_CONN_INSUFFICIENT_ENCRYP:
      return BTA_JV_L2CAP_REASON_INSUFFICIENT_ENCRYP;
    case L2CAP_CONN_INVALID_SOURCE_CID:
      return BTA_JV_L2CAP_REASON_INVALID_SOURCE_CID;
    case L2CAP_CONN_SOURCE_CID_ALREADY_ALLOCATED:
      return BTA_JV_L2CAP_REASON_SOURCE_CID_ALREADY_ALLOCATED;
    case L2CAP_CONN_UNACCEPTABLE_PARAMETERS:
      return BTA_JV_L2CAP_REASON_UNACCEPTABLE_PARAMETERS;
    case L2CAP_CONN_INVALID_PARAMETERS:
      return BTA_JV_L2CAP_REASON_INVALID_PARAMETERS;
    case L2CAP_CONN_NO_RESOURCES:
      return BTA_JV_L2CAP_REASON_NO_RESOURCES;
    case L2CAP_CONN_NO_PSM:
      return BTA_JV_L2CAP_REASON_NO_PSM;
    case L2CAP_CONN_TIMEOUT:
      return BTA_JV_L2CAP_REASON_TIMEOUT;
    default:
      return BTA_JV_L2CAP_REASON_UNKNOWN;
  }
}
/******************************************************************************/

/*******************************************************************************
 *
 * Function     bta_jv_alloc_rfc_cb
@@ -884,6 +932,7 @@ static void bta_jv_l2cap_client_cback(uint16_t gap_handle, uint16_t event,
      p_cb->state = BTA_JV_ST_NONE;
      bta_jv_free_sec_id(&p_cb->sec_id);
      evt_data.l2c_close.async = true;
      evt_data.l2c_close.reason = bta_jv_from_gap_l2cap_err(data->l2cap_result);
      p_cb->p_cback(BTA_JV_L2CAP_CLOSE_EVT, &evt_data, p_cb->l2cap_socket_id);
      p_cb->p_cback = NULL;
      break;