From 990ea211013af6cfc2353b9e324ed84741f59981 Mon Sep 17 00:00:00 2001 From: "jk7744.park" Date: Tue, 8 Sep 2015 22:08:27 +0900 Subject: tizen 2.3.1 release --- CMakeLists.txt | 32 +- TC/READAME.txt | 5 + TC/_export_env.sh | 9 + TC/_export_target_env.sh | 8 + TC/build.sh | 16 + TC/clean.sh | 11 + TC/config | 4 + TC/execute.sh | 15 + TC/push.sh | 13 + TC/run.sh | 15 + TC/testcase/Makefile | 24 + TC/testcase/tslist | 28 + .../utc_network_bluetooth_adapter_negative.c | 429 ++ .../utc_network_bluetooth_adapter_positive.c | 797 +++ TC/testcase/utc_network_bluetooth_audio_negative.c | 383 ++ TC/testcase/utc_network_bluetooth_audio_positive.c | 667 +++ TC/testcase/utc_network_bluetooth_avrcp_negative.c | 174 + TC/testcase/utc_network_bluetooth_avrcp_positive.c | 398 ++ .../utc_network_bluetooth_common_negative.c | 84 + .../utc_network_bluetooth_common_positive.c | 122 + ...c_network_bluetooth_device_discovery_negative.c | 191 + ...c_network_bluetooth_device_discovery_positive.c | 262 + .../utc_network_bluetooth_device_negative.c | 300 ++ .../utc_network_bluetooth_device_positive.c | 695 +++ TC/testcase/utc_network_bluetooth_gatt_negative.c | 298 + TC/testcase/utc_network_bluetooth_gatt_positive.c | 407 ++ TC/testcase/utc_network_bluetooth_hdp_negative.c | 201 + TC/testcase/utc_network_bluetooth_hdp_positive.c | 242 + TC/testcase/utc_network_bluetooth_hid_negative.c | 142 + TC/testcase/utc_network_bluetooth_hid_positive.c | 159 + .../utc_network_bluetooth_opp-client_negative.c | 136 + .../utc_network_bluetooth_opp-client_positive.c | 261 + .../utc_network_bluetooth_opp-server_negative.c | 191 + .../utc_network_bluetooth_opp-server_positive.c | 224 + TC/testcase/utc_network_bluetooth_pan_negative.c | 166 + TC/testcase/utc_network_bluetooth_pan_positive.c | 265 + ...utc_network_bluetooth_service_search_negative.c | 179 + ...utc_network_bluetooth_service_search_positive.c | 407 ++ .../utc_network_bluetooth_socket_negative.c | 268 + .../utc_network_bluetooth_socket_positive.c | 478 ++ TC/tet_scen | 7 + TC/tetbuild.cfg | 5 + TC/tetclean.cfg | 5 + TC/tetexec.cfg | 5 + TC/tetware.conf | 5 + bluetooth-gatt-test.manifest | 12 + bluetooth-infinite-spp-test-client.manifest | 12 + bluetooth-infinite-spp-test-server.manifest | 12 + bluetooth-test.manifest | 12 + bluetooth.manifest | 5 + debian/README | 0 debian/capi-network-bluetooth-dev.install | 4 - debian/capi-network-bluetooth-dev.postinst | 1 - debian/capi-network-bluetooth.install | 1 - debian/capi-network-bluetooth.postinst | 1 - debian/changelog | 304 -- debian/compat | 1 - debian/control | 21 - debian/rules | 68 - doc/bluetooth_doc.h | 696 +++ include/bluetooth.h | 2917 ---------- include/bluetooth_private.h | 304 +- include/mobile/bluetooth.h | 5621 +++++++++++++++++++ include/mobile/bluetooth_internal.h | 1601 ++++++ include/mobile/bluetooth_type.h | 1829 +++++++ include/mobile/bluetooth_type_internal.h | 254 + include/wearable/bluetooth.h | 5039 +++++++++++++++++ include/wearable/bluetooth_internal.h | 2276 ++++++++ include/wearable/bluetooth_type.h | 1608 ++++++ include/wearable/bluetooth_type_internal.h | 582 ++ packaging/capi-network-bluetooth.spec | 190 +- src/bluetooth-adapter.c | 2700 +++++++++- src/bluetooth-audio.c | 1084 +++- src/bluetooth-avrcp.c | 534 +- src/bluetooth-common.c | 1789 +++++- src/bluetooth-device.c | 417 +- src/bluetooth-gatt.c | 2481 +++++++++ src/bluetooth-hdp.c | 60 +- src/bluetooth-hid.c | 67 +- src/bluetooth-opp-client.c | 78 +- src/bluetooth-opp-server.c | 95 +- src/bluetooth-pan.c | 73 +- src/bluetooth-pbap.c | 282 + src/bluetooth-socket.c | 138 +- test/CMakeLists.txt | 8 + test/bt_chat_client.c | 453 -- test/bt_chat_server.c | 281 - test/bt_infinite_spp_test.c | 512 ++ test/bt_infinite_spp_test_client.service | 11 + test/bt_infinite_spp_test_server.service | 11 + test/bt_onoff.c | 131 + test/bt_unit_test.c | 5676 ++++++++++++++++++-- test/bt_unit_test.h | 354 ++ test/capi.network.bluetooth.infinite.spp.test.rule | 4 + test/capi.network.bluetooth.test.rule | 2 + test/gatt_profile_test_suite/CMakeLists.txt | 22 + test/gatt_profile_test_suite/bt_unit_test_gatt.c | 121 + test/gatt_profile_test_suite/bt_unit_test_gatt.h | 43 + .../bt_unit_test_gatt_hr_profile.c | 472 ++ .../bt_unit_test_gatt_hr_profile.h | 64 + .../capi.network.bluetooth.test.gatt.rule | 2 + test_scripts/bt_on_test_while_infinite.service | 13 + test_scripts/check_bt_during_infinite_boot.sh | 39 + .../check_bt_during_infinite_boot_by_sdb.sh | 71 + 104 files changed, 45347 insertions(+), 4845 deletions(-) create mode 100644 TC/READAME.txt create mode 100755 TC/_export_env.sh create mode 100755 TC/_export_target_env.sh create mode 100755 TC/build.sh create mode 100755 TC/clean.sh create mode 100644 TC/config create mode 100755 TC/execute.sh create mode 100755 TC/push.sh create mode 100755 TC/run.sh create mode 100644 TC/testcase/Makefile create mode 100644 TC/testcase/tslist create mode 100755 TC/testcase/utc_network_bluetooth_adapter_negative.c create mode 100755 TC/testcase/utc_network_bluetooth_adapter_positive.c create mode 100755 TC/testcase/utc_network_bluetooth_audio_negative.c create mode 100755 TC/testcase/utc_network_bluetooth_audio_positive.c create mode 100644 TC/testcase/utc_network_bluetooth_avrcp_negative.c create mode 100755 TC/testcase/utc_network_bluetooth_avrcp_positive.c create mode 100644 TC/testcase/utc_network_bluetooth_common_negative.c create mode 100755 TC/testcase/utc_network_bluetooth_common_positive.c create mode 100644 TC/testcase/utc_network_bluetooth_device_discovery_negative.c create mode 100755 TC/testcase/utc_network_bluetooth_device_discovery_positive.c create mode 100755 TC/testcase/utc_network_bluetooth_device_negative.c create mode 100755 TC/testcase/utc_network_bluetooth_device_positive.c create mode 100755 TC/testcase/utc_network_bluetooth_gatt_negative.c create mode 100755 TC/testcase/utc_network_bluetooth_gatt_positive.c create mode 100644 TC/testcase/utc_network_bluetooth_hdp_negative.c create mode 100755 TC/testcase/utc_network_bluetooth_hdp_positive.c create mode 100755 TC/testcase/utc_network_bluetooth_hid_negative.c create mode 100755 TC/testcase/utc_network_bluetooth_hid_positive.c create mode 100755 TC/testcase/utc_network_bluetooth_opp-client_negative.c create mode 100755 TC/testcase/utc_network_bluetooth_opp-client_positive.c create mode 100755 TC/testcase/utc_network_bluetooth_opp-server_negative.c create mode 100755 TC/testcase/utc_network_bluetooth_opp-server_positive.c create mode 100644 TC/testcase/utc_network_bluetooth_pan_negative.c create mode 100755 TC/testcase/utc_network_bluetooth_pan_positive.c create mode 100644 TC/testcase/utc_network_bluetooth_service_search_negative.c create mode 100755 TC/testcase/utc_network_bluetooth_service_search_positive.c create mode 100644 TC/testcase/utc_network_bluetooth_socket_negative.c create mode 100755 TC/testcase/utc_network_bluetooth_socket_positive.c create mode 100755 TC/tet_scen create mode 100644 TC/tetbuild.cfg create mode 100644 TC/tetclean.cfg create mode 100644 TC/tetexec.cfg create mode 100644 TC/tetware.conf create mode 100644 bluetooth-gatt-test.manifest create mode 100644 bluetooth-infinite-spp-test-client.manifest create mode 100644 bluetooth-infinite-spp-test-server.manifest create mode 100644 bluetooth-test.manifest create mode 100644 bluetooth.manifest delete mode 100644 debian/README delete mode 100644 debian/capi-network-bluetooth-dev.install delete mode 100644 debian/capi-network-bluetooth-dev.postinst delete mode 100644 debian/capi-network-bluetooth.install delete mode 100644 debian/capi-network-bluetooth.postinst delete mode 100644 debian/changelog delete mode 100644 debian/compat delete mode 100644 debian/control delete mode 100755 debian/rules create mode 100644 doc/bluetooth_doc.h delete mode 100644 include/bluetooth.h create mode 100755 include/mobile/bluetooth.h create mode 100644 include/mobile/bluetooth_internal.h create mode 100644 include/mobile/bluetooth_type.h create mode 100644 include/mobile/bluetooth_type_internal.h create mode 100755 include/wearable/bluetooth.h create mode 100644 include/wearable/bluetooth_internal.h create mode 100644 include/wearable/bluetooth_type.h create mode 100644 include/wearable/bluetooth_type_internal.h create mode 100755 src/bluetooth-gatt.c create mode 100644 src/bluetooth-pbap.c delete mode 100644 test/bt_chat_client.c delete mode 100644 test/bt_chat_server.c create mode 100644 test/bt_infinite_spp_test.c create mode 100644 test/bt_infinite_spp_test_client.service create mode 100644 test/bt_infinite_spp_test_server.service create mode 100644 test/bt_onoff.c create mode 100644 test/bt_unit_test.h create mode 100644 test/capi.network.bluetooth.infinite.spp.test.rule create mode 100644 test/capi.network.bluetooth.test.rule create mode 100644 test/gatt_profile_test_suite/CMakeLists.txt create mode 100644 test/gatt_profile_test_suite/bt_unit_test_gatt.c create mode 100644 test/gatt_profile_test_suite/bt_unit_test_gatt.h create mode 100644 test/gatt_profile_test_suite/bt_unit_test_gatt_hr_profile.c create mode 100644 test/gatt_profile_test_suite/bt_unit_test_gatt_hr_profile.h create mode 100644 test/gatt_profile_test_suite/capi.network.bluetooth.test.gatt.rule create mode 100644 test_scripts/bt_on_test_while_infinite.service create mode 100755 test_scripts/check_bt_during_infinite_boot.sh create mode 100755 test_scripts/check_bt_during_infinite_boot_by_sdb.sh diff --git a/CMakeLists.txt b/CMakeLists.txt index dfdcb5a..98e31fb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,9 +8,18 @@ SET(PREFIX ${CMAKE_INSTALL_PREFIX}) SET(INC_DIR include) INCLUDE_DIRECTORIES(${INC_DIR}) - -SET(dependents "dlog glib-2.0 capi-base-common bluetooth-api bluetooth-media-control") -SET(pc_dependents "capi-base-common") +IF (TIZEN_WEARABLE) + INCLUDE_DIRECTORIES(${INC_DIR}/wearable) +ELSE () + INCLUDE_DIRECTORIES(${INC_DIR}/mobile) +ENDIF (TIZEN_WEARABLE) + +IF (TIZEN_WEARABLE) +SET(dependents "dlog glib-2.0 capi-base-common bluetooth-api privacy-manager-client") +ELSE () +SET(dependents "dlog glib-2.0 capi-base-common bluetooth-api") +ENDIF (TIZEN_WEARABLE) +SET(pc_dependents "capi-base-common glib-2.0") INCLUDE(FindPkgConfig) pkg_check_modules(${fw_name} REQUIRED ${dependents}) @@ -42,7 +51,11 @@ src/bluetooth-hdp.c src/bluetooth-hid.c src/bluetooth-audio.c src/bluetooth-avrcp.c +src/bluetooth-gatt.c ) +IF (TIZEN_WEARABLE) +LIST(APPEND SOURCES src/bluetooth-pbap.c) +ENDIF (TIZEN_WEARABLE) ADD_LIBRARY(${fw_name} SHARED ${SOURCES}) @@ -62,6 +75,19 @@ INSTALL( PATTERN "*_private.h" EXCLUDE PATTERN "${INC_DIR}/*.h" ) +IF (TIZEN_WEARABLE) +INSTALL( + DIRECTORY ${INC_DIR}/wearable/ DESTINATION include/network + FILES_MATCHING + PATTERN "${INC_DIR}/wearable/*.h" + ) +ELSE () +INSTALL( + DIRECTORY ${INC_DIR}/mobile/ DESTINATION include/network + FILES_MATCHING + PATTERN "${INC_DIR}/mobile/*.h" + ) +ENDIF (TIZEN_WEARABLE) SET(PC_NAME ${fw_name}) SET(PC_REQUIRED ${pc_dependents}) diff --git a/TC/READAME.txt b/TC/READAME.txt new file mode 100644 index 0000000..f0edad5 --- /dev/null +++ b/TC/READAME.txt @@ -0,0 +1,5 @@ +Before run DTS of bluetooth, BT should be disabled. +This DTS needs another target and it must be set as the following: + 1) BT is activated. + 2) BT is discoverable. + 3) BT name is set as "dts_test". diff --git a/TC/_export_env.sh b/TC/_export_env.sh new file mode 100755 index 0000000..ac8f4a1 --- /dev/null +++ b/TC/_export_env.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +. ./config +export TET_INSTALL_PATH=$TET_INSTALL_HOST_PATH # tetware root path +export TET_TARGET_PATH=$TET_INSTALL_PATH/tetware-target # tetware target path +#export TET_TARGET_PATH=$TET_INSTALL_PATH/tetware-simulator # tetware simulator path +export PATH=$TET_TARGET_PATH/bin:$PATH +export LD_LIBRARY_PATH=$TET_TARGET_PATH/lib/tet3:$LD_LIBRARY_PATH +export TET_ROOT=$TET_TARGET_PATH diff --git a/TC/_export_target_env.sh b/TC/_export_target_env.sh new file mode 100755 index 0000000..c693f83 --- /dev/null +++ b/TC/_export_target_env.sh @@ -0,0 +1,8 @@ +#!/bin/sh +. ./config +export TET_INSTALL_PATH=$TET_INSTALL_TARGET_PATH # path to path +export TET_TARGET_PATH=$TET_INSTALL_PATH/tetware-target +#export TET_TARGET_PATH=$TET_INSTALL_PATH/tetware-simulator # tetware simulator path +export PATH=$TET_TARGET_PATH/bin:$PATH +export LD_LIBRARY_PATH=$TET_TARGET_PATH/lib/tet3:$LD_LIBRARY_PATH +export TET_ROOT=$TET_TARGET_PATH diff --git a/TC/build.sh b/TC/build.sh new file mode 100755 index 0000000..72aad6c --- /dev/null +++ b/TC/build.sh @@ -0,0 +1,16 @@ +#!/bin/sh + +. ./_export_env.sh # setting environment variables + +export TET_SUITE_ROOT=`pwd` +FILE_NAME_EXTENSION=`date +%s` + +RESULT_DIR=results +HTML_RESULT=$RESULT_DIR/build-tar-result-$FILE_NAME_EXTENSION.html +JOURNAL_RESULT=$RESULT_DIR/build-tar-result-$FILE_NAME_EXTENSION.journal + +mkdir -p $RESULT_DIR + +tcc -c -p ./ +tcc -b -j $JOURNAL_RESULT -p ./ +grw -c 7 -f chtml -o $HTML_RESULT $JOURNAL_RESULT diff --git a/TC/clean.sh b/TC/clean.sh new file mode 100755 index 0000000..29743e0 --- /dev/null +++ b/TC/clean.sh @@ -0,0 +1,11 @@ +#!/bin/sh + +. ./_export_env.sh # setting environment variables + +export TET_SUITE_ROOT=`pwd` +RESULT_DIR=results + +tcc -c -p ./ # executing tcc, with clean option (-c) +rm -r $RESULT_DIR +rm -r tet_tmp_dir +rm testcase/tet_captured diff --git a/TC/config b/TC/config new file mode 100644 index 0000000..bdfec87 --- /dev/null +++ b/TC/config @@ -0,0 +1,4 @@ +PKG_NAME=capi-network-bluetooth +TET_INSTALL_HOST_PATH=/var/tmp/dts_fw/TC/TETware +TET_INSTALL_TARGET_PATH=/opt/home/$PKG_NAME/TETware + diff --git a/TC/execute.sh b/TC/execute.sh new file mode 100755 index 0000000..0fe02e2 --- /dev/null +++ b/TC/execute.sh @@ -0,0 +1,15 @@ +#!/bin/sh + +. ./_export_target_env.sh # setting environment variables + +export TET_SUITE_ROOT=`pwd` +FILE_NAME_EXTENSION=`date +%s` + +RESULT_DIR=results +HTML_RESULT=$RESULT_DIR/exec-tar-result-$FILE_NAME_EXTENSION.html +JOURNAL_RESULT=$RESULT_DIR/exec-tar-result-$FILE_NAME_EXTENSION.journal + +mkdir -p $RESULT_DIR + +tcc -e -j $JOURNAL_RESULT -p ./ +grw -c 7 -f chtml -o $HTML_RESULT $JOURNAL_RESULT diff --git a/TC/push.sh b/TC/push.sh new file mode 100755 index 0000000..5eb9510 --- /dev/null +++ b/TC/push.sh @@ -0,0 +1,13 @@ +#!/bin/sh + +. ./config + +TC_PATH=/opt/home/$PKG_NAME + +echo $TC_PATH + +sdb shell "mkdir -p $TC_PATH" + +sdb push . $TC_PATH + + diff --git a/TC/run.sh b/TC/run.sh new file mode 100755 index 0000000..cec5778 --- /dev/null +++ b/TC/run.sh @@ -0,0 +1,15 @@ +#!/bin/sh + +source ./_export_target_env.sh + +export TET_SUITE_ROOT=`pwd` +FILE_NAME_EXTENSION=`date +%s` + +RESULT_DIR=results +HTML_RESULT=$RESULT_DIR/exec-tar-result-$FILE_NAME_EXTENSION.html +JOURNAL_RESULT=$RESULT_DIR/exec-tar-result-$FILE_NAME_EXTENSION.journal + +mkdir -p $RESULT_DIR + +tcc -e -j $JOURNAL_RESULT -p ./ +grw -c 7 -f chtml -o $HTML_RESULT $JOURNAL_RESULT diff --git a/TC/testcase/Makefile b/TC/testcase/Makefile new file mode 100644 index 0000000..7d86802 --- /dev/null +++ b/TC/testcase/Makefile @@ -0,0 +1,24 @@ +CC ?= gcc + +C_FILES = $(shell ls *.c) + +PKGS = capi-network-bluetooth glib-2.0 + +LDFLAGS = `pkg-config --libs $(PKGS)` +LDFLAGS += $(TET_ROOT)/lib/tet3/tcm_s.o +LDFLAGS += -L$(TET_ROOT)/lib/tet3 -ltcm_s +LDFLAGS += -L$(TET_ROOT)/lib/tet3 -lapi_s + +CFLAGS = -I. `pkg-config --cflags $(PKGS)` +CFLAGS += -I$(TET_ROOT)/inc/tet3 +CFLAGS += -Wall + +TCS := $(shell ls -1 *.c | cut -d. -f1) + +all: $(TCS) + +%: %.c + $(CC) -o $@ $< $(CFLAGS) $(LDFLAGS) + +clean: + rm -f $(TCS) diff --git a/TC/testcase/tslist b/TC/testcase/tslist new file mode 100644 index 0000000..c3d5dd0 --- /dev/null +++ b/TC/testcase/tslist @@ -0,0 +1,28 @@ +/testcase/utc_network_bluetooth_adapter_positive +/testcase/utc_network_bluetooth_adapter_negative +/testcase/utc_network_bluetooth_audio_negative +/testcase/utc_network_bluetooth_audio_positive +/testcase/utc_network_bluetooth_device_positive +/testcase/utc_network_bluetooth_device_negative +/testcase/utc_network_bluetooth_device_discovery_positive +/testcase/utc_network_bluetooth_device_discovery_negative +/testcase/utc_network_bluetooth_service_search_positive +/testcase/utc_network_bluetooth_service_search_negative +/testcase/utc_network_bluetooth_socket_positive +/testcase/utc_network_bluetooth_socket_negative +/testcase/utc_network_bluetooth_gatt_negative +/testcase/utc_network_bluetooth_gatt_positive +/testcase/utc_network_bluetooth_hid_negative +/testcase/utc_network_bluetooth_hid_positive +/testcase/utc_network_bluetooth_hdp_negative +/testcase/utc_network_bluetooth_hdp_positive +/testcase/utc_network_bluetooth_opp-server_negative +/testcase/utc_network_bluetooth_opp-server_positive +/testcase/utc_network_bluetooth_opp-client_negative +/testcase/utc_network_bluetooth_opp-client_positive +/testcase/utc_network_bluetooth_pan_negative +/testcase/utc_network_bluetooth_pan_positive +/testcase/utc_network_bluetooth_avrcp_negative +/testcase/utc_network_bluetooth_avrcp_positive +/testcase/utc_network_bluetooth_common_negative +/testcase/utc_network_bluetooth_common_positive \ No newline at end of file diff --git a/TC/testcase/utc_network_bluetooth_adapter_negative.c b/TC/testcase/utc_network_bluetooth_adapter_negative.c new file mode 100755 index 0000000..a7e2750 --- /dev/null +++ b/TC/testcase/utc_network_bluetooth_adapter_negative.c @@ -0,0 +1,429 @@ +/* + * 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 +#include +#include +#include +#include +#include + +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; + +static void startup(void); +static void cleanup(void); +bt_adapter_visibility_mode_e adapter_visibility_mode = + BT_ADAPTER_VISIBILITY_MODE_LIMITED_DISCOVERABLE; +char adapter_name[128] = "dts_test"; + +void (*tet_startup)(void) = startup; +void (*tet_cleanup)(void) = cleanup; + + +static void utc_network_bluetooth_deinitialize_n(void); +static void utc_network_bluetooth_adapter_set_state_changed_cb_n(void); +static void utc_network_bluetooth_adapter_set_name_changed_cb_n(void); +static void utc_network_bluetooth_adapter_set_visibility_mode_changed_cb_n(void); +static void utc_network_bluetooth_adapter_set_connectable_changed_cb_n(void); +static void utc_network_bluetooth_adapter_enable_n(void); +static void utc_network_bluetooth_adapter_get_state_n(void); +static void utc_network_bluetooth_adapter_get_address_n(void); +static void utc_network_bluetooth_adapter_set_name_n(void); +static void utc_network_bluetooth_adapter_get_name_n(void); +static void utc_network_bluetooth_adapter_set_visibility_n(void); +static void utc_network_bluetooth_adapter_get_visibility_n(void); +static void utc_network_bluetooth_adapter_add_white_list_n(void); +static void utc_network_bluetooth_adapter_clear_white_list_n(void); +static void utc_network_bluetooth_adapter_remove_white_list_n(void); +static void utc_network_bluetooth_adapter_set_connectable_n(void); +static void utc_network_bluetooth_adapter_get_connectable_n(void); +static void utc_network_bluetooth_adapter_disable_n(void); +static void utc_network_bluetooth_adapter_unset_state_changed_cb_n(void); +static void utc_network_bluetooth_adapter_unset_name_changed_cb_n(void); +static void utc_network_bluetooth_adapter_unset_visibility_mode_changed_cb_n(void); +static void utc_network_bluetooth_adapter_unset_connectable_changed_cb_n(void); +static void utc_network_bluetooth_adapter_set_le_state_changed_cb_n(void); +static void utc_network_bluetooth_adapter_unset_le_state_changed_cb_n(void); +static void utc_network_bluetooth_adapter_le_enable_n(void); +static void utc_network_bluetooth_adapter_get_le_state_n(void); +static void utc_network_bluetooth_adapter_le_disable_n(void); + +void adapter_state_changed_cb_for_adapter_n(int result, + bt_adapter_state_e adapter_state, + void *user_data); +gboolean timeout_func(gpointer data); + +struct tet_testlist tet_testlist[] = { + {utc_network_bluetooth_adapter_disable_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_adapter_set_state_changed_cb_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_adapter_set_name_changed_cb_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_adapter_set_visibility_mode_changed_cb_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_adapter_set_connectable_changed_cb_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_adapter_get_state_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_adapter_get_address_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_adapter_set_name_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_adapter_get_name_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_adapter_get_visibility_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_adapter_set_visibility_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_adapter_le_disable_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_adapter_add_white_list_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_adapter_remove_white_list_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_adapter_clear_white_list_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_adapter_get_connectable_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_deinitialize_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_adapter_set_connectable_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_adapter_enable_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_adapter_unset_connectable_changed_cb_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_adapter_unset_state_changed_cb_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_adapter_unset_name_changed_cb_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_adapter_unset_visibility_mode_changed_cb_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_adapter_set_le_state_changed_cb_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_adapter_get_le_state_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_adapter_le_enable_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_adapter_unset_le_state_changed_cb_n, NEGATIVE_TC_IDX}, + {NULL, 0}, +}; + +static void startup(void) +{ + /* start of TC */ + tet_printf("TC start."); + bt_initialize(); +} + +static void cleanup(void) +{ + /* end of TC */ + tet_printf("TC end"); +} + +/** + * @brief Negative test case of bt_deinitialize() + */ +static void utc_network_bluetooth_deinitialize_n(void) +{ + int ret = bt_deinitialize(); + + if (ret == BT_ERROR_NONE) { + ret = bt_deinitialize(); + dts_check_eq("bt_deinitialize", ret, BT_ERROR_NOT_INITIALIZED, + "BT_ERROR_NOT_INITIALIZED must be returned."); + } else { + dts_fail("bt_deinitialize", "bt_deinitialize() failed."); + } +} + +/** + * @brief Negative test case of bt_adapter_disable() + */ +static void utc_network_bluetooth_adapter_disable_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_adapter_disable(); + dts_check_eq("bt_adapter_disable", ret, BT_ERROR_NOT_ENABLED, + "BT_ERROR_NOT_ENABLED must be returned when BT is disabled"); +} + +/** + * @brief Negative test case of bt_adapter_set_state_changed_cb() + */ +static void utc_network_bluetooth_adapter_set_state_changed_cb_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_adapter_set_state_changed_cb(NULL, NULL); + dts_check_eq("bt_adapter_set_state_changed_cb", ret, + BT_ERROR_INVALID_PARAMETER, + "BT_ERROR_INVALID_PARAMETER must be returned when parameter is NULL."); +} + +/** + * @brief Negative test case of bt_adapter_set_name_changed_cb() + */ +static void utc_network_bluetooth_adapter_set_name_changed_cb_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_adapter_set_name_changed_cb(NULL, NULL); + dts_check_eq("bt_adapter_set_name_changed_cb", ret, + BT_ERROR_INVALID_PARAMETER, + "BT_ERROR_INVALID_PARAMETER must be returned when parameter is NULL."); +} + +/** + * @brief Negative test case of bt_adapter_set_visibility_mode_changed_cb() + */ +static void utc_network_bluetooth_adapter_set_visibility_mode_changed_cb_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_adapter_set_visibility_mode_changed_cb(NULL, NULL); + dts_check_eq("bt_adapter_set_visibility_mode_changed_cb", ret, + BT_ERROR_INVALID_PARAMETER, + "BT_ERROR_INVALID_PARAMETER must be returned when parameter is NULL."); +} + +/** + * @brief Negative test case of bt_adapter_set_connectable_changed_cb() + */ +static void utc_network_bluetooth_adapter_set_connectable_changed_cb_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_adapter_set_connectable_changed_cb(NULL, NULL); + dts_check_eq("bt_adapter_set_connectable_changed_cb", ret, + BT_ERROR_INVALID_PARAMETER, + "BT_ERROR_INVALID_PARAMETER must be returned when parameter is NULL."); +} + +/** + * @brief Negative test case of bt_adapter_get_state() + */ +static void utc_network_bluetooth_adapter_get_state_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_adapter_get_state(NULL); + dts_check_eq("bt_adapter_get_state", ret, BT_ERROR_INVALID_PARAMETER, + "BT_ERROR_INVALID_PARAMETER must be returned when parameter is NULL."); +} + +/** + * @brief Negative test case of bt_adapter_get_address(). + */ +static void utc_network_bluetooth_adapter_get_address_n(void) +{ + char *address = NULL; + int ret = bt_adapter_get_address(&address); + + dts_check_eq("bt_adapter_get_address", ret, BT_ERROR_NOT_ENABLED, + "BT_ERROR_NOT_ENABLED must be returned when BT is not enabled."); +} + +/** + * @brief Negative test case of bt_adapter_get_name(). + */ +static void utc_network_bluetooth_adapter_get_name_n(void) +{ + char *name = NULL; + int ret = bt_adapter_get_name(&name); + + dts_check_eq("bt_adapter_get_name", ret, BT_ERROR_NOT_ENABLED, + "BT_ERROR_NOT_ENABLED must be returned when BT is not enabled."); +} + +/** + * @brief Negative test case of bt_adapter_get_visibility(). + */ +static void utc_network_bluetooth_adapter_get_visibility_n(void) +{ + int dur = 10; + int ret = bt_adapter_get_visibility(NULL, &dur); + + dts_check_eq("bt_adapter_get_visibility", ret, BT_ERROR_INVALID_PARAMETER, + "BT_ERROR_INVALID_PARAMETER must be returned when parameter is NULL."); +} + +/** + * @brief Negative test case of bt_adapter_set_name(). + */ +static void utc_network_bluetooth_adapter_set_name_n(void) +{ + int ret = bt_adapter_set_name(NULL); + dts_check_eq("bt_adapter_set_name", ret, BT_ERROR_INVALID_PARAMETER, + "BT_ERROR_INVALID_PARAMETER must be returned when parameter is NULL."); +} + +/** + * @brief Negative test case of bt_adapter_set_visibility(). + */ +static void utc_network_bluetooth_adapter_set_visibility_n(void) +{ + int ret = bt_adapter_set_visibility(adapter_visibility_mode, 180); + + dts_check_eq("bt_adapter_set_visibility", ret, BT_ERROR_NOT_ENABLED, + "BT_ERROR_NOT_ENABLED must be returned when BT is not enabled."); +} + +/** + * @brief Negative test case of bt_adapter_le_add_white_list + */ +static void utc_network_bluetooth_adapter_add_white_list_n(void) +{ + int ret = bt_adapter_le_add_white_list(NULL); + dts_check_eq("bt_adapter_le_add_white_list", ret, BT_ERROR_INVALID_PARAMETER, + "BT_ERROR_INVALID_PARAMETER must be returned when parameter is NULL."); +} + +/** + * @brief Negative test case of bt_adapter_clear_white_list + */ +static void utc_network_bluetooth_adapter_clear_white_list_n(void) +{ + int ret = BT_ERROR_NONE; + ret = bt_adapter_clear_white_list(); + dts_check_eq("bt_adapter_clear_white_list", ret, BT_ERROR_NOT_ENABLED, + "BT_ERROR_NOT_ENABLED must be returned when BT is not enabled."); +} + +/** + * @brief Negative test case of bt_adapter_le_add_white_list + */ +static void utc_network_bluetooth_adapter_remove_white_list_n(void) +{ + int ret = bt_adapter_le_remove_white_list(NULL); + dts_check_eq("bt_adapter_le_remove_white_list", ret, BT_ERROR_INVALID_PARAMETER, + "BT_ERROR_INVALID_PARAMETER must be returned when parameter is NULL."); +} + +/** + * @brief Negative test case of bt_adapter_get_connectable + */ +static void utc_network_bluetooth_adapter_get_connectable_n(void) +{ + int ret = bt_adapter_get_connectable(NULL); + dts_check_eq("bt_adapter_get_connectable", ret, BT_ERROR_INVALID_PARAMETER, + "BT_ERROR_INVALID_PARAMETER must be returned when parameter is NULL."); +} + +/** + * @brief Negative test case of bt_adapter_set_connectable + */ +static void utc_network_bluetooth_adapter_set_connectable_n(void) +{ + int ret = bt_adapter_set_connectable(NULL); + dts_check_eq("bt_adapter_set_connectable", ret, BT_ERROR_NOT_INITIALIZED, + "BT_ERROR_NOT_INITIALIZED must be returned when BT is not initialized."); +} + +/** + * @brief Negative test case of bt_adapter_unset_state_changed_cb() + */ +static void utc_network_bluetooth_adapter_unset_state_changed_cb_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_adapter_unset_state_changed_cb(); + dts_check_eq("bt_adapter_unset_state_changed_cb", ret, + BT_ERROR_NOT_INITIALIZED, + "BT_ERROR_NOT_INITIALIZED must be returned when BT service is not initialized."); +} + +/** + * @brief Negative test case of bt_adapter_unset_name_changed_cb() + */ +static void utc_network_bluetooth_adapter_unset_name_changed_cb_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_adapter_unset_name_changed_cb(); + dts_check_eq("bt_adapter_unset_name_changed_cb", ret, + BT_ERROR_NOT_INITIALIZED, + "BT_ERROR_NOT_INITIALIZED must be returned when BT service is not initialized."); +} + +/** + * @brief Negative test case of bt_adapter_unset_visibility_mode_changed_cb() + */ +static void +utc_network_bluetooth_adapter_unset_visibility_mode_changed_cb_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_adapter_unset_visibility_mode_changed_cb(); + dts_check_eq("bt_adapter_unset_visibility_mode_changed_cb", ret, + BT_ERROR_NOT_INITIALIZED, + "BT_ERROR_NOT_INITIALIZED must be returned when BT service is not initialized."); +} + +/** + * @brief Negative test case of bt_adapter_enable() + */ +static void utc_network_bluetooth_adapter_enable_n(void) +{ + bt_error_e ret = bt_adapter_enable(); + dts_check_eq("bt_adapter_enable", ret, BT_ERROR_NOT_INITIALIZED, + "BT_ERROR_NOT_INITIALIZED must be returned."); +} + +/** + * @brief Negative test case of bt_adapter_unset_connectable_changed_cb() + */ +static void utc_network_bluetooth_adapter_unset_connectable_changed_cb_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_adapter_unset_connectable_changed_cb(); + dts_check_eq("bt_adapter_unset_connectable_changed_cb", ret, + BT_ERROR_NOT_INITIALIZED, + "bt_adapter_unset_connectable_changed_cb() failed."); +} + +/** + * @brief Negative test case of bt_adapter_le_set_state_changed_cb() + */ +static void utc_network_bluetooth_adapter_set_le_state_changed_cb_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_adapter_le_set_state_changed_cb(NULL, NULL); + dts_check_eq("bt_adapter_le_set_state_changed_cb", ret, + BT_ERROR_INVALID_PARAMETER, + "BT_ERROR_INVALID_PARAMETER must be returned when parameter is NULL."); +} + +static void utc_network_bluetooth_adapter_le_enable_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_adapter_le_enable(); + dts_check_eq("bt_adapter_le_enable", ret, + BT_ERROR_NOT_INITIALIZED, + "BT_ERROR_NOT_INITIALIZED must be returned."); +} + +static void utc_network_bluetooth_adapter_le_disable_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_adapter_le_disable(); + dts_check_eq("bt_adapter_disable", ret, BT_ERROR_NOT_ENABLED, + "BT_ERROR_NOT_ENABLED must be returned when BT is disabled"); +} + +static void utc_network_bluetooth_adapter_get_le_state_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_adapter_le_get_state(NULL); + dts_check_eq("bt_adapter_get_state", ret, BT_ERROR_INVALID_PARAMETER, + "BT_ERROR_INVALID_PARAMETER must be returned when parameter is NULL."); +} + +static void utc_network_bluetooth_adapter_unset_le_state_changed_cb_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_adapter_le_unset_state_changed_cb(); + dts_check_eq("bt_adapter_unset_state_changed_cb", ret, + BT_ERROR_NOT_INITIALIZED, + "BT_ERROR_NOT_INITIALIZED must be returned"); +} diff --git a/TC/testcase/utc_network_bluetooth_adapter_positive.c b/TC/testcase/utc_network_bluetooth_adapter_positive.c new file mode 100755 index 0000000..7a6ac13 --- /dev/null +++ b/TC/testcase/utc_network_bluetooth_adapter_positive.c @@ -0,0 +1,797 @@ +/* + * 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 +#include +#include +#include +#include +#include + +#define CONFIG_FILE_PATH "/opt/home/capi-network-bluetooth/tetware.conf" + +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; + +static void startup(void); +static void cleanup(void); +char *remote_address; +static GMainLoop *mainloop; +static bool callback_result = false; +bt_adapter_visibility_mode_e adapter_visibility_mode = + BT_ADAPTER_VISIBILITY_MODE_LIMITED_DISCOVERABLE; +char adapter_name[128] = "dts_test"; + +void (*tet_startup)(void) = startup; +void (*tet_cleanup)(void) = cleanup; + +static void utc_network_bluetooth_initialize_p(void); +static void utc_network_bluetooth_deinitialize_p(void); +static void utc_network_bluetooth_adapter_set_state_changed_cb_p(void); +static void utc_network_bluetooth_adapter_set_name_changed_cb_p(void); +static void utc_network_bluetooth_adapter_set_visibility_mode_changed_cb_p(void); +static void utc_network_bluetooth_adapter_set_connectable_changed_cb_p(void); +static void utc_network_bluetooth_adapter_enable_p(void); +static void utc_network_bluetooth_adapter_get_state_p(void); +static void utc_network_bluetooth_adapter_get_address_p(void); +static void utc_network_bluetooth_adapter_set_name_p(void); +static void utc_network_bluetooth_adapter_get_name_p(void); +static void utc_network_bluetooth_adapter_set_visibility_p(void); +static void utc_network_bluetooth_adapter_get_visibility_p(void); +static void utc_network_bluetooth_adapter_add_white_list_p(void); +static void utc_network_bluetooth_adapter_remove_white_list_p(void); +static void utc_network_bluetooth_adapter_clear_white_list_p(void); +static void utc_network_bluetooth_adapter_set_connectable_p(void); +static void utc_network_bluetooth_adapter_get_connectable_p(void); +static void utc_network_bluetooth_adapter_disable_p(void); +static void utc_network_bluetooth_adapter_unset_state_changed_cb_p(void); +static void utc_network_bluetooth_adapter_unset_name_changed_cb_p(void); +static void utc_network_bluetooth_adapter_unset_visibility_mode_changed_cb_p(void); +static void utc_network_bluetooth_adapter_unset_connectable_changed_cb_p(void); +static void utc_network_bluetooth_adapter_set_le_state_changed_cb_p(void); +static void utc_network_bluetooth_adapter_le_enable_p(void); +static void utc_network_bluetooth_adapter_get_le_state_p(void); +static void utc_network_bluetooth_adapter_le_disable_p(void); +static void utc_network_bluetooth_adapter_unset_le_state_changed_cb_p(void); + +void adapter_state_changed_cb_for_adapter_p(int result, + bt_adapter_state_e adapter_state, + void *user_data); +void adapter_state_changed_cb_for_adapter_p(int result, + bt_adapter_state_e adapter_state, + void *user_data); +void adapter_name_changed_cb_for_adapter_p(char *device_name, void *user_data); +void adapter_visibility_mode_changed_cb_for_adpater_p(int result, + bt_adapter_visibility_mode_e visibility_mode, + void *user_data); +void device_discovery_state_changed_cb_for_adapter_p(int result, + bt_adapter_device_discovery_state_e discovery_state, + bt_device_info_s *device_info, + void *user_data); +void adapter_connectable_changed_cb_for_adpater_p(int result, + bool connectable, void *user_data); +gboolean timeout_func(gpointer data); + +struct tet_testlist tet_testlist[] = { + {utc_network_bluetooth_initialize_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_adapter_enable_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_adapter_set_state_changed_cb_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_adapter_unset_state_changed_cb_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_adapter_get_state_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_adapter_get_address_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_adapter_get_name_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_adapter_set_name_changed_cb_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_adapter_unset_name_changed_cb_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_adapter_set_connectable_changed_cb_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_adapter_set_name_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_adapter_set_visibility_mode_changed_cb_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_adapter_unset_visibility_mode_changed_cb_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_adapter_get_visibility_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_adapter_set_visibility_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_adapter_get_connectable_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_adapter_set_connectable_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_adapter_unset_connectable_changed_cb_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_adapter_le_enable_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_adapter_add_white_list_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_adapter_remove_white_list_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_adapter_clear_white_list_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_adapter_set_le_state_changed_cb_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_adapter_unset_le_state_changed_cb_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_adapter_get_le_state_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_adapter_le_disable_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_adapter_disable_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_deinitialize_p, POSITIVE_TC_IDX}, + {NULL, 0}, +}; + +int get_value_from_file(void) +{ + FILE *fp; + char *token; + char buf[100]; + + fp = fopen(CONFIG_FILE_PATH, "r"); + if (fp == NULL) { + tet_printf("Default configuration is used\n"); + return -1; + } + while (fgets(buf, sizeof(buf), fp)) { + if (buf[0] == '#' || buf[0] == '\n') + continue; + + token = strrchr(buf, '\n'); + if (token == NULL) { + tet_printf("g_conf is too long\n"); + break; + } + *token = '\0'; + + token = strtok(buf, "="); + if (token == NULL) { + continue; + } + if (strcasecmp(token, "BT_ADDR_MOBILE") == 0) { + token = strtok(NULL, "="); + remote_address = strdup(token); + fclose(fp); + return 0; + } + } + fclose(fp); + return -1; +} + +static void startup(void) +{ + if(get_value_from_file() == -1) { + tet_printf("Failed to read."); + } + + /* start of TC */ + tet_printf("TC start."); + mainloop = g_main_loop_new(NULL, FALSE); +} + +static void cleanup(void) +{ + /* end of TC */ + tet_printf("TC end"); +} + +gboolean timeout_func(gpointer data) +{ + tet_printf("Callback: Timeout."); + g_main_loop_quit((GMainLoop *)data); + return FALSE; +} + +/** + * @brief Callback funtions + */ +void adapter_state_changed_cb_for_adapter_p(int result, + bt_adapter_state_e adapter_state, + void *user_data) +{ + if (user_data != NULL && !strcmp((char *)user_data, "enable")) { + if (adapter_state == BT_ADAPTER_ENABLED && result == BT_ERROR_NONE) { + tet_printf("Callback: BT was enabled."); + callback_result = true; + } else { + tet_printf("Callback: BT was not enabled."); + } + + if (mainloop) + g_main_loop_quit(mainloop); + } else if (user_data != NULL && !strcmp((char *)user_data, "disable")) { + if (adapter_state == BT_ADAPTER_DISABLED && result == BT_ERROR_NONE) { + tet_printf("Callback: BT was disabled."); + callback_result = true; + } else { + tet_printf("Callback: BT was not disabled."); + } + + if (mainloop) { + g_main_loop_quit(mainloop); + } + } +} + +void adapter_le_state_changed_cb_for_adapter_p(int result, + bt_adapter_le_state_e adapter_le_state, + void *user_data) +{ + if (user_data != NULL && !strcmp((char *)user_data, "enable")) { + if (adapter_le_state == BT_ADAPTER_LE_ENABLED && result == BT_ERROR_NONE) { + tet_printf("Callback: BT LE was enabled."); + callback_result = true; + } else { + tet_printf("Callback: BT LE was not enabled."); + } + + if (mainloop) + g_main_loop_quit(mainloop); + } else if (user_data != NULL && !strcmp((char *)user_data, "disable")) { + if (adapter_le_state == BT_ADAPTER_LE_DISABLED && result == BT_ERROR_NONE) { + tet_printf("Callback: BT LEwas disabled."); + callback_result = true; + } else { + tet_printf("Callback: BT LE was not disabled."); + } + + if (mainloop) { + g_main_loop_quit(mainloop); + } + } +} + +void device_discovery_state_changed_cb_for_adapter_p(int result, + bt_adapter_device_discovery_state_e discovery_state, + bt_device_info_s *device_info, + void *user_data) +{ + tet_printf("bt_adapter_device_discovery_state_changed_cb was called"); + + if (user_data != NULL && !strcmp((char *)user_data, "enable")) { + if (discovery_state == BT_ADAPTER_DEVICE_DISCOVERY_FINISHED) { + tet_printf("Callback: bt_adapter_device_discovery_state_changed_cb_for_adapter_p was called \ + and device discovery ends."); + if (mainloop) { + g_main_loop_quit(mainloop); + } + } + } +} + +void adapter_name_changed_cb_for_adapter_p(char *device_name, void *user_data) +{ + tet_printf("bt_adapter_name_changed_cb_for_adapter_p was called: %s", + (char *)device_name); + + if (user_data != NULL && !strcmp((char *)user_data, "set_name")) { + if (!strcmp(device_name, adapter_name)) + callback_result = true; + } + + if (mainloop) + g_main_loop_quit(mainloop); + +} + +void adapter_visibility_mode_changed_cb_for_adpater_p(int result, + bt_adapter_visibility_mode_e visibility_mode, + void *user_data) +{ + tet_printf("bt_adapter_visibility_mode_changed_cb was called: %d", visibility_mode); + + if (user_data != NULL && !strcmp((char *)user_data, "set_visibility")) { + if (result == BT_ERROR_NONE) { + if (visibility_mode == adapter_visibility_mode) { + callback_result = true; + } else { + tet_printf("Callback: adapter_visibility_mode_changed_cb_for_adpater_p() was called but visibility mode is not same."); + tet_printf("Callback: actual visibility mode : %d", visibility_mode); + callback_result = false; + } + } else { + tet_printf("\n Callback: adapter_visibility_mode_changed_cb_for_adpater_p() was called but failed."); + callback_result = false; + } + } + + if (mainloop) + g_main_loop_quit(mainloop); +} + +void adapter_connectable_changed_cb_for_adpater_p(int result, bool connectable, + void *user_data) +{ + tet_printf("adapter_connectable_changed_cb_for_adapter_p was called."); + if (result == BT_ERROR_NONE) { + tet_printf("Callback: Connectable Changed"); + tet_printf("%s", connectable ? "Connectable" : "Non-connectable"); + callback_result = true; + } else { + tet_printf("Callback: adapter_connectable_changed_cb_for_adpater_p() was called but failed."); + callback_result = false; + } + if (mainloop) + g_main_loop_quit(mainloop); +} + +/** + * @brief Positive test case of bt_initialize() + */ +static void utc_network_bluetooth_initialize_p(void) +{ + int ret = bt_initialize(); + dts_check_eq("bt_initialize", ret, BT_ERROR_NONE, + "bt_initialize() failed."); +} + +/** + * @brief Positive test case of bt_deinitialize() + */ +static void utc_network_bluetooth_deinitialize_p(void) +{ + int ret = bt_deinitialize(); + dts_check_eq("bt_deinitialize", ret, + BT_ERROR_NONE, "bt_deinitialize() failed."); +} + +/** + * @brief Positive test case of bt_adapter_set_state_changed_cb() + */ +static void utc_network_bluetooth_adapter_set_state_changed_cb_p(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_adapter_set_state_changed_cb(adapter_state_changed_cb_for_adapter_p, NULL); + dts_check_eq("bt_adapter_set_state_changed_cb", ret, BT_ERROR_NONE, + "bt_adapter_set_state_changed_cb failed."); +} + +/** + * @brief Positive test case of bt_adapter_set_name_changed_cb() + */ +static void utc_network_bluetooth_adapter_set_name_changed_cb_p(void) +{ + int ret = BT_ERROR_NONE; + int timeout_id = 0; + + ret = bt_adapter_set_name_changed_cb(adapter_name_changed_cb_for_adapter_p, NULL); + if (ret == BT_ERROR_NONE) { + timeout_id = g_timeout_add(10000, timeout_func, mainloop); + g_main_loop_run(mainloop); + g_source_remove(timeout_id); + } + dts_check_eq("bt_adapter_set_name_changed_cb", ret, BT_ERROR_NONE, + "bt_adapter_set_name_changed_cb failed."); +} + +/** + * @brief Positive test case of bt_adapter_set_visibility_mode_changed_cb() + */ +static void utc_network_bluetooth_adapter_set_visibility_mode_changed_cb_p(void) +{ + int ret = BT_ERROR_NONE; + int timeout_id = 0; + + ret = bt_adapter_set_visibility_mode_changed_cb( + adapter_visibility_mode_changed_cb_for_adpater_p, NULL); + if (ret == BT_ERROR_NONE) { + timeout_id = g_timeout_add(10000, timeout_func, mainloop); + g_main_loop_run(mainloop); + g_source_remove(timeout_id); + } + dts_check_eq("bt_adapter_set_visibility_mode_changed_cb", ret, + BT_ERROR_NONE, + "bt_adapter_set_visibility_mode_changed_cb failed."); +} + +static void utc_network_bluetooth_adapter_set_connectable_changed_cb_p(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_adapter_set_connectable_changed_cb( + adapter_connectable_changed_cb_for_adpater_p, NULL); + dts_check_eq("bt_adapter_set_connectable_changed_cb", ret, + BT_ERROR_NONE, + "bt_adapter_set_connectable_changed_cb failed."); +} + +/** + * @brief Positive test case of bt_adapter_enable() + */ +static void utc_network_bluetooth_adapter_enable_p(void) +{ + int timeout_id = 0; + callback_result = false; + bt_error_e ret = BT_ERROR_NONE; + + if (bt_adapter_set_state_changed_cb(adapter_state_changed_cb_for_adapter_p, "enable") != BT_ERROR_NONE) { + dts_fail("bt_adapter_enable", + "bt_adapter_set_state_changed_cb() failed."); + } + + ret = bt_adapter_enable(); + if (ret == BT_ERROR_NONE) { + timeout_id = g_timeout_add(60000, timeout_func, mainloop); + g_main_loop_run(mainloop); + g_source_remove(timeout_id); + } else if (ret == BT_ERROR_ALREADY_DONE) { + callback_result = true; + } else { + dts_fail("bt_adapter_enable", "bt_adapter_enable() failed."); + bt_adapter_unset_state_changed_cb(); + return; + } + + tet_printf("callback_result: %d", callback_result); + bt_adapter_unset_state_changed_cb(); + dts_check_eq("bt_adapter_enable", callback_result, true, + "BT was not enabled."); +} + +/** + * @brief Positive test case of bt_adapter_get_state() + */ +static void utc_network_bluetooth_adapter_get_state_p(void) +{ + bt_adapter_state_e adapter_state = BT_ADAPTER_DISABLED; + int ret = BT_ERROR_NONE; + + ret = bt_adapter_get_state(&adapter_state); + if (ret == BT_ERROR_NONE && adapter_state == BT_ADAPTER_ENABLED) { + dts_pass("bt_adapter_get_state", + "bt_adapter_get_state() succeeded."); + } else { + dts_fail("bt_adapter_get_state", + "bt_adapter_get_state() failed."); + } +} + +/** + * @brief Positive test case of bt_adapter_get_address(). + */ +static void utc_network_bluetooth_adapter_get_address_p(void) +{ + char *address = NULL; + int ret = bt_adapter_get_address(&address); + + if (address != NULL) + tet_printf("device address: %s", address); + + dts_check_eq("bt_adapter_get_address", ret, BT_ERROR_NONE, + "bt_adapter_get_address() failed."); +} + +/** + * @brief Positive test case of bt_adapter_get_name(). + */ +static void utc_network_bluetooth_adapter_get_name_p(void) +{ + char *name = NULL; + int ret = bt_adapter_get_name(&name); + + if (name != NULL) + tet_printf("device name : %s", name); + + memset(adapter_name, 0x00, sizeof(adapter_name)); + g_strlcpy(adapter_name, name, sizeof(adapter_name)); + + dts_check_eq("bt_adapter_get_name", ret, BT_ERROR_NONE, \ + "bt_adapter_get_name() failed."); +} + +/** + * @brief Positive test case of bt_adapter_get_visibility(). + */ +static void utc_network_bluetooth_adapter_get_visibility_p(void) +{ + bt_adapter_visibility_mode_e mode = BT_ADAPTER_VISIBILITY_MODE_NON_DISCOVERABLE; + int dur = 1; + int ret = bt_adapter_get_visibility(&mode, &dur); + + tet_printf("visibility mode : %d", mode); + if (mode == BT_ADAPTER_VISIBILITY_MODE_NON_DISCOVERABLE) { + adapter_visibility_mode = BT_ADAPTER_VISIBILITY_MODE_LIMITED_DISCOVERABLE; + } else if (mode == BT_ADAPTER_VISIBILITY_MODE_GENERAL_DISCOVERABLE) { + adapter_visibility_mode = BT_ADAPTER_VISIBILITY_MODE_NON_DISCOVERABLE; + } else + adapter_visibility_mode = BT_ADAPTER_VISIBILITY_MODE_GENERAL_DISCOVERABLE; + + dts_check_eq("bt_adapter_get_visibility", ret, BT_ERROR_NONE, + "bt_adapter_get_visibility() failed."); +} + +/** + * @brief Positive test case of bt_adapter_set_name(). + */ +static void utc_network_bluetooth_adapter_set_name_p(void) +{ + int timeout_id = 0; + char name[128] = ""; + + snprintf(name, 128, "%s_1", adapter_name); + strncpy(adapter_name, name, 128); + + if (bt_adapter_set_name_changed_cb(adapter_name_changed_cb_for_adapter_p, "set_name") != BT_ERROR_NONE) { + dts_fail("bt_adapter_set_name", + "bt_adapter_set_name_changed_cb() failed."); + } + + if (bt_adapter_set_name(adapter_name) == BT_ERROR_NONE) { + tet_printf("adapter_name_changed_cb_for_adapter_p() will be called"); + timeout_id = g_timeout_add(60000, timeout_func, mainloop); + g_main_loop_run(mainloop); + g_source_remove(timeout_id); + bt_adapter_unset_name_changed_cb(); + dts_check_eq("bt_adapter_set_name", callback_result, true, + "The local adapter name was not set."); + } else { + dts_fail("bt_adapter_set_name", "bt_adapter_set_name() failed"); + } +} + +/** + * @brief Positive test case of bt_adapter_set_visibility(). + */ +static void utc_network_bluetooth_adapter_set_visibility_p(void) +{ + callback_result = false; + int timeout = 0; + int timeout_id = 0; + + if (bt_adapter_set_visibility_mode_changed_cb(adapter_visibility_mode_changed_cb_for_adpater_p, "set_visibility") != BT_ERROR_NONE) { + dts_fail("bt_adapter_set_visibility", + "bt_adapter_set_visibility_mode_changed_cb() failed."); + } + + tet_printf("set visibility mode: %d", adapter_visibility_mode); + if (adapter_visibility_mode == BT_ADAPTER_VISIBILITY_MODE_LIMITED_DISCOVERABLE) { + timeout = 90; + tet_printf("set timeout: %d", timeout); + } + + if (bt_adapter_set_visibility(adapter_visibility_mode, timeout) == BT_ERROR_NONE) { + tet_printf("bt_adapter_visibility_changed_cb() will be called"); + timeout_id = g_timeout_add(60000, timeout_func, mainloop); + g_main_loop_run(mainloop); + g_source_remove(timeout_id); + bt_adapter_unset_visibility_mode_changed_cb(); + dts_check_eq("bt_adapter_set_visibility", callback_result, true, + "The visibility of BT was not set."); + } else { + dts_fail("bt_adapter_set_visibility", + "bt_adapter_set_visibility() failed"); + } +} + +/** + * @brief Positive test case of bt_adapter_le_add_white_list + */ +static void utc_network_bluetooth_adapter_add_white_list_p(void) +{ + int ret = BT_ERROR_NONE; + ret = bt_adapter_le_add_white_list(remote_address); + dts_check_eq("bt_adapter_le_add_white_list", ret, BT_ERROR_NONE, + "bt_adapter_le_add_white_list() failed."); +} + +/** + * @brief Positive test case of bt_adapter_le_clear_white_list + */ +static void utc_network_bluetooth_adapter_clear_white_list_p(void) +{ + int ret = BT_ERROR_NONE; + ret = bt_adapter_le_clear_white_list(); + dts_check_eq("bt_adapter_le_clear_white_list", ret, BT_ERROR_NONE, + "bt_adapter_le_clear_white_list() failed."); +} + +/** + * @brief Positive test case of bt_adapter_le_remove_white_list + */ +static void utc_network_bluetooth_adapter_remove_white_list_p(void) +{ + int ret = BT_ERROR_NONE; + ret = bt_adapter_le_remove_white_list(remote_address); + dts_check_eq("bt_adapter_le_remove_white_list", ret, BT_ERROR_NONE, + "bt_adapter_le_remove_white_list() failed."); +} + +/** + * @brief Positive test case of bt_adapter_get_connectable + */ +static void utc_network_bluetooth_adapter_get_connectable_p(void) +{ + int ret = BT_ERROR_NONE; + bool connectable = false; + ret = bt_adapter_get_connectable(&connectable); + dts_check_eq("bt_adapter_get_connectable", ret, BT_ERROR_NONE, + "bt_adapter_get_connectable() failed."); +} + +/** + * @brief Positive test case of bt_adapter_set_connectable + */ +static void utc_network_bluetooth_adapter_set_connectable_p(void) +{ + int ret = BT_ERROR_NONE; + bool connectable = false; + int timeout_id = 0; + callback_result = false; + + ret = bt_adapter_get_connectable(&connectable); + ret = bt_adapter_set_connectable(!connectable); + if (ret == BT_ERROR_NONE) { + tet_printf("adapter_connectable_changed_cb will be called"); + timeout_id = g_timeout_add(60000, timeout_func, mainloop); + g_main_loop_run(mainloop); + g_source_remove(timeout_id); + dts_check_eq("bt_adapter_set_connectable", ret, BT_ERROR_NONE, + "bt_adapter_set_connectable() failed."); + } +} + +/** + * @brief Positive test case of bt_adapter_disable() + */ +static void utc_network_bluetooth_adapter_disable_p(void) +{ + callback_result = false; + int timeout_id = 0; + + if (bt_adapter_set_state_changed_cb(adapter_state_changed_cb_for_adapter_p, "disable") != BT_ERROR_NONE) { + dts_fail("bt_adapter_disable", + "bt_adapter_set_state_changed_cb() failed."); + } + + if (bt_adapter_disable() == BT_ERROR_NONE) { + tet_printf("bt_adapter_state_changed_cb() will be called"); + timeout_id = g_timeout_add(60000, timeout_func, mainloop); + g_main_loop_run(mainloop); + g_source_remove(timeout_id); + bt_adapter_unset_state_changed_cb(); + dts_check_eq("bt_adapter_disable", callback_result, true, + "BT was not disabled"); + } else { + dts_fail("bt_adapter_disable", "bt_adapter_disable() failed"); + } +} + +/** + * @brief Positive test case of bt_adapter_unset_state_changed_cb() + */ +static void utc_network_bluetooth_adapter_unset_state_changed_cb_p(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_adapter_unset_state_changed_cb(); + dts_check_eq("bt_adapter_unset_state_changed_cb", ret, BT_ERROR_NONE, + "bt_adapter_unset_state_changed_cb() failed."); +} + +/** + * @brief Positive test case of bt_adapter_unset_name_changed_cb() + */ +static void utc_network_bluetooth_adapter_unset_name_changed_cb_p(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_adapter_unset_name_changed_cb(); + dts_check_eq("bt_adapter_unset_name_changed_cb", ret, BT_ERROR_NONE, + "bt_adapter_unset_name_changed_cb() failed."); +} + +/** + * @brief Positive test case of bt_adapter_unset_visibility_mode_changed_cb() + */ +static void utc_network_bluetooth_adapter_unset_visibility_mode_changed_cb_p(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_adapter_unset_visibility_mode_changed_cb(); + dts_check_eq("bt_adapter_unset_visibility_mode_changed_cb", ret, + BT_ERROR_NONE, + "bt_adapter_unset_visibility_mode_changed_cb() failed."); +} + +/** + * @brief Positive test case of bt_adapter_unset_connectable_changed_cb() + */ +static void utc_network_bluetooth_adapter_unset_connectable_changed_cb_p(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_adapter_unset_connectable_changed_cb(); + dts_check_eq("bt_adapter_unset_connectable_changed_cb", ret, + BT_ERROR_NONE, + "bt_adapter_unset_connectable_changed_cb() failed."); +} + +/** + * @brief Positive test case of bt_adapter_le_set_state_changed_cb() + */ +static void utc_network_bluetooth_adapter_set_le_state_changed_cb_p(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_adapter_le_set_state_changed_cb( + adapter_le_state_changed_cb_for_adapter_p, NULL); + dts_check_eq("bt_adapter_le_set_state_changed_cb", ret, BT_ERROR_NONE, + "bt_adapter_set_state_le_state_changed_cb failed."); +} + +static void utc_network_bluetooth_adapter_le_enable_p(void) +{ + int timeout_id = 0; + callback_result = false; + bt_error_e ret = BT_ERROR_NONE; + + if (bt_adapter_le_set_state_changed_cb(adapter_le_state_changed_cb_for_adapter_p, "enable") != BT_ERROR_NONE) { + dts_fail("bt_adapter_le_enable", + "bt_adapter_le_set_state_changed_cb() failed."); + } + + ret = bt_adapter_le_enable(); + if (ret == BT_ERROR_NONE) { + timeout_id = g_timeout_add(60000, timeout_func, mainloop); + g_main_loop_run(mainloop); + g_source_remove(timeout_id); + } else if (ret == BT_ERROR_ALREADY_DONE) { + callback_result = true; + } else { + dts_fail("bt_adapter_le_enable", "bt_adapter_le_enable() failed."); + bt_adapter_le_unset_state_changed_cb(); + return; + } + + tet_printf("callback_result: %d", callback_result); + bt_adapter_le_unset_state_changed_cb(); + dts_check_eq("bt_adapter_le_enable", callback_result, true, + "BT LE was not enabled."); +} + +static void utc_network_bluetooth_adapter_le_disable_p(void) +{ + callback_result = false; + int timeout_id = 0; + + if (bt_adapter_le_set_state_changed_cb(adapter_le_state_changed_cb_for_adapter_p, "disable") != BT_ERROR_NONE) { + dts_fail("bt_adapter_le_disable", + "bt_adapter_le_set_state_changed_cb() failed."); + } + + if (bt_adapter_le_disable() == BT_ERROR_NONE) { + tet_printf("bt_adapter_le_state_changed_cb() will be called"); + timeout_id = g_timeout_add(60000, timeout_func, mainloop); + g_main_loop_run(mainloop); + g_source_remove(timeout_id); + bt_adapter_le_unset_state_changed_cb(); + dts_check_eq("bt_adapter_le_disable", callback_result, true, + "BT LE was not disabled"); + } else { + dts_fail("bt_adapter_le_disable", "bt_adapter_le_disable() failed"); + } +} + +static void utc_network_bluetooth_adapter_get_le_state_p(void) +{ + bt_adapter_le_state_e adapter_le_state = BT_ADAPTER_LE_DISABLED; + int ret = BT_ERROR_NONE; + + ret = bt_adapter_le_get_state(&adapter_le_state); + if (ret == BT_ERROR_NONE && adapter_le_state == BT_ADAPTER_LE_ENABLED) { + dts_pass("bt_adapter_le_get_state", + "bt_adapter_le_get_state() succeeded."); + } else { + dts_fail("bt_adapter_le_get_state", + "bt_adapter_le_get_state() failed."); + } +} + +static void utc_network_bluetooth_adapter_unset_le_state_changed_cb_p(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_adapter_le_unset_state_changed_cb(); + dts_check_eq("bt_adapter_le_unset_state_changed_cb", ret, BT_ERROR_NONE, + "bt_adapter_unset_state_le_changed_cb() failed."); +} diff --git a/TC/testcase/utc_network_bluetooth_audio_negative.c b/TC/testcase/utc_network_bluetooth_audio_negative.c new file mode 100755 index 0000000..438b166 --- /dev/null +++ b/TC/testcase/utc_network_bluetooth_audio_negative.c @@ -0,0 +1,383 @@ +/* + * utc_network_bluetooth_audio_negative.c + * + * Created on: 19-Sep-2013 + * Author: mrinal.m + */ + +#include +#include +#include + +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; + +static void startup(void); +static void cleanup(void); + +static GMainLoop *mainloop; + +void (*tet_startup) (void) = startup; +void (*tet_cleanup) (void) = cleanup; + +static void utc_network_bluetooth_audio_connect_n(void); +static void utc_network_bluetooth_audio_disconnect_n(void); +static void utc_network_bluetooth_audio_set_connection_n(void); +static void utc_network_bluetooth_ag_get_speaker_gain_n(void); +static void utc_network_bluetooth_ag_is_nrec_enabled_n(void); +static void utc_network_bluetooth_ag_set_microphone_gain_changed_n(void); +static void utc_network_bluetooth_ag_set_speaker_gain_changed_n(void); +static void utc_network_bluetooth_ag_is_sco_opened_n(void); +static void utc_network_bluetooth_ag_set_sco_state_changed_n(void); +static void utc_network_bluetooth_ag_notify_call_event_n(void); +static void utc_network_bluetooth_ag_notify_call_list_n(void); +static void utc_network_bluetooth_ag_set_call_handling_event_cb_n(void); +static void utc_network_bluetooth_ag_set_multi_call_handling_event_cb_n(void); +static void utc_network_bluetooth_ag_set_vendor_cmd_cb_n(void); +static void utc_network_bluetooth_ag_unset_vendor_cmd_cb_n(void); +static void utc_network_bluetooth_ag_unset_multi_call_handling_event_cb_n(void); +static void utc_network_bluetooth_ag_unset_dtmf_transmitted_cb_n(void); +static void utc_network_bluetooth_ag_call_list_destroy_n(void); +static void utc_network_bluetooth_ag_call_list_reset_n(void); +static void utc_network_bluetooth_ag_call_list_add_n(void); +static void utc_network_bluetooth_ag_set_dtmf_transmitted_cb_n(void); + +void adapter_state_changed_cb_for_audio_negative(int result, + bt_adapter_state_e adapter_state, + void *user_data); +gboolean timeout_func(gpointer data); + +struct tet_testlist tet_testlist[] = { + {utc_network_bluetooth_audio_connect_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_audio_disconnect_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_audio_set_connection_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_ag_get_speaker_gain_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_ag_is_nrec_enabled_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_ag_set_microphone_gain_changed_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_ag_set_speaker_gain_changed_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_ag_is_sco_opened_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_ag_set_sco_state_changed_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_ag_notify_call_event_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_ag_notify_call_list_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_ag_set_call_handling_event_cb_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_ag_set_multi_call_handling_event_cb_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_ag_set_vendor_cmd_cb_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_ag_set_dtmf_transmitted_cb_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_ag_call_list_destroy_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_ag_call_list_reset_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_ag_call_list_add_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_ag_unset_vendor_cmd_cb_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_ag_unset_multi_call_handling_event_cb_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_ag_unset_dtmf_transmitted_cb_n, NEGATIVE_TC_IDX}, + {NULL, 0}, +}; + +static void startup(void) +{ + int ret = BT_ERROR_NONE; + int timeout_id = 0; + + /* start of TC */ + mainloop = g_main_loop_new(NULL, FALSE); + + bt_initialize(); + + if (bt_audio_initialize() != BT_ERROR_NONE) + tet_printf("bt_audio_initialize failed"); + + if (bt_adapter_set_state_changed_cb(adapter_state_changed_cb_for_audio_negative, "startup") != BT_ERROR_NONE) { + tet_printf("DTS may fail because bt_adapter_set_state_changed_cb() failed"); + } + + tet_printf("bt_adapter_disable() was called."); + ret = bt_adapter_disable(); + if (ret == BT_ERROR_NONE) { + tet_printf("bt_adapter_disable() succeeded."); + timeout_id = g_timeout_add(60000, timeout_func, mainloop); + g_main_loop_run(mainloop); + g_source_remove(timeout_id); + } else if (ret == BT_ERROR_NOT_ENABLED) { + tet_printf("Bluetooth adapter is not enabled."); + } else { + tet_printf("DTS may fail because bt_adapter_disable() failed"); + } + + if (bt_adapter_unset_state_changed_cb() != BT_ERROR_NONE) { + tet_printf("bt_adapter_set_state_changed_cb() failed."); + } + + tet_printf("TC start"); +} + +static void cleanup(void) +{ + /* end of TC */ + bt_deinitialize(); + tet_printf("TC end."); +} + +gboolean timeout_func(gpointer data) +{ + tet_printf("Callback: Timeout."); + g_main_loop_quit((GMainLoop *) data); + return FALSE; +} + +/** + * @brief Callback funtions + */ +void adapter_state_changed_cb_for_audio_negative(int result, + bt_adapter_state_e adapter_state, + void *user_data) +{ + tet_printf("Callback: bt_adapter_state_changed_cb was called."); + if (user_data != NULL && !strcmp((char *)user_data, "startup")) { + if (adapter_state == BT_ADAPTER_DISABLED && result == BT_ERROR_NONE) { + tet_printf("Callback: BT was disabled. DTS will be started."); + } else { + tet_printf("Callback: BT was not disabled. DTS will be started but DTS may fail."); + } + + if (mainloop) { + g_main_loop_quit(mainloop); + } + } +} + +/** + * @brief Negative test case of bt_audio_connect() + */ +static void utc_network_bluetooth_audio_connect_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_audio_connect(NULL, BT_AUDIO_PROFILE_TYPE_HSP_HFP); + dts_check_eq("bt_audio_connect", ret, + BT_ERROR_INVALID_PARAMETER, "bt_audio_connect() failed."); +} + +/** + * @brief Negative test case of bt_audio_disconnect() + */ +static void utc_network_bluetooth_audio_disconnect_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_audio_disconnect(NULL, BT_AUDIO_PROFILE_TYPE_A2DP); + dts_check_eq("bt_audio_disconnect", ret, + BT_ERROR_INVALID_PARAMETER, + "bt_audio_disconnect() failed."); +} + +/** + * @brief Negative test case of bt_audio_set_connection_state_changed_cb() + */ +static void utc_network_bluetooth_audio_set_connection_n(void) +{ + int ret = BT_ERROR_NONE; + ret = bt_audio_set_connection_state_changed_cb(NULL, NULL); + dts_check_eq("bt_audio_set_connection_state_changed_cb", ret, + BT_ERROR_INVALID_PARAMETER, + "bt_audio_set_connection_state_changed_cb() failed."); +} + +/** + * @brief Negative test case of bt_ag_get_speaker_gain() + */ +static void utc_network_bluetooth_ag_get_speaker_gain_n(void) +{ + int ret = BT_ERROR_NONE; + ret = bt_ag_get_speaker_gain(NULL); + dts_check_eq("bt_ag_get_speaker_gain", ret, + BT_ERROR_INVALID_PARAMETER, + "bt_ag_get_speaker_gain() failed."); +} + +/** + * @brief Negative test case of bt_ag_is_nrec_enabled() + */ +static void utc_network_bluetooth_ag_is_nrec_enabled_n(void) +{ + int ret = BT_ERROR_NONE; + ret = bt_ag_is_nrec_enabled(NULL); + dts_check_eq("bt_ag_is_nrec_enabled", ret, + BT_ERROR_INVALID_PARAMETER, + "bt_ag_is_nrec_enabled() failed."); +} + +/** + * @brief Negative test case of bt_ag_set_microphone_gain_changed_cb() + */ +static void utc_network_bluetooth_ag_set_microphone_gain_changed_n(void) +{ + int ret = BT_ERROR_NONE; + ret = bt_ag_set_microphone_gain_changed_cb(NULL, NULL); + dts_check_eq("bt_ag_set_microphone_gain_changed_cb", ret, + BT_ERROR_INVALID_PARAMETER, + "bt_ag_set_microphone_gain_changed_cb() failed."); +} + +/** + * @brief Negative test case of bt_ag_set_speaker_gain_changed_cb() + */ +static void utc_network_bluetooth_ag_set_speaker_gain_changed_n(void) +{ + int ret = BT_ERROR_NONE; + ret = bt_ag_set_speaker_gain_changed_cb(NULL, NULL); + dts_check_eq("bt_ag_set_speaker_gain_changed_cb", ret, + BT_ERROR_INVALID_PARAMETER, + "bt_ag_set_speaker_gain_changed_cb() failed."); +} + +/** + * @brief Negative test case of bt_ag_is_sco_opened() + */ +static void utc_network_bluetooth_ag_is_sco_opened_n(void) +{ + int ret = BT_ERROR_NONE; + ret = bt_ag_is_sco_opened(NULL); + dts_check_eq("bt_ag_is_sco_opened", ret, + BT_ERROR_INVALID_PARAMETER, + "bt_ag_is_sco_opened() failed."); +} + +/** + * @brief Negative test case of bt_ag_set_sco_state_changed_cb() + */ +static void utc_network_bluetooth_ag_set_sco_state_changed_n(void) +{ + int ret = BT_ERROR_NONE; + ret = bt_ag_set_sco_state_changed_cb(NULL, NULL); + dts_check_eq("bt_ag_set_sco_state_changed_cb", ret, + BT_ERROR_INVALID_PARAMETER, + "bt_ag_set_sco_state_changed_cb() failed."); +} + +/** + * @brief Negative test case of bt_ag_notify_call_event() + */ +static void utc_network_bluetooth_ag_notify_call_event_n(void) +{ + int ret = BT_ERROR_NONE; + unsigned int call_id = 0; + ret = bt_ag_notify_call_event(BT_AG_CALL_EVENT_INCOMING, call_id, NULL); + dts_check_eq("bt_ag_notify_call_event", ret, + BT_ERROR_INVALID_PARAMETER, + "bt_ag_notify_call_event() failed."); +} + +/** + * @brief Negative test case of bt_ag_notify_call_list() + */ +static void utc_network_bluetooth_ag_notify_call_list_n(void) +{ + int ret = BT_ERROR_NONE; + ret = bt_ag_notify_call_list(NULL); + dts_check_eq("bt_ag_notify_call_list", ret, + BT_ERROR_INVALID_PARAMETER, + "bt_ag_notify_call_list() failed."); +} + +/** + * @brief Negative test case of bt_ag_set_call_handling_event_cb() + */ +static void utc_network_bluetooth_ag_set_call_handling_event_cb_n(void) +{ + int ret = BT_ERROR_NONE; + ret = bt_ag_set_call_handling_event_cb(NULL, NULL); + dts_check_eq("bt_ag_set_call_handling_event_cb", ret, + BT_ERROR_INVALID_PARAMETER, + "bt_ag_set_call_handling_event_cb() failed."); +} + +/** + * @brief Negative test case of bt_ag_set_multi_call_handling_event_cb() + */ +static void utc_network_bluetooth_ag_set_multi_call_handling_event_cb_n(void) +{ + int ret = BT_ERROR_NONE; + ret = bt_ag_set_multi_call_handling_event_cb(NULL, NULL); + dts_check_eq("bt_ag_set_multi_call_handling_event_cb", ret, + BT_ERROR_INVALID_PARAMETER, + "bt_ag_set_multi_call_handling_event_cb() failed."); +} + +/** + * @brief Negative test case of bt_ag_set_dtmf_transmitted_cb() + */ +static void utc_network_bluetooth_ag_set_dtmf_transmitted_cb_n(void) +{ + int ret = BT_ERROR_NONE; + ret = bt_ag_set_dtmf_transmitted_cb(NULL, NULL); + dts_check_eq("bt_ag_set_dtmf_transmitted_cb", ret, + BT_ERROR_INVALID_PARAMETER, + "bt_ag_set_dtmf_transmitted_cb() failed."); + +} + +/** + * @brief Negative test case of bt_ag_unset_multi_call_handling_event_cb() + */ +static void utc_network_bluetooth_ag_unset_multi_call_handling_event_cb_n(void) +{ + int ret = BT_ERROR_NONE; + ret = bt_deinitialize(); + ret = bt_ag_unset_multi_call_handling_event_cb(); + dts_check_eq("bt_ag_unset_multi_call_handling_event_cb", ret, + BT_ERROR_NOT_INITIALIZED, + "BT_ERROR_NOT_INITIALIZED must be returned when BT is not initialized."); +} + +/** + * @brief Negative test case of bt_ag_unset_dtmf_transmitted_cb() + */ +static void utc_network_bluetooth_ag_unset_dtmf_transmitted_cb_n(void) +{ + int ret = BT_ERROR_NONE; + ret = bt_deinitialize(); + ret = bt_ag_unset_dtmf_transmitted_cb(); + dts_check_eq("bt_ag_unset_dtmf_transmitted_cb", ret, + BT_ERROR_NOT_INITIALIZED, + "BT_ERROR_NOT_INITIALIZED must be returned when BT is not initialized."); +} + +/** + * @brief Negative test case of bt_call_list_destroy() + */ +static void utc_network_bluetooth_ag_call_list_destroy_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_call_list_destroy(NULL); + dts_check_eq("bt_call_list_destroy", ret, BT_ERROR_INVALID_PARAMETER, + "bt_call_list_destroy() failed."); +} + +/** + * @brief Negative test case of bt_call_list_reset() + */ +static void utc_network_bluetooth_ag_call_list_reset_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_call_list_reset(NULL); + dts_check_eq("bt_call_list_reset", ret, BT_ERROR_INVALID_PARAMETER, + "bt_call_list_reset() failed."); +} + +/** + * @brief Negative test case of bt_call_list_add() + */ +static void utc_network_bluetooth_ag_call_list_add_n(void) +{ + int ret = BT_ERROR_NONE; + unsigned int call_id = 0; + const char *phone_number = "9663868998"; + + ret = bt_call_list_add(NULL, call_id, BT_AG_CALL_STATE_INCOMING, phone_number); + dts_check_eq("bt_call_list_add", ret, BT_ERROR_INVALID_PARAMETER, + "bt_call_list_add() failed."); + +} diff --git a/TC/testcase/utc_network_bluetooth_audio_positive.c b/TC/testcase/utc_network_bluetooth_audio_positive.c new file mode 100755 index 0000000..186bdb2 --- /dev/null +++ b/TC/testcase/utc_network_bluetooth_audio_positive.c @@ -0,0 +1,667 @@ +/* + * utc_network_bluetooth_audio_positive.c + * + * Created on: 19-Sep-2013 + * Author: mrinal.m + */ + +#include +#include +#include + +#define CONFIG_FILE_PATH "/opt/home/capi-network-bluetooth/tetware.conf" + +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; + +static void startup(void); +static void cleanup(void); + +void (*tet_startup) (void) = startup; +void (*tet_cleanup) (void) = cleanup; + +char *remote_address; +static GMainLoop *mainloop; + +static void utc_network_bluetooth_audio_initialize_p(void); +static void utc_network_bluetooth_audio_deinitialize_p(void); +static void utc_network_bluetooth_audio_connect_p(void); +static void utc_network_bluetooth_audio_disconnect_p(void); +static void utc_network_bluetooth_audio_set_connection_p(void); +static void utc_network_bluetooth_audio_unset_connection_p(void); +static void utc_network_bluetooth_ag_notify_speaker_gain_p(void); +static void utc_network_bluetooth_ag_get_speaker_gain_p(void); +static void utc_network_bluetooth_ag_is_nrec_enabled_p(void); +static void utc_network_bluetooth_ag_set_microphone_gain_changed_p(void); +static void utc_network_bluetooth_ag_unset_microphone_gain_changed_p(void); +static void utc_network_bluetooth_ag_set_speaker_gain_changed_p(void); +static void utc_network_bluetooth_ag_unset_speaker_gain_changed_p(void); +static void utc_network_bluetooth_ag_open_sco_p(void); +static void utc_network_bluetooth_ag_close_sco_p(void); +static void utc_network_bluetooth_ag_is_sco_opened_p(void); +static void utc_network_bluetooth_ag_set_sco_state_changed_p(void); +static void utc_network_bluetooth_ag_unset_sco_state_changed_p(void); +static void utc_network_bluetooth_ag_notify_call_event_p(void); +static void utc_network_bluetooth_ag_notify_call_list_p(void); +static void utc_network_bluetooth_ag_notify_voice_recognition_state_p(void); +static void utc_network_bluetooth_ag_set_call_handling_event_cb_p(void); +static void utc_network_bluetooth_ag_unset_call_handling_event_cb_p(void); +static void utc_network_bluetooth_ag_set_multi_call_handling_event_cb_p(void); +static void utc_network_bluetooth_ag_unset_multi_call_handling_event_cb_p(void); +static void utc_network_bluetooth_ag_set_dtmf_transmitted_cb_p(void); +static void utc_network_bluetooth_ag_unset_dtmf_transmitted_cb_p(void); +static void utc_network_bluetooth_ag_set_vendor_cmd_cb_p(void); +static void utc_network_bluetooth_ag_unset_vendor_cmd_cb_p(void); +static void utc_network_bluetooth_ag_call_list_create_p(void); +static void utc_network_bluetooth_ag_call_list_destroy_p(void); +static void utc_network_bluetooth_ag_call_list_reset_p(void); +static void utc_network_bluetooth_ag_call_list_add_p(void); +static void utc_network_bluetooth_ag_ca2dp_set_content_protection_p(void); + +void connection_state_changed_cb_for_audio_p(int result, bool connected, + const char *remote_address, + bt_audio_profile_type_e type, + void *user_data); +void dtmf_transmitted_cb_for_ag_p(const char *dtmf, void *user_data); +void multi_call_handling_event_cb_for_ag_p(bt_ag_multi_call_handling_event_e event, void *user_data); +void call_handling_event_cb_for_ag_p(bt_ag_call_handling_event_e event, + unsigned int call_id, void *user_data); +void sco_state_changed_cb_for_ag_p(int result, bool opened, void *user_data); +void speaker_gain_changed_cb_for_ag_p(int gain, void *user_data); +void microphone_gain_changed_cb_for_ag_p(int gain, void *user_data); +void adapter_state_changed_cb_for_audio_p(int result, + bt_adapter_state_e adapter_state, + void *user_data); + +gboolean timeout_func(gpointer data); + +struct tet_testlist tet_testlist[] = { + {utc_network_bluetooth_audio_initialize_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_audio_set_connection_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_audio_connect_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_ag_open_sco_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_ag_set_microphone_gain_changed_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_ag_set_speaker_gain_changed_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_ag_notify_speaker_gain_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_ag_get_speaker_gain_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_ag_is_nrec_enabled_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_ag_unset_microphone_gain_changed_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_ag_unset_speaker_gain_changed_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_ag_set_sco_state_changed_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_ag_set_vendor_cmd_cb_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_ag_unset_vendor_cmd_cb_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_ag_is_sco_opened_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_ag_close_sco_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_ag_notify_call_event_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_ag_notify_call_list_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_ag_notify_voice_recognition_state_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_ag_set_call_handling_event_cb_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_ag_unset_call_handling_event_cb_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_ag_set_multi_call_handling_event_cb_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_ag_unset_multi_call_handling_event_cb_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_ag_set_dtmf_transmitted_cb_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_ag_unset_dtmf_transmitted_cb_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_ag_unset_sco_state_changed_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_ag_call_list_create_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_ag_call_list_destroy_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_ag_call_list_reset_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_ag_call_list_add_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_ag_ca2dp_set_content_protection_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_audio_disconnect_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_audio_unset_connection_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_audio_deinitialize_p, POSITIVE_TC_IDX}, + {NULL, 0}, +}; + +int get_value_from_file(void) +{ + FILE *fp; + char *token; + char buf[100]; + + fp = fopen(CONFIG_FILE_PATH, "r"); + if (fp == NULL) { + tet_printf("Default configuration is used\n"); + return -1; + } + while (fgets(buf, sizeof(buf), fp)) { + if (buf[0] == '#' || buf[0] == '\n') + continue; + + token = strrchr(buf, '\n'); + if (token == NULL) { + tet_printf("g_conf is too long\n"); + break; + } + *token = '\0'; + + token = strtok(buf, "="); + if (token == NULL) { + continue; + } + if (strcasecmp(token, "BT_ADDR_HEADSET") == 0) { + token = strtok(NULL, "="); + remote_address = strdup(token); + fclose(fp); + return 0; + } + } + fclose(fp); + return -1; +} + +static void startup(void) +{ + bt_error_e ret = BT_ERROR_NONE; + int timeout_id = 0; + + if(get_value_from_file() == -1) { + tet_printf("Failed to read."); + } + + /* start of TC */ + tet_printf("TC start."); + mainloop = g_main_loop_new(NULL, FALSE); + + bt_initialize(); + + if (bt_adapter_set_state_changed_cb(adapter_state_changed_cb_for_audio_p, "startup") != BT_ERROR_NONE) { + tet_printf("DTS may fail because bt_adapter_set_state_changed_cb() failed"); + } + + tet_printf("bt_adapter_enable() was called."); + ret = bt_adapter_enable(); + if (ret == BT_ERROR_NONE) { + tet_printf("bt_adapter_enable() succeeded."); + timeout_id = g_timeout_add(60000, timeout_func, mainloop); + g_main_loop_run(mainloop); + g_source_remove(timeout_id); + } else if (ret != BT_ERROR_ALREADY_DONE) { + tet_printf("DTS may fail because bt_adapter_disable() failed"); + } + + if (bt_adapter_unset_state_changed_cb() != BT_ERROR_NONE) { + tet_printf("bt_adapter_set_state_changed_cb() failed."); + } + + tet_printf("TC start"); +} + +static void cleanup(void) +{ + /* end of TC */ + bt_deinitialize(); + tet_printf("TC end."); +} + +gboolean timeout_func(gpointer data) +{ + tet_printf("[%s] Callback: Timeout.", __FUNCTION__); + g_main_loop_quit((GMainLoop *) data); + return FALSE; +} + +/** + * @brief Callback funtions + */ + +void adapter_state_changed_cb_for_audio_p(int result, + bt_adapter_state_e adapter_state, + void *user_data) +{ + +} + +void connection_state_changed_cb_for_audio_p(int result, bool connected, + const char *remote_address, + bt_audio_profile_type_e type, + void *user_data) +{ + +} + +void microphone_gain_changed_cb_for_ag_p(int gain, void *user_data) +{ + +} + +void speaker_gain_changed_cb_for_ag_p(int gain, void *user_data) +{ + +} + +void sco_state_changed_cb_for_ag_p(int result, bool opened, void *user_data) +{ + +} + +void call_handling_event_cb_for_ag_p(bt_ag_call_handling_event_e event, + unsigned int call_id, void *user_data) +{ + +} + +void multi_call_handling_event_cb_for_ag_p(bt_ag_multi_call_handling_event_e event, void *user_data) +{ + +} + +void dtmf_transmitted_cb_for_ag_p(const char *dtmf, void *user_data) +{ + +} + +void vendor_cmd_event_cb_for_ag_p(char *cmd, void *user_data) +{ + tet_printf("Callback : vendor_cmd_cb was called."); + tet_printf("Vendor Command[%s]", cmd); +} + +/** + * @brief Positive test case of bt_audio_initialize() + */ +static void utc_network_bluetooth_audio_initialize_p(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_audio_initialize(); + dts_check_eq("bt_audio_initialize", ret, BT_ERROR_NONE, + "bt_audio_initialize() failed. %x", ret); + +} + +/** + * @brief Positive test case of bt_audio_connect() + */ +static void utc_network_bluetooth_audio_connect_p(void) +{ + int ret = BT_ERROR_NONE; + const char *remote_address = "00:23:78:AB:C4:20"; + ret = bt_audio_connect(remote_address, BT_AUDIO_PROFILE_TYPE_HSP_HFP); + dts_check_eq("bt_audio_connect", ret, BT_ERROR_NONE, + "bt_audio_connect() failed. %x", ret); +} + +/** + * @brief Positive test case of bt_audio_disconnect() + */ +static void utc_network_bluetooth_audio_disconnect_p(void) +{ + int ret = BT_ERROR_NONE; + ret = bt_audio_disconnect(remote_address, BT_AUDIO_PROFILE_TYPE_HSP_HFP); + dts_check_eq("bt_audio_disconnect", ret, BT_ERROR_NONE, + "bt_audio_disconnect() failed. %x", ret); +} + +/** + * @brief Positive test case of bt_audio_set_connection_state_changed_cb() + */ +static void utc_network_bluetooth_audio_set_connection_p(void) +{ + int ret = BT_ERROR_NONE; + ret = bt_audio_set_connection_state_changed_cb + (connection_state_changed_cb_for_audio_p, NULL); + dts_check_eq("bt_audio_set_connection_state_changed_cb", ret, + BT_ERROR_NONE, + "bt_audio_set_connection_state_changed_cb() failed."); +} + +/** + * @brief Positive test case of bt_audio_unset_connection_state_changed_cb() + */ +static void utc_network_bluetooth_audio_unset_connection_p(void) +{ + int ret = BT_ERROR_NONE; + ret = bt_audio_unset_connection_state_changed_cb(); + dts_check_eq("bt_audio_set_connection_state_changed_cb", ret, + BT_ERROR_NONE, + "bt_audio_set_connection_state_changed_cb() failed."); +} + +/** + * @brief Positive test case of bt_ag_notify_speaker_gain() + */ +static void utc_network_bluetooth_ag_notify_speaker_gain_p(void) +{ + int ret = BT_ERROR_NONE; + int gain = 10; + ret = bt_ag_notify_speaker_gain(gain); + dts_check_eq("bt_ag_notify_speaker_gain", ret, BT_ERROR_NONE, + "bt_ag_notify_speaker_gain() failed.%x", ret); +} + +/** + * @brief Positive test case of bt_ag_get_speaker_gain() + */ +static void utc_network_bluetooth_ag_get_speaker_gain_p(void) +{ + int ret = BT_ERROR_NONE; + int gain = 0; + ret = bt_ag_get_speaker_gain(&gain); + dts_check_eq("bt_ag_get_speaker_gain", ret, BT_ERROR_NONE, + "bt_ag_get_speaker_gain() failed."); + +} + +/** + * @brief Positive test case of bt_ag_is_nrec_enabled() + */ +static void utc_network_bluetooth_ag_is_nrec_enabled_p(void) +{ + int ret = BT_ERROR_NONE; + bool enabled = 1; + ret = bt_ag_is_nrec_enabled(&enabled); + dts_check_eq("bt_ag_is_nrec_enabled", ret, BT_ERROR_NONE, + "bt_ag_is_nrec_enabled() failed."); + +} + +/** + * @brief Positive test case of bt_ag_set_microphone_gain_changed_cb() + */ +static void utc_network_bluetooth_ag_set_microphone_gain_changed_p(void) +{ + int ret = BT_ERROR_NONE; + ret = bt_ag_set_microphone_gain_changed_cb(microphone_gain_changed_cb_for_ag_p, NULL); + dts_check_eq("bt_ag_set_microphone_gain_changed_cb", ret, BT_ERROR_NONE, + "bt_ag_set_microphone_gain_changed_cb() failed."); + +} + +/** + * @brief Positive test case of bt_ag_unset_microphone_gain_changed_cb() + */ +static void utc_network_bluetooth_ag_unset_microphone_gain_changed_p(void) +{ + int ret = BT_ERROR_NONE; + ret = bt_ag_unset_microphone_gain_changed_cb(); + dts_check_eq("bt_ag_unset_microphone_gain_changed_cb", ret, + BT_ERROR_NONE, + "bt_ag_unset_microphone_gain_changed_cb() failed."); + +} + +/** + * @brief Positive test case of bt_ag_set_speaker_gain_changed_cb() + */ +static void utc_network_bluetooth_ag_set_speaker_gain_changed_p(void) +{ + int ret = BT_ERROR_NONE; + ret = bt_ag_set_speaker_gain_changed_cb(speaker_gain_changed_cb_for_ag_p, NULL); + dts_check_eq("bt_ag_set_speaker_gain_changed_cb", ret, BT_ERROR_NONE, + "bt_ag_set_speaker_gain_changed_cb() failed."); + +} + +/** + * @brief Positive test case of bt_ag_unset_speaker_gain_changed_cb() + */ +static void utc_network_bluetooth_ag_unset_speaker_gain_changed_p(void) +{ + int ret = BT_ERROR_NONE; + ret = bt_ag_unset_speaker_gain_changed_cb(); + dts_check_eq("bt_ag_unset_speaker_gain_changed_cb", ret, BT_ERROR_NONE, + "bt_ag_unset_speaker_gain_changed_cb() failed."); + +} + +/** + * @brief Positive test case of bt_ag_open_sco() + */ +static void utc_network_bluetooth_ag_open_sco_p(void) +{ + int ret = BT_ERROR_NONE; + ret = bt_ag_open_sco(); + dts_check_eq("bt_ag_open_sco", ret, BT_ERROR_NONE, + "bt_ag_open_sco() failed."); + +} + +/** + * @brief Positive test case of bt_ag_close_sco() + */ +static void utc_network_bluetooth_ag_close_sco_p(void) +{ + int ret = BT_ERROR_NONE; + ret = bt_ag_close_sco(); + dts_check_eq("bt_ag_close_sco", ret, BT_ERROR_NONE, + "bt_ag_close_sco() failed."); + +} + +/** + * @brief Positive test case of bt_ag_is_sco_opened() + */ +static void utc_network_bluetooth_ag_is_sco_opened_p(void) +{ + int ret = BT_ERROR_NONE; + bool opened = 1; + ret = bt_ag_is_sco_opened(&opened); + dts_check_eq("bt_ag_is_sco_opened", ret, BT_ERROR_NONE, + "bt_ag_is_sco_opened() failed."); + +} + +/** + * @brief Positive test case of bt_ag_set_sco_state_changed_cb() + */ +static void utc_network_bluetooth_ag_set_sco_state_changed_p(void) +{ + int ret = BT_ERROR_NONE; + ret = bt_ag_set_sco_state_changed_cb(sco_state_changed_cb_for_ag_p, NULL); + dts_check_eq("bt_ag_set_sco_state_changed_cb", ret, BT_ERROR_NONE, + "bt_ag_set_sco_state_changed_cb() failed."); + +} + +/** + * @brief Positive test case of bt_ag_unset_sco_state_changed_cb() + */ +static void utc_network_bluetooth_ag_unset_sco_state_changed_p(void) +{ + int ret = BT_ERROR_NONE; + ret = bt_ag_unset_sco_state_changed_cb(); + dts_check_eq("bt_ag_unset_sco_state_changed_cb", ret, BT_ERROR_NONE, + "bt_ag_unset_sco_state_changed_cb() failed."); + +} + +/** + * @brief Positive test case of bt_ag_notify_call_event() + */ +static void utc_network_bluetooth_ag_notify_call_event_p(void) +{ + int ret = BT_ERROR_NONE; + const char *phone_number = "9663868998"; + unsigned int call_id = 0; + ret = bt_ag_notify_call_event(BT_AG_CALL_EVENT_INCOMING, + call_id, phone_number); + dts_check_eq("bt_ag_notify_call_event", ret, BT_ERROR_NONE, + "bt_ag_notify_call_event() failed."); + +} + +/** + * @brief Positive test case of bt_ag_notify_call_list() + */ +static void utc_network_bluetooth_ag_notify_call_list_p(void) +{ + int ret = BT_ERROR_NONE; + bt_call_list_h handle; + const char *phone_number = "9663868998"; + + handle = g_malloc0(sizeof(bt_call_list_h)); + bt_call_list_add(handle, 1, BT_AG_CALL_STATE_ACTIVE, phone_number); + ret = bt_ag_notify_call_list(handle); + dts_check_eq("bt_ag_notify_call_list", ret, BT_ERROR_NONE, + "bt_ag_notify_call_list() failed."); + +} + +/** + * @brief Positive test case of bt_ag_notify_voice_recognition_state() + */ +static void utc_network_bluetooth_ag_notify_voice_recognition_state_p(void) +{ + int ret = BT_ERROR_NONE; + bool state = 1; + + ret = bt_ag_notify_voice_recognition_state(state); + dts_check_eq("bt_ag_notify_voice_recognition_state", ret, BT_ERROR_NONE, + "bt_ag_notify_voice_recognition_state() failed."); + +} + +/** + * @brief Positive test case of bt_ag_set_call_handling_event_cb() + */ +static void utc_network_bluetooth_ag_set_call_handling_event_cb_p(void) +{ + int ret = BT_ERROR_NONE; + ret = bt_ag_set_call_handling_event_cb(call_handling_event_cb_for_ag_p, + NULL); + dts_check_eq("bt_ag_set_call_handling_event_cb", ret, BT_ERROR_NONE, + "bt_ag_set_call_handling_event_cb() failed."); + +} + +/** + * @brief Positive test case of bt_ag_unset_call_handling_event_cb() + */ +static void utc_network_bluetooth_ag_unset_call_handling_event_cb_p(void) +{ + int ret = BT_ERROR_NONE; + ret = bt_ag_unset_call_handling_event_cb(); + dts_check_eq("bt_ag_unset_call_handling_event_cb", ret, BT_ERROR_NONE, + "bt_ag_unset_call_handling_event_cb() failed."); + +} + +/** + * @brief Positive test case of bt_ag_set_multi_call_handling_event_cb() + */ +static void utc_network_bluetooth_ag_set_multi_call_handling_event_cb_p(void) +{ + int ret = BT_ERROR_NONE; + ret = bt_ag_set_multi_call_handling_event_cb(multi_call_handling_event_cb_for_ag_p, NULL); + dts_check_eq("bt_ag_set_multi_call_handling_event_cb", ret, + BT_ERROR_NONE, + "bt_ag_set_multi_call_handling_event_cb() failed."); + +} + +/** + * @brief Positive test case of bt_ag_unset_multi_call_handling_event_cb() + */ +static void utc_network_bluetooth_ag_unset_multi_call_handling_event_cb_p(void) +{ + int ret = BT_ERROR_NONE; + ret = bt_ag_unset_multi_call_handling_event_cb(); + dts_check_eq("bt_ag_unset_multi_call_handling_event_cb", ret, + BT_ERROR_NONE, + "bt_ag_unset_multi_call_handling_event_cb() failed."); + +} + +/** + * @brief Positive test case of bt_ag_set_dtmf_transmitted_cb() + */ +static void utc_network_bluetooth_ag_set_dtmf_transmitted_cb_p(void) +{ + int ret = BT_ERROR_NONE; + ret = bt_ag_set_dtmf_transmitted_cb(dtmf_transmitted_cb_for_ag_p, NULL); + dts_check_eq("bt_ag_set_dtmf_transmitted_cb", ret, BT_ERROR_NONE, + "bt_ag_set_dtmf_transmitted_cb() failed."); + +} + +/** + * @brief Positive test case of bt_ag_unset_dtmf_transmitted_cb() + */ +static void utc_network_bluetooth_ag_unset_dtmf_transmitted_cb_p(void) +{ + int ret = BT_ERROR_NONE; + ret = bt_ag_unset_dtmf_transmitted_cb(); + dts_check_eq("bt_ag_unset_dtmf_transmitted_cb", ret, BT_ERROR_NONE, + "bt_ag_unset_dtmf_transmitted_cb() failed."); + +} + +/** + * @brief Positive test case of bt_call_list_create() + */ +static void utc_network_bluetooth_ag_call_list_create_p(void) +{ + int ret = BT_ERROR_NONE; + bt_call_list_h handle; + const char *phone_number = "9663868998"; + + ret = bt_call_list_create(&handle); + ret = bt_call_list_add(handle, 1, BT_AG_CALL_STATE_ACTIVE, phone_number); + + dts_check_eq("bt_call_list_create", ret, BT_ERROR_NONE, + "bt_call_list_create() failed."); +} + +/** + * @brief Positive test case of bt_call_list_destroy() + */ +static void utc_network_bluetooth_ag_call_list_destroy_p(void) +{ + int ret = BT_ERROR_NONE; + bt_call_list_h handle; + const char *phone_number = "9663868998"; + + handle = g_malloc0(sizeof(bt_call_list_h)); + bt_call_list_add(handle, 1, BT_AG_CALL_STATE_ACTIVE, phone_number); + ret = bt_call_list_destroy(handle); + dts_check_eq("bt_call_list_destroy", ret, BT_ERROR_NONE, + "bt_call_list_destroy() failed."); +} + +/** + * @brief Positive test case of bt_call_list_reset() + */ +static void utc_network_bluetooth_ag_call_list_reset_p(void) +{ + int ret = BT_ERROR_NONE; + bt_call_list_h handle; + const char *phone_number = "9663868998"; + + handle = g_malloc0(sizeof(bt_call_list_h)); + bt_call_list_add(handle, 1, BT_AG_CALL_STATE_ACTIVE, phone_number); + ret = bt_call_list_reset(handle); + dts_check_eq("bt_call_list_reset", ret, BT_ERROR_NONE, + "bt_call_list_reset() failed."); +} + +/** + * @brief Positive test case of bt_call_list_add() + */ +static void utc_network_bluetooth_ag_call_list_add_p(void) +{ + int ret = BT_ERROR_NONE; + unsigned int call_id = 0; + bt_call_list_h handle; + const char *phone_number = "9663868998"; + + handle = g_malloc0(sizeof(bt_call_list_h)); + bt_call_list_add(handle, 1, BT_AG_CALL_STATE_ACTIVE, phone_number); + ret = bt_call_list_add(handle, call_id, BT_AG_CALL_STATE_INCOMING, phone_number); + dts_check_eq("bt_call_list_add", ret, BT_ERROR_NONE, + "bt_call_list_add() failed."); +} + +/** + * @brief Positive test case of bt_audio_deinitialize() + */ +static void utc_network_bluetooth_audio_deinitialize_p(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_audio_deinitialize(); + dts_check_eq("bt_audio_deinitialize", ret, BT_ERROR_NONE, + "bt_audio_deinitialize() failed."); +} diff --git a/TC/testcase/utc_network_bluetooth_avrcp_negative.c b/TC/testcase/utc_network_bluetooth_avrcp_negative.c new file mode 100644 index 0000000..a62c7b4 --- /dev/null +++ b/TC/testcase/utc_network_bluetooth_avrcp_negative.c @@ -0,0 +1,174 @@ +/* + * utc_network_bluetooth_avrcp_negative.c + * + * Created on: 20-Sep-2013 + * Author: mrinal.m + */ + +#include "bluetooth.h" +#include +#include + +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; + +static void startup(void); +static void cleanup(void); + +void (*tet_startup) (void) = startup; +void (*tet_cleanup) (void) = cleanup; + +const char target_name[128] = "dts_test"; +char target_address[18] = ""; + +static GMainLoop *mainloop; + +static void utc_network_bluetooth_audio_initialize_n(void); +static void utc_network_bluetooth_avrcp_set_equalizer_state_changed_n(void); +static void utc_network_bluetooth_avrcp_set_repeat_mode_changed_n(void); +static void utc_network_bluetooth_avrcp_set_shuffle_mode_changed_n(void); +static void utc_network_bluetooth_avrcp_set_scan_mode_changed_n(void); + + +void adapter_state_changed_cb_for_avrcp_n(int result, + bt_adapter_state_e adapter_state, + void *user_data); +gboolean timeout_func(gpointer data); + + +struct tet_testlist tet_testlist[] = { + {utc_network_bluetooth_audio_initialize_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_avrcp_set_equalizer_state_changed_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_avrcp_set_repeat_mode_changed_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_avrcp_set_shuffle_mode_changed_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_avrcp_set_scan_mode_changed_n, NEGATIVE_TC_IDX}, + {NULL, 0}, +}; + + +static void startup(void) +{ + int ret = BT_ERROR_NONE; + int timeout_id = 0; + + /* start of TC */ + mainloop = g_main_loop_new(NULL, FALSE); + + bt_initialize(); + if (bt_adapter_set_state_changed_cb(adapter_state_changed_cb_for_avrcp_n, "startup") != BT_ERROR_NONE) { + tet_printf("DTS may fail because bt_adapter_set_state_changed_cb() failed"); + } + + tet_printf("bt_adapter_disable() was called."); + ret = bt_adapter_disable(); + if (ret == BT_ERROR_NONE) { + tet_printf("bt_adapter_disable() succeeded."); + timeout_id = g_timeout_add(60000, timeout_func, mainloop); + g_main_loop_run(mainloop); + g_source_remove(timeout_id); + } else if (ret == BT_ERROR_NOT_ENABLED) { + tet_printf("Bluetooth adapter is not enabled."); + } else { + tet_printf("DTS may fail because bt_adapter_disable() failed"); + } + + if (bt_adapter_unset_state_changed_cb() != BT_ERROR_NONE) { + tet_printf("bt_adapter_set_state_changed_cb() failed."); + } + + tet_printf("TC start"); +} + +static void cleanup(void) +{ + /* end of TC */ + bt_deinitialize(); + tet_printf("TC end."); +} + +gboolean timeout_func(gpointer data) +{ + tet_printf("Callback: Timeout."); + g_main_loop_quit((GMainLoop *) data); + return FALSE; +} + +/** + * @brief Negative test case of bt_avrcp_target_initialize() + */ + +void adapter_state_changed_cb_for_avrcp_n(int result, + bt_adapter_state_e adapter_state, + void *user_data) +{ + +} + +static void utc_network_bluetooth_audio_initialize_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_avrcp_target_initialize(NULL, NULL); + dts_check_eq("bt_avrcp_target_initialize", ret, + BT_ERROR_INVALID_PARAMETER, + "bt_avrcp_target_initialize() failed."); + +} + +/** + * @brief Negative test case of bt_avrcp_set_equalizer_state_changed_cb() + */ +static void utc_network_bluetooth_avrcp_set_equalizer_state_changed_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_avrcp_set_equalizer_state_changed_cb(NULL, NULL); + dts_check_eq("bt_avrcp_set_equalizer_state_changed_cb", ret, + BT_ERROR_INVALID_PARAMETER, + "bt_avrcp_set_equalizer_state_changed_cb() failed."); + +} + +/** + * @brief Negative test case of bt_avrcp_set_repeat_mode_changed_cb() + */ +static void utc_network_bluetooth_avrcp_set_repeat_mode_changed_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_avrcp_set_repeat_mode_changed_cb(NULL, NULL); + dts_check_eq("bt_avrcp_set_repeat_mode_changed_cb", ret, + BT_ERROR_INVALID_PARAMETER, + "bt_avrcp_set_repeat_mode_changed_cb() failed."); + +} + +/** + * @brief Negative test case of bt_avrcp_set_shuffle_mode_changed_cb() + */ +static void utc_network_bluetooth_avrcp_set_shuffle_mode_changed_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_avrcp_set_shuffle_mode_changed_cb(NULL, NULL); + dts_check_eq("bt_avrcp_set_shuffle_mode_changed_cb", ret, + BT_ERROR_INVALID_PARAMETER, + "bt_avrcp_set_shuffle_mode_changed_cb() failed."); + +} + +/** + * @brief Negative test case of bt_avrcp_set_scan_mode_changed_cb() + */ +static void utc_network_bluetooth_avrcp_set_scan_mode_changed_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_avrcp_set_scan_mode_changed_cb(NULL, NULL); + dts_check_eq("bt_avrcp_set_scan_mode_changed_cb", ret, + BT_ERROR_INVALID_PARAMETER, + "bt_avrcp_set_scan_mode_changed_cb() failed."); + +} diff --git a/TC/testcase/utc_network_bluetooth_avrcp_positive.c b/TC/testcase/utc_network_bluetooth_avrcp_positive.c new file mode 100755 index 0000000..79e0688 --- /dev/null +++ b/TC/testcase/utc_network_bluetooth_avrcp_positive.c @@ -0,0 +1,398 @@ +/* + * utc_network_bluetooth_avrcp_positive.c + * + * Created on: 20-Sep-2013 + * Author: mrinal.m + */ + +#include +#include +#include + +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; + +static void startup(void); +static void cleanup(void); + +static GMainLoop *mainloop; + +void (*tet_startup) (void) = startup; +void (*tet_cleanup) (void) = cleanup; + +void target_connection_state_changed_cb_for_avrcp_p(bool connected, + const char *remote_address, + void *user_data); +void equalizer_state_changed_cb_for_avrcp_p(bt_avrcp_equalizer_state_e equalizer, + void *user_data); +void repeat_mode_changed_cb_for_avrcp_p(bt_avrcp_repeat_mode_e repeat, + void *user_data); +void shuffle_mode_changed_cb_for_avrcp_p(bt_avrcp_shuffle_mode_e shuffle, + void *user_data); +void scan_mode_changed_cb_for_avrcp_p(bt_avrcp_scan_mode_e scan, + void *user_data); + +static void utc_network_bluetooth_avrcp_targe_initialize_p(void); +static void utc_network_bluetooth_avrcp_target_deinitialize_p(void); +static void utc_network_bluetooth_avrcp_target_notify_equalizer_state_p(void); +static void utc_network_bluetooth_avrcp_target_notify_repeat_mode_p(void); +static void utc_network_bluetooth_avrcp_target_notify_shuffle_mode_p(void); +static void utc_network_bluetooth_avrcp_target_notify_scan_mode_p(void); +static void utc_network_bluetooth_avrcp_target_notify_player_state_p(void); +static void utc_network_bluetooth_avrcp_target_notify_position_p(void); +static void utc_network_bluetooth_avrcp_target_notify_track_p(void); +static void utc_network_bluetooth_avrcp_set_equalizer_state_changed_p(void); +static void utc_network_bluetooth_avrcp_unset_equalizer_state_changed_p(void); +static void utc_network_bluetooth_avrcp_set_repeat_mode_changed_p(void); +static void utc_network_bluetooth_avrcp_unset_repeat_mode_changed_p(void); +static void utc_network_bluetooth_avrcp_set_shuffle_mode_changed_p(void); +static void utc_network_bluetooth_avrcp_unset_shuffle_mode_changed_p(void); +static void utc_network_bluetooth_avrcp_set_scan_mode_changed_p(void); +static void utc_network_bluetooth_avrcp_unset_scan_mode_changed_p(void); + +void adapter_state_changed_cb_for_avrcp_p(int result, + bt_adapter_state_e adapter_state, + void *user_data); +gboolean timeout_func(gpointer data); + +struct tet_testlist tet_testlist[] = { + {utc_network_bluetooth_avrcp_targe_initialize_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_avrcp_target_notify_equalizer_state_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_avrcp_target_notify_repeat_mode_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_avrcp_target_notify_shuffle_mode_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_avrcp_target_notify_scan_mode_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_avrcp_target_notify_player_state_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_avrcp_target_notify_position_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_avrcp_target_notify_track_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_avrcp_set_equalizer_state_changed_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_avrcp_unset_equalizer_state_changed_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_avrcp_set_repeat_mode_changed_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_avrcp_unset_repeat_mode_changed_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_avrcp_set_shuffle_mode_changed_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_avrcp_unset_shuffle_mode_changed_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_avrcp_set_scan_mode_changed_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_avrcp_unset_scan_mode_changed_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_avrcp_target_deinitialize_p, POSITIVE_TC_IDX}, + {NULL, 0}, +}; + +static void startup(void) +{ + int ret = BT_ERROR_NONE; + int timeout_id = 0; + + /* start of TC */ + mainloop = g_main_loop_new(NULL, FALSE); + + bt_initialize(); + if (bt_adapter_set_state_changed_cb(adapter_state_changed_cb_for_avrcp_p, "startup") != BT_ERROR_NONE) { + tet_printf("DTS may fail because bt_adapter_set_state_changed_cb() failed"); + } + + tet_printf("bt_adapter_enable() was called."); + ret = bt_adapter_enable(); + if (ret == BT_ERROR_NONE) { + tet_printf("bt_adapter_enable() succeeded."); + timeout_id = g_timeout_add(60000, timeout_func, mainloop); + g_main_loop_run(mainloop); + g_source_remove(timeout_id); + } else if (ret != BT_ERROR_ALREADY_DONE) { + tet_printf("DTS may fail because bt_adapter_disable() failed"); + } else if (ret == BT_ERROR_NOT_ENABLED) { + tet_printf("Bluetooth adapter is not enabled."); + } else { + tet_printf("DTS may fail because bt_adapter_disable() failed"); + } + + if (bt_adapter_unset_state_changed_cb() != BT_ERROR_NONE) { + tet_printf("bt_adapter_set_state_changed_cb() failed."); + } + + tet_printf("TC start"); +} + +static void cleanup(void) +{ + /* end of TC */ + bt_deinitialize(); + tet_printf("TC end."); +} + +gboolean timeout_func(gpointer data) +{ + tet_printf("Callback: Timeout."); + g_main_loop_quit((GMainLoop *) data); + return FALSE; +} + +/** + * @brief Callback funtions + */ + +void adapter_state_changed_cb_for_avrcp_p(int result, + bt_adapter_state_e adapter_state, + void *user_data) +{ + +} + +void target_connection_state_changed_cb_for_avrcp_p(bool connected, + const char *remote_address, + void *user_data) +{ + +} + +void equalizer_state_changed_cb_for_avrcp_p( + bt_avrcp_equalizer_state_e equalizer, + void *user_data) +{ + +} + +void repeat_mode_changed_cb_for_avrcp_p(bt_avrcp_repeat_mode_e repeat, + void *user_data) +{ + +} + +void shuffle_mode_changed_cb_for_avrcp_p(bt_avrcp_shuffle_mode_e shuffle, + void *user_data) +{ + +} + +void scan_mode_changed_cb_for_avrcp_p(bt_avrcp_scan_mode_e scan, + void *user_data) +{ + +} + +/** + * @brief Positive test case of bt_avrcp_target_initialize() + */ +static void utc_network_bluetooth_avrcp_targe_initialize_p(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_avrcp_target_initialize( + target_connection_state_changed_cb_for_avrcp_p, + NULL); + dts_check_eq("bt_avrcp_target_initialize", ret, BT_ERROR_NONE, + "bt_avrcp_target_initialize() failed."); + +} + +/** + * @brief Positive test case of bt_avrcp_target_deinitialize() + */ +static void utc_network_bluetooth_avrcp_target_deinitialize_p(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_avrcp_target_deinitialize(); + dts_check_eq("bt_avrcp_target_deinitialize", ret, BT_ERROR_NONE, + "bt_avrcp_target_deinitialize() failed."); + +} + +/** + * @brief Positive test case of bt_avrcp_target_notify_equalizer_state() + */ +static void utc_network_bluetooth_avrcp_target_notify_equalizer_state_p(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_avrcp_target_notify_equalizer_state(BT_AVRCP_EQUALIZER_STATE_ON); + dts_check_eq("bt_avrcp_target_notify_equalizer_state", ret, + BT_ERROR_NONE, + "bt_avrcp_target_notify_equalizer_state() failed."); + +} + +/** + * @brief Positive test case of bt_avrcp_target_notify_repeat_mode() + */ +static void utc_network_bluetooth_avrcp_target_notify_repeat_mode_p(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_avrcp_target_notify_repeat_mode(BT_AVRCP_REPEAT_MODE_ALL_TRACK); + dts_check_eq("bt_avrcp_target_notify_repeat_mode", ret, BT_ERROR_NONE, + "bt_avrcp_target_notify_repeat_mode() failed."); + +} + +/** + * @brief Positive test case of bt_avrcp_target_notify_shuffle_mode() + */ +static void utc_network_bluetooth_avrcp_target_notify_shuffle_mode_p(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_avrcp_target_notify_shuffle_mode(BT_AVRCP_SHUFFLE_MODE_ALL_TRACK); + dts_check_eq("bt_avrcp_target_notify_shuffle_mode", ret, BT_ERROR_NONE, + "bt_avrcp_target_notify_shuffle_mode() failed."); + +} + +/** + * @brief Positive test case of bt_avrcp_target_notify_scan_mode() + */ +static void utc_network_bluetooth_avrcp_target_notify_scan_mode_p(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_avrcp_target_notify_scan_mode(BT_AVRCP_SCAN_MODE_ALL_TRACK); + dts_check_eq("bt_avrcp_target_notify_scan_mode", ret, BT_ERROR_NONE, + "bt_avrcp_target_notify_scan_mode() failed."); +} + +/** + * @brief Positive test case of bt_avrcp_target_notify_player_state() + */ +static void utc_network_bluetooth_avrcp_target_notify_player_state_p(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_avrcp_target_notify_player_state(BT_AVRCP_PLAYER_STATE_PLAYING); + dts_check_eq("bt_avrcp_target_notify_player_state", ret, BT_ERROR_NONE, + "bt_avrcp_target_notify_player_state() failed."); +} + +/** + * @brief Positive test case of bt_avrcp_target_notify_position() + */ +static void utc_network_bluetooth_avrcp_target_notify_position_p(void) +{ + int ret = BT_ERROR_NONE; + unsigned int position = 0; + ret = bt_avrcp_target_notify_position(position); + dts_check_eq("bt_avrcp_target_notify_position", ret, BT_ERROR_NONE, + "bt_avrcp_target_notify_position() failed."); +} + +/** + * @brief Positive test case of bt_avrcp_target_notify_track() + */ +static void utc_network_bluetooth_avrcp_target_notify_track_p(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_avrcp_target_notify_track("title", "artist", "album", "genre", 5, 20, 2); + dts_check_eq("bt_avrcp_target_notify_track", ret, BT_ERROR_NONE, + "bt_avrcp_target_notify_track() failed."); +} + +/** + * @brief Positive test case of bt_avrcp_set_equalizer_state_changed_cb() + */ +static void utc_network_bluetooth_avrcp_set_equalizer_state_changed_p(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_avrcp_set_equalizer_state_changed_cb( + equalizer_state_changed_cb_for_avrcp_p, + NULL); + dts_check_eq("bt_avrcp_set_equalizer_state_changed_cb", ret, BT_ERROR_NONE, + "bt_avrcp_set_equalizer_state_changed_cb() failed."); + +} + +/** + * @brief Positive test case of bt_avrcp_unset_equalizer_state_changed_cb() + */ +static void utc_network_bluetooth_avrcp_unset_equalizer_state_changed_p(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_avrcp_unset_equalizer_state_changed_cb(); + dts_check_eq("bt_avrcp_unset_equalizer_state_changed_cb", ret, + BT_ERROR_NONE, + "bt_avrcp_unset_equalizer_state_changed_cb() failed."); + +} + +/** + * @brief Positive test case of bt_avrcp_set_repeat_mode_changed_cb() + */ +static void utc_network_bluetooth_avrcp_set_repeat_mode_changed_p(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_avrcp_set_repeat_mode_changed_cb(repeat_mode_changed_cb_for_avrcp_p, NULL); + dts_check_eq("bt_avrcp_set_repeat_mode_changed_cb", ret, BT_ERROR_NONE, + "bt_avrcp_set_repeat_mode_changed_cb() failed."); + +} + +/** + * @brief Positive test case of bt_avrcp_unset_repeat_mode_changed_cb() + */ +static void utc_network_bluetooth_avrcp_unset_repeat_mode_changed_p(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_avrcp_unset_repeat_mode_changed_cb(); + dts_check_eq("bt_avrcp_unset_repeat_mode_changed_cb", ret, + BT_ERROR_NONE, + "bt_avrcp_unset_repeat_mode_changed_cb() failed."); + +} + +/** + * @brief Positive test case of bt_avrcp_set_shuffle_mode_changed_cb() + */ +static void utc_network_bluetooth_avrcp_set_shuffle_mode_changed_p(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_avrcp_set_shuffle_mode_changed_cb( + shuffle_mode_changed_cb_for_avrcp_p, + NULL); + dts_check_eq("bt_avrcp_set_shuffle_mode_changed_cb", ret, BT_ERROR_NONE, + "bt_avrcp_set_shuffle_mode_changed_cb() failed."); +} + +/** + * @brief Positive test case of bt_avrcp_unset_shuffle_mode_changed_cb() + */ +static void utc_network_bluetooth_avrcp_unset_shuffle_mode_changed_p(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_avrcp_unset_shuffle_mode_changed_cb(); + dts_check_eq("bt_avrcp_unset_shuffle_mode_changed_cb", ret, + BT_ERROR_NONE, + "bt_avrcp_unset_shuffle_mode_changed_cb() failed."); +} + +/** + * @brief Positive test case of bt_avrcp_set_scan_mode_changed_cb() + */ +static void utc_network_bluetooth_avrcp_set_scan_mode_changed_p(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_avrcp_set_scan_mode_changed_cb(scan_mode_changed_cb_for_avrcp_p, + NULL); + dts_check_eq("bt_avrcp_set_scan_mode_changed_cb", ret, BT_ERROR_NONE, + "bt_avrcp_set_scan_mode_changed_cb() failed."); + +} + +/** + * @brief Positive test case of bt_avrcp_unset_scan_mode_changed_cb() + */ +static void utc_network_bluetooth_avrcp_unset_scan_mode_changed_p(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_avrcp_unset_scan_mode_changed_cb(); + dts_check_eq("bt_avrcp_unset_scan_mode_changed_cb", ret, BT_ERROR_NONE, + "bt_avrcp_unset_scan_mode_changed_cb() failed."); + +} + diff --git a/TC/testcase/utc_network_bluetooth_common_negative.c b/TC/testcase/utc_network_bluetooth_common_negative.c new file mode 100644 index 0000000..4d2eb6e --- /dev/null +++ b/TC/testcase/utc_network_bluetooth_common_negative.c @@ -0,0 +1,84 @@ +/* + * utc_network_bluetooth_common_negative.c + * + * Created on: 20-Sep-2013 + * Author: mrinal.m + */ + +#include "bluetooth.h" +#include +#include + +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; + +static void startup(void); +static void cleanup(void); + +static GMainLoop *mainloop; +void (*tet_startup) (void) = startup; +void (*tet_cleanup) (void) = cleanup; +void adapter_state_changed_cb_for_common_n(int result, + bt_adapter_state_e adapter_state, + void *user_data); +gboolean timeout_func(gpointer data); + +struct tet_testlist tet_testlist[] = { + {NULL, 0}, +}; + +static void startup(void) +{ + int ret = BT_ERROR_NONE; + int timeout_id = 0; + + /* start of TC */ + mainloop = g_main_loop_new(NULL, FALSE); + + bt_initialize(); + if (bt_adapter_set_state_changed_cb(adapter_state_changed_cb_for_common_n, "startup") != BT_ERROR_NONE) { + tet_printf("DTS may fail because bt_adapter_set_state_changed_cb() failed"); + } + + tet_printf("bt_adapter_disable() was called."); + ret = bt_adapter_disable(); + if (ret == BT_ERROR_NONE) { + tet_printf("bt_adapter_disable() succeeded."); + timeout_id = g_timeout_add(60000, timeout_func, mainloop); + g_main_loop_run(mainloop); + g_source_remove(timeout_id); + } else if (ret == BT_ERROR_NOT_ENABLED) { + tet_printf("Bluetooth adapter is not enabled."); + } else { + tet_printf("DTS may fail because bt_adapter_disable() failed"); + } + + if (bt_adapter_unset_state_changed_cb() != BT_ERROR_NONE) { + tet_printf("bt_adapter_set_state_changed_cb() failed."); + } + + tet_printf("TC start"); +} + +static void cleanup(void) +{ + /* end of TC */ + bt_deinitialize(); + tet_printf("TC end."); +} + +gboolean timeout_func(gpointer data) +{ + tet_printf("Callback: Timeout."); + g_main_loop_quit((GMainLoop *) data); + return FALSE; +} + +void adapter_state_changed_cb_for_common_n(int result, + bt_adapter_state_e adapter_state, + void *user_data) +{ + +} diff --git a/TC/testcase/utc_network_bluetooth_common_positive.c b/TC/testcase/utc_network_bluetooth_common_positive.c new file mode 100755 index 0000000..bf775cf --- /dev/null +++ b/TC/testcase/utc_network_bluetooth_common_positive.c @@ -0,0 +1,122 @@ +/* + * utc_network_bluetooth_common_positive.c + * + * Created on: 20-Sep-2013 + * Author: mrinal.m + */ + +#include +#include +#include + +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; + +static void startup(void); +static void cleanup(void); + +static GMainLoop *mainloop; + +void (*tet_startup) (void) = startup; +void (*tet_cleanup) (void) = cleanup; + +void adapter_state_changed_cb_for_common_p(int result, + bt_adapter_state_e adapter_state, + void *user_data); +gboolean timeout_func(gpointer data); + +static void utc_network_bluetooth_bt_initialize_p(void); +static void utc_network_bluetooth_bt_deinitialize_p(void); + +struct tet_testlist tet_testlist[] = { + {utc_network_bluetooth_bt_initialize_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_bt_deinitialize_p, POSITIVE_TC_IDX}, + {NULL, 0}, +}; + +static void startup(void) +{ + int ret = BT_ERROR_NONE; + int timeout_id = 0; + + /* start of TC */ + mainloop = g_main_loop_new(NULL, FALSE); + + bt_initialize(); + if (bt_adapter_set_state_changed_cb(adapter_state_changed_cb_for_common_p, "startup") != BT_ERROR_NONE) { + tet_printf("DTS may fail because bt_adapter_set_state_changed_cb() failed"); + } + + tet_printf("bt_adapter_enable() was called."); + ret = bt_adapter_enable(); + if (ret == BT_ERROR_NONE) { + tet_printf("bt_adapter_enable() succeeded."); + timeout_id = g_timeout_add(60000, timeout_func, mainloop); + g_main_loop_run(mainloop); + g_source_remove(timeout_id); + } else if (ret != BT_ERROR_ALREADY_DONE) { + tet_printf("DTS may fail because bt_adapter_disable() failed"); + } else if (ret == BT_ERROR_NOT_ENABLED) { + tet_printf("Bluetooth adapter is not enabled."); + } else { + tet_printf("DTS may fail because bt_adapter_disable() failed"); + } + + if (bt_adapter_unset_state_changed_cb() != BT_ERROR_NONE) { + tet_printf("bt_adapter_set_state_changed_cb() failed."); + } + + tet_printf("TC start"); +} + +static void cleanup(void) +{ + /* end of TC */ + bt_deinitialize(); + tet_printf("TC end."); +} + +gboolean timeout_func(gpointer data) +{ + tet_printf("Callback: Timeout."); + g_main_loop_quit((GMainLoop *) data); + return FALSE; +} + +void adapter_state_changed_cb_for_common_p(int result, + bt_adapter_state_e adapter_state, + void *user_data) +{ + +} + +/** + * @brief Positive test case of bt_initialize() + */ +static void utc_network_bluetooth_bt_initialize_p(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_initialize(); + dts_check_eq("bt_initialize", ret, BT_ERROR_NONE, + "bt_initialize() failed."); + +} + +/** + * @brief Positive test case of bt_deinitialize() + */ +static void utc_network_bluetooth_bt_deinitialize_p(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_deinitialize(); + dts_check_eq("bt_deinitialize", ret, BT_ERROR_NONE, + "bt_deinitialize() failed."); + +} + + + diff --git a/TC/testcase/utc_network_bluetooth_device_discovery_negative.c b/TC/testcase/utc_network_bluetooth_device_discovery_negative.c new file mode 100644 index 0000000..48b22d3 --- /dev/null +++ b/TC/testcase/utc_network_bluetooth_device_discovery_negative.c @@ -0,0 +1,191 @@ +/* + * 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 +#include +#include +#include +#include + +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; + +static GMainLoop *mainloop; +gboolean timeout_func(gpointer data); + +static void startup(void); +static void cleanup(void); + +void (*tet_startup) (void) = startup; +void (*tet_cleanup) (void) = cleanup; + +static void utc_network_bluetooth_device_discovery_cancel_n(void); +static void utc_network_bluetooth_device_discovery_unset_state_changed_cb_n(void); +static void utc_network_bluetooth_device_discovery_set_state_changed_cb_n(void); +static void utc_network_bluetooth_device_discovery_start_n(void); +static void utc_network_bluetooth_device_discovery_get_status_n(void); + +void adapter_state_changed_cb_for_discovery_n(int result, + bt_adapter_state_e adapter_state, + void *user_data); + +struct tet_testlist tet_testlist[] = { + {utc_network_bluetooth_device_discovery_cancel_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_device_discovery_set_state_changed_cb_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_device_discovery_get_status_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_device_discovery_start_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_device_discovery_unset_state_changed_cb_n, NEGATIVE_TC_IDX}, + {NULL, 0}, +}; + +static void startup(void) +{ + int ret = BT_ERROR_NONE; + int timeout_id = 0; + + /* start of TC */ + mainloop = g_main_loop_new(NULL, FALSE); + + bt_initialize(); + if (bt_adapter_set_state_changed_cb(adapter_state_changed_cb_for_discovery_n, "startup") != BT_ERROR_NONE) { + tet_printf("DTS may fail because bt_adapter_set_state_changed_cb() failed"); + } + + tet_printf("bt_adapter_disable() was called."); + ret = bt_adapter_disable(); + if (ret == BT_ERROR_NONE) { + tet_printf("bt_adapter_disable() succeeded."); + timeout_id = g_timeout_add(60000, timeout_func, mainloop); + g_main_loop_run(mainloop); + g_source_remove(timeout_id); + } else if (ret == BT_ERROR_NOT_ENABLED) { + tet_printf("Bluetooth adapter is not enabled."); + } else { + tet_printf("DTS may fail because bt_adapter_disable() failed"); + } + + if (bt_adapter_unset_state_changed_cb() != BT_ERROR_NONE) { + tet_printf("bt_adapter_set_state_changed_cb() failed."); + } + + tet_printf("TC start"); +} + +static void cleanup(void) +{ + /* end of TC */ + bt_deinitialize(); + tet_printf("TC end"); +} + +gboolean timeout_func(gpointer data) +{ + tet_printf("Callback: Timeout."); + g_main_loop_quit((GMainLoop *) data); + return FALSE; +} + +/** + * @brief Callback funtions + */ +void adapter_state_changed_cb_for_discovery_n(int result, + bt_adapter_state_e adapter_state, + void *user_data) +{ + tet_printf("Callback: bt_adapter_state_changed_cb was called."); + if (user_data != NULL && !strcmp((char *)user_data, "startup")) { + if (adapter_state == BT_ADAPTER_DISABLED && + result == BT_ERROR_NONE) { + tet_printf("Callback: BT was disabled. DTS will be started."); + } else { + tet_printf("Callback: BT was not disabled. DTS will be started but DTS may fail."); + } + + if (mainloop) { + g_main_loop_quit(mainloop); + } + } +} + +/** + *@brief Negative test case of bt_adapter_stop_device_discovery() + */ +static void utc_network_bluetooth_device_discovery_cancel_n(void) +{ + int ret = bt_adapter_stop_device_discovery(); + + dts_check_eq("bt_adapter_stop_device_discovery", ret, + BT_ERROR_NOT_ENABLED, + "BT_ERROR_NOT_ENABLED must be returned when BT is not enabled"); +} + +/** + *@brief Negative test case of bt_adapter_unset_device_discovery_state_changed_cb() + */ +static void utc_network_bluetooth_device_discovery_unset_state_changed_cb_n(void) +{ + int ret = BT_ERROR_NONE; + + if (bt_deinitialize() != BT_ERROR_NONE) { + dts_fail("bt_adapter_unset_device_discovery_state_changed_cb", + "bt_deinitialize() failed."); + } + ret = bt_adapter_unset_device_discovery_state_changed_cb(); + dts_check_eq("bt_adapter_unset_device_discovery_state_changed_cb", ret, + BT_ERROR_NOT_INITIALIZED, + "BT_ERROR_NOT_INITIALIZED must be returned when BT service is not initialized."); +} + +/** + *@brief Negative test case of bt_adapter_set_device_discovery_state_changed_cb() + */ +static void utc_network_bluetooth_device_discovery_set_state_changed_cb_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_adapter_set_device_discovery_state_changed_cb(NULL, NULL); + dts_check_eq("bt_adapter_set_device_discovery_state_changed_cb", ret, + BT_ERROR_INVALID_PARAMETER, + "BT_ERROR_INVALID_PARAMETER must be returned when callback parameter is NULL"); +} + +/** + *@brief Negative test case of bt_adapter_start_device_discovery() + */ +static void utc_network_bluetooth_device_discovery_start_n(void) +{ + bt_error_e ret = BT_ERROR_NONE; + + ret = bt_adapter_start_device_discovery();; + dts_check_eq("bt_adapter_start_device_discovery", ret, + BT_ERROR_NOT_ENABLED, + "BT_ERROR_NOT_ENABLED must be returned when BT is not enabled"); +} + +/** + *@brief Negative test case of bt_adapter_is_discovering() + */ +static void utc_network_bluetooth_device_discovery_get_status_n(void) +{ + bt_error_e ret = BT_ERROR_NONE; + bool status = false; + + ret = bt_adapter_is_discovering(&status); + dts_check_eq("bt_adapter_is_discovering", ret, BT_ERROR_NOT_ENABLED, + "BT_ERROR_NOT_ENABLED must be returned when BT is not enabled"); +} diff --git a/TC/testcase/utc_network_bluetooth_device_discovery_positive.c b/TC/testcase/utc_network_bluetooth_device_discovery_positive.c new file mode 100755 index 0000000..76caf9f --- /dev/null +++ b/TC/testcase/utc_network_bluetooth_device_discovery_positive.c @@ -0,0 +1,262 @@ +/* + * 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 +#include +#include +#include +#include + +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; + +static GMainLoop *mainloop; +static bool callback_result = false; + +static void startup(void); +static void cleanup(void); + +void (*tet_startup) (void) = startup; +void (*tet_cleanup) (void) = cleanup; + +static void utc_network_bluetooth_device_discovery_get_status_p(void); +static void utc_network_bluetooth_device_discovery_set_state_changed_cb_p(void); +static void utc_network_bluetooth_device_discovery_start_p(void); +static void utc_network_bluetooth_device_discovery_unset_state_changed_cb_p(void); +static void utc_network_bluetooth_device_discovery_cancel_p(void); + +gboolean timeout_func(gpointer data); +void adapter_state_changed_cb_for_discovery_p(int result, + bt_adapter_state_e adapter_state, + void *user_data); +void device_discovery_state_changed_cb_for_discovery_p(int result, + bt_adapter_device_discovery_state_e discovery_state, + bt_adapter_device_discovery_info_s *discovery_info, + void *user_data); + +struct tet_testlist tet_testlist[] = { + {utc_network_bluetooth_device_discovery_get_status_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_device_discovery_set_state_changed_cb_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_device_discovery_start_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_device_discovery_unset_state_changed_cb_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_device_discovery_cancel_p, POSITIVE_TC_IDX}, + {NULL, 0}, +}; + +static void startup(void) +{ + bt_error_e ret = BT_ERROR_NONE; + int timeout_id = 0; + + /* start of TC */ + mainloop = g_main_loop_new(NULL, FALSE); + + bt_initialize(); + + if (bt_adapter_set_state_changed_cb(adapter_state_changed_cb_for_discovery_p, "startup") != BT_ERROR_NONE) { + tet_printf("DTS may fail because bt_adapter_set_state_changed_cb() failed."); + } + + ret = bt_adapter_enable(); + if (ret == BT_ERROR_NONE) { + tet_printf("bt_adapter_enable() succeeded."); + timeout_id = g_timeout_add(60000, timeout_func, mainloop); + g_main_loop_run(mainloop); + g_source_remove(timeout_id); + } else if (ret == BT_ERROR_ALREADY_DONE) { + tet_printf("BT was already enabled."); + } else { + tet_printf("DTS may fail because bt_adapter_enable() failed."); + } + + if (bt_adapter_unset_state_changed_cb() != BT_ERROR_NONE) { + tet_printf + ("bt_adapter_unset_device_discovery_state_changed_cb() failed."); + } + + tet_printf("TC start"); +} + +static void cleanup(void) +{ + /* end of TC */ + tet_printf("TC end"); + bt_deinitialize(); +} + +gboolean timeout_func(gpointer data) +{ + tet_printf("Callback: Timeout."); + g_main_loop_quit((GMainLoop *) data); + return FALSE; +} + +/** + * @brief Callback funtions + */ +void adapter_state_changed_cb_for_discovery_p(int result, + bt_adapter_state_e adapter_state, + void *user_data) +{ + if (user_data != NULL && !strcmp((char *)user_data, "startup")) { + if (adapter_state == BT_ADAPTER_ENABLED && + result == BT_ERROR_NONE) { + tet_printf("Callback: BT was enabled."); + } else { + tet_printf("Callback: bt_adapter_state_changed_cb() was \ + called but bt_adapter_enable() failed."); + } + + if (mainloop) { + g_main_loop_quit(mainloop); + } + } +} + +void device_discovery_state_changed_cb_for_discovery_p(int result, + bt_adapter_device_discovery_state_e discovery_state, + bt_adapter_device_discovery_info_s *discovery_info, + void *user_data) +{ + tet_printf("Callback: device_discovery_state_changed_cb_for_discovery_p is called"); + + if (discovery_state == BT_ADAPTER_DEVICE_DISCOVERY_FOUND) { + tet_printf("Callback: Devices were found"); + tet_printf("Callback: Device name is %s", discovery_info->remote_name); + tet_printf("Callback: Service class: %x", discovery_info->bt_class.major_service_class_mask); + if (user_data != NULL && !strcmp((char *)user_data, "start")) { + callback_result = true; + if (mainloop) { + g_main_loop_quit(mainloop); + } + } + } else if (discovery_state == BT_ADAPTER_DEVICE_DISCOVERY_FINISHED) { + tet_printf("Callback: Device discovery finished"); + if (user_data != NULL) { + if (!strcmp((char *)user_data, "start") && callback_result == false) { + tet_printf("You need a discoverable device"); + tet_printf("utc_network_bluetooth_device_discovery_start_p and \ + utc_network_bluetooth_device_discovery_cancel_p will fail"); + } else if (!strcmp((char *)user_data, "cancel")) { + if (result == BT_ERROR_CANCELLED) { + callback_result = true; + } + } + } + if (mainloop) { + g_main_loop_quit(mainloop); + } + } +} + +/** + * @brief Positive test case of bt_adapter_is_discovering() + */ +static void utc_network_bluetooth_device_discovery_get_status_p(void) +{ + bt_error_e ret = BT_ERROR_NONE; + bool status = false; + + ret = bt_adapter_is_discovering(&status); + dts_check_eq("bt_adapter_is_discovering", ret, BT_ERROR_NONE, + "bt_adapter_is_discovering() failed."); +} + +/** + * @brief Positive test case of bt_adapter_set_device_discovery_state_changed_cb() + */ +static void utc_network_bluetooth_device_discovery_set_state_changed_cb_p(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_adapter_set_device_discovery_state_changed_cb(device_discovery_state_changed_cb_for_discovery_p, "start"); + dts_check_eq("bt_adapter_set_device_discovery_state_changed_cb", ret, + BT_ERROR_NONE, + "bt_adapter_set_device_discovery_state_changed_cb() failed."); +} + +/** + * @brief Positive test case of bt_adapter_start_device_discovery() + */ +static void utc_network_bluetooth_device_discovery_start_p(void) +{ + int ret = BT_ERROR_NONE; + int timeout_id = 0; + + callback_result = false; + + ret = bt_adapter_start_device_discovery(); + if (ret == BT_ERROR_NONE) { + tet_printf("bt_adapter_device_discovery_state_changed_cb_for_discovery_p() will be called."); + timeout_id = g_timeout_add(60000, timeout_func, mainloop); + g_main_loop_run(mainloop); + g_source_remove(timeout_id); + dts_check_eq("bt_adapter_start_device_discovery", + callback_result, true, + "Callback was called but failed."); + } else { + dts_fail("bt_adapter_start_device_discovery", + "bt_adapter_start_device_discovery() failed."); + } +} + +/** + * @brief Positive test case of bt_adapter_unset_device_discovery_state_changed_cb() + */ +static void utc_network_bluetooth_device_discovery_unset_state_changed_cb_p(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_adapter_unset_device_discovery_state_changed_cb(); + dts_check_eq("bt_adapter_unset_device_discovery_state_changed_cb", ret, + BT_ERROR_NONE, + "bt_device_discovery_uset_state_changed_cb() failed"); +} + +/** + * @brief Positive test case of bt_adapter_stop_device_discovery() + */ +static void utc_network_bluetooth_device_discovery_cancel_p(void) +{ + int ret = BT_ERROR_NONE; + int timeout_id = 0; + + callback_result = false; + + if (bt_adapter_set_device_discovery_state_changed_cb + (device_discovery_state_changed_cb_for_discovery_p, "cancel") != BT_ERROR_NONE) { + dts_fail("bt_adapter_stop_device_discovery", + "bt_adapter_set_device_discovery_state_changed_cb() failed"); + } + + ret = bt_adapter_stop_device_discovery(); + if (ret == BT_ERROR_NONE) { + tet_printf("bt_adapter_device_discovery_state_changed_cb_for_discovery_p() will be called"); + timeout_id = g_timeout_add(60000, timeout_func, mainloop); + g_main_loop_run(mainloop); + g_source_remove(timeout_id); + bt_adapter_unset_device_discovery_state_changed_cb(); + dts_check_eq("bt_adapter_stop_device_discovery", callback_result, true, + "Callback was called but failed"); + } else { + dts_fail("bt_adapter_stop_device_discovery", + "bt_adapter_stop_device_discovery() failed"); + } + +} + diff --git a/TC/testcase/utc_network_bluetooth_device_negative.c b/TC/testcase/utc_network_bluetooth_device_negative.c new file mode 100755 index 0000000..9915c99 --- /dev/null +++ b/TC/testcase/utc_network_bluetooth_device_negative.c @@ -0,0 +1,300 @@ +/* + * 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 +#include +#include +#include +#include + +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; + +static void startup(void); +static void cleanup(void); + +static GMainLoop *mainloop; +gboolean timeout_func(gpointer data); + +void (*tet_startup) (void) = startup; +void (*tet_cleanup) (void) = cleanup; + +static void utc_network_bluetooth_device_set_bonded_cb_n(void); +static void utc_network_bluetooth_device_set_unbonded_cb_n(void); +static void utc_network_bluetooth_device_set_authorization_state_changed_cb_n(void); +static void utc_network_bluetooth_device_cancel_bonding_n(void); +static void utc_network_bluetooth_device_bond_n(void); +static void utc_network_bluetooth_device_foreach_bonded_device_n(void); +static void utc_network_bluetooth_device_set_alias_n(void); +static void utc_network_bluetooth_device_set_authorization_n(void); +static void utc_network_bluetooth_device_unbond_n(void); +static void utc_network_bluetooth_device_unset_bonded_cb_n(void); +static void utc_network_bluetooth_device_unset_unbonded_cb_n(void); +static void utc_network_bluetooth_device_unset_authorization_state_changed_cb_n(void); +static void utc_network_bluetooth_device_get_rssi_strength_n(void); +static void utc_network_bluetooth_device_disable_rssi_monitor_n(void); +static void utc_network_bluetooth_device_enable_rssi_monitor_n(void); +static void utc_network_bluetooth_device_unset_rssi_alert_cb_n(void); + +void adapter_state_changed_cb_for_device_negative(int result, + bt_adapter_state_e adapter_state, + void *user_data); +gboolean timeout_func(gpointer data); + +struct tet_testlist tet_testlist[] = { + {utc_network_bluetooth_device_set_bonded_cb_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_device_set_unbonded_cb_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_device_set_authorization_state_changed_cb_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_device_bond_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_device_cancel_bonding_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_device_unbond_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_device_foreach_bonded_device_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_device_set_alias_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_device_set_authorization_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_device_get_rssi_strength_n, NEGATIVE_TC_IDX }, + {utc_network_bluetooth_device_enable_rssi_monitor_n, NEGATIVE_TC_IDX }, + {utc_network_bluetooth_device_disable_rssi_monitor_n, NEGATIVE_TC_IDX }, + {utc_network_bluetooth_device_unset_rssi_alert_cb_n, NEGATIVE_TC_IDX }, + {utc_network_bluetooth_device_unset_bonded_cb_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_device_unset_unbonded_cb_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_device_unset_authorization_state_changed_cb_n, NEGATIVE_TC_IDX}, + {NULL, 0}, +}; + +gboolean timeout_func(gpointer data) +{ + tet_printf("Callback: Timeout."); + g_main_loop_quit((GMainLoop *) data); + return FALSE; +} + +static void startup(void) +{ + int ret = BT_ERROR_NONE; + int timeout_id = 0; + + /* start of TC */ + mainloop = g_main_loop_new(NULL, FALSE); + + bt_initialize(); + if (bt_adapter_set_state_changed_cb(adapter_state_changed_cb_for_device_negative, "startup") != BT_ERROR_NONE) { + tet_printf("DTS may fail because bt_adapter_set_state_changed_cb() failed"); + } + + tet_printf("bt_adapter_disable() was called."); + ret = bt_adapter_disable(); + if (ret == BT_ERROR_NONE) { + tet_printf("bt_adapter_disable() succeeded."); + timeout_id = g_timeout_add(60000, timeout_func, mainloop); + g_main_loop_run(mainloop); + g_source_remove(timeout_id); + } else if (ret == BT_ERROR_NOT_ENABLED) { + tet_printf("Bluetooth adapter is not enabled."); + } else { + tet_printf("DTS may fail because bt_adapter_disable() failed"); + } + + if (bt_adapter_unset_state_changed_cb() != BT_ERROR_NONE) { + tet_printf("bt_adapter_set_state_changed_cb() failed."); + } + + tet_printf("TC start"); +} + +static void cleanup(void) +{ + /* end of TC */ + bt_deinitialize(); + tet_printf("TC end."); +} + +/** + * @brief Callback funtions + */ +void adapter_state_changed_cb_for_device_negative(int result, + bt_adapter_state_e adapter_state, + void *user_data) +{ + tet_printf("Callback: bt_adapter_state_changed_cb was called."); + if ((user_data != NULL) && !strcmp((char *)user_data, "startup")) { + if (adapter_state == BT_ADAPTER_DISABLED && result == BT_ERROR_NONE) { + tet_printf("Callback: BT was disabled. DTS will be started."); + } else { + tet_printf("Callback: BT was not disabled. DTS will be started but DTS may fail."); + } + + if (mainloop) { + g_main_loop_quit(mainloop); + } + } +} + +/** + * @brief Negative test case of bt_device_set_bond_created_cb() + */ +static void utc_network_bluetooth_device_set_bonded_cb_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_device_set_bond_created_cb(NULL, NULL); + dts_check_eq("bt_device_set_bond_created_cb", ret, + BT_ERROR_INVALID_PARAMETER, + "BT_ERROR_INVALID_PARAMETER must be returned when callback parameter is NULL"); +} + +/** + * @brief Negative test case of bt_device_set_bond_destroyed_cb() + */ +static void utc_network_bluetooth_device_set_unbonded_cb_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_device_set_bond_destroyed_cb(NULL, NULL); + dts_check_eq("bt_device_set_bond_destroyed_cb", ret, + BT_ERROR_INVALID_PARAMETER, + "BT_ERROR_INVALID_PARAMETER must be returned when callback parameter is NULL"); +} + +/** + * @brief Negative test case of bt_device_set_authorization_changed_cb() + */ +static void +utc_network_bluetooth_device_set_authorization_state_changed_cb_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_device_set_authorization_changed_cb(NULL, NULL); + dts_check_eq("bt_device_set_authorization_changed_cb", ret, + BT_ERROR_INVALID_PARAMETER, + "BT_ERROR_INVALID_PARAMETER must be returned when callback parameter is NULL"); +} + +/** + * @brief Negative test case of bt_device_unset_bond_created_cb() + */ +static void utc_network_bluetooth_device_unset_bonded_cb_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_deinitialize(); + + ret = bt_device_unset_bond_created_cb(); + dts_check_eq("bt_device_unset_bond_created_cb", ret, + BT_ERROR_NOT_INITIALIZED, + "BT_ERROR_NOT_INITIALIZED must be returned when BT is not initialized."); +} + + /** + * @brief Negative test case of bt_device_unset_bond_destroyed_cb() + */ +static void utc_network_bluetooth_device_unset_unbonded_cb_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_device_unset_bond_destroyed_cb(); + dts_check_eq("bt_device_unset_bond_destroyed_cb", ret, + BT_ERROR_NOT_INITIALIZED, + "BT_ERROR_NOT_INITIALIZED must be returned when BT service is not initialized."); +} + +/** + * @brief Negative test case of bt_device_unset_authorization_changed_cb() + */ +static void +utc_network_bluetooth_device_unset_authorization_state_changed_cb_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_device_unset_authorization_changed_cb(); + dts_check_eq("bt_device_unset_authorization_changed_cb", ret, + BT_ERROR_NOT_INITIALIZED, + "BT_ERROR_NOT_INITIALIZED must be returned when BT service is not initialized."); +} + + /** + * @brief Negative test case of bt_device_create_bond() + */ +static void utc_network_bluetooth_device_bond_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_device_create_bond(NULL); + dts_check_eq("bt_device_create_bond", ret, BT_ERROR_INVALID_PARAMETER, + "BT_ERROR_NOT_INITIALIZED must be returned when BT service is not initialized."); +} + + /** + * @brief Negative test case of bt_device_cancel_bonding() + */ +static void utc_network_bluetooth_device_cancel_bonding_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_device_cancel_bonding(); + dts_check_eq("bt_device_cancel_bonding", ret, BT_ERROR_NOT_ENABLED, + "BT_ERROR_NOT_ENABLED must be returned when BT is not enabled"); +} + +/** + * @brief Negative test case of bt_device_destroy_bond() + */ +static void utc_network_bluetooth_device_unbond_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_device_destroy_bond(NULL); + dts_check_eq("bt_device_destroy_bond", ret, BT_ERROR_INVALID_PARAMETER, + "BT_ERROR_INVALID_PARAMETER must be returned when parameter is NULL"); +} + +/** + * @brief Negative test case of bt_adapter_foreach_bonded_device() + */ +static void utc_network_bluetooth_device_foreach_bonded_device_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_adapter_foreach_bonded_device(NULL, NULL); + dts_check_eq("bt_adapter_foreach_bonded_device", ret, BT_ERROR_INVALID_PARAMETER, + "BT_ERROR_INVALID_PARAMETER must be returned when parameter is NULL"); +} + +/** + * @brief Negative test case of bt_device_set_alias() + */ +static void utc_network_bluetooth_device_set_alias_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_device_set_alias(NULL, "dts_alias"); + dts_check_eq("bt_device_set_alias", ret, BT_ERROR_INVALID_PARAMETER, + "BT_ERROR_INVALID_PARAMETER must be returned when address parameter is NULL"); +} + +/** + * @brief Negative test case of bt_device_set_authorization() + */ +static void utc_network_bluetooth_device_set_authorization_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_device_set_authorization(NULL, BT_DEVICE_AUTHORIZED); + dts_check_eq("bt_device_set_authorization", ret, + BT_ERROR_INVALID_PARAMETER, + "BT_ERROR_INVALID_PARAMETER must be returned when address parameter is NULL"); +} diff --git a/TC/testcase/utc_network_bluetooth_device_positive.c b/TC/testcase/utc_network_bluetooth_device_positive.c new file mode 100755 index 0000000..631746e --- /dev/null +++ b/TC/testcase/utc_network_bluetooth_device_positive.c @@ -0,0 +1,695 @@ +/* + * 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 +#include +#include +#include +#include + +#define CONFIG_FILE_PATH "/opt/home/capi-network-bluetooth/tetware.conf" + +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; + +static void startup(void); +static void cleanup(void); + +static GMainLoop *mainloop; +static bool callback_result = false; +char target_name[128] = "dts_test"; +char *target_address; +bt_device_info_s *device_info = NULL; +bool discovery_result = false; + +void (*tet_startup) (void) = startup; +void (*tet_cleanup) (void) = cleanup; + +static void utc_network_bluetooth_device_set_bonded_cb_p(void); +static void utc_network_bluetooth_device_set_unbonded_cb_p(void); +static void utc_network_bluetooth_device_set_authorization_state_changed_cb_p(void); +static void utc_network_bluetooth_device_cancel_bonding_p(void); +static void utc_network_bluetooth_device_bond_p(void); +static void utc_network_bluetooth_device_foreach_bonded_device_p(void); +static void utc_network_bluetooth_device_set_alias_p(void); +static void utc_network_bluetooth_device_set_authorization_p(void); +static void utc_network_bluetooth_device_unbond_p(void); +static void utc_network_bluetooth_device_unset_bonded_cb_p(void); +static void utc_network_bluetooth_device_unset_unbonded_cb_p(void); +static void utc_network_bluetooth_device_unset_authorization_state_changed_cb_p(void); +static void utc_network_bluetooth_device_get_rssi_strength_p(void); +static void utc_network_bluetooth_device_disable_rssi_monitor_p(void); +static void utc_network_bluetooth_device_enable_rssi_monitor_p(void); +static void utc_network_bluetooth_device_unset_rssi_alert_cb_p(void); + +gboolean timeout_func(gpointer data); +void adapter_state_changed_cb_for_device_p(int result, + bt_adapter_state_e adapter_state, + void *user_data); +void device_discovery_state_changed_cb_for_device_p(int result, + bt_adapter_device_discovery_state_e discovery_state, + bt_adapter_device_discovery_info_s *discovery_info, + void *user_data); +void device_bonded_cb(int result, bt_device_info_s *device_info, + void *user_data); +void device_unbonded_cb(int result, char *remote_address, void *user_data); +void device_authorization_state_changed_cb(bt_device_authorization_e authorization_state, \ + char *remote_address, void *user_data); +bool bonded_device_cb_for_device_p(bt_device_info_s *dev_info, + void *user_data); +void device_get_rssi_strength_cb(char *bt_address, + bt_device_connection_link_type_e link_type, + int rssi_dbm, void *user_data); +static void device_rssi_enabled_cb(const char *address, + bt_device_connection_link_type_e link_type, + int rssi_enabled, void *user_data); +static void device_rssi_alert_cb(char *bt_address, + bt_device_connection_link_type_e link_type, + int rssi_alert_type, int rssi_alert_dbm, void *user_data); + +struct tet_testlist tet_testlist[] = { + { utc_network_bluetooth_device_set_bonded_cb_p, POSITIVE_TC_IDX }, + { utc_network_bluetooth_device_bond_p, POSITIVE_TC_IDX }, + { utc_network_bluetooth_device_foreach_bonded_device_p, POSITIVE_TC_IDX }, + { utc_network_bluetooth_device_set_alias_p, POSITIVE_TC_IDX }, + { utc_network_bluetooth_device_set_authorization_state_changed_cb_p, POSITIVE_TC_IDX }, + { utc_network_bluetooth_device_set_authorization_p, POSITIVE_TC_IDX }, + { utc_network_bluetooth_device_unset_bonded_cb_p, POSITIVE_TC_IDX }, + { utc_network_bluetooth_device_unset_authorization_state_changed_cb_p, POSITIVE_TC_IDX }, + { utc_network_bluetooth_device_get_rssi_strength_p, POSITIVE_TC_IDX }, + { utc_network_bluetooth_device_enable_rssi_monitor_p, POSITIVE_TC_IDX }, + { utc_network_bluetooth_device_disable_rssi_monitor_p, POSITIVE_TC_IDX }, + { utc_network_bluetooth_device_unset_rssi_alert_cb_p, POSITIVE_TC_IDX }, + { utc_network_bluetooth_device_set_unbonded_cb_p, POSITIVE_TC_IDX }, + { utc_network_bluetooth_device_cancel_bonding_p, POSITIVE_TC_IDX }, + { utc_network_bluetooth_device_unbond_p, POSITIVE_TC_IDX }, + { utc_network_bluetooth_device_unset_unbonded_cb_p, POSITIVE_TC_IDX }, + { NULL, 0 }, +}; + +int get_value_from_file(void) +{ + FILE *fp; + char *token; + char buf[100]; + + fp = fopen(CONFIG_FILE_PATH, "r"); + if (fp == NULL) { + tet_printf("Default configuration is used\n"); + return -1; + } + while (fgets(buf, sizeof(buf), fp)) { + if (buf[0] == '#' || buf[0] == '\n') + continue; + + token = strrchr(buf, '\n'); + if (token == NULL) { + tet_printf("g_conf is too long\n"); + break; + } + *token = '\0'; + + token = strtok(buf, "="); + if (token == NULL) { + continue; + } + if (strcasecmp(token, "BT_ADDR_MOBILE") == 0) { + token = strtok(NULL, "="); + target_address = strdup(token); + fclose(fp); + return 0; + } + } + fclose(fp); + return -1; +} + +static void startup(void) +{ + bt_error_e ret = BT_ERROR_NONE; + int timeout_id = 0; + + if(get_value_from_file() == -1) { + tet_printf("Failed to read."); + } + + /* start of TC */ + callback_result = false; + discovery_result = false; + mainloop = g_main_loop_new(NULL, FALSE); + + bt_initialize(); + + if (bt_adapter_set_state_changed_cb(adapter_state_changed_cb_for_device_p, "startup") != BT_ERROR_NONE) { + tet_printf("bt_adapter_set_state_changed_cb() failed."); + } + + if (bt_adapter_set_device_discovery_state_changed_cb(device_discovery_state_changed_cb_for_device_p, "startup") != BT_ERROR_NONE) { + tet_printf("bt_adapter_set_device_discovery_state_changed_cb() failed."); + } + + ret = bt_adapter_enable(); + if (ret == BT_ERROR_NONE) { + tet_printf("bt_adapter_enable() succeeded."); + timeout_id = g_timeout_add(60000, timeout_func, mainloop); + g_main_loop_run(mainloop); + g_source_remove(timeout_id); + + tet_printf("BT was enabled. Device discovery will be started"); + if (bt_adapter_start_device_discovery() == BT_ERROR_NONE) { + tet_printf("bt_adapter_start_device_discovery() succeeded."); + timeout_id = g_timeout_add(60000, timeout_func, mainloop); + g_main_loop_run(mainloop); + g_source_remove(timeout_id); + } else { + tet_printf("bt_adapter_start_device_discovery() failed."); + } + } else if (ret == BT_ERROR_ALREADY_DONE) { + tet_printf("BT was already enabled. Device discovery will be started"); + if (bt_adapter_start_device_discovery() == BT_ERROR_NONE) { + tet_printf("bt_adapter_start_device_discovery() succeeded."); + timeout_id = g_timeout_add(60000, timeout_func, mainloop); + g_main_loop_run(mainloop); + g_source_remove(timeout_id); + } else { + tet_printf("bt_adapter_start_device_discovery() failed."); + } + } else { + tet_printf("DTS may fail because bt_adapter_enable() failed."); + } + + if (bt_adapter_unset_state_changed_cb() != BT_ERROR_NONE) { + tet_printf("bt_adapter_unset_state_changed_cb() failed."); + } + + if (bt_adapter_unset_device_discovery_state_changed_cb() != + BT_ERROR_NONE) { + tet_printf("bt_adapter_unset_device_discovery_state_changed_cb() failed."); + } + + tet_printf("TC start."); +} + +static void cleanup(void) +{ + /* end of TC */ + if (device_info != NULL) + free(device_info); + + bt_deinitialize(); + tet_printf("TC end"); +} + +gboolean timeout_func(gpointer data) +{ + tet_printf("[%s] Callback: Timeout.", __FUNCTION__); + g_main_loop_quit((GMainLoop *) data); + return FALSE; +} + +void adapter_state_changed_cb_for_device_p(int result, + bt_adapter_state_e adapter_state, + void *user_data) +{ + tet_printf("Callback: bt_adapter_state_changed_cb() was called"); + if (user_data != NULL && !strcmp((char *)user_data, "startup")) { + if (adapter_state == BT_ADAPTER_ENABLED && result == BT_ERROR_NONE) { + tet_printf("Callback: BT was enabled."); + } else { + tet_printf("Callback: BT was not enabled. DTS will be started but DTS may fail."); + } + + if (mainloop) { + g_main_loop_quit(mainloop); + } + } +} + +void device_discovery_state_changed_cb_for_device_p(int result, + bt_adapter_device_discovery_state_e discovery_state, + bt_adapter_device_discovery_info_s *discovery_info, + void *user_data) +{ + tet_printf("Callback: bt_adapter_device_discovery_state_changed_cb() was called"); + if (user_data != NULL && !strcmp((char *)user_data, "startup")) { + if (discovery_state == BT_ADAPTER_DEVICE_DISCOVERY_FINISHED) { + tet_printf("Callback: Device discovery finished. DTS will be started."); + if (mainloop) { + g_main_loop_quit(mainloop); + } + } else if (discovery_state == BT_ADAPTER_DEVICE_DISCOVERY_FOUND) { + tet_printf("Callback: Devices were founded (%s)", discovery_info->remote_name); + if (discovery_info->remote_name != NULL && !strcmp(discovery_info->remote_name, target_name)) { + discovery_result = true; + tet_printf("Callback: dts_test device was found."); + strncpy(target_address, discovery_info->remote_address, 18); + tet_printf("Callback: device address: [%s]", discovery_info->remote_address); + if (bt_adapter_stop_device_discovery() == BT_ERROR_NONE) { + tet_printf("Callback: Device discovery will be stopped"); + } + } + } + } +} + +void device_bonded_cb(int result, bt_device_info_s * device_info, + void *user_data) +{ + int i = 0; + + tet_printf("Callback: bt_device_bond_created_cb() was called."); + if (result == BT_ERROR_TIMED_OUT) + tet_printf("result is BT_ERROR_TIMEOUT"); + else if (result == BT_ERROR_CANCELLED) + tet_printf("result is BT_ERROR_CANCELLED"); + else if (result == BT_ERROR_AUTH_FAILED) + tet_printf("result is BT_ERROR_AUTH_FAILED"); + else if (result == BT_ERROR_OPERATION_FAILED) + tet_printf("result is BT_ERROR_OPERATION_FAILED"); + else if (result == BT_ERROR_AUTH_REJECTED) + tet_printf("result is BT_ERROR_AUTH_REJECTED"); + else if (result == BT_ERROR_REMOTE_DEVICE_NOT_FOUND) + tet_printf("result is BT_ERROR_REMOTE_DEVICE_NOT_FOUND"); + else if (result == BT_ERROR_NONE) + tet_printf("result is BT_ERROR_NONE"); + else + tet_printf("result is unknown: %s", + _bt_convert_error_to_string(result)); + + /* in case of bt_device_cancel_bonding() */ + if (user_data != NULL && !strcmp((char *)user_data, "cancel")) { + if (result == BT_ERROR_CANCELLED) { + tet_printf("Callback: Cancellation of bonding succeeded"); + callback_result = true; + } else { + tet_printf("Callback: Cancellation of bonding failed"); + } + } /* in case of bt_device_create_bond() */ + else if (user_data != NULL && !strcmp((char *)user_data, "bond")) { + if (device_info == NULL) { + tet_printf("Callback data is NULL"); + + if (result == BT_ERROR_CANCELLED) + tet_printf("No user input in the peer device"); + + if (mainloop) + g_main_loop_quit(mainloop); + + return; + } + + if (device_info->remote_name != NULL && !strcmp(device_info->remote_name, target_name)) { + if (result == BT_ERROR_NONE) { + tet_printf("Callback: Bonding succeeded"); + tet_printf("Callback: serivce count : %d", device_info->service_count); + callback_result = true; + for (i = 0; i < device_info->service_count; i++) { + tet_printf("Callback: service list[%d] - %s", i + 1, device_info->service_uuid[i]); + } + } else { + tet_printf("Callback: Bonding failed"); + } + } + } + + if (mainloop) { + g_main_loop_quit(mainloop); + } +} + +void device_unbonded_cb(int result, char *remote_address, void *user_data) +{ + tet_printf("Callback: bt_device_bond_destroyed_cb() was called."); + tet_printf("Callback: target address"); + if (target_address != NULL) { + tet_printf("device address: %s", target_address); + } else + tet_printf("Callback: target address is NULL!"); + + tet_printf("Callback: address of unbonded device"); + if (remote_address != NULL) { + tet_printf("device address: %s", remote_address); + } else + tet_printf("Callback: address of unbonded device is NULL!"); + + if ((remote_address != NULL) && \ + !strcmp(remote_address, target_address)) { + if (result == BT_ERROR_NONE) { + tet_printf("Callback: Unbonding succeeded"); + callback_result = true; + } else { + tet_printf("Callback: Unbonding failed"); + } + } + + if (mainloop) { + g_main_loop_quit(mainloop); + } + +} + +void device_authorization_state_changed_cb(bt_device_authorization_e authorization_state, \ + char *address, void *user_data) +{ + if (authorization_state == BT_DEVICE_AUTHORIZED) { + if (address != NULL && !strcmp(address, target_address)) { + callback_result = true; + if (mainloop) { + g_main_loop_quit(mainloop); + } + } + } else { + if (address != NULL && !strcmp(address, target_address)) { + callback_result = true; + if (mainloop) { + g_main_loop_quit(mainloop); + } + } + } +} + +void device_get_rssi_strength_cb(char *bt_address, + bt_device_connection_link_type_e link_type, + int rssi_dbm, void *user_data) +{ + tet_printf("Callback:Rssi_strength_cb is called."); + tet_printf("RSSI Strength: [Address %s][Link Type %d][RSSI dBm %d]", + bt_address, link_type, rssi_dbm); +} + +static void device_rssi_enabled_cb(const char *address, + bt_device_connection_link_type_e link_type, + int rssi_enabled, void *user_data) +{ + tet_printf("Callback:Rssi_enabled_cb is called."); + tet_printf("RSSI Enabled: %s %d %d", address, link_type, rssi_enabled); +} + +static void device_rssi_alert_cb(char *bt_address, + bt_device_connection_link_type_e link_type, + int rssi_alert_type, int rssi_alert_dbm, void *user_data) +{ + tet_printf("Callback:rssi_alert_cb is called."); + tet_printf("RSSI Alert: [Address:%s LinkType:%d][RSSI Alert Type:%d dBm:%d]", + bt_address, link_type, rssi_alert_type, rssi_alert_dbm); +} + +/** + * @brief Positive test case of bt_device_set_bond_created_cb() + */ +static void utc_network_bluetooth_device_set_bonded_cb_p(void) +{ + int ret = BT_ERROR_NONE; + + /* Normal operation test */ + ret = bt_device_set_bond_created_cb(device_bonded_cb, "cancel"); + dts_check_eq("bt_device_set_bond_created_cb", ret, BT_ERROR_NONE, + "bt_device_set_bond_created_cb() failed"); +} + +/** + * @brief Positive test case of bt_device_set_bond_destroyed_cb() + */ +static void utc_network_bluetooth_device_set_unbonded_cb_p(void) +{ + int ret = BT_ERROR_NONE; + + /* Normal operation test */ + ret = bt_device_set_bond_destroyed_cb(device_unbonded_cb, NULL); + dts_check_eq("bt_device_set_bond_destroyed_cb", ret, BT_ERROR_NONE, + "bt_device_set_bond_destroyed_cb() failed"); +} + +/** + * @brief Positive test case of bt_device_set_authorization_changed_cb() + */ +static void +utc_network_bluetooth_device_set_authorization_state_changed_cb_p(void) +{ + int ret = BT_ERROR_NONE; + + /* Normal operation test */ + ret = bt_device_set_authorization_changed_cb(device_authorization_state_changed_cb, NULL); + dts_check_eq("bt_device_set_authorization_changed_cb", ret, + BT_ERROR_NONE, + "bt_device_set_authorization_changed_cb() failed"); +} + +/** + * @brief Positive test case of bt_device_cancel_bonding() + */ +static void utc_network_bluetooth_device_cancel_bonding_p(void) +{ + int ret = BT_ERROR_NONE; + callback_result = false; + int timeout_id = 0; + + if (bt_device_set_bond_created_cb(device_bonded_cb, "cancel") != + BT_ERROR_NONE) { + dts_fail("bt_device_cancel_bonding", + "bt_device_set_bond_created_cb() failed"); + } + + /* bond device */ + ret = bt_device_create_bond(target_address); + if (ret != BT_ERROR_NONE) { + dts_fail("bt_device_cancel_bonding", + "bt_device_create_bond failed"); + } + tet_printf("bt_device_create_bond() was called"); + + /* cancel bonding */ + ret = bt_device_cancel_bonding(); + if (ret == BT_ERROR_NONE) { + tet_printf("bt_device_cancel_bonding() will be called"); + timeout_id = g_timeout_add(60000, timeout_func, mainloop); + g_main_loop_run(mainloop); + g_source_remove(timeout_id); + bt_device_unset_bond_created_cb(); + dts_check_eq("bt_device_cancel_bonding", callback_result, true, + "Failed"); + } else { + bt_device_unset_bond_created_cb(); + dts_fail("bt_device_cancel_bonding", + "bt_device_cancel_bonding() failed"); + } +} + +/** + * @brief Positive test case of bt_device_unset_bond_created_cb() + */ +static void utc_network_bluetooth_device_unset_bonded_cb_p(void) +{ + int ret = BT_ERROR_NONE; + + /* Normal operation test */ + ret = bt_device_unset_bond_created_cb(); + dts_check_eq("bt_device_unset_bond_created_cb", ret, BT_ERROR_NONE, + "bt_device_unset_bond_created_cb() failed"); +} + +/** + * @brief Positive test case of bt_device_create_bond() + */ +static void utc_network_bluetooth_device_bond_p(void) +{ + int ret = BT_ERROR_NONE; + int timeout_id = 0; + + callback_result = false; + + /* bond device */ + ret = bt_device_set_bond_created_cb(device_bonded_cb, "bond"); + if (ret != BT_ERROR_NONE) { + tet_printf("bt_device_set_bond_created_cb was called"); + } + + ret = bt_device_create_bond(target_address); + if (ret == BT_ERROR_NONE) { + tet_printf("bt_device_bond_created_cb() will be called"); + timeout_id = g_timeout_add(60000, timeout_func, mainloop); + g_main_loop_run(mainloop); + g_source_remove(timeout_id); + bt_device_unset_bond_created_cb(); + dts_check_eq("bt_device_create_bond", ret, BT_ERROR_NONE, + "bt_device_create_bond() failed."); + } else { + bt_device_unset_bond_created_cb(); + dts_fail("bt_device_create_bond", + "bt_device_create_bond() failed"); + } +} + + +bool bonded_device_cb_for_device_p(bt_device_info_s *dev_info, void *user_data) +{ + int i = 0; + device_info = (bt_device_info_s *) malloc(sizeof(bt_device_info_s)); + if (device_info == NULL) { + tet_printf("Callback: Memory allocation failed"); + } else if (dev_info != NULL) { + device_info->remote_address = strdup(dev_info->remote_address); + tet_printf("device address : %s", device_info->remote_address); + device_info->remote_name = strdup(dev_info->remote_name); + tet_printf("device name : %s", device_info->remote_name); + device_info->bt_class.major_device_class = dev_info->bt_class.major_device_class; + tet_printf("major clasee : %2.2X", device_info->bt_class.major_device_class); + device_info->bt_class.minor_device_class = dev_info->bt_class.minor_device_class; + tet_printf("minor clasee : %2.2X", device_info->bt_class.minor_device_class); + device_info->bt_class.major_service_class_mask = dev_info->bt_class.major_service_class_mask; + tet_printf("service clasee : %2.2X", device_info->bt_class.major_service_class_mask); + device_info->service_count = dev_info->service_count; + tet_printf("service count : %d", device_info->service_count); + if (device_info->service_count > 0) { + device_info->service_uuid = (char **)malloc(sizeof(char *) * device_info->service_count); + if (device_info->service_uuid == NULL) { + tet_printf("Failed to allocate memory"); + } else { + if (dev_info->service_uuid == NULL) { + tet_printf("service_list is NULL"); + } else { + tet_printf("Copy service list"); + for (i = 0; i < device_info->service_count; i++) { + device_info->service_uuid[i] = strdup(dev_info->service_uuid[i]); + tet_printf("Callback: service list[%d] - %s", i + 1, device_info->service_uuid[i]); + } + } + } + } else + device_info->service_uuid = NULL; + + device_info->is_bonded = dev_info->is_bonded; + tet_printf("is_bonded : %d", device_info->is_bonded); + device_info->is_connected = dev_info->is_connected; + tet_printf("is_connected : %d", device_info->is_connected); + tet_printf("Callback: device_info was selected."); + } + + return false; +} + +/** + * @brief Positive test case of bt_adapter_foreach_bonded_device() + */ +static void utc_network_bluetooth_device_foreach_bonded_device_p(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_adapter_foreach_bonded_device(bonded_device_cb_for_device_p, NULL); + if (ret == BT_ERROR_NONE) { + dts_pass("bt_adapter_foreach_bonded_device", + "bt_adapter_foreach_bonded_device pass"); + } else { + dts_fail("bt_adapter_foreach_bonded_device", + "bt_adapter_foreach_bonded_device() failed"); + } +} + +/** + * @brief Positive test case of bt_device_set_alias() + */ +static void utc_network_bluetooth_device_set_alias_p(void) +{ + int ret = BT_ERROR_NONE; + + if (device_info == NULL) { + tet_printf("No device to alias"); + dts_fail("bt_device_set_alias", "bt_device_set_alias() failed"); + return; + } + + ret = bt_device_set_alias(device_info->remote_address, "dts_alias"); + dts_check_eq("bt_device_set_alias", ret, BT_ERROR_NONE, + "bt_device_set_alias() failed"); +} + +/** + * @brief Positive test case of bt_device_set_authorization() + */ +static void utc_network_bluetooth_device_set_authorization_p(void) +{ + int ret = BT_ERROR_NONE; + int timeout_id = 0; + + callback_result = false; + + ret = bt_device_set_authorization(target_address, BT_DEVICE_AUTHORIZED); + if (ret == BT_ERROR_NONE) { + tet_printf("device_authorization_state_changed_cb will be called"); + timeout_id = g_timeout_add(60000, timeout_func, mainloop); + g_main_loop_run(mainloop); + g_source_remove(timeout_id); + dts_check_eq("bt_device_set_authorization", ret, BT_ERROR_NONE, + "bt_device_set_authorization() failed."); + callback_result = false; + } else { + dts_fail("bt_device_set_authorization", + "bt_device_set_authorization() failed"); + } +} + +/** + * @brief Positive test case of bt_device_destroy_bond() + */ +static void utc_network_bluetooth_device_unbond_p(void) +{ + int ret = BT_ERROR_NONE; + int timeout_id = 0; + callback_result = false; + + tet_printf("bt_device_destroy_bond() will start"); + ret = bt_device_destroy_bond(target_address); + if (ret == BT_ERROR_NONE) { + tet_printf("bt_device_unbond_cb() will be called"); + timeout_id = g_timeout_add(60000, timeout_func, mainloop); + g_main_loop_run(mainloop); + g_source_remove(timeout_id); + dts_check_eq("bt_device_destroy_bond", ret, BT_ERROR_NONE, + "bt_device_destroy_bond() failed."); + } else { + dts_fail("bt_device_destroy_bond", + "bt_device_destroy_bond() failed"); + } +} + +/** + * @brief Positive test case of bt_device_unset_bond_destroyed_cb() + */ +static void utc_network_bluetooth_device_unset_unbonded_cb_p(void) +{ + int ret = BT_ERROR_NONE; + + /* Normal operation test */ + ret = bt_device_unset_bond_destroyed_cb(); + dts_check_eq("bt_device_unset_bond_destroyed_cb", ret, BT_ERROR_NONE, + "bt_device_unset_bond_destroyed_cb() failed"); +} + +/** + * @brief Positive test case of bt_device_unset_authorization_changed_cb() + */ +static void utc_network_bluetooth_device_unset_authorization_state_changed_cb_p(void) +{ + int ret = BT_ERROR_NONE; + + /* Normal operation test */ + ret = bt_device_unset_authorization_changed_cb(); + dts_check_eq("bt_device_unset_authorization_changed_cb", ret, + BT_ERROR_NONE, + "bt_device_unset_authorization_changed_cb() failed"); +} diff --git a/TC/testcase/utc_network_bluetooth_gatt_negative.c b/TC/testcase/utc_network_bluetooth_gatt_negative.c new file mode 100755 index 0000000..e15467d --- /dev/null +++ b/TC/testcase/utc_network_bluetooth_gatt_negative.c @@ -0,0 +1,298 @@ +/* + * utc_network_bluetooth_gatt_negative.c + * + * Created on: 23-Sep-2013 + * Author: shagun.garg + */ + +#include +#include +#include +#include +#include + +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; + +static void startup(void); +static void cleanup(void); + +static GMainLoop *mainloop; + +void (*tet_startup) (void) = startup; +void (*tet_cleanup) (void) = cleanup; + +static void utc_network_bluetooth_gatt_foreach_primary_services_n(void); +static void utc_network_bluetooth_gatt_discover_characteristics_n(void); +static void utc_network_bluetooth_gatt_get_service_uuid_n(void); +static void utc_network_bluetooth_gatt_foreach_included_services_n(void); +static void utc_network_bluetooth_gatt_set_characteristic_changed_cb_n(void); +static void utc_network_bluetooth_gatt_unset_characteristic_changed_cb_n(void); +static void utc_network_bluetooth_gatt_get_characteristic_declaration_n(void); +static void utc_network_bluetooth_gatt_set_characteristic_value_n(void); +static void utc_network_bluetooth_gatt_clone_attribute_handle_n(void); +static void utc_network_bluetooth_gatt_destroy_attribute_handle_n(void); +static void utc_network_bluetooth_gatt_connect_n(void); +static void utc_network_bluetooth_gatt_disconnect_n(void); +static void utc_network_bluetooth_set_gatt_connection_state_changed_cb_n(void); +static void utc_network_bluetooth_unset_gatt_connection_state_changed_cb_n(void); + +void adapter_state_changed_cb_for_gatt_n(int result, + bt_adapter_state_e adapter_state, void *user_data); +gboolean timeout_func(gpointer data); + +struct tet_testlist tet_testlist[] = { + {utc_network_bluetooth_gatt_foreach_primary_services_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_gatt_discover_characteristics_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_gatt_get_service_uuid_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_gatt_foreach_included_services_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_gatt_set_characteristic_changed_cb_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_set_gatt_connection_state_changed_cb_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_gatt_connect_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_gatt_disconnect_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_gatt_get_characteristic_declaration_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_gatt_set_characteristic_value_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_gatt_clone_attribute_handle_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_gatt_destroy_attribute_handle_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_unset_gatt_connection_state_changed_cb_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_gatt_unset_characteristic_changed_cb_n, NEGATIVE_TC_IDX}, + {NULL, 0}, +}; + +static void startup(void) +{ + int ret = BT_ERROR_NONE; + int timeout_id = 0; + + /* start of TC */ + mainloop = g_main_loop_new(NULL, FALSE); + + bt_initialize(); + if (bt_adapter_set_state_changed_cb(adapter_state_changed_cb_for_gatt_n, "startup") != BT_ERROR_NONE) { + tet_printf("DTS may fail because bt_adapter_set_state_changed_cb() failed"); + } + + tet_printf("bt_adapter_disable() was called."); + ret = bt_adapter_disable(); + if (ret == BT_ERROR_NONE) { + tet_printf("bt_adapter_disable() succeeded."); + timeout_id = g_timeout_add(60000, timeout_func, mainloop); + g_main_loop_run(mainloop); + g_source_remove(timeout_id); + } else if (ret == BT_ERROR_NOT_ENABLED) { + tet_printf("Bluetooth adapter is not enabled."); + } else { + tet_printf("DTS may fail because bt_adapter_disable() failed"); + } + + if (bt_adapter_unset_state_changed_cb() != BT_ERROR_NONE) { + tet_printf("bt_adapter_set_state_changed_cb() failed."); + } + + tet_printf("TC start"); +} + +static void cleanup(void) +{ + /* end of TC */ + bt_deinitialize(); + tet_printf("TC end."); +} + +gboolean timeout_func(gpointer data) +{ + tet_printf("Callback: Timeout."); + g_main_loop_quit((GMainLoop *) data); + return FALSE; +} + +/** + * @brief Callback funtions + */ +void adapter_state_changed_cb_for_gatt_n(int result, + bt_adapter_state_e adapter_state, void *user_data) +{ + tet_printf("Callback: bt_adapter_state_changed_cb was called."); + if ((user_data != NULL) && !strcmp((char *)user_data, "startup")) { + if (adapter_state == BT_ADAPTER_DISABLED && result == BT_ERROR_NONE) { + tet_printf("Callback: BT was disabled. DTS will be started."); + } else { + tet_printf("Callback: BT was not disabled. DTS will be started but DTS may fail."); + } + + if (mainloop) { + g_main_loop_quit(mainloop); + } + } +} + + +/** + * @brief Negative test case of bt_gatt_foreach_primary_services() + */ +static void utc_network_bluetooth_gatt_foreach_primary_services_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_gatt_foreach_primary_services(NULL, NULL, NULL); + dts_check_eq("bt_gatt_foreach_primary_services", ret, + BT_ERROR_INVALID_PARAMETER, + "BT_ERROR_INVALID_PARAMETER must be returned when remote address and callback parameters are NULL."); +} + +/** + * @brief Negative test case of bt_gatt_discover_characteristics() + */ +static void utc_network_bluetooth_gatt_discover_characteristics_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_gatt_discover_characteristics(NULL, NULL, NULL); + dts_check_eq("bt_gatt_discover_characteristics", ret, + BT_ERROR_INVALID_PARAMETER, + "BT_ERROR_INVALID_PARAMETER must be returned when service and callback parameters are NULL."); +} + +/** + * @brief Negative test case of bt_gatt_get_service_uuid() + */ +static void utc_network_bluetooth_gatt_get_service_uuid_n(void) +{ + int ret = BT_ERROR_NONE; + ret = bt_gatt_get_service_uuid(NULL, NULL); + dts_check_eq("bt_gatt_get_service_uuid", ret, BT_ERROR_INVALID_PARAMETER, + "BT_ERROR_INVALID_PARAMETER must be returned when service parameter is NULL."); +} + +/** + * @brief Negative test case of bt_gatt_foreach_included_services() + */ +static void utc_network_bluetooth_gatt_foreach_included_services_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_gatt_foreach_included_services(NULL, NULL, NULL); + dts_check_eq("bt_socket_unset_connection_state_changed_cb", ret, + BT_ERROR_INVALID_PARAMETER, + "BT_ERROR_INVALID_PARAMETER must be returned when service and callback parameters are NULL."); +} + +/** + * @brief Negative test case of bt_gatt_set_characteristic_changed_cb() + */ +static void utc_network_bluetooth_gatt_set_characteristic_changed_cb_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_gatt_set_characteristic_changed_cb(NULL, NULL); + dts_check_eq("bt_gatt_set_characteristic_changed_cb", ret, + BT_ERROR_INVALID_PARAMETER, + "BT_ERROR_INVALID_PARAMETER must be returned when service and callback parameters are NULL."); +} + +/** + * @brief Negative test case of bt_gatt_unset_characteristic_changed_cb() + */ +static void utc_network_bluetooth_gatt_unset_characteristic_changed_cb_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_gatt_unset_characteristic_changed_cb(); + dts_check_eq("bt_gatt_unset_characteristic_changed_cb", ret, + BT_ERROR_NOT_INITIALIZED, + "BT_ERROR_NOT_INITIALIZED must be returned when BT is not initialized."); +} + + +/** + * @brief Negative test case of bt_gatt_get_characteristic_declaration() + */ +static void utc_network_bluetooth_gatt_get_characteristic_declaration_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_gatt_get_characteristic_declaration(NULL, NULL, NULL, 0); + dts_check_eq("bt_gatt_get_characteristic_declaration", ret, + BT_ERROR_INVALID_PARAMETER, + "BT_ERROR_INVALID_PARAMETER must be returned when characteristic parameter is NULL."); +} + +/** + * @brief Negative test case of bt_gatt_set_characteristic_value() + */ +static void utc_network_bluetooth_gatt_set_characteristic_value_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_gatt_set_characteristic_value(NULL, NULL, -1); + dts_check_eq("bt_socket_connect_rfcomm", ret, BT_ERROR_INVALID_PARAMETER, + "BT_ERROR_INVALID_PARAMETER must be returned when characteristic and value parameters are NULL."); +} + +/** + * @brief Negative test case of bt_gatt_clone_attribute_handle() + */ +static void utc_network_bluetooth_gatt_clone_attribute_handle_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_gatt_clone_attribute_handle(NULL, NULL); + dts_check_eq("bt_gatt_clone_attribute_handle", ret, + BT_ERROR_INVALID_PARAMETER, + "BT_ERROR_INVALID_PARAMETER must be returned when origin parameter is NULL."); +} + +/** + * @brief Negative test case of bt_gatt_destroy_attribute_handle() + */ +static void utc_network_bluetooth_gatt_destroy_attribute_handle_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_gatt_destroy_attribute_handle(NULL); + dts_check_eq("bt_gatt_destroy_attribute_handle", ret, + BT_ERROR_INVALID_PARAMETER, + "BT_ERROR_INVALID_PARAMETER must be returned when handle parameter is NULL."); +} + +static void utc_network_bluetooth_gatt_connect_n(void) +{ + int ret = BT_ERROR_NONE; + ret = bt_gatt_connect(NULL, false); + dts_check_eq("bt_gatt_connect", ret, + BT_ERROR_INVALID_PARAMETER, + "BT_ERROR_INVALID_PARAMETER must be returned when address is NULL."); + +} + +static void utc_network_bluetooth_gatt_disconnect_n(void) +{ + int ret = BT_ERROR_NONE; + ret = bt_gatt_disconnect(NULL); + dts_check_eq("bt_gatt_connect", ret, + BT_ERROR_INVALID_PARAMETER, + "BT_ERROR_INVALID_PARAMETER must be returned when address is NULL."); + +} + +static void utc_network_bluetooth_set_gatt_connection_state_changed_cb_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_gatt_set_connection_state_changed_cb(NULL, NULL); + dts_check_eq("bt_gatt_set_connection_state_changed_cb", ret, + BT_ERROR_INVALID_PARAMETER, + "BT_ERROR_INVALID_PARAMETER must be returned when address is NULL."); +} + +static void utc_network_bluetooth_unset_gatt_connection_state_changed_cb_n(void) +{ + int ret = BT_ERROR_NONE; + ret = bt_deinitialize(); + ret = bt_gatt_unset_connection_state_changed_cb(); + dts_check_eq("bt_gatt_unset_connection_state_changed_cb", ret, + BT_ERROR_NOT_INITIALIZED, + "BT_ERROR_NOT_INITIALIZED must be returned when BT is not initialized."); +} diff --git a/TC/testcase/utc_network_bluetooth_gatt_positive.c b/TC/testcase/utc_network_bluetooth_gatt_positive.c new file mode 100755 index 0000000..3c4730f --- /dev/null +++ b/TC/testcase/utc_network_bluetooth_gatt_positive.c @@ -0,0 +1,407 @@ +/* + * utc_network_bluetooth_gatt_positive.c + * + * Created on: 23-Sep-2013 + * Author: shagun.garg + */ + +#include +#include +#include +#include +#include + +#define CONFIG_FILE_PATH "/opt/home/capi-network-bluetooth/tetware.conf" + +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; + +static void startup(void); +static void cleanup(void); + +void (*tet_startup) (void) = startup; +void (*tet_cleanup) (void) = cleanup; + +char *remote_address; +static GMainLoop *mainloop; + +static void utc_network_bluetooth_gatt_foreach_primary_services_p(void); +static void utc_network_bluetooth_gatt_discover_characteristics_p(void); + +static void utc_network_bluetooth_gatt_get_service_uuid_p(void); +static void utc_network_bluetooth_gatt_foreach_included_services_p(void); +static void utc_network_bluetooth_gatt_set_characteristic_changed_cb_p(void); +static void utc_network_bluetooth_gatt_unset_characteristic_changed_cb_p(void); +static void utc_network_bluetooth_gatt_get_characteristic_declaration_p(void); +static void utc_network_bluetooth_gatt_set_characteristic_value_p(void); +static void utc_network_bluetooth_gatt_clone_attribute_handle_p(void); +static void utc_network_bluetooth_gatt_destroy_attribute_handle_p(void); +static void utc_network_bluetooth_gatt_connect_p(void); +static void utc_network_bluetooth_gatt_disconnect_p(void); +static void utc_network_bluetooth_set_gatt_connection_state_changed_cb_p(void); +static void utc_network_bluetooth_unset_gatt_connection_state_changed_cb_p(void); + +gboolean timeout_func(gpointer data); +void adapter_state_changed_cb_for_gatt_p(int result, bt_adapter_state_e adapter_state, + void *user_data); +void adapter_le_state_changed_cb_for_gatt_p(int result, bt_adapter_le_state_e adapter_state, + void *user_data); + +bool primary_service_cb_for_gatt_p(bt_gatt_attribute_h service, void *user_data); +bool included_service_cb_for_gatt_p(bt_gatt_attribute_h service, void *user_data); +bool characteristics_discovered_cb_for_gatt_p(int result, int index, int total, bt_gatt_attribute_h characteristic, + void *user_data); +void characteristics_changed_cb_for_gatt_p(bt_gatt_attribute_h characteristic, unsigned char *value, int value_length, + void *user_data); +void gatt_connection_state_changed_cb(int result, bool connected, + const char *remote_address, void *user_data); + +struct tet_testlist tet_testlist[] = { + {utc_network_bluetooth_gatt_foreach_primary_services_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_gatt_discover_characteristics_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_gatt_get_service_uuid_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_gatt_foreach_included_services_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_gatt_set_characteristic_changed_cb_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_set_gatt_connection_state_changed_cb_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_gatt_connect_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_gatt_disconnect_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_unset_gatt_connection_state_changed_cb_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_gatt_unset_characteristic_changed_cb_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_gatt_get_characteristic_declaration_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_gatt_set_characteristic_value_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_gatt_clone_attribute_handle_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_gatt_destroy_attribute_handle_p, POSITIVE_TC_IDX}, + {NULL, 0}, +}; + +int get_value_from_file(void) +{ + FILE *fp; + char *token; + char buf[100]; + + fp = fopen(CONFIG_FILE_PATH, "r"); + if (fp == NULL) { + tet_printf("Default configuration is used\n"); + return -1; + } + while (fgets(buf, sizeof(buf), fp)) { + if (buf[0] == '#' || buf[0] == '\n') + continue; + + token = strrchr(buf, '\n'); + if (token == NULL) { + tet_printf("g_conf is too long\n"); + break; + } + *token = '\0'; + + token = strtok(buf, "="); + if (token == NULL) { + continue; + } + if (strcasecmp(token, "BT_ADDR_LE") == 0) { + token = strtok(NULL, "="); + remote_address = strdup(token); + fclose(fp); + return 0; + } + } + fclose(fp); + return -1; +} + +static void startup(void) +{ + bt_error_e ret = BT_ERROR_NONE; + int timeout_id = 0; + + if(get_value_from_file() == -1) { + tet_printf("Failed to read."); + } + + /* start of TC */ + tet_printf("TC start."); + mainloop = g_main_loop_new(NULL, FALSE); + + bt_initialize(); + + if (bt_adapter_set_state_changed_cb(adapter_state_changed_cb_for_gatt_p, "startup") != BT_ERROR_NONE) { + tet_printf("DTS may fail because bt_adapter_set_state_changed_cb() failed"); + } + + if (bt_adapter_le_set_state_changed_cb(adapter_le_state_changed_cb_for_gatt_p, "enable") != BT_ERROR_NONE) { + dts_fail("bt_adapter_le_enable", + "bt_adapter_le_set_state_changed_cb() failed."); + } + + tet_printf("bt_adapter_enable() was called."); + ret = bt_adapter_enable(); + if (ret == BT_ERROR_NONE) { + tet_printf("bt_adapter_enable() succeeded."); + tet_printf("bt_adapter_le_enable() was called."); + ret = bt_adapter_le_enable(); + if (ret == BT_ERROR_NONE) { + tet_printf("bt_adapter_le_enable() succeeded."); + timeout_id = g_timeout_add(60000, timeout_func, mainloop); + g_main_loop_run(mainloop); + g_source_remove(timeout_id); + } + else { + tet_printf("DTS may fail because bt_adapter_le_enable failed"); + bt_adapter_le_unset_state_changed_cb(); + } + } else if (ret == BT_ERROR_NOT_ENABLED) { + tet_printf("Bluetooth adapter is not enabled."); + } else { + tet_printf("DTS may fail because bt_adapter_enable failed"); + } + + if (bt_adapter_unset_state_changed_cb() != BT_ERROR_NONE) { + tet_printf("bt_adapter_set_state_changed_cb() failed."); + } + + tet_printf("TC start"); +} + +static void cleanup(void) +{ + /* end of TC */ + bt_deinitialize(); + tet_printf("TC end."); +} + +gboolean timeout_func(gpointer data) +{ + tet_printf("[%s] Callback: Timeout.", __FUNCTION__); + g_main_loop_quit((GMainLoop *) data); + return FALSE; +} + + + +void adapter_state_changed_cb_for_gatt_p(int result, bt_adapter_state_e adapter_state, void* user_data) +{ + +} +void adapter_le_state_changed_cb_for_gatt_p(int result, bt_adapter_le_state_e adapter_le__state, void* user_data) +{ + +} + +bool primary_service_cb_for_gatt_p(bt_gatt_attribute_h service, void *user_data) +{ + return false; +} + +bool characteristics_discovered_cb_for_gatt_p(int result, int index, int total, bt_gatt_attribute_h characteristic, + void *user_data) +{ + return false; +} + +bool included_service_cb_for_gatt_p(bt_gatt_attribute_h service, void *user_data) +{ + return false; +} + +void characteristics_changed_cb_for_gatt_p(bt_gatt_attribute_h characteristic, unsigned char *value, int value_length, + void *user_data) +{ + +} + +void gatt_connection_state_changed_cb(int result, bool connected, + const char *remote_address, void *user_data) +{ + tet_printf("bt_gatt_connection_state_changed_cb : %d", result); + if (connected) + tet_printf("LE Connected"); + else + tet_printf("LE Disconnected"); +} + +/** + * @brief Positive test case of bt_gatt_foreach_primary_services() + */ +static void utc_network_bluetooth_gatt_foreach_primary_services_p(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_gatt_foreach_primary_services(remote_address, primary_service_cb_for_gatt_p, NULL); + dts_check_eq("bt_gatt_foreach_primary_services", ret, BT_ERROR_NONE, + "bt_gatt_foreach_primary_services() failed."); +} + + +/** + * @brief Positive test case of bt_gatt_discover_characteristics() + */ +static void utc_network_bluetooth_gatt_discover_characteristics_p(void) +{ + int ret = BT_ERROR_NONE; + bt_gatt_attribute_h gatt_serv; + gatt_serv = g_malloc0(sizeof(bt_gatt_attribute_h)); + + ret = bt_gatt_discover_characteristics(gatt_serv, characteristics_discovered_cb_for_gatt_p, NULL); + dts_check_eq("bt_gatt_discover_characteristics", ret, BT_ERROR_NONE, "bt_gatt_discover_characteristics() failed."); +} + + +/** + * @brief Positive test case of bt_gatt_get_service_uuid() + */ +static void utc_network_bluetooth_gatt_get_service_uuid_p(void) +{ + int ret = BT_ERROR_NONE; + char *uid = "dts_uid"; + bt_gatt_attribute_h gatt_serv; + gatt_serv = g_malloc0(sizeof(bt_gatt_attribute_h)); + + ret = bt_gatt_get_service_uuid(gatt_serv, &uid); + dts_check_eq("bt_gatt_get_service_uuid", ret, BT_ERROR_NONE, + "bt_gatt_get_service_uuid() failed."); +} + +/** + * @brief Positive test case of bt_gatt_foreach_included_services() + */ +static void utc_network_bluetooth_gatt_foreach_included_services_p(void) +{ + int ret = BT_ERROR_NONE; + bt_gatt_attribute_h gatt_serv; + gatt_serv = g_malloc0(sizeof(bt_gatt_attribute_h)); + ret = bt_gatt_foreach_included_services(gatt_serv, included_service_cb_for_gatt_p, NULL); + dts_check_eq("bt_gatt_foreach_included_services", ret, BT_ERROR_NONE, + "bt_gatt_foreach_included_services() failed."); +} + + +/** + * @brief Positive test case of bt_gatt_set_characteristic_changed_cb() + */ +static void utc_network_bluetooth_gatt_set_characteristic_changed_cb_p(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_gatt_set_characteristic_changed_cb(characteristics_changed_cb_for_gatt_p, NULL); + dts_check_eq("bt_gatt_set_characteristic_changed_cb", ret, BT_ERROR_NONE, + "bt_gatt_set_characteristic_changed_cb() failed."); +} + + +/** + * @brief Positive test case of bt_gatt_unset_characteristic_changed_cb() + */ +static void utc_network_bluetooth_gatt_unset_characteristic_changed_cb_p(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_gatt_unset_characteristic_changed_cb(); + dts_check_eq("bt_gatt_unset_characteristic_changed_cb", ret, BT_ERROR_NONE, + "bt_gatt_unset_characteristic_changed_cb() failed."); + +} + + +/** + * @brief Positive test case of bt_gatt_get_characteristic_declaration() + */ +static void utc_network_bluetooth_gatt_get_characteristic_declaration_p(void) +{ + int ret = BT_ERROR_NONE; + char **uid = "dts_uid"; + unsigned char **val = "dts_value"; + int l = 1; + bt_gatt_attribute_h gatt_charac; + gatt_charac = g_malloc0(sizeof(bt_gatt_attribute_h)); + ret = bt_gatt_get_characteristic_declaration(gatt_charac, uid, val, &l); + dts_check_eq("bt_gatt_get_characteristic_declaration", ret, BT_ERROR_NONE, + "gatt_get_characteristic_declaration() failed."); +} + + +/** + * @brief Positive test case of bt_gatt_set_characteristic_value() + */ +static void utc_network_bluetooth_gatt_set_characteristic_value_p(void) +{ + int ret = BT_ERROR_NONE; + bt_gatt_attribute_h gatt_charac; + gatt_charac = g_malloc0(sizeof(bt_gatt_attribute_h)); + const unsigned char *gatt_value = "dts_value"; + ret = bt_gatt_set_characteristic_value(gatt_charac, gatt_value, strlen("dts_value")); + dts_check_eq("bt_gatt_set_characteristic_value", ret, BT_ERROR_NONE, + "bt_gatt_set_characteristic_value() failed."); +} + + +/** + * @brief Positive test case of bt_gatt_clone_attribute_handle() + */ +static void utc_network_bluetooth_gatt_clone_attribute_handle_p(void) +{ + int ret = BT_ERROR_NONE; + bt_gatt_attribute_h gatt_origin; + bt_gatt_attribute_h gatt_clone; + gatt_origin = g_malloc0(sizeof(bt_gatt_attribute_h)); + gatt_clone = g_malloc0(sizeof(bt_gatt_attribute_h)); + + ret = bt_gatt_clone_attribute_handle(&gatt_clone, gatt_origin); + dts_check_eq("bt_gatt_clone_attribute_handle", ret, BT_ERROR_NONE, + "bt_gatt_clone_attribute_handle() failed."); +} + + +/** + * @brief Positive test case of bt_gatt_destroy_attribute_handle() + */ +static void utc_network_bluetooth_gatt_destroy_attribute_handle_p(void) +{ + int ret = BT_ERROR_NONE; + bt_gatt_attribute_h gatt_handle; + gatt_handle = g_malloc0(sizeof(bt_gatt_attribute_h)); + + ret = bt_gatt_destroy_attribute_handle(gatt_handle); + dts_check_eq("bt_gatt_destroy_attribute_handle", ret, BT_ERROR_NONE, + "bt_gatt_destroy_attribute_handle() failed."); +} + +static void utc_network_bluetooth_gatt_connect_p(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_gatt_connect(remote_address, false); + dts_check_eq("bt_gatt_connect", ret, BT_ERROR_NONE, + "bt_gatt_connect() failed."); + +} + +static void utc_network_bluetooth_gatt_disconnect_p(void) +{ + int ret = BT_ERROR_NONE; + ret = bt_gatt_disconnect(remote_address); + dts_check_eq("bt_gatt_connect", ret, BT_ERROR_NONE, + "bt_gatt_connect() failed."); + +} + +static void utc_network_bluetooth_set_gatt_connection_state_changed_cb_p(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_gatt_set_connection_state_changed_cb(gatt_connection_state_changed_cb, NULL); + dts_check_eq("bt_gatt_set_connection_state_changed_cb", ret, BT_ERROR_NONE, + "bt_gatt_set_connection_state_changed_cb() failed."); +} + +static void utc_network_bluetooth_unset_gatt_connection_state_changed_cb_p(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_gatt_unset_connection_state_changed_cb(); + dts_check_eq("bt_gatt_unset_connection_state_changed_cb", ret, BT_ERROR_NONE, + "bt_gatt_unset_connection_state_changed_cb() failed."); +} diff --git a/TC/testcase/utc_network_bluetooth_hdp_negative.c b/TC/testcase/utc_network_bluetooth_hdp_negative.c new file mode 100644 index 0000000..d157a1f --- /dev/null +++ b/TC/testcase/utc_network_bluetooth_hdp_negative.c @@ -0,0 +1,201 @@ +/* + * 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 +#include +#include +#include +#include + +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; + +static void startup(void); +static void cleanup(void); + +static GMainLoop *mainloop; + +void (*tet_startup) (void) = startup; +void (*tet_cleanup) (void) = cleanup; + +static void utc_network_bluetooth_hdp_register_sink_app_n(void); +static void utc_network_bluetooth_hdp_unregister_sink_app_n(void); +static void utc_network_bluetooth_hdp_connect_to_source_n(void); +static void utc_network_bluetooth_hdp_disconnect_n(void); +static void utc_network_bluetooth_hdp_send_data_n(void); +static void utc_network_bluetooth_hdp_set_connection_state_changed_cb_n(void); +static void utc_network_bluetooth_hdp_set_data_received_cb_n(void); + +void adapter_state_changed_cb_for_hdp_n(int result, + bt_adapter_state_e adapter_state, void *user_data); +gboolean timeout_func(gpointer data); + +struct tet_testlist tet_testlist[] = { + { utc_network_bluetooth_hdp_register_sink_app_n, NEGATIVE_TC_IDX }, + { utc_network_bluetooth_hdp_connect_to_source_n, NEGATIVE_TC_IDX }, + { utc_network_bluetooth_hdp_send_data_n, NEGATIVE_TC_IDX }, + { utc_network_bluetooth_hdp_set_connection_state_changed_cb_n, NEGATIVE_TC_IDX }, + { utc_network_bluetooth_hdp_set_data_received_cb_n, NEGATIVE_TC_IDX }, + { utc_network_bluetooth_hdp_disconnect_n, NEGATIVE_TC_IDX }, + { utc_network_bluetooth_hdp_unregister_sink_app_n, NEGATIVE_TC_IDX }, + { NULL, 0 }, +}; + +static void startup(void) +{ + int ret = BT_ERROR_NONE; + int timeout_id = 0; + + /* start of TC */ + mainloop = g_main_loop_new(NULL, FALSE); + + bt_initialize(); + if (bt_adapter_set_state_changed_cb(adapter_state_changed_cb_for_hdp_n, "startup") != BT_ERROR_NONE) { + tet_printf("DTS may fail because bt_adapter_set_state_changed_cb() failed"); + } + + tet_printf("bt_adapter_disable() was called."); + ret = bt_adapter_disable(); + if (ret == BT_ERROR_NONE) { + tet_printf("bt_adapter_disable() succeeded."); + timeout_id = g_timeout_add(60000, timeout_func, mainloop); + g_main_loop_run(mainloop); + g_source_remove(timeout_id); + } else if (ret == BT_ERROR_NOT_ENABLED) { + tet_printf("Bluetooth adapter is not enabled."); + } else { + tet_printf("DTS may fail because bt_adapter_disable() failed"); + } + + if (bt_adapter_unset_state_changed_cb() != BT_ERROR_NONE) { + tet_printf("bt_adapter_set_state_changed_cb() failed."); + } + + tet_printf("TC start"); +} + +static void cleanup(void) +{ + /* end of TC */ + bt_deinitialize(); + tet_printf("TC end."); +} + +gboolean timeout_func(gpointer data) +{ + tet_printf("Callback: Timeout."); + g_main_loop_quit((GMainLoop *) data); + return FALSE; +} + +/** + * @brief Callback funtions + */ +void adapter_state_changed_cb_for_hdp_n(int result, + bt_adapter_state_e adapter_state, void *user_data) +{ + +} + + +/** + * @brief Negative test case of bt_hdp_set_data_received_cb() + */ +static void utc_network_bluetooth_hdp_set_data_received_cb_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_hdp_set_data_received_cb(NULL, NULL); + dts_check_eq("bt_hdp_set_data_received_cb", ret, BT_ERROR_INVALID_PARAMETER, + "BT_ERROR_INVALID_PARAMETER is returned when cb parameters are NULL"); +} + +/** + * @brief Negative test case of bt_hdp_set_connection_state_changed_cb() + */ +static void utc_network_bluetooth_hdp_set_connection_state_changed_cb_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_hdp_set_connection_state_changed_cb(NULL, NULL, NULL); + dts_check_eq("bt_hdp_set_connection_state_changed_cb", ret, + BT_ERROR_INVALID_PARAMETER, + "BT_ERROR_INVALID_PARAMETER is returned when cb parameters are NULL"); +} + + +/** + * @brief Negative test case of bt_hdp_disconnect() + */ +static void utc_network_bluetooth_hdp_disconnect_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_hdp_disconnect(NULL, 1); + dts_check_eq("bt_hdp_disconnect", ret, BT_ERROR_INVALID_PARAMETER, + "BT_ERROR_INVALID_PARAMETER must be returned when remote address parameter is NULL"); +} + +/** + * @brief Negative test case of bt_hdp_connect_to_source() + */ +static void utc_network_bluetooth_hdp_connect_to_source_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_hdp_connect_to_source(NULL, NULL); + dts_check_eq("bt_hdp_connect_to_source", ret, BT_ERROR_INVALID_PARAMETER, + "BT_ERROR_INVALID_PARAMETER must be returned when remote address and app_id parameter are NULL"); +} + +/** + * @brief Negative test case of bt_hdp_register_sink_app() + */ +static void utc_network_bluetooth_hdp_register_sink_app_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_hdp_register_sink_app(1, NULL); + dts_check_eq("bt_hdp_register_sink_app", ret, BT_ERROR_INVALID_PARAMETER, + "BT_ERROR_INVALID_PARAMETER must be returned when app_id parameter is NULL"); +} + +/** + * @brief Negative test case of bt_hdp_unregister_sink_appe() + */ +static void utc_network_bluetooth_hdp_unregister_sink_app_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_hdp_unregister_sink_app(NULL); + dts_check_eq("bt_shdp_unregister_sink", ret, BT_ERROR_INVALID_PARAMETER, + "BT_ERROR_INVALID_PARAMETER must be returned when app_id parameter is NULL"); +} + +/** + * @brief Negative test case of bt_hdp_send_data() + */ +static void utc_network_bluetooth_hdp_send_data_n(void) +{ + int ret = BT_ERROR_NONE; + char *data = "dts_test"; + + ret = bt_hdp_send_data(1, data, sizeof(data)); + dts_check_eq("bt_hdp_send_data", ret, BT_ERROR_NOT_ENABLED, + "BT_ERROR_NOT_ENABLED must be returned when BT is not enabled"); +} diff --git a/TC/testcase/utc_network_bluetooth_hdp_positive.c b/TC/testcase/utc_network_bluetooth_hdp_positive.c new file mode 100755 index 0000000..b99e6f5 --- /dev/null +++ b/TC/testcase/utc_network_bluetooth_hdp_positive.c @@ -0,0 +1,242 @@ +/* + * 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 +#include +#include +#include +#include + +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; + +static void startup(void); +static void cleanup(void); + +static GMainLoop *mainloop; + +void(*tet_startup)(void) = startup; +void(*tet_cleanup)(void) = cleanup; + +const char *appid = "/org/bluez/health_app_2"; +const char *remote_adr = "00:22:58:07:77:BB"; + +static void utc_network_bluetooth_hdp_register_sink_app_p(void); +static void utc_network_bluetooth_hdp_unregister_sink_app_p(void); +static void utc_network_bluetooth_hdp_connect_to_source_p(void); +static void utc_network_bluetooth_hdp_disconnect_p(void); +static void utc_network_bluetooth_hdp_send_data_p(void); +static void utc_network_bluetooth_hdp_set_connection_state_changed_cb_p(void); +static void utc_network_bluetooth_hdp_unset_connection_state_changed_cb_p(void); +static void utc_network_bluetooth_hdp_set_data_received_cb_p(void); +static void utc_network_bluetooth_hdp_unset_data_received_cb_p(void); + +void data_received_cb_for_hdp_p(unsigned int channel, const char *data, + unsigned int size, void *user_data); +void connected_cb_for_hdp_p(int result, const char *remote_address, + const char *app_id, + bt_hdp_channel_type_e type, unsigned int channel, void *user_data); +void disconnected_cb_for_hdp_p(int result, const char *remote_address, + unsigned int channel, void *user_data); + + + +void adapter_state_changed_cb_for_hdp_p(int result, + bt_adapter_state_e adapter_state, void *user_data); +gboolean timeout_func(gpointer data); + +struct tet_testlist tet_testlist[] = { + {utc_network_bluetooth_hdp_register_sink_app_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_hdp_set_connection_state_changed_cb_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_hdp_set_data_received_cb_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_hdp_connect_to_source_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_hdp_send_data_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_hdp_disconnect_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_hdp_unset_connection_state_changed_cb_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_hdp_unset_data_received_cb_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_hdp_unregister_sink_app_p, POSITIVE_TC_IDX}, + {NULL, 0}, +}; + + +static void startup(void) +{ + int ret = BT_ERROR_NONE; + int timeout_id = 0; + + /* start of TC */ + mainloop = g_main_loop_new(NULL, FALSE); + + bt_initialize(); + if (bt_adapter_set_state_changed_cb(adapter_state_changed_cb_for_hdp_p, "startup") != BT_ERROR_NONE) { + tet_printf("DTS may fail because bt_adapter_set_state_changed_cb() failed"); + } + + tet_printf("bt_adapter_enable() was called."); + ret = bt_adapter_enable(); + if (ret == BT_ERROR_NONE) { + tet_printf("bt_adapter_enable() succeeded."); + timeout_id = g_timeout_add(60000, timeout_func, mainloop); + g_main_loop_run(mainloop); + g_source_remove(timeout_id); + } else if (ret != BT_ERROR_ALREADY_DONE) { + tet_printf("DTS may fail because bt_adapter_disable() failed"); + } else if (ret == BT_ERROR_NOT_ENABLED) { + tet_printf("Bluetooth adapter is not enabled."); + } else { + tet_printf("DTS may fail because bt_adapter_disable() failed"); + } + + if (bt_adapter_unset_state_changed_cb() != BT_ERROR_NONE) { + tet_printf("bt_adapter_set_state_changed_cb() failed."); + } + + tet_printf("TC start"); +} + +static void cleanup(void) +{ + /* end of TC */ + bt_deinitialize(); + tet_printf("TC end."); +} + +gboolean timeout_func(gpointer data) +{ + tet_printf("Callback: Timeout."); + g_main_loop_quit((GMainLoop *) data); + return FALSE; +} + +void adapter_state_changed_cb_for_hdp_p(int result, + bt_adapter_state_e adapter_state, void *user_data) +{ + +} + +void data_received_cb_for_hdp_p(unsigned int channel, const char *data, + unsigned int size, void *user_data) +{ + +} + +void connected_cb_for_hdp_p(int result, const char *remote_address, + const char *app_id, + bt_hdp_channel_type_e type, unsigned int channel, void *user_data) +{ + +} + +void disconnected_cb_for_hdp_p(int result, const char *remote_address, + unsigned int channel, void *user_data) +{ + +} + +static void utc_network_bluetooth_hdp_set_data_received_cb_p(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_hdp_set_data_received_cb(data_received_cb_for_hdp_p, NULL); + dts_check_eq("bt_hdp_set_data_received_cb", ret, BT_ERROR_NONE, + "bt_hdp_set_data_received_cb() failed."); +} + + +static void utc_network_bluetooth_hdp_unset_data_received_cb_p(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_hdp_unset_data_received_cb(); + dts_check_eq("bt_hdp_unset_data_received_cb", ret, BT_ERROR_NONE, + "bt_hdp_unset_data_received_cb() failed."); +} + +static void utc_network_bluetooth_hdp_set_connection_state_changed_cb_p(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_hdp_set_connection_state_changed_cb(connected_cb_for_hdp_p, + disconnected_cb_for_hdp_p, NULL); + dts_check_eq("bt_hdp_set_connection_state_changed_cb", ret, BT_ERROR_NONE, + "bt_hdp_set_connection_state_changed_cb() failed."); +} + +static void utc_network_bluetooth_hdp_unset_connection_state_changed_cb_p(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_hdp_unset_connection_state_changed_cb(); + dts_check_eq("bt_hdp_unset_connection_state_changed_cb", ret, BT_ERROR_NONE, + "bt_hdp_unset_connection_state_changed_cb() failed."); +} + +static void utc_network_bluetooth_hdp_send_data_p(void) +{ + int ret = BT_ERROR_NONE; + char *dts_test = "dts_test"; + + ret = bt_hdp_send_data(1, "dts_test", sizeof(dts_test)); + dts_check_eq("bt_hdp_send_data", ret, BT_ERROR_NONE, + "bt_hdp_send_data() failed."); +} + +static void utc_network_bluetooth_hdp_disconnect_p(void) +{ + int ret = BT_ERROR_NONE; + char *remote_adr = "00:22:58:07:77:BB"; + + ret = bt_hdp_disconnect(remote_adr, 0); + dts_check_eq("bt_hdp_disconnect", ret, BT_ERROR_NONE, + "bt_hdp_disconnect() failed."); +} + +static void utc_network_bluetooth_hdp_connect_to_source_p(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_hdp_connect_to_source(remote_adr, appid); + dts_check_eq("bt_hdp_connect_to_source", ret, BT_ERROR_NONE, + "bt_hdp_connect_to_source() failed."); + +} + +static void utc_network_bluetooth_hdp_unregister_sink_app_p(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_hdp_unregister_sink_app(appid); + dts_check_eq("bt_hdp_unregister_sink_app", ret, BT_ERROR_NONE, + "bt_hdp_unregister_sink_app() failed."); + +} + +static void utc_network_bluetooth_hdp_register_sink_app_p(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_hdp_register_sink_app(1, &appid); + dts_check_eq("bt_hdp_register_sink_app", ret, BT_ERROR_NONE, + "bt_hdp_register_sink_app() failed."); + +} + + + + + diff --git a/TC/testcase/utc_network_bluetooth_hid_negative.c b/TC/testcase/utc_network_bluetooth_hid_negative.c new file mode 100755 index 0000000..e8cb5f8 --- /dev/null +++ b/TC/testcase/utc_network_bluetooth_hid_negative.c @@ -0,0 +1,142 @@ +/* + * 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 +#include +#include +#include +#include + +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; + +static void startup(void); +static void cleanup(void); + +static GMainLoop *mainloop; + +void (*tet_startup) (void) = startup; +void (*tet_cleanup) (void) = cleanup; + +static void utc_network_bluetooth_hid_host_initialize_n(void); +static void utc_network_bluetooth_hid_host_connect_n(void); +static void utc_network_bluetooth_hid_host_disconnect_n(void); + +void adapter_state_changed_cb_for_hid_n(int result, + bt_adapter_state_e adapter_state, void *user_data); +gboolean timeout_func(gpointer data); + +struct tet_testlist tet_testlist[] = { + {utc_network_bluetooth_hid_host_initialize_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_hid_host_connect_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_hid_host_disconnect_n, NEGATIVE_TC_IDX}, + {NULL, 0}, +}; + + +static void startup(void) +{ + int ret = BT_ERROR_NONE; + int timeout_id = 0; + + /* start of TC */ + mainloop = g_main_loop_new(NULL, FALSE); + + bt_initialize(); + if (bt_adapter_set_state_changed_cb(adapter_state_changed_cb_for_hid_n, "startup") != BT_ERROR_NONE) { + tet_printf("DTS may fail because bt_adapter_set_state_changed_cb() failed"); + } + + tet_printf("bt_adapter_disable() was called."); + ret = bt_adapter_disable(); + if (ret == BT_ERROR_NONE) { + tet_printf("bt_adapter_disable() succeeded."); + timeout_id = g_timeout_add(60000, timeout_func, mainloop); + g_main_loop_run(mainloop); + g_source_remove(timeout_id); + } else if (ret == BT_ERROR_NOT_ENABLED) { + tet_printf("Bluetooth adapter is not enabled."); + } else { + tet_printf("DTS may fail because bt_adapter_disable() failed"); + } + + if (bt_adapter_unset_state_changed_cb() != BT_ERROR_NONE) { + tet_printf("bt_adapter_set_state_changed_cb() failed."); + } + + tet_printf("TC start"); +} + + +static void cleanup(void) +{ + /* end of TC */ + bt_deinitialize(); + tet_printf("TC end."); +} + + +gboolean timeout_func(gpointer data) +{ + tet_printf("Callback: Timeout."); + g_main_loop_quit((GMainLoop *) data); + return FALSE; +} + +void adapter_state_changed_cb_for_hid_n(int result, + bt_adapter_state_e adapter_state, void *user_data) +{ + +} +void host_connection_state_changed_cb_for_hid_p(int result, + bool connected, const char *remote_address, void *user_data) +{ + +} + +static void utc_network_bluetooth_hid_host_initialize_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_hid_host_initialize(NULL, NULL); + dts_check_eq("bt_hid_host_initialize", ret, + BT_ERROR_INVALID_PARAMETER, + "BT_ERROR_INVALID_PARAMETER must be returned when callback parameter is NULL."); +} + + +static void utc_network_bluetooth_hid_host_connect_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_hid_host_initialize(host_connection_state_changed_cb_for_hid_p, NULL); + + ret = bt_hid_host_connect(NULL); + dts_check_eq("bt_hid_host_connect", ret, BT_ERROR_INVALID_PARAMETER, + "BT_ERROR_INVALID_PARAMETER must be returned when remote address parameter is NULL."); +} + + +static void utc_network_bluetooth_hid_host_disconnect_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_hid_host_disconnect(NULL); + dts_check_eq("bt_hid_host_disconnect", ret, BT_ERROR_INVALID_PARAMETER, + "BT_ERROR_INVALID_PARAMETER must be returned when remote address parameter is NULL."); +} diff --git a/TC/testcase/utc_network_bluetooth_hid_positive.c b/TC/testcase/utc_network_bluetooth_hid_positive.c new file mode 100755 index 0000000..95e7db1 --- /dev/null +++ b/TC/testcase/utc_network_bluetooth_hid_positive.c @@ -0,0 +1,159 @@ +/* + * 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 +#include +#include +#include +#include + +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; + +static void startup(void); +static void cleanup(void); + +static GMainLoop *mainloop; + +void (*tet_startup) (void) = startup; +void (*tet_cleanup) (void) = cleanup; + +static void utc_network_bluetooth_hid_host_initialize_p(void); +static void utc_network_bluetooth_hid_host_deinitialize_p(void); +static void utc_network_bluetooth_hid_host_connect_p(void); +static void utc_network_bluetooth_hid_host_disconnect_p(void); + +void adapter_state_changed_cb_for_hid_p(int result, + bt_adapter_state_e adapter_state, void *user_data); +void host_connection_state_changed_cb_for_hid_p(int result, + bool connected, const char *remote_address, void *user_data); +gboolean timeout_func(gpointer data); + +struct tet_testlist tet_testlist[] = { + {utc_network_bluetooth_hid_host_initialize_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_hid_host_connect_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_hid_host_disconnect_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_hid_host_deinitialize_p, POSITIVE_TC_IDX}, + {NULL, 0}, +}; + + +static void startup(void) +{ + int ret = BT_ERROR_NONE; + int timeout_id = 0; + + /* start of TC */ + mainloop = g_main_loop_new(NULL, FALSE); + + bt_initialize(); + if (bt_adapter_set_state_changed_cb(adapter_state_changed_cb_for_hid_p, "startup") != BT_ERROR_NONE) { + tet_printf("DTS may fail because bt_adapter_set_state_changed_cb() failed"); + } + + tet_printf("bt_adapter_enable() was called."); + ret = bt_adapter_enable(); + if (ret == BT_ERROR_NONE) { + tet_printf("bt_adapter_enable() succeeded."); + timeout_id = g_timeout_add(60000, timeout_func, mainloop); + g_main_loop_run(mainloop); + g_source_remove(timeout_id); + } else if (ret != BT_ERROR_ALREADY_DONE) { + tet_printf("DTS may fail because bt_adapter_disable() failed"); + } else if (ret == BT_ERROR_NOT_ENABLED) { + tet_printf("Bluetooth adapter is not enabled."); + } else { + tet_printf("DTS may fail because bt_adapter_disable() failed"); + } + + if (bt_adapter_unset_state_changed_cb() != BT_ERROR_NONE) { + tet_printf("bt_adapter_set_state_changed_cb() failed."); + } + + tet_printf("TC start"); +} + + +static void cleanup(void) +{ + /* end of TC */ + bt_deinitialize(); + tet_printf("TC end."); +} + + +gboolean timeout_func(gpointer data) +{ + tet_printf("Callback: Timeout."); + g_main_loop_quit((GMainLoop *) data); + return FALSE; +} + +void adapter_state_changed_cb_for_hid_p(int result, + bt_adapter_state_e adapter_state, void *user_data) +{ + +} + +void host_connection_state_changed_cb_for_hid_p(int result, + bool connected, const char *remote_address, void *user_data) +{ + +} + + +static void utc_network_bluetooth_hid_host_initialize_p(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_hid_host_initialize(host_connection_state_changed_cb_for_hid_p, NULL); + dts_check_eq("bt_hid_host_initialize", ret, BT_ERROR_NONE, + "bt_hid_host_initialize() failed."); +} + + +static void utc_network_bluetooth_hid_host_deinitialize_p(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_hid_host_deinitialize(); + dts_check_eq("bt_hid_host_deinitialize", ret, BT_ERROR_NONE, + "bt_hid_host_deinitialize() failed."); +} + + +static void utc_network_bluetooth_hid_host_connect_p(void) +{ + int ret = BT_ERROR_NONE; + char *remote_addr = "dts_addr"; + + ret = bt_hid_host_connect(remote_addr); + dts_check_eq("bt_hid_host_connect", ret, BT_ERROR_NONE, + "bt_hid_host_connect() failed."); +} + + +static void utc_network_bluetooth_hid_host_disconnect_p(void) +{ + int ret = BT_ERROR_NONE; + char *remote_addr = "dts_addr"; + + ret = bt_hid_host_disconnect(remote_addr); + dts_check_eq("bt_hid_host_disconnect", ret, BT_ERROR_NONE, + "bt_hid_host_disconnect() failed."); +} diff --git a/TC/testcase/utc_network_bluetooth_opp-client_negative.c b/TC/testcase/utc_network_bluetooth_opp-client_negative.c new file mode 100755 index 0000000..77ecc79 --- /dev/null +++ b/TC/testcase/utc_network_bluetooth_opp-client_negative.c @@ -0,0 +1,136 @@ +/* + * 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 +#include +#include +#include +#include + +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; + +static void startup(void); +static void cleanup(void); + +static GMainLoop *mainloop; + +void (*tet_startup) (void) = startup; +void (*tet_cleanup) (void) = cleanup; + +static void utc_network_bluetooth_opp_client_add_file_n(void); +static void utc_network_bluetooth_opp_client_push_files_n(void); + +void adapter_state_changed_cb_for_opp_client_n(int result, + bt_adapter_state_e adapter_state, void *user_data); +gboolean timeout_func(gpointer data); + +struct tet_testlist tet_testlist[] = { + {utc_network_bluetooth_opp_client_add_file_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_opp_client_push_files_n, NEGATIVE_TC_IDX}, + {NULL, 0}, +}; + + +static void startup(void) +{ + int ret = BT_ERROR_NONE; + int timeout_id = 0; + + /* start of TC */ + mainloop = g_main_loop_new(NULL, FALSE); + + bt_initialize(); + bt_opp_client_initialize(); + if (bt_adapter_set_state_changed_cb(adapter_state_changed_cb_for_opp_client_n, "startup") != BT_ERROR_NONE) { + tet_printf("DTS may fail because bt_adapter_set_state_changed_cb() failed"); + } + + tet_printf("bt_adapter_disable() was called."); + ret = bt_adapter_disable(); + if (ret == BT_ERROR_NONE) { + tet_printf("bt_adapter_disable() succeeded."); + timeout_id = g_timeout_add(60000, timeout_func, mainloop); + g_main_loop_run(mainloop); + g_source_remove(timeout_id); + } else if (ret == BT_ERROR_NOT_ENABLED) { + tet_printf("Bluetooth adapter is not enabled."); + } else { + tet_printf("DTS may fail because bt_adapter_disable() failed"); + } + + if (bt_adapter_unset_state_changed_cb() != BT_ERROR_NONE) { + tet_printf("bt_adapter_set_state_changed_cb() failed."); + } + + tet_printf("TC start"); +} + + +static void cleanup(void) +{ + /* end of TC */ + bt_deinitialize(); + tet_printf("TC end."); +} + + +gboolean timeout_func(gpointer data) +{ + tet_printf("Callback: Timeout."); + g_main_loop_quit((GMainLoop *) data); + return FALSE; +} + +void adapter_state_changed_cb_for_opp_client_n(int result, + bt_adapter_state_e adapter_state, void *user_data) +{ + if (user_data != NULL && !strcmp((char *)user_data, "startup")) { + if (adapter_state == BT_ADAPTER_ENABLED && result == BT_ERROR_NONE) { + tet_printf("Callback: BT was enabled."); + bt_adapter_start_device_discovery(); + } else { + tet_printf("Callback: BT was not enabled. DTS will be started but DTS may fail."); + if (mainloop) { + g_main_loop_quit(mainloop); + } + } + } +} + + +static void utc_network_bluetooth_opp_client_add_file_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_opp_client_add_file(NULL); + dts_check_eq("bt_opp_client_add_file", ret, BT_ERROR_INVALID_PARAMETER, + "BT_ERROR_INVALID_PARAMETER must be returned when file parameter is NULL"); +} + + +static void utc_network_bluetooth_opp_client_push_files_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_opp_client_push_files(NULL, NULL, NULL, NULL, NULL); + dts_check_eq("bt_opp_client_push_files", ret, BT_ERROR_INVALID_PARAMETER, + "BT_ERROR_INVALID_PARAMETER must be returned when parameters are NULL"); +} + + diff --git a/TC/testcase/utc_network_bluetooth_opp-client_positive.c b/TC/testcase/utc_network_bluetooth_opp-client_positive.c new file mode 100755 index 0000000..580a788 --- /dev/null +++ b/TC/testcase/utc_network_bluetooth_opp-client_positive.c @@ -0,0 +1,261 @@ +/* + * 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 +#include +#include +#include +#include +#include +#include +#include + +#define CONFIG_FILE_PATH "/opt/home/capi-network-bluetooth/tetware.conf" +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; + +static void startup(void); +static void cleanup(void); + +static GMainLoop *mainloop; + +void(*tet_startup)(void) = startup; +void(*tet_cleanup)(void) = cleanup; + +char *remote_address; + +static void utc_network_bluetooth_opp_client_initialize_p(void); +static void utc_network_bluetooth_opp_client_deinitialize_p(void); +static void utc_network_bluetooth_opp_client_add_file_p(void); +static void utc_network_bluetooth_opp_client_clear_files_p(void); +static void utc_network_bluetooth_opp_client_push_files_p(void); +static void utc_network_bluetooth_opp_client_cancel_push_p(void); + +void push_responded_cb_for_opp_client_p(int result, + const char *remote_address, void *user_data); +void push_progress_cb_for_opp_client_p(const char *file, + long long size, int percent, void *user_data); +void push_finished_cb_for_opp_client_p(int result, + const char *remote_address, void *user_data); +void adapter_state_changed_cb_for_opp_client_p(int result, + bt_adapter_state_e adapter_state, void *user_data); +gboolean timeout_func(gpointer data); + +struct tet_testlist tet_testlist[] = { + {utc_network_bluetooth_opp_client_initialize_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_opp_client_add_file_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_opp_client_push_files_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_opp_client_cancel_push_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_opp_client_clear_files_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_opp_client_deinitialize_p, POSITIVE_TC_IDX}, + {NULL, 0}, +}; + +int get_value_from_file(void) +{ + FILE *fp; + char *token; + char buf[100]; + + fp = fopen(CONFIG_FILE_PATH, "r"); + if (fp == NULL) { + tet_printf("Default configuration is used\n"); + return -1; + } + while (fgets(buf, sizeof(buf), fp)) { + if (buf[0] == '#' || buf[0] == '\n') + continue; + + token = strrchr(buf, '\n'); + if (token == NULL) { + tet_printf("g_conf is too long\n"); + break; + } + *token = '\0'; + + token = strtok(buf, "="); + if (token == NULL) { + continue; + } + if (strcasecmp(token, "BT_ADDR_MOBILE") == 0) { + token = strtok(NULL, "="); + remote_address = strdup(token); + fclose(fp); + return 0; + } + } + fclose(fp); + return -1; +} + +static void startup(void) +{ + int ret = BT_ERROR_NONE; + int timeout_id = 0; + + if(get_value_from_file() == -1) { + tet_printf("Failed to read."); + } + + /* start of TC */ + mainloop = g_main_loop_new(NULL, FALSE); + + bt_initialize(); + if (bt_adapter_set_state_changed_cb(adapter_state_changed_cb_for_opp_client_p, "startup") != BT_ERROR_NONE) { + tet_printf("DTS may fail because bt_adapter_set_state_changed_cb() failed"); + } + + tet_printf("bt_adapter_enable() was called."); + ret = bt_adapter_enable(); + if (ret == BT_ERROR_NONE) { + tet_printf("bt_adapter_enable() succeeded."); + timeout_id = g_timeout_add(60000, timeout_func, mainloop); + g_main_loop_run(mainloop); + g_source_remove(timeout_id); + } else if (ret != BT_ERROR_ALREADY_DONE) { + tet_printf("DTS may fail because bt_adapter_disable() failed"); + } else if (ret == BT_ERROR_NOT_ENABLED) { + tet_printf("Bluetooth adapter is not enabled."); + } else { + tet_printf("DTS may fail because bt_adapter_disable() failed"); + } + + if (bt_adapter_unset_state_changed_cb() != BT_ERROR_NONE) { + tet_printf("bt_adapter_set_state_changed_cb() failed."); + } + + tet_printf("TC start"); +} + +static void cleanup(void) +{ + /* end of TC */ + bt_deinitialize(); + tet_printf("TC end."); +} + +gboolean timeout_func(gpointer data) +{ + tet_printf("Callback: Timeout."); + g_main_loop_quit((GMainLoop *) data); + return FALSE; +} + +void adapter_state_changed_cb_for_opp_client_p(int result, + bt_adapter_state_e adapter_state, void *user_data) +{ + if ((user_data != NULL) && !strcmp((char *)user_data, "startup")) { + if (adapter_state == BT_ADAPTER_ENABLED && result == BT_ERROR_NONE) { + tet_printf("Callback: BT was enabled."); + bt_adapter_start_device_discovery(); + } else { + tet_printf("Callback: BT was not enabled. DTS will be started but DTS may fail."); + if (mainloop) { + g_main_loop_quit(mainloop); + } + } + } +} + +void push_responded_cb_for_opp_client_p(int result, + const char *remote_address, void *user_data) +{ + +} + + +void push_progress_cb_for_opp_client_p(const char *file, long long size, + int percent, void *user_data) +{ + +} + + +void push_finished_cb_for_opp_client_p(int result, + const char *remote_address, void *user_data) +{ + +} + + +static void utc_network_bluetooth_opp_client_initialize_p(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_opp_client_initialize(); + dts_check_eq("bt_opp_client_initialize", ret, + BT_ERROR_NONE, "bt_opp_client_initialize() failed."); +} + +static void utc_network_bluetooth_opp_client_deinitialize_p(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_opp_client_deinitialize(); + dts_check_eq("bt_opp_client_deinitialize", ret, + BT_ERROR_NONE, "bt_opp_client_deinitialize() failed."); + +} + +static void utc_network_bluetooth_opp_client_add_file_p(void) +{ + int ret = BT_ERROR_NONE; + int fd = 0; + const char *file = "/tmp/a.txt"; + + if (access("/tmp/a.txt", F_OK) < 0) { + fd = open("/tmp/a.txt", O_RDWR|O_CREAT,0666); + write(fd, "hey", 3); + } + + ret = bt_opp_client_add_file(file); + dts_check_eq("bt_opp_client_add_file", ret, + BT_ERROR_NONE, "bt_opp_client_add_file() failed"); +} + + +static void utc_network_bluetooth_opp_client_clear_files_p(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_opp_client_clear_files(); + dts_check_eq("bt_opp_client_clear_files", ret, + BT_ERROR_NONE, "bt_opp_client_clear_files() failed."); + +} + + +static void utc_network_bluetooth_opp_client_push_files_p(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_opp_client_push_files(remote_address, push_responded_cb_for_opp_client_p, + push_progress_cb_for_opp_client_p, push_finished_cb_for_opp_client_p, NULL); + + dts_check_eq("bt_opp_client_push_files", ret, + BT_ERROR_NONE, "bt_opp_client_push_files() failed"); +} + +static void utc_network_bluetooth_opp_client_cancel_push_p(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_opp_client_cancel_push(); + dts_check_eq("bt_opp_client_cancel_push", ret, + BT_ERROR_NONE, "bt_opp_client_cancel_push() failed."); +} diff --git a/TC/testcase/utc_network_bluetooth_opp-server_negative.c b/TC/testcase/utc_network_bluetooth_opp-server_negative.c new file mode 100755 index 0000000..a7d911d --- /dev/null +++ b/TC/testcase/utc_network_bluetooth_opp-server_negative.c @@ -0,0 +1,191 @@ +/* + * + * 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 +#include +#include +#include +#include + +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; + +static void startup(void); +static void cleanup(void); + +static GMainLoop *mainloop; +const char *dest = "/tmp"; + +void (*tet_startup) (void) = startup; +void (*tet_cleanup) (void) = cleanup; + +static void utc_network_bluetooth_opp_server_initialize_n(void); +static void utc_network_bluetooth_opp_server_initialize_by_connection_request_n(void); +static void utc_network_bluetooth_opp_server_accept_n(void); +static void utc_network_bluetooth_opp_server_set_destination_n(void); + +void adapter_state_changed_cb_for_opp_server_n(int result, + bt_adapter_state_e adapter_state, void *user_data); +void transfer_progress_cb_for_opp_server(const char *file, long long size, + int percent, void *user_data); +void transfer_finished_cb_for_opp_server(int result, const char *file, + long long size, void *user_data); +void push_requested_cb_for_opp_server(const char *file, int size, void *user_data); + +gboolean timeout_func(gpointer data); + +struct tet_testlist tet_testlist[] = { + {utc_network_bluetooth_opp_server_initialize_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_opp_server_initialize_by_connection_request_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_opp_server_set_destination_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_opp_server_accept_n, NEGATIVE_TC_IDX}, + {NULL, 0}, +}; + +static void startup(void) +{ + int ret = BT_ERROR_NONE; + int timeout_id = 0; + + /* start of TC */ + mainloop = g_main_loop_new(NULL, FALSE); + + bt_initialize(); + if (bt_adapter_set_state_changed_cb(adapter_state_changed_cb_for_opp_server_n, "startup") != BT_ERROR_NONE) { + tet_printf("DTS may fail because bt_adapter_set_state_changed_cb() failed"); + } + + tet_printf("bt_adapter_disable() was called."); + ret = bt_adapter_disable(); + if (ret == BT_ERROR_NONE) { + tet_printf("bt_adapter_disable() succeeded."); + timeout_id = g_timeout_add(60000, timeout_func, mainloop); + g_main_loop_run(mainloop); + g_source_remove(timeout_id); + } else if (ret == BT_ERROR_NOT_ENABLED) { + tet_printf("Bluetooth adapter is not enabled."); + } else { + tet_printf("DTS may fail because bt_adapter_disable() failed"); + } + + if (bt_adapter_unset_state_changed_cb() != BT_ERROR_NONE) { + tet_printf("bt_adapter_set_state_changed_cb() failed."); + } + + tet_printf("TC start"); +} + + +static void cleanup(void) +{ + /* end of TC */ + bt_deinitialize(); + tet_printf("TC end."); +} + + +gboolean timeout_func(gpointer data) +{ + tet_printf("Callback: Timeout."); + g_main_loop_quit((GMainLoop *)data); + return FALSE; +} + +void push_requested_cb_for_opp_server(const char *file, int size, + void *user_data) +{ + +} + +void transfer_progress_cb_for_opp_server(const char *file, long long size, + int percent, void *user_data) +{ + +} + +void transfer_finished_cb_for_opp_server(int result, const char *file, + long long size, void *user_data) +{ + +} + +/** + * @brief Callback funtions + */ +void adapter_state_changed_cb_for_opp_server_n(int result, + bt_adapter_state_e adapter_state, void *user_data) +{ + tet_printf("Callback: bt_adapter_state_changed_cb was called."); + if ((user_data != NULL) && !strcmp((char *)user_data, "startup")) { + if (adapter_state == BT_ADAPTER_DISABLED && result == BT_ERROR_NONE) { + tet_printf("Callback: BT was disabled. DTS will be started."); + } else { + tet_printf("Callback: BT was not disabled. DTS will be started but DTS may fail."); + } + + if (mainloop) { + g_main_loop_quit(mainloop); + } + } +} + +static void utc_network_bluetooth_opp_server_initialize_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_opp_server_initialize(NULL, NULL, NULL); + dts_check_eq("bt_opp_server_initialize", ret, BT_ERROR_INVALID_PARAMETER, + "BT_ERROR_INVALID_PARAMETER must be returned when destination parameter is NULL"); +} + + +static void utc_network_bluetooth_opp_server_accept_n(void) +{ + int ret = BT_ERROR_NONE; + ret = bt_opp_server_accept(transfer_progress_cb_for_opp_server, + transfer_finished_cb_for_opp_server, NULL, NULL, NULL); + dts_check_eq("bt_opp_server_accept", ret, BT_ERROR_INVALID_PARAMETER, + "BT_ERROR_NOT_INITIALIZED must be returned."); + +} + + +static void utc_network_bluetooth_opp_server_set_destination_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_opp_server_initialize(dest, push_requested_cb_for_opp_server_p, + NULL); + + ret = bt_opp_server_set_destination(NULL); + dts_check_eq("bt_opp_server_set_destination", ret, + BT_ERROR_INVALID_PARAMETER, + "BT_ERROR_INVALID_PARAMETER must be returned destination parameter is NULL"); +} + +static void utc_network_bluetooth_opp_server_initialize_by_connection_request_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_opp_server_initialize_by_connection_request(NULL, NULL, NULL); + dts_check_eq("bt_opp_server_initialize_by_connection_request", ret, + BT_ERROR_INVALID_PARAMETER, + "BT_ERROR_INVALID_PARAMETER must be returned destination parameter is NULL"); + +} diff --git a/TC/testcase/utc_network_bluetooth_opp-server_positive.c b/TC/testcase/utc_network_bluetooth_opp-server_positive.c new file mode 100755 index 0000000..39efb77 --- /dev/null +++ b/TC/testcase/utc_network_bluetooth_opp-server_positive.c @@ -0,0 +1,224 @@ +/* + * 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 +#include +#include +#include +#include + +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; + +static void startup(void); +static void cleanup(void); + +static GMainLoop *mainloop; +const char *dest = "/tmp"; + +void (*tet_startup) (void) = startup; +void (*tet_cleanup) (void) = cleanup; + +static void utc_network_bluetooth_opp_server_initialize_p(void); +static void utc_network_bluetooth_opp_server_initialize_by_connection_request_p(void); +static void utc_network_bluetooth_opp_server_deinitialize_p(void); +static void utc_network_bluetooth_opp_server_accept_p(void); +static void utc_network_bluetooth_opp_server_reject_p(void); +static void utc_network_bluetooth_opp_server_set_destination_p(void); + +void push_requested_cb_for_opp_server_p(const char *file, int size, void *user_data); +void connection_requested_cb_for_opp_server_p(const char *remote_address, + void *user_data); +void adapter_state_changed_cb_for_opp_server_p(int result, + bt_adapter_state_e adapter_state, void *user_data); +void transfer_finished_cb_for_opp_server_p(int result, const char *file, + long long size, void *user_data); +void transfer_progress_cb_for_opp_server_p(int result, const char *file, + long long size, void *user_data); + + +gboolean timeout_func(gpointer data); + + +struct tet_testlist tet_testlist[] = { + {utc_network_bluetooth_opp_server_initialize_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_opp_server_initialize_by_connection_request_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_opp_server_set_destination_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_opp_server_accept_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_opp_server_reject_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_opp_server_deinitialize_p, POSITIVE_TC_IDX}, + {NULL, 0}, +}; + +static void startup(void) +{ + int ret = BT_ERROR_NONE; + int timeout_id = 0; + + /* start of TC */ + mainloop = g_main_loop_new(NULL, FALSE); + + bt_initialize(); + if (bt_adapter_set_state_changed_cb(adapter_state_changed_cb_for_opp_server_p, "startup") != BT_ERROR_NONE) { + tet_printf("DTS may fail because bt_adapter_set_state_changed_cb() failed"); + } + + tet_printf("bt_adapter_enable() was called."); + ret = bt_adapter_enable(); + if (ret == BT_ERROR_NONE) { + tet_printf("bt_adapter_enable() succeeded."); + timeout_id = g_timeout_add(60000, timeout_func, mainloop); + g_main_loop_run(mainloop); + g_source_remove(timeout_id); + } else if (ret != BT_ERROR_ALREADY_DONE) { + tet_printf("DTS may fail because bt_adapter_disable() failed"); + } else if (ret == BT_ERROR_NOT_ENABLED) { + tet_printf("Bluetooth adapter is not enabled."); + } else { + tet_printf("DTS may fail because bt_adapter_disable() failed"); + } + + if (bt_adapter_unset_state_changed_cb() != BT_ERROR_NONE) { + tet_printf("bt_adapter_set_state_changed_cb() failed."); + } + + tet_printf("TC start"); +} + + +static void cleanup(void) +{ + /* end of TC */ + bt_deinitialize(); + tet_printf("TC end."); +} + + +gboolean timeout_func(gpointer data) +{ + tet_printf("Callback: Timeout."); + g_main_loop_quit((GMainLoop *)data); + return FALSE; +} + + +void adapter_state_changed_cb_for_opp_server_p(int result, + bt_adapter_state_e adapter_state, void *user_data) +{ + +} + + +void push_requested_cb_for_opp_server_p(const char *file, int size, + void *user_data) +{ + +} + +void connection_requested_cb_for_opp_server_p(const char *remote_address, + void *user_data) +{ + +} + +void transfer_progress_cb_for_opp_server_p(int result, const char *file, + long long size, void *user_data) +{ + +} + +void transfer_finished_cb_for_opp_server_p(int result, const char *file, + long long size, void *user_data) +{ + +} + +static void utc_network_bluetooth_opp_server_initialize_p(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_opp_server_initialize(dest, push_requested_cb_for_opp_server_p, + NULL); + + if (ret != BT_ERROR_RESOURCE_BUSY) { + dts_check_eq("bt_opp_server_initialize", ret, BT_ERROR_NONE, + "bt_opp_server_initialize() failed"); + } else { + dts_check_eq("bt_opp_server_initialize", ret, BT_ERROR_RESOURCE_BUSY, + "bt_opp_server_initialize() failed"); + } + + +} + +static void utc_network_bluetooth_opp_server_deinitialize_p(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_opp_server_deinitialize(); + dts_check_eq("bt_opp_server_deinitialize", ret, BT_ERROR_NONE, + "bt_opp_server_deinitialize() failed."); +} + +static void utc_network_bluetooth_opp_server_accept_p(void) +{ + int ret = BT_ERROR_NONE; + int tid = 0; + const char *name = "abc"; + ret = bt_opp_server_accept(transfer_progress_cb_for_opp_server_p, + transfer_finished_cb_for_opp_server_p, name, NULL, &tid); + dts_check_eq("bt_opp_server_accept", ret, + BT_ERROR_NONE, "bt_opp_server_accept() failed."); + +} + +static void utc_network_bluetooth_opp_server_reject_p(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_opp_server_reject(); + dts_check_eq("bt_opp_server_reject", ret, + BT_ERROR_NONE, "bt_opp_server_reject() failed."); +} + +static void utc_network_bluetooth_opp_server_set_destination_p(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_opp_server_set_destination(dest); + dts_check_eq("bt_opp_server_set_destination", ret, + BT_ERROR_NONE, "bt_opp_server_destination() failed"); +} + +static void utc_network_bluetooth_opp_server_initialize_by_connection_request_p(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_opp_server_initialize_by_connection_request(dest, + connection_requested_cb_for_opp_server_p, NULL); + dts_check_eq("bt_opp_server_initialize_by_connection_request", ret, + BT_ERROR_NONE, + "bt_opp_server_initialize_by_connection_request() failed"); + +} + + + + + + diff --git a/TC/testcase/utc_network_bluetooth_pan_negative.c b/TC/testcase/utc_network_bluetooth_pan_negative.c new file mode 100644 index 0000000..ec9db0c --- /dev/null +++ b/TC/testcase/utc_network_bluetooth_pan_negative.c @@ -0,0 +1,166 @@ +/* + * utc_network_bluetooth_pan_negative.c + * + * Created on: 20-Sep-2013 + * Author: mrinal.m + */ + +#include "bluetooth.h" +#include +#include + +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; + +static void startup(void); +static void cleanup(void); + +static GMainLoop *mainloop; + +void (*tet_startup) (void) = startup; +void (*tet_cleanup) (void) = cleanup; + +static void utc_network_bluetooth_nap_set_connection_state_changed_n(void); +static void utc_network_bluetooth_panu_set_connection_state_changed_n(void); +static void utc_network_bluetooth_panu_connect_n(void); +static void utc_network_bluetooth_nap_disconnect_n(void); +static void utc_network_bluetooth_panu_disconnect_n(void); + +void adapter_state_changed_cb_for_pan_n(int result, + bt_adapter_state_e adapter_state, void *user_data); +gboolean timeout_func(gpointer data); + + +struct tet_testlist tet_testlist[] = { + {utc_network_bluetooth_nap_set_connection_state_changed_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_panu_set_connection_state_changed_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_panu_connect_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_nap_disconnect_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_panu_disconnect_n, NEGATIVE_TC_IDX}, + {NULL, 0}, +}; + +static void startup(void) +{ + int ret = BT_ERROR_NONE; + int timeout_id = 0; + + /* start of TC */ + mainloop = g_main_loop_new(NULL, FALSE); + + bt_initialize(); + if (bt_adapter_set_state_changed_cb(adapter_state_changed_cb_for_pan_n, "startup") != BT_ERROR_NONE) { + tet_printf("DTS may fail because bt_adapter_set_state_changed_cb() failed"); + } + + tet_printf("bt_adapter_disable() was called."); + ret = bt_adapter_disable(); + if (ret == BT_ERROR_NONE) { + tet_printf("bt_adapter_disable() succeeded."); + timeout_id = g_timeout_add(60000, timeout_func, mainloop); + g_main_loop_run(mainloop); + g_source_remove(timeout_id); + } else if (ret == BT_ERROR_NOT_ENABLED) { + tet_printf("Bluetooth adapter is not enabled."); + } else { + tet_printf("DTS may fail because bt_adapter_disable() failed"); + } + + if (bt_adapter_unset_state_changed_cb() != BT_ERROR_NONE) { + tet_printf("bt_adapter_set_state_changed_cb() failed."); + } + + tet_printf("TC start"); +} + + +static void cleanup(void) +{ + /* end of TC */ + bt_deinitialize(); + tet_printf("TC end."); +} + + +gboolean timeout_func(gpointer data) +{ + tet_printf("Callback: Timeout."); + g_main_loop_quit((GMainLoop *)data); + return FALSE; +} + + + + +/** + * @brief Negative test case of bt_nap_set_connection_state_changed_cb() + */ + +void adapter_state_changed_cb_for_pan_n(int result, + bt_adapter_state_e adapter_state, + void *user_data) +{ + +} + +static void utc_network_bluetooth_nap_set_connection_state_changed_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_nap_set_connection_state_changed_cb(NULL, NULL); + dts_check_eq("bt_nap_set_connection_state_changed_cb", ret, + BT_ERROR_INVALID_PARAMETER, + "bt_nap_set_connection_state_changed_cb() failed."); + +} + +/** + * @brief Negative test case of bt_panu_set_connection_state_changed_cb() + */ +static void utc_network_bluetooth_panu_set_connection_state_changed_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_panu_set_connection_state_changed_cb(NULL, NULL); + dts_check_eq("bt_panu_set_connection_state_changed_cb", ret, + BT_ERROR_INVALID_PARAMETER, + "bt_panu_set_connection_state_changed_cb() failed."); + +} + +/** + * @brief Negative test case of bt_panu_connect() + */ +static void utc_network_bluetooth_panu_connect_n(void) +{ + int ret = BT_ERROR_NONE; + ret = bt_panu_connect(NULL, BT_PANU_SERVICE_TYPE_NAP); + dts_check_eq("bt_panu_connect", ret, BT_ERROR_INVALID_PARAMETER, + "bt_panu_connect() failed."); + +} + +/** + * @brief Negative test case of bt_nap_disconnect() + */ +static void utc_network_bluetooth_nap_disconnect_n(void) +{ + int ret = BT_ERROR_NONE; + ret = bt_nap_disconnect(NULL); + dts_check_eq("bt_nap_disconnect", ret, BT_ERROR_INVALID_PARAMETER, + "bt_nap_disconnect() failed."); + +} +/** + * @brief Negative test case of bt_panu_disconnect() + */ +static void utc_network_bluetooth_panu_disconnect_n(void) +{ + int ret = BT_ERROR_NONE; + ret = bt_panu_disconnect(NULL); + dts_check_eq("bt_panu_disconnect", ret, BT_ERROR_INVALID_PARAMETER, + "bt_panu_disconnect() failed."); + +} diff --git a/TC/testcase/utc_network_bluetooth_pan_positive.c b/TC/testcase/utc_network_bluetooth_pan_positive.c new file mode 100755 index 0000000..4526508 --- /dev/null +++ b/TC/testcase/utc_network_bluetooth_pan_positive.c @@ -0,0 +1,265 @@ +/* + * utc_network_bluetooth_pan_positive.c + * + * Created on: 20-Sep-2013 + * Author: mrinal.m + */ + +#include +#include +#include + +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; + +static void startup(void); +static void cleanup(void); + +static GMainLoop *mainloop; + +void (*tet_startup) (void) = startup; +void (*tet_cleanup) (void) = cleanup; + +static void utc_network_bluetooth_nap_activate_p(void); +static void utc_network_bluetooth_nap_deactivate_p(void); +static void utc_network_bluetooth_nap_disconnect_all_p(void); +static void utc_network_bluetooth_nap_set_connection_state_changed_p(void); +static void utc_network_bluetooth_nap_unset_connection_state_changed_p(void); +static void utc_network_bluetooth_panu_set_connection_state_changed_p(void); +static void utc_network_bluetooth_panu_unset_connection_state_changed_p(void); +static void utc_network_bluetooth_panu_connect_p(void); +static void utc_network_bluetooth_nap_disconnect_p(void); +static void utc_network_bluetooth_panu_disconnect_p(void); + +void connection_state_changed_cb_for_nap_p(bool connected, + const char *remote_address, + const char *interface_name, + void *user_data); +void connection_state_changed_cb_for_panu_p(int result, + bool connected, + const char *remote_address, + bt_panu_service_type_e type, + void *user_data); + +void adapter_state_changed_cb_for_pan_p(int result, + bt_adapter_state_e adapter_state, + void *user_data); +gboolean timeout_func(gpointer data); + +struct tet_testlist tet_testlist[] = { + {utc_network_bluetooth_nap_activate_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_nap_set_connection_state_changed_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_nap_unset_connection_state_changed_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_nap_deactivate_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_nap_disconnect_all_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_panu_connect_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_panu_set_connection_state_changed_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_panu_unset_connection_state_changed_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_nap_disconnect_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_panu_disconnect_p, POSITIVE_TC_IDX}, + {NULL, 0}, +}; + + +static void startup(void) +{ + int ret = BT_ERROR_NONE; + int timeout_id = 0; + + /* start of TC */ + mainloop = g_main_loop_new(NULL, FALSE); + + bt_initialize(); + if (bt_adapter_set_state_changed_cb(adapter_state_changed_cb_for_pan_p, "startup") != BT_ERROR_NONE) { + tet_printf("DTS may fail because bt_adapter_set_state_changed_cb() failed"); + } + + tet_printf("bt_adapter_enable() was called."); + + ret = bt_adapter_enable(); + if (ret == BT_ERROR_NONE) { + tet_printf("bt_adapter_enable() succeeded."); + timeout_id = g_timeout_add(60000, timeout_func, mainloop); + g_main_loop_run(mainloop); + g_source_remove(timeout_id); + } else if (ret != BT_ERROR_ALREADY_DONE) { + tet_printf("DTS may fail because bt_adapter_disable() failed"); + } + + if (bt_adapter_unset_state_changed_cb() != BT_ERROR_NONE) { + tet_printf("bt_adapter_set_state_changed_cb() failed."); + } + + tet_printf("TC start"); +} + +static void cleanup(void) +{ + /* end of TC */ + bt_deinitialize(); + tet_printf("TC end."); +} + +gboolean timeout_func(gpointer data) +{ + tet_printf("Callback: Timeout."); + g_main_loop_quit((GMainLoop *) data); + return FALSE; +} + +/** + * @brief Callback funtions +*/ + +void adapter_state_changed_cb_for_pan_p(int result, + bt_adapter_state_e adapter_state, + void *user_data) +{ + +} + +void connection_state_changed_cb_for_nap_p(bool connected, + const char *remote_address, + const char *interface_name, + void *user_data) +{ + +} + +void connection_state_changed_cb_for_panu_p(int result, + bool connected, + const char *remote_address, + bt_panu_service_type_e type, + void *user_data) +{ + +} + +/** + * @brief Positive test case of bt_nap_activate() +*/ +static void utc_network_bluetooth_nap_activate_p(void) +{ + int ret = BT_ERROR_NONE; + ret = bt_nap_activate(); + if (ret != BT_ERROR_ALREADY_DONE) { + dts_check_eq("bt_nap_activate", ret, BT_ERROR_NONE, "bt_nap_activate() failed."); + } else { + dts_check_eq("bt_nap_activate", ret, BT_ERROR_ALREADY_DONE, + "bt_nap_activate() failed."); + } +} + +/** + * @brief Positive test case of bt_nap_deactivate() +*/ +static void utc_network_bluetooth_nap_deactivate_p(void) +{ + int ret = BT_ERROR_NONE; + ret = bt_nap_deactivate(); + dts_check_eq("bt_nap_deactivate", ret, BT_ERROR_NONE, + "bt_nap_deactivate() failed."); + +} + +/** + * @brief Positive test case of bt_nap_disconnect_all() + */ +static void utc_network_bluetooth_nap_disconnect_all_p(void) +{ + int ret = BT_ERROR_NONE; + ret = bt_nap_disconnect_all(); + dts_check_eq("bt_nap_disconnect_all", ret, BT_ERROR_NONE, + "bt_nap_disconnect_all() failed."); +} + +/** + * @brief Positive test case of bt_nap_set_connection_state_changed_cb() + */ +static void utc_network_bluetooth_nap_set_connection_state_changed_p(void) +{ + int ret = BT_ERROR_NONE; + ret = bt_nap_set_connection_state_changed_cb(connection_state_changed_cb_for_nap_p, NULL); + dts_check_eq("bt_nap_set_connection_state_changed_cb", ret, BT_ERROR_NONE, + "bt_nap_set_connection_state_changed_cb() failed."); +} + + +/** + * @brief Positive test case of bt_nap_unset_connection_state_changed_cb() +*/ +static void utc_network_bluetooth_nap_unset_connection_state_changed_p(void) +{ + int ret = BT_ERROR_NONE; + ret = bt_nap_unset_connection_state_changed_cb(); + dts_check_eq("bt_nap_unset_connection_state_changed_cb", ret, BT_ERROR_NONE, + "bt_nap_unset_connection_state_changed_cb() failed."); +} + + +/** + * @brief Positive test case of bt_panu_set_connection_state_changed_cb() +*/ +static void utc_network_bluetooth_panu_set_connection_state_changed_p(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_panu_set_connection_state_changed_cb(connection_state_changed_cb_for_panu_p, NULL); + dts_check_eq("bt_panu_set_connection_state_changed_cb", ret, BT_ERROR_NONE, + "bt_panu_set_connection_state_changed_cb() failed."); + +} + + +/** + * @brief Positive test case of bt_panu_unset_connection_state_changed_cb() +*/ +static void utc_network_bluetooth_panu_unset_connection_state_changed_p(void) +{ + int ret = BT_ERROR_NONE; + ret = bt_panu_unset_connection_state_changed_cb(); + dts_check_eq("bt_panu_unset_connection_state_changed_cb", ret, BT_ERROR_NONE, + "bt_panu_unset_connection_state_changed_cb() failed."); + +} + +/** + * @brief Positive test case of bt_panu_connect() +*/ +static void utc_network_bluetooth_panu_connect_p(void) +{ + int ret = BT_ERROR_NONE; + const char *remote_address = "00:00:00:00:00:00"; + ret = bt_panu_connect(remote_address, BT_PANU_SERVICE_TYPE_NAP); + dts_check_eq("bt_panu_connect", ret, BT_ERROR_NONE, + "bt_panu_connect() failed."); + +} + +/** + * @brief Positive test case of bt_nap_disconnect() +*/ +static void utc_network_bluetooth_nap_disconnect_p(void) +{ + int ret = BT_ERROR_NONE; + const char *remote_address = "00:00:00:00:00:00"; + ret = bt_nap_disconnect(remote_address); + dts_check_eq("bt_nap_disconnect", ret, BT_ERROR_NONE, + "bt_nap_disconnect() failed."); + +} + +/** + * @brief Positive test case of bt_panu_disconnect() +*/ +static void utc_network_bluetooth_panu_disconnect_p(void) +{ + int ret = BT_ERROR_NONE; + const char *remote_address = "00:00:00:00:00:00"; + ret = bt_panu_disconnect(remote_address); + dts_check_eq("bt_panu_disconnect", ret, BT_ERROR_NONE, + "bt_panu_disconnect() failed."); + +} diff --git a/TC/testcase/utc_network_bluetooth_service_search_negative.c b/TC/testcase/utc_network_bluetooth_service_search_negative.c new file mode 100644 index 0000000..ce4dd7d --- /dev/null +++ b/TC/testcase/utc_network_bluetooth_service_search_negative.c @@ -0,0 +1,179 @@ +/* + * 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 +#include +#include +#include +#include + +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; + +static void startup(void); +static void cleanup(void); + +static GMainLoop *mainloop; + +void (*tet_startup) (void) = startup; +void (*tet_cleanup) (void) = cleanup; + +static void utc_network_bluetooth_service_search_set_cb_n(void); +static void utc_network_bluetooth_service_search_unset_cb_n(void); +static void utc_network_bluetooth_service_search_n(void); +static void utc_network_bluetooth_service_search_cancel_n(void); + +void adapter_state_changed_cb_for_service_search_n(int result, + bt_adapter_state_e adapter_state, + void *user_data); +gboolean timeout_func(gpointer data); + +struct tet_testlist tet_testlist[] = { + {utc_network_bluetooth_service_search_set_cb_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_service_search_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_service_search_cancel_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_service_search_unset_cb_n, NEGATIVE_TC_IDX}, + {NULL, 0}, +}; + +static void startup(void) +{ + int ret = BT_ERROR_NONE; + int timeout_id = 0; + + /* start of TC */ + mainloop = g_main_loop_new(NULL, FALSE); + + bt_initialize(); + if (bt_adapter_set_state_changed_cb(adapter_state_changed_cb_for_service_search_n, "startup") != BT_ERROR_NONE) { + tet_printf("DTS may fail because bt_adapter_set_state_changed_cb() failed"); + } + + tet_printf("bt_adapter_disable() was called."); + ret = bt_adapter_disable(); + if (ret == BT_ERROR_NONE) { + tet_printf("bt_adapter_disable() succeeded."); + timeout_id = g_timeout_add(60000, timeout_func, mainloop); + g_main_loop_run(mainloop); + g_source_remove(timeout_id); + } else if (ret == BT_ERROR_NOT_ENABLED) { + tet_printf("Bluetooth adapter is not enabled."); + } else { + tet_printf("DTS may fail because bt_adapter_disable() failed"); + } + + if (bt_adapter_unset_state_changed_cb() != BT_ERROR_NONE) { + tet_printf("bt_adapter_set_state_changed_cb() failed."); + } + + tet_printf("TC start"); +} + + +static void cleanup(void) +{ + /* end of TC */ + bt_deinitialize(); + tet_printf("TC end."); +} + + +gboolean timeout_func(gpointer data) +{ + tet_printf("Callback: Timeout."); + g_main_loop_quit((GMainLoop *) data); + return FALSE; +} + + +/** + * @brief Callback funtions + */ +void adapter_state_changed_cb_for_service_search_n(int result, + bt_adapter_state_e adapter_state, + void *user_data) +{ + tet_printf("Callback: bt_adapter_state_changed_cb was called."); + if (user_data != NULL && !strcmp((char *)user_data, "startup")) { + if (adapter_state == BT_ADAPTER_DISABLED && result == BT_ERROR_NONE) { + tet_printf("Callback: BT was disabled. DTS will be started."); + } else { + tet_printf("Callback: BT was not disabled. DTS will be started but DTS may fail."); + } + + if (mainloop) { + g_main_loop_quit(mainloop); + } + } +} + +/** + * @brief Negative test case of bt_device_set_service_searched_cb() + */ +static void utc_network_bluetooth_service_search_set_cb_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_device_set_service_searched_cb(NULL, NULL); + dts_check_eq("bt_device_set_service_searched_cb", ret, + BT_ERROR_INVALID_PARAMETER, + "BT_ERROR_INVALID_PARAMETER must be returned when callback parameter is NULL"); +} + +/** + * @brief Negative test case of bt_device_unset_service_searched_cb() + */ +static void utc_network_bluetooth_service_search_unset_cb_n(void) +{ + int ret = BT_ERROR_NONE; + + if (bt_deinitialize() != BT_ERROR_NONE) { + dts_fail("bt_device_unset_service_searched_cb", + "bt_deinitialize() failed."); + } + + ret = bt_device_unset_service_searched_cb(); + dts_check_eq("bt_device_unset_service_searched_cb", ret, + BT_ERROR_NOT_INITIALIZED, + "BT_ERROR_NOT_INITIALIZED must be returned when BT service is not initialized."); +} + +/** + * @brief Negative test case of bt_device_start_service_search() + */ +static void utc_network_bluetooth_service_search_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_device_start_service_search(NULL); + dts_check_eq("bt_device_start_service_search", ret, + BT_ERROR_INVALID_PARAMETER, + "BT_ERROR_INVALID_PARAMETER must be returned when parameter is NULL"); +} + +/** + * @brief Negative test case of bt_device_cancel_service_search() + */ +static void utc_network_bluetooth_service_search_cancel_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_device_cancel_service_search(); + dts_check_eq("bt_device_cancel_service_search", ret, BT_ERROR_NOT_ENABLED, + "BT_ERROR_NOT_ENABLED must be returned when BT is not enabled"); +} diff --git a/TC/testcase/utc_network_bluetooth_service_search_positive.c b/TC/testcase/utc_network_bluetooth_service_search_positive.c new file mode 100755 index 0000000..e6219b6 --- /dev/null +++ b/TC/testcase/utc_network_bluetooth_service_search_positive.c @@ -0,0 +1,407 @@ +/* + * 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 +#include +#include +#include +#include + +#define CONFIG_FILE_PATH "/opt/home/capi-network-bluetooth/tetware.conf" +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; + +static void startup(void); +static void cleanup(void); + +void (*tet_startup) (void) = startup; +void (*tet_cleanup) (void) = cleanup; + +char target_name[128] = "dts_test"; +char *target_address; +bool callback_result = false; +bool discovery_result = false; +bool bonding_result = false; +static GMainLoop *mainloop; + +static void utc_network_bluetooth_service_search_set_cb_p(void); +static void utc_network_bluetooth_service_search_p(void); +static void utc_network_bluetooth_service_search_cancel_p(void); +static void utc_network_bluetooth_service_search_unset_cb_p(void); + +gboolean timeout_func(gpointer data); +void adapter_state_changed_cb_for_service_search_p(int result, + bt_adapter_state_e adapter_state, void *user_data); +void device_discovery_state_changed_cb_for_service_search_p(int result, + bt_adapter_device_discovery_state_e discovery_state, + bt_adapter_device_discovery_info_s *discovery_info, void *user_data); +void service_searched_cb_for_service_search_p(int result, + bt_device_sdp_info_s *sdp_info, void *user_data); +void device_bonded_cb_for_service_search_p(int result, + bt_device_info_s *device_info, void *user_data); +void device_unbonded_cb(int result, char *remote_address, void *user_data); + +struct tet_testlist tet_testlist[] = { + {utc_network_bluetooth_service_search_set_cb_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_service_search_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_service_search_cancel_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_service_search_unset_cb_p, POSITIVE_TC_IDX}, + {NULL, 0}, +}; + +int get_value_from_file(void) +{ + FILE *fp; + char *token; + char buf[100]; + + fp = fopen(CONFIG_FILE_PATH, "r"); + if (fp == NULL) { + tet_printf("Default configuration is used\n"); + return -1; + } + while (fgets(buf, sizeof(buf), fp)) { + if (buf[0] == '#' || buf[0] == '\n') + continue; + + token = strrchr(buf, '\n'); + if (token == NULL) { + tet_printf("g_conf is too long\n"); + break; + } + *token = '\0'; + + token = strtok(buf, "="); + if (token == NULL) { + continue; + } + if (strcasecmp(token, "BT_ADDR_MOBILE") == 0) { + token = strtok(NULL, "="); + target_address = strdup(token); + fclose(fp); + return 0; + } + } + fclose(fp); + return -1; +} + +static void startup(void) +{ + bt_error_e ret = BT_ERROR_NONE; + int timeout_id = 0; + + if(get_value_from_file() == -1) { + tet_printf("Failed to read."); + } + + /* start of TC */ + callback_result = false; + discovery_result = false; + mainloop = g_main_loop_new(NULL, FALSE); + + bt_initialize(); + + if (bt_adapter_set_state_changed_cb(adapter_state_changed_cb_for_service_search_p, "startup") != BT_ERROR_NONE) { + tet_printf("bt_adapter_set_state_changed_cb() failed."); + } + + if (bt_adapter_set_device_discovery_state_changed_cb + (device_discovery_state_changed_cb_for_service_search_p, "startup") != BT_ERROR_NONE) { + tet_printf("bt_adapter_set_device_discovery_state_changed_cb() failed."); + } + + ret = bt_adapter_enable(); + if (ret == BT_ERROR_NONE) { + tet_printf("bt_adapter_enable() succeeded."); + timeout_id = g_timeout_add(60000, timeout_func, mainloop); + g_main_loop_run(mainloop); + g_source_remove(timeout_id); + + tet_printf("BT was enabled. Device discovery will be started"); + if (bt_adapter_start_device_discovery() == BT_ERROR_NONE) { + tet_printf("bt_adapter_start_device_discovery() succeeded."); + timeout_id = g_timeout_add(60000, timeout_func, mainloop); + g_main_loop_run(mainloop); + g_source_remove(timeout_id); + } else { + tet_printf("bt_adapter_start_device_discovery() failed."); + } + } else if (ret == BT_ERROR_ALREADY_DONE) { + tet_printf("BT was already enabled. Device discovery will be started"); + if (bt_adapter_start_device_discovery() == BT_ERROR_NONE) { + tet_printf("bt_adapter_start_device_discovery() succeeded."); + timeout_id = g_timeout_add(60000, timeout_func, mainloop); + g_main_loop_run(mainloop); + g_source_remove(timeout_id); + } else { + tet_printf("bt_adapter_start_device_discovery() failed."); + } + } else { + tet_printf("DTS may fail because bt_adapter_enable() failed."); + } + + if (bt_adapter_unset_state_changed_cb() != BT_ERROR_NONE) { + tet_printf("bt_adapter_unset_state_changed_cb() failed."); + } + + if (bt_adapter_unset_device_discovery_state_changed_cb() != BT_ERROR_NONE) { + tet_printf("bt_adapter_unset_device_discovery_state_changed_cb() failed."); + } + + tet_printf("TC start."); +} + + +static void cleanup(void) +{ + /* end of TC */ + int timeout_id = 0; + + /* Destroy a bond */ + bt_device_set_bond_destroyed_cb(device_unbonded_cb, NULL); + if (bt_device_destroy_bond(target_address) == BT_ERROR_NONE) { + timeout_id = g_timeout_add(60000, timeout_func, mainloop); + g_main_loop_run(mainloop); + g_source_remove(timeout_id); + } + + bt_deinitialize(); + tet_printf("TC end."); +} + + +gboolean timeout_func(gpointer data) +{ + tet_printf("[%s] Callback: Timeout.", __FUNCTION__); + g_main_loop_quit((GMainLoop *) data); + return FALSE; +} + + +/** + * @brief Callback funtions + */ +void device_unbonded_cb(int result, char *remote_address, void *user_data) +{ + tet_printf("Callback: bt_device_bond_destroyed_cb() was called."); + + if (mainloop) { + g_main_loop_quit(mainloop); + } + +} + +void adapter_state_changed_cb_for_service_search_p(int result, + bt_adapter_state_e adapter_state, void *user_data) +{ + tet_printf("Callback: bt_adapter_state_changed_cb() was called"); + if (user_data != NULL && !strcmp((char *)user_data, "startup")) { + if (adapter_state == BT_ADAPTER_ENABLED && result == BT_ERROR_NONE) { + tet_printf("Callback: BT was enabled."); + } else { + tet_printf("Callback: BT was not enabled. DTS will be started but DTS may fail."); + } + + if (mainloop) { + g_main_loop_quit(mainloop); + } + } +} + +void device_discovery_state_changed_cb_for_service_search_p(int result, + bt_adapter_device_discovery_state_e discovery_state, + bt_adapter_device_discovery_info_s *discovery_info, void *user_data) +{ + tet_printf("Callback: bt_adapter_device_discovery_state_changed_cb() was called"); + if (user_data != NULL && !strcmp((char *)user_data, "startup")) { + if (discovery_state == BT_ADAPTER_DEVICE_DISCOVERY_FINISHED) { + tet_printf("Callback: Device discovery finished. DTS will be started."); + if (mainloop) { + g_main_loop_quit(mainloop); + } + } else if (discovery_state == BT_ADAPTER_DEVICE_DISCOVERY_FOUND) { + tet_printf("Callback: Devices were founded (%s)", + discovery_info->remote_name); + if (discovery_info->remote_name != NULL && !strcmp(discovery_info->remote_name, target_name)) { + discovery_result = true; + tet_printf("Callback: dts_test device was found."); + strncpy(target_address, discovery_info->remote_address, 18); + tet_printf("Callback: device address: %s", discovery_info->remote_address); + if (bt_adapter_stop_device_discovery() == BT_ERROR_NONE) { + tet_printf("Callback: Device discovery will be stopped"); + } + } + } + } +} + +void service_searched_cb_for_service_search_p(int result, + bt_device_sdp_info_s *sdp_info, + void *user_data) +{ + int i = 0; + + tet_printf("Callback: bt_device_service_searched_cb() was called."); + if (result == BT_ERROR_NONE) { + if (sdp_info != NULL && !strcmp(sdp_info->remote_address, target_address)) { + tet_printf("Callback: Service search succeeded."); + tet_printf("Callback: Service count : %d", sdp_info->service_count); + for (i = 0; i < sdp_info->service_count; i++) { + tet_printf("Callback: uuid[%d] - %s", i + 1, sdp_info->service_uuid[i]); + } + + callback_result = true; + } + } else if (result == BT_ERROR_CANCELLED) { + if (sdp_info != NULL && !strcmp(sdp_info->remote_address, target_address)) { + tet_printf("Callback: Calcellation of service search succeeded."); + callback_result = true; + } + } else { + tet_printf("Callback: Failed."); + } + + if (mainloop) { + g_main_loop_quit(mainloop); + } +} + +void device_bonded_cb_for_service_search_p(int result, + bt_device_info_s *device_info, void *user_data) +{ + if (user_data != NULL && !strcmp((char *)user_data, "startup")) { + if (device_info->remote_address != NULL && !strcmp(device_info->remote_address, target_address)) { + if (result == BT_ERROR_NONE) { + tet_printf("Callback: Bonding succeeded"); + bonding_result = true; + } else { + tet_printf("Callback: Bonding failed"); + } + } + } + + if (mainloop) { + g_main_loop_quit(mainloop); + } +} + +/** + * @brief Positive test case of bt_device_set_service_searched_cb() + */ +static void utc_network_bluetooth_service_search_set_cb_p(void) +{ + int ret = BT_ERROR_NONE; + int timeout_id = 0; + + ret = bt_device_set_service_searched_cb(service_searched_cb_for_service_search_p, NULL); + if (ret == BT_ERROR_NONE) { + if (bt_device_set_bond_created_cb(device_bonded_cb_for_service_search_p, "startup") != BT_ERROR_NONE) { + tet_printf("bt_device_set_bond_created_cb() failed."); + } + + if (discovery_result == true && bt_device_create_bond(target_address) == BT_ERROR_NONE) { + tet_printf("bt_device_create_bond() succeeded."); + timeout_id = g_timeout_add(60000, timeout_func, mainloop); + g_main_loop_run(mainloop); + g_source_remove(timeout_id); + } else { + tet_printf("bt_device_create_bond() failed."); + } + } + + dts_check_eq("bt_device_set_service_searched_cb", ret, BT_ERROR_NONE, + "bt_device_set_service_searched_cb() failed."); +} + +/** + * @brief Positive test case of bt_device_start_service_search() + */ +static void utc_network_bluetooth_service_search_p(void) +{ + int timeout_id = 0; + int ret = BT_ERROR_NONE; + + if (discovery_result != true) { + tet_printf("bt_device_start_service_search failed."); + } + + callback_result = false; + ret = bt_device_start_service_search(target_address); + if (ret == BT_ERROR_NONE) { + tet_printf("bt_device_start_service_search() succeeded."); + tet_printf("service_searched_cb_for_service_search_p() will be called."); + timeout_id = g_timeout_add(60000, timeout_func, mainloop); + g_main_loop_run(mainloop); + g_source_remove(timeout_id); + dts_check_eq("bt_device_start_service_search", ret, BT_ERROR_NONE, + "bt_device_start_service_search() failed."); + } else { + dts_fail("bt_device_start_service_search", + "bt_device_start_service_search() failed."); + } +} + +/** + * @brief Positive test case of bt_device_cancel_service_search() + */ +static void utc_network_bluetooth_service_search_cancel_p(void) +{ + int timeout_id = 0; + int ret = BT_ERROR_NONE; + + if (discovery_result != true) { + tet_printf("t_device_cancel_service_search failed."); + } + + callback_result = false; + if (bt_device_start_service_search(target_address) != BT_ERROR_NONE) { + tet_printf("t_device_start_service_search failed."); + + } else { + tet_printf("bt_device_cancel_service_search", + "bt_device_start_service_search() succeeded."); + } + + ret = bt_device_cancel_service_search(); + if (ret == BT_ERROR_NONE) { + tet_printf("bt_device_cancel_service_search() succeeded."); + tet_printf("service_searched_cb_for_service_search_p() will be called."); + timeout_id = g_timeout_add(60000, timeout_func, mainloop); + g_main_loop_run(mainloop); + g_source_remove(timeout_id); + dts_check_eq("bt_device_cancel_service_search", ret, BT_ERROR_NONE, + "bt_device_cancel_service_search() failed."); + + } else { + dts_fail("bt_device_cancel_service_search", + "bt_device_cancel_service_search() failed."); + } +} + +/** + * @brief Positive test case of bt_device_unset_service_searched_cb() + */ +static void utc_network_bluetooth_service_search_unset_cb_p(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_device_unset_service_searched_cb(); + dts_check_eq("bt_device_unset_service_searched_cb", ret, BT_ERROR_NONE, + "bt_device_set_service_searched_cb() failed."); +} diff --git a/TC/testcase/utc_network_bluetooth_socket_negative.c b/TC/testcase/utc_network_bluetooth_socket_negative.c new file mode 100644 index 0000000..dea118f --- /dev/null +++ b/TC/testcase/utc_network_bluetooth_socket_negative.c @@ -0,0 +1,268 @@ +/* + * 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 +#include +#include +#include +#include + +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; + +static void startup(void); +static void cleanup(void); + +static GMainLoop *mainloop; + +void (*tet_startup) (void) = startup; +void (*tet_cleanup) (void) = cleanup; + +static void utc_network_bluetooth_socket_set_data_received_cb_n(void); +static void utc_network_bluetooth_socket_set_connection_state_changed_cb_n(void); +static void utc_network_bluetooth_socket_unset_data_received_cb_n(void); +static void utc_network_bluetooth_socket_unset_connection_state_changed_cb_n(void); +static void utc_network_bluetooth_socket_create_rfcomm_n(void); +static void utc_network_bluetooth_socket_destroy_rfcomm_n(void); +static void utc_network_bluetooth_socket_listen_and_accept_rfcomm_n(void); +static void utc_network_bluetooth_socket_connect_rfcomm_n(void); +static void utc_network_bluetooth_socket_disconnect_rfcomm_n(void); +static void utc_network_bluetooth_socket_send_data_n(void); + +void adapter_state_changed_cb_for_device_negative(int result, + bt_adapter_state_e adapter_state, void *user_data); +gboolean timeout_func(gpointer data); + +struct tet_testlist tet_testlist[] = { + {utc_network_bluetooth_socket_create_rfcomm_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_socket_set_connection_state_changed_cb_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_socket_listen_and_accept_rfcomm_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_socket_set_data_received_cb_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_socket_connect_rfcomm_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_socket_send_data_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_socket_disconnect_rfcomm_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_socket_destroy_rfcomm_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_socket_unset_data_received_cb_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_socket_unset_connection_state_changed_cb_n, NEGATIVE_TC_IDX}, + {NULL, 0}, +}; + +static void startup(void) +{ + int ret = BT_ERROR_NONE; + int timeout_id = 0; + + /* start of TC */ + mainloop = g_main_loop_new(NULL, FALSE); + + bt_initialize(); + if (bt_adapter_set_state_changed_cb(adapter_state_changed_cb_for_device_negative, "startup") != BT_ERROR_NONE) { + tet_printf("DTS may fail because bt_adapter_set_state_changed_cb() failed"); + } + + tet_printf("bt_adapter_disable() was called."); + ret = bt_adapter_disable(); + if (ret == BT_ERROR_NONE) { + tet_printf("bt_adapter_disable() succeeded."); + timeout_id = g_timeout_add(60000, timeout_func, mainloop); + g_main_loop_run(mainloop); + g_source_remove(timeout_id); + } else if (ret == BT_ERROR_NOT_ENABLED) { + tet_printf("Bluetooth adapter is not enabled."); + } else { + tet_printf("DTS may fail because bt_adapter_disable() failed"); + } + + if (bt_adapter_unset_state_changed_cb() != BT_ERROR_NONE) { + tet_printf("bt_adapter_set_state_changed_cb() failed."); + } + + tet_printf("TC start"); +} + +static void cleanup(void) +{ + /* end of TC */ + bt_deinitialize(); + tet_printf("TC end."); +} + +gboolean timeout_func(gpointer data) +{ + tet_printf("Callback: Timeout."); + g_main_loop_quit((GMainLoop *) data); + return FALSE; +} + +/** + * @brief Callback funtions + */ +void adapter_state_changed_cb_for_device_negative(int result, + bt_adapter_state_e adapter_state, + void *user_data) +{ + tet_printf("Callback: bt_adapter_state_changed_cb was called."); + if (user_data != NULL && !strcmp((char *)user_data, "startup")) { + if (adapter_state == BT_ADAPTER_DISABLED && result == BT_ERROR_NONE) { + tet_printf("Callback: BT was disabled. DTS will be started."); + } else { + tet_printf("Callback: BT was not disabled. DTS will be started but DTS may fail."); + } + + if (mainloop) { + g_main_loop_quit(mainloop); + } + } +} + + + +/** + * @brief Negative test case of bt_socket_set_data_received_cb() + */ +static void utc_network_bluetooth_socket_set_data_received_cb_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_socket_set_data_received_cb(NULL, NULL); + dts_check_eq("bt_socket_set_data_received_cb", ret, + BT_ERROR_INVALID_PARAMETER, + "BT_ERROR_INVALID_PARAMETER must be returned when callback parameter is NULL"); +} + +/** + * @brief Negative test case of bt_socket_set_connection_state_changed_cb() + */ +static void utc_network_bluetooth_socket_set_connection_state_changed_cb_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_socket_set_connection_state_changed_cb(NULL, NULL); + dts_check_eq("bt_socket_set_connection_state_changed_cb", ret, + BT_ERROR_INVALID_PARAMETER, + "BT_ERROR_INVALID_PARAMETER must be returned when callback parameter is NULL"); +} + +/** + * @brief Negative test case of bt_socket_unset_data_received_cb() + */ +static void utc_network_bluetooth_socket_unset_data_received_cb_n(void) +{ + int ret = BT_ERROR_NONE; + + if (bt_deinitialize() != BT_ERROR_NONE) { + dts_fail("bt_socket_unset_data_received_cb", + "bt_deinitialize() failed."); + } + + ret = bt_socket_unset_data_received_cb(); + dts_check_eq("bt_socket_unset_data_received_cb", ret, + BT_ERROR_NOT_INITIALIZED, + "BT_ERROR_NOT_INITIALIZED must be returned when BT service is not initialized."); +} + +/** + * @brief Negative test case of bt_socket_unset_connection_state_changed_cb() + */ +static void utc_network_bluetooth_socket_unset_connection_state_changed_cb_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_socket_unset_connection_state_changed_cb(); + dts_check_eq("bt_socket_unset_connection_state_changed_cb", ret, + BT_ERROR_NOT_INITIALIZED, + "BT_ERROR_NOT_INITIALIZED must be returned when BT service is not initialized."); +} + +/** + * @brief Negative test case of bt_socket_create_rfcomm() + */ +static void utc_network_bluetooth_socket_create_rfcomm_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_socket_create_rfcomm(NULL, NULL); + dts_check_eq("bt_socket_create_rfcomm", ret, BT_ERROR_INVALID_PARAMETER, + "BT_ERROR_INVALID_PARAMETER must be returned when port_uuid parameter is NULL"); +} + +/** + * @brief Negative test case of bt_socket_destroy_rfcomm() + */ +static void utc_network_bluetooth_socket_destroy_rfcomm_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_socket_destroy_rfcomm(NULL); + dts_check_eq("bt_socket_listen_and_accept_rfcomm", ret, + BT_ERROR_NOT_ENABLED, + "BT_ERROR_INVALID_PARAMETER must be returned when socket_fd is below 0"); +} + + +/** + * @brief Negative test case of bt_socket_listen_and_accept_rfcomm() + */ +static void utc_network_bluetooth_socket_listen_and_accept_rfcomm_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_socket_listen_and_accept_rfcomm(1, 1); + dts_check_eq("bt_socket_listen_and_accept_rfcomm", ret, + BT_ERROR_NOT_ENABLED, + "BT_ERROR_NOT_ENABLED must be returned when BT is not enabled"); +} + +/** + * @brief Negative test case of bt_socket_connect_rfcomm() + */ +static void utc_network_bluetooth_socket_connect_rfcomm_n(void) +{ + int ret = BT_ERROR_NONE; + char *address = "00:02:79:AC:7D:FD"; + char *uuid = ""; + + ret = bt_socket_connect_rfcomm(address, uuid); + dts_check_eq("bt_socket_connect_rfcomm", ret, BT_ERROR_NOT_ENABLED, + "BT_ERROR_NOT_ENABLED must be returned when BT is not enabled"); +} + +/** + * @brief Negative test case of bt_socket_disconnect_rfcomm() + */ +static void utc_network_bluetooth_socket_disconnect_rfcomm_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_socket_disconnect_rfcomm(-1); + dts_check_eq("bt_socket_disconnect_rfcomm", ret, BT_ERROR_NOT_ENABLED, + "BT_ERROR_NOT_ENABLED must be returned when BT is not enabled"); +} + +/** + * @brief Negative test case of bt_socket_send_data() + */ +static void utc_network_bluetooth_socket_send_data_n(void) +{ + int ret = BT_ERROR_NONE; + char *data = "dts_test"; + + ret = bt_socket_send_data(1, data, sizeof(data)); + dts_check_eq("bt_socket_send_data", ret, BT_ERROR_NOT_ENABLED, + "BT_ERROR_NOT_ENABLED must be returned when BT is not enabled"); +} diff --git a/TC/testcase/utc_network_bluetooth_socket_positive.c b/TC/testcase/utc_network_bluetooth_socket_positive.c new file mode 100755 index 0000000..7c71338 --- /dev/null +++ b/TC/testcase/utc_network_bluetooth_socket_positive.c @@ -0,0 +1,478 @@ +/* + * 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 +#include +#include +#include +#include + +#define CONFIG_FILE_PATH "/opt/home/capi-network-bluetooth/tetware.conf" + +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; + +static void startup(void); +static void cleanup(void); + +void (*tet_startup) (void) = startup; +void (*tet_cleanup) (void) = cleanup; + +const char target_name[128] = "dts_test"; +const char *rfcomm_test_uuid_spp = "00001101-0000-1000-8000-00805F9B34FB"; +char *target_address; +int socket_fd = 0; +bool callback_result = false; +bool discovery_result = false; +bool bonding_result = false; +bool is_connecting = false; +static GMainLoop *mainloop; + +static void utc_network_bluetooth_socket_set_data_received_cb_p(void); +static void utc_network_bluetooth_socket_set_connection_state_changed_cb_p(void); + +static void utc_network_bluetooth_socket_create_rfcomm_p(void); +static void utc_network_bluetooth_socket_destroy_rfcomm_p(void); +static void utc_network_bluetooth_socket_listen_and_accept_rfcomm_p(void); +static void utc_network_bluetooth_socket_connect_rfcomm_p(void); +static void utc_network_bluetooth_socket_disconnect_rfcomm_p(void); +static void utc_network_bluetooth_socket_send_data_p(void); +static void utc_network_bluetooth_socket_unset_data_received_cb_p(void); +static void utc_network_bluetooth_socket_unset_connection_state_changed_cb_p(void); + +gboolean timeout_func(gpointer data); +void adapter_state_changed_cb_for_socket_p(int result, + bt_adapter_state_e adapter_state, void *user_data); +void device_discovery_state_changed_cb_for_socket_p(int result, + bt_adapter_device_discovery_state_e discovery_state, + bt_adapter_device_discovery_info_s *discovery_info, void *user_data); +void device_bonded_cb_for_socket_p(int result, bt_device_info_s *device_info, + void *user_data); +void socket_data_received_cb_for_socket_p(bt_socket_received_data_s *data, + void *user_data); +void socket_connection_state_changed_cb_for_socket_p(int result, + bt_socket_connection_state_e connection_state, + bt_socket_connection_s *connection, void *user_data); +void device_unbonded_cb(int result, char *remote_address, void *user_data); + +struct tet_testlist tet_testlist[] = { + {utc_network_bluetooth_socket_create_rfcomm_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_socket_set_connection_state_changed_cb_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_socket_listen_and_accept_rfcomm_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_socket_set_data_received_cb_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_socket_connect_rfcomm_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_socket_send_data_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_socket_disconnect_rfcomm_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_socket_destroy_rfcomm_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_socket_unset_data_received_cb_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_socket_unset_connection_state_changed_cb_p, POSITIVE_TC_IDX}, + {NULL, 0}, +}; + +int get_value_from_file(void) +{ + FILE *fp; + char *token; + char buf[100]; + + fp = fopen(CONFIG_FILE_PATH, "r"); + if (fp == NULL) { + tet_printf("Default configuration is used\n"); + return -1; + } + while (fgets(buf, sizeof(buf), fp)) { + if (buf[0] == '#' || buf[0] == '\n') + continue; + + token = strrchr(buf, '\n'); + if (token == NULL) { + tet_printf("g_conf is too long\n"); + break; + } + *token = '\0'; + + token = strtok(buf, "="); + if (token == NULL) { + continue; + } + if (strcasecmp(token, "BT_ADDR_MOBILE") == 0) { + token = strtok(NULL, "="); + target_address = strdup(token); + fclose(fp); + return 0; + } + } + fclose(fp); + return -1; +} + +static void startup(void) +{ + bt_error_e ret = BT_ERROR_NONE; + int timeout_id = 0; + + if(get_value_from_file() == -1) { + tet_printf("Failed to read."); + } + + /* start of TC */ + tet_printf("TC start."); + callback_result = false; + discovery_result = false; + bonding_result = false; + mainloop = g_main_loop_new(NULL, FALSE); + + bt_initialize(); + + if (bt_adapter_set_state_changed_cb(adapter_state_changed_cb_for_socket_p, "startup") != BT_ERROR_NONE) { + tet_printf("bt_adapter_set_state_changed_cb() failed."); + } + + if (bt_adapter_set_device_discovery_state_changed_cb(device_discovery_state_changed_cb_for_socket_p, "startup") != BT_ERROR_NONE) { + tet_printf("bt_adapter_set_device_discovery_state_changed_cb() failed."); + } + + if (bt_device_set_bond_created_cb(device_bonded_cb_for_socket_p, "startup") != BT_ERROR_NONE) { + tet_printf("bt_device_set_bond_created_cb() failed."); + } + + ret = bt_adapter_enable(); + if (ret == BT_ERROR_NONE) { + tet_printf("bt_adapter_enable() succeeded."); + timeout_id = g_timeout_add(60000, timeout_func, mainloop); + g_main_loop_run(mainloop); + g_source_remove(timeout_id); + + tet_printf("BT was enabled. Device discovery will be started"); + if (bt_adapter_start_device_discovery() == BT_ERROR_NONE) { + tet_printf("bt_adapter_start_device_discovery() succeeded."); + timeout_id = g_timeout_add(60000, timeout_func, mainloop); + g_main_loop_run(mainloop); + g_source_remove(timeout_id); + } else { + tet_printf("bt_adapter_start_device_discovery() failed."); + } + } else if (ret == BT_ERROR_ALREADY_DONE) { + tet_printf("BT was already enabled. Device discovery will be started"); + if (bt_adapter_start_device_discovery() == BT_ERROR_NONE) { + tet_printf("bt_adapter_start_device_discovery() succeeded."); + timeout_id = g_timeout_add(60000, timeout_func, mainloop); + g_main_loop_run(mainloop); + g_source_remove(timeout_id); + } else { + tet_printf("bt_adapter_start_device_discovery() failed."); + } + } else { + tet_printf("DTS may fail because bt_adapter_enable() failed."); + } + + if (discovery_result == true && bt_device_create_bond(target_address) == BT_ERROR_NONE) { + tet_printf("bt_device_create_bond() succeeded."); + timeout_id = g_timeout_add(60000, timeout_func, mainloop); + g_main_loop_run(mainloop); + g_source_remove(timeout_id); + } else { + tet_printf("bt_device_create_bond() failed."); + } + + if (bt_adapter_unset_state_changed_cb() != BT_ERROR_NONE) { + tet_printf("bt_adapter_unset_state_changed_cb() failed."); + } + + if (bt_adapter_unset_device_discovery_state_changed_cb() != BT_ERROR_NONE) { + tet_printf("bt_adapter_unset_device_discovery_state_changed_cb() failed."); + } + + if (bt_device_unset_bond_created_cb() != BT_ERROR_NONE) { + tet_printf("bt_device_unset_bond_created_cb() failed."); + } + +} + +static void cleanup(void) +{ + /* end of TC */ + int timeout_id = 0; + + /* Destroy a bond */ + bt_device_set_bond_destroyed_cb(device_unbonded_cb, NULL); + if (bt_device_destroy_bond(target_address) == BT_ERROR_NONE) { + timeout_id = g_timeout_add(60000, timeout_func, mainloop); + g_main_loop_run(mainloop); + g_source_remove(timeout_id); + } + + bt_deinitialize(); + tet_printf("TC end."); +} + +gboolean timeout_func(gpointer data) +{ + tet_printf("[%s] Callback: Timeout.", __FUNCTION__); + g_main_loop_quit((GMainLoop *) data); + return FALSE; +} + +/** + * @brief Callback funtions + */ +void device_unbonded_cb(int result, char *remote_address, void *user_data) +{ + tet_printf("Callback: bt_device_bond_destroyed_cb() was called."); + + if (mainloop) { + g_main_loop_quit(mainloop); + } + +} + +void adapter_state_changed_cb_for_socket_p(int result, + bt_adapter_state_e adapter_state, void *user_data) +{ + if (user_data != NULL && !strcmp((char *)user_data, "startup")) { + if (adapter_state == BT_ADAPTER_ENABLED && result == BT_ERROR_NONE) { + tet_printf("Callback: BT was enabled."); + bt_adapter_start_device_discovery(); + } else { + tet_printf("Callback: BT was not enabled. DTS will be started but DTS may fail."); + if (mainloop) { + g_main_loop_quit(mainloop); + } + } + } +} + +void device_discovery_state_changed_cb_for_socket_p(int result, + bt_adapter_device_discovery_state_e discovery_state, + bt_adapter_device_discovery_info_s *discovery_info, void *user_data) +{ + tet_printf("Callback: bt_adapter_device_discovery_state_changed_cb() was called"); + if (user_data != NULL && !strcmp((char *)user_data, "startup")) { + if (discovery_state == BT_ADAPTER_DEVICE_DISCOVERY_FINISHED) { + tet_printf("Callback: Device discovery finished. DTS will be started."); + if (mainloop) { + g_main_loop_quit(mainloop); + } + } else if (discovery_state == BT_ADAPTER_DEVICE_DISCOVERY_FOUND) { + tet_printf("Callback: Devices were founded (%s)", discovery_info->remote_name); + if (discovery_info->remote_name != NULL && !strcmp(discovery_info->remote_name, target_name)) { + discovery_result = true; + tet_printf("Callback: dts_test device was found."); + strncpy(target_address, discovery_info->remote_address, 18); + tet_printf("Callback: device address: %s", discovery_info->remote_address); + if (bt_adapter_stop_device_discovery() == BT_ERROR_NONE) { + tet_printf("Callback: Device discovery will be stopped"); + } + } + } + } +} + +void device_bonded_cb_for_socket_p(int result, bt_device_info_s *device_info, void *user_data) +{ + if ((user_data != NULL) && !strcmp((char *)user_data, "startup")) { + if ((device_info->remote_address != NULL) && + !strcmp(device_info->remote_address, target_address)) { + if (result == BT_ERROR_NONE) { + tet_printf("Callback: Bonding succeeded"); + bonding_result = true; + } else { + tet_printf("Callback: Bonding failed"); + } + } + } + + if (mainloop) { + g_main_loop_quit(mainloop); + } +} + +void socket_data_received_cb_for_socket_p(bt_socket_received_data_s *data, + void *user_data) +{ +} + +void socket_connection_state_changed_cb_for_socket_p(int result, + bt_socket_connection_state_e connection_state, + bt_socket_connection_s *connection, void *user_data) +{ + tet_printf("Callback: bt_socket_connection_state_changed_cb() was called"); + if (connection_state == BT_SOCKET_CONNECTED) + tet_printf("Callback: Connected"); + else + tet_printf("Callback: Disconnected"); + + if (connection_state == BT_SOCKET_CONNECTED) { + tet_printf("Callback: [BT_SOCKET_CONNECTED] result = %d", result); + if (result == BT_ERROR_NONE && is_connecting == true) { + callback_result = true; + socket_fd = connection->socket_fd; + tet_printf("Callback: socket_fd = %d", socket_fd); + + if (mainloop) { + g_main_loop_quit(mainloop); + } + } + } else if (connection_state == BT_SOCKET_DISCONNECTED) { + tet_printf("Callback: [BT_SOCKET_DISCONNECTED] result = %d", result); + if (result == BT_ERROR_NONE && is_connecting == false) { + callback_result = true; + socket_fd = connection->socket_fd; + tet_printf("Callback: socket_fd = %d", socket_fd); + + if (mainloop) { + g_main_loop_quit(mainloop); + } + } + } +} + +/** + * @brief Positive test case of bt_socket_set_data_received_cb() + */ +static void utc_network_bluetooth_socket_set_data_received_cb_p(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_socket_set_data_received_cb(socket_data_received_cb_for_socket_p, NULL); + dts_check_eq("bt_socket_set_data_received_cb", ret, BT_ERROR_NONE, + "bt_socket_set_data_received_cb() failed."); +} + +/** + * @brief Positive test case of bt_socket_set_connection_state_changed_cb() + */ +static void utc_network_bluetooth_socket_set_connection_state_changed_cb_p(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_socket_set_connection_state_changed_cb(socket_connection_state_changed_cb_for_socket_p, NULL); + dts_check_eq("bt_socket_set_connection_state_changed_cb", ret, + BT_ERROR_NONE, + "bt_socket_set_connection_state_changed_cb() failed."); +} + +/** + * @brief Positive test case of bt_socket_create_rfcomm() + */ +static void utc_network_bluetooth_socket_create_rfcomm_p(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_socket_create_rfcomm(rfcomm_test_uuid_spp, &socket_fd); + dts_check_eq("bt_socket_create_rfcomm", ret, BT_ERROR_NONE, + "bt_socket_create_rfcomm() failed."); +} + +/** + * @brief Positive test case of bt_socket_listen_and_accept_rfcomm() + */ +static void utc_network_bluetooth_socket_listen_and_accept_rfcomm_p(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_socket_listen_and_accept_rfcomm(socket_fd, 1); + dts_check_eq("bt_socket_listen_and_accept_rfcomm", ret, BT_ERROR_NONE, + "bt_socket_listen_and_accept_rfcomm() failed."); +} + +/** + * @brief Positive test case of bt_socket_destroy_rfcomm() + */ +static void utc_network_bluetooth_socket_destroy_rfcomm_p(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_socket_destroy_rfcomm(socket_fd); + dts_check_eq("bt_socket_destroy_rfcomm", ret, BT_ERROR_NONE, + "bt_socket_destroy_rfcomm() failed."); +} + +/** + * @brief Positive test case of bt_socket_connect_rfcomm() + */ +static void utc_network_bluetooth_socket_connect_rfcomm_p(void) +{ + int ret = BT_ERROR_NONE; + int timeout_id = 0; + + is_connecting = true; + callback_result = false; + ret = bt_socket_connect_rfcomm(target_address, rfcomm_test_uuid_spp); + if (ret == BT_ERROR_NONE) { + dts_check_eq("bt_socket_connect_rfcomm", ret, BT_ERROR_NONE, + "bt_socket_connect_rfcomm() failed."); + tet_printf("bt_socket_connect_rfcomm() succeeded."); + timeout_id = g_timeout_add(60000, timeout_func, mainloop); + g_main_loop_run(mainloop); + g_source_remove(timeout_id); + } else { + dts_fail("bt_socket_connect_rfcomm", + "bt_socket_connect_rfcomm() failed"); + } +} + +/** + * @brief Positive test case of bt_socket_disconnect_rfcomm() + */ +static void utc_network_bluetooth_socket_disconnect_rfcomm_p(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_socket_disconnect_rfcomm(socket_fd); + dts_check_eq("bt_socket_disconnect_rfcomm", ret, BT_ERROR_NONE, + "bt_socket_disconnect_rfcomm() failed."); +} + +/** + * @brief Positive test case of bt_socket_send_data() + */ +static void utc_network_bluetooth_socket_send_data_p(void) +{ + int ret = BT_ERROR_NONE; + char *dts_test = "dts_test"; + int socket_fd = 1; + ret = bt_socket_send_data(socket_fd, "dts_test", sizeof(dts_test)); + dts_check_eq("bt_socket_send_data", ret, BT_ERROR_NONE, + "bt_socket_send_data() failed."); +} + +/** + * @brief Positive test case of bt_socket_unset_data_received_cb() + */ +static void utc_network_bluetooth_socket_unset_data_received_cb_p(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_socket_unset_data_received_cb(); + dts_check_eq("bt_socket_unset_data_received_cb", ret, BT_ERROR_NONE, + "bt_socket_unset_data_received_cb() failed."); +} + +/** + * @brief Positive test case of bt_socket_unset_connection_state_changed_cb() + */ +static void utc_network_bluetooth_socket_unset_connection_state_changed_cb_p(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_socket_unset_connection_state_changed_cb(); + dts_check_eq("bt_socket_unset_connection_state_changed_cb", ret, + BT_ERROR_NONE, + "bt_socket_unset_connection_state_changed_cb() failed."); +} diff --git a/TC/tet_scen b/TC/tet_scen new file mode 100755 index 0000000..03f029a --- /dev/null +++ b/TC/tet_scen @@ -0,0 +1,7 @@ +all + ^TEST +##### Scenarios for TEST ##### + +# Test scenario +TEST + :include:/testcase/tslist diff --git a/TC/tetbuild.cfg b/TC/tetbuild.cfg new file mode 100644 index 0000000..f7eda55 --- /dev/null +++ b/TC/tetbuild.cfg @@ -0,0 +1,5 @@ +TET_OUTPUT_CAPTURE=True # capture option for build operation checking +TET_BUILD_TOOL=make # build with using make command +TET_BUILD_FILE=-f Makefile # execution file (Makefile) for build +TET_API_COMPLIANT=True # use TET API in Test Case ? +TET_PASS_TC_NAME=True # report passed TC name in Journal file? diff --git a/TC/tetclean.cfg b/TC/tetclean.cfg new file mode 100644 index 0000000..02d7030 --- /dev/null +++ b/TC/tetclean.cfg @@ -0,0 +1,5 @@ +TET_OUTPUT_CAPTURE=True # capture option +TET_CLEAN_TOOL= make clean # clean tool +TET_CLEAN_FILE= Makefile # file for clean +TET_API_COMPLIANT=True # TET API useage +TET_PASS_TC_NAME=True # showing name , passed TC diff --git a/TC/tetexec.cfg b/TC/tetexec.cfg new file mode 100644 index 0000000..ef3e452 --- /dev/null +++ b/TC/tetexec.cfg @@ -0,0 +1,5 @@ +TET_OUTPUT_CAPTURE=True # capturing execution or not +TET_EXEC_TOOL= # ex) exec : execution tool set up/ Optional +TET_EXEC_FILE= # ex) exectool : execution file/ Optional +TET_API_COMPLIANT=True # Test case or Tool usesTET API? +TET_PASS_TC_NAME=True # showing Passed TC name ? diff --git a/TC/tetware.conf b/TC/tetware.conf new file mode 100644 index 0000000..4d0c237 --- /dev/null +++ b/TC/tetware.conf @@ -0,0 +1,5 @@ +BT_ADDR_HEADSET=00:21:19:14:29:52 +BT_ADDR_MOBILE=E4:32:CB:41:1D:7A +BT_ADDR_HDP=00:22:58:07:77:BB +BT_ADDR_LE=E4:32:CB:41:1F:A6 + diff --git a/bluetooth-gatt-test.manifest b/bluetooth-gatt-test.manifest new file mode 100644 index 0000000..05a98ee --- /dev/null +++ b/bluetooth-gatt-test.manifest @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/bluetooth-infinite-spp-test-client.manifest b/bluetooth-infinite-spp-test-client.manifest new file mode 100644 index 0000000..f937326 --- /dev/null +++ b/bluetooth-infinite-spp-test-client.manifest @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/bluetooth-infinite-spp-test-server.manifest b/bluetooth-infinite-spp-test-server.manifest new file mode 100644 index 0000000..fb64ada --- /dev/null +++ b/bluetooth-infinite-spp-test-server.manifest @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/bluetooth-test.manifest b/bluetooth-test.manifest new file mode 100644 index 0000000..0c26ff0 --- /dev/null +++ b/bluetooth-test.manifest @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/bluetooth.manifest b/bluetooth.manifest new file mode 100644 index 0000000..75b0fa5 --- /dev/null +++ b/bluetooth.manifest @@ -0,0 +1,5 @@ + + + + + diff --git a/debian/README b/debian/README deleted file mode 100644 index e69de29..0000000 diff --git a/debian/capi-network-bluetooth-dev.install b/debian/capi-network-bluetooth-dev.install deleted file mode 100644 index 761a28b..0000000 --- a/debian/capi-network-bluetooth-dev.install +++ /dev/null @@ -1,4 +0,0 @@ -/usr/include/* -/usr/include/*/* -/usr/lib/pkgconfig/*.pc - diff --git a/debian/capi-network-bluetooth-dev.postinst b/debian/capi-network-bluetooth-dev.postinst deleted file mode 100644 index 1a24852..0000000 --- a/debian/capi-network-bluetooth-dev.postinst +++ /dev/null @@ -1 +0,0 @@ -#!/bin/sh diff --git a/debian/capi-network-bluetooth.install b/debian/capi-network-bluetooth.install deleted file mode 100644 index 4a755a4..0000000 --- a/debian/capi-network-bluetooth.install +++ /dev/null @@ -1 +0,0 @@ -/usr/lib/lib*.so* diff --git a/debian/capi-network-bluetooth.postinst b/debian/capi-network-bluetooth.postinst deleted file mode 100644 index 1a24852..0000000 --- a/debian/capi-network-bluetooth.postinst +++ /dev/null @@ -1 +0,0 @@ -#!/bin/sh diff --git a/debian/changelog b/debian/changelog deleted file mode 100644 index 7d8ea06..0000000 --- a/debian/changelog +++ /dev/null @@ -1,304 +0,0 @@ -capi-network-bluetooth (0.1.15-1) unstable; urgency=low - - * Tagging and upload the package - * Git: slp/api/bluetooth - * Tag: capi-network-bluetooth_0.1.15-1 - - -- DoHyun Pyun Tue, 11 Sep 2012 16:08:53 +0900 - -capi-network-bluetooth (0.1.14-1) unstable; urgency=low - - * Tagging and upload the package - * Git: slp/api/bluetooth - * Tag: capi-network-bluetooth_0.1.14-1 - - -- DoHyun Pyun Tue, 11 Sep 2012 09:56:47 +0900 - -capi-network-bluetooth (0.1.13-1) unstable; urgency=low - - * Tagging and upload the package - * Git: slp/api/bluetooth - * Tag: capi-network-bluetooth_0.1.13-1 - - -- DoHyun Pyun Mon, 10 Sep 2012 12:56:50 +0900 - -capi-network-bluetooth (0.1.12-1) unstable; urgency=low - - * Tagging and upload the package - * Git: slp/api/bluetooth - * Tag: capi-network-bluetooth_0.1.12-1 - - -- DoHyun Pyun Thu, 16 Aug 2012 16:56:23 +0900 - -capi-network-bluetooth (0.1.11-1) unstable; urgency=low - - * Tagging and upload the package - * Git: slp/api/bluetooth - * Tag: capi-network-bluetooth_0.1.11-1 - - -- DoHyun Pyun Wed, 08 Aug 2012 19:26:30 +0900 - -capi-network-bluetooth (0.1.10-1) unstable; urgency=low - - * Tagging and upload the package - * Git: slp/api/bluetooth - * Tag: capi-network-bluetooth_0.1.10-1 - - -- DoHyun Pyun Wed, 08 Aug 2012 17:08:38 +0900 - -capi-network-bluetooth (0.1.9-1) unstable; urgency=low - - * Modify the HID APIs - * Git: slp/api/bluetooth - * Tag: capi-network-bluetooth_0.1.9-1 - - -- DoHyun Pyun Tue, 07 Aug 2012 17:39:52 +0900 - -capi-network-bluetooth (0.1.8-1) unstable; urgency=low - - * Implement bt_socket_set_connection_requested_cb APIs - * Git: slp/api/bluetooth - * Tag: capi-network-bluetooth_0.1.8-1 - - -- DoHyun Pyun Mon, 06 Aug 2012 18:08:24 +0900 - -capi-network-bluetooth (0.1.7-1) unstable; urgency=low - - * Implement bt_get_device_info API - * Git: slp/api/bluetooth - * Tag: capi-network-bluetooth_0.1.7-1 - - -- DoHyun Pyun Wed, 01 Aug 2012 14:03:45 +0900 - -capi-network-bluetooth (0.1.6-1) unstable; urgency=low - - * Modify the RFCOMM implement - * Git: slp/api/bluetooth - * Tag: capi-network-bluetooth_0.1.6-1 - - -- DoHyun Pyun Wed, 25 Jul 2012 11:02:31 +0900 - -capi-network-bluetooth (0.1.5-1) unstable; urgency=low - - * Add bt_get_device_info API - * Git: slp/api/bluetooth - * Tag: capi-network-bluetooth_0.1.5-1 - - -- DoHyun Pyun Tue, 17 Jul 2012 13:51:51 +0900 - -capi-network-bluetooth (0.1.4-1) unstable; urgency=low - - * Add HDP API / Fix inapposite data type (rssi) - * Git: slp/api/bluetooth - * Tag: capi-network-bluetooth_0.1.4-1 - - -- Sangki Park Fri, 29 Jun 2012 17:10:28 +0900 - -capi-network-bluetooth (0.1.3-1) unstable; urgency=low - - * Implement the requirements from OSP - * Git: slp/api/bluetooth - * Tag: capi-network-bluetooth_0.1.3-1 - - -- DoHyun Pyun Wed, 13 Jun 2012 09:14:03 +0900 - -capi-network-bluetooth (0.1.2-1) unstable; urgency=low - - * Fix the DTS testcase - * Git: slp/api/bluetooth - * Tag: capi-network-bluetooth_0.1.2-1 - - -- DoHyun Pyun Thu, 12 Apr 2012 15:48:47 +0900 - -capi-network-bluetooth (0.1.1-1) unstable; urgency=low - - * Fix the crash in DTS test - * Git: slp/api/bluetooth - * Tag: capi-network-bluetooth_0.1.1-1 - - -- DoHyun Pyun Thu, 29 Mar 2012 14:45:08 +0900 - -capi-network-bluetooth (0.1.0-14) unstable; urgency=low - - * Initialize the pointer to NULL after free - * Git: slp/api/bluetooth - * Tag: capi-network-bluetooth_0.1.0-14 - - -- DoHyun Pyun Wed, 21 Mar 2012 17:15:59 +0900 - -capi-network-bluetooth (0.1.0-13) unstable; urgency=low - - * Correct dependent package - * Git: slp/api/bluetooth - * Tag: capi-network-bluetooth_0.1.0-13 - - -- ByungWoo Lee Thu, 15 Mar 2012 13:13:36 +0900 - -capi-network-bluetooth (0.1.0-12) unstable; urgency=low - - * Modify coding style - * Git: slp/api/bluetooth - * Tag: capi-network-bluetooth_0.1.0-12 - - -- ByungWoo Lee Mon, 20 Feb 2012 15:50:45 +0900 - -capi-network-bluetooth (0.1.0-11) unstable; urgency=low - - * Add versioning of library - * Git: slp/api/bluetooth - * Tag: capi-network-bluetooth_0.1.0-11 - - -- ByungWoo Lee Tue, 14 Feb 2012 17:09:56 +0900 - -capi-network-bluetooth (0.1.0-10) unstable; urgency=low - - * Clean codes - * Git: slp/api/bluetooth - * Tag: capi-network-bluetooth_0.1.0-10 - - -- ByungWoo Lee Thu, 02 Feb 2012 14:49:58 +0900 - -capi-network-bluetooth (0.1.0-9) unstable; urgency=low - - * Add LICENSE, remove COPYING and Convert TIZEN_ERROR_OK to TIZEN_ERROR_NONE - * Git: slp/api/bluetooth - * Tag: capi-network-bluetooth_0.1.0-9 - - -- ByungWoo Lee Mon, 05 Dec 2011 13:04:56 +0900 - -capi-network-bluetooth (0.1.0-8) unstable; urgency=low - - * Fix bug in destroying a bond - * Git: slp-source.sec.samsung.net:slp/api/bluetooth - * Tag: capi-network-bluetooth_0.1.0-8 - - -- ByungWoo Lee Wed, 30 Nov 2011 21:07:06 +0900 - -capi-network-bluetooth (0.1.0-7) unstable; urgency=low - - * Add service_uuid to bt_device_info_s and bt_device_sdp_info_s instead of service_list and modify log - * Git: slp-source.sec.samsung.net:slp/api/bluetooth - * Tag: capi-network-bluetooth_0.1.0-7 - - -- ByungWoo Lee Wed, 30 Nov 2011 19:49:10 +0900 - -capi-network-bluetooth (0.1.0-6) unstable; urgency=low - - * Convert SLP into TIZEN - * Git: slp-source.sec.samsung.net:slp/api/bluetooth - * Tag: capi-network-bluetooth_0.1.0-6 - - -- ByungWoo Lee Wed, 23 Nov 2011 13:09:26 +0900 - -capi-network-bluetooth (0.1.0-5) unstable; urgency=low - - * Change bt_device_cancel_bonding() and bt_adapter_set_visibility() into synchronous function, and Add BT_ERROR_SERVICE_SEARCH_ERROR to bt_error_e. - * Git: slp-source.sec.samsung.net:slp/api/bluetooth - * Tag: capi-network-bluetooth_0.1.0-5 - - -- ByungWoo Lee Wed, 02 Nov 2011 18:58:16 +0900 - -capi-network-bluetooth (0.1.0-4) unstable; urgency=low - - * Modify bt_error_e and change bt_device_cancel_service_search() and bt_device_cancel_bonding() into synchronous function - * Git: slp-source.sec.samsung.net:slp/api/bluetooth - * Tag: capi-network-bluetooth_0.1.0-4 - - -- ByungWoo Lee Thu, 27 Oct 2011 16:59:18 +0900 - -capi-network-bluetooth (0.1.0-3) unstable; urgency=low - - * Change bt_adapter_set_name into synchronous function - * Git: slp-source.sec.samsung.net:slp/api/bluetooth - * Tag: capi-network-bluetooth_0.1.0-3 - - -- ByungWoo Lee Mon, 17 Oct 2011 18:34:03 +0900 - -capi-network-bluetooth (0.1.0-2) unstable; urgency=low - - * Correct bug which happens when set local name and modify bt_error_e - * Git: slp-source.sec.samsung.net:slp/api/bluetooth - * Tag: capi-network-bluetooth_0.1.0-2 - - -- ByungWoo Lee Mon, 10 Oct 2011 18:37:32 +0900 - -capi-network-bluetooth (0.1.0-1) unstable; urgency=low - - * Modify error code of bt_initialize() and bt_deinitialize() - * Git: slp-source.sec.samsung.net:slp/api/bluetooth - * Tag: capi-network-bluetooth_0.1.0-1 - - -- ByungWoo Lee Tue, 27 Sep 2011 22:17:33 +0900 - -capi-network-bluetooth (0.0.1-9) unstable; urgency=low - - * Remove undefined enum type - * Git: slp-source.sec.samsung.net:slp/api/bluetooth - * Tag: capi-network-bluetooth_0.0.1-9 - - -- Kangho Hur Mon, 26 Sep 2011 21:31:34 +0900 - -capi-network-bluetooth (0.0.1-8) unstable; urgency=low - - * Change device_address to remote_address - * Git: slp-source.sec.samsung.net:slp/api/bluetooth - * Tag: capi-network-bluetooth_0.0.1-8 - - -- ByungWoo Lee Fri, 23 Sep 2011 20:02:07 +0900 - -capi-network-bluetooth (0.0.1-7) unstable; urgency=low - - * Remove BT_MAJOR_SERVICE_CLASS_UNKNOWN - * Git: slp-source.sec.samsung.net:slp/api/bluetooth - * Tag: capi-network-bluetooth_0.0.1-7 - - -- ByungWoo Lee Tue, 20 Sep 2011 17:17:01 +0900 - -capi-network-bluetooth (0.0.1-6) unstable; urgency=low - - * Rename class to bt_class - * Git: slp-source.sec.samsung.net:slp/api/bluetooth - * Tag: capi-network-bluetooth_0.0.1-6 - - -- ByungWoo Lee Thu, 08 Sep 2011 10:54:58 +0900 - -capi-network-bluetooth (0.0.1-5) unstable; urgency=low - - * Remove parameters of bt_adapter_start_device_discovery() - * Git: slp-source.sec.samsung.net:slp/api/bluetooth - * Tag: capi-network-bluetooth_0.0.1-5 - - -- ByungWoo Lee Mon, 05 Sep 2011 20:22:36 +0900 - -capi-network-bluetooth (0.0.1-4) unstable; urgency=low - - * Add bt_adapter_device_discovery_info_s - * Git: slp-source.sec.samsung.net:slp/api/bluetooth - * Tag: capi-network-bluetooth_0.0.1-4 - - -- ByungWoo Lee Mon, 22 Aug 2011 15:41:37 +0900 - -capi-network-bluetooth (0.0.1-3) unstable; urgency=low - - * Fix build break - * Git: slp-source.sec.samsung.net:slp/api/bluetooth - * Tag: capi-network-bluetooth_0.0.1-3 - - -- Kangho Hur Sat, 13 Aug 2011 01:07:56 +0900 - -capi-network-bluetooth (0.0.1-2) unstable; urgency=low - - * Modify how to copy service list - * Git: slp-source.sec.samsung.net:slp/api/bluetooth - * Tag: capi-network-bluetooth_0.0.1-2 - - -- ByungWoo Lee Thu, 11 Aug 2011 19:45:20 +0900 - -capi-network-bluetooth (0.0.1-1) unstable; urgency=low - - * Initial upload - * Git: slp-source.sec.samsung.net:slp/api/bluetooth - * Tag: capi-network-bluetooth_0.0.1-1 - - -- ByungWoo Lee Mon, 08 Aug 2011 10:12:25 +0900 - diff --git a/debian/compat b/debian/compat deleted file mode 100644 index 7ed6ff8..0000000 --- a/debian/compat +++ /dev/null @@ -1 +0,0 @@ -5 diff --git a/debian/control b/debian/control deleted file mode 100644 index 7299ecb..0000000 --- a/debian/control +++ /dev/null @@ -1,21 +0,0 @@ -Source: capi-network-bluetooth -Section: libs -Priority: extra -Maintainer: Kangho Hur , ByungWoo Lee -Build-Depends: debhelper (>= 5), dlog-dev, capi-base-common-dev, libglib2.0-dev, libbluetooth-frwk-dev - -Package: capi-network-bluetooth -Architecture: any -Depends: ${shlibs:Depends}, ${misc:Depends} -Description: A Network Bluetooth library in Tizen Native API - -Package: capi-network-bluetooth-dev -Architecture: any -Depends: ${shlibs:Depends}, ${misc:Depends}, capi-network-bluetooth (= ${Source-Version}), capi-base-common-dev -Description: A Network Bluetooth library in Tizen Native API (DEV) - -Package: capi-network-bluetooth-dbg -Architecture: any -Depends: ${shlibs:Depends}, ${misc:Depends}, capi-network-bluetooth (= ${Source-Version}) -Description: A Network Bluetooth library in Tizen Native API (DBG) - diff --git a/debian/rules b/debian/rules deleted file mode 100755 index 9736f8b..0000000 --- a/debian/rules +++ /dev/null @@ -1,68 +0,0 @@ -#!/usr/bin/make -f - -FULLVER ?= $(shell dpkg-parsechangelog | grep Version: | cut -d ' ' -f 2 | cut -d '-' -f 1) -MAJORVER ?= $(shell echo $(FULLVER) | cut -d '.' -f 1) - -CFLAGS = -Wall -g - -ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS))) - CFLAGS += -O0 -else - CFLAGS += -O2 -endif -CMAKE_ROOT_DIR ?= $(CURDIR) -CMAKE_BUILD_DIR ?= $(CURDIR)/cmake_build_tmp - -configure: configure-stamp -configure-stamp: - dh_testdir - mkdir -p $(CMAKE_BUILD_DIR) && cd $(CMAKE_BUILD_DIR) && cmake .. -DFULLVER=${FULLVER} -DMAJORVER=${MAJORVER} - touch configure-stamp - - -build: build-stamp -build-stamp: configure-stamp - dh_testdir - cd $(CMAKE_BUILD_DIR) && $(MAKE) - touch $@ - -clean: - cd $(CMAKE_ROOT_DIR) - dh_testdir - dh_testroot - rm -f build-stamp configure-stamp - rm -f `find . -name *.pc` - rm -rf $(CMAKE_BUILD_DIR) - dh_clean - -install: build - dh_testdir - dh_testroot - dh_clean -k - dh_installdirs - - cd $(CMAKE_BUILD_DIR) && $(MAKE) DESTDIR=$(CURDIR)/debian/tmp install - -binary-indep: build install - -binary-arch: build install - dh_testdir - dh_testroot - dh_installchangelogs - dh_installdocs - dh_installexamples - dh_install --sourcedir=debian/tmp - dh_installman - dh_link - dh_strip --dbg-package=capi-network-bluetooth-dbg - dh_fixperms - dh_makeshlibs - dh_installdeb - dh_shlibdeps - dh_gencontrol - dh_md5sums - dh_builddeb - -binary: binary-indep binary-arch -.PHONY: build clean binary-indep binary-arch binary install configure - diff --git a/doc/bluetooth_doc.h b/doc/bluetooth_doc.h new file mode 100644 index 0000000..6f318c0 --- /dev/null +++ b/doc/bluetooth_doc.h @@ -0,0 +1,696 @@ +/* + * 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 __TIZEN_NETWORK_BLUETOOTH_DOC_H__ +#define __TIZEN_NETWORK_BLUETOOTH_DOC_H__ + +/** + * @defgroup CAPI_NETWORK_BLUETOOTH_MODULE Bluetooth + * @brief Bluetooth Service provides API to manage Bluetooth device. + * @ingroup CAPI_NETWORK_FRAMEWORK + * + * @section CAPI_NETWORK_BLUETOOTH_MODULE_HEADER Required Header + * \#include + * + * @section CAPI_NETWORK_BLUETOOTH_MODULE_OVERVIEW Overview + * Bluetooth Service consists of @ref CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE, @ref CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE and @ref CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE. + * + *
+ * In order to use the above APIs, you must call #bt_initialize() in advance. + * In addition, #bt_deinitialize() should be called when Bluetooth Service is no longer needed. + * Please refer Bluetooth Tutorial if you want to get more detailed usages and information of this api. + * + * @section CAPI_NETWORK_BLUETOOTH_MODULE_FEATURE Related Features + * This API is related with the following features:\n + * - http://tizen.org/feature/network.bluetooth\n + * + * It is recommended to design feature related codes in your application for reliability.\n + * + * You can check if a device supports the related features for this API by using @ref CAPI_SYSTEM_SYSTEM_INFO_MODULE,thereby controlling the procedure of your application.\n + * + * To ensure your application is only running on the device with specific features, please define the features in your manifest file using the manifest editor in the SDK.\n + * + * More details on featuring your application can be found from Feature Element. + * + */ + +/** + * @defgroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE Bluetooth Adapter + * @brief Bluetooth Adapter API provides functions for setting up Bluetooth and discovering other devices. + * @ingroup CAPI_NETWORK_BLUETOOTH_MODULE + * + * @section CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE_HEADER Required Header + * \#include + * + * @section CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE_OVERVIEW Overview + * This set of function is used to control a bluetooth adapter. + * You can also control visibility of the device, its appearance for others (adapter name). + * In addition, this api is used to discover neighboring bluetooth devices. + * This process is asynchronous, so it is up to you to build and hold list of devices in the neighborhood + * - the api does not provide this list. + * Before starting a device discovery, you can find a device from the connected devices. + * This functionality is implemented by foreach loop. + * + * @section CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE_FEATURE Related Features + * This API is related with the following features:\n + * - http://tizen.org/feature/network.bluetooth\n + * + * It is recommended to design feature related codes in your application for reliability.\n + * + * You can check if a device supports the related features for this API by using @ref CAPI_SYSTEM_SYSTEM_INFO_MODULE,thereby controlling the procedure of your application.\n + * + * To ensure your application is only running on the device with specific features, please define the features in your manifest file using the manifest editor in the SDK.\n + * + * More details on featuring your application can be found from Feature Element. + * + * @section CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE_ASYNCHRONOUS_OPERATIONS Asynchronous Operations + *
+ * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
FUNCTIONCALLBACKDESCRIPTION
bt_adapter_set_name()bt_adapter_name_changed_cb()Used to set adapter name.
bt_adapter_visibility_mode_changed_cb()Used to set visibility mode (#bt_adapter_visibility_mode_e).
bt_adapter_start_device_discovery()
+ * bt_adapter_stop_device_discovery()
bt_adapter_device_discovery_state_changed_cb()Used to start or cancel device discovery.
+ * + * @section CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE_CALLBACK_OPERATIONS Callback(Event) Operations + *
+ * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
REGISTERUNREGISTERCALLBACKDESCRIPTION
bt_adapter_set_state_changed_cb()bt_adapter_unset_state_changed_cb()bt_adapter_state_changed_cb()Used to be notified of state change (enable or disable).
bt_adapter_set_name_changed_cb()bt_adapter_unset_name_changed_cb()bt_adapter_name_changed_cb()Used to be notified of name change.
bt_adapter_set_visibility_mode_changed_cb()bt_adapter_unset_visibility_mode_changed_cb()bt_adapter_visibility_mode_changed_cb()Used to be notified of change of visibility mode (#bt_adapter_visibility_mode_e).
bt_adapter_set_device_discovery_state_changed_cb()bt_adapter_unset_device_discovery_state_changed_cb()bt_adapter_device_discovery_state_changed_cb()Used to be notified of change of device discovery state (#bt_adapter_device_discovery_state_e).
+ * + * @section CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE_FOREACH_OPERATIONS Foreach Operations + *
+ * + * + * + * + * + * + * + * + * + * + *
FOREACHCALLBACKDESCRIPTION
bt_adapter_foreach_bonded_device()bt_adapter_bonded_device_cb()Used to get bonded devices.
+ * + *
+ * Please refer Bluetooth Tutorial if you want to get more detailed usages and information of this api. + */ + +/** + * @defgroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE Bluetooth LE Adapter + * @brief Bluetooth LE API provides functions for managing bonds with other devices for LE and searching for supported LE services. + * @ingroup CAPI_NETWORK_BLUETOOTH_MODULE + * + * @section CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE_HEADER Required Header + * \#include + * + * @section CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE_OVERVIEW Overview + * Bluetooth stack architecture has been changed. Thus, GATT APIs defined in Tizen 2.3 are deprecated and new GATT client APIs are defined. + * + * @section CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE_FEATURE Related Features + * This API is related with the following features:\n + * - http://tizen.org/feature/network.bluetooth\n + * - http://tizen.org/feature/network.bluetooth.le\n + * + * It is recommended to design feature related codes in your application for reliability.\n + * + * You can check if a device supports the related features for this API by using @ref CAPI_SYSTEM_SYSTEM_INFO_MODULE,thereby controlling the procedure of your application.\n + * + * To ensure your application is only running on the device with specific features, please define the features in your manifest file using the manifest editor in the SDK.\n + * + * More details on featuring your application can be found from Feature Element. + * + */ + +/** + * @defgroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE Bluetooth Device + * @brief Bluetooth Device API provides functions for managing bonds with other devices and searching for supported services. + * @ingroup CAPI_NETWORK_BLUETOOTH_MODULE + * + * @section CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE_HEADER Required Header + * \#include + * + * @section CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE_OVERVIEW Overview + * This set of functions is used to handle the connection with other devices. + * Connected devices exchange keys needed for encrypted communication, + * but each connection has to be approved by the latest application user. + * You can also set authorization of other devices. + * Authorized devices are connected, and it is connected automatically without the latest user + * being asked for authorization. + * In addition, this is used to search for services available on remote devices. + * + * @section CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE_FEATURE Related Features + * This API is related with the following features:\n + * - http://tizen.org/feature/network.bluetooth\n + * + * It is recommended to design feature related codes in your application for reliability.\n + * + * You can check if a device supports the related features for this API by using @ref CAPI_SYSTEM_SYSTEM_INFO_MODULE,thereby controlling the procedure of your application.\n + * + * To ensure your application is only running on the device with specific features, please define the features in your manifest file using the manifest editor in the SDK.\n + * + * More details on featuring your application can be found from Feature Element. + * + * @section CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE_ASYNCHRONOUS_OPERATIONS Asynchronous Operations + *
+ * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
FUNCTIONCALLBACKDESCRIPTION
bt_device_create_bond()
+ * bt_device_cancel_bonding()
bt_device_bond_created_cb()Used to create bond or cancel creating bond.
bt_device_destroy_bond()bt_device_bond_destroyed_cb()Used to destroy bond.
bt_device_set_authorization()bt_device_authorization_changed_cb()Used to set as authorized or unauthorized device.
bt_device_start_service_search()bt_device_service_searched_cb()Used to start or cancel service search.
+ * + * @section CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE_CALLBACK_OPERATIONS Callback(Event) Operations + *
+ * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
REGISTERUNREGISTERCALLBACKDESCRIPTION
bt_device_set_bond_created_cb()bt_device_unset_bond_created_cb()bt_device_bond_created_cb()Used to be notified of the result of creating bond.
bt_device_set_bond_destroyed_cb()bt_device_unset_bond_destroyed_cb()bt_device_bond_destroyed_cb()Used to be notified of the result of destroying bond.
bt_device_set_authorization_changed_cb()bt_device_unset_authorization_changed_cb()bt_device_authorization_changed_cb()Used to be notified of change of authorization.
bt_device_set_service_searched_cb()bt_device_unset_service_searched_cb()bt_device_service_searched_cb()Used to be notified of change of service search state.
+ * + *
+ * Please refer Bluetooth Tutorial if you want to get more detailed usages and information of this api. + */ + + +/** + * @defgroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE Bluetooth Socket + * @brief Bluetooth Socket API provides functions for managing connections to other devices and exchanging data. + * @ingroup CAPI_NETWORK_BLUETOOTH_MODULE + * + * @section CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE_HEADER Required Header + * \#include + * + * @section CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE_OVERVIEW Overview + * This set of functions is used for exchanging data between two bluetooth + * devices, our device can have both roles as server (service provider) and client + * (service user). + * Depending on the role, there is difference in creating a connection. + * After that, processes of exchanging data and disconnection are same. + * + * To start communication, you should first register for #bt_socket_set_connection_state_changed_cb() + * and #bt_socket_set_data_received_cb(). + * Next step depends on the role of your application.\n + * If you want to be \b server \b role, application should create socket + * (#bt_socket_create_rfcomm()), and start listening and accepting incoming connections + * (#bt_socket_listen_and_accept_rfcomm()). + * If you want to connect to specific device and use it's services (\a client \a role), + * you have to start connection with #bt_socket_connect_rfcomm() and wait for connection.\n + * After connection has been established (information is passed to your program with + * #bt_socket_connection_state_changed_cb() function call), you can exchange data by + * calling #bt_socket_send_data(). \n + * If you receive data from remote device, #bt_socket_data_received_cb() functions will be called. + * When you finish exchanging data, you should disconnect connection + * with #bt_socket_disconnect_rfcomm() and unregister callback functions (with using + * #bt_socket_unset_data_received_cb(), #bt_socket_unset_connection_state_changed_cb()). + * + * @section CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE_FEATURE Related Features + * This API is related with the following features:\n + * - http://tizen.org/feature/network.bluetooth\n + * + * It is recommended to design feature related codes in your application for reliability.\n + * + * You can check if a device supports the related features for this API by using @ref CAPI_SYSTEM_SYSTEM_INFO_MODULE,thereby controlling the procedure of your application.\n + * + * To ensure your application is only running on the device with specific features, please define the features in your manifest file using the manifest editor in the SDK.\n + * + * More details on featuring your application can be found from Feature Element. + * + * @section CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE_ASYNCHRONOUS_OPERATIONS Asynchronous Operations + *
+ * + * + * + * + * + * + * + * + * + * + *
FUNCTIONCALLBACKDESCRIPTION
bt_socket_listen_and_accept_rfcomm()
+ * bt_socket_connect_rfcomm()
bt_socket_connection_state_changed_cb()Used to connect a device.
+ * + * @section CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE_CALLBACK_OPERATIONS Callback(Event) Operations + *
+ * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
REGISTERUNREGISTERCALLBACKDESCRIPTION
bt_socket_set_data_received_cb()bt_socket_unset_data_received_cb()bt_socket_data_received_cb()Used to be notified of received data.
bt_socket_set_connection_state_changed_cb()bt_socket_unset_connection_state_changed_cb()bt_socket_connection_state_changed_cb()Used to be notified when the state of connection changes.
+ * + *
+ * Please refer Bluetooth Tutorial if you want to get more detailed usages and information of this api. + */ + + +/** + * @defgroup CAPI_NETWORK_BLUETOOTH_OPP_MODULE Bluetooth OPP + * @brief Bluetooth OPP(Object Push Profile) API provides functions for exchanging objects such as pictures. + * @ingroup CAPI_NETWORK_BLUETOOTH_MODULE + * + * @section CAPI_NETWORK_BLUETOOTH_OPP_MODULE_HEADER Required Header + * \#include + * + * @section CAPI_NETWORK_BLUETOOTH_OPP_MODULE_OVERVIEW Overview + * OPP profile let users exchange objects between two devices. + * + */ + +/** + * @defgroup CAPI_NETWORK_BLUETOOTH_OPP_SERVER_MODULE Bluetooth OPP Server + * @brief Bluetooth OPP(Object Push Profile) Server API provides functions for accepting objects such as pictures. + * @ingroup CAPI_NETWORK_BLUETOOTH_OPP_MODULE + * + * @section CAPI_NETWORK_BLUETOOTH_OPP_SERVER_MODULE_HEADER Required Header + * \#include + * + * @section CAPI_NETWORK_BLUETOOTH_OPP_SERVER_MODULE_OVERVIEW Overview + * This is OPP server APIs. + * + * @section CAPI_NETWORK_BLUETOOTH_OPP_SERVER_MODULE_FEATURE Related Features + * This API is related with the following features:\n + * - http://tizen.org/feature/network.bluetooth.opp\n + * + * It is recommended to design feature related codes in your application for reliability.\n + * + * You can check if a device supports the related features for this API by using @ref CAPI_SYSTEM_SYSTEM_INFO_MODULE,thereby controlling the procedure of your application.\n + * + * To ensure your application is only running on the device with specific features, please define the features in your manifest file using the manifest editor in the SDK.\n + * + * More details on featuring your application can be found from Feature Element. + * + */ + +/** + * @defgroup CAPI_NETWORK_BLUETOOTH_OPP_CLIENT_MODULE Bluetooth OPP Client + * @brief Bluetooth OPP(Object Push Profile) Client API provides functions for pushing objects such as pictures. + * @ingroup CAPI_NETWORK_BLUETOOTH_OPP_MODULE + * + * @section CAPI_NETWORK_BLUETOOTH_OPP_CLIENT_MODULE_HEADER Required Header + * \#include + * + * @section CAPI_NETWORK_BLUETOOTH_OPP_CLIENT_MODULE_OVERVIEW Overview + * This is OPP Client APIs. + * + * @section CAPI_NETWORK_BLUETOOTH_OPP_CLIENT_MODULE_FEATURE Related Features + * This API is related with the following features:\n + * - http://tizen.org/feature/network.bluetooth.opp\n + * + * It is recommended to design feature related codes in your application for reliability.\n + * + * You can check if a device supports the related features for this API by using @ref CAPI_SYSTEM_SYSTEM_INFO_MODULE,thereby controlling the procedure of your application.\n + * + * To ensure your application is only running on the device with specific features, please define the features in your manifest file using the manifest editor in the SDK.\n + * + * More details on featuring your application can be found from Feature Element. + * + */ + +/** + * @internal + * @defgroup CAPI_NETWORK_BLUETOOTH_PAN_MODULE Bluetooth PAN + * @brief Bluetooth PAN(Personal Area Networking) API provides functions for connecting to a higher level network and the Internet. + * @ingroup CAPI_NETWORK_BLUETOOTH_MODULE + * + * @section CAPI_NETWORK_BLUETOOTH_PAN_MODULE_OVERVIEW Overview + * The PAN Profile describe how two or more Bluetooth enabled devices can form an ad-hoc network and how the same mechanism can be + * used to access a remote network through a network access point. But this API only supports network access point service. + * + * @section CAPI_NETWORK_BLUETOOTH_PAN_MODULE_FEATURE Related Features + * This API is related with the following features:\n + * - http://tizen.org/feature/network.tethering.bluetooth\n + * + * It is recommended to design feature related codes in your application for reliability.\n + * + * You can check if a device supports the related features for this API by using @ref CAPI_SYSTEM_SYSTEM_INFO_MODULE,thereby controlling the procedure of your application.\n + * + * To ensure your application is only running on the device with specific features, please define the features in your manifest file using the manifest editor in the SDK.\n + * + * More details on featuring your application can be found from Feature Element. + * + */ + +/** + * @internal + * @defgroup CAPI_NETWORK_BLUETOOTH_PAN_NAP_MODULE Bluetooth NAP + * @brief Bluetooth NAP(Network Access Point) API provides functions for an Ethernet bridge to support network services. + * @ingroup CAPI_NETWORK_BLUETOOTH_PAN_MODULE + * + * @section CAPI_NETWORK_BLUETOOTH_PAN_NAP_MODULE_HEADER Required Header + * \#include + * + * @section CAPI_NETWORK_BLUETOOTH_PAN_NAP_MODULE_OVERVIEW Overview + * A Bluetooth device that supports the NAP service is a Bluetooth device that provides some of the features of an Ethernet bridge to support network services. + * + * @section CAPI_NETWORK_BLUETOOTH_PAN_NAP_MODULE_FEATURE Related Features + * This API is related with the following features:\n + * - http://tizen.org/feature/network.tethering.bluetooth\n + * + * It is recommended to design feature related codes in your application for reliability.\n + * + * You can check if a device supports the related features for this API by using @ref CAPI_SYSTEM_SYSTEM_INFO_MODULE, thereby controlling the procedure of your application.\n + * + * To ensure your application is only running on the device with specific features, please define the features in your manifest file using the manifest editor in the SDK.\n + * + * More details on featuring your application can be found from Feature Element. + * + */ + +/** + * @internal + * @defgroup CAPI_NETWORK_BLUETOOTH_PAN_PANU_MODULE Bluetooth PANU + * @brief Bluetooth PANU(Personal Area Networking User) API provides functions for client of both the NAP(Network Access Point). + * @ingroup CAPI_NETWORK_BLUETOOTH_PAN_MODULE + * + * @section CAPI_NETWORK_BLUETOOTH_PAN_PANU_MODULE_HEADER Required Header + * \#include + * + * @section CAPI_NETWORK_BLUETOOTH_PAN_PANU_MODULE_OVERVIEW Overview + * In PAN Profile, PANU can uses either the NAP or GN service, but this API only supports NAP service. + * + * @section CAPI_NETWORK_BLUETOOTH_PAN_PANU_MODULE_FEATURE Related Features + * This API is related with the following features:\n + * - http://tizen.org/feature/network.tethering.bluetooth\n + * + * It is recommended to design feature related codes in your application for reliability.\n + * + * You can check if a device supports the related features for this API by using @ref CAPI_SYSTEM_SYSTEM_INFO_MODULE, thereby controlling the procedure of your application.\n + * + * To ensure your application is only running on the device with specific features, please define the features in your manifest file using the manifest editor in the SDK.\n + * + * More details on featuring your application can be found from Feature Element. + * + */ + +/** + * @defgroup CAPI_NETWORK_BLUETOOTH_HID_MODULE Bluetooth HID + * @brief Bluetooth HID(Human Interface Device) API provides functions for connecting to Bluetooth HID such as keyboards and mouse. + * @ingroup CAPI_NETWORK_BLUETOOTH_MODULE + * + * @section CAPI_NETWORK_BLUETOOTH_HID_MODULE_HEADER Required Header + * \#include + * + * @section CAPI_NETWORK_BLUETOOTH_HID_MODULE_OVERVIEW Overview + * In HID Profile, there are two roles - @a Host and @a Device. + * The @a Host is a device that uses or requests the services of a HID. The @a Device is a device that provides the service of human data input and output to and from the @a Host. + * This API only supports @a Host role. + * + * @section CAPI_NETWORK_BLUETOOTH_HID_MODULE_FEATURE Related Features + * This API is related with the following features:\n + * - http://tizen.org/feature/network.bluetooth.hid\n + * + * It is recommended to design feature related codes in your application for reliability.\n + * + * You can check if a device supports the related features for this API by using @ref CAPI_SYSTEM_SYSTEM_INFO_MODULE, thereby controlling the procedure of your application.\n + * + * To ensure your application is only running on the device with specific features, please define the features in your manifest file using the manifest editor in the SDK.\n + * + * More details on featuring your application can be found from Feature Element. + * + */ + +/** + * @defgroup CAPI_NETWORK_BLUETOOTH_AUDIO_MODULE Bluetooth Audio + * @brief Bluetooth Audio API provides functions for connecting to Bluetooth audio devices such as headset, hand-free and headphone. + * @ingroup CAPI_NETWORK_BLUETOOTH_MODULE + * + * @section CAPI_NETWORK_BLUETOOTH_AUDIO_MODULE_HEADER Required Header + * \#include + * + * @section CAPI_NETWORK_BLUETOOTH_AUDIO_MODULE_OVERVIEW Overview + * This API supports the HFP(Hands-Free Profile), HSP(Headset Profile) and A2DP(Advanced Audio Distribution Profile). + * + * @section CAPI_NETWORK_BLUETOOTH_AUDIO_MODULE_FEATURE Related Features + * This API is related with the following features:\n + * - http://tizen.org/feature/network.bluetooth.audio.call\n + * - http://tizen.org/feature/network.bluetooth.audio.media\n + * + * It is recommended to design feature related codes in your application for reliability.\n + * + * You can check if a device supports the related features for this API by using @ref CAPI_SYSTEM_SYSTEM_INFO_MODULE, thereby controlling the procedure of your application.\n + * + * To ensure your application is only running on the device with specific features, please define the features in your manifest file using the manifest editor in the SDK.\n + * + * More details on featuring your application can be found from Feature Element. + * + */ + +/** + * @internal + * @defgroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE Bluetooth AG + * @brief Bluetooth AG(Audio Gateway) API provides functions for controling the remote audio device. + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_MODULE + * + * @section CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE_HEADER Required Header + * \#include + * + * @section CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE_OVERVIEW Overview + * This API supports the @a Audio @a Gateway role in HSP and HFP. + * Audio Gateway is the devie that is the gateway of the audio, both for input and output, typically a mobile phone or PC. + * + * @section CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE_FEATURE Related Features + * This API is related with the following features:\n + * - http://tizen.org/feature/network.bluetooth.audio.call\n + * - http://tizen.org/feature/network.bluetooth.audio.media\n + * + * It is recommended to design feature related codes in your application for reliability.\n + * + * You can check if a device supports the related features for this API by using @ref CAPI_SYSTEM_SYSTEM_INFO_MODULE, thereby controlling the procedure of your application.\n + * + * To ensure your application is only running on the device with specific features, please define the features in your manifest file using the manifest editor in the SDK.\n + * + * More details on featuring your application can be found from Feature Element. + * + */ + +/** + * @internal + * @defgroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_CALL_MODULE Call List + * @brief Bluetooth AG(Audio Gateway) API provides functions for managing the handler of call list. + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * + * @section CAPI_NETWORK_BLUETOOTH_AUDIO_AG_CALL_MODULE_HEADER Required Header + * \#include + * + * @section CAPI_NETWORK_BLUETOOTH_AUDIO_AG_CALL_OVERVIEW Overview + * This set of functions is used for managing the handler of call list. + * This handler is used for notifying the call list to the remote bluetooth device which supports HFP(Hands-Free Profile). + * + * @section CAPI_NETWORK_BLUETOOTH_AUDIO_AG_CALL_MODULE_FEATURE Related Features + * This API is related with the following features:\n + * - http://tizen.org/feature/network.bluetooth.audio.call\n + * - http://tizen.org/feature/network.bluetooth.audio.media\n + * + * It is recommended to design feature related codes in your application for reliability.\n + * + * You can check if a device supports the related features for this API by using @ref CAPI_SYSTEM_SYSTEM_INFO_MODULE, thereby controlling the procedure of your application.\n + * + * To ensure your application is only running on the device with specific features, please define the features in your manifest file using the manifest editor in the SDK.\n + * + * More details on featuring your application can be found from Feature Element. + * + */ + +/** + * @internal + * @defgroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE Bluetooth AVRCP + * @brief Bluetooth AVRCP(Audio/Video Remote Control Profile) API provides functions for notifying the change of target device to the control device. + * @ingroup CAPI_NETWORK_BLUETOOTH_MODULE + * + * @section CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE_HEADER Required Header + * \#include + * + * @section CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE_OVERVIEW Overview + * This API supports the @a Target role in AVRCP spec. + * The @a Target is the device whose characteristics are being altered. + * In a "walkman" type media player scenario, the @a Control device may be a headset that allows tracks to be skipped and the @a Target device would be the actual medial player. + * + * @section CAPI_NETWORK_BLUETOOTH_AVRCP__MODULE_FEATURE Related Features + * This API is related with the following features:\n + * - http://tizen.org/feature/network.bluetooth.audio.media\n + * + * It is recommended to design feature related codes in your application for reliability.\n + * + * You can check if a device supports the related features for this API by using @ref CAPI_SYSTEM_SYSTEM_INFO_MODULE, thereby controlling the procedure of your application.\n + * + * To ensure your application is only running on the device with specific features, please define the features in your manifest file using the manifest editor in the SDK.\n + * + * More details on featuring your application can be found from Feature Element. + * + */ + +/** + * @defgroup CAPI_NETWORK_BLUETOOTH_HDP_MODULE Bluetooth HDP + * @brief Bluetooth HDP(Health Device Profile) API provides functions for managing connections to health devices and exchanging data. + * @ingroup CAPI_NETWORK_BLUETOOTH_MODULE + * + * @section CAPI_NETWORK_BLUETOOTH_HDP_MODULE_HEADER Required Header + * \#include + * + * @section CAPI_NETWORK_BLUETOOTH_HDP_MODULE_OVERVIEW Overview + * The @a Source is a transmitter of application data that is to be transferred to a @a Sink. The @a Sink is a receiver of application data delivered from a @a Source. + * This API supports the @a Sink role in HDP spec. + * + * @section CAPI_NETWORK_BLUETOOTH_HDP_MODULE_FEATURE Related Features + * This API is related with the following features:\n + * - http://tizen.org/feature/network.bluetooth.health\n + * + * It is recommended to design feature related codes in your application for reliability.\n + * + * You can check if a device supports the related features for this API by using @ref CAPI_SYSTEM_SYSTEM_INFO_MODULE, thereby controlling the procedure of your application.\n + * + * To ensure your application is only running on the device with specific features, please define the features in your manifest file using the manifest editor in the SDK.\n + * + * More details on featuring your application can be found from Feature Element. + * + */ + +/** + * @defgroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE Bluetooth GATT + * @brief Bluetooth GATT(Generic Attribute Profile) API provides functions for discovering, reading and modifying attributes. + * @ingroup CAPI_NETWORK_BLUETOOTH_MODULE + * + * @section CAPI_NETWORK_BLUETOOTH_GATT_MODULE_HEADER Required Header + * \#include + * + * @section CAPI_NETWORK_BLUETOOTH_GATT_MODULE_OVERVIEW Overview + * Two roles are defined for devices that implement GATT. + * The @a Server is the device that accepts incoming commands and requests from the client and sends responses, indications and notifications to a client. + * The @a Client is the device that initiates commands and requests towards the server and can receive responses, indications and notifications sent by the server. + * This API supports the @a Client role in GATT. \n + * Bluetooth stack architecture has been changed. Thus, GATT APIs defined in Tizen 2.3 are deprecated and new GATT client APIs are defined. + * + * @section CAPI_NETWORK_BLUETOOTH_GATT_MODULE_FEATURE Related Features + * This API is related with the following features:\n + * - http://tizen.org/feature/network.bluetooth.le\n + * + * It is recommended to design feature related codes in your application for reliability.\n + * + * You can check if a device supports the related features for this API by using @ref CAPI_SYSTEM_SYSTEM_INFO_MODULE, thereby controlling the procedure of your application.\n + * + * To ensure your application is only running on the device with specific features, please define the features in your manifest file using the manifest editor in the SDK.\n + * + * More details on featuring your application can be found from Feature Element. + * + */ + +#endif /* __TIZEN_NETWORK_BLUETOOTH_DOC_H__ */ diff --git a/include/bluetooth.h b/include/bluetooth.h deleted file mode 100644 index 3a419b9..0000000 --- a/include/bluetooth.h +++ /dev/null @@ -1,2917 +0,0 @@ -/* - * 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 __TIZEN_NETWORK_BLUETOOTH_H__ -#define __TIZEN_NETWORK_BLUETOOTH_H__ - -#include -#include -#include -#include - -#ifdef __cplusplus -extern "C" -{ -#endif /* __cplusplus */ - -/** - * @file bluetooth.h - * @brief API to control the Bluetooth adapter and devices and communications. - * @ingroup CAPI_NETWORK_BLUETOOTH_MODULE - */ - - -/** - * @addtogroup CAPI_NETWORK_BLUETOOTH_MODULE - * @{ - */ - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE - * @brief Enumerations of connected Bluetooth device event role. - */ -typedef enum -{ - BT_SOCKET_UNKNOWN = 0x00, /**< Unknown role*/ - BT_SOCKET_SERVER , /**< Server role*/ - BT_SOCKET_CLIENT, /**< Client role*/ -} bt_socket_role_e; - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_MODULE - * @brief Enumerations of Bluetooth error codes. - */ -typedef enum -{ - BT_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful*/ - BT_ERROR_CANCELLED = TIZEN_ERROR_CANCELED, /**< Operation cancelled */ - BT_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid parameter */ - BT_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of memory */ - BT_ERROR_RESOURCE_BUSY = TIZEN_ERROR_RESOURCE_BUSY, /**< Device or resource busy */ - BT_ERROR_TIMED_OUT = TIZEN_ERROR_TIMED_OUT, /**< Timeout error */ - BT_ERROR_NOW_IN_PROGRESS = TIZEN_ERROR_NOW_IN_PROGRESS, /**< Operation now in progress */ - BT_ERROR_NOT_INITIALIZED = TIZEN_ERROR_NETWORK_CLASS|0x0101, /**< Local adapter not initialized */ - BT_ERROR_NOT_ENABLED = TIZEN_ERROR_NETWORK_CLASS|0x0102, /**< Local adapter not enabled */ - BT_ERROR_ALREADY_DONE = TIZEN_ERROR_NETWORK_CLASS|0x0103, /**< Operation already done */ - BT_ERROR_OPERATION_FAILED = TIZEN_ERROR_NETWORK_CLASS|0x0104, /**< Operation failed */ - BT_ERROR_NOT_IN_PROGRESS = TIZEN_ERROR_NETWORK_CLASS|0x0105, /**< Operation not in progress */ - BT_ERROR_REMOTE_DEVICE_NOT_BONDED = TIZEN_ERROR_NETWORK_CLASS|0x0106, /**< Remote device not bonded */ - BT_ERROR_AUTH_REJECTED = TIZEN_ERROR_NETWORK_CLASS|0x0107, /**< Authentication rejected */ - BT_ERROR_AUTH_FAILED = TIZEN_ERROR_NETWORK_CLASS|0x0108, /**< Authentication failed */ - BT_ERROR_REMOTE_DEVICE_NOT_FOUND = TIZEN_ERROR_NETWORK_CLASS|0x0109, /**< Remote device not found */ - BT_ERROR_SERVICE_SEARCH_FAILED = TIZEN_ERROR_NETWORK_CLASS|0x010A, /**< Service search failed */ - BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED = TIZEN_ERROR_NETWORK_CLASS|0x010B, /**< Remote device is not connected */ -} bt_error_e; - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE - * @brief Enumerations of the Bluetooth adapter state. - */ -typedef enum -{ - BT_ADAPTER_DISABLED = 0x00, /**< Bluetooth adapter is disabled */ - BT_ADAPTER_ENABLED, /**< Bluetooth adapter is enabled */ -} bt_adapter_state_e; - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE - * @brief Enumerations of the Bluetooth visibility mode. - */ -typedef enum -{ - BT_ADAPTER_VISIBILITY_MODE_NON_DISCOVERABLE = 0x00, /**< Other devices cannot find your device via discovery */ - BT_ADAPTER_VISIBILITY_MODE_GENERAL_DISCOVERABLE, /**< Discoverable mode */ - BT_ADAPTER_VISIBILITY_MODE_LIMITED_DISCOVERABLE, /**< Discoverable mode with time limit. After specific period, - it is changed to #BT_ADAPTER_VISIBILITY_MODE_NON_DISCOVERABLE.*/ -} bt_adapter_visibility_mode_e; - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE - * @brief Enumerations of the discovery state of Bluetooth device. - * - */ -typedef enum -{ - BT_ADAPTER_DEVICE_DISCOVERY_STARTED, /**< Device discovery is started */ - BT_ADAPTER_DEVICE_DISCOVERY_FINISHED, /**< Device discovery is finished */ - BT_ADAPTER_DEVICE_DISCOVERY_FOUND, /**< The remote Bluetooth device is found */ -} bt_adapter_device_discovery_state_e; - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE - * @brief Enumerations of device authorization state. - */ -typedef enum -{ - BT_DEVICE_AUTHORIZED, /**< The remote Bluetooth device is authorized */ - BT_DEVICE_UNAUTHORIZED, /**< The remote Bluetooth device is unauthorized */ -} bt_device_authorization_e; - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE - * @brief Enumerations of Bluetooth socket connection state. - */ -typedef enum -{ - BT_SOCKET_CONNECTED, /**< RFCOMM is connected */ - BT_SOCKET_DISCONNECTED, /**< RFCOMM is disconnected */ -} bt_socket_connection_state_e; - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE - * @brief Enumerations of major service class. - */ -typedef enum -{ - BT_MAJOR_SERVICE_CLASS_LIMITED_DISCOVERABLE_MODE = 0x002000, /**< Limited discoverable mode */ - BT_MAJOR_SERVICE_CLASS_POSITIONING = 0x010000, /**< Positioning class */ - BT_MAJOR_SERVICE_CLASS_NETWORKING = 0x020000, /**< Networking class */ - BT_MAJOR_SERVICE_CLASS_RENDERING = 0x040000, /**< Rendering class */ - BT_MAJOR_SERVICE_CLASS_CAPTURING = 0x080000, /**< Capturing class */ - BT_MAJOR_SERVICE_CLASS_OBJECT_TRANSFER = 0x100000, /**< Object transferring class */ - BT_MAJOR_SERVICE_CLASS_AUDIO = 0x200000, /**< Audio class*/ - BT_MAJOR_SERVICE_CLASS_TELEPHONY = 0x400000, /**< Telephony class */ - BT_MAJOR_SERVICE_CLASS_INFORMATION = 0x800000, /**< Information class */ -} bt_major_service_class_e; - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE - * @brief Enumerations of major device class. - */ -typedef enum -{ - BT_MAJOR_DEVICE_CLASS_MISC = 0x00, /**< Miscellaneous major device class*/ - BT_MAJOR_DEVICE_CLASS_COMPUTER = 0x01, /**< Computer major device class */ - BT_MAJOR_DEVICE_CLASS_PHONE = 0x02, /**< Phone major device class */ - BT_MAJOR_DEVICE_CLASS_LAN_NETWORK_ACCESS_POINT = 0x03, /**< LAN/Network access point major device class */ - BT_MAJOR_DEVICE_CLASS_AUDIO_VIDEO = 0x04, /**< Audio/Video major device class */ - BT_MAJOR_DEVICE_CLASS_PERIPHERAL = 0x05, /**< Peripheral major device class */ - BT_MAJOR_DEVICE_CLASS_IMAGING = 0x06, /**< Imaging major device class */ - BT_MAJOR_DEVICE_CLASS_WEARABLE = 0x07, /**< Wearable device class */ - BT_MAJOR_DEVICE_CLASS_TOY = 0x08, /**< Toy device class */ - BT_MAJOR_DEVICE_CLASS_HEALTH = 0x09, /**< Health device class */ - BT_MAJOR_DEVICE_CLASS_UNCATEGORIZED = 0x1F, /**< Uncategorized major device class */ -} bt_major_device_class_e; - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE - * @brief Enumerations of minor device class. - */ -typedef enum -{ - BT_MINOR_DEVICE_CLASS_COMPUTER_UNCATEGORIZED = 0x00, /**< Uncategorized minor device class of computer */ - BT_MINOR_DEVICE_CLASS_COMPUTER_DESKTOP_WORKSTATION = 0x04, /**< Desktop workstation minor device class of computer */ - BT_MINOR_DEVICE_CLASS_COMPUTER_SERVER_CLASS = 0x08, /**< Server minor device class of computer */ - BT_MINOR_DEVICE_CLASS_COMPUTER_LAPTOP = 0x0C, /**< Laptop minor device class of computer */ - BT_MINOR_DEVICE_CLASS_COMPUTER_HANDHELD_PC_OR_PDA = 0x10, /**< Handheld PC/PDA minor device class of computer */ - BT_MINOR_DEVICE_CLASS_COMPUTER_PALM_SIZED_PC_OR_PDA = 0x14, /**< Palm sized PC/PDA minor device class of computer */ - BT_MINOR_DEVICE_CLASS_COMPUTER_WEARABLE_COMPUTER = 0x18, /**< Wearable(watch sized) minor device class of computer */ - - BT_MINOR_DEVICE_CLASS_PHONE_UNCATEGORIZED = 0x00, /**< Uncategorized minor device class of phone */ - BT_MINOR_DEVICE_CLASS_PHONE_CELLULAR = 0x04, /**< Cellular minor device class of phone */ - BT_MINOR_DEVICE_CLASS_PHONE_CORDLESS = 0x08, /**< Cordless minor device class of phone */ - BT_MINOR_DEVICE_CLASS_PHONE_SMART_PHONE = 0x0C, /**< Smart phone minor device class of phone */ - BT_MINOR_DEVICE_CLASS_PHONE_WIRED_MODEM_OR_VOICE_GATEWAY = 0x10, /**< Wired modem or voice gateway minor device class of phone */ - BT_MINOR_DEVICE_CLASS_PHONE_COMMON_ISDN_ACCESS = 0x14, /**< Common ISDN minor device class of phone */ - - BT_MINOR_DEVICE_CLASS_LAN_NETWORK_ACCESS_POINT_FULLY_AVAILABLE = 0x04, /**< Fully available minor device class of LAN/Network access point */ - BT_MINOR_DEVICE_CLASS_LAN_NETWORK_ACCESS_POINT_1_TO_17_PERCENT_UTILIZED = 0x20, /**< 1-17% utilized minor device class of LAN/Network access point */ - BT_MINOR_DEVICE_CLASS_LAN_NETWORK_ACCESS_POINT_17_TO_33_PERCENT_UTILIZED = 0x40, /**< 17-33% utilized minor device class of LAN/Network access point */ - BT_MINOR_DEVICE_CLASS_LAN_NETWORK_ACCESS_POINT_33_TO_50_PERCENT_UTILIZED = 0x60, /**< 33-50% utilized minor device class of LAN/Network access point */ - BT_MINOR_DEVICE_CLASS_LAN_NETWORK_ACCESS_POINT_50_to_67_PERCENT_UTILIZED = 0x80, /**< 50-67% utilized minor device class of LAN/Network access point */ - BT_MINOR_DEVICE_CLASS_LAN_NETWORK_ACCESS_POINT_67_TO_83_PERCENT_UTILIZED = 0xA0, /**< 67-83% utilized minor device class of LAN/Network access point */ - BT_MINOR_DEVICE_CLASS_LAN_NETWORK_ACCESS_POINT_83_TO_99_PERCENT_UTILIZED = 0xC0, /**< 83-99% utilized minor device class of LAN/Network access point */ - BT_MINOR_DEVICE_CLASS_LAN_NETWORK_ACCESS_POINT_NO_SERVICE_AVAILABLE = 0xE0, /**< No service available minor device class of LAN/Network access point */ - - BT_MINOR_DEVICE_CLASS_AUDIO_VIDEO_UNCATEGORIZED = 0x00, /**< Uncategorized minor device class of audio/video */ - BT_MINOR_DEVICE_CLASS_AUDIO_VIDEO_WEARABLE_HEADSET = 0x04, /**< Wearable headset minor device class of audio/video */ - BT_MINOR_DEVICE_CLASS_AUDIO_VIDEO_HANDS_FREE = 0x08, /**< Hands-free minor device class of audio/video */ - BT_MINOR_DEVICE_CLASS_AUDIO_VIDEO_MICROPHONE = 0x10, /**< Microphone minor device class of audio/video */ - BT_MINOR_DEVICE_CLASS_AUDIO_VIDEO_LOUDSPEAKER = 0x14, /**< Loudspeaker minor device class of audio/video */ - BT_MINOR_DEVICE_CLASS_AUDIO_VIDEO_HEADPHONES = 0x18, /**< Headphones minor device class of audio/video */ - BT_MINOR_DEVICE_CLASS_AUDIO_VIDEO_PORTABLE_AUDIO = 0x1C, /**< Portable audio minor device class of audio/video */ - BT_MINOR_DEVICE_CLASS_AUDIO_VIDEO_CAR_AUDIO = 0x20, /**< Car audio minor device class of audio/video */ - BT_MINOR_DEVICE_CLASS_AUDIO_VIDEO_SET_TOP_BOX = 0x24, /**< Set-top box minor device class of audio/video */ - BT_MINOR_DEVICE_CLASS_AUDIO_VIDEO_HIFI_AUDIO_DEVICE = 0x28, /**< Hifi audio minor device class of audio/video */ - BT_MINOR_DEVICE_CLASS_AUDIO_VIDEO_VCR = 0x2C, /**< VCR minor device class of audio/video */ - BT_MINOR_DEVICE_CLASS_AUDIO_VIDEO_VIDEO_CAMERA = 0x30, /**< Video camera minor device class of audio/video */ - BT_MINOR_DEVICE_CLASS_AUDIO_VIDEO_CAMCORDER = 0x34, /**< Camcorder minor device class of audio/video */ - BT_MINOR_DEVICE_CLASS_AUDIO_VIDEO_VIDEO_MONITOR = 0x38, /**< Video monitor minor device class of audio/video */ - BT_MINOR_DEVICE_CLASS_AUDIO_VIDEO_VIDEO_DISPLAY_LOUDSPEAKER = 0x3C, /**< Video display and loudspeaker minor device class of audio/video */ - BT_MINOR_DEVICE_CLASS_AUDIO_VIDEO_VIDEO_CONFERENCING = 0x40, /**< Video conferencing minor device class of audio/video */ - BT_MINOR_DEVICE_CLASS_AUDIO_VIDEO_GAMING_TOY = 0x48, /**< Gaming/toy minor device class of audio/video */ - - BT_MINOR_DEVICE_CLASS_PERIPHERA_UNCATEGORIZED = 0x00, /**< Uncategorized minor device class of peripheral */ - BT_MINOR_DEVICE_CLASS_PERIPHERAL_KEY_BOARD = 0x40, /**< Key board minor device class of peripheral */ - BT_MINOR_DEVICE_CLASS_PERIPHERAL_POINTING_DEVICE = 0x80, /**< Pointing device minor device class of peripheral */ - BT_MINOR_DEVICE_CLASS_PERIPHERAL_COMBO_KEYBOARD_POINTING_DEVICE = 0xC0, /**< Combo keyboard or pointing device minor device class of peripheral */ - BT_MINOR_DEVICE_CLASS_PERIPHERAL_JOYSTICK = 0x04, /**< Joystick minor device class of peripheral */ - BT_MINOR_DEVICE_CLASS_PERIPHERAL_GAME_PAD = 0x08, /**< Game pad minor device class of peripheral */ - BT_MINOR_DEVICE_CLASS_PERIPHERAL_REMOTE_CONTROL = 0x0C, /**< Remote control minor device class of peripheral */ - BT_MINOR_DEVICE_CLASS_PERIPHERAL_SENSING_DEVICE = 0x10, /**< Sensing device minor device class of peripheral */ - BT_MINOR_DEVICE_CLASS_PERIPHERAL_DIGITIZER_TABLET = 0x14, /**< Digitizer minor device class of peripheral */ - BT_MINOR_DEVICE_CLASS_PERIPHERAL_CARD_READER = 0x18, /**< Card reader minor device class of peripheral */ - BT_MINOR_DEVICE_CLASS_PERIPHERAL_DIGITAL_PEN = 0x1C, /**< Digital pen minor device class of peripheral */ - BT_MINOR_DEVICE_CLASS_PERIPHERAL_HANDHELD_SCANNER = 0x20, /**< Handheld scanner minor device class of peripheral */ - BT_MINOR_DEVICE_CLASS_PERIPHERAL_HANDHELD_GESTURAL_INPUT_DEVICE = 0x24, /**< Handheld gestural input device minor device class of peripheral */ - - BT_MINOR_DEVICE_CLASS_IMAGING_DISPLAY = 0x10, /**< Display minor device class of imaging */ - BT_MINOR_DEVICE_CLASS_IMAGING_CAMERA = 0x20, /**< Camera minor device class of imaging */ - BT_MINOR_DEVICE_CLASS_IMAGING_SCANNER = 0x40, /**< Scanner minor device class of imaging */ - BT_MINOR_DEVICE_CLASS_IMAGING_PRINTER = 0x80, /**< Printer minor device class of imaging */ - - BT_MINOR_DEVICE_CLASS_WEARABLE_WRIST_WATCH = 0x04, /**< Wrist watch minor device class of wearable */ - BT_MINOR_DEVICE_CLASS_WEARABLE_PAGER = 0x08, /**< Pager minor device class of wearable */ - BT_MINOR_DEVICE_CLASS_WEARABLE_JACKET = 0x0C, /**< Jacket minor device class of wearable */ - BT_MINOR_DEVICE_CLASS_WEARABLE_HELMET = 0x10, /**< Helmet minor device class of wearable */ - BT_MINOR_DEVICE_CLASS_WEARABLE_GLASSES = 0x14, /**< Glasses minor device class of wearable */ - - BT_MINOR_DEVICE_CLASS_TOY_ROBOT = 0x04, /**< Robot minor device class of toy */ - BT_MINOR_DEVICE_CLASS_TOY_VEHICLE = 0x08, /**< Vehicle minor device class of toy */ - BT_MINOR_DEVICE_CLASS_TOY_DOLL_ACTION = 0x0C, /**< Doll/Action minor device class of toy */ - BT_MINOR_DEVICE_CLASS_TOY_CONTROLLER = 0x10, /**< Controller minor device class of toy */ - BT_MINOR_DEVICE_CLASS_TOY_GAME = 0x14, /**< Game minor device class of toy */ - - BT_MINOR_DEVICE_CLASS_HEATH_UNCATEGORIZED = 0x00, /**< Uncategorized minor device class of health */ - BT_MINOR_DEVICE_CLASS_HEATH_BLOOD_PRESSURE_MONITOR = 0x04, /**< Blood pressure monitor minor device class of health */ - BT_MINOR_DEVICE_CLASS_HEATH_THERMOMETER = 0x08, /**< Thermometer minor device class of health */ - BT_MINOR_DEVICE_CLASS_HEATH_WEIGHING_SCALE = 0x0C, /**< Weighing scale minor device class of health */ - BT_MINOR_DEVICE_CLASS_HEATH_GLUCOSE_METER = 0x10, /**< Glucose minor device class of health */ - BT_MINOR_DEVICE_CLASS_HEATH_PULSE_OXIMETER = 0x14, /**< Pulse oximeter minor device class of health */ - BT_MINOR_DEVICE_CLASS_HEATH_HEART_PULSE_RATE_MONITOR = 0x18, /**< Heart/Pulse rate monitor minor device class of health */ - BT_MINOR_DEVICE_CLASS_HEATH_DATA_DISPLAY = 0x1C, /**< Health data display minor device class of health */ - BT_MINOR_DEVICE_CLASS_HEATH_STEP_COUNTER = 0x20, /**< Step counter minor device class of health */ - BT_MINOR_DEVICE_CLASS_HEATH_BODY_COMPOSITION_ANALYZER = 0x24, /**< Body composition analyzer minor device class of health */ - BT_MINOR_DEVICE_CLASS_HEATH_PEAK_FLOW_MONITOR = 0x28, /**< Peak flow monitor minor device class of health */ - BT_MINOR_DEVICE_CLASS_HEATH_MEDICATION_MONITOR = 0x2C, /**< Medication monitor minor device class of health */ - BT_MINOR_DEVICE_CLASS_HEATH_KNEE_PROSTHESIS = 0x30, /**< Knee prosthesis minor device class of health */ - BT_MINOR_DEVICE_CLASS_HEATH_ANKLE_PROSTHESIS = 0x34, /**< Ankle prosthesis minor device class of health */ -} bt_minor_device_class_e; - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_PAN_PANU_MODULE - * @brief Enumerations for the types of PAN(Personal Area Networking) service - */ -typedef enum { - BT_PANU_SERVICE_TYPE_NAP = 0, /**< Network Access Point */ -} bt_panu_service_type_e; - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_MODULE - * @brief Enumerations for the types of profiles related with audio - */ -typedef enum { - BT_AUDIO_PROFILE_TYPE_ALL = 0, /**< All supported profiles related with audio */ - BT_AUDIO_PROFILE_TYPE_HSP_HFP, /**< HSP(Headset Profile) and HFP(Hands-Free Profile) */ - BT_AUDIO_PROFILE_TYPE_A2DP, /**< A2DP(Advanced Audio Distribution Profile) */ -} bt_audio_profile_type_e; - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE - * @brief Enumerations for the equalizer state - */ -typedef enum { - BT_AVRCP_EQUALIZER_STATE_OFF = 0x01, /**< Equalizer Off */ - BT_AVRCP_EQUALIZER_STATE_ON, /**< Equalizer On */ -} bt_avrcp_equalizer_state_e; - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE - * @brief Enumerations for the repeat mode - */ -typedef enum { - BT_AVRCP_REPEAT_MODE_OFF = 0x01, /**< Repeat Off */ - BT_AVRCP_REPEAT_MODE_SINGLE_TRACK, /**< Single track repeat */ - BT_AVRCP_REPEAT_MODE_ALL_TRACK, /**< All track repeat */ - BT_AVRCP_REPEAT_MODE_GROUP, /**< Group repeat */ -} bt_avrcp_repeat_mode_e; - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE - * @brief Enumerations for the shuffle mode - */ -typedef enum { - BT_AVRCP_SHUFFLE_MODE_OFF = 0x01, /**< Shuffle Off */ - BT_AVRCP_SHUFFLE_MODE_ALL_TRACK, /**< All tracks shuffle */ - BT_AVRCP_SHUFFLE_MODE_GROUP, /**< Group shuffle */ -} bt_avrcp_shuffle_mode_e; - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE - * @brief Enumerations for the scan mode - */ -typedef enum { - BT_AVRCP_SCAN_MODE_OFF = 0x01, /**< Scan Off */ - BT_AVRCP_SCAN_MODE_ALL_TRACK, /**< All tracks scan */ - BT_AVRCP_SCAN_MODE_GROUP, /**< Group scan */ -} bt_avrcp_scan_mode_e; - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE - * @brief Enumerations for the player state - */ -typedef enum { - BT_AVRCP_PLAYER_STATE_STOPPED = 0x00, /**< Stopped */ - BT_AVRCP_PLAYER_STATE_PLAYING, /**< Playing */ - BT_AVRCP_PLAYER_STATE_PAUSED, /**< Paused */ - BT_AVRCP_PLAYER_STATE_FORWARD_SEEK, /**< Seek Forward */ - BT_AVRCP_PLAYER_STATE_REWIND_SEEK, /**< Seek Rewind */ -} bt_avrcp_player_state_e; - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_HDP_MODULE - * @brief Enumerations for the data channel type - */ -typedef enum { - BT_HDP_CHANNEL_TYPE_RELIABLE = 0x01, /**< Reliable Data Channel */ - BT_HDP_CHANNEL_TYPE_STREAMING, /**< Streaming Data Channel */ -} bt_hdp_channel_type_e; - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE - * @brief Class structure of device and service. - * - * @see #bt_device_info_s - * @see #bt_adapter_device_discovery_info_s - * @see bt_device_bond_created_cb() - * @see bt_adapter_device_discovery_state_changed_cb() - */ -typedef struct -{ - bt_major_device_class_e major_device_class; /**< Major device class. */ - bt_minor_device_class_e minor_device_class; /**< Minor device class. */ - int major_service_class_mask; /**< Major service class mask. - This value can be a combination of #bt_major_service_class_e like #BT_MAJOR_SERVICE_CLASS_RENDERING | #BT_MAJOR_SERVICE_CLASS_AUDIO */ -} bt_class_s; - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE - * @brief Structure of device discovery information. - * - * @see #bt_class_s - * @see bt_adapter_device_discovery_state_changed_cb() - */ -typedef struct -{ - char *remote_address; /**< The address of remote device */ - char *remote_name; /**< The name of remote device */ - bt_class_s bt_class; /**< The Bluetooth classes */ - int rssi; /**< The strength indicator of received signal */ - bool is_bonded; /**< The bonding state */ - char **service_uuid; /**< The UUID list of service */ - int service_count; /**< The number of services */ -} bt_adapter_device_discovery_info_s; - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE - * @brief Device information structure used for identifying pear device. - * - * @see #bt_class_s - * @see bt_device_bond_created_cb() - */ -typedef struct -{ - char *remote_address; /**< The address of remote device */ - char *remote_name; /**< The name of remote device */ - bt_class_s bt_class; /**< The Bluetooth classes */ - char **service_uuid; /**< The UUID list of service */ - int service_count; /**< The number of services */ - bool is_bonded; /**< The bonding state */ - bool is_connected; /**< The connection state */ - bool is_authorized; /**< The authorization state */ -} bt_device_info_s; - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE - * @brief Service Discovery Protocol (SDP) data structure. - * - * @details This protocol is used for discovering available services or pear device, - * and finding one to connect with. - * - * @see bt_device_service_searched_cb() - */ -typedef struct -{ - char *remote_address; /**< The address of remote device */ - char **service_uuid; /**< The UUID list of service */ - int service_count; /**< The number of services. */ -} bt_device_sdp_info_s; - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE - * - * @brief Rfcomm connection data used for exchanging data between Bluetooth devices. - * - * @see bt_socket_connection_state_changed_cb() - */ -typedef struct -{ - int socket_fd; /**< The file descriptor of connected socket */ - bt_socket_role_e local_role; /**< The local device role in this connection */ - char *remote_address; /**< The remote device address */ - char *service_uuid; /**< The service UUId */ -} bt_socket_connection_s; - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE - * - * @brief Structure of RFCOMM received data. - * - * @remarks User can use standard linux functions for reading/writing - * data from/to sockets. - * - * @see bt_socket_data_received_cb() - */ -typedef struct -{ - int socket_fd; /**< The socket fd */ - int data_size; /**< The length of the received data */ - char *data; /**< The received data */ -} bt_socket_received_data_s; - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE - * @brief Called when the Bluetooth adapter state changes. - * @param[in] result The result of the adapter state changing - * @param[in] adapter_state The adapter state to be changed - * @param[in] user_data The user data passed from the callback registration function - * @pre Either bt_adapter_enable() or bt_adapter_disable() will invoke this callback if you register this callback using bt_adapter_set_state_changed_cb(). - * @see bt_adapter_enable() - * @see bt_adapter_disable() - * @see bt_adapter_set_state_changed_cb() - * @see bt_adapter_unset_state_changed_cb() - */ -typedef void (*bt_adapter_state_changed_cb)(int result, bt_adapter_state_e adapter_state, void *user_data); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE - * @brief Called when adapter name changes. - * @param[in] device_name The name of the Bluetooth device to be changed - * @param[in] user_data The user data passed from the callback registration function - * @pre This function will be invoked when the name of Bluetooth adapter changes - * if you register this callback using bt_adapter_set_name_changed_cb(). - * @see bt_adapter_set_name() - * @see bt_adapter_set_name_changed_cb() - * @see bt_adapter_unset_name_changed_cb() - */ -typedef void (*bt_adapter_name_changed_cb)(char *device_name, void *user_data); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE - * @brief Called when the visibility mode changes. - * @param[in] result The result of the visibility mode changing - * @param[in] visibility_mode The visibility mode to be changed - * @param[in] user_data The user data passed from the callback registration function - * - * @pre This function will be invoked when the visibility of Bluetooth adapter changes - * if you register this callback using bt_adapter_set_visibility_mode_changed_cb(). - * - * @see bt_adapter_set_visibility() - * @see bt_adapter_set_visibility_mode_changed_cb() - * @see bt_adapter_unset_visibility_mode_changed_cb() - */ -typedef void (*bt_adapter_visibility_mode_changed_cb) - (int result, bt_adapter_visibility_mode_e visibility_mode, void *user_data); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE - * @brief Called when the state of device discovery changes. - * - * @remarks If \a discovery_state is #BT_ADAPTER_DEVICE_DISCOVERY_FOUND, - * then you can get some information, such as remote device address, remote device name, rssi, and bonding state. - * - * @param[in] result The result of the device discovery - * @param[in] discovery_state The discovery state to be changed - * @param[in] device_info The information of the discovered device \n - * If \a discovery_state is #BT_ADAPTER_DEVICE_DISCOVERY_STARTED or - * #BT_ADAPTER_DEVICE_DISCOVERY_FINISHED, then \a device_info is NULL. - * @param[in] user_data The user data passed from the callback registration function - * - * @pre Either bt_adapter_start_device_discovery() or bt_adapter_stop_device_discovery() will invoke this function - * if you register this callback using bt_adapter_set_device_discovery_state_changed_cb(). - * - * @see bt_adapter_start_device_discovery() - * @see bt_adapter_stop_device_discovery() - * @see bt_adapter_set_device_discovery_state_changed_cb() - * @see bt_adapter_unset_device_discovery_state_changed_cb() - * - */ -typedef void (*bt_adapter_device_discovery_state_changed_cb) - (int result, bt_adapter_device_discovery_state_e discovery_state, bt_adapter_device_discovery_info_s *discovery_info, void *user_data); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE - * @brief Called when you get bonded devices repeatedly. - * - * @param[in] device_info The bonded device information - * @param[in] user_data The user data passed from the foreach function - * @return @c true to continue with the next iteration of the loop, - * \n @c false to break out of the loop. - * @pre bt_adapter_foreach_bonded_device() will invoke this function. - * - * @see bt_adapter_foreach_bonded_device() - * - */ -typedef bool (*bt_adapter_bonded_device_cb)(bt_device_info_s *device_info, void *user_data); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE - * @brief Called when the process of creating bond finishes. - * @remarks If the remote user does not respond within 60 seconds, a time out will happen with #BT_ERROR_TIMED_OUT result code.\n - * If bt_device_cancel_bonding() is called and it returns #BT_ERROR_NONE, then this callback function will be called - * with #BT_ERROR_CANCELLED result. \n - * If creating a bond succeeds but service search fails, then this callback will be called with #BT_ERROR_SERVICE_SEARCH_FAILED. - * In this case, you should try service search again by bt_device_start_service_search() to get the supported service list. - * - * @param[in] result The result of the bonding device - * @param[in] device_info The device information which you creates bond with - * @param[in] user_data The user data passed from the callback registration function - * - * @pre Either bt_device_create_bond() will invoke this function - * if you register this callback using bt_device_set_bond_created_cb(). - * - * @see bt_device_create_bond() - * @see bt_device_cancel_bonding() - * @see bt_device_set_bond_created_cb() - * @see bt_device_unset_bond_created_cb() - */ -typedef void (*bt_device_bond_created_cb)(int result, bt_device_info_s *device_info, void *user_data); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE - * @brief Called when the bond destroys. - * @param[in] result The result that a bond is destroyed - * @param[in] remote_address The address of the remote Bluetooth device to destroy bond with - * @param[in] user_data The user data passed from the callback registration function - * @pre bt_device_destroy_bond() will invoke this function - * if you register this callback using bt_device_set_bond_destroyed_cb(). - * - * @see bt_device_destroy_bond() - * @see bt_device_set_bond_destroyed_cb() - * @see bt_device_unset_bond_destroyed_cb() - */ -typedef void (*bt_device_bond_destroyed_cb)(int result, char *remote_address, void *user_data); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE - * @brief Called when the authorization of device changes. - * @param[in] authorization The authorization of device - * @param[in] remote_address The address of the remote Bluetooth device which is (un)authorized - * @param[in] user_data The user data passed from the callback registration function - * @pre bt_device_set_authorization() will invoke this function if you register this callback using bt_device_set_authorization_changed_cb(). - * - * @see bt_device_set_authorization() - * @see #bt_device_set_authorization_changed_cb() - * @see #bt_device_unset_authorization_changed_cb() - */ -typedef void (*bt_device_authorization_changed_cb) - (bt_device_authorization_e authorization, char *remote_address, void *user_data); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE - * @brief Called when the process of service search finishes. - * @remark If bt_device_cancel_service_search() is called and it returns #BT_ERROR_NONE, - * then this callback function will be called with #BT_ERROR_CANCELLED result. - * - * @param[in] result The result of the service searching - * @param[in] sdp_info The structure of service lists found on a device - * @param[in] user_data The user data passed from the callback registration function - * @pre Either bt_device_start_service_search() will invoke this function - * if you register this callback using bt_device_set_service_searched_cb(). - * - * @see bt_device_start_service_search() - * @see bt_device_cancel_service_search() - * @see bt_device_set_service_searched_cb() - * @see bt_device_unset_service_searched_cb() - * - */ -typedef void (*bt_device_service_searched_cb)(int result, bt_device_sdp_info_s *sdp_info, void *user_data); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE - * @brief Called when you receive data. - * - * @param[in] data The received data from the remote device - * @param[in] user_data The user data passed from the callback registration function - * - * @pre When the connected remote Bluetooth device invokes bt_socket_send_data(), - * this function will be invoked if you register this function using bt_socket_set_data_received_cb(). - * - * @see bt_socket_set_data_received_cb() - * @see bt_socket_unset_data_received_cb() - * @see bt_socket_send_data() - */ -typedef void (*bt_socket_data_received_cb)(bt_socket_received_data_s *data, void *user_data); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE - * @brief Called when the socket connection state changes. - * @remarks This function won't be invoked when you call bt_socket_disconnect_rfcomm(), which is synchronous function. - * - * @param[in] result The result of connection state changing - * @param[in] connection_state The connection state - * @param[in] connection The connection information which is established or disconnected - * @param[in] user_data The user data passed from the callback registration function - * @pre Either bt_socket_listen_and_accept_rfcomm() or bt_socket_connect_rfcomm() will invoke this function - * if you register this callback using bt_socket_set_connection_state_changed_cb(). \n - * If the remote Bluetooth device is connected when bt_socket_destroy_rfcomm() is called, then bt_socket_connection_state_changed_cb() will be invoked. - * - * @see bt_socket_listen_and_accept_rfcomm() - * @see bt_socket_connect_rfcomm() - * @see bt_socket_set_connection_state_changed_cb() - * @see bt_socket_unset_connection_state_changed_cb() - */ -typedef void (*bt_socket_connection_state_changed_cb) - (int result, bt_socket_connection_state_e connection_state, bt_socket_connection_s *connection, void *user_data); - - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_MODULE - * @brief Initializes the Bluetooth API. - * - * @remarks This function must be called before Bluetooth API starts. \n - * You must free all resources of the Bluetooth service by calling bt_deinitialize() if Bluetooth service is no longer needed. - * - * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_OPERATION_FAILED Operation failed - * - * @see bt_deinitialize() - */ -int bt_initialize(void); - - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_MODULE - * @brief Releases all resources of the Bluetooth API. - * - * @remarks This function must be called if Bluetooth API is no longer needed. - * - * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_OPERATION_FAILED Operation failed - * - * @pre Bluetooth API must be initialized with bt_initialize(). - * - * @see bt_initialize() - */ -int bt_deinitialize(void); - - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE - * @brief Enables the local Bluetooth adapter, asynchronously. - * - * @details This function enables Bluetooth protocol stack and hardware. - * - * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_ALREADY_DONE Already enabled - * @retval #BT_ERROR_NOW_IN_PROGRESS Operation now in progress - * - * @pre Bluetooth service must be initialized with bt_initialize(). - * @post This function invokes bt_adapter_state_changed_cb(). - * - * @see bt_initialize() - * @see bt_adapter_get_state() - * @see bt_adapter_disable() - * @see bt_adapter_set_state_changed_cb() - * @see bt_adapter_unset_state_changed_cb() - * @see bt_adapter_state_changed_cb() - * - */ -int bt_adapter_enable(void); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE - * @brief Disables the local Bluetooth adapter, asynchronously. - * - * @details This function disables Bluetooth protocol stack and hardware. - * - * @remarks You should disable Bluetooth adapter to switch off Bluetooth chip, which is helpful for saving power. - * - * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_NOT_ENABLED Not enabled - * @retval #BT_ERROR_NOW_IN_PROGRESS Operation now in progress - * - * @pre Bluetooth API must be enabled with bt_adapter_enable(). - * @post This function invokes bt_adapter_state_changed_cb(). - * - * @see bt_adapter_get_state() - * @see bt_adapter_enable() - * @see bt_adapter_state_changed_cb() - * @see bt_adapter_set_state_changed_cb() - * @see bt_adapter_unset_state_changed_cb () - * - */ -int bt_adapter_disable(void); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE - * @brief Gets the current state of local Bluetooth adapter. - * - * @param[out] adapter_state The current adapter state - * - * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter - * - * @pre Bluetooth service must be initialized with bt_initialize(). - * - * @see bt_initialize() - * @see bt_adapter_enable() - * @see bt_adapter_disable() - */ -int bt_adapter_get_state(bt_adapter_state_e *adapter_state); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE - * @brief Gets the address of local Bluetooth adapter. - * - * @remarks The @a local_address must be released with free() by you. - * - * @param[out] local_address The device address of local Bluetooth adapter - * - * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #BT_ERROR_NOT_ENABLED Not enabled - * @retval #BT_ERROR_OUT_OF_MEMORY Out of memory - * @retval #BT_ERROR_OPERATION_FAILED Operation failed - * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED with bt_adapter_enable(). - * @see bt_adapter_enable() - * @see bt_adapter_get_name() - */ -int bt_adapter_get_address(char **local_address); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE - * @brief Gets the name of local Bluetooth adapter. - * - * @details Use this function to get the friendly name associated with Bluetooth - * device, retrieved by the remote Bluetooth devices. - * - * @remarks The @a local_name must be released with free() by you. - * - * @param[out] local_name The local device name - * - * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #BT_ERROR_NOT_ENABLED Not enabled - * @retval #BT_ERROR_OUT_OF_MEMORY Out of memory - * @retval #BT_ERROR_OPERATION_FAILED Operation failed - * - * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED with bt_adapter_enable(). - * - * @see bt_adapter_enable() - * @see bt_adapter_set_name() - */ -int bt_adapter_get_name(char **local_name); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE - * @brief Sets the name of local Bluetooth adapter. - * - * @param[in] local_name The name of the Bluetooth device. \n - * The maximum length is 248 characters. - * - * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #BT_ERROR_NOT_ENABLED Not enabled - * @retval #BT_ERROR_OPERATION_FAILED Operation failed - * - * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED with bt_adapter_enable(). - * @post bt_adapter_name_changed_cb() will be invoked if this function returns #BT_ERROR_NONE. - * - * @see bt_adapter_enable() - * @see bt_adapter_get_name() - * @see bt_adapter_name_changed_cb() - * @see bt_adapter_set_name_changed_cb() - * @see bt_adapter_unset_name_changed_cb() - */ -int bt_adapter_set_name(const char *local_name); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE - * @brief Gets the visibility mode of local Bluetooth adapter. - * - * @param[out] mode The visibility mode of the Bluetooth device - * - * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #BT_ERROR_NOT_ENABLED Not enabled - * @retval #BT_ERROR_OPERATION_FAILED Operation failed - * - * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED with bt_adapter_enable(). - * - * @see bt_adapter_enable() - * @see bt_adapter_set_visibility() - */ -int bt_adapter_get_visibility(bt_adapter_visibility_mode_e *mode); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE - * @brief Sets the visibility mode. - * - * @remarks #BT_ADAPTER_VISIBILITY_MODE_LIMITED_DISCOVERABLE will change to #BT_ADAPTER_VISIBILITY_MODE_NON_DISCOVERABLE - * after the given @a timeout_sec goes. - * - * @param[in] discoverable_mode The Bluetooth discoverable mode to set - * @param[in] timeout_sec The discoverable time duration (in seconds) - * @a timeout_sec is used only for #BT_ADAPTER_VISIBILITY_MODE_LIMITED_DISCOVERABLE mode. - * - * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_NOT_ENABLED Not enabled - * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #BT_ERROR_OPERATION_FAILED Operation failed - * - * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED with bt_adapter_enable(). - * @post bt_adapter_visibility_mode_changed_cb() will be invoked if this function returns #BT_ERROR_NONE. - * - * @see bt_adapter_enable() - * @see bt_adapter_get_visibility() - * @see bt_adapter_visibility_mode_changed_cb() - * @see bt_adapter_set_visibility_mode_changed_cb() - * @see bt_adapter_unset_visibility_mode_changed_cb() - */ -int bt_adapter_set_visibility(bt_adapter_visibility_mode_e discoverable_mode, int timeout_sec); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE - * @brief Starts the device discovery, asynchronously. - * - * @details If a device is discovered, bt_adapter_device_discovery_state_changed_cb() will be invoked - * with #BT_ADAPTER_DEVICE_DISCOVERY_FOUND, and then bt_adapter_device_discovery_state_changed_cb() - * will be called with #BT_ADAPTER_DEVICE_DISCOVERY_FINISHED in case of the completion or cancellation of the discovery. - * - * @remarks To connect to peer Bluetooth device, you need to know its Bluetooth address. \n - * The device discovery can be stopped by bt_adapter_stop_device_discovery(). - * - * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_NOT_ENABLED Not enabled - * @retval #BT_ERROR_NOW_IN_PROGRESS Operation is now in progress - * @retval #BT_ERROR_OPERATION_FAILED Operation failed - * - * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED with bt_adapter_enable(). - * @post This function invokes bt_adapter_device_discovery_state_changed_cb(). - * - * @see bt_adapter_enable() - * @see bt_adapter_is_discovering() - * @see bt_adapter_stop_device_discovery() - * @see bt_adapter_device_discovery_state_changed_cb() - * @see bt_adapter_set_device_discovery_state_changed_cb() - * @see bt_adapter_unset_device_discovery_state_changed_cb() - */ -int bt_adapter_start_device_discovery(void); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE - * @brief Stops the device discovery, asynchronously. - * @remarks The device discovery process will take 10 ~ 20 seconds to get all the devices in vicinity. - * - * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_NOT_ENABLED Not enabled - * @retval #BT_ERROR_NOT_IN_PROGRESS Operation is not in progress - * @retval #BT_ERROR_OPERATION_FAILED Operation failed - * - * @pre The device discovery must be in progress with bt_adapter_start_device_discovery(). - * @post This function invokes bt_adapter_device_discovery_state_changed_cb(). - * - * @see bt_adapter_is_discovering() - * @see bt_adapter_start_device_discovery() - * @see bt_adapter_set_device_discovery_state_changed_cb() - * @see bt_adapter_unset_device_discovery_state_changed_cb() - * @see bt_adapter_device_discovery_state_changed_cb() - */ -int bt_adapter_stop_device_discovery(void); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE - * @brief Checks for the device discovery is in progress or not. - * - * @remarks If Bluetooth discovery is in progress, other operations are not allowed and - * you have to either stop the discovery operation, or wait for it to be finished, - * before performing other operations. - - * @param[out] is_discovering The discovering status: (@c true = in progress , @c false = not in progress ) - * - * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #BT_ERROR_NOT_ENABLED Not enabled - * @retval #BT_ERROR_OPERATION_FAILED Operation failed - * - * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED with bt_adapter_enable(). - * - * @see bt_adapter_enable() - * @see bt_adapter_start_device_discovery() - * @see bt_adapter_stop_device_discovery() - */ -int bt_adapter_is_discovering(bool *is_discovering); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE - * @brief Retrieves the device information of all bonded devices. - * - * @param [in] callback The callback function to invoke - * @param [in] user_data The user data passed from the foreach function - * - * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #BT_ERROR_OUT_OF_MEMORY Out of memory - * @retval #BT_ERROR_NOT_ENABLED Not enabled - * @retval #BT_ERROR_OPERATION_FAILED Operation failed - * - * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED with bt_adapter_enable(). - * @post This function invokes bt_adapter_bonded_device_cb(). - * - * @see bt_adapter_bonded_device_cb() - * @see bt_adapter_enable() - */ -int bt_adapter_foreach_bonded_device(bt_adapter_bonded_device_cb callback, void *user_data); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE - * @brief Gets the device information of a bonded device. - * @remarks The @a device_info must be released with bt_adapter_free_device_info() by you . - * - * @param [in] remote_address The address of remote device - * @param [out] device_info The bonded device information - * - * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #BT_ERROR_OUT_OF_MEMORY Out of memory - * @retval #BT_ERROR_NOT_ENABLED Not enabled - * @retval #BT_ERROR_OPERATION_FAILED Operation failed - * @retval #BT_ERROR_REMOTE_DEVICE_NOT_BONDED Remote device not bonded - * - * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED with bt_adapter_enable(). - * @post This function invokes bt_adapter_bonded_device_cb(). - * - * @see bt_adapter_bonded_device_cb() - * @see bt_adapter_enable() - */ -int bt_adapter_get_bonded_device_info(const char *remote_address, bt_device_info_s **device_info); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE - * @brief Frees device info. - * - * @param [in] device_info The bonded device information - * - * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter - * - * @see bt_adapter_get_bonded_device_info() - */ -int bt_adapter_free_device_info(bt_device_info_s *device_info); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE - * @brief Checks whether the UUID of service is used or not - * @param[in] service_uuid The UUID of service - * @param[out] used Indicates whether the service is used or not - * @return true on success, otherwise false. - * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #BT_ERROR_NOT_ENABLED Not enabled - * @retval #BT_ERROR_OPERATION_FAILED Operation failed - * @see bt_adapter_enable() - */ -int bt_adapter_is_service_used(const char *service_uuid, bool *used); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE - * @brief Registers a callback function to be invoked when the Bluetooth adapter state changes. - * - * @param[in] callback The callback function to invoke - * @param[in] user_data The user data to be passed to the callback function - * - * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter - * - * @pre The Bluetooth service must be initialized with bt_initialize(). - * @post bt_adapter_state_changed_cb() will be invoked. - * - * @see bt_initialize() - * @see bt_adapter_state_changed_cb() - * @see bt_adapter_set_state_changed_cb() - * @see bt_adapter_unset_state_changed_cb() - */ -int bt_adapter_set_state_changed_cb(bt_adapter_state_changed_cb callback, void *user_data); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE - * @brief Unregisters the callback function. - * - * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * - * @pre The Bluetooth service must be initialized with bt_initialize(). - * - * @see bt_initialize() - * @see bt_adapter_set_state_changed_cb() - */ -int bt_adapter_unset_state_changed_cb(void); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE - * @brief Registers a callback function to be invoked when the name of Bluetooth adapter changes. - * - * @param[in] callback The callback function to invoke - * @param[in] user_data The user data to be passed to the callback function - * - * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter - * - * @pre The Bluetooth service must be initialized with bt_initialize(). - * @post bt_adapter_name_changed_cb() will be invoked. - * - * @see bt_initialize() - * @see bt_adapter_name_changed_cb() - * @see bt_adapter_unset_name_changed_cb() - */ -int bt_adapter_set_name_changed_cb(bt_adapter_name_changed_cb callback, void *user_data); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE - * @brief Unregisters the callback function. - * - * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * - * @pre The Bluetooth service must be initialized with bt_initialize(). - * - * @see bt_initialize() - * @see bt_adapter_set_name_changed_cb() - */ -int bt_adapter_unset_name_changed_cb(void); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE - * @brief Registers a callback function to be invoked when the visibility mode changes. - * - * @param[in] callback The callback function to register - * @param[in] user_data The user data to be passed to the callback function - * - * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter - * - * @pre The Bluetooth service must be initialized with bt_initialize(). - * @post bt_adapter_visibility_mode_changed_cb() will be invoked. - * - * @see bt_initialize() - * @see bt_adapter_visibility_mode_changed_cb() - * @see bt_adapter_unset_visibility_mode_changed_cb() - */ -int bt_adapter_set_visibility_mode_changed_cb(bt_adapter_visibility_mode_changed_cb callback, void *user_data); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE - * @brief Unregisters the callback function. - * - * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * - * @pre The Bluetooth service must be initialized with bt_initialize(). - * - * @see bt_initialize() - * @see bt_adapter_set_visibility_mode_changed_cb() - */ -int bt_adapter_unset_visibility_mode_changed_cb(void); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE - * @brief Registers a callback function to be invoked when the device discovery state changes. - * - * @param[in] callback The callback function to register - * @param[in] user_data The user data to be passed to the callback function - * - * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter - * - * @pre The Bluetooth service must be initialized with bt_initialize(). - * @post bt_adapter_device_discovery_state_changed_cb() will be invoked. - * - * @see bt_initialize() - * @see bt_adapter_device_discovery_state_changed_cb() - * @see bt_adapter_set_device_discovery_state_changed_cb() - * @see bt_adapter_unset_device_discovery_state_changed_cb() - */ -int bt_adapter_set_device_discovery_state_changed_cb(bt_adapter_device_discovery_state_changed_cb callback, void *user_data); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE - * @brief Unregisters the callback function. - * - * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * - * @pre The Bluetooth service must be initialized with bt_initialize(). - * - * @see bt_initialize() - * @see bt_adapter_set_device_discovery_state_changed_cb() - */ -int bt_adapter_unset_device_discovery_state_changed_cb(void); - - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE - * @brief Creates a bond with a remote Bluetooth device, asynchronously. - * - * @remarks A bond can be destroyed by bt_device_destroy_bond().\n - * The bonding request can be cancelled by bt_device_cancel_bonding(). - * - * @param[in] remote_address The address of the remote Bluetooth device with which the bond should be created - * - * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #BT_ERROR_NOT_ENABLED Not enabled - * @retval #BT_ERROR_RESOURCE_BUSY Device or resource busy - * @retval #BT_ERROR_OPERATION_FAILED Operation failed - * - * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED with bt_adapter_enable() - * @pre The remote device must be discoverable with bt_adapter_start_device_discovery(). - * @post This function invokes bt_device_bond_created_cb(). - * - * @see bt_adapter_enable() - * @see bt_adapter_start_device_discovery() - * @see bt_device_bond_created_cb() - * @see bt_device_cancel_bonding() - * @see bt_device_destroy_bond() - * @see bt_device_set_bond_created_cb() - * @see bt_device_unset_bond_created_cb() - */ -int bt_device_create_bond(const char *remote_address); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE - * @brief Cancels the bonding process. - * - * @remakrs Use this function when the remote Bluetooth device is not responding to the - * bond request or you wish to cancel the bonding request. - * - * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_NOT_ENABLED Not enabled - * @retval #BT_ERROR_NOT_IN_PROGRESS Operation not in progress - * @pre The creating a bond must be in progress by bt_device_create_bond(). - * - * @see bt_device_create_bond() - * @see bt_device_bond_created_cb() - * @see bt_device_set_bond_created_cb() - * @see bt_device_unset_bond_created_cb() - */ -int bt_device_cancel_bonding(void); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE - * @brief Destroys the bond, asynchronously. - * - * @param[in] remote_address The address of the remote Bluetooth device to remove bonding - * - * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #BT_ERROR_NOT_ENABLED Not enabled - * @retval #BT_ERROR_RESOURCE_BUSY Device or resource busy - * @retval #BT_ERROR_REMOTE_DEVICE_NOT_BONDED Remote device not bonded - * @retval #BT_ERROR_OPERATION_FAILED Operation failed - * - * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED with bt_adapter_enable(). - * @pre The bond with the remote device must be created with bt_device_create_bond(). - * @post This function invokes bt_device_bond_destroyed_cb(). - * - * @see bt_adapter_enable() - * @see bt_device_create_bond() - * @see bt_device_bond_destroyed_cb() - * @see bt_device_set_bond_destroyed_cb() - * @see bt_device_unset_bond_destroyed_cb() - */ -int bt_device_destroy_bond(const char *remote_address); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE - * @brief Sets an alias for the bonded device. - * - * @param[in] remote_address The address of the remote Bluetooth device - * @param[in] alias The alias of the remote Bluetooth device - * - * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #BT_ERROR_NOT_ENABLED Not enabled - * @retval #BT_ERROR_REMOTE_DEVICE_NOT_BONDED Remote device not bonded - * @retval #BT_ERROR_OPERATION_FAILED Operation failed - * - * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED with bt_adapter_enable(). - * @pre The bond with the remote device must be created with bt_device_create_bond(). - * - * @see bt_adapter_enable() - * @see bt_device_create_bond() - */ -int bt_device_set_alias(const char *remote_address, const char *alias); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE - * @brief Sets the authorization of a bonded device, asynchronously. - * - * @remarks Once a device is authorized, you don't need to receive a confirmation. - * - * @param[in] remote_address The address of the remote Bluetooth device to authorize - * @param[in] authorization The Bluetooth authorization state - * - * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #BT_ERROR_NOT_ENABLED Not enabled - * @retval #BT_ERROR_REMOTE_DEVICE_NOT_BONDED Remote device not bonded - * @retval #BT_ERROR_OPERATION_FAILED Operation failed - * - * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED with bt_adapter_enable(). - * @pre The bond with the remote device must be created with bt_device_create_bond(). - * @post bt_device_authorization_changed_cb() will be invoked. - * - * @see bt_adapter_enable() - * @see bt_device_create_bond() - * @see bt_device_authorization_changed_cb() - * @see bt_device_set_authorization_changed_cb() - * @see bt_device_unset_authorization_changed_cb() - */ -int bt_device_set_authorization(const char *remote_address, bt_device_authorization_e authorization_state); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE - * @brief Starts the search for services supported by the specified device, asynchronously. - * - * @remarks If creating a bond succeeds, which means bt_device_bond_created_cb() is called with result #BT_ERROR_NONE, - * then you don't need to run this function.\n - * The service search takes a couple of seconds to complete normally. \n - * The service search can be canceled by bt_device_cancel_service_search(). - * - * @param[in] remote_address The address of the remote Bluetooth device whose services need to be checked - * - * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #BT_ERROR_NOT_ENABLED Not enabled - * @retval #BT_ERROR_REMOTE_DEVICE_NOT_BONDED Remote device not bonded - * @retval #BT_ERROR_SERVICE_SEARCH_FAILED Service search failed - * - * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED with bt_adapter_enable(). - * @pre The remote device must be discoverable with bt_adapter_start_device_discovery(). - * @pre The bond with the remote device must be created with bt_device_create_bond(). - * @post This function invokes bt_device_service_searched_cb(). - * - * @see bt_adapter_enable() - * @see bt_adapter_start_device_discovery() - * @see bt_device_create_bond() - * @see bt_device_bond_created_cb() - * @see bt_device_service_searched_cb() - * @see bt_device_cancel_service_search() - * @see bt_device_set_service_searched_cb() - * @see bt_device_unset_service_searched_cb() - */ -int bt_device_start_service_search(const char *remote_address); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE - * @brief Cancels service search process. - * - * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_NOT_ENABLED Not enabled - * @retval #BT_ERROR_REMOTE_DEVICE_NOT_BONDED Remote device not bonded - * @retval #BT_ERROR_NOT_IN_PROGRESS Operation not in progress - * @retval #BT_ERROR_OPERATION_FAILED Operation failed - * - * @pre The service search must be in progress by bt_device_start_service_search(). - * - * @see bt_device_start_service_search() - * @see bt_device_service_searched_cb() - * @see bt_device_set_service_searched_cb() - * @see bt_device_unset_service_searched_cb() - */ -int bt_device_cancel_service_search(void); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE - * @brief Registers a callback function to be invoked when the bond creates. - * @param[in] callback The callback function to register - * @param[in] user_data The user data to be passed to the callback function - * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter - * @pre The Bluetooth service must be initialized with bt_initialize(). - * @post bt_device_bond_created_cb() will be invoked. - * @see bt_initialize() - * @see bt_device_bond_created_cb() - * @see bt_device_unset_bond_created_cb() - */ -int bt_device_set_bond_created_cb(bt_device_bond_created_cb callback, void *user_data); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE - * @brief Unregisters the callback function. - * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @pre The Bluetooth service must be initialized with bt_initialize(). - * @see bt_initialize() - * @see bt_device_set_bond_created_cb() - */ -int bt_device_unset_bond_created_cb(void); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE - * @brief Registers a callback function to be invoked when the bond destroys. - * @param[in] callback The callback function to register - * @param[in] user_data The user data to be passed to the callback function - * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter - * @pre The Bluetooth service must be initialized with bt_initialize(). - * @post bt_device_bond_destroyed_cb() will be invoked. - * @see bt_initialize() - * @see bt_device_bond_destroyed_cb() - * @see bt_device_unset_bond_destroyed_cb() - */ -int bt_device_set_bond_destroyed_cb(bt_device_bond_destroyed_cb callback, void *user_data); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE - * @brief Unregisters the callback function. - * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @pre The Bluetooth service must be initialized with bt_initialize(). - * @see bt_initialize() - * @see bt_device_set_bond_destroyed_cb() - */ -int bt_device_unset_bond_destroyed_cb(void); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE - * @brief Registers a callback function to be invoked when the authorization of device changes. - * @param[in] callback The callback function to register - * @param[in] user_data The user data to be passed to the callback function - * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter - * @pre The Bluetooth service must be initialized with bt_initialize(). - * @post bt_device_authorization_changed_cb() will be invoked. - * @see bt_initialize() - * @see bt_device_authorization_changed_cb() - * @see bt_device_set_authorization_changed_cb() - * @see bt_device_unset_authorization_changed_cb() - */ -int bt_device_set_authorization_changed_cb(bt_device_authorization_changed_cb callback, void *user_data); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE - * @brief Unregisters the callback function. - * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @pre The Bluetooth service must be initialized with bt_initialize(). - * @see bt_initialize() - * @see bt_device_set_authorization_changed_cb() - */ -int bt_device_unset_authorization_changed_cb(void); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE - * @brief Registers a callback function to be invoked when the process of service search finishes. - * @param[in] callback The callback function to register - * @param[in] user_data The user data to be passed to the callback function - * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter - * @pre The Bluetooth service must be initialized with bt_initialize(). - * @post bt_device_service_searched_cb() will be invoked. - * @see bt_initialize() - * @see bt_device_service_searched_cb() - * @see bt_device_unset_service_searched_cb() - */ -int bt_device_set_service_searched_cb(bt_device_service_searched_cb callback, void *user_data); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE - * @brief Unregisters the callback function. - * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @pre The Bluetooth service must be initialized with bt_initialize(). - * @see bt_initialize() - * @see bt_device_set_service_searched_cb() - */ -int bt_device_unset_service_searched_cb(void); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE - * @brief Registers a rfcomm socket with a specific UUID. - * - * @remarks A socket can be destroyed by bt_socket_destroy_rfcomm(). - * - * @param[in] service_uuid The UUID of service to provide - * @param[out] socket_fd The file descriptor of socket to listen - * @return 0 on success, otherwise a negative error value. - * - * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #BT_ERROR_NOT_ENABLED Not enabled - * @retval #BT_ERROR_OPERATION_FAILED Operation failed - * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED with bt_adapter_enable(). - * - * @see bt_adapter_enable() - * @see bt_socket_listen_and_accept_rfcomm() - * @see bt_socket_destroy_rfcomm() - */ -int bt_socket_create_rfcomm(const char *service_uuid, int *socket_fd); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE - * @brief Removes the rfcomm socket with the given socket. - * - * @param[in] socket_fd The file descriptor of socket to destroy - * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #BT_ERROR_NOT_ENABLED Not enabled - * @retval #BT_ERROR_OPERATION_FAILED Operation failed - * - * @pre The socket must be created with bt_socket_create_rfcomm(). - * @post If callback function bt_socket_connection_state_changed_cb() is set and the remote Bluetooth device is connected, - * then bt_socket_connection_state_changed_cb() will be called. - * - * @see bt_socket_create_rfcomm() - * @see bt_socket_connection_state_changed_cb() - * @see bt_socket_set_connection_state_changed_cb() - * @see bt_socket_unset_connection_state_changed_cb() - */ -int bt_socket_destroy_rfcomm(int socket_fd); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE - * @brief Starts listening on passed rfcomm socket and accepts connection requests. - * @details Pop-up is shown automatically when a RFCOMM connection is requested. - * bt_socket_connection_state_changed_cb() will be called with - * #BT_SOCKET_CONNECTED if you click "yes" and connection is finished successfully. - * - * @param[in] socket_fd The file descriptor of socket on which start to listen - * @param[in] max_pending_connections The maximum number of pending connections - * - * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_NOT_ENABLED Not enabled - * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #BT_ERROR_OPERATION_FAILED Operation failed - * - * @pre The socket must be created with bt_socket_create_rfcomm(). - * @post This function invokes bt_socket_connection_state_changed_cb(). - * - * @see bt_socket_create_rfcomm() - * @see bt_socket_connection_state_changed_cb() - * @see bt_socket_set_connection_state_changed_cb() - * @see bt_socket_unset_connection_state_changed_cb() - */ -int bt_socket_listen_and_accept_rfcomm(int socket_fd, int max_pending_connections); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE - * @brief Called when a RFCOMM connection is requested. - * @details You must call bt_socket_accept() if you want to accept. Otherwise, you must call bt_socket_reject(). - * @param[in] socket_fd The file descriptor of socket on which a connection is requested - * @param[in] remote_address The address of remote device - * @param[in] user_data The user data passed from the callback registration function - * @pre If you register this callback function by bt_socket_set_connection_requested_cb() and listen a socket by bt_socket_listen(), - * bt_socket_connection_requested_cb() will be invoked. - * @see bt_socket_listen() - * @see bt_socket_accept() - * @see bt_socket_reject() - */ -typedef void (*bt_socket_connection_requested_cb) (int socket_fd, const char *remote_address, void *user_data); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE - * @brief Starts listening on passed rfcomm socket. - * @details bt_socket_connection_requested_cb() will be called when a RFCOMM connection is requested. - * - * @param[in] socket_fd The file descriptor socket on which start to listen - * @param[in] user_data The user data to be passed to the callback function - * - * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_NOT_ENABLED Not enabled - * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #BT_ERROR_OPERATION_FAILED Operation failed - * - * @pre The socket must be created with bt_socket_create_rfcomm(). - * @post This function invokes bt_socket_connection_state_changed_cb(). - * - * @see bt_socket_create_rfcomm() - * @see bt_socket_set_connection_requested_cb() - * @see bt_socket_unset_connection_requested_cb() - * @see bt_socket_connection_requested_cb() - */ -int bt_socket_listen(int socket_fd, int max_pending_connections); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE - * @brief Accepts a connection request. - * @param[in] requested_socket_fd The file descriptor of socket on which a connection is requested - * @param[out] connected_socket_fd The file descriptor of connected socket - * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_NOT_ENABLED Not enabled - * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #BT_ERROR_OPERATION_FAILED Operation failed - * @pre The connection is requested by bt_socket_connection_requested_cb(). - * @see bt_socket_create_rfcomm() - * @see bt_socket_connection_requested_cb() - * @see bt_socket_listen() - * @see bt_socket_reject() -*/ -int bt_socket_accept(int requested_socket_fd, int *connected_socket_fd); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE - * @brief Rejects a connection request. - * @param[in] socket_fd The file descriptor of socket on which a connection is requested - * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_NOT_ENABLED Not enabled - * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #BT_ERROR_OPERATION_FAILED Operation failed - * @pre The connection is requested by bt_socket_connection_requested_cb(). - * @see bt_socket_create_rfcomm() - * @see bt_socket_connection_requested_cb() - * @see bt_socket_listen() - * @see bt_socket_accept() - */ -int bt_socket_reject(int socket_fd); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE - * @brief Connects to a specific RFCOMM based service on a remote Bluetooth device UUID, asynchronously. - * - * @remarks A connection can be disconnected by bt_socket_disconnect_rfcomm(). - * - * @param[in] remote_address The address of the remote Bluetooth device - * @param[in] service_uuid The UUID of service provided by the remote Bluetooth device - * - * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #BT_ERROR_NOT_ENABLED Not enabled - * @retval #BT_ERROR_REMOTE_DEVICE_NOT_BONDED Remote device not bonded - * @retval #BT_ERROR_OPERATION_FAILED Operation failed - * - * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED with bt_adapter_enable(). - * @pre The remote device must be discoverable with bt_adapter_start_device_discovery(). - * @pre The bond with the remote device must be created with bt_device_create_bond(). - * @post This function invokes bt_socket_connection_state_changed_cb(). - * - * @see bt_adapter_enable() - * @see bt_device_create_bond() - * @see bt_adapter_start_device_discovery() - * @see bt_device_start_service_search() - * @see bt_socket_disconnect_rfcomm() - * @see bt_socket_connection_state_changed_cb() - * @see bt_socket_set_connection_state_changed_cb() - * @see bt_socket_unset_connection_state_changed_cb() - */ -int bt_socket_connect_rfcomm(const char *remote_address, const char *service_uuid); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE - * @brief Disconnects the RFCOMM connection with the given file descriptor of conneted socket. - * @remarks Because this function is synchronous, bt_socket_connection_state_changed_cb() won't be called - * @param[in] socket_fd The file descriptor of socket to close - * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_NOT_ENABLED Not enabled - * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter - * @pre The connection must be established. - */ -int bt_socket_disconnect_rfcomm(int socket_fd); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE - * @brief Sends data to the connected device. - * - * @param[in] socket_fd The file descriptor of connected socket - * @param[in] data The data to be sent - * @param[in] length The length of data to be sent - * - * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_NOT_ENABLED Not enabled - * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #BT_ERROR_OPERATION_FAILED Operation failed - * - * @pre The connection must be established. - */ -int bt_socket_send_data(int socket_fd, const char *data, int length); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE - * @brief Register a callback function that will be invoked when you receive data. - * @param[in] callback The callback function to register - * @param[in] user_data The user data to be passed to the callback function - * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter - * @pre The Bluetooth service must be initialized with bt_initialize(). - * @post bt_socket_data_received_cb() will be invoked. - * @see bt_initialize() - * @see bt_socket_data_received_cb() - * @see bt_socket_set_data_received_cb() - * @see bt_socket_unset_data_received_cb() - */ -int bt_socket_set_data_received_cb(bt_socket_data_received_cb callback, void *user_data); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE - * @brief Unregisters the callback function. - * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @pre The Bluetooth service must be initialized with bt_initialize(). - * @see bt_initialize() - * @see bt_socket_data_received_cb() - * @see bt_socket_set_data_received_cb() - */ -int bt_socket_unset_data_received_cb(void); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE - * @brief Register a callback function that will be invoked when a RFCOMM connection is requested. - * @param[in] callback The callback function to register - * @param[in] user_data The user data to be passed to the callback function - * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter - * @pre The Bluetooth service must be initialized with bt_initialize(). - * @post If you listen a socket by bt_socket_listen(), bt_socket_connection_requested_cb() will be invoked. - * @see bt_initialize() - * @see bt_socket_unset_connection_requested_cb() - */ -int bt_socket_set_connection_requested_cb(bt_socket_connection_requested_cb callback, void *user_data); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE - * @brief Unregisters the callback function. - * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @pre The Bluetooth service must be initialized with bt_initialize(). - * @see bt_initialize() - * @see bt_socket_set_connection_requested_cb() - * @see bt_socket_connection_requested_cb() - */ -int bt_socket_unset_connection_requested_cb(void); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE - * @brief Register a callback function that will be invoked when the connection state changes. - * @param[in] callback The callback function to register - * @param[in] user_data The user data to be passed to the callback function - * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter - * @pre The Bluetooth service must be initialized with bt_initialize(). - * @post bt_socket_connection_state_changed_cb() will be invoked. - * @see bt_initialize() - * @see bt_socket_connection_state_changed_cb() - * @see bt_socket_unset_connection_state_changed_cb() - */ -int bt_socket_set_connection_state_changed_cb(bt_socket_connection_state_changed_cb callback, void *user_data); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE - * @brief Unregisters the callback function. - * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @pre The Bluetooth service must be initialized with bt_initialize(). - * @see bt_initialize() - * @see bt_socket_connection_state_changed_cb() - * @see bt_socket_set_connection_state_changed_cb() - */ -int bt_socket_unset_connection_state_changed_cb(void); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_OPP_SERVER_MODULE - * @brief Called when the push is requested. - * @details You must call bt_opp_server_accept_push() if you want to accept. - * Otherwise, you must call bt_opp_server_reject_push(). - * @param[in] file The path of file to be pushed - * @param[in] size The file size (bytes) - * @param[in] user_data The user data passed from the callback registration function - * @see bt_opp_server_initialize() - */ -typedef void (*bt_opp_server_push_requested_cb)(const char *file, int size, void *user_data); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_OPP_SERVER_MODULE - * @brief Called when an OPP connection is requested. - * @details You must call bt_opp_server_accept_connection() if you want to accept. - * Otherwise, you must call bt_opp_server_reject_connection(). - * @param[in] remote_address The address of remote device - * @param[in] user_data The user data passed from the callback registration function - * @see bt_opp_server_initialize() - * @see bt_opp_server_accept_connection() - * @see bt_opp_server_reject_connection() - */ -typedef void (*bt_opp_server_connection_requested_cb)(const char *remote_address, void *user_data); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_OPP_SERVER_MODULE - * @brief Initializes the Bluetooth OPP server requested by bt_opp_server_push_requested_cb(). - * @details The popup appears when an OPP connection is requested from a remote device. - * If you accept the request, then connection will be established and bt_opp_server_push_requested_cb() will be called. - * At that time, you can call either bt_opp_server_accept() or bt_opp_server_reject(). - * @remarks This function must be called to start Bluetooth OPP server. You must free all resources of the Bluetooth service - * by calling bt_opp_server_deinitialize() if Bluetooth OPP service is no longer needed. - * @param[in] destination The destination path - * @param[in] push_requested_cb The callback called when a push is requested - * @param[in] user_data The user data to be passed to the callback function - * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_NOT_ENABLED Not enabled - * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #BT_ERROR_RESOURCE_BUSY Device or resource busy - * @retval #BT_ERROR_OPERATION_FAILED Operation failed - * @see bt_opp_server_push_requested_cb() - * @see bt_opp_server_deinitialize() - * @see bt_opp_server_accept_push() - * @see bt_opp_server_reject_push() - */ -int bt_opp_server_initialize(const char *destination, bt_opp_server_push_requested_cb push_requested_cb, void *user_data); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_OPP_SERVER_MODULE - * @brief Initializes the Bluetooth OPP server requested by bt_opp_server_connection_requested_cb(). - * @details No popup appears when an OPP connection is requested from a remote device. - * Instead, @a connection_requested_cb() will be called. - * At that time, you can call either bt_opp_server_accept() or bt_opp_server_reject(). - * @remarks This function must be called to start Bluetooth OPP server. \n - * You must free all resources of the Bluetooth service by calling bt_opp_server_deinitialize() if Bluetooth OPP service is no longer needed. - * @param[in] destination The destination path - * @param[in] connection_requested_cb The callback called when an OPP connection is requested - * @param[in] user_data The user data to be passed to the callback function - * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_NOT_ENABLED Not enabled - * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #BT_ERROR_RESOURCE_BUSY Device or resource busy - * @retval #BT_ERROR_OPERATION_FAILED Operation failed - * @see bt_opp_server_connection_requested_cb() - * @see bt_opp_server_deinitialize() - * @see bt_opp_server_accept_connection() - * @see bt_opp_server_reject_connection() - */ -int bt_opp_server_initialize_by_connection_request(const char *destination, bt_opp_server_connection_requested_cb connection_requested_cb, void *user_data); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_OPP_SERVER_MODULE - * @brief Denitializes the Bluetooth OPP server. - * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_NOT_ENABLED Not enabled - * @retval #BT_ERROR_OPERATION_FAILED Operation failed - * @see bt_opp_server_initialize() - * @see bt_opp_server_deinitialize() - * @see bt_opp_server_initialize() - */ -int bt_opp_server_deinitialize(void); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_OPP_SERVER_MODULE - * @brief Called when a file is being transfered. - * @param[in] file The path of file to be pushed - * @param[in] size The file size (bytes) - * @param[in] percent The progress in percentage (1 ~ 100) - * @param[in] user_data The user data passed from the callback registration function - * @see bt_opp_server_accept_push() - * @see bt_opp_server_accept_connection() - */ -typedef void (*bt_opp_server_transfer_progress_cb) (const char *file, long long size, int percent, void *user_data); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_OPP_SERVER_MODULE - * @brief Called when a transfer is finished. - * @param[in] error_code The result of push - * @param[in] file The path of file to be pushed - * @param[in] size The file size (bytes) - * @param[in] user_data The user data passed from the callback registration function - * @see bt_opp_server_accept_push() - * @see bt_opp_server_accept_connection() - */ -typedef void (*bt_opp_server_transfer_finished_cb) (int result, const char *file, long long size, void *user_data); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_OPP_SERVER_MODULE - * @brief Accepts the push request from the remote device. - * @remarks If you initialize OPP server by bt_opp_server_initialize_by_connection_request(), then name is ignored. - * You can cancel the pushes by bt_opp_server_cancel_transfer() with transfer_id. - * @param[in] progress_cb The callback called when a file is being transfered - * @param[in] finished_cb The callback called when a transfer is finished - * @param[in] name The name to store. This can be NULL if you initialize OPP server by bt_opp_server_initialize_by_connection_request(). - * @param[in] user_data The user data to be passed to the callback function - * @param[out] transfer_id The ID of transfer - * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_NOT_ENABLED Not enabled - * @retval #BT_ERROR_OPERATION_FAILED Operation failed - * @retval #BT_ERROR_NOW_IN_PROGRESS Operation now in progress - * @see bt_opp_server_reject() - */ -int bt_opp_server_accept(bt_opp_server_transfer_progress_cb progress_cb, bt_opp_server_transfer_finished_cb finished_cb, const char *name, - void *user_data, int *transfer_id); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_OPP_SERVER_MODULE - * @brief Rejects the push request from the remote device. - * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_NOT_ENABLED Not enabled - * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #BT_ERROR_OPERATION_FAILED Operation failed - * @see bt_opp_server_accept_push() - */ -int bt_opp_server_reject(void); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_OPP_SERVER_MODULE - * @brief Cancels the transfer. - * @param[in] transfer_id The ID of transfer - * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_NOT_ENABLED Not enabled - * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #BT_ERROR_OPERATION_FAILED Operation failed - * @see bt_opp_server_accept_connection() - * @see bt_opp_server_accept_push() - */ -int bt_opp_server_cancel_transfer(int transfer_id); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_OPP_SERVER_MODULE - * @brief Sets the destination path of file to be pushed. - * @param[in] destination The destination path of file to be pushed - * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_NOT_ENABLED Not enabled - * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #BT_ERROR_OPERATION_FAILED Operation failed - * @see bt_opp_server_initialize() - */ -int bt_opp_server_set_destination(const char *destination); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_OPP_CLIENT_MODULE - * @brief Initializes the Bluetooth OPP client. - * @remarks This function must be called before Bluetooth OPP client starts. \n - * You must free all resources of the Bluetooth service by calling bt_opp_client_deinitialize() - * if Bluetooth OPP service is no longer needed. - * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_NOT_ENABLED Not enabled - * @retval #BT_ERROR_RESOURCE_BUSY Device or resource busy - * @retval #BT_ERROR_OPERATION_FAILED Operation failed - * @see bt_opp_client_deinitialize() - */ -int bt_opp_client_initialize(void); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_OPP_CLIENT_MODULE - * @brief Denitializes the Bluetooth OPP client. - * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_NOT_ENABLED Not enabled - * @retval #BT_ERROR_OPERATION_FAILED Operation failed - * @see bt_opp_client_initialize() - */ -int bt_opp_client_deinitialize(void); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_OPP_CLIENT_MODULE - * @brief Adds file to be pushed. - * @param[in] file The path of file to be pushed - * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_NOT_ENABLED Not enabled - * @retval #BT_ERROR_OPERATION_FAILED Operation failed - * @see bt_opp_client_clear_files() - * @see bt_opp_client_push_files() - */ -int bt_opp_client_add_file(const char *file); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_OPP_CLIENT_MODULE - * @brief Adds file to be pushed. - * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_NOT_ENABLED Not enabled - * @retval #BT_ERROR_OPERATION_FAILED Operation failed - * @see bt_opp_client_add_file() - * @see bt_opp_client_push_files() - */ -int bt_opp_client_clear_files(void); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_OPP_CLIENT_MODULE - * @brief Called when OPP server responds to the push request. - * @param[in] result The result of OPP server response - * @param[in] remote_address The remote address - * @param[in] user_data The user data passed from the callback registration function - * @pre bt_opp_client_push_files() will invoke this function. - * @see bt_opp_client_push_files() - */ -typedef void (*bt_opp_client_push_responded_cb)(int result, const char *remote_address, void *user_data); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_OPP_CLIENT_MODULE - * @brief Called when each file is being transfered. - * @param[in] file The path of file to be pushed - * @param[in] size The file size (bytes) - * @param[in] percent The progress in percentage (1 ~ 100). 100 means that a file is transfered completely. - * @param[in] user_data The user data passed from the callback registration function - * @pre bt_opp_client_push_files() will invoke this function. - * @see bt_opp_client_push_files() - */ -typedef void (*bt_opp_client_push_progress_cb)(const char *file, long long size, int percent, void *user_data); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_OPP_CLIENT_MODULE - * @brief Called when the push request is finished. - * @param[in] result The result of the push request - * @param[in] remote_address The remote address - * @param[in] user_data The user data passed from the callback registration function - * @see bt_opp_client_push_files() - */ -typedef void (*bt_opp_client_push_finished_cb)(int result, const char *remote_address, void *user_data); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_OPP_CLIENT_MODULE - * @brief Pushes the file to the remote device, asynchronously. - * @details At first, bt_opp_client_push_responded_cb() will be called when OPP server responds to the push request. - * After connection is established, bt_opp_client_push_progress_cb() will be called repeatedly until a file is tranfered completely. - * If you send several files, then bt_opp_client_push_progress_cb() with another file will be called repeatedly until the file is tranfered completely. - * bt_opp_client_push_finished_cb() will be called when the push request is finished. - * @param[in] remote_address The remote address - * @param[in] responded_cb The callback called when OPP server responds to the push request - * @param[in] progress_cb The callback called when each file is being transfered - * @param[in] finished_cb The callback called when the push request is finished - * @param[in] user_data The user data to be passed to the callback function - * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_NOT_ENABLED Not enabled - * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #BT_ERROR_OPERATION_FAILED Operation failed - * @retval #BT_ERROR_NOW_IN_PROGRESS Operation now in progress - * @see bt_opp_client_initialize() - * @see bt_opp_client_cancel_push - */ -int bt_opp_client_push_files(const char *remote_address, bt_opp_client_push_responded_cb responded_cb, - bt_opp_client_push_progress_cb progress_cb, bt_opp_client_push_finished_cb finished_cb, void *user_data); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_OPP_CLIENT_MODULE - * @brief Cancels the push request in progress, asynchronously. - * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_NOT_ENABLED Not enabled - * @retval #BT_ERROR_OPERATION_FAILED Operation failed - * @pre bt_opp_client_push_files() must be called. - * @post bt_opp_client_push_finished_cb() will be invoked with result #BT_ERROR_CANCELLED, - * which is a parameter of bt_opp_client_push_files(). - * @see bt_opp_client_initialize() - * @see bt_opp_client_push_files() - */ -int bt_opp_client_cancel_push(void); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_PAN_NAP_MODULE - * @brief Called when the connection state is changed. - * @param[in] connected Indicates whether a client is connected or disconnected - * @param[in] remote_address The remote address - * @param[in] interface_name The interface name. For example, bnep0, bnep1. - * @param[in] user_data The user data passed from the callback registration function - * @see bt_nap_set_connection_state_changed_cb() - * @see bt_nap_unset_connection_state_changed_cb() - */ -typedef void (*bt_nap_connection_state_changed_cb) (bool connected, const char *remote_address, const char *interface_name, void *user_data); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_PAN_NAP_MODULE - * @brief Activates the NAP(Network Access Point). - * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_NOT_ENABLED Not enabled - * @retval #BT_ERROR_OPERATION_FAILED Operation failed - * @pre The Bluetooth must be enabled with bt_adapter_enable(). - * @see bt_adapter_enable() - * @see bt_nap_deactivate() - */ -int bt_nap_activate(void); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_PAN_NAP_MODULE - * @brief Deactivates the NAP(Network Access Point). - * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_NOT_ENABLED Not enabled - * @retval #BT_ERROR_OPERATION_FAILED Operation failed - * @pre The Bluetooth NAP service must be activated with bt_nap_activate(). - * @see bt_nap_activate() - */ -int bt_nap_deactivate(void); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_PAN_NAP_MODULE - * @brief Registers a callback function that will be invoked when the connection state changes. - * @param[in] callback The callback function to register - * @param[in] user_data The user data to be passed to the callback function - * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter - * @pre The Bluetooth service must be initialized with bt_initialize(). - * @post bt_nap_connection_state_changed_cb() will be invoked. - * @see bt_initialize() - * @see bt_nap_connection_state_changed_cb() - * @see bt_nap_unset_connection_state_changed_cb() - */ -int bt_nap_set_connection_state_changed_cb(bt_nap_connection_state_changed_cb callback, void *user_data); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_PAN_NAP_MODULE - * @brief Unregisters a callback function that will be invoked when the connection state changes. - * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @pre The Bluetooth service must be initialized with bt_initialize(). - * @post bt_nap_connection_state_changed_cb() will be invoked. - * @see bt_initialize() - * @see bt_nap_connection_state_changed_cb() - * @see bt_nap_set_connection_state_changed_cb() - */ -int bt_nap_unset_connection_state_changed_cb(void); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_PAN_PANU_MODULE - * @brief Called when the connection state is changed. - * @details This callback is called when the connection state is changed. - * When you call bt_panu_connect() or bt_panu_disconnect(), this callback is also called with error result even though these functions fail. - * @param[in] result The result of changing the connection state - * @param[in] connected The state to be changed. @a true means connected state, Otherwise, @a false. - * @param[in] remote_address The remote address - * @param[in] type The type of PAN service - * @param[in] user_data The user data passed from the callback registration function - * @see bt_nap_set_connection_state_changed_cb() - * @see bt_nap_unset_connection_state_changed_cb() - */ -typedef void (*bt_panu_connection_state_changed_cb) (int result, bool connected, const char *remote_address, bt_panu_service_type_e type, void *user_data); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_PAN_PANU_MODULE - * @brief Registers a callback function that will be invoked when the connection state changes. - * @param[in] callback The callback function to register - * @param[in] user_data The user data to be passed to the callback function - * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter - * @pre The Bluetooth service must be initialized with bt_initialize(). - * @post bt_nap_connection_state_changed_cb() will be invoked. - * @see bt_initialize() - * @see bt_panu_connection_state_changed_cb() - * @see bt_panu_unset_connection_state_changed_cb() - */ -int bt_panu_set_connection_state_changed_cb(bt_panu_connection_state_changed_cb callback, void *user_data); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_PAN_PANU_MODULE - * @brief Unregisters a callback function that will be invoked when the connection state changes. - * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @pre The Bluetooth service must be initialized with bt_initialize(). - * @post bt_nap_connection_state_changed_cb() will be invoked. - * @see bt_initialize() - * @see bt_panu_connection_state_changed_cb() - * @see bt_panu_set_connection_state_changed_cb() - */ -int bt_panu_unset_connection_state_changed_cb(void); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_PAN_PANU_MODULE - * @brief Connects the remote device with the PAN(Personal Area Networking) service, asynchronously. - * @param[in] remote_address The remote address - * @param[in] type The type of PAN service - * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #BT_ERROR_NOT_ENABLED Not enabled - * @retval #BT_ERROR_REMOTE_DEVICE_NOT_BONDED Remote device is not bonded - * @retval #BT_ERROR_OUT_OF_MEMORY Out of memory - * @retval #BT_ERROR_OPERATION_FAILED Operation failed - * @pre The local device must be bonded with the remote device by bt_device_create_bond(). - * @post bt_panu_connection_state_changed_cb() will be invoked. - * @see bt_panu_disconnect() - * @see bt_panu_connection_state_changed_cb() - */ -int bt_panu_connect(const char *remote_address, bt_panu_service_type_e type); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_PAN_PANU_MODULE - * @brief Disconnects the remote device with the PAN(Personal Area Networking) service, asynchronously. - * @param[in] remote_address The remote address - * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #BT_ERROR_NOT_ENABLED Not enabled - * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected - * @retval #BT_ERROR_OUT_OF_MEMORY Out of memory - * @retval #BT_ERROR_OPERATION_FAILED Operation failed - * @pre The remote device must be connected by bt_panu_connect(). - * @post bt_panu_connection_state_changed_cb() will be invoked. - * @see bt_panu_connect() - * @see bt_panu_connection_state_changed_cb() - */ -int bt_panu_disconnect(const char *remote_address); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_HID_MODULE - * @brief Called when the connection state is changed. - * @details This callback is called when the connection state is changed. - * When you call bt_hid_host_connect() or bt_hid_host_disconnect(), this callback is also called with error result even though these functions fail. - * @param[in] result The result of changing the connection state - * @param[in] connected The state to be changed. @a true means connected state, Otherwise, @a false. - * @param[in] remote_address The remote address - * @param[in] user_data The user data passed from the callback registration function - * @see bt_hid_host_connect() - * @see bt_hid_host_disconnect() - */ -typedef void (*bt_hid_host_connection_state_changed_cb) (int result, bool connected, const char *remote_address, void *user_data); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_HID_MODULE - * @brief Initializes the Bluetooth HID(Human Interface Device) Host. - * @remarks This function must be called before Bluetooth HID Host starts. \n - * You must free all resources of the Bluetooth service by calling bt_hid_host_deinitialize() - * if Bluetooth HID Host service is no longer needed. - * @param[in] connection_cb The callback called when the connection state is changed - * @param[in] user_data The user data to be passed to the callback function - * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #BT_ERROR_OPERATION_FAILED Operation failed - * @pre The Bluetooth service must be initialized with bt_initialize(). - * @see bt_initialize() - * @see bt_hid_host_deinitialize() - */ -int bt_hid_host_initialize(bt_hid_host_connection_state_changed_cb connection_cb, void *user_data); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_HID_MODULE - * @brief Deinitializes the Bluetooth HID(Human Interface Device) Host. - * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_OPERATION_FAILED Operation failed - * @pre The Bluetooth HID service must be initialized with bt_hid_host_initialize(). - * @see bt_hid_host_initialize() - */ -int bt_hid_host_deinitialize(void); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_HID_MODULE - * @brief Connects the remote device with the HID(Human Interface Device) service, asynchronously. - * @param[in] remote_address The remote address - * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #BT_ERROR_NOT_ENABLED Not enabled - * @retval #BT_ERROR_REMOTE_DEVICE_NOT_BONDED Remote device is not bonded - * @retval #BT_ERROR_OPERATION_FAILED Operation failed - * @pre The local device must be bonded with the remote device by bt_device_create_bond(). - * @pre The Bluetooth HID service must be initialized with bt_hid_host_initialize(). - * @post bt_hid_host_connection_state_changed_cb() will be invoked. - * @see bt_hid_host_disconnect() - * @see bt_hid_host_connection_state_changed_cb() - */ -int bt_hid_host_connect(const char *remote_address); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_HID_MODULE - * @brief Disconnects the remote device with the HID(Human Interface Device) service, asynchronously. - * @param[in] remote_address The remote address - * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #BT_ERROR_NOT_ENABLED Not enabled - * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected - * @retval #BT_ERROR_OPERATION_FAILED Operation failed - * @pre The remote device must be connected by bt_hid_host_connect(). - * @post bt_hid_host_connection_state_changed_cb() will be invoked. - * @see bt_hid_host_connect() - * @see bt_hid_host_connection_state_changed_cb() - */ -int bt_hid_host_disconnect(const char *remote_address); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_MODULE - * @brief Initializes the Bluetooth profiles related with audio. - * @remarks This function must be called before Bluetooth profiles related with audio starts. \n - * You must free all resources of the this service by calling bt_audio_deinitialize() - * if Bluetooth profiles related with audio service is no longer needed. - * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_OPERATION_FAILED Operation failed - * @pre The Bluetooth service must be initialized with bt_initialize(). - * @see bt_initialize() - * @see bt_audio_deinitialize() - */ -int bt_audio_initialize(void); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_MODULE - * @brief Deinitializes the Bluetooth profiles related with audio. - * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_OPERATION_FAILED Operation failed - * @pre The Bluetooth audio service must be initialized with bt_audio_initialize(). - * @see bt_audio_initialize() - */ -int bt_audio_deinitialize(void); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_MODULE - * @brief Connects the remote device with the given audio profile, asynchronously. - * @details If you input type as #BT_AUDIO_PROFILE_TYPE_ALL and connection request succeeds, then bt_audio_connection_state_changed_cb() will be called twice - * when #BT_AUDIO_PROFILE_TYPE_HSP_HFP is connected and #BT_AUDIO_PROFILE_TYPE_A2DP is connected. - * @param[in] remote_address The remote address - * @param[in] type The type of audio profile - * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #BT_ERROR_NOT_ENABLED Not enabled - * @retval #BT_ERROR_REMOTE_DEVICE_NOT_BONDED Remote device is not bonded - * @retval #BT_ERROR_OPERATION_FAILED Operation failed - * @pre The Bluetooth audio service must be initialized with bt_audio_initialize(). - * @pre The local device must be bonded with the remote device by bt_device_create_bond(). - * @post bt_audio_connection_state_changed_cb() will be invoked. - * @see bt_audio_disconnect() - * @see bt_audio_connection_state_changed_cb() - */ -int bt_audio_connect(const char *remote_address, bt_audio_profile_type_e type); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_MODULE - * @brief Disconnects the remote device with the given audio profile, asynchronously. - * @details If you input type as #BT_AUDIO_PROFILE_TYPE_ALL and disconnection request succeeds, then bt_audio_connection_state_changed_cb() will be called twice - * when #BT_AUDIO_PROFILE_TYPE_HSP_HFP is disconnected and #BT_AUDIO_PROFILE_TYPE_A2DP is disconnected. - * @param[in] remote_address The remote address - * @param[in] type The type of audio profile - * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #BT_ERROR_NOT_ENABLED Not enabled - * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected - * @retval #BT_ERROR_OPERATION_FAILED Operation failed - * @pre The remote device must be connected by bt_audio_connect(). - * @post bt_audio_connection_state_changed_cb() will be invoked. - * @see bt_audio_connect() - * @see bt_audio_connection_state_changed_cb() - */ -int bt_audio_disconnect(const char *remote_address, bt_audio_profile_type_e type); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_MODULE - * @brief Called when the connection state is changed. - * @details This callback is called when the connection state is changed. - * When you call bt_audio_connect() or bt_audio_disconnect(), this callback is also called with error result even though these functions fail. - * @param[in] result The result of changing the connection state - * @param[in] connected The state to be changed. @a true means connected state, Otherwise, @a false. - * @param[in] remote_address The remote address - * @param[in] type The type of audio profile except #BT_AUDIO_PROFILE_TYPE_ALL - * @param[in] user_data The user data passed from the callback registration function - * @see bt_audio_set_connection_state_changed_cb() - * @see bt_audio_unset_connection_state_changed_cb() - */ -typedef void (*bt_audio_connection_state_changed_cb) (int result, bool connected, const char *remote_address, bt_audio_profile_type_e type, void *user_data); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_MODULE - * @brief Registers a callback function that will be invoked when the connection state is changed. - * @param[in] callback The callback function to register - * @param[in] user_data The user data to be passed to the callback function - * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter - * @pre The Bluetooth audio service must be initialized with bt_audio_initialize(). - * @see bt_audio_initialize() - * @see bt_audio_connection_state_changed_cb() - * @see bt_panu_unset_connection_state_changed_cb() - */ -int bt_audio_set_connection_state_changed_cb(bt_audio_connection_state_changed_cb callback, void *user_data); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_MODULE - * @brief Unregisters a callback function that will be invoked when the connection state is changed. - * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @pre The Bluetooth audio service must be initialized with bt_audio_initialize(). - * @see bt_audio_initialize() - * @see bt_audio_connection_state_changed_cb() - * @see bt_audio_set_connection_state_changed_cb() - */ -int bt_audio_unset_connection_state_changed_cb(void); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE - * @brief Notifies the speaker gain to the remote device. - * @details This function sends a signal to the remote device. This signal has the gain value. - * @a gain is represented on a scale from 0 to 15. This value is absolute value relating to a particular volume level. - * When the speaker gain of remote device is changed to the requested gain, bt_audio_speaker_gain_changed_cb() will be called. - * @param[in] remote_address The remote address - * @param[in] gain The gain of speaker (0 ~ 15) - * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #BT_ERROR_NOT_ENABLED Not enabled - * @retval #BT_ERROR_OPERATION_FAILED Operation failed - * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected - * @pre The remote device is connected by bt_audio_connect() with #BT_AUDIO_PROFILE_TYPE_HSP_HFP service. - * @see bt_ag_get_speaker_gain() - * @see bt_ag_set_speaker_gain_changed_cb() - * @see bt_ag_unset_speaker_gain_changed_cb() - */ -int bt_ag_notify_speaker_gain(const char *remote_address, int gain); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE - * @brief Gets the current speaker gain of the remote device. - * @details This function gets the value of speaker gain of the remote device. - * @a gain is represented on a scale from 0 to 15. This value is absolute value relating to a particular volume level. - * @param[in] remote_address The remote address - * @param[out] gain The gain of speaker (0 ~ 15) - * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #BT_ERROR_NOT_ENABLED Not enabled - * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected - * @pre The remote device is connected by bt_audio_connect() with #BT_AUDIO_PROFILE_TYPE_HSP_HFP service. - * @see bt_ag_notify_speaker_gain() - * @see bt_ag_set_speaker_gain_changed_cb() - * @see bt_ag_unset_speaker_gain_changed_cb() - */ -int bt_ag_get_speaker_gain(const char *remote_address, int *gain); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_MODULE - * @brief Called when the speaker gain of the remote device is changed. - * @param[in] remote_address The remote address - * @param[in] gain The gain of speaker (0 ~ 15) - * @param[in] user_data The user data passed from the callback registration function - * @see bt_ag_set_speaker_gain_changed_cb() - * @see bt_ag_unset_speaker_gain_changed_cb() - */ -typedef void (*bt_ag_speaker_gain_changed_cb) (const char *remote_address, int gain, void *user_data); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE - * @brief Registers a callback function that will be invoked when the speaker gain of the remote device is changed. - * @details This function let you know the change of the speaker gain of the remote device. - * @a gain is represented on a scale from 0 to 15. This value is absolute value relating to a particular volume level. - * @param[in] callback The callback function to register - * @param[in] user_data The user data to be passed to the callback function - * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter - * @pre The Bluetooth audio service must be initialized with bt_audio_initialize(). - * @see bt_audio_initialize() - * @see bt_ag_unset_speaker_gain_changed_cb() - */ -int bt_ag_set_speaker_gain_changed_cb(bt_ag_speaker_gain_changed_cb callback, void *user_data); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE - * @brief Unregisters a callback function that will be invoked when the speaker gain of the remote device is changed. - * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter - * @pre The Bluetooth audio service must be initialized with bt_audio_initialize(). - * @see bt_audio_initialize() - * @see bt_ag_set_speaker_gain_changed_cb() - */ -int bt_ag_unset_speaker_gain_changed_cb(void); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_MODULE - * @brief Called when the microphone gain of the remote device is changed. - * @param[in] remote_address The remote address - * @param[in] gain The gain of microphone (0 ~ 15) - * @param[in] user_data The user data passed from the callback registration function - * @see bt_ag_set_microphone_gain_changed_cb() - * @see bt_ag_unset_microphone_gain_changed_cb() - */ -typedef void (*bt_ag_microphone_gain_changed_cb) (const char *remote_address, int gain, void *user_data); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE - * @brief Registers a callback function that will be invoked when the microphone gain of the remote device is changed. - * @param[in] callback The callback function to register - * @param[in] user_data The user data to be passed to the callback function - * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter - * @pre The Bluetooth audio service must be initialized with bt_audio_initialize(). - * @see bt_audio_initialize() - * @see bt_ag_unset_microphone_gain_changed_cb() - */ -int bt_ag_set_microphone_gain_changed_cb(bt_ag_microphone_gain_changed_cb callback, void *user_data); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE - * @brief Unregisters a callback function that will be invoked when the microphone gain of the remote device is changed. - * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter - * @pre The Bluetooth audio service must be initialized with bt_audio_initialize(). - * @see bt_audio_initialize() - * @see bt_ag_set_microphone_gain_changed_cb() - */ -int bt_ag_unset_microphone_gain_changed_cb(void); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE - * @brief Called when the connection state is changed. - * @param[in] connected The state to be changed. @a true means connected state, Otherwise, @a false. - * @param[in] remote_address The remote address - * @param[in] user_data The user data passed from the callback registration function - * @see bt_avrcp_target_initialize() - * @see bt_avrcp_target_deinitialize() - */ -typedef void (*bt_avrcp_target_connection_state_changed_cb) (bool connected, const char *remote_address, void *user_data); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE - * @brief Initializes the Bluetooth AVRCP(Audio/Video Remote Control Profile) service. - * @remarks This function must be called before Bluetooth AVRCP service. \n - * You must free all resources of the this service by calling bt_avrcp_target_deinitialize() - * if Bluetooth AVRCP service is no longer needed. - * @param[in] callback The callback function called when the connection state is changed - * @param[in] user_data The user data to be passed to the callback function - * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #BT_ERROR_OPERATION_FAILED Operation failed - * @pre The Bluetooth service must be initialized with bt_initialize(). - * @see bt_initialize() - * @see bt_avrcp_target_deinitialize() - */ -int bt_avrcp_target_initialize(bt_avrcp_target_connection_state_changed_cb callback, void *user_data); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE - * @brief Deinitializes the Bluetooth AVRCP(Audio/Video Remote Control Profile) service. - * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @pre The Bluetooth audio service must be initialized with bt_avrcp_target_initialize(). - * @see bt_avrcp_target_initialize() - */ -int bt_avrcp_target_deinitialize(void); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE - * @brief Notify the equalize state to the remote device. - * @param[in] state The state of equalizer - * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #BT_ERROR_NOT_ENABLED Not enabled - * @retval #BT_ERROR_OPERATION_FAILED Operation failed - * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected - * @pre The remote device must be connected. - * @see bt_avrcp_target_connection_state_changed_cb() - * @see bt_avrcp_target_initialize() - */ -int bt_avrcp_target_notify_equalizer_state(bt_avrcp_equalizer_state_e state); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE - * @brief Notify the repeat mode to the remote device. - * @param[in] mode The repeat mode - * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #BT_ERROR_NOT_ENABLED Not enabled - * @retval #BT_ERROR_OPERATION_FAILED Operation failed - * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected - * @pre The remote device must be connected. - * @see bt_avrcp_target_connection_state_changed_cb() - * @see bt_avrcp_target_initialize() - */ -int bt_avrcp_target_notify_repeat_mode(bt_avrcp_repeat_mode_e mode); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE - * @brief Notify the shuffle mode to the remote device. - * @param[in] mode The repeat mode - * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #BT_ERROR_NOT_ENABLED Not enabled - * @retval #BT_ERROR_OPERATION_FAILED Operation failed - * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected - * @pre The remote device must be connected. - * @see bt_avrcp_target_connection_state_changed_cb() - * @see bt_avrcp_target_initialize() - */ -int bt_avrcp_target_notify_shuffle_mode(bt_avrcp_shuffle_mode_e mode); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE - * @brief Notify the scan mode to the remote device. - * @param[in] mode The scan mode - * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #BT_ERROR_NOT_ENABLED Not enabled - * @retval #BT_ERROR_OPERATION_FAILED Operation failed - * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected - * @pre The remote device must be connected. - * @see bt_avrcp_target_connection_state_changed_cb() - * @see bt_avrcp_target_initialize() - */ -int bt_avrcp_target_notify_scan_mode(bt_avrcp_scan_mode_e mode); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE - * @brief Notify the player state to the remote device. - * @param[in] state The player state - * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #BT_ERROR_NOT_ENABLED Not enabled - * @retval #BT_ERROR_OPERATION_FAILED Operation failed - * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected - * @pre The remote device must be connected. - * @see bt_avrcp_target_connection_state_changed_cb() - * @see bt_avrcp_target_initialize() - */ -int bt_avrcp_target_notify_player_state(bt_avrcp_player_state_e state); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE - * @brief Notify the current position of song to the remote device. - * @param[in] position The current position in milliseconds - * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #BT_ERROR_NOT_ENABLED Not enabled - * @retval #BT_ERROR_OPERATION_FAILED Operation failed - * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected - * @pre The remote device must be connected. - * @see bt_avrcp_target_connection_state_changed_cb() - * @see bt_avrcp_target_initialize() - */ -int bt_avrcp_target_notify_position(unsigned int position); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE - * @brief Notify the track to the remote device. - * @param[in] title The title of track - * @param[in] artist The artist of track - * @param[in] album The album of track - * @param[in] genre The genre of track - * @param[in] track_num The track number - * @param[in] total_tracks The number of all tracks - * @param[in] duration The duration of track in milliseconds - * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #BT_ERROR_NOT_ENABLED Not enabled - * @retval #BT_ERROR_OPERATION_FAILED Operation failed - * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected - * @pre The remote device must be connected. - * @see bt_avrcp_target_connection_state_changed_cb() - * @see bt_avrcp_target_initialize() - */ -int bt_avrcp_target_notify_track(const char *title, const char *artist, const char *album, const char *genre, unsigned int track_num, unsigned int total_tracks, unsigned int duration); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_HDP_MODULE - * @brief Registers an application that acts as the @a Sink role of HDP(Health Device Profile). - * @param[in] data_type The data type of MDEP. This value is defined in ISO/IEEE 11073-20601 spec. - * For example, pulse oximeter is 0x1004 and blood pressure monitor is 0x1007. - * @param[out] app_id The ID of application - * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_NOT_ENABLED Not enabled - * @pre The Bluetooth must be enabled with bt_adapter_enable(). - * @see bt_adapter_enable() - * @see bt_hdp_deactivate_sink() - */ -int bt_hdp_register_sink_app(unsigned short data_type, char **app_id); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_HDP_MODULE - * @brief Unregisters the given application that acts as the @a Sink role of HDP(Health Device Profile). - * @param[in] app_id The ID of application - * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_NOT_ENABLED Not enabled - * @retval #BT_ERROR_OPERATION_FAILED Operation failed - * @see bt_hdp_register_sink_app() - */ -int bt_hdp_unregister_sink_app(const char *app_id); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_HDP_MODULE - * @brief Connects the remote device which acts as @a Source role, asynchronously. - * @param[in] remote_address The remote address - * @param[in] app_id The ID of application - * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #BT_ERROR_NOT_ENABLED Not enabled - * @retval #BT_ERROR_REMOTE_DEVICE_NOT_BONDED Remote device is not bonded - * @retval #BT_ERROR_OUT_OF_MEMORY Out of memory - * @retval #BT_ERROR_OPERATION_FAILED Operation failed - * @pre The Sink role of HDP must be activated with bt_hdp_activate_sink(). - * @pre The local device must be bonded with the remote device by bt_device_create_bond(). - * @post bt_hdp_connected_cb() will be invoked. - * @see bt_hdp_disconnect() - * @see bt_hdp_set_connection_state_changed_cb() - * @see bt_hdp_unset_connection_state_changed_cb() - */ -int bt_hdp_connect_to_source(const char *remote_address, const char *app_id); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_HDP_MODULE - * @brief Disconnects the remote device, asynchronously. - * @param[in] remote_address The remote address - * @param[in] channel The connected data channel - * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #BT_ERROR_NOT_ENABLED Not enabled - * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected - * @retval #BT_ERROR_OUT_OF_MEMORY Out of memory - * @retval #BT_ERROR_OPERATION_FAILED Operation failed - * @pre The remote device must be connected. - * @post bt_hdp_disconnected_cb() will be invoked. - * @see bt_hdp_set_connection_state_changed_cb() - * @see bt_hdp_unset_connection_state_changed_cb() - */ -int bt_hdp_disconnect(const char *remote_address, unsigned int channel); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_HDP_MODULE - * @brief Sends the data to the remote device. - * @param[in] channel The connected data channel - * @param[in] data The data to send - * @param[in] size The size of data to send (byte) - * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #BT_ERROR_NOT_ENABLED Not enabled - * @retval #BT_ERROR_OPERATION_FAILED Operation failed - * @pre The remote device must be connected. - * @see bt_hdp_data_received_cb() - * @see bt_hdp_set_data_received_cb() - * @see bt_hdp_unset_data_received_cb() - */ -int bt_hdp_send_data(unsigned int channel, const char *data, unsigned int size); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_HDP_MODULE - * @brief Called when the connection is established. - * @param[in] result The result of connecting to the remote device - * @param[in] remote_address The address of connected remote device - * @param[in] app_id The ID of application - * @param[in] type The type of HDP(Health Device Profile) channel - * @param[in] channel The connected data channel - * @param[in] user_data The user data passed from the callback registration function - * @see bt_hdp_disconnected_cb - * @see bt_hdp_set_connection_state_changed_cb() - * @see bt_hdp_unset_connection_state_changed_cb() - */ -typedef void (*bt_hdp_connected_cb) (int result, const char *remote_address, const char *app_id, - bt_hdp_channel_type_e type, unsigned int channel, void *user_data); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_HDP_MODULE - * @brief Called when the connection is disconnected. - * @param[in] result The result of disconnecting from the remote device - * @param[in] remote_address The address of disconnected remote device - * @param[in] channel The connected data channel - * @param[in] user_data The user data passed from the callback registration function - * @see bt_hdp_connected_cb - * @see bt_hdp_set_connection_state_changed_cb() - * @see bt_hdp_unset_connection_state_changed_cb() - */ -typedef void (*bt_hdp_disconnected_cb) (int result, const char *remote_address, unsigned int channel, void *user_data); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_HDP_MODULE - * @brief Registers a callback function that will be invoked when the connection state is changed. - * @param[in] connected_cb The callback function called when a connection is established - * @param[in] disconnected_cb The callback function called when a connection is disconnected - * @param[in] user_data The user data to be passed to the callback function - * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter - * @pre The Bluetooth service must be initialized with bt_initialize(). - * @see bt_hdp_unset_connection_state_changed_cb() - */ -int bt_hdp_set_connection_state_changed_cb(bt_hdp_connected_cb connected_cb, bt_hdp_disconnected_cb disconnected_cb, void *user_data); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_HDP_MODULE - * @brief Unregisters a callback function that will be invoked when the connection state is changed. - * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @pre The Bluetooth service must be initialized with bt_initialize(). - * @see bt_hdp_set_connection_state_changed_cb() - */ -int bt_hdp_unset_connection_state_changed_cb(void); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_HDP_MODULE - * @brief Called when the you receive the data. - * @param[in] channel The connected data channel - * @param[in] data The received data - * @param[in] size The size of received data (byte) - * @param[in] user_data The user data passed from the callback registration function - * @see bt_hdp_set_data_received_cb() - * @see bt_hdp_unset_data_received_cb() - */ -typedef void (*bt_hdp_data_received_cb) (unsigned int channel, const char *data, unsigned int size, void *user_data); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_HDP_MODULE - * @brief Registers a callback function that will be invoked when you receive the data. - * @param[in] callback The callback function to register - * @param[in] user_data The user data to be passed to the callback function - * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter - * @pre The Bluetooth service must be initialized with bt_initialize(). - * @see bt_hdp_unset_data_received_cb() - */ -int bt_hdp_set_data_received_cb(bt_hdp_data_received_cb callback, void *user_data); - -/** - * @ingroup CAPI_NETWORK_BLUETOOTH_HDP_MODULE - * @brief Unregisters a callback function that will be invoked when you receive the data. - * @return 0 on success, otherwise a negative error value. - * @retval #BT_ERROR_NONE Successful - * @retval #BT_ERROR_NOT_INITIALIZED Not initialized - * @pre The Bluetooth service must be initialized with bt_initialize(). - * @see bt_hdp_set_data_received_cb() - */ -int bt_hdp_unset_data_received_cb(void); - -/** - * @} - */ - - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif // __TIZEN_NETWORK_BLUETOOTH_H__ diff --git a/include/bluetooth_private.h b/include/bluetooth_private.h index 5135d81..8367ce8 100644 --- a/include/bluetooth_private.h +++ b/include/bluetooth_private.h @@ -22,15 +22,24 @@ #include #include #include +#include #include #include #include "bluetooth.h" +#include "bluetooth_internal.h" #ifdef __cplusplus extern "C" { #endif +#undef LOG_TAG +#define LOG_TAG "CAPI_NETWORK_BLUETOOTH" + +#define BT_INFO(fmt, args...) SLOGI(fmt, ##args) +#define BT_DBG(fmt, args...) SLOGD(fmt, ##args) +#define BT_ERR(fmt, args...) SLOGE(fmt, ##args) + #define OPP_UUID "00001105-0000-1000-8000-00805f9b34fb" /** @@ -40,9 +49,13 @@ extern "C" { typedef enum { BT_EVENT_STATE_CHANGED = 0x00, /**< Adapter state is changed */ + BT_EVENT_LE_STATE_CHANGED, /**< Adapter le state is changed */ BT_EVENT_NAME_CHANGED, /**< Adapter name is changed */ BT_EVENT_VISIBILITY_MODE_CHANGED, /**< Adapter visibility mode is changed */ + BT_EVENT_VISIBILITY_DURATION_CHANGED, /**< Adapter visibility duration is changed */ BT_EVENT_DEVICE_DISCOVERY_STATE_CHANGED, /**< Device discovery state is changed */ + BT_EVENT_LE_DEVICE_DISCOVERY_STATE_CHANGED, /**< LE Device discovery state is changed */ + BT_EVENT_LE_SCAN_RESULT_UPDATED, /**< LE Scan result is updated */ BT_EVENT_BOND_CREATED, /**< A bond is created */ BT_EVENT_BOND_DESTROYED, /**< A bond is destroyed */ BT_EVENT_AUTHORIZATION_CHANGED, /**< Authorization is changed */ @@ -61,24 +74,255 @@ typedef enum BT_EVENT_NAP_CONNECTION_STATE_CHANGED, /**< NAP connection change */ BT_EVENT_HDP_CONNECTED, /**< HDP connection change */ BT_EVENT_HDP_DISCONNECTED, /**< HDP disconnection change */ - BT_EVENT_HDP_DATA_RECIEVED, /**< HDP Data recieve Callabck */ + BT_EVENT_HDP_DATA_RECEIVED, /**< HDP Data receive Callabck */ BT_EVENT_AUDIO_CONNECTION_STATUS, /**< Audio Connection change callback */ + BT_EVENT_A2DP_SOURCE_CONNECTION_STATUS, /**< A2dp Source Connection Change */ + BT_EVENT_AG_SCO_CONNECTION_STATUS, /**< Audio - AG SCO Connection state change callback */ + BT_EVENT_AG_CALL_HANDLING_EVENT, /**< Audio - AG call event callback */ + BT_EVENT_AG_MULTI_CALL_HANDLING_EVENT, /**< Audio - AG 3-way call event callback */ + BT_EVENT_AG_DTMF_TRANSMITTED, /**< Audio - DTMF tone sending request */ BT_EVENT_AG_MICROPHONE_GAIN_CHANGE, /**< Audio Microphone change callback */ BT_EVENT_AG_SPEAKER_GAIN_CHANGE, /**< Audio Speaker gain change callback */ + BT_EVENT_AG_VENDOR_CMD, /**< Audio - XSAT Vendor cmd */ BT_EVENT_AVRCP_CONNECTION_STATUS, /**< AVRCP connection change callback */ - BT_EVENT_HID_CONNECTION_STATUS /**< HID connection status callback */ + BT_EVENT_AVRCP_EQUALIZER_STATE_CHANGED, /**< AVRCP equalizer state change callback */ + BT_EVENT_AVRCP_REPEAT_MODE_CHANGED, /**< AVRCP repeat mode change callback */ + BT_EVENT_AVRCP_SHUFFLE_MODE_CHANGED, /**< AVRCP equalizer mode change callback */ + BT_EVENT_AVRCP_SCAN_MODE_CHANGED, /**< AVRCP scan mode change callback */ + BT_EVENT_AVRCP_PLAY_STATUS_CHANGED, /**< AVRCP scan mode change callback */ + BT_EVENT_AVRCP_SONG_POSITION_CHANGED, /**< AVRCP scan mode change callback */ + BT_EVENT_AVRCP_TRACK_INFO_CHANGED, /**< AVRCP scan mode change callback */ + BT_EVENT_HID_CONNECTION_STATUS, /**< HID connection status callback */ + BT_EVENT_DEVICE_CONNECTION_STATUS, /**< Device connection status callback */ + BT_EVENT_GATT_CONNECTION_STATUS, /** < GATT connection status callback */ + BT_EVENT_GATT_CLIENT_SERVICE_DISCOVERED, /** GATT services discovered callback */ + BT_EVENT_GATT_CLIENT_VALUE_CHANGED, /**< GATT characteristic value changed callback */ + BT_EVENT_GATT_CLIENT_READ_CHARACTERISTIC, /**< GATT characteristic value read callback */ + BT_EVENT_GATT_CLIENT_WRITE_CHARACTERISTIC, /**< GATT characteristic value write callback */ + BT_EVENT_GATT_CLIENT_READ_DESCRIPTOR, /**< GATT descriptor value read callback */ + BT_EVENT_GATT_CLIENT_WRITE_DESCRIPTOR, /**< GATT descriptor value write callback */ + BT_EVENT_GATT_SERVER_READ_REQUESTED, /**< GATT Characteristic/Descriptor Read Requested callback*/ +#ifdef BT_ENABLE_LEGACY_GATT_CLIENT + BT_EVENT_GATT_CLIENT_CHARACTERISTIC_DISCOVERED_LEGACY, /**< GATT characteristic discovered callback */ + BT_EVENT_GATT_CLIENT_CHARACTERISTIC_DESCRIPTOR_DISCOVERED_LEGACY, /**< GATT characteristic descriptor discovered callback */ + BT_EVENT_GATT_CLIENT_VALUE_CHANGED_LEGACY, /**< GATT characteristic value changed callback */ + BT_EVENT_GATT_CLIENT_READ_CHARACTERISTIC_LEGACY, /**< GATT characteristic value read callback */ + BT_EVENT_GATT_CLIENT_WRITE_CHARACTERISTIC_LEGACY, /**< GATT characteristic value write callback */ +#endif + BT_EVENT_ADVERTISING_STATE_CHANGED, /**< Advertising state changed callback */ + BT_EVENT_MANUFACTURER_DATA_CHANGED, /**< Manufacturer data changed callback */ + BT_EVENT_CONNECTABLE_CHANGED_EVENT, /**< Adapter connectable changed callback */ + BT_EVENT_RSSI_ENABLED_EVENT, /**< RSSI Enabled callback */ + BT_EVENT_RSSI_ALERT_EVENT, /**< RSSI Alert callback */ + BT_EVENT_GET_RSSI_EVENT, /**< Get RSSI Strength callback */ +#ifdef TIZEN_WEARABLE + BT_EVENT_PBAP_CONNECTION_STATUS, /**< PBAP connection status callback */ + BT_EVENT_PBAP_PHONEBOOK_SIZE, /**< PBAP Phonebook Size status callback */ + BT_EVENT_PBAP_PHONEBOOK_PULL, /**< PBAP Phonebook Pull status callback */ + BT_EVENT_PBAP_VCARD_LIST, /**< PBAP vCard List status callback */ + BT_EVENT_PBAP_VCARD_PULL, /**< PBAP vCard Pull status callback */ + BT_EVENT_PBAP_PHONEBOOK_SEARCH, /**< PBAP Phonebook Search status callback */ + BT_EVENT_HF_SCO_CONNECTION_STATUS, /**< Audio - HF SCO Connection state change callback */ + BT_EVENT_HF_SPEAKER_GAIN_CHANGE, /**< Audio - HF Speaker gain change callback */ + BT_EVENT_HF_CALL_HANDLING_EVENT, /**< Audio - HF call event callback */ + BT_EVENT_HF_VENDOR_DEP_CMD_EVENT, /**< Audio - HF Vendor Command callback */ + BT_EVENT_HF_MULTI_CALL_HANDLING_EVENT, /**< Audio - HF 3-way call event callback */ + BT_EVENT_HF_CALL_STATUS_UPDATED_EVENT, /**< Audio - HF call status updated callback */ +#endif + BT_EVENT_MAX } bt_event_e; +typedef enum { + BT_GATT_ROLE_SERVER = 0x01, + BT_GATT_ROLE_CLIENT = 0x02, +} bt_gatt_role_e; + +#ifdef TIZEN_WEARABLE +/** + * @internal + */ +typedef enum { + BT_ADAPTER_LE_ADVERTISING_CONNECTABLE = 0x00, /**< Connectable undirected advertising (ADV_IND) */ + BT_ADAPTER_LE_ADVERTISING_CONNECTABLE_DIRECT_HIGH = 0x01, /* @Deprecated since Tizen 2.4 */ + BT_ADAPTER_LE_ADVERTISING_SCANNABLE = 0x02, /**< Scannable undirected advertising (ADV_SCAN_IND) */ + BT_ADAPTER_LE_ADVERTISING_NON_CONNECTABLE = 0x03, /**< Non connectable undirected advertising (ADV_NONCOND_IND) */ + BT_ADAPTER_LE_ADVERTISING_CONNECTABLE_DIRECT_LOW = 0x04, /* @Deprecated since Tizen 2.4 */ +} bt_adapter_le_advertising_type_e; + +/** + * @internal + */ +typedef enum { + BT_ADAPTER_LE_PACKET_DATA_INCOMP_LIST_16_BIT_SERVICE_CLASS_UUIDS = 0x02, /** +#include +#include +#include + +#include "bluetooth_type.h" + +#ifdef __cplusplus +extern "C" +{ +#endif /* __cplusplus */ + +/** + * @file bluetooth.h + * @brief API to control the Bluetooth adapter and devices and communications. + * @ingroup CAPI_NETWORK_BLUETOOTH_MODULE + */ + + +/** + * @addtogroup CAPI_NETWORK_BLUETOOTH_MODULE + * @{ + */ + + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_MODULE + * @brief Initializes the Bluetooth API. + * @since_tizen 2.3 + * + * @remarks This function must be called before Bluetooth API starts. \n + * You must free all resources of the Bluetooth service by calling bt_deinitialize() if Bluetooth service is no longer needed. + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_deinitialize() + */ +int bt_initialize(void); + + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_MODULE + * @brief Releases all resources of the Bluetooth API. + * @since_tizen 2.3 + * + * @remarks This function must be called if Bluetooth API is no longer needed. + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre Bluetooth API must be initialized with bt_initialize(). + * + * @see bt_initialize() + */ +int bt_deinitialize(void); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Enables the local Bluetooth adapter, asynchronously. + * @since_tizen 2.3 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * + * @details This function enables Bluetooth protocol stack and hardware. + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_ALREADY_DONE Already enabled + * @retval #BT_ERROR_NOW_IN_PROGRESS Operation now in progress + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre Bluetooth service must be initialized with bt_initialize(). + * @pre The state of local Bluetooth must be #BT_ADAPTER_DISABLED + * @post This function invokes bt_adapter_state_changed_cb(). + * + * @see bt_initialize() + * @see bt_adapter_get_state() + * @see bt_adapter_set_state_changed_cb() + * @see bt_adapter_unset_state_changed_cb() + * @see bt_adapter_state_changed_cb() + * + */ +int bt_adapter_enable(void); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Disables the local Bluetooth adapter, asynchronously. + * @since_tizen 2.3 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * + * @details This function disables Bluetooth protocol stack and hardware. + * + * @remarks You should disable Bluetooth adapter, which is helpful for saving power. + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_NOW_IN_PROGRESS Operation now in progress + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED + * @post This function invokes bt_adapter_state_changed_cb(). + * + * @see bt_adapter_get_state() + * @see bt_adapter_state_changed_cb() + * @see bt_adapter_set_state_changed_cb() + * @see bt_adapter_unset_state_changed_cb () + * + */ +int bt_adapter_disable(void); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Recover the local Bluetooth adapter, asynchronously. + * @since_tizen 2.3 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * + * @details This function does recovery logic, disables Bluetooth protocol stack and hardware, then enables after a few seconds. + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_NOW_IN_PROGRESS Operation now in progress + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED + * @post This function invokes bt_adapter_state_changed_cb(). + * + * @see bt_adapter_get_state() + * @see bt_adapter_state_changed_cb() + * @see bt_adapter_set_state_changed_cb() + * @see bt_adapter_unset_state_changed_cb () + * + */ +int bt_adapter_recover(void); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Reset the local Bluetooth adapter, synchronously. + * @since_tizen 2.3 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * + * @details This function resets Bluetooth protocol and values. + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre Bluetooth service must be initialized with bt_initialize(). + * @post bt_adapter_state_changed_cb() will be invoked if The state of local Bluetooth was #BT_ADAPTER_ENABLED. + * + * @see bt_initialize() + * @see bt_adapter_get_state() + * @see bt_adapter_set_state_changed_cb() + * @see bt_adapter_unset_state_changed_cb() + * @see bt_adapter_state_changed_cb() + * + */ +int bt_adapter_reset(void); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Gets the current state of local Bluetooth adapter. + * @since_tizen 2.3 + * + * @param[out] adapter_state The current adapter state + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre Bluetooth service must be initialized with bt_initialize(). + * + * @see bt_initialize() + */ +int bt_adapter_get_state(bt_adapter_state_e *adapter_state); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Gets the address of local Bluetooth adapter. + * @since_tizen 2.3 + * + * @remarks The @a local_address must be released with free() by you. + * + * @param[out] local_address The device address of local Bluetooth adapter + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OUT_OF_MEMORY Out of memory + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * @see bt_adapter_get_name() + */ +int bt_adapter_get_address(char **local_address); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Gets the version of local Bluetooth adapter. + * @since_tizen 2.3 + * @remarks The @a local_version must be released with free() by you. + * + * @param[out] local_version The version of local Bluetooth adapter + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OUT_OF_MEMORY Out of memory + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + */ +int bt_adapter_get_version(char **local_version); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Gets the information regarding local Bluetooth adapter. + * @since_tizen 2.3 + * @remarks The @a all parameters must be released with free() by you. + * + * @param[out] chipset Chipset name of local Bluetooth adapter + * @param[out] firmware Firmware info. of local Bluetooth adapter + * @param[out] stack_version Bluetooth stack version + * @param[out] profiles The profile list of local Bluetooth adapter + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OUT_OF_MEMORY Out of memory + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + */ +int bt_adapter_get_local_info(char **chipset, char **firmware, char **stack_version, char **profiles); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Gets the name of local Bluetooth adapter. + * @since_tizen 2.3 + * + * @details Use this function to get the friendly name associated with Bluetooth + * device, retrieved by the remote Bluetooth devices. + * + * @remarks The @a local_name must be released with free() by you. + * + * @param[out] local_name The local device name + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OUT_OF_MEMORY Out of memory + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * + * @see bt_adapter_set_name() + */ +int bt_adapter_get_name(char **local_name); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Sets the name of local Bluetooth adapter. + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * + * @param[in] local_name The name of the Bluetooth device. \n + * The maximum length is 248 characters. + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * @post bt_adapter_name_changed_cb() will be invoked if this function returns #BT_ERROR_NONE. + * + * @see bt_adapter_get_name() + * @see bt_adapter_name_changed_cb() + * @see bt_adapter_set_name_changed_cb() + * @see bt_adapter_unset_name_changed_cb() + */ +int bt_adapter_set_name(const char *local_name); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Gets the visibility mode of local Bluetooth adapter. + * @since_tizen 2.3 + * @param[out] mode The visibility mode of the Bluetooth device + * @param[out] duration The duration until the visibility mode is changed to #BT_ADAPTER_VISIBILITY_MODE_NON_DISCOVERABLE (in seconds). + * @a duration is valid only if @a mode is #BT_ADAPTER_VISIBILITY_MODE_LIMITED_DISCOVERABLE. This value can be NULL. + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + */ +int bt_adapter_get_visibility(bt_adapter_visibility_mode_e *mode, int *duration); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Sets the visibility mode. + * @since_tizen 2.3 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * + * @remarks #BT_ADAPTER_VISIBILITY_MODE_LIMITED_DISCOVERABLE will change to #BT_ADAPTER_VISIBILITY_MODE_NON_DISCOVERABLE + * after the given @a duration goes. + * + * @param[in] discoverable_mode The Bluetooth visibility mode to set + * @param[in] duration The duration until the visibility mode is changed to #BT_ADAPTER_VISIBILITY_MODE_NON_DISCOVERABLE (in seconds). + * @a duration is used only for #BT_ADAPTER_VISIBILITY_MODE_LIMITED_DISCOVERABLE mode. + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * @post bt_adapter_visibility_mode_changed_cb() will be invoked if this function returns #BT_ERROR_NONE. + * + * @see bt_adapter_get_visibility() + * @see bt_adapter_visibility_mode_changed_cb() + * @see bt_adapter_set_visibility_mode_changed_cb() + * @see bt_adapter_unset_visibility_mode_changed_cb() + */ +int bt_adapter_set_visibility(bt_adapter_visibility_mode_e discoverable_mode, int duration); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Starts the device discovery, asynchronously. + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * + * @details If a device is discovered, bt_adapter_device_discovery_state_changed_cb() will be invoked + * with #BT_ADAPTER_DEVICE_DISCOVERY_FOUND, and then bt_adapter_device_discovery_state_changed_cb() + * will be called with #BT_ADAPTER_DEVICE_DISCOVERY_FINISHED in case of the completion or cancellation of the discovery. + * + * @remarks To connect to peer Bluetooth device, you need to know its Bluetooth address. \n + * The device discovery can be stopped by bt_adapter_stop_device_discovery(). + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_NOW_IN_PROGRESS Operation is now in progress + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * @post This function invokes bt_adapter_device_discovery_state_changed_cb(). + * + * @see bt_adapter_is_discovering() + * @see bt_adapter_stop_device_discovery() + * @see bt_adapter_device_discovery_state_changed_cb() + * @see bt_adapter_set_device_discovery_state_changed_cb() + * @see bt_adapter_unset_device_discovery_state_changed_cb() + */ +int bt_adapter_start_device_discovery(void); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Stops the device discovery, asynchronously. + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * @remarks The device discovery process will take 10 ~ 20 seconds to get all the devices in vicinity. + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_NOT_IN_PROGRESS Operation is not in progress + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The device discovery must be in progress with bt_adapter_start_device_discovery(). + * @post This function invokes bt_adapter_device_discovery_state_changed_cb(). + * + * @see bt_adapter_is_discovering() + * @see bt_adapter_start_device_discovery() + * @see bt_adapter_set_device_discovery_state_changed_cb() + * @see bt_adapter_unset_device_discovery_state_changed_cb() + * @see bt_adapter_device_discovery_state_changed_cb() + */ +int bt_adapter_stop_device_discovery(void); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Checks for the device discovery is in progress or not. + * @since_tizen 2.3 + * + * @remarks If Bluetooth discovery is in progress, other operations are not allowed and + * you have to either stop the discovery operation, or wait for it to be finished, + * before performing other operations. + + * @param[out] is_discovering The discovering status: (@c true = in progress , @c false = not in progress ) + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * + * @see bt_adapter_start_device_discovery() + * @see bt_adapter_stop_device_discovery() + */ +int bt_adapter_is_discovering(bool *is_discovering); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Get the service mask from the uuid list. + * @since_tizen 2.3 + * + * @param[in] uuids The UUID list of the device. + * @param[in] no_of_service The number of the UUID list count. + * @param[out] service_mask_list Service mask list converted from the given UUID list. + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_service_class_t + */ +int bt_device_get_service_mask_from_uuid_list(char **uuids, + int no_of_service, + bt_service_class_t *service_mask_list); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Retrieves the device information of all bonded devices. + * @since_tizen 2.3 + * + * @param [in] callback The callback function to invoke + * @param [in] user_data The user data passed from the foreach function + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_OUT_OF_MEMORY Out of memory + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * @post This function invokes bt_adapter_bonded_device_cb(). + * + * @see bt_adapter_bonded_device_cb() + */ +int bt_adapter_foreach_bonded_device(bt_adapter_bonded_device_cb callback, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Gets the device information of a bonded device. + * @since_tizen 2.3 + * @remarks The @a device_info must be released with bt_adapter_free_device_info() by you . + * + * @param [in] remote_address The address of remote device + * @param [out] device_info The bonded device information + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_OUT_OF_MEMORY Out of memory + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_BONDED Remote device not bonded + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * @post This function invokes bt_adapter_bonded_device_cb(). + * + * @see bt_adapter_bonded_device_cb() + */ +int bt_adapter_get_bonded_device_info(const char *remote_address, bt_device_info_s **device_info); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Frees device info. + * @since_tizen 2.3 + * + * @param [in] device_info The bonded device information + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_adapter_get_bonded_device_info() + */ +int bt_adapter_free_device_info(bt_device_info_s *device_info); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Checks whether the UUID of service is used or not + * @since_tizen 2.3 + * @param[in] service_uuid The UUID of service + * @param[out] used Indicates whether the service is used or not + * @return true on success, otherwise false. + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + */ +int bt_adapter_is_service_used(const char *service_uuid, bool *used); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Registers a callback function to be invoked when the Bluetooth adapter state changes. + * @since_tizen 2.3 + * + * @param[in] callback The callback function to invoke + * @param[in] user_data The user data to be passed to the callback function + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @post bt_adapter_state_changed_cb() will be invoked. + * + * @see bt_initialize() + * @see bt_adapter_state_changed_cb() + * @see bt_adapter_set_state_changed_cb() + * @see bt_adapter_unset_state_changed_cb() + */ +int bt_adapter_set_state_changed_cb(bt_adapter_state_changed_cb callback, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Unregisters the callback function. + * @since_tizen 2.3 + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * + * @see bt_initialize() + * @see bt_adapter_set_state_changed_cb() + */ +int bt_adapter_unset_state_changed_cb(void); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Registers a callback function to be invoked when the name of Bluetooth adapter changes. + * @since_tizen 2.3 + * + * @param[in] callback The callback function to invoke + * @param[in] user_data The user data to be passed to the callback function + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @post bt_adapter_name_changed_cb() will be invoked. + * + * @see bt_initialize() + * @see bt_adapter_name_changed_cb() + * @see bt_adapter_unset_name_changed_cb() + */ +int bt_adapter_set_name_changed_cb(bt_adapter_name_changed_cb callback, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Unregisters the callback function. + * @since_tizen 2.3 + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * + * @see bt_initialize() + * @see bt_adapter_set_name_changed_cb() + */ +int bt_adapter_unset_name_changed_cb(void); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Registers a callback function to be invoked when the visibility mode changes. + * @since_tizen 2.3 + * + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @post bt_adapter_visibility_mode_changed_cb() will be invoked. + * + * @see bt_initialize() + * @see bt_adapter_visibility_mode_changed_cb() + * @see bt_adapter_unset_visibility_mode_changed_cb() + */ +int bt_adapter_set_visibility_mode_changed_cb(bt_adapter_visibility_mode_changed_cb callback, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Unregisters the callback function. + * @since_tizen 2.3 + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * + * @see bt_initialize() + * @see bt_adapter_set_visibility_mode_changed_cb() + */ +int bt_adapter_unset_visibility_mode_changed_cb(void); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Registers a callback function to be invoked every second + * @since_tizen 2.3 + * until the visibility mode is changed from #BT_ADAPTER_VISIBILITY_MODE_LIMITED_DISCOVERABLE + * to #BT_ADAPTER_VISIBILITY_MODE_NON_DISCOVERABLE. + * @details When you set visibility mode as #BT_ADAPTER_VISIBILITY_MODE_LIMITED_DISCOVERABLE, + * @a callback will be called every second until visibility mode is changed to #BT_ADAPTER_VISIBILITY_MODE_NON_DISCOVERABLE. + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized by bt_initialize(). + * @post bt_adapter_visibility_duration_changed_cb() will be invoked. + * @see bt_initialize() + * @see bt_adapter_visibility_duration_changed_cb() + * @see bt_adapter_unset_visibility_duration_changed_cb() + */ +int bt_adapter_set_visibility_duration_changed_cb(bt_adapter_visibility_duration_changed_cb callback, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Unregisters the callback function. + * @since_tizen 2.3 + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @see bt_initialize() + * @see bt_adapter_set_visibility_duration_changed_cb() + */ +int bt_adapter_unset_visibility_duration_changed_cb(void); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Registers a callback function to be invoked when the device discovery state changes. + * @since_tizen 2.3 + * + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @post bt_adapter_device_discovery_state_changed_cb() will be invoked. + * + * @see bt_initialize() + * @see bt_adapter_device_discovery_state_changed_cb() + * @see bt_adapter_set_device_discovery_state_changed_cb() + * @see bt_adapter_unset_device_discovery_state_changed_cb() + */ +int bt_adapter_set_device_discovery_state_changed_cb(bt_adapter_device_discovery_state_changed_cb callback, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Unregisters the callback function. + * @since_tizen 2.3 + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * + * @see bt_initialize() + * @see bt_adapter_set_device_discovery_state_changed_cb() + */ +int bt_adapter_unset_device_discovery_state_changed_cb(void); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Get the Hash and Randmoizer value, synchronously. + * @since_tizen 2.3 + * + * @param[out] hash The hash value recieved from the controller + * @param[out] randomizer The hash value recieved from the controller + * @param[out] hash_len The length of the hash value + * @param[out] randomizer_len The length of the randomizer value + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @see bt_initialize() + */ +int bt_adapter_get_local_oob_data(unsigned char **hash, unsigned char **randomizer, + int *hash_len, int *randomizer_len); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Sets the Hash and Randmoizer value, synchronously. + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * + * @param[in] remote_address Remote device address + * @param[in] hash The hash value recieved from the controller + * @param[in] randomizer The hash value recieved from the controller + * @param[in] hash_len The length of the hash value. Allowed value is 16 + * @param[in] randomizer_len The length of the randomizer value. Allowed value is 16 + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @see bt_initialize() + */ +int bt_adapter_set_remote_oob_data(const char *remote_address, + unsigned char *hash, unsigned char *randomizer, + int hash_len, int randomizer_len); +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Deletes the Hash and Randomizer value, synchronously. + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * + * @param[in] remote_address Remote device address + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @see bt_initialize() + */ +int bt_adapter_remove_remote_oob_data(const char *remote_address); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Registers a callback function to be invoked when the connectable state changes. + * @since_tizen 2.3 + * + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @post bt_adapter_connectable_changed_cb() will be invoked. + * + * @see bt_initialize() + * @see bt_adapter_connectable_changed_cb() + * @see bt_adapter_unset_connectable_changed_cb() + */ +int bt_adapter_set_connectable_changed_cb(bt_adapter_connectable_changed_cb callback, void *user_data); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Unregisters the callback function. + * @since_tizen 2.3 + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * + * @see bt_initialize() + * @see bt_adapter_set_connectable_changed_cb() + */ +int bt_adapter_unset_connectable_changed_cb(void); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Gets the connectable state of local Bluetooth adapter. + * @since_tizen 2.3 + * + * @remarks When connectable state is false, no device can connect to this device and visibility mode cannot be changed. + * + * @param[out] connectable The connectable state of local Bluetooth adapter + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * + * @see bt_adapter_set_connectable() + */ +int bt_adapter_get_connectable(bool *connectable); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Sets the connectable state of local Bluetooth adapter. + * @since_tizen 2.3 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * + * @remarks When connectable state is false, no device can connect to this device and visibility mode cannot be changed. + * + * @param[in] connectable The connectable state to set + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * @post bt_adapter_connectable_changed_cb() will be invoked if this function returns #BT_ERROR_NONE. + * + * @see bt_adapter_get_connectable() + * @see bt_adapter_connectable_changed_cb() + * @see bt_adapter_set_connectable_changed_cb() + * @see bt_adapter_unset_connectable_changed_cb() + */ +int bt_adapter_set_connectable(bool connectable); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Enables the local Bluetooth le adapter, asynchronously. + * @since_tizen 2.3 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * + * @details This function enables Bluetooth protocol stack and hardware. + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_ALREADY_DONE Already enabled + * @retval #BT_ERROR_NOW_IN_PROGRESS Operation now in progress + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre Bluetooth service must be initialized with bt_initialize(). + * @post This function invokes bt_adapter_le_state_changed_cb(). + * + * @see bt_initialize() + * @see bt_adapter_le_get_state() + * @see bt_adapter_le_set_state_changed_cb() + * @see bt_adapter_le_unset_state_changed_cb() + * @see bt_adapter_le_state_changed_cb() + * + */ +int bt_adapter_le_enable(void); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Disables the local Bluetooth le adapter, asynchronously. + * @since_tizen 2.3 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * + * @details This function disables Bluetooth le protocol stack and hardware. + * + * @remarks + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_NOW_IN_PROGRESS Operation now in progress + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_LE_ENABLED + * @post This function invokes bt_adapter_le_state_changed_cb(). + * + * @see bt_adapter_le_get_state() + * @see bt_adapter_le_state_changed_cb() + * @see bt_adapter_le_set_state_changed_cb() + * @see bt_adapter_le_unset_state_changed_cb () + * + */ +int bt_adapter_le_disable(void); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Gets the current state of local Bluetooth adapter. + * @since_tizen 2.3 + * + * @param[out] adapter_le_state The current adapter le state + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre Bluetooth service must be initialized with bt_initialize(). + * + * @see bt_initialize() + */ +int bt_adapter_le_get_state(bt_adapter_le_state_e *adapter_le_state); + +/** + * @deprecated Deprecated since 2.3.1 + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Starts the LE device discovery. + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * + * @details If a LE device is discovered, bt_adapter_le_device_discovery_state_changed_cb() +* will be invoked with #BT_ADAPTER_LE_DEVICE_DISCOVERY_FOUND, and then bt_adapter_le_device_discovery_state_changed_cb() + * will be called with #BT_ADAPTER_LE_DEVICE_DISCOVERY_FINISHED in case of the completion or cancellation of the discovery. + * + * @remarks To connect to peer Bluetooth device, you need to know its Bluetooth address. \n + * The device discovery can be stopped by bt_adapter_le_stop_device_discovery(). + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_NOW_IN_PROGRESS Operation is now in progress + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * @post This function invokes bt_adapter_le_device_discovery_state_changed_cb(). + * + * @see bt_adapter_le_is_discovering() + * @see bt_adapter_le_device_discovery_state_changed_cb() + * @see bt_adapter_le_set_device_discovery_state_changed_cb() + * @see bt_adapter_le_unset_device_discovery_state_changed_cb() + */ +int bt_adapter_le_start_device_discovery(void); + +/** + * @deprecated Deprecated since 2.3.1 + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Stops the LE device discovery, asynchronously. + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_NOT_IN_PROGRESS Operation is not in progress + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The device discovery must be in progress with bt_adapter_le_start_device_discovery(). + * @post This function invokes bt_adapter_le_device_discovery_state_changed_cb(). + * + * @see bt_adapter_le_is_discovering() + * @see bt_adapter_le_start_device_discovery() + * @see bt_adapter_le_set_device_discovery_state_changed_cb() + * @see bt_adapter_le_unset_device_discovery_state_changed_cb() + * @see bt_adapter_le_device_discovery_state_changed_cb() + */ +int bt_adapter_le_stop_device_discovery(void); + +/** + * @deprecated Deprecated since 2.3.1 + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Checks for the LE device discovery is in progress or not. + * @since_tizen 2.3 + * + * @remarks If Bluetooth LE discovery is in progress, other operations are not allowed and + * you have to either stop the LE discovery operation, or wait for it to be finished, + * before performing other operations. + + * @param[out] is_discovering The discovering status: (@c true = in progress , @c false = not in progress ) + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * + * @see bt_adapter_le_start_device_discovery() + * @see bt_adapter_le_stop_device_discovery() + */ +int bt_adapter_le_is_discovering(bool *is_discovering); + +/** + * @deprecated Deprecated since 2.3.1 + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Registers a callback function to be invoked when the LE device discovery state changes. + * @since_tizen 2.3 + * + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @post bt_adapter_le_device_discovery_state_changed_cb() will be invoked. + * + * @see bt_initialize() + * @see bt_adapter_le_device_discovery_state_changed_cb() + * @see bt_adapter_le_unset_device_discovery_state_changed_cb() + */ +int bt_adapter_le_set_device_discovery_state_changed_cb(bt_adapter_le_device_discovery_state_changed_cb callback, void *user_data); + +/** + * @deprecated Deprecated since 2.3.1 + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Unregisters the callback function. + * @since_tizen 2.3 + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * + * @see bt_initialize() + * @see bt_adapter_le_set_device_discovery_state_changed_cb() + */ +int bt_adapter_le_unset_device_discovery_state_changed_cb(void); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Starts the LE scan to find LE advertisement. + * @since_tizen 2.3.1 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * + * @details If a LE advertisement is found, bt_adapter_le_scan_result_cb() will be invoked. + * + * @param[in] cb The callback to report the result of this function + * @param[in] user_data The user data to be passed when callback is called + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_NOW_IN_PROGRESS Operation is now in progress + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * @post This function invokes bt_adapter_le_scan_result_cb(). + * + * @see bt_adapter_le_scan_result_cb() + */ +int bt_adapter_le_start_scan(bt_adapter_le_scan_result_cb cb, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Stops the LE scan. + * @since_tizen 2.3.1 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_NOT_IN_PROGRESS Operation is not in progress + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The LE scan must be in progress with bt_adapter_le_start_scan(). + * + * @see bt_adapter_le_start_scan() + */ +int bt_adapter_le_stop_scan(void); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Gets the service UUID list from the scan result information + * @since_tizen 2.3.1 + * + * @remarks The @a uuids must be iterated as count and each pointed data must be released with free(). + * Then uuids must be released with free(). \n + * 16-bit service UUID or 128-bit service UUID is supported. (e.g. 180F, 0000180F-0000-1000-8000-00805F9B34FB) + * + * @param[in] info The scan result information + * @param[in] pkt_type The packet type + * @param[out] uuids The list of string of the service uuid + * @param[out] count The count of the service UUIDs + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NO_DATA No data available + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * + * @see bt_adapter_le_scan_result_cb() + */ +int bt_adapter_le_get_scan_result_service_uuids(const bt_adapter_le_device_scan_result_info_s *info, + bt_adapter_le_packet_type_e pkt_type, char ***uuids, int *count); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Gets the device name from the scan result information + * @since_tizen 2.3.1 + * + * @remarks The @a name must be released with free() by you. + * + * @param[in] info The scan result information + * @param[in] pkt_type The packet type + * @param[out] name The device name + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NO_DATA No data available + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * + * @see bt_adapter_le_scan_result_cb() + */ +int bt_adapter_le_get_scan_result_device_name(const bt_adapter_le_device_scan_result_info_s *info, + bt_adapter_le_packet_type_e pkt_type, char **name); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Gets the transmission power level from the scan result information + * @since_tizen 2.3.1 + * + * @param[in] info The scan result information + * @param[in] pkt_type The packet type + * @param[out] power_level The transmission power level in dBm + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NO_DATA No data available + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * + * @see bt_adapter_le_scan_result_cb() + */ +int bt_adapter_le_get_scan_result_tx_power_level(const bt_adapter_le_device_scan_result_info_s *info, + bt_adapter_le_packet_type_e pkt_type, int *power_level); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Gets the service solicitation UUID list from the scan result information + * @since_tizen 2.3.1 + * + * @remarks The @a uuids must be iterated as count and each pointed data must be released with free(). + * Then uuids must be released with free(). \n + * 16-bit service solicitation UUID or 128-bit service solicitaion UUID is supported. + * (e.g. 180F, 0000180F-0000-1000-8000-00805F9B34FB) + * + * @param[in] info The scan result information + * @param[in] pkt_type The packet type + * @param[out] uuids The list of string of the service solicitation uuid + * @param[out] count The count of the service UUIDs + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NO_DATA No data available + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * + * @see bt_adapter_le_scan_result_cb() + */ +int bt_adapter_le_get_scan_result_service_solicitation_uuids(const bt_adapter_le_device_scan_result_info_s *info, + bt_adapter_le_packet_type_e pkt_type, char ***uuids, int *count); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Gets the service data list from the scan result information + * @since_tizen 2.3.1 + * + * @remarks The @a data_list must be released with bt_adapter_le_free_service_data_list() by you . + * + * @param[in] info The scan result information + * @param[in] pkt_type The packet type + * @param[out] data_list The list of the service data + * @param[out] count The count of the service data list + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NO_DATA No data available + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * + * @see bt_adapter_le_scan_result_cb() + */ +int bt_adapter_le_get_scan_result_service_data_list(const bt_adapter_le_device_scan_result_info_s *info, + bt_adapter_le_packet_type_e pkt_type, bt_adapter_le_service_data_s **data_list, int *count); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Frees service data list. + * @since_tizen 2.3.1 + * + * @param[in] data_list The list of the service data + * @param[in] count The count of the service data list + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_adapter_le_get_scan_result_service_data_list() + */ +int bt_adapter_le_free_service_data_list(bt_adapter_le_service_data_s *data_list, int count); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Gets the appearance from the scan result information + * @since_tizen 2.3.1 + * + * @param[in] info The scan result information + * @param[in] pkt_type The packet type + * @param[out] appearance The appearance + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NO_DATA No data available + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * + * @see bt_adapter_le_scan_result_cb() + */ +int bt_adapter_le_get_scan_result_appearance(const bt_adapter_le_device_scan_result_info_s *info, + bt_adapter_le_packet_type_e pkt_type, int *appearance); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Gets the manufacturer data from the scan result information + * @since_tizen 2.3.1 + * + * @remarks The @a manufacturer_data must be released with free() by you. + * + * @param[in] info The scan result information + * @param[in] pkt_type The packet type + * @param[out] manufacturer_id The manufacturer ID + * @param[out] manufacturer_data The manufacturer data (byte array) + * @param[out] manufacturer_data_len The length of manufacturer data + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NO_DATA No data available + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * + * @see bt_adapter_le_scan_result_cb() + */ +int bt_adapter_le_get_scan_result_manufacturer_data(const bt_adapter_le_device_scan_result_info_s *info, + bt_adapter_le_packet_type_e pkt_type, int *manufacturer_id, char **manufacturer_data, int *manufacturer_data_len); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Registers a callback function to be invoked when the Bluetooth adapter le state changes. + * @since_tizen 2.3 + * + * @param[in] callback The callback function to invoke + * @param[in] user_data The user data to be passed to the callback function + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @post bt_adapter_le_state_changed_cb() will be invoked. + * + * @see bt_initialize() + * @see bt_adapter_le_state_changed_cb() + * @see bt_adapter_le_unset_state_changed_cb() + */ +int bt_adapter_le_set_state_changed_cb(bt_adapter_le_state_changed_cb callback, void *user_data); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Unregisters the callback function. + * @since_tizen 2.3 + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * + * @see bt_initialize() + * @see bt_adapter_le_set_state_changed_cb() + */ +int bt_adapter_le_unset_state_changed_cb(void); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief add address to whitelist for accepting scanning request. + * @since_tizen 2.3 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * + * @remarks If the adress is in the whitelist then other LE devices are able to + * search this device. Before calling this API, make sure that the adapter is + * enabled. There is no callback event for this API. + + * @param[in] address The other device's address + * @param[in] address_type The other device's address type + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Adapter is not enabled + * @retval #BT_ERROR_RESOURCE_BUSY Device or resource busy + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * + * @see bt_adapter_le_start_advertising_new() + * @see bt_adapter_le_stop_advertising() + */ +int bt_adapter_le_add_white_list(const char *address, bt_device_address_type_e address_type); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief remove address from the whitelist for not accepting scanning request. + * @since_tizen 2.3 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * + * @remarks If the adress is in the whitelist then other LE devices are able to + * search this device. Before calling this API, make sure that the adapter is + * enabled. There is no callback event for this API. + * + * @param[in] address The other device's address + * @param[in] address_type The other device's address type + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Adapter is not enabled + * @retval #BT_ERROR_RESOURCE_BUSY Device or resource busy + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * + * @see bt_adapter_le_start_advertising_new() + * @see bt_adapter_le_stop_advertising() + */ +int bt_adapter_le_remove_white_list(const char *address, bt_device_address_type_e address_type); + +/** + * @internal + * @deprecated Deprecated since 2.3.1 + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief clear address from the whitelist for not accepting scanning request. + * @since_tizen 2.3 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * + * @remarks If the adress is in the whitelist then other LE devices are able to + * search this device. Before calling this API, make sure that the adapter is + * enabled. There is no callback event for this API. + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Adapter is not enabled + * @retval #BT_ERROR_RESOURCE_BUSY Device or resource busy + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * + * @see bt_adapter_le_start_advertising_new() + * @see bt_adapter_le_stop_advertising() + */ +int bt_adapter_le_clear_white_list(void); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Create advertiser to advertise device's existence or respond to LE scanning reqeust. + * @since_tizen 2.3 + * + * @param[out] advertiser The handle of advertiser + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_OUT_OF_MEMORY Out of memory + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * + * @see bt_adapter_le_destroy_advertiser() + */ +int bt_adapter_le_create_advertiser(bt_advertiser_h *advertiser); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Destroy advertiser. + * @since_tizen 2.3 + * + * @param[out] advertiser The handle of advertiser + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * + * @see bt_adapter_le_create_advertiser() + */ +int bt_adapter_le_destroy_advertiser(bt_advertiser_h advertiser); + +/** + * @deprecated Deprecated since 2.3.1 + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Set the data to be advertised or responded to scan request from LE scanning device. + * The maximum advertised or responded data size is 31 bytes + * including data type and system wide data. + * @since_tizen 2.3 + * + * @remarks In case the data_type is local name or tx power level, you don't need to input data + * because the data value is written automatically by system. + * + * @param[in] advertiser The handle of advertiser + * @param[in] pkt_type The packet type + * @param[in] data_type The data type that is included in packet + * @param[in] data The data to be advertised or be responded to scan request from LE scanning device, no need in case of LOCAL_NAME or TX_POWER_LEVEL + * @param[in] data_size The size of data to be set. + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_QUOTA_EXCEEDED Quota exceeded + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * + * @see bt_adapter_le_clear_advertising_data() + */ +int bt_adapter_le_add_advertising_data(bt_advertiser_h advertiser, + bt_adapter_le_packet_type_e pkt_type, bt_adapter_le_packet_data_type_e data_type, + void *data, unsigned int data_size); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Add a service UUID to advertise or scan response data. + * The maximum advertised or responded data size is 31 bytes + * including data type and system wide data. + * @since_tizen 2.3.1 + * + * @remarks 16-bit UUID or 128-bit UUID is supported. (e.g. 180F, 0000180F-0000-1000-8000-00805F9B34FB) + * + * @param[in] advertiser The handle of advertiser + * @param[in] pkt_type The packet type + * @param[in] uuid The string of the service UUID. + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_QUOTA_EXCEEDED Quota exceeded + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * + * @see bt_adapter_le_clear_advertising_data() + */ +int bt_adapter_le_add_advertising_service_uuid(bt_advertiser_h advertiser, + bt_adapter_le_packet_type_e pkt_type, const char *uuid); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Add a service solicitation UUID to advertise or scan response data. + * The maximum advertised or responded data size is 31 bytes + * including data type and system wide data. + * @since_tizen 2.3.1 + * + * @remarks 16-bit service solicitation UUID or 128-bit service solicitation UUID is supported. + * (e.g. 180F, 0000180F-0000-1000-8000-00805F9B34FB) + * + * @param[in] advertiser The handle of advertiser + * @param[in] pkt_type The packet type + * @param[in] uuid The string of the service solicitation UUID. + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_QUOTA_EXCEEDED Quota exceeded + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * + * @see bt_adapter_le_clear_advertising_data() + */ +int bt_adapter_le_add_advertising_service_solicitation_uuid(bt_advertiser_h advertiser, + bt_adapter_le_packet_type_e pkt_type, const char *uuid); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Add service data to advertise or scan response data. + * The maximum advertised or responded data size is 31 bytes + * including data type and system wide data. + * @since_tizen 2.3.1 + * + * @remarks 16-bit UUID is supported. (e.g. 180F) + * + * @param[in] advertiser The handle of advertiser + * @param[in] pkt_type The packet type + * @param[in] uuid 16-bit UUID of the service + * @param[in] service_data The service data + * @param[in] service_data_len The data length of service data + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_QUOTA_EXCEEDED Quota exceeded + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * + * @see bt_adapter_le_clear_advertising_data() + */ +int bt_adapter_le_add_advertising_service_data(bt_advertiser_h advertiser, + bt_adapter_le_packet_type_e pkt_type, const char *uuid, + const char *service_data, int service_data_len); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Sets the external appearance of this device to advertise or scan response data. + * Please refer to the adopted Bluetooth specification for the the appearance. + * @since_tizen 2.3.1 + * + * @param[in] advertiser The handle of advertiser + * @param[in] pkt_type The packet type + * @param[in] appearance The external appearance of device + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_QUOTA_EXCEEDED Quota exceeded + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * + * @see bt_adapter_le_clear_advertising_data() + */ +int bt_adapter_le_set_advertising_appearance(bt_advertiser_h advertiser, + bt_adapter_le_packet_type_e pkt_type, int appearance); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Add manufacturer specific data to advertise or scan response data. + * Please refer to the Bluetooth Assigned Numbers provided by the Bluetooth SIG for a list of existing company identifiers. + * The maximum advertised or responded data size is 31 bytes + * including data type and system wide data. + * @since_tizen 2.3.1 + * + * + * @param[in] advertiser The handle of advertiser + * @param[in] pkt_type The packet type + * @param[in] manufacturer_id Manufacturer identifier + * @param[in] manufacturer_data The manufacturer specific data + * @param[in] manufacturer_data_len The data length of manufacturer data + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_QUOTA_EXCEEDED Quota exceeded + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * + * @see bt_adapter_le_clear_advertising_data() + */ +int bt_adapter_le_add_advertising_manufacturer_data(bt_advertiser_h advertiser, + bt_adapter_le_packet_type_e pkt_type, int manufacturer_id, const char *manufacturer_data, int manufacturer_data_len); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Set whether the device name should be included in advertise or scan response data. + * The maximum advertised or responded data size is 31 bytes + * including data type and system wide data. + * @since_tizen 2.3.1 + * + * @param[in] advertiser The handle of advertiser + * @param[in] pkt_type The packet type + * @param[in] include_name Whether the device name should be included + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_QUOTA_EXCEEDED Quota exceeded + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * + * @see bt_adapter_le_clear_advertising_data() + */ +int bt_adapter_le_set_advertising_device_name(bt_advertiser_h advertiser, + bt_adapter_le_packet_type_e pkt_type, bool include_name); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Set whether the transmission power level should be included in advertise or scan response data. + * The maximum advertised or responded data size is 31 bytes + * including data type and system wide data. + * @since_tizen 2.3.1 + * + * @param[in] advertiser The handle of advertiser + * @param[in] pkt_type The packet type + * @param[in] include_tx_power Whether the transmission power level should be included + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_QUOTA_EXCEEDED Quota exceeded + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * + * @see bt_adapter_le_clear_advertising_data() + */ +int bt_adapter_le_set_advertising_tx_power_level(bt_advertiser_h advertiser, + bt_adapter_le_packet_type_e pkt_type, bool include_tx_power); + +/** + * @deprecated Deprecated since 2.3.1 + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Unset the data to be advertised or responded to scan request from LE scanning device. + * @since_tizen 2.3 + * + * @param[in] advertiser The handle of advertiser + * @param[in] pkt_type The packet type + * @param[in] data_type The data type to be removed from selected packet + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * + * @see bt_adapter_le_add_advertising_data() + * @see bt_adapter_le_clear_advertising_data() + */ +int bt_adapter_le_remove_advertising_data(bt_advertiser_h advertiser, + bt_adapter_le_packet_type_e pkt_type, bt_adapter_le_packet_data_type_e data_type); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Clear all data to be advertised or responded to scan request from LE scanning device. + * @since_tizen 2.3 + * + * @param[in] advertiser The handle of advertiser + * @param[in] pkt_type The packet type to be cleared + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * + * @see bt_adapter_le_add_advertising_data() + */ +int bt_adapter_le_clear_advertising_data(bt_advertiser_h advertiser, bt_adapter_le_packet_type_e pkt_type); + +/** + * @deprecated Deprecated since 2.3.1 + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Start advertising with passed advertiser and advertising parameters. + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * + * @details Once Bluetooth advertising is started, nearby Bluetooth LE(Low Energy) supported + * devices can know this device's existence. And one of them can make a connection reqeust, + * if it is allowed. + * + * @param[in] advertiser The handle of advertiser + * @param[in] adv_params The parameters of advertising \n + * If NULL is passed, default values which are defined in driver / controller are used. + * @param[in] cb The callback to report the result of this function + * @param[in] user_data The user data to be passed when callback is called + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_NOW_IN_PROGRESS Operation is now in progress + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @post This function invokes bt_adapter_le_advertising_state_changed_cb(). + * + * @see bt_adapter_le_stop_advertising() + * @see bt_adapter_le_advertising_state_changed_cb() + */ +int bt_adapter_le_start_advertising(bt_advertiser_h advertiser, bt_adapter_le_advertising_params_s *adv_params, + bt_adapter_le_advertising_state_changed_cb cb, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Stops the advertising. + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * + * @param[in] advertiser The handle of advertiser + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_NOT_IN_PROGRESS Operation is not in progress + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The advertising must be going on with bt_adapter_le_start_advertising_new(). + * @post This function invokes bt_adapter_le_advertising_state_changed_cb(). + * + * @see bt_adapter_le_start_advertising_new() + * @see bt_adapter_le_advertising_state_changed_cb() + */ +int bt_adapter_le_stop_advertising(bt_advertiser_h advertiser); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Start advertising with passed advertiser and advertising parameters. + * @since_tizen 2.3.1 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * + * @details Once Bluetooth advertising is started, nearby Bluetooth LE(Low Energy) supported + * devices can know this device's existence. And one of them can make a connection reqeust, + * if it is allowed. + * + * @param[in] advertiser The handle of advertiser + * @param[in] cb The callback to report the result of this function + * @param[in] user_data The user data to be passed when callback is called + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_NOW_IN_PROGRESS Operation is now in progress + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @post This function invokes bt_adapter_le_advertising_state_changed_cb(). + * + * @see bt_adapter_le_stop_advertising() + * @see bt_adapter_le_advertising_state_changed_cb() + */ +int bt_adapter_le_start_advertising_new(bt_advertiser_h advertiser, bt_adapter_le_advertising_state_changed_cb cb, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Set advertising mode to control the advertising power and latency. + * @since_tizen 2.3.1 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * + * @param[in] advertiser The handle of advertiser + * @param[in] mode The mode of advertising + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_NOW_IN_PROGRESS Operation is now in progress + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * + * @see bt_adapter_le_start_advertising_new() + */ +int bt_adapter_le_set_advertising_mode(bt_advertiser_h advertiser, bt_adapter_le_advertising_mode_e mode); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Set whether the advertising type should be connectable or non-connectable + * @since_tizen 2.3.1 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * + * @param[in] advertiser The handle of advertiser + * @param[in] connectable The type of advertising + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_NOW_IN_PROGRESS Operation is now in progress + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * + * @see bt_adapter_le_start_advertising_new() + */ +int bt_adapter_le_set_advertising_connectable(bt_advertiser_h advertiser, bool connectable); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Sets the Privacy feature state of local Bluetooth adapter. + * @since_tizen 2.3 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * + * @param[in] enable_privacy The privacy feature to set/unset. + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * @pre The state of local Bluetooth must be #BT_ADAPTER_LE_ENABLED. + * + */ +int bt_adapter_le_enable_privacy(bool enable_privacy); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Creates a bond with a remote Bluetooth device, asynchronously. + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * + * @remarks A bond can be destroyed by bt_device_destroy_bond().\n + * The bonding request can be cancelled by bt_device_cancel_bonding(). + * + * @param[in] remote_address The address of the remote Bluetooth device with which the bond should be created + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_RESOURCE_BUSY Device or resource busy + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * @pre The remote device must be discoverable with bt_adapter_start_device_discovery(). + * @post This function invokes bt_device_bond_created_cb(). + * + * @see bt_adapter_start_device_discovery() + * @see bt_device_bond_created_cb() + * @see bt_device_cancel_bonding() + * @see bt_device_destroy_bond() + * @see bt_device_set_bond_created_cb() + * @see bt_device_unset_bond_created_cb() + */ +int bt_device_create_bond(const char *remote_address); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Creates a bond with a remote Bluetooth device, asynchronously. + * @since_tizen 2.3 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * + * @remarks A bond can be destroyed by bt_device_destroy_bond().\n + * The bonding request can be cancelled by bt_device_cancel_bonding(). + * + * @param[in] remote_address The address of the remote Bluetooth device with which the bond should be created + * @param[in] conn_type The connection type(LE or BREDR) to create bond with remote device + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_RESOURCE_BUSY Device or resource busy + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * @pre The remote device must be discoverable with bt_adapter_start_device_discovery(). + * @post This function invokes bt_device_bond_created_cb(). + * + * @see bt_adapter_start_device_discovery() + * @see bt_device_create_bond() + * @see bt_device_bond_created_cb() + * @see bt_device_cancel_bonding() + * @see bt_device_destroy_bond() + * @see bt_device_set_bond_created_cb() + * @see bt_device_unset_bond_created_cb() + */ +int bt_device_create_bond_by_type(const char *remote_address, + bt_device_connection_link_type_e conn_type); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Cancels the bonding process. + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * + * @remarks Use this function when the remote Bluetooth device is not responding to the + * bond request or you wish to cancel the bonding request. + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_NOT_IN_PROGRESS Operation not in progress + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The creating a bond must be in progress by bt_device_create_bond(). + * + * @see bt_device_create_bond() + * @see bt_device_bond_created_cb() + * @see bt_device_set_bond_created_cb() + * @see bt_device_unset_bond_created_cb() + */ +int bt_device_cancel_bonding(void); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Destroys the bond, asynchronously. + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * + * @param[in] remote_address The address of the remote Bluetooth device to remove bonding + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_RESOURCE_BUSY Device or resource busy + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_BONDED Remote device not bonded + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * @pre The bond with the remote device must be created with bt_device_create_bond(). + * @post This function invokes bt_device_bond_destroyed_cb(). + * + * @see bt_device_create_bond() + * @see bt_device_bond_destroyed_cb() + * @see bt_device_set_bond_destroyed_cb() + * @see bt_device_unset_bond_destroyed_cb() + */ +int bt_device_destroy_bond(const char *remote_address); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Sets an alias for the bonded device. + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * + * @param[in] remote_address The address of the remote Bluetooth device + * @param[in] alias The alias of the remote Bluetooth device + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_BONDED Remote device not bonded + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * @pre The bond with the remote device must be created with bt_device_create_bond(). + * + * @see bt_device_create_bond() + */ +int bt_device_set_alias(const char *remote_address, const char *alias); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Sets the authorization of a bonded device, asynchronously. + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * + * @remarks Once a device is authorized, you don't need to receive a confirmation. + * + * @param[in] remote_address The address of the remote Bluetooth device to authorize + * @param[in] authorization_state The Bluetooth authorization state + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_BONDED Remote device not bonded + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * @pre The bond with the remote device must be created with bt_device_create_bond(). + * @post bt_device_authorization_changed_cb() will be invoked. + * + * @see bt_device_create_bond() + * @see bt_device_authorization_changed_cb() + * @see bt_device_set_authorization_changed_cb() + * @see bt_device_unset_authorization_changed_cb() + */ +int bt_device_set_authorization(const char *remote_address, bt_device_authorization_e authorization_state); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Starts the search for services supported by the specified device, asynchronously. + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * + * @remarks If creating a bond succeeds, which means bt_device_bond_created_cb() is called with result #BT_ERROR_NONE, + * then you don't need to run this function.\n + * The service search takes a couple of seconds to complete normally. \n + * + * @param[in] remote_address The address of the remote Bluetooth device whose services need to be checked + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_BONDED Remote device not bonded + * @retval #BT_ERROR_SERVICE_SEARCH_FAILED Service search failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * @pre The remote device must be discoverable with bt_adapter_start_device_discovery(). + * @pre The bond with the remote device must be created with bt_device_create_bond(). + * @post This function invokes bt_device_service_searched_cb(). + * + * @see bt_adapter_start_device_discovery() + * @see bt_device_create_bond() + * @see bt_device_bond_created_cb() + * @see bt_device_service_searched_cb() + * @see bt_device_set_service_searched_cb() + * @see bt_device_unset_service_searched_cb() + */ +int bt_device_start_service_search(const char *remote_address); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Cancels service search process. + * @since_tizen 2.3 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_BONDED Remote device not bonded + * @retval #BT_ERROR_NOT_IN_PROGRESS Operation not in progress + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The service search must be in progress by bt_device_start_service_search(). + * + * @see bt_device_start_service_search() + * @see bt_device_service_searched_cb() + * @see bt_device_set_service_searched_cb() + * @see bt_device_unset_service_searched_cb() + */ +int bt_device_cancel_service_search(void); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Gets the connected profiles. + * @since_tizen 2.3 + * @param[in] remote_address The address of the remote device + * @param[in] callback The callback function to invoke + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * @post bt_device_connected_profile() will be invoked. + * @see bt_device_connected_profile() + */ +int bt_device_foreach_connected_profiles(const char *remote_address, bt_device_connected_profile callback, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Gets the profile connected status. + * @since_tizen 2.3 + * @param[in] remote_address The address of the remote device + * @param[in] bt_profile wish to know bt_profile + * @param[out] connected_status the connected status + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_BONDED Remote device not bonded + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + */ +int bt_device_is_profile_connected(const char *remote_address, bt_profile_e bt_profile, + bool *connected_status); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Registers a callback function to be invoked when the bond creates. + * @since_tizen 2.3 + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @post bt_device_bond_created_cb() will be invoked. + * @see bt_initialize() + * @see bt_device_bond_created_cb() + * @see bt_device_unset_bond_created_cb() + */ +int bt_device_set_bond_created_cb(bt_device_bond_created_cb callback, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Unregisters the callback function. + * @since_tizen 2.3 + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @see bt_initialize() + * @see bt_device_set_bond_created_cb() + */ +int bt_device_unset_bond_created_cb(void); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Registers a callback function to be invoked when the bond destroys. + * @since_tizen 2.3 + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @post bt_device_bond_destroyed_cb() will be invoked. + * @see bt_initialize() + * @see bt_device_bond_destroyed_cb() + * @see bt_device_unset_bond_destroyed_cb() + */ +int bt_device_set_bond_destroyed_cb(bt_device_bond_destroyed_cb callback, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Unregisters the callback function. + * @since_tizen 2.3 + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @see bt_initialize() + * @see bt_device_set_bond_destroyed_cb() + */ +int bt_device_unset_bond_destroyed_cb(void); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Registers a callback function to be invoked when the authorization of device changes. + * @since_tizen 2.3 + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @post bt_device_authorization_changed_cb() will be invoked. + * @see bt_initialize() + * @see bt_device_authorization_changed_cb() + * @see bt_device_set_authorization_changed_cb() + * @see bt_device_unset_authorization_changed_cb() + */ +int bt_device_set_authorization_changed_cb(bt_device_authorization_changed_cb callback, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Unregisters the callback function. + * @since_tizen 2.3 + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @see bt_initialize() + * @see bt_device_set_authorization_changed_cb() + */ +int bt_device_unset_authorization_changed_cb(void); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Registers a callback function to be invoked when the process of service search finishes. + * @since_tizen 2.3 + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @post bt_device_service_searched_cb() will be invoked. + * @see bt_initialize() + * @see bt_device_service_searched_cb() + * @see bt_device_unset_service_searched_cb() + */ +int bt_device_set_service_searched_cb(bt_device_service_searched_cb callback, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Unregisters the callback function. + * @since_tizen 2.3 + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @see bt_initialize() + * @see bt_device_set_service_searched_cb() + */ +int bt_device_unset_service_searched_cb(void); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Registers a callback function to be invoked when the connection state is changed. + * @since_tizen 2.3 + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @post bt_device_connection_state_changed_cb() will be invoked. + * @see bt_initialize() + * @see bt_device_connection_state_changed_cb() + * @see bt_device_unset_connection_state_changed_cb() + */ +int bt_device_set_connection_state_changed_cb(bt_device_connection_state_changed_cb callback, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Unregisters the callback function to be invoked when the connection state is changed. + * @since_tizen 2.3 + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @see bt_initialize() + * @see bt_device_set_connection_state_changed_cb() + */ +int bt_device_unset_connection_state_changed_cb(void); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE + * @brief Registers a rfcomm server socket with a specific UUID. + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * + * @remarks A socket can be destroyed by bt_socket_destroy_rfcomm(). + * + * @param[in] service_uuid The UUID of service to provide + * @param[out] socket_fd The file descriptor of socket to listen + * @return 0 on success, otherwise a negative error value. + * + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * + * @see bt_socket_listen_and_accept_rfcomm() + * @see bt_socket_destroy_rfcomm() + */ +int bt_socket_create_rfcomm(const char *service_uuid, int *socket_fd); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE + * @brief Removes the rfcomm server socket which was created using bt_socket_create_rfcomm(). + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * @remarks If callback function bt_socket_connection_state_changed_cb() is set and the remote Bluetooth device is connected, + * then bt_socket_connection_state_changed_cb() will be called when this function is finished successfully. + * + * @param[in] socket_fd The file descriptor of socket (which was created using bt_socket_create_rfcomm()) to destroy + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The socket must be created with bt_socket_create_rfcomm(). + * @post If callback function bt_socket_connection_state_changed_cb() is set and the remote Bluetooth device is connected, + * then bt_socket_connection_state_changed_cb() will be called. + * @see bt_socket_create_rfcomm() + * @see bt_socket_connection_state_changed_cb() + * @see bt_socket_set_connection_state_changed_cb() + * @see bt_socket_unset_connection_state_changed_cb() + */ +int bt_socket_destroy_rfcomm(int socket_fd); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE + * @brief Starts listening on passed rfcomm socket and accepts connection requests. + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * @details Pop-up is shown automatically when a RFCOMM connection is requested. + * bt_socket_connection_state_changed_cb() will be called with + * #BT_SOCKET_CONNECTED if you click "yes" and connection is finished successfully. + * @param[in] socket_fd The file descriptor of socket on which start to listen + * @param[in] max_pending_connections The maximum number of pending connections + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The socket must be created with bt_socket_create_rfcomm(). + * @post If callback function bt_socket_connection_state_changed_cb() is set, + * then bt_socket_connection_state_changed_cb() will be called when the remote Bluetooth device is connected. + * @see bt_socket_create_rfcomm() + * @see bt_socket_connection_state_changed_cb() + * @see bt_socket_set_connection_state_changed_cb() + * @see bt_socket_unset_connection_state_changed_cb() + */ +int bt_socket_listen_and_accept_rfcomm(int socket_fd, int max_pending_connections); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE + * @brief Starts listening on passed rfcomm socket. + * @since_tizen 2.3 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @details bt_socket_connection_requested_cb() will be called when a RFCOMM connection is requested. + * + * @param[in] socket_fd The file descriptor socket on which start to listen + * @param[in] max_pending_connections The number of pending connections + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The socket must be created with bt_socket_create_rfcomm(). + * @post This function invokes bt_socket_connection_state_changed_cb(). + * + * @see bt_socket_create_rfcomm() + * @see bt_socket_set_connection_requested_cb() + * @see bt_socket_unset_connection_requested_cb() + * @see bt_socket_connection_requested_cb() + */ +int bt_socket_listen(int socket_fd, int max_pending_connections); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE + * @brief Accepts a connection request. + * @since_tizen 2.3 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @param[in] requested_socket_fd The file descriptor of socket on which a connection is requested + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The connection is requested by bt_socket_connection_requested_cb(). + * @see bt_socket_create_rfcomm() + * @see bt_socket_connection_requested_cb() + * @see bt_socket_listen() + * @see bt_socket_reject() +*/ +int bt_socket_accept(int requested_socket_fd); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE + * @brief Rejects a connection request. + * @since_tizen 2.3 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @param[in] socket_fd The file descriptor of socket on which a connection is requested + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The connection is requested by bt_socket_connection_requested_cb(). + * @see bt_socket_create_rfcomm() + * @see bt_socket_connection_requested_cb() + * @see bt_socket_listen() + * @see bt_socket_accept() + */ +int bt_socket_reject(int socket_fd); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE + * @brief Connects to a specific RFCOMM based service on a remote Bluetooth device UUID, asynchronously. + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * + * @remarks A connection can be disconnected by bt_socket_disconnect_rfcomm(). + * + * @param[in] remote_address The address of the remote Bluetooth device + * @param[in] service_uuid The UUID of service provided by the remote Bluetooth device + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * @pre The remote device must be discoverable with bt_adapter_start_device_discovery(). + * @pre The bond with the remote device must be created with bt_device_create_bond(). + * @post This function invokes bt_socket_connection_state_changed_cb(). + * + * @see bt_device_create_bond() + * @see bt_adapter_start_device_discovery() + * @see bt_device_start_service_search() + * @see bt_socket_disconnect_rfcomm() + * @see bt_socket_connection_state_changed_cb() + * @see bt_socket_set_connection_state_changed_cb() + * @see bt_socket_unset_connection_state_changed_cb() + */ +int bt_socket_connect_rfcomm(const char *remote_address, const char *service_uuid); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE + * @brief Disconnects the RFCOMM connection with the given file descriptor of conneted socket. + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * @param[in] socket_fd The file descriptor of socket to close which was received using bt_socket_connection_state_changed_cb(). + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The connection must be established. + * + * @see bt_socket_connection_state_changed_cb() + * @see bt_socket_set_connection_state_changed_cb() + * @see bt_socket_unset_connection_state_changed_cb() + */ +int bt_socket_disconnect_rfcomm(int socket_fd); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE + * @brief Sends data to the connected device. + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * @remark The specific error code can be obtained using the get_last_result() method. Error codes are described in Exception section. + * + * @param[in] socket_fd The file descriptor of connected socket which was received using bt_socket_connection_state_changed_cb() + * @param[in] data The data to be sent + * @param[in] length The length of data to be sent + * + * @return the number of bytes written (zero indicates nothing was written). + * @retval On error, -1 is returned, and errno is set appropriately. See write 2 man page. + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * @exception BT_ERROR_PERMISSION_DENIED Permission denied + * @exception BT_ERROR_AGAIN Resource temporarily unavailable + * + * @pre The connection must be established. + * + * @see bt_socket_connection_state_changed_cb() + * @see bt_socket_set_connection_state_changed_cb() + * @see bt_socket_unset_connection_state_changed_cb() + */ +int bt_socket_send_data(int socket_fd, const char *data, int length); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE + * @brief Register a callback function that will be invoked when you receive data. + * @since_tizen 2.3 + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @post bt_socket_data_received_cb() will be invoked. + * @see bt_initialize() + * @see bt_socket_data_received_cb() + * @see bt_socket_set_data_received_cb() + * @see bt_socket_unset_data_received_cb() + */ +int bt_socket_set_data_received_cb(bt_socket_data_received_cb callback, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE + * @brief Unregisters the callback function. + * @since_tizen 2.3 + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @see bt_initialize() + * @see bt_socket_data_received_cb() + * @see bt_socket_set_data_received_cb() + */ +int bt_socket_unset_data_received_cb(void); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE + * @brief Register a callback function that will be invoked when a RFCOMM connection is requested. + * @since_tizen 2.3 + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @post If you listen and accept a socket by bt_socket_listen_and_accept_rfcomm(), + bt_socket_connection_requested_cb() will be invoked. + * @see bt_initialize() + * @see bt_socket_unset_connection_requested_cb() + */ +int bt_socket_set_connection_requested_cb(bt_socket_connection_requested_cb callback, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE + * @brief Unregisters the callback function. + * @since_tizen 2.3 + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @see bt_initialize() + * @see bt_socket_set_connection_requested_cb() + * @see bt_socket_connection_requested_cb() + */ +int bt_socket_unset_connection_requested_cb(void); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE + * @brief Register a callback function that will be invoked when the connection state changes. + * @since_tizen 2.3 + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @post bt_socket_connection_state_changed_cb() will be invoked. + * @see bt_initialize() + * @see bt_socket_connection_state_changed_cb() + * @see bt_socket_unset_connection_state_changed_cb() + */ +int bt_socket_set_connection_state_changed_cb(bt_socket_connection_state_changed_cb callback, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE + * @brief Unregisters the callback function. + * @since_tizen 2.3 + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @see bt_initialize() + * @see bt_socket_connection_state_changed_cb() + * @see bt_socket_set_connection_state_changed_cb() + */ +int bt_socket_unset_connection_state_changed_cb(void); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_OPP_SERVER_MODULE + * @brief Initializes the Bluetooth OPP server requested by bt_opp_server_push_requested_cb(). + * @since_tizen 2.3 + * @details The popup appears when an OPP connection is requested from a remote device. + * If you accept the request, then connection will be established and bt_opp_server_push_requested_cb() will be called. + * At that time, you can call either bt_opp_server_accept() or bt_opp_server_reject(). + * @remarks This function must be called to start Bluetooth OPP server. You must free all resources of the Bluetooth service + * by calling bt_opp_server_deinitialize() if Bluetooth OPP service is no longer needed. + * @param[in] destination The destination path + * @param[in] push_requested_cb The callback called when a push is requested + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_RESOURCE_BUSY Device or resource busy + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_opp_server_push_requested_cb() + * @see bt_opp_server_deinitialize() + * @see bt_opp_server_accept() + * @see bt_opp_server_reject() + */ +int bt_opp_server_initialize(const char *destination, bt_opp_server_push_requested_cb push_requested_cb, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_OPP_SERVER_MODULE + * @brief Initializes the Bluetooth OPP server requested by bt_opp_server_connection_requested_cb(). + * @since_tizen 2.3 + * @details No popup appears when an OPP connection is requested from a remote device. + * Instead, @a connection_requested_cb() will be called. + * At that time, you can call either bt_opp_server_accept() or bt_opp_server_reject(). + * @remarks This function must be called to start Bluetooth OPP server. \n + * You must free all resources of the Bluetooth service by calling bt_opp_server_deinitialize() if Bluetooth OPP service is no longer needed. + * @param[in] destination The destination path + * @param[in] connection_requested_cb The callback called when an OPP connection is requested + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_RESOURCE_BUSY Device or resource busy + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_opp_server_connection_requested_cb() + * @see bt_opp_server_deinitialize() + * @see bt_opp_server_accept() + * @see bt_opp_server_reject() + */ +int bt_opp_server_initialize_by_connection_request(const char *destination, bt_opp_server_connection_requested_cb connection_requested_cb, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_OPP_SERVER_MODULE + * @brief Denitializes the Bluetooth OPP server. + * @since_tizen 2.3 + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_opp_server_deinitialize() + */ +int bt_opp_server_deinitialize(void); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_OPP_SERVER_MODULE + * @brief Accepts the push request from the remote device. + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * @remarks If you initialize OPP server by bt_opp_server_initialize_by_connection_request(), then name is ignored. + * You can cancel the pushes by bt_opp_server_cancel_transfer() with transfer_id. + * @param[in] progress_cb The callback called when a file is being transfered + * @param[in] finished_cb The callback called when a transfer is finished + * @param[in] name The name to store. This can be NULL if you initialize OPP server by bt_opp_server_initialize_by_connection_request(). + * @param[in] user_data The user data to be passed to the callback function + * @param[out] transfer_id The ID of transfer + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_NOW_IN_PROGRESS Operation now in progress + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_opp_server_reject() + */ +int bt_opp_server_accept(bt_opp_server_transfer_progress_cb progress_cb, bt_opp_server_transfer_finished_cb finished_cb, const char *name, + void *user_data, int *transfer_id); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_OPP_SERVER_MODULE + * @brief Rejects the push request from the remote device. + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_opp_server_accept() + */ +int bt_opp_server_reject(void); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_OPP_SERVER_MODULE + * @brief Cancels the transfer. + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * @param[in] transfer_id The ID of transfer + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_opp_server_accept() + */ +int bt_opp_server_cancel_transfer(int transfer_id); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_OPP_SERVER_MODULE + * @brief Sets the destination path of file to be pushed. + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * @param[in] destination The destination path of file to be pushed + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + */ +int bt_opp_server_set_destination(const char *destination); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_OPP_CLIENT_MODULE + * @brief Initializes the Bluetooth OPP client. + * @since_tizen 2.3 + * @remarks This function must be called before Bluetooth OPP client starts. \n + * You must free all resources of the Bluetooth service by calling bt_opp_client_deinitialize() + * if Bluetooth OPP service is no longer needed. + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_RESOURCE_BUSY Device or resource busy + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_opp_client_deinitialize() + */ +int bt_opp_client_initialize(void); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_OPP_CLIENT_MODULE + * @brief Denitializes the Bluetooth OPP client. + * @since_tizen 2.3 + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_opp_client_initialize() + */ +int bt_opp_client_deinitialize(void); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_OPP_CLIENT_MODULE + * @brief Adds file to be pushed. + * @since_tizen 2.3 + * @param[in] file The path of file to be pushed + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_opp_client_clear_files() + * @see bt_opp_client_push_files() + */ +int bt_opp_client_add_file(const char *file); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_OPP_CLIENT_MODULE + * @brief Adds file to be pushed. + * @since_tizen 2.3 + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_opp_client_add_file() + * @see bt_opp_client_push_files() + */ +int bt_opp_client_clear_files(void); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_OPP_CLIENT_MODULE + * @brief Pushes the file to the remote device, asynchronously. + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * @details At first, bt_opp_client_push_responded_cb() will be called when OPP server responds to the push request. + * After connection is established, bt_opp_client_push_progress_cb() will be called repeatedly until a file is tranfered completely. + * If you send several files, then bt_opp_client_push_progress_cb() with another file will be called repeatedly until the file is tranfered completely. + * bt_opp_client_push_finished_cb() will be called when the push request is finished. + * @param[in] remote_address The remote address + * @param[in] responded_cb The callback called when OPP server responds to the push request + * @param[in] progress_cb The callback called when each file is being transfered + * @param[in] finished_cb The callback called when the push request is finished + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_NOW_IN_PROGRESS Operation now in progress + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_opp_client_initialize() + * @see bt_opp_client_cancel_push + */ +int bt_opp_client_push_files(const char *remote_address, bt_opp_client_push_responded_cb responded_cb, + bt_opp_client_push_progress_cb progress_cb, bt_opp_client_push_finished_cb finished_cb, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_OPP_CLIENT_MODULE + * @brief Cancels the push request in progress, asynchronously. + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre bt_opp_client_push_files() must be called. + * @post bt_opp_client_push_finished_cb() will be invoked with result #BT_ERROR_CANCELLED, + * which is a parameter of bt_opp_client_push_files(). + * @see bt_opp_client_initialize() + * @see bt_opp_client_push_files() + */ +int bt_opp_client_cancel_push(void); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_HID_MODULE + * @brief Initializes the Bluetooth HID(Human Interface Device) Host. + * @since_tizen 2.3 + * @remarks This function must be called before Bluetooth HID Host starts. \n + * You must free all resources of the Bluetooth service by calling bt_hid_host_deinitialize() + * if Bluetooth HID Host service is no longer needed. + * @param[in] connection_cb The callback called when the connection state is changed + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @see bt_initialize() + * @see bt_hid_host_deinitialize() + */ +int bt_hid_host_initialize(bt_hid_host_connection_state_changed_cb connection_cb, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_HID_MODULE + * @brief Deinitializes the Bluetooth HID(Human Interface Device) Host. + * @since_tizen 2.3 + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth HID service must be initialized with bt_hid_host_initialize(). + * @see bt_hid_host_initialize() + */ +int bt_hid_host_deinitialize(void); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_HID_MODULE + * @brief Connects the remote device with the HID(Human Interface Device) service, asynchronously. + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * @param[in] remote_address The remote address + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The local device must be bonded with the remote device by bt_device_create_bond(). + * @pre The Bluetooth HID service must be initialized with bt_hid_host_initialize(). + * @post bt_hid_host_connection_state_changed_cb() will be invoked. + * @see bt_hid_host_disconnect() + * @see bt_hid_host_connection_state_changed_cb() + */ +int bt_hid_host_connect(const char *remote_address); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_HID_MODULE + * @brief Disconnects the remote device with the HID(Human Interface Device) service, asynchronously. + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * @param[in] remote_address The remote address + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The remote device must be connected by bt_hid_host_connect(). + * @post bt_hid_host_connection_state_changed_cb() will be invoked. + * @see bt_hid_host_connect() + * @see bt_hid_host_connection_state_changed_cb() + */ +int bt_hid_host_disconnect(const char *remote_address); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_MODULE + * @brief Initializes the Bluetooth profiles related with audio. + * @since_tizen 2.3 + * @remarks This function must be called before Bluetooth profiles related with audio starts. \n + * You must free all resources of the this service by calling bt_audio_deinitialize() + * if Bluetooth profiles related with audio service is no longer needed. + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @see bt_initialize() + * @see bt_audio_deinitialize() + */ +int bt_audio_initialize(void); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_MODULE + * @brief Deinitializes the Bluetooth profiles related with audio. + * @since_tizen 2.3 + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth audio service must be initialized with bt_audio_initialize(). + * @see bt_audio_initialize() + */ +int bt_audio_deinitialize(void); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_MODULE + * @brief Connects the remote device with the given audio profile, asynchronously. + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * @details If you input type as #BT_AUDIO_PROFILE_TYPE_ALL and connection request succeeds, then bt_audio_connection_state_changed_cb() will be called twice + * when #BT_AUDIO_PROFILE_TYPE_HSP_HFP is connected and #BT_AUDIO_PROFILE_TYPE_A2DP is connected. + * @param[in] remote_address The remote address + * @param[in] type The type of audio profile + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + + * @pre The Bluetooth audio service must be initialized with bt_audio_initialize(). + * @pre The local device must be bonded with the remote device by bt_device_create_bond(). + * @post bt_audio_connection_state_changed_cb() will be invoked. + * @see bt_audio_disconnect() + * @see bt_audio_connection_state_changed_cb() + */ +int bt_audio_connect(const char *remote_address, bt_audio_profile_type_e type); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_MODULE + * @brief Disconnects the remote device with the given audio profile, asynchronously. + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * @details If you input type as #BT_AUDIO_PROFILE_TYPE_ALL and disconnection request succeeds, then bt_audio_connection_state_changed_cb() will be called twice + * when #BT_AUDIO_PROFILE_TYPE_HSP_HFP is disconnected and #BT_AUDIO_PROFILE_TYPE_A2DP is disconnected. + * @param[in] remote_address The remote address + * @param[in] type The type of audio profile + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The remote device must be connected by bt_audio_connect(). + * @post bt_audio_connection_state_changed_cb() will be invoked. + * @see bt_audio_connect() + * @see bt_audio_connection_state_changed_cb() + */ +int bt_audio_disconnect(const char *remote_address, bt_audio_profile_type_e type); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_MODULE + * @brief Registers a callback function that will be invoked when the connection state is changed. + * @since_tizen 2.3 + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth audio service must be initialized with bt_audio_initialize(). + * @see bt_audio_initialize() + * @see bt_audio_connection_state_changed_cb() + */ +int bt_audio_set_connection_state_changed_cb(bt_audio_connection_state_changed_cb callback, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_MODULE + * @brief Unregisters a callback function that will be invoked when the connection state is changed. + * @since_tizen 2.3 + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth audio service must be initialized with bt_audio_initialize(). + * @see bt_audio_initialize() + * @see bt_audio_connection_state_changed_cb() + * @see bt_audio_set_connection_state_changed_cb() + */ +int bt_audio_unset_connection_state_changed_cb(void); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Opens a SCO(Synchronous Connection Oriented link) to connected remote device, asynchronously. + * @since_tizen 2.3 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected + * @retval #BT_ERROR_ALREADY_DONE Operation is already done + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth audio device must be connected with bt_audio_connect(). + * @post bt_ag_sco_state_changed_cb() will be invoked. + * @see bt_ag_close_sco() + * @see bt_ag_sco_state_changed_cb() + * @see bt_audio_connect() + */ +int bt_ag_open_sco(void); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Closes an opened SCO(Synchronous Connection Oriented link), asynchronously. + * @since_tizen 2.3 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The SCO must be opened with bt_ag_open_sco(). + * @post bt_ag_sco_state_changed_cb() will be invoked. + * @see bt_ag_open_sco() + * @see bt_ag_sco_state_changed_cb() + */ +int bt_ag_close_sco(void); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Checks whether an opened SCO(Synchronous Connection Oriented link) exists or not. + * @since_tizen 2.3 + * @param[out] opened The SCO status: (@c true = opened, @c false = not opened) + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth audio service must be initialized with bt_audio_initialize(). + * @see bt_ag_open_sco() + * @see bt_ag_close_sco() + */ +int bt_ag_is_sco_opened(bool *opened); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Registers a callback function that will be invoked when the SCO(Synchronous Connection Oriented link) state is changed. + * @since_tizen 2.3 + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth audio service must be initialized with bt_audio_initialize(). + * @see bt_audio_initialize() + * @see bt_ag_sco_state_changed_cb() + * @see bt_ag_unset_sco_state_changed_cb() + */ +int bt_ag_set_sco_state_changed_cb(bt_ag_sco_state_changed_cb callback, void *user_data); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Unregisters a callback function that will be invoked when the SCO(Synchronous Connection Oriented link) state is changed. + * @since_tizen 2.3 + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth audio service must be initialized with bt_audio_initialize(). + * @see bt_audio_initialize() + * @see bt_ag_sco_state_changed_cb() + * @see bt_ag_set_sco_state_changed_cb() + */ +int bt_ag_unset_sco_state_changed_cb(void); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Notifies the call event to the remote bluetooth device. + * @since_tizen 2.3 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @remarks Before notifying #BT_AG_CALL_EVENT_ANSWERED or #BT_AG_CALL_EVENT_DIALING, you should open SCO(Synchronous Connection Oriented link) + * if Bluetooth Hands-Free need SCO connection. + * @param[in] event The call event + * @param[in] call_id The call ID + * @param[in] phone_number The phone number. You must set this value in case of #BT_AG_CALL_EVENT_DIALING and #BT_AG_CALL_EVENT_INCOMING. + * In other cases, this value can be NULL. + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth audio device must be connected with bt_audio_connect(). + * @see bt_audio_connect() + */ +int bt_ag_notify_call_event(bt_ag_call_event_e event, unsigned int call_id, const char *phone_number); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Notifies the call list to the remote bluetooth device. + * @since_tizen 2.3 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @param[in] list The call list + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth audio device must be connected with bt_audio_connect(). + * @see bt_audio_connect() + */ +int bt_ag_notify_call_list(bt_call_list_h list); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Notifies the state of voice recognition. + * @since_tizen 2.3 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @param[in] state The state of voice recognition: (@c true = enabled, @c false = disabled) + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth audio device must be connected with bt_audio_connect(). + * @see bt_audio_connect() + */ +int bt_ag_notify_voice_recognition_state(bool state); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Registers a callback function that will be invoked when a call handling event happened from Hands-Free. + * @since_tizen 2.3 + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth audio service must be initialized with bt_audio_initialize(). + * @see bt_audio_initialize() + * @see bt_ag_call_handling_event_cb() + * @see bt_ag_unset_call_handling_event_cb() + */ +int bt_ag_set_call_handling_event_cb(bt_ag_call_handling_event_cb callback, void *user_data); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Unregisters a callback function that will be invoked when a call handling event happened from Hands-Free. + * @since_tizen 2.3 + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth audio service must be initialized with bt_audio_initialize(). + * @see bt_audio_initialize() + * @see bt_ag_call_handling_event_cb() + * @see bt_ag_set_call_handling_event_cb() + */ +int bt_ag_unset_call_handling_event_cb(void); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Registers a callback function that will be invoked when a multi call handling event happened from Hands-Free. + * @since_tizen 2.3 + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth audio service must be initialized with bt_audio_initialize(). + * @see bt_audio_initialize() + * @see bt_ag_multi_call_handling_event_cb() + * @see bt_ag_unset_multi_call_handling_event_cb() + */ +int bt_ag_set_multi_call_handling_event_cb(bt_ag_multi_call_handling_event_cb callback, void *user_data); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Unregisters a callback function that will be invoked when a multi call handling event happened from Hands-Free. + * @since_tizen 2.3 + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth audio service must be initialized with bt_audio_initialize(). + * @see bt_audio_initialize() + * @see bt_ag_multi_call_handling_event_cb() + * @see bt_ag_set_multi_call_handling_event_cb() + */ +int bt_ag_unset_multi_call_handling_event_cb(void); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Registers a callback function that will be invoked when a DTMF(Dual Tone Multi Frequency) is transmitted from Hands-Free. + * @since_tizen 2.3 + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth audio service must be initialized with bt_audio_initialize(). + * @see bt_audio_initialize() + * @see bt_ag_dtmf_transmitted_cb() + * @see bt_ag_unset_dtmf_transmitted_cb() + */ +int bt_ag_set_dtmf_transmitted_cb(bt_ag_dtmf_transmitted_cb callback, void *user_data); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Unregisters a callback function that will be invoked when a DTMF(Dual Tone Multi Frequency) is transmitted from Hands-Free. + * @since_tizen 2.3 + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth audio service must be initialized with bt_audio_initialize(). + * @see bt_audio_initialize() + * @see bt_ag_dtmf_transmitted_cb() + * @see bt_ag_set_dtmf_transmitted_cb() + */ +int bt_ag_unset_dtmf_transmitted_cb(void); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Notifies the speaker gain to the remote device. + * @since_tizen 2.3 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @details This function sends a signal to the remote device. This signal has the gain value. + * @a gain is represented on a scale from 0 to 15. This value is absolute value relating to a particular volume level. + * When the speaker gain of remote device is changed to the requested gain, bt_audio_speaker_gain_changed_cb() will be called. + * @param[in] gain The gain of speaker (0 ~ 15) + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The remote device is connected by bt_audio_connect() with #BT_AUDIO_PROFILE_TYPE_HSP_HFP service. + * @see bt_ag_get_speaker_gain() + * @see bt_ag_set_speaker_gain_changed_cb() + * @see bt_ag_unset_speaker_gain_changed_cb() + */ +int bt_ag_notify_speaker_gain(int gain); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Gets the current speaker gain of the remote device. + * @since_tizen 2.3 + * @details This function gets the value of speaker gain of the remote device. + * @a gain is represented on a scale from 0 to 15. This value is absolute value relating to a particular volume level. + * @param[out] gain The gain of speaker (0 ~ 15) + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The remote device is connected by bt_audio_connect() with #BT_AUDIO_PROFILE_TYPE_HSP_HFP service. + * @see bt_ag_notify_speaker_gain() + * @see bt_ag_set_speaker_gain_changed_cb() + * @see bt_ag_unset_speaker_gain_changed_cb() + */ +int bt_ag_get_speaker_gain(int *gain); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Checks whether the remoted device enables NREC(Noise Reduction and Echo Canceling) or not. + * @since_tizen 2.3 + * @param[out] enabled The NREC status: (@c true = enabled, @c false = not enabled) + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The remote device is connected by bt_audio_connect() with #BT_AUDIO_PROFILE_TYPE_HSP_HFP service. + * @see bt_audio_connect() + */ +int bt_ag_is_nrec_enabled(bool *enabled); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Registers a callback function that will be invoked when the speaker gain of the remote device is changed. + * @since_tizen 2.3 + * @details This function let you know the change of the speaker gain of the remote device. + * @a gain is represented on a scale from 0 to 15. This value is absolute value relating to a particular volume level. + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth audio service must be initialized with bt_audio_initialize(). + * @see bt_audio_initialize() + * @see bt_ag_unset_speaker_gain_changed_cb() + */ +int bt_ag_set_speaker_gain_changed_cb(bt_ag_speaker_gain_changed_cb callback, void *user_data); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Unregisters a callback function that will be invoked when the speaker gain of the remote device is changed. + * @since_tizen 2.3 + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth audio service must be initialized with bt_audio_initialize(). + * @see bt_audio_initialize() + * @see bt_ag_set_speaker_gain_changed_cb() + */ +int bt_ag_unset_speaker_gain_changed_cb(void); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Registers a callback function that will be invoked when the microphone gain of the remote device is changed. + * @since_tizen 2.3 + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth audio service must be initialized with bt_audio_initialize(). + * @see bt_audio_initialize() + * @see bt_ag_unset_microphone_gain_changed_cb() + */ +int bt_ag_set_microphone_gain_changed_cb(bt_ag_microphone_gain_changed_cb callback, void *user_data); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Unregisters a callback function that will be invoked when the microphone gain of the remote device is changed. + * @since_tizen 2.3 + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth audio service must be initialized with bt_audio_initialize(). + * @see bt_audio_initialize() + * @see bt_ag_set_microphone_gain_changed_cb() + */ +int bt_ag_unset_microphone_gain_changed_cb(void); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_CALL_MODULE + * @brief Creates a handle of call list. + * @since_tizen 2.3 + * @param[out] list The handle of call list + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_OUT_OF_MEMORY Out of memory + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_call_list_destroy() + */ +int bt_call_list_create(bt_call_list_h *list); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_CALL_MODULE + * @brief Destroys the handle of call list. + * @since_tizen 2.3 + * @param[in] list The handle of call list + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_call_list_create() + */ +int bt_call_list_destroy(bt_call_list_h list); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_CALL_MODULE + * @brief Resets the handle of call list. + * @since_tizen 2.3 + * @param[in] list The handle of call list + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_call_list_create() + */ +int bt_call_list_reset(bt_call_list_h list); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_CALL_MODULE + * @brief Adds a call to the handle of call list. + * @since_tizen 2.3 + * @param[in] list The handle of call list + * @param[in] call_id The call ID + * @param[in] state The state of audio gate call + * @param[in] phone_number The phone number. You must set this value in case of #BT_AG_CALL_EVENT_DIALING and #BT_AG_CALL_EVENT_INCOMING. + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_OUT_OF_MEMORY Out of memory + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_call_list_create() + */ +int bt_call_list_add(bt_call_list_h list, unsigned int call_id, bt_ag_call_state_e state, const char *phone_number); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief Initializes the Bluetooth AVRCP(Audio/Video Remote Control Profile) service. + * @since_tizen 2.3 + * @remarks This function must be called before Bluetooth AVRCP service. \n + * You must free all resources of the this service by calling bt_avrcp_target_deinitialize() + * if Bluetooth AVRCP service is no longer needed. + * @param[in] callback The callback function called when the connection state is changed + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @see bt_initialize() + * @see bt_avrcp_target_deinitialize() + */ +int bt_avrcp_target_initialize(bt_avrcp_target_connection_state_changed_cb callback, void *user_data); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief Deinitializes the Bluetooth AVRCP(Audio/Video Remote Control Profile) service. + * @since_tizen 2.3 + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth audio service must be initialized with bt_avrcp_target_initialize(). + * @see bt_avrcp_target_initialize() + */ +int bt_avrcp_target_deinitialize(void); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief Notifies the equalize state to the remote device. + * @since_tizen 2.3 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @param[in] state The state of equalizer + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The remote device must be connected. + * @see bt_avrcp_target_connection_state_changed_cb() + * @see bt_avrcp_target_initialize() + */ +int bt_avrcp_target_notify_equalizer_state(bt_avrcp_equalizer_state_e state); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief Notifies the repeat mode to the remote device. + * @since_tizen 2.3 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @param[in] mode The repeat mode + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The remote device must be connected. + * @see bt_avrcp_target_connection_state_changed_cb() + * @see bt_avrcp_target_initialize() + */ +int bt_avrcp_target_notify_repeat_mode(bt_avrcp_repeat_mode_e mode); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief Notifies the shuffle mode to the remote device. + * @since_tizen 2.3 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @param[in] mode The repeat mode + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The remote device must be connected. + * @see bt_avrcp_target_connection_state_changed_cb() + * @see bt_avrcp_target_initialize() + */ +int bt_avrcp_target_notify_shuffle_mode(bt_avrcp_shuffle_mode_e mode); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief Notifies the scan mode to the remote device. + * @since_tizen 2.3 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @param[in] mode The scan mode + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The remote device must be connected. + * @see bt_avrcp_target_connection_state_changed_cb() + * @see bt_avrcp_target_initialize() + */ +int bt_avrcp_target_notify_scan_mode(bt_avrcp_scan_mode_e mode); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief Notifies the player state to the remote device. + * @since_tizen 2.3 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @param[in] state The player state + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The remote device must be connected. + * @see bt_avrcp_target_connection_state_changed_cb() + * @see bt_avrcp_target_initialize() + */ +int bt_avrcp_target_notify_player_state(bt_avrcp_player_state_e state); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief Notifies the current position of song to the remote device. + * @since_tizen 2.3 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @param[in] position The current position in milliseconds + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The remote device must be connected. + * @see bt_avrcp_target_connection_state_changed_cb() + * @see bt_avrcp_target_initialize() + */ +int bt_avrcp_target_notify_position(unsigned int position); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief Notifies the track to the remote device. + * @since_tizen 2.3 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @param[in] title The title of track + * @param[in] artist The artist of track + * @param[in] album The album of track + * @param[in] genre The genre of track + * @param[in] track_num The track number + * @param[in] total_tracks The number of all tracks + * @param[in] duration The duration of track in milliseconds + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The remote device must be connected. + * @see bt_avrcp_target_connection_state_changed_cb() + * @see bt_avrcp_target_initialize() + */ +int bt_avrcp_target_notify_track(const char *title, const char *artist, const char *album, const char *genre, unsigned int track_num, unsigned int total_tracks, unsigned int duration); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief Registers a callback function that will be invoked when the equalizer state is changed by the remote control device. + * @since_tizen 2.3 + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized by bt_initialize(). + * @see bt_initialize() + * @see bt_avrcp_unset_equalizer_state_changed_cb() + */ +int bt_avrcp_set_equalizer_state_changed_cb(bt_avrcp_equalizer_state_changed_cb callback, void *user_data); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief Unregisters a callback function that will be invoked when the equalizer state is changed by the remote control device. + * @since_tizen 2.3 + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized by bt_initialize(). + * @see bt_initialize() + * @see bt_avrcp_set_equalizer_state_changed_cb() + */ +int bt_avrcp_unset_equalizer_state_changed_cb(void); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief Registers a callback function that will be invoked when the repeat mode is changed by the remote control device. + * @since_tizen 2.3 + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized by bt_initialize(). + * @see bt_initialize() + * @see bt_avrcp_unset_repeat_mode_changed_cb() + */ +int bt_avrcp_set_repeat_mode_changed_cb(bt_avrcp_repeat_mode_changed_cb callback, void *user_data); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief Unregisters a callback function that will be invoked when the repeat mode is changed by the remote control device. + * @since_tizen 2.3 + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized by bt_initialize(). + * @see bt_initialize() + * @see bt_avrcp_set_repeat_mode_changed_cb() + */ +int bt_avrcp_unset_repeat_mode_changed_cb(void); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief Registers a callback function that will be invoked when the shuffle mode is changed by the remote control device. + * @since_tizen 2.3 + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized by bt_initialize(). + * @see bt_initialize() + * @see bt_avrcp_unset_shuffle_mode_changed_cb() + */ +int bt_avrcp_set_shuffle_mode_changed_cb(bt_avrcp_shuffle_mode_changed_cb callback, void *user_data); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief Unregisters a callback function that will be invoked when the shuffle mode is changed by the remote control device. + * @since_tizen 2.3 + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized by bt_initialize(). + * @see bt_initialize() + * @see bt_avrcp_set_shuffle_mode_changed_cb() + */ +int bt_avrcp_unset_shuffle_mode_changed_cb(void); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief Registers a callback function that will be invoked when the scan mode is changed by the remote control device. + * @since_tizen 2.3 + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized by bt_initialize(). + * @see bt_initialize() + * @see bt_avrcp_unset_scan_mode_changed_cb() + */ +int bt_avrcp_set_scan_mode_changed_cb(bt_avrcp_scan_mode_changed_cb callback, void *user_data); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief Unregisters a callback function that will be invoked when the scan mode is changed by the remote control device. + * @since_tizen 2.3 + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized by bt_initialize(). + * @see bt_initialize() + * @see bt_avrcp_set_scan_mode_changed_cb() + */ +int bt_avrcp_unset_scan_mode_changed_cb(void); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_HDP_MODULE + * @brief Registers an application that acts as the @a Sink role of HDP(Health Device Profile). + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * @remarks The @a app_id must be released with free() by you. + * @param[in] data_type The data type of MDEP. This value is defined in ISO/IEEE 11073-20601 spec. + * For example, pulse oximeter is 0x1004 and blood pressure monitor is 0x1007. + * @param[out] app_id The ID of application + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_OUT_OF_MEMORY Out of memory + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * @see bt_hdp_unregister_sink_app() + */ +int bt_hdp_register_sink_app(unsigned short data_type, char **app_id); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_HDP_MODULE + * @brief Unregisters the given application that acts as the @a Sink role of HDP(Health Device Profile). + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * @param[in] app_id The ID of application + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_hdp_register_sink_app() + */ +int bt_hdp_unregister_sink_app(const char *app_id); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_HDP_MODULE + * @brief Connects the remote device which acts as @a Source role, asynchronously. + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * @param[in] remote_address The remote address + * @param[in] app_id The ID of application + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OUT_OF_MEMORY Out of memory + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Sink role of HDP must be registered with bt_hdp_register_sink_app(). + * @pre The local device must be bonded with the remote device by bt_device_create_bond(). + * @post bt_hdp_connected_cb() will be invoked. + * @see bt_hdp_disconnect() + * @see bt_hdp_set_connection_state_changed_cb() + * @see bt_hdp_unset_connection_state_changed_cb() + */ +int bt_hdp_connect_to_source(const char *remote_address, const char *app_id); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_HDP_MODULE + * @brief Disconnects the remote device, asynchronously. + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * @param[in] remote_address The remote address + * @param[in] channel The connected data channel + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected + * @retval #BT_ERROR_OUT_OF_MEMORY Out of memory + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The remote device must be connected. + * @post bt_hdp_disconnected_cb() will be invoked. + * @see bt_hdp_set_connection_state_changed_cb() + * @see bt_hdp_unset_connection_state_changed_cb() + */ +int bt_hdp_disconnect(const char *remote_address, unsigned int channel); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_HDP_MODULE + * @brief Sends the data to the remote device. + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * @param[in] channel The connected data channel + * @param[in] data The data to send + * @param[in] size The size of data to send (byte) + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The remote device must be connected. + * @see bt_hdp_data_received_cb() + * @see bt_hdp_set_data_received_cb() + * @see bt_hdp_unset_data_received_cb() + */ +int bt_hdp_send_data(unsigned int channel, const char *data, unsigned int size); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_HDP_MODULE + * @brief Registers a callback function that will be invoked when the connection state is changed. + * @since_tizen 2.3 + * @param[in] connected_cb The callback function called when a connection is established + * @param[in] disconnected_cb The callback function called when a connection is disconnected + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @see bt_hdp_unset_connection_state_changed_cb() + */ +int bt_hdp_set_connection_state_changed_cb(bt_hdp_connected_cb connected_cb, bt_hdp_disconnected_cb disconnected_cb, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_HDP_MODULE + * @brief Unregisters a callback function that will be invoked when the connection state is changed. + * @since_tizen 2.3 + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @see bt_hdp_set_connection_state_changed_cb() + */ +int bt_hdp_unset_connection_state_changed_cb(void); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_HDP_MODULE + * @brief Registers a callback function that will be invoked when you receive the data. + * @since_tizen 2.3 + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @see bt_hdp_unset_data_received_cb() + */ +int bt_hdp_set_data_received_cb(bt_hdp_data_received_cb callback, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_HDP_MODULE + * @brief Unregisters a callback function that will be invoked when you receive the data. + * @since_tizen 2.3 + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @see bt_hdp_set_data_received_cb() + */ +int bt_hdp_unset_data_received_cb(void); + +/** + * @deprecated Deprecated since 2.3.1. Use bt_gatt_client_foreach_services or bt_gatt_client_get_service instead. + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Gets the primary services of GATT(Generic Attribute Profile). + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * @param[in] remote_address The address of the remote device + * @param[in] callback The callback function to invoke + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * @post @a callback will be called if there are primary services. + * @see bt_gatt_primary_service_cb() + */ +int bt_gatt_foreach_primary_services(const char *remote_address, bt_gatt_primary_service_cb callback, void *user_data); + +/** + * @deprecated Deprecated since 2.3.1. This function call is not required because characteristic discovery is happened automatically. + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Discovers the characteristics in service, asynchronously. + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * @param[in] service The attribute handle of service + * @param[in] callback The result callback + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * @post @a callback will be called. + * @see bt_gatt_characteristics_discovered_cb() + */ +int bt_gatt_discover_characteristics(bt_gatt_attribute_h service, bt_gatt_characteristics_discovered_cb callback, void *user_data); + +/** + * @deprecated Deprecated since 2.3.1. Use bt_gatt_get_uuid instead. + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Gets the UUID of service. + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * @remarks @a uuid must be released with free() by you. + * @param[in] service The attribute handle of service + * @param[out] uuid The UUID of service + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_OUT_OF_MEMORY Out of memory + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + */ +int bt_gatt_get_service_uuid(bt_gatt_attribute_h service, char **uuid); + +/** + * @deprecated Deprecated since 2.3.1. Use bt_gatt_service_foreach_included_services or bt_gatt_service_get_included_service instead. + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Gets the included services in service. + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * @param[in] service The attribute handle of service + * @param[in] callback The callback function to invoke + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * @post @a callback will be called if there are included services. + * @see bt_gatt_included_service_cb() + */ +int bt_gatt_foreach_included_services(bt_gatt_attribute_h service, bt_gatt_included_service_cb callback, void *user_data); + +/** + * @deprecated Deprecated since 2.3.1. Use bt_gatt_client_set_characteristic_value_changed_cb instead. + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Registers a callback function that will be invoked when a characteristic value is changed. + * @since_tizen 2.3 + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @see bt_gatt_unset_characteristic_changed_cb() + */ +int bt_gatt_set_characteristic_changed_cb(bt_gatt_characteristic_changed_cb callback, void *user_data); + +/** + * @deprecated Deprecated since 2.3.1. Use bt_gatt_client_unset_characteristic_value_changed_cb instead. + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Unregisters a callback function that will be invoked when a characteristic is changed. + * @since_tizen 2.3 + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @see bt_gatt_set_characteristic_changed_cb() + */ +int bt_gatt_unset_characteristic_changed_cb(void); + +/** + * @deprecated Deprecated since 2.3.1. Use bt_gatt_client_set_characteristic_value_changed_cb instead. + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Watches all the characteristic value changes of the service + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * @param[in] service The attribute handle of service + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @see bt_gatt_unset_characteristic_changed_cb() + */ +int bt_gatt_watch_characteristic_changes(bt_gatt_attribute_h service); + +/** + * @deprecated Deprecated since 2.3.1. Use bt_gatt_client_unset_characteristic_value_changed_cb instead. + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Remove watching of all the characteristic value changes of the service + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * @param[in] service The attribute handle of service + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @see bt_gatt_set_characteristic_changed_cb() + */ +int bt_gatt_unwatch_characteristic_changes(bt_gatt_attribute_h service); + +/** + * @deprecated Deprecated since 2.3.1. Use bt_gatt_get_value or bt_gatt_get_uuid after bt_gatt_client_read_value instead. + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Gets the characteristic declaration. + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * @remarks @a uuid and @a value must be released with free() by you. + * @param[in] characteristic The attribute handle of characteristic + * @param[out] uuid The UUID of service + * @param[out] value The value of characteristic (byte array) + * @param[out] value_length The length of value + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_OUT_OF_MEMORY Out of memory + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * @see bt_gatt_set_characteristic_value() + */ +int bt_gatt_get_characteristic_declaration(bt_gatt_attribute_h characteristic, char **uuid, unsigned char **value, int *value_length); + +/** + * @deprecated Deprecated since 2.3.1. Use bt_gatt_set_value and bt_gatt_client_write_value instead. + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Sets the value of characteristic. + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * @param[in] characteristic The attribute handle of characteristic + * @param[in] value The value of characteristic (byte array) + * @param[in] value_length The length of value + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * @see bt_gatt_get_characteristic_declaration() + */ +int bt_gatt_set_characteristic_value(bt_gatt_attribute_h characteristic, const unsigned char *value, int value_length); + +/** + * @deprecated Deprecated since 2.3.1. Use bt_gatt_set_value and bt_gatt_client_write_value instead. + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Sets the value of characteristic request. + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * @param[in] characteristic The attribute handle of characteristic + * @param[in] value The value of characteristic (byte array) + * @param[in] value_length The length of value + * @param[in] callback The result callback + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * @see bt_gatt_get_characteristic_declaration() + */ +int bt_gatt_set_characteristic_value_request(bt_gatt_attribute_h characteristic, const unsigned char *value, + int value_length, bt_gatt_characteristic_write_cb callback); + +/** +* @deprecated Deprecated since 2.3.1. GATT handle clone is not allowed. Instead, all handles for client role must be got from GATT client handle. +* @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE +* @brief Clones the attribute handle. +* @since_tizen 2.3 +* @remarks @a clone must be released with bt_gatt_destroy_attribute_handle(). +* @param[out] clone The cloned attribute handle +* @param[in] origin The origin attribute handle +* @return 0 on success, otherwise negative error value. +* @retval #BT_ERROR_NONE Successful +* @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter +* @retval #BT_ERROR_OUT_OF_MEMORY Out of memory +* @retval #BT_ERROR_NOT_SUPPORTED Not supported +* +* @see bt_gatt_destroy_attribute_handle() +*/ +int bt_gatt_clone_attribute_handle(bt_gatt_attribute_h* clone, bt_gatt_attribute_h origin); + +/** +* @deprecated Deprecated since 2.3.1. GATT handle clone and destroy are not allowed. +* @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE +* @brief Destroys the attribute handle. +* @since_tizen 2.3 +* @param[in] handle The attribute handle +* @return 0 on success, otherwise negative error value. +* @retval #BT_ERROR_NONE Successful +* @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter +* @retval #BT_ERROR_NOT_SUPPORTED Not supported +* +* @see bt_gatt_clone_attribute_handle() +*/ +int bt_gatt_destroy_attribute_handle(bt_gatt_attribute_h handle); + +/** + * @deprecated Deprecated since 2.3.1. Use gatt_client_read_value instead. + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Reads the value of characteristic from remote device + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * @param[in] char_handle The attribute handle of characteristic + * @param[in] callback The result callback + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * @see bt_gatt_get_characteristic_declaration() + */ +int bt_gatt_read_characteristic_value(bt_gatt_attribute_h char_handle, + bt_gatt_characteristic_read_cb callback); + +/** + * @deprecated Deprecated since 2.3.1. This function call is not required because descriptor discovery is happened automatically. + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Discovers the characteristic descriptors of a characteristic within its definition, asynchronously. + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * @param[in] characteristic_handle The attribute handle of characteristic + * @param[in] callback The result callback + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * @post @a callback will be called. + * @see bt_gatt_characteristic_descriptor_discovered_cb() + */ +int bt_gatt_discover_characteristic_descriptor(bt_gatt_attribute_h characteristic_handle, + bt_gatt_characteristic_descriptor_discovered_cb callback, + void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Gets the value of a characteristic or descriptor's GATT handle + * @since_tizen 2.3.1 + * + * @remarks @a value must be released using free(). \n + * When @a gatt_handle is associated with bt_gatt_client_h, bt_gatt_client_read_value() must be used prior to this function \n + * in order to get the remote device's current value. + * + * @param[in] gatt_handle The handle of a characteristic or descriptor + * @param[out] value The value of @a gatt_handle. It is a byte stream type. + * @param[out] value_length The length of @a value + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + */ +int bt_gatt_get_value(bt_gatt_h gatt_handle, char **value, int *value_length); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Gets the value of a characteristic or descriptor's GATT handle as an integer type + * @since_tizen 2.3.1 + * + * @remarks This function returns a locally saved value in @a gatt_handle. \n + * When @a gatt_handle is associated with bt_gatt_client_h, bt_gatt_client_read_value() must be used prior to this function \n + * in order to get the remote device's current value. + * + * @param[in] gatt_handle The handle of a characteristic or descriptor + * @param[in] type The type of a saved value in @a gatt_handle + * @param[in] offset The offset from where a value will be read from @a gatt_handle as an integer type + * @param[out] value The integer type's value of @a gatt_handle + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + */ +int bt_gatt_get_int_value(bt_gatt_h gatt_handle, bt_data_type_int_e type, + int offset, int *value); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Gets the value of a characteristic or descriptor's GATT handle as a float type + * @since_tizen 2.3.1 + * + * @remarks This function returns a locally saved value in @a gatt_handle. \n + * When @a gatt_handle is associated with bt_gatt_client_h, bt_gatt_client_read_value() must be used prior to this function \n + * in order to get the remote device's current value. + * + * @param[in] gatt_handle The handle of a characteristic or descriptor + * @param[in] type The type of a saved value in @a gatt_handle + * @param[in] offset The offset from where a value will be read from @a gatt_handle as an integer type + * @param[out] value The float type's value of @a gatt_handle + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + */ +int bt_gatt_get_float_value(bt_gatt_h gatt_handle, bt_data_type_float_e type, + int offset, float *value); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Updates the value of a characteristic or descriptor's GATT handle + * @since_tizen 2.3.1 + * + * @remarks This function updates a value of @a gatt_handle locally. \n + * When @a gatt_handle is associated with bt_gatt_client_h, bt_gatt_client_write_value() can be used after this function \n + * in order to update the remote device's value. \n + * + * @param[in] gatt_handle The handle of a characteristic or descriptor + * @param[in] value The value to be updated + * @param[in] value_length The length of @a value + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + */ +int bt_gatt_set_value(bt_gatt_h gatt_handle, const char *value, int value_length); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Updates the value of a characteristic or descriptor's GATT handle using a integer type's value + * @since_tizen 2.3.1 + * + * @remarks This function updates a value of @a gatt_handle locally. \n + * When @a gatt_handle is associated with bt_gatt_client_h, bt_gatt_client_write_value() can be used after this function \n + * in order to update the remote device's value. \n + * + * @param[in] gatt_handle The handle of a characteristic or descriptor + * @param[in] type @a value will be saved in @a gatt_handle as this type + * @param[in] value The integer type's value to be updated + * @param[in] offset The offset from where @a value will be saved in @a gatt_handle + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + */ +int bt_gatt_set_int_value(bt_gatt_h gatt_handle, bt_data_type_int_e type, + int value, int offset); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Updates the value of a characteristic or descriptor's GATT handle using a float type's value + * @since_tizen 2.3.1 + * + * @remarks This function updates a value of @a gatt_handle locally. \n + * When @a gatt_handle is associated with bt_gatt_client_h, bt_gatt_client_write_value() can be used after this function \n + * in order to update the remote device's value. \n + * + * @param[in] gatt_handle The handle of a characteristic or descriptor + * @param[in] type @a mantissa and @a exponent will be saved in @a gatt_handle as this type + * @param[in] mantissa The mantissa of float type's value to be updated + * @param[in] exponent The exponent of float type's value to be updated + * @param[in] offset The offset from where @a mantissa and @a exponent will be saved in @a gatt_handle + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + */ +int bt_gatt_set_float_value(bt_gatt_h gatt_handle, bt_data_type_float_e type, + int mantissa, int exponent, int offset); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Gets the UUID of a service, characteristic or descriptor's GATT handle + * @since_tizen 2.3.1 + * + * @remarks @a uuid must be released using free(). \n + * 16-bit UUID or 128-bit UUID is supported. (e.g. 2A19, 00002A19-0000-1000-8000-00805F9B34FB) + * + * @param[in] gatt_handle The handle of a service, characteristic or descriptor + * @param[out] uuid The string of the UUID of @a gatt_handle + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + */ +int bt_gatt_get_uuid(bt_gatt_h gatt_handle, char **uuid); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Gets the type of GATT handle + * @since_tizen 2.3.1 + * + * @param[in] gatt_handle The GATT handle + * @param[out] gatt_type The type of @a gatt_handle + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + */ +int bt_gatt_get_type(bt_gatt_h gatt_handle, bt_gatt_type_e *gatt_type); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Gets the GATT client handle which the specified service belongs to + * @since_tizen 2.3.1 + * + * @remark This function doesn't allocate new memory for GATT client handle. + * The returned GATT client handle is the same one which was got from bt_gatt_client_create(). + * So if it is destroyed by bt_gatt_client_destroy(), all related GATT handles are freed also. + * + * @param[in] service The service's GATT handle + * @param[out] client The GATT client handle which @a service belongs to + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_gatt_client_create() + */ +int bt_gatt_service_get_client(bt_gatt_h service, bt_gatt_client_h *client); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Gets a characteristic's GATT handle which has specific UUID + * @since_tizen 2.3.1 + * + * @remark The returned GATT handle must not be freed by application. + * It will be freed when an associated client is destroyed by bt_gatt_client_destroy(). + * If there are multiple characteristics which have same UUID, only the first matched one will be returned. + * + * @param[in] service The service's GATT handle + * @param[in] uuid The characteristic's GATT handle which has this UUID will be returned if it exists + * @param[out] characteristic The characteristic's GATT handle which has @a uuid if it exists + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NO_DATA No data available + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + */ +int bt_gatt_service_get_characteristic(bt_gatt_h service, const char *uuid, + bt_gatt_h *characteristic); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Invokes @a callback function on each characteristic that belongs to the specified service + * @since_tizen 2.3.1 + * + * @param[in] service The service's GATT handle + * @param[in] callback The function to be invoked on each characteristic + * @param[in] user_data The user data to be passed to @a callback function + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_gatt_foreach_cb() + */ +int bt_gatt_service_foreach_characteristics(bt_gatt_h service, + bt_gatt_foreach_cb callback, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Gets an included service's GATT handle which has specific UUID + * @since_tizen 2.3.1 + * + * @remark The returned GATT handle must not be freed by application. + * It will be freed when an associated client is destroyed by bt_gatt_client_destroy(). + * If there are multiple included services which have same UUID, only the first matched one will be returned. + * + * @param[in] service The service's GATT handle + * @param[in] uuid The included service's GATT handle which has this UUID will be returned if it exists + * @param[out] included_service The included service's GATT handle which has @a uuid if it exists + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NO_DATA No data available + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + */ +int bt_gatt_service_get_included_service(bt_gatt_h service, const char *uuid, + bt_gatt_h *included_service); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Invokes @a callback function on each included service that belongs to the specified service + * @since_tizen 2.3.1 + * + * @param[in] service The service's GATT handle + * @param[in] callback The function to be invoked on each included service + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_gatt_foreach_cb() + */ +int bt_gatt_service_foreach_included_services(bt_gatt_h service, + bt_gatt_foreach_cb callback, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Gets the service's GATT handle which the specified characteristic belongs to + * @since_tizen 2.3.1 + * + * @remark The returned GATT handle must not be freed by application. + * It will be freed when an associated client is destroyed by bt_gatt_client_destroy(). + * + * @param[in] characteristic The characteristic's GATT handle + * @param[out] service The service's GATT handle which @a characteristic belongs to + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + */ +int bt_gatt_characteristic_get_service(bt_gatt_h characteristic, bt_gatt_h *service); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Gets the properties which a characteristic's GATT handle has + * @since_tizen 2.3.1 + * + * @param[in] characteristic The characteristic's GATT handle + * @param[out] properties The properties which a characteristic's GATT handle has + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_gatt_property_e + */ +int bt_gatt_characteristic_get_properties(bt_gatt_h characteristic, int *properties); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Gets the write type of the specified characteristic + * @since_tizen 2.3.1 + * + * @param[in] characteristic The characteristic's GATT handle + * @param[out] write_type The write type of the specified characteristic + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_gatt_write_type_e + */ +int bt_gatt_characteristic_get_write_type(bt_gatt_h characteristic, + bt_gatt_write_type_e *write_type); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Updates the write type of the specified charateristic + * @since_tizen 2.3.1 + * + * @param[in] characteristic The characteristic's GATT handle + * @param[in] write_type The write type to be updated + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_gatt_client_write_value() + * @see bt_gatt_write_type_e + */ +int bt_gatt_characteristic_set_write_type(bt_gatt_h characteristic, + bt_gatt_write_type_e write_type); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Gets a descriptor's GATT handle which has specific UUID + * @since_tizen 2.3.1 + * + * @remark The returned GATT handle must not be freed by application. + * It will be freed when an associated client is destroyed by bt_gatt_client_destroy(). + * If there are multiple descriptors which have same UUID, only the first matched one will be returned. + * + * @param[in] characteristic The characteristic's GATT handle + * @param[in] uuid The descriptor's GATT handle which has this UUID will be returned if it exists + * @param[out] descriptor The descriptor's GATT handle which has @a uuid if it exists + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NO_DATA No data available + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + */ +int bt_gatt_characteristic_get_descriptor(bt_gatt_h characteristic, const char *uuid, + bt_gatt_h *descriptor); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Invokes @a callback function on each descriptor that belongs to the specified characteristic + * @since_tizen 2.3.1 + * + * @param[in] characteristic The characteristic's GATT handle + * @param[in] callback The function to be invoked on each descriptor + * @param[in] user_data The user data to be passed to @a callback function + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_gatt_foreach_cb() + */ +int bt_gatt_characteristic_foreach_descriptors(bt_gatt_h characteristic, + bt_gatt_foreach_cb callback, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Gets the characteristic's GATT handle which the specified descriptor belongs to + * @since_tizen 2.3.1 + * + * @remark The returned GATT handle must not be freed by application. + * It will be freed when an associated client is destroyed by bt_gatt_client_destroy(). + * + * @param[in] descriptor The descriptor's GATT handle + * @param[out] characteristic The characteristic's GATT handle which @a descriptor belongs to + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + */ +int bt_gatt_descriptor_get_characteristic(bt_gatt_h descriptor, bt_gatt_h *characteristic); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Creates the GATT client handle + * @since_tizen 2.3.1 + * + * @remark The GATT client handle must be freed by bt_gatt_client_destroy() after use + * + * @param[in] remote_address The address of the remote device + * @param[out] client The created GATT client's handle + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_OUT_OF_MEMORY Out of memory + * @retval #BT_ERROR_ALREADY_DONE Operation is already done + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_gatt_client_destroy() + */ +int bt_gatt_client_create(const char *remote_address, bt_gatt_client_h *client); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Destroys the GATT client's handle + * @since_tizen 2.3.1 + * + * @remark All related service, characteristic and descriptor's GATT handles are freed also + * + * @param[in] client The GATT client's handle + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_gatt_client_create() + */ +int bt_gatt_client_destroy(bt_gatt_client_h client); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Gets the address of remote device + * @since_tizen 2.3.1 + * + * @param[in] client The created GATT client's handle + * @param[out] remote_address The address of the remote device which is associated with @a client + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_gatt_client_create() + */ +int bt_gatt_client_get_remote_address(bt_gatt_client_h client, + char **remote_address); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Reads the value of a characteristic or descriptor from the remote device asynchronously + * @since_tizen 2.3.1 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * + * @param[in] gatt_handle The GATT handle of a characteristic or descriptor + * @param[in] callback When a read request is completed, this callback function will be called + * @param[in] user_data The user data to be passed to @a callback function + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_NOW_IN_PROGRESS Operation now in progress + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_gatt_client_create() + * @see bt_gatt_client_request_completed_cb() + */ +int bt_gatt_client_read_value(bt_gatt_h gatt_handle, + bt_gatt_client_request_completed_cb callback, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Writes the value of a characteristic or descriptor to the remote device asynchronously + * @since_tizen 2.3.1 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * + * @param[in] gatt_handle The GATT handle of a characteristic or descriptor + * @param[in] callback When a write request is completed, this callback function will be called + * @param[in] user_data The user data to be passed to @a callback function + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_NOW_IN_PROGRESS Operation now in progress + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_gatt_client_create() + * @see bt_gatt_characteristic_set_write_type() + * @see bt_gatt_set_value() + * @see bt_gatt_set_int_value() + * @see bt_gatt_set_float_value() + * @see bt_gatt_client_request_completed_cb() + */ +int bt_gatt_client_write_value(bt_gatt_h gatt_handle, + bt_gatt_client_request_completed_cb callback, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Registers a callback function to be invoked when the characteristic value is changed on the remote device + * @since_tizen 2.3.1 + * + * @param[in] characteristic The characteristic's GATT handle + * @param[in] callback The callback to be invoked when the value is changed and it is informed + * @param[in] user_data The user data to be passed to @a callback function + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_gatt_client_characteristic_value_changed_cb() + * @see bt_gatt_client_unset_characteristic_value_change() + */ +int bt_gatt_client_set_characteristic_value_changed_cb(bt_gatt_h characteristic, + bt_gatt_client_characteristic_value_changed_cb callback, + void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Unregisters a callback function to be invoked when the characteristic value is changed on the remote device + * @since_tizen 2.3.1 + * + * @param[in] characteristic The characteristic's GATT handle, whose value change will not be informed + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_gatt_client_set_characteristic_value_changed_cb() + */ +int bt_gatt_client_unset_characteristic_value_changed_cb(bt_gatt_h characteristic); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Gets a service's GATT handle which has specific UUID + * @since_tizen 2.3.1 + * + * @remark The returned GATT handle must not be freed by application. + * It will be freed when an associated client is destroyed by bt_gatt_client_destroy(). + * If there are multiple services which have same UUID, only the first matched one will be returned. + * + * @param[in] client The GATT client's handle + * @param[in] uuid The serivce's GATT handle which has this UUID will be returned if it exists + * @param[out] service The service's GATT handle which has @a uuid if it exists + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NO_DATA No data available + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + */ +int bt_gatt_client_get_service(bt_gatt_client_h client, const char *uuid, + bt_gatt_h *service); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Invokes @a callback function on each service that belongs to the specified GATT client + * @since_tizen 2.3.1 + * + * @param[in] client The GATT client's handle + * @param[in] callback The function to be invoked on each service + * @param[in] user_data The user data to be passed to @a callback function + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_gatt_foreach_cb() + */ +int bt_gatt_client_foreach_services(bt_gatt_client_h client, + bt_gatt_foreach_cb callback, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Connect to a specific LE based service on a remote bluetooth dievice address, asynchronously. + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * + * @remarks A connection can be disconnected by bt_gatt_disconnect(). + * + * @param[in] address The address of the remote Bluetooth device. + * @param[in] auto_connect The flag of the auto connection. + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_INVALID_PARAMETER Invalid paramater + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @pre The remote device must support le connection. + * @post This function invokes bt_gatt_connection_state_changed_cb(). + * + * @see bt_initialize() + * @see bt_gatt_disconnect() + * @see bt_gatt_set_connection_state_changed_cb() + * @see bt_gatt_unset_connection_state_changed_cb() + * @see bt_gatt_connection_state_changed_cb() + */ +int bt_gatt_connect(const char *address, bool auto_connect); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Disconnect to LE connection with the given remote Bluetooth dievice address, asynchronously. + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * + * @param[in] address The address of the remote Bluetooth device + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_INVALID_PARAMETER Invalid paramater + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The connection must be established. + * @post This function invokes bt_gatt_connection_state_changed_cb(). + * + * @see bt_initialize() + * @see bt_gatt_connect() + * @see bt_gatt_set_connection_state_changed_cb() + * @see bt_gatt_unset_connection_state_changed_cb() + * @see bt_gatt_connection_state_changed_cb() + */ +int bt_gatt_disconnect(const char *address); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Registers a callback function that will be invoked when the connection state is changed. + * @since_tizen 2.3 + * + * @param[in] callback The callback function to register. + * @param[in] user_data The user data to be passed to the callback function. + * + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid paramater + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_gatt_connect() + * @see bt_gatt_disconnect() + * @see bt_gatt_unset_connection_state_changed_cb() + */ +int bt_gatt_set_connection_state_changed_cb(bt_gatt_connection_state_changed_cb callback, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Unregisters a callback function that will be invoked when the connection state is changed. + * @since_tizen 2.3 + * + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_gatt_connect() + * @see bt_gatt_disconnect() + * @see bt_gatt_connection_state_changed_cb() + */ +int bt_gatt_unset_connection_state_changed_cb(void); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_PAN_NAP_MODULE + * @brief Activates the NAP(Network Access Point). + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_ALREADY_DONE Operation is already done + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED + * @see bt_nap_deactivate() + */ +int bt_nap_activate(void); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_PAN_NAP_MODULE + * @brief Deactivates the NAP(Network Access Point). + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_ALREADY_DONE Operation is already done + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth NAP service must be activated with bt_nap_activate(). + * @see bt_nap_activate() + */ +int bt_nap_deactivate(void); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_PAN_NAP_MODULE + * @brief Disconnects the all PANUs(Personal Area Networking User) which are connected to you. + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth NAP service must be activated with bt_nap_activate(). + * @see bt_nap_activate() + */ +int bt_nap_disconnect_all(void); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_PAN_NAP_MODULE + * @brief Disconnects the specified PANU(Personal Area Networking User) which is connected to you. + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * @param[in] remote_address The remote address + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth NAP service must be activated with bt_nap_activate(). + * @see bt_nap_activate() + */ +int bt_nap_disconnect(const char *remote_address); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_PAN_NAP_MODULE + * @brief Registers a callback function that will be invoked when the connection state changes. + * @since_tizen 2.3 + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @post bt_nap_connection_state_changed_cb() will be invoked. + * @see bt_initialize() + * @see bt_nap_connection_state_changed_cb() + * @see bt_nap_unset_connection_state_changed_cb() + */ +int bt_nap_set_connection_state_changed_cb(bt_nap_connection_state_changed_cb callback, void *user_data); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_PAN_NAP_MODULE + * @brief Unregisters a callback function that will be invoked when the connection state changes. + * @since_tizen 2.3 + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @post bt_nap_connection_state_changed_cb() will be invoked. + * @see bt_initialize() + * @see bt_nap_connection_state_changed_cb() + * @see bt_nap_set_connection_state_changed_cb() + */ +int bt_nap_unset_connection_state_changed_cb(void); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_PAN_PANU_MODULE + * @brief Registers a callback function that will be invoked when the connection state changes. + * @since_tizen 2.3 + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @post bt_nap_connection_state_changed_cb() will be invoked. + * @see bt_initialize() + * @see bt_panu_connection_state_changed_cb() + * @see bt_panu_unset_connection_state_changed_cb() + */ +int bt_panu_set_connection_state_changed_cb(bt_panu_connection_state_changed_cb callback, void *user_data); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_PAN_PANU_MODULE + * @brief Unregisters a callback function that will be invoked when the connection state changes. + * @since_tizen 2.3 + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @post bt_nap_connection_state_changed_cb() will be invoked. + * @see bt_initialize() + * @see bt_panu_connection_state_changed_cb() + * @see bt_panu_set_connection_state_changed_cb() + */ +int bt_panu_unset_connection_state_changed_cb(void); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_PAN_PANU_MODULE + * @brief Connects the remote device with the PAN(Personal Area Networking) service, asynchronously. + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * @param[in] remote_address The remote address + * @param[in] type The type of PAN service + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OUT_OF_MEMORY Out of memory + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The local device must be bonded with the remote device by bt_device_create_bond(). + * @post bt_panu_connection_state_changed_cb() will be invoked. + * @see bt_panu_disconnect() + * @see bt_panu_connection_state_changed_cb() + */ +int bt_panu_connect(const char *remote_address, bt_panu_service_type_e type); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_PAN_PANU_MODULE + * @brief Disconnects the remote device with the PAN(Personal Area Networking) service, asynchronously. + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * @param[in] remote_address The remote address + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected + * @retval #BT_ERROR_OUT_OF_MEMORY Out of memory + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The remote device must be connected by bt_panu_connect(). + * @post bt_panu_connection_state_changed_cb() will be invoked. + * @see bt_panu_connect() + * @see bt_panu_connection_state_changed_cb() + */ +int bt_panu_disconnect(const char *remote_address); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief update LE connection. + * @since_tizen 2.3 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized by bt_initialize(). + * @pre The remote device must be connected with bt_gatt_connect(). + */ +int bt_device_le_conn_update(const char *device_address, + const bt_le_conn_update_s *parameters); + + +/** + * @} + */ + + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif // __TIZEN_NETWORK_BLUETOOTH_H__ diff --git a/include/mobile/bluetooth_internal.h b/include/mobile/bluetooth_internal.h new file mode 100644 index 0000000..647a2bb --- /dev/null +++ b/include/mobile/bluetooth_internal.h @@ -0,0 +1,1601 @@ +/* + * 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 __TIZEN_NETWORK_BLUETOOTH_INTERNAL_H__ +#define __TIZEN_NETWORK_BLUETOOTH_INTERNAL_H__ + +#include +#include "bluetooth_type.h" +#include "bluetooth_type_internal.h" + +#ifdef __cplusplus +extern "C" +{ +#endif /* __cplusplus */ + +/** + * @file bluetooth_internal.h + */ + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Sets the manufacturer data of local Bluetooth adapter. + * @since_tizen 2.3 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * + * @param[in] data The manufacturer specific data of the Bluetooth device. + * @param[in] len The length of @a data.Maximaum length is 240 bytes. + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * @post bt_adapter_manufacturer_data_changed_cb() will be invoked + * if this function returns #BT_ERROR_NONE. + * + * @see bt_adapter_manufacturer_data_changed_cb + * @see bt_adapter_set_manufacturer_data_changed_cb() + * @see bt_adapter_unset_manufacturer_data_changed_cb() + */ +int bt_adapter_set_manufacturer_data(char *data, int len); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Registers a callback function to be invoked + * when the manufacturer data of Bluetooth adapter changes. + * @since_tizen 2.3 + * + * @param[in] callback The callback function to invoke + * @param[in] user_data The user data to be passed to the callback function + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @post bt_adapter_manufacturer_data_changed_cb() will be invoked. + * + * @see bt_initialize() + * @see bt_adapter_unset_manufacturer_data_changed_cb() + */ +int bt_adapter_set_manufacturer_data_changed_cb( + bt_adapter_manufacturer_data_changed_cb callback, + void *user_data); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Unregisters the callback function. + * @since_tizen 2.3 + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * + * @see bt_initialize() + * @see bt_adapter_set_manufacturer_data_changed_cb() + */ +int bt_adapter_unset_manufacturer_data_changed_cb(void); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Set Bluetooth LE scan mode + * @since_tizen 2.3 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @param[in] scan_mode The scan mode + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_ENABLED Adapter is not enabled + * @retval #BT_ERROR_INVALID_PARAM Parameter is invalid + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @see bt_initialize() + */ +int bt_adapter_le_set_scan_mode(bt_adapter_le_scan_mode_e scan_mode); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Creates scan filter to find only LE advertisement which has specific data. + * @since_tizen 2.4 + * + * @param[out] scan_filter The handle of scan filter + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_OUT_OF_MEMORY Out of memory + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * + * @see bt_adapter_le_destroy_scan_filter() + */ +int bt_adapter_le_create_scan_filter(bt_scan_filter_h *scan_filter); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Destroys scan filter. + * @since_tizen 2.4 + * + * @param[in] scan_filter The handle of scan filter + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * + * @see bt_adapter_le_create_scan_filter() + */ +int bt_adapter_le_destroy_scan_filter(bt_scan_filter_h scan_filter); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Adds the device address to filter advertisements + * @since_tizen 2.4 + * + * @param[in] scan_filter The handle of scan filter + * @param[in] address The device address to filter advertisements + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * + */ +int bt_adapter_le_scan_filter_set_device_address(bt_scan_filter_h scan_filter, const char *address); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Adds the device name to filter advertisements + * @since_tizen 2.4 + * + * @param[in] scan_filter The handle of scan filter + * @param[in] name The device name to filter advertisements + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * + */ +int bt_adapter_le_scan_filter_set_device_name(bt_scan_filter_h scan_filter, const char *name); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Adds the service UUID to filter advertisements + * @since_tizen 2.4 + * + * @param[in] scan_filter The handle of scan filter + * @param[in] uuid The service UUID to filter advertisements + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * + */ +int bt_adapter_le_scan_filter_set_service_uuid(bt_scan_filter_h scan_filter, const char *uuid); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Adds the service uuid and the mask to filter advertisements by partial data + * @since_tizen 2.4 + * + * @remarks the length of mask msut be the same with the length of service uuid. + * + * @param[in] scan_filter The handle of scan filter + * @param[in] uuid The service UUID to filter advertisements + * @param[in] mask The mask to filter advertisements + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * + */ +int bt_adapter_le_scan_filter_set_service_uuid_with_mask(bt_scan_filter_h scan_filter, + const char *uuid, const char *mask); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Adds the service solicitation UUID to filter advertisements + * @since_tizen 2.4 + * + * @param[in] scan_filter The handle of scan filter + * @param[in] uuid The service solicitation UUID to filter advertisements + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * + */ +int bt_adapter_le_scan_filter_set_service_solicitation_uuid(bt_scan_filter_h scan_filter, const char *uuid); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Adds the service solicitation uuid and the mask to filter advertisements by partial data + * @since_tizen 2.4 + * + * @remarks the length of mask msut be the same with the length of service solicitation uuid. + * + * @param[in] scan_filter The handle of scan filter + * @param[in] uuid The service solicitation UUID to filter advertisements + * @param[in] mask The mask to filter advertisements + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * + */ +int bt_adapter_le_scan_filter_set_service_solicitation_uuid_with_mask(bt_scan_filter_h scan_filter, + const char *uuid, const char *mask); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Adds the service data to filter advertisements + * @since_tizen 2.4 + * + * @param[in] scan_filter The handle of scan filter + * @param[in] uuid The service UUID to filter advertisements + * @param[in] data The service data to filter advertisements + * @param[in] data_len The length of the service data + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * + */ +int bt_adapter_le_scan_filter_set_service_data(bt_scan_filter_h scan_filter, + const char *uuid, const char *data, unsigned int data_len); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Adds the service data and the mask to filter advertisements by partial data + * @since_tizen 2.4 + * + * @remarks the length of mask msut be the same with the length of service data. + * + * @param[in] scan_filter The handle of scan filter + * @param[in] uuid The service UUID to filter advertisements + * @param[in] data The service data to filter advertisements + * @param[in] data_len The length of the service data + * @param[in] mask The mask to filter advertisements + * @param[in] mask_len The length of the mask to be set. + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * + */ +int bt_adapter_le_scan_filter_set_service_data_with_mask(bt_scan_filter_h scan_filter, + const char *uuid, const char *data, unsigned int data_len, const char *mask, unsigned int mask_len); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Adds the manufacturer data to filter advertisements + * @since_tizen 2.4 + * + * @param[in] scan_filter The handle of scan filter + * @param[in] manufacturer_id The manufacturer ID (0x0000 ~ 0xFFFF) + * @param[in] data The manufacturer data (byte array) + * @param[in] data_len The length of manufacturer data + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * + */ +int bt_adapter_le_scan_filter_set_manufacturer_data(bt_scan_filter_h scan_filter, + int manufacturer_id, const char *data, unsigned int data_len); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Adds the manufacturer data and the mask to filter advertisements by partial data + * @since_tizen 2.4 + * + * @remarks the length of mask msut be the same with the length of service uuid. + * + * @param[in] scan_filter The handle of scan filter + * @param[in] manufacturer_id The manufacturer ID (0x0000 ~ 0xFFFF) + * @param[in] data The manufacturer data (byte array) + * @param[in] data_len The length of manufacturer data + * @param[in] mask The mask to filter advertisements + * @param[in] mask_len The length of the mask to be set. + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * + */ +int bt_adapter_le_scan_filter_set_manufacturer_data_with_mask(bt_scan_filter_h scan_filter, + int manufacturer_id, const char *data, unsigned int data_len, const char *mask, unsigned int mask_len); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Registers the scan filter to use for scanning + * @since_tizen 2.4 + * + * @remarks Several scan filters can be registered. And the specific advertisements, satisfy the one of scan filters, will be found. + * + * @param[in] scan_filter The handle of scan filter + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOW_IN_PROGRESS Scan is in progress + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * + */ +int bt_adapter_le_register_scan_filter(bt_scan_filter_h scan_filter); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Unregisters the scan filter to be registered + * @since_tizen 2.4 + * + * @param[in] scan_filter The handle of scan filter + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOW_IN_PROGRESS Scan is in progress + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * + */ +int bt_adapter_le_unregister_scan_filter(bt_scan_filter_h scan_filter); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Unregisters all scan filters to be registered + * @since_tizen 2.4 + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOW_IN_PROGRESS Scan is in progress + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * + */ +int bt_adapter_le_unregister_all_scan_filters(void); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Set advertising filter policy to use white list + * @since_tizen 2.4 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * + * @param[in] advertiser The handle of advertiser + * @param[in] filter_policy The filter policy of advertising + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_NOW_IN_PROGRESS Operation is now in progress + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * + * @see bt_adapter_le_start_advertising_new() + */ +int bt_adapter_le_set_advertising_filter_policy(bt_advertiser_h advertiser, bt_adapter_le_advertising_filter_policy_e filter_policy); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Gets a connection state + * @since_tizen 2.4 + * + * @param[in] remote_address The address of the remote Bluetooth device + * @param[in] link_type The link type to get a connection state + * @param[out] connected The connection state + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + */ +int bt_device_get_connection_state(const char *remote_address, bt_device_connection_link_type_e link_type, bool *connected); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE + * @brief Registers a rfcomm server socket with a specific UUID. Activation by dbus is possible when the profile is connected. + * @since_tizen 2.4 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * + * @remarks A socket can be destroyed by bt_socket_destroy_rfcomm_ex(). + * Application should call this API to receive a connection event when launched again by dbus. + * + * @param[in] uuid The UUID of service to provide + * @param[in] bus_name bus_name of the application which is provided in service file. + * @param[in] object_path dbus of the application + * @return 0 on success, otherwise a negative error value. + * + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_NOW_IN_PROGRESS Already registered + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * + * @see bt_socket_listen_and_accept_rfcomm_ex() + * @see bt_socket_destroy_rfcomm_ex() + */ +int bt_socket_create_rfcomm_ex(const char *uuid, const char *bus_name, const char *object_path); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE + * @brief Removes the rfcomm server socket which was created using bt_socket_create_rfcomm_ex(). + * @since_tizen 2.4 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @remarks If callback function bt_socket_connection_state_changed_cb() is set and the remote Bluetooth device is connected, + * then bt_socket_connection_state_changed_cb() will be called when this function is finished successfully. + * + * @param[in] uuid The UUID (which was created using bt_socket_create_rfcomm()) to destroy + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The socket must be created with bt_socket_create_rfcomm_ex(). + * @post If callback function bt_socket_connection_state_changed_cb() is set and the remote Bluetooth device is connected, + * then bt_socket_connection_state_changed_cb() will be called. + * @see bt_socket_create_rfcomm_ex() + * @see bt_socket_connection_state_changed_cb() + * @see bt_socket_set_connection_state_changed_cb() + * @see bt_socket_unset_connection_state_changed_cb() + */ +int bt_socket_destroy_rfcomm_ex(const char *uuid); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE + * @brief Starts listening on passed rfcomm socket and accepts connection requests. Activation by dbus is possible when the profile is connected. + * @since_tizen 2.4 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @details Pop-up is shown automatically when a RFCOMM connection is requested. + * bt_socket_connection_state_changed_cb() will be called with + * #BT_SOCKET_CONNECTED if you click "yes" and connection is finished successfully. + * @param[in] uuid The UUID of service to provide + * @param[in] max_pending_connections The maximum number of pending connections + * @param[in] bus_name bus_name of the application which is provided in service file. + * @param[in] object_path dbus of the application + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The socket must be created with bt_socket_create_rfcomm_ex(). + * @post If callback function bt_socket_connection_state_changed_cb() is set, + * then bt_socket_connection_state_changed_cb() will be called when the remote Bluetooth device is connected. + * @see bt_socket_create_rfcomm_ex() + * @see bt_socket_connection_state_changed_cb() + * @see bt_socket_set_connection_state_changed_cb() + * @see bt_socket_unset_connection_state_changed_cb() + */ +int bt_socket_listen_and_accept_rfcomm_ex(const char *uuid, int max_pending_connections, const char* bus_name, const char *object_path); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Checks whether the remoted device is wbs (Wide Band Speech) mode or not. + * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif + * @param[out] wbs_mode The wbs status: (@c true = wide band speech, @c false = narrow band speech) + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * @pre The remote device is connected by bt_audio_connect() with #BT_AUDIO_PROFILE_TYPE_HSP_HFP service. + * @see bt_audio_connect() + */ +int bt_ag_is_wbs_mode(bool *wbs_mode); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Gets the HF(Hands-Free) profile connected status for AG role. + * @since_tizen 2.4 + * @param[out] connected the connected status: (@c true = connected , @c false = not connected ) + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + */ +int bt_ag_is_connected(bool *connected); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_A2DP_MODULE + * @brief Sets copy protection. streaming application that needs to have the copy protection for the streaming data, shall invoke this API. + * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @param[in] status - TRUE/FALSE + * @return 0 on success, otherwise negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_OPERATION_FAILED on failure + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + */ +int bt_a2dp_set_content_protection(bool status); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Gets the specification name from the UUID + * @since_tizen 2.4 + * + * @remarks @a name must be released with free() by you. + * + * @param[in] uuid The UUID + * @param[out] name The specification name which defined from www.bluetooth.org + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_gatt_get_uuid() + */ +int bt_gatt_get_uuid_specification_name(const char *uuid, char **name); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Destroys the GATT handle + * @since_tizen 2.4 + * + * @param[in] gatt_handle The handle of service, characteristic or descriptor + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_gatt_service_create() + * @see bt_gatt_characteristic_create() + * @see bt_gatt_descriptor_create() + */ +int bt_gatt_destroy(bt_gatt_h gatt_handle); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Gets the permissions which a characteristic or descriptor's GATT handle has + * @since_tizen 2.4 + * + * @param[in] gatt_handle The handle of a characteristic or descriptor + * @param[out] permissions The permissions which a characteristic or descriptor's GATT handle has. + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_gatt_characteristic_create() + * @see bt_gatt_descriptor_create() + * @see bt_gatt_permission_e + */ +int bt_gatt_get_permissions(bt_gatt_h gatt_handle, int *permissions); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Updates the permissions which a characteristic or descriptor's GATT handle has + * @since_tizen 2.4 + * + * @param[in] gatt_handle The handle of a characteristic or descriptor + * @param[in] permissions The permissions to be updated + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_gatt_characteristic_create() + * @see bt_gatt_descriptor_create() + * @see bt_gatt_permission_e + */ +int bt_gatt_set_permissions(bt_gatt_h gatt_handle, int permissions); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Creates the GATT service + * @since_tizen 2.4 + * + * @param[in] uuid The UUID of the service + * @param[in] type The type of the service + * @param[out] service The GATT handle of the created service + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_OUT_OF_MEMORY Out of memory + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_gatt_destroy() + */ +int bt_gatt_service_create(const char *uuid, bt_gatt_service_type_e type, + bt_gatt_h *service); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Adds a characteristic to a specified service + * @since_tizen 2.4 + * + * @param[in] service The service's GATT handle + * @param[in] characteristic The characteristic's GATT handle to be added + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_gatt_service_create() + * @see bt_gatt_characteristic_create() + */ +int bt_gatt_service_add_characteristic(bt_gatt_h service, + bt_gatt_h characteristic); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Adds a service to a specified service as included service + * @since_tizen 2.4 + * + * @param[in] service The service's GATT handle + * @param[in] included_service The service's GATT handle to be added as included service + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_gatt_service_create() + */ +int bt_gatt_service_add_included_service(bt_gatt_h service, + bt_gatt_h included_service); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Gets the GATT server handle to which the specified service belongs + * @since_tizen 2.4 + * + * @param[in] service The service's GATT handle + * @param[out] server The GATT server handle to which @a service belongs + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_gatt_server_create() + * @see bt_gatt_service_create() + * @see bt_gatt_server_register_service() + */ +int bt_gatt_service_get_server(bt_gatt_h service, bt_gatt_server_h *server); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Creates the GATT characteristic + * @since_tizen 2.4 + * + * @param[in] uuid The UUID of the characteristic + * @param[in] permissions the permissions of the characteristic + * @param[in] properties The properties of the characteristic + * @param[in] Value The value(byte stream) of the characteristic + * @param[in] value_length The length of @a value + * @param[out] characteristic The GATT handle of the created characteristic + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_OUT_OF_MEMORY Out of memory + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_gatt_destroy() + */ +int bt_gatt_characteristic_create(const char *uuid, int permissions, + int properties, const char *value, int value_length, + bt_gatt_h *characteristic); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Adds a descriptor to a specified characteristic + * @since_tizen 2.4 + * + * @param[in] characteristic The GATT handle of the characteristic + * @param[in] descriptor The descriptor's GATT handle to be added + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_gatt_characteristic_create() + * @see bt_gatt_descriptor_create() + */ +int bt_gatt_characteristic_add_descriptor(bt_gatt_h characteristic, + bt_gatt_h descriptor); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Creates the GATT characteristic descriptor + * @since_tizen 2.4 + * + * @param[in] uuid The UUID of the descriptor + * @param[in] permissions The permissions of the descriptor + * @param[in] value The value(byte stream) associated with the descriptor + * @param[in] value_length The length of @a value + * @param[out] descriptor The GATT handle of the created characteristic descriptor + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_OUT_OF_MEMORY Out of memory + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_gatt_destroy() + */ +int bt_gatt_descriptor_create(const char *uuid, int permissions, + const char *value, int value_length, + bt_gatt_h *descriptor); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Initializes the GATT Server + * @since_tizen 2.4 + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * @see bt_gatt_server_deinitialize() + */ +int bt_gatt_server_initialize(void); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief DeInitializes the GATT server + * @since_tizen 2.4 + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * @see bt_gatt_server_initialize() + */ +int bt_gatt_server_deinitialize(void); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Creates the GATT server's handle + * @since_tizen 2.4 + * + * @param[out] server The GATT server's handle + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_OUT_OF_MEMORY Out of memory + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_gatt_server_destroy() + */ +int bt_gatt_server_create(bt_gatt_server_h *server); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Destroys the GATT server's handle + * @since_tizen 2.4 + * + * @remarks All registered services to GATT server are unregistered + * + * @param[in] server The GATT server's handle + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_gatt_server_create() + */ +int bt_gatt_server_destroy(bt_gatt_server_h server); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Registers a callback function to be invoked when a read request for a specified characteristic or descriptor is issued from a remote device(GATT client) + * @since_tizen 2.4 + * + * @param[in] gatt_handle The GATT handle of a characteristic or descriptor + * @param[in] callback The callback to be invoked + * @param[in] user_data The user data to be passed to @a callback function + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_gatt_server_read_value_requested_cb() + * @see bt_gatt_server_send_response() + */ +int bt_gatt_server_set_read_value_requested_cb(bt_gatt_h gatt_handle, + bt_gatt_server_read_value_requested_cb callback, + void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Registers a callback function to be invoked when a value of a characteristic or descriptor has been changed by a remote device(GATT client)'s request + * @since_tizen 2.4 + * + * @param[in] gatt_handle The GATT handle of a characteristic or descriptor + * @param[in] callback The callback to be invoked + * @param[in] user_data The user data to be passed to @a callback function + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_gatt_server_value_changed_cb() + */ +int bt_gatt_server_set_value_changed_cb(bt_gatt_h gatt_handle, + bt_gatt_server_value_changed_cb callback, + void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Registers a specified service to the specified GATT server that the local device is hosting + * @since_tizen 2.4 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * + * @param[in] server The GATT server that local device is hosting + * @param[in] service The service, which needs to be registered in @a server + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_ALREADY_DONE Operation is already done + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_gatt_server_create() + * @see bt_gatt_service_create() + * @see bt_gatt_server_unregister_service() + */ +int bt_gatt_server_register_service(bt_gatt_server_h server, bt_gatt_h service); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Unregisters a specified service from the specified GATT server that the local device is hosting + * @since_tizen 2.4 + * + * @param[in] server The GATT server that local device is hosting + * @param[in] service The service, which needs to be unregistered from @a server + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_SERVICE_NOT_FOUND Service not found + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_gatt_server_register_service() + */ +int bt_gatt_server_unregister_service(bt_gatt_server_h server, bt_gatt_h service); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Unregisters all services from the specified GATT server that the local device is hosting + * @since_tizen 2.4 + * + * @param[in] server The GATT server that local device is hosting + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_gatt_server_register_service() + */ +int bt_gatt_server_unregister_all_services(bt_gatt_server_h server); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Sends a response to the remote device as a result of a read request + * @since_tizen 2.4 + * + * @remarks Until this function is called, a read request is not finished. + * + * @param[in] request_id The identification of a read request + * @param[in] offset The offset from where a value is read + * @param[in] value The value to be sent. It will be sent from @a offset. If it is NULL, a requested GATT handle's value will be sent from @a offset. + * @param[in] value_length Value Length + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_gatt_server_read_value_requested_cb() + */ +int bt_gatt_server_send_response(int request_id, + int offset, char *value, int value_length); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Notifys a value change of the characteristic to the remote devices which enable a Client Characteristic Configuration Descriptor + * @since_tizen 2.4 + * + * @param[in] characteristic The characteristic which has a changed value + * @param[in] need_confirm If it is true, an indication is sent. If it is false, a notification is sent. + * @param[in] callback The function to be invoked on each remote device when a sending operation is done + * @param[in] user_data The user data to be passed to @a callback function + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_gatt_server_notification_sent_cb() + */ +int bt_gatt_server_notify(bt_gatt_h characteristic, bool need_confirm, + bt_gatt_server_notification_sent_cb callback, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Gets a service's GATT handle which has specific UUID + * @since_tizen 2.4 + * + * @remark The returned GATT handle must not be freed by application. + * It will be freed when an associated server is destroyed by bt_gatt_server_destroy(). + * If there are multiple services which have same UUID, only the first matched one will be returned. + * + * @param[in] server The GATT server's handle + * @param[in] uuid The serivce's GATT handle which has this UUID will be returned if it exists + * @param[out] service The service's GATT handle which has @a uuid if it exists + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NO_DATA No data available + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + */ +int bt_gatt_server_get_service(bt_gatt_server_h server, const char *uuid, + bt_gatt_h *service); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Invokes @a callback function on each service that belongs to the specified GATT server + * @since_tizen 2.4 + * + * @param[in] server The GATT server's handle + * @param[in] callback The function to be invoked on each service + * @param[in] user_data The user data to be passed to @a callback function + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_gatt_foreach_cb() + */ +int bt_gatt_server_foreach_services(bt_gatt_server_h server, + bt_gatt_foreach_cb callback, void *user_data); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief Registers a callback function that will be invoked when the song position is changed by the remote target device. + * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized by bt_initialize(). + * @see bt_initialize() + * @see bt_avrcp_unset_song_position_changed_cb() + */ +int bt_avrcp_set_song_position_changed_cb(bt_avrcp_song_position_changed_cb callback, void *user_data); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief Unregisters a callback function that will be invoked when the song position is changed by the remote target device. + * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized by bt_initialize(). + * @see bt_initialize() + * @see bt_avrcp_set_song_position_changed_cb() + */ +int bt_avrcp_unset_song_position_changed_cb(void); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief Registers a callback function that will be invoked when the Play status is changed by the remote target device. + * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized by bt_initialize(). + * @see bt_initialize() + * @see bt_avrcp_unset_play_status_changed_cb() + */ +int bt_avrcp_set_play_status_changed_cb(bt_avrcp_play_status_changed_cb callback, void *user_data); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief Unregisters a callback function that will be invoked when the Play status is changed by the remote target device. + * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized by bt_initialize(). + * @see bt_initialize() + * @see bt_avrcp_unset_play_status_changed_cb() + */ +int bt_avrcp_unset_play_status_changed_cb(void); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief Registers a callback function that will be invoked when the track metadata is changed by the remote target device. + * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized by bt_initialize(). + * @see bt_initialize() + * @see bt_avrcp_unset_track_info_changed_cb() + */ +int bt_avrcp_set_track_info_changed_cb(bt_avrcp_track_info_changed_cb callback, void *user_data); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief Unregisters a callback function that will be invoked when the track metadata is changed by the remote target device. + * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized by bt_initialize(). + * @see bt_initialize() + * @see bt_avrcp_set_track_info_changed_cb() + */ +int bt_avrcp_unset_track_info_changed_cb(void); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_MODULE + * @brief Registers a callback function that will be invoked when the A2DP Source connection state is changed. + * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth audio service must be initialized with bt_audio_initialize(). + * @see bt_audio_initialize() + * @see bt_audio_connection_state_changed_cb() + */ +int bt_a2dp_source_audio_set_connection_state_changed_cb(bt_audio_connection_state_changed_cb callback, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_MODULE + * @brief Unregisters a callback function that will be invoked when the A2DP Source connection state is changed. + * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth audio service must be initialized with bt_audio_initialize(). + * @see bt_audio_initialize() + * @see bt_audio_connection_state_changed_cb() + * @see bt_audio_set_connection_state_changed_cb() + */ +int bt_a2dp_source_audio_unset_connection_state_changed_cb(void); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief Initializes the Bluetooth AVRCP(Audio/Video Remote Control Profile) service. + * @since_tizen 2.4 + * @remarks This function must be called before Bluetooth AVRCP service. \n + * You must free all resources of the this service by calling bt_avrcp_control_deinitialize() + * if Bluetooth AVRCP service is no longer needed. + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @param[in] callback The callback function called when the connection state is changed + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @see bt_initialize() + * @see bt_avrcp_control_deinitialize() + */ +int bt_avrcp_control_initialize(bt_avrcp_control_connection_state_changed_cb callback, void *user_data); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief Deinitializes the Bluetooth AVRCP(Audio/Video Remote Control Profile) service. + * @since_tizen 2.4 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * @pre The Bluetooth audio service must be initialized with bt_avrcp_control_initialize(). + * @see bt_avrcp_control_initialize() + */ +int bt_avrcp_control_deinitialize(void); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief Connects the Bluetooth AVRCP(Audio/Video Remote Control Profile) service. + * @since_tizen 2.4 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * @pre The Bluetooth audio service must be initialized with bt_avrcp_control_initialize(). + * @see bt_avrcp_control_initialize() + */ +int bt_avrcp_control_connect(const char *remote_address); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief Disconnects the Bluetooth AVRCP(Audio/Video Remote Control Profile) service. + * @since_tizen 2.4 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * @pre The Bluetooth audio service must be initialized with bt_avrcp_control_initialize(). + * @see bt_avrcp_control_initialize() + * @see bt_avrcp_control_connect() + */ +int bt_avrcp_control_disconnect(const char *remote_address); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief Handle the Bluetooth AVRCP(Audio/Video Remote Control Profile) commands. + * @since_tizen 2.4 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @param[in] AVRCP Commands Play, Pause, Next, Rewind. + * @return 0 on success, otherwise a negative error value. + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * @pre The Bluetooth audio service must be initialized with bt_avrcp_control_initialize(). + * @see bt_avrcp_control_initialize() + * @see bt_avrcp_control_connect() + */ +int bt_avrcp_control_send_player_command(bt_avrcp_player_command_e cmd); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief send the equalizer change to the remote device. + * @since_tizen 2.4 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @param[in] state To set the equalizer state ON/OFF + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The remote device must be connected. + * @see bt_avrcp_target_connection_state_changed_cb() + * @see bt_avrcp_target_initialize() + */ +int bt_avrcp_control_set_equalizer_state(bt_avrcp_equalizer_state_e state); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief get the the equalize state of the remote device. + * @since_tizen 2.4 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @param[in] equalizer To get the equalizer value ON/OFF + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The remote device must be connected. + * @see bt_avrcp_target_connection_state_changed_cb() + * @see bt_avrcp_target_initialize() + */ +int bt_avrcp_control_get_equalizer_state(bt_avrcp_equalizer_state_e *state); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief send the repeat change to the remote device. + * @since_tizen 2.4 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @param[in] Mode To set the repeat mode OFF, SINGLE, ALL + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The remote device must be connected. + * @see bt_avrcp_target_connection_state_changed_cb() + * @see bt_avrcp_target_initialize() + */ +int bt_avrcp_control_set_repeat_mode(bt_avrcp_repeat_mode_e mode); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief get the repeat state of the remote device. + * @since_tizen 2.4 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @param[in] Mode To get the repeat mode OFF, SINGLE, ALL + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The remote device must be connected. + * @see bt_avrcp_target_connection_state_changed_cb() + * @see bt_avrcp_target_initialize() + */ +int bt_avrcp_control_get_repeat_mode(bt_avrcp_repeat_mode_e *mode); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief send the shuffle change to the remote device. + * @since_tizen 2.4 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @param[in] Mode To set the shuffle mode OFF, GROUP, ALL + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The remote device must be connected. + * @see bt_avrcp_target_connection_state_changed_cb() + * @see bt_avrcp_target_initialize() + */ +int bt_avrcp_control_set_shuffle_mode(bt_avrcp_shuffle_mode_e mode); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief get the shuffle state of the remote device. + * @since_tizen 2.4 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @param[in] Mode To get the shuffle mode OFF, GROUP, ALL + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The remote device must be connected. + * @see bt_avrcp_target_connection_state_changed_cb() + * @see bt_avrcp_target_initialize() + */ +int bt_avrcp_control_get_shuffle_mode(bt_avrcp_shuffle_mode_e *mode); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief send the scan mode change to the remote device. + * @since_tizen 2.4 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @param[in] Mode To set the scan mode OFF, GROUP, ALL + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The remote device must be connected. + * @see bt_avrcp_target_connection_state_changed_cb() + * @see bt_avrcp_target_initialize() + */ +int bt_avrcp_control_set_scan_mode(bt_avrcp_scan_mode_e mode); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief get the scan mode of the remote device. + * @since_tizen 2.4 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @param[in] Mode To get the scan mode OFF, GROUP, ALL + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The remote device must be connected. + * @see bt_avrcp_target_connection_state_changed_cb() + * @see bt_avrcp_target_initialize() + */ +int bt_avrcp_control_get_scan_mode(bt_avrcp_scan_mode_e *mode); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief get the song position vale of the remote device. + * @since_tizen 2.4 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @param[in] Mode To get the position value in milliseconds + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The remote device must be connected. + * @see bt_avrcp_target_connection_state_changed_cb() + * @see bt_avrcp_target_initialize() + */ +int bt_avrcp_control_get_position(unsigned int *position); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief get the play status of the remote device. + * @since_tizen 2.4 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @param[in] Mode To get the play status PLAYING, STOPPED... + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The remote device must be connected. + * @see bt_avrcp_target_connection_state_changed_cb() + * @see bt_avrcp_target_initialize() + */ +int bt_avrcp_control_get_play_status(bt_avrcp_player_state_e *status); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief get the metadata of the remote device. + * @since_tizen 2.4 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @param[in] track To get the metadata of track played in remote device. + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The remote device must be connected. + * @see bt_avrcp_target_connection_state_changed_cb() + * @see bt_avrcp_target_initialize() + */ +int bt_avrcp_control_get_track_info(bt_avrcp_metadata_attributes_info_s **track); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief to free the metadata staructure. + * @since_tizen 2.4 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @param[in] track To free the memory of metadata structure. + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @pre track should point to valid metadata address. + * @see bt_avrcp_control_get_track_info() + * @see bt_avrcp_target_initialize() + */ +int bt_avrcp_control_free_track_info(bt_avrcp_metadata_attributes_info_s *track); + +/** + * @} + */ + + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif // __TIZEN_NETWORK_BLUETOOTH_INTERNAL_H__ diff --git a/include/mobile/bluetooth_type.h b/include/mobile/bluetooth_type.h new file mode 100644 index 0000000..96aa359 --- /dev/null +++ b/include/mobile/bluetooth_type.h @@ -0,0 +1,1829 @@ +/* + * 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 __TIZEN_NETWORK_BLUETOOTH_TYPE_H__ +#define __TIZEN_NETWORK_BLUETOOTH_TYPE_H__ + + #ifdef __cplusplus +extern "C" +{ +#endif /* __cplusplus */ + +/** + * @file bluetooth_type.h + * @brief API to control the Bluetooth adapter, devices and communications. + * @ingroup CAPI_NETWORK_BLUETOOTH_TYPE_MODULE + */ + + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_MODULE + * @brief Enumerations of Bluetooth error codes. + * @since_tizen 2.3 + */ +typedef enum +{ + BT_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful*/ + BT_ERROR_CANCELLED = TIZEN_ERROR_CANCELED, /**< Operation cancelled */ + BT_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid parameter */ + BT_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of memory */ + BT_ERROR_RESOURCE_BUSY = TIZEN_ERROR_RESOURCE_BUSY, /**< Device or resource busy */ + BT_ERROR_TIMED_OUT = TIZEN_ERROR_TIMED_OUT, /**< Timeout error */ + BT_ERROR_NOW_IN_PROGRESS = TIZEN_ERROR_NOW_IN_PROGRESS, /**< Operation now in progress */ + BT_ERROR_NOT_SUPPORTED = TIZEN_ERROR_NOT_SUPPORTED, /**< BT is Not Supported */ + BT_ERROR_PERMISSION_DENIED = TIZEN_ERROR_PERMISSION_DENIED, /**< Permission denied */ + BT_ERROR_QUOTA_EXCEEDED = TIZEN_ERROR_QUOTA_EXCEEDED, /**< Quota exceeded */ + BT_ERROR_NO_DATA = TIZEN_ERROR_NO_DATA, /**< No data available */ + BT_ERROR_NOT_INITIALIZED = TIZEN_ERROR_BLUETOOTH|0x0101, /**< Local adapter not initialized */ + BT_ERROR_NOT_ENABLED = TIZEN_ERROR_BLUETOOTH|0x0102, /**< Local adapter not enabled */ + BT_ERROR_ALREADY_DONE = TIZEN_ERROR_BLUETOOTH|0x0103, /**< Operation already done */ + BT_ERROR_OPERATION_FAILED = TIZEN_ERROR_BLUETOOTH|0x0104, /**< Operation failed */ + BT_ERROR_NOT_IN_PROGRESS = TIZEN_ERROR_BLUETOOTH|0x0105, /**< Operation not in progress */ + BT_ERROR_REMOTE_DEVICE_NOT_BONDED = TIZEN_ERROR_BLUETOOTH|0x0106, /**< Remote device not bonded */ + BT_ERROR_AUTH_REJECTED = TIZEN_ERROR_BLUETOOTH|0x0107, /**< Authentication rejected */ + BT_ERROR_AUTH_FAILED = TIZEN_ERROR_BLUETOOTH|0x0108, /**< Authentication failed */ + BT_ERROR_REMOTE_DEVICE_NOT_FOUND = TIZEN_ERROR_BLUETOOTH|0x0109, /**< Remote device not found */ + BT_ERROR_SERVICE_SEARCH_FAILED = TIZEN_ERROR_BLUETOOTH|0x010A, /**< Service search failed */ + BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED = TIZEN_ERROR_BLUETOOTH|0x010B, /**< Remote device is not connected */ + BT_ERROR_AGAIN = TIZEN_ERROR_BLUETOOTH|0x010C, /**< Resource temporarily unavailable */ + BT_ERROR_SERVICE_NOT_FOUND = TIZEN_ERROR_BLUETOOTH|0x010D, /**< Service Not Found */ +} bt_error_e; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Enumerations of the Bluetooth adapter state. + * @since_tizen 2.3 + */ +typedef enum +{ + BT_ADAPTER_DISABLED = 0x00, /**< Bluetooth adapter is disabled */ + BT_ADAPTER_ENABLED, /**< Bluetooth adapter is enabled */ +} bt_adapter_state_e; + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Enumerations of the Bluetooth adapter le state. + * @since_tizen 2.3 + */ +typedef enum +{ + BT_ADAPTER_LE_DISABLED = 0x00, /**< Bluetooth le is disabled */ + BT_ADAPTER_LE_ENABLED, /**< Bluetooth le is enabled */ +} bt_adapter_le_state_e; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Enumerations of the Bluetooth visibility mode. + * @since_tizen 2.3 + */ +typedef enum +{ + BT_ADAPTER_VISIBILITY_MODE_NON_DISCOVERABLE = 0x00, /**< Other devices cannot find your device via discovery */ + BT_ADAPTER_VISIBILITY_MODE_GENERAL_DISCOVERABLE, /**< Discoverable mode */ + BT_ADAPTER_VISIBILITY_MODE_LIMITED_DISCOVERABLE, /**< Discoverable mode with time limit. After specific period, + it is changed to #BT_ADAPTER_VISIBILITY_MODE_NON_DISCOVERABLE.*/ +} bt_adapter_visibility_mode_e; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Enumerations of the discovery state of Bluetooth device. + * @since_tizen 2.3 + */ +typedef enum +{ + BT_ADAPTER_DEVICE_DISCOVERY_STARTED, /**< Device discovery is started */ + BT_ADAPTER_DEVICE_DISCOVERY_FINISHED, /**< Device discovery is finished */ + BT_ADAPTER_DEVICE_DISCOVERY_FOUND, /**< The remote Bluetooth device is found */ +} bt_adapter_device_discovery_state_e; + +/** + * @deprecated Deprecated since 2.3.1 + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Enumerations of the discovery state of Bluetooth LE device. + * @since_tizen 2.3 + * + */ +typedef enum +{ + BT_ADAPTER_LE_DEVICE_DISCOVERY_STARTED, /**< LE device discovery is started */ + BT_ADAPTER_LE_DEVICE_DISCOVERY_FINISHED, /**< LE device discovery is finished */ + BT_ADAPTER_LE_DEVICE_DISCOVERY_FOUND, /**< The remote Bluetooth LE device is found */ +} bt_adapter_le_device_discovery_state_e; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Enumerations of the Bluetooth advertising state. + * @since_tizen 2.3 + */ +typedef enum { + BT_ADAPTER_LE_ADVERTISING_STOPPED = 0x00, /**< Bluetooth advertising is stopped */ + BT_ADAPTER_LE_ADVERTISING_STARTED, /**< Bluetooth advertising is started */ +} bt_adapter_le_advertising_state_e; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Enumerations of the Bluetooth advertising mode. + * @since_tizen 2.3.1 + */ +typedef enum +{ + BT_ADAPTER_LE_ADVERTISING_MODE_BALANCED, /**< Balanced advertising mode */ + BT_ADAPTER_LE_ADVERTISING_MODE_LOW_LATENCY, /**< Low latency advertising mode */ + BT_ADAPTER_LE_ADVERTISING_MODE_LOW_ENERGY /**< Low energy advertising mode */ +} bt_adapter_le_advertising_mode_e; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Enumerations of the Bluetooth advertising filter policy. + * @since_tizen 2.3 + */ +typedef enum { + BT_ADAPTER_LE_ADVERTISING_FILTER_DEFAULT = 0x00, /**< White list is not in use */ + BT_ADAPTER_LE_ADVERTISING_FILTER_ALLOW_SCAN_WL = 0x01, /**< Allow the scan + request that in the White list */ + BT_ADAPTER_LE_ADVERTISING_FILTER_ALLOW_CONN_WL = 0x02, /**< Allow the connectoin + request that in the White list */ + BT_ADAPTER_LE_ADVERTISING_FILTER_ALLOW_SCAN_CONN_WL = 0x03, /**< Allow the + scan and connectoin request that in the White list */ +} bt_adapter_le_advertising_filter_policy_e; + +/** + * @deprecated Deprecated since 2.3.1 + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Enumerations of the Bluetooth advertising type. + * @since_tizen 2.3 + */ +typedef enum { + BT_ADAPTER_LE_ADVERTISING_CONNECTABLE = 0x00, /**< Connectable undirected advertising (ADV_IND) */ + BT_ADAPTER_LE_ADVERTISING_CONNECTABLE_DIRECT_HIGH = 0x01, /**< Connectable high duty cycle directed advertising (ADV_DIRECT_IND) */ + BT_ADAPTER_LE_ADVERTISING_SCANNABLE = 0x02, /**< Scannable undirected advertising (ADV_SCAN_IND) */ + BT_ADAPTER_LE_ADVERTISING_NON_CONNECTABLE = 0x03, /**< Non connectable undirected advertising (ADV_NONCOND_IND) */ + BT_ADAPTER_LE_ADVERTISING_CONNECTABLE_DIRECT_LOW = 0x04, /**< Connectable low duty cycle directed advertising (ADV_DIRECT_IND) */ +} bt_adapter_le_advertising_type_e; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Enumerations of the Bluetooth LE packet type. + * @since_tizen 2.3 + */ +typedef enum { + BT_ADAPTER_LE_PACKET_ADVERTISING, /**< Advertising packet */ + BT_ADAPTER_LE_PACKET_SCAN_RESPONSE, /**< Sacn response packet */ +} bt_adapter_le_packet_type_e; + +/** + * @deprecated Deprecated since 2.3.1 + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Enumerations of the Bluetooth LE data type + * that can be included in LE packets. + * @since_tizen 2.3 + */ +typedef enum { + BT_ADAPTER_LE_PACKET_DATA_COMP_LIST_16_BIT_SERVICE_CLASS_UUIDS = 0x03, /**< Complete list of 16 bit UUIDs */ + BT_ADAPTER_LE_PACKET_DATA_MANUFACTURER_SPECIFIC_DATA = 0xff, /**< Manufacturer data */ +} bt_adapter_le_packet_data_type_e; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Enumerations of device disconnect reason. + * @since_tizen 2.3 + */ +typedef enum +{ + BT_DEVICE_DISCONNECT_REASON_UNKNOWN, /**< Disconnected by unknown reason */ + BT_DEVICE_DISCONNECT_REASON_TIMEOUT, /**< Disconnected by timeout */ + BT_DEVICE_DISCONNECT_REASON_LOCAL_HOST, /**< Disconnected by local host */ + BT_DEVICE_DISCONNECT_REASON_REMOTE, /**< Disconnected by remote */ +} bt_device_disconnect_reason_e; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Enumerations of connection link type. + * @since_tizen 2.3 + */ +typedef enum +{ + BT_DEVICE_CONNECTION_LINK_BREDR, /**< BR/EDR link */ + BT_DEVICE_CONNECTION_LINK_LE, /**< LE link */ + BT_DEVICE_CONNECTION_LINK_DEFAULT = 0xFF, /**< The connection type defualt */ +} bt_device_connection_link_type_e; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Enumerations of device authorization state. + * @since_tizen 2.3 + */ +typedef enum +{ + BT_DEVICE_AUTHORIZED, /**< The remote Bluetooth device is authorized */ + BT_DEVICE_UNAUTHORIZED, /**< The remote Bluetooth device is unauthorized */ +} bt_device_authorization_e; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Enumerations of Bluetooth profile. + * @since_tizen 2.3 + */ +typedef enum +{ + BT_PROFILE_RFCOMM = 0x01, /**< RFCOMM Profile */ + BT_PROFILE_A2DP = 0x02, /**< Advanced Audio Distribution Profile */ + BT_PROFILE_HSP = 0x04, /**< Headset Profile */ + BT_PROFILE_HID = 0x08, /**< Human Interface Device Profile */ + BT_PROFILE_NAP = 0x10, /**< Network Access Point Profile */ + BT_PROFILE_AG = 0x20, /**< Audio Gateway Profile */ + BT_PROFILE_GATT = 0x40, /**< Generic Attribute Profile */ + BT_PROFILE_NAP_SERVER = 0x80, /**< NAP server Profile */ +} bt_profile_e; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Enumerations of device address type. + * @since_tizen 2.3 + */ +typedef enum +{ + BT_DEVICE_PUBLIC_ADDRESS = 0x00, /**< Public address */ + BT_DEVICE_RANDOM_ADDRESS, /**< Random address */ +} bt_device_address_type_e; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Enumerations of service class. + * @since_tizen 2.3 + */ +typedef enum { + BT_SC_NONE = 0, /**< No service class */ + BT_SC_RES_SERVICE_MASK = 0x00000001, /**< RES service class */ + BT_SC_SPP_SERVICE_MASK = 0x00000002, /**< SPP service class */ + BT_SC_DUN_SERVICE_MASK = 0x00000004, /**< DUN service class */ + BT_SC_FAX_SERVICE_MASK = 0x00000008, /**< FAX service class */ + BT_SC_LAP_SERVICE_MASK = 0x00000010, /**< LAP service class */ + BT_SC_HSP_SERVICE_MASK = 0x00000020, /**< HSP service class */ + BT_SC_HFP_SERVICE_MASK = 0x00000040, /**< HFP service class */ + BT_SC_OPP_SERVICE_MASK = 0x00000080, /**< OPP service class */ + BT_SC_FTP_SERVICE_MASK = 0x00000100, /**< FTP service class */ + BT_SC_CTP_SERVICE_MASK = 0x00000200, /**< CTP service class */ + BT_SC_ICP_SERVICE_MASK = 0x00000400, /**< ICP service class */ + BT_SC_SYNC_SERVICE_MASK = 0x00000800, /**< SYNC service class */ + BT_SC_BPP_SERVICE_MASK = 0x00001000, /**< BPP service class */ + BT_SC_BIP_SERVICE_MASK = 0x00002000, /**< BIP service class */ + BT_SC_PANU_SERVICE_MASK = 0x00004000, /**< PANU service class */ + BT_SC_NAP_SERVICE_MASK = 0x00008000, /**< NAP service class */ + BT_SC_GN_SERVICE_MASK = 0x00010000, /**< GN service class */ + BT_SC_SAP_SERVICE_MASK = 0x00020000, /**< SAP service class */ + BT_SC_A2DP_SERVICE_MASK = 0x00040000, /**< A2DP service class */ + BT_SC_AVRCP_SERVICE_MASK = 0x00080000, /**< AVRCP service class */ + BT_SC_PBAP_SERVICE_MASK = 0x00100000, /**< PBAP service class */ + BT_SC_HID_SERVICE_MASK = 0x00200000, /**< HID service class */ + BT_SC_A2DP_SOURCE_SERVICE_MASK = 0x00400000, /**< A2DP SOURCE service class */ + BT_SC_ALL_SERVICE_MASK = 0x00FFFFFF, /**< ALL service class */ + BT_SC_MAX /**< MAX service class */ +} bt_service_class_t; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Enumerations of major service class. + * @since_tizen 2.3 + */ +typedef enum +{ + BT_MAJOR_SERVICE_CLASS_LIMITED_DISCOVERABLE_MODE = 0x002000, /**< Limited discoverable mode */ + BT_MAJOR_SERVICE_CLASS_POSITIONING = 0x010000, /**< Positioning class */ + BT_MAJOR_SERVICE_CLASS_NETWORKING = 0x020000, /**< Networking class */ + BT_MAJOR_SERVICE_CLASS_RENDERING = 0x040000, /**< Rendering class */ + BT_MAJOR_SERVICE_CLASS_CAPTURING = 0x080000, /**< Capturing class */ + BT_MAJOR_SERVICE_CLASS_OBJECT_TRANSFER = 0x100000, /**< Object transferring class */ + BT_MAJOR_SERVICE_CLASS_AUDIO = 0x200000, /**< Audio class*/ + BT_MAJOR_SERVICE_CLASS_TELEPHONY = 0x400000, /**< Telephony class */ + BT_MAJOR_SERVICE_CLASS_INFORMATION = 0x800000, /**< Information class */ +} bt_major_service_class_e; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Enumerations of major device class. + * @since_tizen 2.3 + */ +typedef enum +{ + BT_MAJOR_DEVICE_CLASS_MISC = 0x00, /**< Miscellaneous major device class*/ + BT_MAJOR_DEVICE_CLASS_COMPUTER = 0x01, /**< Computer major device class */ + BT_MAJOR_DEVICE_CLASS_PHONE = 0x02, /**< Phone major device class */ + BT_MAJOR_DEVICE_CLASS_LAN_NETWORK_ACCESS_POINT = 0x03, /**< LAN/Network access point major device class */ + BT_MAJOR_DEVICE_CLASS_AUDIO_VIDEO = 0x04, /**< Audio/Video major device class */ + BT_MAJOR_DEVICE_CLASS_PERIPHERAL = 0x05, /**< Peripheral major device class */ + BT_MAJOR_DEVICE_CLASS_IMAGING = 0x06, /**< Imaging major device class */ + BT_MAJOR_DEVICE_CLASS_WEARABLE = 0x07, /**< Wearable device class */ + BT_MAJOR_DEVICE_CLASS_TOY = 0x08, /**< Toy device class */ + BT_MAJOR_DEVICE_CLASS_HEALTH = 0x09, /**< Health device class */ + BT_MAJOR_DEVICE_CLASS_UNCATEGORIZED = 0x1F, /**< Uncategorized major device class */ +} bt_major_device_class_e; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Enumerations of minor device class. + * @since_tizen 2.3 + */ +typedef enum +{ + BT_MINOR_DEVICE_CLASS_COMPUTER_UNCATEGORIZED = 0x00, /**< Uncategorized minor device class of computer */ + BT_MINOR_DEVICE_CLASS_COMPUTER_DESKTOP_WORKSTATION = 0x04, /**< Desktop workstation minor device class of computer */ + BT_MINOR_DEVICE_CLASS_COMPUTER_SERVER_CLASS = 0x08, /**< Server minor device class of computer */ + BT_MINOR_DEVICE_CLASS_COMPUTER_LAPTOP = 0x0C, /**< Laptop minor device class of computer */ + BT_MINOR_DEVICE_CLASS_COMPUTER_HANDHELD_PC_OR_PDA = 0x10, /**< Handheld PC/PDA minor device class of computer */ + BT_MINOR_DEVICE_CLASS_COMPUTER_PALM_SIZED_PC_OR_PDA = 0x14, /**< Palm sized PC/PDA minor device class of computer */ + BT_MINOR_DEVICE_CLASS_COMPUTER_WEARABLE_COMPUTER = 0x18, /**< Wearable(watch sized) minor device class of computer */ + + BT_MINOR_DEVICE_CLASS_PHONE_UNCATEGORIZED = 0x00, /**< Uncategorized minor device class of phone */ + BT_MINOR_DEVICE_CLASS_PHONE_CELLULAR = 0x04, /**< Cellular minor device class of phone */ + BT_MINOR_DEVICE_CLASS_PHONE_CORDLESS = 0x08, /**< Cordless minor device class of phone */ + BT_MINOR_DEVICE_CLASS_PHONE_SMART_PHONE = 0x0C, /**< Smart phone minor device class of phone */ + BT_MINOR_DEVICE_CLASS_PHONE_WIRED_MODEM_OR_VOICE_GATEWAY = 0x10, /**< Wired modem or voice gateway minor device class of phone */ + BT_MINOR_DEVICE_CLASS_PHONE_COMMON_ISDN_ACCESS = 0x14, /**< Common ISDN minor device class of phone */ + + BT_MINOR_DEVICE_CLASS_LAN_NETWORK_ACCESS_POINT_FULLY_AVAILABLE = 0x04, /**< Fully available minor device class of LAN/Network access point */ + BT_MINOR_DEVICE_CLASS_LAN_NETWORK_ACCESS_POINT_1_TO_17_PERCENT_UTILIZED = 0x20, /**< 1-17% utilized minor device class of LAN/Network access point */ + BT_MINOR_DEVICE_CLASS_LAN_NETWORK_ACCESS_POINT_17_TO_33_PERCENT_UTILIZED = 0x40, /**< 17-33% utilized minor device class of LAN/Network access point */ + BT_MINOR_DEVICE_CLASS_LAN_NETWORK_ACCESS_POINT_33_TO_50_PERCENT_UTILIZED = 0x60, /**< 33-50% utilized minor device class of LAN/Network access point */ + BT_MINOR_DEVICE_CLASS_LAN_NETWORK_ACCESS_POINT_50_to_67_PERCENT_UTILIZED = 0x80, /**< 50-67% utilized minor device class of LAN/Network access point */ + BT_MINOR_DEVICE_CLASS_LAN_NETWORK_ACCESS_POINT_67_TO_83_PERCENT_UTILIZED = 0xA0, /**< 67-83% utilized minor device class of LAN/Network access point */ + BT_MINOR_DEVICE_CLASS_LAN_NETWORK_ACCESS_POINT_83_TO_99_PERCENT_UTILIZED = 0xC0, /**< 83-99% utilized minor device class of LAN/Network access point */ + BT_MINOR_DEVICE_CLASS_LAN_NETWORK_ACCESS_POINT_NO_SERVICE_AVAILABLE = 0xE0, /**< No service available minor device class of LAN/Network access point */ + + BT_MINOR_DEVICE_CLASS_AUDIO_VIDEO_UNCATEGORIZED = 0x00, /**< Uncategorized minor device class of audio/video */ + BT_MINOR_DEVICE_CLASS_AUDIO_VIDEO_WEARABLE_HEADSET = 0x04, /**< Wearable headset minor device class of audio/video */ + BT_MINOR_DEVICE_CLASS_AUDIO_VIDEO_HANDS_FREE = 0x08, /**< Hands-free minor device class of audio/video */ + BT_MINOR_DEVICE_CLASS_AUDIO_VIDEO_MICROPHONE = 0x10, /**< Microphone minor device class of audio/video */ + BT_MINOR_DEVICE_CLASS_AUDIO_VIDEO_LOUDSPEAKER = 0x14, /**< Loudspeaker minor device class of audio/video */ + BT_MINOR_DEVICE_CLASS_AUDIO_VIDEO_HEADPHONES = 0x18, /**< Headphones minor device class of audio/video */ + BT_MINOR_DEVICE_CLASS_AUDIO_VIDEO_PORTABLE_AUDIO = 0x1C, /**< Portable audio minor device class of audio/video */ + BT_MINOR_DEVICE_CLASS_AUDIO_VIDEO_CAR_AUDIO = 0x20, /**< Car audio minor device class of audio/video */ + BT_MINOR_DEVICE_CLASS_AUDIO_VIDEO_SET_TOP_BOX = 0x24, /**< Set-top box minor device class of audio/video */ + BT_MINOR_DEVICE_CLASS_AUDIO_VIDEO_HIFI_AUDIO_DEVICE = 0x28, /**< Hifi audio minor device class of audio/video */ + BT_MINOR_DEVICE_CLASS_AUDIO_VIDEO_VCR = 0x2C, /**< VCR minor device class of audio/video */ + BT_MINOR_DEVICE_CLASS_AUDIO_VIDEO_VIDEO_CAMERA = 0x30, /**< Video camera minor device class of audio/video */ + BT_MINOR_DEVICE_CLASS_AUDIO_VIDEO_CAMCORDER = 0x34, /**< Camcorder minor device class of audio/video */ + BT_MINOR_DEVICE_CLASS_AUDIO_VIDEO_VIDEO_MONITOR = 0x38, /**< Video monitor minor device class of audio/video */ + BT_MINOR_DEVICE_CLASS_AUDIO_VIDEO_VIDEO_DISPLAY_LOUDSPEAKER = 0x3C, /**< Video display and loudspeaker minor device class of audio/video */ + BT_MINOR_DEVICE_CLASS_AUDIO_VIDEO_VIDEO_CONFERENCING = 0x40, /**< Video conferencing minor device class of audio/video */ + BT_MINOR_DEVICE_CLASS_AUDIO_VIDEO_GAMING_TOY = 0x48, /**< Gaming/toy minor device class of audio/video */ + + BT_MINOR_DEVICE_CLASS_PERIPHERA_UNCATEGORIZED = 0x00, /**< Uncategorized minor device class of peripheral */ + BT_MINOR_DEVICE_CLASS_PERIPHERAL_KEY_BOARD = 0x40, /**< Key board minor device class of peripheral */ + BT_MINOR_DEVICE_CLASS_PERIPHERAL_POINTING_DEVICE = 0x80, /**< Pointing device minor device class of peripheral */ + BT_MINOR_DEVICE_CLASS_PERIPHERAL_COMBO_KEYBOARD_POINTING_DEVICE = 0xC0, /**< Combo keyboard or pointing device minor device class of peripheral */ + BT_MINOR_DEVICE_CLASS_PERIPHERAL_JOYSTICK = 0x04, /**< Joystick minor device class of peripheral */ + BT_MINOR_DEVICE_CLASS_PERIPHERAL_GAME_PAD = 0x08, /**< Game pad minor device class of peripheral */ + BT_MINOR_DEVICE_CLASS_PERIPHERAL_REMOTE_CONTROL = 0x0C, /**< Remote control minor device class of peripheral */ + BT_MINOR_DEVICE_CLASS_PERIPHERAL_SENSING_DEVICE = 0x10, /**< Sensing device minor device class of peripheral */ + BT_MINOR_DEVICE_CLASS_PERIPHERAL_DIGITIZER_TABLET = 0x14, /**< Digitizer minor device class of peripheral */ + BT_MINOR_DEVICE_CLASS_PERIPHERAL_CARD_READER = 0x18, /**< Card reader minor device class of peripheral */ + BT_MINOR_DEVICE_CLASS_PERIPHERAL_DIGITAL_PEN = 0x1C, /**< Digital pen minor device class of peripheral */ + BT_MINOR_DEVICE_CLASS_PERIPHERAL_HANDHELD_SCANNER = 0x20, /**< Handheld scanner minor device class of peripheral */ + BT_MINOR_DEVICE_CLASS_PERIPHERAL_HANDHELD_GESTURAL_INPUT_DEVICE = 0x24, /**< Handheld gestural input device minor device class of peripheral */ + + BT_MINOR_DEVICE_CLASS_IMAGING_DISPLAY = 0x10, /**< Display minor device class of imaging */ + BT_MINOR_DEVICE_CLASS_IMAGING_CAMERA = 0x20, /**< Camera minor device class of imaging */ + BT_MINOR_DEVICE_CLASS_IMAGING_SCANNER = 0x40, /**< Scanner minor device class of imaging */ + BT_MINOR_DEVICE_CLASS_IMAGING_PRINTER = 0x80, /**< Printer minor device class of imaging */ + + BT_MINOR_DEVICE_CLASS_WEARABLE_WRIST_WATCH = 0x04, /**< Wrist watch minor device class of wearable */ + BT_MINOR_DEVICE_CLASS_WEARABLE_PAGER = 0x08, /**< Pager minor device class of wearable */ + BT_MINOR_DEVICE_CLASS_WEARABLE_JACKET = 0x0C, /**< Jacket minor device class of wearable */ + BT_MINOR_DEVICE_CLASS_WEARABLE_HELMET = 0x10, /**< Helmet minor device class of wearable */ + BT_MINOR_DEVICE_CLASS_WEARABLE_GLASSES = 0x14, /**< Glasses minor device class of wearable */ + + BT_MINOR_DEVICE_CLASS_TOY_ROBOT = 0x04, /**< Robot minor device class of toy */ + BT_MINOR_DEVICE_CLASS_TOY_VEHICLE = 0x08, /**< Vehicle minor device class of toy */ + BT_MINOR_DEVICE_CLASS_TOY_DOLL_ACTION = 0x0C, /**< Doll/Action minor device class of toy */ + BT_MINOR_DEVICE_CLASS_TOY_CONTROLLER = 0x10, /**< Controller minor device class of toy */ + BT_MINOR_DEVICE_CLASS_TOY_GAME = 0x14, /**< Game minor device class of toy */ + + BT_MINOR_DEVICE_CLASS_HEALTH_UNCATEGORIZED = 0x00, /**< Uncategorized minor device class of health */ + BT_MINOR_DEVICE_CLASS_HEALTH_BLOOD_PRESSURE_MONITOR = 0x04, /**< Blood pressure monitor minor device class of health */ + BT_MINOR_DEVICE_CLASS_HEALTH_THERMOMETER = 0x08, /**< Thermometer minor device class of health */ + BT_MINOR_DEVICE_CLASS_HEALTH_WEIGHING_SCALE = 0x0C, /**< Weighing scale minor device class of health */ + BT_MINOR_DEVICE_CLASS_HEALTH_GLUCOSE_METER = 0x10, /**< Glucose minor device class of health */ + BT_MINOR_DEVICE_CLASS_HEALTH_PULSE_OXIMETER = 0x14, /**< Pulse oximeter minor device class of health */ + BT_MINOR_DEVICE_CLASS_HEALTH_HEART_PULSE_RATE_MONITOR = 0x18, /**< Heart/Pulse rate monitor minor device class of health */ + BT_MINOR_DEVICE_CLASS_HEALTH_DATA_DISPLAY = 0x1C, /**< Health data display minor device class of health */ + BT_MINOR_DEVICE_CLASS_HEALTH_STEP_COUNTER = 0x20, /**< Step counter minor device class of health */ + BT_MINOR_DEVICE_CLASS_HEALTH_BODY_COMPOSITION_ANALYZER = 0x24, /**< Body composition analyzer minor device class of health */ + BT_MINOR_DEVICE_CLASS_HEALTH_PEAK_FLOW_MONITOR = 0x28, /**< Peak flow monitor minor device class of health */ + BT_MINOR_DEVICE_CLASS_HEALTH_MEDICATION_MONITOR = 0x2C, /**< Medication monitor minor device class of health */ + BT_MINOR_DEVICE_CLASS_HEALTH_KNEE_PROSTHESIS = 0x30, /**< Knee prosthesis minor device class of health */ + BT_MINOR_DEVICE_CLASS_HEALTH_ANKLE_PROSTHESIS = 0x34, /**< Ankle prosthesis minor device class of health */ +} bt_minor_device_class_e; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Enumerations of gap appearance type. + * @since_tizen 2.3 + */ +typedef enum +{ + BT_APPEARANCE_TYPE_UNKNOWN = 0x00, /**< Unknown appearance type */ + BT_APPEARANCE_TYPE_GENERIC_PHONE = 0x40, /**< Generic Phone type - Generic category */ + BT_APPEARANCE_TYPE_GENERIC_COMPUTER = 0x80, /**< Generic Computer type - Generic category */ + BT_APPEARANCE_TYPE_GENERIC_WATCH = 0xC0, /**< Generic Watch type - Generic category */ +} bt_appearance_type_e; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE + * @brief Enumerations of connected Bluetooth device event role. + * @since_tizen 2.3 + */ +typedef enum +{ + BT_SOCKET_UNKNOWN = 0x00, /**< Unknown role*/ + BT_SOCKET_SERVER , /**< Server role*/ + BT_SOCKET_CLIENT, /**< Client role*/ +} bt_socket_role_e; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE + * @brief Enumerations of Bluetooth socket connection state. + * @since_tizen 2.3 + */ +typedef enum +{ + BT_SOCKET_CONNECTED, /**< RFCOMM is connected */ + BT_SOCKET_DISCONNECTED, /**< RFCOMM is disconnected */ +} bt_socket_connection_state_e; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_MODULE + * @brief Enumerations for the types of profiles related with audio + * @since_tizen 2.3 + */ +typedef enum { + BT_AUDIO_PROFILE_TYPE_ALL = 0, /**< All supported profiles related with audio */ + BT_AUDIO_PROFILE_TYPE_HSP_HFP, /**< HSP(Headset Profile) and HFP(Hands-Free Profile) */ + BT_AUDIO_PROFILE_TYPE_A2DP, /**< A2DP(Advanced Audio Distribution Profile) */ + BT_AUDIO_PROFILE_TYPE_AG, /**< AG(Audio Gateway) */ +} bt_audio_profile_type_e; + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Enumerations for the call handling event + * @since_tizen 2.3 + */ +typedef enum { + BT_AG_CALL_HANDLING_EVENT_ANSWER = 0x00, /**< Request to answer an incoming call */ + BT_AG_CALL_HANDLING_EVENT_RELEASE, /**< Request to release a call */ + BT_AG_CALL_HANDLING_EVENT_REJECT, /**< Request to reject an incoming call */ +} bt_ag_call_handling_event_e; + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Enumerations for the multi call handling event + * @since_tizen 2.3 + */ +typedef enum { + BT_AG_MULTI_CALL_HANDLING_EVENT_RELEASE_HELD_CALLS = 0x00, /**< Request to release held calls */ + BT_AG_MULTI_CALL_HANDLING_EVENT_RELEASE_ACTIVE_CALLS, /**< Request to release active calls */ + BT_AG_MULTI_CALL_HANDLING_EVENT_ACTIVATE_HELD_CALL, /**< Request to put active calls into hold state and activate another (held or waiting) call */ + BT_AG_MULTI_CALL_HANDLING_EVENT_MERGE_CALLS, /**< Request to add a held call to the conversation */ + BT_AG_MULTI_CALL_HANDLING_EVENT_EXPLICIT_CALL_TRANSFER, /**< Request to let a user who has two calls to connect these two calls together and release its connections to both other parties */ +} bt_ag_multi_call_handling_event_e; + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Enumerations for the call state + * @since_tizen 2.3 + */ +typedef enum { + BT_AG_CALL_EVENT_IDLE = 0x00, /**< Idle */ + BT_AG_CALL_EVENT_ANSWERED, /**< Answered */ + BT_AG_CALL_EVENT_HELD, /**< Held */ + BT_AG_CALL_EVENT_RETRIEVED, /**< Retrieved */ + BT_AG_CALL_EVENT_DIALING, /**< Dialing */ + BT_AG_CALL_EVENT_ALERTING, /**< Alerting */ + BT_AG_CALL_EVENT_INCOMING, /**< Incoming */ +} bt_ag_call_event_e; + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Enumerations for the call state + * @since_tizen 2.3 + */ +typedef enum { + BT_AG_CALL_STATE_IDLE = 0x00, /**< Idle state */ + BT_AG_CALL_STATE_ACTIVE, /**< Active state */ + BT_AG_CALL_STATE_HELD, /**< Held state */ + BT_AG_CALL_STATE_DIALING, /**< Dialing state */ + BT_AG_CALL_STATE_ALERTING, /**< Alerting state */ + BT_AG_CALL_STATE_INCOMING, /**< Incoming state */ + BT_AG_CALL_STATE_WAITING, /**< Waiting for connected indication event after answering an incoming call*/ +} bt_ag_call_state_e; + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief Enumerations for the equalizer state + * @since_tizen 2.3 + */ +typedef enum { + BT_AVRCP_EQUALIZER_STATE_OFF = 0x01, /**< Equalizer Off */ + BT_AVRCP_EQUALIZER_STATE_ON, /**< Equalizer On */ +} bt_avrcp_equalizer_state_e; + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief Enumerations for the repeat mode + * @since_tizen 2.3 + */ +typedef enum { + BT_AVRCP_REPEAT_MODE_OFF = 0x01, /**< Repeat Off */ + BT_AVRCP_REPEAT_MODE_SINGLE_TRACK, /**< Single track repeat */ + BT_AVRCP_REPEAT_MODE_ALL_TRACK, /**< All track repeat */ + BT_AVRCP_REPEAT_MODE_GROUP, /**< Group repeat */ +} bt_avrcp_repeat_mode_e; + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief Enumerations for the shuffle mode + * @since_tizen 2.3 + */ +typedef enum { + BT_AVRCP_SHUFFLE_MODE_OFF = 0x01, /**< Shuffle Off */ + BT_AVRCP_SHUFFLE_MODE_ALL_TRACK, /**< All tracks shuffle */ + BT_AVRCP_SHUFFLE_MODE_GROUP, /**< Group shuffle */ +} bt_avrcp_shuffle_mode_e; + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief Enumerations for the scan mode + * @since_tizen 2.3 + */ +typedef enum { + BT_AVRCP_SCAN_MODE_OFF = 0x01, /**< Scan Off */ + BT_AVRCP_SCAN_MODE_ALL_TRACK, /**< All tracks scan */ + BT_AVRCP_SCAN_MODE_GROUP, /**< Group scan */ +} bt_avrcp_scan_mode_e; + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief Enumerations for the player state + * @since_tizen 2.3 + */ +typedef enum { + BT_AVRCP_PLAYER_STATE_STOPPED = 0x00, /**< Stopped */ + BT_AVRCP_PLAYER_STATE_PLAYING, /**< Playing */ + BT_AVRCP_PLAYER_STATE_PAUSED, /**< Paused */ + BT_AVRCP_PLAYER_STATE_FORWARD_SEEK, /**< Seek Forward */ + BT_AVRCP_PLAYER_STATE_REWIND_SEEK, /**< Seek Rewind */ +} bt_avrcp_player_state_e; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_HDP_MODULE + * @brief Enumerations for the data channel type + * @since_tizen 2.3 + */ +typedef enum { + BT_HDP_CHANNEL_TYPE_RELIABLE = 0x01, /**< Reliable Data Channel */ + BT_HDP_CHANNEL_TYPE_STREAMING, /**< Streaming Data Channel */ +} bt_hdp_channel_type_e; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Enumerations of the integer type for GATT handle's value + * @since_tizen 2.3.1 + */ +typedef enum { + BT_DATA_TYPE_SINT8, /**< 8 bit signed int type */ + BT_DATA_TYPE_SINT16, /**< 16 bit signed int type */ + BT_DATA_TYPE_SINT32, /**< 32 bit signed int type */ + BT_DATA_TYPE_UINT8, /**< 8 bit unsigned int type */ + BT_DATA_TYPE_UINT16, /**< 16 bit unsigned int type */ + BT_DATA_TYPE_UINT32 /**< 32 bit unsigned int type */ +} bt_data_type_int_e; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Enumerations of the float type for GATT handle's value + * @since_tizen 2.3.1 + */ +typedef enum { + BT_DATA_TYPE_FLOAT, /**< 32 bit float type */ + BT_DATA_TYPE_SFLOAT /**< 16 bit float type */ +} bt_data_type_float_e; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Enumerations of the write type + * @since_tizen 2.3.1 + */ +typedef enum { + BT_GATT_WRITE_TYPE_WRITE_NO_RESPONSE, /**< Write without response type */ + BT_GATT_WRITE_TYPE_WRITE /**< Write type */ +} bt_gatt_write_type_e; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Enumerations of the GATT handle's type + * @since_tizen 2.3.1 + */ +typedef enum { + BT_GATT_TYPE_SERVICE = 0x01, /**< GATT service type */ + BT_GATT_TYPE_CHARACTERISTIC = 0x02, /** GATT characteristic type */ + BT_GATT_TYPE_DESCRIPTOR = 0x03, /** GATT descriptor type */ +} bt_gatt_type_e; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Enumerations of the service type + * @since_tizen 2.3.1 + */ +typedef enum { + BT_GATT_SERVICE_TYPE_PRIMARY = 0x01, /**< GATT primary service type */ + BT_GATT_SERVICE_TYPE_SECONDARY = 0x02, /**< GATT secondary service type */ +} bt_gatt_service_type_e; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Enumerations of the characteristic's property + * @since_tizen 2.3.1 + */ +typedef enum { + BT_GATT_PROPERTY_BROADCAST = 0x01, /**< Broadcast property */ + BT_GATT_PROPERTY_READ = 0x02, /**< Read property */ + BT_GATT_PROPERTY_WRITE_WITHOUT_RESPONSE = 0x04, /**< Write without response property */ + BT_GATT_PROPERTY_WRITE = 0x08, /**< Write property */ + BT_GATT_PROPERTY_NOTIFY = 0x10, /**< Notify property */ + BT_GATT_PROPERTY_INDICATE = 0x20, /**< Indicate property */ + BT_GATT_PROPERTY_AUTHENTICATED_SIGNED_WRITES = 0x40, /**< Authenticated signed writes property */ + BT_GATT_PROPERTY_EXTENDED_PROPERTIES = 0x80, /**< Extended properties */ +} bt_gatt_property_e; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_PAN_PANU_MODULE + * @brief Enumerations for the types of PAN(Personal Area Networking) service + * @since_tizen 2.3 + */ +typedef enum { + BT_PANU_SERVICE_TYPE_NAP = 0, /**< Network Access Point */ +} bt_panu_service_type_e; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief The handle to control Bluetooth LE advertising + * @since_tizen 2.3 + */ +typedef void* bt_advertiser_h; + +/** + * @deprecated Deprecated since 2.3.1. Use bt_gatt_h instead. + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief The attribute handle of GATT(Generic Attribute Profile) + * @since_tizen 2.3 + */ +typedef void* bt_gatt_attribute_h; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief The handle of a service, characteristic or descriptor + * @since_tizen 2.3.1 + */ +typedef void* bt_gatt_h; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief The handle of a GATT client which is associated with a remote device + * @since_tizen 2.3.1 + */ +typedef void* bt_gatt_client_h; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief The handle of calls state + * @since_tizen 2.3 + */ +typedef void* bt_call_list_h; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Class structure of device and service. + * @since_tizen 2.3 + * + * @see #bt_device_info_s + * @see #bt_adapter_device_discovery_info_s + * @see bt_device_bond_created_cb() + * @see bt_adapter_device_discovery_state_changed_cb() + */ +typedef struct +{ + bt_major_device_class_e major_device_class; /**< Major device class. */ + bt_minor_device_class_e minor_device_class; /**< Minor device class. */ + int major_service_class_mask; /**< Major service class mask. + This value can be a combination of #bt_major_service_class_e like #BT_MAJOR_SERVICE_CLASS_RENDERING | #BT_MAJOR_SERVICE_CLASS_AUDIO */ +} bt_class_s; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Structure of device discovery information. + * @since_tizen 2.3 + * + * @see #bt_class_s + * @see bt_adapter_device_discovery_state_changed_cb() + */ +typedef struct +{ + char *remote_address; /**< The address of remote device */ + char *remote_name; /**< The name of remote device */ + bt_class_s bt_class; /**< The Bluetooth classes */ + int rssi; /**< The strength indicator of received signal */ + bool is_bonded; /**< The bonding state */ + char **service_uuid; /**< The UUID list of service */ + int service_count; /**< The number of services */ + bt_appearance_type_e appearance; /**< The Bluetooth appearance */ + int manufacturer_data_len; /**< manufacturer specific data length */ + char *manufacturer_data; /**< manufacturer specific data */ +} bt_adapter_device_discovery_info_s; + +/** + * @deprecated Deprecated since 2.3.1 + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Structure of le device discovery information. + * @since_tizen 2.3 + * + * @see #bt_class_s + * @see bt_adapter_le_device_discovery_state_changed_cb() + */ +typedef struct +{ + char *remote_address; /**< The address of remote device */ + int address_type; /**< The address type of remote device */ + int rssi; /**< The strength indicator of received signal */ + int adv_data_len; /**< advertising indication data length */ + char *adv_data; /**< advertising indication data */ + int scan_data_len; /**< scan response data length */ + char *scan_data; /**< scan response data */ +} bt_adapter_le_device_discovery_info_s; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Structure of le scan result information. + * @since_tizen 2.3.1 + * + * @see bt_adapter_le_start_scan() + */ +typedef struct +{ + char *remote_address; /**< The address of remote device */ + bt_device_address_type_e address_type; /**< The address type of remote device */ + int rssi; /**< The strength indicator of received signal */ + int adv_data_len; /**< advertising indication data length */ + char *adv_data; /**< advertising indication data */ + int scan_data_len; /**< scan response data length */ + char *scan_data; /**< scan response data */ +} bt_adapter_le_device_scan_result_info_s; + +/** + * @deprecated Deprecated since 2.3.1 + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Structure of advertising parameters + * @since_tizen 2.3 + * + * @see bt_adapter_le_advertising_state_changed_cb() + * @see bt_adapter_le_start_advertising() + */ +typedef struct { + float interval_min; /**< Minimum advertising interval for non-directed advertising. + A multiple of 0.625ms is only allowed (Time range : 20ms to 10.24sec). */ + float interval_max; /**< Maximum advertising interval for non-directed advertising. + A multiple of 0.625ms is only allowed (Time range : 20ms to 10.24sec). */ + char filter_policy; /* Advertising filter policy */ + char type; /* Advertising type */ +} bt_adapter_le_advertising_params_s; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief LE service data structure + * @since_tizen 2.3.1 + * + * @see bt_adapter_le_get_scan_result_service_data() + */ +typedef struct +{ + char *service_uuid; /**< 16 bit UUID of the service data */ + char *service_data; /**< Service data */ + int service_data_len; /**< Service data length */ +} bt_adapter_le_service_data_s; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Device information structure used for identifying pear device. + * @since_tizen 2.3 + * + * @see #bt_class_s + * @see bt_device_bond_created_cb() + */ +typedef struct +{ + char *remote_address; /**< The address of remote device */ + char *remote_name; /**< The name of remote device */ + bt_class_s bt_class; /**< The Bluetooth classes */ + char **service_uuid; /**< The UUID list of service */ + int service_count; /**< The number of services */ + bool is_bonded; /**< The bonding state */ + bool is_connected; /**< The connection state */ + bool is_authorized; /**< The authorization state */ + int manufacturer_data_len; /**< manufacturer specific data length */ + char *manufacturer_data; /**< manufacturer specific data */ +} bt_device_info_s; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Service Discovery Protocol (SDP) data structure. + * @since_tizen 2.3 + * + * @details This protocol is used for discovering available services or pear device, + * and finding one to connect with. + * + * @see bt_device_service_searched_cb() + */ +typedef struct +{ + char *remote_address; /**< The address of remote device */ + char **service_uuid; /**< The UUID list of service */ + int service_count; /**< The number of services. */ +} bt_device_sdp_info_s; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Device connection information structure. + * @since_tizen 2.3 + * + * @see bt_device_connection_state_changed_cb() + */ +typedef struct +{ + char *remote_address; /**< The address of remote device */ + bt_device_connection_link_type_e link; /**< Link type */ + bt_device_disconnect_reason_e disconn_reason; /**< Disconnection reason */ +} bt_device_connection_info_s; + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Device LE connection update structure. + * @since_tizen 2.3 + * + * @see bt_device_le_conn_update() + */ +typedef struct +{ + unsigned int interval_min; /**< Minimum value for the connection event interval (msec) */ + unsigned int interval_max; /**< Maximum value for the connection event interval (msec) */ + unsigned int latency; /**< Slave latency (msec) */ + unsigned int time_out; /**< Supervision timeout (msec) */ +} bt_le_conn_update_s; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE + * @brief Rfcomm connection data used for exchanging data between Bluetooth devices. + * @since_tizen 2.3 + * + * @see bt_socket_connection_state_changed_cb() + */ +typedef struct +{ + int socket_fd; /**< The file descriptor of connected socket */ + int server_fd; /**< The file descriptor of the server socket or -1 for client connection */ + bt_socket_role_e local_role; /**< The local device role in this connection */ + char *remote_address; /**< The remote device address */ + char *service_uuid; /**< The service UUId */ +} bt_socket_connection_s; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE + * @brief Structure of RFCOMM received data. + * @since_tizen 2.3 + * + * @remarks User can use standard linux functions for reading/writing + * data from/to sockets. + * + * @see bt_socket_data_received_cb() + */ +typedef struct +{ + int socket_fd; /**< The socket fd */ + int data_size; /**< The length of the received data */ + char *data; /**< The received data */ +} bt_socket_received_data_s; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Called when the Bluetooth adapter state changes. + * @since_tizen 2.3 + * + * @param[in] result The result of the adapter state changing + * @param[in] adapter_state The adapter state to be changed + * @param[in] user_data The user data passed from the callback registration function + * @see bt_adapter_set_state_changed_cb() + * @see bt_adapter_unset_state_changed_cb() + */ +typedef void (*bt_adapter_state_changed_cb)(int result, bt_adapter_state_e adapter_state, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Called when adapter name changes. + * @since_tizen 2.3 + * + * @param[in] device_name The name of the Bluetooth device to be changed + * @param[in] user_data The user data passed from the callback registration function + * @pre This function will be invoked when the name of Bluetooth adapter changes + * if you register this callback using bt_adapter_set_name_changed_cb(). + * @see bt_adapter_set_name() + * @see bt_adapter_set_name_changed_cb() + * @see bt_adapter_unset_name_changed_cb() + */ +typedef void (*bt_adapter_name_changed_cb)(char *device_name, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Called when the visibility mode changes. + * @since_tizen 2.3 + * + * @param[in] result The result of the visibility mode changing + * @param[in] visibility_mode The visibility mode to be changed + * @param[in] user_data The user data passed from the callback registration function + * + * @pre This function will be invoked when the visibility of Bluetooth adapter changes + * if you register this callback using bt_adapter_set_visibility_mode_changed_cb(). + * + * @see bt_adapter_set_visibility_mode_changed_cb() + * @see bt_adapter_unset_visibility_mode_changed_cb() + */ +typedef void (*bt_adapter_visibility_mode_changed_cb) + (int result, bt_adapter_visibility_mode_e visibility_mode, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Called every second until the visibility mode is changed to #BT_ADAPTER_VISIBILITY_MODE_NON_DISCOVERABLE. + * @since_tizen 2.3 + * + * @remarks This callback function is called only if visibility mode is #BT_ADAPTER_VISIBILITY_MODE_LIMITED_DISCOVERABLE. + * @param[in] duration The duration until the visibility mode is changed to #BT_ADAPTER_VISIBILITY_MODE_NON_DISCOVERABLE (in seconds) + * @param[in] user_data The user data passed from the callback registration function + * @pre This function will be invoked if you register this callback using bt_adapter_set_visibility_duration_changed_cb(). + * @see bt_adapter_set_visibility_duration_changed_cb() + * @see bt_adapter_unset_visibility_duration_changed_cb() + */ +typedef void (*bt_adapter_visibility_duration_changed_cb)(int duration, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Called when the state of device discovery changes. + * @since_tizen 2.3 + * + * @remarks If \a discovery_state is #BT_ADAPTER_DEVICE_DISCOVERY_FOUND, + * then you can get some information, such as remote device address, remote device name, rssi, and bonding state. + * + * @param[in] result The result of the device discovery + * @param[in] discovery_state The discovery state to be changed + * @param[in] discovery_info The information of the discovered device \n + * If \a discovery_state is #BT_ADAPTER_DEVICE_DISCOVERY_STARTED or + * #BT_ADAPTER_DEVICE_DISCOVERY_FINISHED, then \a discovery_info is NULL. + * @param[in] user_data The user data passed from the callback registration function + * + * @pre Either bt_adapter_start_device_discovery() or bt_adapter_stop_device_discovery() will invoke this function + * if you register this callback using bt_adapter_set_device_discovery_state_changed_cb(). + * + * @see bt_adapter_start_device_discovery() + * @see bt_adapter_stop_device_discovery() + * @see bt_adapter_set_device_discovery_state_changed_cb() + * @see bt_adapter_unset_device_discovery_state_changed_cb() + * + */ +typedef void (*bt_adapter_device_discovery_state_changed_cb) + (int result, bt_adapter_device_discovery_state_e discovery_state, bt_adapter_device_discovery_info_s *discovery_info, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Called when you get bonded devices repeatedly. + * @since_tizen 2.3 + * + * @param[in] device_info The bonded device information + * @param[in] user_data The user data passed from the foreach function + * @return @c true to continue with the next iteration of the loop, + * \n @c false to break out of the loop. + * @pre bt_adapter_foreach_bonded_device() will invoke this function. + * + * @see bt_adapter_foreach_bonded_device() + * + */ +typedef bool (*bt_adapter_bonded_device_cb)(bt_device_info_s *device_info, void *user_data); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Called when the connectable state changes. + * @since_tizen 2.3 + * + * @param[in] result The result of the connectable state changing + * @param[in] connectable The connectable to be changed + * @param[in] user_data The user data passed from the callback registration function + * + * @pre This function will be invoked when the connectable state of local Bluetooth adapter changes + * if you register this callback using bt_adapter_set_connectable_changed_cb(). + * + * @see bt_adapter_set_connectable() + * @see bt_adapter_set_connectable_changed_cb() + * @see bt_adapter_unset_connectable_changed_cb() + */ +typedef void (*bt_adapter_connectable_changed_cb) + (int result, bool connectable, void *user_data); + +/** + * @deprecated Deprecated since 2.3.1 + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Called when the state of LE device discovery changes. + * @since_tizen 2.3 + * + * @remarks If \a discovery_state is #BT_ADAPTER_LE_DEVICE_DISCOVERY_FOUND, + * then you can get some information, such as remote LE device address, remote device name, rssi, and bonding state. + * + * @param[in] result The result of the LE device discovery + * @param[in] discovery_state The discovery state to be changed + * @param[in] discovery_info The information of the discovered LE device \n + * If \a discovery_state is #BT_ADAPTER_LE_DEVICE_DISCOVERY_STARTED or + * #BT_ADAPTER_LE_DEVICE_DISCOVERY_FINISHED, then \a discovery_info is NULL. + * @param[in] user_data The user data passed from the callback registration function + * + * @pre Either bt_adapter_start_device_discovery() or bt_adapter_stop_device_discovery() will invoke this function + * if you register this callback using bt_adapter_set_device_discovery_state_changed_cb(). + * + * @see bt_adapter_le_start_device_discovery() + * @see bt_adapter_le_stop_device_discovery() + * @see bt_adapter_le_set_device_discovery_state_changed_cb() + * @see bt_adapter_le_unset_device_discovery_state_changed_cb() + * + */ +typedef void (*bt_adapter_le_device_discovery_state_changed_cb) + (int result, bt_adapter_le_device_discovery_state_e discovery_state, bt_adapter_le_device_discovery_info_s *discovery_info, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Called when the LE advertisement has been found. + * @since_tizen 2.3.1 + * + * @param[in] result The result of the LE scan + * @param[in] info The information of the found LE advertisement. + * @param[in] user_data The user data passed from the start function + * + * @see bt_adapter_le_start_scan() + * + */ +typedef void (*bt_adapter_le_scan_result_cb)(int result, + bt_adapter_le_device_scan_result_info_s *info, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Called when the state of advertiser changes. + * @since_tizen 2.3 + * + * @param[out] result The result of the requested state change of advertiser + * @param[out] advertiser The handle of the state changed advertiser + * @param[out] adv_state The advertiser state to be changed + * @param[out] user_data The user data passed from the start function + * + * @see bt_adapter_le_start_advertising_new() + * @see bt_adapter_le_stop_advertising() + */ +typedef void (*bt_adapter_le_advertising_state_changed_cb)(int result, + bt_advertiser_h advertiser, bt_adapter_le_advertising_state_e adv_state, void *user_data); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Called when the Bluetooth adapter le state changes. + * @since_tizen 2.3 + * + * @param[in] result The result of the adapter state changing + * @param[in] adapter_le_state The adapter le state to be changed + * @param[in] user_data The user data passed from the callback registration function + * @pre Either bt_adapter_le_enable() or bt_adapter_le_disable() will invoke this callback if you register this callback using bt_adapter_le_set_state_changed_cb(). + * @see bt_adapter_le_enable() + * @see bt_adapter_le_disable() + * @see bt_adapter_le_set_state_changed_cb() + * @see bt_adapter_le_unset_state_changed_cb() + */ +typedef void (*bt_adapter_le_state_changed_cb)(int result, bt_adapter_le_state_e adapter_le_state, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Called when the process of creating bond finishes. + * @since_tizen 2.3 + * + * @remarks If the remote user does not respond within 60 seconds, a time out will happen with #BT_ERROR_TIMED_OUT result code.\n + * If bt_device_cancel_bonding() is called and it returns #BT_ERROR_NONE, then this callback function will be called + * with #BT_ERROR_CANCELLED result. \n + * If creating a bond succeeds but service search fails, then this callback will be called with #BT_ERROR_SERVICE_SEARCH_FAILED. + * In this case, you should try service search again by bt_device_start_service_search() to get the supported service list. + * + * @param[in] result The result of the bonding device + * @param[in] device_info The device information which you creates bond with + * @param[in] user_data The user data passed from the callback registration function + * + * @pre Either bt_device_create_bond() will invoke this function + * if you register this callback using bt_device_set_bond_created_cb(). + * + * @see bt_device_create_bond() + * @see bt_device_cancel_bonding() + * @see bt_device_set_bond_created_cb() + * @see bt_device_unset_bond_created_cb() + */ +typedef void (*bt_device_bond_created_cb)(int result, bt_device_info_s *device_info, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Called when you get connected profiles repeatedly. + * @since_tizen 2.3 + * + * @param[in] profile The connected Bluetooth profile + * @param[in] user_data The user data passed from the foreach function + * @return @c true to continue with the next iteration of the loop, + * \n @c false to break out of the loop. + * @pre bt_device_foreach_connected_profiles() will invoke this function. + * @see bt_device_foreach_connected_profiles() + */ +typedef bool (*bt_device_connected_profile)(bt_profile_e profile, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Called when the bond destroys. + * @since_tizen 2.3 + * + * @param[in] result The result that a bond is destroyed + * @param[in] remote_address The address of the remote Bluetooth device to destroy bond with + * @param[in] user_data The user data passed from the callback registration function + * @pre bt_device_destroy_bond() will invoke this function + * if you register this callback using bt_device_set_bond_destroyed_cb(). + * + * @see bt_device_destroy_bond() + * @see bt_device_set_bond_destroyed_cb() + * @see bt_device_unset_bond_destroyed_cb() + */ +typedef void (*bt_device_bond_destroyed_cb)(int result, char *remote_address, void *user_data); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Called when the authorization of device changes. + * @since_tizen 2.3 + * + * @param[in] authorization The authorization of device + * @param[in] remote_address The address of the remote Bluetooth device which is (un)authorized + * @param[in] user_data The user data passed from the callback registration function + * @pre bt_device_set_authorization() will invoke this function if you register this callback using bt_device_set_authorization_changed_cb(). + * + * @see bt_device_set_authorization() + * @see #bt_device_set_authorization_changed_cb() + * @see #bt_device_unset_authorization_changed_cb() + */ +typedef void (*bt_device_authorization_changed_cb) + (bt_device_authorization_e authorization, char *remote_address, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Called when the process of service search finishes. + * @since_tizen 2.3 + * + * @remark + * + * @param[in] result The result of the service searching + * @param[in] sdp_info The structure of service lists found on a device + * @param[in] user_data The user data passed from the callback registration function + * @pre Either bt_device_start_service_search() will invoke this function + * if you register this callback using bt_device_set_service_searched_cb(). + * + * @see bt_device_start_service_search() + * @see bt_device_set_service_searched_cb() + * @see bt_device_unset_service_searched_cb() + * + */ +typedef void (*bt_device_service_searched_cb)(int result, bt_device_sdp_info_s *sdp_info, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Called when the connection state is changed. + * @since_tizen 2.3 + * + * @param[in] connected The connection status: (@c true = connected, @c false = disconnected) + * @param[in] conn_info The connection information + * @param[in] user_data The user data passed from the callback registration function + * @see bt_device_set_connection_state_changed_cb() + * @see bt_device_unset_connection_state_changed_cb() + */ +typedef void (*bt_device_connection_state_changed_cb)(bool connected, bt_device_connection_info_s *conn_info, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE + * @brief Called when you receive data. + * @since_tizen 2.3 + * + * @param[in] data The received data from the remote device + * @param[in] user_data The user data passed from the callback registration function + * + * @pre When the connected remote Bluetooth device invokes bt_socket_send_data(), + * this function will be invoked if you register this function using bt_socket_set_data_received_cb(). + * + * @see bt_socket_set_data_received_cb() + * @see bt_socket_unset_data_received_cb() + * @see bt_socket_send_data() + */ +typedef void (*bt_socket_data_received_cb)(bt_socket_received_data_s *data, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE + * @brief Called when the socket connection state changes. + * @since_tizen 2.3 + * + * @param[in] result The result of connection state changing + * @param[in] connection_state The connection state + * @param[in] connection The connection information which is established or disconnected + * @param[in] user_data The user data passed from the callback registration function + * @pre Either bt_socket_connect_rfcomm() will invoke this function. + * In addtion, bt_socket_connection_state_changed_cb() will be invoked when the socket connection state is changed. + * @see bt_socket_listen_and_accept_rfcomm() + * @see bt_socket_connect_rfcomm() + * @see bt_socket_set_connection_state_changed_cb() + * @see bt_socket_unset_connection_state_changed_cb() + */ +typedef void (*bt_socket_connection_state_changed_cb) + (int result, bt_socket_connection_state_e connection_state, bt_socket_connection_s *connection, void *user_data); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE + * @brief Called when a RFCOMM connection is requested. + * @since_tizen 2.3 + * + * @details You must call bt_socket_accept() if you want to accept. Otherwise, you must call bt_socket_reject(). + * @param[in] socket_fd The file descriptor of socket on which a connection is requested + * @param[in] remote_address The address of remote device + * @param[in] user_data The user data passed from the callback registration function + * @pre If you register this callback function by bt_socket_set_connection_requested_cb() and listen a socket by bt_socket_listen(), + * bt_socket_connection_requested_cb() will be invoked. + * @see bt_socket_listen() + * @see bt_socket_accept() + * @see bt_socket_reject() + */ +typedef void (*bt_socket_connection_requested_cb) (int socket_fd, const char *remote_address, void *user_data); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_OPP_SERVER_MODULE + * @brief Called when the push is requested. + * @since_tizen 2.3 + * + * @details You must call bt_opp_server_accept() if you want to accept. + * Otherwise, you must call bt_opp_server_reject(). + * @param[in] file The path of file to be pushed + * @param[in] size The file size (bytes) + * @param[in] user_data The user data passed from the callback registration function + * @see bt_opp_server_initialize() + */ +typedef void (*bt_opp_server_push_requested_cb)(const char *file, int size, void *user_data); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_OPP_SERVER_MODULE + * @brief Called when an OPP connection is requested. + * @since_tizen 2.3 + * + * @details You must call bt_opp_server_accept_connection() if you want to accept. + * Otherwise, you must call bt_opp_server_reject_connection(). + * @param[in] remote_address The address of remote device + * @param[in] user_data The user data passed from the callback registration function + * @see bt_opp_server_accept() + * @see bt_opp_server_reject() + */ +typedef void (*bt_opp_server_connection_requested_cb)(const char *remote_address, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_OPP_SERVER_MODULE + * @brief Called when a file is being transfered. + * @since_tizen 2.3 + * + * @param[in] file The path of file to be pushed + * @param[in] size The file size (bytes) + * @param[in] percent The progress in percentage (1 ~ 100) + * @param[in] user_data The user data passed from the callback registration function + * @see bt_opp_server_accept() + * @see bt_opp_server_accept_connection() + */ +typedef void (*bt_opp_server_transfer_progress_cb) (const char *file, long long size, int percent, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_OPP_SERVER_MODULE + * @brief Called when a transfer is finished. + * @since_tizen 2.3 + * + * @param[in] error_code The result of push + * @param[in] file The path of file to be pushed + * @param[in] size The file size (bytes) + * @param[in] user_data The user data passed from the callback registration function + * @see bt_opp_server_accept() + * @see bt_opp_server_accept_connection() + */ +typedef void (*bt_opp_server_transfer_finished_cb) (int result, const char *file, long long size, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_OPP_CLIENT_MODULE + * @brief Called when OPP server responds to the push request. + * @since_tizen 2.3 + * + * @param[in] result The result of OPP server response + * @param[in] remote_address The remote address + * @param[in] user_data The user data passed from the callback registration function + * @pre bt_opp_client_push_files() will invoke this function. + * @see bt_opp_client_push_files() + */ +typedef void (*bt_opp_client_push_responded_cb)(int result, const char *remote_address, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_OPP_CLIENT_MODULE + * @brief Called when each file is being transfered. + * @since_tizen 2.3 + * + * @param[in] file The path of file to be pushed + * @param[in] size The file size (bytes) + * @param[in] percent The progress in percentage (1 ~ 100). 100 means that a file is transfered completely. + * @param[in] user_data The user data passed from the callback registration function + * @pre bt_opp_client_push_files() will invoke this function. + * @see bt_opp_client_push_files() + */ +typedef void (*bt_opp_client_push_progress_cb)(const char *file, long long size, int percent, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_OPP_CLIENT_MODULE + * @brief Called when the push request is finished. + * @since_tizen 2.3 + * + * @param[in] result The result of the push request + * @param[in] remote_address The remote address + * @param[in] user_data The user data passed from the callback registration function + * @see bt_opp_client_push_files() + */ +typedef void (*bt_opp_client_push_finished_cb)(int result, const char *remote_address, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_MODULE + * @brief Called when the connection state is changed. + * @since_tizen 2.3 + * + * @details This callback is called when the connection state is changed. + * When you call bt_audio_connect() or bt_audio_disconnect(), this callback is also called with error result even though these functions fail. + * @param[in] result The result of changing the connection state + * @param[in] connected The state to be changed. @a true means connected state, Otherwise, @a false. + * @param[in] remote_address The remote address + * @param[in] type The type of audio profile except #BT_AUDIO_PROFILE_TYPE_ALL + * @param[in] user_data The user data passed from the callback registration function + * @see bt_audio_set_connection_state_changed_cb() + * @see bt_audio_unset_connection_state_changed_cb() + */ +typedef void (*bt_audio_connection_state_changed_cb) (int result, bool connected, const char *remote_address, bt_audio_profile_type_e type, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Called when the SCO(Synchronous Connection Oriented link) state is changed. + * @since_tizen 2.3 + * + * @details This callback is called when the SCO state is changed. + * When you call bt_ag_open_sco() or bt_ag_close_sco(), this callback is also called with error result even though these functions failed. + * @param[in] result The result of changing the connection state + * @param[in] opened The state to be changed: (@c true = opened, @c false = not opened) + * @param[in] user_data The user data passed from the callback registration function + * @see bt_ag_set_sco_state_changed_cb() + * @see bt_ag_unset_sco_state_changed_cb() + * @see bt_ag_open_sco() + * @see bt_ag_close_sco() + */ +typedef void (*bt_ag_sco_state_changed_cb) (int result, bool opened, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Called when a call handling event happened from Hands-Free. + * @since_tizen 2.3 + * + * @param[in] event The call handling event happened from Hands-Free + * @param[in] call_id The call ID + * @param[in] user_data The user data passed from the callback registration function + * @see bt_ag_set_call_handling_event_cb() + * @see bt_ag_unset_call_handling_event_cb() + */ +typedef void (*bt_ag_call_handling_event_cb) (bt_ag_call_handling_event_e event, unsigned int call_id, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Called when a multi call handling event happened from Hands-Free. + * @since_tizen 2.3 + * + * @param[in] event The call handling event happened from Hands-Free + * @param[in] user_data The user data passed from the callback registration function + * @see bt_ag_set_multi_call_handling_event_cb() + * @see bt_ag_unset_multi_call_handling_event_cb() + */ +typedef void (*bt_ag_multi_call_handling_event_cb) (bt_ag_multi_call_handling_event_e event, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Called when a DTMF(Dual Tone Multi Frequency) is transmitted from Hands-Free. + * @since_tizen 2.3 + * + * @param[in] dtmf The DTMF transmitted from Hands-Free + * @param[in] user_data The user data passed from the callback registration function + * @see bt_ag_set_dtmf_transmitted_cb() + * @see bt_ag_unset_dtmf_transmitted_cb() + */ +typedef void (*bt_ag_dtmf_transmitted_cb) (const char *dtmf, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Called when the speaker gain of the remote device is changed. + * @since_tizen 2.3 + * + * @param[in] gain The gain of speaker (0 ~ 15) + * @param[in] user_data The user data passed from the callback registration function + * @see bt_ag_set_speaker_gain_changed_cb() + * @see bt_ag_unset_speaker_gain_changed_cb() + */ +typedef void (*bt_ag_speaker_gain_changed_cb) (int gain, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Called when the microphone gain of the remote device is changed. + * @since_tizen 2.3 + * + * @param[in] gain The gain of microphone (0 ~ 15) + * @param[in] user_data The user data passed from the callback registration function + * @see bt_ag_set_microphone_gain_changed_cb() + * @see bt_ag_unset_microphone_gain_changed_cb() + */ +typedef void (*bt_ag_microphone_gain_changed_cb) (int gain, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief Called when the connection state is changed. + * @since_tizen 2.3 + * + * @param[in] connected The state to be changed. @a true means connected state, Otherwise, @a false. + * @param[in] remote_address The remote address + * @param[in] user_data The user data passed from the callback registration function + * @see bt_avrcp_target_initialize() + * @see bt_avrcp_target_deinitialize() + */ +typedef void (*bt_avrcp_target_connection_state_changed_cb) (bool connected, const char *remote_address, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief Called when the equalizer state is changed by the remote control device. + * @since_tizen 2.3 + * + * @param[in] equalizer The equalizer state + * @param[in] user_data The user data passed from the callback registration function + * @see bt_avrcp_set_equalizer_state_changed_cb() + * @see bt_avrcp_unset_equalizer_state_changed_cb() + */ +typedef void (*bt_avrcp_equalizer_state_changed_cb) (bt_avrcp_equalizer_state_e equalizer, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief Called when the repeat mode is changed by the remote control device. + * @since_tizen 2.3 + * + * @param[in] repeat The repeat mode + * @param[in] user_data The user data passed from the callback registration function + * @see bt_avrcp_set_repeat_mode_changed_cb() + * @see bt_avrcp_unset_repeat_mode_changed_cb() + */ +typedef void (*bt_avrcp_repeat_mode_changed_cb) (bt_avrcp_repeat_mode_e repeat, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief Called when the shuffle mode is changed by the remote control device. + * @since_tizen 2.3 + * + * @param[in] shuffle The shuffle mode + * @param[in] user_data The user data passed from the callback registration function + * @see bt_avrcp_set_shuffle_mode_changed_cb() + * @see bt_avrcp_unset_shuffle_mode_changed_cb() + */ +typedef void (*bt_avrcp_shuffle_mode_changed_cb) (bt_avrcp_shuffle_mode_e shuffle, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief Called when the scan mode is changed by the remote control device. + * @since_tizen 2.3 + * + * @param[in] shuffle The shuffle mode + * @param[in] user_data The user data passed from the callback registration function + * @see bt_avrcp_set_scan_mode_changed_cb() + * @see bt_avrcp_unset_scan_mode_changed_cb() + */ +typedef void (*bt_avrcp_scan_mode_changed_cb) (bt_avrcp_scan_mode_e scan, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_HID_MODULE + * @brief Called when the connection state is changed. + * @since_tizen 2.3 + * + * @details This callback is called when the connection state is changed. + * When you call bt_hid_host_connect() or bt_hid_host_disconnect(), this callback is also called with error result even though these functions fail. + * @param[in] result The result of changing the connection state + * @param[in] connected The state to be changed. @a true means connected state, Otherwise, @a false. + * @param[in] remote_address The remote address + * @param[in] user_data The user data passed from the callback registration function + * @see bt_hid_host_connect() + * @see bt_hid_host_disconnect() + */ +typedef void (*bt_hid_host_connection_state_changed_cb) (int result, bool connected, const char *remote_address, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_HDP_MODULE + * @brief Called when the connection is established. + * @since_tizen 2.3 + * + * @param[in] result The result of connecting to the remote device + * @param[in] remote_address The address of connected remote device + * @param[in] app_id The ID of application + * @param[in] type The type of HDP(Health Device Profile) channel + * @param[in] channel The connected data channel + * @param[in] user_data The user data passed from the callback registration function + * @see bt_hdp_disconnected_cb + * @see bt_hdp_set_connection_state_changed_cb() + * @see bt_hdp_unset_connection_state_changed_cb() + */ +typedef void (*bt_hdp_connected_cb) (int result, const char *remote_address, const char *app_id, + bt_hdp_channel_type_e type, unsigned int channel, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_HDP_MODULE + * @brief Called when the connection is disconnected. + * @since_tizen 2.3 + * + * @param[in] result The result of disconnecting from the remote device + * @param[in] remote_address The address of disconnected remote device + * @param[in] channel The connected data channel + * @param[in] user_data The user data passed from the callback registration function + * @see bt_hdp_connected_cb + * @see bt_hdp_set_connection_state_changed_cb() + * @see bt_hdp_unset_connection_state_changed_cb() + */ +typedef void (*bt_hdp_disconnected_cb) (int result, const char *remote_address, unsigned int channel, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_HDP_MODULE + * @brief Called when the you receive the data. + * @since_tizen 2.3 + * + * @param[in] channel The connected data channel + * @param[in] data The received data + * @param[in] size The size of received data (byte) + * @param[in] user_data The user data passed from the callback registration function + * @see bt_hdp_set_data_received_cb() + * @see bt_hdp_unset_data_received_cb() + */ +typedef void (*bt_hdp_data_received_cb) (unsigned int channel, const char *data, unsigned int size, void *user_data); + +/** + * @deprecated Deprecated since 2.3.1. Use bt_gatt_foreach_cb instead. + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Called when you get the primary services repeatedly. + * @since_tizen 2.3 + * + * @param[in] service The attribute handle of service + * @param[in] user_data The user data passed from the foreach function + * @return @c true to continue with the next iteration of the loop, + * \n @c false to break out of the loop. + * @pre bt_gatt_foreach_primary_services() will invoke this function. + * @see bt_gatt_foreach_primary_services() + */ +typedef bool (*bt_gatt_primary_service_cb) (bt_gatt_attribute_h service, void *user_data); + +/** + * @deprecated Deprecated since 2.3.1. This is not required because characteristic discovery is happened automatically. + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Called after the characteristics are discovered by bt_gatt_discover_characteristics(). + * @since_tizen 2.3 + * + * @remarks If bt_gatt_discover_characteristics() failed, then this callback function is called only once with 0 totla and NULL characteristic_handle. + * @param[in] result The result of discovering + * @param[in] index The index of characteristics in a service, starts from 0 + * @param[in] total The total number of characteristics in a service + * @param[in] characteristic The attribute handle of characteristic + * @param[in] user_data The user data passed from the request function + * @return @c true to continue with the next iteration of the loop, + * \n @c false to break out of the loop. + * @pre bt_gatt_discover_characteristics() will invoke this callback. + * @see bt_gatt_discover_characteristics() + */ +typedef bool (*bt_gatt_characteristics_discovered_cb) (int result, int index, int total, bt_gatt_attribute_h characteristic, void *user_data); + +/** + * @deprecated Deprecated since 2.3.1. Use bt_gatt_foreach_cb instead. + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Called when you get the included services repeatedly. + * @since_tizen 2.3 + * + * @param[in] service The attribute handle of service + * @param[in] user_data The user data passed from the foreach function + * @return @c true to continue with the next iteration of the loop, + * \n @c false to break out of the loop. + * @pre bt_gatt_foreach_included_services() will invoke this function. + * @see bt_gatt_foreach_included_services() + */ +typedef bool (*bt_gatt_included_service_cb) (bt_gatt_attribute_h service, void *user_data); + +/** + * @deprecated Deprecated since 2.3.1. Use bt_gatt_client_characteristic_value_changed_cb instead. + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Called when a characteristic in service is changed. + * @since_tizen 2.3 + * + * @param[in] characteristic The attribute handle of characteristic + * @param[in] value The value of characteristic (byte array) + * @param[in] value_length The length of value + * @param[in] user_data The user data passed from the callback registration function + * @see bt_gatt_set_characteristic_changed_cb() + * @see bt_gatt_unset_characteristic_changed_cb() + */ +typedef void (*bt_gatt_characteristic_changed_cb) (bt_gatt_attribute_h characteristic, unsigned char *value, int value_length, void *user_data); + +/** + * @deprecated Deprecated since 2.3.1. Use bt_gatt_client_request_completed_cb instead. + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Called when a characteristic value is written. + * @since_tizen 2.3 + * + * @see bt_gatt_set_characteristic_value() + */ +typedef void (*bt_gatt_characteristic_write_cb) (void *user_data); + +/** + * @deprecated Deprecated since 2.3.1. Use bt_gatt_client_request_completed_cb instead. + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Called when a characteristic value is read. + * @since_tizen 2.3 + * + * @param[in] value The value of characteristic (byte array) + * @param[in] value_length The length of value + * @param[in] user_data The user data passed from the foreach function + * @see bt_gatt_read_characteristic_value() + */ +typedef void (*bt_gatt_characteristic_read_cb) (unsigned char *value, + int value_length, void *user_data); + +/** + * @deprecated Deprecated since 2.3.1. This is not required because descriptor discovery is happened automatically. + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Called after the characteristics descriptors are discovered by bt_gatt_discover_characteristic_descriptor(). + * @since_tizen 2.3 + * + * @param[in] result The result of discovering + * @param[in] characteristic_format The format of the information data. + * characteristic_format = 0x01 indicates UUIDs are 16-bits + * characteristic_format = 0x02 indicates UUIDs are 128-bits + * @param[in] total The total number of elements in characteristic_descriptor + * @param[in] characteristic descriptor The attribute handle and the UUID of characteristic descriptor + * @param[in] user_data The user data passed from the request function + * @see bt_gatt_discover_characteristic_descriptor() + */ +typedef void (*bt_gatt_characteristic_descriptor_discovered_cb) (int result, + unsigned char characteristic_format, int total, + bt_gatt_attribute_h characteristic_descriptor, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Called when you get GATT handles repeatedly + * @since_tizen 2.3.1 + * + * @param[in] total The total number of GATT handles to be called + * @param[in] index The index of current GATT handle. It starts from 0. + * @param[in] gatt_handle The GATT handle + * @param[in] user_data The user data passed from the foreach function + * + * @see bt_gatt_service_foreach_characteristics() + * @see bt_gatt_service_foreach_included_services() + * @see bt_gatt_characteristic_foreach_descriptors() + * @see bt_gatt_client_foreach_services() + */ +typedef bool (*bt_gatt_foreach_cb) (int total, int index, bt_gatt_h gatt_handle, + void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Called when the client request(e.g. read / write) has been completed + * @since_tizen 2.3.1 + * + * @param[in] result The result of a request + * @param[in] request_handle The requesting GATT handle + * @param[in] user_data The user data passed from the requesting function + * + * @see bt_gatt_client_read_value() + * @see bt_gatt_client_write_value() + */ +typedef void (*bt_gatt_client_request_completed_cb) (int result, + bt_gatt_h request_handle, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Called when a value of a watched characteristic's GATT handle has been changed + * @since_tizen 2.3.1 + * + * @remarks After this function is returned, a changed vlaue is automatically + * applied to @a characteristic. Before that, @a characteristic has an old value. + * + * @param[in] characteristic The characteristic's GATT handle of which value change is informed. It has an old value. + * @param[in] value The new value + * @param[in] len The length of @a value + * @param[in] user_data The user data passed from the registering function + * + * @see bt_gatt_client_set_characteristic_value_changed_cb() + */ +typedef void (*bt_gatt_client_characteristic_value_changed_cb) (bt_gatt_h characteristic, + char *value, int len, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Called when the connection state is changed. + * @since_tizen 2.3 + * + * @details This callback is called when the connection state is changed. + * When you called bt_gatt_connect() or bt_gatt_disconnect(), this callback is also called with error result even though these functions fail. + * + * @param[in] result The result of changing the connection state. + * @param[in] connected The state to be changed, @a true means connected state, Otherwise, @a false. + * @param[in] remote_address The remote_address + * @param[in] user_data The user data passed from the callback registration function. + * + * @see bt_gatt_connect() + * @see bt_gatt_disconnect() + * @see bt_gatt_set_connection_state_changed_cb() + * @see bt_gatt_unset_connection_state_changed_cb() + */ +typedef void (*bt_gatt_connection_state_changed_cb)(int result, bool connected, const char *remote_address, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_PAN_NAP_MODULE + * @brief Called when the connection state is changed. + * @since_tizen 2.3 + * + * @param[in] connected Indicates whether a client is connected or disconnected + * @param[in] remote_address The remote address + * @param[in] interface_name The interface name. For example, bnep0, bnep1. + * @param[in] user_data The user data passed from the callback registration function + * @see bt_nap_set_connection_state_changed_cb() + * @see bt_nap_unset_connection_state_changed_cb() + */ +typedef void (*bt_nap_connection_state_changed_cb) (bool connected, const char *remote_address, const char *interface_name, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_PAN_PANU_MODULE + * @brief Called when the connection state is changed. + * @since_tizen 2.3 + * + * @details This callback is called when the connection state is changed. + * When you call bt_panu_connect() or bt_panu_disconnect(), this callback is also called with error result even though these functions fail. + * @param[in] result The result of changing the connection state + * @param[in] connected The state to be changed. @a true means connected state, Otherwise, @a false. + * @param[in] remote_address The remote address + * @param[in] type The type of PAN service + * @param[in] user_data The user data passed from the callback registration function + * @see bt_nap_set_connection_state_changed_cb() + * @see bt_nap_unset_connection_state_changed_cb() + */ +typedef void (*bt_panu_connection_state_changed_cb) (int result, bool connected, const char *remote_address, bt_panu_service_type_e type, void *user_data); + + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif // __TIZEN_NETWORK_BLUETOOTH_TYPE_H__ diff --git a/include/mobile/bluetooth_type_internal.h b/include/mobile/bluetooth_type_internal.h new file mode 100644 index 0000000..c1be7e8 --- /dev/null +++ b/include/mobile/bluetooth_type_internal.h @@ -0,0 +1,254 @@ +/* + * 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 __TIZEN_NETWORK_BLUETOOTH_TYPE_INTERNAL_H__ +#define __TIZEN_NETWORK_BLUETOOTH_TYPE_INTERNAL_H__ + + #ifdef __cplusplus +extern "C" +{ +#endif /* __cplusplus */ + +/** + * @file bluetooth_type_internal.h + */ + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Enumerations of the Bluetooth adapter le scan type. + * @since_tizen 2.3 + */ +typedef enum +{ + BT_ADAPTER_LE_PASSIVE_SCAN = 0x00, + BT_ADAPTER_LE_ACTIVE_SCAN +} bt_adapter_le_scan_type_e; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Enumerations of the Bluetooth le scan mode. + * @since_tizen 2.3 + */ +typedef enum +{ + BT_ADAPTER_LE_SCAN_MODE_BALANCED, + BT_ADAPTER_LE_SCAN_MODE_LOW_LATENCY, + BT_ADAPTER_LE_SCAN_MODE_LOW_ENERGY +} bt_adapter_le_scan_mode_e; + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Called when the manufacturer dat changes. + * @since_tizen 2.3 + * + * @param[in] data The manufacurer data of the Bluetooth device to be changed + * @param[in] len The length of @a data + * @param[in] user_data The user data passed from the callback registration function + * @pre This function will be invoked when the manufacturer data of Bluetooth adapter changes + * if callback is registered using bt_adapter_set_manufacturer_data_changed_cb(). + * @see bt_adapter_set_manufacturer_data() + * @see bt_adapter_set_manufacturer_data_changed_cb() + * @see bt_adapter_unset_manufacturer_data_changed_cb() + */ +typedef void (*bt_adapter_manufacturer_data_changed_cb) (char *data, + int len, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Enumerations of the attribute's permission + * @since_tizen 2.4 + */ +typedef enum { + BT_GATT_PERMISSION_READ = 0x01, + BT_GATT_PERMISSION_WRITE = 0x02, + BT_GATT_PERMISSION_ENCRYPTION = 0x04, + BT_GATT_PERMISSION_AUTHENTICATION = 0x08, + BT_GATT_PERMISSION_AUTHORIZATION = 0x10, + BT_GATT_PERMISSION_NONE = 0x20, +} bt_gatt_permission_e; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief The handle to control Bluetooth LE scan filter + * @since_tizen 2.4 + */ +typedef void* bt_scan_filter_h; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief The handle of a GATT server + * @since_tizen 2.4 + */ +typedef void* bt_gatt_server_h; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Called when a value of a characteristic or descriptor's GATT handle has been changed + * @since_tizen 2.4 + * + * @remarks After this function is returned, a changed vlaue is automatically + * applied to @a gatt_handle. Before that, @a gatt_handle has an old value. + * + * @param[in] remote_address The address of the remote device which requests a change + * @param[in] server The GATT server handle + * @param[in] gatt_handle The characteristic or descriptor's GATT handle which has an old value + * @param[in] offset The requested offset from where the @a gatt_handle value will be updated + * @param[in] value The new value + * @param[in] len The length of @a value + * @param[in] user_data The user data passed from the registration function + * + * @see bt_gatt_server_set_value_changed_cb() + */ +typedef void (*bt_gatt_server_value_changed_cb) (char *remote_address, + bt_gatt_server_h server, bt_gatt_h gatt_handle, + int offset, char *value, int len, + void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Called when the remote device requests to read a value on a GATT server + * @since_tizen 2.4 + * + * @param[in] remote_address The address of the requesting remote device + * @param[in] server The GATT server handle + * @param[in] gatt_handle The characteristic or descriptor's GATT handle to be read + * @param[in] request_id The identification of this request. It will be used to send a reponse. + * @param[in] offset The requested offset from where the GATT handle's value is read + * @param[in] user_data The user data passed from the registration function + * + * @see bt_gatt_server_set_read_value_requested_cb() + * @see bt_gatt_server_send_response() + */ +typedef void (*bt_gatt_server_read_value_requested_cb) (char *remote_address, + int request_id, bt_gatt_server_h server, bt_gatt_h gatt_handle, + int offset, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Called when the sending notification / indication is done + * @since_tizen 2.4 + * + * @remarks In case of an indication, once a confirmation is received from the remote device this callback will be called. \n + * This callback will be called several times if there are two or more remote devices which enable a Client Characteristic Configuration Descriptor(CCCD). \n + * For the last remote device, @a completed will be set as true. + * + * @param[in] result The result of a sending operation + * @param[in] remote_address The address of the remote device + * @param[in] server The GATT server handle + * @param[in] characteristic The characteristic's GATT handle + * @param[in] completed If this callback is for the last remote device which enables a CCCD, it will be true. Or it will be false. + * @param[in] user_data The user data passed from the requesting function + * + * @see bt_gatt_server_notify() + */ +typedef void (*bt_gatt_server_notification_sent_cb) (int result, + char *remote_address, bt_gatt_server_h server, + bt_gatt_h characteristic, bool completed, void *user_data); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief Enumerations for the player control command + * @since_tizen 2.3 + */ + typedef enum { + BT_AVRCP_CONTROL_PLAY = 0x01, /**< Play */ + BT_AVRCP_CONTROL_PAUSE, /**< Pause */ + BT_AVRCP_CONTROL_STOP, /**< Stop */ + BT_AVRCP_CONTROL_NEXT, /**< Next Track*/ + BT_AVRCP_CONTROL_PREVIOUS, /**< Previous track */ + BT_AVRCP_CONTROL_FAST_FORWARD, /**< Fast Forward */ + BT_AVRCP_CONTROL_REWIND /**< Rewind */ +} bt_avrcp_player_command_e; + + /** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief Structure of Track metadata information. + * @since_tizen 2.3 + * + * @see #bt_class_s + */ +typedef struct { + const char *title; + const char *artist; + const char *album; + const char *genre; + unsigned int total_tracks; + unsigned int number; + unsigned int duration; +} bt_avrcp_metadata_attributes_info_s; + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief Called when the connection state is changed. + * @since_tizen 2.3 + * @param[in] connected The state to be changed. @a true means connected state, Otherwise, @a false. + * @param[in] remote_address The remote address + * @param[in] user_data The user data passed from the callback registration function + * @see bt_avrcp_control_initialize() + * @see bt_avrcp_control_deinitialize() + */ +typedef void (*bt_avrcp_control_connection_state_changed_cb) (bool connected, const char *remote_address, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief Called when the Song position mode is changed by the remote target device. + * @since_tizen 2.3 + * + * @param[in] position The song position + * @param[in] user_data The user data passed from the callback registration function + * @see bt_avrcp_set_song_position_changed_cb() + * @see bt_avrcp_unset_song_position_changed_cb() + */ +typedef void (*bt_avrcp_song_position_changed_cb) (unsigned int position, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief Called when the Song metadata information is changed by the remote target device. + * @since_tizen 2.3 + * + * @param[in] position The song metadata information + * @param[in] user_data The user data passed from the callback registration function + * @see bt_avrcp_set_track_info_changed_cb() + * @see bt_avrcp_unset_track_info_changed_cb() + */ +typedef void (*bt_avrcp_track_info_changed_cb) (bt_avrcp_metadata_attributes_info_s *track, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief Called when the Song Play status mode is changed by the remote target device. + * @since_tizen 2.3 + * + * @param[in] play_state The song play status + * @param[in] user_data The user data passed from the callback registration function + * @see bt_avrcp_set_play_status_changed_cb() + * @see bt_avrcp_unset_play_status_changed_cb() + */ +typedef void (*bt_avrcp_play_status_changed_cb) (bt_avrcp_player_state_e play_state, void *user_data); + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif // __TIZEN_NETWORK_BLUETOOTH_TYPE_INTERNAL_H__ diff --git a/include/wearable/bluetooth.h b/include/wearable/bluetooth.h new file mode 100755 index 0000000..6b5bf00 --- /dev/null +++ b/include/wearable/bluetooth.h @@ -0,0 +1,5039 @@ +/* + * 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 __TIZEN_NETWORK_BLUETOOTH_H__ +#define __TIZEN_NETWORK_BLUETOOTH_H__ + +#include +#include +#include +#include + +#include "bluetooth_type.h" + +#ifdef __cplusplus +extern "C" +{ +#endif /* __cplusplus */ + +/** + * @file bluetooth.h + * @brief API to control the Bluetooth adapter and devices and communications. + * @ingroup CAPI_NETWORK_BLUETOOTH_MODULE + */ + + +/** + * @addtogroup CAPI_NETWORK_BLUETOOTH_MODULE + * @{ + */ + + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_MODULE + * @brief Initializes the Bluetooth API. + * @since_tizen 2.3.1 + * + * @remarks This function must be called before Bluetooth API starts. \n + * You must free all resources of the Bluetooth service by calling bt_deinitialize() if Bluetooth service is no longer needed. + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_deinitialize() + */ +int bt_initialize(void); + + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_MODULE + * @brief Releases all resources of the Bluetooth API. + * @since_tizen 2.3.1 + * + * @remarks This function must be called if Bluetooth API is no longer needed. + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre Bluetooth API must be initialized with bt_initialize(). + * + * @see bt_initialize() + */ +int bt_deinitialize(void); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Enables the local Bluetooth adapter, asynchronously. + * @since_tizen 2.3.1 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * + * @details This function enables Bluetooth protocol stack and hardware. + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_ALREADY_DONE Already enabled + * @retval #BT_ERROR_NOW_IN_PROGRESS Operation now in progress + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre Bluetooth service must be initialized with bt_initialize(). + * @pre The state of local Bluetooth must be #BT_ADAPTER_DISABLED + * @post This function invokes bt_adapter_state_changed_cb(). + * + * @see bt_initialize() + * @see bt_adapter_get_state() + * @see bt_adapter_set_state_changed_cb() + * @see bt_adapter_unset_state_changed_cb() + * @see bt_adapter_state_changed_cb() + * + */ +int bt_adapter_enable(void); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Disables the local Bluetooth adapter, asynchronously. + * @since_tizen 2.3.1 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * + * @details This function disables Bluetooth protocol stack and hardware. + * + * @remarks You should disable Bluetooth adapter, which is helpful for saving power. + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_NOW_IN_PROGRESS Operation now in progress + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED + * @post This function invokes bt_adapter_state_changed_cb(). + * + * @see bt_adapter_get_state() + * @see bt_adapter_state_changed_cb() + * @see bt_adapter_set_state_changed_cb() + * @see bt_adapter_unset_state_changed_cb () + * + */ +int bt_adapter_disable(void); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Recover the local Bluetooth adapter, asynchronously. + * @since_tizen 2.3.1 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * + * @details This function does recovery logic, disables Bluetooth protocol stack and hardware, then enables after a few seconds. + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_NOW_IN_PROGRESS Operation now in progress + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED + * @post This function invokes bt_adapter_state_changed_cb(). + * + * @see bt_adapter_get_state() + * @see bt_adapter_state_changed_cb() + * @see bt_adapter_set_state_changed_cb() + * @see bt_adapter_unset_state_changed_cb () + * + */ +int bt_adapter_recover(void); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Reset the local Bluetooth adapter, synchronously. + * @since_tizen 2.3.1 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * + * @details This function resets Bluetooth protocol and values. + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre Bluetooth service must be initialized with bt_initialize(). + * @post bt_adapter_state_changed_cb() will be invoked if The state of local Bluetooth was #BT_ADAPTER_ENABLED. + * + * @see bt_initialize() + * @see bt_adapter_get_state() + * @see bt_adapter_set_state_changed_cb() + * @see bt_adapter_unset_state_changed_cb() + * @see bt_adapter_state_changed_cb() + * + */ +int bt_adapter_reset(void); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Gets the current state of local Bluetooth adapter. + * @since_tizen 2.3.1 + * + * @param[out] adapter_state The current adapter state + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre Bluetooth service must be initialized with bt_initialize(). + * + * @see bt_initialize() + */ +int bt_adapter_get_state(bt_adapter_state_e *adapter_state); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Gets the address of local Bluetooth adapter. + * @since_tizen 2.3.1 + * + * @remarks The @a local_address must be released with free() by you. + * + * @param[out] local_address The device address of local Bluetooth adapter + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OUT_OF_MEMORY Out of memory + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * @see bt_adapter_get_name() + */ +int bt_adapter_get_address(char **local_address); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Gets the version of local Bluetooth adapter. + * @since_tizen 2.3.1 + * @remarks The @a local_version must be released with free() by you. + * + * @param[out] local_version The version of local Bluetooth adapter + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OUT_OF_MEMORY Out of memory + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + */ +int bt_adapter_get_version(char **local_version); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Gets the information regarding local Bluetooth adapter. + * @since_tizen 2.3.1 + * @remarks The @a all parameters must be released with free() by you. + * + * @param[out] chipset Chipset name of local Bluetooth adapter + * @param[out] firmware Firmware info. of local Bluetooth adapter + * @param[out] stack_version Bluetooth stack version + * @param[out] profiles The profile list of local Bluetooth adapter + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OUT_OF_MEMORY Out of memory + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + */ +int bt_adapter_get_local_info(char **chipset, char **firmware, char **stack_version, char **profiles); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Gets the name of local Bluetooth adapter. + * @since_tizen 2.3.1 + * + * @details Use this function to get the friendly name associated with Bluetooth + * device, retrieved by the remote Bluetooth devices. + * + * @remarks The @a local_name must be released with free() by you. + * + * @param[out] local_name The local device name + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OUT_OF_MEMORY Out of memory + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * + * @see bt_adapter_set_name() + */ +int bt_adapter_get_name(char **local_name); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Sets the name of local Bluetooth adapter. + * @since_tizen 2.3.1 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * + * @param[in] local_name The name of the Bluetooth device. \n + * The maximum length is 248 characters. + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * @post bt_adapter_name_changed_cb() will be invoked if this function returns #BT_ERROR_NONE. + * + * @see bt_adapter_get_name() + * @see bt_adapter_name_changed_cb() + * @see bt_adapter_set_name_changed_cb() + * @see bt_adapter_unset_name_changed_cb() + */ +int bt_adapter_set_name(const char *local_name); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Gets the visibility mode of local Bluetooth adapter. + * @since_tizen 2.3.1 + * @param[out] mode The visibility mode of the Bluetooth device + * @param[out] duration The duration until the visibility mode is changed to #BT_ADAPTER_VISIBILITY_MODE_NON_DISCOVERABLE (in seconds). + * @a duration is valid only if @a mode is #BT_ADAPTER_VISIBILITY_MODE_LIMITED_DISCOVERABLE. This value can be NULL. + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + */ +int bt_adapter_get_visibility(bt_adapter_visibility_mode_e *mode, int *duration); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Sets the visibility mode. + * @since_tizen 2.3.1 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * + * @remarks #BT_ADAPTER_VISIBILITY_MODE_LIMITED_DISCOVERABLE will change to #BT_ADAPTER_VISIBILITY_MODE_NON_DISCOVERABLE + * after the given @a duration goes. + * + * @param[in] discoverable_mode The Bluetooth visibility mode to set + * @param[in] duration The duration until the visibility mode is changed to #BT_ADAPTER_VISIBILITY_MODE_NON_DISCOVERABLE (in seconds). + * @a duration is used only for #BT_ADAPTER_VISIBILITY_MODE_LIMITED_DISCOVERABLE mode. + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * @post bt_adapter_visibility_mode_changed_cb() will be invoked if this function returns #BT_ERROR_NONE. + * + * @see bt_adapter_get_visibility() + * @see bt_adapter_visibility_mode_changed_cb() + * @see bt_adapter_set_visibility_mode_changed_cb() + * @see bt_adapter_unset_visibility_mode_changed_cb() + */ +int bt_adapter_set_visibility(bt_adapter_visibility_mode_e discoverable_mode, int duration); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Starts the device discovery, asynchronously. + * @since_tizen 2.3.1 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * + * @details If a device is discovered, bt_adapter_device_discovery_state_changed_cb() will be invoked + * with #BT_ADAPTER_DEVICE_DISCOVERY_FOUND, and then bt_adapter_device_discovery_state_changed_cb() + * will be called with #BT_ADAPTER_DEVICE_DISCOVERY_FINISHED in case of the completion or cancellation of the discovery. + * + * @remarks To connect to peer Bluetooth device, you need to know its Bluetooth address. \n + * The device discovery can be stopped by bt_adapter_stop_device_discovery(). + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_NOW_IN_PROGRESS Operation is now in progress + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * @post This function invokes bt_adapter_device_discovery_state_changed_cb(). + * + * @see bt_adapter_is_discovering() + * @see bt_adapter_stop_device_discovery() + * @see bt_adapter_device_discovery_state_changed_cb() + * @see bt_adapter_set_device_discovery_state_changed_cb() + * @see bt_adapter_unset_device_discovery_state_changed_cb() + */ +int bt_adapter_start_device_discovery(void); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Stops the device discovery, asynchronously. + * @since_tizen 2.3.1 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * @remarks The device discovery process will take 10 ~ 20 seconds to get all the devices in vicinity. + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_NOT_IN_PROGRESS Operation is not in progress + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The device discovery must be in progress with bt_adapter_start_device_discovery(). + * @post This function invokes bt_adapter_device_discovery_state_changed_cb(). + * + * @see bt_adapter_is_discovering() + * @see bt_adapter_start_device_discovery() + * @see bt_adapter_set_device_discovery_state_changed_cb() + * @see bt_adapter_unset_device_discovery_state_changed_cb() + * @see bt_adapter_device_discovery_state_changed_cb() + */ +int bt_adapter_stop_device_discovery(void); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Checks for the device discovery is in progress or not. + * @since_tizen 2.3.1 + * + * @remarks If Bluetooth discovery is in progress, other operations are not allowed and + * you have to either stop the discovery operation, or wait for it to be finished, + * before performing other operations. + + * @param[out] is_discovering The discovering status: (@c true = in progress , @c false = not in progress ) + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * + * @see bt_adapter_start_device_discovery() + * @see bt_adapter_stop_device_discovery() + */ +int bt_adapter_is_discovering(bool *is_discovering); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Get the service mask from the uuid list. + * @since_tizen 2.3.1 + * + * @param[in] uuids The UUID list of the device. + * @param[in] no_of_service The number of the UUID list count. + * @param[out] service_mask_list Service mask list converted from the given UUID list. + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_service_class_t + */ +int bt_device_get_service_mask_from_uuid_list(char **uuids, + int no_of_service, + bt_service_class_t *service_mask_list); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Retrieves the device information of all bonded devices. + * @since_tizen 2.3.1 + * + * @param [in] callback The callback function to invoke + * @param [in] user_data The user data passed from the foreach function + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_OUT_OF_MEMORY Out of memory + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * @post This function invokes bt_adapter_bonded_device_cb(). + * + * @see bt_adapter_bonded_device_cb() + */ +int bt_adapter_foreach_bonded_device(bt_adapter_bonded_device_cb callback, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Gets the device information of a bonded device. + * @since_tizen 2.3.1 + * @remarks The @a device_info must be released with bt_adapter_free_device_info() by you . + * + * @param [in] remote_address The address of remote device + * @param [out] device_info The bonded device information + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_OUT_OF_MEMORY Out of memory + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_BONDED Remote device not bonded + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * @post This function invokes bt_adapter_bonded_device_cb(). + * + * @see bt_adapter_bonded_device_cb() + */ +int bt_adapter_get_bonded_device_info(const char *remote_address, bt_device_info_s **device_info); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Frees device info. + * @since_tizen 2.3.1 + * + * @param [in] device_info The bonded device information + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_adapter_get_bonded_device_info() + */ +int bt_adapter_free_device_info(bt_device_info_s *device_info); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Checks whether the UUID of service is used or not + * @since_tizen 2.3.1 + * @param[in] service_uuid The UUID of service + * @param[out] used Indicates whether the service is used or not + * @return true on success, otherwise false. + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + */ +int bt_adapter_is_service_used(const char *service_uuid, bool *used); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Registers a callback function to be invoked when the Bluetooth adapter state changes. + * @since_tizen 2.3.1 + * + * @param[in] callback The callback function to invoke + * @param[in] user_data The user data to be passed to the callback function + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @post bt_adapter_state_changed_cb() will be invoked. + * + * @see bt_initialize() + * @see bt_adapter_state_changed_cb() + * @see bt_adapter_set_state_changed_cb() + * @see bt_adapter_unset_state_changed_cb() + */ +int bt_adapter_set_state_changed_cb(bt_adapter_state_changed_cb callback, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Unregisters the callback function. + * @since_tizen 2.3.1 + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * + * @see bt_initialize() + * @see bt_adapter_set_state_changed_cb() + */ +int bt_adapter_unset_state_changed_cb(void); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Registers a callback function to be invoked when the name of Bluetooth adapter changes. + * @since_tizen 2.3.1 + * + * @param[in] callback The callback function to invoke + * @param[in] user_data The user data to be passed to the callback function + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @post bt_adapter_name_changed_cb() will be invoked. + * + * @see bt_initialize() + * @see bt_adapter_name_changed_cb() + * @see bt_adapter_unset_name_changed_cb() + */ +int bt_adapter_set_name_changed_cb(bt_adapter_name_changed_cb callback, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Unregisters the callback function. + * @since_tizen 2.3.1 + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * + * @see bt_initialize() + * @see bt_adapter_set_name_changed_cb() + */ +int bt_adapter_unset_name_changed_cb(void); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Registers a callback function to be invoked when the visibility mode changes. + * @since_tizen 2.3.1 + * + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @post bt_adapter_visibility_mode_changed_cb() will be invoked. + * + * @see bt_initialize() + * @see bt_adapter_visibility_mode_changed_cb() + * @see bt_adapter_unset_visibility_mode_changed_cb() + */ +int bt_adapter_set_visibility_mode_changed_cb(bt_adapter_visibility_mode_changed_cb callback, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Unregisters the callback function. + * @since_tizen 2.3.1 + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * + * @see bt_initialize() + * @see bt_adapter_set_visibility_mode_changed_cb() + */ +int bt_adapter_unset_visibility_mode_changed_cb(void); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Registers a callback function to be invoked every second + * @since_tizen 2.3.1 + * until the visibility mode is changed from #BT_ADAPTER_VISIBILITY_MODE_LIMITED_DISCOVERABLE + * to #BT_ADAPTER_VISIBILITY_MODE_NON_DISCOVERABLE. + * @details When you set visibility mode as #BT_ADAPTER_VISIBILITY_MODE_LIMITED_DISCOVERABLE, + * @a callback will be called every second until visibility mode is changed to #BT_ADAPTER_VISIBILITY_MODE_NON_DISCOVERABLE. + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized by bt_initialize(). + * @post bt_adapter_visibility_duration_changed_cb() will be invoked. + * @see bt_initialize() + * @see bt_adapter_visibility_duration_changed_cb() + * @see bt_adapter_unset_visibility_duration_changed_cb() + */ +int bt_adapter_set_visibility_duration_changed_cb(bt_adapter_visibility_duration_changed_cb callback, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Unregisters the callback function. + * @since_tizen 2.3.1 + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @see bt_initialize() + * @see bt_adapter_set_visibility_duration_changed_cb() + */ +int bt_adapter_unset_visibility_duration_changed_cb(void); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Registers a callback function to be invoked when the device discovery state changes. + * @since_tizen 2.3.1 + * + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @post bt_adapter_device_discovery_state_changed_cb() will be invoked. + * + * @see bt_initialize() + * @see bt_adapter_device_discovery_state_changed_cb() + * @see bt_adapter_set_device_discovery_state_changed_cb() + * @see bt_adapter_unset_device_discovery_state_changed_cb() + */ +int bt_adapter_set_device_discovery_state_changed_cb(bt_adapter_device_discovery_state_changed_cb callback, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Unregisters the callback function. + * @since_tizen 2.3.1 + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * + * @see bt_initialize() + * @see bt_adapter_set_device_discovery_state_changed_cb() + */ +int bt_adapter_unset_device_discovery_state_changed_cb(void); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Get the Hash and Randmoizer value, synchronously. + * @since_tizen 2.3.1 + * + * @param[out] hash The hash value recieved from the controller + * @param[out] randomizer The hash value recieved from the controller + * @param[out] hash_len The length of the hash value + * @param[out] randomizer_len The length of the randomizer value + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @see bt_initialize() + */ +int bt_adapter_get_local_oob_data(unsigned char **hash, unsigned char **randomizer, + int *hash_len, int *randomizer_len); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Sets the Hash and Randmoizer value, synchronously. + * @since_tizen 2.3.1 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * + * @param[in] remote_address Remote device address + * @param[in] hash The hash value recieved from the controller + * @param[in] randomizer The hash value recieved from the controller + * @param[in] hash_len The length of the hash value. Allowed value is 16 + * @param[in] randomizer_len The length of the randomizer value. Allowed value is 16 + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @see bt_initialize() + */ +int bt_adapter_set_remote_oob_data(const char *remote_address, + unsigned char *hash, unsigned char *randomizer, + int hash_len, int randomizer_len); +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Deletes the Hash and Randomizer value, synchronously. + * @since_tizen 2.3.1 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * + * @param[in] remote_address Remote device address + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @see bt_initialize() + */ +int bt_adapter_remove_remote_oob_data(const char *remote_address); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Registers a callback function to be invoked when the connectable state changes. + * @since_tizen 2.3.1 + * + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @post bt_adapter_connectable_changed_cb() will be invoked. + * + * @see bt_initialize() + * @see bt_adapter_connectable_changed_cb() + * @see bt_adapter_unset_connectable_changed_cb() + */ +int bt_adapter_set_connectable_changed_cb(bt_adapter_connectable_changed_cb callback, void *user_data); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Unregisters the callback function. + * @since_tizen 2.3.1 + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * + * @see bt_initialize() + * @see bt_adapter_set_connectable_changed_cb() + */ +int bt_adapter_unset_connectable_changed_cb(void); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Gets the connectable state of local Bluetooth adapter. + * @since_tizen 2.3.1 + * + * @remarks When connectable state is false, no device can connect to this device and visibility mode cannot be changed. + * + * @param[out] connectable The connectable state of local Bluetooth adapter + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * + * @see bt_adapter_set_connectable() + */ +int bt_adapter_get_connectable(bool *connectable); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Sets the connectable state of local Bluetooth adapter. + * @since_tizen 2.3.1 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * + * @remarks When connectable state is false, no device can connect to this device and visibility mode cannot be changed. + * + * @param[in] connectable The connectable state to set + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * @post bt_adapter_connectable_changed_cb() will be invoked if this function returns #BT_ERROR_NONE. + * + * @see bt_adapter_get_connectable() + * @see bt_adapter_connectable_changed_cb() + * @see bt_adapter_set_connectable_changed_cb() + * @see bt_adapter_unset_connectable_changed_cb() + */ +int bt_adapter_set_connectable(bool connectable); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Enables the local Bluetooth le adapter, asynchronously. + * @since_tizen 2.3.1 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * + * @details This function enables Bluetooth protocol stack and hardware. + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_ALREADY_DONE Already enabled + * @retval #BT_ERROR_NOW_IN_PROGRESS Operation now in progress + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre Bluetooth service must be initialized with bt_initialize(). + * @post This function invokes bt_adapter_le_state_changed_cb(). + * + * @see bt_initialize() + * @see bt_adapter_le_get_state() + * @see bt_adapter_le_set_state_changed_cb() + * @see bt_adapter_le_unset_state_changed_cb() + * @see bt_adapter_le_state_changed_cb() + * + */ +int bt_adapter_le_enable(void); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Disables the local Bluetooth le adapter, asynchronously. + * @since_tizen 2.3.1 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * + * @details This function disables Bluetooth le protocol stack and hardware. + * + * @remarks + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_NOW_IN_PROGRESS Operation now in progress + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_LE_ENABLED + * @post This function invokes bt_adapter_le_state_changed_cb(). + * + * @see bt_adapter_le_get_state() + * @see bt_adapter_le_state_changed_cb() + * @see bt_adapter_le_set_state_changed_cb() + * @see bt_adapter_le_unset_state_changed_cb () + * + */ +int bt_adapter_le_disable(void); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Gets the current state of local Bluetooth adapter. + * @since_tizen 2.3.1 + * + * @param[out] adapter_le_state The current adapter le state + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre Bluetooth service must be initialized with bt_initialize(). + * + * @see bt_initialize() + */ +int bt_adapter_le_get_state(bt_adapter_le_state_e *adapter_le_state); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Starts the LE scan to find LE advertisement. + * @since_tizen 2.3.1 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * + * @details If a LE advertisement is found, bt_adapter_le_scan_result_cb() will be invoked. + * + * @param[in] cb The callback to report the result of this function + * @param[in] user_data The user data to be passed when callback is called + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_NOW_IN_PROGRESS Operation is now in progress + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * @post This function invokes bt_adapter_le_scan_result_cb(). + * + * @see bt_adapter_le_scan_result_cb() + */ +int bt_adapter_le_start_scan(bt_adapter_le_scan_result_cb cb, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Stops the LE scan. + * @since_tizen 2.3.1 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_NOT_IN_PROGRESS Operation is not in progress + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The LE scan must be in progress with bt_adapter_le_start_scan(). + * + * @see bt_adapter_le_start_scan() + */ +int bt_adapter_le_stop_scan(void); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Gets the service UUID list from the scan result information + * @since_tizen 2.3.1 + * + * @remarks The @a uuids must be iterated as count and each pointed data must be released with free(). + * Then uuids must be released with free(). \n + * 16-bit service UUID or 128-bit service UUID is supported. (e.g. 180F, 0000180F-0000-1000-8000-00805F9B34FB) + * + * @param[in] info The scan result information + * @param[in] pkt_type The packet type + * @param[out] uuids The list of string of the service uuid + * @param[out] count The count of the service UUIDs + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NO_DATA No data available + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * + * @see bt_adapter_le_scan_result_cb() + */ +int bt_adapter_le_get_scan_result_service_uuids(const bt_adapter_le_device_scan_result_info_s *info, + bt_adapter_le_packet_type_e pkt_type, char ***uuids, int *count); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Gets the device name from the scan result information + * @since_tizen 2.3.1 + * + * @remarks The @a name must be released with free() by you. + * + * @param[in] info The scan result information + * @param[in] pkt_type The packet type + * @param[out] name The device name + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NO_DATA No data available + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * + * @see bt_adapter_le_scan_result_cb() + */ +int bt_adapter_le_get_scan_result_device_name(const bt_adapter_le_device_scan_result_info_s *info, + bt_adapter_le_packet_type_e pkt_type, char **name); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Gets the transmission power level from the scan result information + * @since_tizen 2.3.1 + * + * @param[in] info The scan result information + * @param[in] pkt_type The packet type + * @param[out] power_level The transmission power level in dBm + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NO_DATA No data available + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * + * @see bt_adapter_le_scan_result_cb() + */ +int bt_adapter_le_get_scan_result_tx_power_level(const bt_adapter_le_device_scan_result_info_s *info, + bt_adapter_le_packet_type_e pkt_type, int *power_level); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Gets the service solicitation UUID list from the scan result information + * @since_tizen 2.3.1 + * + * @remarks The @a uuids must be iterated as count and each pointed data must be released with free(). + * Then uuids must be released with free(). \n + * 16-bit service solicitation UUID or 128-bit service solicitaion UUID is supported. + * (e.g. 180F, 0000180F-0000-1000-8000-00805F9B34FB) + * + * @param[in] info The scan result information + * @param[in] pkt_type The packet type + * @param[out] uuids The list of string of the service solicitation uuid + * @param[out] count The count of the service UUIDs + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NO_DATA No data available + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * + * @see bt_adapter_le_scan_result_cb() + */ +int bt_adapter_le_get_scan_result_service_solicitation_uuids(const bt_adapter_le_device_scan_result_info_s *info, + bt_adapter_le_packet_type_e pkt_type, char ***uuids, int *count); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Gets the service data list from the scan result information + * @since_tizen 2.3.1 + * + * @remarks The @a data_list must be released with bt_adapter_le_free_service_data_list() by you . + * + * @param[in] info The scan result information + * @param[in] pkt_type The packet type + * @param[out] data_list The list of the service data + * @param[out] count The count of the service data list + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NO_DATA No data available + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * + * @see bt_adapter_le_scan_result_cb() + */ +int bt_adapter_le_get_scan_result_service_data_list(const bt_adapter_le_device_scan_result_info_s *info, + bt_adapter_le_packet_type_e pkt_type, bt_adapter_le_service_data_s **data_list, int *count); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Frees service data list. + * @since_tizen 2.3.1 + * + * @param[in] data_list The list of the service data + * @param[in] count The count of the service data list + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_adapter_le_get_scan_result_service_data_list() + */ +int bt_adapter_le_free_service_data_list(bt_adapter_le_service_data_s *data_list, int count); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Gets the appearance from the scan result information + * @since_tizen 2.3.1 + * + * @param[in] info The scan result information + * @param[in] pkt_type The packet type + * @param[out] appearance The appearance + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NO_DATA No data available + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * + * @see bt_adapter_le_scan_result_cb() + */ +int bt_adapter_le_get_scan_result_appearance(const bt_adapter_le_device_scan_result_info_s *info, + bt_adapter_le_packet_type_e pkt_type, int *appearance); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Gets the manufacturer data from the scan result information + * @since_tizen 2.3.1 + * + * @remarks The @a manufacturer_data must be released with free() by you. + * + * @param[in] info The scan result information + * @param[in] pkt_type The packet type + * @param[out] manufacturer_id The manufacturer ID + * @param[out] manufacturer_data The manufacturer data (byte array) + * @param[out] manufacturer_data_len The length of manufacturer data + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NO_DATA No data available + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * + * @see bt_adapter_le_scan_result_cb() + */ +int bt_adapter_le_get_scan_result_manufacturer_data(const bt_adapter_le_device_scan_result_info_s *info, + bt_adapter_le_packet_type_e pkt_type, int *manufacturer_id, char **manufacturer_data, int *manufacturer_data_len); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Registers a callback function to be invoked when the Bluetooth adapter le state changes. + * @since_tizen 2.3.1 + * + * @param[in] callback The callback function to invoke + * @param[in] user_data The user data to be passed to the callback function + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @post bt_adapter_le_state_changed_cb() will be invoked. + * + * @see bt_initialize() + * @see bt_adapter_le_state_changed_cb() + * @see bt_adapter_le_unset_state_changed_cb() + */ +int bt_adapter_le_set_state_changed_cb(bt_adapter_le_state_changed_cb callback, void *user_data); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Unregisters the callback function. + * @since_tizen 2.3.1 + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * + * @see bt_initialize() + * @see bt_adapter_le_set_state_changed_cb() + */ +int bt_adapter_le_unset_state_changed_cb(void); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief add address to whitelist for accepting scanning request. + * @since_tizen 2.3.1 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * + * @remarks If the adress is in the whitelist then other LE devices are able to + * search this device. Before calling this API, make sure that the adapter is + * enabled. There is no callback event for this API. + + * @param[in] address The other device's address + * @param[in] address_type The other device's address type + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Adapter is not enabled + * @retval #BT_ERROR_RESOURCE_BUSY Device or resource busy + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * + * @see bt_adapter_le_start_advertising_new() + * @see bt_adapter_le_stop_advertising() + */ +int bt_adapter_le_add_white_list(const char *address, bt_device_address_type_e address_type); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief remove address from the whitelist for not accepting scanning request. + * @since_tizen 2.3.1 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * + * @remarks If the adress is in the whitelist then other LE devices are able to + * search this device. Before calling this API, make sure that the adapter is + * enabled. There is no callback event for this API. + * + * @param[in] address The other device's address + * @param[in] address_type The other device's address type + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Adapter is not enabled + * @retval #BT_ERROR_RESOURCE_BUSY Device or resource busy + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * + * @see bt_adapter_le_start_advertising_new() + * @see bt_adapter_le_stop_advertising() + */ +int bt_adapter_le_remove_white_list(const char *address, bt_device_address_type_e address_type); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Create advertiser to advertise device's existence or respond to LE scanning reqeust. + * @since_tizen 2.3.1 + * + * @param[out] advertiser The handle of advertiser + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_OUT_OF_MEMORY Out of memory + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * + * @see bt_adapter_le_destroy_advertiser() + */ +int bt_adapter_le_create_advertiser(bt_advertiser_h *advertiser); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Destroy advertiser. + * @since_tizen 2.3.1 + * + * @param[out] advertiser The handle of advertiser + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * + * @see bt_adapter_le_create_advertiser() + */ +int bt_adapter_le_destroy_advertiser(bt_advertiser_h advertiser); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Add a service UUID to advertise or scan response data. + * The maximum advertised or responded data size is 31 bytes + * including data type and system wide data. + * @since_tizen 2.3.1 + * + * @remarks 16-bit UUID or 128-bit UUID is supported. (e.g. 180F, 0000180F-0000-1000-8000-00805F9B34FB) + * + * @param[in] advertiser The handle of advertiser + * @param[in] pkt_type The packet type + * @param[in] uuid The string of the service UUID. + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_QUOTA_EXCEEDED Quota exceeded + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * + * @see bt_adapter_le_clear_advertising_data() + */ +int bt_adapter_le_add_advertising_service_uuid(bt_advertiser_h advertiser, + bt_adapter_le_packet_type_e pkt_type, const char *uuid); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Add a service solicitation UUID to advertise or scan response data. + * The maximum advertised or responded data size is 31 bytes + * including data type and system wide data. + * @since_tizen 2.3.1 + * + * @remarks 16-bit service solicitation UUID or 128-bit service solicitation UUID is supported. + * (e.g. 180F, 0000180F-0000-1000-8000-00805F9B34FB) + * + * @param[in] advertiser The handle of advertiser + * @param[in] pkt_type The packet type + * @param[in] uuid The string of the service solicitation UUID. + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_QUOTA_EXCEEDED Quota exceeded + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * + * @see bt_adapter_le_clear_advertising_data() + */ +int bt_adapter_le_add_advertising_service_solicitation_uuid(bt_advertiser_h advertiser, + bt_adapter_le_packet_type_e pkt_type, const char *uuid); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Add service data to advertise or scan response data. + * The maximum advertised or responded data size is 31 bytes + * including data type and system wide data. + * @since_tizen 2.3.1 + * + * @remarks 16-bit UUID is supported. (e.g. 180F) + * + * @param[in] advertiser The handle of advertiser + * @param[in] pkt_type The packet type + * @param[in] uuid 16-bit UUID of the service + * @param[in] service_data The service data + * @param[in] service_data_len The data length of service data + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_QUOTA_EXCEEDED Quota exceeded + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * + * @see bt_adapter_le_clear_advertising_data() + */ +int bt_adapter_le_add_advertising_service_data(bt_advertiser_h advertiser, + bt_adapter_le_packet_type_e pkt_type, const char *uuid, + const char *service_data, int service_data_len); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Sets the external appearance of this device to advertise or scan response data. + * Please refer to the adopted Bluetooth specification for the the appearance. + * @since_tizen 2.3.1 + * + * @param[in] advertiser The handle of advertiser + * @param[in] pkt_type The packet type + * @param[in] appearance The external appearance of device + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_QUOTA_EXCEEDED Quota exceeded + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * + * @see bt_adapter_le_clear_advertising_data() + */ +int bt_adapter_le_set_advertising_appearance(bt_advertiser_h advertiser, + bt_adapter_le_packet_type_e pkt_type, int appearance); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Add manufacturer specific data to advertise or scan response data. + * Please refer to the Bluetooth Assigned Numbers provided by the Bluetooth SIG for a list of existing company identifiers. + * The maximum advertised or responded data size is 31 bytes + * including data type and system wide data. + * @since_tizen 2.3.1 + * + * + * @param[in] advertiser The handle of advertiser + * @param[in] pkt_type The packet type + * @param[in] manufacturer_id Manufacturer identifier + * @param[in] manufacturer_data The manufacturer specific data + * @param[in] manufacturer_data_len The data length of manufacturer data + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_QUOTA_EXCEEDED Quota exceeded + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * + * @see bt_adapter_le_clear_advertising_data() + */ +int bt_adapter_le_add_advertising_manufacturer_data(bt_advertiser_h advertiser, + bt_adapter_le_packet_type_e pkt_type, int manufacturer_id, const char *manufacturer_data, int manufacturer_data_len); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Set whether the device name should be included in advertise or scan response data. + * The maximum advertised or responded data size is 31 bytes + * including data type and system wide data. + * @since_tizen 2.3.1 + * + * @param[in] advertiser The handle of advertiser + * @param[in] pkt_type The packet type + * @param[in] include_name Whether the device name should be included + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_QUOTA_EXCEEDED Quota exceeded + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * + * @see bt_adapter_le_clear_advertising_data() + */ +int bt_adapter_le_set_advertising_device_name(bt_advertiser_h advertiser, + bt_adapter_le_packet_type_e pkt_type, bool include_name); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Set whether the transmission power level should be included in advertise or scan response data. + * The maximum advertised or responded data size is 31 bytes + * including data type and system wide data. + * @since_tizen 2.3.1 + * + * @param[in] advertiser The handle of advertiser + * @param[in] pkt_type The packet type + * @param[in] include_tx_power Whether the transmission power level should be included + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_QUOTA_EXCEEDED Quota exceeded + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * + * @see bt_adapter_le_clear_advertising_data() + */ +int bt_adapter_le_set_advertising_tx_power_level(bt_advertiser_h advertiser, + bt_adapter_le_packet_type_e pkt_type, bool include_tx_power); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Clear all data to be advertised or responded to scan request from LE scanning device. + * @since_tizen 2.3.1 + * + * @param[in] advertiser The handle of advertiser + * @param[in] pkt_type The packet type to be cleared + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + */ +int bt_adapter_le_clear_advertising_data(bt_advertiser_h advertiser, bt_adapter_le_packet_type_e pkt_type); + + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Stops the advertising. + * @since_tizen 2.3.1 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * + * @param[in] advertiser The handle of advertiser + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_NOT_IN_PROGRESS Operation is not in progress + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The advertising must be going on with bt_adapter_le_start_advertising_new(). + * @post This function invokes bt_adapter_le_advertising_state_changed_cb(). + * + * @see bt_adapter_le_start_advertising_new() + * @see bt_adapter_le_advertising_state_changed_cb() + */ +int bt_adapter_le_stop_advertising(bt_advertiser_h advertiser); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Start advertising with passed advertiser and advertising parameters. + * @since_tizen 2.3.1 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * + * @details Once Bluetooth advertising is started, nearby Bluetooth LE(Low Energy) supported + * devices can know this device's existence. And one of them can make a connection reqeust, + * if it is allowed. + * + * @param[in] advertiser The handle of advertiser + * @param[in] cb The callback to report the result of this function + * @param[in] user_data The user data to be passed when callback is called + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_NOW_IN_PROGRESS Operation is now in progress + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @post This function invokes bt_adapter_le_advertising_state_changed_cb(). + * + * @see bt_adapter_le_stop_advertising() + * @see bt_adapter_le_advertising_state_changed_cb() + */ +int bt_adapter_le_start_advertising_new(bt_advertiser_h advertiser, bt_adapter_le_advertising_state_changed_cb cb, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Set advertising mode to control the advertising power and latency. + * @since_tizen 2.3.1 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * + * @param[in] advertiser The handle of advertiser + * @param[in] mode The mode of advertising + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_NOW_IN_PROGRESS Operation is now in progress + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * + * @see bt_adapter_le_start_advertising_new() + */ +int bt_adapter_le_set_advertising_mode(bt_advertiser_h advertiser, bt_adapter_le_advertising_mode_e mode); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Set whether the advertising type should be connectable or non-connectable + * @since_tizen 2.3.1 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * + * @param[in] advertiser The handle of advertiser + * @param[in] connectable The type of advertising + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_NOW_IN_PROGRESS Operation is now in progress + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * + * @see bt_adapter_le_start_advertising_new() + */ +int bt_adapter_le_set_advertising_connectable(bt_advertiser_h advertiser, bool connectable); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Sets the Privacy feature state of local Bluetooth adapter. + * @since_tizen 2.3.1 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * + * @param[in] enable_privacy The privacy feature to set/unset. + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * @pre The state of local Bluetooth must be #BT_ADAPTER_LE_ENABLED. + * + */ +int bt_adapter_le_enable_privacy(bool enable_privacy); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Creates a bond with a remote Bluetooth device, asynchronously. + * @since_tizen 2.3.1 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * + * @remarks A bond can be destroyed by bt_device_destroy_bond().\n + * The bonding request can be cancelled by bt_device_cancel_bonding(). + * + * @param[in] remote_address The address of the remote Bluetooth device with which the bond should be created + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_RESOURCE_BUSY Device or resource busy + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * @pre The remote device must be discoverable with bt_adapter_start_device_discovery(). + * @post This function invokes bt_device_bond_created_cb(). + * + * @see bt_adapter_start_device_discovery() + * @see bt_device_bond_created_cb() + * @see bt_device_cancel_bonding() + * @see bt_device_destroy_bond() + * @see bt_device_set_bond_created_cb() + * @see bt_device_unset_bond_created_cb() + */ +int bt_device_create_bond(const char *remote_address); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Creates a bond with a remote Bluetooth device, asynchronously. + * @since_tizen 2.3.1 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * + * @remarks A bond can be destroyed by bt_device_destroy_bond().\n + * The bonding request can be cancelled by bt_device_cancel_bonding(). + * + * @param[in] remote_address The address of the remote Bluetooth device with which the bond should be created + * @param[in] conn_type The connection type(LE or BREDR) to create bond with remote device + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_RESOURCE_BUSY Device or resource busy + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * @pre The remote device must be discoverable with bt_adapter_start_device_discovery(). + * @post This function invokes bt_device_bond_created_cb(). + * + * @see bt_adapter_start_device_discovery() + * @see bt_device_create_bond() + * @see bt_device_bond_created_cb() + * @see bt_device_cancel_bonding() + * @see bt_device_destroy_bond() + * @see bt_device_set_bond_created_cb() + * @see bt_device_unset_bond_created_cb() + */ +int bt_device_create_bond_by_type(const char *remote_address, + bt_device_connection_link_type_e conn_type); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Cancels the bonding process. + * @since_tizen 2.3.1 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * + * @remarks Use this function when the remote Bluetooth device is not responding to the + * bond request or you wish to cancel the bonding request. + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_NOT_IN_PROGRESS Operation not in progress + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The creating a bond must be in progress by bt_device_create_bond(). + * + * @see bt_device_create_bond() + * @see bt_device_bond_created_cb() + * @see bt_device_set_bond_created_cb() + * @see bt_device_unset_bond_created_cb() + */ +int bt_device_cancel_bonding(void); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Destroys the bond, asynchronously. + * @since_tizen 2.3.1 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * + * @param[in] remote_address The address of the remote Bluetooth device to remove bonding + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_RESOURCE_BUSY Device or resource busy + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_BONDED Remote device not bonded + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * @pre The bond with the remote device must be created with bt_device_create_bond(). + * @post This function invokes bt_device_bond_destroyed_cb(). + * + * @see bt_device_create_bond() + * @see bt_device_bond_destroyed_cb() + * @see bt_device_set_bond_destroyed_cb() + * @see bt_device_unset_bond_destroyed_cb() + */ +int bt_device_destroy_bond(const char *remote_address); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Sets an alias for the bonded device. + * @since_tizen 2.3.1 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * + * @param[in] remote_address The address of the remote Bluetooth device + * @param[in] alias The alias of the remote Bluetooth device + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_BONDED Remote device not bonded + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * @pre The bond with the remote device must be created with bt_device_create_bond(). + * + * @see bt_device_create_bond() + */ +int bt_device_set_alias(const char *remote_address, const char *alias); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Sets the authorization of a bonded device, asynchronously. + * @since_tizen 2.3.1 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * + * @remarks Once a device is authorized, you don't need to receive a confirmation. + * + * @param[in] remote_address The address of the remote Bluetooth device to authorize + * @param[in] authorization_state The Bluetooth authorization state + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_BONDED Remote device not bonded + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * @pre The bond with the remote device must be created with bt_device_create_bond(). + * @post bt_device_authorization_changed_cb() will be invoked. + * + * @see bt_device_create_bond() + * @see bt_device_authorization_changed_cb() + * @see bt_device_set_authorization_changed_cb() + * @see bt_device_unset_authorization_changed_cb() + */ +int bt_device_set_authorization(const char *remote_address, bt_device_authorization_e authorization_state); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Starts the search for services supported by the specified device, asynchronously. + * @since_tizen 2.3.1 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * + * @remarks If creating a bond succeeds, which means bt_device_bond_created_cb() is called with result #BT_ERROR_NONE, + * then you don't need to run this function.\n + * The service search takes a couple of seconds to complete normally. \n + * + * @param[in] remote_address The address of the remote Bluetooth device whose services need to be checked + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_BONDED Remote device not bonded + * @retval #BT_ERROR_SERVICE_SEARCH_FAILED Service search failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * @pre The remote device must be discoverable with bt_adapter_start_device_discovery(). + * @pre The bond with the remote device must be created with bt_device_create_bond(). + * @post This function invokes bt_device_service_searched_cb(). + * + * @see bt_adapter_start_device_discovery() + * @see bt_device_create_bond() + * @see bt_device_bond_created_cb() + * @see bt_device_service_searched_cb() + * @see bt_device_set_service_searched_cb() + * @see bt_device_unset_service_searched_cb() + */ +int bt_device_start_service_search(const char *remote_address); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Cancels service search process. + * @since_tizen 2.3.1 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_BONDED Remote device not bonded + * @retval #BT_ERROR_NOT_IN_PROGRESS Operation not in progress + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The service search must be in progress by bt_device_start_service_search(). + * + * @see bt_device_start_service_search() + * @see bt_device_service_searched_cb() + * @see bt_device_set_service_searched_cb() + * @see bt_device_unset_service_searched_cb() + */ +int bt_device_cancel_service_search(void); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Gets the connected profiles. + * @since_tizen 2.3.1 + * @param[in] remote_address The address of the remote device + * @param[in] callback The callback function to invoke + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * @post bt_device_connected_profile() will be invoked. + * @see bt_device_connected_profile() + */ +int bt_device_foreach_connected_profiles(const char *remote_address, bt_device_connected_profile callback, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Gets the profile connected status. + * @since_tizen 2.3.1 + * @param[in] remote_address The address of the remote device + * @param[in] bt_profile wish to know bt_profile + * @param[out] connected_status the connected status + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_BONDED Remote device not bonded + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + */ +int bt_device_is_profile_connected(const char *remote_address, bt_profile_e bt_profile, + bool *connected_status); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Registers a callback function to be invoked when the bond creates. + * @since_tizen 2.3.1 + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @post bt_device_bond_created_cb() will be invoked. + * @see bt_initialize() + * @see bt_device_bond_created_cb() + * @see bt_device_unset_bond_created_cb() + */ +int bt_device_set_bond_created_cb(bt_device_bond_created_cb callback, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Unregisters the callback function. + * @since_tizen 2.3.1 + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @see bt_initialize() + * @see bt_device_set_bond_created_cb() + */ +int bt_device_unset_bond_created_cb(void); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Registers a callback function to be invoked when the bond destroys. + * @since_tizen 2.3.1 + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @post bt_device_bond_destroyed_cb() will be invoked. + * @see bt_initialize() + * @see bt_device_bond_destroyed_cb() + * @see bt_device_unset_bond_destroyed_cb() + */ +int bt_device_set_bond_destroyed_cb(bt_device_bond_destroyed_cb callback, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Unregisters the callback function. + * @since_tizen 2.3.1 + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @see bt_initialize() + * @see bt_device_set_bond_destroyed_cb() + */ +int bt_device_unset_bond_destroyed_cb(void); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Registers a callback function to be invoked when the authorization of device changes. + * @since_tizen 2.3.1 + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @post bt_device_authorization_changed_cb() will be invoked. + * @see bt_initialize() + * @see bt_device_authorization_changed_cb() + * @see bt_device_set_authorization_changed_cb() + * @see bt_device_unset_authorization_changed_cb() + */ +int bt_device_set_authorization_changed_cb(bt_device_authorization_changed_cb callback, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Unregisters the callback function. + * @since_tizen 2.3.1 + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @see bt_initialize() + * @see bt_device_set_authorization_changed_cb() + */ +int bt_device_unset_authorization_changed_cb(void); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Registers a callback function to be invoked when the process of service search finishes. + * @since_tizen 2.3.1 + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @post bt_device_service_searched_cb() will be invoked. + * @see bt_initialize() + * @see bt_device_service_searched_cb() + * @see bt_device_unset_service_searched_cb() + */ +int bt_device_set_service_searched_cb(bt_device_service_searched_cb callback, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Unregisters the callback function. + * @since_tizen 2.3.1 + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @see bt_initialize() + * @see bt_device_set_service_searched_cb() + */ +int bt_device_unset_service_searched_cb(void); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Registers a callback function to be invoked when the connection state is changed. + * @since_tizen 2.3.1 + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @post bt_device_connection_state_changed_cb() will be invoked. + * @see bt_initialize() + * @see bt_device_connection_state_changed_cb() + * @see bt_device_unset_connection_state_changed_cb() + */ +int bt_device_set_connection_state_changed_cb(bt_device_connection_state_changed_cb callback, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Unregisters the callback function to be invoked when the connection state is changed. + * @since_tizen 2.3.1 + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @see bt_initialize() + * @see bt_device_set_connection_state_changed_cb() + */ +int bt_device_unset_connection_state_changed_cb(void); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE + * @brief Registers a rfcomm server socket with a specific UUID. + * @since_tizen 2.3.1 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * + * @remarks A socket can be destroyed by bt_socket_destroy_rfcomm(). + * + * @param[in] service_uuid The UUID of service to provide + * @param[out] socket_fd The file descriptor of socket to listen + * @return 0 on success, otherwise a negative error value. + * + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * + * @see bt_socket_listen_and_accept_rfcomm() + * @see bt_socket_destroy_rfcomm() + */ +int bt_socket_create_rfcomm(const char *service_uuid, int *socket_fd); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE + * @brief Removes the rfcomm server socket which was created using bt_socket_create_rfcomm(). + * @since_tizen 2.3.1 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * @remarks If callback function bt_socket_connection_state_changed_cb() is set and the remote Bluetooth device is connected, + * then bt_socket_connection_state_changed_cb() will be called when this function is finished successfully. + * + * @param[in] socket_fd The file descriptor of socket (which was created using bt_socket_create_rfcomm()) to destroy + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The socket must be created with bt_socket_create_rfcomm(). + * @post If callback function bt_socket_connection_state_changed_cb() is set and the remote Bluetooth device is connected, + * then bt_socket_connection_state_changed_cb() will be called. + * @see bt_socket_create_rfcomm() + * @see bt_socket_connection_state_changed_cb() + * @see bt_socket_set_connection_state_changed_cb() + * @see bt_socket_unset_connection_state_changed_cb() + */ +int bt_socket_destroy_rfcomm(int socket_fd); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE + * @brief Starts listening on passed rfcomm socket and accepts connection requests. + * @since_tizen 2.3.1 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * @details Pop-up is shown automatically when a RFCOMM connection is requested. + * bt_socket_connection_state_changed_cb() will be called with + * #BT_SOCKET_CONNECTED if you click "yes" and connection is finished successfully. + * @param[in] socket_fd The file descriptor of socket on which start to listen + * @param[in] max_pending_connections The maximum number of pending connections + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The socket must be created with bt_socket_create_rfcomm(). + * @post If callback function bt_socket_connection_state_changed_cb() is set, + * then bt_socket_connection_state_changed_cb() will be called when the remote Bluetooth device is connected. + * @see bt_socket_create_rfcomm() + * @see bt_socket_connection_state_changed_cb() + * @see bt_socket_set_connection_state_changed_cb() + * @see bt_socket_unset_connection_state_changed_cb() + */ +int bt_socket_listen_and_accept_rfcomm(int socket_fd, int max_pending_connections); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE + * @brief Starts listening on passed rfcomm socket. + * @since_tizen 2.3.1 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @details bt_socket_connection_requested_cb() will be called when a RFCOMM connection is requested. + * + * @param[in] socket_fd The file descriptor socket on which start to listen + * @param[in] max_pending_connections The number of pending connections + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The socket must be created with bt_socket_create_rfcomm(). + * @post This function invokes bt_socket_connection_state_changed_cb(). + * + * @see bt_socket_create_rfcomm() + * @see bt_socket_set_connection_requested_cb() + * @see bt_socket_unset_connection_requested_cb() + * @see bt_socket_connection_requested_cb() + */ +int bt_socket_listen(int socket_fd, int max_pending_connections); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE + * @brief Accepts a connection request. + * @since_tizen 2.3.1 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @param[in] requested_socket_fd The file descriptor of socket on which a connection is requested + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The connection is requested by bt_socket_connection_requested_cb(). + * @see bt_socket_create_rfcomm() + * @see bt_socket_connection_requested_cb() + * @see bt_socket_listen() + * @see bt_socket_reject() +*/ +int bt_socket_accept(int requested_socket_fd); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE + * @brief Rejects a connection request. + * @since_tizen 2.3.1 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @param[in] socket_fd The file descriptor of socket on which a connection is requested + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The connection is requested by bt_socket_connection_requested_cb(). + * @see bt_socket_create_rfcomm() + * @see bt_socket_connection_requested_cb() + * @see bt_socket_listen() + * @see bt_socket_accept() + */ +int bt_socket_reject(int socket_fd); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE + * @brief Connects to a specific RFCOMM based service on a remote Bluetooth device UUID, asynchronously. + * @since_tizen 2.3.1 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * + * @remarks A connection can be disconnected by bt_socket_disconnect_rfcomm(). + * + * @param[in] remote_address The address of the remote Bluetooth device + * @param[in] service_uuid The UUID of service provided by the remote Bluetooth device + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * @pre The remote device must be discoverable with bt_adapter_start_device_discovery(). + * @pre The bond with the remote device must be created with bt_device_create_bond(). + * @post This function invokes bt_socket_connection_state_changed_cb(). + * + * @see bt_device_create_bond() + * @see bt_adapter_start_device_discovery() + * @see bt_device_start_service_search() + * @see bt_socket_disconnect_rfcomm() + * @see bt_socket_connection_state_changed_cb() + * @see bt_socket_set_connection_state_changed_cb() + * @see bt_socket_unset_connection_state_changed_cb() + */ +int bt_socket_connect_rfcomm(const char *remote_address, const char *service_uuid); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE + * @brief Disconnects the RFCOMM connection with the given file descriptor of conneted socket. + * @since_tizen 2.3.1 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * @param[in] socket_fd The file descriptor of socket to close which was received using bt_socket_connection_state_changed_cb(). + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The connection must be established. + * + * @see bt_socket_connection_state_changed_cb() + * @see bt_socket_set_connection_state_changed_cb() + * @see bt_socket_unset_connection_state_changed_cb() + */ +int bt_socket_disconnect_rfcomm(int socket_fd); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE + * @brief Sends data to the connected device. + * @since_tizen 2.3.1 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * @remark The specific error code can be obtained using the get_last_result() method. Error codes are described in Exception section. + * + * @param[in] socket_fd The file descriptor of connected socket which was received using bt_socket_connection_state_changed_cb() + * @param[in] data The data to be sent + * @param[in] length The length of data to be sent + * + * @return the number of bytes written (zero indicates nothing was written). + * @retval On error, -1 is returned, and errno is set appropriately. See write 2 man page. + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * @exception BT_ERROR_PERMISSION_DENIED Permission denied + * @exception BT_ERROR_AGAIN Resource temporarily unavailable + * + * @pre The connection must be established. + * + * @see bt_socket_connection_state_changed_cb() + * @see bt_socket_set_connection_state_changed_cb() + * @see bt_socket_unset_connection_state_changed_cb() + */ +int bt_socket_send_data(int socket_fd, const char *data, int length); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE + * @brief Register a callback function that will be invoked when you receive data. + * @since_tizen 2.3.1 + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @post bt_socket_data_received_cb() will be invoked. + * @see bt_initialize() + * @see bt_socket_data_received_cb() + * @see bt_socket_set_data_received_cb() + * @see bt_socket_unset_data_received_cb() + */ +int bt_socket_set_data_received_cb(bt_socket_data_received_cb callback, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE + * @brief Unregisters the callback function. + * @since_tizen 2.3.1 + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @see bt_initialize() + * @see bt_socket_data_received_cb() + * @see bt_socket_set_data_received_cb() + */ +int bt_socket_unset_data_received_cb(void); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE + * @brief Register a callback function that will be invoked when a RFCOMM connection is requested. + * @since_tizen 2.3.1 + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @post If you listen and accept a socket by bt_socket_listen_and_accept_rfcomm(), + bt_socket_connection_requested_cb() will be invoked. + * @see bt_initialize() + * @see bt_socket_unset_connection_requested_cb() + */ +int bt_socket_set_connection_requested_cb(bt_socket_connection_requested_cb callback, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE + * @brief Unregisters the callback function. + * @since_tizen 2.3.1 + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @see bt_initialize() + * @see bt_socket_set_connection_requested_cb() + * @see bt_socket_connection_requested_cb() + */ +int bt_socket_unset_connection_requested_cb(void); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE + * @brief Register a callback function that will be invoked when the connection state changes. + * @since_tizen 2.3.1 + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @post bt_socket_connection_state_changed_cb() will be invoked. + * @see bt_initialize() + * @see bt_socket_connection_state_changed_cb() + * @see bt_socket_unset_connection_state_changed_cb() + */ +int bt_socket_set_connection_state_changed_cb(bt_socket_connection_state_changed_cb callback, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE + * @brief Unregisters the callback function. + * @since_tizen 2.3.1 + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @see bt_initialize() + * @see bt_socket_connection_state_changed_cb() + * @see bt_socket_set_connection_state_changed_cb() + */ +int bt_socket_unset_connection_state_changed_cb(void); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_OPP_SERVER_MODULE + * @brief Initializes the Bluetooth OPP server requested by bt_opp_server_push_requested_cb(). + * @since_tizen 2.3.1 + * @details The popup appears when an OPP connection is requested from a remote device. + * If you accept the request, then connection will be established and bt_opp_server_push_requested_cb() will be called. + * At that time, you can call either bt_opp_server_accept() or bt_opp_server_reject(). + * @remarks This function must be called to start Bluetooth OPP server. You must free all resources of the Bluetooth service + * by calling bt_opp_server_deinitialize() if Bluetooth OPP service is no longer needed. + * @param[in] destination The destination path + * @param[in] push_requested_cb The callback called when a push is requested + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_RESOURCE_BUSY Device or resource busy + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_opp_server_push_requested_cb() + * @see bt_opp_server_deinitialize() + * @see bt_opp_server_accept() + * @see bt_opp_server_reject() + */ +int bt_opp_server_initialize(const char *destination, bt_opp_server_push_requested_cb push_requested_cb, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_OPP_SERVER_MODULE + * @brief Initializes the Bluetooth OPP server requested by bt_opp_server_connection_requested_cb(). + * @since_tizen 2.3.1 + * @details No popup appears when an OPP connection is requested from a remote device. + * Instead, @a connection_requested_cb() will be called. + * At that time, you can call either bt_opp_server_accept() or bt_opp_server_reject(). + * @remarks This function must be called to start Bluetooth OPP server. \n + * You must free all resources of the Bluetooth service by calling bt_opp_server_deinitialize() if Bluetooth OPP service is no longer needed. + * @param[in] destination The destination path + * @param[in] connection_requested_cb The callback called when an OPP connection is requested + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_RESOURCE_BUSY Device or resource busy + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_opp_server_connection_requested_cb() + * @see bt_opp_server_deinitialize() + * @see bt_opp_server_accept() + * @see bt_opp_server_reject() + */ +int bt_opp_server_initialize_by_connection_request(const char *destination, bt_opp_server_connection_requested_cb connection_requested_cb, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_OPP_SERVER_MODULE + * @brief Denitializes the Bluetooth OPP server. + * @since_tizen 2.3.1 + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_opp_server_deinitialize() + */ +int bt_opp_server_deinitialize(void); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_OPP_SERVER_MODULE + * @brief Accepts the push request from the remote device. + * @since_tizen 2.3.1 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * @remarks If you initialize OPP server by bt_opp_server_initialize_by_connection_request(), then name is ignored. + * You can cancel the pushes by bt_opp_server_cancel_transfer() with transfer_id. + * @param[in] progress_cb The callback called when a file is being transfered + * @param[in] finished_cb The callback called when a transfer is finished + * @param[in] name The name to store. This can be NULL if you initialize OPP server by bt_opp_server_initialize_by_connection_request(). + * @param[in] user_data The user data to be passed to the callback function + * @param[out] transfer_id The ID of transfer + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_NOW_IN_PROGRESS Operation now in progress + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_opp_server_reject() + */ +int bt_opp_server_accept(bt_opp_server_transfer_progress_cb progress_cb, bt_opp_server_transfer_finished_cb finished_cb, const char *name, + void *user_data, int *transfer_id); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_OPP_SERVER_MODULE + * @brief Rejects the push request from the remote device. + * @since_tizen 2.3.1 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_opp_server_accept() + */ +int bt_opp_server_reject(void); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_OPP_SERVER_MODULE + * @brief Cancels the transfer. + * @since_tizen 2.3.1 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * @param[in] transfer_id The ID of transfer + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_opp_server_accept() + */ +int bt_opp_server_cancel_transfer(int transfer_id); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_OPP_SERVER_MODULE + * @brief Sets the destination path of file to be pushed. + * @since_tizen 2.3.1 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * @param[in] destination The destination path of file to be pushed + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + */ +int bt_opp_server_set_destination(const char *destination); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_OPP_CLIENT_MODULE + * @brief Initializes the Bluetooth OPP client. + * @since_tizen 2.3.1 + * @remarks This function must be called before Bluetooth OPP client starts. \n + * You must free all resources of the Bluetooth service by calling bt_opp_client_deinitialize() + * if Bluetooth OPP service is no longer needed. + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_RESOURCE_BUSY Device or resource busy + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_opp_client_deinitialize() + */ +int bt_opp_client_initialize(void); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_OPP_CLIENT_MODULE + * @brief Denitializes the Bluetooth OPP client. + * @since_tizen 2.3.1 + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_opp_client_initialize() + */ +int bt_opp_client_deinitialize(void); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_OPP_CLIENT_MODULE + * @brief Adds file to be pushed. + * @since_tizen 2.3.1 + * @param[in] file The path of file to be pushed + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_opp_client_clear_files() + * @see bt_opp_client_push_files() + */ +int bt_opp_client_add_file(const char *file); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_OPP_CLIENT_MODULE + * @brief Adds file to be pushed. + * @since_tizen 2.3.1 + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_opp_client_add_file() + * @see bt_opp_client_push_files() + */ +int bt_opp_client_clear_files(void); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_OPP_CLIENT_MODULE + * @brief Pushes the file to the remote device, asynchronously. + * @since_tizen 2.3.1 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * @details At first, bt_opp_client_push_responded_cb() will be called when OPP server responds to the push request. + * After connection is established, bt_opp_client_push_progress_cb() will be called repeatedly until a file is tranfered completely. + * If you send several files, then bt_opp_client_push_progress_cb() with another file will be called repeatedly until the file is tranfered completely. + * bt_opp_client_push_finished_cb() will be called when the push request is finished. + * @param[in] remote_address The remote address + * @param[in] responded_cb The callback called when OPP server responds to the push request + * @param[in] progress_cb The callback called when each file is being transfered + * @param[in] finished_cb The callback called when the push request is finished + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_NOW_IN_PROGRESS Operation now in progress + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_opp_client_initialize() + * @see bt_opp_client_cancel_push + */ +int bt_opp_client_push_files(const char *remote_address, bt_opp_client_push_responded_cb responded_cb, + bt_opp_client_push_progress_cb progress_cb, bt_opp_client_push_finished_cb finished_cb, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_OPP_CLIENT_MODULE + * @brief Cancels the push request in progress, asynchronously. + * @since_tizen 2.3.1 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre bt_opp_client_push_files() must be called. + * @post bt_opp_client_push_finished_cb() will be invoked with result #BT_ERROR_CANCELLED, + * which is a parameter of bt_opp_client_push_files(). + * @see bt_opp_client_initialize() + * @see bt_opp_client_push_files() + */ +int bt_opp_client_cancel_push(void); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_HID_MODULE + * @brief Initializes the Bluetooth HID(Human Interface Device) Host. + * @since_tizen 2.3.1 + * @remarks This function must be called before Bluetooth HID Host starts. \n + * You must free all resources of the Bluetooth service by calling bt_hid_host_deinitialize() + * if Bluetooth HID Host service is no longer needed. + * @param[in] connection_cb The callback called when the connection state is changed + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @see bt_initialize() + * @see bt_hid_host_deinitialize() + */ +int bt_hid_host_initialize(bt_hid_host_connection_state_changed_cb connection_cb, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_HID_MODULE + * @brief Deinitializes the Bluetooth HID(Human Interface Device) Host. + * @since_tizen 2.3.1 + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth HID service must be initialized with bt_hid_host_initialize(). + * @see bt_hid_host_initialize() + */ +int bt_hid_host_deinitialize(void); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_HID_MODULE + * @brief Connects the remote device with the HID(Human Interface Device) service, asynchronously. + * @since_tizen 2.3.1 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * @param[in] remote_address The remote address + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The local device must be bonded with the remote device by bt_device_create_bond(). + * @pre The Bluetooth HID service must be initialized with bt_hid_host_initialize(). + * @post bt_hid_host_connection_state_changed_cb() will be invoked. + * @see bt_hid_host_disconnect() + * @see bt_hid_host_connection_state_changed_cb() + */ +int bt_hid_host_connect(const char *remote_address); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_HID_MODULE + * @brief Disconnects the remote device with the HID(Human Interface Device) service, asynchronously. + * @since_tizen 2.3.1 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * @param[in] remote_address The remote address + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The remote device must be connected by bt_hid_host_connect(). + * @post bt_hid_host_connection_state_changed_cb() will be invoked. + * @see bt_hid_host_connect() + * @see bt_hid_host_connection_state_changed_cb() + */ +int bt_hid_host_disconnect(const char *remote_address); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_MODULE + * @brief Initializes the Bluetooth profiles related with audio. + * @since_tizen 2.3.1 + * @remarks This function must be called before Bluetooth profiles related with audio starts. \n + * You must free all resources of the this service by calling bt_audio_deinitialize() + * if Bluetooth profiles related with audio service is no longer needed. + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @see bt_initialize() + * @see bt_audio_deinitialize() + */ +int bt_audio_initialize(void); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_MODULE + * @brief Deinitializes the Bluetooth profiles related with audio. + * @since_tizen 2.3.1 + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth audio service must be initialized with bt_audio_initialize(). + * @see bt_audio_initialize() + */ +int bt_audio_deinitialize(void); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_MODULE + * @brief Connects the remote device with the given audio profile, asynchronously. + * @since_tizen 2.3.1 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * @details If you input type as #BT_AUDIO_PROFILE_TYPE_ALL and connection request succeeds, then bt_audio_connection_state_changed_cb() will be called twice + * when #BT_AUDIO_PROFILE_TYPE_HSP_HFP is connected and #BT_AUDIO_PROFILE_TYPE_A2DP is connected. + * @param[in] remote_address The remote address + * @param[in] type The type of audio profile + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + + * @pre The Bluetooth audio service must be initialized with bt_audio_initialize(). + * @pre The local device must be bonded with the remote device by bt_device_create_bond(). + * @post bt_audio_connection_state_changed_cb() will be invoked. + * @see bt_audio_disconnect() + * @see bt_audio_connection_state_changed_cb() + */ +int bt_audio_connect(const char *remote_address, bt_audio_profile_type_e type); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_MODULE + * @brief Disconnects the remote device with the given audio profile, asynchronously. + * @since_tizen 2.3.1 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * @details If you input type as #BT_AUDIO_PROFILE_TYPE_ALL and disconnection request succeeds, then bt_audio_connection_state_changed_cb() will be called twice + * when #BT_AUDIO_PROFILE_TYPE_HSP_HFP is disconnected and #BT_AUDIO_PROFILE_TYPE_A2DP is disconnected. + * @param[in] remote_address The remote address + * @param[in] type The type of audio profile + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The remote device must be connected by bt_audio_connect(). + * @post bt_audio_connection_state_changed_cb() will be invoked. + * @see bt_audio_connect() + * @see bt_audio_connection_state_changed_cb() + */ +int bt_audio_disconnect(const char *remote_address, bt_audio_profile_type_e type); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_MODULE + * @brief Registers a callback function that will be invoked when the connection state is changed. + * @since_tizen 2.3.1 + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth audio service must be initialized with bt_audio_initialize(). + * @see bt_audio_initialize() + * @see bt_audio_connection_state_changed_cb() + */ +int bt_audio_set_connection_state_changed_cb(bt_audio_connection_state_changed_cb callback, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_MODULE + * @brief Unregisters a callback function that will be invoked when the connection state is changed. + * @since_tizen 2.3.1 + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth audio service must be initialized with bt_audio_initialize(). + * @see bt_audio_initialize() + * @see bt_audio_connection_state_changed_cb() + * @see bt_audio_set_connection_state_changed_cb() + */ +int bt_audio_unset_connection_state_changed_cb(void); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Opens a SCO(Synchronous Connection Oriented link) to connected remote device, asynchronously. + * @since_tizen 2.3.1 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected + * @retval #BT_ERROR_ALREADY_DONE Operation is already done + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth audio device must be connected with bt_audio_connect(). + * @post bt_ag_sco_state_changed_cb() will be invoked. + * @see bt_ag_close_sco() + * @see bt_ag_sco_state_changed_cb() + * @see bt_audio_connect() + */ +int bt_ag_open_sco(void); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Closes an opened SCO(Synchronous Connection Oriented link), asynchronously. + * @since_tizen 2.3.1 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The SCO must be opened with bt_ag_open_sco(). + * @post bt_ag_sco_state_changed_cb() will be invoked. + * @see bt_ag_open_sco() + * @see bt_ag_sco_state_changed_cb() + */ +int bt_ag_close_sco(void); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Checks whether an opened SCO(Synchronous Connection Oriented link) exists or not. + * @since_tizen 2.3.1 + * @param[out] opened The SCO status: (@c true = opened, @c false = not opened) + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth audio service must be initialized with bt_audio_initialize(). + * @see bt_ag_open_sco() + * @see bt_ag_close_sco() + */ +int bt_ag_is_sco_opened(bool *opened); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Registers a callback function that will be invoked when the SCO(Synchronous Connection Oriented link) state is changed. + * @since_tizen 2.3.1 + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth audio service must be initialized with bt_audio_initialize(). + * @see bt_audio_initialize() + * @see bt_ag_sco_state_changed_cb() + * @see bt_ag_unset_sco_state_changed_cb() + */ +int bt_ag_set_sco_state_changed_cb(bt_ag_sco_state_changed_cb callback, void *user_data); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Unregisters a callback function that will be invoked when the SCO(Synchronous Connection Oriented link) state is changed. + * @since_tizen 2.3.1 + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth audio service must be initialized with bt_audio_initialize(). + * @see bt_audio_initialize() + * @see bt_ag_sco_state_changed_cb() + * @see bt_ag_set_sco_state_changed_cb() + */ +int bt_ag_unset_sco_state_changed_cb(void); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Notifies the call event to the remote bluetooth device. + * @since_tizen 2.3.1 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @remarks Before notifying #BT_AG_CALL_EVENT_ANSWERED or #BT_AG_CALL_EVENT_DIALING, you should open SCO(Synchronous Connection Oriented link) + * if Bluetooth Hands-Free need SCO connection. + * @param[in] event The call event + * @param[in] call_id The call ID + * @param[in] phone_number The phone number. You must set this value in case of #BT_AG_CALL_EVENT_DIALING and #BT_AG_CALL_EVENT_INCOMING. + * In other cases, this value can be NULL. + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth audio device must be connected with bt_audio_connect(). + * @see bt_audio_connect() + */ +int bt_ag_notify_call_event(bt_ag_call_event_e event, unsigned int call_id, const char *phone_number); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Notifies the call list to the remote bluetooth device. + * @since_tizen 2.3.1 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @param[in] list The call list + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth audio device must be connected with bt_audio_connect(). + * @see bt_audio_connect() + */ +int bt_ag_notify_call_list(bt_call_list_h list); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Notifies the state of voice recognition. + * @since_tizen 2.3.1 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @param[in] state The state of voice recognition: (@c true = enabled, @c false = disabled) + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth audio device must be connected with bt_audio_connect(). + * @see bt_audio_connect() + */ +int bt_ag_notify_voice_recognition_state(bool state); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Registers a callback function that will be invoked when a call handling event happened from Hands-Free. + * @since_tizen 2.3.1 + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth audio service must be initialized with bt_audio_initialize(). + * @see bt_audio_initialize() + * @see bt_ag_call_handling_event_cb() + * @see bt_ag_unset_call_handling_event_cb() + */ +int bt_ag_set_call_handling_event_cb(bt_ag_call_handling_event_cb callback, void *user_data); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Unregisters a callback function that will be invoked when a call handling event happened from Hands-Free. + * @since_tizen 2.3.1 + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth audio service must be initialized with bt_audio_initialize(). + * @see bt_audio_initialize() + * @see bt_ag_call_handling_event_cb() + * @see bt_ag_set_call_handling_event_cb() + */ +int bt_ag_unset_call_handling_event_cb(void); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Registers a callback function that will be invoked when a multi call handling event happened from Hands-Free. + * @since_tizen 2.3.1 + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth audio service must be initialized with bt_audio_initialize(). + * @see bt_audio_initialize() + * @see bt_ag_multi_call_handling_event_cb() + * @see bt_ag_unset_multi_call_handling_event_cb() + */ +int bt_ag_set_multi_call_handling_event_cb(bt_ag_multi_call_handling_event_cb callback, void *user_data); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Unregisters a callback function that will be invoked when a multi call handling event happened from Hands-Free. + * @since_tizen 2.3.1 + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth audio service must be initialized with bt_audio_initialize(). + * @see bt_audio_initialize() + * @see bt_ag_multi_call_handling_event_cb() + * @see bt_ag_set_multi_call_handling_event_cb() + */ +int bt_ag_unset_multi_call_handling_event_cb(void); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Registers a callback function that will be invoked when a DTMF(Dual Tone Multi Frequency) is transmitted from Hands-Free. + * @since_tizen 2.3.1 + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth audio service must be initialized with bt_audio_initialize(). + * @see bt_audio_initialize() + * @see bt_ag_dtmf_transmitted_cb() + * @see bt_ag_unset_dtmf_transmitted_cb() + */ +int bt_ag_set_dtmf_transmitted_cb(bt_ag_dtmf_transmitted_cb callback, void *user_data); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Unregisters a callback function that will be invoked when a DTMF(Dual Tone Multi Frequency) is transmitted from Hands-Free. + * @since_tizen 2.3.1 + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth audio service must be initialized with bt_audio_initialize(). + * @see bt_audio_initialize() + * @see bt_ag_dtmf_transmitted_cb() + * @see bt_ag_set_dtmf_transmitted_cb() + */ +int bt_ag_unset_dtmf_transmitted_cb(void); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Notifies the speaker gain to the remote device. + * @since_tizen 2.3.1 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @details This function sends a signal to the remote device. This signal has the gain value. + * @a gain is represented on a scale from 0 to 15. This value is absolute value relating to a particular volume level. + * When the speaker gain of remote device is changed to the requested gain, bt_audio_speaker_gain_changed_cb() will be called. + * @param[in] gain The gain of speaker (0 ~ 15) + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The remote device is connected by bt_audio_connect() with #BT_AUDIO_PROFILE_TYPE_HSP_HFP service. + * @see bt_ag_get_speaker_gain() + * @see bt_ag_set_speaker_gain_changed_cb() + * @see bt_ag_unset_speaker_gain_changed_cb() + */ +int bt_ag_notify_speaker_gain(int gain); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Gets the current speaker gain of the remote device. + * @since_tizen 2.3.1 + * @details This function gets the value of speaker gain of the remote device. + * @a gain is represented on a scale from 0 to 15. This value is absolute value relating to a particular volume level. + * @param[out] gain The gain of speaker (0 ~ 15) + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The remote device is connected by bt_audio_connect() with #BT_AUDIO_PROFILE_TYPE_HSP_HFP service. + * @see bt_ag_notify_speaker_gain() + * @see bt_ag_set_speaker_gain_changed_cb() + * @see bt_ag_unset_speaker_gain_changed_cb() + */ +int bt_ag_get_speaker_gain(int *gain); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Checks whether the remoted device enables NREC(Noise Reduction and Echo Canceling) or not. + * @since_tizen 2.3.1 + * @param[out] enabled The NREC status: (@c true = enabled, @c false = not enabled) + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The remote device is connected by bt_audio_connect() with #BT_AUDIO_PROFILE_TYPE_HSP_HFP service. + * @see bt_audio_connect() + */ +int bt_ag_is_nrec_enabled(bool *enabled); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Registers a callback function that will be invoked when the speaker gain of the remote device is changed. + * @since_tizen 2.3.1 + * @details This function let you know the change of the speaker gain of the remote device. + * @a gain is represented on a scale from 0 to 15. This value is absolute value relating to a particular volume level. + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth audio service must be initialized with bt_audio_initialize(). + * @see bt_audio_initialize() + * @see bt_ag_unset_speaker_gain_changed_cb() + */ +int bt_ag_set_speaker_gain_changed_cb(bt_ag_speaker_gain_changed_cb callback, void *user_data); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Unregisters a callback function that will be invoked when the speaker gain of the remote device is changed. + * @since_tizen 2.3.1 + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth audio service must be initialized with bt_audio_initialize(). + * @see bt_audio_initialize() + * @see bt_ag_set_speaker_gain_changed_cb() + */ +int bt_ag_unset_speaker_gain_changed_cb(void); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Registers a callback function that will be invoked when the microphone gain of the remote device is changed. + * @since_tizen 2.3.1 + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth audio service must be initialized with bt_audio_initialize(). + * @see bt_audio_initialize() + * @see bt_ag_unset_microphone_gain_changed_cb() + */ +int bt_ag_set_microphone_gain_changed_cb(bt_ag_microphone_gain_changed_cb callback, void *user_data); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Unregisters a callback function that will be invoked when the microphone gain of the remote device is changed. + * @since_tizen 2.3.1 + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth audio service must be initialized with bt_audio_initialize(). + * @see bt_audio_initialize() + * @see bt_ag_set_microphone_gain_changed_cb() + */ +int bt_ag_unset_microphone_gain_changed_cb(void); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_CALL_MODULE + * @brief Creates a handle of call list. + * @since_tizen 2.3.1 + * @param[out] list The handle of call list + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_OUT_OF_MEMORY Out of memory + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_call_list_destroy() + */ +int bt_call_list_create(bt_call_list_h *list); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_CALL_MODULE + * @brief Destroys the handle of call list. + * @since_tizen 2.3.1 + * @param[in] list The handle of call list + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_call_list_create() + */ +int bt_call_list_destroy(bt_call_list_h list); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_CALL_MODULE + * @brief Resets the handle of call list. + * @since_tizen 2.3.1 + * @param[in] list The handle of call list + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_call_list_create() + */ +int bt_call_list_reset(bt_call_list_h list); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_CALL_MODULE + * @brief Adds a call to the handle of call list. + * @since_tizen 2.3.1 + * @param[in] list The handle of call list + * @param[in] call_id The call ID + * @param[in] state The state of audio gate call + * @param[in] phone_number The phone number. You must set this value in case of #BT_AG_CALL_EVENT_DIALING and #BT_AG_CALL_EVENT_INCOMING. + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_OUT_OF_MEMORY Out of memory + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_call_list_create() + */ +int bt_call_list_add(bt_call_list_h list, unsigned int call_id, bt_ag_call_state_e state, const char *phone_number); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief Initializes the Bluetooth AVRCP(Audio/Video Remote Control Profile) service. + * @since_tizen 2.3.1 + * @remarks This function must be called before Bluetooth AVRCP service. \n + * You must free all resources of the this service by calling bt_avrcp_target_deinitialize() + * if Bluetooth AVRCP service is no longer needed. + * @param[in] callback The callback function called when the connection state is changed + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @see bt_initialize() + * @see bt_avrcp_target_deinitialize() + */ +int bt_avrcp_target_initialize(bt_avrcp_target_connection_state_changed_cb callback, void *user_data); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief Deinitializes the Bluetooth AVRCP(Audio/Video Remote Control Profile) service. + * @since_tizen 2.3.1 + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth audio service must be initialized with bt_avrcp_target_initialize(). + * @see bt_avrcp_target_initialize() + */ +int bt_avrcp_target_deinitialize(void); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief Notifies the equalize state to the remote device. + * @since_tizen 2.3.1 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @param[in] state The state of equalizer + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The remote device must be connected. + * @see bt_avrcp_target_connection_state_changed_cb() + * @see bt_avrcp_target_initialize() + */ +int bt_avrcp_target_notify_equalizer_state(bt_avrcp_equalizer_state_e state); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief Notifies the repeat mode to the remote device. + * @since_tizen 2.3.1 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @param[in] mode The repeat mode + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The remote device must be connected. + * @see bt_avrcp_target_connection_state_changed_cb() + * @see bt_avrcp_target_initialize() + */ +int bt_avrcp_target_notify_repeat_mode(bt_avrcp_repeat_mode_e mode); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief Notifies the shuffle mode to the remote device. + * @since_tizen 2.3.1 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @param[in] mode The repeat mode + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The remote device must be connected. + * @see bt_avrcp_target_connection_state_changed_cb() + * @see bt_avrcp_target_initialize() + */ +int bt_avrcp_target_notify_shuffle_mode(bt_avrcp_shuffle_mode_e mode); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief Notifies the scan mode to the remote device. + * @since_tizen 2.3.1 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @param[in] mode The scan mode + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The remote device must be connected. + * @see bt_avrcp_target_connection_state_changed_cb() + * @see bt_avrcp_target_initialize() + */ +int bt_avrcp_target_notify_scan_mode(bt_avrcp_scan_mode_e mode); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief Notifies the player state to the remote device. + * @since_tizen 2.3.1 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @param[in] state The player state + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The remote device must be connected. + * @see bt_avrcp_target_connection_state_changed_cb() + * @see bt_avrcp_target_initialize() + */ +int bt_avrcp_target_notify_player_state(bt_avrcp_player_state_e state); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief Notifies the current position of song to the remote device. + * @since_tizen 2.3.1 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @param[in] position The current position in milliseconds + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The remote device must be connected. + * @see bt_avrcp_target_connection_state_changed_cb() + * @see bt_avrcp_target_initialize() + */ +int bt_avrcp_target_notify_position(unsigned int position); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief Notifies the track to the remote device. + * @since_tizen 2.3.1 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @param[in] title The title of track + * @param[in] artist The artist of track + * @param[in] album The album of track + * @param[in] genre The genre of track + * @param[in] track_num The track number + * @param[in] total_tracks The number of all tracks + * @param[in] duration The duration of track in milliseconds + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The remote device must be connected. + * @see bt_avrcp_target_connection_state_changed_cb() + * @see bt_avrcp_target_initialize() + */ +int bt_avrcp_target_notify_track(const char *title, const char *artist, const char *album, const char *genre, unsigned int track_num, unsigned int total_tracks, unsigned int duration); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief Registers a callback function that will be invoked when the equalizer state is changed by the remote control device. + * @since_tizen 2.3.1 + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized by bt_initialize(). + * @see bt_initialize() + * @see bt_avrcp_unset_equalizer_state_changed_cb() + */ +int bt_avrcp_set_equalizer_state_changed_cb(bt_avrcp_equalizer_state_changed_cb callback, void *user_data); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief Unregisters a callback function that will be invoked when the equalizer state is changed by the remote control device. + * @since_tizen 2.3.1 + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized by bt_initialize(). + * @see bt_initialize() + * @see bt_avrcp_set_equalizer_state_changed_cb() + */ +int bt_avrcp_unset_equalizer_state_changed_cb(void); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief Registers a callback function that will be invoked when the repeat mode is changed by the remote control device. + * @since_tizen 2.3.1 + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized by bt_initialize(). + * @see bt_initialize() + * @see bt_avrcp_unset_repeat_mode_changed_cb() + */ +int bt_avrcp_set_repeat_mode_changed_cb(bt_avrcp_repeat_mode_changed_cb callback, void *user_data); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief Unregisters a callback function that will be invoked when the repeat mode is changed by the remote control device. + * @since_tizen 2.3.1 + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized by bt_initialize(). + * @see bt_initialize() + * @see bt_avrcp_set_repeat_mode_changed_cb() + */ +int bt_avrcp_unset_repeat_mode_changed_cb(void); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief Registers a callback function that will be invoked when the shuffle mode is changed by the remote control device. + * @since_tizen 2.3.1 + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized by bt_initialize(). + * @see bt_initialize() + * @see bt_avrcp_unset_shuffle_mode_changed_cb() + */ +int bt_avrcp_set_shuffle_mode_changed_cb(bt_avrcp_shuffle_mode_changed_cb callback, void *user_data); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief Unregisters a callback function that will be invoked when the shuffle mode is changed by the remote control device. + * @since_tizen 2.3.1 + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized by bt_initialize(). + * @see bt_initialize() + * @see bt_avrcp_set_shuffle_mode_changed_cb() + */ +int bt_avrcp_unset_shuffle_mode_changed_cb(void); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief Registers a callback function that will be invoked when the scan mode is changed by the remote control device. + * @since_tizen 2.3.1 + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized by bt_initialize(). + * @see bt_initialize() + * @see bt_avrcp_unset_scan_mode_changed_cb() + */ +int bt_avrcp_set_scan_mode_changed_cb(bt_avrcp_scan_mode_changed_cb callback, void *user_data); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief Unregisters a callback function that will be invoked when the scan mode is changed by the remote control device. + * @since_tizen 2.3.1 + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized by bt_initialize(). + * @see bt_initialize() + * @see bt_avrcp_set_scan_mode_changed_cb() + */ +int bt_avrcp_unset_scan_mode_changed_cb(void); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_HDP_MODULE + * @brief Registers an application that acts as the @a Sink role of HDP(Health Device Profile). + * @since_tizen 2.3.1 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * @remarks The @a app_id must be released with free() by you. + * @param[in] data_type The data type of MDEP. This value is defined in ISO/IEEE 11073-20601 spec. + * For example, pulse oximeter is 0x1004 and blood pressure monitor is 0x1007. + * @param[out] app_id The ID of application + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_OUT_OF_MEMORY Out of memory + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * @see bt_hdp_unregister_sink_app() + */ +int bt_hdp_register_sink_app(unsigned short data_type, char **app_id); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_HDP_MODULE + * @brief Unregisters the given application that acts as the @a Sink role of HDP(Health Device Profile). + * @since_tizen 2.3.1 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * @param[in] app_id The ID of application + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_hdp_register_sink_app() + */ +int bt_hdp_unregister_sink_app(const char *app_id); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_HDP_MODULE + * @brief Connects the remote device which acts as @a Source role, asynchronously. + * @since_tizen 2.3.1 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * @param[in] remote_address The remote address + * @param[in] app_id The ID of application + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OUT_OF_MEMORY Out of memory + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Sink role of HDP must be registered with bt_hdp_register_sink_app(). + * @pre The local device must be bonded with the remote device by bt_device_create_bond(). + * @post bt_hdp_connected_cb() will be invoked. + * @see bt_hdp_disconnect() + * @see bt_hdp_set_connection_state_changed_cb() + * @see bt_hdp_unset_connection_state_changed_cb() + */ +int bt_hdp_connect_to_source(const char *remote_address, const char *app_id); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_HDP_MODULE + * @brief Disconnects the remote device, asynchronously. + * @since_tizen 2.3.1 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * @param[in] remote_address The remote address + * @param[in] channel The connected data channel + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected + * @retval #BT_ERROR_OUT_OF_MEMORY Out of memory + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The remote device must be connected. + * @post bt_hdp_disconnected_cb() will be invoked. + * @see bt_hdp_set_connection_state_changed_cb() + * @see bt_hdp_unset_connection_state_changed_cb() + */ +int bt_hdp_disconnect(const char *remote_address, unsigned int channel); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_HDP_MODULE + * @brief Sends the data to the remote device. + * @since_tizen 2.3.1 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * @param[in] channel The connected data channel + * @param[in] data The data to send + * @param[in] size The size of data to send (byte) + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The remote device must be connected. + * @see bt_hdp_data_received_cb() + * @see bt_hdp_set_data_received_cb() + * @see bt_hdp_unset_data_received_cb() + */ +int bt_hdp_send_data(unsigned int channel, const char *data, unsigned int size); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_HDP_MODULE + * @brief Registers a callback function that will be invoked when the connection state is changed. + * @since_tizen 2.3.1 + * @param[in] connected_cb The callback function called when a connection is established + * @param[in] disconnected_cb The callback function called when a connection is disconnected + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @see bt_hdp_unset_connection_state_changed_cb() + */ +int bt_hdp_set_connection_state_changed_cb(bt_hdp_connected_cb connected_cb, bt_hdp_disconnected_cb disconnected_cb, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_HDP_MODULE + * @brief Unregisters a callback function that will be invoked when the connection state is changed. + * @since_tizen 2.3.1 + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @see bt_hdp_set_connection_state_changed_cb() + */ +int bt_hdp_unset_connection_state_changed_cb(void); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_HDP_MODULE + * @brief Registers a callback function that will be invoked when you receive the data. + * @since_tizen 2.3.1 + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @see bt_hdp_unset_data_received_cb() + */ +int bt_hdp_set_data_received_cb(bt_hdp_data_received_cb callback, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_HDP_MODULE + * @brief Unregisters a callback function that will be invoked when you receive the data. + * @since_tizen 2.3.1 + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @see bt_hdp_set_data_received_cb() + */ +int bt_hdp_unset_data_received_cb(void); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Gets the value of a characteristic or descriptor's GATT handle + * @since_tizen 2.3.1 + * + * @remarks @a value must be released using free(). \n + * When @a gatt_handle is associated with bt_gatt_client_h, bt_gatt_client_read_value() must be used prior to this function \n + * in order to get the remote device's current value. + * + * @param[in] gatt_handle The handle of a characteristic or descriptor + * @param[out] value The value of @a gatt_handle. It is a byte stream type. + * @param[out] value_length The length of @a value + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + */ +int bt_gatt_get_value(bt_gatt_h gatt_handle, char **value, int *value_length); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Gets the value of a characteristic or descriptor's GATT handle as an integer type + * @since_tizen 2.3.1 + * + * @remarks This function returns a locally saved value in @a gatt_handle. \n + * When @a gatt_handle is associated with bt_gatt_client_h, bt_gatt_client_read_value() must be used prior to this function \n + * in order to get the remote device's current value. + * + * @param[in] gatt_handle The handle of a characteristic or descriptor + * @param[in] type The type of a saved value in @a gatt_handle + * @param[in] offset The offset from where a value will be read from @a gatt_handle as an integer type + * @param[out] value The integer type's value of @a gatt_handle + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + */ +int bt_gatt_get_int_value(bt_gatt_h gatt_handle, bt_data_type_int_e type, + int offset, int *value); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Gets the value of a characteristic or descriptor's GATT handle as a float type + * @since_tizen 2.3.1 + * + * @remarks This function returns a locally saved value in @a gatt_handle. \n + * When @a gatt_handle is associated with bt_gatt_client_h, bt_gatt_client_read_value() must be used prior to this function \n + * in order to get the remote device's current value. + * + * @param[in] gatt_handle The handle of a characteristic or descriptor + * @param[in] type The type of a saved value in @a gatt_handle + * @param[in] offset The offset from where a value will be read from @a gatt_handle as an integer type + * @param[out] value The float type's value of @a gatt_handle + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + */ +int bt_gatt_get_float_value(bt_gatt_h gatt_handle, bt_data_type_float_e type, + int offset, float *value); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Updates the value of a characteristic or descriptor's GATT handle + * @since_tizen 2.3.1 + * + * @remarks This function updates a value of @a gatt_handle locally. \n + * When @a gatt_handle is associated with bt_gatt_client_h, bt_gatt_client_write_value() can be used after this function \n + * in order to update the remote device's value. \n + * + * @param[in] gatt_handle The handle of a characteristic or descriptor + * @param[in] value The value to be updated + * @param[in] value_length The length of @a value + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + */ +int bt_gatt_set_value(bt_gatt_h gatt_handle, const char *value, int value_length); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Updates the value of a characteristic or descriptor's GATT handle using a integer type's value + * @since_tizen 2.3.1 + * + * @remarks This function updates a value of @a gatt_handle locally. \n + * When @a gatt_handle is associated with bt_gatt_client_h, bt_gatt_client_write_value() can be used after this function \n + * in order to update the remote device's value. \n + * + * @param[in] gatt_handle The handle of a characteristic or descriptor + * @param[in] type @a value will be saved in @a gatt_handle as this type + * @param[in] value The integer type's value to be updated + * @param[in] offset The offset from where @a value will be saved in @a gatt_handle + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + */ +int bt_gatt_set_int_value(bt_gatt_h gatt_handle, bt_data_type_int_e type, + int value, int offset); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Updates the value of a characteristic or descriptor's GATT handle using a float type's value + * @since_tizen 2.3.1 + * + * @remarks This function updates a value of @a gatt_handle locally. \n + * When @a gatt_handle is associated with bt_gatt_client_h, bt_gatt_client_write_value() can be used after this function \n + * in order to update the remote device's value. \n + * + * @param[in] gatt_handle The handle of a characteristic or descriptor + * @param[in] type @a mantissa and @a exponent will be saved in @a gatt_handle as this type + * @param[in] mantissa The mantissa of float type's value to be updated + * @param[in] exponent The exponent of float type's value to be updated + * @param[in] offset The offset from where @a mantissa and @a exponent will be saved in @a gatt_handle + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + */ +int bt_gatt_set_float_value(bt_gatt_h gatt_handle, bt_data_type_float_e type, + int mantissa, int exponent, int offset); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Gets the UUID of a service, characteristic or descriptor's GATT handle + * @since_tizen 2.3.1 + * + * @remarks @a uuid must be released using free(). \n + * 16-bit UUID or 128-bit UUID is supported. (e.g. 2A19, 00002A19-0000-1000-8000-00805F9B34FB) + * + * @param[in] gatt_handle The handle of a service, characteristic or descriptor + * @param[out] uuid The string of the UUID of @a gatt_handle + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + */ +int bt_gatt_get_uuid(bt_gatt_h gatt_handle, char **uuid); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Gets the type of GATT handle + * @since_tizen 2.3.1 + * + * @param[in] gatt_handle The GATT handle + * @param[out] gatt_type The type of @a gatt_handle + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + */ +int bt_gatt_get_type(bt_gatt_h gatt_handle, bt_gatt_type_e *gatt_type); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Gets the GATT client handle which the specified service belongs to + * @since_tizen 2.3.1 + * + * @remark This function doesn't allocate new memory for GATT client handle. + * The returned GATT client handle is the same one which was got from bt_gatt_client_create(). + * So if it is destroyed by bt_gatt_client_destroy(), all related GATT handles are freed also. + * + * @param[in] service The service's GATT handle + * @param[out] client The GATT client handle which @a service belongs to + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_gatt_client_create() + */ +int bt_gatt_service_get_client(bt_gatt_h service, bt_gatt_client_h *client); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Gets a characteristic's GATT handle which has specific UUID + * @since_tizen 2.3.1 + * + * @remark The returned GATT handle must not be freed by application. + * It will be freed when an associated client is destroyed by bt_gatt_client_destroy(). + * If there are multiple characteristics which have same UUID, only the first matched one will be returned. + * + * @param[in] service The service's GATT handle + * @param[in] uuid The characteristic's GATT handle which has this UUID will be returned if it exists + * @param[out] characteristic The characteristic's GATT handle which has @a uuid if it exists + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NO_DATA No data available + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + */ +int bt_gatt_service_get_characteristic(bt_gatt_h service, const char *uuid, + bt_gatt_h *characteristic); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Invokes @a callback function on each characteristic that belongs to the specified service + * @since_tizen 2.3.1 + * + * @param[in] service The service's GATT handle + * @param[in] callback The function to be invoked on each characteristic + * @param[in] user_data The user data to be passed to @a callback function + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_gatt_foreach_cb() + */ +int bt_gatt_service_foreach_characteristics(bt_gatt_h service, + bt_gatt_foreach_cb callback, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Gets an included service's GATT handle which has specific UUID + * @since_tizen 2.3.1 + * + * @remark The returned GATT handle must not be freed by application. + * It will be freed when an associated client is destroyed by bt_gatt_client_destroy(). + * If there are multiple included services which have same UUID, only the first matched one will be returned. + * + * @param[in] service The service's GATT handle + * @param[in] uuid The included service's GATT handle which has this UUID will be returned if it exists + * @param[out] included_service The included service's GATT handle which has @a uuid if it exists + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NO_DATA No data available + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + */ +int bt_gatt_service_get_included_service(bt_gatt_h service, const char *uuid, + bt_gatt_h *included_service); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Invokes @a callback function on each included service that belongs to the specified service + * @since_tizen 2.3.1 + * + * @param[in] service The service's GATT handle + * @param[in] callback The function to be invoked on each included service + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_gatt_foreach_cb() + */ +int bt_gatt_service_foreach_included_services(bt_gatt_h service, + bt_gatt_foreach_cb callback, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Gets the service's GATT handle which the specified characteristic belongs to + * @since_tizen 2.3.1 + * + * @remark The returned GATT handle must not be freed by application. + * It will be freed when an associated client is destroyed by bt_gatt_client_destroy(). + * + * @param[in] characteristic The characteristic's GATT handle + * @param[out] service The service's GATT handle which @a characteristic belongs to + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + */ +int bt_gatt_characteristic_get_service(bt_gatt_h characteristic, bt_gatt_h *service); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Gets the properties which a characteristic's GATT handle has + * @since_tizen 2.3.1 + * + * @param[in] characteristic The characteristic's GATT handle + * @param[out] properties The properties which a characteristic's GATT handle has + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_gatt_property_e + */ +int bt_gatt_characteristic_get_properties(bt_gatt_h characteristic, int *properties); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Gets the write type of the specified characteristic + * @since_tizen 2.3.1 + * + * @param[in] characteristic The characteristic's GATT handle + * @param[out] write_type The write type of the specified characteristic + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_gatt_write_type_e + */ +int bt_gatt_characteristic_get_write_type(bt_gatt_h characteristic, + bt_gatt_write_type_e *write_type); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Updates the write type of the specified charateristic + * @since_tizen 2.3.1 + * + * @param[in] characteristic The characteristic's GATT handle + * @param[in] write_type The write type to be updated + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_gatt_client_write_value() + * @see bt_gatt_write_type_e + */ +int bt_gatt_characteristic_set_write_type(bt_gatt_h characteristic, + bt_gatt_write_type_e write_type); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Gets a descriptor's GATT handle which has specific UUID + * @since_tizen 2.3.1 + * + * @remark The returned GATT handle must not be freed by application. + * It will be freed when an associated client is destroyed by bt_gatt_client_destroy(). + * If there are multiple descriptors which have same UUID, only the first matched one will be returned. + * + * @param[in] characteristic The characteristic's GATT handle + * @param[in] uuid The descriptor's GATT handle which has this UUID will be returned if it exists + * @param[out] descriptor The descriptor's GATT handle which has @a uuid if it exists + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NO_DATA No data available + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + */ +int bt_gatt_characteristic_get_descriptor(bt_gatt_h characteristic, const char *uuid, + bt_gatt_h *descriptor); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Invokes @a callback function on each descriptor that belongs to the specified characteristic + * @since_tizen 2.3.1 + * + * @param[in] characteristic The characteristic's GATT handle + * @param[in] callback The function to be invoked on each descriptor + * @param[in] user_data The user data to be passed to @a callback function + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_gatt_foreach_cb() + */ +int bt_gatt_characteristic_foreach_descriptors(bt_gatt_h characteristic, + bt_gatt_foreach_cb callback, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Gets the characteristic's GATT handle which the specified descriptor belongs to + * @since_tizen 2.3.1 + * + * @remark The returned GATT handle must not be freed by application. + * It will be freed when an associated client is destroyed by bt_gatt_client_destroy(). + * + * @param[in] descriptor The descriptor's GATT handle + * @param[out] characteristic The characteristic's GATT handle which @a descriptor belongs to + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + */ +int bt_gatt_descriptor_get_characteristic(bt_gatt_h descriptor, bt_gatt_h *characteristic); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Creates the GATT client handle + * @since_tizen 2.3.1 + * + * @remark The GATT client handle must be freed by bt_gatt_client_destroy() after use + * + * @param[in] remote_address The address of the remote device + * @param[out] client The created GATT client's handle + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_OUT_OF_MEMORY Out of memory + * @retval #BT_ERROR_ALREADY_DONE Operation is already done + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_gatt_client_destroy() + */ +int bt_gatt_client_create(const char *remote_address, bt_gatt_client_h *client); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Destroys the GATT client's handle + * @since_tizen 2.3.1 + * + * @remark All related service, characteristic and descriptor's GATT handles are freed also + * + * @param[in] client The GATT client's handle + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_gatt_client_create() + */ +int bt_gatt_client_destroy(bt_gatt_client_h client); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Gets the address of remote device + * @since_tizen 2.3.1 + * + * @param[in] client The created GATT client's handle + * @param[out] remote_address The address of the remote device which is associated with @a client + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_gatt_client_create() + */ +int bt_gatt_client_get_remote_address(bt_gatt_client_h client, + char **remote_address); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Reads the value of a characteristic or descriptor from the remote device asynchronously + * @since_tizen 2.3.1 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * + * @param[in] gatt_handle The GATT handle of a characteristic or descriptor + * @param[in] callback When a read request is completed, this callback function will be called + * @param[in] user_data The user data to be passed to @a callback function + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_NOW_IN_PROGRESS Operation now in progress + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_gatt_client_create() + * @see bt_gatt_client_request_completed_cb() + */ +int bt_gatt_client_read_value(bt_gatt_h gatt_handle, + bt_gatt_client_request_completed_cb callback, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Writes the value of a characteristic or descriptor to the remote device asynchronously + * @since_tizen 2.3.1 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * + * @param[in] gatt_handle The GATT handle of a characteristic or descriptor + * @param[in] callback When a write request is completed, this callback function will be called + * @param[in] user_data The user data to be passed to @a callback function + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_NOW_IN_PROGRESS Operation now in progress + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_gatt_client_create() + * @see bt_gatt_characteristic_set_write_type() + * @see bt_gatt_set_value() + * @see bt_gatt_set_int_value() + * @see bt_gatt_set_float_value() + * @see bt_gatt_client_request_completed_cb() + */ +int bt_gatt_client_write_value(bt_gatt_h gatt_handle, + bt_gatt_client_request_completed_cb callback, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Registers a callback function to be invoked when the characteristic value is changed on the remote device + * @since_tizen 2.3.1 + * + * @param[in] characteristic The characteristic's GATT handle + * @param[in] callback The callback to be invoked when the value is changed and it is informed + * @param[in] user_data The user data to be passed to @a callback function + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_gatt_client_characteristic_value_changed_cb() + * @see bt_gatt_client_unset_characteristic_value_change() + */ +int bt_gatt_client_set_characteristic_value_changed_cb(bt_gatt_h characteristic, + bt_gatt_client_characteristic_value_changed_cb callback, + void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Unregisters a callback function to be invoked when the characteristic value is changed on the remote device + * @since_tizen 2.3.1 + * + * @param[in] characteristic The characteristic's GATT handle, whose value change will not be informed + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_gatt_client_set_characteristic_value_changed_cb() + */ +int bt_gatt_client_unset_characteristic_value_changed_cb(bt_gatt_h characteristic); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Gets a service's GATT handle which has specific UUID + * @since_tizen 2.3.1 + * + * @remark The returned GATT handle must not be freed by application. + * It will be freed when an associated client is destroyed by bt_gatt_client_destroy(). + * If there are multiple services which have same UUID, only the first matched one will be returned. + * + * @param[in] client The GATT client's handle + * @param[in] uuid The serivce's GATT handle which has this UUID will be returned if it exists + * @param[out] service The service's GATT handle which has @a uuid if it exists + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NO_DATA No data available + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + */ +int bt_gatt_client_get_service(bt_gatt_client_h client, const char *uuid, + bt_gatt_h *service); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Invokes @a callback function on each service that belongs to the specified GATT client + * @since_tizen 2.3.1 + * + * @param[in] client The GATT client's handle + * @param[in] callback The function to be invoked on each service + * @param[in] user_data The user data to be passed to @a callback function + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_gatt_foreach_cb() + */ +int bt_gatt_client_foreach_services(bt_gatt_client_h client, + bt_gatt_foreach_cb callback, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Connect to a specific LE based service on a remote bluetooth dievice address, asynchronously. + * @since_tizen 2.3.1 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * + * @remarks A connection can be disconnected by bt_gatt_disconnect(). + * + * @param[in] address The address of the remote Bluetooth device. + * @param[in] auto_connect The flag of the auto connection. + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_INVALID_PARAMETER Invalid paramater + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @pre The remote device must support le connection. + * @post This function invokes bt_gatt_connection_state_changed_cb(). + * + * @see bt_initialize() + * @see bt_gatt_disconnect() + * @see bt_gatt_set_connection_state_changed_cb() + * @see bt_gatt_unset_connection_state_changed_cb() + * @see bt_gatt_connection_state_changed_cb() + */ +int bt_gatt_connect(const char *address, bool auto_connect); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Disconnect to LE connection with the given remote Bluetooth dievice address, asynchronously. + * @since_tizen 2.3.1 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * + * @param[in] address The address of the remote Bluetooth device + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_INVALID_PARAMETER Invalid paramater + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The connection must be established. + * @post This function invokes bt_gatt_connection_state_changed_cb(). + * + * @see bt_initialize() + * @see bt_gatt_connect() + * @see bt_gatt_set_connection_state_changed_cb() + * @see bt_gatt_unset_connection_state_changed_cb() + * @see bt_gatt_connection_state_changed_cb() + */ +int bt_gatt_disconnect(const char *address); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Registers a callback function that will be invoked when the connection state is changed. + * @since_tizen 2.3.1 + * + * @param[in] callback The callback function to register. + * @param[in] user_data The user data to be passed to the callback function. + * + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid paramater + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_gatt_connect() + * @see bt_gatt_disconnect() + * @see bt_gatt_unset_connection_state_changed_cb() + */ +int bt_gatt_set_connection_state_changed_cb(bt_gatt_connection_state_changed_cb callback, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Unregisters a callback function that will be invoked when the connection state is changed. + * @since_tizen 2.3.1 + * + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_gatt_connect() + * @see bt_gatt_disconnect() + * @see bt_gatt_connection_state_changed_cb() + */ +int bt_gatt_unset_connection_state_changed_cb(void); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_PAN_NAP_MODULE + * @brief Activates the NAP(Network Access Point). + * @since_tizen 2.3.1 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_ALREADY_DONE Operation is already done + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED + * @see bt_nap_deactivate() + */ +int bt_nap_activate(void); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_PAN_NAP_MODULE + * @brief Deactivates the NAP(Network Access Point). + * @since_tizen 2.3.1 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_ALREADY_DONE Operation is already done + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth NAP service must be activated with bt_nap_activate(). + * @see bt_nap_activate() + */ +int bt_nap_deactivate(void); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_PAN_NAP_MODULE + * @brief Disconnects the all PANUs(Personal Area Networking User) which are connected to you. + * @since_tizen 2.3.1 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth NAP service must be activated with bt_nap_activate(). + * @see bt_nap_activate() + */ +int bt_nap_disconnect_all(void); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_PAN_NAP_MODULE + * @brief Disconnects the specified PANU(Personal Area Networking User) which is connected to you. + * @since_tizen 2.3.1 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * @param[in] remote_address The remote address + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth NAP service must be activated with bt_nap_activate(). + * @see bt_nap_activate() + */ +int bt_nap_disconnect(const char *remote_address); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_PAN_NAP_MODULE + * @brief Registers a callback function that will be invoked when the connection state changes. + * @since_tizen 2.3.1 + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @post bt_nap_connection_state_changed_cb() will be invoked. + * @see bt_initialize() + * @see bt_nap_connection_state_changed_cb() + * @see bt_nap_unset_connection_state_changed_cb() + */ +int bt_nap_set_connection_state_changed_cb(bt_nap_connection_state_changed_cb callback, void *user_data); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_PAN_NAP_MODULE + * @brief Unregisters a callback function that will be invoked when the connection state changes. + * @since_tizen 2.3.1 + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @post bt_nap_connection_state_changed_cb() will be invoked. + * @see bt_initialize() + * @see bt_nap_connection_state_changed_cb() + * @see bt_nap_set_connection_state_changed_cb() + */ +int bt_nap_unset_connection_state_changed_cb(void); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_PAN_PANU_MODULE + * @brief Registers a callback function that will be invoked when the connection state changes. + * @since_tizen 2.3.1 + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @post bt_nap_connection_state_changed_cb() will be invoked. + * @see bt_initialize() + * @see bt_panu_connection_state_changed_cb() + * @see bt_panu_unset_connection_state_changed_cb() + */ +int bt_panu_set_connection_state_changed_cb(bt_panu_connection_state_changed_cb callback, void *user_data); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_PAN_PANU_MODULE + * @brief Unregisters a callback function that will be invoked when the connection state changes. + * @since_tizen 2.3.1 + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @post bt_nap_connection_state_changed_cb() will be invoked. + * @see bt_initialize() + * @see bt_panu_connection_state_changed_cb() + * @see bt_panu_set_connection_state_changed_cb() + */ +int bt_panu_unset_connection_state_changed_cb(void); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_PAN_PANU_MODULE + * @brief Connects the remote device with the PAN(Personal Area Networking) service, asynchronously. + * @since_tizen 2.3.1 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * @param[in] remote_address The remote address + * @param[in] type The type of PAN service + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OUT_OF_MEMORY Out of memory + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The local device must be bonded with the remote device by bt_device_create_bond(). + * @post bt_panu_connection_state_changed_cb() will be invoked. + * @see bt_panu_disconnect() + * @see bt_panu_connection_state_changed_cb() + */ +int bt_panu_connect(const char *remote_address, bt_panu_service_type_e type); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_PAN_PANU_MODULE + * @brief Disconnects the remote device with the PAN(Personal Area Networking) service, asynchronously. + * @since_tizen 2.3.1 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * @param[in] remote_address The remote address + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected + * @retval #BT_ERROR_OUT_OF_MEMORY Out of memory + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The remote device must be connected by bt_panu_connect(). + * @post bt_panu_connection_state_changed_cb() will be invoked. + * @see bt_panu_connect() + * @see bt_panu_connection_state_changed_cb() + */ +int bt_panu_disconnect(const char *remote_address); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief update LE connection. + * @since_tizen 2.3.1 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized by bt_initialize(). + * @pre The remote device must be connected with bt_gatt_connect(). + */ +int bt_device_le_conn_update(const char *device_address, + const bt_le_conn_update_s *parameters); + + +/** + * @} + */ + + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif // __TIZEN_NETWORK_BLUETOOTH_H__ diff --git a/include/wearable/bluetooth_internal.h b/include/wearable/bluetooth_internal.h new file mode 100644 index 0000000..c00233d --- /dev/null +++ b/include/wearable/bluetooth_internal.h @@ -0,0 +1,2276 @@ +/* + * 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 __TIZEN_NETWORK_BLUETOOTH_INTERNAL_H__ +#define __TIZEN_NETWORK_BLUETOOTH_INTERNAL_H__ + +#include +#include "bluetooth_type.h" +#include "bluetooth_type_internal.h" + +#ifdef __cplusplus +extern "C" +{ +#endif /* __cplusplus */ + +/** + * @file bluetooth_internal.h + */ + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Sets the manufacturer data of local Bluetooth adapter. + * @since_tizen 2.3 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * + * @param[in] data The manufacturer specific data of the Bluetooth device. + * @param[in] len The length of @a data.Maximaum length is 240 bytes. + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * @post bt_adapter_manufacturer_data_changed_cb() will be invoked + * if this function returns #BT_ERROR_NONE. + * + * @see bt_adapter_manufacturer_data_changed_cb + * @see bt_adapter_set_manufacturer_data_changed_cb() + * @see bt_adapter_unset_manufacturer_data_changed_cb() + */ +int bt_adapter_set_manufacturer_data(char *data, int len); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Registers a callback function to be invoked + * when the manufacturer data of Bluetooth adapter changes. + * @since_tizen 2.3 + * + * @param[in] callback The callback function to invoke + * @param[in] user_data The user data to be passed to the callback function + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @post bt_adapter_manufacturer_data_changed_cb() will be invoked. + * + * @see bt_initialize() + * @see bt_adapter_unset_manufacturer_data_changed_cb() + */ +int bt_adapter_set_manufacturer_data_changed_cb( + bt_adapter_manufacturer_data_changed_cb callback, + void *user_data); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Unregisters the callback function. + * @since_tizen 2.3 + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * + * @see bt_initialize() + * @see bt_adapter_set_manufacturer_data_changed_cb() + */ +int bt_adapter_unset_manufacturer_data_changed_cb(void); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Set Bluetooth LE scan mode + * @since_tizen 2.3 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @param[in] scan_mode The scan mode + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_ENABLED Adapter is not enabled + * @retval #BT_ERROR_INVALID_PARAM Parameter is invalid + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @see bt_initialize() + */ +int bt_adapter_le_set_scan_mode(bt_adapter_le_scan_mode_e scan_mode); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Creates scan filter to find only LE advertisement which has specific data. + * @since_tizen 2.4 + * + * @param[out] scan_filter The handle of scan filter + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_OUT_OF_MEMORY Out of memory + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * + * @see bt_adapter_le_destroy_scan_filter() + */ +int bt_adapter_le_create_scan_filter(bt_scan_filter_h *scan_filter); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Destroys scan filter. + * @since_tizen 2.4 + * + * @param[in] scan_filter The handle of scan filter + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * + * @see bt_adapter_le_create_scan_filter() + */ +int bt_adapter_le_destroy_scan_filter(bt_scan_filter_h scan_filter); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Adds the device address to filter advertisements + * @since_tizen 2.4 + * + * @param[in] scan_filter The handle of scan filter + * @param[in] address The device address to filter advertisements + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * + */ +int bt_adapter_le_scan_filter_set_device_address(bt_scan_filter_h scan_filter, const char *address); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Adds the device name to filter advertisements + * @since_tizen 2.4 + * + * @param[in] scan_filter The handle of scan filter + * @param[in] name The device name to filter advertisements + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * + */ +int bt_adapter_le_scan_filter_set_device_name(bt_scan_filter_h scan_filter, const char *name); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Adds the service UUID to filter advertisements + * @since_tizen 2.4 + * + * @param[in] scan_filter The handle of scan filter + * @param[in] uuid The service UUID to filter advertisements + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * + */ +int bt_adapter_le_scan_filter_set_service_uuid(bt_scan_filter_h scan_filter, const char *uuid); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Adds the service uuid and the mask to filter advertisements by partial data + * @since_tizen 2.4 + * + * @remarks the length of mask msut be the same with the length of service uuid. + * + * @param[in] scan_filter The handle of scan filter + * @param[in] uuid The service UUID to filter advertisements + * @param[in] mask The mask to filter advertisements + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * + */ +int bt_adapter_le_scan_filter_set_service_uuid_with_mask(bt_scan_filter_h scan_filter, + const char *uuid, const char *mask); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Adds the service solicitation UUID to filter advertisements + * @since_tizen 2.4 + * + * @param[in] scan_filter The handle of scan filter + * @param[in] uuid The service solicitation UUID to filter advertisements + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * + */ +int bt_adapter_le_scan_filter_set_service_solicitation_uuid(bt_scan_filter_h scan_filter, const char *uuid); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Adds the service solicitation uuid and the mask to filter advertisements by partial data + * @since_tizen 2.4 + * + * @remarks the length of mask msut be the same with the length of service solicitation uuid. + * + * @param[in] scan_filter The handle of scan filter + * @param[in] uuid The service solicitation UUID to filter advertisements + * @param[in] mask The mask to filter advertisements + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * + */ +int bt_adapter_le_scan_filter_set_service_solicitation_uuid_with_mask(bt_scan_filter_h scan_filter, + const char *uuid, const char *mask); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Adds the service data to filter advertisements + * @since_tizen 2.4 + * + * @param[in] scan_filter The handle of scan filter + * @param[in] uuid The service UUID to filter advertisements + * @param[in] data The service data to filter advertisements + * @param[in] data_len The length of the service data + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * + */ +int bt_adapter_le_scan_filter_set_service_data(bt_scan_filter_h scan_filter, + const char *uuid, const char *data, unsigned int data_len); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Adds the service data and the mask to filter advertisements by partial data + * @since_tizen 2.4 + * + * @remarks the length of mask msut be the same with the length of service data. + * + * @param[in] scan_filter The handle of scan filter + * @param[in] uuid The service UUID to filter advertisements + * @param[in] data The service data to filter advertisements + * @param[in] data_len The length of the service data + * @param[in] mask The mask to filter advertisements + * @param[in] mask_len The length of the mask to be set. + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * + */ +int bt_adapter_le_scan_filter_set_service_data_with_mask(bt_scan_filter_h scan_filter, + const char *uuid, const char *data, unsigned int data_len, const char *mask, unsigned int mask_len); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Adds the manufacturer data to filter advertisements + * @since_tizen 2.4 + * + * @param[in] scan_filter The handle of scan filter + * @param[in] manufacturer_id The manufacturer ID (0x0000 ~ 0xFFFF) + * @param[in] data The manufacturer data (byte array) + * @param[in] data_len The length of manufacturer data + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * + */ +int bt_adapter_le_scan_filter_set_manufacturer_data(bt_scan_filter_h scan_filter, + int manufacturer_id, const char *data, unsigned int data_len); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Adds the manufacturer data and the mask to filter advertisements by partial data + * @since_tizen 2.4 + * + * @remarks the length of mask msut be the same with the length of service uuid. + * + * @param[in] scan_filter The handle of scan filter + * @param[in] manufacturer_id The manufacturer ID (0x0000 ~ 0xFFFF) + * @param[in] data The manufacturer data (byte array) + * @param[in] data_len The length of manufacturer data + * @param[in] mask The mask to filter advertisements + * @param[in] mask_len The length of the mask to be set. + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * + */ +int bt_adapter_le_scan_filter_set_manufacturer_data_with_mask(bt_scan_filter_h scan_filter, + int manufacturer_id, const char *data, unsigned int data_len, const char *mask, unsigned int mask_len); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Registers the scan filter to use for scanning + * @since_tizen 2.4 + * + * @remarks Several scan filters can be registered. And the specific advertisements, satisfy the one of scan filters, will be found. + * + * @param[in] scan_filter The handle of scan filter + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOW_IN_PROGRESS Scan is in progress + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * + */ +int bt_adapter_le_register_scan_filter(bt_scan_filter_h scan_filter); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Unregisters the scan filter to be registered + * @since_tizen 2.4 + * + * @param[in] scan_filter The handle of scan filter + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOW_IN_PROGRESS Scan is in progress + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * + */ +int bt_adapter_le_unregister_scan_filter(bt_scan_filter_h scan_filter); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Unregisters all scan filters to be registered + * @since_tizen 2.4 + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOW_IN_PROGRESS Scan is in progress + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * + */ +int bt_adapter_le_unregister_all_scan_filters(void); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Set advertising filter policy to use white list + * @since_tizen 2.4 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * + * @param[in] advertiser The handle of advertiser + * @param[in] filter_policy The filter policy of advertising + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_NOW_IN_PROGRESS Operation is now in progress + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * + * @see bt_adapter_le_start_advertising_new() + */ +int bt_adapter_le_set_advertising_filter_policy(bt_advertiser_h advertiser, bt_adapter_le_advertising_filter_policy_e filter_policy); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Gets a connection state + * @since_tizen 2.4 + * + * @param[in] remote_address The address of the remote Bluetooth device + * @param[in] link_type The link type to get a connection state + * @param[out] connected The connection state + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + */ +int bt_device_get_connection_state(const char *remote_address, bt_device_connection_link_type_e link_type, bool *connected); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE + * @brief Registers a rfcomm server socket with a specific UUID. Activation by dbus is possible when the profile is connected. + * @since_tizen 2.4 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * + * @remarks A socket can be destroyed by bt_socket_destroy_rfcomm_ex(). + * Application should call this API to receive a connection event when launched again by dbus. + * + * @param[in] uuid The UUID of service to provide + * @param[in] bus_name bus_name of the application which is provided in service file. + * @param[in] object_path dbus of the application + * @return 0 on success, otherwise a negative error value. + * + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_NOW_IN_PROGRESS Already registered + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * + * @see bt_socket_listen_and_accept_rfcomm_ex() + * @see bt_socket_destroy_rfcomm_ex() + */ +int bt_socket_create_rfcomm_ex(const char *uuid, const char *bus_name, const char *object_path); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE + * @brief Removes the rfcomm server socket which was created using bt_socket_create_rfcomm_ex(). + * @since_tizen 2.4 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @remarks If callback function bt_socket_connection_state_changed_cb() is set and the remote Bluetooth device is connected, + * then bt_socket_connection_state_changed_cb() will be called when this function is finished successfully. + * + * @param[in] uuid The UUID (which was created using bt_socket_create_rfcomm()) to destroy + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The socket must be created with bt_socket_create_rfcomm_ex(). + * @post If callback function bt_socket_connection_state_changed_cb() is set and the remote Bluetooth device is connected, + * then bt_socket_connection_state_changed_cb() will be called. + * @see bt_socket_create_rfcomm_ex() + * @see bt_socket_connection_state_changed_cb() + * @see bt_socket_set_connection_state_changed_cb() + * @see bt_socket_unset_connection_state_changed_cb() + */ +int bt_socket_destroy_rfcomm_ex(const char *uuid); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE + * @brief Starts listening on passed rfcomm socket and accepts connection requests. Activation by dbus is possible when the profile is connected. + * @since_tizen 2.4 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @details Pop-up is shown automatically when a RFCOMM connection is requested. + * bt_socket_connection_state_changed_cb() will be called with + * #BT_SOCKET_CONNECTED if you click "yes" and connection is finished successfully. + * @param[in] uuid The UUID of service to provide + * @param[in] max_pending_connections The maximum number of pending connections + * @param[in] bus_name bus_name of the application which is provided in service file. + * @param[in] object_path dbus of the application + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The socket must be created with bt_socket_create_rfcomm_ex(). + * @post If callback function bt_socket_connection_state_changed_cb() is set, + * then bt_socket_connection_state_changed_cb() will be called when the remote Bluetooth device is connected. + * @see bt_socket_create_rfcomm_ex() + * @see bt_socket_connection_state_changed_cb() + * @see bt_socket_set_connection_state_changed_cb() + * @see bt_socket_unset_connection_state_changed_cb() + */ +int bt_socket_listen_and_accept_rfcomm_ex(const char *uuid, int max_pending_connections, const char* bus_name, const char *object_path); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Checks whether the remoted device is wbs (Wide Band Speech) mode or not. + * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif + * @param[out] wbs_mode The wbs status: (@c true = wide band speech, @c false = narrow band speech) + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * @pre The remote device is connected by bt_audio_connect() with #BT_AUDIO_PROFILE_TYPE_HSP_HFP service. + * @see bt_audio_connect() + */ +int bt_ag_is_wbs_mode(bool *wbs_mode); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Gets the HF(Hands-Free) profile connected status for AG role. + * @since_tizen 2.4 + * @param[out] connected the connected status: (@c true = connected , @c false = not connected ) + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + */ +int bt_ag_is_connected(bool *connected); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_HF_MODULE + * @brief Registers a callback function that will be invoked when the SCO(Synchronous Connection Oriented link) state is changed. + * @since_tizen @if MOBILE @elseif WEARABLE 2.3.1 @endif + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * @pre The Bluetooth audio service must be initialized with bt_audio_initialize(). + * @see bt_audio_initialize() + * @see bt_ag_sco_state_changed_cb() + * @see bt_ag_unset_sco_state_changed_cb() + */ +int bt_hf_set_sco_state_changed_cb(bt_hf_sco_state_changed_cb callback, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_HF_MODULE + * @brief Unregisters a callback function that will be invoked when the SCO(Synchronous Connection Oriented link) state is changed. + * @since_tizen @if MOBILE @elseif WEARABLE 2.3.1 @endif + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * @pre The Bluetooth audio service must be initialized with bt_audio_initialize(). + * @see bt_audio_initialize() + * @see bt_ag_sco_state_changed_cb() + * @see bt_ag_set_sco_state_changed_cb() + */ +int bt_hf_unset_sco_state_changed_cb(void); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_HF_MODULE + * @brief Registers a callback function that will be invoked when a call handling event happened from Hands-Free. + * @since_tizen @if MOBILE @elseif WEARABLE 2.3.1 @endif + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * @pre The Bluetooth audio service must be initialized with bt_audio_initialize(). + * @see bt_audio_initialize() + * @see bt_ag_call_handling_event_cb() + * @see bt_ag_unset_call_handling_event_cb() + */ +int bt_hf_set_call_handling_event_cb(bt_hf_call_handling_event_cb callback, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_HF_MODULE + * @brief Unregisters a callback function that will be invoked when a call handling event happened from Hands-Free. + * @since_tizen @if MOBILE @elseif WEARABLE 2.3.1 @endif + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * @pre The Bluetooth audio service must be initialized with bt_audio_initialize(). + * @see bt_audio_initialize() + * @see bt_ag_call_handling_event_cb() + * @see bt_ag_set_call_handling_event_cb() + */ +int bt_hf_unset_call_handling_event_cb(void); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_HF_MODULE + * @brief Registers a callback function that will be invoked when a multi call handling event happened from Hands-Free. + * @since_tizen @if MOBILE @elseif WEARABLE 2.3.1 @endif + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * @pre The Bluetooth audio service must be initialized with bt_audio_initialize(). + * @see bt_audio_initialize() + * @see bt_ag_multi_call_handling_event_cb() + * @see bt_ag_unset_multi_call_handling_event_cb() + */ +int bt_hf_set_multi_call_handling_event_cb(bt_hf_multi_call_handling_event_cb callback, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_HF_MODULE + * @brief Unregisters a callback function that will be invoked when a multi call handling event happened from Hands-Free. + * @since_tizen @if MOBILE @elseif WEARABLE 2.3.1 @endif + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * @pre The Bluetooth audio service must be initialized with bt_audio_initialize(). + * @see bt_audio_initialize() + * @see bt_ag_multi_call_handling_event_cb() + * @see bt_ag_set_multi_call_handling_event_cb() + */ +int bt_hf_unset_multi_call_handling_event_cb(void); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_HF_MODULE + * @brief Initializes the Bluetooth HF profile related with audio. + * @since_tizen @if MOBILE @elseif WEARABLE 2.3.1 @endif + * @remarks This function must be called before Bluetooth profiles related with audio starts. + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @see bt_hf_deinitialize() + */ +int bt_hf_initialize(void); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_HF_MODULE + * @brief Deinitializes the Bluetooth HF profile related with audio. + * @since_tizen @if MOBILE @elseif WEARABLE 2.3.1 @endif + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * @pre The Bluetooth audio service must be initialized with bt_audio_initialize(). + * @see bt_audio_initialize() + */ +int bt_hf_deinitialize(void); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_HF_MODULE + * @brief Notifies the call event to the remote bluetooth device. + * @since_tizen @if MOBILE @elseif WEARABLE 2.3.1 @endif + * @privlevel platform + * @privilege http://tizen.org/privilege/bluetooth.admin + * @remarks Before notifying #BT_HF_CALL_EVENT_ANSWERED or #BT_HF_CALL_EVENT_DIALING, you should open SCO(Synchronous Connection Oriented link) + * if Bluetooth Hands-Free need SCO connection. + * @param[in] event The call event + * @param[in] call_id The call ID + * @param[in] phone_number The phone number. You must set this value in case of #BT_HF_CALL_EVENT_DIALING and #BT_HF_CALL_EVENT_INCOMING. + * In other cases, this value can be NULL. + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * @pre The Bluetooth audio device must be connected with bt_audio_connect(). + * @see bt_audio_connect() + */ +int bt_hf_notify_call_event(bt_hf_call_event_e event, char *phone_number); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_HF_MODULE + * @brief Notifies the speaker gain to the remote device. + * @since_tizen @if MOBILE @elseif WEARABLE 2.3.1 @endif + * @privlevel platform + * @privilege http://tizen.org/privilege/bluetooth.admin + * @details This function sends a signal to the remote device. This signal has the gain value. + * @a gain is represented on a scale from 0 to 15. This value is absolute value relating to a particular volume level. + * When the speaker gain of remote device is changed to the requested gain, bt_audio_speaker_gain_changed_cb() will be called. + * @param[in] gain The gain of speaker (0 ~ 15) + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * @pre The remote device is connected by bt_audio_connect() with #BT_AUDIO_PROFILE_TYPE_HSP_HFP service. + * @see bt_hf_get_speaker_gain() + * @see bt_hf_set_speaker_gain_changed_cb() + * @see bt_hf_unset_speaker_gain_changed_cb() + */ +int bt_hf_notify_speaker_gain(int gain); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_HF_MODULE + * @brief Registers a callback function that will be invoked when the speaker gain of the remote device is changed. + * @since_tizen @if MOBILE @elseif WEARABLE 2.3.1 @endif + * @details This function let you know the change of the speaker gain of the remote device. + * @a gain is represented on a scale from 0 to 15. This value is absolute value relating to a particular volume level. + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * @pre The Bluetooth audio service must be initialized with bt_audio_initialize(). + * @see bt_audio_initialize() + * @see bt_hf_unset_speaker_gain_changed_cb() + */ +int bt_hf_set_speaker_gain_changed_cb(bt_hf_speaker_gain_changed_cb callback, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_HF_MODULE + * @brief Unregisters a callback function that will be invoked when the speaker gain of the remote device is changed. + * @since_tizen @if MOBILE @elseif WEARABLE 2.3.1 @endif + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * @pre The Bluetooth audio service must be initialized with bt_audio_initialize(). + * @see bt_audio_initialize() + * @see bt_hf_set_speaker_gain_changed_cb() + */ +int bt_hf_unset_speaker_gain_changed_cb(void); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_HF_MODULE + * @brief Notifies the state of voice recognition. + * @since_tizen @if MOBILE @elseif WEARABLE 2.3.1 @endif + * @privlevel platform + * @privilege http://tizen.org/privilege/bluetooth.admin + * @param[in] state The state of voice recognition: (@c true = enabled, @c false = disabled) + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * @pre The Bluetooth audio device must be connected with bt_audio_connect(). + * @see bt_audio_connect() + */ +int bt_hf_notify_voice_recognition_state(bool state); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_HF_MODULE + * @brief Registers a callback function that will be invoked when a call status event happened from Hands-Free. + * @since_tizen @if MOBILE @elseif WEARABLE 2.3.1 @endif + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * @pre The Bluetooth audio service must be initialized with bt_audio_initialize(). + * @see bt_audio_initialize() + * @see bt_hf_unset_call_status_updated_event_cb() + */ +int bt_hf_set_call_status_updated_event_cb(bt_hf_call_status_updated_event_cb callback, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_HF_MODULE + * @brief Unregisters a callback function that will be invoked when a call status event happened from Hands-Free. + * @since_tizen @if MOBILE @elseif WEARABLE 2.3.1 @endif + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * @pre The Bluetooth audio service must be initialized with bt_audio_initialize(). + * @see bt_audio_initialize() + * @see bt_hf_set_call_status_updated_event_cb() + */ +int bt_hf_unset_call_status_updated_event_cb(void); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_HF_MODULE + * @brief Closes an opened SCO(Synchronous Connection Oriented link), synchronously. + * @since_tizen @if MOBILE @elseif WEARABLE 2.3.1 @endif + * @privlevel platform + * @privilege http://tizen.org/privilege/bluetooth.admin + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + */ +int bt_hf_close_sco(void); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_HF_MODULE + * @brief Sends the DTMF(Dual Tone Multi Frequency). + * @since_tizen @if MOBILE @elseif WEARABLE 2.3.1 @endif + * @privlevel platform + * @privilege http://tizen.org/privilege/bluetooth.admin + * @param[in] dtmf The DTMF to send + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * @pre The Bluetooth audio device must be connected with bt_audio_connect(). + * @see bt_audio_connect() + */ +int bt_hf_send_dtmf(char *dtmf); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_HF_MODULE + * @brief Gets the HF(Hands-Free) profile connected status for HF role. + * @since_tizen @if MOBILE @elseif WEARABLE 2.3.1 @endif + * @param[out] connected the connected status: (@c true = connected , @c false = not connected ) + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + */ +int bt_hf_is_connected(bool *connected); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_HF_MODULE + * @brief Checks whether an opened SCO(Synchronous Connection Oriented link) exists or not. + * @since_tizen @if MOBILE @elseif WEARABLE 2.3.1 @endif + * + * @param[out] opened The SCO status: (@c true = opened, @c false = not opened) + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth audio device must be connected with bt_audio_connect(). + * @see bt_audio_connect() + */ +int bt_hf_is_sco_opened(bool *opened); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_HF_MODULE + * @brief Gets the codec ID. + * @since_tizen @if MOBILE @elseif WEARABLE 2.3.1 @endif + * @remarks The @a codec_id must be released with free() by you. + * + * @param[out] codec_id The codec ID + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth audio device must be connected with bt_audio_connect(). + * @see bt_audio_connect() + */ +int bt_hf_get_codec_id(unsigned int *codec_id); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_HF_MODULE + * @brief Gets the call status information list. + * @since_tizen @if MOBILE @elseif WEARABLE 2.3.1 @endif + * @remarks The @a call_list must be released with bt_hf_free_call_status_info_list() by you. + * @remarks call_info_list has elements which consist of bt_hf_call_status_info_s + * + * @param[out] call_list The call status information list + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth audio device must be connected with bt_audio_connect(). + * @see bt_hf_call_status_info_s + * @see bt_audio_connect() + */ +int bt_hf_get_call_status_info_list(GSList **call_list); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_HF_MODULE + * @brief Frees the call status information list. + * @since_tizen @if MOBILE @elseif WEARABLE 2.3.1 @endif + * + * @param[in] call_list The call status information list + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_hf_get_call_status_info_list() + */ +int bt_hf_free_call_status_info_list(GSList *call_list); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_PBAP_MODULE + * @brief Initializes the Bluetooth PBAP Client. + * @since_tizen @if MOBILE @elseif WEARABLE 2.3.1 @endif + * @details Initializes the Bluetooth PBAP Client. + * This initialization is necessary to call other PBAP client APIs. + * + * @remarks This function must be called to initiatize Bluetooth PBAP client. You must free all resources of the Bluetooth service + * by calling bt_pbap_deinit() if Bluetooth PBAP Client is no longer needed. + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * + * @see bt_pbap_deinit() + * @see bt_pbap_connect() + * @see bt_pbap_disconnect() + * @see bt_pbap_get_phonebook_size() + * @see bt_pbap_get_phonebook() + * @see bt_pbap_get_list() + * @see bt_pbap_pull_vcard() + * @see bt_pbap_phonebook_search() + */ +int bt_pbap_init(void); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_PBAP_MODULE + * @brief De-initializes the Bluetooth PBAP Client. + * @since_tizen @if MOBILE @elseif WEARABLE 2.3.1 @endif + * @details De-Initializes the Bluetooth PBAP Client. + * This deinitialization must be done to free resource when PBAP client is not longer needed. + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * PBAP client must be initialized with bt_pbap_init() + * @see bt_pbap_deinit() + * @see bt_pbap_connect() + * @see bt_pbap_disconnect() + * @see bt_pbap_get_phonebook_size() + * @see bt_pbap_get_phonebook() + * @see bt_pbap_get_list() + * @see bt_pbap_pull_vcard() + * @see bt_pbap_phonebook_search() + */ +int bt_pbap_deinit(void); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_PBAP_MODULE + * @brief To connect to PBAP server + * @since_tizen @if MOBILE @elseif WEARABLE 2.3.1 @endif + * @privlevel platform + * @privilege http://tizen.org/privilege/bluetooth.admin + * + * @param[in] address The other device's address + * @param[in] Callback to be called when PBAP session is Connected. + * @param[in] user_data Data to be passed to PBAP enabled/disabled callback. + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Adapter is not enabled + * @retval #BLUETOOTH_ERROR_ALREADY_CONNECT PBAP client already connected + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * PBAP client must be initialized with bt_pbap_init() + * @see bt_pbap_disconnect() + */ +int bt_pbap_connect(const char *address, bt_pbap_enabled_cb callback, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_PBAP_MODULE + * @brief To disconnect from PBAP server + * @since_tizen @if MOBILE @elseif WEARABLE 2.3.1 @endif + * @privlevel platform + * @privilege http://tizen.org/privilege/bluetooth.admin + * + * @param[in] address The other device's address + * @param[in] Callback to be called when PBAP session is disconnected. + * @param[in] user_data Data to be passed to PBAP enabled/disabled callback. + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Adapter is not enabled + * @retval #BLUETOOTH_ERROR_NOT_CONNECTED PBAP Client is not connected + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * PBAP client must be initialized with bt_pbap_init() + * PBAP connection must be created with bt_pbap_connect(). + * + * @see bt_pbap_connect() + */ +int bt_pbap_disconnect(const char *address, bt_pbap_enabled_cb callback, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_PBAP_MODULE + * @brief To get size of phonebook from PBAP server + * @since_tizen @if MOBILE @elseif WEARABLE 2.3.1 @endif + * @privlevel platform + * @privilege http://tizen.org/privilege/bluetooth.admin + * + * @param[in] address The other device's address + * @param[in] source Source of Phonebook (Phone/SIM) + * @param[in] type Type of folder + * @param[in] Callback to be called when PBAP Phonebook Size is Returned. + * @param[in] user_data Data to be passed to the PBAP Phonebook Size callback. + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Adapter is not enabled + * @retval #BLUETOOTH_ERROR_NOT_CONNECTED PBAP Client is not connected + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * PBAP client must be initialized with bt_pbap_init() + * PBAP connection must be created with bt_pbap_connect(). + * + * @see bt_pbap_connect() + */ +int bt_pbap_get_phonebook_size(const char *address, bt_pbap_addressbook_source_e source, + bt_pbap_folder_type_e type, bt_pbap_phonebook_size_cb callback, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_PBAP_MODULE + * @brief To get contacts/call logs as vCards from PBAP server + * @since_tizen @if MOBILE @elseif WEARABLE 2.3.1 @endif + * @privlevel platform + * @privilege http://tizen.org/privilege/bluetooth.admin + * + * @param[in] address The other device's address + * @param[in] source Source of Phonebook (Phone/SIM) + * @param[in] type Type of folder + * @param[in] format Format of vCard + * @param[in] order Specifies which field shall be used to sort vCards. + * @param[in] offset vCards to be excluded from beginning. + * @param[in] maxlistcount Maximum number of vCards to be fetched + * @param[in] fields Fields of vCard to be fetched. + * @param[in] Callback to be called when PBAP Phonebook is Pulled. + * @param[in] user_data Data to be passed to the PBAP Phonebook Pull callback. + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Adapter is not enabled + * @retval #BLUETOOTH_ERROR_NOT_CONNECTED PBAP Client is not connected + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * PBAP client must be initialized with bt_pbap_init() + * PBAP connection must be created with bt_pbap_connect(). + * + * @see bt_pbap_connect() + */ +int bt_pbap_get_phonebook(const char *address, bt_pbap_addressbook_source_e source, + bt_pbap_folder_type_e type, bt_pbap_filter_vcard_format_e format, + bt_pbap_filter_sort_order_e order, unsigned short offset, + unsigned short maxlistcount, long long unsigned fields, + bt_pbap_phonebook_pull_cb callback, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_PBAP_MODULE + * @brief To get Contact or Call List from PBAP server + * @since_tizen @if MOBILE @elseif WEARABLE 2.3.1 @endif + * @privlevel platform + * @privilege http://tizen.org/privilege/bluetooth.admin + * + * @param[in] address The other device's address + * @param[in] source Source of Phonebook (Phone/SIM) + * @param[in] type Type of folder + * @param[in] order Specifies which field shall be used to sort vCards. + * @param[in] offset vCards to be excluded from beginning. + * @param[in] maxlistcount Maximum number of vCards to be fetched + * @param[in] Callback to be called when PBAP List is returned. + * @param[in] user_data Data to be passed to the PBAP Phonebook Pull callback. + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Adapter is not enabled + * @retval #BLUETOOTH_ERROR_NOT_CONNECTED PBAP Client is not connected + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * PBAP client must be initialized with bt_pbap_init() + * PBAP connection must be created with bt_pbap_connect(). + * + * @see bt_pbap_connect() + */ +int bt_pbap_get_list(const char *address, bt_pbap_addressbook_source_e source, + bt_pbap_folder_type_e type, bt_pbap_filter_sort_order_e order, + unsigned short offset, unsigned short maxlistcount, + bt_pbap_list_vcards_cb callback, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_PBAP_MODULE + * @brief To get a contact/call log from PBAP server + * @since_tizen @if MOBILE @elseif WEARABLE 2.3.1 @endif + * @privlevel platform + * @privilege http://tizen.org/privilege/bluetooth.admin + * + * @param[in] address The other device's address + * @param[in] source Source of Phonebook (Phone/SIM) + * @param[in] type Type of folder + * @param[in] index Handle of vCard to be fetched + * @param[in] format Format of vCard + * @param[in] fields Fields of vCard to be fetched. + * @param[in] Callback to be called when PBAP Phonebook is Pulled. + * @param[in] user_data Data to be passed to the PBAP Phonebook Pull callback. + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Adapter is not enabled + * @retval #BLUETOOTH_ERROR_NOT_CONNECTED PBAP Client is not connected + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * PBAP client must be initialized with bt_pbap_init() + * PBAP connection must be created with bt_pbap_connect(). + * + * @see bt_pbap_connect() + */ +int bt_pbap_pull_vcard(const char *address, bt_pbap_addressbook_source_e source, + bt_pbap_folder_type_e type, int index, + bt_pbap_filter_vcard_format_e format, long long unsigned fields, + bt_pbap_get_vcard_cb callback, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_PBAP_MODULE + * @brief To get Contact or Call List from PBAP server + * @since_tizen @if MOBILE @elseif WEARABLE 2.3.1 @endif + * @privlevel platform + * @privilege http://tizen.org/privilege/bluetooth.admin + * + * @param[in] address The other device's address + * @param[in] source Source of Phonebook (Phone/SIM) + * @param[in] type Type of folder + * @param[in] search_attribute field to be search + * @param[in] search_value pattern to be searched for + * @param[in] order Specifies which field shall be used to sort vCards. + * @param[in] offset vCards to be excluded from beginning. + * @param[in] maxlistcount Maximum number of vCards to be fetched + * @param[in] Callback to be called when PBAP List is returned. + * @param[in] user_data Data to be passed to the PBAP Phonebook Pull callback. + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Adapter is not enabled + * @retval #BLUETOOTH_ERROR_NOT_CONNECTED PBAP Client is not connected + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * PBAP client must be initialized with bt_pbap_init() + * PBAP connection must be created with bt_pbap_connect(). + * + * @see bt_pbap_connect() + */ +int bt_pbap_phonebook_search(const char *address, + bt_pbap_addressbook_source_e source, bt_pbap_folder_type_e type, + bt_pbap_search_field_e search_attribute, const char *search_value, + bt_pbap_filter_sort_order_e order, + unsigned short offset, unsigned short maxlistcount, + bt_pbap_search_list_cb callback, void *user_data); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Gets the specification name from the UUID + * @since_tizen 2.4 + * + * @remarks @a name must be released with free() by you. + * + * @param[in] uuid The UUID + * @param[out] name The specification name which defined from www.bluetooth.org + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_gatt_get_uuid() + */ +int bt_gatt_get_uuid_specification_name(const char *uuid, char **name); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Destroys the GATT handle + * @since_tizen 2.4 + * + * @param[in] gatt_handle The handle of service, characteristic or descriptor + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_gatt_service_create() + * @see bt_gatt_characteristic_create() + * @see bt_gatt_descriptor_create() + */ +int bt_gatt_destroy(bt_gatt_h gatt_handle); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Gets the permissions which a characteristic or descriptor's GATT handle has + * @since_tizen 2.4 + * + * @param[in] gatt_handle The handle of a characteristic or descriptor + * @param[out] permissions The permissions which a characteristic or descriptor's GATT handle has. + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_gatt_characteristic_create() + * @see bt_gatt_descriptor_create() + * @see bt_gatt_permission_e + */ +int bt_gatt_get_permissions(bt_gatt_h gatt_handle, int *permissions); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Updates the permissions which a characteristic or descriptor's GATT handle has + * @since_tizen 2.4 + * + * @param[in] gatt_handle The handle of a characteristic or descriptor + * @param[in] permissions The permissions to be updated + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_gatt_characteristic_create() + * @see bt_gatt_descriptor_create() + * @see bt_gatt_permission_e + */ +int bt_gatt_set_permissions(bt_gatt_h gatt_handle, int permissions); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Creates the GATT service + * @since_tizen 2.4 + * + * @param[in] uuid The UUID of the service + * @param[in] type The type of the service + * @param[out] service The GATT handle of the created service + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_OUT_OF_MEMORY Out of memory + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_gatt_destroy() + */ +int bt_gatt_service_create(const char *uuid, bt_gatt_service_type_e type, + bt_gatt_h *service); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Adds a characteristic to a specified service + * @since_tizen 2.4 + * + * @param[in] service The service's GATT handle + * @param[in] characteristic The characteristic's GATT handle to be added + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_gatt_service_create() + * @see bt_gatt_characteristic_create() + */ +int bt_gatt_service_add_characteristic(bt_gatt_h service, + bt_gatt_h characteristic); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Adds a service to a specified service as included service + * @since_tizen 2.4 + * + * @param[in] service The service's GATT handle + * @param[in] included_service The service's GATT handle to be added as included service + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_gatt_service_create() + */ +int bt_gatt_service_add_included_service(bt_gatt_h service, + bt_gatt_h included_service); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Gets the GATT server handle to which the specified service belongs + * @since_tizen 2.4 + * + * @param[in] service The service's GATT handle + * @param[out] server The GATT server handle to which @a service belongs + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_gatt_server_create() + * @see bt_gatt_service_create() + * @see bt_gatt_server_register_service() + */ +int bt_gatt_service_get_server(bt_gatt_h service, bt_gatt_server_h *server); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Creates the GATT characteristic + * @since_tizen 2.4 + * + * @param[in] uuid The UUID of the characteristic + * @param[in] permissions the permissions of the characteristic + * @param[in] properties The properties of the characteristic + * @param[in] Value The value(byte stream) of the characteristic + * @param[in] value_length The length of @a value + * @param[out] characteristic The GATT handle of the created characteristic + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_OUT_OF_MEMORY Out of memory + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_gatt_destroy() + */ +int bt_gatt_characteristic_create(const char *uuid, int permissions, + int properties, const char *value, int value_length, + bt_gatt_h *characteristic); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Adds a descriptor to a specified characteristic + * @since_tizen 2.4 + * + * @param[in] characteristic The GATT handle of the characteristic + * @param[in] descriptor The descriptor's GATT handle to be added + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_gatt_characteristic_create() + * @see bt_gatt_descriptor_create() + */ +int bt_gatt_characteristic_add_descriptor(bt_gatt_h characteristic, + bt_gatt_h descriptor); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Creates the GATT characteristic descriptor + * @since_tizen 2.4 + * + * @param[in] uuid The UUID of the descriptor + * @param[in] permissions The permissions of the descriptor + * @param[in] value The value(byte stream) associated with the descriptor + * @param[in] value_length The length of @a value + * @param[out] descriptor The GATT handle of the created characteristic descriptor + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_OUT_OF_MEMORY Out of memory + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_gatt_destroy() + */ +int bt_gatt_descriptor_create(const char *uuid, int permissions, + const char *value, int value_length, + bt_gatt_h *descriptor); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Initializes the GATT Server + * @since_tizen 2.4 + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * @see bt_gatt_server_deinitialize() + */ +int bt_gatt_server_initialize(void); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief DeInitializes the GATT server + * @since_tizen 2.4 + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * @see bt_gatt_server_initialize() + */ +int bt_gatt_server_deinitialize(void); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Creates the GATT server's handle + * @since_tizen 2.4 + * + * @param[out] server The GATT server's handle + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_OUT_OF_MEMORY Out of memory + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_gatt_server_destroy() + */ +int bt_gatt_server_create(bt_gatt_server_h *server); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Destroys the GATT server's handle + * @since_tizen 2.4 + * + * @remarks All registered services to GATT server are unregistered + * + * @param[in] server The GATT server's handle + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_gatt_server_create() + */ +int bt_gatt_server_destroy(bt_gatt_server_h server); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Registers a callback function to be invoked when a read request for a specified characteristic or descriptor is issued from a remote device(GATT client) + * @since_tizen 2.4 + * + * @param[in] gatt_handle The GATT handle of a characteristic or descriptor + * @param[in] callback The callback to be invoked + * @param[in] user_data The user data to be passed to @a callback function + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_gatt_server_read_value_requested_cb() + * @see bt_gatt_server_send_response() + */ +int bt_gatt_server_set_read_value_requested_cb(bt_gatt_h gatt_handle, + bt_gatt_server_read_value_requested_cb callback, + void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Registers a callback function to be invoked when a value of a characteristic or descriptor has been changed by a remote device(GATT client)'s request + * @since_tizen 2.4 + * + * @param[in] gatt_handle The GATT handle of a characteristic or descriptor + * @param[in] callback The callback to be invoked + * @param[in] user_data The user data to be passed to @a callback function + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_gatt_server_value_changed_cb() + */ +int bt_gatt_server_set_value_changed_cb(bt_gatt_h gatt_handle, + bt_gatt_server_value_changed_cb callback, + void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Registers a specified service to the specified GATT server that the local device is hosting + * @since_tizen 2.4 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * + * @param[in] server The GATT server that local device is hosting + * @param[in] service The service, which needs to be registered in @a server + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_ALREADY_DONE Operation is already done + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_gatt_server_create() + * @see bt_gatt_service_create() + * @see bt_gatt_server_unregister_service() + */ +int bt_gatt_server_register_service(bt_gatt_server_h server, bt_gatt_h service); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Unregisters a specified service from the specified GATT server that the local device is hosting + * @since_tizen 2.4 + * + * @param[in] server The GATT server that local device is hosting + * @param[in] service The service, which needs to be unregistered from @a server + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_SERVICE_NOT_FOUND Service not found + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_gatt_server_register_service() + */ +int bt_gatt_server_unregister_service(bt_gatt_server_h server, bt_gatt_h service); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Unregisters all services from the specified GATT server that the local device is hosting + * @since_tizen 2.4 + * + * @param[in] server The GATT server that local device is hosting + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_gatt_server_register_service() + */ +int bt_gatt_server_unregister_all_services(bt_gatt_server_h server); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Sends a response to the remote device as a result of a read request + * @since_tizen 2.4 + * + * @remarks Until this function is called, a read request is not finished. + * + * @param[in] request_id The identification of a read request + * @param[in] offset The offset from where a value is read + * @param[in] value The value to be sent. It will be sent from @a offset. If it is NULL, a requested GATT handle's value will be sent from @a offset. + * @param[in] value_length Value Length + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_gatt_server_read_value_requested_cb() + */ +int bt_gatt_server_send_response(int request_id, + int offset, char *value, int value_length); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Notifys a value change of the characteristic to the remote devices which enable a Client Characteristic Configuration Descriptor + * @since_tizen 2.4 + * + * @param[in] characteristic The characteristic which has a changed value + * @param[in] need_confirm If it is true, an indication is sent. If it is false, a notification is sent. + * @param[in] callback The function to be invoked on each remote device when a sending operation is done + * @param[in] user_data The user data to be passed to @a callback function + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_gatt_server_notification_sent_cb() + */ +int bt_gatt_server_notify(bt_gatt_h characteristic, bool need_confirm, + bt_gatt_server_notification_sent_cb callback, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Gets a service's GATT handle which has specific UUID + * @since_tizen 2.4 + * + * @remark The returned GATT handle must not be freed by application. + * It will be freed when an associated server is destroyed by bt_gatt_server_destroy(). + * If there are multiple services which have same UUID, only the first matched one will be returned. + * + * @param[in] server The GATT server's handle + * @param[in] uuid The serivce's GATT handle which has this UUID will be returned if it exists + * @param[out] service The service's GATT handle which has @a uuid if it exists + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NO_DATA No data available + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + */ +int bt_gatt_server_get_service(bt_gatt_server_h server, const char *uuid, + bt_gatt_h *service); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Invokes @a callback function on each service that belongs to the specified GATT server + * @since_tizen 2.4 + * + * @param[in] server The GATT server's handle + * @param[in] callback The function to be invoked on each service + * @param[in] user_data The user data to be passed to @a callback function + * @return 0 on success, otherwise a negative error value + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_gatt_foreach_cb() + */ +int bt_gatt_server_foreach_services(bt_gatt_server_h server, + bt_gatt_foreach_cb callback, void *user_data); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief Registers a callback function that will be invoked when the song position is changed by the remote target device. + * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized by bt_initialize(). + * @see bt_initialize() + * @see bt_avrcp_unset_song_position_changed_cb() + */ +int bt_avrcp_set_song_position_changed_cb(bt_avrcp_song_position_changed_cb callback, void *user_data); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief Unregisters a callback function that will be invoked when the song position is changed by the remote target device. + * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized by bt_initialize(). + * @see bt_initialize() + * @see bt_avrcp_set_song_position_changed_cb() + */ +int bt_avrcp_unset_song_position_changed_cb(void); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief Registers a callback function that will be invoked when the Play status is changed by the remote target device. + * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized by bt_initialize(). + * @see bt_initialize() + * @see bt_avrcp_unset_play_status_changed_cb() + */ +int bt_avrcp_set_play_status_changed_cb(bt_avrcp_play_status_changed_cb callback, void *user_data); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief Unregisters a callback function that will be invoked when the Play status is changed by the remote target device. + * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized by bt_initialize(). + * @see bt_initialize() + * @see bt_avrcp_unset_play_status_changed_cb() + */ +int bt_avrcp_unset_play_status_changed_cb(void); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief Registers a callback function that will be invoked when the track metadata is changed by the remote target device. + * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized by bt_initialize(). + * @see bt_initialize() + * @see bt_avrcp_unset_track_info_changed_cb() + */ +int bt_avrcp_set_track_info_changed_cb(bt_avrcp_track_info_changed_cb callback, void *user_data); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief Unregisters a callback function that will be invoked when the track metadata is changed by the remote target device. + * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized by bt_initialize(). + * @see bt_initialize() + * @see bt_avrcp_set_track_info_changed_cb() + */ +int bt_avrcp_unset_track_info_changed_cb(void); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_MODULE + * @brief Registers a callback function that will be invoked when the A2DP Source connection state is changed. + * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth audio service must be initialized with bt_audio_initialize(). + * @see bt_audio_initialize() + * @see bt_audio_connection_state_changed_cb() + */ +int bt_a2dp_source_audio_set_connection_state_changed_cb(bt_audio_connection_state_changed_cb callback, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_MODULE + * @brief Unregisters a callback function that will be invoked when the A2DP Source connection state is changed. + * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth audio service must be initialized with bt_audio_initialize(). + * @see bt_audio_initialize() + * @see bt_audio_connection_state_changed_cb() + * @see bt_audio_set_connection_state_changed_cb() + */ +int bt_a2dp_source_audio_unset_connection_state_changed_cb(void); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief Initializes the Bluetooth AVRCP(Audio/Video Remote Control Profile) service. + * @since_tizen 2.4 + * @remarks This function must be called before Bluetooth AVRCP service. \n + * You must free all resources of the this service by calling bt_avrcp_control_deinitialize() + * if Bluetooth AVRCP service is no longer needed. + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @param[in] callback The callback function called when the connection state is changed + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @see bt_initialize() + * @see bt_avrcp_control_deinitialize() + */ +int bt_avrcp_control_initialize(bt_avrcp_control_connection_state_changed_cb callback, void *user_data); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief Deinitializes the Bluetooth AVRCP(Audio/Video Remote Control Profile) service. + * @since_tizen 2.4 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * @pre The Bluetooth audio service must be initialized with bt_avrcp_control_initialize(). + * @see bt_avrcp_control_initialize() + */ +int bt_avrcp_control_deinitialize(void); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief Connects the Bluetooth AVRCP(Audio/Video Remote Control Profile) service. + * @since_tizen 2.4 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * @pre The Bluetooth audio service must be initialized with bt_avrcp_control_initialize(). + * @see bt_avrcp_control_initialize() + */ +int bt_avrcp_control_connect(const char *remote_address); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief Disconnects the Bluetooth AVRCP(Audio/Video Remote Control Profile) service. + * @since_tizen 2.4 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * @pre The Bluetooth audio service must be initialized with bt_avrcp_control_initialize(). + * @see bt_avrcp_control_initialize() + * @see bt_avrcp_control_connect() + */ +int bt_avrcp_control_disconnect(const char *remote_address); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief Handle the Bluetooth AVRCP(Audio/Video Remote Control Profile) commands. + * @since_tizen 2.4 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @param[in] AVRCP Commands Play, Pause, Next, Rewind. + * @return 0 on success, otherwise a negative error value. + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * @pre The Bluetooth audio service must be initialized with bt_avrcp_control_initialize(). + * @see bt_avrcp_control_initialize() + * @see bt_avrcp_control_connect() + */ +int bt_avrcp_control_send_player_command(bt_avrcp_player_command_e cmd); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief send the equalizer change to the remote device. + * @since_tizen 2.4 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @param[in] state To set the equalizer state ON/OFF + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The remote device must be connected. + * @see bt_avrcp_target_connection_state_changed_cb() + * @see bt_avrcp_target_initialize() + */ +int bt_avrcp_control_set_equalizer_state(bt_avrcp_equalizer_state_e state); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief get the the equalize state of the remote device. + * @since_tizen 2.4 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @param[in] equalizer To get the equalizer value ON/OFF + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The remote device must be connected. + * @see bt_avrcp_target_connection_state_changed_cb() + * @see bt_avrcp_target_initialize() + */ +int bt_avrcp_control_get_equalizer_state(bt_avrcp_equalizer_state_e *state); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief send the repeat change to the remote device. + * @since_tizen 2.4 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @param[in] Mode To set the repeat mode OFF, SINGLE, ALL + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The remote device must be connected. + * @see bt_avrcp_target_connection_state_changed_cb() + * @see bt_avrcp_target_initialize() + */ +int bt_avrcp_control_set_repeat_mode(bt_avrcp_repeat_mode_e mode); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief get the repeat state of the remote device. + * @since_tizen 2.4 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @param[in] Mode To get the repeat mode OFF, SINGLE, ALL + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The remote device must be connected. + * @see bt_avrcp_target_connection_state_changed_cb() + * @see bt_avrcp_target_initialize() + */ +int bt_avrcp_control_get_repeat_mode(bt_avrcp_repeat_mode_e *mode); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief send the shuffle change to the remote device. + * @since_tizen 2.4 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @param[in] Mode To set the shuffle mode OFF, GROUP, ALL + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The remote device must be connected. + * @see bt_avrcp_target_connection_state_changed_cb() + * @see bt_avrcp_target_initialize() + */ +int bt_avrcp_control_set_shuffle_mode(bt_avrcp_shuffle_mode_e mode); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief get the shuffle state of the remote device. + * @since_tizen 2.4 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @param[in] Mode To get the shuffle mode OFF, GROUP, ALL + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The remote device must be connected. + * @see bt_avrcp_target_connection_state_changed_cb() + * @see bt_avrcp_target_initialize() + */ +int bt_avrcp_control_get_shuffle_mode(bt_avrcp_shuffle_mode_e *mode); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief send the scan mode change to the remote device. + * @since_tizen 2.4 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @param[in] Mode To set the scan mode OFF, GROUP, ALL + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The remote device must be connected. + * @see bt_avrcp_target_connection_state_changed_cb() + * @see bt_avrcp_target_initialize() + */ +int bt_avrcp_control_set_scan_mode(bt_avrcp_scan_mode_e mode); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief get the scan mode of the remote device. + * @since_tizen 2.4 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @param[in] Mode To get the scan mode OFF, GROUP, ALL + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The remote device must be connected. + * @see bt_avrcp_target_connection_state_changed_cb() + * @see bt_avrcp_target_initialize() + */ +int bt_avrcp_control_get_scan_mode(bt_avrcp_scan_mode_e *mode); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief get the song position vale of the remote device. + * @since_tizen 2.4 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @param[in] Mode To get the position value in milliseconds + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The remote device must be connected. + * @see bt_avrcp_target_connection_state_changed_cb() + * @see bt_avrcp_target_initialize() + */ +int bt_avrcp_control_get_position(unsigned int *position); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief get the play status of the remote device. + * @since_tizen 2.4 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @param[in] Mode To get the play status PLAYING, STOPPED... + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The remote device must be connected. + * @see bt_avrcp_target_connection_state_changed_cb() + * @see bt_avrcp_target_initialize() + */ +int bt_avrcp_control_get_play_status(bt_avrcp_player_state_e *status); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief get the metadata of the remote device. + * @since_tizen 2.4 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @param[in] track To get the metadata of track played in remote device. + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The remote device must be connected. + * @see bt_avrcp_target_connection_state_changed_cb() + * @see bt_avrcp_target_initialize() + */ +int bt_avrcp_control_get_track_info(bt_avrcp_metadata_attributes_info_s **track); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief to free the metadata staructure. + * @since_tizen 2.4 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @param[in] track To free the memory of metadata structure. + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @pre track should point to valid metadata address. + * @see bt_avrcp_control_get_track_info() + * @see bt_avrcp_target_initialize() + */ +int bt_avrcp_control_free_track_info(bt_avrcp_metadata_attributes_info_s *track); + +/** + * @} + */ + + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif // __TIZEN_NETWORK_BLUETOOTH_INTERNAL_H__ diff --git a/include/wearable/bluetooth_type.h b/include/wearable/bluetooth_type.h new file mode 100644 index 0000000..6690427 --- /dev/null +++ b/include/wearable/bluetooth_type.h @@ -0,0 +1,1608 @@ +/* + * 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 __TIZEN_NETWORK_BLUETOOTH_TYPE_H__ +#define __TIZEN_NETWORK_BLUETOOTH_TYPE_H__ + + #ifdef __cplusplus +extern "C" +{ +#endif /* __cplusplus */ + +/** + * @file bluetooth_type.h + * @brief API to control the Bluetooth adapter, devices and communications. + * @ingroup CAPI_NETWORK_BLUETOOTH_TYPE_MODULE + */ + + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_MODULE + * @brief Enumerations of Bluetooth error codes. + * @since_tizen 2.3.1 + */ +typedef enum +{ + BT_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful*/ + BT_ERROR_CANCELLED = TIZEN_ERROR_CANCELED, /**< Operation cancelled */ + BT_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid parameter */ + BT_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of memory */ + BT_ERROR_RESOURCE_BUSY = TIZEN_ERROR_RESOURCE_BUSY, /**< Device or resource busy */ + BT_ERROR_TIMED_OUT = TIZEN_ERROR_TIMED_OUT, /**< Timeout error */ + BT_ERROR_NOW_IN_PROGRESS = TIZEN_ERROR_NOW_IN_PROGRESS, /**< Operation now in progress */ + BT_ERROR_NOT_SUPPORTED = TIZEN_ERROR_NOT_SUPPORTED, /**< BT is Not Supported */ + BT_ERROR_PERMISSION_DENIED = TIZEN_ERROR_PERMISSION_DENIED, /**< Permission denied */ + BT_ERROR_QUOTA_EXCEEDED = TIZEN_ERROR_QUOTA_EXCEEDED, /**< Quota exceeded */ + BT_ERROR_NO_DATA = TIZEN_ERROR_NO_DATA, /**< No data available */ + BT_ERROR_NOT_INITIALIZED = TIZEN_ERROR_BLUETOOTH|0x0101, /**< Local adapter not initialized */ + BT_ERROR_NOT_ENABLED = TIZEN_ERROR_BLUETOOTH|0x0102, /**< Local adapter not enabled */ + BT_ERROR_ALREADY_DONE = TIZEN_ERROR_BLUETOOTH|0x0103, /**< Operation already done */ + BT_ERROR_OPERATION_FAILED = TIZEN_ERROR_BLUETOOTH|0x0104, /**< Operation failed */ + BT_ERROR_NOT_IN_PROGRESS = TIZEN_ERROR_BLUETOOTH|0x0105, /**< Operation not in progress */ + BT_ERROR_REMOTE_DEVICE_NOT_BONDED = TIZEN_ERROR_BLUETOOTH|0x0106, /**< Remote device not bonded */ + BT_ERROR_AUTH_REJECTED = TIZEN_ERROR_BLUETOOTH|0x0107, /**< Authentication rejected */ + BT_ERROR_AUTH_FAILED = TIZEN_ERROR_BLUETOOTH|0x0108, /**< Authentication failed */ + BT_ERROR_REMOTE_DEVICE_NOT_FOUND = TIZEN_ERROR_BLUETOOTH|0x0109, /**< Remote device not found */ + BT_ERROR_SERVICE_SEARCH_FAILED = TIZEN_ERROR_BLUETOOTH|0x010A, /**< Service search failed */ + BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED = TIZEN_ERROR_BLUETOOTH|0x010B, /**< Remote device is not connected */ + BT_ERROR_AGAIN = TIZEN_ERROR_BLUETOOTH|0x010C, /**< Resource temporarily unavailable */ + BT_ERROR_SERVICE_NOT_FOUND = TIZEN_ERROR_BLUETOOTH|0x010D, /**< Service Not Found */ +} bt_error_e; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Enumerations of the Bluetooth adapter state. + * @since_tizen 2.3.1 + */ +typedef enum +{ + BT_ADAPTER_DISABLED = 0x00, /**< Bluetooth adapter is disabled */ + BT_ADAPTER_ENABLED, /**< Bluetooth adapter is enabled */ +} bt_adapter_state_e; + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Enumerations of the Bluetooth adapter le state. + * @since_tizen 2.3.1 + */ +typedef enum +{ + BT_ADAPTER_LE_DISABLED = 0x00, /**< Bluetooth le is disabled */ + BT_ADAPTER_LE_ENABLED, /**< Bluetooth le is enabled */ +} bt_adapter_le_state_e; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Enumerations of the Bluetooth visibility mode. + * @since_tizen 2.3.1 + */ +typedef enum +{ + BT_ADAPTER_VISIBILITY_MODE_NON_DISCOVERABLE = 0x00, /**< Other devices cannot find your device via discovery */ + BT_ADAPTER_VISIBILITY_MODE_GENERAL_DISCOVERABLE, /**< Discoverable mode */ + BT_ADAPTER_VISIBILITY_MODE_LIMITED_DISCOVERABLE, /**< Discoverable mode with time limit. After specific period, + it is changed to #BT_ADAPTER_VISIBILITY_MODE_NON_DISCOVERABLE.*/ +} bt_adapter_visibility_mode_e; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Enumerations of the discovery state of Bluetooth device. + * @since_tizen 2.3.1 + */ +typedef enum +{ + BT_ADAPTER_DEVICE_DISCOVERY_STARTED, /**< Device discovery is started */ + BT_ADAPTER_DEVICE_DISCOVERY_FINISHED, /**< Device discovery is finished */ + BT_ADAPTER_DEVICE_DISCOVERY_FOUND, /**< The remote Bluetooth device is found */ +} bt_adapter_device_discovery_state_e; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Enumerations of the Bluetooth advertising state. + * @since_tizen 2.3.1 + */ +typedef enum { + BT_ADAPTER_LE_ADVERTISING_STOPPED = 0x00, /**< Bluetooth advertising is stopped */ + BT_ADAPTER_LE_ADVERTISING_STARTED, /**< Bluetooth advertising is started */ +} bt_adapter_le_advertising_state_e; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Enumerations of the Bluetooth advertising mode. + * @since_tizen 2.3.1 + */ +typedef enum +{ + BT_ADAPTER_LE_ADVERTISING_MODE_BALANCED, /**< Balanced advertising mode */ + BT_ADAPTER_LE_ADVERTISING_MODE_LOW_LATENCY, /**< Low latency advertising mode */ + BT_ADAPTER_LE_ADVERTISING_MODE_LOW_ENERGY /**< Low energy advertising mode */ +} bt_adapter_le_advertising_mode_e; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Enumerations of the Bluetooth advertising filter policy. + * @since_tizen 2.3.1 + */ +typedef enum { + BT_ADAPTER_LE_ADVERTISING_FILTER_DEFAULT = 0x00, /**< White list is not in use */ + BT_ADAPTER_LE_ADVERTISING_FILTER_ALLOW_SCAN_WL = 0x01, /**< Allow the scan + request that in the White list */ + BT_ADAPTER_LE_ADVERTISING_FILTER_ALLOW_CONN_WL = 0x02, /**< Allow the connectoin + request that in the White list */ + BT_ADAPTER_LE_ADVERTISING_FILTER_ALLOW_SCAN_CONN_WL = 0x03, /**< Allow the + scan and connectoin request that in the White list */ +} bt_adapter_le_advertising_filter_policy_e; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Enumerations of the Bluetooth LE packet type. + * @since_tizen 2.3.1 + */ +typedef enum { + BT_ADAPTER_LE_PACKET_ADVERTISING, /**< Advertising packet */ + BT_ADAPTER_LE_PACKET_SCAN_RESPONSE, /**< Sacn response packet */ +} bt_adapter_le_packet_type_e; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Enumerations of device disconnect reason. + * @since_tizen 2.3.1 + */ +typedef enum +{ + BT_DEVICE_DISCONNECT_REASON_UNKNOWN, /**< Disconnected by unknown reason */ + BT_DEVICE_DISCONNECT_REASON_TIMEOUT, /**< Disconnected by timeout */ + BT_DEVICE_DISCONNECT_REASON_LOCAL_HOST, /**< Disconnected by local host */ + BT_DEVICE_DISCONNECT_REASON_REMOTE, /**< Disconnected by remote */ +} bt_device_disconnect_reason_e; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Enumerations of connection link type. + * @since_tizen 2.3.1 + */ +typedef enum +{ + BT_DEVICE_CONNECTION_LINK_BREDR, /**< BR/EDR link */ + BT_DEVICE_CONNECTION_LINK_LE, /**< LE link */ + BT_DEVICE_CONNECTION_LINK_DEFAULT = 0xFF, /**< The connection type defualt */ +} bt_device_connection_link_type_e; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Enumerations of device authorization state. + * @since_tizen 2.3.1 + */ +typedef enum +{ + BT_DEVICE_AUTHORIZED, /**< The remote Bluetooth device is authorized */ + BT_DEVICE_UNAUTHORIZED, /**< The remote Bluetooth device is unauthorized */ +} bt_device_authorization_e; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Enumerations of Bluetooth profile. + * @since_tizen 2.3.1 + */ +typedef enum +{ + BT_PROFILE_RFCOMM = 0x01, /**< RFCOMM Profile */ + BT_PROFILE_A2DP = 0x02, /**< Advanced Audio Distribution Profile */ + BT_PROFILE_HSP = 0x04, /**< Headset Profile */ + BT_PROFILE_HID = 0x08, /**< Human Interface Device Profile */ + BT_PROFILE_NAP = 0x10, /**< Network Access Point Profile */ + BT_PROFILE_AG = 0x20, /**< Audio Gateway Profile */ + BT_PROFILE_GATT = 0x40, /**< Generic Attribute Profile */ + BT_PROFILE_NAP_SERVER = 0x80, /**< NAP server Profile */ +} bt_profile_e; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Enumerations of device address type. + * @since_tizen 2.3.1 + */ +typedef enum +{ + BT_DEVICE_PUBLIC_ADDRESS = 0x00, /**< Public address */ + BT_DEVICE_RANDOM_ADDRESS, /**< Random address */ +} bt_device_address_type_e; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Enumerations of service class. + * @since_tizen 2.3.1 + */ +typedef enum { + BT_SC_NONE = 0, /**< No service class */ + BT_SC_RES_SERVICE_MASK = 0x00000001, /**< RES service class */ + BT_SC_SPP_SERVICE_MASK = 0x00000002, /**< SPP service class */ + BT_SC_DUN_SERVICE_MASK = 0x00000004, /**< DUN service class */ + BT_SC_FAX_SERVICE_MASK = 0x00000008, /**< FAX service class */ + BT_SC_LAP_SERVICE_MASK = 0x00000010, /**< LAP service class */ + BT_SC_HSP_SERVICE_MASK = 0x00000020, /**< HSP service class */ + BT_SC_HFP_SERVICE_MASK = 0x00000040, /**< HFP service class */ + BT_SC_OPP_SERVICE_MASK = 0x00000080, /**< OPP service class */ + BT_SC_FTP_SERVICE_MASK = 0x00000100, /**< FTP service class */ + BT_SC_CTP_SERVICE_MASK = 0x00000200, /**< CTP service class */ + BT_SC_ICP_SERVICE_MASK = 0x00000400, /**< ICP service class */ + BT_SC_SYNC_SERVICE_MASK = 0x00000800, /**< SYNC service class */ + BT_SC_BPP_SERVICE_MASK = 0x00001000, /**< BPP service class */ + BT_SC_BIP_SERVICE_MASK = 0x00002000, /**< BIP service class */ + BT_SC_PANU_SERVICE_MASK = 0x00004000, /**< PANU service class */ + BT_SC_NAP_SERVICE_MASK = 0x00008000, /**< NAP service class */ + BT_SC_GN_SERVICE_MASK = 0x00010000, /**< GN service class */ + BT_SC_SAP_SERVICE_MASK = 0x00020000, /**< SAP service class */ + BT_SC_A2DP_SERVICE_MASK = 0x00040000, /**< A2DP service class */ + BT_SC_AVRCP_SERVICE_MASK = 0x00080000, /**< AVRCP service class */ + BT_SC_PBAP_SERVICE_MASK = 0x00100000, /**< PBAP service class */ + BT_SC_HID_SERVICE_MASK = 0x00200000, /**< HID service class */ + BT_SC_A2DP_SOURCE_SERVICE_MASK = 0x00400000, /**< A2DP SOURCE service class */ + BT_SC_ALL_SERVICE_MASK = 0x00FFFFFF, /**< ALL service class */ + BT_SC_MAX /**< MAX service class */ +} bt_service_class_t; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Enumerations of major service class. + * @since_tizen 2.3.1 + */ +typedef enum +{ + BT_MAJOR_SERVICE_CLASS_LIMITED_DISCOVERABLE_MODE = 0x002000, /**< Limited discoverable mode */ + BT_MAJOR_SERVICE_CLASS_POSITIONING = 0x010000, /**< Positioning class */ + BT_MAJOR_SERVICE_CLASS_NETWORKING = 0x020000, /**< Networking class */ + BT_MAJOR_SERVICE_CLASS_RENDERING = 0x040000, /**< Rendering class */ + BT_MAJOR_SERVICE_CLASS_CAPTURING = 0x080000, /**< Capturing class */ + BT_MAJOR_SERVICE_CLASS_OBJECT_TRANSFER = 0x100000, /**< Object transferring class */ + BT_MAJOR_SERVICE_CLASS_AUDIO = 0x200000, /**< Audio class*/ + BT_MAJOR_SERVICE_CLASS_TELEPHONY = 0x400000, /**< Telephony class */ + BT_MAJOR_SERVICE_CLASS_INFORMATION = 0x800000, /**< Information class */ +} bt_major_service_class_e; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Enumerations of major device class. + * @since_tizen 2.3.1 + */ +typedef enum +{ + BT_MAJOR_DEVICE_CLASS_MISC = 0x00, /**< Miscellaneous major device class*/ + BT_MAJOR_DEVICE_CLASS_COMPUTER = 0x01, /**< Computer major device class */ + BT_MAJOR_DEVICE_CLASS_PHONE = 0x02, /**< Phone major device class */ + BT_MAJOR_DEVICE_CLASS_LAN_NETWORK_ACCESS_POINT = 0x03, /**< LAN/Network access point major device class */ + BT_MAJOR_DEVICE_CLASS_AUDIO_VIDEO = 0x04, /**< Audio/Video major device class */ + BT_MAJOR_DEVICE_CLASS_PERIPHERAL = 0x05, /**< Peripheral major device class */ + BT_MAJOR_DEVICE_CLASS_IMAGING = 0x06, /**< Imaging major device class */ + BT_MAJOR_DEVICE_CLASS_WEARABLE = 0x07, /**< Wearable device class */ + BT_MAJOR_DEVICE_CLASS_TOY = 0x08, /**< Toy device class */ + BT_MAJOR_DEVICE_CLASS_HEALTH = 0x09, /**< Health device class */ + BT_MAJOR_DEVICE_CLASS_UNCATEGORIZED = 0x1F, /**< Uncategorized major device class */ +} bt_major_device_class_e; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Enumerations of minor device class. + * @since_tizen 2.3.1 + */ +typedef enum +{ + BT_MINOR_DEVICE_CLASS_COMPUTER_UNCATEGORIZED = 0x00, /**< Uncategorized minor device class of computer */ + BT_MINOR_DEVICE_CLASS_COMPUTER_DESKTOP_WORKSTATION = 0x04, /**< Desktop workstation minor device class of computer */ + BT_MINOR_DEVICE_CLASS_COMPUTER_SERVER_CLASS = 0x08, /**< Server minor device class of computer */ + BT_MINOR_DEVICE_CLASS_COMPUTER_LAPTOP = 0x0C, /**< Laptop minor device class of computer */ + BT_MINOR_DEVICE_CLASS_COMPUTER_HANDHELD_PC_OR_PDA = 0x10, /**< Handheld PC/PDA minor device class of computer */ + BT_MINOR_DEVICE_CLASS_COMPUTER_PALM_SIZED_PC_OR_PDA = 0x14, /**< Palm sized PC/PDA minor device class of computer */ + BT_MINOR_DEVICE_CLASS_COMPUTER_WEARABLE_COMPUTER = 0x18, /**< Wearable(watch sized) minor device class of computer */ + + BT_MINOR_DEVICE_CLASS_PHONE_UNCATEGORIZED = 0x00, /**< Uncategorized minor device class of phone */ + BT_MINOR_DEVICE_CLASS_PHONE_CELLULAR = 0x04, /**< Cellular minor device class of phone */ + BT_MINOR_DEVICE_CLASS_PHONE_CORDLESS = 0x08, /**< Cordless minor device class of phone */ + BT_MINOR_DEVICE_CLASS_PHONE_SMART_PHONE = 0x0C, /**< Smart phone minor device class of phone */ + BT_MINOR_DEVICE_CLASS_PHONE_WIRED_MODEM_OR_VOICE_GATEWAY = 0x10, /**< Wired modem or voice gateway minor device class of phone */ + BT_MINOR_DEVICE_CLASS_PHONE_COMMON_ISDN_ACCESS = 0x14, /**< Common ISDN minor device class of phone */ + + BT_MINOR_DEVICE_CLASS_LAN_NETWORK_ACCESS_POINT_FULLY_AVAILABLE = 0x04, /**< Fully available minor device class of LAN/Network access point */ + BT_MINOR_DEVICE_CLASS_LAN_NETWORK_ACCESS_POINT_1_TO_17_PERCENT_UTILIZED = 0x20, /**< 1-17% utilized minor device class of LAN/Network access point */ + BT_MINOR_DEVICE_CLASS_LAN_NETWORK_ACCESS_POINT_17_TO_33_PERCENT_UTILIZED = 0x40, /**< 17-33% utilized minor device class of LAN/Network access point */ + BT_MINOR_DEVICE_CLASS_LAN_NETWORK_ACCESS_POINT_33_TO_50_PERCENT_UTILIZED = 0x60, /**< 33-50% utilized minor device class of LAN/Network access point */ + BT_MINOR_DEVICE_CLASS_LAN_NETWORK_ACCESS_POINT_50_to_67_PERCENT_UTILIZED = 0x80, /**< 50-67% utilized minor device class of LAN/Network access point */ + BT_MINOR_DEVICE_CLASS_LAN_NETWORK_ACCESS_POINT_67_TO_83_PERCENT_UTILIZED = 0xA0, /**< 67-83% utilized minor device class of LAN/Network access point */ + BT_MINOR_DEVICE_CLASS_LAN_NETWORK_ACCESS_POINT_83_TO_99_PERCENT_UTILIZED = 0xC0, /**< 83-99% utilized minor device class of LAN/Network access point */ + BT_MINOR_DEVICE_CLASS_LAN_NETWORK_ACCESS_POINT_NO_SERVICE_AVAILABLE = 0xE0, /**< No service available minor device class of LAN/Network access point */ + + BT_MINOR_DEVICE_CLASS_AUDIO_VIDEO_UNCATEGORIZED = 0x00, /**< Uncategorized minor device class of audio/video */ + BT_MINOR_DEVICE_CLASS_AUDIO_VIDEO_WEARABLE_HEADSET = 0x04, /**< Wearable headset minor device class of audio/video */ + BT_MINOR_DEVICE_CLASS_AUDIO_VIDEO_HANDS_FREE = 0x08, /**< Hands-free minor device class of audio/video */ + BT_MINOR_DEVICE_CLASS_AUDIO_VIDEO_MICROPHONE = 0x10, /**< Microphone minor device class of audio/video */ + BT_MINOR_DEVICE_CLASS_AUDIO_VIDEO_LOUDSPEAKER = 0x14, /**< Loudspeaker minor device class of audio/video */ + BT_MINOR_DEVICE_CLASS_AUDIO_VIDEO_HEADPHONES = 0x18, /**< Headphones minor device class of audio/video */ + BT_MINOR_DEVICE_CLASS_AUDIO_VIDEO_PORTABLE_AUDIO = 0x1C, /**< Portable audio minor device class of audio/video */ + BT_MINOR_DEVICE_CLASS_AUDIO_VIDEO_CAR_AUDIO = 0x20, /**< Car audio minor device class of audio/video */ + BT_MINOR_DEVICE_CLASS_AUDIO_VIDEO_SET_TOP_BOX = 0x24, /**< Set-top box minor device class of audio/video */ + BT_MINOR_DEVICE_CLASS_AUDIO_VIDEO_HIFI_AUDIO_DEVICE = 0x28, /**< Hifi audio minor device class of audio/video */ + BT_MINOR_DEVICE_CLASS_AUDIO_VIDEO_VCR = 0x2C, /**< VCR minor device class of audio/video */ + BT_MINOR_DEVICE_CLASS_AUDIO_VIDEO_VIDEO_CAMERA = 0x30, /**< Video camera minor device class of audio/video */ + BT_MINOR_DEVICE_CLASS_AUDIO_VIDEO_CAMCORDER = 0x34, /**< Camcorder minor device class of audio/video */ + BT_MINOR_DEVICE_CLASS_AUDIO_VIDEO_VIDEO_MONITOR = 0x38, /**< Video monitor minor device class of audio/video */ + BT_MINOR_DEVICE_CLASS_AUDIO_VIDEO_VIDEO_DISPLAY_LOUDSPEAKER = 0x3C, /**< Video display and loudspeaker minor device class of audio/video */ + BT_MINOR_DEVICE_CLASS_AUDIO_VIDEO_VIDEO_CONFERENCING = 0x40, /**< Video conferencing minor device class of audio/video */ + BT_MINOR_DEVICE_CLASS_AUDIO_VIDEO_GAMING_TOY = 0x48, /**< Gaming/toy minor device class of audio/video */ + + BT_MINOR_DEVICE_CLASS_PERIPHERA_UNCATEGORIZED = 0x00, /**< Uncategorized minor device class of peripheral */ + BT_MINOR_DEVICE_CLASS_PERIPHERAL_KEY_BOARD = 0x40, /**< Key board minor device class of peripheral */ + BT_MINOR_DEVICE_CLASS_PERIPHERAL_POINTING_DEVICE = 0x80, /**< Pointing device minor device class of peripheral */ + BT_MINOR_DEVICE_CLASS_PERIPHERAL_COMBO_KEYBOARD_POINTING_DEVICE = 0xC0, /**< Combo keyboard or pointing device minor device class of peripheral */ + BT_MINOR_DEVICE_CLASS_PERIPHERAL_JOYSTICK = 0x04, /**< Joystick minor device class of peripheral */ + BT_MINOR_DEVICE_CLASS_PERIPHERAL_GAME_PAD = 0x08, /**< Game pad minor device class of peripheral */ + BT_MINOR_DEVICE_CLASS_PERIPHERAL_REMOTE_CONTROL = 0x0C, /**< Remote control minor device class of peripheral */ + BT_MINOR_DEVICE_CLASS_PERIPHERAL_SENSING_DEVICE = 0x10, /**< Sensing device minor device class of peripheral */ + BT_MINOR_DEVICE_CLASS_PERIPHERAL_DIGITIZER_TABLET = 0x14, /**< Digitizer minor device class of peripheral */ + BT_MINOR_DEVICE_CLASS_PERIPHERAL_CARD_READER = 0x18, /**< Card reader minor device class of peripheral */ + BT_MINOR_DEVICE_CLASS_PERIPHERAL_DIGITAL_PEN = 0x1C, /**< Digital pen minor device class of peripheral */ + BT_MINOR_DEVICE_CLASS_PERIPHERAL_HANDHELD_SCANNER = 0x20, /**< Handheld scanner minor device class of peripheral */ + BT_MINOR_DEVICE_CLASS_PERIPHERAL_HANDHELD_GESTURAL_INPUT_DEVICE = 0x24, /**< Handheld gestural input device minor device class of peripheral */ + + BT_MINOR_DEVICE_CLASS_IMAGING_DISPLAY = 0x10, /**< Display minor device class of imaging */ + BT_MINOR_DEVICE_CLASS_IMAGING_CAMERA = 0x20, /**< Camera minor device class of imaging */ + BT_MINOR_DEVICE_CLASS_IMAGING_SCANNER = 0x40, /**< Scanner minor device class of imaging */ + BT_MINOR_DEVICE_CLASS_IMAGING_PRINTER = 0x80, /**< Printer minor device class of imaging */ + + BT_MINOR_DEVICE_CLASS_WEARABLE_WRIST_WATCH = 0x04, /**< Wrist watch minor device class of wearable */ + BT_MINOR_DEVICE_CLASS_WEARABLE_PAGER = 0x08, /**< Pager minor device class of wearable */ + BT_MINOR_DEVICE_CLASS_WEARABLE_JACKET = 0x0C, /**< Jacket minor device class of wearable */ + BT_MINOR_DEVICE_CLASS_WEARABLE_HELMET = 0x10, /**< Helmet minor device class of wearable */ + BT_MINOR_DEVICE_CLASS_WEARABLE_GLASSES = 0x14, /**< Glasses minor device class of wearable */ + + BT_MINOR_DEVICE_CLASS_TOY_ROBOT = 0x04, /**< Robot minor device class of toy */ + BT_MINOR_DEVICE_CLASS_TOY_VEHICLE = 0x08, /**< Vehicle minor device class of toy */ + BT_MINOR_DEVICE_CLASS_TOY_DOLL_ACTION = 0x0C, /**< Doll/Action minor device class of toy */ + BT_MINOR_DEVICE_CLASS_TOY_CONTROLLER = 0x10, /**< Controller minor device class of toy */ + BT_MINOR_DEVICE_CLASS_TOY_GAME = 0x14, /**< Game minor device class of toy */ + + BT_MINOR_DEVICE_CLASS_HEALTH_UNCATEGORIZED = 0x00, /**< Uncategorized minor device class of health */ + BT_MINOR_DEVICE_CLASS_HEALTH_BLOOD_PRESSURE_MONITOR = 0x04, /**< Blood pressure monitor minor device class of health */ + BT_MINOR_DEVICE_CLASS_HEALTH_THERMOMETER = 0x08, /**< Thermometer minor device class of health */ + BT_MINOR_DEVICE_CLASS_HEALTH_WEIGHING_SCALE = 0x0C, /**< Weighing scale minor device class of health */ + BT_MINOR_DEVICE_CLASS_HEALTH_GLUCOSE_METER = 0x10, /**< Glucose minor device class of health */ + BT_MINOR_DEVICE_CLASS_HEALTH_PULSE_OXIMETER = 0x14, /**< Pulse oximeter minor device class of health */ + BT_MINOR_DEVICE_CLASS_HEALTH_HEART_PULSE_RATE_MONITOR = 0x18, /**< Heart/Pulse rate monitor minor device class of health */ + BT_MINOR_DEVICE_CLASS_HEALTH_DATA_DISPLAY = 0x1C, /**< Health data display minor device class of health */ + BT_MINOR_DEVICE_CLASS_HEALTH_STEP_COUNTER = 0x20, /**< Step counter minor device class of health */ + BT_MINOR_DEVICE_CLASS_HEALTH_BODY_COMPOSITION_ANALYZER = 0x24, /**< Body composition analyzer minor device class of health */ + BT_MINOR_DEVICE_CLASS_HEALTH_PEAK_FLOW_MONITOR = 0x28, /**< Peak flow monitor minor device class of health */ + BT_MINOR_DEVICE_CLASS_HEALTH_MEDICATION_MONITOR = 0x2C, /**< Medication monitor minor device class of health */ + BT_MINOR_DEVICE_CLASS_HEALTH_KNEE_PROSTHESIS = 0x30, /**< Knee prosthesis minor device class of health */ + BT_MINOR_DEVICE_CLASS_HEALTH_ANKLE_PROSTHESIS = 0x34, /**< Ankle prosthesis minor device class of health */ +} bt_minor_device_class_e; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Enumerations of gap appearance type. + * @since_tizen 2.3.1 + */ +typedef enum +{ + BT_APPEARANCE_TYPE_UNKNOWN = 0x00, /**< Unknown appearance type */ + BT_APPEARANCE_TYPE_GENERIC_PHONE = 0x40, /**< Generic Phone type - Generic category */ + BT_APPEARANCE_TYPE_GENERIC_COMPUTER = 0x80, /**< Generic Computer type - Generic category */ + BT_APPEARANCE_TYPE_GENERIC_WATCH = 0xC0, /**< Generic Watch type - Generic category */ +} bt_appearance_type_e; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE + * @brief Enumerations of connected Bluetooth device event role. + * @since_tizen 2.3.1 + */ +typedef enum +{ + BT_SOCKET_UNKNOWN = 0x00, /**< Unknown role*/ + BT_SOCKET_SERVER , /**< Server role*/ + BT_SOCKET_CLIENT, /**< Client role*/ +} bt_socket_role_e; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE + * @brief Enumerations of Bluetooth socket connection state. + * @since_tizen 2.3.1 + */ +typedef enum +{ + BT_SOCKET_CONNECTED, /**< RFCOMM is connected */ + BT_SOCKET_DISCONNECTED, /**< RFCOMM is disconnected */ +} bt_socket_connection_state_e; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_MODULE + * @brief Enumerations for the types of profiles related with audio + * @since_tizen 2.3.1 + */ +typedef enum { + BT_AUDIO_PROFILE_TYPE_ALL = 0, /**< All supported profiles related with audio */ + BT_AUDIO_PROFILE_TYPE_HSP_HFP, /**< HSP(Headset Profile) and HFP(Hands-Free Profile) */ + BT_AUDIO_PROFILE_TYPE_A2DP, /**< A2DP(Advanced Audio Distribution Profile) */ + BT_AUDIO_PROFILE_TYPE_AG, /**< AG(Audio Gateway) */ +} bt_audio_profile_type_e; + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Enumerations for the call handling event + * @since_tizen 2.3.1 + */ +typedef enum { + BT_AG_CALL_HANDLING_EVENT_ANSWER = 0x00, /**< Request to answer an incoming call */ + BT_AG_CALL_HANDLING_EVENT_RELEASE, /**< Request to release a call */ + BT_AG_CALL_HANDLING_EVENT_REJECT, /**< Request to reject an incoming call */ +} bt_ag_call_handling_event_e; + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Enumerations for the multi call handling event + * @since_tizen 2.3.1 + */ +typedef enum { + BT_AG_MULTI_CALL_HANDLING_EVENT_RELEASE_HELD_CALLS = 0x00, /**< Request to release held calls */ + BT_AG_MULTI_CALL_HANDLING_EVENT_RELEASE_ACTIVE_CALLS, /**< Request to release active calls */ + BT_AG_MULTI_CALL_HANDLING_EVENT_ACTIVATE_HELD_CALL, /**< Request to put active calls into hold state and activate another (held or waiting) call */ + BT_AG_MULTI_CALL_HANDLING_EVENT_MERGE_CALLS, /**< Request to add a held call to the conversation */ + BT_AG_MULTI_CALL_HANDLING_EVENT_EXPLICIT_CALL_TRANSFER, /**< Request to let a user who has two calls to connect these two calls together and release its connections to both other parties */ +} bt_ag_multi_call_handling_event_e; + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Enumerations for the call state + * @since_tizen 2.3.1 + */ +typedef enum { + BT_AG_CALL_EVENT_IDLE = 0x00, /**< Idle */ + BT_AG_CALL_EVENT_ANSWERED, /**< Answered */ + BT_AG_CALL_EVENT_HELD, /**< Held */ + BT_AG_CALL_EVENT_RETRIEVED, /**< Retrieved */ + BT_AG_CALL_EVENT_DIALING, /**< Dialing */ + BT_AG_CALL_EVENT_ALERTING, /**< Alerting */ + BT_AG_CALL_EVENT_INCOMING, /**< Incoming */ +} bt_ag_call_event_e; + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Enumerations for the call state + * @since_tizen 2.3.1 + */ +typedef enum { + BT_AG_CALL_STATE_IDLE = 0x00, /**< Idle state */ + BT_AG_CALL_STATE_ACTIVE, /**< Active state */ + BT_AG_CALL_STATE_HELD, /**< Held state */ + BT_AG_CALL_STATE_DIALING, /**< Dialing state */ + BT_AG_CALL_STATE_ALERTING, /**< Alerting state */ + BT_AG_CALL_STATE_INCOMING, /**< Incoming state */ + BT_AG_CALL_STATE_WAITING, /**< Waiting for connected indication event after answering an incoming call*/ +} bt_ag_call_state_e; + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief Enumerations for the equalizer state + * @since_tizen 2.3.1 + */ +typedef enum { + BT_AVRCP_EQUALIZER_STATE_OFF = 0x01, /**< Equalizer Off */ + BT_AVRCP_EQUALIZER_STATE_ON, /**< Equalizer On */ +} bt_avrcp_equalizer_state_e; + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief Enumerations for the repeat mode + * @since_tizen 2.3.1 + */ +typedef enum { + BT_AVRCP_REPEAT_MODE_OFF = 0x01, /**< Repeat Off */ + BT_AVRCP_REPEAT_MODE_SINGLE_TRACK, /**< Single track repeat */ + BT_AVRCP_REPEAT_MODE_ALL_TRACK, /**< All track repeat */ + BT_AVRCP_REPEAT_MODE_GROUP, /**< Group repeat */ +} bt_avrcp_repeat_mode_e; + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief Enumerations for the shuffle mode + * @since_tizen 2.3.1 + */ +typedef enum { + BT_AVRCP_SHUFFLE_MODE_OFF = 0x01, /**< Shuffle Off */ + BT_AVRCP_SHUFFLE_MODE_ALL_TRACK, /**< All tracks shuffle */ + BT_AVRCP_SHUFFLE_MODE_GROUP, /**< Group shuffle */ +} bt_avrcp_shuffle_mode_e; + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief Enumerations for the scan mode + * @since_tizen 2.3.1 + */ +typedef enum { + BT_AVRCP_SCAN_MODE_OFF = 0x01, /**< Scan Off */ + BT_AVRCP_SCAN_MODE_ALL_TRACK, /**< All tracks scan */ + BT_AVRCP_SCAN_MODE_GROUP, /**< Group scan */ +} bt_avrcp_scan_mode_e; + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief Enumerations for the player state + * @since_tizen 2.3.1 + */ +typedef enum { + BT_AVRCP_PLAYER_STATE_STOPPED = 0x00, /**< Stopped */ + BT_AVRCP_PLAYER_STATE_PLAYING, /**< Playing */ + BT_AVRCP_PLAYER_STATE_PAUSED, /**< Paused */ + BT_AVRCP_PLAYER_STATE_FORWARD_SEEK, /**< Seek Forward */ + BT_AVRCP_PLAYER_STATE_REWIND_SEEK, /**< Seek Rewind */ +} bt_avrcp_player_state_e; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_HDP_MODULE + * @brief Enumerations for the data channel type + * @since_tizen 2.3.1 + */ +typedef enum { + BT_HDP_CHANNEL_TYPE_RELIABLE = 0x01, /**< Reliable Data Channel */ + BT_HDP_CHANNEL_TYPE_STREAMING, /**< Streaming Data Channel */ +} bt_hdp_channel_type_e; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Enumerations of the integer type for GATT handle's value + * @since_tizen 2.3.1 + */ +typedef enum { + BT_DATA_TYPE_SINT8, /**< 8 bit signed int type */ + BT_DATA_TYPE_SINT16, /**< 16 bit signed int type */ + BT_DATA_TYPE_SINT32, /**< 32 bit signed int type */ + BT_DATA_TYPE_UINT8, /**< 8 bit unsigned int type */ + BT_DATA_TYPE_UINT16, /**< 16 bit unsigned int type */ + BT_DATA_TYPE_UINT32 /**< 32 bit unsigned int type */ +} bt_data_type_int_e; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Enumerations of the float type for GATT handle's value + * @since_tizen 2.3.1 + */ +typedef enum { + BT_DATA_TYPE_FLOAT, /**< 32 bit float type */ + BT_DATA_TYPE_SFLOAT /**< 16 bit float type */ +} bt_data_type_float_e; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Enumerations of the write type + * @since_tizen 2.3.1 + */ +typedef enum { + BT_GATT_WRITE_TYPE_WRITE_NO_RESPONSE, /**< Write without response type */ + BT_GATT_WRITE_TYPE_WRITE /**< Write type */ +} bt_gatt_write_type_e; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Enumerations of the GATT handle's type + * @since_tizen 2.3.1 + */ +typedef enum { + BT_GATT_TYPE_SERVICE = 0x01, /**< GATT service type */ + BT_GATT_TYPE_CHARACTERISTIC = 0x02, /** GATT characteristic type */ + BT_GATT_TYPE_DESCRIPTOR = 0x03, /** GATT descriptor type */ +} bt_gatt_type_e; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Enumerations of the service type + * @since_tizen 2.3.1 + */ +typedef enum { + BT_GATT_SERVICE_TYPE_PRIMARY = 0x01, /**< GATT primary service type */ + BT_GATT_SERVICE_TYPE_SECONDARY = 0x02, /**< GATT secondary service type */ +} bt_gatt_service_type_e; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Enumerations of the characteristic's property + * @since_tizen 2.3.1 + */ +typedef enum { + BT_GATT_PROPERTY_BROADCAST = 0x01, /**< Broadcast property */ + BT_GATT_PROPERTY_READ = 0x02, /**< Read property */ + BT_GATT_PROPERTY_WRITE_WITHOUT_RESPONSE = 0x04, /**< Write without response property */ + BT_GATT_PROPERTY_WRITE = 0x08, /**< Write property */ + BT_GATT_PROPERTY_NOTIFY = 0x10, /**< Notify property */ + BT_GATT_PROPERTY_INDICATE = 0x20, /**< Indicate property */ + BT_GATT_PROPERTY_AUTHENTICATED_SIGNED_WRITES = 0x40, /**< Authenticated signed writes property */ + BT_GATT_PROPERTY_EXTENDED_PROPERTIES = 0x80, /**< Extended properties */ +} bt_gatt_property_e; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_PAN_PANU_MODULE + * @brief Enumerations for the types of PAN(Personal Area Networking) service + * @since_tizen 2.3.1 + */ +typedef enum { + BT_PANU_SERVICE_TYPE_NAP = 0, /**< Network Access Point */ +} bt_panu_service_type_e; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief The handle to control Bluetooth LE advertising + * @since_tizen 2.3.1 + */ +typedef void* bt_advertiser_h; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief The handle of a service, characteristic or descriptor + * @since_tizen 2.3.1 + */ +typedef void* bt_gatt_h; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief The handle of a GATT client which is associated with a remote device + * @since_tizen 2.3.1 + */ +typedef void* bt_gatt_client_h; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief The handle of calls state + * @since_tizen 2.3.1 + */ +typedef void* bt_call_list_h; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Class structure of device and service. + * @since_tizen 2.3.1 + * + * @see #bt_device_info_s + * @see #bt_adapter_device_discovery_info_s + * @see bt_device_bond_created_cb() + * @see bt_adapter_device_discovery_state_changed_cb() + */ +typedef struct +{ + bt_major_device_class_e major_device_class; /**< Major device class. */ + bt_minor_device_class_e minor_device_class; /**< Minor device class. */ + int major_service_class_mask; /**< Major service class mask. + This value can be a combination of #bt_major_service_class_e like #BT_MAJOR_SERVICE_CLASS_RENDERING | #BT_MAJOR_SERVICE_CLASS_AUDIO */ +} bt_class_s; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Structure of device discovery information. + * @since_tizen 2.3.1 + * + * @see #bt_class_s + * @see bt_adapter_device_discovery_state_changed_cb() + */ +typedef struct +{ + char *remote_address; /**< The address of remote device */ + char *remote_name; /**< The name of remote device */ + bt_class_s bt_class; /**< The Bluetooth classes */ + int rssi; /**< The strength indicator of received signal */ + bool is_bonded; /**< The bonding state */ + char **service_uuid; /**< The UUID list of service */ + int service_count; /**< The number of services */ + bt_appearance_type_e appearance; /**< The Bluetooth appearance */ + int manufacturer_data_len; /**< manufacturer specific data length */ + char *manufacturer_data; /**< manufacturer specific data */ +} bt_adapter_device_discovery_info_s; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Structure of le scan result information. + * @since_tizen 2.3.1 + * + * @see bt_adapter_le_start_scan() + */ +typedef struct +{ + char *remote_address; /**< The address of remote device */ + bt_device_address_type_e address_type; /**< The address type of remote device */ + int rssi; /**< The strength indicator of received signal */ + int adv_data_len; /**< advertising indication data length */ + char *adv_data; /**< advertising indication data */ + int scan_data_len; /**< scan response data length */ + char *scan_data; /**< scan response data */ +} bt_adapter_le_device_scan_result_info_s; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief LE service data structure + * @since_tizen 2.3.1 + * + * @see bt_adapter_le_get_scan_result_service_data() + */ +typedef struct +{ + char *service_uuid; /**< 16 bit UUID of the service data */ + char *service_data; /**< Service data */ + int service_data_len; /**< Service data length */ +} bt_adapter_le_service_data_s; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Device information structure used for identifying pear device. + * @since_tizen 2.3.1 + * + * @see #bt_class_s + * @see bt_device_bond_created_cb() + */ +typedef struct +{ + char *remote_address; /**< The address of remote device */ + char *remote_name; /**< The name of remote device */ + bt_class_s bt_class; /**< The Bluetooth classes */ + char **service_uuid; /**< The UUID list of service */ + int service_count; /**< The number of services */ + bool is_bonded; /**< The bonding state */ + bool is_connected; /**< The connection state */ + bool is_authorized; /**< The authorization state */ + int manufacturer_data_len; /**< manufacturer specific data length */ + char *manufacturer_data; /**< manufacturer specific data */ +} bt_device_info_s; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Service Discovery Protocol (SDP) data structure. + * @since_tizen 2.3.1 + * + * @details This protocol is used for discovering available services or pear device, + * and finding one to connect with. + * + * @see bt_device_service_searched_cb() + */ +typedef struct +{ + char *remote_address; /**< The address of remote device */ + char **service_uuid; /**< The UUID list of service */ + int service_count; /**< The number of services. */ +} bt_device_sdp_info_s; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Device connection information structure. + * @since_tizen 2.3.1 + * + * @see bt_device_connection_state_changed_cb() + */ +typedef struct +{ + char *remote_address; /**< The address of remote device */ + bt_device_connection_link_type_e link; /**< Link type */ + bt_device_disconnect_reason_e disconn_reason; /**< Disconnection reason */ +} bt_device_connection_info_s; + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Device LE connection update structure. + * @since_tizen 2.3.1 + * + * @see bt_device_le_conn_update() + */ +typedef struct +{ + unsigned int interval_min; /**< Minimum value for the connection event interval (msec) */ + unsigned int interval_max; /**< Maximum value for the connection event interval (msec) */ + unsigned int latency; /**< Slave latency (msec) */ + unsigned int time_out; /**< Supervision timeout (msec) */ +} bt_le_conn_update_s; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE + * @brief Rfcomm connection data used for exchanging data between Bluetooth devices. + * @since_tizen 2.3.1 + * + * @see bt_socket_connection_state_changed_cb() + */ +typedef struct +{ + int socket_fd; /**< The file descriptor of connected socket */ + int server_fd; /**< The file descriptor of the server socket or -1 for client connection */ + bt_socket_role_e local_role; /**< The local device role in this connection */ + char *remote_address; /**< The remote device address */ + char *service_uuid; /**< The service UUId */ +} bt_socket_connection_s; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE + * @brief Structure of RFCOMM received data. + * @since_tizen 2.3.1 + * + * @remarks User can use standard linux functions for reading/writing + * data from/to sockets. + * + * @see bt_socket_data_received_cb() + */ +typedef struct +{ + int socket_fd; /**< The socket fd */ + int data_size; /**< The length of the received data */ + char *data; /**< The received data */ +} bt_socket_received_data_s; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Called when the Bluetooth adapter state changes. + * @since_tizen 2.3.1 + * + * @param[in] result The result of the adapter state changing + * @param[in] adapter_state The adapter state to be changed + * @param[in] user_data The user data passed from the callback registration function + * @see bt_adapter_set_state_changed_cb() + * @see bt_adapter_unset_state_changed_cb() + */ +typedef void (*bt_adapter_state_changed_cb)(int result, bt_adapter_state_e adapter_state, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Called when adapter name changes. + * @since_tizen 2.3.1 + * + * @param[in] device_name The name of the Bluetooth device to be changed + * @param[in] user_data The user data passed from the callback registration function + * @pre This function will be invoked when the name of Bluetooth adapter changes + * if you register this callback using bt_adapter_set_name_changed_cb(). + * @see bt_adapter_set_name() + * @see bt_adapter_set_name_changed_cb() + * @see bt_adapter_unset_name_changed_cb() + */ +typedef void (*bt_adapter_name_changed_cb)(char *device_name, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Called when the visibility mode changes. + * @since_tizen 2.3.1 + * + * @param[in] result The result of the visibility mode changing + * @param[in] visibility_mode The visibility mode to be changed + * @param[in] user_data The user data passed from the callback registration function + * + * @pre This function will be invoked when the visibility of Bluetooth adapter changes + * if you register this callback using bt_adapter_set_visibility_mode_changed_cb(). + * + * @see bt_adapter_set_visibility_mode_changed_cb() + * @see bt_adapter_unset_visibility_mode_changed_cb() + */ +typedef void (*bt_adapter_visibility_mode_changed_cb) + (int result, bt_adapter_visibility_mode_e visibility_mode, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Called every second until the visibility mode is changed to #BT_ADAPTER_VISIBILITY_MODE_NON_DISCOVERABLE. + * @since_tizen 2.3.1 + * + * @remarks This callback function is called only if visibility mode is #BT_ADAPTER_VISIBILITY_MODE_LIMITED_DISCOVERABLE. + * @param[in] duration The duration until the visibility mode is changed to #BT_ADAPTER_VISIBILITY_MODE_NON_DISCOVERABLE (in seconds) + * @param[in] user_data The user data passed from the callback registration function + * @pre This function will be invoked if you register this callback using bt_adapter_set_visibility_duration_changed_cb(). + * @see bt_adapter_set_visibility_duration_changed_cb() + * @see bt_adapter_unset_visibility_duration_changed_cb() + */ +typedef void (*bt_adapter_visibility_duration_changed_cb)(int duration, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Called when the state of device discovery changes. + * @since_tizen 2.3.1 + * + * @remarks If \a discovery_state is #BT_ADAPTER_DEVICE_DISCOVERY_FOUND, + * then you can get some information, such as remote device address, remote device name, rssi, and bonding state. + * + * @param[in] result The result of the device discovery + * @param[in] discovery_state The discovery state to be changed + * @param[in] discovery_info The information of the discovered device \n + * If \a discovery_state is #BT_ADAPTER_DEVICE_DISCOVERY_STARTED or + * #BT_ADAPTER_DEVICE_DISCOVERY_FINISHED, then \a discovery_info is NULL. + * @param[in] user_data The user data passed from the callback registration function + * + * @pre Either bt_adapter_start_device_discovery() or bt_adapter_stop_device_discovery() will invoke this function + * if you register this callback using bt_adapter_set_device_discovery_state_changed_cb(). + * + * @see bt_adapter_start_device_discovery() + * @see bt_adapter_stop_device_discovery() + * @see bt_adapter_set_device_discovery_state_changed_cb() + * @see bt_adapter_unset_device_discovery_state_changed_cb() + * + */ +typedef void (*bt_adapter_device_discovery_state_changed_cb) + (int result, bt_adapter_device_discovery_state_e discovery_state, bt_adapter_device_discovery_info_s *discovery_info, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Called when you get bonded devices repeatedly. + * @since_tizen 2.3.1 + * + * @param[in] device_info The bonded device information + * @param[in] user_data The user data passed from the foreach function + * @return @c true to continue with the next iteration of the loop, + * \n @c false to break out of the loop. + * @pre bt_adapter_foreach_bonded_device() will invoke this function. + * + * @see bt_adapter_foreach_bonded_device() + * + */ +typedef bool (*bt_adapter_bonded_device_cb)(bt_device_info_s *device_info, void *user_data); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Called when the connectable state changes. + * @since_tizen 2.3.1 + * + * @param[in] result The result of the connectable state changing + * @param[in] connectable The connectable to be changed + * @param[in] user_data The user data passed from the callback registration function + * + * @pre This function will be invoked when the connectable state of local Bluetooth adapter changes + * if you register this callback using bt_adapter_set_connectable_changed_cb(). + * + * @see bt_adapter_set_connectable() + * @see bt_adapter_set_connectable_changed_cb() + * @see bt_adapter_unset_connectable_changed_cb() + */ +typedef void (*bt_adapter_connectable_changed_cb) + (int result, bool connectable, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Called when the LE advertisement has been found. + * @since_tizen 2.3.1 + * + * @param[in] result The result of the LE scan + * @param[in] info The information of the found LE advertisement. + * @param[in] user_data The user data passed from the start function + * + * @see bt_adapter_le_start_scan() + * + */ +typedef void (*bt_adapter_le_scan_result_cb)(int result, + bt_adapter_le_device_scan_result_info_s *info, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Called when the state of advertiser changes. + * @since_tizen 2.3.1 + * + * @param[out] result The result of the requested state change of advertiser + * @param[out] advertiser The handle of the state changed advertiser + * @param[out] adv_state The advertiser state to be changed + * @param[out] user_data The user data passed from the start function + * + * @see bt_adapter_le_start_advertising_new() + * @see bt_adapter_le_stop_advertising() + */ +typedef void (*bt_adapter_le_advertising_state_changed_cb)(int result, + bt_advertiser_h advertiser, bt_adapter_le_advertising_state_e adv_state, void *user_data); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Called when the Bluetooth adapter le state changes. + * @since_tizen 2.3.1 + * + * @param[in] result The result of the adapter state changing + * @param[in] adapter_le_state The adapter le state to be changed + * @param[in] user_data The user data passed from the callback registration function + * @pre Either bt_adapter_le_enable() or bt_adapter_le_disable() will invoke this callback if you register this callback using bt_adapter_le_set_state_changed_cb(). + * @see bt_adapter_le_enable() + * @see bt_adapter_le_disable() + * @see bt_adapter_le_set_state_changed_cb() + * @see bt_adapter_le_unset_state_changed_cb() + */ +typedef void (*bt_adapter_le_state_changed_cb)(int result, bt_adapter_le_state_e adapter_le_state, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Called when the process of creating bond finishes. + * @since_tizen 2.3.1 + * + * @remarks If the remote user does not respond within 60 seconds, a time out will happen with #BT_ERROR_TIMED_OUT result code.\n + * If bt_device_cancel_bonding() is called and it returns #BT_ERROR_NONE, then this callback function will be called + * with #BT_ERROR_CANCELLED result. \n + * If creating a bond succeeds but service search fails, then this callback will be called with #BT_ERROR_SERVICE_SEARCH_FAILED. + * In this case, you should try service search again by bt_device_start_service_search() to get the supported service list. + * + * @param[in] result The result of the bonding device + * @param[in] device_info The device information which you creates bond with + * @param[in] user_data The user data passed from the callback registration function + * + * @pre Either bt_device_create_bond() will invoke this function + * if you register this callback using bt_device_set_bond_created_cb(). + * + * @see bt_device_create_bond() + * @see bt_device_cancel_bonding() + * @see bt_device_set_bond_created_cb() + * @see bt_device_unset_bond_created_cb() + */ +typedef void (*bt_device_bond_created_cb)(int result, bt_device_info_s *device_info, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Called when you get connected profiles repeatedly. + * @since_tizen 2.3.1 + * + * @param[in] profile The connected Bluetooth profile + * @param[in] user_data The user data passed from the foreach function + * @return @c true to continue with the next iteration of the loop, + * \n @c false to break out of the loop. + * @pre bt_device_foreach_connected_profiles() will invoke this function. + * @see bt_device_foreach_connected_profiles() + */ +typedef bool (*bt_device_connected_profile)(bt_profile_e profile, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Called when the bond destroys. + * @since_tizen 2.3.1 + * + * @param[in] result The result that a bond is destroyed + * @param[in] remote_address The address of the remote Bluetooth device to destroy bond with + * @param[in] user_data The user data passed from the callback registration function + * @pre bt_device_destroy_bond() will invoke this function + * if you register this callback using bt_device_set_bond_destroyed_cb(). + * + * @see bt_device_destroy_bond() + * @see bt_device_set_bond_destroyed_cb() + * @see bt_device_unset_bond_destroyed_cb() + */ +typedef void (*bt_device_bond_destroyed_cb)(int result, char *remote_address, void *user_data); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Called when the authorization of device changes. + * @since_tizen 2.3.1 + * + * @param[in] authorization The authorization of device + * @param[in] remote_address The address of the remote Bluetooth device which is (un)authorized + * @param[in] user_data The user data passed from the callback registration function + * @pre bt_device_set_authorization() will invoke this function if you register this callback using bt_device_set_authorization_changed_cb(). + * + * @see bt_device_set_authorization() + * @see #bt_device_set_authorization_changed_cb() + * @see #bt_device_unset_authorization_changed_cb() + */ +typedef void (*bt_device_authorization_changed_cb) + (bt_device_authorization_e authorization, char *remote_address, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Called when the process of service search finishes. + * @since_tizen 2.3.1 + * + * @remark + * + * @param[in] result The result of the service searching + * @param[in] sdp_info The structure of service lists found on a device + * @param[in] user_data The user data passed from the callback registration function + * @pre Either bt_device_start_service_search() will invoke this function + * if you register this callback using bt_device_set_service_searched_cb(). + * + * @see bt_device_start_service_search() + * @see bt_device_set_service_searched_cb() + * @see bt_device_unset_service_searched_cb() + * + */ +typedef void (*bt_device_service_searched_cb)(int result, bt_device_sdp_info_s *sdp_info, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Called when the connection state is changed. + * @since_tizen 2.3.1 + * + * @param[in] connected The connection status: (@c true = connected, @c false = disconnected) + * @param[in] conn_info The connection information + * @param[in] user_data The user data passed from the callback registration function + * @see bt_device_set_connection_state_changed_cb() + * @see bt_device_unset_connection_state_changed_cb() + */ +typedef void (*bt_device_connection_state_changed_cb)(bool connected, bt_device_connection_info_s *conn_info, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE + * @brief Called when you receive data. + * @since_tizen 2.3.1 + * + * @param[in] data The received data from the remote device + * @param[in] user_data The user data passed from the callback registration function + * + * @pre When the connected remote Bluetooth device invokes bt_socket_send_data(), + * this function will be invoked if you register this function using bt_socket_set_data_received_cb(). + * + * @see bt_socket_set_data_received_cb() + * @see bt_socket_unset_data_received_cb() + * @see bt_socket_send_data() + */ +typedef void (*bt_socket_data_received_cb)(bt_socket_received_data_s *data, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE + * @brief Called when the socket connection state changes. + * @since_tizen 2.3.1 + * + * @param[in] result The result of connection state changing + * @param[in] connection_state The connection state + * @param[in] connection The connection information which is established or disconnected + * @param[in] user_data The user data passed from the callback registration function + * @pre Either bt_socket_connect_rfcomm() will invoke this function. + * In addtion, bt_socket_connection_state_changed_cb() will be invoked when the socket connection state is changed. + * @see bt_socket_listen_and_accept_rfcomm() + * @see bt_socket_connect_rfcomm() + * @see bt_socket_set_connection_state_changed_cb() + * @see bt_socket_unset_connection_state_changed_cb() + */ +typedef void (*bt_socket_connection_state_changed_cb) + (int result, bt_socket_connection_state_e connection_state, bt_socket_connection_s *connection, void *user_data); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE + * @brief Called when a RFCOMM connection is requested. + * @since_tizen 2.3.1 + * + * @details You must call bt_socket_accept() if you want to accept. Otherwise, you must call bt_socket_reject(). + * @param[in] socket_fd The file descriptor of socket on which a connection is requested + * @param[in] remote_address The address of remote device + * @param[in] user_data The user data passed from the callback registration function + * @pre If you register this callback function by bt_socket_set_connection_requested_cb() and listen a socket by bt_socket_listen(), + * bt_socket_connection_requested_cb() will be invoked. + * @see bt_socket_listen() + * @see bt_socket_accept() + * @see bt_socket_reject() + */ +typedef void (*bt_socket_connection_requested_cb) (int socket_fd, const char *remote_address, void *user_data); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_OPP_SERVER_MODULE + * @brief Called when the push is requested. + * @since_tizen 2.3.1 + * + * @details You must call bt_opp_server_accept() if you want to accept. + * Otherwise, you must call bt_opp_server_reject(). + * @param[in] file The path of file to be pushed + * @param[in] size The file size (bytes) + * @param[in] user_data The user data passed from the callback registration function + * @see bt_opp_server_initialize() + */ +typedef void (*bt_opp_server_push_requested_cb)(const char *file, int size, void *user_data); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_OPP_SERVER_MODULE + * @brief Called when an OPP connection is requested. + * @since_tizen 2.3.1 + * + * @details You must call bt_opp_server_accept_connection() if you want to accept. + * Otherwise, you must call bt_opp_server_reject_connection(). + * @param[in] remote_address The address of remote device + * @param[in] user_data The user data passed from the callback registration function + * @see bt_opp_server_accept() + * @see bt_opp_server_reject() + */ +typedef void (*bt_opp_server_connection_requested_cb)(const char *remote_address, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_OPP_SERVER_MODULE + * @brief Called when a file is being transfered. + * @since_tizen 2.3.1 + * + * @param[in] file The path of file to be pushed + * @param[in] size The file size (bytes) + * @param[in] percent The progress in percentage (1 ~ 100) + * @param[in] user_data The user data passed from the callback registration function + * @see bt_opp_server_accept() + * @see bt_opp_server_accept_connection() + */ +typedef void (*bt_opp_server_transfer_progress_cb) (const char *file, long long size, int percent, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_OPP_SERVER_MODULE + * @brief Called when a transfer is finished. + * @since_tizen 2.3.1 + * + * @param[in] error_code The result of push + * @param[in] file The path of file to be pushed + * @param[in] size The file size (bytes) + * @param[in] user_data The user data passed from the callback registration function + * @see bt_opp_server_accept() + * @see bt_opp_server_accept_connection() + */ +typedef void (*bt_opp_server_transfer_finished_cb) (int result, const char *file, long long size, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_OPP_CLIENT_MODULE + * @brief Called when OPP server responds to the push request. + * @since_tizen 2.3.1 + * + * @param[in] result The result of OPP server response + * @param[in] remote_address The remote address + * @param[in] user_data The user data passed from the callback registration function + * @pre bt_opp_client_push_files() will invoke this function. + * @see bt_opp_client_push_files() + */ +typedef void (*bt_opp_client_push_responded_cb)(int result, const char *remote_address, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_OPP_CLIENT_MODULE + * @brief Called when each file is being transfered. + * @since_tizen 2.3.1 + * + * @param[in] file The path of file to be pushed + * @param[in] size The file size (bytes) + * @param[in] percent The progress in percentage (1 ~ 100). 100 means that a file is transfered completely. + * @param[in] user_data The user data passed from the callback registration function + * @pre bt_opp_client_push_files() will invoke this function. + * @see bt_opp_client_push_files() + */ +typedef void (*bt_opp_client_push_progress_cb)(const char *file, long long size, int percent, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_OPP_CLIENT_MODULE + * @brief Called when the push request is finished. + * @since_tizen 2.3.1 + * + * @param[in] result The result of the push request + * @param[in] remote_address The remote address + * @param[in] user_data The user data passed from the callback registration function + * @see bt_opp_client_push_files() + */ +typedef void (*bt_opp_client_push_finished_cb)(int result, const char *remote_address, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_MODULE + * @brief Called when the connection state is changed. + * @since_tizen 2.3.1 + * + * @details This callback is called when the connection state is changed. + * When you call bt_audio_connect() or bt_audio_disconnect(), this callback is also called with error result even though these functions fail. + * @param[in] result The result of changing the connection state + * @param[in] connected The state to be changed. @a true means connected state, Otherwise, @a false. + * @param[in] remote_address The remote address + * @param[in] type The type of audio profile except #BT_AUDIO_PROFILE_TYPE_ALL + * @param[in] user_data The user data passed from the callback registration function + * @see bt_audio_set_connection_state_changed_cb() + * @see bt_audio_unset_connection_state_changed_cb() + */ +typedef void (*bt_audio_connection_state_changed_cb) (int result, bool connected, const char *remote_address, bt_audio_profile_type_e type, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Called when the SCO(Synchronous Connection Oriented link) state is changed. + * @since_tizen 2.3.1 + * + * @details This callback is called when the SCO state is changed. + * When you call bt_ag_open_sco() or bt_ag_close_sco(), this callback is also called with error result even though these functions failed. + * @param[in] result The result of changing the connection state + * @param[in] opened The state to be changed: (@c true = opened, @c false = not opened) + * @param[in] user_data The user data passed from the callback registration function + * @see bt_ag_set_sco_state_changed_cb() + * @see bt_ag_unset_sco_state_changed_cb() + * @see bt_ag_open_sco() + * @see bt_ag_close_sco() + */ +typedef void (*bt_ag_sco_state_changed_cb) (int result, bool opened, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Called when a call handling event happened from Hands-Free. + * @since_tizen 2.3.1 + * + * @param[in] event The call handling event happened from Hands-Free + * @param[in] call_id The call ID + * @param[in] user_data The user data passed from the callback registration function + * @see bt_ag_set_call_handling_event_cb() + * @see bt_ag_unset_call_handling_event_cb() + */ +typedef void (*bt_ag_call_handling_event_cb) (bt_ag_call_handling_event_e event, unsigned int call_id, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Called when a multi call handling event happened from Hands-Free. + * @since_tizen 2.3.1 + * + * @param[in] event The call handling event happened from Hands-Free + * @param[in] user_data The user data passed from the callback registration function + * @see bt_ag_set_multi_call_handling_event_cb() + * @see bt_ag_unset_multi_call_handling_event_cb() + */ +typedef void (*bt_ag_multi_call_handling_event_cb) (bt_ag_multi_call_handling_event_e event, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Called when a DTMF(Dual Tone Multi Frequency) is transmitted from Hands-Free. + * @since_tizen 2.3.1 + * + * @param[in] dtmf The DTMF transmitted from Hands-Free + * @param[in] user_data The user data passed from the callback registration function + * @see bt_ag_set_dtmf_transmitted_cb() + * @see bt_ag_unset_dtmf_transmitted_cb() + */ +typedef void (*bt_ag_dtmf_transmitted_cb) (const char *dtmf, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Called when the speaker gain of the remote device is changed. + * @since_tizen 2.3.1 + * + * @param[in] gain The gain of speaker (0 ~ 15) + * @param[in] user_data The user data passed from the callback registration function + * @see bt_ag_set_speaker_gain_changed_cb() + * @see bt_ag_unset_speaker_gain_changed_cb() + */ +typedef void (*bt_ag_speaker_gain_changed_cb) (int gain, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Called when the microphone gain of the remote device is changed. + * @since_tizen 2.3.1 + * + * @param[in] gain The gain of microphone (0 ~ 15) + * @param[in] user_data The user data passed from the callback registration function + * @see bt_ag_set_microphone_gain_changed_cb() + * @see bt_ag_unset_microphone_gain_changed_cb() + */ +typedef void (*bt_ag_microphone_gain_changed_cb) (int gain, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief Called when the connection state is changed. + * @since_tizen 2.3.1 + * + * @param[in] connected The state to be changed. @a true means connected state, Otherwise, @a false. + * @param[in] remote_address The remote address + * @param[in] user_data The user data passed from the callback registration function + * @see bt_avrcp_target_initialize() + * @see bt_avrcp_target_deinitialize() + */ +typedef void (*bt_avrcp_target_connection_state_changed_cb) (bool connected, const char *remote_address, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief Called when the equalizer state is changed by the remote control device. + * @since_tizen 2.3.1 + * + * @param[in] equalizer The equalizer state + * @param[in] user_data The user data passed from the callback registration function + * @see bt_avrcp_set_equalizer_state_changed_cb() + * @see bt_avrcp_unset_equalizer_state_changed_cb() + */ +typedef void (*bt_avrcp_equalizer_state_changed_cb) (bt_avrcp_equalizer_state_e equalizer, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief Called when the repeat mode is changed by the remote control device. + * @since_tizen 2.3.1 + * + * @param[in] repeat The repeat mode + * @param[in] user_data The user data passed from the callback registration function + * @see bt_avrcp_set_repeat_mode_changed_cb() + * @see bt_avrcp_unset_repeat_mode_changed_cb() + */ +typedef void (*bt_avrcp_repeat_mode_changed_cb) (bt_avrcp_repeat_mode_e repeat, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief Called when the shuffle mode is changed by the remote control device. + * @since_tizen 2.3.1 + * + * @param[in] shuffle The shuffle mode + * @param[in] user_data The user data passed from the callback registration function + * @see bt_avrcp_set_shuffle_mode_changed_cb() + * @see bt_avrcp_unset_shuffle_mode_changed_cb() + */ +typedef void (*bt_avrcp_shuffle_mode_changed_cb) (bt_avrcp_shuffle_mode_e shuffle, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief Called when the scan mode is changed by the remote control device. + * @since_tizen 2.3.1 + * + * @param[in] shuffle The shuffle mode + * @param[in] user_data The user data passed from the callback registration function + * @see bt_avrcp_set_scan_mode_changed_cb() + * @see bt_avrcp_unset_scan_mode_changed_cb() + */ +typedef void (*bt_avrcp_scan_mode_changed_cb) (bt_avrcp_scan_mode_e scan, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_HID_MODULE + * @brief Called when the connection state is changed. + * @since_tizen 2.3.1 + * + * @details This callback is called when the connection state is changed. + * When you call bt_hid_host_connect() or bt_hid_host_disconnect(), this callback is also called with error result even though these functions fail. + * @param[in] result The result of changing the connection state + * @param[in] connected The state to be changed. @a true means connected state, Otherwise, @a false. + * @param[in] remote_address The remote address + * @param[in] user_data The user data passed from the callback registration function + * @see bt_hid_host_connect() + * @see bt_hid_host_disconnect() + */ +typedef void (*bt_hid_host_connection_state_changed_cb) (int result, bool connected, const char *remote_address, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_HDP_MODULE + * @brief Called when the connection is established. + * @since_tizen 2.3.1 + * + * @param[in] result The result of connecting to the remote device + * @param[in] remote_address The address of connected remote device + * @param[in] app_id The ID of application + * @param[in] type The type of HDP(Health Device Profile) channel + * @param[in] channel The connected data channel + * @param[in] user_data The user data passed from the callback registration function + * @see bt_hdp_disconnected_cb + * @see bt_hdp_set_connection_state_changed_cb() + * @see bt_hdp_unset_connection_state_changed_cb() + */ +typedef void (*bt_hdp_connected_cb) (int result, const char *remote_address, const char *app_id, + bt_hdp_channel_type_e type, unsigned int channel, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_HDP_MODULE + * @brief Called when the connection is disconnected. + * @since_tizen 2.3.1 + * + * @param[in] result The result of disconnecting from the remote device + * @param[in] remote_address The address of disconnected remote device + * @param[in] channel The connected data channel + * @param[in] user_data The user data passed from the callback registration function + * @see bt_hdp_connected_cb + * @see bt_hdp_set_connection_state_changed_cb() + * @see bt_hdp_unset_connection_state_changed_cb() + */ +typedef void (*bt_hdp_disconnected_cb) (int result, const char *remote_address, unsigned int channel, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_HDP_MODULE + * @brief Called when the you receive the data. + * @since_tizen 2.3.1 + * + * @param[in] channel The connected data channel + * @param[in] data The received data + * @param[in] size The size of received data (byte) + * @param[in] user_data The user data passed from the callback registration function + * @see bt_hdp_set_data_received_cb() + * @see bt_hdp_unset_data_received_cb() + */ +typedef void (*bt_hdp_data_received_cb) (unsigned int channel, const char *data, unsigned int size, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Called when you get GATT handles repeatedly + * @since_tizen 2.3.1 + * + * @param[in] total The total number of GATT handles to be called + * @param[in] index The index of current GATT handle. It starts from 0. + * @param[in] gatt_handle The GATT handle + * @param[in] user_data The user data passed from the foreach function + * + * @see bt_gatt_service_foreach_characteristics() + * @see bt_gatt_service_foreach_included_services() + * @see bt_gatt_characteristic_foreach_descriptors() + * @see bt_gatt_client_foreach_services() + */ +typedef bool (*bt_gatt_foreach_cb) (int total, int index, bt_gatt_h gatt_handle, + void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Called when the client request(e.g. read / write) has been completed + * @since_tizen 2.3.1 + * + * @param[in] result The result of a request + * @param[in] request_handle The requesting GATT handle + * @param[in] user_data The user data passed from the requesting function + * + * @see bt_gatt_client_read_value() + * @see bt_gatt_client_write_value() + */ +typedef void (*bt_gatt_client_request_completed_cb) (int result, + bt_gatt_h request_handle, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Called when a value of a watched characteristic's GATT handle has been changed + * @since_tizen 2.3.1 + * + * @remarks After this function is returned, a changed vlaue is automatically + * applied to @a characteristic. Before that, @a characteristic has an old value. + * + * @param[in] characteristic The characteristic's GATT handle of which value change is informed. It has an old value. + * @param[in] value The new value + * @param[in] len The length of @a value + * @param[in] user_data The user data passed from the registering function + * + * @see bt_gatt_client_set_characteristic_value_changed_cb() + */ +typedef void (*bt_gatt_client_characteristic_value_changed_cb) (bt_gatt_h characteristic, + char *value, int len, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Called when the connection state is changed. + * @since_tizen 2.3.1 + * + * @details This callback is called when the connection state is changed. + * When you called bt_gatt_connect() or bt_gatt_disconnect(), this callback is also called with error result even though these functions fail. + * + * @param[in] result The result of changing the connection state. + * @param[in] connected The state to be changed, @a true means connected state, Otherwise, @a false. + * @param[in] remote_address The remote_address + * @param[in] user_data The user data passed from the callback registration function. + * + * @see bt_gatt_connect() + * @see bt_gatt_disconnect() + * @see bt_gatt_set_connection_state_changed_cb() + * @see bt_gatt_unset_connection_state_changed_cb() + */ +typedef void (*bt_gatt_connection_state_changed_cb)(int result, bool connected, const char *remote_address, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_PAN_NAP_MODULE + * @brief Called when the connection state is changed. + * @since_tizen 2.3.1 + * + * @param[in] connected Indicates whether a client is connected or disconnected + * @param[in] remote_address The remote address + * @param[in] interface_name The interface name. For example, bnep0, bnep1. + * @param[in] user_data The user data passed from the callback registration function + * @see bt_nap_set_connection_state_changed_cb() + * @see bt_nap_unset_connection_state_changed_cb() + */ +typedef void (*bt_nap_connection_state_changed_cb) (bool connected, const char *remote_address, const char *interface_name, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_PAN_PANU_MODULE + * @brief Called when the connection state is changed. + * @since_tizen 2.3.1 + * + * @details This callback is called when the connection state is changed. + * When you call bt_panu_connect() or bt_panu_disconnect(), this callback is also called with error result even though these functions fail. + * @param[in] result The result of changing the connection state + * @param[in] connected The state to be changed. @a true means connected state, Otherwise, @a false. + * @param[in] remote_address The remote address + * @param[in] type The type of PAN service + * @param[in] user_data The user data passed from the callback registration function + * @see bt_nap_set_connection_state_changed_cb() + * @see bt_nap_unset_connection_state_changed_cb() + */ +typedef void (*bt_panu_connection_state_changed_cb) (int result, bool connected, const char *remote_address, bt_panu_service_type_e type, void *user_data); + + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif // __TIZEN_NETWORK_BLUETOOTH_TYPE_H__ diff --git a/include/wearable/bluetooth_type_internal.h b/include/wearable/bluetooth_type_internal.h new file mode 100644 index 0000000..80e1f5b --- /dev/null +++ b/include/wearable/bluetooth_type_internal.h @@ -0,0 +1,582 @@ +/* + * 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 __TIZEN_NETWORK_BLUETOOTH_TYPE_INTERNAL_H__ +#define __TIZEN_NETWORK_BLUETOOTH_TYPE_INTERNAL_H__ + + #ifdef __cplusplus +extern "C" +{ +#endif /* __cplusplus */ + +/** + * @file bluetooth_type_internal.h + */ + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_PBAP_MODULE + * @brief definitions for PBAP fields. + * @since_tizen 2.3 + */ +#define BT_PBAP_FIELD_ALL (0xFFFFFFFFFFFFFFFFULL) +#define BT_PBAP_FIELD_VERSION (1ULL << 0) +#define BT_PBAP_FIELD_FN (1ULL << 1) +#define BT_PBAP_FIELD_N (1ULL << 2) +#define BT_PBAP_FIELD_PHOTO (1ULL << 3) +#define BT_PBAP_FIELD_BDAY (1ULL << 4) +#define BT_PBAP_FIELD_ADR (1ULL << 5) +#define BT_PBAP_FIELD_LABEL (1ULL << 6) +#define BT_PBAP_FIELD_TEL (1ULL << 7) +#define BT_PBAP_FIELD_EMAIL (1ULL << 8) +#define BT_PBAP_FIELD_MAILER (1ULL << 9) +#define BT_PBAP_FIELD_TZ (1ULL << 10) +#define BT_PBAP_FIELD_GEO (1ULL << 11) +#define BT_PBAP_FIELD_TITLE (1ULL << 12) +#define BT_PBAP_FIELD_ROLE (1ULL << 13) +#define BT_PBAP_FIELD_LOGO (1ULL << 14) +#define BT_PBAP_FIELD_AGENT (1ULL << 15) +#define BT_PBAP_FIELD_ORG (1ULL << 16) +#define BT_PBAP_FIELD_NOTE (1ULL << 17) +#define BT_PBAP_FIELD_REV (1ULL << 18) +#define BT_PBAP_FIELD_SOUND (1ULL << 19) +#define BT_PBAP_FIELD_URL (1ULL << 20) +#define BT_PBAP_FIELD_UID (1ULL << 21) +#define BT_PBAP_FIELD_KEY (1ULL << 22) +#define BT_PBAP_FIELD_NICKNAME (1ULL << 23) +#define BT_PBAP_FIELD_CATEGORIES (1ULL << 24) +#define BT_PBAP_FIELD_PROID (1ULL << 25) +#define BT_PBAP_FIELD_CLASS (1ULL << 26) +#define BT_PBAP_FIELD_SORT_STRING (1ULL << 27) +#define BT_PBAP_FIELD_X_IRMC_CALL_DATETIME (1ULL << 28) + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Enumerations of the Bluetooth adapter le scan type. + * @since_tizen 2.3 + */ +typedef enum +{ + BT_ADAPTER_LE_PASSIVE_SCAN = 0x00, + BT_ADAPTER_LE_ACTIVE_SCAN +} bt_adapter_le_scan_type_e; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Enumerations of the Bluetooth le scan mode. + * @since_tizen 2.3 + */ +typedef enum +{ + BT_ADAPTER_LE_SCAN_MODE_BALANCED, + BT_ADAPTER_LE_SCAN_MODE_LOW_LATENCY, + BT_ADAPTER_LE_SCAN_MODE_LOW_ENERGY +} bt_adapter_le_scan_mode_e; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_HF_MODULE + * @brief Enumerations for the call handling event + * @since_tizen 2.3 + */ +typedef enum { + BT_HF_CALL_HANDLING_EVENT_ANSWER = 0x00, /**< Request to answer an incoming call */ + BT_HF_CALL_HANDLING_EVENT_RELEASE, /**< Request to release a call */ + BT_HF_CALL_HANDLING_EVENT_REJECT, /**< Request to reject an incoming call */ + BT_HF_CALL_HANDLING_EVENT_RING, /**< Request of ringing call */ + BT_HF_CALL_HANDLING_EVENT_CALL_STARTED, /**< Request of Call started */ + BT_HF_CALL_HANDLING_EVENT_CALL_ENDED, /**< Request of Call Ended */ + BT_HF_CALL_HANDLING_EVENT_VOICE_RECOGNITION_ENABLED, /**< Request of voice recognition enabled */ + BT_HF_CALL_HANDLING_EVENT_VOICE_RECOGNITION_DISABLED, /**< Request of voice recognition disabled */ + BT_HF_CALL_HANDLING_EVENT_VENDOR_DEP_CMD, /**< Request of Vendor command */ + BT_HF_CALL_HANDLING_EVENT_WAITING, /**< Request to waiting a call */ + BT_HF_CALL_HANDLING_EVENT_HELD, /**< Request to hold a call */ + BT_HF_CALL_HANDLING_EVENT_UNHELD, /**< Request to unhold calls */ + BT_HF_CALL_HANDLING_EVENT_SWAPPED, /**< Request to swap calls */ +} bt_hf_call_handling_event_e; + + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_HF_MODULE + * @brief Enumerations for the multi call handling event + * @since_tizen 2.3 + */ +typedef enum { + BT_HF_MULTI_CALL_HANDLING_EVENT_RELEASE_HELD_CALLS = 0x00, /**< Request to release held calls */ + BT_HF_MULTI_CALL_HANDLING_EVENT_RELEASE_ACTIVE_CALLS, /**< Request to release active calls */ + BT_HF_MULTI_CALL_HANDLING_EVENT_ACTIVATE_HELD_CALL, /**< Request to put active calls into hold state and activate another (held or waiting) call */ + BT_HF_MULTI_CALL_HANDLING_EVENT_MERGE_CALLS, /**< Request to add a held call to the conversation */ + BT_HF_MULTI_CALL_HANDLING_EVENT_EXPLICIT_CALL_TRANSFER, /**< Request to let a user who has two calls to connect these two calls together and release its connections to both other parties */ +} bt_hf_multi_call_handling_event_e; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_HF_MODULE + * @brief Enumerations for the call state + * @since_tizen 2.3 + */ +typedef enum { + BT_HF_CALL_EVENT_IDLE = 0x00, /**< Idle */ + BT_HF_CALL_EVENT_ANSWER, /**< Answered */ + BT_HF_CALL_EVENT_HOLD, /**< Held */ + BT_HF_CALL_EVENT_RETRIEVE, /**< Retrieved */ + BT_HF_CALL_EVENT_DIAL, /**< Dialing */ + BT_HF_CALL_EVENT_ALERT, /**< Alerting */ + BT_HF_CALL_EVENT_INCOMING, /**< Incoming */ + BT_HF_CALL_EVENT_REDIAL, /**< Redialling */ + BT_HF_CALL_EVENT_RELEASE_ALL_NONACTIVE_CALLS, /**< Release all nonactive calls */ + BT_HF_CALL_EVENT_ACCEPT_AND_RELEASE, /**< Accept and Release */ + BT_HF_CALL_EVENT_ACCEPT_AND_HOLD, /**< Accept and Hold */ + BT_HF_CALL_EVENT_ADD_TO_CONVERSATION, /**< Add to the conversation */ +} bt_hf_call_event_e; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_PBAP_MODULE + * @brief Enumerations of Addressbook memory for PBAP. + * @since_tizen 2.3 + */ +typedef enum +{ + BT_PBAP_PHONE = 0x00, /**< Request for Addressbook from Phone*/ + BT_PBAP_SIM , /**< Request for Addressbook from SIM*/ +} bt_pbap_addressbook_source_e; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_PBAP_MODULE + * @brief Enumerations of Folder type. + * @since_tizen 2.3 + */ +typedef enum +{ + BT_PBAP_PHONEBOOK = 0x00, /**< Request for Addressbook*/ + BT_PBAP_INCOMING , /**< Request for Incoming Calls*/ + BT_PBAP_OUTGOING , /**< Request for Outgoing Calls*/ + BT_PBAP_MISSED , /**< Request for Missed Calls*/ + BT_PBAP_COMBINED , /**< Request for Combined Calls*/ +} bt_pbap_folder_type_e; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_PBAP_MODULE + * @brief Enumerations of Phonebook Search field. + * @since_tizen 2.3 + */ +typedef enum +{ + BT_PBAP_SEARCH_NAME = 0x00, /**< Request for Search by name (default)*/ + BT_PBAP_SEARCH_NUMBER, /**< Request for Search by phone number*/ + BT_PBAP_SEARCH_SOUND, /**< Request for Search by sound*/ +} bt_pbap_search_field_e; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_PBAP_MODULE + * @brief Enumerations of vCard Formats. + * @since_tizen 2.3 + */ +typedef enum +{ + BT_PBAP_APP_PARAM_VCARD21 = 0x00, /**< vCard Format 2.1 (default)*/ + BT_PBAP_APP_PARAM_VCARD30, /**< vCard Format 3.0*/ +} bt_pbap_filter_vcard_format_e; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_PBAP_MODULE + * @brief Enumerations of Sorting Orders. + * @since_tizen 2.3 + */ +typedef enum +{ + BT_PBAP_APP_PARAM_ORDER_INDEXED = 0x00, /**< Filter Order Indexed (default)*/ + BT_PBAP_APP_PARAM_ORDER_ALPHANUMERIC, /**< Filter Order Alphanumeric*/ + BT_PBAP_APP_PARAM_ORDER_PHONETIC, /**< Filter Order Phonetic*/ +} bt_pbap_filter_sort_order_e; + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief Enumerations for the player control command + * @since_tizen 2.3 + */ + typedef enum { + BT_AVRCP_CONTROL_PLAY = 0x01, /**< Play */ + BT_AVRCP_CONTROL_PAUSE, /**< Pause */ + BT_AVRCP_CONTROL_STOP, /**< Stop */ + BT_AVRCP_CONTROL_NEXT, /**< Next Track*/ + BT_AVRCP_CONTROL_PREVIOUS, /**< Previous track */ + BT_AVRCP_CONTROL_FAST_FORWARD, /**< Fast Forward */ + BT_AVRCP_CONTROL_REWIND /**< Rewind */ +} bt_avrcp_player_command_e; + + /** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief Structure of Track metadata information. + * @since_tizen 2.3 + * + * @see #bt_class_s + */ +typedef struct { + const char *title; + const char *artist; + const char *album; + const char *genre; + unsigned int total_tracks; + unsigned int number; + unsigned int duration; +} bt_avrcp_metadata_attributes_info_s; + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief Called when the connection state is changed. + * @since_tizen 2.3 + * @param[in] connected The state to be changed. @a true means connected state, Otherwise, @a false. + * @param[in] remote_address The remote address + * @param[in] user_data The user data passed from the callback registration function + * @see bt_avrcp_control_initialize() + * @see bt_avrcp_control_deinitialize() + */ +typedef void (*bt_avrcp_control_connection_state_changed_cb) (bool connected, const char *remote_address, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief Called when the Song position mode is changed by the remote target device. + * @since_tizen 2.3 + * + * @param[in] position The song position + * @param[in] user_data The user data passed from the callback registration function + * @see bt_avrcp_set_song_position_changed_cb() + * @see bt_avrcp_unset_song_position_changed_cb() + */ +typedef void (*bt_avrcp_song_position_changed_cb) (unsigned int position, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief Called when the Song metadata information is changed by the remote target device. + * @since_tizen 2.3 + * + * @param[in] position The song metadata information + * @param[in] user_data The user data passed from the callback registration function + * @see bt_avrcp_set_track_info_changed_cb() + * @see bt_avrcp_unset_track_info_changed_cb() + */ +typedef void (*bt_avrcp_track_info_changed_cb) (bt_avrcp_metadata_attributes_info_s *track, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief Called when the Song Play status mode is changed by the remote target device. + * @since_tizen 2.3 + * + * @param[in] play_state The song play status + * @param[in] user_data The user data passed from the callback registration function + * @see bt_avrcp_set_play_status_changed_cb() + * @see bt_avrcp_unset_play_status_changed_cb() + */ +typedef void (*bt_avrcp_play_status_changed_cb) (bt_avrcp_player_state_e play_state, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_HF_MODULE + * @brief HF Call status information. + * @since_tizen 2.3 + */ +typedef struct { + char *number; /**< Phone Number */ + int direction; /**< Direction :Incoming(1), Outgoing(0) */ + int status; /**< Call Status :Active(0), Held(1), Waiting(5), Dailing(2) */ + int multi_party; /**< Multiparty/conf call: Yes(1), No(0) */ + int index; /**< Call index/ID */ +} bt_hf_call_status_info_s; + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Called when the manufacturer dat changes. + * @since_tizen 2.3 + * + * @param[in] data The manufacurer data of the Bluetooth device to be changed + * @param[in] len The length of @a data + * @param[in] user_data The user data passed from the callback registration function + * @pre This function will be invoked when the manufacturer data of Bluetooth adapter changes + * if callback is registered using bt_adapter_set_manufacturer_data_changed_cb(). + * @see bt_adapter_set_manufacturer_data() + * @see bt_adapter_set_manufacturer_data_changed_cb() + * @see bt_adapter_unset_manufacturer_data_changed_cb() + */ +typedef void (*bt_adapter_manufacturer_data_changed_cb) (char *data, + int len, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_HF_MODULE + * @brief Called when the SCO(Synchronous Connection Oriented link) state is changed. + * @since_tizen 2.3 + * + * @details This callback is called when the SCO state is changed. + * When you call bt_ag_open_sco() or bt_ag_close_sco(), this callback is also called with error result even though these functions failed. + * @param[in] result The result of changing the connection state + * @param[in] opened The state to be changed: (@c true = opened, @c false = not opened) + * @param[in] user_data The user data passed from the callback registration function + * @see bt_ag_set_sco_state_changed_cb() + * @see bt_ag_unset_sco_state_changed_cb() + * @see bt_ag_open_sco() + * @see bt_ag_close_sco() + */ +typedef void (*bt_hf_sco_state_changed_cb) (int result, bool opened, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_HF_MODULE + * @brief Called when a call handling event happened from Hands-Free. + * @since_tizen 2.3 + * + * @param[in] event The call handling event happened from Hands-Free + * @param[in] call_id The call ID + * @param[in] user_data The user data passed from the callback registration function + * @see bt_ag_set_call_handling_event_cb() + * @see bt_ag_unset_call_handling_event_cb() + */ +typedef void (*bt_hf_call_handling_event_cb) (bt_hf_call_handling_event_e event, char *phone_number, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_HF_MODULE + * @brief Called when a multi call handling event happened from Hands-Free. + * @since_tizen 2.3 + * + * @param[in] event The call handling event happened from Hands-Free + * @param[in] user_data The user data passed from the callback registration function + * @see bt_ag_set_multi_call_handling_event_cb() + * @see bt_ag_unset_multi_call_handling_event_cb() + */ +typedef void (*bt_hf_multi_call_handling_event_cb) (bt_hf_multi_call_handling_event_e event, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_HF_MODULE + * @brief Called when the speaker gain of the remote device is changed. + * @since_tizen 2.3 + * + * @param[in] gain The gain of speaker (0 ~ 15) + * @param[in] user_data The user data passed from the callback registration function + * @see bt_hf_set_speaker_gain_changed_cb() + * @see bt_hf_unset_speaker_gain_changed_cb() + */ +typedef void (*bt_hf_speaker_gain_changed_cb) (int gain, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_HF_MODULE + * @brief Called when a call status updated event happened from Hands-Free. + * @since_tizen 2.3 + * @remarks call_info_list has elements which consist of bt_hf_call_status_info_s + * @remarks The @a call_info_list must be released with bt_hf_free_call_status_info_list() by you. + * + * @param[in] event The call handling event happened from Hands-Free + * @param[in] call_id The call ID + * @param[in] user_data The user data passed from the callback registration function + * @see bt_hf_call_status_info_s + * @see bt_hf_set_call_status_updated_event_cb() + * @see bt_hf_unset_call_status_updated_event_cb() + */ +typedef void (*bt_hf_call_status_updated_event_cb) (GSList *call_info_list, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_PBAP_MODULE + * @brief Called when PBAP is Connected or Disconnected. + * @since_tizen 2.3 + * + * @param[in] remote_address Remote Device address + * @param[in] pbap_enabled PBAP connection status (@c 1 = enabled, @c 0 = disabled) + * @param[in] user_data The user data passed from the callback registration function + * @see bt_pbap_connect() + * @see bt_pbap_disconnect() + */ +typedef void (*bt_pbap_enabled_cb)(const char *remote_address, + int pbap_enabled, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_PBAP_MODULE + * @brief Called when PBAP Phonebook Size is returned. + * @since_tizen 2.3 + * + * @param[in] remote_address Remote Device address + * @param[in] size Size of Phonebook + * @param[in] user_data The user data passed from the callback registration function + * @see bt_pbap_get_phonebook_size() + * @see bt_pbap_connect() + * @see bt_pbap_disconnect() + */ +typedef void (*bt_pbap_phonebook_size_cb)(const char *remote_address, + int size, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_PBAP_MODULE + * @brief Called when PBAP Phonebook Pull returns all contacts. + * @since_tizen 2.3 + * + * @param[in] remote_address Remote Device address + * @param[in] vcf_file File in which vCards are saved + * @param[in] status Status for successful Transfer (@c 0 = Unsuccessful, @c 1 = Successful) + * @param[in] user_data The user data passed from the callback registration function + * @see bt_pbap_get_phonebook() + * @see bt_pbap_connect() + * @see bt_pbap_disconnect() + */ +typedef void (*bt_pbap_phonebook_pull_cb)(const char *remote_address, + char *vcf_file, int status, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_PBAP_MODULE + * @brief Called when PBAP List vCards returns the handles and Names. + * @since_tizen 2.3 + * + * @param[in] remote_address Remote Device address + * @param[in] vcards List of vCards + * @param[in] count Number of contacts in the list + * @param[in] status Status for successful Transfer (@c 0 = Unsuccessful, @c 1 = Successful) + * @param[in] user_data The user data passed from the callback registration function + * @see bt_pbap_get_phonebook() + * @see bt_pbap_connect() + * @see bt_pbap_disconnect() + */ +typedef void (*bt_pbap_list_vcards_cb)(const char *remote_address, + char **vcards, int count, int status, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_PBAP_MODULE + * @brief Called when PBAP Get vCard returns the contact. + * @since_tizen 2.3 + * + * @param[in] remote_address Remote Device address + * @param[in] vcard Contact as vCard + * @param[in] status Status for successful Transfer (@c 0 = Unsuccessful, @c 1 = Successful) + * @param[in] user_data The user data passed from the callback registration function + * @see bt_pbap_get_phonebook() + * @see bt_pbap_connect() + * @see bt_pbap_disconnect() + */ +typedef void (*bt_pbap_get_vcard_cb)(const char *remote_address, + char *vcard, int status, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_PBAP_MODULE + * @brief Called when PBAP Phonebook Search returns the handles and Names. + * @since_tizen 2.3 + * + * @param[in] remote_address Remote Device address + * @param[in] vcards List of vCards + * @param[in] count Number of contacts in the list + * @param[in] status Status for successful Transfer (@c 0 = Unsuccessful, @c 1 = Successful) + * @param[in] user_data The user data passed from the callback registration function + * @see bt_pbap_get_phonebook() + * @see bt_pbap_connect() + * @see bt_pbap_disconnect() + */ +typedef void (*bt_pbap_search_list_cb)(const char *remote_address, + char **vcards, int count, int status, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Enumerations of the attribute's permission + * @since_tizen 2.4 + */ +typedef enum { + BT_GATT_PERMISSION_READ = 0x01, + BT_GATT_PERMISSION_WRITE = 0x02, + BT_GATT_PERMISSION_ENCRYPTION = 0x04, + BT_GATT_PERMISSION_AUTHENTICATION = 0x08, + BT_GATT_PERMISSION_AUTHORIZATION = 0x10, + BT_GATT_PERMISSION_NONE = 0x20, +} bt_gatt_permission_e; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief The handle to control Bluetooth LE scan filter + * @since_tizen 2.4 + */ +typedef void* bt_scan_filter_h; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief The handle of a GATT server + * @since_tizen 2.4 + */ +typedef void* bt_gatt_server_h; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Called when a value of a characteristic or descriptor's GATT handle has been changed + * @since_tizen 2.4 + * + * @remarks After this function is returned, a changed vlaue is automatically + * applied to @a gatt_handle. Before that, @a gatt_handle has an old value. + * + * @param[in] remote_address The address of the remote device which requests a change + * @param[in] server The GATT server handle + * @param[in] gatt_handle The characteristic or descriptor's GATT handle which has an old value + * @param[in] offset The requested offset from where the @a gatt_handle value will be updated + * @param[in] value The new value + * @param[in] len The length of @a value + * @param[in] user_data The user data passed from the registration function + * + * @see bt_gatt_server_set_value_changed_cb() + */ +typedef void (*bt_gatt_server_value_changed_cb) (char *remote_address, + bt_gatt_server_h server, bt_gatt_h gatt_handle, + int offset, char *value, int len, + void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Called when the remote device requests to read a value on a GATT server + * @since_tizen 2.4 + * + * @param[in] remote_address The address of the requesting remote device + * @param[in] server The GATT server handle + * @param[in] gatt_handle The characteristic or descriptor's GATT handle to be read + * @param[in] request_id The identification of this request. It will be used to send a reponse. + * @param[in] offset The requested offset from where the GATT handle's value is read + * @param[in] user_data The user data passed from the registration function + * + * @see bt_gatt_server_set_read_value_requested_cb() + * @see bt_gatt_server_send_response() + */ +typedef void (*bt_gatt_server_read_value_requested_cb) (char *remote_address, + int request_id, bt_gatt_server_h server, bt_gatt_h gatt_handle, + int offset, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Called when the sending notification / indication is done + * @since_tizen 2.4 + * + * @remarks In case of an indication, once a confirmation is received from the remote device this callback will be called. \n + * This callback will be called several times if there are two or more remote devices which enable a Client Characteristic Configuration Descriptor(CCCD). \n + * For the last remote device, @a completed will be set as true. + * + * @param[in] result The result of a sending operation + * @param[in] remote_address The address of the remote device + * @param[in] server The GATT server handle + * @param[in] characteristic The characteristic's GATT handle + * @param[in] completed If this callback is for the last remote device which enables a CCCD, it will be true. Or it will be false. + * @param[in] user_data The user data passed from the requesting function + * + * @see bt_gatt_server_notify() + */ +typedef void (*bt_gatt_server_notification_sent_cb) (int result, + char *remote_address, bt_gatt_server_h server, + bt_gatt_h characteristic, bool completed, void *user_data); +/** + * @} + */ + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif // __TIZEN_NETWORK_BLUETOOTH_TYPE_INTERNAL_H__ diff --git a/packaging/capi-network-bluetooth.spec b/packaging/capi-network-bluetooth.spec index a41c233..774dc0f 100644 --- a/packaging/capi-network-bluetooth.spec +++ b/packaging/capi-network-bluetooth.spec @@ -1,22 +1,25 @@ #sbs-git:slp/api/bluetooth capi-network-bluetooth 0.1.0 686c444083e4197845c768e5dd034022b1dfa250 Name: capi-network-bluetooth Summary: Network Bluetooth Framework -Version: 0.1.15 +Version: 0.1.53 Release: 1 Group: TO_BE/FILLED_IN -License: TO BE FILLED IN +License: Apache-2.0 Source0: %{name}-%{version}.tar.gz -Requires(post): /sbin/ldconfig -Requires(postun): /sbin/ldconfig +Requires(post): eglibc +Requires(postun): eglibc -BuildRequires: pkgconfig(dbus-glib-1) BuildRequires: pkgconfig(dlog) BuildRequires: pkgconfig(glib-2.0) BuildRequires: pkgconfig(vconf) BuildRequires: pkgconfig(bluetooth-api) BuildRequires: pkgconfig(capi-base-common) +%if "%{?tizen_profile_name}" == "wearable" +BuildRequires: pkgconfig(privacy-manager-client) +%endif BuildRequires: cmake +BuildRequires: model-build-features %description @@ -30,10 +33,127 @@ Requires: %{name} = %{version}-%{release} %description devel Network Bluetooth Framework (DEV). +%package test +Summary: Network Bluetooth Framework test application +Group: TO_BE/FILLED +Requires: %{name} = %{version}-%{release} + +%description test +This package is C-API test application. + +%package gatt-test +Summary: Gatt Test Application +Group: TO_BE/FILLED +Requires: %{name} = %{version}-%{release} + +%description gatt-test +This package is C-API gatt-test application. + +%package infinite-boot-test +Summary: Network Bluetooth Framework infinite reboot test application +Group: TO_BE/FILLED + +%description infinite-boot-test +This package is made to test BT on while infinte boot + +%package infinite-spp-test-server +Summary: Network Bluetooth Framework infinite spp test application as server role +Group: TO_BE/FILLED + +%description infinite-spp-test-server +This package is made to test SPP throughput infintely as server role + +%package infinite-spp-test-client +Summary: Network Bluetooth Framework infinite spp test application as client role +Group: TO_BE/FILLED + +%description infinite-spp-test-client +This package is made to test SPP throughput infintely as client role + %prep %setup -q %build +export CFLAGS="$CFLAGS -DTIZEN_DEBUG_ENABLE -DTIZEN_ENGINEER_MODE" +export CXXFLAGS="$CXXFLAGS -DTIZEN_DEBUG_ENABLE -DTIZEN_ENGINEER_MODE" +export FFLAGS="$FFLAGS -DTIZEN_DEBUG_ENABLE -DTIZEN_ENGINEER_MODE" + +%if "%{?tizen_profile_name}" == "wearable" +export CFLAGS="$CFLAGS -DTIZEN_WEARABLE" +export CXXFLAGS="$CXXFLAGS -DTIZEN_WEARABLE" +export FFLAGS="$FFLAGS -DTIZEN_WEARABLE" +%endif + +%if "%{?tizen_profile_name}" == "mobile" +export CFLAGS="$CFLAGS -DBT_ENABLE_LEGACY_GATT_CLIENT" +export CXXFLAGS="$CXXFLAGS -DBT_ENABLE_LEGACY_GATT_CLIENT" +export FFLAGS="$FFLAGS -DBT_ENABLE_LEGACY_GATT_CLIENT" +%endif + +%if %{?model_build_feature_bt_disable_all} +export CFLAGS="$CFLAGS -DTIZEN_BT_DISABLE -DTIZEN_LE_DISABLE -DTIZEN_GATT_DISABLE + -DTIZEN_OPP_SERVER_DISABLE -DTIZEN_OPP_CLIENT_DISABLE + -DTIZEN_PAN_DISABLE -DTIZEN_HID_DISABLE -DTELEPHONY_DISABLED + -DTIZEN_AVRCP_DISABLE -DTIZEN_HDP_DISABLE" +export CXXFLAGS="$CXXFLAGS -DTIZEN_BT_DISABLE -DTIZEN_LE_DISABLE -DTIZEN_GATT_DISABLE + -DTIZEN_OPP_SERVER_DISABLE -DTIZEN_OPP_CLIENT_DISABLE + -DTIZEN_PAN_DISABLE -DTIZEN_HID_DISABLE -DTELEPHONY_DISABLED + -DTIZEN_AVRCP_DISABLE -DTIZEN_HDP_DISABLE" +export FFLAGS="$FFLAGS -DTIZEN_BT_DISABLE -DTIZEN_LE_DISABLE -DTIZEN_GATT_DISABLE + -DTIZEN_OPP_SERVER_DISABLE -DTIZEN_OPP_CLIENT_DISABLE + -DTIZEN_PAN_DISABLE -DTIZEN_HID_DISABLE -DTELEPHONY_DISABLED + -DTIZEN_AVRCP_DISABLE -DTIZEN_HDP_DISABLE" +%else +%if %{?model_build_feature_bt_disable_le} +export CFLAGS="$CFLAGS -DTIZEN_LE_DISABLE -DTIZEN_GATT_DISABLE" +export CXXFLAGS="$CXXFLAGS -DTIZEN_LE_DISABLE -DTIZEN_GATT_DISABLE" +export FFLAGS="$FFLAGS -DTIZEN_LE_DISABLE -DTIZEN_GATT_DISABLE" +%endif + +%if %{?model_build_feature_bt_disable_opp} +export CFLAGS="$CFLAGS -DTIZEN_OPP_SERVER_DISABLE -DTIZEN_OPP_CLIENT_DISABLE" +export CXXFLAGS="$CXXFLAGS -DTIZEN_OPP_SERVER_DISABLE -DTIZEN_OPP_CLIENT_DISABLE" +export FFLAGS="$FFLAGS -DTIZEN_OPP_SERVER_DISABLE -DTIZEN_OPP_CLIENT_DISABLE" +%endif + +%if %{?model_build_feature_bt_disable_tethering} +export CFLAGS="$CFLAGS -DTIZEN_PAN_DISABLE" +export CXXFLAGS="$CXXFLAGS -DTIZEN_PAN_DISABLE" +export FFLAGS="$FFLAGS -DTIZEN_PAN_DISABLE" +%endif + +%if %{?model_build_feature_bt_disable_hid} +export CFLAGS="$CFLAGS -DTIZEN_HID_DISABLE" +export CXXFLAGS="$CXXFLAGS -DTIZEN_HID_DISABLE" +export FFLAGS="$FFLAGS -DTIZEN_HID_DISABLE" +%endif + +%if %{?model_build_feature_bt_disable_audio_call} +export CFLAGS="$CFLAGS -DTELEPHONY_DISABLED -DTIZEN_HFP_DISABLE" +export CXXFLAGS="$CXXFLAGS -DTELEPHONY_DISABLED -DTIZEN_HFP_DISABLE" +export FFLAGS="$FFLAGS -DTELEPHONY_DISABLED -DTIZEN_HFP_DISABLE" +%endif + +%if %{?model_build_feature_bt_disable_audio_media} +export CFLAGS="$CFLAGS -DTIZEN_AVRCP_DISABLE -DTIZEN_A2DP_DISABLE" +export CXXFLAGS="$CXXFLAGS -DTIZEN_AVRCP_DISABLE -DTIZEN_A2DP_DISABLE" +export FFLAGS="$FFLAGS -DTIZEN_AVRCP_DISABLE -DTIZEN_A2DP_DISABLE" +%endif + +%if %{?model_build_feature_bt_disable_health} +export CFLAGS="$CFLAGS -DTIZEN_HDP_DISABLE" +export CXXFLAGS="$CXXFLAGS -DTIZEN_HDP_DISABLE" +export FFLAGS="$FFLAGS -DTIZEN_HDP_DISABLE" +%endif +%endif + +%cmake \ +%if "%{?tizen_profile_name}" == "wearable" + -DTIZEN_WEARABLE=YES \ +%else + -DTIZEN_WEARABLE=NO \ +%endif + MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'` cmake . -DCMAKE_INSTALL_PREFIX=/usr -DFULLVER=%{version} -DMAJORVER=${MAJORVER} @@ -42,17 +162,77 @@ make %{?jobs:-j%jobs} %install rm -rf %{buildroot} %make_install +install -D -m 0644 LICENSE %{buildroot}%{_datadir}/license/capi-network-bluetooth +install -D -m 0644 LICENSE %{buildroot}%{_datadir}/license/capi-network-bluetooth-devel +install -D -m 0644 test_scripts/bt_on_test_while_infinite.service %{buildroot}%{_libdir}/systemd/system/bt_on_test_while_infinite.service +install -D -m 0644 test/bt_infinite_spp_test_server.service %{buildroot}%{_libdir}/systemd/system/bt_infinite_spp_test_server.service +install -D -m 0644 test/bt_infinite_spp_test_client.service %{buildroot}%{_libdir}/systemd/system/bt_infinite_spp_test_client.service +install -D -m 0755 test_scripts/check_bt_during_infinite_boot.sh %{buildroot}/%{_prefix}/etc/bluetooth/check_bt_during_infinite_boot.sh %post -p /sbin/ldconfig %postun -p /sbin/ldconfig %files +%manifest bluetooth.manifest %{_libdir}/libcapi-network-bluetooth.so.* +%{_datadir}/license/capi-network-bluetooth + +%files test +%manifest bluetooth-test.manifest +%{_bindir}/bt_unit_test +%{_bindir}/bt_onoff +/etc/smack/accesses2.d/capi.network.bluetooth.test.rule + +%files gatt-test +%manifest bluetooth-gatt-test.manifest +%{_bindir}/bt_unit_test_gatt +/etc/smack/accesses2.d/capi.network.bluetooth.test.gatt.rule + +%files infinite-boot-test +%{_libdir}/systemd/system/bt_on_test_while_infinite.service +%attr(755,-,-) %{_prefix}/etc/bluetooth/check_bt_during_infinite_boot.sh + +%post infinite-boot-test +/usr/bin/systemctl daemon-reload +/usr/bin/systemctl enable bt_on_test_while_infinite.service + +%preun infinite-boot-test +/usr/bin/systemctl disable bt_on_test_while_infinite.service + +%files infinite-spp-test-server +%manifest bluetooth-infinite-spp-test-server.manifest +%{_bindir}/bt_infinite_spp_test +%{_libdir}/systemd/system/bt_infinite_spp_test_server.service +/etc/smack/accesses2.d/capi.network.bluetooth.infinite.spp.test.rule + +%post infinite-spp-test-server +/usr/bin/systemctl daemon-reload +/usr/bin/systemctl enable bt_infinite_spp_test_server.service + +%preun infinite-spp-test-server +/usr/bin/systemctl disable bt_infinite_spp_test_server.service + +%files infinite-spp-test-client +%manifest bluetooth-infinite-spp-test-client.manifest +%{_bindir}/bt_infinite_spp_test +%{_libdir}/systemd/system/bt_infinite_spp_test_client.service +/etc/smack/accesses2.d/capi.network.bluetooth.infinite.spp.test.rule + +%post infinite-spp-test-client +/usr/bin/systemctl daemon-reload +/usr/bin/systemctl enable bt_infinite_spp_test_client.service + +%preun infinite-spp-test-client +/usr/bin/systemctl disable bt_infinite_spp_test_client.service %files devel %{_includedir}/network/bluetooth.h +%{_includedir}/network/bluetooth_type.h +%{_includedir}/network/bluetooth_internal.h +%{_includedir}/network/bluetooth_type_internal.h %{_libdir}/pkgconfig/capi-network-bluetooth.pc %{_libdir}/libcapi-network-bluetooth.so +%{_datadir}/license/capi-network-bluetooth-devel diff --git a/src/bluetooth-adapter.c b/src/bluetooth-adapter.c index da0f9c8..400375e 100644 --- a/src/bluetooth-adapter.c +++ b/src/bluetooth-adapter.c @@ -21,25 +21,50 @@ #include #include #include +#include +#ifdef TIZEN_WEARABLE +#include +#endif #include #include "bluetooth.h" +#include "bluetooth_internal.h" #include "bluetooth_private.h" -#ifdef LOG_TAG -#undef LOG_TAG +#ifdef TIZEN_LE_DISABLE +#define BT_CHECK_LE_SUPPORT() \ + { \ + BT_CHECK_BT_SUPPORT(); \ + LOGE("[%s] NOT_SUPPORTED(0x%08x)", __FUNCTION__, BT_ERROR_NOT_SUPPORTED); \ + return BT_ERROR_NOT_SUPPORTED; \ + } +#else +#define BT_CHECK_LE_SUPPORT() #endif -#define LOG_TAG "TIZEN_N_BLUETOOTH" +static GSList *advertiser_list = NULL; int bt_adapter_enable(void) { int error_code = BT_ERROR_NONE; + BT_CHECK_BT_SUPPORT(); +#ifdef TIZEN_WEARABLE + static const char* PRIVILEGE_ID_BLUETOOTH_ADMIN = "http://tizen.org/privilege/bluetooth.admin"; + + error_code = privacy_checker_check_by_privilege(PRIVILEGE_ID_BLUETOOTH_ADMIN); + if (error_code != PRIV_MGR_ERROR_SUCCESS) { + privacy_checker_finalize(); + BT_ERR("PERMISSION_DENIED(0x%08x)", error_code); + return BT_ERROR_PERMISSION_DENIED; + } + privacy_checker_finalize(); +#endif + BT_CHECK_INIT_STATUS(); error_code = _bt_get_error_code(bluetooth_enable_adapter()); if (error_code != BT_ERROR_NONE) { - LOGE("[%s] %s(0x%08x)", __FUNCTION__, _bt_convert_error_to_string(error_code), error_code); + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error_code), error_code); } return error_code; } @@ -48,16 +73,44 @@ int bt_adapter_disable(void) { int error_code = BT_ERROR_NONE; + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); error_code = _bt_get_error_code(bluetooth_disable_adapter()); if (error_code != BT_ERROR_NONE) { - LOGE("[%s] %s(0x%08x)", __FUNCTION__, _bt_convert_error_to_string(error_code), error_code); + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error_code), error_code); + } + return error_code; +} + +int bt_adapter_recover(void) +{ + int error_code = BT_ERROR_NONE; + + BT_CHECK_BT_SUPPORT(); + BT_CHECK_INIT_STATUS(); + error_code = _bt_get_error_code(bluetooth_recover_adapter()); + if (error_code != BT_ERROR_NONE) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error_code), error_code); + } + return error_code; +} + +int bt_adapter_reset(void) +{ + int error_code = BT_ERROR_NONE; + + BT_CHECK_BT_SUPPORT(); + BT_CHECK_INIT_STATUS(); + error_code = _bt_get_error_code(bluetooth_reset_adapter()); + if (error_code != BT_ERROR_NONE) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error_code), error_code); } return error_code; } int bt_adapter_get_state(bt_adapter_state_e *adapter_state) { + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(adapter_state); @@ -65,46 +118,307 @@ int bt_adapter_get_state(bt_adapter_state_e *adapter_state) return BT_ERROR_NONE; } +int bt_adapter_le_enable(void) +{ + int error_code = BT_ERROR_NONE; + + BT_CHECK_BT_SUPPORT(); + BT_CHECK_INIT_STATUS(); + error_code = _bt_get_error_code(bluetooth_enable_adapter_le()); + if (error_code != BT_ERROR_NONE) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error_code), error_code); + } + return error_code; +} + +int bt_adapter_le_disable(void) +{ + int error_code = BT_ERROR_NONE; + + BT_CHECK_BT_SUPPORT(); + BT_CHECK_INIT_STATUS(); + + error_code = _bt_get_error_code(bluetooth_disable_adapter_le()); + if (error_code != BT_ERROR_NONE) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error_code), error_code); + } + return error_code; +} + +int bt_adapter_le_get_state(bt_adapter_le_state_e *adapter_le_state) +{ + BT_CHECK_BT_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(adapter_le_state); + + *adapter_le_state = bluetooth_check_adapter_le(); + return BT_ERROR_NONE; +} + int bt_adapter_get_address(char **address) { bluetooth_device_address_t loc_address = { {0} }; int error_code = BT_ERROR_NONE; + BT_CHECK_BT_SUPPORT(); 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) { - LOGE("[%s] %s(0x%08x)", __FUNCTION__, _bt_convert_error_to_string(error_code), error_code); + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error_code), error_code); return error_code; } error_code = _bt_convert_address_to_string(address, &loc_address); if (error_code != BT_ERROR_NONE) { - LOGE("[%s] %s(0x%08x)", __FUNCTION__, _bt_convert_error_to_string(error_code), error_code); + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error_code), error_code); return error_code; } return BT_ERROR_NONE; } +int bt_adapter_get_version(char **version) +{ + int ret = BT_ERROR_NONE; + bluetooth_version_t loc_ver = { { 0 } }; + + BT_CHECK_BT_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(version); + + ret = _bt_get_error_code(bluetooth_get_local_version(&loc_ver)); + if (ret != BT_ERROR_NONE) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); + return ret; + } + + *version = strdup(loc_ver.version); + if (*version == NULL) { + BT_ERR("OUT_OF_MEMORY(0x%08x)", BT_ERROR_OUT_OF_MEMORY); + return BT_ERROR_OUT_OF_MEMORY; + } + + return BT_ERROR_NONE; +} + +#define BT_ADAPTER_FIRMWARE_INFO_FILE_PATH "/var/lib/bluetooth/bcmtool_log" +#define BT_ADAPTER_STACK_INFO_FILE_PATH "/usr/etc/bluetooth/stack_info" + +int bt_adapter_get_local_info(char **chipset, char **firmware, char **stack_version, char **profiles) +{ + int ret = BT_ERROR_NONE; + FILE *fp = NULL; + char *buf = NULL; + long lsize; + size_t result; + char *info_start = NULL; + char *info_end = NULL; + long info_size; + char *local_chipset = NULL; + char *local_firmware = NULL; + char *local_stack_version = NULL; + char *local_profiles = NULL; + + BT_CHECK_BT_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(chipset); + BT_CHECK_INPUT_PARAMETER(firmware); + BT_CHECK_INPUT_PARAMETER(stack_version); + BT_CHECK_INPUT_PARAMETER(profiles); + + if ((fp = fopen(BT_ADAPTER_FIRMWARE_INFO_FILE_PATH, "r")) == NULL) { + BT_ERR("fopen() is failed(%s)", BT_ADAPTER_FIRMWARE_INFO_FILE_PATH); + + local_firmware = (char *)malloc(sizeof(char) * 1); + if (local_firmware == NULL) { + ret = BT_ERROR_OUT_OF_MEMORY; + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); + goto ERROR; + } + local_firmware[0] = '\0'; + local_chipset = (char *)malloc(sizeof(char) * 1); + if (local_chipset == NULL) { + ret = BT_ERROR_OUT_OF_MEMORY; + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); + goto ERROR; + } + local_chipset[0] = '\0'; + } else { + fseek(fp, 0, SEEK_END); + lsize = ftell(fp); + if (lsize < 0) { + BT_ERR("ftell() error(0x%x)", lsize); + ret = BT_ERROR_OPERATION_FAILED; + goto ERROR; + } + buf = (char *)malloc(sizeof(char) * (lsize + 1)); + if (buf == NULL) { + ret = BT_ERROR_OUT_OF_MEMORY; + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); + goto ERROR; + } + fseek(fp, 0, SEEK_SET); + result = fread(buf, 1, lsize, fp); + buf[lsize] = '\0'; + + if (result != lsize) + BT_ERR("fread() error"); + + info_start = strstr(buf, "bluetooth"); + if (info_start == NULL) { + BT_ERR("strstr() error(0x%x)", info_start); + ret = BT_ERROR_OPERATION_FAILED; + goto ERROR; + } + info_start += 10; + info_end = strstr(buf, "hcd"); + if (info_end == NULL) { + BT_ERR("strstr() error(0x%x)", info_end); + ret = BT_ERROR_OPERATION_FAILED; + goto ERROR; + } + info_size = info_end - info_start - 1; + + local_firmware = (char *)malloc(sizeof(char) * (info_size + 1)); + if (local_firmware == NULL) { + ret = BT_ERROR_OUT_OF_MEMORY; + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); + goto ERROR; + } + + strncpy(local_firmware, info_start, info_size); + local_firmware[info_size] = '\0'; + + info_end = strchr(buf, '_'); + if (info_end == NULL) { + BT_ERR("strchr() error(0x%x)", info_end); + ret = BT_ERROR_OPERATION_FAILED; + goto ERROR; + } + info_size = info_end - info_start; + + local_chipset = (char *)malloc(sizeof(char) * (info_size + 1)); + if (local_chipset == NULL) { + ret = BT_ERROR_OUT_OF_MEMORY; + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); + goto ERROR; + } + + strncpy(local_chipset, info_start, info_size); + local_chipset[info_size] = '\0'; + + if (buf) + free(buf); + buf = NULL; + fclose(fp); + } + + if ((fp = fopen(BT_ADAPTER_STACK_INFO_FILE_PATH, "r")) == NULL) { + BT_ERR("fopen() error"); + ret = BT_ERROR_OPERATION_FAILED; + goto ERROR; + } + + fseek(fp, 0, SEEK_END); + lsize = ftell(fp); + if (lsize < 0) { + BT_ERR("ftell() error(0x%x)", lsize); + ret = BT_ERROR_OPERATION_FAILED; + goto ERROR; + } + buf = (char *)malloc(sizeof(char) * (lsize + 1)); + if (buf == NULL) { + ret = BT_ERROR_OUT_OF_MEMORY; + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); + goto ERROR; + } + fseek(fp, 0, SEEK_SET); + result = fread(buf, 1, lsize, fp); + buf[lsize] = '\0'; + + if (result != lsize) { + BT_ERR("fread() error(0x%x)", result); + ret = BT_ERROR_OPERATION_FAILED; + goto ERROR; + } + + info_start = buf; + info_end = strchr(buf, ','); + if (info_end == NULL) { + BT_ERR("strchr() error(0x%x)", info_end); + ret = BT_ERROR_OPERATION_FAILED; + goto ERROR; + } + info_size = info_end - info_start; + + local_stack_version = (char *)malloc(sizeof(char) * (info_size + 1)); + if (local_stack_version == NULL) { + ret = BT_ERROR_OUT_OF_MEMORY; + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); + goto ERROR; + } + + strncpy(local_stack_version, info_start, info_size); + local_stack_version[info_size] = '\0'; + + info_start = info_end + 2; + info_size = lsize - info_size - 3; + + local_profiles = (char *)malloc(sizeof(char) * (info_size + 1)); + if (local_profiles == NULL) { + ret = BT_ERROR_OUT_OF_MEMORY; + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); + goto ERROR; + } + + strncpy(local_profiles, info_start, info_size); + local_profiles[info_size] = '\0'; + + if (buf) + free(buf); + fclose(fp); + + *chipset = local_chipset; + *firmware = local_firmware; + *stack_version = local_stack_version; + *profiles = local_profiles; + + return BT_ERROR_NONE; + +ERROR: + if (local_chipset) + free(local_chipset); + if (local_firmware) + free(local_firmware); + if (local_stack_version) + free(local_stack_version); + if (buf) + free(buf); + if (fp) + fclose(fp); + return ret; +} + int bt_adapter_get_name(char **name) { int ret = BT_ERROR_NONE; bluetooth_device_name_t loc_name = { {0} }; + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(name); ret = _bt_get_error_code(bluetooth_get_local_name(&loc_name)); if (ret != BT_ERROR_NONE) { - LOGE("[%s] %s(0x%08x)", __FUNCTION__, _bt_convert_error_to_string(ret), ret); + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); return ret; } *name = strdup(loc_name.name); if (*name == NULL) { - LOGE("[%s] OUT_OF_MEMORY(0x%08x)", __FUNCTION__, BT_ERROR_OUT_OF_MEMORY); + BT_ERR("OUT_OF_MEMORY(0x%08x)", BT_ERROR_OUT_OF_MEMORY); return BT_ERROR_OUT_OF_MEMORY; } @@ -116,6 +430,7 @@ int bt_adapter_set_name(const char *name) bluetooth_device_name_t loc_name = { {0} }; int ret = BT_ERROR_NONE; + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(name); @@ -124,27 +439,41 @@ int bt_adapter_set_name(const char *name) ret = _bt_get_error_code(bluetooth_set_local_name(&loc_name)); if (ret != BT_ERROR_NONE) { - LOGE("[%s] %s(0x%08x)", __FUNCTION__, _bt_convert_error_to_string(ret), ret); + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); } return ret; } -int bt_adapter_get_visibility(bt_adapter_visibility_mode_e *mode) +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_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(mode); ret = _bt_get_error_code(bluetooth_get_discoverable_mode(&discoverable_mode)); if (ret != BT_ERROR_NONE) { - LOGE("[%s] %s(0x%08x)", __FUNCTION__, _bt_convert_error_to_string(ret), ret); + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); return ret; } *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) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); + } + } + return BT_ERROR_NONE; } @@ -153,6 +482,7 @@ int bt_adapter_set_visibility(bt_adapter_visibility_mode_e visibility_mode, int bluetooth_discoverable_mode_t discoverable_mode = BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE; int error_code = BT_ERROR_NONE; + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); switch (visibility_mode) { case BT_ADAPTER_VISIBILITY_MODE_LIMITED_DISCOVERABLE: @@ -167,13 +497,71 @@ int bt_adapter_set_visibility(bt_adapter_visibility_mode_e visibility_mode, int timeout_sec = 0; break; default: - LOGE("[%s] INVALID_PARAMETER(0x%08x)", __FUNCTION__, BT_ERROR_INVALID_PARAMETER); + BT_ERR("INVALID_PARAMETER(0x%08x)", BT_ERROR_INVALID_PARAMETER); return BT_ERROR_INVALID_PARAMETER; } error_code = _bt_get_error_code(bluetooth_set_discoverable_mode(discoverable_mode, timeout_sec)); if (error_code != BT_ERROR_NONE) { - LOGE("[%s] %s(0x%08x)", __FUNCTION__, _bt_convert_error_to_string(error_code), error_code); + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error_code), error_code); + } + + return error_code; +} + +int bt_adapter_set_connectable_changed_cb(bt_adapter_connectable_changed_cb callback, void *user_data) +{ + int ret = BT_ERROR_NONE; + + BT_CHECK_BT_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(callback); + _bt_set_cb(BT_EVENT_CONNECTABLE_CHANGED_EVENT, callback, user_data); + if (ret != BT_ERROR_NONE) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); + } + + return ret; +} + +int bt_adapter_unset_connectable_changed_cb(void) +{ + BT_CHECK_BT_SUPPORT(); + BT_CHECK_INIT_STATUS(); + _bt_unset_cb(BT_EVENT_CONNECTABLE_CHANGED_EVENT); + return BT_ERROR_NONE; +} + +int bt_adapter_get_connectable(bool *connectable) +{ + gboolean is_connectable = FALSE; + int ret = BT_ERROR_NONE; + + BT_CHECK_BT_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(connectable); + + ret = _bt_get_error_code(bluetooth_is_connectable(&is_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; +} + +int bt_adapter_set_connectable(bool connectable) +{ + int error_code = BT_ERROR_NONE; + + BT_CHECK_BT_SUPPORT(); + BT_CHECK_INIT_STATUS(); + + error_code = _bt_get_error_code(bluetooth_set_connectable(connectable)); + if (error_code != BT_ERROR_NONE) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error_code), error_code); } return error_code; @@ -187,18 +575,19 @@ int bt_adapter_foreach_bonded_device(bt_adapter_bonded_device_cb foreach_cb, voi int ret = BT_ERROR_NONE; int i = 0; + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(foreach_cb); dev_list = g_ptr_array_new(); if (dev_list == NULL) { - LOGE("[%s] OUT_OF_MEMORY(0x%08x)", __FUNCTION__, BT_ERROR_OUT_OF_MEMORY); + BT_ERR("OUT_OF_MEMORY(0x%08x)", BT_ERROR_OUT_OF_MEMORY); return BT_ERROR_OUT_OF_MEMORY; } ret = _bt_get_error_code(bluetooth_get_bonded_device_list(&dev_list)); if (ret != BT_ERROR_NONE) { - LOGE("[%s] %s(0x%08x) : Failed to get bonded device list", __FUNCTION__, _bt_convert_error_to_string(ret), ret); + BT_ERR("%s(0x%08x) : Failed to get bonded device list", _bt_convert_error_to_string(ret), ret); return ret; } @@ -207,7 +596,7 @@ int bt_adapter_foreach_bonded_device(bt_adapter_bonded_device_cb foreach_cb, voi if (ptr != NULL) { ret = _bt_get_bt_device_info_s(&dev_info, (bluetooth_device_info_t *)ptr); if (ret != BT_ERROR_NONE) { - LOGE("[%s] %s(0x%08x) : Failed to get device info", __FUNCTION__, _bt_convert_error_to_string(ret), ret); + BT_ERR("%s(0x%08x) : Failed to get device info", _bt_convert_error_to_string(ret), ret); break; } @@ -217,15 +606,14 @@ int bt_adapter_foreach_bonded_device(bt_adapter_bonded_device_cb foreach_cb, voi } _bt_free_bt_device_info_s(dev_info); } else { - LOGE("[%s] OPERATION_FAILED(0x%08x)", __FUNCTION__, BT_ERROR_OPERATION_FAILED); + BT_ERR("OPERATION_FAILED(0x%08x)", BT_ERROR_OPERATION_FAILED); ret = BT_ERROR_OPERATION_FAILED; break; } } - if (dev_list != NULL) { - g_ptr_array_free(dev_list, TRUE); - } + g_ptr_array_foreach(dev_list, (GFunc)g_free, NULL); + g_ptr_array_free(dev_list, TRUE); return ret; } @@ -236,6 +624,7 @@ int bt_adapter_get_bonded_device_info(const char *remote_address, bt_device_info bluetooth_device_address_t addr_hex = { {0,} }; bluetooth_device_info_t *info; + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(remote_address); @@ -247,13 +636,12 @@ int bt_adapter_get_bonded_device_info(const char *remote_address, bt_device_info ret = _bt_get_error_code(bluetooth_get_bonded_device(&addr_hex, info)); if (ret != BT_ERROR_NONE) { - LOGE("[%s] %s(0x%08x) : Failed to run function", __FUNCTION__, + 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) { - LOGE("[%s] %s(0x%08x) : Failed to get device info", - __FUNCTION__, + BT_ERR("%s(0x%08x) : Failed to get device info", _bt_convert_error_to_string(ret), ret); } @@ -266,6 +654,7 @@ int bt_adapter_get_bonded_device_info(const char *remote_address, bt_device_info int bt_adapter_free_device_info(bt_device_info_s *device_info) { + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(device_info); @@ -277,7 +666,9 @@ int bt_adapter_free_device_info(bt_device_info_s *device_info) int bt_adapter_is_service_used(const char *service_uuid, bool *used) { int ret = BT_ERROR_NONE; + gboolean is_used = FALSE; + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(service_uuid); BT_CHECK_INPUT_PARAMETER(used); @@ -286,11 +677,12 @@ int bt_adapter_is_service_used(const char *service_uuid, bool *used) *used = bluetooth_obex_server_is_activated(); } else { ret = _bt_get_error_code(bluetooth_is_service_used(service_uuid, - (gboolean *)used)); + &is_used)); + *used = is_used ? true : false; } if (ret != BT_ERROR_NONE) { - LOGE("[%s] %s(0x%08x) : Failed to run function", __FUNCTION__, _bt_convert_error_to_string(ret), ret); + BT_ERR("%s(0x%08x) : Failed to run function", _bt_convert_error_to_string(ret), ret); } return ret; @@ -298,27 +690,41 @@ int bt_adapter_is_service_used(const char *service_uuid, bool *used) int bt_adapter_set_state_changed_cb(bt_adapter_state_changed_cb callback, void *user_data) { + BT_DBG(""); int ret = BT_ERROR_NONE; + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(callback); _bt_set_cb(BT_EVENT_STATE_CHANGED, callback, user_data); if (ret != BT_ERROR_NONE) { - LOGE("[%s] %s(0x%08x)", __FUNCTION__, _bt_convert_error_to_string(ret), ret); + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); } return ret; } +int bt_adapter_le_set_state_changed_cb(bt_adapter_le_state_changed_cb callback, void *user_data) +{ + BT_CHECK_BT_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(callback); + + _bt_le_adapter_init(); + _bt_set_cb(BT_EVENT_LE_STATE_CHANGED, callback, user_data); + return BT_ERROR_NONE; +} + int bt_adapter_set_name_changed_cb(bt_adapter_name_changed_cb callback, void *user_data) { int ret = BT_ERROR_NONE; + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(callback); _bt_set_cb(BT_EVENT_NAME_CHANGED, callback, user_data); if (ret != BT_ERROR_NONE) { - LOGE("[%s] %s(0x%08x)", __FUNCTION__, _bt_convert_error_to_string(ret), ret); + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); } return ret; @@ -328,11 +734,12 @@ int bt_adapter_set_visibility_mode_changed_cb(bt_adapter_visibility_mode_changed { int ret = BT_ERROR_NONE; + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(callback); _bt_set_cb(BT_EVENT_VISIBILITY_MODE_CHANGED, callback, user_data); if (ret != BT_ERROR_NONE) { - LOGE("[%s] %s(0x%08x)", __FUNCTION__, _bt_convert_error_to_string(ret), ret); + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); } return ret; @@ -342,25 +749,50 @@ int bt_adapter_set_device_discovery_state_changed_cb(bt_adapter_device_discovery { int ret = BT_ERROR_NONE; + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(callback); _bt_set_cb(BT_EVENT_DEVICE_DISCOVERY_STATE_CHANGED, callback, user_data); if (ret != BT_ERROR_NONE) { - LOGE("[%s] %s(0x%08x)", __FUNCTION__, _bt_convert_error_to_string(ret), ret); + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); } return ret; } +#ifndef TIZEN_WEARABLE +int bt_adapter_le_set_device_discovery_state_changed_cb(bt_adapter_le_device_discovery_state_changed_cb callback, void *user_data) +{ + BT_CHECK_LE_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(callback); + + _bt_le_adapter_init(); + _bt_set_cb(BT_EVENT_LE_DEVICE_DISCOVERY_STATE_CHANGED, callback, user_data); + return BT_ERROR_NONE; +} +#endif + int bt_adapter_unset_state_changed_cb(void) { + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); _bt_unset_cb(BT_EVENT_STATE_CHANGED); return BT_ERROR_NONE; } +int bt_adapter_le_unset_state_changed_cb(void) +{ + BT_CHECK_LE_SUPPORT(); + BT_CHECK_INIT_STATUS(); + _bt_unset_cb(BT_EVENT_LE_STATE_CHANGED); + _bt_le_adapter_deinit(); + return BT_ERROR_NONE; +} + int bt_adapter_unset_name_changed_cb(void) { + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); _bt_unset_cb(BT_EVENT_NAME_CHANGED); return BT_ERROR_NONE; @@ -368,26 +800,63 @@ int bt_adapter_unset_name_changed_cb(void) int bt_adapter_unset_visibility_mode_changed_cb(void) { + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); _bt_unset_cb(BT_EVENT_VISIBILITY_MODE_CHANGED); return BT_ERROR_NONE; } +int bt_adapter_set_visibility_duration_changed_cb(bt_adapter_visibility_duration_changed_cb callback, void *user_data) +{ + int ret = BT_ERROR_NONE; + + BT_CHECK_BT_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(callback); + _bt_set_cb(BT_EVENT_VISIBILITY_DURATION_CHANGED, callback, user_data); + if (ret != BT_ERROR_NONE) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); + } + + return ret; +} + +int bt_adapter_unset_visibility_duration_changed_cb(void) +{ + BT_CHECK_BT_SUPPORT(); + BT_CHECK_INIT_STATUS(); + _bt_unset_cb(BT_EVENT_VISIBILITY_DURATION_CHANGED); + return BT_ERROR_NONE; +} + int bt_adapter_unset_device_discovery_state_changed_cb(void) { + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); _bt_unset_cb(BT_EVENT_DEVICE_DISCOVERY_STATE_CHANGED); return BT_ERROR_NONE; } +#ifndef TIZEN_WEARABLE +int bt_adapter_le_unset_device_discovery_state_changed_cb(void) +{ + BT_CHECK_LE_SUPPORT(); + BT_CHECK_INIT_STATUS(); + _bt_unset_cb(BT_EVENT_LE_DEVICE_DISCOVERY_STATE_CHANGED); + _bt_le_adapter_deinit(); + return BT_ERROR_NONE; +} +#endif + int bt_adapter_start_device_discovery(void) { int error_code = BT_ERROR_NONE; + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); error_code = _bt_get_error_code(bluetooth_start_discovery(0, 0, BLUETOOTH_DEVICE_MAJOR_MASK_MISC)); if (error_code != BT_ERROR_NONE) { - LOGE("[%s] %s(0x%08x)", __FUNCTION__, _bt_convert_error_to_string(error_code), error_code); + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error_code), error_code); } return error_code; } @@ -396,10 +865,11 @@ int bt_adapter_stop_device_discovery(void) { int error_code = BT_ERROR_NONE; + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); error_code = _bt_get_error_code(bluetooth_cancel_discovery()); if (error_code != BT_ERROR_NONE) { - LOGE("[%s] %s(0x%08x)", __FUNCTION__, _bt_convert_error_to_string(error_code), error_code); + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error_code), error_code); } return error_code; } @@ -408,6 +878,7 @@ int bt_adapter_is_discovering(bool *is_discovering) { int ret = 0; + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(is_discovering); @@ -417,8 +888,2171 @@ int bt_adapter_is_discovering(bool *is_discovering) return BT_ERROR_NONE; } else { ret = _bt_get_error_code(ret); - LOGE("[%s] %s(0x%08x)", __FUNCTION__, _bt_convert_error_to_string(ret), ret); + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); + return ret; + } +} + +#ifndef TIZEN_WEARABLE +int bt_adapter_le_start_device_discovery(void) +{ + int error_code = BT_ERROR_NONE; + + BT_CHECK_LE_SUPPORT(); + BT_CHECK_INIT_STATUS(); + error_code = _bt_get_error_code(bluetooth_start_le_discovery()); + if (error_code != BT_ERROR_NONE) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error_code), error_code); + } + return error_code; +} + +int bt_adapter_le_stop_device_discovery(void) +{ + int error_code = BT_ERROR_NONE; + + BT_CHECK_LE_SUPPORT(); + BT_CHECK_INIT_STATUS(); + error_code = _bt_get_error_code(bluetooth_stop_le_discovery()); + if (error_code != BT_ERROR_NONE) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error_code), error_code); + } + return error_code; +} + +int bt_adapter_le_is_discovering(bool *is_discovering) +{ + int ret = 0; + + 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); + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); return ret; } } +#endif + +int bt_adapter_get_local_oob_data(unsigned char **hash, unsigned char **randomizer, + int *hash_len, int *randomizer_len) +{ + int ret = BT_ERROR_NONE; + + BT_CHECK_BT_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(hash); + BT_CHECK_INPUT_PARAMETER(randomizer); + BT_CHECK_INPUT_PARAMETER(hash_len); + BT_CHECK_INPUT_PARAMETER(randomizer_len); + + bt_oob_data_t oob_data; + + ret = _bt_get_error_code(bluetooth_oob_read_local_data(&oob_data)); + if (BT_ERROR_NONE == ret) { + *hash = g_memdup(oob_data.hash, BLUETOOTH_OOB_DATA_LENGTH); + *randomizer = g_memdup(oob_data.randomizer, + BLUETOOTH_OOB_DATA_LENGTH); + *hash_len = BLUETOOTH_OOB_DATA_LENGTH; + *randomizer_len = BLUETOOTH_OOB_DATA_LENGTH; + } else { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); + } + return ret; +} + +int bt_adapter_set_remote_oob_data(const char *remote_address, + unsigned char *hash, unsigned char *randomizer, + int hash_len, int randomizer_len) +{ + int ret = BT_ERROR_NONE; + bluetooth_device_address_t addr_hex = { {0,} }; + bt_oob_data_t oob_data = { {0},}; + + BT_CHECK_BT_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(remote_address); + + _bt_convert_address_to_hex(&addr_hex, remote_address); + + if (hash != NULL && randomizer != NULL) { + memcpy(oob_data.hash, hash, hash_len); + memcpy(oob_data.randomizer, randomizer, randomizer_len); + oob_data.hash_len = hash_len; + oob_data.randomizer_len = randomizer_len; + } + ret = _bt_get_error_code(bluetooth_oob_add_remote_data(&addr_hex, &oob_data)); + if (BT_ERROR_NONE != ret) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); + } + return ret; +} + +int bt_adapter_remove_remote_oob_data(const char *remote_address) +{ + int ret = BT_ERROR_NONE; + bluetooth_device_address_t addr_hex = { {0,} }; + + BT_CHECK_BT_SUPPORT(); + 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_oob_remove_remote_data(&addr_hex)); + if (BT_ERROR_NONE != ret) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); + } + return ret; +} + +int bt_adapter_set_manufacturer_data(char *data, int len) +{ + + int ret; + bluetooth_manufacturer_data_t m_data = { 0 }; + + BT_CHECK_BT_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(data); + + if (len + 2 > sizeof(m_data.data) || len < 0) + return BT_ERROR_INVALID_PARAMETER; + + m_data.data_len = len; + m_data.data[0] = len + 1; + m_data.data[1] = 0xFF; + + memcpy(&m_data.data[2], data, len); + + ret = _bt_get_error_code(bluetooth_set_manufacturer_data(&m_data)); + if (ret != BT_ERROR_NONE) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); + } + + return ret; +} + +int bt_adapter_set_manufacturer_data_changed_cb( + bt_adapter_manufacturer_data_changed_cb callback, + void *user_data) +{ + int ret = BT_ERROR_NONE; + + BT_CHECK_BT_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(callback); + _bt_set_cb(BT_EVENT_MANUFACTURER_DATA_CHANGED, + callback, user_data); + if (ret != BT_ERROR_NONE) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); + } + + return ret; +} + +int bt_adapter_unset_manufacturer_data_changed_cb(void) +{ + BT_CHECK_BT_SUPPORT(); + BT_CHECK_INIT_STATUS(); + _bt_unset_cb(BT_EVENT_MANUFACTURER_DATA_CHANGED); + return BT_ERROR_NONE; +} + +int bt_adapter_le_add_white_list(const char *address, bt_device_address_type_e address_type) +{ + int error_code = BT_ERROR_NONE; + bluetooth_device_address_t addr_hex = { {0,} }; + + BT_CHECK_LE_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(address); + _bt_convert_address_to_hex(&addr_hex, address); + + error_code = _bt_get_error_code(bluetooth_add_white_list(&addr_hex, address_type)); + if (error_code != BT_ERROR_NONE) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error_code), error_code); + } + + return error_code; +} + +int bt_adapter_le_remove_white_list(const char *address, bt_device_address_type_e address_type) +{ + int error_code = BT_ERROR_NONE; + bluetooth_device_address_t addr_hex = { {0,} }; + + BT_CHECK_BT_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(address); + _bt_convert_address_to_hex(&addr_hex, address); + + error_code = _bt_get_error_code(bluetooth_remove_white_list(&addr_hex, address_type)); + if (error_code != BT_ERROR_NONE) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error_code), error_code); + } + + return error_code; +} + +int bt_adapter_le_clear_white_list(void) +{ + int error_code = BT_ERROR_NONE; + + BT_CHECK_LE_SUPPORT(); + BT_CHECK_INIT_STATUS(); + + error_code = _bt_get_error_code(bluetooth_clear_white_list()); + if (error_code != BT_ERROR_NONE) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error_code), error_code); + } + + return error_code; +} + +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; + + BT_CHECK_LE_SUPPORT(); + BT_CHECK_INIT_STATUS(); + + scan_params.type = BT_ADAPTER_LE_ACTIVE_SCAN; + + if (scan_mode == BT_ADAPTER_LE_SCAN_MODE_BALANCED) { + scan_params.interval = 5000; + scan_params.window = 2000; + } else if (scan_mode == BT_ADAPTER_LE_SCAN_MODE_LOW_LATENCY) { + scan_params.interval = 5000; + scan_params.window = 5000; + } else if (scan_mode == BT_ADAPTER_LE_SCAN_MODE_LOW_ENERGY) { + scan_params.interval = 5000; + scan_params.window = 500; + } else + return BT_ERROR_INVALID_PARAMETER; + + ret = _bt_get_error_code(bluetooth_set_scan_parameters(&scan_params)); + if (ret != BT_ERROR_NONE) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); + } + return ret; +} + + +int bt_adapter_le_create_advertiser(bt_advertiser_h *advertiser) +{ + bt_advertiser_s *__adv = NULL; + + BT_CHECK_LE_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(advertiser); + + __adv = (bt_advertiser_s*)g_malloc0(sizeof(bt_advertiser_s)); + if (__adv == NULL) { + BT_ERR("OUT_OF_MEMORY(0x%08x)", BT_ERROR_OUT_OF_MEMORY); + return BT_ERROR_OUT_OF_MEMORY; + } + __adv->handle = (int)__adv; + + *advertiser = (bt_advertiser_h)__adv; + + advertiser_list = g_slist_append(advertiser_list, __adv); + + return BT_ERROR_NONE; +} + +int bt_adapter_le_destroy_advertiser(bt_advertiser_h advertiser) +{ + int ret = BT_ERROR_NONE; + int error_code; + bt_advertiser_s *__adv = (bt_advertiser_s *)advertiser; + + BT_CHECK_LE_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(advertiser); + + _bt_unset_cb(BT_EVENT_ADVERTISING_STATE_CHANGED); + + error_code = bluetooth_set_advertising(__adv->handle, FALSE); + ret = _bt_get_error_code(error_code); + if (ret != BT_ERROR_NONE) + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); + + advertiser_list = g_slist_remove(advertiser_list, __adv); + + /* Free advertising data */ + g_free(__adv->adv_data); + g_free(__adv->scan_rsp_data); + g_free(__adv); + + return BT_ERROR_NONE; +} + +static int __bt_remove_ad_data_by_type(char *in_data, unsigned int in_len, + char in_type, char **data, unsigned int *data_len) +{ + if (in_data == NULL || data == NULL || data_len == NULL) + return BT_ERROR_OPERATION_FAILED; + + int i; + int len = 0; + int type = 0; + char *p; + + for (i = 0; i < in_len; i++) { + len = in_data[i]; + if (len <= 0 || i + 1 >= in_len) { + BT_ERR("Invalid advertising data"); + return BT_ERROR_OPERATION_FAILED; + } + + type = in_data[i + 1]; + if (type == in_type) { + i = i + 2; + len--; + break; + } + + i += len; + len = 0; + } + + if (i + len > in_len) { + BT_ERR("Invalid advertising data"); + return BT_ERROR_OPERATION_FAILED; + } else if (len == 0 && + in_type != BT_ADAPTER_LE_ADVERTISING_DATA_LOCAL_NAME && + in_type != BT_ADAPTER_LE_ADVERTISING_DATA_TX_POWER_LEVEL) { + BT_INFO("AD Type 0x%02x data is not set", in_type); + return BT_ERROR_OPERATION_FAILED; + } + + p = (char *)malloc(sizeof(char) * (in_len - len)); + if (p == NULL) { + return BT_ERROR_OUT_OF_MEMORY; + } + + memcpy(p, in_data, sizeof(char) * i); + memcpy(p + i, in_data + i + len, sizeof(char) * (in_len - len - i)); + + *data = p; + *data_len = in_len - len; + + return BT_ERROR_NONE; +} + +int bt_adapter_le_add_advertising_data(bt_advertiser_h advertiser, + bt_adapter_le_packet_type_e pkt_type, bt_adapter_le_packet_data_type_e data_type, + void *data, unsigned int data_size) +{ + int ret = BT_ERROR_NONE; + bt_advertiser_s *__adv = (bt_advertiser_s *)advertiser; + char **p; + unsigned int *len; + unsigned int *system_data_len; + char *new_p; + bt_adapter_le_advertising_data_type_e adv_type; + + adv_type = (bt_adapter_le_advertising_data_type_e)data_type; + + BT_CHECK_LE_SUPPORT(); + BT_CHECK_INIT_STATUS(); + if ((data == NULL || data_size == 0) && + (adv_type != BT_ADAPTER_LE_ADVERTISING_DATA_LOCAL_NAME && + adv_type != BT_ADAPTER_LE_ADVERTISING_DATA_TX_POWER_LEVEL)) { + BT_ERR("empty data for packet type %d", pkt_type); + return BT_ERROR_INVALID_PARAMETER; + } + + BT_CHECK_INPUT_PARAMETER(advertiser); + + if (pkt_type == BT_ADAPTER_LE_PACKET_ADVERTISING) { + p = &__adv->adv_data; + len = &__adv->adv_data_len; + system_data_len = &__adv->adv_system_data_len; + } else if (pkt_type == BT_ADAPTER_LE_PACKET_SCAN_RESPONSE) { + p = &__adv->scan_rsp_data; + len = &__adv->scan_rsp_data_len; + system_data_len = &__adv->scan_rsp_system_data_len; + } else + return BT_ERROR_INVALID_PARAMETER; + + if (adv_type == BT_ADAPTER_LE_ADVERTISING_DATA_LOCAL_NAME || + adv_type == BT_ADAPTER_LE_ADVERTISING_DATA_TX_POWER_LEVEL) + *system_data_len += 1; + + /* 2 bytes are required for Length and AD Type */ + if (*len + *system_data_len + data_size + 2 > 31) { + BT_ERR("Quota exceeded.(0x%08x)", ret); + return BT_ERROR_QUOTA_EXCEEDED; + } + + if (*len == 0) + *p = NULL; + + new_p = realloc(*p, sizeof(char) * (*len + data_size + 2)); + if (new_p == NULL) { + return BT_ERROR_OUT_OF_MEMORY; + } + + new_p[*len] = data_size + 1; + new_p[*len + 1] = adv_type; + if ((data != NULL) && (data_size != 0)) + memcpy(new_p + (*len + 2), data, data_size); + + *p = new_p; + *len += data_size + 2; + return ret; +} + +int bt_adapter_le_remove_advertising_data(bt_advertiser_h advertiser, + bt_adapter_le_packet_type_e pkt_type, bt_adapter_le_packet_data_type_e data_type) +{ + int ret = BT_ERROR_NONE; + bt_advertiser_s *__adv = (bt_advertiser_s *)advertiser; + char **p; + unsigned int *len; + unsigned int *system_data_len; + char *new_p = NULL; + unsigned int new_len = 0; + bt_adapter_le_advertising_data_type_e adv_type; + + adv_type = (bt_adapter_le_advertising_data_type_e)data_type; + + BT_CHECK_LE_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(advertiser); + + switch (pkt_type) { + case BT_ADAPTER_LE_PACKET_ADVERTISING: + p = &__adv->adv_data; + len = &__adv->adv_data_len; + system_data_len = &__adv->adv_system_data_len; + break; + + case BT_ADAPTER_LE_PACKET_SCAN_RESPONSE: + p = &__adv->scan_rsp_data; + len = &__adv->scan_rsp_data_len; + system_data_len = &__adv->scan_rsp_system_data_len; + break; + + default: + BT_ERR("Unknown LE packet type : %d", pkt_type); + return BT_ERROR_INVALID_PARAMETER; + } + + ret = __bt_remove_ad_data_by_type(*p, *len, adv_type, &new_p, &new_len); + if (ret != BT_ERROR_NONE) { + return ret; + } + + free(*p); + *p = new_p; + *len = new_len; + + if (adv_type == BT_ADAPTER_LE_ADVERTISING_DATA_LOCAL_NAME || + adv_type == BT_ADAPTER_LE_ADVERTISING_DATA_TX_POWER_LEVEL) + *system_data_len -= 1; + + return ret; +} + +static int __bt_convert_string_to_uuid(const char *string, char **uuid, int *bit) +{ + char *data; + + if (strlen(string) == 4) { // 16 bit uuid + unsigned short val; + char *stop; + data = g_malloc0(sizeof(char) * 2); + val = strtol(string, &stop, 16); + val = htons(val); + memcpy(data, &val, 2); + *uuid = data; + *bit = 16; + } else if (strlen(string) == 36) { // 128 bit uuid + if (string[8] != '-' || string[13] != '-' || + string[18] != '-' || string[23] != '-') { + BT_ERR("Invalid UUID"); + return BT_ERROR_INVALID_PARAMETER; + } + + int ret; + unsigned int val0, val4; + unsigned short val1, val2, val3, val5; + data = g_malloc0(sizeof(char) * 16); + /* Fix : NULL_RETURNS */ + if (data == NULL) + return BT_ERROR_OUT_OF_MEMORY; + + ret = sscanf(string, "%08x-%04hx-%04hx-%04hx-%08x%04hx", + &val0, &val1, &val2, &val3, &val4, &val5); + if (ret != 6) + return BT_ERROR_OPERATION_FAILED; + + val0 = htonl(val0); + val1 = htons(val1); + val2 = htons(val2); + val3 = htons(val3); + val4 = htonl(val4); + val5 = htons(val5); + + memcpy(data, &val0, 4); + memcpy(data + 4, &val1, 2); + memcpy(data + 6, &val2, 2); + memcpy(data + 8, &val3, 2); + memcpy(data + 10, &val4, 4); + memcpy(data + 14, &val5, 2); + + *uuid = data; + *bit = 128; + } else { + BT_ERR("Invalid UUID"); + return BT_ERROR_INVALID_PARAMETER; + } + + return BT_ERROR_NONE; +} + +static int __bt_convert_byte_ordering(char *data, int data_len, char **converted_data) +{ + char *swp; + int i, j; + + /* Convert to little endian */ + swp = g_malloc0(data_len); + /* Fix : NULL_RETURNS */ + if (swp == NULL) + return BT_ERROR_OUT_OF_MEMORY; + for (i = 0, j = data_len - 1; i < data_len; i++, j--) + swp[i] = data[j]; + + *converted_data = swp; + + return BT_ERROR_NONE; +} + +static int __bt_find_adv_data_type(bt_advertiser_h advertiser, + bt_adapter_le_packet_type_e pkt_type, bt_adapter_le_advertising_data_type_e data_type, + char **data_ptr, int *data_len) +{ + int type; + int len; + int i; + char *adv_data = NULL; + int adv_len = 0; + bt_advertiser_s *__adv = (bt_advertiser_s *)advertiser; + + if (pkt_type == BT_ADAPTER_LE_PACKET_ADVERTISING) { + adv_data = __adv->adv_data; + adv_len = __adv->adv_data_len; + } else if (pkt_type == BT_ADAPTER_LE_PACKET_SCAN_RESPONSE) { + adv_data = __adv->scan_rsp_data; + adv_len = __adv->scan_rsp_data_len; + } else + return BT_ERROR_INVALID_PARAMETER; + + if (!adv_data) + return BT_ERROR_OPERATION_FAILED; + + for (i = 0; i adv_data; + adv_len = __adv->adv_data_len; + } else if (pkt_type == BT_ADAPTER_LE_PACKET_SCAN_RESPONSE) { + adv_data = __adv->scan_rsp_data; + adv_len = __adv->scan_rsp_data_len; + } else + return BT_ERROR_INVALID_PARAMETER; + + if (!adv_data) + return BT_ERROR_OPERATION_FAILED; + + dest_type = data_ptr[1]; + + if (data_type != dest_type) { + BT_ERR("Invalid data type"); + return BT_ERROR_INVALID_PARAMETER; + } + + new_adv = g_malloc0(adv_len + new_data_len); + if (!new_adv) + return BT_ERROR_OUT_OF_MEMORY; + + for (i = 0; i < adv_len; i++) { + len = adv_data[i]; + type = adv_data[i + 1]; + + if (type == dest_type) { + int rest_data_len; + + memcpy(new_adv + i, &adv_data[i], len + 1); + memcpy(new_adv + i + len + 1, new_data, new_data_len); + new_adv[i] += new_data_len; + + rest_data_len = adv_len - (i + len + 1); + if (rest_data_len > 0) + memcpy(new_adv + i + len + 1 + new_data_len, + &adv_data[i + len + 1], rest_data_len); + + break; + } else { + memcpy(new_adv + i, &adv_data[i], len + 1); + i = i + len; + } + } + + if (pkt_type == BT_ADAPTER_LE_PACKET_ADVERTISING) { + g_free(__adv->adv_data); + __adv->adv_data = new_adv; + __adv->adv_data_len += new_data_len; + } else if (pkt_type == BT_ADAPTER_LE_PACKET_SCAN_RESPONSE) { + g_free(__adv->scan_rsp_data); + __adv->scan_rsp_data = new_adv; + __adv->scan_rsp_data_len += new_data_len; + } + + return BT_ERROR_NONE; +} + +int bt_adapter_le_add_advertising_service_uuid(bt_advertiser_h advertiser, + bt_adapter_le_packet_type_e pkt_type, const char *uuid) +{ + int ret = BT_ERROR_NONE; + bt_adapter_le_advertising_data_type_e data_type = 0; + int byte_len = 0; + int uuid_bit = 0; + char *uuid_ptr = NULL; + char *data_ptr = NULL; + char *converted_uuid = NULL; + int data_len = 0; + + BT_CHECK_LE_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(advertiser); + BT_CHECK_INPUT_PARAMETER(uuid); + + ret = __bt_convert_string_to_uuid(uuid, &uuid_ptr, &uuid_bit); + if (ret != BT_ERROR_NONE) + return ret; + + if (uuid_bit == 16) { + byte_len = 2; + data_type = BT_ADAPTER_LE_ADVERTISING_DATA_INCOMP_LIST_16_BIT_SERVICE_CLASS_UUIDS; + } else if (uuid_bit == 128) { + byte_len = 16; + data_type = BT_ADAPTER_LE_ADVERTISING_DATA_INCOMP_LIST_128_BIT_SERVICE_CLASS_UUIDS; + } + + __bt_convert_byte_ordering(uuid_ptr, byte_len, &converted_uuid); + g_free(uuid_ptr); + + __bt_find_adv_data_type(advertiser, pkt_type, data_type, &data_ptr, &data_len); + if (data_ptr) { + ret = __bt_append_adv_type_data(advertiser, pkt_type, converted_uuid, byte_len, data_type, data_ptr, data_len); + } else { + ret = bt_adapter_le_add_advertising_data(advertiser, pkt_type, data_type, converted_uuid, byte_len); + } + g_free(converted_uuid); + + return ret; +} + +int bt_adapter_le_add_advertising_service_solicitation_uuid(bt_advertiser_h advertiser, + bt_adapter_le_packet_type_e pkt_type, const char *uuid) +{ + int ret = BT_ERROR_NONE; + bt_adapter_le_advertising_data_type_e data_type = 0; + int byte_len = 0; + int uuid_bit = 0; + char *uuid_ptr = NULL; + char *data_ptr = NULL; + char *converted_uuid = NULL; + int data_len = 0; + + BT_CHECK_LE_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(advertiser); + BT_CHECK_INPUT_PARAMETER(uuid); + + ret = __bt_convert_string_to_uuid(uuid, &uuid_ptr, &uuid_bit); + if (ret != BT_ERROR_NONE) + return ret; + + if (uuid_bit == 16) { + byte_len = 2; + data_type = BT_ADAPTER_LE_ADVERTISING_DATA_16_BIT_SERVICE_SOLICITATION_UUIDS; + } else if (uuid_bit == 128) { + byte_len = 16; + data_type = BT_ADAPTER_LE_ADVERTISING_DATA_128_BIT_SERVICE_SOLICITATION_UUIDS; + } + + __bt_convert_byte_ordering(uuid_ptr, byte_len, &converted_uuid); + g_free(uuid_ptr); + + __bt_find_adv_data_type(advertiser, pkt_type, data_type, &data_ptr, &data_len); + if (data_ptr) { + ret = __bt_append_adv_type_data(advertiser, pkt_type, converted_uuid, byte_len, data_type, data_ptr, data_len); + } else { + ret = bt_adapter_le_add_advertising_data(advertiser, pkt_type, data_type, converted_uuid, byte_len); + } + g_free(converted_uuid); + + return ret; +} + +int bt_adapter_le_add_advertising_service_data(bt_advertiser_h advertiser, + bt_adapter_le_packet_type_e pkt_type, const char *uuid, + const char *service_data, int service_data_len) +{ + int ret = BT_ERROR_NONE; + char *data_ptr = NULL; + int data_len; + char *adv_data = NULL; + int uuid_bit; + char *uuid_ptr; + int byte_len; + char *converted_uuid; + + BT_CHECK_LE_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(advertiser); + BT_CHECK_INPUT_PARAMETER(service_data); + + __bt_find_adv_data_type(advertiser, pkt_type, + BT_ADAPTER_LE_ADVERTISING_DATA_SERVICE_DATA, + &data_ptr, &data_len); + if (data_ptr) { + BT_ERR("Aleady existed"); + return BT_ERROR_ALREADY_DONE; + } + + ret = __bt_convert_string_to_uuid(uuid, &uuid_ptr, &uuid_bit); + if (ret != BT_ERROR_NONE) + return ret; + + if (uuid_bit == 16) { + byte_len = 2; + } else if (uuid_bit == 128) { + BT_ERR("128 bit UUID is not supported"); + g_free(uuid_ptr); + return BT_ERROR_INVALID_PARAMETER; + } + + __bt_convert_byte_ordering(uuid_ptr, byte_len, &converted_uuid); + g_free(uuid_ptr); + + adv_data = g_malloc0(sizeof(char) * (service_data_len + 2)); + if (!adv_data) { + g_free(converted_uuid); + return BT_ERROR_OUT_OF_MEMORY; + } + + memcpy(adv_data, converted_uuid, 2); + memcpy(adv_data + 2, service_data, service_data_len); + + ret = bt_adapter_le_add_advertising_data(advertiser, + pkt_type, BT_ADAPTER_LE_ADVERTISING_DATA_SERVICE_DATA, + adv_data, service_data_len + 2); + + g_free(adv_data); + g_free(converted_uuid); + + return ret; +} + +int bt_adapter_le_set_advertising_appearance(bt_advertiser_h advertiser, + bt_adapter_le_packet_type_e pkt_type, int appearance) +{ + int ret = BT_ERROR_NONE; + char *data_ptr = NULL; + int data_len; + + BT_CHECK_LE_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(advertiser); + + __bt_find_adv_data_type(advertiser, pkt_type, BT_ADAPTER_LE_ADVERTISING_DATA_APPEARANCE, + &data_ptr, &data_len); + if (data_ptr) { + BT_ERR("Aleady existed"); + return BT_ERROR_ALREADY_DONE; + } + + ret = bt_adapter_le_add_advertising_data(advertiser, + pkt_type, BT_ADAPTER_LE_ADVERTISING_DATA_APPEARANCE, &appearance, 2); + + return ret; +} + +int bt_adapter_le_add_advertising_manufacturer_data(bt_advertiser_h advertiser, + bt_adapter_le_packet_type_e pkt_type, int manufacturer_id, + const char *manufacturer_data, int manufacturer_data_len) +{ + int ret = BT_ERROR_NONE; + char *data_ptr = NULL; + int data_len; + char *adv_data = NULL; + + BT_CHECK_LE_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(advertiser); + BT_CHECK_INPUT_PARAMETER(manufacturer_data); + + __bt_find_adv_data_type(advertiser, pkt_type, + BT_ADAPTER_LE_ADVERTISING_DATA_MANUFACTURER_SPECIFIC_DATA, + &data_ptr, &data_len); + if (data_ptr) { + BT_ERR("Aleady existed"); + return BT_ERROR_ALREADY_DONE; + } + + adv_data = g_malloc0(sizeof(char) * (manufacturer_data_len + 2)); + if (!adv_data) + return BT_ERROR_OUT_OF_MEMORY; + + adv_data[0] = manufacturer_id & 0xffffffff; + adv_data[1] = (manufacturer_id & 0xff00) >> 8; + memcpy(adv_data + 2, manufacturer_data, manufacturer_data_len); + + ret = bt_adapter_le_add_advertising_data(advertiser, + pkt_type, BT_ADAPTER_LE_ADVERTISING_DATA_MANUFACTURER_SPECIFIC_DATA, + adv_data, manufacturer_data_len + 2); + + g_free(adv_data); + + return ret; +} + +int bt_adapter_le_set_advertising_device_name(bt_advertiser_h advertiser, + bt_adapter_le_packet_type_e pkt_type, bool include_name) +{ + int ret = BT_ERROR_NONE; + char *data_ptr = NULL; + int data_len; + + BT_CHECK_LE_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(advertiser); + + if (!include_name) { + ret = bt_adapter_le_remove_advertising_data(advertiser, pkt_type, + BT_ADAPTER_LE_ADVERTISING_DATA_LOCAL_NAME); + return ret; + } + + __bt_find_adv_data_type(advertiser, pkt_type, + BT_ADAPTER_LE_ADVERTISING_DATA_LOCAL_NAME, + &data_ptr, &data_len); + if (data_ptr) { + BT_ERR("Aleady existed"); + return BT_ERROR_ALREADY_DONE; + } + + ret = bt_adapter_le_add_advertising_data(advertiser, + pkt_type, BT_ADAPTER_LE_ADVERTISING_DATA_LOCAL_NAME, + NULL, 0); + + return ret; +} + +int bt_adapter_le_set_advertising_tx_power_level(bt_advertiser_h advertiser, + bt_adapter_le_packet_type_e pkt_type, bool include_tx_power) +{ + int ret = BT_ERROR_NONE; + char *data_ptr = NULL; + int data_len; + + BT_CHECK_LE_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(advertiser); + + if (!include_tx_power) { + ret = bt_adapter_le_remove_advertising_data(advertiser, pkt_type, + BT_ADAPTER_LE_ADVERTISING_DATA_TX_POWER_LEVEL); + return ret; + } + + __bt_find_adv_data_type(advertiser, pkt_type, + BT_ADAPTER_LE_ADVERTISING_DATA_TX_POWER_LEVEL, + &data_ptr, &data_len); + if (data_ptr) { + BT_ERR("Aleady existed"); + return BT_ERROR_ALREADY_DONE; + } + + ret = bt_adapter_le_add_advertising_data(advertiser, + pkt_type, BT_ADAPTER_LE_ADVERTISING_DATA_TX_POWER_LEVEL, + NULL, 0); + + return ret; +} + +int bt_adapter_le_clear_advertising_data(bt_advertiser_h advertiser, + bt_adapter_le_packet_type_e pkt_type) +{ + int ret = BT_ERROR_NONE; + bt_advertiser_s *__adv = (bt_advertiser_s *)advertiser; + char **p; + unsigned int *len; + unsigned int *system_data_len; + + BT_CHECK_LE_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(advertiser); + + switch (pkt_type) { + case BT_ADAPTER_LE_PACKET_ADVERTISING: + p = &__adv->adv_data; + len = &__adv->adv_data_len; + system_data_len = &__adv->adv_system_data_len; + break; + + case BT_ADAPTER_LE_PACKET_SCAN_RESPONSE: + p = &__adv->scan_rsp_data; + len = &__adv->scan_rsp_data_len; + system_data_len = &__adv->scan_rsp_system_data_len; + break; + + default: + BT_ERR("Unknown LE packet type : %d", pkt_type); + return BT_ERROR_INVALID_PARAMETER; + } + + if (*p) { + free(*p); + *p = NULL; + } + *len = 0; + *system_data_len = 0; + + return ret; +} + +#ifndef TIZEN_WEARABLE +int bt_adapter_le_start_advertising(bt_advertiser_h advertiser, + bt_adapter_le_advertising_params_s *adv_params, + 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; + + BT_CHECK_LE_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(advertiser); + + if (__adv->adv_data_len > 0 && __adv->adv_data) { + 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); + if (ret != BT_ERROR_NONE) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); + return ret; + } + } + + if (__adv->scan_rsp_data_len > 0 && __adv->scan_rsp_data) { + 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); + if (ret != BT_ERROR_NONE) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); + return ret; + } + } + + if (adv_params == NULL) { + error_code = bluetooth_set_advertising(__adv->handle, TRUE); + } else { + param.interval_min = adv_params->interval_min; + param.interval_max = adv_params->interval_max; + param.filter_policy = BT_ADAPTER_LE_ADVERTISING_FILTER_DEFAULT; + param.type = BT_ADAPTER_LE_ADVERTISING_CONNECTABLE; + error_code = bluetooth_set_custom_advertising(__adv->handle, TRUE, ¶m); + } + + ret = _bt_get_error_code(error_code); + if (ret != BT_ERROR_NONE) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); + return ret; + } + + _bt_set_cb(BT_EVENT_ADVERTISING_STATE_CHANGED, cb, user_data); + + return ret; +} +#endif + +int bt_adapter_le_stop_advertising(bt_advertiser_h advertiser) +{ + int ret = BT_ERROR_NONE; + bt_advertiser_s *__adv = (bt_advertiser_s *)advertiser; + + BT_CHECK_LE_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(advertiser); + + ret = _bt_get_error_code(bluetooth_set_advertising(__adv->handle, FALSE)); + if (ret != BT_ERROR_NONE) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); + } + + return ret; +} + +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; + + BT_CHECK_LE_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(advertiser); + + if (__adv->adv_data_len > 0 && __adv->adv_data) { + 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); + if (ret != BT_ERROR_NONE) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); + return ret; + } + } + + if (__adv->scan_rsp_data_len > 0 && __adv->scan_rsp_data) { + 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); + if (ret != BT_ERROR_NONE) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); + return ret; + } + } + + if (__adv->adv_params.mode == BT_ADAPTER_LE_ADVERTISING_MODE_BALANCED) + interval = 500; + else if (__adv->adv_params.mode == BT_ADAPTER_LE_ADVERTISING_MODE_LOW_LATENCY) + interval = 150; + 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, ¶m); + + ret = _bt_get_error_code(error_code); + if (ret != BT_ERROR_NONE) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); + return ret; + } + + __adv->cb = cb; + __adv->user_data = user_data; + + return ret; +} + +void _bt_adapter_le_invoke_advertising_state_cb(int handle, int result, bt_adapter_le_advertising_state_e adv_state) +{ + const GSList *l = NULL; + + for (l = advertiser_list; l; l = g_slist_next(l)) { + bt_advertiser_s *__adv = (bt_advertiser_s *)l->data; + if (__adv->handle == handle) { + if (__adv->cb == NULL) { + BT_ERR("advertiser cb is NULL"); + return; + } + + __adv->cb(result, (bt_advertiser_h)__adv, adv_state, __adv->user_data); + return; + } + } + + BT_ERR("No available advertiser"); +} + +int bt_adapter_le_set_advertising_mode(bt_advertiser_h advertiser, + bt_adapter_le_advertising_mode_e mode) +{ + int error_code = BT_ERROR_NONE; + bt_advertiser_s *__adv = (bt_advertiser_s *)advertiser; + + BT_CHECK_LE_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(advertiser); + + if (mode < BT_ADAPTER_LE_ADVERTISING_MODE_BALANCED || + 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); + return BT_ERROR_PERMISSION_DENIED; + } + + // TODO : Before set the mode, check the inprogress status + __adv->adv_params.mode = mode; + + return error_code; +} + +int bt_adapter_le_set_advertising_filter_policy(bt_advertiser_h advertiser, + bt_adapter_le_advertising_filter_policy_e filter_policy) +{ + int error_code = BT_ERROR_NONE; + bt_advertiser_s *__adv = (bt_advertiser_s *)advertiser; + + BT_CHECK_LE_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(advertiser); + + if (filter_policy < BT_ADAPTER_LE_ADVERTISING_FILTER_DEFAULT || + 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; + + return error_code; +} + +int bt_adapter_le_set_advertising_connectable(bt_advertiser_h advertiser, bool connectable) +{ + int error_code = BT_ERROR_NONE; + bt_advertiser_s *__adv = (bt_advertiser_s *)advertiser; + + BT_CHECK_LE_SUPPORT(); + 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); + return BT_ERROR_PERMISSION_DENIED; + } + + if (connectable) + __adv->adv_params.type = BT_ADAPTER_LE_ADVERTISING_CONNECTABLE; + else + __adv->adv_params.type = BT_ADAPTER_LE_ADVERTISING_SCANNABLE; + + // TODO : Before set the type, check the inprogress status + + return error_code; +} + +int bt_adapter_le_enable_privacy(bool enable_privacy) +{ + int error_code = BT_ERROR_NONE; + + BT_CHECK_LE_SUPPORT(); + BT_CHECK_INIT_STATUS(); + + error_code = _bt_get_error_code(bluetooth_enable_le_privacy(enable_privacy)); + + if (error_code != BT_ERROR_NONE) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error_code), error_code); + } + return error_code; +} + +static void __bt_adapter_le_convert_scan_filter(bluetooth_le_scan_filter_t *dest, bt_le_scan_filter_s *src) +{ + int bit; + char *data; + + memset(dest, 0x00, sizeof(bluetooth_le_scan_filter_t)); + + if (src->device_address) { + dest->added_features |= BLUETOOTH_LE_SCAN_FILTER_FEATURE_DEVICE_ADDRESS; + _bt_convert_address_to_hex(&dest->device_address, src->device_address); + } + + if (src->device_name) { + dest->added_features |= BLUETOOTH_LE_SCAN_FILTER_FEATURE_DEVICE_NAME; + strncpy(dest->device_name, src->device_name, BLUETOOTH_ADVERTISING_DATA_LENGTH_MAX); + dest->device_name[BLUETOOTH_ADVERTISING_DATA_LENGTH_MAX - 1] = '\0'; + } + + if (src->service_uuid) { + if (__bt_convert_string_to_uuid(src->service_uuid, &data, &bit) == BT_ERROR_NONE) { + dest->added_features |= BLUETOOTH_LE_SCAN_FILTER_FEATURE_SERVICE_UUID; + if (bit == 16) + dest->service_uuid.data_len = 2; + else + dest->service_uuid.data_len = 16; + memcpy(dest->service_uuid.data.data, data, dest->service_uuid.data_len); + g_free(data); + + dest->service_uuid_mask.data_len = dest->service_uuid.data_len; + if (src->service_uuid_mask) { + __bt_convert_string_to_uuid(src->service_uuid_mask, &data, &bit); + memcpy(dest->service_uuid_mask.data.data, data, dest->service_uuid_mask.data_len); + g_free(data); + } else { + memset(dest->service_uuid_mask.data.data, 0xFF, dest->service_uuid_mask.data_len); + } + } + } + + if (src->service_solicitation_uuid) { + if (__bt_convert_string_to_uuid(src->service_solicitation_uuid, &data, &bit) == BT_ERROR_NONE) { + dest->added_features |= BLUETOOTH_LE_SCAN_FILTER_FEATURE_SERVICE_SOLICITATION_UUID; + + if (bit == 16) + dest->service_solicitation_uuid.data_len = 2; + else + dest->service_solicitation_uuid.data_len = 16; + memcpy(dest->service_solicitation_uuid.data.data, data, dest->service_solicitation_uuid.data_len); + g_free(data); + + dest->service_solicitation_uuid_mask.data_len = dest->service_solicitation_uuid.data_len; + if (src->service_solicitation_uuid_mask) { + __bt_convert_string_to_uuid(src->service_solicitation_uuid_mask, &data, &bit); + memcpy(dest->service_solicitation_uuid_mask.data.data, data, dest->service_solicitation_uuid_mask.data_len); + g_free(data); + } else { + memset(dest->service_solicitation_uuid_mask.data.data, 0xFF, dest->service_solicitation_uuid_mask.data_len); + } + } + } + + if (src->service_data_uuid) { + char *service_uuid; + int uuid_len; + if (__bt_convert_string_to_uuid(src->service_data_uuid, &service_uuid, &bit) == BT_ERROR_NONE) { + dest->added_features |= BLUETOOTH_LE_SCAN_FILTER_FEATURE_SERVICE_DATA; + if (bit == 16) + uuid_len = 2; + else + uuid_len = 16; + + memcpy(dest->service_data.data.data, service_uuid, uuid_len); + g_free(service_uuid); + memcpy(dest->service_data.data.data + uuid_len, src->service_data, src->service_data_len); + dest->service_data.data_len = uuid_len + src->service_data_len; + + dest->service_data_mask.data_len = uuid_len + src->service_data_len; + memset(dest->service_data_mask.data.data, 0xFF, uuid_len); + if (src->service_data_mask) + memcpy(dest->service_data_mask.data.data + uuid_len, src->service_data_mask, src->service_data_len); + else + memset(dest->service_data_mask.data.data + uuid_len, 0xFF, src->service_data_len); + } + } + + if (src->manufacturer_id > -1) { + dest->added_features |= BLUETOOTH_LE_SCAN_FILTER_FEATURE_MANUFACTURER_DATA; + dest->manufacturer_id = src->manufacturer_id; + + if (src->manufacturer_data) { + memcpy(dest->manufacturer_data.data.data, src->manufacturer_data, src->manufacturer_data_len); + dest->manufacturer_data.data_len = src->manufacturer_data_len; + + dest->manufacturer_data_mask.data_len = src->manufacturer_data_len; + if (src->manufacturer_data_mask) + memcpy(dest->manufacturer_data_mask.data.data, src->manufacturer_data_mask, src->manufacturer_data_len); + else + memset(dest->manufacturer_data_mask.data.data, 0xFF, src->manufacturer_data_len); + } + } +} + +int bt_adapter_le_start_scan(bt_adapter_le_scan_result_cb cb, void *user_data) +{ + int error_code = BT_ERROR_NONE; + + BT_CHECK_LE_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(cb); + + _bt_le_adapter_init(); + _bt_set_cb(BT_EVENT_LE_SCAN_RESULT_UPDATED, cb, user_data); + + error_code = _bt_get_error_code(bluetooth_start_le_discovery()); + if (error_code != BT_ERROR_NONE) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error_code), error_code); + } + return error_code; +} + +int bt_adapter_le_stop_scan(void) +{ + int error_code = BT_ERROR_NONE; + + BT_CHECK_LE_SUPPORT(); + BT_CHECK_INIT_STATUS(); + error_code = _bt_get_error_code(bluetooth_stop_le_discovery()); + if (error_code != BT_ERROR_NONE) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error_code), error_code); + } + return error_code; +} + +int bt_adapter_le_get_scan_result_service_uuids(const bt_adapter_le_device_scan_result_info_s *info, + bt_adapter_le_packet_type_e pkt_type, char ***uuids, int *count) +{ + BT_CHECK_LE_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(info); + BT_CHECK_INPUT_PARAMETER(uuids); + BT_CHECK_INPUT_PARAMETER(count); + + int adv_length = 0; + char *adv_data = NULL; + char *remain_data = NULL; + int remain_len = 0; + int field_len = 0; + int uuid_size = 0; + int uuid_count = 0; + int uuid_index = 0; + int i; + + if (pkt_type == BT_ADAPTER_LE_PACKET_ADVERTISING) { + adv_data = info->adv_data; + adv_length = info->adv_data_len; + } else if (pkt_type == BT_ADAPTER_LE_PACKET_SCAN_RESPONSE) { + adv_data = info->scan_data; + adv_length = info->scan_data_len; + } else + return BT_ERROR_INVALID_PARAMETER; + + if (!adv_data || adv_length < 3) + return BT_ERROR_NO_DATA; + + remain_data = adv_data; + remain_len = adv_length; + field_len = 0; + while (remain_len > 0) { + field_len = remain_data[0]; + if (remain_data[1] == BT_ADAPTER_LE_ADVERTISING_DATA_INCOMP_LIST_16_BIT_SERVICE_CLASS_UUIDS || + remain_data[1] == BT_ADAPTER_LE_ADVERTISING_DATA_COMP_LIST_16_BIT_SERVICE_CLASS_UUIDS) + uuid_count += (field_len - 1) / 2; + else if (remain_data[1] == BT_ADAPTER_LE_ADVERTISING_DATA_INCOMP_LIST_128_BIT_SERVICE_CLASS_UUIDS || + remain_data[1] == BT_ADAPTER_LE_ADVERTISING_DATA_COMP_LIST_128_BIT_SERVICE_CLASS_UUIDS) + uuid_count += (field_len - 1) / 16; + + remain_len = remain_len - field_len - 1; + remain_data += field_len + 1; + } + + if (uuid_count == 0) + return BT_ERROR_NO_DATA; + + *uuids = g_malloc0(sizeof(char*) * uuid_count); + /* Fix : NULL_RETURNS */ + if (*uuids == NULL) + return BT_ERROR_OUT_OF_MEMORY; + + *count = uuid_count; + + remain_data = adv_data; + remain_len = adv_length; + field_len = 0; + while (remain_len) { + field_len = remain_data[0]; + if (remain_data[1] == BT_ADAPTER_LE_ADVERTISING_DATA_INCOMP_LIST_16_BIT_SERVICE_CLASS_UUIDS || + remain_data[1] == BT_ADAPTER_LE_ADVERTISING_DATA_COMP_LIST_16_BIT_SERVICE_CLASS_UUIDS) + uuid_size = 2; + else if (remain_data[1] == BT_ADAPTER_LE_ADVERTISING_DATA_INCOMP_LIST_128_BIT_SERVICE_CLASS_UUIDS || + remain_data[1] == BT_ADAPTER_LE_ADVERTISING_DATA_COMP_LIST_128_BIT_SERVICE_CLASS_UUIDS) + uuid_size = 16; + else + uuid_size = 0; + + if (uuid_size != 0) { + for (i = 0; i < (field_len - 1); i += uuid_size) { + if (uuid_size == 2) { + (*uuids)[uuid_index] = g_malloc0(sizeof(char) * 4 + 1); + /* Fix : NULL_RETURNS */ + if ((*uuids)[uuid_index] == NULL) + return BT_ERROR_OUT_OF_MEMORY; + snprintf((*uuids)[uuid_index], 5, "%2.2X%2.2X", remain_data[i+3], remain_data[i+2]); + } else { + (*uuids)[uuid_index] = g_malloc0(sizeof(char) * 36 + 1); + /* Fix : NULL_RETURNS */ + if ((*uuids)[uuid_index] == NULL) + return BT_ERROR_OUT_OF_MEMORY; + snprintf((*uuids)[uuid_index], 37, "%2.2X%2.2X%2.2X%2.2X-%2.2X%2.2X-%2.2X%2.2X-%2.2X%2.2X-%2.2X%2.2X%2.2X%2.2X%2.2X%2.2X", + remain_data[i+17], remain_data[i+16], remain_data[i+15], remain_data[i+14], + remain_data[i+13], remain_data[i+12], remain_data[i+11], remain_data[i+10], remain_data[i+9], remain_data[i+8], + remain_data[i+7], remain_data[i+6], remain_data[i+5], remain_data[i+4], remain_data[i+3], remain_data[i+2]); + } + uuid_index++; + } + } + + remain_len = remain_len - field_len - 1; + remain_data += field_len + 1; + } + + return BT_ERROR_NONE; +} + +int bt_adapter_le_get_scan_result_device_name(const bt_adapter_le_device_scan_result_info_s *info, + bt_adapter_le_packet_type_e pkt_type, char **name) +{ + BT_CHECK_LE_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(info); + BT_CHECK_INPUT_PARAMETER(name); + + int adv_length = 0; + char *adv_data = NULL; + int field_len = 0; + + if (pkt_type == BT_ADAPTER_LE_PACKET_ADVERTISING) { + adv_data = info->adv_data; + adv_length = info->adv_data_len; + } else if (pkt_type == BT_ADAPTER_LE_PACKET_SCAN_RESPONSE) { + adv_data = info->scan_data; + adv_length = info->scan_data_len; + } else + return BT_ERROR_INVALID_PARAMETER; + + if (!adv_data || adv_length < 3) + return BT_ERROR_NO_DATA; + + while (adv_length > 0) { + field_len = adv_data[0]; + if (adv_data[1] == BT_ADAPTER_LE_ADVERTISING_DATA_LOCAL_NAME) { + *name = g_malloc0(sizeof(char) * field_len); + /* Fix : NULL_RETURNS */ + if (*name == NULL) + return BT_ERROR_OUT_OF_MEMORY; + memcpy(*name, &adv_data[2], field_len - 1); + + return BT_ERROR_NONE; + } + + adv_length = adv_length - field_len - 1; + adv_data += field_len + 1; + } + + return BT_ERROR_NO_DATA; +} + +int bt_adapter_le_get_scan_result_tx_power_level(const bt_adapter_le_device_scan_result_info_s *info, + bt_adapter_le_packet_type_e pkt_type, int *power_level) +{ + BT_CHECK_LE_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(info); + BT_CHECK_INPUT_PARAMETER(power_level); + + int adv_length = 0; + char *adv_data = NULL; + int field_len = 0; + + if (pkt_type == BT_ADAPTER_LE_PACKET_ADVERTISING) { + adv_data = info->adv_data; + adv_length = info->adv_data_len; + } else if (pkt_type == BT_ADAPTER_LE_PACKET_SCAN_RESPONSE) { + adv_data = info->scan_data; + adv_length = info->scan_data_len; + } else + return BT_ERROR_INVALID_PARAMETER; + + if (!adv_data || adv_length < 3) + return BT_ERROR_NO_DATA; + + while (adv_length > 0) { + field_len = adv_data[0]; + if (adv_data[1] == BT_ADAPTER_LE_ADVERTISING_DATA_TX_POWER_LEVEL) { + *power_level = (int)adv_data[2]; + + return BT_ERROR_NONE; + } + + adv_length = adv_length - field_len - 1; + adv_data += field_len + 1; + } + + return BT_ERROR_NO_DATA; +} + +int bt_adapter_le_get_scan_result_service_solicitation_uuids(const bt_adapter_le_device_scan_result_info_s *info, + bt_adapter_le_packet_type_e pkt_type, char ***uuids, int *count) +{ + BT_CHECK_LE_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(info); + BT_CHECK_INPUT_PARAMETER(uuids); + BT_CHECK_INPUT_PARAMETER(count); + + int adv_length = 0; + char *adv_data = NULL; + char *remain_data = NULL; + int remain_len = 0; + int field_len = 0; + int uuid_size = 0; + int uuid_count = 0; + int uuid_index = 0; + int i; + + if (pkt_type == BT_ADAPTER_LE_PACKET_ADVERTISING) { + adv_data = info->adv_data; + adv_length = info->adv_data_len; + } else if (pkt_type == BT_ADAPTER_LE_PACKET_SCAN_RESPONSE) { + adv_data = info->scan_data; + adv_length = info->scan_data_len; + } else + return BT_ERROR_INVALID_PARAMETER; + + if (!adv_data || adv_length < 3) + return BT_ERROR_NO_DATA; + + remain_data = adv_data; + remain_len = adv_length; + field_len = 0; + while (remain_len > 0) { + field_len = remain_data[0]; + if (remain_data[1] == BT_ADAPTER_LE_ADVERTISING_DATA_16_BIT_SERVICE_SOLICITATION_UUIDS) + uuid_count += (field_len - 1) / 2; + else if (remain_data[1] == BT_ADAPTER_LE_ADVERTISING_DATA_128_BIT_SERVICE_SOLICITATION_UUIDS) + uuid_count += (field_len - 1) / 16; + + remain_len = remain_len - field_len - 1; + remain_data += field_len + 1; + } + + if (uuid_count == 0) + return BT_ERROR_NO_DATA; + + *uuids = g_malloc0(sizeof(char*) * uuid_count); + /* Fix : NULL_RETURNS */ + if (*uuids == NULL) + return BT_ERROR_OUT_OF_MEMORY; + *count = uuid_count; + + remain_data = adv_data; + remain_len = adv_length; + field_len = 0; + while (remain_len > 0) { + field_len = remain_data[0]; + if (remain_data[1] == BT_ADAPTER_LE_ADVERTISING_DATA_16_BIT_SERVICE_SOLICITATION_UUIDS) + uuid_size = 2; + else if (remain_data[1] == BT_ADAPTER_LE_ADVERTISING_DATA_128_BIT_SERVICE_SOLICITATION_UUIDS) + uuid_size = 16; + else + uuid_size = 0; + + if (uuid_size != 0) { + for (i = 0; i < (field_len - 1); i += uuid_size) { + if (uuid_size == 2) { + (*uuids)[uuid_index] = g_malloc0(sizeof(char) * 4 + 1); + /* Fix : NULL_RETURNS */ + if ((*uuids)[uuid_index] == NULL) + return BT_ERROR_OUT_OF_MEMORY; + snprintf((*uuids)[uuid_index], 5, "%2.2X%2.2X", remain_data[i+3], remain_data[i+2]); + } else { + (*uuids)[uuid_index] = g_malloc0(sizeof(char) * 36 + 1); + /* Fix : NULL_RETURNS */ + if ((*uuids)[uuid_index] == NULL) + return BT_ERROR_OUT_OF_MEMORY; + snprintf((*uuids)[uuid_index], 37, "%2.2X%2.2X%2.2X%2.2X-%2.2X%2.2X-%2.2X%2.2X-%2.2X%2.2X-%2.2X%2.2X%2.2X%2.2X%2.2X%2.2X", + remain_data[i+17], remain_data[i+16], remain_data[i+15], remain_data[i+14], + remain_data[i+13], remain_data[i+12], remain_data[i+11], remain_data[i+10], remain_data[i+9], remain_data[i+8], + remain_data[i+7], remain_data[i+6], remain_data[i+5], remain_data[i+4], remain_data[i+3], remain_data[i+2]); + } + uuid_index++; + } + } + + remain_len = remain_len - field_len - 1; + remain_data += field_len + 1; + } + + return BT_ERROR_NONE; +} + +int bt_adapter_le_get_scan_result_service_data_list(const bt_adapter_le_device_scan_result_info_s *info, + bt_adapter_le_packet_type_e pkt_type, bt_adapter_le_service_data_s **data_list, int *count) +{ + BT_CHECK_LE_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(info); + BT_CHECK_INPUT_PARAMETER(count); + + int adv_length = 0; + char *adv_data = NULL; + char *remain_data = NULL; + int remain_len = 0; + int field_len = 0; + int data_count = 0; + int data_index = 0; + + if (pkt_type == BT_ADAPTER_LE_PACKET_ADVERTISING) { + adv_data = info->adv_data; + adv_length = info->adv_data_len; + } else if (pkt_type == BT_ADAPTER_LE_PACKET_SCAN_RESPONSE) { + adv_data = info->scan_data; + adv_length = info->scan_data_len; + } else + return BT_ERROR_INVALID_PARAMETER; + + if (!adv_data || adv_length < 3) + return BT_ERROR_NO_DATA; + + remain_data = adv_data; + remain_len = adv_length; + field_len = 0; + while (remain_len > 0) { + field_len = remain_data[0]; + if (remain_data[1] == BT_ADAPTER_LE_ADVERTISING_DATA_SERVICE_DATA) + data_count++; + + remain_len = remain_len - field_len - 1; + remain_data += field_len + 1; + } + + if (data_count == 0) + return BT_ERROR_NO_DATA; + + *data_list = g_malloc0(sizeof(bt_adapter_le_service_data_s) * data_count); + /* Fix : NULL_RETURNS */ + if (*data_list == NULL) + return BT_ERROR_OUT_OF_MEMORY; + *count = data_count; + + remain_data = adv_data; + remain_len = adv_length; + field_len = 0; + while (remain_len > 0) { + field_len = remain_data[0]; + if (remain_data[1] == BT_ADAPTER_LE_ADVERTISING_DATA_SERVICE_DATA) { + (*data_list)[data_index].service_uuid = g_malloc0(sizeof(char) * 4 + 1); + snprintf((*data_list)[data_index].service_uuid, 5, "%2.2X%2.2X", remain_data[3], remain_data[2]); + + (*data_list)[data_index].service_data = g_memdup(&remain_data[4], field_len - 3); + (*data_list)[data_index].service_data_len = field_len - 3; + + data_index++; + } + + remain_len = remain_len - field_len - 1; + remain_data += field_len + 1; + } + + return BT_ERROR_NONE; +} + +int bt_adapter_le_free_service_data_list(bt_adapter_le_service_data_s *data_list, int count) +{ + int i; + + BT_CHECK_LE_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(data_list); + + for (i = 0; i < count; i++) { + g_free(data_list[i].service_uuid); + g_free(data_list[i].service_data); + } + g_free(data_list); + + return BT_ERROR_NONE; +} + +int bt_adapter_le_get_scan_result_appearance(const bt_adapter_le_device_scan_result_info_s *info, + bt_adapter_le_packet_type_e pkt_type, int *appearance) +{ + BT_CHECK_LE_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(info); + BT_CHECK_INPUT_PARAMETER(appearance); + + int adv_length = 0; + char *adv_data = NULL; + int field_len = 0; + + if (pkt_type == BT_ADAPTER_LE_PACKET_ADVERTISING) { + adv_data = info->adv_data; + adv_length = info->adv_data_len; + } else if (pkt_type == BT_ADAPTER_LE_PACKET_SCAN_RESPONSE) { + adv_data = info->scan_data; + adv_length = info->scan_data_len; + } else + return BT_ERROR_INVALID_PARAMETER; + + if (!adv_data || adv_length < 3) + return BT_ERROR_NO_DATA; + + while (adv_length > 0) { + field_len = adv_data[0]; + if (adv_data[1] == BT_ADAPTER_LE_ADVERTISING_DATA_APPEARANCE) { + *appearance = (int)adv_data[2]; + *appearance |= (int)adv_data[3] << 8; + + return BT_ERROR_NONE; + } + + adv_length = adv_length - field_len - 1; + adv_data += field_len + 1; + } + + return BT_ERROR_NO_DATA; +} + + +int bt_adapter_le_get_scan_result_manufacturer_data(const bt_adapter_le_device_scan_result_info_s *info, + bt_adapter_le_packet_type_e pkt_type, int *manufacturer_id, char **manufacturer_data, int *manufacturer_data_len) +{ + BT_CHECK_LE_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(info); + BT_CHECK_INPUT_PARAMETER(manufacturer_id); + BT_CHECK_INPUT_PARAMETER(manufacturer_data); + BT_CHECK_INPUT_PARAMETER(manufacturer_data_len); + + int adv_length = 0; + char *adv_data = NULL; + char *remain_data = NULL; + int remain_len = 0; + int field_len = 0; + + if (pkt_type == BT_ADAPTER_LE_PACKET_ADVERTISING) { + adv_data = info->adv_data; + adv_length = info->adv_data_len; + } else if (pkt_type == BT_ADAPTER_LE_PACKET_SCAN_RESPONSE) { + adv_data = info->scan_data; + adv_length = info->scan_data_len; + } else + return BT_ERROR_INVALID_PARAMETER; + + if (!adv_data || adv_length < 3) + return BT_ERROR_NO_DATA; + + remain_data = adv_data; + remain_len = adv_length; + field_len = 0; + while (remain_len > 0) { + field_len = remain_data[0]; + if (remain_data[1] == BT_ADAPTER_LE_ADVERTISING_DATA_MANUFACTURER_SPECIFIC_DATA) { + *manufacturer_id = remain_data[3] << 8; + *manufacturer_id += remain_data[2]; + + *manufacturer_data = g_memdup(&adv_data[4], field_len - 3); + *manufacturer_data_len = field_len - 3; + + return BT_ERROR_NONE; + } + + remain_len = remain_len - field_len - 1; + remain_data += field_len + 1; + } + + return BT_ERROR_NO_DATA; +} + +int bt_adapter_le_create_scan_filter(bt_scan_filter_h *scan_filter) +{ + bt_le_scan_filter_s *__filter = NULL; + + BT_CHECK_LE_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(scan_filter); + + __filter = (bt_le_scan_filter_s*)g_malloc0(sizeof(bt_le_scan_filter_s)); + if (__filter == NULL) { + BT_ERR("OUT_OF_MEMORY(0x%08x)", BT_ERROR_OUT_OF_MEMORY); + return BT_ERROR_OUT_OF_MEMORY; + } + + __filter->manufacturer_id = -1; + *scan_filter = (bt_scan_filter_h)__filter; + + return BT_ERROR_NONE; +} + +int bt_adapter_le_destroy_scan_filter(bt_scan_filter_h scan_filter) +{ + bt_le_scan_filter_s *__filter = (bt_le_scan_filter_s *)scan_filter; + + BT_CHECK_LE_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(scan_filter); + + g_free(__filter->device_address); + g_free(__filter->device_name); + g_free(__filter->service_uuid); + g_free(__filter->service_uuid_mask); + g_free(__filter->service_solicitation_uuid); + g_free(__filter->service_solicitation_uuid_mask); + g_free(__filter->service_data_uuid); + g_free(__filter->service_data); + g_free(__filter->service_data_mask); + g_free(__filter->manufacturer_data); + g_free(__filter->manufacturer_data_mask); + g_free(__filter); + + return BT_ERROR_NONE; +} + +int bt_adapter_le_scan_filter_set_device_address(bt_scan_filter_h scan_filter, const char *address) +{ + bt_le_scan_filter_s *__filter = (bt_le_scan_filter_s *)scan_filter; + + BT_CHECK_LE_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(scan_filter); + BT_CHECK_INPUT_PARAMETER(address); + + g_free(__filter->device_address); + + __filter->device_address = strdup(address); + + return BT_ERROR_NONE; +} + +int bt_adapter_le_scan_filter_set_device_name(bt_scan_filter_h scan_filter, const char *name) +{ + bt_le_scan_filter_s *__filter = (bt_le_scan_filter_s *)scan_filter; + + BT_CHECK_LE_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(scan_filter); + BT_CHECK_INPUT_PARAMETER(name); + + if (strlen(name) > 29) { + BT_ERR("INVALID_PARAMETER(0x%08x)", BT_ERROR_INVALID_PARAMETER); + return BT_ERROR_INVALID_PARAMETER; + } + + g_free(__filter->device_name); + + __filter->device_name = strdup(name); + + return BT_ERROR_NONE; +} + +int bt_adapter_le_scan_filter_set_service_uuid(bt_scan_filter_h scan_filter, const char *uuid) +{ + bt_le_scan_filter_s *__filter = (bt_le_scan_filter_s *)scan_filter; + + BT_CHECK_LE_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(scan_filter); + BT_CHECK_INPUT_PARAMETER(uuid); + + g_free(__filter->service_uuid); + g_free(__filter->service_uuid_mask); + + __filter->service_uuid = strdup(uuid); + __filter->service_uuid_mask = NULL; + + return BT_ERROR_NONE; +} + +int bt_adapter_le_scan_filter_set_service_uuid_with_mask(bt_scan_filter_h scan_filter, + const char *uuid, const char *mask) +{ + bt_le_scan_filter_s *__filter = (bt_le_scan_filter_s *)scan_filter; + + BT_CHECK_LE_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(scan_filter); + BT_CHECK_INPUT_PARAMETER(uuid); + BT_CHECK_INPUT_PARAMETER(mask); + + if (strlen(uuid) != strlen(mask)) { + BT_ERR("INVALID_PARAMETER(0x%08x)", BT_ERROR_INVALID_PARAMETER); + return BT_ERROR_INVALID_PARAMETER; + } + + g_free(__filter->service_uuid); + g_free(__filter->service_uuid_mask); + + __filter->service_uuid = strdup(uuid); + __filter->service_uuid_mask = strdup(mask); + + return BT_ERROR_NONE; +} + +int bt_adapter_le_scan_filter_set_service_solicitation_uuid(bt_scan_filter_h scan_filter, const char *uuid) +{ + bt_le_scan_filter_s *__filter = (bt_le_scan_filter_s *)scan_filter; + + BT_CHECK_LE_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(scan_filter); + BT_CHECK_INPUT_PARAMETER(uuid); + + g_free(__filter->service_solicitation_uuid); + g_free(__filter->service_solicitation_uuid_mask); + + __filter->service_solicitation_uuid = strdup(uuid); + __filter->service_solicitation_uuid_mask = NULL; + + return BT_ERROR_NONE; +} + +int bt_adapter_le_scan_filter_set_service_solicitation_uuid_with_mask(bt_scan_filter_h scan_filter, + const char *uuid, const char *mask) +{ + bt_le_scan_filter_s *__filter = (bt_le_scan_filter_s *)scan_filter; + + BT_CHECK_LE_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(scan_filter); + BT_CHECK_INPUT_PARAMETER(uuid); + BT_CHECK_INPUT_PARAMETER(mask); + + if (strlen(uuid) != strlen(mask)) { + BT_ERR("INVALID_PARAMETER(0x%08x)", BT_ERROR_INVALID_PARAMETER); + return BT_ERROR_INVALID_PARAMETER; + } + + g_free(__filter->service_solicitation_uuid); + g_free(__filter->service_solicitation_uuid_mask); + + __filter->service_solicitation_uuid = strdup(uuid); + __filter->service_solicitation_uuid_mask = strdup(mask); + + return BT_ERROR_NONE; +} + +int bt_adapter_le_scan_filter_set_service_data(bt_scan_filter_h scan_filter, + const char *uuid, const char *data, unsigned int data_len) +{ + bt_le_scan_filter_s *__filter = (bt_le_scan_filter_s *)scan_filter; + + BT_CHECK_LE_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(scan_filter); + BT_CHECK_INPUT_PARAMETER(uuid); + BT_CHECK_INPUT_PARAMETER(data); + + if (data_len > 27) { + BT_ERR("INVALID_PARAMETER(0x%08x)", BT_ERROR_INVALID_PARAMETER); + return BT_ERROR_INVALID_PARAMETER; + } + + g_free(__filter->service_data_uuid); + g_free(__filter->service_data); + g_free(__filter->service_data_mask); + + __filter->service_data_uuid = strdup(uuid); + __filter->service_data = g_memdup(data, data_len); + __filter->service_data_len = data_len; + __filter->service_data_mask = NULL; + + return BT_ERROR_NONE; +} + +int bt_adapter_le_scan_filter_set_service_data_with_mask(bt_scan_filter_h scan_filter, + const char *uuid, const char *data, unsigned int data_len, const char *mask, unsigned int mask_len) +{ + bt_le_scan_filter_s *__filter = (bt_le_scan_filter_s *)scan_filter; + + BT_CHECK_LE_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(scan_filter); + BT_CHECK_INPUT_PARAMETER(uuid); + BT_CHECK_INPUT_PARAMETER(data); + BT_CHECK_INPUT_PARAMETER(mask); + + if (data_len != mask_len || data_len > 27) { + BT_ERR("INVALID_PARAMETER(0x%08x)", BT_ERROR_INVALID_PARAMETER); + return BT_ERROR_INVALID_PARAMETER; + } + + g_free(__filter->service_data_uuid); + g_free(__filter->service_data); + g_free(__filter->service_data_mask); + + __filter->service_data_uuid = strdup(uuid); + __filter->service_data = g_memdup(data, data_len); + __filter->service_data_len = data_len; + __filter->service_data_mask = g_memdup(mask, data_len); + + return BT_ERROR_NONE; +} + +int bt_adapter_le_scan_filter_set_manufacturer_data(bt_scan_filter_h scan_filter, + int manufacturer_id, const char *data, unsigned int data_len) +{ + bt_le_scan_filter_s *__filter = (bt_le_scan_filter_s *)scan_filter; + + BT_CHECK_LE_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(scan_filter); + + if (manufacturer_id < 0 || manufacturer_id > 0xFFFF) { + BT_ERR("manufacturer_id is %.8x(0x%08x)", manufacturer_id, BT_ERROR_INVALID_PARAMETER); + return BT_ERROR_INVALID_PARAMETER; + } + + if (data_len > 27) { + BT_ERR("INVALID_PARAMETER(0x%08x)", BT_ERROR_INVALID_PARAMETER); + return BT_ERROR_INVALID_PARAMETER; + } + + g_free(__filter->manufacturer_data); + g_free(__filter->manufacturer_data_mask); + + __filter->manufacturer_id = manufacturer_id; + if (data != NULL) { + __filter->manufacturer_data = g_memdup(data, data_len); + __filter->manufacturer_data_len = data_len; + } else { + __filter->manufacturer_data = NULL; + __filter->manufacturer_data_len = 0; + } + __filter->manufacturer_data_mask = NULL; + + return BT_ERROR_NONE; +} + +int bt_adapter_le_scan_filter_set_manufacturer_data_with_mask(bt_scan_filter_h scan_filter, + int manufacturer_id, const char *data, unsigned int data_len, const char *mask, unsigned int mask_len) +{ + bt_le_scan_filter_s *__filter = (bt_le_scan_filter_s *)scan_filter; + + BT_CHECK_LE_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(scan_filter); + BT_CHECK_INPUT_PARAMETER(data); + BT_CHECK_INPUT_PARAMETER(mask); + + if (manufacturer_id < 0 || manufacturer_id > 0xFFFF) { + BT_ERR("manufacturer_id is %.8x(0x%08x)", manufacturer_id, BT_ERROR_INVALID_PARAMETER); + return BT_ERROR_INVALID_PARAMETER; + } + + if (data_len != mask_len || data_len > 27) { + BT_ERR("INVALID_PARAMETER(0x%08x)", BT_ERROR_INVALID_PARAMETER); + return BT_ERROR_INVALID_PARAMETER; + } + + g_free(__filter->manufacturer_data); + g_free(__filter->manufacturer_data_mask); + + __filter->manufacturer_id = manufacturer_id; + __filter->manufacturer_data = g_memdup(data, data_len); + __filter->manufacturer_data_len = data_len; + __filter->manufacturer_data_mask = g_memdup(mask, data_len); + + return BT_ERROR_NONE; +} + +int bt_adapter_le_register_scan_filter(bt_scan_filter_h scan_filter) +{ + int error_code = BT_ERROR_NONE; + bt_le_scan_filter_s *__filter = (bt_le_scan_filter_s*)scan_filter; + bluetooth_le_scan_filter_t filter; + + BT_CHECK_LE_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(scan_filter); + if (bluetooth_is_le_scanning() == TRUE) { + BT_ERR("NOW_IN_PROGRESS(0x%08x)", BT_ERROR_NOW_IN_PROGRESS); + return BT_ERROR_NOW_IN_PROGRESS; + } + + __bt_adapter_le_convert_scan_filter(&filter, __filter); + + error_code = _bt_get_error_code(bluetooth_register_scan_filter(&filter, &__filter->slot_id)); + if (error_code != BT_ERROR_NONE) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error_code), error_code); + } + + return error_code; +} + +int bt_adapter_le_unregister_scan_filter(bt_scan_filter_h scan_filter) +{ + int error_code = BT_ERROR_NONE; + bt_le_scan_filter_s *__filter = (bt_le_scan_filter_s*)scan_filter; + + BT_CHECK_LE_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(scan_filter); + if (bluetooth_is_le_scanning() == TRUE) { + BT_ERR("NOW_IN_PROGRESS(0x%08x)", BT_ERROR_NOW_IN_PROGRESS); + return BT_ERROR_NOW_IN_PROGRESS; + } + + error_code = _bt_get_error_code(bluetooth_unregister_scan_filter(__filter->slot_id)); + if (error_code != BT_ERROR_NONE) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error_code), error_code); + } + + return BT_ERROR_NONE; +} + +int bt_adapter_le_unregister_all_scan_filters(void) +{ + int error_code = BT_ERROR_NONE; + + BT_CHECK_LE_SUPPORT(); + BT_CHECK_INIT_STATUS(); + if (bluetooth_is_le_scanning() == TRUE) { + BT_ERR("NOW_IN_PROGRESS(0x%08x)", BT_ERROR_NOW_IN_PROGRESS); + return BT_ERROR_NOW_IN_PROGRESS; + } + + error_code = _bt_get_error_code(bluetooth_unregister_all_scan_filters()); + if (error_code != BT_ERROR_NONE) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error_code), error_code); + } + + return BT_ERROR_NONE; +} diff --git a/src/bluetooth-audio.c b/src/bluetooth-audio.c index 6ce6abd..369c727 100644 --- a/src/bluetooth-audio.c +++ b/src/bluetooth-audio.c @@ -19,124 +19,284 @@ #include #include #include "bluetooth.h" +#include "bluetooth_internal.h" #include "bluetooth_private.h" #include "bluetooth-audio-api.h" +#include "bluetooth-telephony-api.h" +#include "bluetooth-scmst-api.h" -#ifdef LOG_TAG -#undef LOG_TAG +typedef struct _call_list_s { + GList *list; +} call_list_s; + +static bool is_audio_initialized = false; + +#if defined (TIZEN_HFP_DISABLE) && defined (TIZEN_A2DP_DISABLE) +#define BT_CHECK_AUDIO_SUPPORT() \ + { \ + BT_CHECK_BT_SUPPORT(); \ + LOGE("[%s] NOT_SUPPORTED(0x%08x)", __FUNCTION__, BT_ERROR_NOT_SUPPORTED); \ + return BT_ERROR_NOT_SUPPORTED; \ + } +#else +#define BT_CHECK_AUDIO_SUPPORT() +#endif + +#ifdef TIZEN_HFP_DISABLE +#define BT_CHECK_HFP_SUPPORT() \ + { \ + BT_CHECK_BT_SUPPORT(); \ + LOGE("[%s] NOT_SUPPORTED(0x%08x)", __FUNCTION__, BT_ERROR_NOT_SUPPORTED); \ + return BT_ERROR_NOT_SUPPORTED; \ + } +#else +#define BT_CHECK_HFP_SUPPORT() #endif -#define LOG_TAG "TIZEN_N_BLUETOOTH" -/*The below API is just to convert the error from Audio API's to CAPI error codes, +#ifdef TIZEN_A2DP_DISABLE +#define BT_CHECK_A2DP_SUPPORT() \ + { \ + BT_CHECK_BT_SUPPORT(); \ + LOGE("[%s] NOT_SUPPORTED(0x%08x)", __FUNCTION__, BT_ERROR_NOT_SUPPORTED); \ + return BT_ERROR_NOT_SUPPORTED; \ + } +#else +#define BT_CHECK_A2DP_SUPPORT() +#endif + +#define BT_CHECK_AUDIO_INIT_STATUS() \ + if (__bt_check_audio_init_status() == BT_ERROR_NOT_INITIALIZED) \ + { \ + LOGE("[%s] NOT_INITIALIZED(0x%08x)", __FUNCTION__, BT_ERROR_NOT_INITIALIZED); \ + return BT_ERROR_NOT_INITIALIZED; \ + } + +int __bt_check_audio_init_status(void) +{ + if (is_audio_initialized != true) { + BT_ERR("NOT_INITIALIZED(0x%08x)", BT_ERROR_NOT_INITIALIZED); + return BT_ERROR_NOT_INITIALIZED; + } + + return BT_ERROR_NONE; +} + +/*The below API is just to convert the error from Telephony API's to CAPI error codes, * this is temporary change and changes to proper error code will be done in * subsequent check ins.*/ -int _bt_convert_media_error_code(int error) +int _bt_convert_telephony_error_code(int error) { switch(error) { - case BLUETOOTH_AUDIO_ERROR_NONE: + case BLUETOOTH_TELEPHONY_ERROR_NONE: return BT_ERROR_NONE; - case BLUETOOTH_AUDIO_ERROR_INTERNAL: - return BT_ERROR_INVALID_PARAMETER; - case BLUETOOTH_AUDIO_ERROR_INVALID_PARAM: + case BLUETOOTH_TELEPHONY_ERROR_INVALID_PARAM: return BT_ERROR_INVALID_PARAMETER; - case BLUETOOTH_AG_ERROR_CONNECTION_ERROR: - return BT_ERROR_OPERATION_FAILED; - case BLUETOOTH_AV_ERROR_CONNECTION_ERROR: + case BLUETOOTH_TELEPHONY_ERROR_NOT_INITIALIZED: + return BT_ERROR_NOT_INITIALIZED; + case BLUETOOTH_TELEPHONY_ERROR_NOT_ENABLED: + return BT_ERROR_NOT_ENABLED; + case BLUETOOTH_TELEPHONY_ERROR_AUDIO_NOT_CONNECTED: + case BLUETOOTH_TELEPHONY_ERROR_NOT_CONNECTED: + return BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED; + case BLUETOOTH_TELEPHONY_ERROR_BUSY: + return BT_ERROR_RESOURCE_BUSY; + case BLUETOOTH_TELEPHONY_ERROR_NO_MEMORY: + return BT_ERROR_OUT_OF_MEMORY; + case BLUETOOTH_TELEPHONY_ERROR_ALREADY_INITIALIZED: + case BLUETOOTH_TELEPHONY_ERROR_ALREADY_EXSIST: + case BLUETOOTH_TELEPHONY_ERROR_ALREADY_CONNECTED: + return BT_ERROR_ALREADY_DONE; + case BLUETOOTH_TELEPHONY_ERROR_INTERNAL: + case BLUETOOTH_TELEPHONY_ERROR_NOT_AVAILABLE: + case BLUETOOTH_TELEPHONY_ERROR_I_O_ERROR: + case BLUETOOTH_TELEPHONY_ERROR_OPERATION_NOT_AVAILABLE: return BT_ERROR_OPERATION_FAILED; + case BLUETOOTH_TELEPHONY_ERROR_PERMISSION_DENIED: + return BT_ERROR_PERMISSION_DENIED; default: return BT_ERROR_NONE; } } + int bt_audio_initialize(void) { - int error = BT_ERROR_NONE; + int error; + BT_CHECK_AUDIO_SUPPORT(); BT_CHECK_INIT_STATUS(); error = bluetooth_audio_init(_bt_audio_event_proxy, NULL); - error = _bt_convert_media_error_code(error); error = _bt_get_error_code(error); if (BT_ERROR_NONE != error) { - LOGE("[%s] %s(0x%08x)", __FUNCTION__, - _bt_convert_error_to_string(error), error); + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error), error); + return error; } - return error; + +#ifdef TIZEN_WEARABLE + error = bluetooth_hf_init(_bt_hf_event_proxy, NULL); + error = _bt_get_error_code(error); + if (BT_ERROR_NONE != error) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error), error); + return error; + } +#endif + +#ifndef TELEPHONY_DISABLED /* B2_3G */ + error = bluetooth_telephony_init((void *)_bt_telephony_event_proxy, NULL); + error = _bt_convert_telephony_error_code(error); + if (BT_ERROR_NONE != error) { + BT_ERR("[%s] (0x%08x)", _bt_convert_error_to_string(error), error); + return error; + } +#endif + + is_audio_initialized = true; + return BT_ERROR_NONE; } int bt_audio_deinitialize(void) { - int error = BT_ERROR_NONE; + int error; + BT_CHECK_AUDIO_SUPPORT(); BT_CHECK_INIT_STATUS(); + BT_CHECK_AUDIO_INIT_STATUS(); + +#ifdef TIZEN_WEARABLE + error = bluetooth_hf_deinit(); + error = _bt_get_error_code(error); + if (BT_ERROR_NONE != error) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error), error); + return error; + } +#endif error = bluetooth_audio_deinit(); - error = _bt_convert_media_error_code(error); error = _bt_get_error_code(error); if (BT_ERROR_NONE != error) { - LOGE("[%s] %s(0x%08x)", __FUNCTION__, - _bt_convert_error_to_string(error), error); + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error), error); + return error; } - return error; + +#ifndef TELEPHONY_DISABLED /* B2_3G */ + error = bluetooth_telephony_deinit(); + error = _bt_convert_telephony_error_code(error); + if (BT_ERROR_NONE != error) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error), error); + return error; + } +#endif + + is_audio_initialized = false; + return BT_ERROR_NONE; } int bt_audio_connect(const char *remote_address, bt_audio_profile_type_e type) { - int error = BT_ERROR_NONE; + int error; bluetooth_device_address_t addr_hex = { {0,} }; + + BT_CHECK_AUDIO_SUPPORT(); BT_CHECK_INIT_STATUS(); + BT_CHECK_AUDIO_INIT_STATUS(); + + if (type == BT_AUDIO_PROFILE_TYPE_HSP_HFP) { + BT_CHECK_HFP_SUPPORT(); +#ifdef TELEPHONY_DISABLED + BT_ERR("NOT SUPPORTED(0x%08x)", BT_ERROR_NOT_SUPPORTED); + return BT_ERROR_NOT_SUPPORTED; +#endif + } else if (type == BT_AUDIO_PROFILE_TYPE_A2DP) { + BT_CHECK_A2DP_SUPPORT(); + } else if (type == BT_AUDIO_PROFILE_TYPE_ALL) { +#if defined (TIZEN_HFP_DISABLE) || defined (TELEPHONY_DISABLED) + BT_ERR("HSP NOT SUPPORTED(0x%08x)", BT_ERROR_NOT_SUPPORTED); + type = BT_AUDIO_PROFILE_TYPE_A2DP; +#else + BT_ERR("ALL SUPPORTED"); + type = BT_AUDIO_PROFILE_TYPE_ALL; +#endif + } + BT_CHECK_INPUT_PARAMETER(remote_address); _bt_convert_address_to_hex(&addr_hex, remote_address); switch(type) { +#ifndef TELEPHONY_DISABLED case BT_AUDIO_PROFILE_TYPE_HSP_HFP: error = bluetooth_ag_connect(&addr_hex); break; +#endif case BT_AUDIO_PROFILE_TYPE_A2DP: error = bluetooth_av_connect(&addr_hex); break; +#ifdef TIZEN_WEARABLE + case BT_AUDIO_PROFILE_TYPE_AG: + error = bluetooth_hf_connect(&addr_hex); + break; +#endif case BT_AUDIO_PROFILE_TYPE_ALL: default: error = bluetooth_audio_connect(&addr_hex); break; } - error = _bt_convert_media_error_code(error); error = _bt_get_error_code(error); if (error != BT_ERROR_NONE) { - LOGE("[%s] %s(0x%08x)", __FUNCTION__, - _bt_convert_error_to_string(error), error); + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error), error); } return error; } int bt_audio_disconnect(const char *remote_address, bt_audio_profile_type_e type) { - int error = BT_ERROR_NONE; + int error; bluetooth_device_address_t addr_hex = { {0,} }; + + BT_CHECK_AUDIO_SUPPORT(); BT_CHECK_INIT_STATUS(); + BT_CHECK_AUDIO_INIT_STATUS(); + + if (type == BT_AUDIO_PROFILE_TYPE_HSP_HFP) { + BT_CHECK_HFP_SUPPORT(); +#ifdef TELEPHONY_DISABLED + BT_ERR("NOT SUPPORTED(0x%08x)", BT_ERROR_NOT_SUPPORTED); + return BT_ERROR_NOT_SUPPORTED; +#endif + } else if (type == BT_AUDIO_PROFILE_TYPE_A2DP) { + BT_CHECK_A2DP_SUPPORT(); + } + BT_CHECK_INPUT_PARAMETER(remote_address); _bt_convert_address_to_hex(&addr_hex, remote_address); switch(type) { +#ifndef TELEPHONY_DISABLED case BT_AUDIO_PROFILE_TYPE_HSP_HFP: error = bluetooth_ag_disconnect(&addr_hex); break; +#endif case BT_AUDIO_PROFILE_TYPE_A2DP: error = bluetooth_av_disconnect(&addr_hex); break; +#ifdef TIZEN_WEARABLE + case BT_AUDIO_PROFILE_TYPE_AG: + error = bluetooth_hf_disconnect(&addr_hex); + break; +#endif case BT_AUDIO_PROFILE_TYPE_ALL: default: error = bluetooth_audio_disconnect(&addr_hex); break; } - error = _bt_convert_media_error_code(error); error = _bt_get_error_code(error); if (error != BT_ERROR_NONE) { - LOGE("[%s] %s(0x%08x)", __FUNCTION__, - _bt_convert_error_to_string(error), error); + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error), error); } return error; } int bt_audio_set_connection_state_changed_cb(bt_audio_connection_state_changed_cb callback, void *user_data) { + BT_CHECK_AUDIO_SUPPORT(); BT_CHECK_INIT_STATUS(); + BT_CHECK_AUDIO_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(callback); _bt_set_cb(BT_EVENT_AUDIO_CONNECTION_STATUS, callback, user_data); return BT_ERROR_NONE; @@ -144,57 +304,128 @@ int bt_audio_set_connection_state_changed_cb(bt_audio_connection_state_changed_c } int bt_audio_unset_connection_state_changed_cb(void) { + BT_CHECK_AUDIO_SUPPORT(); BT_CHECK_INIT_STATUS(); + BT_CHECK_AUDIO_INIT_STATUS(); if (_bt_check_cb(BT_EVENT_AUDIO_CONNECTION_STATUS) == true) _bt_unset_cb(BT_EVENT_AUDIO_CONNECTION_STATUS); return BT_ERROR_NONE; } -int bt_ag_notify_speaker_gain(const char *remote_address, int gain) +int bt_a2dp_source_audio_set_connection_state_changed_cb(bt_audio_connection_state_changed_cb callback, void *user_data) { - int error = BT_ERROR_NONE; + BT_CHECK_AUDIO_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_AUDIO_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(callback); + _bt_set_cb(BT_EVENT_A2DP_SOURCE_CONNECTION_STATUS, callback, user_data); + return BT_ERROR_NONE; +} + +int bt_a2dp_source_audio_unset_connection_state_changed_cb(void) +{ + BT_CHECK_AUDIO_SUPPORT(); BT_CHECK_INIT_STATUS(); - BT_CHECK_INPUT_PARAMETER(remote_address); - error = bluetooth_ag_set_speaker_gain((unsigned short)gain); - error = _bt_convert_media_error_code(error); - error = _bt_get_error_code(error); + BT_CHECK_AUDIO_INIT_STATUS(); + if (_bt_check_cb(BT_EVENT_A2DP_SOURCE_CONNECTION_STATUS) == true) + _bt_unset_cb(BT_EVENT_A2DP_SOURCE_CONNECTION_STATUS); + return BT_ERROR_NONE; +} + +int bt_ag_notify_speaker_gain(int gain) +{ + int error; + + BT_CHECK_HFP_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_AUDIO_INIT_STATUS(); + error = bluetooth_telephony_set_speaker_gain((unsigned short)gain); + error = _bt_convert_telephony_error_code(error); if (BT_ERROR_NONE != error) { - LOGE("[%s] %s(0x%08x)", __FUNCTION__, - _bt_convert_error_to_string(error), error); + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error), error); } return error; } -int bt_ag_get_speaker_gain(const char *remote_address, int *gain) +int bt_ag_get_speaker_gain(int *gain) { - int error = BT_ERROR_NONE; + int error; + BT_CHECK_HFP_SUPPORT(); BT_CHECK_INIT_STATUS(); + BT_CHECK_AUDIO_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(gain); - BT_CHECK_INPUT_PARAMETER(remote_address); - error = bluetooth_ag_get_headset_volume((unsigned int *)gain); - error = _bt_convert_media_error_code(error); - error = _bt_get_error_code(error); + error = bluetooth_telephony_get_headset_volume((unsigned int *)gain); + error = _bt_convert_telephony_error_code(error); if (BT_ERROR_NONE != error) { - LOGE("[%s] %s(0x%08x)", __FUNCTION__, - _bt_convert_error_to_string(error), error); + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error), error); } return error; } +int bt_ag_is_nrec_enabled(bool *enabled) +{ + int error; + gboolean is_enabled = FALSE; + + BT_CHECK_HFP_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_AUDIO_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(enabled); + + error = bluetooth_telephony_is_nrec_enabled(&is_enabled); + error = _bt_convert_telephony_error_code(error); + if (BT_ERROR_NONE != error) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error), error); + } + if (is_enabled) + *enabled = true; + else + *enabled = false; + + return error; +} + +int bt_ag_is_wbs_mode(bool *wbs_mode) +{ + int error; + gboolean is_wbs_mode = FALSE; + + BT_CHECK_HFP_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_AUDIO_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(wbs_mode); + + error = bluetooth_telephony_is_wbs_mode(&is_wbs_mode); + error = _bt_convert_telephony_error_code(error); + if (BT_ERROR_NONE != error) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error), error); + } + if (is_wbs_mode) + *wbs_mode = true; + else + *wbs_mode = false; + + return error; +} + int bt_ag_set_microphone_gain_changed_cb(bt_ag_microphone_gain_changed_cb callback, void *user_data) { + BT_CHECK_HFP_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_AUDIO_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(callback); _bt_set_cb(BT_EVENT_AG_MICROPHONE_GAIN_CHANGE, callback, user_data); return BT_ERROR_NONE; - } int bt_ag_unset_microphone_gain_changed_cb(void) { + BT_CHECK_HFP_SUPPORT(); BT_CHECK_INIT_STATUS(); + BT_CHECK_AUDIO_INIT_STATUS(); if (_bt_check_cb(BT_EVENT_AG_MICROPHONE_GAIN_CHANGE) == true) _bt_unset_cb(BT_EVENT_AG_MICROPHONE_GAIN_CHANGE); return BT_ERROR_NONE; @@ -203,7 +434,9 @@ int bt_ag_unset_microphone_gain_changed_cb(void) int bt_ag_set_speaker_gain_changed_cb(bt_ag_speaker_gain_changed_cb callback, void *user_data) { + BT_CHECK_HFP_SUPPORT(); BT_CHECK_INIT_STATUS(); + BT_CHECK_AUDIO_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(callback); _bt_set_cb(BT_EVENT_AG_SPEAKER_GAIN_CHANGE, callback, user_data); return BT_ERROR_NONE; @@ -211,8 +444,765 @@ int bt_ag_set_speaker_gain_changed_cb(bt_ag_speaker_gain_changed_cb callback, int bt_ag_unset_speaker_gain_changed_cb(void) { + BT_CHECK_HFP_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_AUDIO_INIT_STATUS(); if (_bt_check_cb(BT_EVENT_AG_SPEAKER_GAIN_CHANGE) == true) _bt_unset_cb(BT_EVENT_AG_SPEAKER_GAIN_CHANGE); return BT_ERROR_NONE; } + +int bt_ag_open_sco(void) +{ + int error; + + BT_CHECK_HFP_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_AUDIO_INIT_STATUS(); + error = bluetooth_telephony_audio_open(); + error = _bt_convert_telephony_error_code(error); + if (error != BT_ERROR_NONE) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error), error); + } + return error; +} + +int bt_ag_close_sco(void) +{ + int error; + + BT_CHECK_HFP_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_AUDIO_INIT_STATUS(); + error = bluetooth_telephony_audio_close(); + error = _bt_convert_telephony_error_code(error); + if (error != BT_ERROR_NONE) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error), error); + } + return error; +} + +int bt_ag_is_sco_opened(bool *opened) +{ + BT_CHECK_HFP_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_AUDIO_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(opened); + if (bluetooth_telephony_is_sco_connected()) + *opened = true; + else + *opened = false; + return BT_ERROR_NONE; +} + +int bt_ag_set_sco_state_changed_cb(bt_ag_sco_state_changed_cb callback, + void *user_data) +{ + BT_CHECK_HFP_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_AUDIO_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(callback); + _bt_set_cb(BT_EVENT_AG_SCO_CONNECTION_STATUS, callback, user_data); + return BT_ERROR_NONE; +} + +int bt_ag_unset_sco_state_changed_cb(void) +{ + BT_CHECK_HFP_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_AUDIO_INIT_STATUS(); + if (_bt_check_cb(BT_EVENT_AG_SCO_CONNECTION_STATUS) == true) + _bt_unset_cb(BT_EVENT_AG_SCO_CONNECTION_STATUS); + return BT_ERROR_NONE; +} + +int bt_ag_notify_call_event(bt_ag_call_event_e event, unsigned int call_id, const char *phone_number) +{ + int error; + + BT_CHECK_HFP_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_AUDIO_INIT_STATUS(); + BT_INFO("call_id [%d] / event [%d]", call_id, event); + + switch(event) { + case BT_AG_CALL_EVENT_IDLE: + error = bluetooth_telephony_call_end(call_id); + break; + case BT_AG_CALL_EVENT_ANSWERED: + error = bluetooth_telephony_call_answered(call_id, FALSE); + break; + case BT_AG_CALL_EVENT_HELD: + error = bluetooth_telephony_call_held(call_id); + break; + case BT_AG_CALL_EVENT_RETRIEVED: + error = bluetooth_telephony_call_retrieved(call_id); + break; + case BT_AG_CALL_EVENT_DIALING: + BT_CHECK_INPUT_PARAMETER(phone_number); + error = bluetooth_telephony_indicate_outgoing_call( + phone_number, call_id, FALSE); + break; + case BT_AG_CALL_EVENT_ALERTING: + error = bluetooth_telephony_call_remote_ringing(call_id); + break; + case BT_AG_CALL_EVENT_INCOMING: + BT_CHECK_INPUT_PARAMETER(phone_number); + error = bluetooth_telephony_indicate_incoming_call(phone_number, + call_id); + break; + default: + error = BLUETOOTH_TELEPHONY_ERROR_INVALID_PARAM; + } + error = _bt_convert_telephony_error_code(error); + if (error != BT_ERROR_NONE) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error), error); + } + return error; +} + +int bt_ag_notify_call_list(bt_call_list_h list) +{ + int error; + unsigned int call_count; + call_list_s *handle; + + BT_CHECK_HFP_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_AUDIO_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(list); + handle = (call_list_s *)list; + call_count = g_list_length(handle->list); + error = bluetooth_telephony_set_call_status((void *)handle->list, call_count); + error = _bt_convert_telephony_error_code(error); + if (error != BT_ERROR_NONE) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error), error); + } + return error; +} + +int bt_ag_notify_voice_recognition_state(bool state) +{ + int error; + + BT_CHECK_HFP_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_AUDIO_INIT_STATUS(); + if (state) + error = bluetooth_telephony_start_voice_recognition(); + else + error = bluetooth_telephony_stop_voice_recognition(); + error = _bt_convert_telephony_error_code(error); + if (error != BT_ERROR_NONE) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error), error); + } + return error; +} + +int bt_ag_set_call_handling_event_cb(bt_ag_call_handling_event_cb callback, + void *user_data) +{ + BT_CHECK_HFP_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_AUDIO_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(callback); + _bt_set_cb(BT_EVENT_AG_CALL_HANDLING_EVENT, callback, user_data); + return BT_ERROR_NONE; +} + +int bt_ag_unset_call_handling_event_cb(void) +{ + BT_CHECK_HFP_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_AUDIO_INIT_STATUS(); + if (_bt_check_cb(BT_EVENT_AG_CALL_HANDLING_EVENT) == true) + _bt_unset_cb(BT_EVENT_AG_CALL_HANDLING_EVENT); + return BT_ERROR_NONE; +} + +int bt_ag_set_multi_call_handling_event_cb( + bt_ag_multi_call_handling_event_cb callback, + void *user_data) +{ + BT_CHECK_HFP_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_AUDIO_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(callback); + _bt_set_cb(BT_EVENT_AG_MULTI_CALL_HANDLING_EVENT, callback, user_data); + return BT_ERROR_NONE; +} + +int bt_ag_unset_multi_call_handling_event_cb(void) +{ + BT_CHECK_HFP_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_AUDIO_INIT_STATUS(); + if (_bt_check_cb(BT_EVENT_AG_MULTI_CALL_HANDLING_EVENT) == true) + _bt_unset_cb(BT_EVENT_AG_MULTI_CALL_HANDLING_EVENT); + return BT_ERROR_NONE; +} + +int bt_ag_set_dtmf_transmitted_cb(bt_ag_dtmf_transmitted_cb callback, + void *user_data) +{ + BT_CHECK_HFP_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_AUDIO_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(callback); + _bt_set_cb(BT_EVENT_AG_DTMF_TRANSMITTED, callback, user_data); + return BT_ERROR_NONE; +} + +int bt_ag_unset_dtmf_transmitted_cb(void) +{ + BT_CHECK_HFP_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_AUDIO_INIT_STATUS(); + if (_bt_check_cb(BT_EVENT_AG_DTMF_TRANSMITTED) == true) + _bt_unset_cb(BT_EVENT_AG_DTMF_TRANSMITTED); + return BT_ERROR_NONE; +} + +int bt_ag_is_connected(bool *connected) +{ + int error; + gboolean is_connected = false; + + BT_CHECK_HFP_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(connected); + + error = bluetooth_telephony_is_connected(&is_connected); + error = _bt_get_error_code(error); + if (error != BT_ERROR_NONE) + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error), error); + + if (is_connected) + *connected = true; + else + *connected = false; + + return error; +} + +int bt_call_list_create(bt_call_list_h *list) +{ + call_list_s *handle; + + BT_CHECK_HFP_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_AUDIO_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(list); + if (*list != NULL) { + BT_ERR("BT_ERROR_ALREADY_DONE(0x%08x)", BT_ERROR_ALREADY_DONE); + return BT_ERROR_ALREADY_DONE; + } + handle = g_malloc0(sizeof(call_list_s)); + if (handle == NULL) { + BT_ERR("BT_ERROR_OUT_OF_MEMORY(0x%08x)", BT_ERROR_OUT_OF_MEMORY); + return BT_ERROR_OUT_OF_MEMORY; + } + + *list = handle; + return BT_ERROR_NONE; +} + +int bt_call_list_destroy(bt_call_list_h list) +{ + int result; + call_list_s *handle; + + BT_CHECK_HFP_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_AUDIO_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(list); + handle = (call_list_s *)list; + result = bt_call_list_reset(list); + g_free(handle); + return result; +} + +int bt_call_list_reset(bt_call_list_h list) +{ + call_list_s *handle; + bt_telephony_call_status_info_t *call_status; + + BT_CHECK_HFP_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_AUDIO_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(list); + handle = (call_list_s *)list; + do { + call_status = (bt_telephony_call_status_info_t *)g_list_nth_data(handle->list, 0); + if (call_status == NULL) + break; + handle->list = g_list_remove(handle->list, call_status); + + if (NULL != call_status->phone_number) + g_free(call_status->phone_number); + + g_free(call_status); + } while (1); + return BT_ERROR_NONE; +} + +int bt_call_list_add(bt_call_list_h list, unsigned int call_id, bt_ag_call_state_e state, const char *phone_number) +{ + call_list_s *handle; + bt_telephony_call_status_info_t *call_status; + + BT_CHECK_HFP_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_AUDIO_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(list); + BT_CHECK_INPUT_PARAMETER(phone_number); + + handle = (call_list_s *)list; + call_status = g_malloc0(sizeof(bt_telephony_call_status_info_t)); + + /* Fix : NULL_RETURNS */ + if (call_status == NULL) + return BT_ERROR_OUT_OF_MEMORY; + call_status->call_id = call_id; + call_status->call_status = state; + call_status->phone_number = g_strdup(phone_number); + + handle->list = g_list_append(handle->list, (gpointer)call_status); + return BT_ERROR_NONE; +} + +#ifdef TIZEN_WEARABLE +int bt_hf_initialize(void) +{ +#ifdef TIZEN_AUDIO_HF_SUPPORT + int error; + + BT_CHECK_INIT_STATUS(); + error = bluetooth_hf_init(_bt_hf_event_proxy, NULL); + error = _bt_get_error_code(error); + if (BT_ERROR_NONE != error) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error), error); + return error; + } + return error; +#else + BT_ERR("NOT_SUPPORTED(0x%08x)", BT_ERROR_NOT_SUPPORTED); + return BT_ERROR_NOT_SUPPORTED; +#endif +} + +int bt_hf_deinitialize(void) +{ +#ifdef TIZEN_AUDIO_HF_SUPPORT + int error; + + BT_CHECK_INIT_STATUS(); + error = bluetooth_hf_deinit(); + error = _bt_get_error_code(error); + if (BT_ERROR_NONE != error) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error), error); + return error; + } + return error; +#else + BT_ERR("NOT_SUPPORTED(0x%08x)", BT_ERROR_NOT_SUPPORTED); + return BT_ERROR_NOT_SUPPORTED; +#endif +} + +int bt_hf_notify_call_event(bt_hf_call_event_e event, char *phone_number) +{ +#ifdef TIZEN_AUDIO_HF_SUPPORT + int error = BT_ERROR_NONE; + + BT_CHECK_INIT_STATUS(); + BT_INFO("event [%d]", event); + + switch(event) { + case BT_HF_CALL_EVENT_IDLE: + error = bluetooth_hf_terminate_call(); + break; + case BT_HF_CALL_EVENT_ANSWER: + error = bluetooth_hf_answer_call(); + break; + case BT_HF_CALL_EVENT_HOLD: + break; + case BT_HF_CALL_EVENT_RETRIEVE: + break; + case BT_HF_CALL_EVENT_DIAL: + BT_CHECK_INPUT_PARAMETER(phone_number); + error = bluetooth_hf_initiate_call(phone_number); + break; + case BT_HF_CALL_EVENT_REDIAL: + break; + case BT_HF_CALL_EVENT_RELEASE_ALL_NONACTIVE_CALLS: + error = bluetooth_hf_release_all_call(); + break; + case BT_HF_CALL_EVENT_ACCEPT_AND_RELEASE: + error = bluetooth_hf_release_and_accept(); + break; + case BT_HF_CALL_EVENT_ACCEPT_AND_HOLD: + error = bluetooth_hf_swap_call(); + break; + case BT_HF_CALL_EVENT_ADD_TO_CONVERSATION: + error = bluetooth_hf_join_call(); + break; + default: + error = BLUETOOTH_ERROR_INVALID_PARAM; + break; + } + + error = _bt_get_error_code(error); + if (error != BT_ERROR_NONE) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error), error); + } + return error; +#else + BT_ERR("NOT_SUPPORTED(0x%08x)", BT_ERROR_NOT_SUPPORTED); + return BT_ERROR_NOT_SUPPORTED; +#endif +} + +int bt_hf_notify_speaker_gain(int gain) +{ +#ifdef TIZEN_AUDIO_HF_SUPPORT + int error; + + BT_CHECK_INIT_STATUS(); + error = bluetooth_hf_set_speaker_gain((unsigned int)gain); + error = _bt_get_error_code(error); + if (BT_ERROR_NONE != error) + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error), error); + + return error; +#else + BT_ERR("NOT_SUPPORTED(0x%08x)", BT_ERROR_NOT_SUPPORTED); + return BT_ERROR_NOT_SUPPORTED; +#endif +} + +int bt_hf_set_speaker_gain_changed_cb(bt_hf_speaker_gain_changed_cb callback, void *user_data) +{ +#ifdef TIZEN_AUDIO_HF_SUPPORT + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(callback); + _bt_set_cb(BT_EVENT_HF_SPEAKER_GAIN_CHANGE, callback, user_data); + return BT_ERROR_NONE; +#else + BT_ERR("NOT_SUPPORTED(0x%08x)", BT_ERROR_NOT_SUPPORTED); + return BT_ERROR_NOT_SUPPORTED; +#endif +} + +int bt_hf_unset_speaker_gain_changed_cb(void) +{ +#ifdef TIZEN_AUDIO_HF_SUPPORT + BT_CHECK_INIT_STATUS(); + if (_bt_check_cb(BT_EVENT_HF_SPEAKER_GAIN_CHANGE) == true) + _bt_unset_cb(BT_EVENT_HF_SPEAKER_GAIN_CHANGE); + return BT_ERROR_NONE; +#else + BT_ERR("NOT_SUPPORTED(0x%08x)", BT_ERROR_NOT_SUPPORTED); + return BT_ERROR_NOT_SUPPORTED; +#endif +} + +int bt_hf_notify_voice_recognition_state(bool state) +{ +#ifdef TIZEN_AUDIO_HF_SUPPORT + int error; + + BT_CHECK_INIT_STATUS(); + error = bluetooth_hf_voice_recognition(state); + error = _bt_get_error_code(error); + if (error != BT_ERROR_NONE) + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error), error); + + return error; +#else + BT_ERR("NOT_SUPPORTED(0x%08x)", BT_ERROR_NOT_SUPPORTED); + return BT_ERROR_NOT_SUPPORTED; +#endif +} + +int bt_hf_set_call_status_updated_event_cb(bt_hf_call_status_updated_event_cb callback, void *user_data) +{ +#ifdef TIZEN_AUDIO_HF_SUPPORT + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(callback); + _bt_set_cb(BT_EVENT_HF_CALL_STATUS_UPDATED_EVENT, callback, user_data); + return BT_ERROR_NONE; +#else + BT_ERR("NOT_SUPPORTED(0x%08x)", BT_ERROR_NOT_SUPPORTED); + return BT_ERROR_NOT_SUPPORTED; +#endif +} + +int bt_hf_unset_call_status_updated_event_cb(void) +{ +#ifdef TIZEN_AUDIO_HF_SUPPORT + BT_CHECK_INIT_STATUS(); + if (_bt_check_cb(BT_EVENT_HF_CALL_STATUS_UPDATED_EVENT) == true) + _bt_unset_cb(BT_EVENT_HF_CALL_STATUS_UPDATED_EVENT); + return BT_ERROR_NONE; +#else + BT_ERR("NOT_SUPPORTED(0x%08x)", BT_ERROR_NOT_SUPPORTED); + return BT_ERROR_NOT_SUPPORTED; +#endif +} + +int bt_hf_close_sco(void) +{ +#ifdef TIZEN_AUDIO_HF_SUPPORT + int error; + + BT_CHECK_INIT_STATUS(); + error = bluetooth_hf_audio_disconnect(); + error = _bt_get_error_code(error); + if (error != BT_ERROR_NONE) + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error), error); + + return error; +#else + BT_ERR("NOT_SUPPORTED(0x%08x)", BT_ERROR_NOT_SUPPORTED); + return BT_ERROR_NOT_SUPPORTED; +#endif +} + +int bt_hf_send_dtmf(char *dtmf) +{ +#ifdef TIZEN_AUDIO_HF_SUPPORT + int error; + + BT_CHECK_INIT_STATUS(); + error = bluetooth_hf_send_dtmf(dtmf); + error = _bt_get_error_code(error); + if (error != BT_ERROR_NONE) + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error), error); + + return error; +#else + BT_ERR("NOT_SUPPORTED(0x%08x)", BT_ERROR_NOT_SUPPORTED); + return BT_ERROR_NOT_SUPPORTED; +#endif +} + +int bt_hf_is_connected(bool *connected) +{ +#ifdef TIZEN_AUDIO_HF_SUPPORT + int error; + gboolean is_connected = false; + + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(connected); + + error = bluetooth_hf_is_connected(&is_connected); + error = _bt_get_error_code(error); + if (error != BT_ERROR_NONE) + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error), error); + + if (is_connected) + *connected = true; + else + *connected = false; + + return error; +#else + BT_ERR("NOT_SUPPORTED(0x%08x)", BT_ERROR_NOT_SUPPORTED); + return BT_ERROR_NOT_SUPPORTED; +#endif +} + +int bt_hf_is_sco_opened(bool *opened) +{ +#ifdef TIZEN_AUDIO_HF_SUPPORT + int error; + unsigned int audio_connected = BLUETOOTH_HF_AUDIO_DISCONNECTED; + + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(opened); + + error = bluetooth_hf_get_audio_connected(&audio_connected); + error = _bt_get_error_code(error); + if (error != BT_ERROR_NONE) + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error), error); + + if (audio_connected == BLUETOOTH_HF_AUDIO_CONNECTED) + *opened = true; + else + *opened = false; + + return error; +#else + BT_ERR("NOT_SUPPORTED(0x%08x)", BT_ERROR_NOT_SUPPORTED); + return BT_ERROR_NOT_SUPPORTED; +#endif +} + +int bt_hf_get_codec_id(unsigned int *codec_id) +{ +#ifdef TIZEN_AUDIO_HF_SUPPORT + int error; + + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(codec_id); + + error = bluetooth_hf_get_codec(codec_id); + error = _bt_get_error_code(error); + if (error != BT_ERROR_NONE) + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error), error); + + return error; +#else + BT_ERR("NOT_SUPPORTED(0x%08x)", BT_ERROR_NOT_SUPPORTED); + return BT_ERROR_NOT_SUPPORTED; +#endif +} + +int bt_hf_get_call_status_info_list(GSList **call_list) +{ +#ifdef TIZEN_AUDIO_HF_SUPPORT + int error; + bt_hf_call_list_s *hf_call_list = NULL; + GList *l; + + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(call_list); + + error = bluetooth_hf_request_call_list(&hf_call_list); + error = _bt_get_error_code(error); + if (error != BT_ERROR_NONE) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error), error); + return error; + } + + *call_list = NULL; + for (l = g_list_first(hf_call_list->list); l; l = g_list_next(l)) { + bt_hf_call_status_info_t *hf_call_info = l->data; + bt_hf_call_status_info_s *call_info = NULL; + + call_info = g_malloc0(sizeof(bt_hf_call_status_info_s)); + call_info->number = strdup(hf_call_info->number); + call_info->direction = hf_call_info->direction; + call_info->status = hf_call_info->status; + call_info->multi_party = hf_call_info->mpart; + call_info->index = hf_call_info->idx; + *call_list = g_slist_append(*call_list, call_info); + } + + bluetooth_hf_free_call_list(hf_call_list); + + return error; +#else + BT_ERR("NOT_SUPPORTED(0x%08x)", BT_ERROR_NOT_SUPPORTED); + return BT_ERROR_NOT_SUPPORTED; +#endif +} + +#ifdef TIZEN_AUDIO_HF_SUPPORT +static void __bt_hf_free_call_status_info(void *data) +{ + bt_hf_call_status_info_s *call_info = (bt_hf_call_status_info_s*)data; + g_free(call_info->number); + g_free(call_info); +} +#endif + +int bt_hf_free_call_status_info_list(GSList *call_list) +{ +#ifdef TIZEN_AUDIO_HF_SUPPORT + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(call_list); + + g_slist_free_full(call_list, __bt_hf_free_call_status_info); + + return BT_ERROR_NONE; +#else + BT_ERR("NOT_SUPPORTED(0x%08x)", BT_ERROR_NOT_SUPPORTED); + return BT_ERROR_NOT_SUPPORTED; +#endif +} + +int bt_hf_set_sco_state_changed_cb(bt_hf_sco_state_changed_cb callback, + void *user_data) +{ +#ifdef TIZEN_AUDIO_HF_SUPPORT + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(callback); + _bt_set_cb(BT_EVENT_HF_SCO_CONNECTION_STATUS, callback, user_data); + return BT_ERROR_NONE; +#else + BT_ERR("NOT_SUPPORTED(0x%08x)", BT_ERROR_NOT_SUPPORTED); + return BT_ERROR_NOT_SUPPORTED; +#endif +} + +int bt_hf_unset_sco_state_changed_cb(void) +{ +#ifdef TIZEN_AUDIO_HF_SUPPORT + BT_CHECK_INIT_STATUS(); + if (_bt_check_cb(BT_EVENT_HF_SCO_CONNECTION_STATUS) == true) + _bt_unset_cb(BT_EVENT_HF_SCO_CONNECTION_STATUS); + return BT_ERROR_NONE; +#else + BT_ERR("NOT_SUPPORTED(0x%08x)", BT_ERROR_NOT_SUPPORTED); + return BT_ERROR_NOT_SUPPORTED; +#endif +} + +int bt_hf_set_call_handling_event_cb(bt_hf_call_handling_event_cb callback, + void *user_data) +{ +#ifdef TIZEN_AUDIO_HF_SUPPORT + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(callback); + _bt_set_cb(BT_EVENT_HF_CALL_HANDLING_EVENT, callback, user_data); + return BT_ERROR_NONE; +#else + BT_ERR("NOT_SUPPORTED(0x%08x)", BT_ERROR_NOT_SUPPORTED); + return BT_ERROR_NOT_SUPPORTED; +#endif +} + +int bt_hf_unset_call_handling_event_cb(void) +{ +#ifdef TIZEN_AUDIO_HF_SUPPORT + BT_CHECK_INIT_STATUS(); + if (_bt_check_cb(BT_EVENT_HF_CALL_HANDLING_EVENT) == true) + _bt_unset_cb(BT_EVENT_HF_CALL_HANDLING_EVENT); + return BT_ERROR_NONE; +#else + BT_ERR("NOT_SUPPORTED(0x%08x)", BT_ERROR_NOT_SUPPORTED); + return BT_ERROR_NOT_SUPPORTED; +#endif +} + +int bt_hf_set_multi_call_handling_event_cb( + bt_hf_multi_call_handling_event_cb callback, + void *user_data) +{ +#ifdef TIZEN_AUDIO_HF_SUPPORT + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(callback); + _bt_set_cb(BT_EVENT_HF_MULTI_CALL_HANDLING_EVENT, callback, user_data); + return BT_ERROR_NONE; +#else + BT_ERR("NOT_SUPPORTED(0x%08x)", BT_ERROR_NOT_SUPPORTED); + return BT_ERROR_NOT_SUPPORTED; +#endif +} + +int bt_hf_unset_multi_call_handling_event_cb(void) +{ +#ifdef TIZEN_AUDIO_HF_SUPPORT + BT_CHECK_INIT_STATUS(); + if (_bt_check_cb(BT_EVENT_HF_MULTI_CALL_HANDLING_EVENT) == true) + _bt_unset_cb(BT_EVENT_HF_MULTI_CALL_HANDLING_EVENT); + return BT_ERROR_NONE; +#else + BT_ERR("NOT_SUPPORTED(0x%08x)", BT_ERROR_NOT_SUPPORTED); + return BT_ERROR_NOT_SUPPORTED; +#endif +} +#endif diff --git a/src/bluetooth-avrcp.c b/src/bluetooth-avrcp.c index b20a5c5..d737a10 100644 --- a/src/bluetooth-avrcp.c +++ b/src/bluetooth-avrcp.c @@ -21,10 +21,54 @@ #include "bluetooth_private.h" #include "bluetooth-audio-api.h" #include "bluetooth-media-control.h" -#ifdef LOG_TAG -#undef LOG_TAG + +static bool is_avrcp_target_initialized = false; +static bool is_avrcp_control_initialized = false; + +#ifdef TIZEN_AVRCP_DISABLE +#define BT_CHECK_AVRCP_SUPPORT() \ + { \ + BT_CHECK_BT_SUPPORT(); \ + LOGE("[%s] NOT_SUPPORTED(0x%08x)", __FUNCTION__, BT_ERROR_NOT_SUPPORTED); \ + return BT_ERROR_NOT_SUPPORTED; \ + } +#else +#define BT_CHECK_AVRCP_SUPPORT() #endif -#define LOG_TAG "TIZEN_N_BLUETOOTH" + +#define BT_CHECK_AVRCP_TARGET_INIT_STATUS() \ + if (__bt_check_avrcp_target_init_status() == BT_ERROR_NOT_INITIALIZED) \ + { \ + LOGE("[%s] NOT_INITIALIZED(0x%08x)", __FUNCTION__, BT_ERROR_NOT_INITIALIZED); \ + return BT_ERROR_NOT_INITIALIZED; \ + } + +int __bt_check_avrcp_target_init_status(void) +{ + if (is_avrcp_target_initialized != true) { + BT_ERR("NOT_INITIALIZED(0x%08x)", BT_ERROR_NOT_INITIALIZED); + return BT_ERROR_NOT_INITIALIZED; + } + + return BT_ERROR_NONE; +} + +#define BT_CHECK_AVRCP_CONTROL_INIT_STATUS() \ + if (__bt_check_avrcp_control_init_status() == BT_ERROR_NOT_INITIALIZED) \ + { \ + LOGE("[%s] NOT_INITIALIZED(0x%08x)", __FUNCTION__, BT_ERROR_NOT_INITIALIZED); \ + return BT_ERROR_NOT_INITIALIZED; \ + } + +int __bt_check_avrcp_control_init_status(void) +{ + if (is_avrcp_control_initialized != true) { + BT_ERR("NOT_INITIALIZED(0x%08x)", BT_ERROR_NOT_INITIALIZED); + return BT_ERROR_NOT_INITIALIZED; + } + + return BT_ERROR_NONE; +} /*The below API is just to conver the error from Audio API's to CAPI error codes, * this is temporary change and changes to proper error code will be done in @@ -38,6 +82,8 @@ int _bt_convert_avrcp_error_code(int error) return BT_ERROR_INVALID_PARAMETER; case BT_MEDIA_ERROR_ALREADY_INITIALIZED: return BT_ERROR_OPERATION_FAILED; + case BT_MEDIA_ERROR_NOT_CONNECTED: + return BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED; default: return BT_ERROR_NONE; } @@ -47,6 +93,7 @@ int bt_avrcp_target_initialize(bt_avrcp_target_connection_state_changed_cb callb { int error; + BT_CHECK_AVRCP_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(callback); _bt_set_cb(BT_EVENT_AVRCP_CONNECTION_STATUS, callback, user_data); @@ -54,17 +101,21 @@ int bt_avrcp_target_initialize(bt_avrcp_target_connection_state_changed_cb callb error = _bt_convert_avrcp_error_code(error); error = _bt_get_error_code(error); if (BT_ERROR_NONE != error) { - LOGE("[%s] %s(0x%08x)", __FUNCTION__, - _bt_convert_error_to_string(error), error); + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error), error); + return error; } - return error; + + is_avrcp_target_initialized = true; + return BT_ERROR_NONE; } int bt_avrcp_target_deinitialize(void) { int error; + BT_CHECK_AVRCP_SUPPORT(); BT_CHECK_INIT_STATUS(); + BT_CHECK_AVRCP_TARGET_INIT_STATUS(); if (_bt_check_cb(BT_EVENT_AVRCP_CONNECTION_STATUS) == true) _bt_unset_cb(BT_EVENT_AVRCP_CONNECTION_STATUS); @@ -73,35 +124,41 @@ int bt_avrcp_target_deinitialize(void) error = _bt_get_error_code(error); if (BT_ERROR_NONE != error) { - LOGE("[%s] %s(0x%08x)", __FUNCTION__, - _bt_convert_error_to_string(error), error); + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error), error); + return error; } - return error; + + is_avrcp_target_initialized = false; + return BT_ERROR_NONE; } int bt_avrcp_target_notify_equalizer_state(bt_avrcp_equalizer_state_e state) { int error; + + BT_CHECK_AVRCP_SUPPORT(); BT_CHECK_INIT_STATUS(); - error = bluetooth_media_player_change_property(EQUILIZER, state); + BT_CHECK_AVRCP_TARGET_INIT_STATUS(); + error = bluetooth_media_player_change_property(EQUALIZER, state); error = _bt_convert_avrcp_error_code(error); error = _bt_get_error_code(error); if (BT_ERROR_NONE != error) { - LOGE("[%s] %s(0x%08x)", __FUNCTION__, - _bt_convert_error_to_string(error), error); + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error), error); } return error; } int bt_avrcp_target_notify_repeat_mode(bt_avrcp_repeat_mode_e mode) { int error; + + BT_CHECK_AVRCP_SUPPORT(); BT_CHECK_INIT_STATUS(); + BT_CHECK_AVRCP_TARGET_INIT_STATUS(); error = bluetooth_media_player_change_property(REPEAT, mode); error = _bt_convert_avrcp_error_code(error); error = _bt_get_error_code(error); if (BT_ERROR_NONE != error) { - LOGE("[%s] %s(0x%08x)", __FUNCTION__, - _bt_convert_error_to_string(error), error); + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error), error); } return error; } @@ -109,26 +166,30 @@ int bt_avrcp_target_notify_repeat_mode(bt_avrcp_repeat_mode_e mode) int bt_avrcp_target_notify_shuffle_mode(bt_avrcp_shuffle_mode_e mode) { int error; + + BT_CHECK_AVRCP_SUPPORT(); BT_CHECK_INIT_STATUS(); + BT_CHECK_AVRCP_TARGET_INIT_STATUS(); error = bluetooth_media_player_change_property(SHUFFLE, mode); error = _bt_convert_avrcp_error_code(error); error = _bt_get_error_code(error); if (BT_ERROR_NONE != error) { - LOGE("[%s] %s(0x%08x)", __FUNCTION__, - _bt_convert_error_to_string(error), error); + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error), error); } return error; } int bt_avrcp_target_notify_scan_mode(bt_avrcp_scan_mode_e mode) { int error; + + BT_CHECK_AVRCP_SUPPORT(); BT_CHECK_INIT_STATUS(); + BT_CHECK_AVRCP_TARGET_INIT_STATUS(); error = bluetooth_media_player_change_property(SCAN, mode); error = _bt_convert_avrcp_error_code(error); error = _bt_get_error_code(error); if (BT_ERROR_NONE != error) { - LOGE("[%s] %s(0x%08x)", __FUNCTION__, - _bt_convert_error_to_string(error), error); + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error), error); } return error; } @@ -136,13 +197,15 @@ int bt_avrcp_target_notify_scan_mode(bt_avrcp_scan_mode_e mode) int bt_avrcp_target_notify_player_state(bt_avrcp_player_state_e state) { int error; + + BT_CHECK_AVRCP_SUPPORT(); BT_CHECK_INIT_STATUS(); + BT_CHECK_AVRCP_TARGET_INIT_STATUS(); error = bluetooth_media_player_change_property(STATUS, state); error = _bt_convert_avrcp_error_code(error); error = _bt_get_error_code(error); if (BT_ERROR_NONE != error) { - LOGE("[%s] %s(0x%08x)", __FUNCTION__, - _bt_convert_error_to_string(error), error); + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error), error); } return error; } @@ -150,13 +213,15 @@ int bt_avrcp_target_notify_player_state(bt_avrcp_player_state_e state) int bt_avrcp_target_notify_position(unsigned int position) { int error; + + BT_CHECK_AVRCP_SUPPORT(); BT_CHECK_INIT_STATUS(); + BT_CHECK_AVRCP_TARGET_INIT_STATUS(); error = bluetooth_media_player_change_property(POSITION, position); error = _bt_convert_avrcp_error_code(error); error = _bt_get_error_code(error); if (BT_ERROR_NONE != error) { - LOGE("[%s] %s(0x%08x)", __FUNCTION__, - _bt_convert_error_to_string(error), error); + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error), error); } return error; } @@ -165,7 +230,10 @@ int bt_avrcp_target_notify_track(const char *title, const char *artist, const ch const char *genre, unsigned int track_num, unsigned int total_tracks, unsigned int duration) { int error; + + BT_CHECK_AVRCP_SUPPORT(); BT_CHECK_INIT_STATUS(); + BT_CHECK_AVRCP_TARGET_INIT_STATUS(); media_metadata_attributes_t metadata; metadata.title = title; metadata.artist = artist; @@ -178,8 +246,426 @@ int bt_avrcp_target_notify_track(const char *title, const char *artist, const ch error = _bt_convert_avrcp_error_code(error); error = _bt_get_error_code(error); if (BT_ERROR_NONE != error) { - LOGE("[%s] %s(0x%08x)", __FUNCTION__, - _bt_convert_error_to_string(error), error); + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error), error); + } + return error; +} + +int bt_avrcp_control_initialize(bt_avrcp_control_connection_state_changed_cb callback, + void *user_data) +{ + int error; + + BT_CHECK_AVRCP_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(callback); + _bt_set_cb(BT_EVENT_AVRCP_CONNECTION_STATUS, callback, user_data); + error = bluetooth_media_control_init(_bt_avrcp_event_proxy, NULL); + error = _bt_convert_avrcp_error_code(error); + error = _bt_get_error_code(error); + if (BT_ERROR_NONE != error) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error), error); + return error; + } + + is_avrcp_control_initialized = true; + return BT_ERROR_NONE; +} + +int bt_avrcp_control_deinitialize(void) +{ + int error; + + BT_CHECK_AVRCP_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_AVRCP_CONTROL_INIT_STATUS(); + if (_bt_check_cb(BT_EVENT_AVRCP_CONNECTION_STATUS) == true) + _bt_unset_cb(BT_EVENT_AVRCP_CONNECTION_STATUS); + + error = bluetooth_media_control_deinit(); + error = _bt_convert_avrcp_error_code(error); + + error = _bt_get_error_code(error); + if (BT_ERROR_NONE != error) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error), error); + return error; + } + + is_avrcp_control_initialized = false; + return BT_ERROR_NONE; +} + +int bt_avrcp_control_connect(const char *remote_address) +{ + int error; + bluetooth_device_address_t addr_hex = { {0,} }; + + BT_CHECK_AVRCP_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_AVRCP_CONTROL_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(remote_address); + _bt_convert_address_to_hex(&addr_hex, remote_address); + + error = bluetooth_media_control_connect(&addr_hex); + error = _bt_get_error_code(error); + if (error != BT_ERROR_NONE) + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error), error); + + return error; +} + +int bt_avrcp_control_disconnect(const char *remote_address) +{ + int error; + bluetooth_device_address_t addr_hex = { {0,} }; + + BT_CHECK_AVRCP_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_AVRCP_CONTROL_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(remote_address); + _bt_convert_address_to_hex(&addr_hex, remote_address); + + error = bluetooth_media_control_disconnect(&addr_hex); + error = _bt_get_error_code(error); + if (error != BT_ERROR_NONE) + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error), error); + + return error; +} + +int bt_avrcp_control_send_player_command(bt_avrcp_player_command_e cmd) +{ + int error; + + BT_CHECK_AVRCP_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_AVRCP_CONTROL_INIT_STATUS(); + error = bluetooth_media_control_command(cmd); + error = _bt_convert_avrcp_error_code(error); + error = _bt_get_error_code(error); + if (BT_ERROR_NONE != error) + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error), error); + + return error; +} + +int bt_avrcp_control_set_equalizer_state(bt_avrcp_equalizer_state_e state) +{ + int error; + + BT_CHECK_AVRCP_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_AVRCP_CONTROL_INIT_STATUS(); + error = bluetooth_media_control_set_property(EQUALIZER, state); + error = _bt_convert_avrcp_error_code(error); + error = _bt_get_error_code(error); + if (BT_ERROR_NONE != error) + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error), error); + + return error; +} + +int bt_avrcp_control_get_equalizer_state(bt_avrcp_equalizer_state_e *state) +{ + int error; + + BT_CHECK_AVRCP_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_AVRCP_CONTROL_INIT_STATUS(); + error = bluetooth_media_control_get_property(EQUALIZER, state); + error = _bt_convert_avrcp_error_code(error); + error = _bt_get_error_code(error); + if (BT_ERROR_NONE != error) + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error), error); + + return error; +} + +int bt_avrcp_control_set_repeat_mode(bt_avrcp_repeat_mode_e mode) +{ + int error; + + BT_CHECK_AVRCP_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_AVRCP_CONTROL_INIT_STATUS(); + error = bluetooth_media_control_set_property(REPEAT, mode); + error = _bt_convert_avrcp_error_code(error); + error = _bt_get_error_code(error); + if (BT_ERROR_NONE != error) + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error), error); + + return error; +} + +int bt_avrcp_control_get_repeat_mode(bt_avrcp_repeat_mode_e *mode) +{ + int error; + + BT_CHECK_AVRCP_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_AVRCP_CONTROL_INIT_STATUS(); + error = bluetooth_media_control_get_property(REPEAT, mode); + error = _bt_convert_avrcp_error_code(error); + error = _bt_get_error_code(error); + if (BT_ERROR_NONE != error) + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error), error); + + return error; +} + +int bt_avrcp_control_set_shuffle_mode(bt_avrcp_shuffle_mode_e mode) +{ + int error; + + BT_CHECK_AVRCP_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_AVRCP_CONTROL_INIT_STATUS(); + error = bluetooth_media_control_set_property(SHUFFLE, mode); + error = _bt_convert_avrcp_error_code(error); + error = _bt_get_error_code(error); + if (BT_ERROR_NONE != error) + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error), error); + + return error; +} + +int bt_avrcp_control_get_shuffle_mode(bt_avrcp_shuffle_mode_e *mode) +{ + int error; + + BT_CHECK_AVRCP_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_AVRCP_CONTROL_INIT_STATUS(); + error = bluetooth_media_control_get_property(SHUFFLE, mode); + error = _bt_convert_avrcp_error_code(error); + error = _bt_get_error_code(error); + if (BT_ERROR_NONE != error) + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error), error); + + return error; +} +int bt_avrcp_control_set_scan_mode(bt_avrcp_scan_mode_e mode) +{ + int error; + + BT_CHECK_AVRCP_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_AVRCP_CONTROL_INIT_STATUS(); + error = bluetooth_media_control_set_property(SCAN, mode); + error = _bt_convert_avrcp_error_code(error); + error = _bt_get_error_code(error); + if (BT_ERROR_NONE != error) + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error), error); + + return error; +} + +int bt_avrcp_control_get_scan_mode(bt_avrcp_scan_mode_e *mode) +{ + int error; + + BT_CHECK_AVRCP_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_AVRCP_CONTROL_INIT_STATUS(); + error = bluetooth_media_control_get_property(SCAN, mode); + error = _bt_convert_avrcp_error_code(error); + error = _bt_get_error_code(error); + if (BT_ERROR_NONE != error) + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error), error); + + return error; +} + +int bt_avrcp_control_get_position(unsigned int *position) +{ + int error; + + BT_CHECK_AVRCP_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_AVRCP_CONTROL_INIT_STATUS(); + error = bluetooth_media_control_get_property(POSITION, position); + error = _bt_convert_avrcp_error_code(error); + error = _bt_get_error_code(error); + if (BT_ERROR_NONE != error) + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error), error); + + return error; +} + +int bt_avrcp_control_get_play_status(bt_avrcp_player_state_e *status) +{ + int error; + + BT_CHECK_AVRCP_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_AVRCP_CONTROL_INIT_STATUS(); + error = bluetooth_media_control_get_property(STATUS, status); + error = _bt_convert_avrcp_error_code(error); + error = _bt_get_error_code(error); + if (BT_ERROR_NONE != error) + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error), error); + + return error; +} + +int bt_avrcp_control_get_track_info(bt_avrcp_metadata_attributes_info_s **track) +{ + int error; + media_metadata_attributes_t metadata = {0,}; + bt_avrcp_metadata_attributes_info_s *tr_info; + + BT_CHECK_AVRCP_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_AVRCP_CONTROL_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(track); + error = bluetooth_media_control_get_track_info(&metadata); + error = _bt_convert_avrcp_error_code(error); + error = _bt_get_error_code(error); + if (BT_ERROR_NONE != error) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error), error); + } else { + tr_info = (bt_avrcp_metadata_attributes_info_s *)g_malloc0( + sizeof(bt_avrcp_metadata_attributes_info_s)); + tr_info->title = metadata.title; + tr_info->artist = metadata.artist; + tr_info->album = metadata.album; + tr_info->genre = metadata.genre; + tr_info->total_tracks = metadata.total_tracks; + tr_info->number = metadata.number; + tr_info->duration = metadata.duration; + *track = tr_info; } return error; } + +int bt_avrcp_control_free_track_info(bt_avrcp_metadata_attributes_info_s *track) +{ + BT_CHECK_AVRCP_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(track); + g_free((gpointer)track->title); + g_free((gpointer)track->artist); + g_free((gpointer)track->album); + g_free((gpointer)track->genre); + g_free((gpointer)track); + return BT_ERROR_NONE; +} + +int bt_avrcp_set_equalizer_state_changed_cb(bt_avrcp_equalizer_state_changed_cb callback, void *user_data) +{ + BT_CHECK_AVRCP_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(callback); + _bt_set_cb(BT_EVENT_AVRCP_EQUALIZER_STATE_CHANGED, callback, user_data); + return BT_ERROR_NONE; +} + +int bt_avrcp_unset_equalizer_state_changed_cb(void) +{ + BT_CHECK_AVRCP_SUPPORT(); + BT_CHECK_INIT_STATUS(); + _bt_unset_cb(BT_EVENT_AVRCP_EQUALIZER_STATE_CHANGED); + return BT_ERROR_NONE; +} + +int bt_avrcp_set_repeat_mode_changed_cb(bt_avrcp_repeat_mode_changed_cb callback, void *user_data) +{ + BT_CHECK_AVRCP_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(callback); + _bt_set_cb(BT_EVENT_AVRCP_REPEAT_MODE_CHANGED, callback, user_data); + return BT_ERROR_NONE; +} + +int bt_avrcp_unset_repeat_mode_changed_cb(void) +{ + BT_CHECK_AVRCP_SUPPORT(); + BT_CHECK_INIT_STATUS(); + _bt_unset_cb(BT_EVENT_AVRCP_REPEAT_MODE_CHANGED); + return BT_ERROR_NONE; +} + +int bt_avrcp_set_shuffle_mode_changed_cb(bt_avrcp_shuffle_mode_changed_cb callback, void *user_data) +{ + BT_CHECK_AVRCP_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(callback); + _bt_set_cb(BT_EVENT_AVRCP_SHUFFLE_MODE_CHANGED, callback, user_data); + return BT_ERROR_NONE; +} + +int bt_avrcp_unset_shuffle_mode_changed_cb(void) +{ + BT_CHECK_AVRCP_SUPPORT(); + BT_CHECK_INIT_STATUS(); + _bt_unset_cb(BT_EVENT_AVRCP_SHUFFLE_MODE_CHANGED); + return BT_ERROR_NONE; +} + +int bt_avrcp_set_scan_mode_changed_cb(bt_avrcp_scan_mode_changed_cb callback, void *user_data) +{ + BT_CHECK_AVRCP_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(callback); + _bt_set_cb(BT_EVENT_AVRCP_SCAN_MODE_CHANGED, callback, user_data); + return BT_ERROR_NONE; +} + +int bt_avrcp_unset_scan_mode_changed_cb(void) +{ + BT_CHECK_AVRCP_SUPPORT(); + BT_CHECK_INIT_STATUS(); + _bt_unset_cb(BT_EVENT_AVRCP_SCAN_MODE_CHANGED); + return BT_ERROR_NONE; +} + +int bt_avrcp_set_song_position_changed_cb(bt_avrcp_song_position_changed_cb callback, void *user_data) +{ + BT_CHECK_AVRCP_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(callback); + _bt_set_cb(BT_EVENT_AVRCP_SONG_POSITION_CHANGED, callback, user_data); + return BT_ERROR_NONE; +} + +int bt_avrcp_unset_song_position_changed_cb(void) +{ + BT_CHECK_AVRCP_SUPPORT(); + BT_CHECK_INIT_STATUS(); + _bt_unset_cb(BT_EVENT_AVRCP_SONG_POSITION_CHANGED); + return BT_ERROR_NONE; +} + +int bt_avrcp_set_play_status_changed_cb(bt_avrcp_play_status_changed_cb callback, void *user_data) +{ + BT_CHECK_AVRCP_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(callback); + _bt_set_cb(BT_EVENT_AVRCP_PLAY_STATUS_CHANGED, callback, user_data); + return BT_ERROR_NONE; +} + +int bt_avrcp_unset_play_status_changed_cb(void) +{ + BT_CHECK_AVRCP_SUPPORT(); + BT_CHECK_INIT_STATUS(); + _bt_unset_cb(BT_EVENT_AVRCP_PLAY_STATUS_CHANGED); + return BT_ERROR_NONE; +} + +int bt_avrcp_set_track_info_changed_cb(bt_avrcp_track_info_changed_cb callback, void *user_data) +{ + BT_CHECK_AVRCP_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(callback); + _bt_set_cb(BT_EVENT_AVRCP_TRACK_INFO_CHANGED, callback, user_data); + return BT_ERROR_NONE; +} + +int bt_avrcp_unset_track_info_changed_cb(void) +{ + BT_CHECK_AVRCP_SUPPORT(); + BT_CHECK_INIT_STATUS(); + _bt_unset_cb(BT_EVENT_AVRCP_TRACK_INFO_CHANGED); + return BT_ERROR_NONE; +} diff --git a/src/bluetooth-common.c b/src/bluetooth-common.c index c531dd1..81e6778 100644 --- a/src/bluetooth-common.c +++ b/src/bluetooth-common.c @@ -24,56 +24,37 @@ #include #include "bluetooth.h" +#include "bluetooth_internal.h" #include "bluetooth_private.h" #include "bluetooth-media-control.h" -#ifdef LOG_TAG -#undef LOG_TAG -#endif -#define LOG_TAG "TIZEN_N_BLUETOOTH" +#include "bluetooth-telephony-api.h" static bool is_initialized = false; -static bt_event_sig_event_slot_s bt_event_slot_container[] = { - {BT_EVENT_STATE_CHANGED, NULL, NULL}, - {BT_EVENT_NAME_CHANGED, NULL, NULL}, - {BT_EVENT_VISIBILITY_MODE_CHANGED, NULL, NULL}, - {BT_EVENT_DEVICE_DISCOVERY_STATE_CHANGED, NULL, NULL}, - {BT_EVENT_BOND_CREATED, NULL, NULL}, - {BT_EVENT_BOND_DESTROYED, NULL, NULL}, - {BT_EVENT_AUTHORIZATION_CHANGED, NULL, NULL}, - {BT_EVENT_SERVICE_SEARCHED, NULL, NULL}, - {BT_EVENT_DATA_RECEIVED, NULL, NULL}, - {BT_EVENT_CONNECTION_STATE_CHANGED, NULL, NULL}, - {BT_EVENT_RFCOMM_CONNECTION_REQUESTED, NULL, NULL}, - {BT_EVENT_OPP_CONNECTION_REQUESTED, NULL, NULL}, - {BT_EVENT_OPP_PUSH_REQUESTED, NULL, NULL}, - {BT_EVENT_OPP_SERVER_TRANSFER_PROGRESS, NULL, NULL}, - {BT_EVENT_OPP_SERVER_TRANSFER_FINISHED, NULL, NULL}, - {BT_EVENT_OPP_CLIENT_PUSH_RESPONSED, NULL, NULL}, - {BT_EVENT_OPP_CLIENT_PUSH_PROGRESS, NULL, NULL}, - {BT_EVENT_OPP_CLIENT_PUSH_FINISHED, NULL, NULL}, - {BT_EVENT_PAN_CONNECTION_STATE_CHANGED, NULL, NULL}, - {BT_EVENT_NAP_CONNECTION_STATE_CHANGED, NULL, NULL}, - {BT_EVENT_HDP_CONNECTED, NULL, NULL}, - {BT_EVENT_HDP_DISCONNECTED, NULL, NULL}, - {BT_EVENT_HDP_DATA_RECIEVED, NULL, NULL}, - {BT_EVENT_AUDIO_CONNECTION_STATUS, NULL, NULL}, - {BT_EVENT_AG_MICROPHONE_GAIN_CHANGE, NULL, NULL}, - {BT_EVENT_AG_MICROPHONE_GAIN_CHANGE, NULL, NULL}, - {BT_EVENT_AVRCP_CONNECTION_STATUS, NULL, NULL}, - {BT_EVENT_HID_CONNECTION_STATUS, NULL, NULL} -}; +static bool is_le_initialized = false; + +static bt_event_sig_event_slot_s bt_event_slot_container[BT_EVENT_MAX] = { {NULL, NULL}, }; /* * Internal Functions */ static void __bt_event_proxy(int event, bluetooth_event_param_t * param, void *user_data); +static void __bt_le_event_proxy(int event, bluetooth_event_param_t *param, void *user_data); static int __bt_get_cb_index(int event); static void __bt_convert_lower_to_upper(char *origin); static int __bt_get_bt_device_sdp_info_s(bt_device_sdp_info_s **dest, bt_sdp_info_t *source); static void __bt_free_bt_device_sdp_info_s(bt_device_sdp_info_s *sdp_info); +static int __bt_get_bt_device_connection_info_s(bt_device_connection_info_s **dest, bt_connection_info_t *source); +static void __bt_free_bt_device_connection_info_s(bt_device_connection_info_s *conn_info); static int __bt_get_bt_adapter_device_discovery_info_s(bt_adapter_device_discovery_info_s **discovery_info, bluetooth_device_info_t *source_info); static void __bt_free_bt_adapter_device_discovery_info_s(bt_adapter_device_discovery_info_s *discovery_info); - +static int __bt_get_bt_adapter_le_device_scan_info_s(bt_adapter_le_device_scan_result_info_s **scan_info, bluetooth_le_device_info_t *source_info); +static void __bt_free_bt_adapter_le_device_scan_info_s(bt_adapter_le_device_scan_result_info_s *scan_info); +#ifndef TIZEN_WEARABLE +static int __bt_get_bt_adapter_le_device_discovery_info_s(bt_adapter_le_device_discovery_info_s **le_discovery_info, bluetooth_le_device_info_t *source_info); +static void __bt_free_bt_adapter_le_device_discovery_info_s(bt_adapter_le_device_discovery_info_s *discovery_info); +#endif +static int __bt_gatt_client_update_characteristics(bt_gatt_handle_info_t char_handles, bt_gatt_service_s *service); +static int __bt_gatt_client_update_descriptors(bt_gatt_handle_info_t desc_handles, bt_gatt_characteristic_s *characteristic); /* * Public Functions @@ -81,9 +62,10 @@ static void __bt_free_bt_adapter_device_discovery_info_s(bt_adapter_device_disco int bt_initialize(void) { + BT_CHECK_BT_SUPPORT(); if (is_initialized != true) { if (bluetooth_register_callback(&__bt_event_proxy, NULL) != BLUETOOTH_ERROR_NONE) { - LOGE("[%s] OPERATION_FAILED(0x%08x)", __FUNCTION__, BT_ERROR_OPERATION_FAILED); + BT_ERR("OPERATION_FAILED(0x%08x)", BT_ERROR_OPERATION_FAILED); return BT_ERROR_OPERATION_FAILED; } is_initialized = true; @@ -94,9 +76,10 @@ int bt_initialize(void) int bt_deinitialize(void) { + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); if (bluetooth_unregister_callback() != BLUETOOTH_ERROR_NONE) { - LOGE("[%s] OPERATION_FAILED(0x%08x)", __FUNCTION__, BT_ERROR_OPERATION_FAILED); + BT_ERR("OPERATION_FAILED(0x%08x)", BT_ERROR_OPERATION_FAILED); return BT_ERROR_OPERATION_FAILED; } is_initialized = false; @@ -104,15 +87,13 @@ int bt_deinitialize(void) return BT_ERROR_NONE; } - /* * Common Functions */ int _bt_check_init_status(void) { - if (is_initialized != true) - { - LOGE("[%s] NOT_INITIALIZED(0x%08x)", __FUNCTION__, BT_ERROR_NOT_INITIALIZED); + if (is_initialized != true) { + BT_ERR("NOT_INITIALIZED(0x%08x)", BT_ERROR_NOT_INITIALIZED); return BT_ERROR_NOT_INITIALIZED; } @@ -138,6 +119,39 @@ bool _bt_check_cb(int events) return (bt_event_slot_container[events].callback != NULL) ? true : false; } +int _bt_le_adapter_init(void) +{ + if (is_le_initialized) + return BT_ERROR_NONE; + + if (bluetooth_le_register_callback(&__bt_le_event_proxy, NULL) != BLUETOOTH_ERROR_NONE) { + BT_ERR("OPERATION_FAILED(0x%08x)", BT_ERROR_OPERATION_FAILED); + return BT_ERROR_OPERATION_FAILED; + } + is_le_initialized = true; + + return BT_ERROR_NONE; +} + +int _bt_le_adapter_deinit(void) +{ + if (!is_le_initialized) { + BT_ERR("NOT_INITIALIZED(0x%08x)", BT_ERROR_NOT_INITIALIZED); + return BT_ERROR_NOT_INITIALIZED; + } + + if (!_bt_check_cb(BT_EVENT_LE_STATE_CHANGED) && + !_bt_check_cb(BT_EVENT_LE_DEVICE_DISCOVERY_STATE_CHANGED)) { + if (bluetooth_le_unregister_callback() != BLUETOOTH_ERROR_NONE) { + BT_ERR("OPERATION_FAILED(0x%08x)", BT_ERROR_OPERATION_FAILED); + return BT_ERROR_OPERATION_FAILED; + } + is_le_initialized = false; + } + + return BT_ERROR_NONE; +} + int _bt_get_error_code(int origin_error) { switch (origin_error) { @@ -146,8 +160,9 @@ int _bt_get_error_code(int origin_error) case BLUETOOTH_ERROR_INVALID_DATA: case BLUETOOTH_ERROR_INVALID_PARAM: case BLUETOOTH_ERROR_NOT_CONNECTED: - case BLUETOOTH_ERROR_NOT_SUPPORT: return BT_ERROR_INVALID_PARAMETER; + case BLUETOOTH_ERROR_NOT_SUPPORT: + return BT_ERROR_NOT_SUPPORTED; case BLUETOOTH_ERROR_MEMORY_ALLOCATION: case BLUETOOTH_ERROR_OUT_OF_MEMORY: return BT_ERROR_OUT_OF_MEMORY; @@ -156,6 +171,9 @@ int _bt_get_error_code(int origin_error) case BLUETOOTH_ERROR_DEVICE_NOT_ENABLED: return BT_ERROR_NOT_ENABLED; case BLUETOOTH_ERROR_DEVICE_ALREADY_ENABLED: + case BLUETOOTH_ERROR_ALREADY_INITIALIZED: + case BLUETOOTH_ERROR_AGENT_DOES_NOT_EXIST: + case BLUETOOTH_ERROR_ALREADY_DEACTIVATED: return BT_ERROR_ALREADY_DONE; case BLUETOOTH_ERROR_NOT_PAIRED: return BT_ERROR_REMOTE_DEVICE_NOT_BONDED; @@ -174,7 +192,12 @@ int _bt_get_error_code(int origin_error) return BT_ERROR_REMOTE_DEVICE_NOT_FOUND; case BLUETOOTH_ERROR_SERVICE_SEARCH_ERROR: return BT_ERROR_SERVICE_SEARCH_FAILED; + case BLUETOOTH_ERROR_PERMISSION_DEINED : + return BT_ERROR_PERMISSION_DENIED; case BLUETOOTH_ERROR_SERVICE_NOT_FOUND: + return BT_ERROR_SERVICE_NOT_FOUND; + case BLUETOOTH_ERROR_NOT_INITIALIZED: + return BT_ERROR_NOT_INITIALIZED; case BLUETOOTH_ERROR_PARING_FAILED: case BLUETOOTH_ERROR_MAX_CONNECTION: case BLUETOOTH_ERROR_ALREADY_CONNECT: @@ -219,7 +242,9 @@ int _bt_get_bt_device_info_s(bt_device_info_s **dest_dev, bluetooth_device_info_ (*dest_dev)->service_uuid = (char **)malloc(sizeof(char *) * source_dev->service_index); if ((*dest_dev)->service_uuid != NULL) { for (i = 0; i < source_dev->service_index; i++) { - (*dest_dev)->service_uuid[i] = strdup(source_dev->uuids[i]); + (*dest_dev)->service_uuid[i] = + g_strndup(source_dev->uuids[i], + BLUETOOTH_UUID_STRING_MAX - 1); if ((*dest_dev)->service_uuid[i] != NULL) { __bt_convert_lower_to_upper((*dest_dev)->service_uuid[i]); } @@ -230,9 +255,18 @@ int _bt_get_bt_device_info_s(bt_device_info_s **dest_dev, bluetooth_device_info_ } (*dest_dev)->service_count = source_dev->service_index; (*dest_dev)->is_bonded = (bool)source_dev->paired; - (*dest_dev)->is_connected = (bool)source_dev->connected; + (*dest_dev)->is_connected = source_dev->connected != BLUETOOTH_CONNECTED_LINK_NONE ? TRUE : FALSE; (*dest_dev)->is_authorized = (bool)source_dev->trust; + (*dest_dev)->manufacturer_data_len = source_dev->manufacturer_data.data_len; + if (source_dev->manufacturer_data.data_len > 0) { + (*dest_dev)->manufacturer_data = (char *)malloc(source_dev->manufacturer_data.data_len); + memcpy((*dest_dev)->manufacturer_data, source_dev->manufacturer_data.data, source_dev->manufacturer_data.data_len); + } else { + (*dest_dev)->manufacturer_data = (char *)malloc(1); + (*dest_dev)->manufacturer_data[0] = 0; + } + return BT_ERROR_NONE; } @@ -252,11 +286,14 @@ void _bt_free_bt_device_info_s(bt_device_info_s *device_info) if (device_info->service_uuid != NULL) { for (i = 0; i < device_info->service_count; i++) { if (device_info->service_uuid[i] != NULL) - free(device_info->service_uuid[i]); + g_free(device_info->service_uuid[i]); } free(device_info->service_uuid); } + if (device_info->manufacturer_data != NULL) + free(device_info->manufacturer_data); + free(device_info); device_info = NULL; } @@ -265,6 +302,8 @@ int _bt_convert_address_to_string(char **addr_str, bluetooth_device_address_t *a { char address[18] = { 0, }; + BT_CHECK_INPUT_PARAMETER(addr_hex); + snprintf(address, 18, "%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X", addr_hex->addr[0], addr_hex->addr[1], addr_hex->addr[2], addr_hex->addr[3], addr_hex->addr[4], addr_hex->addr[5]); *addr_str = strdup(address); @@ -280,9 +319,12 @@ void _bt_convert_address_to_hex(bluetooth_device_address_t *addr_hex, const char int i = 0; unsigned int addr[BLUETOOTH_ADDRESS_LENGTH] = { 0, }; + if (addr_str == NULL || addr_str[0] == '\0') + return; + i = sscanf(addr_str, "%X:%X:%X:%X:%X:%X", &addr[0], &addr[1], &addr[2], &addr[3], &addr[4], &addr[5]); if (i != BLUETOOTH_ADDRESS_LENGTH) { - LOGI("[%s] Invalid format string - %s", __FUNCTION__, addr_str); + BT_ERR("Invalid format string - [%s]", addr_str); } for (i = 0; i < BLUETOOTH_ADDRESS_LENGTH; i++) { @@ -325,6 +367,14 @@ char *_bt_convert_error_to_string(int error) return "REMOTE_DEVICE_NOT_FOUND"; case BT_ERROR_SERVICE_SEARCH_FAILED: return "SERVICE_SEARCH_FAILED"; + case BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED: + return "REMOTE_DEVICE_NOT_CONNECTED"; + case BT_ERROR_PERMISSION_DENIED: + return "PERMISSION_DENIED"; + case BT_ERROR_SERVICE_NOT_FOUND: + return "SERVICE_NOT_FOUND"; + case BT_ERROR_NOT_SUPPORTED: + return "NOT_SUPPORTD"; default: return "UNKNOWN"; } @@ -350,10 +400,11 @@ static int __bt_get_bt_device_sdp_info_s(bt_device_sdp_info_s **dest, bt_sdp_inf { int i = 0; - *dest = (bt_device_sdp_info_s *)malloc(sizeof(bt_device_sdp_info_s)); - if (*dest == NULL) { + *dest = (bt_device_sdp_info_s *)g_malloc0(sizeof(bt_device_sdp_info_s)); + + /* Fix : NULL_RETURNS */ + if (*dest == NULL) return BT_ERROR_OUT_OF_MEMORY; - } if (_bt_convert_address_to_string(&((*dest)->remote_address), &(source->device_addr)) != BT_ERROR_NONE) { __bt_free_bt_device_sdp_info_s(*dest); @@ -401,10 +452,90 @@ static void __bt_free_bt_device_sdp_info_s(bt_device_sdp_info_s *sdp_info) free(sdp_info->service_uuid); } - free(sdp_info); + g_free(sdp_info); sdp_info = NULL; } +static int __bt_get_bt_device_connection_info_s(bt_device_connection_info_s **dest, bt_connection_info_t *source) +{ + *dest = (bt_device_connection_info_s *)g_malloc0(sizeof(bt_device_connection_info_s)); + + /* Fix : NULL_RETURNS */ + if (*dest == NULL) + return BT_ERROR_OUT_OF_MEMORY; + + if (_bt_convert_address_to_string(&((*dest)->remote_address), &(source->device_addr)) != BT_ERROR_NONE) { + __bt_free_bt_device_connection_info_s(*dest); + return BT_ERROR_OUT_OF_MEMORY; + } + + switch (source->addr_type) { + case 0: + (*dest)->link = BT_DEVICE_CONNECTION_LINK_BREDR; + break; + case 1: + case 2: + (*dest)->link = BT_DEVICE_CONNECTION_LINK_LE; + break; + default: + (*dest)->link = BT_DEVICE_CONNECTION_LINK_BREDR; + break; + } + + (*dest)->disconn_reason = source->disc_reason; + + return BT_ERROR_NONE; +} + +static bt_gatt_server_read_value_requested_cb __bt_gatt_attribute_get_read_cb( + bt_gatt_h service, bt_gatt_h characteristic, void **user_data) +{ + gchar *svc_path = (gchar *)service; + gchar *chr_path = (gchar *)characteristic; + const GSList *gatt_server_list = NULL; + const GSList *l1, *l2, *l3; + + gatt_server_list = _bt_gatt_get_server_list(); + + for (l1 = gatt_server_list; l1 != NULL; l1 = l1->next) { + bt_gatt_server_s *serv = l1->data; + + if (!serv) + return NULL; + + for (l2 = serv->services; l2 != NULL; l2 = l2->next) { + bt_gatt_service_s *svc = l2->data; + + if (g_strcmp0(svc->path, svc_path) == 0) { + for (l3 = svc->characteristics; l3 != NULL; l3 = l3->next) { + bt_gatt_characteristic_s *chr = l3->data; + + if (chr && g_strcmp0(chr->path, chr_path) == 0) { + if (chr->read_requested_cb) { + *user_data = chr->read_requested_user_data; + return chr->read_requested_cb; + } else + return NULL; + } + } + } + } + } + return NULL; +} + +static void __bt_free_bt_device_connection_info_s(bt_device_connection_info_s *conn_info) +{ + if (conn_info == NULL) + return; + + if (conn_info->remote_address != NULL) + free(conn_info->remote_address); + + g_free(conn_info); + conn_info = NULL; +} + void _bt_audio_event_proxy(int event, bt_audio_event_param_t *param, void *user_data) { bluetooth_event_param_t new_param; @@ -415,6 +546,28 @@ void _bt_audio_event_proxy(int event, bt_audio_event_param_t *param, void *user_ __bt_event_proxy(event, &new_param, user_data); } +#ifdef TIZEN_WEARABLE +void _bt_hf_event_proxy(int event, bt_hf_event_param_t *param, void *user_data) +{ + bluetooth_event_param_t new_param; + new_param.event = param->event; + new_param.param_data = param->param_data; + new_param.result = param->result; + new_param.user_data = NULL; + __bt_event_proxy(event, &new_param, user_data); +} +#endif + +void _bt_telephony_event_proxy(int event, telephony_event_param_t *param, void *user_data) +{ + bluetooth_event_param_t new_param; + new_param.event = param->event; + new_param.param_data = param->param_data; + new_param.result = param->result; + new_param.user_data = NULL; + __bt_event_proxy(event, &new_param, user_data); +} + void _bt_avrcp_event_proxy(int event, media_event_param_t *param, void *user_data) { bluetooth_event_param_t new_param; @@ -437,10 +590,15 @@ void _bt_hid_event_proxy(int event, hid_event_param_t *param, void *user_data) static void __bt_event_proxy(int event, bluetooth_event_param_t *param, void *user_data) { + int call_id; + int *avrcp_mode; + int *discoverable_timeout; + int *adv_handle; bluetooth_rfcomm_connection_t *connection_ind = NULL; bluetooth_rfcomm_disconnection_t *disconnection_ind = NULL; bt_socket_connection_s rfcomm_connection; bt_device_sdp_info_s *sdp_info = NULL; + bt_device_connection_info_s *conn_info = NULL; bt_adapter_device_discovery_info_s *discovery_info = NULL; bt_device_info_s *bonded_device = NULL; bluetooth_rfcomm_connection_request_t *reqeust_ind = NULL; @@ -448,54 +606,102 @@ static void __bt_event_proxy(int event, bluetooth_event_param_t *param, void *us bt_obex_server_transfer_info_t *transfer_info = NULL; bt_opc_transfer_info_t *client_info = NULL; bluetooth_device_address_t *bd_addr = NULL; + telephony_event_callid_t *call_data = NULL; char *device_addr = NULL; +#ifdef TIZEN_WEARABLE + char *phone_number = NULL; +#endif int error_code = BT_ERROR_NONE; int event_index = -1; bluetooth_network_device_info_t *dev_info = NULL; bt_hdp_connected_t *hdp_conn_info = NULL; bt_hdp_disconnected_t *hdp_disconn_info = NULL; bt_hdp_data_ind_t *hdp_data_ind = NULL; + bt_gatt_char_value_t *char_val = NULL; + media_metadata_attributes_t *metadata = NULL; event_index = __bt_get_cb_index(event); - if (event_index == -1 || bt_event_slot_container[event_index].callback == NULL) { - return; + + if (event == BLUETOOTH_EVENT_GATT_CONNECTED) { + const GSList *clients = NULL; + const GSList *l = NULL; + int ret; + + _bt_convert_address_to_string(&device_addr, + (bluetooth_device_address_t *)(param->param_data)); + + clients = _bt_gatt_get_client_list(); + for (l = clients; l; l = g_slist_next(l)) { + bt_gatt_client_s *client_s = l->data; + + if (!g_strcmp0(client_s->remote_address, device_addr)) { + if (client_s->services_discovered == false) { + BT_INFO("Matched GATT Client is found"); + ret = _bt_gatt_client_update_all((bt_gatt_client_h)l->data); + if (ret != BT_ERROR_NONE) + BT_ERR("bluetooth_gatt_get_primary_services is failed"); + else + client_s->services_discovered = true; + } + break; + } + } + g_free(device_addr); + device_addr = NULL; } + if (event == BLUETOOTH_EVENT_GATT_SERVER_CHARACTERISTIC_VALUE_CHANGED || + event == BLUETOOTH_EVENT_ADVERTISING_STARTED || event == BLUETOOTH_EVENT_ADVERTISING_STOPPED) + BT_INFO("NOT use bt_event_slot_container"); + else if (event_index == -1 || bt_event_slot_container[event_index].callback == NULL) + return; + memset(&rfcomm_connection, 0x00, sizeof(bt_socket_connection_s)); switch (event) { case BLUETOOTH_EVENT_ENABLED: - LOGI("[%s] bt_adapter_state_changed_cb() will be called with BT_ADAPTER_ENABLED", __FUNCTION__); + BT_INFO("bt_adapter_state_changed_cb() will be called with BT_ADAPTER_ENABLED"); ((bt_adapter_state_changed_cb) bt_event_slot_container[event_index].callback) (_bt_get_error_code(param->result), BT_ADAPTER_ENABLED, bt_event_slot_container[event_index].user_data); break; case BLUETOOTH_EVENT_DISABLED: - LOGI("[%s] bt_adapter_state_changed_cb() will be called with BT_ADAPTER_DISABLED", __FUNCTION__); + BT_INFO("bt_adapter_state_changed_cb() will be called with BT_ADAPTER_DISABLED"); ((bt_adapter_state_changed_cb) bt_event_slot_container[event_index].callback) (_bt_get_error_code(param->result), BT_ADAPTER_DISABLED, bt_event_slot_container[event_index].user_data); break; case BLUETOOTH_EVENT_LOCAL_NAME_CHANGED: - LOGI("[%s] bt_adapter_name_changed_cb() will be called", __FUNCTION__); + BT_INFO("bt_adapter_name_changed_cb() will be called"); ((bt_adapter_name_changed_cb)bt_event_slot_container[event_index].callback) ((char *)(param->param_data), bt_event_slot_container[event_index].user_data); break; case BLUETOOTH_EVENT_DISCOVERABLE_MODE_CHANGED: - LOGI("[%s] bt_adapter_visibility_mode_changed_cb() will be called", __FUNCTION__); + BT_INFO("bt_adapter_visibility_mode_changed_cb() will be called"); ((bt_adapter_visibility_mode_changed_cb)bt_event_slot_container[event_index].callback) (_bt_get_error_code(param->result), _bt_get_bt_visibility_mode_e(*(bt_adapter_visibility_mode_e *)(param->param_data)), bt_event_slot_container[event_index].user_data); break; + case BLUETOOTH_EVENT_DISCOVERABLE_TIMEOUT_CHANGED: + BT_INFO("bt_adapter_visibility_duration_changed_cb() will be called"); + discoverable_timeout = (int *)(param->param_data); + ((bt_adapter_visibility_duration_changed_cb)bt_event_slot_container[event_index].callback) + (*discoverable_timeout, bt_event_slot_container[event_index].user_data); + break; + case BLUETOOTH_EVENT_CONNECTABLE_CHANGED: + BT_INFO("bt_adapter_connectable_changed_cb() will be called"); + ((bt_adapter_connectable_changed_cb)bt_event_slot_container[event_index].callback) + (_bt_get_error_code(param->result), *(bool *)(param->param_data), bt_event_slot_container[event_index].user_data); + break; case BLUETOOTH_EVENT_DISCOVERY_STARTED: - LOGI("[%s] bt_adapter_device_discovery_state_changed_cb() will be called with BT_ADAPTER_DEVICE_DISCOVERY_STARTED", __FUNCTION__); + BT_INFO("bt_adapter_device_discovery_state_changed_cb() will be called with BT_ADAPTER_DEVICE_DISCOVERY_STARTED"); ((bt_adapter_device_discovery_state_changed_cb) bt_event_slot_container[event_index].callback) (_bt_get_error_code(param->result), BT_ADAPTER_DEVICE_DISCOVERY_STARTED, NULL, bt_event_slot_container[event_index].user_data); break; case BLUETOOTH_EVENT_DISCOVERY_FINISHED: - LOGI("[%s] bt_adapter_device_discovery_state_changed_cb() will be called with BT_ADAPTER_DEVICE_DISCOVERY_FINISHED", __FUNCTION__); + BT_INFO("bt_adapter_device_discovery_state_changed_cb() will be called with BT_ADAPTER_DEVICE_DISCOVERY_FINISHED"); ((bt_adapter_device_discovery_state_changed_cb)bt_event_slot_container[event_index].callback) (_bt_get_error_code(param->result), BT_ADAPTER_DEVICE_DISCOVERY_FINISHED, NULL, bt_event_slot_container[event_index].user_data); break; case BLUETOOTH_EVENT_REMOTE_DEVICE_NAME_UPDATED: - LOGI("[%s] bt_adapter_device_discovery_state_changed_cb() will be called with BT_ADAPTER_DEVICE_DISCOVERY_FOUND", __FUNCTION__); + BT_INFO("bt_adapter_device_discovery_state_changed_cb() will be called with BT_ADAPTER_DEVICE_DISCOVERY_FOUND"); if (__bt_get_bt_adapter_device_discovery_info_s(&discovery_info, (bluetooth_device_info_t *)(param->param_data)) == BT_ERROR_NONE) { ((bt_adapter_device_discovery_state_changed_cb)bt_event_slot_container[event_index].callback) (_bt_get_error_code(param->result), BT_ADAPTER_DEVICE_DISCOVERY_FOUND, discovery_info, bt_event_slot_container[event_index].user_data); @@ -506,7 +712,7 @@ static void __bt_event_proxy(int event, bluetooth_event_param_t *param, void *us } break; case BLUETOOTH_EVENT_BONDING_FINISHED: - LOGI("[%s] bt_device_bond_created_cb() will be called", __FUNCTION__); + BT_INFO("bt_device_bond_created_cb() will be called"); _bt_get_bt_device_info_s(&bonded_device, (bluetooth_device_info_t *)(param->param_data)); ((bt_device_bond_created_cb)bt_event_slot_container[event_index].callback) @@ -515,7 +721,7 @@ static void __bt_event_proxy(int event, bluetooth_event_param_t *param, void *us bonded_device = NULL; break; case BLUETOOTH_EVENT_BONDED_DEVICE_REMOVED: - LOGI("[%s] bt_device_bond_destroyed_cb() will be called", __FUNCTION__); + BT_INFO("bt_device_bond_destroyed_cb() will be called"); _bt_convert_address_to_string(&device_addr, (bluetooth_device_address_t *)(param->param_data)); ((bt_device_bond_destroyed_cb)bt_event_slot_container[event_index].callback) (_bt_get_error_code(param->result), device_addr, bt_event_slot_container[event_index].user_data); @@ -524,25 +730,37 @@ static void __bt_event_proxy(int event, bluetooth_event_param_t *param, void *us device_addr = NULL; break; case BLUETOOTH_EVENT_DEVICE_AUTHORIZED: - LOGI("[%s] bt_device_authorization_changed_cb() will be called with BT_DEVICE_AUTHORIZED", __FUNCTION__); + BT_INFO("bt_device_authorization_changed_cb() will be called with BT_DEVICE_AUTHORIZED"); _bt_convert_address_to_string(&device_addr, (bluetooth_device_address_t *)(param->param_data)); ((bt_device_authorization_changed_cb)bt_event_slot_container[event_index].callback) (BT_DEVICE_AUTHORIZED, device_addr, bt_event_slot_container[event_index].user_data); if (device_addr != NULL) free(device_addr); - device_addr = NULL; break; case BLUETOOTH_EVENT_DEVICE_UNAUTHORIZED: - LOGI("[%s] bt_device_authorization_changed_cb() will be called with BT_DEVICE_UNAUTHORIZED", __FUNCTION__); + BT_INFO("bt_device_authorization_changed_cb() will be called with BT_DEVICE_UNAUTHORIZED"); _bt_convert_address_to_string(&device_addr, (bluetooth_device_address_t *)(param->param_data)); ((bt_device_authorization_changed_cb)bt_event_slot_container[event_index].callback) (BT_DEVICE_UNAUTHORIZED, device_addr, bt_event_slot_container[event_index].user_data); if (device_addr != NULL) free(device_addr); - device_addr = NULL; + break; + case BLUETOOTH_EVENT_DEVICE_CONNECTED: + BT_INFO("bt_device_connection_state_changed_cb() will be called"); + __bt_get_bt_device_connection_info_s(&conn_info, (bt_connection_info_t *)(param->param_data)); + ((bt_device_connection_state_changed_cb)bt_event_slot_container[event_index].callback) + (true, conn_info, bt_event_slot_container[event_index].user_data); + __bt_free_bt_device_connection_info_s(conn_info); + break; + case BLUETOOTH_EVENT_DEVICE_DISCONNECTED: + BT_INFO("bt_device_connection_state_changed_cb() will be called"); + __bt_get_bt_device_connection_info_s(&conn_info, (bt_connection_info_t *)(param->param_data)); + ((bt_device_connection_state_changed_cb)bt_event_slot_container[event_index].callback) + (false, conn_info, bt_event_slot_container[event_index].user_data); + __bt_free_bt_device_connection_info_s(conn_info); break; case BLUETOOTH_EVENT_SERVICE_SEARCHED: - LOGI("[%s] bt_device_service_searched_cb() will be called", __FUNCTION__); + BT_INFO("bt_device_service_searched_cb() will be called"); __bt_get_bt_device_sdp_info_s(&sdp_info, (bt_sdp_info_t *)(param->param_data)); error_code = _bt_get_error_code(param->result); // In service search, BT_ERROR_SERVICE_SEARCH_FAILED is returned instead of BT_ERROR_OPERATION_FAILED. @@ -553,27 +771,32 @@ static void __bt_event_proxy(int event, bluetooth_event_param_t *param, void *us __bt_free_bt_device_sdp_info_s(sdp_info); break; case BLUETOOTH_EVENT_RFCOMM_DATA_RECEIVED: - LOGI("[%s] bt_socket_data_received_cb() will be called", __FUNCTION__); + /*BT_INFO("bt_socket_data_received_cb() will be * called"); */ ((bt_socket_data_received_cb)bt_event_slot_container[event_index].callback) ((bt_socket_received_data_s *)(param->param_data), bt_event_slot_container[event_index].user_data); break; case BLUETOOTH_EVENT_RFCOMM_CONNECTED: - LOGI("[%s] bt_socket_connection_state_changed_cb() will be called with BT_SOCKET_CONNECTED", __FUNCTION__); + BT_INFO("bt_socket_connection_state_changed_cb() will be called with BT_SOCKET_CONNECTED"); if (param->result == BLUETOOTH_ERROR_INVALID_PARAM) error_code = BT_ERROR_OPERATION_FAILED; else error_code = _bt_get_error_code(param->result); connection_ind = (bluetooth_rfcomm_connection_t *)(param->param_data); - rfcomm_connection.socket_fd = connection_ind->socket_fd; - rfcomm_connection.local_role = connection_ind->device_role; - if (connection_ind->uuid) { - rfcomm_connection.service_uuid = strdup(connection_ind->uuid); - LOGI("uuid: [%s]", rfcomm_connection.service_uuid); - } + if (connection_ind) { + rfcomm_connection.socket_fd = connection_ind->socket_fd; + rfcomm_connection.local_role = connection_ind->device_role; + rfcomm_connection.server_fd = connection_ind->server_id; + + if (strlen(connection_ind->uuid) > 0) { + rfcomm_connection.service_uuid = strdup(connection_ind->uuid); + BT_INFO("uuid: [%s]", rfcomm_connection.service_uuid); + } - _bt_convert_address_to_string(&(rfcomm_connection.remote_address), &(connection_ind->device_addr)); + _bt_convert_address_to_string(&(rfcomm_connection.remote_address), + &(connection_ind->device_addr)); + } ((bt_socket_connection_state_changed_cb)bt_event_slot_container[event_index].callback) (error_code, BT_SOCKET_CONNECTED, &rfcomm_connection, bt_event_slot_container[event_index].user_data); @@ -590,18 +813,23 @@ static void __bt_event_proxy(int event, bluetooth_event_param_t *param, void *us break; case BLUETOOTH_EVENT_RFCOMM_DISCONNECTED: - LOGI("[%s] bt_socket_connection_state_changed_cb() will be called with BT_SOCKET_DISCONNECTED", __FUNCTION__); + BT_INFO("bt_socket_connection_state_changed_cb() will be called with BT_SOCKET_DISCONNECTED"); disconnection_ind = (bluetooth_rfcomm_disconnection_t *)(param->param_data); - rfcomm_connection.socket_fd = disconnection_ind->socket_fd; - rfcomm_connection.local_role = disconnection_ind->device_role; - if (disconnection_ind->uuid) { - rfcomm_connection.service_uuid = strdup(disconnection_ind->uuid); - LOGI("uuid: [%s]", rfcomm_connection.service_uuid); + if (disconnection_ind) { + rfcomm_connection.socket_fd = disconnection_ind->socket_fd; + rfcomm_connection.local_role = disconnection_ind->device_role; + + if (strlen(disconnection_ind->uuid) > 0) { + rfcomm_connection.service_uuid = strdup(disconnection_ind->uuid); + BT_INFO("uuid: [%s]", rfcomm_connection.service_uuid); + } + + _bt_convert_address_to_string(&(rfcomm_connection.remote_address), + &(disconnection_ind->device_addr)); } - _bt_convert_address_to_string(&(rfcomm_connection.remote_address), &(disconnection_ind->device_addr)); ((bt_socket_connection_state_changed_cb)bt_event_slot_container[event_index].callback) (_bt_get_error_code(param->result), BT_SOCKET_DISCONNECTED, &rfcomm_connection, bt_event_slot_container[event_index].user_data); @@ -617,7 +845,7 @@ static void __bt_event_proxy(int event, bluetooth_event_param_t *param, void *us break; case BLUETOOTH_EVENT_RFCOMM_AUTHORIZE: - LOGI("[%s] bt_socket_connection_requested_cb() will be called", __FUNCTION__); + BT_INFO("bt_socket_connection_requested_cb() will be called"); reqeust_ind = (bluetooth_rfcomm_connection_request_t *)(param->param_data); _bt_convert_address_to_string(&device_addr, &(reqeust_ind->device_addr)); ((bt_socket_connection_requested_cb)bt_event_slot_container[event_index].callback) @@ -627,7 +855,7 @@ static void __bt_event_proxy(int event, bluetooth_event_param_t *param, void *us free(device_addr); break; case BLUETOOTH_EVENT_OBEX_SERVER_CONNECTION_AUTHORIZE: - LOGI("[%s] bt_opp_server_connection_requested_cb() will be called", __FUNCTION__); + BT_INFO("bt_opp_server_connection_requested_cb() will be called"); bd_addr = (bluetooth_device_address_t *)(param->param_data); _bt_convert_address_to_string(&device_addr, bd_addr); ((bt_opp_server_connection_requested_cb)bt_event_slot_container[event_index].callback) @@ -637,28 +865,28 @@ static void __bt_event_proxy(int event, bluetooth_event_param_t *param, void *us free(device_addr); break; case BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_AUTHORIZE: - LOGI("[%s] bt_opp_server_push_requested_cb() will be called", __FUNCTION__); + BT_INFO("bt_opp_server_push_requested_cb() will be called"); auth_info = (bt_obex_server_authorize_into_t *)(param->param_data); ((bt_opp_server_push_requested_cb)bt_event_slot_container[event_index].callback) (auth_info->filename, auth_info->length, bt_event_slot_container[event_index].user_data); break; case BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_STARTED: - LOGI("[%s] bt_opp_server_transfer_started_cb() will be called", __FUNCTION__); + BT_INFO("bt_opp_server_transfer_started_cb() will be called"); transfer_info = (bt_obex_server_transfer_info_t *)(param->param_data); ((bt_opp_server_transfer_progress_cb)bt_event_slot_container[event_index].callback) (transfer_info->filename, transfer_info->file_size, 0, bt_event_slot_container[event_index].user_data); break; case BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_PROGRESS: - LOGI("[%s] bt_opp_server_transfer_in_progress_cb() will be called", __FUNCTION__); + BT_INFO("bt_opp_server_transfer_in_progress_cb() will be called"); transfer_info = (bt_obex_server_transfer_info_t *)(param->param_data); ((bt_opp_server_transfer_progress_cb)bt_event_slot_container[event_index].callback) (transfer_info->filename, transfer_info->file_size, transfer_info->percentage, bt_event_slot_container[event_index].user_data); break; case BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_COMPLETED: - LOGI("[%s] bt_opp_server_transfer_completed_cb() will be called", __FUNCTION__); + BT_INFO("bt_opp_server_transfer_completed_cb() will be called"); transfer_info = (bt_obex_server_transfer_info_t *)(param->param_data); ((bt_opp_server_transfer_finished_cb)bt_event_slot_container[event_index].callback) @@ -667,115 +895,129 @@ static void __bt_event_proxy(int event, bluetooth_event_param_t *param, void *us break; case BLUETOOTH_EVENT_OPC_CONNECTED: - LOGI("[%s] bt_opp_client_push_responded_cb() will be called", __FUNCTION__); + BT_INFO("bt_opp_client_push_responded_cb() will be called"); bd_addr = (bluetooth_device_address_t *)(param->param_data); _bt_convert_address_to_string(&device_addr, bd_addr); - LOGI("address: %s", device_addr); - ((bt_opp_client_push_responded_cb)bt_event_slot_container[event_index].callback) (_bt_get_error_code(param->result), device_addr, bt_event_slot_container[event_index].user_data); + + if (device_addr != NULL) + free(device_addr); break; case BLUETOOTH_EVENT_OPC_DISCONNECTED: - LOGI("[%s] bt_opp_client_push_finished_cb() will be called", __FUNCTION__); + BT_INFO("bt_opp_client_push_finished_cb() will be called"); bd_addr = (bluetooth_device_address_t *)(param->param_data); _bt_convert_address_to_string(&device_addr, bd_addr); - LOGI("address: %s", device_addr); - ((bt_opp_client_push_finished_cb)bt_event_slot_container[event_index].callback) (_bt_get_error_code(param->result), device_addr, bt_event_slot_container[event_index].user_data); + + if (device_addr != NULL) + free(device_addr); break; case BLUETOOTH_EVENT_OPC_TRANSFER_STARTED: - LOGI("[%s] bt_opp_client_transfer_started_cb() will be called", __FUNCTION__); - client_info = (bt_opc_transfer_info_t *)(param->param_data); - ((bt_opp_client_push_progress_cb)bt_event_slot_container[event_index].callback) - (client_info->filename, client_info->size, 0, bt_event_slot_container[event_index].user_data); + BT_INFO("BLUETOOTH_EVENT_OPC_TRANSFER_STARTED"); + /* This event don't be used in CAPI */ break; case BLUETOOTH_EVENT_OPC_TRANSFER_PROGRESS: - LOGI("[%s] bt_opp_client_transfer_in_progress_cb() will be called", __FUNCTION__); + BT_INFO("bt_opp_client_transfer_in_progress_cb() will be called"); client_info = (bt_opc_transfer_info_t *)(param->param_data); ((bt_opp_client_push_progress_cb)bt_event_slot_container[event_index].callback) (client_info->filename, client_info->size, client_info->percentage, bt_event_slot_container[event_index].user_data); break; case BLUETOOTH_EVENT_OPC_TRANSFER_COMPLETE: - LOGI("[%s] bt_opp_client_push_progress_cb() will be called", __FUNCTION__); - client_info = (bt_opc_transfer_info_t *)(param->param_data); - - if (param->result != BLUETOOTH_ERROR_NONE) { - LOGI("[%s] bt_opp_client_push_finished_cb() will be called", __FUNCTION__); - break; - } - - ((bt_opp_client_push_progress_cb)bt_event_slot_container[event_index].callback) - (client_info->filename, client_info->size, 100, bt_event_slot_container[event_index].user_data); + BT_INFO("BLUETOOTH_EVENT_OPC_TRANSFER_COMPLETE"); + /* This event don't be used in CAPI */ break; case BLUETOOTH_EVENT_NETWORK_SERVER_CONNECTED: - LOGI("[%s] BLUETOOTH_EVENT_NETWORK_SERVER_CONNECTED", __FUNCTION__); + BT_INFO("BLUETOOTH_EVENT_NETWORK_SERVER_CONNECTED"); dev_info = (bluetooth_network_device_info_t *)(param->param_data); if (param->result != BLUETOOTH_ERROR_NONE) { - LOGI("[%s]BLUETOOTH_EVENT_NETWORK_SERVER_CONNECTED", __FUNCTION__); + BT_ERR("Fail to connect the network server"); } _bt_convert_address_to_string(&device_addr, &dev_info->device_address); ((bt_nap_connection_state_changed_cb)bt_event_slot_container[event_index].callback) (TRUE, device_addr, dev_info->interface_name, bt_event_slot_container[event_index].user_data); + + if (device_addr != NULL) + free(device_addr); break; case BLUETOOTH_EVENT_NETWORK_SERVER_DISCONNECTED: - LOGI("[%s] BLUETOOTH_EVENT_NETWORK_SERVER_DISCONNECTED", __FUNCTION__); + BT_INFO("BLUETOOTH_EVENT_NETWORK_SERVER_DISCONNECTED"); dev_info = (bluetooth_network_device_info_t *)(param->param_data); if (param->result != BLUETOOTH_ERROR_NONE) { - LOGI("[%s]BLUETOOTH_EVENT_NETWORK_SERVER_DISCONNECTED", __FUNCTION__); + BT_ERR("Fail to disconnect the network server"); } _bt_convert_address_to_string(&device_addr, &dev_info->device_address); ((bt_nap_connection_state_changed_cb)bt_event_slot_container[event_index].callback) (FALSE, device_addr, dev_info->interface_name, bt_event_slot_container[event_index].user_data); + + if (device_addr != NULL) + free(device_addr); break; case BLUETOOTH_EVENT_NETWORK_DISCONNECTED: - LOGI("[%s] Network callback will be", __FUNCTION__); + BT_INFO("BLUETOOTH_EVENT_NETWORK_DISCONNECTED"); + bd_addr = (bluetooth_device_address_t *)(param->param_data); + _bt_convert_address_to_string(&device_addr, bd_addr); + ((bt_panu_connection_state_changed_cb)bt_event_slot_container[event_index].callback) - (_bt_get_error_code(param->result), FALSE, NULL, BLUETOOTH_NETWORK_NAP_ROLE, + (_bt_get_error_code(param->result), FALSE, device_addr, BLUETOOTH_NETWORK_NAP_ROLE, bt_event_slot_container[event_index].user_data); + if (device_addr != NULL) + free(device_addr); break; case BLUETOOTH_EVENT_NETWORK_CONNECTED: - LOGI("[%s] Network callback will be ", __FUNCTION__); + BT_INFO("BLUETOOTH_EVENT_NETWORK_CONNECTED"); + bd_addr = (bluetooth_device_address_t *)(param->param_data); + _bt_convert_address_to_string(&device_addr, bd_addr); + ((bt_panu_connection_state_changed_cb)bt_event_slot_container[event_index].callback) - (_bt_get_error_code(param->result), TRUE, NULL, BLUETOOTH_NETWORK_NAP_ROLE, + (_bt_get_error_code(param->result), TRUE, device_addr, BLUETOOTH_NETWORK_NAP_ROLE, bt_event_slot_container[event_index].user_data); + if (device_addr != NULL) + free(device_addr); break; case BLUETOOTH_EVENT_HDP_CONNECTED: - LOGI("[%s] HDP Connected ", __FUNCTION__); + BT_INFO("HDP Connected "); hdp_conn_info = (bt_hdp_connected_t *)(param->param_data); _bt_convert_address_to_string(&device_addr, &hdp_conn_info->device_address); ((bt_hdp_connected_cb)bt_event_slot_container[event_index].callback) (_bt_get_error_code(param->result), device_addr, hdp_conn_info->app_handle, hdp_conn_info->type, hdp_conn_info->channel_id, bt_event_slot_container[event_index].user_data); + + if (device_addr != NULL) + free(device_addr); break; case BLUETOOTH_EVENT_HDP_DISCONNECTED: - LOGI("[%s] HDP disconnected callback will be ", __FUNCTION__); + BT_INFO("HDP disconnected callback will be "); hdp_disconn_info = (bt_hdp_disconnected_t *)(param->param_data); _bt_convert_address_to_string(&device_addr, &hdp_disconn_info->device_address); ((bt_hdp_disconnected_cb)bt_event_slot_container[event_index].callback) (_bt_get_error_code(param->result), device_addr, hdp_disconn_info->channel_id, bt_event_slot_container[event_index].user_data); + + if (device_addr != NULL) + free(device_addr); break; case BLUETOOTH_EVENT_HDP_DATA_RECEIVED: - LOGI("[%s] HDP data recieved callback will be ", __FUNCTION__); + BT_INFO("HDP data recieved callback will be "); hdp_data_ind = (bt_hdp_data_ind_t *)(param->param_data); if (param->result != BLUETOOTH_ERROR_NONE) { - LOGI("[%s] BLUETOOTH_EVENT_HDP_DATA_RECEIVED will be called", __FUNCTION__); + BT_ERR("Fail to receive HDP data"); } ((bt_hdp_data_received_cb)bt_event_slot_container[event_index].callback) @@ -783,45 +1025,114 @@ static void __bt_event_proxy(int event, bluetooth_event_param_t *param, void *us bt_event_slot_container[event_index].user_data); break; case BLUETOOTH_EVENT_AG_CONNECTED: - LOGI("[%s] BLUETOOTH_EVENT_AG_CONNECTED ", __FUNCTION__); + BT_INFO("BLUETOOTH_EVENT_AG_CONNECTED "); device_addr = (char *)(param->param_data); ((bt_audio_connection_state_changed_cb)bt_event_slot_container[event_index].callback) (_bt_get_error_code(param->result), TRUE, device_addr, BT_AUDIO_PROFILE_TYPE_HSP_HFP, bt_event_slot_container[event_index].user_data); break; case BLUETOOTH_EVENT_AG_DISCONNECTED: - LOGI("[%s] BLUETOOTH_EVENT_AG_DISCONNECTED ", __FUNCTION__); + BT_INFO("BLUETOOTH_EVENT_AG_DISCONNECTED "); device_addr = (char *)(param->param_data); ((bt_audio_connection_state_changed_cb)bt_event_slot_container[event_index].callback) (_bt_get_error_code(param->result), FALSE, device_addr, BT_AUDIO_PROFILE_TYPE_HSP_HFP, bt_event_slot_container[event_index].user_data); break; + case BLUETOOTH_EVENT_TELEPHONY_AUDIO_CONNECTED: + BT_INFO("BLUETOOTH_EVENT_TELEPHONY_AUDIO_CONNECTED "); + ((bt_ag_sco_state_changed_cb)bt_event_slot_container[event_index].callback) + (_bt_get_error_code(param->result), TRUE, + bt_event_slot_container[event_index].user_data); + break; + case BLUETOOTH_EVENT_TELEPHONY_AUDIO_DISCONNECTED: + BT_INFO("BLUETOOTH_EVENT_TELEPHONY_AUDIO_DISCONNECTED "); + ((bt_ag_sco_state_changed_cb)bt_event_slot_container[event_index].callback) + (_bt_get_error_code(param->result), FALSE, + bt_event_slot_container[event_index].user_data); + break; + case BLUETOOTH_EVENT_TELEPHONY_ANSWER_CALL: + call_data = (telephony_event_callid_t *)param->param_data; + call_id = call_data->callid; + BT_INFO("BLUETOOTH_EVENT_TELEPHONY_ANSWER_CALL "); + ((bt_ag_call_handling_event_cb)bt_event_slot_container[event_index].callback) + (BT_AG_CALL_HANDLING_EVENT_ANSWER, call_id, + bt_event_slot_container[event_index].user_data); + break; + case BLUETOOTH_EVENT_TELEPHONY_RELEASE_CALL: + call_data = (telephony_event_callid_t *)param->param_data; + call_id = call_data->callid; + BT_INFO("BLUETOOTH_EVENT_TELEPHONY_RELEASE_CALL "); + ((bt_ag_call_handling_event_cb)bt_event_slot_container[event_index].callback) + (BT_AG_CALL_HANDLING_EVENT_RELEASE, call_id, + bt_event_slot_container[event_index].user_data); + break; + case BLUETOOTH_EVENT_TELEPHONY_REJECT_CALL: + call_data = (telephony_event_callid_t *)param->param_data; + call_id = call_data->callid; + BT_INFO("BLUETOOTH_EVENT_TELEPHONY_REJECT_CALL "); + ((bt_ag_call_handling_event_cb)bt_event_slot_container[event_index].callback) + (BT_AG_CALL_HANDLING_EVENT_REJECT, call_id, + bt_event_slot_container[event_index].user_data); + break; + case BLUETOOTH_EVENT_TELEPHONY_CHLD_0_RELEASE_ALL_HELD_CALL: + BT_INFO("BLUETOOTH_EVENT_TELEPHONY_CHLD_0_RELEASE_ALL_HELD_CALL "); + ((bt_ag_multi_call_handling_event_cb)bt_event_slot_container[event_index].callback) + (BT_AG_MULTI_CALL_HANDLING_EVENT_RELEASE_HELD_CALLS, + bt_event_slot_container[event_index].user_data); + break; + case BLUETOOTH_EVENT_TELEPHONY_CHLD_1_RELEASE_ALL_ACTIVE_CALL: + BT_INFO("BLUETOOTH_EVENT_TELEPHONY_CHLD_1_RELEASE_ALL_ACTIVE_CALL "); + ((bt_ag_multi_call_handling_event_cb)bt_event_slot_container[event_index].callback) + (BT_AG_MULTI_CALL_HANDLING_EVENT_RELEASE_ACTIVE_CALLS, + bt_event_slot_container[event_index].user_data); + break; + case BLUETOOTH_EVENT_TELEPHONY_CHLD_2_ACTIVE_HELD_CALL: + BT_INFO("BLUETOOTH_EVENT_TELEPHONY_CHLD_2_ACTIVE_HELD_CALL "); + ((bt_ag_multi_call_handling_event_cb)bt_event_slot_container[event_index].callback) + (BT_AG_MULTI_CALL_HANDLING_EVENT_ACTIVATE_HELD_CALL, + bt_event_slot_container[event_index].user_data); + break; + case BLUETOOTH_EVENT_TELEPHONY_CHLD_3_MERGE_CALL: + BT_INFO("BLUETOOTH_EVENT_TELEPHONY_CHLD_3_MERGE_CALL "); + ((bt_ag_multi_call_handling_event_cb)bt_event_slot_container[event_index].callback) + (BT_AG_MULTI_CALL_HANDLING_EVENT_MERGE_CALLS, + bt_event_slot_container[event_index].user_data); + break; + case BLUETOOTH_EVENT_TELEPHONY_CHLD_4_EXPLICIT_CALL_TRANSFER: + BT_INFO("BLUETOOTH_EVENT_TELEPHONY_CHLD_4_EXPLICIT_CALL_TRANSFER "); + ((bt_ag_multi_call_handling_event_cb)bt_event_slot_container[event_index].callback) + (BT_AG_MULTI_CALL_HANDLING_EVENT_EXPLICIT_CALL_TRANSFER, + bt_event_slot_container[event_index].user_data); + break; + case BLUETOOTH_EVENT_TELEPHONY_SEND_DTMF: { + telephony_event_dtmf_t *call_data = param->param_data; + + BT_INFO("BLUETOOTH_EVENT_TELEPHONY_SEND_DTMF "); + ((bt_ag_dtmf_transmitted_cb)bt_event_slot_container[event_index].callback) + (call_data->dtmf, bt_event_slot_container[event_index].user_data); + break; + } + case BLUETOOTH_EVENT_AG_SPEAKER_GAIN: - LOGI("[%s] BLUETOOTH_EVENT_AG_SPEAKER_GAIN", __FUNCTION__); + BT_INFO("BLUETOOTH_EVENT_AG_SPEAKER_GAIN"); int *spk_gain = (int *)(param->param_data); - if (param->result != BLUETOOTH_ERROR_NONE) { - LOGI("[%s] BLUETOOTH_EVENT_AG_SPEAKER_GAIN will be called", __FUNCTION__); - } ((bt_ag_speaker_gain_changed_cb)bt_event_slot_container[event_index].callback) - (NULL, *spk_gain, bt_event_slot_container[event_index].user_data); + (*spk_gain, bt_event_slot_container[event_index].user_data); break; case BLUETOOTH_EVENT_AG_MIC_GAIN: - LOGI("[%s] BLUETOOTH_EVENT_AG_MIC_GAIN", __FUNCTION__); + BT_INFO("BLUETOOTH_EVENT_AG_MIC_GAIN"); int *mik_gain = (int *)(param->param_data); - if (param->result != BLUETOOTH_ERROR_NONE) { - LOGI("[%s] BLUETOOTH_EVENT_AG_MIC_GAIN will be called", __FUNCTION__); - } ((bt_ag_microphone_gain_changed_cb)bt_event_slot_container[event_index].callback) - (NULL, *mik_gain , bt_event_slot_container[event_index].user_data); + (*mik_gain, bt_event_slot_container[event_index].user_data); break; case BLUETOOTH_EVENT_AG_AUDIO_CONNECTED: - LOGI("[%s] BLUETOOTH_EVENT_AG_AUDIO_CONNECTED", __FUNCTION__); + BT_INFO("BLUETOOTH_EVENT_AG_AUDIO_CONNECTED"); ((bt_audio_connection_state_changed_cb)bt_event_slot_container[event_index].callback) (_bt_get_error_code(param->result), TRUE, NULL, BT_AUDIO_PROFILE_TYPE_HSP_HFP, bt_event_slot_container[event_index].user_data); break; case BLUETOOTH_EVENT_AG_AUDIO_DISCONNECTED: - LOGI("[%s] BLUETOOTH_EVENT_AG_AUDIO_DISCONNECTED", __FUNCTION__); + BT_INFO("BLUETOOTH_EVENT_AG_AUDIO_DISCONNECTED"); device_addr = (char *)(param->param_data); ((bt_audio_connection_state_changed_cb)bt_event_slot_container[event_index].callback) @@ -829,71 +1140,717 @@ static void __bt_event_proxy(int event, bluetooth_event_param_t *param, void *us bt_event_slot_container[event_index].user_data); break; case BLUETOOTH_EVENT_AV_CONNECTED: - LOGI("[%s] BLUETOOTH_EVENT_AV_CONNECTED ", __FUNCTION__); + BT_INFO("BLUETOOTH_EVENT_AV_CONNECTED "); device_addr = (char *)(param->param_data); ((bt_audio_connection_state_changed_cb)bt_event_slot_container[event_index].callback) (_bt_get_error_code(param->result), TRUE, device_addr, BT_AUDIO_PROFILE_TYPE_A2DP, bt_event_slot_container[event_index].user_data); break; case BLUETOOTH_EVENT_AV_DISCONNECTED: - LOGI("[%s] BLUETOOTH_EVENT_Av_DISCONNECTED ", __FUNCTION__); + BT_INFO("BLUETOOTH_EVENT_Av_DISCONNECTED "); device_addr = (char *)(param->param_data); ((bt_audio_connection_state_changed_cb)bt_event_slot_container[event_index].callback) (_bt_get_error_code(param->result), FALSE, device_addr, BT_AUDIO_PROFILE_TYPE_A2DP, bt_event_slot_container[event_index].user_data); break; + case BLUETOOTH_EVENT_AVRCP_CONNECTED: + BT_INFO("BLUETOOTH_EVENT_AVRCP_CONNECTED "); + device_addr = (char *)(param->param_data); + ((bt_avrcp_target_connection_state_changed_cb)bt_event_slot_container[event_index].callback) + (TRUE, device_addr, bt_event_slot_container[event_index].user_data); + break; + case BLUETOOTH_EVENT_AVRCP_DISCONNECTED: + BT_INFO("BLUETOOTH_EVENT_AVRCP_DISCONNECTED "); + device_addr = (char *)(param->param_data); + ((bt_avrcp_target_connection_state_changed_cb)bt_event_slot_container[event_index].callback) + (FALSE, device_addr, bt_event_slot_container[event_index].user_data); + break; + case BLUETOOTH_EVENT_AVRCP_SETTING_SHUFFLE_STATUS: + BT_INFO("BLUETOOTH_EVENT_AVRCP_SETTING_SHUFFLE_STATUS "); + avrcp_mode = (int *)(param->param_data); + ((bt_avrcp_shuffle_mode_changed_cb)bt_event_slot_container[event_index].callback) + ((bt_avrcp_shuffle_mode_e)*avrcp_mode, bt_event_slot_container[event_index].user_data); + break; + case BLUETOOTH_EVENT_AVRCP_SETTING_EQUALIZER_STATUS: + BT_INFO("BLUETOOTH_EVENT_AVRCP_SETTING_EQUALIZER_STATUS "); + avrcp_mode = (int *)(param->param_data); + ((bt_avrcp_equalizer_state_changed_cb)bt_event_slot_container[event_index].callback) + ((bt_avrcp_equalizer_state_e)*avrcp_mode, bt_event_slot_container[event_index].user_data); + break; + case BLUETOOTH_EVENT_AVRCP_SETTING_REPEAT_STATUS: + BT_INFO("BLUETOOTH_EVENT_AVRCP_SETTING_REPEAT_STATUS "); + avrcp_mode = (int *)(param->param_data); + ((bt_avrcp_repeat_mode_changed_cb)bt_event_slot_container[event_index].callback) + ((bt_avrcp_repeat_mode_e)*avrcp_mode, bt_event_slot_container[event_index].user_data); + break; + case BLUETOOTH_EVENT_AVRCP_SETTING_SCAN_STATUS: + BT_INFO("BLUETOOTH_EVENT_AVRCP_SETTING_SCAN_STATUS "); + avrcp_mode = (int *)(param->param_data); + ((bt_avrcp_scan_mode_changed_cb)bt_event_slot_container[event_index].callback) + ((bt_avrcp_scan_mode_e)*avrcp_mode, bt_event_slot_container[event_index].user_data); + break; + case BLUETOOTH_EVENT_AVRCP_CONTROL_CONNECTED: + BT_INFO("BLUETOOTH_EVENT_AVRCP_CONTROL_CONNECTED "); + device_addr = (char *)(param->param_data); + ((bt_avrcp_target_connection_state_changed_cb)bt_event_slot_container[event_index].callback) + (TRUE, device_addr, bt_event_slot_container[event_index].user_data); + break; + case BLUETOOTH_EVENT_AVRCP_CONTROL_DISCONNECTED: + BT_INFO("BLUETOOTH_EVENT_AVRCP_CONTROL_DISCONNECTED "); + device_addr = (char *)(param->param_data); + ((bt_avrcp_target_connection_state_changed_cb)bt_event_slot_container[event_index].callback) + (FALSE, device_addr, bt_event_slot_container[event_index].user_data); + break; + case BLUETOOTH_EVENT_AVRCP_CONTROL_SHUFFLE_STATUS: + BT_INFO("BLUETOOTH_EVENT_AVRCP_CONTROL_SHUFFLE_STATUS "); + avrcp_mode = (int *)(param->param_data); + ((bt_avrcp_shuffle_mode_changed_cb)bt_event_slot_container[event_index].callback) + ((bt_avrcp_shuffle_mode_e)*avrcp_mode, bt_event_slot_container[event_index].user_data); + break; + case BLUETOOTH_EVENT_AVRCP_CONTROL_EQUALIZER_STATUS: + BT_INFO("BLUETOOTH_EVENT_AVRCP_CONTROL_EQUALIZER_STATUS "); + avrcp_mode = (int *)(param->param_data); + ((bt_avrcp_equalizer_state_changed_cb)bt_event_slot_container[event_index].callback) + ((bt_avrcp_equalizer_state_e)*avrcp_mode, bt_event_slot_container[event_index].user_data); + break; + case BLUETOOTH_EVENT_AVRCP_CONTROL_REPEAT_STATUS: + BT_INFO("BLUETOOTH_EVENT_AVRCP_CONTROL_REPEAT_STATUS "); + avrcp_mode = (int *)(param->param_data); + ((bt_avrcp_repeat_mode_changed_cb)bt_event_slot_container[event_index].callback) + ((bt_avrcp_repeat_mode_e)*avrcp_mode, bt_event_slot_container[event_index].user_data); + break; + case BLUETOOTH_EVENT_AVRCP_CONTROL_SCAN_STATUS: + BT_INFO("BLUETOOTH_EVENT_AVRCP_CONTROL_SCAN_STATUS "); + avrcp_mode = (int *)(param->param_data); + ((bt_avrcp_scan_mode_changed_cb)bt_event_slot_container[event_index].callback) + ((bt_avrcp_scan_mode_e)*avrcp_mode, bt_event_slot_container[event_index].user_data); + break; + case BLUETOOTH_EVENT_AVRCP_PLAY_STATUS_CHANGED: + BT_INFO("BLUETOOTH_EVENT_AVRCP_PLAY_STATUS_CHANGED "); + avrcp_mode = (int *)(param->param_data); + ((bt_avrcp_play_status_changed_cb)bt_event_slot_container[event_index].callback) + ((bt_avrcp_player_state_e)*avrcp_mode, bt_event_slot_container[event_index].user_data); + break; + case BLUETOOTH_EVENT_AVRCP_SONG_POSITION_STATUS: + BT_INFO("BLUETOOTH_EVENT_AVRCP_SONG_POSITION_STATUS "); + unsigned int *postion = (unsigned int *)(param->param_data); + ((bt_avrcp_song_position_changed_cb)bt_event_slot_container[event_index].callback) + (*postion, bt_event_slot_container[event_index].user_data); + break; + case BLUETOOTH_EVENT_AVRCP_TRACK_CHANGED: + BT_INFO("BLUETOOTH_EVENT_AVRCP_TRACK_CHANGED "); + bt_avrcp_metadata_attributes_info_s meta_info = {0, }; + metadata = (media_metadata_attributes_t *)(param->param_data); + meta_info.title = metadata->title; /* No need to allocate memory*/ + meta_info.artist = metadata->artist; /* No need to allocate memory*/ + meta_info.album = metadata->album; /* No need to allocate memory*/ + meta_info.genre = metadata->genre; /* No need to allocate memory*/ + meta_info.total_tracks = metadata->total_tracks; + meta_info.number = metadata->number; + meta_info.duration = metadata->duration; + ((bt_avrcp_track_info_changed_cb)bt_event_slot_container[event_index].callback) + (&meta_info, bt_event_slot_container[event_index].user_data); + break; case BLUETOOTH_HID_CONNECTED: - LOGI("[%s] BLUETOOTH_HID_CONNECTED", __FUNCTION__); + BT_INFO("BLUETOOTH_HID_CONNECTED"); bd_addr = (bluetooth_device_address_t *)(param->param_data); _bt_convert_address_to_string(&device_addr, bd_addr); ((bt_hid_host_connection_state_changed_cb)bt_event_slot_container[event_index].callback) (_bt_get_error_code(param->result), TRUE, device_addr, bt_event_slot_container[event_index].user_data); + + if (device_addr != NULL) + free(device_addr); break; case BLUETOOTH_HID_DISCONNECTED: - LOGI("[%s] BLUETOOTH_HID_DISCONNECTED", __FUNCTION__); + BT_INFO("BLUETOOTH_HID_DISCONNECTED"); bd_addr = (bluetooth_device_address_t *)(param->param_data); _bt_convert_address_to_string(&device_addr, bd_addr); ((bt_hid_host_connection_state_changed_cb)bt_event_slot_container[event_index].callback) (_bt_get_error_code(param->result), FALSE, device_addr, bt_event_slot_container[event_index].user_data); + + if (device_addr != NULL) + free(device_addr); break; - default: + case BLUETOOTH_EVENT_GATT_CONNECTED: + BT_INFO("BLUETOOTH_EVENT_GATT_CONNECTED"); + bd_addr = (bluetooth_device_address_t *)(param->param_data); + _bt_convert_address_to_string(&device_addr, bd_addr); + ((bt_gatt_connection_state_changed_cb)bt_event_slot_container[event_index].callback) + (_bt_get_error_code(param->result), TRUE, device_addr, + bt_event_slot_container[event_index].user_data); + break; + case BLUETOOTH_EVENT_GATT_DISCONNECTED: + BT_INFO("BLUETOOTH_EVENT_GATT_DISCONNECTED"); + bd_addr = (bluetooth_device_address_t *)(param->param_data); + _bt_convert_address_to_string(&device_addr, bd_addr); + ((bt_gatt_connection_state_changed_cb)bt_event_slot_container[event_index].callback) + (_bt_get_error_code(param->result), FALSE, device_addr, + bt_event_slot_container[event_index].user_data); + break; +#ifdef BT_ENABLE_LEGACY_GATT_CLIENT + case BLUETOOTH_EVENT_GATT_SVC_CHAR_DISCOVERED: { + BT_INFO("BLUETOOTH_EVENT_GATT_SVC_CHAR_DISCOVERED"); + if (_bt_gatt_is_legacy_client_mode()) { + bt_gatt_discovered_char_t *svc_char = param->param_data; + int i; + + if (svc_char == NULL) + return; + for (i = 1; i <= svc_char->handle_info.count; i++) { + ((bt_gatt_characteristics_discovered_cb)bt_event_slot_container[event_index].callback) + (_bt_get_error_code(param->result), i, svc_char->handle_info.count, svc_char->handle_info.handle[i-1], + bt_event_slot_container[event_index].user_data); + } + _bt_unset_cb(BT_EVENT_GATT_CLIENT_CHARACTERISTIC_DISCOVERED_LEGACY); + } break; } -} +#endif + case BLUETOOTH_EVENT_GATT_CHAR_VAL_CHANGED: + BT_INFO("BLUETOOTH_EVENT_GATT_CHAR_VAL_CHANGED"); + char_val = (bt_gatt_char_value_t *)(param->param_data); + +#ifdef BT_ENABLE_LEGACY_GATT_CLIENT + if (_bt_gatt_is_legacy_client_mode()) { + bt_gatt_char_value_t *char_val = param->param_data; + + if (char_val == NULL) + return; + ((bt_gatt_characteristic_changed_cb)bt_event_slot_container[event_index].callback) + (char_val->char_handle, char_val->char_value, char_val->val_len, + bt_event_slot_container[event_index].user_data); + break; + } +#endif + if (char_val == NULL) + return; -static int __bt_get_bt_adapter_device_discovery_info_s(bt_adapter_device_discovery_info_s **discovery_info, bluetooth_device_info_t *source_info) { - int i; + ((_bt_gatt_client_value_changed_cb)bt_event_slot_container[event_index].callback) + (char_val->char_handle, char_val->char_value, char_val->val_len, + bt_event_slot_container[event_index].user_data); - BT_CHECK_INPUT_PARAMETER(source_info); + break; + case BLUETOOTH_EVENT_GATT_READ_CHAR: { + int ret; + bt_gatt_client_request_completed_cb cb = bt_event_slot_container[event_index].callback; + bt_gatt_client_cb_data_s *cb_data = bt_event_slot_container[event_index].user_data; - *discovery_info = (bt_adapter_device_discovery_info_s *)malloc(sizeof(bt_adapter_device_discovery_info_s)); - if (*discovery_info == NULL) { - return BT_ERROR_OUT_OF_MEMORY; - } + BT_INFO("BLUETOOTH_EVENT_GATT_READ_CHAR"); - if (strlen(source_info->device_name.name) > 0) { - (*discovery_info)->remote_name = strdup(source_info->device_name.name); - } else { - (*discovery_info)->remote_name = NULL; - } +#ifdef BT_ENABLE_LEGACY_GATT_CLIENT + if (_bt_gatt_is_legacy_client_mode()) { + bt_gatt_char_value_t *char_val = param->param_data; - _bt_convert_address_to_string(&((*discovery_info)->remote_address), &(source_info->device_address)); + ((bt_gatt_characteristic_read_cb)bt_event_slot_container[event_index].callback) + (char_val->char_value, char_val->val_len, + bt_event_slot_container[event_index].user_data); + _bt_unset_cb(BT_EVENT_GATT_CLIENT_READ_CHARACTERISTIC_LEGACY); + break; + } +#endif + _bt_unset_cb(BT_EVENT_GATT_CLIENT_READ_CHARACTERISTIC); + ret = _bt_get_error_code(param->result); + if (ret == BT_ERROR_NONE) { + char_val = (bt_gatt_char_value_t *)(param->param_data); + bt_gatt_set_value(cb_data->gatt_handle, + (char *)char_val->char_value, (int)char_val->val_len); + } + cb(ret, cb_data->gatt_handle, cb_data->user_data); + g_free(cb_data); - (*discovery_info)->bt_class.major_device_class = source_info->device_class.major_class; - (*discovery_info)->bt_class.minor_device_class = source_info->device_class.minor_class; - (*discovery_info)->bt_class.major_service_class_mask = source_info->device_class.service_class; + break; + } + case BLUETOOTH_EVENT_GATT_WRITE_CHAR: { + int ret; + bt_gatt_client_request_completed_cb cb = bt_event_slot_container[event_index].callback; + bt_gatt_client_cb_data_s *cb_data = bt_event_slot_container[event_index].user_data; - if (source_info->service_index > 0) { - (*discovery_info)->service_uuid = (char **)malloc(sizeof(char *) * source_info->service_index); - if ((*discovery_info)->service_uuid != NULL) { - for (i = 0; i < source_info->service_index; i++) { - (*discovery_info)->service_uuid[i] = strdup(source_info->uuids[i]); - if ((*discovery_info)->service_uuid[i] != NULL) { - __bt_convert_lower_to_upper((*discovery_info)->service_uuid[i]); - } + BT_INFO("BLUETOOTH_EVENT_GATT_WRITE_CHAR"); - LOGI("[%s] UUID: %s", __FUNCTION__, (*discovery_info)->service_uuid[i]); - } +#ifdef BT_ENABLE_LEGACY_GATT_CLIENT + if (_bt_gatt_is_legacy_client_mode()) { + ((bt_gatt_characteristic_write_cb)bt_event_slot_container[event_index].callback) + (bt_event_slot_container[event_index].user_data); + + _bt_unset_cb(BT_EVENT_GATT_CLIENT_WRITE_CHARACTERISTIC_LEGACY); + break; + } +#endif + _bt_unset_cb(BT_EVENT_GATT_CLIENT_WRITE_CHARACTERISTIC); + ret = _bt_get_error_code(param->result); + cb(ret, cb_data->gatt_handle, cb_data->user_data); + g_free(cb_data); + + break; + } + case BLUETOOTH_EVENT_GATT_READ_DESC: { + int ret; + bt_gatt_client_request_completed_cb cb = bt_event_slot_container[event_index].callback; + bt_gatt_client_cb_data_s *cb_data = bt_event_slot_container[event_index].user_data; + bt_gatt_char_property_t *desc_val = NULL; + + BT_INFO("BLUETOOTH_EVENT_GATT_READ_DESC"); + + _bt_unset_cb(BT_EVENT_GATT_CLIENT_READ_DESCRIPTOR); + ret = _bt_get_error_code(param->result); + if (ret == BT_ERROR_NONE) { + desc_val = (bt_gatt_char_property_t *)(param->param_data); + bt_gatt_set_value(cb_data->gatt_handle, + desc_val->description, (int)desc_val->val_len); + } + cb(ret, cb_data->gatt_handle, cb_data->user_data); + g_free(cb_data); + + break; + } + case BLUETOOTH_EVENT_GATT_WRITE_DESC: { + int ret; + bt_gatt_client_request_completed_cb cb = bt_event_slot_container[event_index].callback; + bt_gatt_client_cb_data_s *cb_data = bt_event_slot_container[event_index].user_data; + + BT_INFO("BLUETOOTH_EVENT_GATT_WRITE_DESC"); + + _bt_unset_cb(BT_EVENT_GATT_CLIENT_WRITE_DESCRIPTOR); + ret = _bt_get_error_code(param->result); + cb(ret, cb_data->gatt_handle, cb_data->user_data); + g_free(cb_data); + + break; + } + case BLUETOOTH_EVENT_GATT_SERVER_READ_REQUESTED: { + bt_gatt_read_req_t *read_req = param->param_data; + bt_gatt_server_read_value_requested_cb cb; + void *user_data = NULL; + cb = __bt_gatt_attribute_get_read_cb(read_req->service_handle, + read_req->char_handle, &user_data); + + BT_INFO("BLUETOOTH_EVENT_GATT_SERVER_READ_REQUESTED"); + if (cb == NULL) + return; + + cb(read_req->address, read_req->req_id, read_req->service_handle, + read_req->char_handle, read_req->offset, + user_data); + break; + } +#ifdef BT_ENABLE_LEGACY_GATT_CLIENT + case BLUETOOTH_EVENT_GATT_SVC_CHAR_DESC_DISCOVERED: { + BT_INFO("BLUETOOTH_EVENT_GATT_SVC_CHAR_DESC_DISCOVERED"); + if (_bt_gatt_is_legacy_client_mode()) { + bt_gatt_char_property_t *char_desc = param->param_data; + + if (char_desc == NULL) + return; + ((bt_gatt_characteristic_descriptor_discovered_cb) + bt_event_slot_container[event_index].callback)(_bt_get_error_code(param->result), + char_desc->format.format, char_desc->val_len, char_desc->description, + bt_event_slot_container[event_index].user_data); + _bt_unset_cb(BT_EVENT_GATT_CLIENT_CHARACTERISTIC_DESCRIPTOR_DISCOVERED_LEGACY); + } + break; + } +#endif + case BLUETOOTH_EVENT_GATT_SERVER_CHARACTERISTIC_VALUE_CHANGED: { + const GSList *server_list = NULL; + BT_INFO("BLUETOOTH_EVENT_GATT_SERVER_CHARACTERISTIC_VALUE_CHANGED"); + + char_val = (bt_gatt_char_value_t *)(param->param_data); + + if (char_val == NULL) + return; + + for (server_list = _bt_gatt_get_server_list() ; server_list; server_list = g_slist_next(server_list)) { + bt_gatt_server_s *serv = (bt_gatt_server_s*)server_list->data; + GSList *service_list = NULL; + + for (service_list = serv->services; service_list; service_list = g_slist_next(service_list)) { + bt_gatt_service_s *svc = (bt_gatt_service_s*)service_list->data; + GSList *char_list = NULL; + + for (char_list = svc->characteristics; char_list; char_list = g_slist_next(char_list)) { + bt_gatt_characteristic_s *chr = (bt_gatt_characteristic_s*)char_list->data; + if (chr->path && strcmp(char_val->char_handle, chr->path) == 0) { + g_free(chr->value); + chr->value = NULL; + if (char_val->val_len > 0) + chr->value = g_memdup(char_val->char_value, char_val->val_len); + chr->value_length = char_val->val_len; + /* TODO : Fix build error temporary */ + if (chr->server_value_changed_cb) + chr->server_value_changed_cb(NULL, (bt_gatt_server_h)serv, (bt_gatt_h)chr, + 0, (char*)char_val->char_value, char_val->val_len, + chr->server_value_changed_user_data); + } + } + } + } + break; + } + case BLUETOOTH_EVENT_ADVERTISING_STARTED: + BT_INFO("BLUETOOTH_EVENT_ADVERTISING_STARTED"); + adv_handle = (int *)(param->param_data); + + if (bt_event_slot_container[event_index].callback != NULL) { + ((bt_adapter_le_advertising_state_changed_cb)bt_event_slot_container[event_index].callback) + (_bt_get_error_code(param->result), NULL, BT_ADAPTER_LE_ADVERTISING_STARTED, + bt_event_slot_container[event_index].user_data); + } + + _bt_adapter_le_invoke_advertising_state_cb(*adv_handle, + _bt_get_error_code(param->result), BT_ADAPTER_LE_ADVERTISING_STARTED); + + break; + case BLUETOOTH_EVENT_ADVERTISING_STOPPED: + BT_INFO("BLUETOOTH_EVENT_ADVERTISING_STOPPED"); + adv_handle = (int *)(param->param_data); + + if (bt_event_slot_container[event_index].callback != NULL) { + ((bt_adapter_le_advertising_state_changed_cb)bt_event_slot_container[event_index].callback) + (_bt_get_error_code(param->result), NULL, BT_ADAPTER_LE_ADVERTISING_STOPPED, + bt_event_slot_container[event_index].user_data); + } + + _bt_adapter_le_invoke_advertising_state_cb(*adv_handle, + _bt_get_error_code(param->result), BT_ADAPTER_LE_ADVERTISING_STOPPED); + + break; + case BLUETOOTH_EVENT_MANUFACTURER_DATA_CHANGED: + BT_INFO("BLUETOOTH_EVENT_MANUFACTURER_DATA_CHANGED"); + + ((bt_adapter_manufacturer_data_changed_cb)bt_event_slot_container[event_index].callback) + (param->param_data, param->result, + bt_event_slot_container[event_index].user_data); + + break; +#ifdef TIZEN_WEARABLE + case BLUETOOTH_PBAP_CONNECTED: { + bt_pbap_enabled_cb cb = bt_event_slot_container[event_index].callback; + void *user_data = bt_event_slot_container[event_index].user_data; + bt_pbap_connected_t *connected = (bt_pbap_connected_t *)param->param_data; + + BT_INFO("BLUETOOTH_PBAP_CONNECTED/DISCONNECTED"); + if (connected->connected == 0) + _bt_unset_cb(BT_EVENT_PBAP_CONNECTION_STATUS); + _bt_convert_address_to_string(&device_addr, &connected->btaddr); + cb(device_addr, connected->connected, user_data); + + if (device_addr != NULL) + free(device_addr); + + break; + } + case BLUETOOTH_PBAP_PHONEBOOK_SIZE: { + bt_pbap_phonebook_size_cb cb = bt_event_slot_container[event_index].callback; + void *user_data = bt_event_slot_container[event_index].user_data; + bt_pbap_phonebook_size_t *pb_size = (bt_pbap_phonebook_size_t *)param->param_data; + + BT_INFO("BLUETOOTH_PBAP_PHONEBOOK_SIZE"); + + _bt_unset_cb(BT_EVENT_PBAP_PHONEBOOK_SIZE); + _bt_convert_address_to_string(&device_addr, &pb_size->btaddr); + cb(device_addr, pb_size->size, user_data); + + if (device_addr != NULL) + free(device_addr); + + break; + } + case BLUETOOTH_PBAP_PHONEBOOK_PULL: { + bt_pbap_phonebook_pull_cb cb = bt_event_slot_container[event_index].callback; + void *user_data = bt_event_slot_container[event_index].user_data; + bt_pbap_phonebook_pull_t *pb_pull = (bt_pbap_phonebook_pull_t *)(param->param_data); + + BT_INFO("BLUETOOTH_PBAP_PHONEBOOK_PULL"); + + _bt_unset_cb(BT_EVENT_PBAP_PHONEBOOK_PULL); + _bt_convert_address_to_string(&device_addr, &pb_pull->btaddr); + cb(device_addr, pb_pull->vcf_file, pb_pull->success, user_data); + + if (device_addr != NULL) + free(device_addr); + + break; + } + case BLUETOOTH_PBAP_VCARD_LIST: { + bt_pbap_list_vcards_cb cb = bt_event_slot_container[event_index].callback; + void *user_data = bt_event_slot_container[event_index].user_data; + bt_pbap_vcard_list_t *vc_list = (bt_pbap_vcard_list_t *)(param->param_data); + + BT_INFO("BLUETOOTH_PBAP_VCARD_LIST"); + + _bt_unset_cb(BT_EVENT_PBAP_VCARD_LIST); + _bt_convert_address_to_string(&device_addr, &vc_list->btaddr); + cb(device_addr, vc_list->vcards, vc_list->length, vc_list->success, user_data); + + if (device_addr != NULL) + free(device_addr); + + break; + } + case BLUETOOTH_PBAP_VCARD_PULL: { + bt_pbap_get_vcard_cb cb = bt_event_slot_container[event_index].callback; + void *user_data = bt_event_slot_container[event_index].user_data; + bt_pbap_vcard_pull_t *vc_pull = (bt_pbap_vcard_pull_t *)(param->param_data); + + BT_INFO("BLUETOOTH_PBAP_VCARD_PULL"); + + _bt_unset_cb(BT_EVENT_PBAP_VCARD_PULL); + _bt_convert_address_to_string(&device_addr, &vc_pull->btaddr); + cb(device_addr, vc_pull->vcf_file, vc_pull->success, user_data); + + if (device_addr != NULL) + free(device_addr); + + break; + } + case BLUETOOTH_PBAP_PHONEBOOK_SEARCH: { + bt_pbap_search_list_cb cb = bt_event_slot_container[event_index].callback; + void *user_data = bt_event_slot_container[event_index].user_data; + bt_pbap_phonebook_search_list_t *vc_list = (bt_pbap_phonebook_search_list_t *)(param->param_data); + + BT_INFO("BLUETOOTH_PBAP_PHONEBOOK_SEARCH"); + + _bt_unset_cb(BT_EVENT_PBAP_PHONEBOOK_SEARCH); + _bt_convert_address_to_string(&device_addr, &vc_list->btaddr); + cb(device_addr, vc_list->vcards, vc_list->length, vc_list->success, user_data); + + if (device_addr != NULL) + free(device_addr); + + break; + } + case BLUETOOTH_EVENT_HF_CONNECTED: + BT_INFO("BLUETOOTH_EVENT_HF_CONNECTED"); + device_addr = (char *)(param->param_data); + ((bt_audio_connection_state_changed_cb)bt_event_slot_container[event_index].callback) + (_bt_get_error_code(param->result), TRUE, device_addr, BT_AUDIO_PROFILE_TYPE_AG, + bt_event_slot_container[event_index].user_data); + break; + case BLUETOOTH_EVENT_HF_DISCONNECTED: + BT_INFO("BLUETOOTH_EVENT_HF_DISCONNECTED"); + device_addr = (char *)(param->param_data); + ((bt_audio_connection_state_changed_cb)bt_event_slot_container[event_index].callback) + (_bt_get_error_code(param->result), FALSE, device_addr, BT_AUDIO_PROFILE_TYPE_AG, + bt_event_slot_container[event_index].user_data); + break; + case BLUETOOTH_EVENT_HF_AUDIO_CONNECTED: + BT_INFO("BLUETOOTH_EVENT_HF_AUDIO_CONNECTED"); + device_addr = (char *)(param->param_data); + ((bt_hf_sco_state_changed_cb)bt_event_slot_container[event_index].callback) + (_bt_get_error_code(param->result), TRUE, + bt_event_slot_container[event_index].user_data); + break; + case BLUETOOTH_EVENT_HF_AUDIO_DISCONNECTED: + BT_INFO("BLUETOOTH_EVENT_HF_AUDIO_DISCONNECTED"); + device_addr = (char *)(param->param_data); + ((bt_hf_sco_state_changed_cb)bt_event_slot_container[event_index].callback) + (_bt_get_error_code(param->result), FALSE, + bt_event_slot_container[event_index].user_data); + break; + case BLUETOOTH_EVENT_HF_RING_INDICATOR: + BT_INFO("BLUETOOTH_EVENT_HF_RING_INDICATOR"); + phone_number = (char *)(param->param_data); + ((bt_hf_call_handling_event_cb)bt_event_slot_container[event_index].callback) + (BT_HF_CALL_HANDLING_EVENT_RING, phone_number, + bt_event_slot_container[event_index].user_data); + break; + case BLUETOOTH_EVENT_HF_CALL_TERMINATED: + BT_INFO("BLUETOOTH_EVENT_HF_CALL_TERMINATED"); + ((bt_hf_call_handling_event_cb)bt_event_slot_container[event_index].callback) + (BT_HF_CALL_HANDLING_EVENT_RELEASE, NULL, + bt_event_slot_container[event_index].user_data); + break; + case BLUETOOTH_EVENT_HF_CALL_STARTED: + BT_INFO("BLUETOOTH_EVENT_HF_CALL_STARTED"); + ((bt_hf_call_handling_event_cb)bt_event_slot_container[event_index].callback) + (BT_HF_CALL_HANDLING_EVENT_CALL_STARTED, NULL, + bt_event_slot_container[event_index].user_data); + break; + case BLUETOOTH_EVENT_HF_CALL_ENDED: + BT_INFO("BLUETOOTH_EVENT_HF_CALL_ENDED"); + ((bt_hf_call_handling_event_cb)bt_event_slot_container[event_index].callback) + (BT_HF_CALL_HANDLING_EVENT_CALL_ENDED, NULL, + bt_event_slot_container[event_index].user_data); + break; + case BLUETOOTH_EVENT_HF_VOICE_RECOGNITION_ENABLED: + BT_INFO("BLUETOOTH_EVENT_HF_VOICE_RECOGNITION_ENABLED"); + ((bt_hf_call_handling_event_cb)bt_event_slot_container[event_index].callback) + (BT_HF_CALL_HANDLING_EVENT_VOICE_RECOGNITION_ENABLED, NULL, + bt_event_slot_container[event_index].user_data); + break; + case BLUETOOTH_EVENT_HF_VOICE_RECOGNITION_DISABLED: + BT_INFO("BLUETOOTH_EVENT_HF_VOICE_RECOGNITION_DISABLED"); + ((bt_hf_call_handling_event_cb)bt_event_slot_container[event_index].callback) + (BT_HF_CALL_HANDLING_EVENT_VOICE_RECOGNITION_DISABLED, NULL, + bt_event_slot_container[event_index].user_data); + break; + case BLUETOOTH_EVENT_HF_CALL_WAITING: + BT_INFO("BLUETOOTH_EVENT_HF_CALL_WAITING"); + phone_number = (char *)(param->param_data); + ((bt_hf_call_handling_event_cb)bt_event_slot_container[event_index].callback) + (BT_HF_CALL_HANDLING_EVENT_WAITING, phone_number, + bt_event_slot_container[event_index].user_data); + break; + case BLUETOOTH_EVENT_HF_CALL_ON_HOLD: + BT_INFO("BLUETOOTH_EVENT_HF_CALL_ON_HOLD"); + ((bt_hf_call_handling_event_cb)bt_event_slot_container[event_index].callback) + (BT_HF_CALL_HANDLING_EVENT_HELD, NULL, + bt_event_slot_container[event_index].user_data); + break; + case BLUETOOTH_EVENT_HF_CALL_UNHOLD: + BT_INFO("BLUETOOTH_EVENT_HF_CALL_UNHOLD"); + ((bt_hf_call_handling_event_cb)bt_event_slot_container[event_index].callback) + (BT_HF_CALL_HANDLING_EVENT_UNHELD, NULL, + bt_event_slot_container[event_index].user_data); + break; + case BLUETOOTH_EVENT_HF_CALL_SWAPPED: + BT_INFO("BLUETOOTH_EVENT_HF_CALL_SWAPPED"); + ((bt_hf_call_handling_event_cb)bt_event_slot_container[event_index].callback) + (BT_HF_CALL_HANDLING_EVENT_SWAPPED, NULL, + bt_event_slot_container[event_index].user_data); + break; + case BLUETOOTH_EVENT_HF_VOLUME_SPEAKER: { + BT_INFO("BLUETOOTH_EVENT_HF_VOLUME_SPEAKER"); + int *spk_gain = (int *)(param->param_data); + ((bt_hf_speaker_gain_changed_cb)bt_event_slot_container[event_index].callback) + (*spk_gain, bt_event_slot_container[event_index].user_data); + break; + } + case BLUETOOTH_EVENT_HF_CALL_STATUS: { + BT_INFO("BLUETOOTH_EVENT_HF_CALL_STATUS"); + bt_hf_call_list_s *handle = (bt_hf_call_list_s *)(param->param_data); + GList *l = NULL; + GSList *call_list = NULL; + + for (l = g_list_first(handle->list); l; l = g_list_next(l)) { + bt_hf_call_status_info_t *hf_call_info = l->data; + bt_hf_call_status_info_s *call_info = NULL; + + call_info = g_malloc0(sizeof(bt_hf_call_status_info_s)); + call_info->number = strdup(hf_call_info->number); + call_info->direction = hf_call_info->direction; + call_info->status = hf_call_info->status; + call_info->multi_party = hf_call_info->mpart; + call_info->index = hf_call_info->idx; + call_list = g_slist_append(call_list, call_info); + } + + ((bt_hf_call_status_updated_event_cb)bt_event_slot_container[event_index].callback) + (call_list, bt_event_slot_container[event_index].user_data); + break; + } +#endif + default: + break; + } +} + + +static void __bt_le_event_proxy(int event, bluetooth_event_param_t *param, void *user_data) +{ + bt_adapter_le_device_scan_result_info_s *scan_info = NULL; +#ifndef TIZEN_WEARABLE + bt_adapter_le_device_discovery_info_s *discovery_info = NULL; +#endif + int event_index = -1; + + event_index = __bt_get_cb_index(event); + if (event == BLUETOOTH_EVENT_REMOTE_LE_DEVICE_FOUND) + BT_INFO("Need to check 2 slots in the case"); + else if (event_index == -1 || bt_event_slot_container[event_index].callback == NULL) + return; + + switch (event) { + case BLUETOOTH_EVENT_LE_ENABLED: + BT_INFO("BLUETOOTH_EVENT_LE_ENABLED"); + ((bt_adapter_le_state_changed_cb) bt_event_slot_container[event_index].callback) + (_bt_get_error_code(param->result), BT_ADAPTER_LE_ENABLED, bt_event_slot_container[event_index].user_data); + break; + case BLUETOOTH_EVENT_LE_DISABLED: + BT_INFO("BLUETOOTH_EVENT_LE_DISABLED"); + ((bt_adapter_le_state_changed_cb) bt_event_slot_container[event_index].callback) + (_bt_get_error_code(param->result), BT_ADAPTER_LE_DISABLED, bt_event_slot_container[event_index].user_data); + break; + +#ifndef TIZEN_WEARABLE + case BLUETOOTH_EVENT_LE_DISCOVERY_STARTED: + BT_INFO("BLUETOOTH_EVENT_LE_DISCOVERY_STARTED"); + ((bt_adapter_le_device_discovery_state_changed_cb) bt_event_slot_container[event_index].callback) + (_bt_get_error_code(param->result), BT_ADAPTER_LE_DEVICE_DISCOVERY_STARTED, NULL, bt_event_slot_container[event_index].user_data); + break; + case BLUETOOTH_EVENT_LE_DISCOVERY_FINISHED: + BT_INFO("BLUETOOTH_EVENT_LE_DISCOVERY_FINISHED"); + ((bt_adapter_le_device_discovery_state_changed_cb)bt_event_slot_container[event_index].callback) + (_bt_get_error_code(param->result), BT_ADAPTER_LE_DEVICE_DISCOVERY_FINISHED, NULL, bt_event_slot_container[event_index].user_data); + break; +#endif + + case BLUETOOTH_EVENT_REMOTE_LE_DEVICE_FOUND: + BT_INFO("BLUETOOTH_EVENT_REMOTE_LE_DEVICE_FOUND"); + event_index = BT_EVENT_LE_SCAN_RESULT_UPDATED; + if (bt_event_slot_container[event_index].callback != NULL) { + if (__bt_get_bt_adapter_le_device_scan_info_s(&scan_info, (bluetooth_le_device_info_t *)(param->param_data)) == BT_ERROR_NONE) { + ((bt_adapter_le_scan_result_cb)bt_event_slot_container[event_index].callback) + (_bt_get_error_code(param->result), scan_info, bt_event_slot_container[event_index].user_data); + __bt_free_bt_adapter_le_device_scan_info_s(scan_info); + } else { + ((bt_adapter_le_scan_result_cb)bt_event_slot_container[event_index].callback) + (_bt_get_error_code(param->result), NULL, bt_event_slot_container[event_index].user_data); + } + } +#ifndef TIZEN_WEARABLE + event_index = BT_EVENT_LE_DEVICE_DISCOVERY_STATE_CHANGED; + if (bt_event_slot_container[event_index].callback != NULL) { + if (__bt_get_bt_adapter_le_device_discovery_info_s(&discovery_info, (bluetooth_le_device_info_t *)(param->param_data)) == BT_ERROR_NONE) { + ((bt_adapter_le_device_discovery_state_changed_cb)bt_event_slot_container[event_index].callback) + (_bt_get_error_code(param->result), BT_ADAPTER_LE_DEVICE_DISCOVERY_FOUND, discovery_info, bt_event_slot_container[event_index].user_data); + __bt_free_bt_adapter_le_device_discovery_info_s(discovery_info); + } else { + ((bt_adapter_le_device_discovery_state_changed_cb)bt_event_slot_container[event_index].callback) + (_bt_get_error_code(param->result), BT_ADAPTER_LE_DEVICE_DISCOVERY_FOUND, NULL, bt_event_slot_container[event_index].user_data); + } + } +#endif + break; + + default: + break; + } +} + +static int __bt_get_bt_adapter_device_discovery_info_s(bt_adapter_device_discovery_info_s **discovery_info, bluetooth_device_info_t *source_info) { + int i; + + BT_CHECK_INPUT_PARAMETER(source_info); + + *discovery_info = (bt_adapter_device_discovery_info_s *)malloc(sizeof(bt_adapter_device_discovery_info_s)); + if (*discovery_info == NULL) { + return BT_ERROR_OUT_OF_MEMORY; + } + + if (strlen(source_info->device_name.name) > 0) { + (*discovery_info)->remote_name = strdup(source_info->device_name.name); + } else { + (*discovery_info)->remote_name = NULL; + } + + _bt_convert_address_to_string(&((*discovery_info)->remote_address), &(source_info->device_address)); + + (*discovery_info)->bt_class.major_device_class = source_info->device_class.major_class; + (*discovery_info)->bt_class.minor_device_class = source_info->device_class.minor_class; + (*discovery_info)->bt_class.major_service_class_mask = source_info->device_class.service_class; + + if (source_info->service_index > 0) { + (*discovery_info)->service_uuid = (char **)malloc(sizeof(char *) * source_info->service_index); + if ((*discovery_info)->service_uuid != NULL) { + for (i = 0; i < source_info->service_index; i++) { + (*discovery_info)->service_uuid[i] = strdup(source_info->uuids[i]); + if ((*discovery_info)->service_uuid[i] != NULL) { + __bt_convert_lower_to_upper((*discovery_info)->service_uuid[i]); + } + + BT_INFO("UUID: %s", (*discovery_info)->service_uuid[i]); + } } } else { (*discovery_info)->service_uuid = NULL; @@ -903,6 +1860,16 @@ static int __bt_get_bt_adapter_device_discovery_info_s(bt_adapter_device_discove (*discovery_info)->rssi = (int)source_info->rssi; (*discovery_info)->is_bonded = (bool)source_info->paired; + (*discovery_info)->appearance = 0; + + (*discovery_info)->manufacturer_data_len = source_info->manufacturer_data.data_len; + if ((*discovery_info)->manufacturer_data_len > 0) { + (*discovery_info)->manufacturer_data = malloc(source_info->manufacturer_data.data_len); + memcpy((*discovery_info)->manufacturer_data, source_info->manufacturer_data.data, source_info->manufacturer_data.data_len); + } else { + (*discovery_info)->manufacturer_data = NULL; + } + return BT_ERROR_NONE; } @@ -926,25 +1893,171 @@ static void __bt_free_bt_adapter_device_discovery_info_s(bt_adapter_device_disco } free(discovery_info->service_uuid); } + if (discovery_info->manufacturer_data != NULL) + free(discovery_info->manufacturer_data); free(discovery_info); discovery_info = NULL; } +static int __bt_get_bt_adapter_le_device_scan_info_s( + bt_adapter_le_device_scan_result_info_s **scan_info, + bluetooth_le_device_info_t *source_info) +{ + + BT_CHECK_INPUT_PARAMETER(source_info); + + *scan_info = (bt_adapter_le_device_scan_result_info_s *)malloc(sizeof(bt_adapter_le_device_scan_result_info_s)); + if (*scan_info == NULL) { + return BT_ERROR_OUT_OF_MEMORY; + } + + _bt_convert_address_to_string(&((*scan_info)->remote_address), &(source_info->device_address)); + + if (source_info->addr_type == 0x02) + (*scan_info)->address_type = BT_DEVICE_RANDOM_ADDRESS; + else + (*scan_info)->address_type = BT_DEVICE_PUBLIC_ADDRESS; + (*scan_info)->rssi = (int)source_info->rssi; + (*scan_info)->adv_data_len = source_info->adv_ind_data.data_len; + if ((*scan_info)->adv_data_len > 0) { + (*scan_info)->adv_data = malloc(source_info->adv_ind_data.data_len); + memcpy((*scan_info)->adv_data, source_info->adv_ind_data.data.data, source_info->adv_ind_data.data_len); + } else { + (*scan_info)->adv_data = NULL; + } + + (*scan_info)->scan_data_len = source_info->scan_resp_data.data_len; + if ((*scan_info)->scan_data_len > 0) { + (*scan_info)->scan_data = malloc(source_info->scan_resp_data.data_len); + memcpy((*scan_info)->scan_data, source_info->scan_resp_data.data.data, source_info->scan_resp_data.data_len); + } else { + (*scan_info)->scan_data = NULL; + } + + return BT_ERROR_NONE; +} + +static void __bt_free_bt_adapter_le_device_scan_info_s(bt_adapter_le_device_scan_result_info_s *scan_info) +{ + if (scan_info == NULL) + return; + + if (scan_info->remote_address != NULL) + free(scan_info->remote_address); + + if (scan_info->adv_data != NULL) + free(scan_info->adv_data); + if (scan_info->scan_data != NULL) + free(scan_info->scan_data); + + free(scan_info); + scan_info = NULL; +} + +#ifndef TIZEN_WEARABLE +static int __bt_get_bt_adapter_le_device_discovery_info_s( + bt_adapter_le_device_discovery_info_s **le_discovery_info, + bluetooth_le_device_info_t *source_info) +{ + + BT_CHECK_INPUT_PARAMETER(source_info); + + *le_discovery_info = (bt_adapter_le_device_discovery_info_s *)malloc(sizeof(bt_adapter_le_device_discovery_info_s)); + if (*le_discovery_info == NULL) { + return BT_ERROR_OUT_OF_MEMORY; + } + + _bt_convert_address_to_string(&((*le_discovery_info)->remote_address), &(source_info->device_address)); + + (*le_discovery_info)->address_type = (int)source_info->addr_type; + (*le_discovery_info)->rssi = (int)source_info->rssi; + (*le_discovery_info)->adv_data_len = source_info->adv_ind_data.data_len; + if ((*le_discovery_info)->adv_data_len > 0) { + (*le_discovery_info)->adv_data = malloc(source_info->adv_ind_data.data_len); + memcpy((*le_discovery_info)->adv_data, source_info->adv_ind_data.data.data, source_info->adv_ind_data.data_len); + } else { + (*le_discovery_info)->adv_data = NULL; + } + + (*le_discovery_info)->scan_data_len = source_info->scan_resp_data.data_len; + if ((*le_discovery_info)->scan_data_len > 0) { + (*le_discovery_info)->scan_data = malloc(source_info->scan_resp_data.data_len); + memcpy((*le_discovery_info)->scan_data, source_info->scan_resp_data.data.data, source_info->scan_resp_data.data_len); + } else { + (*le_discovery_info)->scan_data = NULL; + } + + return BT_ERROR_NONE; +} + +static void __bt_free_bt_adapter_le_device_discovery_info_s(bt_adapter_le_device_discovery_info_s *discovery_info) +{ + if (discovery_info == NULL) + return; + + if (discovery_info->remote_address != NULL) + free(discovery_info->remote_address); + + if (discovery_info->adv_data != NULL) + free(discovery_info->adv_data); + if (discovery_info->scan_data != NULL) + free(discovery_info->scan_data); + + free(discovery_info); + discovery_info = NULL; +} + +#endif + +#ifdef BT_ENABLE_LEGACY_GATT_CLIENT +static int __bt_get_gatt_client_cb_index(int event) +{ + switch (event) { + case BLUETOOTH_EVENT_GATT_CHAR_VAL_CHANGED: + if (_bt_gatt_is_legacy_client_mode()) + return BT_EVENT_GATT_CLIENT_VALUE_CHANGED_LEGACY; + else + return BT_EVENT_GATT_CLIENT_VALUE_CHANGED; + case BLUETOOTH_EVENT_GATT_READ_CHAR: + if (_bt_gatt_is_legacy_client_mode()) + return BT_EVENT_GATT_CLIENT_READ_CHARACTERISTIC_LEGACY; + else + return BT_EVENT_GATT_CLIENT_READ_CHARACTERISTIC; + case BLUETOOTH_EVENT_GATT_WRITE_CHAR: + if (_bt_gatt_is_legacy_client_mode()) + return BT_EVENT_GATT_CLIENT_WRITE_CHARACTERISTIC_LEGACY; + else + return BT_EVENT_GATT_CLIENT_WRITE_CHARACTERISTIC; + } + + return -1; +} +#endif + static int __bt_get_cb_index(int event) { switch (event) { case BLUETOOTH_EVENT_ENABLED: case BLUETOOTH_EVENT_DISABLED: return BT_EVENT_STATE_CHANGED; + case BLUETOOTH_EVENT_LE_ENABLED: + case BLUETOOTH_EVENT_LE_DISABLED: + return BT_EVENT_LE_STATE_CHANGED; case BLUETOOTH_EVENT_LOCAL_NAME_CHANGED: return BT_EVENT_NAME_CHANGED; case BLUETOOTH_EVENT_DISCOVERABLE_MODE_CHANGED: return BT_EVENT_VISIBILITY_MODE_CHANGED; + case BLUETOOTH_EVENT_DISCOVERABLE_TIMEOUT_CHANGED: + return BT_EVENT_VISIBILITY_DURATION_CHANGED; case BLUETOOTH_EVENT_DISCOVERY_STARTED: case BLUETOOTH_EVENT_DISCOVERY_FINISHED: case BLUETOOTH_EVENT_REMOTE_DEVICE_NAME_UPDATED: return BT_EVENT_DEVICE_DISCOVERY_STATE_CHANGED; + case BLUETOOTH_EVENT_LE_DISCOVERY_STARTED: + case BLUETOOTH_EVENT_LE_DISCOVERY_FINISHED: + case BLUETOOTH_EVENT_REMOTE_LE_DEVICE_FOUND: + return BT_EVENT_LE_DEVICE_DISCOVERY_STATE_CHANGED; case BLUETOOTH_EVENT_BONDING_FINISHED: return BT_EVENT_BOND_CREATED; case BLUETOOTH_EVENT_BONDED_DEVICE_REMOVED: @@ -952,6 +2065,12 @@ static int __bt_get_cb_index(int event) case BLUETOOTH_EVENT_DEVICE_AUTHORIZED: case BLUETOOTH_EVENT_DEVICE_UNAUTHORIZED: return BT_EVENT_AUTHORIZATION_CHANGED; + case BLUETOOTH_EVENT_DEVICE_CONNECTED: + case BLUETOOTH_EVENT_DEVICE_DISCONNECTED: + return BT_EVENT_DEVICE_CONNECTION_STATUS; + case BLUETOOTH_EVENT_GATT_CONNECTED: + case BLUETOOTH_EVENT_GATT_DISCONNECTED: + return BT_EVENT_GATT_CONNECTION_STATUS; case BLUETOOTH_EVENT_SERVICE_SEARCHED: return BT_EVENT_SERVICE_SEARCHED; case BLUETOOTH_EVENT_RFCOMM_DATA_RECEIVED: @@ -987,7 +2106,7 @@ static int __bt_get_cb_index(int event) case BLUETOOTH_EVENT_NETWORK_DISCONNECTED: return BT_EVENT_PAN_CONNECTION_STATE_CHANGED; case BLUETOOTH_EVENT_HDP_DATA_RECEIVED: - return BT_EVENT_HDP_DATA_RECIEVED; + return BT_EVENT_HDP_DATA_RECEIVED; case BLUETOOTH_EVENT_HDP_CONNECTED: return BT_EVENT_HDP_CONNECTED; case BLUETOOTH_EVENT_HDP_DISCONNECTED: @@ -1004,14 +2123,123 @@ static int __bt_get_cb_index(int event) return BT_EVENT_AUDIO_CONNECTION_STATUS; case BLUETOOTH_EVENT_AG_AUDIO_DISCONNECTED: return BT_EVENT_AUDIO_CONNECTION_STATUS; + case BLUETOOTH_EVENT_TELEPHONY_AUDIO_CONNECTED: + return BT_EVENT_AG_SCO_CONNECTION_STATUS; + case BLUETOOTH_EVENT_TELEPHONY_AUDIO_DISCONNECTED: + return BT_EVENT_AG_SCO_CONNECTION_STATUS; + case BLUETOOTH_EVENT_TELEPHONY_ANSWER_CALL: + case BLUETOOTH_EVENT_TELEPHONY_RELEASE_CALL: + case BLUETOOTH_EVENT_TELEPHONY_REJECT_CALL: + return BT_EVENT_AG_CALL_HANDLING_EVENT; + case BLUETOOTH_EVENT_TELEPHONY_CHLD_0_RELEASE_ALL_HELD_CALL: + case BLUETOOTH_EVENT_TELEPHONY_CHLD_1_RELEASE_ALL_ACTIVE_CALL: + case BLUETOOTH_EVENT_TELEPHONY_CHLD_2_ACTIVE_HELD_CALL: + case BLUETOOTH_EVENT_TELEPHONY_CHLD_3_MERGE_CALL: + case BLUETOOTH_EVENT_TELEPHONY_CHLD_4_EXPLICIT_CALL_TRANSFER: + return BT_EVENT_AG_MULTI_CALL_HANDLING_EVENT; + case BLUETOOTH_EVENT_TELEPHONY_SEND_DTMF: + return BT_EVENT_AG_DTMF_TRANSMITTED; case BLUETOOTH_EVENT_AV_CONNECTED: return BT_EVENT_AUDIO_CONNECTION_STATUS; case BLUETOOTH_EVENT_AV_DISCONNECTED: return BT_EVENT_AUDIO_CONNECTION_STATUS; + case BLUETOOTH_EVENT_AV_SOURCE_CONNECTED: + case BLUETOOTH_EVENT_AV_SOURCE_DISCONNECTED: + return BT_EVENT_A2DP_SOURCE_CONNECTION_STATUS; + case BLUETOOTH_EVENT_AVRCP_CONNECTED: + case BLUETOOTH_EVENT_AVRCP_DISCONNECTED: + case BLUETOOTH_EVENT_AVRCP_CONTROL_CONNECTED: + case BLUETOOTH_EVENT_AVRCP_CONTROL_DISCONNECTED: + return BT_EVENT_AVRCP_CONNECTION_STATUS; + case BLUETOOTH_EVENT_AVRCP_SETTING_SHUFFLE_STATUS: + case BLUETOOTH_EVENT_AVRCP_CONTROL_SHUFFLE_STATUS: + return BT_EVENT_AVRCP_SHUFFLE_MODE_CHANGED; + case BLUETOOTH_EVENT_AVRCP_SETTING_EQUALIZER_STATUS: + case BLUETOOTH_EVENT_AVRCP_CONTROL_EQUALIZER_STATUS: + return BT_EVENT_AVRCP_EQUALIZER_STATE_CHANGED; + case BLUETOOTH_EVENT_AVRCP_SETTING_REPEAT_STATUS: + case BLUETOOTH_EVENT_AVRCP_CONTROL_REPEAT_STATUS: + return BT_EVENT_AVRCP_REPEAT_MODE_CHANGED; + case BLUETOOTH_EVENT_AVRCP_SETTING_SCAN_STATUS: + case BLUETOOTH_EVENT_AVRCP_CONTROL_SCAN_STATUS: + return BT_EVENT_AVRCP_SCAN_MODE_CHANGED; + case BLUETOOTH_EVENT_AVRCP_SONG_POSITION_STATUS: + return BT_EVENT_AVRCP_SONG_POSITION_CHANGED; + case BLUETOOTH_EVENT_AVRCP_PLAY_STATUS_CHANGED: + return BT_EVENT_AVRCP_PLAY_STATUS_CHANGED; + case BLUETOOTH_EVENT_AVRCP_TRACK_CHANGED: + return BT_EVENT_AVRCP_TRACK_INFO_CHANGED; case BLUETOOTH_HID_CONNECTED: return BT_EVENT_HID_CONNECTION_STATUS; case BLUETOOTH_HID_DISCONNECTED: return BT_EVENT_HID_CONNECTION_STATUS; +#ifdef BT_ENABLE_LEGACY_GATT_CLIENT + case BLUETOOTH_EVENT_GATT_SVC_CHAR_DISCOVERED: + return BT_EVENT_GATT_CLIENT_CHARACTERISTIC_DISCOVERED_LEGACY; + case BLUETOOTH_EVENT_GATT_SVC_CHAR_DESC_DISCOVERED: + return BT_EVENT_GATT_CLIENT_CHARACTERISTIC_DESCRIPTOR_DISCOVERED_LEGACY; + case BLUETOOTH_EVENT_GATT_CHAR_VAL_CHANGED: + case BLUETOOTH_EVENT_GATT_READ_CHAR: + case BLUETOOTH_EVENT_GATT_WRITE_CHAR: + return __bt_get_gatt_client_cb_index(event); +#else + case BLUETOOTH_EVENT_GATT_CHAR_VAL_CHANGED: + return BT_EVENT_GATT_CLIENT_VALUE_CHANGED; + case BLUETOOTH_EVENT_GATT_READ_CHAR: + return BT_EVENT_GATT_CLIENT_READ_CHARACTERISTIC; + case BLUETOOTH_EVENT_GATT_WRITE_CHAR: + return BT_EVENT_GATT_CLIENT_WRITE_CHARACTERISTIC; +#endif + case BLUETOOTH_EVENT_GATT_READ_DESC: + return BT_EVENT_GATT_CLIENT_READ_DESCRIPTOR; + case BLUETOOTH_EVENT_GATT_WRITE_DESC: + return BT_EVENT_GATT_CLIENT_WRITE_DESCRIPTOR; + case BLUETOOTH_EVENT_GATT_SERVER_READ_REQUESTED: + return BT_EVENT_GATT_SERVER_READ_REQUESTED; + case BLUETOOTH_EVENT_ADVERTISING_STARTED: + case BLUETOOTH_EVENT_ADVERTISING_STOPPED: + return BT_EVENT_ADVERTISING_STATE_CHANGED; + case BLUETOOTH_EVENT_MANUFACTURER_DATA_CHANGED: + return BT_EVENT_MANUFACTURER_DATA_CHANGED; + case BLUETOOTH_EVENT_CONNECTABLE_CHANGED: + return BT_EVENT_CONNECTABLE_CHANGED_EVENT; +#ifdef TIZEN_WEARABLE + case BLUETOOTH_PBAP_CONNECTED: + return BT_EVENT_PBAP_CONNECTION_STATUS; + case BLUETOOTH_PBAP_PHONEBOOK_SIZE: + return BT_EVENT_PBAP_PHONEBOOK_SIZE; + case BLUETOOTH_PBAP_PHONEBOOK_PULL: + return BT_EVENT_PBAP_PHONEBOOK_PULL; + case BLUETOOTH_PBAP_VCARD_LIST: + return BT_EVENT_PBAP_VCARD_LIST; + case BLUETOOTH_PBAP_VCARD_PULL: + return BT_EVENT_PBAP_VCARD_PULL; + case BLUETOOTH_PBAP_PHONEBOOK_SEARCH: + return BT_EVENT_PBAP_PHONEBOOK_SEARCH; + case BLUETOOTH_EVENT_HF_CONNECTED: + return BT_EVENT_AUDIO_CONNECTION_STATUS; + case BLUETOOTH_EVENT_HF_DISCONNECTED: + return BT_EVENT_AUDIO_CONNECTION_STATUS; + case BLUETOOTH_EVENT_HF_AUDIO_CONNECTED: + return BT_EVENT_HF_SCO_CONNECTION_STATUS; + case BLUETOOTH_EVENT_HF_AUDIO_DISCONNECTED: + return BT_EVENT_HF_SCO_CONNECTION_STATUS; + case BLUETOOTH_EVENT_HF_RING_INDICATOR: + case BLUETOOTH_EVENT_HF_CALL_TERMINATED: + case BLUETOOTH_EVENT_HF_CALL_STARTED: + case BLUETOOTH_EVENT_HF_CALL_ENDED: + case BLUETOOTH_EVENT_HF_VOICE_RECOGNITION_ENABLED: + case BLUETOOTH_EVENT_HF_VOICE_RECOGNITION_DISABLED: + case BLUETOOTH_EVENT_HF_CALL_WAITING: + case BLUETOOTH_EVENT_HF_CALL_ON_HOLD: + case BLUETOOTH_EVENT_HF_CALL_UNHOLD: + case BLUETOOTH_EVENT_HF_CALL_SWAPPED: + return BT_EVENT_HF_CALL_HANDLING_EVENT; + case BLUETOOTH_EVENT_HF_VOLUME_SPEAKER: + return BT_EVENT_HF_SPEAKER_GAIN_CHANGE; + case BLUETOOTH_EVENT_HF_CALL_STATUS: + return BT_EVENT_HF_CALL_STATUS_UPDATED_EVENT; +#endif default: return -1; } @@ -1028,3 +2256,228 @@ static void __bt_convert_lower_to_upper(char *origin) } } } + +static void bt_gatt_client_handle_destroy(bt_gatt_h gatt_handle) +{ + if (gatt_handle) + bt_gatt_destroy(gatt_handle); +} + +int _bt_gatt_client_update_all(bt_gatt_client_h client) +{ + bt_gatt_client_s *client_s = client; + bluetooth_device_address_t addr_hex = { {0, } }; + bt_gatt_handle_info_t *prim_svc = NULL; + int ret; + int i; + int j; + GSList *svc_list = NULL; + + prim_svc = g_new0(bt_gatt_handle_info_t, 1); + + _bt_convert_address_to_hex(&addr_hex, client_s->remote_address); + ret = bluetooth_gatt_get_primary_services(&addr_hex, prim_svc); + ret = _bt_get_error_code(ret); + if (ret != BT_ERROR_NONE) { + BT_ERR("bluetooth_gatt_get_primary_services is failed"); + return ret; + } + + if (prim_svc->count == 0) + goto done; + + for (i = 0; i < prim_svc->count; i++) { + bt_gatt_service_s *svc = NULL; + bt_gatt_service_property_t property; + + if (prim_svc->handle[i] == NULL) + continue; + BT_DBG("handle: %s", prim_svc->handle[i]); + + memset(&property, 0x00, sizeof(property)); + + ret = bluetooth_gatt_get_service_property( + prim_svc->handle[i], &property); + ret = _bt_get_error_code(ret); + if (ret != BT_ERROR_NONE) { + BT_ERR("bluetooth_gatt_get_service_property is failed"); + continue; + } + + /* Add primary service */ + ret = bt_gatt_service_create(property.uuid, + BT_GATT_SERVICE_TYPE_PRIMARY, + (bt_gatt_h *)&svc); + if (ret != BT_ERROR_NONE) { + BT_ERR("bt_gatt_service_create is failed"); + continue; + } + + svc->role = BT_GATT_ROLE_CLIENT; + svc->parent = (void *)client_s; + svc->path = g_strdup(prim_svc->handle[i]); + + svc_list = g_slist_append(svc_list, svc); + + if (property.include_handles.count != 0 && property.include_handles.handle) { + GSList *include_list = NULL; + /* Add included services */ + for (j = 0; j < property.include_handles.count; j++) { + bt_gatt_service_s *sec_svc = NULL; + bt_gatt_service_property_t sec_property; + + if (property.include_handles.handle[j] == NULL) + continue; + + memset(&sec_property, 0x00, sizeof(sec_property)); + + ret = bluetooth_gatt_get_service_property( + property.include_handles.handle[j], + &sec_property); + ret = _bt_get_error_code(ret); + if (ret != BT_ERROR_NONE) + continue; + + ret = bt_gatt_service_create(sec_property.uuid, + BT_GATT_SERVICE_TYPE_SECONDARY, + (bt_gatt_h *)&sec_svc); + if (ret != BT_ERROR_NONE) + continue; + + sec_svc->role = BT_GATT_ROLE_CLIENT; + sec_svc->parent = (void *)svc; + sec_svc->is_included_service = true; + sec_svc->path = g_strdup(property.include_handles.handle[j]); + + include_list = g_slist_append(include_list, sec_svc); + bluetooth_gatt_free_service_property(&sec_property); + } + + g_slist_free_full(svc->included_services, + bt_gatt_client_handle_destroy); + svc->included_services = include_list; + } + if (property.char_handle.count != 0 && property.char_handle.handle) { + + /* Add characteristics */ + __bt_gatt_client_update_characteristics(property.char_handle, svc); + } + bluetooth_gatt_free_service_property(&property); + } + g_strfreev(prim_svc->handle); + + g_free(prim_svc); + + if (svc_list == NULL) + return BT_ERROR_OPERATION_FAILED; + +done: + g_slist_free_full(client_s->services, + bt_gatt_client_handle_destroy); + + client_s->services = svc_list; + + return BT_ERROR_NONE; +} + +static int __bt_gatt_client_update_characteristics(bt_gatt_handle_info_t char_handles, + bt_gatt_service_s *service) +{ + GSList *chr_list = NULL; + int i; + + for (i = 0; i < char_handles.count; i++) { + bt_gatt_characteristic_s *chr = NULL; + bt_gatt_char_property_t char_property; + int ret; + + memset(&char_property, 0x00, sizeof(char_property)); + ret = bluetooth_gatt_get_characteristics_property( + char_handles.handle[i], &char_property); + ret = _bt_get_error_code(ret); + if (ret != BT_ERROR_NONE) { + BT_ERR("bluetooth_gatt_get_characteristics_property is failed"); + goto next; + } + + ret = bt_gatt_characteristic_create(char_property.uuid, 0, + char_property.permission, (char *)char_property.val, + (int)char_property.val_len, (bt_gatt_h *)&chr); + if (ret != BT_ERROR_NONE) { + BT_ERR("bt_gatt_characteristic_create is failed"); + goto next; + } + + if (char_property.permission & BT_GATT_PROPERTY_WRITE_WITHOUT_RESPONSE) + chr->write_type = BT_GATT_WRITE_TYPE_WRITE_NO_RESPONSE; + else if (char_property.permission & BT_GATT_PROPERTY_WRITE) + chr->write_type = BT_GATT_WRITE_TYPE_WRITE; + + chr->path = g_strdup(char_handles.handle[i]); + BT_DBG("path : %s", chr->path); + chr->parent = (void *)service; + chr->role = BT_GATT_ROLE_CLIENT; + + if (char_property.char_desc_handle.count != 0 && char_property.char_desc_handle.handle) { + + /* Add characteristics descriptor */ + __bt_gatt_client_update_descriptors(char_property.char_desc_handle, chr); + } + + chr_list = g_slist_append(chr_list, chr); +next: + bluetooth_gatt_free_char_property(&char_property); + } + + g_slist_free_full(service->characteristics, + bt_gatt_client_handle_destroy); + service->characteristics = chr_list; + return BT_ERROR_NONE; +} + +static int __bt_gatt_client_update_descriptors(bt_gatt_handle_info_t desc_handles, + bt_gatt_characteristic_s *characteristic) + +{ + GSList *desc_list = NULL; + int i; + + /* Add characteristics descriptor */ + + for (i = 0; i < desc_handles.count; i++) { + bt_gatt_descriptor_s *desc = NULL; + bt_gatt_char_descriptor_property_t desc_property; + int ret; + + memset(&desc_property, 0x00, sizeof(desc_property)); + ret = bluetooth_gatt_get_char_descriptor_property( + desc_handles.handle[i], &desc_property); + ret = _bt_get_error_code(ret); + if (ret != BT_ERROR_NONE) { + BT_ERR("bluetooth_gatt_get_char_descriptor_property is failed"); + goto next; + } + + ret = bt_gatt_descriptor_create(desc_property.uuid, 0, + (char*)desc_property.val, (int)desc_property.val_len, + (bt_gatt_h *)&desc); + + if (ret != BT_ERROR_NONE) { + BT_ERR("bt_gatt_characteristic_create is failed"); + goto next; + } + desc->path = g_strdup(desc_handles.handle[i]); + BT_DBG("path : %s", desc->path); + desc->parent = (void *)characteristic; + desc->role = BT_GATT_ROLE_CLIENT; + desc_list = g_slist_append(desc_list, desc); + +next: + bluetooth_gatt_free_desc_property(&desc_property); + } + + g_slist_free_full(characteristic->descriptors, + bt_gatt_client_handle_destroy); + characteristic->descriptors = desc_list; + return BT_ERROR_NONE; +} diff --git a/src/bluetooth-device.c b/src/bluetooth-device.c index a242617..15ab193 100644 --- a/src/bluetooth-device.c +++ b/src/bluetooth-device.c @@ -20,25 +20,41 @@ #include #include "bluetooth.h" +#include "bluetooth_internal.h" #include "bluetooth_private.h" -#ifdef LOG_TAG -#undef LOG_TAG -#endif -#define LOG_TAG "TIZEN_N_BLUETOOTH" - int bt_device_create_bond(const char *device_address) { bluetooth_device_address_t addr_hex = { {0,} }; int error_code = BT_ERROR_NONE; + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(device_address); _bt_convert_address_to_hex(&addr_hex, device_address); error_code = _bt_get_error_code(bluetooth_bond_device(&addr_hex)); if (error_code != BT_ERROR_NONE) { - LOGE("[%s] %s(0x%08x)", __FUNCTION__, _bt_convert_error_to_string(error_code), error_code); + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error_code), error_code); + } + + return error_code; +} + +int bt_device_create_bond_by_type(const char *device_address, + bt_device_connection_link_type_e conn_type) +{ + bluetooth_device_address_t addr_hex = { {0,} }; + int error_code = BT_ERROR_NONE; + + BT_CHECK_BT_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(device_address); + + _bt_convert_address_to_hex(&addr_hex, device_address); + error_code = _bt_get_error_code(bluetooth_bond_device_by_type(&addr_hex, conn_type)); + if (error_code != BT_ERROR_NONE) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error_code), error_code); } return error_code; @@ -48,10 +64,11 @@ int bt_device_cancel_bonding(void) { int error_code = BT_ERROR_NONE; + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); error_code = _bt_get_error_code(bluetooth_cancel_bonding()); if (error_code != BT_ERROR_NONE) { - LOGE("[%s] %s(0x%08x)", __FUNCTION__, _bt_convert_error_to_string(error_code), error_code); + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error_code), error_code); } return error_code; @@ -62,13 +79,14 @@ int bt_device_destroy_bond(const char *device_address) bluetooth_device_address_t addr_hex = { {0,} }; int error_code = BT_ERROR_NONE; + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(device_address); _bt_convert_address_to_hex(&addr_hex, device_address); error_code = _bt_get_error_code(bluetooth_unbond_device(&addr_hex)); if (error_code != BT_ERROR_NONE) { - LOGE("[%s] %s(0x%08x)", __FUNCTION__, _bt_convert_error_to_string(error_code), error_code); + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error_code), error_code); } return error_code; @@ -79,6 +97,7 @@ int bt_device_set_alias(const char *device_address, const char *alias) bluetooth_device_address_t addr_hex = { {0,} }; int error_code = BT_ERROR_NONE; + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(device_address); BT_CHECK_INPUT_PARAMETER(alias); @@ -86,7 +105,7 @@ int bt_device_set_alias(const char *device_address, const char *alias) _bt_convert_address_to_hex(&addr_hex, device_address); error_code = _bt_get_error_code(bluetooth_set_alias(&addr_hex, alias)); if (error_code != BT_ERROR_NONE) { - LOGE("[%s] %s(0x%08x)", __FUNCTION__, _bt_convert_error_to_string(error_code), error_code); + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error_code), error_code); } return error_code; } @@ -97,6 +116,7 @@ int bt_device_set_authorization(const char *device_address, bt_device_authorizat gboolean trusted = FALSE; int error_code = BT_ERROR_NONE; + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(device_address); @@ -106,7 +126,7 @@ int bt_device_set_authorization(const char *device_address, bt_device_authorizat error_code = _bt_get_error_code(bluetooth_authorize_device(&addr_hex, trusted)); if (error_code != BT_ERROR_NONE) { - LOGE("[%s] %s(0x%08x)", __FUNCTION__, _bt_convert_error_to_string(error_code), error_code); + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error_code), error_code); } return error_code; } @@ -116,18 +136,19 @@ int bt_device_start_service_search(const char *device_address) bluetooth_device_address_t addr_hex = { {0,} }; int ret = 0; + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(device_address); _bt_convert_address_to_hex(&addr_hex, device_address); ret = _bt_get_error_code(bluetooth_search_service(&addr_hex)); - // In service search, BT_ERROR_SERVICE_SEARCH_FAILED is returned instead of BT_ERROR_OPERATION_FAILED. + /* In service search, BT_ERROR_SERVICE_SEARCH_FAILED is returned instead of BT_ERROR_OPERATION_FAILED. */ if (ret == BT_ERROR_OPERATION_FAILED) ret = BT_ERROR_SERVICE_SEARCH_FAILED; if (ret != BT_ERROR_NONE) { - LOGE("[%s] %s(0x%08x)", __FUNCTION__, _bt_convert_error_to_string(ret), ret); + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); } return ret; } @@ -136,73 +157,178 @@ int bt_device_cancel_service_search(void) { int ret = 0; + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); ret = _bt_get_error_code(bluetooth_cancel_service_search()); if (ret != BT_ERROR_NONE) { - LOGE("[%s] %s(0x%08x)", __FUNCTION__, _bt_convert_error_to_string(ret), ret); + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); } return ret; } -int bt_device_set_bond_created_cb(bt_device_bond_created_cb callback, void *user_data) +int bt_device_foreach_connected_profiles(const char *remote_address, bt_device_connected_profile callback, void *user_data) { - int ret = BT_ERROR_NONE; - + bluetooth_device_address_t addr_hex = { {0,} }; + gboolean is_connected = FALSE; + int ret; + int i = 0; + int profiles[] = {BT_PROFILE_RFCOMM, BT_PROFILE_A2DP, + BT_PROFILE_HSP, BT_PROFILE_HID, BT_PROFILE_NAP, + BT_PROFILE_AG, BT_PROFILE_GATT, BT_PROFILE_NAP_SERVER, + 0}; + + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(remote_address); BT_CHECK_INPUT_PARAMETER(callback); - _bt_set_cb(BT_EVENT_BOND_CREATED, callback, user_data); + + _bt_convert_address_to_hex(&addr_hex, remote_address); + + while (profiles[i] != 0) { + ret = _bt_get_error_code(bluetooth_is_device_connected(&addr_hex, + profiles[i], + &is_connected)); + if (ret != BT_ERROR_NONE) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); + return ret; + } + + if (is_connected == TRUE) { + if (!callback(profiles[i], user_data)) + break; + } + + i++; + } + + return BT_ERROR_NONE; +} + +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_BT_SUPPORT(); + 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; + if (ret != BT_ERROR_NONE) { - LOGE("[%s] %s(0x%08x)", __FUNCTION__, _bt_convert_error_to_string(ret), ret); + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); + return ret; } return ret; + } -int bt_device_set_bond_destroyed_cb(bt_device_bond_destroyed_cb callback, void *user_data) +int bt_device_set_bond_created_cb(bt_device_bond_created_cb callback, void *user_data) { - int ret = BT_ERROR_NONE; + BT_CHECK_BT_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(callback); + _bt_set_cb(BT_EVENT_BOND_CREATED, callback, user_data); + + return BT_ERROR_NONE; +} +int bt_device_set_bond_destroyed_cb(bt_device_bond_destroyed_cb callback, void *user_data) +{ + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(callback); _bt_set_cb(BT_EVENT_BOND_DESTROYED, callback, user_data); - if (ret != BT_ERROR_NONE) { - LOGE("[%s] %s(0x%08x)", __FUNCTION__, _bt_convert_error_to_string(ret), ret); - } - return ret; + return BT_ERROR_NONE; } int bt_device_set_authorization_changed_cb(bt_device_authorization_changed_cb callback, void *user_data) { - int ret = BT_ERROR_NONE; - + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(callback); _bt_set_cb(BT_EVENT_AUTHORIZATION_CHANGED, callback, user_data); - if (ret != BT_ERROR_NONE) { - LOGE("[%s] %s(0x%08x)", __FUNCTION__, _bt_convert_error_to_string(ret), ret); - } - return ret; + return BT_ERROR_NONE; } int bt_device_set_service_searched_cb(bt_device_service_searched_cb callback, void *user_data) { - int ret = BT_ERROR_NONE; - + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(callback); _bt_set_cb(BT_EVENT_SERVICE_SEARCHED, callback, user_data); + + return BT_ERROR_NONE; +} + +int bt_device_get_connection_state(const char *remote_address, + bt_device_connection_link_type_e link_type, bool *connected) +{ + int ret; + bluetooth_device_address_t addr_hex = { {0,} }; + bluetooth_connected_link_t connected_link = BLUETOOTH_CONNECTED_LINK_NONE; + + BT_CHECK_BT_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(remote_address); + BT_CHECK_INPUT_PARAMETER(connected); + + if (link_type != BT_DEVICE_CONNECTION_LINK_BREDR && + link_type != BT_DEVICE_CONNECTION_LINK_LE) + return BT_ERROR_INVALID_PARAMETER; + + _bt_convert_address_to_hex(&addr_hex, remote_address); + + ret = _bt_get_error_code(bluetooth_get_connected_link_type(&addr_hex, &connected_link)); if (ret != BT_ERROR_NONE) { - LOGE("[%s] %s(0x%08x)", __FUNCTION__, _bt_convert_error_to_string(ret), ret); + BT_ERR("%s(0x%08x) : Failed to run function", + _bt_convert_error_to_string(ret), ret); + return ret; } - return ret; + if (connected_link == BLUETOOTH_CONNECTED_LINK_BREDR_LE) { + *connected = true; + return BT_ERROR_NONE; + } + + if (link_type == BT_DEVICE_CONNECTION_LINK_BREDR) { + if (connected_link == BLUETOOTH_CONNECTED_LINK_BREDR) + *connected = true; + else + *connected = false; + } else if (link_type == BT_DEVICE_CONNECTION_LINK_LE) { + if (connected_link == BLUETOOTH_CONNECTED_LINK_LE) + *connected = true; + else + *connected = false; + } + + return BT_ERROR_NONE; +} + +int bt_device_set_connection_state_changed_cb(bt_device_connection_state_changed_cb callback, void *user_data) +{ + BT_CHECK_BT_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(callback); + _bt_set_cb(BT_EVENT_DEVICE_CONNECTION_STATUS, callback, user_data); + + return BT_ERROR_NONE; } int bt_device_unset_bond_created_cb(void) { + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); _bt_unset_cb(BT_EVENT_BOND_CREATED); return BT_ERROR_NONE; @@ -210,6 +336,7 @@ int bt_device_unset_bond_created_cb(void) int bt_device_unset_bond_destroyed_cb(void) { + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); _bt_unset_cb(BT_EVENT_BOND_DESTROYED); return BT_ERROR_NONE; @@ -217,6 +344,7 @@ int bt_device_unset_bond_destroyed_cb(void) int bt_device_unset_authorization_changed_cb(void) { + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); _bt_unset_cb(BT_EVENT_AUTHORIZATION_CHANGED); return BT_ERROR_NONE; @@ -224,8 +352,229 @@ int bt_device_unset_authorization_changed_cb(void) int bt_device_unset_service_searched_cb(void) { + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); _bt_unset_cb(BT_EVENT_SERVICE_SEARCHED); return BT_ERROR_NONE; } +int bt_device_unset_connection_state_changed_cb(void) +{ + BT_CHECK_BT_SUPPORT(); + BT_CHECK_INIT_STATUS(); + _bt_unset_cb(BT_EVENT_DEVICE_CONNECTION_STATUS); + return BT_ERROR_NONE; +} + +int bt_device_le_conn_update(const char *device_address, + const bt_le_conn_update_s *parameters) +{ + bluetooth_device_address_t addr_hex = { {0,} }; + bluetooth_le_conn_update_t param= { 0 }; + int ret = BT_ERROR_NONE; + + BT_CHECK_BT_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(device_address); + BT_CHECK_INPUT_PARAMETER(parameters); + + _bt_convert_address_to_hex(&addr_hex, device_address); + param.interval_min = parameters->interval_min; + param.interval_max = parameters->interval_max; + param.latency = parameters->latency; + param.time_out = parameters->time_out; + + ret = _bt_get_error_code(bluetooth_le_conn_update(&addr_hex, ¶m)); + + if (BT_ERROR_NONE != ret) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); + } + + return ret; +} + +int bt_device_get_service_mask_from_uuid_list(char **uuids, + int no_of_service, + bt_service_class_t *service_mask_list) +{ + int i = 0; + unsigned int service = 0; + char **parts = NULL; + bt_service_class_t service_mask = 0; + + BT_CHECK_BT_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(uuids); + BT_CHECK_INPUT_PARAMETER(service_mask_list); + + BT_DBG("Get service mask from uuid list"); + BT_DBG("no_of_service = %d", no_of_service); + + for (i = 0; i < no_of_service; i++) { + parts = g_strsplit(uuids[i], "-", -1); + + if (parts == NULL || parts[0] == NULL) { + g_strfreev(parts); + continue; + } + + service = g_ascii_strtoull(parts[0], NULL, 16); + g_strfreev(parts); + + switch (service) { + case BLUETOOTH_SPP_PROFILE_UUID: + service_mask |= BT_SC_SPP_SERVICE_MASK; + break; + + case BLUETOOTH_LAP_PROFILE_UUID: + service_mask |= BT_SC_LAP_SERVICE_MASK; + break; + + case BLUETOOTH_DUN_PROFILE_UUID: + service_mask |= BT_SC_DUN_SERVICE_MASK; + break; + + case BLUETOOTH_OBEX_IR_MC_SYNC_SERVICE_UUID: + service_mask |= BT_SC_SYNC_SERVICE_MASK; + break; + + case BLUETOOTH_OBEX_OBJECT_PUSH_SERVICE_UUID: + service_mask |= BT_SC_OPP_SERVICE_MASK; + break; + + case BLUETOOTH_OBEX_FILE_TRANSFER_UUID: + service_mask |= BT_SC_FTP_SERVICE_MASK; + break; + + case BLUETOOTH_HS_PROFILE_UUID: + service_mask |= BT_SC_HSP_SERVICE_MASK; + break; + + case BLUETOOTH_CTP_PROFILE_UUID: + service_mask |= BT_SC_CTP_SERVICE_MASK; + break; + + case BLUETOOTH_AUDIO_SOURCE_UUID: + service_mask |= BT_SC_A2DP_SOURCE_SERVICE_MASK; + break; + + case BLUETOOTH_AUDIO_SINK_UUID: + service_mask |= BT_SC_A2DP_SERVICE_MASK; + break; + + case BLUETOOTH_VIDEO_SOURCE_UUID: + service_mask |= BT_SC_NONE; + break; + + case BLUETOOTH_VIDEO_SINK_UUID: + service_mask |= BT_SC_NONE; + break; + + case BLUETOOTH_AV_REMOTE_CONTROL_TARGET_UUID: + service_mask |= BT_SC_NONE; + break; + + case BLUETOOTH_ADVANCED_AUDIO_PROFILE_UUID: + service_mask |= BT_SC_A2DP_SERVICE_MASK; + break; + + case BLUETOOTH_AV_REMOTE_CONTROL_UUID: + service_mask |= BT_SC_AVRCP_SERVICE_MASK; + break; + + case BLUETOOTH_ICP_PROFILE_UUID: + service_mask |= BT_SC_ICP_SERVICE_MASK; + break; + + case BLUETOOTH_FAX_PROFILE_UUID: + service_mask |= BT_SC_FAX_SERVICE_MASK; + break; + + case BLUETOOTH_HEADSET_AG_SERVICE_UUID: + service_mask |= BT_SC_NONE; /* BT_SC_HSP_SERVICE_MASK */ + break; + + case BLUETOOTH_PAN_PANU_PROFILE_UUID: + service_mask |= BT_SC_PANU_SERVICE_MASK; + break; + + case BLUETOOTH_PAN_NAP_PROFILE_UUID: + service_mask |= BT_SC_NAP_SERVICE_MASK; + break; + + case BLUETOOTH_PAN_GN_PROFILE_UUID: + service_mask |= BT_SC_GN_SERVICE_MASK; + break; + + case BLUETOOTH_REFERENCE_PRINTING: + service_mask |= BT_SC_NONE; + break; + + case BLUETOOTH_OBEX_IMAGING_UUID: + service_mask |= BT_SC_NONE; + break; + + case BLUETOOTH_OBEX_IMAGING_RESPONDER_UUID: + service_mask |= BT_SC_BIP_SERVICE_MASK; + break; + + case BLUETOOTH_HF_PROFILE_UUID: + service_mask |= BT_SC_HFP_SERVICE_MASK; + break; + + case BLUETOOTH_HFG_PROFILE_UUID: + service_mask |= BT_SC_NONE; + break; + + case BLUETOOTH_DIRECT_PRINTING_REFERENCE_OBJ_UUID: + service_mask |= BT_SC_NONE; + break; + + case BLUETOOTH_BASIC_PRINTING: + service_mask |= BT_SC_NONE; + break; + + case BLUETOOTH_HID_PROFILE_UUID: + service_mask |= BT_SC_HID_SERVICE_MASK; + break; + + case BLUETOOTH_SIM_ACCESS_PROFILE_UUID: + service_mask |= BT_SC_SAP_SERVICE_MASK; + break; + + case BLUETOOTH_OBEX_PBA_PROFILE_UUID: + service_mask |= BT_SC_PBAP_SERVICE_MASK; + break; + + case BLUETOOTH_OBEX_BPPS_PROFILE_UUID: + service_mask |= BT_SC_BPP_SERVICE_MASK; + break; + + case BLUETOOTH_PNP_INFORMATION_UUID: + service_mask |= BT_SC_NONE; + break; + + case BLUETOOTH_OBEX_PRINTING_STATUS_UUID: + service_mask |= BT_SC_BPP_SERVICE_MASK; + break; + + case BLUETOOTH_HCR_PROFILE_UUID: + service_mask |= BT_SC_NONE; + break; + + case BLUETOOTH_OBEX_SYNCML_TRANSFER_UUID: + service_mask |= BT_SC_NONE; + break; + + default: + break; + } + + } + + *service_mask_list = service_mask; + BT_DBG("service_mask = %x, service_mask_list = %x", service_mask, + service_mask_list); + + return BT_ERROR_NONE; +} diff --git a/src/bluetooth-gatt.c b/src/bluetooth-gatt.c new file mode 100755 index 0000000..aa8ae45 --- /dev/null +++ b/src/bluetooth-gatt.c @@ -0,0 +1,2481 @@ +/* + * 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 +#include +#include +#include + +#include "bluetooth.h" +#include "bluetooth_private.h" +#include "bluetooth_internal.h" +#include "bluetooth_type_internal.h" + +#define BT_ADDR_STR_LEN 17 + +static GSList *gatt_client_list = NULL; + +static GSList *gatt_server_list = NULL; +static bool is_gatt_server_initialized = false; + +#ifdef TIZEN_GATT_DISABLE +#define BT_CHECK_GATT_SUPPORT() \ + { \ + BT_CHECK_BT_SUPPORT(); \ + LOGE("[%s] NOT_SUPPORTED(0x%08x)", __FUNCTION__, BT_ERROR_NOT_SUPPORTED); \ + return BT_ERROR_NOT_SUPPORTED; \ + } +#else +#define BT_CHECK_GATT_SUPPORT() +#endif + +#define BT_CHECK_GATT_SERVER_INIT_STATUS() \ + if (__bt_check_gatt_server_init_status() == BT_ERROR_NOT_INITIALIZED) \ + { \ + LOGE("[%s] NOT_INITIALIZED(0x%08x)", __FUNCTION__, BT_ERROR_NOT_INITIALIZED); \ + return BT_ERROR_NOT_INITIALIZED; \ + } + +int __bt_check_gatt_server_init_status(void) +{ + if (is_gatt_server_initialized != true) { + BT_ERR("NOT_INITIALIZED(0x%08x)", BT_ERROR_NOT_INITIALIZED); + return BT_ERROR_NOT_INITIALIZED; + } + + return BT_ERROR_NONE; +} + +static char *__convert_uuid_to_uuid128(const char *uuid) +{ + int len; + char *uuid128; + + len = strlen(uuid); + + switch (len) { + case 4: /* UUID 16bits */ + uuid128 = g_strdup_printf("0000%s-0000-1000-8000-00805F9B34FB", uuid); + break; + + case 8: /* UUID 32bits */ + uuid128 = g_strdup_printf("%s-0000-1000-8000-00805F9B34FB", uuid); + break; + + case 36: /* UUID 128bits */ + uuid128 = strdup(uuid); + break; + + default: + return NULL; + } + + return uuid128; +} + +static int __get_gatt_handle_by_uuid(GSList *list, const char *uuid, + bt_gatt_h *gatt_handle) +{ + GSList *l; + char *uuid128_a; + char *uuid128_b; + + uuid128_a = __convert_uuid_to_uuid128(uuid); + if (uuid128_a == NULL) { + BT_ERR("Wrong type of uuid : %s", uuid); + return BT_ERROR_INVALID_PARAMETER; + } + + for (l = list; l; l = g_slist_next(l)) { + bt_gatt_common_s *common = (bt_gatt_common_s *)l->data; + + uuid128_b = __convert_uuid_to_uuid128(common->uuid); + if (g_ascii_strcasecmp(uuid128_a, uuid128_b) == 0) { + g_free(uuid128_b); + break; + } + + g_free(uuid128_b); + } + + if (!l) + return BT_ERROR_NO_DATA; + + *gatt_handle = l->data; + + return BT_ERROR_NONE; +} + +const GSList* _bt_gatt_get_client_list(void) +{ + return gatt_client_list; +} + +const GSList* _bt_gatt_get_server_list(void) +{ + return gatt_server_list; +} + +#ifdef BT_ENABLE_LEGACY_GATT_CLIENT +bool _bt_gatt_is_legacy_client_mode(void) +{ + if (gatt_client_list) { + BT_INFO("New GATT Client APIs"); + return false; + } + + BT_INFO("Legacy GATT Client APIs"); + return true; +} + +int bt_gatt_foreach_primary_services(const char *remote_address, + bt_gatt_primary_service_cb callback, + void *user_data) +{ + int i; + int ret; + bool foreach_call = true; + bluetooth_device_address_t addr_hex = { {0,} }; + bt_gatt_handle_info_t *prim_svc; + + BT_CHECK_GATT_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(remote_address); + BT_CHECK_INPUT_PARAMETER(callback); + + prim_svc = g_new0(bt_gatt_handle_info_t, 1); + + _bt_convert_address_to_hex(&addr_hex, remote_address); + + ret = _bt_get_error_code(bluetooth_gatt_get_primary_services(&addr_hex, + prim_svc)); + if (ret != BT_ERROR_NONE) { + BT_ERR("%s(0x%08x) : Failed to run function", + _bt_convert_error_to_string(ret), ret); + g_free(prim_svc); + return ret; + } + + for (i = 0; i < prim_svc->count; i++) { + if (prim_svc->handle[i] == NULL) + continue; + + BT_INFO("handle: %s", prim_svc->handle[i]); + + if (foreach_call == true && + !callback((bt_gatt_attribute_h)prim_svc->handle[i], user_data)) { + foreach_call = false; + } + + /* Application should clone the handle using API in callback */ + /* bt_gatt_clone_attribute_handle */ + g_free(prim_svc->handle[i]); + } + + g_free(prim_svc->handle); + g_free(prim_svc); + + return ret; +} + +int bt_gatt_discover_characteristics(bt_gatt_attribute_h service, + bt_gatt_characteristics_discovered_cb callback, + void *user_data) +{ + int ret; + + BT_CHECK_GATT_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(service); + BT_CHECK_INPUT_PARAMETER(callback); + + ret = _bt_get_error_code(bluetooth_gatt_discover_service_characteristics((const char *)service)); + + if (ret != BT_ERROR_NONE) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); + } else { + _bt_set_cb(BT_EVENT_GATT_CLIENT_CHARACTERISTIC_DISCOVERED_LEGACY, callback, user_data); + } + + return ret; +} + +int bt_gatt_get_service_uuid(bt_gatt_attribute_h service, char **uuid) +{ + int i; + int ret; + bt_gatt_service_property_t property; + + BT_CHECK_GATT_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(service); + + memset(&property, 0x00, sizeof(bt_gatt_service_property_t)); + + ret = _bt_get_error_code(bluetooth_gatt_get_service_property((const char *)service, &property)); + + if (ret != BT_ERROR_NONE) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); + } else { + *uuid = g_strdup(property.uuid); + + if (property.include_handles.count != 0 && property.include_handles.handle) { + for (i = 0; i < property.include_handles.count; i++) { + g_free(property.include_handles.handle[i]); + } + g_free(property.include_handles.handle); + } + if (property.char_handle.count != 0 && property.char_handle.handle) { + for (i = 0; i < property.char_handle.count; i++) { + g_free(property.char_handle.handle[i]); + } + g_free(property.char_handle.handle); + } + } + + return ret; +} + +int bt_gatt_foreach_included_services(bt_gatt_attribute_h service, + bt_gatt_included_service_cb callback, + void *user_data) +{ + int i; + int ret; + bool foreach_call = true; + bt_gatt_service_property_t property; + + BT_CHECK_GATT_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(service); + BT_CHECK_INPUT_PARAMETER(callback); + + memset(&property, 0x00, sizeof(bt_gatt_service_property_t)); + + ret = _bt_get_error_code(bluetooth_gatt_get_service_property((const char *)service, &property)); + + if (ret != BT_ERROR_NONE) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); + } else { + if (property.char_handle.count != 0 && property.char_handle.handle) { + for (i = 0; i < property.char_handle.count; i++) { + g_free(property.char_handle.handle[i]); + } + g_free(property.char_handle.handle); + } + if (property.include_handles.count == 0 || + property.include_handles.handle == NULL) { + return ret; + } + + for (i = 0; i < property.include_handles.count; i++) { + if (property.include_handles.handle[i] == NULL) + continue; + + if (foreach_call == true && + !callback((bt_gatt_attribute_h)property.include_handles.handle[i], + user_data)) { + foreach_call = false; + } + + g_free(property.include_handles.handle[i]); + } + g_free(property.include_handles.handle); + } + return ret; +} + +int bt_gatt_set_characteristic_changed_cb(bt_gatt_characteristic_changed_cb callback, + void *user_data) +{ + BT_CHECK_GATT_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(callback); + + _bt_set_cb(BT_EVENT_GATT_CLIENT_VALUE_CHANGED_LEGACY, callback, user_data); + + return BT_ERROR_NONE; +} + +int bt_gatt_unset_characteristic_changed_cb() +{ + BT_CHECK_GATT_SUPPORT(); + BT_CHECK_INIT_STATUS(); + + _bt_unset_cb(BT_EVENT_GATT_CLIENT_VALUE_CHANGED_LEGACY); + + return BT_ERROR_NONE; +} + +int bt_gatt_watch_characteristic_changes(bt_gatt_attribute_h service) +{ + int ret; + + BT_CHECK_GATT_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(service); + + ret = _bt_get_error_code(bluetooth_gatt_watch_characteristics((const char *)service)); + + if (ret != BT_ERROR_NONE) + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); + + return ret; +} + +int bt_gatt_unwatch_characteristic_changes(bt_gatt_attribute_h service) +{ + int ret; + + BT_CHECK_GATT_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(service); + + ret = _bt_get_error_code(bluetooth_gatt_unwatch_characteristics((const char *)service)); + + if (ret != BT_ERROR_NONE) + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); + + return ret; +} + +int bt_gatt_get_characteristic_declaration(bt_gatt_attribute_h characteristic, + char **uuid, unsigned char **value, + int *value_length) +{ + int ret; + bt_gatt_char_property_t property; + + BT_CHECK_GATT_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(characteristic); + + memset(&property, 0x00, sizeof(bt_gatt_char_property_t)); + + ret = _bt_get_error_code(bluetooth_gatt_get_characteristics_property((const char *)characteristic, &property)); + + if (ret != BT_ERROR_NONE) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); + } else { + if (property.uuid) { + *uuid = g_strdup(property.uuid); + g_free(property.uuid); + } + + if (property.val && property.val_len != 0) { + *value = g_memdup(property.val, property.val_len); + *value_length = property.val_len; + g_free(property.val); + } + + g_free(property.name); + + } + + return ret; +} + +int bt_gatt_set_characteristic_value(bt_gatt_attribute_h characteristic, + const unsigned char *value, + int value_length) +{ + int ret; + + BT_CHECK_GATT_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(characteristic); + BT_CHECK_INPUT_PARAMETER(value); + + if (value_length <= 0) + return BT_ERROR_INVALID_PARAMETER; + + ret = _bt_get_error_code(bluetooth_gatt_set_characteristics_value((const char *)characteristic, + (const guint8 *)value, value_length)); + + if (ret != BT_ERROR_NONE) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); + } + + return ret; +} + +int bt_gatt_set_characteristic_value_request(bt_gatt_attribute_h characteristic, + const unsigned char *value, int value_length, + bt_gatt_characteristic_write_cb callback) +{ + int ret; + + BT_CHECK_GATT_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(characteristic); + BT_CHECK_INPUT_PARAMETER(value); + + if (value_length <= 0) + return BT_ERROR_INVALID_PARAMETER; + + ret = _bt_get_error_code(bluetooth_gatt_set_characteristics_value_request( + (const char *)characteristic, + (const guint8 *)value, value_length)); + + if (ret != BT_ERROR_NONE) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); + } else { + _bt_set_cb(BT_EVENT_GATT_CLIENT_WRITE_CHARACTERISTIC_LEGACY, callback, characteristic); + } + + return ret; +} + +int bt_gatt_clone_attribute_handle(bt_gatt_attribute_h *clone, + bt_gatt_attribute_h origin) +{ + int error = BT_ERROR_NONE; + + BT_CHECK_GATT_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(origin); + + *clone = g_strdup((char *)origin); + + return error; +} + +int bt_gatt_destroy_attribute_handle(bt_gatt_attribute_h handle) +{ + int error = BT_ERROR_NONE; + + BT_CHECK_GATT_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(handle); + + g_free(handle); + + return error; +} + +int bt_gatt_read_characteristic_value(bt_gatt_attribute_h characteristic, + bt_gatt_characteristic_read_cb callback) +{ + int ret; + + BT_CHECK_GATT_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(characteristic); + BT_CHECK_INPUT_PARAMETER(callback); + + ret = _bt_get_error_code(bluetooth_gatt_read_characteristic_value((const char *)characteristic)); + + if (ret != BT_ERROR_NONE) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); + } else { + _bt_set_cb(BT_EVENT_GATT_CLIENT_READ_CHARACTERISTIC_LEGACY, callback, NULL); + } + + return ret; +} + +int bt_gatt_discover_characteristic_descriptor(bt_gatt_attribute_h characteristic_handle, + bt_gatt_characteristic_descriptor_discovered_cb callback, + void *user_data) +{ + int ret; + + BT_CHECK_GATT_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(characteristic_handle); + BT_CHECK_INPUT_PARAMETER(callback); + + ret = _bt_get_error_code(bluetooth_gatt_discover_characteristic_descriptor + ((const char *)characteristic_handle)); + + if (ret != BT_ERROR_NONE) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); + } else { + _bt_set_cb(BT_EVENT_GATT_CLIENT_CHARACTERISTIC_DESCRIPTOR_DISCOVERED_LEGACY, callback, user_data); + } + + return ret; +} +#endif + +int bt_gatt_connect(const char *address, bool auto_connect) +{ + int ret; + bluetooth_device_address_t bd_addr = { {0,} }; + + BT_CHECK_GATT_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(address); + _bt_convert_address_to_hex(&bd_addr, address); + + ret = _bt_get_error_code(bluetooth_connect_le(&bd_addr, auto_connect ? TRUE : FALSE)); + + if (ret != BT_ERROR_NONE) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); + } + return ret; +} + +int bt_gatt_disconnect(const char *address) +{ + int ret; + bluetooth_device_address_t bd_addr = { {0,} }; + + BT_CHECK_GATT_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(address); + _bt_convert_address_to_hex(&bd_addr, address); + + ret = _bt_get_error_code(bluetooth_disconnect_le(&bd_addr)); + + if (ret != BT_ERROR_NONE) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); + } + return ret; +} + +int bt_gatt_set_connection_state_changed_cb(bt_gatt_connection_state_changed_cb callback, void *user_data) +{ + BT_CHECK_GATT_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(callback); + _bt_set_cb(BT_EVENT_GATT_CONNECTION_STATUS, callback, user_data); + + return BT_ERROR_NONE; +} + +int bt_gatt_unset_connection_state_changed_cb(void) +{ + BT_CHECK_GATT_SUPPORT(); + BT_CHECK_INIT_STATUS(); + _bt_unset_cb(BT_EVENT_GATT_CONNECTION_STATUS); + return BT_ERROR_NONE; +} + +int bt_gatt_get_uuid_specification_name(const char *uuid, char **name) +{ + BT_CHECK_INPUT_PARAMETER(uuid); + BT_CHECK_INPUT_PARAMETER(name); + + int i; + int offset = 0; + static struct { + const char *uuid; + const char *specification_name; + } bt_uuid_name[] = { + /* GATT Services */ + {"1800", "Generic Access"}, + {"1801", "Generic Attribute"}, + {"1802", "Immediate Alert"}, + {"1803", "Link Loss"}, + {"1804", "Tx Power"}, + {"1805", "Current Time Service"}, + {"1806", "Reference Time Update Service"}, + {"1807", "Next DST Change Service"}, + {"1808", "Glucose"}, + {"1809", "Health Thermometer"}, + {"180A", "Device Information"}, + {"180D", "Heart Rate"}, + {"180F", "Battery Service"}, + {"1810", "Blood Pressure"}, + {"1811", "Alert Notification Service"}, + {"1812", "Human Interface Device"}, + + /* GATT Declarations */ + {"2800", "Primary Service Declaration"}, + {"2801", "Secondary Service Declaration"}, + {"2802", "Include Declaration"}, + {"2803", "Characteristic Declaration"}, + + /* GATT Descriptors */ + {"2900", "Characteristic Extended Properties"}, + {"2901", "Characteristic User Description"}, + {"2902", "Client Characteristic Configuration"}, + {"2903", "Server Characteristic Configuration"}, + {"2904", "Characteristic Format"}, + {"2905", "Characteristic Aggregate Formate"}, + {"2906", "Valid Range"}, + {"2907", "External Report Reference"}, + {"2908", "Report Reference"}, + + /* GATT Characteristics */ + {"2A00", "Device Name"}, + {"2A01", "Appearance"}, + {"2A02", "Peripheral Privacy Flag"}, + {"2A03", "Reconnection Address"}, + {"2A04", "Peripheral Preferred Connection Parameters"}, + {"2A05", "Service Changed"}, + {"2A06", "Alert Level"}, + {"2A07", "Tx Power Level"}, + {"2A08", "Date Time"}, + {"2A09", "Day of Week"}, + {"2A0A", "Day Date Time"}, + {"2A19", "Battery Level"}, + {"2A1E", "Intermediate Temperature"}, + {"2A23", "System ID"}, + {"2A24", "Model Number String"}, + {"2A25", "Serial Number String"}, + {"2A26", "Firmware Revision String"}, + {"2A27", "Hardware Revision String"}, + {"2A28", "Software Revision String"}, + {"2A29", "Manufacturer Name String"}, + {"2A2A", "IEEE 11073-20601 Regulatory Certification Data List"}, + {"2A2B", "Current Time"}, + {"2A37", "Heart Rate Measurement"}, + {"2A38", "Body Sensor Location"}, + {"2A3F", "Alert Status"}, + {"2A46", "New Alert"}, + {"2A4A", "HID Information"}, + {"2A4C", "HID Control Point"}, + {"2A50", "PnP ID"}, + {NULL, NULL} + }; + + if (strlen(uuid) >= 8) + offset = 4; + + for (i = 0; bt_uuid_name[i].uuid; i++) { + if (!g_ascii_strncasecmp(uuid + offset, bt_uuid_name[i].uuid, 4)) { + *name = g_strdup(bt_uuid_name[i].specification_name); + return BT_ERROR_NONE; + } + } + + *name = g_strdup("Unknown"); + return BT_ERROR_NONE; +} + +static void __bt_gatt_free_descriptor(bt_gatt_h gatt_handle) +{ + bt_gatt_descriptor_s *desc = (bt_gatt_descriptor_s*)gatt_handle; + + g_free(desc->path); + g_free(desc->uuid); + g_free(desc->value); + g_free(desc); +} + +static void __bt_gatt_free_characteristic(bt_gatt_h gatt_handle) +{ + bt_gatt_characteristic_s *chr = (bt_gatt_characteristic_s*)gatt_handle; + + g_slist_free_full(chr->descriptors, __bt_gatt_free_descriptor); + + g_free(chr->path); + g_free(chr->uuid); + g_free(chr->value); + g_free(chr); +} + +static void __bt_gatt_free_service(bt_gatt_h gatt_handle) +{ + int ret = BT_ERROR_NONE; + bt_gatt_service_s *svc = (bt_gatt_service_s*)gatt_handle; + + g_slist_free_full(svc->included_services, __bt_gatt_free_service); + g_slist_free_full(svc->characteristics, __bt_gatt_free_characteristic); + + if (svc->role == BT_GATT_ROLE_SERVER) { + ret = _bt_get_error_code(bluetooth_gatt_unregister_service(svc->path)); + if (ret != BT_ERROR_NONE) + BT_ERR("%s(0x%08x) : Failed to unregister service", + _bt_convert_error_to_string(ret), ret); + } + + g_free(svc->path); + g_free(svc->uuid); + g_free(svc); +} + +static void __bt_gatt_destroy_descriptor(bt_gatt_h gatt_handle) +{ + bt_gatt_descriptor_s *desc = (bt_gatt_descriptor_s*)gatt_handle; + bt_gatt_characteristic_s *parent_chr = (bt_gatt_characteristic_s*)desc->parent; + + if (parent_chr) + parent_chr->descriptors = g_slist_remove(parent_chr->descriptors, desc); + + __bt_gatt_free_descriptor(gatt_handle); +} + +static void __bt_gatt_destroy_characteristic(bt_gatt_h gatt_handle) +{ + bt_gatt_characteristic_s *chr = (bt_gatt_characteristic_s*)gatt_handle; + bt_gatt_service_s *parent_svc = (bt_gatt_service_s*)chr->parent; + + if (parent_svc) + parent_svc->characteristics = g_slist_remove(parent_svc->characteristics, chr); + + __bt_gatt_free_characteristic(gatt_handle); +} + +static void __bt_gatt_destroy_service(bt_gatt_h gatt_handle) +{ + bt_gatt_service_s *svc = (bt_gatt_service_s*)gatt_handle; + bt_gatt_server_s *server = NULL; + bt_gatt_client_s *client = NULL; + bt_gatt_service_s *parent_svc = NULL; + + if (svc->is_included_service == FALSE) { + if (svc->role == BT_GATT_ROLE_SERVER) { + server = (bt_gatt_server_s*)svc->parent; + if (server) + server->services = g_slist_remove(server->services, svc); + } else { + client = (bt_gatt_client_s*)svc->parent; + if (client) + client->services = g_slist_remove(client->services, svc); + } + } else { + parent_svc = (bt_gatt_service_s*)svc->parent; + if (parent_svc) + parent_svc->included_services = g_slist_remove(parent_svc->included_services, svc); + } + + __bt_gatt_free_service(gatt_handle); +} + +static int __convert_int_to_signed_bits(int i, int size) +{ + if (i < 0) + i = (1 << (size - 1)) + (i & ((1 << (size - 1)) - 1)); + + return i; + } + +static int __convert_unsigned_to_signed(int value, int size) +{ + if ((value & (1 << (size-1))) != 0) { + value = -1 * ((1 << (size-1)) - (value & ((1 << (size-1)) - 1))); + } + return value; +} + +static int __convert_unsigned_byte_to_int(char b) +{ + return b & 0xFF; +} + +static int __convert_unsigned_bytes_to_int16(char b0, char b1) +{ + return (__convert_unsigned_byte_to_int(b0) + (__convert_unsigned_byte_to_int(b1) << 8)); +} + +static int __convert_unsigned_bytes_to_int32(char b0, char b1, char b2, char b3) +{ + return (__convert_unsigned_byte_to_int(b0) + (__convert_unsigned_byte_to_int(b1) << 8)) + + (__convert_unsigned_byte_to_int(b2) << 16) + (__convert_unsigned_byte_to_int(b3) << 24); +} + +static float __convert_bytes_to_short_float(char b0, char b1) +{ + int mantissa; + int exponent; + float tmp; + mantissa = __convert_unsigned_to_signed(__convert_unsigned_byte_to_int(b0) + + ((__convert_unsigned_byte_to_int(b1) & 0x0F) << 8), 12); + exponent = __convert_unsigned_to_signed(__convert_unsigned_byte_to_int(b1) >> 4, 4); + tmp = pow(10, exponent); + + return (float)(mantissa * tmp); +} + +float __convert_bytes_to_float(char b0, char b1, char b2, char b3) +{ + int mantissa; + float exponent; + mantissa = __convert_unsigned_to_signed(__convert_unsigned_byte_to_int(b0) + + (__convert_unsigned_byte_to_int(b1) << 8) + + (__convert_unsigned_byte_to_int(b2) << 16), 24); + exponent = pow(10, b3); + + return (float)(mantissa * exponent); +} + +static int __get_data_type_float_size(bt_data_type_float_e type) +{ + switch (type) { + case BT_DATA_TYPE_SFLOAT: + return 2; + case BT_DATA_TYPE_FLOAT: + return 4; + default: + return 0; + } + } + +static int __get_data_type_int_size(bt_data_type_int_e format) +{ + switch (format) { + case BT_DATA_TYPE_SINT8: + case BT_DATA_TYPE_UINT8: + return 1; + case BT_DATA_TYPE_SINT16: + case BT_DATA_TYPE_UINT16: + return 2; + case BT_DATA_TYPE_SINT32: + case BT_DATA_TYPE_UINT32: + return 4; + default: + return 0; + } + } + +int bt_gatt_destroy(bt_gatt_h gatt_handle) +{ + bt_gatt_common_s *handle = (bt_gatt_common_s*)gatt_handle; + + BT_CHECK_INPUT_PARAMETER(gatt_handle); + + if (handle->type == BT_GATT_TYPE_SERVICE) + __bt_gatt_destroy_service(gatt_handle); + else if (handle->type == BT_GATT_TYPE_CHARACTERISTIC) + __bt_gatt_destroy_characteristic(gatt_handle); + else if (handle->type == BT_GATT_TYPE_DESCRIPTOR) + __bt_gatt_destroy_descriptor(gatt_handle); + else { + BT_ERR("Type is invalid(type:%d)", handle->type); + return BT_ERROR_INVALID_PARAMETER; + } + + return BT_ERROR_NONE; +} + +int bt_gatt_get_value(bt_gatt_h gatt_handle, char **value, int *value_length) +{ + bt_gatt_common_s *handle = (bt_gatt_common_s*)gatt_handle; + bt_gatt_characteristic_s *chr = (bt_gatt_characteristic_s*)gatt_handle; + bt_gatt_descriptor_s *desc = (bt_gatt_descriptor_s*)gatt_handle; + + BT_CHECK_GATT_SUPPORT(); + BT_CHECK_INPUT_PARAMETER(gatt_handle); + BT_CHECK_INPUT_PARAMETER(value); + BT_CHECK_INPUT_PARAMETER(value_length); + + if (handle->type == BT_GATT_TYPE_CHARACTERISTIC) { + *value_length = chr->value_length; + if (chr->value_length > 0) + *value = g_memdup(chr->value, chr->value_length); + } else if (handle->type == BT_GATT_TYPE_DESCRIPTOR) { + *value_length = desc->value_length; + if (desc->value_length > 0) + *value = g_memdup(desc->value, desc->value_length); + } else { + BT_ERR("Type is invalid(type:%d)", handle->type); + return BT_ERROR_INVALID_PARAMETER; + } + + return BT_ERROR_NONE; +} + +int bt_gatt_get_int_value(bt_gatt_h gatt_handle, bt_data_type_int_e type, int offset, int *value) +{ + char *val; + int val_len; + bt_gatt_common_s *handle = (bt_gatt_common_s*)gatt_handle; + bt_gatt_characteristic_s *chr = (bt_gatt_characteristic_s*)gatt_handle; + bt_gatt_descriptor_s *desc = (bt_gatt_descriptor_s*)gatt_handle; + + BT_CHECK_GATT_SUPPORT(); + BT_CHECK_INPUT_PARAMETER(gatt_handle); + BT_CHECK_INPUT_PARAMETER(value); + + if (handle->type == BT_GATT_TYPE_CHARACTERISTIC) { + val = chr->value; + val_len = chr->value_length; + } else if (handle->type == BT_GATT_TYPE_DESCRIPTOR) { + val = desc->value; + val_len = desc->value_length; + } else { + BT_ERR("Type is invalid(type:%d)", handle->type); + return BT_ERROR_INVALID_PARAMETER; + } + + if ((offset + __get_data_type_int_size(type)) > val_len) { + BT_ERR("Offset exceed the memory"); + return BT_ERROR_INVALID_PARAMETER; + } + + switch (type) { + case BT_DATA_TYPE_UINT8: + *value = __convert_unsigned_byte_to_int(val[offset]); + break; + case BT_DATA_TYPE_UINT16: + *value = __convert_unsigned_bytes_to_int16(val[offset], val[offset+1]); + break; + + case BT_DATA_TYPE_UINT32: + *value = __convert_unsigned_bytes_to_int32(val[offset], val[offset+1], + val[offset+2], val[offset+3]); + break; + case BT_DATA_TYPE_SINT8: + *value = __convert_unsigned_to_signed(__convert_unsigned_byte_to_int(val[offset]), 8); + break; + + case BT_DATA_TYPE_SINT16: + *value = __convert_unsigned_to_signed(__convert_unsigned_bytes_to_int16(val[offset], + val[offset+1]), 16); + break; + + case BT_DATA_TYPE_SINT32: + *value = __convert_unsigned_to_signed(__convert_unsigned_bytes_to_int32(val[offset], + val[offset+1], val[offset+2], val[offset+3]), 32); + break; + default: + return BT_ERROR_INVALID_PARAMETER; + } + + return BT_ERROR_NONE; +} + +int bt_gatt_get_float_value(bt_gatt_h gatt_handle, bt_data_type_float_e type, int offset, float *value) +{ + char *val; + int val_len; + bt_gatt_common_s *handle = (bt_gatt_common_s*)gatt_handle; + bt_gatt_characteristic_s *chr = (bt_gatt_characteristic_s*)gatt_handle; + bt_gatt_descriptor_s *desc = (bt_gatt_descriptor_s*)gatt_handle; + + BT_CHECK_GATT_SUPPORT(); + BT_CHECK_INPUT_PARAMETER(gatt_handle); + BT_CHECK_INPUT_PARAMETER(value); + + if (handle->type == BT_GATT_TYPE_CHARACTERISTIC) { + val = chr->value; + val_len = chr->value_length; + } else if (handle->type == BT_GATT_TYPE_DESCRIPTOR) { + val = desc->value; + val_len = desc->value_length; + } else { + BT_ERR("Type is invalid(type:%d)", handle->type); + return BT_ERROR_INVALID_PARAMETER; + } + + if ((offset + __get_data_type_float_size(type)) > val_len) { + BT_ERR("Offset exceed the memory"); + return BT_ERROR_INVALID_PARAMETER; + } + + switch (type) { + case BT_DATA_TYPE_SFLOAT: + *value = __convert_bytes_to_short_float(val[offset], val[offset+1]); + break; + + case BT_DATA_TYPE_FLOAT: + *value = __convert_bytes_to_float(val[offset], val[offset+1], + val[offset+2], val[offset+3]); + break; + default: + return BT_ERROR_INVALID_PARAMETER; + } + + return BT_ERROR_NONE; +} + +int bt_gatt_set_value(bt_gatt_h gatt_handle, const char *value, int value_length) +{ + int ret; + char **val = NULL; + int *val_len = NULL; + bt_gatt_common_s *handle = (bt_gatt_common_s*)gatt_handle; + bt_gatt_characteristic_s *chr = (bt_gatt_characteristic_s*)gatt_handle; + bt_gatt_descriptor_s *desc = (bt_gatt_descriptor_s*)gatt_handle; + + BT_CHECK_GATT_SUPPORT(); + BT_CHECK_INPUT_PARAMETER(gatt_handle); + BT_CHECK_INPUT_PARAMETER(value); + + if (handle->type == BT_GATT_TYPE_CHARACTERISTIC) { + val = &chr->value; + val_len = &chr->value_length; + } else if (handle->type == BT_GATT_TYPE_DESCRIPTOR) { + val = &desc->value; + val_len = &desc->value_length; + } else { + BT_ERR("Type is invalid(type:%d)", handle->type); + return BT_ERROR_INVALID_PARAMETER; + } + + if (handle->role == BT_GATT_ROLE_SERVER && handle->path) { + ret = _bt_get_error_code(bluetooth_gatt_update_characteristic(handle->path, value, value_length)); + if (ret != BT_ERROR_NONE) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); + return ret; + } + } + + g_free(*val); + *val = NULL; + if (value_length > 0) + *val = g_memdup(value, value_length); + *val_len = value_length; + + return BT_ERROR_NONE; +} + +int bt_gatt_set_int_value(bt_gatt_h gatt_handle, bt_data_type_int_e type, int value, int offset) +{ + int ret; + char **val = NULL; + int *val_len = NULL; + char *tmp; + int fmt_size; + int idx = offset; + bt_gatt_common_s *handle = (bt_gatt_common_s*)gatt_handle; + bt_gatt_characteristic_s *chr = (bt_gatt_characteristic_s*)gatt_handle; + bt_gatt_descriptor_s *desc = (bt_gatt_descriptor_s*)gatt_handle; + + BT_CHECK_GATT_SUPPORT(); + BT_CHECK_INPUT_PARAMETER(gatt_handle); + + if (handle->type == BT_GATT_TYPE_CHARACTERISTIC) { + val = &chr->value; + val_len = &chr->value_length; + } else if (handle->type == BT_GATT_TYPE_DESCRIPTOR) { + val = &desc->value; + val_len = &desc->value_length; + } else { + BT_ERR("Type is invalid(type:%d)", handle->type); + return BT_ERROR_INVALID_PARAMETER; + } + + if (*val_len < offset) { + BT_ERR("Offset is invalid"); + return BT_ERROR_INVALID_PARAMETER; + } + + fmt_size = __get_data_type_int_size(type); + if (*val == NULL) { + *val = g_malloc0(fmt_size); + *val_len = fmt_size; + } else if (*val_len == offset) {// Added + tmp = g_malloc0(*val_len + fmt_size); + /* Fix : NULL_RETURNS */ + if (!tmp) { + g_free(*val); + return BT_ERROR_OUT_OF_MEMORY; + } + memcpy(tmp, *val, *val_len); + g_free(*val); + *val = tmp; + *val_len += fmt_size; + } else if (*val_len < offset + fmt_size) {// Overlapped + tmp = g_malloc0(offset + fmt_size); + /* Fix : NULL_RETURNS */ + if (!tmp) { + g_free(*val); + return BT_ERROR_OUT_OF_MEMORY; + } + memcpy(tmp, *val, *val_len); + g_free(*val); + *val = tmp; + *val_len = offset + fmt_size; + } + + switch (type) { + case BT_DATA_TYPE_SINT8: + value = __convert_int_to_signed_bits(value, 8); + case BT_DATA_TYPE_UINT8: + if (*val) + (*val)[idx] = (char)(value & 0xFF); + break; + + case BT_DATA_TYPE_SINT16: + value = __convert_int_to_signed_bits(value, 16); + case BT_DATA_TYPE_UINT16: + if (*val) { + (*val)[idx++] = (char)(value & 0xFF); + (*val)[idx] = (char)((value >> 8) & 0xFF); + } + break; + + case BT_DATA_TYPE_SINT32: + value = __convert_int_to_signed_bits(value, 32); + case BT_DATA_TYPE_UINT32: + if (*val) { + (*val)[idx++] = (char)(value & 0xFF); + (*val)[idx++] = (char)((value >> 8) & 0xFF); + (*val)[idx++] = (char)((value >> 16) & 0xFF); + (*val)[idx] = (char)((value >> 24) & 0xFF); + } + break; + + default: + return BT_ERROR_INVALID_PARAMETER; + } + + if (handle->role == BT_GATT_ROLE_SERVER && handle->path) { + ret = _bt_get_error_code(bluetooth_gatt_update_characteristic(handle->path, *val, *val_len)); + if (ret != BT_ERROR_NONE) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); + return ret; + } + } + + return BT_ERROR_NONE; +} + +int bt_gatt_set_float_value(bt_gatt_h gatt_handle, bt_data_type_float_e type, + int mantissa, int exponent, int offset) +{ + int ret; + char **val = NULL; + int *val_len = NULL; + int mant; + int exp; + char *tmp; + int fmt_size; + int idx = offset; + bt_gatt_common_s *handle = (bt_gatt_common_s*)gatt_handle; + bt_gatt_characteristic_s *chr = (bt_gatt_characteristic_s*)gatt_handle; + bt_gatt_descriptor_s *desc = (bt_gatt_descriptor_s*)gatt_handle; + + BT_CHECK_GATT_SUPPORT(); + BT_CHECK_INPUT_PARAMETER(gatt_handle); + + if (handle->type == BT_GATT_TYPE_CHARACTERISTIC) { + val = &chr->value; + val_len = &chr->value_length; + } else if (handle->type == BT_GATT_TYPE_DESCRIPTOR) { + val = &desc->value; + val_len = &desc->value_length; + } else { + BT_ERR("Type is invalid(type:%d)", handle->type); + return BT_ERROR_INVALID_PARAMETER; + } + + if (*val_len < offset) { + BT_ERR("Offset is invalid"); + return BT_ERROR_INVALID_PARAMETER; + } + + fmt_size = __get_data_type_float_size(type); + if (fmt_size == 0) { + BT_ERR("Format is invalid"); + return BT_ERROR_INVALID_PARAMETER; + } + + if (*val == NULL) { + *val = g_malloc0(fmt_size); + /* Fix : NULL_RETURNS */ + if (*val == NULL) + return BT_ERROR_OUT_OF_MEMORY; + *val_len = fmt_size; + } else if (*val_len == offset) {// Added + tmp = g_malloc0(*val_len + fmt_size); + /* Fix : NULL_RETURNS */ + if (tmp == NULL) { + g_free(*val); + return BT_ERROR_OUT_OF_MEMORY; + } + memcpy(tmp, *val, *val_len); + g_free(*val); + *val = tmp; + *val_len += fmt_size; + } else if (*val_len < offset + fmt_size) {// Overlapped + tmp = g_malloc0(offset + fmt_size); + /* Fix : NULL_RETURNS */ + if (tmp == NULL) { + g_free(*val); + return BT_ERROR_OUT_OF_MEMORY; + } + memcpy(tmp, *val, *val_len); + g_free(*val); + *val = tmp; + *val_len = offset + fmt_size; + } + + switch (type) { + case BT_DATA_TYPE_FLOAT: + mant = __convert_int_to_signed_bits(mantissa, 24); + exp = __convert_int_to_signed_bits(exponent, 8); + (*val)[idx++] = (char)(mant & 0xFF); + (*val)[idx++] = (char)((mant >> 8) & 0xFF); + (*val)[idx++] = (char)((mant >> 16) & 0xFF); + (*val)[idx] = (char)(exp & 0xFF); + break; + + case BT_DATA_TYPE_SFLOAT: + mant = __convert_int_to_signed_bits(mantissa, 12); + exp = __convert_int_to_signed_bits(exponent, 4); + (*val)[idx++] = (char)(mant & 0xFF); + (*val)[idx] = (char)((mant >> 8) & 0x0F); + (*val)[idx] += (char)((exp & 0x0F) << 4); + break; + + default: + return BT_ERROR_INVALID_PARAMETER; + } + + if (handle->role == BT_GATT_ROLE_SERVER && handle->path) { + ret = _bt_get_error_code(bluetooth_gatt_update_characteristic(handle->path, *val, *val_len)); + if (ret != BT_ERROR_NONE) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); + return ret; + } + } + + return BT_ERROR_NONE; +} + +int bt_gatt_get_permissions(bt_gatt_h gatt_handle, int *permissions) +{ + bt_gatt_common_s *handle = (bt_gatt_common_s*)gatt_handle; + bt_gatt_characteristic_s *chr = (bt_gatt_characteristic_s*)gatt_handle; + bt_gatt_descriptor_s *desc = (bt_gatt_descriptor_s*)gatt_handle; + + BT_CHECK_INPUT_PARAMETER(gatt_handle); + BT_CHECK_INPUT_PARAMETER(permissions); + + if (handle->type == BT_GATT_TYPE_CHARACTERISTIC) + *permissions = chr->permissions; + else if (handle->type == BT_GATT_TYPE_DESCRIPTOR) + *permissions = desc->permissions; + else { + BT_ERR("Type is invalid(type:%d)", handle->type); + return BT_ERROR_INVALID_PARAMETER; + } + + return BT_ERROR_NONE; +} + +int bt_gatt_set_permissions(bt_gatt_h gatt_handle, int permissions) +{ + bt_gatt_common_s *handle = (bt_gatt_common_s*)gatt_handle; + bt_gatt_characteristic_s *chr = (bt_gatt_characteristic_s*)gatt_handle; + bt_gatt_descriptor_s *desc = (bt_gatt_descriptor_s*)gatt_handle; + + BT_CHECK_INPUT_PARAMETER(gatt_handle); + + if (handle->type == BT_GATT_TYPE_CHARACTERISTIC) + chr->permissions = permissions; + else if (handle->type == BT_GATT_TYPE_DESCRIPTOR) + desc->permissions = permissions; + else { + BT_ERR("Type is invalid(type:%d)", handle->type); + return BT_ERROR_INVALID_PARAMETER; + } + + return BT_ERROR_NONE; +} + +int bt_gatt_get_uuid(bt_gatt_h gatt_handle, char **uuid) +{ + bt_gatt_common_s *handle = (bt_gatt_common_s*)gatt_handle; + + BT_CHECK_GATT_SUPPORT(); + BT_CHECK_INPUT_PARAMETER(gatt_handle); + BT_CHECK_INPUT_PARAMETER(uuid); + + *uuid = g_strdup(handle->uuid); + + return BT_ERROR_NONE; +} + +int bt_gatt_get_type(bt_gatt_h gatt_handle, bt_gatt_type_e *gatt_type) +{ + bt_gatt_common_s *handle = (bt_gatt_common_s*)gatt_handle; + + BT_CHECK_GATT_SUPPORT(); + BT_CHECK_INPUT_PARAMETER(gatt_handle); + BT_CHECK_INPUT_PARAMETER(gatt_type); + + *gatt_type = handle->type; + + return BT_ERROR_NONE; +} + +int bt_gatt_service_create(const char *uuid, bt_gatt_service_type_e type, + bt_gatt_h *service) +{ + bt_gatt_service_s *svc; + + BT_CHECK_INPUT_PARAMETER(uuid); + BT_CHECK_INPUT_PARAMETER(service); + + svc = (bt_gatt_service_s*)g_malloc0(sizeof(bt_gatt_service_s)); + if (svc == NULL) + return BT_ERROR_OUT_OF_MEMORY; + svc->type = BT_GATT_TYPE_SERVICE; + svc->role = BT_GATT_ROLE_SERVER; + if (strlen(uuid) == 8) + svc->uuid = __convert_uuid_to_uuid128(uuid); + else + svc->uuid = strdup(uuid); + if (svc->uuid == NULL) { + g_free(svc); + return BT_ERROR_OUT_OF_MEMORY; + } + svc->is_included_service = false; + svc->service_type = type; + + *service = (bt_gatt_h)svc; + + return BT_ERROR_NONE; +} + +int bt_gatt_service_add_characteristic(bt_gatt_h service, + bt_gatt_h characteristic) +{ + bt_gatt_service_s *svc = (bt_gatt_service_s*)service; + bt_gatt_characteristic_s *chr = (bt_gatt_characteristic_s*)characteristic; + + BT_CHECK_INPUT_PARAMETER(service); + BT_CHECK_INPUT_PARAMETER(characteristic); + if (chr->parent) { + BT_ERR("This characteristic is already added."); + return BT_ERROR_INVALID_PARAMETER; + } + + svc->characteristics = g_slist_append(svc->characteristics, chr); + chr->parent = (void *)service; + + return BT_ERROR_NONE; +} + +int bt_gatt_service_add_included_service(bt_gatt_h service, + bt_gatt_h included_service) +{ + bt_gatt_service_s *svc = (bt_gatt_service_s*)service; + bt_gatt_service_s *included_svc = (bt_gatt_service_s*)included_service; + + BT_CHECK_INPUT_PARAMETER(service); + BT_CHECK_INPUT_PARAMETER(included_service); + if (included_svc->parent) { + BT_ERR("This service is already added."); + return BT_ERROR_INVALID_PARAMETER; + } + + svc->included_services = g_slist_append(svc->included_services, included_svc); + included_svc->parent = (void *)service; + + return BT_ERROR_NONE; +} + +int bt_gatt_service_get_server(bt_gatt_h service, bt_gatt_server_h *server) +{ + bt_gatt_service_s *svc = (bt_gatt_service_s *)service; + + BT_CHECK_INPUT_PARAMETER(service); + BT_CHECK_INPUT_PARAMETER(server); + + if (svc->is_included_service) { + BT_ERR("This is included service of %p", svc->parent); + return BT_ERROR_INVALID_PARAMETER; + } + + if (svc->role != BT_GATT_ROLE_SERVER) { + BT_ERR("This is not server's service"); + return BT_ERROR_INVALID_PARAMETER; + } + + *server = (bt_gatt_server_h)svc->parent; + + return BT_ERROR_NONE; +} + +int bt_gatt_service_get_client(bt_gatt_h service, bt_gatt_client_h *client) +{ + bt_gatt_service_s *svc = (bt_gatt_service_s *)service; + + BT_CHECK_GATT_SUPPORT(); + BT_CHECK_INPUT_PARAMETER(service); + BT_CHECK_INPUT_PARAMETER(client); + + if (svc->is_included_service) { + BT_ERR("This is included service of %p", svc->parent); + return BT_ERROR_INVALID_PARAMETER; + } + + if (svc->role != BT_GATT_ROLE_CLIENT) { + BT_ERR("This is not client's service"); + return BT_ERROR_INVALID_PARAMETER; + } + + *client = (bt_gatt_client_h)svc->parent; + + return BT_ERROR_NONE; +} + +int bt_gatt_service_get_characteristic(bt_gatt_h service, const char *uuid, + bt_gatt_h *characteristic) +{ + bt_gatt_service_s *svc = (bt_gatt_service_s*)service; + bt_gatt_h gatt_handle = NULL; + int ret; + + BT_CHECK_GATT_SUPPORT(); + BT_CHECK_INPUT_PARAMETER(service); + BT_CHECK_INPUT_PARAMETER(uuid); + BT_CHECK_INPUT_PARAMETER(characteristic); + + ret = __get_gatt_handle_by_uuid(svc->characteristics, uuid, &gatt_handle); + if (ret == BT_ERROR_NONE && gatt_handle != NULL) { + *characteristic = gatt_handle; + return BT_ERROR_NONE; + } + + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); + return ret; +} + +int bt_gatt_service_foreach_characteristics(bt_gatt_h service, + bt_gatt_foreach_cb callback, void *user_data) +{ + bt_gatt_service_s *svc = (bt_gatt_service_s*)service; + bt_gatt_characteristic_s *chr = NULL; + GSList *l = NULL; + int total = 0; + int index = 1; + + BT_CHECK_GATT_SUPPORT(); + BT_CHECK_INPUT_PARAMETER(service); + BT_CHECK_INPUT_PARAMETER(callback); + + total = g_slist_length(svc->characteristics); + + for (l = svc->characteristics; l; l = g_slist_next(l)) { + chr = l->data; + if (!callback(total, index++, (bt_gatt_h)chr, user_data)) + break; + } + + return BT_ERROR_NONE; +} + +int bt_gatt_service_get_included_service(bt_gatt_h service, const char *uuid, + bt_gatt_h *included_service) +{ + bt_gatt_service_s *svc = (bt_gatt_service_s*)service; + bt_gatt_h gatt_handle = NULL; + int ret; + + BT_CHECK_GATT_SUPPORT(); + BT_CHECK_INPUT_PARAMETER(service); + BT_CHECK_INPUT_PARAMETER(uuid); + BT_CHECK_INPUT_PARAMETER(included_service); + + ret = __get_gatt_handle_by_uuid(svc->included_services, uuid, &gatt_handle); + if (ret == BT_ERROR_NONE && gatt_handle != NULL) { + *included_service = gatt_handle; + return BT_ERROR_NONE; + } + + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); + return ret; +} + +int bt_gatt_service_foreach_included_services(bt_gatt_h service, + bt_gatt_foreach_cb callback, void *user_data) +{ + bt_gatt_service_s *svc = (bt_gatt_service_s*)service; + bt_gatt_service_s *included_svc = NULL; + GSList *l = NULL; + int total = 0; + int index = 1; + + BT_CHECK_GATT_SUPPORT(); + BT_CHECK_INPUT_PARAMETER(service); + BT_CHECK_INPUT_PARAMETER(callback); + + total = g_slist_length(svc->included_services); + + for (l = svc->included_services; l; l = g_slist_next(l)) { + included_svc = l->data; + if (!callback(total, index++, (bt_gatt_h)included_svc, user_data)) + break; + } + + return BT_ERROR_NONE; +} + +int bt_gatt_characteristic_create(const char *uuid, int permissions, + int properties, const char *value, int value_length, + bt_gatt_h *characteristic) +{ + int ret = BT_ERROR_NONE; + bt_gatt_characteristic_s *chr = NULL; + + BT_CHECK_INPUT_PARAMETER(uuid); + BT_CHECK_INPUT_PARAMETER(characteristic); + if (value_length > 0) + BT_CHECK_INPUT_PARAMETER(value); + + chr = malloc(sizeof(*chr)); + if (chr == NULL) + return BT_ERROR_OUT_OF_MEMORY; + + memset(chr, 0x00, sizeof(*chr)); + + chr->type = BT_GATT_TYPE_CHARACTERISTIC; + chr->role = BT_GATT_ROLE_SERVER; + if (strlen(uuid) == 8) + chr->uuid = __convert_uuid_to_uuid128(uuid); + else + chr->uuid = g_strdup(uuid); + if (chr->uuid == NULL) { + ret = BT_ERROR_OUT_OF_MEMORY; + goto fail; + } + chr->permissions = permissions; + chr->properties = properties; + chr->write_type = BT_GATT_WRITE_TYPE_WRITE; + chr->value_length = value_length; + if (value_length > 0) { + chr->value = g_memdup(value, value_length); + if (chr->value == NULL) { + ret = BT_ERROR_OUT_OF_MEMORY; + goto fail; + } + } + + *characteristic = (bt_gatt_h)chr; + + return BT_ERROR_NONE; + +fail: + g_free(chr->value); + g_free(chr->uuid); + g_free(chr); + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); + return ret; +} + +int bt_gatt_characteristic_add_descriptor(bt_gatt_h characteristic, + bt_gatt_h descriptor) +{ + bt_gatt_characteristic_s *chr = (bt_gatt_characteristic_s *)characteristic; + bt_gatt_descriptor_s *desc = (bt_gatt_descriptor_s *)descriptor; + + BT_CHECK_INPUT_PARAMETER(characteristic); + BT_CHECK_INPUT_PARAMETER(descriptor); + + if (chr->type != BT_GATT_TYPE_CHARACTERISTIC || + desc->type != BT_GATT_TYPE_DESCRIPTOR) { + BT_ERR("Wrong type. chr : %d, desc : %d", chr->type, desc->type); + return BT_ERROR_INVALID_PARAMETER; + } + + if (desc->parent) { + BT_ERR("Already added descriptor : %p", desc->parent); + return BT_ERROR_INVALID_PARAMETER; + } + + chr->descriptors = g_slist_append(chr->descriptors, desc); + desc->parent = (void *)characteristic; + + return BT_ERROR_NONE; +} + +int bt_gatt_characteristic_get_service(bt_gatt_h characteristic, bt_gatt_h *service) +{ + bt_gatt_characteristic_s *chr = (bt_gatt_characteristic_s *)characteristic; + + BT_CHECK_GATT_SUPPORT(); + BT_CHECK_INPUT_PARAMETER(characteristic); + BT_CHECK_INPUT_PARAMETER(service); + + *service = (bt_gatt_h)chr->parent; + + return BT_ERROR_NONE; +} + +int bt_gatt_characteristic_get_properties(bt_gatt_h characteristic, int *properties) +{ + bt_gatt_characteristic_s *chr = (bt_gatt_characteristic_s *)characteristic; + + BT_CHECK_GATT_SUPPORT(); + BT_CHECK_INPUT_PARAMETER(characteristic); + BT_CHECK_INPUT_PARAMETER(properties); + + if (chr->type != BT_GATT_TYPE_CHARACTERISTIC) { + BT_ERR("Wrong type of GATT handle : %d", chr->type); + return BT_ERROR_INVALID_PARAMETER; + } + + *properties = chr->properties; + + return BT_ERROR_NONE; +} + +int bt_gatt_characteristic_set_properties(bt_gatt_h characteristic, int properties) +{ + bt_gatt_characteristic_s *chr = (bt_gatt_characteristic_s *)characteristic; + + BT_CHECK_INPUT_PARAMETER(characteristic); + + if (chr->type != BT_GATT_TYPE_CHARACTERISTIC) { + BT_ERR("Wrong type of GATT handle : %d", chr->type); + return BT_ERROR_INVALID_PARAMETER; + } + + chr->properties = properties; + + return BT_ERROR_NONE; +} + +int bt_gatt_characteristic_get_write_type(bt_gatt_h characteristic, + bt_gatt_write_type_e *write_type) +{ + bt_gatt_characteristic_s *chr = (bt_gatt_characteristic_s *)characteristic; + + BT_CHECK_GATT_SUPPORT(); + BT_CHECK_INPUT_PARAMETER(characteristic); + BT_CHECK_INPUT_PARAMETER(write_type); + + if (chr->type != BT_GATT_TYPE_CHARACTERISTIC) { + BT_ERR("Wrong type of GATT handle : %d", chr->type); + return BT_ERROR_INVALID_PARAMETER; + } + + *write_type = chr->write_type; + + return BT_ERROR_NONE; +} + +int bt_gatt_characteristic_set_write_type(bt_gatt_h characteristic, + bt_gatt_write_type_e write_type) +{ + bt_gatt_characteristic_s *chr = (bt_gatt_characteristic_s *)characteristic; + + BT_CHECK_GATT_SUPPORT(); + BT_CHECK_INPUT_PARAMETER(characteristic); + + if (chr->type != BT_GATT_TYPE_CHARACTERISTIC) { + BT_ERR("Wrong type of GATT handle : %d", chr->type); + return BT_ERROR_INVALID_PARAMETER; + } + + chr->write_type = write_type; + + return BT_ERROR_NONE; +} + +int bt_gatt_characteristic_get_descriptor(bt_gatt_h characteristic, const char *uuid, + bt_gatt_h *descriptor) +{ + bt_gatt_characteristic_s *chr = (bt_gatt_characteristic_s *)characteristic; + bt_gatt_h gatt_handle = NULL; + int ret; + + BT_CHECK_GATT_SUPPORT(); + BT_CHECK_INPUT_PARAMETER(characteristic); + BT_CHECK_INPUT_PARAMETER(uuid); + BT_CHECK_INPUT_PARAMETER(descriptor); + + ret = __get_gatt_handle_by_uuid(chr->descriptors, uuid, &gatt_handle); + if (ret == BT_ERROR_NONE && gatt_handle != NULL) { + *descriptor = gatt_handle; + return BT_ERROR_NONE; + } + + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); + return ret; +} + +int bt_gatt_characteristic_foreach_descriptors(bt_gatt_h characteristic, + bt_gatt_foreach_cb callback, void *user_data) +{ + GSList *l; + bt_gatt_characteristic_s *chr = (bt_gatt_characteristic_s *)characteristic; + int total; + int i; + + BT_CHECK_GATT_SUPPORT(); + BT_CHECK_INPUT_PARAMETER(characteristic); + BT_CHECK_INPUT_PARAMETER(callback); + + if (chr->type != BT_GATT_TYPE_CHARACTERISTIC) { + BT_ERR("Wrong type of GATT handle : %d", chr->type); + return BT_ERROR_INVALID_PARAMETER; + } + + total = g_slist_length(chr->descriptors); + + i = 1; + for (l = chr->descriptors; l; l = g_slist_next(l)) { + if (!callback(total, i++, (bt_gatt_h)l->data, user_data)) + break; + } + + return BT_ERROR_NONE; +} + +int bt_gatt_descriptor_create(const char *uuid, int permissions, + const char *value, int value_length, + bt_gatt_h *descriptor) +{ + int ret = BT_ERROR_NONE; + bt_gatt_descriptor_s *desc = NULL; + + BT_CHECK_INPUT_PARAMETER(uuid); + BT_CHECK_INPUT_PARAMETER(descriptor); + if (value_length > 0) + BT_CHECK_INPUT_PARAMETER(value); + + desc = malloc(sizeof(*desc)); + if (desc == NULL) + return BT_ERROR_OUT_OF_MEMORY; + + memset(desc, 0x00, sizeof(*desc)); + + desc->type = BT_GATT_TYPE_DESCRIPTOR; + desc->role = BT_GATT_ROLE_SERVER; + if (strlen(uuid) == 8) + desc->uuid = __convert_uuid_to_uuid128(uuid); + else + desc->uuid = g_strdup(uuid); + if (desc->uuid == NULL) { + ret = BT_ERROR_OUT_OF_MEMORY; + goto fail; + } + desc->permissions = permissions; + desc->value_length = value_length; + if (value_length > 0) { + desc->value = g_memdup(value, value_length); + if (desc->value == NULL) { + ret = BT_ERROR_OUT_OF_MEMORY; + goto fail; + } + } + + *descriptor = (bt_gatt_h)desc; + + return ret; + +fail: + g_free(desc->uuid); + g_free(desc->value); + g_free(desc); + + return ret; +} + +int bt_gatt_descriptor_get_characteristic(bt_gatt_h descriptor, bt_gatt_h *characteristic) +{ + bt_gatt_descriptor_s *desc = (bt_gatt_descriptor_s *)descriptor; + + BT_CHECK_GATT_SUPPORT(); + BT_CHECK_INPUT_PARAMETER(descriptor); + BT_CHECK_INPUT_PARAMETER(characteristic); + + *characteristic = (bt_gatt_h)desc->parent; + + return BT_ERROR_NONE; +} + +int bt_gatt_server_initialize(void) +{ + BT_CHECK_INIT_STATUS(); + + int ret = BT_ERROR_NONE; + + if (!is_gatt_server_initialized) { + ret = _bt_get_error_code(bluetooth_gatt_init()); + + if (ret != BT_ERROR_NONE) { + BT_ERR("%s(0x%08x)", + _bt_convert_error_to_string(ret), ret); + return BT_ERROR_OPERATION_FAILED; + } + + is_gatt_server_initialized = true; + return BT_ERROR_NONE; + } + + BT_DBG("Gatt-service already initialized"); + + return ret; +} + +int bt_gatt_server_deinitialize(void) +{ + BT_CHECK_INIT_STATUS(); + + int ret = BT_ERROR_NONE; + + if (is_gatt_server_initialized) { + GSList *l; + for (l = gatt_server_list; l; l = g_slist_next(l)) { + bt_gatt_server_s *serv = l->data; + g_slist_free_full(serv->services, __bt_gatt_free_service); + g_free(serv); + } + g_slist_free(gatt_server_list); + gatt_server_list = NULL; + + ret = _bt_get_error_code(bluetooth_gatt_deinit()); + + if (ret != BT_ERROR_NONE) { + BT_ERR("%s(0x%08x)", + _bt_convert_error_to_string(ret), ret); + return BT_ERROR_OPERATION_FAILED; + } + + is_gatt_server_initialized = false; + return BT_ERROR_NONE; + } + + BT_DBG("Gatt-service is not initialized"); + + return ret; +} + +int bt_gatt_server_create(bt_gatt_server_h *server) +{ + bt_gatt_server_s *serv = NULL; + + BT_CHECK_INPUT_PARAMETER(server); + + serv = g_malloc0(sizeof(bt_gatt_server_s)); + if (serv == NULL) + return BT_ERROR_OUT_OF_MEMORY; + + *server = (bt_gatt_server_h)serv; + + gatt_server_list = g_slist_append(gatt_server_list, serv); + + return BT_ERROR_NONE; +} + +int bt_gatt_server_destroy(bt_gatt_server_h server) +{ + bt_gatt_server_s *serv = (bt_gatt_server_s*)server; + + BT_CHECK_INPUT_PARAMETER(server); + + g_slist_free_full(serv->services, __bt_gatt_free_service); + gatt_server_list = g_slist_remove(gatt_server_list, serv); + g_free(serv); + + return BT_ERROR_NONE; +} + +int bt_gatt_server_set_read_value_requested_cb(bt_gatt_h gatt_handle, + bt_gatt_server_read_value_requested_cb callback, + void *user_data) +{ + bt_gatt_characteristic_s *chr = (bt_gatt_characteristic_s*)gatt_handle; + + BT_CHECK_INIT_STATUS(); + BT_CHECK_GATT_SERVER_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(gatt_handle); + BT_CHECK_INPUT_PARAMETER(callback); + + chr->read_requested_cb = callback; + chr->read_requested_user_data = user_data; + + _bt_set_cb(BT_EVENT_GATT_SERVER_READ_REQUESTED, callback, user_data); + + return BT_ERROR_NONE; +} + +int bt_gatt_server_register_service(bt_gatt_server_h server, bt_gatt_h service) +{ + int ret = BT_ERROR_NONE; + bt_gatt_server_s *serv = (bt_gatt_server_s*)server; + bt_gatt_service_s *svc = (bt_gatt_service_s*)service; + GSList *char_l; + + BT_CHECK_INIT_STATUS(); + BT_CHECK_GATT_SERVER_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(server); + BT_CHECK_INPUT_PARAMETER(service); + + if (g_slist_find(serv->services, svc)) { + BT_ERR("Already added service."); + return BT_ERROR_ALREADY_DONE; + } + + ret = _bt_get_error_code(bluetooth_gatt_add_service(svc->uuid, &svc->path)); + + if (ret != BT_ERROR_NONE) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); + return ret; + } + + for (char_l = svc->characteristics; char_l; char_l = g_slist_next(char_l)) { + GSList *desc_l; + bt_gatt_characteristic_s *chr = char_l->data; + + ret = _bt_get_error_code(bluetooth_gatt_add_new_characteristic(svc->path, chr->uuid, + (bt_gatt_characteristic_property_t)chr->properties, &chr->path)); + if (ret != BT_ERROR_NONE) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); + goto fail; + } + + ret = _bt_get_error_code(bluetooth_gatt_set_characteristic_value(chr->path, + chr->value, chr->value_length)); + + if (ret != BT_ERROR_NONE) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); + goto fail; + } + + for (desc_l = chr->descriptors; desc_l; desc_l = g_slist_next(desc_l)) { + bt_gatt_descriptor_s *desc = desc_l->data; + + ret = _bt_get_error_code(bluetooth_gatt_add_descriptor(chr->path, desc->uuid, &desc->path)); + + if (ret != BT_ERROR_NONE) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); + goto fail; + } + + ret = _bt_get_error_code(bluetooth_gatt_set_descriptor_value(desc->path, desc->value, desc->value_length)); + + if (ret != BT_ERROR_NONE) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); + goto fail; + } + } + } + + ret = _bt_get_error_code(bluetooth_gatt_register_service(svc->path)); + + if (ret != BT_ERROR_NONE) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); + goto fail; + } + + serv->services = g_slist_append(serv->services, svc); + svc->parent = (void *)server; + + return ret; + +fail: + bluetooth_gatt_unregister_service(svc->path); + + return ret; +} + +int bt_gatt_server_unregister_service(bt_gatt_server_h server, bt_gatt_h service) +{ + bt_gatt_server_s *serv = (bt_gatt_server_s*)server; + bt_gatt_service_s *svc = (bt_gatt_service_s*)service; + + BT_CHECK_INIT_STATUS(); + BT_CHECK_GATT_SERVER_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(server); + BT_CHECK_INPUT_PARAMETER(service); + + if (!g_slist_find(serv->services, svc)) { + BT_ERR("Service is NOT found."); + return BT_ERROR_SERVICE_NOT_FOUND; + } + + __bt_gatt_destroy_service(svc); + + return BT_ERROR_NONE; +} + +int bt_gatt_server_unregister_all_services(bt_gatt_server_h server) +{ + bt_gatt_server_s *serv = (bt_gatt_server_s*)server; + + BT_CHECK_INIT_STATUS(); + BT_CHECK_GATT_SERVER_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(server); + + g_slist_free_full(serv->services, __bt_gatt_free_service); + serv->services = NULL; + + return BT_ERROR_NONE; +} + +int bt_gatt_server_send_response(int request_id, + int offset, char *value, int value_length) +{ + int ret = BT_ERROR_NONE; + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(value); + + if (value_length <= 0) + return BT_ERROR_INVALID_PARAMETER; + + ret = _bt_get_error_code(bluetooth_gatt_send_response(request_id, offset, value, value_length)); + + if (ret != BT_ERROR_NONE) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); + } + + return ret; +} + +int bt_gatt_server_notify(bt_gatt_h characteristic, bool need_confirm, + bt_gatt_server_notification_sent_cb callback, void *user_data) +{ + return BT_ERROR_NONE; +} + +int bt_gatt_server_set_value_changed_cb(bt_gatt_h characteristic, + bt_gatt_server_value_changed_cb callback, + void *user_data) +{ + bt_gatt_characteristic_s *chr = (bt_gatt_characteristic_s *)characteristic; + + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(characteristic); + BT_CHECK_INPUT_PARAMETER(callback); + + chr->server_value_changed_cb = callback; + chr->server_value_changed_user_data = user_data; + + return BT_ERROR_NONE; +} + +int bt_gatt_server_get_service(bt_gatt_server_h server, const char *uuid, + bt_gatt_h *service) +{ + bt_gatt_server_s *server_s = (bt_gatt_server_s *)server; + bt_gatt_h gatt_handle = NULL; + int ret; + + BT_CHECK_INPUT_PARAMETER(server); + BT_CHECK_INPUT_PARAMETER(uuid); + BT_CHECK_INPUT_PARAMETER(service); + + ret = __get_gatt_handle_by_uuid(server_s->services, uuid, &gatt_handle); + if (ret == BT_ERROR_NONE && gatt_handle != NULL) { + *service = gatt_handle; + return BT_ERROR_NONE; + } + + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); + return ret; +} + +int bt_gatt_server_foreach_services(bt_gatt_server_h server, + bt_gatt_foreach_cb callback, void *user_data) +{ + bt_gatt_server_s *server_s = (bt_gatt_server_s *)server; + GSList *l = NULL; + int total = 0; + int index = 1; + + BT_CHECK_INPUT_PARAMETER(server); + BT_CHECK_INPUT_PARAMETER(callback); + + total = g_slist_length(server_s->services); + + for (l = server_s->services; l; l = g_slist_next(l)) { + if (!callback(total, index++, (bt_gatt_h)l->data, user_data)) + break; + } + + return BT_ERROR_NONE; +} + +int bt_gatt_client_create(const char *remote_address, bt_gatt_client_h *client) +{ + int ret = BT_ERROR_NONE; + bt_gatt_client_s *client_s; + GSList *l; + + BT_CHECK_GATT_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(remote_address); + + for (l = gatt_client_list; l; l = g_slist_next(gatt_client_list)) { + bt_gatt_client_s *c = (bt_gatt_client_s *)l->data; + + if (!g_ascii_strcasecmp(c->remote_address, remote_address)) { + BT_ERR("Gatt client for %s is already created", + remote_address); + return BT_ERROR_ALREADY_DONE; + } + } + + client_s = g_malloc0(sizeof(*client_s)); + if (client_s == NULL) { + ret = BT_ERROR_OUT_OF_MEMORY; + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); + return ret; + } + memset(client_s, 0x00, sizeof(*client_s)); + + client_s->remote_address = g_strdup(remote_address); + if (client_s->remote_address == NULL) { + free(client_s); + ret = BT_ERROR_OUT_OF_MEMORY; + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); + return ret; + } + client_s->services_discovered = false; + + *client = (bt_gatt_client_h)client_s; + gatt_client_list = g_slist_append(gatt_client_list, client_s); + + + if (_bt_gatt_client_update_all(*client) == BT_ERROR_NONE) + client_s->services_discovered = true; + + return ret; +} + +int bt_gatt_client_destroy(bt_gatt_client_h client) +{ + bt_gatt_client_s *client_s = (bt_gatt_client_s *)client; + + BT_CHECK_GATT_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(client); + + g_free(client_s->remote_address); + g_slist_free_full(client_s->services, __bt_gatt_free_service); + gatt_client_list = g_slist_remove(gatt_client_list, client_s); + g_free(client_s); + + return BT_ERROR_NONE; +} + +int bt_gatt_client_get_remote_address(bt_gatt_client_h client, + char **remote_address) +{ + bt_gatt_client_s *client_s = (bt_gatt_client_s *)client; + + BT_CHECK_GATT_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(client); + BT_CHECK_INPUT_PARAMETER(remote_address); + + *remote_address = g_strdup(client_s->remote_address); + + return BT_ERROR_NONE; +} + +static bool __bt_gatt_client_is_in_progress(void) +{ + if (_bt_check_cb(BT_EVENT_GATT_CLIENT_WRITE_CHARACTERISTIC) || + _bt_check_cb(BT_EVENT_GATT_CLIENT_WRITE_DESCRIPTOR) || + _bt_check_cb(BT_EVENT_GATT_CLIENT_READ_CHARACTERISTIC) || + _bt_check_cb(BT_EVENT_GATT_CLIENT_READ_DESCRIPTOR)) { + BT_ERR("Operation is in progress"); + return true; + } + + return false; +} + +int bt_gatt_client_read_value(bt_gatt_h gatt_handle, + bt_gatt_client_request_completed_cb callback, void *user_data) +{ + int ret = BT_ERROR_NONE; + bt_gatt_common_s *c = (bt_gatt_common_s *)gatt_handle; + bt_gatt_client_cb_data_s *cb_data; + + BT_CHECK_GATT_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(gatt_handle); + BT_CHECK_INPUT_PARAMETER(callback); + + if (__bt_gatt_client_is_in_progress()) { + BT_ERR("Operation is in progress"); + return BT_ERROR_NOW_IN_PROGRESS; + } + + cb_data = malloc(sizeof(bt_gatt_client_cb_data_s)); + if (cb_data == NULL) { + BT_ERR("Cannot alloc cb_data"); + return BT_ERROR_OPERATION_FAILED; + } + + cb_data->gatt_handle = gatt_handle; + cb_data->user_data = user_data; + + if (c->type == BT_GATT_TYPE_CHARACTERISTIC) { + bt_gatt_characteristic_s *chr = (bt_gatt_characteristic_s *)gatt_handle; + + ret = _bt_get_error_code(bluetooth_gatt_read_characteristic_value(chr->path)); + if (ret != BT_ERROR_NONE) { + g_free(cb_data); + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); + } else { + _bt_set_cb(BT_EVENT_GATT_CLIENT_READ_CHARACTERISTIC, callback, cb_data); + } + } else if (c->type == BT_GATT_TYPE_DESCRIPTOR) { + bt_gatt_descriptor_s *desc = (bt_gatt_descriptor_s *)gatt_handle; + + ret = _bt_get_error_code(bluetooth_gatt_read_descriptor_value(desc->path)); + if (ret != BT_ERROR_NONE) { + g_free(cb_data); + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); + } else { + _bt_set_cb(BT_EVENT_GATT_CLIENT_READ_DESCRIPTOR, callback, cb_data); + } + } else { + BT_ERR("Invalid handle type for read "); + g_free(cb_data); + } + + return ret; +} + +int bt_gatt_client_write_value(bt_gatt_h gatt_handle, + bt_gatt_client_request_completed_cb callback, void *user_data) +{ + int ret = BT_ERROR_NONE; + bt_gatt_common_s *c = (bt_gatt_common_s *)gatt_handle; + bt_gatt_client_cb_data_s *cb_data; + + BT_CHECK_GATT_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(gatt_handle); + BT_CHECK_INPUT_PARAMETER(callback); + + if (__bt_gatt_client_is_in_progress()) { + BT_ERR("Operation is in progress"); + return BT_ERROR_NOW_IN_PROGRESS; + } + + cb_data = malloc(sizeof(bt_gatt_client_cb_data_s)); + if (cb_data == NULL) { + BT_ERR("Cannot alloc cb_data"); + return BT_ERROR_OPERATION_FAILED; + } + + cb_data->gatt_handle = gatt_handle; + cb_data->user_data = user_data; + + if (c->type == BT_GATT_TYPE_CHARACTERISTIC) { + bt_gatt_characteristic_s *chr = (bt_gatt_characteristic_s *)gatt_handle; + + BT_DBG("path : %s", chr->path); + if (chr->write_type == BT_GATT_WRITE_TYPE_WRITE) + ret = _bt_get_error_code(bluetooth_gatt_set_characteristics_value_by_type( + chr->path, (guint8 *)chr->value, chr->value_length, + BT_GATT_PROPERTY_WRITE)); + else if (chr->write_type == BT_GATT_WRITE_TYPE_WRITE_NO_RESPONSE) + ret = _bt_get_error_code(bluetooth_gatt_set_characteristics_value_by_type( + chr->path, (guint8 *)chr->value, chr->value_length, + BT_GATT_PROPERTY_WRITE_WITHOUT_RESPONSE)); + else { + BT_ERR("Unknow write type : %d", chr->write_type); + ret = BT_ERROR_OPERATION_FAILED; + } + if (ret != BT_ERROR_NONE) { + g_free(cb_data); + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); + } else { + _bt_set_cb(BT_EVENT_GATT_CLIENT_WRITE_CHARACTERISTIC, callback, cb_data); + } + } else if (c->type == BT_GATT_TYPE_DESCRIPTOR) { + bt_gatt_descriptor_s *desc = (bt_gatt_descriptor_s *)gatt_handle; + + ret = _bt_get_error_code(bluetooth_gatt_write_descriptor_value(desc->path, + (guint8 *)desc->value, desc->value_length)); + if (ret != BT_ERROR_NONE) { + g_free(cb_data); + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); + } else { + _bt_set_cb(BT_EVENT_GATT_CLIENT_WRITE_DESCRIPTOR, callback, cb_data); + } + } else { + BT_ERR("Invalid handle type for write "); + g_free(cb_data); + } + + return ret; +} + +static const bt_gatt_client_h __find_gatt_client(const char *remote_address) +{ + GSList *l = NULL; + + for (l = gatt_client_list; l; l = g_slist_next(l)) { + bt_gatt_client_s *client_s = l->data; + + if (!g_strcmp0(client_s->remote_address, remote_address)) { + return (const bt_gatt_client_h)l->data; + } + } + + return NULL; +} + +static gboolean __get_bdaddr_from_path(const char *path, char *addr) +{ + int i; + char *tmp; + + /* + * e.g. + * /org/bluez/hci0/dev_E7_56_2A_AA_0C_FD/service001b + */ + tmp = g_strstr_len(path, strlen(path), "dev_"); + if (tmp == NULL) + return FALSE; + tmp += 4; + + for (i = 0; *tmp != '\0' && i < BT_ADDR_STR_LEN; i++, tmp++) { + if (*tmp == '_') + addr[i] = ':'; + else + addr[i] = *tmp; + } + addr[i] = '\0'; + + BT_DBG("path : %s, addr : %s", path, addr); + + return TRUE; +} + +static void __value_changed_cb(char *char_path, + char *value, int value_length, void *user_data) +{ + GSList *l; + GSList *ll; + bt_gatt_client_h client; + bt_gatt_client_s *client_s; + bt_gatt_service_s *svc; + bt_gatt_characteristic_s *chr; + char remote_address[BT_ADDR_STR_LEN + 1] = { 0, }; + + BT_DBG("%s", char_path); + + if (__get_bdaddr_from_path(char_path, remote_address) == FALSE) { + BT_ERR("Cannot get addr from path : %s", char_path); + return; + } + + client = __find_gatt_client(remote_address); + if (client == NULL) { + BT_ERR("Cannot find client [%s]", remote_address); + return; + } + + client_s = (bt_gatt_client_s *)client; + for (l = client_s->services; l; l = g_slist_next(l)) { + svc = (bt_gatt_service_s *)l->data; + for (ll = svc->characteristics; ll; ll = g_slist_next(ll)) { + chr = (bt_gatt_characteristic_s *)ll->data; + if (g_ascii_strcasecmp(chr->path, char_path) == 0) { + if (chr->value_changed_cb) + chr->value_changed_cb(chr, value, + value_length, + chr->value_changed_user_data); + + bt_gatt_set_value(chr, value, value_length); + return; + } + } + } +} + +int bt_gatt_client_set_characteristic_value_changed_cb(bt_gatt_h characteristic, + bt_gatt_client_characteristic_value_changed_cb callback, + void *user_data) +{ + int ret; + bt_gatt_characteristic_s *chr = (bt_gatt_characteristic_s *)characteristic; + + BT_CHECK_GATT_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(characteristic); + BT_CHECK_INPUT_PARAMETER(callback); + + chr->value_changed_cb = callback; + chr->value_changed_user_data = user_data; + + if (chr->properties & + (BT_GATT_PROPERTY_NOTIFY | BT_GATT_PROPERTY_INDICATE)) { + ret = _bt_get_error_code(bluetooth_gatt_watch_characteristics( + chr->path)); + if (ret != BT_ERROR_NONE) + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); + else + _bt_set_cb(BT_EVENT_GATT_CLIENT_VALUE_CHANGED, + __value_changed_cb, NULL); + } else { + BT_DBG("notify or indication is not supported"); + ret = BT_ERROR_NOT_SUPPORTED; + } + + return BT_ERROR_NONE; +} + +int bt_gatt_client_unset_characteristic_value_changed_cb(bt_gatt_h characteristic) +{ + int ret; + bt_gatt_characteristic_s *chr = (bt_gatt_characteristic_s *)characteristic; + + BT_CHECK_GATT_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(characteristic); + + if (chr->properties & + (BT_GATT_PROPERTY_NOTIFY | BT_GATT_PROPERTY_INDICATE)) { + ret = _bt_get_error_code(bluetooth_gatt_unwatch_characteristics( + chr->path)); + if (ret != BT_ERROR_NONE) + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); + else { + chr->value_changed_cb = NULL; + chr->value_changed_user_data = NULL; + } + } else { + BT_DBG("notify or indication is not supported"); + ret = BT_ERROR_NOT_SUPPORTED; + } + + return ret; +} + +int bt_gatt_client_get_service(bt_gatt_client_h client, const char *uuid, + bt_gatt_h *service) +{ + bt_gatt_client_s *client_s = (bt_gatt_client_s *)client; + bt_gatt_h gatt_handle = NULL; + int ret; + + BT_CHECK_GATT_SUPPORT(); + BT_CHECK_INPUT_PARAMETER(client); + BT_CHECK_INPUT_PARAMETER(uuid); + BT_CHECK_INPUT_PARAMETER(service); + + ret = __get_gatt_handle_by_uuid(client_s->services, uuid, &gatt_handle); + if (ret == BT_ERROR_NONE && gatt_handle != NULL) { + *service = gatt_handle; + return BT_ERROR_NONE; + } + + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); + return ret; +} + +int bt_gatt_client_foreach_services(bt_gatt_client_h client, + bt_gatt_foreach_cb callback, void *user_data) +{ + bt_gatt_client_s *client_s = (bt_gatt_client_s *)client; + GSList *l = NULL; + int total = 0; + int index = 1; + + BT_CHECK_GATT_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(client); + BT_CHECK_INPUT_PARAMETER(callback); + + total = g_slist_length(client_s->services); + + for (l = client_s->services; l; l = g_slist_next(l)) { + if (!callback(total, index++, (bt_gatt_h)l->data, user_data)) + break; + } + + return BT_ERROR_NONE; +} diff --git a/src/bluetooth-hdp.c b/src/bluetooth-hdp.c index 60fe951..116c62d 100644 --- a/src/bluetooth-hdp.c +++ b/src/bluetooth-hdp.c @@ -24,38 +24,51 @@ #include "bluetooth.h" #include "bluetooth_private.h" -#ifdef LOG_TAG -#undef LOG_TAG +#ifdef TIZEN_HDP_DISABLE +#define BT_CHECK_HDP_SUPPORT() \ + { \ + BT_CHECK_BT_SUPPORT(); \ + LOGE("[%s] NOT_SUPPORTED(0x%08x)", __FUNCTION__, BT_ERROR_NOT_SUPPORTED); \ + return BT_ERROR_NOT_SUPPORTED; \ + } +#else +#define BT_CHECK_HDP_SUPPORT() #endif -#define LOG_TAG "TIZEN_N_BLUETOOTH" - int bt_hdp_register_sink_app(unsigned short data_type, char **app_id) { int error = BT_ERROR_NONE; + char *app_handle = NULL; + BT_CHECK_HDP_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(app_id); - error = bluetooth_hdp_activate(data_type, HDP_ROLE_SINK, HDP_QOS_ANY, app_id); + error = bluetooth_hdp_activate(data_type, HDP_ROLE_SINK, HDP_QOS_ANY, &app_handle); error = _bt_get_error_code(error); if (BT_ERROR_NONE != error) { - LOGE("[%s] %s(0x%08x)", __FUNCTION__, - _bt_convert_error_to_string(error), error); + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error), error); + return error; } - return error; + + *app_id = strdup(app_handle); + if (*app_id == NULL) { + return BT_ERROR_OUT_OF_MEMORY; + } + + return BT_ERROR_NONE; } int bt_hdp_unregister_sink_app(const char *app_id) { int error = BT_ERROR_NONE; + BT_CHECK_HDP_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(app_id); error = bluetooth_hdp_deactivate(app_id); error = _bt_get_error_code(error); if (BT_ERROR_NONE != error) { - LOGE("[%s] %s(0x%08x)", __FUNCTION__, - _bt_convert_error_to_string(error), error); + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error), error); } return error; } @@ -64,16 +77,15 @@ int bt_hdp_send_data(unsigned int channel, const char *data, unsigned int size) { int error = BT_ERROR_NONE; + BT_CHECK_HDP_SUPPORT(); BT_CHECK_INIT_STATUS(); if (NULL == data || 0 >= size) { - LOGE("[%s] %s)", __FUNCTION__, - _bt_convert_error_to_string(error)); + BT_ERR("%s", _bt_convert_error_to_string(BT_ERROR_INVALID_PARAMETER)); } error = bluetooth_hdp_send_data(channel, data, size); error = _bt_get_error_code(error); if (BT_ERROR_NONE != error) { - LOGE("[%s] %s(0x%08x)", __FUNCTION__, - _bt_convert_error_to_string(error), error); + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error), error); } return error; } @@ -82,6 +94,8 @@ int bt_hdp_connect_to_source(const char *remote_address, const char *app_id) { int error = BT_ERROR_NONE; bluetooth_device_address_t addr_hex = { {0,} }; + + BT_CHECK_HDP_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(app_id); BT_CHECK_INPUT_PARAMETER(remote_address); @@ -89,8 +103,7 @@ int bt_hdp_connect_to_source(const char *remote_address, const char *app_id) error = bluetooth_hdp_connect(app_id, HDP_QOS_ANY, &addr_hex); error = _bt_get_error_code(error); if (error != BT_ERROR_NONE) { - LOGE("[%s] %s(0x%08x)", __FUNCTION__, - _bt_convert_error_to_string(error), error); + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error), error); } return error; } @@ -99,6 +112,8 @@ int bt_hdp_disconnect(const char *remote_address, unsigned int channel) { int error = BT_ERROR_NONE; bluetooth_device_address_t addr_hex = { {0,} }; + + BT_CHECK_HDP_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(remote_address); _bt_convert_address_to_hex(&addr_hex, remote_address); @@ -106,8 +121,7 @@ int bt_hdp_disconnect(const char *remote_address, unsigned int channel) error = bluetooth_hdp_disconnect(channel, &addr_hex); error = _bt_get_error_code(error); if (error != BT_ERROR_NONE) { - LOGE("[%s] %s(0x%08x)", __FUNCTION__, - _bt_convert_error_to_string(error), error); + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error), error); } return error; } @@ -115,6 +129,7 @@ int bt_hdp_disconnect(const char *remote_address, unsigned int channel) int bt_hdp_set_connection_state_changed_cb(bt_hdp_connected_cb connected_cb, bt_hdp_disconnected_cb disconnected_cb, void *user_data) { + BT_CHECK_HDP_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(connected_cb); BT_CHECK_INPUT_PARAMETER(disconnected_cb); @@ -126,6 +141,7 @@ int bt_hdp_set_connection_state_changed_cb(bt_hdp_connected_cb connected_cb, int bt_hdp_unset_connection_state_changed_cb(void) { + BT_CHECK_HDP_SUPPORT(); BT_CHECK_INIT_STATUS(); if ( _bt_check_cb(BT_EVENT_HDP_CONNECTED) == true) _bt_unset_cb(BT_EVENT_HDP_CONNECTED); @@ -138,16 +154,18 @@ int bt_hdp_unset_connection_state_changed_cb(void) int bt_hdp_set_data_received_cb(bt_hdp_data_received_cb callback, void *user_data) { + BT_CHECK_HDP_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(callback); - _bt_set_cb(BT_EVENT_HDP_DATA_RECIEVED, callback, user_data); + _bt_set_cb(BT_EVENT_HDP_DATA_RECEIVED, callback, user_data); return BT_ERROR_NONE; } int bt_hdp_unset_data_received_cb(void) { + BT_CHECK_HDP_SUPPORT(); BT_CHECK_INIT_STATUS(); - if ( _bt_check_cb(BT_EVENT_HDP_DATA_RECIEVED) == true) - _bt_unset_cb(BT_EVENT_HDP_DATA_RECIEVED); + if ( _bt_check_cb(BT_EVENT_HDP_DATA_RECEIVED) == true) + _bt_unset_cb(BT_EVENT_HDP_DATA_RECEIVED); return BT_ERROR_NONE; } diff --git a/src/bluetooth-hid.c b/src/bluetooth-hid.c index 921e1bf..a00fb72 100644 --- a/src/bluetooth-hid.c +++ b/src/bluetooth-hid.c @@ -25,46 +25,77 @@ #include "bluetooth.h" #include "bluetooth_private.h" -#ifdef LOG_TAG -#undef LOG_TAG +static bool is_hid_host_initialized = false; + +#ifdef TIZEN_HID_DISABLE +#define BT_CHECK_HID_SUPPORT() \ + { \ + BT_CHECK_BT_SUPPORT(); \ + LOGE("[%s] NOT_SUPPORTED(0x%08x)", __FUNCTION__, BT_ERROR_NOT_SUPPORTED); \ + return BT_ERROR_NOT_SUPPORTED; \ + } +#else +#define BT_CHECK_HID_SUPPORT() #endif -#define LOG_TAG "TIZEN_N_BLUETOOTH" + +#define BT_CHECK_HID_HOST_INIT_STATUS() \ + if (__bt_check_hid_host_init_status() == BT_ERROR_NOT_INITIALIZED) \ + { \ + LOGE("[%s] NOT_INITIALIZED(0x%08x)", __FUNCTION__, BT_ERROR_NOT_INITIALIZED); \ + return BT_ERROR_NOT_INITIALIZED; \ + } + +int __bt_check_hid_host_init_status(void) +{ + if (is_hid_host_initialized != true) { + BT_ERR("NOT_INITIALIZED(0x%08x)", BT_ERROR_NOT_INITIALIZED); + return BT_ERROR_NOT_INITIALIZED; + } + + return BT_ERROR_NONE; +} int bt_hid_host_initialize(bt_hid_host_connection_state_changed_cb connection_cb, void *user_data) { int error; + BT_CHECK_HID_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(connection_cb); error = bluetooth_hid_init(_bt_hid_event_proxy, user_data); error = _bt_get_error_code(error); if (BT_ERROR_NONE != error) { - LOGE("[%s] %s(0x%08x)", __FUNCTION__, - _bt_convert_error_to_string(error), error); - } else { - _bt_set_cb(BT_EVENT_HID_CONNECTION_STATUS, connection_cb, user_data); + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error), error); + return error; } - return error; + + _bt_set_cb(BT_EVENT_HID_CONNECTION_STATUS, connection_cb, user_data); + + is_hid_host_initialized = true; + return BT_ERROR_NONE; } int bt_hid_host_deinitialize() { int error; + BT_CHECK_HID_SUPPORT(); BT_CHECK_INIT_STATUS(); + BT_CHECK_HID_HOST_INIT_STATUS(); error = bluetooth_hid_deinit(); error = _bt_get_error_code(error); if (BT_ERROR_NONE != error) { - LOGE("[%s] %s(0x%08x)", __FUNCTION__, - _bt_convert_error_to_string(error), error); - } else { - _bt_unset_cb(BT_EVENT_HID_CONNECTION_STATUS); + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error), error); + return error; } - return error; + _bt_unset_cb(BT_EVENT_HID_CONNECTION_STATUS); + + is_hid_host_initialized = false; + return BT_ERROR_NONE; } int bt_hid_host_connect(const char *remote_address) @@ -72,7 +103,9 @@ int bt_hid_host_connect(const char *remote_address) int error; bluetooth_device_address_t addr_hex = { {0,} }; + BT_CHECK_HID_SUPPORT(); BT_CHECK_INIT_STATUS(); + BT_CHECK_HID_HOST_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(remote_address); _bt_convert_address_to_hex(&addr_hex, remote_address); @@ -80,8 +113,7 @@ int bt_hid_host_connect(const char *remote_address) error = bluetooth_hid_connect((hid_device_address_t *)&addr_hex); error = _bt_get_error_code(error); if (error != BT_ERROR_NONE) { - LOGE("[%s] %s(0x%08x)", __FUNCTION__, - _bt_convert_error_to_string(error), error); + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error), error); } return error; } @@ -91,7 +123,9 @@ int bt_hid_host_disconnect(const char *remote_address) int error; bluetooth_device_address_t addr_hex = { {0,} }; + BT_CHECK_HID_SUPPORT(); BT_CHECK_INIT_STATUS(); + BT_CHECK_HID_HOST_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(remote_address); _bt_convert_address_to_hex(&addr_hex, remote_address); @@ -99,8 +133,7 @@ int bt_hid_host_disconnect(const char *remote_address) error = bluetooth_hid_disconnect((hid_device_address_t *)&addr_hex); error = _bt_get_error_code(error); if (error != BT_ERROR_NONE) { - LOGE("[%s] %s(0x%08x)", __FUNCTION__, - _bt_convert_error_to_string(error), error); + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error), error); } return error; } diff --git a/src/bluetooth-opp-client.c b/src/bluetooth-opp-client.c index 817c1bd..a05321b 100644 --- a/src/bluetooth-opp-client.c +++ b/src/bluetooth-opp-client.c @@ -24,12 +24,36 @@ #include "bluetooth.h" #include "bluetooth_private.h" -#ifdef LOG_TAG -#undef LOG_TAG +GList *sending_files; +static bool is_opp_client_initialized = false; + +#ifdef TIZEN_OPP_CLIENT_DISABLE +#define BT_CHECK_OPP_CLIENT_SUPPORT() \ + { \ + BT_CHECK_BT_SUPPORT(); \ + LOGE("[%s] NOT_SUPPORTED(0x%08x)", __FUNCTION__, BT_ERROR_NOT_SUPPORTED); \ + return BT_ERROR_NOT_SUPPORTED; \ + } +#else +#define BT_CHECK_OPP_CLIENT_SUPPORT() #endif -#define LOG_TAG "TIZEN_N_BLUETOOTH" -GList *sending_files; +#define BT_CHECK_OPP_CLIENT_INIT_STATUS() \ + if (__bt_check_opp_client_init_status() == BT_ERROR_NOT_INITIALIZED) \ + { \ + LOGE("[%s] NOT_INITIALIZED(0x%08x)", __FUNCTION__, BT_ERROR_NOT_INITIALIZED); \ + return BT_ERROR_NOT_INITIALIZED; \ + } + +int __bt_check_opp_client_init_status(void) +{ + if (is_opp_client_initialized != true) { + BT_ERR("NOT_INITIALIZED(0x%08x)", BT_ERROR_NOT_INITIALIZED); + return BT_ERROR_NOT_INITIALIZED; + } + + return BT_ERROR_NONE; +} char** __bt_opp_get_file_array(GList *file_list) { @@ -60,7 +84,7 @@ char** __bt_opp_get_file_array(GList *file_list) } for (i = 0; i < file_num; i++) - LOGE("[%s] %s", __FUNCTION__, files[i]); + BT_DBG("file: %s", files[i]); return files; } @@ -69,46 +93,61 @@ int bt_opp_client_initialize(void) { int error_code = BT_ERROR_NONE; + BT_CHECK_OPP_CLIENT_SUPPORT(); BT_CHECK_INIT_STATUS(); error_code = _bt_get_error_code(bluetooth_opc_init()); if (error_code != BT_ERROR_NONE) { - LOGE("[%s] %s(0x%08x)", __FUNCTION__, _bt_convert_error_to_string(error_code), error_code); + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error_code), + error_code); + return error_code; } - return error_code; + is_opp_client_initialized = true; + return BT_ERROR_NONE; } int bt_opp_client_deinitialize(void) { int error_code = BT_ERROR_NONE; + BT_CHECK_OPP_CLIENT_SUPPORT(); BT_CHECK_INIT_STATUS(); + BT_CHECK_OPP_CLIENT_INIT_STATUS(); error_code = _bt_get_error_code(bluetooth_opc_deinit()); + bt_opp_client_clear_files(); if (error_code != BT_ERROR_NONE) { - LOGE("[%s] %s(0x%08x)", __FUNCTION__, _bt_convert_error_to_string(error_code), error_code); + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error_code), + error_code); + return error_code; } - bt_opp_client_clear_files(); - - return error_code; + is_opp_client_initialized = false; + return BT_ERROR_NONE; } int bt_opp_client_add_file(const char *file) { int error_code = BT_ERROR_NONE; + BT_CHECK_OPP_CLIENT_SUPPORT(); BT_CHECK_INIT_STATUS(); + BT_CHECK_OPP_CLIENT_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(file); + BT_CHECK_ADAPTER_STATUS(); if (access(file, F_OK) == 0) { sending_files = g_list_append(sending_files, strdup(file)); } else { - error_code = BT_ERROR_INVALID_PARAMETER; - LOGE("[%s] %s(0x%08x)", __FUNCTION__, _bt_convert_error_to_string(error_code), error_code); + if (errno == EACCES || errno == EPERM) + error_code = BT_ERROR_PERMISSION_DENIED; + else + error_code = BT_ERROR_INVALID_PARAMETER; + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error_code), + error_code); } return error_code; @@ -120,7 +159,10 @@ int bt_opp_client_clear_files(void) int file_num = 0; char *c_file = NULL; + BT_CHECK_OPP_CLIENT_SUPPORT(); BT_CHECK_INIT_STATUS(); + BT_CHECK_OPP_CLIENT_INIT_STATUS(); + BT_CHECK_ADAPTER_STATUS(); if (sending_files) { file_num = g_list_length(sending_files); @@ -151,7 +193,9 @@ int bt_opp_client_push_files(const char *remote_address, bluetooth_device_address_t addr_hex = { {0,} }; char **files = NULL; + BT_CHECK_OPP_CLIENT_SUPPORT(); BT_CHECK_INIT_STATUS(); + BT_CHECK_OPP_CLIENT_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(remote_address); _bt_convert_address_to_hex(&addr_hex, remote_address); @@ -161,7 +205,8 @@ int bt_opp_client_push_files(const char *remote_address, error_code = _bt_get_error_code(bluetooth_opc_push_files(&addr_hex, files)); if (error_code != BT_ERROR_NONE) { - LOGE("[%s] %s(0x%08x)", __FUNCTION__, _bt_convert_error_to_string(error_code), error_code); + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error_code), + error_code); } else { _bt_set_cb(BT_EVENT_OPP_CLIENT_PUSH_RESPONSED, responded_cb, user_data); _bt_set_cb(BT_EVENT_OPP_CLIENT_PUSH_PROGRESS, progress_cb, user_data); @@ -180,12 +225,15 @@ int bt_opp_client_cancel_push(void) { int error_code = BT_ERROR_NONE; + BT_CHECK_OPP_CLIENT_SUPPORT(); BT_CHECK_INIT_STATUS(); + BT_CHECK_OPP_CLIENT_INIT_STATUS(); error_code = _bt_get_error_code(bluetooth_opc_cancel_push()); if (error_code != BT_ERROR_NONE) { - LOGE("[%s] %s(0x%08x)", __FUNCTION__, _bt_convert_error_to_string(error_code), error_code); + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error_code), + error_code); } return error_code; diff --git a/src/bluetooth-opp-server.c b/src/bluetooth-opp-server.c index 9526a92..9830305 100644 --- a/src/bluetooth-opp-server.c +++ b/src/bluetooth-opp-server.c @@ -22,10 +22,36 @@ #include "bluetooth.h" #include "bluetooth_private.h" -#ifdef LOG_TAG -#undef LOG_TAG +static bool is_opp_server_initialized = false; + +#ifdef TIZEN_OPP_SERVER_DISABLE +#define BT_CHECK_OPP_SERVER_SUPPORT() \ + { \ + BT_CHECK_BT_SUPPORT(); \ + LOGE("[%s] NOT_SUPPORTED(0x%08x)", __FUNCTION__, BT_ERROR_NOT_SUPPORTED); \ + return BT_ERROR_NOT_SUPPORTED; \ + } +#else +#define BT_CHECK_OPP_SERVER_SUPPORT() #endif -#define LOG_TAG "TIZEN_N_BLUETOOTH" + + +#define BT_CHECK_OPP_SERVER_INIT_STATUS() \ + if (__bt_check_opp_server_init_status() == BT_ERROR_NOT_INITIALIZED) \ + { \ + LOGE("[%s] NOT_INITIALIZED(0x%08x)", __FUNCTION__, BT_ERROR_NOT_INITIALIZED); \ + return BT_ERROR_NOT_INITIALIZED; \ + } + +int __bt_check_opp_server_init_status(void) +{ + if (is_opp_server_initialized != true) { + BT_ERR("NOT_INITIALIZED(0x%08x)", BT_ERROR_NOT_INITIALIZED); + return BT_ERROR_NOT_INITIALIZED; + } + + return BT_ERROR_NONE; +} int bt_opp_server_initialize(const char *destination, bt_opp_server_push_requested_cb push_requested_cb, @@ -33,18 +59,22 @@ int bt_opp_server_initialize(const char *destination, { int error_code = BT_ERROR_NONE; + BT_CHECK_OPP_SERVER_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(destination); - _bt_get_error_code(bluetooth_obex_server_init(destination)); + error_code = _bt_get_error_code(bluetooth_obex_server_init(destination)); if (error_code != BT_ERROR_NONE) { - LOGE("[%s] %s(0x%08x)", __FUNCTION__, _bt_convert_error_to_string(error_code), error_code); - } else { - _bt_set_cb(BT_EVENT_OPP_PUSH_REQUESTED, push_requested_cb, user_data); + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error_code), + error_code); + return error_code; } - return error_code; + _bt_set_cb(BT_EVENT_OPP_PUSH_REQUESTED, push_requested_cb, user_data); + + is_opp_server_initialized = true; + return BT_ERROR_NONE; } int bt_opp_server_initialize_by_connection_request(const char *destination, @@ -53,25 +83,31 @@ int bt_opp_server_initialize_by_connection_request(const char *destination, { int error_code = BT_ERROR_NONE; + BT_CHECK_OPP_SERVER_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(destination); - _bt_get_error_code(bluetooth_obex_server_init_without_agent(destination)); + error_code = _bt_get_error_code(bluetooth_obex_server_init_without_agent(destination)); if (error_code != BT_ERROR_NONE) { - LOGE("[%s] %s(0x%08x)", __FUNCTION__, _bt_convert_error_to_string(error_code), error_code); - } else { - _bt_set_cb(BT_EVENT_OPP_CONNECTION_REQUESTED, connection_requested_cb, user_data); + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error_code), + error_code); + return error_code; } - return error_code; + _bt_set_cb(BT_EVENT_OPP_CONNECTION_REQUESTED, connection_requested_cb, user_data); + + is_opp_server_initialized = true; + return BT_ERROR_NONE; } int bt_opp_server_deinitialize(void) { int error_code = BT_ERROR_NONE; + BT_CHECK_OPP_SERVER_SUPPORT(); BT_CHECK_INIT_STATUS(); + BT_CHECK_OPP_SERVER_INIT_STATUS(); if (_bt_check_cb(BT_EVENT_OPP_CONNECTION_REQUESTED) == false) { error_code = _bt_get_error_code(bluetooth_obex_server_deinit()); @@ -80,14 +116,17 @@ int bt_opp_server_deinitialize(void) error_code = _bt_get_error_code(bluetooth_obex_server_deinit_without_agent()); } - if (error_code != BT_ERROR_NONE) { - LOGE("[%s] %s(0x%08x)", __FUNCTION__, _bt_convert_error_to_string(error_code), error_code); - } - _bt_unset_cb(BT_EVENT_OPP_CONNECTION_REQUESTED); _bt_unset_cb(BT_EVENT_OPP_PUSH_REQUESTED); - return error_code; + if (error_code != BT_ERROR_NONE) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error_code), + error_code); + return error_code; + } + + is_opp_server_initialized = false; + return BT_ERROR_NONE; } int bt_opp_server_accept(bt_opp_server_transfer_progress_cb progress_cb, @@ -98,7 +137,9 @@ int bt_opp_server_accept(bt_opp_server_transfer_progress_cb progress_cb, { int error_code = BT_ERROR_NONE; + BT_CHECK_OPP_SERVER_SUPPORT(); BT_CHECK_INIT_STATUS(); + BT_CHECK_OPP_SERVER_INIT_STATUS(); /* Unset the transfer callbacks */ _bt_unset_cb(BT_EVENT_OPP_SERVER_TRANSFER_PROGRESS); @@ -112,7 +153,8 @@ int bt_opp_server_accept(bt_opp_server_transfer_progress_cb progress_cb, } if (error_code != BT_ERROR_NONE) { - LOGE("[%s] %s(0x%08x)", __FUNCTION__, _bt_convert_error_to_string(error_code), error_code); + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error_code), + error_code); } else { _bt_set_cb(BT_EVENT_OPP_SERVER_TRANSFER_PROGRESS, progress_cb, user_data); _bt_set_cb(BT_EVENT_OPP_SERVER_TRANSFER_FINISHED, finished_cb, user_data); @@ -125,7 +167,9 @@ int bt_opp_server_reject(void) { int error_code = BT_ERROR_NONE; + BT_CHECK_OPP_SERVER_SUPPORT(); BT_CHECK_INIT_STATUS(); + BT_CHECK_OPP_SERVER_INIT_STATUS(); if (_bt_check_cb(BT_EVENT_OPP_CONNECTION_REQUESTED) == false) { error_code = _bt_get_error_code(bluetooth_obex_server_reject_authorize()); @@ -135,7 +179,8 @@ int bt_opp_server_reject(void) } if (error_code != BT_ERROR_NONE) { - LOGE("[%s] %s(0x%08x)", __FUNCTION__, _bt_convert_error_to_string(error_code), error_code); + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error_code), + error_code); } /* Unset the transfer callbacks */ @@ -149,12 +194,15 @@ int bt_opp_server_set_destination(const char *destination) { int error_code = BT_ERROR_NONE; + BT_CHECK_OPP_SERVER_SUPPORT(); BT_CHECK_INIT_STATUS(); + BT_CHECK_OPP_SERVER_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(destination); error_code = _bt_get_error_code(bluetooth_obex_server_set_destination_path(destination)); if (error_code != BT_ERROR_NONE) { - LOGE("[%s] %s(0x%08x)", __FUNCTION__, _bt_convert_error_to_string(error_code), error_code); + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error_code), + error_code); } return error_code; @@ -164,11 +212,14 @@ int bt_opp_server_cancel_transfer(int transfer_id) { int error_code = BT_ERROR_NONE; + BT_CHECK_OPP_SERVER_SUPPORT(); BT_CHECK_INIT_STATUS(); + BT_CHECK_OPP_SERVER_INIT_STATUS(); error_code = _bt_get_error_code(bluetooth_obex_server_cancel_transfer(transfer_id)); if (error_code != BT_ERROR_NONE) { - LOGE("[%s] %s(0x%08x)", __FUNCTION__, _bt_convert_error_to_string(error_code), error_code); + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error_code), + error_code); } return error_code; diff --git a/src/bluetooth-pan.c b/src/bluetooth-pan.c index 2366b92..a00cd7f 100644 --- a/src/bluetooth-pan.c +++ b/src/bluetooth-pan.c @@ -24,23 +24,29 @@ #include "bluetooth.h" #include "bluetooth_private.h" -#ifdef LOG_TAG -#undef LOG_TAG -#endif -#define LOG_TAG "TIZEN_N_BLUETOOTH" - GList *sending_files; +#ifdef TIZEN_PAN_DISABLE +#define BT_CHECK_PAN_SUPPORT() \ + { \ + BT_CHECK_BT_SUPPORT(); \ + LOGE("[%s] NOT_SUPPORTED(0x%08x)", __FUNCTION__, BT_ERROR_NOT_SUPPORTED); \ + return BT_ERROR_NOT_SUPPORTED; \ + } +#else +#define BT_CHECK_PAN_SUPPORT() +#endif + int bt_nap_activate(void) { int error = BT_ERROR_NONE; + BT_CHECK_PAN_SUPPORT(); BT_CHECK_INIT_STATUS(); error = bluetooth_network_activate_server(); error = _bt_get_error_code(error); if (error != BT_ERROR_NONE) { - LOGE("[%s] %s(0x%08x)", __FUNCTION__, - _bt_convert_error_to_string(error), error); + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error), error); } return error; } @@ -49,12 +55,49 @@ int bt_nap_deactivate(void) { int error = BT_ERROR_NONE; + BT_CHECK_PAN_SUPPORT(); + BT_CHECK_INIT_STATUS(); + error = bluetooth_network_deactivate_server(); + error = _bt_get_error_code(error); + if (error != BT_ERROR_NONE) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error), error); + } + return error; +} + +/* bluez don't support the disconnect API about NAP server */ +/* So we implement this, deactivate the server and re-activate the server */ +int bt_nap_disconnect_all(void) +{ + int error = BT_ERROR_NONE; + + BT_CHECK_PAN_SUPPORT(); BT_CHECK_INIT_STATUS(); error = bluetooth_network_deactivate_server(); error = _bt_get_error_code(error); if (error != BT_ERROR_NONE) { - LOGE("[%s] %s(0x%08x)", __FUNCTION__, - _bt_convert_error_to_string(error), error); + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error), error); + } else { + return bt_nap_activate(); + } + + return error; +} + +int bt_nap_disconnect(const char *remote_address) +{ + int error = BT_ERROR_INVALID_PARAMETER; + bluetooth_device_address_t addr_hex = { {0,} }; + + BT_CHECK_PAN_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(remote_address); + _bt_convert_address_to_hex(&addr_hex, remote_address); + error = bluetooth_network_server_disconnect(&addr_hex); + error = _bt_get_error_code(error); + if (error != BT_ERROR_NONE) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error), + error); } return error; } @@ -63,6 +106,7 @@ int bt_nap_set_connection_state_changed_cb( bt_nap_connection_state_changed_cb callback, void *user_data) { + BT_CHECK_PAN_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(callback); _bt_set_cb(BT_EVENT_NAP_CONNECTION_STATE_CHANGED, callback, user_data); @@ -80,6 +124,7 @@ int bt_panu_set_connection_state_changed_cb( bt_panu_connection_state_changed_cb callback, void *user_data) { + BT_CHECK_PAN_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(callback); _bt_set_cb(BT_EVENT_PAN_CONNECTION_STATE_CHANGED, callback, user_data); @@ -97,6 +142,7 @@ int bt_panu_connect(const char *remote_address, bt_panu_service_type_e type) int error = BT_ERROR_INVALID_PARAMETER; bluetooth_device_address_t addr_hex = { {0,} }; + BT_CHECK_PAN_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(remote_address); _bt_convert_address_to_hex(&addr_hex, remote_address); @@ -105,8 +151,8 @@ int bt_panu_connect(const char *remote_address, bt_panu_service_type_e type) BLUETOOTH_NETWORK_NAP_ROLE, NULL); error = _bt_get_error_code(error); if (error != BT_ERROR_NONE) { - LOGE("[%s] %s(0x%08x)", __FUNCTION__, - _bt_convert_error_to_string(error), error); + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error), + error); } } return error; @@ -117,14 +163,15 @@ int bt_panu_disconnect(const char *remote_address) int error = BT_ERROR_INVALID_PARAMETER; bluetooth_device_address_t addr_hex = { {0,} }; + BT_CHECK_PAN_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(remote_address); _bt_convert_address_to_hex(&addr_hex, remote_address); error = bluetooth_network_disconnect(&addr_hex); error = _bt_get_error_code(error); if (error != BT_ERROR_NONE) { - LOGE("[%s] %s(0x%08x)", __FUNCTION__, - _bt_convert_error_to_string(error), error); + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error), + error); } return error; } diff --git a/src/bluetooth-pbap.c b/src/bluetooth-pbap.c new file mode 100644 index 0000000..96d8419 --- /dev/null +++ b/src/bluetooth-pbap.c @@ -0,0 +1,282 @@ +/* + * 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 +#include +#include +#include +#include +#include + +#include "bluetooth.h" +#include "bluetooth_internal.h" +#include "bluetooth_private.h" + +#ifdef TIZEN_PBAP_DISABLE +#define BT_CHECK_PBAP_SUPPORT() \ + { \ + BT_CHECK_BT_SUPPORT(); \ + LOGE("[%s] NOT_SUPPORTED(0x%08x)", __FUNCTION__, BT_ERROR_NOT_SUPPORTED); \ + return BT_ERROR_NOT_SUPPORTED; \ + } +#else +#define BT_CHECK_PBAP_SUPPORT() +#endif + +int bt_pbap_init(void) +{ + BT_CHECK_PBAP_SUPPORT(); + BT_CHECK_INIT_STATUS(); + int error_code = BT_ERROR_NONE; + error_code = _bt_get_error_code(bluetooth_pbap_init()); + if (error_code != BT_ERROR_NONE) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error_code), error_code); + } + + return error_code; +} + +int bt_pbap_deinit(void) +{ + BT_CHECK_PBAP_SUPPORT(); + BT_CHECK_INIT_STATUS(); + int error_code = BT_ERROR_NONE; + error_code = _bt_get_error_code(bluetooth_pbap_deinit()); + if (error_code != BT_ERROR_NONE) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error_code), error_code); + } + + return error_code; +} + +int bt_pbap_connect(const char *address, bt_pbap_enabled_cb callback, void *user_data) +{ + bluetooth_device_address_t addr_hex = { {0,} }; + int error_code = BT_ERROR_NONE; + + BT_CHECK_PBAP_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(address); + BT_CHECK_INPUT_PARAMETER(callback); + + _bt_convert_address_to_hex(&addr_hex, address); + _bt_set_cb(BT_EVENT_PBAP_CONNECTION_STATUS, callback, user_data); + + error_code = _bt_get_error_code(bluetooth_pbap_connect(&addr_hex)); + if (error_code != BT_ERROR_NONE) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error_code), error_code); + _bt_unset_cb(BT_EVENT_PBAP_CONNECTION_STATUS); + } + + return error_code; +} + +int bt_pbap_disconnect(const char *address, bt_pbap_enabled_cb callback, void *user_data) +{ + bluetooth_device_address_t addr_hex = { {0,} }; + int error_code = BT_ERROR_NONE; + + BT_CHECK_PBAP_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(address); + BT_CHECK_INPUT_PARAMETER(callback); + + _bt_convert_address_to_hex(&addr_hex, address); + _bt_set_cb(BT_EVENT_PBAP_CONNECTION_STATUS, callback, user_data); + + error_code = _bt_get_error_code(bluetooth_pbap_disconnect(&addr_hex)); + if (error_code != BT_ERROR_NONE) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error_code), error_code); + _bt_unset_cb(BT_EVENT_PBAP_CONNECTION_STATUS); + } + + return error_code; +} + +int bt_pbap_get_phonebook_size(const char *address, bt_pbap_addressbook_source_e source, + bt_pbap_folder_type_e type, bt_pbap_phonebook_size_cb callback, void *user_data) +{ + bluetooth_device_address_t addr_hex = { {0,} }; + bt_pbap_folder_t folder = { 0, }; + int error_code = BT_ERROR_NONE; + + BT_CHECK_PBAP_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(address); + BT_CHECK_INPUT_PARAMETER(callback); + + folder.addressbook = source; + folder.folder_type = type; + _bt_convert_address_to_hex(&addr_hex, address); + _bt_set_cb(BT_EVENT_PBAP_PHONEBOOK_SIZE, callback, user_data); + error_code = _bt_get_error_code(bluetooth_pbap_get_phonebook_size(&addr_hex, &folder)); + if (error_code != BT_ERROR_NONE) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error_code), error_code); + _bt_unset_cb(BT_EVENT_PBAP_PHONEBOOK_SIZE); + } + + return error_code; +} + +int bt_pbap_get_phonebook(const char *address, bt_pbap_addressbook_source_e source, + bt_pbap_folder_type_e type, bt_pbap_filter_vcard_format_e format, + bt_pbap_filter_sort_order_e order, unsigned short offset, + unsigned short maxlistcount, long long unsigned fields, + bt_pbap_phonebook_pull_cb callback, void *user_data) +{ + bluetooth_device_address_t addr_hex = { {0,} }; + bt_pbap_pull_parameters_t app_param = { 0, }; + bt_pbap_folder_t folder = { 0, }; + int error_code = BT_ERROR_NONE; + + BT_CHECK_PBAP_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(address); + BT_CHECK_INPUT_PARAMETER(callback); + + /* To get size of phonebook, a separate API is provided + * Hence, passing maxlistcount as 0 is restricted. */ + if (maxlistcount <= 0) + return BT_ERROR_INVALID_PARAMETER; + + /* Maximum value of maxlistcount is 65535 */ + if (maxlistcount > 65535) + maxlistcount = 65535; + + app_param.format = format; + app_param.order = order; + app_param.offset = offset; + app_param.maxlist = maxlistcount; + app_param.fields = fields; + + folder.addressbook = source; + folder.folder_type = type; + + _bt_convert_address_to_hex(&addr_hex, address); + _bt_set_cb(BT_EVENT_PBAP_PHONEBOOK_PULL, callback, user_data); + error_code = _bt_get_error_code(bluetooth_pbap_get_phonebook(&addr_hex, &folder, &app_param)); + if (error_code != BT_ERROR_NONE) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error_code), error_code); + _bt_unset_cb(BT_EVENT_PBAP_PHONEBOOK_PULL); + } + + return error_code; +} + +int bt_pbap_get_list(const char *address, bt_pbap_addressbook_source_e source, + bt_pbap_folder_type_e type, bt_pbap_filter_sort_order_e order, + unsigned short offset, unsigned short maxlistcount, + bt_pbap_list_vcards_cb callback, void *user_data) +{ + bluetooth_device_address_t addr_hex = { {0,} }; + bt_pbap_list_parameters_t app_param = { 0, }; + bt_pbap_folder_t folder = { 0, }; + int error_code = BT_ERROR_NONE; + + BT_CHECK_PBAP_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(address); + BT_CHECK_INPUT_PARAMETER(callback); + + _bt_convert_address_to_hex(&addr_hex, address); + app_param.order = order; + app_param.offset = offset; + app_param.maxlist = maxlistcount; + + folder.addressbook = source; + folder.folder_type = type; + + _bt_set_cb(BT_EVENT_PBAP_VCARD_LIST, callback, user_data); + error_code = _bt_get_error_code(bluetooth_pbap_get_list(&addr_hex, &folder, &app_param)); + if (error_code != BT_ERROR_NONE) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error_code), error_code); + _bt_unset_cb(BT_EVENT_PBAP_VCARD_LIST); + } + + return error_code; +} + +int bt_pbap_pull_vcard(const char *address, bt_pbap_addressbook_source_e source, + bt_pbap_folder_type_e type, int index, + bt_pbap_filter_vcard_format_e format, long long unsigned fields, + bt_pbap_get_vcard_cb callback, void *user_data) +{ + bluetooth_device_address_t addr_hex = { {0,} }; + bt_pbap_pull_vcard_parameters_t app_param = { 0, }; + bt_pbap_folder_t folder = { 0, }; + + int error_code = BT_ERROR_NONE; + + BT_CHECK_PBAP_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(address); + BT_CHECK_INPUT_PARAMETER(callback); + + _bt_convert_address_to_hex(&addr_hex, address); + app_param.format = format; + app_param.fields = fields; + app_param.index = index; + + folder.addressbook = source; + folder.folder_type = type; + + _bt_set_cb(BT_EVENT_PBAP_VCARD_PULL, callback, user_data); + error_code = _bt_get_error_code(bluetooth_pbap_pull_vcard(&addr_hex, &folder, &app_param)); + if (error_code != BT_ERROR_NONE) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error_code), error_code); + _bt_unset_cb(BT_EVENT_PBAP_VCARD_PULL); + } + + return error_code; +} + +int bt_pbap_phonebook_search(const char *address, + bt_pbap_addressbook_source_e source, bt_pbap_folder_type_e type, + bt_pbap_search_field_e search_attribute, const char *search_value, + bt_pbap_filter_sort_order_e order, + unsigned short offset, unsigned short maxlistcount, + bt_pbap_search_list_cb callback, void *user_data) +{ + bluetooth_device_address_t addr_hex = { {0,} }; + bt_pbap_folder_t folder = { 0, }; + bt_pbap_search_parameters_t app_param = { 0, }; + int error_code = BT_ERROR_NONE; + + BT_CHECK_PBAP_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(address); + BT_CHECK_INPUT_PARAMETER(callback); + + _bt_convert_address_to_hex(&addr_hex, address); + folder.addressbook = source; + folder.folder_type = type; + + app_param.order = order; + app_param.offset = offset; + app_param.maxlist = maxlistcount; + app_param.search_attribute = search_attribute; + strncpy(app_param.search_value, search_value, + BLUETOOTH_PBAP_MAX_SEARCH_VALUE_LENGTH -1 ); + + _bt_set_cb(BT_EVENT_PBAP_PHONEBOOK_SEARCH, callback, user_data); + error_code = _bt_get_error_code(bluetooth_pbap_phonebook_search(&addr_hex, &folder, &app_param)); + if (error_code != BT_ERROR_NONE) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error_code), error_code); + _bt_unset_cb(BT_EVENT_PBAP_PHONEBOOK_SEARCH); + } + + return error_code; +} diff --git a/src/bluetooth-socket.c b/src/bluetooth-socket.c index e0563be..52c6a69 100644 --- a/src/bluetooth-socket.c +++ b/src/bluetooth-socket.c @@ -14,6 +14,8 @@ * limitations under the License. */ +#include +#include #include #include #include @@ -21,16 +23,11 @@ #include "bluetooth.h" #include "bluetooth_private.h" -#ifdef LOG_TAG -#undef LOG_TAG -#endif -#define LOG_TAG "TIZEN_N_BLUETOOTH" - - int bt_socket_create_rfcomm(const char *uuid, int *socket_fd) { int ret = 0; + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(uuid); BT_CHECK_INPUT_PARAMETER(socket_fd); @@ -38,7 +35,7 @@ int bt_socket_create_rfcomm(const char *uuid, int *socket_fd) ret = bluetooth_rfcomm_create_socket(uuid); if (ret < 0) { ret = _bt_get_error_code(ret); - LOGE("[%s] %s(0x%08x)", __FUNCTION__, _bt_convert_error_to_string(ret), ret); + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); return ret; } else { *socket_fd = ret; @@ -50,10 +47,12 @@ int bt_socket_destroy_rfcomm(int socket_fd) { int error_code = BT_ERROR_NONE; + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); error_code = _bt_get_error_code(bluetooth_rfcomm_remove_socket(socket_fd)); if (error_code != BT_ERROR_NONE) { - LOGE("[%s] %s(0x%08x)", __FUNCTION__, _bt_convert_error_to_string(error_code), error_code); + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error_code), + error_code); } return error_code; @@ -61,6 +60,7 @@ int bt_socket_destroy_rfcomm(int socket_fd) int bt_socket_is_service_used(const char* service_uuid, bool *used) { + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(service_uuid); BT_CHECK_INPUT_PARAMETER(used); @@ -74,10 +74,12 @@ int bt_socket_listen_and_accept_rfcomm(int socket_fd, int max_pending_connection { int error_code = BT_ERROR_NONE; + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); error_code = _bt_get_error_code(bluetooth_rfcomm_listen_and_accept(socket_fd, max_pending_connections)); if (error_code != BT_ERROR_NONE) { - LOGE("[%s] %s(0x%08x)", __FUNCTION__, _bt_convert_error_to_string(error_code), error_code); + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error_code), + error_code); } return error_code; @@ -87,25 +89,29 @@ int bt_socket_listen(int socket_fd, int max_pending_connections) { int error_code = BT_ERROR_NONE; + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); error_code = _bt_get_error_code(bluetooth_rfcomm_listen(socket_fd, max_pending_connections)); if (error_code != BT_ERROR_NONE) { - LOGE("[%s] %s(0x%08x)", __FUNCTION__, _bt_convert_error_to_string(error_code), error_code); + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error_code), + error_code); } return error_code; } -int bt_socket_accept(int socket_fd, int *connected_socket_fd) +int bt_socket_accept(int socket_fd) { int error_code = BT_ERROR_NONE; + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); - error_code = _bt_get_error_code(bluetooth_rfcomm_accept_connection(socket_fd, connected_socket_fd)); + error_code = _bt_get_error_code(bluetooth_rfcomm_accept_connection(socket_fd)); if (error_code != BT_ERROR_NONE) { - LOGE("[%s] %s(0x%08x)", __FUNCTION__, _bt_convert_error_to_string(error_code), error_code); + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error_code), + error_code); } return error_code; @@ -115,11 +121,68 @@ int bt_socket_reject(int socket_fd) { int error_code = BT_ERROR_NONE; + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); error_code = _bt_get_error_code(bluetooth_rfcomm_reject_connection(socket_fd)); if (error_code != BT_ERROR_NONE) { - LOGE("[%s] %s(0x%08x)", __FUNCTION__, _bt_convert_error_to_string(error_code), error_code); + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error_code), + error_code); + } + + return error_code; +} + +int bt_socket_create_rfcomm_ex(const char *uuid, const char *bus_name, const char *object_path) +{ + int error_code = BT_ERROR_NONE; + + BT_CHECK_BT_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(uuid); + BT_CHECK_INPUT_PARAMETER(bus_name); + BT_CHECK_INPUT_PARAMETER(object_path); + + error_code = bluetooth_rfcomm_create_socket_ex(uuid, bus_name, object_path); + if (error_code != BT_ERROR_NONE) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error_code), + error_code); + } + + return error_code; +} + +int bt_socket_destroy_rfcomm_ex(const char *uuid) +{ + int error_code = BT_ERROR_NONE; + + BT_CHECK_BT_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(uuid); + + error_code = _bt_get_error_code(bluetooth_rfcomm_remove_socket_ex(uuid)); + if (error_code != BT_ERROR_NONE) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error_code), + error_code); + } + + return error_code; +} + +int bt_socket_listen_and_accept_rfcomm_ex(const char *uuid, int max_pending_connections, const char* bus_name, const char *object_path) +{ + int error_code = BT_ERROR_NONE; + + BT_CHECK_BT_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(uuid); + BT_CHECK_INPUT_PARAMETER(bus_name); + BT_CHECK_INPUT_PARAMETER(object_path); + + error_code = _bt_get_error_code(bluetooth_rfcomm_listen_and_accept_ex(uuid, max_pending_connections, bus_name, object_path)); + if (error_code != BT_ERROR_NONE) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error_code), + error_code); } return error_code; @@ -130,6 +193,7 @@ int bt_socket_connect_rfcomm(const char *remote_address, const char *remote_port bluetooth_device_address_t addr_hex = { {0,} }; int error_code = BT_ERROR_NONE; + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(remote_address); BT_CHECK_INPUT_PARAMETER(remote_port_uuid); @@ -138,7 +202,8 @@ int bt_socket_connect_rfcomm(const char *remote_address, const char *remote_port error_code = _bt_get_error_code(bluetooth_rfcomm_connect(&addr_hex, remote_port_uuid)); if (error_code != BT_ERROR_NONE) { - LOGE("[%s] %s(0x%08x)", __FUNCTION__, _bt_convert_error_to_string(error_code), error_code); + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error_code), + error_code); } return error_code; @@ -146,32 +211,43 @@ int bt_socket_connect_rfcomm(const char *remote_address, const char *remote_port int bt_socket_disconnect_rfcomm(int socket_fd) { - int ret = BT_ERROR_NONE; + int error_code = BT_ERROR_NONE; + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); - ret = _bt_get_error_code(bluetooth_rfcomm_disconnect(socket_fd)); - if (ret != BT_ERROR_NONE) { - LOGE("[%s] %s(0x%08x)", __FUNCTION__, _bt_convert_error_to_string(ret), ret); + error_code = _bt_get_error_code(bluetooth_rfcomm_disconnect(socket_fd)); + if (error_code != BT_ERROR_NONE) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error_code), + error_code); } - return ret; + return error_code; } int bt_socket_send_data(int socket_fd, const char *data, int length) { int ret = 0; + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); - ret = bluetooth_rfcomm_write(socket_fd, data, length); - if (ret == BLUETOOTH_ERROR_NOT_IN_OPERATION) { - LOGE("[%s] OPERATION_FAILED(0x%08x)", __FUNCTION__, BT_ERROR_OPERATION_FAILED); - return BT_ERROR_OPERATION_FAILED; - } - ret = _bt_get_error_code(ret); - if (ret != BT_ERROR_NONE) { - LOGE("[%s] %s(0x%08x)", __FUNCTION__, _bt_convert_error_to_string(ret), ret); + ret = bluetooth_rfcomm_write(socket_fd, data, length); + if (ret <= 0) { + if (ret == -1) { + /* write fail case */ + if (errno == EACCES || errno == EPERM) + set_last_result(BT_ERROR_PERMISSION_DENIED); + else if (errno == EAGAIN || errno == EWOULDBLOCK) + set_last_result(BT_ERROR_AGAIN); + else + set_last_result(BT_ERROR_OPERATION_FAILED); + } else { + ret = _bt_get_error_code(ret); + set_last_result(ret); + } + + BT_ERR("Write failed, ret = %d", ret); } return ret; @@ -179,6 +255,7 @@ int bt_socket_send_data(int socket_fd, const char *data, int length) int bt_socket_set_data_received_cb(bt_socket_data_received_cb callback, void *user_data) { + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(callback); _bt_set_cb(BT_EVENT_DATA_RECEIVED, callback, user_data); @@ -187,6 +264,7 @@ int bt_socket_set_data_received_cb(bt_socket_data_received_cb callback, void *us int bt_socket_unset_data_received_cb(void) { + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); _bt_unset_cb(BT_EVENT_DATA_RECEIVED); return BT_ERROR_NONE; @@ -194,6 +272,7 @@ int bt_socket_unset_data_received_cb(void) int bt_socket_set_connection_requested_cb(bt_socket_connection_requested_cb callback, void *user_data) { + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(callback); _bt_set_cb(BT_EVENT_RFCOMM_CONNECTION_REQUESTED, callback, user_data); @@ -202,6 +281,7 @@ int bt_socket_set_connection_requested_cb(bt_socket_connection_requested_cb call int bt_socket_unset_connection_requested_cb(void) { + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); _bt_unset_cb(BT_EVENT_RFCOMM_CONNECTION_REQUESTED); return BT_ERROR_NONE; @@ -209,6 +289,7 @@ int bt_socket_unset_connection_requested_cb(void) int bt_socket_set_connection_state_changed_cb(bt_socket_connection_state_changed_cb callback, void *user_data) { + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); BT_CHECK_INPUT_PARAMETER(callback); _bt_set_cb(BT_EVENT_CONNECTION_STATE_CHANGED, callback, user_data); @@ -217,6 +298,7 @@ int bt_socket_set_connection_state_changed_cb(bt_socket_connection_state_changed int bt_socket_unset_connection_state_changed_cb(void) { + BT_CHECK_BT_SUPPORT(); BT_CHECK_INIT_STATUS(); _bt_unset_cb(BT_EVENT_CONNECTION_STATE_CHANGED); return BT_ERROR_NONE; diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 7715cac..e5a75bd 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -15,3 +15,11 @@ FOREACH(src ${sources}) ADD_EXECUTABLE(${src_name} ${src}) TARGET_LINK_LIBRARIES(${src_name} ${fw_name} ${${fw_test}_LDFLAGS}) ENDFOREACH() + +INSTALL(TARGETS bt_unit_test DESTINATION bin) +INSTALL(TARGETS bt_onoff DESTINATION bin) +INSTALL(TARGETS bt_infinite_spp_test DESTINATION bin) +INSTALL(FILES capi.network.bluetooth.test.rule DESTINATION /etc/smack/accesses2.d/) +INSTALL(FILES capi.network.bluetooth.infinite.spp.test.rule DESTINATION /etc/smack/accesses2.d/) + +ADD_SUBDIRECTORY(gatt_profile_test_suite) diff --git a/test/bt_chat_client.c b/test/bt_chat_client.c deleted file mode 100644 index bfdd5e8..0000000 --- a/test/bt_chat_client.c +++ /dev/null @@ -1,453 +0,0 @@ -/* - * 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 -#include -#include -#include - -#ifdef LOG_TAG -#undef LOG_TAG -#endif -#define LOG_TAG "BT_CHAT_CLIENT" - -/** - * Variables - **/ -static GMainLoop* g_mainloop = NULL; -static bt_adapter_state_e bt_state = BT_ADAPTER_DISABLED; -static int socket_fd = -1; -static char* bt_address = NULL; -static char* server_name = "chat_server"; -static char quit_command[5] = "Quit"; -static int bonding_state = BT_ERROR_OPERATION_FAILED; - - -/** - * Callback functions - **/ -gboolean timeout_func(gpointer data) -{ - LOGE("[%s] Callback: Timeout.", __FUNCTION__); - g_main_loop_quit((GMainLoop*)data); - return FALSE; -} - -void bt_state_changed_impl(int result, bt_adapter_state_e adapter_state, void* user_data) -{ - if(adapter_state == BT_ADAPTER_ENABLED) - { - if(result == BT_ERROR_NONE) - { - LOGI("[%s] Callback: BT was enabled successfully.", __FUNCTION__); - bt_state = BT_ADAPTER_ENABLED; - } - else - { - LOGE("[%s] Callback: Failed to enable BT.", __FUNCTION__); - } - } - - if(g_mainloop) - { - g_main_loop_quit(g_mainloop); - } -} - -void bt_socket_connection_state_changed_impl(int result, bt_socket_connection_state_e connection_state, - bt_socket_connection_s *connection, void *user_data) -{ - if(result == BT_ERROR_NONE) - { - LOGI("[%s] Callback: Result is BT_ERROR_NONE.", __FUNCTION__); - } - else - { - LOGI("[%s] Callback: Result is not BT_ERROR_NONE.", __FUNCTION__); - } - - if(connection_state == BT_SOCKET_CONNECTED) - { - LOGI("[%s] Callback: Connected.", __FUNCTION__); - if(result == BT_ERROR_NONE && connection != NULL) - { - socket_fd = connection->socket_fd; - LOGI("[%s] Callback: Socket of connection - %d.", __FUNCTION__, socket_fd); - LOGI("[%s] Callback: Role of connection - %d.", __FUNCTION__, connection->local_role); - LOGI("[%s] Callback: Address of connection - %s.", __FUNCTION__, connection->remote_address); - - if(bt_socket_send_data(socket_fd, quit_command, strlen(quit_command)) == BT_ERROR_NONE) - { - LOGI("[%s] Callback: Send quit command.", __FUNCTION__); - } - else - { - LOGE("[%s] Callback: bt_socket_send_data() failed.", __FUNCTION__); - if(g_mainloop) - { - g_main_loop_quit(g_mainloop); - } - } - } - else - { - LOGI("[%s] Callback: Failed to connect", __FUNCTION__); - if(g_mainloop) - { - g_main_loop_quit(g_mainloop); - } - } - } - else - { - LOGI("[%s] Callback: Disconnected.", __FUNCTION__); - } -} - -void bt_socket_data_received_impl(bt_socket_received_data_s *data, void *user_data) -{ - if(socket_fd == data->socket_fd) - { - if(data->data_size > 0) - { - if(!strncmp(data->data, quit_command, data->data_size)) - { - LOGI("[%s] Callback: Quit command.", __FUNCTION__); - if(g_mainloop) - { - g_main_loop_quit(g_mainloop); - } - } - } - else - { - LOGE("[%s] Callback: No data.", __FUNCTION__); - } - } - else - { - LOGI("[%s] Callback: Another socket - %d.", __FUNCTION__, data->socket_fd); - } -} - -bool bt_adapter_bonded_device_impl(bt_device_info_s *device_info, void *user_data) -{ - int i = 0; - if(device_info != NULL) - { - if(device_info->remote_name != NULL && !strcmp(device_info->remote_name, (char*)user_data)) - { - LOGI("[%s] Callback: chat_server is found in bonded list.", __FUNCTION__); - if( device_info->remote_address != NULL ) - { - LOGI("[%s] Callback: Address of chat_server - %s.", __FUNCTION__, device_info->remote_address); - bt_address = strdup(device_info->remote_address); - LOGI("[%s] Callback: The number of service_count - %d.", __FUNCTION__, device_info->service_count); - if(device_info->service_count <= 0) - { - bonding_state = BT_ERROR_SERVICE_SEARCH_FAILED; - } - else - { - bonding_state = BT_ERROR_NONE; - for(i=0; iservice_count; i++) - { - LOGI("[%s] Callback: service[%d] - %s", __FUNCTION__, i+1, device_info->service_uuid[i]); - } - LOGI("[%s] Callback: is_bonded - %d.", __FUNCTION__, device_info->is_bonded); - LOGI("[%s] Callback: is_connected - %d.", __FUNCTION__, device_info->is_connected); - LOGI("[%s] Callback: is_authorized - %d.", __FUNCTION__, device_info->is_authorized); - } - } - else - { - LOGE("[%s] Callback: Address of chat_server is NULL.", __FUNCTION__); - } - - return false; - } - } - - return true; -} - -void bt_adapter_device_discovery_state_changed_impl(int result, bt_adapter_device_discovery_state_e discovery_state, - bt_adapter_device_discovery_info_s *discovery_info, void *user_data) -{ - if(discovery_state == BT_ADAPTER_DEVICE_DISCOVERY_FOUND) - { - if(discovery_info->remote_address != NULL && !strcmp(discovery_info->remote_name, server_name)) - { - LOGI("[%s] Callback: chat_server is found.", __FUNCTION__); - LOGI("[%s] Callback: Address of chat_server - %s.", __FUNCTION__, discovery_info->remote_address); - LOGI("[%s] Callback: Device major class - %d.", __FUNCTION__, discovery_info->bt_class.major_device_class); - LOGI("[%s] Callback: Device minor class - %d.", __FUNCTION__, discovery_info->bt_class.minor_device_class); - LOGI("[%s] Callback: Service major class - %d.", __FUNCTION__, discovery_info->bt_class.major_service_class_mask); - bt_address = strdup(discovery_info->remote_address); - LOGI("[%s] Callback: is_bonded - %d.", __FUNCTION__, discovery_info->is_bonded); - bt_adapter_stop_device_discovery(); - } - else - { - LOGE("[%s] Callback: Another device is found.", __FUNCTION__); - } - } - else if(discovery_state == BT_ADAPTER_DEVICE_DISCOVERY_FINISHED) - { - LOGI("[%s] Callback: device discovery finished.", __FUNCTION__); - if(g_mainloop) - { - g_main_loop_quit(g_mainloop); - } - } -} - -void bt_device_bond_created_impl(int result, bt_device_info_s *device_info, void *user_data) -{ - if(device_info != NULL && !strcmp(device_info->remote_address, bt_address)) - { - bonding_state = result; - if(result == BT_ERROR_NONE) - { - LOGI("[%s] Callback: A bond with chat_server is created.", __FUNCTION__); - LOGI("[%s] Callback: The number of service - %d.", __FUNCTION__, device_info->service_count); - - int i = 0; - for(i=0; iservice_count; i++) - { - LOGI("[%s] Callback: service[%d] - %s", __FUNCTION__, i+1, device_info->service_uuid[i]); - } - LOGI("[%s] Callback: is_bonded - %d.", __FUNCTION__, device_info->is_bonded); - LOGI("[%s] Callback: is_connected - %d.", __FUNCTION__, device_info->is_connected); - } - else - { - LOGE("[%s] Callback: Creating a bond is failed.", __FUNCTION__); - } - } - else - { - LOGE("[%s] Callback: A bond with another device is created.", __FUNCTION__); - } - - if(g_mainloop) - { - g_main_loop_quit(g_mainloop); - } -} - -void bt_device_service_searched_impl(int result, bt_device_sdp_info_s* sdp_info, void* user_data) -{ - if(sdp_info != NULL && !strcmp(sdp_info->remote_address, bt_address)) - { - bonding_state = result; - if(result == BT_ERROR_NONE) - { - LOGI("[%s] Callback: Services of chat_service are found.", __FUNCTION__); - LOGI("[%s] Callback: The number of service - %d.", __FUNCTION__, sdp_info->service_count); - - int i = 0; - for(i = 0; i < sdp_info->service_count; i++) - { - LOGI("[%s] Callback: service[%d] - %s", __FUNCTION__, i+1, sdp_info->service_uuid[i]); - } - } - } - else - { - LOGE("[%s] Callback: Services of another device are found.", __FUNCTION__); - } - - if(g_mainloop) - { - g_main_loop_quit(g_mainloop); - } -} - - - - -int main() -{ - g_mainloop = g_main_loop_new(NULL, FALSE); - const char* my_uuid="11011101-0000-1000-8000-00805F9B34FB"; - int timeout_id = -1; - - LOGI("[%s] Client starts.", __FUNCTION__); - - if(bt_initialize() != BT_ERROR_NONE) - { - LOGE("[%s] bt_initialize() failed.", __FUNCTION__); - return -1; - } - - if(bt_adapter_get_state(&bt_state) != BT_ERROR_NONE) - { - LOGE("[%s] bt_adapter_get_state() failed.", __FUNCTION__); - return -1; - } - - // Enable BT - if(bt_state == BT_ADAPTER_DISABLED) - { - if(bt_adapter_set_state_changed_cb(bt_state_changed_impl, NULL) != BT_ERROR_NONE) - { - LOGE("[%s] bt_adapter_set_state_changed_cb() failed.", __FUNCTION__); - return -1; - } - - if(bt_adapter_enable() == BT_ERROR_NONE) - { - LOGI("[%s] bt_adapter_state_changed_cb will be called.", __FUNCTION__); - timeout_id = g_timeout_add (60000, timeout_func, g_mainloop); - g_main_loop_run(g_mainloop); - g_source_remove(timeout_id); - } - else - { - LOGE("[%s] bt_adapter_enable() failed.", __FUNCTION__); - return -1; - } - } - else - { - LOGI("[%s] BT was already enabled.", __FUNCTION__); - } - - // Device discovery - if(bt_state == BT_ADAPTER_ENABLED) - { - if(bt_adapter_foreach_bonded_device(bt_adapter_bonded_device_impl, server_name) != BT_ERROR_NONE) - { - LOGE("[%s] bt_adapter_foreach_bonded_device() failed.", __FUNCTION__); - return -1; - } - - if(bt_address == NULL) - { - if(bt_adapter_set_device_discovery_state_changed_cb(bt_adapter_device_discovery_state_changed_impl, NULL) - != BT_ERROR_NONE ) - { - LOGE("[%s] bt_adapter_set_device_discovery_state_changed_cb() failed.", __FUNCTION__); - return -1; - } - - if(bt_adapter_start_device_discovery() == BT_ERROR_NONE) - { - LOGI("[%s] bt_adapter_device_discovery_state_changed_cb will be called.", __FUNCTION__); - g_main_loop_run(g_mainloop); - } - else - { - LOGE("[%s] bt_adapter_start_device_discovery() failed.", __FUNCTION__); - return -1; - } - } - else - { - LOGI("[%s] chat_server is found in bonded device list.", __FUNCTION__); - } - } - else - { - LOGE("[%s] BT is not enabled.", __FUNCTION__); - return -1; - } - - // Create bond with a server - if(bonding_state == BT_ERROR_SERVICE_SEARCH_FAILED) - { - if(bt_device_set_service_searched_cb(bt_device_service_searched_impl, NULL) != BT_ERROR_NONE) - { - LOGE("[%s] bt_device_set_service_searched_cb() failed.", __FUNCTION__); - return -1; - } - - if(bt_device_start_service_search(bt_address) == BT_ERROR_NONE) - { - LOGI("[%s] bt_device_service_searched_cb will be called.", __FUNCTION__); - g_main_loop_run(g_mainloop); - } - else - { - LOGE("[%s] bt_device_start_service_search() failed.", __FUNCTION__); - return -1; - } - } - else if(bonding_state != BT_ERROR_NONE) - { - if(bt_device_set_bond_created_cb(bt_device_bond_created_impl, NULL) != BT_ERROR_NONE) - { - LOGE("[%s] bt_device_set_bond_created_cb() failed.", __FUNCTION__); - return -1; - } - - if(bt_device_create_bond(bt_address) == BT_ERROR_NONE) - { - LOGI("[%s] bt_device_bond_created_cb will be called.", __FUNCTION__); - g_main_loop_run(g_mainloop); - } - else - { - LOGE("[%s] bt_device_create_bond() failed.", __FUNCTION__); - return -1; - } - } - - // Connecting socket as a client - if( bonding_state == BT_ERROR_NONE ) - { - if( bt_socket_set_connection_state_changed_cb(bt_socket_connection_state_changed_impl, NULL) != BT_ERROR_NONE ) - { - LOGE("[%s] bt_socket_set_connection_state_changed_cb() failed.", __FUNCTION__); - return -1; - } - - if( bt_socket_set_data_received_cb(bt_socket_data_received_impl, NULL) != BT_ERROR_NONE ) - { - LOGE("[%s] bt_socket_set_data_received_cb() failed.", __FUNCTION__); - return -1; - } - - if( bt_socket_connect_rfcomm(bt_address, my_uuid) == BT_ERROR_NONE ) - { - LOGI("[%s] bt_socket_connection_state_changed_cb will be called.", __FUNCTION__); - g_main_loop_run(g_mainloop); - } - else - { - LOGE("[%s] bt_socket_connect_rfcomm() failed.", __FUNCTION__); - return -1; - } - - if( bt_socket_disconnect_rfcomm(socket_fd) != BT_ERROR_NONE ) - { - LOGE("[%s] bt_socket_disconnect_rfcomm() failed.", __FUNCTION__); - return -1; - } - } - else - { - LOGE("[%s] Bond is not created.", __FUNCTION__); - return -1; - } - - bt_deinitialize(); - - LOGI("[%s] Client ends.", __FUNCTION__); - return 0; -} diff --git a/test/bt_chat_server.c b/test/bt_chat_server.c deleted file mode 100644 index 95493a1..0000000 --- a/test/bt_chat_server.c +++ /dev/null @@ -1,281 +0,0 @@ -/* - * 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 -#include -#include -#include - -#ifdef LOG_TAG -#undef LOG_TAG -#endif -#define LOG_TAG "BT_CHAT_SERVER" - -/** - * Variables - **/ -static GMainLoop* g_mainloop = NULL; -static bt_adapter_visibility_mode_e visibility_mode = BT_ADAPTER_VISIBILITY_MODE_NON_DISCOVERABLE; -static bt_adapter_state_e bt_state = BT_ADAPTER_DISABLED; -static int service_socket = -1; -static int connected_socket = -1; -static char* quit_command = "Quit"; - - -/** - * Callback functions - **/ -gboolean timeout_func(gpointer data) -{ - LOGE("[%s] Timeout.", __FUNCTION__); - if(g_mainloop) - { - g_main_loop_quit((GMainLoop*)data); - } - - return FALSE; -} - -void bt_state_changed_impl(int result, bt_adapter_state_e adapter_state, void* user_data) -{ - if( adapter_state == BT_ADAPTER_ENABLED ) - { - if( result == BT_ERROR_NONE ) - { - LOGI("[%s] Callback: BT was enabled successfully.", __FUNCTION__); - bt_state = BT_ADAPTER_ENABLED; - } - else - { - LOGE("[%s] Callback: Failed to enable BT.", __FUNCTION__); - } - } - - if(g_mainloop) - { - g_main_loop_quit(g_mainloop); - } -} - -void bt_socket_connection_state_changed_impl(int result, bt_socket_connection_state_e connection_state, - bt_socket_connection_s *connection, void *user_data) -{ - if( result == BT_ERROR_NONE ) - { - LOGI("[%s] Callback: Result is BT_ERROR_NONE.", __FUNCTION__); - } - else - { - LOGI("[%s] Callback: Result is not BT_ERROR_NONE.", __FUNCTION__); - } - - if( connection_state == BT_SOCKET_CONNECTED ) - { - LOGI("[%s] Callback: Connected.", __FUNCTION__); - if( connection != NULL ) - { - connected_socket = connection->socket_fd; - LOGI("[%s] Callback: Socket of connection - %d.", __FUNCTION__, connected_socket); - LOGI("[%s] Callback: Role of connection - %d.", __FUNCTION__, connection->local_role); - LOGI("[%s] Callback: Address of connection - %s.", __FUNCTION__, connection->remote_address); - } - else - { - LOGI("[%s] Callback: No connection data", __FUNCTION__); - } - } - else - { - LOGI("[%s] Callback: Disconnected.", __FUNCTION__); - LOGI("[%s] Callback: Socket of connection - %d.", __FUNCTION__, connected_socket); - LOGI("[%s] Callback: Role of connection - %d.", __FUNCTION__, connection->local_role); - LOGI("[%s] Callback: Address of connection - %s.", __FUNCTION__, connection->remote_address); - } -} - -void bt_socket_data_received_impl(bt_socket_received_data_s *data, void *user_data) -{ - if( data->data_size > 0 ) - { - if( !strncmp(data->data, quit_command, data->data_size) ) - { - LOGI("[%s] Callback: Quit command.", __FUNCTION__); - if(g_mainloop) - { - g_main_loop_quit(g_mainloop); - } - } - - if( bt_socket_send_data(connected_socket, quit_command, strlen(quit_command)) == BT_ERROR_NONE ) - { - LOGI("[%s] Callback: Send quit command.", __FUNCTION__); - } - else - { - LOGE("[%s] Callback: bt_socket_send_data() failed.", __FUNCTION__); - } - } - else - { - LOGE("[%s] Callback: No data.", __FUNCTION__); - } -} - - -int main() -{ - g_mainloop = g_main_loop_new(NULL, FALSE); - const char* my_uuid="11011101-0000-1000-8000-00805F9B34FB"; - int timeout_id = -1; - - LOGI("[%s] Server starts.", __FUNCTION__); - - if(bt_initialize() != BT_ERROR_NONE) - { - LOGE("[%s] bt_initialize() failed.", __FUNCTION__); - return -1; - } - - if(bt_adapter_get_state(&bt_state) != BT_ERROR_NONE) - { - LOGE("[%s] bt_adapter_get_state() failed.", __FUNCTION__); - return -1; - } - - // Enable BT - if(bt_state == BT_ADAPTER_DISABLED) - { - if(bt_adapter_set_state_changed_cb(bt_state_changed_impl, NULL) != BT_ERROR_NONE) - { - LOGE("[%s] bt_adapter_set_state_changed_cb() failed.", __FUNCTION__); - return -1; - } - - if(bt_adapter_enable() == BT_ERROR_NONE) - { - LOGI("[%s] bt_adapter_state_changed_cb will be called.", __FUNCTION__); - timeout_id = g_timeout_add (60000, timeout_func, g_mainloop); - g_main_loop_run(g_mainloop); - g_source_remove(timeout_id); - } - else - { - LOGE("[%s] bt_adapter_enable() failed.", __FUNCTION__); - return -1; - } - } - else - { - LOGI("[%s] BT was already enabled.", __FUNCTION__); - } - - // Set name as "chat_server" - if(bt_state == BT_ADAPTER_ENABLED) - { - char* name = NULL; - if(bt_adapter_get_name(&name) != BT_ERROR_NONE) - { - LOGE("[%s] bt_adapter_get_name() failed.", __FUNCTION__); - return -1; - } - - if(strncmp(name, "chat_server", strlen(name)) != 0) - { - if(bt_adapter_set_name("chat_server") != BT_ERROR_NONE) - { - if (NULL != name) - free(name); - LOGE("[%s] bt_adapter_set_name() failed.", __FUNCTION__); - return -1; - } - } - if (NULL != name) - free(name); - } - else - { - LOGE("[%s] BT is not enabled.", __FUNCTION__); - return -1; - } - // Set visibility as BT_ADAPTER_VISIBILITY_MODE_GENERAL_DISCOVERABLE - if(bt_adapter_get_visibility(&visibility_mode) != BT_ERROR_NONE) - { - LOGE("[%s] bt_adapter_get_visibility() failed.", __FUNCTION__); - return -1; - } - - if(visibility_mode != BT_ADAPTER_VISIBILITY_MODE_GENERAL_DISCOVERABLE) - { - if(bt_adapter_set_visibility(BT_ADAPTER_VISIBILITY_MODE_GENERAL_DISCOVERABLE, 0) != BT_ERROR_NONE) - { - LOGE("[%s] bt_adapter_set_visibility() failed.", __FUNCTION__); - return -1; - } - visibility_mode = BT_ADAPTER_VISIBILITY_MODE_GENERAL_DISCOVERABLE; - } - else - { - LOGI("[%s] Visibility mode was already set as BT_ADAPTER_VISIBILITY_MODE_GENERAL_DISCOVERABLE.", __FUNCTION__); - } - - // Connecting socket as a server - if(bt_socket_create_rfcomm(my_uuid, &service_socket) != BT_ERROR_NONE) - { - LOGE("[%s] bt_socket_create_rfcomm() failed.", __FUNCTION__); - return -1; - } - LOGI("[%s] socket is created - %d.", __FUNCTION__, service_socket); - - if(bt_socket_set_connection_state_changed_cb(bt_socket_connection_state_changed_impl, NULL) != BT_ERROR_NONE) - { - LOGE("[%s] bt_socket_set_connection_state_changed_cb() failed.", __FUNCTION__); - return -1; - } - - if(bt_socket_set_data_received_cb(bt_socket_data_received_impl, NULL) != BT_ERROR_NONE) - { - LOGE("[%s] bt_socket_set_data_received_cb() failed.", __FUNCTION__); - return -1; - } - - if(bt_socket_listen_and_accept_rfcomm(service_socket, 5) == BT_ERROR_NONE) - { - LOGI("[%s] bt_socket_connection_state_changed_cb will be called.", __FUNCTION__); - g_main_loop_run(g_mainloop); - } - else - { - LOGE("[%s] bt_socket_listen_and_accept_rfcomm() failed.", __FUNCTION__); - return -1; - } - - sleep(5); // Wait for completing delivery - if(bt_socket_destroy_rfcomm(service_socket) != BT_ERROR_NONE) - { - LOGE("[%s] bt_socket_destroy_rfcomm() failed.", __FUNCTION__); - return -1; - } - else - { - LOGE("[%s] bt_socket_destroy_rfcomm() succeeded.", __FUNCTION__); - } - - bt_deinitialize(); - - LOGI("[%s] Server ends.", __FUNCTION__); - return 0; -} diff --git a/test/bt_infinite_spp_test.c b/test/bt_infinite_spp_test.c new file mode 100644 index 0000000..cde3b6e --- /dev/null +++ b/test/bt_infinite_spp_test.c @@ -0,0 +1,512 @@ +/* + * Copyright (c) 2014 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 +#include +#include +#include +#include + +#undef LOG_TAG +#define LOG_TAG "BT_SPP_TEST" + +#define BT_DBG(fmt, args...) \ + SLOGD(fmt, ##args) +#define BT_INFO(fmt, args...) \ + SLOGI(fmt, ##args) +#define BT_ERR(fmt, args...) \ + SLOGE(fmt, ##args) + +typedef enum +{ + BT_SPP_TEST_ROLE_SERVER = 0x00, + BT_SPP_TEST_ROLE_CLIENT, +} bt_spp_test_role_e; + +#define BT_INFINITE_SPP_TEST_REMOTE_ADDRESS_FILE_PATH "/opt/usr/media/Others/.bt_dump/spp_test_addr" +#define BT_INFINITE_SPP_TEST_RESULT_FILE_PATH "/opt/usr/media/Others/.bt_dump/spp_result.log" + +bool __bt_connect_spp(void); +static gboolean __bt_send_data(gpointer user_data); +bool __bt_verify_data(char *data, int data_size); +bool __bt_bond_remote_device(void); +bool __bt_is_paired(void); + +static GMainLoop* g_mainloop = NULL; + +static bt_spp_test_role_e spp_role = BT_SPP_TEST_ROLE_SERVER; +static char remote_addr[18] = {0,}; +static bt_adapter_state_e bt_state = BT_ADAPTER_DISABLED; + +const char *spp_secure_uuid = "fa87c0d0-afac-11de-8a39-0800200c9a66"; +static int server_fd = -1; +static int socket_fd = -1; +static bool is_receive_complete = false; + +static int packet_size = 65536; +static char *buf = NULL; +static int total_count = 32; +static int sent_count = 0; +static int receive_count = 0; +static int receive_index = 0; + +static struct timeval start_time = {0,}; +static struct timeval end_time = {0,}; +static struct timeval diff_time = {0,}; + +static int sum_time_ms = 0; +static int avg_time_ms = 0; +static int total_test_count = 0; + +void __bt_create_log_dump(void) +{ + char *argv[] = {NULL}; + + execv("/usr/bin/all_log_dump.sh", argv); + + if (g_mainloop) + g_main_loop_quit(g_mainloop); + else + exit(0); +} + +static void __bt_socket_data_received_cb(bt_socket_received_data_s *data, void *user_data) +{ + if (data == NULL) { + BT_ERR("data is NULL"); + return; + } + BT_INFO("FD = %d, Buffer len = %d", data->socket_fd, data->data_size); + + if (__bt_verify_data(data->data, data->data_size) == false) + __bt_create_log_dump(); + + if (is_receive_complete == true) + g_idle_add(__bt_send_data, NULL); +} + +static void __bt_device_bond_created_cb(int result, bt_device_info_s *device_info, void *user_data) +{ + if (result != BT_ERROR_NONE) { + BT_ERR("result[0x%X]", result); + return; + } + + if (strcmp(device_info->remote_address, remote_addr) == 0) { + if (__bt_connect_spp() == false) + BT_ERR("__bt_connect_spp() failed."); + } +} + +static bool __bt_adapter_bonded_device_cb(bt_device_info_s *device_info, void *user_data) +{ + bool *is_paired = (bool*)user_data; + + if (strcmp(device_info->remote_address, remote_addr) == 0) { + BT_INFO("remote_addr is exist."); + *is_paired = true; + return false; + } + + return true; +} + +void __bt_adapter_state_changed_cb(int result, bt_adapter_state_e adapter_state, void *user_data) +{ + BT_INFO("result [0x%04x] state = %d", result, adapter_state); + + if (result == BT_ERROR_NONE) { + bt_state = adapter_state; + if (adapter_state == BT_ADAPTER_ENABLED) { + if (__bt_is_paired() == true) + __bt_connect_spp(); + else + __bt_bond_remote_device(); + } + } +} + +void __bt_socket_connection_state_changed_cb(int result, bt_socket_connection_state_e connection_state, bt_socket_connection_s *connection, void *user_data) +{ + if (connection_state == BT_SOCKET_CONNECTED) { + BT_INFO("RFCOMM connected, result [0x%04x] Fd = %d, device add = %s, Role = %s", + result, connection->socket_fd, connection->remote_address, + (connection->local_role == BT_SOCKET_SERVER) ? "SERVER" : "CLIENT"); + + if (connection->socket_fd > 0) { + socket_fd = connection->socket_fd; + if (spp_role == BT_SPP_TEST_ROLE_CLIENT) + g_idle_add(__bt_send_data, NULL); + } else { + BT_ERR("socket_fd is INVALID"); + } + } else { + BT_INFO("RFCOMM disconnected, result [0x%04x] Fd = %d, device add = %s", + result, connection->socket_fd, connection->remote_address); + __bt_create_log_dump(); + } +} + +void __bt_spp_calc_speed(void) +{ + int total_time_ms; + FILE *fp = NULL; + static char str_speed[30] = "\0"; + int speed; + + diff_time.tv_sec = end_time.tv_sec - start_time.tv_sec; + diff_time.tv_usec = end_time.tv_usec - start_time.tv_usec; + + if(diff_time.tv_usec < 0) + { + diff_time.tv_sec = diff_time.tv_sec - 1; + diff_time.tv_usec = diff_time.tv_usec + 1000000; + } + + fp = fopen(BT_INFINITE_SPP_TEST_RESULT_FILE_PATH, "a+"); + /* Fix : NULL_RETURNS */ + if (fp == NULL) { + BT_ERR("Cannot open file: %s\n", BT_INFINITE_SPP_TEST_RESULT_FILE_PATH); + return; + } + total_time_ms = (diff_time.tv_sec * 1000); + total_time_ms += diff_time.tv_usec / 1000; + + speed = (packet_size * total_count * 8) / total_time_ms; + + BT_INFO("%s @ %d kbps", "2MB", speed); + sprintf(str_speed, "%s @ %d kbps", "2MB", speed); + fprintf(fp, "%s\n", str_speed); + + total_test_count++; + sum_time_ms += total_time_ms; + if (total_test_count % 10 == 0) { + avg_time_ms = sum_time_ms / total_test_count; + speed = (packet_size * total_count * 8) / avg_time_ms; + BT_INFO("[AVG(%d times)] %d kbps", total_test_count, speed); + sprintf(str_speed, "[AVG(%d times)] %d kbps", total_test_count, speed); + fprintf(fp, "%s\n", str_speed); + } + + if (total_test_count == 1000) { + sum_time_ms = 0; + avg_time_ms = 0; + total_test_count = 0; + } + + fclose(fp); +} + +void __bt_make_data(void) +{ + int i; + int j; + char w = 0x20; + + memset(buf, 0x00, packet_size); + for (i = 0; i < packet_size / 256; i++) { + for (j = 0; j < 256; j++) { + buf[i * 256 + j] = w; + } + + w++; + if (w > 0x7e) + w = 0x20; + } +} + +bool __bt_verify_data(char *data, int data_size) +{ + int i; + + if (receive_count == 0 && receive_index == 0) + gettimeofday(&start_time, NULL); + + for (i = 0; i < data_size; i++) { + if (data[i] != buf[receive_index]) { + BT_ERR("data error. rcv_cnt=%d, data[%d]=%d, buf[%d]=%d", receive_count, i, data[i], receive_index, buf[receive_index]); + return false; + } + + receive_index++; + if (receive_index == packet_size) { + receive_index = 0; + receive_count++; + + if (receive_count == total_count) + is_receive_complete = true; + } + } + + if (is_receive_complete == true) { + gettimeofday(&end_time, NULL); + __bt_spp_calc_speed(); + receive_count = 0; + receive_index = 0; + } + + return true; +} + +static gboolean __bt_send_data(gpointer user_data) +{ + int ret = BT_ERROR_NONE; + int write = 0; + int state = 0; + struct timeval tv_write_timeout = {0, }; + fd_set wfds; + int fail_count = 0; + + tv_write_timeout.tv_sec = 1; + + is_receive_complete = false; + + if (sent_count == 0) + gettimeofday(&start_time, NULL); + + while (write < packet_size) { + FD_ZERO(&wfds); + FD_SET(socket_fd, &wfds); + state = select(socket_fd + 1, NULL, &wfds, NULL, &tv_write_timeout); + if (state == -1) { + BT_ERR("select() error.[0x%X]", ret); + __bt_create_log_dump(); + return FALSE; + } else { + if (FD_ISSET(socket_fd, &wfds)) { + ret = bt_socket_send_data(socket_fd, buf + write, packet_size - write); + if(ret <= 0) { + BT_ERR("bt_socket_send_data() failed.[0x%X]", ret); + __bt_create_log_dump(); + return FALSE; + } else { + write += ret; + } + fail_count = 0; + } else { + BT_ERR("socket is NOT ready.(fail_count = %d)", fail_count); + if (fail_count++ == 10) { + BT_ERR("__bt_send_data failed."); + __bt_create_log_dump(); + return FALSE; + } + } + } + } + + sent_count++; + if (sent_count == total_count) { + BT_INFO("Last packet."); + gettimeofday(&end_time, NULL); + __bt_spp_calc_speed(); + sent_count = 0; + } else { + return TRUE; + } + + return FALSE; +} + +bool __bt_connect_spp(void) +{ + int ret = BT_ERROR_NONE; + + if (spp_role == BT_SPP_TEST_ROLE_SERVER) { + if (server_fd < 0) { + ret = bt_socket_create_rfcomm(spp_secure_uuid, &server_fd); + if (ret != BT_ERROR_NONE) { + BT_ERR("bt_socket_create_rfcomm() failed.[0x%X]", ret); + return false; + } + } + + ret = bt_socket_listen_and_accept_rfcomm(server_fd, 1); + if (ret != BT_ERROR_NONE) { + BT_ERR("bt_socket_listen_and_accept_rfcomm() failed.[0x%X]", ret); + return false; + } + } else { + ret = bt_socket_connect_rfcomm(remote_addr, spp_secure_uuid); + if (ret != BT_ERROR_NONE) { + BT_ERR("bt_socket_connect_rfcomm() failed.[0x%X]", ret); + bt_socket_destroy_rfcomm(server_fd); + return false; + } + } + + return true; +} + +bool __bt_bond_remote_device(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_device_set_bond_created_cb(__bt_device_bond_created_cb, NULL); + if (ret != BT_ERROR_NONE) { + BT_ERR("bt_device_set_bond_created_cb() failed.[0x%X]", ret); + return false; + } + + if (spp_role == BT_SPP_TEST_ROLE_CLIENT) { + ret = bt_device_create_bond(remote_addr); + if (ret != BT_ERROR_NONE) { + BT_ERR("bt_device_create_bond() failed.[0x%X]", ret); + return false; + } + } + + return true; +} + +bool __bt_is_paired(void) +{ + int ret = BT_ERROR_NONE; + bool is_paired = false; + + ret = bt_adapter_foreach_bonded_device(__bt_adapter_bonded_device_cb, &is_paired); + if (ret != BT_ERROR_NONE) { + BT_ERR("bt_adapter_foreach_bonded_device() failed.[0x%X]", ret); + return false; + } + + return is_paired; +} + +bool __bt_init(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_initialize(); + if(ret != BT_ERROR_NONE) { + BT_ERR("bt_initialize() failed.[0x%X]", ret); + return false; + } + + ret = bt_adapter_get_state(&bt_state); + if(ret != BT_ERROR_NONE) { + BT_ERR("bt_adapter_get_state() failed.[0x%X]", ret); + return false; + } + + ret = bt_adapter_set_state_changed_cb(__bt_adapter_state_changed_cb, NULL); + if(ret != BT_ERROR_NONE) { + BT_ERR("bt_adapter_get_state() failed.[0x%X]", ret); + return false; + } + + ret = bt_socket_set_connection_state_changed_cb(__bt_socket_connection_state_changed_cb, NULL); + if (ret != BT_ERROR_NONE) { + BT_ERR("bt_socket_set_connection_state_changed_cb() failed.[0x%X]", ret); + return false; + } + + ret = bt_socket_set_data_received_cb(__bt_socket_data_received_cb, NULL); + if (ret != BT_ERROR_NONE) { + BT_ERR("bt_socket_set_data_received_cb() failed.[0x%X]", ret); + return false; + } + + if (buf == NULL) { + buf = malloc(packet_size); + if (buf == NULL) { + BT_ERR("Out of memory"); + return false; + } + __bt_make_data(); + } + + return true; +} + +void __bt_deinit(void) +{ + int ret = BT_ERROR_NONE; + + if (buf) + free(buf); + + if (server_fd >= 0) + bt_socket_destroy_rfcomm(server_fd); + + ret = bt_socket_unset_data_received_cb(); + if (ret != BT_ERROR_NONE) + BT_ERR("bt_socket_unset_data_received_cb() failed.[0x%X]", ret); + + ret = bt_socket_unset_connection_state_changed_cb(); + if (ret != BT_ERROR_NONE) + BT_ERR("bt_socket_unset_connection_state_changed_cb() failed.[0x%X]", ret); + + ret = bt_device_unset_bond_created_cb(); + if (ret != BT_ERROR_NONE) + BT_ERR("bt_device_unset_bond_created_cb() failed.[0x%X]", ret); + + ret = bt_deinitialize(); + if(ret != BT_ERROR_NONE) + BT_ERR("bt_deinitialize() failed.[0x%X]", ret); +} + +bool __bt_set_remote_address(void) +{ + FILE *fp = NULL; + + if ((fp = fopen(BT_INFINITE_SPP_TEST_REMOTE_ADDRESS_FILE_PATH, "r")) == NULL) { + BT_ERR("remote_addr file is NOT exist."); + return false; + } + + if (fgets(remote_addr, 18, fp) == NULL) { + BT_ERR("remote_addr is INVALID."); + fclose(fp); + return false; + } + + fclose(fp); + return true; +} + +int main(int argc, char *argv[]) +{ + if (argc == 2 && strcmp(argv[1], "client") == 0) + spp_role = BT_SPP_TEST_ROLE_CLIENT; + BT_INFO("SPP test role is %s", spp_role==BT_SPP_TEST_ROLE_SERVER?"SERVER":"CLIENT"); + + if (__bt_set_remote_address() == false) + return -1; + + if (__bt_init() == false) + goto fail; + + if (bt_state == BT_ADAPTER_ENABLED) { + if (__bt_is_paired() == true) { + if (__bt_connect_spp() == false) + goto fail; + } else { + if (__bt_bond_remote_device() == false) + goto fail; + } + } + + g_mainloop = g_main_loop_new(NULL, FALSE); + g_main_loop_run(g_mainloop); + +fail: + if (g_mainloop) + g_main_loop_unref(g_mainloop); + + __bt_deinit(); + + return 0; +} diff --git a/test/bt_infinite_spp_test_client.service b/test/bt_infinite_spp_test_client.service new file mode 100644 index 0000000..f425cb8 --- /dev/null +++ b/test/bt_infinite_spp_test_client.service @@ -0,0 +1,11 @@ +[Unit] +Description=BT SPP test infinitely +PartOf=bluetooth-hciattach@bt.service + +[Service] +Type=oneshot +ExecStart=/usr/bin/bt_infinite_spp_test client +RemainAfterExit=yes + +[Install] +RequiredBy=bluetooth-hciattach@bt.service diff --git a/test/bt_infinite_spp_test_server.service b/test/bt_infinite_spp_test_server.service new file mode 100644 index 0000000..917658b --- /dev/null +++ b/test/bt_infinite_spp_test_server.service @@ -0,0 +1,11 @@ +[Unit] +Description=BT SPP test infinitely +PartOf=bluetooth-hciattach@bt.service + +[Service] +Type=oneshot +ExecStart=/usr/bin/bt_infinite_spp_test +RemainAfterExit=yes + +[Install] +RequiredBy=bluetooth-hciattach@bt.service diff --git a/test/bt_onoff.c b/test/bt_onoff.c new file mode 100644 index 0000000..f95106a --- /dev/null +++ b/test/bt_onoff.c @@ -0,0 +1,131 @@ +/* + * 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. + */ + +/** + * @file bt_onoff.c + * @brief This is the source file for bt activation/deactivation. + */ + +#include +#include + +#include "bluetooth.h" + +#define PRT(format, args...) printf("%s:%d() "format, __FUNCTION__, __LINE__, ##args) +#define TC_PRT(format, args...) PRT(format"\n", ##args) + +GMainLoop *main_loop = NULL; +static guint onoff_timer = 0; + +static void __bt_adapter_state_changed_cb(int result, bt_adapter_state_e adapter_state, void *user_data) +{ + TC_PRT("state(%d), error(%d)", adapter_state, result); + + if (onoff_timer) + g_source_remove(onoff_timer); + onoff_timer = 0; + + if (result != BT_ERROR_NONE) { + char *argv[] = {NULL}; + execv("all_log_dump.sh", argv); + } + + if (main_loop) + g_main_loop_quit(main_loop); + else + exit(0); +} + +static gboolean __bt_onoff_timeout_cb(gpointer data) +{ + TC_PRT("Timed out"); + + char *argv[] = {NULL}; + execv("all_log_dump.sh", argv); + + if (main_loop) + g_main_loop_quit(main_loop); + else + exit(0); + + return FALSE; +} + +int main(int argc, char* argv[]) +{ + int ret; + bt_adapter_state_e state; + + if(bt_initialize() != BT_ERROR_NONE) + { + TC_PRT("bt_initialize() failed."); + return -1; + } + if (bt_adapter_set_state_changed_cb(__bt_adapter_state_changed_cb, NULL) != BT_ERROR_NONE) + { + TC_PRT("bt_adapter_set_state_changed_cb() failed."); + goto DONE; + } + + main_loop = g_main_loop_new(NULL, FALSE); + + bt_adapter_get_state(&state); + ret = bt_adapter_get_state(&state); + TC_PRT("state(%d), error(%d)", state, ret); + + onoff_timer = g_timeout_add(20000, (GSourceFunc)__bt_onoff_timeout_cb, NULL); + + if (argc <= 1) { + if (state == BT_ADAPTER_DISABLED) + ret = bt_adapter_enable(); + else + ret = bt_adapter_disable(); + TC_PRT("bt_adapter_%s() error(%d)", state==BT_ADAPTER_DISABLED?"enable":"disable", ret); + } else { + if (argv[1][0] == '0') { + if (state == BT_ADAPTER_DISABLED) { + TC_PRT("Already disabled"); + goto DONE; + } else { + ret = bt_adapter_disable(); + TC_PRT("bt_adapter_disable() error(%d)", ret); + if (ret != BT_ERROR_NONE) + goto DONE; + } + } else { + if (state == BT_ADAPTER_ENABLED) { + TC_PRT("Already eabled"); + goto DONE; + } else { + ret = bt_adapter_enable(); + TC_PRT("bt_adapter_enable() error(%d)", ret); + if (ret != BT_ERROR_NONE) + goto DONE; + } + } + } + + g_main_loop_run(main_loop); + +DONE: + if (onoff_timer) + g_source_remove(onoff_timer); + onoff_timer = 0; + bt_adapter_unset_state_changed_cb(); + bt_deinitialize(); + + return 0; +} diff --git a/test/bt_unit_test.c b/test/bt_unit_test.c index 2ce27f4..8415988 100644 --- a/test/bt_unit_test.c +++ b/test/bt_unit_test.c @@ -28,441 +28,5345 @@ #include #include +#include +#include #include -#include +#include +#include #include "bluetooth.h" +#include "bluetooth_internal.h" +#include "bluetooth_private.h" +#include "bluetooth-telephony-api.h" +#include "bt_unit_test.h" -#define BUFFER_LEN 10 -#define PRT(format, args...) printf("%s:%d() "format, __FUNCTION__, __LINE__, ##args) -#define TC_PRT(format, args...) PRT(format"\n", ##args) +const char *spp_uuid = "00001101-0000-1000-8000-00805F9B34FB"; +const char *opp_uuid = "00001105-0000-1000-8000-00805f9b34fb"; +const char *custom_uuid = "fa87c0d0-afac-11de-8a39-0800200c9a66"; + +static bt_unit_test_table_e current_tc_table; +static char remote_addr[18] = "F6:FB:8F:D8:C8:7C"; +static bool input_automated_test_delay = false; + +static bool need_to_set_params = false; +static int g_test_id = -1; +static tc_params_t g_test_param = {0,}; + +static int server_fd; +static int client_fd; +static int custom_server_fd; +static int custom_client_fd; + +static int bt_onoff_cnt = 0; +static int bt_onoff_cnt_success = 0; +static int bt_onoff_cnt_fail = 0; +static time_t bt_onoff_timer; + +static gboolean is_sub_index = FALSE; +#ifdef BT_ENABLE_LEGACY_GATT_CLIENT +int service_index; +int char_service_index; +static int selected_service_index = -1; +static int selected_char_index = 0; +#endif + +static bt_advertiser_h advertiser = NULL; +static bt_advertiser_h advertiser_list[3] = {NULL, }; +static int advertiser_index = 0; + +bt_gatt_client_h client = NULL; + +bt_gatt_server_h server = NULL; +typedef struct { + bt_gatt_h svc; + bt_gatt_h chr; + bt_gatt_h desc; +} gatt_handle_t; +gatt_handle_t battery_h; +gatt_handle_t heart_rate_h; +gatt_handle_t thermometer_h; +gatt_handle_t custom_h; + +#ifdef BT_ENABLE_LEGACY_GATT_CLIENT +bt_gatt_attribute_h service_clone[MAX_SERVICES]; +bt_gatt_attribute_h characteristics[MAX_SERVICES]; +bt_gatt_attribute_h characteristics_services[MAX_SERVICES]; +#endif + +static unsigned char *hash = NULL; +static unsigned char *randomizer = NULL; +int hash_len; +int rand_len; + +bt_call_list_h call_list; +GMainLoop *main_loop = NULL; + +tc_table_t tc_main[] = { + /* Categories */ + {"SET ADDRESS" , BT_UNIT_TEST_FUNCTION_SET_ADDRESS}, + {"bt_initialize" , BT_UNIT_TEST_FUNCTION_INITIALIZE}, + {"bt_deinitialize" , BT_UNIT_TEST_FUNCTION_DEINITIALIZE}, + {"Adapter" , BT_UNIT_TEST_TABLE_ADAPTER}, + {"Adapter LE" , BT_UNIT_TEST_TABLE_ADAPTER_LE}, + {"Device" , BT_UNIT_TEST_TABLE_DEVICE}, + {"Socket" , BT_UNIT_TEST_TABLE_SOCKET}, + {"Opp" , BT_UNIT_TEST_TABLE_OPP}, + {"Audio(ag, a2dp, call)" , BT_UNIT_TEST_TABLE_AUDIO}, + {"Pan(nap, panu)" , BT_UNIT_TEST_TABLE_PAN}, + {"Gatt" , BT_UNIT_TEST_TABLE_GATT}, + {"Avrcp" , BT_UNIT_TEST_TABLE_AVRCP}, + {"Hid" , BT_UNIT_TEST_TABLE_HID}, +#ifdef TIZEN_WEARABLE + {"HF Role" , BT_UNIT_TEST_TABLE_HF}, + {"PBAP Client" , BT_UNIT_TEST_TABLE_PBAP_CLIENT}, +#endif + {"Automated test" , BT_UNIT_TEST_TABLE_AUTOMATED_TEST}, + {"Initialize All" , BT_UNIT_TEST_FUNCTION_INITIALIZE_ALL}, + {"FINISH" , BT_UNIT_TEST_TABLE_FINISH}, + {NULL , 0x0000}, +}; + +tc_table_t tc_adapter[] = { + /* Adapter functions */ + {"BACK" , BT_UNIT_TEST_FUNCTION_BACK}, + {"bt_adapter_get_state" , BT_UNIT_TEST_FUNCTION_ADAPTER_GET_STATE}, + {"bt_adapter_enable" , BT_UNIT_TEST_FUNCTION_ADAPTER_ENABLE}, + {"bt_adapter_disable" , BT_UNIT_TEST_FUNCTION_ADAPTER_DISABLE}, + {"bt_adapter_recover" , BT_UNIT_TEST_FUNCTION_ADAPTER_RECOVER}, + {"bt_adapter_start_device_discovery" , BT_UNIT_TEST_FUNCTION_ADAPTER_START_DEVICE_DISCOVERY}, + {"bt_adapter_stop_device_discovery" , BT_UNIT_TEST_FUNCTION_ADAPTER_STOP_DEVICE_DISCOVERY}, + {"bt_adapter_is_discovering" , BT_UNIT_TEST_FUNCTION_ADAPTER_IS_DISCOVERING}, + {"bt_adapter_foreach_bonded_device" , BT_UNIT_TEST_FUNCTION_ADAPTER_FOREACH_BONDED_DEVICE}, + {"bt_adapter_get_bonded_device_info" , BT_UNIT_TEST_FUNCTION_ADAPTER_GET_BONDED_DEVICE_INFO}, + {"bt_adapter_is_service_used" , BT_UNIT_TEST_FUNCTION_ADAPTER_IS_SERVICE_USED}, + {"bt_adapter_get_visibility" , BT_UNIT_TEST_FUNCTION_ADAPTER_GET_VISIBILITY}, + {"bt_adapter_set_device_discovery_state_changed_cb" , BT_UNIT_TEST_FUNCTION_ADAPTER_SET_DEVICE_DISCOVERY_STATE_CHANGED_CB}, + {"bt_adapter_unset_device_discovery_state_changed_cb" , BT_UNIT_TEST_FUNCTION_ADAPTER_UNSET_DEVICE_DISCOVERY_STATE_CHANGED_CB}, + {"bt_adapter_get_local_oob_data" , BT_UNIT_TEST_FUNCTION_ADAPTER_GET_LOCAL_OOB_DATA}, + {"bt_adapter_set_remote_oob_data" , BT_UNIT_TEST_FUNCTION_ADAPTER_SET_LOCAL_OOB_DATA}, + {"bt_adapter_remove_remote_oob_data" , BT_UNIT_TEST_FUNCTION_ADAPTER_REMOVE_REMOTE_OOB_DATA}, + {"bt_adapter_set_visibility_mode_changed_cb" , BT_UNIT_TEST_FUNCTION_ADAPTER_SET_VISIBILITY_MODE_CHANGED_CB}, + {"bt_adapter_unset_visibility_mode_changed_cb" , BT_UNIT_TEST_FUNCTION_ADAPTER_UNSET_VISIBILITY_MODE_CHANGED_CB}, + {"bt_adapter_set_visibility_duration_changed_cb" , BT_UNIT_TEST_FUNCTION_ADAPTER_SET_VISIBILITY_DURATION_CHANGED_CB}, + {"bt_adapter_unset_visibility_duration_changed_cb" , BT_UNIT_TEST_FUNCTION_ADAPTER_UNSET_VISIBILITY_DURATION_CHANGED_CB}, + {"bt_adapter_set_connectable_changed_cb" , BT_UNIT_TEST_FUNCTION_ADAPTER_SET_CONNECTABLE_CHANGED_CB}, + {"bt_adapter_unset_connectable_changed_cb" , BT_UNIT_TEST_FUNCTION_ADAPTER_UNSET_CONNECTABLE_CHANGED_CB}, + {"bt_adapter_get_connectable" , BT_UNIT_TEST_FUNCTION_ADAPTER_GET_CONNECTABLE}, + {"bt_adapter_set_connectable" , BT_UNIT_TEST_FUNCTION_ADAPTER_SET_CONNECTABLE}, + {"bt_adapter_get_version" , BT_UNIT_TEST_FUNCTION_ADAPTER_GET_VERSION}, + {"bt_adapter_get_local_info" , BT_UNIT_TEST_FUNCTION_ADAPTER_GET_LOCAL_INFO}, + {"bt_adapter_set_manufacturer_data_changed_cb" , BT_UNIT_TEST_FUNCTION_ADAPTER_SET_MANUFACTURER_DATA_CHANGED_CB}, + {"bt_adapter_unset_manufacturer_data_changed_cb" , BT_UNIT_TEST_FUNCTION_ADAPTER_UNSET_MANUFACTURER_DATA_CHANGED_CB}, + {"bt_adapter_set_manufacturer_data" , BT_UNIT_TEST_FUNCTION_ADAPTER_SET_MANUFACTURER_DATA}, + {"Select this menu to set parameters and then select the function again." , BT_UNIT_TEST_FUNCTION_ACTIVATE_FLAG_TO_SET_PARAMETERS}, + {NULL , 0x0000}, +}; + +tc_table_t tc_adapter_le[] = { + /* Adapter functions */ + {"BACK" , BT_UNIT_TEST_FUNCTION_BACK}, + {"bt_adapter_le_get_state" , BT_UNIT_TEST_FUNCTION_ADAPTER_LE_GET_STATE}, + {"bt_adapter_le_enable" , BT_UNIT_TEST_FUNCTION_ADAPTER_LE_ENABLE}, + {"bt_adapter_le_disable" , BT_UNIT_TEST_FUNCTION_ADAPTER_LE_DISABLE}, + {"bt_adapter_le_set_scan_mode" , BT_UNIT_TEST_FUNCTION_ADAPTER_LE_SET_SCAN_MODE}, + {"bt_adapter_le_start_scan" , BT_UNIT_TEST_FUNCTION_ADAPTER_LE_START_SCAN}, + {"bt_adapter_le_stop_scan" , BT_UNIT_TEST_FUNCTION_ADAPTER_LE_STOP_SCAN}, +#ifndef TIZEN_WEARABLE + {"bt_adapter_le_start_device_discovery" , BT_UNIT_TEST_FUNCTION_ADAPTER_LE_START_DEVICE_DISCOVERY}, + {"bt_adapter_le_stop_device_discovery" , BT_UNIT_TEST_FUNCTION_ADAPTER_LE_STOP_DEVICE_DISCOVERY}, +#endif + {"bt_adapter_le_add_advertising_data" , BT_UNIT_TEST_FUNCTION_ADAPTER_LE_ADD_ADVERTISING_DATA}, + {"bt_adapter_le_set_advertising_mode" , BT_UNIT_TEST_FUNCTION_ADAPTER_LE_SET_ADVERTISING_MODE}, + {"bt_adapter_le_set_advertising_filter_policy" , BT_UNIT_TEST_FUNCTION_ADAPTER_LE_SET_ADVERTISING_FILTER_POLICY}, + {"bt_adapter_le_set_advertising_connectable" , BT_UNIT_TEST_FUNCTION_ADAPTER_LE_SET_ADVERTISING_CONNECTABLE}, + {"bt_adapter_le_start_advertising_new" , BT_UNIT_TEST_FUNCTION_ADAPTER_LE_START_ADVERTISING_NEW}, +#ifndef TIZEN_WEARABLE + {"bt_adapter_le_start_advertising" , BT_UNIT_TEST_FUNCTION_ADAPTER_LE_START_ADVERTISING}, +#endif + {"bt_adapter_le_stop_advertising" , BT_UNIT_TEST_FUNCTION_ADAPTER_LE_STOP_ADVERTISING}, + {"bt_adapter_le_add_white_list" , BT_UNIT_TEST_FUNCTION_ADAPTER_LE_ADD_WHITE_LIST}, + {"bt_adapter_le_remove_white_list" , BT_UNIT_TEST_FUNCTION_ADAPTER_LE_REMOVE_WHITE_LIST}, +#ifndef TIZEN_WEARABLE + {"bt_adapter_le_clear_white_list" , BT_UNIT_TEST_FUNCTION_ADAPTER_LE_CLEAR_WHITE_LIST}, +#endif + {"bt_adapter_le_enable_privacy" , BT_UNIT_TEST_FUNCTION_ADAPTER_LE_ENABLE_PRIVACY}, + {"Register scan filter (Device Address)" , BT_UNIT_TEST_FUNCTION_ADAPTER_LE_REGISTER_SCAN_FILTER_DEVICE_ADDRESS}, + {"Register scan filter (Service UUID)" , BT_UNIT_TEST_FUNCTION_ADAPTER_LE_REGISTER_SCAN_FILTER_SERVICE_UUID}, + {"Register scan filter (Service Solicitation UUID)" , BT_UNIT_TEST_FUNCTION_ADAPTER_LE_REGISTER_SCAN_FILTER_SERVICE_SOLICITATION_UUID}, + {"Unregister all scan filters" , BT_UNIT_TEST_FUNCTION_ADAPTER_LE_UNREGISTER_ALL_SCAN_FILTERS}, +#ifndef TIZEN_WEARABLE + {"bt_adapter_le_set_device_discovery_state_changed_cb" , BT_UNIT_TEST_FUNCTION_ADAPTER_LE_SET_DEVICE_DISCOVERY_STATE_CHANGED_CB}, + {"bt_adapter_le_unset_device_discovery_state_changed_cb" , BT_UNIT_TEST_FUNCTION_ADAPTER_LE_UNSET_DEVICE_DISCOVERY_STATE_CHANGED_CB}, +#endif + {"Select this menu to set parameters and then select the function again." , BT_UNIT_TEST_FUNCTION_ACTIVATE_FLAG_TO_SET_PARAMETERS}, + {NULL , 0x0000}, +}; + +tc_table_t tc_device[] = { + /* Device functions */ + {"BACK" , BT_UNIT_TEST_FUNCTION_BACK}, + {"bt_device_set_authorization (true)" , BT_UNIT_TEST_FUNCTION_DEVICE_SET_AUTHORIZATION_TRUE}, + {"bt_device_set_authorization (false)" , BT_UNIT_TEST_FUNCTION_DEVICE_SET_AUTHORIZATION_FALSE}, + {"bt_device_set_authorization_changed_cb" , BT_UNIT_TEST_FUNCTION_DEVICE_SET_AUTHORIZATION_CHANGED_CB}, + {"bt_device_unset_authorization_changed_cb" , BT_UNIT_TEST_FUNCTION_DEVICE_UNSET_AUTHORIZATION_CHANGED_CB}, + {"bt_device_set_connection_state_changed_cb" , BT_UNIT_TEST_FUNCTION_DEVICE_SET_CONNECTION_STAET_CHANGED_CB}, + {"bt_device_unset_connection_state_changed_cb" , BT_UNIT_TEST_FUNCTION_DEVICE_UNSET_CONNECTION_STAET_CHANGED_CB}, + {"bt_device_foreach_connected_profiles" , BT_UNIT_TEST_FUNCTION_DEVICE_FOREACH_CONNECTED_PROFILES}, + {"bt_device_is_profile_connected" , BT_UNIT_TEST_FUNCTION_DEVICE_IS_PROFILE_CONNECTED}, + {"bt_device_set_bond_created_cb" , BT_UNIT_TEST_FUNCTION_DEVICE_SET_BOND_CREATED_CB}, + {"bt_device_set_bond_destroyed_cb" , BT_UNIT_TEST_FUNCTION_DEVICE_SET_BOND_DESTROYED_CB}, + {"bt_device_create_bond" , BT_UNIT_TEST_FUNCTION_DEVICE_CREATE_BOND}, + {"bt_device_create_bond_by_type" , BT_UNIT_TEST_FUNCTION_DEVICE_CREATE_BOND_BY_TYPE}, + {"bt_device_destroy_bond" , BT_UNIT_TEST_FUNCTION_DEVICE_DESTROY_BOND}, + {"Select this menu to set parameters and then select the function again." , BT_UNIT_TEST_FUNCTION_ACTIVATE_FLAG_TO_SET_PARAMETERS}, + {NULL , 0x0000}, +}; + +tc_table_t tc_socket[] = { + /* Socket functions */ + {"BACK" , BT_UNIT_TEST_FUNCTION_BACK}, + {"bt_socket_create_rfcomm" , BT_UNIT_TEST_FUNCTION_SOCKET_CREATE_RFCOMM}, + {"bt_socket_destroy_rfcomm" , BT_UNIT_TEST_FUNCTION_SOCKET_DESTROY_RFCOMM}, + {"bt_socket_listen_and_accept_rfcomm" , BT_UNIT_TEST_FUNCTION_SOCKET_LISTEN_AND_ACCEPT_RFCOMM}, + {"bt_socket_listen" , BT_UNIT_TEST_FUNCTION_SOCKET_LISTEN}, + {"bt_socket_accept" , BT_UNIT_TEST_FUNCTION_SOCKET_ACCEPT}, + {"bt_socket_reject" , BT_UNIT_TEST_FUNCTION_SOCKET_REJECT}, + {"bt_socket_connect_rfcomm" , BT_UNIT_TEST_FUNCTION_SOCKET_CONNECT_RFCOMM}, + {"bt_socket_disconnect_rfcomm" , BT_UNIT_TEST_FUNCTION_SOCKET_DISCONNECT_RFCOMM}, + {"bt_socket_send_data" , BT_UNIT_TEST_FUNCTION_SOCKET_SEND_DATA}, + {"bt_socket_create_rfcomm with custom uuid" , BT_UNIT_TEST_FUNCTION_SOCKET_CREATE_RFCOMM_CUSTOM_UUID}, + {"bt_socket_destroy_rfcomm with custom uuid" , BT_UNIT_TEST_FUNCTION_SOCKET_DESTROY_RFCOMM_CUSTOM_UUID}, + {"bt_socket_listen_and_accept_rfcomm with custom uuid" , BT_UNIT_TEST_FUNCTION_SOCKET_LISTEN_AND_ACCEPT_RFCOMM_CUSTOM_UUID}, + {"bt_socket_connect_rfcomm with custom uuid" , BT_UNIT_TEST_FUNCTION_SOCKET_CONNECT_RFCOMM_CUSTOM_UUID}, + {"bt_socket_disconnect_rfcomm with custom uuid" , BT_UNIT_TEST_FUNCTION_SOCKET_DISCONNECT_RFCOMM_CUSTOM_UUID}, + {"bt_socket_send_data with custom uuid" , BT_UNIT_TEST_FUNCTION_SOCKET_SEND_DATA_CUSTOM_UUID}, + {"bt_socket_set_data_received_cb" , BT_UNIT_TEST_FUNCTION_SOCKET_SET_DATA_RECEIVED_CB}, + {"bt_socket_unset_data_received_cb" , BT_UNIT_TEST_FUNCTION_SOCKET_UNSET_DATA_RECEIVED_CB}, + {"bt_socket_set_connection_requested_cb" , BT_UNIT_TEST_FUNCTION_SOCKET_SET_CONNECTION_REQUESTED_CB}, + {"bt_socket_unset_connection_requested_cb" , BT_UNIT_TEST_FUNCTION_SOCKET_UNSET_CONNECTION_REQUESTED_CB}, + {"bt_socket_set_connection_state_changed_cb" , BT_UNIT_TEST_FUNCTION_SOCKET_SET_CONNECTION_STATE_CHANGED_CB}, + {"bt_socket_unset_connection_state_changed_cb" , BT_UNIT_TEST_FUNCTION_SOCKET_UNSET_CONNECTION_STATE_CHANGED_CB}, + {"Select this menu to set parameters and then select the function again." , BT_UNIT_TEST_FUNCTION_ACTIVATE_FLAG_TO_SET_PARAMETERS}, + {NULL , 0x0000}, +}; + +tc_table_t tc_opp[] = { + /* OPP functions */ + {"BACK" , BT_UNIT_TEST_FUNCTION_BACK}, + {"bt_opp_client_initialize" , BT_UNIT_TEST_FUNCTION_OPP_CLIENT_INITIALIZE}, + {"bt_opp_client_deinitialize" , BT_UNIT_TEST_FUNCTION_OPP_CLIENT_DEINITIALIZE}, + {"bt_opp_client_add_file" , BT_UNIT_TEST_FUNCTION_OPP_CLIENT_ADD_FILE}, + {"bt_opp_client_clear_files" , BT_UNIT_TEST_FUNCTION_OPP_CLIENT_CLEAR_FILES}, + {"bt_opp_client_push_files" , BT_UNIT_TEST_FUNCTION_OPP_CLIENT_PUSH_FILES}, + {"bt_opp_client_cancel_push" , BT_UNIT_TEST_FUNCTION_OPP_CLIENT_CANCEL_PUSH}, + {"Select this menu to set parameters and then select the function again." , BT_UNIT_TEST_FUNCTION_ACTIVATE_FLAG_TO_SET_PARAMETERS}, + {NULL , 0x0000}, +}; + +tc_table_t tc_audio[] = { + /* AG functions */ + {"BACK" , BT_UNIT_TEST_FUNCTION_BACK}, + {"bt_audio_initialize" , BT_UNIT_TEST_FUNCTION_AUDIO_INITIALIZE}, + {"bt_audio_deinitialize" , BT_UNIT_TEST_FUNCTION_AUDIO_DEINITIALIZE}, + {"bt_audio_connect" , BT_UNIT_TEST_FUNCTION_AUDIO_CONNECT}, + {"bt_audio_disconnect" , BT_UNIT_TEST_FUNCTION_AUDIO_DISCONNECT}, + {"bt_audio_source_connect" , BT_UNIT_TEST_FUNCTION_AUDIO_SOURCE_CONNECT}, + {"bt_audio_source_disconnect" , BT_UNIT_TEST_FUNCTION_AUDIO_SOURCE_DISCONNECT}, + {"bt_audio_set_connection_state_changed_cb" , BT_UNIT_TEST_FUNCTION_AUDIO_SET_CONNECTION_STATE_CHANGED_CB}, + {"bt_audio_unset_connection_state_changed_cb" , BT_UNIT_TEST_FUNCTION_AUDIO_UNSET_CONNECTION_STATE_CHANGED_CB}, + {"bt_a2dp_source_audio_set_connection_state_cb", BT_UNIT_TEST_FUNCTION_A2DP_AUDIO_SET_CONNECTION_STATE_CB}, + {"bt_a2dp_source_audio_unset_connection_state_cb", BT_UNIT_TEST_FUNCTION_A2DP_AUDIO_UNSET_CONNECTION_STATE_CB}, + {"bt_ag_open_sco" , BT_UNIT_TEST_FUNCTION_AG_OPEN_SCO}, + {"bt_ag_close_sco" , BT_UNIT_TEST_FUNCTION_AG_CLOSE_SCO}, + {"bt_ag_is_sco_opened" , BT_UNIT_TEST_FUNCTION_AG_IS_SCO_OPENED}, + {"bt_ag_set_sco_state_changed_cb" , BT_UNIT_TEST_FUNCTION_AG_SET_SCO_STATE_CHANGED_CB}, + {"bt_ag_unset_sco_state_changed_cb" , BT_UNIT_TEST_FUNCTION_AG_UNSET_SCO_STATE_CHANGED_CB}, + {"bt_ag_is_connected" , BT_UNIT_TEST_FUNCTION_AG_IS_CONNECTED}, + {"BT_AG_CALL_EVENT_IDLE" , BT_UNIT_TEST_FUNCTION_AG_CALL_EVENT_IDLE}, + {"BT_AG_CALL_EVENT_ANSWERED" , BT_UNIT_TEST_FUNCTION_AG_CALL_EVENT_ANSWERED}, + {"BT_AG_CALL_EVENT_DIALING" , BT_UNIT_TEST_FUNCTION_AG_CALL_EVENT_DIALING}, + {"BT_AG_CALL_EVENT_ALERTING" , BT_UNIT_TEST_FUNCTION_AG_CALL_EVENT_ALERTING}, + {"BT_AG_CALL_EVENT_INCOMING" , BT_UNIT_TEST_FUNCTION_AG_CALL_EVENT_INCOMING}, + {"bt_call_list_create" , BT_UNIT_TEST_FUNCTION_CALL_LIST_CREATE}, + {"bt_call_list_destroy" , BT_UNIT_TEST_FUNCTION_CALL_LIST_DESTROY}, + {"bt_call_list_reset" , BT_UNIT_TEST_FUNCTION_CALL_LIST_RESET}, + {"bt_call_list_add" , BT_UNIT_TEST_FUNCTION_CALL_LIST_ADD}, + {"bt_ag_notify_call_list" , BT_UNIT_TEST_FUNCTION_AG_NOTIFY_CALL_LIST}, + {"bt_ag_set_call_handling_event_cb" , BT_UNIT_TEST_FUNCTION_AG_SET_CALL_HANDLING_EVENT_CB}, + {"bt_ag_is_nrec_enabled" , BT_UNIT_TEST_FUNCTION_AG_IS_NREC_ENABLED}, + + /* A2DP SCMS-T functions */ + {"Select this menu to set parameters and then select the function again." , BT_UNIT_TEST_FUNCTION_ACTIVATE_FLAG_TO_SET_PARAMETERS}, + {NULL , 0x0000}, +}; + +tc_table_t tc_pan[] = { + /* Network functions */ + {"BACK" , BT_UNIT_TEST_FUNCTION_BACK}, + {"bt_nap_activate" , BT_UNIT_TEST_FUNCTION_NAP_ACTIVATE}, + {"bt_nap_deactivate" , BT_UNIT_TEST_FUNCTION_NAP_DEACTIVATE}, + {"bt_nap_disconnect_all" , BT_UNIT_TEST_FUNCTION_NAP_DISCONNECT_ALL}, + {"bt_nap_disconnect" , BT_UNIT_TEST_FUNCTION_NAP_DISCONNECT}, + {"bt_panu_set_connection_state_changed_cb" , BT_UNIT_TEST_FUNCTION_PANU_SET_CONNECTION_STATE_CHANGED_CB}, + {"bt_panu_connect" , BT_UNIT_TEST_FUNCTION_PANU_CONNECT}, + {"Select this menu to set parameters and then select the function again." , BT_UNIT_TEST_FUNCTION_ACTIVATE_FLAG_TO_SET_PARAMETERS}, + {NULL , 0x0000}, +}; + +tc_table_t tc_gatt[] = { + /* Gatt functions */ + {"BACK" , BT_UNIT_TEST_FUNCTION_BACK}, + {"bt_gatt_connect" , BT_UNIT_TEST_FUNCTION_GATT_CONNECT}, + {"bt_gatt_disconnect" , BT_UNIT_TEST_FUNCTION_GATT_DISCONNECT}, + {"bt_gatt_set_connection_state_changed_cb" , BT_UNIT_TEST_FUNCTION_SET_GATT_CONNECTION_STATE_CHANGED_CB}, + {"bt_gatt_unset_connection_state_changed_cb" , BT_UNIT_TEST_FUNCTION_UNSET_GATT_CONNECTION_STATE_CHANGED_CB}, + {"bt_gatt_client_create" , BT_UNIT_TEST_FUNCTION_GATT_CLIENT_CREATE}, + {"bt_gatt_client_destroy" , BT_UNIT_TEST_FUNCTION_GATT_CLIENT_DESTROY}, + {"bt_gatt_client_get_remote_address" , BT_UNIT_TEST_FUNCTION_GATT_CLIENT_GET_REMOTE_ADDRESS}, + {"bt_gatt_client_print_all" , BT_UNIT_TEST_FUNCTION_GATT_CLIENT_PRINT_ALL}, + {"bt_gatt_client_read_value" , BT_UNIT_TEST_FUNCTION_GATT_CLIENT_READ_VALUE}, + {"bt_gatt_client_write_value" , BT_UNIT_TEST_FUNCTION_GATT_CLIENT_WRITE_VALUE}, + {"bt_gatt_client_set_char_value_changed_cb" , BT_UNIT_TEST_FUNCTION_GATT_CLIENT_SET_CHAR_VALUE_CHANGED_CB}, + {"bt_gatt_client_unset_char_value_changed_cb" , BT_UNIT_TEST_FUNCTION_GATT_CLIENT_UNSET_CHAR_VALUE_CHANGED_CB}, + {"bt_gatt_client_foreach_services" , BT_UNIT_TEST_FUNCTION_GATT_CLIENT_FOREACH_SERVICES}, + {"bt_gatt_server_initialize" , BT_UNIT_TEST_FUNCTION_GATT_SERVER_INITIALIZE}, + {"bt_gatt_server_deinitilaize" , BT_UNIT_TEST_FUNCTION_GATT_SERVER_DEINITIALIZE}, + {"bt_gatt_server_unregister_all_services" , BT_UNIT_TEST_FUNCTION_GATT_SERVER_UNREGISTER_ALL_SERVICES}, + {"Register Battery Service" , BT_UNIT_TEST_FUNCTION_GATT_SERVER_REGISTER_BATTERY_SVC}, + {"Change Battery Level" , BT_UNIT_TEST_FUNCTION_GATT_SERVER_CHANGE_BATTERY_LEVEL}, + {"Register Heart Rate Service" , BT_UNIT_TEST_FUNCTION_GATT_SERVER_REGISTER_HEART_RATE_SVC}, + {"Notify Heart Rate Measurement" , BT_UNIT_TEST_FUNCTION_GATT_SERVER_NOTIFY_HEART_RATE_MEASUREMENT}, + {"Register Thermometer Service" , BT_UNIT_TEST_FUNCTION_GATT_SERVER_REGISTER_THERMOMETER_SVC}, + {"Change Thermometer Measurement" , BT_UNIT_TEST_FUNCTION_GATT_SERVER_CHANGE_THERMOMETER_MEASUREMENT}, + {"Register Device Information Service" , BT_UNIT_TEST_FUNCTION_GATT_SERVER_REGISTER_DEVICE_INFORMATION_SVC}, + {"Register Link Loss Service" , BT_UNIT_TEST_FUNCTION_GATT_SERVER_REGISTER_LINK_LOSS_SVC}, + {"Register Custom Service" , BT_UNIT_TEST_FUNCTION_GATT_SERVER_REGISTER_CUSTOM_SVC}, + {"Change Custom Value" , BT_UNIT_TEST_FUNCTION_GATT_SERVER_CHANGE_CUSTOM_VAL}, + {"ANCS (Pair)" , BT_UNIT_TEST_FUNCTION_ANCS_PAIR}, + {"ANCS (Watch notification)" , BT_UNIT_TEST_FUNCTION_ANCS_WATCH}, + {"ANCS (Positive action)" , BT_UNIT_TEST_FUNCTION_ANCS_POSITIVE_ACTION}, + {"ANCS (Negative action)" , BT_UNIT_TEST_FUNCTION_ANCS_NEGATIVE_ACTION}, + {"ANCS (Get Noti. Attr.)" , BT_UNIT_TEST_FUNCTION_ANCS_GET_NOTI_ATTR}, +#ifdef BT_ENABLE_LEGACY_GATT_CLIENT + {"bt_gatt_foreach_primary_services" , BT_UNIT_TEST_FUNCTION_GATT_FOREACH_PRIMARY_SERVICES}, + {"bt_gatt_discover_characteristics" , BT_UNIT_TEST_FUNCTION_GATT_DISCOVER_CHARACTERISTICS}, + {"bt_gatt_discover_characteristic_descriptor" , BT_UNIT_TEST_FUNCTION_GATT_DISCOVER_CHARACTERISTIC_DESCRIPTORS}, + {"bt_gatt_get_service_uuid" , BT_UNIT_TEST_FUNCTION_GATT_GET_SERVICE_UUID}, + {"bt_gatt_foreach_included_services" , BT_UNIT_TEST_FUNCTION_GATT_FOREACH_INCLUDED_SERVICES}, + {"bt_gatt_set_characteristic_changed_cb" , BT_UNIT_TEST_FUNCTION_GATT_SET_CHARACTERISTIC_CHANGED_CB}, + {"bt_gatt_unset_characteristic_changed_cb" , BT_UNIT_TEST_FUNCTION_GATT_UNSET_CHARACTERISTIC_CHANGED_CB}, + {"bt_gatt_get_characteristic_declaration" , BT_UNIT_TEST_FUNCTION_GATT_GET_CHARACTERISTIC_DECLARATION}, + {"bt_gatt_set_characteristic_value" , BT_UNIT_TEST_FUNCTION_GATT_SET_CHARACTERISTIC_VALUE}, + {"bt_gatt_set_characteristic_value_request" , BT_UNIT_TEST_FUNCTION_GATT_SET_CHARACTERISTIC_VALUE_REQUEST}, + {"bt_gatt_read_characteristic_value" , BT_UNIT_TEST_FUNCTION_GATT_READ_CHARACTERISTIC_VALUE}, + {"bt_gatt_watch_characteristic_changes" , BT_UNIT_TEST_FUNCTION_GATT_WATCH_CHARACTERISTIC_CHANGES}, + {"bt_gatt_unwatch_characteristic_changes" , BT_UNIT_TEST_FUNCTION_GATT_UNWATCH_CHARACTERISTIC_CHANGES}, +#endif + {"Select this menu to set parameters and then select the function again." , BT_UNIT_TEST_FUNCTION_ACTIVATE_FLAG_TO_SET_PARAMETERS}, + {NULL , 0x0000}, +}; + +tc_table_t tc_avrcp[] = { + /* AVRCP functions */ + {"BACK" , BT_UNIT_TEST_FUNCTION_BACK}, + {"bt_avrcp_target_initialize" , BT_UNIT_TEST_FUNCTION_AVRCP_TARGET_INITIALIZE}, + {"bt_avrcp_target_deinitialize" , BT_UNIT_TEST_FUNCTION_AVRCP_TARGET_DEINITIALIZE}, + {"bt_avrcp_set_equalizer_state_changed_cb" , BT_UNIT_TEST_FUNCTION_AVRCP_SET_EQUALIZER_STATE_CHANGED_CB}, + {"bt_avrcp_set_repeat_mode_changed_cb" , BT_UNIT_TEST_FUNCTION_AVRCP_SET_REPEAT_MODE_CHANGED_CB}, + {"bt_avrcp_set_shuffle_mode_changed_cb" , BT_UNIT_TEST_FUNCTION_AVRCP_SET_SHUFFLE_MODE_CHANGED_CB}, + {"bt_avrcp_set_scan_mode_changed_cb" , BT_UNIT_TEST_FUNCTION_AVRCP_SET_SCAN_MODE_CHANGED_CB}, + {"bt_avrcp_unset_equalizer_state_changed_cb" , BT_UNIT_TEST_FUNCTION_AVRCP_UNSET_EQUALIZER_STATE_CHANGED_CB}, + {"bt_avrcp_unset_repeat_mode_changed_cb" , BT_UNIT_TEST_FUNCTION_AVRCP_UNSET_REPEAT_MODE_CHANGED_CB}, + {"bt_avrcp_unset_shuffle_mode_changed_cb" , BT_UNIT_TEST_FUNCTION_AVRCP_UNSET_SHUFFLE_MODE_CHANGED_CB}, + {"bt_avrcp_unset_scan_mode_changed_cb" , BT_UNIT_TEST_FUNCTION_AVRCP_UNSET_SCAN_MODE_CHANGED_CB}, + {"bt_avrcp_control_initialize" , BT_UNIT_TEST_FUNCTION_AVRCP_CONTROL_INITIALIZE}, + {"bt_avrcp_control_deinitialize" , BT_UNIT_TEST_FUNCTION_AVRCP_CONTROL_DEINITIALIZE}, + {"bt_avrcp_control_connect" , BT_UNIT_TEST_FUNCTION_AVRCP_CONTROL_CONNECT}, + {"bt_avrcp_control_disconnect" , BT_UNIT_TEST_FUNCTION_AVRCP_CONTROL_DISCONNECT}, + {"bt_avrcp_control_player_PLAY" , BT_UNIT_TEST_FUNCTION_AVRCP_CONTROL_PLAY}, + {"bt_avrcp_control_player_STOP" , BT_UNIT_TEST_FUNCTION_AVRCP_CONTROL_STOP}, + {"bt_avrcp_control_player_PAUSE" , BT_UNIT_TEST_FUNCTION_AVRCP_CONTROL_PAUSE}, + {"bt_avrcp_control_player_FF" , BT_UNIT_TEST_FUNCTION_AVRCP_CONTROL_FF}, + {"bt_avrcp_control_player_RW" , BT_UNIT_TEST_FUNCTION_AVRCP_CONTROL_RW}, + {"bt_avrcp_control_player_NEXT" , BT_UNIT_TEST_FUNCTION_AVRCP_CONTROL_NEXT}, + {"bt_avrcp_control_player_PREV" , BT_UNIT_TEST_FUNCTION_AVRCP_CONTROL_PREV}, + {"bt_avrcp_control_player_GET_REPEAT" , BT_UNIT_TEST_FUNCTION_AVRCP_CONTROL_GET_REPEAT}, + {"bt_avrcp_control_player_SET_REPEAT" , BT_UNIT_TEST_FUNCTION_AVRCP_CONTROL_SET_REPEAT}, + {"bt_avrcp_control_player_GET_SHUFFLE" , BT_UNIT_TEST_FUNCTION_AVRCP_CONTROL_GET_SHUFFLE}, + {"bt_avrcp_control_player_SET_SHUFFLE" , BT_UNIT_TEST_FUNCTION_AVRCP_CONTROL_SET_SHUFFLE}, + {"bt_avrcp_control_player_GET_POSITION" , BT_UNIT_TEST_FUNCTION_AVRCP_CONTROL_GET_POSITION}, + {"bt_avrcp_control_player_GET_PLAY STATUS" , BT_UNIT_TEST_FUNCTION_AVRCP_CONTROL_GET_PLAY_STATUS}, + {"bt_avrcp_control_player_GET_TRACK_INFO" ,BT_UNIT_TEST_FUNCTION_AVRCP_CONTROL_GET_TRACK_INFO}, + {"bt_avrcp_set_song_position_changed_cb" , BT_UNIT_TEST_FUNCTION_AVRCP_SET_SONG_POSITION_CHANGED_CB}, + {"bt_avrcp_set_play_status_changed_cb" , BT_UNIT_TEST_FUNCTION_AVRCP_SET_PLAY_STATE_CHANGED_CB}, + {"bt_avrcp_set_track_info_changed_cb" , BT_UNIT_TEST_FUNCTION_AVRCP_SET_TRACK_INFO_CHANGED_CB}, + {"bt_avrcp_unset_song_position_changed_cb" , BT_UNIT_TEST_FUNCTION_AVRCP_UNSET_SONG_POSITION_CHANGED_CB}, + {"bt_avrcp_unset_play_status_changed_cb" , BT_UNIT_TEST_FUNCTION_AVRCP_UNSET_PLAY_STATE_CHANGED_CB}, + {"bt_avrcp_unset_track_info_changed_cb" , BT_UNIT_TEST_FUNCTION_AVRCP_UNSET_TRACK_INFO_CHANGED_CB}, + {"Select this menu to set parameters and then select the function again." , BT_UNIT_TEST_FUNCTION_ACTIVATE_FLAG_TO_SET_PARAMETERS}, + {NULL , 0x0000}, +}; + +tc_table_t tc_hid[] = { + /* HID functions */ + {"BACK" , BT_UNIT_TEST_FUNCTION_BACK}, + {"bt_hid_host_initialize" , BT_UNIT_TEST_FUNCTION_HID_HOST_INITIALIZE}, + {"bt_hid_host_deinitialize" , BT_UNIT_TEST_FUNCTION_HID_HOST_DEINITIALIZE}, + {"bt_hid_host_connect" , BT_UNIT_TEST_FUNCTION_HID_HOST_CONNECT}, + {"bt_hid_host_disconnect" , BT_UNIT_TEST_FUNCTION_HID_HOST_DISCONNECT}, + {"Select this menu to set parameters and then select the function again." , BT_UNIT_TEST_FUNCTION_ACTIVATE_FLAG_TO_SET_PARAMETERS}, + {NULL , 0x0000}, +}; + +#ifdef TIZEN_WEARABLE +tc_table_t tc_hf[] = { + /* Handsfree role functions */ + {"BACK" , BT_UNIT_TEST_FUNCTION_BACK}, + {"bt_hf_initialize" , BT_UNIT_TEST_FUNCTION_HF_INITIALIZE}, + {"bt_hf_deinitialize" , BT_UNIT_TEST_FUNCTION_HF_DEINITIALIZE}, + {"(CALL Handling) bt_hf_notify_call_event(answer)" , BT_UNIT_TEST_FUNCTION_HF_NOTIFY_CALL_ANSWER}, + {"(CALL Handling) bt_hf_notify_call_event(initiate)" , BT_UNIT_TEST_FUNCTION_HF_NOTIFY_CALL_INIT}, + {"(CALL Handling) bt_hf_notify_call_event(terminate)" , BT_UNIT_TEST_FUNCTION_HF_NOTIFY_CALL_TERM}, + {"(CALL Status) bt_hf_get_call_status_info_list" , BT_UNIT_TEST_FUNCTION_HF_GET_CALL_STATUS_INFO_LIST}, + {"(CALL Status) bt_hf_set_call_handling_event_cb()" , BT_UNIT_TEST_FUNCTION_HF_SET_CALL_EVENT_CB}, + {"(CALL Status) bt_hf_unset_call_handling_event_cb" , BT_UNIT_TEST_FUNCTION_HF_UNSET_CALL_EVENT_CB}, + {"(CALL Status) bt_hf_set_call_status_updated_event_cb" , BT_UNIT_TEST_FUNCTION_HF_SET_CALL_STATUS_UPDATED_EVENT_CB}, + {"(CALL Status) bt_hf_unset_call_status_updated_event_cb" , BT_UNIT_TEST_FUNCTION_HF_UNSET_CALL_STATUS_UPDATED_EVENT_CB}, + {"(Volume) bt_hf_notify_speaker_gain" , BT_UNIT_TEST_FUNCTION_HF_NOTIFY_SPEAKER_GAIN}, + {"(Volume) bt_hf_set_speaker_gain_changed_cb" , BT_UNIT_TEST_FUNCTION_HF_SET_SPEAKER_GAIN_CB}, + {"(Volume) bt_hf_unset_speaker_gain_changed_cb" , BT_UNIT_TEST_FUNCTION_HF_UNSET_SPEAKER_GAIN_CB}, + {"(Voice-recog) bt_hf_notify_voice_recognition_state(true)" , BT_UNIT_TEST_FUNCTION_HF_NOTIFY_VOICE_REC_TRUE}, + {"(Voice-recog) bt_hf_notify_voice_recognition_state(false)" , BT_UNIT_TEST_FUNCTION_HF_NOTIFY_VOICE_REC_FALSE}, + {"(SCO) bt_hf_is_sco_opened" , BT_UNIT_TEST_FUNCTION_HF_IS_SCO_OPENED}, + {"(SCO) bt_hf_get_codec_id" , BT_UNIT_TEST_FUNCTION_HF_GET_CODEC_ID}, + {"(SCO) bt_hf_set_sco_state_changed_cb()" , BT_UNIT_TEST_FUNCTION_HF_SET_SCO_CHANGED_CB}, + {"(SCO) bt_hf_unset_sco_state_changed_cb()" , BT_UNIT_TEST_FUNCTION_HF_UNSET_SCO_CHANGED_CB}, + {"Select this menu to set parameters and then select the function again." , BT_UNIT_TEST_FUNCTION_ACTIVATE_FLAG_TO_SET_PARAMETERS}, + {NULL , 0x0000}, +}; + +tc_table_t tc_pbap_client[] = { + /* PBAP Functions*/ + {"BACK" , BT_UNIT_TEST_FUNCTION_BACK}, + {"bt_pbap_init()", BT_UNIT_TEST_FUNCTION_PBAP_CLIENT_INITIALIZE}, + {"bt_pbap_deinit()", BT_UNIT_TEST_FUNCTION_PBAP_CLIENT_DEINITIALIZE}, + {"bt_pbap_connect()", BT_UNIT_TEST_FUNCTION_PBAP_CLIENT_CONNECT}, + {"bt_pbap_disconnect()", BT_UNIT_TEST_FUNCTION_PBAP_CLIENT_DISCONNECT}, + {"bt_pbap_get_phonebook_size()", BT_UNIT_TEST_FUNCTION_PBAP_CLIENT_GETSIZE}, + {"bt_pbap_get_phonebook()", BT_UNIT_TEST_FUNCTION_PBAP_CLIENT_PHONEBOOKPULL}, + {"bt_pbap_get_list()", BT_UNIT_TEST_FUNCTION_PBAP_CLIENT_VCARDLIST}, + {"bt_pbap_pull_vcard()", BT_UNIT_TEST_FUNCTION_PBAP_CLIENT_VCARDPULL}, + {"bt_pbap_phonebook_search()", BT_UNIT_TEST_FUNCTION_PBAP_CLIENT_PHONEBOOKSEARCH}, + {"bt_pbap_get_list() Maxlist=0", BT_UNIT_TEST_FUNCTION_PBAP_CLIENT_VCARDLIST_MAXLIST_ZERO}, + + {"Select this menu to set parameters and then select the function again." , BT_UNIT_TEST_FUNCTION_ACTIVATE_FLAG_TO_SET_PARAMETERS}, + {NULL , 0x0000}, +}; +#endif + +tc_table_t tc_automated_test[] = { + /* Automated test Functions*/ + {"BACK" , BT_UNIT_TEST_FUNCTION_BACK}, + {"On/Off repeat test()" , BT_UNIT_TEST_FUNCTION_ON_OFF_REPEAT_TEST}, + {"On/Off repeat(1sec delay) test()" , BT_UNIT_TEST_FUNCTION_ON_OFF_REPEAT_TEST_1_SEC_DELAY}, + {"On/Off repeat(Nsec delay) test()" , BT_UNIT_TEST_FUNCTION_ON_OFF_REPEAT_TEST_N_SEC_DELAY}, + {NULL , 0x0000}, +}; + +static void __bt_initialize_all(void); + +void __bt_gatt_client_value_changed_cb(bt_gatt_h chr, char *value, int len, + void *user_data); + +void tc_usage_print(void) +{ + int i = 0; + tc_table_t* tc_table = NULL; + + switch (current_tc_table) { + case BT_UNIT_TEST_TABLE_SET_ADDRESS: + TC_PRT("Key 0 : usage BACK"); + TC_PRT("Input the address of remote device.(e.g., F6:FB:8F:D8:C8:7C)\n\n"); + return; + case BT_UNIT_TEST_TABLE_ADAPTER: + tc_table = tc_adapter; + break; + case BT_UNIT_TEST_TABLE_ADAPTER_LE: + tc_table = tc_adapter_le; + break; + case BT_UNIT_TEST_TABLE_DEVICE: + tc_table = tc_device; + break; + case BT_UNIT_TEST_TABLE_SOCKET: + tc_table = tc_socket; + break; + case BT_UNIT_TEST_TABLE_OPP: + tc_table = tc_opp; + break; + case BT_UNIT_TEST_TABLE_AUDIO: + tc_table = tc_audio; + break; + case BT_UNIT_TEST_TABLE_PAN: + tc_table = tc_pan; + break; + case BT_UNIT_TEST_TABLE_GATT: + tc_table = tc_gatt; + break; + case BT_UNIT_TEST_TABLE_AVRCP: + tc_table = tc_avrcp; + break; + case BT_UNIT_TEST_TABLE_HID: + tc_table = tc_hid; + break; +#ifdef TIZEN_WEARABLE + case BT_UNIT_TEST_TABLE_HF: + tc_table = tc_hf; + break; + case BT_UNIT_TEST_TABLE_PBAP_CLIENT: + tc_table = tc_pbap_client; + break; +#endif + case BT_UNIT_TEST_TABLE_AUTOMATED_TEST: + if (input_automated_test_delay == true) { + TC_PRT("Input the delay for automated test.(e.g., 10)\n\n"); + return; + } + tc_table = tc_automated_test; + break; + case BT_UNIT_TEST_FUNCTION_INITIALIZE_ALL: + __bt_initialize_all(); + TC_PRT("Key 0 : usage BACK"); + return; + case BT_UNIT_TEST_TABLE_MAIN: + default: + tc_table = tc_main; + break; + } + + while (tc_table[i].tc_name) { + TC_PRT("Key %d : usage %s", tc_table[i].tc_code, + tc_table[i].tc_name); + i++; + } + printf("\n\n"); +} + +static void __bt_free_test_param(tc_params_t *param) +{ + int i = 0; + + for (i = 0; i < param->param_count; i++) + g_free(param->params[i]); + g_free(param->params); + param->params = NULL; + param->param_count = 0; +} + +static const char* __bt_get_error_message(bt_error_e err) +{ + const char* err_str = NULL; + + switch (err) { + case BT_ERROR_NONE: + err_str = "BT_ERROR_NONE"; + break; + case BT_ERROR_CANCELLED: + err_str = "BT_ERROR_CANCELLED"; + break; + case BT_ERROR_INVALID_PARAMETER: + err_str = "BT_ERROR_INVALID_PARAMETER"; + break; + case BT_ERROR_OUT_OF_MEMORY: + err_str = "BT_ERROR_OUT_OF_MEMORY"; + break; + case BT_ERROR_RESOURCE_BUSY: + err_str = "BT_ERROR_RESOURCE_BUSY"; + break; + case BT_ERROR_TIMED_OUT: + err_str = "BT_ERROR_TIMED_OUT"; + break; + case BT_ERROR_NOW_IN_PROGRESS: + err_str = "BT_ERROR_NOW_IN_PROGRESS"; + break; + case BT_ERROR_NOT_INITIALIZED: + err_str = "BT_ERROR_NOT_INITIALIZED"; + break; + case BT_ERROR_NOT_ENABLED: + err_str = "BT_ERROR_NOT_ENABLED"; + break; + case BT_ERROR_ALREADY_DONE: + err_str = "BT_ERROR_ALREADY_DONE"; + break; + case BT_ERROR_OPERATION_FAILED: + err_str = "BT_ERROR_OPERATION_FAILED"; + break; + case BT_ERROR_NOT_IN_PROGRESS: + err_str = "BT_ERROR_NOT_IN_PROGRESS"; + break; + case BT_ERROR_REMOTE_DEVICE_NOT_BONDED: + err_str = "BT_ERROR_REMOTE_DEVICE_NOT_BONDED"; + break; + case BT_ERROR_AUTH_REJECTED: + err_str = "BT_ERROR_AUTH_REJECTED"; + break; + case BT_ERROR_AUTH_FAILED: + err_str = "BT_ERROR_AUTH_FAILED"; + break; + case BT_ERROR_REMOTE_DEVICE_NOT_FOUND: + err_str = "BT_ERROR_REMOTE_DEVICE_NOT_FOUND"; + break; + case BT_ERROR_SERVICE_SEARCH_FAILED: + err_str = "BT_ERROR_SERVICE_SEARCH_FAILED"; + break; + case BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED: + err_str = "BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED"; + break; + case BT_ERROR_PERMISSION_DENIED: + err_str = "BT_ERROR_PERMISSION_DENIED"; + break; + case BT_ERROR_SERVICE_NOT_FOUND: + err_str = "BT_ERROR_SERVICE_NOT_FOUND"; + break; + case BT_ERROR_NOT_SUPPORTED: + err_str = "BT_ERROR_NOT_SUPPORTED"; + break; + default: + err_str = "NOT Defined"; + break; + } + + return err_str; +} + +#ifdef BT_ENABLE_LEGACY_GATT_CLIENT +static gboolean __select_index_cb(GIOChannel *chan, + GIOCondition cond, + gpointer data) +{ + char buf[BUFFER_LEN] = { 0 }; + unsigned int len = 0; + int *index = data; + + memset(buf, 0, sizeof(buf)); + + if (g_io_channel_read_chars(chan, buf, sizeof(buf), + &len, NULL) == G_IO_STATUS_ERROR) { + TC_PRT("IO Channel read error"); + is_sub_index = FALSE; + return FALSE; + } + + *index = atoi(buf); + is_sub_index = FALSE; + + return FALSE; +} + +static void __select_index(void *data, const char *str) +{ + GIOChannel *key_io; + + is_sub_index = TRUE; + + if (str) + TC_PRT("%s ", str); + + key_io = g_io_channel_unix_new(fileno(stdin)); + + g_io_channel_set_encoding(key_io, NULL, NULL); + g_io_channel_set_flags(key_io, G_IO_FLAG_NONBLOCK, NULL); + + g_io_add_watch(key_io, G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL, + __select_index_cb, data); + + g_io_channel_unref(key_io); +} + +static void __bt_free_gatt_services(void) +{ + int i; + + for (i = 0; i < service_index; i++) { + bt_gatt_destroy_attribute_handle(service_clone[i]); + service_clone[i] = NULL; + } + + service_index = 0; +} + +static void __bt_free_gatt_characteristics(void) +{ + int i; + + for (i = 0; i < MAX_SERVICES; i++) { + if (characteristics[i] == NULL) + return; + + bt_gatt_destroy_attribute_handle(characteristics[i]); + characteristics[i] = NULL; + } +} + +static void __bt_free_gatt_characteristics_services(void) +{ + int i; + + for (i = 0; i < char_service_index; i++) { + bt_gatt_destroy_attribute_handle(characteristics_services[i]); + characteristics_services[i] = NULL; + } + char_service_index = 0; +} +#endif + +void __bt_adapter_state_changed_cb(int result, bt_adapter_state_e adapter_state, void *user_data) +{ + TC_PRT("__bt_adapter_state_changed_cb"); + TC_PRT("result: %s", __bt_get_error_message(result)); + TC_PRT("state: %s", + (adapter_state == BT_ADAPTER_ENABLED)? + "ENABLED" : "DISABLED"); +} + +static void __bt_adapter_device_visibility_mode_changed_cb(int result, + bt_adapter_visibility_mode_e visibility_mode, + void *user_data) +{ + TC_PRT("result: %s", __bt_get_error_message(result)); + TC_PRT("visibility_mode: %d", visibility_mode); +} + +static void __bt_adapter_device_visibility_duration_changed_cb(int duration, + void *user_data) +{ + TC_PRT("visibility_duration: %d", duration); +} + +static void __bt_adapter_connectable_changed_cb(int result, + bool connectable, void *user_data) +{ + if (result != BT_ERROR_NONE) { + TC_PRT("connectable change is failed : [0x%04x]", result); + return; + } + + TC_PRT("%s", connectable ? "Connectable" : "Non-connectable"); +} + +static void __bt_adapter_manufacturer_data_changed_cb(char *data, + int len, void *user_data) +{ + int i; + + TC_PRT("manufacturer data is changed"); + for (i = 0; i < len; i++) { + TC_PRT("[%d] %02x", i, data[i]); + } +} + +static bool __bt_adapter_bonded_device_cb(bt_device_info_s *device_info, void *user_data) +{ + int i; + + TC_PRT("remote_address: %s", device_info->remote_address); + TC_PRT("remote_name: %s", device_info->remote_name); + TC_PRT("service_count: %d", device_info->service_count); + + if (device_info->service_uuid == NULL) { + TC_PRT("No uuids"); + } else { + for (i = 0; i < device_info->service_count; i++) { + TC_PRT("uuid: %s", device_info->service_uuid[i]); + } + } + + if (device_info->manufacturer_data_len > 0) { + TC_PRT("manufacturer specific data(len:%d)", device_info->manufacturer_data_len); + printf("data ["); + for (i = 0; i < device_info->manufacturer_data_len; i++) + printf("%02x ", device_info->manufacturer_data[i]); + printf("]\n"); + } + + return true; +} + +static void __bt_adapter_device_discovery_state_changed_cb(int result, + bt_adapter_device_discovery_state_e discovery_state, + bt_adapter_device_discovery_info_s *discovery_info, + void *user_data) +{ + int i; + + TC_PRT("discovery_state: %d", discovery_state); + + if (discovery_info == NULL) { + TC_PRT("No discovery_info!"); + return; + } + + TC_PRT("remote_address: %s", discovery_info->remote_address); + TC_PRT("remote_name: %s", discovery_info->remote_name); + TC_PRT("rssi: %d", discovery_info->rssi); + TC_PRT("is_bonded: %d", discovery_info->is_bonded); + TC_PRT("service_count: %d", discovery_info->service_count); + + if (discovery_info->service_uuid == NULL) { + TC_PRT("No uuids"); + } else { + for (i = 0; i < discovery_info->service_count; i++) { + TC_PRT("uuid: %s", discovery_info->service_uuid[i]); + } + } + + if (discovery_info->manufacturer_data_len > 0) { + TC_PRT("manufacturer specific data(len:%d)", discovery_info->manufacturer_data_len); + printf("data ["); + for (i = 0; i < discovery_info->manufacturer_data_len; i++) + printf("%02x ", discovery_info->manufacturer_data[i]); + printf("]\n"); + } +} + +static void __bt_adapter_le_scan_result_cb(int result, + bt_adapter_le_device_scan_result_info_s *info, void *user_data) +{ + int i; + bt_adapter_le_packet_type_e pkt_type = BT_ADAPTER_LE_PACKET_ADVERTISING; + + if (info == NULL) { + TC_PRT("No discovery_info!"); + return; + } + + TC_PRT("%s Adv %d Scan resp %d RSSI %d Addr_type %d", info->remote_address, + info->adv_data_len, info->scan_data_len, info->rssi, + info->address_type); + + if (info->adv_data_len > 31 || info->scan_data_len > 31) { + TC_PRT("###################"); + bt_adapter_le_stop_scan(); + TC_PRT("###################"); + return; + } + + for (i = 0; i < 2; i++) { + char **uuids; + char *device_name; + int tx_power_level; + bt_adapter_le_service_data_s *data_list; + int appearance; + int manufacturer_id; + char *manufacturer_data; + int manufacturer_data_len; + int count; + + pkt_type += i; + if (pkt_type == BT_ADAPTER_LE_PACKET_ADVERTISING && info->adv_data == NULL) continue; + if (pkt_type == BT_ADAPTER_LE_PACKET_SCAN_RESPONSE && info->scan_data == NULL) break; + + if (bt_adapter_le_get_scan_result_service_uuids(info, pkt_type, &uuids, &count) == BT_ERROR_NONE) { + int i; + for (i = 0; i < count; i++) { + TC_PRT("UUID[%d] = %s", i + 1, uuids[i]); + g_free(uuids[i]); + } + g_free(uuids); + } + if (bt_adapter_le_get_scan_result_device_name(info, pkt_type, &device_name) == BT_ERROR_NONE) { + TC_PRT("Device name = %s", device_name); + g_free(device_name); + } + if (bt_adapter_le_get_scan_result_tx_power_level(info, pkt_type, &tx_power_level) == BT_ERROR_NONE) { + TC_PRT("TX Power level = %d", tx_power_level); + } + if (bt_adapter_le_get_scan_result_service_solicitation_uuids(info, pkt_type, &uuids, &count) == BT_ERROR_NONE) { + int i; + for (i = 0; i < count; i++) { + TC_PRT("Solicitation UUID[%d] = %s", i + 1, uuids[i]); + g_free(uuids[i]); + } + g_free(uuids); + } + if (bt_adapter_le_get_scan_result_service_data_list(info, pkt_type, &data_list, &count) == BT_ERROR_NONE) { + int i; + for (i = 0; i < count; i++) + TC_PRT("Service Data[%d] = [0x%2.2X%2.2X:0x%.2X...]", i + 1, data_list[i].service_uuid[0], data_list[i].service_uuid[1], data_list[i].service_data[0]); + bt_adapter_le_free_service_data_list(data_list, count); + } + if (bt_adapter_le_get_scan_result_appearance(info, pkt_type, &appearance) == BT_ERROR_NONE) { + TC_PRT("Appearance = %d", appearance); + } + if (bt_adapter_le_get_scan_result_manufacturer_data(info, pkt_type, &manufacturer_id, &manufacturer_data, &manufacturer_data_len) == BT_ERROR_NONE) { + TC_PRT("Manufacturer data[ID:%.4X, 0x%.2X%.2X...(len:%d)]", manufacturer_id, manufacturer_data[0], manufacturer_data[1], manufacturer_data_len); + g_free(manufacturer_data); + } + } +} + +void __bt_gatt_server_read_value_requested_cb (char *remote_address, + int request_id, bt_gatt_server_h server, bt_gatt_h gatt_handle, + int offset, void *user_data) +{ + char char_value_1[3] = {0, 1, 2}; + + TC_PRT("__bt_gatt_server_read_value_requested_cb"); + TC_PRT("req_id %d", request_id); + TC_PRT("server %s", (char *)server); + TC_PRT("server %s", (char *)gatt_handle); + TC_PRT("Offset %d", offset); + /* Get the attribute new values here */ + bt_gatt_server_send_response(request_id, offset, char_value_1, 3 - offset); +} + +#ifndef TIZEN_WEARABLE +static void __bt_adapter_le_device_discovery_state_changed_cb(int result, + bt_adapter_le_device_discovery_state_e discovery_state, + bt_adapter_le_device_discovery_info_s *discovery_info, + void *user_data) +{ + if (discovery_info == NULL && discovery_state == BT_ADAPTER_LE_DEVICE_DISCOVERY_FOUND) { + TC_PRT("No discovery_info!"); + return; + } + + if (discovery_state != BT_ADAPTER_LE_DEVICE_DISCOVERY_FOUND) { + TC_PRT("LE discovery %s", discovery_state == BT_ADAPTER_LE_DEVICE_DISCOVERY_STARTED? + "Started" : "Finished"); + } else { + TC_PRT("%s Adv %d Scan resp %d RSSI %d Addr_type %d", discovery_info->remote_address, + discovery_info->adv_data_len, discovery_info->scan_data_len, discovery_info->rssi, + discovery_info->address_type); + + if (discovery_info->adv_data_len > 31 || discovery_info->scan_data_len > 31) { + TC_PRT("###################"); + bt_adapter_le_stop_device_discovery(); + TC_PRT("###################"); + return; + } +#if 0 + /* LE ADV information */ + int i, ret; + int field_len = 0; + unsigned char *field_data; + + printf("Adv data ["); + for (i = 0; i < discovery_info->adv_data_len; i++) + printf("%02x ", discovery_info->adv_data[i]); + printf("]\n"); + + printf("Scan resp data ["); + for (i = 0; i < discovery_info->scan_data_len; i++) + printf("%02x ", discovery_info->scan_data[i]); + printf("]\n"); + + ret = bt_adapter_le_get_scan_field_data(discovery_info, BT_ADAPTER_LE_PACKET_ADVERTISING, + BT_ADAPTER_LE_PACKET_DATA_MANUFACTURER_SPECIFIC_DATA, &field_data, &field_len); + if (ret == BT_ERROR_NONE) { + printf("Manufacturer specific data ["); + for (i = 0; i < field_len; i++) + printf("%02x ", field_data[i]); + printf("]\n"); + g_free(field_data); + } + + ret = bt_adapter_le_get_scan_field_data(discovery_info, BT_ADAPTER_LE_PACKET_SCAN_RESPONSE, + BT_ADAPTER_LE_PACKET_DATA_LOCAL_NAME, &field_data, &field_len); + if (ret == BT_ERROR_NONE) { + TC_PRT("%s", field_data); + g_free(field_data); + } +#endif + } +} +#endif + +static void __bt_adapter_le_advertising_state_changed_cb(int result, + bt_advertiser_h advertiser, bt_adapter_le_advertising_state_e adv_state, void *user_data) +{ + TC_PRT("Result : %d", result); + TC_PRT("Advertiser : %p", advertiser); + TC_PRT("Advertising %s [%d]", adv_state == BT_ADAPTER_LE_ADVERTISING_STARTED ? + "started" : "stopped", adv_state); +} + +static void __bt_adapter_le_advertising_state_changed_cb_2(int result, + bt_advertiser_h advertiser, bt_adapter_le_advertising_state_e adv_state, void *user_data) +{ + TC_PRT("Result : %d", result); + TC_PRT("Advertiser : %p", advertiser); + TC_PRT("Advertising %s [%d]", adv_state == BT_ADAPTER_LE_ADVERTISING_STARTED ? + "started" : "stopped", adv_state); +} + +static void __bt_adapter_le_advertising_state_changed_cb_3(int result, + bt_advertiser_h advertiser, bt_adapter_le_advertising_state_e adv_state, void *user_data) +{ + TC_PRT("Result : %d", result); + TC_PRT("Advertiser : %p", advertiser); + TC_PRT("Advertising %s [%d]", adv_state == BT_ADAPTER_LE_ADVERTISING_STARTED ? + "started" : "stopped", adv_state); +} + +static void __bt_socket_data_received_cb(bt_socket_received_data_s *data, void *user_data) +{ + TC_PRT("+"); + + if (data == NULL) { + TC_PRT("No recieved data!"); + return; + } + + TC_PRT("Socket fd: %d", data->socket_fd); + TC_PRT("Data: %s", data->data); + TC_PRT("Size: %d", data->data_size); +} + +static void __bt_socket_connection_requested_cb(int socket_fd, const char *remote_address, void *user_data) +{ + TC_PRT("Socket fd: %d", socket_fd); + TC_PRT("remote_address: %s", remote_address); +} + +static void __bt_socket_connection_state_changed_cb(int result, + bt_socket_connection_state_e connection_state, + bt_socket_connection_s *connection, + void *user_data) +{ + TC_PRT("result: %s", __bt_get_error_message(result)); + TC_PRT("connection_state: %d", connection_state); + + if (connection == NULL) { + TC_PRT("No connection data!"); + return; + } + + TC_PRT("socket fd: %d", connection->socket_fd); + TC_PRT("server socket fd: %d", connection->server_fd); + TC_PRT("role: %d", connection->local_role); + TC_PRT("remote address: %s", connection->remote_address); + if (strcmp(spp_uuid, connection->service_uuid) == 0) { + TC_PRT("service_uuid: %s", spp_uuid); + client_fd = connection->socket_fd; + } else { + TC_PRT("service_uuid: %s", connection->service_uuid); + custom_client_fd = connection->socket_fd; + } +} + +void __bt_opp_client_push_responded_cb(int result, + const char *remote_address, + void *user_data) +{ + TC_PRT("result: %s", __bt_get_error_message(result)); + TC_PRT("remote_address: %s", remote_address); +} + +void __bt_opp_client_push_progress_cb(const char *file, + long long size, + int percent, + void *user_data) +{ + TC_PRT("size: %ld", (long)size); + TC_PRT("percent: %d", percent); + TC_PRT("file: %s", file); +} + +void __bt_opp_client_push_finished_cb(int result, + const char *remote_address, + void *user_data) +{ + TC_PRT("result: %s", __bt_get_error_message(result)); + TC_PRT("remote_address: %s", remote_address); +} + +void __bt_audio_connection_state_changed_cb(int result, + bool connected, const char *remote_address, + bt_audio_profile_type_e type, void *user_data) +{ + TC_PRT("result [%s]", __bt_get_error_message(result)); + TC_PRT("connected [%d]", connected); + TC_PRT("address [%s]", remote_address); + TC_PRT("type [%d]", type); +} + +void __bt_ag_sco_state_changed_cb(int result, bool opened, void *user_data) +{ + TC_PRT("result [%s]", __bt_get_error_message(result)); + TC_PRT("opened [%s]", opened ? "YES" : "NO"); +} + +void __bt_ag_set_call_handling_event_cb(bt_ag_call_handling_event_e event, + unsigned int call_id, void *user_data) +{ + TC_PRT("event[%d] call_id[%d]", event, call_id); +} + +void __bt_device_authorization_changed_cb(bt_device_authorization_e authorization, + char *remote_address, void *user_data) +{ + TC_PRT("__bt_device_authorization_changed_cb [%d]", authorization); + TC_PRT("address: %s", remote_address); +} + +void __bt_device_connection_state_changed_cb(bool connected, + bt_device_connection_info_s *conn_info, + void *user_data) +{ + TC_PRT("__bt_device_connection_state_changed_cb [%d]", connected); + TC_PRT("address [%s]", conn_info->remote_address); + TC_PRT("link type [%d]", conn_info->link); + TC_PRT("disconnection reason [%d]", conn_info->disconn_reason); +} + +bool __bt_device_connected_profile(bt_profile_e profile, void *user_data) +{ + TC_PRT("__bt_device_connected_profile [%d]", profile); + return true; +} + +void __bt_device_bond_created_cb(int result, bt_device_info_s *device_info, void *user_data) +{ + if(result == BT_ERROR_NONE) + { + TC_PRT("Callback: A bond is created."); + TC_PRT("Callback: The number of service - %d.", device_info->service_count); + + int i = 0; + for(i=0; iservice_count; i++) { + TC_PRT("Callback: service[%d] - %s", i+1, device_info->service_uuid[i]); + } + TC_PRT("Callback: is_bonded - %d.", device_info->is_bonded); + TC_PRT("Callback: is_connected - %d.", device_info->is_connected); + + if (device_info->manufacturer_data_len > 0) { + TC_PRT("manufacturer specific data(len:%d)", device_info->manufacturer_data_len); + printf("data ["); + for (i = 0; i < device_info->manufacturer_data_len; i++) + printf("%02x ", device_info->manufacturer_data[i]); + printf("]\n"); + } + } else { + TC_PRT("Callback: Creating a bond is failed."); + TC_PRT("result: %s", __bt_get_error_message(result)); + } +} + +void __bt_device_bond_destroyed_cb(int result, char *remote_address, void *user_data) +{ + if(result == BT_ERROR_NONE) + { + TC_PRT("Callback: A bond is destroyed."); + TC_PRT("Callback: Address - %s.", remote_address); + } else { + TC_PRT("Callback: Destroying a bond is failed."); + TC_PRT("result: %s", __bt_get_error_message(result)); + } +} + +void __bt_repeat_test_onoff_count_time_summary() +{ + time_t ctimer; + struct tm *_tm; + + ctimer = time(NULL); + ctimer -= bt_onoff_timer; + _tm = gmtime(&ctimer); + + if (_tm == NULL) { + /* Fix : NULL_RETURNS */ + TC_PRT("gmtime failed error "); + return; + } + + TC_PRT("try: %d, success: %d, fail: %d, time(%dd,%d:%d:%d)\n", + bt_onoff_cnt/2, bt_onoff_cnt_success/2, bt_onoff_cnt_fail, + _tm->tm_mday-1, _tm->tm_hour, _tm->tm_min, _tm->tm_sec); +} + +void __bt_gatt_connection_state_changed_cb(int result, bool connected, const char *remote_address, void *user_data) +{ + TC_PRT("result: %s", __bt_get_error_message(result)); + if (connected) { + TC_PRT("LE connected(address = %s)", remote_address); + /* Fix : STRING_OVERFLOW */ + strncpy(remote_addr, remote_address, strlen(remote_addr)); + } else { + TC_PRT("LE DISconnected"); + } +} + +int __bt_gatt_client_set_value(char *type, char *value, bt_gatt_h h) +{ + int ret; + int s_val; + unsigned int u_val; + char *buf; + int len; + + if (strcasecmp(type, "int8") == 0) { + s_val = atoi(value); + buf = (char *)&s_val; + len = 1; + } else if (strcasecmp(type, "int16") == 0) { + s_val = atoi(value); + buf = (char *)&s_val; + len = 2; + } else if (strcasecmp(type, "int32") == 0) { + s_val = atoi(value); + buf = (char *)&s_val; + len = 4; + } else if (strcasecmp(type, "uint8") == 0) { + u_val = strtoul(value, NULL, 10); + buf = (char *)&u_val; + len = 1; + } else if (strcasecmp(type, "uint16") == 0) { + u_val = strtoul(value, NULL, 10); + buf = (char *)&u_val; + len = 2; + } else if (strcasecmp(type, "uint32") == 0) { + u_val = strtoul(value, NULL, 10); + buf = (char *)&u_val; + len = 4; + } else if (strcasecmp(type, "str") == 0) { + buf = value; + len = strlen(buf); + } else + return BT_ERROR_INVALID_PARAMETER; + + ret = bt_gatt_set_value(h, buf, len); + if (ret != BT_ERROR_NONE) + TC_PRT("bt_gatt_set_value is failed : %d", ret); + + return ret; +} + +void __bt_gatt_client_print_value(bt_gatt_h h) +{ + int ret; + char *str = NULL; + char *value = NULL; + int len = 0; + bool hex_format = false; + int i; + + ret = bt_gatt_get_value(h, &value, &len); + if (ret != BT_ERROR_NONE) { + TC_PRT("bt_gatt_get_value is failed : %d", ret); + return; + } + + for (i = 0; i < len; i++) + if (isalnum(value[i]) == 0) { + hex_format = true; + break; + } + + if (hex_format) { + str = g_malloc0(len * 5 + 1); + /* Fix : NULL_RETURNS */ + if (!str) { + TC_PRT("BT_ERROR_OUT_OF_MEMORY"); + goto fail; + } + for (i = 0; i < len; i++) { + if (i > 0) + str[i * 5 - 1] = ' '; + + snprintf(&str[i * 5], 5, "0x%02X", value[i]); + } + } else { + str = g_malloc0(len + 1); + /* Fix : NULL_RETURNS */ + if (!str) { + TC_PRT("BT_ERROR_OUT_OF_MEMORY"); + goto fail; + } + memcpy(str, value, len); + } + + TC_PRT("Value : %s", str); + + g_free(str); +fail: + g_free(value); +} + +bool __bt_gatt_print_info_cb(int total, int index, bt_gatt_h gatt_handle, void *user_data) +{ + char *uuid = NULL; + char *str = NULL; + + bt_gatt_get_uuid(gatt_handle, &uuid); + bt_gatt_get_uuid_specification_name(uuid, &str); + + TC_PRT("[%d / %d] %s (%s)", index, total, str ? str : "Unknown", uuid); + + g_free(str); + g_free(uuid); + + return true; +} + +void __bt_gatt_client_write_complete_cb(int result, bt_gatt_h gatt_handle, void *data) +{ + char *uuid = NULL; + char *str = NULL; + + bt_gatt_get_uuid(gatt_handle, &uuid); + bt_gatt_get_uuid_specification_name(uuid, &str); + + TC_PRT("Write %s for %s (%s)", result == BT_ERROR_NONE ? "Success" : "Fail", str ? str : "Unknown", uuid); + + g_free(str); + g_free(uuid); + + return; +} + +void __bt_gatt_client_read_complete_cb(int result, bt_gatt_h gatt_handle, void *data) +{ + char *uuid = NULL; + char *str = NULL; + + bt_gatt_get_uuid(gatt_handle, &uuid); + bt_gatt_get_uuid_specification_name(uuid, &str); + + TC_PRT("Read %s for %s (%s)", result == BT_ERROR_NONE ? "Success" : "Fail", str ? str : "Unknown", uuid); + + g_free(str); + g_free(uuid); + + if (result != BT_ERROR_NONE) + return; + + __bt_gatt_client_print_value(gatt_handle); + + return; +} + +bool __bt_gatt_client_foreach_desc_cb(int total, int index, bt_gatt_h desc_handle, void *data) +{ + char *uuid = NULL; + char *str = NULL; + + bt_gatt_get_uuid(desc_handle, &uuid); + bt_gatt_get_uuid_specification_name(uuid, &str); + + TC_PRT("\t\t[%d / %d] %s (%s)", index, total, str ? str : "Unknown", uuid); + __bt_gatt_client_print_value(desc_handle); + + g_free(str); + g_free(uuid); + + return true; +} + +bool __bt_gatt_client_foreach_chr_cb(int total, int index, bt_gatt_h chr_handle, void *data) +{ + int ret; + char *uuid = NULL; + char *str = NULL; + + bt_gatt_get_uuid(chr_handle, &uuid); + bt_gatt_get_uuid_specification_name(uuid, &str); + + TC_PRT("\t[%d / %d] %s (%s)", index, total, str ? str : "Unknown", uuid); + __bt_gatt_client_print_value(chr_handle); + + g_free(str); + g_free(uuid); + + ret = bt_gatt_characteristic_foreach_descriptors(chr_handle, + __bt_gatt_client_foreach_desc_cb, NULL); + if (ret != BT_ERROR_NONE) + TC_PRT("bt_gatt_characteristic_foreach_descriptors is failed : %d", ret); + + return true; +} + +bool __bt_gatt_client_foreach_svc_cb(int total, int index, bt_gatt_h svc_handle, void *data) +{ + int test_id = (int)data; + int ret; + char *uuid = NULL; + char *str = NULL; + + bt_gatt_get_uuid(svc_handle, &uuid); + bt_gatt_get_uuid_specification_name(uuid, &str); + + TC_PRT("[%d / %d] %s (%s)", index, total, str ? str : "Unknown", uuid); + + g_free(str); + g_free(uuid); + + if (test_id == BT_UNIT_TEST_FUNCTION_GATT_CLIENT_PRINT_ALL) { + ret = bt_gatt_service_foreach_characteristics(svc_handle, + __bt_gatt_client_foreach_chr_cb, (void *)test_id); + if (ret != BT_ERROR_NONE) + TC_PRT("bt_gatt_service_foreach_characteristics is failed : %d", ret); + } + + return true; +} + +static void __ancs_write_completed_cb(int result, bt_gatt_h request_handle, + void *user_data) +{ + if (result != BT_ERROR_NONE) { + TC_PRT("write request is failed : %d", result); + return; + } + + TC_PRT("write request is done"); + + return; +} + +static int __ancs_write_value_to_control_point(bt_gatt_client_h client, char *value, int len) +{ + bt_gatt_h ancs_svc = NULL; + bt_gatt_h control_point = NULL; + char *svc_uuid = "7905F431-B5CE-4E99-A40F-4B1E122D00D0"; + char *chr_uuid = "69D1D8F3-45E1-49A8-9821-9BBDFDAAD9D9"; + int ret; + + ret = bt_gatt_client_get_service(client, svc_uuid, &ancs_svc); + if (ret != BT_ERROR_NONE) { + TC_PRT("bt_gatt_client_get_service is failed : %d", ret); + return ret; + } + + ret = bt_gatt_service_get_characteristic(ancs_svc, chr_uuid, &control_point); + if (ret != BT_ERROR_NONE) { + TC_PRT("bt_gatt_service_get_characteristic is failed"); + return ret; + } + + ret = bt_gatt_characteristic_set_write_type(control_point, + BT_GATT_WRITE_TYPE_WRITE); + if (ret != BT_ERROR_NONE) { + TC_PRT("bt_gatt_characteristic_set_write_type is failed : %d", ret); + return ret; + } + + ret = bt_gatt_set_value(control_point, value, len); + if (ret != BT_ERROR_NONE) { + TC_PRT("bt_gatt_set_value is failed : %d", ret); + return ret; + } + + ret = bt_gatt_client_write_value(control_point, + __ancs_write_completed_cb, NULL); + if (ret != BT_ERROR_NONE) { + TC_PRT("bt_gatt_client_write_value is failed : %d", ret); + return ret; + } + + return ret; +} + +void __bt_gatt_client_value_changed_cb(bt_gatt_h chr, char *value, int len, + void *user_data) +{ + char *uuid = NULL; + int i; + + bt_gatt_get_uuid(chr, &uuid); + + TC_PRT("Value changed for [%s]", uuid); + TC_PRT("len [%d]", len); + for (i = 0; i < len; i++) { + TC_PRT("value %u", value[i]); + } + + g_free(uuid); + + return; +} + +void __bt_gatt_server_notification_sent_cb(int result, + char *remote_address, bt_gatt_server_h server, + bt_gatt_h characteristic, bool completed, void *user_data) +{ + TC_PRT("result [%s]", __bt_get_error_message(result)); + TC_PRT("remote_address : %s", remote_address); + TC_PRT("completed : %d", completed); + TC_PRT("characteristic : %p", characteristic); +} + +#ifdef BT_ENABLE_LEGACY_GATT_CLIENT +bool __bt_gatt_primary_service_cb(bt_gatt_attribute_h service, void *user_data) +{ + TC_PRT("__bt_gatt_primary_service_cb"); + TC_PRT("service %s", (char *)service); + if (service_index >= MAX_SERVICES) + return true; + + bt_gatt_clone_attribute_handle(&service_clone[service_index], service); + service_index++; + return true; +} + +bool __bt_gatt_characteristics_discovered_cb(int result, int index, int total, bt_gatt_attribute_h characteristic, void *user_data) +{ + TC_PRT("result: %s", __bt_get_error_message(result)); + TC_PRT("index %d", index); + TC_PRT("total %d", total); + TC_PRT("characteristic %s", (char *)characteristic); + + if (index >= MAX_SERVICES) + return true; + + bt_gatt_clone_attribute_handle(&characteristics[index], characteristic); + return true; +} + +void __bt_gatt_characteristic_descriptor_discovered_cb(int result, + unsigned char characteristic_format, int total, + bt_gatt_attribute_h characteristic_descriptor, void *user_data) { + TC_PRT("result: %s", __bt_get_error_message(result)); + TC_PRT("total %d", total); + TC_PRT("characteristic_format 0x%02X", characteristic_format); + TC_PRT("characteristic_descriptor %s", (char *)characteristic_descriptor); +} + +bool __bt_gatt_included_service_cb(bt_gatt_attribute_h service, void *user_data) +{ + char *uuid = NULL; + char *name = NULL; + unsigned char *value = NULL; + int value_length = 0; + + TC_PRT("__bt_gatt_included_service_cb"); + TC_PRT("service %s", (char *)service); + + if (char_service_index >= MAX_SERVICES) + return true; + + bt_gatt_clone_attribute_handle(&characteristics_services[char_service_index], service); + char_service_index++; + + bt_gatt_get_characteristic_declaration(service, &uuid, &value, &value_length); + bt_gatt_get_uuid_specification_name(uuid, &name); + TC_PRT("uuid: %s [%s]", uuid, name); + + g_free(uuid); + g_free(name); + return true; +} + +void __bt_gatt_characteristic_changed_cb(bt_gatt_attribute_h characteristic, unsigned char *value, int value_length, void *user_data) +{ + int i; + + TC_PRT("__bt_gatt_characteristic_changed_cb"); + TC_PRT("service %s", (char *)characteristic); + TC_PRT("value_length %d", value_length); + + for (i = 0; i < value_length; i++) { + TC_PRT("value %c", value[i]); + } + + return; +} + +void __bt_gatt_char_write_cb(void *user_data) +{ + TC_PRT("__bt_gatt_char_write_cb"); + return; +} + +void __bt_gatt_char_read_cb(unsigned char *value, int value_length, void *user_data) +{ + int i; + + TC_PRT("__bt_gatt_char_read_cb"); + + TC_PRT("value_length %d", value_length); + + for (i = 0; i < value_length; i++) { + TC_PRT("value %u", value[i]); + } + + return; +} + +void __bt_gatt_remote_characteristic_write_cb(bt_gatt_attribute_h characteristic, + unsigned char *char_value, + int char_length, void *user_data) +{ + TC_PRT("remote device updated the characteristics in db"); + + TC_PRT("updated characteristic is %s", (char *)characteristic); + TC_PRT("new char value is %s", char_value); +} +#endif + +void __bt_avrcp_target_connection_state_changed_cb(bool connected, const char *remote_address, void *user_data) +{ + TC_PRT("__bt_avrcp_target_connection_state_changed_cb"); + TC_PRT("connected %d", connected); + TC_PRT("remote_address %s", remote_address); +} + +void __bt_avrcp_equalizer_state_changed_cb(bt_avrcp_equalizer_state_e equalizer, void *user_data) +{ + TC_PRT("__bt_avrcp_equalizer_state_changed_cb"); + TC_PRT("equalizer %d (1: OFF, 2: ON)", equalizer); +} + +void __bt_avrcp_repeat_mode_changed_cb(bt_avrcp_repeat_mode_e repeat, void *user_data) +{ + TC_PRT("__bt_avrcp_repeat_mode_changed_cb"); + TC_PRT("repeat %d (1: OFF, 2: SINGLE, 3: All, 4:GROUP)", repeat); +} + +void __bt_avrcp_shuffle_mode_changed_cb(bt_avrcp_shuffle_mode_e shuffle, void *user_data) +{ + TC_PRT("__bt_avrcp_shuffle_mode_changed_cb"); + TC_PRT("shuffle -> %d (1: OFF, 2: All TRACK, 3:GROUP)", shuffle); +} + +void __bt_avrcp_scan_mode_changed_cb(bt_avrcp_scan_mode_e scan, void *user_data) +{ + TC_PRT("__bt_avrcp_scan_mode_changed_cb"); + TC_PRT("scan -> %d", scan); +} + +void __bt_avrcp_control_connection_state_changed_cb(bool connected, const char *remote_address, void *user_data) +{ + TC_PRT("__bt_avrcp_target_connection_state_changed_cb"); + TC_PRT("connected %d", connected); + TC_PRT("remote_address %s", remote_address); +} + +void __bt_avrcp_song_position_changed_cb(unsigned int postion, void *user_data) +{ + TC_PRT("__bt_avrcp_song_position_changed_cb"); + TC_PRT("Position %d", postion); +} + +void __bt_avrcp_player_state_changed_cb(bt_avrcp_player_state_e state, void *user_data) +{ + TC_PRT("__bt_avrcp_player_state_changed_cb"); + TC_PRT("Player state -> %d (0: stopped, 1: Playing, 2:Paused, 3:FF, 4:REW)", state); +} + +void __bt_avrcp_track_info_changed_cb(bt_avrcp_metadata_attributes_info_s *metadata, void *user_data) +{ + TC_PRT("__bt_avrcp_track_info_changed_cb"); + TC_PRT("title %s", metadata->title); + TC_PRT("artist %s", metadata->artist); + TC_PRT("album %s", metadata->album); + TC_PRT("genre %s", metadata->genre); + TC_PRT("total_tracks %d", metadata->total_tracks); + TC_PRT("number %d", metadata->number); + TC_PRT("duration %d", metadata->duration); +} + +void panu_conn_state_changed(int result, bool connected, + const char *remote_address, + bt_panu_service_type_e type, + void *user_data) +{ + TC_PRT("result [%s]", __bt_get_error_message(result)); + TC_PRT("connected [%d]", connected); + TC_PRT("address [%s]", remote_address); + TC_PRT("type [%d]", type); + +} + +void __bt_hid_host_connection_state_changed_cb(int result, + bool connected, const char *remote_address, void *user_data) +{ + TC_PRT("__bt_hid_host_connection_state_changed_cb: called"); + TC_PRT("result: %s", __bt_get_error_message(result)); +} + +#ifdef TIZEN_WEARABLE +void __bt_hf_sco_state_changed_cb(int result, bool opened, void *user_data) +{ + TC_PRT("opened [%s]", opened ? "YES" : "NO"); +} + +void __bt_hf_set_call_handling_event_cb(bt_hf_call_handling_event_e event, + char *phone_number, void *user_data) +{ + switch(event) { + case BT_HF_CALL_HANDLING_EVENT_ANSWER: + TC_PRT("[call_handling_event_cb] event [ANSWER]"); + break; + case BT_HF_CALL_HANDLING_EVENT_RELEASE: + TC_PRT("[call_handling_event_cb] event [RELEASE]"); + break; + case BT_HF_CALL_HANDLING_EVENT_REJECT: + TC_PRT("[call_handling_event_cb] event [REJECT]"); + break; + case BT_HF_CALL_HANDLING_EVENT_RING: + TC_PRT("[call_handling_event_cb] event [RING]"); + break; + case BT_HF_CALL_HANDLING_EVENT_CALL_STARTED: + TC_PRT("[call_handling_event_cb] event [CALL_STARTED]"); + break; + case BT_HF_CALL_HANDLING_EVENT_CALL_ENDED: + TC_PRT("[call_handling_event_cb] event [CALL_ENDED]"); + break; + case BT_HF_CALL_HANDLING_EVENT_VOICE_RECOGNITION_ENABLED: + TC_PRT("[call_handling_event_cb] event [VOICE_RECOGNITION_ENABLED]"); + break; + case BT_HF_CALL_HANDLING_EVENT_VOICE_RECOGNITION_DISABLED: + TC_PRT("[call_handling_event_cb] event [VOICE_RECOGNITION_DISABLED]"); + break; + case BT_HF_CALL_HANDLING_EVENT_WAITING: + TC_PRT("[call_handling_event_cb] event [WAITING]"); + break; + case BT_HF_CALL_HANDLING_EVENT_HELD: + TC_PRT("[call_handling_event_cb] event [HELD]"); + break; + case BT_HF_CALL_HANDLING_EVENT_UNHELD: + TC_PRT("[call_handling_event_cb] event [UNHELD]"); + break; + case BT_HF_CALL_HANDLING_EVENT_SWAPPED: + TC_PRT("[call_handling_event_cb] event [SWAPPED]"); + break; + default: + TC_PRT("[call_handling_event_cb] event [UNKNOWN]"); + } + + TC_PRT("[call_handling_event_cb] phone_number [%s]", phone_number); +} + +void __bt_hf_call_status_updated_event_cb(GSList *call_info_list, void *user_data) +{ + TC_PRT("[call_status_updated_event_cb]"); + for (; call_info_list; call_info_list = g_slist_next(call_info_list)) { + bt_hf_call_status_info_s *call_info = call_info_list->data; + TC_PRT(" > Call info [No:%s, Dir:%d, Stat:%d, Mpt:%d, Idx:%d]", + call_info->number, call_info->direction, call_info->status, call_info->multi_party, call_info->index); + } + + bt_hf_free_call_status_info_list(call_info_list); +} + +void __bt_hf_speaker_gain_changed_cb(int gain, void *user_data) +{ + TC_PRT("__bt_hf_speaker_gain_changed_cb"); + TC_PRT("Gain= %d", gain); +} + +void __bt_pbap_enabled_cb(const char *remote_address, + int pbap_enabled, void *user_data) +{ + TC_PRT("__bt_pbap_enabled_cb"); + TC_PRT("Remote Device: %s", remote_address); + TC_PRT("Connected Status: %d", pbap_enabled); +} + +void __bt_pbap_phonebook_size_cb(const char *remote_address, + int size, void *user_data) +{ + TC_PRT("__bt_pbap_phonebook_size_cb"); + TC_PRT("Remote Device: %s", remote_address); + TC_PRT("Phonebook Size: %d", size); +} + +void __bt_pbap_phonebook_pull_cb(const char *remote_address, + char *vcf_file, int status, void *user_data) +{ + TC_PRT("__bt_pbap_phonebook_pull_cb"); + TC_PRT("Remote Device: %s", remote_address); + TC_PRT("Phonebook Download File: %s", vcf_file); + TC_PRT("Phonebook Download Status: %s", status? "Successful" : "Unsuccessful"); +} + +void __bt_pbap_vcard_list_cb(const char *remote_address, + char **vcards, int count, int status, void *user_data) +{ + TC_PRT("__bt_pbap_vcard_list_cb"); + TC_PRT("Remote Device: %s", remote_address); + TC_PRT("vCard List: %s", vcards[0]); + TC_PRT("vCard Count: %d", count); + TC_PRT("Listing Status: %s", status? "Successful" : "Unsuccessful"); +} +#endif + +void __bt_repeat_test_adapter_state_changed_cb(int result, bt_adapter_state_e adapter_state, void *user_data) +{ + unsigned int delay = *(unsigned int*)user_data; + + TC_PRT("__bt_repeat_test_adapter_state_changed_cb"); + TC_PRT("result: %s", __bt_get_error_message(result)); + TC_PRT("state: %s, delay(%dsec)", + (adapter_state == BT_ADAPTER_ENABLED)? + "ENABLED" : "DISABLED", delay); + + if (result != BT_ERROR_NONE) { + char *argv[] = {NULL}; + + TC_PRT("make dump\n"); + execv("all_log_dump.sh", argv); + + bt_onoff_cnt_fail++; + } else { + bt_onoff_cnt_success++; + + if (delay) + sleep(delay); + } + + if (adapter_state == BT_ADAPTER_DISABLED) + bt_adapter_enable(); + else + bt_adapter_disable(); + + bt_onoff_cnt++; + __bt_repeat_test_onoff_count_time_summary(); +} + +static void __bt_initialize_all(void) +{ + int ret; + TC_PRT("Initialize and set callback functions"); + + ret = bt_initialize(); + if (ret != BT_ERROR_NONE) + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + ret = bt_adapter_set_state_changed_cb(__bt_adapter_state_changed_cb, NULL); + if (ret != BT_ERROR_NONE) + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + ret = bt_adapter_set_connectable_changed_cb(__bt_adapter_connectable_changed_cb, NULL); + if (ret != BT_ERROR_NONE) + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + ret = bt_device_set_bond_created_cb(__bt_device_bond_created_cb, NULL); + if (ret != BT_ERROR_NONE) + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + ret = bt_device_set_bond_destroyed_cb(__bt_device_bond_destroyed_cb, NULL); + if (ret != BT_ERROR_NONE) + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + ret = bt_gatt_set_connection_state_changed_cb(__bt_gatt_connection_state_changed_cb, NULL); + if (ret != BT_ERROR_NONE) + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + ret = bt_adapter_set_device_discovery_state_changed_cb(__bt_adapter_device_discovery_state_changed_cb, NULL); + if (ret != BT_ERROR_NONE) + TC_PRT("returns %s\n", __bt_get_error_message(ret)); +#ifndef TIZEN_WEARABLE + ret = bt_adapter_le_set_device_discovery_state_changed_cb(__bt_adapter_le_device_discovery_state_changed_cb, NULL); + if (ret != BT_ERROR_NONE) + TC_PRT("returns %s\n", __bt_get_error_message(ret)); +#endif + ret = bt_socket_set_connection_state_changed_cb(__bt_socket_connection_state_changed_cb, NULL); + if (ret != BT_ERROR_NONE) + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + + return; +} + +int test_set_params(int test_id, char *param) +{ + static int param_index = 0; + const char *param_type = NULL; + + switch (current_tc_table) { + case BT_UNIT_TEST_TABLE_ADAPTER: { + switch (test_id) { + case BT_UNIT_TEST_FUNCTION_ADAPTER_SET_CONNECTABLE: { + if (param_index == 0) { + g_test_param.param_count = 1; + g_test_param.params = g_malloc0(sizeof(char*) * g_test_param.param_count); + param_type = BT_UNIT_TEST_PARAM_TYPE_BOOL; + } + + if (param_index > 0) { + g_test_param.params[param_index - 1] = g_malloc0(strlen(param) + 1); + strcpy(g_test_param.params[param_index - 1], param); + } + + if (param_index == g_test_param.param_count) { + need_to_set_params = false; + test_input_callback((void *)test_id); + param_index = 0; + return 0; + } + + TC_PRT("Input param(%d) type:%s", param_index + 1, param_type); + param_index++; + + break; + } + case BT_UNIT_TEST_FUNCTION_ADAPTER_SET_MANUFACTURER_DATA: + { + if (param_index == 0) { + g_test_param.param_count = 1; + g_test_param.params = g_malloc0(sizeof(char*) * g_test_param.param_count); + param_type = BT_UNIT_TEST_PARAM_TYPE_BYTE_ARRAY; + } + + if (param_index > 0) { + g_test_param.params[param_index - 1] = g_malloc0(strlen(param) + 1); + strcpy(g_test_param.params[param_index - 1], param); + } + + if (param_index == g_test_param.param_count) { + need_to_set_params = false; + test_input_callback((void *)test_id); + param_index = 0; + return 0; + } + + TC_PRT("Input param(%d) type:%s", param_index + 1, param_type); + param_index++; + + break; + } + + default: + TC_PRT("There is no param to set\n"); + need_to_set_params = false; + break; + } + + break; + } + + case BT_UNIT_TEST_TABLE_ADAPTER_LE: { + switch (test_id) { + case BT_UNIT_TEST_FUNCTION_ADAPTER_LE_SET_SCAN_MODE: + case BT_UNIT_TEST_FUNCTION_ADAPTER_LE_ADD_ADVERTISING_DATA: + case BT_UNIT_TEST_FUNCTION_ADAPTER_LE_SET_ADVERTISING_MODE: + case BT_UNIT_TEST_FUNCTION_ADAPTER_LE_SET_ADVERTISING_FILTER_POLICY: + case BT_UNIT_TEST_FUNCTION_ADAPTER_LE_SET_ADVERTISING_CONNECTABLE: + case BT_UNIT_TEST_FUNCTION_ADAPTER_LE_STOP_ADVERTISING: { + 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) { + g_test_param.params[param_index - 1] = g_malloc0(strlen(param) + 1); + strcpy(g_test_param.params[param_index - 1], param); + } + + if (param_index == g_test_param.param_count) { + need_to_set_params = false; + test_input_callback((void *)test_id); + param_index = 0; + return 0; + } + + switch (test_id) { + case BT_UNIT_TEST_FUNCTION_ADAPTER_LE_SET_SCAN_MODE: + TC_PRT("Scan mode\n (0 : Balanced (5000/2000 ms), 1: Low Latency (5000/5000 ms), 2 : Low Energy (5000/500 ms)"); + break; + case BT_UNIT_TEST_FUNCTION_ADAPTER_LE_ADD_ADVERTISING_DATA: + TC_PRT("Select advertising data \n (0 : Service uuid, 1: Service solicitation 2 : Appearance & Tx power, 3 : All, 4 : ANCS"); + TC_PRT("\t (Default scan response : Service Data &Local name & Manufacturer data)"); + break; + case BT_UNIT_TEST_FUNCTION_ADAPTER_LE_SET_ADVERTISING_MODE: + TC_PRT("Input mode \n (0 : Balanced(500 ms), 1 : Low Latency(150 ms), 2 : Low Energy (1000 ms))"); + break; + case BT_UNIT_TEST_FUNCTION_ADAPTER_LE_SET_ADVERTISING_FILTER_POLICY: + TC_PRT("Input filter_policy \n (0 : No use White List, 1 : Allow scan, 2 : Allow conneciton, 3 : Allow scan & conneciton)"); + break; + case BT_UNIT_TEST_FUNCTION_ADAPTER_LE_SET_ADVERTISING_CONNECTABLE: + TC_PRT("Input adv type \n (0 : Non-connectable (ADV_SCAN_IND), 1 : Connectable (ADV_IND) "); + break; + case BT_UNIT_TEST_FUNCTION_ADAPTER_LE_STOP_ADVERTISING: + TC_PRT("Input adv slot id \n (Default is 0, Maximum is 2) "); + break; + } + param_index++; + + break; + } + case BT_UNIT_TEST_FUNCTION_ADAPTER_LE_ENABLE_PRIVACY: { + if (param_index == 0) { + g_test_param.param_count = 1; + g_test_param.params = g_malloc0(sizeof(char*) * g_test_param.param_count); + param_type = BT_UNIT_TEST_PARAM_TYPE_BOOL; + } + + if (param_index > 0) { + g_test_param.params[param_index - 1] = g_malloc0(strlen(param) + 1); + strcpy(g_test_param.params[param_index - 1], param); + } + + if (param_index == g_test_param.param_count) { + need_to_set_params = false; + test_input_callback((void *)test_id); + param_index = 0; + return 0; + } + + TC_PRT("Input param(%d) type:%s", param_index + 1, param_type); + param_index++; + + break; + } + + default: + TC_PRT("There is no param to set\n"); + need_to_set_params = false; + break; + } + + break; + } + + case BT_UNIT_TEST_TABLE_DEVICE: { + switch (test_id) { + case BT_UNIT_TEST_FUNCTION_DEVICE_IS_PROFILE_CONNECTED: { + if (param_index == 0) { + g_test_param.param_count = 1; + g_test_param.params = g_malloc0(sizeof(char*) * g_test_param.param_count); + param_type = BT_UNIT_TEST_PARAM_TYPE_INT; + } + + if (param_index > 0) { + g_test_param.params[param_index - 1] = g_malloc0(strlen(param) + 1); + strcpy(g_test_param.params[param_index - 1], param); + } + + if (param_index == g_test_param.param_count) { + need_to_set_params = false; + test_input_callback((void *)test_id); + param_index = 0; + return 0; + } + + TC_PRT("Input param(%d) type:%s", param_index + 1, param_type); + param_index++; + + break; + } + + case BT_UNIT_TEST_FUNCTION_DEVICE_CREATE_BOND_BY_TYPE : { + if (param_index == 0) { + g_test_param.param_count = 1; + g_test_param.params = g_malloc0(sizeof(char*) * g_test_param.param_count); + param_type = BT_UNIT_TEST_PARAM_TYPE_INT; + } + + if (param_index > 0) { + g_test_param.params[param_index - 1] = g_malloc0(strlen(param) + 1); + strcpy(g_test_param.params[param_index - 1], param); + } + + if (param_index == g_test_param.param_count) { + need_to_set_params = false; + test_input_callback((void *)test_id); + param_index = 0; + return 0; + } + + TC_PRT("Input param(%d) type:%s", param_index + 1, param_type); + param_index++; + + break; + } + + default: + TC_PRT("There is no param to set\n"); + need_to_set_params = false; + break; + } + + break; + } + case BT_UNIT_TEST_TABLE_SOCKET: { + switch (test_id) { + case BT_UNIT_TEST_FUNCTION_SOCKET_SEND_DATA: { + if (param_index == 0) { + g_test_param.param_count = 1; + g_test_param.params = g_malloc0(sizeof(char*) * g_test_param.param_count); + param_type = BT_UNIT_TEST_PARAM_TYPE_STRING; + } + + if (param_index > 0) { + g_test_param.params[param_index - 1] = g_malloc0(strlen(param) + 1); + strcpy(g_test_param.params[param_index - 1], param); + } + + if (param_index == g_test_param.param_count) { + need_to_set_params = false; + test_input_callback((void *)test_id); + param_index = 0; + return 0; + } + + TC_PRT("Input param(%d) type:%s", param_index + 1, param_type); + param_index++; + + break; + } + default: + TC_PRT("There is no param to set\n"); + need_to_set_params = false; + break; + } + + break; + } + case BT_UNIT_TEST_TABLE_OPP: { + switch (test_id) { + default: + TC_PRT("There is no param to set\n"); + need_to_set_params = false; + break; + } + + break; + } + case BT_UNIT_TEST_TABLE_AUDIO: { + switch (test_id) { + case BT_UNIT_TEST_FUNCTION_AUDIO_CONNECT: { + if (param_index == 0) { + g_test_param.param_count = 1; + g_test_param.params = g_malloc0(sizeof(char*) * g_test_param.param_count); + param_type = BT_UNIT_TEST_PARAM_TYPE_INT; + } + + if (param_index > 0) { + g_test_param.params[param_index - 1] = g_malloc0(strlen(param) + 1); + strcpy(g_test_param.params[param_index - 1], param); + } + + if (param_index == g_test_param.param_count) { + need_to_set_params = false; + test_input_callback((void *)test_id); + param_index = 0; + return 0; + } + + TC_PRT("Input param(%d) type:%s", param_index + 1, param_type); + param_index++; + + break; + } + case BT_UNIT_TEST_FUNCTION_AUDIO_DISCONNECT: { + if (param_index == 0) { + g_test_param.param_count = 1; + g_test_param.params = g_malloc0(sizeof(char*) * g_test_param.param_count); + param_type = BT_UNIT_TEST_PARAM_TYPE_INT; + } + + if (param_index > 0) { + g_test_param.params[param_index - 1] = g_malloc0(strlen(param) + 1); + strcpy(g_test_param.params[param_index - 1], param); + } + + if (param_index == g_test_param.param_count) { + need_to_set_params = false; + test_input_callback((void *)test_id); + param_index = 0; + return 0; + } + + TC_PRT("Input param(%d) type:%s", param_index + 1, param_type); + param_index++; + + break; + } + + case BT_UNIT_TEST_FUNCTION_AG_CALL_EVENT_DIALING: { + if (param_index == 0) { + g_test_param.param_count = 1; + g_test_param.params = g_malloc0(sizeof(char*) * g_test_param.param_count); + param_type = BT_UNIT_TEST_PARAM_TYPE_STRING; + } + + if (param_index > 0) { + g_test_param.params[param_index - 1] = g_malloc0(strlen(param) + 1); + strcpy(g_test_param.params[param_index - 1], param); + } + + if (param_index == g_test_param.param_count) { + need_to_set_params = false; + test_input_callback((void *)test_id); + param_index = 0; + return 0; + } + + TC_PRT("Input param(%d) type:%s", param_index + 1, param_type); + param_index++; + + break; + } + case BT_UNIT_TEST_FUNCTION_AG_CALL_EVENT_INCOMING: { + if (param_index == 0) { + g_test_param.param_count = 1; + g_test_param.params = g_malloc0(sizeof(char*) * g_test_param.param_count); + param_type = BT_UNIT_TEST_PARAM_TYPE_STRING; + } + + if (param_index > 0) { + g_test_param.params[param_index - 1] = g_malloc0(strlen(param) + 1); + strcpy(g_test_param.params[param_index - 1], param); + } + + if (param_index == g_test_param.param_count) { + need_to_set_params = false; + test_input_callback((void *)test_id); + param_index = 0; + return 0; + } + + TC_PRT("Input param(%d) type:%s", param_index + 1, param_type); + param_index++; + + break; + } + case BT_UNIT_TEST_FUNCTION_CALL_LIST_ADD: { + if (param_index == 0) { + g_test_param.param_count = 1; + g_test_param.params = g_malloc0(sizeof(char*) * g_test_param.param_count); + param_type = BT_UNIT_TEST_PARAM_TYPE_STRING; + } + + if (param_index > 0) { + g_test_param.params[param_index - 1] = g_malloc0(strlen(param) + 1); + strcpy(g_test_param.params[param_index - 1], param); + } + + if (param_index == g_test_param.param_count) { + need_to_set_params = false; + test_input_callback((void *)test_id); + param_index = 0; + return 0; + } + + TC_PRT("Input param(%d) type:%s", param_index + 1, param_type); + param_index++; + + break; + } + + default: + TC_PRT("There is no param to set\n"); + need_to_set_params = false; + break; + } + + break; + } + case BT_UNIT_TEST_TABLE_PAN: { + switch (test_id) { + default: + TC_PRT("There is no param to set\n"); + need_to_set_params = false; + break; + } + + break; + } + case BT_UNIT_TEST_TABLE_GATT: { + switch (test_id) { + case BT_UNIT_TEST_FUNCTION_GATT_CONNECT: { + if (param_index == 0) { + g_test_param.param_count = 1; + g_test_param.params = g_malloc0(sizeof(char*) * g_test_param.param_count); + param_type = BT_UNIT_TEST_PARAM_TYPE_BOOL; + } + + if (param_index > 0) { + g_test_param.params[param_index - 1] = g_malloc0(strlen(param) + 1); + strcpy(g_test_param.params[param_index - 1], param); + } + + if (param_index == g_test_param.param_count) { + need_to_set_params = false; + test_input_callback((void *)test_id); + param_index = 0; + return 0; + } + + TC_PRT("Input param(%d) type:%s", param_index + 1, param_type); + param_index++; + + break; + } + case BT_UNIT_TEST_FUNCTION_GATT_CLIENT_READ_VALUE: { + if (param_index == 0) { + g_test_param.param_count = 3; + 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'; + strcpy(g_test_param.params[param_index - 1], param); + } + + if (param_index == g_test_param.param_count) { + need_to_set_params = false; + test_input_callback((void *)test_id); + param_index = 0; + return 0; + } + + switch (param_index) { + case 0: + TC_PRT("Input Service UUID"); + break; + case 1: + TC_PRT("Input Characteristic UUID"); + break; + case 2: + TC_PRT("Input Descriptor UUID or nothing"); + break; + } + + param_index++; + + break; + } + case BT_UNIT_TEST_FUNCTION_GATT_CLIENT_WRITE_VALUE: { + if (param_index == 0) { + g_test_param.param_count = 5; + 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'; + strcpy(g_test_param.params[param_index - 1], param); + } + + if (param_index == g_test_param.param_count) { + need_to_set_params = false; + test_input_callback((void *)test_id); + param_index = 0; + return 0; + } + + switch (param_index) { + case 0: + TC_PRT("Input Service UUID"); + break; + case 1: + TC_PRT("Input Characteristic UUID"); + break; + case 2: + TC_PRT("Input Descriptor UUID or nothing"); + break; + case 3: + TC_PRT("Input Value Type (avail. : uint8, uint16, uint32, int8, int16, int32, str)"); + break; + case 4: + TC_PRT("Input Value"); + break; + } + + param_index++; + + break; + } + case BT_UNIT_TEST_FUNCTION_GATT_CLIENT_SET_CHAR_VALUE_CHANGED_CB: { + if (param_index == 0) { + g_test_param.param_count = 2; + 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'; + strcpy(g_test_param.params[param_index - 1], param); + } + + if (param_index == g_test_param.param_count) { + need_to_set_params = false; + test_input_callback((void *)test_id); + param_index = 0; + return 0; + } + + switch (param_index) { + case 0: + TC_PRT("Input Service UUID"); + break; + case 1: + TC_PRT("Input Characteristic UUID"); + break; + } + + param_index++; + + break; + } + case BT_UNIT_TEST_FUNCTION_GATT_CLIENT_UNSET_CHAR_VALUE_CHANGED_CB: { + if (param_index == 0) { + g_test_param.param_count = 2; + 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'; + strcpy(g_test_param.params[param_index - 1], param); + } + + if (param_index == g_test_param.param_count) { + need_to_set_params = false; + test_input_callback((void *)test_id); + param_index = 0; + return 0; + } + + switch (param_index) { + case 0: + TC_PRT("Input Service UUID"); + break; + case 1: + TC_PRT("Input Characteristic UUID"); + break; + } + + param_index++; + + break; + } + case BT_UNIT_TEST_FUNCTION_ANCS_POSITIVE_ACTION: + case BT_UNIT_TEST_FUNCTION_ANCS_NEGATIVE_ACTION: + case BT_UNIT_TEST_FUNCTION_ANCS_GET_NOTI_ATTR: { + if (param_index == 0) { + g_test_param.param_count = 1; + g_test_param.params = g_malloc0(sizeof(char *) * g_test_param.param_count); + param_type = BT_UNIT_TEST_PARAM_TYPE_STRING; + } + + 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'; + strcpy(g_test_param.params[param_index - 1], param); + } + + if (param_index == g_test_param.param_count) { + need_to_set_params = false; + test_input_callback((void *)test_id); + param_index = 0; + return 0; + } + + TC_PRT("Input param(%d) type:%s", param_index + 1, param_type); + param_index++; + break; + } + + default: + TC_PRT("There is no param to set\n"); + need_to_set_params = false; + break; + } + + break; + } + case BT_UNIT_TEST_TABLE_AVRCP: { + switch (test_id) { + default: + TC_PRT("There is no param to set\n"); + need_to_set_params = false; + break; + } + + break; + } + case BT_UNIT_TEST_TABLE_HID: { + switch (test_id) { + default: + TC_PRT("There is no param to set\n"); + need_to_set_params = false; + break; + } + + break; + } +#ifdef TIZEN_WEARABLE + case BT_UNIT_TEST_TABLE_HF: { + switch (test_id) { + default: + TC_PRT("There is no param to set\n"); + need_to_set_params = false; + break; + } + + break; + } + case BT_UNIT_TEST_TABLE_PBAP_CLIENT: { + switch (test_id) { + default: + TC_PRT("There is no param to set\n"); + need_to_set_params = false; + break; + } + + break; + } +#endif + default: + TC_PRT("There is no param to set\n"); + need_to_set_params = false; + break; + } + + return 0; +} + +int test_input_callback(void *data) +{ + int ret = 0; + int test_id = (int)data; + + switch (current_tc_table) { + case BT_UNIT_TEST_TABLE_MAIN: { + switch (test_id) { + case 0x00ff: + TC_PRT("Finished"); + g_main_loop_quit(main_loop); + break; + + case BT_UNIT_TEST_FUNCTION_INITIALIZE: + ret = bt_initialize(); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + case BT_UNIT_TEST_FUNCTION_DEINITIALIZE: + ret = bt_deinitialize(); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + default: + break; + } + + break; + } + case BT_UNIT_TEST_TABLE_ADAPTER: { + switch (test_id) { + case BT_UNIT_TEST_FUNCTION_ADAPTER_GET_STATE: { + bt_adapter_state_e state = BT_ADAPTER_DISABLED; + + ret = bt_adapter_get_state(&state); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + TC_PRT("state: %d", state); + break; + } + case BT_UNIT_TEST_FUNCTION_ADAPTER_ENABLE: + ret = bt_adapter_enable(); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + case BT_UNIT_TEST_FUNCTION_ADAPTER_DISABLE: + ret = bt_adapter_disable(); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + case BT_UNIT_TEST_FUNCTION_ADAPTER_RECOVER: + ret = bt_adapter_recover(); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + case BT_UNIT_TEST_FUNCTION_ADAPTER_START_DEVICE_DISCOVERY: + ret = bt_adapter_start_device_discovery(); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + case BT_UNIT_TEST_FUNCTION_ADAPTER_STOP_DEVICE_DISCOVERY: + ret = bt_adapter_stop_device_discovery(); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + case BT_UNIT_TEST_FUNCTION_ADAPTER_IS_DISCOVERING: { + bool is_discovering = FALSE; + ret = bt_adapter_is_discovering(&is_discovering); + if (ret < BT_ERROR_NONE) + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + else + TC_PRT("is_discovering: %d", is_discovering); + + break; + } + case BT_UNIT_TEST_FUNCTION_ADAPTER_FOREACH_BONDED_DEVICE: { + ret = bt_adapter_foreach_bonded_device(__bt_adapter_bonded_device_cb, NULL); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + } + case BT_UNIT_TEST_FUNCTION_ADAPTER_GET_BONDED_DEVICE_INFO: { + bt_device_info_s *device_info = NULL; + + ret = bt_adapter_get_bonded_device_info(remote_addr, + &device_info); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + + if (device_info) { + TC_PRT("address: %s", device_info->remote_address); + TC_PRT("name: %s", device_info->remote_name); + } + + bt_adapter_free_device_info(device_info); + break; + } + case BT_UNIT_TEST_FUNCTION_ADAPTER_IS_SERVICE_USED: { + bool used = FALSE; + + ret = bt_adapter_is_service_used(opp_uuid, &used); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + TC_PRT("used: %d", used); + break; + } + case BT_UNIT_TEST_FUNCTION_ADAPTER_GET_VISIBILITY: { + bt_adapter_visibility_mode_e visibility_mode = BT_ADAPTER_VISIBILITY_MODE_NON_DISCOVERABLE; + int time = 0; + + ret = bt_adapter_get_visibility(&visibility_mode, &time); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + TC_PRT("mode: %d", visibility_mode); + TC_PRT("time: %d", time); + break; + } + case BT_UNIT_TEST_FUNCTION_ADAPTER_SET_DEVICE_DISCOVERY_STATE_CHANGED_CB: + ret = bt_adapter_set_device_discovery_state_changed_cb(__bt_adapter_device_discovery_state_changed_cb, NULL); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + case BT_UNIT_TEST_FUNCTION_ADAPTER_UNSET_DEVICE_DISCOVERY_STATE_CHANGED_CB: + ret = bt_adapter_unset_device_discovery_state_changed_cb(); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + + case BT_UNIT_TEST_FUNCTION_ADAPTER_GET_LOCAL_OOB_DATA: { + ret = bt_adapter_get_local_oob_data(&hash, &randomizer, &hash_len, &rand_len); + if (ret < BT_ERROR_NONE) { + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + } else { + TC_PRT("hash = [%s]", hash); + TC_PRT("randomizer = [%s]", randomizer); + } + break; + } + + case BT_UNIT_TEST_FUNCTION_ADAPTER_SET_LOCAL_OOB_DATA: { + ret = bt_adapter_set_remote_oob_data(remote_addr, hash, randomizer, hash_len, rand_len); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + } + + case BT_UNIT_TEST_FUNCTION_ADAPTER_REMOVE_REMOTE_OOB_DATA: { + ret = bt_adapter_remove_remote_oob_data(remote_addr); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + } + + case BT_UNIT_TEST_FUNCTION_ADAPTER_SET_VISIBILITY_MODE_CHANGED_CB: + ret = bt_adapter_set_visibility_mode_changed_cb(__bt_adapter_device_visibility_mode_changed_cb, NULL); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + case BT_UNIT_TEST_FUNCTION_ADAPTER_UNSET_VISIBILITY_MODE_CHANGED_CB: + ret = bt_adapter_unset_visibility_mode_changed_cb(); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + + case BT_UNIT_TEST_FUNCTION_ADAPTER_SET_VISIBILITY_DURATION_CHANGED_CB: + ret = bt_adapter_set_visibility_duration_changed_cb( + __bt_adapter_device_visibility_duration_changed_cb, NULL); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + case BT_UNIT_TEST_FUNCTION_ADAPTER_UNSET_VISIBILITY_DURATION_CHANGED_CB: + ret = bt_adapter_unset_visibility_duration_changed_cb(); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + + case BT_UNIT_TEST_FUNCTION_ADAPTER_SET_CONNECTABLE_CHANGED_CB: { + ret = bt_adapter_set_connectable_changed_cb(__bt_adapter_connectable_changed_cb, NULL); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + } + + case BT_UNIT_TEST_FUNCTION_ADAPTER_UNSET_CONNECTABLE_CHANGED_CB: { + ret = bt_adapter_unset_connectable_changed_cb(); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + } + + case BT_UNIT_TEST_FUNCTION_ADAPTER_GET_CONNECTABLE: { + bool connectable = false; + + ret = bt_adapter_get_connectable(&connectable); + if (ret < BT_ERROR_NONE) { + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + } + + TC_PRT("%s", connectable ? "Connectable" : "Non-connectable"); + break; + } + + case BT_UNIT_TEST_FUNCTION_ADAPTER_SET_CONNECTABLE: { + bool connectable = false; + + bt_adapter_get_connectable(&connectable); + + if (g_test_param.param_count > 0) { + if (g_strrstr(g_test_param.params[0], "true")) + connectable = true; + else + connectable = false; + + __bt_free_test_param(&g_test_param); + } + + ret = bt_adapter_set_connectable(!connectable); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + } + + case BT_UNIT_TEST_FUNCTION_ADAPTER_GET_VERSION: { + char *version = NULL; + + ret = bt_adapter_get_version(&version); + if (ret < BT_ERROR_NONE) + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + else { + TC_PRT("Version: [%s]",version); + g_free(version); + } + break; + } + + case BT_UNIT_TEST_FUNCTION_ADAPTER_GET_LOCAL_INFO: { + char *chipset = NULL; + char *firmware = NULL; + char *stack_version = NULL; + char *profiles = NULL; + + ret = bt_adapter_get_local_info(&chipset, &firmware, &stack_version, &profiles); + if (ret < BT_ERROR_NONE) + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + else { + TC_PRT("Local info: [%s, %s, %s]", chipset, firmware, stack_version); + TC_PRT("Local info(Profiles):\n%s", profiles); + g_free(chipset); + g_free(firmware); + g_free(stack_version); + g_free(profiles); + } + break; + } + + case BT_UNIT_TEST_FUNCTION_ADAPTER_SET_MANUFACTURER_DATA_CHANGED_CB: + { + ret = bt_adapter_set_manufacturer_data_changed_cb(__bt_adapter_manufacturer_data_changed_cb, NULL); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + } + + case BT_UNIT_TEST_FUNCTION_ADAPTER_UNSET_MANUFACTURER_DATA_CHANGED_CB: + ret = bt_adapter_unset_manufacturer_data_changed_cb(); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + + case BT_UNIT_TEST_FUNCTION_ADAPTER_SET_MANUFACTURER_DATA: + { + char data[20] = {0x03, 0xFF, 0x01, 0x02}; + int len = 4; + int i = 0; + + if (g_test_param.param_count > 0) { + len = 0; + for (i = 0; i < (strlen(g_test_param.params[0]) - 1); i += 2) { + if (g_test_param.params[0][i] >= 'A' && g_test_param.params[0][i] <= 'F') + data[i/2] = (g_test_param.params[0][i] - 'A' + 0X0A) << 4; + else + data[i/2] = (g_test_param.params[0][i] - '0') << 4; + + if (g_test_param.params[0][i+1] >= 'A' && g_test_param.params[0][i+1] <= 'F') + data[i/2] += (g_test_param.params[0][i+1] - 'A' + 0X0A); + else + data[i/2] += (g_test_param.params[0][i+1] - '0'); + len++; + } + + __bt_free_test_param(&g_test_param); + } + + ret = bt_adapter_set_manufacturer_data(data, len); + + 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_ADAPTER_LE: { + switch (test_id) { + case BT_UNIT_TEST_FUNCTION_ADAPTER_LE_GET_STATE: { + bt_adapter_le_state_e le_state = BT_ADAPTER_LE_DISABLED; + + ret = bt_adapter_le_get_state(&le_state); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + TC_PRT("le_state: %d", le_state); + break; + } + + case BT_UNIT_TEST_FUNCTION_ADAPTER_LE_ENABLE: { + ret = bt_adapter_le_enable(); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + } + + case BT_UNIT_TEST_FUNCTION_ADAPTER_LE_DISABLE: { + ret = bt_adapter_le_disable(); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + } + + case BT_UNIT_TEST_FUNCTION_ADAPTER_LE_SET_SCAN_MODE: { + int mode = BT_ADAPTER_LE_SCAN_MODE_BALANCED; + + if (g_test_param.param_count > 0) { + mode = atoi(g_test_param.params[0]); + __bt_free_test_param(&g_test_param); + } + + ret = bt_adapter_le_set_scan_mode(mode); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + } + + case BT_UNIT_TEST_FUNCTION_ADAPTER_LE_START_SCAN: + ret = bt_adapter_le_start_scan(__bt_adapter_le_scan_result_cb, NULL); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + + case BT_UNIT_TEST_FUNCTION_ADAPTER_LE_STOP_SCAN: + ret = bt_adapter_le_stop_scan(); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + +#ifndef TIZEN_WEARABLE + case BT_UNIT_TEST_FUNCTION_ADAPTER_LE_START_DEVICE_DISCOVERY: + ret = bt_adapter_le_start_device_discovery(); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + + case BT_UNIT_TEST_FUNCTION_ADAPTER_LE_STOP_DEVICE_DISCOVERY: + ret = bt_adapter_le_stop_device_discovery(); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; +#endif + + case BT_UNIT_TEST_FUNCTION_ADAPTER_LE_ADD_ADVERTISING_DATA: { + int adv_data_type = 3; // default all + int manufacturer_id = 117; + char *manufacture = NULL; + char manufacture_0[] = {0x0, 0x0, 0x0, 0x0}; + char manufacture_1[] = {0x01, 0x01, 0x01, 0x01}; + char manufacture_2[] = {0x02, 0x02, 0x02, 0x02}; + char manufacture_3[] = {0x03, 0x03, 0x03, 0x03}; + char service_data[] = {0x01, 0x02, 0x03}; + const char *time_svc_uuid_16 = "1805"; + const char *battery_svc_uuid_16 = "180f"; + const char *heart_rate_svc_uuid_16 = "180d"; + const char *lmmediate_alert_svc_uuid_16 = "1802"; + const char *ancs_uuid_128 = "7905F431-B5CE-4E99-A40F-4B1E122D00D0"; + int appearance = 192; // 192 is generic watch + + advertiser = advertiser_list[advertiser_index]; + + if (advertiser == NULL) { + ret = bt_adapter_le_create_advertiser(&advertiser); + TC_PRT("created le advertiser(%d)", ret); + advertiser_list[advertiser_index] = advertiser; + } else { + ret = bt_adapter_le_clear_advertising_data(advertiser, BT_ADAPTER_LE_PACKET_ADVERTISING); + if (ret != BT_ERROR_NONE) + TC_PRT("clear advertising data [0x%04x]", ret); + ret = bt_adapter_le_clear_advertising_data(advertiser, BT_ADAPTER_LE_PACKET_SCAN_RESPONSE); + if (ret != BT_ERROR_NONE) + TC_PRT("clear scan response data [0x%04x]", ret); + } + + if (g_test_param.param_count > 0) { + adv_data_type = atoi(g_test_param.params[0]); + __bt_free_test_param(&g_test_param); + } + + switch (adv_data_type) { + case 0: // service uuid + ret = bt_adapter_le_add_advertising_service_uuid(advertiser, + BT_ADAPTER_LE_PACKET_ADVERTISING, time_svc_uuid_16); + if (ret != BT_ERROR_NONE) + TC_PRT("add service_uuid [0x%04x]", ret); + + ret = bt_adapter_le_add_advertising_service_uuid(advertiser, + BT_ADAPTER_LE_PACKET_ADVERTISING, battery_svc_uuid_16); + if (ret != BT_ERROR_NONE) + TC_PRT("add service_uuid [0x%04x]", ret); + + manufacture = manufacture_0; + break; + + case 1: // service solicitation + ret = bt_adapter_le_add_advertising_service_solicitation_uuid(advertiser, + BT_ADAPTER_LE_PACKET_ADVERTISING, heart_rate_svc_uuid_16); + if (ret != BT_ERROR_NONE) + TC_PRT("add service_solicitation_uuid [0x%04x]", ret); + + ret = bt_adapter_le_add_advertising_service_solicitation_uuid(advertiser, + BT_ADAPTER_LE_PACKET_ADVERTISING, lmmediate_alert_svc_uuid_16); + if (ret != BT_ERROR_NONE) + TC_PRT("add service_solicitation_uuid [0x%04x]", ret); + + manufacture = manufacture_1; + break; + + case 2: // appearance & tx power level + ret = bt_adapter_le_set_advertising_appearance(advertiser, + BT_ADAPTER_LE_PACKET_ADVERTISING, appearance); + if (ret != BT_ERROR_NONE) + TC_PRT("add appearance data [0x%04x]", ret); + + ret = bt_adapter_le_set_advertising_tx_power_level(advertiser, + BT_ADAPTER_LE_PACKET_ADVERTISING, true); + if (ret != BT_ERROR_NONE) + TC_PRT("add appearance data [0x%04x]", ret); + manufacture = manufacture_2; + break; + + case 3: // All + ret = bt_adapter_le_add_advertising_service_uuid(advertiser, + BT_ADAPTER_LE_PACKET_ADVERTISING, time_svc_uuid_16); + if (ret != BT_ERROR_NONE) + TC_PRT("add service_uuid [0x%04x]", ret); + + ret = bt_adapter_le_add_advertising_service_uuid(advertiser, + BT_ADAPTER_LE_PACKET_ADVERTISING, battery_svc_uuid_16); + if (ret != BT_ERROR_NONE) + TC_PRT("add service_uuid [0x%04x]", ret); + + ret = bt_adapter_le_add_advertising_service_solicitation_uuid(advertiser, + BT_ADAPTER_LE_PACKET_ADVERTISING, heart_rate_svc_uuid_16); + if (ret != BT_ERROR_NONE) + TC_PRT("add service_solicitation_uuid [0x%04x]", ret); + + ret = bt_adapter_le_add_advertising_service_solicitation_uuid(advertiser, + BT_ADAPTER_LE_PACKET_ADVERTISING, lmmediate_alert_svc_uuid_16); + if (ret != BT_ERROR_NONE) + TC_PRT("add service_solicitation_uuid [0x%04x]", ret); + + ret = bt_adapter_le_set_advertising_appearance(advertiser, + BT_ADAPTER_LE_PACKET_ADVERTISING, appearance); + if (ret != BT_ERROR_NONE) + TC_PRT("add appearance data [0x%04x]", ret); + + ret = bt_adapter_le_set_advertising_tx_power_level(advertiser, + BT_ADAPTER_LE_PACKET_ADVERTISING, true); + if (ret != BT_ERROR_NONE) + TC_PRT("add tx_power_level [0x%04x]", ret); + + manufacture = manufacture_3; + break; + + case 4: // ANCS + ret = bt_adapter_le_add_advertising_service_solicitation_uuid(advertiser, + BT_ADAPTER_LE_PACKET_ADVERTISING, time_svc_uuid_16); + if (ret != BT_ERROR_NONE) + TC_PRT("add service_solicitation_uuid [0x%04x]", ret); + + ret = bt_adapter_le_add_advertising_service_solicitation_uuid(advertiser, + BT_ADAPTER_LE_PACKET_ADVERTISING, ancs_uuid_128); + if (ret != BT_ERROR_NONE) + TC_PRT("add service_solicitation_uuid [0x%04x]", ret); + + ret = bt_adapter_le_set_advertising_device_name(advertiser, + BT_ADAPTER_LE_PACKET_SCAN_RESPONSE, true); + if (ret != BT_ERROR_NONE) + TC_PRT("set device name [0x%04x]", ret); + + return 0; + + default: + TC_PRT("No adv data"); + break; + } + + /* Default scsn response data */ + ret = bt_adapter_le_add_advertising_service_data(advertiser, + BT_ADAPTER_LE_PACKET_SCAN_RESPONSE, time_svc_uuid_16, + service_data, sizeof(service_data)); + if (ret != BT_ERROR_NONE) + TC_PRT("add service_data [0x%04x]", ret); + + ret = bt_adapter_le_set_advertising_device_name(advertiser, + BT_ADAPTER_LE_PACKET_SCAN_RESPONSE, true); + if (ret != BT_ERROR_NONE) + TC_PRT("set device name [0x%04x]", ret); + + ret = bt_adapter_le_add_advertising_manufacturer_data(advertiser, + BT_ADAPTER_LE_PACKET_SCAN_RESPONSE, + manufacturer_id, + manufacture, sizeof(manufacture_0)); + if (ret != BT_ERROR_NONE) + TC_PRT("add manufacturer data [0x%04x]", ret); + + break; + } + case BT_UNIT_TEST_FUNCTION_ADAPTER_LE_SET_ADVERTISING_MODE: { + int mode = BT_ADAPTER_LE_ADVERTISING_MODE_BALANCED; + + advertiser = advertiser_list[advertiser_index]; + + if (advertiser == NULL) { + ret = bt_adapter_le_create_advertiser(&advertiser); + TC_PRT("created le advertiser(%d)", ret); + advertiser_list[advertiser_index] = advertiser; + } + + if (g_test_param.param_count > 0) { + mode = atoi(g_test_param.params[0]); + __bt_free_test_param(&g_test_param); + } + + ret = bt_adapter_le_set_advertising_mode(advertiser, mode); + if (ret != BT_ERROR_NONE) + TC_PRT("add scan response data [0x%04x]", ret); + break; + } + case BT_UNIT_TEST_FUNCTION_ADAPTER_LE_SET_ADVERTISING_FILTER_POLICY: { + int filter_policy = BT_ADAPTER_LE_ADVERTISING_FILTER_ALLOW_CONN_WL; + + advertiser = advertiser_list[advertiser_index]; + + if (advertiser == NULL) { + ret = bt_adapter_le_create_advertiser(&advertiser); + TC_PRT("created le advertiser(%d)", ret); + advertiser_list[advertiser_index] = advertiser; + } + + if (g_test_param.param_count > 0) { + filter_policy = atoi(g_test_param.params[0]); + __bt_free_test_param(&g_test_param); + } + + ret = bt_adapter_le_set_advertising_filter_policy(advertiser, filter_policy); + if (ret != BT_ERROR_NONE) + TC_PRT("add scan response data [0x%04x]", ret); + break; + } + case BT_UNIT_TEST_FUNCTION_ADAPTER_LE_SET_ADVERTISING_CONNECTABLE: { + int type = BT_ADAPTER_LE_ADVERTISING_CONNECTABLE; + + advertiser = advertiser_list[advertiser_index]; + + if (advertiser == NULL) { + ret = bt_adapter_le_create_advertiser(&advertiser); + TC_PRT("created le advertiser(%d)", ret); + advertiser_list[advertiser_index] = advertiser; + } + + if (g_test_param.param_count > 0) { + type = atoi(g_test_param.params[0]); + __bt_free_test_param(&g_test_param); + } + + ret = bt_adapter_le_set_advertising_connectable(advertiser, type); + if (ret != BT_ERROR_NONE) + TC_PRT("add scan response data [0x%04x]", ret); + break; + } + case BT_UNIT_TEST_FUNCTION_ADAPTER_LE_START_ADVERTISING_NEW: { + bt_adapter_le_advertising_state_changed_cb cb; + + if (advertiser_index == 0) cb = __bt_adapter_le_advertising_state_changed_cb; + else if (advertiser_index == 1) cb = __bt_adapter_le_advertising_state_changed_cb_2; + else cb = __bt_adapter_le_advertising_state_changed_cb_3; + + advertiser = advertiser_list[advertiser_index]; + + if (advertiser == NULL) { + ret = bt_adapter_le_create_advertiser(&advertiser); + TC_PRT("created le advertiser(%d)", ret); + advertiser_list[advertiser_index] = advertiser; + } + advertiser_index++; + advertiser_index %= 3; + + TC_PRT("advertiser: %p", advertiser); + + ret = bt_adapter_le_start_advertising_new(advertiser, cb, NULL); + if (ret < BT_ERROR_NONE) + TC_PRT("failed with [0x%04x]", ret); + break; + } +#ifndef TIZEN_WEARABLE + case BT_UNIT_TEST_FUNCTION_ADAPTER_LE_START_ADVERTISING: { + bt_adapter_le_advertising_state_changed_cb cb; + bt_adapter_le_advertising_params_s adv_params = { 0, }; + + if (advertiser_index == 0) cb = __bt_adapter_le_advertising_state_changed_cb; + else if (advertiser_index == 1) cb = __bt_adapter_le_advertising_state_changed_cb_2; + else cb = __bt_adapter_le_advertising_state_changed_cb_3; + + advertiser = advertiser_list[advertiser_index]; + + adv_params.interval_min= 500; + adv_params.interval_max= 500; + adv_params.type = BT_ADAPTER_LE_ADVERTISING_CONNECTABLE; + + if (advertiser == NULL) { + ret = bt_adapter_le_create_advertiser(&advertiser); + TC_PRT("created le advertiser(%d)", ret); + advertiser_list[advertiser_index] = advertiser; + } + advertiser_index++; + advertiser_index %= 3; + + TC_PRT("type: %d", adv_params.type); + + ret = bt_adapter_le_start_advertising(advertiser, &adv_params, cb, NULL); + if (ret < BT_ERROR_NONE) + TC_PRT("failed with [0x%04x]", ret); + break; + } +#endif + case BT_UNIT_TEST_FUNCTION_ADAPTER_LE_STOP_ADVERTISING: { + int slot_id = 0; + + if (g_test_param.param_count > 0) { + slot_id = atoi(g_test_param.params[0]); + __bt_free_test_param(&g_test_param); + } + + advertiser = advertiser_list[slot_id]; + + TC_PRT("advertiser: %p", advertiser); + + ret = bt_adapter_le_stop_advertising(advertiser); + + if(advertiser_index > 0) + advertiser_index--; + else + advertiser_index = 2; + + advertiser_list[slot_id] = NULL; + + if (ret < BT_ERROR_NONE) + TC_PRT("failed with [0x%04x]", ret); + break; + } + case BT_UNIT_TEST_FUNCTION_ADAPTER_LE_ADD_WHITE_LIST: { + ret = bt_adapter_le_add_white_list(remote_addr, BT_DEVICE_PUBLIC_ADDRESS); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + } + + case BT_UNIT_TEST_FUNCTION_ADAPTER_LE_REMOVE_WHITE_LIST: { + ret = bt_adapter_le_remove_white_list(remote_addr, BT_DEVICE_PUBLIC_ADDRESS); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + } + +#ifndef TIZEN_WEARABLE + case BT_UNIT_TEST_FUNCTION_ADAPTER_LE_CLEAR_WHITE_LIST: { + ret = bt_adapter_le_clear_white_list(); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + } +#endif + + case BT_UNIT_TEST_FUNCTION_ADAPTER_LE_ENABLE_PRIVACY: { + static bool enable_privacy = false; + + if (enable_privacy == false) + enable_privacy = true; + else + enable_privacy = false; + + if (g_test_param.param_count > 0) { + if (g_strrstr(g_test_param.params[0], "true")) + enable_privacy = true; + else + enable_privacy = false; + + __bt_free_test_param(&g_test_param); + } + + ret = bt_adapter_le_enable_privacy(enable_privacy); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + } + + case BT_UNIT_TEST_FUNCTION_ADAPTER_LE_REGISTER_SCAN_FILTER_DEVICE_ADDRESS: { + bt_scan_filter_h scan_filter; + + ret = bt_adapter_le_create_scan_filter(&scan_filter); + if (ret != BT_ERROR_NONE) + TC_PRT("failed with [0x%04x]", ret); + + ret = bt_adapter_le_scan_filter_set_device_address(scan_filter, remote_addr); + if (ret != BT_ERROR_NONE) + TC_PRT("failed with [0x%04x]", ret); + + ret = bt_adapter_le_register_scan_filter(scan_filter); + if (ret != BT_ERROR_NONE) + TC_PRT("failed with [0x%04x]", ret); + + ret = bt_adapter_le_destroy_scan_filter(scan_filter); + if (ret != BT_ERROR_NONE) + TC_PRT("failed with [0x%04x]", ret); + + break; + } + + case BT_UNIT_TEST_FUNCTION_ADAPTER_LE_REGISTER_SCAN_FILTER_SERVICE_UUID: { + bt_scan_filter_h scan_filter; + + ret = bt_adapter_le_create_scan_filter(&scan_filter); + if (ret != BT_ERROR_NONE) + TC_PRT("failed with [0x%04x]", ret); + + ret = bt_adapter_le_scan_filter_set_service_uuid(scan_filter, "1805"); + if (ret != BT_ERROR_NONE) + TC_PRT("failed with [0x%04x]", ret); + + ret = bt_adapter_le_register_scan_filter(scan_filter); + if (ret != BT_ERROR_NONE) + TC_PRT("failed with [0x%04x]", ret); + + ret = bt_adapter_le_destroy_scan_filter(scan_filter); + if (ret != BT_ERROR_NONE) + TC_PRT("failed with [0x%04x]", ret); + + break; + } + + case BT_UNIT_TEST_FUNCTION_ADAPTER_LE_REGISTER_SCAN_FILTER_SERVICE_SOLICITATION_UUID: { + bt_scan_filter_h scan_filter; + + ret = bt_adapter_le_create_scan_filter(&scan_filter); + if (ret != BT_ERROR_NONE) + TC_PRT("failed with [0x%04x]", ret); + + ret = bt_adapter_le_scan_filter_set_service_solicitation_uuid(scan_filter, "1805"); + if (ret != BT_ERROR_NONE) + TC_PRT("failed with [0x%04x]", ret); + + ret = bt_adapter_le_register_scan_filter(scan_filter); + if (ret != BT_ERROR_NONE) + TC_PRT("failed with [0x%04x]", ret); + + ret = bt_adapter_le_destroy_scan_filter(scan_filter); + if (ret != BT_ERROR_NONE) + TC_PRT("failed with [0x%04x]", ret); + + break; + } + + case BT_UNIT_TEST_FUNCTION_ADAPTER_LE_UNREGISTER_ALL_SCAN_FILTERS: { + ret = bt_adapter_le_unregister_all_scan_filters(); + if (ret != BT_ERROR_NONE) + TC_PRT("failed with [0x%04x]", ret); + + break; + } + +#ifndef TIZEN_WEARABLE + case BT_UNIT_TEST_FUNCTION_ADAPTER_LE_SET_DEVICE_DISCOVERY_STATE_CHANGED_CB: + ret = bt_adapter_le_set_device_discovery_state_changed_cb(__bt_adapter_le_device_discovery_state_changed_cb, NULL); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + + case BT_UNIT_TEST_FUNCTION_ADAPTER_LE_UNSET_DEVICE_DISCOVERY_STATE_CHANGED_CB: + ret = bt_adapter_le_unset_device_discovery_state_changed_cb(); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; +#endif + + 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_DEVICE: { + switch (test_id) { + case BT_UNIT_TEST_FUNCTION_DEVICE_SET_AUTHORIZATION_TRUE: { + ret = bt_device_set_authorization(remote_addr, BT_DEVICE_AUTHORIZED); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + } + case BT_UNIT_TEST_FUNCTION_DEVICE_SET_AUTHORIZATION_FALSE: { + ret = bt_device_set_authorization(remote_addr, BT_DEVICE_UNAUTHORIZED); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + } + case BT_UNIT_TEST_FUNCTION_DEVICE_SET_AUTHORIZATION_CHANGED_CB: + ret = bt_device_set_authorization_changed_cb(__bt_device_authorization_changed_cb, NULL); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + + case BT_UNIT_TEST_FUNCTION_DEVICE_UNSET_AUTHORIZATION_CHANGED_CB: + ret = bt_device_unset_authorization_changed_cb(); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + + case BT_UNIT_TEST_FUNCTION_DEVICE_SET_CONNECTION_STAET_CHANGED_CB: + ret = bt_device_set_connection_state_changed_cb(__bt_device_connection_state_changed_cb, NULL); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + + case BT_UNIT_TEST_FUNCTION_DEVICE_UNSET_CONNECTION_STAET_CHANGED_CB: + ret = bt_device_unset_connection_state_changed_cb(); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + + case BT_UNIT_TEST_FUNCTION_DEVICE_FOREACH_CONNECTED_PROFILES: { + ret = bt_device_foreach_connected_profiles(remote_addr, __bt_device_connected_profile, NULL); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + } + + case BT_UNIT_TEST_FUNCTION_DEVICE_IS_PROFILE_CONNECTED: { + bool connected_status = false; + bt_profile_e profile = BT_PROFILE_HSP; + + if (g_test_param.param_count > 0) { + profile = atoi(g_test_param.params[0]); + + __bt_free_test_param(&g_test_param); + } + + ret = bt_device_is_profile_connected(remote_addr, profile, &connected_status); + if (ret < BT_ERROR_NONE) { + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + } + TC_PRT("Profile [%s]", connected_status ? "Connected" : "Disconnected"); + break; + } + + case BT_UNIT_TEST_FUNCTION_DEVICE_SET_BOND_CREATED_CB : { + ret = bt_device_set_bond_created_cb(__bt_device_bond_created_cb, NULL); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + } + + case BT_UNIT_TEST_FUNCTION_DEVICE_SET_BOND_DESTROYED_CB : { + ret = bt_device_set_bond_destroyed_cb(__bt_device_bond_destroyed_cb, NULL); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + } + + case BT_UNIT_TEST_FUNCTION_DEVICE_CREATE_BOND : { + ret = bt_device_create_bond(remote_addr); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + } + + case BT_UNIT_TEST_FUNCTION_DEVICE_CREATE_BOND_BY_TYPE : { + bt_device_connection_link_type_e link_type = BT_DEVICE_CONNECTION_LINK_LE; + + if (g_test_param.param_count > 0) { + link_type = atoi(g_test_param.params[0]); + + __bt_free_test_param(&g_test_param); + } + + ret = bt_device_create_bond_by_type(remote_addr, link_type); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + } + + case BT_UNIT_TEST_FUNCTION_DEVICE_DESTROY_BOND : { + ret = bt_device_destroy_bond(remote_addr); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + } + + case BT_UNIT_TEST_FUNCTION_DEVICE_GET_CONNECTION_STATE: { + bool bredr_connected = false; + bool le_connected = false; + + ret = bt_device_get_connection_state(remote_addr, + BT_DEVICE_CONNECTION_LINK_BREDR, + &bredr_connected); + if (ret < BT_ERROR_NONE) { + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + } + + ret = bt_device_get_connection_state(remote_addr, + BT_DEVICE_CONNECTION_LINK_LE, + &le_connected); + if (ret < BT_ERROR_NONE) { + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + } + + TC_PRT("BR/EDR [%s], LE [%s]", + bredr_connected ? "Connected" : "Disconnected", + le_connected ? "Connected" : "Disconnected"); + + 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_SOCKET: { + switch (test_id) { + case BT_UNIT_TEST_FUNCTION_SOCKET_CREATE_RFCOMM: { + int socket_fd = 0; + + ret = bt_socket_create_rfcomm(spp_uuid, &socket_fd); + if (ret < BT_ERROR_NONE) { + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + } else { + TC_PRT("socket_fd: %d", socket_fd); + server_fd = socket_fd; + } + break; + } + case BT_UNIT_TEST_FUNCTION_SOCKET_DESTROY_RFCOMM: + ret = bt_socket_destroy_rfcomm(server_fd); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + case BT_UNIT_TEST_FUNCTION_SOCKET_LISTEN_AND_ACCEPT_RFCOMM: + ret = bt_socket_listen_and_accept_rfcomm(server_fd, 1); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + case BT_UNIT_TEST_FUNCTION_SOCKET_LISTEN: + ret = bt_socket_listen(server_fd, 1); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + case BT_UNIT_TEST_FUNCTION_SOCKET_ACCEPT: { + int socket_fd = 0; + + ret = bt_socket_accept(server_fd); + if (ret < BT_ERROR_NONE) { + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + } else { + TC_PRT("socket_fd: %d", socket_fd); + client_fd = socket_fd; + } + break; + } + case BT_UNIT_TEST_FUNCTION_SOCKET_REJECT: + ret = bt_socket_reject(server_fd); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + case BT_UNIT_TEST_FUNCTION_SOCKET_CONNECT_RFCOMM: { + ret = bt_socket_connect_rfcomm(remote_addr, spp_uuid); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + } + case BT_UNIT_TEST_FUNCTION_SOCKET_DISCONNECT_RFCOMM: + ret = bt_socket_disconnect_rfcomm(client_fd); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + case BT_UNIT_TEST_FUNCTION_SOCKET_SEND_DATA: { + char data[] = "Sending test"; + + if (g_test_param.param_count > 0) { + ret = bt_socket_send_data(client_fd, g_test_param.params[0], strlen(g_test_param.params[0]) + 1); + + __bt_free_test_param(&g_test_param); + } else { + ret = bt_socket_send_data(client_fd, data, sizeof(data)); + } + + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + } + case BT_UNIT_TEST_FUNCTION_SOCKET_CREATE_RFCOMM_CUSTOM_UUID: { + int socket_fd = 0; + + ret = bt_socket_create_rfcomm(custom_uuid, &socket_fd); + if (ret < BT_ERROR_NONE) { + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + } else { + TC_PRT("socket_fd: %d", socket_fd); + custom_server_fd = socket_fd; + } + break; + } + case BT_UNIT_TEST_FUNCTION_SOCKET_DESTROY_RFCOMM_CUSTOM_UUID: + ret = bt_socket_destroy_rfcomm(custom_server_fd); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + case BT_UNIT_TEST_FUNCTION_SOCKET_LISTEN_AND_ACCEPT_RFCOMM_CUSTOM_UUID: + ret = bt_socket_listen_and_accept_rfcomm(custom_server_fd, 1); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + case BT_UNIT_TEST_FUNCTION_SOCKET_CONNECT_RFCOMM_CUSTOM_UUID: { + ret = bt_socket_connect_rfcomm(remote_addr, custom_uuid); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + } + case BT_UNIT_TEST_FUNCTION_SOCKET_DISCONNECT_RFCOMM_CUSTOM_UUID: + ret = bt_socket_disconnect_rfcomm(custom_client_fd); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + case BT_UNIT_TEST_FUNCTION_SOCKET_SEND_DATA_CUSTOM_UUID: { + char data[] = "Sending test"; + + if (g_test_param.param_count > 0) { + ret = bt_socket_send_data(custom_client_fd, g_test_param.params[0], strlen(g_test_param.params[0]) + 1); + + __bt_free_test_param(&g_test_param); + } else { + ret = bt_socket_send_data(custom_client_fd, data, sizeof(data)); + } + + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + } + case BT_UNIT_TEST_FUNCTION_SOCKET_SET_DATA_RECEIVED_CB: + ret = bt_socket_set_data_received_cb(__bt_socket_data_received_cb, NULL); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + case BT_UNIT_TEST_FUNCTION_SOCKET_UNSET_DATA_RECEIVED_CB: + ret = bt_socket_unset_data_received_cb(); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + case BT_UNIT_TEST_FUNCTION_SOCKET_SET_CONNECTION_REQUESTED_CB: + ret = bt_socket_set_connection_requested_cb(__bt_socket_connection_requested_cb, NULL); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + case BT_UNIT_TEST_FUNCTION_SOCKET_UNSET_CONNECTION_REQUESTED_CB: + ret = bt_socket_unset_connection_requested_cb(); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + case BT_UNIT_TEST_FUNCTION_SOCKET_SET_CONNECTION_STATE_CHANGED_CB: + ret = bt_socket_set_connection_state_changed_cb(__bt_socket_connection_state_changed_cb, NULL); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + case BT_UNIT_TEST_FUNCTION_SOCKET_UNSET_CONNECTION_STATE_CHANGED_CB: + ret = bt_socket_unset_connection_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_OPP: { + switch (test_id) { + case BT_UNIT_TEST_FUNCTION_OPP_CLIENT_INITIALIZE: + ret = bt_opp_client_initialize(); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + case BT_UNIT_TEST_FUNCTION_OPP_CLIENT_DEINITIALIZE: + ret = bt_opp_client_deinitialize(); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + case BT_UNIT_TEST_FUNCTION_OPP_CLIENT_ADD_FILE: + ret = bt_opp_client_add_file("/opt/media/Images/image1.jpg"); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + case BT_UNIT_TEST_FUNCTION_OPP_CLIENT_CLEAR_FILES: + ret = bt_opp_client_clear_files(); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + case BT_UNIT_TEST_FUNCTION_OPP_CLIENT_PUSH_FILES: { + ret = bt_opp_client_push_files(remote_addr,__bt_opp_client_push_responded_cb, + __bt_opp_client_push_progress_cb, + __bt_opp_client_push_finished_cb, + NULL); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + } + case BT_UNIT_TEST_FUNCTION_OPP_CLIENT_CANCEL_PUSH: + ret = bt_opp_client_cancel_push(); + 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_AUDIO: { + switch (test_id) { + case BT_UNIT_TEST_FUNCTION_AUDIO_INITIALIZE: + ret = bt_audio_initialize(); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + case BT_UNIT_TEST_FUNCTION_AUDIO_DEINITIALIZE: + ret = bt_audio_deinitialize(); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + case BT_UNIT_TEST_FUNCTION_AUDIO_CONNECT: { + bt_audio_profile_type_e audio_profile = BT_AUDIO_PROFILE_TYPE_ALL; + + if (g_test_param.param_count > 0) { + audio_profile = atoi(g_test_param.params[0]); + + __bt_free_test_param(&g_test_param); + } + + ret = bt_audio_connect(remote_addr, audio_profile); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + } + case BT_UNIT_TEST_FUNCTION_AUDIO_DISCONNECT: { + bt_audio_profile_type_e audio_profile = BT_AUDIO_PROFILE_TYPE_ALL; + + if (g_test_param.param_count > 0) { + audio_profile = atoi(g_test_param.params[0]); + + __bt_free_test_param(&g_test_param); + } + + ret = bt_audio_disconnect(remote_addr, audio_profile); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + } + case BT_UNIT_TEST_FUNCTION_AUDIO_SET_CONNECTION_STATE_CHANGED_CB: + ret = bt_audio_set_connection_state_changed_cb( + __bt_audio_connection_state_changed_cb, NULL); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + case BT_UNIT_TEST_FUNCTION_AUDIO_UNSET_CONNECTION_STATE_CHANGED_CB: + ret = bt_audio_unset_connection_state_changed_cb(); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + case BT_UNIT_TEST_FUNCTION_A2DP_AUDIO_SET_CONNECTION_STATE_CB: + ret = bt_a2dp_source_audio_set_connection_state_changed_cb( + __bt_audio_connection_state_changed_cb, NULL); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + case BT_UNIT_TEST_FUNCTION_A2DP_AUDIO_UNSET_CONNECTION_STATE_CB: + ret = bt_a2dp_source_audio_unset_connection_state_changed_cb(); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + case BT_UNIT_TEST_FUNCTION_AG_OPEN_SCO: + ret = bt_ag_open_sco(); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + case BT_UNIT_TEST_FUNCTION_AG_CLOSE_SCO: + ret = bt_ag_close_sco(); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + case BT_UNIT_TEST_FUNCTION_AG_IS_SCO_OPENED: { + bool opened = false; + ret = bt_ag_is_sco_opened(&opened); + TC_PRT("opend[%s]", opened ? "YES" : "NO"); + if (ret < BT_ERROR_NONE) { + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + } + break; + } + case BT_UNIT_TEST_FUNCTION_AG_SET_SCO_STATE_CHANGED_CB: + ret = bt_ag_set_sco_state_changed_cb(__bt_ag_sco_state_changed_cb, NULL); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + case BT_UNIT_TEST_FUNCTION_AG_UNSET_SCO_STATE_CHANGED_CB: + ret = bt_ag_unset_sco_state_changed_cb(); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + case BT_UNIT_TEST_FUNCTION_AG_IS_CONNECTED: { + bool connected = false; + ret = bt_ag_is_connected(&connected); + TC_PRT("returns %s\n", connected ? "Connected" : "Disconnected"); + break; + } + case BT_UNIT_TEST_FUNCTION_AG_CALL_EVENT_IDLE: { + unsigned int call_id = 1; + + ret = bt_ag_notify_call_event(BT_AG_CALL_EVENT_IDLE, call_id, NULL); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + } + case BT_UNIT_TEST_FUNCTION_AG_CALL_EVENT_ANSWERED: { + unsigned int call_id = 1; + bool sco_required = true; + + ret = bt_ag_notify_call_event(BT_AG_CALL_EVENT_ANSWERED, call_id, NULL); + if (sco_required) + bt_ag_open_sco(); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + } + case BT_UNIT_TEST_FUNCTION_AG_CALL_EVENT_DIALING: { + unsigned int call_id = 1; + bool sco_required = TRUE; + const char *phone_number; + + if (g_test_param.param_count > 0) { + ret = bt_ag_notify_call_event(BT_AG_CALL_EVENT_DIALING, + call_id, g_test_param.params[0]); + + __bt_free_test_param(&g_test_param); + } else { + phone_number = g_strdup("01012345678"); + + ret = bt_ag_notify_call_event(BT_AG_CALL_EVENT_DIALING, + call_id, phone_number); + } + + if (sco_required) + bt_ag_open_sco(); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + } + case BT_UNIT_TEST_FUNCTION_AG_CALL_EVENT_ALERTING: { + unsigned int call_id = 1; + + ret = bt_ag_notify_call_event(BT_AG_CALL_EVENT_ALERTING, + call_id, NULL); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + } + case BT_UNIT_TEST_FUNCTION_AG_CALL_EVENT_INCOMING: { + unsigned int call_id = 1; + const char *phone_number; + + if (g_test_param.param_count > 0) { + ret = bt_ag_notify_call_event(BT_AG_CALL_EVENT_INCOMING, + call_id, g_test_param.params[0]); + + __bt_free_test_param(&g_test_param); + } else { + phone_number = g_strdup("01012345678"); + + ret = bt_ag_notify_call_event(BT_AG_CALL_EVENT_INCOMING, + call_id, phone_number); + } + + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + } + case BT_UNIT_TEST_FUNCTION_CALL_LIST_CREATE: + ret = bt_call_list_create(&call_list); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + case BT_UNIT_TEST_FUNCTION_CALL_LIST_DESTROY: + ret = bt_call_list_destroy(call_list); + call_list = NULL; + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + case BT_UNIT_TEST_FUNCTION_CALL_LIST_RESET: + ret = bt_call_list_reset(call_list); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + case BT_UNIT_TEST_FUNCTION_CALL_LIST_ADD: { + const char *phone_number; + + if (g_test_param.param_count > 0) { + ret = bt_call_list_add(call_list, 1, BT_AG_CALL_STATE_ACTIVE, g_test_param.params[0]); + + __bt_free_test_param(&g_test_param); + } else { + phone_number = g_strdup("01012345678"); + + ret = bt_call_list_add(call_list, 1, BT_AG_CALL_STATE_ACTIVE, phone_number); + } + + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + } + case BT_UNIT_TEST_FUNCTION_AG_NOTIFY_CALL_LIST: + ret = bt_ag_notify_call_list(call_list); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + case BT_UNIT_TEST_FUNCTION_AG_SET_CALL_HANDLING_EVENT_CB: + ret = bt_ag_set_call_handling_event_cb( + __bt_ag_set_call_handling_event_cb, NULL); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + case BT_UNIT_TEST_FUNCTION_AG_IS_NREC_ENABLED: { + bool enabled = false; + ret = bt_ag_is_nrec_enabled(&enabled); + TC_PRT("opend[%s]", enabled ? "YES" : "NO"); + if (ret < BT_ERROR_NONE) { + 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_PAN: { + switch (test_id) { + case BT_UNIT_TEST_FUNCTION_NAP_ACTIVATE: + ret = bt_nap_activate(); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + + case BT_UNIT_TEST_FUNCTION_NAP_DEACTIVATE: + ret = bt_nap_deactivate(); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + + case BT_UNIT_TEST_FUNCTION_NAP_DISCONNECT_ALL: + ret = bt_nap_disconnect_all(); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + + case BT_UNIT_TEST_FUNCTION_NAP_DISCONNECT: { + ret = bt_nap_disconnect(remote_addr); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + } + + case BT_UNIT_TEST_FUNCTION_PANU_SET_CONNECTION_STATE_CHANGED_CB: { + ret = bt_panu_set_connection_state_changed_cb(panu_conn_state_changed, + NULL); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + } + case BT_UNIT_TEST_FUNCTION_PANU_CONNECT: { + ret = bt_panu_connect(remote_addr, BT_PANU_SERVICE_TYPE_NAP); + 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_GATT: { + switch (test_id) { + case BT_UNIT_TEST_FUNCTION_GATT_CONNECT : { + bool auto_connect = false; + + if (g_test_param.param_count > 0) { + if (g_strrstr(g_test_param.params[0], "true")) + auto_connect = true; + else + auto_connect = false; + + __bt_free_test_param(&g_test_param); + } + + ret = bt_gatt_connect(remote_addr, auto_connect); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + } + case BT_UNIT_TEST_FUNCTION_GATT_DISCONNECT : { + ret = bt_gatt_disconnect(remote_addr); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + } + case BT_UNIT_TEST_FUNCTION_SET_GATT_CONNECTION_STATE_CHANGED_CB : { + ret = bt_gatt_set_connection_state_changed_cb(__bt_gatt_connection_state_changed_cb, NULL); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + } + case BT_UNIT_TEST_FUNCTION_UNSET_GATT_CONNECTION_STATE_CHANGED_CB : { + ret = bt_gatt_unset_connection_state_changed_cb(); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + } + case BT_UNIT_TEST_FUNCTION_GATT_CLIENT_CREATE: { + if (client) { + bt_gatt_client_destroy(client); + client = NULL; + } + ret = bt_gatt_client_create(remote_addr, &client); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + } + case BT_UNIT_TEST_FUNCTION_GATT_CLIENT_DESTROY: { + if (!client) + break; + + ret = bt_gatt_client_destroy(client); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + client = NULL; + break; + } + case BT_UNIT_TEST_FUNCTION_GATT_CLIENT_GET_REMOTE_ADDRESS: { + char *addr = NULL; + + ret = bt_gatt_client_get_remote_address(client, &addr); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + + if (addr) { + TC_PRT("remote addr : %s\n", addr); + g_free(addr); + } + break; + } + case BT_UNIT_TEST_FUNCTION_GATT_CLIENT_PRINT_ALL: { + ret = bt_gatt_client_foreach_services(client, + __bt_gatt_client_foreach_svc_cb, (void *)test_id); + if (ret != BT_ERROR_NONE) { + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + } + break; + } + case BT_UNIT_TEST_FUNCTION_GATT_CLIENT_READ_VALUE: { + char *svc_uuid = NULL; + char *chr_uuid = NULL; + char *desc_uuid = NULL; + bt_gatt_h svc = NULL; + bt_gatt_h chr = NULL; + bt_gatt_h desc = NULL; + + if (g_test_param.param_count < 3) { + TC_PRT("Input parameters first"); + break; + } + + svc_uuid = g_test_param.params[0]; + chr_uuid = g_test_param.params[1]; + + ret = bt_gatt_client_get_service(client, svc_uuid, &svc); + if (ret != BT_ERROR_NONE) { + TC_PRT("bt_gatt_client_get_service is failed : %d", ret); + __bt_free_test_param(&g_test_param); + break; + } + + ret = bt_gatt_service_get_characteristic(svc, chr_uuid, &chr); + if (ret != BT_ERROR_NONE) { + TC_PRT("bt_gatt_service_get_characteristic is failed : %d", ret); + __bt_free_test_param(&g_test_param); + break; + } + + if (strlen(g_test_param.params[2]) > 0) { + desc_uuid = g_test_param.params[2]; + ret = bt_gatt_characteristic_get_descriptor(chr, desc_uuid, &desc); + if (ret != BT_ERROR_NONE) { + TC_PRT("bt_gatt_characteristic_get_descriptor is failed : %d", ret); + __bt_free_test_param(&g_test_param); + break; + } + ret = bt_gatt_client_read_value(desc, + __bt_gatt_client_read_complete_cb, NULL); + } else { + ret = bt_gatt_client_read_value(chr, + __bt_gatt_client_read_complete_cb, NULL); + } + + if (ret != BT_ERROR_NONE) { + TC_PRT("bt_gatt_client_read_value is failed : %d", ret); + } + + __bt_free_test_param(&g_test_param); + break; + } + case BT_UNIT_TEST_FUNCTION_GATT_CLIENT_WRITE_VALUE: { + char *svc_uuid = NULL; + char *chr_uuid = NULL; + char *desc_uuid = NULL; + bt_gatt_h svc = NULL; + bt_gatt_h chr = NULL; + bt_gatt_h desc = NULL; + + if (g_test_param.param_count < 5) { + TC_PRT("Input parameters first"); + break; + } + + svc_uuid = g_test_param.params[0]; + chr_uuid = g_test_param.params[1]; + + ret = bt_gatt_client_get_service(client, svc_uuid, &svc); + if (ret != BT_ERROR_NONE) { + TC_PRT("bt_gatt_client_get_service is failed : %d", ret); + __bt_free_test_param(&g_test_param); + break; + } + + ret = bt_gatt_service_get_characteristic(svc, chr_uuid, &chr); + if (ret != BT_ERROR_NONE) { + TC_PRT("bt_gatt_service_get_characteristic is failed : %d", ret); + __bt_free_test_param(&g_test_param); + break; + } + + if (strlen(g_test_param.params[2]) > 0) { + desc_uuid = g_test_param.params[2]; + ret = bt_gatt_characteristic_get_descriptor(chr, desc_uuid, &desc); + if (ret != BT_ERROR_NONE) { + TC_PRT("bt_gatt_characteristic_get_descriptor is failed : %d", ret); + __bt_free_test_param(&g_test_param); + break; + } + + ret = __bt_gatt_client_set_value(g_test_param.params[3], + g_test_param.params[4], desc); + if (ret != BT_ERROR_NONE) { + TC_PRT("bt_gatt_set_value is failed : %d", ret); + __bt_free_test_param(&g_test_param); + break; + } + + ret = bt_gatt_client_write_value(desc, + __bt_gatt_client_write_complete_cb, NULL); + } else { + ret = __bt_gatt_client_set_value(g_test_param.params[3], + g_test_param.params[4], chr); + if (ret != BT_ERROR_NONE) { + TC_PRT("bt_gatt_set_value is failed : %d", ret); + __bt_free_test_param(&g_test_param); + break; + } + + ret = bt_gatt_client_write_value(chr, + __bt_gatt_client_write_complete_cb, NULL); + } + + if (ret != BT_ERROR_NONE) { + TC_PRT("bt_gatt_client_write_value is failed : %d", ret); + } + + __bt_free_test_param(&g_test_param); + break; + } + case BT_UNIT_TEST_FUNCTION_GATT_CLIENT_SET_CHAR_VALUE_CHANGED_CB: { + char *svc_uuid = NULL; + char *chr_uuid = NULL; + bt_gatt_h svc = NULL; + bt_gatt_h chr = NULL; + + if (g_test_param.param_count < 2) { + TC_PRT("Input parameters first"); + break; + } + + svc_uuid = g_test_param.params[0]; + chr_uuid = g_test_param.params[1]; + + ret = bt_gatt_client_get_service(client, svc_uuid, &svc); + if (ret != BT_ERROR_NONE) { + TC_PRT("bt_gatt_client_get_service is failed : %d", ret); + __bt_free_test_param(&g_test_param); + break; + } + + ret = bt_gatt_service_get_characteristic(svc, chr_uuid, &chr); + if (ret != BT_ERROR_NONE) { + TC_PRT("bt_gatt_service_get_characteristic is failed : %d", ret); + __bt_free_test_param(&g_test_param); + break; + } + + ret = bt_gatt_client_set_characteristic_value_changed_cb(chr, + __bt_gatt_client_value_changed_cb, NULL); + if (ret != BT_ERROR_NONE) + TC_PRT("bt_gatt_client_set_characteristic_value_changed_cb is failed : %d", ret); + + __bt_free_test_param(&g_test_param); + break; + } + case BT_UNIT_TEST_FUNCTION_GATT_CLIENT_UNSET_CHAR_VALUE_CHANGED_CB: { + char *svc_uuid = NULL; + char *chr_uuid = NULL; + bt_gatt_h svc = NULL; + bt_gatt_h chr = NULL; + + if (g_test_param.param_count < 2) { + TC_PRT("Input parameters first"); + break; + } + + svc_uuid = g_test_param.params[0]; + chr_uuid = g_test_param.params[1]; + + ret = bt_gatt_client_get_service(client, svc_uuid, &svc); + if (ret != BT_ERROR_NONE) { + TC_PRT("bt_gatt_client_get_service is failed : %d", ret); + __bt_free_test_param(&g_test_param); + break; + } + + ret = bt_gatt_service_get_characteristic(svc, chr_uuid, &chr); + if (ret != BT_ERROR_NONE) { + TC_PRT("bt_gatt_service_get_characteristic is failed : %d", ret); + __bt_free_test_param(&g_test_param); + break; + } + + ret = bt_gatt_client_unset_characteristic_value_changed_cb(chr); + if (ret != BT_ERROR_NONE) + TC_PRT("bt_gatt_client_unset_characteristic_value_changed_cb is failed : %d", ret); + + __bt_free_test_param(&g_test_param); + break; + } + case BT_UNIT_TEST_FUNCTION_GATT_CLIENT_FOREACH_SERVICES: { + ret = bt_gatt_client_foreach_services(client, + __bt_gatt_client_foreach_svc_cb, (void *)test_id); + if (ret != BT_ERROR_NONE) + TC_PRT("bt_gatt_client_foreach_services_by_uuid is failed"); + break; + } + case BT_UNIT_TEST_FUNCTION_GATT_SERVER_INITIALIZE : { + + ret = bt_gatt_server_initialize(); + + TC_PRT("returns %s \n", __bt_get_error_message(ret)); + break; + } + case BT_UNIT_TEST_FUNCTION_GATT_SERVER_DEINITIALIZE : { + + ret = bt_gatt_server_deinitialize(); + + TC_PRT("returns %s \n", __bt_get_error_message(ret)); + break; + } + case BT_UNIT_TEST_FUNCTION_GATT_SERVER_UNREGISTER_ALL_SERVICES: { + ret = bt_gatt_server_unregister_all_services(server); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + + break; + } + case BT_UNIT_TEST_FUNCTION_GATT_SERVER_REGISTER_BATTERY_SVC: { + bt_gatt_h service = NULL; + bt_gatt_h characteristic = NULL; + bt_gatt_h descriptor = NULL; + char *service_uuid = "180f"; // Battery Service + char *char_uuid = "2a19"; // Battery Level + char *desc_uuid = "2902"; // CCCD + char char_value[1] = {80}; // 80% + char desc_value[2] = {0, 0}; // Notification & Indication disabled + int permissions = BT_GATT_PERMISSION_READ; + int properties = BT_GATT_PROPERTY_READ | BT_GATT_PROPERTY_NOTIFY; + + ret = bt_gatt_server_initialize(); + TC_PRT("bt_gatt_server_initialize : %s \n", __bt_get_error_message(ret)); + + if (server == NULL) { + ret = bt_gatt_server_create(&server); + TC_PRT("bt_gatt_server_create : %s \n", __bt_get_error_message(ret)); + } + + ret = bt_gatt_service_create(service_uuid, BT_GATT_SERVICE_TYPE_PRIMARY, &service); + TC_PRT("bt_gatt_service_create : %s \n", __bt_get_error_message(ret)); + + ret = bt_gatt_characteristic_create(char_uuid, permissions, properties, + char_value, sizeof(char_value), &characteristic); + TC_PRT("bt_gatt_characteristic_create : %s\n", __bt_get_error_message(ret)); + + ret = bt_gatt_service_add_characteristic(service, characteristic); + TC_PRT("bt_gatt_service_add_characteristic : %s\n", __bt_get_error_message(ret)); + + permissions = BT_GATT_PERMISSION_READ | BT_GATT_PERMISSION_WRITE; + ret = bt_gatt_descriptor_create(desc_uuid, permissions, desc_value, sizeof(desc_value), &descriptor); + TC_PRT("bt_gatt_descriptor_create : %s\n", __bt_get_error_message(ret)); + + ret = bt_gatt_characteristic_add_descriptor(characteristic, descriptor); + TC_PRT("bt_gatt_characteristic_add_descriptor : %s\n", __bt_get_error_message(ret)); + + ret = bt_gatt_server_register_service(server, service); + TC_PRT("bt_gatt_server_register_service : %s\n", __bt_get_error_message(ret)); + + battery_h.svc = service; + battery_h.chr = characteristic; + battery_h.desc = descriptor; + + break; + } + case BT_UNIT_TEST_FUNCTION_GATT_SERVER_CHANGE_BATTERY_LEVEL: { + char char_value[1] = {1 + (rand()%100)}; + if (!server) { + TC_PRT("bt gatt server is not created"); + break; + } + ret = bt_gatt_set_value(battery_h.chr, char_value, 1); + TC_PRT("Value[%d], returns %s\n", char_value[0], __bt_get_error_message(ret)); + + break; + } + case BT_UNIT_TEST_FUNCTION_GATT_SERVER_REGISTER_HEART_RATE_SVC: { + bt_gatt_h service = NULL; + bt_gatt_h characteristic = NULL; + bt_gatt_h descriptor = NULL; + char *service_uuid = "180d"; // Heart Rate Service + char *char_uuid = "2a37"; // Heart Rate Measurement + char *desc_uuid = "2902"; // CCCD + char char_value_1[3] = {1, 0x38, 0}; // Flag + Measurement value (56) + char desc_value[2] = {1, 0}; // Notification enabled + int permissions = BT_GATT_PERMISSION_READ; + int properties = BT_GATT_PROPERTY_NOTIFY | BT_GATT_PROPERTY_READ; // READ property added for testing + + ret = bt_gatt_server_initialize(); + TC_PRT("bt_gatt_server_initialize : %s \n", __bt_get_error_message(ret)); + + if (server == NULL) { + ret = bt_gatt_server_create(&server); + TC_PRT("bt_gatt_server_create : %s \n", __bt_get_error_message(ret)); + } + + ret = bt_gatt_service_create(service_uuid, BT_GATT_SERVICE_TYPE_PRIMARY, &service); + TC_PRT("bt_gatt_service_create : %s \n", __bt_get_error_message(ret)); + + ret = bt_gatt_characteristic_create(char_uuid, permissions, properties, + char_value_1, sizeof(char_value_1), &characteristic); + TC_PRT("bt_gatt_characteristic_create : %s\n", __bt_get_error_message(ret)); + + heart_rate_h.chr = characteristic; + + bt_gatt_server_set_read_value_requested_cb(characteristic, __bt_gatt_server_read_value_requested_cb, NULL); + ret = bt_gatt_service_add_characteristic(service, characteristic); + TC_PRT("bt_gatt_service_add_characteristic : %s\n", __bt_get_error_message(ret)); + + permissions = BT_GATT_PERMISSION_READ | BT_GATT_PERMISSION_WRITE; + ret = bt_gatt_descriptor_create(desc_uuid, permissions, desc_value, sizeof(desc_value), &descriptor); + TC_PRT("bt_gatt_descriptor_create : %s\n", __bt_get_error_message(ret)); + + ret = bt_gatt_characteristic_add_descriptor(characteristic, descriptor); + TC_PRT("bt_gatt_characteristic_add_descriptor : %s\n", __bt_get_error_message(ret)); + + char_uuid = "2a38"; // Body Sensor Location + permissions = BT_GATT_PERMISSION_READ; + properties = BT_GATT_PROPERTY_READ; + char char_value_2 = 4; // Hand + ret = bt_gatt_characteristic_create(char_uuid, permissions, properties, + &char_value_2, sizeof(char_value_2), &characteristic); + TC_PRT("bt_gatt_characteristic_create : %s\n", __bt_get_error_message(ret)); + + ret = bt_gatt_service_add_characteristic(service, characteristic); + TC_PRT("bt_gatt_service_add_characteristic : %s\n", __bt_get_error_message(ret)); + + ret = bt_gatt_server_register_service(server, service); + TC_PRT("bt_gatt_server_register_service : %s\n", __bt_get_error_message(ret)); + + heart_rate_h.svc = service; + heart_rate_h.desc = descriptor; + + break; + } + case BT_UNIT_TEST_FUNCTION_GATT_SERVER_NOTIFY_HEART_RATE_MEASUREMENT: { + int char_value = 60 + (rand()%60); + if (!server) { + TC_PRT("bt gatt server is not created"); + break; + } + ret = bt_gatt_set_int_value(heart_rate_h.chr, BT_DATA_TYPE_UINT16, char_value, 1); + TC_PRT("bt_gatt_set_value(value : %d) : %s\n", char_value, __bt_get_error_message(ret)); + + ret = bt_gatt_server_notify(heart_rate_h.chr, false, __bt_gatt_server_notification_sent_cb, NULL); + TC_PRT("bt_gatt_server_notify : %s\n", __bt_get_error_message(ret)); + + break; + } + case BT_UNIT_TEST_FUNCTION_GATT_SERVER_REGISTER_THERMOMETER_SVC: { + bt_gatt_h service = NULL; + bt_gatt_h characteristic = NULL; + bt_gatt_h descriptor = NULL; + char *service_uuid = "1809"; // Health Thermometer Service + char *char_uuid = "2a1c"; // Temperature Measurement + char *desc_uuid = "2902"; // CCCD + char char_value[5] = {0, 0x85, 0xff, 0xff, 0xfe}; // Flag + Temperature Measurement Value (Celsius, -1.23) + char desc_value[2] = {2, 0}; // Indication enabled + int permissions = BT_GATT_PERMISSION_READ; + int properties = BT_GATT_PROPERTY_INDICATE | BT_GATT_PROPERTY_READ; // READ property added for testing + + ret = bt_gatt_server_initialize(); + TC_PRT("bt_gatt_server_initialize : %s \n", __bt_get_error_message(ret)); + + if (server == NULL) { + ret = bt_gatt_server_create(&server); + TC_PRT("bt_gatt_server_create : %s \n", __bt_get_error_message(ret)); + } + + ret = bt_gatt_service_create(service_uuid, BT_GATT_SERVICE_TYPE_PRIMARY, &service); + TC_PRT("bt_gatt_service_create : %s \n", __bt_get_error_message(ret)); + + ret = bt_gatt_characteristic_create(char_uuid, permissions, properties, + char_value, sizeof(char_value), &characteristic); + TC_PRT("bt_gatt_characteristic_create : %s\n", __bt_get_error_message(ret)); + + ret = bt_gatt_service_add_characteristic(service, characteristic); + TC_PRT("bt_gatt_service_add_characteristic : %s\n", __bt_get_error_message(ret)); + + permissions = BT_GATT_PERMISSION_READ | BT_GATT_PERMISSION_WRITE; + ret = bt_gatt_descriptor_create(desc_uuid, permissions, desc_value, sizeof(desc_value), &descriptor); + TC_PRT("bt_gatt_descriptor_create : %s\n", __bt_get_error_message(ret)); + + ret = bt_gatt_characteristic_add_descriptor(characteristic, descriptor); + TC_PRT("bt_gatt_characteristic_add_descriptor : %s\n", __bt_get_error_message(ret)); + + ret = bt_gatt_server_register_service(server, service); + TC_PRT("bt_gatt_server_register_service : %s\n", __bt_get_error_message(ret)); + + thermometer_h.chr = characteristic; + thermometer_h.svc = service; + thermometer_h.desc = descriptor; + + break; + } + case BT_UNIT_TEST_FUNCTION_GATT_SERVER_CHANGE_THERMOMETER_MEASUREMENT: { + if (!server) { + TC_PRT("bt gatt server is not created"); + break; + } + ret = bt_gatt_set_float_value(thermometer_h.chr, BT_DATA_TYPE_FLOAT, 123, -2, 1); + TC_PRT("bt_gatt_set_value(value : 1.23) : %s\n", __bt_get_error_message(ret)); + + break; + } + case BT_UNIT_TEST_FUNCTION_GATT_SERVER_REGISTER_DEVICE_INFORMATION_SVC: { + bt_gatt_h service = NULL; + bt_gatt_h characteristic = NULL; + char *service_uuid = "180a"; // Device Infromation Service + char *char_uuid = NULL; + char *char_value; + int permissions = BT_GATT_PERMISSION_READ; + int properties = BT_GATT_PROPERTY_READ; + + ret = bt_gatt_server_initialize(); + TC_PRT("bt_gatt_server_initialize : %s \n", __bt_get_error_message(ret)); + + if (server == NULL) { + ret = bt_gatt_server_create(&server); + TC_PRT("bt_gatt_server_create : %s \n", __bt_get_error_message(ret)); + } + + ret = bt_gatt_service_create(service_uuid, BT_GATT_SERVICE_TYPE_PRIMARY, &service); + TC_PRT("bt_gatt_service_create : %s \n", __bt_get_error_message(ret)); + + char_uuid = "2a29"; // Manufacturer Name String + char_value = g_strdup("Samsung"); + ret = bt_gatt_characteristic_create(char_uuid, permissions, properties, + char_value, strlen(char_value), &characteristic); + TC_PRT("bt_gatt_characteristic_create : %s\n", __bt_get_error_message(ret)); + g_free(char_value); + + ret = bt_gatt_service_add_characteristic(service, characteristic); + TC_PRT("bt_gatt_service_add_characteristic : %s\n", __bt_get_error_message(ret)); + + char_uuid = "2a24"; // Model Number String + char_value = g_strdup("TIZEN_HR 0408"); + ret = bt_gatt_characteristic_create(char_uuid, permissions, properties, + char_value, strlen(char_value), &characteristic); + TC_PRT("bt_gatt_characteristic_create : %s\n", __bt_get_error_message(ret)); + g_free(char_value); + + ret = bt_gatt_service_add_characteristic(service, characteristic); + TC_PRT("bt_gatt_service_add_characteristic : %s\n", __bt_get_error_message(ret)); + + char_uuid = "2a28"; // S/W Revision String + char_value = g_strdup("NC2"); + ret = bt_gatt_characteristic_create(char_uuid, permissions, properties, + char_value, strlen(char_value), &characteristic); + TC_PRT("bt_gatt_characteristic_create : %s\n", __bt_get_error_message(ret)); + g_free(char_value); + + ret = bt_gatt_service_add_characteristic(service, characteristic); + TC_PRT("bt_gatt_service_add_characteristic : %s\n", __bt_get_error_message(ret)); + + char_uuid = "2a26"; // Firmware Revision Name String + char_value = g_strdup("Firmware Ver 04"); + ret = bt_gatt_characteristic_create(char_uuid, permissions, properties, + char_value, strlen(char_value), &characteristic); + TC_PRT("bt_gatt_characteristic_create : %s\n", __bt_get_error_message(ret)); + g_free(char_value); + + ret = bt_gatt_service_add_characteristic(service, characteristic); + TC_PRT("bt_gatt_service_add_characteristic : %s\n", __bt_get_error_message(ret)); + + ret = bt_gatt_server_register_service(server, service); + TC_PRT("bt_gatt_server_register_service : %s\n", __bt_get_error_message(ret)); + break; + } + case BT_UNIT_TEST_FUNCTION_GATT_SERVER_REGISTER_LINK_LOSS_SVC: { + bt_gatt_h service = NULL; + bt_gatt_h characteristic = NULL; + char *service_uuid = "1803"; // Link Loss Service + char *char_uuid = "2a06"; // Alert Level + char char_value[1] = {2}; // high alert + int value_length = 1; + int permissions = BT_GATT_PERMISSION_READ; + int properties = BT_GATT_PROPERTY_READ | BT_GATT_PROPERTY_WRITE; + + ret = bt_gatt_server_initialize(); + TC_PRT("bt_gatt_server_initialize : %s \n", __bt_get_error_message(ret)); + + if (server == NULL) { + ret = bt_gatt_server_create(&server); + TC_PRT("bt_gatt_server_create : %s \n", __bt_get_error_message(ret)); + } -const char *spp_uuid = "00001101-0000-1000-8000-00805F9B34FB"; -const char *opp_uuid = "00001105-0000-1000-8000-00805f9b34fb"; + ret = bt_gatt_service_create(service_uuid, BT_GATT_SERVICE_TYPE_PRIMARY, &service); + TC_PRT("bt_gatt_service_create : %s \n", __bt_get_error_message(ret)); -static int server_fd; -static int client_fd; + ret = bt_gatt_characteristic_create(char_uuid, permissions, properties, + char_value, value_length, &characteristic); + TC_PRT("bt_gatt_characteristic_create : %s\n", __bt_get_error_message(ret)); -GMainLoop *main_loop = NULL; + ret = bt_gatt_service_add_characteristic(service, characteristic); + TC_PRT("bt_gatt_service_add_characteristic : %s\n", __bt_get_error_message(ret)); -typedef struct { - const char *tc_name; - int tc_code; -} tc_table_t; + ret = bt_gatt_server_register_service(server, service); + TC_PRT("bt_gatt_server_register_service : %s\n", __bt_get_error_message(ret)); -tc_table_t tc_table[] = { - /* Adapter functions */ - {"bt_initialize" , 1}, - {"bt_deinitialize" , 2}, - {"bt_adapter_get_state" , 3}, - {"bt_adapter_enable" , 4}, - {"bt_adapter_disable" , 5}, - {"bt_adapter_start_device_discovery" , 6}, - {"bt_adapter_stop_device_discovery" , 7}, - {"bt_adapter_is_discovering" , 8}, - {"bt_adapter_get_bonded_device_info" , 9}, - {"bt_adapter_is_service_used" , 10}, - {"bt_adapter_set_device_discovery_state_changed_cb" , 11}, - {"bt_adapter_unset_device_discovery_state_changed_cb" , 12}, + break; + } + case BT_UNIT_TEST_FUNCTION_GATT_SERVER_REGISTER_CUSTOM_SVC: { + bt_gatt_h service = NULL; + bt_gatt_h characteristic = NULL; + bt_gatt_h descriptor = NULL; + char *service_uuid = "000018f2-0000-1000-8000-00805f9b34fb"; + char *char_uuid = "00002af6-0000-1000-8000-00805f9b34fb"; + char *desc_uuid = "00002a56-0000-1000-8000-00805f9b34fb"; + char char_value[4] = {10, 20, 30, 40}; + char desc_value[4] = {12, 34, 56, 78}; + int value_length = 4; + int permissions = BT_GATT_PERMISSION_READ; + int properties = BT_GATT_PROPERTY_BROADCAST | BT_GATT_PROPERTY_READ | + BT_GATT_PROPERTY_WRITE | BT_GATT_PROPERTY_NOTIFY; - /* Socket functions */ - {"bt_socket_create_rfcomm" , 50}, - {"bt_socket_destroy_rfcomm" , 51}, - {"bt_socket_listen_and_accept_rfcomm" , 52}, - {"bt_socket_listen" , 53}, - {"bt_socket_accept" , 54}, - {"bt_socket_reject" , 55}, - {"bt_socket_connect_rfcomm" , 56}, - {"bt_socket_disconnect_rfcomm" , 57}, - {"bt_socket_send_data" , 58}, - {"bt_socket_set_data_received_cb" , 59}, - {"bt_socket_unset_data_received_cb" , 60}, - {"bt_socket_set_connection_requested_cb" , 61}, - {"bt_socket_unset_connection_requested_cb" , 62}, - {"bt_socket_set_connection_state_changed_cb" , 63}, - {"bt_socket_unset_connection_state_changed_cb" , 64}, + ret = bt_gatt_server_initialize(); + TC_PRT("bt_gatt_server_initialize : %s \n", __bt_get_error_message(ret)); - /* OPP functions */ - {"bt_opp_client_initialize" , 70}, - {"bt_opp_client_deinitialize" , 71}, - {"bt_opp_client_add_file" , 72}, - {"bt_opp_client_clear_files" , 73}, - {"bt_opp_client_push_files" , 74}, - {"bt_opp_client_cancel_push" , 75}, - - /* -----------------------------------------*/ - {"Finish" , 0x00ff}, - {NULL , 0x0000}, -}; + if (server == NULL) { + ret = bt_gatt_server_create(&server); + TC_PRT("bt_gatt_server_create : %s \n", __bt_get_error_message(ret)); + } -void tc_usage_print(void) -{ - int i = 0; + ret = bt_gatt_service_create(service_uuid, BT_GATT_SERVICE_TYPE_PRIMARY, &service); + TC_PRT("bt_gatt_service_create : %s \n", __bt_get_error_message(ret)); - while (tc_table[i].tc_name) { - if (tc_table[i].tc_code != 0x00ff) { - TC_PRT("Key %d : usage %s", tc_table[i].tc_code, - tc_table[i].tc_name); - } else { - TC_PRT("Key %d : usage %s\n\n", 0x00ff, - tc_table[i].tc_name); + ret = bt_gatt_characteristic_create(char_uuid, permissions, properties, + char_value, value_length, &characteristic); + TC_PRT("bt_gatt_characteristic_create : %s\n", __bt_get_error_message(ret)); + + ret = bt_gatt_service_add_characteristic(service, characteristic); + TC_PRT("bt_gatt_service_add_characteristic : %s\n", __bt_get_error_message(ret)); + + ret = bt_gatt_descriptor_create(desc_uuid, permissions, desc_value, value_length, &descriptor); + TC_PRT("bt_gatt_descriptor_create : %s\n", __bt_get_error_message(ret)); + + ret = bt_gatt_characteristic_add_descriptor(characteristic, descriptor); + TC_PRT("bt_gatt_characteristic_add_descriptor : %s\n", __bt_get_error_message(ret)); + + ret = bt_gatt_server_register_service(server, service); + TC_PRT("bt_gatt_server_register_service : %s\n", __bt_get_error_message(ret)); + + custom_h.svc = service; + custom_h.chr = characteristic; + custom_h.desc = descriptor; + break; } + case BT_UNIT_TEST_FUNCTION_GATT_SERVER_CHANGE_CUSTOM_VAL: { + char char_value[4] = {50, 60, 70, 80}; + if (!server) { + TC_PRT("bt gatt server is not created"); + break; + } + ret = bt_gatt_set_value(custom_h.chr, char_value, 4); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + } + case BT_UNIT_TEST_FUNCTION_ANCS_PAIR: { + bt_device_connection_link_type_e link_type = BT_DEVICE_CONNECTION_LINK_LE; - i++; - } -} + if (g_test_param.param_count > 0) { + link_type = atoi(g_test_param.params[0]); -static void __bt_adapter_device_discovery_state_changed_cb(int result, - bt_adapter_device_discovery_state_e discovery_state, - bt_adapter_device_discovery_info_s *discovery_info, - void *user_data) -{ - int i; + __bt_free_test_param(&g_test_param); + } - TC_PRT("discovery_state: %d", discovery_state); + ret = bt_device_create_bond_by_type(remote_addr, link_type); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + } + case BT_UNIT_TEST_FUNCTION_ANCS_WATCH: { + bt_gatt_h ancs_svc = NULL; + bt_gatt_h noti_source = NULL;; + char *svc_uuid = "7905F431-B5CE-4E99-A40F-4B1E122D00D0"; + char *chr_uuid = "9FBF120D-6301-42D9-8C58-25E699A21DBD"; - if (discovery_info == NULL) { - TC_PRT("No discovery_info!"); - return; - } + ret = bt_gatt_client_get_service(client, svc_uuid, &ancs_svc); + if (ret != BT_ERROR_NONE) { + TC_PRT("bt_gatt_client_get_service is failed : %d", ret); + break; + } - TC_PRT("remote_address: %s", discovery_info->remote_address); - TC_PRT("remote_name: %s", discovery_info->remote_name); - TC_PRT("rssi: %d", discovery_info->rssi); - TC_PRT("is_bonded: %d", discovery_info->is_bonded); - TC_PRT("service_count: %d", discovery_info->service_count); + ret = bt_gatt_service_get_characteristic(ancs_svc, chr_uuid, ¬i_source); + if (ret != BT_ERROR_NONE) { + TC_PRT("bt_gatt_service_get_characteristic is failed : %d", ret); + break; + } - if (discovery_info->service_uuid == NULL) { - TC_PRT("No uuids"); - return; - } + ret = bt_gatt_client_set_characteristic_value_changed_cb(noti_source, + __bt_gatt_client_value_changed_cb, NULL); + if (ret != BT_ERROR_NONE) { + TC_PRT("bt_gatt_client_set_characteristic_value_changed_cb is failed : %d", ret); + } + break; + } + case BT_UNIT_TEST_FUNCTION_ANCS_POSITIVE_ACTION: { + char value[6]; + char *noti_id = NULL; + int id; - for (i = 0; i < discovery_info->service_count; i++) { - TC_PRT("uuid: %s", discovery_info->service_uuid[i]); - } -} + if (g_test_param.param_count == 0) { + TC_PRT("Input parameters first"); + break; + } -static void __bt_socket_data_received_cb(bt_socket_received_data_s *data, void *user_data) -{ - TC_PRT("+"); + noti_id = g_test_param.params[0]; + id = atoi(noti_id); - if (data == NULL) { - TC_PRT("No recieved data!"); - return; - } + value[0] = 0x02; + memcpy(&value[1], &id, sizeof(int)); + value[5] = 0x00; - TC_PRT("Socket fd: %d", data->socket_fd); - TC_PRT("Data: %s", data->data); - TC_PRT("Size: %d", data->data_size); -} + __ancs_write_value_to_control_point(client, value, sizeof(value)); -static void __bt_socket_connection_requested_cb(int socket_fd, const char *remote_address, void *user_data) -{ - TC_PRT("Socket fd: %d", socket_fd); - TC_PRT("remote_address: %s", remote_address); -} + break; + } + case BT_UNIT_TEST_FUNCTION_ANCS_NEGATIVE_ACTION: { + char value[6]; + char *noti_id = NULL; + int id; -static void __bt_socket_connection_state_changed_cb(int result, - bt_socket_connection_state_e connection_state, - bt_socket_connection_s *connection, - void *user_data) -{ - TC_PRT("result: %d", result); - TC_PRT("connection_state: %d", connection_state); + if (g_test_param.param_count == 0) { + TC_PRT("Input parameters first"); + break; + } - if (connection == NULL) { - TC_PRT("No connection data!"); - return; - } + noti_id = g_test_param.params[0]; + id = atoi(noti_id); - TC_PRT("socket fd: %d", connection->socket_fd); - TC_PRT("role: %d", connection->local_role); - TC_PRT("remote address: %s", connection->remote_address); - TC_PRT("service_uuid: %s", connection->service_uuid); -} + value[0] = 0x02; + memcpy(&value[1], &id, sizeof(int)); + value[5] = 0x01; -void __bt_opp_client_push_responded_cb(int result, - const char *remote_address, - void *user_data) -{ - TC_PRT("result: %d", result); - TC_PRT("remote_address: %s", remote_address); -} + __ancs_write_value_to_control_point(client, value, sizeof(value)); -void __bt_opp_client_push_progress_cb(const char *file, - long long size, - int percent, - void *user_data) -{ - TC_PRT("size: %ld", (long)size); - TC_PRT("percent: %d", percent); - TC_PRT("file: %s", file); -} + break; + } + case BT_UNIT_TEST_FUNCTION_ANCS_GET_NOTI_ATTR: { + bt_gatt_h ancs_svc = NULL; + bt_gatt_h data_source = NULL;; + char *svc_uuid = "7905F431-B5CE-4E99-A40F-4B1E122D00D0"; + char *chr_uuid = "22EAC6E9-24D6-4BB5-BE44-B36ACE7C7BFB"; -void __bt_opp_client_push_finished_cb(int result, - const char *remote_address, - void *user_data) -{ - TC_PRT("result: %d", result); - TC_PRT("remote_address: %s", remote_address); -} + char value[19]; + char *noti_id = NULL; + int id; + if (g_test_param.param_count == 0) { + TC_PRT("Input parameters first"); + break; + } -int test_input_callback(void *data) -{ - int ret = 0; - int test_id = (int)data; + ret = bt_gatt_client_get_service(client, svc_uuid, &ancs_svc); + if (ret != BT_ERROR_NONE) { + TC_PRT("bt_gatt_client_get_service is failed : %d", ret); + break; + } - switch (test_id) { - case 0x00ff: - TC_PRT("Finished"); - g_main_loop_quit(main_loop); - break; + ret = bt_gatt_service_get_characteristic(ancs_svc, chr_uuid, &data_source); + if (ret != BT_ERROR_NONE) { + TC_PRT("bt_gatt_service_get_characteristic is failed : %d", ret); + break; + } - case 1: - ret = bt_initialize(); - if (ret < BT_ERROR_NONE) - TC_PRT("failed with [0x%04x]", ret); - break; - case 2: - ret = bt_deinitialize(); - if (ret < BT_ERROR_NONE) - TC_PRT("failed with [0x%04x]", ret); - break; - case 3: { - bt_adapter_state_e state = BT_ADAPTER_DISABLED; + ret = bt_gatt_client_set_characteristic_value_changed_cb(data_source, + __bt_gatt_client_value_changed_cb, NULL); + if (ret != BT_ERROR_NONE) { + TC_PRT("bt_gatt_client_set_characteristic_value_changed_cb is failed : %d", ret); + } - ret = bt_adapter_get_state(&state); - if (ret < BT_ERROR_NONE) - TC_PRT("failed with [0x%04x]", ret); + noti_id = g_test_param.params[0]; + id = atoi(noti_id); - TC_PRT("state: %d", state); - break; - } - case 4: - ret = bt_adapter_enable(); - if (ret < BT_ERROR_NONE) - TC_PRT("failed with [0x%04x]", ret); - break; - case 5: - ret = bt_adapter_disable(); - if (ret < BT_ERROR_NONE) - TC_PRT("failed with [0x%04x]", ret); - break; - case 6: - ret = bt_adapter_start_device_discovery(); - if (ret < BT_ERROR_NONE) - TC_PRT("failed with [0x%04x]", ret); - break; - case 7: - ret = bt_adapter_stop_device_discovery(); - if (ret < BT_ERROR_NONE) - TC_PRT("failed with [0x%04x]", ret); - break; - case 8: { - bool is_discovering = FALSE; - ret = bt_adapter_is_discovering(&is_discovering); - if (ret < BT_ERROR_NONE) - TC_PRT("failed with [0x%04x]", ret); - else - TC_PRT("is_discovering: %d", is_discovering); + value[0] = 0x00; + memcpy(&value[1], &id, sizeof(int)); + value[5] = 0x00; + value[6] = 0x01; + value[7] = 0xff; + value[8] = 0x00; + value[9] = 0x02; + value[10] = 0xff; + value[11] = 0x00; + value[12] = 0x03; + value[13] = 0xff; + value[14] = 0x00; + value[15] = 0x04; + value[16] = 0x05; + value[17] = 0x06; + value[18] = 0x07; - break; - } - case 9: { - char *address; - bt_device_info_s *device_info = NULL; + __ancs_write_value_to_control_point(client, value, sizeof(value)); + + break; + } +#ifdef BT_ENABLE_LEGACY_GATT_CLIENT + case BT_UNIT_TEST_FUNCTION_GATT_FOREACH_PRIMARY_SERVICES: { + __bt_free_gatt_services(); - address = g_strdup("00:19:0E:01:61:17"); + ret = bt_gatt_foreach_primary_services(remote_addr, __bt_gatt_primary_service_cb, NULL); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + if (ret == BT_ERROR_NONE) + __select_index(&selected_service_index, "Select primary service :"); + break; + } - ret = bt_adapter_get_bonded_device_info((const char *)address, - &device_info); - if (ret < BT_ERROR_NONE) - TC_PRT("failed with [0x%04x]", ret); + case BT_UNIT_TEST_FUNCTION_GATT_DISCOVER_CHARACTERISTICS: { + __bt_free_gatt_characteristics(); - g_free(address); + if (selected_service_index < 0) { + TC_PRT("Need to select primary service \n"); + break; + } - if (device_info) { - TC_PRT("address: %s", device_info->remote_address); - TC_PRT("name: %s", device_info->remote_name); + ret = bt_gatt_discover_characteristics(service_clone[selected_service_index], __bt_gatt_characteristics_discovered_cb, NULL); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + if (ret == BT_ERROR_NONE) + __select_index(&selected_char_index, "Select index :"); + break; } - bt_adapter_free_device_info(device_info); - break; - } - case 10: { - bool used = FALSE; + case BT_UNIT_TEST_FUNCTION_GATT_DISCOVER_CHARACTERISTIC_DESCRIPTORS: { + ret = bt_gatt_discover_characteristic_descriptor(characteristics[selected_char_index], + __bt_gatt_characteristic_descriptor_discovered_cb, NULL); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + } - ret = bt_adapter_is_service_used(opp_uuid, &used); - if (ret < BT_ERROR_NONE) - TC_PRT("failed with [0x%04x]", ret); + case BT_UNIT_TEST_FUNCTION_GATT_GET_SERVICE_UUID: { + char *uuid = NULL; + char *name = NULL; - TC_PRT("used: %d", used); - break; - } - case 11: - ret = bt_adapter_set_device_discovery_state_changed_cb(__bt_adapter_device_discovery_state_changed_cb, NULL); - if (ret < BT_ERROR_NONE) - TC_PRT("failed with [0x%04x]", ret); - break; - case 12: - ret = bt_adapter_unset_device_discovery_state_changed_cb(); - if (ret < BT_ERROR_NONE) - TC_PRT("failed with [0x%04x]", ret); - break; + if (selected_service_index < 0) { + TC_PRT("Need to select primary service \n"); + break; + } - /* Socket functions */ - case 50: { - int socket_fd = 0; + ret = bt_gatt_get_service_uuid(service_clone[selected_service_index], &uuid); + if (ret < BT_ERROR_NONE) { + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + } else { + bt_gatt_get_uuid_specification_name(uuid, &name); + TC_PRT("uuid: %s [%s]", uuid, name); + g_free(name); + g_free(uuid); + } + break; + } - ret = bt_socket_create_rfcomm(spp_uuid, &socket_fd); - if (ret < BT_ERROR_NONE) { - TC_PRT("failed with [0x%04x]", ret); - } else { - TC_PRT("socket_fd: %d", socket_fd); - server_fd = socket_fd; + case BT_UNIT_TEST_FUNCTION_GATT_FOREACH_INCLUDED_SERVICES: { + __bt_free_gatt_characteristics_services(); + + if (selected_service_index < 0) { + TC_PRT("Need to select primary service \n"); + break; + } + + ret = bt_gatt_foreach_included_services(service_clone[selected_service_index], __bt_gatt_included_service_cb, NULL); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + } + + case BT_UNIT_TEST_FUNCTION_GATT_SET_CHARACTERISTIC_CHANGED_CB: { + ret = bt_gatt_set_characteristic_changed_cb(__bt_gatt_characteristic_changed_cb, NULL); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + } + + case BT_UNIT_TEST_FUNCTION_GATT_UNSET_CHARACTERISTIC_CHANGED_CB: { + ret = bt_gatt_unset_characteristic_changed_cb(); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + } + + case BT_UNIT_TEST_FUNCTION_GATT_GET_CHARACTERISTIC_DECLARATION: { + int i; + char *uuid = NULL; + char *name = NULL; + unsigned char *value = NULL; + int value_length = 0; + + ret = bt_gatt_get_characteristic_declaration(characteristics_services[0], &uuid, &value, &value_length); + if (ret < BT_ERROR_NONE) { + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + } else { + bt_gatt_get_uuid_specification_name(uuid, &name); + TC_PRT("uuid: %s [%s]", uuid, name); + + for (i = 0; i < value_length; i++) { + TC_PRT("value %c", value[i]); + } + + g_free(uuid); + g_free(name); + g_free(value); + } + break; + } + + case BT_UNIT_TEST_FUNCTION_GATT_SET_CHARACTERISTIC_VALUE: { + unsigned char value[] = { 1 }; + if (selected_char_index == 0) { + TC_PRT("Need to select charateristic value \n"); + break; + } + + ret = bt_gatt_set_characteristic_value(characteristics[selected_char_index], value, 1); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + } + + case BT_UNIT_TEST_FUNCTION_GATT_SET_CHARACTERISTIC_VALUE_REQUEST: { + unsigned char value[] = { 1 }; + if (selected_char_index == 0) { + TC_PRT("Need to select charateristic value \n"); + break; + } + + ret = bt_gatt_set_characteristic_value_request(characteristics[selected_char_index], value, 1, + __bt_gatt_char_write_cb); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + } + + case BT_UNIT_TEST_FUNCTION_GATT_READ_CHARACTERISTIC_VALUE : { + if (selected_char_index == 0) { + TC_PRT("Need to select charateristic value \n"); + break; + } + + ret = bt_gatt_read_characteristic_value(characteristics[selected_char_index], __bt_gatt_char_read_cb); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + } + + case BT_UNIT_TEST_FUNCTION_GATT_WATCH_CHARACTERISTIC_CHANGES: { + if (selected_service_index < 0) { + TC_PRT("Need to select primary service \n"); + break; + } + + ret = bt_gatt_watch_characteristic_changes(service_clone[selected_service_index]); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + } + case BT_UNIT_TEST_FUNCTION_GATT_UNWATCH_CHARACTERISTIC_CHANGES: { + ret = bt_gatt_unwatch_characteristic_changes(service_clone[selected_service_index]); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + } +#endif + 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 51: - ret = bt_socket_destroy_rfcomm(server_fd); - if (ret < BT_ERROR_NONE) - TC_PRT("failed with [0x%04x]", ret); - break; - case 52: - ret = bt_socket_listen_and_accept_rfcomm(server_fd, 1); - if (ret < BT_ERROR_NONE) - TC_PRT("failed with [0x%04x]", ret); - break; - case 53: - ret = bt_socket_listen(server_fd, 1); - if (ret < BT_ERROR_NONE) - TC_PRT("failed with [0x%04x]", ret); - break; - case 54: { - int socket_fd = 0; + case BT_UNIT_TEST_TABLE_AVRCP: { + switch (test_id) { + case BT_UNIT_TEST_FUNCTION_AVRCP_TARGET_INITIALIZE: + ret = bt_avrcp_target_initialize(__bt_avrcp_target_connection_state_changed_cb, NULL); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; - ret = bt_socket_accept(server_fd, &socket_fd); - if (ret < BT_ERROR_NONE) { - TC_PRT("failed with [0x%04x]", ret); - } else { - TC_PRT("socket_fd: %d", socket_fd); - client_fd = socket_fd; + case BT_UNIT_TEST_FUNCTION_AVRCP_TARGET_DEINITIALIZE: + ret = bt_avrcp_target_deinitialize(); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + + case BT_UNIT_TEST_FUNCTION_AVRCP_SET_EQUALIZER_STATE_CHANGED_CB: + ret = bt_avrcp_set_equalizer_state_changed_cb(__bt_avrcp_equalizer_state_changed_cb, NULL); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + + case BT_UNIT_TEST_FUNCTION_AVRCP_SET_REPEAT_MODE_CHANGED_CB: + ret = bt_avrcp_set_repeat_mode_changed_cb(__bt_avrcp_repeat_mode_changed_cb, NULL); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + + case BT_UNIT_TEST_FUNCTION_AVRCP_SET_SHUFFLE_MODE_CHANGED_CB: + ret = bt_avrcp_set_shuffle_mode_changed_cb(__bt_avrcp_shuffle_mode_changed_cb, NULL); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + + case BT_UNIT_TEST_FUNCTION_AVRCP_SET_SCAN_MODE_CHANGED_CB: + ret = bt_avrcp_set_scan_mode_changed_cb(__bt_avrcp_scan_mode_changed_cb, NULL); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + + case BT_UNIT_TEST_FUNCTION_AVRCP_UNSET_EQUALIZER_STATE_CHANGED_CB: + ret = bt_avrcp_unset_equalizer_state_changed_cb(); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + + case BT_UNIT_TEST_FUNCTION_AVRCP_UNSET_REPEAT_MODE_CHANGED_CB: + ret = bt_avrcp_unset_repeat_mode_changed_cb(); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + + case BT_UNIT_TEST_FUNCTION_AVRCP_UNSET_SHUFFLE_MODE_CHANGED_CB: + ret = bt_avrcp_unset_shuffle_mode_changed_cb(); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + + case BT_UNIT_TEST_FUNCTION_AVRCP_UNSET_SCAN_MODE_CHANGED_CB: + ret = bt_avrcp_unset_scan_mode_changed_cb(); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + + case BT_UNIT_TEST_FUNCTION_AVRCP_CONTROL_INITIALIZE: + ret = bt_avrcp_control_initialize(__bt_avrcp_control_connection_state_changed_cb, NULL); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + + case BT_UNIT_TEST_FUNCTION_AVRCP_CONTROL_DEINITIALIZE: + ret = bt_avrcp_control_deinitialize(); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + + case BT_UNIT_TEST_FUNCTION_AVRCP_CONTROL_CONNECT: + ret = bt_avrcp_control_connect(remote_addr); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + + case BT_UNIT_TEST_FUNCTION_AVRCP_CONTROL_DISCONNECT: + ret = bt_avrcp_control_disconnect(remote_addr); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + + case BT_UNIT_TEST_FUNCTION_AVRCP_CONTROL_PLAY: + ret = bt_avrcp_control_send_player_command(BT_AVRCP_CONTROL_PLAY); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + + case BT_UNIT_TEST_FUNCTION_AVRCP_CONTROL_STOP: + ret = bt_avrcp_control_send_player_command(BT_AVRCP_CONTROL_STOP); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + + case BT_UNIT_TEST_FUNCTION_AVRCP_CONTROL_PAUSE: + ret = bt_avrcp_control_send_player_command(BT_AVRCP_CONTROL_PAUSE); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + + case BT_UNIT_TEST_FUNCTION_AVRCP_CONTROL_FF: + ret = bt_avrcp_control_send_player_command(BT_AVRCP_CONTROL_FAST_FORWARD); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + + case BT_UNIT_TEST_FUNCTION_AVRCP_CONTROL_RW: + ret = bt_avrcp_control_send_player_command(BT_AVRCP_CONTROL_REWIND); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + + case BT_UNIT_TEST_FUNCTION_AVRCP_CONTROL_NEXT: + ret = bt_avrcp_control_send_player_command(BT_AVRCP_CONTROL_NEXT); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + + case BT_UNIT_TEST_FUNCTION_AVRCP_CONTROL_PREV: { + ret = bt_avrcp_control_send_player_command(BT_AVRCP_CONTROL_PREVIOUS); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + } + + case BT_UNIT_TEST_FUNCTION_AVRCP_CONTROL_GET_REPEAT: { + bt_avrcp_repeat_mode_e mode = BT_AVRCP_REPEAT_MODE_GROUP; + ret = bt_avrcp_control_get_repeat_mode(&mode); + TC_PRT("Repet mode : %d returns %s\n", mode, __bt_get_error_message(ret)); + break; + } + + case BT_UNIT_TEST_FUNCTION_AVRCP_CONTROL_SET_REPEAT: { + ret = bt_avrcp_control_set_repeat_mode(2); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + } + + case BT_UNIT_TEST_FUNCTION_AVRCP_CONTROL_GET_SHUFFLE: { + bt_avrcp_shuffle_mode_e mode = BT_AVRCP_SHUFFLE_MODE_ALL_TRACK; + ret = bt_avrcp_control_get_shuffle_mode(&mode); + TC_PRT("Shuffle mode %d returns %s\n", mode, __bt_get_error_message(ret)); + break; + } + + case BT_UNIT_TEST_FUNCTION_AVRCP_CONTROL_SET_SHUFFLE: { + ret = bt_avrcp_control_set_shuffle_mode(1); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + } + + case BT_UNIT_TEST_FUNCTION_AVRCP_CONTROL_GET_POSITION: { + unsigned int position = 0; + ret = bt_avrcp_control_get_position(&position); + TC_PRT("position %d returns %s\n", position, __bt_get_error_message(ret)); + break; + } + + case BT_UNIT_TEST_FUNCTION_AVRCP_CONTROL_GET_PLAY_STATUS: { + unsigned int status = 0; + ret = bt_avrcp_control_get_play_status(&status); + TC_PRT("status %d returns %s\n", status, __bt_get_error_message(ret)); + break; + } + + case BT_UNIT_TEST_FUNCTION_AVRCP_CONTROL_GET_TRACK_INFO: { + bt_avrcp_metadata_attributes_info_s *track; + ret = bt_avrcp_control_get_track_info(&track); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + if (ret == BT_ERROR_NONE) { + TC_PRT("Title. %s\n", track->title); + TC_PRT("Artist %s\n", track->artist); + TC_PRT("Album %s\n", track->album); + TC_PRT("Genre %s\n", track->genre); + TC_PRT("Total tracks %d\n", track->total_tracks); + TC_PRT("Number %d\n", track->number); + TC_PRT("Duration %d\n", track->duration); + bt_avrcp_control_free_track_info(track); + } + break; + } + + case BT_UNIT_TEST_FUNCTION_AVRCP_SET_SONG_POSITION_CHANGED_CB: + ret = bt_avrcp_set_song_position_changed_cb(__bt_avrcp_song_position_changed_cb, NULL); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + + case BT_UNIT_TEST_FUNCTION_AVRCP_SET_PLAY_STATE_CHANGED_CB: + ret = bt_avrcp_set_play_status_changed_cb(__bt_avrcp_player_state_changed_cb, NULL); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + + case BT_UNIT_TEST_FUNCTION_AVRCP_SET_TRACK_INFO_CHANGED_CB: + ret = bt_avrcp_set_track_info_changed_cb(__bt_avrcp_track_info_changed_cb, NULL); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + + case BT_UNIT_TEST_FUNCTION_AVRCP_UNSET_SONG_POSITION_CHANGED_CB: + ret = bt_avrcp_unset_song_position_changed_cb(); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + + case BT_UNIT_TEST_FUNCTION_AVRCP_UNSET_PLAY_STATE_CHANGED_CB: + ret = bt_avrcp_unset_play_status_changed_cb(); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + + case BT_UNIT_TEST_FUNCTION_AVRCP_UNSET_TRACK_INFO_CHANGED_CB: + ret = bt_avrcp_unset_track_info_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 55: - ret = bt_socket_reject(server_fd); - if (ret < BT_ERROR_NONE) { - TC_PRT("failed with [0x%04x]", ret); + case BT_UNIT_TEST_TABLE_HID: { + switch (test_id) { + case BT_UNIT_TEST_FUNCTION_HID_HOST_INITIALIZE: + ret = bt_hid_host_initialize(__bt_hid_host_connection_state_changed_cb, + NULL); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + case BT_UNIT_TEST_FUNCTION_HID_HOST_DEINITIALIZE: + ret = bt_hid_host_deinitialize(); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + case BT_UNIT_TEST_FUNCTION_HID_HOST_CONNECT: { + ret = bt_hid_host_connect(remote_addr); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + } + case BT_UNIT_TEST_FUNCTION_HID_HOST_DISCONNECT: { + ret = bt_hid_host_disconnect(remote_addr); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; } - break; - case 56: { - char *address; - address = g_strdup("00:02:48:F4:3E:D2"); + case BT_UNIT_TEST_FUNCTION_ACTIVATE_FLAG_TO_SET_PARAMETERS: + need_to_set_params = true; + TC_PRT("Select the function again"); + break; - ret = bt_socket_connect_rfcomm(address, spp_uuid); - if (ret < BT_ERROR_NONE) { - TC_PRT("failed with [0x%04x]", ret); + default: + break; } - g_free(address); break; } - case 57: - ret = bt_socket_disconnect_rfcomm(client_fd); - if (ret < BT_ERROR_NONE) { - TC_PRT("failed with [0x%04x]", ret); +#ifdef TIZEN_WEARABLE + case BT_UNIT_TEST_TABLE_HF: { + switch (test_id) { + case BT_UNIT_TEST_FUNCTION_HF_INITIALIZE: + ret = bt_hf_initialize(); + 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_HF_DEINITIALIZE: + ret = bt_hf_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_HF_NOTIFY_CALL_ANSWER: + ret = bt_hf_notify_call_event(BT_HF_CALL_EVENT_ANSWER, "9663868998"); + 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_HF_NOTIFY_SPEAKER_GAIN: + ret = bt_hf_notify_speaker_gain(10); + 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_HF_SET_SPEAKER_GAIN_CB: + ret = bt_hf_set_speaker_gain_changed_cb(__bt_hf_speaker_gain_changed_cb, NULL); + 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_HF_UNSET_SPEAKER_GAIN_CB: + ret = bt_hf_unset_speaker_gain_changed_cb(); + 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_HF_NOTIFY_VOICE_REC_TRUE: + ret = bt_hf_notify_voice_recognition_state(true); + 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_HF_NOTIFY_CALL_TERM: + ret = bt_hf_notify_call_event(BT_HF_CALL_EVENT_IDLE, "9663868998"); + 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_HF_NOTIFY_CALL_INIT: + ret = bt_hf_notify_call_event(BT_HF_CALL_EVENT_DIAL, "9663868998"); + 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_HF_NOTIFY_VOICE_REC_FALSE: + ret = bt_hf_notify_voice_recognition_state(false); + 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_HF_IS_SCO_OPENED: { + bool is_opened = false; + ret = bt_hf_is_sco_opened(&is_opened); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + TC_PRT("Sco is opened [%s]", is_opened ? "YES" : "NO"); + break; } - break; - case 58: - ret = bt_socket_send_data(client_fd, "Sending test\0", 20); - if (ret < BT_ERROR_NONE) { - TC_PRT("failed with [0x%04x]", ret); + case BT_UNIT_TEST_FUNCTION_HF_GET_CODEC_ID: { + unsigned int codec_id = 0; + ret = bt_hf_get_codec_id(&codec_id); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + TC_PRT("Codec ID [%d]", codec_id); + break; } - break; - case 59: - ret = bt_socket_set_data_received_cb(__bt_socket_data_received_cb, NULL); - if (ret < BT_ERROR_NONE) { - TC_PRT("failed with [0x%04x]", ret); + case BT_UNIT_TEST_FUNCTION_HF_GET_CALL_STATUS_INFO_LIST: { + GSList *list; + ret = bt_hf_get_call_status_info_list(&list); + + if (ret < BT_ERROR_NONE) { + TC_PRT("failed with [0x%04x]", ret); + } else { + for (; list; list = g_slist_next(list)) { + bt_hf_call_status_info_s *call_info = list->data; + TC_PRT("Call info [No:%s, Dir:%d, Stat:%d, Mpt:%d, Idx:%d]", + call_info->number, call_info->direction, call_info->status, call_info->multi_party, call_info->index); + } + bt_hf_free_call_status_info_list(list); + } + break; } - break; - case 60: - ret = bt_socket_unset_data_received_cb(); - if (ret < BT_ERROR_NONE) { - TC_PRT("failed with [0x%04x]", ret); + case BT_UNIT_TEST_FUNCTION_HF_SET_SCO_CHANGED_CB: + ret = bt_hf_set_sco_state_changed_cb( + __bt_hf_sco_state_changed_cb, NULL); + 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_HF_UNSET_SCO_CHANGED_CB: + ret = bt_hf_unset_sco_state_changed_cb(); + 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_HF_SET_CALL_EVENT_CB: + ret = bt_hf_set_call_handling_event_cb(__bt_hf_set_call_handling_event_cb, NULL); + 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_HF_UNSET_CALL_EVENT_CB: + ret = bt_hf_unset_call_handling_event_cb(); + 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_HF_SET_CALL_STATUS_UPDATED_EVENT_CB: + ret = bt_hf_set_call_status_updated_event_cb(__bt_hf_call_status_updated_event_cb, NULL); + 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_HF_UNSET_CALL_STATUS_UPDATED_EVENT_CB: + ret = bt_hf_unset_call_status_updated_event_cb(); + 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_ACTIVATE_FLAG_TO_SET_PARAMETERS: + need_to_set_params = true; + TC_PRT("Select the function again"); + break; + + default: + break; } + break; - case 61: - ret = bt_socket_set_connection_requested_cb(__bt_socket_connection_requested_cb, NULL); - if (ret < BT_ERROR_NONE) { - TC_PRT("failed with [0x%04x]", ret); + } + case BT_UNIT_TEST_TABLE_PBAP_CLIENT: { + switch (test_id) { + + /*PBAP Test Cases */ + case BT_UNIT_TEST_FUNCTION_PBAP_CLIENT_INITIALIZE: + ret = bt_pbap_init(); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + case BT_UNIT_TEST_FUNCTION_PBAP_CLIENT_DEINITIALIZE: + ret = bt_pbap_deinit(); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + case BT_UNIT_TEST_FUNCTION_PBAP_CLIENT_CONNECT: { + ret = bt_pbap_connect(remote_addr, __bt_pbap_enabled_cb, NULL); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; } - break; - case 62: - ret = bt_socket_unset_connection_requested_cb(); - if (ret < BT_ERROR_NONE) { - TC_PRT("failed with [0x%04x]", ret); + case BT_UNIT_TEST_FUNCTION_PBAP_CLIENT_DISCONNECT: { + ret = bt_pbap_disconnect(remote_addr, __bt_pbap_enabled_cb, NULL); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; } - break; - case 63: - ret = bt_socket_set_connection_state_changed_cb(__bt_socket_connection_state_changed_cb, NULL); - if (ret < BT_ERROR_NONE) { - TC_PRT("failed with [0x%04x]", ret); + case BT_UNIT_TEST_FUNCTION_PBAP_CLIENT_GETSIZE: { + ret = bt_pbap_get_phonebook_size(remote_addr, 0, 0, __bt_pbap_phonebook_size_cb, NULL); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; } - break; - case 64: - ret = bt_socket_unset_connection_state_changed_cb(); - if (ret < BT_ERROR_NONE) { - TC_PRT("failed with [0x%04x]", ret); + case BT_UNIT_TEST_FUNCTION_PBAP_CLIENT_PHONEBOOKPULL: { + long long unsigned fields = BT_PBAP_FIELD_PHOTO | BT_PBAP_FIELD_EMAIL | BT_PBAP_FIELD_ORG; + ret = bt_pbap_get_phonebook(remote_addr, 0, 0, 0, 0, 0, 100, + fields, __bt_pbap_phonebook_pull_cb, NULL); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; } - break; - case 70: - ret = bt_opp_client_initialize(); - if (ret < BT_ERROR_NONE) { - TC_PRT("failed with [0x%04x]", ret); + case BT_UNIT_TEST_FUNCTION_PBAP_CLIENT_VCARDLIST: { + ret = bt_pbap_get_list(remote_addr, 0, 0, 0, 0, 100, + __bt_pbap_vcard_list_cb, NULL); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; } - break; - case 71: - ret = bt_opp_client_deinitialize(); - if (ret < BT_ERROR_NONE) { - TC_PRT("failed with [0x%04x]", ret); + case BT_UNIT_TEST_FUNCTION_PBAP_CLIENT_VCARDPULL: { + long long unsigned fields = BT_PBAP_FIELD_PHOTO | BT_PBAP_FIELD_EMAIL | BT_PBAP_FIELD_ORG; + ret = bt_pbap_pull_vcard(remote_addr, 0, 0, 0, 0, fields, + __bt_pbap_phonebook_pull_cb, NULL); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; } - break; - case 72: - ret = bt_opp_client_add_file("/opt/media/Images/image1.jpg"); - if (ret < BT_ERROR_NONE) { - TC_PRT("failed with [0x%04x]", ret); + case BT_UNIT_TEST_FUNCTION_PBAP_CLIENT_PHONEBOOKSEARCH: { + ret = bt_pbap_phonebook_search(remote_addr, 0, 0, + 0, "abc", + 0, 0, 100, + __bt_pbap_vcard_list_cb, NULL); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; } - break; - case 73: - ret = bt_opp_client_clear_files(); - if (ret < BT_ERROR_NONE) { - TC_PRT("failed with [0x%04x]", ret); + case BT_UNIT_TEST_FUNCTION_PBAP_CLIENT_VCARDLIST_MAXLIST_ZERO: { + ret = bt_pbap_get_list(remote_addr, 0, 0, 0, 0, 0, + __bt_pbap_vcard_list_cb, NULL); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; } - break; - case 74: { - char *address; - address = g_strdup("00:02:37:A9:17:9E"); + case BT_UNIT_TEST_FUNCTION_ACTIVATE_FLAG_TO_SET_PARAMETERS: + need_to_set_params = true; + TC_PRT("Select the function again"); + break; - ret = bt_opp_client_push_files(address,__bt_opp_client_push_responded_cb, - __bt_opp_client_push_progress_cb, - __bt_opp_client_push_finished_cb, - NULL); - if (ret < BT_ERROR_NONE) { - TC_PRT("failed with [0x%04x]", ret); + default: + break; } + break; } - case 75: - ret = bt_opp_client_cancel_push(); - if (ret < BT_ERROR_NONE) { - TC_PRT("failed with [0x%04x]", ret); +#endif + case BT_UNIT_TEST_TABLE_AUTOMATED_TEST: { + static unsigned int delay = 0; + bt_onoff_cnt = 0; + bt_onoff_cnt_success = 0; + bt_onoff_cnt_fail = 0; + bt_onoff_timer = time(NULL); + + if (input_automated_test_delay == true) { + delay = test_id; + test_id = BT_UNIT_TEST_FUNCTION_ON_OFF_REPEAT_TEST_N_SEC_DELAY; } - break; + switch (test_id) { + /*Automated Test Cases */ + case BT_UNIT_TEST_FUNCTION_ON_OFF_REPEAT_TEST: { + bt_adapter_state_e state = BT_ADAPTER_DISABLED; + delay = 0; + + ret = bt_adapter_set_state_changed_cb(__bt_repeat_test_adapter_state_changed_cb, &delay); + TC_PRT("set_cb returns %s\n", __bt_get_error_message(ret)); + + ret = bt_adapter_get_state(&state); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + TC_PRT("Current state: %d", state); + + if (state == BT_ADAPTER_DISABLED) + bt_adapter_enable(); + else + bt_adapter_disable(); + break; + } + case BT_UNIT_TEST_FUNCTION_ON_OFF_REPEAT_TEST_1_SEC_DELAY: { + bt_adapter_state_e state = BT_ADAPTER_DISABLED; + delay = 1; + + ret = bt_adapter_set_state_changed_cb(__bt_repeat_test_adapter_state_changed_cb, &delay); + TC_PRT("set_cb returns %s\n", __bt_get_error_message(ret)); + + ret = bt_adapter_get_state(&state); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + TC_PRT("Current state: %d", state); + + if (state == BT_ADAPTER_DISABLED) + bt_adapter_enable(); + else + bt_adapter_disable(); + break; + } + case BT_UNIT_TEST_FUNCTION_ON_OFF_REPEAT_TEST_N_SEC_DELAY: { + bt_adapter_state_e state = BT_ADAPTER_DISABLED; + + input_automated_test_delay = false; + + ret = bt_adapter_set_state_changed_cb(__bt_repeat_test_adapter_state_changed_cb, &delay); + TC_PRT("set_cb returns %s\n", __bt_get_error_message(ret)); + + ret = bt_adapter_get_state(&state); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + TC_PRT("Current state: %d", state); + + if (state == BT_ADAPTER_DISABLED) + bt_adapter_enable(); + else + bt_adapter_disable(); + break; + } + default: + break; + } + + break; + } default: break; } @@ -478,31 +5382,81 @@ static gboolean key_event_cb(GIOChannel *chan, unsigned int len = 0; int test_id; + bool is_call_api = false; + + if (is_sub_index) + return TRUE; memset(buf, 0, sizeof(buf)); - if(g_io_channel_read_chars(chan, buf, sizeof(buf), + if (g_io_channel_read_chars(chan, buf, sizeof(buf), &len, NULL) == G_IO_STATUS_ERROR) { TC_PRT("IO Channel read error"); return FALSE; } - TC_PRT("%s", buf); - tc_usage_print(); + if (need_to_set_params == true) { + if (g_test_id == -1) { + test_id = atoi(buf); + g_test_id = test_id; + } + test_set_params(g_test_id, buf); + return TRUE; + } else { + TC_PRT("%s", buf); + test_id = atoi(buf); + + g_test_id = -1; + need_to_set_params = false; + } + + if (current_tc_table == BT_UNIT_TEST_TABLE_MAIN) { + if (buf[0] == '0' && buf[2] == 0) + current_tc_table = BT_UNIT_TEST_TABLE_SET_ADDRESS; + else if(test_id >= BT_UNIT_TEST_TABLE_ADAPTER && test_id < BT_UNIT_TEST_TABLE_FINISH) + current_tc_table = test_id; + else + is_call_api = true; + } else { + if (buf[0] == '0' && buf[2] == 0) { + current_tc_table = BT_UNIT_TEST_TABLE_MAIN; + } else if (current_tc_table == BT_UNIT_TEST_TABLE_AUTOMATED_TEST + && test_id == BT_UNIT_TEST_FUNCTION_ON_OFF_REPEAT_TEST_N_SEC_DELAY + && input_automated_test_delay == false) { + input_automated_test_delay = true; + } else { + is_call_api = true; + } + } - test_id = atoi(buf); + tc_usage_print(); - if(test_id) + if (current_tc_table == BT_UNIT_TEST_TABLE_SET_ADDRESS && is_call_api == true) { + memcpy (remote_addr, buf, 17); + remote_addr[17] = 0; + } else if (test_id && is_call_api) g_idle_add(test_input_callback, (void *)test_id); return TRUE; } +void sig_handler(int signo) +{ + if (signo == SIGINT) { + if (bt_onoff_cnt > 0) + __bt_repeat_test_onoff_count_time_summary(); + + bt_deinitialize(); + exit(0); + } +} + int main() { GIOChannel *key_io; - g_type_init(); +// g_type_init(); + current_tc_table = BT_UNIT_TEST_TABLE_MAIN; key_io = g_io_channel_unix_new(fileno(stdin)); @@ -516,10 +5470,12 @@ int main() main_loop = g_main_loop_new(NULL, FALSE); + if (signal(SIGINT, sig_handler) == SIG_ERR) + TC_PRT("\n can't catch SIGINT\n"); + g_main_loop_run(main_loop); bt_deinitialize(); return 0; } - diff --git a/test/bt_unit_test.h b/test/bt_unit_test.h new file mode 100644 index 0000000..cc02183 --- /dev/null +++ b/test/bt_unit_test.h @@ -0,0 +1,354 @@ +/* + * + * Copyright (c) 2000 - 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 __TIZEN_NETWORK_BLUETOOTH_UNIT_TEST_H__ +#define __TIZEN_NETWORK_BLUETOOTH_UNIT_TEST_H__ + + +#ifdef __cplusplus +extern "C" { +#endif + +#define BUFFER_LEN 49 +#define MAX_SERVICES 10 +#define PRT(format, args...) printf("%s:%d() "format, __FUNCTION__, __LINE__, ##args) +#define TC_PRT(format, args...) PRT(format"\n", ##args) + +typedef enum +{ + BT_UNIT_TEST_TABLE_MAIN = 1, + BT_UNIT_TEST_TABLE_SET_ADDRESS, + BT_UNIT_TEST_TABLE_ADAPTER, + BT_UNIT_TEST_TABLE_ADAPTER_LE, + BT_UNIT_TEST_TABLE_DEVICE, + BT_UNIT_TEST_TABLE_SOCKET, + BT_UNIT_TEST_TABLE_OPP, + BT_UNIT_TEST_TABLE_AUDIO, + BT_UNIT_TEST_TABLE_PAN, + BT_UNIT_TEST_TABLE_GATT, + BT_UNIT_TEST_TABLE_AVRCP, + BT_UNIT_TEST_TABLE_HID, +#ifdef TIZEN_WEARABLE + BT_UNIT_TEST_TABLE_HF, + BT_UNIT_TEST_TABLE_PBAP_CLIENT, +#endif + BT_UNIT_TEST_TABLE_AUTOMATED_TEST, + BT_UNIT_TEST_FUNCTION_INITIALIZE_ALL, + BT_UNIT_TEST_TABLE_FINISH = 0xFF, +} bt_unit_test_table_e; + +typedef enum +{ + BT_UNIT_TEST_FUNCTION_BACK = 0, + BT_UNIT_TEST_FUNCTION_SET_ADDRESS = 0, + BT_UNIT_TEST_FUNCTION_INITIALIZE = 1, + BT_UNIT_TEST_FUNCTION_DEINITIALIZE, + BT_UNIT_TEST_FUNCTION_ADAPTER_GET_STATE = 1, + BT_UNIT_TEST_FUNCTION_ADAPTER_ENABLE, + BT_UNIT_TEST_FUNCTION_ADAPTER_DISABLE, + BT_UNIT_TEST_FUNCTION_ADAPTER_RECOVER, + BT_UNIT_TEST_FUNCTION_ADAPTER_START_DEVICE_DISCOVERY, + BT_UNIT_TEST_FUNCTION_ADAPTER_STOP_DEVICE_DISCOVERY, + BT_UNIT_TEST_FUNCTION_ADAPTER_IS_DISCOVERING, + BT_UNIT_TEST_FUNCTION_ADAPTER_FOREACH_BONDED_DEVICE, + BT_UNIT_TEST_FUNCTION_ADAPTER_GET_BONDED_DEVICE_INFO, + BT_UNIT_TEST_FUNCTION_ADAPTER_IS_SERVICE_USED, + BT_UNIT_TEST_FUNCTION_ADAPTER_GET_VISIBILITY, + BT_UNIT_TEST_FUNCTION_ADAPTER_SET_DEVICE_DISCOVERY_STATE_CHANGED_CB, + BT_UNIT_TEST_FUNCTION_ADAPTER_UNSET_DEVICE_DISCOVERY_STATE_CHANGED_CB, + BT_UNIT_TEST_FUNCTION_ADAPTER_GET_LOCAL_OOB_DATA, + BT_UNIT_TEST_FUNCTION_ADAPTER_SET_LOCAL_OOB_DATA, + BT_UNIT_TEST_FUNCTION_ADAPTER_REMOVE_REMOTE_OOB_DATA, + BT_UNIT_TEST_FUNCTION_ADAPTER_SET_VISIBILITY_MODE_CHANGED_CB, + BT_UNIT_TEST_FUNCTION_ADAPTER_UNSET_VISIBILITY_MODE_CHANGED_CB, + BT_UNIT_TEST_FUNCTION_ADAPTER_SET_VISIBILITY_DURATION_CHANGED_CB, + BT_UNIT_TEST_FUNCTION_ADAPTER_UNSET_VISIBILITY_DURATION_CHANGED_CB, + BT_UNIT_TEST_FUNCTION_ADAPTER_SET_CONNECTABLE_CHANGED_CB, + BT_UNIT_TEST_FUNCTION_ADAPTER_UNSET_CONNECTABLE_CHANGED_CB, + BT_UNIT_TEST_FUNCTION_ADAPTER_GET_CONNECTABLE, + BT_UNIT_TEST_FUNCTION_ADAPTER_SET_CONNECTABLE, + BT_UNIT_TEST_FUNCTION_ADAPTER_GET_VERSION, + BT_UNIT_TEST_FUNCTION_ADAPTER_GET_LOCAL_INFO, + BT_UNIT_TEST_FUNCTION_ADAPTER_SET_MANUFACTURER_DATA_CHANGED_CB, + BT_UNIT_TEST_FUNCTION_ADAPTER_UNSET_MANUFACTURER_DATA_CHANGED_CB, + BT_UNIT_TEST_FUNCTION_ADAPTER_SET_MANUFACTURER_DATA, + BT_UNIT_TEST_FUNCTION_ADAPTER_LE_GET_STATE = 1, + BT_UNIT_TEST_FUNCTION_ADAPTER_LE_ENABLE, + BT_UNIT_TEST_FUNCTION_ADAPTER_LE_DISABLE, + BT_UNIT_TEST_FUNCTION_ADAPTER_LE_SET_SCAN_MODE, + BT_UNIT_TEST_FUNCTION_ADAPTER_LE_START_SCAN, + BT_UNIT_TEST_FUNCTION_ADAPTER_LE_STOP_SCAN, +#ifndef TIZEN_WEARABLE + BT_UNIT_TEST_FUNCTION_ADAPTER_LE_START_DEVICE_DISCOVERY, + BT_UNIT_TEST_FUNCTION_ADAPTER_LE_STOP_DEVICE_DISCOVERY, +#endif + BT_UNIT_TEST_FUNCTION_ADAPTER_LE_ADD_ADVERTISING_DATA, + BT_UNIT_TEST_FUNCTION_ADAPTER_LE_SET_ADVERTISING_MODE, + BT_UNIT_TEST_FUNCTION_ADAPTER_LE_SET_ADVERTISING_FILTER_POLICY, + BT_UNIT_TEST_FUNCTION_ADAPTER_LE_SET_ADVERTISING_CONNECTABLE, + BT_UNIT_TEST_FUNCTION_ADAPTER_LE_START_ADVERTISING_NEW, +#ifndef TIZEN_WEARABLE + BT_UNIT_TEST_FUNCTION_ADAPTER_LE_START_ADVERTISING, +#endif + BT_UNIT_TEST_FUNCTION_ADAPTER_LE_STOP_ADVERTISING, + BT_UNIT_TEST_FUNCTION_ADAPTER_LE_ADD_WHITE_LIST, + BT_UNIT_TEST_FUNCTION_ADAPTER_LE_REMOVE_WHITE_LIST, +#ifndef TIZEN_WEARABLE + BT_UNIT_TEST_FUNCTION_ADAPTER_LE_CLEAR_WHITE_LIST, +#endif + BT_UNIT_TEST_FUNCTION_ADAPTER_LE_ENABLE_PRIVACY, + BT_UNIT_TEST_FUNCTION_ADAPTER_LE_REGISTER_SCAN_FILTER_DEVICE_ADDRESS, + BT_UNIT_TEST_FUNCTION_ADAPTER_LE_REGISTER_SCAN_FILTER_SERVICE_UUID, + BT_UNIT_TEST_FUNCTION_ADAPTER_LE_REGISTER_SCAN_FILTER_SERVICE_SOLICITATION_UUID, + BT_UNIT_TEST_FUNCTION_ADAPTER_LE_UNREGISTER_ALL_SCAN_FILTERS, +#ifndef TIZEN_WEARABLE + BT_UNIT_TEST_FUNCTION_ADAPTER_LE_SET_DEVICE_DISCOVERY_STATE_CHANGED_CB, + BT_UNIT_TEST_FUNCTION_ADAPTER_LE_UNSET_DEVICE_DISCOVERY_STATE_CHANGED_CB, +#endif + BT_UNIT_TEST_FUNCTION_DEVICE_SET_AUTHORIZATION_TRUE = 1, + BT_UNIT_TEST_FUNCTION_DEVICE_SET_AUTHORIZATION_FALSE, + BT_UNIT_TEST_FUNCTION_DEVICE_SET_AUTHORIZATION_CHANGED_CB, + BT_UNIT_TEST_FUNCTION_DEVICE_UNSET_AUTHORIZATION_CHANGED_CB, + BT_UNIT_TEST_FUNCTION_DEVICE_SET_CONNECTION_STAET_CHANGED_CB, + BT_UNIT_TEST_FUNCTION_DEVICE_UNSET_CONNECTION_STAET_CHANGED_CB, + BT_UNIT_TEST_FUNCTION_DEVICE_FOREACH_CONNECTED_PROFILES, + BT_UNIT_TEST_FUNCTION_DEVICE_IS_PROFILE_CONNECTED, + BT_UNIT_TEST_FUNCTION_DEVICE_SET_BOND_CREATED_CB, + BT_UNIT_TEST_FUNCTION_DEVICE_SET_BOND_DESTROYED_CB, + BT_UNIT_TEST_FUNCTION_DEVICE_CREATE_BOND, + BT_UNIT_TEST_FUNCTION_DEVICE_CREATE_BOND_BY_TYPE, + BT_UNIT_TEST_FUNCTION_DEVICE_DESTROY_BOND, + BT_UNIT_TEST_FUNCTION_DEVICE_ENABLE_RSSI_MONITOR, + BT_UNIT_TEST_FUNCTION_DEVICE_DISABLE_RSSI_MONITOR, + BT_UNIT_TEST_FUNCTION_DEVICE_GET_RSSI_STRENGTH, + BT_UNIT_TEST_FUNCTION_DEVICE_GET_CONNECTION_STATE, + BT_UNIT_TEST_FUNCTION_SOCKET_CREATE_RFCOMM = 1, + BT_UNIT_TEST_FUNCTION_SOCKET_DESTROY_RFCOMM, + BT_UNIT_TEST_FUNCTION_SOCKET_LISTEN_AND_ACCEPT_RFCOMM, + BT_UNIT_TEST_FUNCTION_SOCKET_LISTEN, + BT_UNIT_TEST_FUNCTION_SOCKET_ACCEPT, + BT_UNIT_TEST_FUNCTION_SOCKET_REJECT, + BT_UNIT_TEST_FUNCTION_SOCKET_CONNECT_RFCOMM, + BT_UNIT_TEST_FUNCTION_SOCKET_DISCONNECT_RFCOMM, + BT_UNIT_TEST_FUNCTION_SOCKET_SEND_DATA, + BT_UNIT_TEST_FUNCTION_SOCKET_CREATE_RFCOMM_CUSTOM_UUID, + BT_UNIT_TEST_FUNCTION_SOCKET_DESTROY_RFCOMM_CUSTOM_UUID, + BT_UNIT_TEST_FUNCTION_SOCKET_LISTEN_AND_ACCEPT_RFCOMM_CUSTOM_UUID, + BT_UNIT_TEST_FUNCTION_SOCKET_CONNECT_RFCOMM_CUSTOM_UUID, + BT_UNIT_TEST_FUNCTION_SOCKET_DISCONNECT_RFCOMM_CUSTOM_UUID, + BT_UNIT_TEST_FUNCTION_SOCKET_SEND_DATA_CUSTOM_UUID, + BT_UNIT_TEST_FUNCTION_SOCKET_SET_DATA_RECEIVED_CB, + BT_UNIT_TEST_FUNCTION_SOCKET_UNSET_DATA_RECEIVED_CB, + BT_UNIT_TEST_FUNCTION_SOCKET_SET_CONNECTION_REQUESTED_CB, + BT_UNIT_TEST_FUNCTION_SOCKET_UNSET_CONNECTION_REQUESTED_CB, + BT_UNIT_TEST_FUNCTION_SOCKET_SET_CONNECTION_STATE_CHANGED_CB, + BT_UNIT_TEST_FUNCTION_SOCKET_UNSET_CONNECTION_STATE_CHANGED_CB, + BT_UNIT_TEST_FUNCTION_OPP_CLIENT_INITIALIZE = 1, + BT_UNIT_TEST_FUNCTION_OPP_CLIENT_DEINITIALIZE, + BT_UNIT_TEST_FUNCTION_OPP_CLIENT_ADD_FILE, + BT_UNIT_TEST_FUNCTION_OPP_CLIENT_CLEAR_FILES, + BT_UNIT_TEST_FUNCTION_OPP_CLIENT_PUSH_FILES, + BT_UNIT_TEST_FUNCTION_OPP_CLIENT_CANCEL_PUSH, + BT_UNIT_TEST_FUNCTION_AUDIO_INITIALIZE = 1, + BT_UNIT_TEST_FUNCTION_AUDIO_DEINITIALIZE, + BT_UNIT_TEST_FUNCTION_AUDIO_CONNECT, + BT_UNIT_TEST_FUNCTION_AUDIO_DISCONNECT, + BT_UNIT_TEST_FUNCTION_AUDIO_SOURCE_CONNECT, + BT_UNIT_TEST_FUNCTION_AUDIO_SOURCE_DISCONNECT, + BT_UNIT_TEST_FUNCTION_AUDIO_SET_CONNECTION_STATE_CHANGED_CB, + BT_UNIT_TEST_FUNCTION_AUDIO_UNSET_CONNECTION_STATE_CHANGED_CB, + BT_UNIT_TEST_FUNCTION_A2DP_AUDIO_SET_CONNECTION_STATE_CB, + BT_UNIT_TEST_FUNCTION_A2DP_AUDIO_UNSET_CONNECTION_STATE_CB, + BT_UNIT_TEST_FUNCTION_AG_OPEN_SCO, + BT_UNIT_TEST_FUNCTION_AG_CLOSE_SCO, + BT_UNIT_TEST_FUNCTION_AG_IS_SCO_OPENED, + BT_UNIT_TEST_FUNCTION_AG_SET_SCO_STATE_CHANGED_CB, + BT_UNIT_TEST_FUNCTION_AG_UNSET_SCO_STATE_CHANGED_CB, + BT_UNIT_TEST_FUNCTION_AG_IS_CONNECTED, + BT_UNIT_TEST_FUNCTION_AG_CALL_EVENT_IDLE, + BT_UNIT_TEST_FUNCTION_AG_CALL_EVENT_ANSWERED, + BT_UNIT_TEST_FUNCTION_AG_CALL_EVENT_DIALING, + BT_UNIT_TEST_FUNCTION_AG_CALL_EVENT_ALERTING, + BT_UNIT_TEST_FUNCTION_AG_CALL_EVENT_INCOMING, + BT_UNIT_TEST_FUNCTION_CALL_LIST_CREATE, + BT_UNIT_TEST_FUNCTION_CALL_LIST_DESTROY, + BT_UNIT_TEST_FUNCTION_CALL_LIST_RESET, + BT_UNIT_TEST_FUNCTION_CALL_LIST_ADD, + BT_UNIT_TEST_FUNCTION_AG_NOTIFY_CALL_LIST, + BT_UNIT_TEST_FUNCTION_AG_SET_CALL_HANDLING_EVENT_CB, + BT_UNIT_TEST_FUNCTION_AG_IS_NREC_ENABLED, + BT_UNIT_TEST_FUNCTION_AG_IS_WBS_MODE, + BT_UNIT_TEST_FUNCTION_AG_SET_VENDOR_CMD_CB, + BT_UNIT_TEST_FUNCTION_AG_UNSET_VENDOR_CMD_CB, + BT_UNIT_TEST_FUNCTION_AG_NOTIFY_VENDOR_CMD, + BT_UNIT_TEST_FUNCTION_A2DP_SET_CONTENT_PROTECTION_ENABLE, + BT_UNIT_TEST_FUNCTION_A2DP_SET_CONTENT_PROTECTION_DISABLE, + BT_UNIT_TEST_FUNCTION_NAP_ACTIVATE = 1, + BT_UNIT_TEST_FUNCTION_NAP_DEACTIVATE, + BT_UNIT_TEST_FUNCTION_NAP_DISCONNECT_ALL, + BT_UNIT_TEST_FUNCTION_NAP_DISCONNECT, + BT_UNIT_TEST_FUNCTION_PANU_SET_CONNECTION_STATE_CHANGED_CB, + BT_UNIT_TEST_FUNCTION_PANU_CONNECT, + BT_UNIT_TEST_FUNCTION_GATT_CONNECT = 1, + BT_UNIT_TEST_FUNCTION_GATT_DISCONNECT, + BT_UNIT_TEST_FUNCTION_SET_GATT_CONNECTION_STATE_CHANGED_CB, + BT_UNIT_TEST_FUNCTION_UNSET_GATT_CONNECTION_STATE_CHANGED_CB, + BT_UNIT_TEST_FUNCTION_GATT_CLIENT_CREATE, + BT_UNIT_TEST_FUNCTION_GATT_CLIENT_DESTROY, + BT_UNIT_TEST_FUNCTION_GATT_CLIENT_GET_REMOTE_ADDRESS, + BT_UNIT_TEST_FUNCTION_GATT_CLIENT_PRINT_ALL, + BT_UNIT_TEST_FUNCTION_GATT_CLIENT_READ_VALUE, + BT_UNIT_TEST_FUNCTION_GATT_CLIENT_WRITE_VALUE, + BT_UNIT_TEST_FUNCTION_GATT_CLIENT_SET_CHAR_VALUE_CHANGED_CB, + BT_UNIT_TEST_FUNCTION_GATT_CLIENT_UNSET_CHAR_VALUE_CHANGED_CB, + BT_UNIT_TEST_FUNCTION_GATT_CLIENT_FOREACH_SERVICES, + BT_UNIT_TEST_FUNCTION_GATT_SERVER_INITIALIZE, + BT_UNIT_TEST_FUNCTION_GATT_SERVER_DEINITIALIZE, + BT_UNIT_TEST_FUNCTION_GATT_SERVER_UNREGISTER_ALL_SERVICES, + BT_UNIT_TEST_FUNCTION_GATT_SERVER_REGISTER_BATTERY_SVC, + BT_UNIT_TEST_FUNCTION_GATT_SERVER_CHANGE_BATTERY_LEVEL, + BT_UNIT_TEST_FUNCTION_GATT_SERVER_REGISTER_HEART_RATE_SVC, + BT_UNIT_TEST_FUNCTION_GATT_SERVER_NOTIFY_HEART_RATE_MEASUREMENT, + BT_UNIT_TEST_FUNCTION_GATT_SERVER_REGISTER_THERMOMETER_SVC, + BT_UNIT_TEST_FUNCTION_GATT_SERVER_CHANGE_THERMOMETER_MEASUREMENT, + BT_UNIT_TEST_FUNCTION_GATT_SERVER_REGISTER_DEVICE_INFORMATION_SVC, + BT_UNIT_TEST_FUNCTION_GATT_SERVER_REGISTER_LINK_LOSS_SVC, + BT_UNIT_TEST_FUNCTION_GATT_SERVER_REGISTER_CUSTOM_SVC, + BT_UNIT_TEST_FUNCTION_GATT_SERVER_CHANGE_CUSTOM_VAL, + BT_UNIT_TEST_FUNCTION_ANCS_PAIR, + BT_UNIT_TEST_FUNCTION_ANCS_WATCH, + BT_UNIT_TEST_FUNCTION_ANCS_POSITIVE_ACTION, + BT_UNIT_TEST_FUNCTION_ANCS_NEGATIVE_ACTION, + BT_UNIT_TEST_FUNCTION_ANCS_GET_NOTI_ATTR, +#ifdef BT_ENABLE_LEGACY_GATT_CLIENT + BT_UNIT_TEST_FUNCTION_GATT_FOREACH_PRIMARY_SERVICES, + BT_UNIT_TEST_FUNCTION_GATT_DISCOVER_CHARACTERISTICS, + BT_UNIT_TEST_FUNCTION_GATT_DISCOVER_CHARACTERISTIC_DESCRIPTORS, + BT_UNIT_TEST_FUNCTION_GATT_GET_SERVICE_UUID, + BT_UNIT_TEST_FUNCTION_GATT_FOREACH_INCLUDED_SERVICES, + BT_UNIT_TEST_FUNCTION_GATT_SET_CHARACTERISTIC_CHANGED_CB, + BT_UNIT_TEST_FUNCTION_GATT_UNSET_CHARACTERISTIC_CHANGED_CB, + BT_UNIT_TEST_FUNCTION_GATT_GET_CHARACTERISTIC_DECLARATION, + BT_UNIT_TEST_FUNCTION_GATT_SET_CHARACTERISTIC_VALUE, + BT_UNIT_TEST_FUNCTION_GATT_SET_CHARACTERISTIC_VALUE_REQUEST, + BT_UNIT_TEST_FUNCTION_GATT_READ_CHARACTERISTIC_VALUE, + BT_UNIT_TEST_FUNCTION_GATT_WATCH_CHARACTERISTIC_CHANGES, + BT_UNIT_TEST_FUNCTION_GATT_UNWATCH_CHARACTERISTIC_CHANGES, +#endif + BT_UNIT_TEST_FUNCTION_AVRCP_TARGET_INITIALIZE = 1, + BT_UNIT_TEST_FUNCTION_AVRCP_TARGET_DEINITIALIZE, + BT_UNIT_TEST_FUNCTION_AVRCP_SET_EQUALIZER_STATE_CHANGED_CB, + BT_UNIT_TEST_FUNCTION_AVRCP_SET_REPEAT_MODE_CHANGED_CB, + BT_UNIT_TEST_FUNCTION_AVRCP_SET_SHUFFLE_MODE_CHANGED_CB, + BT_UNIT_TEST_FUNCTION_AVRCP_SET_SCAN_MODE_CHANGED_CB, + BT_UNIT_TEST_FUNCTION_AVRCP_UNSET_EQUALIZER_STATE_CHANGED_CB, + BT_UNIT_TEST_FUNCTION_AVRCP_UNSET_REPEAT_MODE_CHANGED_CB, + BT_UNIT_TEST_FUNCTION_AVRCP_UNSET_SHUFFLE_MODE_CHANGED_CB, + BT_UNIT_TEST_FUNCTION_AVRCP_UNSET_SCAN_MODE_CHANGED_CB, + BT_UNIT_TEST_FUNCTION_AVRCP_CONTROL_INITIALIZE, + BT_UNIT_TEST_FUNCTION_AVRCP_CONTROL_DEINITIALIZE, + BT_UNIT_TEST_FUNCTION_AVRCP_CONTROL_CONNECT, + BT_UNIT_TEST_FUNCTION_AVRCP_CONTROL_DISCONNECT, + BT_UNIT_TEST_FUNCTION_AVRCP_CONTROL_PLAY, + BT_UNIT_TEST_FUNCTION_AVRCP_CONTROL_STOP, + BT_UNIT_TEST_FUNCTION_AVRCP_CONTROL_PAUSE, + BT_UNIT_TEST_FUNCTION_AVRCP_CONTROL_FF, + BT_UNIT_TEST_FUNCTION_AVRCP_CONTROL_RW, + BT_UNIT_TEST_FUNCTION_AVRCP_CONTROL_NEXT, + BT_UNIT_TEST_FUNCTION_AVRCP_CONTROL_PREV, + BT_UNIT_TEST_FUNCTION_AVRCP_CONTROL_GET_REPEAT, + BT_UNIT_TEST_FUNCTION_AVRCP_CONTROL_SET_REPEAT, + BT_UNIT_TEST_FUNCTION_AVRCP_CONTROL_GET_SHUFFLE, + BT_UNIT_TEST_FUNCTION_AVRCP_CONTROL_SET_SHUFFLE, + BT_UNIT_TEST_FUNCTION_AVRCP_CONTROL_GET_POSITION, + BT_UNIT_TEST_FUNCTION_AVRCP_CONTROL_GET_PLAY_STATUS, + BT_UNIT_TEST_FUNCTION_AVRCP_CONTROL_GET_TRACK_INFO, + BT_UNIT_TEST_FUNCTION_AVRCP_SET_SONG_POSITION_CHANGED_CB, + BT_UNIT_TEST_FUNCTION_AVRCP_SET_PLAY_STATE_CHANGED_CB, + BT_UNIT_TEST_FUNCTION_AVRCP_SET_TRACK_INFO_CHANGED_CB, + BT_UNIT_TEST_FUNCTION_AVRCP_UNSET_SONG_POSITION_CHANGED_CB, + BT_UNIT_TEST_FUNCTION_AVRCP_UNSET_PLAY_STATE_CHANGED_CB, + BT_UNIT_TEST_FUNCTION_AVRCP_UNSET_TRACK_INFO_CHANGED_CB, + BT_UNIT_TEST_FUNCTION_HID_HOST_INITIALIZE = 1, + BT_UNIT_TEST_FUNCTION_HID_HOST_DEINITIALIZE, + BT_UNIT_TEST_FUNCTION_HID_HOST_CONNECT, + BT_UNIT_TEST_FUNCTION_HID_HOST_DISCONNECT, +#ifdef TIZEN_WEARABLE + BT_UNIT_TEST_FUNCTION_HF_INITIALIZE = 1, + BT_UNIT_TEST_FUNCTION_HF_DEINITIALIZE, + BT_UNIT_TEST_FUNCTION_HF_NOTIFY_CALL_ANSWER, + BT_UNIT_TEST_FUNCTION_HF_NOTIFY_CALL_INIT, + BT_UNIT_TEST_FUNCTION_HF_NOTIFY_CALL_TERM, + BT_UNIT_TEST_FUNCTION_HF_GET_CALL_STATUS_INFO_LIST, + BT_UNIT_TEST_FUNCTION_HF_SET_CALL_EVENT_CB, + BT_UNIT_TEST_FUNCTION_HF_UNSET_CALL_EVENT_CB, + BT_UNIT_TEST_FUNCTION_HF_SET_CALL_STATUS_UPDATED_EVENT_CB, + BT_UNIT_TEST_FUNCTION_HF_UNSET_CALL_STATUS_UPDATED_EVENT_CB, + BT_UNIT_TEST_FUNCTION_HF_NOTIFY_SPEAKER_GAIN, + BT_UNIT_TEST_FUNCTION_HF_SET_SPEAKER_GAIN_CB, + BT_UNIT_TEST_FUNCTION_HF_UNSET_SPEAKER_GAIN_CB, + BT_UNIT_TEST_FUNCTION_HF_NOTIFY_VOICE_REC_TRUE, + BT_UNIT_TEST_FUNCTION_HF_NOTIFY_VOICE_REC_FALSE, + BT_UNIT_TEST_FUNCTION_HF_IS_SCO_OPENED, + BT_UNIT_TEST_FUNCTION_HF_GET_CODEC_ID, + BT_UNIT_TEST_FUNCTION_HF_SET_SCO_CHANGED_CB, + BT_UNIT_TEST_FUNCTION_HF_UNSET_SCO_CHANGED_CB, + BT_UNIT_TEST_FUNCTION_HF_NOTIFY_VENDOR_CMD, + BT_UNIT_TEST_FUNCTION_HF_SET_VENDOR_CMD_EVENT_CB, + BT_UNIT_TEST_FUNCTION_HF_UNSET_VENDOR_CMD_EVENT_CB, + BT_UNIT_TEST_FUNCTION_PBAP_CLIENT_INITIALIZE = 1, + BT_UNIT_TEST_FUNCTION_PBAP_CLIENT_DEINITIALIZE, + BT_UNIT_TEST_FUNCTION_PBAP_CLIENT_CONNECT, + BT_UNIT_TEST_FUNCTION_PBAP_CLIENT_DISCONNECT, + BT_UNIT_TEST_FUNCTION_PBAP_CLIENT_GETSIZE, + BT_UNIT_TEST_FUNCTION_PBAP_CLIENT_PHONEBOOKPULL, + BT_UNIT_TEST_FUNCTION_PBAP_CLIENT_VCARDLIST, + BT_UNIT_TEST_FUNCTION_PBAP_CLIENT_VCARDPULL, + BT_UNIT_TEST_FUNCTION_PBAP_CLIENT_PHONEBOOKSEARCH, + BT_UNIT_TEST_FUNCTION_PBAP_CLIENT_VCARDLIST_MAXLIST_ZERO, +#endif + BT_UNIT_TEST_FUNCTION_ON_OFF_REPEAT_TEST = 1, + BT_UNIT_TEST_FUNCTION_ON_OFF_REPEAT_TEST_1_SEC_DELAY, + BT_UNIT_TEST_FUNCTION_ON_OFF_REPEAT_TEST_N_SEC_DELAY, + + BT_UNIT_TEST_FUNCTION_ACTIVATE_FLAG_TO_SET_PARAMETERS = 0XFF, +} bt_unit_test_function_e; + +typedef struct { + const char *tc_name; + int tc_code; +} tc_table_t; + +typedef struct { + int param_count; + char **params; +} tc_params_t; + +#define BT_UNIT_TEST_PARAM_TYPE_BOOL "bool(true, false)" +#define BT_UNIT_TEST_PARAM_TYPE_INT "int(1, 2, 10, 777...)" +#define BT_UNIT_TEST_PARAM_TYPE_FLOAT "float(1.5, 0.625...)" +#define BT_UNIT_TEST_PARAM_TYPE_STRING "string(abc, HAHA..)" +#define BT_UNIT_TEST_PARAM_TYPE_BYTE_ARRAY "byte array(03FF0102, 0015836CF7B2...)" + +int test_input_callback(void *data); + +#ifdef __cplusplus +} +#endif + +#endif /* __TIZEN_NETWORK_BLUETOOTH_UNIT_TEST_H__ */ diff --git a/test/capi.network.bluetooth.infinite.spp.test.rule b/test/capi.network.bluetooth.infinite.spp.test.rule new file mode 100644 index 0000000..a5a4466 --- /dev/null +++ b/test/capi.network.bluetooth.infinite.spp.test.rule @@ -0,0 +1,4 @@ +capi-network-bluetooth-infinite-spp-test-server bt-service::public w +capi-network-bluetooth-infinite-spp-test-server bt-service::platform rw +capi-network-bluetooth-infinite-spp-test-client bt-service::public w +capi-network-bluetooth-infinite-spp-test-client bt-service::platform rw diff --git a/test/capi.network.bluetooth.test.rule b/test/capi.network.bluetooth.test.rule new file mode 100644 index 0000000..59d60ad --- /dev/null +++ b/test/capi.network.bluetooth.test.rule @@ -0,0 +1,2 @@ +capi-network-bluetooth-test bt-service::public w +capi-network-bluetooth-test bt-service::platform rw diff --git a/test/gatt_profile_test_suite/CMakeLists.txt b/test/gatt_profile_test_suite/CMakeLists.txt new file mode 100644 index 0000000..dccbadd --- /dev/null +++ b/test/gatt_profile_test_suite/CMakeLists.txt @@ -0,0 +1,22 @@ +SET(fw_test "${fw_name}-test") +PROJECT(bt_unit_test_gatt C) + +INCLUDE(FindPkgConfig) +pkg_check_modules(${fw_test} REQUIRED glib-2.0) +FOREACH(flag ${${fw_test}_CFLAGS}) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") +ENDFOREACH(flag) + +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -Wall") + +SET(SOURCES +bt_unit_test_gatt.c +bt_unit_test_gatt_hr_profile.c +) + +ADD_EXECUTABLE(${PROJECT_NAME} ${SOURCES}) +TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${fw_name} ${${fw_test}_LDFLAGS}) + +INSTALL(TARGETS bt_unit_test_gatt DESTINATION bin) +INSTALL(FILES capi.network.bluetooth.test.gatt.rule DESTINATION /etc/smack/accesses2.d/) + diff --git a/test/gatt_profile_test_suite/bt_unit_test_gatt.c b/test/gatt_profile_test_suite/bt_unit_test_gatt.c new file mode 100644 index 0000000..db2c966 --- /dev/null +++ b/test/gatt_profile_test_suite/bt_unit_test_gatt.c @@ -0,0 +1,121 @@ +#include "bt_unit_test_gatt.h" +#include + +GMainLoop *main_loop = NULL; +gatt_test_role_e role = GATT_ROLE_INVALID; +bool gatt_debug = false; + +typedef void (*gatt_test_signal_handler) (int signo); + +gatt_test_signal_handler profile_signal_handler_cb = NULL; + +void sig_handler(int signo) +{ +/* TODO: decide on what more to be done here. Should each profile register callback for this */ + if(profile_signal_handler_cb) + profile_signal_handler_cb(signo); + exit(0); +} + +static struct option main_options[] = { + { "heart-rate-profile", optional_argument, NULL, 'H' }, + { "client", no_argument, NULL, 'c' }, + { "server", no_argument, NULL, 's' }, + { "help", no_argument, NULL, 'h' }, + { } +}; + + +void usage() +{ + USR_PRT("Usage:\tbt_unit_test_gatt [option[parameter]]\n\n"\ + "\t Role:\n"\ + "\t -c client role\n"\ + "\t -s server role\n\n"\ + "\t [option..]:\n"\ + "\t -H Heart rate Profile\n"\ + "\t -d Debug enable\n"\ + "\t -h Help Menu\n"); +} + +int main(int argc, char *argv[]) +{ + GIOChannel *key_io; + int opt; + bool profile_selected = false; + char buf[BUFFER_LEN] = { 0 }; +// g_type_init(); + + key_io = g_io_channel_unix_new(fileno(stdin)); + + g_io_channel_set_encoding(key_io, NULL, NULL); + g_io_channel_set_flags(key_io, G_IO_FLAG_NONBLOCK, NULL); + + while ((opt = getopt_long(argc, argv, + "H:hcsd", main_options, NULL)) != -1) { + switch(opt) { + case 'c': + if (role == GATT_ROLE_SERVER) { + USR_PRT(" both can't be selected"); + goto fail; + } else { + role = GATT_ROLE_CLIENT; + } + break; + case 's': + if (role == GATT_ROLE_CLIENT) { + USR_PRT("both can't be selected"); + goto fail; + } else { + role = GATT_ROLE_SERVER; + } + break; + case 'H': + if (role == GATT_ROLE_INVALID) { + USR_PRT(" parameter is missing"); + usage(); + exit(0); + }else if(role == GATT_ROLE_CLIENT) { + hr_client_initialize(); + USR_PRT("Launching Heart rate profile test-suite"); + memcpy(buf, optarg, sizeof(buf)); + hr_client_accept_input(buf); + g_io_add_watch(key_io, G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL, + hr_client_key_event_cb, NULL); + g_io_channel_unref(key_io); + profile_selected = true; + profile_signal_handler_cb = hr_client_signal_handler; + } else { + //Heart-rate profile server + profile_selected = true; + } + break; + case 'd': + gatt_debug = true; + break; + case 'h': + default: + usage(); + exit(0); + } + } + + if(profile_selected == false) { + USR_PRT("No profile selected: So, nothing to do"); + goto fail; + } + + main_loop = g_main_loop_new(NULL, FALSE); + + if (signal(SIGINT, sig_handler) == SIG_ERR) + USR_PRT("\n can't catch SIGINT\n"); + + g_main_loop_run(main_loop); + + bt_deinitialize(); + + return 0; +fail: + usage(); + exit(0); +} diff --git a/test/gatt_profile_test_suite/bt_unit_test_gatt.h b/test/gatt_profile_test_suite/bt_unit_test_gatt.h new file mode 100644 index 0000000..76df892 --- /dev/null +++ b/test/gatt_profile_test_suite/bt_unit_test_gatt.h @@ -0,0 +1,43 @@ +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include +#include +#include +#include +#include +#include + +#include "bluetooth.h" +#include "bluetooth_internal.h" +#include "bluetooth_private.h" +#include "bluetooth-telephony-api.h" + +#define PRT(format, args...) do { \ + if (gatt_debug)\ + printf("%s:%d() "format, __FUNCTION__, __LINE__, ##args);\ +}while(0) + +#define DBG_PRT(format, args...) PRT(format"\n", ##args) +#define USR_PRT(format, args...) printf(format"\n", ##args) +#define BUFFER_LEN 49 + +typedef enum +{ + GATT_ROLE_INVALID = 0x00, + GATT_ROLE_CLIENT, + GATT_ROLE_SERVER, +}gatt_test_role_e; + + +int hr_client_initialize(void); +void hr_client_signal_handler(int); + +void hr_client_accept_input(char *buf); + +gboolean hr_client_key_event_cb(GIOChannel *chan, GIOCondition cond, + gpointer data); + + diff --git a/test/gatt_profile_test_suite/bt_unit_test_gatt_hr_profile.c b/test/gatt_profile_test_suite/bt_unit_test_gatt_hr_profile.c new file mode 100644 index 0000000..41bea37 --- /dev/null +++ b/test/gatt_profile_test_suite/bt_unit_test_gatt_hr_profile.c @@ -0,0 +1,472 @@ +#include "bt_unit_test_gatt_hr_profile.h" + +extern bool gatt_debug; + +static hr_test_gatt_state_e test_cursor = BT_GATT_TEST_HR_INITIALIZATION; +static bool input_valid = false; +static bt_gatt_h hr_control_point_handle = NULL; + +static void __hr_client_scan_result_cb(int result, + bt_adapter_le_device_scan_result_info_s *info, void *user_data) +{ + if (info == NULL) { + DBG_PRT("No discovery_info!"); + return; + } + if(!strcmp(info->remote_address, remote_addr)) { + bt_adapter_le_stop_scan(); + if(bt_gatt_connect(remote_addr, false) != BT_ERROR_NONE) + test_cursor = BT_GATT_TEST_UNRECOVERABLE; + } +} + +void __hr_client_search_and_connect() +{ + int ret; + ret = bt_adapter_le_start_scan(__hr_client_scan_result_cb, NULL); + if(ret != BT_ERROR_NONE) + test_cursor = BT_GATT_TEST_UNRECOVERABLE; +} + +void __hr_client_initiate_connection() +{ + int ret; + USR_PRT("Make sure the remote device is turned on and visible"); + USR_PRT("Please wait.. while we connect the device"); + + test_cursor = BT_GATT_TEST_TABLE_CONNECTING; + + ret = bt_gatt_connect(remote_addr, false); + if(ret != BT_ERROR_NONE) + __hr_client_search_and_connect(); +} + +static void __hr_client_reset_energy_expended_cb(int result, bt_gatt_h request_handle, + void *user_data) +{ + if (result != BT_ERROR_NONE) { + USR_PRT("Reset of Energy expended value failed"); + DBG_PRT("result code %d", result); + return; + } + + USR_PRT("Reset of Energy expended value is complete"); + return; +} + +void __hr_client_reset_energy_expended() +{ + if (hr_control_point_handle) { + char reset = 0x01; + USR_PRT("Attempting to reset the energy expended"); + bt_gatt_characteristic_set_write_type(hr_control_point_handle, + BT_GATT_WRITE_TYPE_WRITE); + bt_gatt_set_value(hr_control_point_handle, &reset, sizeof(reset)); + bt_gatt_client_write_value(hr_control_point_handle, __hr_client_reset_energy_expended_cb, NULL); + } else + USR_PRT("Heart rate control point is not supported"); +} +void __hr_client_measurement_cb(bt_gatt_h chr, char *value, int len, + void *user_data) +{ + int value_cursor = 0; + char flags; + DBG_PRT("len [%d]", len); + if(len < 1) { + DBG_PRT("invalid notification"); + } + flags = value[0]; + value_cursor++; + + if((flags & HR_VALUE_FORMAT_MASK)) { + USR_PRT("Heart Rate Measurement Value %x %x", value[value_cursor], value[value_cursor+1]); + value_cursor += 2; + }else { + USR_PRT("Heart Rate Measurement Value %x", value[value_cursor]); + value_cursor++; + } + + switch(flags & HR_SENSOR_CONTACT_STATUS_BIT_MASK) { + case 0x00: + USR_PRT("Sensor Contact feature is not supported in the current connection"); + break; + case 0x02: + USR_PRT("Sensor Contact feature is not supported in the current connection"); + break; + case 0x04: + USR_PRT("Sensor Contact feature is supported, but contact is not detected "); + break; + case 0x06: + USR_PRT("Sensor Contact feature is supported and contact is detected"); + break; + default: + USR_PRT("unreachable code"); + } + if(flags & HR_ENERGY_EXPENDED_BIT_MASK) { + USR_PRT("Energy Expended %x %x KJ", value[value_cursor], value[value_cursor + 1]); + if((value[value_cursor] == 0xff) && (value[value_cursor + 1] == 0xff)) + __hr_client_reset_energy_expended(); + value_cursor += 2; + } + + if(flags & HR_RR_INTERVAL_BIT_MASK) { + while(value_cursor <= (len - 2)) { + USR_PRT("RR Interval %x %x", value[value_cursor], value[value_cursor+1]); + value_cursor += 2; + } + } + +} + +void __hr_client_print_sensor_loc(bt_gatt_h h) +{ + int ret; + char *value = NULL; + int len = 0; + + ret = bt_gatt_get_value(h, &value, &len); + if (ret != BT_ERROR_NONE) { + DBG_PRT("bt_gatt_get_value is failed : %d", ret); + return; + } + + if(len > 1) { + DBG_PRT("invalid sensor location value"); + return; + } + + switch(value[0]) { + case 0: + USR_PRT("location : other"); + break; + case 1: + USR_PRT("location : Chest"); + break; + case 2: + USR_PRT("location : Wrist"); + break; + case 3: + USR_PRT("location : Finger"); + break; + case 4: + USR_PRT("location : Hand"); + break; + case 5: + USR_PRT("location : Ear Lobe"); + break; + case 6: + USR_PRT("location : Foot"); + break; + default: + USR_PRT("Invalid Location value."); + } + g_free(value); +} + +void __hr_client_body_sensor_loc_cb(int result, bt_gatt_h gatt_handle, void *data) +{ + + DBG_PRT("Read %s", result == BT_ERROR_NONE ? "Success" : "Fail"); + + if (result != BT_ERROR_NONE) + return; + + __hr_client_print_sensor_loc(gatt_handle); + + return; +} +void __hr_client_dev_inf_read_complete_cb(int result, bt_gatt_h gatt_handle, void *data) +{ + int ret; + char *str = NULL; + char *value = NULL; + int len = 0; + bool hex_format = false; + int i; + + if (result != BT_ERROR_NONE) { + USR_PRT("error occured in reading"); + DBG_PRT("error number =%d", result); + return; + } + + ret = bt_gatt_get_value(gatt_handle, &value, &len); + if (ret != BT_ERROR_NONE) { + USR_PRT("error occured in reading"); + DBG_PRT("error number =%d", result); + return; + } + + for (i = 0; i < len; i++) + if (isalnum(value[i]) == 0) { + hex_format = true; + break; + } + + if (hex_format) { + str = g_malloc0(len * 5 + 1); + for (i = 0; i < len; i++) { + if (i > 0) + str[i * 5 - 1] = ' '; + + snprintf(&str[i * 5], 5, "0x%02X", value[i]); + } + } else { + str = g_malloc0(len + 1); + memcpy(str, value, len); + } + + USR_PRT("Value : %s", str); + + g_free(str); + g_free(value); + return; +} + +bool __hr_client_dev_inf_service_cb(int total, int index, bt_gatt_h chr_handle, void *data) +{ + char *uuid = NULL; + char *str = NULL; + + bt_gatt_get_uuid(chr_handle, &uuid); + bt_gatt_get_uuid_specification_name(uuid, &str); + + if(!strcasecmp(uuid, manufacture_name_string)){ + USR_PRT("Reading Manufacturer name. Printed data is in Hexa decimal"); + } else if(!strcasecmp(uuid, model_number_string)){ + DBG_PRT("Reading Model Number. Printed data is in Hexa decimal"); + } else if(!strcasecmp(uuid, serial_number_string)){ + USR_PRT("Serial Number. Printed data is in Hexa decimaal"); + } else if(!strcasecmp(uuid, firmware_revision_string)){ + USR_PRT("Firmware Revision. Printed data is in Hexa decimal"); + } else if(!strcasecmp(uuid, hardware_revision_string)){ + USR_PRT("Hardware Rivision. Printed data is in Hexa decimal"); + } else if(!strcasecmp(uuid, software_revision_string)){ + USR_PRT("Software revision. Printed data is in Hexa decimaal"); + } else if(!strcasecmp(uuid, system_id)){ + USR_PRT("System id. Printed data is in Hexa decimal"); + USR_PRT("this is a 8 byte value."); + USR_PRT("The first 40 bits is Manufacturer Identifier."); + USR_PRT("Remaining 24 bits is Organizationally Unique Identifier."); + } else if(!strcasecmp(uuid, regulatory_certification_data_list)){ + USR_PRT("IEEE 11073-20601 Regulatory Certification Data List"); + USR_PRT("Printed data is a opaque data structure, application to make sense"); + } else if(!strcasecmp(uuid, PnP_id)){ + USR_PRT("PnP id. Printed data is in Hexa decimal"); + USR_PRT("First byte is Vendor ID Source: 0X01 means SIG assigned, 0x02 means USB Implementer Forum"); + USR_PRT("Next 2 byte is Vendor ID"); + USR_PRT("Next 2 byte is Product ID"); + USR_PRT("Next 2 byte is Product version"); + } + + bt_gatt_client_read_value(chr_handle, __hr_client_dev_inf_read_complete_cb, NULL); + + g_free(str); + g_free(uuid); + + return true; +} + +bool __hr_client_hr_service_cb(int total, int index, bt_gatt_h chr_handle, void *data) +{ + char *uuid = NULL; + char *str = NULL; + + bt_gatt_get_uuid(chr_handle, &uuid); + bt_gatt_get_uuid_specification_name(uuid, &str); + + if(!strcasecmp(uuid, heart_rate_measurement_uuid)){ + DBG_PRT("Enabling notification for %s characteristic" ,str ? str : "Unknown"); + if(bt_gatt_client_set_characteristic_value_changed_cb(chr_handle, + __hr_client_measurement_cb, NULL) != BT_ERROR_NONE) + DBG_PRT("registerinig Notification failed"); + } else if(!strcasecmp(uuid, body_sensor_location)){ + DBG_PRT("Reading Body sensor location"); + bt_gatt_client_read_value(chr_handle, __hr_client_body_sensor_loc_cb, NULL); + } else if(!strcasecmp(uuid, heart_rate_control_point)){ + USR_PRT("Energy Expended feature is supported"); + if(hr_control_point_handle) + g_free(hr_control_point_handle); + hr_control_point_handle = g_strdup(chr_handle); + } + g_free(str); + g_free(uuid); + + return true; +} + +bool __hr_client_monitor_svc_cb(int total, int index, bt_gatt_h svc_handle, void *data) +{ + char *svc_str = NULL; + char *uuid = NULL; + + bt_gatt_get_uuid(svc_handle, &uuid); + bt_gatt_get_uuid_specification_name(uuid, &svc_str); + DBG_PRT("%s service (uuid = %s)", svc_str ? svc_str : uuid, uuid); + + if(!strcasecmp(uuid, heart_rate_service_uuid)){ + DBG_PRT("%s service", svc_str ? svc_str : uuid); + bt_gatt_service_foreach_characteristics(svc_handle, + __hr_client_hr_service_cb, NULL); + } else if(!strcasecmp(uuid, device_information_service_uuid)){ + DBG_PRT("%s service", svc_str ? svc_str : uuid); + bt_gatt_service_foreach_characteristics(svc_handle, + __hr_client_dev_inf_service_cb, NULL); + } + g_free(svc_str); + g_free(uuid); + + return true; +} +void __hr_client_connection_state_changed_cb(int result, bool connected, const char *remote_address, void *user_data) +{ + if(!strcmp(remote_address, remote_addr)) { + if (connected) { + DBG_PRT("Connected to the remote device"); + test_cursor = BT_GATT_TEST_TABLE_SERVICE; + if (gatt_client) { + bt_gatt_client_destroy(gatt_client); + gatt_client = NULL; + if(hr_control_point_handle) + g_free(hr_control_point_handle); + } + if(bt_gatt_client_create(remote_addr, &gatt_client) != BT_ERROR_NONE) { + test_cursor = BT_GATT_TEST_UNRECOVERABLE; + DBG_PRT("GATT_Client creation failed"); + return; + } + if(bt_gatt_client_foreach_services(gatt_client, + __hr_client_monitor_svc_cb, NULL) != BT_ERROR_NONE) { + test_cursor = BT_GATT_TEST_UNRECOVERABLE; + return; + } + test_cursor = BT_GATT_TEST_TABLE_MONITOR_SERVICES; + } else { + USR_PRT("Connection to the remote device is removed"); + USR_PRT("Attempting to re-connect to the device"); + USR_PRT("Make sure the remote device is turned on and in range"); + test_cursor = BT_GATT_TEST_TABLE_CONNECTING; + bt_gatt_connect(remote_addr, true); + } + } + +} + +int __hr_client_validate_input_bd_addr (char *bd_addr) +{ + /*have to design better check for validity check of the input*/ + if (bd_addr == NULL || strlen(bd_addr) < 16) { + input_valid = false; + return BT_ERROR_INVALID_PARAMETER; + } + input_valid = true; + return BT_ERROR_NONE; +} + +void hr_client_accept_input(char *buf) +{ + if (__hr_client_validate_input_bd_addr(buf) != BT_ERROR_NONE) { + USR_PRT("invalid bluetooth address"); + } else { + memcpy (remote_addr, buf, 17); + remote_addr[17] = 0; + if (test_cursor == BT_GATT_TEST_HR_INITIALIZED) + __hr_client_initiate_connection(); + } + +} +int hr_client_initialize(void) +{ + int ret = BT_ERROR_NONE; + test_cursor = BT_GATT_TEST_HR_INITIALIZATION; + + ret = bt_initialize(); + if (ret == BT_ERROR_NONE || ret == BT_ERROR_ALREADY_DONE) + DBG_PRT("Initialized"); + else + goto fail; + + ret = bt_adapter_enable(); + if(ret == BT_ERROR_NONE || ret == BT_ERROR_ALREADY_DONE) + DBG_PRT("Adapter enabled"); + else + goto fail; + + ret = bt_gatt_set_connection_state_changed_cb(__hr_client_connection_state_changed_cb, NULL); + if (ret != BT_ERROR_NONE) + goto fail; + + test_cursor = BT_GATT_TEST_HR_INITIALIZED; + return ret; +fail: + DBG_PRT("Initiailization error returns %d", ret); + return ret; +} + +void hr_client_signal_handler(int signno) +{ + bt_gatt_disconnect(remote_addr); + bt_gatt_unset_connection_state_changed_cb(); +} + +gboolean hr_client_key_event_cb(GIOChannel *chan, + GIOCondition cond, + gpointer data) +{ + char buf[BUFFER_LEN] = { 0 }; + unsigned int len = 0; + + if (g_io_channel_read_chars(chan, buf, sizeof(buf), + &len, NULL) == G_IO_STATUS_ERROR) { + DBG_PRT("IO Channel read error"); + return FALSE; + } + + if (test_cursor == BT_GATT_TEST_UNRECOVERABLE) { + USR_PRT("Unrecoverable error, please reboot"); + } else if (test_cursor == BT_GATT_TEST_HR_INITIALIZATION) { + if(hr_client_initialize() != BT_ERROR_NONE) { + USR_PRT("Initialization failed please reboot"); + } else { + DBG_PRT("Initialization is successfull"); + if(!input_valid) { + USR_PRT("In-put remote BD-ADDR in the below format"); + USR_PRT("00:11:22:33:44:55"); + test_cursor = BT_GATT_TEST_TABLE_SET_ADDRESS; + } else { + __hr_client_initiate_connection(); + } + } + } else if (test_cursor == BT_GATT_TEST_HR_INITIALIZED) { + if(!input_valid) { + USR_PRT("In-put remote BD-ADDR in the below format"); + USR_PRT("00:11:22:33:44:55"); + test_cursor = BT_GATT_TEST_TABLE_SET_ADDRESS; + } else { + __hr_client_initiate_connection(); + } + } else if (test_cursor == BT_GATT_TEST_TABLE_SET_ADDRESS) { + if (__hr_client_validate_input_bd_addr(buf) != BT_ERROR_NONE) { + USR_PRT("invalid bluetooth address"); + USR_PRT("In-put remote BD-ADDR in the below format"); + USR_PRT("00:11:22:33:44:55"); + test_cursor = BT_GATT_TEST_TABLE_SET_ADDRESS; + } else { + memcpy (remote_addr, buf, 17); + remote_addr[17] = 0; + __hr_client_initiate_connection(); + } + } else if (test_cursor == BT_GATT_TEST_TABLE_CONNECT) { + __hr_client_initiate_connection(); + USR_PRT("Please wait.. while we connect the device"); + } else if (test_cursor == BT_GATT_TEST_TABLE_CONNECTING) { + USR_PRT("Please wait.. while we connect the device"); + } else if (test_cursor == BT_GATT_TEST_TABLE_SERVICE) { + USR_PRT("Quering supported services.."); + } else if (test_cursor == BT_GATT_TEST_TABLE_MONITOR_SERVICES) { + // DBG_PRT("TODO"); + } + + return TRUE; +} + diff --git a/test/gatt_profile_test_suite/bt_unit_test_gatt_hr_profile.h b/test/gatt_profile_test_suite/bt_unit_test_gatt_hr_profile.h new file mode 100644 index 0000000..fc31f18 --- /dev/null +++ b/test/gatt_profile_test_suite/bt_unit_test_gatt_hr_profile.h @@ -0,0 +1,64 @@ + +#include "bt_unit_test_gatt.h" + +bt_gatt_client_h gatt_client = NULL; +char remote_addr[18] = "00:11:22:33:44:55"; + +/* Mandatory Services for HR profile*/ + +//Heart Rate service begin +char *heart_rate_service_uuid = "0000180D-0000-1000-8000-00805F9B34FB"; +/*Mandatory Characteristics for this service, in HR profile*/ +char *heart_rate_measurement_uuid = "00002A37-0000-1000-8000-00805F9B34FB"; +char *body_sensor_location = "00002A38-0000-1000-8000-00805F9B34FB"; +/*optional characteristics for this service, in HR profile */ +char *heart_rate_control_point= "00002A39-0000-1000-8000-00805F9B34FB"; +//Heart Rate service end + +//Device Information Service begin +char *device_information_service_uuid = "0000180A-0000-1000-8000-00805F9B34FB"; +/*Mandatory Characteristics for this service, in HR profile*/ +char *manufacture_name_string = "00002A29-0000-1000-8000-00805F9B34FB"; +/*optional characteristics for this service, in HR profile */ +char *model_number_string = "00002A24-0000-1000-8000-00805F9B34FB"; +char *serial_number_string = "00002A25-0000-1000-8000-00805F9B34FB"; +char *firmware_revision_string = "00002A26-0000-1000-8000-00805F9B34FB"; +char *hardware_revision_string = "00002A27-0000-1000-8000-00805F9B34FB"; +char *software_revision_string = "00002A28-0000-1000-8000-00805F9B34FB"; +char *system_id = "00002A23-0000-1000-8000-00805F9B34FB"; +char *regulatory_certification_data_list = "00002A2A-0000-1000-8000-00805F9B34FB"; +char *PnP_id = "00002A50-0000-1000-8000-00805F9B34FB"; +//Device Information Service end + +/* Mandatory Services for HR profile end */ + + +/* Optional services for HR profile */ + +// there are no optional services for this profile + +/* Optional services for HR profile end */ + + +typedef enum +{ + HR_VALUE_FORMAT_MASK = 0x01, + HR_SENSOR_CONTACT_STATUS_BIT_MASK = 0x06, + HR_ENERGY_EXPENDED_BIT_MASK = 0x08, + HR_RR_INTERVAL_BIT_MASK = 0x10, +}gatt_hr_measurement_property_e; + + +typedef enum +{ + BT_GATT_TEST_UNRECOVERABLE = 1, + BT_GATT_TEST_INITIALIZATION, + BT_GATT_TEST_HR_INITIALIZATION, + BT_GATT_TEST_HR_INITIALIZED, + BT_GATT_TEST_TABLE_SET_ADDRESS, + BT_GATT_TEST_TABLE_CONNECT, + BT_GATT_TEST_TABLE_CONNECTING, + BT_GATT_TEST_TABLE_SERVICE, + BT_GATT_TEST_TABLE_MONITOR_SERVICES, + BT_UNIT_TEST_TABLE_FINISH = 0xFF, +} hr_test_gatt_state_e; diff --git a/test/gatt_profile_test_suite/capi.network.bluetooth.test.gatt.rule b/test/gatt_profile_test_suite/capi.network.bluetooth.test.gatt.rule new file mode 100644 index 0000000..096ce47 --- /dev/null +++ b/test/gatt_profile_test_suite/capi.network.bluetooth.test.gatt.rule @@ -0,0 +1,2 @@ +capi-network-bluetooth-test-gatt bt-service::public w +capi-network-bluetooth-test-gatt bt-service::platform rw diff --git a/test_scripts/bt_on_test_while_infinite.service b/test_scripts/bt_on_test_while_infinite.service new file mode 100644 index 0000000..073bbaf --- /dev/null +++ b/test_scripts/bt_on_test_while_infinite.service @@ -0,0 +1,13 @@ +[Unit] +Description=BT On test while infinite reboot +PartOf=bluetooth-hciattach@bt.service + +[Service] +Type=oneshot +ExecStart=/usr/etc/bluetooth/check_bt_during_infinite_boot.sh +RemainAfterExit=yes +StandardOutput=journal+console +StandardError=inherit + +[Install] +RequiredBy=bluetooth-hciattach@bt.service diff --git a/test_scripts/check_bt_during_infinite_boot.sh b/test_scripts/check_bt_during_infinite_boot.sh new file mode 100755 index 0000000..be42080 --- /dev/null +++ b/test_scripts/check_bt_during_infinite_boot.sh @@ -0,0 +1,39 @@ +#!/bin/bash +set -x + +LOG_FILE_NAME=/opt/usr/media/.bt_dump/log.txt + +function get_error_message_from_device { + all_log_dump.sh + sleep 10 + sync +} + +function check_bt_up_and_logging { + if (hciconfig | grep hci0) ; then + DOWNLOAD_TIME=`systemctl status bluetooth-hci-device -l|grep Break` + echo $COUNTER "ON" `date -R` ${DOWNLOAD_TIME##*.} >> $LOG_FILE_NAME + + if (hciconfig hci0 sspmode | grep Disabled) ; then + echo "BT SSP is not setuped" `date -R` >> $LOG_FILE_NAME + hciconfig -a >> $LOG_FILE_NAME + get_error_message_from_device; + fi + + return 0 + else + echo $COUNTER "FAIL" `date -R` >> $LOG_FILE_NAME + hciconfig -a >> $LOG_FILE_NAME + get_error_message_from_device; + return 1 + fi +} + +echo "Infinite Loop" +touch $LOG_FILE_NAME + +sleep 10 +check_bt_up_and_logging +sleep 10 +reboot + diff --git a/test_scripts/check_bt_during_infinite_boot_by_sdb.sh b/test_scripts/check_bt_during_infinite_boot_by_sdb.sh new file mode 100755 index 0000000..1c2bba9 --- /dev/null +++ b/test_scripts/check_bt_during_infinite_boot_by_sdb.sh @@ -0,0 +1,71 @@ +#!/bin/bash +set -x + +LOG_FILE_NAME=log.txt +COUNTER=0 +MODEL_NAME="SM-Z130H" +SDB_OFFLINE="offline" +SDB_FAILURE_COUNTER=0 + +function get_error_message_from_device { + LOG_PATH="LOG"$COUNTER + sdb shell all_log_dump.sh + sdb pull /opt/usr/media/SLP_debug $LOG_PATH + sdb shell rm -rf /opt/usr/media/SLP_debug/* +} + +function check_bt_up_and_logging { + if (sdb shell hciconfig |grep hci0) ; then + echo "BT is ON" + echo $COUNTER "ON" `date -R` >> $LOG_FILE_NAME + + if (sdb shell hciconfig hci0 sspmode |grep Disabled) ; then + echo "BT SSP is disabled" + echo "BT SSP is not setuped" `date -R` >> $LOG_FILE_NAME + sdb shell hciconfig -a >> $LOG_FILE_NAME + get_error_message_from_device; + else + sdb shell systemctl status bluetooth-hci-device -l |grep Break >> $LOG_FILE_NAME + fi + + return 0 + else + echo $COUNTER "FAIL" `date -R` >> $LOG_FILE_NAME + sdb shell hciconfig -a >> $LOG_FILE_NAME + get_error_message_from_device; + return 1 + fi +} + +echo "Infinite Loop" +touch $LOG_FILE_NAME +echo "Start" `date -R` >> $LOG_FILE_NAME + +while true +do + if (sdb devices | grep $MODEL_NAME) ; then + let COUNTER+=1 + sleep 10 + sdb root on + sdb shell rm -rf /opt/usr/media/SLP_debug/* + check_bt_up_and_logging + sdb shell reboot + sleep 20 + fi + + if (sdb devices | grep $SDB_OFFLINE) ; then + let SDB_FAILURE_COUNTER+=1 + echo "SDB is offline" + if [ $SDB_FAILURE_COUNTER -eq "10" ] + then + echo "SDB is offline more than 10 sec" + sdb kill-server + sleep 8 + sdb start-server + let SDB_FAILURE_COUNTER=0 + fi + fi + sleep 1 +done + + -- cgit v1.2.3