1 /******************************************************************************
2  *
3  *  Copyright (C) 2002-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 interface file contains the interface to the Audio Video
22  *  Distribution Transport Protocol (AVDTP).
23  *
24  ******************************************************************************/
25 #ifndef AVDT_API_H
26 #define AVDT_API_H
27 
28 #include "bt_target.h"
29 #include "bt_types.h"
30 
31 /*****************************************************************************
32  *  Constants
33  ****************************************************************************/
34 #ifndef AVDT_VERSION
35 #define AVDT_VERSION 0x0102
36 #endif
37 #define AVDT_VERSION_SYNC 0x0103
38 
39 /* Maximum size in bytes of the codec capabilities information element. */
40 #define AVDT_CODEC_SIZE 20
41 
42 /* API function return value result codes. */
43 #define AVDT_SUCCESS 0      /* Function successful */
44 #define AVDT_BAD_PARAMS 1   /* Invalid parameters */
45 #define AVDT_NO_RESOURCES 2 /* Not enough resources */
46 #define AVDT_BAD_HANDLE 3   /* Bad handle */
47 #define AVDT_BUSY 4         /* A procedure is already in progress */
48 #define AVDT_WRITE_FAIL 5   /* Write failed */
49 
50 /* The index to access the codec type in codec_info[]. */
51 #define AVDT_CODEC_TYPE_INDEX 2
52 
53 /* The size in bytes of a Adaptation Layer header. */
54 #define AVDT_AL_HDR_SIZE 3
55 
56 /* The size in bytes of a media packet header. */
57 #define AVDT_MEDIA_HDR_SIZE 12
58 
59 /* The handle is used when reporting MULTI_AV specific events */
60 #define AVDT_MULTI_AV_HANDLE 0xFF
61 
62 /* The number of bytes needed by the protocol stack for the protocol headers
63  * of a media packet.  This is the size of the media packet header, the
64  * L2CAP packet header and HCI header.
65 */
66 #define AVDT_MEDIA_OFFSET 23
67 
68 /* The marker bit is used by the application to mark significant events such
69  * as frame boundaries in the data stream.  This constant is used to check or
70  * set the marker bit in the m_pt parameter of an AVDT_WriteReq()
71  * or AVDT_DATA_IND_EVT.
72 */
73 #define AVDT_MARKER_SET 0x80
74 
75 /* SEP Type.  This indicates the stream endpoint type. */
76 #define AVDT_TSEP_SRC 0     /* Source SEP */
77 #define AVDT_TSEP_SNK 1     /* Sink SEP */
78 #define AVDT_TSEP_INVALID 3 /* Invalid SEP */
79 
80 /* initiator/acceptor role for adaption */
81 #define AVDT_INT 0 /* initiator */
82 #define AVDT_ACP 1 /* acceptor */
83 
84 /* Media Type of the stream endpoint */
85 /* The value does not include the reserved 4-bit LSBs field */
86 #define AVDT_MEDIA_TYPE_AUDIO 0 /* Audio SEP */
87 #define AVDT_MEDIA_TYPE_VIDEO 1 /* Video SEP */
88 #define AVDT_MEDIA_TYPE_MULTI 2 /* Multimedia SEP */
89 
90 /* for reporting packets (packet types) */
91 #define AVDT_RTCP_PT_SR 200   /* SR (Sender Report) */
92 #define AVDT_RTCP_PT_RR 201   /* RR (Receiver Report) */
93 #define AVDT_RTCP_PT_SDES 202 /* SDES (Source Description) */
94 typedef uint8_t AVDT_REPORT_TYPE;
95 
96 #define AVDT_RTCP_SDES_CNAME 1 /* SDES item CNAME */
97 #ifndef AVDT_MAX_CNAME_SIZE
98 #define AVDT_MAX_CNAME_SIZE 28
99 #endif
100 
101 /* Protocol service capabilities.  This indicates the protocol service
102  * capabilities of a stream endpoint.  This value is a mask.
103  * Multiple values can be combined with a bitwise OR.
104 */
105 #define AVDT_PSC_TRANS (1 << 1)     /* Media transport */
106 #define AVDT_PSC_REPORT (1 << 2)    /* Reporting */
107 #define AVDT_PSC_RECOV (1 << 3)     /* Recovery */
108 #define AVDT_PSC_HDRCMP (1 << 5)    /* Header compression */
109 #define AVDT_PSC_MUX (1 << 6)       /* Multiplexing */
110 #define AVDT_PSC_DELAY_RPT (1 << 8) /* Delay Report */
111 
112 /* Recovery type.  This indicates the recovery type. */
113 #define AVDT_RECOV_RFC2733 1 /* RFC2733 recovery */
114 
115 /* Header compression capabilities.  This indicates the header compression
116  * capabilities.  This value is a mask.  Multiple values can be combined
117  * with a bitwise OR.
118 */
119 #define AVDT_HDRCMP_MEDIA (1 << 5)  /* Available for media packets */
120 #define AVDT_HDRCMP_RECOV (1 << 6)  /* Available for recovery packets */
121 #define AVDT_HDRCMP_BACKCH (1 << 7) /* Back channel supported */
122 
123 /* Multiplexing capabilities mask. */
124 #define AVDT_MUX_FRAG (1 << 7) /* Allow Adaptation Layer Fragmentation */
125 
126 /* Application service category. This indicates the application
127  * service category.
128 */
129 #define AVDT_ASC_PROTECT 4 /* Content protection */
130 #define AVDT_ASC_CODEC 7   /* Codec */
131 
132 /* the content protection IDs assigned by BT SIG */
133 #define AVDT_CP_SCMS_T_ID 0x0002
134 #define AVDT_CP_DTCP_ID 0x0001
135 
136 #define AVDT_CP_LOSC 2
137 #define AVDT_CP_INFO_LEN 3
138 
139 #define AVDT_CP_SCMS_COPY_MASK 3
140 #define AVDT_CP_SCMS_COPY_FREE 2
141 #define AVDT_CP_SCMS_COPY_ONCE 1
142 #define AVDT_CP_SCMS_COPY_NEVER 0
143 
144 /* Error codes.  The following are error codes defined in the AVDTP and GAVDP
145  * specifications.  These error codes communicate protocol errors between
146  * AVDTP and the application.  More detailed descriptions of the error codes
147  * and their appropriate use can be found in the AVDTP and GAVDP specifications.
148  * These error codes are unrelated to the result values returned by the
149  * AVDTP API functions.
150 */
151 /* Bad packet header format */
152 #define AVDT_ERR_HEADER 0x01
153 /* Bad packet length */
154 #define AVDT_ERR_LENGTH 0x11
155 /* Invalid SEID */
156 #define AVDT_ERR_SEID 0x12
157 /* The SEP is in use */
158 #define AVDT_ERR_IN_USE 0x13
159 /* The SEP is not in use */
160 #define AVDT_ERR_NOT_IN_USE 0x14
161 /* Bad service category */
162 #define AVDT_ERR_CATEGORY 0x17
163 /* Bad payload format */
164 #define AVDT_ERR_PAYLOAD 0x18
165 /* Requested command not supported */
166 #define AVDT_ERR_NSC 0x19
167 /* Reconfigure attempted invalid capabilities */
168 #define AVDT_ERR_INVALID_CAP 0x1A
169 /* Requested recovery type not defined */
170 #define AVDT_ERR_RECOV_TYPE 0x22
171 /* Media transport capability not correct */
172 #define AVDT_ERR_MEDIA_TRANS 0x23
173 /* Recovery service capability not correct */
174 #define AVDT_ERR_RECOV_FMT 0x25
175 /* Header compression service capability not correct */
176 #define AVDT_ERR_ROHC_FMT 0x26
177 /* Content protection service capability not correct */
178 #define AVDT_ERR_CP_FMT 0x27
179 /* Multiplexing service capability not correct */
180 #define AVDT_ERR_MUX_FMT 0x28
181 /* Configuration not supported */
182 #define AVDT_ERR_UNSUP_CFG 0x29
183 /* Message cannot be processed in this state */
184 #define AVDT_ERR_BAD_STATE 0x31
185 /* Report service capability not correct */
186 #define AVDT_ERR_REPORT_FMT 0x65
187 /* Invalid service category */
188 #define AVDT_ERR_SERVICE 0x80
189 /* Insufficient resources */
190 #define AVDT_ERR_RESOURCE 0x81
191 /* Invalid Media Codec Type */
192 #define AVDT_ERR_INVALID_MCT 0xC1
193 /* Unsupported Media Codec Type */
194 #define AVDT_ERR_UNSUP_MCT 0xC2
195 /* Invalid Level */
196 #define AVDT_ERR_INVALID_LEVEL 0xC3
197 /* Unsupported Level */
198 #define AVDT_ERR_UNSUP_LEVEL 0xC4
199 /* Invalid Content Protection Type */
200 #define AVDT_ERR_INVALID_CP 0xE0
201 /* Invalid Content Protection format */
202 #define AVDT_ERR_INVALID_FORMAT 0xE1
203 
204 /* Additional error codes.  This indicates error codes used by AVDTP
205  * in addition to the ones defined in the specifications.
206 */
207 #define AVDT_ERR_CONNECT 0x07 /* Connection failed. */
208 #define AVDT_ERR_TIMEOUT 0x08 /* Response timeout. */
209 
210 /* Control callback events. */
211 #define AVDT_DISCOVER_CFM_EVT 0      /* Discover confirm */
212 #define AVDT_GETCAP_CFM_EVT 1        /* Get capabilities confirm */
213 #define AVDT_OPEN_CFM_EVT 2          /* Open confirm */
214 #define AVDT_OPEN_IND_EVT 3          /* Open indication */
215 #define AVDT_CONFIG_IND_EVT 4        /* Configuration indication */
216 #define AVDT_START_CFM_EVT 5         /* Start confirm */
217 #define AVDT_START_IND_EVT 6         /* Start indication */
218 #define AVDT_SUSPEND_CFM_EVT 7       /* Suspend confirm */
219 #define AVDT_SUSPEND_IND_EVT 8       /* Suspend indication */
220 #define AVDT_CLOSE_CFM_EVT 9         /* Close confirm */
221 #define AVDT_CLOSE_IND_EVT 10        /* Close indication */
222 #define AVDT_RECONFIG_CFM_EVT 11     /* Reconfiguration confirm */
223 #define AVDT_RECONFIG_IND_EVT 12     /* Reconfiguration indication */
224 #define AVDT_SECURITY_CFM_EVT 13     /* Security confirm */
225 #define AVDT_SECURITY_IND_EVT 14     /* Security indication */
226 #define AVDT_WRITE_CFM_EVT 15        /* Write confirm */
227 #define AVDT_CONNECT_IND_EVT 16      /* Signaling channel connected */
228 #define AVDT_DISCONNECT_IND_EVT 17   /* Signaling channel disconnected */
229 #define AVDT_REPORT_CONN_EVT 18      /* Reporting channel connected */
230 #define AVDT_REPORT_DISCONN_EVT 19   /* Reporting channel disconnected */
231 #define AVDT_DELAY_REPORT_EVT 20     /* Delay report received */
232 #define AVDT_DELAY_REPORT_CFM_EVT 21 /* Delay report response received */
233 
234 #define AVDT_MAX_EVT (AVDT_DELAY_REPORT_CFM_EVT)
235 
236 /* PSM for AVDT */
237 #define AVDT_PSM 0x0019
238 
239 /* Nonsupported protocol command messages.  This value is used in tAVDT_CS */
240 #define AVDT_NSC_SUSPEND 0x01  /* Suspend command not supported */
241 #define AVDT_NSC_RECONFIG 0x02 /* Reconfigure command not supported */
242 #define AVDT_NSC_SECURITY 0x04 /* Security command not supported */
243 
244 /*****************************************************************************
245  *  Type Definitions
246  ****************************************************************************/
247 
248 typedef struct {
249   uint32_t ntp_sec; /* NTP time: seconds relative to 0h UTC on 1 January 1900 */
250   uint32_t ntp_frac;    /* NTP time: the fractional part */
251   uint32_t rtp_time;    /* timestamp in RTP header */
252   uint32_t pkt_count;   /* sender's packet count: since starting transmission
253                         * up until the time this SR packet was generated. */
254   uint32_t octet_count; /* sender's octet count: same comment */
255 } tAVDT_SENDER_INFO;
256 
257 typedef struct {
258   uint8_t frag_lost; /* fraction lost since last RR */
259   uint32_t
260       packet_lost; /* cumulative number of packets lost since the beginning */
261   uint32_t seq_num_rcvd; /* extended highest sequence number received */
262   uint32_t jitter;       /* interarrival jitter */
263   uint32_t lsr;          /* last SR timestamp */
264   uint32_t dlsr;         /* delay since last SR */
265 } tAVDT_REPORT_BLK;
266 
267 typedef union {
268   tAVDT_SENDER_INFO sr;
269   tAVDT_REPORT_BLK rr;
270   uint8_t cname[AVDT_MAX_CNAME_SIZE + 1];
271 } tAVDT_REPORT_DATA;
272 
273 /* This structure contains parameters which are set at registration. */
274 typedef struct {
275   uint16_t ctrl_mtu; /* L2CAP MTU of the AVDTP signaling channel */
276   uint8_t ret_tout;  /* AVDTP signaling retransmission timeout */
277   uint8_t sig_tout;  /* AVDTP signaling message timeout */
278   uint8_t idle_tout; /* AVDTP idle signaling channel timeout */
279   uint8_t sec_mask;  /* Security mask for BTM_SetSecurityLevel() */
280 } tAVDT_REG;
281 
282 /* This structure contains the SEP information.  This information is
283  * transferred during the discovery procedure.
284 */
285 typedef struct {
286   bool in_use;        /* true if stream is currently in use */
287   uint8_t seid;       /* Stream endpoint identifier */
288   uint8_t media_type; /* Media type: AVDT_MEDIA_TYPE_* */
289   uint8_t tsep;       /* SEP type */
290 } tAVDT_SEP_INFO;
291 
292 /* This structure contains the SEP configuration. */
293 typedef struct {
294   uint8_t codec_info[AVDT_CODEC_SIZE];     /* Codec capabilities array */
295   uint8_t protect_info[AVDT_PROTECT_SIZE]; /* Content protection capabilities */
296   uint8_t num_codec;   /* Number of media codec information elements */
297   uint8_t num_protect; /* Number of content protection information elements */
298   uint16_t psc_mask;   /* Protocol service capabilities mask */
299   uint8_t recov_type;  /* Recovery type */
300   uint8_t recov_mrws;  /* Maximum recovery window size */
301   uint8_t recov_mnmp;  /* Recovery maximum number of media packets */
302   uint8_t hdrcmp_mask; /* Header compression capabilities */
303 } tAVDT_CFG;
304 
305 /* Header structure for callback event parameters. */
306 typedef struct {
307   uint8_t
308       err_code; /* Zero if operation succeeded; nonzero if operation failed */
309   uint8_t err_param; /* Error parameter included for some events */
310   uint8_t label;     /* Transaction label */
311   uint8_t seid;      /* For internal use only */
312   uint8_t sig_id;    /* For internal use only */
313   uint8_t ccb_idx;   /* For internal use only */
314 } tAVDT_EVT_HDR;
315 
316 /* This data structure is associated with the AVDT_GETCAP_CFM_EVT,
317  * AVDT_RECONFIG_IND_EVT, and AVDT_RECONFIG_CFM_EVT.
318 */
319 typedef struct {
320   tAVDT_EVT_HDR hdr; /* Event header */
321   tAVDT_CFG* p_cfg;  /* Pointer to configuration for this SEP */
322 } tAVDT_CONFIG;
323 
324 /* This data structure is associated with the AVDT_CONFIG_IND_EVT. */
325 typedef struct {
326   tAVDT_EVT_HDR hdr; /* Event header */
327   tAVDT_CFG* p_cfg;  /* Pointer to configuration for this SEP */
328   uint8_t int_seid;  /* Stream endpoint ID of stream initiating the operation */
329 } tAVDT_SETCONFIG;
330 
331 /* This data structure is associated with the AVDT_OPEN_IND_EVT and
332  * AVDT_OPEN_CFM_EVT. */
333 typedef struct {
334   tAVDT_EVT_HDR hdr; /* Event header */
335   uint16_t peer_mtu; /* Transport channel L2CAP MTU of the peer */
336   uint16_t lcid;     /* L2CAP LCID for media channel */
337 } tAVDT_OPEN;
338 
339 /* This data structure is associated with the AVDT_SECURITY_IND_EVT
340  * and AVDT_SECURITY_CFM_EVT.
341 */
342 typedef struct {
343   tAVDT_EVT_HDR hdr; /* Event header */
344   uint8_t* p_data;   /* Pointer to security data */
345   uint16_t len;      /* Length in bytes of the security data */
346 } tAVDT_SECURITY;
347 
348 /* This data structure is associated with the AVDT_DISCOVER_CFM_EVT. */
349 typedef struct {
350   tAVDT_EVT_HDR hdr;          /* Event header */
351   tAVDT_SEP_INFO* p_sep_info; /* Pointer to SEP information */
352   uint8_t num_seps;           /* Number of stream endpoints */
353 } tAVDT_DISCOVER;
354 
355 /* This data structure is associated with the AVDT_DELAY_REPORT_EVT. */
356 typedef struct {
357   tAVDT_EVT_HDR hdr; /* Event header */
358   uint16_t delay;    /* Delay value */
359 } tAVDT_DELAY_RPT;
360 
361 /* Union of all control callback event data structures */
362 typedef union {
363   tAVDT_EVT_HDR hdr;
364   tAVDT_DISCOVER discover_cfm;
365   tAVDT_CONFIG getcap_cfm;
366   tAVDT_OPEN open_cfm;
367   tAVDT_OPEN open_ind;
368   tAVDT_SETCONFIG config_ind;
369   tAVDT_EVT_HDR start_cfm;
370   tAVDT_EVT_HDR suspend_cfm;
371   tAVDT_EVT_HDR close_cfm;
372   tAVDT_CONFIG reconfig_cfm;
373   tAVDT_CONFIG reconfig_ind;
374   tAVDT_SECURITY security_cfm;
375   tAVDT_SECURITY security_ind;
376   tAVDT_EVT_HDR connect_ind;
377   tAVDT_EVT_HDR disconnect_ind;
378   tAVDT_EVT_HDR report_conn;
379   tAVDT_DELAY_RPT delay_rpt_cmd;
380 } tAVDT_CTRL;
381 
382 /* This is the control callback function.  This function passes control events
383  * to the application.  This function is required for all registered stream
384  * endpoints and for the AVDT_DiscoverReq() and AVDT_GetCapReq() functions.
385  *
386 */
387 typedef void(tAVDT_CTRL_CBACK)(uint8_t handle, BD_ADDR bd_addr, uint8_t event,
388                                tAVDT_CTRL* p_data);
389 
390 /* This is the data callback function.  It is executed when AVDTP has a media
391  * packet ready for the application.  This function is required for SNK
392  * endpoints and not applicable for SRC endpoints.
393 */
394 typedef void(tAVDT_SINK_DATA_CBACK)(uint8_t handle, BT_HDR* p_pkt,
395                                     uint32_t time_stamp, uint8_t m_pt);
396 
397 #if (AVDT_REPORTING == TRUE)
398 /* This is the report callback function.  It is executed when AVDTP has a
399  * reporting packet ready for the application.  This function is required for
400  * streams created with AVDT_PSC_REPORT.
401 */
402 typedef void(tAVDT_REPORT_CBACK)(uint8_t handle, AVDT_REPORT_TYPE type,
403                                  tAVDT_REPORT_DATA* p_data);
404 #endif
405 
406 typedef uint16_t(tAVDT_GETCAP_REQ)(BD_ADDR bd_addr, uint8_t seid,
407                                    tAVDT_CFG* p_cfg, tAVDT_CTRL_CBACK* p_cback);
408 
409 /* This structure contains information required when a stream is created.
410  * It is passed to the AVDT_CreateStream() function.
411 */
412 typedef struct {
413   tAVDT_CFG cfg;                            /* SEP configuration */
414   tAVDT_CTRL_CBACK* p_ctrl_cback;           /* Control callback function */
415   tAVDT_SINK_DATA_CBACK* p_sink_data_cback; /* Sink data callback function */
416 #if (AVDT_REPORTING == TRUE)
417   tAVDT_REPORT_CBACK* p_report_cback; /* Report callback function. */
418 #endif
419   uint16_t mtu;       /* The L2CAP MTU of the transport channel */
420   uint16_t flush_to;  /* The L2CAP flush timeout of the transport channel */
421   uint8_t tsep;       /* SEP type */
422   uint8_t media_type; /* Media type: AVDT_MEDIA_TYPE_* */
423   uint16_t nsc_mask;  /* Nonsupported protocol command messages */
424 } tAVDT_CS;
425 
426 /* AVDT data option mask is used in the write request */
427 #define AVDT_DATA_OPT_NONE 0x00          /* No option still add RTP header */
428 #define AVDT_DATA_OPT_NO_RTP (0x01 << 0) /* Skip adding RTP header */
429 
430 typedef uint8_t tAVDT_DATA_OPT_MASK;
431 
432 /*****************************************************************************
433  *  External Function Declarations
434  ****************************************************************************/
435 
436 /*******************************************************************************
437  *
438  * Function         AVDT_Register
439  *
440  * Description      This is the system level registration function for the
441  *                  AVDTP protocol.  This function initializes AVDTP and
442  *                  prepares the protocol stack for its use.  This function
443  *                  must be called once by the system or platform using AVDTP
444  *                  before the other functions of the API an be used.
445  *
446  *
447  * Returns          void
448  *
449  ******************************************************************************/
450 extern void AVDT_Register(tAVDT_REG* p_reg, tAVDT_CTRL_CBACK* p_cback);
451 
452 /*******************************************************************************
453  *
454  * Function         AVDT_Deregister
455  *
456  * Description      This function is called to deregister use AVDTP protocol.
457  *                  It is called when AVDTP is no longer being used by any
458  *                  application in the system.  Before this function can be
459  *                  called, all streams must be removed with AVDT_RemoveStream.
460  *
461  * Returns          void
462  *
463  ******************************************************************************/
464 extern void AVDT_Deregister(void);
465 
466 /*******************************************************************************
467  *
468  * Function         AVDT_AbortReq
469  *
470  * Description      Trigger Abort request to pass AVDTP Abort related mandatory
471  *                  PTS Test case.
472  *
473  * Returns          void.
474  *
475  ******************************************************************************/
476 extern void AVDT_AbortReq(uint8_t handle);
477 
478 /*******************************************************************************
479  *
480  * Function         AVDT_CreateStream
481  *
482  * Description      Create a stream endpoint.  After a stream endpoint is
483  *                  created an application can initiate a connection between
484  *                  this endpoint and an endpoint on a peer device.  In
485  *                  addition, a peer device can discover, get the capabilities,
486  *                  and connect to this endpoint.
487  *
488  *
489  * Returns          AVDT_SUCCESS if successful, otherwise error.
490  *
491  ******************************************************************************/
492 extern uint16_t AVDT_CreateStream(uint8_t* p_handle, tAVDT_CS* p_cs);
493 
494 /*******************************************************************************
495  *
496  * Function         AVDT_RemoveStream
497  *
498  * Description      Remove a stream endpoint.  This function is called when
499  *                  the application is no longer using a stream endpoint.
500  *                  If this function is called when the endpoint is connected
501  *                  the connection is closed and then the stream endpoint
502  *                  is removed.
503  *
504  *
505  * Returns          AVDT_SUCCESS if successful, otherwise error.
506  *
507  ******************************************************************************/
508 extern uint16_t AVDT_RemoveStream(uint8_t handle);
509 
510 /*******************************************************************************
511  *
512  * Function         AVDT_DiscoverReq
513  *
514  * Description      This function initiates a connection to the AVDTP service
515  *                  on the peer device, if not already present, and discovers
516  *                  the stream endpoints on the peer device.  (Please note
517  *                  that AVDTP discovery is unrelated to SDP discovery).
518  *                  This function can be called at any time regardless of
519  *                  whether there is an AVDTP connection to the peer device.
520  *
521  *                  When discovery is complete, an AVDT_DISCOVER_CFM_EVT
522  *                  is sent to the application via its callback function.
523  *                  The application must not call AVDT_GetCapReq() or
524  *                  AVDT_DiscoverReq() again to the same device until
525  *                  discovery is complete.
526  *
527  *                  The memory addressed by sep_info is allocated by the
528  *                  application.  This memory is written to by AVDTP as part
529  *                  of the discovery procedure.  This memory must remain
530  *                  accessible until the application receives the
531  *                  AVDT_DISCOVER_CFM_EVT.
532  *
533  * Returns          AVDT_SUCCESS if successful, otherwise error.
534  *
535  ******************************************************************************/
536 extern uint16_t AVDT_DiscoverReq(BD_ADDR bd_addr, tAVDT_SEP_INFO* p_sep_info,
537                                  uint8_t max_seps, tAVDT_CTRL_CBACK* p_cback);
538 
539 /*******************************************************************************
540  *
541  * Function         AVDT_GetCapReq
542  *
543  * Description      This function initiates a connection to the AVDTP service
544  *                  on the peer device, if not already present, and gets the
545  *                  capabilities of a stream endpoint on the peer device.
546  *                  This function can be called at any time regardless of
547  *                  whether there is an AVDTP connection to the peer device.
548  *
549  *                  When the procedure is complete, an AVDT_GETCAP_CFM_EVT is
550  *                  sent to the application via its callback function.  The
551  *                  application must not call AVDT_GetCapReq() or
552  *                  AVDT_DiscoverReq() again until the procedure is complete.
553  *
554  *                  The memory pointed to by p_cfg is allocated by the
555  *                  application.  This memory is written to by AVDTP as part
556  *                  of the get capabilities procedure.  This memory must
557  *                  remain accessible until the application receives
558  *                  the AVDT_GETCAP_CFM_EVT.
559  *
560  * Returns          AVDT_SUCCESS if successful, otherwise error.
561  *
562  ******************************************************************************/
563 extern uint16_t AVDT_GetCapReq(BD_ADDR bd_addr, uint8_t seid, tAVDT_CFG* p_cfg,
564                                tAVDT_CTRL_CBACK* p_cback);
565 
566 /*******************************************************************************
567  *
568  * Function         AVDT_GetAllCapReq
569  *
570  * Description      This function initiates a connection to the AVDTP service
571  *                  on the peer device, if not already present, and gets the
572  *                  capabilities of a stream endpoint on the peer device.
573  *                  This function can be called at any time regardless of
574  *                  whether there is an AVDTP connection to the peer device.
575  *
576  *                  When the procedure is complete, an AVDT_GETCAP_CFM_EVT is
577  *                  sent to the application via its callback function.  The
578  *                  application must not call AVDT_GetCapReq() or
579  *                  AVDT_DiscoverReq() again until the procedure is complete.
580  *
581  *                  The memory pointed to by p_cfg is allocated by the
582  *                  application.  This memory is written to by AVDTP as part
583  *                  of the get capabilities procedure.  This memory must
584  *                  remain accessible until the application receives
585  *                  the AVDT_GETCAP_CFM_EVT.
586  *
587  * Returns          AVDT_SUCCESS if successful, otherwise error.
588  *
589  ******************************************************************************/
590 extern uint16_t AVDT_GetAllCapReq(BD_ADDR bd_addr, uint8_t seid,
591                                   tAVDT_CFG* p_cfg, tAVDT_CTRL_CBACK* p_cback);
592 
593 /*******************************************************************************
594  *
595  * Function         AVDT_DelayReport
596  *
597  * Description      This functions sends a Delay Report to the peer device
598  *                  that is associated with a particular SEID.
599  *                  This function is called by SNK device.
600  *
601  * Returns          AVDT_SUCCESS if successful, otherwise error.
602  *
603  ******************************************************************************/
604 extern uint16_t AVDT_DelayReport(uint8_t handle, uint8_t seid, uint16_t delay);
605 
606 /*******************************************************************************
607  *
608  * Function         AVDT_OpenReq
609  *
610  * Description      This function initiates a connection to the AVDTP service
611  *                  on the peer device, if not already present, and connects
612  *                  to a stream endpoint on a peer device.  When the connection
613  *                  is completed, an AVDT_OPEN_CFM_EVT is sent to the
614  *                  application via the control callback function for this
615  *                  handle.
616  *
617  * Returns          AVDT_SUCCESS if successful, otherwise error.
618  *
619  ******************************************************************************/
620 extern uint16_t AVDT_OpenReq(uint8_t handle, BD_ADDR bd_addr, uint8_t seid,
621                              tAVDT_CFG* p_cfg);
622 
623 /*******************************************************************************
624  *
625  * Function         AVDT_ConfigRsp
626  *
627  * Description      Respond to a configure request from the peer device.  This
628  *                  function must be called if the application receives an
629  *                  AVDT_CONFIG_IND_EVT through its control callback.
630  *
631  *
632  * Returns          AVDT_SUCCESS if successful, otherwise error.
633  *
634  ******************************************************************************/
635 extern uint16_t AVDT_ConfigRsp(uint8_t handle, uint8_t label,
636                                uint8_t error_code, uint8_t category);
637 
638 /*******************************************************************************
639  *
640  * Function         AVDT_StartReq
641  *
642  * Description      Start one or more stream endpoints.  This initiates the
643  *                  transfer of media packets for the streams.  All stream
644  *                  endpoints must previously be opened.  When the streams
645  *                  are started, an AVDT_START_CFM_EVT is sent to the
646  *                  application via the control callback function for each
647  *                  stream.
648  *
649  *
650  * Returns          AVDT_SUCCESS if successful, otherwise error.
651  *
652  ******************************************************************************/
653 extern uint16_t AVDT_StartReq(uint8_t* p_handles, uint8_t num_handles);
654 
655 /*******************************************************************************
656  *
657  * Function         AVDT_SuspendReq
658  *
659  * Description      Suspend one or more stream endpoints. This suspends the
660  *                  transfer of media packets for the streams.  All stream
661  *                  endpoints must previously be open and started.  When the
662  *                  streams are suspended, an AVDT_SUSPEND_CFM_EVT is sent to
663  *                  the application via the control callback function for
664  *                  each stream.
665  *
666  *
667  * Returns          AVDT_SUCCESS if successful, otherwise error.
668  *
669  ******************************************************************************/
670 extern uint16_t AVDT_SuspendReq(uint8_t* p_handles, uint8_t num_handles);
671 
672 /*******************************************************************************
673  *
674  * Function         AVDT_CloseReq
675  *
676  * Description      Close a stream endpoint.  This stops the transfer of media
677  *                  packets and closes the transport channel associated with
678  *                  this stream endpoint.  When the stream is closed, an
679  *                  AVDT_CLOSE_CFM_EVT is sent to the application via the
680  *                  control callback function for this handle.
681  *
682  *
683  * Returns          AVDT_SUCCESS if successful, otherwise error.
684  *
685  ******************************************************************************/
686 extern uint16_t AVDT_CloseReq(uint8_t handle);
687 
688 /*******************************************************************************
689  *
690  * Function         AVDT_ReconfigReq
691  *
692  * Description      Reconfigure a stream endpoint.  This allows the application
693  *                  to change the codec or content protection capabilities of
694  *                  a stream endpoint after it has been opened.  This function
695  *                  can only be called if the stream is opened but not started
696  *                  or if the stream has been suspended.  When the procedure
697  *                  is completed, an AVDT_RECONFIG_CFM_EVT is sent to the
698  *                  application via the control callback function for this
699  *                  handle.
700  *
701  *
702  * Returns          AVDT_SUCCESS if successful, otherwise error.
703  *
704  ******************************************************************************/
705 extern uint16_t AVDT_ReconfigReq(uint8_t handle, tAVDT_CFG* p_cfg);
706 
707 /*******************************************************************************
708  *
709  * Function         AVDT_ReconfigRsp
710  *
711  * Description      Respond to a reconfigure request from the peer device.
712  *                  This function must be called if the application receives
713  *                  an AVDT_RECONFIG_IND_EVT through its control callback.
714  *
715  *
716  * Returns          AVDT_SUCCESS if successful, otherwise error.
717  *
718  ******************************************************************************/
719 extern uint16_t AVDT_ReconfigRsp(uint8_t handle, uint8_t label,
720                                  uint8_t error_code, uint8_t category);
721 
722 /*******************************************************************************
723  *
724  * Function         AVDT_SecurityReq
725  *
726  * Description      Send a security request to the peer device.  When the
727  *                  security procedure is completed, an AVDT_SECURITY_CFM_EVT
728  *                  is sent to the application via the control callback function
729  *                  for this handle.  (Please note that AVDTP security
730  *                  procedures are unrelated to Bluetooth link level security.)
731  *
732  *
733  * Returns          AVDT_SUCCESS if successful, otherwise error.
734  *
735  ******************************************************************************/
736 extern uint16_t AVDT_SecurityReq(uint8_t handle, uint8_t* p_data, uint16_t len);
737 
738 /*******************************************************************************
739  *
740  * Function         AVDT_SecurityRsp
741  *
742  * Description      Respond to a security request from the peer device.
743  *                  This function must be called if the application receives
744  *                  an AVDT_SECURITY_IND_EVT through its control callback.
745  *                  (Please note that AVDTP security procedures are unrelated
746  *                  to Bluetooth link level security.)
747  *
748  *
749  * Returns          AVDT_SUCCESS if successful, otherwise error.
750  *
751  ******************************************************************************/
752 extern uint16_t AVDT_SecurityRsp(uint8_t handle, uint8_t label,
753                                  uint8_t error_code, uint8_t* p_data,
754                                  uint16_t len);
755 
756 /*******************************************************************************
757  *
758  * Function         AVDT_WriteReq
759  *
760  * Description      Send a media packet to the peer device.  The stream must
761  *                  be started before this function is called.  Also, this
762  *                  function can only be called if the stream is a SRC.
763  *
764  *                  When AVDTP has sent the media packet and is ready for the
765  *                  next packet, an AVDT_WRITE_CFM_EVT is sent to the
766  *                  application via the control callback.  The application must
767  *                  wait for the AVDT_WRITE_CFM_EVT before it makes the next
768  *                  call to AVDT_WriteReq().  If the applications calls
769  *                  AVDT_WriteReq() before it receives the event the packet
770  *                  will not be sent.  The application may make its first call
771  *                  to AVDT_WriteReq() after it receives an AVDT_START_CFM_EVT
772  *                  or AVDT_START_IND_EVT.
773  *
774  *                  The application passes the packet using the BT_HDR
775  *                  structure.
776  *                  This structure is described in section 2.1.  The offset
777  *                  field must be equal to or greater than AVDT_MEDIA_OFFSET.
778  *                  This allows enough space in the buffer for the L2CAP and
779  *                  AVDTP headers.
780  *
781  *                  The memory pointed to by p_pkt must be a GKI buffer
782  *                  allocated by the application.  This buffer will be freed
783  *                  by the protocol stack; the application must not free
784  *                  this buffer.
785  *
786  *
787  * Returns          AVDT_SUCCESS if successful, otherwise error.
788  *
789  ******************************************************************************/
790 extern uint16_t AVDT_WriteReq(uint8_t handle, BT_HDR* p_pkt,
791                               uint32_t time_stamp, uint8_t m_pt);
792 /*******************************************************************************
793  *
794  * Function         AVDT_WriteReqOpt
795  *
796  * Description      Send a media packet to the peer device.  The stream must
797  *                  be started before this function is called.  Also, this
798  *                  function can only be called if the stream is a SRC
799  *
800  *                  When AVDTP has sent the media packet and is ready for the
801  *                  next packet, an AVDT_WRITE_CFM_EVT is sent to the
802  *                  application via the control callback.  The application must
803  *                  wait for the AVDT_WRITE_CFM_EVT before it makes the next
804  *                  call to AVDT_WriteReq().  If the applications calls
805  *                  AVDT_WriteReq() before it receives the event the packet
806  *                  will not be sent.  The application may make its first call
807  *                  to AVDT_WriteReq() after it receives an AVDT_START_CFM_EVT
808  *                  or AVDT_START_IND_EVT.
809  *
810  *                  The application passes the packet using the BT_HDR structure
811  *                  This structure is described in section 2.1.  The offset
812  *                  field must be equal to or greater than AVDT_MEDIA_OFFSET
813  *                  (if NO_RTP is specified, L2CAP_MIN_OFFSET can be used)
814  *                  This allows enough space in the buffer for the L2CAP and
815  *                  AVDTP headers.
816  *
817  *                  The memory pointed to by p_pkt must be a GKI buffer
818  *                  allocated by the application.  This buffer will be freed
819  *                  by the protocol stack; the application must not free
820  *                  this buffer.
821  *
822  *                  The opt parameter allows passing specific options like:
823  *                  - NO_RTP : do not add the RTP header to buffer
824  *
825  * Returns          AVDT_SUCCESS if successful, otherwise error.
826  *
827  ******************************************************************************/
828 extern uint16_t AVDT_WriteReqOpt(uint8_t handle, BT_HDR* p_pkt,
829                                  uint32_t time_stamp, uint8_t m_pt,
830                                  tAVDT_DATA_OPT_MASK opt);
831 
832 /*******************************************************************************
833  *
834  * Function         AVDT_ConnectReq
835  *
836  * Description      This function initiates an AVDTP signaling connection
837  *                  to the peer device.  When the connection is completed, an
838  *                  AVDT_CONNECT_IND_EVT is sent to the application via its
839  *                  control callback function.  If the connection attempt fails
840  *                  an AVDT_DISCONNECT_IND_EVT is sent.  The security mask
841  *                  parameter overrides the outgoing security mask set in
842  *                  AVDT_Register().
843  *
844  * Returns          AVDT_SUCCESS if successful, otherwise error.
845  *
846  ******************************************************************************/
847 extern uint16_t AVDT_ConnectReq(BD_ADDR bd_addr, uint8_t sec_mask,
848                                 tAVDT_CTRL_CBACK* p_cback);
849 
850 /*******************************************************************************
851  *
852  * Function         AVDT_DisconnectReq
853  *
854  * Description      This function disconnect an AVDTP signaling connection
855  *                  to the peer device.  When disconnected an
856  *                  AVDT_DISCONNECT_IND_EVT is sent to the application via its
857  *                  control callback function.
858  *
859  * Returns          AVDT_SUCCESS if successful, otherwise error.
860  *
861  ******************************************************************************/
862 extern uint16_t AVDT_DisconnectReq(BD_ADDR bd_addr, tAVDT_CTRL_CBACK* p_cback);
863 
864 /*******************************************************************************
865  *
866  * Function         AVDT_GetL2CapChannel
867  *
868  * Description      Get the L2CAP CID used by the handle.
869  *
870  * Returns          CID if successful, otherwise 0.
871  *
872  ******************************************************************************/
873 extern uint16_t AVDT_GetL2CapChannel(uint8_t handle);
874 
875 /*******************************************************************************
876  *
877  * Function         AVDT_GetSignalChannel
878  *
879  * Description      Get the L2CAP CID used by the signal channel of the given
880  *                  handle.
881  *
882  * Returns          CID if successful, otherwise 0.
883  *
884  ******************************************************************************/
885 extern uint16_t AVDT_GetSignalChannel(uint8_t handle, BD_ADDR bd_addr);
886 
887 /*******************************************************************************
888  *
889  * Function         AVDT_SendReport
890  *
891  * Description
892  *
893  *
894  *
895  * Returns
896  *
897  ******************************************************************************/
898 extern uint16_t AVDT_SendReport(uint8_t handle, AVDT_REPORT_TYPE type,
899                                 tAVDT_REPORT_DATA* p_data);
900 
901 /******************************************************************************
902  *
903  * Function         AVDT_SetTraceLevel
904  *
905  * Description      Sets the trace level for AVDT. If 0xff is passed, the
906  *                  current trace level is returned.
907  *
908  *                  Input Parameters:
909  *                      new_level:  The level to set the AVDT tracing to:
910  *                      0xff-returns the current setting.
911  *                      0-turns off tracing.
912  *                      >= 1-Errors.
913  *                      >= 2-Warnings.
914  *                      >= 3-APIs.
915  *                      >= 4-Events.
916  *                      >= 5-Debug.
917  *
918  * Returns          The new trace level or current trace level if
919  *                  the input parameter is 0xff.
920  *
921  *****************************************************************************/
922 extern uint8_t AVDT_SetTraceLevel(uint8_t new_level);
923 
924 #endif /* AVDT_API_H */
925