1 /******************************************************************************
2 *
3 * Copyright (C) 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 "common/bt_target.h"
26 #include "bta/bta_api.h"
27 #include "bta/bta_sys.h"
28 #include "bta/bta_sdp_api.h"
29 #include "bta_sdp_int.h"
30 #include <string.h>
31 #include "osi/allocator.h"
32 #include "stack/sdp_api.h"
33
34 #if defined(BTA_SDP_INCLUDED) && (BTA_SDP_INCLUDED == TRUE)
35 /*****************************************************************************
36 ** Constants
37 *****************************************************************************/
38
39 static const tBTA_SYS_REG bta_sdp_reg = {
40 bta_sdp_sm_execute,
41 NULL
42 };
43
44 /*******************************************************************************
45 **
46 ** Function BTA_SdpEnable
47 **
48 ** Description Enable the SDP search I/F service. When the enable
49 ** operation is complete the callback function will be
50 ** called with a BTA_SDP_ENABLE_EVT. This function must
51 ** be called before other functions in the SDP search API are
52 ** called.
53 **
54 ** Returns BTA_SDP_SUCCESS if successful.
55 ** BTA_SDP_FAIL if internal failure.
56 **
57 *******************************************************************************/
BTA_SdpEnable(tBTA_SDP_DM_CBACK * p_cback)58 tBTA_SDP_STATUS BTA_SdpEnable(tBTA_SDP_DM_CBACK *p_cback)
59 {
60 tBTA_SDP_STATUS status = BTA_SDP_FAILURE;
61 tBTA_SDP_API_ENABLE *p_buf;
62
63 APPL_TRACE_API("%s\n", __FUNCTION__);
64
65 #if BTA_DYNAMIC_MEMORY == TRUE
66 /* Malloc buffer for SDP configuration structure */
67 p_bta_sdp_cfg->p_sdp_db = (tSDP_DISCOVERY_DB *)osi_malloc(p_bta_sdp_cfg->sdp_db_size);
68 if (p_bta_sdp_cfg->p_sdp_db == NULL) {
69 return BTA_SDP_FAILURE;
70 }
71 #endif
72
73 if (p_cback && FALSE == bta_sys_is_register(BTA_ID_SDP)) {
74 memset(&bta_sdp_cb, 0, sizeof(tBTA_SDP_CB));
75
76 /* register with BTA system manager */
77 bta_sys_register(BTA_ID_SDP, &bta_sdp_reg);
78
79 if (p_cback &&
80 (p_buf = (tBTA_SDP_API_ENABLE *) osi_malloc(sizeof(tBTA_SDP_API_ENABLE))) != NULL) {
81 p_buf->hdr.event = BTA_SDP_API_ENABLE_EVT;
82 p_buf->p_cback = p_cback;
83 bta_sys_sendmsg(p_buf);
84 status = BTA_SDP_SUCCESS;
85 }
86 }
87 return (status);
88 }
89
90
91 /*******************************************************************************
92 **
93 ** Function BTA_SdpDisable
94 **
95 ** Description Disable the SDP search I/F service.
96 ** Free buffer for SDP configuration structure.
97 **
98 ** Returns BTA_SDP_SUCCESS if successful.
99 ** BTA_SDP_FAIL if internal failure.
100 **
101 *******************************************************************************/
BTA_SdpDisable(void)102 tBTA_SDP_STATUS BTA_SdpDisable(void)
103 {
104 tBTA_SDP_STATUS status = BTA_SDP_SUCCESS;
105 #if BTA_DYNAMIC_MEMORY == TRUE
106 /* Free buffer for SDP configuration structure */
107 osi_free(p_bta_sdp_cfg->p_sdp_db);
108 p_bta_sdp_cfg->p_sdp_db = NULL;
109 #endif
110 return (status);
111 }
112
113 /*******************************************************************************
114 **
115 ** Function BTA_SdpSearch
116 **
117 ** Description This function performs service discovery for a specific service
118 ** on given peer device. When the operation is completed
119 ** the tBTA_SDP_DM_CBACK callback function will be called with
120 ** a BTA_SDP_SEARCH_COMPLETE_EVT.
121 **
122 ** Returns BTA_SDP_SUCCESS, if the request is being processed.
123 ** BTA_SDP_FAILURE, otherwise.
124 **
125 *******************************************************************************/
BTA_SdpSearch(BD_ADDR bd_addr,tSDP_UUID * uuid)126 tBTA_SDP_STATUS BTA_SdpSearch(BD_ADDR bd_addr, tSDP_UUID *uuid)
127 {
128 tBTA_SDP_STATUS ret = BTA_SDP_FAILURE;
129 tBTA_SDP_API_SEARCH *p_msg;
130
131 APPL_TRACE_API("%s\n", __FUNCTION__);
132 if ((p_msg = (tBTA_SDP_API_SEARCH *)osi_malloc(sizeof(tBTA_SDP_API_SEARCH))) != NULL) {
133 p_msg->hdr.event = BTA_SDP_API_SEARCH_EVT;
134 bdcpy(p_msg->bd_addr, bd_addr);
135 //p_msg->uuid = uuid;
136 memcpy(&(p_msg->uuid), uuid, sizeof(tSDP_UUID));
137 bta_sys_sendmsg(p_msg);
138 ret = BTA_SDP_SUCCESS;
139 }
140
141 return (ret);
142 }
143
144 /*******************************************************************************
145 **
146 ** Function BTA_SdpCreateRecordByUser
147 **
148 ** Description This function is used to request a callback to create a SDP
149 ** record. The registered callback will be called with event
150 ** BTA_SDP_CREATE_RECORD_USER_EVT.
151 **
152 ** Returns BTA_SDP_SUCCESS, if the request is being processed.
153 ** BTA_SDP_FAILURE, otherwise.
154 **
155 *******************************************************************************/
BTA_SdpCreateRecordByUser(void * user_data)156 tBTA_SDP_STATUS BTA_SdpCreateRecordByUser(void *user_data)
157 {
158 tBTA_SDP_STATUS ret = BTA_SDP_FAILURE;
159 tBTA_SDP_API_RECORD_USER *p_msg;
160
161 APPL_TRACE_API("%s\n", __FUNCTION__);
162 if ((p_msg = (tBTA_SDP_API_RECORD_USER *)osi_malloc(sizeof(tBTA_SDP_API_RECORD_USER))) != NULL) {
163 p_msg->hdr.event = BTA_SDP_API_CREATE_RECORD_USER_EVT;
164 p_msg->user_data = user_data;
165 bta_sys_sendmsg(p_msg);
166 ret = BTA_SDP_SUCCESS;
167 }
168
169 return (ret);
170 }
171
172 /*******************************************************************************
173 **
174 ** Function BTA_SdpRemoveRecordByUser
175 **
176 ** Description This function is used to request a callback to remove a SDP
177 ** record. The registered callback will be called with event
178 ** BTA_SDP_REMOVE_RECORD_USER_EVT.
179 **
180 ** Returns BTA_SDP_SUCCESS, if the request is being processed.
181 ** BTA_SDP_FAILURE, otherwise.
182 **
183 *******************************************************************************/
BTA_SdpRemoveRecordByUser(void * user_data)184 tBTA_SDP_STATUS BTA_SdpRemoveRecordByUser(void *user_data)
185 {
186 tBTA_SDP_STATUS ret = BTA_SDP_FAILURE;
187 tBTA_SDP_API_RECORD_USER *p_msg;
188
189 APPL_TRACE_API("%s\n", __FUNCTION__);
190 if ((p_msg = (tBTA_SDP_API_RECORD_USER *)osi_malloc(sizeof(tBTA_SDP_API_RECORD_USER))) != NULL) {
191 p_msg->hdr.event = BTA_SDP_API_REMOVE_RECORD_USER_EVT;
192 p_msg->user_data = user_data;
193 bta_sys_sendmsg(p_msg);
194 ret = BTA_SDP_SUCCESS;
195 }
196
197 return (ret);
198 }
199
200
201 #endif /* #if defined(BTA_SDP_INCLUDED) && (BTA_SDP_INCLUDED == TRUE) */
202