Added the GATT server disconnect
[platform/core/connectivity/bluetooth-frwk.git] / bt-oal / include / oal-gatt.h
1 /*
2  * Open Adaptation Layer (OAL)
3  *
4  * Copyright (c) 2014-2015 Samsung Electronics Co., Ltd.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *              http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  */
19
20 #ifndef OAL_GATT_H_
21 #define OAL_GATT_H_
22
23 #include <oal-manager.h>
24
25 #define OAL_GATT_MAX_ATTR_LEN 600
26 #define GATTC_READ_VALUE_TYPE_VALUE          0x0000  /* Attribute value itself */
27 #define GATTC_READ_VALUE_TYPE_AGG_FORMAT     0x2905  /* Characteristic Aggregate Format*/
28
29 typedef enum {
30         OAL_GATT_WRITE_NO_RSP = 1,
31         OAL_GATT_WRITE ,
32 } oal_gatt_write_type_t;
33
34 typedef enum {
35         OAL_GATT_AUTH_REQ_NONE = 0,
36         OAL_GATT_AUTH_REQ_NO_MITM,                      /* unauthenticated encryption */
37         OAL_GATT_AUTH_REQ_MITM,                         /* authenticated encryption */
38         OAL_GATT_AUTH_REQ_SIGNED_NO_MITM,
39         OAL_GATT_AUTH_REQ_SIGNED_MITM,
40 } oal_gatt_auth_req_t;
41
42 /** GATT value type used in response to remote read requests */
43 typedef struct {
44         uint8_t           value[OAL_GATT_MAX_ATTR_LEN];
45         uint16_t          handle;
46         uint16_t          offset;
47         uint16_t          len;
48         uint8_t           auth_req;
49 } oal_gatt_value_t;
50
51 /** GATT remote read request response type */
52 typedef union {
53         oal_gatt_value_t attr_value;
54         uint16_t            handle;
55 } oal_gatt_response_t;
56
57 typedef struct {
58         uint8_t  server_if;
59         uint8_t  set_scan_rsp;
60         uint8_t  include_name;
61         uint8_t  include_txpower;
62         uint16_t  appearance;
63         char*    manufacturer_data;
64         uint16_t manufacturer_data_len;
65         char*    service_data;
66         uint16_t service_data_len;
67         char*    service_uuid;
68         uint16_t service_uuid_len;
69         char*    solicit_uuid;
70         uint16_t solicit_uuid_len;
71         uint16_t min_interval;
72         uint16_t max_interval;
73         uint8_t  adv_type;
74         uint8_t  chnl_map;
75         uint16_t  tx_power;
76         uint8_t  timeout_s;
77 } oal_ble_multi_adv_param_setup_t;
78
79 /**
80  * @brief Enable Bluetooth Low Energy GATT Feature
81  *
82  * @remarks  Application will be able to advertise and scan other Low Energy devices.
83  *
84  * @return OAL_STATUS_SUCCESS on success, otherwise non-zero error value.
85  * @retval #OAL_STATUS_SUCCESS  Successful
86  *
87  * @pre OAL API must be initialized with oal_bt_init().
88  *
89  * @see  gatt_disable()
90  */
91 oal_status_t gatt_enable(void);
92
93 /**
94  * @brief Disable Bluetooth Low Energy GATT Feature
95  *
96  * @remarks  Application will not be able to advertise or scan other Low Energy devices.
97  *
98  * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
99  * @retval #OAL_STATUS_SUCCESS  Successful
100  *
101  * @pre OAL API should be enabled with gatt_enable().
102  *
103  * @see  gatt_enable()
104  */
105 oal_status_t gatt_disable(void);
106
107 /**
108  * @brief Register the GATT Server
109  *
110  * @remarks  Application will register the GATT Server
111  *
112  * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
113  * @retval #OAL_STATUS_SUCCESS  Successful
114  *
115  * @pre OAl API should be enabled with gatt_enable().
116  *
117  * @see  gatt_enable()
118  */
119 oal_status_t gatts_register(oal_uuid_t* server_uuid);
120
121 /**
122  * @brief UnRegister the GATT Server
123  *
124  * @remarks  Application will unregister the GATT Server
125  *
126  * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
127  * @retval #OAL_STATUS_SUCCESS  Successful
128  *
129  * @pre OAl API should be enabled with gatti_enable().
130  *
131  * @see  gatts_register()
132  */
133 oal_status_t gatts_unregister(int instance_id);
134
135 /**
136  * @brief Start BLE Advertising feature
137  *
138  * @remarks  Application will start advertising and behave as a peripheral device
139  *
140  * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
141  * @retval #OAL_STATUS_SUCCESS  Successful
142  *
143  * @pre OAl API should be enabled with gatt_enable().
144  *
145  * @see  gatt_enable()
146  */
147 oal_status_t gatts_start_listen(int instance_id, gboolean enable);
148
149 /**
150  * @brief Stop BLE Advertising feature
151  *
152  * @remarks  Application will stop advertising and will no longer behave as a peripheral device.
153  *
154  * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
155  * @retval #OAL_STATUS_SUCCESS  Successful
156  *
157  * @pre Advertising should have been started with gatts_start_advertising().
158  *
159  * @see  gatts_start_listen()
160  */
161 oal_status_t gatts_stop_advertising(int instance_id);
162
163 /**
164  * @brief Enables the Bluetooth Low Energy Multiple advertisement feature
165  *
166  * @remarks  The application will be able to do multiple advertising
167  *
168  * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
169  * @retval #OAL_STATUS_SUCCESS  Successful
170  *
171  * @pre OAL API must be initialized with oal_bt_init().
172  *
173  * @see  gatts_multi_adv_disable()
174  */
175 oal_status_t gatts_multi_adv_enable(int instance_id);
176
177 /**
178  * @brief Disables the Bluetooth Low Energy Multiple advertisement feature
179  *
180  * @remarks  The application will not be able to do multiple advertising
181  *
182  * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
183  * @retval #OAL_STATUS_SUCCESS  Successful
184  *
185  * @pre OAL API must be initialized with oal_bt_init().
186  *
187  * @see  gatts_multi_adv_enable()
188  */
189 oal_status_t gatts_multi_adv_disable(int instance_id);
190
191 /**
192  * @brief Updates the parameters to configure the Multiple Advertising Features
193  *
194  * @remarks  The parameters like min and max interval, advertising type,
195  * channel map, tx power and timeout will be updated.
196  *
197  * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
198  * @retval #OAL_STATUS_SUCCESS  Successful
199  *
200  * @pre OAL API should be enabled with gatts_multi_adv_enable().
201  *
202  * @see  gatts_multi_adv_enable()
203  */
204 oal_status_t gatts_multi_adv_update(int instance_id, int min_intv, int max_intv,
205                 int adv_type, int chnl_map,
206                 int tx_power, int timeout_s);
207
208 /**
209  * @brief Sets the the Multiple Advertising Data
210  *
211  * @remarks  The Multiple advertising data will be set.
212  *
213  * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
214  * @retval #OAL_STATUS_SUCCESS  Successful
215  *
216  * @pre OAL API should be enabled with gatts_multi_adv_enable().
217  *
218  * @see  gatts_multi_adv_enable()
219  */
220 oal_status_t gatts_multi_adv_set_inst_data(int instance_id,
221                 oal_ble_multi_adv_param_setup_t *adv_param_setup);
222
223 /**
224  * @brief Get current ATT MTU size of the connection
225  *
226  * @remarks  The application will get current ATT MTU size of the connection
227  *
228  * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
229  * @retval #OAL_STATUS_SUCCESS>-Successful
230  *
231  * @pre OAL API must be initialized with oal_bt_init().
232  *
233  * @param conn_id: active connection id (input)
234  * mtu: att mtu size of the connection (output)
235  *
236  * @see  gatts_multi_adv_enable()
237  */
238 oal_status_t gatts_get_att_mtu(int conn_id, int *mtu);
239
240 /**
241  * @brief GATT Server Add Service
242  *
243  * @remarks  GATT Server will add new service in gatt server database.
244  *
245  * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
246  * @retval #OAL_STATUS_SUCCESS  Successful
247  *
248  * @pre Advertising should have been started with gatts_start_advertising().
249  *
250  * @see  gatts_start_advertising()
251  */
252 oal_status_t gatts_add_service(int instance_id, oal_gatt_srvc_id_t *gatt_serv_id, int num_handles);
253
254 /**
255  * @brief GATT Server Add Included Service
256  *
257  * @remarks  GATT Server will add new included service in gatt server database.
258  *
259  * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
260  * @retval #OAL_STATUS_SUCCESS  Successful
261  *
262  * @pre Primary service should have been added with gatts_add_service().
263  *
264  * @see  gatts_add_service()
265  */
266 oal_status_t gatts_add_included_services(int instance_id, int srv_handle, int incld_handle);
267
268 /**
269  * @brief GATT Server Add Charactertistic
270  *
271  * @remarks  GATT Server will add new Charactertistic in gatt server database.
272  *
273  * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
274  * @retval #OAL_STATUS_SUCCESS  Successful
275  *
276  * @pre Primary service should have been added with gatts_add_service().
277  *
278  * @see  gatts_add_service()
279  */
280 oal_status_t gatts_add_characteristics(int instance_id, int srv_handle, oal_uuid_t* charc_uuid, int propts, int permsn);
281
282 /**
283  * @brief GATT Server Add Descriptor
284  *
285  * @remarks  GATT Server will add new Descriptor in gatt server database.
286  *
287  * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
288  * @retval #OAL_STATUS_SUCCESS  Successful
289  *
290  * @pre Primary service should have been added with gatts_add_service().
291  *
292  * @see  gatts_add_service()
293  */
294 oal_status_t gatts_add_descriptor(int instance_id, int srv_handle, oal_uuid_t* desc_uuid, int permsn);
295
296 /**
297  * @brief GATT Server make ready the new service for advertiment
298  *
299  * @remarks  GATT Server will enable the new service for advertiment.
300  *
301  * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
302  * @retval #OAL_STATUS_SUCCESS  Successful
303  *
304  * @pre Primary service should have been added with gatts_add_service().
305  *
306  * @see  gatts_add_service()
307  */
308 oal_status_t gatts_start_service(int innstance_id, int svc_handle, int transport);
309
310 /**
311  * @brief GATT Server Stop the added service from advertiment
312  *
313  * @remarks  GATT Server will Stop the added service from advertiment .
314  *
315  * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
316  * @retval #OAL_STATUS_SUCCESS  Successful
317  *
318  * @pre Primary service should have been started with gatts_start_service().
319  *
320  * @see  gatts_start_service()
321  */
322 oal_status_t gatts_stop_service(int instance_id, int svc_hdl);
323
324 /**
325  * @brief GATT Server delete the already added service
326  *
327  * @remarks  GATT Server will delete the already added service in gatt server database.
328  *
329  * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
330  * @retval #OAL_STATUS_SUCCESS  Successful
331  *
332  * @pre Primary service should have been added with gatts_add_service().
333  *
334  * @see  gatts_add_service()
335  */
336 oal_status_t gatts_delete_service(int instance_id, int svc_handle);
337
338 /**
339  * @brief GATT Server send the indication for change in attribute value
340  *
341  * @remarks  GATT Server will send the indication to client for change in attribute value .
342  *
343  * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
344  * @retval #OAL_STATUS_SUCCESS  Successful
345  *
346  * @pre A Client should be connected to this server.
347  *
348  * @see  gatts_connect()
349  */
350 oal_status_t gatts_send_indication(int ins_id, int attr_hndl, int conn_id, int len, int confirm, char* value);
351
352 /**
353  * @brief GATT Server Update value of the attribute associated with a GATT server instance
354  *
355  * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
356  * @retval #OAL_STATUS_SUCCESS  Successful
357  */
358 oal_status_t gatts_update_att_value(int ins_id, oal_gatt_value_t *value);
359
360 /**
361  * @brief GATT Server send the response for attribute value
362  *
363  * @remarks  GATT Server will send the response for attribute value asked from client .
364  *
365  * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
366  * @retval #OAL_STATUS_SUCCESS  Successful
367  *
368  * @pre A Client should be connected to this server.
369  *
370  * @see  gatts_connect()
371  */
372 oal_status_t gatts_send_response(int conn_id, int trans_id, int resp_status, oal_gatt_response_t *response);
373
374 oal_status_t gatts_disconnect(int Ins_id, bt_address_t *device_address, int conId);
375
376 /**
377  * @brief Start LE Device discovery
378  *
379  * @remarks  BLE discovery will be started
380  *
381  * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
382  * @retval #OAL_STATUS_SUCCESS  Successful
383  *
384  * @pre OAL API should be enabled with gatt_enable().
385  *
386  * @see  gatt_enable()
387  */
388 oal_status_t gattc_start_le_discovery(int client_id);
389 /**
390  * @brief Stop LE Device discovery
391  *
392  * @remarks  BLE discovery will be stopped
393  *
394  * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
395  * @retval #OAL_STATUS_SUCCESS  Successful
396  *
397  * @pre BLE Discovery should be started using the gattc_start_le_discovery().
398  *
399  * @see  gattc_start_le_discovery()
400  */
401 oal_status_t gattc_stop_le_discovery(int client_id);
402
403 /**
404  * @brief Set scan parameters
405  *
406  * @remarks  scan parameters will be set
407  *
408  * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
409  * @retval #OAL_STATUS_SUCCESS  Successful
410  *
411  */
412 oal_status_t gattc_set_le_scan_param(int scan_type, int itv, int win);
413
414 /** Registers a GATT client application with the stack */
415 oal_status_t gattc_register(oal_uuid_t* client_uuid);
416
417 oal_status_t gattc_deregister(int client_id);
418
419  /** Create a connection to a remote LE or dual-mode device */
420 oal_status_t gattc_connect(int client_id, bt_address_t *device_address, int isDirect);
421
422 oal_status_t gattc_search_service(int conn_id, oal_uuid_t *service_uuid);
423
424 oal_status_t gattc_get_characteristic(int conn_id, oal_gatt_srvc_id_t *srvc_id, oal_gatt_id_t *char_id);
425
426 oal_status_t gattc_get_descriptor(int conn_id, oal_gatt_srvc_id_t *srvc_id, oal_gatt_id_t *char_id,
427                                                         oal_gatt_id_t *desc_id);
428
429 oal_status_t gattc_read_characteristic(int conn_id, oal_gatt_srvc_id_t *srvc_id, oal_gatt_id_t *char_id,
430                                                                         oal_gatt_auth_req_t auth_req);
431
432 oal_status_t gattc_read_descriptor(int conn_id, oal_gatt_srvc_id_t *srvc_id, oal_gatt_id_t *char_id,
433                                                 oal_gatt_id_t *desc_id, oal_gatt_auth_req_t auth_req);
434 oal_status_t gattc_write_characteristic(int conn_id, oal_gatt_srvc_id_t *srvc_id, oal_gatt_id_t *char_id, oal_gatt_write_type_t write_type,
435                 int len, oal_gatt_auth_req_t auth_req, char* data);
436
437 oal_status_t gattc_acquire_notify(int conn_id, oal_gatt_srvc_id_t *srvc_id,
438                 oal_gatt_id_t *char_id,  int *fd, int *mtu);
439
440 oal_status_t gattc_acquire_write(int conn_id, oal_gatt_srvc_id_t *srvc_id,
441                 oal_gatt_id_t *char_id,  oal_gatt_auth_req_t auth_req , int *fd, int*mtu);
442
443 oal_status_t gattc_write_descriptor(int conn_id, oal_gatt_srvc_id_t *srvc_id, oal_gatt_id_t *char_id, oal_gatt_id_t *desc_id,
444                 oal_gatt_write_type_t write_type, int len, oal_gatt_auth_req_t auth_req, char* data);
445
446 oal_status_t gattc_disconnect(int client_id, bt_address_t *device_address, int conn_id);
447
448 oal_status_t gattc_conn_param_update(bt_address_t * address, int min, int max, int latency, int timeout);
449
450 oal_status_t gattc_register_for_notification(int client_id, bt_address_t * address,
451                                 oal_gatt_srvc_id_t *srvc_id, oal_gatt_id_t *char_id);
452
453 oal_status_t gattc_deregister_for_notification(int client_id, bt_address_t * address,
454                                 oal_gatt_srvc_id_t *srvc_id, oal_gatt_id_t *char_id);
455
456 oal_status_t gatt_send_response_acquire(int conn_id, int trans_id,
457                 int status, int fd, int mtu, void *);
458
459 #endif /* OAL_GATT_H_ */