1 /******************************************************************************
2  *
3  *  Copyright (C) 2014 The Android Open Source Project
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  *  This file contains action functions for SDP search.
21  ******************************************************************************/
22 
23 // #include <hardware/bluetooth.h>
24 #include "bt_sdp.h"
25 // #include <arpa/inet.h>
26 #include "common/bt_defs.h"
27 #include <stdlib.h>
28 #include <string.h>
29 #include "common/bt_target.h"
30 #include "osi/allocator.h"
31 #include "stack/bt_types.h"
32 #include "bta/utl.h"
33 #include "bta/bta_sys.h"
34 #include "bta/bta_api.h"
35 #include "bta/bta_sdp_api.h"
36 #include "bta_sdp_int.h"
37 #include "stack/btm_api.h"
38 #include "btm_int.h"
39 #include "stack/sdp_api.h"
40 
41 #if (SDP_INCLUDED == TRUE)
42 
43 /*****************************************************************************
44 **  Constants
45 *****************************************************************************/
46 
47 static const uint8_t  UUID_OBEX_OBJECT_PUSH[] = {0x00, 0x00, 0x11, 0x05, 0x00, 0x00, 0x10, 0x00,
48                                                  0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB
49                                                 };
50 static const uint8_t  UUID_PBAP_PSE[] = {0x00, 0x00, 0x11, 0x2F, 0x00, 0x00, 0x10, 0x00,
51                                          0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB
52                                         };
53 static const uint8_t  UUID_MAP_MAS[] = {0x00, 0x00, 0x11, 0x32, 0x00, 0x00, 0x10, 0x00,
54                                         0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB
55                                        };
56 static const uint8_t  UUID_MAP_MNS[] = {0x00, 0x00, 0x11, 0x33, 0x00, 0x00, 0x10, 0x00,
57                                         0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB
58                                        };
59 static const uint8_t  UUID_SPP[] = {0x00, 0x00, 0x11, 0x01, 0x00, 0x00, 0x10, 0x00,
60                                     0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB
61                                    };
62 static const uint8_t  UUID_SAP[] = {0x00, 0x00, 0x11, 0x2D, 0x00, 0x00, 0x10, 0x00,
63                                     0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB
64                                    };
65 // TODO:
66 // Both the fact that the UUIDs are declared in multiple places, plus the fact
67 // that there is a mess of UUID comparison and shortening methods will have to
68 // be fixed.
69 // The btcore->uuid module should be used for all instances.
70 
71 #define UUID_MAX_LENGTH 16
72 #define IS_UUID(u1,u2)  !memcmp(u1,u2,UUID_MAX_LENGTH)
73 
shorten_sdp_uuid(const tBT_UUID * u)74 static inline tBT_UUID shorten_sdp_uuid(const tBT_UUID *u)
75 {
76     static uint8_t bt_base_uuid[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00,
77                                      0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB
78                                     };
79 
80     APPL_TRACE_DEBUG("%s() - uuid len:%d\n", __func__, u->len);
81     if (u->len != 16) {
82         return *u;
83     }
84 
85     if (memcmp(&u->uu.uuid128[4], &bt_base_uuid[4], 12) != 0) {
86         return *u;
87     }
88 
89     tBT_UUID su;
90     memset(&su, 0, sizeof(su));
91     if (u->uu.uuid128[0] == 0 && u->uu.uuid128[1] == 0) {
92         su.len = 2;
93         uint16_t u16;
94         memcpy(&u16, &u->uu.uuid128[2], sizeof(u16));
95         su.uu.uuid16 = ntohs(u16);
96     } else {
97         su.len = 4;
98         uint32_t u32;
99         memcpy(&u32, &u->uu.uuid128[0], sizeof(u32));
100         su.uu.uuid32 = ntohl(u32);
101     }
102     return su;
103 }
104 
bta_create_mns_sdp_record(bluetooth_sdp_record * record,tSDP_DISC_REC * p_rec)105 static void bta_create_mns_sdp_record(bluetooth_sdp_record *record, tSDP_DISC_REC *p_rec)
106 {
107     tSDP_DISC_ATTR *p_attr;
108     tSDP_PROTOCOL_ELEM pe;
109     UINT16 pversion = 0;
110     record->mns.hdr.type = SDP_TYPE_MAP_MNS;
111     record->mns.hdr.service_name_length = 0;
112     record->mns.hdr.service_name = NULL;
113     record->mns.hdr.rfcomm_channel_number = 0;
114     record->mns.hdr.l2cap_psm = -1;
115     record->mns.hdr.profile_version = 0;
116     record->mns.supported_features = 0x0000001F; //default value if not found
117 
118     if ((p_attr = SDP_FindAttributeInRec(p_rec, ATTR_ID_MAP_SUPPORTED_FEATURES)) != NULL) {
119         record->mns.supported_features = p_attr->attr_value.v.u32;
120     }
121 
122     if ((p_attr = SDP_FindAttributeInRec(p_rec, ATTR_ID_SERVICE_NAME)) != NULL) {
123         record->mns.hdr.service_name_length = SDP_DISC_ATTR_LEN(p_attr->attr_len_type);
124         record->mns.hdr.service_name = (char *)p_attr->attr_value.v.array;
125     }
126 
127     if (SDP_FindProfileVersionInRec(p_rec, UUID_SERVCLASS_MAP_PROFILE, &pversion)) {
128         record->mns.hdr.profile_version = pversion;
129     }
130 
131     if (SDP_FindProtocolListElemInRec(p_rec, UUID_PROTOCOL_RFCOMM, &pe)) {
132         record->mns.hdr.rfcomm_channel_number = pe.params[0];
133     }
134 
135     if ((p_attr = SDP_FindAttributeInRec(p_rec, ATTR_ID_GOEP_L2CAP_PSM)) != NULL) {
136         record->mns.hdr.l2cap_psm = p_attr->attr_value.v.u16;
137     }
138 }
139 
bta_create_mas_sdp_record(bluetooth_sdp_record * record,tSDP_DISC_REC * p_rec)140 static void bta_create_mas_sdp_record(bluetooth_sdp_record *record, tSDP_DISC_REC *p_rec)
141 {
142     tSDP_DISC_ATTR *p_attr;
143     tSDP_PROTOCOL_ELEM pe;
144     UINT16 pversion = -1;
145 
146     record->mas.hdr.type = SDP_TYPE_MAP_MAS;
147     record->mas.hdr.service_name_length = 0;
148     record->mas.hdr.service_name = NULL;
149     record->mas.hdr.rfcomm_channel_number = 0;
150     record->mas.hdr.l2cap_psm = -1;
151     record->mas.hdr.profile_version = 0;
152     record->mas.mas_instance_id = 0;
153     record->mas.supported_features = 0x0000001F;
154     record->mas.supported_message_types = 0;
155 
156     if ((p_attr = SDP_FindAttributeInRec(p_rec, ATTR_ID_MAS_INSTANCE_ID)) != NULL) {
157         record->mas.mas_instance_id = p_attr->attr_value.v.u8;
158     }
159 
160     if ((p_attr = SDP_FindAttributeInRec(p_rec, ATTR_ID_SUPPORTED_MSG_TYPE)) != NULL) {
161         record->mas.supported_message_types = p_attr->attr_value.v.u8;
162     }
163 
164     if ((p_attr = SDP_FindAttributeInRec(p_rec, ATTR_ID_MAP_SUPPORTED_FEATURES)) != NULL) {
165         record->mas.supported_features = p_attr->attr_value.v.u32;
166     }
167 
168     if ((p_attr = SDP_FindAttributeInRec(p_rec, ATTR_ID_SERVICE_NAME)) != NULL) {
169         record->mas.hdr.service_name_length = SDP_DISC_ATTR_LEN(p_attr->attr_len_type);
170         record->mas.hdr.service_name = (char *)p_attr->attr_value.v.array;
171     }
172 
173     if (SDP_FindProfileVersionInRec(p_rec, UUID_SERVCLASS_MAP_PROFILE, &pversion)) {
174         record->mas.hdr.profile_version = pversion;
175     }
176 
177     if (SDP_FindProtocolListElemInRec(p_rec, UUID_PROTOCOL_RFCOMM, &pe)) {
178         record->mas.hdr.rfcomm_channel_number = pe.params[0];
179     }
180 
181     if ((p_attr = SDP_FindAttributeInRec(p_rec, ATTR_ID_GOEP_L2CAP_PSM)) != NULL) {
182         record->mas.hdr.l2cap_psm = p_attr->attr_value.v.u16;
183     }
184 }
185 
bta_create_pse_sdp_record(bluetooth_sdp_record * record,tSDP_DISC_REC * p_rec)186 static void bta_create_pse_sdp_record(bluetooth_sdp_record *record, tSDP_DISC_REC *p_rec)
187 {
188     tSDP_DISC_ATTR *p_attr;
189     UINT16 pversion;
190     tSDP_PROTOCOL_ELEM pe;
191 
192     record->pse.hdr.type = SDP_TYPE_PBAP_PSE;
193     record->pse.hdr.service_name_length = 0;
194     record->pse.hdr.service_name = NULL;
195     record->pse.hdr.rfcomm_channel_number = 0;
196     record->pse.hdr.l2cap_psm = -1;
197     record->pse.hdr.profile_version = 0;
198     record->pse.supported_features = 0x00000003;
199     record->pse.supported_repositories = 0;
200 
201     if ((p_attr = SDP_FindAttributeInRec(p_rec, ATTR_ID_SUPPORTED_REPOSITORIES)) != NULL) {
202         record->pse.supported_repositories = p_attr->attr_value.v.u8;
203     }
204     if ((p_attr = SDP_FindAttributeInRec(p_rec, ATTR_ID_PBAP_SUPPORTED_FEATURES)) != NULL) {
205         record->pse.supported_features = p_attr->attr_value.v.u32;
206     }
207 
208     if ((p_attr = SDP_FindAttributeInRec(p_rec, ATTR_ID_SERVICE_NAME)) != NULL) {
209         record->pse.hdr.service_name_length = SDP_DISC_ATTR_LEN(p_attr->attr_len_type);
210         record->pse.hdr.service_name = (char *)p_attr->attr_value.v.array;
211     }
212 
213     if (SDP_FindProfileVersionInRec(p_rec, UUID_SERVCLASS_PHONE_ACCESS, &pversion)) {
214         record->pse.hdr.profile_version = pversion;
215     }
216 
217     if (SDP_FindProtocolListElemInRec(p_rec, UUID_PROTOCOL_RFCOMM, &pe)) {
218         record->pse.hdr.rfcomm_channel_number = pe.params[0];
219     }
220 
221     if ((p_attr = SDP_FindAttributeInRec(p_rec, ATTR_ID_GOEP_L2CAP_PSM)) != NULL) {
222         record->pse.hdr.l2cap_psm = p_attr->attr_value.v.u16;
223     }
224 }
225 
bta_create_ops_sdp_record(bluetooth_sdp_record * record,tSDP_DISC_REC * p_rec)226 static void bta_create_ops_sdp_record(bluetooth_sdp_record *record, tSDP_DISC_REC *p_rec)
227 {
228     tSDP_DISC_ATTR *p_attr, *p_sattr;
229     tSDP_PROTOCOL_ELEM pe;
230     UINT16 pversion = -1;
231 
232     record->ops.hdr.type = SDP_TYPE_OPP_SERVER;
233     record->ops.hdr.service_name_length = 0;
234     record->ops.hdr.service_name = NULL;
235     record->ops.hdr.rfcomm_channel_number = 0;
236     record->ops.hdr.l2cap_psm = -1;
237     record->ops.hdr.profile_version = 0;
238     record->ops.supported_formats_list_len = 0;
239 
240     if ((p_attr = SDP_FindAttributeInRec(p_rec, ATTR_ID_SERVICE_NAME)) != NULL) {
241         record->ops.hdr.service_name_length = SDP_DISC_ATTR_LEN(p_attr->attr_len_type);
242         record->ops.hdr.service_name = (char *)p_attr->attr_value.v.array;
243     }
244 
245     if (SDP_FindProfileVersionInRec(p_rec, UUID_SERVCLASS_OBEX_OBJECT_PUSH, &pversion)) {
246         record->ops.hdr.profile_version = pversion;
247     }
248 
249     if (SDP_FindProtocolListElemInRec(p_rec, UUID_PROTOCOL_RFCOMM, &pe)) {
250         record->ops.hdr.rfcomm_channel_number = pe.params[0];
251     }
252 
253     if ((p_attr = SDP_FindAttributeInRec(p_rec, ATTR_ID_GOEP_L2CAP_PSM)) != NULL) {
254         record->ops.hdr.l2cap_psm = p_attr->attr_value.v.u16;
255     }
256     if ((p_attr = SDP_FindAttributeInRec(p_rec, ATTR_ID_SUPPORTED_FORMATS_LIST)) != NULL) {
257         /* Safety check - each entry should itself be a sequence */
258         if (SDP_DISC_ATTR_TYPE(p_attr->attr_len_type) != DATA_ELE_SEQ_DESC_TYPE) {
259             record->ops.supported_formats_list_len = 0;
260             APPL_TRACE_ERROR("%s() - supported_formats_list - wrong attribute length/type:"
261                              " 0x%02x - expected 0x06", __func__, p_attr->attr_len_type);
262         } else {
263             int count = 0;
264             /* 1 byte for type/length 1 byte for value */
265             record->ops.supported_formats_list_len = SDP_DISC_ATTR_LEN(p_attr->attr_len_type) / 2;
266 
267             /* Extract each value into */
268             for (p_sattr = p_attr->attr_value.v.p_sub_attr;
269                     p_sattr != NULL; p_sattr = p_sattr->p_next_attr) {
270                 if ((SDP_DISC_ATTR_TYPE(p_sattr->attr_len_type) == UINT_DESC_TYPE)
271                         && (SDP_DISC_ATTR_LEN(p_sattr->attr_len_type) == 1)) {
272                     if (count == sizeof(record->ops.supported_formats_list)) {
273                         APPL_TRACE_ERROR("%s() - supported_formats_list - count overflow - "
274                                          "too many sub attributes!!\n", __func__);
275                         /* If you hit this, new formats have been added,
276                          * update SDP_OPP_SUPPORTED_FORMATS_MAX_LENGTH */
277                         break;
278                     }
279                     record->ops.supported_formats_list[count] = p_sattr->attr_value.v.u8;
280                     count++;
281                 } else {
282                     APPL_TRACE_ERROR("%s() - supported_formats_list - wrong sub attribute "
283                                      "length/type: 0x%02x - expected 0x80", __func__,
284                                      p_sattr->attr_len_type);
285                     break;
286                 }
287             }
288             if (record->ops.supported_formats_list_len != count) {
289                 APPL_TRACE_WARNING("%s() - supported_formats_list - Length of attribute different "
290                                    "from the actual number of sub-attributes in the sequence "
291                                    "att-length: %d - number of elements: %d\n", __func__,
292                                    record->ops.supported_formats_list_len , count);
293 
294             }
295             record->ops.supported_formats_list_len = count;
296         }
297     }
298 }
299 
bta_create_sap_sdp_record(bluetooth_sdp_record * record,tSDP_DISC_REC * p_rec)300 static void bta_create_sap_sdp_record(bluetooth_sdp_record *record, tSDP_DISC_REC *p_rec)
301 {
302     tSDP_DISC_ATTR *p_attr;
303     tSDP_PROTOCOL_ELEM pe;
304     UINT16 pversion = -1;
305 
306     record->sap.hdr.type = SDP_TYPE_MAP_MAS;
307     record->sap.hdr.service_name_length = 0;
308     record->sap.hdr.service_name = NULL;
309     record->sap.hdr.rfcomm_channel_number = 0;
310     record->sap.hdr.l2cap_psm = -1;
311     record->sap.hdr.profile_version = 0;
312 
313     if ((p_attr = SDP_FindAttributeInRec(p_rec, ATTR_ID_SERVICE_NAME)) != NULL) {
314         record->sap.hdr.service_name_length = SDP_DISC_ATTR_LEN(p_attr->attr_len_type);
315         record->sap.hdr.service_name = (char *)p_attr->attr_value.v.array;
316     }
317 
318     if (SDP_FindProfileVersionInRec(p_rec, UUID_SERVCLASS_SAP, &pversion)) {
319         record->sap.hdr.profile_version = pversion;
320     }
321 
322     if (SDP_FindProtocolListElemInRec(p_rec, UUID_PROTOCOL_RFCOMM, &pe)) {
323         record->sap.hdr.rfcomm_channel_number = pe.params[0];
324     }
325 }
326 
bta_create_raw_sdp_record(bluetooth_sdp_record * record,tSDP_DISC_REC * p_rec)327 static void bta_create_raw_sdp_record(bluetooth_sdp_record *record, tSDP_DISC_REC *p_rec)
328 {
329     tSDP_DISC_ATTR *p_attr;
330     tSDP_PROTOCOL_ELEM pe;
331 
332     record->hdr.type = SDP_TYPE_RAW;
333     record->hdr.service_name_length = 0;
334     record->hdr.service_name = NULL;
335     record->hdr.rfcomm_channel_number = -1;
336     record->hdr.l2cap_psm = -1;
337     record->hdr.profile_version = -1;
338 
339     /* Try to extract a service name */
340     if ((p_attr = SDP_FindAttributeInRec(p_rec, ATTR_ID_SERVICE_NAME)) != NULL) {
341         record->pse.hdr.service_name_length = SDP_DISC_ATTR_LEN(p_attr->attr_len_type);
342         record->pse.hdr.service_name = (char *)p_attr->attr_value.v.array;
343     }
344 
345     /* Try to extract an RFCOMM channel */
346     if (SDP_FindProtocolListElemInRec(p_rec, UUID_PROTOCOL_RFCOMM, &pe)) {
347         record->pse.hdr.rfcomm_channel_number = pe.params[0];
348     }
349     record->hdr.user1_ptr_len = p_bta_sdp_cfg->p_sdp_db->raw_size;
350     record->hdr.user1_ptr = p_bta_sdp_cfg->p_sdp_db->raw_data;
351 }
352 
353 
354 /*******************************************************************************
355 **
356 ** Function     bta_sdp_search_cback
357 **
358 ** Description  Callback from btm after search is completed
359 **
360 ** Returns      void
361 **
362 *******************************************************************************/
bta_sdp_search_cback(UINT16 result,void * user_data)363 static void bta_sdp_search_cback(UINT16 result, void *user_data)
364 {
365     tSDP_DISC_REC *p_rec = NULL;
366     tBTA_SDP_SEARCH_COMP evt_data = {0}; // We need to zero-initialize
367     tBTA_SDP_STATUS status = BTA_SDP_FAILURE;
368     int count = 0;
369     tBT_UUID su;
370     APPL_TRACE_DEBUG("%s() -  res: 0x%x\n", __func__, result);
371 
372     bta_sdp_cb.sdp_active = BTA_SDP_ACTIVE_NONE;
373 
374     if (bta_sdp_cb.p_dm_cback == NULL) {
375         return;
376     }
377 
378     bdcpy(evt_data.remote_addr, bta_sdp_cb.remote_addr);
379     tBT_UUID *uuid = (tBT_UUID *)user_data;
380     memcpy(&evt_data.uuid, uuid, sizeof(tBT_UUID));
381     su = shorten_sdp_uuid(uuid);
382 
383     if (result == SDP_SUCCESS || result == SDP_DB_FULL) {
384         do {
385             p_rec = SDP_FindServiceUUIDInDb(p_bta_sdp_cfg->p_sdp_db, &su, p_rec);
386             /* generate the matching record data pointer */
387             if (p_rec != NULL) {
388                 status = BTA_SDP_SUCCESS;
389                 if (IS_UUID(UUID_MAP_MAS, uuid->uu.uuid128)) {
390                     APPL_TRACE_DEBUG("%s() - found MAP (MAS) uuid\n", __func__);
391                     bta_create_mas_sdp_record(&evt_data.records[count], p_rec);
392                 } else if (IS_UUID(UUID_MAP_MNS, uuid->uu.uuid128)) {
393                     APPL_TRACE_DEBUG("%s() - found MAP (MNS) uuid\n", __func__);
394                     bta_create_mns_sdp_record(&evt_data.records[count], p_rec);
395                 } else if (IS_UUID(UUID_PBAP_PSE, uuid->uu.uuid128)) {
396                     APPL_TRACE_DEBUG("%s() - found PBAP (PSE) uuid\n", __func__);
397                     bta_create_pse_sdp_record(&evt_data.records[count], p_rec);
398                 } else if (IS_UUID(UUID_OBEX_OBJECT_PUSH, uuid->uu.uuid128)) {
399                     APPL_TRACE_DEBUG("%s() - found Object Push Server (OPS) uuid\n", __func__);
400                     bta_create_ops_sdp_record(&evt_data.records[count], p_rec);
401                 } else if (IS_UUID(UUID_SAP, uuid->uu.uuid128)) {
402                     APPL_TRACE_DEBUG("%s() - found SAP uuid\n", __func__);
403                     bta_create_sap_sdp_record(&evt_data.records[count], p_rec);
404                 } else {
405 
406                     /* we do not have specific structure for this */
407                     APPL_TRACE_DEBUG("%s() - profile not identified. using raw data\n", __func__);
408                     bta_create_raw_sdp_record(&evt_data.records[count], p_rec);
409                     p_rec = NULL; // Terminate loop
410                     /* For raw, we only extract the first entry, and then return the entire
411                        raw data chunk.
412                        TODO: Find a way to split the raw data into record chunks, and iterate
413                              to extract generic data for each chunk - e.g. rfcomm channel and
414                              service name. */
415                 }
416                 count++;
417             } else {
418                 APPL_TRACE_DEBUG("%s() - UUID not found\n", __func__);
419             }
420         } while (p_rec != NULL && count < BTA_SDP_MAX_RECORDS);
421 
422         evt_data.record_count = count;
423     }
424     evt_data.status = status;
425 
426     bta_sdp_cb.p_dm_cback(BTA_SDP_SEARCH_COMP_EVT, (tBTA_SDP *) &evt_data, (void *)&uuid->uu.uuid128);
427     osi_free(user_data); // We no longer need the user data to track the search
428 }
429 
430 /*******************************************************************************
431 **
432 ** Function     bta_sdp_enable
433 **
434 ** Description  Initializes the SDP I/F
435 **
436 ** Returns      void
437 **
438 *******************************************************************************/
bta_sdp_enable(tBTA_SDP_MSG * p_data)439 void bta_sdp_enable(tBTA_SDP_MSG *p_data)
440 {
441     APPL_TRACE_DEBUG("%s in, sdp_active:%d\n", __func__, bta_sdp_cb.sdp_active);
442     tBTA_SDP_STATUS status = BTA_SDP_SUCCESS;
443     bta_sdp_cb.p_dm_cback = p_data->enable.p_cback;
444     bta_sdp_cb.p_dm_cback(BTA_SDP_ENABLE_EVT, (tBTA_SDP *)&status, NULL);
445 }
446 
447 /*******************************************************************************
448 **
449 ** Function     bta_sdp_search
450 **
451 ** Description  Discovers all sdp records for an uuid on remote device
452 **
453 ** Returns      void
454 **
455 *******************************************************************************/
bta_sdp_search(tBTA_SDP_MSG * p_data)456 void bta_sdp_search(tBTA_SDP_MSG *p_data)
457 {
458     int x = 0;
459     // TODO: Leaks!!! but needed as user-data pointer
460     tBT_UUID *bta_sdp_search_uuid = osi_malloc(sizeof(tBT_UUID));
461     if (p_data == NULL) {
462         APPL_TRACE_DEBUG("SDP control block handle is null\n");
463         return;
464     }
465     tBTA_SDP_STATUS status = BTA_SDP_FAILURE;
466 
467     APPL_TRACE_DEBUG("%s in, sdp_active:%d\n", __func__, bta_sdp_cb.sdp_active);
468 
469     if (bta_sdp_cb.sdp_active != BTA_SDP_ACTIVE_NONE) {
470         /* SDP is still in progress */
471         status = BTA_SDP_BUSY;
472         if (bta_sdp_cb.p_dm_cback) {
473             tBTA_SDP_SEARCH_COMP result = {0};
474             result.uuid = p_data->get_search.uuid;
475             bdcpy(result.remote_addr, p_data->get_search.bd_addr);
476             result.status = status;
477             bta_sdp_cb.p_dm_cback(BTA_SDP_SEARCH_COMP_EVT, (tBTA_SDP *)&result, NULL);
478         }
479         return;
480     }
481 
482     bta_sdp_cb.sdp_active = BTA_SDP_ACTIVE_YES;
483     bdcpy(bta_sdp_cb.remote_addr, p_data->get_search.bd_addr);
484     /* set the uuid used in the search */
485     memcpy(bta_sdp_search_uuid, &(p_data->get_search.uuid), sizeof(tBT_UUID));
486 
487     /* initialize the search for the uuid */
488     APPL_TRACE_DEBUG("%s init discovery with UUID(len: %d):\n",
489                      __func__, bta_sdp_search_uuid->len);
490     for (x = 0; x < bta_sdp_search_uuid->len; x++) {
491         APPL_TRACE_DEBUG("%X", bta_sdp_search_uuid->uu.uuid128[x]);
492     }
493     SDP_InitDiscoveryDb (p_bta_sdp_cfg->p_sdp_db, p_bta_sdp_cfg->sdp_db_size, 1,
494                          bta_sdp_search_uuid, 0, NULL);
495 
496     if (!SDP_ServiceSearchAttributeRequest2(p_data->get_search.bd_addr, p_bta_sdp_cfg->p_sdp_db,
497                                             bta_sdp_search_cback, (void *)bta_sdp_search_uuid)) {
498         bta_sdp_cb.sdp_active = BTA_SDP_ACTIVE_NONE;
499 
500         /* failed to start SDP. report the failure right away */
501         if (bta_sdp_cb.p_dm_cback) {
502             tBTA_SDP_SEARCH_COMP result = {0};
503             result.uuid = p_data->get_search.uuid;
504             bdcpy(result.remote_addr, p_data->get_search.bd_addr);
505             result.status = status;
506             bta_sdp_cb.p_dm_cback(BTA_SDP_SEARCH_COMP_EVT, (tBTA_SDP *)&result, NULL);
507         }
508     }
509     /*
510     else report the result when the cback is called
511     */
512 }
513 
514 /*******************************************************************************
515 **
516 ** Function     bta_sdp_record
517 **
518 ** Description  Discovers all sdp records for an uuid on remote device
519 **
520 ** Returns      void
521 **
522 *******************************************************************************/
bta_sdp_create_record(tBTA_SDP_MSG * p_data)523 void bta_sdp_create_record(tBTA_SDP_MSG *p_data)
524 {
525     APPL_TRACE_DEBUG("%s() event: %d\n", __func__, p_data->record.hdr.event);
526     if (bta_sdp_cb.p_dm_cback) {
527         bta_sdp_cb.p_dm_cback(BTA_SDP_CREATE_RECORD_USER_EVT, NULL, p_data->record.user_data);
528     }
529 }
530 
531 /*******************************************************************************
532 **
533 ** Function     bta_sdp_create_record
534 **
535 ** Description  Discovers all sdp records for an uuid on remote device
536 **
537 ** Returns      void
538 **
539 *******************************************************************************/
bta_sdp_remove_record(tBTA_SDP_MSG * p_data)540 void bta_sdp_remove_record(tBTA_SDP_MSG *p_data)
541 {
542     APPL_TRACE_DEBUG("%s() event: %d\n", __func__, p_data->record.hdr.event);
543     if (bta_sdp_cb.p_dm_cback) {
544         bta_sdp_cb.p_dm_cback(BTA_SDP_REMOVE_RECORD_USER_EVT, NULL, p_data->record.user_data);
545     }
546 }
547 
548 #endif  ///SDP_INCLUDED == TRUE
549