1 /*
2  * Copyright 2025 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include "test/mock/mock_stack_gap_conn_interface.h"
18 
19 #include "stack/include/gap_api.h"
20 #include "test/common/mock_functions.h"
21 
22 namespace {
23 bluetooth::testing::stack::gap_conn::Mock mock_gap_conn_interface;
24 bluetooth::testing::stack::gap_conn::Interface* interface_ = &mock_gap_conn_interface;
25 }  // namespace
26 
reset_interface()27 void bluetooth::testing::stack::gap_conn::reset_interface() {
28   interface_ = &mock_gap_conn_interface;
29 }
30 
set_interface(bluetooth::testing::stack::gap_conn::Interface * interface)31 void bluetooth::testing::stack::gap_conn::set_interface(
32         bluetooth::testing::stack::gap_conn::Interface* interface) {
33   interface_ = interface;
34 }
35 
GAP_ConnOpen(const char * p_serv_name,uint8_t service_id,bool is_server,const RawAddress * p_rem_bda,uint16_t psm,uint16_t le_mps,tL2CAP_CFG_INFO * p_cfg,tL2CAP_ERTM_INFO * ertm_info,uint16_t security,tGAP_CONN_CALLBACK * p_cb,tBT_TRANSPORT transport)36 uint16_t GAP_ConnOpen(const char* p_serv_name, uint8_t service_id, bool is_server,
37                       const RawAddress* p_rem_bda, uint16_t psm, uint16_t le_mps,
38                       tL2CAP_CFG_INFO* p_cfg, tL2CAP_ERTM_INFO* ertm_info, uint16_t security,
39                       tGAP_CONN_CALLBACK* p_cb, tBT_TRANSPORT transport) {
40   inc_func_call_count(__func__);
41 
42   return interface_->GAP_ConnOpen(p_serv_name, service_id, is_server, p_rem_bda, psm, le_mps, p_cfg,
43                                   ertm_info, security, p_cb, transport);
44 }
45 
GAP_ConnGetRemoteAddr(uint16_t gap_handle)46 const RawAddress* GAP_ConnGetRemoteAddr(uint16_t gap_handle) {
47   inc_func_call_count(__func__);
48 
49   return interface_->GAP_ConnGetRemoteAddr(gap_handle);
50 }
GAP_GetRxQueueCnt(uint16_t,uint32_t *)51 int GAP_GetRxQueueCnt(uint16_t /* handle */, uint32_t* /* p_rx_queue_count */) {
52   inc_func_call_count(__func__);
53   return 0;
54 }
GAP_ConnClose(uint16_t)55 uint16_t GAP_ConnClose(uint16_t /* gap_handle */) {
56   inc_func_call_count(__func__);
57   return 0;
58 }
GAP_ConnGetL2CAPCid(uint16_t)59 uint16_t GAP_ConnGetL2CAPCid(uint16_t /* gap_handle */) {
60   inc_func_call_count(__func__);
61   return 0;
62 }
GAP_ConnGetRemMtuSize(uint16_t)63 uint16_t GAP_ConnGetRemMtuSize(uint16_t /* gap_handle */) {
64   inc_func_call_count(__func__);
65   return 0;
66 }
GAP_ConnReadData(uint16_t,uint8_t *,uint16_t,uint16_t *)67 uint16_t GAP_ConnReadData(uint16_t /* gap_handle */, uint8_t* /* p_data */, uint16_t /* max_len */,
68                           uint16_t* /* p_len */) {
69   inc_func_call_count(__func__);
70   return 0;
71 }
GAP_ConnWriteData(uint16_t,BT_HDR *)72 uint16_t GAP_ConnWriteData(uint16_t /* gap_handle */, BT_HDR* /* msg */) {
73   inc_func_call_count(__func__);
74   return 0;
75 }
GAP_GetLeChannelInfo(uint16_t,uint16_t *,uint16_t *,uint16_t *,uint16_t *,uint16_t *,uint16_t *,uint16_t *,uint16_t *)76 bool GAP_GetLeChannelInfo(uint16_t /* gap_handle */, uint16_t* /*remote_mtu */,
77                           uint16_t* /* local_mps */, uint16_t* /* remote_mps */,
78                           uint16_t* /* local_credit */, uint16_t* /* remote_credit */,
79                           uint16_t* /* local_cid */, uint16_t* /* remote_cid */,
80                           uint16_t* /* acl_handle */) {
81   inc_func_call_count(__func__);
82   return false;
83 }
GAP_IsTransportLe(uint16_t)84 bool GAP_IsTransportLe(uint16_t /* gap_handle */) {
85   inc_func_call_count(__func__);
86   return false;
87 }
GAP_Init(void)88 void GAP_Init(void) { inc_func_call_count(__func__); }
89 
90 bluetooth::testing::stack::gap_conn::Interface&
get_interface()91 bluetooth::testing::stack::gap_conn::get_interface() {
92   return *interface_;
93 }
94