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