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