• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /******************************************************************************
2  *
3  *  Copyright (C) 2003-2013 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  *  AVRCP SDP related functions
22  *
23  ******************************************************************************/
24 #include <string.h>
25 
26 #include "bt_common.h"
27 #include "avrc_api.h"
28 #include "avrc_int.h"
29 
30 #ifndef SDP_AVRCP_1_4
31 #define SDP_AVRCP_1_4      TRUE
32 #endif
33 
34 #ifndef SDP_AVCTP_1_4
35 #define SDP_AVCTP_1_4      TRUE
36 #endif
37 
38 /*****************************************************************************
39 **  Global data
40 *****************************************************************************/
41 #if AVRC_DYNAMIC_MEMORY == FALSE
42 tAVRC_CB avrc_cb;
43 #endif
44 
45 /******************************************************************************
46 **
47 ** Function         avrc_sdp_cback
48 **
49 ** Description      This is the SDP callback function used by A2D_FindService.
50 **                  This function will be executed by SDP when the service
51 **                  search is completed.  If the search is successful, it
52 **                  finds the first record in the database that matches the
53 **                  UUID of the search.  Then retrieves various parameters
54 **                  from the record.  When it is finished it calls the
55 **                  application callback function.
56 **
57 ** Returns          Nothing.
58 **
59 ******************************************************************************/
avrc_sdp_cback(UINT16 status)60 static void avrc_sdp_cback(UINT16 status)
61 {
62     AVRC_TRACE_API("avrc_sdp_cback status: %d", status);
63 
64     /* reset service_uuid, so can start another find service */
65     avrc_cb.service_uuid = 0;
66 
67     /* return info from sdp record in app callback function */
68     (*avrc_cb.p_cback) (status);
69 
70     return;
71 }
72 
73 /******************************************************************************
74 **
75 ** Function         AVRC_FindService
76 **
77 ** Description      This function is called by the application to perform service
78 **                  discovery and retrieve AVRCP SDP record information from a
79 **                  peer device.  Information is returned for the first service
80 **                  record found on the server that matches the service UUID.
81 **                  The callback function will be executed when service discovery
82 **                  is complete.  There can only be one outstanding call to
83 **                  AVRC_FindService() at a time; the application must wait for
84 **                  the callback before it makes another call to the function.
85 **                  The application is responsible for allocating memory for the
86 **                  discovery database.  It is recommended that the size of the
87 **                  discovery database be at least 300 bytes.  The application
88 **                  can deallocate the memory after the callback function has
89 **                  executed.
90 **
91 **                  Input Parameters:
92 **                      service_uuid: Indicates TG(UUID_SERVCLASS_AV_REM_CTRL_TARGET)
93 **                                           or CT(UUID_SERVCLASS_AV_REMOTE_CONTROL)
94 **
95 **                      bd_addr:  BD address of the peer device.
96 **
97 **                      p_db:  SDP discovery database parameters.
98 **
99 **                      p_cback:  Pointer to the callback function.
100 **
101 **                  Output Parameters:
102 **                      None.
103 **
104 ** Returns          AVRC_SUCCESS if successful.
105 **                  AVRC_BAD_PARAMS if discovery database parameters are invalid.
106 **                  AVRC_NO_RESOURCES if there are not enough resources to
107 **                                    perform the service search.
108 **
109 ******************************************************************************/
AVRC_FindService(UINT16 service_uuid,BD_ADDR bd_addr,tAVRC_SDP_DB_PARAMS * p_db,tAVRC_FIND_CBACK * p_cback)110 UINT16 AVRC_FindService(UINT16 service_uuid, BD_ADDR bd_addr,
111                 tAVRC_SDP_DB_PARAMS *p_db, tAVRC_FIND_CBACK *p_cback)
112 {
113     tSDP_UUID   uuid_list;
114     BOOLEAN     result = TRUE;
115     UINT16      a2d_attr_list[] = {ATTR_ID_SERVICE_CLASS_ID_LIST, /* update AVRC_NUM_ATTR, if changed */
116                                    ATTR_ID_PROTOCOL_DESC_LIST,
117                                    ATTR_ID_BT_PROFILE_DESC_LIST,
118                                    ATTR_ID_SERVICE_NAME,
119                                    ATTR_ID_SUPPORTED_FEATURES,
120                                    ATTR_ID_PROVIDER_NAME};
121 
122     AVRC_TRACE_API("AVRC_FindService uuid: %x", service_uuid);
123     if( (service_uuid != UUID_SERVCLASS_AV_REM_CTRL_TARGET && service_uuid != UUID_SERVCLASS_AV_REMOTE_CONTROL) ||
124         p_db == NULL || p_db->p_db == NULL || p_cback == NULL)
125         return AVRC_BAD_PARAM;
126 
127     /* check if it is busy */
128     if( avrc_cb.service_uuid == UUID_SERVCLASS_AV_REM_CTRL_TARGET ||
129         avrc_cb.service_uuid == UUID_SERVCLASS_AV_REMOTE_CONTROL)
130         return AVRC_NO_RESOURCES;
131 
132     /* set up discovery database */
133     uuid_list.len = LEN_UUID_16;
134     uuid_list.uu.uuid16 = service_uuid;
135 
136     if(p_db->p_attrs == NULL || p_db->num_attr == 0)
137     {
138         p_db->p_attrs  = a2d_attr_list;
139         p_db->num_attr = AVRC_NUM_ATTR;
140     }
141 
142     result = SDP_InitDiscoveryDb(p_db->p_db, p_db->db_len, 1, &uuid_list, p_db->num_attr,
143                                  p_db->p_attrs);
144 
145     if (result == TRUE)
146     {
147         /* store service_uuid and discovery db pointer */
148         avrc_cb.p_db = p_db->p_db;
149         avrc_cb.service_uuid = service_uuid;
150         avrc_cb.p_cback = p_cback;
151 
152         /* perform service search */
153         result = SDP_ServiceSearchAttributeRequest(bd_addr, p_db->p_db, avrc_sdp_cback);
154     }
155 
156     return (result ? AVRC_SUCCESS : AVRC_FAIL);
157 }
158 
159 /******************************************************************************
160 **
161 ** Function         AVRC_AddRecord
162 **
163 ** Description      This function is called to build an AVRCP SDP record.
164 **                  Prior to calling this function the application must
165 **                  call SDP_CreateRecord() to create an SDP record.
166 **
167 **                  Input Parameters:
168 **                      service_uuid:  Indicates TG(UUID_SERVCLASS_AV_REM_CTRL_TARGET)
169 **                                            or CT(UUID_SERVCLASS_AV_REMOTE_CONTROL)
170 **
171 **                      p_service_name:  Pointer to a null-terminated character
172 **                      string containing the service name.
173 **                      If service name is not used set this to NULL.
174 **
175 **                      p_provider_name:  Pointer to a null-terminated character
176 **                      string containing the provider name.
177 **                      If provider name is not used set this to NULL.
178 **
179 **                      categories:  Supported categories.
180 **
181 **                      sdp_handle:  SDP handle returned by SDP_CreateRecord().
182 **
183 **                      browse_supported:  browse support info.
184 **
185 **                      profile_version:  profile version of avrcp record.
186 **
187 **                  Output Parameters:
188 **                      None.
189 **
190 ** Returns          AVRC_SUCCESS if successful.
191 **                  AVRC_NO_RESOURCES if not enough resources to build the SDP record.
192 **
193 ******************************************************************************/
AVRC_AddRecord(UINT16 service_uuid,char * p_service_name,char * p_provider_name,UINT16 categories,UINT32 sdp_handle,BOOLEAN browse_supported,UINT16 profile_version)194 UINT16 AVRC_AddRecord(UINT16 service_uuid, char *p_service_name,
195                 char *p_provider_name, UINT16 categories, UINT32 sdp_handle,
196                 BOOLEAN browse_supported, UINT16 profile_version)
197 {
198     UINT16      browse_list[1];
199     BOOLEAN     result = TRUE;
200     UINT8       temp[8];
201     UINT8       *p;
202     UINT16      count = 1;
203     UINT8       index = 0;
204     UINT16      class_list[2];
205 
206 
207     AVRC_TRACE_API("AVRC_AddRecord uuid: %x", service_uuid);
208 
209     if( service_uuid != UUID_SERVCLASS_AV_REM_CTRL_TARGET && service_uuid != UUID_SERVCLASS_AV_REMOTE_CONTROL )
210         return AVRC_BAD_PARAM;
211 
212     /* add service class id list */
213     class_list[0] = service_uuid;
214     if((service_uuid == UUID_SERVCLASS_AV_REMOTE_CONTROL ) && (profile_version > AVRC_REV_1_3))
215     {
216         class_list[1] = UUID_SERVCLASS_AV_REM_CTRL_CONTROL;
217         count = 2;
218     }
219     result &= SDP_AddServiceClassIdList(sdp_handle, count, class_list);
220 
221     /* add protocol descriptor list   */
222     tSDP_PROTOCOL_ELEM  avrc_proto_desc_list [AVRC_NUM_PROTO_ELEMS];
223     avrc_proto_desc_list[0].num_params = 1;
224     avrc_proto_desc_list[0].protocol_uuid = UUID_PROTOCOL_L2CAP;
225     avrc_proto_desc_list[0].params[0] = AVCT_PSM;
226     avrc_proto_desc_list[0].params[1] = 0;
227     for (index = 1; index < AVRC_NUM_PROTO_ELEMS; index++)
228     {
229         avrc_proto_desc_list[index].num_params = 1;
230         avrc_proto_desc_list[index].protocol_uuid = UUID_PROTOCOL_AVCTP;
231         avrc_proto_desc_list[index].params[0] = AVCT_REV_1_4;
232         avrc_proto_desc_list[index].params[1] = 0;
233     }
234     result &= SDP_AddProtocolList(sdp_handle, AVRC_NUM_PROTO_ELEMS,
235                                                   (tSDP_PROTOCOL_ELEM *)avrc_proto_desc_list);
236 
237     /* additional protocal descriptor, required only for version > 1.3    */
238     if ((profile_version > AVRC_REV_1_3) && (browse_supported))
239     {
240         tSDP_PROTO_LIST_ELEM  avrc_add_proto_desc_list;
241         avrc_add_proto_desc_list.num_elems = 2;
242         avrc_add_proto_desc_list.list_elem[0].num_params = 1;
243         avrc_add_proto_desc_list.list_elem[0].protocol_uuid = UUID_PROTOCOL_L2CAP;
244         avrc_add_proto_desc_list.list_elem[0].params[0] = AVCT_BR_PSM;
245         avrc_add_proto_desc_list.list_elem[0].params[1] = 0;
246         avrc_add_proto_desc_list.list_elem[1].num_params = 1;
247         avrc_add_proto_desc_list.list_elem[1].protocol_uuid = UUID_PROTOCOL_AVCTP;
248         avrc_add_proto_desc_list.list_elem[1].params[0] = AVCT_REV_1_4;
249         avrc_add_proto_desc_list.list_elem[1].params[1] = 0;
250 
251         result &= SDP_AddAdditionProtoLists( sdp_handle, 1, (tSDP_PROTO_LIST_ELEM *)&avrc_add_proto_desc_list);
252     }
253     /* add profile descriptor list   */
254     result &= SDP_AddProfileDescriptorList(sdp_handle, UUID_SERVCLASS_AV_REMOTE_CONTROL, profile_version);
255 
256     /* add supported categories */
257     p = temp;
258     UINT16_TO_BE_STREAM(p, categories);
259     result &= SDP_AddAttribute(sdp_handle, ATTR_ID_SUPPORTED_FEATURES, UINT_DESC_TYPE,
260               (UINT32)2, (UINT8*)temp);
261 
262     /* add provider name */
263     if (p_provider_name != NULL)
264     {
265         result &= SDP_AddAttribute(sdp_handle, ATTR_ID_PROVIDER_NAME, TEXT_STR_DESC_TYPE,
266                     (UINT32)(strlen(p_provider_name)+1), (UINT8 *) p_provider_name);
267     }
268 
269     /* add service name */
270     if (p_service_name != NULL)
271     {
272         result &= SDP_AddAttribute(sdp_handle, ATTR_ID_SERVICE_NAME, TEXT_STR_DESC_TYPE,
273                     (UINT32)(strlen(p_service_name)+1), (UINT8 *) p_service_name);
274     }
275 
276     /* add browse group list */
277     browse_list[0] = UUID_SERVCLASS_PUBLIC_BROWSE_GROUP;
278     result &= SDP_AddUuidSequence(sdp_handle, ATTR_ID_BROWSE_GROUP_LIST, 1, browse_list);
279 
280 
281     return (result ? AVRC_SUCCESS : AVRC_FAIL);
282 }
283 
284 
285 
286 /******************************************************************************
287 **
288 ** Function         AVRC_SetTraceLevel
289 **
290 ** Description      Sets the trace level for AVRC. If 0xff is passed, the
291 **                  current trace level is returned.
292 **
293 **                  Input Parameters:
294 **                      new_level:  The level to set the AVRC tracing to:
295 **                      0xff-returns the current setting.
296 **                      0-turns off tracing.
297 **                      >= 1-Errors.
298 **                      >= 2-Warnings.
299 **                      >= 3-APIs.
300 **                      >= 4-Events.
301 **                      >= 5-Debug.
302 **
303 ** Returns          The new trace level or current trace level if
304 **                  the input parameter is 0xff.
305 **
306 ******************************************************************************/
AVRC_SetTraceLevel(UINT8 new_level)307 UINT8 AVRC_SetTraceLevel (UINT8 new_level)
308 {
309     if (new_level != 0xFF)
310         avrc_cb.trace_level = new_level;
311 
312     return (avrc_cb.trace_level);
313 }
314 
315 /*******************************************************************************
316 **
317 ** Function         AVRC_Init
318 **
319 ** Description      This function is called at stack startup to allocate the
320 **                  control block (if using dynamic memory), and initializes the
321 **                  control block and tracing level.
322 **
323 ** Returns          void
324 **
325 *******************************************************************************/
AVRC_Init(void)326 void AVRC_Init(void)
327 {
328     memset(&avrc_cb, 0, sizeof(tAVRC_CB));
329 
330 #if defined(AVRC_INITIAL_TRACE_LEVEL)
331     avrc_cb.trace_level  = AVRC_INITIAL_TRACE_LEVEL;
332 #else
333     avrc_cb.trace_level  = BT_TRACE_LEVEL_NONE;
334 #endif
335 }
336 
337