• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #pragma once
18 
19 #include <bluetooth/log.h>
20 #include <stdbool.h>
21 
22 #include <cstdint>
23 #include <vector>
24 
25 #include "stack/include/bt_hdr.h"
26 #include "stack/include/l2cap_types.h"
27 #include "types/bt_transport.h"
28 #include "types/hci_role.h"
29 #include "types/raw_address.h"
30 
31 /* result code for L2CA_DataWrite() */
32 enum class tL2CAP_DW_RESULT : uint8_t {
33   FAILED = 0,
34   SUCCESS = 1,
35   CONGESTED = 2,
36 };
37 
38 /*********************************
39  *  Callback Functions Prototypes
40  *********************************/
41 
42 /* Connection indication callback prototype. Parameters are
43  *              BD Address of remote
44  *              Local CID assigned to the connection
45  *              PSM that the remote wants to connect to
46  *              Identifier that the remote sent
47  */
48 typedef void(tL2CA_CONNECT_IND_CB)(const RawAddress&, uint16_t, uint16_t, uint8_t);
49 
50 /* Connection confirmation callback prototype. Parameters are
51  *              Local CID
52  *              Result - 0 = connected
53  *              If there is an error, tL2CA_ERROR_CB is invoked
54  */
55 typedef void(tL2CA_CONNECT_CFM_CB)(uint16_t, tL2CAP_CONN);
56 
57 /* Configuration indication callback prototype. Parameters are
58  *              Local CID assigned to the connection
59  *              Pointer to configuration info
60  */
61 typedef void(tL2CA_CONFIG_IND_CB)(uint16_t, tL2CAP_CFG_INFO*);
62 
63 /* Configuration confirm callback prototype. Parameters are
64  *              Local CID assigned to the connection
65  *              Initiator (1 for local, 0 for remote)
66  *              Initial config from remote
67  * If there is an error, tL2CA_ERROR_CB is invoked
68  */
69 typedef void(tL2CA_CONFIG_CFM_CB)(uint16_t, uint16_t, tL2CAP_CFG_INFO*);
70 
71 /* Disconnect indication callback prototype. Parameters are
72  *              Local CID
73  *              Boolean whether upper layer should ack this
74  */
75 typedef void(tL2CA_DISCONNECT_IND_CB)(uint16_t, bool);
76 
77 /* Disconnect confirm callback prototype. Parameters are
78  *              Local CID
79  *              Result
80  */
81 typedef void(tL2CA_DISCONNECT_CFM_CB)(uint16_t, uint16_t);
82 
83 /* Disconnect confirm callback prototype. Parameters are
84  *              Local CID
85  *              Result
86  */
87 typedef void(tL2CA_DATA_IND_CB)(uint16_t, BT_HDR*);
88 
89 /* Congestion status callback protype. This callback is optional. If
90  * an application tries to send data when the transmit queue is full,
91  * the data will anyways be dropped. The parameter is:
92  *              Local CID
93  *              true if congested, false if uncongested
94  */
95 typedef void(tL2CA_CONGESTION_STATUS_CB)(uint16_t, bool);
96 
97 /* Transmit complete callback protype. This callback is optional. If
98  * set, L2CAP will call it when packets are sent or flushed. If the
99  * count is 0xFFFF, it means all packets are sent for that CID (eRTM
100  * mode only). The parameters are:
101  *              Local CID
102  *              Number of SDUs sent or dropped
103  */
104 typedef void(tL2CA_TX_COMPLETE_CB)(uint16_t, uint16_t);
105 
106 /*
107  * Notify the user when the remote send error result on ConnectRsp or ConfigRsp
108  * The parameters are:
109  *              Local CID
110  *              Error code
111  */
112 typedef void(tL2CA_ERROR_CB)(uint16_t, uint16_t);
113 
114 /* Create credit based connection request callback prototype. Parameters are
115  *              BD Address of remote
116  *              Vector of allocated local cids to accept
117  *              PSM
118  *              Peer MTU
119  *              Identifier that the remote sent
120  */
121 typedef void(tL2CA_CREDIT_BASED_CONNECT_IND_CB)(const RawAddress& bdaddr,
122                                                 std::vector<uint16_t>& lcids, uint16_t psm,
123                                                 uint16_t peer_mtu, uint8_t identifier);
124 
125 /* Collision Indication callback prototype. Used to notify upper layer that
126  * remote devices sent Credit Based Connection Request but it was rejected due
127  * to ongoing local request. Upper layer might want to sent another request when
128  * local request is completed. Parameters are:
129  *              BD Address of remote
130  */
131 typedef void(tL2CA_CREDIT_BASED_COLLISION_IND_CB)(const RawAddress& bdaddr);
132 
133 /* Credit based connection confirmation callback prototype. Parameters are
134  *              BD Address of remote
135  *              Connected Local CIDs
136  *              Peer MTU
137  *              Result - 0 = connected, non-zero means CID is not connected
138  */
139 typedef void(tL2CA_CREDIT_BASED_CONNECT_CFM_CB)(const RawAddress& bdaddr, uint16_t lcid,
140                                                 uint16_t peer_mtu, tL2CAP_LE_RESULT_CODE result);
141 
142 /* Credit based reconfiguration confirm callback prototype. Parameters are
143  *              BD Address of remote
144  *              Local CID assigned to the connection
145  *              Flag indicating if this is local or peer configuration
146  *              Pointer to configuration info
147  */
148 typedef void(tL2CA_CREDIT_BASED_RECONFIG_COMPLETED_CB)(const RawAddress& bdaddr, uint16_t lcid,
149                                                        bool is_local_cfg,
150                                                        tL2CAP_LE_CFG_INFO* p_cfg);
151 
152 /* Define the structure that applications use to register with
153  * L2CAP. This structure includes callback functions. All functions
154  * MUST be provided, with the exception of the "connect pending"
155  * callback and "congestion status" callback.
156  */
157 struct tL2CAP_APPL_INFO {
158   tL2CA_CONNECT_IND_CB* pL2CA_ConnectInd_Cb;
159   tL2CA_CONNECT_CFM_CB* pL2CA_ConnectCfm_Cb;
160   tL2CA_CONFIG_IND_CB* pL2CA_ConfigInd_Cb;
161   tL2CA_CONFIG_CFM_CB* pL2CA_ConfigCfm_Cb;
162   tL2CA_DISCONNECT_IND_CB* pL2CA_DisconnectInd_Cb;
163   tL2CA_DISCONNECT_CFM_CB* pL2CA_DisconnectCfm_Cb;
164   tL2CA_DATA_IND_CB* pL2CA_DataInd_Cb;
165   tL2CA_CONGESTION_STATUS_CB* pL2CA_CongestionStatus_Cb;
166   tL2CA_TX_COMPLETE_CB* pL2CA_TxComplete_Cb;
167   tL2CA_ERROR_CB* pL2CA_Error_Cb;
168   tL2CA_CREDIT_BASED_CONNECT_IND_CB* pL2CA_CreditBasedConnectInd_Cb;
169   tL2CA_CREDIT_BASED_CONNECT_CFM_CB* pL2CA_CreditBasedConnectCfm_Cb;
170   tL2CA_CREDIT_BASED_RECONFIG_COMPLETED_CB* pL2CA_CreditBasedReconfigCompleted_Cb;
171   tL2CA_CREDIT_BASED_COLLISION_IND_CB* pL2CA_CreditBasedCollisionInd_Cb;
172 };
173 
174 /*******************************************************************************
175  *
176  *                      Fixed Channel callback prototypes
177  *
178  ******************************************************************************/
179 
180 /* Fixed channel connected and disconnected. Parameters are
181  *      channel
182  *      BD Address of remote
183  *      true if channel is connected, false if disconnected
184  *      Reason for connection failure
185  *      transport : physical transport, BR/EDR or LE
186  */
187 typedef void(tL2CA_FIXED_CHNL_CB)(uint16_t, const RawAddress&, bool, uint16_t, tBT_TRANSPORT);
188 
189 /* Signalling data received. Parameters are
190  *      channel
191  *      BD Address of remote
192  *      Pointer to buffer with data
193  */
194 typedef void(tL2CA_FIXED_DATA_CB)(uint16_t, const RawAddress&, BT_HDR*);
195 
196 /* Congestion status callback protype. This callback is optional. If
197  * an application tries to send data when the transmit queue is full,
198  * the data will anyways be dropped. The parameter is:
199  *      remote BD_ADDR
200  *      true if congested, false if uncongested
201  */
202 typedef void(tL2CA_FIXED_CONGESTION_STATUS_CB)(const RawAddress&, bool);
203 
204 /* Fixed channel registration info (the callback addresses and channel config)
205  */
206 struct tL2CAP_FIXED_CHNL_REG {
207   tL2CA_FIXED_CHNL_CB* pL2CA_FixedConn_Cb;
208   tL2CA_FIXED_DATA_CB* pL2CA_FixedData_Cb;
209   tL2CA_FIXED_CONGESTION_STATUS_CB* pL2CA_FixedCong_Cb;
210 
211   uint16_t default_idle_tout;
212   tL2CA_TX_COMPLETE_CB* pL2CA_FixedTxComplete_Cb; /* fixed channel tx complete callback */
213 };
214 
215 /*******************************************************************************
216  *
217  *                      Fixed Channel callback prototypes
218  *
219  ******************************************************************************/
220 
221 /* Fixed channel connected and disconnected. Parameters are
222  *      channel
223  *      BD Address of remote
224  *      true if channel is connected, false if disconnected
225  *      Reason for connection failure
226  *      transport : physical transport, BR/EDR or LE
227  */
228 typedef void(tL2CA_FIXED_CHNL_CB)(uint16_t, const RawAddress&, bool, uint16_t, tBT_TRANSPORT);
229 
230 /* Signalling data received. Parameters are
231  *      channel
232  *      BD Address of remote
233  *      Pointer to buffer with data
234  */
235 typedef void(tL2CA_FIXED_DATA_CB)(uint16_t, const RawAddress&, BT_HDR*);
236 
237 /* Congestion status callback protype. This callback is optional. If
238  * an application tries to send data when the transmit queue is full,
239  * the data will anyways be dropped. The parameter is:
240  *      remote BD_ADDR
241  *      true if congested, false if uncongested
242  */
243 typedef void(tL2CA_FIXED_CONGESTION_STATUS_CB)(const RawAddress&, bool);
244 
245 /* Fixed channel registration info (the callback addresses and channel config)
246  */
247 namespace bluetooth {
248 namespace stack {
249 namespace l2cap {
250 
251 class Interface {
252 public:
253   virtual ~Interface() = default;
254 
255   /*******************************************************************************
256    **
257    ** Function         L2CA_Register
258    **
259    ** Description      Register for L2CAP a PSM service.
260    **
261    ** Parameters:      psm: L2cap PSM service to register
262    **                  p_cb_info: Set of l2cap callbacks
263    **                  enable_snoop: Enable to disable snooping on this PSM
264    **                  p_ertm_info:
265    **                  my_mtu:
266    **                  required_remote_mtu:
267    **                  sec_level: Security requirements for connection
268    **
269    ** Returns          PSM to use or zero if error. Typically, the PSM returned
270    **                  is the same as was passed in, but for an outgoing-only
271    **                  connection to a dynamic PSM, a "virtual" PSM is returned
272    **                  and should be used in the calls to L2CA_ConnectReq() and
273    **                  BTM_SetSecurityLevel().
274    **
275    ******************************************************************************/
276   virtual uint16_t L2CA_Register(uint16_t psm, const tL2CAP_APPL_INFO& p_cb_info, bool enable_snoop,
277                                  tL2CAP_ERTM_INFO* p_ertm_info, uint16_t my_mtu,
278                                  uint16_t required_remote_mtu, uint16_t sec_level) = 0;
279   virtual uint16_t L2CA_RegisterWithSecurity(uint16_t psm, const tL2CAP_APPL_INFO& p_cb_info,
280                                              bool enable_snoop, tL2CAP_ERTM_INFO* p_ertm_info,
281                                              uint16_t my_mtu, uint16_t required_remote_mtu,
282                                              uint16_t sec_level) = 0;
283 
284   /*******************************************************************************
285    **
286    ** Function         L2CA_Deregister
287    **
288    ** Description      Other layers call this function to deregister for L2CAP
289    **                  services.
290    **
291    ** Parameters:      psm: L2cap PSM value to deregister
292    **
293    ** Returns          void
294    **
295    ******************************************************************************/
296   virtual void L2CA_Deregister(uint16_t psm) = 0;
297 
298   /*******************************************************************************
299    **
300    ** Function         L2CA_AllocateLePSM
301    **
302    ** Description      Find an unused LE PSM for an L2CAP service.
303    **
304    ** Returns          LE_PSM to use if success. Otherwise returns 0.
305    **
306    ******************************************************************************/
307   virtual uint16_t L2CA_AllocateLePSM(void) = 0;
308 
309   /*******************************************************************************
310    **
311    ** Function         L2CA_FreeLePSM
312    **
313    ** Description      Free an assigned LE PSM.
314    **
315    ** Parameters:      psm: L2cap PSM value to free.
316    **
317    ** Returns          void
318    **
319    ******************************************************************************/
320   virtual void L2CA_FreeLePSM(uint16_t psm) = 0;
321 
322   /*******************************************************************************
323    **
324    ** Function         L2CA_ConnectReq
325    **
326    ** Description      Create an L2CAP connection to a target device requesting
327    **                  the PSM service.
328    **                  Note that the connection is not established at this time,
329    **                  but connection establishment gets started. The callback
330    **                  will be invoked when connection establishes or fails.
331    **
332    ** Parameters:      psm: L2cap PSM on remote to request connection.
333    **                  bd_addr: Remote address of peer connection device.
334    **                  sec_level: Security requirements for connection.
335    **
336    ** Returns          Local CID of the connection, or 0 if it failed to
337    **                  start
338    **
339    ******************************************************************************/
340   virtual uint16_t L2CA_ConnectReq(uint16_t psm, const RawAddress& p_bd_addr) = 0;
341   virtual uint16_t L2CA_ConnectReqWithSecurity(uint16_t psm, const RawAddress& p_bd_addr,
342                                                uint16_t sec_level) = 0;
343 
344   /*******************************************************************************
345    **
346    ** Function         L2CA_RegisterLECoc
347    **
348    ** Description      Register for L2CAP Connection Oriented Channel.
349    **
350    ** Parameters:      psm: L2cap PSM service to register
351    **                  p_cb_info: Set of l2cap callbacks
352    **                  sec_level: Security requirements for connection
353    **                  cfg: Le configuration info.
354    **
355    ** Returns          PSM to use or zero if error. Typically, the PSM returned
356    **                  is the same as was passed in, but for an outgoing-only
357    **                  connection to a dynamic PSM, a "virtual" PSM is returned
358    **                  and should be used in the calls to L2CA_ConnectLECocReq()
359    **                  and BTM_SetSecurityLevel().
360    **
361    ******************************************************************************/
362   virtual uint16_t L2CA_RegisterLECoc(uint16_t psm, const tL2CAP_APPL_INFO& p_cb_info,
363                                       uint16_t sec_level, tL2CAP_LE_CFG_INFO cfg) = 0;
364 
365   /*******************************************************************************
366    **
367    ** Function         L2CA_DeregisterLECoc
368    **
369    ** Description      Other layers call this function to deregister for L2CAP
370    **                  Connection Oriented Channel.
371    **
372    ** Parameters:      psm: L2cap PSM service to deregister
373    **
374    ** Returns          void
375    **
376    ******************************************************************************/
377   virtual void L2CA_DeregisterLECoc(uint16_t psm) = 0;
378 
379   /*******************************************************************************
380    **
381    ** Function         L2CA_ConnectLECocReq
382    **
383    ** Description      Higher layers call this function to create an L2CAP LE
384    **                  COC. Note that the connection is not established at this
385    **                  time, but connection establishment gets started. The
386    **                  callback will be invoked when connection establishes or
387    **                  fails.
388    **
389    ** Parameters:      psm: L2cap PSM service to register
390    **                  bd_addr: Peer bluetooth device address
391    **                  p_cfg: Peer le configuration info
392    **                  sec_level: Security requirements for connection
393    **
394    ** Returns          the CID of the connection, or 0 if it failed to start
395    **
396    ******************************************************************************/
397   virtual uint16_t L2CA_ConnectLECocReq(uint16_t psm, const RawAddress& p_bd_addr,
398                                         tL2CAP_LE_CFG_INFO* p_cfg, uint16_t sec_level) = 0;
399 
400   /*******************************************************************************
401    **
402    ** Function         L2CA_ConnectCreditBasedReq
403    **
404    ** Description      With this function L2CAP will initiate setup of up to 5
405    **                  credit based connections for given psm using provided
406    **                  configuration. L2CAP will notify user on the connection
407    **                  result, by calling pL2CA_CreditBasedConnectCfm_Cb for
408    **                  each cid with a result.
409    **
410    ** Parameters:      psm: PSM of peer service for connection
411    **                  bd_addr: Peer bluetooth device address
412    **                  p_cfg: Peer le configuration info
413    **
414    ** Returns          Local cids allocated for the connection
415    **
416    ******************************************************************************/
417   virtual std::vector<uint16_t> L2CA_ConnectCreditBasedReq(uint16_t psm,
418                                                            const RawAddress& p_bd_addr,
419                                                            tL2CAP_LE_CFG_INFO* p_cfg) = 0;
420 
421   /*******************************************************************************
422    **
423    ** Function         L2CA_GetPeerLECocCredit
424    **
425    ** Description      Get peers current credit for LE Connection Oriented
426    **                  Channel.
427    **
428    ** Parameters:      bd_addr: Peer bluetooth device address
429    **                  lcid: Local l2cap channel id
430    **
431    ** Returns          Number of the peer current credit
432    **
433    ******************************************************************************/
434   virtual uint16_t L2CA_GetPeerLECocCredit(const RawAddress& bd_addr, uint16_t lcid) = 0;
435 
436   /*******************************************************************************
437    **
438    ** Function         L2CA_ReconfigCreditBasedConnsReq
439    **
440    ** Description      Start reconfigure procedure on Connection Oriented
441    **                  Channel.
442    **
443    ** Parameters:      bd_addr: Peer bluetooth device address
444    **                  lcids: Local channel ids for reconfiguration
445    **                  p_cfg: Peer le configuration info
446    **
447    ** Returns          true if peer is connected
448    **
449    ******************************************************************************/
450   virtual bool L2CA_ReconfigCreditBasedConnsReq(const RawAddress& bd_addr,
451                                                 std::vector<uint16_t>& lcids,
452                                                 tL2CAP_LE_CFG_INFO* p_cfg) = 0;
453 
454   /*******************************************************************************
455    **
456    ** Function         L2CA_ConnectCreditBasedRsp
457    **
458    ** Description      Response for the pL2CA_CreditBasedConnectInd_Cb which is
459    **                  the indication for peer requesting credit based
460    **                  connection.
461    **
462    ** Parameters:      bd_addr: Peer bluetooth device address
463    **                  id:
464    **                  accepted_lcids:
465    **                  result:
466    **                  p_cfg: Peer le configuration info
467    **
468    ** Returns          true if peer is connected false otherwise
469    **
470    ******************************************************************************/
471   virtual bool L2CA_ConnectCreditBasedRsp(const RawAddress& p_bd_addr, uint8_t id,
472                                           std::vector<uint16_t>& accepted_lcids,
473                                           tL2CAP_LE_RESULT_CODE result,
474                                           tL2CAP_LE_CFG_INFO* p_cfg) = 0;
475 
476   /*******************************************************************************
477    **
478    ** Function         L2CA_SetIdleTimeoutByBdAddr
479    **
480    ** Description      Higher layers call this function to set the idle timeout
481    **                  for a connection. The "idle timeout" is the amount of
482    *time
483    **                  that a connection can remain up with no L2CAP channels on
484    **                  it. A timeout of zero means that the connection will be
485    **                  torn down immediately when the last channel is removed.
486    **                  A timeout of 0xFFFF means no timeout. Values are in
487    **                  seconds. A bd_addr is the remote BD address. If
488    **                  bd_addr = RawAddress::kAny, then the idle timeouts for
489    **                  all active l2cap links will be changed.
490    **
491    ** Parameters:      bd_addr: Peer bluetooth device address
492    **                  timeout: Timeout value for ACL link
493    **                  transport: Transport to set timeout (BR/EDR or BLE)
494    **
495    ** Returns          true if command succeeded, false if failed
496    **
497    ** NOTE             This timeout applies to all logical channels active on
498    *the
499    **                  ACL link.
500    ******************************************************************************/
501   virtual bool L2CA_SetIdleTimeoutByBdAddr(const RawAddress& bd_addr, uint16_t timeout,
502                                            tBT_TRANSPORT transport) = 0;
503 
504   /*******************************************************************************
505    **
506    ** Function         L2CA_UseLatencyMode
507    **
508    ** Description      Sets use latency mode for an ACL channel.
509    **
510    ** Parameters:      bd_addr: Peer bluetooth device address
511    **                  use_latency_mode: Enable or disable latency mode
512    **
513    ** Returns          true if command succeeded, false if failed
514    **
515    ******************************************************************************/
516   virtual bool L2CA_UseLatencyMode(const RawAddress& bd_addr, bool use_latency_mode) = 0;
517 
518   /*******************************************************************************
519    **
520    ** Function         L2CA_SetAclPriority
521    **
522    ** Description      Sets the transmission priority for an ACL channel.
523    **                  (For initial implementation only two values are valid.
524    **                  L2CAP_PRIORITY_NORMAL and L2CAP_PRIORITY_HIGH).
525    **
526    ** Parameters:      bd_addr: Peer bluetooth device address
527    **                  priority: Priority for ACL to peer
528    **
529    ** Returns          true if command succeeded, false if failed
530    **
531    ******************************************************************************/
532   virtual bool L2CA_SetAclPriority(const RawAddress& bd_addr, tL2CAP_PRIORITY priority) = 0;
533 
534   /*******************************************************************************
535    **
536    ** Function         L2CA_SetAclLatency
537    **
538    ** Description      Sets the transmission latency for a channel.
539    **
540    ** Parameters:      bd_addr: Peer bluetooth device address
541    **                  latency: Latency value for the ACL link
542    **
543    ** Returns          true if command succeeded, false if failed
544    **
545    ******************************************************************************/
546   virtual bool L2CA_SetAclLatency(const RawAddress& bd_addr, tL2CAP_LATENCY latency) = 0;
547 
548   /*******************************************************************************
549    **
550    ** Function         L2CA_GetPeerFeatures
551    **
552    ** Description      Request peer features and fixed channel map
553    **
554    ** Parameters:      bd_addr: Peer bluetooth device address
555    **                  p_ext_feat: Peer features
556    **                  p_chnl_mask: Peer fixed channel map
557    **
558    ** Returns          true if command succeeded, false if failed
559    **
560    ******************************************************************************/
561   virtual bool L2CA_GetPeerFeatures(const RawAddress& bd_addr, uint32_t* p_ext_feat,
562                                     uint8_t* p_chnl_mask) = 0;
563 
564   /*******************************************************************************
565    **
566    ** Function         L2CA_SetLeGattTimeout
567    **
568    ** Description      Higher layers call this function to set the idle timeout
569    **                  for a fixed channel. The "idle timeout" is the amount of
570    **                  time that a connection can remain up with no L2CAP
571    **                  channels on it. A timeout of zero means that the
572    **                  connection will be torn down immediately when the last
573    **                  channel is removed. A timeout of 0xFFFF means no timeout.
574    **                  Values are in seconds. A bd_addr is the remote BD
575    *address.
576    **                  If bd_addr = RawAddress::kAny, then the idle timeouts for
577    **                  all active l2cap links will be changed.
578    **
579    ** Parameters:      bd_addr: Peer bluetooth device address
580    **                  idle_tout: Idle timeout for GATT BLE connection
581    **
582    ** Returns          true if command succeeded, false if failed
583    **
584    ******************************************************************************/
585   virtual bool L2CA_SetLeGattTimeout(const RawAddress& rem_bda, uint16_t idle_tout) = 0;
586 
587   virtual bool L2CA_MarkLeLinkAsActive(const RawAddress& rem_bda) = 0;
588 
589   virtual bool L2CA_UpdateBleConnParams(const RawAddress& rem_bda, uint16_t min_int,
590                                         uint16_t max_int, uint16_t latency, uint16_t timeout,
591                                         uint16_t min_ce_len, uint16_t max_ce_len) = 0;
592 
593   /*******************************************************************************
594    **
595    ** Function         L2CA_LockBleConnParamsForServiceDiscovery
596    **
597    ** Description:     When called with lock=true, LE connection parameters will
598    **                  be locked on fastest value, and we won't accept request
599    **                  to change it from remote. When called with lock=false,
600    **                  parameters are relaxed.
601    **
602    ** Parameters:      bd_addr: Peer bluetooth device address
603    **                  lock: Determines fast or relaxed parameters
604    **
605    ** Returns          void
606    **
607    ******************************************************************************/
608   virtual void L2CA_LockBleConnParamsForServiceDiscovery(const RawAddress& rem_bda, bool lock) = 0;
609 
610   /*******************************************************************************
611    **
612    ** Function         L2CA_LockBleConnParamsForProfileConnection
613    **
614    ** Description:     When called with lock=true, LE connection parameters will
615    **                  be locked on fastest value, and we won't accept request
616    **                  to change it from remote. When called with lock=false,
617    **                  parameters are relaxed.
618    **
619    ** Parameters:      bd_addr: Peer bluetooth device address
620    **                  lock: Determines fast or relaxed parameters
621    **
622    ** Returns          void
623    **
624    ******************************************************************************/
625   virtual void L2CA_LockBleConnParamsForProfileConnection(const RawAddress& rem_bda, bool lock) = 0;
626 
627   /*******************************************************************************
628    **
629    ** Function         L2CA_Consolidate
630    **
631    ** Description      This function consolidates two addresses.
632    **
633    ** Parameters:      identity_addr: Identity address of peer
634    **                  rpa: Resolvable Private Address of peer
635    **
636    ** Returns          void
637    **
638    ******************************************************************************/
639   virtual void L2CA_Consolidate(const RawAddress& identity_addr, const RawAddress& rpa) = 0;
640   virtual tHCI_ROLE L2CA_GetBleConnRole(const RawAddress& bd_addr) = 0;
641   virtual uint16_t L2CA_GetBleConnInterval(const RawAddress& bd_addr) = 0;
642 
643   /*******************************************************************************
644    **
645    ** Function         L2CA_IsLinkEstablished
646    **
647    ** Description      Check if a BR/EDR or BLE link to the remote device is
648    **                  established.
649    **
650    ** Parameters:      bd_addr: Peer bluetooth device address
651    **                  transport: Transport to check (BR/EDR or BLE)
652    **
653    ** Returns          true if peer is connected false otherwise
654    **
655    ******************************************************************************/
656   virtual bool L2CA_IsLinkEstablished(const RawAddress& bd_addr, tBT_TRANSPORT transport) = 0;
657 
658   /*******************************************************************************
659    **
660    ** Function         L2CA_SubrateRequest
661    **
662    ** Description      BLE Subrate request.
663    **
664    ** Parameters:      bd_addr: Peer bluetooth device address
665    **                  Power subrating parameters
666    **
667    ** Return value:    true if update started
668    **
669    ******************************************************************************/
670   virtual bool L2CA_SubrateRequest(const RawAddress& rem_bda, uint16_t subrate_min,
671                                    uint16_t subrate_max, uint16_t max_latency, uint16_t cont_num,
672                                    uint16_t timeout) = 0;
673 
674   /*******************************************************************************
675    **
676    ** Function         L2CA_GetPeerLECocConfig
677    **
678    ** Description      Request peer configuration for LE Connection Oriented
679    **                  Channel.
680    **
681    ** Parameters:      cid: Local channel id of L2CAP connection
682    **                  peer_cfg: Peer LE CoC configuration
683    **
684    ** Return value:    true if peer is connected
685    **
686    ******************************************************************************/
687   virtual bool L2CA_GetPeerLECocConfig(uint16_t cid, tL2CAP_LE_CFG_INFO* peer_cfg) = 0;
688 
689   /*******************************************************************************
690    **
691    ** Function         L2CA_DisconnectReq
692    **
693    ** Description      Higher layers call this function to disconnect a channel.
694    **
695    ** Parameters:      cid: Local channel id of L2CAP connection
696    **
697    ** Returns          true if disconnect sent, else false
698    **
699    ******************************************************************************/
700   virtual bool L2CA_DisconnectReq(uint16_t cid) = 0;
701   virtual bool L2CA_DisconnectLECocReq(uint16_t cid) = 0;
702 
703   /*******************************************************************************
704    **
705    ** Function         L2CA_DataWrite
706    **
707    ** Description      Higher layers call this function to write data.
708    **
709    ** Parameters:      cid: Local channel id of L2CAP connection
710    **                  p_data: Data to write to peer
711    **
712    ** Returns          L2CAP_DW_SUCCESS, if data accepted, else false
713    **                  L2CAP_DW_CONGESTED, if data accepted and the channel is
714    **                                      congested
715    **                  L2CAP_DW_FAILED, if error
716    **
717    ******************************************************************************/
718   virtual tL2CAP_DW_RESULT L2CA_DataWrite(uint16_t cid, BT_HDR* p_data) = 0;
719   virtual tL2CAP_DW_RESULT L2CA_LECocDataWrite(uint16_t cid, BT_HDR* p_data) = 0;
720 
721   /*******************************************************************************
722    **
723    ** Function         L2CA_GetRemoteChannelId
724    **
725    ** Description      Given a local channel identifier, |lcid|, this function
726    **                  returns the bound remote channel identifier, |rcid|. If
727    **                  |lcid| is not known or is invalid, this function returns
728    **                  false and does not modify the value pointed at by |rcid|.
729    **                  |rcid| may be NULL.
730    **
731    ** Parameters:      cid: Local channel id of L2CAP connection
732    **                  rcid: Remote channel id of L2CAP connection
733    **
734    ** Returns          true if remote cid exists, false otherwise
735    **
736    ******************************************************************************/
737   virtual bool L2CA_GetRemoteChannelId(uint16_t cid, uint16_t* rcid) = 0;
738 
739   /*******************************************************************************
740    **
741    ** Function         L2CA_FlushChannel
742    **
743    ** Description      This function flushes none, some or all buffers queued up
744    **                  for xmission for a particular CID. If called with
745    **                  L2CAP_FLUSH_CHANS_GET (0), it simply returns the number
746    **                  of buffers queued for that CID L2CAP_FLUSH_CHANS_ALL
747    **                  (0xffff) flushes all buffers.  All other values specifies
748    **                  the maximum buffers to flush.
749    **
750    ** Parameters:      lcid: Local channel id of L2CAP connection
751    **                  num_to_flush: Number of buffers to flush or
752    **                  L2CAP_FLUSH_CHANS_ALL
753    **
754    ** Returns          Number of buffers left queued for that CID
755    **
756    ******************************************************************************/
757   virtual uint16_t L2CA_FlushChannel(uint16_t cid, uint16_t num_to_flush) = 0;
758 
759   /*******************************************************************************
760    **
761    ** Function         L2CA_SetTxPriority
762    **
763    ** Description      Sets the transmission priority for a channel. (FCR Mode)
764    **
765    ** Parameters:      cid: Local channel id of L2CAP connection
766    **                  priority: L2CAP channel priority
767    **
768    ** Returns          true if a valid channel, else false
769    **
770    ******************************************************************************/
771   virtual bool L2CA_SetTxPriority(uint16_t cid, tL2CAP_CHNL_PRIORITY priority) = 0;
772 
773   /*******************************************************************************
774    *
775    * Function         L2CA_SetChnlFlushability
776    *
777    * Description      Higher layers call this function to set a channels
778    *                  flushability flags
779    *
780    ** Parameters:      cid: Local channel id of L2CAP connection
781    **                  is_flushable: Set or clear flushability flag for channel
782    * Returns          true if CID found, else false
783    *
784    ******************************************************************************/
785   virtual bool L2CA_SetChnlFlushability(uint16_t cid, bool is_flushable) = 0;
786 
787   /*******************************************************************************
788    **
789    **  Function        L2CA_RegisterFixedChannel
790    **
791    **  Description     Register a fixed channel.
792    **
793    **  Parameters:     fixed_cid: Fixed Channel #
794    **                  p_freg: Channel Callbacks and config
795    **
796    **  Return value:   true if registered OK, false otherwise
797    **
798    ******************************************************************************/
799   virtual bool L2CA_RegisterFixedChannel(uint16_t fixed_cid, tL2CAP_FIXED_CHNL_REG* p_freg) = 0;
800 
801   /*******************************************************************************
802    **
803    **  Function        L2CA_ConnectFixedChnl
804    **
805    **  Description     Connect an fixed signalling channel to a remote device.
806    **
807    **  Parameters:     fixed_cid: Fixed CID
808    **                  bd_addr: BD Address of remote
809    **
810    **  Return value:   true if connection started, false otherwise
811    **
812    ******************************************************************************/
813   virtual bool L2CA_ConnectFixedChnl(uint16_t fixed_cid, const RawAddress& bd_addr) = 0;
814 
815   /*******************************************************************************
816    **
817    **  Function        L2CA_SendFixedChnlData
818    **
819    **  Description     Write data on a fixed signalling channel.
820    **
821    **  Parameters:     fixed_cid: Fixed CID
822    **                  bd_addr: BD Address of remote
823    **                  p_buf: Pointer to data buffer
824    **
825    ** Return value     L2CAP_DW_SUCCESS, if data accepted
826    **                  L2CAP_DW_FAILED,  if error
827    **
828    ******************************************************************************/
829   virtual tL2CAP_DW_RESULT L2CA_SendFixedChnlData(uint16_t fixed_cid, const RawAddress& rem_bda,
830                                                   BT_HDR* p_buf) = 0;
831 
832   /*******************************************************************************
833    **
834    **  Function        L2CA_RemoveFixedChnl
835    **
836    **  Description     Remove a fixed channel to a remote device.
837    **
838    **  Parameters:     fixed_cid: Fixed CID
839    **                  bd_addr: Mac address of remote
840    **
841    **  Return value:   true if channel removed, false otherwise
842    **
843    ******************************************************************************/
844   virtual bool L2CA_RemoveFixedChnl(uint16_t fixed_cid, const RawAddress& rem_bda) = 0;
845 
846   /*******************************************************************************
847    **
848    ** Function         L2CA_AdjustConnectionIntervals
849    **
850    ** Description      Adjust connection intervals
851    **
852    ** Parameters:      Connection intervals
853    **
854    ** Return value:    void
855    **
856    ******************************************************************************/
857   virtual void L2CA_AdjustConnectionIntervals(uint16_t* min_interval, uint16_t* max_interval,
858                                               uint16_t floor_interval) = 0;
859 
860   /*******************************************************************************
861    **
862    ** Function         L2CA_SetEcosystemBaseInterval
863    **
864    ** Description      Sets the base ecosystem interval
865    **
866    ** Parameters:      Base interval
867    **
868    ** Return value:    void
869    **
870    ******************************************************************************/
871   virtual void L2CA_SetEcosystemBaseInterval(uint32_t base_interval) = 0;
872 
873   /*******************************************************************************
874    **
875    ** Function         L2CA_SetMediaStreamChannel
876    **
877    ** Description      This function is called to set/reset the ccb of active
878    **                  media streaming channel
879    **
880    **  Parameters:     local_media_cid: The local cid provided to A2DP to be
881    **                    used for streaming
882    **                  status: The status of media streaming on this channel
883    **
884    ** Returns          void
885    **
886    *******************************************************************************/
887   virtual void L2CA_SetMediaStreamChannel(uint16_t local_media_cid, bool status) = 0;
888 
889   /*******************************************************************************
890    **
891    ** Function         L2CA_isMediaChannel
892    **
893    ** Description      This function returns if the channel id passed as
894    **                  parameter is an A2DP streaming channel
895    **
896    **  Parameters:     handle: Connection handle with the remote device
897    **                  channel_id: Channel ID
898    **                  is_local_cid: Signifies if the channel id passed is local
899    **                    cid or remote cid (true if local, remote otherwise)
900    **
901    ** Returns          bool
902    **
903    *******************************************************************************/
904   virtual bool L2CA_isMediaChannel(uint16_t handle, uint16_t channel_id, bool is_local_cid) = 0;
905 
906   /*******************************************************************************
907    **
908    ** Function         L2CA_GetAclHandle
909    **
910    ** Description      Given a local channel identifier, |lcid|, this function
911    **                  returns the handle of the corresponding ACL connection, |acl_handle|. If
912    **                  |lcid| is not known or is invalid, this function returns false and does not
913    **                  modify the value pointed at by |acl_handle|.
914    **
915    ** Parameters:      lcid: Local CID
916    **                  acl_handle: Pointer to ACL handle must NOT be nullptr
917    **
918    ** Returns          true if acl_handle lookup was successful
919    **
920    ******************************************************************************/
921   virtual bool L2CA_GetAclHandle(uint16_t lcid, uint16_t* acl_handle) = 0;
922 
923   /*******************************************************************************
924    **
925    ** Function         L2CA_GetLocalMtu
926    **
927    ** Description      Given a local channel identifier, |lcid|, this function
928    **                  returns the L2CAP local mtu, |local_mtu|. If
929    **                  |lcid| is not known or is invalid, this function returns false and does not
930    **                  modify the value pointed at by |local_mtu|.
931    **
932    ** Parameters:      lcid: Local CID
933    **                  local_mtu: Pointer to L2CAP local mtu must NOT be nullptr
934    **
935    ** Returns          true if local_mtu lookup was successful
936    **
937    ******************************************************************************/
938   virtual bool L2CA_GetLocalMtu(uint16_t lcid, uint16_t* local_mtu) = 0;
939 };
940 
941 Interface& get_interface();
942 
943 }  // namespace l2cap
944 }  // namespace stack
945 }  // namespace bluetooth
946