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