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, bool is_direct);
32   void (*BTA_GATTC_Refresh)(const RawAddress& remote_bda);
33   void (*BTA_GATTC_GetGattDb)(tCONN_ID conn_id, uint16_t start_handle, uint16_t end_handle,
34                               btgatt_db_element_t** db, int* count);
35   void (*BTA_GATTC_AppRegister)(tBTA_GATTC_CBACK* p_client_cb, BtaAppRegisterCallback cb,
36                                 bool eatt_support);
37   void (*BTA_GATTC_Close)(tCONN_ID conn_id);
38   void (*BTA_GATTC_ServiceSearchRequest)(tCONN_ID conn_id, const bluetooth::Uuid* p_srvc_uuid);
39   void (*BTA_GATTC_Open)(tGATT_IF client_if, const RawAddress& remote_bda,
40                          tBTM_BLE_CONN_TYPE connection_type, bool opportunistic,
41                          uint16_t preferred_mtu);
42 };
43 
44 //
45 // Returns the current GATT client interface
46 //
47 gatt_interface_t& get_gatt_interface();
48 
49 //
50 // Appends a callback entry into GATT client API/callback history
51 //
52 void gatt_history_callback(const std::string& entry);
53 
54 //
55 // Dumps the GATT client API/callback history to dumpsys
56 //
57 void DumpsysBtaDmGattClient(int fd);
58 
59 namespace bluetooth {
60 namespace testing {
61 
62 //
63 // TESTING: Sets a specialzed GATT client interface implementation for testing
64 //
65 void set_gatt_interface(const gatt_interface_t& interface);
66 
67 }  // namespace testing
68 }  // namespace bluetooth
69