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