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 "gki.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     tBTA_SDP_API_ENABLE  *p_buf;
62 
63     APPL_TRACE_API(__FUNCTION__);
64     if(p_cback && FALSE == bta_sys_is_register(BTA_ID_SDP))
65     {
66         memset(&bta_sdp_cb, 0, sizeof(tBTA_SDP_CB));
67 
68         /* register with BTA system manager */
69         bta_sys_register(BTA_ID_SDP, &bta_sdp_reg);
70 
71         if (p_cback &&
72                 (p_buf = (tBTA_SDP_API_ENABLE *) GKI_getbuf(sizeof(tBTA_SDP_API_ENABLE))) != NULL)
73         {
74             p_buf->hdr.event = BTA_SDP_API_ENABLE_EVT;
75             p_buf->p_cback = p_cback;
76             bta_sys_sendmsg(p_buf);
77             status = BTA_SDP_SUCCESS;
78         }
79     }
80     return(status);
81 }
82 
83 /*******************************************************************************
84 **
85 ** Function         BTA_SdpSearch
86 **
87 ** Description      This function performs service discovery for a specific service
88 **                  on given peer device. When the operation is completed
89 **                  the tBTA_SDP_DM_CBACK callback function will be  called with
90 **                  a BTA_SDP_SEARCH_COMPLETE_EVT.
91 **
92 ** Returns          BTA_SDP_SUCCESS, if the request is being processed.
93 **                  BTA_SDP_FAILURE, otherwise.
94 **
95 *******************************************************************************/
BTA_SdpSearch(BD_ADDR bd_addr,tSDP_UUID * uuid)96 tBTA_SDP_STATUS BTA_SdpSearch(BD_ADDR bd_addr, tSDP_UUID *uuid)
97 {
98     tBTA_SDP_STATUS ret = BTA_SDP_FAILURE;
99     tBTA_SDP_API_SEARCH *p_msg;
100 
101     APPL_TRACE_API(__FUNCTION__);
102     if ((p_msg = (tBTA_SDP_API_SEARCH *)GKI_getbuf(sizeof(tBTA_SDP_API_SEARCH))) != NULL)
103     {
104         p_msg->hdr.event = BTA_SDP_API_SEARCH_EVT;
105         bdcpy(p_msg->bd_addr, bd_addr);
106         //p_msg->uuid = uuid;
107         memcpy(&(p_msg->uuid), uuid, sizeof(tSDP_UUID));
108         bta_sys_sendmsg(p_msg);
109         ret = BTA_SDP_SUCCESS;
110     }
111 
112     return(ret);
113 }
114 
115 /*******************************************************************************
116 **
117 ** Function         BTA_SdpCreateRecordByUser
118 **
119 ** Description      This function is used to request a callback to create a SDP
120 **                  record. The registered callback will be called with event
121 **                  BTA_SDP_CREATE_RECORD_USER_EVT.
122 **
123 ** Returns          BTA_SDP_SUCCESS, if the request is being processed.
124 **                  BTA_SDP_FAILURE, otherwise.
125 **
126 *******************************************************************************/
BTA_SdpCreateRecordByUser(void * user_data)127 tBTA_SDP_STATUS BTA_SdpCreateRecordByUser(void* user_data)
128 {
129     tBTA_SDP_STATUS ret = BTA_SDP_FAILURE;
130     tBTA_SDP_API_RECORD_USER *p_msg;
131 
132     APPL_TRACE_API(__FUNCTION__);
133     if ((p_msg = (tBTA_SDP_API_RECORD_USER *)GKI_getbuf(sizeof(tBTA_SDP_API_RECORD_USER))) != NULL)
134     {
135         p_msg->hdr.event = BTA_SDP_API_CREATE_RECORD_USER_EVT;
136         p_msg->user_data = user_data;
137         bta_sys_sendmsg(p_msg);
138         ret = BTA_SDP_SUCCESS;
139     }
140 
141     return(ret);
142 }
143 
144 /*******************************************************************************
145 **
146 ** Function         BTA_SdpRemoveRecordByUser
147 **
148 ** Description      This function is used to request a callback to remove a SDP
149 **                  record. The registered callback will be called with event
150 **                  BTA_SDP_REMOVE_RECORD_USER_EVT.
151 **
152 ** Returns          BTA_SDP_SUCCESS, if the request is being processed.
153 **                  BTA_SDP_FAILURE, otherwise.
154 **
155 *******************************************************************************/
BTA_SdpRemoveRecordByUser(void * user_data)156 tBTA_SDP_STATUS BTA_SdpRemoveRecordByUser(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(__FUNCTION__);
162     if ((p_msg = (tBTA_SDP_API_RECORD_USER *)GKI_getbuf(sizeof(tBTA_SDP_API_RECORD_USER))) != NULL)
163     {
164         p_msg->hdr.event = BTA_SDP_API_REMOVE_RECORD_USER_EVT;
165         p_msg->user_data = user_data;
166         bta_sys_sendmsg(p_msg);
167         ret = BTA_SDP_SUCCESS;
168     }
169 
170     return(ret);
171 }
172 
173 
174