• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /******************************************************************************
2  *
3  *  Copyright 1999-2012 Broadcom Corporation
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 
19 /******************************************************************************
20  *
21  *  this file contains the L2CAP API definitions
22  *
23  ******************************************************************************/
24 #ifndef L2C_API_H
25 #define L2C_API_H
26 
27 #include <stdbool.h>
28 
29 #include "bt_target.h"
30 #include "hcidefs.h"
31 #include "l2cdefs.h"
32 
33 /*****************************************************************************
34  *  Constants
35  ****************************************************************************/
36 
37 /* Define the minimum offset that L2CAP needs in a buffer. This is made up of
38  * HCI type(1), len(2), handle(2), L2CAP len(2) and CID(2) => 9
39  */
40 #define L2CAP_MIN_OFFSET 13 /* plus control(2), SDU length(2) */
41 
42 #define L2CAP_LCC_SDU_LENGTH 2
43 #define L2CAP_LCC_OFFSET \
44   (L2CAP_MIN_OFFSET + L2CAP_LCC_SDU_LENGTH) /* plus SDU length(2) */
45 
46 #define L2CAP_FCS_LENGTH 2
47 
48 /* ping result codes */
49 #define L2CAP_PING_RESULT_OK 0      /* Ping reply received OK     */
50 #define L2CAP_PING_RESULT_NO_LINK 1 /* Link could not be setup    */
51 #define L2CAP_PING_RESULT_NO_RESP 2 /* Remote L2CAP did not reply */
52 
53 /* result code for L2CA_DataWrite() */
54 #define L2CAP_DW_FAILED false
55 #define L2CAP_DW_SUCCESS true
56 #define L2CAP_DW_CONGESTED 2
57 
58 /* Values for priority parameter to L2CA_SetAclPriority */
59 #define L2CAP_PRIORITY_NORMAL 0
60 #define L2CAP_PRIORITY_HIGH 1
61 
62 /* Values for priority parameter to L2CA_SetTxPriority */
63 #define L2CAP_CHNL_PRIORITY_HIGH 0
64 #define L2CAP_CHNL_PRIORITY_MEDIUM 1
65 #define L2CAP_CHNL_PRIORITY_LOW 2
66 
67 typedef uint8_t tL2CAP_CHNL_PRIORITY;
68 
69 /* Values for Tx/Rx data rate parameter to L2CA_SetChnlDataRate */
70 #define L2CAP_CHNL_DATA_RATE_HIGH 3
71 #define L2CAP_CHNL_DATA_RATE_MEDIUM 2
72 #define L2CAP_CHNL_DATA_RATE_LOW 1
73 #define L2CAP_CHNL_DATA_RATE_NO_TRAFFIC 0
74 
75 typedef uint8_t tL2CAP_CHNL_DATA_RATE;
76 
77 /* Data Packet Flags  (bits 2-15 are reserved) */
78 /* layer specific 14-15 bits are used for FCR SAR */
79 #define L2CAP_FLUSHABLE_MASK 0x0003
80 #define L2CAP_FLUSHABLE_CH_BASED 0x0000
81 #define L2CAP_FLUSHABLE_PKT 0x0001
82 #define L2CAP_NON_FLUSHABLE_PKT 0x0002
83 
84 /* L2CA_FlushChannel num_to_flush definitions */
85 #define L2CAP_FLUSH_CHANS_ALL 0xffff
86 #define L2CAP_FLUSH_CHANS_GET 0x0000
87 
88 /* set this bit to allow switch at create conn */
89 #define L2CAP_ROLE_ALLOW_SWITCH 0x80
90 /* set this bit to disallow switch at create conn */
91 #define L2CAP_ROLE_DISALLOW_SWITCH 0x40
92 #define L2CAP_ROLE_CHECK_SWITCH 0xC0
93 
94 /* Values for 'allowed_modes' field passed in structure tL2CAP_ERTM_INFO
95  */
96 #define L2CAP_FCR_CHAN_OPT_BASIC (1 << L2CAP_FCR_BASIC_MODE)
97 #define L2CAP_FCR_CHAN_OPT_ERTM (1 << L2CAP_FCR_ERTM_MODE)
98 #define L2CAP_FCR_CHAN_OPT_STREAM (1 << L2CAP_FCR_STREAM_MODE)
99 
100 #define L2CAP_FCR_CHAN_OPT_ALL_MASK                     \
101   (L2CAP_FCR_CHAN_OPT_BASIC | L2CAP_FCR_CHAN_OPT_ERTM | \
102    L2CAP_FCR_CHAN_OPT_STREAM)
103 
104 /* Validity check for PSM.  PSM values must be odd.  Also, all PSM values must
105  * be assigned such that the least significant bit of the most sigificant
106  * octet equals zero.
107  */
108 #define L2C_INVALID_PSM(psm) (((psm)&0x0101) != 0x0001)
109 #define L2C_IS_VALID_PSM(psm) (((psm)&0x0101) == 0x0001)
110 #define L2C_IS_VALID_LE_PSM(psm) (((psm) > 0x0000) && ((psm) < 0x0100))
111 
112 /*****************************************************************************
113  *  Type Definitions
114  ****************************************************************************/
115 
116 typedef struct {
117 #define L2CAP_FCR_BASIC_MODE 0x00
118 #define L2CAP_FCR_ERTM_MODE 0x03
119 #define L2CAP_FCR_STREAM_MODE 0x04
120 #define L2CAP_FCR_LE_COC_MODE 0x05
121 
122   uint8_t mode;
123 
124   uint8_t tx_win_sz;
125   uint8_t max_transmit;
126   uint16_t rtrans_tout;
127   uint16_t mon_tout;
128   uint16_t mps;
129 } tL2CAP_FCR_OPTS;
130 
131 /* Define a structure to hold the configuration parameters. Since the
132  * parameters are optional, for each parameter there is a boolean to
133  * use to signify its presence or absence.
134  */
135 typedef struct {
136   uint16_t result; /* Only used in confirm messages */
137   bool mtu_present;
138   uint16_t mtu;
139   bool qos_present;
140   FLOW_SPEC qos;
141   bool flush_to_present;
142   uint16_t flush_to;
143   bool fcr_present;
144   tL2CAP_FCR_OPTS fcr;
145   bool fcs_present; /* Optionally bypasses FCS checks */
146   uint8_t fcs;      /* '0' if desire is to bypass FCS, otherwise '1' */
147   bool ext_flow_spec_present;
148   tHCI_EXT_FLOW_SPEC ext_flow_spec;
149   uint16_t flags; /* bit 0: 0-no continuation, 1-continuation */
150 } tL2CAP_CFG_INFO;
151 
152 /* Define a structure to hold the configuration parameter for LE L2CAP
153  * connection oriented channels.
154  */
155 typedef struct {
156   uint16_t mtu;
157   uint16_t mps;
158   uint16_t credits;
159 } tL2CAP_LE_CFG_INFO;
160 
161 /* L2CAP channel configured field bitmap */
162 #define L2CAP_CH_CFG_MASK_MTU 0x0001
163 #define L2CAP_CH_CFG_MASK_QOS 0x0002
164 #define L2CAP_CH_CFG_MASK_FLUSH_TO 0x0004
165 #define L2CAP_CH_CFG_MASK_FCR 0x0008
166 #define L2CAP_CH_CFG_MASK_FCS 0x0010
167 #define L2CAP_CH_CFG_MASK_EXT_FLOW_SPEC 0x0020
168 
169 typedef uint16_t tL2CAP_CH_CFG_BITS;
170 
171 /*********************************
172  *  Callback Functions Prototypes
173  *********************************/
174 
175 /* Connection indication callback prototype. Parameters are
176  *              BD Address of remote
177  *              Local CID assigned to the connection
178  *              PSM that the remote wants to connect to
179  *              Identifier that the remote sent
180  */
181 typedef void(tL2CA_CONNECT_IND_CB)(const RawAddress&, uint16_t, uint16_t,
182                                    uint8_t);
183 
184 /* Connection confirmation callback prototype. Parameters are
185  *              Local CID
186  *              Result - 0 = connected, non-zero means failure reason
187  */
188 typedef void(tL2CA_CONNECT_CFM_CB)(uint16_t, uint16_t);
189 
190 /* Connection pending callback prototype. Parameters are
191  *              Local CID
192  */
193 typedef void(tL2CA_CONNECT_PND_CB)(uint16_t);
194 
195 /* Configuration indication callback prototype. Parameters are
196  *              Local CID assigned to the connection
197  *              Pointer to configuration info
198  */
199 typedef void(tL2CA_CONFIG_IND_CB)(uint16_t, tL2CAP_CFG_INFO*);
200 
201 /* Configuration confirm callback prototype. Parameters are
202  *              Local CID assigned to the connection
203  *              Pointer to configuration info
204  */
205 typedef void(tL2CA_CONFIG_CFM_CB)(uint16_t, tL2CAP_CFG_INFO*);
206 
207 /* Disconnect indication callback prototype. Parameters are
208  *              Local CID
209  *              Boolean whether upper layer should ack this
210  */
211 typedef void(tL2CA_DISCONNECT_IND_CB)(uint16_t, bool);
212 
213 /* Disconnect confirm callback prototype. Parameters are
214  *              Local CID
215  *              Result
216  */
217 typedef void(tL2CA_DISCONNECT_CFM_CB)(uint16_t, uint16_t);
218 
219 /* QOS Violation indication callback prototype. Parameters are
220  *              BD Address of violating device
221  */
222 typedef void(tL2CA_QOS_VIOLATION_IND_CB)(const RawAddress&);
223 
224 /* Data received indication callback prototype. Parameters are
225  *              Local CID
226  *              Address of buffer
227  */
228 typedef void(tL2CA_DATA_IND_CB)(uint16_t, BT_HDR*);
229 
230 /* Echo response callback prototype. Note that this is not included in the
231  * registration information, but is passed to L2CAP as part of the API to
232  * actually send an echo request. Parameters are
233  *              Result
234  */
235 typedef void(tL2CA_ECHO_RSP_CB)(uint16_t);
236 
237 /* Callback function prototype to pass broadcom specific echo response  */
238 /* to the upper layer                                                   */
239 typedef void(tL2CA_ECHO_DATA_CB)(const RawAddress&, uint16_t, uint8_t*);
240 
241 /* Congestion status callback protype. This callback is optional. If
242  * an application tries to send data when the transmit queue is full,
243  * the data will anyways be dropped. The parameter is:
244  *              Local CID
245  *              true if congested, false if uncongested
246  */
247 typedef void(tL2CA_CONGESTION_STATUS_CB)(uint16_t, bool);
248 
249 /* Callback prototype for number of packets completed events.
250  * This callback notifies the application when Number of Completed Packets
251  * event has been received.
252  * This callback is originally designed for 3DG devices.
253  * The parameter is:
254  *          peer BD_ADDR
255  */
256 typedef void(tL2CA_NOCP_CB)(const RawAddress&);
257 
258 /* Transmit complete callback protype. This callback is optional. If
259  * set, L2CAP will call it when packets are sent or flushed. If the
260  * count is 0xFFFF, it means all packets are sent for that CID (eRTM
261  * mode only). The parameters are:
262  *              Local CID
263  *              Number of SDUs sent or dropped
264  */
265 typedef void(tL2CA_TX_COMPLETE_CB)(uint16_t, uint16_t);
266 
267 /* Callback for receiving credits from the remote device.
268  * |credit_received| parameter represents number of credits received in "LE Flow
269  * Control Credit" packet from the remote. |credit_count| parameter represents
270  * the total available credits, including |credit_received|.
271  */
272 typedef void(tL2CA_CREDITS_RECEIVED_CB)(uint16_t local_cid,
273                                         uint16_t credits_received,
274                                         uint16_t credit_count);
275 
276 /* Define the structure that applications use to register with
277  * L2CAP. This structure includes callback functions. All functions
278  * MUST be provided, with the exception of the "connect pending"
279  * callback and "congestion status" callback.
280  */
281 typedef struct {
282   tL2CA_CONNECT_IND_CB* pL2CA_ConnectInd_Cb;
283   tL2CA_CONNECT_CFM_CB* pL2CA_ConnectCfm_Cb;
284   tL2CA_CONNECT_PND_CB* pL2CA_ConnectPnd_Cb;
285   tL2CA_CONFIG_IND_CB* pL2CA_ConfigInd_Cb;
286   tL2CA_CONFIG_CFM_CB* pL2CA_ConfigCfm_Cb;
287   tL2CA_DISCONNECT_IND_CB* pL2CA_DisconnectInd_Cb;
288   tL2CA_DISCONNECT_CFM_CB* pL2CA_DisconnectCfm_Cb;
289   tL2CA_QOS_VIOLATION_IND_CB* pL2CA_QoSViolationInd_Cb;
290   tL2CA_DATA_IND_CB* pL2CA_DataInd_Cb;
291   tL2CA_CONGESTION_STATUS_CB* pL2CA_CongestionStatus_Cb;
292   tL2CA_TX_COMPLETE_CB* pL2CA_TxComplete_Cb;
293   tL2CA_CREDITS_RECEIVED_CB* pL2CA_CreditsReceived_Cb;
294 } tL2CAP_APPL_INFO;
295 
296 /* Define the structure that applications use to create or accept
297  * connections with enhanced retransmission mode.
298  */
299 typedef struct {
300   uint8_t preferred_mode;
301   uint8_t allowed_modes;
302   uint16_t user_rx_buf_size;
303   uint16_t user_tx_buf_size;
304   uint16_t fcr_rx_buf_size;
305   uint16_t fcr_tx_buf_size;
306 
307 } tL2CAP_ERTM_INFO;
308 
309 /*****************************************************************************
310  *  External Function Declarations
311  ****************************************************************************/
312 
313 /*******************************************************************************
314  *
315  * Function         L2CA_Register
316  *
317  * Description      Other layers call this function to register for L2CAP
318  *                  services.
319  *
320  * Returns          PSM to use or zero if error. Typically, the PSM returned
321  *                  is the same as was passed in, but for an outgoing-only
322  *                  connection to a dynamic PSM, a "virtual" PSM is returned
323  *                  and should be used in the calls to L2CA_ConnectReq() and
324  *                  BTM_SetSecurityLevel().
325  *
326  ******************************************************************************/
327 extern uint16_t L2CA_Register(uint16_t psm, tL2CAP_APPL_INFO* p_cb_info,
328                               bool enable_snoop, tL2CAP_ERTM_INFO* p_ertm_info);
329 
330 /*******************************************************************************
331  *
332  * Function         L2CA_Deregister
333  *
334  * Description      Other layers call this function to deregister for L2CAP
335  *                  services.
336  *
337  * Returns          void
338  *
339  ******************************************************************************/
340 extern void L2CA_Deregister(uint16_t psm);
341 
342 /*******************************************************************************
343  *
344  * Function         L2CA_AllocatePSM
345  *
346  * Description      Other layers call this function to find an unused PSM for
347  *                  L2CAP services.
348  *
349  * Returns          PSM to use.
350  *
351  ******************************************************************************/
352 extern uint16_t L2CA_AllocatePSM(void);
353 
354 /*******************************************************************************
355  *
356  * Function         L2CA_AllocateLePSM
357  *
358  * Description      Other layers call this function to find an unused LE PSM for
359  *                  L2CAP services.
360  *
361  * Returns          LE_PSM to use if success. Otherwise returns 0.
362  *
363  ******************************************************************************/
364 extern uint16_t L2CA_AllocateLePSM(void);
365 
366 /*******************************************************************************
367  *
368  * Function         L2CA_FreeLePSM
369  *
370  * Description      Free an assigned LE PSM.
371  *
372  * Returns          void
373  *
374  ******************************************************************************/
375 extern void L2CA_FreeLePSM(uint16_t psm);
376 
377 /*******************************************************************************
378  *
379  * Function         L2CA_ConnectReq
380  *
381  * Description      Higher layers call this function to create an L2CAP
382  *                  connection.
383  *                  Note that the connection is not established at this time,
384  *                  but connection establishment gets started. The callback
385  *                  will be invoked when connection establishes or fails.
386  *
387  * Returns          the CID of the connection, or 0 if it failed to start
388  *
389  ******************************************************************************/
390 extern uint16_t L2CA_ConnectReq(uint16_t psm, const RawAddress& p_bd_addr);
391 
392 /*******************************************************************************
393  *
394  * Function         L2CA_ConnectRsp
395  *
396  * Description      Higher layers call this function to accept an incoming
397  *                  L2CAP connection, for which they had gotten an connect
398  *                  indication callback.
399  *
400  * Returns          true for success, false for failure
401  *
402  ******************************************************************************/
403 extern bool L2CA_ConnectRsp(const RawAddress& p_bd_addr, uint8_t id,
404                             uint16_t lcid, uint16_t result, uint16_t status);
405 
406 /*******************************************************************************
407  *
408  * Function         L2CA_ErtmConnectReq
409  *
410  * Description      Higher layers call this function to create an L2CAP
411  *                  connection that needs to use Enhanced Retransmission Mode.
412  *                  Note that the connection is not established at this time,
413  *                  but connection establishment gets started. The callback
414  *                  will be invoked when connection establishes or fails.
415  *
416  * Returns          the CID of the connection, or 0 if it failed to start
417  *
418  ******************************************************************************/
419 extern uint16_t L2CA_ErtmConnectReq(uint16_t psm, const RawAddress& p_bd_addr,
420                                     tL2CAP_ERTM_INFO* p_ertm_info);
421 
422 /*******************************************************************************
423  *
424  * Function         L2CA_RegisterLECoc
425  *
426  * Description      Other layers call this function to register for L2CAP
427  *                  Connection Oriented Channel.
428  *
429  * Returns          PSM to use or zero if error. Typically, the PSM returned
430  *                  is the same as was passed in, but for an outgoing-only
431  *                  connection to a dynamic PSM, a "virtual" PSM is returned
432  *                  and should be used in the calls to L2CA_ConnectLECocReq()
433  *                  and BTM_SetSecurityLevel().
434  *
435  ******************************************************************************/
436 extern uint16_t L2CA_RegisterLECoc(uint16_t psm, tL2CAP_APPL_INFO* p_cb_info);
437 
438 /*******************************************************************************
439  *
440  * Function         L2CA_DeregisterLECoc
441  *
442  * Description      Other layers call this function to deregister for L2CAP
443  *                  Connection Oriented Channel.
444  *
445  * Returns          void
446  *
447  ******************************************************************************/
448 extern void L2CA_DeregisterLECoc(uint16_t psm);
449 
450 /*******************************************************************************
451  *
452  * Function         L2CA_ConnectLECocReq
453  *
454  * Description      Higher layers call this function to create an L2CAP LE COC.
455  *                  Note that the connection is not established at this time,
456  *                  but connection establishment gets started. The callback
457  *                  will be invoked when connection establishes or fails.
458  *
459  * Returns          the CID of the connection, or 0 if it failed to start
460  *
461  ******************************************************************************/
462 extern uint16_t L2CA_ConnectLECocReq(uint16_t psm, const RawAddress& p_bd_addr,
463                                      tL2CAP_LE_CFG_INFO* p_cfg);
464 
465 /*******************************************************************************
466  *
467  * Function         L2CA_ConnectLECocRsp
468  *
469  * Description      Higher layers call this function to accept an incoming
470  *                  L2CAP LE COC connection, for which they had gotten a connect
471  *                  indication callback.
472  *
473  * Returns          true for success, false for failure
474  *
475  ******************************************************************************/
476 extern bool L2CA_ConnectLECocRsp(const RawAddress& p_bd_addr, uint8_t id,
477                                  uint16_t lcid, uint16_t result,
478                                  uint16_t status, tL2CAP_LE_CFG_INFO* p_cfg);
479 
480 /*******************************************************************************
481  *
482  *  Function         L2CA_GetPeerLECocConfig
483  *
484  *  Description      Get peers configuration for LE Connection Oriented Channel.
485  *
486  *  Return value:    true if peer is connected
487  *
488  ******************************************************************************/
489 extern bool L2CA_GetPeerLECocConfig(uint16_t lcid,
490                                     tL2CAP_LE_CFG_INFO* peer_cfg);
491 
492 /*******************************************************************************
493  *
494  * Function         L2CA_ErtmConnectRsp
495  *
496  * Description      Higher layers call this function to accept an incoming
497  *                  L2CAP connection, for which they had gotten an connect
498  *                  indication callback, and for which the higher layer wants
499  *                  to use Enhanced Retransmission Mode.
500  *
501  * Returns          true for success, false for failure
502  *
503  ******************************************************************************/
504 extern bool L2CA_ErtmConnectRsp(const RawAddress& p_bd_addr, uint8_t id,
505                                 uint16_t lcid, uint16_t result, uint16_t status,
506                                 tL2CAP_ERTM_INFO* p_ertm_info);
507 
508 /*******************************************************************************
509  *
510  * Function         L2CA_ConfigReq
511  *
512  * Description      Higher layers call this function to send configuration.
513  *
514  * Returns          true if configuration sent, else false
515  *
516  ******************************************************************************/
517 extern bool L2CA_ConfigReq(uint16_t cid, tL2CAP_CFG_INFO* p_cfg);
518 
519 /*******************************************************************************
520  *
521  * Function         L2CA_ConfigRsp
522  *
523  * Description      Higher layers call this function to send a configuration
524  *                  response.
525  *
526  * Returns          true if configuration response sent, else false
527  *
528  ******************************************************************************/
529 extern bool L2CA_ConfigRsp(uint16_t cid, tL2CAP_CFG_INFO* p_cfg);
530 
531 /*******************************************************************************
532  *
533  * Function         L2CA_DisconnectReq
534  *
535  * Description      Higher layers call this function to disconnect a channel.
536  *
537  * Returns          true if disconnect sent, else false
538  *
539  ******************************************************************************/
540 extern bool L2CA_DisconnectReq(uint16_t cid);
541 
542 /*******************************************************************************
543  *
544  * Function         L2CA_DisconnectRsp
545  *
546  * Description      Higher layers call this function to acknowledge the
547  *                  disconnection of a channel.
548  *
549  * Returns          void
550  *
551  ******************************************************************************/
552 extern bool L2CA_DisconnectRsp(uint16_t cid);
553 
554 /*******************************************************************************
555  *
556  * Function         L2CA_DataWrite
557  *
558  * Description      Higher layers call this function to write data.
559  *
560  * Returns          L2CAP_DW_SUCCESS, if data accepted, else false
561  *                  L2CAP_DW_CONGESTED, if data accepted and the channel is
562  *                                      congested
563  *                  L2CAP_DW_FAILED, if error
564  *
565  ******************************************************************************/
566 extern uint8_t L2CA_DataWrite(uint16_t cid, BT_HDR* p_data);
567 
568 // Given a local channel identifier, |lcid|, this function returns the bound
569 // remote channel identifier, |rcid|, and the ACL link handle, |handle|. If
570 // |lcid| is not known or is invalid, this function returns false and does not
571 // modify the values pointed at by |rcid| and |handle|. |rcid| and |handle| may
572 // be NULL.
573 bool L2CA_GetIdentifiers(uint16_t lcid, uint16_t* rcid, uint16_t* handle);
574 
575 /*******************************************************************************
576  *
577  * Function         L2CA_SetIdleTimeout
578  *
579  * Description      Higher layers call this function to set the idle timeout for
580  *                  a connection, or for all future connections. The "idle
581  *                  timeout" is the amount of time that a connection can remain
582  *                  up with no L2CAP channels on it. A timeout of zero means
583  *                  that the connection will be torn down immediately when the
584  *                  last channel is removed. A timeout of 0xFFFF means no
585  *                  timeout. Values are in seconds.
586  *
587  * Returns          true if command succeeded, false if failed
588  *
589  ******************************************************************************/
590 extern bool L2CA_SetIdleTimeout(uint16_t cid, uint16_t timeout, bool is_global);
591 
592 /*******************************************************************************
593  *
594  * Function         L2CA_SetIdleTimeoutByBdAddr
595  *
596  * Description      Higher layers call this function to set the idle timeout for
597  *                  a connection. The "idle timeout" is the amount of time that
598  *                  a connection can remain up with no L2CAP channels on it.
599  *                  A timeout of zero means that the connection will be torn
600  *                  down immediately when the last channel is removed.
601  *                  A timeout of 0xFFFF means no timeout. Values are in seconds.
602  *                  A bd_addr is the remote BD address. If bd_addr =
603  *                  RawAddress::kAny, then the idle timeouts for all active
604  *                  l2cap links will be changed.
605  *
606  * Returns          true if command succeeded, false if failed
607  *
608  * NOTE             This timeout applies to all logical channels active on the
609  *                  ACL link.
610  ******************************************************************************/
611 extern bool L2CA_SetIdleTimeoutByBdAddr(const RawAddress& bd_addr,
612                                         uint16_t timeout,
613                                         tBT_TRANSPORT transport);
614 
615 /*******************************************************************************
616  *
617  * Function         L2CA_SetTraceLevel
618  *
619  * Description      This function sets the trace level for L2CAP. If called with
620  *                  a value of 0xFF, it simply reads the current trace level.
621  *
622  * Returns          the new (current) trace level
623  *
624  ******************************************************************************/
625 extern uint8_t L2CA_SetTraceLevel(uint8_t trace_level);
626 
627 /*******************************************************************************
628  *
629  * Function     L2CA_SetDesireRole
630  *
631  * Description  This function sets the desire role for L2CAP.
632  *              If the new role is L2CAP_ROLE_ALLOW_SWITCH, allow switch on
633  *              HciCreateConnection.
634  *              If the new role is L2CAP_ROLE_DISALLOW_SWITCH, do not allow
635  *              switch on HciCreateConnection.
636  *
637  *              If the new role is a valid role (HCI_ROLE_MASTER or
638  *              HCI_ROLE_SLAVE), the desire role is set to the new value.
639  *              Otherwise, it is not changed.
640  *
641  * Returns      the new (current) role
642  *
643  ******************************************************************************/
644 extern uint8_t L2CA_SetDesireRole(uint8_t new_role);
645 
646 /*******************************************************************************
647  *
648  * Function     L2CA_FlushChannel
649  *
650  * Description  This function flushes none, some or all buffers queued up
651  *              for xmission for a particular CID. If called with
652  *              L2CAP_FLUSH_CHANS_GET (0), it simply returns the number
653  *              of buffers queued for that CID L2CAP_FLUSH_CHANS_ALL (0xffff)
654  *              flushes all buffers.  All other values specifies the maximum
655  *              buffers to flush.
656  *
657  * Returns      Number of buffers left queued for that CID
658  *
659  ******************************************************************************/
660 extern uint16_t L2CA_FlushChannel(uint16_t lcid, uint16_t num_to_flush);
661 
662 /*******************************************************************************
663  *
664  * Function         L2CA_SetAclPriority
665  *
666  * Description      Sets the transmission priority for an ACL channel.
667  *                  (For initial implementation only two values are valid.
668  *                  L2CAP_PRIORITY_NORMAL and L2CAP_PRIORITY_HIGH).
669  *
670  * Returns          true if a valid channel, else false
671  *
672  ******************************************************************************/
673 extern bool L2CA_SetAclPriority(const RawAddress& bd_addr, uint8_t priority);
674 
675 /*******************************************************************************
676  *
677  * Function         L2CA_SetTxPriority
678  *
679  * Description      Sets the transmission priority for a channel. (FCR Mode)
680  *
681  * Returns          true if a valid channel, else false
682  *
683  ******************************************************************************/
684 extern bool L2CA_SetTxPriority(uint16_t cid, tL2CAP_CHNL_PRIORITY priority);
685 
686 /*******************************************************************************
687  *
688  * Function         L2CA_SetFlushTimeout
689  *
690  * Description      This function set the automatic flush time out in Baseband
691  *                  for ACL-U packets.
692  *                  BdAddr : the remote BD address of ACL link. If it is
693  *                           BT_DB_ANY then the flush time out will be applied
694  *                           to all ACL link.
695  *                  FlushTimeout: flush time out in ms
696  *                           0x0000 : No automatic flush
697  *                           L2CAP_NO_RETRANSMISSION : No retransmission
698  *                           0x0002 - 0xFFFE : flush time out, if
699  *                                             (flush_tout * 8) + 3 / 5) <=
700  *                                             HCI_MAX_AUTOMATIC_FLUSH_TIMEOUT
701  *                                             (in 625us slot).
702  *                                    Otherwise, return false.
703  *                           L2CAP_NO_AUTOMATIC_FLUSH : No automatic flush
704  *
705  * Returns          true if command succeeded, false if failed
706  *
707  * NOTE             This flush timeout applies to all logical channels active on
708  *                  the ACL link.
709  ******************************************************************************/
710 extern bool L2CA_SetFlushTimeout(const RawAddress& bd_addr,
711                                  uint16_t flush_tout);
712 
713 /*******************************************************************************
714  *
715  * Function         L2CA_SetChnlFlushability
716  *
717  * Description      Higher layers call this function to set a channels
718  *                  flushability flags
719  *
720  * Returns          true if CID found, else false
721  *
722  ******************************************************************************/
723 extern bool L2CA_SetChnlFlushability(uint16_t cid, bool is_flushable);
724 
725 /*******************************************************************************
726  *
727  *  Function         L2CA_GetPeerFeatures
728  *
729  *  Description      Get a peers features and fixed channel map
730  *
731  *  Parameters:      BD address of the peer
732  *                   Pointers to features and channel mask storage area
733  *
734  *  Return value:    true if peer is connected
735  *
736  ******************************************************************************/
737 extern bool L2CA_GetPeerFeatures(const RawAddress& bd_addr,
738                                  uint32_t* p_ext_feat, uint8_t* p_chnl_mask);
739 
740 /*******************************************************************************
741  *
742  *                      Fixed Channel callback prototypes
743  *
744  ******************************************************************************/
745 
746 /* Fixed channel connected and disconnected. Parameters are
747  *      channel
748  *      BD Address of remote
749  *      true if channel is connected, false if disconnected
750  *      Reason for connection failure
751  *      transport : physical transport, BR/EDR or LE
752  */
753 typedef void(tL2CA_FIXED_CHNL_CB)(uint16_t, const RawAddress&, bool, uint16_t,
754                                   tBT_TRANSPORT);
755 
756 /* Signalling data received. Parameters are
757  *      channel
758  *      BD Address of remote
759  *      Pointer to buffer with data
760  */
761 typedef void(tL2CA_FIXED_DATA_CB)(uint16_t, const RawAddress&, BT_HDR*);
762 
763 /* Congestion status callback protype. This callback is optional. If
764  * an application tries to send data when the transmit queue is full,
765  * the data will anyways be dropped. The parameter is:
766  *      remote BD_ADDR
767  *      true if congested, false if uncongested
768  */
769 typedef void(tL2CA_FIXED_CONGESTION_STATUS_CB)(const RawAddress&, bool);
770 
771 /* Fixed channel registration info (the callback addresses and channel config)
772  */
773 typedef struct {
774   tL2CA_FIXED_CHNL_CB* pL2CA_FixedConn_Cb;
775   tL2CA_FIXED_DATA_CB* pL2CA_FixedData_Cb;
776   tL2CA_FIXED_CONGESTION_STATUS_CB* pL2CA_FixedCong_Cb;
777   tL2CAP_FCR_OPTS fixed_chnl_opts;
778 
779   uint16_t default_idle_tout;
780   tL2CA_TX_COMPLETE_CB*
781       pL2CA_FixedTxComplete_Cb; /* fixed channel tx complete callback */
782 } tL2CAP_FIXED_CHNL_REG;
783 
784 #if (L2CAP_NUM_FIXED_CHNLS > 0)
785 /*******************************************************************************
786  *
787  *  Function        L2CA_RegisterFixedChannel
788  *
789  *  Description     Register a fixed channel.
790  *
791  *  Parameters:     Fixed Channel #
792  *                  Channel Callbacks and config
793  *
794  *  Return value:   true if registered OK
795  *
796  ******************************************************************************/
797 extern bool L2CA_RegisterFixedChannel(uint16_t fixed_cid,
798                                       tL2CAP_FIXED_CHNL_REG* p_freg);
799 
800 /*******************************************************************************
801  *
802  *  Function        L2CA_ConnectFixedChnl
803  *
804  *  Description     Connect an fixed signalling channel to a remote device.
805  *
806  *  Parameters:     Fixed CID
807  *                  BD Address of remote
808  *
809  *  Return value:   true if connection started
810  *
811  ******************************************************************************/
812 extern bool L2CA_ConnectFixedChnl(uint16_t fixed_cid,
813                                   const RawAddress& bd_addr);
814 extern bool L2CA_ConnectFixedChnl(uint16_t fixed_cid, const RawAddress& bd_addr,
815                                   uint8_t initiating_phys);
816 
817 /*******************************************************************************
818  *
819  *  Function        L2CA_SendFixedChnlData
820  *
821  *  Description     Write data on a fixed signalling channel.
822  *
823  *  Parameters:     Fixed CID
824  *                  BD Address of remote
825  *                  Pointer to buffer of type BT_HDR
826  *
827  * Return value     L2CAP_DW_SUCCESS, if data accepted
828  *                  L2CAP_DW_FAILED,  if error
829  *
830  ******************************************************************************/
831 extern uint16_t L2CA_SendFixedChnlData(uint16_t fixed_cid,
832                                        const RawAddress& rem_bda,
833                                        BT_HDR* p_buf);
834 
835 /*******************************************************************************
836  *
837  *  Function        L2CA_RemoveFixedChnl
838  *
839  *  Description     Remove a fixed channel to a remote device.
840  *
841  *  Parameters:     Fixed CID
842  *                  BD Address of remote
843  *                  Idle timeout to use (or 0xFFFF if don't care)
844  *
845  *  Return value:   true if channel removed
846  *
847  ******************************************************************************/
848 extern bool L2CA_RemoveFixedChnl(uint16_t fixed_cid, const RawAddress& rem_bda);
849 
850 /*******************************************************************************
851  *
852  * Function         L2CA_SetFixedChannelTout
853  *
854  * Description      Higher layers call this function to set the idle timeout for
855  *                  a fixed channel. The "idle timeout" is the amount of time
856  *                  that a connection can remain up with no L2CAP channels on
857  *                  it. A timeout of zero means that the connection will be torn
858  *                  down immediately when the last channel is removed.
859  *                  A timeout of 0xFFFF means no timeout. Values are in seconds.
860  *                  A bd_addr is the remote BD address. If bd_addr =
861  *                  RawAddress::kAny, then the idle timeouts for all active
862  *                  l2cap links will be changed.
863  *
864  * Returns          true if command succeeded, false if failed
865  *
866  ******************************************************************************/
867 extern bool L2CA_SetFixedChannelTout(const RawAddress& rem_bda,
868                                      uint16_t fixed_cid, uint16_t idle_tout);
869 
870 #endif /* (L2CAP_NUM_FIXED_CHNLS > 0) */
871 
872 /*******************************************************************************
873  *
874  *  Function        L2CA_CancelBleConnectReq
875  *
876  *  Description     Cancel a pending connection attempt to a BLE device.
877  *
878  *  Parameters:     BD Address of remote
879  *
880  *  Return value:   true if connection was cancelled
881  *
882  ******************************************************************************/
883 extern bool L2CA_CancelBleConnectReq(const RawAddress& rem_bda);
884 
885 /*******************************************************************************
886  *
887  *  Function        L2CA_UpdateBleConnParams
888  *
889  *  Description     Update BLE connection parameters.
890  *
891  *  Parameters:     BD Address of remote
892  *
893  *  Return value:   true if update started
894  *
895  ******************************************************************************/
896 extern bool L2CA_UpdateBleConnParams(const RawAddress& rem_bdRa,
897                                      uint16_t min_int, uint16_t max_int,
898                                      uint16_t latency, uint16_t timeout);
899 extern bool L2CA_UpdateBleConnParams(const RawAddress& rem_bda,
900                                      uint16_t min_int, uint16_t max_int,
901                                      uint16_t latency, uint16_t timeout,
902                                      uint16_t min_ce_len, uint16_t max_ce_len);
903 
904 /*******************************************************************************
905  *
906  *  Function        L2CA_EnableUpdateBleConnParams
907  *
908  *  Description     Update BLE connection parameters.
909  *
910  *  Parameters:     BD Address of remote
911  *                  enable flag
912  *
913  *  Return value:   true if update started
914  *
915  ******************************************************************************/
916 extern bool L2CA_EnableUpdateBleConnParams(const RawAddress& rem_bda,
917                                            bool enable);
918 
919 /*******************************************************************************
920  *
921  * Function         L2CA_GetBleConnRole
922  *
923  * Description      This function returns the connection role.
924  *
925  * Returns          link role.
926  *
927  ******************************************************************************/
928 extern uint8_t L2CA_GetBleConnRole(const RawAddress& bd_addr);
929 
930 /*******************************************************************************
931  *
932  * Function         L2CA_GetDisconnectReason
933  *
934  * Description      This function returns the disconnect reason code.
935  *
936  *  Parameters:     BD Address of remote
937  *                  Physical transport for the L2CAP connection (BR/EDR or LE)
938  *
939  * Returns          disconnect reason
940  *
941  ******************************************************************************/
942 extern uint16_t L2CA_GetDisconnectReason(const RawAddress& remote_bda,
943                                          tBT_TRANSPORT transport);
944 
945 extern void L2CA_AdjustConnectionIntervals(uint16_t* min_interval,
946                                            uint16_t* max_interval,
947                                            uint16_t floor_interval);
948 #endif /* L2C_API_H */
949