15738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/******************************************************************************
25738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project *
35738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project *  Copyright (C) 1999-2012 Broadcom Corporation
45738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project *
55738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project *  Licensed under the Apache License, Version 2.0 (the "License");
65738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project *  you may not use this file except in compliance with the License.
75738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project *  You may obtain a copy of the License at:
85738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project *
95738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project *  http://www.apache.org/licenses/LICENSE-2.0
105738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project *
115738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project *  Unless required by applicable law or agreed to in writing, software
125738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project *  distributed under the License is distributed on an "AS IS" BASIS,
135738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
145738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project *  See the License for the specific language governing permissions and
155738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project *  limitations under the License.
165738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project *
175738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project ******************************************************************************/
185738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
195738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/******************************************************************************
205738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project *
215738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project *  this file contains the main GATT client functions
225738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project *
235738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project ******************************************************************************/
245738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
255738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project#include "bt_target.h"
265738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
275738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project#if BLE_INCLUDED == TRUE
285738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
295738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project#include <string.h>
307fa4fba6f59f97df00aff07dbe8fb21b114b3c2cGanesh Ganapathi Batta#include "bt_utils.h"
315738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project#include "gki.h"
325738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project#include "gatt_int.h"
33636d6714a4c08dd99d2147dcce05dc3892e804b4Priti Aghera#include "l2c_int.h"
345738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
355738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project#define GATT_WRITE_LONG_HDR_SIZE    5 /* 1 opcode + 2 handle + 2 offset */
365738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project#define GATT_READ_CHAR_VALUE_HDL    (GATT_READ_CHAR_VALUE | 0x80)
375738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project#define GATT_READ_INC_SRV_UUID128   (GATT_DISC_INC_SRVC   | 0x90)
385738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
39ccf9c15f52eea21858d994601d71308e84c7c859Andre Eisenbach#define GATT_PREP_WRITE_RSP_MIN_LEN 4
40ccf9c15f52eea21858d994601d71308e84c7c859Andre Eisenbach#define GATT_NOTIFICATION_MIN_LEN 2
41ccf9c15f52eea21858d994601d71308e84c7c859Andre Eisenbach#define GATT_WRITE_RSP_MIN_LEN  2
42ccf9c15f52eea21858d994601d71308e84c7c859Andre Eisenbach#define GATT_INFO_RSP_MIN_LEN   1
43ccf9c15f52eea21858d994601d71308e84c7c859Andre Eisenbach#define GATT_MTU_RSP_MIN_LEN    2
44ccf9c15f52eea21858d994601d71308e84c7c859Andre Eisenbach#define GATT_READ_BY_TYPE_RSP_MIN_LEN    1
45ccf9c15f52eea21858d994601d71308e84c7c859Andre Eisenbach
465738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/********************************************************************************
475738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**                       G L O B A L      G A T T       D A T A                 *
485738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*********************************************************************************/
495738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectvoid gatt_send_prepare_write(tGATT_TCB  *p_tcb, tGATT_CLCB *p_clcb);
505738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
515738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source ProjectUINT8   disc_type_to_att_opcode[GATT_DISC_MAX] =
525738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{
535738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    0,
545738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    GATT_REQ_READ_BY_GRP_TYPE,     /*  GATT_DISC_SRVC_ALL = 1, */
555738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    GATT_REQ_FIND_TYPE_VALUE,      /*  GATT_DISC_SRVC_BY_UUID,  */
565738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    GATT_REQ_READ_BY_TYPE,         /*  GATT_DISC_INC_SRVC,      */
575738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    GATT_REQ_READ_BY_TYPE,         /*  GATT_DISC_CHAR,          */
585738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    GATT_REQ_FIND_INFO             /*  GATT_DISC_CHAR_DSCPT,    */
595738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project};
605738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
615738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source ProjectUINT16 disc_type_to_uuid[GATT_DISC_MAX] =
625738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{
635738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    0,                  /* reserved */
645738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    GATT_UUID_PRI_SERVICE, /* <service> DISC_SRVC_ALL */
655738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    GATT_UUID_PRI_SERVICE, /* <service> for DISC_SERVC_BY_UUID */
665738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    GATT_UUID_INCLUDE_SERVICE, /* <include_service> for DISC_INC_SRVC */
675738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    GATT_UUID_CHAR_DECLARE,   /* <characteristic> for DISC_CHAR */
685738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    0                   /* no type filtering for DISC_CHAR_DSCPT */
695738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project};
705738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
715738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
725738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/*******************************************************************************
735738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
745738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function         gatt_act_discovery
755738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
765738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description      GATT discovery operation.
775738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
785738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns          void.
795738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
805738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/
815738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectvoid gatt_act_discovery(tGATT_CLCB *p_clcb)
825738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{
835738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    UINT8       op_code = disc_type_to_att_opcode[p_clcb->op_subtype];
845738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tGATT_CL_MSG   cl_req;
856975b4d711142b885af479721cada448952c6b41Andre Eisenbach    tGATT_STATUS    st;
865738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
875738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    if (p_clcb->s_handle <= p_clcb->e_handle && p_clcb->s_handle != 0)
885738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
895738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        memset(&cl_req, 0, sizeof(tGATT_CL_MSG));
905738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
915738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        cl_req.browse.s_handle = p_clcb->s_handle;
925738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        cl_req.browse.e_handle = p_clcb->e_handle;
935738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
945738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        if (disc_type_to_uuid[p_clcb->op_subtype] != 0)
955738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        {
965738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            cl_req.browse.uuid.len = 2;
975738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            cl_req.browse.uuid.uu.uuid16 = disc_type_to_uuid[p_clcb->op_subtype];
985738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        }
995738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
1005738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        if (p_clcb->op_subtype == GATT_DISC_SRVC_BY_UUID) /* fill in the FindByTypeValue request info*/
1015738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        {
1025738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            cl_req.find_type_value.uuid.len = 2;
1035738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            cl_req.find_type_value.uuid.uu.uuid16 = disc_type_to_uuid[p_clcb->op_subtype];
1045738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            cl_req.find_type_value.s_handle = p_clcb->s_handle;
1055738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            cl_req.find_type_value.e_handle = p_clcb->e_handle;
1065738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            cl_req.find_type_value.value_len = p_clcb->uuid.len;
1077fa4fba6f59f97df00aff07dbe8fb21b114b3c2cGanesh Ganapathi Batta            /* if service type is 32 bits UUID, convert it now */
1087fa4fba6f59f97df00aff07dbe8fb21b114b3c2cGanesh Ganapathi Batta            if (p_clcb->uuid.len == LEN_UUID_32)
1097fa4fba6f59f97df00aff07dbe8fb21b114b3c2cGanesh Ganapathi Batta            {
1107fa4fba6f59f97df00aff07dbe8fb21b114b3c2cGanesh Ganapathi Batta                cl_req.find_type_value.value_len = LEN_UUID_128;
1117fa4fba6f59f97df00aff07dbe8fb21b114b3c2cGanesh Ganapathi Batta                gatt_convert_uuid32_to_uuid128(cl_req.find_type_value.value, p_clcb->uuid.uu.uuid32);
1127fa4fba6f59f97df00aff07dbe8fb21b114b3c2cGanesh Ganapathi Batta            }
1137fa4fba6f59f97df00aff07dbe8fb21b114b3c2cGanesh Ganapathi Batta            else
1145738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            memcpy (cl_req.find_type_value.value,  &p_clcb->uuid.uu, p_clcb->uuid.len);
1155738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        }
1165738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
1176975b4d711142b885af479721cada448952c6b41Andre Eisenbach        st = attp_send_cl_msg(p_clcb->p_tcb, p_clcb->clcb_idx, op_code, &cl_req);
1186975b4d711142b885af479721cada448952c6b41Andre Eisenbach
1196975b4d711142b885af479721cada448952c6b41Andre Eisenbach        if (st !=  GATT_SUCCESS && st != GATT_CMD_STARTED)
1205738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        {
1215738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            gatt_end_operation(p_clcb, GATT_ERROR, NULL);
1225738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        }
1235738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
1245738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    else /* end of handle range */
1255738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        gatt_end_operation(p_clcb, GATT_SUCCESS, NULL);
1265738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project}
1275738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
1285738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/*******************************************************************************
1295738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
1305738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function         gatt_act_read
1315738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
1325738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description      GATT read operation.
1335738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
1345738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns          void.
1355738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
1365738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/
1375738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectvoid gatt_act_read (tGATT_CLCB *p_clcb, UINT16 offset)
1385738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{
1395738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tGATT_TCB  *p_tcb = p_clcb->p_tcb;
1405738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    UINT8   rt = GATT_INTERNAL_ERROR;
1415738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tGATT_CL_MSG  msg;
1425738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    UINT8        op_code = 0;
1435738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
1445738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    memset (&msg, 0, sizeof(tGATT_CL_MSG));
1455738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
1465738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    switch (p_clcb->op_subtype)
1475738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
1485738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        case GATT_READ_CHAR_VALUE:
1495738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        case GATT_READ_BY_TYPE:
1505738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            op_code = GATT_REQ_READ_BY_TYPE;
1515738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            msg.browse.s_handle = p_clcb->s_handle;
1525738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            msg.browse.e_handle = p_clcb->e_handle;
1535738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            if (p_clcb->op_subtype == GATT_READ_BY_TYPE)
1545738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                memcpy(&msg.browse.uuid, &p_clcb->uuid, sizeof(tBT_UUID));
1555738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            else
1565738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            {
1575738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                msg.browse.uuid.len = LEN_UUID_16;
1585738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                msg.browse.uuid.uu.uuid16 = GATT_UUID_CHAR_DECLARE;
1595738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            }
1605738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            break;
1615738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
1625738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        case GATT_READ_CHAR_VALUE_HDL:
1635738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        case GATT_READ_BY_HANDLE:
1645738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            if (!p_clcb->counter)
1655738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            {
1665738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                op_code = GATT_REQ_READ;
1675738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                msg.handle = p_clcb->s_handle;
1685738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            }
1695738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            else
1705738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            {
1715738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                if (!p_clcb->first_read_blob_after_read)
1725738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                    p_clcb->first_read_blob_after_read = TRUE;
1735738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                else
1745738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                    p_clcb->first_read_blob_after_read = FALSE;
1755738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
176b44cc59d286ad255e872c60df02e032bd8d9d75bSharvil Nanavati                GATT_TRACE_DEBUG("gatt_act_read first_read_blob_after_read=%d",
1775738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                                  p_clcb->first_read_blob_after_read);
1785738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                op_code = GATT_REQ_READ_BLOB;
1795738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                msg.read_blob.offset = offset;
1805738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                msg.read_blob.handle = p_clcb->s_handle;
1815738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            }
1825738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            p_clcb->op_subtype &= ~ 0x80;
1835738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            break;
1845738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
1855738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        case GATT_READ_PARTIAL:
1865738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            op_code = GATT_REQ_READ_BLOB;
1875738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            msg.read_blob.handle = p_clcb->s_handle;
1885738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            msg.read_blob.offset = offset;
1895738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            break;
1905738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
1915738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        case GATT_READ_MULTIPLE:
1925738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            op_code = GATT_REQ_READ_MULTI;
1935738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            memcpy (&msg.read_multi, p_clcb->p_attr_buf, sizeof(tGATT_READ_MULTI));
1945738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            break;
1955738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
1965738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        case GATT_READ_INC_SRV_UUID128:
1975738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            op_code = GATT_REQ_READ;
1985738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            msg.handle = p_clcb->s_handle;
1995738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            p_clcb->op_subtype &= ~ 0x90;
2005738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            break;
2015738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
2025738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        default:
203b44cc59d286ad255e872c60df02e032bd8d9d75bSharvil Nanavati            GATT_TRACE_ERROR("Unknown read type: %d", p_clcb->op_subtype);
2045738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            break;
2055738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
2065738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
2076975b4d711142b885af479721cada448952c6b41Andre Eisenbach    if (op_code != 0)
2086975b4d711142b885af479721cada448952c6b41Andre Eisenbach        rt = attp_send_cl_msg(p_tcb, p_clcb->clcb_idx, op_code, &msg);
2096975b4d711142b885af479721cada448952c6b41Andre Eisenbach
2106975b4d711142b885af479721cada448952c6b41Andre Eisenbach    if ( op_code == 0 || (rt != GATT_SUCCESS && rt != GATT_CMD_STARTED))
2115738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
2125738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        gatt_end_operation(p_clcb, rt, NULL);
2135738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
2145738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project}
2155738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
2165738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/*******************************************************************************
2175738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
2185738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function         gatt_act_write
2195738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
2205738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description      GATT write operation.
2215738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
2225738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns          void.
2235738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
2245738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/
225ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Battavoid gatt_act_write (tGATT_CLCB *p_clcb, UINT8 sec_act)
2265738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{
2275738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tGATT_TCB           *p_tcb = p_clcb->p_tcb;
2286975b4d711142b885af479721cada448952c6b41Andre Eisenbach    UINT8               rt = GATT_SUCCESS, op_code = 0;
2295738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tGATT_VALUE         *p_attr = (tGATT_VALUE *)p_clcb->p_attr_buf;
2305738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
2315738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    if (p_attr)
2325738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
2335738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        switch (p_clcb->op_subtype)
2345738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        {
2355738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            case GATT_WRITE_NO_RSP:
2365738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                p_clcb->s_handle = p_attr->handle;
237ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta                op_code = (sec_act == GATT_SEC_SIGN_DATA) ? GATT_SIGN_CMD_WRITE : GATT_CMD_WRITE;
2385738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                rt = gatt_send_write_msg(p_tcb,
2395738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                                         p_clcb->clcb_idx,
2405738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                                         op_code,
2415738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                                         p_attr->handle,
2425738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                                         p_attr->len,
2435738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                                         0,
2445738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                                         p_attr->value);
2455738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                break;
2465738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
2475738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            case GATT_WRITE:
2485738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                if (p_attr->len <= (p_tcb->payload_size - GATT_HDR_SIZE))
2495738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                {
2505738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                    p_clcb->s_handle = p_attr->handle;
2515738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
2525738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                    rt = gatt_send_write_msg(p_tcb,
2535738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                                             p_clcb->clcb_idx,
2545738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                                             GATT_REQ_WRITE,
2555738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                                             p_attr->handle,
2565738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                                             p_attr->len,
2575738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                                             0,
2585738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                                             p_attr->value);
2595738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                }
2605738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                else /* prepare write for long attribute */
2615738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                {
2625738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                    gatt_send_prepare_write(p_tcb, p_clcb);
2635738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                }
2645738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                break;
2655738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
2665738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            case GATT_WRITE_PREPARE:
2675738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                gatt_send_prepare_write(p_tcb, p_clcb);
2685738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                break;
2695738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
2705738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            default:
2715738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                rt = GATT_INTERNAL_ERROR;
272b44cc59d286ad255e872c60df02e032bd8d9d75bSharvil Nanavati                GATT_TRACE_ERROR("Unknown write type: %d", p_clcb->op_subtype);
2735738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                break;
2745738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        }
2755738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
2765738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    else
2775738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        rt = GATT_INTERNAL_ERROR;
2785738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
27917b04bd498405f2bb109a85562ebbdcb6bb06e95Andre Eisenbach    if ((rt != GATT_SUCCESS  && rt != GATT_CMD_STARTED && rt != GATT_CONGESTED)
2805738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        || (rt != GATT_CMD_STARTED && p_clcb->op_subtype == GATT_WRITE_NO_RSP))
2815738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
2825738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        if (rt != GATT_SUCCESS)
2835738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        {
2845d5b041ca497013df4ecfeb415db3843d0a90eb3Andre Eisenbach            GATT_TRACE_ERROR("gatt_act_write() failed op_code=0x%x rt=%d", op_code, rt);
2855738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        }
2865738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        gatt_end_operation(p_clcb, rt, NULL);
2875738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
2885738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project}
2895738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/*******************************************************************************
2905738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
2915738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function         gatt_send_queue_write_cancel
2925738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
2935738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description      send queue write cancel
2945738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
2955738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns          void.
2965738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
2975738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/
2985738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectvoid gatt_send_queue_write_cancel (tGATT_TCB *p_tcb, tGATT_CLCB *p_clcb, tGATT_EXEC_FLAG flag)
2995738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{
3005738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    UINT8       rt ;
3015738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
302b44cc59d286ad255e872c60df02e032bd8d9d75bSharvil Nanavati    GATT_TRACE_DEBUG("gatt_send_queue_write_cancel ");
3035738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
3045738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    rt = attp_send_cl_msg(p_tcb, p_clcb->clcb_idx, GATT_REQ_EXEC_WRITE, (tGATT_CL_MSG *)&flag);
3055738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
3065738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    if (rt != GATT_SUCCESS)
3075738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
3085738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        gatt_end_operation(p_clcb, rt, NULL);
3095738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
3105738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project}
3115738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/*******************************************************************************
3125738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
3135738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function         gatt_check_write_long_terminate
3145738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
3155738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description      To terminate write long or not.
3165738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
3175738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns          TRUE: write long is terminated; FALSE keep sending.
3185738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
3195738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/
3205738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source ProjectBOOLEAN gatt_check_write_long_terminate(tGATT_TCB  *p_tcb, tGATT_CLCB *p_clcb, tGATT_VALUE *p_rsp_value)
3215738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{
3225738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tGATT_VALUE         *p_attr = (tGATT_VALUE *)p_clcb->p_attr_buf;
3235738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    BOOLEAN             exec = FALSE;
3245738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tGATT_EXEC_FLAG     flag = GATT_PREP_WRITE_EXEC;
3255738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
326b44cc59d286ad255e872c60df02e032bd8d9d75bSharvil Nanavati    GATT_TRACE_DEBUG("gatt_check_write_long_terminate ");
3275738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    /* check the first write response status */
3285738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    if (p_rsp_value != NULL)
3295738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
3305738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        if (p_rsp_value->handle != p_attr->handle ||
3315738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            p_rsp_value->len != p_clcb->counter ||
3325738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            memcmp(p_rsp_value->value, p_attr->value + p_attr->offset, p_rsp_value->len))
3335738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        {
3345738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            /* data does not match    */
3355738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            p_clcb->status = GATT_ERROR;
3365738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            flag = GATT_PREP_WRITE_CANCEL;
3375738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            exec = TRUE;
3385738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        }
3395738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        else /* response checking is good */
3405738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        {
3415738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            p_clcb->status = GATT_SUCCESS;
3425738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            /* update write offset and check if end of attribute value */
3435738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            if ((p_attr->offset += p_rsp_value->len) >= p_attr->len)
3445738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                exec = TRUE;
3455738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        }
3465738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
3475738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    if (exec)
3485738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
3495738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        gatt_send_queue_write_cancel (p_tcb, p_clcb, flag);
3505738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        return TRUE;
3515738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
3525738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    return FALSE;
3535738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project}
3545738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/*******************************************************************************
3555738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
3565738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function         gatt_send_prepare_write
3575738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
3585738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description      Send prepare write.
3595738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
3605738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns          void.
3615738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
3625738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/
3635738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectvoid gatt_send_prepare_write(tGATT_TCB  *p_tcb, tGATT_CLCB *p_clcb)
3645738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{
3655738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tGATT_VALUE  *p_attr = (tGATT_VALUE *)p_clcb->p_attr_buf;
3665738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    UINT16  to_send, offset;
3675738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    UINT8   rt = GATT_SUCCESS;
3685738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    UINT8   type = p_clcb->op_subtype;
3695738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
370b44cc59d286ad255e872c60df02e032bd8d9d75bSharvil Nanavati    GATT_TRACE_DEBUG("gatt_send_prepare_write type=0x%x", type );
3715738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    to_send = p_attr->len - p_attr->offset;
3725738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
3735738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    if (to_send > (p_tcb->payload_size - GATT_WRITE_LONG_HDR_SIZE)) /* 2 = UINT16 offset bytes  */
3745738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        to_send = p_tcb->payload_size - GATT_WRITE_LONG_HDR_SIZE;
3755738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
3765738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    p_clcb->s_handle = p_attr->handle;
3775738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
3785738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    offset = p_attr->offset;
3795738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    if (type == GATT_WRITE_PREPARE)
3805738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
3815738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        offset += p_clcb->start_offset;
3825738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
3835738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
384b44cc59d286ad255e872c60df02e032bd8d9d75bSharvil Nanavati    GATT_TRACE_DEBUG("offset =0x%x len=%d", offset, to_send );
3855738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
3865738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    rt = gatt_send_write_msg(p_tcb,
3875738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                             p_clcb->clcb_idx,
3885738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                             GATT_REQ_PREPARE_WRITE,
3895738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                             p_attr->handle,
3905738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                             to_send,                           /* length */
3915738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                             offset,                            /* used as offset */
3925738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                             p_attr->value + p_attr->offset);   /* data */
3935738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
3945738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    /* remember the write long attribute length */
3955738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    p_clcb->counter = to_send;
3965738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
3976975b4d711142b885af479721cada448952c6b41Andre Eisenbach    if (rt != GATT_SUCCESS && rt != GATT_CMD_STARTED)
3985738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
3995738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        gatt_end_operation(p_clcb, rt, NULL);
4005738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
4015738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project}
4025738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
403ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta
4045738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/*******************************************************************************
4055738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
4065738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function         gatt_process_find_type_value_rsp
4075738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
4085738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description      This function is called to handle find by type value response.
4095738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
4105738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
4115738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns          void
4125738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
4135738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/
4147fa4fba6f59f97df00aff07dbe8fb21b114b3c2cGanesh Ganapathi Battavoid gatt_process_find_type_value_rsp (tGATT_TCB *p_tcb, tGATT_CLCB *p_clcb, UINT16 len, UINT8 *p_data)
4155738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{
4165738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tGATT_DISC_RES      result;
4175738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    UINT8               *p = p_data;
4185738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
4197fa4fba6f59f97df00aff07dbe8fb21b114b3c2cGanesh Ganapathi Batta    UNUSED(p_tcb);
4207fa4fba6f59f97df00aff07dbe8fb21b114b3c2cGanesh Ganapathi Batta
421b44cc59d286ad255e872c60df02e032bd8d9d75bSharvil Nanavati    GATT_TRACE_DEBUG("gatt_process_find_type_value_rsp ");
4225738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    /* unexpected response */
4235738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    if (p_clcb->operation != GATTC_OPTYPE_DISCOVERY || p_clcb->op_subtype != GATT_DISC_SRVC_BY_UUID)
4245738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        return;
4255738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
426ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    memset (&result, 0, sizeof(tGATT_DISC_RES));
4275738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    result.type.len = 2;
4285738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    result.type.uu.uuid16 = GATT_UUID_PRI_SERVICE;
4295738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
4305738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    /* returns a series of handle ranges */
4315738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    while (len >= 4)
4325738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
4335738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        STREAM_TO_UINT16 (result.handle, p);
434ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta        STREAM_TO_UINT16 (result.value.group_value.e_handle, p);
435ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta        memcpy (&result.value.group_value.service_type,  &p_clcb->uuid, sizeof(tBT_UUID));
4365738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
437ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta        len -= 4;
4385738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
4395738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        if (p_clcb->p_reg->app_cb.p_disc_res_cb)
4405738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            (*p_clcb->p_reg->app_cb.p_disc_res_cb)(p_clcb->conn_id, p_clcb->op_subtype, &result);
4415738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
4425738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
4435738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    /* last handle  + 1 */
444ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    p_clcb->s_handle = (result.value.group_value.e_handle == 0) ? 0 : (result.value.group_value.e_handle + 1);
4455738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    /* initiate another request */
4465738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    gatt_act_discovery(p_clcb) ;
4475738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project}
4485738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/*******************************************************************************
4495738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
4505738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function         gatt_process_read_info_rsp
4515738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
4525738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description      This function is called to handle the read information
4535738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**                  response.
4545738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
4555738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
4565738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns          void
4575738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
4585738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/
4597fa4fba6f59f97df00aff07dbe8fb21b114b3c2cGanesh Ganapathi Battavoid gatt_process_read_info_rsp(tGATT_TCB *p_tcb, tGATT_CLCB *p_clcb, UINT8 op_code,
4607fa4fba6f59f97df00aff07dbe8fb21b114b3c2cGanesh Ganapathi Batta                                UINT16 len, UINT8 *p_data)
4615738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{
4625738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tGATT_DISC_RES  result;
4635738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    UINT8   *p = p_data, uuid_len = 0, type;
4645738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
4657fa4fba6f59f97df00aff07dbe8fb21b114b3c2cGanesh Ganapathi Batta    UNUSED(p_tcb);
4667fa4fba6f59f97df00aff07dbe8fb21b114b3c2cGanesh Ganapathi Batta    UNUSED(op_code);
4677fa4fba6f59f97df00aff07dbe8fb21b114b3c2cGanesh Ganapathi Batta
468ccf9c15f52eea21858d994601d71308e84c7c859Andre Eisenbach    if (len < GATT_INFO_RSP_MIN_LEN)
469ccf9c15f52eea21858d994601d71308e84c7c859Andre Eisenbach    {
470b44cc59d286ad255e872c60df02e032bd8d9d75bSharvil Nanavati        GATT_TRACE_ERROR("invalid Info Response PDU received, discard.");
471ccf9c15f52eea21858d994601d71308e84c7c859Andre Eisenbach        gatt_end_operation(p_clcb, GATT_INVALID_PDU, NULL);
472ccf9c15f52eea21858d994601d71308e84c7c859Andre Eisenbach        return;
473ccf9c15f52eea21858d994601d71308e84c7c859Andre Eisenbach    }
4745738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    /* unexpected response */
4755738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    if (p_clcb->operation != GATTC_OPTYPE_DISCOVERY || p_clcb->op_subtype != GATT_DISC_CHAR_DSCPT)
4765738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        return;
4775738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
4785738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    STREAM_TO_UINT8(type, p);
4795738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    len -= 1;
4805738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
4815738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    if (type == GATT_INFO_TYPE_PAIR_16)
4825738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        uuid_len = LEN_UUID_16;
4835738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    else if (type == GATT_INFO_TYPE_PAIR_128)
4845738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        uuid_len = LEN_UUID_128;
4855738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
4865738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    while (len >= uuid_len + 2)
4875738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
4885738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        STREAM_TO_UINT16 (result.handle, p);
4895738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
4905738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        if (uuid_len > 0)
4915738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        {
4925738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            if (!gatt_parse_uuid_from_cmd(&result.type, uuid_len, &p))
4935738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                break;
4945738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        }
4955738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        else
4965738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            memcpy (&result.type, &p_clcb->uuid, sizeof(tBT_UUID));
4975738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
4985738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        len -= (uuid_len + 2);
4995738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
5005738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        if (p_clcb->p_reg->app_cb.p_disc_res_cb)
5015738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            (*p_clcb->p_reg->app_cb.p_disc_res_cb)(p_clcb->conn_id, p_clcb->op_subtype, &result);
5025738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
5035738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
5045738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    p_clcb->s_handle = (result.handle == 0) ? 0 :(result.handle + 1);
5055738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    /* initiate another request */
5065738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    gatt_act_discovery(p_clcb) ;
5075738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project}
5085738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/*******************************************************************************
5095738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
5105738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function         gatt_proc_disc_error_rsp
5115738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
5125738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description      This function process the read by type response and send another
5135738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**                  request if needed.
5145738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
5155738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns          void.
5165738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
5175738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/
5187fa4fba6f59f97df00aff07dbe8fb21b114b3c2cGanesh Ganapathi Battavoid gatt_proc_disc_error_rsp(tGATT_TCB *p_tcb, tGATT_CLCB *p_clcb, UINT8 opcode,
5197fa4fba6f59f97df00aff07dbe8fb21b114b3c2cGanesh Ganapathi Batta                              UINT16 handle, UINT8 reason)
5205738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{
5215738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tGATT_STATUS    status = (tGATT_STATUS) reason;
5225738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
5237fa4fba6f59f97df00aff07dbe8fb21b114b3c2cGanesh Ganapathi Batta    UNUSED(p_tcb);
5247fa4fba6f59f97df00aff07dbe8fb21b114b3c2cGanesh Ganapathi Batta    UNUSED(handle);
5257fa4fba6f59f97df00aff07dbe8fb21b114b3c2cGanesh Ganapathi Batta
526b44cc59d286ad255e872c60df02e032bd8d9d75bSharvil Nanavati    GATT_TRACE_DEBUG("gatt_proc_disc_error_rsp reason: %02x cmd_code %04x", reason, opcode);
5275738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
5285738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    switch (opcode)
5295738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
5305738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        case GATT_REQ_READ_BY_GRP_TYPE:
5315738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        case GATT_REQ_FIND_TYPE_VALUE:
5325738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        case GATT_REQ_READ_BY_TYPE:
5335738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        case GATT_REQ_FIND_INFO:
5345738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            if (reason == GATT_NOT_FOUND)
5355738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            {
5365738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                status = GATT_SUCCESS;
537b44cc59d286ad255e872c60df02e032bd8d9d75bSharvil Nanavati                GATT_TRACE_DEBUG("Discovery completed");
5385738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            }
5395738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            break;
5405738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        default:
541b44cc59d286ad255e872c60df02e032bd8d9d75bSharvil Nanavati            GATT_TRACE_ERROR("Incorrect discovery opcode %04x",   opcode);
5425738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            break;
5435738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
5445738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
5455738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    gatt_end_operation(p_clcb, status, NULL);
5465738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project}
5475738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
5485738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/*******************************************************************************
5495738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
5505738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function         gatt_process_error_rsp
5515738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
5525738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description      This function is called to handle the error response
5535738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
5545738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
5555738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns          void
5565738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
5575738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/
5587fa4fba6f59f97df00aff07dbe8fb21b114b3c2cGanesh Ganapathi Battavoid gatt_process_error_rsp(tGATT_TCB *p_tcb, tGATT_CLCB *p_clcb, UINT8 op_code,
5597fa4fba6f59f97df00aff07dbe8fb21b114b3c2cGanesh Ganapathi Batta                            UINT16 len, UINT8 *p_data)
5605738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{
5615738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    UINT8   opcode, reason, * p= p_data;
5625738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    UINT16  handle;
5635738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tGATT_VALUE  *p_attr = (tGATT_VALUE *)p_clcb->p_attr_buf;
5645738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
5657fa4fba6f59f97df00aff07dbe8fb21b114b3c2cGanesh Ganapathi Batta    UNUSED(op_code);
5667fa4fba6f59f97df00aff07dbe8fb21b114b3c2cGanesh Ganapathi Batta    UNUSED(len);
5677fa4fba6f59f97df00aff07dbe8fb21b114b3c2cGanesh Ganapathi Batta
568b44cc59d286ad255e872c60df02e032bd8d9d75bSharvil Nanavati    GATT_TRACE_DEBUG("gatt_process_error_rsp ");
5695738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    STREAM_TO_UINT8(opcode, p);
5705738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    STREAM_TO_UINT16(handle, p);
5715738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    STREAM_TO_UINT8(reason, p);
5725738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
5735738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    if (p_clcb->operation == GATTC_OPTYPE_DISCOVERY)
5745738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
5757fa4fba6f59f97df00aff07dbe8fb21b114b3c2cGanesh Ganapathi Batta        gatt_proc_disc_error_rsp(p_tcb, p_clcb, opcode, handle, reason);
5765738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
5775738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    else
5785738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
5795738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        if ( (p_clcb->operation == GATTC_OPTYPE_WRITE) &&
5805738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project             (p_clcb->op_subtype == GATT_WRITE) &&
5815738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project             (opcode == GATT_REQ_PREPARE_WRITE) &&
5825738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project             (p_attr) &&
5835738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project             (handle == p_attr->handle)  )
5845738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        {
5855738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            p_clcb->status = reason;
5865738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            gatt_send_queue_write_cancel(p_tcb, p_clcb, GATT_PREP_WRITE_CANCEL);
5875738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        }
5885738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        else if ((p_clcb->operation == GATTC_OPTYPE_READ) &&
5895738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                 ((p_clcb->op_subtype == GATT_READ_CHAR_VALUE_HDL) ||
5905738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                  (p_clcb->op_subtype == GATT_READ_BY_HANDLE)) &&
5915738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                 (opcode == GATT_REQ_READ_BLOB) &&
5925738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                 p_clcb->first_read_blob_after_read &&
5935738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                 (reason == GATT_NOT_LONG))
5945738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        {
5955738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            gatt_end_operation(p_clcb, GATT_SUCCESS, (void *)p_clcb->p_attr_buf);
5965738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        }
5975738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        else
5985738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            gatt_end_operation(p_clcb, reason, NULL);
5995738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
6005738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project}
6015738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/*******************************************************************************
6025738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
6035738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function         gatt_process_prep_write_rsp
6045738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
6055738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description      This function is called to handle the read response
6065738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
6075738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
6085738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns          void
6095738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
6105738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/
6115738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectvoid gatt_process_prep_write_rsp (tGATT_TCB *p_tcb, tGATT_CLCB *p_clcb, UINT8 op_code,
6125738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                                  UINT16 len, UINT8 *p_data)
6135738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{
6145738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tGATT_VALUE  value = {0};
6155738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    UINT8        *p= p_data;
6165738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
617b44cc59d286ad255e872c60df02e032bd8d9d75bSharvil Nanavati    GATT_TRACE_ERROR("value resp op_code = %s len = %d", gatt_dbg_op_name(op_code), len);
6185738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
619ccf9c15f52eea21858d994601d71308e84c7c859Andre Eisenbach    if (len < GATT_PREP_WRITE_RSP_MIN_LEN)
620ccf9c15f52eea21858d994601d71308e84c7c859Andre Eisenbach    {
621b44cc59d286ad255e872c60df02e032bd8d9d75bSharvil Nanavati        GATT_TRACE_ERROR("illegal prepare write response length, discard");
622ccf9c15f52eea21858d994601d71308e84c7c859Andre Eisenbach        gatt_end_operation(p_clcb, GATT_INVALID_PDU, &value);
623ccf9c15f52eea21858d994601d71308e84c7c859Andre Eisenbach        return;
624ccf9c15f52eea21858d994601d71308e84c7c859Andre Eisenbach    }
625ccf9c15f52eea21858d994601d71308e84c7c859Andre Eisenbach
6265738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    STREAM_TO_UINT16 (value.handle, p);
6275738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    STREAM_TO_UINT16 (value.offset, p);
6285738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
6295738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    value.len = len - 4;
6305738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
6315738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    memcpy (value.value, p, value.len);
6325738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
6335738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    if (p_clcb->op_subtype == GATT_WRITE_PREPARE)
6345738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
6355738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        p_clcb->status = GATT_SUCCESS;
6365738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        /* application should verify handle offset
6375738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project           and value are matched or not */
6385738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
6395738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        gatt_end_operation(p_clcb, p_clcb->status, &value);
6405738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
6415738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    else if (p_clcb->op_subtype == GATT_WRITE )
6425738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
6435738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        if (!gatt_check_write_long_terminate(p_tcb, p_clcb, &value))
6445738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            gatt_send_prepare_write(p_tcb, p_clcb);
6455738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
6465738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
6475738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project}
6485738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/*******************************************************************************
6495738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
6505738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function         gatt_process_notification
6515738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
6525738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description      This function is called to handle the handle value indication
6535738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**                  or handle value notification.
6545738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
6555738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
6565738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns          void
6575738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
6585738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/
6595738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectvoid gatt_process_notification(tGATT_TCB *p_tcb, UINT8 op_code,
6605738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                               UINT16 len, UINT8 *p_data)
6615738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{
6625738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tGATT_VALUE     value = {0};
6635738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tGATT_REG       *p_reg;
6645738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    UINT16          conn_id;
6655738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tGATT_STATUS    encrypt_status;
6665738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    UINT8           *p= p_data, i,
6675738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    event = (op_code == GATT_HANDLE_VALUE_NOTIF) ? GATTC_OPTYPE_NOTIFICATION : GATTC_OPTYPE_INDICATION;
6685738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
669b44cc59d286ad255e872c60df02e032bd8d9d75bSharvil Nanavati    GATT_TRACE_DEBUG("gatt_process_notification ");
6705738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
671ccf9c15f52eea21858d994601d71308e84c7c859Andre Eisenbach    if (len < GATT_NOTIFICATION_MIN_LEN)
672ccf9c15f52eea21858d994601d71308e84c7c859Andre Eisenbach    {
673b44cc59d286ad255e872c60df02e032bd8d9d75bSharvil Nanavati        GATT_TRACE_ERROR("illegal notification PDU length, discard");
674ccf9c15f52eea21858d994601d71308e84c7c859Andre Eisenbach        return;
675ccf9c15f52eea21858d994601d71308e84c7c859Andre Eisenbach    }
676ccf9c15f52eea21858d994601d71308e84c7c859Andre Eisenbach
6775738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    STREAM_TO_UINT16 (value.handle, p);
6785738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    value.len = len - 2;
6795738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    memcpy (value.value, p, value.len);
6805738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
6815738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    if (!GATT_HANDLE_IS_VALID(value.handle))
6825738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
6835738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        /* illegal handle, send ack now */
6845738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        if (op_code == GATT_HANDLE_VALUE_IND)
6855738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            attp_send_cl_msg(p_tcb, 0, GATT_HANDLE_VALUE_CONF, NULL);
6865738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        return;
6875738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
6885738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
6895738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    if (event == GATTC_OPTYPE_INDICATION)
6905738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
6915738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        if (p_tcb->ind_count)
6925738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        {
6935738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            /* this is an error case that receiving an indication but we
6945738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project               still has an indication not being acked yet.
6955738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project               For now, just log the error reset the counter.
6965738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project               Later we need to disconnect the link unconditionally.
6975738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            */
698b44cc59d286ad255e872c60df02e032bd8d9d75bSharvil Nanavati            GATT_TRACE_ERROR("gatt_process_notification rcv Ind. but ind_count=%d (will reset ind_count)",  p_tcb->ind_count);
6995738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        }
7005738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        p_tcb->ind_count = 0;
7015738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
7025738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
7035738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    /* should notify all registered client with the handle value notificaion/indication
7045738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project       Note: need to do the indication count and start timer first then do callback
7055738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project     */
7065738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
7075738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    for (i = 0, p_reg = gatt_cb.cl_rcb; i < GATT_MAX_APPS; i++, p_reg++)
7085738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
7095738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        if (p_reg->in_use && p_reg->app_cb.p_cmpl_cb && (event == GATTC_OPTYPE_INDICATION))
7105738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            p_tcb->ind_count++;
7115738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
7125738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
7135738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    if (event == GATTC_OPTYPE_INDICATION)
7145738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
7155738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        /* start a timer for app confirmation */
7165738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        if (p_tcb->ind_count > 0)
7175738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            gatt_start_ind_ack_timer(p_tcb);
7185738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        else /* no app to indicate, or invalid handle */
7195738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            attp_send_cl_msg(p_tcb, 0, GATT_HANDLE_VALUE_CONF, NULL);
7205738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
7215738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
722ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    encrypt_status = gatt_get_link_encrypt_status(p_tcb);
7235738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    for (i = 0, p_reg = gatt_cb.cl_rcb; i < GATT_MAX_APPS; i++, p_reg++)
7245738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
7255738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        if (p_reg->in_use && p_reg->app_cb.p_cmpl_cb)
7265738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        {
7275738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            conn_id = GATT_CREATE_CONN_ID(p_tcb->tcb_idx, p_reg->gatt_if);
7285738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            (*p_reg->app_cb.p_cmpl_cb) (conn_id, event, encrypt_status, (tGATT_CL_COMPLETE *)&value);
7295738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        }
7305738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
7315738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
7325738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project}
7335738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
7345738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/*******************************************************************************
7355738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
7365738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function         gatt_process_read_by_type_rsp
7375738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
7385738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description      This function is called to handle the read by type response.
7395738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**                  read by type can be used for discovery, or read by type or
7405738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**                  read characteristic value.
7415738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
7425738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns          void
7435738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
7445738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/
7455738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectvoid gatt_process_read_by_type_rsp (tGATT_TCB *p_tcb, tGATT_CLCB *p_clcb, UINT8 op_code,
7465738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                                    UINT16 len, UINT8 *p_data)
7475738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{
7485738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tGATT_DISC_RES      result;
7495738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tGATT_DISC_VALUE    record_value;
7505738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    UINT8               *p = p_data, value_len, handle_len = 2;
7515738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    UINT16              handle = 0;
7525738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
7535738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    /* discovery procedure and no callback function registered */
7545738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    if (((!p_clcb->p_reg) || (!p_clcb->p_reg->app_cb.p_disc_res_cb)) && (p_clcb->operation == GATTC_OPTYPE_DISCOVERY))
7555738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        return;
7565738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
757ccf9c15f52eea21858d994601d71308e84c7c859Andre Eisenbach    if (len < GATT_READ_BY_TYPE_RSP_MIN_LEN)
758ccf9c15f52eea21858d994601d71308e84c7c859Andre Eisenbach    {
759b44cc59d286ad255e872c60df02e032bd8d9d75bSharvil Nanavati        GATT_TRACE_ERROR("Illegal ReadByType/ReadByGroupType Response length, discard");
760ccf9c15f52eea21858d994601d71308e84c7c859Andre Eisenbach        gatt_end_operation(p_clcb, GATT_INVALID_PDU, NULL);
761ccf9c15f52eea21858d994601d71308e84c7c859Andre Eisenbach        return;
762ccf9c15f52eea21858d994601d71308e84c7c859Andre Eisenbach    }
763ccf9c15f52eea21858d994601d71308e84c7c859Andre Eisenbach
7645738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    STREAM_TO_UINT8(value_len, p);
7655738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
7665738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    if ((value_len > (p_tcb->payload_size - 2)) || (value_len > (len-1))  )
7675738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
7685738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        /* this is an error case that server's response containing a value length which is larger than MTU-2
7695738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project           or value_len > message total length -1 */
770b44cc59d286ad255e872c60df02e032bd8d9d75bSharvil Nanavati        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)",
7715738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                          op_code, value_len, (p_tcb->payload_size - 2), (len-1));
7725738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        gatt_end_operation(p_clcb, GATT_ERROR, NULL);
7735738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        return;
7745738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
7755738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
7765738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    if (op_code == GATT_RSP_READ_BY_GRP_TYPE)
7775738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        handle_len = 4;
7785738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
7795738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    value_len -= handle_len; /* substract the handle pairs bytes */
7805738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    len -= 1;
7815738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
7825738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    while (len >= (handle_len + value_len))
7835738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
7845738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        STREAM_TO_UINT16(handle, p);
7855738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
7865738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        if (!GATT_HANDLE_IS_VALID(handle))
7875738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        {
7885738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            gatt_end_operation(p_clcb, GATT_INVALID_HANDLE, NULL);
7895738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            return;
7905738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        }
7915738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
7925738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        memset(&result, 0, sizeof(tGATT_DISC_RES));
7935738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        memset(&record_value, 0, sizeof(tGATT_DISC_VALUE));
7945738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
7955738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        result.handle = handle;
7965738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        result.type.len = 2;
7975738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        result.type.uu.uuid16 = disc_type_to_uuid[p_clcb->op_subtype];
7985738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
7995738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        /* discover all services */
8005738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        if (p_clcb->operation == GATTC_OPTYPE_DISCOVERY &&
8015738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            p_clcb->op_subtype == GATT_DISC_SRVC_ALL &&
8025738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            op_code == GATT_RSP_READ_BY_GRP_TYPE)
8035738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        {
8045738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            STREAM_TO_UINT16(handle, p);
8055738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
8065738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            if (!GATT_HANDLE_IS_VALID(handle))
8075738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            {
8085738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                gatt_end_operation(p_clcb, GATT_INVALID_HANDLE, NULL);
8095738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                return;
8105738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            }
8115738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            else
8125738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            {
8135738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                record_value.group_value.e_handle = handle;
8145738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                if (!gatt_parse_uuid_from_cmd(&record_value.group_value.service_type, value_len, &p))
8155738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                {
816b44cc59d286ad255e872c60df02e032bd8d9d75bSharvil Nanavati                    GATT_TRACE_ERROR("discover all service response parsing failure");
8175738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                    break;
8185738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                }
8195738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            }
8205738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        }
8215738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        /* discover included service */
8225738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        else if (p_clcb->operation == GATTC_OPTYPE_DISCOVERY && p_clcb->op_subtype == GATT_DISC_INC_SRVC)
8235738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        {
8245738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            STREAM_TO_UINT16(record_value.incl_service.s_handle, p);
8255738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            STREAM_TO_UINT16(record_value.incl_service.e_handle, p);
8265738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
8275738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            if (!GATT_HANDLE_IS_VALID(record_value.incl_service.s_handle) ||
8285738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                !GATT_HANDLE_IS_VALID(record_value.incl_service.e_handle))
8295738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            {
8305738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                gatt_end_operation(p_clcb, GATT_INVALID_HANDLE, NULL);
8315738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                return;
8325738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            }
8335738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
8345738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            if(value_len == 6)
8355738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            {
8365738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                STREAM_TO_UINT16(record_value.incl_service.service_type.uu.uuid16, p);
8375738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                record_value.incl_service.service_type.len = LEN_UUID_16;
8385738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            }
8395738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            else if (value_len == 4)
8405738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            {
8415738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                p_clcb->s_handle = record_value.incl_service.s_handle;
8425738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                p_clcb->read_uuid128.wait_for_read_rsp = TRUE;
8435738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                p_clcb->read_uuid128.next_disc_start_hdl = handle + 1;
8445738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                memcpy(&p_clcb->read_uuid128.result, &result, sizeof(result));
8455738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                memcpy(&p_clcb->read_uuid128.result.value, &record_value, sizeof (result.value));
8465738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                p_clcb->op_subtype |= 0x90;
8475738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                gatt_act_read(p_clcb, 0);
8485738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                return;
8495738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            }
8505738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            else
8515738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            {
852b44cc59d286ad255e872c60df02e032bd8d9d75bSharvil Nanavati               GATT_TRACE_ERROR("gatt_process_read_by_type_rsp INCL_SRVC failed with invalid data value_len=%d", value_len);
8535738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project               gatt_end_operation(p_clcb, GATT_INVALID_PDU, (void *)p);
8545738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project               return;
8555738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            }
8565738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        }
8575738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        /* read by type */
8585738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        else if (p_clcb->operation == GATTC_OPTYPE_READ && p_clcb->op_subtype == GATT_READ_BY_TYPE)
8595738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        {
8605738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            p_clcb->counter = len - 2;
8615738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            p_clcb->s_handle = handle;
8625738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            if ( p_clcb->counter == (p_clcb->p_tcb->payload_size -4))
8635738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            {
8645738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                p_clcb->op_subtype = GATT_READ_BY_HANDLE;
8655738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                if (!p_clcb->p_attr_buf)
8665738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                    p_clcb->p_attr_buf = (UINT8 *)GKI_getbuf(GATT_MAX_ATTR_LEN);
8675738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                if (p_clcb->p_attr_buf && p_clcb->counter <= GATT_MAX_ATTR_LEN)
8685738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                {
8695738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                    memcpy(p_clcb->p_attr_buf, p, p_clcb->counter);
8705738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                    gatt_act_read(p_clcb, p_clcb->counter);
8715738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                }
8725738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                else
8735738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                   gatt_end_operation(p_clcb, GATT_INTERNAL_ERROR, (void *)p);
8745738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            }
8755738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            else
8765738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            {
8775738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                 gatt_end_operation(p_clcb, GATT_SUCCESS, (void *)p);
8785738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            }
8795738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            return;
8805738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        }
8816975b4d711142b885af479721cada448952c6b41Andre Eisenbach        else /* discover characterisitic */
8825738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        {
8835738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            STREAM_TO_UINT8 (record_value.dclr_value.char_prop, p);
8845738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            STREAM_TO_UINT16(record_value.dclr_value.val_handle, p);
8855738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            if (!GATT_HANDLE_IS_VALID(record_value.dclr_value.val_handle))
8865738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            {
8875738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                gatt_end_operation(p_clcb, GATT_INVALID_HANDLE, NULL);
8885738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                return;
8895738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            }
890ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta            if (!gatt_parse_uuid_from_cmd(&record_value.dclr_value.char_uuid, (UINT16)(value_len - 3), &p))
891ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta            {
892ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta                gatt_end_operation(p_clcb, GATT_SUCCESS, NULL);
893ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta                /* invalid format, and skip the result */
894ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta                return;
895ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta            }
8965738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
8975738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            /* UUID not matching */
8985738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            if (!gatt_uuid_compare(record_value.dclr_value.char_uuid, p_clcb->uuid))
8995738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            {
9005738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                len -= (value_len + 2);
9015738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                continue; /* skip the result, and look for next one */
9025738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            }
9035738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            else if (p_clcb->operation == GATTC_OPTYPE_READ)
9045738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            /* UUID match for read characteristic value */
9055738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            {
9065738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                /* only read the first matching UUID characteristic value, and
9075738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                  discard the rest results */
9085738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                p_clcb->s_handle = record_value.dclr_value.val_handle;
9095738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                p_clcb->op_subtype |= 0x80;
9105738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                gatt_act_read(p_clcb, 0);
9115738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                return;
9125738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            }
9135738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        }
9145738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        len -= (value_len + handle_len);
9155738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
9165738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        /* result is (handle, 16bits UUID) pairs */
9175738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        memcpy (&result.value, &record_value, sizeof (result.value));
9185738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
9195738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        /* send callback if is discover procedure */
9205738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        if (p_clcb->operation == GATTC_OPTYPE_DISCOVERY && p_clcb->p_reg->app_cb.p_disc_res_cb)
9215738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            (*p_clcb->p_reg->app_cb.p_disc_res_cb)(p_clcb->conn_id, p_clcb->op_subtype, &result);
9225738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
9235738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
9245738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    p_clcb->s_handle = (handle == 0) ? 0 : (handle + 1);
9255738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
9265738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    if (p_clcb->operation == GATTC_OPTYPE_DISCOVERY)
9275738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
9285738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        /* initiate another request */
9295738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        gatt_act_discovery(p_clcb) ;
9305738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
9315738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    else /* read characteristic value */
9325738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
9335738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        gatt_act_read(p_clcb, 0);
9345738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
9355738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project}
9365738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
9375738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/*******************************************************************************
9385738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
9395738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function         gatt_process_read_rsp
9405738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
9415738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description      This function is called to handle the read BLOB response
9425738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
9435738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
9445738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns          void
9455738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
9465738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/
9477fa4fba6f59f97df00aff07dbe8fb21b114b3c2cGanesh Ganapathi Battavoid gatt_process_read_rsp(tGATT_TCB *p_tcb, tGATT_CLCB *p_clcb,  UINT8 op_code,
9487fa4fba6f59f97df00aff07dbe8fb21b114b3c2cGanesh Ganapathi Batta                           UINT16 len, UINT8 *p_data)
9495738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{
9505738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    UINT16      offset = p_clcb->counter;
9515738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    UINT8       * p= p_data;
9525738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
9537fa4fba6f59f97df00aff07dbe8fb21b114b3c2cGanesh Ganapathi Batta    UNUSED(op_code);
9547fa4fba6f59f97df00aff07dbe8fb21b114b3c2cGanesh Ganapathi Batta
9555738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    if (p_clcb->operation == GATTC_OPTYPE_READ)
9565738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
9575738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        if (p_clcb->op_subtype != GATT_READ_BY_HANDLE)
9585738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        {
9595738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            p_clcb->counter = len;
9605738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            gatt_end_operation(p_clcb, GATT_SUCCESS, (void *)p);
9615738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        }
9625738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        else
9635738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        {
9645738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
9655738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            /* allocate GKI buffer holding up long attribute value  */
9665738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            if (!p_clcb->p_attr_buf)
9675738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                p_clcb->p_attr_buf = (UINT8 *)GKI_getbuf(GATT_MAX_ATTR_LEN);
9685738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
9695738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            /* copy attrobute value into cb buffer  */
9705738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            if (p_clcb->p_attr_buf && offset < GATT_MAX_ATTR_LEN)
9715738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            {
9725738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                if ((len + offset) > GATT_MAX_ATTR_LEN)
9735738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                    len = GATT_MAX_ATTR_LEN - offset;
9745738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
9755738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                p_clcb->counter += len;
9765738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
9775738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                memcpy(p_clcb->p_attr_buf + offset, p, len);
9785738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
9795738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                /* send next request if needed  */
9805738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
9815738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                if (len == (p_tcb->payload_size - 1) && /* full packet for read or read blob rsp */
9825738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                    len + offset < GATT_MAX_ATTR_LEN)
9835738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                {
984b44cc59d286ad255e872c60df02e032bd8d9d75bSharvil Nanavati                    GATT_TRACE_DEBUG("full pkt issue read blob for remianing bytes old offset=%d len=%d new offset=%d",
9855738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                                      offset, len, p_clcb->counter);
9865738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                    gatt_act_read(p_clcb, p_clcb->counter);
9875738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                }
9885738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                else /* end of request, send callback */
9895738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                {
9905738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                    gatt_end_operation(p_clcb, GATT_SUCCESS, (void *)p_clcb->p_attr_buf);
9915738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                }
9925738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            }
9935738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            else /* exception, should not happen */
9945738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            {
995b44cc59d286ad255e872c60df02e032bd8d9d75bSharvil Nanavati                GATT_TRACE_ERROR("attr offset = %d p_attr_buf = %d ", offset, p_clcb->p_attr_buf);
9965738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                gatt_end_operation(p_clcb, GATT_NO_RESOURCES, (void *)p_clcb->p_attr_buf);
9975738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            }
9985738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        }
9995738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
10005738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    else
10015738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
10025738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        if (p_clcb->operation == GATTC_OPTYPE_DISCOVERY &&
10035738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            p_clcb->op_subtype == GATT_DISC_INC_SRVC &&
10045738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            p_clcb->read_uuid128.wait_for_read_rsp )
10055738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        {
10065738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            p_clcb->s_handle = p_clcb->read_uuid128.next_disc_start_hdl;
10075738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            p_clcb->read_uuid128.wait_for_read_rsp = FALSE;
10085738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            if (len == LEN_UUID_128)
10095738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            {
10105738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
10115738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                memcpy(p_clcb->read_uuid128.result.value.incl_service.service_type.uu.uuid128, p, len);
10125738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                p_clcb->read_uuid128.result.value.incl_service.service_type.len = LEN_UUID_128;
10135738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                if ( p_clcb->p_reg->app_cb.p_disc_res_cb)
10145738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                    (*p_clcb->p_reg->app_cb.p_disc_res_cb)(p_clcb->conn_id, p_clcb->op_subtype, &p_clcb->read_uuid128.result);
10155738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                gatt_act_discovery(p_clcb) ;
10165738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            }
10175738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            else
10185738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            {
10195738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                gatt_end_operation(p_clcb, GATT_INVALID_PDU, (void *)p);
10205738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            }
10215738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        }
10225738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
10235738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
10245738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project}
10255738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
10265738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
10275738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/*******************************************************************************
10285738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
10295738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function         gatt_process_handle_rsp
10305738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
10315738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description      This function is called to handle the write response
10325738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
10335738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
10345738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns          void
10355738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
10365738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/
1037ccf9c15f52eea21858d994601d71308e84c7c859Andre Eisenbachvoid gatt_process_handle_rsp(tGATT_CLCB *p_clcb)
10385738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{
1039ccf9c15f52eea21858d994601d71308e84c7c859Andre Eisenbach    gatt_end_operation(p_clcb, GATT_SUCCESS, NULL);
10405738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project}
10415738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/*******************************************************************************
10425738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
10435738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function         gatt_process_mtu_rsp
10445738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
10455738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description      This function is called to process the configure MTU response.
10465738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
10475738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
10485738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns          void
10495738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
10505738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/
10515738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectvoid gatt_process_mtu_rsp(tGATT_TCB *p_tcb, tGATT_CLCB *p_clcb, UINT16 len, UINT8 *p_data)
10525738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{
10535738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    UINT16 mtu;
1054ccf9c15f52eea21858d994601d71308e84c7c859Andre Eisenbach    tGATT_STATUS    status = GATT_SUCCESS;
10555738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
1056ccf9c15f52eea21858d994601d71308e84c7c859Andre Eisenbach    if (len < GATT_MTU_RSP_MIN_LEN)
1057ccf9c15f52eea21858d994601d71308e84c7c859Andre Eisenbach    {
1058b44cc59d286ad255e872c60df02e032bd8d9d75bSharvil Nanavati        GATT_TRACE_ERROR("invalid MTU response PDU received, discard.");
1059ccf9c15f52eea21858d994601d71308e84c7c859Andre Eisenbach        status = GATT_INVALID_PDU;
1060ccf9c15f52eea21858d994601d71308e84c7c859Andre Eisenbach    }
1061ccf9c15f52eea21858d994601d71308e84c7c859Andre Eisenbach    else
1062ccf9c15f52eea21858d994601d71308e84c7c859Andre Eisenbach    {
10635738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    STREAM_TO_UINT16(mtu, p_data);
10645738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
10655738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    if (mtu < p_tcb->payload_size && mtu >= GATT_DEF_BLE_MTU_SIZE)
10665738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        p_tcb->payload_size = mtu;
1067ccf9c15f52eea21858d994601d71308e84c7c859Andre Eisenbach    }
10685738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
1069636d6714a4c08dd99d2147dcce05dc3892e804b4Priti Aghera    l2cble_set_fixed_channel_tx_data_length(p_tcb->peer_bda, L2CAP_ATT_CID, p_tcb->payload_size);
1070ccf9c15f52eea21858d994601d71308e84c7c859Andre Eisenbach    gatt_end_operation(p_clcb, status, NULL);
10715738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project}
10725738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/*******************************************************************************
10735738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
10745738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function         gatt_cmd_to_rsp_code
10755738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
10765738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description      The function convert a ATT command op code into the corresponding
10775738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**                  response code assume no error occurs.
10785738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
10795738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns          response code.
10805738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
10815738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/
10825738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source ProjectUINT8 gatt_cmd_to_rsp_code (UINT8 cmd_code)
10835738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{
10845738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    UINT8   rsp_code  = 0;
10855738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
10865738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    if (cmd_code > 1 && cmd_code != GATT_CMD_WRITE)
10875738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
10885738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        rsp_code = cmd_code + 1;
10895738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
10905738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    return rsp_code;
10915738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project}
10925738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/*******************************************************************************
10935738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
10945738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function         gatt_cl_send_next_cmd_inq
10955738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
10965738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description      Find next command in queue and sent to server
10975738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
10985738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns          TRUE if command sent, otherwise FALSE.
10995738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
11005738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/
11015738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source ProjectBOOLEAN gatt_cl_send_next_cmd_inq(tGATT_TCB *p_tcb)
11025738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{
11035738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tGATT_CMD_Q  *p_cmd = &p_tcb->cl_cmd_q[p_tcb->pending_cl_req];
11045738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    BOOLEAN     sent = FALSE;
1105ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    UINT8       rsp_code;
1106ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    tGATT_CLCB   *p_clcb = NULL;
110717b04bd498405f2bb109a85562ebbdcb6bb06e95Andre Eisenbach    tGATT_STATUS att_ret = GATT_SUCCESS;
11085738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
11095738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    while (!sent &&
11105738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project           p_tcb->pending_cl_req != p_tcb->next_slot_inq &&
11115738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project           p_cmd->to_send && p_cmd->p_cmd != NULL)
11125738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
111317b04bd498405f2bb109a85562ebbdcb6bb06e95Andre Eisenbach        att_ret = attp_send_msg_to_l2cap(p_tcb, p_cmd->p_cmd);
11145738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
111517b04bd498405f2bb109a85562ebbdcb6bb06e95Andre Eisenbach        if (att_ret == GATT_SUCCESS || att_ret == GATT_CONGESTED)
11165738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        {
111717b04bd498405f2bb109a85562ebbdcb6bb06e95Andre Eisenbach            sent = TRUE;
11185738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            p_cmd->to_send = FALSE;
11195738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            p_cmd->p_cmd = NULL;
11205738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
1121ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta            /* dequeue the request if is write command or sign write */
1122ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta            if (p_cmd->op_code != GATT_CMD_WRITE && p_cmd->op_code != GATT_SIGN_CMD_WRITE)
1123ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta            {
11245fba60a8761b28adec2704dcbf69376ebde4f19bZhihai Xu                gatt_start_rsp_timer (p_cmd->clcb_idx);
1125ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta            }
1126ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta            else
1127ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta            {
1128ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta                p_clcb = gatt_cmd_dequeue(p_tcb, &rsp_code);
1129ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta
1130ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta                /* if no ack needed, keep sending */
113117b04bd498405f2bb109a85562ebbdcb6bb06e95Andre Eisenbach                if (att_ret == GATT_SUCCESS)
113217b04bd498405f2bb109a85562ebbdcb6bb06e95Andre Eisenbach                    sent = FALSE;
113317b04bd498405f2bb109a85562ebbdcb6bb06e95Andre Eisenbach
1134ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta                p_cmd = &p_tcb->cl_cmd_q[p_tcb->pending_cl_req];
1135ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta                /* send command complete callback here */
113617b04bd498405f2bb109a85562ebbdcb6bb06e95Andre Eisenbach                gatt_end_operation(p_clcb, att_ret, NULL);
1137ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta            }
11385738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        }
11395738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        else
11405738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        {
1141b44cc59d286ad255e872c60df02e032bd8d9d75bSharvil Nanavati            GATT_TRACE_ERROR("gatt_cl_send_next_cmd_inq: L2CAP sent error");
11425738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
11435738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            memset(p_cmd, 0, sizeof(tGATT_CMD_Q));
11445738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            p_tcb->pending_cl_req ++;
11455738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            p_cmd = &p_tcb->cl_cmd_q[p_tcb->pending_cl_req];
11465738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        }
1147ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta
11485738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
11495738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    return sent;
11505738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project}
11515738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
11525738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/*******************************************************************************
11535738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
11545738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function         gatt_client_handle_server_rsp
11555738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
11565738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description      This function is called to handle the server response to
11575738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**                  client.
11585738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
11595738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
11605738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns          void
11615738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
11625738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/
11635738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectvoid gatt_client_handle_server_rsp (tGATT_TCB *p_tcb, UINT8 op_code,
11645738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                                    UINT16 len, UINT8 *p_data)
11655738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{
11665738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tGATT_CLCB   *p_clcb = NULL;
11675738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    UINT8        rsp_code;
11685738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
11695738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    if (op_code != GATT_HANDLE_VALUE_IND && op_code != GATT_HANDLE_VALUE_NOTIF)
11705738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
11715738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        p_clcb = gatt_cmd_dequeue(p_tcb, &rsp_code);
11725738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
11735738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        rsp_code = gatt_cmd_to_rsp_code(rsp_code);
11745738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
11755738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        if (p_clcb == NULL || (rsp_code != op_code && op_code != GATT_RSP_ERROR))
11765738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        {
1177b44cc59d286ad255e872c60df02e032bd8d9d75bSharvil Nanavati            GATT_TRACE_WARNING ("ATT - Ignore wrong response. Receives (%02x) \
11785738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                                Request(%02x) Ignored", op_code, rsp_code);
11795738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
11805738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            return;
11815738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        }
11825738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        else
11835fba60a8761b28adec2704dcbf69376ebde4f19bZhihai Xu        {
11845fba60a8761b28adec2704dcbf69376ebde4f19bZhihai Xu            btu_stop_timer (&p_clcb->rsp_timer_ent);
11855fba60a8761b28adec2704dcbf69376ebde4f19bZhihai Xu            p_clcb->retry_count = 0;
11865fba60a8761b28adec2704dcbf69376ebde4f19bZhihai Xu        }
11875738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
11885738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    /* the size of the message may not be bigger than the local max PDU size*/
11895738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    /* The message has to be smaller than the agreed MTU, len does not count op_code */
11905738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    if (len >= p_tcb->payload_size)
11915738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
1192b44cc59d286ad255e872c60df02e032bd8d9d75bSharvil Nanavati        GATT_TRACE_ERROR("invalid response/indicate pkt size: %d, PDU size: %d", len + 1, p_tcb->payload_size);
11935738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        if (op_code != GATT_HANDLE_VALUE_NOTIF &&
11945738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            op_code != GATT_HANDLE_VALUE_IND)
11955738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            gatt_end_operation(p_clcb, GATT_ERROR, NULL);
11965738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
11975738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    else
11985738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
11995738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        switch (op_code)
12005738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        {
12015738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            case GATT_RSP_ERROR:
12027fa4fba6f59f97df00aff07dbe8fb21b114b3c2cGanesh Ganapathi Batta                gatt_process_error_rsp(p_tcb, p_clcb, op_code, len, p_data);
12035738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                break;
12045738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
12055738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            case GATT_RSP_MTU:       /* 2 bytes mtu */
12065738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                gatt_process_mtu_rsp(p_tcb, p_clcb, len ,p_data);
12075738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                break;
12085738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
12095738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            case GATT_RSP_FIND_INFO:
12107fa4fba6f59f97df00aff07dbe8fb21b114b3c2cGanesh Ganapathi Batta                gatt_process_read_info_rsp(p_tcb, p_clcb, op_code, len, p_data);
12115738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                break;
12125738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
12135738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            case GATT_RSP_READ_BY_TYPE:
12145738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            case GATT_RSP_READ_BY_GRP_TYPE:
12155738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                gatt_process_read_by_type_rsp(p_tcb, p_clcb, op_code, len, p_data);
12165738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                break;
12175738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
12185738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            case GATT_RSP_READ:
12195738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            case GATT_RSP_READ_BLOB:
12205738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            case GATT_RSP_READ_MULTI:
12217fa4fba6f59f97df00aff07dbe8fb21b114b3c2cGanesh Ganapathi Batta                gatt_process_read_rsp(p_tcb, p_clcb, op_code, len, p_data);
12225738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                break;
12235738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
12245738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            case GATT_RSP_FIND_TYPE_VALUE: /* disc service with UUID */
12257fa4fba6f59f97df00aff07dbe8fb21b114b3c2cGanesh Ganapathi Batta                gatt_process_find_type_value_rsp(p_tcb, p_clcb, len, p_data);
12265738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                break;
12275738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
12285738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            case GATT_RSP_WRITE:
1229ccf9c15f52eea21858d994601d71308e84c7c859Andre Eisenbach                gatt_process_handle_rsp(p_clcb);
12305738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                break;
12315738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
12325738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            case GATT_RSP_PREPARE_WRITE:
12335738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                gatt_process_prep_write_rsp(p_tcb, p_clcb, op_code, len, p_data);
12345738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                break;
12355738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
12365738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            case GATT_RSP_EXEC_WRITE:
12375738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                gatt_end_operation(p_clcb, p_clcb->status, NULL);
12385738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                break;
12395738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
12405738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            case GATT_HANDLE_VALUE_NOTIF:
12415738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            case GATT_HANDLE_VALUE_IND:
12425738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                gatt_process_notification(p_tcb, op_code, len, p_data);
12435738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                break;
12445738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
12455738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            default:
1246b44cc59d286ad255e872c60df02e032bd8d9d75bSharvil Nanavati                GATT_TRACE_ERROR("Unknown opcode = %d", op_code);
12475738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                break;
12485738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        }
12495738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
12505738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
12515738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    if (op_code != GATT_HANDLE_VALUE_IND && op_code != GATT_HANDLE_VALUE_NOTIF)
12525738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
12535738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        gatt_cl_send_next_cmd_inq(p_tcb);
12545738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
12555738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
12565738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    return;
12575738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project}
12585738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
12595738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project#endif  /* BLE_INCLUDED */
1260