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 #include "mock_l2cap_layer.h"
19 
20 #include <bluetooth/log.h>
21 
22 #include "stack/include/bt_hdr.h"
23 #include "stack/l2cap/l2c_int.h"
24 #include "types/raw_address.h"
25 
26 static bluetooth::l2cap::MockL2capInterface* l2cap_interface = nullptr;
27 
SetMockInterface(MockL2capInterface * mock_l2cap_interface)28 void bluetooth::l2cap::SetMockInterface(
29     MockL2capInterface* mock_l2cap_interface) {
30   l2cap_interface = mock_l2cap_interface;
31 }
32 
l2cu_find_ccb_by_cid(tL2C_LCB * p_lcb,uint16_t local_cid)33 tL2C_CCB* l2cu_find_ccb_by_cid(tL2C_LCB* p_lcb, uint16_t local_cid) {
34   return nullptr;
35 }
36 
L2CA_Register(uint16_t psm,const tL2CAP_APPL_INFO & p_cb_info,bool enable_snoop,tL2CAP_ERTM_INFO * p_ertm_info,uint16_t my_mtu,uint16_t required_remote_mtu,uint16_t sec_level)37 uint16_t L2CA_Register(uint16_t psm, const tL2CAP_APPL_INFO& p_cb_info,
38                        bool enable_snoop, tL2CAP_ERTM_INFO* p_ertm_info,
39                        uint16_t my_mtu, uint16_t required_remote_mtu,
40                        uint16_t sec_level) {
41   bluetooth::log::verbose("psm={}, enable_snoop={}", psm, enable_snoop);
42   return l2cap_interface->Register(psm, p_cb_info, enable_snoop, p_ertm_info);
43 }
44 
L2CA_ConnectReq(uint16_t psm,const RawAddress & bd_addr)45 uint16_t L2CA_ConnectReq(uint16_t psm, const RawAddress& bd_addr) {
46   return l2cap_interface->ConnectRequest(psm, bd_addr);
47 }
48 
L2CA_ConnectRsp(const RawAddress & bd_addr,uint8_t id,uint16_t lcid,uint16_t result,uint16_t status)49 bool L2CA_ConnectRsp(const RawAddress& bd_addr, uint8_t id, uint16_t lcid,
50                      uint16_t result, uint16_t status) {
51   return l2cap_interface->ConnectResponse(bd_addr, id, lcid, result, status);
52 }
53 
L2CA_DisconnectReq(uint16_t cid)54 bool L2CA_DisconnectReq(uint16_t cid) {
55   return l2cap_interface->DisconnectRequest(cid);
56 }
57 
L2CA_DisconnectRsp(uint16_t cid)58 bool L2CA_DisconnectRsp(uint16_t cid) {
59   return l2cap_interface->DisconnectResponse(cid);
60 }
61 
L2CA_ConfigReq(uint16_t cid,tL2CAP_CFG_INFO * p_cfg)62 bool L2CA_ConfigReq(uint16_t cid, tL2CAP_CFG_INFO* p_cfg) {
63   return l2cap_interface->ConfigRequest(cid, p_cfg);
64 }
65 
L2CA_ConfigRsp(uint16_t cid,tL2CAP_CFG_INFO * p_cfg)66 bool L2CA_ConfigRsp(uint16_t cid, tL2CAP_CFG_INFO* p_cfg) {
67   return l2cap_interface->ConfigResponse(cid, p_cfg);
68 }
69 
L2CA_DataWrite(uint16_t cid,BT_HDR * p_data)70 uint8_t L2CA_DataWrite(uint16_t cid, BT_HDR* p_data) {
71   return l2cap_interface->DataWrite(cid, p_data);
72 }
73 
L2CA_RegisterLECoc(uint16_t psm,const tL2CAP_APPL_INFO & cb_info,uint16_t sec_level,tL2CAP_LE_CFG_INFO cfg)74 uint16_t L2CA_RegisterLECoc(uint16_t psm, const tL2CAP_APPL_INFO& cb_info,
75                             uint16_t sec_level, tL2CAP_LE_CFG_INFO cfg) {
76   return l2cap_interface->RegisterLECoc(psm, cb_info, sec_level);
77 }
78 
L2CA_DeregisterLECoc(uint16_t psm)79 void L2CA_DeregisterLECoc(uint16_t psm) {
80   return l2cap_interface->DeregisterLECoc(psm);
81 }
82 
L2CA_GetBleConnRole(const RawAddress & bd_addr)83 tHCI_ROLE L2CA_GetBleConnRole(const RawAddress& bd_addr) {
84   return to_hci_role(l2cap_interface->GetBleConnRole(bd_addr));
85 }
86 
L2CA_ConnectCreditBasedReq(uint16_t psm,const RawAddress & bd_addr,tL2CAP_LE_CFG_INFO * p_cfg)87 std::vector<uint16_t> L2CA_ConnectCreditBasedReq(uint16_t psm,
88                                 const RawAddress& bd_addr,
89                                 tL2CAP_LE_CFG_INFO* p_cfg) {
90   return l2cap_interface->ConnectCreditBasedReq(psm, bd_addr, p_cfg);
91 }
92 
L2CA_ConnectCreditBasedRsp(const RawAddress & bd_addr,uint8_t id,std::vector<uint16_t> & lcids,uint16_t result,tL2CAP_LE_CFG_INFO * p_cfg)93 bool L2CA_ConnectCreditBasedRsp(const RawAddress& bd_addr, uint8_t id,
94                                        std::vector<uint16_t> &lcids,
95                                        uint16_t result,
96                                        tL2CAP_LE_CFG_INFO* p_cfg) {
97   return l2cap_interface->ConnectCreditBasedRsp(bd_addr, id, lcids, result, p_cfg);
98 }
99 
L2CA_ReconfigCreditBasedConnsReq(const RawAddress & bd_addr,std::vector<uint16_t> & lcids,tL2CAP_LE_CFG_INFO * peer_cfg)100 bool L2CA_ReconfigCreditBasedConnsReq(const RawAddress& bd_addr, std::vector<uint16_t> &lcids,
101                                       tL2CAP_LE_CFG_INFO* peer_cfg) {
102   return l2cap_interface->ReconfigCreditBasedConnsReq(bd_addr, lcids, peer_cfg);
103 }
L2CA_LeCreditDefault()104 uint16_t L2CA_LeCreditDefault() { return l2cap_interface->LeCreditDefault(); }
105 
L2CA_LeCreditThreshold()106 uint16_t L2CA_LeCreditThreshold() {
107   return l2cap_interface->LeCreditThreshold();
108 }
109