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

Commit db5fc3de authored by Jakub Pawlowski's avatar Jakub Pawlowski
Browse files

Get rid of clcb_idx in favour of pointers

Test: compilation test
Change-Id: Ib2c4b13b85343693e6cff4a94eed49382e3aec00
parent 5fce4191
Loading
Loading
Loading
Loading
+8 −7
Original line number Diff line number Diff line
@@ -326,6 +326,7 @@ tGATT_STATUS attp_send_msg_to_l2cap(tGATT_TCB& tcb, BT_HDR* p_toL2CAP) {
  if (tcb.att_lcid == L2CAP_ATT_CID)
    l2cap_ret = L2CA_SendFixedChnlData(L2CAP_ATT_CID, tcb.peer_bda, p_toL2CAP);
  else

    l2cap_ret = (uint16_t)L2CA_DataWrite(tcb.att_lcid, p_toL2CAP);

  if (l2cap_ret == L2CAP_DW_FAILED) {
@@ -430,12 +431,12 @@ tGATT_STATUS attp_send_sr_msg(tGATT_TCB& tcb, BT_HDR* p_msg) {
 *                  GATT_ERROR if command sending failure
 *
 ******************************************************************************/
tGATT_STATUS attp_cl_send_cmd(tGATT_TCB& tcb, uint16_t clcb_idx,
tGATT_STATUS attp_cl_send_cmd(tGATT_TCB& tcb, tGATT_CLCB* p_clcb,
                              uint8_t cmd_code, BT_HDR* p_cmd) {
  cmd_code &= ~GATT_AUTH_SIGN_MASK;

  if (!tcb.cl_cmd_q.empty() && cmd_code != GATT_HANDLE_VALUE_CONF) {
    gatt_cmd_enq(tcb, clcb_idx, true, cmd_code, p_cmd);
    gatt_cmd_enq(tcb, p_clcb, true, cmd_code, p_cmd);
    return GATT_CMD_STARTED;
  }

@@ -450,8 +451,8 @@ tGATT_STATUS attp_cl_send_cmd(tGATT_TCB& tcb, uint16_t clcb_idx,
    return att_ret;
  }

  gatt_start_rsp_timer(clcb_idx);
  gatt_cmd_enq(tcb, clcb_idx, false, cmd_code, NULL);
  gatt_start_rsp_timer(p_clcb);
  gatt_cmd_enq(tcb, p_clcb, false, cmd_code, NULL);
  return att_ret;
}

@@ -463,7 +464,7 @@ tGATT_STATUS attp_cl_send_cmd(tGATT_TCB& tcb, uint16_t clcb_idx,
 *                  message to server.
 *
 * Parameter        p_tcb: pointer to the connectino control block.
 *                  clcb_idx: clcb index
 *                  p_clcb: clcb
 *                  op_code: message op code.
 *                  p_msg: pointer to message parameters structure.
 *
@@ -471,7 +472,7 @@ tGATT_STATUS attp_cl_send_cmd(tGATT_TCB& tcb, uint16_t clcb_idx,
 *
 *
 ******************************************************************************/
tGATT_STATUS attp_send_cl_msg(tGATT_TCB& tcb, uint16_t clcb_idx,
tGATT_STATUS attp_send_cl_msg(tGATT_TCB& tcb, tGATT_CLCB* p_clcb,
                              uint8_t op_code, tGATT_CL_MSG* p_msg) {
  BT_HDR* p_cmd = NULL;
  uint16_t offset = 0, handle;
@@ -546,5 +547,5 @@ tGATT_STATUS attp_send_cl_msg(tGATT_TCB& tcb, uint16_t clcb_idx,

  if (p_cmd == NULL) return GATT_NO_RESOURCES;

  return attp_cl_send_cmd(tcb, clcb_idx, op_code, p_cmd);
  return attp_cl_send_cmd(tcb, p_clcb, op_code, p_cmd);
}
+2 −2
Original line number Diff line number Diff line
@@ -683,7 +683,7 @@ tGATT_STATUS GATTC_ConfigureMTU(uint16_t conn_id, uint16_t mtu) {
    p_clcb->p_tcb->payload_size = mtu;
    p_clcb->operation = GATTC_OPTYPE_CONFIG;

    ret = attp_send_cl_msg(*p_clcb->p_tcb, p_clcb->clcb_idx, GATT_REQ_MTU,
    ret = attp_send_cl_msg(*p_clcb->p_tcb, p_clcb, GATT_REQ_MTU,
                           (tGATT_CL_MSG*)&mtu);
  }

@@ -1057,7 +1057,7 @@ tGATT_STATUS GATTC_SendHandleValueConfirm(uint16_t conn_id, uint16_t handle) {

  GATT_TRACE_DEBUG("notif_count=%d ", p_tcb->ind_count);
  /* send confirmation now */
  tGATT_STATUS ret = attp_send_cl_msg(*p_tcb, 0, GATT_HANDLE_VALUE_CONF,
  tGATT_STATUS ret = attp_send_cl_msg(*p_tcb, nullptr, GATT_HANDLE_VALUE_CONF,
                                      (tGATT_CL_MSG*)&handle);

  p_tcb->ind_count = 0;
+15 −19
Original line number Diff line number Diff line
@@ -109,7 +109,7 @@ void gatt_act_discovery(tGATT_CLCB* p_clcb) {
               p_clcb->uuid.len);
    }

    st = attp_send_cl_msg(*p_clcb->p_tcb, p_clcb->clcb_idx, op_code, &cl_req);
    st = attp_send_cl_msg(*p_clcb->p_tcb, p_clcb, op_code, &cl_req);

    if (st != GATT_SUCCESS && st != GATT_CMD_STARTED) {
      gatt_end_operation(p_clcb, GATT_ERROR, NULL);
@@ -191,7 +191,7 @@ void gatt_act_read(tGATT_CLCB* p_clcb, uint16_t offset) {
      break;
  }

  if (op_code != 0) rt = attp_send_cl_msg(tcb, p_clcb->clcb_idx, op_code, &msg);
  if (op_code != 0) rt = attp_send_cl_msg(tcb, p_clcb, op_code, &msg);

  if (op_code == 0 || (rt != GATT_SUCCESS && rt != GATT_CMD_STARTED)) {
    gatt_end_operation(p_clcb, rt, NULL);
@@ -218,7 +218,7 @@ void gatt_act_write(tGATT_CLCB* p_clcb, uint8_t sec_act) {
        p_clcb->s_handle = p_attr->handle;
        op_code = (sec_act == GATT_SEC_SIGN_DATA) ? GATT_SIGN_CMD_WRITE
                                                  : GATT_CMD_WRITE;
        rt = gatt_send_write_msg(tcb, p_clcb->clcb_idx, op_code, p_attr->handle,
        rt = gatt_send_write_msg(tcb, p_clcb, op_code, p_attr->handle,
                                 p_attr->len, 0, p_attr->value);
        break;

@@ -226,9 +226,8 @@ void gatt_act_write(tGATT_CLCB* p_clcb, uint8_t sec_act) {
        if (p_attr->len <= (tcb.payload_size - GATT_HDR_SIZE)) {
          p_clcb->s_handle = p_attr->handle;

          rt = gatt_send_write_msg(tcb, p_clcb->clcb_idx, GATT_REQ_WRITE,
                                   p_attr->handle, p_attr->len, 0,
                                   p_attr->value);
          rt = gatt_send_write_msg(tcb, p_clcb, GATT_REQ_WRITE, p_attr->handle,
                                   p_attr->len, 0, p_attr->value);
        } else /* prepare write for long attribute */
        {
          gatt_send_prepare_write(tcb, p_clcb);
@@ -271,8 +270,7 @@ void gatt_send_queue_write_cancel(tGATT_TCB& tcb, tGATT_CLCB* p_clcb,

  GATT_TRACE_DEBUG("gatt_send_queue_write_cancel ");

  rt = attp_send_cl_msg(tcb, p_clcb->clcb_idx, GATT_REQ_EXEC_WRITE,
                        (tGATT_CL_MSG*)&flag);
  rt = attp_send_cl_msg(tcb, p_clcb, GATT_REQ_EXEC_WRITE, (tGATT_CL_MSG*)&flag);

  if (rt != GATT_SUCCESS) {
    gatt_end_operation(p_clcb, rt, NULL);
@@ -348,8 +346,8 @@ void gatt_send_prepare_write(tGATT_TCB& tcb, tGATT_CLCB* p_clcb) {

  GATT_TRACE_DEBUG("offset =0x%x len=%d", offset, to_send);

  rt = gatt_send_write_msg(tcb, p_clcb->clcb_idx, GATT_REQ_PREPARE_WRITE,
                           p_attr->handle, to_send,         /* length */
  rt = gatt_send_write_msg(tcb, p_clcb, GATT_REQ_PREPARE_WRITE, p_attr->handle,
                           to_send,                         /* length */
                           offset,                          /* used as offset */
                           p_attr->value + p_attr->offset); /* data */

@@ -620,7 +618,7 @@ void gatt_process_notification(tGATT_TCB& tcb, uint8_t op_code, uint16_t len,
  if (!GATT_HANDLE_IS_VALID(value.handle)) {
    /* illegal handle, send ack now */
    if (op_code == GATT_HANDLE_VALUE_IND)
      attp_send_cl_msg(tcb, 0, GATT_HANDLE_VALUE_CONF, NULL);
      attp_send_cl_msg(tcb, nullptr, GATT_HANDLE_VALUE_CONF, NULL);
    return;
  }

@@ -656,7 +654,7 @@ void gatt_process_notification(tGATT_TCB& tcb, uint8_t op_code, uint16_t len,
    if (tcb.ind_count > 0)
      gatt_start_ind_ack_timer(tcb);
    else /* no app to indicate, or invalid handle */
      attp_send_cl_msg(tcb, 0, GATT_HANDLE_VALUE_CONF, NULL);
      attp_send_cl_msg(tcb, nullptr, GATT_HANDLE_VALUE_CONF, NULL);
  }

  encrypt_status = gatt_get_link_encrypt_status(tcb);
@@ -1029,7 +1027,7 @@ bool gatt_cl_send_next_cmd_inq(tGATT_TCB& tcb) {
      return true;
    }

    gatt_start_rsp_timer(cmd.clcb_idx);
    gatt_start_rsp_timer(cmd.p_clcb);
    return true;
  }

@@ -1059,16 +1057,14 @@ void gatt_client_handle_server_rsp(tGATT_TCB& tcb, uint8_t op_code,

    if (p_clcb == NULL || (rsp_code != op_code && op_code != GATT_RSP_ERROR)) {
      GATT_TRACE_WARNING(
          "ATT - Ignore wrong response. Receives (%02x) \
                                Request(%02x) Ignored",
          "ATT - Ignore wrong response. Receives (%02x) Request(%02x) Ignored",
          op_code, rsp_code);

      return;
    } else {
    }

    alarm_cancel(p_clcb->gatt_rsp_timer_ent);
    p_clcb->retry_count = 0;
  }
  }
  /* the size of the message may not be bigger than the local max PDU size*/
  /* The message has to be smaller than the agreed MTU, len does not count
   * op_code */
+7 −8
Original line number Diff line number Diff line
@@ -195,10 +195,12 @@ typedef struct {
  uint8_t listening; /* if adv for all has been enabled */
} tGATT_REG;

struct tGATT_CLCB;

/* command queue for each connection */
typedef struct {
  BT_HDR* p_cmd;
  uint16_t clcb_idx;
  tGATT_CLCB* p_clcb;
  uint8_t op_code;
  bool to_send;
} tGATT_CMD_Q;
@@ -261,8 +263,6 @@ typedef struct {
  bool is_primary;
} tGATT_SRV_LIST_ELEM;

struct tGATT_CLCB;

typedef struct {
  std::queue<tGATT_CLCB*> pending_enc_clcb; /* pending encryption channel q */
  tGATT_SEC_ACTION sec_act;
@@ -310,7 +310,6 @@ struct tGATT_CLCB {
  uint8_t* p_attr_buf; /* attribute buffer for read multiple, prepare write */
  tBT_UUID uuid;
  uint16_t conn_id; /* connection handle */
  uint16_t clcb_idx;
  uint16_t s_handle; /* starting handle of the active request */
  uint16_t e_handle; /* ending handle of the active request */
  uint16_t counter; /* used as offset, attribute length, num of prepare write */
@@ -425,7 +424,7 @@ extern void gatt_add_a_bonded_dev_for_srv_chg(BD_ADDR bda);
extern uint16_t gatt_profile_find_conn_id_by_bd_addr(BD_ADDR bda);

/* Functions provided by att_protocol.cc */
extern tGATT_STATUS attp_send_cl_msg(tGATT_TCB& tcb, uint16_t clcb_idx,
extern tGATT_STATUS attp_send_cl_msg(tGATT_TCB& tcb, tGATT_CLCB* p_clcb,
                                     uint8_t op_code, tGATT_CL_MSG* p_msg);
extern BT_HDR* attp_build_sr_msg(tGATT_TCB& tcb, uint8_t op_code,
                                 tGATT_SR_MSG* p_msg);
@@ -444,7 +443,7 @@ extern void gatt_convert_uuid32_to_uuid128(uint8_t uuid_128[LEN_UUID_128],
                                           uint32_t uuid_32);
extern void gatt_sr_get_sec_info(BD_ADDR rem_bda, tBT_TRANSPORT transport,
                                 uint8_t* p_sec_flag, uint8_t* p_key_size);
extern void gatt_start_rsp_timer(uint16_t clcb_idx);
extern void gatt_start_rsp_timer(tGATT_CLCB* p_clcb);
extern void gatt_start_conf_timer(tGATT_TCB* p_tcb);
extern void gatt_rsp_timeout(void* data);
extern void gatt_indication_confirmation_timeout(void* data);
@@ -532,7 +531,7 @@ extern bool gatt_send_ble_burst_data(BD_ADDR remote_bda, BT_HDR* p_buf);

/* GATT client functions */
extern void gatt_dequeue_sr_cmd(tGATT_TCB& tcb);
extern uint8_t gatt_send_write_msg(tGATT_TCB& p_tcb, uint16_t clcb_idx,
extern uint8_t gatt_send_write_msg(tGATT_TCB& p_tcb, tGATT_CLCB* p_clcb,
                                   uint8_t op_code, uint16_t handle,
                                   uint16_t len, uint16_t offset,
                                   uint8_t* p_data);
@@ -545,7 +544,7 @@ extern void gatt_act_discovery(tGATT_CLCB* p_clcb);
extern void gatt_act_read(tGATT_CLCB* p_clcb, uint16_t offset);
extern void gatt_act_write(tGATT_CLCB* p_clcb, uint8_t sec_act);
extern tGATT_CLCB* gatt_cmd_dequeue(tGATT_TCB& tcb, uint8_t* p_opcode);
extern void gatt_cmd_enq(tGATT_TCB& tcb, uint16_t clcb_idx, bool to_send,
extern void gatt_cmd_enq(tGATT_TCB& tcb, tGATT_CLCB* p_clcb, bool to_send,
                         uint8_t op_code, BT_HDR* p_buf);
extern void gatt_client_handle_server_rsp(tGATT_TCB& tcb, uint8_t op_code,
                                          uint16_t len, uint8_t* p_data);
+8 −11
Original line number Diff line number Diff line
@@ -657,8 +657,7 @@ bool gatt_parse_uuid_from_cmd(tBT_UUID* p_uuid_rec, uint16_t uuid_size,
 * Returns          void
 *
 ******************************************************************************/
void gatt_start_rsp_timer(uint16_t clcb_idx) {
  tGATT_CLCB* p_clcb = &gatt_cb.clcb[clcb_idx];
void gatt_start_rsp_timer(tGATT_CLCB* p_clcb) {
  period_ms_t timeout_ms = GATT_WAIT_FOR_RSP_TIMEOUT_MS;

  if (p_clcb->operation == GATTC_OPTYPE_DISCOVERY &&
@@ -770,7 +769,7 @@ void gatt_ind_ack_timeout(void* data) {

  GATT_TRACE_WARNING("%s send ack now", __func__);
  p_tcb->ind_count = 0;
  attp_send_cl_msg(*p_tcb, 0, GATT_HANDLE_VALUE_CONF, NULL);
  attp_send_cl_msg(*p_tcb, nullptr, GATT_HANDLE_VALUE_CONF, NULL);
}
/*******************************************************************************
 *
@@ -1035,7 +1034,6 @@ tGATT_CLCB* gatt_clcb_alloc(uint16_t conn_id) {

      p_clcb->in_use = true;
      p_clcb->conn_id = conn_id;
      p_clcb->clcb_idx = i;
      p_clcb->p_reg = p_reg;
      p_clcb->p_tcb = p_tcb;
      break;
@@ -1308,13 +1306,13 @@ bool gatt_find_app_hold_link(tGATT_TCB* p_tcb, uint8_t start_idx,
}

/** Enqueue this command */
void gatt_cmd_enq(tGATT_TCB& tcb, uint16_t clcb_idx, bool to_send,
void gatt_cmd_enq(tGATT_TCB& tcb, tGATT_CLCB* p_clcb, bool to_send,
                  uint8_t op_code, BT_HDR* p_buf) {
  tGATT_CMD_Q cmd;
  cmd.to_send = to_send; /* waiting to be sent */
  cmd.op_code = op_code;
  cmd.p_cmd = p_buf;
  cmd.clcb_idx = clcb_idx;
  cmd.p_clcb = p_clcb;

  if (!to_send) {
    // TODO: WTF why do we clear the queue here ?!
@@ -1329,7 +1327,7 @@ tGATT_CLCB* gatt_cmd_dequeue(tGATT_TCB& tcb, uint8_t* p_op_code) {
  if (tcb.cl_cmd_q.empty()) return nullptr;

  tGATT_CMD_Q cmd = tcb.cl_cmd_q.front();
  tGATT_CLCB* p_clcb = &gatt_cb.clcb[cmd.clcb_idx];
  tGATT_CLCB* p_clcb = cmd.p_clcb;
  *p_op_code = cmd.op_code;
  tcb.cl_cmd_q.pop();

@@ -1345,7 +1343,7 @@ tGATT_CLCB* gatt_cmd_dequeue(tGATT_TCB& tcb, uint8_t* p_op_code) {
 * Returns          status code
 *
 ******************************************************************************/
uint8_t gatt_send_write_msg(tGATT_TCB& tcb, uint16_t clcb_idx, uint8_t op_code,
uint8_t gatt_send_write_msg(tGATT_TCB& tcb, tGATT_CLCB* p_clcb, uint8_t op_code,
                            uint16_t handle, uint16_t len, uint16_t offset,
                            uint8_t* p_data) {
  tGATT_CL_MSG msg;
@@ -1357,7 +1355,7 @@ uint8_t gatt_send_write_msg(tGATT_TCB& tcb, uint16_t clcb_idx, uint8_t op_code,
  memcpy(msg.attr_value.value, p_data, len);

  /* write by handle */
  return attp_send_cl_msg(tcb, clcb_idx, op_code, &msg);
  return attp_send_cl_msg(tcb, p_clcb, op_code, &msg);
}

/*******************************************************************************
@@ -1459,8 +1457,7 @@ void gatt_cleanup_upon_disc(BD_ADDR bda, uint16_t reason,
      p_clcb = &gatt_cb.clcb[i];
      if (p_clcb->in_use && p_clcb->p_tcb == p_tcb) {
        alarm_cancel(p_clcb->gatt_rsp_timer_ent);
        GATT_TRACE_DEBUG("found p_clcb conn_id=%d clcb_idx=%d", p_clcb->conn_id,
                         p_clcb->clcb_idx);
        GATT_TRACE_DEBUG("found p_clcb conn_id=%d", p_clcb->conn_id);
        if (p_clcb->operation != GATTC_OPTYPE_NONE)
          gatt_end_operation(p_clcb, GATT_ERROR, NULL);