1 /*
2 * Copyright 2021 HIMSA II K/S - www.himsa.com.
3 * Represented by EHIMA - www.ehima.com
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 #include "bta_gatt_api_mock.h"
19
20 #include "types/bluetooth/uuid.h"
21 #include "types/raw_address.h"
22
23 static gatt::MockBtaGattInterface* gatt_interface = nullptr;
24
SetMockBtaGattInterface(MockBtaGattInterface * mock_bta_gatt_interface)25 void gatt::SetMockBtaGattInterface(
26 MockBtaGattInterface* mock_bta_gatt_interface) {
27 gatt_interface = mock_bta_gatt_interface;
28 }
29
BTA_GATTC_AppRegister(tBTA_GATTC_CBACK * p_client_cb,BtaAppRegisterCallback cb,bool eatt_support)30 void BTA_GATTC_AppRegister(tBTA_GATTC_CBACK* p_client_cb,
31 BtaAppRegisterCallback cb, bool eatt_support) {
32 LOG_ASSERT(gatt_interface) << "Mock GATT interface not set!";
33 gatt_interface->AppRegister(p_client_cb, cb, eatt_support);
34 }
35
BTA_GATTC_AppDeregister(tGATT_IF client_if)36 void BTA_GATTC_AppDeregister(tGATT_IF client_if) {
37 LOG_ASSERT(gatt_interface) << "Mock GATT interface not set!";
38 gatt_interface->AppDeregister(client_if);
39 }
40
BTA_GATTC_Open(tGATT_IF client_if,const RawAddress & remote_bda,tBTM_BLE_CONN_TYPE connection_type,tBT_TRANSPORT transport,bool opportunistic,uint8_t initiating_phys)41 void BTA_GATTC_Open(tGATT_IF client_if, const RawAddress& remote_bda,
42 tBTM_BLE_CONN_TYPE connection_type, tBT_TRANSPORT transport,
43 bool opportunistic, uint8_t initiating_phys) {
44 LOG_ASSERT(gatt_interface) << "Mock GATT interface not set!";
45 gatt_interface->Open(client_if, remote_bda, connection_type, transport,
46 opportunistic, initiating_phys);
47 }
48
BTA_GATTC_Open(tGATT_IF client_if,const RawAddress & remote_bda,tBTM_BLE_CONN_TYPE connection_type,bool opportunistic)49 void BTA_GATTC_Open(tGATT_IF client_if, const RawAddress& remote_bda,
50 tBTM_BLE_CONN_TYPE connection_type, bool opportunistic) {
51 LOG_ASSERT(gatt_interface) << "Mock GATT interface not set!";
52 gatt_interface->Open(client_if, remote_bda, connection_type, opportunistic);
53 }
54
BTA_GATTC_CancelOpen(tGATT_IF client_if,const RawAddress & remote_bda,bool is_direct)55 void BTA_GATTC_CancelOpen(tGATT_IF client_if, const RawAddress& remote_bda,
56 bool is_direct) {
57 LOG_ASSERT(gatt_interface) << "Mock GATT interface not set!";
58 gatt_interface->CancelOpen(client_if, remote_bda, is_direct);
59 }
60
BTA_GATTC_Close(uint16_t conn_id)61 void BTA_GATTC_Close(uint16_t conn_id) {
62 LOG_ASSERT(gatt_interface) << "Mock GATT interface not set!";
63 gatt_interface->Close(conn_id);
64 }
65
BTA_GATTC_ServiceSearchRequest(uint16_t conn_id,const bluetooth::Uuid * p_srvc_uuid)66 void BTA_GATTC_ServiceSearchRequest(uint16_t conn_id,
67 const bluetooth::Uuid* p_srvc_uuid) {
68 LOG_ASSERT(gatt_interface) << "Mock GATT interface not set!";
69 gatt_interface->ServiceSearchRequest(conn_id, p_srvc_uuid);
70 }
71
BTA_GATTC_SendIndConfirm(uint16_t conn_id,uint16_t cid)72 void BTA_GATTC_SendIndConfirm(uint16_t conn_id, uint16_t cid) {
73 LOG_ASSERT(gatt_interface) << "Mock GATT interface not set!";
74 gatt_interface->SendIndConfirm(conn_id, cid);
75 }
76
BTA_GATTC_GetServices(uint16_t conn_id)77 const std::list<gatt::Service>* BTA_GATTC_GetServices(uint16_t conn_id) {
78 LOG_ASSERT(gatt_interface) << "Mock GATT interface not set!";
79 return gatt_interface->GetServices(conn_id);
80 }
81
BTA_GATTC_GetCharacteristic(uint16_t conn_id,uint16_t handle)82 const gatt::Characteristic* BTA_GATTC_GetCharacteristic(uint16_t conn_id,
83 uint16_t handle) {
84 LOG_ASSERT(gatt_interface) << "Mock GATT interface not set!";
85 return gatt_interface->GetCharacteristic(conn_id, handle);
86 }
87
BTA_GATTC_GetOwningService(uint16_t conn_id,uint16_t handle)88 const gatt::Service* BTA_GATTC_GetOwningService(uint16_t conn_id,
89 uint16_t handle) {
90 LOG_ASSERT(gatt_interface) << "Mock GATT interface not set!";
91 return gatt_interface->GetOwningService(conn_id, handle);
92 }
93
BTA_GATTC_RegisterForNotifications(tGATT_IF client_if,const RawAddress & remote_bda,uint16_t handle)94 tGATT_STATUS BTA_GATTC_RegisterForNotifications(tGATT_IF client_if,
95 const RawAddress& remote_bda,
96 uint16_t handle) {
97 LOG_ASSERT(gatt_interface) << "Mock GATT interface not set!";
98 return gatt_interface->RegisterForNotifications(client_if, remote_bda,
99 handle);
100 }
101
BTA_GATTC_DeregisterForNotifications(tGATT_IF client_if,const RawAddress & remote_bda,uint16_t handle)102 tGATT_STATUS BTA_GATTC_DeregisterForNotifications(tGATT_IF client_if,
103 const RawAddress& remote_bda,
104 uint16_t handle) {
105 LOG_ASSERT(gatt_interface) << "Mock GATT interface not set!";
106 return gatt_interface->DeregisterForNotifications(client_if, remote_bda,
107 handle);
108 }
109