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 "stack/test/common/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 // TODO(b/369381361) Enfore -Wmissing-prototypes
27 #pragma GCC diagnostic ignored "-Wmissing-prototypes"
28 
29 static bluetooth::l2cap::MockL2capInterface* l2cap_interface = nullptr;
30 
SetMockInterface(MockL2capInterface * mock_l2cap_interface)31 void bluetooth::l2cap::SetMockInterface(MockL2capInterface* mock_l2cap_interface) {
32   l2cap_interface = mock_l2cap_interface;
33 }
34 
l2cu_find_ccb_by_cid(tL2C_LCB *,uint16_t)35 tL2C_CCB* l2cu_find_ccb_by_cid(tL2C_LCB* /*p_lcb*/, uint16_t /*local_cid*/) { return nullptr; }
36 
L2CA_Register(uint16_t psm,const tL2CAP_APPL_INFO & p_cb_info,bool enable_snoop,tL2CAP_ERTM_INFO * p_ertm_info,uint16_t,uint16_t,uint16_t)37 uint16_t L2CA_Register(uint16_t psm, const tL2CAP_APPL_INFO& p_cb_info, bool enable_snoop,
38                        tL2CAP_ERTM_INFO* p_ertm_info, uint16_t /*my_mtu*/,
39                        uint16_t /*required_remote_mtu*/, uint16_t /*sec_level*/) {
40   bluetooth::log::verbose("psm={}, enable_snoop={}", psm, enable_snoop);
41   return l2cap_interface->Register(psm, p_cb_info, enable_snoop, p_ertm_info);
42 }
43 
L2CA_ConnectReq(uint16_t psm,const RawAddress & bd_addr)44 uint16_t L2CA_ConnectReq(uint16_t psm, const RawAddress& bd_addr) {
45   return l2cap_interface->ConnectRequest(psm, bd_addr);
46 }
47 
L2CA_DisconnectReq(uint16_t cid)48 bool L2CA_DisconnectReq(uint16_t cid) { return l2cap_interface->DisconnectRequest(cid); }
49 
L2CA_DisconnectRsp(uint16_t cid)50 bool L2CA_DisconnectRsp(uint16_t cid) { return l2cap_interface->DisconnectResponse(cid); }
51 
L2CA_ConfigReq(uint16_t cid,tL2CAP_CFG_INFO * p_cfg)52 bool L2CA_ConfigReq(uint16_t cid, tL2CAP_CFG_INFO* p_cfg) {
53   return l2cap_interface->ConfigRequest(cid, p_cfg);
54 }
55 
L2CA_ConfigRsp(uint16_t cid,tL2CAP_CFG_INFO * p_cfg)56 bool L2CA_ConfigRsp(uint16_t cid, tL2CAP_CFG_INFO* p_cfg) {
57   return l2cap_interface->ConfigResponse(cid, p_cfg);
58 }
59 
L2CA_DataWrite(uint16_t cid,BT_HDR * p_data)60 tL2CAP_DW_RESULT L2CA_DataWrite(uint16_t cid, BT_HDR* p_data) {
61   return l2cap_interface->DataWrite(cid, p_data);
62 }
63 
L2CA_RegisterLECoc(uint16_t psm,const tL2CAP_APPL_INFO & cb_info,uint16_t sec_level,tL2CAP_LE_CFG_INFO)64 uint16_t L2CA_RegisterLECoc(uint16_t psm, const tL2CAP_APPL_INFO& cb_info, uint16_t sec_level,
65                             tL2CAP_LE_CFG_INFO /*cfg*/) {
66   return l2cap_interface->RegisterLECoc(psm, cb_info, sec_level);
67 }
68 
L2CA_DeregisterLECoc(uint16_t psm)69 void L2CA_DeregisterLECoc(uint16_t psm) { return l2cap_interface->DeregisterLECoc(psm); }
70 
L2CA_GetBleConnRole(const RawAddress & bd_addr)71 tHCI_ROLE L2CA_GetBleConnRole(const RawAddress& bd_addr) {
72   return to_hci_role(l2cap_interface->GetBleConnRole(bd_addr));
73 }
74 
L2CA_ConnectCreditBasedReq(uint16_t psm,const RawAddress & bd_addr,tL2CAP_LE_CFG_INFO * p_cfg)75 std::vector<uint16_t> L2CA_ConnectCreditBasedReq(uint16_t psm, const RawAddress& bd_addr,
76                                                  tL2CAP_LE_CFG_INFO* p_cfg) {
77   return l2cap_interface->ConnectCreditBasedReq(psm, bd_addr, p_cfg);
78 }
79 
L2CA_ConnectCreditBasedRsp(const RawAddress & bd_addr,uint8_t id,std::vector<uint16_t> & lcids,tL2CAP_LE_RESULT_CODE result,tL2CAP_LE_CFG_INFO * p_cfg)80 bool L2CA_ConnectCreditBasedRsp(const RawAddress& bd_addr, uint8_t id, std::vector<uint16_t>& lcids,
81                                 tL2CAP_LE_RESULT_CODE result, tL2CAP_LE_CFG_INFO* p_cfg) {
82   return l2cap_interface->ConnectCreditBasedRsp(bd_addr, id, lcids, result, p_cfg);
83 }
84 
L2CA_ReconfigCreditBasedConnsReq(const RawAddress & bd_addr,std::vector<uint16_t> & lcids,tL2CAP_LE_CFG_INFO * peer_cfg)85 bool L2CA_ReconfigCreditBasedConnsReq(const RawAddress& bd_addr, std::vector<uint16_t>& lcids,
86                                       tL2CAP_LE_CFG_INFO* peer_cfg) {
87   return l2cap_interface->ReconfigCreditBasedConnsReq(bd_addr, lcids, peer_cfg);
88 }
L2CA_LeCreditDefault()89 uint16_t L2CA_LeCreditDefault() { return l2cap_interface->LeCreditDefault(); }
90 
L2CA_LeCreditThreshold()91 uint16_t L2CA_LeCreditThreshold() { return l2cap_interface->LeCreditThreshold(); }
92