Remove wrong dependency in the systemd service file
[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 } bluetooth_gatt_server_indication_params_t;
85
86 /**
87  * GATT Server connection/disconnection info
88  */
89 typedef struct {
90         bluetooth_device_address_t device_address;      /** < Device address */
91         int server_instance;                            /** < GATT Server Instance Id */
92 } bluetooth_gatt_server_connection_info_t;
93
94 /**
95 * GATT Server Service Added info
96 */
97 typedef struct {
98         int server_instance;       /** < GATT Server Instance Id */
99         int service_handle;        /** < GATT Server Service handle */
100         int is_primary;            /** < GATT Server Is Primary Service */
101         char uuid[BLUETOOTH_UUID_STRING_MAX];
102 } bluetooth_gatt_server_service_added_info_t;
103
104 /**
105 * GATT Server Included Service Added info
106 */
107 typedef struct {
108         int server_instance;               /** < GATT Server Instance Id */
109         int service_handle;                /** < GATT Server Service handle */
110         int included_service_handle;       /** < GATT Server Included service handle */
111 } bluetooth_gatt_server_included_service_added_info_t;
112
113
114 /**
115  * GATT Server write attribute data received from Remote GATT client: Max Size is 600 bytes
116  */
117 typedef struct {
118         char data[BLUETOOTH_GATT_ATT_DATA_LENGTH_MAX + 1];
119 } bluetooth_gatt_server_write_data_t;
120
121
122 /**
123 * GATT Server Attribute Added Info
124 */
125 typedef struct {
126         int server_instance;    /** < GATT Server Instance Id */
127         int service_handle;     /** < GATT Server Service handle */
128         int attr_handle;        /** < GATT Server Attribute Handle (Characteristic or Descriptor) */
129         char uuid[BLUETOOTH_UUID_STRING_MAX];   /** < GATT Server Atribute UUID */
130 } bluetooth_gatt_server_attribute_added_info_t;
131
132 /**
133 * GATT Server Service Info
134 */
135 typedef struct {
136         int server_instance;            /** < GATT Server Instance Id */
137         int service_handle;             /** < GATT Server Service handle */
138 } bluetooth_gatt_server_service_status_t;
139
140 /**
141 * GATT Server Read Requested Info
142 */
143 typedef struct {
144         int connection_id;              /** < GATT Server Connection ID */
145         int request_id;                 /** < GATT Server Read Request ID */
146         int attribute_handle;           /** < GATT Server att handle */
147         int offset;                     /** < GATT Server attribute offset */
148         gboolean is_long;               /** < GATT Server Is Long attribute  */
149         bluetooth_device_address_t device_address;      /**< Remote GATT client device address */
150 } bluetooth_gatt_server_read_requested_info_t;
151
152 /**
153 * GATT Server Write Requested Info
154 */
155 typedef struct {
156         int connection_id;                              /** < GATT Server Connection ID */
157         int request_id;                                 /** < GATT Server Write Request ID */
158         int attribute_handle;                           /** < GATT Server Write att handle */
159         int offset;                             /** < GATT Server attribute offset */
160         gboolean need_resp;                                 /** < GATT Server Write req needs response  */
161         gboolean is_prep_write;                             /** < GATT Server Is Prepared write  */
162         int length;                             /** < GATT Server Write attribute length  */
163         bluetooth_gatt_server_write_data_t data;        /** < Write attribute data */
164         bluetooth_device_address_t device_address;      /** < Remote GATT client device address */
165 } bluetooth_gatt_server_write_requested_info_t;
166
167 /**
168 * GATT Server Write Requested Info
169 */
170 typedef struct {
171         int connection_id;                              /** < GATT Server Connection ID */
172         int request_id;                                 /** < GATT Server Write Request ID */
173         int attribute_handle;                           /** < GATT Server Write att handle */
174         int offset;                             /** < GATT Server attribute offset */
175         char address[BLUETOOTH_ADDRESS_STRING_LENGTH];
176 } bluetooth_gatt_server_acquire_write_info_t;;
177
178
179 /**
180  * GATT Server Update Characteristic Value
181  */
182 typedef struct {
183         int attribute_handle;                           /** < GATT Server Write att handle */
184         int length;                        /** < GATT Server Write attribute length  */
185         bluetooth_gatt_server_write_data_t data;        /** < Write attribute data */
186 } bluetooth_gatt_server_update_value_t;
187
188 /**
189  * GATT Server Exec write Requested Info
190  */
191 typedef struct {
192         int connection_id;      /** < GATT Server Connection ID */
193         int request_id;         /** < GATT Server Exec Write Request ID */
194         int exec_write;         /** < GATT Server Exec Write */
195         bluetooth_device_address_t device_address;      /** < Remote GATT client device address */
196 } bluetooth_gatt_server_exec_write_requested_info_t;
197
198 /**
199  * GATT Server Indicate confirmed Info
200  */
201 typedef struct {
202         int handle;             /** < GATT Attribute handle */
203         gboolean completed;     /** < GATT Server Exec Write Request ID */
204         bluetooth_device_address_t device_address;      /** < Remote GATT client device address */
205 } bluetooth_gatt_server_indicate_confirmed_info_t;
206
207 /**
208  * GATT Server Indicate confirmed Info
209  */
210 typedef struct {
211         int handle;     /** < GATT Attribute handle */
212         gboolean notification;                          /** < GATT CCCD Notification changed */
213         bluetooth_device_address_t device_address;      /** < Remote GATT client device address */
214 } bluetooth_gatt_server_notification_changed_t;
215
216 /**
217  * GATT Server response data
218  */
219 typedef struct {
220         bluetooth_gatt_att_request_type_e req_type;
221         int request_id;
222         int response_status;
223         gboolean auth_req;
224 } bluetooth_gatt_server_response_params_t;
225
226 /**
227  * GATT Server acquire response data
228  */
229 typedef struct {
230         bluetooth_gatt_att_request_type_e req_type;
231         int request_id;
232         int fd;
233         int mtu;
234 } bluetooth_gatt_server_acquire_response_params_t;
235
236 /**
237  * GATT Server Bluedroid Specific Permission Mask
238  */
239 typedef enum {
240         BLUETOOTH_PRODUCT_GATT_PERMISSION_READ = 0x01,
241         BLUETOOTH_PRODUCT_GATT_PERMISSION_ENCRYPT_READ = 0x02,
242         BLUETOOTH_PRODUCT_GATT_PERMISSION_ENCRYPT_READ_MITM = 0x04,
243         BLUETOOTH_PRODUCT_GATT_PERMISSION_WRITE = 0x10,
244         BLUETOOTH_PRODUCT_GATT_PERMISSION_ENCRYPT_WRITE = 0x20,
245         BLUETOOTH_PRODUCT_GATT_PERMISSION_ENCRYPT_WRITE_MITM = 0x40,
246         BLUETOOTH_PRODUCT_GATT_PERMISSION_WRITE_SIGNED = 0x80,
247         BLUETOOTH_PRODUCT_GATT_PERMISSION_WRITE_SIGNED_MITM = 0x100,
248         BLUETOOTH_PRODUCT_GATT_PERMISSION_INVALID = 0xffff,
249 } bt_product_gatt_permission_t;
250
251 typedef struct {
252         int event;
253         int result;
254         void *param_data;
255         void *user_data;
256 } gatt_server_event_param_t;
257
258 typedef void (*gatt_server_cb_func_ptr)(int, gatt_server_event_param_t *, void *);
259
260 /**
261  * @fn int bluetooth_gatt_server_init(gatt_server_cb_func_ptr callback_ptr, void *user_data)
262  * @brief Initialize GATT Server and register the callback
263  *
264  * This function is a synchronous call.
265  *
266  * @remark      None
267  *
268  */
269 int bluetooth_gatt_server_init(int *instance_id, gatt_server_cb_func_ptr callback_ptr,
270                 void *user_data);
271
272 //int bluetooth_gatt_register_application(int instance_id);
273 //int bluetooth_gatt_server_init(gatt_server_cb_func_ptr callback_ptr, void *user_data);
274
275 int bluetooth_gatt_server_deinit(void);
276
277 int bluetooth_gatt_server_register(const gchar *name, int *instance_id);
278
279 int bluetooth_gatt_server_unregister(int instance_id);
280
281 int bluetooth_gatt_server_connect(bluetooth_device_address_t *addr_hex, int instance_id);
282
283 int bluetooth_gatt_server_disconnect(bluetooth_device_address_t *addr_hex, int instance_id);
284
285 int bluetooth_gatt_server_add_service(const char *svc_uuid, int type, int numhandles, int instance_id, int *service_handle);
286
287 int bluetooth_gatt_server_add_included_service(int instance_id, int service_handle, int included_handle);
288
289 int bluetooth_gatt_server_add_new_characteristic(const char *char_uuid, const bluetooth_gatt_server_attribute_params_t *param, int *char_handle);
290
291
292 int bluetooth_gatt_server_add_descriptor(const char *desc_uuid, bt_gatt_permission_t permissions, int service_handle,
293                 int instance_id, int *descriptor_handle);
294
295 int bluetooth_gatt_server_start_service(int service_handle, int instance_id);
296
297 int bluetooth_gatt_server_stop_service(int service_handle, int instance_id);
298
299 int bluetooth_gatt_server_delete_service(int service_handle, int instance_id);
300
301 int bluetooth_gatt_server_send_indication(bluetooth_device_address_t *addr_hex,
302                 const bluetooth_gatt_server_indication_params_t *param,
303                 const bluetooth_gatt_att_data_t *att_value);
304
305 int bluetooth_gatt_server_send_response(const bluetooth_gatt_server_response_params_t *param,
306                 const bluetooth_gatt_att_data_t *value);
307
308 int bluetooth_gatt_server_update_multi_adv_instance(const gchar *unique_name, int instance_id);
309
310 int bluetooth_gatt_server_update_characteristic(int instance_id, const bluetooth_gatt_server_update_value_t *value);
311
312 #ifdef __cplusplus
313 }
314 #endif
315 #endif /* __BLUETOOTH_GATT_SERVER_API_H */