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 "bta_api.h"
26 #include "bta_sys.h"
27 #include "bta_sdp_api.h"
28 #include "bta_sdp_int.h"
29 #include "bt_common.h"
30 #include <string.h>
31 #include "port_api.h"
32 #include "sdp_api.h"
33 
34 /*****************************************************************************
35 **  Constants
36 *****************************************************************************/
37 
38 static const tBTA_SYS_REG bta_sdp_reg =
39 {
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 
62     APPL_TRACE_API(__FUNCTION__);
63     if(p_cback && FALSE == bta_sys_is_register(BTA_ID_SDP))
64     {
65         memset(&bta_sdp_cb, 0, sizeof(tBTA_SDP_CB));
66 
67         /* register with BTA system manager */
68         bta_sys_register(BTA_ID_SDP, &bta_sdp_reg);
69 
70         if (p_cback) {
71             tBTA_SDP_API_ENABLE *p_buf =
72                 (tBTA_SDP_API_ENABLE *)osi_malloc(sizeof(tBTA_SDP_API_ENABLE));
73             p_buf->hdr.event = BTA_SDP_API_ENABLE_EVT;
74             p_buf->p_cback = p_cback;
75             bta_sys_sendmsg(p_buf);
76             status = BTA_SDP_SUCCESS;
77         }
78     }
79     return status;
80 }
81 
82 /*******************************************************************************
83 **
84 ** Function         BTA_SdpSearch
85 **
86 ** Description      This function performs service discovery for a specific service
87 **                  on given peer device. When the operation is completed
88 **                  the tBTA_SDP_DM_CBACK callback function will be  called with
89 **                  a BTA_SDP_SEARCH_COMPLETE_EVT.
90 **
91 ** Returns          BTA_SDP_SUCCESS, if the request is being processed.
92 **                  BTA_SDP_FAILURE, otherwise.
93 **
94 *******************************************************************************/
BTA_SdpSearch(BD_ADDR bd_addr,tSDP_UUID * uuid)95 tBTA_SDP_STATUS BTA_SdpSearch(BD_ADDR bd_addr, tSDP_UUID *uuid)
96 {
97     tBTA_SDP_API_SEARCH *p_msg =
98         (tBTA_SDP_API_SEARCH *)osi_malloc(sizeof(tBTA_SDP_API_SEARCH));
99 
100     APPL_TRACE_API("%s", __func__);
101 
102     p_msg->hdr.event = BTA_SDP_API_SEARCH_EVT;
103     bdcpy(p_msg->bd_addr, bd_addr);
104     // p_msg->uuid = uuid;
105     memcpy(&(p_msg->uuid), uuid, sizeof(tSDP_UUID));
106 
107     bta_sys_sendmsg(p_msg);
108 
109     return BTA_SDP_SUCCESS;
110 }
111 
112 /*******************************************************************************
113 **
114 ** Function         BTA_SdpCreateRecordByUser
115 **
116 ** Description      This function is used to request a callback to create a SDP
117 **                  record. The registered callback will be called with event
118 **                  BTA_SDP_CREATE_RECORD_USER_EVT.
119 **
120 ** Returns          BTA_SDP_SUCCESS, if the request is being processed.
121 **                  BTA_SDP_FAILURE, otherwise.
122 **
123 *******************************************************************************/
BTA_SdpCreateRecordByUser(void * user_data)124 tBTA_SDP_STATUS BTA_SdpCreateRecordByUser(void* user_data)
125 {
126     tBTA_SDP_API_RECORD_USER *p_msg =
127         (tBTA_SDP_API_RECORD_USER *)osi_malloc(sizeof(tBTA_SDP_API_RECORD_USER));
128 
129     APPL_TRACE_API("%s", __func__);
130 
131     p_msg->hdr.event = BTA_SDP_API_CREATE_RECORD_USER_EVT;
132     p_msg->user_data = user_data;
133 
134     bta_sys_sendmsg(p_msg);
135 
136     return BTA_SDP_SUCCESS;
137 }
138 
139 /*******************************************************************************
140 **
141 ** Function         BTA_SdpRemoveRecordByUser
142 **
143 ** Description      This function is used to request a callback to remove a SDP
144 **                  record. The registered callback will be called with event
145 **                  BTA_SDP_REMOVE_RECORD_USER_EVT.
146 **
147 ** Returns          BTA_SDP_SUCCESS, if the request is being processed.
148 **                  BTA_SDP_FAILURE, otherwise.
149 **
150 *******************************************************************************/
BTA_SdpRemoveRecordByUser(void * user_data)151 tBTA_SDP_STATUS BTA_SdpRemoveRecordByUser(void* user_data)
152 {
153     tBTA_SDP_API_RECORD_USER *p_msg =
154         (tBTA_SDP_API_RECORD_USER *)osi_malloc(sizeof(tBTA_SDP_API_RECORD_USER));
155 
156     APPL_TRACE_API("%s", __func__);
157 
158     p_msg->hdr.event = BTA_SDP_API_REMOVE_RECORD_USER_EVT;
159     p_msg->user_data = user_data;
160 
161     bta_sys_sendmsg(p_msg);
162 
163     return BTA_SDP_SUCCESS;
164 }
165