Upgrade bluez5_37 :Merge the code from private
[platform/upstream/bluez.git] / src / shared / gatt-client.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 #include <stddef.h>
27
28 #define BT_GATT_UUID_SIZE 16
29
30 struct bt_gatt_client;
31
32 struct bt_gatt_client *bt_gatt_client_new(struct gatt_db *db,
33                                                         struct bt_att *att,
34                                                         uint16_t mtu);
35
36 struct bt_gatt_client *bt_gatt_client_ref(struct bt_gatt_client *client);
37 void bt_gatt_client_unref(struct bt_gatt_client *client);
38
39 typedef void (*bt_gatt_client_destroy_func_t)(void *user_data);
40 typedef void (*bt_gatt_client_callback_t)(bool success, uint8_t att_ecode,
41                                                         void *user_data);
42 typedef void (*bt_gatt_client_debug_func_t)(const char *str, void *user_data);
43 typedef void (*bt_gatt_client_read_callback_t)(bool success, uint8_t att_ecode,
44                                         const uint8_t *value, uint16_t length,
45                                         void *user_data);
46 typedef void (*bt_gatt_client_write_long_callback_t)(bool success,
47                                         bool reliable_error, uint8_t att_ecode,
48                                         void *user_data);
49 typedef void (*bt_gatt_client_notify_callback_t)(uint16_t value_handle,
50                                         const uint8_t *value, uint16_t length,
51                                         void *user_data);
52 typedef void (*bt_gatt_client_register_callback_t)(uint16_t att_ecode,
53                                                         void *user_data);
54 typedef void (*bt_gatt_client_service_changed_callback_t)(uint16_t start_handle,
55                                                         uint16_t end_handle,
56                                                         void *user_data);
57
58 bool bt_gatt_client_is_ready(struct bt_gatt_client *client);
59 bool bt_gatt_client_set_ready_handler(struct bt_gatt_client *client,
60                                         bt_gatt_client_callback_t callback,
61                                         void *user_data,
62                                         bt_gatt_client_destroy_func_t destroy);
63 bool bt_gatt_client_set_service_changed(struct bt_gatt_client *client,
64                         bt_gatt_client_service_changed_callback_t callback,
65                         void *user_data,
66                         bt_gatt_client_destroy_func_t destroy);
67 bool bt_gatt_client_set_debug(struct bt_gatt_client *client,
68                                         bt_gatt_client_debug_func_t callback,
69                                         void *user_data,
70                                         bt_gatt_client_destroy_func_t destroy);
71
72 uint16_t bt_gatt_client_get_mtu(struct bt_gatt_client *client);
73 struct gatt_db *bt_gatt_client_get_db(struct bt_gatt_client *client);
74
75 bool bt_gatt_client_cancel(struct bt_gatt_client *client, unsigned int id);
76 bool bt_gatt_client_cancel_all(struct bt_gatt_client *client);
77
78 unsigned int bt_gatt_client_read_value(struct bt_gatt_client *client,
79                                         uint16_t value_handle,
80                                         bt_gatt_client_read_callback_t callback,
81                                         void *user_data,
82                                         bt_gatt_client_destroy_func_t destroy);
83 unsigned int bt_gatt_client_read_long_value(struct bt_gatt_client *client,
84                                         uint16_t value_handle, uint16_t offset,
85                                         bt_gatt_client_read_callback_t callback,
86                                         void *user_data,
87                                         bt_gatt_client_destroy_func_t destroy);
88 unsigned int bt_gatt_client_read_multiple(struct bt_gatt_client *client,
89                                         uint16_t *handles, uint8_t num_handles,
90                                         bt_gatt_client_read_callback_t callback,
91                                         void *user_data,
92                                         bt_gatt_client_destroy_func_t destroy);
93
94 #ifdef __TIZEN_PATCH__
95 unsigned int bt_gatt_client_write_without_response_async(
96                                         struct bt_gatt_client *client,
97                                         uint16_t value_handle,
98                                         bool signed_write,
99                                         const uint8_t *value, uint16_t length,
100                                         bt_gatt_client_callback_t callback,
101                                         void *user_data,
102                                         bt_gatt_client_destroy_func_t destroy);
103 #endif
104
105 unsigned int bt_gatt_client_write_without_response(
106                                         struct bt_gatt_client *client,
107                                         uint16_t value_handle,
108                                         bool signed_write,
109                                         const uint8_t *value, uint16_t length);
110 unsigned int bt_gatt_client_write_value(struct bt_gatt_client *client,
111                                         uint16_t value_handle,
112                                         const uint8_t *value, uint16_t length,
113                                         bt_gatt_client_callback_t callback,
114                                         void *user_data,
115                                         bt_gatt_client_destroy_func_t destroy);
116 unsigned int bt_gatt_client_write_long_value(struct bt_gatt_client *client,
117                                 bool reliable,
118                                 uint16_t value_handle, uint16_t offset,
119                                 const uint8_t *value, uint16_t length,
120                                 bt_gatt_client_write_long_callback_t callback,
121                                 void *user_data,
122                                 bt_gatt_client_destroy_func_t destroy);
123 unsigned int bt_gatt_client_prepare_write(struct bt_gatt_client *client,
124                                 unsigned int id,
125                                 uint16_t value_handle, uint16_t offset,
126                                 const uint8_t *value, uint16_t length,
127                                 bt_gatt_client_write_long_callback_t callback,
128                                 void *user_data,
129                                 bt_gatt_client_destroy_func_t destroy);
130 unsigned int bt_gatt_client_write_execute(struct bt_gatt_client *client,
131                                         unsigned int id,
132                                         bt_gatt_client_callback_t callback,
133                                         void *user_data,
134                                         bt_gatt_client_destroy_func_t destroy);
135
136 unsigned int bt_gatt_client_register_notify(struct bt_gatt_client *client,
137                                 uint16_t chrc_value_handle,
138                                 bt_gatt_client_register_callback_t callback,
139                                 bt_gatt_client_notify_callback_t notify,
140                                 void *user_data,
141                                 bt_gatt_client_destroy_func_t destroy);
142 bool bt_gatt_client_unregister_notify(struct bt_gatt_client *client,
143                                                         unsigned int id);
144
145 bool bt_gatt_client_set_security(struct bt_gatt_client *client, int level);
146 int bt_gatt_client_get_security(struct bt_gatt_client *client);
147
148 #if defined __TIZEN_PATCH__ && defined BLUEZ5_27_GATT_CLIENT
149 bool bt_gatt_discover_services(struct bt_gatt_client *client);
150 #endif
151
152 #ifdef __TIZEN_PATCH__
153 char *bt_gatt_client_get_gap_device_name(struct bt_gatt_client *client);
154 bool bt_gatt_request_att_mtu(struct bt_gatt_client *client, uint16_t mtu,
155                                         void *callback, void *user_data);
156 bool bt_gatt_client_svc_changed_received(struct bt_gatt_client *client);
157 #endif