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 Server 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 275738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project#include "bt_target.h" 285738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 295738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project#if defined(BTA_GATT_INCLUDED) && (BTA_GATT_INCLUDED == TRUE) 305738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 315738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project#include "utl.h" 325738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project#include "gki.h" 335738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project#include "bta_sys.h" 345738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project#include "bta_gatts_int.h" 355738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project#include "bta_gatts_co.h" 36781b5adee20e222ef87b56b72bfcd3f64013e4a0Andre Eisenbach#include "btm_ble_api.h" 375738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project#include <string.h> 385738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 395738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectstatic void bta_gatts_nv_save_cback(BOOLEAN is_saved, tGATTS_HNDL_RANGE *p_hndl_range); 407fa4fba6f59f97df00aff07dbe8fb21b114b3c2cGanesh Ganapathi Battastatic BOOLEAN bta_gatts_nv_srv_chg_cback(tGATTS_SRV_CHG_CMD cmd, tGATTS_SRV_CHG_REQ *p_req, 417fa4fba6f59f97df00aff07dbe8fb21b114b3c2cGanesh Ganapathi Batta tGATTS_SRV_CHG_RSP *p_rsp); 425738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 437fa4fba6f59f97df00aff07dbe8fb21b114b3c2cGanesh Ganapathi Battastatic void bta_gatts_conn_cback (tGATT_IF gatt_if, BD_ADDR bda, UINT16 conn_id, 447fa4fba6f59f97df00aff07dbe8fb21b114b3c2cGanesh Ganapathi Batta BOOLEAN connected, tGATT_DISCONN_REASON reason, 457fa4fba6f59f97df00aff07dbe8fb21b114b3c2cGanesh Ganapathi Batta tGATT_TRANSPORT transport); 465738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectstatic void bta_gatts_send_request_cback (UINT16 conn_id, 475738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project UINT32 trans_id, 485738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project tGATTS_REQ_TYPE req_type, tGATTS_DATA *p_data); 4917b04bd498405f2bb109a85562ebbdcb6bb06e95Andre Eisenbachstatic void bta_gatts_cong_cback (UINT16 conn_id, BOOLEAN congested); 5017b04bd498405f2bb109a85562ebbdcb6bb06e95Andre Eisenbach 515738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectstatic tGATT_CBACK bta_gatts_cback = 525738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{ 535738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project bta_gatts_conn_cback, 545738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project NULL, 555738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project NULL, 565738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project NULL, 577051db3a486aae771d9b5a81c3546790f86ede34Zhihai Xu bta_gatts_send_request_cback, 5817b04bd498405f2bb109a85562ebbdcb6bb06e95Andre Eisenbach NULL, 5917b04bd498405f2bb109a85562ebbdcb6bb06e95Andre Eisenbach bta_gatts_cong_cback 605738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project}; 615738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 625738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source ProjecttGATT_APPL_INFO bta_gatts_nv_cback = 635738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{ 645738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project bta_gatts_nv_save_cback, 655738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project bta_gatts_nv_srv_chg_cback 665738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project}; 675738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 685738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/******************************************************************************* 695738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 705738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function bta_gatts_nv_save_cback 715738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 725738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description NV save callback function. 735738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 745738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Parameter is_add: true is to add a handle range; otherwise is to delete. 755738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns none. 765738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 775738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/ 785738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectstatic void bta_gatts_nv_save_cback(BOOLEAN is_add, tGATTS_HNDL_RANGE *p_hndl_range) 795738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{ 805738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project bta_gatts_co_update_handle_range(is_add, (tBTA_GATTS_HNDL_RANGE *)p_hndl_range); 815738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project} 825738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 835738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 845738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/******************************************************************************* 855738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 865738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function bta_gatts_nv_srv_chg_cback 875738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 885738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description NV save callback function. 895738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 905738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Parameter is_add: true is to add a handle range; otherwise is to delete. 915738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns none. 925738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 935738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/ 947fa4fba6f59f97df00aff07dbe8fb21b114b3c2cGanesh Ganapathi Battastatic BOOLEAN bta_gatts_nv_srv_chg_cback(tGATTS_SRV_CHG_CMD cmd, 957fa4fba6f59f97df00aff07dbe8fb21b114b3c2cGanesh Ganapathi Batta tGATTS_SRV_CHG_REQ *p_req, tGATTS_SRV_CHG_RSP *p_rsp) 965738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{ 975738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project return bta_gatts_co_srv_chg((tBTA_GATTS_SRV_CHG_CMD) cmd, 985738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project (tBTA_GATTS_SRV_CHG_REQ *) p_req, 995738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project (tBTA_GATTS_SRV_CHG_RSP *) p_rsp); 1005738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project} 1015738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 1025738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 1035738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/******************************************************************************* 1045738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 1055738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function bta_gatts_enable 1065738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 1075738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description enable BTA GATTS module. 1085738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 1095738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns none. 1105738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 1115738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/ 1125738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectvoid bta_gatts_enable(tBTA_GATTS_CB *p_cb) 1135738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{ 1145738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project UINT8 index=0; 1155738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project tBTA_GATTS_HNDL_RANGE handle_range; 116e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach tBTA_GATT_STATUS status = BTA_GATT_OK; 1175738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 118e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach if (p_cb->enabled) 1195738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 120e8c3d75b75493911ebf0f99c83676359657178f7Sharvil Nanavati APPL_TRACE_DEBUG("GATTS already enabled."); 1215738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 122e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach else 123e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach { 124e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach memset(p_cb, 0, sizeof(tBTA_GATTS_CB)); 1255738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 126e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach p_cb->enabled = TRUE; 127e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach 128e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach while ( bta_gatts_co_load_handle_range(index, &handle_range)) 129e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach { 130e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach GATTS_AddHandleRange((tGATTS_HNDL_RANGE *)&handle_range); 131e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach memset(&handle_range, 0, sizeof(tGATTS_HNDL_RANGE)); 132e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach index++; 133e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach } 134e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach 135e8c3d75b75493911ebf0f99c83676359657178f7Sharvil Nanavati APPL_TRACE_DEBUG("bta_gatts_enable: num of handle range added=%d", index); 136e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach 137e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach if (!GATTS_NVRegister(&bta_gatts_nv_cback)) 138e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach { 139e8c3d75b75493911ebf0f99c83676359657178f7Sharvil Nanavati APPL_TRACE_ERROR("BTA GATTS NV register failed."); 140e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach status = BTA_GATT_ERROR; 141e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach } 142e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach } 143e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach} 144e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach 145e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach/******************************************************************************* 146e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach** 147e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach** Function bta_gatts_api_disable 148e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach** 149e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach** Description disable BTA GATTS module. 150e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach** 151e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach** Returns none. 152e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach** 153e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach*******************************************************************************/ 154e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbachvoid bta_gatts_api_disable(tBTA_GATTS_CB *p_cb) 155e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach{ 156e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach UINT8 i; 157e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach tBTA_GATT_STATUS status = BTA_GATT_OK; 1585738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 159e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach if (p_cb->enabled) 1605738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 161e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach for (i = 0; i < BTA_GATTS_MAX_APP_NUM; i ++) 162e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach { 163e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach if (p_cb->rcb[i].in_use) 164e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach { 165e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach GATT_Deregister(p_cb->rcb[i].gatt_if); 166e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach } 167e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach } 168e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach memset(p_cb, 0, sizeof(tBTA_GATTS_CB)); 169e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach } 170e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach else 171e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach { 172e8c3d75b75493911ebf0f99c83676359657178f7Sharvil Nanavati APPL_TRACE_ERROR("GATTS not enabled"); 1735738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 1745738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project} 175e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach 1765738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/******************************************************************************* 1775738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 1785738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function bta_gatts_register 1795738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 1805738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description register an application. 1815738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 1825738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns none. 1835738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 1845738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/ 1855738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectvoid bta_gatts_register(tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA *p_msg) 1865738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{ 1875738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project tBTA_GATTS_INT_START_IF *p_buf; 1885738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project tBTA_GATTS cb_data; 1895738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project tBTA_GATT_STATUS status = BTA_GATT_OK; 1905738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project UINT8 i, first_unuse = 0xff; 1915738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 192e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach if (p_cb->enabled == FALSE) 193e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach { 1945738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project bta_gatts_enable(p_cb); 195e1202caae4920139ea0cfed5c51f5f76b2dc8bc4Andre Eisenbach } 1965738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 1975738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project for (i = 0; i < BTA_GATTS_MAX_APP_NUM; i ++) 1985738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 1995738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project if (p_cb->rcb[i].in_use) 2005738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 2015738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project if (bta_gatts_uuid_compare(p_cb->rcb[i].app_uuid, p_msg->api_reg.app_uuid)) 2025738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 203e8c3d75b75493911ebf0f99c83676359657178f7Sharvil Nanavati APPL_TRACE_ERROR("application already registered."); 2045738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project status = BTA_GATT_DUP_REG; 2055738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project break; 2065738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 2075738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 2085738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 2095738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 2105738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project if (status == BTA_GATT_OK) 2115738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 2125738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project for (i = 0; i < BTA_GATTS_MAX_APP_NUM; i ++) 2135738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 2145738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project if (first_unuse == 0xff && !p_cb->rcb[i].in_use) 2155738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 2165738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project first_unuse = i; 2175738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project break; 2185738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 2195738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 2205738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 2215738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project cb_data.reg_oper.server_if = BTA_GATTS_INVALID_IF; 2225738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project// btla-specific ++ 2235738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project memcpy(&cb_data.reg_oper.uuid, &p_msg->api_reg.app_uuid, sizeof(tBT_UUID)); 2245738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project// btla-specific -- 2255738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project if (first_unuse != 0xff) 2265738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 227e8c3d75b75493911ebf0f99c83676359657178f7Sharvil Nanavati APPL_TRACE_ERROR("register application first_unuse rcb_idx = %d", first_unuse); 2285738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 2295738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project p_cb->rcb[first_unuse].in_use = TRUE; 2305738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project p_cb->rcb[first_unuse].p_cback = p_msg->api_reg.p_cback; 2315738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project memcpy(&p_cb->rcb[first_unuse].app_uuid, &p_msg->api_reg.app_uuid, sizeof(tBT_UUID)); 2325738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project cb_data.reg_oper.server_if = 23316fe0822ccd3eb6f66d3afd9965d25a0a0cb4c30Prerepa Viswanadham p_cb->rcb[first_unuse].gatt_if = 2347fa4fba6f59f97df00aff07dbe8fb21b114b3c2cGanesh Ganapathi Batta GATT_Register(&p_msg->api_reg.app_uuid, &bta_gatts_cback); 2355738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project if ( !p_cb->rcb[first_unuse].gatt_if) 2365738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 2375738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project status = BTA_GATT_NO_RESOURCES; 2385738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 2395738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project else 2405738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 2417fa4fba6f59f97df00aff07dbe8fb21b114b3c2cGanesh Ganapathi Batta if ((p_buf = 2427fa4fba6f59f97df00aff07dbe8fb21b114b3c2cGanesh Ganapathi Batta (tBTA_GATTS_INT_START_IF *) GKI_getbuf(sizeof(tBTA_GATTS_INT_START_IF))) != NULL) 2435738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 2445738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project p_buf->hdr.event = BTA_GATTS_INT_START_IF_EVT; 2455738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project p_buf->server_if = p_cb->rcb[first_unuse].gatt_if; 2465738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 2475738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project bta_sys_sendmsg(p_buf); 2485738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 2495738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project else 2505738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 2515738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project status = BTA_GATT_NO_RESOURCES; 2525738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project memset( &p_cb->rcb[first_unuse], 0 , sizeof(tBTA_GATTS_RCB)); 2535738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 2545738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 2555738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 2565738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project else 2575738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 2585738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project status = BTA_GATT_NO_RESOURCES; 2595738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 2605738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 2615738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 2625738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project cb_data.reg_oper.status = status; 2635738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project if (p_msg->api_reg.p_cback) 2645738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project (*p_msg->api_reg.p_cback)(BTA_GATTS_REG_EVT, &cb_data); 2655738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project} 2665738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 2675738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 2685738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/******************************************************************************* 2695738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 2705738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function bta_gatts_start_if 2715738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 2725738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description start an application interface. 2735738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 2745738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns none. 2755738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 2765738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/ 2775738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectvoid bta_gatts_start_if(tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA *p_msg) 2785738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{ 2795cd8bff2dd0337cb52bf48f312e3d2d55a8882fbMike J. Chen UNUSED(p_cb); 2805cd8bff2dd0337cb52bf48f312e3d2d55a8882fbMike J. Chen 2815738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project if (bta_gatts_find_app_rcb_by_app_if(p_msg->int_start_if.server_if)) 2825738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 2835738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project GATT_StartIf(p_msg->int_start_if.server_if); 2845738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 2855738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project else 2865738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 287e8c3d75b75493911ebf0f99c83676359657178f7Sharvil Nanavati APPL_TRACE_ERROR("Unable to start app.: Unknown interface =%d", 2887fa4fba6f59f97df00aff07dbe8fb21b114b3c2cGanesh Ganapathi Batta p_msg->int_start_if.server_if ); 2895738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 2905738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project} 2915738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/******************************************************************************* 2925738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 2935738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function bta_gatts_deregister 2945738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 2955738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description deregister an application. 2965738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 2975738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns none. 2985738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 2995738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/ 3005738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectvoid bta_gatts_deregister(tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA *p_msg) 3015738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{ 3025738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project tBTA_GATT_STATUS status = BTA_GATT_ERROR; 3035738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project tBTA_GATTS_CBACK *p_cback = NULL; 3045738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project UINT8 i; 3055738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project tBTA_GATTS cb_data; 3065738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 3075738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project cb_data.reg_oper.server_if = p_msg->api_dereg.server_if; 3085738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project cb_data.reg_oper.status = status; 3095738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 3105738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project for (i = 0; i < BTA_GATTS_MAX_APP_NUM; i ++) 3115738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 3125738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project if (p_cb->rcb[i].in_use && p_cb->rcb[i].gatt_if == p_msg->api_dereg.server_if) 3135738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 3145738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project p_cback = p_cb->rcb[i].p_cback; 3155738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project status = BTA_GATT_OK; 3165738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 3175738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project /* deregister the app */ 3185738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project GATT_Deregister(p_cb->rcb[i].gatt_if); 3195738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 3205738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project /* reset cb */ 3215738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project memset(&p_cb->rcb[i], 0, sizeof(tBTA_GATTS_RCB)); 3225738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project cb_data.reg_oper.status = status; 3235738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project break; 3245738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 3255738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 3265738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 3275738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project if (p_cback) 3285738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 3295738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project (*p_cback)(BTA_GATTS_DEREG_EVT, &cb_data); 3305738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 3315738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project else 3325738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 333e8c3d75b75493911ebf0f99c83676359657178f7Sharvil Nanavati APPL_TRACE_ERROR("application not registered."); 3345738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 3355738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project} 3365738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/******************************************************************************* 3375738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 3385738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function bta_gatts_create_srvc 3395738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 3405738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description action function to create a service. 3415738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 3425738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns none. 3435738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 3445738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/ 3455738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectvoid bta_gatts_create_srvc(tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA * p_msg) 3465738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{ 3475738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project UINT8 rcb_idx; 3485738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project tBTA_GATTS cb_data; 3495738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project UINT8 srvc_idx; 3505738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project UINT16 service_id = 0; 3515738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 3525738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project cb_data.create.status = BTA_GATT_ERROR; 3535738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 3545738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project rcb_idx = bta_gatts_find_app_rcb_idx_by_app_if(p_cb, p_msg->api_create_svc.server_if); 3555738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 356e8c3d75b75493911ebf0f99c83676359657178f7Sharvil Nanavati APPL_TRACE_ERROR("create service rcb_idx = %d", rcb_idx); 3575738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 3585738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project if (rcb_idx != BTA_GATTS_INVALID_APP) 3595738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 3605738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project if ((srvc_idx = bta_gatts_alloc_srvc_cb(p_cb, rcb_idx)) != BTA_GATTS_INVALID_APP) 3615738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 3625738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project /* create the service now */ 3635738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project service_id = GATTS_CreateService (p_cb->rcb[rcb_idx].gatt_if, 3645738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project &p_msg->api_create_svc.service_uuid, 3655738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project p_msg->api_create_svc.inst, 3665738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project p_msg->api_create_svc.num_handle, 3675738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project p_msg->api_create_svc.is_pri); 3685738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 3695738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project if (service_id != 0) 3705738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 3717fa4fba6f59f97df00aff07dbe8fb21b114b3c2cGanesh Ganapathi Batta memcpy(&p_cb->srvc_cb[srvc_idx].service_uuid, 3727fa4fba6f59f97df00aff07dbe8fb21b114b3c2cGanesh Ganapathi Batta &p_msg->api_create_svc.service_uuid, sizeof(tBT_UUID)); 3735738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project p_cb->srvc_cb[srvc_idx].service_id = service_id; 3745738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project p_cb->srvc_cb[srvc_idx].inst_num = p_msg->api_create_svc.inst; 3755738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project p_cb->srvc_cb[srvc_idx].idx = srvc_idx; 3765738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 3775738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project cb_data.create.status = BTA_GATT_OK; 3785738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project cb_data.create.service_id = service_id; 3795738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project// btla-specific ++ 3805738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project cb_data.create.is_primary = p_msg->api_create_svc.is_pri; 3815738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project// btla-specific -- 3825738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project cb_data.create.server_if = p_cb->rcb[rcb_idx].gatt_if; 3835738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 3845738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project else 3855738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 3865738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project cb_data.status = BTA_GATT_ERROR; 3875738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project memset(&p_cb->srvc_cb[srvc_idx], 0, sizeof(tBTA_GATTS_SRVC_CB)); 388e8c3d75b75493911ebf0f99c83676359657178f7Sharvil Nanavati APPL_TRACE_ERROR("service creation failed."); 3895738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 3905738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project// btla-specific ++ 3915738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project memcpy(&cb_data.create.uuid, &p_msg->api_create_svc.service_uuid, sizeof(tBT_UUID)); 3925738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project cb_data.create.svc_instance= p_msg->api_create_svc.inst; 3935738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project// btla-specific -- 3945738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 3955738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project if (p_cb->rcb[rcb_idx].p_cback) 3965738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project (* p_cb->rcb[rcb_idx].p_cback)(BTA_GATTS_CREATE_EVT, &cb_data); 3975738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 3985738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project else /* application not registered */ 3995738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 400e8c3d75b75493911ebf0f99c83676359657178f7Sharvil Nanavati APPL_TRACE_ERROR("Application not registered"); 4015738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 4025738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project} 4035738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/******************************************************************************* 4045738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 4055738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function bta_gatts_add_include_srvc 4065738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 4075738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description action function to add an included service. 4085738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 4095738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns none. 4105738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 4115738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/ 4125738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectvoid bta_gatts_add_include_srvc(tBTA_GATTS_SRVC_CB *p_srvc_cb,tBTA_GATTS_DATA * p_msg) 4135738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{ 4145738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project tBTA_GATTS_RCB *p_rcb = &bta_gatts_cb.rcb[p_srvc_cb->rcb_idx]; 4155738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project UINT16 attr_id = 0; 4165738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project tBTA_GATTS cb_data; 4175738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 4185738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project attr_id = GATTS_AddIncludeService(p_msg->api_add_incl_srvc.hdr.layer_specific, 4195738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project p_msg->api_add_incl_srvc.included_service_id); 4205738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 4215738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project cb_data.add_result.server_if = p_rcb->gatt_if; 4225738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project cb_data.add_result.service_id = p_msg->api_add_incl_srvc.hdr.layer_specific; 4235738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project cb_data.add_result.attr_id = attr_id; 4245738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 4255738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project if (attr_id) 4265738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 4275738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project cb_data.add_result.status = BTA_GATT_OK; 4285738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 4295738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project else 4305738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 4315738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project cb_data.add_result.status = BTA_GATT_ERROR; 4325738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 4335738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 4345738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project if (p_rcb->p_cback) 4355738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project (*p_rcb->p_cback)(BTA_GATTS_ADD_INCL_SRVC_EVT, &cb_data); 4365738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project} 4375738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/******************************************************************************* 4385738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 4395738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function bta_gatts_add_char 4405738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 4415738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description action function to add characteristic. 4425738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 4435738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns none. 4445738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 4455738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/ 4465738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectvoid bta_gatts_add_char(tBTA_GATTS_SRVC_CB *p_srvc_cb, tBTA_GATTS_DATA * p_msg) 4475738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{ 4485738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project tBTA_GATTS_RCB *p_rcb = &bta_gatts_cb.rcb[p_srvc_cb->rcb_idx]; 4495738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project UINT16 attr_id = 0; 4505738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project tBTA_GATTS cb_data; 4515738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 4525738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project attr_id = GATTS_AddCharacteristic(p_msg->api_add_char.hdr.layer_specific, 4535738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project &p_msg->api_add_char.char_uuid, 4545738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project p_msg->api_add_char.perm, 4555738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project p_msg->api_add_char.property); 4565738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project cb_data.add_result.server_if = p_rcb->gatt_if; 4575738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project cb_data.add_result.service_id = p_msg->api_add_incl_srvc.hdr.layer_specific; 4585738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project cb_data.add_result.attr_id = attr_id; 4595738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project// btla-specific ++ 4605738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project memcpy(&cb_data.add_result.char_uuid, &p_msg->api_add_char.char_uuid, sizeof(tBT_UUID)); 4615738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project// btla-specific -- 4625738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 4635738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project if (attr_id) 4645738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 4655738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project cb_data.add_result.status = BTA_GATT_OK; 4665738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 4675738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project else 4685738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 4695738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project cb_data.add_result.status = BTA_GATT_ERROR; 4705738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 4715738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 4725738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project if (p_rcb->p_cback) 4735738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project (*p_rcb->p_cback)(BTA_GATTS_ADD_CHAR_EVT, &cb_data); 4745738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project} 4755738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/******************************************************************************* 4765738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 4775738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function bta_gatts_add_char_descr 4785738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 4795738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description action function to add characteristic descriptor. 4805738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 4815738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns none. 4825738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 4835738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/ 4845738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectvoid bta_gatts_add_char_descr(tBTA_GATTS_SRVC_CB *p_srvc_cb, tBTA_GATTS_DATA * p_msg) 4855738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{ 4865738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project tBTA_GATTS_RCB *p_rcb = &bta_gatts_cb.rcb[p_srvc_cb->rcb_idx]; 4875738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project UINT16 attr_id = 0; 4885738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project tBTA_GATTS cb_data; 4895738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 4905738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project attr_id = GATTS_AddCharDescriptor(p_msg->api_add_char_descr.hdr.layer_specific, 4915738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project p_msg->api_add_char_descr.perm, 4925738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project &p_msg->api_add_char_descr.descr_uuid); 4935738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 4945738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project cb_data.add_result.server_if = p_rcb->gatt_if; 4955738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project cb_data.add_result.service_id = p_msg->api_add_incl_srvc.hdr.layer_specific; 4965738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project cb_data.add_result.attr_id = attr_id; 4975738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project// btla-specific ++ 4985738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project memcpy(&cb_data.add_result.char_uuid, &p_msg->api_add_char_descr.descr_uuid, sizeof(tBT_UUID)); 4995738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project// btla-specific -- 5005738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 5015738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project if (attr_id) 5025738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 5035738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project cb_data.add_result.status = BTA_GATT_OK; 5045738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 5055738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project else 5065738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 5075738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project cb_data.add_result.status = BTA_GATT_ERROR; 5085738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 5095738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 5105738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project if (p_rcb->p_cback) 5115738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project (*p_rcb->p_cback)(BTA_GATTS_ADD_CHAR_DESCR_EVT, &cb_data); 5125738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 5135738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project} 5145738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/******************************************************************************* 5155738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 5165738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function bta_gatts_delete_service 5175738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 5185738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description action function to delete a service. 5195738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 5205738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns none. 5215738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 5225738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/ 5235738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectvoid bta_gatts_delete_service(tBTA_GATTS_SRVC_CB *p_srvc_cb, tBTA_GATTS_DATA * p_msg) 5245738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{ 5255738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project tBTA_GATTS_RCB *p_rcb = &bta_gatts_cb.rcb[p_srvc_cb->rcb_idx]; 5265738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project tBTA_GATTS cb_data; 5275738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 5285738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project cb_data.srvc_oper.server_if = p_rcb->gatt_if; 5295738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project cb_data.srvc_oper.service_id = p_msg->api_add_incl_srvc.hdr.layer_specific; 5305738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 5315738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project if (GATTS_DeleteService(p_rcb->gatt_if, 5325738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project &p_srvc_cb->service_uuid, 5335738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project p_srvc_cb->inst_num)) 5345738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 5355738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project cb_data.srvc_oper.status = BTA_GATT_OK; 5365738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project memset(p_srvc_cb, 0, sizeof(tBTA_GATTS_SRVC_CB)); 5375738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 5385738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project else 5395738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 5405738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project cb_data.srvc_oper.status = BTA_GATT_ERROR; 5415738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 5425738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 5435738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project if (p_rcb->p_cback) 5445738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project (*p_rcb->p_cback)(BTA_GATTS_DELELTE_EVT, &cb_data); 5455738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 5465738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project} 5475738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/******************************************************************************* 5485738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 5495738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function bta_gatts_start_service 5505738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 5515738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description action function to start a service. 5525738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 5535738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns none. 5545738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 5555738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/ 5565738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectvoid bta_gatts_start_service(tBTA_GATTS_SRVC_CB *p_srvc_cb, tBTA_GATTS_DATA * p_msg) 5575738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{ 5585738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project tBTA_GATTS_RCB *p_rcb = &bta_gatts_cb.rcb[p_srvc_cb->rcb_idx]; 5595738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project tBTA_GATTS cb_data; 5605738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 5615738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project cb_data.srvc_oper.server_if = p_rcb->gatt_if; 5625738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project cb_data.srvc_oper.service_id = p_msg->api_add_incl_srvc.hdr.layer_specific; 5635738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 5645738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project if (GATTS_StartService(p_rcb->gatt_if, 5655738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project p_srvc_cb->service_id, 5665738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project p_msg->api_start.transport) == GATT_SUCCESS) 5675738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 568e8c3d75b75493911ebf0f99c83676359657178f7Sharvil Nanavati APPL_TRACE_DEBUG("bta_gatts_start_service service_id= %d", p_srvc_cb->service_id); 5695738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project cb_data.srvc_oper.status = BTA_GATT_OK; 5705738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 5715738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project else 5725738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 5735738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project cb_data.srvc_oper.status = BTA_GATT_ERROR; 5745738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 5755738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 5765738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project if (p_rcb->p_cback) 5775738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project (*p_rcb->p_cback)(BTA_GATTS_START_EVT, &cb_data); 5785738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 5795738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project} 5805738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/******************************************************************************* 5815738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 5825738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function bta_gatts_stop_service 5835738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 5845738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description action function to stop a service. 5855738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 5865738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns none. 5875738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 5885738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/ 5895738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectvoid bta_gatts_stop_service(tBTA_GATTS_SRVC_CB *p_srvc_cb, tBTA_GATTS_DATA * p_msg) 5905738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{ 5915738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project tBTA_GATTS_RCB *p_rcb = &bta_gatts_cb.rcb[p_srvc_cb->rcb_idx]; 5925738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project tBTA_GATTS cb_data; 5935cd8bff2dd0337cb52bf48f312e3d2d55a8882fbMike J. Chen UNUSED(p_msg); 5945738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 5955738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project GATTS_StopService(p_srvc_cb->service_id); 5965738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project cb_data.srvc_oper.server_if = p_rcb->gatt_if; 5975738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project cb_data.srvc_oper.service_id = p_srvc_cb->service_id; 5985738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project cb_data.srvc_oper.status = BTA_GATT_OK; 599e8c3d75b75493911ebf0f99c83676359657178f7Sharvil Nanavati APPL_TRACE_ERROR("bta_gatts_stop_service service_id= %d", p_srvc_cb->service_id); 6005738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 6015738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project if (p_rcb->p_cback) 6025738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project (*p_rcb->p_cback)(BTA_GATTS_STOP_EVT, &cb_data); 6035738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 6045738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project} 6055738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/******************************************************************************* 6065738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 6076975b4d711142b885af479721cada448952c6b41Andre Eisenbach** Function bta_gatts_send_rsp 6085738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 6096975b4d711142b885af479721cada448952c6b41Andre Eisenbach** Description GATTS send response. 6105738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 6115738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns none. 6125738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 6135738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/ 6145738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectvoid bta_gatts_send_rsp (tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA * p_msg) 6155738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{ 6165cd8bff2dd0337cb52bf48f312e3d2d55a8882fbMike J. Chen UNUSED(p_cb); 6175738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 6185738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project if (GATTS_SendRsp (p_msg->api_rsp.hdr.layer_specific, 6195738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project p_msg->api_rsp.trans_id, 6205738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project p_msg->api_rsp.status, 6215738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project (tGATTS_RSP *)p_msg->api_rsp.p_rsp) != GATT_SUCCESS) 6225738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 623e8c3d75b75493911ebf0f99c83676359657178f7Sharvil Nanavati APPL_TRACE_ERROR("Sending response failed"); 6245738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 6255738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 6265738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project} 6275738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/******************************************************************************* 6285738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 629781b5adee20e222ef87b56b72bfcd3f64013e4a0Andre Eisenbach** Function bta_gatts_indicate_handle 6305738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 6316975b4d711142b885af479721cada448952c6b41Andre Eisenbach** Description GATTS send handle value indication or notification. 6325738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 6335738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns none. 6345738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 6355738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/ 6365738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectvoid bta_gatts_indicate_handle (tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA * p_msg) 6375738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{ 6385738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project tBTA_GATTS_SRVC_CB *p_srvc_cb; 63917b04bd498405f2bb109a85562ebbdcb6bb06e95Andre Eisenbach tBTA_GATTS_RCB *p_rcb = NULL; 640781b5adee20e222ef87b56b72bfcd3f64013e4a0Andre Eisenbach tBTA_GATT_STATUS status = BTA_GATT_ILLEGAL_PARAMETER; 641781b5adee20e222ef87b56b72bfcd3f64013e4a0Andre Eisenbach tGATT_IF gatt_if; 642781b5adee20e222ef87b56b72bfcd3f64013e4a0Andre Eisenbach BD_ADDR remote_bda; 6437fa4fba6f59f97df00aff07dbe8fb21b114b3c2cGanesh Ganapathi Batta tBTA_TRANSPORT transport; 64417b04bd498405f2bb109a85562ebbdcb6bb06e95Andre Eisenbach tBTA_GATTS cb_data; 6455738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 6465738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project p_srvc_cb = bta_gatts_find_srvc_cb_by_attr_id (p_cb, p_msg->api_indicate.attr_id); 6475738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 6485738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project if (p_srvc_cb ) 6495738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 6507fa4fba6f59f97df00aff07dbe8fb21b114b3c2cGanesh Ganapathi Batta if (GATT_GetConnectionInfor(p_msg->api_indicate.hdr.layer_specific, 6517fa4fba6f59f97df00aff07dbe8fb21b114b3c2cGanesh Ganapathi Batta &gatt_if, remote_bda, &transport)) 652781b5adee20e222ef87b56b72bfcd3f64013e4a0Andre Eisenbach { 65317b04bd498405f2bb109a85562ebbdcb6bb06e95Andre Eisenbach p_rcb = bta_gatts_find_app_rcb_by_app_if(gatt_if); 65417b04bd498405f2bb109a85562ebbdcb6bb06e95Andre Eisenbach 655781b5adee20e222ef87b56b72bfcd3f64013e4a0Andre Eisenbach if (p_msg->api_indicate.need_confirm) 6565738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 657781b5adee20e222ef87b56b72bfcd3f64013e4a0Andre Eisenbach status = GATTS_HandleValueIndication (p_msg->api_indicate.hdr.layer_specific, 658781b5adee20e222ef87b56b72bfcd3f64013e4a0Andre Eisenbach p_msg->api_indicate.attr_id, 659781b5adee20e222ef87b56b72bfcd3f64013e4a0Andre Eisenbach p_msg->api_indicate.len, 660781b5adee20e222ef87b56b72bfcd3f64013e4a0Andre Eisenbach p_msg->api_indicate.value); 661781b5adee20e222ef87b56b72bfcd3f64013e4a0Andre Eisenbach else 662781b5adee20e222ef87b56b72bfcd3f64013e4a0Andre Eisenbach status = GATTS_HandleValueNotification (p_msg->api_indicate.hdr.layer_specific, 663781b5adee20e222ef87b56b72bfcd3f64013e4a0Andre Eisenbach p_msg->api_indicate.attr_id, 664781b5adee20e222ef87b56b72bfcd3f64013e4a0Andre Eisenbach p_msg->api_indicate.len, 665781b5adee20e222ef87b56b72bfcd3f64013e4a0Andre Eisenbach p_msg->api_indicate.value); 666781b5adee20e222ef87b56b72bfcd3f64013e4a0Andre Eisenbach 667781b5adee20e222ef87b56b72bfcd3f64013e4a0Andre Eisenbach /* if over BR_EDR, inform PM for mode change */ 6687fa4fba6f59f97df00aff07dbe8fb21b114b3c2cGanesh Ganapathi Batta if (transport == BTA_TRANSPORT_BR_EDR) 669781b5adee20e222ef87b56b72bfcd3f64013e4a0Andre Eisenbach { 670781b5adee20e222ef87b56b72bfcd3f64013e4a0Andre Eisenbach bta_sys_busy(BTA_ID_GATTS, BTA_ALL_APP_ID, remote_bda); 671781b5adee20e222ef87b56b72bfcd3f64013e4a0Andre Eisenbach bta_sys_idle(BTA_ID_GATTS, BTA_ALL_APP_ID, remote_bda); 672781b5adee20e222ef87b56b72bfcd3f64013e4a0Andre Eisenbach } 673781b5adee20e222ef87b56b72bfcd3f64013e4a0Andre Eisenbach } 6745738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project else 675781b5adee20e222ef87b56b72bfcd3f64013e4a0Andre Eisenbach { 676e8c3d75b75493911ebf0f99c83676359657178f7Sharvil Nanavati APPL_TRACE_ERROR("Unknown connection ID: %d fail sending notification", 677781b5adee20e222ef87b56b72bfcd3f64013e4a0Andre Eisenbach p_msg->api_indicate.hdr.layer_specific); 678781b5adee20e222ef87b56b72bfcd3f64013e4a0Andre Eisenbach } 67917b04bd498405f2bb109a85562ebbdcb6bb06e95Andre Eisenbach 6807fa4fba6f59f97df00aff07dbe8fb21b114b3c2cGanesh Ganapathi Batta if ((status != GATT_SUCCESS || !p_msg->api_indicate.need_confirm) && 68117b04bd498405f2bb109a85562ebbdcb6bb06e95Andre Eisenbach p_rcb && p_cb->rcb[p_srvc_cb->rcb_idx].p_cback) 6825738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 68317b04bd498405f2bb109a85562ebbdcb6bb06e95Andre Eisenbach cb_data.req_data.status = status; 68417b04bd498405f2bb109a85562ebbdcb6bb06e95Andre Eisenbach cb_data.req_data.conn_id = p_msg->api_indicate.hdr.layer_specific; 68517b04bd498405f2bb109a85562ebbdcb6bb06e95Andre Eisenbach 68617b04bd498405f2bb109a85562ebbdcb6bb06e95Andre Eisenbach (*p_rcb->p_cback)(BTA_GATTS_CONF_EVT, &cb_data); 6875738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 6885738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 6895738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project else 6905738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 691e8c3d75b75493911ebf0f99c83676359657178f7Sharvil Nanavati APPL_TRACE_ERROR("Not an registered servce attribute ID: 0x%04x", 692781b5adee20e222ef87b56b72bfcd3f64013e4a0Andre Eisenbach p_msg->api_indicate.attr_id); 6935738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 6945738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project} 6955738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 6965738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 6975738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/******************************************************************************* 6985738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 6995738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function bta_gatts_open 7005738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 7015738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description 7025738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 7035738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns none. 7045738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 7055738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/ 7065738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectvoid bta_gatts_open (tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA * p_msg) 7075738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{ 7085738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project tBTA_GATTS_RCB *p_rcb=NULL; 7095738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project tBTA_GATT_STATUS status= BTA_GATT_ERROR; 7107fa4fba6f59f97df00aff07dbe8fb21b114b3c2cGanesh Ganapathi Batta UINT16 conn_id; 7115cd8bff2dd0337cb52bf48f312e3d2d55a8882fbMike J. Chen UNUSED(p_cb); 7125738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 7135738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project if ((p_rcb = bta_gatts_find_app_rcb_by_app_if(p_msg->api_open.server_if)) != NULL) 7145738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 7157fa4fba6f59f97df00aff07dbe8fb21b114b3c2cGanesh Ganapathi Batta /* should always get the connection ID */ 7167fa4fba6f59f97df00aff07dbe8fb21b114b3c2cGanesh Ganapathi Batta if (GATT_Connect(p_rcb->gatt_if, p_msg->api_open.remote_bda, 7177fa4fba6f59f97df00aff07dbe8fb21b114b3c2cGanesh Ganapathi Batta p_msg->api_open.is_direct, p_msg->api_open.transport)) 7185738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 7195738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project status = BTA_GATT_OK; 7207fa4fba6f59f97df00aff07dbe8fb21b114b3c2cGanesh Ganapathi Batta 7217fa4fba6f59f97df00aff07dbe8fb21b114b3c2cGanesh Ganapathi Batta if (GATT_GetConnIdIfConnected(p_rcb->gatt_if, p_msg->api_open.remote_bda, 7227fa4fba6f59f97df00aff07dbe8fb21b114b3c2cGanesh Ganapathi Batta &conn_id, p_msg->api_open.transport)) 7237fa4fba6f59f97df00aff07dbe8fb21b114b3c2cGanesh Ganapathi Batta { 7247fa4fba6f59f97df00aff07dbe8fb21b114b3c2cGanesh Ganapathi Batta status = BTA_GATT_ALREADY_OPEN; 7257fa4fba6f59f97df00aff07dbe8fb21b114b3c2cGanesh Ganapathi Batta } 7265738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 7275738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 7285738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project else 7295738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 730e8c3d75b75493911ebf0f99c83676359657178f7Sharvil Nanavati APPL_TRACE_ERROR("Inavlide server_if=%d", p_msg->api_open.server_if); 7315738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 7325738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 7335738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project if (p_rcb && p_rcb->p_cback) 7345738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project (*p_rcb->p_cback)(BTA_GATTS_OPEN_EVT, (tBTA_GATTS *)&status); 7355738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 7365738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project} 7375738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/******************************************************************************* 7385738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 7395738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function bta_gatts_cancel_open 7405738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 7415738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description 7425738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 7435738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns none. 7445738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 7455738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/ 7465738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectvoid bta_gatts_cancel_open (tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA * p_msg) 7475738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{ 7485738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project tBTA_GATTS_RCB *p_rcb; 7495738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project tBTA_GATT_STATUS status= BTA_GATT_ERROR; 7505cd8bff2dd0337cb52bf48f312e3d2d55a8882fbMike J. Chen UNUSED(p_cb); 7515738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 7525738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project if ((p_rcb = bta_gatts_find_app_rcb_by_app_if(p_msg->api_cancel_open.server_if)) != NULL) 7535738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 7547fa4fba6f59f97df00aff07dbe8fb21b114b3c2cGanesh Ganapathi Batta if (!GATT_CancelConnect(p_rcb->gatt_if, p_msg->api_cancel_open.remote_bda, 7557fa4fba6f59f97df00aff07dbe8fb21b114b3c2cGanesh Ganapathi Batta p_msg->api_cancel_open.is_direct)) 7565738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 757e8c3d75b75493911ebf0f99c83676359657178f7Sharvil Nanavati APPL_TRACE_ERROR("bta_gatts_cancel_open failed for open request"); 7585738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 7595738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project else 7605738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 7615738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project status= BTA_GATT_OK; 7625738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 7635738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 7645738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project else 7655738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 766e8c3d75b75493911ebf0f99c83676359657178f7Sharvil Nanavati APPL_TRACE_ERROR("Inavlide server_if=%d", p_msg->api_cancel_open.server_if); 7675738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 7685738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 7695738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project if (p_rcb && p_rcb->p_cback) 7705738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project (*p_rcb->p_cback)(BTA_GATTS_CANCEL_OPEN_EVT, (tBTA_GATTS *)&status); 7715738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project} 7725738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/******************************************************************************* 7735738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 7745738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function bta_gatts_close 7755738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 7765738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description 7775738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 7785738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns none. 7795738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 7805738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/ 7815738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectvoid bta_gatts_close (tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA * p_msg) 7825738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{ 7835738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project tBTA_GATTS_RCB *p_rcb; 7845738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project tBTA_GATT_STATUS status= BTA_GATT_ERROR; 7855738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project tGATT_IF gatt_if; 7865738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project BD_ADDR remote_bda; 7877fa4fba6f59f97df00aff07dbe8fb21b114b3c2cGanesh Ganapathi Batta tBTA_GATT_TRANSPORT transport; 7887fa4fba6f59f97df00aff07dbe8fb21b114b3c2cGanesh Ganapathi Batta 7895cd8bff2dd0337cb52bf48f312e3d2d55a8882fbMike J. Chen UNUSED(p_cb); 7905738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 7917fa4fba6f59f97df00aff07dbe8fb21b114b3c2cGanesh Ganapathi Batta if (GATT_GetConnectionInfor(p_msg->hdr.layer_specific, &gatt_if, remote_bda, &transport)) 7925738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 7935738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project if (GATT_Disconnect(p_msg->hdr.layer_specific) != GATT_SUCCESS) 7945738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 795e8c3d75b75493911ebf0f99c83676359657178f7Sharvil Nanavati APPL_TRACE_ERROR("bta_gatts_close fail conn_id=%d", p_msg->hdr.layer_specific); 7965738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 7975738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project else 7985738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 7995738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project status= BTA_GATT_OK; 8005738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 8015738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 8025738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project p_rcb = bta_gatts_find_app_rcb_by_app_if(gatt_if); 8035738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 8045738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project if (p_rcb && p_rcb->p_cback) 805781b5adee20e222ef87b56b72bfcd3f64013e4a0Andre Eisenbach { 8067fa4fba6f59f97df00aff07dbe8fb21b114b3c2cGanesh Ganapathi Batta if (transport == BTA_TRANSPORT_BR_EDR) 807781b5adee20e222ef87b56b72bfcd3f64013e4a0Andre Eisenbach bta_sys_conn_close( BTA_ID_GATTS ,BTA_ALL_APP_ID, remote_bda); 808781b5adee20e222ef87b56b72bfcd3f64013e4a0Andre Eisenbach 8095738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project (*p_rcb->p_cback)(BTA_GATTS_CLOSE_EVT, (tBTA_GATTS *)&status); 810781b5adee20e222ef87b56b72bfcd3f64013e4a0Andre Eisenbach } 8115738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 8125738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project else 8135738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 814e8c3d75b75493911ebf0f99c83676359657178f7Sharvil Nanavati APPL_TRACE_ERROR("Unknown connection ID: %d", p_msg->hdr.layer_specific); 8155738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 8165738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 8175738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project} 8185c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach/******************************************************************************* 8195c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach** 8205c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach** Function bta_gatts_listen 8215c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach** 8225c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach** Description Start or stop listening for LE connection on a GATT server 8235c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach** 8245c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach** Returns none. 8255c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach** 8265c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach*******************************************************************************/ 8275c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbachvoid bta_gatts_listen(tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA * p_msg) 8285c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach{ 8295c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach tBTA_GATTS_RCB *p_rcb = bta_gatts_find_app_rcb_by_app_if(p_msg->api_listen.server_if); 8305c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach tBTA_GATTS cb_data; 8315cd8bff2dd0337cb52bf48f312e3d2d55a8882fbMike J. Chen UNUSED(p_cb); 8325cd8bff2dd0337cb52bf48f312e3d2d55a8882fbMike J. Chen 8335c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach cb_data.reg_oper.status = BTA_GATT_OK; 8345c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach cb_data.reg_oper.server_if = p_msg->api_listen.server_if; 8355c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach 8365c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach if (p_rcb == NULL) 8375c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach { 838e8c3d75b75493911ebf0f99c83676359657178f7Sharvil Nanavati APPL_TRACE_ERROR("Unknown GATTS application"); 8395c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach return; 8405c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach } 8415c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach 8425c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach if (!GATT_Listen(p_msg->api_listen.server_if, 8435c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach p_msg->api_listen.start, 8445c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach p_msg->api_listen.remote_bda)) 8455c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach { 8465c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach cb_data.status = BTA_GATT_ERROR; 847e8c3d75b75493911ebf0f99c83676359657178f7Sharvil Nanavati APPL_TRACE_ERROR("bta_gatts_listen Listen failed"); 8485c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach } 8495c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach 8505c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach if (p_rcb->p_cback) 8515c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach (*p_rcb->p_cback)(BTA_GATTS_LISTEN_EVT, &cb_data); 8525c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach} 8535738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 8545738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/******************************************************************************* 8555738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 8565738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function bta_gatts_request_cback 8575738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 8585738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description GATTS attribute request callback. 8595738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 8605738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns none. 8615738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 8625738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/ 8635738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectstatic void bta_gatts_send_request_cback (UINT16 conn_id, 8645738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project UINT32 trans_id, 8655738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project tGATTS_REQ_TYPE req_type, tGATTS_DATA *p_data) 8665738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{ 8675738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project tBTA_GATTS cb_data; 8685738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project tBTA_GATTS_RCB *p_rcb; 8695738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project tGATT_IF gatt_if; 8707fa4fba6f59f97df00aff07dbe8fb21b114b3c2cGanesh Ganapathi Batta tBTA_GATT_TRANSPORT transport; 8715738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 8725738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project memset(&cb_data, 0 , sizeof(tBTA_GATTS)); 8735738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 8747fa4fba6f59f97df00aff07dbe8fb21b114b3c2cGanesh Ganapathi Batta if (GATT_GetConnectionInfor(conn_id, &gatt_if, cb_data.req_data.remote_bda, &transport)) 8755738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 8765738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project p_rcb = bta_gatts_find_app_rcb_by_app_if(gatt_if); 8775738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 878e8c3d75b75493911ebf0f99c83676359657178f7Sharvil Nanavati APPL_TRACE_DEBUG ("bta_gatts_send_request_cback conn_id=%d trans_id=%d req_type=%d", 8797fa4fba6f59f97df00aff07dbe8fb21b114b3c2cGanesh Ganapathi Batta conn_id, trans_id, req_type); 8805738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 8815738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project if (p_rcb && p_rcb->p_cback) 8825738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 883781b5adee20e222ef87b56b72bfcd3f64013e4a0Andre Eisenbach /* if over BR_EDR, inform PM for mode change */ 8847fa4fba6f59f97df00aff07dbe8fb21b114b3c2cGanesh Ganapathi Batta if (transport == BTA_TRANSPORT_BR_EDR) 885781b5adee20e222ef87b56b72bfcd3f64013e4a0Andre Eisenbach { 886781b5adee20e222ef87b56b72bfcd3f64013e4a0Andre Eisenbach bta_sys_busy(BTA_ID_GATTS, BTA_ALL_APP_ID, cb_data.req_data.remote_bda); 887781b5adee20e222ef87b56b72bfcd3f64013e4a0Andre Eisenbach bta_sys_idle(BTA_ID_GATTS, BTA_ALL_APP_ID, cb_data.req_data.remote_bda); 888781b5adee20e222ef87b56b72bfcd3f64013e4a0Andre Eisenbach } 889781b5adee20e222ef87b56b72bfcd3f64013e4a0Andre Eisenbach 8905738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project cb_data.req_data.conn_id = conn_id; 8915738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project cb_data.req_data.trans_id = trans_id; 8925738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project cb_data.req_data.p_data = (tBTA_GATTS_REQ_DATA *)p_data; 8935738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 8945738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project (*p_rcb->p_cback)(req_type, &cb_data); 8955738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 8965738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project else 8975738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 898e8c3d75b75493911ebf0f99c83676359657178f7Sharvil Nanavati APPL_TRACE_ERROR("connection request on gatt_if[%d] is not interested", gatt_if); 8995738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 9005738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 9015738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project else 9025738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 903e8c3d75b75493911ebf0f99c83676359657178f7Sharvil Nanavati APPL_TRACE_ERROR("request received on unknown connectino ID: %d", conn_id); 9045738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 9055738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project} 9065738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 9075738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/******************************************************************************* 9085738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 9095738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function bta_gatts_conn_cback 9105738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 9115738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description connection callback. 9125738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 9135738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns none. 9145738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 9155738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/ 9165738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectstatic void bta_gatts_conn_cback (tGATT_IF gatt_if, BD_ADDR bda, UINT16 conn_id, 9177fa4fba6f59f97df00aff07dbe8fb21b114b3c2cGanesh Ganapathi Batta BOOLEAN connected, tGATT_DISCONN_REASON reason, 9187fa4fba6f59f97df00aff07dbe8fb21b114b3c2cGanesh Ganapathi Batta tGATT_TRANSPORT transport) 9195738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{ 9205738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project tBTA_GATTS cb_data; 9215738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project UINT8 evt = connected ? BTA_GATTS_CONNECT_EVT: BTA_GATTS_DISCONNECT_EVT; 9225738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project tBTA_GATTS_RCB *p_reg; 9235738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 924e8c3d75b75493911ebf0f99c83676359657178f7Sharvil Nanavati APPL_TRACE_DEBUG ("bta_gatts_conn_cback gatt_if=%d conn_id=%d connected=%d reason = 0x%04d", 9255738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project gatt_if, conn_id, connected, reason); 926e8c3d75b75493911ebf0f99c83676359657178f7Sharvil Nanavati APPL_TRACE_DEBUG("bta_gatts_conn_cback bda :%02x-%02x-%02x-%02x-%02x-%02x ", 9275738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project bda[0], bda[1], bda[2], bda[3], bda[4], bda[5]); 9285738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 9295738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project p_reg = bta_gatts_find_app_rcb_by_app_if(gatt_if); 9305738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 9315738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project if (p_reg && p_reg->p_cback) 9325738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 933781b5adee20e222ef87b56b72bfcd3f64013e4a0Andre Eisenbach /* there is no RM for GATT */ 9347fa4fba6f59f97df00aff07dbe8fb21b114b3c2cGanesh Ganapathi Batta if (transport == BTA_TRANSPORT_BR_EDR) 9356975b4d711142b885af479721cada448952c6b41Andre Eisenbach { 9366975b4d711142b885af479721cada448952c6b41Andre Eisenbach if (connected) 9376975b4d711142b885af479721cada448952c6b41Andre Eisenbach bta_sys_conn_open(BTA_ID_GATTS, BTA_ALL_APP_ID, bda); 9386975b4d711142b885af479721cada448952c6b41Andre Eisenbach else 9396975b4d711142b885af479721cada448952c6b41Andre Eisenbach bta_sys_conn_close( BTA_ID_GATTS ,BTA_ALL_APP_ID, bda); 9406975b4d711142b885af479721cada448952c6b41Andre Eisenbach } 941781b5adee20e222ef87b56b72bfcd3f64013e4a0Andre Eisenbach 9425738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project cb_data.conn.conn_id = conn_id; 9435738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project cb_data.conn.server_if = gatt_if; 9445738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project cb_data.conn.reason = reason; 9457fa4fba6f59f97df00aff07dbe8fb21b114b3c2cGanesh Ganapathi Batta cb_data.conn.transport = transport; 9465738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project memcpy(cb_data.conn.remote_bda, bda, BD_ADDR_LEN); 9475738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project (*p_reg->p_cback)(evt, &cb_data); 9485738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 9495738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project else 9505738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 951e8c3d75b75493911ebf0f99c83676359657178f7Sharvil Nanavati APPL_TRACE_ERROR("bta_gatts_conn_cback server_if=%d not found",gatt_if); 9525738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 9535738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project} 95417b04bd498405f2bb109a85562ebbdcb6bb06e95Andre Eisenbach 95517b04bd498405f2bb109a85562ebbdcb6bb06e95Andre Eisenbach/******************************************************************************* 95617b04bd498405f2bb109a85562ebbdcb6bb06e95Andre Eisenbach** 95717b04bd498405f2bb109a85562ebbdcb6bb06e95Andre Eisenbach** Function bta_gatts_cong_cback 95817b04bd498405f2bb109a85562ebbdcb6bb06e95Andre Eisenbach** 95917b04bd498405f2bb109a85562ebbdcb6bb06e95Andre Eisenbach** Description congestion callback. 96017b04bd498405f2bb109a85562ebbdcb6bb06e95Andre Eisenbach** 96117b04bd498405f2bb109a85562ebbdcb6bb06e95Andre Eisenbach** Returns none. 96217b04bd498405f2bb109a85562ebbdcb6bb06e95Andre Eisenbach** 96317b04bd498405f2bb109a85562ebbdcb6bb06e95Andre Eisenbach*******************************************************************************/ 96417b04bd498405f2bb109a85562ebbdcb6bb06e95Andre Eisenbachstatic void bta_gatts_cong_cback (UINT16 conn_id, BOOLEAN congested) 96517b04bd498405f2bb109a85562ebbdcb6bb06e95Andre Eisenbach{ 96617b04bd498405f2bb109a85562ebbdcb6bb06e95Andre Eisenbach tBTA_GATTS_RCB *p_rcb; 96717b04bd498405f2bb109a85562ebbdcb6bb06e95Andre Eisenbach tGATT_IF gatt_if; 96817b04bd498405f2bb109a85562ebbdcb6bb06e95Andre Eisenbach tBTA_GATT_TRANSPORT transport; 96917b04bd498405f2bb109a85562ebbdcb6bb06e95Andre Eisenbach tBTA_GATTS cb_data; 97017b04bd498405f2bb109a85562ebbdcb6bb06e95Andre Eisenbach 97117b04bd498405f2bb109a85562ebbdcb6bb06e95Andre Eisenbach if (GATT_GetConnectionInfor(conn_id, &gatt_if, cb_data.req_data.remote_bda, &transport)) 97217b04bd498405f2bb109a85562ebbdcb6bb06e95Andre Eisenbach { 97317b04bd498405f2bb109a85562ebbdcb6bb06e95Andre Eisenbach p_rcb = bta_gatts_find_app_rcb_by_app_if(gatt_if); 97417b04bd498405f2bb109a85562ebbdcb6bb06e95Andre Eisenbach 97517b04bd498405f2bb109a85562ebbdcb6bb06e95Andre Eisenbach if (p_rcb && p_rcb->p_cback) 97617b04bd498405f2bb109a85562ebbdcb6bb06e95Andre Eisenbach { 97717b04bd498405f2bb109a85562ebbdcb6bb06e95Andre Eisenbach cb_data.congest.conn_id = conn_id; 97817b04bd498405f2bb109a85562ebbdcb6bb06e95Andre Eisenbach cb_data.congest.congested = congested; 97917b04bd498405f2bb109a85562ebbdcb6bb06e95Andre Eisenbach 98017b04bd498405f2bb109a85562ebbdcb6bb06e95Andre Eisenbach (*p_rcb->p_cback)(BTA_GATTS_CONGEST_EVT, &cb_data); 98117b04bd498405f2bb109a85562ebbdcb6bb06e95Andre Eisenbach } 98217b04bd498405f2bb109a85562ebbdcb6bb06e95Andre Eisenbach } 98317b04bd498405f2bb109a85562ebbdcb6bb06e95Andre Eisenbach} 9845738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project#endif /* BTA_GATT_INCLUDED */ 985