Upgrade bluez5_37 :Merge the code from private
[platform/upstream/bluez.git] / src / shared / att.h
1 /*
2  *
3  *  BlueZ - Bluetooth protocol stack for Linux
4  *
5  *  Copyright (C) 2014  Google Inc.
6  *
7  *
8  *  This library is free software; you can redistribute it and/or
9  *  modify it under the terms of the GNU Lesser General Public
10  *  License as published by the Free Software Foundation; either
11  *  version 2.1 of the License, or (at your option) any later version.
12  *
13  *  This library is distributed in the hope that it will be useful,
14  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  *  Lesser General Public License for more details.
17  *
18  *  You should have received a copy of the GNU Lesser General Public
19  *  License along with this library; if not, write to the Free Software
20  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
21  *
22  */
23
24 #include <stdbool.h>
25 #include <stdint.h>
26
27 #include "src/shared/att-types.h"
28
29 struct bt_att;
30
31 struct bt_att *bt_att_new(int fd, bool ext_signed);
32
33 struct bt_att *bt_att_ref(struct bt_att *att);
34 void bt_att_unref(struct bt_att *att);
35
36 bool bt_att_set_close_on_unref(struct bt_att *att, bool do_close);
37
38 int bt_att_get_fd(struct bt_att *att);
39
40 typedef void (*bt_att_response_func_t)(uint8_t opcode, const void *pdu,
41                                         uint16_t length, void *user_data);
42 typedef void (*bt_att_notify_func_t)(uint8_t opcode, const void *pdu,
43                                         uint16_t length, void *user_data);
44 typedef void (*bt_att_destroy_func_t)(void *user_data);
45 typedef void (*bt_att_debug_func_t)(const char *str, void *user_data);
46 typedef void (*bt_att_timeout_func_t)(unsigned int id, uint8_t opcode,
47                                                         void *user_data);
48 typedef void (*bt_att_disconnect_func_t)(int err, void *user_data);
49 typedef bool (*bt_att_counter_func_t)(uint32_t *sign_cnt, void *user_data);
50
51 bool bt_att_set_debug(struct bt_att *att, bt_att_debug_func_t callback,
52                                 void *user_data, bt_att_destroy_func_t destroy);
53
54 uint16_t bt_att_get_mtu(struct bt_att *att);
55 bool bt_att_set_mtu(struct bt_att *att, uint16_t mtu);
56
57 bool bt_att_set_timeout_cb(struct bt_att *att, bt_att_timeout_func_t callback,
58                                                 void *user_data,
59                                                 bt_att_destroy_func_t destroy);
60
61 unsigned int bt_att_send(struct bt_att *att, uint8_t opcode,
62                                         const void *pdu, uint16_t length,
63                                         bt_att_response_func_t callback,
64                                         void *user_data,
65                                         bt_att_destroy_func_t destroy);
66 bool bt_att_cancel(struct bt_att *att, unsigned int id);
67 bool bt_att_cancel_all(struct bt_att *att);
68
69 unsigned int bt_att_send_error_rsp(struct bt_att *att, uint8_t opcode,
70                                                 uint16_t handle, int error);
71
72 unsigned int bt_att_register(struct bt_att *att, uint8_t opcode,
73                                                 bt_att_notify_func_t callback,
74                                                 void *user_data,
75                                                 bt_att_destroy_func_t destroy);
76 bool bt_att_unregister(struct bt_att *att, unsigned int id);
77
78 unsigned int bt_att_register_disconnect(struct bt_att *att,
79                                         bt_att_disconnect_func_t callback,
80                                         void *user_data,
81                                         bt_att_destroy_func_t destroy);
82 bool bt_att_unregister_disconnect(struct bt_att *att, unsigned int id);
83
84 bool bt_att_unregister_all(struct bt_att *att);
85
86 int bt_att_get_security(struct bt_att *att);
87 bool bt_att_set_security(struct bt_att *att, int level);
88
89 bool bt_att_set_local_key(struct bt_att *att, uint8_t sign_key[16],
90                         bt_att_counter_func_t func, void *user_data);
91 bool bt_att_set_remote_key(struct bt_att *att, uint8_t sign_key[16],
92                         bt_att_counter_func_t func, void *user_data);
93 bool bt_att_has_crypto(struct bt_att *att);