Fix 64bit build error
[platform/core/connectivity/bluetooth-frwk.git] / include / bluetooth-gatt-server-api.h
1 /*
2  * Bluetooth-frwk
3  *
4  * Contact: Anupam Roy (anupam.r@samsung.com)
5  *
6  * Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *              http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  */
21
22 #ifndef __BLUETOOTH_GATT_SERVER_API_H
23 #define __BLUETOOTH_GATT_SERVER_API_H
24
25 #include <stdint.h>
26 #include <glib.h>
27 #include <dlog.h>
28
29 #include <bluetooth-api.h>
30
31 #define BLUETOOTH_GATT_ATT_DATA_LENGTH_MAX      610 /**< GATT ATT value max len */
32
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36
37 /**
38  * GATT Server Request type
39  */
40 typedef enum {
41         BLUETOOTH_GATT_REQUEST_TYPE_READ = 0x00,       /* Read Requested */
42         BLUETOOTH_GATT_REQUEST_TYPE_WRITE = 0x01,      /* Write Requested */
43         BLUETOOTH_GATT_REQUEST_TYPE_EXEC_WRITE = 0x02, /* Exec Write Requested */
44         BLUETOOTH_GATT_REQUEST_TYPE_ACQUIRE_WRITE = 0x03,
45         BLUETOOTH_GATT_REQUEST_TYPE_ACQUIRE_NOTIFY = 0x04
46 } bluetooth_gatt_att_request_type_e;
47
48 /**
49  * GATT Server Response/Indication data
50  */
51 typedef struct {
52         guint8 data[BLUETOOTH_GATT_ATT_DATA_LENGTH_MAX];
53         int length;
54         int offset;
55 } bluetooth_gatt_att_data_t;
56
57 /**
58  * GATT Server service add data
59  */
60 typedef struct {
61         int service_type;
62         int num_handles;
63         int instance_id;
64 } bluetooth_gatt_server_service_params_t;
65
66 /**
67  * GATT Server attributes(characteristic/descriptors) add data
68  */
69 typedef struct {
70         bt_gatt_permission_t permissions;
71         bt_gatt_characteristic_property_t properties;
72         int service_handle;
73         int instance_id;
74 } bluetooth_gatt_server_attribute_params_t;
75
76 /**
77  * GATT Server Indication data
78  */
79 typedef struct {
80         int atrribute_handle;
81         bluetooth_device_address_t device_address;      /**< device address */
82         gboolean need_confirmation;
83         int instance_id;
84         int fd; /**< handle fd if existing */
85 } bluetooth_gatt_server_indication_params_t;
86
87 /**
88  * GATT Server connection/disconnection info
89  */
90 typedef struct {
91         bluetooth_device_address_t device_address;      /** < Device address */
92         int server_instance;                            /** < GATT Server Instance Id */
93 } bluetooth_gatt_server_connection_info_t;
94
95 /**
96 * GATT Server Service Added info
97 */
98 typedef struct {
99         int server_instance;       /** < GATT Server Instance Id */
100         int service_handle;        /** < GATT Server Service handle */
101         int is_primary;            /** < GATT Server Is Primary Service */
102         char uuid[BLUETOOTH_UUID_STRING_MAX];
103 } bluetooth_gatt_server_service_added_info_t;
104
105 /**
106 * GATT Server Included Service Added info
107 */
108 typedef struct {
109         int server_instance;               /** < GATT Server Instance Id */
110         int service_handle;                /** < GATT Server Service handle */
111         int included_service_handle;       /** < GATT Server Included service handle */
112 } bluetooth_gatt_server_included_service_added_info_t;
113
114
115 /**
116  * GATT Server write attribute data received from Remote GATT client: Max Size is 600 bytes
117  */
118 typedef struct {
119         char data[BLUETOOTH_GATT_ATT_DATA_LENGTH_MAX + 1];
120 } bluetooth_gatt_server_write_data_t;
121
122
123 /**
124 * GATT Server Attribute Added Info
125 */
126 typedef struct {
127         int server_instance;    /** < GATT Server Instance Id */
128         int service_handle;     /** < GATT Server Service handle */
129         int attr_handle;        /** < GATT Server Attribute Handle (Characteristic or Descriptor) */
130         char uuid[BLUETOOTH_UUID_STRING_MAX];   /** < GATT Server Atribute UUID */
131 } bluetooth_gatt_server_attribute_added_info_t;
132
133 /**
134 * GATT Server Service Info
135 */
136 typedef struct {
137         int server_instance;            /** < GATT Server Instance Id */
138         int service_handle;             /** < GATT Server Service handle */
139 } bluetooth_gatt_server_service_status_t;
140
141 /**
142 * GATT Server Read Requested Info
143 */
144 typedef struct {
145         int connection_id;              /** < GATT Server Connection ID */
146         int request_id;                 /** < GATT Server Read Request ID */
147         int attribute_handle;           /** < GATT Server att handle */
148         int offset;                     /** < GATT Server attribute offset */
149         gboolean is_long;               /** < GATT Server Is Long attribute  */
150         bluetooth_device_address_t device_address;      /**< Remote GATT client device address */
151 } bluetooth_gatt_server_read_requested_info_t;
152
153 /**
154 * GATT Server Write Requested Info
155 */
156 typedef struct {
157         int connection_id;                              /** < GATT Server Connection ID */
158         int request_id;                                 /** < GATT Server Write Request ID */
159         int attribute_handle;                           /** < GATT Server Write att handle */
160         int offset;                             /** < GATT Server attribute offset */
161         gboolean need_resp;                                 /** < GATT Server Write req needs response  */
162         gboolean is_prep_write;                             /** < GATT Server Is Prepared write  */
163         int length;                             /** < GATT Server Write attribute length  */
164         bluetooth_gatt_server_write_data_t data;        /** < Write attribute data */
165         bluetooth_device_address_t device_address;      /** < Remote GATT client device address */
166 } bluetooth_gatt_server_write_requested_info_t;
167
168 /**
169 * GATT Server Write Requested Info
170 */
171 typedef struct {
172         int connection_id;                              /** < GATT Server Connection ID */
173         int request_id;                                 /** < GATT Server Write Request ID */
174         int attribute_handle;                           /** < GATT Server Write att handle */
175         int offset;                             /** < GATT Server attribute offset */
176         char address[BLUETOOTH_ADDRESS_STRING_LENGTH];
177 } bluetooth_gatt_server_acquire_write_info_t;;
178
179 typedef struct {
180         int write_fd;
181         int relpy_fd;
182         int mtu;
183         int att_hand;
184         void *io_channel;
185         guint watch_id;
186         char *path ;
187 } bluetooth_gatt_acquire_notify_info_t;
188
189 /**
190  * GATT Server Update Characteristic Value
191  */
192 typedef struct {
193         int attribute_handle;                           /** < GATT Server Write att handle */
194         int length;                        /** < GATT Server Write attribute length  */
195         bluetooth_gatt_server_write_data_t data;        /** < Write attribute data */
196 } bluetooth_gatt_server_update_value_t;
197
198 /**
199  * GATT Server Exec write Requested Info
200  */
201 typedef struct {
202         int connection_id;      /** < GATT Server Connection ID */
203         int request_id;         /** < GATT Server Exec Write Request ID */
204         int exec_write;         /** < GATT Server Exec Write */
205         bluetooth_device_address_t device_address;      /** < Remote GATT client device address */
206 } bluetooth_gatt_server_exec_write_requested_info_t;
207
208 /**
209  * GATT Server Indicate confirmed Info
210  */
211 typedef struct {
212         int handle;             /** < GATT Attribute handle */
213         gboolean completed;     /** < GATT Server Exec Write Request ID */
214         bluetooth_device_address_t device_address;      /** < Remote GATT client device address */
215 } bluetooth_gatt_server_indicate_confirmed_info_t;
216
217 /**
218  * GATT Server Indicate confirmed Info
219  */
220 typedef struct {
221         int handle;     /** < GATT Attribute handle */
222         gboolean notification;                          /** < GATT CCCD Notification changed */
223         bluetooth_device_address_t device_address;      /** < Remote GATT client device address */
224 } bluetooth_gatt_server_notification_changed_t;
225
226 /**
227  * GATT Server response data
228  */
229 typedef struct {
230         bluetooth_gatt_att_request_type_e req_type;
231         int request_id;
232         int response_status;
233         gboolean auth_req;
234 } bluetooth_gatt_server_response_params_t;
235
236 /**
237  * GATT Server acquire response data
238  */
239 typedef struct {
240         bluetooth_gatt_att_request_type_e req_type;
241         int request_id;
242         int fd;
243         int mtu;
244 } bluetooth_gatt_server_acquire_response_params_t;
245
246 /**
247  * GATT Server Bluedroid Specific Permission Mask
248  */
249 typedef enum {
250         BLUETOOTH_PRODUCT_GATT_PERMISSION_READ = 0x01,
251         BLUETOOTH_PRODUCT_GATT_PERMISSION_ENCRYPT_READ = 0x02,
252         BLUETOOTH_PRODUCT_GATT_PERMISSION_ENCRYPT_READ_MITM = 0x04,
253         BLUETOOTH_PRODUCT_GATT_PERMISSION_WRITE = 0x10,
254         BLUETOOTH_PRODUCT_GATT_PERMISSION_ENCRYPT_WRITE = 0x20,
255         BLUETOOTH_PRODUCT_GATT_PERMISSION_ENCRYPT_WRITE_MITM = 0x40,
256         BLUETOOTH_PRODUCT_GATT_PERMISSION_WRITE_SIGNED = 0x80,
257         BLUETOOTH_PRODUCT_GATT_PERMISSION_WRITE_SIGNED_MITM = 0x100,
258         BLUETOOTH_PRODUCT_GATT_PERMISSION_INVALID = 0xffff,
259 } bt_product_gatt_permission_t;
260
261 typedef struct {
262         int event;
263         int result;
264         void *param_data;
265         void *user_data;
266 } gatt_server_event_param_t;
267
268 typedef void (*gatt_server_cb_func_ptr)(int, gatt_server_event_param_t *, void *);
269
270 /**
271  * @fn int bluetooth_gatt_server_init(gatt_server_cb_func_ptr callback_ptr, void *user_data)
272  * @brief Initialize GATT Server and register the callback
273  *
274  * This function is a synchronous call.
275  *
276  * @remark      None
277  *
278  */
279 int bluetooth_gatt_server_init(int *instance_id, gatt_server_cb_func_ptr callback_ptr,
280                 void *user_data);
281
282 //int bluetooth_gatt_register_application(int instance_id);
283 //int bluetooth_gatt_server_init(gatt_server_cb_func_ptr callback_ptr, void *user_data);
284
285 int bluetooth_gatt_server_deinit(void);
286
287 int bluetooth_gatt_server_register(const gchar *name, int *instance_id);
288
289 int bluetooth_gatt_server_unregister(int instance_id);
290
291 int bluetooth_gatt_server_connect(bluetooth_device_address_t *addr_hex, int instance_id);
292
293 int bluetooth_gatt_server_disconnect(bluetooth_device_address_t *addr_hex, int instance_id);
294
295 int bluetooth_gatt_server_add_service(const char *svc_uuid, int type, int numhandles, int instance_id, int *service_handle);
296
297 int bluetooth_gatt_server_add_included_service(int instance_id, int service_handle, int included_handle);
298
299 int bluetooth_gatt_server_add_new_characteristic(const char *char_uuid, const bluetooth_gatt_server_attribute_params_t *param, int *char_handle);
300
301
302 int bluetooth_gatt_server_add_descriptor(const char *desc_uuid, bt_gatt_permission_t permissions, int service_handle,
303                 int instance_id, int *descriptor_handle);
304
305 int bluetooth_gatt_server_start_service(int service_handle, int instance_id);
306
307 int bluetooth_gatt_server_stop_service(int service_handle, int instance_id);
308
309 int bluetooth_gatt_server_delete_service(int service_handle, int instance_id);
310
311 int bluetooth_gatt_server_send_indication(bluetooth_device_address_t *addr_hex,
312                 bluetooth_gatt_server_indication_params_t *param,
313                 const bluetooth_gatt_att_data_t *att_value);
314
315 int bluetooth_gatt_server_send_response(const bluetooth_gatt_server_response_params_t *param,
316                 const bluetooth_gatt_att_data_t *value);
317
318 int bluetooth_gatt_server_update_multi_adv_instance(const gchar *unique_name, int instance_id);
319
320 int bluetooth_gatt_server_update_characteristic(int instance_id, const bluetooth_gatt_server_update_value_t *value);
321
322 #ifdef __cplusplus
323 }
324 #endif
325 #endif /* __BLUETOOTH_GATT_SERVER_API_H */