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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
|
/*
*
* BlueZ - Bluetooth protocol stack for Linux
*
* Copyright (C) 2006-2010 Nokia Corporation
* Copyright (C) 2004-2010 Marcel Holtmann <marcel@holtmann.org>
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#include <stdbool.h>
#include <dbus/dbus.h>
#include <glib.h>
#ifdef __TIZEN_PATCH__
#include <bluetooth/bluetooth.h>
#include <bluetooth/sdp.h>
#include <bluetooth/hci.h>
#include <bluetooth/hci_lib.h>
#endif
#define MAX_NAME_LENGTH 248
/* Invalid SSP passkey value used to indicate negative replies */
#define INVALID_PASSKEY 0xffffffff
#ifdef __TIZEN_PATCH__
#define BT_DISC_TYPE_DEFAULT 0
#define BT_DISC_TYPE_BREDR_ONLY 1
#define BT_DISC_TYPE_LE_ONLY 2
#define BT_DISC_TYPE_LE_BREDR 3
#endif
struct btd_adapter;
struct btd_device;
struct btd_adapter *btd_adapter_get_default(void);
bool btd_adapter_is_default(struct btd_adapter *adapter);
uint16_t btd_adapter_get_index(struct btd_adapter *adapter);
typedef void (*adapter_cb) (struct btd_adapter *adapter, gpointer user_data);
typedef void (*oob_read_local_cb_t) (struct btd_adapter *adapter,
const uint8_t *hash,
const uint8_t *randomizer,
void *user_data);
typedef void (*oob_bonding_cb_t) (struct btd_adapter *adapter,
const bdaddr_t *bdaddr, uint8_t status,
void *user_data);
struct oob_handler {
oob_read_local_cb_t read_local_cb;
oob_bonding_cb_t bonding_cb;
bdaddr_t remote_addr;
void *user_data;
};
int adapter_init(void);
void adapter_cleanup(void);
void adapter_shutdown(void);
typedef void (*btd_disconnect_cb) (struct btd_device *device, uint8_t reason);
void btd_add_disconnect_cb(btd_disconnect_cb func);
void btd_remove_disconnect_cb(btd_disconnect_cb func);
typedef void (*btd_conn_fail_cb) (struct btd_device *device, uint8_t status);
void btd_add_conn_fail_cb(btd_conn_fail_cb func);
void btd_remove_conn_fail_cb(btd_conn_fail_cb func);
struct btd_adapter *adapter_find(const bdaddr_t *sba);
struct btd_adapter *adapter_find_by_id(int id);
void adapter_foreach(adapter_cb func, gpointer user_data);
bool btd_adapter_get_pairable(struct btd_adapter *adapter);
bool btd_adapter_get_powered(struct btd_adapter *adapter);
bool btd_adapter_get_connectable(struct btd_adapter *adapter);
struct btd_gatt_database *btd_adapter_get_database(struct btd_adapter *adapter);
uint32_t btd_adapter_get_class(struct btd_adapter *adapter);
const char *btd_adapter_get_name(struct btd_adapter *adapter);
void btd_adapter_remove_device(struct btd_adapter *adapter,
struct btd_device *dev);
struct btd_device *btd_adapter_get_device(struct btd_adapter *adapter,
const bdaddr_t *addr,
uint8_t addr_type);
sdp_list_t *btd_adapter_get_services(struct btd_adapter *adapter);
struct btd_device *btd_adapter_find_device(struct btd_adapter *adapter,
const bdaddr_t *dst,
uint8_t dst_type);
const char *adapter_get_path(struct btd_adapter *adapter);
const bdaddr_t *btd_adapter_get_address(struct btd_adapter *adapter);
int adapter_set_name(struct btd_adapter *adapter, const char *name);
int adapter_service_add(struct btd_adapter *adapter, sdp_record_t *rec);
void adapter_service_remove(struct btd_adapter *adapter, uint32_t handle);
struct agent *adapter_get_agent(struct btd_adapter *adapter);
struct btd_adapter *btd_adapter_ref(struct btd_adapter *adapter);
void btd_adapter_unref(struct btd_adapter *adapter);
void btd_adapter_set_class(struct btd_adapter *adapter, uint8_t major,
uint8_t minor);
struct btd_adapter_driver {
const char *name;
int (*probe) (struct btd_adapter *adapter);
void (*remove) (struct btd_adapter *adapter);
};
typedef void (*service_auth_cb) (DBusError *derr, void *user_data);
void adapter_add_profile(struct btd_adapter *adapter, gpointer p);
void adapter_remove_profile(struct btd_adapter *adapter, gpointer p);
int btd_register_adapter_driver(struct btd_adapter_driver *driver);
void btd_unregister_adapter_driver(struct btd_adapter_driver *driver);
guint btd_request_authorization(const bdaddr_t *src, const bdaddr_t *dst,
const char *uuid, service_auth_cb cb, void *user_data);
int btd_cancel_authorization(guint id);
int btd_adapter_restore_powered(struct btd_adapter *adapter);
typedef ssize_t (*btd_adapter_pin_cb_t) (struct btd_adapter *adapter,
struct btd_device *dev, char *out, bool *display,
unsigned int attempt);
void btd_adapter_register_pin_cb(struct btd_adapter *adapter,
btd_adapter_pin_cb_t cb);
void btd_adapter_unregister_pin_cb(struct btd_adapter *adapter,
btd_adapter_pin_cb_t cb);
struct btd_adapter_pin_cb_iter *btd_adapter_pin_cb_iter_new(
struct btd_adapter *adapter);
void btd_adapter_pin_cb_iter_free(struct btd_adapter_pin_cb_iter *iter);
bool btd_adapter_pin_cb_iter_end(struct btd_adapter_pin_cb_iter *iter);
typedef void (*btd_msd_cb_t) (struct btd_adapter *adapter,
struct btd_device *dev,
uint16_t company,
const uint8_t *data,
uint8_t data_len);
void btd_adapter_register_msd_cb(struct btd_adapter *adapter,
btd_msd_cb_t cb);
void btd_adapter_unregister_msd_cb(struct btd_adapter *adapter,
btd_msd_cb_t cb);
/* If TRUE, enables fast connectabe, i.e. reduces page scan interval and changes
* type. If FALSE, disables fast connectable, i.e. sets page scan interval and
* type to default values. Valid for both connectable and discoverable modes. */
int btd_adapter_set_fast_connectable(struct btd_adapter *adapter,
gboolean enable);
int btd_adapter_read_clock(struct btd_adapter *adapter, const bdaddr_t *bdaddr,
int which, int timeout, uint32_t *clock,
uint16_t *accuracy);
int btd_adapter_block_address(struct btd_adapter *adapter,
const bdaddr_t *bdaddr, uint8_t bdaddr_type);
int btd_adapter_unblock_address(struct btd_adapter *adapter,
const bdaddr_t *bdaddr, uint8_t bdaddr_type);
int btd_adapter_disconnect_device(struct btd_adapter *adapter,
const bdaddr_t *bdaddr,
uint8_t bdaddr_type);
int btd_adapter_remove_bonding(struct btd_adapter *adapter,
const bdaddr_t *bdaddr, uint8_t bdaddr_type);
int btd_adapter_pincode_reply(struct btd_adapter *adapter,
const bdaddr_t *bdaddr,
const char *pin, size_t pin_len);
int btd_adapter_confirm_reply(struct btd_adapter *adapter,
const bdaddr_t *bdaddr, uint8_t bdaddr_type,
gboolean success);
int btd_adapter_passkey_reply(struct btd_adapter *adapter,
const bdaddr_t *bdaddr, uint8_t bdaddr_type,
uint32_t passkey);
int adapter_create_bonding(struct btd_adapter *adapter, const bdaddr_t *bdaddr,
uint8_t addr_type, uint8_t io_cap);
int adapter_bonding_attempt(struct btd_adapter *adapter, const bdaddr_t *bdaddr,
uint8_t addr_type, uint8_t io_cap);
int adapter_cancel_bonding(struct btd_adapter *adapter, const bdaddr_t *bdaddr,
uint8_t addr_type);
int adapter_set_io_capability(struct btd_adapter *adapter, uint8_t io_cap);
int btd_adapter_read_local_oob_data(struct btd_adapter *adapter);
int btd_adapter_add_remote_oob_data(struct btd_adapter *adapter,
const bdaddr_t *bdaddr,
uint8_t *hash, uint8_t *randomizer);
int btd_adapter_remove_remote_oob_data(struct btd_adapter *adapter,
const bdaddr_t *bdaddr);
int btd_adapter_gatt_server_start(struct btd_adapter *adapter);
void btd_adapter_gatt_server_stop(struct btd_adapter *adapter);
bool btd_adapter_ssp_enabled(struct btd_adapter *adapter);
int adapter_connect_list_add(struct btd_adapter *adapter,
struct btd_device *device);
void adapter_connect_list_remove(struct btd_adapter *adapter,
struct btd_device *device);
void adapter_auto_connect_add(struct btd_adapter *adapter,
struct btd_device *device);
void adapter_auto_connect_remove(struct btd_adapter *adapter,
struct btd_device *device);
void adapter_whitelist_add(struct btd_adapter *adapter,
struct btd_device *dev);
void adapter_whitelist_remove(struct btd_adapter *adapter,
struct btd_device *dev);
void btd_adapter_set_oob_handler(struct btd_adapter *adapter,
struct oob_handler *handler);
gboolean btd_adapter_check_oob_handler(struct btd_adapter *adapter);
void btd_adapter_for_each_device(struct btd_adapter *adapter,
void (*cb)(struct btd_device *device, void *data),
void *data);
bool btd_le_connect_before_pairing(void);
#ifdef __TIZEN_PATCH__
#if 0 // Not used
int btd_adapter_read_rssi(struct btd_adapter *adapter, bdaddr_t *bdaddr,
struct btd_device *device);
int btd_adapter_l2cap_conn_param_update(struct btd_adapter *adapter,
bdaddr_t *bdaddr, uint16_t interval_min,
uint16_t interval_max, uint16_t latency,
uint16_t supervision_time_out);
int btd_adapter_write_auth_payload_timeout(struct btd_adapter *adapter,
bdaddr_t *bdaddr, uint32_t payload_timeout,
struct btd_device *device);
int btd_adapter_read_auth_payload_timeout(struct btd_adapter *adapter,
bdaddr_t *bdaddr, struct btd_device *device);
#endif
int btd_adapter_le_conn_update(struct btd_adapter *adapter, bdaddr_t *bdaddr,
uint16_t interval_min, uint16_t interval_max,
uint16_t latency, uint16_t supervision_time_out);
gboolean adapter_clear_le_white_list(struct btd_adapter *adapter);
gboolean adapter_add_le_white_list(struct btd_adapter *adapter, struct btd_device *device);
gboolean btd_adapter_is_le_auto_connect(struct btd_adapter *adapter);
void btd_adapter_set_le_auto_connect(struct btd_adapter *adapter, gboolean auto_connect);
gboolean btd_adapter_disable_le_auto_connect(struct btd_adapter *adapter);
void adapter_check_version(struct btd_adapter *adapter, uint8_t hci_ver);
GSList *btd_adapter_get_connections(struct btd_adapter *adapter);
int btd_adapter_connect_ipsp(struct btd_adapter *adapter,
const bdaddr_t *bdaddr,
uint8_t bdaddr_type);
int btd_adapter_disconnect_ipsp(struct btd_adapter *adapter,
const bdaddr_t *bdaddr,
uint8_t bdaddr_type);
int btd_adapter_set_dev_rpa_res_support(struct btd_adapter *adapter,
struct btd_device *device);
typedef void (*read_max_data_length_cb_t) (struct btd_adapter *adapter,
const uint16_t max_txOctects,
const uint16_t max_txTime,
const uint16_t max_rxOctects,
const uint16_t max_rxTime,
void *user_data);
struct le_data_length_read_handler {
read_max_data_length_cb_t read_callback;
void *user_data;
};
typedef void (*read_host_suggested_default_data_length_cb_t) (struct btd_adapter *adapter,
const uint16_t def_txOctects,
const uint16_t def_txTime,
void *user_data);
struct le_data_length_read_default_data_length_handler {
read_host_suggested_default_data_length_cb_t read_callback;
void *user_data;
};
#endif
|