src/bluetooth-dpm.c
src/bluetooth-proximity.c
src/bluetooth-tds.c
+src/bluetooth-otp.c
)
LIST(APPEND SOURCES src/bluetooth-proximity.c)
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);
+
/**
* @}
*/
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;
*/
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);
+
/**
* @}
*/
%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
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");
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;
}
--- /dev/null
+/*
+ * 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
, 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"
{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*/
__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:
}
}
+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;
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");
}
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;
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;
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;