[Bluetooth][OTP] Add APIs for OTP server role 55/121655/4
authorGowtham Anandha Babu <gowtham.ab@samsung.com>
Tue, 28 Mar 2017 10:33:05 +0000 (16:03 +0530)
committerPyun DoHyun <dh79.pyun@samsung.com>
Wed, 12 Apr 2017 06:58:17 +0000 (23:58 -0700)
Change-Id: I8114a4e5816185bc97553b8ca4d8bcbcc7e10273
Signed-off-by: Gowtham Anandha Babu <gowtham.ab@samsung.com>
CMakeLists.txt
include/bluetooth_internal.h
include/bluetooth_private.h
include/bluetooth_type_internal.h
packaging/capi-network-bluetooth.spec
src/bluetooth-common.c
src/bluetooth-otp.c [new file with mode: 0644]
test/bt_unit_test.c
test/bt_unit_test.h

index 377965c..c6d3219 100644 (file)
@@ -49,6 +49,7 @@ src/bluetooth-ipsp.c
 src/bluetooth-dpm.c
 src/bluetooth-proximity.c
 src/bluetooth-tds.c
+src/bluetooth-otp.c
 )
 
 LIST(APPEND SOURCES src/bluetooth-proximity.c)
index eef273e..da22eb0 100644 (file)
@@ -3995,6 +3995,31 @@ int bt_tds_seeker_get_complete_transport_blocks(bt_tds_seeker_h seeker,
 int bt_tds_seeker_activate_control_point(bt_tds_seeker_h seeker,
                                bt_tds_transport_e transport, unsigned char *buffer, int len,
                                bt_tds_control_point_activation_indication_cb callback, void *user_data);
+
+/**
+ * @ingroup
+ * @brief Starts OTP server on the given directory location.
+ */
+int bt_otp_server_initialize(const char *directory);
+
+/**
+ * @ingroup
+ * @brief Stops OTP server.
+ */
+int bt_otp_server_deinitialize();
+
+/**
+ * @ingroup
+ * @brief Registers a callback function that will be invoked when the server state is changed.
+ */
+int bt_otp_set_server_state_changed_cb(bt_otp_server_state_changed_cb callback, void *user_data);
+
+/**
+ * @ingroup
+ * @brief Registers a callback function that will be invoked when the server state is changed.
+ */
+int bt_otp_unset_server_state_changed_cb(void);
+
 /**
  * @}
  */
index 6d32366..193e0f1 100644 (file)
@@ -158,6 +158,7 @@ typedef enum {
        BT_EVENT_MAP_CLIENT_PUSH_MESSAGE, /**< MAP - pushMessage event*/
        BT_EVENT_TDS_ACTIVATION_REQUESTED, /**< TDS - transport activation requested event */
        BT_EVENT_TDS_PROVIDER_FOUND_RESULT, /**< TDS - CUSTOM Provider */
+       BT_EVENT_OTP_SERVER_STATE_CHANGED, /**< OTP - Server Status */
        BT_EVENT_MAX
 } bt_event_e;
 
index 51138df..67770e1 100644 (file)
@@ -910,6 +910,13 @@ typedef void (*bt_tds_seeker_complete_transport_data_cb)
  */
 typedef void (*bt_tds_control_point_activation_indication_cb)
                (int result, const char *remote_address, unsigned char *data, int data_length, void *user_data);
+
+/**
+ * @internal
+ * @brief  Called when OTP Server is Enabled or Disabled.
+ */
+typedef void (*bt_otp_server_state_changed_cb)(int result, bool connected);
+
 /**
  * @}
  */
index 6e05bae..c119a5a 100644 (file)
@@ -48,9 +48,9 @@ cp %{SOURCE1001} %{SOURCE1002} .
 
 %build
 
-export CFLAGS="$CFLAGS -DTIZEN_FEATURE_AUDIO_HF_DISABLE -DTIZEN_FEATURE_IPSP_SUPPORT"
-export CXXFLAGS="$CXXFLAGS -DTIZEN_FEATURE_AUDIO_HF_DISABLE -DTIZEN_FEATURE_IPSP_SUPPORT"
-export FFLAGS="$FFLAGS -DTIZEN_FEATURE_AUDIO_HF_DISABLE -DTIZEN_FEATURE_IPSP_SUPPORT"
+export CFLAGS="$CFLAGS -DTIZEN_FEATURE_AUDIO_HF_DISABLE -DTIZEN_FEATURE_IPSP_SUPPORT -DTIZEN_FEATURE_OTP_SUPPORT"
+export CXXFLAGS="$CXXFLAGS -DTIZEN_FEATURE_AUDIO_HF_DISABLE -DTIZEN_FEATURE_IPSP_SUPPORT -DTIZEN_FEATURE_OTP_SUPPORT"
+export FFLAGS="$FFLAGS -DTIZEN_FEATURE_AUDIO_HF_DISABLE -DTIZEN_FEATURE_IPSP_SUPPORT -DTIZEN_FEATURE_OTP_SUPPORT"
 
 %ifarch aarch64
 echo arch64
index 8815a90..0cee711 100644 (file)
@@ -2918,6 +2918,14 @@ static void __bt_event_proxy(int event, bluetooth_event_param_t *param, void *us
                if (device_addr != NULL)
                        free(device_addr); /* LCOV_EXCL_STOP */
                break;
+       } case BLUETOOTH_EVENT_OTP_SERVER_STATE_CHANGED: {
+               bt_otp_server_state_changed_cb cb = bt_event_slot_container[event_index].callback;
+               bool *status = (bool *)(param->param_data);
+
+               BT_INFO("BLUETOOTH_EVENT_OTP_SERVER_STATE_CHANGED [%s]", *status ? "enabled" : "disabled");
+
+               cb(_bt_get_error_code(param->result), *status ? true : false);
+               break;
        }
        default:
                BT_INFO("Unknown function");
@@ -3555,6 +3563,8 @@ static int __bt_get_cb_index(int event)
                return BT_EVENT_PROXIMITY_REPORTER_PROPERTY_CHANGED;
        case BLUETOOTH_EVENT_TDS_ACTIVATION_REQUESTED:
                return BT_EVENT_TDS_ACTIVATION_REQUESTED;
+       case BLUETOOTH_EVENT_OTP_SERVER_STATE_CHANGED:
+               return BT_EVENT_OTP_SERVER_STATE_CHANGED;
        default:
                return -1;
        }
diff --git a/src/bluetooth-otp.c b/src/bluetooth-otp.c
new file mode 100644 (file)
index 0000000..464c5a5
--- /dev/null
@@ -0,0 +1,122 @@
+/*
+ * 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.
+ */
+
+#include <glib.h>
+#include <dlog.h>
+#include <string.h>
+#include <stdio.h>
+#include <stdbool.h>
+#include <string.h>
+#include <bluetooth-api.h>
+
+#include "bluetooth.h"
+#include "bluetooth_internal.h"
+#include "bluetooth_private.h"
+
+#ifdef TIZEN_FEATURE_OTP_SUPPORT
+#define BT_CHECK_OTP_SUPPORT()
+#else
+#define BT_CHECK_OTP_SUPPORT() \
+       { \
+               LOGE("[%s] NOT_SUPPORTED(0x%08x)", __FUNCTION__, BT_ERROR_NOT_SUPPORTED); \
+               return BT_ERROR_NOT_SUPPORTED; \
+       }
+#endif
+
+#define BT_CHECK_LE_SUPPORT() \
+{ \
+       BT_CHECK_SUPPORTED_FEATURE(BT_FEATURE_COMMON); \
+       BT_CHECK_SUPPORTED_FEATURE(BT_FEATURE_LE); \
+}
+
+#define BT_CHECK_OTP_SERVER_INIT_STATUS() \
+       if (__bt_check_otp_server_init_status() == BT_ERROR_NOT_INITIALIZED) { \
+               LOGE("[%s] NOT_INITIALIZED(0x%08x)", __FUNCTION__, \
+                                       BT_ERROR_NOT_INITIALIZED); \
+               return BT_ERROR_NOT_INITIALIZED; \
+       }
+
+static bool is_otp_server_initialized = false;
+
+int __bt_check_otp_server_init_status(void)
+{
+       if (is_otp_server_initialized != true) {
+               BT_ERR("NOT_INITIALIZED(0x%08x)", BT_ERROR_NOT_INITIALIZED);
+               return BT_ERROR_NOT_INITIALIZED;
+       }
+
+       return BT_ERROR_NONE;
+}
+
+/* LCOV_EXCL_START */
+int bt_otp_server_initialize(const char *directory)
+{
+       int error_code = BT_ERROR_NONE;
+
+       BT_CHECK_OTP_SUPPORT();
+       BT_CHECK_LE_SUPPORT();
+       BT_CHECK_INIT_STATUS();
+
+       error_code = _bt_get_error_code(bluetooth_otp_server_init(directory));
+
+       if (error_code != BT_ERROR_NONE) {
+               BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error_code),
+                               error_code);
+               return error_code;
+       }
+
+       is_otp_server_initialized = true;
+       return BT_ERROR_NONE;
+}
+
+int bt_otp_server_deinitialize()
+{
+       int error_code = BT_ERROR_NONE;
+
+       BT_CHECK_OTP_SUPPORT();
+       BT_CHECK_LE_SUPPORT();
+       BT_CHECK_INIT_STATUS();
+       BT_CHECK_OTP_SERVER_INIT_STATUS();
+
+       error_code = _bt_get_error_code(bluetooth_otp_server_deinit());
+
+       if (error_code != BT_ERROR_NONE) {
+               BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error_code), /* LCOV_EXCL_LINE */
+                               error_code);
+               return error_code; /* LCOV_EXCL_LINE */
+       }
+
+       is_otp_server_initialized = false;
+       return BT_ERROR_NONE;
+}
+
+int bt_otp_set_server_state_changed_cb(bt_otp_server_state_changed_cb callback, void *user_data)
+{
+       BT_CHECK_OTP_SUPPORT();
+       BT_CHECK_INIT_STATUS();
+       BT_CHECK_INPUT_PARAMETER(callback);
+       _bt_set_cb(BT_EVENT_OTP_SERVER_STATE_CHANGED, callback, user_data);
+       return BT_ERROR_NONE;
+
+}
+int bt_otp_unset_server_state_changed_cb(void)
+{
+       BT_CHECK_OTP_SUPPORT();
+       BT_CHECK_INIT_STATUS();
+       if (_bt_check_cb(BT_EVENT_OTP_SERVER_STATE_CHANGED) == true)
+               _bt_unset_cb(BT_EVENT_OTP_SERVER_STATE_CHANGED);
+       return BT_ERROR_NONE;
+}
\ No newline at end of file
index a8f0c0e..60e6cf4 100644 (file)
@@ -185,6 +185,8 @@ tc_table_t tc_main[] = {
                , BT_UNIT_TEST_TABLE_TDS_PROVIDER},
        {"TDS Seeker"
                , BT_UNIT_TEST_TABLE_TDS_SEEKER},
+       {"OTP"
+               , BT_UNIT_TEST_TABLE_OTP},
        {"Initialize All"
                , BT_UNIT_TEST_FUNCTION_INITIALIZE_ALL},
        {"FINISH"
@@ -1146,6 +1148,20 @@ tc_table_t tc_tds_seeker[] = {
        {NULL                                   , 0x0000},
 };
 
+tc_table_t tc_otp[] = {
+       /* OTP functions */
+       {"BACK"
+               , BT_UNIT_TEST_FUNCTION_BACK},
+       {"bt_otp_server_init"
+               , BT_UNIT_TEST_FUNCTION_OTP_SERVER_INIT},
+       {"bt_otp_server_deinit"
+               , BT_UNIT_TEST_FUNCTION_OTP_SERVER_DEINIT},
+       {"bt_otp_set_server_state_changed_cb"
+               , BT_UNIT_TEST_FUNCTION_OTP_SET_SERVER_STATE_CHANGED_CB},
+       {"bt_otp_unset_server_state_changed_cb"
+               , BT_UNIT_TEST_FUNCTION_OTP_UNSET_SERVER_STATE_CHANGED_CB},
+       {NULL                                   , 0x0000},
+};
 
 tc_table_t tc_automated_test[] = {
        /* Automated test Functions*/
@@ -1246,6 +1262,9 @@ void tc_usage_print(void)
                __bt_initialize_all();
                TC_PRT("Key 0 : usage BACK");
                return;
+       case BT_UNIT_TEST_TABLE_OTP:
+               tc_table = tc_otp;
+               break;
        case BT_UNIT_TEST_TABLE_MAIN:
 __default__:
        default:
@@ -3193,6 +3212,13 @@ static void __bt_tds_control_point_activation_result_cb(int result, const char *
        }
 }
 
+void __bt_otp_server_state_changed_cb(int result, bool status)
+{
+       TC_PRT("__bt_otp_server_state_changed_cb");
+       TC_PRT("Result: %d", result);
+       TC_PRT("Server Status: %s", status ? "enabled" : "disabled");
+}
+
 static void __bt_initialize_all(void)
 {
        int ret;
@@ -4748,6 +4774,51 @@ int test_set_params(int test_id, char *param)
 
                break;
        }
+       case BT_UNIT_TEST_TABLE_OTP: {
+               switch (test_id) {
+               case BT_UNIT_TEST_FUNCTION_OTP_SERVER_INIT: {
+                       if (param_index == 0) {
+                               g_test_param.param_count = 1;
+                               g_test_param.params = g_malloc0(sizeof(char *) *g_test_param.param_count);
+                       }
+
+                       if (param_index > 0) {
+                               int len = strlen(param);
+                               g_test_param.params[param_index - 1] = g_malloc0(len + 1);
+                               /* Remove new line character */
+                               param[len - 1] = '\0';
+                               strncpy(g_test_param.params[param_index - 1], param, strlen(param));
+                       }
+
+                       if (param_index == g_test_param.param_count) {
+                               need_to_set_params = false;
+#ifdef ARCH64
+                               test_input_callback((void *)(uintptr_t)test_id);
+#else
+                               test_input_callback((void *)test_id);
+#endif
+                               param_index = 0;
+                               return 0;
+                       }
+
+                       switch (param_index) {
+                       case 0:
+                               TC_PRT("Input Value in string");
+                               break;
+                       }
+
+                       param_index++;
+
+                       break;
+               }
+               default:
+                       TC_PRT("There is no param to set\n");
+                       need_to_set_params = false;
+                       break;
+               }
+
+               break;
+       }
 __default__:
        default:
                TC_PRT("There is no param to set\n");
@@ -10006,6 +10077,52 @@ int test_input_callback(void *data)
                }
                break;
        }
+       case BT_UNIT_TEST_TABLE_OTP: {
+               switch (test_id) {
+               case BT_UNIT_TEST_FUNCTION_OTP_SERVER_INIT: {
+                       char *directory = NULL;
+                       if (g_test_param.param_count < 1) {
+                                       TC_PRT("No relative path set");
+                       } else {
+                               directory = g_test_param.params[0];
+                       }
+                       TC_PRT("%s", directory);
+                       ret = bt_otp_server_initialize(directory);
+                       if (ret < BT_ERROR_NONE)
+                               TC_PRT("failed with [0x%04x]", ret);
+                       else if (ret == BT_ERROR_NONE)
+                               TC_PRT("Success");
+                       /* __bt_free_test_param(&g_test_param); */
+                       break;
+               }
+               case BT_UNIT_TEST_FUNCTION_OTP_SERVER_DEINIT: {
+                       ret = bt_otp_server_deinitialize();
+                       if (ret < BT_ERROR_NONE)
+                               TC_PRT("failed with [0x%04x]", ret);
+                       else if (ret == BT_ERROR_NONE)
+                               TC_PRT("Success");
+                       break;
+               }
+               case BT_UNIT_TEST_FUNCTION_OTP_SET_SERVER_STATE_CHANGED_CB: {
+                       ret = bt_otp_set_server_state_changed_cb(
+                                               __bt_otp_server_state_changed_cb, NULL);
+                       TC_PRT("returns %s\n", __bt_get_error_message(ret));
+                       break;
+               }
+               case BT_UNIT_TEST_FUNCTION_OTP_UNSET_SERVER_STATE_CHANGED_CB: {
+                       ret = bt_otp_unset_server_state_changed_cb();
+                       TC_PRT("returns %s\n", __bt_get_error_message(ret));
+                       break;
+               }
+               case BT_UNIT_TEST_FUNCTION_ACTIVATE_FLAG_TO_SET_PARAMETERS:
+                       need_to_set_params = true;
+                       TC_PRT("Select the function again");
+                       break;
+               default:
+                       break;
+               }
+               break;
+       }
        case BT_UNIT_TEST_TABLE_ETC: {
                static unsigned int delay = 0;
                bt_onoff_cnt = 0;
index 3457df7..d2295dc 100644 (file)
@@ -53,6 +53,7 @@ typedef enum {
        BT_UNIT_TEST_FUNCTION_INITIALIZE_ALL,
        BT_UNIT_TEST_TABLE_TDS_PROVIDER,
        BT_UNIT_TEST_TABLE_TDS_SEEKER,
+       BT_UNIT_TEST_TABLE_OTP,
        BT_UNIT_TEST_TABLE_FINISH = 0xFF,
 } bt_unit_test_table_e;
 
@@ -480,6 +481,12 @@ typedef enum {
        BT_UNIT_TEST_FUNCTION_TDS_SEEKER_GET_COMPLETE_DATA,
        BT_UNIT_TEST_FUNCTION_TDS_SEEKER_ACTIVATE_CONTROL_POINT,
 
+       /* OTP */
+       BT_UNIT_TEST_FUNCTION_OTP_SERVER_INIT = 1,
+       BT_UNIT_TEST_FUNCTION_OTP_SERVER_DEINIT,
+       BT_UNIT_TEST_FUNCTION_OTP_SET_SERVER_STATE_CHANGED_CB,
+       BT_UNIT_TEST_FUNCTION_OTP_UNSET_SERVER_STATE_CHANGED_CB,
+
        BT_UNIT_TEST_FUNCTION_ACTIVATE_FLAG_TO_SET_PARAMETERS = 0XFF,
 } bt_unit_test_function_e;