summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDoHyun Pyun <dh79.pyun@samsung.com>2021-01-25 10:03:00 +0900
committerDoHyun Pyun <dh79.pyun@samsung.com>2021-01-25 10:04:29 +0900
commit47cf46abaa31170e2ec49b7b66b9c349655ce091 (patch)
tree2f4823acb8f0282ae35ce98a79140c45efbdc706 /src
parente1776bb4ad3ba1dce3c6c6a28adc16661affa439 (diff)
downloadbluetooth-usb-47cf46abaa31170e2ec49b7b66b9c349655ce091.tar.gz
bluetooth-usb-47cf46abaa31170e2ec49b7b66b9c349655ce091.tar.bz2
bluetooth-usb-47cf46abaa31170e2ec49b7b66b9c349655ce091.zip
Change-Id: Ia04989ec234d6eb1f9cee5b8117a354da711dc85 Signed-off-by: DoHyun Pyun <dh79.pyun@samsung.com>
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt25
-rw-r--r--src/hal-backend-bluetooth.c75
2 files changed, 100 insertions, 0 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
new file mode 100644
index 0000000..ca1fc73
--- /dev/null
+++ b/src/CMakeLists.txt
@@ -0,0 +1,25 @@
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+PROJECT(hal-backend-bluetooth C)
+
+INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/include)
+
+INCLUDE(FindPkgConfig)
+pkg_check_modules(hal-backend-bluetooth_pkgs REQUIRED
+ dlog
+ hal-api-common
+ hal-api-bluetooth
+)
+
+SET(SRCS
+ ${PROJECT_SOURCE_DIR}/${PROJECT_NAME}.c)
+
+FOREACH(flag ${hal-backend-bluetooth_pkgs_CFLAGS})
+ SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden")
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
+
+ADD_LIBRARY(${PROJECT_NAME} SHARED ${SRCS})
+TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${hal-backend-bluetooth_pkgs_LDFLAGS})
+INSTALL(TARGETS ${PROJECT_NAME} DESTINATION /hal/lib COMPONENT RuntimeLibraries)
diff --git a/src/hal-backend-bluetooth.c b/src/hal-backend-bluetooth.c
new file mode 100644
index 0000000..c293800
--- /dev/null
+++ b/src/hal-backend-bluetooth.c
@@ -0,0 +1,75 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <errno.h>
+#include <dlog.h>
+
+#include <hal/hal-bluetooth-interface.h>
+
+#undef LOG_TAG
+#define LOG_TAG "HALAPI_BLUETOOTH"
+
+#define EXPORT __attribute__ ((visibility("default")))
+
+static int bluetooth_usb_start(void)
+{
+ int ret;
+ ret = system("/usr/etc/bluetooth/bt-dev-start.sh");
+ if (ret == 0x100) {
+ LOGE("script internal failed");
+ return HAL_BACKEND_ERROR_INTERNAL;
+ } else if (ret == 0x200) {
+ LOGE("script timeout failed");
+ return HAL_BACKEND_ERROR_TIMEOUT;
+ }
+ LOGD("script started successfully");
+ return HAL_BACKEND_ERROR_NONE;
+}
+
+static int bluetooth_usb_stop(void)
+{
+ int ret;
+ ret = system("/usr/etc/bluetooth/bt-dev-end.sh");
+ if (ret == 0x100) {
+ LOGE("script internal failed");
+ return HAL_BACKEND_ERROR_INTERNAL;
+ } else if (ret == 0x200) {
+ LOGE("script timeout failed");
+ return HAL_BACKEND_ERROR_TIMEOUT;
+ }
+ LOGD("script started successfully");
+ return HAL_BACKEND_ERROR_NONE;
+}
+
+static int bluetooth_usb_init(void **data)
+{
+ hal_backend_bluetooth_funcs *bluetooth_funcs;
+
+ bluetooth_funcs = calloc(1, sizeof(hal_backend_bluetooth_funcs));
+ if (!bluetooth_funcs)
+ return -ENOMEM;
+
+ bluetooth_funcs->start = bluetooth_usb_start;
+ bluetooth_funcs->stop = bluetooth_usb_stop;
+
+ *data = (void *)bluetooth_funcs;
+
+ return 0;
+}
+
+static int bluetooth_usb_exit(void *data)
+{
+ if (!data)
+ return -EINVAL;
+ free(data);
+
+ return 0;
+}
+
+hal_backend EXPORT hal_backend_bluetooth_data = {
+ .name = "bluetooth-usb",
+ .vendor = "Usb",
+ .abi_version = HAL_ABI_VERSION_TIZEN_6_5,
+ .init = bluetooth_usb_init,
+ .exit = bluetooth_usb_exit,
+};