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 "btm_api_mock.h"
19
20 #include "types/raw_address.h"
21
22 static bluetooth::manager::MockBtmInterface* btm_interface = nullptr;
23
SetMockBtmInterface(MockBtmInterface * mock_btm_interface)24 void bluetooth::manager::SetMockBtmInterface(
25 MockBtmInterface* mock_btm_interface) {
26 btm_interface = mock_btm_interface;
27 }
28
BTM_GetSecurityFlagsByTransport(const RawAddress & bd_addr,uint8_t * p_sec_flags,tBT_TRANSPORT transport)29 bool BTM_GetSecurityFlagsByTransport(const RawAddress& bd_addr,
30 uint8_t* p_sec_flags,
31 tBT_TRANSPORT transport) {
32 LOG_ASSERT(btm_interface) << "Mock btm interface not set!";
33 return btm_interface->GetSecurityFlagsByTransport(bd_addr, p_sec_flags,
34 transport);
35 }
36
BTM_IsLinkKeyKnown(const RawAddress & bd_addr,tBT_TRANSPORT transport)37 bool BTM_IsLinkKeyKnown(const RawAddress& bd_addr, tBT_TRANSPORT transport) {
38 LOG_ASSERT(btm_interface) << "Mock btm interface not set!";
39 return btm_interface->IsLinkKeyKnown(bd_addr, transport);
40 }
41
BTM_IsEncrypted(const RawAddress & bd_addr,tBT_TRANSPORT transport)42 bool BTM_IsEncrypted(const RawAddress& bd_addr, tBT_TRANSPORT transport) {
43 return btm_interface->BTM_IsEncrypted(bd_addr, transport);
44 }
45
BTM_SetEncryption(const RawAddress & bd_addr,tBT_TRANSPORT transport,tBTM_SEC_CALLBACK * p_callback,void * p_ref_data,tBTM_BLE_SEC_ACT sec_act)46 tBTM_STATUS BTM_SetEncryption(const RawAddress& bd_addr,
47 tBT_TRANSPORT transport,
48 tBTM_SEC_CALLBACK* p_callback, void* p_ref_data,
49 tBTM_BLE_SEC_ACT sec_act) {
50 return btm_interface->SetEncryption(bd_addr, transport, p_callback,
51 p_ref_data, sec_act);
52 }
53
BTM_IsPhy2mSupported(const RawAddress & remote_bda,tBT_TRANSPORT transport)54 bool BTM_IsPhy2mSupported(const RawAddress& remote_bda,
55 tBT_TRANSPORT transport) {
56 LOG_ASSERT(btm_interface) << "Mock btm interface not set!";
57 return btm_interface->IsPhy2mSupported(remote_bda, transport);
58 }
59
BTM_GetPeerSCA(const RawAddress & remote_bda,tBT_TRANSPORT transport)60 uint8_t BTM_GetPeerSCA(const RawAddress& remote_bda, tBT_TRANSPORT transport) {
61 LOG_ASSERT(btm_interface) << "Mock btm interface not set!";
62 return btm_interface->GetPeerSCA(remote_bda, transport);
63 }
64
BTM_BleSetPhy(const RawAddress & bd_addr,uint8_t tx_phys,uint8_t rx_phys,uint16_t phy_options)65 void BTM_BleSetPhy(const RawAddress& bd_addr, uint8_t tx_phys, uint8_t rx_phys,
66 uint16_t phy_options) {
67 LOG_ASSERT(btm_interface) << "Mock btm interface not set!";
68 btm_interface->BleSetPhy(bd_addr, tx_phys, rx_phys, phy_options);
69 }
70
BTM_SecIsSecurityPending(const RawAddress & bd_addr)71 bool BTM_SecIsSecurityPending(const RawAddress& bd_addr) {
72 LOG_ASSERT(btm_interface) << "Mock btm interface not set!";
73 return btm_interface->SecIsSecurityPending(bd_addr);
74 }
75
btm_find_dev(const RawAddress & bd_addr)76 tBTM_SEC_DEV_REC* btm_find_dev(const RawAddress& bd_addr) {
77 LOG_ASSERT(btm_interface) << "Mock btm interface not set!";
78 return btm_interface->FindDevice(bd_addr);
79 }
80
BTM_RequestPeerSCA(RawAddress const & bd_addr,tBT_TRANSPORT transport)81 void BTM_RequestPeerSCA(RawAddress const& bd_addr, tBT_TRANSPORT transport) {
82 LOG_ASSERT(btm_interface) << "Mock btm interface not set!";
83 btm_interface->RequestPeerSCA(bd_addr, transport);
84 }
85
BTM_GetHCIConnHandle(RawAddress const & bd_addr,tBT_TRANSPORT transport)86 uint16_t BTM_GetHCIConnHandle(RawAddress const& bd_addr,
87 tBT_TRANSPORT transport) {
88 LOG_ASSERT(btm_interface) << "Mock btm interface not set!";
89 return btm_interface->GetHCIConnHandle(bd_addr, transport);
90 }
91
acl_disconnect_from_handle(uint16_t handle,tHCI_STATUS reason,std::string comment)92 void acl_disconnect_from_handle(uint16_t handle, tHCI_STATUS reason,
93 std::string comment) {
94 LOG_ASSERT(btm_interface) << "Mock btm interface not set!";
95 return btm_interface->AclDisconnectFromHandle(handle, reason);
96 }
97
btm_configure_data_path(uint8_t direction,uint8_t path_id,std::vector<uint8_t> vendor_config)98 void btm_configure_data_path(uint8_t direction, uint8_t path_id,
99 std::vector<uint8_t> vendor_config) {
100 LOG_ASSERT(btm_interface) << "Mock btm interface not set!";
101 return btm_interface->ConfigureDataPath(direction, path_id, vendor_config);
102 }
103
BTM_InqDbFirst(void)104 tBTM_INQ_INFO* BTM_InqDbFirst(void) {
105 LOG_ASSERT(btm_interface) << "Mock btm interface not set!";
106 return btm_interface->BTM_InqDbFirst();
107 }
BTM_InqDbNext(tBTM_INQ_INFO * p_cur)108 tBTM_INQ_INFO* BTM_InqDbNext(tBTM_INQ_INFO* p_cur) {
109 LOG_ASSERT(btm_interface) << "Mock btm interface not set!";
110 return btm_interface->BTM_InqDbNext(p_cur);
111 }