1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
|
/******************************************************************************
*
* Copyright 2014 Samsung System LSI
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************/
/*******************************************************************************
*
* Filename: btif_sdp.c
* Description: SDP Bluetooth Interface.
* Implements the generic message handling and search
* functionality.
* References btif_sdp_server.c for SDP record creation.
*
******************************************************************************/
#define LOG_TAG "bt_btif_sdp"
#include <hardware/bluetooth.h>
#include <hardware/bt_sdp.h>
#include <stdlib.h>
#include <string.h>
#include "bta_api.h"
#include "bta_sdp_api.h"
#include "btif_common.h"
#include "btif_profile_queue.h"
#include "btif_util.h"
#include "types/bluetooth/uuid.h"
#include "types/raw_address.h"
using bluetooth::Uuid;
/*****************************************************************************
* Functions implemented in sdp_server.c
*****************************************************************************/
bt_status_t sdp_server_init();
void sdp_server_cleanup();
bt_status_t create_sdp_record(bluetooth_sdp_record* records,
int* record_handles);
bt_status_t remove_sdp_record(int record_handle);
void on_create_record_event(int handle);
void on_remove_record_event(int handle);
// Utility functions:
int get_sdp_records_size(bluetooth_sdp_record* in_record, int count);
void copy_sdp_records(bluetooth_sdp_record* in_records,
bluetooth_sdp_record* out_records, int count);
/*****************************************************************************
* Static variables
*****************************************************************************/
static btsdp_callbacks_t* bt_sdp_callbacks = NULL;
static void btif_sdp_search_comp_evt(uint16_t event, char* p_param) {
tBTA_SDP_SEARCH_COMP* evt_data = (tBTA_SDP_SEARCH_COMP*)p_param;
BTIF_TRACE_DEBUG("%s: event = %d", __func__, event);
if (event != BTA_SDP_SEARCH_COMP_EVT) return;
HAL_CBACK(bt_sdp_callbacks, sdp_search_cb, (bt_status_t)evt_data->status,
evt_data->remote_addr, evt_data->uuid, evt_data->record_count,
evt_data->records);
}
static void sdp_search_comp_copy_cb(uint16_t event, char* p_dest, char* p_src) {
tBTA_SDP_SEARCH_COMP* p_dest_data = (tBTA_SDP_SEARCH_COMP*)p_dest;
tBTA_SDP_SEARCH_COMP* p_src_data = (tBTA_SDP_SEARCH_COMP*)p_src;
if (!p_src) return;
if (event != BTA_SDP_SEARCH_COMP_EVT) return;
maybe_non_aligned_memcpy(p_dest_data, p_src_data, sizeof(*p_src_data));
copy_sdp_records(p_src_data->records, p_dest_data->records,
p_src_data->record_count);
}
static void sdp_dm_cback(tBTA_SDP_EVT event, tBTA_SDP* p_data,
void* user_data) {
switch (event) {
case BTA_SDP_SEARCH_COMP_EVT: {
int size = sizeof(tBTA_SDP);
size += get_sdp_records_size(p_data->sdp_search_comp.records,
p_data->sdp_search_comp.record_count);
/* need to deep copy the record content */
btif_transfer_context(btif_sdp_search_comp_evt, event, (char*)p_data,
size, sdp_search_comp_copy_cb);
break;
}
case BTA_SDP_CREATE_RECORD_USER_EVT: {
on_create_record_event(PTR_TO_INT(user_data));
break;
}
case BTA_SDP_REMOVE_RECORD_USER_EVT: {
on_remove_record_event(PTR_TO_INT(user_data));
break;
}
default:
break;
}
}
static bt_status_t init(btsdp_callbacks_t* callbacks) {
BTIF_TRACE_DEBUG("Sdp Search %s", __func__);
bt_sdp_callbacks = callbacks;
sdp_server_init();
btif_enable_service(BTA_SDP_SERVICE_ID);
return BT_STATUS_SUCCESS;
}
static bt_status_t deinit() {
BTIF_TRACE_DEBUG("Sdp Search %s", __func__);
bt_sdp_callbacks = NULL;
sdp_server_cleanup();
btif_disable_service(BTA_SDP_SERVICE_ID);
return BT_STATUS_SUCCESS;
}
static bt_status_t search(RawAddress* bd_addr, const Uuid& uuid) {
BTA_SdpSearch(*bd_addr, uuid);
return BT_STATUS_SUCCESS;
}
static const btsdp_interface_t sdp_if = {
sizeof(btsdp_interface_t), init, deinit, search, create_sdp_record,
remove_sdp_record};
const btsdp_interface_t* btif_sdp_get_interface(void) {
BTIF_TRACE_DEBUG("%s", __func__);
return &sdp_if;
}
/*******************************************************************************
*
* Function btif_sdp_execute_service
*
* Description Initializes/Shuts down the service
*
* Returns BT_STATUS_SUCCESS on success, BT_STATUS_FAIL otherwise
*
******************************************************************************/
bt_status_t btif_sdp_execute_service(bool b_enable) {
BTIF_TRACE_DEBUG("%s enable:%d", __func__, b_enable);
if (b_enable) {
BTA_SdpEnable(sdp_dm_cback);
} else {
/* This is called on BT disable so no need to extra cleanup */
}
return BT_STATUS_SUCCESS;
}
|