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