1/******************************************************************************
2 *
3 *  Copyright (C) 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 "l2cdefs.h"
31#include "hcidefs.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/* Minimum offset for broadcast needs another two bytes for the PSM */
43#define L2CAP_BCST_MIN_OFFSET       11
44
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 */
49
50/* result code for L2CA_DataWrite() */
51#define L2CAP_DW_FAILED        FALSE
52#define L2CAP_DW_SUCCESS       TRUE
53#define L2CAP_DW_CONGESTED     2
54
55/* Values for priority parameter to L2CA_SetAclPriority */
56#define L2CAP_PRIORITY_NORMAL       0
57#define L2CAP_PRIORITY_HIGH         1
58
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
63
64typedef UINT8 tL2CAP_CHNL_PRIORITY;
65
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
71
72typedef UINT8 tL2CAP_CHNL_DATA_RATE;
73
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
80
81
82/* L2CA_FlushChannel num_to_flush definitions */
83#define L2CAP_FLUSH_CHANS_ALL       0xffff
84#define L2CAP_FLUSH_CHANS_GET       0x0000
85
86
87/* special CID for Multi-AV for reporting congestion */
88#define L2CAP_MULTI_AV_CID          0
89
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
93
94/* length of padding for 4 bytes align */
95#define L2CAP_MULTI_AV_PADDING_LEN  2
96
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
100
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
104
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
111
112
113/* Values for 'allowed_modes' field passed in structure tL2CAP_ERTM_INFO
114*/
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)
118
119#define L2CAP_FCR_CHAN_OPT_ALL_MASK (L2CAP_FCR_CHAN_OPT_BASIC | L2CAP_FCR_CHAN_OPT_ERTM | L2CAP_FCR_CHAN_OPT_STREAM)
120
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.
124*/
125#define L2C_INVALID_PSM(psm)    (((psm) & 0x0101) != 0x0001)
126#define L2C_IS_VALID_PSM(psm)   (((psm) & 0x0101) == 0x0001)
127
128/*****************************************************************************
129**  Type Definitions
130*****************************************************************************/
131
132typedef struct
133{
134#define L2CAP_FCR_BASIC_MODE    0x00
135#define L2CAP_FCR_ERTM_MODE     0x03
136#define L2CAP_FCR_STREAM_MODE   0x04
137
138    UINT8  mode;
139
140    UINT8  tx_win_sz;
141    UINT8  max_transmit;
142    UINT16 rtrans_tout;
143    UINT16 mon_tout;
144    UINT16 mps;
145} tL2CAP_FCR_OPTS;
146
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.
150*/
151typedef struct
152{
153    UINT16      result;                 /* Only used in confirm messages */
154    BOOLEAN     mtu_present;
155    UINT16      mtu;
156    BOOLEAN     qos_present;
157    FLOW_SPEC   qos;
158    BOOLEAN     flush_to_present;
159    UINT16      flush_to;
160    BOOLEAN     fcr_present;
161    tL2CAP_FCR_OPTS fcr;
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 */
167} tL2CAP_CFG_INFO;
168
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
176
177typedef UINT16 tL2CAP_CH_CFG_BITS;
178
179/*********************************
180**  Callback Functions Prototypes
181**********************************/
182
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
188*/
189typedef void (tL2CA_CONNECT_IND_CB) (BD_ADDR, UINT16, UINT16, UINT8);
190
191
192/* Connection confirmation callback prototype. Parameters are
193**              Local CID
194**              Result - 0 = connected, non-zero means failure reason
195*/
196typedef void (tL2CA_CONNECT_CFM_CB) (UINT16, UINT16);
197
198
199/* Connection pending callback prototype. Parameters are
200**              Local CID
201*/
202typedef void (tL2CA_CONNECT_PND_CB) (UINT16);
203
204
205/* Configuration indication callback prototype. Parameters are
206**              Local CID assigned to the connection
207**              Pointer to configuration info
208*/
209typedef void (tL2CA_CONFIG_IND_CB) (UINT16, tL2CAP_CFG_INFO *);
210
211
212/* Configuration confirm callback prototype. Parameters are
213**              Local CID assigned to the connection
214**              Pointer to configuration info
215*/
216typedef void (tL2CA_CONFIG_CFM_CB) (UINT16, tL2CAP_CFG_INFO *);
217
218
219/* Disconnect indication callback prototype. Parameters are
220**              Local CID
221**              Boolean whether upper layer should ack this
222*/
223typedef void (tL2CA_DISCONNECT_IND_CB) (UINT16, BOOLEAN);
224
225
226/* Disconnect confirm callback prototype. Parameters are
227**              Local CID
228**              Result
229*/
230typedef void (tL2CA_DISCONNECT_CFM_CB) (UINT16, UINT16);
231
232
233/* QOS Violation indication callback prototype. Parameters are
234**              BD Address of violating device
235*/
236typedef void (tL2CA_QOS_VIOLATION_IND_CB) (BD_ADDR);
237
238
239/* Data received indication callback prototype. Parameters are
240**              Local CID
241**              Address of buffer
242*/
243typedef void (tL2CA_DATA_IND_CB) (UINT16, BT_HDR *);
244
245
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
249**              Result
250*/
251typedef void (tL2CA_ECHO_RSP_CB) (UINT16);
252
253
254/* Callback function prototype to pass broadcom specific echo response  */
255/* to the upper layer                                                   */
256typedef void (tL2CA_ECHO_DATA_CB) (BD_ADDR, UINT16, UINT8 *);
257
258
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:
262**              Local CID
263**              TRUE if congested, FALSE if uncongested
264*/
265typedef void (tL2CA_CONGESTION_STATUS_CB) (UINT16, BOOLEAN);
266
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.
271** The parameter is:
272**          peer BD_ADDR
273*/
274typedef void (tL2CA_NOCP_CB) (BD_ADDR);
275
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:
280**              Local CID
281**              Number of SDUs sent or dropped
282*/
283typedef void (tL2CA_TX_COMPLETE_CB) (UINT16, UINT16);
284
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.
289*/
290typedef struct
291{
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;
303
304} tL2CAP_APPL_INFO;
305
306/* Define the structure that applications use to create or accept
307** connections with enhanced retransmission mode.
308*/
309typedef struct
310{
311    UINT8       preferred_mode;
312    UINT8       allowed_modes;
313    UINT8       user_rx_pool_id;
314    UINT8       user_tx_pool_id;
315    UINT8       fcr_rx_pool_id;
316    UINT8       fcr_tx_pool_id;
317
318} tL2CAP_ERTM_INFO;
319
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,d)   L2CA_ErtmConnectReq(a,b,c)
323#define L2CA_CONNECT_RSP(a,b,c,d,e,f,g) 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)
329
330/*****************************************************************************
331**  External Function Declarations
332*****************************************************************************/
333#ifdef __cplusplus
334extern "C"
335{
336#endif
337
338/*******************************************************************************
339**
340** Function         L2CA_Register
341**
342** Description      Other layers call this function to register for L2CAP
343**                  services.
344**
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().
350**
351*******************************************************************************/
352extern UINT16 L2CA_Register (UINT16 psm, tL2CAP_APPL_INFO *p_cb_info);
353
354/*******************************************************************************
355**
356** Function         L2CA_Deregister
357**
358** Description      Other layers call this function to deregister for L2CAP
359**                  services.
360**
361** Returns          void
362**
363*******************************************************************************/
364extern void L2CA_Deregister (UINT16 psm);
365
366/*******************************************************************************
367**
368** Function         L2CA_AllocatePSM
369**
370** Description      Other layers call this function to find an unused PSM for L2CAP
371**                  services.
372**
373** Returns          PSM to use.
374**
375*******************************************************************************/
376extern UINT16 L2CA_AllocatePSM(void);
377
378/*******************************************************************************
379**
380** Function         L2CA_ConnectReq
381**
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.
386**
387** Returns          the CID of the connection, or 0 if it failed to start
388**
389*******************************************************************************/
390extern UINT16 L2CA_ConnectReq (UINT16 psm, BD_ADDR 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*******************************************************************************/
403extern BOOLEAN L2CA_ConnectRsp (BD_ADDR p_bd_addr, UINT8 id, UINT16 lcid,
404                                        UINT16 result, UINT16 status);
405
406/*******************************************************************************
407**
408** Function         L2CA_ErtmConnectReq
409**
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.
415**
416** Returns          the CID of the connection, or 0 if it failed to start
417**
418*******************************************************************************/
419extern UINT16 L2CA_ErtmConnectReq (UINT16 psm, BD_ADDR p_bd_addr,
420                                           tL2CAP_ERTM_INFO *p_ertm_info);
421
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).
427bool L2CA_SetConnectionCallbacks(uint16_t local_cid, const tL2CAP_APPL_INFO *callbacks);
428
429/*******************************************************************************
430**
431** Function         L2CA_ErtmConnectRsp
432**
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.
437**
438** Returns          TRUE for success, FALSE for failure
439**
440*******************************************************************************/
441extern BOOLEAN  L2CA_ErtmConnectRsp (BD_ADDR p_bd_addr, UINT8 id, UINT16 lcid,
442                                             UINT16 result, UINT16 status,
443                                             tL2CAP_ERTM_INFO *p_ertm_info);
444
445/*******************************************************************************
446**
447** Function         L2CA_ConfigReq
448**
449** Description      Higher layers call this function to send configuration.
450**
451** Returns          TRUE if configuration sent, else FALSE
452**
453*******************************************************************************/
454extern BOOLEAN L2CA_ConfigReq (UINT16 cid, tL2CAP_CFG_INFO *p_cfg);
455
456/*******************************************************************************
457**
458** Function         L2CA_ConfigRsp
459**
460** Description      Higher layers call this function to send a configuration
461**                  response.
462**
463** Returns          TRUE if configuration response sent, else FALSE
464**
465*******************************************************************************/
466extern BOOLEAN L2CA_ConfigRsp (UINT16 cid, tL2CAP_CFG_INFO *p_cfg);
467
468/*******************************************************************************
469**
470** Function         L2CA_DisconnectReq
471**
472** Description      Higher layers call this function to disconnect a channel.
473**
474** Returns          TRUE if disconnect sent, else FALSE
475**
476*******************************************************************************/
477extern BOOLEAN L2CA_DisconnectReq (UINT16 cid);
478
479/*******************************************************************************
480**
481** Function         L2CA_DisconnectRsp
482**
483** Description      Higher layers call this function to acknowledge the
484**                  disconnection of a channel.
485**
486** Returns          void
487**
488*******************************************************************************/
489extern BOOLEAN L2CA_DisconnectRsp (UINT16 cid);
490
491/*******************************************************************************
492**
493** Function         L2CA_DataWrite
494**
495** Description      Higher layers call this function to write data.
496**
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
500**
501*******************************************************************************/
502extern UINT8 L2CA_DataWrite (UINT16 cid, BT_HDR *p_data);
503
504/*******************************************************************************
505**
506** Function         L2CA_Ping
507**
508** Description      Higher layers call this function to send an echo request.
509**
510** Returns          TRUE if echo request sent, else FALSE.
511**
512*******************************************************************************/
513extern BOOLEAN L2CA_Ping (BD_ADDR p_bd_addr, tL2CA_ECHO_RSP_CB *p_cb);
514
515/*******************************************************************************
516**
517** Function         L2CA_Echo
518**
519** Description      Higher layers call this function to send an echo request
520**                  with application-specific data.
521**
522** Returns          TRUE if echo request sent, else FALSE.
523**
524*******************************************************************************/
525extern BOOLEAN  L2CA_Echo (BD_ADDR p_bd_addr, BT_HDR *p_data, tL2CA_ECHO_DATA_CB *p_callback);
526
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.
531bool L2CA_GetIdentifiers(uint16_t lcid, uint16_t *rcid, uint16_t *handle);
532
533/*******************************************************************************
534**
535** Function         L2CA_SetIdleTimeout
536**
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
543**                  in seconds.
544**
545** Returns          TRUE if command succeeded, FALSE if failed
546**
547*******************************************************************************/
548extern BOOLEAN L2CA_SetIdleTimeout (UINT16 cid, UINT16 timeout,
549                                            BOOLEAN is_global);
550
551/*******************************************************************************
552**
553** Function         L2CA_SetIdleTimeoutByBdAddr
554**
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
563**                  changed.
564**
565** Returns          TRUE if command succeeded, FALSE if failed
566**
567** NOTE             This timeout applies to all logical channels active on the
568**                  ACL link.
569*******************************************************************************/
570extern BOOLEAN L2CA_SetIdleTimeoutByBdAddr(BD_ADDR bd_addr, UINT16 timeout,
571                                           tBT_TRANSPORT transport);
572
573/*******************************************************************************
574**
575** Function         L2CA_SetTraceLevel
576**
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.
579**
580** Returns          the new (current) trace level
581**
582*******************************************************************************/
583extern UINT8 L2CA_SetTraceLevel (UINT8 trace_level);
584
585/*******************************************************************************
586**
587** Function     L2CA_SetDesireRole
588**
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.
594**
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.
597**
598** Returns      the new (current) role
599**
600*******************************************************************************/
601extern UINT8 L2CA_SetDesireRole (UINT8 new_role);
602
603/*******************************************************************************
604**
605** Function     L2CA_LocalLoopbackReq
606**
607** Description  This function sets up a CID for local loopback
608**
609** Returns      CID of 0 if none.
610**
611*******************************************************************************/
612extern UINT16 L2CA_LocalLoopbackReq (UINT16 psm, UINT16 handle, BD_ADDR p_bd_addr);
613
614/*******************************************************************************
615**
616** Function     L2CA_FlushChannel
617**
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
623**              buffers to flush.
624**
625** Returns      Number of buffers left queued for that CID
626**
627*******************************************************************************/
628extern UINT16   L2CA_FlushChannel (UINT16 lcid, UINT16 num_to_flush);
629
630
631/*******************************************************************************
632**
633** Function         L2CA_SetAclPriority
634**
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).
638**
639** Returns          TRUE if a valid channel, else FALSE
640**
641*******************************************************************************/
642extern BOOLEAN L2CA_SetAclPriority (BD_ADDR bd_addr, UINT8 priority);
643
644/*******************************************************************************
645**
646** Function         L2CA_FlowControl
647**
648** Description      Higher layers call this function to flow control a channel.
649**
650**                  data_enabled - TRUE data flows, FALSE data is stopped
651**
652** Returns          TRUE if valid channel, else FALSE
653**
654*******************************************************************************/
655extern BOOLEAN L2CA_FlowControl (UINT16 cid, BOOLEAN data_enabled);
656
657/*******************************************************************************
658**
659** Function         L2CA_SendTestSFrame
660**
661** Description      Higher layers call this function to send a test S-frame.
662**
663** Returns          TRUE if valid Channel, else FALSE
664**
665*******************************************************************************/
666extern BOOLEAN L2CA_SendTestSFrame (UINT16 cid, UINT8 sup_type,
667                                            UINT8 back_track);
668
669/*******************************************************************************
670**
671** Function         L2CA_SetTxPriority
672**
673** Description      Sets the transmission priority for a channel. (FCR Mode)
674**
675** Returns          TRUE if a valid channel, else FALSE
676**
677*******************************************************************************/
678extern BOOLEAN L2CA_SetTxPriority (UINT16 cid, tL2CAP_CHNL_PRIORITY priority);
679
680/*******************************************************************************
681**
682** Function         L2CA_RegForNoCPEvt
683**
684** Description      Register callback for Number of Completed Packets event.
685**
686** Input Param      p_cb - callback for Number of completed packets event
687**                  p_bda - BT address of remote device
688**
689** Returns
690**
691*******************************************************************************/
692extern BOOLEAN L2CA_RegForNoCPEvt(tL2CA_NOCP_CB *p_cb, BD_ADDR p_bda);
693
694/*******************************************************************************
695**
696** Function         L2CA_SetChnlDataRate
697**
698** Description      Sets the tx/rx data rate for a channel.
699**
700** Returns          TRUE if a valid channel, else FALSE
701**
702*******************************************************************************/
703extern BOOLEAN L2CA_SetChnlDataRate (UINT16 cid, tL2CAP_CHNL_DATA_RATE tx, tL2CAP_CHNL_DATA_RATE rx);
704
705typedef void (tL2CA_RESERVE_CMPL_CBACK) (void);
706
707/*******************************************************************************
708**
709** Function         L2CA_SetFlushTimeout
710**
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
722**
723** Returns          TRUE if command succeeded, FALSE if failed
724**
725** NOTE             This flush timeout applies to all logical channels active on the
726**                  ACL link.
727*******************************************************************************/
728extern BOOLEAN L2CA_SetFlushTimeout (BD_ADDR bd_addr, UINT16 flush_tout);
729
730/*******************************************************************************
731**
732** Function         L2CA_DataWriteEx
733**
734** Description      Higher layers call this function to write data with extended
735**                  flags.
736**                  flags : L2CAP_FLUSHABLE_CH_BASED
737**                          L2CAP_FLUSHABLE_PKT
738**                          L2CAP_NON_FLUSHABLE_PKT
739**
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
743**
744*******************************************************************************/
745extern UINT8 L2CA_DataWriteEx (UINT16 cid, BT_HDR *p_data, UINT16 flags);
746
747/*******************************************************************************
748**
749** Function         L2CA_SetChnlFlushability
750**
751** Description      Higher layers call this function to set a channels
752**                  flushability flags
753**
754** Returns          TRUE if CID found, else FALSE
755**
756*******************************************************************************/
757extern BOOLEAN L2CA_SetChnlFlushability (UINT16 cid, BOOLEAN is_flushable);
758
759/*******************************************************************************
760**
761**  Function         L2CA_GetPeerFeatures
762**
763**  Description      Get a peers features and fixed channel map
764**
765**  Parameters:      BD address of the peer
766**                   Pointers to features and channel mask storage area
767**
768**  Return value:    TRUE if peer is connected
769**
770*******************************************************************************/
771extern BOOLEAN L2CA_GetPeerFeatures (BD_ADDR bd_addr, UINT32 *p_ext_feat, UINT8 *p_chnl_mask);
772
773/*******************************************************************************
774**
775**  Function         L2CA_GetBDAddrbyHandle
776**
777**  Description      Get BD address for the given HCI handle
778**
779**  Parameters:      HCI handle
780**                   BD address of the peer
781**
782**  Return value:    TRUE if found lcb for the given handle, FALSE otherwise
783**
784*******************************************************************************/
785extern BOOLEAN L2CA_GetBDAddrbyHandle (UINT16 handle, BD_ADDR bd_addr);
786
787/*******************************************************************************
788**
789**  Function         L2CA_GetChnlFcrMode
790**
791**  Description      Get the channel FCR mode
792**
793**  Parameters:      Local CID
794**
795**  Return value:    Channel mode
796**
797*******************************************************************************/
798extern UINT8 L2CA_GetChnlFcrMode (UINT16 lcid);
799
800
801/*******************************************************************************
802**
803**                      UCD callback prototypes
804**
805*******************************************************************************/
806
807/* UCD discovery. Parameters are
808**      BD Address of remote
809**      Data Type
810**      Data
811*/
812#define L2CAP_UCD_INFO_TYPE_RECEPTION   0x01
813#define L2CAP_UCD_INFO_TYPE_MTU         0x02
814
815typedef void (tL2CA_UCD_DISCOVER_CB) (BD_ADDR, UINT8, UINT32);
816
817/* UCD data received. Parameters are
818**      BD Address of remote
819**      Pointer to buffer with data
820*/
821typedef void (tL2CA_UCD_DATA_CB) (BD_ADDR, BT_HDR *);
822
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:
826**              remote BD_ADDR
827**              TRUE if congested, FALSE if uncongested
828*/
829typedef void (tL2CA_UCD_CONGESTION_STATUS_CB) (BD_ADDR, BOOLEAN);
830
831/* UCD registration info (the callback addresses and PSM)
832*/
833typedef struct
834{
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;
839
840/*******************************************************************************
841**
842**  Function        L2CA_UcdRegister
843**
844**  Description     Register PSM on UCD.
845**
846**  Parameters:     tL2CAP_UCD_CB_INFO
847**
848**  Return value:   TRUE if successs
849**
850*******************************************************************************/
851extern BOOLEAN L2CA_UcdRegister ( UINT16 psm, tL2CAP_UCD_CB_INFO *p_cb_info );
852
853/*******************************************************************************
854**
855**  Function        L2CA_UcdDeregister
856**
857**  Description     Deregister PSM on UCD.
858**
859**  Parameters:     PSM
860**
861**  Return value:   TRUE if successs
862**
863*******************************************************************************/
864extern BOOLEAN L2CA_UcdDeregister ( UINT16 psm );
865
866/*******************************************************************************
867**
868**  Function        L2CA_UcdDiscover
869**
870**  Description     Discover UCD of remote device.
871**
872**  Parameters:     PSM
873**                  BD_ADDR of remote device
874**                  info_type : L2CAP_UCD_INFO_TYPE_RECEPTION
875**                              L2CAP_UCD_INFO_TYPE_MTU
876**
877**
878**  Return value:   TRUE if successs
879**
880*******************************************************************************/
881extern BOOLEAN L2CA_UcdDiscover ( UINT16 psm, BD_ADDR rem_bda, UINT8 info_type );
882
883/*******************************************************************************
884**
885**  Function        L2CA_UcdDataWrite
886**
887**  Description     Send UCD to remote device
888**
889**  Parameters:     PSM
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
895**
896** Return value     L2CAP_DW_SUCCESS, if data accepted
897**                  L2CAP_DW_FAILED,  if error
898**
899*******************************************************************************/
900extern UINT16 L2CA_UcdDataWrite (UINT16 psm, BD_ADDR rem_bda, BT_HDR *p_buf, UINT16 flags);
901
902/*******************************************************************************
903**
904**  Function        L2CA_UcdSetIdleTimeout
905**
906**  Description     Set UCD Idle timeout.
907**
908**  Parameters:     BD Addr
909**                  Timeout in second
910**
911**  Return value:   TRUE if successs
912**
913*******************************************************************************/
914extern BOOLEAN L2CA_UcdSetIdleTimeout ( BD_ADDR rem_bda, UINT16 timeout );
915
916/*******************************************************************************
917**
918** Function         L2CA_UCDSetTxPriority
919**
920** Description      Sets the transmission priority for a connectionless channel.
921**
922** Returns          TRUE if a valid channel, else FALSE
923**
924*******************************************************************************/
925extern BOOLEAN L2CA_UCDSetTxPriority ( BD_ADDR rem_bda, tL2CAP_CHNL_PRIORITY priority );
926
927
928/*******************************************************************************
929**
930**                      Fixed Channel callback prototypes
931**
932*******************************************************************************/
933
934/* Fixed channel connected and disconnected. Parameters are
935**      channel
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
940*/
941typedef void (tL2CA_FIXED_CHNL_CB) (UINT16, BD_ADDR, BOOLEAN, UINT16, tBT_TRANSPORT);
942
943/* Signalling data received. Parameters are
944**      channel
945**      BD Address of remote
946**      Pointer to buffer with data
947*/
948typedef void (tL2CA_FIXED_DATA_CB) (UINT16, BD_ADDR, BT_HDR *);
949
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:
953**      remote BD_ADDR
954**      TRUE if congested, FALSE if uncongested
955*/
956typedef void (tL2CA_FIXED_CONGESTION_STATUS_CB) (BD_ADDR, BOOLEAN);
957
958/* Fixed channel registration info (the callback addresses and channel config)
959*/
960typedef struct
961{
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;
966
967    UINT16                  default_idle_tout;
968    tL2CA_TX_COMPLETE_CB    *pL2CA_FixedTxComplete_Cb; /* fixed channel tx complete callback */
969} tL2CAP_FIXED_CHNL_REG;
970
971
972#if (L2CAP_NUM_FIXED_CHNLS > 0)
973/*******************************************************************************
974**
975**  Function        L2CA_RegisterFixedChannel
976**
977**  Description     Register a fixed channel.
978**
979**  Parameters:     Fixed Channel #
980**                  Channel Callbacks and config
981**
982**  Return value:   TRUE if registered OK
983**
984*******************************************************************************/
985extern BOOLEAN  L2CA_RegisterFixedChannel (UINT16 fixed_cid, tL2CAP_FIXED_CHNL_REG *p_freg);
986
987/*******************************************************************************
988**
989**  Function        L2CA_ConnectFixedChnl
990**
991**  Description     Connect an fixed signalling channel to a remote device.
992**
993**  Parameters:     Fixed CID
994**                  BD Address of remote
995**
996**  Return value:   TRUE if connection started
997**
998*******************************************************************************/
999extern BOOLEAN L2CA_ConnectFixedChnl (UINT16 fixed_cid, BD_ADDR bd_addr);
1000
1001/*******************************************************************************
1002**
1003**  Function        L2CA_SendFixedChnlData
1004**
1005**  Description     Write data on a fixed signalling channel.
1006**
1007**  Parameters:     Fixed CID
1008**                  BD Address of remote
1009**                  Pointer to buffer of type BT_HDR
1010**
1011** Return value     L2CAP_DW_SUCCESS, if data accepted
1012**                  L2CAP_DW_FAILED,  if error
1013**
1014*******************************************************************************/
1015extern UINT16 L2CA_SendFixedChnlData (UINT16 fixed_cid, BD_ADDR rem_bda, BT_HDR *p_buf);
1016
1017/*******************************************************************************
1018**
1019**  Function        L2CA_RemoveFixedChnl
1020**
1021**  Description     Remove a fixed channel to a remote device.
1022**
1023**  Parameters:     Fixed CID
1024**                  BD Address of remote
1025**                  Idle timeout to use (or 0xFFFF if don't care)
1026**
1027**  Return value:   TRUE if channel removed
1028**
1029*******************************************************************************/
1030extern BOOLEAN L2CA_RemoveFixedChnl (UINT16 fixed_cid, BD_ADDR rem_bda);
1031
1032/*******************************************************************************
1033**
1034** Function         L2CA_SetFixedChannelTout
1035**
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
1044**                  changed.
1045**
1046** Returns          TRUE if command succeeded, FALSE if failed
1047**
1048*******************************************************************************/
1049extern BOOLEAN L2CA_SetFixedChannelTout (BD_ADDR rem_bda, UINT16 fixed_cid, UINT16 idle_tout);
1050
1051#endif /* (L2CAP_NUM_FIXED_CHNLS > 0) */
1052
1053/*******************************************************************************
1054**
1055** Function     L2CA_GetCurrentConfig
1056**
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
1062**
1063** Returns      TRUE if successful
1064**
1065*******************************************************************************/
1066extern 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);
1069
1070#if (BLE_INCLUDED == TRUE)
1071/*******************************************************************************
1072**
1073**  Function        L2CA_CancelBleConnectReq
1074**
1075**  Description     Cancel a pending connection attempt to a BLE device.
1076**
1077**  Parameters:     BD Address of remote
1078**
1079**  Return value:   TRUE if connection was cancelled
1080**
1081*******************************************************************************/
1082extern BOOLEAN L2CA_CancelBleConnectReq (BD_ADDR rem_bda);
1083
1084/*******************************************************************************
1085**
1086**  Function        L2CA_UpdateBleConnParams
1087**
1088**  Description     Update BLE connection parameters.
1089**
1090**  Parameters:     BD Address of remote
1091**
1092**  Return value:   TRUE if update started
1093**
1094*******************************************************************************/
1095extern BOOLEAN L2CA_UpdateBleConnParams (BD_ADDR rem_bdRa, UINT16 min_int,
1096                                         UINT16 max_int, UINT16 latency, UINT16 timeout);
1097
1098/*******************************************************************************
1099**
1100**  Function        L2CA_EnableUpdateBleConnParams
1101**
1102**  Description     Update BLE connection parameters.
1103**
1104**  Parameters:     BD Address of remote
1105**                  enable flag
1106**
1107**  Return value:   TRUE if update started
1108**
1109*******************************************************************************/
1110extern BOOLEAN L2CA_EnableUpdateBleConnParams (BD_ADDR rem_bda, BOOLEAN enable);
1111
1112/*******************************************************************************
1113**
1114** Function         L2CA_GetBleConnRole
1115**
1116** Description      This function returns the connection role.
1117**
1118** Returns          link role.
1119**
1120*******************************************************************************/
1121extern UINT8 L2CA_GetBleConnRole (BD_ADDR bd_addr);
1122
1123/*******************************************************************************
1124**
1125** Function         L2CA_GetDisconnectReason
1126**
1127** Description      This function returns the disconnect reason code.
1128**
1129**  Parameters:     BD Address of remote
1130**                         Physical transport for the L2CAP connection (BR/EDR or LE)
1131**
1132** Returns          disconnect reason
1133**
1134*******************************************************************************/
1135extern UINT16 L2CA_GetDisconnectReason (BD_ADDR remote_bda, tBT_TRANSPORT transport);
1136
1137#endif /* (BLE_INCLUDED == TRUE) */
1138
1139#ifdef __cplusplus
1140}
1141#endif
1142
1143#endif  /* L2C_API_H */
1144