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

Commit 90d88342 authored by Grzegorz Kołodziejczyk's avatar Grzegorz Kołodziejczyk
Browse files

gatt: Extend gatt attr with reading of SIRK characteristic

This extends gatt attr module with reading of SIRK characteristic which
will be used while pairing with set of devices.

Tag: #feature
Bug: 282134244
Test: manual
Change-Id: I783c83edcd36da21fe069c467f854037bbcc5c16
parent ff9fedcf
Loading
Loading
Loading
Loading
+98 −0
Original line number Diff line number Diff line
@@ -55,10 +55,13 @@ using bluetooth::Uuid;

using gatt_sr_supported_feat_cb =
    base::OnceCallback<void(const RawAddress&, uint8_t)>;
using gatt_sirk_cb = base::OnceCallback<void(
    tGATT_STATUS status, const RawAddress&, uint8_t sirk_type, Octet16& sirk)>;

typedef struct {
  uint16_t op_uuid;
  gatt_sr_supported_feat_cb cb;
  gatt_sirk_cb sirk_cb;
} gatt_op_cb_data;

static std::map<uint16_t, std::deque<gatt_op_cb_data>> OngoingOps;
@@ -85,6 +88,11 @@ static bool gatt_sr_is_robust_caching_enabled();

static bool read_sr_supported_feat_req(
    uint16_t conn_id, base::OnceCallback<void(const RawAddress&, uint8_t)> cb);
static bool read_sr_sirk_req(
    uint16_t conn_id,
    base::OnceCallback<void(tGATT_STATUS status, const RawAddress&,
                            uint8_t sirk_type, Octet16& sirk)>
        cb);

static tGATT_STATUS gatt_sr_read_db_hash(uint16_t conn_id,
                                         tGATT_VALUE* p_value);
@@ -643,6 +651,24 @@ static void gatt_cl_op_cmpl_cback(uint16_t conn_id, tGATTC_OPTYPE op,

      break;
    }
    case GATT_UUID_CSIS_SIRK: {
      uint8_t tcb_idx = GATT_GET_TCB_IDX(conn_id);
      tGATT_TCB& tcb = gatt_cb.tcb[tcb_idx];

      auto operation_callback_data = std::move(iter->second.front());
      iter->second.pop_front();
      tcb.gatt_status = status;

      if (status == GATT_SUCCESS) {
        STREAM_TO_UINT8(tcb.sirk_type, pp);
        STREAM_TO_ARRAY(tcb.sirk.data(), pp, 16);
      }

      std::move(operation_callback_data.sirk_cb)
          .Run(tcb.gatt_status, tcb.peer_bda, tcb.sirk_type, tcb.sirk);

      break;
    }
    case GATT_UUID_CLIENT_SUP_FEAT:
      /*We don't need callback data anymore */
      iter->second.pop_front();
@@ -785,6 +811,34 @@ static bool read_sr_supported_feat_req(
  return true;
}

static bool read_sr_sirk_req(
    uint16_t conn_id,
    base::OnceCallback<void(tGATT_STATUS status, const RawAddress&,
                            uint8_t sirk_type, Octet16& sirk)>
        cb) {
  tGATT_READ_PARAM param = {};

  param.service.s_handle = 1;
  param.service.e_handle = 0xFFFF;
  param.service.auth_req = 0;

  param.service.uuid = bluetooth::Uuid::From16Bit(GATT_UUID_CSIS_SIRK);

  if (GATTC_Read(conn_id, GATT_READ_BY_TYPE, &param) != GATT_SUCCESS) {
    LOG_ERROR("Read GATT Support features GATT_Read Failed, conn_id: %d",
              static_cast<int>(conn_id));
    return false;
  }

  gatt_op_cb_data cb_data;

  cb_data.sirk_cb = std::move(cb);
  cb_data.op_uuid = GATT_UUID_CSIS_SIRK;
  OngoingOps[conn_id].emplace_back(std::move(cb_data));

  return true;
}

/*******************************************************************************
 *
 * Function         gatt_cl_read_sr_supp_feat_req
@@ -827,6 +881,50 @@ bool gatt_cl_read_sr_supp_feat_req(
  return read_sr_supported_feat_req(conn_id, std::move(cb));
}

/*******************************************************************************
 *
 * Function         gatt_cl_read_sirk_req
 *
 * Description      Read remote SIRK if it's a set member device.
 *
 * Returns          bool
 *
 ******************************************************************************/
bool gatt_cl_read_sirk_req(
    const RawAddress& peer_bda,
    base::OnceCallback<void(tGATT_STATUS status, const RawAddress&,
                            uint8_t sirk_type, Octet16& sirk)>
        cb) {
  tGATT_PROFILE_CLCB* p_clcb;
  uint16_t conn_id;

  if (!cb) return false;

  LOG_DEBUG("BDA: %s, read SIRK", ADDRESS_TO_LOGGABLE_CSTR(peer_bda));

  GATT_GetConnIdIfConnected(gatt_cb.gatt_if, peer_bda, &conn_id,
                            BT_TRANSPORT_LE);
  if (conn_id == GATT_INVALID_CONN_ID) return false;

  p_clcb = gatt_profile_find_clcb_by_conn_id(conn_id);
  if (!p_clcb) {
    p_clcb = gatt_profile_clcb_alloc(conn_id, peer_bda, BT_TRANSPORT_LE);
  }

  if (!p_clcb) {
    LOG_VERBOSE("p_clcb is NULL, conn_id: %04x", conn_id);
    return false;
  }

  auto it = OngoingOps.find(conn_id);

  if (it == OngoingOps.end()) {
    OngoingOps[conn_id] = std::deque<gatt_op_cb_data>();
  }

  return read_sr_sirk_req(conn_id, std::move(cb));
}

/*******************************************************************************
 *
 * Function         gatt_profile_get_eatt_support
+10 −0
Original line number Diff line number Diff line
@@ -340,6 +340,11 @@ typedef struct {
  /* Use for server. if false, should handle database out of sync. */
  bool is_robust_cache_change_aware;

  /* SIRK read related data */
  tGATT_STATUS gatt_status;
  uint8_t sirk_type;
  Octet16 sirk;

  bool in_use;
  uint8_t tcb_idx;

@@ -503,6 +508,11 @@ void gatt_cl_init_sr_status(tGATT_TCB& tcb);
bool gatt_cl_read_sr_supp_feat_req(
    const RawAddress& peer_bda,
    base::OnceCallback<void(const RawAddress&, uint8_t)> cb);
bool gatt_cl_read_sirk_req(
    const RawAddress& peer_bda,
    base::OnceCallback<void(tGATT_STATUS status, const RawAddress&,
                            uint8_t sirk_type, Octet16& sirk)>
        cb);
bool gatt_sr_is_cl_multi_variable_len_notif_supported(tGATT_TCB& tcb);

bool gatt_sr_is_cl_change_aware(tGATT_TCB& tcb);
+3 −0
Original line number Diff line number Diff line
@@ -138,4 +138,7 @@
/* Database Hash characteristic */
#define GATT_UUID_DATABASE_HASH 0x2B2A

/* CSIS SIRK characteristic */
#define GATT_UUID_CSIS_SIRK 0x2B84

#endif