Add service added event handling logic
[platform/core/connectivity/bluetooth-frwk.git] / bt-oal / include / oal-adapter-mgr.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_ADAPTER_MGR_H_
21 #define _OAL_ADAPTER_MGR_H_
22
23 #include <glib.h>
24 #include <sys/types.h>
25
26 #include <oal-manager.h>
27 #include <oal-gatt.h>
28
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32
33 #define OAL_BT_ADDRESS_STRING_SIZE 18
34
35
36 /**
37  * @brief Enable BT chip for usage.
38  *
39  * @remarks Other API can only be used after successful event. \n
40  *
41  * @details EVENT: OAL_EVENT_ADAPTER_ENABLED/OAL_EVENT_ADAPTER_DISABLED
42  *
43  * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
44  * @retval #OAL_STATUS_SUCCESS  Successful
45  *
46  * @pre OAL API must be initialized with oal_bt_init().
47  *
48  * @see  adapter_disable()
49  */
50 oal_status_t adapter_enable(void);
51
52
53 /**
54  * @brief Disable Adapter.
55  *
56  * @remarks  Disables the BT stack and chip. After this, no OAL API is valid except "adapter_enable()"
57  *
58  * @details EVENT: OAL_EVENT_ADAPTER_DISABLED
59  *
60  * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
61  * @retval #OAL_STATUS_SUCCESS  Successful
62  *
63  * @pre Adapter must be enabled with adapter_enable() followed by OAL_EVENT_ADAPTER_ENABLED
64  *
65  * @see  adapter_enable()
66  */
67 oal_status_t adapter_disable(void);
68
69 #ifdef TIZEN_BT_HAL
70
71 /**
72  * @brief Enable LE Mode BT chip for usage.
73  *
74  * @remarks Other API can only be used after successful event. \n
75  *
76  * @details EVENT: OAL_EVENT_LE_ENABLED/OAL_EVENT_LE_DISABLED
77  *
78  * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
79  * @retval #OAL_STATUS_SUCCESS  Successful
80  *
81  * @pre OAL API must be initialized with oal_bt_init().
82  *
83  * @see  le_disable()
84  */
85 oal_status_t le_enable(void);
86
87 /**
88  * @brief Disable LE Adapter.
89  *
90  * @remarks  Disables the LE mode in the chip. After this, no OAL API is valid except "le_enable()"
91  *
92  * @details EVENT: OAL_EVENT_LE_DISABLED
93  *
94  * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
95  * @retval #OAL_STATUS_SUCCESS  Successful
96  *
97  * @pre LE Adapter must be enabled with le_enable() followed by OAL_EVENT_LE_ENABLED
98  *
99  * @see  le_enable()
100  */
101 oal_status_t le_disable(void);
102
103
104 /**
105  * @brief init LE Adapter.
106  *
107  * @remarks  Initilizes LE Advertisement slot list
108  *
109  * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
110  * @retval #OAL_STATUS_SUCCESS  Successful
111  *
112  * @pre LE Adapter must be enabled with le_enable() followed by OAL_EVENT_LE_ENABLED
113  *
114  * @see  le_enable()
115  */
116 oal_status_t le_init(void);
117
118
119 /**
120  * @brief deinit LE Adapter.
121  *
122  * @remarks  free LE Advertisement slot list
123  *
124  * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
125  * @retval #OAL_STATUS_SUCCESS  Successful
126  *
127  * @pre LE Adapter must be enabled with le_enable() followed by OAL_EVENT_LE_ENABLED and Initilized using le_init()
128  *
129  * @see  le_enable()
130  */
131 oal_status_t le_deinit(void);
132
133 #endif
134
135 /**
136  * @brief Start Custom Discovery.
137  *
138  * @remarks  Based on discovery type, it either starts BREDR, LE or DUAL discovery in Adapter
139  *
140  * @details For each device found either OAL_EVENT_ADAPTER_INQUIRY_RESULT_BREDR_ONLY
141  *                or OAL_EVENT_ADAPTER_INQUIRY_RESULT_BLE will be generated.
142  *
143  * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
144  * @retval #OAL_STATUS_SUCCESS  Successful
145  *
146  * @see  adapter_stop_inquiry()
147  * @see  OAL_EVENT_ADAPTER_INQUIRY_STARTED
148  * @see  OAL_EVENT_ADAPTER_INQUIRY_RESULT_BREDR_ONLY
149  * @see  OAL_EVENT_ADAPTER_INQUIRY_RESULT_BLE
150  * @see  OAL_EVENT_ADAPTER_INQUIRY_FINISHED
151  */
152 oal_status_t adapter_start_custom_inquiry(discovery_type_t disc_type);
153
154
155 /**
156  * @brief Get Adapter Powered state.
157  *
158  * @remarks  It is possible that stack is up but BT hardware interface is still not enabled.
159  * Application can call this API to explicitly check for Powered state
160  *
161  * @details If API returns OAL_STATUS_FAIL, then adapter can be considered Powered Down.
162  * If API returns OAL_STATUS_SUCCESS, then application needs to check powered status. It can be either
163  * true or false depending on real status of the BT hardware.
164  *
165  * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
166  * @retval #OAL_STATUS_SUCCESS  Successful
167  *
168  */
169 oal_status_t adapter_get_powered_status(gboolean *status);
170
171 /**
172  * @brief Reset Adapter.
173  *
174  * @remarks  Disables the BT stack and chip.
175  *
176  * @details EVENT: OAL_EVENT_ADAPTER_DISABLED
177  *
178  * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
179  * @retval #OAL_STATUS_SUCCESS  Successful
180  *
181  * @see  adapter_enable()
182  */
183 oal_status_t adapter_reset(void);
184
185 /**
186  * @brief Recovers Adapter.
187  *
188  * @remarks  Disables the BT stack and chip, enables after after seconds.
189  *
190  * @details EVENT: OAL_EVENT_ADAPTER_DISABLED
191  *
192  * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
193  * @retval #OAL_STATUS_SUCCESS  Successful
194  *
195  */
196 oal_status_t adapter_recover(void);
197
198 /**
199  * @brief Start device discovery
200  *
201  * @details For each device found either OAL_EVENT_ADAPTER_INQUIRY_RESULT_BREDR_ONLY
202  *                or OAL_EVENT_ADAPTER_INQUIRY_RESULT_BLE will be generated.
203  *
204  * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
205  * @retval #OAL_STATUS_SUCCESS  Successful
206  *
207  * @pre Adapter must be enabled with adapter_enable() followed by OAL_EVENT_ADAPTER_ENABLED
208  *
209  * @see  adapter_stop_inquiry()
210  * @see  OAL_EVENT_ADAPTER_INQUIRY_STARTED
211  * @see  OAL_EVENT_ADAPTER_INQUIRY_RESULT_BREDR_ONLY
212  * @see  OAL_EVENT_ADAPTER_INQUIRY_RESULT_BLE
213  * @see  OAL_EVENT_ADAPTER_INQUIRY_FINISHED
214  */
215 oal_status_t adapter_start_inquiry(unsigned short duration);
216
217 /**
218  * @brief Stop device discovery
219  *
220  * @details OAL_EVENT_ADAPTER_INQUIRY_FINISHED will be generated by OAL
221  * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
222  * @retval #OAL_STATUS_SUCCESS  Successful
223  *
224  * @pre Discovery must be in progress by calling adapter_start_inquiry()
225  *
226  * @see  adapter_start_inquiry()
227  * @see  OAL_EVENT_ADAPTER_INQUIRY_FINISHED
228  */
229 oal_status_t adapter_stop_inquiry(void);
230
231 /**
232  * @brief Get local adapter properties
233  *
234  * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
235  * @retval #OAL_STATUS_SUCCESS  Successful
236  *
237  * @pre Adapter must be enabled with adapter_enable() followed by OAL_EVENT_ADAPTER_ENABLED
238  */
239 oal_status_t adapter_get_properties(void);
240
241 /**
242  * @brief Get local BT chip address
243  *
244  * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
245  * @retval #OAL_STATUS_SUCCESS  Successful
246  *
247  * @pre Adapter must be enabled with adapter_enable() followed by OAL_EVENT_ADAPTER_ENABLED
248  *
249  * @see OAL_EVENT_ADAPTER_PROPERTY_ADDRESS
250  */
251 oal_status_t adapter_get_address(void);
252
253 /**
254  * @brief Get local BT version
255  *
256  * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
257  * @retval #OAL_STATUS_SUCCESS  Successful
258  *
259  * @pre Adapter must be enabled with adapter_enable() followed by OAL_EVENT_ADAPTER_ENABLED
260  *
261  * @see OAL_EVENT_ADAPTER_PROPERTY_VERSION
262  */
263 oal_status_t adapter_get_version(void);
264
265 /**
266  * @brief Get local BT chip name
267  *
268  * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
269  * @retval #OAL_STATUS_SUCCESS  Successful
270  *
271  * @pre Adapter must be enabled with adapter_enable() followed by OAL_EVENT_ADAPTER_ENABLED
272  *
273  * @see OAL_EVENT_ADAPTER_PROPERTY_NAME
274  */
275 oal_status_t adapter_get_name(void);
276
277 /**
278  * @brief Set local BT chip name
279  *
280  * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
281  * @retval #OAL_STATUS_SUCCESS  Successful
282  *
283  * @pre Adapter must be enabled with adapter_enable() followed by OAL_EVENT_ADAPTER_ENABLED
284  *
285  * @see OAL_EVENT_ADAPTER_PROPERTY_NAME
286  */
287 oal_status_t adapter_set_name(char * name);
288
289 /**
290  * @brief Sets output variable to TRUE if adapter is discoverable & connectable.
291  */
292 oal_status_t adapter_is_discoverable(int *p_discoverable);
293
294 /**
295  * @brief Sets output variable to TRUE if adapter is either discoverable or connectable.
296  */
297 oal_status_t adapter_is_connectable(int *p_connectable);
298
299 /**
300  * @brief Gets the connectable state of the adapter.
301  */
302 oal_status_t adapter_get_connectable(void);
303
304 /**
305  * @brief Sets output variable to value of current discoverable timeout.
306  */
307 oal_status_t adapter_get_discoverable_timeout(int *p_timeout);
308
309 /**
310  * @brief Get List of UUIDs for services supported
311  *
312  * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
313  * @retval #OAL_STATUS_SUCCESS  Successful
314  *
315  * @pre Adapter must be enabled with adapter_enable() followed by OAL_EVENT_ADAPTER_ENABLED
316  *
317  * @see OAL_EVENT_ADAPTER_PROPERTY_SERVICES
318  */
319 oal_status_t adapter_get_service_uuids(void);
320
321 /**
322  * @brief Get list of bonded devices
323  *
324  * @remarks     A list of bt_address_t is provided in the event data.
325  *
326  * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
327  * @retval #OAL_STATUS_SUCCESS  Successful
328  *
329  * @pre Adapter must be enabled with adapter_enable() followed by OAL_EVENT_ADAPTER_ENABLED
330  *
331  * @see OAL_EVENT_ADAPTER_BONDED_DEVICE_LIST
332  */
333 oal_status_t adapter_get_bonded_devices(void);
334
335 /*
336  * @brief Set connectability of adapter
337  *
338  * @remarks     If enabled, after success event, device can connected from remote device.
339  *                      If disabled, after success event, device cannot be connected from remote device;
340  *                      neither can be found in discoveries.
341  *
342  * @details EVENT:  OAL_EVENT_ADAPTER_MODE_CONNECTABLE/OAL_EVENT_ADAPTER_MODE_NON_CONNECTABLE
343  *
344  * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
345  * @retval #OAL_STATUS_SUCCESS  Successful
346  *
347  * @pre Adapter must be enabled with adapter_enable() followed by OAL_EVENT_ADAPTER_ENABLED
348  *
349  * @see  adapter_is_connectable()
350  * @see  OAL_EVENT_ADAPTER_MODE_CONNECTABLE
351  * @see  OAL_EVENT_ADAPTER_MODE_NON_CONNECTABLE
352  */
353 oal_status_t adapter_set_connectable(int connectable);
354
355 /**
356  * @brief Make adapter discoverable
357  *
358  * @remarks  This device appears in inquiries and can be connected by remote device.
359  *
360  * @details If operation successful OAL_EVENT_ADAPTER_MODE_DISCOVERABLE is generated
361  *
362  * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
363  * @retval #OAL_STATUS_SUCCESS  Successful
364  *
365  * @pre Adapter must be enabled with adapter_enable() followed by OAL_EVENT_ADAPTER_ENABLED
366  *
367  * @see  adapter_is_discoverable()
368  * @see  OAL_EVENT_ADAPTER_MODE_DISCOVERABLE
369  */
370 oal_status_t adapter_set_discoverable(void);
371
372 /**
373  * @brief Set discoverable timeout
374  *
375  * @param timeout Timeout in seconds after which device cannot be found in discoveries
376  *
377  * @details Event  OAL_EVENT_ADAPTER_MODE_DISCOVERABLE_TIMEOUT will be generated.
378  *
379  * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
380  * @retval #OAL_STATUS_SUCCESS  Successful
381  *
382  * @pre Adapter must be enabled with adapter_enable() followed by OAL_EVENT_ADAPTER_ENABLED
383  *
384  * @see  adapter_is_discoverable()
385  * @see  OAL_EVENT_ADAPTER_MODE_DISCOVERABLE_TIMEOUT
386  */
387 oal_status_t adapter_set_discoverable_timeout(int timeout);
388
389 /**
390  * @brief Set Advertising data on specific Instance ID
391  *
392  * @param instance_id Multi advertising slot ID initialized by stack
393  *
394  * @details Event  OAL_EVENT_BLE_MULTI_ADVERTISING_SET_INST_DATA will be generated.
395  *
396  * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
397  * @retval #OAL_STATUS_SUCCESS  Successful
398  *
399  * @pre Adapter must be enabled with adapter_enable() followed by OAL_EVENT_ADAPTER_ENABLED
400  *
401  * @see  gatts_multi_adv_set_inst_data()
402  */
403 oal_status_t adapter_ble_multi_adv_set_inst_data(int instance_id, oal_ble_multi_adv_param_setup_t *adv_param_setup);
404
405 /**
406  * @brief Set Advertising parameters on specific Instance ID
407  *
408  * @param instance_id Multi advertising slot ID initialized by stack
409  *
410  * @details Event  OAL_EVENT_BLE_MULTI_ADVERTISING_UPDATE event will be generated.
411  *
412  * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
413  * @retval #OAL_STATUS_SUCCESS  Successful
414  *
415  * @pre Adapter must be enabled with adapter_enable() followed by OAL_EVENT_ADAPTER_ENABLED
416  *
417  * @see  gatts_multi_adv_set_inst_data()
418  */
419 oal_status_t adapter_ble_multi_adv_update(int Ins_id, int min_intv, int max_intv,
420                 int adv_type, int chnl_map, int tx_power, int timeout_s);
421
422 /**
423  * @brief Set Advertising filter policy for a advertiser
424  *
425  * @param filter_policy Type of policy to be used for a particular advertiser.
426  *
427  * @return OAL_STATUS_SUCCESS on success.
428  *
429  * @pre Adapter must be enabled with adapter_enable()
430  */
431 oal_status_t adapter_ble_set_filter_policy(int filter_policy);
432
433 /**
434  * @brief Enable Multi Advertising on specific Instance ID
435  *
436  * @param instance_id Multi advertising slot ID initialized by stack
437  *
438  * @details Event OAL_EVENT_BLE_MULTI_ADVERTISING_ENABLE will be generated.
439  *
440  * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
441  * @retval #OAL_STATUS_SUCCESS  Successful
442  *
443  * @pre Adapter must be enabled with adapter_enable() followed by OAL_EVENT_ADAPTER_ENABLED
444  */
445 oal_status_t adapter_ble_multi_adv_enable(int instance_id);
446
447 /**
448  * @brief Disable Multi Advertising on specific Instance ID
449  *
450  * @param instance_id Multi advertising slot ID initialized by stack
451  *
452  * @details Event OAL_EVENT_BLE_MULTI_ADVERTISING_DISABLE will be generated.
453  *
454  * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
455  * @retval #OAL_STATUS_SUCCESS  Successful
456  *
457  * @pre Adapter must be enabled with adapter_enable() followed by OAL_EVENT_ADAPTER_ENABLED
458  */
459 oal_status_t adapter_ble_multi_adv_disable(int instance_id);
460
461 oal_status_t adapter_set_le_static_random_address(int enable);
462
463 /**
464  * @brief Check if the advertising is enable
465  *
466  * @param void
467  *
468  * @details check from the LE adv list if the Advertising is enabled on the server created.
469  *
470  * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
471  * @retval #OAL_STATUS_SUCCESS  Successful
472  *
473  * @pre Adapter must be enabled with adapter_enable() followed by OAL_EVENT_ADAPTER_ENABLED
474  */
475 oal_status_t is_advertising(void);
476
477 /**
478  * @brief Add/removes device to/from whitelist
479  *
480  * @param remote device address
481  * @param remote device address type
482  * @param whether to add/remove from white list
483  *
484  * @details adds/removes device to/from controller's white list.
485  *
486  * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
487  * @retval #OAL_STATUS_SUCCESS  Successful
488  *
489  * @pre Adapter must be enabled with adapter_enable() followed by OAL_EVENT_ADAPTER_ENABLED
490  */
491 oal_status_t adapter_set_white_list(bt_address_t* device_address, int address_type, bool is_add);
492
493 /**
494  * @brief Set the privacy functionality of the adapter
495  *
496  * @param privacy mode
497  *
498  * @details Set the privacy functionality of the adaptor.
499  *
500  * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
501  * @retval #OAL_STATUS_SUCCESS  Successful
502  *
503  * @pre Adapter must be enabled with adapter_enable() followed by OAL_EVENT_ADAPTER_ENABLED
504  */
505 oal_status_t adapter_ble_set_privacy(int set_privacy);
506
507 /**
508  * @brief set the manufacturer data of the adapter
509  *
510  * @param manufacturer data
511  *
512  * @details sets the specified manufacturer data in the BT-chip
513  *
514  * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
515  * @retval #OAL_STATUS_SUCCESS  Successful
516  *
517  * @pre Adapter must be enabled with adapter_enable() followed by OAL_EVENT_ADAPTER_ENABLED
518  */
519 oal_status_t adapter_set_manufacturer_data(oal_manufacturer_data_t* m_data);
520 #ifdef __cplusplus
521 }
522 #endif /* __cplusplus */
523 #endif /*_OAL_ADAPTER_MGR_H_*/