• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /******************************************************************************
2  *
3  *  Copyright 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  *  Filename:      btif_gatt.c
22  *
23  *  Description:   GATT Profile Bluetooth Interface
24  *
25  ******************************************************************************/
26 
27 #define LOG_TAG "bt_btif_gatt"
28 
29 #include "btif_gatt.h"
30 
31 #include <com_android_bluetooth_flags.h>
32 #include <hardware/bluetooth.h>
33 #include <hardware/bt_gatt.h>
34 #include <stdlib.h>
35 #include <string.h>
36 
37 #include "bta/include/bta_gatt_api.h"
38 #include "btif/include/btif_common.h"
39 #include "main/shim/distance_measurement_manager.h"
40 #include "main/shim/le_advertising_manager.h"
41 
42 const btgatt_callbacks_t* bt_gatt_callbacks = NULL;
43 
44 /*******************************************************************************
45  *
46  * Function         btif_gatt_init
47  *
48  * Description      Initializes the GATT interface
49  *
50  * Returns          bt_status_t
51  *
52  ******************************************************************************/
btif_gatt_init(const btgatt_callbacks_t * callbacks)53 static bt_status_t btif_gatt_init(const btgatt_callbacks_t* callbacks) {
54   bt_gatt_callbacks = callbacks;
55   BTA_GATTS_InitBonded();
56   return BT_STATUS_SUCCESS;
57 }
58 
59 /*******************************************************************************
60  *
61  * Function         btif_gatt_cleanup
62  *
63  * Description      Closes the GATT interface
64  *
65  * Returns          void
66  *
67  ******************************************************************************/
btif_gatt_cleanup(void)68 static void btif_gatt_cleanup(void) {
69   if (bt_gatt_callbacks) {
70     bt_gatt_callbacks = NULL;
71   }
72 
73   BTA_GATTC_Disable();
74   BTA_GATTS_Disable();
75 }
76 
77 static btgatt_interface_t btgattInterface = {
78         .size = sizeof(btgattInterface),
79 
80         .init = btif_gatt_init,
81         .cleanup = btif_gatt_cleanup,
82 
83         .client = &btgattClientInterface,
84         .server = &btgattServerInterface,
85         .scanner = nullptr,    // filled in btif_gatt_get_interface
86         .advertiser = nullptr  // filled in btif_gatt_get_interface
87 };
88 
89 /*******************************************************************************
90  *
91  * Function         btif_gatt_get_interface
92  *
93  * Description      Get the gatt callback interface
94  *
95  * Returns          btgatt_interface_t
96  *
97  ******************************************************************************/
btif_gatt_get_interface()98 const btgatt_interface_t* btif_gatt_get_interface() {
99   // TODO(jpawlowski) right now initializing advertiser field in static
100   // structure cause explosion of dependencies. It must be initialized here
101   // until those dependencies are properly abstracted for tests.
102   btgattInterface.scanner = get_ble_scanner_instance();
103   btgattInterface.advertiser = bluetooth::shim::get_ble_advertiser_instance();
104   btgattInterface.distance_measurement_manager =
105           bluetooth::shim::get_distance_measurement_instance();
106   return &btgattInterface;
107 }
108