1 /****************************************************************************** 2 * 3 * Copyright 2018 The Android Open Source Project 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 #pragma once 19 20 #include <gmock/gmock.h> 21 22 #include "l2c_api.h" 23 #include "stack/include/bt_hdr.h" 24 #include "types/raw_address.h" 25 26 namespace bluetooth { 27 namespace l2cap { 28 29 class L2capInterface { 30 public: 31 virtual uint16_t Register(uint16_t psm, const tL2CAP_APPL_INFO& p_cb_info, 32 bool enable_snoop, 33 tL2CAP_ERTM_INFO* p_ertm_info) = 0; 34 virtual uint16_t ConnectRequest(uint16_t psm, const RawAddress& bd_addr) = 0; 35 virtual bool ConnectResponse(const RawAddress& bd_addr, uint8_t id, 36 uint16_t lcid, uint16_t result, 37 uint16_t status) = 0; 38 virtual bool DisconnectRequest(uint16_t cid) = 0; 39 virtual bool DisconnectResponse(uint16_t cid) = 0; 40 virtual bool ConfigRequest(uint16_t cid, tL2CAP_CFG_INFO* p_cfg) = 0; 41 virtual bool ConfigResponse(uint16_t cid, tL2CAP_CFG_INFO* p_cfg) = 0; 42 virtual uint8_t DataWrite(uint16_t cid, BT_HDR* p_data) = 0; 43 virtual uint16_t RegisterLECoc(uint16_t psm, const tL2CAP_APPL_INFO &cb_info, uint16_t sec_level) = 0; 44 virtual void DeregisterLECoc(uint16_t psm) = 0; 45 virtual bool ConnectCreditBasedRsp(const RawAddress& bd_addr, uint8_t id, 46 std::vector<uint16_t> &lcids, 47 uint16_t result, 48 tL2CAP_LE_CFG_INFO* p_cfg) = 0; 49 virtual std::vector<uint16_t> ConnectCreditBasedReq(uint16_t psm, 50 const RawAddress& bd_addr, 51 tL2CAP_LE_CFG_INFO* p_cfg) = 0; 52 virtual bool ReconfigCreditBasedConnsReq(const RawAddress& bd_addr, std::vector<uint16_t> &lcids, 53 tL2CAP_LE_CFG_INFO* peer_cfg) = 0; 54 virtual uint16_t LeCreditDefault() = 0; 55 virtual uint16_t LeCreditThreshold() = 0; 56 virtual ~L2capInterface() = default; 57 }; 58 59 class MockL2capInterface : public L2capInterface { 60 public: 61 MOCK_METHOD4(Register, 62 uint16_t(uint16_t psm, const tL2CAP_APPL_INFO& p_cb_info, 63 bool enable_snoop, tL2CAP_ERTM_INFO* p_ertm_info)); 64 MOCK_METHOD2(ConnectRequest, 65 uint16_t(uint16_t psm, const RawAddress& bd_addr)); 66 MOCK_METHOD5(ConnectResponse, 67 bool(const RawAddress& bd_addr, uint8_t id, uint16_t lcid, 68 uint16_t result, uint16_t status)); 69 MOCK_METHOD1(DisconnectRequest, bool(uint16_t cid)); 70 MOCK_METHOD1(DisconnectResponse, bool(uint16_t cid)); 71 MOCK_METHOD2(ConfigRequest, bool(uint16_t cid, tL2CAP_CFG_INFO* p_cfg)); 72 MOCK_METHOD2(ConfigResponse, bool(uint16_t cid, tL2CAP_CFG_INFO* p_cfg)); 73 MOCK_METHOD2(DataWrite, uint8_t(uint16_t cid, BT_HDR* p_data)); 74 MOCK_METHOD3(RegisterLECoc, 75 uint16_t(uint16_t psm, const tL2CAP_APPL_INFO &cb_info, uint16_t sec_level)); 76 MOCK_METHOD1(DeregisterLECoc, void(uint16_t psm)); 77 MOCK_METHOD1(GetBleConnRole, uint8_t(const RawAddress& bd_addr)); 78 MOCK_METHOD5(ConnectCreditBasedRsp, 79 bool(const RawAddress& p_bd_addr, uint8_t id, 80 std::vector<uint16_t> &lcids, 81 uint16_t result, 82 tL2CAP_LE_CFG_INFO* p_cfg)); 83 MOCK_METHOD3(ConnectCreditBasedReq, 84 std::vector<uint16_t> (uint16_t psm, 85 const RawAddress& bd_addr, 86 tL2CAP_LE_CFG_INFO* p_cfg)); 87 MOCK_METHOD3(ReconfigCreditBasedConnsReq, 88 bool(const RawAddress& p_bd_addr, std::vector<uint16_t> &lcids, tL2CAP_LE_CFG_INFO* peer_cfg)); 89 MOCK_METHOD(uint16_t, LeCreditDefault, ()); 90 MOCK_METHOD(uint16_t, LeCreditThreshold, ()); 91 }; 92 93 /** 94 * Set the {@link MockL2capInterface} for testing 95 * 96 * @param mock_l2cap_interface pointer to mock l2cap interface, could be null 97 */ 98 void SetMockInterface(MockL2capInterface* mock_l2cap_interface); 99 100 } // namespace l2cap 101 } // namespace bluetooth 102