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

Commit 194a49e2 authored by Jakub Pawlowski's avatar Jakub Pawlowski
Browse files

GATTC_Discover: pass parameters directly instead of through pointer

Bug: 67057055
Test: manual
Change-Id: I7be853241595b336e2d4b67bc57170ee01ce6e72
parent 6d3cb118
Loading
Loading
Loading
Loading
+8 −9
Original line number Diff line number Diff line
@@ -246,15 +246,14 @@ void BTA_GATTC_ServiceSearchRequest(uint16_t conn_id, Uuid* p_srvc_uuid) {
  bta_sys_sendmsg(p_buf);
}

void BTA_GATTC_DiscoverServiceByUuid(uint16_t conn_id,
                                     const Uuid& p_srvc_uuid) {
  tGATT_DISC_PARAM* param = new tGATT_DISC_PARAM;
  param->s_handle = 0x0001;
  param->e_handle = 0xFFFF;
  param->service = p_srvc_uuid;
  do_in_bta_thread(FROM_HERE,
                   base::Bind(base::IgnoreResult(&GATTC_Discover), conn_id,
                              GATT_DISC_SRVC_BY_UUID, base::Owned(param)));
void BTA_GATTC_DiscoverServiceByUuid(uint16_t conn_id, const Uuid& srvc_uuid) {
  do_in_bta_thread(
      FROM_HERE,
      base::Bind(
          base::IgnoreResult<tGATT_STATUS (*)(uint16_t, tGATT_DISC_TYPE,
                                              uint16_t, uint16_t, const Uuid&)>(
              &GATTC_Discover),
          conn_id, GATT_DISC_SRVC_BY_UUID, 0x0001, 0xFFFF, srvc_uuid));
}

/*******************************************************************************
+6 −13
Original line number Diff line number Diff line
@@ -137,8 +137,7 @@ tGATT_STATUS bta_gattc_discover_pri_service(uint16_t conn_id,
  if (!p_clcb) return GATT_ERROR;

  if (p_clcb->transport == BTA_TRANSPORT_LE) {
    tGATT_DISC_PARAM param{.s_handle = 0x0001, .e_handle = 0xFFFF};
    return GATTC_Discover(conn_id, disc_type, &param);
    return GATTC_Discover(conn_id, disc_type, 0x0001, 0xFFFF);
  }

  // only for Classic transport
@@ -164,9 +163,7 @@ static void bta_gattc_explore_next_service(uint16_t conn_id,
  VLOG(1) << "Start service discovery";

  /* start discovering included services */
  tGATT_DISC_PARAM param = {.s_handle = service.first,
                            .e_handle = service.second};
  GATTC_Discover(conn_id, GATT_DISC_INC_SRVC, &param);
  GATTC_Discover(conn_id, GATT_DISC_INC_SRVC, service.first, service.second);
}

static void bta_gattc_explore_srvc_finished(uint16_t conn_id,
@@ -207,12 +204,10 @@ void bta_gattc_start_disc_char_dscp(uint16_t conn_id,
    goto descriptor_discovery_done;
  }

  {
    tGATT_DISC_PARAM param{.s_handle = range.first, .e_handle = range.second};
    if (GATTC_Discover(conn_id, GATT_DISC_CHAR_DSCPT, &param) != 0) {
  if (GATTC_Discover(conn_id, GATT_DISC_CHAR_DSCPT, range.first,
                     range.second) != 0) {
    goto descriptor_discovery_done;
  }
  }
  return;

descriptor_discovery_done:
@@ -384,9 +379,7 @@ void bta_gattc_disc_cmpl_cback(uint16_t conn_id, tGATT_DISC_TYPE disc_type,
    case GATT_DISC_INC_SRVC: {
      auto& service = p_srvc_cb->pending_discovery.CurrentlyExploredService();
      /* start discovering characteristic */
      tGATT_DISC_PARAM param = {.s_handle = service.first,
                                .e_handle = service.second};
      GATTC_Discover(conn_id, GATT_DISC_CHAR, &param);
      GATTC_Discover(conn_id, GATT_DISC_CHAR, service.first, service.second);
      break;
    }

+1 −1
Original line number Diff line number Diff line
@@ -476,7 +476,7 @@ extern void BTA_GATTC_ServiceSearchRequest(uint16_t conn_id,
 * PTS tests.
 */
extern void BTA_GATTC_DiscoverServiceByUuid(uint16_t conn_id,
                                            const bluetooth::Uuid& p_srvc_uuid);
                                            const bluetooth::Uuid& srvc_uuid);

/*******************************************************************************
 *
+3 −9
Original line number Diff line number Diff line
@@ -219,24 +219,18 @@ bt_status_t btif_gattc_test_command_impl(int command,

    case 0x04: /* Discover */
    {
      tGATT_DISC_PARAM param;
      memset(&param, 0, sizeof(tGATT_DISC_PARAM));

      if (params->u1 >= GATT_DISC_MAX) {
        LOG_ERROR(LOG_TAG, "%s: DISCOVER - Invalid type (%d)!", __func__,
                  params->u1);
        return (bt_status_t)0;
      }

      param.s_handle = params->u2;
      param.e_handle = params->u3;
      param.service = *params->uuid1;

      LOG_DEBUG(LOG_TAG,
                "%s: DISCOVER (%s), conn_id=%d, uuid=%s, handles=0x%04x-0x%04x",
                __func__, disc_name[params->u1], test_cb.conn_id,
                param.service.ToString().c_str(), params->u2, params->u3);
      GATTC_Discover(test_cb.conn_id, params->u1, &param);
                params->uuid1->ToString().c_str(), params->u2, params->u3);
      GATTC_Discover(test_cb.conn_id, params->u1, params->u2, params->u3,
                     *params->uuid1);
      break;
    }

+20 −12
Original line number Diff line number Diff line
@@ -613,20 +613,22 @@ tGATT_STATUS GATTC_ConfigureMTU(uint16_t conn_id, uint16_t mtu) {
 *
 * Parameters       conn_id: connection identifier.
 *                  disc_type:discovery type.
 *                  p_param: parameters of discovery requirement.
 *                  start_handle and end_handle: range of handles for discovery
 *                  uuid: uuid to discovery. set to Uuid::kEmpty for requests
 *                        that don't need it
 *
 * Returns          GATT_SUCCESS if command received/sent successfully.
 *
 ******************************************************************************/
tGATT_STATUS GATTC_Discover(uint16_t conn_id, tGATT_DISC_TYPE disc_type,
                            tGATT_DISC_PARAM* p_param) {
                            uint16_t start_handle, uint16_t end_handle,
                            const Uuid& uuid) {
  tGATT_IF gatt_if = GATT_GET_GATT_IF(conn_id);
  uint8_t tcb_idx = GATT_GET_TCB_IDX(conn_id);
  tGATT_TCB* p_tcb = gatt_get_tcb_by_idx(tcb_idx);
  tGATT_REG* p_reg = gatt_get_regcb(gatt_if);

  if ((p_tcb == NULL) || (p_reg == NULL) || (p_param == NULL) ||
      (disc_type >= GATT_DISC_MAX)) {
  if ((p_tcb == NULL) || (p_reg == NULL) || (disc_type >= GATT_DISC_MAX)) {
    LOG(ERROR) << __func__ << " Illegal param: disc_type=" << +disc_type
               << " conn_id=" << loghex(conn_id);
    return GATT_ILLEGAL_PARAMETER;
@@ -634,13 +636,13 @@ tGATT_STATUS GATTC_Discover(uint16_t conn_id, tGATT_DISC_TYPE disc_type,

  LOG(INFO) << __func__ << " conn_id=" << loghex(conn_id)
            << ", disc_type=" << +disc_type
            << ", s_handle=" << loghex(p_param->s_handle)
            << ", e_handle=" << loghex(p_param->e_handle);
            << ", s_handle=" << loghex(start_handle)
            << ", e_handle=" << loghex(end_handle);

  if (!GATT_HANDLE_IS_VALID(p_param->s_handle) ||
      !GATT_HANDLE_IS_VALID(p_param->e_handle) ||
  if (!GATT_HANDLE_IS_VALID(start_handle) ||
      !GATT_HANDLE_IS_VALID(end_handle) ||
      /* search by type does not have a valid UUID param */
      (disc_type == GATT_DISC_SRVC_BY_UUID && p_param->service.IsEmpty())) {
      (disc_type == GATT_DISC_SRVC_BY_UUID && uuid.IsEmpty())) {
    return GATT_ILLEGAL_PARAMETER;
  }

@@ -654,14 +656,20 @@ tGATT_STATUS GATTC_Discover(uint16_t conn_id, tGATT_DISC_TYPE disc_type,

  p_clcb->operation = GATTC_OPTYPE_DISCOVERY;
  p_clcb->op_subtype = disc_type;
  p_clcb->s_handle = p_param->s_handle;
  p_clcb->e_handle = p_param->e_handle;
  p_clcb->uuid = p_param->service;
  p_clcb->s_handle = start_handle;
  p_clcb->e_handle = end_handle;
  p_clcb->uuid = uuid;

  gatt_act_discovery(p_clcb);
  return GATT_SUCCESS;
}

tGATT_STATUS GATTC_Discover(uint16_t conn_id, tGATT_DISC_TYPE disc_type,
                            uint16_t start_handle, uint16_t end_handle) {
  return GATTC_Discover(conn_id, disc_type, start_handle, end_handle,
                        Uuid::kEmpty);
}

/*******************************************************************************
 *
 * Function         GATTC_Read
Loading