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