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 ******************************************************************************/
27 #include "bt_target.h"
31 /*****************************************************************************
33 *****************************************************************************/
35 /* Define the minimum offset that L2CAP needs in a buffer. This is made up of
36 ** HCI type(1), len(2), handle(2), L2CAP len(2) and CID(2) => 9
38 #define L2CAP_MIN_OFFSET 13 /* plus control(2), SDU length(2) */
40 /* Minimum offset for broadcast needs another two bytes for the PSM */
41 #define L2CAP_BCST_MIN_OFFSET 11
43 /* ping result codes */
44 #define L2CAP_PING_RESULT_OK 0 /* Ping reply received OK */
45 #define L2CAP_PING_RESULT_NO_LINK 1 /* Link could not be setup */
46 #define L2CAP_PING_RESULT_NO_RESP 2 /* Remote L2CAP did not reply */
48 /* result code for L2CA_DataWrite() */
49 #define L2CAP_DW_FAILED FALSE
50 #define L2CAP_DW_SUCCESS TRUE
51 #define L2CAP_DW_CONGESTED 2
53 /* Values for priority parameter to L2CA_SetAclPriority */
54 #define L2CAP_PRIORITY_NORMAL 0
55 #define L2CAP_PRIORITY_HIGH 1
57 /* Values for priority parameter to L2CA_SetTxPriority */
58 #define L2CAP_CHNL_PRIORITY_HIGH 0
59 #define L2CAP_CHNL_PRIORITY_MEDIUM 1
60 #define L2CAP_CHNL_PRIORITY_LOW 2
62 typedef UINT8 tL2CAP_CHNL_PRIORITY;
64 /* Values for Tx/Rx data rate parameter to L2CA_SetChnlDataRate */
65 #define L2CAP_CHNL_DATA_RATE_HIGH 3
66 #define L2CAP_CHNL_DATA_RATE_MEDIUM 2
67 #define L2CAP_CHNL_DATA_RATE_LOW 1
68 #define L2CAP_CHNL_DATA_RATE_NO_TRAFFIC 0
70 typedef UINT8 tL2CAP_CHNL_DATA_RATE;
72 /* Data Packet Flags (bits 2-15 are reserved) */
73 /* layer specific 14-15 bits are used for FCR SAR */
74 #define L2CAP_FLUSHABLE_MASK 0x0003
75 #define L2CAP_FLUSHABLE_CH_BASED 0x0000
76 #define L2CAP_FLUSHABLE_PKT 0x0001
77 #define L2CAP_NON_FLUSHABLE_PKT 0x0002
80 /* L2CA_FlushChannel num_to_flush definitions */
81 #define L2CAP_FLUSH_CHANS_ALL 0xffff
82 #define L2CAP_FLUSH_CHANS_GET 0x0000
85 /* special CID for Multi-AV for reporting congestion */
86 #define L2CAP_MULTI_AV_CID 0
88 /* length of the HCI header block */
89 /* HCI header(4) + SNK count(1) + FCR bits(1) + AV data length(2) */
90 #define L2CAP_MULTI_AV_HCI_HDR_LEN 8
92 /* length of padding for 4 bytes align */
93 #define L2CAP_MULTI_AV_PADDING_LEN 2
95 /* length of the HCI header block with padding for FCR */
96 /* HCI header(4) + SNK count(1) + FCR bits(1) + AV data length(2) + padding(2) */
97 #define L2CAP_MULTI_AV_HCI_HDR_LEN_WITH_PADDING 10
99 /* length of the L2CAP header block */
100 /* HCI header(4) + L2CAP header(4) + padding(4) or control word(2) + FCS(2) */
101 #define L2CAP_MULTI_AV_L2C_HDR_LEN 12
103 /* definition used for L2CA_SetDesireRole */
104 #define L2CAP_ROLE_SLAVE HCI_ROLE_SLAVE
105 #define L2CAP_ROLE_MASTER HCI_ROLE_MASTER
106 #define L2CAP_ROLE_ALLOW_SWITCH 0x80 /* set this bit to allow switch at create conn */
107 #define L2CAP_ROLE_DISALLOW_SWITCH 0x40 /* set this bit to disallow switch at create conn */
108 #define L2CAP_ROLE_CHECK_SWITCH 0xC0
111 /* Values for 'allowed_modes' field passed in structure tL2CAP_ERTM_INFO
113 #define L2CAP_FCR_CHAN_OPT_BASIC (1 << L2CAP_FCR_BASIC_MODE)
114 #define L2CAP_FCR_CHAN_OPT_ERTM (1 << L2CAP_FCR_ERTM_MODE)
115 #define L2CAP_FCR_CHAN_OPT_STREAM (1 << L2CAP_FCR_STREAM_MODE)
117 #define L2CAP_FCR_CHAN_OPT_ALL_MASK (L2CAP_FCR_CHAN_OPT_BASIC | L2CAP_FCR_CHAN_OPT_ERTM | L2CAP_FCR_CHAN_OPT_STREAM)
119 /* Validity check for PSM. PSM values must be odd. Also, all PSM values must
120 ** be assigned such that the least significant bit of the most sigificant
121 ** octet equals zero.
123 #define L2C_INVALID_PSM(psm) (((psm) & 0x0101) != 0x0001)
124 #define L2C_IS_VALID_PSM(psm) (((psm) & 0x0101) == 0x0001)
126 /*****************************************************************************
128 *****************************************************************************/
132 #define L2CAP_FCR_BASIC_MODE 0x00
133 #define L2CAP_FCR_ERTM_MODE 0x03
134 #define L2CAP_FCR_STREAM_MODE 0x04
145 /* Define a structure to hold the configuration parameters. Since the
146 ** parameters are optional, for each parameter there is a boolean to
147 ** use to signify its presence or absence.
151 UINT16 result; /* Only used in confirm messages */
156 BOOLEAN flush_to_present;
160 BOOLEAN fcs_present; /* Optionally bypasses FCS checks */
161 UINT8 fcs; /* '0' if desire is to bypass FCS, otherwise '1' */
162 BOOLEAN ext_flow_spec_present;
163 tHCI_EXT_FLOW_SPEC ext_flow_spec;
164 UINT16 flags; /* bit 0: 0-no continuation, 1-continuation */
167 /* L2CAP channel configured field bitmap */
168 #define L2CAP_CH_CFG_MASK_MTU 0x0001
169 #define L2CAP_CH_CFG_MASK_QOS 0x0002
170 #define L2CAP_CH_CFG_MASK_FLUSH_TO 0x0004
171 #define L2CAP_CH_CFG_MASK_FCR 0x0008
172 #define L2CAP_CH_CFG_MASK_FCS 0x0010
173 #define L2CAP_CH_CFG_MASK_EXT_FLOW_SPEC 0x0020
175 typedef UINT16 tL2CAP_CH_CFG_BITS;
177 /*********************************
178 ** Callback Functions Prototypes
179 **********************************/
181 /* Connection indication callback prototype. Parameters are
182 ** BD Address of remote
183 ** Local CID assigned to the connection
184 ** PSM that the remote wants to connect to
185 ** Identifier that the remote sent
187 typedef void (tL2CA_CONNECT_IND_CB) (BD_ADDR, UINT16, UINT16, UINT8);
190 /* Connection confirmation callback prototype. Parameters are
192 ** Result - 0 = connected, non-zero means failure reason
194 typedef void (tL2CA_CONNECT_CFM_CB) (UINT16, UINT16);
197 /* Connection pending callback prototype. Parameters are
200 typedef void (tL2CA_CONNECT_PND_CB) (UINT16);
203 /* Configuration indication callback prototype. Parameters are
204 ** Local CID assigned to the connection
205 ** Pointer to configuration info
207 typedef void (tL2CA_CONFIG_IND_CB) (UINT16, tL2CAP_CFG_INFO *);
210 /* Configuration confirm callback prototype. Parameters are
211 ** Local CID assigned to the connection
212 ** Pointer to configuration info
214 typedef void (tL2CA_CONFIG_CFM_CB) (UINT16, tL2CAP_CFG_INFO *);
217 /* Disconnect indication callback prototype. Parameters are
219 ** Boolean whether upper layer should ack this
221 typedef void (tL2CA_DISCONNECT_IND_CB) (UINT16, BOOLEAN);
224 /* Disconnect confirm callback prototype. Parameters are
228 typedef void (tL2CA_DISCONNECT_CFM_CB) (UINT16, UINT16);
231 /* QOS Violation indication callback prototype. Parameters are
232 ** BD Address of violating device
234 typedef void (tL2CA_QOS_VIOLATION_IND_CB) (BD_ADDR);
237 /* Data received indication callback prototype. Parameters are
241 typedef void (tL2CA_DATA_IND_CB) (UINT16, BT_HDR *);
244 /* Echo response callback prototype. Note that this is not included in the
245 ** registration information, but is passed to L2CAP as part of the API to
246 ** actually send an echo request. Parameters are
249 typedef void (tL2CA_ECHO_RSP_CB) (UINT16);
252 /* Callback function prototype to pass broadcom specific echo response */
253 /* to the upper layer */
254 typedef void (tL2CA_ECHO_DATA_CB) (BD_ADDR, UINT16, UINT8 *);
257 /* Congestion status callback protype. This callback is optional. If
258 ** an application tries to send data when the transmit queue is full,
259 ** the data will anyways be dropped. The parameter is:
261 ** TRUE if congested, FALSE if uncongested
263 typedef void (tL2CA_CONGESTION_STATUS_CB) (UINT16, BOOLEAN);
265 /* Callback prototype for number of packets completed events.
266 ** This callback notifies the application when Number of Completed Packets
267 ** event has been received.
268 ** This callback is originally designed for 3DG devices.
272 typedef void (tL2CA_NOCP_CB) (BD_ADDR);
274 /* Transmit complete callback protype. This callback is optional. If
275 ** set, L2CAP will call it when packets are sent or flushed. If the
276 ** count is 0xFFFF, it means all packets are sent for that CID (eRTM
277 ** mode only). The parameters are:
279 ** Number of SDUs sent or dropped
281 typedef void (tL2CA_TX_COMPLETE_CB) (UINT16, UINT16);
283 /* Define the structure that applications use to register with
284 ** L2CAP. This structure includes callback functions. All functions
285 ** MUST be provided, with the exception of the "connect pending"
286 ** callback and "congestion status" callback.
290 tL2CA_CONNECT_IND_CB *pL2CA_ConnectInd_Cb;
291 tL2CA_CONNECT_CFM_CB *pL2CA_ConnectCfm_Cb;
292 tL2CA_CONNECT_PND_CB *pL2CA_ConnectPnd_Cb;
293 tL2CA_CONFIG_IND_CB *pL2CA_ConfigInd_Cb;
294 tL2CA_CONFIG_CFM_CB *pL2CA_ConfigCfm_Cb;
295 tL2CA_DISCONNECT_IND_CB *pL2CA_DisconnectInd_Cb;
296 tL2CA_DISCONNECT_CFM_CB *pL2CA_DisconnectCfm_Cb;
297 tL2CA_QOS_VIOLATION_IND_CB *pL2CA_QoSViolationInd_Cb;
298 tL2CA_DATA_IND_CB *pL2CA_DataInd_Cb;
299 tL2CA_CONGESTION_STATUS_CB *pL2CA_CongestionStatus_Cb;
300 tL2CA_TX_COMPLETE_CB *pL2CA_TxComplete_Cb;
304 /* Define the structure that applications use to create or accept
305 ** connections with enhanced retransmission mode.
309 UINT8 preferred_mode;
311 UINT8 user_rx_pool_id;
312 UINT8 user_tx_pool_id;
313 UINT8 fcr_rx_pool_id;
314 UINT8 fcr_tx_pool_id;
318 #define L2CA_REGISTER(a,b,c) L2CA_Register(a,(tL2CAP_APPL_INFO *)b)
319 #define L2CA_DEREGISTER(a) L2CA_Deregister(a)
320 #define L2CA_CONNECT_REQ(a,b,c,d) L2CA_ErtmConnectReq(a,b,c)
321 #define L2CA_CONNECT_RSP(a,b,c,d,e,f,g) L2CA_ErtmConnectRsp(a,b,c,d,e,f)
322 #define L2CA_CONFIG_REQ(a,b) L2CA_ConfigReq(a,b)
323 #define L2CA_CONFIG_RSP(a,b) L2CA_ConfigRsp(a,b)
324 #define L2CA_DISCONNECT_REQ(a) L2CA_DisconnectReq(a)
325 #define L2CA_DISCONNECT_RSP(a) L2CA_DisconnectRsp(a)
326 #define L2CA_DATA_WRITE(a, b) L2CA_DataWrite(a, b)
328 /*****************************************************************************
329 ** External Function Declarations
330 *****************************************************************************/
336 /*******************************************************************************
338 ** Function L2CA_Register
340 ** Description Other layers call this function to register for L2CAP
343 ** Returns PSM to use or zero if error. Typically, the PSM returned
344 ** is the same as was passed in, but for an outgoing-only
345 ** connection to a dynamic PSM, a "virtual" PSM is returned
346 ** and should be used in the calls to L2CA_ConnectReq() and
347 ** BTM_SetSecurityLevel().
349 *******************************************************************************/
350 L2C_API extern UINT16 L2CA_Register (UINT16 psm, tL2CAP_APPL_INFO *p_cb_info);
352 /*******************************************************************************
354 ** Function L2CA_Deregister
356 ** Description Other layers call this function to deregister for L2CAP
361 *******************************************************************************/
362 L2C_API extern void L2CA_Deregister (UINT16 psm);
364 /*******************************************************************************
366 ** Function L2CA_AllocatePSM
368 ** Description Other layers call this function to find an unused PSM for L2CAP
371 ** Returns PSM to use.
373 *******************************************************************************/
374 L2C_API extern UINT16 L2CA_AllocatePSM(void);
376 /*******************************************************************************
378 ** Function L2CA_ConnectReq
380 ** Description Higher layers call this function to create an L2CAP connection.
381 ** Note that the connection is not established at this time, but
382 ** connection establishment gets started. The callback function
383 ** will be invoked when connection establishes or fails.
385 ** Returns the CID of the connection, or 0 if it failed to start
387 *******************************************************************************/
388 L2C_API extern UINT16 L2CA_ConnectReq (UINT16 psm, BD_ADDR p_bd_addr);
390 /*******************************************************************************
392 ** Function L2CA_ConnectRsp
394 ** Description Higher layers call this function to accept an incoming
395 ** L2CAP connection, for which they had gotten an connect
396 ** indication callback.
398 ** Returns TRUE for success, FALSE for failure
400 *******************************************************************************/
401 L2C_API extern BOOLEAN L2CA_ConnectRsp (BD_ADDR p_bd_addr, UINT8 id, UINT16 lcid,
402 UINT16 result, UINT16 status);
404 /*******************************************************************************
406 ** Function L2CA_ErtmConnectReq
408 ** Description Higher layers call this function to create an L2CAP connection
409 ** that needs to use Enhanced Retransmission Mode.
410 ** Note that the connection is not established at this time, but
411 ** connection establishment gets started. The callback function
412 ** will be invoked when connection establishes or fails.
414 ** Returns the CID of the connection, or 0 if it failed to start
416 *******************************************************************************/
417 L2C_API extern UINT16 L2CA_ErtmConnectReq (UINT16 psm, BD_ADDR p_bd_addr,
418 tL2CAP_ERTM_INFO *p_ertm_info);
420 /*******************************************************************************
422 ** Function L2CA_ErtmConnectRsp
424 ** Description Higher layers call this function to accept an incoming
425 ** L2CAP connection, for which they had gotten an connect
426 ** indication callback, and for which the higher layer wants
427 ** to use Enhanced Retransmission Mode.
429 ** Returns TRUE for success, FALSE for failure
431 *******************************************************************************/
432 L2C_API extern BOOLEAN L2CA_ErtmConnectRsp (BD_ADDR p_bd_addr, UINT8 id, UINT16 lcid,
433 UINT16 result, UINT16 status,
434 tL2CAP_ERTM_INFO *p_ertm_info);
436 /*******************************************************************************
438 ** Function L2CA_ConfigReq
440 ** Description Higher layers call this function to send configuration.
442 ** Returns TRUE if configuration sent, else FALSE
444 *******************************************************************************/
445 L2C_API extern BOOLEAN L2CA_ConfigReq (UINT16 cid, tL2CAP_CFG_INFO *p_cfg);
447 /*******************************************************************************
449 ** Function L2CA_ConfigRsp
451 ** Description Higher layers call this function to send a configuration
454 ** Returns TRUE if configuration response sent, else FALSE
456 *******************************************************************************/
457 L2C_API extern BOOLEAN L2CA_ConfigRsp (UINT16 cid, tL2CAP_CFG_INFO *p_cfg);
459 /*******************************************************************************
461 ** Function L2CA_DisconnectReq
463 ** Description Higher layers call this function to disconnect a channel.
465 ** Returns TRUE if disconnect sent, else FALSE
467 *******************************************************************************/
468 L2C_API extern BOOLEAN L2CA_DisconnectReq (UINT16 cid);
470 /*******************************************************************************
472 ** Function L2CA_DisconnectRsp
474 ** Description Higher layers call this function to acknowledge the
475 ** disconnection of a channel.
479 *******************************************************************************/
480 L2C_API extern BOOLEAN L2CA_DisconnectRsp (UINT16 cid);
482 /*******************************************************************************
484 ** Function L2CA_DataWrite
486 ** Description Higher layers call this function to write data.
488 ** Returns L2CAP_DW_SUCCESS, if data accepted, else FALSE
489 ** L2CAP_DW_CONGESTED, if data accepted and the channel is congested
490 ** L2CAP_DW_FAILED, if error
492 *******************************************************************************/
493 L2C_API extern UINT8 L2CA_DataWrite (UINT16 cid, BT_HDR *p_data);
495 /*******************************************************************************
497 ** Function L2CA_Ping
499 ** Description Higher layers call this function to send an echo request.
501 ** Returns TRUE if echo request sent, else FALSE.
503 *******************************************************************************/
504 L2C_API extern BOOLEAN L2CA_Ping (BD_ADDR p_bd_addr, tL2CA_ECHO_RSP_CB *p_cb);
506 /*******************************************************************************
508 ** Function L2CA_Echo
510 ** Description Higher layers call this function to send an echo request
511 ** with application-specific data.
513 ** Returns TRUE if echo request sent, else FALSE.
515 *******************************************************************************/
516 L2C_API extern BOOLEAN L2CA_Echo (BD_ADDR p_bd_addr, BT_HDR *p_data, tL2CA_ECHO_DATA_CB *p_callback);
518 /*******************************************************************************
520 ** Function L2CA_SetIdleTimeout
522 ** Description Higher layers call this function to set the idle timeout for
523 ** a connection, or for all future connections. The "idle timeout"
524 ** is the amount of time that a connection can remain up with
525 ** no L2CAP channels on it. A timeout of zero means that the
526 ** connection will be torn down immediately when the last channel
527 ** is removed. A timeout of 0xFFFF means no timeout. Values are
530 ** Returns TRUE if command succeeded, FALSE if failed
532 *******************************************************************************/
533 L2C_API extern BOOLEAN L2CA_SetIdleTimeout (UINT16 cid, UINT16 timeout,
536 /*******************************************************************************
538 ** Function L2CA_SetIdleTimeoutByBdAddr
540 ** Description Higher layers call this function to set the idle timeout for
541 ** a connection. The "idle timeout" is the amount of time that
542 ** a connection can remain up with no L2CAP channels on it.
543 ** A timeout of zero means that the connection will be torn
544 ** down immediately when the last channel is removed.
545 ** A timeout of 0xFFFF means no timeout. Values are in seconds.
546 ** A bd_addr is the remote BD address. If bd_addr = BT_BD_ANY,
547 ** then the idle timeouts for all active l2cap links will be
550 ** Returns TRUE if command succeeded, FALSE if failed
552 ** NOTE This timeout applies to all logical channels active on the
554 *******************************************************************************/
555 L2C_API extern BOOLEAN L2CA_SetIdleTimeoutByBdAddr(BD_ADDR bd_addr, UINT16 timeout);
557 /*******************************************************************************
559 ** Function L2CA_SetTraceLevel
561 ** Description This function sets the trace level for L2CAP. If called with
562 ** a value of 0xFF, it simply reads the current trace level.
564 ** Returns the new (current) trace level
566 *******************************************************************************/
567 L2C_API extern UINT8 L2CA_SetTraceLevel (UINT8 trace_level);
569 /*******************************************************************************
571 ** Function L2CA_SetDesireRole
573 ** Description This function sets the desire role for L2CAP.
574 ** If the new role is L2CAP_ROLE_ALLOW_SWITCH, allow switch on
575 ** HciCreateConnection.
576 ** If the new role is L2CAP_ROLE_DISALLOW_SWITCH, do not allow switch on
577 ** HciCreateConnection.
579 ** If the new role is a valid role (HCI_ROLE_MASTER or HCI_ROLE_SLAVE),
580 ** the desire role is set to the new value. Otherwise, it is not changed.
582 ** Returns the new (current) role
584 *******************************************************************************/
585 L2C_API extern UINT8 L2CA_SetDesireRole (UINT8 new_role);
587 /*******************************************************************************
589 ** Function L2CA_LocalLoopbackReq
591 ** Description This function sets up a CID for local loopback
593 ** Returns CID of 0 if none.
595 *******************************************************************************/
596 L2C_API extern UINT16 L2CA_LocalLoopbackReq (UINT16 psm, UINT16 handle, BD_ADDR p_bd_addr);
598 /*******************************************************************************
600 ** Function L2CA_FlushChannel
602 ** Description This function flushes none, some or all buffers queued up
603 ** for xmission for a particular CID. If called with
604 ** L2CAP_FLUSH_CHANS_GET (0), it simply returns the number
605 ** of buffers queued for that CID L2CAP_FLUSH_CHANS_ALL (0xffff)
606 ** flushes all buffers. All other values specifies the maximum
609 ** Returns Number of buffers left queued for that CID
611 *******************************************************************************/
612 L2C_API extern UINT16 L2CA_FlushChannel (UINT16 lcid, UINT16 num_to_flush);
615 /*******************************************************************************
617 ** Function L2CA_SetAclPriority
619 ** Description Sets the transmission priority for an ACL channel.
620 ** (For initial implementation only two values are valid.
621 ** L2CAP_PRIORITY_NORMAL and L2CAP_PRIORITY_HIGH).
623 ** Returns TRUE if a valid channel, else FALSE
625 *******************************************************************************/
626 L2C_API extern BOOLEAN L2CA_SetAclPriority (BD_ADDR bd_addr, UINT8 priority);
628 /*******************************************************************************
630 ** Function L2CA_FlowControl
632 ** Description Higher layers call this function to flow control a channel.
634 ** data_enabled - TRUE data flows, FALSE data is stopped
636 ** Returns TRUE if valid channel, else FALSE
638 *******************************************************************************/
639 L2C_API extern BOOLEAN L2CA_FlowControl (UINT16 cid, BOOLEAN data_enabled);
641 /*******************************************************************************
643 ** Function L2CA_SendTestSFrame
645 ** Description Higher layers call this function to send a test S-frame.
647 ** Returns TRUE if valid Channel, else FALSE
649 *******************************************************************************/
650 L2C_API extern BOOLEAN L2CA_SendTestSFrame (UINT16 cid, UINT8 sup_type,
653 /*******************************************************************************
655 ** Function L2CA_SetTxPriority
657 ** Description Sets the transmission priority for a channel. (FCR Mode)
659 ** Returns TRUE if a valid channel, else FALSE
661 *******************************************************************************/
662 L2C_API extern BOOLEAN L2CA_SetTxPriority (UINT16 cid, tL2CAP_CHNL_PRIORITY priority);
664 /*******************************************************************************
666 ** Function L2CA_RegForNoCPEvt
668 ** Description Register callback for Number of Completed Packets event.
670 ** Input Param p_cb - callback for Number of completed packets event
671 ** p_bda - BT address of remote device
675 *******************************************************************************/
676 L2C_API extern BOOLEAN L2CA_RegForNoCPEvt(tL2CA_NOCP_CB *p_cb, BD_ADDR p_bda);
678 /*******************************************************************************
680 ** Function L2CA_SetChnlDataRate
682 ** Description Sets the tx/rx data rate for a channel.
684 ** Returns TRUE if a valid channel, else FALSE
686 *******************************************************************************/
687 L2C_API extern BOOLEAN L2CA_SetChnlDataRate (UINT16 cid, tL2CAP_CHNL_DATA_RATE tx, tL2CAP_CHNL_DATA_RATE rx);
689 typedef void (tL2CA_RESERVE_CMPL_CBACK) (void);
691 /*******************************************************************************
693 ** Function L2CA_SetFlushTimeout
695 ** Description This function set the automatic flush time out in Baseband
696 ** for ACL-U packets.
697 ** BdAddr : the remote BD address of ACL link. If it is BT_DB_ANY
698 ** then the flush time out will be applied to all ACL link.
699 ** FlushTimeout: flush time out in ms
700 ** 0x0000 : No automatic flush
701 ** L2CAP_NO_RETRANSMISSION : No retransmission
702 ** 0x0002 - 0xFFFE : flush time out, if (flush_tout*8)+3/5)
703 ** <= HCI_MAX_AUTO_FLUSH_TOUT (in 625us slot).
704 ** Otherwise, return FALSE.
705 ** L2CAP_NO_AUTOMATIC_FLUSH : No automatic flush
707 ** Returns TRUE if command succeeded, FALSE if failed
709 ** NOTE This flush timeout applies to all logical channels active on the
711 *******************************************************************************/
712 L2C_API extern BOOLEAN L2CA_SetFlushTimeout (BD_ADDR bd_addr, UINT16 flush_tout);
714 /*******************************************************************************
716 ** Function L2CA_DataWriteEx
718 ** Description Higher layers call this function to write data with extended
720 ** flags : L2CAP_FLUSHABLE_CH_BASED
721 ** L2CAP_FLUSHABLE_PKT
722 ** L2CAP_NON_FLUSHABLE_PKT
724 ** Returns L2CAP_DW_SUCCESS, if data accepted, else FALSE
725 ** L2CAP_DW_CONGESTED, if data accepted and the channel is congested
726 ** L2CAP_DW_FAILED, if error
728 *******************************************************************************/
729 L2C_API extern UINT8 L2CA_DataWriteEx (UINT16 cid, BT_HDR *p_data, UINT16 flags);
731 /*******************************************************************************
733 ** Function L2CA_SetChnlFlushability
735 ** Description Higher layers call this function to set a channels
736 ** flushability flags
738 ** Returns TRUE if CID found, else FALSE
740 *******************************************************************************/
741 L2C_API extern BOOLEAN L2CA_SetChnlFlushability (UINT16 cid, BOOLEAN is_flushable);
743 /*******************************************************************************
745 ** Function L2CA_GetPeerFeatures
747 ** Description Get a peers features and fixed channel map
749 ** Parameters: BD address of the peer
750 ** Pointers to features and channel mask storage area
752 ** Return value: TRUE if peer is connected
754 *******************************************************************************/
755 L2C_API extern BOOLEAN L2CA_GetPeerFeatures (BD_ADDR bd_addr, UINT32 *p_ext_feat, UINT8 *p_chnl_mask);
757 /*******************************************************************************
759 ** Function L2CA_GetBDAddrbyHandle
761 ** Description Get BD address for the given HCI handle
763 ** Parameters: HCI handle
764 ** BD address of the peer
766 ** Return value: TRUE if found lcb for the given handle, FALSE otherwise
768 *******************************************************************************/
769 L2C_API extern BOOLEAN L2CA_GetBDAddrbyHandle (UINT16 handle, BD_ADDR bd_addr);
771 /*******************************************************************************
773 ** Function L2CA_GetChnlFcrMode
775 ** Description Get the channel FCR mode
777 ** Parameters: Local CID
779 ** Return value: Channel mode
781 *******************************************************************************/
782 L2C_API extern UINT8 L2CA_GetChnlFcrMode (UINT16 lcid);
785 /*******************************************************************************
787 ** UCD callback prototypes
789 *******************************************************************************/
791 /* UCD discovery. Parameters are
792 ** BD Address of remote
796 #define L2CAP_UCD_INFO_TYPE_RECEPTION 0x01
797 #define L2CAP_UCD_INFO_TYPE_MTU 0x02
799 typedef void (tL2CA_UCD_DISCOVER_CB) (BD_ADDR, UINT8, UINT32);
801 /* UCD data received. Parameters are
802 ** BD Address of remote
803 ** Pointer to buffer with data
805 typedef void (tL2CA_UCD_DATA_CB) (BD_ADDR, BT_HDR *);
807 /* Congestion status callback protype. This callback is optional. If
808 ** an application tries to send data when the transmit queue is full,
809 ** the data will anyways be dropped. The parameter is:
811 ** TRUE if congested, FALSE if uncongested
813 typedef void (tL2CA_UCD_CONGESTION_STATUS_CB) (BD_ADDR, BOOLEAN);
815 /* UCD registration info (the callback addresses and PSM)
819 tL2CA_UCD_DISCOVER_CB *pL2CA_UCD_Discover_Cb;
820 tL2CA_UCD_DATA_CB *pL2CA_UCD_Data_Cb;
821 tL2CA_UCD_CONGESTION_STATUS_CB *pL2CA_UCD_Congestion_Status_Cb;
822 } tL2CAP_UCD_CB_INFO;
824 /*******************************************************************************
826 ** Function L2CA_UcdRegister
828 ** Description Register PSM on UCD.
830 ** Parameters: tL2CAP_UCD_CB_INFO
832 ** Return value: TRUE if successs
834 *******************************************************************************/
835 L2C_API extern BOOLEAN L2CA_UcdRegister ( UINT16 psm, tL2CAP_UCD_CB_INFO *p_cb_info );
837 /*******************************************************************************
839 ** Function L2CA_UcdDeregister
841 ** Description Deregister PSM on UCD.
845 ** Return value: TRUE if successs
847 *******************************************************************************/
848 L2C_API extern BOOLEAN L2CA_UcdDeregister ( UINT16 psm );
850 /*******************************************************************************
852 ** Function L2CA_UcdDiscover
854 ** Description Discover UCD of remote device.
857 ** BD_ADDR of remote device
858 ** info_type : L2CAP_UCD_INFO_TYPE_RECEPTION
859 ** L2CAP_UCD_INFO_TYPE_MTU
862 ** Return value: TRUE if successs
864 *******************************************************************************/
865 L2C_API extern BOOLEAN L2CA_UcdDiscover ( UINT16 psm, BD_ADDR rem_bda, UINT8 info_type );
867 /*******************************************************************************
869 ** Function L2CA_UcdDataWrite
871 ** Description Send UCD to remote device
874 ** BD Address of remote
875 ** Pointer to buffer of type BT_HDR
876 ** flags : L2CAP_FLUSHABLE_CH_BASED
877 ** L2CAP_FLUSHABLE_PKT
878 ** L2CAP_NON_FLUSHABLE_PKT
880 ** Return value L2CAP_DW_SUCCESS, if data accepted
881 ** L2CAP_DW_FAILED, if error
883 *******************************************************************************/
884 L2C_API extern UINT16 L2CA_UcdDataWrite (UINT16 psm, BD_ADDR rem_bda, BT_HDR *p_buf, UINT16 flags);
886 /*******************************************************************************
888 ** Function L2CA_UcdSetIdleTimeout
890 ** Description Set UCD Idle timeout.
892 ** Parameters: BD Addr
895 ** Return value: TRUE if successs
897 *******************************************************************************/
898 L2C_API extern BOOLEAN L2CA_UcdSetIdleTimeout ( BD_ADDR rem_bda, UINT16 timeout );
900 /*******************************************************************************
902 ** Function L2CA_UCDSetTxPriority
904 ** Description Sets the transmission priority for a connectionless channel.
906 ** Returns TRUE if a valid channel, else FALSE
908 *******************************************************************************/
909 L2C_API extern BOOLEAN L2CA_UCDSetTxPriority ( BD_ADDR rem_bda, tL2CAP_CHNL_PRIORITY priority );
912 /*******************************************************************************
914 ** Fixed Channel callback prototypes
916 *******************************************************************************/
918 /* Fixed channel connected and disconnected. Parameters are
919 ** BD Address of remote
920 ** TRUE if channel is connected, FALSE if disconnected
921 ** Reason for connection failure
922 ** transport : physical transport, BR/EDR or LE
924 typedef void (tL2CA_FIXED_CHNL_CB) (BD_ADDR, BOOLEAN, UINT16, tBT_TRANSPORT);
926 /* Signalling data received. Parameters are
927 ** BD Address of remote
928 ** Pointer to buffer with data
930 typedef void (tL2CA_FIXED_DATA_CB) (BD_ADDR, BT_HDR *);
932 /* Congestion status callback protype. This callback is optional. If
933 ** an application tries to send data when the transmit queue is full,
934 ** the data will anyways be dropped. The parameter is:
936 ** TRUE if congested, FALSE if uncongested
938 typedef void (tL2CA_FIXED_CONGESTION_STATUS_CB) (BD_ADDR, BOOLEAN);
940 /* Fixed channel registration info (the callback addresses and channel config)
944 tL2CA_FIXED_CHNL_CB *pL2CA_FixedConn_Cb;
945 tL2CA_FIXED_DATA_CB *pL2CA_FixedData_Cb;
946 tL2CA_FIXED_CONGESTION_STATUS_CB *pL2CA_FixedCong_Cb;
947 tL2CAP_FCR_OPTS fixed_chnl_opts;
949 UINT16 default_idle_tout;
950 } tL2CAP_FIXED_CHNL_REG;
953 #if (L2CAP_NUM_FIXED_CHNLS > 0)
954 /*******************************************************************************
956 ** Function L2CA_RegisterFixedChannel
958 ** Description Register a fixed channel.
960 ** Parameters: Fixed Channel #
961 ** Channel Callbacks and config
963 ** Return value: TRUE if registered OK
965 *******************************************************************************/
966 L2C_API extern BOOLEAN L2CA_RegisterFixedChannel (UINT16 fixed_cid, tL2CAP_FIXED_CHNL_REG *p_freg);
968 /*******************************************************************************
970 ** Function L2CA_ConnectFixedChnl
972 ** Description Connect an fixed signalling channel to a remote device.
974 ** Parameters: Fixed CID
975 ** BD Address of remote
977 ** Return value: TRUE if connection started
979 *******************************************************************************/
980 L2C_API extern BOOLEAN L2CA_ConnectFixedChnl (UINT16 fixed_cid, BD_ADDR bd_addr);
982 /*******************************************************************************
984 ** Function L2CA_SendFixedChnlData
986 ** Description Write data on a fixed signalling channel.
988 ** Parameters: Fixed CID
989 ** BD Address of remote
990 ** Pointer to buffer of type BT_HDR
992 ** Return value L2CAP_DW_SUCCESS, if data accepted
993 ** L2CAP_DW_FAILED, if error
995 *******************************************************************************/
996 L2C_API extern UINT16 L2CA_SendFixedChnlData (UINT16 fixed_cid, BD_ADDR rem_bda, BT_HDR *p_buf);
998 /*******************************************************************************
1000 ** Function L2CA_RemoveFixedChnl
1002 ** Description Remove a fixed channel to a remote device.
1004 ** Parameters: Fixed CID
1005 ** BD Address of remote
1006 ** Idle timeout to use (or 0xFFFF if don't care)
1008 ** Return value: TRUE if channel removed
1010 *******************************************************************************/
1011 L2C_API extern BOOLEAN L2CA_RemoveFixedChnl (UINT16 fixed_cid, BD_ADDR rem_bda);
1013 /*******************************************************************************
1015 ** Function L2CA_SetFixedChannelTout
1017 ** Description Higher layers call this function to set the idle timeout for
1018 ** a fixed channel. The "idle timeout" is the amount of time that
1019 ** a connection can remain up with no L2CAP channels on it.
1020 ** A timeout of zero means that the connection will be torn
1021 ** down immediately when the last channel is removed.
1022 ** A timeout of 0xFFFF means no timeout. Values are in seconds.
1023 ** A bd_addr is the remote BD address. If bd_addr = BT_BD_ANY,
1024 ** then the idle timeouts for all active l2cap links will be
1027 ** Returns TRUE if command succeeded, FALSE if failed
1029 *******************************************************************************/
1030 L2C_API extern BOOLEAN L2CA_SetFixedChannelTout (BD_ADDR rem_bda, UINT16 fixed_cid, UINT16 idle_tout);
1032 #endif /* (L2CAP_NUM_FIXED_CHNLS > 0) */
1034 /*******************************************************************************
1036 ** Function L2CA_GetCurrentConfig
1038 ** Description This function returns configurations of L2CAP channel
1039 ** pp_our_cfg : pointer of our saved configuration options
1040 ** p_our_cfg_bits : valid config in bitmap
1041 ** pp_peer_cfg: pointer of peer's saved configuration options
1042 ** p_peer_cfg_bits : valid config in bitmap
1044 ** Returns TRUE if successful
1046 *******************************************************************************/
1047 L2C_API extern BOOLEAN L2CA_GetCurrentConfig (UINT16 lcid,
1048 tL2CAP_CFG_INFO **pp_our_cfg, tL2CAP_CH_CFG_BITS *p_our_cfg_bits,
1049 tL2CAP_CFG_INFO **pp_peer_cfg, tL2CAP_CH_CFG_BITS *p_peer_cfg_bits);
1051 #if (L2CAP_CORRUPT_ERTM_PKTS == TRUE)
1052 /*******************************************************************************
1054 ** Function L2CA_SetupErtmTest
1056 ** Description This function is used for testing purposes only.
1057 ** It corrupts or drops one or more packets used with ERTM channels.
1060 ** cid - channel ID (0 uses RFCOMM PSM's CID)
1062 ** type - type of test to run (L2CAP_FCR_TTYPE_CORR_IFRAMES
1063 ** L2CAP_FCR_TTYPE_CORR_SFRAME
1064 ** L2CAP_FCR_TTYPE_STOP_TEST
1065 ** L2CAP_FCR_TTYPE_GET_CID - returns rfcomm cid only)
1067 ** is_rx - TRUE to corrupt Rx packet, FALSE for Tx packet)
1069 ** freq - L2CAP_FCR_FREQ_RANDOM (turns on random corruptions/drops)
1070 ** L2CAP_FCR_FREQ_NORMAL (turns on test with "count" corruptions/drops)
1072 ** count - number of packets in a row to drop or corrupt
1074 ** Returns CID of channel running test
1076 *******************************************************************************/
1077 L2C_API extern UINT16 L2CA_SetupErtmTest (UINT16 cid, UINT8 type, BOOLEAN is_rx, UINT8 freq, UINT16 count);
1079 /*******************************************************************************
1081 ** Function L2CA_SendPolledSFrame
1083 ** Description This function is used for testing purposes only.
1084 ** It Sends a Polled RR or RNR to the peer
1089 ** sup_type - (L2CAP_FCR_SUP_RR or L2CAP_FCR_SUP_RNR)
1093 *******************************************************************************/
1094 L2C_API extern void L2CA_SendPolledSFrame (UINT16 cid, UINT16 sup_type);
1096 /*******************************************************************************
1098 ** Function L2CA_BypassSFrame
1100 ** Description This function is used for testing purposes only.
1101 ** It skips sending 'count' S-Frames.
1106 ** count - Number of S-Frames to skip sending
1110 *******************************************************************************/
1111 L2C_API extern void L2CA_BypassSFrame (UINT16 cid, UINT8 count);
1113 #endif /* (L2CAP_CORRUPT_ERTM_PKTS == TRUE) */
1116 #if (BLE_INCLUDED == TRUE)
1117 /*******************************************************************************
1119 ** Function L2CA_CancelBleConnectReq
1121 ** Description Cancel a pending connection attempt to a BLE device.
1123 ** Parameters: BD Address of remote
1125 ** Return value: TRUE if connection was cancelled
1127 *******************************************************************************/
1128 L2C_API extern BOOLEAN L2CA_CancelBleConnectReq (BD_ADDR rem_bda);
1130 /*******************************************************************************
1132 ** Function L2CA_UpdateBleConnParams
1134 ** Description Update BLE connection parameters.
1136 ** Parameters: BD Address of remote
1138 ** Return value: TRUE if update started
1140 *******************************************************************************/
1141 L2C_API extern BOOLEAN L2CA_UpdateBleConnParams (BD_ADDR rem_bdRa, UINT16 min_int,
1142 UINT16 max_int, UINT16 latency, UINT16 timeout);
1144 /*******************************************************************************
1146 ** Function L2CA_EnableUpdateBleConnParams
1148 ** Description Update BLE connection parameters.
1150 ** Parameters: BD Address of remote
1153 ** Return value: TRUE if update started
1155 *******************************************************************************/
1156 L2C_API extern BOOLEAN L2CA_EnableUpdateBleConnParams (BD_ADDR rem_bda, BOOLEAN enable);
1158 /*******************************************************************************
1160 ** Function L2CA_GetBleConnRole
1162 ** Description This function returns the connection role.
1164 ** Returns link role.
1166 *******************************************************************************/
1167 L2C_API extern UINT8 L2CA_GetBleConnRole (BD_ADDR bd_addr);
1169 /*******************************************************************************
1171 ** Function L2CA_GetDisconnectReason
1173 ** Description This function returns the disconnect reason code.
1175 ** Parameters: BD Address of remote
1176 ** Physical transport for the L2CAP connection (BR/EDR or LE)
1178 ** Returns disconnect reason
1180 *******************************************************************************/
1181 L2C_API extern UINT16 L2CA_GetDisconnectReason (BD_ADDR remote_bda, tBT_TRANSPORT transport);
1183 #endif /* (BLE_INCLUDED == TRUE) */
1189 #endif /* L2C_API_H */