1/******************************************************************************
2 *
3 *  Copyright (C) 2000-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// A2DP API
21//
22
23#ifndef A2DP_API_H
24#define A2DP_API_H
25
26#include <inttypes.h>
27
28#include "a2dp_constants.h"
29#include "a2dp_error_codes.h"
30#include "sdp_api.h"
31
32/*****************************************************************************
33 *  constants
34 ****************************************************************************/
35
36//
37// |MAX_PCM_FRAME_NUM_PER_TICK| controls how many buffers we can hold in
38// the A2DP buffer queues during temporary link congestion.
39//
40#ifndef MAX_PCM_FRAME_NUM_PER_TICK
41#define MAX_PCM_FRAME_NUM_PER_TICK 14
42#endif
43
44/* the return values from A2DP_BitsSet() */
45#define A2DP_SET_ONE_BIT 1   /* one and only one bit is set */
46#define A2DP_SET_ZERO_BIT 0  /* all bits clear */
47#define A2DP_SET_MULTL_BIT 2 /* multiple bits are set */
48
49/*****************************************************************************
50 *  type definitions
51 ****************************************************************************/
52
53/* This data type is used in A2DP_FindService() to initialize the SDP database
54 * to hold the result service search. */
55typedef struct {
56  uint32_t db_len;   /* Length, in bytes, of the discovery database */
57  uint16_t num_attr; /* The number of attributes in p_attrs */
58  uint16_t* p_attrs; /* The attributes filter. If NULL, A2DP API sets the
59                      * attribute filter
60                      * to be ATTR_ID_SERVICE_CLASS_ID_LIST,
61                      * ATTR_ID_BT_PROFILE_DESC_LIST,
62                      * ATTR_ID_SUPPORTED_FEATURES, ATTR_ID_SERVICE_NAME and
63                      * ATTR_ID_PROVIDER_NAME.
64                      * If not NULL, the input is taken as the filter. */
65} tA2DP_SDP_DB_PARAMS;
66
67/* This data type is used in tA2DP_FIND_CBACK to report the result of the SDP
68 * discovery process. */
69typedef struct {
70  uint16_t service_len;  /* Length, in bytes, of the service name */
71  uint16_t provider_len; /* Length, in bytes, of the provider name */
72  char* p_service_name;  /* Pointer the service name.  This character string may
73                          * not be null terminated.
74                          * Use the service_len parameter to safely copy this
75                          * string */
76  char* p_provider_name; /* Pointer the provider name.  This character string
77                          * may not be null terminated.
78                          * Use the provider_len parameter to safely copy this
79                          * string */
80  uint16_t features;     /* Profile supported features */
81  uint16_t avdt_version; /* AVDTP protocol version */
82} tA2DP_Service;
83
84/* This is the callback to notify the result of the SDP discovery process. */
85typedef void(tA2DP_FIND_CBACK)(bool found, tA2DP_Service* p_service);
86
87/*****************************************************************************
88 *  external function declarations
89 ****************************************************************************/
90/******************************************************************************
91 *
92 * Function         A2DP_AddRecord
93 *
94 * Description      This function is called by a server application to add
95 *                  SRC or SNK information to an SDP record.  Prior to
96 *                  calling this function the application must call
97 *                  SDP_CreateRecord() to create an SDP record.
98 *
99 *                  Input Parameters:
100 *                      service_uuid:  Indicates SRC or SNK.
101 *
102 *                      p_service_name:  Pointer to a null-terminated character
103 *                      string containing the service name.
104 *
105 *                      p_provider_name:  Pointer to a null-terminated character
106 *                      string containing the provider name.
107 *
108 *                      features:  Profile supported features.
109 *
110 *                      sdp_handle:  SDP handle returned by SDP_CreateRecord().
111 *
112 *                  Output Parameters:
113 *                      None.
114 *
115 * Returns          A2DP_SUCCESS if function execution succeeded,
116 *                  A2DP_INVALID_PARAMS if bad parameters are given.
117 *                  A2DP_FAIL if function execution failed.
118 *
119 *****************************************************************************/
120extern tA2DP_STATUS A2DP_AddRecord(uint16_t service_uuid, char* p_service_name,
121                                   char* p_provider_name, uint16_t features,
122                                   uint32_t sdp_handle);
123
124/******************************************************************************
125 *
126 * Function         A2DP_FindService
127 *
128 * Description      This function is called by a client application to
129 *                  perform service discovery and retrieve SRC or SNK SDP
130 *                  record information from a server.  Information is
131 *                  returned for the first service record found on the
132 *                  server that matches the service UUID.  The callback
133 *                  function will be executed when service discovery is
134 *                  complete.  There can only be one outstanding call to
135 *                  A2DP_FindService() at a time; the application must wait
136 *                  for the callback before it makes another call to
137 *                  the function.
138 *
139 *                  Input Parameters:
140 *                      service_uuid:  Indicates SRC or SNK.
141 *
142 *                      bd_addr:  BD address of the peer device.
143 *
144 *                      p_db:  Pointer to the information to initialize
145 *                             the discovery database.
146 *
147 *                      p_cback:  Pointer to the A2DP_FindService()
148 *                      callback function.
149 *
150 *                  Output Parameters:
151 *                      None.
152 *
153 * Returns          A2DP_SUCCESS if function execution succeeded,
154 *                  A2DP_INVALID_PARAMS if bad parameters are given.
155 *                  A2DP_BUSY if discovery is already in progress.
156 *                  A2DP_FAIL if function execution failed.
157 *
158 *****************************************************************************/
159extern tA2DP_STATUS A2DP_FindService(uint16_t service_uuid,
160                                     const RawAddress& bd_addr,
161                                     tA2DP_SDP_DB_PARAMS* p_db,
162                                     tA2DP_FIND_CBACK* p_cback);
163
164/******************************************************************************
165 *
166 * Function         A2DP_GetAvdtpVersion()
167 *
168 * Description      Gets the local version of AVDTP
169 *
170 * Returns          The local version of AVDTP.
171 *
172 *****************************************************************************/
173extern uint16_t A2DP_GetAvdtpVersion(void);
174
175/******************************************************************************
176 *
177 * Function         A2DP_SetTraceLevel
178 *
179 * Description      Sets the trace level for A2D. If 0xff is passed, the
180 *                  current trace level is returned.
181 *
182 *                  Input Parameters:
183 *                      new_level:  The level to set the A2DP tracing to:
184 *                      0xff-returns the current setting.
185 *                      0-turns off tracing.
186 *                      >= 1-Errors.
187 *                      >= 2-Warnings.
188 *                      >= 3-APIs.
189 *                      >= 4-Events.
190 *                      >= 5-Debug.
191 *
192 * Returns          The new trace level or current trace level if
193 *                  the input parameter is 0xff.
194 *
195 *****************************************************************************/
196extern uint8_t A2DP_SetTraceLevel(uint8_t new_level);
197
198/******************************************************************************
199 * Function         A2DP_BitsSet
200 *
201 * Description      Check the given num for the number of bits set
202 * Returns          A2DP_SET_ONE_BIT, if one and only one bit is set
203 *                  A2DP_SET_ZERO_BIT, if all bits clear
204 *                  A2DP_SET_MULTL_BIT, if multiple bits are set
205 *****************************************************************************/
206extern uint8_t A2DP_BitsSet(uint64_t num);
207
208// Initializes the A2DP control block.
209void A2DP_Init(void);
210
211#endif  // A2DP_API_H
212