1 /*
2  * Copyright 2024 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 "stack/include/l2cap_interface.h"
18 #include "stack/l2cap/internal/l2c_api.h"
19 #include "stack/l2cap/l2c_api.h"
20 
21 static bluetooth::stack::l2cap::Impl l2cap_impl;
22 static bluetooth::stack::l2cap::Interface* interface_ = &l2cap_impl;
23 
get_interface()24 bluetooth::stack::l2cap::Interface& bluetooth::stack::l2cap::get_interface() { return *interface_; }
25 
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)26 [[nodiscard]] uint16_t bluetooth::stack::l2cap::Impl::L2CA_Register(
27         uint16_t psm, const tL2CAP_APPL_INFO& p_cb_info, bool enable_snoop,
28         tL2CAP_ERTM_INFO* p_ertm_info, uint16_t my_mtu, uint16_t required_remote_mtu,
29         uint16_t sec_level) {
30   return ::L2CA_Register(psm, p_cb_info, enable_snoop, p_ertm_info, my_mtu, required_remote_mtu,
31                          sec_level);
32 }
33 
L2CA_RegisterWithSecurity(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)34 [[nodiscard]] uint16_t bluetooth::stack::l2cap::Impl::L2CA_RegisterWithSecurity(
35         uint16_t psm, const tL2CAP_APPL_INFO& p_cb_info, bool enable_snoop,
36         tL2CAP_ERTM_INFO* p_ertm_info, uint16_t my_mtu, uint16_t required_remote_mtu,
37         uint16_t sec_level) {
38   return ::L2CA_RegisterWithSecurity(psm, p_cb_info, enable_snoop, p_ertm_info, my_mtu,
39                                      required_remote_mtu, sec_level);
40 }
41 
L2CA_Deregister(uint16_t psm)42 void bluetooth::stack::l2cap::Impl::L2CA_Deregister(uint16_t psm) { ::L2CA_Deregister(psm); }
43 
L2CA_AllocateLePSM(void)44 [[nodiscard]] uint16_t bluetooth::stack::l2cap::Impl::L2CA_AllocateLePSM(void) {
45   return ::L2CA_AllocateLePSM();
46 }
47 
L2CA_FreeLePSM(uint16_t psm)48 void bluetooth::stack::l2cap::Impl::L2CA_FreeLePSM(uint16_t psm) { return ::L2CA_FreeLePSM(psm); }
49 
L2CA_ConnectReq(uint16_t psm,const RawAddress & p_bd_addr)50 [[nodiscard]] uint16_t bluetooth::stack::l2cap::Impl::L2CA_ConnectReq(uint16_t psm,
51                                                                       const RawAddress& p_bd_addr) {
52   return ::L2CA_ConnectReq(psm, p_bd_addr);
53 }
54 
L2CA_ConnectReqWithSecurity(uint16_t psm,const RawAddress & p_bd_addr,uint16_t sec_level)55 [[nodiscard]] uint16_t bluetooth::stack::l2cap::Impl::L2CA_ConnectReqWithSecurity(
56         uint16_t psm, const RawAddress& p_bd_addr, uint16_t sec_level) {
57   return ::L2CA_ConnectReqWithSecurity(psm, p_bd_addr, sec_level);
58 }
59 
L2CA_RegisterLECoc(uint16_t psm,const tL2CAP_APPL_INFO & p_cb_info,uint16_t sec_level,tL2CAP_LE_CFG_INFO cfg)60 [[nodiscard]] uint16_t bluetooth::stack::l2cap::Impl::L2CA_RegisterLECoc(
61         uint16_t psm, const tL2CAP_APPL_INFO& p_cb_info, uint16_t sec_level,
62         tL2CAP_LE_CFG_INFO cfg) {
63   return ::L2CA_RegisterLECoc(psm, p_cb_info, sec_level, cfg);
64 }
65 
L2CA_DeregisterLECoc(uint16_t psm)66 void bluetooth::stack::l2cap::Impl::L2CA_DeregisterLECoc(uint16_t psm) {
67   ::L2CA_DeregisterLECoc(psm);
68 }
69 
L2CA_ConnectLECocReq(uint16_t psm,const RawAddress & p_bd_addr,tL2CAP_LE_CFG_INFO * p_cfg,uint16_t sec_level)70 [[nodiscard]] uint16_t bluetooth::stack::l2cap::Impl::L2CA_ConnectLECocReq(
71         uint16_t psm, const RawAddress& p_bd_addr, tL2CAP_LE_CFG_INFO* p_cfg, uint16_t sec_level) {
72   return ::L2CA_ConnectLECocReq(psm, p_bd_addr, p_cfg, sec_level);
73 }
74 
L2CA_GetPeerLECocConfig(uint16_t lcid,tL2CAP_LE_CFG_INFO * peer_cfg)75 [[nodiscard]] bool bluetooth::stack::l2cap::Impl::L2CA_GetPeerLECocConfig(
76         uint16_t lcid, tL2CAP_LE_CFG_INFO* peer_cfg) {
77   return ::L2CA_GetPeerLECocConfig(lcid, peer_cfg);
78 }
79 
L2CA_GetPeerLECocCredit(const RawAddress & bd_addr,uint16_t lcid)80 [[nodiscard]] uint16_t bluetooth::stack::l2cap::Impl::L2CA_GetPeerLECocCredit(
81         const RawAddress& bd_addr, uint16_t lcid) {
82   return ::L2CA_GetPeerLECocCredit(bd_addr, lcid);
83 }
84 
L2CA_ReconfigCreditBasedConnsReq(const RawAddress & bd_addr,std::vector<uint16_t> & lcids,tL2CAP_LE_CFG_INFO * p_cfg)85 [[nodiscard]] bool bluetooth::stack::l2cap::Impl::L2CA_ReconfigCreditBasedConnsReq(
86         const RawAddress& bd_addr, std::vector<uint16_t>& lcids, tL2CAP_LE_CFG_INFO* p_cfg) {
87   return ::L2CA_ReconfigCreditBasedConnsReq(bd_addr, lcids, p_cfg);
88 }
89 
L2CA_ConnectCreditBasedReq(uint16_t psm,const RawAddress & p_bd_addr,tL2CAP_LE_CFG_INFO * p_cfg)90 [[nodiscard]] std::vector<uint16_t> bluetooth::stack::l2cap::Impl::L2CA_ConnectCreditBasedReq(
91         uint16_t psm, const RawAddress& p_bd_addr, tL2CAP_LE_CFG_INFO* p_cfg) {
92   return ::L2CA_ConnectCreditBasedReq(psm, p_bd_addr, p_cfg);
93 }
94 
L2CA_ConnectCreditBasedRsp(const RawAddress & p_bd_addr,uint8_t id,std::vector<uint16_t> & accepted_lcids,tL2CAP_LE_RESULT_CODE result,tL2CAP_LE_CFG_INFO * p_cfg)95 [[nodiscard]] bool bluetooth::stack::l2cap::Impl::L2CA_ConnectCreditBasedRsp(
96         const RawAddress& p_bd_addr, uint8_t id, std::vector<uint16_t>& accepted_lcids,
97         tL2CAP_LE_RESULT_CODE result, tL2CAP_LE_CFG_INFO* p_cfg) {
98   return ::L2CA_ConnectCreditBasedRsp(p_bd_addr, id, accepted_lcids, result, p_cfg);
99 }
100 
L2CA_DisconnectReq(uint16_t cid)101 [[nodiscard]] bool bluetooth::stack::l2cap::Impl::L2CA_DisconnectReq(uint16_t cid) {
102   return ::L2CA_DisconnectReq(cid);
103 }
104 
L2CA_DisconnectLECocReq(uint16_t cid)105 [[nodiscard]] bool bluetooth::stack::l2cap::Impl::L2CA_DisconnectLECocReq(uint16_t cid) {
106   return ::L2CA_DisconnectLECocReq(cid);
107 }
108 
L2CA_DataWrite(uint16_t cid,BT_HDR * p_data)109 [[nodiscard]] tL2CAP_DW_RESULT bluetooth::stack::l2cap::Impl::L2CA_DataWrite(uint16_t cid,
110                                                                              BT_HDR* p_data) {
111   return ::L2CA_DataWrite(cid, p_data);
112 }
113 
L2CA_LECocDataWrite(uint16_t cid,BT_HDR * p_data)114 [[nodiscard]] tL2CAP_DW_RESULT bluetooth::stack::l2cap::Impl::L2CA_LECocDataWrite(uint16_t cid,
115                                                                                   BT_HDR* p_data) {
116   return ::L2CA_LECocDataWrite(cid, p_data);
117 }
118 
L2CA_SetIdleTimeoutByBdAddr(const RawAddress & bd_addr,uint16_t timeout,tBT_TRANSPORT transport)119 [[nodiscard]] bool bluetooth::stack::l2cap::Impl::L2CA_SetIdleTimeoutByBdAddr(
120         const RawAddress& bd_addr, uint16_t timeout, tBT_TRANSPORT transport) {
121   return ::L2CA_SetIdleTimeoutByBdAddr(bd_addr, timeout, transport);
122 }
123 
L2CA_FlushChannel(uint16_t lcid,uint16_t num_to_flush)124 [[nodiscard]] uint16_t bluetooth::stack::l2cap::Impl::L2CA_FlushChannel(uint16_t lcid,
125                                                                         uint16_t num_to_flush) {
126   return ::L2CA_FlushChannel(lcid, num_to_flush);
127 }
128 
L2CA_UseLatencyMode(const RawAddress & bd_addr,bool use_latency_mode)129 [[nodiscard]] bool bluetooth::stack::l2cap::Impl::L2CA_UseLatencyMode(const RawAddress& bd_addr,
130                                                                       bool use_latency_mode) {
131   return ::L2CA_UseLatencyMode(bd_addr, use_latency_mode);
132 }
133 
L2CA_SetAclPriority(const RawAddress & bd_addr,tL2CAP_PRIORITY priority)134 [[nodiscard]] bool bluetooth::stack::l2cap::Impl::L2CA_SetAclPriority(const RawAddress& bd_addr,
135                                                                       tL2CAP_PRIORITY priority) {
136   return ::L2CA_SetAclPriority(bd_addr, priority);
137 }
138 
L2CA_SetAclLatency(const RawAddress & bd_addr,tL2CAP_LATENCY latency)139 [[nodiscard]] bool bluetooth::stack::l2cap::Impl::L2CA_SetAclLatency(const RawAddress& bd_addr,
140                                                                      tL2CAP_LATENCY latency) {
141   return ::L2CA_SetAclLatency(bd_addr, latency);
142 }
143 
L2CA_SetTxPriority(uint16_t cid,tL2CAP_CHNL_PRIORITY priority)144 [[nodiscard]] bool bluetooth::stack::l2cap::Impl::L2CA_SetTxPriority(
145         uint16_t cid, tL2CAP_CHNL_PRIORITY priority) {
146   return ::L2CA_SetTxPriority(cid, priority);
147 }
148 
L2CA_SetChnlFlushability(uint16_t cid,bool is_flushable)149 [[nodiscard]] bool bluetooth::stack::l2cap::Impl::L2CA_SetChnlFlushability(uint16_t cid,
150                                                                            bool is_flushable) {
151   return ::L2CA_SetChnlFlushability(cid, is_flushable);
152 }
153 
L2CA_GetPeerFeatures(const RawAddress & bd_addr,uint32_t * p_ext_feat,uint8_t * p_chnl_mask)154 [[nodiscard]] bool bluetooth::stack::l2cap::Impl::L2CA_GetPeerFeatures(const RawAddress& bd_addr,
155                                                                        uint32_t* p_ext_feat,
156                                                                        uint8_t* p_chnl_mask) {
157   return ::L2CA_GetPeerFeatures(bd_addr, p_ext_feat, p_chnl_mask);
158 }
159 
L2CA_RegisterFixedChannel(uint16_t fixed_cid,tL2CAP_FIXED_CHNL_REG * p_freg)160 [[nodiscard]] bool bluetooth::stack::l2cap::Impl::L2CA_RegisterFixedChannel(
161         uint16_t fixed_cid, tL2CAP_FIXED_CHNL_REG* p_freg) {
162   return ::L2CA_RegisterFixedChannel(fixed_cid, p_freg);
163 }
164 
L2CA_ConnectFixedChnl(uint16_t fixed_cid,const RawAddress & bd_addr)165 [[nodiscard]] bool bluetooth::stack::l2cap::Impl::L2CA_ConnectFixedChnl(uint16_t fixed_cid,
166                                                                         const RawAddress& bd_addr) {
167   return ::L2CA_ConnectFixedChnl(fixed_cid, bd_addr);
168 }
169 
L2CA_SendFixedChnlData(uint16_t fixed_cid,const RawAddress & rem_bda,BT_HDR * p_buf)170 [[nodiscard]] tL2CAP_DW_RESULT bluetooth::stack::l2cap::Impl::L2CA_SendFixedChnlData(
171         uint16_t fixed_cid, const RawAddress& rem_bda, BT_HDR* p_buf) {
172   return ::L2CA_SendFixedChnlData(fixed_cid, rem_bda, p_buf);
173 }
174 
L2CA_RemoveFixedChnl(uint16_t fixed_cid,const RawAddress & rem_bda)175 [[nodiscard]] bool bluetooth::stack::l2cap::Impl::L2CA_RemoveFixedChnl(uint16_t fixed_cid,
176                                                                        const RawAddress& rem_bda) {
177   return ::L2CA_RemoveFixedChnl(fixed_cid, rem_bda);
178 }
179 
L2CA_SetLeGattTimeout(const RawAddress & rem_bda,uint16_t idle_tout)180 [[nodiscard]] bool bluetooth::stack::l2cap::Impl::L2CA_SetLeGattTimeout(const RawAddress& rem_bda,
181                                                                         uint16_t idle_tout) {
182   return ::L2CA_SetLeGattTimeout(rem_bda, idle_tout);
183 }
184 
L2CA_MarkLeLinkAsActive(const RawAddress & rem_bda)185 [[nodiscard]] bool bluetooth::stack::l2cap::Impl::L2CA_MarkLeLinkAsActive(
186         const RawAddress& rem_bda) {
187   return ::L2CA_MarkLeLinkAsActive(rem_bda);
188 }
189 
L2CA_UpdateBleConnParams(const RawAddress & rem_bda,uint16_t min_int,uint16_t max_int,uint16_t latency,uint16_t timeout,uint16_t min_ce_len,uint16_t max_ce_len)190 [[nodiscard]] bool bluetooth::stack::l2cap::Impl::L2CA_UpdateBleConnParams(
191         const RawAddress& rem_bda, uint16_t min_int, uint16_t max_int, uint16_t latency,
192         uint16_t timeout, uint16_t min_ce_len, uint16_t max_ce_len) {
193   return ::L2CA_UpdateBleConnParams(rem_bda, min_int, max_int, latency, timeout, min_ce_len,
194                                     max_ce_len);
195 }
196 
L2CA_LockBleConnParamsForServiceDiscovery(const RawAddress & rem_bda,bool lock)197 void bluetooth::stack::l2cap::Impl::L2CA_LockBleConnParamsForServiceDiscovery(
198         const RawAddress& rem_bda, bool lock) {
199   ::L2CA_LockBleConnParamsForServiceDiscovery(rem_bda, lock);
200 }
201 
L2CA_LockBleConnParamsForProfileConnection(const RawAddress & rem_bda,bool lock)202 void bluetooth::stack::l2cap::Impl::L2CA_LockBleConnParamsForProfileConnection(
203         const RawAddress& rem_bda, bool lock) {
204   ::L2CA_LockBleConnParamsForProfileConnection(rem_bda, lock);
205 }
206 
L2CA_Consolidate(const RawAddress & identity_addr,const RawAddress & rpa)207 void bluetooth::stack::l2cap::Impl::L2CA_Consolidate(const RawAddress& identity_addr,
208                                                      const RawAddress& rpa) {
209   ::L2CA_Consolidate(identity_addr, rpa);
210 }
211 
L2CA_GetBleConnRole(const RawAddress & bd_addr)212 [[nodiscard]] tHCI_ROLE bluetooth::stack::l2cap::Impl::L2CA_GetBleConnRole(
213         const RawAddress& bd_addr) {
214   return ::L2CA_GetBleConnRole(bd_addr);
215 }
216 
L2CA_AdjustConnectionIntervals(uint16_t * min_interval,uint16_t * max_interval,uint16_t floor_interval)217 void bluetooth::stack::l2cap::Impl::L2CA_AdjustConnectionIntervals(uint16_t* min_interval,
218                                                                    uint16_t* max_interval,
219                                                                    uint16_t floor_interval) {
220   ::L2CA_AdjustConnectionIntervals(min_interval, max_interval, floor_interval);
221 }
222 
L2CA_SetEcosystemBaseInterval(uint32_t base_interval)223 void bluetooth::stack::l2cap::Impl::L2CA_SetEcosystemBaseInterval(uint32_t base_interval) {
224   ::L2CA_SetEcosystemBaseInterval(base_interval);
225 }
226 
L2CA_IsLinkEstablished(const RawAddress & bd_addr,tBT_TRANSPORT transport)227 [[nodiscard]] bool bluetooth::stack::l2cap::Impl::L2CA_IsLinkEstablished(const RawAddress& bd_addr,
228                                                                          tBT_TRANSPORT transport) {
229   return ::L2CA_IsLinkEstablished(bd_addr, transport);
230 }
231 
L2CA_SetDefaultSubrate(uint16_t subrate_min,uint16_t subrate_max,uint16_t max_latency,uint16_t cont_num,uint16_t timeout)232 void bluetooth::stack::l2cap::Impl::L2CA_SetDefaultSubrate(uint16_t subrate_min,
233                                                            uint16_t subrate_max,
234                                                            uint16_t max_latency, uint16_t cont_num,
235                                                            uint16_t timeout) {
236   ::L2CA_SetDefaultSubrate(subrate_min, subrate_max, max_latency, cont_num, timeout);
237 }
238 
L2CA_SubrateRequest(const RawAddress & rem_bda,uint16_t subrate_min,uint16_t subrate_max,uint16_t max_latency,uint16_t cont_num,uint16_t timeout)239 [[nodiscard]] bool bluetooth::stack::l2cap::Impl::L2CA_SubrateRequest(
240         const RawAddress& rem_bda, uint16_t subrate_min, uint16_t subrate_max, uint16_t max_latency,
241         uint16_t cont_num, uint16_t timeout) {
242   return ::L2CA_SubrateRequest(rem_bda, subrate_min, subrate_max, max_latency, cont_num, timeout);
243 }
244 
L2CA_SetMediaStreamChannel(uint16_t local_media_cid,bool status)245 void bluetooth::stack::l2cap::Impl::L2CA_SetMediaStreamChannel(uint16_t local_media_cid,
246                                                                bool status) {
247   ::L2CA_SetMediaStreamChannel(local_media_cid, status);
248 }
249 
L2CA_isMediaChannel(uint16_t handle,uint16_t channel_id,bool is_local_cid)250 [[nodiscard]] bool bluetooth::stack::l2cap::Impl::L2CA_isMediaChannel(uint16_t handle,
251                                                                       uint16_t channel_id,
252                                                                       bool is_local_cid) {
253   return ::L2CA_isMediaChannel(handle, channel_id, is_local_cid);
254 }
255 
L2CA_GetRemoteChannelId(uint16_t lcid,uint16_t * rcid)256 [[nodiscard]] bool bluetooth::stack::l2cap::Impl::L2CA_GetRemoteChannelId(uint16_t lcid,
257                                                                           uint16_t* rcid) {
258   return ::L2CA_GetRemoteChannelId(lcid, rcid);
259 }
260 
L2CA_GetAclHandle(uint16_t lcid,uint16_t * acl_handle)261 [[nodiscard]] bool bluetooth::stack::l2cap::Impl::L2CA_GetAclHandle(uint16_t lcid,
262                                                                     uint16_t* acl_handle) {
263   return ::L2CA_GetAclHandle(lcid, acl_handle);
264 }
265