Add the adaptation layer and replace functions 50/208650/3
authorDoHyun Pyun <dh79.pyun@samsung.com>
Thu, 27 Jun 2019 05:04:29 +0000 (14:04 +0900)
committerDoHyun Pyun <dh79.pyun@samsung.com>
Thu, 27 Jun 2019 05:24:11 +0000 (14:24 +0900)
This patchset is for adaptater / device / commom function.
We should add GATT adaptation function, and need to replace.

Change-Id: I7478a43c362452bcafa469cb6f8c16e7ef135ce1
Signed-off-by: DoHyun Pyun <dh79.pyun@samsung.com>
CMakeLists.txt
adaptation/bt-adatation-adapter.c [new file with mode: 0644]
adaptation/bt-adatation-common.c [new file with mode: 0644]
adaptation/bt-adatation-device.c [new file with mode: 0644]
adaptation/include/bt-adaptation-adapter.h [new file with mode: 0644]
adaptation/include/bt-adaptation-common.h [new file with mode: 0644]
adaptation/include/bt-adaptation-device.h [new file with mode: 0644]
src/bluetooth-adapter.c
src/bluetooth-common.c
src/bluetooth-device.c

index 6d28ba3bd3292e93ffcc303fdfdabd9f6e404563..f4a482f4effff406af77754943cc1109db6ae01f 100644 (file)
@@ -7,7 +7,9 @@ SET(CMAKE_INSTALL_PREFIX /usr)
 SET(PREFIX ${CMAKE_INSTALL_PREFIX})
 
 SET(INC_DIR include)
+SET(ADAPTATION_INC_DIR adaptation/include)
 INCLUDE_DIRECTORIES(${INC_DIR})
+INCLUDE_DIRECTORIES(${ADAPTATION_INC_DIR})
 
 SET(dependents "glib-2.0 bluetooth-api")
 SET(pc_dependents "glib-2.0")
@@ -32,6 +34,9 @@ SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -Wl,--rpath=${LIB_INSTALL_DIR}")
 
 
 SET(SOURCES
+adaptation/bt-adatation-common.c
+adaptation/bt-adatation-adapter.c
+adaptation/bt-adatation-device.c
 src/bluetooth-common.c
 src/bluetooth-adapter.c
 src/bluetooth-device.c
diff --git a/adaptation/bt-adatation-adapter.c b/adaptation/bt-adatation-adapter.c
new file mode 100644 (file)
index 0000000..7933f39
--- /dev/null
@@ -0,0 +1,168 @@
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *             http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include "bt-adaptation-adapter.h"
+#include "bluetooth.h"
+
+/* Need to include BT stack's header in here */
+
+int bt_adapt_get_state(bt_adapter_state_e *adapter_state)
+{
+       /* To be implemented */
+       return BT_ERROR_NONE;
+}
+
+int bt_adapt_enable(void)
+{
+       /* To be implemented */
+       return BT_ERROR_NONE;
+}
+
+int bt_adapt_disable(void)
+{
+       /* To be implemented */
+       return BT_ERROR_NONE;
+}
+
+int bt_adapt_get_local_address(char **address)
+{
+       /* To be implemented */
+       return BT_ERROR_NONE;
+}
+
+int bt_adapt_get_local_name(char **name)
+{
+       /* To be implemented */
+       return BT_ERROR_NONE;
+}
+
+int bt_adapt_set_local_name(const char *name)
+{
+       /* To be implemented */
+       return BT_ERROR_NONE;
+}
+
+int bt_adapt_get_discoverable_mode(bt_adapter_visibility_mode_e *mode)
+{
+       /* To be implemented */
+       return BT_ERROR_NONE;
+}
+
+int bt_adapt_set_discoverable_mode(bt_adapter_visibility_mode_e mode)
+{
+       /* To be implemented */
+       return BT_ERROR_NONE;
+}
+
+int bt_adapt_start_discovery(void)
+{
+       /* To be implemented */
+       return BT_ERROR_NONE;
+}
+
+int bt_adapt_stop_discovery(void)
+{
+       /* To be implemented */
+       return BT_ERROR_NONE;
+}
+
+int bt_adapt_is_discovering(bool *is_discovering)
+{
+       /* To be implemented */
+       return BT_ERROR_NONE;
+}
+
+int bt_adapt_is_connectable(bool *is_connectable)
+{
+       /* To be implemented */
+       return BT_ERROR_NONE;
+}
+
+int bt_adapt_set_connectable(bool is_connectable)
+{
+       /* To be implemented */
+       return BT_ERROR_NONE;
+}
+
+int bt_adapt_get_bonded_device_list(GPtrArray **dev_list)
+{
+       /* To be implemented */
+       return BT_ERROR_NONE;
+}
+
+int bt_adapt_start_le_scan(void)
+{
+       /* To be implemented */
+       return BT_ERROR_NONE;
+}
+
+int bt_adapt_stop_le_scan(void)
+{
+       /* To be implemented */
+       return BT_ERROR_NONE;
+}
+
+int bt_adapt_is_le_scanning(bool *is_scanning)
+{
+       /* To be implemented */
+       return BT_ERROR_NONE;
+}
+
+int bt_adapt_start_adv(int handle, int interval_min,
+                               int interval_max, unsigned int filter_policy,
+                               unsigned int type)
+{
+       /* To be implemented */
+       return BT_ERROR_NONE;
+}
+
+int bt_adapt_stop_adv(int handle)
+{
+       /* To be implemented */
+       return BT_ERROR_NONE;
+}
+
+int bt_adapt_is_adv(bool *is_advertising)
+{
+       /* To be implemented */
+       return BT_ERROR_NONE;
+}
+
+int bt_adapt_set_adv_data(int handle, const char *data, int len)
+{
+       /* To be implemented */
+       return BT_ERROR_NONE;
+}
+
+int bt_adapt_set_scan_res_data(int handle, const char *data, int len)
+{
+       /* To be implemented */
+       return BT_ERROR_NONE;
+}
+
+/*
+       int type;  < passive 0, active 1 >
+       float interval;  < LE scan interval >
+       float window;  < LE scan window >
+*/
+int bt_adapt_set_scan_params(  int type, unsigned int interval,
+                               unsigned int window)
+{
+       /* To be implemented */
+       return BT_ERROR_NONE;
+}
+
diff --git a/adaptation/bt-adatation-common.c b/adaptation/bt-adatation-common.c
new file mode 100644 (file)
index 0000000..e5e092e
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *             http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include "bt-adaptation-adapter.h"
+#include "bluetooth.h"
+
+/* Need to include BT stack's header in here */
+
+int bt_adapt_init(void)
+{
+       /* To be implemented */
+       return BT_ERROR_NONE;
+}
+
+int bt_adapt_deinit(void)
+{
+       /* To be implemented */
+       return BT_ERROR_NONE;
+}
+
diff --git a/adaptation/bt-adatation-device.c b/adaptation/bt-adatation-device.c
new file mode 100644 (file)
index 0000000..0c599b6
--- /dev/null
@@ -0,0 +1,89 @@
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *             http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <stdbool.h>
+
+#include "bt-adaptation-device.h"
+#include "bluetooth.h"
+
+/* Need to include BT stack's header in here */
+
+int bt_adapt_bond_device(const char *device_address)
+{
+       /* To be implemented */
+       return BT_ERROR_NONE;
+}
+
+int bt_adapt_unbond_device(const char *device_address)
+{
+       /* To be implemented */
+       return BT_ERROR_NONE;
+}
+
+int bt_adapt_get_bonded_device(const char *device_address,
+                                             bt_device_info_s *device_info)
+{
+       /* To be implemented */
+       return BT_ERROR_NONE;
+}
+
+int bt_adapt_is_device_connected(const char *device_address,
+                               bt_profile_e bt_profile,
+                               bool *is_connected)
+{
+       /* To be implemented */
+       return BT_ERROR_NONE;
+}
+
+int bt_adapt_connect_le(const char *device_address)
+{
+       /* To be implemented */
+       return BT_ERROR_NONE;
+}
+
+int bt_adapt_disconnect_le(const char *device_address)
+{
+       /* To be implemented */
+       return BT_ERROR_NONE;
+}
+
+int bt_adapt_le_conn_update(const char *device_address,
+                               const bt_le_conn_update_s *parameters)
+{
+       /* To be implemented */
+       return BT_ERROR_NONE;
+}
+
+int bt_adapt_update_le_connection_mode(const char *device_address,
+                               bt_device_le_connection_mode_e mode)
+{
+       /* To be implemented */
+       return BT_ERROR_NONE;
+}
+
+int bt_adapt_request_att_mtu(const char *device_address, unsigned int mtu)
+{
+       /* To be implemented */
+       return BT_ERROR_NONE;
+}
+
+int bt_adapt_get_att_mtu(const char *device_address, unsigned int *mtu)
+{
+       /* To be implemented */
+       return BT_ERROR_NONE;
+}
+
diff --git a/adaptation/include/bt-adaptation-adapter.h b/adaptation/include/bt-adaptation-adapter.h
new file mode 100644 (file)
index 0000000..1452dfa
--- /dev/null
@@ -0,0 +1,89 @@
+/*
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+#ifndef __BT_ADAPTATION_ADAPTER_H__
+#define __BT_ADAPTATION_ADAPTER_H__
+
+#include <glib.h>
+
+#include "bluetooth_type.h"
+#include "bluetooth_type_internal.h"
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif /* __cplusplus */
+
+int bt_adapt_get_state(bt_adapter_state_e *adapter_state);
+
+int bt_adapt_enable(void);
+
+int bt_adapt_disable(void);
+
+int bt_adapt_get_local_address(char **address);
+
+int bt_adapt_get_local_name(char **name);
+
+int bt_adapt_set_local_name(const char *name);
+
+int bt_adapt_get_discoverable_mode(bt_adapter_visibility_mode_e *mode);
+
+int bt_adapt_set_discoverable_mode(bt_adapter_visibility_mode_e mode);
+
+int bt_adapt_start_discovery(void);
+
+int bt_adapt_stop_discovery(void);
+
+int bt_adapt_is_discovering(bool *is_discovering);
+
+int bt_adapt_is_connectable(bool *is_connectable);
+
+int bt_adapt_set_connectable(bool is_connectable);
+
+int bt_adapt_get_bonded_device_list(GPtrArray **dev_list);
+
+int bt_adapt_start_le_scan(void);
+
+int bt_adapt_stop_le_scan(void);
+
+int bt_adapt_is_le_scanning(bool *is_scanning);
+
+int bt_adapt_start_adv(int handle, int interval_min,
+                               int interval_max, unsigned int filter_policy,
+                               unsigned int type);
+
+int bt_adapt_stop_adv(int handle);
+
+int bt_adapt_is_adv(bool *is_advertising);
+
+int bt_adapt_set_adv_data(int handle, const char *data, int len);
+
+int bt_adapt_set_scan_res_data(int handle, const char *data, int len);
+
+/*
+       int type;  < passive 0, active 1 >
+       float interval;  < LE scan interval >
+       float window;  < LE scan window >
+*/
+int bt_adapt_set_scan_params(  int type, unsigned int interval,
+                               unsigned int window);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* __BT_ADAPTATION_ADAPTER_H__ */
diff --git a/adaptation/include/bt-adaptation-common.h b/adaptation/include/bt-adaptation-common.h
new file mode 100644 (file)
index 0000000..b654f77
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+#ifndef __BT_ADAPTATION_COMMON_H__
+#define __BT_ADAPTATION_COMMON_H__
+
+#include "bluetooth_type.h"
+#include "bluetooth_type_internal.h"
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif /* __cplusplus */
+
+#define BT_UUID_STR_MAX 50
+#define BT_ADDR_STR_MAX 18
+
+int bt_adapt_init(void);
+
+int bt_adapt_deinit(void);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* __BT_ADAPTATION_COMMON_H__ */
diff --git a/adaptation/include/bt-adaptation-device.h b/adaptation/include/bt-adaptation-device.h
new file mode 100644 (file)
index 0000000..742fc0e
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+#ifndef __BT_ADAPTATION_DEVICE_H__
+#define __BT_ADAPTATION_DEVICE_H__
+
+#include "bluetooth_type.h"
+#include "bluetooth_type_internal.h"
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif /* __cplusplus */
+
+int bt_adapt_bond_device(const char *device_address);
+
+int bt_adapt_unbond_device(const char *device_address);
+
+int bt_adapt_get_bonded_device(const char *device_address,
+                                             bt_device_info_s *device_info);
+
+int bt_adapt_is_device_connected(const char *device_address,
+                               bt_profile_e bt_profile,
+                               bool *is_connected);
+
+int bt_adapt_connect_le(const char *device_address);
+
+int bt_adapt_disconnect_le(const char *device_address);
+
+int bt_adapt_le_conn_update(const char *device_address,
+                               const bt_le_conn_update_s *parameters);
+
+int bt_adapt_update_le_connection_mode(const char *device_address,
+                               bt_device_le_connection_mode_e mode);
+
+int bt_adapt_request_att_mtu(const char *device_address, unsigned int mtu);
+
+int bt_adapt_get_att_mtu(const char *device_address, unsigned int *mtu);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* __BT_ADAPTATION_DEVICE_H__ */
index 25b26ed688fe7b2711af39225036562646782194..925ac48ff4a8974f14f1ddd818b23955311a0687 100644 (file)
 #include <stdio.h>
 #include <stdbool.h>
 #include <arpa/inet.h>
-#include <bluetooth-api.h>
+
+#include "bt-adaptation-adapter.h"
+#include "bt-adaptation-device.h"
 
 #include "bluetooth.h"
 #include "bluetooth_internal.h"
 #include "bluetooth_private.h"
 
+#define BT_NAME_LEN_MAX 248
+#define BT_ADDR_STR_LEN 18 /**< This specifies BT device address length (AA:BB:CC:DD:EE:FF) */
+
 #define BT_CHECK_LE_SUPPORT() \
 { \
        BT_CHECK_SUPPORTED_FEATURE(BT_FEATURE_COMMON); \
@@ -48,7 +53,7 @@ int bt_adapter_enable(void)
 
        BT_CHECK_SUPPORTED_FEATURE(BT_FEATURE_COMMON);
        BT_CHECK_INIT_STATUS();
-       error_code = _bt_get_error_code(bluetooth_enable_adapter());
+       error_code = bt_adapt_enable();
        if (error_code != BT_ERROR_NONE) { /* LCOV_EXCL_LINE */
                BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error_code),
                                        error_code); /* LCOV_EXCL_LINE */
@@ -62,7 +67,7 @@ int bt_adapter_disable(void)
 
        BT_CHECK_SUPPORTED_FEATURE(BT_FEATURE_COMMON);
        BT_CHECK_INIT_STATUS();
-       error_code = _bt_get_error_code(bluetooth_disable_adapter());
+       error_code = bt_adapt_disable();
        if (error_code != BT_ERROR_NONE) { /* LCOV_EXCL_LINE */
                BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error_code),
                                        error_code); /* LCOV_EXCL_LINE */
@@ -87,8 +92,7 @@ int bt_adapter_get_state(bt_adapter_state_e *adapter_state)
        BT_CHECK_INIT_STATUS();
        BT_CHECK_INPUT_PARAMETER(adapter_state);
 
-       *adapter_state = bluetooth_check_adapter();
-       return BT_ERROR_NONE;
+       return bt_adapt_get_state(adapter_state);
 }
 
 /* LCOV_EXCL_START */
@@ -110,22 +114,17 @@ int bt_adapter_le_get_state(bt_adapter_le_state_e *adapter_le_state)
 
 int bt_adapter_get_address(char **address)
 {
-       bluetooth_device_address_t loc_address = { {0} };
        int error_code = BT_ERROR_NONE;
 
        BT_CHECK_SUPPORTED_FEATURE(BT_FEATURE_COMMON);
        BT_CHECK_INIT_STATUS();
-       BT_CHECK_INPUT_PARAMETER(address);
 
-       error_code = _bt_get_error_code(bluetooth_get_local_address(&loc_address));
-       if (error_code != BT_ERROR_NONE) { /* LCOV_EXCL_LINE */
-               BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error_code), /* LCOV_EXCL_LINE */
-                                       error_code); /* LCOV_EXCL_LINE */
-               return error_code; /* LCOV_EXCL_LINE */
-       }
+       *address = g_malloc0(BT_ADDR_STR_LEN * sizeof(char));
 
-       error_code = _bt_convert_address_to_string(address, &loc_address);
+       error_code = bt_adapt_get_local_address(address);
        if (error_code != BT_ERROR_NONE) { /* LCOV_EXCL_LINE */
+               g_free(*address);
+               *address = NULL;
                BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error_code), /* LCOV_EXCL_LINE */
                                        error_code); /* LCOV_EXCL_LINE */
                return error_code; /* LCOV_EXCL_LINE */
@@ -141,10 +140,6 @@ int bt_adapter_get_version(char **version)
 }
 /* LCOV_EXCL_STOP */
 
-#define BT_ADAPTER_FIRMWARE_INFO_FILE_PATH "/var/lib/bluetooth/bcmtool_log"
-#define BT_ADAPTER_STACK_INFO_FILE_PATH "/usr/etc/bluetooth/stack_info"
-#define BT_ADAPTER_MAX_BUFFER_SIZE (32767 * 1000)
-
 /* LCOV_EXCL_START */
 int bt_adapter_get_local_info(char **chipset, char **firmware,
                        char **stack_version, char **profiles)
@@ -156,42 +151,34 @@ int bt_adapter_get_local_info(char **chipset, char **firmware,
 int bt_adapter_get_name(char **name)
 {
        int ret = BT_ERROR_NONE;
-       bluetooth_device_name_t loc_name = { {0} };
 
        BT_CHECK_SUPPORTED_FEATURE(BT_FEATURE_COMMON);
        BT_CHECK_INIT_STATUS();
-       BT_CHECK_INPUT_PARAMETER(name);
 
-       ret = _bt_get_error_code(bluetooth_get_local_name(&loc_name));
+       *name = g_malloc0(BT_ADDR_STR_LEN * sizeof(char));
+
+       ret = bt_adapt_get_local_name(name);
        if (ret != BT_ERROR_NONE) { /* LCOV_EXCL_LINE */
+               g_free(*name);
+               *name = NULL;
+
                BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), /* LCOV_EXCL_LINE */
                                                ret); /* LCOV_EXCL_LINE */
                return ret; /* LCOV_EXCL_LINE */
        }
 
-       *name = strdup(loc_name.name);
-       if (*name == NULL) {
-               BT_ERR("OUT_OF_MEMORY(0x%08x)", /* LCOV_EXCL_LINE */
-                               BT_ERROR_OUT_OF_MEMORY); /* LCOV_EXCL_LINE */
-               return BT_ERROR_OUT_OF_MEMORY;
-       }
-
        return BT_ERROR_NONE;
 }
 
 int bt_adapter_set_name(const char *name)
 {
-       bluetooth_device_name_t loc_name = { {0} };
        int ret = BT_ERROR_NONE;
 
        BT_CHECK_SUPPORTED_FEATURE(BT_FEATURE_COMMON);
        BT_CHECK_INIT_STATUS();
        BT_CHECK_INPUT_PARAMETER(name);
 
-       strncpy(loc_name.name, name, BLUETOOTH_DEVICE_NAME_LENGTH_MAX);
-       loc_name.name[BLUETOOTH_DEVICE_NAME_LENGTH_MAX] = '\0';
-
-       ret = _bt_get_error_code(bluetooth_set_local_name(&loc_name));
+       ret = bt_adapt_set_local_name(name);
        if (ret != BT_ERROR_NONE) { /* LCOV_EXCL_LINE */
                BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), /* LCOV_EXCL_LINE */
                                                ret); /* LCOV_EXCL_LINE */
@@ -203,34 +190,21 @@ int bt_adapter_set_name(const char *name)
 /* LCOV_EXCL_START */
 int bt_adapter_get_visibility(bt_adapter_visibility_mode_e *mode, int *duration)
 {
-       bluetooth_discoverable_mode_t discoverable_mode = BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE;
        int ret = BT_ERROR_NONE;
 
        BT_CHECK_SUPPORTED_FEATURE(BT_FEATURE_COMMON);
        BT_CHECK_INIT_STATUS();
        BT_CHECK_INPUT_PARAMETER(mode);
 
-       ret = _bt_get_error_code(bluetooth_get_discoverable_mode(&discoverable_mode));
+       ret = bt_adapt_get_discoverable_mode(mode);
        if (ret != BT_ERROR_NONE) { /* LCOV_EXCL_LINE */
                BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret),
                                                ret); /* LCOV_EXCL_LINE */
                return ret; /* LCOV_EXCL_LINE */
        }
 
-       *mode = _bt_get_bt_visibility_mode_e(discoverable_mode);
-
-       if (duration)
-               *duration = 0;
-
-       if (discoverable_mode == BLUETOOTH_DISCOVERABLE_MODE_TIME_LIMITED_DISCOVERABLE) {
-               if (duration == NULL)
-                       return BT_ERROR_NONE;
-               ret = bluetooth_get_timeout_value(duration);
-               if (ret != BT_ERROR_NONE) { /* LCOV_EXCL_LINE */
-                       BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret),
-                                               ret); /* LCOV_EXCL_LINE */
-               } /* LCOV_EXCL_LINE */
-       }
+       /* Not support BLUETOOTH_DISCOVERABLE_MODE_TIME_LIMITED_DISCOVERABLE */
+       *duration = 0;
 
        return ret;
 }
@@ -238,30 +212,17 @@ int bt_adapter_get_visibility(bt_adapter_visibility_mode_e *mode, int *duration)
 int bt_adapter_set_visibility(bt_adapter_visibility_mode_e visibility_mode,
                                                        int timeout_sec)
 {
-       bluetooth_discoverable_mode_t discoverable_mode = BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE;
        int error_code = BT_ERROR_NONE;
 
        BT_CHECK_SUPPORTED_FEATURE(BT_FEATURE_COMMON);
        BT_CHECK_INIT_STATUS();
-       switch (visibility_mode) {
-       case BT_ADAPTER_VISIBILITY_MODE_LIMITED_DISCOVERABLE:
-               discoverable_mode = BLUETOOTH_DISCOVERABLE_MODE_TIME_LIMITED_DISCOVERABLE;
-               break;
-       case BT_ADAPTER_VISIBILITY_MODE_NON_DISCOVERABLE:
-               discoverable_mode = BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE;
-               timeout_sec = 0;
-               break;
-       case BT_ADAPTER_VISIBILITY_MODE_GENERAL_DISCOVERABLE:
-               discoverable_mode = BLUETOOTH_DISCOVERABLE_MODE_GENERAL_DISCOVERABLE;
-               timeout_sec = 0;
-               break;
-       default:
-               BT_ERR("INVALID_PARAMETER(0x%08x)", BT_ERROR_INVALID_PARAMETER);
-               return BT_ERROR_INVALID_PARAMETER;
+
+       if (visibility_mode == BT_ADAPTER_VISIBILITY_MODE_LIMITED_DISCOVERABLE) {
+               /* Not support BLUETOOTH_DISCOVERABLE_MODE_TIME_LIMITED_DISCOVERABLE */
+               return BT_ERROR_NOT_SUPPORTED;
        }
 
-       error_code = _bt_get_error_code(bluetooth_set_discoverable_mode(
-                                       discoverable_mode, timeout_sec));
+       error_code = bt_adapt_set_discoverable_mode(visibility_mode);
        if (error_code != BT_ERROR_NONE) { /* LCOV_EXCL_LINE */
                BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error_code),
                                        error_code); /* LCOV_EXCL_LINE */
@@ -290,21 +251,18 @@ int bt_adapter_unset_connectable_changed_cb(void)
 
 int bt_adapter_get_connectable(bool *connectable)
 {
-       gboolean is_connectable = FALSE;
        int ret = BT_ERROR_NONE;
 
        BT_CHECK_SUPPORTED_FEATURE(BT_FEATURE_COMMON);
        BT_CHECK_INIT_STATUS();
        BT_CHECK_INPUT_PARAMETER(connectable);
 
-       ret = _bt_get_error_code(bluetooth_is_connectable(&is_connectable));
+       ret = bt_adapt_is_connectable(connectable);
        if (ret != BT_ERROR_NONE) {
                BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret);
                return ret;
        }
 
-       *connectable = is_connectable ? true : false;
-
        return BT_ERROR_NONE;
 }
 
@@ -315,7 +273,7 @@ int bt_adapter_set_connectable(bool connectable)
        BT_CHECK_SUPPORTED_FEATURE(BT_FEATURE_COMMON);
        BT_CHECK_INIT_STATUS();
 
-       error_code = _bt_get_error_code(bluetooth_set_connectable(connectable));
+       error_code = bt_adapt_set_connectable(connectable);
        if (error_code != BT_ERROR_NONE) { /* LCOV_EXCL_LINE */
                BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error_code),
                                        error_code); /* LCOV_EXCL_LINE */
@@ -330,7 +288,6 @@ int bt_adapter_foreach_bonded_device(bt_adapter_bonded_device_cb foreach_cb,
 {
        GPtrArray *dev_list = NULL;
        bt_device_info_s *dev_info = NULL;
-       bluetooth_device_info_t *ptr = NULL;
        int ret = BT_ERROR_NONE;
        int i = 0;
 
@@ -345,7 +302,7 @@ int bt_adapter_foreach_bonded_device(bt_adapter_bonded_device_cb foreach_cb,
                return BT_ERROR_OUT_OF_MEMORY;
        }
 
-       ret = _bt_get_error_code(bluetooth_get_bonded_device_list(&dev_list));
+       ret = bt_adapt_get_bonded_device_list(&dev_list);
        if (ret != BT_ERROR_NONE) {
                BT_ERR("%s(0x%08x) : Failed to get bonded device list", /* LCOV_EXCL_LINE */
                _bt_convert_error_to_string(ret), ret); /* LCOV_EXCL_LINE */
@@ -354,22 +311,10 @@ int bt_adapter_foreach_bonded_device(bt_adapter_bonded_device_cb foreach_cb,
        }
 
        for (i = 0; i < dev_list->len; i++) { /* LCOV_EXCL_LINE */
-               ptr = g_ptr_array_index(dev_list, i);
-               if (ptr != NULL) {
-                       ret = _bt_get_bt_device_info_s(&dev_info,
-                                       (bluetooth_device_info_t *)ptr);
-                       if (ret != BT_ERROR_NONE) {
-                               BT_ERR("%s(0x%08x) : Failed to get device info", /* LCOV_EXCL_LINE */
-                                       _bt_convert_error_to_string(ret),
-                                       ret); /* LCOV_EXCL_LINE */
+               dev_info = g_ptr_array_index(dev_list, i);
+               if (dev_info != NULL) {
+                       if (!foreach_cb(dev_info, user_data))
                                break;
-                       }
-
-                       if (!foreach_cb(dev_info, user_data)) {
-                               _bt_free_bt_device_info_s(dev_info);
-                               break;
-                       }
-                       _bt_free_bt_device_info_s(dev_info); /* LCOV_EXCL_LINE */
                } else {
                        BT_ERR("OPERATION_FAILED(0x%08x)", /* LCOV_EXCL_LINE */
                        BT_ERROR_OPERATION_FAILED); /* LCOV_EXCL_LINE */
@@ -388,35 +333,22 @@ int bt_adapter_get_bonded_device_info(const char *remote_address,
                                        bt_device_info_s **device_info)
 {
        int ret;
-       bluetooth_device_address_t addr_hex = { {0,} };
-       bluetooth_device_info_t *info;
 
        BT_CHECK_SUPPORTED_FEATURE(BT_FEATURE_COMMON);
        BT_CHECK_INIT_STATUS();
        BT_CHECK_INPUT_PARAMETER(remote_address); /* LCOV_EXCL_START */
 
-       info = (bluetooth_device_info_t *)malloc(sizeof(bluetooth_device_info_t));
-       if (info == NULL)
-               return BT_ERROR_OUT_OF_MEMORY;
-
-       _bt_convert_address_to_hex(&addr_hex, remote_address);
-
-       ret = _bt_get_error_code(bluetooth_get_bonded_device(&addr_hex, info));
+       *device_info = (bt_device_info_s *)g_malloc0(sizeof(bt_device_info_s));
+       ret = bt_adapt_get_bonded_device(remote_address, *device_info);
        if (ret != BT_ERROR_NONE) {
+               g_free(*device_info);
+               *device_info = NULL;
+
                BT_ERR("%s(0x%08x) : Failed to run function",
                                _bt_convert_error_to_string(ret),
                                ret);
-       } else {
-               ret = _bt_get_bt_device_info_s(device_info, info);
-               if (ret != BT_ERROR_NONE) {
-                       BT_ERR("%s(0x%08x) : Failed to get device info",
-                                       _bt_convert_error_to_string(ret),
-                                       ret);
-               }
        }
 
-       free(info);
-
        return ret; /* LCOV_EXCL_STOP */
 }
 
@@ -533,8 +465,7 @@ int bt_adapter_start_device_discovery(void)
 
        BT_CHECK_SUPPORTED_FEATURE(BT_FEATURE_COMMON);
        BT_CHECK_INIT_STATUS();
-       error_code = _bt_get_error_code(bluetooth_start_discovery(0, 0,
-                                       BLUETOOTH_DEVICE_MAJOR_MASK_MISC));
+       error_code = bt_adapt_start_discovery();
        if (error_code != BT_ERROR_NONE) { /* LCOV_EXCL_LINE */
                BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error_code),
                                        error_code); /* LCOV_EXCL_LINE */
@@ -548,7 +479,7 @@ int bt_adapter_stop_device_discovery(void)
 
        BT_CHECK_SUPPORTED_FEATURE(BT_FEATURE_COMMON);
        BT_CHECK_INIT_STATUS();
-       error_code = _bt_get_error_code(bluetooth_cancel_discovery());
+       error_code = bt_adapt_stop_discovery();
        if (error_code != BT_ERROR_NONE) { /* LCOV_EXCL_LINE */
                BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error_code),
                                        error_code); /* LCOV_EXCL_LINE */
@@ -558,42 +489,36 @@ int bt_adapter_stop_device_discovery(void)
 
 int bt_adapter_is_discovering(bool *is_discovering)
 {
-       int ret = 0;
+       int ret = BT_ERROR_NONE;
 
        BT_CHECK_SUPPORTED_FEATURE(BT_FEATURE_COMMON);
        BT_CHECK_INIT_STATUS();
        BT_CHECK_INPUT_PARAMETER(is_discovering);
 
-       ret = bluetooth_is_discovering();
-       if (ret >= BLUETOOTH_ERROR_BASE) {
-               *is_discovering = (ret == 1) ? true : false;
-               return BT_ERROR_NONE;
-       } else {
-               ret = _bt_get_error_code(ret); /* LCOV_EXCL_LINE */
+       ret = bt_adapt_is_discovering(is_discovering);
+       if (ret != BT_ERROR_NONE) {
                BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret),
                                                ret); /* LCOV_EXCL_LINE */
-               return ret; /* LCOV_EXCL_LINE */
        }
+
+       return ret;
 }
 
 int bt_adapter_le_is_discovering(bool *is_discovering)
 {
-       int ret = 0;
+       int ret = BT_ERROR_NONE;
 
        BT_CHECK_LE_SUPPORT();
        BT_CHECK_INIT_STATUS();
        BT_CHECK_INPUT_PARAMETER(is_discovering);
 
-       ret = bluetooth_is_le_discovering();
-       if (ret >= BLUETOOTH_ERROR_BASE) {
-               *is_discovering = (ret == 1) ? true : false;
-               return BT_ERROR_NONE;
-       } else {
-               ret = _bt_get_error_code(ret); /* LCOV_EXCL_LINE */
+       ret = bt_adapt_is_le_scanning(is_discovering);
+       if (ret != BT_ERROR_NONE) {
                BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret),
                                                ret); /* LCOV_EXCL_LINE */
-               return ret; /* LCOV_EXCL_LINE */
        }
+
+       return ret;
 }
 
 int bt_adapter_get_local_oob_data(unsigned char **hash,
@@ -698,26 +623,28 @@ int bt_adapter_le_remove_white_list(const char *address, bt_device_address_type_
 int bt_adapter_le_set_scan_mode(bt_adapter_le_scan_mode_e scan_mode)
 {
        int ret = BT_ERROR_NONE;
-       bluetooth_le_scan_params_t scan_params;
+       int type;
+       unsigned int interval;
+       unsigned int window;
 
        BT_CHECK_LE_SUPPORT();
        BT_CHECK_INIT_STATUS();
 
-       scan_params.type = BT_ADAPTER_LE_ACTIVE_SCAN;
+       type = BT_ADAPTER_LE_ACTIVE_SCAN;
 
        if (scan_mode == BT_ADAPTER_LE_SCAN_MODE_BALANCED) {
-               scan_params.interval = 5000;
-               scan_params.window = 2000;
+               interval = 5000;
+               window = 2000;
        } else if (scan_mode == BT_ADAPTER_LE_SCAN_MODE_LOW_LATENCY) {
-               scan_params.interval = 5000;
-               scan_params.window = 5000;
+               interval = 5000;
+               window = 5000;
        } else if (scan_mode == BT_ADAPTER_LE_SCAN_MODE_LOW_ENERGY) {
-               scan_params.interval = 5000;
-               scan_params.window = 500;
+               interval = 5000;
+               window = 500;
        } else
                return BT_ERROR_INVALID_PARAMETER;
 
-       ret = _bt_get_error_code(bluetooth_set_scan_parameters(&scan_params));
+       ret = bt_adapt_set_scan_params(type, interval, window);
        if (ret != BT_ERROR_NONE) { /* LCOV_EXCL_LINE */
                BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret),
                                                ret); /* LCOV_EXCL_LINE */
@@ -729,15 +656,17 @@ int bt_adapter_le_set_scan_mode(bt_adapter_le_scan_mode_e scan_mode)
 int bt_adapter_le_set_customized_scan_mode(float scan_interval, float scan_window)
 {
        int ret = BT_ERROR_NONE;
-       bluetooth_le_scan_params_t scan_params;
+       int type;
+       unsigned int interval;
+       unsigned int window;
 
        BT_CHECK_INIT_STATUS();
 
-       scan_params.type = BT_ADAPTER_LE_ACTIVE_SCAN;
-       scan_params.interval = scan_interval;
-       scan_params.window = scan_window;
+       type = BT_ADAPTER_LE_ACTIVE_SCAN;
+       interval = (unsigned int)scan_interval;
+       window = (unsigned int)scan_window;
 
-       ret = _bt_get_error_code(bluetooth_set_scan_parameters(&scan_params));
+       ret = bt_adapt_set_scan_params(type, interval, window);
        if (ret != BT_ERROR_NONE)
                BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret);
 
@@ -766,8 +695,7 @@ int bt_adapter_le_create_advertiser(bt_advertiser_h *advertiser)
 int bt_adapter_le_destroy_advertiser(bt_advertiser_h advertiser)
 {
        int ret = BT_ERROR_NONE;
-       int error_code;
-       gboolean is_advertising = FALSE;
+       bool is_advertising = FALSE;
 
        bt_advertiser_s *__adv = (bt_advertiser_s *)advertiser;
 
@@ -778,12 +706,10 @@ int bt_adapter_le_destroy_advertiser(bt_advertiser_h advertiser)
        _bt_unset_cb(BT_EVENT_ADVERTISING_STATE_CHANGED);
 
        /* This operation is not related to the result */
-       error_code = bluetooth_is_advertising(&is_advertising);
+       ret = bt_adapt_is_adv(&is_advertising);
 
        if (is_advertising == TRUE) {
-               error_code = bluetooth_set_advertising(__adv->handle, FALSE);
-
-               ret = _bt_get_error_code(error_code);
+               ret = bt_adapt_stop_adv(__adv->handle);
 
                if (ret != BT_ERROR_NONE) {
                        BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret),
@@ -1533,8 +1459,7 @@ int bt_adapter_le_stop_advertising(bt_advertiser_h advertiser)
        BT_CHECK_INIT_STATUS();
        BT_CHECK_INPUT_PARAMETER(advertiser);
 
-       ret = _bt_get_error_code(bluetooth_set_advertising(__adv->handle,
-                                                               FALSE));
+       ret = bt_adapt_stop_adv(__adv->handle);
        if (ret != BT_ERROR_NONE) {
                BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret),
                                                ret); /* LCOV_EXCL_LINE */
@@ -1547,12 +1472,8 @@ int bt_adapter_le_start_advertising_new(bt_advertiser_h advertiser,
                bt_adapter_le_advertising_state_changed_cb cb, void *user_data)
 {
        int ret = BT_ERROR_NONE;
-       int error_code;
        bt_advertiser_s *__adv = (bt_advertiser_s *)advertiser;
-       bluetooth_advertising_data_t adv = { {0} };
-       bluetooth_scan_resp_data_t resp = { {0} };
-       bluetooth_advertising_params_t param;
-       float interval = 500;
+       unsigned int interval = 500;
 
        BT_CHECK_LE_SUPPORT();
        BT_CHECK_INIT_STATUS();
@@ -1560,10 +1481,9 @@ int bt_adapter_le_start_advertising_new(bt_advertiser_h advertiser,
 
        if (__adv->adv_data_len > 0 &&
                __adv->adv_data) { /* LCOV_EXCL_START */
-               memcpy(adv.data, __adv->adv_data, __adv->adv_data_len);
-               error_code = bluetooth_set_advertising_data(__adv->handle,
-                                       &adv, __adv->adv_data_len);
-               ret = _bt_get_error_code(error_code);
+               ret = bt_adapt_set_adv_data(__adv->handle,
+                                       (const char *)__adv->adv_data, __adv->adv_data_len);
+
                if (ret != BT_ERROR_NONE) {
                        BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret),
                                                ret); /* LCOV_EXCL_STOP */
@@ -1573,10 +1493,9 @@ int bt_adapter_le_start_advertising_new(bt_advertiser_h advertiser,
 
        if (__adv->scan_rsp_data_len > 0 &&
                __adv->scan_rsp_data) { /* LCOV_EXCL_START */
-               memcpy(resp.data, __adv->scan_rsp_data, __adv->scan_rsp_data_len);
-               error_code = bluetooth_set_scan_response_data(__adv->handle,
-                                       &resp, __adv->scan_rsp_data_len);
-               ret = _bt_get_error_code(error_code);
+               ret = bt_adapt_set_scan_res_data(__adv->handle,
+                                       (const char *)__adv->scan_rsp_data, __adv->scan_rsp_data_len);
+
                if (ret != BT_ERROR_NONE) {
                        BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret),
                                                ret); /* LCOV_EXCL_STOP */
@@ -1591,14 +1510,10 @@ int bt_adapter_le_start_advertising_new(bt_advertiser_h advertiser,
        else if (__adv->adv_params.mode == BT_ADAPTER_LE_ADVERTISING_MODE_LOW_ENERGY)
                interval = 1000;
 
-       param.interval_min = interval;
-       param.interval_max = interval;
-       param.filter_policy = __adv->adv_params.filter_policy;
-       param.type = __adv->adv_params.type;
-       error_code = bluetooth_set_custom_advertising(__adv->handle,
-                                       TRUE, &param);
+       ret = bt_adapt_start_adv(__adv->handle, interval, interval,
+                                                       __adv->adv_params.filter_policy,
+                                                       __adv->adv_params.type);
 
-       ret = _bt_get_error_code(error_code);
        if (ret != BT_ERROR_NONE) {
                BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret),
                                                ret); /* LCOV_EXCL_LINE */
@@ -1647,13 +1562,6 @@ int bt_adapter_le_set_advertising_mode(bt_advertiser_h advertiser,
                mode > BT_ADAPTER_LE_ADVERTISING_MODE_LOW_ENERGY)
                return BT_ERROR_INVALID_PARAMETER;
 
-       error_code = _bt_get_error_code(bluetooth_check_privilege_advertising_parameter());
-       if (error_code != BT_ERROR_NONE) {
-               BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error_code),
-                                       error_code); /* LCOV_EXCL_LINE */
-               return BT_ERROR_PERMISSION_DENIED; /* LCOV_EXCL_LINE */
-       }
-
        /* TODO : Before set the mode, check the inprogress status */
        __adv->adv_params.mode = mode;
 
@@ -1675,13 +1583,6 @@ int bt_adapter_le_set_advertising_filter_policy(bt_advertiser_h advertiser,
                filter_policy > BT_ADAPTER_LE_ADVERTISING_FILTER_ALLOW_SCAN_CONN_WL)
                return BT_ERROR_INVALID_PARAMETER;
 
-       error_code = _bt_get_error_code(bluetooth_check_privilege_advertising_parameter());
-       if (error_code != BT_ERROR_NONE) {
-               BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error_code),
-                                       error_code);
-               return BT_ERROR_PERMISSION_DENIED;
-       }
-
        /* TODO : Before set the filter policy, check the inprogress status */
        __adv->adv_params.filter_policy = filter_policy;
 
@@ -1699,14 +1600,6 @@ int bt_adapter_le_set_advertising_connectable(bt_advertiser_h advertiser,
        BT_CHECK_INIT_STATUS();
        BT_CHECK_INPUT_PARAMETER(advertiser);
 
-       error_code = _bt_get_error_code(
-                       bluetooth_check_privilege_advertising_parameter());
-       if (error_code != BT_ERROR_NONE) {
-               BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error_code),
-                                       error_code); /* LCOV_EXCL_LINE */
-               return BT_ERROR_PERMISSION_DENIED; /* LCOV_EXCL_LINE */
-       }
-
        if (connectable)
                __adv->adv_params.type = BT_ADAPTER_LE_ADVERTISING_CONNECTABLE; /* LCOV_EXCL_LINE */
        else
@@ -1737,7 +1630,7 @@ int bt_adapter_le_start_scan(bt_adapter_le_scan_result_cb cb, void *user_data)
 
        _bt_set_cb(BT_EVENT_LE_SCAN_RESULT_UPDATED, cb, user_data);
 
-       error_code = _bt_get_error_code(bluetooth_start_le_discovery());
+       error_code = bt_adapt_start_le_scan();
        if (error_code != BT_ERROR_NONE) {
                BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error_code),
                                        error_code); /* LCOV_EXCL_LINE */
@@ -1752,7 +1645,7 @@ int bt_adapter_le_stop_scan(void)
        BT_CHECK_LE_SUPPORT();
        BT_CHECK_INIT_STATUS();
 
-       error_code = _bt_get_error_code(bluetooth_stop_le_discovery());
+       error_code = bt_adapt_stop_le_scan();
        if (error_code != BT_ERROR_NONE) {
                BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error_code),
                                        error_code); /* LCOV_EXCL_LINE */
index 0592c714a29f4e7edf804d49859d67d0de0c663e..b3986a1277b4c1f8a3e361c1bf36887792eeab99 100644 (file)
@@ -18,7 +18,8 @@
 #include <string.h>
 #include <stdlib.h>
 #include <ctype.h>
-#include <bluetooth-api.h>
+
+#include "bt-adaptation-common.h"
 
 #include "bluetooth.h"
 #include "bluetooth_internal.h"
@@ -76,6 +77,8 @@ typedef struct {
 
 int bt_initialize(void)
 {
+       bt_adapt_init();
+
        is_initialized = true;
 
        return BT_ERROR_NONE;
@@ -85,6 +88,8 @@ int bt_deinitialize(void)
 {
        BT_CHECK_INIT_STATUS();
 
+       bt_adapt_deinit();
+
        is_initialized = false;
 
        return BT_ERROR_NONE;
@@ -306,5 +311,3 @@ char *_bt_convert_error_to_string(int error)
        return "UNKNOWN"; /* LCOV_EXCL_LINE */
 }
 
-
-
index 5f03494c76e3dde2a6f6b1d9a0eaaadd5f84f4b6..8abef78d5b1822ad064cfd16e4be236ce1e811e3 100644 (file)
@@ -14,9 +14,7 @@
  * limitations under the License.
  */
 
-#include <glib.h>
-#include <stdio.h>
-#include <bluetooth-api.h>
+#include "bt-adaptation-device.h"
 
 #include "bluetooth.h"
 #include "bluetooth_internal.h"
@@ -31,15 +29,13 @@ int bt_device_disconnect(const char *remote_address)
 
 int bt_device_create_bond(const char *device_address)
 {
-       bluetooth_device_address_t addr_hex = { {0,} };
        int error_code = BT_ERROR_NONE;
 
        BT_CHECK_SUPPORTED_FEATURE(BT_FEATURE_COMMON);
        BT_CHECK_INIT_STATUS();
        BT_CHECK_INPUT_PARAMETER(device_address);
 
-       _bt_convert_address_to_hex(&addr_hex, device_address); /* LCOV_EXCL_LINE */
-       error_code = _bt_get_error_code(bluetooth_bond_device(&addr_hex));
+       error_code = bt_adapt_bond_device(device_address);
        if (error_code != BT_ERROR_NONE)
                BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error_code), error_code);
 
@@ -61,15 +57,13 @@ int bt_device_cancel_bonding(void)
 
 int bt_device_destroy_bond(const char *device_address)
 {
-       bluetooth_device_address_t addr_hex = { {0,} };
        int error_code = BT_ERROR_NONE;
 
        BT_CHECK_SUPPORTED_FEATURE(BT_FEATURE_COMMON);
        BT_CHECK_INIT_STATUS();
        BT_CHECK_INPUT_PARAMETER(device_address); /* LCOV_EXCL_LINE */
 
-       _bt_convert_address_to_hex(&addr_hex, device_address); /* LCOV_EXCL_LINE */
-       error_code = _bt_get_error_code(bluetooth_unbond_device(&addr_hex)); /* LCOV_EXCL_LINE */
+       error_code = bt_adapt_unbond_device(device_address); /* LCOV_EXCL_LINE */
        if (error_code != BT_ERROR_NONE) { /* LCOV_EXCL_LINE */
                BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error_code), error_code); /* LCOV_EXCL_LINE */
        }
@@ -107,19 +101,14 @@ int bt_device_foreach_connected_profiles(const char *remote_address, bt_device_c
 int bt_device_is_profile_connected(const char *remote_address, bt_profile_e bt_profile,
                                bool *connected_status)
 {
-       bluetooth_device_address_t addr_hex = { {0,} };
        int ret;
-       gboolean is_connected = FALSE;
 
        BT_CHECK_SUPPORTED_FEATURE(BT_FEATURE_COMMON);
        BT_CHECK_INIT_STATUS();
        BT_CHECK_INPUT_PARAMETER(remote_address);
 
-       _bt_convert_address_to_hex(&addr_hex, remote_address);
-
-       ret = _bt_get_error_code(bluetooth_is_device_connected(&addr_hex, bt_profile,
-                                                               &is_connected));
-       *connected_status = is_connected ? true : false;
+       *connected_status = false;
+       ret = bt_adapt_is_device_connected(remote_address, bt_profile, connected_status);
 
        if (ret != BT_ERROR_NONE) {
                BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); /* LCOV_EXCL_LINE */
@@ -266,11 +255,22 @@ int bt_device_get_rssi_strength(const char *remote_address,
        return BT_ERROR_NOT_SUPPORTED;
 }
 
-
 int bt_device_le_conn_update(const char *device_address,
        const bt_le_conn_update_s *parameters)
 {
-       return BT_ERROR_NOT_SUPPORTED;
+       int ret = BT_ERROR_NONE;
+
+       BT_CHECK_SUPPORTED_FEATURE(BT_FEATURE_COMMON);
+       BT_CHECK_INIT_STATUS();
+       BT_CHECK_INPUT_PARAMETER(device_address);
+       BT_CHECK_INPUT_PARAMETER(parameters);
+
+       ret = bt_adapt_le_conn_update(device_address, parameters);
+
+       if (BT_ERROR_NONE != ret)
+               BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret);
+
+       return ret;
 }
 /* LCOV_EXCL_STOP */
 
@@ -294,7 +294,22 @@ int bt_device_unset_pin_code(const char *remote_address)
 
 int bt_device_update_le_connection_mode(const char *remote_address, bt_device_le_connection_mode_e mode)
 {
-       return BT_ERROR_NOT_SUPPORTED;
+       int ret;
+
+       BT_CHECK_SUPPORTED_FEATURE(BT_FEATURE_COMMON);
+       BT_CHECK_INIT_STATUS();
+       BT_CHECK_INPUT_PARAMETER(remote_address);
+
+       if (mode < BT_DEVICE_LE_CONNECTION_MODE_BALANCED ||
+                mode > BT_DEVICE_LE_CONNECTION_MODE_LOW_ENERGY) {
+               return BT_ERROR_INVALID_PARAMETER;
+       }
+
+       ret = bt_adapt_update_le_connection_mode(remote_address, mode);
+       if (BT_ERROR_NONE != ret)
+               BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret);
+
+       return ret;
 }
 
 int bt_device_request_att_mtu(const char *remote_address, unsigned int mtu)