1 /******************************************************************************
3 * Copyright (C) 1999-2012 Broadcom Corporation
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:
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 ******************************************************************************/
19 /******************************************************************************
21 * this file contains the L2CAP API definitions
23 ******************************************************************************/
29 #include "bt_target.h"
33 /*****************************************************************************
35 *****************************************************************************/
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
40 #define L2CAP_MIN_OFFSET 13 /* plus control(2), SDU length(2) */
42 /* Minimum offset for broadcast needs another two bytes for the PSM */
43 #define L2CAP_BCST_MIN_OFFSET 11
45 /* ping result codes */
46 #define L2CAP_PING_RESULT_OK 0 /* Ping reply received OK */
47 #define L2CAP_PING_RESULT_NO_LINK 1 /* Link could not be setup */
48 #define L2CAP_PING_RESULT_NO_RESP 2 /* Remote L2CAP did not reply */
50 /* result code for L2CA_DataWrite() */
51 #define L2CAP_DW_FAILED FALSE
52 #define L2CAP_DW_SUCCESS TRUE
53 #define L2CAP_DW_CONGESTED 2
55 /* Values for priority parameter to L2CA_SetAclPriority */
56 #define L2CAP_PRIORITY_NORMAL 0
57 #define L2CAP_PRIORITY_HIGH 1
59 /* Values for priority parameter to L2CA_SetTxPriority */
60 #define L2CAP_CHNL_PRIORITY_HIGH 0
61 #define L2CAP_CHNL_PRIORITY_MEDIUM 1
62 #define L2CAP_CHNL_PRIORITY_LOW 2
64 typedef UINT8 tL2CAP_CHNL_PRIORITY;
66 /* Values for Tx/Rx data rate parameter to L2CA_SetChnlDataRate */
67 #define L2CAP_CHNL_DATA_RATE_HIGH 3
68 #define L2CAP_CHNL_DATA_RATE_MEDIUM 2
69 #define L2CAP_CHNL_DATA_RATE_LOW 1
70 #define L2CAP_CHNL_DATA_RATE_NO_TRAFFIC 0
72 typedef UINT8 tL2CAP_CHNL_DATA_RATE;
74 /* Data Packet Flags (bits 2-15 are reserved) */
75 /* layer specific 14-15 bits are used for FCR SAR */
76 #define L2CAP_FLUSHABLE_MASK 0x0003
77 #define L2CAP_FLUSHABLE_CH_BASED 0x0000
78 #define L2CAP_FLUSHABLE_PKT 0x0001
79 #define L2CAP_NON_FLUSHABLE_PKT 0x0002
82 /* L2CA_FlushChannel num_to_flush definitions */
83 #define L2CAP_FLUSH_CHANS_ALL 0xffff
84 #define L2CAP_FLUSH_CHANS_GET 0x0000
87 /* special CID for Multi-AV for reporting congestion */
88 #define L2CAP_MULTI_AV_CID 0
90 /* length of the HCI header block */
91 /* HCI header(4) + SNK count(1) + FCR bits(1) + AV data length(2) */
92 #define L2CAP_MULTI_AV_HCI_HDR_LEN 8
94 /* length of padding for 4 bytes align */
95 #define L2CAP_MULTI_AV_PADDING_LEN 2
97 /* length of the HCI header block with padding for FCR */
98 /* HCI header(4) + SNK count(1) + FCR bits(1) + AV data length(2) + padding(2) */
99 #define L2CAP_MULTI_AV_HCI_HDR_LEN_WITH_PADDING 10
101 /* length of the L2CAP header block */
102 /* HCI header(4) + L2CAP header(4) + padding(4) or control word(2) + FCS(2) */
103 #define L2CAP_MULTI_AV_L2C_HDR_LEN 12
105 /* definition used for L2CA_SetDesireRole */
106 #define L2CAP_ROLE_SLAVE HCI_ROLE_SLAVE
107 #define L2CAP_ROLE_MASTER HCI_ROLE_MASTER
108 #define L2CAP_ROLE_ALLOW_SWITCH 0x80 /* set this bit to allow switch at create conn */
109 #define L2CAP_ROLE_DISALLOW_SWITCH 0x40 /* set this bit to disallow switch at create conn */
110 #define L2CAP_ROLE_CHECK_SWITCH 0xC0
113 /* Values for 'allowed_modes' field passed in structure tL2CAP_ERTM_INFO
115 #define L2CAP_FCR_CHAN_OPT_BASIC (1 << L2CAP_FCR_BASIC_MODE)
116 #define L2CAP_FCR_CHAN_OPT_ERTM (1 << L2CAP_FCR_ERTM_MODE)
117 #define L2CAP_FCR_CHAN_OPT_STREAM (1 << L2CAP_FCR_STREAM_MODE)
119 #define L2CAP_FCR_CHAN_OPT_ALL_MASK (L2CAP_FCR_CHAN_OPT_BASIC | L2CAP_FCR_CHAN_OPT_ERTM | L2CAP_FCR_CHAN_OPT_STREAM)
121 /* Validity check for PSM. PSM values must be odd. Also, all PSM values must
122 ** be assigned such that the least significant bit of the most sigificant
123 ** octet equals zero.
125 #define L2C_INVALID_PSM(psm) (((psm) & 0x0101) != 0x0001)
126 #define L2C_IS_VALID_PSM(psm) (((psm) & 0x0101) == 0x0001)
128 /*****************************************************************************
130 *****************************************************************************/
134 #define L2CAP_FCR_BASIC_MODE 0x00
135 #define L2CAP_FCR_ERTM_MODE 0x03
136 #define L2CAP_FCR_STREAM_MODE 0x04
147 /* Define a structure to hold the configuration parameters. Since the
148 ** parameters are optional, for each parameter there is a boolean to
149 ** use to signify its presence or absence.
153 UINT16 result; /* Only used in confirm messages */
158 BOOLEAN flush_to_present;
162 BOOLEAN fcs_present; /* Optionally bypasses FCS checks */
163 UINT8 fcs; /* '0' if desire is to bypass FCS, otherwise '1' */
164 BOOLEAN ext_flow_spec_present;
165 tHCI_EXT_FLOW_SPEC ext_flow_spec;
166 UINT16 flags; /* bit 0: 0-no continuation, 1-continuation */
169 /* L2CAP channel configured field bitmap */
170 #define L2CAP_CH_CFG_MASK_MTU 0x0001
171 #define L2CAP_CH_CFG_MASK_QOS 0x0002
172 #define L2CAP_CH_CFG_MASK_FLUSH_TO 0x0004
173 #define L2CAP_CH_CFG_MASK_FCR 0x0008
174 #define L2CAP_CH_CFG_MASK_FCS 0x0010
175 #define L2CAP_CH_CFG_MASK_EXT_FLOW_SPEC 0x0020
177 typedef UINT16 tL2CAP_CH_CFG_BITS;
179 /*********************************
180 ** Callback Functions Prototypes
181 **********************************/
183 /* Connection indication callback prototype. Parameters are
184 ** BD Address of remote
185 ** Local CID assigned to the connection
186 ** PSM that the remote wants to connect to
187 ** Identifier that the remote sent
189 typedef void (tL2CA_CONNECT_IND_CB) (BD_ADDR, UINT16, UINT16, UINT8);
192 /* Connection confirmation callback prototype. Parameters are
194 ** Result - 0 = connected, non-zero means failure reason
196 typedef void (tL2CA_CONNECT_CFM_CB) (UINT16, UINT16);
199 /* Connection pending callback prototype. Parameters are
202 typedef void (tL2CA_CONNECT_PND_CB) (UINT16);
205 /* Configuration indication callback prototype. Parameters are
206 ** Local CID assigned to the connection
207 ** Pointer to configuration info
209 typedef void (tL2CA_CONFIG_IND_CB) (UINT16, tL2CAP_CFG_INFO *);
212 /* Configuration confirm callback prototype. Parameters are
213 ** Local CID assigned to the connection
214 ** Pointer to configuration info
216 typedef void (tL2CA_CONFIG_CFM_CB) (UINT16, tL2CAP_CFG_INFO *);
219 /* Disconnect indication callback prototype. Parameters are
221 ** Boolean whether upper layer should ack this
223 typedef void (tL2CA_DISCONNECT_IND_CB) (UINT16, BOOLEAN);
226 /* Disconnect confirm callback prototype. Parameters are
230 typedef void (tL2CA_DISCONNECT_CFM_CB) (UINT16, UINT16);
233 /* QOS Violation indication callback prototype. Parameters are
234 ** BD Address of violating device
236 typedef void (tL2CA_QOS_VIOLATION_IND_CB) (BD_ADDR);
239 /* Data received indication callback prototype. Parameters are
243 typedef void (tL2CA_DATA_IND_CB) (UINT16, BT_HDR *);
246 /* Echo response callback prototype. Note that this is not included in the
247 ** registration information, but is passed to L2CAP as part of the API to
248 ** actually send an echo request. Parameters are
251 typedef void (tL2CA_ECHO_RSP_CB) (UINT16);
254 /* Callback function prototype to pass broadcom specific echo response */
255 /* to the upper layer */
256 typedef void (tL2CA_ECHO_DATA_CB) (BD_ADDR, UINT16, UINT8 *);
259 /* Congestion status callback protype. This callback is optional. If
260 ** an application tries to send data when the transmit queue is full,
261 ** the data will anyways be dropped. The parameter is:
263 ** TRUE if congested, FALSE if uncongested
265 typedef void (tL2CA_CONGESTION_STATUS_CB) (UINT16, BOOLEAN);
267 /* Callback prototype for number of packets completed events.
268 ** This callback notifies the application when Number of Completed Packets
269 ** event has been received.
270 ** This callback is originally designed for 3DG devices.
274 typedef void (tL2CA_NOCP_CB) (BD_ADDR);
276 /* Transmit complete callback protype. This callback is optional. If
277 ** set, L2CAP will call it when packets are sent or flushed. If the
278 ** count is 0xFFFF, it means all packets are sent for that CID (eRTM
279 ** mode only). The parameters are:
281 ** Number of SDUs sent or dropped
283 typedef void (tL2CA_TX_COMPLETE_CB) (UINT16, UINT16);
285 /* Define the structure that applications use to register with
286 ** L2CAP. This structure includes callback functions. All functions
287 ** MUST be provided, with the exception of the "connect pending"
288 ** callback and "congestion status" callback.
292 tL2CA_CONNECT_IND_CB *pL2CA_ConnectInd_Cb;
293 tL2CA_CONNECT_CFM_CB *pL2CA_ConnectCfm_Cb;
294 tL2CA_CONNECT_PND_CB *pL2CA_ConnectPnd_Cb;
295 tL2CA_CONFIG_IND_CB *pL2CA_ConfigInd_Cb;
296 tL2CA_CONFIG_CFM_CB *pL2CA_ConfigCfm_Cb;
297 tL2CA_DISCONNECT_IND_CB *pL2CA_DisconnectInd_Cb;
298 tL2CA_DISCONNECT_CFM_CB *pL2CA_DisconnectCfm_Cb;
299 tL2CA_QOS_VIOLATION_IND_CB *pL2CA_QoSViolationInd_Cb;
300 tL2CA_DATA_IND_CB *pL2CA_DataInd_Cb;
301 tL2CA_CONGESTION_STATUS_CB *pL2CA_CongestionStatus_Cb;
302 tL2CA_TX_COMPLETE_CB *pL2CA_TxComplete_Cb;
306 /* Define the structure that applications use to create or accept
307 ** connections with enhanced retransmission mode.
311 UINT8 preferred_mode;
313 UINT8 user_rx_pool_id;
314 UINT8 user_tx_pool_id;
315 UINT8 fcr_rx_pool_id;
316 UINT8 fcr_tx_pool_id;
320 #define L2CA_REGISTER(a,b,c) L2CA_Register(a,(tL2CAP_APPL_INFO *)b)
321 #define L2CA_DEREGISTER(a) L2CA_Deregister(a)
322 #define L2CA_CONNECT_REQ(a,b,c) L2CA_ErtmConnectReq(a,b,c)
323 #define L2CA_CONNECT_RSP(a,b,c,d,e,f) L2CA_ErtmConnectRsp(a,b,c,d,e,f)
324 #define L2CA_CONFIG_REQ(a,b) L2CA_ConfigReq(a,b)
325 #define L2CA_CONFIG_RSP(a,b) L2CA_ConfigRsp(a,b)
326 #define L2CA_DISCONNECT_REQ(a) L2CA_DisconnectReq(a)
327 #define L2CA_DISCONNECT_RSP(a) L2CA_DisconnectRsp(a)
328 #define L2CA_DATA_WRITE(a, b) L2CA_DataWrite(a, b)
330 /*****************************************************************************
331 ** External Function Declarations
332 *****************************************************************************/
338 /*******************************************************************************
340 ** Function L2CA_Register
342 ** Description Other layers call this function to register for L2CAP
345 ** Returns PSM to use or zero if error. Typically, the PSM returned
346 ** is the same as was passed in, but for an outgoing-only
347 ** connection to a dynamic PSM, a "virtual" PSM is returned
348 ** and should be used in the calls to L2CA_ConnectReq() and
349 ** BTM_SetSecurityLevel().
351 *******************************************************************************/
352 extern UINT16 L2CA_Register (UINT16 psm, tL2CAP_APPL_INFO *p_cb_info);
354 /*******************************************************************************
356 ** Function L2CA_Deregister
358 ** Description Other layers call this function to deregister for L2CAP
363 *******************************************************************************/
364 extern void L2CA_Deregister (UINT16 psm);
366 /*******************************************************************************
368 ** Function L2CA_AllocatePSM
370 ** Description Other layers call this function to find an unused PSM for L2CAP
373 ** Returns PSM to use.
375 *******************************************************************************/
376 extern UINT16 L2CA_AllocatePSM(void);
378 /*******************************************************************************
380 ** Function L2CA_ConnectReq
382 ** Description Higher layers call this function to create an L2CAP connection.
383 ** Note that the connection is not established at this time, but
384 ** connection establishment gets started. The callback function
385 ** will be invoked when connection establishes or fails.
387 ** Returns the CID of the connection, or 0 if it failed to start
389 *******************************************************************************/
390 extern UINT16 L2CA_ConnectReq (UINT16 psm, BD_ADDR p_bd_addr);
392 /*******************************************************************************
394 ** Function L2CA_ConnectRsp
396 ** Description Higher layers call this function to accept an incoming
397 ** L2CAP connection, for which they had gotten an connect
398 ** indication callback.
400 ** Returns TRUE for success, FALSE for failure
402 *******************************************************************************/
403 extern BOOLEAN L2CA_ConnectRsp (BD_ADDR p_bd_addr, UINT8 id, UINT16 lcid,
404 UINT16 result, UINT16 status);
406 /*******************************************************************************
408 ** Function L2CA_ErtmConnectReq
410 ** Description Higher layers call this function to create an L2CAP connection
411 ** that needs to use Enhanced Retransmission Mode.
412 ** Note that the connection is not established at this time, but
413 ** connection establishment gets started. The callback function
414 ** will be invoked when connection establishes or fails.
416 ** Returns the CID of the connection, or 0 if it failed to start
418 *******************************************************************************/
419 extern UINT16 L2CA_ErtmConnectReq (UINT16 psm, BD_ADDR p_bd_addr,
420 tL2CAP_ERTM_INFO *p_ertm_info);
422 // This function sets the callback routines for the L2CAP connection referred to by
423 // |local_cid|. The callback routines can only be modified for outgoing connections
424 // established by |L2CA_ConnectReq| or accepted incoming connections. |callbacks|
425 // must not be NULL. This function returns true if the callbacks could be updated,
426 // false if not (e.g. |local_cid| was not found).
427 bool L2CA_SetConnectionCallbacks(uint16_t local_cid, const tL2CAP_APPL_INFO *callbacks);
429 /*******************************************************************************
431 ** Function L2CA_ErtmConnectRsp
433 ** Description Higher layers call this function to accept an incoming
434 ** L2CAP connection, for which they had gotten an connect
435 ** indication callback, and for which the higher layer wants
436 ** to use Enhanced Retransmission Mode.
438 ** Returns TRUE for success, FALSE for failure
440 *******************************************************************************/
441 extern BOOLEAN L2CA_ErtmConnectRsp (BD_ADDR p_bd_addr, UINT8 id, UINT16 lcid,
442 UINT16 result, UINT16 status,
443 tL2CAP_ERTM_INFO *p_ertm_info);
445 /*******************************************************************************
447 ** Function L2CA_ConfigReq
449 ** Description Higher layers call this function to send configuration.
451 ** Returns TRUE if configuration sent, else FALSE
453 *******************************************************************************/
454 extern BOOLEAN L2CA_ConfigReq (UINT16 cid, tL2CAP_CFG_INFO *p_cfg);
456 /*******************************************************************************
458 ** Function L2CA_ConfigRsp
460 ** Description Higher layers call this function to send a configuration
463 ** Returns TRUE if configuration response sent, else FALSE
465 *******************************************************************************/
466 extern BOOLEAN L2CA_ConfigRsp (UINT16 cid, tL2CAP_CFG_INFO *p_cfg);
468 /*******************************************************************************
470 ** Function L2CA_DisconnectReq
472 ** Description Higher layers call this function to disconnect a channel.
474 ** Returns TRUE if disconnect sent, else FALSE
476 *******************************************************************************/
477 extern BOOLEAN L2CA_DisconnectReq (UINT16 cid);
479 /*******************************************************************************
481 ** Function L2CA_DisconnectRsp
483 ** Description Higher layers call this function to acknowledge the
484 ** disconnection of a channel.
488 *******************************************************************************/
489 extern BOOLEAN L2CA_DisconnectRsp (UINT16 cid);
491 /*******************************************************************************
493 ** Function L2CA_DataWrite
495 ** Description Higher layers call this function to write data.
497 ** Returns L2CAP_DW_SUCCESS, if data accepted, else FALSE
498 ** L2CAP_DW_CONGESTED, if data accepted and the channel is congested
499 ** L2CAP_DW_FAILED, if error
501 *******************************************************************************/
502 extern UINT8 L2CA_DataWrite (UINT16 cid, BT_HDR *p_data);
504 /*******************************************************************************
506 ** Function L2CA_Ping
508 ** Description Higher layers call this function to send an echo request.
510 ** Returns TRUE if echo request sent, else FALSE.
512 *******************************************************************************/
513 extern BOOLEAN L2CA_Ping (BD_ADDR p_bd_addr, tL2CA_ECHO_RSP_CB *p_cb);
515 /*******************************************************************************
517 ** Function L2CA_Echo
519 ** Description Higher layers call this function to send an echo request
520 ** with application-specific data.
522 ** Returns TRUE if echo request sent, else FALSE.
524 *******************************************************************************/
525 extern BOOLEAN L2CA_Echo (BD_ADDR p_bd_addr, BT_HDR *p_data, tL2CA_ECHO_DATA_CB *p_callback);
527 // Given a local channel identifier, |lcid|, this function returns the bound remote
528 // channel identifier, |rcid|, and the ACL link handle, |handle|. If |lcid| is not
529 // known or is invalid, this function returns false and does not modify the values
530 // pointed at by |rcid| and |handle|. |rcid| and |handle| may be NULL.
531 bool L2CA_GetIdentifiers(uint16_t lcid, uint16_t *rcid, uint16_t *handle);
533 /*******************************************************************************
535 ** Function L2CA_SetIdleTimeout
537 ** Description Higher layers call this function to set the idle timeout for
538 ** a connection, or for all future connections. The "idle timeout"
539 ** is the amount of time that a connection can remain up with
540 ** no L2CAP channels on it. A timeout of zero means that the
541 ** connection will be torn down immediately when the last channel
542 ** is removed. A timeout of 0xFFFF means no timeout. Values are
545 ** Returns TRUE if command succeeded, FALSE if failed
547 *******************************************************************************/
548 extern BOOLEAN L2CA_SetIdleTimeout (UINT16 cid, UINT16 timeout,
551 /*******************************************************************************
553 ** Function L2CA_SetIdleTimeoutByBdAddr
555 ** Description Higher layers call this function to set the idle timeout for
556 ** a connection. The "idle timeout" is the amount of time that
557 ** a connection can remain up with no L2CAP channels on it.
558 ** A timeout of zero means that the connection will be torn
559 ** down immediately when the last channel is removed.
560 ** A timeout of 0xFFFF means no timeout. Values are in seconds.
561 ** A bd_addr is the remote BD address. If bd_addr = BT_BD_ANY,
562 ** then the idle timeouts for all active l2cap links will be
565 ** Returns TRUE if command succeeded, FALSE if failed
567 ** NOTE This timeout applies to all logical channels active on the
569 *******************************************************************************/
570 extern BOOLEAN L2CA_SetIdleTimeoutByBdAddr(BD_ADDR bd_addr, UINT16 timeout,
571 tBT_TRANSPORT transport);
573 /*******************************************************************************
575 ** Function L2CA_SetTraceLevel
577 ** Description This function sets the trace level for L2CAP. If called with
578 ** a value of 0xFF, it simply reads the current trace level.
580 ** Returns the new (current) trace level
582 *******************************************************************************/
583 extern UINT8 L2CA_SetTraceLevel (UINT8 trace_level);
585 /*******************************************************************************
587 ** Function L2CA_SetDesireRole
589 ** Description This function sets the desire role for L2CAP.
590 ** If the new role is L2CAP_ROLE_ALLOW_SWITCH, allow switch on
591 ** HciCreateConnection.
592 ** If the new role is L2CAP_ROLE_DISALLOW_SWITCH, do not allow switch on
593 ** HciCreateConnection.
595 ** If the new role is a valid role (HCI_ROLE_MASTER or HCI_ROLE_SLAVE),
596 ** the desire role is set to the new value. Otherwise, it is not changed.
598 ** Returns the new (current) role
600 *******************************************************************************/
601 extern UINT8 L2CA_SetDesireRole (UINT8 new_role);
603 /*******************************************************************************
605 ** Function L2CA_LocalLoopbackReq
607 ** Description This function sets up a CID for local loopback
609 ** Returns CID of 0 if none.
611 *******************************************************************************/
612 extern UINT16 L2CA_LocalLoopbackReq (UINT16 psm, UINT16 handle, BD_ADDR p_bd_addr);
614 /*******************************************************************************
616 ** Function L2CA_FlushChannel
618 ** Description This function flushes none, some or all buffers queued up
619 ** for xmission for a particular CID. If called with
620 ** L2CAP_FLUSH_CHANS_GET (0), it simply returns the number
621 ** of buffers queued for that CID L2CAP_FLUSH_CHANS_ALL (0xffff)
622 ** flushes all buffers. All other values specifies the maximum
625 ** Returns Number of buffers left queued for that CID
627 *******************************************************************************/
628 extern UINT16 L2CA_FlushChannel (UINT16 lcid, UINT16 num_to_flush);
631 /*******************************************************************************
633 ** Function L2CA_SetAclPriority
635 ** Description Sets the transmission priority for an ACL channel.
636 ** (For initial implementation only two values are valid.
637 ** L2CAP_PRIORITY_NORMAL and L2CAP_PRIORITY_HIGH).
639 ** Returns TRUE if a valid channel, else FALSE
641 *******************************************************************************/
642 extern BOOLEAN L2CA_SetAclPriority (BD_ADDR bd_addr, UINT8 priority);
644 /*******************************************************************************
646 ** Function L2CA_FlowControl
648 ** Description Higher layers call this function to flow control a channel.
650 ** data_enabled - TRUE data flows, FALSE data is stopped
652 ** Returns TRUE if valid channel, else FALSE
654 *******************************************************************************/
655 extern BOOLEAN L2CA_FlowControl (UINT16 cid, BOOLEAN data_enabled);
657 /*******************************************************************************
659 ** Function L2CA_SendTestSFrame
661 ** Description Higher layers call this function to send a test S-frame.
663 ** Returns TRUE if valid Channel, else FALSE
665 *******************************************************************************/
666 extern BOOLEAN L2CA_SendTestSFrame (UINT16 cid, UINT8 sup_type,
669 /*******************************************************************************
671 ** Function L2CA_SetTxPriority
673 ** Description Sets the transmission priority for a channel. (FCR Mode)
675 ** Returns TRUE if a valid channel, else FALSE
677 *******************************************************************************/
678 extern BOOLEAN L2CA_SetTxPriority (UINT16 cid, tL2CAP_CHNL_PRIORITY priority);
680 /*******************************************************************************
682 ** Function L2CA_RegForNoCPEvt
684 ** Description Register callback for Number of Completed Packets event.
686 ** Input Param p_cb - callback for Number of completed packets event
687 ** p_bda - BT address of remote device
691 *******************************************************************************/
692 extern BOOLEAN L2CA_RegForNoCPEvt(tL2CA_NOCP_CB *p_cb, BD_ADDR p_bda);
694 /*******************************************************************************
696 ** Function L2CA_SetChnlDataRate
698 ** Description Sets the tx/rx data rate for a channel.
700 ** Returns TRUE if a valid channel, else FALSE
702 *******************************************************************************/
703 extern BOOLEAN L2CA_SetChnlDataRate (UINT16 cid, tL2CAP_CHNL_DATA_RATE tx, tL2CAP_CHNL_DATA_RATE rx);
705 typedef void (tL2CA_RESERVE_CMPL_CBACK) (void);
707 /*******************************************************************************
709 ** Function L2CA_SetFlushTimeout
711 ** Description This function set the automatic flush time out in Baseband
712 ** for ACL-U packets.
713 ** BdAddr : the remote BD address of ACL link. If it is BT_DB_ANY
714 ** then the flush time out will be applied to all ACL link.
715 ** FlushTimeout: flush time out in ms
716 ** 0x0000 : No automatic flush
717 ** L2CAP_NO_RETRANSMISSION : No retransmission
718 ** 0x0002 - 0xFFFE : flush time out, if (flush_tout*8)+3/5)
719 ** <= HCI_MAX_AUTO_FLUSH_TOUT (in 625us slot).
720 ** Otherwise, return FALSE.
721 ** L2CAP_NO_AUTOMATIC_FLUSH : No automatic flush
723 ** Returns TRUE if command succeeded, FALSE if failed
725 ** NOTE This flush timeout applies to all logical channels active on the
727 *******************************************************************************/
728 extern BOOLEAN L2CA_SetFlushTimeout (BD_ADDR bd_addr, UINT16 flush_tout);
730 /*******************************************************************************
732 ** Function L2CA_DataWriteEx
734 ** Description Higher layers call this function to write data with extended
736 ** flags : L2CAP_FLUSHABLE_CH_BASED
737 ** L2CAP_FLUSHABLE_PKT
738 ** L2CAP_NON_FLUSHABLE_PKT
740 ** Returns L2CAP_DW_SUCCESS, if data accepted, else FALSE
741 ** L2CAP_DW_CONGESTED, if data accepted and the channel is congested
742 ** L2CAP_DW_FAILED, if error
744 *******************************************************************************/
745 extern UINT8 L2CA_DataWriteEx (UINT16 cid, BT_HDR *p_data, UINT16 flags);
747 /*******************************************************************************
749 ** Function L2CA_SetChnlFlushability
751 ** Description Higher layers call this function to set a channels
752 ** flushability flags
754 ** Returns TRUE if CID found, else FALSE
756 *******************************************************************************/
757 extern BOOLEAN L2CA_SetChnlFlushability (UINT16 cid, BOOLEAN is_flushable);
759 /*******************************************************************************
761 ** Function L2CA_GetPeerFeatures
763 ** Description Get a peers features and fixed channel map
765 ** Parameters: BD address of the peer
766 ** Pointers to features and channel mask storage area
768 ** Return value: TRUE if peer is connected
770 *******************************************************************************/
771 extern BOOLEAN L2CA_GetPeerFeatures (BD_ADDR bd_addr, UINT32 *p_ext_feat, UINT8 *p_chnl_mask);
773 /*******************************************************************************
775 ** Function L2CA_GetBDAddrbyHandle
777 ** Description Get BD address for the given HCI handle
779 ** Parameters: HCI handle
780 ** BD address of the peer
782 ** Return value: TRUE if found lcb for the given handle, FALSE otherwise
784 *******************************************************************************/
785 extern BOOLEAN L2CA_GetBDAddrbyHandle (UINT16 handle, BD_ADDR bd_addr);
787 /*******************************************************************************
789 ** Function L2CA_GetChnlFcrMode
791 ** Description Get the channel FCR mode
793 ** Parameters: Local CID
795 ** Return value: Channel mode
797 *******************************************************************************/
798 extern UINT8 L2CA_GetChnlFcrMode (UINT16 lcid);
801 /*******************************************************************************
803 ** UCD callback prototypes
805 *******************************************************************************/
807 /* UCD discovery. Parameters are
808 ** BD Address of remote
812 #define L2CAP_UCD_INFO_TYPE_RECEPTION 0x01
813 #define L2CAP_UCD_INFO_TYPE_MTU 0x02
815 typedef void (tL2CA_UCD_DISCOVER_CB) (BD_ADDR, UINT8, UINT32);
817 /* UCD data received. Parameters are
818 ** BD Address of remote
819 ** Pointer to buffer with data
821 typedef void (tL2CA_UCD_DATA_CB) (BD_ADDR, BT_HDR *);
823 /* Congestion status callback protype. This callback is optional. If
824 ** an application tries to send data when the transmit queue is full,
825 ** the data will anyways be dropped. The parameter is:
827 ** TRUE if congested, FALSE if uncongested
829 typedef void (tL2CA_UCD_CONGESTION_STATUS_CB) (BD_ADDR, BOOLEAN);
831 /* UCD registration info (the callback addresses and PSM)
835 tL2CA_UCD_DISCOVER_CB *pL2CA_UCD_Discover_Cb;
836 tL2CA_UCD_DATA_CB *pL2CA_UCD_Data_Cb;
837 tL2CA_UCD_CONGESTION_STATUS_CB *pL2CA_UCD_Congestion_Status_Cb;
838 } tL2CAP_UCD_CB_INFO;
840 /*******************************************************************************
842 ** Function L2CA_UcdRegister
844 ** Description Register PSM on UCD.
846 ** Parameters: tL2CAP_UCD_CB_INFO
848 ** Return value: TRUE if successs
850 *******************************************************************************/
851 extern BOOLEAN L2CA_UcdRegister ( UINT16 psm, tL2CAP_UCD_CB_INFO *p_cb_info );
853 /*******************************************************************************
855 ** Function L2CA_UcdDeregister
857 ** Description Deregister PSM on UCD.
861 ** Return value: TRUE if successs
863 *******************************************************************************/
864 extern BOOLEAN L2CA_UcdDeregister ( UINT16 psm );
866 /*******************************************************************************
868 ** Function L2CA_UcdDiscover
870 ** Description Discover UCD of remote device.
873 ** BD_ADDR of remote device
874 ** info_type : L2CAP_UCD_INFO_TYPE_RECEPTION
875 ** L2CAP_UCD_INFO_TYPE_MTU
878 ** Return value: TRUE if successs
880 *******************************************************************************/
881 extern BOOLEAN L2CA_UcdDiscover ( UINT16 psm, BD_ADDR rem_bda, UINT8 info_type );
883 /*******************************************************************************
885 ** Function L2CA_UcdDataWrite
887 ** Description Send UCD to remote device
890 ** BD Address of remote
891 ** Pointer to buffer of type BT_HDR
892 ** flags : L2CAP_FLUSHABLE_CH_BASED
893 ** L2CAP_FLUSHABLE_PKT
894 ** L2CAP_NON_FLUSHABLE_PKT
896 ** Return value L2CAP_DW_SUCCESS, if data accepted
897 ** L2CAP_DW_FAILED, if error
899 *******************************************************************************/
900 extern UINT16 L2CA_UcdDataWrite (UINT16 psm, BD_ADDR rem_bda, BT_HDR *p_buf, UINT16 flags);
902 /*******************************************************************************
904 ** Function L2CA_UcdSetIdleTimeout
906 ** Description Set UCD Idle timeout.
908 ** Parameters: BD Addr
911 ** Return value: TRUE if successs
913 *******************************************************************************/
914 extern BOOLEAN L2CA_UcdSetIdleTimeout ( BD_ADDR rem_bda, UINT16 timeout );
916 /*******************************************************************************
918 ** Function L2CA_UCDSetTxPriority
920 ** Description Sets the transmission priority for a connectionless channel.
922 ** Returns TRUE if a valid channel, else FALSE
924 *******************************************************************************/
925 extern BOOLEAN L2CA_UCDSetTxPriority ( BD_ADDR rem_bda, tL2CAP_CHNL_PRIORITY priority );
928 /*******************************************************************************
930 ** Fixed Channel callback prototypes
932 *******************************************************************************/
934 /* Fixed channel connected and disconnected. Parameters are
936 ** BD Address of remote
937 ** TRUE if channel is connected, FALSE if disconnected
938 ** Reason for connection failure
939 ** transport : physical transport, BR/EDR or LE
941 typedef void (tL2CA_FIXED_CHNL_CB) (UINT16, BD_ADDR, BOOLEAN, UINT16, tBT_TRANSPORT);
943 /* Signalling data received. Parameters are
945 ** BD Address of remote
946 ** Pointer to buffer with data
948 typedef void (tL2CA_FIXED_DATA_CB) (UINT16, BD_ADDR, BT_HDR *);
950 /* Congestion status callback protype. This callback is optional. If
951 ** an application tries to send data when the transmit queue is full,
952 ** the data will anyways be dropped. The parameter is:
954 ** TRUE if congested, FALSE if uncongested
956 typedef void (tL2CA_FIXED_CONGESTION_STATUS_CB) (BD_ADDR, BOOLEAN);
958 /* Fixed channel registration info (the callback addresses and channel config)
962 tL2CA_FIXED_CHNL_CB *pL2CA_FixedConn_Cb;
963 tL2CA_FIXED_DATA_CB *pL2CA_FixedData_Cb;
964 tL2CA_FIXED_CONGESTION_STATUS_CB *pL2CA_FixedCong_Cb;
965 tL2CAP_FCR_OPTS fixed_chnl_opts;
967 UINT16 default_idle_tout;
968 tL2CA_TX_COMPLETE_CB *pL2CA_FixedTxComplete_Cb; /* fixed channel tx complete callback */
969 } tL2CAP_FIXED_CHNL_REG;
972 #if (L2CAP_NUM_FIXED_CHNLS > 0)
973 /*******************************************************************************
975 ** Function L2CA_RegisterFixedChannel
977 ** Description Register a fixed channel.
979 ** Parameters: Fixed Channel #
980 ** Channel Callbacks and config
982 ** Return value: TRUE if registered OK
984 *******************************************************************************/
985 extern BOOLEAN L2CA_RegisterFixedChannel (UINT16 fixed_cid, tL2CAP_FIXED_CHNL_REG *p_freg);
987 /*******************************************************************************
989 ** Function L2CA_ConnectFixedChnl
991 ** Description Connect an fixed signalling channel to a remote device.
993 ** Parameters: Fixed CID
994 ** BD Address of remote
996 ** Return value: TRUE if connection started
998 *******************************************************************************/
999 extern BOOLEAN L2CA_ConnectFixedChnl (UINT16 fixed_cid, BD_ADDR bd_addr);
1001 /*******************************************************************************
1003 ** Function L2CA_SendFixedChnlData
1005 ** Description Write data on a fixed signalling channel.
1007 ** Parameters: Fixed CID
1008 ** BD Address of remote
1009 ** Pointer to buffer of type BT_HDR
1011 ** Return value L2CAP_DW_SUCCESS, if data accepted
1012 ** L2CAP_DW_FAILED, if error
1014 *******************************************************************************/
1015 extern UINT16 L2CA_SendFixedChnlData (UINT16 fixed_cid, BD_ADDR rem_bda, BT_HDR *p_buf);
1017 /*******************************************************************************
1019 ** Function L2CA_RemoveFixedChnl
1021 ** Description Remove a fixed channel to a remote device.
1023 ** Parameters: Fixed CID
1024 ** BD Address of remote
1025 ** Idle timeout to use (or 0xFFFF if don't care)
1027 ** Return value: TRUE if channel removed
1029 *******************************************************************************/
1030 extern BOOLEAN L2CA_RemoveFixedChnl (UINT16 fixed_cid, BD_ADDR rem_bda);
1032 /*******************************************************************************
1034 ** Function L2CA_SetFixedChannelTout
1036 ** Description Higher layers call this function to set the idle timeout for
1037 ** a fixed channel. The "idle timeout" is the amount of time that
1038 ** a connection can remain up with no L2CAP channels on it.
1039 ** A timeout of zero means that the connection will be torn
1040 ** down immediately when the last channel is removed.
1041 ** A timeout of 0xFFFF means no timeout. Values are in seconds.
1042 ** A bd_addr is the remote BD address. If bd_addr = BT_BD_ANY,
1043 ** then the idle timeouts for all active l2cap links will be
1046 ** Returns TRUE if command succeeded, FALSE if failed
1048 *******************************************************************************/
1049 extern BOOLEAN L2CA_SetFixedChannelTout (BD_ADDR rem_bda, UINT16 fixed_cid, UINT16 idle_tout);
1051 #endif /* (L2CAP_NUM_FIXED_CHNLS > 0) */
1053 /*******************************************************************************
1055 ** Function L2CA_GetCurrentConfig
1057 ** Description This function returns configurations of L2CAP channel
1058 ** pp_our_cfg : pointer of our saved configuration options
1059 ** p_our_cfg_bits : valid config in bitmap
1060 ** pp_peer_cfg: pointer of peer's saved configuration options
1061 ** p_peer_cfg_bits : valid config in bitmap
1063 ** Returns TRUE if successful
1065 *******************************************************************************/
1066 extern BOOLEAN L2CA_GetCurrentConfig (UINT16 lcid,
1067 tL2CAP_CFG_INFO **pp_our_cfg, tL2CAP_CH_CFG_BITS *p_our_cfg_bits,
1068 tL2CAP_CFG_INFO **pp_peer_cfg, tL2CAP_CH_CFG_BITS *p_peer_cfg_bits);
1070 #if (BLE_INCLUDED == TRUE)
1071 /*******************************************************************************
1073 ** Function L2CA_CancelBleConnectReq
1075 ** Description Cancel a pending connection attempt to a BLE device.
1077 ** Parameters: BD Address of remote
1079 ** Return value: TRUE if connection was cancelled
1081 *******************************************************************************/
1082 extern BOOLEAN L2CA_CancelBleConnectReq (BD_ADDR rem_bda);
1084 /*******************************************************************************
1086 ** Function L2CA_UpdateBleConnParams
1088 ** Description Update BLE connection parameters.
1090 ** Parameters: BD Address of remote
1092 ** Return value: TRUE if update started
1094 *******************************************************************************/
1095 extern BOOLEAN L2CA_UpdateBleConnParams (BD_ADDR rem_bdRa, UINT16 min_int,
1096 UINT16 max_int, UINT16 latency, UINT16 timeout);
1098 /*******************************************************************************
1100 ** Function L2CA_EnableUpdateBleConnParams
1102 ** Description Update BLE connection parameters.
1104 ** Parameters: BD Address of remote
1107 ** Return value: TRUE if update started
1109 *******************************************************************************/
1110 extern BOOLEAN L2CA_EnableUpdateBleConnParams (BD_ADDR rem_bda, BOOLEAN enable);
1112 /*******************************************************************************
1114 ** Function L2CA_GetBleConnRole
1116 ** Description This function returns the connection role.
1118 ** Returns link role.
1120 *******************************************************************************/
1121 extern UINT8 L2CA_GetBleConnRole (BD_ADDR bd_addr);
1123 /*******************************************************************************
1125 ** Function L2CA_GetDisconnectReason
1127 ** Description This function returns the disconnect reason code.
1129 ** Parameters: BD Address of remote
1130 ** Physical transport for the L2CAP connection (BR/EDR or LE)
1132 ** Returns disconnect reason
1134 *******************************************************************************/
1135 extern UINT16 L2CA_GetDisconnectReason (BD_ADDR remote_bda, tBT_TRANSPORT transport);
1137 #endif /* (BLE_INCLUDED == TRUE) */
1143 #endif /* L2C_API_H */