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