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 #pragma once 18 19 #include <gmock/gmock.h> 20 21 #include "btm_api.h" 22 #include "stack/btm/security_device_record.h" 23 #include "types/raw_address.h" 24 25 namespace bluetooth { 26 namespace manager { 27 28 class BtmInterface { 29 public: 30 virtual bool GetSecurityFlagsByTransport(const RawAddress& bd_addr, 31 uint8_t* p_sec_flags, 32 tBT_TRANSPORT transport) = 0; 33 virtual bool IsLinkKeyKnown(const RawAddress& bd_addr, 34 tBT_TRANSPORT transport) = 0; 35 virtual bool BTM_IsEncrypted(const RawAddress& bd_addr, 36 tBT_TRANSPORT transport) = 0; 37 virtual tBTM_STATUS SetEncryption(const RawAddress& bd_addr, 38 tBT_TRANSPORT transport, 39 tBTM_SEC_CALLBACK* p_callback, 40 void* p_ref_data, 41 tBTM_BLE_SEC_ACT sec_act) = 0; 42 virtual tBTM_SEC_DEV_REC* FindDevice(const RawAddress& bd_addr) = 0; 43 virtual bool IsPhy2mSupported(const RawAddress& remote_bda, 44 tBT_TRANSPORT transport) = 0; 45 virtual uint8_t GetPeerSCA(const RawAddress& remote_bda, 46 tBT_TRANSPORT transport) = 0; 47 virtual void BleSetPhy(const RawAddress& bd_addr, uint8_t tx_phys, 48 uint8_t rx_phys, uint16_t phy_options) = 0; 49 virtual bool SecIsSecurityPending(const RawAddress& bd_addr) = 0; 50 virtual void RequestPeerSCA(RawAddress const& bd_addr, 51 tBT_TRANSPORT transport) = 0; 52 virtual uint16_t GetHCIConnHandle(RawAddress const& bd_addr, 53 tBT_TRANSPORT transport) = 0; 54 virtual void AclDisconnectFromHandle(uint16_t handle, tHCI_STATUS reason) = 0; 55 virtual void ConfigureDataPath(uint8_t direction, uint8_t path_id, 56 std::vector<uint8_t> vendor_config) = 0; 57 virtual tBTM_INQ_INFO* BTM_InqDbFirst() = 0; 58 virtual tBTM_INQ_INFO* BTM_InqDbNext(tBTM_INQ_INFO* p_cur) = 0; 59 virtual ~BtmInterface() = default; 60 }; 61 62 class MockBtmInterface : public BtmInterface { 63 public: 64 MOCK_METHOD((bool), GetSecurityFlagsByTransport, 65 (const RawAddress& bd_addr, uint8_t* p_sec_flags, 66 tBT_TRANSPORT transport), 67 (override)); 68 MOCK_METHOD((bool), IsLinkKeyKnown, 69 (const RawAddress& bd_addr, tBT_TRANSPORT transport), (override)); 70 MOCK_METHOD((bool), BTM_IsEncrypted, 71 (const RawAddress& bd_addr, tBT_TRANSPORT transport), (override)); 72 MOCK_METHOD((tBTM_STATUS), SetEncryption, 73 (const RawAddress& bd_addr, tBT_TRANSPORT transport, 74 tBTM_SEC_CALLBACK* p_callback, void* p_ref_data, 75 tBTM_BLE_SEC_ACT sec_act), 76 (override)); 77 MOCK_METHOD((tBTM_SEC_DEV_REC*), FindDevice, (const RawAddress& bd_addr), 78 (override)); 79 MOCK_METHOD((bool), IsPhy2mSupported, 80 (const RawAddress& remote_bda, tBT_TRANSPORT transport), 81 (override)); 82 MOCK_METHOD((uint8_t), GetPeerSCA, 83 (const RawAddress& remote_bda, tBT_TRANSPORT transport), 84 (override)); 85 MOCK_METHOD((void), BleSetPhy, 86 (const RawAddress& bd_addr, uint8_t tx_phys, uint8_t rx_phys, 87 uint16_t phy_options), 88 (override)); 89 MOCK_METHOD((bool), SecIsSecurityPending, (const RawAddress& bd_addr), 90 (override)); 91 MOCK_METHOD((void), RequestPeerSCA, 92 (RawAddress const& bd_addr, tBT_TRANSPORT transport), (override)); 93 MOCK_METHOD((uint16_t), GetHCIConnHandle, 94 (RawAddress const& bd_addr, tBT_TRANSPORT transport), (override)); 95 MOCK_METHOD((void), AclDisconnectFromHandle, 96 (uint16_t handle, tHCI_STATUS reason), (override)); 97 MOCK_METHOD((void), ConfigureDataPath, 98 (uint8_t direction, uint8_t path_id, 99 std::vector<uint8_t> vendor_config), 100 (override)); 101 MOCK_METHOD((tBTM_INQ_INFO*), BTM_InqDbFirst, (), (override)); 102 MOCK_METHOD((tBTM_INQ_INFO*), BTM_InqDbNext, (tBTM_INQ_INFO * p_cur), 103 (override)); 104 }; 105 106 /** 107 * Set the {@link MockBtmInterface} for testing 108 * 109 * @param mock_btm_interface pointer to mock btm interface, could be null 110 */ 111 void SetMockBtmInterface(MockBtmInterface* mock_btm_interface); 112 113 } // namespace manager 114 } // namespace bluetooth 115