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 static bluetooth::l2cap::MockL2capInterface* l2cap_interface = nullptr;
21
SetMockInterface(MockL2capInterface * mock_l2cap_interface)22 void bluetooth::l2cap::SetMockInterface(
23 MockL2capInterface* mock_l2cap_interface) {
24 l2cap_interface = mock_l2cap_interface;
25 }
26
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)27 uint16_t L2CA_Register(uint16_t psm, const tL2CAP_APPL_INFO& p_cb_info,
28 bool enable_snoop, tL2CAP_ERTM_INFO* p_ertm_info,
29 uint16_t my_mtu, uint16_t required_remote_mtu,
30 uint16_t sec_level) {
31 VLOG(1) << __func__ << ": psm=" << psm << ", enable_snoop=" << enable_snoop;
32 return l2cap_interface->Register(psm, p_cb_info, enable_snoop, p_ertm_info);
33 }
34
L2CA_ConnectReq(uint16_t psm,const RawAddress & bd_addr)35 uint16_t L2CA_ConnectReq(uint16_t psm, const RawAddress& bd_addr) {
36 return l2cap_interface->ConnectRequest(psm, bd_addr);
37 }
38
L2CA_ConnectRsp(const RawAddress & bd_addr,uint8_t id,uint16_t lcid,uint16_t result,uint16_t status)39 bool L2CA_ConnectRsp(const RawAddress& bd_addr, uint8_t id, uint16_t lcid,
40 uint16_t result, uint16_t status) {
41 return l2cap_interface->ConnectResponse(bd_addr, id, lcid, result, status);
42 }
43
L2CA_DisconnectReq(uint16_t cid)44 bool L2CA_DisconnectReq(uint16_t cid) {
45 return l2cap_interface->DisconnectRequest(cid);
46 }
47
L2CA_DisconnectRsp(uint16_t cid)48 bool L2CA_DisconnectRsp(uint16_t cid) {
49 return l2cap_interface->DisconnectResponse(cid);
50 }
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 uint8_t 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 cfg)64 uint16_t L2CA_RegisterLECoc(uint16_t psm, const tL2CAP_APPL_INFO& cb_info,
65 uint16_t sec_level, 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) {
70 return l2cap_interface->DeregisterLECoc(psm);
71 }
72
L2CA_GetBleConnRole(const RawAddress & bd_addr)73 tHCI_ROLE L2CA_GetBleConnRole(const RawAddress& bd_addr) {
74 return to_hci_role(l2cap_interface->GetBleConnRole(bd_addr));
75 }
76
L2CA_ConnectCreditBasedReq(uint16_t psm,const RawAddress & bd_addr,tL2CAP_LE_CFG_INFO * p_cfg)77 std::vector<uint16_t> L2CA_ConnectCreditBasedReq(uint16_t psm,
78 const RawAddress& bd_addr,
79 tL2CAP_LE_CFG_INFO* p_cfg) {
80 return l2cap_interface->ConnectCreditBasedReq(psm, bd_addr, p_cfg);
81 }
82
L2CA_ConnectCreditBasedRsp(const RawAddress & bd_addr,uint8_t id,std::vector<uint16_t> & lcids,uint16_t result,tL2CAP_LE_CFG_INFO * p_cfg)83 bool L2CA_ConnectCreditBasedRsp(const RawAddress& bd_addr, uint8_t id,
84 std::vector<uint16_t> &lcids,
85 uint16_t result,
86 tL2CAP_LE_CFG_INFO* p_cfg) {
87 return l2cap_interface->ConnectCreditBasedRsp(bd_addr, id, lcids, result, p_cfg);
88 }
89
L2CA_ReconfigCreditBasedConnsReq(const RawAddress & bd_addr,std::vector<uint16_t> & lcids,tL2CAP_LE_CFG_INFO * peer_cfg)90 bool L2CA_ReconfigCreditBasedConnsReq(const RawAddress& bd_addr, std::vector<uint16_t> &lcids,
91 tL2CAP_LE_CFG_INFO* peer_cfg) {
92 return l2cap_interface->ReconfigCreditBasedConnsReq(bd_addr, lcids, peer_cfg);
93 }
94