2 * Open Adaptation Layer (OAL)
4 * Copyright (c) 2014-2015 Samsung Electronics Co., Ltd.
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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
27 #include <bluetooth.h>
29 #include "oal-event.h"
30 #include "oal-internal.h"
31 #include "oal-manager.h"
32 #include "oal-hardware.h"
34 #define CHECK_MAX(max, x) (((max) > (x)) ? (x) : (max))
36 static const bt_interface_t * blued_api;
38 /* Forward declarations */
39 const char * status2string(bt_status_t status);
40 oal_status_t convert_to_oal_status(bt_status_t status);
41 void parse_device_properties(int num_properties, bt_property_t *properties,
42 remote_device_t *dev_info, ble_adv_data_t * adv_info);
43 static gboolean retry_enable_adapter(gpointer data);
44 oal_status_t oal_mgr_init_internal(void);
47 /* Callback registered with Stack */
48 static void cb_adapter_state_change(bt_state_t status);
50 static bt_callbacks_t callbacks = {
52 cb_adapter_state_change,
53 NULL, /* adapter_properties_callback */
54 NULL, /* remote_device_properties_callback */
55 NULL, /* device_found_callback */
56 NULL, /* discovery_state_changed_callback */
57 NULL, /* pin_request_callback */
58 NULL, /* ssp_request_callback */
59 NULL, /* bond_state_changed_callback */
60 NULL, /* acl_state_changed_callback */
61 NULL, /* callback_thread_event */
62 NULL, /* dut_mode_recv_callback */
63 NULL, /* le_test_mode_callback*/
64 NULL, /* energy_info_callback */
67 oal_status_t adapter_mgr_init(const bt_interface_t * stack_if)
72 ret = blued_api->init(&callbacks);
74 if(ret != BT_STATUS_SUCCESS) {
75 BT_ERR("Adapter callback registration failed: [%s]", status2string(ret));
77 return convert_to_oal_status(ret);
80 return OAL_STATUS_SUCCESS;
83 const bt_interface_t* adapter_get_stack_interface(void)
88 void adapter_mgr_cleanup(void)
90 /* Nothing to clean yet , do not set blued_api NULL as it will be used to clean Bluedroid states */
94 oal_status_t adapter_enable(void)
96 int ret = BT_STATUS_SUCCESS;
99 CHECK_OAL_INITIALIZED();
100 if (OAL_STATUS_SUCCESS != hw_is_module_ready()) {
101 g_timeout_add(200, retry_enable_adapter, NULL);
102 return OAL_STATUS_PENDING;
105 ret = blued_api->enable();
107 if (ret != BT_STATUS_SUCCESS) {
108 BT_ERR("Enable failed: [%s]", status2string(ret));
109 return convert_to_oal_status(ret);
112 return OAL_STATUS_SUCCESS;
115 oal_status_t adapter_disable(void)
121 CHECK_OAL_INITIALIZED();
123 ret = blued_api->disable();
125 if (ret != BT_STATUS_SUCCESS) {
126 BT_ERR("Disable failed: [%s]", status2string(ret));
127 return convert_to_oal_status(ret);
129 return OAL_STATUS_SUCCESS;
132 /* Callbacks from Stack */
133 static void cb_adapter_state_change(bt_state_t status)
138 event = (BT_STATE_ON == status)?OAL_EVENT_ADAPTER_ENABLED:OAL_EVENT_ADAPTER_DISABLED;
140 send_event(event, NULL);
143 static gboolean retry_enable_adapter(gpointer data)