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