1/******************************************************************************
2 *
3 *  Copyright (C) 2009-2013 Broadcom Corporation
4 *
5 *  Licensed under the Apache License, Version 2.0 (the "License");
6 *  you may not use this file except in compliance with the License.
7 *  You may obtain a copy of the License at:
8 *
9 *  http://www.apache.org/licenses/LICENSE-2.0
10 *
11 *  Unless required by applicable law or agreed to in writing, software
12 *  distributed under the License is distributed on an "AS IS" BASIS,
13 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 *  See the License for the specific language governing permissions and
15 *  limitations under the License.
16 *
17 ******************************************************************************/
18
19
20/*******************************************************************************
21 *
22 *  Filename:      btif_gatt.c
23 *
24 *  Description:   GATT Profile Bluetooth Interface
25 *
26 *******************************************************************************/
27
28#include <hardware/bluetooth.h>
29#include <hardware/bt_gatt.h>
30#include <stdio.h>
31#include <stdlib.h>
32#include <errno.h>
33#include <string.h>
34
35#define LOG_TAG "bt_btif_gatt"
36
37#include "btif_common.h"
38#include "btif_util.h"
39
40#if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
41
42#include "bta_api.h"
43#include "bta_gatt_api.h"
44#include "btif_storage.h"
45
46#include "btif_gatt.h"
47#include "btif_gatt_util.h"
48
49const btgatt_callbacks_t *bt_gatt_callbacks = NULL;
50
51extern btgatt_client_interface_t btgattClientInterface;
52extern btgatt_server_interface_t btgattServerInterface;
53
54/*******************************************************************************
55**
56** Function         btif_gatt_init
57**
58** Description      Initializes the GATT interface
59**
60** Returns          bt_status_t
61**
62*******************************************************************************/
63static bt_status_t btif_gatt_init( const btgatt_callbacks_t* callbacks )
64{
65    bt_gatt_callbacks = callbacks;
66
67    return BT_STATUS_SUCCESS;
68}
69
70/*******************************************************************************
71**
72** Function         btif_gatt_cleanup
73**
74** Description      Closes the GATT interface
75**
76** Returns          void
77**
78*******************************************************************************/
79static void  btif_gatt_cleanup( void )
80{
81    if (bt_gatt_callbacks)
82        bt_gatt_callbacks = NULL;
83
84    BTA_GATTC_Disable();
85    BTA_GATTS_Disable();
86}
87
88static const btgatt_interface_t btgattInterface = {
89    sizeof(btgattInterface),
90
91    btif_gatt_init,
92    btif_gatt_cleanup,
93
94    &btgattClientInterface,
95    &btgattServerInterface,
96};
97
98/*******************************************************************************
99**
100** Function         btif_gatt_get_interface
101**
102** Description      Get the gatt callback interface
103**
104** Returns          btgatt_interface_t
105**
106*******************************************************************************/
107const btgatt_interface_t *btif_gatt_get_interface()
108{
109    return &btgattInterface;
110}
111
112#endif
113