1 /*
2  * Copyright 2023 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 
19 #include <cstdint>
20 
21 #include "bta/include/bta_gatt_api.h"
22 #include "include/hardware/bt_common_types.h"
23 #include "stack/include/btm_ble_api_types.h"
24 #include "types/bluetooth/uuid.h"
25 #include "types/raw_address.h"
26 
27 //
28 // Interface as a GATT client for bta clients
29 //
30 struct gatt_interface_t {
31   void (*BTA_GATTC_CancelOpen)(tGATT_IF client_if, const RawAddress& remote_bda,
32                                bool is_direct);
33   void (*BTA_GATTC_Refresh)(const RawAddress& remote_bda);
34   void (*BTA_GATTC_GetGattDb)(uint16_t conn_id, uint16_t start_handle,
35                               uint16_t end_handle, btgatt_db_element_t** db,
36                               int* count);
37   void (*BTA_GATTC_AppRegister)(tBTA_GATTC_CBACK* p_client_cb,
38                                 BtaAppRegisterCallback cb, bool eatt_support);
39   void (*BTA_GATTC_Close)(uint16_t conn_id);
40   void (*BTA_GATTC_ServiceSearchRequest)(uint16_t conn_id,
41                                          const bluetooth::Uuid* p_srvc_uuid);
42   void (*BTA_GATTC_Open)(tGATT_IF client_if, const RawAddress& remote_bda,
43                          tBTM_BLE_CONN_TYPE connection_type,
44                          bool opportunistic);
45 };
46 
47 //
48 // Returns the current GATT client interface
49 //
50 gatt_interface_t& get_gatt_interface();
51 
52 //
53 // Appends a callback entry into GATT client API/callback history
54 //
55 void gatt_history_callback(const std::string& entry);
56 
57 //
58 // Dumps the GATT client API/callback history to dumpsys
59 //
60 void DumpsysBtaDmGattClient(int fd);
61 
62 namespace bluetooth {
63 namespace testing {
64 
65 //
66 // TESTING: Sets a specialzed GATT client interface implementation for testing
67 //
68 void set_gatt_interface(const gatt_interface_t& interface);
69 
70 }  // namespace testing
71 }  // namespace bluetooth
72