1ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta/****************************************************************************** 2ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta * 3ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta * Copyright (C) 2009-2013 Broadcom Corporation 4ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta * 5ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta * Licensed under the Apache License, Version 2.0 (the "License"); 6ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta * you may not use this file except in compliance with the License. 7ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta * You may obtain a copy of the License at: 8ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta * 9ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta * http://www.apache.org/licenses/LICENSE-2.0 10ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta * 11ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta * Unless required by applicable law or agreed to in writing, software 12ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta * distributed under the License is distributed on an "AS IS" BASIS, 13ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta * See the License for the specific language governing permissions and 15ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta * limitations under the License. 16ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta * 17ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta ******************************************************************************/ 18ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 19ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 20ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta/************************************************************************************ 21ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta * 22ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta * Filename: btif_gatt_server.c 23ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta * 24ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta * Description: GATT server implementation 25ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta * 26ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta ***********************************************************************************/ 27ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 28ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta#include <hardware/bluetooth.h> 29ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta#include <hardware/bt_gatt.h> 30ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta#include <stdio.h> 31ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta#include <stdlib.h> 32ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta#include <errno.h> 33ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta#include <string.h> 34ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 35f8027005333c88a2f097cfd70d15c3d54c7764aeChris Manton#define LOG_TAG "bt_btif_gatt" 36ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 37ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta#include "btif_common.h" 38ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta#include "btif_util.h" 39ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 40ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta#if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE)) 41ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 42ca22ac493ab777199084d87b3c7627e7f27555afAndre Eisenbach#include "gki.h" 43ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta#include "bta_api.h" 44ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta#include "bta_gatt_api.h" 45ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta#include "btif_dm.h" 46ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta#include "btif_storage.h" 4786f97eda524568f2d264186844450db5e56dac36Matthew Xie#include "btif_config.h" 48ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 49ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta#include "btif_gatt.h" 50ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta#include "btif_gatt_util.h" 5144802768c447ab480d4227b3a852a97d923b816dSharvil Nanavati#include "osi/include/log.h" 52ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 53ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta/************************************************************************************ 54ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta** Constants & Macros 55ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta************************************************************************************/ 56ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 57ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta#define CHECK_BTGATT_INIT() if (bt_gatt_callbacks == NULL)\ 58ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta {\ 5944802768c447ab480d4227b3a852a97d923b816dSharvil Nanavati LOG_WARN("%s: BTGATT not initialized", __FUNCTION__);\ 60ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta return BT_STATUS_NOT_READY;\ 61ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta } else {\ 628a7e179c9ebe76c0c16a71c33bf322b77e0aa439Andre Eisenbach LOG_VERBOSE("%s", __FUNCTION__);\ 63ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta } 64ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 65ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 66ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Battatypedef enum { 67ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta BTIF_GATTS_REGISTER_APP = 2000, 68ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta BTIF_GATTS_UNREGISTER_APP, 69ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta BTIF_GATTS_OPEN, 70ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta BTIF_GATTS_CLOSE, 71ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta BTIF_GATTS_CREATE_SERVICE, 72ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta BTIF_GATTS_ADD_INCLUDED_SERVICE, 73ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta BTIF_GATTS_ADD_CHARACTERISTIC, 74ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta BTIF_GATTS_ADD_DESCRIPTOR, 75ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta BTIF_GATTS_START_SERVICE, 76ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta BTIF_GATTS_STOP_SERVICE, 77ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta BTIF_GATTS_DELETE_SERVICE, 78ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta BTIF_GATTS_SEND_INDICATION, 79ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta BTIF_GATTS_SEND_RESPONSE 80ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta} btif_gatts_event_t; 81ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 82ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta/************************************************************************************ 83ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta** Local type definitions 84ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta************************************************************************************/ 85ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 86ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Battatypedef struct 87ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta{ 88ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta uint8_t value[BTGATT_MAX_ATTR_LEN]; 89ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta btgatt_response_t response; 90ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta btgatt_srvc_id_t srvc_id; 91ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta bt_bdaddr_t bd_addr; 92ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta bt_uuid_t uuid; 93ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta uint32_t trans_id; 94ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta uint16_t conn_id; 95ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta uint16_t srvc_handle; 96ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta uint16_t incl_handle; 97ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta uint16_t attr_handle; 98ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta uint16_t permissions; 99ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta uint16_t len; 100ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta uint8_t server_if; 101ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta uint8_t is_direct; 102ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta uint8_t num_handles; 103ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta uint8_t properties; 104ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta uint8_t confirm; 105ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta uint8_t status; 1067fa4fba6f59f97df00aff07dbe8fb21b114b3c2cGanesh Ganapathi Batta btgatt_transport_t transport; 1077fa4fba6f59f97df00aff07dbe8fb21b114b3c2cGanesh Ganapathi Batta 108ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta} __attribute__((packed)) btif_gatts_cb_t; 109ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 110ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 111ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta/************************************************************************************ 112ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta** Static variables 113ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta************************************************************************************/ 114ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 115ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Battaextern const btgatt_callbacks_t *bt_gatt_callbacks; 116ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 117ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 118ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta/************************************************************************************ 119ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta** Static functions 120ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta************************************************************************************/ 121ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 122ca22ac493ab777199084d87b3c7627e7f27555afAndre Eisenbachstatic void btapp_gatts_copy_req_data(UINT16 event, char *p_dest, char *p_src) 123ca22ac493ab777199084d87b3c7627e7f27555afAndre Eisenbach{ 124ca22ac493ab777199084d87b3c7627e7f27555afAndre Eisenbach tBTA_GATTS *p_dest_data = (tBTA_GATTS*) p_dest; 125ca22ac493ab777199084d87b3c7627e7f27555afAndre Eisenbach tBTA_GATTS *p_src_data = (tBTA_GATTS*) p_src; 126ca22ac493ab777199084d87b3c7627e7f27555afAndre Eisenbach 127ca22ac493ab777199084d87b3c7627e7f27555afAndre Eisenbach if (!p_src_data || !p_dest_data) 128ca22ac493ab777199084d87b3c7627e7f27555afAndre Eisenbach return; 129ca22ac493ab777199084d87b3c7627e7f27555afAndre Eisenbach 130ca22ac493ab777199084d87b3c7627e7f27555afAndre Eisenbach // Copy basic structure first 131ca22ac493ab777199084d87b3c7627e7f27555afAndre Eisenbach memcpy(p_dest_data, p_src_data, sizeof(tBTA_GATTS)); 132ca22ac493ab777199084d87b3c7627e7f27555afAndre Eisenbach 133ca22ac493ab777199084d87b3c7627e7f27555afAndre Eisenbach // Allocate buffer for request data if necessary 134ca22ac493ab777199084d87b3c7627e7f27555afAndre Eisenbach switch (event) 135ca22ac493ab777199084d87b3c7627e7f27555afAndre Eisenbach { 136ca22ac493ab777199084d87b3c7627e7f27555afAndre Eisenbach case BTA_GATTS_READ_EVT: 137ca22ac493ab777199084d87b3c7627e7f27555afAndre Eisenbach case BTA_GATTS_WRITE_EVT: 138ca22ac493ab777199084d87b3c7627e7f27555afAndre Eisenbach case BTA_GATTS_EXEC_WRITE_EVT: 139ca22ac493ab777199084d87b3c7627e7f27555afAndre Eisenbach case BTA_GATTS_MTU_EVT: 140ca22ac493ab777199084d87b3c7627e7f27555afAndre Eisenbach p_dest_data->req_data.p_data = GKI_getbuf(sizeof(tBTA_GATTS_REQ_DATA)); 141ca22ac493ab777199084d87b3c7627e7f27555afAndre Eisenbach if (p_dest_data->req_data.p_data != NULL) 142ca22ac493ab777199084d87b3c7627e7f27555afAndre Eisenbach { 143ca22ac493ab777199084d87b3c7627e7f27555afAndre Eisenbach memcpy(p_dest_data->req_data.p_data, p_src_data->req_data.p_data, 144ca22ac493ab777199084d87b3c7627e7f27555afAndre Eisenbach sizeof(tBTA_GATTS_REQ_DATA)); 145ca22ac493ab777199084d87b3c7627e7f27555afAndre Eisenbach } 146ca22ac493ab777199084d87b3c7627e7f27555afAndre Eisenbach break; 147ca22ac493ab777199084d87b3c7627e7f27555afAndre Eisenbach 148ca22ac493ab777199084d87b3c7627e7f27555afAndre Eisenbach default: 149ca22ac493ab777199084d87b3c7627e7f27555afAndre Eisenbach break; 150ca22ac493ab777199084d87b3c7627e7f27555afAndre Eisenbach } 151ca22ac493ab777199084d87b3c7627e7f27555afAndre Eisenbach} 152ca22ac493ab777199084d87b3c7627e7f27555afAndre Eisenbach 153ca22ac493ab777199084d87b3c7627e7f27555afAndre Eisenbachstatic void btapp_gatts_free_req_data(UINT16 event, tBTA_GATTS *p_data) 154ca22ac493ab777199084d87b3c7627e7f27555afAndre Eisenbach{ 155ca22ac493ab777199084d87b3c7627e7f27555afAndre Eisenbach switch (event) 156ca22ac493ab777199084d87b3c7627e7f27555afAndre Eisenbach { 157ca22ac493ab777199084d87b3c7627e7f27555afAndre Eisenbach case BTA_GATTS_READ_EVT: 158ca22ac493ab777199084d87b3c7627e7f27555afAndre Eisenbach case BTA_GATTS_WRITE_EVT: 159ca22ac493ab777199084d87b3c7627e7f27555afAndre Eisenbach case BTA_GATTS_EXEC_WRITE_EVT: 160ca22ac493ab777199084d87b3c7627e7f27555afAndre Eisenbach case BTA_GATTS_MTU_EVT: 161ca22ac493ab777199084d87b3c7627e7f27555afAndre Eisenbach if (p_data && p_data->req_data.p_data) 162ca22ac493ab777199084d87b3c7627e7f27555afAndre Eisenbach GKI_freebuf(p_data->req_data.p_data); 163ca22ac493ab777199084d87b3c7627e7f27555afAndre Eisenbach break; 164ca22ac493ab777199084d87b3c7627e7f27555afAndre Eisenbach 165ca22ac493ab777199084d87b3c7627e7f27555afAndre Eisenbach default: 166ca22ac493ab777199084d87b3c7627e7f27555afAndre Eisenbach break; 167ca22ac493ab777199084d87b3c7627e7f27555afAndre Eisenbach } 168ca22ac493ab777199084d87b3c7627e7f27555afAndre Eisenbach} 169ca22ac493ab777199084d87b3c7627e7f27555afAndre Eisenbach 170ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Battastatic void btapp_gatts_handle_cback(uint16_t event, char* p_param) 171ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta{ 1728a7e179c9ebe76c0c16a71c33bf322b77e0aa439Andre Eisenbach LOG_VERBOSE("%s: Event %d", __FUNCTION__, event); 173ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 174ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta tBTA_GATTS *p_data = (tBTA_GATTS*)p_param; 175ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta switch (event) 176ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta { 177ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta case BTA_GATTS_REG_EVT: 178ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta { 179ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta bt_uuid_t app_uuid; 180ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta bta_to_btif_uuid(&app_uuid, &p_data->reg_oper.uuid); 181ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta HAL_CBACK(bt_gatt_callbacks, server->register_server_cb 182ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta , p_data->reg_oper.status 183ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta , p_data->reg_oper.server_if 184ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta , &app_uuid 185ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta ); 186ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta break; 187ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta } 188ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 189ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta case BTA_GATTS_DEREG_EVT: 190ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta break; 191ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 192ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta case BTA_GATTS_CONNECT_EVT: 193ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta { 194ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta bt_bdaddr_t bda; 195ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta bdcpy(bda.address, p_data->conn.remote_bda); 196ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 1974f6c9b4f68d152baf7aa029cbe9b570994584101Nitin Arora btif_gatt_check_encrypted_link(p_data->conn.remote_bda, p_data->conn.transport); 198ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 199ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta HAL_CBACK(bt_gatt_callbacks, server->connection_cb, 200977b854e5121c0ea19ecab6eb2bdb3583f439568Andre Eisenbach p_data->conn.conn_id, p_data->conn.server_if, TRUE, &bda); 201ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta break; 202ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta } 203ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 204ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta case BTA_GATTS_DISCONNECT_EVT: 205ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta { 206ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta bt_bdaddr_t bda; 207ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta bdcpy(bda.address, p_data->conn.remote_bda); 208ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 209ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta HAL_CBACK(bt_gatt_callbacks, server->connection_cb, 210977b854e5121c0ea19ecab6eb2bdb3583f439568Andre Eisenbach p_data->conn.conn_id, p_data->conn.server_if, FALSE, &bda); 211ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta break; 212ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta } 213ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 214ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta case BTA_GATTS_CREATE_EVT: 215ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta { 216ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta btgatt_srvc_id_t srvc_id; 217ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta srvc_id.is_primary = p_data->create.is_primary; 218ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta srvc_id.id.inst_id = p_data->create.svc_instance; 219ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta bta_to_btif_uuid(&srvc_id.id.uuid, &p_data->create.uuid); 220ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 221ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta HAL_CBACK(bt_gatt_callbacks, server->service_added_cb, 222ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta p_data->create.status, p_data->create.server_if, &srvc_id, 223ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta p_data->create.service_id 224ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta ); 225ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta } 226ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta break; 227ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 228ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta case BTA_GATTS_ADD_INCL_SRVC_EVT: 229ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta HAL_CBACK(bt_gatt_callbacks, server->included_service_added_cb, 230ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta p_data->add_result.status, 231ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta p_data->add_result.server_if, 232ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta p_data->add_result.service_id, 233ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta p_data->add_result.attr_id); 234ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta break; 235ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 236ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta case BTA_GATTS_ADD_CHAR_EVT: 237ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta { 238ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta bt_uuid_t uuid; 239ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta bta_to_btif_uuid(&uuid, &p_data->add_result.char_uuid); 240ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 241ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta HAL_CBACK(bt_gatt_callbacks, server->characteristic_added_cb, 242ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta p_data->add_result.status, 243ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta p_data->add_result.server_if, 244ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta &uuid, 245ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta p_data->add_result.service_id, 246ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta p_data->add_result.attr_id); 247ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta break; 248ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta } 249ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 250ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta case BTA_GATTS_ADD_CHAR_DESCR_EVT: 251ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta { 252ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta bt_uuid_t uuid; 253ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta bta_to_btif_uuid(&uuid, &p_data->add_result.char_uuid); 254ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 255ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta HAL_CBACK(bt_gatt_callbacks, server->descriptor_added_cb, 256ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta p_data->add_result.status, 257ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta p_data->add_result.server_if, 258ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta &uuid, 259ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta p_data->add_result.service_id, 260ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta p_data->add_result.attr_id); 261ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta break; 262ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta } 263ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 264ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta case BTA_GATTS_START_EVT: 265ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta HAL_CBACK(bt_gatt_callbacks, server->service_started_cb, 266ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta p_data->srvc_oper.status, 267ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta p_data->srvc_oper.server_if, 268ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta p_data->srvc_oper.service_id); 269ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta break; 270ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 271ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta case BTA_GATTS_STOP_EVT: 272ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta HAL_CBACK(bt_gatt_callbacks, server->service_stopped_cb, 273ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta p_data->srvc_oper.status, 274ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta p_data->srvc_oper.server_if, 275ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta p_data->srvc_oper.service_id); 276ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta break; 277ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 278ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta case BTA_GATTS_DELELTE_EVT: 279ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta HAL_CBACK(bt_gatt_callbacks, server->service_deleted_cb, 280ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta p_data->srvc_oper.status, 281ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta p_data->srvc_oper.server_if, 282ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta p_data->srvc_oper.service_id); 283ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta break; 284ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 285ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta case BTA_GATTS_READ_EVT: 286ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta { 287ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta bt_bdaddr_t bda; 288ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta bdcpy(bda.address, p_data->req_data.remote_bda); 289ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 290ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta HAL_CBACK(bt_gatt_callbacks, server->request_read_cb, 291ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta p_data->req_data.conn_id,p_data->req_data.trans_id, &bda, 292ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta p_data->req_data.p_data->read_req.handle, 293ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta p_data->req_data.p_data->read_req.offset, 294ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta p_data->req_data.p_data->read_req.is_long); 295ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta break; 296ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta } 297ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 298ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta case BTA_GATTS_WRITE_EVT: 299ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta { 300ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta bt_bdaddr_t bda; 301ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta bdcpy(bda.address, p_data->req_data.remote_bda); 302ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 303ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta HAL_CBACK(bt_gatt_callbacks, server->request_write_cb, 304ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta p_data->req_data.conn_id,p_data->req_data.trans_id, &bda, 305ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta p_data->req_data.p_data->write_req.handle, 306ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta p_data->req_data.p_data->write_req.offset, 307ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta p_data->req_data.p_data->write_req.len, 308ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta p_data->req_data.p_data->write_req.need_rsp, 309ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta p_data->req_data.p_data->write_req.is_prep, 310ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta p_data->req_data.p_data->write_req.value); 311ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta break; 312ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta } 313ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 314ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta case BTA_GATTS_EXEC_WRITE_EVT: 315ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta { 316ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta bt_bdaddr_t bda; 317ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta bdcpy(bda.address, p_data->req_data.remote_bda); 318ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 319ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta HAL_CBACK(bt_gatt_callbacks, server->request_exec_write_cb, 320ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta p_data->req_data.conn_id,p_data->req_data.trans_id, &bda, 321ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta p_data->req_data.p_data->exec_write); 322ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta break; 323ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta } 324ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 32517b04bd498405f2bb109a85562ebbdcb6bb06e95Andre Eisenbach case BTA_GATTS_CONF_EVT: 32617b04bd498405f2bb109a85562ebbdcb6bb06e95Andre Eisenbach HAL_CBACK(bt_gatt_callbacks, server->indication_sent_cb, 32717b04bd498405f2bb109a85562ebbdcb6bb06e95Andre Eisenbach p_data->req_data.conn_id, p_data->req_data.status); 32817b04bd498405f2bb109a85562ebbdcb6bb06e95Andre Eisenbach break; 32917b04bd498405f2bb109a85562ebbdcb6bb06e95Andre Eisenbach 33017b04bd498405f2bb109a85562ebbdcb6bb06e95Andre Eisenbach case BTA_GATTS_CONGEST_EVT: 33117b04bd498405f2bb109a85562ebbdcb6bb06e95Andre Eisenbach HAL_CBACK(bt_gatt_callbacks, server->congestion_cb 33217b04bd498405f2bb109a85562ebbdcb6bb06e95Andre Eisenbach , p_data->congest.conn_id 33317b04bd498405f2bb109a85562ebbdcb6bb06e95Andre Eisenbach , p_data->congest.congested 33417b04bd498405f2bb109a85562ebbdcb6bb06e95Andre Eisenbach ); 33517b04bd498405f2bb109a85562ebbdcb6bb06e95Andre Eisenbach break; 33617b04bd498405f2bb109a85562ebbdcb6bb06e95Andre Eisenbach 337ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta case BTA_GATTS_MTU_EVT: 338e79be3d6ca41ed6349012c73a3374aca3714a053Andre Eisenbach HAL_CBACK(bt_gatt_callbacks, server->mtu_changed_cb 339e79be3d6ca41ed6349012c73a3374aca3714a053Andre Eisenbach , p_data->req_data.conn_id 340e79be3d6ca41ed6349012c73a3374aca3714a053Andre Eisenbach , p_data->req_data.p_data->mtu 341e79be3d6ca41ed6349012c73a3374aca3714a053Andre Eisenbach ); 342e79be3d6ca41ed6349012c73a3374aca3714a053Andre Eisenbach break; 343e79be3d6ca41ed6349012c73a3374aca3714a053Andre Eisenbach 344ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta case BTA_GATTS_OPEN_EVT: 345ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta case BTA_GATTS_CANCEL_OPEN_EVT: 346ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta case BTA_GATTS_CLOSE_EVT: 34744802768c447ab480d4227b3a852a97d923b816dSharvil Nanavati LOG_DEBUG("%s: Empty event (%d)!", __FUNCTION__, event); 348ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta break; 349ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 350ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta default: 35144802768c447ab480d4227b3a852a97d923b816dSharvil Nanavati LOG_ERROR("%s: Unhandled event (%d)!", __FUNCTION__, event); 352ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta break; 353ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta } 354ca22ac493ab777199084d87b3c7627e7f27555afAndre Eisenbach 355ca22ac493ab777199084d87b3c7627e7f27555afAndre Eisenbach btapp_gatts_free_req_data(event, p_data); 356ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta} 357ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 358ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Battastatic void btapp_gatts_cback(tBTA_GATTS_EVT event, tBTA_GATTS *p_data) 359ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta{ 360ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta bt_status_t status; 361ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta status = btif_transfer_context(btapp_gatts_handle_cback, (uint16_t) event, 362ca22ac493ab777199084d87b3c7627e7f27555afAndre Eisenbach (void*)p_data, sizeof(tBTA_GATTS), btapp_gatts_copy_req_data); 363ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta ASSERTC(status == BT_STATUS_SUCCESS, "Context transfer failed!", status); 364ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta} 365ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 366ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Battastatic void btgatts_handle_event(uint16_t event, char* p_param) 367ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta{ 368ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta btif_gatts_cb_t* p_cb = (btif_gatts_cb_t*)p_param; 369ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta if (!p_cb) return; 370ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 3718a7e179c9ebe76c0c16a71c33bf322b77e0aa439Andre Eisenbach LOG_VERBOSE("%s: Event %d", __FUNCTION__, event); 372ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 373ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta switch (event) 374ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta { 375ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta case BTIF_GATTS_REGISTER_APP: 376ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta { 377ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta tBT_UUID uuid; 378ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta btif_to_bta_uuid(&uuid, &p_cb->uuid); 379ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta BTA_GATTS_AppRegister(&uuid, btapp_gatts_cback); 380ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta break; 381ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta } 382ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 383ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta case BTIF_GATTS_UNREGISTER_APP: 384ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta BTA_GATTS_AppDeregister(p_cb->server_if); 385ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta break; 386ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 387ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta case BTIF_GATTS_OPEN: 388306bddadeec993013cfed6bf0e41a1a47a69367cAndre Eisenbach { 389306bddadeec993013cfed6bf0e41a1a47a69367cAndre Eisenbach // Ensure device is in inquiry database 390306bddadeec993013cfed6bf0e41a1a47a69367cAndre Eisenbach int addr_type = 0; 391306bddadeec993013cfed6bf0e41a1a47a69367cAndre Eisenbach int device_type = 0; 3927fa4fba6f59f97df00aff07dbe8fb21b114b3c2cGanesh Ganapathi Batta tBTA_GATT_TRANSPORT transport = BTA_GATT_TRANSPORT_LE; 393306bddadeec993013cfed6bf0e41a1a47a69367cAndre Eisenbach 39486f97eda524568f2d264186844450db5e56dac36Matthew Xie if (btif_get_address_type(p_cb->bd_addr.address, &addr_type) && 39586f97eda524568f2d264186844450db5e56dac36Matthew Xie btif_get_device_type(p_cb->bd_addr.address, &device_type) && 39686f97eda524568f2d264186844450db5e56dac36Matthew Xie device_type != BT_DEVICE_TYPE_BREDR) 39786f97eda524568f2d264186844450db5e56dac36Matthew Xie { 398306bddadeec993013cfed6bf0e41a1a47a69367cAndre Eisenbach BTA_DmAddBleDevice(p_cb->bd_addr.address, addr_type, device_type); 39986f97eda524568f2d264186844450db5e56dac36Matthew Xie } 400306bddadeec993013cfed6bf0e41a1a47a69367cAndre Eisenbach 401306bddadeec993013cfed6bf0e41a1a47a69367cAndre Eisenbach // Mark background connections 402ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta if (!p_cb->is_direct) 403ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta BTA_DmBleSetBgConnType(BTM_BLE_CONN_AUTO, NULL); 404306bddadeec993013cfed6bf0e41a1a47a69367cAndre Eisenbach 4057fa4fba6f59f97df00aff07dbe8fb21b114b3c2cGanesh Ganapathi Batta switch(device_type) 4067fa4fba6f59f97df00aff07dbe8fb21b114b3c2cGanesh Ganapathi Batta { 4077fa4fba6f59f97df00aff07dbe8fb21b114b3c2cGanesh Ganapathi Batta case BT_DEVICE_TYPE_BREDR: 4087fa4fba6f59f97df00aff07dbe8fb21b114b3c2cGanesh Ganapathi Batta transport = BTA_GATT_TRANSPORT_BR_EDR; 4097fa4fba6f59f97df00aff07dbe8fb21b114b3c2cGanesh Ganapathi Batta break; 4107fa4fba6f59f97df00aff07dbe8fb21b114b3c2cGanesh Ganapathi Batta 4117fa4fba6f59f97df00aff07dbe8fb21b114b3c2cGanesh Ganapathi Batta case BT_DEVICE_TYPE_BLE: 4127fa4fba6f59f97df00aff07dbe8fb21b114b3c2cGanesh Ganapathi Batta transport = BTA_GATT_TRANSPORT_LE; 4137fa4fba6f59f97df00aff07dbe8fb21b114b3c2cGanesh Ganapathi Batta break; 4147fa4fba6f59f97df00aff07dbe8fb21b114b3c2cGanesh Ganapathi Batta 4157fa4fba6f59f97df00aff07dbe8fb21b114b3c2cGanesh Ganapathi Batta case BT_DEVICE_TYPE_DUMO: 4167cb76b4277d603e5abfe7f9222a45ebdf7a715e2Satya Calloji if (p_cb->transport == GATT_TRANSPORT_LE) 4177fa4fba6f59f97df00aff07dbe8fb21b114b3c2cGanesh Ganapathi Batta transport = BTA_GATT_TRANSPORT_LE; 4187fa4fba6f59f97df00aff07dbe8fb21b114b3c2cGanesh Ganapathi Batta else 4197fa4fba6f59f97df00aff07dbe8fb21b114b3c2cGanesh Ganapathi Batta transport = BTA_GATT_TRANSPORT_BR_EDR; 4207fa4fba6f59f97df00aff07dbe8fb21b114b3c2cGanesh Ganapathi Batta break; 4217fa4fba6f59f97df00aff07dbe8fb21b114b3c2cGanesh Ganapathi Batta 4227fa4fba6f59f97df00aff07dbe8fb21b114b3c2cGanesh Ganapathi Batta default: 423e8c3d75b75493911ebf0f99c83676359657178f7Sharvil Nanavati BTIF_TRACE_ERROR (" GATT Open :Invalid device type %d",device_type); 4247fa4fba6f59f97df00aff07dbe8fb21b114b3c2cGanesh Ganapathi Batta return; 4257fa4fba6f59f97df00aff07dbe8fb21b114b3c2cGanesh Ganapathi Batta } 4267fa4fba6f59f97df00aff07dbe8fb21b114b3c2cGanesh Ganapathi Batta 427306bddadeec993013cfed6bf0e41a1a47a69367cAndre Eisenbach // Connect! 428ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta BTA_GATTS_Open(p_cb->server_if, p_cb->bd_addr.address, 4297fa4fba6f59f97df00aff07dbe8fb21b114b3c2cGanesh Ganapathi Batta p_cb->is_direct, transport); 430ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta break; 431306bddadeec993013cfed6bf0e41a1a47a69367cAndre Eisenbach } 432ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 433ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta case BTIF_GATTS_CLOSE: 434ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta // Cancel pending foreground/background connections 435ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta BTA_GATTS_CancelOpen(p_cb->server_if, p_cb->bd_addr.address, TRUE); 436ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta BTA_GATTS_CancelOpen(p_cb->server_if, p_cb->bd_addr.address, FALSE); 437ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 438ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta // Close active connection 439ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta if (p_cb->conn_id != 0) 440ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta BTA_GATTS_Close(p_cb->conn_id); 441ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta break; 442ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 443ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta case BTIF_GATTS_CREATE_SERVICE: 444ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta { 445ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta tBTA_GATT_SRVC_ID srvc_id; 446ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta btif_to_bta_srvc_id(&srvc_id, &p_cb->srvc_id); 447ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta BTA_GATTS_CreateService(p_cb->server_if, &srvc_id.id.uuid, 448ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta srvc_id.id.inst_id, p_cb->num_handles, 449ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta srvc_id.is_primary); 450ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta break; 451ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta } 452ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 453ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta case BTIF_GATTS_ADD_INCLUDED_SERVICE: 454ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta BTA_GATTS_AddIncludeService(p_cb->srvc_handle, p_cb->incl_handle); 455ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta break; 456ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 457ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta case BTIF_GATTS_ADD_CHARACTERISTIC: 458ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta { 459ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta tBT_UUID uuid; 460ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta btif_to_bta_uuid(&uuid, &p_cb->uuid); 461ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 462ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta BTA_GATTS_AddCharacteristic(p_cb->srvc_handle, &uuid, 463ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta p_cb->permissions, p_cb->properties); 464ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta break; 465ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta } 466ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 467ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta case BTIF_GATTS_ADD_DESCRIPTOR: 468ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta { 469ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta tBT_UUID uuid; 470ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta btif_to_bta_uuid(&uuid, &p_cb->uuid); 471ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 472ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta BTA_GATTS_AddCharDescriptor(p_cb->srvc_handle, p_cb->permissions, 473ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta &uuid); 474ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta break; 475ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta } 476ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 477ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta case BTIF_GATTS_START_SERVICE: 478ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta BTA_GATTS_StartService(p_cb->srvc_handle, p_cb->transport); 479ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta break; 480ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 481ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta case BTIF_GATTS_STOP_SERVICE: 482ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta BTA_GATTS_StopService(p_cb->srvc_handle); 483ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta break; 484ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 485ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta case BTIF_GATTS_DELETE_SERVICE: 486ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta BTA_GATTS_DeleteService(p_cb->srvc_handle); 487ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta break; 488ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 489ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta case BTIF_GATTS_SEND_INDICATION: 490ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta BTA_GATTS_HandleValueIndication(p_cb->conn_id, p_cb->attr_handle, 491ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta p_cb->len, p_cb->value, p_cb->confirm); 492ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta // TODO: Might need to send an ACK if handle value indication is 493ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta // invoked without need for confirmation. 494ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta break; 495ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 496ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta case BTIF_GATTS_SEND_RESPONSE: 497ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta { 498ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta tBTA_GATTS_RSP rsp_struct; 499ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta btgatt_response_t *p_rsp = &p_cb->response; 500ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta btif_to_bta_response(&rsp_struct, p_rsp); 501ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 502ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta BTA_GATTS_SendRsp(p_cb->conn_id, p_cb->trans_id, 503ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta p_cb->status, &rsp_struct); 504ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 505ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta HAL_CBACK(bt_gatt_callbacks, server->response_confirmation_cb, 506ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 0, rsp_struct.attr_value.handle); 507ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta break; 508ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta } 509ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 510ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta default: 51144802768c447ab480d4227b3a852a97d923b816dSharvil Nanavati LOG_ERROR("%s: Unknown event (%d)!", __FUNCTION__, event); 512ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta break; 513ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta } 514ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta} 515ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 516ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta/************************************************************************************ 517ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta** Server API Functions 518ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta************************************************************************************/ 519ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 520ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Battastatic bt_status_t btif_gatts_register_app(bt_uuid_t *uuid) 521ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta{ 522ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta CHECK_BTGATT_INIT(); 523ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta btif_gatts_cb_t btif_cb; 524ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta memcpy(&btif_cb.uuid, uuid, sizeof(bt_uuid_t)); 525ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta return btif_transfer_context(btgatts_handle_event, BTIF_GATTS_REGISTER_APP, 526ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta (char*) &btif_cb, sizeof(btif_gatts_cb_t), NULL); 527ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta} 528ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 529ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Battastatic bt_status_t btif_gatts_unregister_app( int server_if ) 530ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta{ 531ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta CHECK_BTGATT_INIT(); 532ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta btif_gatts_cb_t btif_cb; 533ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta btif_cb.server_if = (uint8_t) server_if; 534ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta return btif_transfer_context(btgatts_handle_event, BTIF_GATTS_UNREGISTER_APP, 535ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta (char*) &btif_cb, sizeof(btif_gatts_cb_t), NULL); 536ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta} 537ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 5387fa4fba6f59f97df00aff07dbe8fb21b114b3c2cGanesh Ganapathi Battastatic bt_status_t btif_gatts_open( int server_if, const bt_bdaddr_t *bd_addr, 5397fa4fba6f59f97df00aff07dbe8fb21b114b3c2cGanesh Ganapathi Batta bool is_direct, int transport ) 540ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta{ 541ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta CHECK_BTGATT_INIT(); 542ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta btif_gatts_cb_t btif_cb; 543ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta btif_cb.server_if = (uint8_t) server_if; 544ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta btif_cb.is_direct = is_direct ? 1 : 0; 5457fa4fba6f59f97df00aff07dbe8fb21b114b3c2cGanesh Ganapathi Batta btif_cb.transport = (btgatt_transport_t)transport; 546ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta bdcpy(btif_cb.bd_addr.address, bd_addr->address); 547ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta return btif_transfer_context(btgatts_handle_event, BTIF_GATTS_OPEN, 548ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta (char*) &btif_cb, sizeof(btif_gatts_cb_t), NULL); 549ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta} 550ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 551ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Battastatic bt_status_t btif_gatts_close(int server_if, const bt_bdaddr_t *bd_addr, int conn_id) 552ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta{ 553ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta CHECK_BTGATT_INIT(); 554ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta btif_gatts_cb_t btif_cb; 555ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta btif_cb.server_if = (uint8_t) server_if; 556ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta btif_cb.conn_id = (uint16_t) conn_id; 557ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta bdcpy(btif_cb.bd_addr.address, bd_addr->address); 558ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta return btif_transfer_context(btgatts_handle_event, BTIF_GATTS_CLOSE, 559ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta (char*) &btif_cb, sizeof(btif_gatts_cb_t), NULL); 560ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta} 561ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 562ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Battastatic bt_status_t btif_gatts_add_service(int server_if, btgatt_srvc_id_t *srvc_id, 563ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta int num_handles) 564ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta{ 565ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta CHECK_BTGATT_INIT(); 566ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta btif_gatts_cb_t btif_cb; 567ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta btif_cb.server_if = (uint8_t) server_if; 568ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta btif_cb.num_handles = (uint8_t) num_handles; 569ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta memcpy(&btif_cb.srvc_id, srvc_id, sizeof(btgatt_srvc_id_t)); 570ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta return btif_transfer_context(btgatts_handle_event, BTIF_GATTS_CREATE_SERVICE, 571ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta (char*) &btif_cb, sizeof(btif_gatts_cb_t), NULL); 572ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta} 573ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 574ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Battastatic bt_status_t btif_gatts_add_included_service(int server_if, int service_handle, 575ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta int included_handle) 576ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta{ 577ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta CHECK_BTGATT_INIT(); 578ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta btif_gatts_cb_t btif_cb; 579ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta btif_cb.server_if = (uint8_t) server_if; 580ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta btif_cb.srvc_handle = (uint16_t) service_handle; 581ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta btif_cb.incl_handle = (uint16_t) included_handle; 582ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta return btif_transfer_context(btgatts_handle_event, BTIF_GATTS_ADD_INCLUDED_SERVICE, 583ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta (char*) &btif_cb, sizeof(btif_gatts_cb_t), NULL); 584ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta} 585ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 586ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Battastatic bt_status_t btif_gatts_add_characteristic(int server_if, int service_handle, 587ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta bt_uuid_t *uuid, int properties, 588ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta int permissions) 589ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta{ 590ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta CHECK_BTGATT_INIT(); 591ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta btif_gatts_cb_t btif_cb; 592ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta btif_cb.server_if = (uint8_t) server_if; 593ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta btif_cb.srvc_handle = (uint16_t) service_handle; 594ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta btif_cb.properties = (uint8_t) properties; 595ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta btif_cb.permissions = (uint16_t) permissions; 596ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta memcpy(&btif_cb.uuid, uuid, sizeof(bt_uuid_t)); 597ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta return btif_transfer_context(btgatts_handle_event, BTIF_GATTS_ADD_CHARACTERISTIC, 598ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta (char*) &btif_cb, sizeof(btif_gatts_cb_t), NULL); 599ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta} 600ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 601ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Battastatic bt_status_t btif_gatts_add_descriptor(int server_if, int service_handle, bt_uuid_t *uuid, 602ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta int permissions) 603ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta{ 604ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta CHECK_BTGATT_INIT(); 605ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta btif_gatts_cb_t btif_cb; 606ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta btif_cb.server_if = (uint8_t) server_if; 607ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta btif_cb.srvc_handle = (uint16_t) service_handle; 608ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta btif_cb.permissions = (uint16_t) permissions; 609ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta memcpy(&btif_cb.uuid, uuid, sizeof(bt_uuid_t)); 610ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta return btif_transfer_context(btgatts_handle_event, BTIF_GATTS_ADD_DESCRIPTOR, 611ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta (char*) &btif_cb, sizeof(btif_gatts_cb_t), NULL); 612ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta} 613ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 614ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Battastatic bt_status_t btif_gatts_start_service(int server_if, int service_handle, int transport) 615ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta{ 616ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta CHECK_BTGATT_INIT(); 617ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta btif_gatts_cb_t btif_cb; 618ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta btif_cb.server_if = (uint8_t) server_if; 619ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta btif_cb.srvc_handle = (uint16_t) service_handle; 620ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta btif_cb.transport = (uint8_t) transport; 621ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta return btif_transfer_context(btgatts_handle_event, BTIF_GATTS_START_SERVICE, 622ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta (char*) &btif_cb, sizeof(btif_gatts_cb_t), NULL); 623ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta} 624ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 625ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Battastatic bt_status_t btif_gatts_stop_service(int server_if, int service_handle) 626ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta{ 627ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta CHECK_BTGATT_INIT(); 628ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta btif_gatts_cb_t btif_cb; 629ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta btif_cb.server_if = (uint8_t) server_if; 630ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta btif_cb.srvc_handle = (uint16_t) service_handle; 631ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta return btif_transfer_context(btgatts_handle_event, BTIF_GATTS_STOP_SERVICE, 632ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta (char*) &btif_cb, sizeof(btif_gatts_cb_t), NULL); 633ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta} 634ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 635ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Battastatic bt_status_t btif_gatts_delete_service(int server_if, int service_handle) 636ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta{ 637ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta CHECK_BTGATT_INIT(); 638ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta btif_gatts_cb_t btif_cb; 639ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta btif_cb.server_if = (uint8_t) server_if; 640ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta btif_cb.srvc_handle = (uint16_t) service_handle; 641ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta return btif_transfer_context(btgatts_handle_event, BTIF_GATTS_DELETE_SERVICE, 642ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta (char*) &btif_cb, sizeof(btif_gatts_cb_t), NULL); 643ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta} 644ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 645ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Battastatic bt_status_t btif_gatts_send_indication(int server_if, int attribute_handle, int conn_id, 646ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta int len, int confirm, char* p_value) 647ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta{ 648ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta CHECK_BTGATT_INIT(); 649ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta btif_gatts_cb_t btif_cb; 650ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta btif_cb.server_if = (uint8_t) server_if; 651ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta btif_cb.conn_id = (uint16_t) conn_id; 652ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta btif_cb.attr_handle = attribute_handle; 653ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta btif_cb.confirm = confirm; 654ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta btif_cb.len = len; 655ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta memcpy(btif_cb.value, p_value, len > BTGATT_MAX_ATTR_LEN ? BTGATT_MAX_ATTR_LEN : len); 656ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta return btif_transfer_context(btgatts_handle_event, BTIF_GATTS_SEND_INDICATION, 657ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta (char*) &btif_cb, sizeof(btif_gatts_cb_t), NULL); 658ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta} 659ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 660ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Battastatic bt_status_t btif_gatts_send_response(int conn_id, int trans_id, 661ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta int status, btgatt_response_t *response) 662ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta{ 663ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta CHECK_BTGATT_INIT(); 664ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta btif_gatts_cb_t btif_cb; 665ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta btif_cb.conn_id = (uint16_t) conn_id; 666ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta btif_cb.trans_id = (uint32_t) trans_id; 667ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta btif_cb.status = (uint8_t) status; 668ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta memcpy(&btif_cb.response, response, sizeof(btgatt_response_t)); 669ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta return btif_transfer_context(btgatts_handle_event, BTIF_GATTS_SEND_RESPONSE, 670ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta (char*) &btif_cb, sizeof(btif_gatts_cb_t), NULL); 671ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta} 672ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 673ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Battaconst btgatt_server_interface_t btgattServerInterface = { 674ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta btif_gatts_register_app, 675ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta btif_gatts_unregister_app, 676ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta btif_gatts_open, 677ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta btif_gatts_close, 678ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta btif_gatts_add_service, 679ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta btif_gatts_add_included_service, 680ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta btif_gatts_add_characteristic, 681ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta btif_gatts_add_descriptor, 682ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta btif_gatts_start_service, 683ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta btif_gatts_stop_service, 684ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta btif_gatts_delete_service, 685ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta btif_gatts_send_indication, 686ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta btif_gatts_send_response 687ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta}; 688ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 689ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta#endif 690