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) {
* 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;
}
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;
}
* 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.
*
*
*
******************************************************************************/
-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;
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);
}
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);
}
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;
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);
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);
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;
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);
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);
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 */
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;
}
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);
return true;
}
- gatt_start_rsp_timer(cmd.clcb_idx);
+ gatt_start_rsp_timer(cmd.p_clcb);
return true;
}
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;
}
+
+ 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
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;
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;
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 */
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);
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);
/* 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);
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);
* 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 &&
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);
}
/*******************************************************************************
*
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;
}
/** 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 ?!
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();
* 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;
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);
}
/*******************************************************************************
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);