tizen 2.3.1 release
[framework/connectivity/bluez.git] / src / gatt.h
1 #ifdef __TIZEN_PATCH__
2 /*
3  *
4  *  BlueZ - Bluetooth protocol stack for Linux
5  *
6  *  Copyright (C) 2014  Instituto Nokia de Tecnologia - INdT
7  *
8  *
9  *  This program is free software; you can redistribute it and/or modify
10  *  it under the terms of the GNU General Public License as published by
11  *  the Free Software Foundation; either version 2 of the License, or
12  *  (at your option) any later version.
13  *
14  *  This program is distributed in the hope that it will be useful,
15  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  *  GNU General Public License for more details.
18  *
19  *  You should have received a copy of the GNU General Public License
20  *  along with this program; if not, write to the Free Software
21  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
22  *
23  */
24
25 struct btd_attribute;
26
27 void gatt_init(void);
28
29 void gatt_cleanup(void);
30
31 /*
32  * Read operation result callback. Called from the service implementation
33  * informing the core (ATT layer) the result of read operation.
34  * @err:        error in -errno format.
35  * @value:      value of the attribute read.
36  * @len:        length of value.
37  * @user_data:  user_data passed in btd_attr_read_t callback.
38  */
39 #ifdef __TIZEN_PATCH__
40 typedef uint8_t (*btd_attr_read_result_t) (int err, uint8_t *value, size_t len,
41                                                         void *user_data);
42 #else
43 typedef void (*btd_attr_read_result_t) (int err, uint8_t *value, size_t len,
44                                                         void *user_data);
45 #endif
46
47 /*
48  * Service implementation callback passed to core (ATT layer). It manages read
49  * operations received from remote devices.
50  * @attr:       reference of the attribute to be read.
51  * @bdaddr: Remote device address, which requets read value
52  * @result:     callback called from the service implementation informing the
53  *              value of attribute read.
54  * @user_data:  user_data passed in btd_attr_read_result_t callback.
55  */
56 #ifdef __TIZEN_PATCH__
57 typedef uint8_t (*btd_attr_read_t) (struct btd_attribute *attr, bdaddr_t *bdaddr,
58                                                 btd_attr_read_result_t result,
59                                                 void *user_data);
60 #else
61 typedef void (*btd_attr_read_t) (struct btd_attribute *attr,
62                                                 btd_attr_read_result_t result,
63                                                 void *user_data);
64 #endif
65
66 /*
67  * Write operation result callback. Called from the service implementation
68  * informing the core (ATT layer) the result of the write operation. It is used
69  * to manage Write Request operations.
70  * @err:        error in -errno format.
71  * @user_data:  user_data passed in btd_attr_write_t callback.
72  */
73 #ifdef __TIZEN_PATCH__
74 typedef uint8_t (*btd_attr_write_result_t) (int err,    void *user_data);
75 #else
76 typedef void (*btd_attr_write_result_t) (int err, void *user_data);
77 #endif
78 /*
79  * Service implementation callback passed to core (ATT layer). It manages write
80  * operations received from remote devices.
81  * @attr:       reference of the attribute to be changed.
82  * @value:      new attribute value.
83  * @len:        length of value.
84  * @result:     callback called from the service implementation informing the
85  *              result of the write operation.
86  * @user_data:  user_data passed in btd_attr_write_result_t callback.
87  */
88 #ifdef __TIZEN_PATCH__
89 typedef uint8_t (*btd_attr_write_t) (struct btd_attribute *attr,
90                                         const uint8_t *value, size_t len,
91                                         btd_attr_write_result_t result,
92                                         void *user_data);
93 #else
94 typedef void (*btd_attr_write_t) (struct btd_attribute *attr,
95                                         const uint8_t *value, size_t len,
96                                         btd_attr_write_result_t result,
97                                         void *user_data);
98 #endif
99
100 /* btd_gatt_add_service - Add a service declaration to local attribute database.
101  * @uuid:       Service UUID.
102  * @path:       Service object path.
103  *
104  * Returns a reference to service declaration attribute. In case of error,
105  * NULL is returned.
106  */
107 #ifdef __TIZEN_PATCH__
108 struct btd_attribute *btd_gatt_add_service(const bt_uuid_t *uuid, const char *path);
109 #else
110 struct btd_attribute *btd_gatt_add_service(const bt_uuid_t *uuid);
111 #endif
112
113 #ifdef __TIZEN_PATCH__
114 /*
115  * btd_gatt_update_attr_db - updates the attribute data base.
116  */
117 bool btd_gatt_update_attr_db(void);
118
119 /*
120  * btd_get_service_path - Gets the Service object path if registerd.
121  */
122 char *btd_get_service_path(bt_uuid_t uuid);
123
124 /*
125  * btd_get_attrib_path - Gets the attribute path if registerd.
126  */
127 const char *btd_get_attrib_path(struct btd_attribute *attrib);
128
129 /*
130  * btd_find_service_from_attr - Gets the Service from attribute if registerd.
131  */
132 const char *btd_find_service_from_attr(struct btd_attribute *attrib);
133
134 /*
135  * service_append_dict - Prepare the dictionar entry for a Service
136  * along with characteristics and discriptors.
137  */
138 DBusMessage *service_append_dict(bt_uuid_t uuid, DBusMessage *msg);
139
140 /*
141  * btd_gatt_set_notify_indicate_flag - Set the notification and indication flag.
142  * @attrib:     attribute.
143  * @notify_indicate: flag to set
144  */
145 void btd_gatt_set_notify_indicate_flag(struct btd_attribute *attrib,
146                                                 bool notify_indicate);
147 #endif
148
149 /*
150  * btd_gatt_remove_service - Remove a service (along with all its
151  * characteristics) from the local attribute database.
152  * @service:    Service declaration attribute.
153  */
154 void btd_gatt_remove_service(struct btd_attribute *service);
155
156 /*
157  * btd_gatt_add_char - Add a characteristic (declaration and value attributes)
158  * to local attribute database.
159  * @uuid:       Characteristic UUID (16-bits or 128-bits).
160  * @properties: Characteristic properties. See Core SPEC 4.1 page 2183.
161  * @path:       Characteristic object path.
162  * @read_cb:    Callback used to provide the characteristic value.
163  * @write_cb:   Callback called to notify the implementation that a new value
164  *              is available.
165  *
166  * Returns a reference to characteristic value attribute. In case of error,
167  * NULL is returned.
168  */
169 #ifdef __TIZEN_PATCH__
170 struct btd_attribute *btd_gatt_add_char(const bt_uuid_t *uuid,
171                                                 uint8_t properties,
172                                                 const char *path,
173                                                 btd_attr_read_t read_cb,
174                                                 btd_attr_write_t write_cb);
175 #else
176 struct btd_attribute *btd_gatt_add_char(const bt_uuid_t *uuid,
177                                                 uint8_t properties,
178                                                 btd_attr_read_t read_cb,
179                                                 btd_attr_write_t write_cb);
180 #endif
181
182 /*
183  * btd_gatt_add_char_desc - Add a characteristic descriptor to the local
184  * attribute database.
185  * @uuid:       Characteristic Descriptor UUID (16-bits or 128-bits).
186  * @path:       Characteristic object path.
187  * @read_cb:    Callback that should be called once the characteristic
188  *              descriptor attribute is read.
189  * @write_cb:   Callback that should be called once the characteristic
190  *              descriptor attribute is written.
191  *
192  * Returns a reference to characteristic descriptor attribute. In case of
193  * error, NULL is returned.
194  */
195 #ifdef __TIZEN_PATCH__
196 struct btd_attribute *btd_gatt_add_char_desc(const bt_uuid_t *uuid,
197                                                 const char *path,
198                                                 btd_attr_read_t read_cb,
199                                                 btd_attr_write_t write_cb);
200 #else
201 struct btd_attribute *btd_gatt_add_char_desc(const bt_uuid_t *uuid,
202                                                 btd_attr_read_t read_cb,
203                                                 btd_attr_write_t write_cb);
204 #endif
205
206 #ifdef __TIZEN_PATCH__
207 /*
208  * btd_gatt_update_char - update characteristic value to the local
209  * attribute database.
210  * @uuid:       Characteristic UUID (16-bits or 32-bits or 128-bits).
211  * @value:      charateristci value to update the databas with
212  * @len:        length of the value.
213  *
214  * Returns a TRUE or FALSE.
215  */
216 bool btd_gatt_update_char(const bt_uuid_t *uuid, uint8_t *value, size_t len);
217 #endif
218
219 #endif