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. */
55 typedef 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. */
69 typedef 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. */
85 typedef 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  *****************************************************************************/
120 extern 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  *****************************************************************************/
159 extern tA2DP_STATUS A2DP_FindService(uint16_t service_uuid, BD_ADDR bd_addr,
160                                      tA2DP_SDP_DB_PARAMS* p_db,
161                                      tA2DP_FIND_CBACK* p_cback);
162 
163 /******************************************************************************
164  *
165  * Function         A2DP_SetTraceLevel
166  *
167  * Description      Sets the trace level for A2D. If 0xff is passed, the
168  *                  current trace level is returned.
169  *
170  *                  Input Parameters:
171  *                      new_level:  The level to set the A2DP tracing to:
172  *                      0xff-returns the current setting.
173  *                      0-turns off tracing.
174  *                      >= 1-Errors.
175  *                      >= 2-Warnings.
176  *                      >= 3-APIs.
177  *                      >= 4-Events.
178  *                      >= 5-Debug.
179  *
180  * Returns          The new trace level or current trace level if
181  *                  the input parameter is 0xff.
182  *
183  *****************************************************************************/
184 extern uint8_t A2DP_SetTraceLevel(uint8_t new_level);
185 
186 /******************************************************************************
187  * Function         A2DP_BitsSet
188  *
189  * Description      Check the given num for the number of bits set
190  * Returns          A2DP_SET_ONE_BIT, if one and only one bit is set
191  *                  A2DP_SET_ZERO_BIT, if all bits clear
192  *                  A2DP_SET_MULTL_BIT, if multiple bits are set
193  *****************************************************************************/
194 extern uint8_t A2DP_BitsSet(uint64_t num);
195 
196 // Initializes the A2DP control block.
197 void A2DP_Init(void);
198 
199 #endif  // A2DP_API_H
200