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  *
21  *  This is the implementation of the API for SDP search subsystem
22  *
23  ******************************************************************************/
24 
25 #include "bta/include/bta_sdp_api.h"
26 
27 #include <base/functional/bind.h>
28 #include <base/location.h>
29 
30 #include "bta/sdp/bta_sdp_int.h"
31 #include "internal_include/bt_target.h"
32 #include "stack/include/main_thread.h"
33 #include "types/bluetooth/uuid.h"
34 #include "types/raw_address.h"
35 
36 /*****************************************************************************
37  *  Constants
38  ****************************************************************************/
39 
40 /*******************************************************************************
41  *
42  * Function         BTA_SdpEnable
43  *
44  * Description      Enable the SDP search I/F service. When the enable
45  *                  operation is complete the callback function will be
46  *                  called with a BTA_SDP_ENABLE_EVT. This function must
47  *                  be called before other functions in the SDP search API are
48  *                  called.
49  *
50  * Returns          BTA_SDP_SUCCESS if successful.
51  *                  BTA_SDP_FAIL if internal failure.
52  *
53  ******************************************************************************/
BTA_SdpEnable(tBTA_SDP_DM_CBACK * p_cback)54 tBTA_SDP_STATUS BTA_SdpEnable(tBTA_SDP_DM_CBACK* p_cback) {
55   if (!p_cback) {
56     return BTA_SDP_FAILURE;
57   }
58 
59   memset(&bta_sdp_cb, 0, sizeof(tBTA_SDP_CB));
60   do_in_main_thread(FROM_HERE, base::BindOnce(bta_sdp_enable, p_cback));
61   return BTA_SDP_SUCCESS;
62 }
63 
64 /*******************************************************************************
65  *
66  * Function         BTA_SdpSearch
67  *
68  * Description      This function performs service discovery for a specific
69  *                  service on given peer device. When the operation is
70  *                  completed the tBTA_SDP_DM_CBACK callback function will be
71  *                  called with a BTA_SDP_SEARCH_COMPLETE_EVT.
72  *
73  * Returns          BTA_SDP_SUCCESS, if the request is being processed.
74  *                  BTA_SDP_FAILURE, otherwise.
75  *
76  ******************************************************************************/
BTA_SdpSearch(const RawAddress & bd_addr,const bluetooth::Uuid & uuid)77 tBTA_SDP_STATUS BTA_SdpSearch(const RawAddress& bd_addr,
78                               const bluetooth::Uuid& uuid) {
79   do_in_main_thread(FROM_HERE, base::BindOnce(bta_sdp_search, bd_addr, uuid));
80   return BTA_SDP_SUCCESS;
81 }
82 
83 /*******************************************************************************
84  *
85  * Function         BTA_SdpCreateRecordByUser
86  *
87  * Description      This function is used to request a callback to create a SDP
88  *                  record. The registered callback will be called with event
89  *                  BTA_SDP_CREATE_RECORD_USER_EVT.
90  *
91  * Returns          BTA_SDP_SUCCESS, if the request is being processed.
92  *                  BTA_SDP_FAILURE, otherwise.
93  *
94  ******************************************************************************/
BTA_SdpCreateRecordByUser(void * user_data)95 tBTA_SDP_STATUS BTA_SdpCreateRecordByUser(void* user_data) {
96   do_in_main_thread(FROM_HERE,
97                     base::BindOnce(bta_sdp_create_record, user_data));
98   return BTA_SDP_SUCCESS;
99 }
100 
101 /*******************************************************************************
102  *
103  * Function         BTA_SdpRemoveRecordByUser
104  *
105  * Description      This function is used to request a callback to remove a SDP
106  *                  record. The registered callback will be called with event
107  *                  BTA_SDP_REMOVE_RECORD_USER_EVT.
108  *
109  * Returns          BTA_SDP_SUCCESS, if the request is being processed.
110  *                  BTA_SDP_FAILURE, otherwise.
111  *
112  ******************************************************************************/
BTA_SdpRemoveRecordByUser(void * user_data)113 tBTA_SDP_STATUS BTA_SdpRemoveRecordByUser(void* user_data) {
114   do_in_main_thread(FROM_HERE,
115                     base::BindOnce(bta_sdp_remove_record, user_data));
116   return BTA_SDP_SUCCESS;
117 }
118