[Adapt]Add OAL and implement Bluez HAL lib
[platform/core/connectivity/bluetooth-frwk.git] / bt-oal / oal-adapter-mgr.c
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 #include <stdio.h>
21 #include <stdlib.h>
22 #include <dlog.h>
23 #include <string.h>
24 #include <vconf.h>
25 #include <sys/wait.h>
26
27 #include <bluetooth.h>
28
29 #include "oal-event.h"
30 #include "oal-internal.h"
31 #include "oal-manager.h"
32 #include "oal-hardware.h"
33
34 #define CHECK_MAX(max, x) (((max) > (x)) ? (x) : (max))
35
36 static const bt_interface_t * blued_api;
37
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 oal_status_t oal_mgr_init_internal(void);
44
45 static bt_callbacks_t callbacks = {
46         sizeof(callbacks),
47         NULL, /* adapter_state_changed_callback */
48         NULL, /* adapter_properties_callback */
49         NULL, /* remote_device_properties_callback */
50         NULL, /* device_found_callback */
51         NULL, /* discovery_state_changed_callback */
52         NULL, /* pin_request_callback */
53         NULL, /* ssp_request_callback */
54         NULL, /* bond_state_changed_callback */
55         NULL, /* acl_state_changed_callback */
56         NULL, /* callback_thread_event */
57         NULL, /* dut_mode_recv_callback */
58         NULL, /* le_test_mode_callback*/
59         NULL, /* energy_info_callback */
60 };
61
62 oal_status_t adapter_mgr_init(const bt_interface_t * stack_if)
63 {
64         int ret;
65         blued_api = stack_if;
66
67         ret = blued_api->init(&callbacks);
68
69         if(ret != BT_STATUS_SUCCESS) {
70                 BT_ERR("Adapter callback registration failed: [%s]", status2string(ret));
71                 blued_api->cleanup();
72                 return convert_to_oal_status(ret);
73         }
74
75         return OAL_STATUS_SUCCESS;
76 }
77
78 const bt_interface_t* adapter_get_stack_interface(void)
79 {
80         return blued_api;
81 }
82
83 void adapter_mgr_cleanup(void)
84 {
85         /* Nothing to clean yet , do not set blued_api NULL as it will be used to clean Bluedroid states */
86         BT_DBG();
87 }
88