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