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