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