1 /*
2  * Copyright (C) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 /**
16  * @addtogroup Bluetooth
17  * @{
18  *
19  * @brief This file is a part of BTStack.
20  * @since 6.0
21  */
22 
23 /**
24  * @file avdtp.h
25  *
26  * @brief AVDT protocol Interface.
27  *
28  * @since 6.0
29  */
30 #ifndef AVDTP_H
31 #define AVDTP_H
32 
33 #include <stdbool.h>
34 #include <stddef.h>
35 #include <stdint.h>
36 
37 #include "btstack.h"
38 #include "packet.h"
39 
40 #ifdef __cplusplus
41 extern "C" {
42 #endif
43 /**
44  *  Constants
45  */
46 #define AVDT_VERSION_1_3 0x0103  // AVDTP.ICS #Table 14a-3,15a-3 version 1.3
47 
48 #ifndef AVDT_NUM_SEPS
49 #define AVDT_NUM_SEPS 6  // SOW Max Number of stream endpoints
50 #endif
51 
52 #ifndef AVDT_NUM_LINKS
53 #define AVDT_NUM_LINKS 6  // SOW Max Number of link devices
54 #endif
55 
56 /**
57  * AVDTP.ICS #Table 14-1, 15-1 Basics Service.
58  * The Max size of the codec capabilities information element.
59  */
60 #define AVDT_CODEC_SIZE 20
61 
62 /**
63  * The return value of the API function
64  */
65 #define AVDT_SUCCESS 0       // Successful
66 #define AVDT_BAD_PARAMS 1    // Invalid parameters
67 #define AVDT_NO_RESOURCES 2  // Not resources
68 #define AVDT_BAD_HANDLE 3    // Invalid handle
69 #define AVDT_BUSY 4          // A procedure is doing,such as discovery seps
70 #define AVDT_FAILED 5        // Procedure failed
71 
72 /**
73  * AVDTP.ICS #Table 1-1,1-2 SEP Type.
74  */
75 #define AVDT_SEP_SRC 0      // Source SEP
76 #define AVDT_SEP_SNK 1      // Sink SEP
77 #define AVDT_SEP_INVALID 2  // Invalid SEP
78 
79 /**
80  * AVDTP Initiator(INT)and Acceptor(ACP).
81  */
82 #define AVDT_INT 0  // Initiator
83 #define AVDT_ACP 1  // Acceptor
84 
85 /**
86  * AVDTP Source(SRC)and Sink(SNK)
87  */
88 #define AVDT_ROLE_SRC 0     // source
89 #define AVDT_ROLE_SNK 1     // sink
90 #define AVDT_ROLE_UNKOWN 2  // unknown
91 
92 /**
93  * Media Type of the SEP
94  */
95 #define AVDT_MEDIA_TYPE_AUDIO 0  // Audio SEP
96 #define AVDT_MEDIA_TYPE_VIDEO 1  // Retain: Video SEP
97 
98 /**
99  * Error codes defined in the AVDTP and GAVDP specifications.
100  * AVDTP.ICS #Table 16-1, Reporting Capability Error
101  */
102 #define AVDT_ERR_BAD_HEADER_FORMAT 0x01           // Packet header format is error
103 #define AVDT_ERR_BAD_LENGTH 0x11                  // The length of packet is error
104 #define AVDT_ERR_BAD_ACP_SEID 0x12                // Invalid SEID
105 #define AVDT_ERR_SEP_IN_USE 0x13                  // The SEP use
106 #define AVDT_ERR_SEP_NOT_IN_USE 0x14              // The SEP used
107 #define AVDT_ERR_BAD_SERV_CATEGORY 0x17           // The service category is error
108 #define AVDT_ERR_BAD_PAYLOAD_FORMAT 0x18          // The payload format is error
109 #define AVDT_ERR_UNSUPPORTED_COMMAND 0x19         // Requested command is not supported
110 #define AVDT_ERR_INVALID_CAPABILITIES 0x1A        // Invalid capabilities
111 #define AVDT_ERR_BAD_RECOVERY_TYPE 0x22           // The requested Recovery Type is not defined in AVDTP.
112 #define AVDT_ERR_BAD_MEDIA_TRANSPORT_FORMAT 0x23  // Media transport capability is error
113 #define AVDT_ERR_BAD_RECOVERY_FORMAT 0x25         // The format of Recovery Service Capability is not correct.
114 #define AVDT_ERR_UNSUPPORTED_CONFIGURATION 0x29   // Configuration is not supported
115 #define AVDT_ERR_BAD_STATE 0x31                   // Message can't be processed in this state
116 #define AVDT_ERR_SERVICE 0x80                     // Invalid service category
117 #define AVDT_ERR_RESOURCE 0x81                    // Not enough resources
118 #define AVDT_ERR_INVALID_MCT 0xC1                 // Invalid Media Codec Type
119 #define AVDT_ERR_UNSUP_MCT 0xC2                   // Unsupported Media Codec Type
120 
121 /**
122  * AVDTP 13.1.1 Control callback events
123  */
124 #define AVDT_DISCOVER_CFM_EVT 0       // Discover confirm
125 #define AVDT_DISCOVER_IND_EVT 1       // Discover indication
126 #define AVDT_GETCAP_CFM_EVT 2         // Get capabilities confirm
127 #define AVDT_GETCAP_IND_EVT 3         // Get capabilities indication
128 #define AVDT_OPEN_CFM_EVT 4           // Open confirm
129 #define AVDT_OPEN_IND_EVT 5           // Open indication
130 #define AVDT_CONFIG_CFM_EVT 6         // Configuration confirm
131 #define AVDT_CONFIG_IND_EVT 7         // Configuration indication
132 #define AVDT_START_CFM_EVT 8          // Start confirm
133 #define AVDT_START_IND_EVT 9          // Start indication
134 #define AVDT_SUSPEND_CFM_EVT 10       // Suspend confirm
135 #define AVDT_SUSPEND_IND_EVT 11       // Suspend indication
136 #define AVDT_CLOSE_CFM_EVT 12         // Close confirm
137 #define AVDT_CLOSE_IND_EVT 13         // Close indication
138 #define AVDT_RECONFIG_CFM_EVT 14      // Reconfiguration confirm
139 #define AVDT_RECONFIG_IND_EVT 15      // Reconfiguration indication
140 #define AVDT_WRITE_CFM_EVT 16         // Write confirm
141 #define AVDT_READ_IND_EVT 17          // Read indication
142 #define AVDT_CONNECT_CFM_EVT 18       // Connected confirm
143 #define AVDT_CONNECT_IND_EVT 19       // Connected indication
144 #define AVDT_DISCONNECT_CFM_EVT 20    // Disconnected confirm
145 #define AVDT_DISCONNECT_IND_EVT 21    // Disconnected indication
146 #define AVDT_DELAY_REPORT_IND_EVT 22  // Delay report indication
147 #define AVDT_DELAY_REPORT_CFM_EVT 23  // Delay report confirm
148 #define AVDT_ABORT_CFM_EVT 24         // Abort confirm
149 #define AVDT_ABORT_IND_EVT 25         // Abort indication
150 #define AVDT_GETCONFIG_CFM_EVT 26     // get Configuration confirm
151 #define AVDT_GETCONFIG_IND_EVT 27     // get Configuration indication
152 #define AVDT_GET_ALLCAP_CFM_EVT 28    // Get all capabilities confirm
153 #define AVDT_GET_ALLCAP_IND_EVT 29    // Get all capabilities indication
154 #define AVDT_CLOSE_TRANS_IND_EVT 30   // Receive transport released inication
155 #define AVDT_MAX_EVT (AVDT_CLOSE_TRANS_IND_EVT)
156 
157 #define AVDT_PSM 0x0019  // PSM for AVDT
158 /**
159  * Capability mask
160  * AVDTP.ICS #Table 14-1, 15-1 AVDT protocol service capabilities
161  */
162 
163 #define AVDT_PSC_MSK_TRANS (1 << 0)      // Media Transport
164 #define AVDT_PSC_MSK_REPORT (1 << 1)     // Reporting
165 #define AVDT_PSC_MSK_RECOV (1 << 2)      // Recovery
166 #define AVDT_PSC_MSK_PROTECT (1 << 3)    // Content Protection
167 #define AVDT_PSC_MSK_HDRCMP (1 << 4)     // Header Compression
168 #define AVDT_PSC_MSK_MUX (1 << 5)        // Header Compression
169 #define AVDT_PSC_MSK_CODEC (1 << 6)      // Media Codec
170 #define AVDT_PSC_MSK_DELAY_RPT (1 << 7)  // Delay Reporting
171 /**
172  * Type Definitions
173  */
174 
175 /**
176  * Service category
177  */
178 typedef struct {
179     uint8_t errCode;   // error code
180     uint8_t category;  // category
181 } AvdtCatetory;
182 
183 /**
184  * SEP information. transportred during the discovery procedure.
185  */
186 typedef struct {
187     uint8_t seid;       // The identifier of SEP
188     uint8_t mediaType;  // Media type: AVDT_MEDIA_TYPE_AUDIO
189     uint8_t sepType;    // SEP type
190     uint8_t role;       // actor role
191     bool isUsed;        // true if stream is used
192 } AvdtSepInfo;
193 
194 /**
195  * Reject error information.
196  */
197 typedef struct {
198     uint8_t errCode;   // error code
199     uint8_t errParam;  // error param
200 } AvdtRejErrInfo;
201 
202 /*
203  * AVDTP SEP Configuration.
204  */
205 typedef struct {
206     uint8_t codecInfo[AVDT_CODEC_SIZE];  // Codec capabilities
207     uint8_t numCodec;                    // Number of media codec information elements
208     uint8_t mediaType;                   // AVDT_MEDIA_TYPE
209     uint16_t pscMask;                    // Protocol service capabilities mask
210 } AvdtSepConfig;
211 
212 /**
213  * Header structure for callback event parameters
214  */
215 typedef struct {
216     uint8_t errCode;    // Zero if operation succeeded;otherwise failed
217     uint8_t errParam;   // Error parameter included for some events
218     uint8_t label;      // Transaction label
219     uint8_t seid;       // Used inner AVDTp only
220     uint8_t sigId;      // Used inner AVDTponly
221     uint8_t sigHandle;  // Used inner AVDTponly
222     uint16_t mtu;       // Mtu size
223 } AvdtEvtHeader;
224 
225 /**
226  * Configure structure
227  * * */
228 typedef struct {
229     AvdtEvtHeader hdr;  // Event header
230     AvdtSepConfig cfg;  // Pointer to configuration for this SEP
231 } AvdtConfig;
232 
233 /**
234  * Set Configure structure
235  * * */
236 typedef struct {
237     AvdtEvtHeader hdr;  // Event header
238     AvdtSepConfig cfg;  // Pointer to configuration for this SEP
239     uint8_t intSeid;    // The SEP ID initiated
240     uint8_t acpSeid;    // The SEP ID acceptor
241 } AvdtSetConfig;
242 
243 /**
244  * Open stream structure
245  */
246 typedef struct {
247     AvdtEvtHeader hdr;  // Event header
248     uint16_t peerMtu;   // L2CAP MTU of the peer
249     uint16_t lcid;      // L2CAP LCID for media channel.recorded by AVDTP
250 } AvdtOpen;
251 
252 /**
253  * Seps structure
254  */
255 typedef struct {
256     AvdtEvtHeader hdr;                // Event header
257     uint8_t seidList[AVDT_NUM_SEPS];  // Array of SEID values
258     uint8_t numSeps;                  // Number of values in array
259 } AvdtMulti;
260 
261 typedef struct {
262     AvdtEvtHeader hdr;                // Event header
263     AvdtSepInfo seps[AVDT_NUM_SEPS];  // Pointer to SEP information
264     uint8_t numSeps;                  // Number of stream endpoints
265 } AvdtDiscover;
266 
267 typedef struct {
268     AvdtEvtHeader hdr;  // Event header
269     uint16_t delay;     // Delay value
270 } AvdtDelayRpt;
271 
272 /**
273  * Union of all control callback event data structures
274  */
275 typedef union {
276     AvdtEvtHeader hdr;
277     AvdtDiscover discoverCfm;
278     AvdtDiscover discoverInd;
279     AvdtConfig getCapCfm;
280     AvdtConfig getCapInd;
281     AvdtOpen openCfm;
282     AvdtOpen openInd;
283     AvdtSetConfig configInd;
284     AvdtSetConfig configCfm;
285     AvdtEvtHeader startCfm;
286     AvdtEvtHeader startInd;
287     AvdtEvtHeader suspendCfm;
288     AvdtEvtHeader suspendInd;
289     AvdtEvtHeader closeCfm;
290     AvdtEvtHeader closeInd;
291     AvdtConfig reconfigCfm;
292     AvdtConfig reconfigInd;
293     AvdtConfig getconfigCfm;
294     AvdtConfig getconfigInd;
295     AvdtEvtHeader connectInd;
296     AvdtEvtHeader connectCfm;
297     AvdtEvtHeader disconnectInd;
298     AvdtEvtHeader disconnectCfm;
299     AvdtDelayRpt delayRptInd;
300     AvdtDelayRpt delayRptCfm;
301     AvdtEvtHeader abortInd;
302     AvdtEvtHeader abortCfm;
303 } AvdtCtrlData;
304 
305 /**
306  * @brief       Protocol Message data callback function
307  * @details     This is the callback function used by AVDTP to report received AV control messages.
308  * @param[in]   handle    Stream handle
309  * @param[in]   bdAddr    Peer device address
310  * @param[in]   event     Indication/Confirm event of message
311  * @param[in]   data      Avdt event data
312  * @param[in]   role      Local instance role
313  * @return      @c void
314  */
315 typedef void (*AvdtCtrlCallback)(
316     uint16_t handle, const BtAddr *bdAddr, uint8_t event, const AvdtCtrlData *data, uint8_t role);
317 
318 /**
319  * @brief       Callback function for sink to read MediaData
320  * @details     This is the callback function used by AVDTP to report sink to received AV stream data.
321  * @param[in]   handle          Block handle
322  * @param[in]   pkt             Stream data
323  * @param[in]   timeStamp       Timestamp of frame
324  * @param[in]   pt              Packet type
325  * @param[in]   streamHandle    Stream handle
326  * @return      @c void
327  */
328 typedef void (*AVDT_SinkDataCallback)(
329     uint16_t handle, Packet *pkt, uint32_t timeStamp, uint8_t pt, uint16_t streamHandle);
330 
331 /**
332  * AVDT Registration Control Block.
333  */
334 typedef struct {
335     uint16_t mtu;                   // L2CAP MTU for AVDT signaling channel
336     uint8_t role;                   // Source or Sink
337     AvdtCtrlCallback ctrlCallback;  // Control Callback function
338 } AvdtRegisterParam;
339 
340 /**
341  * Used before to create a stream
342  */
343 typedef struct {
344     AvdtSepConfig cfg;                    // SEP configuration
345     uint16_t codecIndex;                  // The handle to the a2dp stream control entry
346     AVDT_SinkDataCallback sinkDataCback;  // Sink data callback function
347     uint16_t mtu;                         // The L2CAP MTU of the transport channel
348     uint16_t flushTo;                     // The L2CAP flush timeout of the transport channel
349     uint8_t sepType;                      // SEP type
350     uint16_t nscMask;                     // Protocol command messages is not supported
351 } AvdtStreamConfig;
352 
353 /**
354  *
355  * @brief       Function AVDT_Register
356  * @details     This function initializes AVDTP and prepares the protocol stack for its use.
357  *              It must be called once by the system or platform using AVDT before the other functions of the API an be
358  *              used.
359  * @param[in]   reg  Register information
360  * @return      void
361  *
362  */
363 BTSTACK_API void AVDT_Register(const AvdtRegisterParam *reg);
364 
365 /**
366  *
367  * @brief   Function AVDT_Deregister
368  * @details This function is called to deregister AVDTP protocol.
369  *          This function can be called after all streams must be removed.
370  * @return  void
371  *
372  */
373 BTSTACK_API void AVDT_Deregister(void);
374 
375 /**
376  *
377  * @brief       Function AVDT_AbortReq
378  * @details     This function is called to request to pass AVDT Abort.
379  *              AVDTP.ICS #Table 5-5, 5b-5 Abort stream command.
380  * @param[in]   handle      Handle of stream
381  * @param[out]  transLabel  The label of this message
382  * @return      AVDT_SUCCESS if successful, otherwise error.
383  *
384  */
385 BTSTACK_API uint16_t AVDT_AbortReq(uint16_t handle, uint8_t *transLabel);
386 
387 /**
388  *
389  * @brief       Function AVDT_AbortRsp
390  * @details     The response of  Abort request from peer device.
391  *              AVDTP.ICS #Table 11-5, 11b-5 Abort stream response
392  * @param[in]   handle      Handle of stream
393  * @param[in]   transLabel  The label of this message
394  * @param[in]   errCode     Error code
395  * @return      AVDT_SUCCESS if successful, otherwise error.
396  *
397  */
398 BTSTACK_API uint16_t AVDT_AbortRsp(uint16_t handle, uint8_t transLabel, uint8_t errCode);
399 
400 /**
401  *
402  * @brief       Function AVDT_CreateStream
403  * @details     Create a stream endpoint. An application can initiate a connection between this endpoint and an endpoint
404  *              on a peer device after a stream endpoint is created.
405  * @param[in]   bdAddr              Peer device address
406  * @param[in]   avdtStreamConfig    Stream  endpoint configure information
407  * @param[out]  handle              Sep handle
408  * @return      AVDT_SUCCESS if successful, otherwise error.
409  *
410  */
411 BTSTACK_API uint16_t AVDT_CreateStream(const BtAddr *bdAddr, uint16_t *handle, uint16_t codeIndex);
412 
413 /**
414  *
415  * @brief       Function AVDT_RegisterLocalSEP
416  * @details     Register local stream endpoint information.
417  * @param[in]   avdtStreamConfig  Stream  endpoint configure information
418  * @return      AVDT_SUCCESS if successful, otherwise error.
419  *
420  */
421 BTSTACK_API uint16_t AVDT_RegisterLocalSEP(AvdtStreamConfig *avdtStreamConfig, uint8_t number);
422 
423 /**
424  *
425  * @brief       Function AVDT_RemoveStream (Retain)
426  * @details     Remove a stream endpoint.
427  * @param[in]   handle   Handle of stream.
428  * @return      AVDT_SUCCESS if successful, otherwise error.
429  *
430  */
431 BTSTACK_API uint16_t AVDT_RemoveStream(uint16_t handle);
432 
433 /**
434  *
435  * @brief       Function AVDT_DiscoverReq
436  * @details     This function send AVDT_DISCOVER_CMD from INT to ACP and it request to get the overview of all SEP
437  *              information of the ACP. When discovery is complete, an AVDT_DISCOVER_CFM_EVT is sent to the application
438  *              via its callback function.The application must not call AVDT_GetCapReq() or AVDT_DiscoverReq() again to
439  *              the same device until discovery is complete. AVDTP.ICS #Table 4-1, 4b-1 Stream discover command
440  * @param[in]   bdAddr        Peer device address
441  * @param[in]   maxSeps       Max number to get SEP
442  * @param[out]  transLabel    Label of this message
443  * @return      AVDT_SUCCESS if successful, otherwise error.
444  *
445  */
446 BTSTACK_API uint16_t AVDT_DiscoverReq(const BtAddr *bdAddr, uint8_t maxSeps, uint8_t *transLabel);
447 
448 /**
449  *
450  * @brief       Function AVDT_DiscoverRsp(Retain)
451  * @details     Respond to a discover request from ACP.
452  *              AVDTP.ICS #Table 10-1, 10b-1 Stream discover response
453  * @param[in]   bdAddr        Peer device address
454  * @param[in]   transLabel    Label of Disvover message
455  * @param[in]   errCode       Error code
456  * @param[in]   sepInfo       SEP information
457  * @param[in]   numSeps       Number of SEP
458  * @return      AVDT_SUCCESS if successful, otherwise error.
459  *
460  */
461 BTSTACK_API uint16_t AVDT_DiscoverRsp(
462     const BtAddr *bdAddr, uint8_t transLabel, uint8_t errCode, AvdtSepInfo *sepInfo, uint8_t numSeps);
463 
464 /**
465  *
466  * @brief       Function AVDT_GetCapReq
467  * @details     This function send AVDT_GETCAP_REQ from INT to ACP and it used to get the information of a SEP of
468  *              ACP.When the procedure is complete, an AVDT_GETCAP_CFM_EVT is sent to the application via its callback
469  *              function.  The application must not call AVDT_GetCapReq() or AVDT_DiscoverReq() again until the
470  *              procedure is complete. AVDTP.ICS #Table 4-2, 4b-2 Stream get capabilities command AVDTP.ICS #Table 4-6,
471  *              4b-6 Stream get all capabilities command.
472  * @param[in]   bdAddr        Peer device address
473  * @param[in]   acpSeid       Seid of Acceptor
474  * @param[out]  transLabel    Label of this message
475  * @return      AVDT_SUCCESS if successful, otherwise error.
476  *
477  */
478 BTSTACK_API uint16_t AVDT_GetCapReq(const BtAddr *bdAddr, uint8_t acpSeid, uint8_t *transLabel);
479 
480 /**
481  *
482  * @brief       Function AVDT_GetCapRsp(Retain)
483  * @details     Respond to a getcap request from ACP.
484  *              AVDTP.ICS #Table 10-2, 10b-2 Stream get capabilities response.
485  * @param[in]   bdAddr        Peer device address
486  * @param[in]   transLabel    Lable of getcapability cmd
487  * @param[in]   errCode       Error code
488  * @param[in]   sepCap        SEP capability information
489  * @return      AVDT_SUCCESS if successful, otherwise error.
490  *
491  */
492 BTSTACK_API uint16_t AVDT_GetCapRsp(const BtAddr *bdAddr, uint8_t transLabel, uint8_t errCode, AvdtSepConfig *sepCap);
493 
494 /**
495  *
496  * @brief       Function AVDT_GetAllCapReq
497  * @details     This function send AVDT_GETALLCAP_REQ from INT to ACP and it used to get the information of a SEP of
498  *              ACP.When the procedure is complete, an AVDT_GETALLCAP_CFM_EVT is sent to the application via its
499  *              callback function. The application must not call AVDT_GetAllCapReq() or AVDT_DiscoverReq() again until
500  *              the procedure is complete. AVDTP.ICS #Table 4-2, 4b-2 Stream get capabilities command AVDTP.ICS #Table
501  *              4-6, 4b-6 Stream get all capabilities command.
502  * @param[in]   bdAddr        Peer device address
503  * @param[in]   acpSeid       Seid of Acceptor
504  * @param[out]  transLabel    Label of this message
505  * @return      AVDT_SUCCESS if successful, otherwise error.
506  *
507  */
508 BTSTACK_API uint16_t AVDT_GetAllCapReq(const BtAddr *bdAddr, uint8_t acpSeid, uint8_t *transLabel);
509 
510 /**
511  *
512  * @brief       Function AVDT_GetAllCapRsp(Retain)
513  * @details     Respond to a getcap request from ACP.
514  *              AVDTP.ICS #Table 10-2, 10b-2 Stream get capabilities response.
515  * @param[in]   bdAddr        Peer device address
516  * @param[in]   transLabel    Lable of getcapability cmd
517  * @param[in]   errCode       Error code
518  * @param[in]   sepCap        SEP capability information
519  * @return      AVDT_SUCCESS if successful, otherwise error.
520  *
521  */
522 BTSTACK_API uint16_t AVDT_GetAllCapRsp(
523     const BtAddr *bdAddr, uint8_t transLabel, uint8_t errCode, AvdtSepConfig *sepCap);
524 
525 /**
526  *
527  * @brief       Function AVDT_DelayReq
528  * @details     This functions sends a Delay Report to ACP that is associated with a particular SEID.This function is
529  *              called by SNK device. AVDTP.ICS #Table 15-6 Delay Reporting
530  * @param[in]   bdAddr        Peer device address
531  * @param[in]   delayValue    Delay data
532  * @param[out]  transLabel    Label of this message
533  * @return      AVDT_SUCCESS if successful, otherwise error.
534  *
535  */
536 BTSTACK_API uint16_t AVDT_DelayReq(uint16_t handle, uint8_t *transLabel, uint16_t delayValue);
537 
538 /**
539  *
540  * @brief       Function AVDT_DelayRsp(Retain)
541  * @details     Respond to a delay request from the peer device.
542  *              AVDTP.ICS #Table 14-6 Delay Reporting.
543  * @param[in]   handle        Handle of stream
544  * @param[in]   transLabel    Label of delay cmd
545  * @param[in]   errCode       Error code
546  * @return      AVDT_SUCCESS if successful, otherwise error.
547  *
548  */
549 BTSTACK_API uint16_t AVDT_DelayRsp(uint16_t handle, uint8_t transLabel, uint8_t errCode);
550 
551 /**
552  *
553  * @brief       Function AVDT_OpenReq
554  * @details     This function send the AVDT_OPEN_REQ from INT to ACP and create the stream between INT and ACP.When the
555  *              connection is completed, an AVDT _OPEN_CFM_EVT is sent to the application via the control callback
556  *              function for this handle. AVDTP.ICS #Table 5-1,5b-1 Open stream command
557  * @param[in]   handle        Handle of stream
558  * @param[out]   transLabel    Label of this message
559  * @return      AVDT_SUCCESS if successful, otherwise error.
560  *
561  */
562 BTSTACK_API uint16_t AVDT_OpenReq(uint16_t handle, uint8_t *transLabel);
563 
564 /**
565  *
566  * @brief       Function AVDT_OpenRsp(Retain)
567  * @details     Respond to an open request from ACP.
568  *              AVDTP.ICS #Table 11-1, 11b-1 Open stream response
569  * @param[in]   handle        Handle of stream
570  * @param[in]   transLabel    Label of this message
571  * @param[in]   errCode       Error code
572  * @return      AVDT_SUCCESS if successful, otherwise error.
573  *
574  */
575 BTSTACK_API uint16_t AVDT_OpenRsp(uint16_t handle, uint8_t transLabel, uint8_t errCode);
576 
577 /**
578  *
579  * @brief       Function AVDT_SetConfigReq
580  * @details     This function send AVDT_CONFIG_CMD from INT to ACP. When the config is completed, an AVDT_CONFIG_CFM_EVT
581  *              is sent to the application via the control callback function for this handle. AVDTP.ICS #Table 4-3, 4b-3
582  *              Set configuration command
583  * @param[in]   handle        Handle of stream
584  * @param[in]   seid          The id of SEP in acceptor
585  * @param[in]   sepConfig     Configure information
586  * @param[out]   transLabel    Label of this message
587  * @return      AVDT_SUCCESS if successful, otherwise error.
588  *
589  */
590 BTSTACK_API uint16_t AVDT_SetConfigReq(uint16_t handle, uint8_t seid, AvdtSepConfig *sepConfig, uint8_t *transLabel);
591 
592 /**
593  *
594  * @brief       AVDT_SetConfigRsp
595  * @details     Respond to a configure request from ACP.  This function must be called if the application receives an
596  *              AVDT_CONFIG_IND_EVT through its control callback. AVDTP.ICS #Table 10-3, 10b-3 Set configuration
597  *              response
598  * @param[in]   handle        Handle of stream
599  * @param[in]   transLabel    Lable of setconfigure cmd
600  * @param[in]   category      Configure result information
601  * @return      AVDT_SUCCESS if successful, otherwise error.
602  *
603  */
604 BTSTACK_API uint16_t AVDT_SetConfigRsp(uint16_t handle, uint8_t transLabel, AvdtCatetory category);
605 
606 /**
607  *
608  * @brief       Function AVDT_GetConfigReq
609  * @details     This function send AVDT_GETCONFIG_CMD from INT to ACP to get the current configuration of a SEP in ACP.
610  *              When the config is completed, an AVDT_GETCONFIG_CFM _EVT is sent to the application via the control
611  *              callback function. AVDTP.ICS #Table 4-4, 4b-4 Get configuration command
612  * @param[in]   handle        Handle of stream
613  * @param[out]  transLabel    Label of this message
614  * @return      AVDT_SUCCESS if successful, otherwise error.
615  *
616  */
617 BTSTACK_API uint16_t AVDT_GetConfigReq(uint16_t handle, uint8_t *transLabel);
618 
619 /**
620  *
621  * @brief       Function AVDT_StartReq
622  * @details     Start one or more stream endpoints(audio/video). All stream endpoints must previously be opened.  When
623  *              the streams are started, an AVDT_START_CFM_EVT is sent to the application via the control callback
624  *              function for each stream. AVDTP.ICS #Table 5-2, 5b-2 Start stream command
625  * @param[in]   handles       Handles of stream, use the first one usually
626  * @param[in]   numHandles    Number of stream
627  * @param[out]  transLabel    Lable of this message
628  * @return      AVDT_SUCCESS if successful, otherwise error.
629  *
630  */
631 BTSTACK_API uint16_t AVDT_StartReq(const uint16_t *handles, uint8_t numHandles, uint8_t *transLabel);
632 
633 /**
634  *
635  * @brief       Function AVDT_StartRsp
636  * @details     Respond to a start request from ACP.  This function must be called if the application receives an
637  *              AVDT_START_IND_EVT through its control callback. AVDTP.ICS #Table 11-2, 11b-2 Start stream command
638  * @param[in]   firstHandle       First stream handle successful
639  * @param[in]   transLabel        Label of start cmd
640  * @param[in]   firstFailHandle   First stream handle failed
641  * @param[in]   errCode           Error code ot the failed handle
642  * @return      AVDT_SUCCESS if successful, otherwise error.
643  *
644  */
645 BTSTACK_API uint16_t AVDT_StartRsp(uint16_t firstHandle, uint8_t transLabel, uint16_t firstFailHandle, uint8_t errCode);
646 
647 /**
648  *
649  * @brief       Function AVDT_SuspendReq
650  * @details     Suspend one or more stream endpoints. This suspends the transport of media packets for the streams.  All
651  *              stream endpoints must previously be open and started.  When the streams are suspended, an
652  *              AVDT_SUSPEND_CFM_EVT is sent to the application via the control callback function for each stream.
653  *              AVDTP.ICS #Table 5-4, 5b-4 Suspend command
654  * @param[in]   handles       Handles of stream, use the first one usually
655  * @param[in]   numHandles    Number of stream
656  * @param[out]  transLabel    Lable of this message
657  * @return      AVDT_SUCCESS if successful, otherwise error.
658  *
659  */
660 BTSTACK_API uint16_t AVDT_SuspendReq(const uint16_t *handles, uint8_t numHandles, uint8_t *transLabel);
661 
662 /**
663  *
664  * @brief       Function AVDT_SuspendRsp
665  * @details     Respond to a suspend request from ACP.  This function must be called if the application receives an
666  *              AVDT_SUSPEND_IND_EVT through its control callback. AVDTP.ICS #Table 11-4, 11b-4 Suspend response
667  * @param[in]   firstHandle       First stream handle successful
668  * @param[in]   transLabel        Label of start cmd
669  * @param[in]   firstFailHandle   First stream handle failed
670  * @param[in]   errCode           Error code ot the failed handle
671  * @return      AVDT_SUCCESS if successful, otherwise error.
672  *
673  */
674 BTSTACK_API uint16_t AVDT_SuspendRsp(
675     uint16_t firstHandle, uint8_t transLabel, uint16_t firstFailHandle, uint8_t errCode);
676 
677 /**
678  *
679  * @brief       Function AVDT_CloseReq
680  * @details     It stops the transport of media packets and close the transport channel associated with this stream
681  *              endpoint.  When the stream is closed,an AVDT_CLOSE_CFM _EVT is sent to the application via the control
682  *              callback function for this handle. AVDTP.ICS #Table 5-3, 5b-3 Close stream command
683  * @param[in]   handle       Handle of stream
684  * @return      AVDT_SUCCESS if successful, otherwise error.
685  *
686  */
687 BTSTACK_API uint16_t AVDT_CloseReq(uint16_t handle);
688 
689 /**
690  *
691  * @brief       Function AVDT_CloseRsp
692  * @details     Respond to a close request from ACP.  This function must be called if the application receives an
693  *              AVDT_CLOSE_IND_EVT through its control callback. AVDTP.ICS #Table 11-3, 11b-c Close stream response
694  * @param[in]   handle       Handle of stream
695  * @param[in]   transLabel   Label of close cmd
696  * @param[in]   errCode      Error code
697  * @return      AVDT_SUCCESS if successful, otherwise error.
698  *
699  */
700 BTSTACK_API uint16_t AVDT_CloseRsp(uint16_t handle, uint8_t transLabel, uint8_t errCode);
701 
702 /**
703  *
704  * @brief       Function AVDT_ReconfigReq
705  * @details     Reconfigure a stream endpoint.  It allows the application can only be called if the stream is opened but
706  *              not started to change the codec capabilities of a stream endpoint after it has been opened.  When the
707  *              procedure is completed, an AVDT_RECONFIG _CFM_EVT is sent to the application via the control callback
708  *              function for this handle. AVDTP.ICS #Table 4-5, 4b-5 Reconfigure command
709  * @param[in]   handle       Handle of stream
710  * @param[in]   cfg          Reconfigure information
711  * @param[out]  transLabel   Label of this message
712  * @return      AVDT_SUCCESS if successful, otherwise error.
713  *
714  */
715 BTSTACK_API uint16_t AVDT_ReconfigReq(uint16_t handle, AvdtSepConfig *cfg, uint8_t *transLabel);
716 
717 /**
718  *
719  * @brief       Funciton AVDT_ReconfigRsp
720  * @details     Respond to a reconfigure request from ACP.This function must be called if the application receives an
721  *              AVDT_RECONFIG_IND_EVT through its control callback. AVDTP.ICS #Table 10-5, 10b-5 Reconfigure response
722  * @param[in]   handle       Handle of stream
723  * @param[in]   transLabel   Label of reconfigure cmd
724  * @param[in]   errCode      Error code
725  * @return      AVDT_SUCCESS if successful, otherwise error.
726  *
727  */
728 BTSTACK_API uint16_t AVDT_ReconfigRsp(uint16_t handle, uint8_t transLabel, AvdtCatetory category);
729 
730 /**
731  *
732  * @brief       Function AVDT_WriteReq
733  * @details     Send a media packet from SOURCE to the SINK and the status of the stream must be streaming. AVDTP 13.2.1
734  * @param[in]   handle       Handle of stream
735  * @param[in]   pkt          Stream data
736  * @param[in]   timeStamp    Timestamp of this stream data sent
737  * @param[in]   payloadType  Payload type
738  * @param[in]   marker       Marker: such ad frame boundaries in the data stream
739  * @return      AVDT_SUCCESS if successful, otherwise error.
740  *
741  */
742 BTSTACK_API uint16_t AVDT_WriteReq(
743     uint16_t handle, const Packet *pkt, uint32_t timeStamp, uint8_t payloadType, uint16_t marker);
744 /**
745  *
746  * @brief       Function AVDT_ConnectRsp(Retain)
747  * @details     Respond to a connect request from ACP. AVDTP.ICS #Table 9-1, 9b-1 Establish signaling channel
748  * @param[in]   bdAddr       Peer device address
749  * @param[in]   errCode      Error code
750  * @return      AVDT_SUCCESS if successful, otherwise error.
751  *
752  */
753 BTSTACK_API uint16_t AVDT_ConnectRsp(const BtAddr *bdAddr, uint8_t errCode);
754 
755 /**
756  *
757  * @brief       Function AVDT_ConnectReq
758  * @details     This function send an AVDT_CONNECT_REQ from INT to ACP.When the connection is completed, an
759  *              AVDT_CONNECT_CFM_EVT is sent to the application via its control callback function. AVDTP.ICS #Table 3-1,
760  *              3b-1 Establish signaling channel
761  * @param[in]   bdAddr   Peer device address
762  * @param[in]   role     Local role
763  * @return      AVDT_SUCCESS if successful, otherwise error.
764  *
765  */
766 BTSTACK_API uint16_t AVDT_ConnectReq(const BtAddr *bdAddr, uint8_t role);
767 
768 /**
769  *
770  * @brief       Function AVDT_DisconnectReq
771  * @details     This function send an AVDT_DISCONNECT_REQ from INT to ACP.When the connection is completed, an
772  *              AVDT_DISCONNECT_CFM_EVT is sent to the application via its control callback function. AVDTP.ICS #Table
773  *              3-2, 3b-2 Establish signaling channel
774  * @param[in]   bdAddr       Peer device address
775  * @return      AVDT_SUCCESS if successful, otherwise error.
776  *
777  */
778 BTSTACK_API uint16_t AVDT_DisconnectReq(const BtAddr *bdAddr);
779 
780 /**
781  *
782  * @brief       Function AVDT_DisconnectRsp(Retain)
783  * @details     Respond to a disconnect request from ACP.
784  *              AVDTP.ICS #Table 9-2, 9b-2 Establish signaling channel
785  * @param[in]   bdAddr       Peer device address
786  * @param[in]   errCode      Error code
787  * @return      AVDT_SUCCESS if successful, otherwise error.
788  *
789  */
790 BTSTACK_API uint16_t AVDT_DisconnectRsp(const BtAddr *bdAddr, uint8_t errCode);
791 
792 /**
793  *
794  * @brief       Function AVDT_GetL2capChannel(Retain)
795  * @details     Get the L2CAP CID used by the handle.
796  * @param[in]   handle       Handle of stream
797  * @return      return channel id if successful, otherwise 0.
798  *
799  */
800 BTSTACK_API uint16_t AVDT_GetL2capChannel(uint16_t handle);
801 
802 /**
803  *
804  * @brief       Function AVDT_Rej(Retain)
805  * @details     Send a reject message from ACP to INT.
806  *              AVDTP.ICS #Table 11-6,11b-6,16-3 General Reject Response Includes Signal ID,General reject message
807  * @param[in]   handle       Handle of stream
808  * @param[in]   bdAddr       Peer device address
809  * @param[in]   cmd          Signaling of AVDT
810  * @param[in]   transLabel    Label of cmd received
811  * @param[in]   errInfo      Error info rejected for command received
812  * @return      void
813  *
814  */
815 BTSTACK_API void AVDT_Rej(
816     uint16_t handle, const BtAddr *bdAddr, uint8_t cmd, uint8_t transLabel, AvdtRejErrInfo errInfo);
817 
818 #ifdef __cplusplus
819 }
820 #endif
821 
822 #endif /* AVDTP_H */
823