2016-09-26 13:37:39 +00:00
|
|
|
/******************************************************************************
|
|
|
|
*
|
|
|
|
* Copyright (C) 1999-2012 Broadcom Corporation
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at:
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
*
|
|
|
|
* this file contains the main GATT client functions
|
|
|
|
*
|
|
|
|
******************************************************************************/
|
|
|
|
|
2018-04-08 04:10:50 +00:00
|
|
|
#include "common/bt_target.h"
|
2016-09-26 13:37:39 +00:00
|
|
|
|
2017-04-20 11:18:05 +00:00
|
|
|
#if BLE_INCLUDED == TRUE && GATTC_INCLUDED == TRUE
|
2016-09-26 13:37:39 +00:00
|
|
|
|
|
|
|
#include <string.h>
|
2018-04-08 04:10:50 +00:00
|
|
|
#include "osi/allocator.h"
|
2016-09-26 13:37:39 +00:00
|
|
|
#include "gatt_int.h"
|
|
|
|
#include "l2c_int.h"
|
|
|
|
|
|
|
|
#define GATT_WRITE_LONG_HDR_SIZE 5 /* 1 opcode + 2 handle + 2 offset */
|
|
|
|
#define GATT_READ_CHAR_VALUE_HDL (GATT_READ_CHAR_VALUE | 0x80)
|
|
|
|
#define GATT_READ_INC_SRV_UUID128 (GATT_DISC_INC_SRVC | 0x90)
|
|
|
|
|
|
|
|
#define GATT_PREP_WRITE_RSP_MIN_LEN 4
|
|
|
|
#define GATT_NOTIFICATION_MIN_LEN 2
|
|
|
|
#define GATT_WRITE_RSP_MIN_LEN 2
|
|
|
|
#define GATT_INFO_RSP_MIN_LEN 1
|
|
|
|
#define GATT_MTU_RSP_MIN_LEN 2
|
|
|
|
#define GATT_READ_BY_TYPE_RSP_MIN_LEN 1
|
|
|
|
|
|
|
|
/********************************************************************************
|
|
|
|
** G L O B A L G A T T D A T A *
|
|
|
|
*********************************************************************************/
|
|
|
|
void gatt_send_prepare_write(tGATT_TCB *p_tcb, tGATT_CLCB *p_clcb);
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
UINT8 disc_type_to_att_opcode[GATT_DISC_MAX] = {
|
2016-09-26 13:37:39 +00:00
|
|
|
0,
|
|
|
|
GATT_REQ_READ_BY_GRP_TYPE, /* GATT_DISC_SRVC_ALL = 1, */
|
|
|
|
GATT_REQ_FIND_TYPE_VALUE, /* GATT_DISC_SRVC_BY_UUID, */
|
|
|
|
GATT_REQ_READ_BY_TYPE, /* GATT_DISC_INC_SRVC, */
|
|
|
|
GATT_REQ_READ_BY_TYPE, /* GATT_DISC_CHAR, */
|
|
|
|
GATT_REQ_FIND_INFO /* GATT_DISC_CHAR_DSCPT, */
|
|
|
|
};
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
UINT16 disc_type_to_uuid[GATT_DISC_MAX] = {
|
2016-09-26 13:37:39 +00:00
|
|
|
0, /* reserved */
|
|
|
|
GATT_UUID_PRI_SERVICE, /* <service> DISC_SRVC_ALL */
|
|
|
|
GATT_UUID_PRI_SERVICE, /* <service> for DISC_SERVC_BY_UUID */
|
|
|
|
GATT_UUID_INCLUDE_SERVICE, /* <include_service> for DISC_INC_SRVC */
|
|
|
|
GATT_UUID_CHAR_DECLARE, /* <characteristic> for DISC_CHAR */
|
|
|
|
0 /* no type filtering for DISC_CHAR_DSCPT */
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function gatt_act_discovery
|
|
|
|
**
|
|
|
|
** Description GATT discovery operation.
|
|
|
|
**
|
|
|
|
** Returns void.
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void gatt_act_discovery(tGATT_CLCB *p_clcb)
|
|
|
|
{
|
|
|
|
UINT8 op_code = disc_type_to_att_opcode[p_clcb->op_subtype];
|
|
|
|
tGATT_CL_MSG cl_req;
|
|
|
|
tGATT_STATUS st;
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
if (p_clcb->s_handle <= p_clcb->e_handle && p_clcb->s_handle != 0) {
|
2016-09-26 13:37:39 +00:00
|
|
|
memset(&cl_req, 0, sizeof(tGATT_CL_MSG));
|
|
|
|
|
|
|
|
cl_req.browse.s_handle = p_clcb->s_handle;
|
|
|
|
cl_req.browse.e_handle = p_clcb->e_handle;
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
if (disc_type_to_uuid[p_clcb->op_subtype] != 0) {
|
2016-09-26 13:37:39 +00:00
|
|
|
cl_req.browse.uuid.len = 2;
|
|
|
|
cl_req.browse.uuid.uu.uuid16 = disc_type_to_uuid[p_clcb->op_subtype];
|
|
|
|
}
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
if (p_clcb->op_subtype == GATT_DISC_SRVC_BY_UUID) { /* fill in the FindByTypeValue request info*/
|
2016-09-26 13:37:39 +00:00
|
|
|
cl_req.find_type_value.uuid.len = 2;
|
|
|
|
cl_req.find_type_value.uuid.uu.uuid16 = disc_type_to_uuid[p_clcb->op_subtype];
|
|
|
|
cl_req.find_type_value.s_handle = p_clcb->s_handle;
|
|
|
|
cl_req.find_type_value.e_handle = p_clcb->e_handle;
|
|
|
|
cl_req.find_type_value.value_len = p_clcb->uuid.len;
|
|
|
|
/* if service type is 32 bits UUID, convert it now */
|
2016-11-24 18:10:15 +00:00
|
|
|
if (p_clcb->uuid.len == LEN_UUID_32) {
|
2016-09-26 13:37:39 +00:00
|
|
|
cl_req.find_type_value.value_len = LEN_UUID_128;
|
|
|
|
gatt_convert_uuid32_to_uuid128(cl_req.find_type_value.value, p_clcb->uuid.uu.uuid32);
|
2016-11-24 18:10:15 +00:00
|
|
|
} else {
|
|
|
|
memcpy (cl_req.find_type_value.value, &p_clcb->uuid.uu, p_clcb->uuid.len);
|
2016-09-26 13:37:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
st = attp_send_cl_msg(p_clcb->p_tcb, p_clcb->clcb_idx, op_code, &cl_req);
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
if (st != GATT_SUCCESS && st != GATT_CMD_STARTED) {
|
2016-09-26 13:37:39 +00:00
|
|
|
gatt_end_operation(p_clcb, GATT_ERROR, NULL);
|
|
|
|
}
|
2016-11-24 18:10:15 +00:00
|
|
|
} else { /* end of handle range */
|
2016-09-26 13:37:39 +00:00
|
|
|
gatt_end_operation(p_clcb, GATT_SUCCESS, NULL);
|
2016-11-24 18:10:15 +00:00
|
|
|
}
|
2016-09-26 13:37:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function gatt_act_read
|
|
|
|
**
|
|
|
|
** Description GATT read operation.
|
|
|
|
**
|
|
|
|
** Returns void.
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void gatt_act_read (tGATT_CLCB *p_clcb, UINT16 offset)
|
|
|
|
{
|
|
|
|
tGATT_TCB *p_tcb = p_clcb->p_tcb;
|
|
|
|
UINT8 rt = GATT_INTERNAL_ERROR;
|
|
|
|
tGATT_CL_MSG msg;
|
|
|
|
UINT8 op_code = 0;
|
|
|
|
|
|
|
|
memset (&msg, 0, sizeof(tGATT_CL_MSG));
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
switch (p_clcb->op_subtype) {
|
|
|
|
case GATT_READ_CHAR_VALUE:
|
|
|
|
case GATT_READ_BY_TYPE:
|
|
|
|
op_code = GATT_REQ_READ_BY_TYPE;
|
|
|
|
msg.browse.s_handle = p_clcb->s_handle;
|
|
|
|
msg.browse.e_handle = p_clcb->e_handle;
|
|
|
|
if (p_clcb->op_subtype == GATT_READ_BY_TYPE) {
|
|
|
|
memcpy(&msg.browse.uuid, &p_clcb->uuid, sizeof(tBT_UUID));
|
|
|
|
} else {
|
|
|
|
msg.browse.uuid.len = LEN_UUID_16;
|
|
|
|
msg.browse.uuid.uu.uuid16 = GATT_UUID_CHAR_DECLARE;
|
|
|
|
}
|
|
|
|
break;
|
2016-09-26 13:37:39 +00:00
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
case GATT_READ_CHAR_VALUE_HDL:
|
|
|
|
case GATT_READ_BY_HANDLE:
|
|
|
|
if (!p_clcb->counter) {
|
|
|
|
op_code = GATT_REQ_READ;
|
|
|
|
msg.handle = p_clcb->s_handle;
|
|
|
|
} else {
|
|
|
|
if (!p_clcb->first_read_blob_after_read) {
|
|
|
|
p_clcb->first_read_blob_after_read = TRUE;
|
|
|
|
} else {
|
|
|
|
p_clcb->first_read_blob_after_read = FALSE;
|
2016-09-26 13:37:39 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
GATT_TRACE_DEBUG("gatt_act_read first_read_blob_after_read=%d",
|
|
|
|
p_clcb->first_read_blob_after_read);
|
2016-09-26 13:37:39 +00:00
|
|
|
op_code = GATT_REQ_READ_BLOB;
|
|
|
|
msg.read_blob.offset = offset;
|
2016-11-24 18:10:15 +00:00
|
|
|
msg.read_blob.handle = p_clcb->s_handle;
|
|
|
|
}
|
|
|
|
p_clcb->op_subtype &= ~ 0x80;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GATT_READ_PARTIAL:
|
|
|
|
op_code = GATT_REQ_READ_BLOB;
|
|
|
|
msg.read_blob.handle = p_clcb->s_handle;
|
|
|
|
msg.read_blob.offset = offset;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GATT_READ_MULTIPLE:
|
|
|
|
op_code = GATT_REQ_READ_MULTI;
|
|
|
|
memcpy (&msg.read_multi, p_clcb->p_attr_buf, sizeof(tGATT_READ_MULTI));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GATT_READ_INC_SRV_UUID128:
|
|
|
|
op_code = GATT_REQ_READ;
|
|
|
|
msg.handle = p_clcb->s_handle;
|
|
|
|
p_clcb->op_subtype &= ~ 0x90;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
GATT_TRACE_ERROR("Unknown read type: %d", p_clcb->op_subtype);
|
|
|
|
break;
|
2016-09-26 13:37:39 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
if (op_code != 0) {
|
2016-09-26 13:37:39 +00:00
|
|
|
rt = attp_send_cl_msg(p_tcb, p_clcb->clcb_idx, op_code, &msg);
|
2016-11-24 18:10:15 +00:00
|
|
|
}
|
2016-09-26 13:37:39 +00:00
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
if ( op_code == 0 || (rt != GATT_SUCCESS && rt != GATT_CMD_STARTED)) {
|
2016-09-26 13:37:39 +00:00
|
|
|
gatt_end_operation(p_clcb, rt, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function gatt_act_write
|
|
|
|
**
|
|
|
|
** Description GATT write operation.
|
|
|
|
**
|
|
|
|
** Returns void.
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void gatt_act_write (tGATT_CLCB *p_clcb, UINT8 sec_act)
|
|
|
|
{
|
|
|
|
tGATT_TCB *p_tcb = p_clcb->p_tcb;
|
|
|
|
UINT8 rt = GATT_SUCCESS, op_code = 0;
|
|
|
|
tGATT_VALUE *p_attr = (tGATT_VALUE *)p_clcb->p_attr_buf;
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
if (p_attr) {
|
|
|
|
switch (p_clcb->op_subtype) {
|
|
|
|
case GATT_WRITE_NO_RSP:
|
2020-07-24 06:30:47 +00:00
|
|
|
l2ble_update_att_acl_pkt_num(L2CA_DECREASE_BTU_NUM, NULL);
|
2016-11-24 18:10:15 +00:00
|
|
|
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(p_tcb,
|
|
|
|
p_clcb->clcb_idx,
|
|
|
|
op_code,
|
|
|
|
p_attr->handle,
|
|
|
|
p_attr->len,
|
|
|
|
0,
|
|
|
|
p_attr->value);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GATT_WRITE:
|
|
|
|
if (p_attr->len <= (p_tcb->payload_size - GATT_HDR_SIZE)) {
|
2016-09-26 13:37:39 +00:00
|
|
|
p_clcb->s_handle = p_attr->handle;
|
2016-11-24 18:10:15 +00:00
|
|
|
|
2016-09-26 13:37:39 +00:00
|
|
|
rt = gatt_send_write_msg(p_tcb,
|
|
|
|
p_clcb->clcb_idx,
|
2016-11-24 18:10:15 +00:00
|
|
|
GATT_REQ_WRITE,
|
2016-09-26 13:37:39 +00:00
|
|
|
p_attr->handle,
|
|
|
|
p_attr->len,
|
|
|
|
0,
|
|
|
|
p_attr->value);
|
2016-11-24 18:10:15 +00:00
|
|
|
} else { /* prepare write for long attribute */
|
2016-09-26 13:37:39 +00:00
|
|
|
gatt_send_prepare_write(p_tcb, p_clcb);
|
2016-11-24 18:10:15 +00:00
|
|
|
}
|
|
|
|
break;
|
2016-09-26 13:37:39 +00:00
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
case GATT_WRITE_PREPARE:
|
|
|
|
gatt_send_prepare_write(p_tcb, p_clcb);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
rt = GATT_INTERNAL_ERROR;
|
|
|
|
GATT_TRACE_ERROR("Unknown write type: %d", p_clcb->op_subtype);
|
|
|
|
break;
|
2016-09-26 13:37:39 +00:00
|
|
|
}
|
2016-11-24 18:10:15 +00:00
|
|
|
} else {
|
2016-09-26 13:37:39 +00:00
|
|
|
rt = GATT_INTERNAL_ERROR;
|
2016-11-24 18:10:15 +00:00
|
|
|
}
|
2016-09-26 13:37:39 +00:00
|
|
|
|
|
|
|
if ((rt != GATT_SUCCESS && rt != GATT_CMD_STARTED && rt != GATT_CONGESTED)
|
2016-11-24 18:10:15 +00:00
|
|
|
|| (rt != GATT_CMD_STARTED && p_clcb->op_subtype == GATT_WRITE_NO_RSP)) {
|
|
|
|
if (rt != GATT_SUCCESS) {
|
2016-09-26 13:37:39 +00:00
|
|
|
GATT_TRACE_ERROR("gatt_act_write() failed op_code=0x%x rt=%d", op_code, rt);
|
|
|
|
}
|
|
|
|
gatt_end_operation(p_clcb, rt, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function gatt_send_queue_write_cancel
|
|
|
|
**
|
|
|
|
** Description send queue write cancel
|
|
|
|
**
|
|
|
|
** Returns void.
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void gatt_send_queue_write_cancel (tGATT_TCB *p_tcb, tGATT_CLCB *p_clcb, tGATT_EXEC_FLAG flag)
|
|
|
|
{
|
|
|
|
UINT8 rt ;
|
|
|
|
|
|
|
|
GATT_TRACE_DEBUG("gatt_send_queue_write_cancel ");
|
|
|
|
|
|
|
|
rt = attp_send_cl_msg(p_tcb, p_clcb->clcb_idx, GATT_REQ_EXEC_WRITE, (tGATT_CL_MSG *)&flag);
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
if (rt != GATT_SUCCESS) {
|
2016-09-26 13:37:39 +00:00
|
|
|
gatt_end_operation(p_clcb, rt, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function gatt_check_write_long_terminate
|
|
|
|
**
|
|
|
|
** Description To terminate write long or not.
|
|
|
|
**
|
|
|
|
** Returns TRUE: write long is terminated; FALSE keep sending.
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
BOOLEAN gatt_check_write_long_terminate(tGATT_TCB *p_tcb, tGATT_CLCB *p_clcb, tGATT_VALUE *p_rsp_value)
|
|
|
|
{
|
|
|
|
tGATT_VALUE *p_attr = (tGATT_VALUE *)p_clcb->p_attr_buf;
|
|
|
|
BOOLEAN exec = FALSE;
|
|
|
|
tGATT_EXEC_FLAG flag = GATT_PREP_WRITE_EXEC;
|
|
|
|
|
|
|
|
GATT_TRACE_DEBUG("gatt_check_write_long_terminate ");
|
|
|
|
/* check the first write response status */
|
2016-11-24 18:10:15 +00:00
|
|
|
if (p_rsp_value != NULL) {
|
2016-09-26 13:37:39 +00:00
|
|
|
if (p_rsp_value->handle != p_attr->handle ||
|
2016-11-24 18:10:15 +00:00
|
|
|
p_rsp_value->len != p_clcb->counter ||
|
|
|
|
memcmp(p_rsp_value->value, p_attr->value + p_attr->offset, p_rsp_value->len)) {
|
2016-09-26 13:37:39 +00:00
|
|
|
/* data does not match */
|
|
|
|
p_clcb->status = GATT_ERROR;
|
|
|
|
flag = GATT_PREP_WRITE_CANCEL;
|
|
|
|
exec = TRUE;
|
2016-11-24 18:10:15 +00:00
|
|
|
} else { /* response checking is good */
|
2016-09-26 13:37:39 +00:00
|
|
|
p_clcb->status = GATT_SUCCESS;
|
|
|
|
/* update write offset and check if end of attribute value */
|
2016-11-24 18:10:15 +00:00
|
|
|
if ((p_attr->offset += p_rsp_value->len) >= p_attr->len) {
|
2016-09-26 13:37:39 +00:00
|
|
|
exec = TRUE;
|
2016-11-24 18:10:15 +00:00
|
|
|
}
|
2016-09-26 13:37:39 +00:00
|
|
|
}
|
|
|
|
}
|
2016-11-24 18:10:15 +00:00
|
|
|
if (exec) {
|
2016-09-26 13:37:39 +00:00
|
|
|
gatt_send_queue_write_cancel (p_tcb, p_clcb, flag);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function gatt_send_prepare_write
|
|
|
|
**
|
|
|
|
** Description Send prepare write.
|
|
|
|
**
|
|
|
|
** Returns void.
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void gatt_send_prepare_write(tGATT_TCB *p_tcb, tGATT_CLCB *p_clcb)
|
|
|
|
{
|
|
|
|
tGATT_VALUE *p_attr = (tGATT_VALUE *)p_clcb->p_attr_buf;
|
|
|
|
UINT16 to_send, offset;
|
|
|
|
UINT8 rt = GATT_SUCCESS;
|
|
|
|
UINT8 type = p_clcb->op_subtype;
|
|
|
|
|
|
|
|
GATT_TRACE_DEBUG("gatt_send_prepare_write type=0x%x", type );
|
|
|
|
to_send = p_attr->len - p_attr->offset;
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
if (to_send > (p_tcb->payload_size - GATT_WRITE_LONG_HDR_SIZE)) { /* 2 = UINT16 offset bytes */
|
2016-09-26 13:37:39 +00:00
|
|
|
to_send = p_tcb->payload_size - GATT_WRITE_LONG_HDR_SIZE;
|
2016-11-24 18:10:15 +00:00
|
|
|
}
|
2016-09-26 13:37:39 +00:00
|
|
|
|
|
|
|
p_clcb->s_handle = p_attr->handle;
|
|
|
|
|
|
|
|
offset = p_attr->offset;
|
2016-11-24 18:10:15 +00:00
|
|
|
if (type == GATT_WRITE_PREPARE) {
|
2016-09-26 13:37:39 +00:00
|
|
|
offset += p_clcb->start_offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
GATT_TRACE_DEBUG("offset =0x%x len=%d", offset, to_send );
|
|
|
|
|
|
|
|
rt = gatt_send_write_msg(p_tcb,
|
|
|
|
p_clcb->clcb_idx,
|
|
|
|
GATT_REQ_PREPARE_WRITE,
|
|
|
|
p_attr->handle,
|
|
|
|
to_send, /* length */
|
|
|
|
offset, /* used as offset */
|
|
|
|
p_attr->value + p_attr->offset); /* data */
|
|
|
|
|
|
|
|
/* remember the write long attribute length */
|
|
|
|
p_clcb->counter = to_send;
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
if (rt != GATT_SUCCESS && rt != GATT_CMD_STARTED) {
|
2016-09-26 13:37:39 +00:00
|
|
|
gatt_end_operation(p_clcb, rt, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function gatt_process_find_type_value_rsp
|
|
|
|
**
|
|
|
|
** Description This function is called to handle find by type value response.
|
|
|
|
**
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void gatt_process_find_type_value_rsp (tGATT_TCB *p_tcb, tGATT_CLCB *p_clcb, UINT16 len, UINT8 *p_data)
|
|
|
|
{
|
|
|
|
tGATT_DISC_RES result;
|
|
|
|
UINT8 *p = p_data;
|
|
|
|
|
|
|
|
UNUSED(p_tcb);
|
|
|
|
|
|
|
|
GATT_TRACE_DEBUG("gatt_process_find_type_value_rsp ");
|
|
|
|
/* unexpected response */
|
2016-11-24 18:10:15 +00:00
|
|
|
if (p_clcb->operation != GATTC_OPTYPE_DISCOVERY || p_clcb->op_subtype != GATT_DISC_SRVC_BY_UUID) {
|
2016-09-26 13:37:39 +00:00
|
|
|
return;
|
2016-11-24 18:10:15 +00:00
|
|
|
}
|
2016-09-26 13:37:39 +00:00
|
|
|
|
|
|
|
memset (&result, 0, sizeof(tGATT_DISC_RES));
|
|
|
|
result.type.len = 2;
|
|
|
|
result.type.uu.uuid16 = GATT_UUID_PRI_SERVICE;
|
|
|
|
|
|
|
|
/* returns a series of handle ranges */
|
2016-11-24 18:10:15 +00:00
|
|
|
while (len >= 4) {
|
2016-09-26 13:37:39 +00:00
|
|
|
STREAM_TO_UINT16 (result.handle, p);
|
|
|
|
STREAM_TO_UINT16 (result.value.group_value.e_handle, p);
|
|
|
|
memcpy (&result.value.group_value.service_type, &p_clcb->uuid, sizeof(tBT_UUID));
|
|
|
|
|
|
|
|
len -= 4;
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
if (p_clcb->p_reg->app_cb.p_disc_res_cb) {
|
2016-09-26 13:37:39 +00:00
|
|
|
(*p_clcb->p_reg->app_cb.p_disc_res_cb)(p_clcb->conn_id, p_clcb->op_subtype, &result);
|
2016-11-24 18:10:15 +00:00
|
|
|
}
|
2016-09-26 13:37:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* last handle + 1 */
|
|
|
|
p_clcb->s_handle = (result.value.group_value.e_handle == 0) ? 0 : (result.value.group_value.e_handle + 1);
|
|
|
|
/* initiate another request */
|
|
|
|
gatt_act_discovery(p_clcb) ;
|
|
|
|
}
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function gatt_process_read_info_rsp
|
|
|
|
**
|
|
|
|
** Description This function is called to handle the read information
|
|
|
|
** response.
|
|
|
|
**
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void gatt_process_read_info_rsp(tGATT_TCB *p_tcb, tGATT_CLCB *p_clcb, UINT8 op_code,
|
|
|
|
UINT16 len, UINT8 *p_data)
|
|
|
|
{
|
|
|
|
tGATT_DISC_RES result;
|
|
|
|
UINT8 *p = p_data, uuid_len = 0, type;
|
|
|
|
|
|
|
|
UNUSED(p_tcb);
|
|
|
|
UNUSED(op_code);
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
if (len < GATT_INFO_RSP_MIN_LEN) {
|
2016-09-26 13:37:39 +00:00
|
|
|
GATT_TRACE_ERROR("invalid Info Response PDU received, discard.");
|
|
|
|
gatt_end_operation(p_clcb, GATT_INVALID_PDU, NULL);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* unexpected response */
|
2016-11-24 18:10:15 +00:00
|
|
|
if (p_clcb->operation != GATTC_OPTYPE_DISCOVERY || p_clcb->op_subtype != GATT_DISC_CHAR_DSCPT) {
|
2016-09-26 13:37:39 +00:00
|
|
|
return;
|
2016-11-24 18:10:15 +00:00
|
|
|
}
|
2016-09-26 13:37:39 +00:00
|
|
|
|
|
|
|
STREAM_TO_UINT8(type, p);
|
|
|
|
len -= 1;
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
if (type == GATT_INFO_TYPE_PAIR_16) {
|
2016-09-26 13:37:39 +00:00
|
|
|
uuid_len = LEN_UUID_16;
|
2016-11-24 18:10:15 +00:00
|
|
|
} else if (type == GATT_INFO_TYPE_PAIR_128) {
|
2016-09-26 13:37:39 +00:00
|
|
|
uuid_len = LEN_UUID_128;
|
2016-11-24 18:10:15 +00:00
|
|
|
}
|
2016-09-26 13:37:39 +00:00
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
while (len >= uuid_len + 2) {
|
2016-09-26 13:37:39 +00:00
|
|
|
STREAM_TO_UINT16 (result.handle, p);
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
if (uuid_len > 0) {
|
|
|
|
if (!gatt_parse_uuid_from_cmd(&result.type, uuid_len, &p)) {
|
2016-09-26 13:37:39 +00:00
|
|
|
break;
|
2016-11-24 18:10:15 +00:00
|
|
|
}
|
|
|
|
} else {
|
2016-09-26 13:37:39 +00:00
|
|
|
memcpy (&result.type, &p_clcb->uuid, sizeof(tBT_UUID));
|
2016-11-24 18:10:15 +00:00
|
|
|
}
|
2016-09-26 13:37:39 +00:00
|
|
|
|
|
|
|
len -= (uuid_len + 2);
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
if (p_clcb->p_reg->app_cb.p_disc_res_cb) {
|
2016-09-26 13:37:39 +00:00
|
|
|
(*p_clcb->p_reg->app_cb.p_disc_res_cb)(p_clcb->conn_id, p_clcb->op_subtype, &result);
|
2016-11-24 18:10:15 +00:00
|
|
|
}
|
2016-09-26 13:37:39 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
p_clcb->s_handle = (result.handle == 0) ? 0 : (result.handle + 1);
|
2016-09-26 13:37:39 +00:00
|
|
|
/* initiate another request */
|
|
|
|
gatt_act_discovery(p_clcb) ;
|
|
|
|
}
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function gatt_proc_disc_error_rsp
|
|
|
|
**
|
|
|
|
** Description This function process the read by type response and send another
|
|
|
|
** request if needed.
|
|
|
|
**
|
|
|
|
** Returns void.
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void gatt_proc_disc_error_rsp(tGATT_TCB *p_tcb, tGATT_CLCB *p_clcb, UINT8 opcode,
|
|
|
|
UINT16 handle, UINT8 reason)
|
|
|
|
{
|
|
|
|
tGATT_STATUS status = (tGATT_STATUS) reason;
|
|
|
|
|
|
|
|
UNUSED(p_tcb);
|
|
|
|
UNUSED(handle);
|
|
|
|
|
|
|
|
GATT_TRACE_DEBUG("gatt_proc_disc_error_rsp reason: %02x cmd_code %04x", reason, opcode);
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
switch (opcode) {
|
|
|
|
case GATT_REQ_READ_BY_GRP_TYPE:
|
|
|
|
case GATT_REQ_FIND_TYPE_VALUE:
|
|
|
|
case GATT_REQ_READ_BY_TYPE:
|
|
|
|
case GATT_REQ_FIND_INFO:
|
|
|
|
if (reason == GATT_NOT_FOUND) {
|
|
|
|
status = GATT_SUCCESS;
|
|
|
|
GATT_TRACE_DEBUG("Discovery completed");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
GATT_TRACE_ERROR("Incorrect discovery opcode %04x", opcode);
|
|
|
|
break;
|
2016-09-26 13:37:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gatt_end_operation(p_clcb, status, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function gatt_process_error_rsp
|
|
|
|
**
|
|
|
|
** Description This function is called to handle the error response
|
|
|
|
**
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void gatt_process_error_rsp(tGATT_TCB *p_tcb, tGATT_CLCB *p_clcb, UINT8 op_code,
|
|
|
|
UINT16 len, UINT8 *p_data)
|
|
|
|
{
|
2016-11-24 18:10:15 +00:00
|
|
|
UINT8 opcode, reason, * p = p_data;
|
2016-09-26 13:37:39 +00:00
|
|
|
UINT16 handle;
|
|
|
|
tGATT_VALUE *p_attr = (tGATT_VALUE *)p_clcb->p_attr_buf;
|
|
|
|
|
|
|
|
UNUSED(op_code);
|
|
|
|
UNUSED(len);
|
|
|
|
|
|
|
|
GATT_TRACE_DEBUG("gatt_process_error_rsp ");
|
|
|
|
STREAM_TO_UINT8(opcode, p);
|
|
|
|
STREAM_TO_UINT16(handle, p);
|
|
|
|
STREAM_TO_UINT8(reason, p);
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
if (p_clcb->operation == GATTC_OPTYPE_DISCOVERY) {
|
2016-09-26 13:37:39 +00:00
|
|
|
gatt_proc_disc_error_rsp(p_tcb, p_clcb, opcode, handle, reason);
|
2016-11-24 18:10:15 +00:00
|
|
|
} else {
|
2016-09-26 13:37:39 +00:00
|
|
|
if ( (p_clcb->operation == GATTC_OPTYPE_WRITE) &&
|
2016-11-24 18:10:15 +00:00
|
|
|
(p_clcb->op_subtype == GATT_WRITE) &&
|
|
|
|
(opcode == GATT_REQ_PREPARE_WRITE) &&
|
|
|
|
(p_attr) &&
|
|
|
|
(handle == p_attr->handle) ) {
|
2017-06-09 07:08:06 +00:00
|
|
|
if (reason == GATT_SUCCESS){
|
|
|
|
reason = GATT_ERROR;
|
|
|
|
}
|
2016-09-26 13:37:39 +00:00
|
|
|
p_clcb->status = reason;
|
|
|
|
gatt_send_queue_write_cancel(p_tcb, p_clcb, GATT_PREP_WRITE_CANCEL);
|
2016-11-24 18:10:15 +00:00
|
|
|
} else if ((p_clcb->operation == GATTC_OPTYPE_READ) &&
|
|
|
|
((p_clcb->op_subtype == GATT_READ_CHAR_VALUE_HDL) ||
|
|
|
|
(p_clcb->op_subtype == GATT_READ_BY_HANDLE)) &&
|
|
|
|
(opcode == GATT_REQ_READ_BLOB) &&
|
|
|
|
p_clcb->first_read_blob_after_read &&
|
|
|
|
(reason == GATT_NOT_LONG)) {
|
2016-09-26 13:37:39 +00:00
|
|
|
gatt_end_operation(p_clcb, GATT_SUCCESS, (void *)p_clcb->p_attr_buf);
|
2016-11-24 18:10:15 +00:00
|
|
|
} else {
|
2016-09-26 13:37:39 +00:00
|
|
|
gatt_end_operation(p_clcb, reason, NULL);
|
2016-11-24 18:10:15 +00:00
|
|
|
}
|
2016-09-26 13:37:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function gatt_process_prep_write_rsp
|
|
|
|
**
|
|
|
|
** Description This function is called to handle the read response
|
|
|
|
**
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void gatt_process_prep_write_rsp (tGATT_TCB *p_tcb, tGATT_CLCB *p_clcb, UINT8 op_code,
|
|
|
|
UINT16 len, UINT8 *p_data)
|
|
|
|
{
|
|
|
|
tGATT_VALUE value = {0};
|
2016-11-24 18:10:15 +00:00
|
|
|
UINT8 *p = p_data;
|
2016-09-26 13:37:39 +00:00
|
|
|
|
2018-02-12 08:34:30 +00:00
|
|
|
GATT_TRACE_DEBUG("value resp op_code = %s len = %d", gatt_dbg_op_name(op_code), len);
|
2016-09-26 13:37:39 +00:00
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
if (len < GATT_PREP_WRITE_RSP_MIN_LEN) {
|
2016-09-26 13:37:39 +00:00
|
|
|
GATT_TRACE_ERROR("illegal prepare write response length, discard");
|
|
|
|
gatt_end_operation(p_clcb, GATT_INVALID_PDU, &value);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
STREAM_TO_UINT16 (value.handle, p);
|
|
|
|
STREAM_TO_UINT16 (value.offset, p);
|
|
|
|
|
|
|
|
value.len = len - 4;
|
|
|
|
|
|
|
|
memcpy (value.value, p, value.len);
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
if (p_clcb->op_subtype == GATT_WRITE_PREPARE) {
|
2016-09-26 13:37:39 +00:00
|
|
|
p_clcb->status = GATT_SUCCESS;
|
|
|
|
/* application should verify handle offset
|
|
|
|
and value are matched or not */
|
|
|
|
|
|
|
|
gatt_end_operation(p_clcb, p_clcb->status, &value);
|
2016-11-24 18:10:15 +00:00
|
|
|
} else if (p_clcb->op_subtype == GATT_WRITE ) {
|
|
|
|
if (!gatt_check_write_long_terminate(p_tcb, p_clcb, &value)) {
|
2016-09-26 13:37:39 +00:00
|
|
|
gatt_send_prepare_write(p_tcb, p_clcb);
|
2016-11-24 18:10:15 +00:00
|
|
|
}
|
2016-09-26 13:37:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function gatt_process_notification
|
|
|
|
**
|
|
|
|
** Description This function is called to handle the handle value indication
|
|
|
|
** or handle value notification.
|
|
|
|
**
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void gatt_process_notification(tGATT_TCB *p_tcb, UINT8 op_code,
|
|
|
|
UINT16 len, UINT8 *p_data)
|
|
|
|
{
|
|
|
|
tGATT_VALUE value = {0};
|
|
|
|
tGATT_REG *p_reg;
|
|
|
|
UINT16 conn_id;
|
|
|
|
tGATT_STATUS encrypt_status;
|
2016-11-24 18:10:15 +00:00
|
|
|
UINT8 *p = p_data, i,
|
|
|
|
event = (op_code == GATT_HANDLE_VALUE_NOTIF) ? GATTC_OPTYPE_NOTIFICATION : GATTC_OPTYPE_INDICATION;
|
2016-09-26 13:37:39 +00:00
|
|
|
|
|
|
|
GATT_TRACE_DEBUG("gatt_process_notification ");
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
if (len < GATT_NOTIFICATION_MIN_LEN) {
|
2016-09-26 13:37:39 +00:00
|
|
|
GATT_TRACE_ERROR("illegal notification PDU length, discard");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
STREAM_TO_UINT16 (value.handle, p);
|
|
|
|
value.len = len - 2;
|
|
|
|
memcpy (value.value, p, value.len);
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
if (!GATT_HANDLE_IS_VALID(value.handle)) {
|
2016-09-26 13:37:39 +00:00
|
|
|
/* illegal handle, send ack now */
|
2016-11-24 18:10:15 +00:00
|
|
|
if (op_code == GATT_HANDLE_VALUE_IND) {
|
2016-09-26 13:37:39 +00:00
|
|
|
attp_send_cl_msg(p_tcb, 0, GATT_HANDLE_VALUE_CONF, NULL);
|
2016-11-24 18:10:15 +00:00
|
|
|
}
|
2016-09-26 13:37:39 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
if (event == GATTC_OPTYPE_INDICATION) {
|
|
|
|
if (p_tcb->ind_count) {
|
2016-09-26 13:37:39 +00:00
|
|
|
/* this is an error case that receiving an indication but we
|
|
|
|
still has an indication not being acked yet.
|
|
|
|
For now, just log the error reset the counter.
|
|
|
|
Later we need to disconnect the link unconditionally.
|
|
|
|
*/
|
|
|
|
GATT_TRACE_ERROR("gatt_process_notification rcv Ind. but ind_count=%d (will reset ind_count)", p_tcb->ind_count);
|
|
|
|
}
|
|
|
|
p_tcb->ind_count = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* should notify all registered client with the handle value notificaion/indication
|
|
|
|
Note: need to do the indication count and start timer first then do callback
|
|
|
|
*/
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
for (i = 0, p_reg = gatt_cb.cl_rcb; i < GATT_MAX_APPS; i++, p_reg++) {
|
|
|
|
if (p_reg->in_use && p_reg->app_cb.p_cmpl_cb && (event == GATTC_OPTYPE_INDICATION)) {
|
2016-09-26 13:37:39 +00:00
|
|
|
p_tcb->ind_count++;
|
2016-11-24 18:10:15 +00:00
|
|
|
}
|
2016-09-26 13:37:39 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
if (event == GATTC_OPTYPE_INDICATION) {
|
2016-09-26 13:37:39 +00:00
|
|
|
/* start a timer for app confirmation */
|
2016-11-24 18:10:15 +00:00
|
|
|
if (p_tcb->ind_count > 0) {
|
2016-09-26 13:37:39 +00:00
|
|
|
gatt_start_ind_ack_timer(p_tcb);
|
2016-11-24 18:10:15 +00:00
|
|
|
} else { /* no app to indicate, or invalid handle */
|
2016-09-26 13:37:39 +00:00
|
|
|
attp_send_cl_msg(p_tcb, 0, GATT_HANDLE_VALUE_CONF, NULL);
|
2016-11-24 18:10:15 +00:00
|
|
|
}
|
2016-09-26 13:37:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
encrypt_status = gatt_get_link_encrypt_status(p_tcb);
|
2016-11-24 18:10:15 +00:00
|
|
|
for (i = 0, p_reg = gatt_cb.cl_rcb; i < GATT_MAX_APPS; i++, p_reg++) {
|
|
|
|
if (p_reg->in_use && p_reg->app_cb.p_cmpl_cb) {
|
2016-09-26 13:37:39 +00:00
|
|
|
conn_id = GATT_CREATE_CONN_ID(p_tcb->tcb_idx, p_reg->gatt_if);
|
|
|
|
(*p_reg->app_cb.p_cmpl_cb) (conn_id, event, encrypt_status, (tGATT_CL_COMPLETE *)&value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function gatt_process_read_by_type_rsp
|
|
|
|
**
|
|
|
|
** Description This function is called to handle the read by type response.
|
|
|
|
** read by type can be used for discovery, or read by type or
|
|
|
|
** read characteristic value.
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void gatt_process_read_by_type_rsp (tGATT_TCB *p_tcb, tGATT_CLCB *p_clcb, UINT8 op_code,
|
|
|
|
UINT16 len, UINT8 *p_data)
|
|
|
|
{
|
|
|
|
tGATT_DISC_RES result;
|
|
|
|
tGATT_DISC_VALUE record_value;
|
|
|
|
UINT8 *p = p_data, value_len, handle_len = 2;
|
|
|
|
UINT16 handle = 0;
|
|
|
|
|
|
|
|
/* discovery procedure and no callback function registered */
|
2016-11-24 18:10:15 +00:00
|
|
|
if (((!p_clcb->p_reg) || (!p_clcb->p_reg->app_cb.p_disc_res_cb)) && (p_clcb->operation == GATTC_OPTYPE_DISCOVERY)) {
|
2016-09-26 13:37:39 +00:00
|
|
|
return;
|
2016-11-24 18:10:15 +00:00
|
|
|
}
|
2016-09-26 13:37:39 +00:00
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
if (len < GATT_READ_BY_TYPE_RSP_MIN_LEN) {
|
2016-09-26 13:37:39 +00:00
|
|
|
GATT_TRACE_ERROR("Illegal ReadByType/ReadByGroupType Response length, discard");
|
|
|
|
gatt_end_operation(p_clcb, GATT_INVALID_PDU, NULL);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
STREAM_TO_UINT8(value_len, p);
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
if ((value_len > (p_tcb->payload_size - 2)) || (value_len > (len - 1)) ) {
|
2016-09-26 13:37:39 +00:00
|
|
|
/* this is an error case that server's response containing a value length which is larger than MTU-2
|
|
|
|
or value_len > message total length -1 */
|
|
|
|
GATT_TRACE_ERROR("gatt_process_read_by_type_rsp: Discard response op_code=%d vale_len=%d > (MTU-2=%d or msg_len-1=%d)",
|
2016-11-24 18:10:15 +00:00
|
|
|
op_code, value_len, (p_tcb->payload_size - 2), (len - 1));
|
2016-09-26 13:37:39 +00:00
|
|
|
gatt_end_operation(p_clcb, GATT_ERROR, NULL);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
if (op_code == GATT_RSP_READ_BY_GRP_TYPE) {
|
2016-09-26 13:37:39 +00:00
|
|
|
handle_len = 4;
|
2016-11-24 18:10:15 +00:00
|
|
|
}
|
2016-09-26 13:37:39 +00:00
|
|
|
|
|
|
|
value_len -= handle_len; /* substract the handle pairs bytes */
|
|
|
|
len -= 1;
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
while (len >= (handle_len + value_len)) {
|
2016-09-26 13:37:39 +00:00
|
|
|
STREAM_TO_UINT16(handle, p);
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
if (!GATT_HANDLE_IS_VALID(handle)) {
|
2016-09-26 13:37:39 +00:00
|
|
|
gatt_end_operation(p_clcb, GATT_INVALID_HANDLE, NULL);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(&result, 0, sizeof(tGATT_DISC_RES));
|
|
|
|
memset(&record_value, 0, sizeof(tGATT_DISC_VALUE));
|
|
|
|
|
|
|
|
result.handle = handle;
|
|
|
|
result.type.len = 2;
|
|
|
|
result.type.uu.uuid16 = disc_type_to_uuid[p_clcb->op_subtype];
|
|
|
|
|
|
|
|
/* discover all services */
|
|
|
|
if (p_clcb->operation == GATTC_OPTYPE_DISCOVERY &&
|
2016-11-24 18:10:15 +00:00
|
|
|
p_clcb->op_subtype == GATT_DISC_SRVC_ALL &&
|
|
|
|
op_code == GATT_RSP_READ_BY_GRP_TYPE) {
|
2016-09-26 13:37:39 +00:00
|
|
|
STREAM_TO_UINT16(handle, p);
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
if (!GATT_HANDLE_IS_VALID(handle)) {
|
2016-09-26 13:37:39 +00:00
|
|
|
gatt_end_operation(p_clcb, GATT_INVALID_HANDLE, NULL);
|
|
|
|
return;
|
2016-11-24 18:10:15 +00:00
|
|
|
} else {
|
2016-09-26 13:37:39 +00:00
|
|
|
record_value.group_value.e_handle = handle;
|
2016-11-24 18:10:15 +00:00
|
|
|
if (!gatt_parse_uuid_from_cmd(&record_value.group_value.service_type, value_len, &p)) {
|
2016-09-26 13:37:39 +00:00
|
|
|
GATT_TRACE_ERROR("discover all service response parsing failure");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* discover included service */
|
2016-11-24 18:10:15 +00:00
|
|
|
else if (p_clcb->operation == GATTC_OPTYPE_DISCOVERY && p_clcb->op_subtype == GATT_DISC_INC_SRVC) {
|
2016-09-26 13:37:39 +00:00
|
|
|
STREAM_TO_UINT16(record_value.incl_service.s_handle, p);
|
|
|
|
STREAM_TO_UINT16(record_value.incl_service.e_handle, p);
|
|
|
|
|
|
|
|
if (!GATT_HANDLE_IS_VALID(record_value.incl_service.s_handle) ||
|
2016-11-24 18:10:15 +00:00
|
|
|
!GATT_HANDLE_IS_VALID(record_value.incl_service.e_handle)) {
|
2016-09-26 13:37:39 +00:00
|
|
|
gatt_end_operation(p_clcb, GATT_INVALID_HANDLE, NULL);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
if (value_len == 6) {
|
2016-09-26 13:37:39 +00:00
|
|
|
STREAM_TO_UINT16(record_value.incl_service.service_type.uu.uuid16, p);
|
|
|
|
record_value.incl_service.service_type.len = LEN_UUID_16;
|
2016-11-24 18:10:15 +00:00
|
|
|
} else if (value_len == 4) {
|
2016-09-26 13:37:39 +00:00
|
|
|
p_clcb->s_handle = record_value.incl_service.s_handle;
|
|
|
|
p_clcb->read_uuid128.wait_for_read_rsp = TRUE;
|
|
|
|
p_clcb->read_uuid128.next_disc_start_hdl = handle + 1;
|
|
|
|
memcpy(&p_clcb->read_uuid128.result, &result, sizeof(result));
|
|
|
|
memcpy(&p_clcb->read_uuid128.result.value, &record_value, sizeof (result.value));
|
|
|
|
p_clcb->op_subtype |= 0x90;
|
|
|
|
gatt_act_read(p_clcb, 0);
|
|
|
|
return;
|
2016-11-24 18:10:15 +00:00
|
|
|
} else {
|
|
|
|
GATT_TRACE_ERROR("gatt_process_read_by_type_rsp INCL_SRVC failed with invalid data value_len=%d", value_len);
|
|
|
|
gatt_end_operation(p_clcb, GATT_INVALID_PDU, (void *)p);
|
|
|
|
return;
|
2016-09-26 13:37:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* read by type */
|
2016-11-24 18:10:15 +00:00
|
|
|
else if (p_clcb->operation == GATTC_OPTYPE_READ && p_clcb->op_subtype == GATT_READ_BY_TYPE) {
|
2016-09-26 13:37:39 +00:00
|
|
|
p_clcb->counter = len - 2;
|
|
|
|
p_clcb->s_handle = handle;
|
2016-11-24 18:10:15 +00:00
|
|
|
if ( p_clcb->counter == (p_clcb->p_tcb->payload_size - 4)) {
|
2016-09-26 13:37:39 +00:00
|
|
|
p_clcb->op_subtype = GATT_READ_BY_HANDLE;
|
2016-11-24 18:10:15 +00:00
|
|
|
if (!p_clcb->p_attr_buf) {
|
2017-08-17 13:13:45 +00:00
|
|
|
p_clcb->p_attr_buf = (UINT8 *)osi_malloc(GATT_MAX_ATTR_LEN);
|
2016-11-24 18:10:15 +00:00
|
|
|
}
|
|
|
|
if (p_clcb->p_attr_buf && p_clcb->counter <= GATT_MAX_ATTR_LEN) {
|
2016-09-26 13:37:39 +00:00
|
|
|
memcpy(p_clcb->p_attr_buf, p, p_clcb->counter);
|
|
|
|
gatt_act_read(p_clcb, p_clcb->counter);
|
2016-11-24 18:10:15 +00:00
|
|
|
} else {
|
|
|
|
gatt_end_operation(p_clcb, GATT_INTERNAL_ERROR, (void *)p);
|
2016-09-26 13:37:39 +00:00
|
|
|
}
|
2016-11-24 18:10:15 +00:00
|
|
|
} else {
|
|
|
|
gatt_end_operation(p_clcb, GATT_SUCCESS, (void *)p);
|
2016-09-26 13:37:39 +00:00
|
|
|
}
|
|
|
|
return;
|
2016-11-24 18:10:15 +00:00
|
|
|
} else { /* discover characterisitic */
|
2016-09-26 13:37:39 +00:00
|
|
|
STREAM_TO_UINT8 (record_value.dclr_value.char_prop, p);
|
|
|
|
STREAM_TO_UINT16(record_value.dclr_value.val_handle, p);
|
2016-11-24 18:10:15 +00:00
|
|
|
if (!GATT_HANDLE_IS_VALID(record_value.dclr_value.val_handle)) {
|
2016-09-26 13:37:39 +00:00
|
|
|
gatt_end_operation(p_clcb, GATT_INVALID_HANDLE, NULL);
|
|
|
|
return;
|
|
|
|
}
|
2016-11-24 18:10:15 +00:00
|
|
|
if (!gatt_parse_uuid_from_cmd(&record_value.dclr_value.char_uuid, (UINT16)(value_len - 3), &p)) {
|
2016-09-26 13:37:39 +00:00
|
|
|
gatt_end_operation(p_clcb, GATT_SUCCESS, NULL);
|
|
|
|
/* invalid format, and skip the result */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* UUID not matching */
|
2016-11-24 18:10:15 +00:00
|
|
|
if (!gatt_uuid_compare(record_value.dclr_value.char_uuid, p_clcb->uuid)) {
|
2016-09-26 13:37:39 +00:00
|
|
|
len -= (value_len + 2);
|
|
|
|
continue; /* skip the result, and look for next one */
|
2016-11-24 18:10:15 +00:00
|
|
|
} else if (p_clcb->operation == GATTC_OPTYPE_READ)
|
|
|
|
/* UUID match for read characteristic value */
|
2016-09-26 13:37:39 +00:00
|
|
|
{
|
|
|
|
/* only read the first matching UUID characteristic value, and
|
|
|
|
discard the rest results */
|
|
|
|
p_clcb->s_handle = record_value.dclr_value.val_handle;
|
|
|
|
p_clcb->op_subtype |= 0x80;
|
|
|
|
gatt_act_read(p_clcb, 0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
len -= (value_len + handle_len);
|
|
|
|
|
|
|
|
/* result is (handle, 16bits UUID) pairs */
|
|
|
|
memcpy (&result.value, &record_value, sizeof (result.value));
|
|
|
|
|
|
|
|
/* send callback if is discover procedure */
|
2016-11-24 18:10:15 +00:00
|
|
|
if (p_clcb->operation == GATTC_OPTYPE_DISCOVERY && p_clcb->p_reg->app_cb.p_disc_res_cb) {
|
2016-09-26 13:37:39 +00:00
|
|
|
(*p_clcb->p_reg->app_cb.p_disc_res_cb)(p_clcb->conn_id, p_clcb->op_subtype, &result);
|
2016-11-24 18:10:15 +00:00
|
|
|
}
|
2016-09-26 13:37:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
p_clcb->s_handle = (handle == 0) ? 0 : (handle + 1);
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
if (p_clcb->operation == GATTC_OPTYPE_DISCOVERY) {
|
2016-09-26 13:37:39 +00:00
|
|
|
/* initiate another request */
|
|
|
|
gatt_act_discovery(p_clcb) ;
|
2016-11-24 18:10:15 +00:00
|
|
|
} else { /* read characteristic value */
|
2016-09-26 13:37:39 +00:00
|
|
|
gatt_act_read(p_clcb, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function gatt_process_read_rsp
|
|
|
|
**
|
|
|
|
** Description This function is called to handle the read BLOB response
|
|
|
|
**
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void gatt_process_read_rsp(tGATT_TCB *p_tcb, tGATT_CLCB *p_clcb, UINT8 op_code,
|
|
|
|
UINT16 len, UINT8 *p_data)
|
|
|
|
{
|
|
|
|
UINT16 offset = p_clcb->counter;
|
2016-11-24 18:10:15 +00:00
|
|
|
UINT8 *p = p_data;
|
2016-09-26 13:37:39 +00:00
|
|
|
|
|
|
|
UNUSED(op_code);
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
if (p_clcb->operation == GATTC_OPTYPE_READ) {
|
|
|
|
if (p_clcb->op_subtype != GATT_READ_BY_HANDLE) {
|
2016-09-26 13:37:39 +00:00
|
|
|
p_clcb->counter = len;
|
|
|
|
gatt_end_operation(p_clcb, GATT_SUCCESS, (void *)p);
|
2016-11-24 18:10:15 +00:00
|
|
|
} else {
|
2016-09-26 13:37:39 +00:00
|
|
|
|
|
|
|
/* allocate GKI buffer holding up long attribute value */
|
2016-11-24 18:10:15 +00:00
|
|
|
if (!p_clcb->p_attr_buf) {
|
2017-08-17 13:13:45 +00:00
|
|
|
p_clcb->p_attr_buf = (UINT8 *)osi_malloc(GATT_MAX_ATTR_LEN);
|
2016-11-24 18:10:15 +00:00
|
|
|
}
|
2016-09-26 13:37:39 +00:00
|
|
|
|
|
|
|
/* copy attrobute value into cb buffer */
|
2016-11-24 18:10:15 +00:00
|
|
|
if (p_clcb->p_attr_buf && offset < GATT_MAX_ATTR_LEN) {
|
|
|
|
if ((len + offset) > GATT_MAX_ATTR_LEN) {
|
2016-09-26 13:37:39 +00:00
|
|
|
len = GATT_MAX_ATTR_LEN - offset;
|
2016-11-24 18:10:15 +00:00
|
|
|
}
|
2016-09-26 13:37:39 +00:00
|
|
|
|
|
|
|
p_clcb->counter += len;
|
|
|
|
|
|
|
|
memcpy(p_clcb->p_attr_buf + offset, p, len);
|
|
|
|
|
|
|
|
/* send next request if needed */
|
|
|
|
|
|
|
|
if (len == (p_tcb->payload_size - 1) && /* full packet for read or read blob rsp */
|
2016-11-24 18:10:15 +00:00
|
|
|
len + offset < GATT_MAX_ATTR_LEN) {
|
2016-09-26 13:37:39 +00:00
|
|
|
GATT_TRACE_DEBUG("full pkt issue read blob for remianing bytes old offset=%d len=%d new offset=%d",
|
2016-11-24 18:10:15 +00:00
|
|
|
offset, len, p_clcb->counter);
|
2016-09-26 13:37:39 +00:00
|
|
|
gatt_act_read(p_clcb, p_clcb->counter);
|
2016-11-24 18:10:15 +00:00
|
|
|
} else { /* end of request, send callback */
|
2016-09-26 13:37:39 +00:00
|
|
|
gatt_end_operation(p_clcb, GATT_SUCCESS, (void *)p_clcb->p_attr_buf);
|
|
|
|
}
|
2016-11-24 18:10:15 +00:00
|
|
|
} else { /* exception, should not happen */
|
2016-12-07 06:11:40 +00:00
|
|
|
GATT_TRACE_ERROR("attr offset = %d p_attr_buf = %p ", offset, p_clcb->p_attr_buf);
|
2016-09-26 13:37:39 +00:00
|
|
|
gatt_end_operation(p_clcb, GATT_NO_RESOURCES, (void *)p_clcb->p_attr_buf);
|
|
|
|
}
|
|
|
|
}
|
2016-11-24 18:10:15 +00:00
|
|
|
} else {
|
2016-09-26 13:37:39 +00:00
|
|
|
if (p_clcb->operation == GATTC_OPTYPE_DISCOVERY &&
|
2016-11-24 18:10:15 +00:00
|
|
|
p_clcb->op_subtype == GATT_DISC_INC_SRVC &&
|
|
|
|
p_clcb->read_uuid128.wait_for_read_rsp ) {
|
2016-09-26 13:37:39 +00:00
|
|
|
p_clcb->s_handle = p_clcb->read_uuid128.next_disc_start_hdl;
|
|
|
|
p_clcb->read_uuid128.wait_for_read_rsp = FALSE;
|
2016-11-24 18:10:15 +00:00
|
|
|
if (len == LEN_UUID_128) {
|
2016-09-26 13:37:39 +00:00
|
|
|
|
|
|
|
memcpy(p_clcb->read_uuid128.result.value.incl_service.service_type.uu.uuid128, p, len);
|
|
|
|
p_clcb->read_uuid128.result.value.incl_service.service_type.len = LEN_UUID_128;
|
2016-11-24 18:10:15 +00:00
|
|
|
if ( p_clcb->p_reg->app_cb.p_disc_res_cb) {
|
2016-09-26 13:37:39 +00:00
|
|
|
(*p_clcb->p_reg->app_cb.p_disc_res_cb)(p_clcb->conn_id, p_clcb->op_subtype, &p_clcb->read_uuid128.result);
|
2016-11-24 18:10:15 +00:00
|
|
|
}
|
2016-09-26 13:37:39 +00:00
|
|
|
gatt_act_discovery(p_clcb) ;
|
2016-11-24 18:10:15 +00:00
|
|
|
} else {
|
2016-09-26 13:37:39 +00:00
|
|
|
gatt_end_operation(p_clcb, GATT_INVALID_PDU, (void *)p);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function gatt_process_handle_rsp
|
|
|
|
**
|
|
|
|
** Description This function is called to handle the write response
|
|
|
|
**
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void gatt_process_handle_rsp(tGATT_CLCB *p_clcb)
|
|
|
|
{
|
|
|
|
gatt_end_operation(p_clcb, GATT_SUCCESS, NULL);
|
|
|
|
}
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function gatt_process_mtu_rsp
|
|
|
|
**
|
|
|
|
** Description This function is called to process the configure MTU response.
|
|
|
|
**
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void gatt_process_mtu_rsp(tGATT_TCB *p_tcb, tGATT_CLCB *p_clcb, UINT16 len, UINT8 *p_data)
|
|
|
|
{
|
|
|
|
UINT16 mtu;
|
|
|
|
tGATT_STATUS status = GATT_SUCCESS;
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
if (len < GATT_MTU_RSP_MIN_LEN) {
|
2016-09-26 13:37:39 +00:00
|
|
|
GATT_TRACE_ERROR("invalid MTU response PDU received, discard.");
|
|
|
|
status = GATT_INVALID_PDU;
|
2016-11-24 18:10:15 +00:00
|
|
|
} else {
|
|
|
|
STREAM_TO_UINT16(mtu, p_data);
|
2016-09-26 13:37:39 +00:00
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
if (mtu < p_tcb->payload_size && mtu >= GATT_DEF_BLE_MTU_SIZE) {
|
|
|
|
p_tcb->payload_size = mtu;
|
|
|
|
}
|
2016-09-26 13:37:39 +00:00
|
|
|
}
|
2017-12-07 07:00:06 +00:00
|
|
|
/* host will set packet data length to 251 automatically if remote device support set packet data length,
|
|
|
|
so l2cble_set_fixed_channel_tx_data_length() is not necessary.
|
|
|
|
l2cble_set_fixed_channel_tx_data_length(p_tcb->peer_bda, L2CAP_ATT_CID, p_tcb->payload_size);
|
|
|
|
*/
|
2016-09-26 13:37:39 +00:00
|
|
|
gatt_end_operation(p_clcb, status, NULL);
|
|
|
|
}
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function gatt_cmd_to_rsp_code
|
|
|
|
**
|
|
|
|
** Description The function convert a ATT command op code into the corresponding
|
|
|
|
** response code assume no error occurs.
|
|
|
|
**
|
|
|
|
** Returns response code.
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
UINT8 gatt_cmd_to_rsp_code (UINT8 cmd_code)
|
|
|
|
{
|
|
|
|
UINT8 rsp_code = 0;
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
if (cmd_code > 1 && cmd_code != GATT_CMD_WRITE) {
|
2016-09-26 13:37:39 +00:00
|
|
|
rsp_code = cmd_code + 1;
|
|
|
|
}
|
|
|
|
return rsp_code;
|
|
|
|
}
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function gatt_cl_send_next_cmd_inq
|
|
|
|
**
|
|
|
|
** Description Find next command in queue and sent to server
|
|
|
|
**
|
|
|
|
** Returns TRUE if command sent, otherwise FALSE.
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
BOOLEAN gatt_cl_send_next_cmd_inq(tGATT_TCB *p_tcb)
|
|
|
|
{
|
|
|
|
tGATT_CMD_Q *p_cmd = &p_tcb->cl_cmd_q[p_tcb->pending_cl_req];
|
|
|
|
BOOLEAN sent = FALSE;
|
|
|
|
UINT8 rsp_code;
|
|
|
|
tGATT_CLCB *p_clcb = NULL;
|
|
|
|
tGATT_STATUS att_ret = GATT_SUCCESS;
|
|
|
|
|
|
|
|
while (!sent &&
|
2016-11-24 18:10:15 +00:00
|
|
|
p_tcb->pending_cl_req != p_tcb->next_slot_inq &&
|
|
|
|
p_cmd->to_send && p_cmd->p_cmd != NULL) {
|
2016-09-26 13:37:39 +00:00
|
|
|
att_ret = attp_send_msg_to_l2cap(p_tcb, p_cmd->p_cmd);
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
if (att_ret == GATT_SUCCESS || att_ret == GATT_CONGESTED) {
|
2016-09-26 13:37:39 +00:00
|
|
|
sent = TRUE;
|
|
|
|
p_cmd->to_send = FALSE;
|
2018-08-14 12:35:43 +00:00
|
|
|
if(p_cmd->p_cmd) {
|
|
|
|
osi_free(p_cmd->p_cmd);
|
|
|
|
p_cmd->p_cmd = NULL;
|
|
|
|
}
|
2016-09-26 13:37:39 +00:00
|
|
|
|
|
|
|
/* dequeue the request if is write command or sign write */
|
2016-11-24 18:10:15 +00:00
|
|
|
if (p_cmd->op_code != GATT_CMD_WRITE && p_cmd->op_code != GATT_SIGN_CMD_WRITE) {
|
2016-09-26 13:37:39 +00:00
|
|
|
gatt_start_rsp_timer (p_cmd->clcb_idx);
|
2016-11-24 18:10:15 +00:00
|
|
|
} else {
|
2016-09-26 13:37:39 +00:00
|
|
|
p_clcb = gatt_cmd_dequeue(p_tcb, &rsp_code);
|
|
|
|
|
|
|
|
/* if no ack needed, keep sending */
|
2016-11-24 18:10:15 +00:00
|
|
|
if (att_ret == GATT_SUCCESS) {
|
2016-09-26 13:37:39 +00:00
|
|
|
sent = FALSE;
|
2016-11-24 18:10:15 +00:00
|
|
|
}
|
2016-09-26 13:37:39 +00:00
|
|
|
|
|
|
|
p_cmd = &p_tcb->cl_cmd_q[p_tcb->pending_cl_req];
|
|
|
|
/* send command complete callback here */
|
|
|
|
gatt_end_operation(p_clcb, att_ret, NULL);
|
|
|
|
}
|
2016-11-24 18:10:15 +00:00
|
|
|
} else {
|
2016-09-26 13:37:39 +00:00
|
|
|
GATT_TRACE_ERROR("gatt_cl_send_next_cmd_inq: L2CAP sent error");
|
|
|
|
|
|
|
|
memset(p_cmd, 0, sizeof(tGATT_CMD_Q));
|
|
|
|
p_tcb->pending_cl_req ++;
|
|
|
|
p_cmd = &p_tcb->cl_cmd_q[p_tcb->pending_cl_req];
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
return sent;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function gatt_client_handle_server_rsp
|
|
|
|
**
|
|
|
|
** Description This function is called to handle the server response to
|
|
|
|
** client.
|
|
|
|
**
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void gatt_client_handle_server_rsp (tGATT_TCB *p_tcb, UINT8 op_code,
|
|
|
|
UINT16 len, UINT8 *p_data)
|
|
|
|
{
|
|
|
|
tGATT_CLCB *p_clcb = NULL;
|
|
|
|
UINT8 rsp_code;
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
if (op_code != GATT_HANDLE_VALUE_IND && op_code != GATT_HANDLE_VALUE_NOTIF) {
|
2016-09-26 13:37:39 +00:00
|
|
|
p_clcb = gatt_cmd_dequeue(p_tcb, &rsp_code);
|
|
|
|
|
|
|
|
rsp_code = gatt_cmd_to_rsp_code(rsp_code);
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
if (p_clcb == NULL || (rsp_code != op_code && op_code != GATT_RSP_ERROR)) {
|
2016-09-26 13:37:39 +00:00
|
|
|
GATT_TRACE_WARNING ("ATT - Ignore wrong response. Receives (%02x) \
|
|
|
|
Request(%02x) Ignored", op_code, rsp_code);
|
|
|
|
|
|
|
|
return;
|
2016-11-24 18:10:15 +00:00
|
|
|
} else {
|
2016-09-26 13:37:39 +00:00
|
|
|
btu_stop_timer (&p_clcb->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 */
|
2016-11-24 18:10:15 +00:00
|
|
|
if (len >= p_tcb->payload_size) {
|
2016-09-26 13:37:39 +00:00
|
|
|
GATT_TRACE_ERROR("invalid response/indicate pkt size: %d, PDU size: %d", len + 1, p_tcb->payload_size);
|
|
|
|
if (op_code != GATT_HANDLE_VALUE_NOTIF &&
|
2016-11-24 18:10:15 +00:00
|
|
|
op_code != GATT_HANDLE_VALUE_IND) {
|
2016-09-26 13:37:39 +00:00
|
|
|
gatt_end_operation(p_clcb, GATT_ERROR, NULL);
|
2016-11-24 18:10:15 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
switch (op_code) {
|
|
|
|
case GATT_RSP_ERROR:
|
|
|
|
gatt_process_error_rsp(p_tcb, p_clcb, op_code, len, p_data);
|
|
|
|
break;
|
2016-09-26 13:37:39 +00:00
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
case GATT_RSP_MTU: /* 2 bytes mtu */
|
|
|
|
gatt_process_mtu_rsp(p_tcb, p_clcb, len , p_data);
|
|
|
|
break;
|
2016-09-26 13:37:39 +00:00
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
case GATT_RSP_FIND_INFO:
|
|
|
|
gatt_process_read_info_rsp(p_tcb, p_clcb, op_code, len, p_data);
|
|
|
|
break;
|
2016-09-26 13:37:39 +00:00
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
case GATT_RSP_READ_BY_TYPE:
|
|
|
|
case GATT_RSP_READ_BY_GRP_TYPE:
|
|
|
|
gatt_process_read_by_type_rsp(p_tcb, p_clcb, op_code, len, p_data);
|
|
|
|
break;
|
2016-09-26 13:37:39 +00:00
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
case GATT_RSP_READ:
|
|
|
|
case GATT_RSP_READ_BLOB:
|
|
|
|
case GATT_RSP_READ_MULTI:
|
|
|
|
gatt_process_read_rsp(p_tcb, p_clcb, op_code, len, p_data);
|
|
|
|
break;
|
2016-09-26 13:37:39 +00:00
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
case GATT_RSP_FIND_TYPE_VALUE: /* disc service with UUID */
|
|
|
|
gatt_process_find_type_value_rsp(p_tcb, p_clcb, len, p_data);
|
|
|
|
break;
|
2016-09-26 13:37:39 +00:00
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
case GATT_RSP_WRITE:
|
|
|
|
gatt_process_handle_rsp(p_clcb);
|
|
|
|
break;
|
2016-09-26 13:37:39 +00:00
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
case GATT_RSP_PREPARE_WRITE:
|
|
|
|
gatt_process_prep_write_rsp(p_tcb, p_clcb, op_code, len, p_data);
|
|
|
|
break;
|
2016-09-26 13:37:39 +00:00
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
case GATT_RSP_EXEC_WRITE:
|
|
|
|
gatt_end_operation(p_clcb, p_clcb->status, NULL);
|
|
|
|
break;
|
2016-09-26 13:37:39 +00:00
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
case GATT_HANDLE_VALUE_NOTIF:
|
|
|
|
case GATT_HANDLE_VALUE_IND:
|
|
|
|
gatt_process_notification(p_tcb, op_code, len, p_data);
|
|
|
|
break;
|
2016-09-26 13:37:39 +00:00
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
default:
|
|
|
|
GATT_TRACE_ERROR("Unknown opcode = %d", op_code);
|
|
|
|
break;
|
2016-09-26 13:37:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
if (op_code != GATT_HANDLE_VALUE_IND && op_code != GATT_HANDLE_VALUE_NOTIF) {
|
2016-09-26 13:37:39 +00:00
|
|
|
gatt_cl_send_next_cmd_inq(p_tcb);
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-04-20 11:18:05 +00:00
|
|
|
#endif /* BLE_INCLUDED == TRUE && GATTC_INCLUDED == TRUE */
|