1 /******************************************************************************
3 * Copyright (C) 2014 Samsung System LSI
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:
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 ******************************************************************************/
19 /************************************************************************************
21 * Filename: btif_sdp.c
22 * Description: SDP Bluetooth Interface.
23 * Implements the generic message handling and search functionality.
24 * References btif_sdp_server.c for SDP record creation.
26 ***********************************************************************************/
32 #define LOG_TAG "BTIF_SDP"
33 #include "btif_common.h"
34 #include "btif_util.h"
37 #include "bt_sdp_api.h"
39 /*****************************************************************************
40 ** Functions implemented in sdp_server.c
41 ******************************************************************************/
42 bt_status_t sdp_server_init();
43 void sdp_server_cleanup();
44 void on_create_record_event(int handle);
45 void on_remove_record_event(int handle);
48 int get_sdp_records_size(bluetooth_sdp_record* in_record, int count);
49 void copy_sdp_records(bluetooth_sdp_record* in_records,
50 bluetooth_sdp_record* out_records, int count);
53 /*****************************************************************************
55 ******************************************************************************/
57 static btsdp_callbacks_t *bt_sdp_callbacks = NULL;
59 static void btif_sdp_search_comp_evt(UINT16 event, char *p_param)
61 bt_sdp_search_comp_t *evt_data = (bt_sdp_search_comp_t *) p_param;
63 BTIF_TRACE_DEBUG("%s: event = %d\n", __FUNCTION__, event);
65 if (event != BT_SDP_SEARCH_COMP_EVT)
68 bdcpy(addr.address, evt_data->remote_addr);
70 HAL_CBACK(bt_sdp_callbacks, sdp_search_cb, evt_data->status,
71 &addr, (uint8_t*)(evt_data->uuid.uu.uuid128),
72 evt_data->record_count, evt_data->records);
75 static void sdp_search_comp_copy_cb(UINT16 event, char *p_dest, char *p_src)
77 bt_sdp_search_comp_t *p_dest_data = (bt_sdp_search_comp_t *) p_dest;
78 bt_sdp_search_comp_t *p_src_data = (bt_sdp_search_comp_t *) p_src;
82 if (event != BT_SDP_SEARCH_COMP_EVT)
85 memcpy(p_dest_data, p_src_data, sizeof(bt_sdp_search_comp_t));
87 copy_sdp_records(p_src_data->records, p_dest_data->records, p_src_data->record_count);
91 static void sdp_dm_cback(bt_sdp_evt_t event, bt_sdp_t *p_data, void * user_data)
95 case BT_SDP_SEARCH_COMP_EVT:
97 int size = sizeof(bt_sdp_t);
98 size += get_sdp_records_size(p_data->sdp_search_comp.records,
99 p_data->sdp_search_comp.record_count);
101 BTIF_TRACE_DEBUG("%s: stat %d, record_cnt = %d\n", __FUNCTION__, p_data->sdp_search_comp.status, p_data->sdp_search_comp.record_count);
102 /* need to deep copy the record content */
103 btif_transfer_context(btif_sdp_search_comp_evt, event,
104 (char*)p_data, size, sdp_search_comp_copy_cb);
107 case BT_SDP_CREATE_RECORD_USER_EVT:
109 on_create_record_event((int)user_data);
112 case BT_SDP_REMOVE_RECORD_USER_EVT:
114 on_remove_record_event((int)user_data);
122 bt_status_t BTIF_SdpInit(btsdp_callbacks_t *callbacks)
124 BTIF_TRACE_DEBUG("Sdp Search %s\n", __FUNCTION__);
126 bt_sdp_callbacks = callbacks;
129 btif_enable_service(BTA_SDP_SERVICE_ID);
131 return BT_STATUS_SUCCESS;
134 bt_status_t BTIF_SdpDeinit(void)
136 BTIF_TRACE_DEBUG("Sdp Search %s\n", __FUNCTION__);
138 bt_sdp_callbacks = NULL;
139 sdp_server_cleanup();
140 btif_disable_service(BTA_SDP_SERVICE_ID);
142 return BT_STATUS_SUCCESS;
145 bt_status_t BTIF_SdpSearch(bt_bdaddr_t *bd_addr, const uint8_t* uuid)
147 esp_bt_uuid_t sdp_uuid;
149 memcpy(sdp_uuid.uu.uuid128, uuid, sizeof(sdp_uuid.uu.uuid128));
151 esp_bt_sdp_search(bd_addr->address, &sdp_uuid);
152 return BT_STATUS_SUCCESS;
155 /*******************************************************************************
157 ** Function btif_sdp_execute_service
159 ** Description Initializes/Shuts down the service
161 ** Returns BT_STATUS_SUCCESS on success, BT_STATUS_FAIL otherwise
163 *******************************************************************************/
164 bt_status_t btif_sdp_execute_service(BOOLEAN b_enable)
166 BTIF_TRACE_DEBUG("%s enable:%d\n", __FUNCTION__, b_enable);
169 esp_bt_sdp_enable(sdp_dm_cback);
171 /* This is called on BT disable so no need to extra cleanup */
173 return BT_STATUS_SUCCESS;