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