Merge tizen_next codes into tizen branch
[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 /** GATT value type used in response to remote read requests */
30 typedef struct {
31         uint8_t           value[OAL_GATT_MAX_ATTR_LEN];
32         uint16_t          handle;
33         uint16_t          offset;
34         uint16_t          len;
35         uint8_t           auth_req;
36 } oal_gatt_value_t;
37
38 /** GATT remote read request response type */
39 typedef union {
40         oal_gatt_value_t attr_value;
41         uint16_t            handle;
42 } oal_gatt_response_t;
43
44 typedef struct {
45         uint8_t  server_if;
46         uint8_t  set_scan_rsp;
47         uint8_t  include_name;
48         uint8_t  include_txpower;
49         uint16_t  appearance;
50         char*    manufacturer_data;
51         uint16_t manufacturer_data_len;
52         char*    service_data;
53         uint16_t service_data_len;
54         char*    service_uuid;
55         uint16_t service_uuid_len;
56         char*    solicit_uuid;
57         uint16_t solicit_uuid_len;
58         uint16_t min_interval;
59         uint16_t max_interval;
60         uint8_t  adv_type;
61         uint8_t  chnl_map;
62         uint16_t  tx_power;
63         uint8_t  timeout_s;
64 } oal_ble_multi_adv_param_setup_t;
65
66 /**
67  * @brief Enable Bluetooth Low Energy GATT Feature
68  *
69  * @remarks  Application will be able to advertise and scan other Low Energy devices.
70  *
71  * @return OAL_STATUS_SUCCESS on success, otherwise non-zero error value.
72  * @retval #OAL_STATUS_SUCCESS  Successful
73  *
74  * @pre OAL API must be initialized with oal_bt_init().
75  *
76  * @see  gatt_disable()
77  */
78 oal_status_t gatt_enable(void);
79
80 /**
81  * @brief Disable Bluetooth Low Energy GATT Feature
82  *
83  * @remarks  Application will not be able to advertise or scan other Low Energy devices.
84  *
85  * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
86  * @retval #OAL_STATUS_SUCCESS  Successful
87  *
88  * @pre OAL API should be enabled with gatt_enable().
89  *
90  * @see  gatt_enable()
91  */
92 oal_status_t gatt_disable(void);
93
94 /**
95  * @brief Register the GATT Server
96  *
97  * @remarks  Application will register the GATT Server
98  *
99  * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
100  * @retval #OAL_STATUS_SUCCESS  Successful
101  *
102  * @pre OAl API should be enabled with gatt_enable().
103  *
104  * @see  gatt_enable()
105  */
106 oal_status_t gatts_register(oal_uuid_t* server_uuid);
107
108 /**
109  * @brief UnRegister the GATT Server
110  *
111  * @remarks  Application will unregister the GATT Server
112  *
113  * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
114  * @retval #OAL_STATUS_SUCCESS  Successful
115  *
116  * @pre OAl API should be enabled with gatti_enable().
117  *
118  * @see  gatts_register()
119  */
120 oal_status_t gatts_unregister(int instance_id);
121
122 /**
123  * @brief Start BLE Advertising feature
124  *
125  * @remarks  Application will start advertising and behave as a peripheral device
126  *
127  * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
128  * @retval #OAL_STATUS_SUCCESS  Successful
129  *
130  * @pre OAl API should be enabled with gatt_enable().
131  *
132  * @see  gatt_enable()
133  */
134 oal_status_t gatts_start_listen(int instance_id, gboolean enable);
135
136 /**
137  * @brief Stop BLE Advertising feature
138  *
139  * @remarks  Application will stop advertising and will no longer behave as a peripheral device.
140  *
141  * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
142  * @retval #OAL_STATUS_SUCCESS  Successful
143  *
144  * @pre Advertising should have been started with gatts_start_advertising().
145  *
146  * @see  gatts_start_listen()
147  */
148 oal_status_t gatts_stop_advertising(int instance_id);
149
150 /**
151  * @brief Enables the Bluetooth Low Energy Multiple advertisement feature
152  *
153  * @remarks  The application will be able to do multiple advertising
154  *
155  * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
156  * @retval #OAL_STATUS_SUCCESS  Successful
157  *
158  * @pre OAL API must be initialized with oal_bt_init().
159  *
160  * @see  gatts_multi_adv_disable()
161  */
162 oal_status_t gatts_multi_adv_enable(int instance_id);
163
164 /**
165  * @brief Disables the Bluetooth Low Energy Multiple advertisement feature
166  *
167  * @remarks  The application will not be able to do multiple advertising
168  *
169  * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
170  * @retval #OAL_STATUS_SUCCESS  Successful
171  *
172  * @pre OAL API must be initialized with oal_bt_init().
173  *
174  * @see  gatts_multi_adv_enable()
175  */
176 oal_status_t gatts_multi_adv_disable(int instance_id);
177
178 /**
179  * @brief Updates the parameters to configure the Multiple Advertising Features
180  *
181  * @remarks  The parameters like min and max interval, advertising type,
182  * channel map, tx power and timeout will be updated.
183  *
184  * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
185  * @retval #OAL_STATUS_SUCCESS  Successful
186  *
187  * @pre OAL API should be enabled with gatts_multi_adv_enable().
188  *
189  * @see  gatts_multi_adv_enable()
190  */
191 oal_status_t gatts_multi_adv_update(int instance_id, int min_intv, int max_intv,
192                 int adv_type, int chnl_map,
193                 int tx_power, int timeout_s);
194
195 /**
196  * @brief Sets the the Multiple Advertising Data
197  *
198  * @remarks  The Multiple advertising data will be set.
199  *
200  * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
201  * @retval #OAL_STATUS_SUCCESS  Successful
202  *
203  * @pre OAL API should be enabled with gatts_multi_adv_enable().
204  *
205  * @see  gatts_multi_adv_enable()
206  */
207 oal_status_t gatts_multi_adv_set_inst_data(int instance_id,
208                 oal_ble_multi_adv_param_setup_t *adv_param_setup);
209
210 /**
211  * @brief Get current ATT MTU size of the connection
212  *
213  * @remarks  The application will get current ATT MTU size of the connection
214  *
215  * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
216  * @retval #OAL_STATUS_SUCCESS>-Successful
217  *
218  * @pre OAL API must be initialized with oal_bt_init().
219  *
220  * @param conn_id: active connection id (input)
221  * mtu: att mtu size of the connection (output)
222  *
223  * @see  gatts_multi_adv_enable()
224  */
225 oal_status_t gatts_get_att_mtu(int conn_id, int *mtu);
226
227 /**
228  * @brief GATT Server Add Service
229  *
230  * @remarks  GATT Server will add new service in gatt server database.
231  *
232  * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
233  * @retval #OAL_STATUS_SUCCESS  Successful
234  *
235  * @pre Advertising should have been started with gatts_start_advertising().
236  *
237  * @see  gatts_start_advertising()
238  */
239 oal_status_t gatts_add_service(int instance_id, oal_gatt_srvc_id_t *gatt_serv_id, int num_handles);
240
241 /**
242  * @brief GATT Server Add Included Service
243  *
244  * @remarks  GATT Server will add new included service in gatt server database.
245  *
246  * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
247  * @retval #OAL_STATUS_SUCCESS  Successful
248  *
249  * @pre Primary service should have been added with gatts_add_service().
250  *
251  * @see  gatts_add_service()
252  */
253 oal_status_t gatts_add_included_services(int instance_id, int srv_handle, int incld_handle);
254
255 /**
256  * @brief GATT Server Add Charactertistic
257  *
258  * @remarks  GATT Server will add new Charactertistic in gatt server database.
259  *
260  * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
261  * @retval #OAL_STATUS_SUCCESS  Successful
262  *
263  * @pre Primary service should have been added with gatts_add_service().
264  *
265  * @see  gatts_add_service()
266  */
267 oal_status_t gatts_add_characteristics(int instance_id, int srv_handle, oal_uuid_t* charc_uuid, int propts, int permsn);
268
269 /**
270  * @brief GATT Server Add Descriptor
271  *
272  * @remarks  GATT Server will add new Descriptor in gatt server database.
273  *
274  * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
275  * @retval #OAL_STATUS_SUCCESS  Successful
276  *
277  * @pre Primary service should have been added with gatts_add_service().
278  *
279  * @see  gatts_add_service()
280  */
281 oal_status_t gatts_add_descriptor(int instance_id, int srv_handle, oal_uuid_t* desc_uuid, int permsn);
282
283 /**
284  * @brief GATT Server make ready the new service for advertiment
285  *
286  * @remarks  GATT Server will enable the new service for advertiment.
287  *
288  * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
289  * @retval #OAL_STATUS_SUCCESS  Successful
290  *
291  * @pre Primary service should have been added with gatts_add_service().
292  *
293  * @see  gatts_add_service()
294  */
295 oal_status_t gatts_start_service(int innstance_id, int svc_handle, int transport);
296
297 /**
298  * @brief GATT Server Stop the added service from advertiment
299  *
300  * @remarks  GATT Server will Stop the added service from advertiment .
301  *
302  * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
303  * @retval #OAL_STATUS_SUCCESS  Successful
304  *
305  * @pre Primary service should have been started with gatts_start_service().
306  *
307  * @see  gatts_start_service()
308  */
309 oal_status_t gatts_stop_service(int instance_id, int svc_hdl);
310
311 /**
312  * @brief GATT Server delete the already added service
313  *
314  * @remarks  GATT Server will delete the already added service in gatt server database.
315  *
316  * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
317  * @retval #OAL_STATUS_SUCCESS  Successful
318  *
319  * @pre Primary service should have been added with gatts_add_service().
320  *
321  * @see  gatts_add_service()
322  */
323 oal_status_t gatts_delete_service(int instance_id, int svc_handle);
324
325 /**
326  * @brief GATT Server send the indication for change in attribute value
327  *
328  * @remarks  GATT Server will send the indication to client for change in attribute value .
329  *
330  * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
331  * @retval #OAL_STATUS_SUCCESS  Successful
332  *
333  * @pre A Client should be connected to this server.
334  *
335  * @see  gatts_connect()
336  */
337 oal_status_t gatts_send_indication(int ins_id, int attr_hndl, int conn_id, int len, int confirm, char* value);
338
339 /**
340  * @brief GATT Server Update value of the attribute associated with a GATT server instance
341  *
342  * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
343  * @retval #OAL_STATUS_SUCCESS  Successful
344  */
345 oal_status_t gatts_update_att_value(int ins_id, oal_gatt_value_t *value);
346
347 /**
348  * @brief GATT Server send the response for attribute value
349  *
350  * @remarks  GATT Server will send the response for attribute value asked from client .
351  *
352  * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
353  * @retval #OAL_STATUS_SUCCESS  Successful
354  *
355  * @pre A Client should be connected to this server.
356  *
357  * @see  gatts_connect()
358  */
359 oal_status_t gatts_send_response(int conn_id, int trans_id, int resp_status, oal_gatt_response_t *response);
360
361 /**
362  * @brief Start LE Device discovery
363  *
364  * @remarks  BLE discovery will be started
365  *
366  * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
367  * @retval #OAL_STATUS_SUCCESS  Successful
368  *
369  * @pre OAL API should be enabled with gatt_enable().
370  *
371  * @see  gatt_enable()
372  */
373 oal_status_t gattc_start_le_discovery(void);
374
375 /**
376  * @brief Stop LE Device discovery
377  *
378  * @remarks  BLE discovery will be stopped
379  *
380  * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
381  * @retval #OAL_STATUS_SUCCESS  Successful
382  *
383  * @pre BLE Discovery should be started using the gattc_start_le_discovery().
384  *
385  * @see  gattc_start_le_discovery()
386  */
387 oal_status_t gattc_stop_le_discovery(void);
388
389 /**
390  * @brief Set scan parameters
391  *
392  * @remarks  scan parameters will be set
393  *
394  * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
395  * @retval #OAL_STATUS_SUCCESS  Successful
396  *
397  */
398 oal_status_t gattc_set_le_scan_param(int scan_type, int itv, int win);
399
400 #endif /* OAL_GATT_H_ */