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(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, const bluetooth::Uuid& uuid) {
78 do_in_main_thread(base::BindOnce(bta_sdp_search, bd_addr, uuid));
79 return BTA_SDP_SUCCESS;
80 }
81
82 /*******************************************************************************
83 *
84 * Function BTA_SdpCreateRecordByUser
85 *
86 * Description This function is used to request a callback to create a SDP
87 * record. The registered callback will be called with event
88 * BTA_SDP_CREATE_RECORD_USER_EVT.
89 *
90 * Returns BTA_SDP_SUCCESS, if the request is being processed.
91 * BTA_SDP_FAILURE, otherwise.
92 *
93 ******************************************************************************/
BTA_SdpCreateRecordByUser(void * user_data)94 tBTA_SDP_STATUS BTA_SdpCreateRecordByUser(void* user_data) {
95 do_in_main_thread(base::BindOnce(bta_sdp_create_record, user_data));
96 return BTA_SDP_SUCCESS;
97 }
98
99 /*******************************************************************************
100 *
101 * Function BTA_SdpRemoveRecordByUser
102 *
103 * Description This function is used to request a callback to remove a SDP
104 * record. The registered callback will be called with event
105 * BTA_SDP_REMOVE_RECORD_USER_EVT.
106 *
107 * Returns BTA_SDP_SUCCESS, if the request is being processed.
108 * BTA_SDP_FAILURE, otherwise.
109 *
110 ******************************************************************************/
BTA_SdpRemoveRecordByUser(void * user_data)111 tBTA_SDP_STATUS BTA_SdpRemoveRecordByUser(void* user_data) {
112 do_in_main_thread(base::BindOnce(bta_sdp_remove_record, user_data));
113 return BTA_SDP_SUCCESS;
114 }
115