• 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  *
21  *  This is the implementation of the API for SDP search subsystem
22  *
23  ******************************************************************************/
24 
25 #include <string.h>
26 
27 #include "bt_common.h"
28 #include "bta_api.h"
29 #include "bta_sdp_api.h"
30 #include "bta_sdp_int.h"
31 #include "bta_sys.h"
32 #include "port_api.h"
33 #include "sdp_api.h"
34 
35 /*****************************************************************************
36  *  Constants
37  ****************************************************************************/
38 
39 static const tBTA_SYS_REG bta_sdp_reg = {bta_sdp_sm_execute, NULL};
40 
41 /*******************************************************************************
42  *
43  * Function         BTA_SdpEnable
44  *
45  * Description      Enable the SDP search I/F service. When the enable
46  *                  operation is complete the callback function will be
47  *                  called with a BTA_SDP_ENABLE_EVT. This function must
48  *                  be called before other functions in the SDP search API are
49  *                  called.
50  *
51  * Returns          BTA_SDP_SUCCESS if successful.
52  *                  BTA_SDP_FAIL if internal failure.
53  *
54  ******************************************************************************/
BTA_SdpEnable(tBTA_SDP_DM_CBACK * p_cback)55 tBTA_SDP_STATUS BTA_SdpEnable(tBTA_SDP_DM_CBACK* p_cback) {
56   tBTA_SDP_STATUS status = BTA_SDP_FAILURE;
57 
58   APPL_TRACE_API(__func__);
59   if (p_cback && !bta_sys_is_register(BTA_ID_SDP)) {
60     memset(&bta_sdp_cb, 0, sizeof(tBTA_SDP_CB));
61 
62     /* register with BTA system manager */
63     bta_sys_register(BTA_ID_SDP, &bta_sdp_reg);
64 
65     if (p_cback) {
66       tBTA_SDP_API_ENABLE* p_buf =
67           (tBTA_SDP_API_ENABLE*)osi_malloc(sizeof(tBTA_SDP_API_ENABLE));
68       p_buf->hdr.event = BTA_SDP_API_ENABLE_EVT;
69       p_buf->p_cback = p_cback;
70       bta_sys_sendmsg(p_buf);
71       status = BTA_SDP_SUCCESS;
72     }
73   }
74   return status;
75 }
76 
77 /*******************************************************************************
78  *
79  * Function         BTA_SdpSearch
80  *
81  * Description      This function performs service discovery for a specific
82  *                  service on given peer device. When the operation is
83  *                  completed the tBTA_SDP_DM_CBACK callback function will be
84  *                  called with a BTA_SDP_SEARCH_COMPLETE_EVT.
85  *
86  * Returns          BTA_SDP_SUCCESS, if the request is being processed.
87  *                  BTA_SDP_FAILURE, otherwise.
88  *
89  ******************************************************************************/
BTA_SdpSearch(const RawAddress & bd_addr,const bluetooth::Uuid & uuid)90 tBTA_SDP_STATUS BTA_SdpSearch(const RawAddress& bd_addr,
91                               const bluetooth::Uuid& uuid) {
92   tBTA_SDP_API_SEARCH* p_msg =
93       (tBTA_SDP_API_SEARCH*)osi_malloc(sizeof(tBTA_SDP_API_SEARCH));
94 
95   APPL_TRACE_API("%s", __func__);
96 
97   p_msg->hdr.event = BTA_SDP_API_SEARCH_EVT;
98   p_msg->bd_addr = bd_addr;
99   p_msg->uuid = uuid;
100 
101   bta_sys_sendmsg(p_msg);
102 
103   return BTA_SDP_SUCCESS;
104 }
105 
106 /*******************************************************************************
107  *
108  * Function         BTA_SdpCreateRecordByUser
109  *
110  * Description      This function is used to request a callback to create a SDP
111  *                  record. The registered callback will be called with event
112  *                  BTA_SDP_CREATE_RECORD_USER_EVT.
113  *
114  * Returns          BTA_SDP_SUCCESS, if the request is being processed.
115  *                  BTA_SDP_FAILURE, otherwise.
116  *
117  ******************************************************************************/
BTA_SdpCreateRecordByUser(void * user_data)118 tBTA_SDP_STATUS BTA_SdpCreateRecordByUser(void* user_data) {
119   tBTA_SDP_API_RECORD_USER* p_msg =
120       (tBTA_SDP_API_RECORD_USER*)osi_malloc(sizeof(tBTA_SDP_API_RECORD_USER));
121 
122   APPL_TRACE_API("%s", __func__);
123 
124   p_msg->hdr.event = BTA_SDP_API_CREATE_RECORD_USER_EVT;
125   p_msg->user_data = user_data;
126 
127   bta_sys_sendmsg(p_msg);
128 
129   return BTA_SDP_SUCCESS;
130 }
131 
132 /*******************************************************************************
133  *
134  * Function         BTA_SdpRemoveRecordByUser
135  *
136  * Description      This function is used to request a callback to remove a SDP
137  *                  record. The registered callback will be called with event
138  *                  BTA_SDP_REMOVE_RECORD_USER_EVT.
139  *
140  * Returns          BTA_SDP_SUCCESS, if the request is being processed.
141  *                  BTA_SDP_FAILURE, otherwise.
142  *
143  ******************************************************************************/
BTA_SdpRemoveRecordByUser(void * user_data)144 tBTA_SDP_STATUS BTA_SdpRemoveRecordByUser(void* user_data) {
145   tBTA_SDP_API_RECORD_USER* p_msg =
146       (tBTA_SDP_API_RECORD_USER*)osi_malloc(sizeof(tBTA_SDP_API_RECORD_USER));
147 
148   APPL_TRACE_API("%s", __func__);
149 
150   p_msg->hdr.event = BTA_SDP_API_REMOVE_RECORD_USER_EVT;
151   p_msg->user_data = user_data;
152 
153   bta_sys_sendmsg(p_msg);
154 
155   return BTA_SDP_SUCCESS;
156 }
157