• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "bt_target.h"
28 #include "l2cdefs.h"
29 #include "hcidefs.h"
30 
31 /*****************************************************************************
32 **  Constants
33 *****************************************************************************/
34 
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
37 */
38 #define L2CAP_MIN_OFFSET    13     /* plus control(2), SDU length(2) */
39 
40 /* Minimum offset for broadcast needs another two bytes for the PSM */
41 #define L2CAP_BCST_MIN_OFFSET       11
42 
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 */
47 
48 /* result code for L2CA_DataWrite() */
49 #define L2CAP_DW_FAILED        FALSE
50 #define L2CAP_DW_SUCCESS       TRUE
51 #define L2CAP_DW_CONGESTED     2
52 
53 /* Values for priority parameter to L2CA_SetAclPriority */
54 #define L2CAP_PRIORITY_NORMAL       0
55 #define L2CAP_PRIORITY_HIGH         1
56 
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
61 
62 typedef UINT8 tL2CAP_CHNL_PRIORITY;
63 
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
69 
70 typedef UINT8 tL2CAP_CHNL_DATA_RATE;
71 
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
78 
79 
80 /* L2CA_FlushChannel num_to_flush definitions */
81 #define L2CAP_FLUSH_CHANS_ALL       0xffff
82 #define L2CAP_FLUSH_CHANS_GET       0x0000
83 
84 
85 /* special CID for Multi-AV for reporting congestion */
86 #define L2CAP_MULTI_AV_CID          0
87 
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
91 
92 /* length of padding for 4 bytes align */
93 #define L2CAP_MULTI_AV_PADDING_LEN  2
94 
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
98 
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
102 
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
109 
110 
111 /* Values for 'allowed_modes' field passed in structure tL2CAP_ERTM_INFO
112 */
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)
116 
117 #define L2CAP_FCR_CHAN_OPT_ALL_MASK (L2CAP_FCR_CHAN_OPT_BASIC | L2CAP_FCR_CHAN_OPT_ERTM | L2CAP_FCR_CHAN_OPT_STREAM)
118 
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.
122 */
123 #define L2C_INVALID_PSM(psm)    (((psm) & 0x0101) != 0x0001)
124 #define L2C_IS_VALID_PSM(psm)   (((psm) & 0x0101) == 0x0001)
125 
126 /*****************************************************************************
127 **  Type Definitions
128 *****************************************************************************/
129 
130 typedef struct
131 {
132 #define L2CAP_FCR_BASIC_MODE    0x00
133 #define L2CAP_FCR_ERTM_MODE     0x03
134 #define L2CAP_FCR_STREAM_MODE   0x04
135 
136     UINT8  mode;
137 
138     UINT8  tx_win_sz;
139     UINT8  max_transmit;
140     UINT16 rtrans_tout;
141     UINT16 mon_tout;
142     UINT16 mps;
143 } tL2CAP_FCR_OPTS;
144 
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.
148 */
149 typedef struct
150 {
151     UINT16      result;                 /* Only used in confirm messages */
152     BOOLEAN     mtu_present;
153     UINT16      mtu;
154     BOOLEAN     qos_present;
155     FLOW_SPEC   qos;
156     BOOLEAN     flush_to_present;
157     UINT16      flush_to;
158     BOOLEAN     fcr_present;
159     tL2CAP_FCR_OPTS fcr;
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 */
165 } tL2CAP_CFG_INFO;
166 
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
174 
175 typedef UINT16 tL2CAP_CH_CFG_BITS;
176 
177 /*********************************
178 **  Callback Functions Prototypes
179 **********************************/
180 
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
186 */
187 typedef void (tL2CA_CONNECT_IND_CB) (BD_ADDR, UINT16, UINT16, UINT8);
188 
189 
190 /* Connection confirmation callback prototype. Parameters are
191 **              Local CID
192 **              Result - 0 = connected, non-zero means failure reason
193 */
194 typedef void (tL2CA_CONNECT_CFM_CB) (UINT16, UINT16);
195 
196 
197 /* Connection pending callback prototype. Parameters are
198 **              Local CID
199 */
200 typedef void (tL2CA_CONNECT_PND_CB) (UINT16);
201 
202 
203 /* Configuration indication callback prototype. Parameters are
204 **              Local CID assigned to the connection
205 **              Pointer to configuration info
206 */
207 typedef void (tL2CA_CONFIG_IND_CB) (UINT16, tL2CAP_CFG_INFO *);
208 
209 
210 /* Configuration confirm callback prototype. Parameters are
211 **              Local CID assigned to the connection
212 **              Pointer to configuration info
213 */
214 typedef void (tL2CA_CONFIG_CFM_CB) (UINT16, tL2CAP_CFG_INFO *);
215 
216 
217 /* Disconnect indication callback prototype. Parameters are
218 **              Local CID
219 **              Boolean whether upper layer should ack this
220 */
221 typedef void (tL2CA_DISCONNECT_IND_CB) (UINT16, BOOLEAN);
222 
223 
224 /* Disconnect confirm callback prototype. Parameters are
225 **              Local CID
226 **              Result
227 */
228 typedef void (tL2CA_DISCONNECT_CFM_CB) (UINT16, UINT16);
229 
230 
231 /* QOS Violation indication callback prototype. Parameters are
232 **              BD Address of violating device
233 */
234 typedef void (tL2CA_QOS_VIOLATION_IND_CB) (BD_ADDR);
235 
236 
237 /* Data received indication callback prototype. Parameters are
238 **              Local CID
239 **              Address of buffer
240 */
241 typedef void (tL2CA_DATA_IND_CB) (UINT16, BT_HDR *);
242 
243 
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
247 **              Result
248 */
249 typedef void (tL2CA_ECHO_RSP_CB) (UINT16);
250 
251 
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 *);
255 
256 
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:
260 **              Local CID
261 **              TRUE if congested, FALSE if uncongested
262 */
263 typedef void (tL2CA_CONGESTION_STATUS_CB) (UINT16, BOOLEAN);
264 
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.
269 ** The parameter is:
270 **          peer BD_ADDR
271 */
272 typedef void (tL2CA_NOCP_CB) (BD_ADDR);
273 
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:
278 **              Local CID
279 **              Number of SDUs sent or dropped
280 */
281 typedef void (tL2CA_TX_COMPLETE_CB) (UINT16, UINT16);
282 
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.
287 */
288 typedef struct
289 {
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;
301 
302 } tL2CAP_APPL_INFO;
303 
304 /* Define the structure that applications use to create or accept
305 ** connections with enhanced retransmission mode.
306 */
307 typedef struct
308 {
309     UINT8       preferred_mode;
310     UINT8       allowed_modes;
311     UINT8       user_rx_pool_id;
312     UINT8       user_tx_pool_id;
313     UINT8       fcr_rx_pool_id;
314     UINT8       fcr_tx_pool_id;
315 
316 } tL2CAP_ERTM_INFO;
317 
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)
327 
328 /*****************************************************************************
329 **  External Function Declarations
330 *****************************************************************************/
331 #ifdef __cplusplus
332 extern "C"
333 {
334 #endif
335 
336 /*******************************************************************************
337 **
338 ** Function         L2CA_Register
339 **
340 ** Description      Other layers call this function to register for L2CAP
341 **                  services.
342 **
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().
348 **
349 *******************************************************************************/
350 L2C_API extern UINT16 L2CA_Register (UINT16 psm, tL2CAP_APPL_INFO *p_cb_info);
351 
352 /*******************************************************************************
353 **
354 ** Function         L2CA_Deregister
355 **
356 ** Description      Other layers call this function to deregister for L2CAP
357 **                  services.
358 **
359 ** Returns          void
360 **
361 *******************************************************************************/
362 L2C_API extern void L2CA_Deregister (UINT16 psm);
363 
364 /*******************************************************************************
365 **
366 ** Function         L2CA_AllocatePSM
367 **
368 ** Description      Other layers call this function to find an unused PSM for L2CAP
369 **                  services.
370 **
371 ** Returns          PSM to use.
372 **
373 *******************************************************************************/
374 L2C_API extern UINT16 L2CA_AllocatePSM(void);
375 
376 /*******************************************************************************
377 **
378 ** Function         L2CA_ConnectReq
379 **
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.
384 **
385 ** Returns          the CID of the connection, or 0 if it failed to start
386 **
387 *******************************************************************************/
388 L2C_API extern UINT16 L2CA_ConnectReq (UINT16 psm, BD_ADDR p_bd_addr);
389 
390 /*******************************************************************************
391 **
392 ** Function         L2CA_ConnectRsp
393 **
394 ** Description      Higher layers call this function to accept an incoming
395 **                  L2CAP connection, for which they had gotten an connect
396 **                  indication callback.
397 **
398 ** Returns          TRUE for success, FALSE for failure
399 **
400 *******************************************************************************/
401 L2C_API extern BOOLEAN L2CA_ConnectRsp (BD_ADDR p_bd_addr, UINT8 id, UINT16 lcid,
402                                         UINT16 result, UINT16 status);
403 
404 /*******************************************************************************
405 **
406 ** Function         L2CA_ErtmConnectReq
407 **
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.
413 **
414 ** Returns          the CID of the connection, or 0 if it failed to start
415 **
416 *******************************************************************************/
417 L2C_API extern UINT16 L2CA_ErtmConnectReq (UINT16 psm, BD_ADDR p_bd_addr,
418                                            tL2CAP_ERTM_INFO *p_ertm_info);
419 
420 /*******************************************************************************
421 **
422 ** Function         L2CA_ErtmConnectRsp
423 **
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.
428 **
429 ** Returns          TRUE for success, FALSE for failure
430 **
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);
435 
436 /*******************************************************************************
437 **
438 ** Function         L2CA_ConfigReq
439 **
440 ** Description      Higher layers call this function to send configuration.
441 **
442 ** Returns          TRUE if configuration sent, else FALSE
443 **
444 *******************************************************************************/
445 L2C_API extern BOOLEAN L2CA_ConfigReq (UINT16 cid, tL2CAP_CFG_INFO *p_cfg);
446 
447 /*******************************************************************************
448 **
449 ** Function         L2CA_ConfigRsp
450 **
451 ** Description      Higher layers call this function to send a configuration
452 **                  response.
453 **
454 ** Returns          TRUE if configuration response sent, else FALSE
455 **
456 *******************************************************************************/
457 L2C_API extern BOOLEAN L2CA_ConfigRsp (UINT16 cid, tL2CAP_CFG_INFO *p_cfg);
458 
459 /*******************************************************************************
460 **
461 ** Function         L2CA_DisconnectReq
462 **
463 ** Description      Higher layers call this function to disconnect a channel.
464 **
465 ** Returns          TRUE if disconnect sent, else FALSE
466 **
467 *******************************************************************************/
468 L2C_API extern BOOLEAN L2CA_DisconnectReq (UINT16 cid);
469 
470 /*******************************************************************************
471 **
472 ** Function         L2CA_DisconnectRsp
473 **
474 ** Description      Higher layers call this function to acknowledge the
475 **                  disconnection of a channel.
476 **
477 ** Returns          void
478 **
479 *******************************************************************************/
480 L2C_API extern BOOLEAN L2CA_DisconnectRsp (UINT16 cid);
481 
482 /*******************************************************************************
483 **
484 ** Function         L2CA_DataWrite
485 **
486 ** Description      Higher layers call this function to write data.
487 **
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
491 **
492 *******************************************************************************/
493 L2C_API extern UINT8 L2CA_DataWrite (UINT16 cid, BT_HDR *p_data);
494 
495 /*******************************************************************************
496 **
497 ** Function         L2CA_Ping
498 **
499 ** Description      Higher layers call this function to send an echo request.
500 **
501 ** Returns          TRUE if echo request sent, else FALSE.
502 **
503 *******************************************************************************/
504 L2C_API extern BOOLEAN L2CA_Ping (BD_ADDR p_bd_addr, tL2CA_ECHO_RSP_CB *p_cb);
505 
506 /*******************************************************************************
507 **
508 ** Function         L2CA_Echo
509 **
510 ** Description      Higher layers call this function to send an echo request
511 **                  with application-specific data.
512 **
513 ** Returns          TRUE if echo request sent, else FALSE.
514 **
515 *******************************************************************************/
516 L2C_API extern BOOLEAN  L2CA_Echo (BD_ADDR p_bd_addr, BT_HDR *p_data, tL2CA_ECHO_DATA_CB *p_callback);
517 
518 /*******************************************************************************
519 **
520 ** Function         L2CA_SetIdleTimeout
521 **
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
528 **                  in seconds.
529 **
530 ** Returns          TRUE if command succeeded, FALSE if failed
531 **
532 *******************************************************************************/
533 L2C_API extern BOOLEAN L2CA_SetIdleTimeout (UINT16 cid, UINT16 timeout,
534                                             BOOLEAN is_global);
535 
536 /*******************************************************************************
537 **
538 ** Function         L2CA_SetIdleTimeoutByBdAddr
539 **
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
548 **                  changed.
549 **
550 ** Returns          TRUE if command succeeded, FALSE if failed
551 **
552 ** NOTE             This timeout applies to all logical channels active on the
553 **                  ACL link.
554 *******************************************************************************/
555 L2C_API extern BOOLEAN L2CA_SetIdleTimeoutByBdAddr(BD_ADDR bd_addr, UINT16 timeout);
556 
557 /*******************************************************************************
558 **
559 ** Function         L2CA_SetTraceLevel
560 **
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.
563 **
564 ** Returns          the new (current) trace level
565 **
566 *******************************************************************************/
567 L2C_API extern UINT8 L2CA_SetTraceLevel (UINT8 trace_level);
568 
569 /*******************************************************************************
570 **
571 ** Function     L2CA_SetDesireRole
572 **
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.
578 **
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.
581 **
582 ** Returns      the new (current) role
583 **
584 *******************************************************************************/
585 L2C_API extern UINT8 L2CA_SetDesireRole (UINT8 new_role);
586 
587 /*******************************************************************************
588 **
589 ** Function     L2CA_LocalLoopbackReq
590 **
591 ** Description  This function sets up a CID for local loopback
592 **
593 ** Returns      CID of 0 if none.
594 **
595 *******************************************************************************/
596 L2C_API extern UINT16 L2CA_LocalLoopbackReq (UINT16 psm, UINT16 handle, BD_ADDR p_bd_addr);
597 
598 /*******************************************************************************
599 **
600 ** Function     L2CA_FlushChannel
601 **
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
607 **              buffers to flush.
608 **
609 ** Returns      Number of buffers left queued for that CID
610 **
611 *******************************************************************************/
612 L2C_API extern UINT16   L2CA_FlushChannel (UINT16 lcid, UINT16 num_to_flush);
613 
614 
615 /*******************************************************************************
616 **
617 ** Function         L2CA_SetAclPriority
618 **
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).
622 **
623 ** Returns          TRUE if a valid channel, else FALSE
624 **
625 *******************************************************************************/
626 L2C_API extern BOOLEAN L2CA_SetAclPriority (BD_ADDR bd_addr, UINT8 priority);
627 
628 /*******************************************************************************
629 **
630 ** Function         L2CA_FlowControl
631 **
632 ** Description      Higher layers call this function to flow control a channel.
633 **
634 **                  data_enabled - TRUE data flows, FALSE data is stopped
635 **
636 ** Returns          TRUE if valid channel, else FALSE
637 **
638 *******************************************************************************/
639 L2C_API extern BOOLEAN L2CA_FlowControl (UINT16 cid, BOOLEAN data_enabled);
640 
641 /*******************************************************************************
642 **
643 ** Function         L2CA_SendTestSFrame
644 **
645 ** Description      Higher layers call this function to send a test S-frame.
646 **
647 ** Returns          TRUE if valid Channel, else FALSE
648 **
649 *******************************************************************************/
650 L2C_API extern BOOLEAN L2CA_SendTestSFrame (UINT16 cid, UINT8 sup_type,
651                                             UINT8 back_track);
652 
653 /*******************************************************************************
654 **
655 ** Function         L2CA_SetTxPriority
656 **
657 ** Description      Sets the transmission priority for a channel. (FCR Mode)
658 **
659 ** Returns          TRUE if a valid channel, else FALSE
660 **
661 *******************************************************************************/
662 L2C_API extern BOOLEAN L2CA_SetTxPriority (UINT16 cid, tL2CAP_CHNL_PRIORITY priority);
663 
664 /*******************************************************************************
665 **
666 ** Function         L2CA_RegForNoCPEvt
667 **
668 ** Description      Register callback for Number of Completed Packets event.
669 **
670 ** Input Param      p_cb - callback for Number of completed packets event
671 **                  p_bda - BT address of remote device
672 **
673 ** Returns
674 **
675 *******************************************************************************/
676 L2C_API extern BOOLEAN L2CA_RegForNoCPEvt(tL2CA_NOCP_CB *p_cb, BD_ADDR p_bda);
677 
678 /*******************************************************************************
679 **
680 ** Function         L2CA_SetChnlDataRate
681 **
682 ** Description      Sets the tx/rx data rate for a channel.
683 **
684 ** Returns          TRUE if a valid channel, else FALSE
685 **
686 *******************************************************************************/
687 L2C_API extern BOOLEAN L2CA_SetChnlDataRate (UINT16 cid, tL2CAP_CHNL_DATA_RATE tx, tL2CAP_CHNL_DATA_RATE rx);
688 
689 typedef void (tL2CA_RESERVE_CMPL_CBACK) (void);
690 
691 /*******************************************************************************
692 **
693 ** Function         L2CA_SetFlushTimeout
694 **
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
706 **
707 ** Returns          TRUE if command succeeded, FALSE if failed
708 **
709 ** NOTE             This flush timeout applies to all logical channels active on the
710 **                  ACL link.
711 *******************************************************************************/
712 L2C_API extern BOOLEAN L2CA_SetFlushTimeout (BD_ADDR bd_addr, UINT16 flush_tout);
713 
714 /*******************************************************************************
715 **
716 ** Function         L2CA_DataWriteEx
717 **
718 ** Description      Higher layers call this function to write data with extended
719 **                  flags.
720 **                  flags : L2CAP_FLUSHABLE_CH_BASED
721 **                          L2CAP_FLUSHABLE_PKT
722 **                          L2CAP_NON_FLUSHABLE_PKT
723 **
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
727 **
728 *******************************************************************************/
729 L2C_API extern UINT8 L2CA_DataWriteEx (UINT16 cid, BT_HDR *p_data, UINT16 flags);
730 
731 /*******************************************************************************
732 **
733 ** Function         L2CA_SetChnlFlushability
734 **
735 ** Description      Higher layers call this function to set a channels
736 **                  flushability flags
737 **
738 ** Returns          TRUE if CID found, else FALSE
739 **
740 *******************************************************************************/
741 L2C_API extern BOOLEAN L2CA_SetChnlFlushability (UINT16 cid, BOOLEAN is_flushable);
742 
743 /*******************************************************************************
744 **
745 **  Function         L2CA_GetPeerFeatures
746 **
747 **  Description      Get a peers features and fixed channel map
748 **
749 **  Parameters:      BD address of the peer
750 **                   Pointers to features and channel mask storage area
751 **
752 **  Return value:    TRUE if peer is connected
753 **
754 *******************************************************************************/
755 L2C_API extern BOOLEAN L2CA_GetPeerFeatures (BD_ADDR bd_addr, UINT32 *p_ext_feat, UINT8 *p_chnl_mask);
756 
757 /*******************************************************************************
758 **
759 **  Function         L2CA_GetBDAddrbyHandle
760 **
761 **  Description      Get BD address for the given HCI handle
762 **
763 **  Parameters:      HCI handle
764 **                   BD address of the peer
765 **
766 **  Return value:    TRUE if found lcb for the given handle, FALSE otherwise
767 **
768 *******************************************************************************/
769 L2C_API extern BOOLEAN L2CA_GetBDAddrbyHandle (UINT16 handle, BD_ADDR bd_addr);
770 
771 /*******************************************************************************
772 **
773 **  Function         L2CA_GetChnlFcrMode
774 **
775 **  Description      Get the channel FCR mode
776 **
777 **  Parameters:      Local CID
778 **
779 **  Return value:    Channel mode
780 **
781 *******************************************************************************/
782 L2C_API extern UINT8 L2CA_GetChnlFcrMode (UINT16 lcid);
783 
784 
785 /*******************************************************************************
786 **
787 **                      UCD callback prototypes
788 **
789 *******************************************************************************/
790 
791 /* UCD discovery. Parameters are
792 **      BD Address of remote
793 **      Data Type
794 **      Data
795 */
796 #define L2CAP_UCD_INFO_TYPE_RECEPTION   0x01
797 #define L2CAP_UCD_INFO_TYPE_MTU         0x02
798 
799 typedef void (tL2CA_UCD_DISCOVER_CB) (BD_ADDR, UINT8, UINT32);
800 
801 /* UCD data received. Parameters are
802 **      BD Address of remote
803 **      Pointer to buffer with data
804 */
805 typedef void (tL2CA_UCD_DATA_CB) (BD_ADDR, BT_HDR *);
806 
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:
810 **              remote BD_ADDR
811 **              TRUE if congested, FALSE if uncongested
812 */
813 typedef void (tL2CA_UCD_CONGESTION_STATUS_CB) (BD_ADDR, BOOLEAN);
814 
815 /* UCD registration info (the callback addresses and PSM)
816 */
817 typedef struct
818 {
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;
823 
824 /*******************************************************************************
825 **
826 **  Function        L2CA_UcdRegister
827 **
828 **  Description     Register PSM on UCD.
829 **
830 **  Parameters:     tL2CAP_UCD_CB_INFO
831 **
832 **  Return value:   TRUE if successs
833 **
834 *******************************************************************************/
835 L2C_API extern BOOLEAN L2CA_UcdRegister ( UINT16 psm, tL2CAP_UCD_CB_INFO *p_cb_info );
836 
837 /*******************************************************************************
838 **
839 **  Function        L2CA_UcdDeregister
840 **
841 **  Description     Deregister PSM on UCD.
842 **
843 **  Parameters:     PSM
844 **
845 **  Return value:   TRUE if successs
846 **
847 *******************************************************************************/
848 L2C_API extern BOOLEAN L2CA_UcdDeregister ( UINT16 psm );
849 
850 /*******************************************************************************
851 **
852 **  Function        L2CA_UcdDiscover
853 **
854 **  Description     Discover UCD of remote device.
855 **
856 **  Parameters:     PSM
857 **                  BD_ADDR of remote device
858 **                  info_type : L2CAP_UCD_INFO_TYPE_RECEPTION
859 **                              L2CAP_UCD_INFO_TYPE_MTU
860 **
861 **
862 **  Return value:   TRUE if successs
863 **
864 *******************************************************************************/
865 L2C_API extern BOOLEAN L2CA_UcdDiscover ( UINT16 psm, BD_ADDR rem_bda, UINT8 info_type );
866 
867 /*******************************************************************************
868 **
869 **  Function        L2CA_UcdDataWrite
870 **
871 **  Description     Send UCD to remote device
872 **
873 **  Parameters:     PSM
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
879 **
880 ** Return value     L2CAP_DW_SUCCESS, if data accepted
881 **                  L2CAP_DW_FAILED,  if error
882 **
883 *******************************************************************************/
884 L2C_API extern UINT16 L2CA_UcdDataWrite (UINT16 psm, BD_ADDR rem_bda, BT_HDR *p_buf, UINT16 flags);
885 
886 /*******************************************************************************
887 **
888 **  Function        L2CA_UcdSetIdleTimeout
889 **
890 **  Description     Set UCD Idle timeout.
891 **
892 **  Parameters:     BD Addr
893 **                  Timeout in second
894 **
895 **  Return value:   TRUE if successs
896 **
897 *******************************************************************************/
898 L2C_API extern BOOLEAN L2CA_UcdSetIdleTimeout ( BD_ADDR rem_bda, UINT16 timeout );
899 
900 /*******************************************************************************
901 **
902 ** Function         L2CA_UCDSetTxPriority
903 **
904 ** Description      Sets the transmission priority for a connectionless channel.
905 **
906 ** Returns          TRUE if a valid channel, else FALSE
907 **
908 *******************************************************************************/
909 L2C_API extern BOOLEAN L2CA_UCDSetTxPriority ( BD_ADDR rem_bda, tL2CAP_CHNL_PRIORITY priority );
910 
911 
912 /*******************************************************************************
913 **
914 **                      Fixed Channel callback prototypes
915 **
916 *******************************************************************************/
917 
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
923 */
924 typedef void (tL2CA_FIXED_CHNL_CB) (BD_ADDR, BOOLEAN, UINT16, tBT_TRANSPORT);
925 
926 /* Signalling data received. Parameters are
927 **      BD Address of remote
928 **      Pointer to buffer with data
929 */
930 typedef void (tL2CA_FIXED_DATA_CB) (BD_ADDR, BT_HDR *);
931 
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:
935 **      remote BD_ADDR
936 **      TRUE if congested, FALSE if uncongested
937 */
938 typedef void (tL2CA_FIXED_CONGESTION_STATUS_CB) (BD_ADDR, BOOLEAN);
939 
940 /* Fixed channel registration info (the callback addresses and channel config)
941 */
942 typedef struct
943 {
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;
948 
949     UINT16                  default_idle_tout;
950 } tL2CAP_FIXED_CHNL_REG;
951 
952 
953 #if (L2CAP_NUM_FIXED_CHNLS > 0)
954 /*******************************************************************************
955 **
956 **  Function        L2CA_RegisterFixedChannel
957 **
958 **  Description     Register a fixed channel.
959 **
960 **  Parameters:     Fixed Channel #
961 **                  Channel Callbacks and config
962 **
963 **  Return value:   TRUE if registered OK
964 **
965 *******************************************************************************/
966 L2C_API extern BOOLEAN  L2CA_RegisterFixedChannel (UINT16 fixed_cid, tL2CAP_FIXED_CHNL_REG *p_freg);
967 
968 /*******************************************************************************
969 **
970 **  Function        L2CA_ConnectFixedChnl
971 **
972 **  Description     Connect an fixed signalling channel to a remote device.
973 **
974 **  Parameters:     Fixed CID
975 **                  BD Address of remote
976 **
977 **  Return value:   TRUE if connection started
978 **
979 *******************************************************************************/
980 L2C_API extern BOOLEAN L2CA_ConnectFixedChnl (UINT16 fixed_cid, BD_ADDR bd_addr);
981 
982 /*******************************************************************************
983 **
984 **  Function        L2CA_SendFixedChnlData
985 **
986 **  Description     Write data on a fixed signalling channel.
987 **
988 **  Parameters:     Fixed CID
989 **                  BD Address of remote
990 **                  Pointer to buffer of type BT_HDR
991 **
992 ** Return value     L2CAP_DW_SUCCESS, if data accepted
993 **                  L2CAP_DW_FAILED,  if error
994 **
995 *******************************************************************************/
996 L2C_API extern UINT16 L2CA_SendFixedChnlData (UINT16 fixed_cid, BD_ADDR rem_bda, BT_HDR *p_buf);
997 
998 /*******************************************************************************
999 **
1000 **  Function        L2CA_RemoveFixedChnl
1001 **
1002 **  Description     Remove a fixed channel to a remote device.
1003 **
1004 **  Parameters:     Fixed CID
1005 **                  BD Address of remote
1006 **                  Idle timeout to use (or 0xFFFF if don't care)
1007 **
1008 **  Return value:   TRUE if channel removed
1009 **
1010 *******************************************************************************/
1011 L2C_API extern BOOLEAN L2CA_RemoveFixedChnl (UINT16 fixed_cid, BD_ADDR rem_bda);
1012 
1013 /*******************************************************************************
1014 **
1015 ** Function         L2CA_SetFixedChannelTout
1016 **
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
1025 **                  changed.
1026 **
1027 ** Returns          TRUE if command succeeded, FALSE if failed
1028 **
1029 *******************************************************************************/
1030 L2C_API extern BOOLEAN L2CA_SetFixedChannelTout (BD_ADDR rem_bda, UINT16 fixed_cid, UINT16 idle_tout);
1031 
1032 #endif /* (L2CAP_NUM_FIXED_CHNLS > 0) */
1033 
1034 /*******************************************************************************
1035 **
1036 ** Function     L2CA_GetCurrentConfig
1037 **
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
1043 **
1044 ** Returns      TRUE if successful
1045 **
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);
1050 
1051 #if (L2CAP_CORRUPT_ERTM_PKTS == TRUE)
1052 /*******************************************************************************
1053 **
1054 ** Function         L2CA_SetupErtmTest
1055 **
1056 ** Description      This function is used for testing purposes only.
1057 **                  It corrupts or drops one or more packets used with ERTM channels.
1058 **
1059 ** Parameters
1060 **                  cid - channel ID  (0 uses RFCOMM PSM's CID)
1061 **
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)
1066 **
1067 **                  is_rx  - TRUE to corrupt Rx packet, FALSE for Tx packet)
1068 **
1069 **                  freq - L2CAP_FCR_FREQ_RANDOM    (turns on random corruptions/drops)
1070 **                         L2CAP_FCR_FREQ_NORMAL    (turns on test with "count" corruptions/drops)
1071 **
1072 **                  count - number of packets in a row to drop or corrupt
1073 **
1074 ** Returns          CID of channel running test
1075 **
1076 *******************************************************************************/
1077 L2C_API extern UINT16 L2CA_SetupErtmTest (UINT16 cid, UINT8 type, BOOLEAN is_rx, UINT8 freq, UINT16 count);
1078 
1079 /*******************************************************************************
1080 **
1081 ** Function         L2CA_SendPolledSFrame
1082 **
1083 ** Description      This function is used for testing purposes only.
1084 **                  It Sends a Polled RR or RNR to the peer
1085 **
1086 ** Parameters
1087 **                  cid - channel ID
1088 **
1089 **                  sup_type - (L2CAP_FCR_SUP_RR or L2CAP_FCR_SUP_RNR)
1090 **
1091 ** Returns          void
1092 **
1093 *******************************************************************************/
1094 L2C_API extern void L2CA_SendPolledSFrame (UINT16 cid, UINT16 sup_type);
1095 
1096 /*******************************************************************************
1097 **
1098 ** Function         L2CA_BypassSFrame
1099 **
1100 ** Description      This function is used for testing purposes only.
1101 **                  It skips sending 'count' S-Frames.
1102 **
1103 ** Parameters
1104 **                  cid - channel ID
1105 **
1106 **                  count - Number of S-Frames to skip sending
1107 **
1108 ** Returns          void
1109 **
1110 *******************************************************************************/
1111 L2C_API extern void L2CA_BypassSFrame (UINT16 cid, UINT8 count);
1112 
1113 #endif /* (L2CAP_CORRUPT_ERTM_PKTS == TRUE) */
1114 
1115 
1116 #if (BLE_INCLUDED == TRUE)
1117 /*******************************************************************************
1118 **
1119 **  Function        L2CA_CancelBleConnectReq
1120 **
1121 **  Description     Cancel a pending connection attempt to a BLE device.
1122 **
1123 **  Parameters:     BD Address of remote
1124 **
1125 **  Return value:   TRUE if connection was cancelled
1126 **
1127 *******************************************************************************/
1128 L2C_API extern BOOLEAN L2CA_CancelBleConnectReq (BD_ADDR rem_bda);
1129 
1130 /*******************************************************************************
1131 **
1132 **  Function        L2CA_UpdateBleConnParams
1133 **
1134 **  Description     Update BLE connection parameters.
1135 **
1136 **  Parameters:     BD Address of remote
1137 **
1138 **  Return value:   TRUE if update started
1139 **
1140 *******************************************************************************/
1141 L2C_API extern BOOLEAN L2CA_UpdateBleConnParams (BD_ADDR rem_bdRa, UINT16 min_int,
1142                                                           UINT16 max_int, UINT16 latency, UINT16 timeout);
1143 
1144 /*******************************************************************************
1145 **
1146 **  Function        L2CA_EnableUpdateBleConnParams
1147 **
1148 **  Description     Update BLE connection parameters.
1149 **
1150 **  Parameters:     BD Address of remote
1151 **                  enable flag
1152 **
1153 **  Return value:   TRUE if update started
1154 **
1155 *******************************************************************************/
1156 L2C_API extern BOOLEAN L2CA_EnableUpdateBleConnParams (BD_ADDR rem_bda, BOOLEAN enable);
1157 
1158 /*******************************************************************************
1159 **
1160 ** Function         L2CA_GetBleConnRole
1161 **
1162 ** Description      This function returns the connection role.
1163 **
1164 ** Returns          link role.
1165 **
1166 *******************************************************************************/
1167 L2C_API extern UINT8 L2CA_GetBleConnRole (BD_ADDR bd_addr);
1168 
1169 /*******************************************************************************
1170 **
1171 ** Function         L2CA_GetDisconnectReason
1172 **
1173 ** Description      This function returns the disconnect reason code.
1174 **
1175 **  Parameters:     BD Address of remote
1176 **                         Physical transport for the L2CAP connection (BR/EDR or LE)
1177 **
1178 ** Returns          disconnect reason
1179 **
1180 *******************************************************************************/
1181 L2C_API extern UINT16 L2CA_GetDisconnectReason (BD_ADDR remote_bda, tBT_TRANSPORT transport);
1182 
1183 #endif /* (BLE_INCLUDED == TRUE) */
1184 
1185 #ifdef __cplusplus
1186 }
1187 #endif
1188 
1189 #endif  /* L2C_API_H */
1190