Apply next HAL architecture (hal api + backend)
[platform/adaptation/bluetooth-firmware-bcm.git] / src / hal-backend-bluetooth.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <stdint.h>
4 #include <errno.h>
5 #include <dlog.h>
6
7 #include <hal/hal-bluetooth-interface.h>
8
9 #undef LOG_TAG
10 #define LOG_TAG "HALAPI_BLUETOOTH"
11
12 #define EXPORT __attribute__ ((visibility("default")))
13
14 static int bluetooth_bcm_start(void)
15 {
16         int ret;
17         ret = system("/usr/etc/bluetooth/bt-stack-up.sh");
18         if (ret == 0x100) {
19                 LOGE("script internal failed");
20                 return HAL_BACKEND_ERROR_INTERNAL;
21         } else if (ret == 0x200) {
22                 LOGE("script timeout failed");
23                 return HAL_BACKEND_ERROR_TIMEOUT;
24         }
25         LOGD("script started successfully");
26         return HAL_BACKEND_ERROR_NONE;
27 }
28
29 static int bluetooth_bcm_stop(void)
30 {
31         int ret;
32         ret = system("/usr/etc/bluetooth/bt-stack-down.sh");
33         if (ret == 0x100) {
34                 LOGE("script internal failed");
35                 return HAL_BACKEND_ERROR_INTERNAL;
36         } else if (ret == 0x200) {
37                 LOGE("script timeout failed");
38                 return HAL_BACKEND_ERROR_TIMEOUT;
39         }
40         LOGD("script started successfully");
41         return HAL_BACKEND_ERROR_NONE;
42 }
43
44 static int bluetooth_bcm_init(void **data)
45 {
46         hal_backend_bluetooth_funcs *bluetooth_funcs;
47
48         bluetooth_funcs = calloc(1, sizeof(hal_backend_bluetooth_funcs));
49         if (!bluetooth_funcs)
50                 return -ENOMEM;
51
52         bluetooth_funcs->start = bluetooth_bcm_start;
53         bluetooth_funcs->stop = bluetooth_bcm_stop;
54
55         *data = (void *)bluetooth_funcs;
56
57         return 0;
58 }
59
60 static int bluetooth_bcm_exit(void *data)
61 {
62         if (!data)
63                 return -EINVAL;
64         free(data);
65
66         return 0;
67 }
68
69 hal_backend EXPORT hal_backend_bluetooth_data = {
70         .name = "bluetooth",
71         .vendor = "broadcom",
72         .abi_version = HAL_ABI_VERSION_TIZEN_6_5,
73         .init = bluetooth_bcm_init,
74         .exit = bluetooth_bcm_exit,
75 };