15738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/******************************************************************************
25738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project *
35738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project *  Copyright (C) 2003-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 GATT client action functions for the state
225738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project *  machine.
235738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project *
245738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project ******************************************************************************/
255738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
265738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project#include "bt_target.h"
275738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
285738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project#include "utl.h"
295738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project#include "gki.h"
305738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project#include "bd.h"
315738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project#include "bta_sys.h"
325738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
335738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project#include "bta_gattc_int.h"
345738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project#include "l2c_api.h"
355738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
3636b686527892172cb44091d160b7d2806d49fc76Zhihai Xu#if (defined BTA_HH_LE_INCLUDED && BTA_HH_LE_INCLUDED == TRUE)
3736b686527892172cb44091d160b7d2806d49fc76Zhihai Xu#include "bta_hh_int.h"
3836b686527892172cb44091d160b7d2806d49fc76Zhihai Xu#endif
395738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
405738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project#include <string.h>
415738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
42e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach#if BTA_GATT_INCLUDED && BLE_INCLUDED == TRUE
43e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach
445738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/*****************************************************************************
455738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**  Constants
465738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*****************************************************************************/
475738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectstatic void bta_gattc_conn_cback(tGATT_IF gattc_if, BD_ADDR bda, UINT16 conn_id,
485738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                                 BOOLEAN connected, tGATT_DISCONN_REASON reason);
495738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
505738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectstatic void  bta_gattc_cmpl_cback(UINT16 conn_id, tGATTC_OPTYPE op, tGATT_STATUS status,
515738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                                  tGATT_CL_COMPLETE *p_data);
525738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
53e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbachstatic void bta_gattc_deregister_cmpl(tBTA_GATTC_RCB *p_clreg);
54e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach
55b9912730d082c7bca7d94bb9ddac4447cfad362fZhihai Xustatic void bta_gattc_enc_cmpl_cback(tGATT_IF gattc_if, BD_ADDR bda);
56b9912730d082c7bca7d94bb9ddac4447cfad362fZhihai Xu
575738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectstatic tGATT_CBACK bta_gattc_cl_cback =
585738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{
595738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    bta_gattc_conn_cback,
605738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    bta_gattc_cmpl_cback,
615738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    bta_gattc_disc_res_cback,
625738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    bta_gattc_disc_cmpl_cback,
63b9912730d082c7bca7d94bb9ddac4447cfad362fZhihai Xu    NULL,
64b9912730d082c7bca7d94bb9ddac4447cfad362fZhihai Xu    bta_gattc_enc_cmpl_cback
655738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project};
665738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
675738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/* opcode(tGATTC_OPTYPE) order has to be comply with internal event order */
685738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectstatic UINT16 bta_gattc_opcode_to_int_evt[] =
695738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{
705738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    BTA_GATTC_API_READ_EVT,
715738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    BTA_GATTC_API_WRITE_EVT,
725738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    BTA_GATTC_API_EXEC_EVT
735738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project};
745738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
755738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project#if (BT_TRACE_VERBOSE == TRUE)
765738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectstatic const char *bta_gattc_op_code_name[] =
775738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{
785738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    "Unknown",
795738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    "Discovery",
805738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    "Read",
815738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    "Write",
825738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    "Exec",
835738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    "Config",
845738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    "Notification",
855738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    "Indication"
865738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project};
875738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project#endif
885738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/*****************************************************************************
895738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**  Action Functions
905738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*****************************************************************************/
915738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
925738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/*******************************************************************************
935738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
94e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach** Function         bta_gattc_enable
95e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach**
96e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach** Description      Enables GATTC module
97e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach**
98e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach**
99e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach** Returns          void
100e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach**
101e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach*******************************************************************************/
102e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbachstatic void bta_gattc_enable(tBTA_GATTC_CB *p_cb)
103e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach{
104e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach    APPL_TRACE_DEBUG0("bta_gattc_enable");
105e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach
106e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach    if (p_cb->state == BTA_GATTC_STATE_DISABLED)
107e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach    {
108e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach        /* initialize control block */
109e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach        memset(&bta_gattc_cb, 0, sizeof(tBTA_GATTC_CB));
110e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach        p_cb->state = BTA_GATTC_STATE_ENABLED;
111e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach    }
112e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach    else
113e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach    {
114e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach        APPL_TRACE_DEBUG0("GATTC is arelady enabled");
115e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach    }
116e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach}
117e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach
118e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach
119e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach/*******************************************************************************
120e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach**
121e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach** Function         bta_gattc_disable
122e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach**
123e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach** Description      Disable GATTC module by cleaning up all active connections
124e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach**                  and deregister all application.
125e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach**
126e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach** Returns          void
127e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach**
128e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach*******************************************************************************/
129e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbachvoid bta_gattc_disable(tBTA_GATTC_CB *p_cb)
130e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach{
131e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach    UINT8           i;
132e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach
133e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach    APPL_TRACE_DEBUG0("bta_gattc_disable");
134e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach
135e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach    if (p_cb->state != BTA_GATTC_STATE_ENABLED)
136e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach    {
137e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach        APPL_TRACE_ERROR0("not enabled or disable in pogress");
138e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach        return;
139e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach    }
140e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach
141e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach    for (i = 0; i <BTA_GATTC_CL_MAX; i ++)
142e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach    {
143e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach        if (p_cb->cl_rcb[i].in_use)
144e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach        {
145e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach            p_cb->state = BTA_GATTC_STATE_DISABLING;
14636b686527892172cb44091d160b7d2806d49fc76Zhihai Xu            /* don't deregister HH GATT IF */
14736b686527892172cb44091d160b7d2806d49fc76Zhihai Xu            /* HH GATT IF will be deregistered by bta_hh_le_deregister when disable HH */
14836b686527892172cb44091d160b7d2806d49fc76Zhihai Xu#if (defined BTA_HH_LE_INCLUDED && BTA_HH_LE_INCLUDED == TRUE)
14936b686527892172cb44091d160b7d2806d49fc76Zhihai Xu            if (!bta_hh_le_is_hh_gatt_if(p_cb->cl_rcb[i].client_if)) {
15036b686527892172cb44091d160b7d2806d49fc76Zhihai Xu#endif
15136b686527892172cb44091d160b7d2806d49fc76Zhihai Xu                bta_gattc_deregister(p_cb, &p_cb->cl_rcb[i]);
15236b686527892172cb44091d160b7d2806d49fc76Zhihai Xu#if (defined BTA_HH_LE_INCLUDED && BTA_HH_LE_INCLUDED == TRUE)
15336b686527892172cb44091d160b7d2806d49fc76Zhihai Xu            }
15436b686527892172cb44091d160b7d2806d49fc76Zhihai Xu#endif
155e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach        }
156e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach    }
157e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach
158e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach    /* no registered apps, indicate disable completed */
159e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach    if (p_cb->state != BTA_GATTC_STATE_DISABLING)
160e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach    {
161e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach        p_cb->state = BTA_GATTC_STATE_DISABLED;
162e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach        memset(p_cb, 0, sizeof(tBTA_GATTC_CB));
163e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach    }
164e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach}
165e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach
166e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach/*******************************************************************************
167e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach**
1685738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function         bta_gattc_register
1695738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
1705738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description      Register a GATT client application with BTA.
1715738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
1725738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns          void
1735738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
1745738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/
1755738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectvoid bta_gattc_register(tBTA_GATTC_CB *p_cb, tBTA_GATTC_DATA *p_data)
1765738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{
1775738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tBTA_GATTC               cb_data;
1785738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    UINT8                    i;
1795738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tBT_UUID                 *p_app_uuid = &p_data->api_reg.app_uuid;
1805738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tBTA_GATTC_INT_START_IF  *p_buf;
1815f63da7ae32d35c42281b999f63e544fec2b705eAndre Eisenbach    tBTA_GATT_STATUS         status = BTA_GATT_NO_RESOURCES;
1825738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
183781b5adee20e222ef87b56b72bfcd3f64013e4a0Andre Eisenbach
184781b5adee20e222ef87b56b72bfcd3f64013e4a0Andre Eisenbach    APPL_TRACE_DEBUG1("bta_gattc_register state %d",p_cb->state);
185781b5adee20e222ef87b56b72bfcd3f64013e4a0Andre Eisenbach    memset(&cb_data, 0, sizeof(cb_data));
186781b5adee20e222ef87b56b72bfcd3f64013e4a0Andre Eisenbach    cb_data.reg_oper.status = BTA_GATT_NO_RESOURCES;
187e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach
188e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach     /* check if  GATTC module is already enabled . Else enable */
189e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach     if (p_cb->state == BTA_GATTC_STATE_DISABLED)
190e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach     {
191e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach         bta_gattc_enable (p_cb);
192e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach     }
1935738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    /* todo need to check duplicate uuid */
1945738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    for (i = 0; i < BTA_GATTC_CL_MAX; i ++)
1955738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
1965738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        if (!p_cb->cl_rcb[i].in_use)
1975738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        {
1985738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            if ((p_app_uuid == NULL) || (p_cb->cl_rcb[i].client_if = GATT_Register(p_app_uuid, &bta_gattc_cl_cback)) == 0)
1995738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            {
2005738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                APPL_TRACE_ERROR0("Register with GATT stack failed.");
2015f63da7ae32d35c42281b999f63e544fec2b705eAndre Eisenbach                status = BTA_GATT_ERROR;
2025738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            }
2035738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            else
2045738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            {
2055738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                p_cb->cl_rcb[i].in_use = TRUE;
2065738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                p_cb->cl_rcb[i].p_cback = p_data->api_reg.p_cback;
2075738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                memcpy(&p_cb->cl_rcb[i].app_uuid, p_app_uuid, sizeof(tBT_UUID));
2085738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
2095738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                /* BTA use the same client interface as BTE GATT statck */
2105738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                cb_data.reg_oper.client_if = p_cb->cl_rcb[i].client_if;
2115738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
2125738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                if ((p_buf = (tBTA_GATTC_INT_START_IF *) GKI_getbuf(sizeof(tBTA_GATTC_INT_START_IF))) != NULL)
2135738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                {
2145738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                    p_buf->hdr.event    = BTA_GATTC_INT_START_IF_EVT;
2155738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                    p_buf->client_if    = p_cb->cl_rcb[i].client_if;
2165738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
2175738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                    bta_sys_sendmsg(p_buf);
2185f63da7ae32d35c42281b999f63e544fec2b705eAndre Eisenbach                    status = BTA_GATT_OK;
2195738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                }
2205738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                else
2215738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                {
222e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach                    GATT_Deregister(p_cb->cl_rcb[i].client_if);
223e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach
224e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach                    status = BTA_GATT_NO_RESOURCES;
2255738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                    memset( &p_cb->cl_rcb[i], 0 , sizeof(tBTA_GATTC_RCB));
2265738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                }
2275738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                break;
2285738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            }
2295738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        }
2305738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
2315f63da7ae32d35c42281b999f63e544fec2b705eAndre Eisenbach
2325738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    /* callback with register event */
2335738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    if (p_data->api_reg.p_cback)
2345738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
235dda9a3e71119078181638cf3f5a51e38d173f6d4Andre Eisenbach        if (p_app_uuid != NULL)
236dda9a3e71119078181638cf3f5a51e38d173f6d4Andre Eisenbach            memcpy(&(cb_data.reg_oper.app_uuid),p_app_uuid,sizeof(tBT_UUID));
237dda9a3e71119078181638cf3f5a51e38d173f6d4Andre Eisenbach
2385f63da7ae32d35c42281b999f63e544fec2b705eAndre Eisenbach        cb_data.reg_oper.status = status;
2395738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        (*p_data->api_reg.p_cback)(BTA_GATTC_REG_EVT,  (tBTA_GATTC *)&cb_data);
2405738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
2415738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project}
2425738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/*******************************************************************************
2435738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
2445738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function         bta_gattc_start_if
2455738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
2465738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description      start an application interface.
2475738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
2485738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns          none.
2495738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
2505738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/
2515738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectvoid bta_gattc_start_if(tBTA_GATTC_CB *p_cb, tBTA_GATTC_DATA *p_msg)
2525738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{
2535738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    if (bta_gattc_cl_get_regcb(p_msg->int_start_if.client_if) !=NULL )
2545738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
2555738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        GATT_StartIf(p_msg->int_start_if.client_if);
2565738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
2575738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    else
2585738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
2595738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        APPL_TRACE_ERROR1("Unable to start app.: Unknown interface =%d",p_msg->int_start_if.client_if );
2605738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
2615738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project}
2625738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/*******************************************************************************
2635738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
2645738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function         bta_gattc_deregister
2655738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
2665738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description      De-Register a GATT client application with BTA.
2675738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
2685738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns          void
2695738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
2705738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/
271e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbachvoid bta_gattc_deregister(tBTA_GATTC_CB *p_cb, tBTA_GATTC_RCB  *p_clreg)
2725738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{
2735738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    UINT8               i;
2745738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    BT_HDR              buf;
2755738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
276e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach    if (p_clreg != NULL)
2775738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
278e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach        /* remove bg connection associated with this rcb */
279e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach        for (i = 0; i < BTA_GATTC_KNOWN_SR_MAX; i ++)
280e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach        {
281e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach            if (p_cb->bg_track[i].in_use)
282e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach            {
283e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach                if (p_cb->bg_track[i].cif_mask & (1 <<(p_clreg->client_if - 1)))
284e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach                {
285e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach                    bta_gattc_mark_bg_conn(p_clreg->client_if, p_cb->bg_track[i].remote_bda, FALSE, FALSE);
286e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach                    GATT_CancelConnect(p_clreg->client_if, p_cb->bg_track[i].remote_bda, FALSE);
287e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach                }
288e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach                if (p_cb->bg_track[i].cif_adv_mask & (1 <<(p_clreg->client_if - 1)))
289e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach                {
290e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach                    bta_gattc_mark_bg_conn(p_clreg->client_if, p_cb->bg_track[i].remote_bda, FALSE, TRUE);
291e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach                }
292e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach            }
293e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach        }
294e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach
2955738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        if (p_clreg->num_clcb > 0)
2965738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        {
2975738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            /* close all CLCB related to this app */
2985738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            for (i= 0; i < BTA_GATTC_CLCB_MAX; i ++)
2995738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            {
3005738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                if (p_cb->clcb[i].in_use && (p_cb->clcb[i].p_rcb == p_clreg))
3015738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                {
3025738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                    p_clreg->dereg_pending = TRUE;
3035738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
3045738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                    buf.event = BTA_GATTC_API_CLOSE_EVT;
3055738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                    buf.layer_specific = p_cb->clcb[i].bta_conn_id;
3065738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                    bta_gattc_close(&p_cb->clcb[i], (tBTA_GATTC_DATA *)&buf)  ;
3075738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                }
3085738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            }
3095738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        }
3105738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        else
311e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach            bta_gattc_deregister_cmpl(p_clreg);
3125738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
3135738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    else
3145738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
315e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach        APPL_TRACE_ERROR0("bta_gattc_deregister Deregister Failedm unknown client cif");
3165738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
3175738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project}
3185738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/*******************************************************************************
3195738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
3205738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function         bta_gattc_process_api_open
3215738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
3225738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description      process connect API request.
3235738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
3245738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns          void
3255738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
3265738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/
3275738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectvoid bta_gattc_process_api_open (tBTA_GATTC_CB *p_cb, tBTA_GATTC_DATA * p_msg)
3285738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{
3295738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    UINT16 event = ((BT_HDR *)p_msg)->event;
3305738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tBTA_GATTC_CLCB *p_clcb = NULL;
3315738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tBTA_GATTC_RCB *p_clreg = bta_gattc_cl_get_regcb(p_msg->api_conn.client_if);
3325738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
3335738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    if (p_clreg != NULL)
3345738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
3355738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        if (p_msg->api_conn.is_direct)
3365738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        {
3375738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            if ((p_clcb = bta_gattc_find_alloc_clcb(p_msg->api_conn.client_if,
3385738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                                                    p_msg->api_conn.remote_bda)) != NULL)
3395738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            {
3405738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                bta_gattc_sm_execute(p_clcb, event, p_msg);
3415738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            }
3425738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            else
3435738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            {
3445738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                APPL_TRACE_ERROR0("No resources to open a new connection.");
3455738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
3465738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                bta_gattc_send_open_cback(p_clreg,
3475738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                                          BTA_GATT_NO_RESOURCES,
3485738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                                          p_msg->api_conn.remote_bda,
3495738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                                          BTA_GATT_INVALID_CONN_ID);
3505738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            }
3515738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        }
3525738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        else
3535738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        {
3545738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            bta_gattc_init_bk_conn(&p_msg->api_conn, p_clreg);
3555738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        }
3565738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
3575738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    else
3585738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
3595738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        APPL_TRACE_ERROR1("bta_gattc_process_api_open Failed, unknown client_if: %d",
3605738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                        p_msg->api_conn.client_if);
3615738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
3625738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project}
3635738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/*******************************************************************************
3645738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
3655738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function         bta_gattc_process_api_open_cancel
3665738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
3675738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description      process connect API request.
3685738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
3695738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns          void
3705738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
3715738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/
3725738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectvoid bta_gattc_process_api_open_cancel (tBTA_GATTC_CB *p_cb, tBTA_GATTC_DATA * p_msg)
3735738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{
3745738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    UINT16 event = ((BT_HDR *)p_msg)->event;
3755738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tBTA_GATTC_CLCB *p_clcb = NULL;
3765738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tBTA_GATTC_RCB *p_clreg;
377ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    tBTA_GATTC cb_data;
3785738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
3795738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    if (p_msg->api_cancel_conn.is_direct)
3805738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
3815738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        if ((p_clcb = bta_gattc_find_clcb_by_cif(p_msg->api_cancel_conn.client_if,
3825738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                                                 p_msg->api_cancel_conn.remote_bda)) != NULL)
3835738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        {
3845738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            bta_gattc_sm_execute(p_clcb, event, p_msg);
3855738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        }
3865738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        else
3875738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        {
3885738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            APPL_TRACE_ERROR0("No such connection need to be cancelled");
3895738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
3905738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            p_clreg = bta_gattc_cl_get_regcb(p_msg->api_cancel_conn.client_if);
3915738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
3925738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            if (p_clreg && p_clreg->p_cback)
3935738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            {
394ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta                cb_data.status = BTA_GATT_ERROR;
395ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta                (*p_clreg->p_cback)(BTA_GATTC_CANCEL_OPEN_EVT, &cb_data);
3965738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            }
3975738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        }
3985738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
3995738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    else
4005738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
4015738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        bta_gattc_cancel_bk_conn(&p_msg->api_cancel_conn);
4025738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
4035738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
4045738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project}
405b9912730d082c7bca7d94bb9ddac4447cfad362fZhihai Xu
406b9912730d082c7bca7d94bb9ddac4447cfad362fZhihai Xu/*******************************************************************************
407b9912730d082c7bca7d94bb9ddac4447cfad362fZhihai Xu**
408b9912730d082c7bca7d94bb9ddac4447cfad362fZhihai Xu** Function         bta_gattc_process_enc_cmpl
409b9912730d082c7bca7d94bb9ddac4447cfad362fZhihai Xu**
410b9912730d082c7bca7d94bb9ddac4447cfad362fZhihai Xu** Description      process encryption complete message.
411b9912730d082c7bca7d94bb9ddac4447cfad362fZhihai Xu**
412b9912730d082c7bca7d94bb9ddac4447cfad362fZhihai Xu** Returns          void
413b9912730d082c7bca7d94bb9ddac4447cfad362fZhihai Xu**
414b9912730d082c7bca7d94bb9ddac4447cfad362fZhihai Xu*******************************************************************************/
415b9912730d082c7bca7d94bb9ddac4447cfad362fZhihai Xuvoid bta_gattc_process_enc_cmpl(tBTA_GATTC_CB *p_cb, tBTA_GATTC_DATA *p_msg)
416b9912730d082c7bca7d94bb9ddac4447cfad362fZhihai Xu{
417b9912730d082c7bca7d94bb9ddac4447cfad362fZhihai Xu    tBTA_GATTC_RCB *p_clreg;
418b9912730d082c7bca7d94bb9ddac4447cfad362fZhihai Xu    tBTA_GATTC cb_data;
419b9912730d082c7bca7d94bb9ddac4447cfad362fZhihai Xu
420b9912730d082c7bca7d94bb9ddac4447cfad362fZhihai Xu    p_clreg = bta_gattc_cl_get_regcb(p_msg->enc_cmpl.client_if);
421b9912730d082c7bca7d94bb9ddac4447cfad362fZhihai Xu
422b9912730d082c7bca7d94bb9ddac4447cfad362fZhihai Xu    if (p_clreg && p_clreg->p_cback)
423b9912730d082c7bca7d94bb9ddac4447cfad362fZhihai Xu    {
424b9912730d082c7bca7d94bb9ddac4447cfad362fZhihai Xu        memset(&cb_data, 0, sizeof(tBTA_GATTC));
425b9912730d082c7bca7d94bb9ddac4447cfad362fZhihai Xu
426b9912730d082c7bca7d94bb9ddac4447cfad362fZhihai Xu        cb_data.enc_cmpl.client_if = p_msg->enc_cmpl.client_if;
427b9912730d082c7bca7d94bb9ddac4447cfad362fZhihai Xu        bdcpy(cb_data.enc_cmpl.remote_bda, p_msg->enc_cmpl.remote_bda);
428b9912730d082c7bca7d94bb9ddac4447cfad362fZhihai Xu
429b9912730d082c7bca7d94bb9ddac4447cfad362fZhihai Xu        (*p_clreg->p_cback)(BTA_GATTC_ENC_CMPL_CB_EVT, &cb_data);
430b9912730d082c7bca7d94bb9ddac4447cfad362fZhihai Xu    }
431b9912730d082c7bca7d94bb9ddac4447cfad362fZhihai Xu}
432b9912730d082c7bca7d94bb9ddac4447cfad362fZhihai Xu
4335738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/*******************************************************************************
4345738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
4355738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function         bta_gattc_cancel_open_error
4365738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
4375738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description
4385738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
4395738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns          void
4405738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
4415738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/
4425738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectvoid bta_gattc_cancel_open_error(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data)
4435738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{
444ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    tBTA_GATTC cb_data;
445ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    cb_data.status=BTA_GATT_ERROR;
4465738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
447ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    if ( p_clcb && p_clcb->p_rcb && p_clcb->p_rcb->p_cback )
448ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta        (*p_clcb->p_rcb->p_cback)(BTA_GATTC_CANCEL_OPEN_EVT, &cb_data);
4495738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project}
4505738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
4515738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/*******************************************************************************
4525738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
4535738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function         bta_gattc_open_error
4545738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
4555738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description
4565738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
4575738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns          void
4585738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
4595738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/
4605738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectvoid bta_gattc_open_error(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data)
4615738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{
4625738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    APPL_TRACE_ERROR0("Connection already opened. wrong state");
4635738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
4645738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    bta_gattc_send_open_cback(p_clcb->p_rcb,
465e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach                              BTA_GATT_OK,
4665738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                              p_clcb->bda,
4675738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                              p_clcb->bta_conn_id);
4685738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project}
4695738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/*******************************************************************************
4705738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
4715738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function         bta_gattc_open_fail
4725738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
4735738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description
4745738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
4755738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns          void
4765738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
4775738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/
4785738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectvoid bta_gattc_open_fail(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data)
4795738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{
480e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach    bta_gattc_send_open_cback(p_clcb->p_rcb,
481e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach                              BTA_GATT_ERROR,
482e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach                              p_clcb->bda,
483e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach                              p_clcb->bta_conn_id);
484e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach
4855738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    /* open failure, remove clcb */
4865738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    bta_gattc_clcb_dealloc(p_clcb);
4875738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project}
4885738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
4895738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/*******************************************************************************
4905738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
4915738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function         bta_gattc_open
4925738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
4935738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description      Process API connection function.
4945738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
4955738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns          void
4965738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
4975738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/
4985738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectvoid bta_gattc_open(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data)
4995738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{
5005738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tBTA_GATTC_DATA gattc_data;
5015738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
5025738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    /* open/hold a connection */
5035738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    if (!GATT_Connect(p_clcb->p_rcb->client_if, p_data->api_conn.remote_bda, TRUE))
5045738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
5055738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        APPL_TRACE_ERROR0("Connection open failure");
5065738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
5075738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        bta_gattc_sm_execute(p_clcb, BTA_GATTC_INT_OPEN_FAIL_EVT, p_data);
5085738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
5095738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    else
5105738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
5115738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        /* a connected remote device */
5125738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        if (GATT_GetConnIdIfConnected(p_clcb->p_rcb->client_if,
5135738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                                      p_data->api_conn.remote_bda,
5145738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                                      &p_clcb->bta_conn_id))
5155738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        {
5166975b4d711142b885af479721cada448952c6b41Andre Eisenbach            gattc_data.int_conn.hdr.layer_specific = p_clcb->bta_conn_id;
5175738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
5185738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            bta_gattc_sm_execute(p_clcb, BTA_GATTC_INT_CONN_EVT, &gattc_data);
5195738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        }
5205738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        /* else wait for the callback event */
5215738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
5225738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project}
5235738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/*******************************************************************************
5245738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
5255738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function         bta_gattc_init_bk_conn
5265738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
5275738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description      Process API Open for a background connection
5285738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
5295738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns          void
5305738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
5315738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/
5325738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectvoid bta_gattc_init_bk_conn(tBTA_GATTC_API_OPEN *p_data, tBTA_GATTC_RCB *p_clreg)
5335738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{
5345738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tBTA_GATT_STATUS         status = BTA_GATT_NO_RESOURCES;
5355738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    UINT16                   conn_id;
5365738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tBTA_GATTC_CLCB         *p_clcb;
5375738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tBTA_GATTC_DATA         gattc_data;
5385738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
539ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    if (bta_gattc_mark_bg_conn(p_data->client_if, p_data->remote_bda, TRUE, FALSE))
5405738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
5415738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        /* alwaya call open to hold a connection */
5425738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        if (!GATT_Connect(p_data->client_if, p_data->remote_bda, FALSE))
5435738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        {
5445738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            status = BTA_GATT_ERROR;
5455738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            APPL_TRACE_ERROR0("bta_gattc_init_bk_conn failed");
5465738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        }
5475738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        else
5485738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        {
5495738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            status = BTA_GATT_OK;
5505738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
5515738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            /* if is a connected remote device */
5525738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            if (GATT_GetConnIdIfConnected(p_data->client_if,
5535738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                                          p_data->remote_bda,
5545738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                                          &conn_id))
5555738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            {
5566975b4d711142b885af479721cada448952c6b41Andre Eisenbach                if ((p_clcb = bta_gattc_find_alloc_clcb(p_data->client_if, p_data->remote_bda)) != NULL)
5575738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                {
5585738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                    gattc_data.hdr.layer_specific = p_clcb->bta_conn_id = conn_id;
5595738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
5605738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                    /* open connection */
5615738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                    bta_gattc_sm_execute(p_clcb, BTA_GATTC_INT_CONN_EVT, &gattc_data);
5625738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                    status = BTA_GATT_OK;
5635738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                }
5645738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            }
5655738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        }
5665738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
5675738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
5685738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    /* open failure, report OPEN_EVT */
5695738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    if (status != BTA_GATT_OK)
5705738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
5715738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        bta_gattc_send_open_cback(p_clreg, status, p_data->remote_bda, BTA_GATT_INVALID_CONN_ID);
5725738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
5735738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project}
5745738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/*******************************************************************************
5755738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
5765738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function         bta_gattc_cancel_bk_conn
5775738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
5785738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description      Process API Cancel Open for a background connection
5795738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
5805738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns          void
5815738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
5825738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/
5835738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectvoid bta_gattc_cancel_bk_conn(tBTA_GATTC_API_CANCEL_OPEN *p_data)
5845738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{
5855738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tBTA_GATTC_RCB      *p_clreg;
586ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    tBTA_GATTC          cb_data;
587ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    cb_data.status = BTA_GATT_ERROR;
5885738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
5895738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    /* remove the device from the bg connection mask */
590ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    if (bta_gattc_mark_bg_conn(p_data->client_if, p_data->remote_bda, FALSE, FALSE))
5915738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
5925738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        if (GATT_CancelConnect(p_data->client_if, p_data->remote_bda, FALSE))
5935738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        {
594ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta            cb_data.status = BTA_GATT_OK;
5955738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        }
5965738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        else
5975738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        {
5985738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            APPL_TRACE_ERROR0("bta_gattc_cancel_bk_conn failed");
5995738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        }
6005738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
6015738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    p_clreg = bta_gattc_cl_get_regcb(p_data->client_if);
6025738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
6035738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    if (p_clreg && p_clreg->p_cback)
6045738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
605ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta        (*p_clreg->p_cback)(BTA_GATTC_CANCEL_OPEN_EVT, &cb_data);
6065738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
6075738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
6085738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project}
6095738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/*******************************************************************************
6105738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
6115738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function         bta_gattc_int_cancel_open_ok
6125738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
6135738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description
6145738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
6155738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns          void
6165738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
6175738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/
6185738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectvoid bta_gattc_cancel_open_ok(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data)
6195738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{
620ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    tBTA_GATTC          cb_data;
6215738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
6225738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    if ( p_clcb->p_rcb->p_cback )
6235738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
624ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta        cb_data.status = BTA_GATT_OK;
625ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta        (*p_clcb->p_rcb->p_cback)(BTA_GATTC_CANCEL_OPEN_EVT, &cb_data);
6265738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
6275738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
6285738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    bta_gattc_clcb_dealloc(p_clcb);
6295738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project}
6305738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/*******************************************************************************
6315738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
6325738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function         bta_gattc_cancel_open
6335738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
6345738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description
6355738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
6365738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns          void
6375738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
6385738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/
6395738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectvoid bta_gattc_cancel_open(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data)
6405738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{
641ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    tBTA_GATTC          cb_data;
6425738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
6435738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    if (GATT_CancelConnect(p_clcb->p_rcb->client_if, p_data->api_cancel_conn.remote_bda, TRUE))
6445738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
6455738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        bta_gattc_sm_execute(p_clcb, BTA_GATTC_INT_CANCEL_OPEN_OK_EVT, p_data);
6465738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
6475738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    else
6485738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
6495738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        if ( p_clcb->p_rcb->p_cback )
6505738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        {
651ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta            cb_data.status = BTA_GATT_ERROR;
652ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta            (*p_clcb->p_rcb->p_cback)(BTA_GATTC_CANCEL_OPEN_EVT, &cb_data);
6535738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        }
6545738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
6555738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project}
6565738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/*******************************************************************************
6575738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
6585738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function         bta_gattc_conn
6595738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
6605738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description      receive connection callback from stack
6615738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
6625738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns          void
6635738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
6645738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/
6655738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectvoid bta_gattc_conn(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data)
6665738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{
6675738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tBTA_GATTC_IF   gatt_if;
6685738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    APPL_TRACE_DEBUG1("bta_gattc_conn server cache state=%d",p_clcb->p_srcb->state);
6695738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
6705738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    if (p_data != NULL)
6715738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
6725738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        APPL_TRACE_DEBUG1("bta_gattc_conn conn_id=%d",p_data->hdr.layer_specific);
6736975b4d711142b885af479721cada448952c6b41Andre Eisenbach        p_clcb->bta_conn_id  = p_data->int_conn.hdr.layer_specific;
6746975b4d711142b885af479721cada448952c6b41Andre Eisenbach        GATT_GetConnectionInfor(p_data->int_conn.hdr.layer_specific, &gatt_if, p_clcb->bda);
6756975b4d711142b885af479721cada448952c6b41Andre Eisenbach    }
6765738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
6775738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        p_clcb->p_srcb->connected = TRUE;
6785738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        /* start database cache if needed */
679ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta        if (p_clcb->p_srcb->p_srvc_cache == NULL ||
680ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta            p_clcb->p_srcb->state != BTA_GATTC_SERV_IDLE)
6815738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        {
6825738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            if (p_clcb->p_srcb->state == BTA_GATTC_SERV_IDLE)
6835738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            {
6845738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                p_clcb->p_srcb->state = BTA_GATTC_SERV_LOAD;
6856975b4d711142b885af479721cada448952c6b41Andre Eisenbach                bta_gattc_sm_execute(p_clcb, BTA_GATTC_START_CACHE_EVT, NULL);
6865738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            }
6875738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            else /* cache is building */
6885738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                p_clcb->state = BTA_GATTC_DISCOVER_ST;
6895738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        }
6905738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
6915738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        else
6925738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        {
6935738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            /* a pending service handle change indication */
6945738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            if (p_clcb->p_srcb->srvc_hdl_chg)
6955738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            {
6965738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                p_clcb->p_srcb->srvc_hdl_chg = FALSE;
6975738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                /* start discovery */
6985738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                bta_gattc_sm_execute(p_clcb, BTA_GATTC_INT_DISCOVER_EVT, NULL);
6995738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            }
7005738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        }
7015738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
7025738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        if (p_clcb->p_rcb)
7035738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        {
704781b5adee20e222ef87b56b72bfcd3f64013e4a0Andre Eisenbach            /* there is no RM for GATT */
705781b5adee20e222ef87b56b72bfcd3f64013e4a0Andre Eisenbach            if (!BTM_IsBleLink(p_clcb->bda))
706781b5adee20e222ef87b56b72bfcd3f64013e4a0Andre Eisenbach                bta_sys_conn_open(BTA_ID_GATTC, BTA_ALL_APP_ID, p_clcb->bda);
7075738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            bta_gattc_send_open_cback(p_clcb->p_rcb,
7085738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                                      BTA_GATT_OK,
7095738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                                      p_clcb->bda,
7105738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                                      p_clcb->bta_conn_id);
7115738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        }
7125738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
7135738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/*******************************************************************************
7145738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
7155738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function         bta_gattc_close_fail
7165738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
7175738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description      close a  connection.
7185738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
7195738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns          void
7205738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
7215738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/
7225738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectvoid bta_gattc_close_fail(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data)
7235738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{
7245738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tBTA_GATTC           cb_data;
7255738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
7265738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    if ( p_clcb->p_rcb->p_cback )
7275738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
7285738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        memset(&cb_data, 0, sizeof(tBTA_GATTC));
7295738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        cb_data.close.client_if = p_clcb->p_rcb->client_if;
7305738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        cb_data.close.conn_id   = p_data->hdr.layer_specific;
7315738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        bdcpy(cb_data.close.remote_bda, p_clcb->bda);
7325738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        cb_data.close.status    = BTA_GATT_ERROR;
7335738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        cb_data.close.reason    = BTA_GATT_CONN_NONE;
7345738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
7355738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
7365738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        (*p_clcb->p_rcb->p_cback)(BTA_GATTC_CLOSE_EVT, &cb_data);
7375738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
7385738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project}
7395738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/*******************************************************************************
7405738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
7415738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function         bta_gattc_api_close
7425738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
7435738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description      close a GATTC connection.
7445738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
7455738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns          void
7465738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
7475738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/
7485738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectvoid bta_gattc_close(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data)
7495738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{
7505738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tBTA_GATTC_CBACK    *p_cback = p_clcb->p_rcb->p_cback;
7515738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tBTA_GATTC_RCB      *p_clreg = p_clcb->p_rcb;
7525738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tBTA_GATTC           cb_data;
7535738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
7545738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    APPL_TRACE_DEBUG1("bta_gattc_close conn_id=%d",p_clcb->bta_conn_id);
7555738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
7565738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    cb_data.close.client_if = p_clcb->p_rcb->client_if;
7575738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    cb_data.close.conn_id   = p_clcb->bta_conn_id;
7585738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    cb_data.close.reason    = p_clcb->reason;
759e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach    cb_data.close.status    = p_clcb->status;
7605738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    bdcpy(cb_data.close.remote_bda, p_clcb->bda);
7615738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
762781b5adee20e222ef87b56b72bfcd3f64013e4a0Andre Eisenbach    if (!BTM_IsBleLink(p_clcb->bda))
763781b5adee20e222ef87b56b72bfcd3f64013e4a0Andre Eisenbach        bta_sys_conn_close( BTA_ID_GATTC ,BTA_ALL_APP_ID, p_clcb->bda);
764781b5adee20e222ef87b56b72bfcd3f64013e4a0Andre Eisenbach
7656975b4d711142b885af479721cada448952c6b41Andre Eisenbach    bta_gattc_clcb_dealloc(p_clcb);
7665738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
767e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach    if (p_data->hdr.event == BTA_GATTC_API_CLOSE_EVT)
768e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach        cb_data.close.status = GATT_Disconnect(p_data->hdr.layer_specific);
769e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach
7706975b4d711142b885af479721cada448952c6b41Andre Eisenbach    if(p_cback)
7716975b4d711142b885af479721cada448952c6b41Andre Eisenbach        (* p_cback)(BTA_GATTC_CLOSE_EVT,   (tBTA_GATTC *)&cb_data);
7725738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
773ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    if (p_clreg->num_clcb == 0 && p_clreg->dereg_pending)
7745738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
775e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach        bta_gattc_deregister_cmpl(p_clreg);
7765738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
7775738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project}
7785738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/*******************************************************************************
7795738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
7805738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function         bta_gattc_reset_discover_st
7815738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
7825738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description      when a SRCB finished discovery, tell all related clcb.
7835738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
7845738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns          None.
7855738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
7865738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/
787ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Battavoid bta_gattc_reset_discover_st(tBTA_GATTC_SERV *p_srcb, tBTA_GATT_STATUS status)
7885738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{
7895738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tBTA_GATTC_CB   *p_cb = &bta_gattc_cb;
7905738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    UINT8 i;
7915738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
7925738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    for (i = 0; i < BTA_GATTC_CLCB_MAX; i ++)
7935738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
7945738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        if (p_cb->clcb[i].p_srcb == p_srcb)
7955738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        {
796ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta            p_cb->clcb[i].status = status;
7975738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            bta_gattc_sm_execute(&p_cb->clcb[i], BTA_GATTC_DISCOVER_CMPL_EVT, NULL);
7985738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        }
7995738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
8005738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project}
8015738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/*******************************************************************************
8025738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
803ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta** Function         bta_gattc_disc_close
804ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta**
805ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta** Description      close a GATTC connection while in discovery state.
806ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta**
807ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta** Returns          void
808ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta**
809ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta*******************************************************************************/
810ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Battavoid bta_gattc_disc_close(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data)
811ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta{
812ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    APPL_TRACE_DEBUG1("Discovery cancel conn_id=%d",p_clcb->bta_conn_id);
813ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta
814ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    bta_gattc_reset_discover_st(p_clcb->p_srcb, BTA_GATT_ERROR);
815ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    bta_gattc_sm_execute(p_clcb, BTA_GATTC_API_CLOSE_EVT, p_data);
816ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta}
817ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta/*******************************************************************************
818ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta**
8195738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function         bta_gattc_set_discover_st
8205738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
8215738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description      when a SRCB start discovery, tell all related clcb and set
8225738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**                  the state.
8235738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
8245738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns          None.
8255738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
8265738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/
8275738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectvoid bta_gattc_set_discover_st(tBTA_GATTC_SERV *p_srcb)
8285738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{
8295738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tBTA_GATTC_CB   *p_cb = &bta_gattc_cb;
8305738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    UINT8   i;
8315738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
8325738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project#if BLE_INCLUDED == TRUE
8335738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    L2CA_EnableUpdateBleConnParams(p_srcb->server_bda, FALSE);
8345738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project#endif
8355738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    for (i = 0; i < BTA_GATTC_CLCB_MAX; i ++)
8365738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
8375738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        if (p_cb->clcb[i].p_srcb == p_srcb)
8385738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        {
839ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta            p_cb->clcb[i].status = BTA_GATT_OK;
8405738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            p_cb->clcb[i].state = BTA_GATTC_DISCOVER_ST;
8415738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        }
8425738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
8435738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project}
8445738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/*******************************************************************************
8455738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
846ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta** Function         bta_gattc_restart_discover
847ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta**
848ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta** Description      process service change in discovery state, mark up the auto
849ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta**                  update flag and set status to be discovery cancel for current
850ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta**                  discovery.
851ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta**
852ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta** Returns          None.
853ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta**
854ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta*******************************************************************************/
855ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Battavoid bta_gattc_restart_discover(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data)
856ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta{
857ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    p_clcb->status      = BTA_GATT_CANCEL;
858ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    p_clcb->auto_update = BTA_GATTC_DISC_WAITING;
859ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta}
860ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta/*******************************************************************************
861ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta**
8625738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function         bta_gattc_start_discover
8635738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
8645738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description      Start a discovery on server.
8655738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
8665738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns          None.
8675738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
8685738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/
8695738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectvoid bta_gattc_start_discover(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data)
8705738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{
8715738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
872ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    APPL_TRACE_DEBUG2("bta_gattc_start_discover conn_id=%d p_clcb->p_srcb->state = %d ",
873ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta        p_clcb->bta_conn_id, p_clcb->p_srcb->state);
874ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta
875ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    if (((p_clcb->p_q_cmd == NULL || p_clcb->auto_update == BTA_GATTC_REQ_WAITING) &&
876ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta        p_clcb->p_srcb->state == BTA_GATTC_SERV_IDLE) ||
877ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta        p_clcb->p_srcb->state == BTA_GATTC_SERV_DISC)
878ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    /* no pending operation, start discovery right away */
8795738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
8805738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        p_clcb->auto_update = BTA_GATTC_NO_SCHEDULE;
8815738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
8825738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        if (p_clcb->p_srcb != NULL)
8835738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        {
8845738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            /* clear the service change mask */
8855738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            p_clcb->p_srcb->srvc_hdl_chg = FALSE;
8865738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            p_clcb->p_srcb->update_count = 0;
887ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta            p_clcb->p_srcb->state = BTA_GATTC_SERV_DISC_ACT;
8885738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
8895738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            /* set all srcb related clcb into discovery ST */
8905738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            bta_gattc_set_discover_st(p_clcb->p_srcb);
8915738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
892ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta            if ((p_clcb->status = bta_gattc_init_cache(p_clcb->p_srcb)) == BTA_GATT_OK)
893ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta            {
894ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta                p_clcb->status = bta_gattc_discover_pri_service(p_clcb->bta_conn_id, p_clcb->p_srcb, GATT_DISC_SRVC_ALL);
895ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta            }
896ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta            if (p_clcb->status != BTA_GATT_OK)
8975738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            {
8985738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                APPL_TRACE_ERROR0("discovery on server failed");
899ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta                bta_gattc_reset_discover_st(p_clcb->p_srcb, p_clcb->status);
9005738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            }
9015738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        }
9025738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        else
9035738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        {
9045738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            APPL_TRACE_ERROR0("unknown device, can not start discovery");
9055738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        }
9065738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
907ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    /* pending operation, wait until it finishes */
908ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    else
909ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    {
910ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta        p_clcb->auto_update = BTA_GATTC_DISC_WAITING;
911ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta
912ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta        if (p_clcb->p_srcb->state == BTA_GATTC_SERV_IDLE)
913ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta            p_clcb->state = BTA_GATTC_CONN_ST; /* set clcb state */
914ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    }
915ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta
9165738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project}
9175738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/*******************************************************************************
9185738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
9195738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function         bta_gattc_disc_cmpl
9205738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
9215738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description      discovery on server is finished
9225738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
9235738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns          None.
9245738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
9255738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/
9265738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectvoid bta_gattc_disc_cmpl(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data)
9275738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{
9285738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tBTA_GATTC_DATA *p_q_cmd = p_clcb->p_q_cmd;
9295738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    APPL_TRACE_DEBUG1("bta_gattc_disc_cmpl conn_id=%d",p_clcb->bta_conn_id);
9305738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
9315738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project#if BLE_INCLUDED == TRUE
9325738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    L2CA_EnableUpdateBleConnParams(p_clcb->p_srcb->server_bda, TRUE);
9335738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project#endif
9345738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    p_clcb->p_srcb->state = BTA_GATTC_SERV_IDLE;
9355738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
936ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    if (p_clcb->status != GATT_SUCCESS)
937ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    {
938ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta        /* clean up cache */
939ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta        if(p_clcb->p_srcb && p_clcb->p_srcb->p_srvc_cache)
940ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta        {
941ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta            while (p_clcb->p_srcb->cache_buffer.p_first)
942ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta            {
943ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta                GKI_freebuf (GKI_dequeue (&p_clcb->p_srcb->cache_buffer));
944ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta            }
945ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta            p_clcb->p_srcb->p_srvc_cache = NULL;
946ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta        }
947ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta
948ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta        /* used to reset cache in application */
949ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta        bta_gattc_co_cache_reset(p_clcb->p_srcb->server_bda);
950ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    }
9515738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    /* release pending attribute list buffer */
9525738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    utl_freebuf((void **)&p_clcb->p_srcb->p_srvc_list);
9535738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
954ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    if (p_clcb->auto_update == BTA_GATTC_DISC_WAITING)
955ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    {
956ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta        /* start discovery again */
957ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta        bta_gattc_sm_execute(p_clcb, BTA_GATTC_INT_DISCOVER_EVT, NULL);
958ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    }
9595738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    /* get any queued command to proceed */
960ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    else if (p_q_cmd != NULL)
9615738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
9625738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        p_clcb->p_q_cmd = NULL;
9635738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
9645738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        bta_gattc_sm_execute(p_clcb, p_q_cmd->hdr.event, p_q_cmd);
9655738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
9665738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        utl_freebuf((void **)&p_q_cmd);
9675738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
9685738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
9695738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project}
9705738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/*******************************************************************************
9715738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
9725738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function         bta_gattc_read
9735738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
9745738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description      Read an attribute
9755738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
9765738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns          None.
9775738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
9785738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/
9795738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectvoid bta_gattc_read(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data)
9805738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{
9815738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    UINT16 handle = 0;
9825738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tGATT_READ_PARAM    read_param;
9835738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tBTA_GATTC_OP_CMPL  op_cmpl;
9845738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
9855738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    memset (&read_param, 0 ,sizeof(tGATT_READ_PARAM));
9865738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    memset (&op_cmpl, 0 ,sizeof(tBTA_GATTC_OP_CMPL));
9875738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
9885738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    if (bta_gattc_enqueue(p_clcb, p_data))
9895738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
9905738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        if ((handle = bta_gattc_id2handle(p_clcb->p_srcb,
9915738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                                          &p_data->api_read.srvc_id,
9925738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                                          &p_data->api_read.char_id,
9936975b4d711142b885af479721cada448952c6b41Andre Eisenbach                                          p_data->api_read.p_descr_type)) == 0)
9945738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        {
9955738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            op_cmpl.status = BTA_GATT_ERROR;
9965738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        }
9975738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        else
9985738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        {
9995738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            read_param.by_handle.handle = handle;
10005738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            read_param.by_handle.auth_req = p_data->api_read.auth_req;
10015738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
10025738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            op_cmpl.status = GATTC_Read(p_clcb->bta_conn_id, GATT_READ_BY_HANDLE, &read_param);
10035738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        }
10045738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
10055738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        /* read fail */
10065738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        if (op_cmpl.status != BTA_GATT_OK)
10075738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        {
10085738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            op_cmpl.op_code = GATTC_OPTYPE_READ;
10095738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            op_cmpl.p_cmpl = NULL;
10105738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
10115738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            bta_gattc_sm_execute(p_clcb, BTA_GATTC_OP_CMPL_EVT, (tBTA_GATTC_DATA *)&op_cmpl);
10125738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        }
10135738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
10145738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project}
10155738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/*******************************************************************************
10165738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
10175738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function         bta_gattc_read_multi
10185738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
10195738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description      read multiple
10205738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
10215738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns          None.
10225738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*********************************************************************************/
10235738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectvoid bta_gattc_read_multi(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data)
10245738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{
10255738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    UINT16              i, handle;
10265738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tBTA_GATT_STATUS    status = BTA_GATT_OK;
10275738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tGATT_READ_PARAM    read_param;
10285738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tBTA_GATTC_OP_CMPL  op_cmpl;
10295738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tBTA_GATTC_ATTR_ID  *p_id;
10305738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
10315738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    if (bta_gattc_enqueue(p_clcb, p_data))
10325738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
10335738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        memset(&read_param, 0, sizeof(tGATT_READ_PARAM));
10345738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
10355738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        p_id = p_data->api_read_multi.p_id_list;
10365738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
10375738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        for (i = 0; i < p_data->api_read_multi.num_attr && p_id; i ++, p_id ++)
10385738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        {
10395738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            handle = 0;
10405738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
10415738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            if (p_id->id_type == BTA_GATT_TYPE_CHAR)
10425738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            {
10435738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                handle = bta_gattc_id2handle(p_clcb->p_srcb,
10445738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                                     &p_id->id_value.char_id.srvc_id,
10455738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                                     &p_id->id_value.char_id.char_id,
10466975b4d711142b885af479721cada448952c6b41Andre Eisenbach                                     NULL);
10475738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            }
10485738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            else if (p_id->id_type == BTA_GATT_TYPE_CHAR_DESCR)
10495738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            {
10505738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                handle = bta_gattc_id2handle(p_clcb->p_srcb,
10515738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                                     &p_id->id_value.char_descr_id.char_id.srvc_id,
10525738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                                     &p_id->id_value.char_descr_id.char_id.char_id,
10536975b4d711142b885af479721cada448952c6b41Andre Eisenbach                                     &p_id->id_value.char_descr_id.descr_id);
10545738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            }
10555738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            else
10565738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            {
10575738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                APPL_TRACE_ERROR1("invalud ID type: %d", p_id->id_type);
10585738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            }
10595738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
10605738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            if (handle == 0)
10615738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            {
10625738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                status = BTA_GATT_ERROR;
10635738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                break;
10645738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            }
10655738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        }
10665738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        if (status == BTA_GATT_OK)
10675738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        {
10685738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            read_param.read_multiple.num_handles = p_data->api_read_multi.num_attr;
10695738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            read_param.read_multiple.auth_req = p_data->api_read_multi.auth_req;
10705738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
10715738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            status = GATTC_Read(p_clcb->bta_conn_id, GATT_READ_MULTIPLE, &read_param);
10725738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        }
10735738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
10745738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        /* read fail */
10755738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        if (status != BTA_GATT_OK)
10765738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        {
10775738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            memset(&op_cmpl, 0, sizeof(tBTA_GATTC_OP_CMPL));
10785738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
10795738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            op_cmpl.status  = status;
10805738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            op_cmpl.op_code = GATTC_OPTYPE_READ;
10815738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            op_cmpl.p_cmpl  = NULL;
10825738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
10835738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            bta_gattc_sm_execute(p_clcb, BTA_GATTC_OP_CMPL_EVT, (tBTA_GATTC_DATA *)&op_cmpl);
10845738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        }
10855738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
10865738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project}
10875738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/*******************************************************************************
10885738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
10895738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function         bta_gattc_write
10905738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
10915738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description      Write an attribute
10925738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
10935738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns          None.
10945738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
10955738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/
10965738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectvoid bta_gattc_write(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data)
10975738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{
10985738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    UINT16              handle = 0;
10995738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tGATT_VALUE         attr = {0};
11005738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tBTA_GATTC_OP_CMPL  op_cmpl;
11015738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tBTA_GATT_STATUS    status = BTA_GATT_OK;
11025738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
11035738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    if (bta_gattc_enqueue(p_clcb, p_data))
11045738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
11055738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        if ((handle = bta_gattc_id2handle(p_clcb->p_srcb,
11065738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                                          &p_data->api_write.srvc_id,
11075738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                                          &p_data->api_write.char_id,
11086975b4d711142b885af479721cada448952c6b41Andre Eisenbach                                          p_data->api_write.p_descr_type)) == 0)
11095738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        {
11105738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            status = BTA_GATT_ERROR;
11115738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        }
11125738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        else
11135738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        {
11145738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            attr.handle= handle;
11155738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            attr.offset = p_data->api_write.offset;
11165738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            attr.len    = p_data->api_write.len;
11175738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            attr.auth_req = p_data->api_write.auth_req;
11185738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
11195738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            if (p_data->api_write.p_value)
11205738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                memcpy(attr.value, p_data->api_write.p_value, p_data->api_write.len);
11215738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
11225738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            status = GATTC_Write(p_clcb->bta_conn_id, p_data->api_write.write_type, &attr);
11235738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        }
11245738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
11255738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        /* write fail */
11265738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        if (status != BTA_GATT_OK)
11275738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        {
11285738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            memset(&op_cmpl, 0, sizeof(tBTA_GATTC_OP_CMPL));
11295738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
11305738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            op_cmpl.status  = status;
11315738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            op_cmpl.op_code = GATTC_OPTYPE_WRITE;
11325738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            op_cmpl.p_cmpl  = NULL;
11335738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
11345738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            bta_gattc_sm_execute(p_clcb, BTA_GATTC_OP_CMPL_EVT, (tBTA_GATTC_DATA *)&op_cmpl);
11355738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        }
11365738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
11375738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project}
11385738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/*******************************************************************************
11395738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
11405738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function         bta_gattc_execute
11415738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
11425738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description      send execute write
11435738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
11445738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns          None.
11455738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*********************************************************************************/
11465738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectvoid bta_gattc_execute(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data)
11475738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{
11485738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tBTA_GATTC_OP_CMPL  op_cmpl;
11495738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tBTA_GATT_STATUS    status;
11505738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
11515738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    if (bta_gattc_enqueue(p_clcb, p_data))
11525738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
11535738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        status = GATTC_ExecuteWrite(p_clcb->bta_conn_id, p_data->api_exec.is_execute);
11545738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
11555738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        if (status != BTA_GATT_OK)
11565738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        {
11575738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            memset(&op_cmpl, 0, sizeof(tBTA_GATTC_OP_CMPL));
11585738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
11595738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            op_cmpl.status  = status;
11605738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            op_cmpl.op_code = GATTC_OPTYPE_EXE_WRITE;
11615738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            op_cmpl.p_cmpl  = NULL;
11625738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
11635738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            bta_gattc_sm_execute(p_clcb, BTA_GATTC_OP_CMPL_EVT, (tBTA_GATTC_DATA *)&op_cmpl);
11645738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        }
11655738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
11665738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project}
11675738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/*******************************************************************************
11685738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
11695738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function         bta_gattc_confirm
11705738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
11715738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description      send handle value confirmation
11725738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
11735738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns          None.
11745738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
11755738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/
11765738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectvoid bta_gattc_confirm(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data)
11775738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{
11785738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    UINT16 handle;
11795738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
11805738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    if ((handle = bta_gattc_id2handle(p_clcb->p_srcb,
11815738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                                      &p_data->api_confirm.srvc_id,
11825738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                                      &p_data->api_confirm.char_id,
11836975b4d711142b885af479721cada448952c6b41Andre Eisenbach                                      NULL)) == 0)
11845738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
11855738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        APPL_TRACE_ERROR0("Can not map service/char ID into valid handle");
11865738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
11875738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    else
11885738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
11895738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        if (GATTC_SendHandleValueConfirm(p_data->api_confirm.hdr.layer_specific, handle)
11905738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            != GATT_SUCCESS)
11915738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        {
11925738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            APPL_TRACE_ERROR1("bta_gattc_confirm to handle [0x%04x] failed", handle);
11935738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        }
1194781b5adee20e222ef87b56b72bfcd3f64013e4a0Andre Eisenbach        /* if over BR_EDR, inform PM for mode change */
1195781b5adee20e222ef87b56b72bfcd3f64013e4a0Andre Eisenbach        else if (!BTM_IsBleLink(p_clcb->bda))
1196781b5adee20e222ef87b56b72bfcd3f64013e4a0Andre Eisenbach        {
1197781b5adee20e222ef87b56b72bfcd3f64013e4a0Andre Eisenbach            bta_sys_busy(BTA_ID_GATTC, BTA_ALL_APP_ID, p_clcb->bda);
1198781b5adee20e222ef87b56b72bfcd3f64013e4a0Andre Eisenbach            bta_sys_idle(BTA_ID_GATTC, BTA_ALL_APP_ID, p_clcb->bda);
1199781b5adee20e222ef87b56b72bfcd3f64013e4a0Andre Eisenbach        }
12005738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
12015738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project}
12025738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/*******************************************************************************
12035738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
12045738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function         bta_gattc_read_cmpl
12055738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
12065738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description      read complete
12075738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
12085738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns          None.
12095738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
12105738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/
12115738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectvoid bta_gattc_read_cmpl(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_OP_CMPL *p_data)
12125738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{
12135738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    UINT8               event;
12145738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tBTA_GATTC          cb_data;
12155738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tBTA_GATT_READ_VAL  read_value;
12165738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
12175738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    memset(&cb_data, 0, sizeof(tBTA_GATTC));
12185738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    memset(&read_value, 0, sizeof(tBTA_GATT_READ_VAL));
12195738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
12205738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    cb_data.read.status     = p_data->status;
12215738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
12225738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    if (p_data->p_cmpl != NULL && p_data->status == BTA_GATT_OK)
12235738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
12245738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        if (bta_gattc_handle2id(p_clcb->p_srcb,
12255738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                                p_data->p_cmpl->att_value.handle,
12265738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                                &cb_data.read.srvc_id,
12275738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                                &cb_data.read.char_id,
12285738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                                &cb_data.read.descr_type) == FALSE)
12295738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        {
12305738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            cb_data.read.status = BTA_GATT_INTERNAL_ERROR;
12315738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            APPL_TRACE_ERROR1("can not map to GATT ID. handle = 0x%04x", p_data->p_cmpl->att_value.handle);
12325738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        }
12335738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        else
12345738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        {
12355738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            cb_data.read.status = bta_gattc_pack_read_cb_data(p_clcb->p_srcb,
12366975b4d711142b885af479721cada448952c6b41Andre Eisenbach                                                              &cb_data.read.descr_type.uuid,
12375738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                                                              &p_data->p_cmpl->att_value,
12385738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                                                              &read_value);
12395738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            cb_data.read.p_value = &read_value;
12405738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        }
12415738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
12425738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    else
12435738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
12445738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        cb_data.read.srvc_id = p_clcb->p_q_cmd->api_read.srvc_id;
12455738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        cb_data.read.char_id = p_clcb->p_q_cmd->api_read.char_id;
12466975b4d711142b885af479721cada448952c6b41Andre Eisenbach        if (p_clcb->p_q_cmd->api_read.p_descr_type)
12476975b4d711142b885af479721cada448952c6b41Andre Eisenbach            memcpy(&cb_data.read.descr_type, p_clcb->p_q_cmd->api_read.p_descr_type, sizeof(tBTA_GATT_ID));
12485738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
12495738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
12506975b4d711142b885af479721cada448952c6b41Andre Eisenbach    event = (p_clcb->p_q_cmd->api_read.p_descr_type == NULL) ? BTA_GATTC_READ_CHAR_EVT: BTA_GATTC_READ_DESCR_EVT;
12515738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    cb_data.read.conn_id = p_clcb->bta_conn_id;
12525738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
12535738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    utl_freebuf((void **)&p_clcb->p_q_cmd);
12545738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    /* read complete, callback */
12555738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    ( *p_clcb->p_rcb->p_cback)(event, (tBTA_GATTC *)&cb_data);
12565738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
12575738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project}
12585738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/*******************************************************************************
12595738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
12605738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function         bta_gattc_write_cmpl
12615738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
12625738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description      read complete
12635738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
12645738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns          None.
12655738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
12665738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/
12675738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectvoid bta_gattc_write_cmpl(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_OP_CMPL *p_data)
12685738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{
12695738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tBTA_GATTC      cb_data = {0};
12705738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    UINT8          event;
12715738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
12726975b4d711142b885af479721cada448952c6b41Andre Eisenbach    memset(&cb_data, 0, sizeof(tBTA_GATTC));
12736975b4d711142b885af479721cada448952c6b41Andre Eisenbach
12745738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    cb_data.write.status     = p_data->status;
12755738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
12765738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    if (p_data->p_cmpl != NULL)
12775738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
12785738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        bta_gattc_handle2id(p_clcb->p_srcb, p_data->p_cmpl->handle,
12795738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                            &cb_data.write.srvc_id, &cb_data.write.char_id,
12805738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                            &cb_data.write.descr_type);
12815738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
12825738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    else
12835738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
12846975b4d711142b885af479721cada448952c6b41Andre Eisenbach        memcpy(&cb_data.write.srvc_id, &p_clcb->p_q_cmd->api_write.srvc_id, sizeof(tBTA_GATT_SRVC_ID));
12856975b4d711142b885af479721cada448952c6b41Andre Eisenbach        memcpy(&cb_data.write.char_id, &p_clcb->p_q_cmd->api_write.char_id, sizeof(tBTA_GATT_ID));
12866975b4d711142b885af479721cada448952c6b41Andre Eisenbach        if (p_clcb->p_q_cmd->api_write.p_descr_type)
12876975b4d711142b885af479721cada448952c6b41Andre Eisenbach            memcpy(&cb_data.write.descr_type, p_clcb->p_q_cmd->api_write.p_descr_type, sizeof(tBTA_GATT_ID));
12885738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
12895738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
12905738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    if (p_clcb->p_q_cmd->api_write.hdr.event == BTA_GATTC_API_WRITE_EVT &&
12915738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        p_clcb->p_q_cmd->api_write.write_type == BTA_GATTC_WRITE_PREPARE)
12925738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
12935738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        event = BTA_GATTC_PREP_WRITE_EVT;
12945738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
12956975b4d711142b885af479721cada448952c6b41Andre Eisenbach    else if (p_clcb->p_q_cmd->api_write.p_descr_type == NULL)
12965738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
12975738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        event = BTA_GATTC_WRITE_CHAR_EVT;
12985738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
12995738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    else
13005738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        event = BTA_GATTC_WRITE_DESCR_EVT;
13015738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
13025738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    utl_freebuf((void **)&p_clcb->p_q_cmd);
13035738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    cb_data.write.conn_id = p_clcb->bta_conn_id;
13045738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    /* write complete, callback */
13055738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    ( *p_clcb->p_rcb->p_cback)(event, (tBTA_GATTC *)&cb_data);
13065738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
13075738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project}
13085738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/*******************************************************************************
13095738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
13105738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function         bta_gattc_exec_cmpl
13115738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
13125738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description      execute write complete
13135738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
13145738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns          None.
13155738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
13165738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/
13175738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectvoid bta_gattc_exec_cmpl(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_OP_CMPL *p_data)
13185738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{
13195738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tBTA_GATTC          cb_data;
13205738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
13215738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    utl_freebuf((void **)&p_clcb->p_q_cmd);
13225738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
13235738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    p_clcb->status      = BTA_GATT_OK;
13245738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
13255738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    /* execute complete, callback */
13265738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    cb_data.exec_cmpl.conn_id = p_clcb->bta_conn_id;
13275738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    cb_data.exec_cmpl.status = p_data->status;
13285738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
13295738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    ( *p_clcb->p_rcb->p_cback)(BTA_GATTC_EXEC_EVT,  &cb_data);
13305738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
13315738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project}
13325738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/*******************************************************************************
13335738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
13345738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function         bta_gattc_op_cmpl
13355738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
13365738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description      operation completed.
13375738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
13385738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns          None.
13395738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
13405738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/
13415738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectvoid  bta_gattc_op_cmpl(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data)
13425738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{
13435738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    UINT8           op = (UINT8)p_data->op_cmpl.op_code;
13445738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    UINT8           mapped_op = 0;
13455738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
13465738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    APPL_TRACE_DEBUG1("bta_gattc_op_cmpl op = %d", op);
13475738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
13485738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    if (op == GATTC_OPTYPE_INDICATION || op == GATTC_OPTYPE_NOTIFICATION)
13495738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
13505738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        APPL_TRACE_ERROR0("unexpected operation, ignored");
13515738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
13525738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    else if (op >= GATTC_OPTYPE_READ)
13535738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
13545738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        if (p_clcb->p_q_cmd == NULL)
13555738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        {
13565738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            APPL_TRACE_ERROR0("No pending command");
13575738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            return;
13585738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        }
13595738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        if (p_clcb->p_q_cmd->hdr.event != bta_gattc_opcode_to_int_evt[op - GATTC_OPTYPE_READ])
13605738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        {
13615738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            mapped_op = p_clcb->p_q_cmd->hdr.event - BTA_GATTC_API_READ_EVT + GATTC_OPTYPE_READ;
13625738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            if ( mapped_op > GATTC_OPTYPE_INDICATION)   mapped_op = 0;
13635738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
13645738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project#if (BT_TRACE_VERBOSE == TRUE)
13655738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            APPL_TRACE_ERROR3("expect op:(%s :0x%04x), receive unexpected operation (%s).",
13665738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                                bta_gattc_op_code_name[mapped_op] , p_clcb->p_q_cmd->hdr.event,
13675738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                                bta_gattc_op_code_name[op]);
13685738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project#else
13695738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            APPL_TRACE_ERROR3("expect op:(%u :0x%04x), receive unexpected operation (%u).",
13705738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                                mapped_op , p_clcb->p_q_cmd->hdr.event, op);
13715738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project#endif
13725738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            return;
13735738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        }
13745738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
13755738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        /* service handle change void the response, discard it */
13765738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        if (p_clcb->auto_update == BTA_GATTC_DISC_WAITING)
13775738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        {
13785738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            p_clcb->auto_update = BTA_GATTC_REQ_WAITING;
13795738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            bta_gattc_sm_execute(p_clcb, BTA_GATTC_INT_DISCOVER_EVT, NULL);
13805738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        }
13815738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        else if (op == GATTC_OPTYPE_READ)
13825738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            bta_gattc_read_cmpl(p_clcb, &p_data->op_cmpl);
13835738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
13845738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        else if (op == GATTC_OPTYPE_WRITE)
13855738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            bta_gattc_write_cmpl(p_clcb, &p_data->op_cmpl);
13865738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
13875738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        else if (op == GATTC_OPTYPE_EXE_WRITE)
13885738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            bta_gattc_exec_cmpl(p_clcb, &p_data->op_cmpl);
13895738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        /*
13905738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        else if (op == GATTC_OPTYPE_CONFIG) // API to be added
13915738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        {
13925738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        }
13935738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project       */
13945738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
13955738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project}
13965738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/*******************************************************************************
13975738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
13985738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function         bta_gattc_op_cmpl
13995738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
14005738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description      operation completed.
14015738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
14025738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns          None.
14035738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
14045738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/
14055738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectvoid  bta_gattc_ignore_op_cmpl(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data)
14065738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{
14075738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    /* receive op complete when discovery is started, ignore the response,
14085738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        and wait for discovery finish and resent */
14095738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    APPL_TRACE_DEBUG1("bta_gattc_ignore_op_cmpl op = %d", p_data->hdr.layer_specific);
14105738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
14115738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project}
14125738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/*******************************************************************************
14135738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
14145738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function         bta_gattc_search
14155738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
14165738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description      start a search in the local server cache
14175738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
14185738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns          None.
14195738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
14205738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/
14215738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectvoid bta_gattc_search(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data)
14225738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{
14235738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tBTA_GATT_STATUS    status = GATT_INTERNAL_ERROR;
14245738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tBTA_GATTC cb_data;
14255738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    APPL_TRACE_DEBUG1("bta_gattc_search conn_id=%d",p_clcb->bta_conn_id);
14265738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    if (p_clcb->p_srcb && p_clcb->p_srcb->p_srvc_cache)
14275738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
14285738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        status = BTA_GATT_OK;
14295738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        /* search the local cache of a server device */
14306975b4d711142b885af479721cada448952c6b41Andre Eisenbach        bta_gattc_search_service(p_clcb, p_data->api_search.p_srvc_uuid);
14315738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
14325738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    cb_data.search_cmpl.status  = status;
14335738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    cb_data.search_cmpl.conn_id = p_clcb->bta_conn_id;
14345738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
14355738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    /* end of search or no server cache available */
14365738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    ( *p_clcb->p_rcb->p_cback)(BTA_GATTC_SEARCH_CMPL_EVT,  &cb_data);
14375738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project}
14385738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/*******************************************************************************
14395738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
14405738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function         bta_gattc_q_cmd
14415738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
14425738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description      enqueue a command into control block, usually because discovery
14435738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**                  operation is busy.
14445738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
14455738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns          None.
14465738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
14475738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/
14485738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectvoid bta_gattc_q_cmd(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data)
14495738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{
14505738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    bta_gattc_enqueue(p_clcb, p_data);
14515738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project}
14525738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/*******************************************************************************
14535738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
14545738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function         bta_gattc_cache_open
14555738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
14565738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description      open a NV cache for loading
14575738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
14585738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns          void
14595738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
14605738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/
14615738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectvoid bta_gattc_cache_open(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data)
14625738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{
14635738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    bta_gattc_set_discover_st(p_clcb->p_srcb);
14645738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
14655738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    APPL_TRACE_DEBUG1("bta_gattc_cache_open conn_id=%d",p_clcb->bta_conn_id);
14665738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    bta_gattc_co_cache_open(p_clcb->p_srcb->server_bda, BTA_GATTC_CI_CACHE_OPEN_EVT,
14675738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                            p_clcb->bta_conn_id, FALSE);
14685738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project}
14695738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/*******************************************************************************
14705738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
14715738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function         bta_gattc_start_load
14725738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
14735738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description      start cache loading by sending callout open cache
14745738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
14755738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns          None.
14765738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
14775738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/
14785738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectvoid bta_gattc_ci_open(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data)
14795738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{
14805738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    APPL_TRACE_DEBUG2("bta_gattc_ci_open conn_id=%d server state=%d" ,
14815738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                      p_clcb->bta_conn_id, p_clcb->p_srcb->state);
14825738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    if (p_clcb->p_srcb->state == BTA_GATTC_SERV_LOAD)
14835738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
14845738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        if (p_data->ci_open.status == BTA_GATT_OK)
14855738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        {
14865738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            p_clcb->p_srcb->attr_index = 0;
14875738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            bta_gattc_co_cache_load(p_clcb->p_srcb->server_bda,
14885738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                                    BTA_GATTC_CI_CACHE_LOAD_EVT,
14895738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                                    p_clcb->p_srcb->attr_index,
14905738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                                    p_clcb->bta_conn_id);
14915738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        }
14925738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        else
14935738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        {
1494ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta            p_clcb->p_srcb->state = BTA_GATTC_SERV_DISC;
14955738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            /* cache open failure, start discovery */
14965738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            bta_gattc_start_discover(p_clcb, NULL);
14975738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        }
14985738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
14995738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    if (p_clcb->p_srcb->state == BTA_GATTC_SERV_SAVE)
15005738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
15015738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        if (p_data->ci_open.status == BTA_GATT_OK)
15025738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        {
15035738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            if (!bta_gattc_cache_save(p_clcb->p_srcb, p_clcb->bta_conn_id))
15045738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            {
15055738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                p_data->ci_open.status = BTA_GATT_ERROR;
15065738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            }
15075738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        }
15085738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        if (p_data->ci_open.status != BTA_GATT_OK)
15095738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        {
15105738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            p_clcb->p_srcb->attr_index = 0;
15115738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            bta_gattc_co_cache_close(p_clcb->p_srcb->server_bda, p_clcb->bta_conn_id);
1512ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta            bta_gattc_reset_discover_st(p_clcb->p_srcb, p_clcb->status);
15135738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
15145738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        }
15155738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
15165738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project}
15175738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/*******************************************************************************
15185738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
15195738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function         bta_gattc_ci_load
15205738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
15215738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description      cache loading received.
15225738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
15235738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns          None.
15245738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
15255738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/
15265738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectvoid bta_gattc_ci_load(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data)
15275738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{
15285738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
15295738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    APPL_TRACE_DEBUG2("bta_gattc_ci_load conn_id=%d load status=%d" ,
15305738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                      p_clcb->bta_conn_id, p_data->ci_load.status );
15315738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    bta_gattc_co_cache_close(p_clcb->p_srcb->server_bda, 0);
15325738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
15335738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    if ((p_data->ci_load.status == BTA_GATT_OK ||
15345738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project         p_data->ci_load.status == BTA_GATT_MORE) &&
15355738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        p_data->ci_load.num_attr > 0)
15365738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
15375738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        bta_gattc_rebuild_cache(p_clcb->p_srcb, p_data->ci_load.num_attr, p_data->ci_load.attr, p_clcb->p_srcb->attr_index);
15385738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
15395738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        if (p_data->ci_load.status == BTA_GATT_OK)
15405738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        {
15415738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            p_clcb->p_srcb->attr_index = 0;
1542ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta            bta_gattc_reset_discover_st(p_clcb->p_srcb, BTA_GATT_OK);
15435738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
15445738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        }
15455738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        else /* load more */
15465738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        {
15475738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            p_clcb->p_srcb->attr_index += p_data->ci_load.num_attr;
15485738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
15495738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            bta_gattc_co_cache_load(p_clcb->p_srcb->server_bda,
15505738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                                    BTA_GATTC_CI_CACHE_LOAD_EVT,
15515738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                                    p_clcb->p_srcb->attr_index,
15525738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                                    p_clcb->bta_conn_id);
15535738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        }
15545738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
15555738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    else
15565738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
1557ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta        p_clcb->p_srcb->state = BTA_GATTC_SERV_DISC;
15585738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        p_clcb->p_srcb->attr_index = 0;
1559e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach        /* cache load failure, start discovery */
15605738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        bta_gattc_start_discover(p_clcb, NULL);
15615738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
15625738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project}
15635738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/*******************************************************************************
15645738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
15655738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function         bta_gattc_ci_load
15665738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
15675738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description      cache loading received.
15685738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
15695738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns          None.
15705738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
15715738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/
15725738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectvoid bta_gattc_ci_save(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data)
15735738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{
15745738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    APPL_TRACE_DEBUG1("bta_gattc_ci_save conn_id=%d  " ,
15755738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                      p_clcb->bta_conn_id   );
15765738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
15775738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    if (!bta_gattc_cache_save(p_clcb->p_srcb, p_clcb->bta_conn_id))
15785738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
15795738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        p_clcb->p_srcb->attr_index = 0;
15805738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        bta_gattc_co_cache_close(p_clcb->p_srcb->server_bda, 0);
1581ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta        bta_gattc_reset_discover_st(p_clcb->p_srcb, p_clcb->status);
15825738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
15835738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project}
15845738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/*******************************************************************************
15855738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
15865738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function         bta_gattc_fail
15875738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
15885738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description      report API call failure back to apps
15895738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
15905738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns          None.
15915738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
15925738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/
15935738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectvoid bta_gattc_fail(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data)
15945738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{
15955738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    if (p_clcb->status == BTA_GATT_OK)
15965738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
15975738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        APPL_TRACE_ERROR1("operation not supported at current state [%d]", p_clcb->state);
15985738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
15995738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project}
1600e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach
1601e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach/*******************************************************************************
1602e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach**
1603e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach** Function         bta_gattc_deregister_cmpl
1604e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach**
1605e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach** Description      De-Register a GATT client application with BTA completed.
1606e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach**
1607e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach** Returns          void
1608e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach**
1609e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach*******************************************************************************/
1610e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbachstatic void bta_gattc_deregister_cmpl(tBTA_GATTC_RCB *p_clreg)
1611e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach{
1612e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach    tBTA_GATTC_CB       *p_cb = &bta_gattc_cb;
1613e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach    tBTA_GATTC_IF       client_if = p_clreg->client_if;
1614e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach    tBTA_GATTC          cb_data;
1615e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach    tBTA_GATTC_CBACK    *p_cback = p_clreg->p_cback;
1616e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach
1617e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach    memset(&cb_data, 0, sizeof(tBTA_GATTC));
1618e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach
1619e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach    GATT_Deregister(p_clreg->client_if);
1620e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach    memset(p_clreg, 0, sizeof(tBTA_GATTC_RCB));
1621e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach
1622e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach    cb_data.reg_oper.client_if = client_if;
1623e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach    cb_data.reg_oper.status    = BTA_GATT_OK;
1624e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach
1625e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach    if (p_cback)
1626e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach        /* callback with de-register event */
1627e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach        (*p_cback)(BTA_GATTC_DEREG_EVT,  (tBTA_GATTC *)&cb_data);
1628e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach
1629e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach    if (bta_gattc_num_reg_app() == 0 && p_cb->state == BTA_GATTC_STATE_DISABLING)
1630e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach    {
1631e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach        p_cb->state = BTA_GATTC_STATE_DISABLED;
1632e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach    }
1633e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach}
16345738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/*******************************************************************************
16355738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
16365738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function         bta_gattc_conn_cback
16375738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**                  bta_gattc_cmpl_cback
16385738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
16395738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description      callback functions to GATT client stack.
16405738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
16415738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns          void
16425738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
16435738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/
16445738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectstatic void bta_gattc_conn_cback(tGATT_IF gattc_if, BD_ADDR bda, UINT16 conn_id,
16455738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                                 BOOLEAN connected, tGATT_DISCONN_REASON reason)
16465738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{
16476975b4d711142b885af479721cada448952c6b41Andre Eisenbach    tBTA_GATTC_DATA *p_buf;
1648e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach
16495738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    APPL_TRACE_DEBUG4("bta_gattc_conn_cback: cif = %d connected = %d conn_id = %d reaosn = 0x%04x",
16505738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                      gattc_if, connected, conn_id, reason);
16515738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
16526975b4d711142b885af479721cada448952c6b41Andre Eisenbach    if ((p_buf = (tBTA_GATTC_DATA *) GKI_getbuf(sizeof(tBTA_GATTC_DATA))) != NULL)
16535738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
16546975b4d711142b885af479721cada448952c6b41Andre Eisenbach        memset(p_buf, 0, sizeof(tBTA_GATTC_DATA));
1655ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta
16566975b4d711142b885af479721cada448952c6b41Andre Eisenbach        p_buf->int_conn.hdr.event            = connected ? BTA_GATTC_INT_CONN_EVT: BTA_GATTC_INT_DISCONN_EVT;
16576975b4d711142b885af479721cada448952c6b41Andre Eisenbach        p_buf->int_conn.hdr.layer_specific   = conn_id;
16586975b4d711142b885af479721cada448952c6b41Andre Eisenbach        p_buf->int_conn.client_if            = gattc_if;
16596975b4d711142b885af479721cada448952c6b41Andre Eisenbach        p_buf->int_conn.role                 = L2CA_GetBleConnRole(bda);
16606975b4d711142b885af479721cada448952c6b41Andre Eisenbach        p_buf->int_conn.reason               = reason;
16616975b4d711142b885af479721cada448952c6b41Andre Eisenbach        bdcpy(p_buf->int_conn.remote_bda, bda);
16625738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
16635738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                bta_sys_sendmsg(p_buf);
16645738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            }
16655738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        }
16665738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
16675738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/*******************************************************************************
16685738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
1669b9912730d082c7bca7d94bb9ddac4447cfad362fZhihai Xu** Function         bta_gattc_enc_cmpl_cback
1670b9912730d082c7bca7d94bb9ddac4447cfad362fZhihai Xu**
1671b9912730d082c7bca7d94bb9ddac4447cfad362fZhihai Xu** Description      encryption complete callback function to GATT client stack.
1672b9912730d082c7bca7d94bb9ddac4447cfad362fZhihai Xu**
1673b9912730d082c7bca7d94bb9ddac4447cfad362fZhihai Xu** Returns          void
1674b9912730d082c7bca7d94bb9ddac4447cfad362fZhihai Xu**
1675b9912730d082c7bca7d94bb9ddac4447cfad362fZhihai Xu*******************************************************************************/
1676b9912730d082c7bca7d94bb9ddac4447cfad362fZhihai Xustatic void bta_gattc_enc_cmpl_cback(tGATT_IF gattc_if, BD_ADDR bda)
1677b9912730d082c7bca7d94bb9ddac4447cfad362fZhihai Xu{
1678b9912730d082c7bca7d94bb9ddac4447cfad362fZhihai Xu    tBTA_GATTC_DATA *p_buf;
1679b9912730d082c7bca7d94bb9ddac4447cfad362fZhihai Xu    tBTA_GATTC_CLCB *p_clcb = NULL;
1680b9912730d082c7bca7d94bb9ddac4447cfad362fZhihai Xu
1681b9912730d082c7bca7d94bb9ddac4447cfad362fZhihai Xu    if ((p_clcb = bta_gattc_find_clcb_by_cif(gattc_if, bda)) == NULL)
1682b9912730d082c7bca7d94bb9ddac4447cfad362fZhihai Xu    {
1683b9912730d082c7bca7d94bb9ddac4447cfad362fZhihai Xu        return;
1684b9912730d082c7bca7d94bb9ddac4447cfad362fZhihai Xu    }
1685b9912730d082c7bca7d94bb9ddac4447cfad362fZhihai Xu
1686b9912730d082c7bca7d94bb9ddac4447cfad362fZhihai Xu#if (defined BTA_HH_LE_INCLUDED && BTA_HH_LE_INCLUDED == TRUE)
1687b9912730d082c7bca7d94bb9ddac4447cfad362fZhihai Xu    /* filter this event just for BTA HH LE GATT client,
1688b9912730d082c7bca7d94bb9ddac4447cfad362fZhihai Xu       In the future, if we want to enable encryption complete event
1689b9912730d082c7bca7d94bb9ddac4447cfad362fZhihai Xu       for all GATT clients, we can remove this code */
1690b9912730d082c7bca7d94bb9ddac4447cfad362fZhihai Xu    if (!bta_hh_le_is_hh_gatt_if(gattc_if))
1691b9912730d082c7bca7d94bb9ddac4447cfad362fZhihai Xu    {
1692b9912730d082c7bca7d94bb9ddac4447cfad362fZhihai Xu        return;
1693b9912730d082c7bca7d94bb9ddac4447cfad362fZhihai Xu    }
1694b9912730d082c7bca7d94bb9ddac4447cfad362fZhihai Xu#endif
1695b9912730d082c7bca7d94bb9ddac4447cfad362fZhihai Xu
1696b9912730d082c7bca7d94bb9ddac4447cfad362fZhihai Xu    APPL_TRACE_DEBUG1("bta_gattc_enc_cmpl_cback: cif = %d", gattc_if);
1697b9912730d082c7bca7d94bb9ddac4447cfad362fZhihai Xu
1698b9912730d082c7bca7d94bb9ddac4447cfad362fZhihai Xu    if ((p_buf = (tBTA_GATTC_DATA *) GKI_getbuf(sizeof(tBTA_GATTC_DATA))) != NULL)
1699b9912730d082c7bca7d94bb9ddac4447cfad362fZhihai Xu    {
1700b9912730d082c7bca7d94bb9ddac4447cfad362fZhihai Xu        memset(p_buf, 0, sizeof(tBTA_GATTC_DATA));
1701b9912730d082c7bca7d94bb9ddac4447cfad362fZhihai Xu
1702b9912730d082c7bca7d94bb9ddac4447cfad362fZhihai Xu        p_buf->enc_cmpl.hdr.event            = BTA_GATTC_ENC_CMPL_EVT;
1703b9912730d082c7bca7d94bb9ddac4447cfad362fZhihai Xu        p_buf->enc_cmpl.hdr.layer_specific   = p_clcb->bta_conn_id;
1704b9912730d082c7bca7d94bb9ddac4447cfad362fZhihai Xu        p_buf->enc_cmpl.client_if            = gattc_if;
1705b9912730d082c7bca7d94bb9ddac4447cfad362fZhihai Xu        bdcpy(p_buf->enc_cmpl.remote_bda, bda);
1706b9912730d082c7bca7d94bb9ddac4447cfad362fZhihai Xu
1707b9912730d082c7bca7d94bb9ddac4447cfad362fZhihai Xu        bta_sys_sendmsg(p_buf);
1708b9912730d082c7bca7d94bb9ddac4447cfad362fZhihai Xu    }
1709b9912730d082c7bca7d94bb9ddac4447cfad362fZhihai Xu}
1710b9912730d082c7bca7d94bb9ddac4447cfad362fZhihai Xu
1711b9912730d082c7bca7d94bb9ddac4447cfad362fZhihai Xu/*******************************************************************************
1712b9912730d082c7bca7d94bb9ddac4447cfad362fZhihai Xu**
1713ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta** Function         bta_gattc_process_api_refresh
1714ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta**
1715ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta** Description      process refresh API to delete cache and start a new discovery
1716ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta**                  if currently connected.
1717ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta**
1718ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta** Returns          None.
1719ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta**
1720ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta*******************************************************************************/
1721ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Battavoid bta_gattc_process_api_refresh(tBTA_GATTC_CB *p_cb, tBTA_GATTC_DATA * p_msg)
1722ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta{
1723ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    tBTA_GATTC_SERV *p_srvc_cb = bta_gattc_find_srvr_cache(p_msg->api_conn.remote_bda);
1724ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    tBTA_GATTC_CLCB      *p_clcb = &bta_gattc_cb.clcb[0];
1725ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    BOOLEAN         found = FALSE;
1726ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    UINT8           i;
1727ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta
1728ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    if (p_srvc_cb != NULL)
1729ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    {
1730ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta        /* try to find a CLCB */
1731ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta        if (p_srvc_cb->connected && p_srvc_cb->num_clcb != 0)
1732ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta        {
1733ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta            for (i = 0; i < BTA_GATTC_CLCB_MAX; i ++, p_clcb ++)
1734ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta            {
1735ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta                if (p_clcb->in_use && p_clcb->p_srcb == p_srvc_cb)
1736ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta                {
1737ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta                    found = TRUE;
1738ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta                    break;
1739ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta                }
1740ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta            }
1741ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta            if (found)
1742ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta            {
1743ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta                bta_gattc_sm_execute(p_clcb, BTA_GATTC_INT_DISCOVER_EVT, NULL);
1744ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta                return;
1745ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta            }
1746ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta        }
1747ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta        /* in all other cases, mark it and delete the cache */
1748ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta        if (p_srvc_cb->p_srvc_cache != NULL)
1749ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta        {
1750ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta            while (p_srvc_cb->cache_buffer.p_first)
1751ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta                GKI_freebuf (GKI_dequeue (&p_srvc_cb->cache_buffer));
1752ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta
1753ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta            p_srvc_cb->p_srvc_cache = NULL;
1754ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta        }
1755ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    }
1756ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    /* used to reset cache in application */
1757ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    bta_gattc_co_cache_reset(p_msg->api_conn.remote_bda);
1758ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta
1759ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta}
1760ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta/*******************************************************************************
1761ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta**
17625738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function         bta_gattc_process_srvc_chg_ind
17635738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
17645738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description      process service change indication.
17655738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
17665738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns          None.
17675738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
17685738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/
17695738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source ProjectBOOLEAN bta_gattc_process_srvc_chg_ind(UINT16 conn_id,
17705738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                                       tBTA_GATTC_RCB      *p_clrcb,
17715738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                                       tBTA_GATTC_SERV     *p_srcb,
17725738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                                       tBTA_GATTC_CLCB      *p_clcb,
17735738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                                       tBTA_GATTC_NOTIFY    *p_notify,
17745738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                                       UINT16 handle)
17755738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{
17765738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tBT_UUID        gattp_uuid, srvc_chg_uuid;
17775738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    BOOLEAN         processed = FALSE;
17785738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    UINT8           i;
17795738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
17805738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    gattp_uuid.len = 2;
17815738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    gattp_uuid.uu.uuid16 = UUID_SERVCLASS_GATT_SERVER;
17825738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
17835738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    srvc_chg_uuid.len = 2;
17845738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    srvc_chg_uuid.uu.uuid16 = GATT_UUID_GATT_SRV_CHGD;
17855738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
17866975b4d711142b885af479721cada448952c6b41Andre Eisenbach    if (bta_gattc_uuid_compare(&p_notify->char_id.srvc_id.id.uuid, &gattp_uuid, TRUE) &&
17876975b4d711142b885af479721cada448952c6b41Andre Eisenbach        bta_gattc_uuid_compare(&p_notify->char_id.char_id.uuid, &srvc_chg_uuid, TRUE))
17885738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
17895738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        processed = TRUE;
17905738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        /* mark service handle change pending */
17915738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        p_srcb->srvc_hdl_chg = TRUE;
17925738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        /* clear up all notification/indication registration */
17935738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        bta_gattc_clear_notif_registration(conn_id);
17945738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        /* service change indication all received, do discovery update */
17955738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        if ( ++ p_srcb->update_count == bta_gattc_num_reg_app())
17965738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        {
17975738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            /* not an opened connection; or connection busy */
17985738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            /* search for first available clcb and start discovery */
17995738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            if (p_clcb == NULL || (p_clcb && p_clcb->p_q_cmd != NULL))
18005738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            {
18015738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                for (i = 0 ; i < BTA_GATTC_CLCB_MAX; i ++)
18025738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                {
18035738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                    if (bta_gattc_cb.clcb[i].in_use &&
18045738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                        bta_gattc_cb.clcb[i].p_srcb == p_srcb &&
18055738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                        bta_gattc_cb.clcb[i].p_q_cmd == NULL)
18065738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                    {
18075738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                        p_clcb = &bta_gattc_cb.clcb[i];
18085738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                        break;
18095738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                    }
18105738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                }
18115738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            }
18125738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            /* send confirmation here if this is an indication, it should always be */
18135738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            GATTC_SendHandleValueConfirm(conn_id, handle);
18145738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
18155738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            /* if connection available, refresh cache by doing discovery now */
18165738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            if (p_clcb != NULL)
18175738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                bta_gattc_sm_execute(p_clcb, BTA_GATTC_INT_DISCOVER_EVT, NULL);
18185738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        }
18195738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        /* notify applicationf or service change */
18205738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        if (p_clrcb->p_cback != NULL)
18215738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        {
18225738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project           (* p_clrcb->p_cback)(BTA_GATTC_SRVC_CHG_EVT, (tBTA_GATTC *)p_srcb->server_bda);
18235738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        }
18245738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
18255738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
18265738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
18275738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    return processed;
18285738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
18295738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project}
18305738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/*******************************************************************************
18315738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
18325738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function         bta_gattc_proc_other_indication
18335738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
18345738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description      process all non-service change indication/notification.
18355738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
18365738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns          None.
18375738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
18385738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/
18395738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectvoid bta_gattc_proc_other_indication(tBTA_GATTC_CLCB *p_clcb, UINT8 op,
18405738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                                     tGATT_CL_COMPLETE *p_data,
18415738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                                     tBTA_GATTC_NOTIFY *p_notify)
18425738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{
18435738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    APPL_TRACE_DEBUG2("bta_gattc_proc_other_indication check \
18445738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                       p_data->att_value.handle=%d p_data->handle=%d",
18455738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                       p_data->att_value.handle, p_data->handle);
18465738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    APPL_TRACE_DEBUG1("is_notify", p_notify->is_notify);
18475738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
18485738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    p_notify->is_notify = (op == GATTC_OPTYPE_INDICATION) ? FALSE : TRUE;
18495738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    p_notify->len = p_data->att_value.len;
18505738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    bdcpy(p_notify->bda, p_clcb->bda);
18515738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    memcpy(p_notify->value, p_data->att_value.value, p_data->att_value.len);
18525738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    p_notify->conn_id = p_clcb->bta_conn_id;
18535738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
18545738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    if (p_clcb->p_rcb->p_cback)
18555738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        (*p_clcb->p_rcb->p_cback)(BTA_GATTC_NOTIF_EVT,  (tBTA_GATTC *)p_notify);
18565738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
18575738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project}
18585738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/*******************************************************************************
18595738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
18605738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function         bta_gattc_process_indicate
18615738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
18625738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description      process indication/notification.
18635738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
18645738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns          None.
18655738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
18665738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/
18675738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectvoid bta_gattc_process_indicate(UINT16 conn_id, tGATTC_OPTYPE op, tGATT_CL_COMPLETE *p_data)
18685738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{
18695738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    UINT16              handle = p_data->att_value.handle;
18705738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tBTA_GATTC_CLCB     *p_clcb ;
18715738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tBTA_GATTC_RCB      *p_clrcb = NULL;
18725738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tBTA_GATTC_SERV     *p_srcb = NULL;
18735738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tBTA_GATTC_NOTIFY   notify;
18745738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    BD_ADDR             remote_bda;
18755738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tBTA_GATTC_IF       gatt_if;
18765738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
18775738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    if (!GATT_GetConnectionInfor(conn_id, &gatt_if, remote_bda))
18785738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
18795738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        APPL_TRACE_ERROR0("indication/notif for unknown app");
18805738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        return;
18815738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
18825738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
18835738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    if ((p_clrcb = bta_gattc_cl_get_regcb(gatt_if)) == NULL)
18845738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
18855738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        APPL_TRACE_ERROR0("indication/notif for unregistered app");
18865738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        return;
18875738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
18885738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
18895738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    if ((p_srcb = bta_gattc_find_srcb(remote_bda)) == NULL)
18905738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
18915738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        APPL_TRACE_ERROR0("indication/notif for unknown device, ignore");
18925738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        return;
18935738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
18945738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
18955738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    p_clcb = bta_gattc_find_clcb_by_conn_id(conn_id);
18965738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
18975738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    if (bta_gattc_handle2id(p_srcb, handle,
18985738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                            &notify.char_id.srvc_id,
18995738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                            &notify.char_id.char_id,
19005738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                            &notify.descr_type))
19015738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
19025738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        /* if non-service change indication/notification, forward to application */
19035738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        if (!bta_gattc_process_srvc_chg_ind(conn_id, p_clrcb, p_srcb, p_clcb, &notify, handle))
19045738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        {
19055738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            /* if app registered for the notification */
19065738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            if (bta_gattc_check_notif_registry(p_clrcb, p_srcb, &notify))
19075738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            {
19085738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                /* connection not open yet */
19095738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                if (p_clcb == NULL)
19105738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                {
19115738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                    if ((p_clcb = bta_gattc_clcb_alloc(gatt_if, remote_bda)) != NULL)
19125738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                    {
19135738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                        p_clcb->bta_conn_id = conn_id;
19145738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
19156975b4d711142b885af479721cada448952c6b41Andre Eisenbach                        bta_gattc_sm_execute(p_clcb, BTA_GATTC_INT_CONN_EVT, NULL);
19165738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                    }
19175738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                    else
19185738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                    {
19195738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                        APPL_TRACE_ERROR0("No resources");
19205738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                    }
19215738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                }
19225738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
19235738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                if (p_clcb != NULL)
19245738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                    bta_gattc_proc_other_indication(p_clcb, op, p_data, &notify);
19255738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            }
19265738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            /* no one intersted and need ack? */
19275738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            else if (op == GATTC_OPTYPE_INDICATION)
19285738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            {
19295738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                APPL_TRACE_DEBUG0("no one interested, ack now");
19305738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                GATTC_SendHandleValueConfirm(conn_id, handle);
19315738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            }
19325738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        }
19335738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
19345738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    else
19355738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
19365738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        APPL_TRACE_ERROR1("Indi/Notif for Unknown handle[0x%04x], can not find in local cache.", handle);
19375738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
19385738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project}
19395738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/*******************************************************************************
19405738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
19415738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function         bta_gattc_cmpl_cback
19425738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
19435738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description      client operation complete callback register with BTE GATT.
19445738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
19455738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns          None.
19465738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project**
19475738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/
19485738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectstatic void  bta_gattc_cmpl_cback(UINT16 conn_id, tGATTC_OPTYPE op, tGATT_STATUS status,
19495738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                                  tGATT_CL_COMPLETE *p_data)
19505738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{
19515738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tBTA_GATTC_CLCB     *p_clcb ;
19525738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    tBTA_GATTC_OP_CMPL  *p_buf;
19535738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    UINT16              len = sizeof(tBTA_GATTC_OP_CMPL) + sizeof(tGATT_CL_COMPLETE);
19545738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
19555738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    APPL_TRACE_DEBUG3("bta_gattc_cmpl_cback: conn_id = %d op = %d status = %d",
19565738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project                      conn_id, op, status);
19575738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
19585738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    /* notification and indication processed right away */
19595738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    if (op == GATTC_OPTYPE_NOTIFICATION || op == GATTC_OPTYPE_INDICATION)
19605738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
19615738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        bta_gattc_process_indicate(conn_id, op, p_data);
19625738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        return;
19635738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
19645738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    /* for all other operation, not expected if w/o connection */
19655738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    else if ((p_clcb = bta_gattc_find_clcb_by_conn_id(conn_id)) == NULL)
19665738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
19675738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        APPL_TRACE_ERROR1("bta_gattc_cmpl_cback unknown conn_id =  %d, ignore data", conn_id);
19685738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        return;
19695738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
19705738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
1971781b5adee20e222ef87b56b72bfcd3f64013e4a0Andre Eisenbach
1972781b5adee20e222ef87b56b72bfcd3f64013e4a0Andre Eisenbach/* if over BR_EDR, inform PM for mode change */
1973781b5adee20e222ef87b56b72bfcd3f64013e4a0Andre Eisenbach    if (!BTM_IsBleLink(p_clcb->bda))
1974781b5adee20e222ef87b56b72bfcd3f64013e4a0Andre Eisenbach    {
1975781b5adee20e222ef87b56b72bfcd3f64013e4a0Andre Eisenbach        bta_sys_busy(BTA_ID_GATTC, BTA_ALL_APP_ID, p_clcb->bda);
1976781b5adee20e222ef87b56b72bfcd3f64013e4a0Andre Eisenbach        bta_sys_idle(BTA_ID_GATTC, BTA_ALL_APP_ID, p_clcb->bda);
1977781b5adee20e222ef87b56b72bfcd3f64013e4a0Andre Eisenbach    }
1978781b5adee20e222ef87b56b72bfcd3f64013e4a0Andre Eisenbach
19795738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    if ((p_buf = (tBTA_GATTC_OP_CMPL *) GKI_getbuf(len)) != NULL)
19805738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    {
19815738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        memset(p_buf, 0, len);
19825738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        p_buf->hdr.event = BTA_GATTC_OP_CMPL_EVT;
19835738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        p_buf->hdr.layer_specific = conn_id;
19845738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        p_buf->status = status;
19855738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        p_buf->op_code = op;
19865738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
19875738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        if (p_data != NULL)
19885738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        {
19895738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            p_buf->p_cmpl = (tGATT_CL_COMPLETE *)(p_buf + 1);
19905738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project            memcpy(p_buf->p_cmpl, p_data, sizeof(tGATT_CL_COMPLETE));
19915738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        }
19925738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
19935738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project        bta_sys_sendmsg(p_buf);
19945738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    }
19955738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project
19965738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project    return;
19975738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project}
1998ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta#if BLE_INCLUDED == TRUE
1999ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta/*******************************************************************************
2000ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta**
2001ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta** Function         bta_gattc_init_clcb_conn
2002ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta**
2003ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta** Description      Initaite a BTA CLCB connection
2004ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta**
2005ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta** Returns          void
2006ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta**
2007ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta********************************************************************************/
2008ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Battavoid bta_gattc_init_clcb_conn(UINT8 cif, BD_ADDR remote_bda)
2009ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta{
2010ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    tBTA_GATTC_CLCB     *p_clcb = NULL;
2011ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    tBTA_GATTC_DATA     gattc_data;
2012ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    UINT16              conn_id;
2013ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta
2014ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    /* should always get the connection ID */
2015ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    if (GATT_GetConnIdIfConnected(cif, remote_bda,&conn_id) == FALSE)
2016ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    {
2017ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta        APPL_TRACE_ERROR0("bta_gattc_init_clcb_conn ERROR: not a connected device");
2018ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta        return;
2019ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    }
2020ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta
2021ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    /* initaite a new connection here */
2022ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    if ((p_clcb = bta_gattc_clcb_alloc(cif, remote_bda)) != NULL)
2023ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    {
2024ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta        gattc_data.hdr.layer_specific = p_clcb->bta_conn_id = conn_id;
2025ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta
2026ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta        gattc_data.api_conn.client_if = cif;
2027ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta        memcpy(gattc_data.api_conn.remote_bda, remote_bda, BD_ADDR_LEN);
2028ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta        gattc_data.api_conn.is_direct = TRUE;
2029ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta
2030ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta        bta_gattc_sm_execute(p_clcb, BTA_GATTC_API_OPEN_EVT, &gattc_data);
2031ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    }
2032ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    else
2033ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    {
2034ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta        APPL_TRACE_ERROR0("No resources");
2035ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    }
2036ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta}
20375c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach/*******************************************************************************
20385c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach**
20395c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach** Function         bta_gattc_process_listen_all
20405c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach**
20415c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach** Description      process listen all, send open callback to application for all
20425c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach**                  connected slave LE link.
20435c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach**
20445c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach** Returns          void
20455c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach**
20465c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach********************************************************************************/
20475c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbachvoid bta_gattc_process_listen_all(UINT8 cif)
20485c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach{
20495c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach    UINT8               i_conn = 0;
20505c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach    tBTA_GATTC_CONN     *p_conn = &bta_gattc_cb.conn_track[0];
20515c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach
20525c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach    for (i_conn = 0; i_conn < BTA_GATTC_CONN_MAX; i_conn++, p_conn ++)
20535c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach    {
20545c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach        if (p_conn->in_use )
20555c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach        {
20565c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach            if (bta_gattc_find_clcb_by_cif(cif, p_conn->remote_bda) == NULL)
20575c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach            {
20585c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach                bta_gattc_init_clcb_conn(cif, p_conn->remote_bda);
20595c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach            }
20605c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach            /* else already connected */
20615c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach        }
20625c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach    }
20635c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach}
20645c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach/*******************************************************************************
20655c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach**
20665c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach** Function         bta_gattc_listen
20675c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach**
20685c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach** Description      Start or stop a listen for connection
20695c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach**
20705c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach** Returns          void
20715c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach**
20725c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach********************************************************************************/
20735c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbachvoid bta_gattc_listen(tBTA_GATTC_CB *p_cb, tBTA_GATTC_DATA * p_msg)
20745c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach{
20755c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach    tBTA_GATTC_RCB      *p_clreg = bta_gattc_cl_get_regcb(p_msg->api_listen.client_if);
20765c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach    tBTA_GATTC          cb_data;
20775c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach    cb_data.reg_oper.status = BTA_GATT_ERROR;
20785c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach    cb_data.reg_oper.client_if = p_msg->api_listen.client_if;
20795c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach
20805c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach    if (p_clreg == NULL)
20815c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach    {
20825c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach        APPL_TRACE_ERROR1("bta_gattc_listen failed, unknown client_if: %d",
20835c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach                            p_msg->api_listen.client_if);
20845c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach        return;
20855c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach    }
20865c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach    /* mark bg conn record */
20875c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach    if (bta_gattc_mark_bg_conn(p_msg->api_listen.client_if,
20885c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach                               (BD_ADDR_PTR) p_msg->api_listen.remote_bda,
20895c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach                               p_msg->api_listen.start,
20905c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach                               TRUE))
20915c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach    {
20925c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach        if (!GATT_Listen(p_msg->api_listen.client_if,
20935c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach                         p_msg->api_listen.start,
20945c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach                         p_msg->api_listen.remote_bda))
20955c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach        {
20965c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach            APPL_TRACE_ERROR0("Listen failure");
20975c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach            (*p_clreg->p_cback)(BTA_GATTC_LISTEN_EVT, &cb_data);
20985c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach        }
20995c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach        else
21005c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach        {
21015c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach            cb_data.status = BTA_GATT_OK;
21025c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach
21035c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach            (*p_clreg->p_cback)(BTA_GATTC_LISTEN_EVT, &cb_data);
21045c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach
21055c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach            if (p_msg->api_listen.start)
21065c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach            {
21075c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach                /* if listen to a specific target */
21085c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach                if (p_msg->api_listen.remote_bda != NULL)
21095c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach                {
2110ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta
21115c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach                    /* if is a connected remote device */
21125c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach                    if (L2CA_GetBleConnRole(p_msg->api_listen.remote_bda) == HCI_ROLE_SLAVE &&
21135c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach                        bta_gattc_find_clcb_by_cif(p_msg->api_listen.client_if, p_msg->api_listen.remote_bda) == NULL)
21145c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach                    {
21155c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach
21165c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach                        bta_gattc_init_clcb_conn(p_msg->api_listen.client_if,
21175c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach                                                p_msg->api_listen.remote_bda);
21185c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach                    }
21195c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach                }
21205c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach                /* if listen to all */
21215c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach                else
21225c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach                {
21235c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach                    APPL_TRACE_ERROR0("Listen For All now");
21245c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach                    /* go through all connected device and send callback for all connected slave connection */
21255c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach                    bta_gattc_process_listen_all(p_msg->api_listen.client_if);
21265c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach                }
21275c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach            }
21285c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach        }
21295c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach    }
21305c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach}
2131a4611ac05f07360785adcff8640da01a3894e4c5Andre Eisenbach
2132a4611ac05f07360785adcff8640da01a3894e4c5Andre Eisenbach/*******************************************************************************
2133a4611ac05f07360785adcff8640da01a3894e4c5Andre Eisenbach**
2134a4611ac05f07360785adcff8640da01a3894e4c5Andre Eisenbach** Function         bta_gattc_broadcast
2135a4611ac05f07360785adcff8640da01a3894e4c5Andre Eisenbach**
2136a4611ac05f07360785adcff8640da01a3894e4c5Andre Eisenbach** Description      Start or stop broadcasting
2137a4611ac05f07360785adcff8640da01a3894e4c5Andre Eisenbach**
2138a4611ac05f07360785adcff8640da01a3894e4c5Andre Eisenbach** Returns          void
2139a4611ac05f07360785adcff8640da01a3894e4c5Andre Eisenbach**
2140a4611ac05f07360785adcff8640da01a3894e4c5Andre Eisenbach********************************************************************************/
2141a4611ac05f07360785adcff8640da01a3894e4c5Andre Eisenbachvoid bta_gattc_broadcast(tBTA_GATTC_CB *p_cb, tBTA_GATTC_DATA * p_msg)
2142a4611ac05f07360785adcff8640da01a3894e4c5Andre Eisenbach{
2143a4611ac05f07360785adcff8640da01a3894e4c5Andre Eisenbach    tBTA_GATTC_RCB      *p_clreg = bta_gattc_cl_get_regcb(p_msg->api_listen.client_if);
2144a4611ac05f07360785adcff8640da01a3894e4c5Andre Eisenbach    tBTA_GATTC          cb_data;
2145a4611ac05f07360785adcff8640da01a3894e4c5Andre Eisenbach    (void)(p_cb);
2146a4611ac05f07360785adcff8640da01a3894e4c5Andre Eisenbach
2147a4611ac05f07360785adcff8640da01a3894e4c5Andre Eisenbach    cb_data.reg_oper.client_if = p_msg->api_listen.client_if;
2148a4611ac05f07360785adcff8640da01a3894e4c5Andre Eisenbach    cb_data.reg_oper.status = BTM_BleBroadcast(p_msg->api_listen.start);
2149a4611ac05f07360785adcff8640da01a3894e4c5Andre Eisenbach
2150a4611ac05f07360785adcff8640da01a3894e4c5Andre Eisenbach    if (p_clreg && p_clreg->p_cback)
2151a4611ac05f07360785adcff8640da01a3894e4c5Andre Eisenbach        (*p_clreg->p_cback)(BTA_GATTC_LISTEN_EVT, &cb_data);
2152a4611ac05f07360785adcff8640da01a3894e4c5Andre Eisenbach}
21535c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach#endif
21545c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach#endif
2155