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