18ba68975bcf7ad7854c1b8d523df3dd131016f4
[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 /**
43 * Scan filter entry
44 */
45 typedef enum {
46         OAL_BLE_SCAN_FILTER_FEATURE_DEVICE_ADDRESS = 0x01,                 /**< device address */
47         OAL_BLE_SCAN_FILTER_FEATURE_SERVICE_DATA_CHANGED = 0x02,           /**< service data changed */
48         OAL_BLE_SCAN_FILTER_FEATURE_SERVICE_UUID = 0x04,                   /**< service uuid */
49         OAL_BLE_SCAN_FILTER_FEATURE_SERVICE_SOLICITATION_UUID = 0x08,      /**< service solicitation uuid */
50         OAL_BLE_SCAN_FILTER_FEATURE_DEVICE_NAME = 0x10,                    /**< device name */
51         OAL_BLE_SCAN_FILTER_FEATURE_MANUFACTURER_DATA = 0x20,              /**< manufacturer data */
52         OAL_BLE_SCAN_FILTER_FEATURE_SERVICE_DATA = 0x40,                   /**< service data */
53 } oal_ble_scan_filter_feature_t;
54
55 /** GATT value type used in response to remote read requests */
56 typedef struct {
57         uint8_t           value[OAL_GATT_MAX_ATTR_LEN];
58         uint16_t          handle;
59         uint16_t          offset;
60         uint16_t          len;
61         uint8_t           auth_req;
62 } oal_gatt_value_t;
63
64 /** GATT remote read request response type */
65 typedef union {
66         oal_gatt_value_t attr_value;
67         uint16_t            handle;
68 } oal_gatt_response_t;
69
70 typedef struct {
71         uint8_t  server_if;
72         uint8_t  set_scan_rsp;
73         uint8_t  include_name;
74         uint8_t  include_txpower;
75         uint16_t  appearance;
76         char*    manufacturer_data;
77         uint16_t manufacturer_data_len;
78         char*    service_data;
79         uint16_t service_data_len;
80         char*    service_uuid;
81         uint16_t service_uuid_len;
82         char*    solicit_uuid;
83         uint16_t solicit_uuid_len;
84         uint16_t min_interval;
85         uint16_t max_interval;
86         uint8_t  adv_type;
87         uint8_t  chnl_map;
88         uint16_t  tx_power;
89         uint8_t  timeout_s;
90 } oal_ble_multi_adv_param_setup_t;
91
92 typedef struct {
93         int slot_id;
94         int added_features;
95         bt_address_t* device_address;
96         char*  device_name;
97         oal_uuid_t* service_uuid;
98         int service_uuid_len;
99         oal_uuid_t* service_uuid_mask;
100         int service_uuid_mask_len;
101         oal_uuid_t* service_solicitation_uuid;
102         int  service_solicitation_uuid_len;
103         oal_uuid_t* service_solicitation_uuid_mask;
104         int service_solicitation_uuid_mask_len;
105         uint8_t* service_data;
106         int service_data_len;
107         uint8_t* service_data_mask;
108         int service_data_mask_len;
109         int manufacturer_id;
110         uint8_t* manufacturer_data;
111         int manufacturer_data_len;
112         uint8_t* manufacturer_data_mask;
113         int manufacturer_data_mask_len;
114 } oal_ble_scan_filter_t;
115
116 typedef struct {
117         int list_logic_type;   // list_logic_type (OR - 0x00, AND - 0x01)
118         int filt_logic_type;   // filt_logic_type (OR - 0x00, AND - 0x01)
119         int rssi_high_thres;
120         int rssi_low_thres;
121         int dely_mode;         // dely_mode (Immediate - 0x00, on found - 0x01, batched - 0x02)
122         int found_timeout;
123         int lost_timeout;
124         int found_timeout_cnt;
125 } oal_ble_scan_filter_param_setup_t;
126
127 /**
128  * @brief Enable Bluetooth Low Energy GATT Feature
129  *
130  * @remarks  Application will be able to advertise and scan other Low Energy devices.
131  *
132  * @return OAL_STATUS_SUCCESS on success, otherwise non-zero error value.
133  * @retval #OAL_STATUS_SUCCESS  Successful
134  *
135  * @pre OAL API must be initialized with oal_bt_init().
136  *
137  * @see  gatt_disable()
138  */
139 oal_status_t gatt_enable(void);
140
141 /**
142  * @brief Disable Bluetooth Low Energy GATT Feature
143  *
144  * @remarks  Application will not be able to advertise or scan other Low Energy devices.
145  *
146  * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
147  * @retval #OAL_STATUS_SUCCESS  Successful
148  *
149  * @pre OAL API should be enabled with gatt_enable().
150  *
151  * @see  gatt_enable()
152  */
153 oal_status_t gatt_disable(void);
154
155 /**
156  * @brief Register the GATT Server
157  *
158  * @remarks  Application will register the GATT Server
159  *
160  * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
161  * @retval #OAL_STATUS_SUCCESS  Successful
162  *
163  * @pre OAl API should be enabled with gatt_enable().
164  *
165  * @see  gatt_enable()
166  */
167 oal_status_t gatts_register(oal_uuid_t* server_uuid);
168
169 /**
170  * @brief UnRegister the GATT Server
171  *
172  * @remarks  Application will unregister the GATT Server
173  *
174  * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
175  * @retval #OAL_STATUS_SUCCESS  Successful
176  *
177  * @pre OAl API should be enabled with gatti_enable().
178  *
179  * @see  gatts_register()
180  */
181 oal_status_t gatts_unregister(int instance_id);
182
183 /**
184  * @brief Start BLE Advertising feature
185  *
186  * @remarks  Application will start advertising and behave as a peripheral device
187  *
188  * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
189  * @retval #OAL_STATUS_SUCCESS  Successful
190  *
191  * @pre OAl API should be enabled with gatt_enable().
192  *
193  * @see  gatt_enable()
194  */
195 oal_status_t gatts_start_listen(int instance_id, gboolean enable);
196
197 /**
198  * @brief Stop BLE Advertising feature
199  *
200  * @remarks  Application will stop advertising and will no longer behave as a peripheral device.
201  *
202  * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
203  * @retval #OAL_STATUS_SUCCESS  Successful
204  *
205  * @pre Advertising should have been started with gatts_start_advertising().
206  *
207  * @see  gatts_start_listen()
208  */
209 oal_status_t gatts_stop_advertising(int instance_id);
210
211 /**
212  * @brief Enables the Bluetooth Low Energy Multiple advertisement feature
213  *
214  * @remarks  The application will be able to do multiple advertising
215  *
216  * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
217  * @retval #OAL_STATUS_SUCCESS  Successful
218  *
219  * @pre OAL API must be initialized with oal_bt_init().
220  *
221  * @see  gatts_multi_adv_disable()
222  */
223 oal_status_t gatts_multi_adv_enable(int instance_id);
224
225 /**
226  * @brief Disables the Bluetooth Low Energy Multiple advertisement feature
227  *
228  * @remarks  The application will not be able to do multiple advertising
229  *
230  * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
231  * @retval #OAL_STATUS_SUCCESS  Successful
232  *
233  * @pre OAL API must be initialized with oal_bt_init().
234  *
235  * @see  gatts_multi_adv_enable()
236  */
237 oal_status_t gatts_multi_adv_disable(int instance_id);
238
239 /**
240  * @brief Updates the parameters to configure the Multiple Advertising Features
241  *
242  * @remarks  The parameters like min and max interval, advertising type,
243  * channel map, tx power and timeout will be updated.
244  *
245  * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
246  * @retval #OAL_STATUS_SUCCESS  Successful
247  *
248  * @pre OAL API should be enabled with gatts_multi_adv_enable().
249  *
250  * @see  gatts_multi_adv_enable()
251  */
252 oal_status_t gatts_multi_adv_update(int instance_id, int min_intv, int max_intv,
253                 int adv_type, int chnl_map,
254                 int tx_power, int timeout_s);
255
256 /**
257  * @brief sets the filter policy for a particular advertiser in HAL layer.
258  */
259 oal_status_t gatts_set_filter_policy(int filter_policy);
260
261 /**
262  * @brief Sets the the Multiple Advertising Data
263  *
264  * @remarks  The Multiple advertising data will be set.
265  *
266  * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
267  * @retval #OAL_STATUS_SUCCESS  Successful
268  *
269  * @pre OAL API should be enabled with gatts_multi_adv_enable().
270  *
271  * @see  gatts_multi_adv_enable()
272  */
273 oal_status_t gatts_multi_adv_set_inst_data(int instance_id,
274                 oal_ble_multi_adv_param_setup_t *adv_param_setup);
275
276 /**
277  * @brief Get current ATT MTU size of the connection
278  *
279  * @remarks  The application will get current ATT MTU size of the connection
280  *
281  * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
282  * @retval #OAL_STATUS_SUCCESS>-Successful
283  *
284  * @pre OAL API must be initialized with oal_bt_init().
285  *
286  * @param conn_id: active connection id (input)
287  * mtu: att mtu size of the connection (output)
288  *
289  * @see  gatts_multi_adv_enable()
290  */
291 oal_status_t gatts_get_att_mtu(int conn_id, int *mtu);
292
293 /**
294  * @brief GATT Server Add Service
295  *
296  * @remarks  GATT Server will add new service in gatt server database.
297  *
298  * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
299  * @retval #OAL_STATUS_SUCCESS  Successful
300  *
301  * @pre Advertising should have been started with gatts_start_advertising().
302  *
303  * @see  gatts_start_advertising()
304  */
305 oal_status_t gatts_add_service(int instance_id, oal_gatt_srvc_id_t *gatt_serv_id, int num_handles);
306
307 /**
308  * @brief GATT Server Add Included Service
309  *
310  * @remarks  GATT Server will add new included service in gatt server database.
311  *
312  * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
313  * @retval #OAL_STATUS_SUCCESS  Successful
314  *
315  * @pre Primary service should have been added with gatts_add_service().
316  *
317  * @see  gatts_add_service()
318  */
319 oal_status_t gatts_add_included_services(int instance_id, int srv_handle, int incld_handle);
320
321 /**
322  * @brief GATT Server Add Charactertistic
323  *
324  * @remarks  GATT Server will add new Charactertistic in gatt server database.
325  *
326  * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
327  * @retval #OAL_STATUS_SUCCESS  Successful
328  *
329  * @pre Primary service should have been added with gatts_add_service().
330  *
331  * @see  gatts_add_service()
332  */
333 oal_status_t gatts_add_characteristics(int instance_id, int srv_handle, oal_uuid_t* charc_uuid, int propts, int permsn);
334
335 /**
336  * @brief GATT Server Add Descriptor
337  *
338  * @remarks  GATT Server will add new Descriptor in gatt server database.
339  *
340  * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
341  * @retval #OAL_STATUS_SUCCESS  Successful
342  *
343  * @pre Primary service should have been added with gatts_add_service().
344  *
345  * @see  gatts_add_service()
346  */
347 oal_status_t gatts_add_descriptor(int instance_id, int srv_handle, oal_uuid_t* desc_uuid, int permsn);
348
349 /**
350  * @brief GATT Server make ready the new service for advertiment
351  *
352  * @remarks  GATT Server will enable the new service for advertiment.
353  *
354  * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
355  * @retval #OAL_STATUS_SUCCESS  Successful
356  *
357  * @pre Primary service should have been added with gatts_add_service().
358  *
359  * @see  gatts_add_service()
360  */
361 oal_status_t gatts_start_service(int innstance_id, int svc_handle, int transport);
362
363 /**
364  * @brief GATT Server Stop the added service from advertiment
365  *
366  * @remarks  GATT Server will Stop the added service from advertiment .
367  *
368  * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
369  * @retval #OAL_STATUS_SUCCESS  Successful
370  *
371  * @pre Primary service should have been started with gatts_start_service().
372  *
373  * @see  gatts_start_service()
374  */
375 oal_status_t gatts_stop_service(int instance_id, int svc_hdl);
376
377 /**
378  * @brief GATT Server delete the already added service
379  *
380  * @remarks  GATT Server will delete the already added service in gatt server database.
381  *
382  * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
383  * @retval #OAL_STATUS_SUCCESS  Successful
384  *
385  * @pre Primary service should have been added with gatts_add_service().
386  *
387  * @see  gatts_add_service()
388  */
389 oal_status_t gatts_delete_service(int instance_id, int svc_handle);
390
391 /**
392  * @brief GATT Server send the indication for change in attribute value
393  *
394  * @remarks  GATT Server will send the indication to client for change in attribute value .
395  *
396  * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
397  * @retval #OAL_STATUS_SUCCESS  Successful
398  *
399  * @pre A Client should be connected to this server.
400  *
401  * @see  gatts_connect()
402  */
403 oal_status_t gatts_send_indication(int ins_id, int attr_hndl, int conn_id, int len, int confirm, char* value);
404
405 /**
406  * @brief GATT Server Update value of the attribute associated with a GATT server instance
407  *
408  * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
409  * @retval #OAL_STATUS_SUCCESS  Successful
410  */
411 oal_status_t gatts_update_att_value(int ins_id, oal_gatt_value_t *value);
412
413 /**
414  * @brief GATT Server send the response for attribute value
415  *
416  * @remarks  GATT Server will send the response for attribute value asked from client .
417  *
418  * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
419  * @retval #OAL_STATUS_SUCCESS  Successful
420  *
421  * @pre A Client should be connected to this server.
422  *
423  * @see  gatts_connect()
424  */
425 oal_status_t gatts_send_response(int conn_id, int trans_id, int resp_status, oal_gatt_response_t *response);
426
427 oal_status_t gatts_disconnect(int Ins_id, bt_address_t *device_address, int conId);
428
429 /**
430  * @brief Start LE Device discovery
431  *
432  * @remarks  BLE discovery will be started
433  *
434  * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
435  * @retval #OAL_STATUS_SUCCESS  Successful
436  *
437  * @pre OAL API should be enabled with gatt_enable().
438  *
439  * @see  gatt_enable()
440  */
441 oal_status_t gattc_start_le_discovery(int client_id);
442 /**
443  * @brief Stop LE Device discovery
444  *
445  * @remarks  BLE discovery will be stopped
446  *
447  * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
448  * @retval #OAL_STATUS_SUCCESS  Successful
449  *
450  * @pre BLE Discovery should be started using the gattc_start_le_discovery().
451  *
452  * @see  gattc_start_le_discovery()
453  */
454 oal_status_t gattc_stop_le_discovery(int client_id);
455
456 /**
457  * @brief Set scan parameters
458  *
459  * @remarks  scan parameters will be set
460  *
461  * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
462  * @retval #OAL_STATUS_SUCCESS  Successful
463  *
464  */
465 oal_status_t gattc_set_le_scan_param(int scan_type, int itv, int win);
466
467 /** Registers a GATT client application with the stack */
468 oal_status_t gattc_register(oal_uuid_t* client_uuid);
469
470 oal_status_t gattc_deregister(int client_id);
471
472  /** Create a connection to a remote LE or dual-mode device */
473 oal_status_t gattc_connect(int client_id, bt_address_t *device_address, int isDirect);
474
475 oal_status_t gattc_search_service(int conn_id, oal_uuid_t *service_uuid);
476
477 oal_status_t gattc_get_characteristic(int conn_id, oal_gatt_srvc_id_t *srvc_id, oal_gatt_id_t *char_id);
478
479 oal_status_t gattc_get_descriptor(int conn_id, oal_gatt_srvc_id_t *srvc_id, oal_gatt_id_t *char_id,
480                                                         oal_gatt_id_t *desc_id);
481
482 oal_status_t gattc_read_characteristic(int conn_id, oal_gatt_srvc_id_t *srvc_id, oal_gatt_id_t *char_id,
483                                                                         oal_gatt_auth_req_t auth_req);
484
485 oal_status_t gattc_read_descriptor(int conn_id, oal_gatt_srvc_id_t *srvc_id, oal_gatt_id_t *char_id,
486                                                 oal_gatt_id_t *desc_id, oal_gatt_auth_req_t auth_req);
487 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,
488                 int len, oal_gatt_auth_req_t auth_req, char* data);
489
490 oal_status_t gattc_acquire_notify(int conn_id, oal_gatt_srvc_id_t *srvc_id,
491                 oal_gatt_id_t *char_id,  int *fd, int *mtu);
492
493 oal_status_t gattc_acquire_write(int conn_id, oal_gatt_srvc_id_t *srvc_id,
494                 oal_gatt_id_t *char_id,  oal_gatt_auth_req_t auth_req , int *fd, int*mtu);
495
496 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,
497                 oal_gatt_write_type_t write_type, int len, oal_gatt_auth_req_t auth_req, char* data);
498
499 oal_status_t gattc_disconnect(int client_id, bt_address_t *device_address, int conn_id);
500
501 oal_status_t gattc_unregister_scan_filter(int slot_id);
502
503 oal_status_t gattc_enable_scan_filter(int client_if);
504
505 oal_status_t gattc_disable_scan_filter(int client_if);
506
507 oal_status_t gattc_conn_param_update(bt_address_t * address, int min, int max, int latency, int timeout);
508
509 oal_status_t gattc_register_scan_filter(oal_ble_scan_filter_t* filter_data);
510
511 oal_status_t gattc_register_for_notification(int client_id, bt_address_t * address,
512                                 oal_gatt_srvc_id_t *srvc_id, oal_gatt_id_t *char_id);
513
514 oal_status_t gattc_deregister_for_notification(int client_id, bt_address_t * address,
515                                 oal_gatt_srvc_id_t *srvc_id, oal_gatt_id_t *char_id);
516
517 oal_status_t gatt_send_response_acquire(int conn_id, int trans_id,
518                 int status, int fd, int mtu, void *);
519
520 #endif /* OAL_GATT_H_ */