From: DoHyun Pyun Date: Fri, 17 Jun 2016 09:23:47 +0000 (+0900) Subject: Apply the initial codes for BT emulator X-Git-Tag: accepted/tizen/common/20160620.163738^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=57d29a2109aee23e5bb4faede301999792954e36;p=platform%2Fcore%2Fconnectivity%2Fbluetooth-frwk.git Apply the initial codes for BT emulator BT on / off operation was verified. We should implement other functionalities. Change-Id: I6221b7a768d87bab51246510483c7a0fa0e5752e Signed-off-by: DoHyun Pyun --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 6018a43..52c75d6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,11 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.6) ADD_SUBDIRECTORY(bt-api) +IF("$ENV{CFLAGS}" MATCHES "-DEMUL") +ADD_SUBDIRECTORY(bt-service-emul) +ELSE() ADD_SUBDIRECTORY(bt-service) +ENDIF() ADD_SUBDIRECTORY(bt-httpproxy) diff --git a/bt-api/bt-adapter.c b/bt-api/bt-adapter.c index 3da83d4..a8a68eb 100644 --- a/bt-api/bt-adapter.c +++ b/bt-api/bt-adapter.c @@ -60,14 +60,17 @@ static int __bt_fill_device_list(GArray *out_param2, GPtrArray **dev_list) BT_EXPORT_API int bluetooth_check_adapter(void) { - int ret; int value; +#ifndef EMUL + int ret; + ret = _bt_get_adapter_path(_bt_gdbus_get_system_gconn(), NULL); if (ret != BLUETOOTH_ERROR_NONE) { return BLUETOOTH_ADAPTER_DISABLED; } +#endif /* check VCONFKEY_BT_STATUS */ if (vconf_get_int(VCONFKEY_BT_STATUS, &value) != 0) { diff --git a/bt-service-emul/CMakeLists.txt b/bt-service-emul/CMakeLists.txt new file mode 100644 index 0000000..1fe6449 --- /dev/null +++ b/bt-service-emul/CMakeLists.txt @@ -0,0 +1,102 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) +PROJECT(bt-service C) + +SET(SRCS +marshal.c +bt-service-main.c +bt-service-event-sender.c +bt-service-event-generator.c +bt-service-common.c +bt-service-util.c +bt-service-adapter.c +bt-service-adapter-le.c +bt-service-device.c +bt-service-hid.c +bt-service-network.c +bt-service-audio.c +bt-service-oob.c +bt-service-opp-client.c +bt-service-obex-server.c +bt-service-rfcomm-client.c +bt-service-rfcomm-server.c +bt-service-avrcp.c +bt-service-avrcp-controller.c +bt-request-handler.c +bt-service-pbap.c +bt-service-dpm.c +) + +IF("${CMAKE_BUILD_TYPE}" STREQUAL "") + SET(CMAKE_BUILD_TYPE "Release") +ENDIF("${CMAKE_BUILD_TYPE}" STREQUAL "") +MESSAGE("Build type: ${CMAKE_BUILD_TYPE}") + +INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include) +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include) + +SET(PKG_MODULES + vconf + aul + dbus-glib-1 + dbus-1 + gio-2.0 + alarm-service + cynara-client + cynara-creds-gdbus + eventsystem +) + +INCLUDE(FindPkgConfig) +pkg_check_modules(service_pkgs REQUIRED ${PKG_MODULES}) + +FOREACH(flag ${service_pkgs_CFLAGS}) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag} -Wall") +ENDFOREACH(flag) + +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -fPIC -Wall") +SET(CMAKE_C_FLAGS_DEBUG "-O0 -g") +SET(CMAKE_C_FLAGS_RELEASE "-O2") +SET(APP_SYSCONFDIR /opt/var/lib/bluetooth) + +FIND_PROGRAM(UNAME NAMES uname) +EXEC_PROGRAM("${UNAME}" ARGS "-m" OUTPUT_VARIABLE "ARCH") +IF("${ARCH}" STREQUAL "arm") + ADD_DEFINITIONS("-DTARGET") + MESSAGE("add -DTARGET") +ENDIF("${ARCH}" STREQUAL "arm") + +FIND_PROGRAM(MARSHALTOOL NAMES glib-genmarshal) +EXEC_PROGRAM("${MARSHALTOOL}" ARGS "--prefix=marshal ${CMAKE_CURRENT_SOURCE_DIR}/marshal.list --header > ${CMAKE_CURRENT_SOURCE_DIR}/include/marshal.h") +EXEC_PROGRAM("${MARSHALTOOL}" ARGS "--prefix=marshal ${CMAKE_CURRENT_SOURCE_DIR}/marshal.list --body > ${CMAKE_CURRENT_SOURCE_DIR}/marshal.c") + +ADD_DEFINITIONS("-DPREFIX=\"${CMAKE_INSTALL_PREFIX}\"") +ADD_DEFINITIONS("-DVENDOR=\"${APP_VENDOR}\"") +ADD_DEFINITIONS("-DAPPNAME=\"${APP_NAME}\"") +ADD_DEFINITIONS("-DAPP_DIR=\"${APP_DIR}\"") +ADD_DEFINITIONS("-DAPP_LOCALEDIR=\"${APP_LOCALEDIR}\"") +ADD_DEFINITIONS("-DAPP_SYSCONFDIR=\"${APP_SYSCONFDIR}\"") +ADD_DEFINITIONS("-DTIZEN_DPM_ENABLE") + +SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -pie") + +ADD_EXECUTABLE(${PROJECT_NAME} ${SRCS}) +TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${service_pkgs_LDFLAGS}) + +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/org.projectx.bt.service DESTINATION share/dbus-1/system-services) +INSTALL(TARGETS ${PROJECT_NAME} DESTINATION bin) + +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/auto-pair-blacklist DESTINATION /opt/var/lib/bluetooth/) + +# install booting script +CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/bluetooth-frwk-service.conf.in ${CMAKE_CURRENT_SOURCE_DIR}/bluetooth-frwk-service.conf) + +IF (TIZEN_WEARABLE) + INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/wearable/stack_info DESTINATION /usr/etc/bluetooth/) +ELSE () + INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/mobile/stack_info DESTINATION /usr/etc/bluetooth/) +ENDIF (TIZEN_WEARABLE) + +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/bluetooth-frwk-service.conf DESTINATION /etc/dbus-1/system.d) + +SET(PREFIX ${CMAKE_INSTALL_PREFIX}) + diff --git a/bt-service-emul/auto-pair-blacklist b/bt-service-emul/auto-pair-blacklist new file mode 100644 index 0000000..9f15b76 --- /dev/null +++ b/bt-service-emul/auto-pair-blacklist @@ -0,0 +1,4 @@ +AddressBlacklist=00:02:C7,00:16:FE,00:19:C1,00:1B:FB,00:1E:3D,00:21:4F,00:23:06,00:24:33,00:A0:79,00:0E:6D,00:13:E0,00:21:E8,00:60:57,00:0E:9F,00:12:1C,00:18:91,00:18:96,00:13:04,00:16:FD,00:22:A0,00:0B:4C,00:60:6F,00:23:3D,00:C0:59,00:0A:30,00:1E:AE,00:1C:D7,00:80:F0,00:12:8A,00:09:93,00:80:37,00:26:7E,00:1A:1B,00:14:9A,00:0B:24,08:76:95,00:14:09,00:1E:B2 +ExactNameBlacklist=Motorola IHF1000,i.TechBlueBAND,X5 Stereo v1.3,KML_CAN,SYNC,UConnect +PartialNameBlacklist=BMW,Audi,Parrot,HandsFreeLink,Car,MB PhoneSystem,CAR MULTIMEDIA,MB Bluetooth,Pama +KeyboardAutoPair=00:0F:F6 diff --git a/bt-service-emul/bluetooth-frwk-service b/bt-service-emul/bluetooth-frwk-service new file mode 100644 index 0000000..7533d97 --- /dev/null +++ b/bt-service-emul/bluetooth-frwk-service @@ -0,0 +1,9 @@ +#!/bin/sh + +# +# Script for running BT Service during booting time +# + +if [ -x /usr/bin/bt-service ]; then + /usr/bin/bt-service & +fi diff --git a/bt-service-emul/bluetooth-frwk-service.conf.in b/bt-service-emul/bluetooth-frwk-service.conf.in new file mode 100644 index 0000000..8fc61f5 --- /dev/null +++ b/bt-service-emul/bluetooth-frwk-service.conf.in @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/bt-service-emul/bt-request-handler.c b/bt-service-emul/bt-request-handler.c new file mode 100644 index 0000000..f3b0055 --- /dev/null +++ b/bt-service-emul/bt-request-handler.c @@ -0,0 +1,2837 @@ +/* + * 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-api.h" +#include "bt-service-common.h" +#include "bt-service-util.h" +#include "bt-service-event.h" +#include "bt-service-adapter.h" +#include "bt-service-adapter-le.h" +#include "bt-service-device.h" +#include "bt-service-hid.h" +#include "bt-service-network.h" +#include "bt-service-audio.h" +#include "bt-service-oob.h" +#include "bt-service-avrcp.h" +#include "bt-service-avrcp-controller.h" +#include "bt-service-opp-client.h" +#include "bt-service-obex-server.h" +#include "bt-service-rfcomm-client.h" +#include "bt-service-rfcomm-server.h" +#include "bt-request-handler.h" +#include "bt-service-pbap.h" +#include "bt-service-dpm.h" + +static GDBusConnection *bt_service_conn; +static guint owner_id = 0; +cynara *p_cynara; +cynara_configuration *conf; + +static const gchar bt_service_introspection_xml[] = +"" +" " +" " + /* Input Parameters */ +" " +" " +" " +" " +" " +" " +" " +" " + /* Return Parameters */ +" " +" " +" " +" " +""; + +GDBusNodeInfo *node_info = NULL; + +static void __bt_service_method(GDBusConnection *connection, + const gchar *sender, + const gchar *object_path, + const gchar *interface_name, + const gchar *method_name, + GVariant *parameters, + GDBusMethodInvocation *invocation, + gpointer user_data); + +int __bt_bluez_request(int function_name, + int request_type, + int request_id, + GDBusMethodInvocation *context, + GVariant *in_param1, + GVariant *in_param2, + GVariant *in_param3, + GVariant *in_param4, + GArray **out_param1); +int __bt_obexd_request(int function_name, + int request_type, + int request_id, + GDBusMethodInvocation *context, + GVariant *in_param1, + GVariant *in_param2, + GVariant *in_param3, + GVariant *in_param4, + GVariant *in_param5, + GArray **out_param1); +int __bt_agent_request(int function_name, + int request_type, + int request_id, + GDBusMethodInvocation *context, + GVariant *in_param1, + GVariant *in_param2, + GVariant *in_param3, + GVariant *in_param4, + GArray **out_param1); +int __bt_core_request(int function_name, + int request_type, + int request_id, + GDBusMethodInvocation *context, + GVariant *in_param1); + +gboolean __bt_service_check_privilege(int function_name, + int service_type, + const char *unique_name); + +/* Function definitions*/ +static void __bt_fill_garray_from_variant(GVariant *var, GArray *param) +{ + char *data; + int size; + + size = g_variant_get_size(var); + if (size > 0) { + data = (char *)g_variant_get_data(var); + if (data) + param = g_array_append_vals(param, data, size); + + } +} + +static void __bt_service_get_parameters(GVariant *in_param, + void *value, int size) +{ + void *buf = NULL; + buf = (void *)g_variant_get_data(in_param); + memcpy(value, buf, size); +} + +static void __bt_service_method(GDBusConnection *connection, + const gchar *sender, + const gchar *object_path, + const gchar *interface_name, + const gchar *method_name, + GVariant *parameters, + GDBusMethodInvocation *invocation, + gpointer user_data) +{ + FN_START; + BT_DBG("Method[%s] Object Path[%s] Interface Name[%s]", + method_name, object_path, interface_name); + + if (g_strcmp0(method_name, "service_request") == 0) { + int service_type; + int service_function; + int request_type; + GVariant *param1 = NULL; + GVariant *param2 = NULL; + GVariant *param3 = NULL; + GVariant *param4 = NULL; + GVariant *param5 = NULL; + GArray *out_param1 = NULL; + GVariant *out_var = NULL; + int result = 0; + int request_id = -1; + const char *sender = NULL; + + g_variant_get(parameters, "(iii@ay@ay@ay@ay@ay)", &service_type, + &service_function, &request_type, + ¶m1, ¶m2, ¶m3, ¶m4, ¶m5); + + out_param1 = g_array_new(FALSE, FALSE, sizeof(gchar)); + + sender = g_dbus_method_invocation_get_sender(invocation); + + if (service_type == BT_CORE_SERVICE) { + BT_DBG("No need to check privilege from bt-core"); + } else if (__bt_service_check_privilege(service_function, + service_type, (const char *)sender) == FALSE) { + BT_ERR("Client don't have the privilege to excute this function"); + result = BLUETOOTH_ERROR_PERMISSION_DEINED; + goto fail; + } + + if (request_type == BT_ASYNC_REQ + || service_function == BT_OBEX_SERVER_ACCEPT_CONNECTION) { + /* Set the timer */ + request_id = _bt_assign_request_id(); + BT_DBG("Request ID: %d", request_id); + + if (request_id < 0) { + BT_ERR("Fail to assign the request id"); + result = BLUETOOTH_ERROR_INTERNAL; + + goto fail; + } + } + + BT_DBG("SERVICE TYPE [%d] SERVICE FUNC [%d]", + service_type, service_function); + switch (service_type) { + case BT_BLUEZ_SERVICE: + result = __bt_bluez_request(service_function, + request_type, request_id, + invocation, param1, param2, + param3, param4, &out_param1); + break; + case BT_OBEX_SERVICE: + result = __bt_obexd_request(service_function, + request_type, request_id, + invocation, param1, + param2, param3, + param4, param5, &out_param1); + break; + case BT_AGENT_SERVICE: + result = __bt_agent_request(service_function, + request_type, request_id, + invocation, param1, + param2, param3, + param4, &out_param1); + break; + case BT_CORE_SERVICE: + result = __bt_core_request(service_function, + request_type, request_id, + invocation, param1); + break; + case BT_CHECK_PRIVILEGE: + result = BLUETOOTH_ERROR_NONE; + break; + default: + BT_ERR("Unknown service type"); + result = BLUETOOTH_ERROR_INTERNAL; + goto fail; + } + + if (result != BLUETOOTH_ERROR_NONE) { + goto fail; + } + + if ((request_type == BT_ASYNC_REQ || + service_function == BT_OBEX_SERVER_ACCEPT_CONNECTION) && + service_function != BT_OPP_PUSH_FILES) { + BT_DBG("INSERT INTO REQ LIST"); + _bt_insert_request_list(request_id, service_function, + NULL, invocation); + } else { + /* Return result */ + if (service_type == BT_CHECK_PRIVILEGE || + service_function != BT_OPP_PUSH_FILES) { + out_var = g_variant_new_from_data((const GVariantType *)"ay", + out_param1->data, out_param1->len, + TRUE, NULL, NULL); + + GVariant *temp = g_variant_new("(iv)", result, out_var); + g_dbus_method_invocation_return_value(invocation, temp); + + g_array_free(out_param1, TRUE); + out_param1 = NULL; + } + } + + g_variant_unref(param1); + g_variant_unref(param2); + g_variant_unref(param3); + g_variant_unref(param4); + g_variant_unref(param5); +// g_free(sender); + FN_END; + return; +fail: + BT_ERR_C("Request is failed [%s] [%x]", + _bt_convert_error_to_string(result), result); + + out_var = g_variant_new_from_data((const GVariantType *)"ay", + out_param1->data, out_param1->len, + TRUE, NULL, NULL); + + GVariant *temp = g_variant_new("(iv)", result, out_var); + g_dbus_method_invocation_return_value(invocation, temp); + + g_array_free(out_param1, TRUE); + out_param1 = NULL; + + if (request_type == BT_ASYNC_REQ) + _bt_delete_request_id(request_id); + + g_variant_unref(param1); + g_variant_unref(param2); + g_variant_unref(param3); + g_variant_unref(param4); + g_variant_unref(param5); +// g_free(sender); + } + + FN_END; + return; +} + + +static const GDBusInterfaceVTable method_table = { + __bt_service_method, + NULL, + NULL, +}; + +int __bt_bluez_request(int function_name, + int request_type, + int request_id, + GDBusMethodInvocation *context, + GVariant *in_param1, + GVariant *in_param2, + GVariant *in_param3, + GVariant *in_param4, + GArray **out_param1) +{ + int result = BLUETOOTH_ERROR_NONE; + + switch (function_name) { + case BT_ENABLE_ADAPTER: + result = _bt_enable_adapter(); + break; + case BT_DISABLE_ADAPTER: + result = _bt_disable_adapter(); + break; + case BT_RECOVER_ADAPTER: + result = _bt_recover_adapter(); + break; + case BT_ENABLE_ADAPTER_LE: + result = _bt_enable_adapter_le(); + break; + case BT_DISABLE_ADAPTER_LE: + result = _bt_disable_adapter_le(); + break; + case BT_RESET_ADAPTER: + result = _bt_reset_adapter(); + break; + case BT_CHECK_ADAPTER: { + int enabled = BT_ADAPTER_DISABLED; + + result = _bt_check_adapter(&enabled); + + g_array_append_vals(*out_param1, &enabled, + sizeof(int)); + break; + } + case BT_GET_LOCAL_ADDRESS: { + bluetooth_device_address_t local_address = { {0} }; + result = _bt_get_local_address(&local_address); + + g_array_append_vals(*out_param1, &local_address, + sizeof(bluetooth_device_address_t)); + break; + } + case BT_GET_LOCAL_VERSION: { + bluetooth_version_t ver = { {0} }; + result = _bt_get_local_version(&ver); + + g_array_append_vals(*out_param1, &ver, + sizeof(bluetooth_version_t)); + break; + } + case BT_GET_LOCAL_NAME: { + bluetooth_device_name_t local_name = { {0} }; + result = _bt_get_local_name(&local_name); + + g_array_append_vals(*out_param1, &local_name, + sizeof(bluetooth_device_name_t)); + + break; + } + case BT_SET_LOCAL_NAME: { + bluetooth_device_name_t local_name = { {0} }; + __bt_service_get_parameters(in_param1, + &local_name, sizeof(bluetooth_device_name_t)); + + result = _bt_set_local_name(local_name.name); + + break; + } + case BT_IS_SERVICE_USED: { + char *uuid; + gboolean used = FALSE; + + uuid = (char *)g_variant_get_data(in_param1); + + result = _bt_is_service_used(uuid, &used); + + if (result == BLUETOOTH_ERROR_NONE) { + g_array_append_vals(*out_param1, &used, + sizeof(gboolean)); + } + break; + } + case BT_GET_DISCOVERABLE_MODE: { + int mode = BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE; + + result = _bt_get_discoverable_mode(&mode); + + g_array_append_vals(*out_param1, &mode, sizeof(int)); + break; + } + case BT_SET_DISCOVERABLE_MODE: { + int mode = BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE; + int time = 0; + + __bt_service_get_parameters(in_param1, &mode, sizeof(int)); + __bt_service_get_parameters(in_param2, &time, sizeof(int)); + + result = _bt_set_discoverable_mode(mode, time); + break; + } + case BT_GET_DISCOVERABLE_TIME: { + int timeout = 0; + + result = _bt_get_timeout_value(&timeout); + + g_array_append_vals(*out_param1, &timeout, sizeof(int)); + break; + } + case BT_START_DISCOVERY: + result = _bt_start_discovery(); + + break; + case BT_START_CUSTOM_DISCOVERY: { + bt_discovery_role_type_t role; + + __bt_service_get_parameters(in_param1, + &role, sizeof(bt_discovery_role_type_t)); + result = _bt_start_custom_discovery(role); + + break; + } + case BT_CANCEL_DISCOVERY: + result = _bt_cancel_discovery(); + break; + case BT_IS_DISCOVERYING: { + gboolean discovering = FALSE; + discovering = _bt_is_discovering(); + g_array_append_vals(*out_param1, + &discovering, sizeof(gboolean)); + break; + } + case BT_START_LE_DISCOVERY: { + char *sender = NULL; + + sender = (char *)g_dbus_method_invocation_get_sender(context); + result = _bt_start_le_scan(sender); + + break; + } + case BT_STOP_LE_DISCOVERY: { + char *sender = NULL; + + sender = (char *)g_dbus_method_invocation_get_sender(context); + result = _bt_stop_le_scan(sender); + + break; + } + case BT_IS_LE_DISCOVERYING: { + gboolean le_discovering = FALSE; + + le_discovering = _bt_is_le_scanning(); + g_array_append_vals(*out_param1, + &le_discovering, sizeof(gboolean)); + + break; + } + case BT_REGISTER_SCAN_FILTER: { + char *sender = NULL; + bluetooth_le_scan_filter_t scan_filter; + int slot_id; + + sender = (char *)g_dbus_method_invocation_get_sender(context); + __bt_service_get_parameters(in_param1, &scan_filter, + sizeof(bluetooth_le_scan_filter_t)); + BT_DBG("bluetooth_le_scan_filter_t [features : %.2x]", + scan_filter.added_features); + + result = _bt_register_scan_filter(sender, + &scan_filter, &slot_id); + + g_array_append_vals(*out_param1, &slot_id, sizeof(int)); + break; + } + case BT_UNREGISTER_SCAN_FILTER:{ + char *sender = NULL; + int slot_id; + + sender = (char *)g_dbus_method_invocation_get_sender(context); + __bt_service_get_parameters(in_param1, &slot_id, sizeof(int)); + BT_DBG("Remove scan filter [Slot ID : %d]", slot_id); + + result = _bt_unregister_scan_filter(sender, slot_id); + + break; + } + case BT_UNREGISTER_ALL_SCAN_FILTERS:{ + char *sender = NULL; + + sender = (char *)g_dbus_method_invocation_get_sender(context); + + BT_DBG("Remove all scan filters [Sender : %s]", sender); + + result = _bt_unregister_all_scan_filters(sender); + + break; + } + case BT_ENABLE_RSSI: { + bluetooth_device_address_t bd_addr; + int link_type; + bt_rssi_threshold_t rssi_threshold; + int low_threshold; + int in_range_threshold; + int high_threshold; + + BT_DBG("Enable RSSI"); + + __bt_service_get_parameters(in_param1, + &bd_addr, sizeof(bluetooth_device_address_t)); + __bt_service_get_parameters(in_param2, + &link_type, sizeof(int)); + __bt_service_get_parameters(in_param3, + &rssi_threshold, sizeof(bt_rssi_threshold_t)); + + low_threshold = rssi_threshold.low_threshold; + in_range_threshold = rssi_threshold.in_range_threshold; + high_threshold = rssi_threshold.high_threshold; + + result = _bt_enable_rssi(&bd_addr, + link_type, low_threshold, + in_range_threshold, high_threshold); + break; + } + case BT_GET_RSSI: { + int link_type; + bluetooth_device_address_t bd_addr; + + BT_DBG("Get RSSI Strength"); + + __bt_service_get_parameters(in_param1, + &bd_addr, sizeof(bluetooth_device_address_t)); + __bt_service_get_parameters(in_param2, + &link_type, sizeof(int)); + + result = _bt_get_rssi_strength(&bd_addr, link_type); + break; + } + case BT_IS_CONNECTABLE: { + gboolean is_connectable; + + is_connectable = _bt_is_connectable(); + g_array_append_vals(*out_param1, + &is_connectable, sizeof(gboolean)); + break; + } + case BT_SET_CONNECTABLE: { + gboolean is_connectable; + + __bt_service_get_parameters(in_param1, + &is_connectable, sizeof(gboolean)); + result = _bt_set_connectable(is_connectable); + break; + } + case BT_SET_ADVERTISING: { + char *sender = NULL; + int adv_handle; + gboolean enable = FALSE; + gboolean use_reserved_slot = FALSE; + + __bt_service_get_parameters(in_param1, + &adv_handle, sizeof(int)); + __bt_service_get_parameters(in_param2, + &enable, sizeof(gboolean)); + __bt_service_get_parameters(in_param3, + &use_reserved_slot, sizeof(gboolean)); + + sender = (char *)g_dbus_method_invocation_get_sender(context); + + result = _bt_set_advertising(sender, adv_handle, + enable, use_reserved_slot); + break; + } + case BT_SET_CUSTOM_ADVERTISING: { + char *sender = NULL; + int adv_handle; + gboolean enable = FALSE; + bluetooth_advertising_params_t adv_params; + gboolean use_reserved_slot = FALSE; + + sender = (char *)g_dbus_method_invocation_get_sender(context); + + __bt_service_get_parameters(in_param1, &adv_handle, + sizeof(int)); + __bt_service_get_parameters(in_param2, &enable, + sizeof(gboolean)); + __bt_service_get_parameters(in_param3, &adv_params, + sizeof(bluetooth_advertising_params_t)); + __bt_service_get_parameters(in_param4, &use_reserved_slot, + sizeof(gboolean)); + + BT_DBG("bluetooth_advertising_params_t [%f %f %d %d]", + adv_params.interval_min, adv_params.interval_max, + adv_params.filter_policy, adv_params.type); + result = _bt_set_custom_advertising(sender, adv_handle, + enable, &adv_params, use_reserved_slot); + break; + } + case BT_GET_ADVERTISING_DATA: { + bluetooth_advertising_data_t adv = { {0} }; + int length = 0; + + result = _bt_get_advertising_data(&adv, &length); + if (result == BLUETOOTH_ERROR_NONE) { + g_array_append_vals(*out_param1, adv.data, length); + } + break; + } + case BT_SET_ADVERTISING_DATA: { + char *sender = NULL; + int adv_handle; + bluetooth_advertising_data_t adv = { {0} }; + int length; + gboolean use_reserved_slot = FALSE; + + sender = (char *)g_dbus_method_invocation_get_sender(context); + + __bt_service_get_parameters(in_param1, + &adv_handle, sizeof(int)); + __bt_service_get_parameters(in_param2, + &adv, sizeof(bluetooth_advertising_data_t)); + __bt_service_get_parameters(in_param3, + &length, sizeof(int)); + __bt_service_get_parameters(in_param4, + &use_reserved_slot, sizeof(gboolean)); + + result = _bt_set_advertising_data(sender, adv_handle, + &adv, length, use_reserved_slot); + break; + } + case BT_GET_SCAN_RESPONSE_DATA: { + bluetooth_scan_resp_data_t rsp = { {0} }; + int length = 0; + + result = _bt_get_scan_response_data(&rsp, &length); + if (result == BLUETOOTH_ERROR_NONE) { + g_array_append_vals(*out_param1, rsp.data, length); + } + + break; + } + case BT_SET_SCAN_RESPONSE_DATA: { + char *sender = NULL; + int adv_handle; + bluetooth_scan_resp_data_t rsp = { {0} }; + int length; + gboolean use_reserved_slot = FALSE; + + sender = (char *)g_dbus_method_invocation_get_sender(context); + + __bt_service_get_parameters(in_param1, + &adv_handle, sizeof(int)); + __bt_service_get_parameters(in_param2, + &rsp, sizeof(bluetooth_scan_resp_data_t)); + __bt_service_get_parameters(in_param3, + &length, sizeof(int)); + __bt_service_get_parameters(in_param4, + &use_reserved_slot, sizeof(gboolean)); + + result = _bt_set_scan_response_data(sender, adv_handle, + &rsp, length, use_reserved_slot); + + break; + } + case BT_SET_MANUFACTURER_DATA: { + bluetooth_manufacturer_data_t m_data = { 0 }; + __bt_service_get_parameters(in_param1, + &m_data, sizeof(bluetooth_manufacturer_data_t)); + + result = _bt_set_manufacturer_data(&m_data); + break; + } + case BT_SET_SCAN_PARAMETERS: { + bluetooth_le_scan_params_t scan_params; + __bt_service_get_parameters(in_param1, &scan_params, + sizeof(bluetooth_le_scan_params_t)); + + BT_DBG("bluetooth_le_scan_params_t [%f %f %d]", + scan_params.interval, scan_params.window, + scan_params.type); + + result = _bt_set_scan_parameters(&scan_params); + break; + } + case BT_LE_CONN_UPDATE: { + bluetooth_device_address_t local_address = { {0} }; + bluetooth_le_connection_param_t parameters = {0}; + + __bt_service_get_parameters(in_param1, &local_address, + sizeof(bluetooth_device_address_t)); + __bt_service_get_parameters(in_param2, ¶meters, + sizeof(bluetooth_le_connection_param_t)); + + result = _bt_le_conn_update(local_address.addr, + parameters.interval_min, + parameters.interval_max, + parameters.latency, + parameters.timeout); + break; + } + case BT_IS_ADVERTISING: { + gboolean advertising = FALSE; + advertising = _bt_is_advertising(); + + g_array_append_vals(*out_param1, &advertising, + sizeof(gboolean)); + break; + } + case BT_ADD_WHITE_LIST: { + bluetooth_device_address_t address = { {0} }; + int addr_type = 0; + + __bt_service_get_parameters(in_param1, &address, + sizeof(bluetooth_device_address_t)); + __bt_service_get_parameters(in_param2, &addr_type, + sizeof(int)); + + result = _bt_add_white_list(&address, addr_type); + break; + } + case BT_REMOVE_WHITE_LIST: { + bluetooth_device_address_t address = { {0} }; + int addr_type = 0; + + __bt_service_get_parameters(in_param1, + &address, sizeof(bluetooth_device_address_t)); + __bt_service_get_parameters(in_param2, + &addr_type, sizeof(int)); + + result = _bt_remove_white_list(&address, addr_type); + break; + } + case BT_CLEAR_WHITE_LIST: { + result = _bt_clear_white_list(); + break; + } + case BT_GET_BONDED_DEVICES: { + result = _bt_get_bonded_devices(out_param1); + break; + } + case BT_GET_BONDED_DEVICE: { + bluetooth_device_address_t address = { {0} }; + bluetooth_device_info_t dev_info; + + __bt_service_get_parameters(in_param1, + &address, sizeof(bluetooth_device_address_t)); + + memset(&dev_info, 0x00, sizeof(bluetooth_device_info_t)); + result = _bt_get_bonded_device_info(&address, &dev_info); + + if (result == BLUETOOTH_ERROR_NONE) { + g_array_append_vals(*out_param1, &dev_info, + sizeof(bluetooth_device_info_t)); + } + break; + } + case BT_BOND_DEVICE: { + bluetooth_device_address_t address = { {0} }; + + __bt_service_get_parameters(in_param1, + &address, sizeof(bluetooth_device_address_t)); + + result = _bt_bond_device(request_id, &address, + BLUETOOTH_DEV_CONN_DEFAULT, out_param1); + break; + } + case BT_BOND_DEVICE_BY_TYPE: { + bluetooth_device_address_t address = { {0} }; + unsigned short conn_type = 0; + + __bt_service_get_parameters(in_param1, + &address, sizeof(bluetooth_device_address_t)); + __bt_service_get_parameters(in_param2, + &conn_type, sizeof(unsigned short)); + + result = _bt_bond_device(request_id, &address, + conn_type, out_param1); + break; + } + case BT_CANCEL_BONDING: { + result = _bt_cancel_bonding(); + break; + } + case BT_PASSKEY_REPLY: { + const char *passkey = NULL; + gboolean authentication_reply = FALSE; + + passkey = g_variant_get_data(in_param1); + __bt_service_get_parameters(in_param2, + &authentication_reply, sizeof(gboolean)); + result = _bt_passkey_reply(passkey, authentication_reply); + break; + } + case BT_PASSKEY_CONFIRMATION_REPLY: { + gboolean confirmation_reply = FALSE; + + __bt_service_get_parameters(in_param1, + &confirmation_reply, sizeof(gboolean)); + result = _bt_passkey_confirmation_reply(confirmation_reply); + break; + } + case BT_UNBOND_DEVICE: { + bluetooth_device_address_t address = { {0} }; + + __bt_service_get_parameters(in_param1, + &address, sizeof(bluetooth_device_address_t)); + + result = _bt_unbond_device(request_id, &address, out_param1); + + break; + } + case BT_SET_ALIAS: { + bluetooth_device_address_t address = { {0} }; + const char *local_name; + + __bt_service_get_parameters(in_param1, + &address, sizeof(bluetooth_device_address_t)); + local_name = (const char *)g_variant_get_data(in_param2); + + result = _bt_set_alias(&address, local_name); + break; + } + case BT_SEARCH_SERVICE: { + bluetooth_device_address_t address = { {0} }; + + __bt_service_get_parameters(in_param1, + &address, sizeof(bluetooth_device_address_t)); + + result = _bt_search_device(request_id, &address); + if (result != BLUETOOTH_ERROR_NONE) { + g_array_append_vals(*out_param1, &address, + sizeof(bluetooth_device_address_t)); + } + break; + } + case BT_CANCEL_SEARCH_SERVICE: { + result = _bt_cancel_search_device(); + break; + } + case BT_SET_AUTHORIZATION: { + bluetooth_device_address_t address = { {0} }; + gboolean authorize; + + __bt_service_get_parameters(in_param1, + &address, sizeof(bluetooth_device_address_t)); + __bt_service_get_parameters(in_param2, + &authorize, sizeof(gboolean)); + + result = _bt_set_authorization(&address, authorize); + break; + } + case BT_IS_DEVICE_CONNECTED: { + bluetooth_device_address_t address = { {0} }; + int type; + gboolean connected = FALSE; + + __bt_service_get_parameters(in_param1, + &address, sizeof(bluetooth_device_address_t)); + __bt_service_get_parameters(in_param2, + &type, sizeof(int)); + + result = _bt_is_device_connected(&address, type, &connected); + BT_DBG("is_connected: %d", connected); + if (result == BLUETOOTH_ERROR_NONE) { + g_array_append_vals(*out_param1, &connected, + sizeof(gboolean)); + } + + break; + } + case BT_GET_CONNECTED_LINK_TYPE: { + bluetooth_device_address_t address = { {0} }; + bluetooth_connected_link_t connected = BLUETOOTH_CONNECTED_LINK_NONE; + + __bt_service_get_parameters(in_param1, + &address, sizeof(bluetooth_device_address_t)); + + result = _bt_get_connected_link(&address, &connected); + + if (result == BLUETOOTH_ERROR_NONE) { + g_array_append_vals(*out_param1, &connected, + sizeof(guint)); + } + + break; + } + case BT_SET_PIN_CODE: { + bluetooth_device_address_t address = { {0} }; + bluetooth_device_pin_code_t pin_code = { {0} }; + + __bt_service_get_parameters(in_param1, + &address, sizeof(bluetooth_device_address_t)); + __bt_service_get_parameters(in_param2, + &pin_code, sizeof(bluetooth_device_pin_code_t)); + + result = _bt_set_pin_code(&address, &pin_code); + break; + } + case BT_UNSET_PIN_CODE: { + bluetooth_device_address_t address = { {0} }; + + __bt_service_get_parameters(in_param1, + &address, sizeof(bluetooth_device_address_t)); + + result = _bt_unset_pin_code(&address); + break; + } + case BT_UPDATE_LE_CONNECTION_MODE: { + bluetooth_device_address_t remote_address = { { 0 } }; + bluetooth_le_connection_param_t param = { 0 }; + bluetooth_le_connection_mode_t mode = BLUETOOTH_LE_CONNECTION_MODE_BALANCED; + + __bt_service_get_parameters(in_param1, &remote_address, + sizeof(bluetooth_device_address_t)); + __bt_service_get_parameters(in_param2, &mode, + sizeof(bluetooth_le_connection_mode_t)); + + result = _bt_get_le_connection_parameter(mode, ¶m); + if (result != BLUETOOTH_ERROR_NONE) + break; + + result = _bt_le_conn_update(remote_address.addr, + param.interval_min, + param.interval_max, + param.latency, + param.timeout); + break; + } + + case BT_HID_CONNECT: { + bluetooth_device_address_t address = { {0} }; + + __bt_service_get_parameters(in_param1, + &address, sizeof(bluetooth_device_address_t)); + + result = _bt_hid_connect(request_id, &address); + if (result != BLUETOOTH_ERROR_NONE) { + g_array_append_vals(*out_param1, &address, + sizeof(bluetooth_device_address_t)); + } + break; + } + case BT_HID_DISCONNECT: { + bluetooth_device_address_t address = { {0} }; + + __bt_service_get_parameters(in_param1, + &address, sizeof(bluetooth_device_address_t)); + + result = _bt_hid_disconnect(request_id, &address); + if (result != BLUETOOTH_ERROR_NONE) { + g_array_append_vals(*out_param1, &address, + sizeof(bluetooth_device_address_t)); + } + break; + } + case BT_NETWORK_ACTIVATE: + result = _bt_network_activate(); + break; + case BT_NETWORK_DEACTIVATE: + result = _bt_network_deactivate(); + break; + case BT_NETWORK_CONNECT: { + bluetooth_device_address_t address = { {0} }; + int role; + + __bt_service_get_parameters(in_param1, + &address, sizeof(bluetooth_device_address_t)); + __bt_service_get_parameters(in_param2, + &role, sizeof(int)); + + result = _bt_network_connect(request_id, role, &address); + if (result != BLUETOOTH_ERROR_NONE) { + g_array_append_vals(*out_param1, &address, + sizeof(bluetooth_device_address_t)); + } + break; + } + case BT_NETWORK_DISCONNECT: { + bluetooth_device_address_t address = { {0} }; + + __bt_service_get_parameters(in_param1, + &address, sizeof(bluetooth_device_address_t)); + + result = _bt_network_disconnect(request_id, &address); + if (result != BLUETOOTH_ERROR_NONE) { + g_array_append_vals(*out_param1, &address, + sizeof(bluetooth_device_address_t)); + } + break; + } + case BT_NETWORK_SERVER_DISCONNECT: { + bluetooth_device_address_t address = { {0} }; + + __bt_service_get_parameters(in_param1, + &address, sizeof(bluetooth_device_address_t)); + + result = _bt_network_server_disconnect(request_id, &address); + if (result != BLUETOOTH_ERROR_NONE) { + g_array_append_vals(*out_param1, &address, + sizeof(bluetooth_device_address_t)); + } + break; + } + + case BT_AUDIO_CONNECT: { + bluetooth_device_address_t address = { {0} }; + + __bt_service_get_parameters(in_param1, + &address, sizeof(bluetooth_device_address_t)); + + result = _bt_audio_connect(request_id, BT_AUDIO_ALL, + &address, out_param1); + break; + } + case BT_AUDIO_DISCONNECT: { + bluetooth_device_address_t address = { {0} }; + + __bt_service_get_parameters(in_param1, + &address, sizeof(bluetooth_device_address_t)); + + result = _bt_audio_disconnect(request_id, BT_AUDIO_ALL, + &address, out_param1); + break; + } + case BT_AG_CONNECT: { + bluetooth_device_address_t address = { {0} }; + + __bt_service_get_parameters(in_param1, + &address, sizeof(bluetooth_device_address_t)); + + result = _bt_audio_connect(request_id, BT_AUDIO_HSP, + &address, out_param1); + break; + } + case BT_AG_DISCONNECT: { + bluetooth_device_address_t address = { {0} }; + + __bt_service_get_parameters(in_param1, + &address, sizeof(bluetooth_device_address_t)); + + result = _bt_audio_disconnect(request_id, BT_AUDIO_HSP, + &address, out_param1); + break; + } + case BT_AV_CONNECT: { + bluetooth_device_address_t address = { {0} }; + + __bt_service_get_parameters(in_param1, + &address, sizeof(bluetooth_device_address_t)); + + result = _bt_audio_connect(request_id, BT_AUDIO_A2DP, + &address, out_param1); + break; + } + case BT_AV_DISCONNECT: { + bluetooth_device_address_t address = { {0} }; + + __bt_service_get_parameters(in_param1, + &address, sizeof(bluetooth_device_address_t)); + + result = _bt_audio_disconnect(request_id, BT_AUDIO_A2DP, + &address, out_param1); + break; + } + case BT_AVRCP_CONTROL_CONNECT: { + bluetooth_device_address_t address = { {0} }; + + __bt_service_get_parameters(in_param1, + &address, sizeof(bluetooth_device_address_t)); + + result = _bt_audio_connect(request_id, BT_AVRCP, + &address, out_param1); + break; + } + case BT_AVRCP_CONTROL_DISCONNECT: { + bluetooth_device_address_t address = { {0} }; + + __bt_service_get_parameters(in_param1, + &address, sizeof(bluetooth_device_address_t)); + + result = _bt_audio_disconnect(request_id, BT_AVRCP, + &address, out_param1); + break; + } + case BT_AV_SOURCE_CONNECT: { + bluetooth_device_address_t address = { {0} }; + + __bt_service_get_parameters(in_param1, &address, + sizeof(bluetooth_device_address_t)); + + result = _bt_audio_connect(request_id, BT_AUDIO_A2DP_SOURCE, + &address, out_param1); + break; + } + case BT_AV_SOURCE_DISCONNECT: { + bluetooth_device_address_t address = { {0} }; + + __bt_service_get_parameters(in_param1, &address, + sizeof(bluetooth_device_address_t)); + + result = _bt_audio_disconnect(request_id, BT_AUDIO_A2DP_SOURCE, + &address, out_param1); + break; + } + case BT_HF_CONNECT: { + bluetooth_device_address_t address = { {0} }; + + __bt_service_get_parameters(in_param1, + &address, sizeof(bluetooth_device_address_t)); + + result = _bt_hf_connect(request_id, &address, out_param1); + break; + } + case BT_HF_DISCONNECT: { + bluetooth_device_address_t address = { {0} }; + + __bt_service_get_parameters(in_param1, + &address, sizeof(bluetooth_device_address_t)); + + result = _bt_hf_disconnect(request_id, &address, out_param1); + break; + } + case BT_SET_CONTENT_PROTECT: { + gboolean status; + + __bt_service_get_parameters(in_param1, + &status, sizeof(gboolean)); + + result = _bt_audio_set_content_protect(status); + + break; + } + case BT_OOB_READ_LOCAL_DATA: { + bt_oob_data_t local_oob_data; + + memset(&local_oob_data, 0x00, sizeof(bt_oob_data_t)); + result = _bt_oob_read_local_data(&local_oob_data); + + g_array_append_vals(*out_param1, &local_oob_data, + sizeof(bt_oob_data_t)); + + break; + } + case BT_OOB_ADD_REMOTE_DATA: { + bluetooth_device_address_t address = { {0} }; + bt_oob_data_t local_oob_data; + + __bt_service_get_parameters(in_param1, + &address, sizeof(bluetooth_device_address_t)); + __bt_service_get_parameters(in_param2, + &local_oob_data, sizeof(bt_oob_data_t)); + + result = _bt_oob_add_remote_data(&address, &local_oob_data); + + break; + } + case BT_OOB_REMOVE_REMOTE_DATA: { + bluetooth_device_address_t address = { {0} }; + + __bt_service_get_parameters(in_param1, + &address, sizeof(bluetooth_device_address_t)); + + result = _bt_oob_remove_remote_data(&address); + + break; + } + case BT_AVRCP_SET_TRACK_INFO: { + media_metadata_t data; + media_metadata_attributes_t meta_data; + + memset(&data, 0x00, sizeof(media_metadata_t)); + memset(&meta_data, 0x00, sizeof(media_metadata_attributes_t)); + + __bt_service_get_parameters(in_param1, + &data, sizeof(media_metadata_t)); + + meta_data.title = g_strdup(data.title); + meta_data.artist = g_strdup(data.artist); + meta_data.album = g_strdup(data.album); + meta_data.genre = g_strdup(data.genre); + meta_data.total_tracks = data.total_tracks; + meta_data.number = data.number; + meta_data.duration = (int64_t) data.duration; + + result = _bt_avrcp_set_track_info(&meta_data); + + g_free((gpointer)meta_data.title); + g_free((gpointer)meta_data.artist); + g_free((gpointer)meta_data.album); + g_free((gpointer)meta_data.genre); + + break; + } + case BT_AVRCP_SET_PROPERTY: { + int type; + unsigned int value; + + __bt_service_get_parameters(in_param1, + &type, sizeof(int)); + __bt_service_get_parameters(in_param2, + &value, sizeof(unsigned int)); + + result = _bt_avrcp_set_property(type, value); + + break; + } + case BT_AVRCP_SET_PROPERTIES: { + media_player_settings_t properties; + + memset(&properties, 0x00, sizeof(media_player_settings_t)); + __bt_service_get_parameters(in_param1, + &properties, sizeof(media_player_settings_t)); + + result = _bt_avrcp_set_properties(&properties); + + break; + } + case BT_AVRCP_HANDLE_CONTROL: { + int type; + + __bt_service_get_parameters(in_param1, &type, sizeof(int)); + + result = _bt_avrcp_control_cmd(type); + + break; + } + case BT_AVRCP_CONTROL_SET_PROPERTY: { + int type; + unsigned int value; + + __bt_service_get_parameters(in_param1, + &type, sizeof(int)); + __bt_service_get_parameters(in_param2, + &value, sizeof(unsigned int)); + + result = _bt_avrcp_control_set_property(type, value); + + break; + } + case BT_AVRCP_CONTROL_GET_PROPERTY: { + int type; + unsigned int value; + + __bt_service_get_parameters(in_param1, &type, sizeof(int)); + + result = _bt_avrcp_control_get_property(type, &value); + g_array_append_vals(*out_param1, &value, sizeof(int)); + + break; + } + case BT_AVRCP_GET_TRACK_INFO: { + media_metadata_t meta_data; + media_metadata_attributes_t metadata; + + memset(&meta_data, 0x00, sizeof(media_metadata_t)); + memset(&metadata, 0x00, sizeof(media_metadata_attributes_t)); + + result = _bt_avrcp_control_get_track_info(&metadata); + + if (BLUETOOTH_ERROR_NONE != result) + break; + + if (_bt_copy_utf8_string(meta_data.title, metadata.title, + BT_META_DATA_MAX_LEN)) + BT_ERR("Error in copying Title\n"); + if (_bt_copy_utf8_string(meta_data.artist, metadata.artist, + BT_META_DATA_MAX_LEN)) + BT_ERR("Error in copying Artist\n"); + if (_bt_copy_utf8_string(meta_data.album, metadata.album, + BT_META_DATA_MAX_LEN)) + BT_ERR("Error in copying Album\n"); + if (_bt_copy_utf8_string(meta_data.genre, metadata.genre, + BT_META_DATA_MAX_LEN)) + BT_ERR("Error in copying Genre\n"); + + if (_bt_utf8_validate(meta_data.title) == FALSE) + meta_data.title[0] = '\0'; + + if (_bt_utf8_validate(meta_data.artist) == FALSE) + meta_data.artist[0] = '\0'; + + if (_bt_utf8_validate(meta_data.album) == FALSE) + meta_data.album[0] = '\0'; + + if (_bt_utf8_validate(meta_data.genre) == FALSE) + meta_data.genre[0] = '\0'; + + meta_data.total_tracks = metadata.total_tracks; + meta_data.number = metadata.number; + meta_data.duration = metadata.duration; + + g_free((gpointer)metadata.title); + g_free((gpointer)metadata.artist); + g_free((gpointer)metadata.album); + g_free((gpointer)metadata.genre); + + g_array_append_vals(*out_param1, &meta_data, + sizeof(media_metadata_t)); + break; + } + case BT_RFCOMM_CLIENT_CONNECT: { +#ifdef RFCOMM_DIRECT + result = BLUETOOTH_ERROR_NONE; +#else + bluetooth_device_address_t address = { {0} }; + char *input_string; + int connect_type; + + __bt_service_get_parameters(in_param1, + &address, sizeof(bluetooth_device_address_t)); + + input_string = &g_array_index(in_param2, char, 0); + + connect_type = g_array_index(in_param3, int, 0); + + if (connect_type == BT_RFCOMM_UUID) { + result = _bt_rfcomm_connect_using_uuid(request_id, + &address, input_string); + } else { + result = _bt_rfcomm_connect_using_channel(request_id, + &address, input_string); + } + + if (result != BLUETOOTH_ERROR_NONE) { + g_array_append_vals(*out_param1, &address, + sizeof(bluetooth_device_address_t)); + } +#endif + break; + } + case BT_RFCOMM_CLIENT_CANCEL_CONNECT: + result = _bt_rfcomm_cancel_connect(); + break; + case BT_RFCOMM_CLIENT_IS_CONNECTED: { + gboolean connected = FALSE; + result = _bt_rfcomm_is_connected(&connected); + + g_array_append_vals(*out_param1, &connected, sizeof(gboolean)); + break; + } + case BT_RFCOMM_SOCKET_DISCONNECT: { +#ifdef RFCOMM_DIRECT + result = BLUETOOTH_ERROR_NONE; +#else + int socket_fd; + + socket_fd = g_array_index(in_param1, int, 0); + + result = _bt_rfcomm_disconnect(socket_fd); +#endif + break; + } + case BT_RFCOMM_SOCKET_WRITE: { +#ifdef RFCOMM_DIRECT + result = BLUETOOTH_ERROR_NONE; +#else + int socket_fd; + int length; + char *buffer; + + socket_fd = g_array_index(in_param1, int, 0); + length = g_array_index(in_param2, int, 0); + buffer = &g_array_index(in_param3, char, 0); + + result = _bt_rfcomm_write(socket_fd, buffer, length); +#endif + break; + } + case BT_RFCOMM_CREATE_SOCKET: { +#ifdef RFCOMM_DIRECT + result = BLUETOOTH_ERROR_NONE; +#else + char *sender; + char *uuid; + int socket_fd = -1; + + sender = (char *)g_dbus_method_invocation_get_sender(context); + uuid = &g_array_index(in_param1, char, 0); + + result = _bt_rfcomm_create_socket(sender, uuid); + + if (result > 0) { + socket_fd = result; + result = BLUETOOTH_ERROR_NONE; + } + + g_array_append_vals(*out_param1, &socket_fd, sizeof(int)); + + g_free(sender); +#endif + break; + } + case BT_RFCOMM_REMOVE_SOCKET: { +#ifdef RFCOMM_DIRECT + result = BLUETOOTH_ERROR_NONE; +#else + int socket_fd; + + socket_fd = g_array_index(in_param1, int, 0); + + result = _bt_rfcomm_remove_socket(socket_fd); +#endif + break; + } + case BT_RFCOMM_LISTEN: { + int socket_fd; + int pending; + gboolean is_native; + + __bt_service_get_parameters(in_param1, &socket_fd, + sizeof(int)); + __bt_service_get_parameters(in_param2, &pending, + sizeof(int)); + __bt_service_get_parameters(in_param3, &is_native, + sizeof(gboolean)); + + result = _bt_rfcomm_listen(socket_fd, pending, is_native); + break; + } + case BT_RFCOMM_IS_UUID_AVAILABLE: { + gboolean available = TRUE; + char *uuid; + + uuid = (char *)g_variant_get_data(in_param1); + + result = _bt_rfcomm_is_uuid_available(uuid, &available); + + g_array_append_vals(*out_param1, &available, sizeof(gboolean)); + break; + } + case BT_RFCOMM_ACCEPT_CONNECTION: { + int socket_fd; + + __bt_service_get_parameters(in_param1, &socket_fd, sizeof(int)); + BT_DBG(" socket fd %d", socket_fd); + result = _bt_rfcomm_accept_connection(); + break; + } + case BT_RFCOMM_REJECT_CONNECTION: { + int socket_fd; + + __bt_service_get_parameters(in_param1, &socket_fd, sizeof(int)); + BT_DBG(" socket fd %d", socket_fd); + result = _bt_rfcomm_reject_connection(); + break; + } + case BT_RFCOMM_CREATE_SOCKET_EX: { + result = BLUETOOTH_ERROR_NONE; + break; + } + case BT_RFCOMM_REMOVE_SOCKET_EX: { + result = BLUETOOTH_ERROR_NONE; + break; + } + case BT_CONNECT_LE: { + bluetooth_device_address_t address = { {0} }; + gboolean auto_connect; + + __bt_service_get_parameters(in_param1, + &address, sizeof(bluetooth_device_address_t)); + __bt_service_get_parameters(in_param2, + &auto_connect, sizeof(gboolean)); + + result = _bt_connect_le_device(request_id, &address, auto_connect); + if (result != BLUETOOTH_ERROR_NONE) { + g_array_append_vals(*out_param1, &address, + sizeof(bluetooth_device_address_t)); + } + break; + } + case BT_DISCONNECT_LE: { + bluetooth_device_address_t address = { {0} }; + + __bt_service_get_parameters(in_param1, &address, + sizeof(bluetooth_device_address_t)); + + result = _bt_disconnect_le_device(request_id, &address); + if (result != BLUETOOTH_ERROR_NONE) { + g_array_append_vals(*out_param1, &address, + sizeof(bluetooth_device_address_t)); + } + break; + } + case BT_SET_LE_PRIVACY: { + gboolean set_privacy; + + __bt_service_get_parameters(in_param1, &set_privacy, + sizeof(gboolean)); + + result = _bt_set_le_privacy(set_privacy); + + break; + } + case BT_HDP_CONNECT: + case BT_HDP_DISCONNECT: + case BT_HDP_SEND_DATA: + + case BT_GATT_GET_PRIMARY_SERVICES: + case BT_GATT_DISCOVER_CHARACTERISTICS: + case BT_GATT_SET_PROPERTY_REQUEST: + case BT_GATT_READ_CHARACTERISTIC: + case BT_GATT_DISCOVER_CHARACTERISTICS_DESCRIPTOR: + + case BT_HID_DEVICE_ACTIVATE: + case BT_HID_DEVICE_DEACTIVATE: + case BT_HID_DEVICE_CONNECT: + case BT_HID_DEVICE_DISCONNECT: + case BT_HID_DEVICE_SEND_MOUSE_EVENT: + case BT_HID_DEVICE_SEND_KEY_EVENT: + case BT_HID_DEVICE_SEND_REPLY_TO_REPORT: + /* Just call to check the privilege */ + break; + case BT_LE_IPSP_INIT: + result = _bt_initialize_ipsp(); + break; + case BT_LE_IPSP_DEINIT: + result = _bt_deinitialize_ipsp(); + break; + case BT_LE_IPSP_CONNECT: { + bluetooth_device_address_t address = { {0} }; + __bt_service_get_parameters(in_param1, &address, + sizeof(bluetooth_device_address_t)); + + result = _bt_connect_le_ipsp_device(&address); + break; + } + case BT_LE_IPSP_DISCONNECT: { + bluetooth_device_address_t address = { {0} }; + + __bt_service_get_parameters(in_param1, &address, + sizeof(bluetooth_device_address_t)); + + result = _bt_disconnect_le_ipsp_device(&address); + break; + } + case BT_LE_READ_MAXIMUM_DATA_LENGTH: { + bluetooth_le_read_maximum_data_length_t max_le_datalength = {0}; + + result = _bt_le_read_maximum_data_length(&max_le_datalength); + + g_array_append_vals(*out_param1, &max_le_datalength, + sizeof(bluetooth_le_read_maximum_data_length_t)); + break; + } + case BT_LE_WRITE_HOST_SUGGESTED_DATA_LENGTH: { + unsigned int def_tx_Octects = 0; + unsigned int def_tx_Time = 0; + + __bt_service_get_parameters(in_param1, + &def_tx_Octects, sizeof(int)); + __bt_service_get_parameters(in_param2, + &def_tx_Time, sizeof(int)); + + result = _bt_le_write_host_suggested_default_data_length( + def_tx_Octects, def_tx_Time); + break; + } + case BT_LE_READ_HOST_SUGGESTED_DATA_LENGTH: { + bluetooth_le_read_host_suggested_data_length_t def_data_length = {0}; + + result = _bt_le_read_host_suggested_default_data_length(&def_data_length); + + g_array_append_vals(*out_param1, &def_data_length, + sizeof(bluetooth_le_read_host_suggested_data_length_t)); + + break; + } + case BT_LE_SET_DATA_LENGTH: { + int max_tx_Octets = 0; + int max_tx_Time = 0; + bluetooth_device_address_t address = { {0} }; + + __bt_service_get_parameters(in_param1, &address, + sizeof(bluetooth_device_address_t)); + __bt_service_get_parameters(in_param2, + &max_tx_Octets, sizeof(int)); + __bt_service_get_parameters(in_param3, + &max_tx_Time, sizeof(int)); + + result = _bt_le_set_data_length(&address, max_tx_Octets, max_tx_Time); + break; + } + case BT_DPM_SET_ALLOW_BT_MODE: { + dpm_bt_allow_t value = DPM_BT_ERROR; + + __bt_service_get_parameters(in_param1, &value, + sizeof(int)); + + result = _bt_dpm_set_allow_bluetooth_mode(value); + break; + } + case BT_DPM_GET_ALLOW_BT_MODE: { + dpm_bt_allow_t value = DPM_BT_ERROR; + + value = _bt_dpm_get_allow_bluetooth_mode(); + result = DPM_RESULT_SUCCESS; + g_array_append_vals(*out_param1, &value, sizeof(int)); + + break; + } + case BT_DPM_SET_DEVICE_RESTRITION: { + dpm_status_t value = DPM_BT_ERROR; + + __bt_service_get_parameters(in_param1, &value, + sizeof(int)); + + result = _bt_dpm_activate_bluetooth_device_restriction(value); + break; + } + case BT_DPM_GET_DEVICE_RESTRITION: { + dpm_status_t value = DPM_BT_ERROR; + + value = _bt_dpm_is_bluetooth_device_restriction_active(); + result = DPM_RESULT_SUCCESS; + g_array_append_vals(*out_param1, &value, sizeof(int)); + + break; + } + case BT_DPM_SET_UUID_RESTRITION: { + dpm_status_t value = DPM_BT_ERROR; + + __bt_service_get_parameters(in_param1, &value, + sizeof(int)); + + result = _bt_dpm_activate_bluetoooth_uuid_restriction(value); + break; + } + case BT_DPM_GET_UUID_RESTRITION: { + dpm_status_t value = DPM_BT_ERROR; + + value = _bt_dpm_is_bluetooth_uuid_restriction_active(); + result = DPM_RESULT_SUCCESS; + g_array_append_vals(*out_param1, &value, sizeof(int)); + + break; + } + case BT_DPM_ADD_DEVICES_BLACKLIST: { + bluetooth_device_address_t address = { {0} }; + + __bt_service_get_parameters(in_param1, &address, + sizeof(bluetooth_device_address_t)); + + result = _bt_dpm_add_bluetooth_devices_to_blacklist(&address); + break; + } + case BT_DPM_ADD_DEVICES_WHITELIST: { + bluetooth_device_address_t address = { {0} }; + + __bt_service_get_parameters(in_param1, &address, + sizeof(bluetooth_device_address_t)); + + result = _bt_dpm_add_bluetooth_devices_to_whitelist(&address); + break; + } + case BT_DPM_ADD_UUIDS_BLACKLIST: { + const char *uuid = NULL; + + uuid = g_variant_get_data(in_param1); + + result = _bt_dpm_add_bluetooth_uuids_to_blacklist(uuid); + break; + } + case BT_DPM_ADD_UUIDS_WHITELIST: { + const char *uuid = NULL; + + uuid = g_variant_get_data(in_param1); + + result = _bt_dpm_add_bluetooth_uuids_to_whitelist(uuid); + break; + } + case BT_DPM_CLEAR_DEVICES_BLACKLIST: { + result = _bt_dpm_clear_bluetooth_devices_from_blacklist(); + break; + } + case BT_DPM_CLEAR_DEVICES_WHITELIST: { + result = _bt_dpm_clear_bluetooth_devices_from_whitelist(); + break; + } + case BT_DPM_CLEAR_UUIDS_BLACKLIST: { + result = _bt_dpm_clear_bluetooth_uuids_from_blacklist(); + break; + } + case BT_DPM_CLEAR_UUIDS_WHITELIST: { + result = _bt_dpm_clear_bluetooth_uuids_from_whitelist(); + break; + } + case BT_DPM_REMOVE_DEVICE_BLACKLIST: { + bluetooth_device_address_t address = { {0} }; + + __bt_service_get_parameters(in_param1, &address, + sizeof(bluetooth_device_address_t)); + + result = _bt_dpm_remove_bluetooth_devices_from_blacklist(&address); + break; + } + case BT_DPM_REMOVE_DEVICE_WHITELIST: { + bluetooth_device_address_t address = { {0} }; + + __bt_service_get_parameters(in_param1, &address, + sizeof(bluetooth_device_address_t)); + + result = _bt_dpm_remove_bluetooth_devices_from_whitelist(&address); + break; + } + case BT_DPM_REMOVE_UUID_BLACKLIST: { + const char *uuid = NULL; + + uuid = g_variant_get_data(in_param1); + + result = _bt_dpm_remove_bluetooth_uuids_from_blacklist(uuid); + break; + } + case BT_DPM_REMOVE_UUID_WHITELIST: { + const char *uuid = NULL; + + uuid = g_variant_get_data(in_param1); + + result = _bt_dpm_remove_bluetooth_uuids_from_whitelist(uuid); + + break; + } + case BT_DPM_GET_DEVICES_BLACKLIST: { + result = _bt_dpm_get_bluetooth_devices_from_blacklist(out_param1); + break; + } + case BT_DPM_GET_DEVICES_WHITELIST: { + result = _bt_dpm_get_bluetooth_devices_from_whitelist(out_param1); + break; + } + case BT_DPM_GET_UUIDS_BLACKLIST: { + result = _bt_dpm_get_bluetooth_uuids_from_blacklist(out_param1); + break; + } + case BT_DPM_GET_UUIDS_WHITELIST: { + result = _bt_dpm_get_bluetooth_uuids_from_whitelist(out_param1); + break; + } + case BT_DPM_SET_ALLOW_OUTGOING_CALL: { + dpm_status_t value = DPM_BT_ERROR; + + __bt_service_get_parameters(in_param1, &value, + sizeof(int)); + + result = _bt_dpm_set_allow_bluetooth_outgoing_call(value); + + break; + } + case BT_DPM_GET_ALLOW_OUTGOING_CALL: { + dpm_status_t value = DPM_BT_ERROR; + + value = _bt_dpm_get_allow_bluetooth_outgoing_call(); + result = DPM_RESULT_SUCCESS; + g_array_append_vals(*out_param1, &value, sizeof(int)); + + break; + } + case BT_DPM_SET_PAIRING_STATE: { + dpm_status_t value = DPM_BT_ERROR; + + __bt_service_get_parameters(in_param1, &value, + sizeof(int)); + + result = _bt_dpm_set_bluetooth_pairing_state(value); + + break; + } + case BT_DPM_GET_PAIRING_STATE: { + dpm_status_t value = DPM_BT_ERROR; + + value = _bt_dpm_get_bluetooth_pairing_state(); + result = DPM_RESULT_SUCCESS; + g_array_append_vals(*out_param1, &value, sizeof(int)); + + break; + } + case BT_DPM_SET_PROFILE_STATE: { + dpm_status_t value = DPM_BT_ERROR; + dpm_profile_t profile = DPM_PROFILE_NONE; + + __bt_service_get_parameters(in_param1, &profile, + sizeof(int)); + __bt_service_get_parameters(in_param2, &value, + sizeof(int)); + + result = _bt_dpm_set_bluetooth_profile_state(profile, value); + + break; + } + case BT_DPM_GET_PROFILE_STATE: { + dpm_status_t value = DPM_BT_ERROR; + dpm_profile_t profile = DPM_PROFILE_NONE; + + __bt_service_get_parameters(in_param2, &profile, + sizeof(int)); + + value = _bt_dpm_get_bluetooth_profile_state(profile); + result = DPM_RESULT_SUCCESS; + g_array_append_vals(*out_param1, &value, sizeof(int)); + + break; + } + case BT_DPM_SET_DESKROP_CONNECTIVITY_STATE: { + dpm_status_t value = DPM_BT_ERROR; + + __bt_service_get_parameters(in_param1, &value, + sizeof(int)); + + result = _bt_dpm_set_bluetooth_desktop_connectivity_state(value); + + break; + } + case BT_DPM_GET_DESKROP_CONNECTIVITY_STATE: { + dpm_status_t value = DPM_BT_ERROR; + + value = _bt_dpm_get_bluetooth_desktop_connectivity_state(); + result = DPM_RESULT_SUCCESS; + g_array_append_vals(*out_param1, &value, sizeof(int)); + + break; + } + case BT_DPM_SET_DISCOVERABLE_STATE: { + dpm_status_t value = DPM_BT_ERROR; + + __bt_service_get_parameters(in_param1, &value, + sizeof(int)); + + result = _bt_dpm_set_bluetooth_discoverable_state(value); + + break; + } + case BT_DPM_GET_DISCOVERABLE_STATE: { + dpm_status_t value = DPM_BT_ERROR; + + value = _bt_dpm_get_bluetooth_discoverable_state(); + result = DPM_RESULT_SUCCESS; + g_array_append_vals(*out_param1, &value, sizeof(int)); + + break; + } + case BT_DPM_SET_LIMITED_DISCOVERABLE_STATE: { + dpm_status_t value = DPM_BT_ERROR; + + __bt_service_get_parameters(in_param1, &value, + sizeof(int)); + + result = _bt_dpm_set_bluetooth_limited_discoverable_state(value); + + break; + } + case BT_DPM_GET_LIMITED_DISCOVERABLE_STATE: { + dpm_status_t value = DPM_BT_ERROR; + + value = _bt_dpm_get_bluetooth_limited_discoverable_state(); + result = DPM_RESULT_SUCCESS; + g_array_append_vals(*out_param1, &value, sizeof(int)); + + break; + } + case BT_DPM_SET_DATA_TRANSFER_STATE: { + dpm_status_t value = DPM_BT_ERROR; + + __bt_service_get_parameters(in_param1, &value, + sizeof(int)); + + result = _bt_dpm_set_bluetooth_data_transfer_state(value); + + break; + } + case BT_DPM_GET_DATA_TRANSFER_STATE: { + dpm_status_t value = DPM_BT_ERROR; + + value = _bt_dpm_get_allow_bluetooth_data_transfer_state(); + result = DPM_RESULT_SUCCESS; + g_array_append_vals(*out_param1, &value, sizeof(int)); + + break; + } + default: + result = BLUETOOTH_ERROR_INTERNAL; + break; + } + + return result; +} + +int __bt_obexd_request(int function_name, + int request_type, + int request_id, + GDBusMethodInvocation *context, + GVariant *in_param1, + GVariant *in_param2, + GVariant *in_param3, + GVariant *in_param4, + GVariant *in_param5, + GArray **out_param1) +{ + BT_DBG("+"); + + int result; + + BT_DBG("function_name : %x", function_name); + + switch (function_name) { + case BT_OPP_PUSH_FILES: { + BT_DBG("BT_OPP_PUSH_FILES"); + int i; + bluetooth_device_address_t address = { {0} }; + bt_file_path_t path; + char **file_path; + int file_count; + GDBusProxy *process_proxy; + guint owner_pid = 0; + int opp_server_pid = 0; + const gchar *owner_sender_name = NULL; + GDBusConnection *owner_connection = NULL; + GVariant *val_get = NULL; + GError *error_connection = NULL; + GError *errro_proxy = NULL; + GArray *param2; + + __bt_service_get_parameters(in_param1, &address, + sizeof(bluetooth_device_address_t)); + __bt_service_get_parameters(in_param3, &file_count, + sizeof(int)); + + file_path = g_new0(char *, file_count + 1); + + param2 = g_array_new(TRUE, TRUE, sizeof(gchar)); + __bt_fill_garray_from_variant(in_param2, param2); + + for (i = 0; i < file_count; i++) { + path = g_array_index(param2, bt_file_path_t, i); + file_path[i] = g_strdup(path.path); + } + + owner_connection = g_dbus_method_invocation_get_connection(context); + owner_sender_name = g_dbus_method_invocation_get_sender(context); + + BT_DBG("sender = %s", owner_sender_name); + + process_proxy = g_dbus_proxy_new_sync(owner_connection, + G_DBUS_PROXY_FLAGS_NONE, + NULL, + "org.freedesktop.DBus", + "/org/freedesktop/DBus", + "org.freedesktop.DBus", + NULL, &error_connection); + + if (process_proxy == NULL) + BT_DBG("Fail to get process_proxy"); + + if (error_connection) { + BT_DBG("Fail to get proxy : %s", error_connection->message); + g_error_free(error_connection); + error_connection = NULL; + } + + if (process_proxy) { + val_get = g_dbus_proxy_call_sync(process_proxy, + "GetConnectionUnixProcessID", + g_variant_new("(s)", owner_sender_name), + G_DBUS_CALL_FLAGS_NONE, + -1, NULL, + &errro_proxy); + + if (val_get == NULL) { + BT_DBG("Fail to get pid"); + } else { + g_variant_get(val_get, "(u)", &owner_pid); + BT_DBG("request is from pid %d\n", owner_pid); + } + + if (errro_proxy) { + g_error("Unable to get PID for %s: %s", + owner_sender_name, errro_proxy->message); + g_error_free(errro_proxy); + errro_proxy = NULL; + } + } else { + BT_DBG("fail to get proxy"); + } + + opp_server_pid = _bt_obex_get_native_pid(); + + BT_DBG("owner_pid, agent_info.native_server->app_pid = %d, %d", + owner_pid, opp_server_pid); + if (opp_server_pid == owner_pid) { + BT_DBG("The exception case : _bt_opp_client_push_files"); + result = _bt_opp_client_push_files(request_id, context, + &address, file_path, + file_count); + } else { + BT_DBG("normal case"); + result = _bt_opp_client_push_files(request_id, context, + &address, file_path, + file_count); + } + + for (i = 0; i < file_count; i++) { + g_free(file_path[i]); + } + g_free(file_path); + g_array_free(param2, TRUE); + if (process_proxy) + g_object_unref(process_proxy); + break; + } + case BT_OPP_CANCEL_PUSH: { + result = _bt_opp_client_cancel_push(); + + break; + } + case BT_OPP_IS_PUSHING_FILES: { + gboolean is_sending = FALSE; + + result = _bt_opp_client_is_sending(&is_sending); + + g_array_append_vals(*out_param1, &is_sending, + sizeof(gboolean)); + break; + } + case BT_OBEX_SERVER_ALLOCATE: { + int app_pid; + gboolean is_native; + char *path; + char *sender; + + sender = (char *)g_dbus_method_invocation_get_sender(context); + + path = (char *)g_variant_get_data(in_param1); + __bt_service_get_parameters(in_param2, &is_native, + sizeof(gboolean)); + __bt_service_get_parameters(in_param3, &app_pid, + sizeof(int)); + result = _bt_obex_server_allocate(sender, + path, app_pid, is_native); + + break; + } + case BT_OBEX_SERVER_DEALLOCATE: { + int app_pid; + gboolean is_native; + + __bt_service_get_parameters(in_param1, &is_native, + sizeof(gboolean)); + __bt_service_get_parameters(in_param2, &app_pid, + sizeof(int)); + + result = _bt_obex_server_deallocate(app_pid, is_native); + break; + } + case BT_OBEX_SERVER_IS_ACTIVATED: { + gboolean is_activated = FALSE; + + result = _bt_obex_server_is_activated(&is_activated); + + g_array_append_vals(*out_param1, &is_activated, + sizeof(gboolean)); + + break; + } + case BT_OBEX_SERVER_ACCEPT_CONNECTION: { + result = _bt_obex_server_accept_connection(request_id); + + break; + } + case BT_OBEX_SERVER_REJECT_CONNECTION: { + result = _bt_obex_server_reject_connection(); + + break; + } + case BT_OBEX_SERVER_ACCEPT_FILE: { + char *file_name; + + file_name = (char *)g_variant_get_data(in_param1); + result = _bt_obex_server_accept_authorize(file_name, TRUE); + + break; + } + case BT_OBEX_SERVER_REJECT_FILE: { + result = _bt_obex_server_reject_authorize(); + + break; + } + case BT_OBEX_SERVER_SET_PATH: { + gboolean is_native; + char *destination_path; + + destination_path = (char *)g_variant_get_data(in_param1); + __bt_service_get_parameters(in_param2, &is_native, + sizeof(gboolean)); + + result = _bt_obex_server_set_destination_path( + destination_path, is_native); + + break; + } + case BT_OBEX_SERVER_SET_ROOT: { + char *root; + + root = (char *)g_variant_get_data(in_param1); + + result = _bt_obex_server_set_root(root); + + break; + } + case BT_OBEX_SERVER_CANCEL_TRANSFER: { + int transfer_id; + + __bt_service_get_parameters(in_param1, &transfer_id, + sizeof(int)); + + result = _bt_obex_server_cancel_transfer(transfer_id); + + break; + } + case BT_OBEX_SERVER_CANCEL_ALL_TRANSFERS: { + result = _bt_obex_server_cancel_all_transfers(); + + break; + } + case BT_OBEX_SERVER_IS_RECEIVING: { + gboolean is_receiving = FALSE; + + result = _bt_obex_server_is_receiving(&is_receiving); + + g_array_append_vals(*out_param1, &is_receiving, + sizeof(gboolean)); + break; + } + case BT_PBAP_CONNECT: { + bluetooth_device_address_t address = { {0} }; + + __bt_service_get_parameters(in_param1, &address, + sizeof(bluetooth_device_address_t)); + + result = _bt_pbap_connect(&address); + break; + } + case BT_PBAP_DISCONNECT: { + bluetooth_device_address_t address = { {0} }; + + __bt_service_get_parameters(in_param1, &address, + sizeof(bluetooth_device_address_t)); + + result = _bt_pbap_disconnect(&address); + break; + } + case BT_PBAP_GET_PHONEBOOK_SIZE: { + bluetooth_device_address_t address = { {0} }; + bt_pbap_folder_t folder = { 0, }; + + __bt_service_get_parameters(in_param1, &address, + sizeof(bluetooth_device_address_t)); + __bt_service_get_parameters(in_param2, &folder, + sizeof(bt_pbap_folder_t)); + + result = _bt_pbap_get_phonebook_size(&address, + folder.addressbook, folder.folder_type); + break; + } + case BT_PBAP_GET_PHONEBOOK: { + bluetooth_device_address_t address = { {0} }; + bt_pbap_folder_t folder = { 0, }; + bt_pbap_pull_parameters_t app_param = { 0, }; + + __bt_service_get_parameters(in_param1, &address, + sizeof(bluetooth_device_address_t)); + __bt_service_get_parameters(in_param2, &folder, + sizeof(bt_pbap_folder_t)); + __bt_service_get_parameters(in_param3, &app_param, + sizeof(bt_pbap_pull_parameters_t)); + + result = _bt_pbap_get_phonebook(&address, folder.addressbook, + folder.folder_type, &app_param); + break; + } + case BT_PBAP_GET_LIST: { + bluetooth_device_address_t address = { {0} }; + bt_pbap_folder_t folder = { 0, }; + bt_pbap_list_parameters_t app_param = { 0, }; + + __bt_service_get_parameters(in_param1, &address, + sizeof(bluetooth_device_address_t)); + __bt_service_get_parameters(in_param2, &folder, + sizeof(bt_pbap_folder_t)); + __bt_service_get_parameters(in_param3, &app_param, + sizeof(bt_pbap_list_parameters_t)); + + result = _bt_pbap_get_list(&address, folder.addressbook, + folder.folder_type, &app_param); + break; + } + case BT_PBAP_PULL_VCARD: { + bluetooth_device_address_t address = { {0} }; + bt_pbap_folder_t folder = { 0, }; + bt_pbap_pull_vcard_parameters_t app_param = { 0, }; + + __bt_service_get_parameters(in_param1, &address, + sizeof(bluetooth_device_address_t)); + __bt_service_get_parameters(in_param2, &folder, + sizeof(bt_pbap_folder_t)); + __bt_service_get_parameters(in_param3, &app_param, + sizeof(bt_pbap_pull_vcard_parameters_t)); + + result = _bt_pbap_pull_vcard(&address, folder.addressbook, + folder.folder_type, &app_param); + break; + } + case BT_PBAP_PHONEBOOK_SEARCH: { + bluetooth_device_address_t address = { {0} }; + bt_pbap_folder_t folder = { 0, }; + bt_pbap_search_parameters_t app_param = { 0, }; + + __bt_service_get_parameters(in_param1, &address, + sizeof(bluetooth_device_address_t)); + __bt_service_get_parameters(in_param2, &folder, + sizeof(bt_pbap_folder_t)); + __bt_service_get_parameters(in_param3, &app_param, + sizeof(bt_pbap_search_parameters_t)); + + result = _bt_pbap_phonebook_search(&address, folder.addressbook, + folder.folder_type, &app_param); + break; + } + + default: + BT_ERR("Unknown function!"); + result = BLUETOOTH_ERROR_INTERNAL; + break; + } + + FN_END; + + return result; +} + +int __bt_agent_request(int function_name, + int request_type, + int request_id, + GDBusMethodInvocation *context, + GVariant *in_param1, + GVariant *in_param2, + GVariant *in_param3, + GVariant *in_param4, + GArray **out_param1) +{ + int result; + switch (function_name) { + case BT_SET_AUTHORIZATION: { + int type; + char *uuid; + char *path; + int fd; + + __bt_service_get_parameters(in_param1, &type, sizeof(int)); + uuid = (char *)g_variant_get_data(in_param2); + path = (char *)g_variant_get_data(in_param3); + __bt_service_get_parameters(in_param4, &fd, sizeof(int)); + + result = _bt_register_osp_server_in_agent(type, uuid, path, fd); + break; + } + case BT_UNSET_AUTHORIZATION: { + int type; + char *uuid; + + __bt_service_get_parameters(in_param1, &type, sizeof(int)); + uuid = (char *)g_variant_get_data(in_param2); + + result = _bt_unregister_osp_server_in_agent(type, uuid); + break; + } + default: + BT_ERR("Unknown function!"); + result = BLUETOOTH_ERROR_INTERNAL; + break; + } + + return result; +} + +int __bt_core_request(int function_name, + int request_type, + int request_id, + GDBusMethodInvocation *context, + GVariant *in_param1) +{ + int result; + + switch (function_name) { + case BT_ENABLE_ADAPTER: + { + bt_status_t status; + + status = _bt_adapter_get_status(); + + if (status == BT_ACTIVATING) { + BT_DBG("Enabling in progress"); + result = BLUETOOTH_ERROR_IN_PROGRESS; + } else if (status == BT_ACTIVATED) { + BT_DBG("Already enabled"); + result = BLUETOOTH_ERROR_DEVICE_ALREADY_ENABLED; + } else { + _bt_adapter_set_status(BT_ACTIVATING); + _bt_adapter_start_enable_timer(); + result = BLUETOOTH_ERROR_NONE; + } + + break; + } + case BT_DISABLE_ADAPTER: + { + bt_status_t status; + + status = _bt_adapter_get_status(); + if (status == BT_DEACTIVATING) { + BT_DBG("Disabling in progress"); + result = BLUETOOTH_ERROR_IN_PROGRESS; + } else if (status == BT_DEACTIVATED) { + BT_DBG("Already disabled"); + result = BLUETOOTH_ERROR_DEVICE_NOT_ENABLED; + } else { + _bt_adapter_set_status(BT_DEACTIVATING); + result = BLUETOOTH_ERROR_NONE; + } + + break; + } + case BT_ENABLE_ADAPTER_LE: + { + bt_le_status_t le_status; + + le_status = _bt_adapter_get_le_status(); + if (le_status == BT_LE_ACTIVATING) { + BT_DBG("Enabling in progress"); + result = BLUETOOTH_ERROR_IN_PROGRESS; + } else if (le_status == BT_LE_ACTIVATED) { + BT_DBG("Already enabled"); + result = BLUETOOTH_ERROR_DEVICE_ALREADY_ENABLED; + } else { + _bt_adapter_set_le_status(BT_LE_ACTIVATING); + _bt_adapter_start_le_enable_timer(); + result = BLUETOOTH_ERROR_NONE; + } + + break; + } + case BT_DISABLE_ADAPTER_LE: + { + bt_le_status_t le_status; + + le_status = _bt_adapter_get_le_status(); + if (le_status == BT_LE_DEACTIVATING) { + BT_DBG("Disabling in progress"); + result = BLUETOOTH_ERROR_IN_PROGRESS; + } else if (le_status == BT_LE_DEACTIVATED) { + BT_DBG("Already disabled"); + result = BLUETOOTH_ERROR_DEVICE_NOT_ENABLED; + } else { + _bt_adapter_set_le_status(BT_LE_DEACTIVATING); + result = BLUETOOTH_ERROR_NONE; + } + + break; + } + default: + BT_ERR("Unknown function!"); + result = BLUETOOTH_ERROR_INTERNAL; + break; + } + + return result; +} + +gboolean __bt_service_check_privilege(int function_name, + int service_type, + const char *unique_name) +{ + int ret_val; + gboolean result = TRUE; + char *client_creds = NULL; + char *user_creds = NULL; + char *client_session = ""; + enum cynara_client_creds client_creds_method = CLIENT_METHOD_SMACK; + enum cynara_user_creds user_creds_method = USER_METHOD_UID; + char err_msg[256] = {0, }; + + retv_if(unique_name == NULL, FALSE); + + BT_DBG("unique_name: %s", unique_name); + + retv_if(bt_service_conn == NULL, FALSE); + + ret_val = cynara_creds_get_default_client_method(&client_creds_method); + if (ret_val != CYNARA_API_SUCCESS) { + cynara_strerror(ret_val, err_msg, sizeof(err_msg)); + BT_ERR("Fail to get default client method: %s", err_msg); + return FALSE; + } + + ret_val = cynara_creds_get_default_user_method(&user_creds_method); + if (ret_val != CYNARA_API_SUCCESS) { + cynara_strerror(ret_val, err_msg, sizeof(err_msg)); + BT_ERR("Fail to get default user method: %s", err_msg); + return FALSE; + } + + ret_val = cynara_creds_gdbus_get_client(bt_service_conn, unique_name, client_creds_method, &client_creds); + if (ret_val != CYNARA_API_SUCCESS) { + cynara_strerror(ret_val, err_msg, sizeof(err_msg)); + BT_ERR("Fail to get client credential: %s", err_msg); + return FALSE; + } + + BT_DBG("client_creds: %s", client_creds); + + ret_val = cynara_creds_gdbus_get_user(bt_service_conn, unique_name, user_creds_method, &user_creds); + if (ret_val != CYNARA_API_SUCCESS) { + cynara_strerror(ret_val, err_msg, sizeof(err_msg)); + BT_ERR("Fail to get user credential: %s", err_msg); + if (client_creds) + free(client_creds); + return FALSE; + } + + BT_DBG("user_creds: %s", user_creds); + + switch (function_name) { + case BT_SET_LOCAL_NAME: + case BT_START_DISCOVERY: + case BT_START_CUSTOM_DISCOVERY: + case BT_CANCEL_DISCOVERY: + case BT_OOB_ADD_REMOTE_DATA: + case BT_OOB_REMOVE_REMOTE_DATA: + case BT_SET_ADVERTISING: + case BT_SET_CUSTOM_ADVERTISING: + case BT_SET_ADVERTISING_PARAMETERS: + case BT_START_LE_DISCOVERY: + case BT_STOP_LE_DISCOVERY: + + case BT_BOND_DEVICE: + case BT_CANCEL_BONDING: + case BT_UNBOND_DEVICE: + case BT_SET_ALIAS: + case BT_SET_AUTHORIZATION: + case BT_UNSET_AUTHORIZATION: + case BT_SEARCH_SERVICE: + + case BT_RFCOMM_CLIENT_CONNECT: + case BT_RFCOMM_CLIENT_CANCEL_CONNECT: + case BT_RFCOMM_SOCKET_DISCONNECT: + case BT_RFCOMM_SOCKET_WRITE: + case BT_RFCOMM_CREATE_SOCKET: + case BT_RFCOMM_REMOVE_SOCKET: + + case BT_OPP_PUSH_FILES: + case BT_OPP_CANCEL_PUSH: + + case BT_OBEX_SERVER_ACCEPT_CONNECTION: + case BT_OBEX_SERVER_REJECT_CONNECTION: + case BT_OBEX_SERVER_ACCEPT_FILE: + case BT_OBEX_SERVER_REJECT_FILE: + case BT_OBEX_SERVER_SET_PATH: + case BT_OBEX_SERVER_SET_ROOT: + case BT_OBEX_SERVER_CANCEL_TRANSFER: + case BT_OBEX_SERVER_CANCEL_ALL_TRANSFERS: + + case BT_AUDIO_CONNECT: + case BT_AUDIO_DISCONNECT: + case BT_AG_CONNECT: + case BT_AG_DISCONNECT: + case BT_AV_CONNECT: + case BT_AV_DISCONNECT: + case BT_AV_SOURCE_CONNECT: + case BT_AV_SOURCE_DISCONNECT: + case BT_AVRCP_CONTROL_CONNECT: + case BT_AVRCP_CONTROL_DISCONNECT: + case BT_AVRCP_HANDLE_CONTROL: + case BT_AVRCP_SET_TRACK_INFO: + case BT_AVRCP_SET_PROPERTY: + case BT_AVRCP_SET_PROPERTIES: + case BT_AVRCP_CONTROL_SET_PROPERTY: + + case BT_HF_CONNECT: + case BT_HF_DISCONNECT: + + case BT_HID_CONNECT: + case BT_HID_DISCONNECT: + + case BT_HID_DEVICE_ACTIVATE: + case BT_HID_DEVICE_DEACTIVATE: + case BT_HID_DEVICE_CONNECT: + case BT_HID_DEVICE_DISCONNECT: + case BT_HID_DEVICE_SEND_MOUSE_EVENT: + case BT_HID_DEVICE_SEND_KEY_EVENT: + case BT_HID_DEVICE_SEND_REPLY_TO_REPORT: + + case BT_CONNECT_LE: + case BT_DISCONNECT_LE: + + case BT_SET_ADVERTISING_DATA: + case BT_SET_SCAN_RESPONSE_DATA: + + case BT_HDP_CONNECT: + case BT_HDP_DISCONNECT: + case BT_HDP_SEND_DATA: + + case BT_DPM_SET_ALLOW_BT_MODE: + case BT_DPM_GET_ALLOW_BT_MODE: + case BT_DPM_SET_DEVICE_RESTRITION: + case BT_DPM_GET_DEVICE_RESTRITION: + case BT_DPM_SET_UUID_RESTRITION: + case BT_DPM_GET_UUID_RESTRITION: + case BT_DPM_ADD_DEVICES_BLACKLIST: + case BT_DPM_ADD_DEVICES_WHITELIST: + case BT_DPM_ADD_UUIDS_BLACKLIST: + case BT_DPM_ADD_UUIDS_WHITELIST: + case BT_DPM_CLEAR_DEVICES_BLACKLIST: + case BT_DPM_CLEAR_DEVICES_WHITELIST: + case BT_DPM_CLEAR_UUIDS_BLACKLIST: + case BT_DPM_CLEAR_UUIDS_WHITELIST: + case BT_DPM_REMOVE_DEVICE_BLACKLIST: + case BT_DPM_REMOVE_DEVICE_WHITELIST: + case BT_DPM_REMOVE_UUID_BLACKLIST: + case BT_DPM_REMOVE_UUID_WHITELIST: + case BT_DPM_GET_DEVICES_BLACKLIST: + case BT_DPM_GET_DEVICES_WHITELIST: + case BT_DPM_GET_UUIDS_BLACKLIST: + case BT_DPM_GET_UUIDS_WHITELIST: + case BT_DPM_SET_ALLOW_OUTGOING_CALL: + case BT_DPM_GET_ALLOW_OUTGOING_CALL: + case BT_DPM_SET_PAIRING_STATE: + case BT_DPM_GET_PAIRING_STATE: + case BT_DPM_SET_PROFILE_STATE: + case BT_DPM_GET_PROFILE_STATE: + case BT_DPM_SET_DESKROP_CONNECTIVITY_STATE: + case BT_DPM_GET_DESKROP_CONNECTIVITY_STATE: + case BT_DPM_SET_DISCOVERABLE_STATE: + case BT_DPM_GET_DISCOVERABLE_STATE: + case BT_DPM_SET_LIMITED_DISCOVERABLE_STATE: + case BT_DPM_GET_LIMITED_DISCOVERABLE_STATE: + case BT_DPM_SET_DATA_TRANSFER_STATE: + case BT_DPM_GET_DATA_TRANSFER_STATE: + + case BT_NETWORK_ACTIVATE: + case BT_NETWORK_DEACTIVATE: + case BT_NETWORK_CONNECT: + case BT_NETWORK_DISCONNECT: + case BT_NETWORK_SERVER_DISCONNECT: + + case BT_GATT_GET_PRIMARY_SERVICES: + case BT_GATT_DISCOVER_CHARACTERISTICS: + case BT_GATT_SET_PROPERTY_REQUEST: + case BT_GATT_READ_CHARACTERISTIC: + case BT_GATT_DISCOVER_CHARACTERISTICS_DESCRIPTOR: + case BT_GATT_REGISTER_APPLICATION: + case BT_GATT_REGISTER_SERVICE: + case BT_GATT_SEND_RESPONSE: + case BT_PBAP_CONNECT: + case BT_PBAP_DISCONNECT: + case BT_PBAP_GET_PHONEBOOK_SIZE: + case BT_PBAP_GET_PHONEBOOK: + case BT_PBAP_GET_LIST: + case BT_PBAP_PULL_VCARD: + case BT_PBAP_PHONEBOOK_SEARCH: + + ret_val = cynara_check(p_cynara, client_creds, client_session, user_creds, + BT_PRIVILEGE_PUBLIC); + + if (ret_val != CYNARA_API_ACCESS_ALLOWED) { + BT_ERR("Fail to access: %s", BT_PRIVILEGE_PUBLIC); + result = FALSE; + } + + /* Need to check mediastorage privilege */ + if (function_name == BT_PBAP_GET_PHONEBOOK || + function_name == BT_PBAP_PULL_VCARD) { + ret_val = cynara_check(p_cynara, client_creds, client_session, user_creds, + MEDIASTORAGE_PRIVILEGE); + + if (ret_val != CYNARA_API_ACCESS_ALLOWED) { + BT_ERR("Fail to access: %s", MEDIASTORAGE_PRIVILEGE); + result = FALSE; + } + } + break; + + case BT_ENABLE_ADAPTER: + case BT_DISABLE_ADAPTER: + case BT_RESET_ADAPTER: + case BT_RECOVER_ADAPTER: + case BT_ENABLE_ADAPTER_LE: + case BT_DISABLE_ADAPTER_LE: + case BT_SET_CONNECTABLE: + case BT_SET_DISCOVERABLE_MODE: + case BT_ADD_WHITE_LIST: + case BT_REMOVE_WHITE_LIST: + case BT_CLEAR_WHITE_LIST: + case BT_SET_MANUFACTURER_DATA: + case BT_SET_SCAN_PARAMETERS: + + case BT_CANCEL_SEARCH_SERVICE: + case BT_ENABLE_RSSI: + + case BT_RFCOMM_ACCEPT_CONNECTION: + case BT_RFCOMM_REJECT_CONNECTION: + case BT_RFCOMM_LISTEN: + + case BT_AVRCP_CONTROL_GET_PROPERTY: + case BT_AVRCP_GET_TRACK_INFO: + + case BT_SET_CONTENT_PROTECT: + case BT_BOND_DEVICE_BY_TYPE: + case BT_SET_LE_PRIVACY: + case BT_LE_CONN_UPDATE: + case BT_LE_READ_MAXIMUM_DATA_LENGTH: + case BT_LE_WRITE_HOST_SUGGESTED_DATA_LENGTH: + case BT_LE_READ_HOST_SUGGESTED_DATA_LENGTH: + case BT_LE_SET_DATA_LENGTH: + + case BT_LE_IPSP_INIT: + case BT_LE_IPSP_DEINIT: + case BT_LE_IPSP_CONNECT: + case BT_LE_IPSP_DISCONNECT: + ret_val = cynara_check(p_cynara, client_creds, client_session, user_creds, + BT_PRIVILEGE_PLATFORM); + + if (ret_val != CYNARA_API_ACCESS_ALLOWED) { + BT_ERR("Fail to access: %s", BT_PRIVILEGE_PLATFORM); + result = FALSE; + } + break; + + case BT_CHECK_ADAPTER: + case BT_GET_RSSI: + + case BT_GET_LOCAL_NAME: + case BT_GET_LOCAL_ADDRESS: + case BT_GET_LOCAL_VERSION: + case BT_IS_SERVICE_USED: + case BT_GET_DISCOVERABLE_MODE: + case BT_GET_DISCOVERABLE_TIME: + case BT_IS_DISCOVERYING: + case BT_IS_LE_DISCOVERYING: + case BT_IS_CONNECTABLE: + case BT_GET_BONDED_DEVICES: + case BT_GET_BONDED_DEVICE: + case BT_IS_DEVICE_CONNECTED: + case BT_GET_SPEAKER_GAIN: + case BT_SET_SPEAKER_GAIN: + case BT_OOB_READ_LOCAL_DATA: + case BT_RFCOMM_CLIENT_IS_CONNECTED: + case BT_RFCOMM_IS_UUID_AVAILABLE: + case BT_GET_ADVERTISING_DATA: + case BT_GET_SCAN_RESPONSE_DATA: + case BT_IS_ADVERTISING: + + case BT_OBEX_SERVER_ALLOCATE: + case BT_OBEX_SERVER_DEALLOCATE: + /* Non-privilege control */ + break; + default: + BT_ERR("Unknown function!"); + result = FALSE; + break; + } + + if (client_creds) + free(client_creds); + + if (user_creds) + free(user_creds); + + return result; +} + +GDBusNodeInfo *__bt_service_create_method_node_info + (const gchar *introspection_data) +{ + GError *err = NULL; + GDBusNodeInfo *node_info = NULL; + + if (introspection_data == NULL) { + ERR("Introspection XML not present"); + return NULL; + } + + node_info = g_dbus_node_info_new_for_xml(introspection_data, &err); + + if (err) { + ERR("Unable to create node: %s", err->message); + g_clear_error(&err); + } + return node_info; +} + +int __bt_service_register_object(GDBusConnection *conn, + GDBusNodeInfo *node_info, gboolean reg) +{ + static guint service_id = 0; + GError *error = NULL; + + if (reg) { + if (node_info == NULL) + return -1; + + service_id = g_dbus_connection_register_object(conn, + BT_SERVICE_PATH, + node_info->interfaces[0], + &method_table, + NULL, NULL, &error); + if (service_id == 0) + return -1; + } else { + if (service_id > 0) { + g_dbus_connection_unregister_object(conn, + service_id); + service_id = 0; + } + } + + return 0; +} + +int _bt_service_register(void) +{ + GDBusConnection *conn; + GError *err = NULL; + int result; + + conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &err); + retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL); + + owner_id = g_bus_own_name(G_BUS_TYPE_SYSTEM, + BT_SERVICE_NAME, + G_BUS_NAME_OWNER_FLAGS_NONE, + NULL, NULL, NULL, + NULL, NULL); + BT_DBG("owner_id is [%d]", owner_id); + if (owner_id == 0) + goto fail; + + node_info = __bt_service_create_method_node_info( + bt_service_introspection_xml); + + if (node_info == NULL) + goto fail; + + result = __bt_service_register_object(conn, node_info, TRUE); + g_dbus_node_info_unref(node_info); + node_info = NULL; + + if (result != BLUETOOTH_ERROR_NONE) + goto fail; + + bt_service_conn = conn; + + return BLUETOOTH_ERROR_NONE; + +fail: + if (bt_service_conn) { + g_object_unref(bt_service_conn); + bt_service_conn = NULL; + } + + return BLUETOOTH_ERROR_INTERNAL; +} + +void _bt_service_unregister(void) +{ + if (bt_service_conn) { + __bt_service_register_object(bt_service_conn, NULL, FALSE); + if (bt_service_conn) { + g_object_unref(bt_service_conn); + bt_service_conn = NULL; + } + if (node_info) { + g_dbus_node_info_unref(node_info); + node_info = NULL; + } + if (owner_id > 0) { + g_bus_unown_name(owner_id); + owner_id = 0; + } + } +} + +int _bt_service_cynara_init(void) +{ + int result; + char err_msg[256] = {0, }; + + retv_if(p_cynara != NULL, BLUETOOTH_ERROR_ALREADY_INITIALIZED); + + result = cynara_initialize(&p_cynara, conf); + + if (result != CYNARA_API_SUCCESS) { + cynara_strerror(result, err_msg, sizeof(err_msg)); + BT_ERR("Fail to initialize cynara: [%s]", err_msg); + return BLUETOOTH_ERROR_INTERNAL; + } + + return BLUETOOTH_ERROR_NONE; +} + +void _bt_service_cynara_deinit(void) +{ + int result; + char err_msg[256] = {0, }; + + ret_if(p_cynara == NULL); + + result = cynara_finish(p_cynara); + + if (result != CYNARA_API_SUCCESS) { + cynara_strerror(result, err_msg, sizeof(err_msg)); + BT_ERR("Fail to finish cynara: [%s]", err_msg); + return; + } + + p_cynara = NULL; + conf = NULL; +} + diff --git a/bt-service-emul/bt-service-adapter-le.c b/bt-service-emul/bt-service-adapter-le.c new file mode 100644 index 0000000..0e05c23 --- /dev/null +++ b/bt-service-emul/bt-service-adapter-le.c @@ -0,0 +1,170 @@ +/* + * 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 "bt-internal-types.h" +#include "bt-service-common.h" +#include "bt-service-event.h" +#include "bt-service-adapter-le.h" +#include "bt-service-util.h" + +static gboolean is_le_scanning = FALSE; + +gboolean _bt_is_advertising(void) +{ + return FALSE; +} + +int _bt_set_advertising(const char *sender, int adv_handle, gboolean enable, gboolean use_reserved_slot) +{ + return BLUETOOTH_ERROR_NOT_SUPPORT; +} + +int _bt_set_custom_advertising(const char *sender, int adv_handle, + gboolean enable, bluetooth_advertising_params_t *params, gboolean use_reserved_slot) +{ + BT_CHECK_PARAMETER(params, return); + + return BLUETOOTH_ERROR_NOT_SUPPORT; +} + +int _bt_get_advertising_data(bluetooth_advertising_data_t *adv, int *length) +{ + BT_CHECK_PARAMETER(adv, return); + BT_CHECK_PARAMETER(length, return); + + return BLUETOOTH_ERROR_NOT_SUPPORT; +} + +int _bt_set_advertising_data(const char *sender, int adv_handle, + bluetooth_advertising_data_t *adv, int length, gboolean use_reserved_slot) +{ + BT_CHECK_PARAMETER(adv, return); + + return BLUETOOTH_ERROR_NOT_SUPPORT; +} + +int _bt_get_scan_response_data(bluetooth_scan_resp_data_t *response, int *length) +{ + BT_CHECK_PARAMETER(response, return); + BT_CHECK_PARAMETER(length, return); + + return BLUETOOTH_ERROR_NOT_SUPPORT; +} + +int _bt_set_scan_response_data(const char *sender, int adv_handle, + bluetooth_scan_resp_data_t *response, int length, gboolean use_reserved_slot) +{ + BT_CHECK_PARAMETER(response, return); + + return BLUETOOTH_ERROR_NOT_SUPPORT; +} + +int _bt_set_scan_parameters(bluetooth_le_scan_params_t *params) +{ + BT_CHECK_PARAMETER(params, return); + + return BLUETOOTH_ERROR_NOT_SUPPORT; +} + +int _bt_register_scan_filter(const char *sender, bluetooth_le_scan_filter_t *filter, int *slot_id) +{ + return BLUETOOTH_ERROR_NOT_SUPPORT; +} + +int _bt_unregister_scan_filter(const char *sender, int slot_id) +{ + return BLUETOOTH_ERROR_NOT_SUPPORT; +} + +int _bt_unregister_all_scan_filters(const char *sender) +{ + return BLUETOOTH_ERROR_NOT_SUPPORT; +} + +void _bt_set_le_scan_status(gboolean mode) +{ + is_le_scanning = mode; +} + +gboolean _bt_is_le_scanning(void) +{ + return is_le_scanning; +} + +int _bt_start_le_scan(const char *sender) +{ + return BLUETOOTH_ERROR_NOT_SUPPORT; +} + +int _bt_stop_le_scan(const char *sender) +{ + return BLUETOOTH_ERROR_NOT_SUPPORT; +} + +int _bt_add_white_list(bluetooth_device_address_t *device_address, bluetooth_device_address_type_t address_type) +{ + BT_CHECK_PARAMETER(device_address, return); + + return BLUETOOTH_ERROR_NOT_SUPPORT; +} + +int _bt_remove_white_list(bluetooth_device_address_t *device_address, bluetooth_device_address_type_t address_type) +{ + BT_CHECK_PARAMETER(device_address, return); + + return BLUETOOTH_ERROR_NOT_SUPPORT; +} + +int _bt_clear_white_list(void) +{ + return BLUETOOTH_ERROR_NOT_SUPPORT; +} + +int _bt_initialize_ipsp(void) +{ + return BLUETOOTH_ERROR_NOT_SUPPORT; +} + +int _bt_deinitialize_ipsp(void) +{ + return BLUETOOTH_ERROR_NOT_SUPPORT; +} + +int _bt_le_read_maximum_data_length( + bluetooth_le_read_maximum_data_length_t *max_le_datalength) +{ + return BLUETOOTH_ERROR_NOT_SUPPORT; +} +int _bt_le_write_host_suggested_default_data_length( + const unsigned int def_tx_Octets, const unsigned int def_tx_Time) +{ + return BLUETOOTH_ERROR_NOT_SUPPORT; +} + +int _bt_le_read_host_suggested_default_data_length( + bluetooth_le_read_host_suggested_data_length_t *def_data_length) +{ + return BLUETOOTH_ERROR_NOT_SUPPORT; +} + +int _bt_le_set_data_length(bluetooth_device_address_t *device_address, + const unsigned int max_tx_Octets, const unsigned int max_tx_Time) +{ + return BLUETOOTH_ERROR_NOT_SUPPORT; +} diff --git a/bt-service-emul/bt-service-adapter.c b/bt-service-emul/bt-service-adapter.c new file mode 100644 index 0000000..562de12 --- /dev/null +++ b/bt-service-emul/bt-service-adapter.c @@ -0,0 +1,964 @@ +/* + * 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-api.h" +#include "bt-internal-types.h" + +#include "bt-service-common.h" +#include "bt-service-event.h" +#include "bt-service-adapter.h" +#include "bt-service-util.h" +#include "bt-service-main.h" + +typedef struct { + guint event_id; + int timeout; + time_t start_time; + gboolean alarm_init; + int alarm_id; +} bt_adapter_timer_t; + +bt_adapter_timer_t visible_timer = {0, }; + +static gboolean is_discovering; +static gboolean cancel_by_user; +static bt_status_t adapter_status = BT_DEACTIVATED; +static bt_le_status_t adapter_le_status = BT_LE_DEACTIVATED; +static guint timer_id = 0; +static guint le_timer_id = 0; + +static uint status_reg_id; + +static char *g_local_name; +static gboolean g_is_discoverable; + +#define BT_DISABLE_TIME 500 /* 500 ms */ +#define BT_DEFAULT_NAME "Tizen Emulator" + + +static gboolean __bt_timeout_handler(gpointer user_data) +{ + int result = BLUETOOTH_ERROR_NONE; + time_t current_time; + int time_diff; + + /* Take current time */ + time(¤t_time); + time_diff = difftime(current_time, visible_timer.start_time); + + /* Send event to application */ + _bt_send_event(BT_ADAPTER_EVENT, + BLUETOOTH_EVENT_DISCOVERABLE_TIMEOUT_CHANGED, + g_variant_new("(in)", result, time_diff)); + + if (visible_timer.timeout <= time_diff) { + g_source_remove(visible_timer.event_id); + visible_timer.event_id = 0; + visible_timer.timeout = 0; + +#ifndef TIZEN_WEARABLE + if (vconf_set_int(BT_FILE_VISIBLE_TIME, 0) != 0) + BT_ERR("Set vconf failed\n"); +#endif + return FALSE; + } + + return TRUE; +} + +static int __bt_visibility_alarm_cb(alarm_id_t alarm_id, void* user_param) +{ + BT_DBG("__bt_visibility_alarm_cb - alram id = [%d] \n", alarm_id); + + int result = BLUETOOTH_ERROR_NONE; + int timeout = 0; + + if (alarm_id != visible_timer.alarm_id) + return 0; + + if (visible_timer.event_id) { + _bt_send_event(BT_ADAPTER_EVENT, + BLUETOOTH_EVENT_DISCOVERABLE_TIMEOUT_CHANGED, + g_variant_new("(in)", result, timeout)); + g_source_remove(visible_timer.event_id); + visible_timer.event_id = 0; + visible_timer.timeout = 0; + +#ifndef TIZEN_WEARABLE + if (vconf_set_int(BT_FILE_VISIBLE_TIME, 0) != 0) + BT_ERR("Set vconf failed\n"); +#endif + } + /* Switch Off visibility in Bluez */ + _bt_set_discoverable_mode(BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE, 0); + visible_timer.alarm_id = 0; + return 0; +} + +static void __bt_visibility_alarm_create() +{ + alarm_id_t alarm_id; + int result; + + result = alarmmgr_add_alarm(ALARM_TYPE_VOLATILE, visible_timer.timeout, + 0, NULL, &alarm_id); + if (result < 0) { + BT_ERR("Failed to create alarm error = %d\n", result); + } else { + BT_DBG("Alarm created = %d\n", alarm_id); + visible_timer.alarm_id = alarm_id; + } +} + +static void __bt_visibility_alarm_remove() +{ + if (visible_timer.event_id > 0) { + g_source_remove(visible_timer.event_id); + visible_timer.event_id = 0; + } + + if (visible_timer.alarm_id > 0) { + alarmmgr_remove_alarm(visible_timer.alarm_id); + visible_timer.alarm_id = 0; + } +} + +int __bt_set_visible_time(int timeout) +{ + int result; + + __bt_visibility_alarm_remove(); + + visible_timer.timeout = timeout; + +#ifndef TIZEN_WEARABLE + if (vconf_set_int(BT_FILE_VISIBLE_TIME, timeout) != 0) + BT_ERR("Set vconf failed"); +#endif + + if (timeout <= 0) + return BLUETOOTH_ERROR_NONE; + + if (!visible_timer.alarm_init) { + /* Set Alarm timer to switch off BT */ + result = alarmmgr_init("bt-service"); + if (result != 0) + return BLUETOOTH_ERROR_INTERNAL; + + visible_timer.alarm_init = TRUE; + } + + result = alarmmgr_set_cb(__bt_visibility_alarm_cb, NULL); + if (result != 0) + return BLUETOOTH_ERROR_INTERNAL; + + /* Take start time */ + time(&(visible_timer.start_time)); + visible_timer.event_id = g_timeout_add_seconds(1, + __bt_timeout_handler, NULL); + + __bt_visibility_alarm_create(); + + return BLUETOOTH_ERROR_NONE; +} + +void _bt_set_discovery_status(gboolean mode) +{ + is_discovering = mode; +} + +void _bt_set_cancel_by_user(gboolean value) +{ + cancel_by_user = value; +} + +gboolean _bt_get_cancel_by_user(void) +{ + return cancel_by_user; +} + +void _bt_adapter_set_status(bt_status_t status) +{ + BT_INFO("adapter_status changed [%d] -> [%d]", adapter_status, status); + adapter_status = status; +} + +bt_status_t _bt_adapter_get_status(void) +{ + return adapter_status; +} + +void _bt_adapter_set_le_status(bt_le_status_t status) +{ + BT_INFO("adapter_le_status changed [%d] -> [%d]", adapter_le_status, status); + adapter_le_status = status; +} + +bt_le_status_t _bt_adapter_get_le_status(void) +{ + return adapter_le_status; +} + +static void __bt_phone_name_changed_cb(keynode_t *node, void *data) +{ + char *phone_name = NULL; + char *ptr = NULL; + + if (node == NULL) + return; + + if (vconf_keynode_get_type(node) == VCONF_TYPE_STRING) { + phone_name = vconf_keynode_get_str(node); + + if (phone_name && strlen(phone_name) != 0) { + if (!g_utf8_validate(phone_name, -1, + (const char **)&ptr)) + *ptr = '\0'; + + _bt_set_local_name(phone_name); + } + } +} + +#ifdef TIZEN_MOBILE +static void __bt_set_visible_mode(void) +{ + int timeout = 0; + + if (vconf_get_int(BT_FILE_VISIBLE_TIME, &timeout) != 0) + BT_ERR("Fail to get the timeout value"); + + if (timeout == -1) { + if (_bt_set_discoverable_mode( + BLUETOOTH_DISCOVERABLE_MODE_GENERAL_DISCOVERABLE, + timeout) != BLUETOOTH_ERROR_NONE) { + if (vconf_set_int(BT_FILE_VISIBLE_TIME, 0) != 0) + BT_ERR("Set vconf failed"); + } + } else { + if (_bt_set_discoverable_mode( + BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE, + timeout) != BLUETOOTH_ERROR_NONE) { + BT_ERR("Set connectable mode failed"); + } + } +} +#endif + +static void __bt_set_local_name(void) +{ + char *phone_name = NULL; + char *ptr = NULL; + + phone_name = vconf_get_str(VCONFKEY_SETAPPL_DEVICE_NAME_STR); + + if (!phone_name) + return; + + if (strlen(phone_name) != 0) { + if (!g_utf8_validate(phone_name, -1, (const char **)&ptr)) + *ptr = '\0'; + + _bt_set_local_name(phone_name); + } + free(phone_name); +} + +static int __bt_set_enabled(void) +{ + BT_DBG("+"); + int result = BLUETOOTH_ERROR_NONE; + +#ifdef TIZEN_MOBILE + __bt_set_visible_mode(); +#else +#ifdef TIZEN_TV + if (_bt_set_discoverable_mode( + BLUETOOTH_DISCOVERABLE_MODE_GENERAL_DISCOVERABLE, 0) != BLUETOOTH_ERROR_NONE) + BT_ERR("Fail to set discoverable mode"); +#endif +#endif + __bt_set_local_name(); + + /* Update Bluetooth Status to notify other modules */ + if (vconf_set_int(VCONFKEY_BT_STATUS, VCONFKEY_BT_STATUS_ON) != 0) + BT_ERR("Set vconf failed\n"); + + if (vconf_set_int(VCONFKEY_BT_DEVICE, VCONFKEY_BT_DEVICE_NONE) != 0) + BT_ERR("Set vconf failed\n"); +#if 0 + if (_bt_eventsystem_set_value(SYS_EVENT_BT_STATE, EVT_KEY_BT_STATE, + EVT_VAL_BT_ON) != ES_R_OK) + BT_ERR("Fail to set value"); +#endif + + /* Send enabled event to API */ + _bt_send_event(BT_ADAPTER_EVENT, BLUETOOTH_EVENT_ENABLED, + g_variant_new("(i)", result)); + BT_DBG("-"); + + return BLUETOOTH_ERROR_NONE; +} + +void _bt_set_disabled(int result) +{ + int power_off_status = 0; + int ret; + int ret_pm_ignore; + int pm_ignore_mode = 0; + + ret = vconf_get_int(VCONFKEY_SYSMAN_POWER_OFF_STATUS, &power_off_status); + BT_DBG("ret : %d, power_off_status : %d", ret, power_off_status); + + ret_pm_ignore = vconf_get_int(VCONFKEY_PM_KEY_IGNORE, &pm_ignore_mode); + + /* Update the vconf BT status in normal Deactivation case only */ + if (ret == 0 && power_off_status == VCONFKEY_SYSMAN_POWER_OFF_NONE && + ret_pm_ignore == 0 && pm_ignore_mode != VCONFKEY_PM_KEY_LOCK) { + + BT_DBG("Update vconf for BT normal Deactivation"); + + if (result == BLUETOOTH_ERROR_TIMEOUT) + if (vconf_set_int(BT_OFF_DUE_TO_TIMEOUT, 1) != 0) + BT_ERR("Set vconf failed"); + + /* Update Bluetooth Status to notify other modules */ + if (vconf_set_int(VCONFKEY_BT_STATUS, VCONFKEY_BT_STATUS_OFF) != 0) + BT_ERR("Set vconf failed"); + + if (_bt_eventsystem_set_value(SYS_EVENT_BT_STATE, EVT_KEY_BT_STATE, + EVT_VAL_BT_OFF) != ES_R_OK) + BT_ERR("Fail to set value"); + } + + if (vconf_set_int(VCONFKEY_BT_DEVICE, VCONFKEY_BT_DEVICE_NONE) != 0) + BT_ERR("Set vconf failed\n"); + + _bt_adapter_set_status(BT_DEACTIVATED); + + _bt_send_event(BT_ADAPTER_EVENT, BLUETOOTH_EVENT_DISABLED, + g_variant_new("(i)", result)); + + BT_INFO("Adapter disabled"); +} + +static int __bt_set_le_enabled(void) +{ + BT_DBG("+"); + int result = BLUETOOTH_ERROR_NONE; + bt_status_t status; + + __bt_set_local_name(); + + /* Update Bluetooth Status to notify other modules */ + if (vconf_set_int(VCONFKEY_BT_LE_STATUS, VCONFKEY_BT_LE_STATUS_ON) != 0) + BT_ERR("Set vconf failed\n"); + + if (_bt_eventsystem_set_value(SYS_EVENT_BT_STATE, EVT_KEY_BT_LE_STATE, + EVT_VAL_BT_LE_ON) != ES_R_OK) + BT_ERR("Fail to set value"); + + /* Send enabled event to API */ + /* + _bt_send_event(BT_ADAPTER_EVENT, BLUETOOTH_EVENT_ENABLED, + DBUS_TYPE_INT32, &result, DBUS_TYPE_INVALID); + */ + status = _bt_adapter_get_status(); + if (status == BT_DEACTIVATED) { + BT_INFO("BREDR is off, turn off PSCAN"); + _bt_set_connectable(FALSE); + } + if (le_timer_id > 0) { + g_source_remove(le_timer_id); + le_timer_id = 0; + } + + /* Send enabled event to API */ + _bt_send_event(BT_LE_ADAPTER_EVENT, BLUETOOTH_EVENT_LE_ENABLED, + g_variant_new("(i)", result)); + + BT_DBG("-"); + return BLUETOOTH_ERROR_NONE; +} + +void _bt_set_le_disabled(int result) +{ + int power_off_status; + int ret; + + ret = vconf_get_int(VCONFKEY_SYSMAN_POWER_OFF_STATUS, &power_off_status); + BT_DBG("ret : %d", ret); + BT_DBG("power_off_status : %d", power_off_status); + + /* Update Bluetooth Status to notify other modules */ + BT_DBG("Update vconf for BT LE normal Deactivation"); + if (vconf_set_int(VCONFKEY_BT_LE_STATUS, VCONFKEY_BT_LE_STATUS_OFF) != 0) + BT_ERR("Set vconf failed\n"); + _bt_adapter_set_le_status(BT_LE_DEACTIVATED); + + if (_bt_eventsystem_set_value(SYS_EVENT_BT_STATE, EVT_KEY_BT_LE_STATE, + EVT_VAL_BT_LE_OFF) != ES_R_OK) + BT_ERR("Fail to set value"); + + /* Send disabled event */ + _bt_send_event(BT_LE_ADAPTER_EVENT, BLUETOOTH_EVENT_LE_DISABLED, + g_variant_new_int32(result)); +} + +#if defined(TIZEN_BT_FLIGHTMODE_ENABLED) || (!defined(TIZEN_WEARABLE) && defined(ENABLE_TIZEN_2_4)) +static void __bt_service_flight_ps_mode_cb(keynode_t *node, void *data) +{ + gboolean flight_mode = FALSE; + int power_saving_mode = 0; + int type; + + DBG_SECURE("key=%s", vconf_keynode_get_name(node)); + type = vconf_keynode_get_type(node); + if (type == VCONF_TYPE_BOOL) { + flight_mode = vconf_keynode_get_bool(node); + if (flight_mode != TRUE) { + BT_ERR("Ignore the event"); + return; + } + } else if (type == VCONF_TYPE_INT) { + power_saving_mode = vconf_keynode_get_int(node); + if (power_saving_mode != 2) { + BT_ERR("Ignore the event"); + return; + } + } else { + BT_ERR("Invaild vconf key type : %d", type); + return; + } +} +#endif + +void _bt_service_register_vconf_handler(void) +{ + BT_DBG("+"); + +#ifdef TIZEN_BT_FLIGHTMODE_ENABLED + if (vconf_notify_key_changed(VCONFKEY_TELEPHONY_FLIGHT_MODE, + (vconf_callback_fn)__bt_service_flight_ps_mode_cb, NULL) < 0) + BT_ERR("Unable to register key handler"); +#else + BT_DBG("Telephony is disabled"); +#endif + +#ifndef TIZEN_WEARABLE +#ifdef ENABLE_TIZEN_2_4 + if (vconf_notify_key_changed(VCONFKEY_SETAPPL_PSMODE, + (vconf_callback_fn)__bt_service_flight_ps_mode_cb, NULL) < 0) + BT_ERR("Unable to register key handler"); +#endif +#endif +} + +void _bt_service_unregister_vconf_handler(void) +{ + BT_DBG("+"); + +#ifdef TIZEN_BT_FLIGHTMODE_ENABLED + vconf_ignore_key_changed(VCONFKEY_TELEPHONY_FLIGHT_MODE, + (vconf_callback_fn)__bt_service_flight_ps_mode_cb); +#endif + +#ifndef TIZEN_WEARABLE +#ifdef ENABLE_TIZEN_2_4 + vconf_ignore_key_changed(VCONFKEY_SETAPPL_PSMODE, + (vconf_callback_fn)__bt_service_flight_ps_mode_cb); +#endif +#endif +} + +static void __bt_state_event_handler(const char *event_name, bundle *data, void *user_data) +{ +#ifdef ENABLE_TIZEN_2_4 + const char *bt_status = NULL; + const char *bt_le_status = NULL; + BT_DBG("bt state set event(%s) received", event_name); + bt_status = bundle_get_val(data, EVT_KEY_BT_STATE); + BT_DBG("bt_state: (%s)", bt_status); + + bt_le_status = bundle_get_val(data, EVT_KEY_BT_LE_STATE); + BT_DBG("bt_state: (%s)", bt_le_status); +#endif +} + +void _bt_handle_adapter_added(void) +{ + BT_DBG("+"); + bt_status_t status; + bt_le_status_t le_status; + int ret; + + if (timer_id > 0) { + BT_DBG("g_source is removed"); + g_source_remove(timer_id); + timer_id = 0; + } + + status = _bt_adapter_get_status(); + le_status = _bt_adapter_get_le_status(); + BT_DBG("status : %d", status); + BT_DBG("le_status : %d", le_status); + + /* add the vconf noti handler */ + ret = vconf_notify_key_changed(VCONFKEY_SETAPPL_DEVICE_NAME_STR, + __bt_phone_name_changed_cb, NULL); + if (ret < 0) + BT_ERR("Unable to register key handler"); + + if (le_status == BT_LE_ACTIVATING || + status == BT_ACTIVATING) { + __bt_set_le_enabled(); + _bt_adapter_set_le_status(BT_LE_ACTIVATED); + } + + if (status == BT_ACTIVATING) { + __bt_set_enabled(); + _bt_adapter_set_status(BT_ACTIVATED); + } +#ifdef ENABLE_TIZEN_2_4 + journal_bt_on(); +#endif + + _bt_service_register_vconf_handler(); + + /* eventsystem */ + if (eventsystem_register_event(SYS_EVENT_BT_STATE, &status_reg_id, + (eventsystem_handler)__bt_state_event_handler, NULL) != ES_R_OK) { + BT_ERR("Fail to register system event"); + } +} + +void _bt_handle_adapter_removed(void) +{ + int ret; + + _bt_adapter_set_status(BT_DEACTIVATED); +#ifdef ENABLE_TIZEN_2_4 + journal_bt_off(); +#endif + + __bt_visibility_alarm_remove(); + + if (visible_timer.alarm_init) { + alarmmgr_fini(); + visible_timer.alarm_init = FALSE; + } + + ret = vconf_ignore_key_changed(VCONFKEY_SETAPPL_DEVICE_NAME_STR, + (vconf_callback_fn)__bt_phone_name_changed_cb); + if (0 != ret) { + BT_ERR("vconf_ignore_key_changed failed\n"); + } + + _bt_reliable_terminate_service(NULL); + + if (eventsystem_unregister_event(status_reg_id) != ES_R_OK) { + BT_ERR("Fail to unregister system event"); + } + +} + +static gboolean __bt_enable_timeout_cb(gpointer user_data) +{ + timer_id = 0; + + retv_if(_bt_adapter_get_status() == BT_ACTIVATED, FALSE); + + BT_ERR("EnableAdapter is failed"); + + _bt_set_disabled(BLUETOOTH_ERROR_TIMEOUT); + + _bt_terminate_service(NULL); + + return FALSE; +} + +static gboolean __bt_enable_le_timeout_cb(gpointer user_data) +{ + le_timer_id = 0; + + retv_if(_bt_adapter_get_le_status() == BT_LE_ACTIVATED, FALSE); + + BT_ERR("EnableAdapterLE is failed"); + + _bt_adapter_set_le_status(BT_LE_DEACTIVATED); + + _bt_set_le_disabled(BLUETOOTH_ERROR_TIMEOUT); + + if (_bt_adapter_get_status() == BT_DEACTIVATED) + _bt_terminate_service(NULL); + + return FALSE; +} + +void _bt_adapter_start_le_enable_timer(void) +{ + if (le_timer_id > 0) { + g_source_remove(le_timer_id); + le_timer_id = 0; + } + + le_timer_id = g_timeout_add(BT_ENABLE_TIMEOUT, + __bt_enable_le_timeout_cb, NULL); + + return; +} + +void _bt_adapter_start_enable_timer(void) +{ + if (timer_id > 0) { + g_source_remove(timer_id); + timer_id = 0; + } + + timer_id = g_timeout_add(BT_ENABLE_TIMEOUT, + __bt_enable_timeout_cb, NULL); + + return; +} + +int _bt_enable_adapter(void) +{ + bt_status_t status = _bt_adapter_get_status(); + bt_le_status_t le_status = _bt_adapter_get_le_status(); + + BT_DBG(""); + + if (status == BT_ACTIVATING) { + BT_ERR("Enabling in progress"); + return BLUETOOTH_ERROR_IN_PROGRESS; + } + + if (status == BT_ACTIVATED) { + BT_ERR("Already enabled"); + return BLUETOOTH_ERROR_DEVICE_ALREADY_ENABLED; + } + + if (status == BT_DEACTIVATING || le_status == BT_LE_DEACTIVATING) { + BT_ERR("Disabling in progress"); + return BLUETOOTH_ERROR_DEVICE_BUSY; + } + + _bt_adapter_set_status(BT_ADAPTER_ENABLED); + + __bt_set_enabled(); + + return BLUETOOTH_ERROR_NONE; +} + +int _bt_disable_adapter(void) +{ + BT_DBG("+"); + + if (_bt_adapter_get_status() == BT_DEACTIVATING) { + BT_DBG("Disabling in progress"); + return BLUETOOTH_ERROR_IN_PROGRESS; + } + + if (_bt_adapter_get_status() == BT_DEACTIVATED) { + BT_DBG("Already disabled"); + return BLUETOOTH_ERROR_DEVICE_NOT_ENABLED; + } + + if (timer_id > 0) { + g_source_remove(timer_id); + timer_id = 0; + } + + _bt_handle_adapter_removed(); + + BT_DBG("-"); + return BLUETOOTH_ERROR_NONE; +} + +int _bt_recover_adapter(void) +{ + return BLUETOOTH_ERROR_NOT_SUPPORT; +} + +int _bt_reset_adapter(void) +{ + if (timer_id > 0) { + g_source_remove(timer_id); + timer_id = 0; + } + + _bt_set_disabled(BLUETOOTH_ERROR_NONE); + + return BLUETOOTH_ERROR_NONE; +} + +int _bt_check_adapter(int *status) +{ + + BT_CHECK_PARAMETER(status, return); + + *status = adapter_status; + + return BLUETOOTH_ERROR_NONE; +} + +int _bt_enable_adapter_le(void) +{ + BT_DBG("+"); + bt_status_t status = _bt_adapter_get_status(); + bt_le_status_t le_status = _bt_adapter_get_le_status(); + + if (le_status == BT_LE_ACTIVATING) { + BT_ERR("Enabling in progress"); + return BLUETOOTH_ERROR_IN_PROGRESS; + } + + if (le_status == BT_LE_ACTIVATED) { + BT_ERR("Already enabled"); + return BLUETOOTH_ERROR_DEVICE_ALREADY_ENABLED; + } + + if (status == BT_DEACTIVATING || le_status == BT_LE_DEACTIVATING) { + BT_ERR("Disabling in progress"); + return BLUETOOTH_ERROR_DEVICE_BUSY; + } + + __bt_set_le_enabled(); + + BT_DBG("le status : %d", _bt_adapter_get_le_status()); + BT_DBG("-"); + return BLUETOOTH_ERROR_NONE; +} + +int _bt_disable_adapter_le(void) +{ + BT_DBG("+"); + bt_le_status_t bt_le_state; + + bt_le_state = _bt_adapter_get_le_status(); + if (bt_le_state == BT_LE_DEACTIVATING) { + BT_DBG("Disabling in progress"); + return BLUETOOTH_ERROR_IN_PROGRESS; + } + + if (bt_le_state == BT_LE_DEACTIVATED) { + BT_DBG("Already disabled"); + return BLUETOOTH_ERROR_DEVICE_NOT_ENABLED; + } + + _bt_set_le_disabled(BLUETOOTH_ERROR_NONE); + + BT_DBG("le status : %d", _bt_adapter_get_le_status()); + BT_DBG("-"); + return BLUETOOTH_ERROR_NONE; +} + +int _bt_get_local_address(bluetooth_device_address_t *local_address) +{ + const char *address = "11:22:33:44:55:66"; + + BT_CHECK_PARAMETER(local_address, return); + + BT_DBG("Address:%s", address); + + _bt_convert_addr_string_to_type(local_address->addr, address); + + return BLUETOOTH_ERROR_NONE; +} + +int _bt_get_local_version(bluetooth_version_t *local_version) +{ + const char *ver = "Tizen BT emul v0.1"; + + BT_CHECK_PARAMETER(local_version, return); + + g_strlcpy(local_version->version, ver, BLUETOOTH_VERSION_LENGTH_MAX + 1); + + return BLUETOOTH_ERROR_NONE; +} + +int _bt_get_local_name(bluetooth_device_name_t *local_name) +{ + BT_CHECK_PARAMETER(local_name, return); + + if (g_local_name != NULL) + g_local_name = g_strdup(BT_DEFAULT_NAME); + + g_strlcpy(local_name->name, g_local_name, BLUETOOTH_DEVICE_NAME_LENGTH_MAX + 1); + + return BLUETOOTH_ERROR_NONE; +} + +int _bt_set_local_name(char *local_name) +{ + BT_CHECK_PARAMETER(local_name, return); + + g_free(g_local_name); + g_local_name = g_strdup(local_name); + + return BLUETOOTH_ERROR_NONE; +} + +int _bt_is_service_used(char *service_uuid, gboolean *used) +{ + BT_CHECK_PARAMETER(service_uuid, return); + BT_CHECK_PARAMETER(used, return); + + *used = FALSE; + + return BLUETOOTH_ERROR_NOT_SUPPORT; +} + +int _bt_get_discoverable_mode(int *mode) +{ + BT_CHECK_PARAMETER(mode, return); + + if (g_is_discoverable == TRUE) { + if (visible_timer.timeout == 0) + *mode = BLUETOOTH_DISCOVERABLE_MODE_GENERAL_DISCOVERABLE; + else + *mode = BLUETOOTH_DISCOVERABLE_MODE_TIME_LIMITED_DISCOVERABLE; + } else { + *mode = BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE; + } + return BLUETOOTH_ERROR_NONE; +} + + +int _bt_set_discoverable_mode(int discoverable_mode, int timeout) +{ + int ret = BLUETOOTH_ERROR_NONE; + + switch (discoverable_mode) { + case BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE: + g_is_discoverable = FALSE; + timeout = 0; + break; + case BLUETOOTH_DISCOVERABLE_MODE_GENERAL_DISCOVERABLE: + timeout = 0; + g_is_discoverable = TRUE; + break; + case BLUETOOTH_DISCOVERABLE_MODE_TIME_LIMITED_DISCOVERABLE: + g_is_discoverable = TRUE; + break; + default: + return BLUETOOTH_ERROR_INVALID_PARAM; + } + + BT_INFO("Req. discoverable_mode : %d, timeout : %d", + discoverable_mode, timeout); + + if (discoverable_mode == BLUETOOTH_DISCOVERABLE_MODE_GENERAL_DISCOVERABLE) + timeout = -1; + + ret = __bt_set_visible_time(timeout); + + return ret; +} + +int _bt_start_discovery(void) +{ + return _bt_start_custom_discovery(DISCOVERY_ROLE_LE_BREDR); +} + +int _bt_start_custom_discovery(bt_discovery_role_type_t role) +{ + is_discovering = TRUE; + cancel_by_user = FALSE; + + /* Need to implement the timer and event for this API */ + + return BLUETOOTH_ERROR_NONE; + +} + +int _bt_cancel_discovery(void) +{ + is_discovering = FALSE; + cancel_by_user = TRUE; + + /* Need to implement the event for this API */ + + return BLUETOOTH_ERROR_NONE; +} + +gboolean _bt_is_discovering(void) +{ + return is_discovering; +} + +gboolean _bt_is_connectable(void) +{ + return FALSE; +} + +int _bt_set_connectable(gboolean is_connectable) +{ + return BLUETOOTH_ERROR_NOT_SUPPORT; +} + +int _bt_get_bonded_devices(GArray **dev_list) +{ + /* Should implement this */ + + return BLUETOOTH_ERROR_NONE; +} + +int _bt_get_bonded_device_info(bluetooth_device_address_t *device_address, + bluetooth_device_info_t *dev_info) +{ + BT_CHECK_PARAMETER(device_address, return); + BT_CHECK_PARAMETER(dev_info, return); + + /* Should implement this */ + + return BLUETOOTH_ERROR_NONE; +} + +int _bt_get_timeout_value(int *timeout) +{ + time_t current_time; + int time_diff; + + /* Take current time */ + time(¤t_time); + time_diff = difftime(current_time, visible_timer.start_time); + + BT_DBG("Time diff = %d\n", time_diff); + + *timeout = visible_timer.timeout - time_diff; + + return BLUETOOTH_ERROR_NONE; +} + +int _bt_set_le_privacy(gboolean set_privacy) +{ + return BLUETOOTH_ERROR_NOT_SUPPORT; +} + +int _bt_set_manufacturer_data(bluetooth_manufacturer_data_t *m_data) +{ + BT_CHECK_PARAMETER(m_data, return); + + return BLUETOOTH_ERROR_NOT_SUPPORT; +} + diff --git a/bt-service-emul/bt-service-audio.c b/bt-service-emul/bt-service-audio.c new file mode 100644 index 0000000..34f8d44 --- /dev/null +++ b/bt-service-emul/bt-service-audio.c @@ -0,0 +1,70 @@ +/* + * 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 "bluetooth-api.h" +#include "bt-internal-types.h" + +#include "bt-service-audio.h" +#include "bt-service-common.h" +#include "bt-service-device.h" +#include "bt-service-util.h" + + +int _bt_audio_connect(int request_id, int type, + bluetooth_device_address_t *device_address, + GArray **out_param1) +{ + BT_CHECK_PARAMETER(device_address, return); + + return BLUETOOTH_ERROR_NOT_SUPPORT; +} + +int _bt_audio_disconnect(int request_id, int type, + bluetooth_device_address_t *device_address, + GArray **out_param1) +{ + BT_CHECK_PARAMETER(device_address, return); + + return BLUETOOTH_ERROR_NOT_SUPPORT; +} + +int _bt_hf_connect(int request_id, + bluetooth_device_address_t *device_address, + GArray **out_param1) +{ + BT_CHECK_PARAMETER(device_address, return); + + return BLUETOOTH_ERROR_NOT_SUPPORT; +} + +int _bt_hf_disconnect(int request_id, + bluetooth_device_address_t *device_address, + GArray **out_param1) +{ + BT_CHECK_PARAMETER(device_address, return); + + return BLUETOOTH_ERROR_NOT_SUPPORT; +} + +int _bt_audio_set_content_protect(gboolean status) +{ + return BLUETOOTH_ERROR_NOT_SUPPORT; +} diff --git a/bt-service-emul/bt-service-avrcp-controller.c b/bt-service-emul/bt-service-avrcp-controller.c new file mode 100644 index 0000000..9fbf0f7 --- /dev/null +++ b/bt-service-emul/bt-service-avrcp-controller.c @@ -0,0 +1,45 @@ +/* + * 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 "bt-internal-types.h" +#include "bt-service-common.h" +#include "bt-service-avrcp-controller.h" +#include "bt-service-event.h" + +int _bt_avrcp_control_cmd(int type) +{ + return BLUETOOTH_ERROR_NOT_SUPPORT; +} + +int _bt_avrcp_control_get_property(int type, unsigned int *value) +{ + BT_CHECK_PARAMETER(value, return); + + return BLUETOOTH_ERROR_NOT_SUPPORT; +} + +int _bt_avrcp_control_set_property(int type, unsigned int value) +{ + return BLUETOOTH_ERROR_NOT_SUPPORT; +} + +int _bt_avrcp_control_get_track_info(media_metadata_attributes_t *metadata) +{ + retv_if(metadata == NULL, BLUETOOTH_ERROR_INTERNAL); + + return BLUETOOTH_ERROR_NOT_SUPPORT; +} diff --git a/bt-service-emul/bt-service-avrcp.c b/bt-service-emul/bt-service-avrcp.c new file mode 100644 index 0000000..ea546d8 --- /dev/null +++ b/bt-service-emul/bt-service-avrcp.c @@ -0,0 +1,46 @@ +/* + * 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 "bluetooth-api.h" +#include "bt-internal-types.h" +#include "bt-service-common.h" +#include "bt-service-avrcp.h" +#include "bt-service-event.h" +#include "bt-service-util.h" + +int _bt_avrcp_set_track_info(media_metadata_attributes_t *meta_data) +{ + retv_if(meta_data == NULL, BLUETOOTH_ERROR_INTERNAL); + + return BLUETOOTH_ERROR_NOT_SUPPORT; +} + +int _bt_avrcp_set_properties(media_player_settings_t *properties) +{ + retv_if(properties == NULL, BLUETOOTH_ERROR_INTERNAL); + + return BLUETOOTH_ERROR_NOT_SUPPORT; +} + +int _bt_avrcp_set_property(int type, unsigned int value) +{ + return BLUETOOTH_ERROR_NOT_SUPPORT; +} diff --git a/bt-service-emul/bt-service-common.c b/bt-service-emul/bt-service-common.c new file mode 100644 index 0000000..348fa6f --- /dev/null +++ b/bt-service-emul/bt-service-common.c @@ -0,0 +1,547 @@ +/* + * 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 +#include +#include +#include +#include +#include +#include +#include + +#include "bluetooth-api.h" +#include "bt-service-common.h" + +static GDBusConnection *system_conn; +static GDBusConnection *session_conn; +static GDBusConnection *system_gconn = NULL; + +GDBusConnection *_bt_gdbus_init_system_gconn(void) +{ + GError *error = NULL; + + dbus_threads_init_default(); + + if (system_gconn != NULL) + return system_gconn; + + system_gconn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error); + + if (!system_gconn) { + BT_ERR("Unable to connect to dbus: %s", error->message); + g_clear_error(&error); + } + + return system_gconn; +} + +GDBusConnection *_bt_gdbus_get_system_gconn(void) +{ + GDBusConnection *local_system_gconn = NULL; + GError *error = NULL; + + if (system_gconn == NULL) { + system_gconn = _bt_gdbus_init_system_gconn(); + } else if (g_dbus_connection_is_closed(system_gconn)) { + + local_system_gconn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error); + + if (!local_system_gconn) { + BT_ERR("Unable to connect to dbus: %s", error->message); + g_clear_error(&error); + } + + system_gconn = local_system_gconn; + } + + return system_gconn; +} + +GDBusConnection *__bt_init_system_gconn(void) +{ + if (system_conn == NULL) + system_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, NULL); + + return system_conn; +} + +GDBusConnection *__bt_init_session_conn(void) +{ + if (session_conn == NULL) + session_conn = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, NULL); + + return session_conn; +} + +GDBusConnection *_bt_get_session_gconn(void) +{ + return (session_conn) ? session_conn : __bt_init_session_conn(); +} + +GDBusConnection *_bt_get_system_gconn(void) +{ + return (system_conn) ? system_conn : __bt_init_system_gconn(); +} + +GDBusConnection *_bt_get_system_conn(void) +{ + GDBusConnection *g_conn; + + if (system_conn == NULL) { + g_conn = __bt_init_system_gconn(); + } else { + g_conn = system_conn; + } + + retv_if(g_conn == NULL, NULL); + + return g_conn; +} + +void _bt_deinit_proxys(void) +{ + if (system_conn) { + g_object_unref(system_conn); + system_conn = NULL; + } + + if (session_conn) { + g_object_unref(session_conn); + session_conn = NULL; + } +} + +void _bt_convert_device_path_to_address(const char *device_path, + char *device_address) +{ + char address[BT_ADDRESS_STRING_SIZE] = { 0 }; + char *dev_addr; + + ret_if(device_path == NULL); + ret_if(device_address == NULL); + + dev_addr = strstr(device_path, "dev_"); + if (dev_addr != NULL) { + char *pos = NULL; + dev_addr += 4; + g_strlcpy(address, dev_addr, sizeof(address)); + + while ((pos = strchr(address, '_')) != NULL) { + *pos = ':'; + } + + g_strlcpy(device_address, address, BT_ADDRESS_STRING_SIZE); + } +} + + +void _bt_convert_addr_string_to_type(unsigned char *addr, + const char *address) +{ + int i; + char *ptr = NULL; + + ret_if(address == NULL); + ret_if(addr == NULL); + + for (i = 0; i < BT_ADDRESS_LENGTH_MAX; i++) { + addr[i] = strtol(address, &ptr, 16); + if (ptr[0] != '\0') { + if (ptr[0] != ':') + return; + + address = ptr + 1; + } + } +} + +void _bt_convert_addr_type_to_string(char *address, + unsigned char *addr) +{ + ret_if(address == NULL); + ret_if(addr == NULL); + + snprintf(address, BT_ADDRESS_STRING_SIZE, + "%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X", + addr[0], addr[1], addr[2], + addr[3], addr[4], addr[5]); +} + +void _bt_print_device_address_t(const bluetooth_device_address_t *addr) +{ + BT_DBG("%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X\n", addr->addr[0], addr->addr[1], addr->addr[2], + addr->addr[3], addr->addr[4], addr->addr[5]); +} + +void _bt_divide_device_class(bluetooth_device_class_t *device_class, + unsigned int cod) +{ + ret_if(device_class == NULL); + + device_class->major_class = (unsigned short)(cod & 0x00001F00) >> 8; + device_class->minor_class = (unsigned short)((cod & 0x000000FC)); + device_class->service_class = (unsigned long)((cod & 0x00FF0000)); + + if (cod & 0x002000) { + device_class->service_class |= + BLUETOOTH_DEVICE_SERVICE_CLASS_LIMITED_DISCOVERABLE_MODE; + } +} + +void _bt_free_device_info(bt_remote_dev_info_t *dev_info) +{ + int i; + + ret_if(dev_info == NULL); + + g_free(dev_info->address); + g_free(dev_info->name); + g_free(dev_info->manufacturer_data); + + if (dev_info->uuids) { + for (i = 0; i < dev_info->uuid_count && dev_info->uuids[i]; i++) + g_free(dev_info->uuids[i]); + + g_free(dev_info->uuids); + } + + g_free(dev_info); +} + +void _bt_free_le_device_info(bt_remote_le_dev_info_t *le_dev_info) +{ + ret_if(le_dev_info == NULL); + + g_free(le_dev_info->adv_data); + g_free(le_dev_info); +} + +int _bt_copy_utf8_string(char *dest, const char *src, unsigned int length) +{ + int i; + const char *p = src; + char *next; + int count; + + if (dest == NULL || src == NULL) + return BLUETOOTH_ERROR_INVALID_PARAM; + + BT_DBG("+src : %s", src); + BT_DBG("+dest : %s", dest); + + i = 0; + while (*p != '\0' && i < length) { + next = g_utf8_next_char(p); + count = next - p; + + while (count > 0 && ((i + count) < length)) { + dest[i++] = *p; + p++; + count--; + } + p = next; + } + return BLUETOOTH_ERROR_NONE; +} + +gboolean _bt_utf8_validate(char *name) +{ + BT_DBG("+"); + gunichar2 *u16; + glong items_written = 0; + + if (FALSE == g_utf8_validate(name, -1, NULL)) + return FALSE; + + u16 = g_utf8_to_utf16(name, -1, NULL, &items_written, NULL); + if (u16 == NULL) + return FALSE; + + g_free(u16); + + if (items_written != g_utf8_strlen(name, -1)) + return FALSE; + + BT_DBG("-"); + return TRUE; +} + +int _bt_register_osp_server_in_agent(int type, char *uuid, char *path, int fd) +{ + return BLUETOOTH_ERROR_NOT_SUPPORT; +} + +int _bt_unregister_osp_server_in_agent(int type, char *uuid) +{ + return BLUETOOTH_ERROR_NOT_SUPPORT; +} + +int _bt_set_socket_non_blocking(int socket_fd) +{ + /* Set Nonblocking */ + long arg; + + arg = fcntl(socket_fd, F_GETFL); + + if (arg < 0) + return -errno; + + if (arg & O_NONBLOCK) { + BT_ERR("Already Non-blocking \n"); + } + + arg |= O_NONBLOCK; + + if (fcntl(socket_fd, F_SETFL, arg) < 0) + return -errno; + + return BLUETOOTH_ERROR_NONE; +} + +int _bt_set_non_blocking_tty(int sk) +{ + struct termios ti = {0,}; + int err; + + err = _bt_set_socket_non_blocking(sk); + + if (err < 0) { + BT_ERR("Error in set non blocking!\n"); + return err; + } + + tcflush(sk, TCIOFLUSH); + + /* Switch tty to RAW mode */ + cfmakeraw(&ti); + tcsetattr(sk, TCSANOW, &ti); + + return BLUETOOTH_ERROR_NONE; +} + +char *_bt_get_profile_uuid128(bt_profile_type_t profile_type) +{ + switch (profile_type) { + case BT_PROFILE_CONN_RFCOMM: + return strdup(RFCOMM_UUID_STR); + case BT_PROFILE_CONN_A2DP: + return strdup(A2DP_SINK_UUID); + case BT_PROFILE_CONN_A2DP_SINK: + return strdup(A2DP_SOURCE_UUID); + case BT_PROFILE_CONN_HSP: + return strdup(HFP_HS_UUID); + case BT_PROFILE_CONN_HID: + return strdup(HID_UUID); + case BT_PROFILE_CONN_NAP: + return strdup(NAP_UUID); + case BT_PROFILE_CONN_HFG: + return strdup(HFP_AG_UUID); + case BT_PROFILE_CONN_GATT: + case BT_PROFILE_CONN_ALL: /* NULL UUID will connect to both the audio profiles*/ + default: + return NULL; + }; +} + +char *_bt_convert_error_to_string(int error) +{ + switch (error) { + case BLUETOOTH_ERROR_CANCEL: + return "CANCELLED"; + case BLUETOOTH_ERROR_INVALID_PARAM: + return "INVALID_PARAMETER"; + case BLUETOOTH_ERROR_INVALID_DATA: + return "INVALID DATA"; + case BLUETOOTH_ERROR_MEMORY_ALLOCATION: + case BLUETOOTH_ERROR_OUT_OF_MEMORY: + return "OUT_OF_MEMORY"; + case BLUETOOTH_ERROR_TIMEOUT: + return "TIMEOUT"; + case BLUETOOTH_ERROR_NO_RESOURCES: + return "NO_RESOURCES"; + case BLUETOOTH_ERROR_INTERNAL: + return "INTERNAL"; + case BLUETOOTH_ERROR_NOT_SUPPORT: + return "NOT_SUPPORT"; + case BLUETOOTH_ERROR_DEVICE_NOT_ENABLED: + return "NOT_ENABLED"; + case BLUETOOTH_ERROR_DEVICE_ALREADY_ENABLED: + return "ALREADY_ENABLED"; + case BLUETOOTH_ERROR_DEVICE_BUSY: + return "DEVICE_BUSY"; + case BLUETOOTH_ERROR_ACCESS_DENIED: + return "ACCESS_DENIED"; + case BLUETOOTH_ERROR_MAX_CLIENT: + return "MAX_CLIENT"; + case BLUETOOTH_ERROR_NOT_FOUND: + return "NOT_FOUND"; + case BLUETOOTH_ERROR_SERVICE_SEARCH_ERROR: + return "SERVICE_SEARCH_ERROR"; + case BLUETOOTH_ERROR_PARING_FAILED: + return "PARING_FAILED"; + case BLUETOOTH_ERROR_NOT_PAIRED: + return "NOT_PAIRED"; + case BLUETOOTH_ERROR_SERVICE_NOT_FOUND: + return "SERVICE_NOT_FOUND"; + case BLUETOOTH_ERROR_NOT_CONNECTED: + return "NOT_CONNECTED"; + case BLUETOOTH_ERROR_ALREADY_CONNECT: + return "ALREADY_CONNECT"; + case BLUETOOTH_ERROR_CONNECTION_BUSY: + return "CONNECTION_BUSY"; + case BLUETOOTH_ERROR_CONNECTION_ERROR: + return "CONNECTION_ERROR"; + case BLUETOOTH_ERROR_MAX_CONNECTION: + return "MAX_CONNECTION"; + case BLUETOOTH_ERROR_NOT_IN_OPERATION: + return "NOT_IN_OPERATION"; + case BLUETOOTH_ERROR_CANCEL_BY_USER: + return "CANCEL_BY_USER"; + case BLUETOOTH_ERROR_REGISTRATION_FAILED: + return "REGISTRATION_FAILED"; + case BLUETOOTH_ERROR_IN_PROGRESS: + return "IN_PROGRESS"; + case BLUETOOTH_ERROR_AUTHENTICATION_FAILED: + return "AUTHENTICATION_FAILED"; + case BLUETOOTH_ERROR_HOST_DOWN: + return "HOST_DOWN"; + case BLUETOOTH_ERROR_END_OF_DEVICE_LIST: + return "END_OF_DEVICE_LIST"; + case BLUETOOTH_ERROR_AGENT_ALREADY_EXIST: + return "AGENT_ALREADY_EXIST"; + case BLUETOOTH_ERROR_AGENT_DOES_NOT_EXIST: + return "AGENT_DOES_NOT_EXIST"; + case BLUETOOTH_ERROR_ALREADY_INITIALIZED: + return "ALREADY_INITIALIZED"; + case BLUETOOTH_ERROR_PERMISSION_DEINED: + return "PERMISSION_DEINED"; + case BLUETOOTH_ERROR_ALREADY_DEACTIVATED: + return "ALREADY_DEACTIVATED"; + case BLUETOOTH_ERROR_NOT_INITIALIZED: + return "NOT_INITIALIZED"; + default: + return "UNKNOWN"; + } +} + +char * _bt_convert_disc_reason_to_string(int reason) +{ + switch (reason) { + case 1: + return "Link loss"; + case 2: + return "Connection terminated by local host"; + case 3: + return "Remote user terminated connection"; + case 0: + default: + return "Unknown"; + } +} + +void _bt_logging_connection(gboolean connect, int addr_type) +{ + static int le_conn = 0; + static int le_disc = 0; + static int edr_conn = 0; + static int edr_disc = 0; + + if (connect) { + if (addr_type) + le_conn++; + else + edr_conn++; + } else { + if (addr_type) + le_disc++; + else + edr_disc++; + } + + BT_INFO("[PM] Number of LE conn: %d disc: %d, Number of BR/EDR conn: %d disc: %d", + le_conn, le_disc, edr_conn, edr_disc); +} + +int _bt_eventsystem_set_value(const char *event, const char *key, const char *value) +{ + int ret; + bundle *b = NULL; + + b = bundle_create(); + + bundle_add_str(b, key, value); + + ret = eventsystem_send_system_event(event, b); + + BT_DBG("eventsystem_send_system_event result: %d", ret); + + bundle_free(b); + + return ret; +} + +void _bt_swap_byte_ordering(char *data, int data_len) +{ + char temp; + int i, j; + + ret_if(data == NULL); + /* Swap to opposite endian */ + for (i = 0, j = data_len - 1; i < data_len; i++, j--) { + temp = data[i]; + data[i] = data[j]; + data[j] = temp; + } +} + +int _bt_byte_arr_cmp(const char *data1, const char *data2, int data_len) +{ + int i; + + retv_if(data1 == NULL, -1); + retv_if(data2 == NULL, -1); + for (i = 0; i < data_len; i++) { + if (data1[i] != data2[i]) + return data1[i] - data2[i]; + } + return 0; +} +int _bt_byte_arr_cmp_with_mask(const char *data1, const char *data2, + const char *mask, int data_len) +{ + int i; + char a, b; + + retv_if(data1 == NULL, -1); + retv_if(data2 == NULL, -1); + retv_if(mask == NULL, -1); + for (i = 0; i < data_len; i++) { + a = data1[i] & mask[i]; + b = data2[i] & mask[i]; + if (a != b) + return (int)(a - b); + } + return 0; +} diff --git a/bt-service-emul/bt-service-device.c b/bt-service-emul/bt-service-device.c new file mode 100644 index 0000000..07c3abb --- /dev/null +++ b/bt-service-emul/bt-service-device.c @@ -0,0 +1,204 @@ +/* + * 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 "bluetooth-api.h" +#include "bt-internal-types.h" + +#include "bt-service-common.h" +#include "bt-service-event.h" +#include "bt-service-device.h" +#include "bt-service-util.h" + +int _bt_bond_device(int request_id, + bluetooth_device_address_t *device_address, + unsigned short conn_type, GArray **out_param1) +{ + BT_CHECK_PARAMETER(device_address, return); + + return BLUETOOTH_ERROR_NOT_SUPPORT; +} + +int _bt_cancel_bonding(void) +{ + return BLUETOOTH_ERROR_NOT_SUPPORT; +} + +int _bt_unbond_device(int request_id, + bluetooth_device_address_t *device_address, + GArray **out_param1) +{ + BT_CHECK_PARAMETER(device_address, return); + + return BLUETOOTH_ERROR_NOT_SUPPORT; +} + +int _bt_search_device(int request_id, + bluetooth_device_address_t *device_address) +{ + BT_CHECK_PARAMETER(device_address, return); + + return BLUETOOTH_ERROR_NOT_SUPPORT; +} + +int _bt_cancel_search_device(void) +{ + return BLUETOOTH_ERROR_NOT_SUPPORT; +} + +int _bt_set_alias(bluetooth_device_address_t *device_address, + const char *alias) +{ + BT_CHECK_PARAMETER(device_address, return); + BT_CHECK_PARAMETER(alias, return); + + return BLUETOOTH_ERROR_NOT_SUPPORT; +} + +int _bt_set_authorization(bluetooth_device_address_t *device_address, + gboolean authorize) +{ + BT_CHECK_PARAMETER(device_address, return); + + return BLUETOOTH_ERROR_NOT_SUPPORT; +} + +int _bt_is_device_connected(bluetooth_device_address_t *device_address, + int connection_type, gboolean *is_connected) +{ + retv_if(device_address == NULL, BLUETOOTH_ERROR_INVALID_PARAM); + retv_if(is_connected == NULL, BLUETOOTH_ERROR_INVALID_PARAM); + + *is_connected = FALSE; + + return BLUETOOTH_ERROR_NOT_SUPPORT; +} + +int _bt_get_connected_link(bluetooth_device_address_t *device_address, + bluetooth_connected_link_t *connected) +{ + BT_CHECK_PARAMETER(device_address, return); + + return BLUETOOTH_ERROR_NOT_SUPPORT; +} + +int _bt_connect_le_device(int request_id, + const bluetooth_device_address_t *bd_addr, + gboolean auto_connect) +{ + BT_CHECK_PARAMETER(bd_addr, return); + + return BLUETOOTH_ERROR_NOT_SUPPORT; +} + +int _bt_disconnect_le_device(int request_id, + const bluetooth_device_address_t *bd_addr) +{ + BT_CHECK_PARAMETER(bd_addr, return); + + return BLUETOOTH_ERROR_NOT_SUPPORT; +} + +int _bt_connect_le_ipsp_device(const bluetooth_device_address_t *bd_addr) +{ + BT_CHECK_PARAMETER(bd_addr, return); + + return BLUETOOTH_ERROR_NOT_SUPPORT; +} + +int _bt_disconnect_le_ipsp_device(const bluetooth_device_address_t *bd_addr) +{ + BT_CHECK_PARAMETER(bd_addr, return); + + return BLUETOOTH_ERROR_NOT_SUPPORT; +} + +int _bt_connect_profile(char *address, char *uuid, + void *cb, gpointer func_data) +{ + return BLUETOOTH_ERROR_NOT_SUPPORT; +} + +int _bt_disconnect_profile(char *address, char *uuid, + void *cb, gpointer func_data) +{ + return BLUETOOTH_ERROR_NOT_SUPPORT; +} + +int _bt_enable_rssi(bluetooth_device_address_t *bd_addr, int link_type, + int low_threshold, int in_range_threshold, int high_threshold) +{ + BT_CHECK_PARAMETER(bd_addr, return); + + return BLUETOOTH_ERROR_NOT_SUPPORT; +} + +int _bt_get_rssi_strength(bluetooth_device_address_t *bd_addr, + int link_type) +{ + BT_CHECK_PARAMETER(bd_addr, return); + + return BLUETOOTH_ERROR_NOT_SUPPORT; +} + +int _bt_le_conn_update(unsigned char *device_address, + guint16 interval_min, guint16 interval_max, + guint16 latency, guint16 time_out) +{ + BT_CHECK_PARAMETER(device_address, return); + + return BLUETOOTH_ERROR_NOT_SUPPORT; +} + +int _bt_set_pin_code(bluetooth_device_address_t *device_address, + bluetooth_device_pin_code_t *pin_code) +{ + BT_CHECK_PARAMETER(device_address, return); + BT_CHECK_PARAMETER(pin_code, return); + + return BLUETOOTH_ERROR_NOT_SUPPORT; +} + +int _bt_unset_pin_code(bluetooth_device_address_t *device_address) +{ + BT_CHECK_PARAMETER(device_address, return); + + return BLUETOOTH_ERROR_NOT_SUPPORT; +} + +int _bt_get_device_pin_code(const char *address, char *pin_code) +{ + BT_CHECK_PARAMETER(address, return); + BT_CHECK_PARAMETER(pin_code, return); + + return BLUETOOTH_ERROR_NOT_SUPPORT; +} + +int _bt_get_le_connection_parameter(bluetooth_le_connection_mode_t mode, + bluetooth_le_connection_param_t *param) +{ + return BLUETOOTH_ERROR_NOT_SUPPORT; +} + +int _bt_passkey_reply(const char *passkey, gboolean authentication_reply) +{ + return BLUETOOTH_ERROR_NOT_SUPPORT; +} + +int _bt_passkey_confirmation_reply(gboolean confirmation_reply) +{ + return BLUETOOTH_ERROR_NOT_SUPPORT; +} diff --git a/bt-service-emul/bt-service-dpm.c b/bt-service-emul/bt-service-dpm.c new file mode 100644 index 0000000..e5540f1 --- /dev/null +++ b/bt-service-emul/bt-service-dpm.c @@ -0,0 +1,685 @@ +/* + * 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. + * + */ +#ifdef TIZEN_DPM_ENABLE + +#include +#include +#include +#include +#include +#include + +#include "bluetooth-api.h" +#include "bt-internal-types.h" + +#include "bt-service-common.h" +#include "bt-service-adapter.h" +#include "bt-service-dpm.h" + +static dpm_policy_t policy_table[DPM_POLICY_END] = { + [DPM_POLICY_ALLOW_BLUETOOTH] = { {DPM_BT_ERROR} }, + [DPM_POLICY_BLUETOOTH_DEVICE_RESTRICTION] = { {DPM_STATUS_ERROR} }, + [DPM_POLICY_BLUETOOTH_UUID_RESTRICTION] = { {DPM_STATUS_ERROR} }, + [DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST] = { {NULL} }, + [DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST] = { {NULL} }, + [DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST] = { {NULL} }, + [DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST] = { {NULL} }, + [DPM_POLICY_ALLOW_BLUETOOTH_OUTGOING_CALL] = { {DPM_STATUS_ERROR} }, + [DPM_POLICY_BLUETOOTH_PAIRING_STATE] = { {DPM_STATUS_ERROR} }, + [DPM_POLICY_BLUETOOTH_DESKTOP_CONNECTIVITY_STATE] = { {DPM_STATUS_ERROR} }, + [DPM_POLICY_BLUETOOTH_DISCOVERABLE_STATE] = { {DPM_STATUS_ERROR} }, + [DPM_POLICY_BLUETOOTH_LIMITED_DISCOVERABLE_STATE] = { {DPM_STATUS_ERROR} }, + [DPM_POLICY_BLUETOOTH_DATA_TRANSFER_STATE] = { {DPM_STATUS_ERROR} }, +}; + + +/** + * @brief DPM profile state + * @see + */ +static dpm_profile_state_t dpm_profile_state[DPM_PROFILE_NONE] = { + [DPM_POLICY_BLUETOOTH_A2DP_PROFILE_STATE] = {DPM_STATUS_ERROR}, + [DPM_POLICY_BLUETOOTH_AVRCP_PROFILE_STATE] = {DPM_STATUS_ERROR}, + [DPM_POLICY_BLUETOOTH_BPP_PROFILE_STATE] = {DPM_STATUS_ERROR}, + [DPM_POLICY_BLUETOOTH_DUN_PROFILE_STATE] = {DPM_STATUS_ERROR}, + [DPM_POLICY_BLUETOOTH_FTP_PROFILE_STATE] = {DPM_STATUS_ERROR}, + [DPM_POLICY_BLUETOOTH_HFP_PROFILE_STATE] = {DPM_STATUS_ERROR}, + [DPM_POLICY_BLUETOOTH_HSP_PROFILE_STATE] = {DPM_STATUS_ERROR}, + [DPM_POLICY_BLUETOOTH_PBAP_PROFILE_STATE] = {DPM_STATUS_ERROR}, + [DPM_POLICY_BLUETOOTH_SAP_PROFILE_STATE] = {DPM_STATUS_ERROR}, + [DPM_POLICY_BLUETOOTH_SPP_PROFILE_STATE] = {DPM_STATUS_ERROR}, +}; + +dpm_result_t _bt_dpm_set_allow_bluetooth_mode(dpm_bt_allow_t value) +{ + BT_INFO("_bt_dpm_set_allow_bluetooth_mode"); + +#if 0 + if (value == DPM_BT_ALLOWED && value == DPM_BT_HANDSFREE_ONLY) { + /* Update Bluetooth DPM Status to notify other modules */ + if (vconf_set_int(VCONFKEY_BT_DPM_STATUS, value) != 0) + BT_ERR("Set vconf failed\n"); + return DPM_RESULT_FAIL; + } else { + /* Update Bluetooth DPM Status to notify other modules */ + if (vconf_set_int(VCONFKEY_BT_DPM_STATUS, VCONFKEY_BT_DPM_STATUS_RESTRICTED) != 0) + BT_ERR("Set vconf failed\n"); + return DPM_RESULT_FAIL; + } +#endif + policy_table[DPM_POLICY_ALLOW_BLUETOOTH].value = value; + + return DPM_RESULT_SUCCESS; +} + +dpm_bt_allow_t _bt_dpm_get_allow_bluetooth_mode(void) +{ + BT_INFO("_bt_dpm_get_allow_bluetooth_mode"); + + return policy_table[DPM_POLICY_ALLOW_BLUETOOTH].value; +} + +dpm_result_t _bt_dpm_activate_bluetooth_device_restriction(dpm_status_t value) +{ + BT_INFO("_bt_dpm_activate_bluetooth_device_restriction"); + if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED) + return DPM_RESULT_ACCESS_DENIED; + + policy_table[DPM_POLICY_BLUETOOTH_DEVICE_RESTRICTION].value = value; + + return DPM_RESULT_SUCCESS; +} + +dpm_status_t _bt_dpm_is_bluetooth_device_restriction_active(void) +{ + BT_INFO("_bt_dpm_is_bluetooth_device_restriction_active"); + + if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED) + return DPM_RESTRICTED; + + return policy_table[DPM_POLICY_BLUETOOTH_DEVICE_RESTRICTION].value; +} + +dpm_result_t _bt_dpm_activate_bluetoooth_uuid_restriction(dpm_status_t value) +{ + BT_INFO("_bt_dpm_activate_bluetooth_device_restriction"); + if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED) + return DPM_RESULT_ACCESS_DENIED; + + policy_table[DPM_POLICY_BLUETOOTH_UUID_RESTRICTION].value = value; + + return DPM_RESULT_SUCCESS; +} + +dpm_status_t _bt_dpm_is_bluetooth_uuid_restriction_active(void) +{ + BT_INFO("_bt_dpm_is_bluetooth_uuid_restriction_active"); + + if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED) + return DPM_RESTRICTED; + + return policy_table[DPM_POLICY_BLUETOOTH_UUID_RESTRICTION].value; +} + +dpm_result_t _bt_dpm_add_bluetooth_devices_to_blacklist(bluetooth_device_address_t *bd_addr) +{ + char device_address[BT_ADDRESS_STRING_SIZE] = { 0 }; + char *dev_addr = NULL; + + BT_INFO("_bt_dpm_add_bluetooth_devices_to_blacklist"); + + if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED) + return DPM_RESULT_ACCESS_DENIED; + + BT_CHECK_PARAMETER(bd_addr, return); + + _bt_convert_addr_type_to_string(device_address, + (unsigned char *)bd_addr->addr); + + dev_addr = g_strdup(device_address); + if (!dev_addr) + return DPM_RESULT_FAIL; + policy_table[DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST].list = g_slist_append(policy_table[DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST].list, dev_addr); + + return DPM_RESULT_SUCCESS; +} + +dpm_result_t _bt_dpm_get_bluetooth_devices_from_blacklist(GArray **out_param1) +{ + dpm_result_t ret = DPM_RESULT_FAIL; + bt_dpm_device_list_t device_list; + GSList *list = policy_table[DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST].list; + int i = 0; + + BT_INFO("_bt_dpm_get_bluetooth_devices_from_blacklist"); + + if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED) + return ret; + + if (list) { + ret = DPM_RESULT_SUCCESS; + for (; list; list = list->next, i++) { + memset(device_list.addresses[i].addr, 0, BT_ADDRESS_STRING_SIZE); + _bt_convert_addr_string_to_type(device_list.addresses[i].addr, list->data); + } + device_list.count = g_slist_length(policy_table[DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST].list); + g_array_append_vals(*out_param1, &device_list, sizeof(bt_dpm_device_list_t)); + } else { + ret = DPM_RESULT_SUCCESS; + device_list.count = 0; + g_array_append_vals(*out_param1, &device_list, sizeof(bt_dpm_device_list_t)); + } + return ret; +} + +dpm_result_t _bt_dpm_add_bluetooth_devices_to_whitelist(bluetooth_device_address_t *bd_addr) +{ + char device_address[BT_ADDRESS_STRING_SIZE] = { 0 }; + char *dev_addr = NULL; + + BT_INFO("_bt_dpm_add_bluetooth_devices_to_whitelist"); + + if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED) + return DPM_RESULT_ACCESS_DENIED; + + BT_CHECK_PARAMETER(bd_addr, return); + + _bt_convert_addr_type_to_string(device_address, + (unsigned char *)bd_addr->addr); + + dev_addr = g_strdup(device_address); + if (!dev_addr) + return DPM_RESULT_FAIL; + policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list = g_slist_append(policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list, dev_addr); + return DPM_RESULT_SUCCESS; +} + +dpm_result_t _bt_dpm_get_bluetooth_devices_from_whitelist(GArray **out_param1) +{ + dpm_result_t ret = DPM_RESULT_FAIL; + bt_dpm_device_list_t device_list; + GSList *list = policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list; + int i = 0; + + BT_INFO("_bt_dpm_get_bluetooth_devices_from_whitelist"); + + if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED) + return ret; + + if (list) { + ret = DPM_RESULT_SUCCESS; + for (; list; list = list->next, i++) { + memset(device_list.addresses[i].addr, 0, BT_ADDRESS_STRING_SIZE); + _bt_convert_addr_string_to_type(device_list.addresses[i].addr, list->data); + + } + device_list.count = g_slist_length(policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list); + g_array_append_vals(*out_param1, &device_list, sizeof(bt_dpm_device_list_t)); + } else { + ret = DPM_RESULT_SUCCESS; + device_list.count = 0; + g_array_append_vals(*out_param1, &device_list, sizeof(bt_dpm_device_list_t)); + } + return ret; +} + +dpm_result_t _bt_dpm_add_bluetooth_uuids_to_blacklist(const char *uuid) +{ + char *l_uuid; + BT_INFO("_bt_dpm_add_bluetooth_uuids_to_blacklist"); + + if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED) + return DPM_RESULT_ACCESS_DENIED; + + l_uuid = g_strdup(uuid); + if (!l_uuid) + return DPM_RESULT_FAIL; + policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list = g_slist_append(policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list, l_uuid); + return DPM_RESULT_SUCCESS; +} + +dpm_result_t _bt_dpm_get_bluetooth_uuids_from_blacklist(GArray **out_param1) +{ + dpm_result_t ret = DPM_RESULT_FAIL; + bt_dpm_uuids_list_t uuids_list = {0, { {0}, } }; + GSList *list = policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list; + int i = 0; + + BT_INFO("_bt_dpm_get_bluetooth_uuids_from_blacklist"); + + if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED) + return ret; + + if (list) { + ret = DPM_RESULT_SUCCESS; + uuids_list.count = g_slist_length(policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list); + for (; list; list = list->next, i++) { + memset(uuids_list.uuids[i], 0, BLUETOOTH_UUID_STRING_MAX); + g_strlcpy(uuids_list.uuids[i], list->data, + BLUETOOTH_UUID_STRING_MAX); + } + g_array_append_vals(*out_param1, &uuids_list, sizeof(bt_dpm_uuids_list_t)); + } else { + ret = DPM_RESULT_SUCCESS; + uuids_list.count = 0; + g_array_append_vals(*out_param1, &uuids_list, sizeof(bt_dpm_uuids_list_t)); + } + + return ret; +} + +dpm_result_t _bt_dpm_add_bluetooth_uuids_to_whitelist(const char *uuid) +{ + char *l_uuid; + BT_INFO("_bt_dpm_add_bluetooth_uuids_to_whitelist"); + + if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED) + return DPM_RESULT_ACCESS_DENIED; + + l_uuid = g_strdup(uuid); + if (!l_uuid) + return DPM_RESULT_FAIL; + policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list = g_slist_append(policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list, l_uuid); + return DPM_RESULT_SUCCESS; +} + + +dpm_result_t _bt_dpm_get_bluetooth_uuids_from_whitelist(GArray **out_param1) +{ + dpm_result_t ret = DPM_RESULT_FAIL; + bt_dpm_uuids_list_t uuids_list = {0, { {0}, } }; + GSList *list = policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list; + int i = 0; + + BT_INFO("_bt_dpm_get_bluetooth_uuids_from_whitelist"); + + if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED) + return ret; + + if (list) { + ret = DPM_RESULT_SUCCESS; + uuids_list.count = g_slist_length(policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list); + for (; list; list = list->next, i++) { + memset(uuids_list.uuids[i], 0, BLUETOOTH_UUID_STRING_MAX); + g_strlcpy(uuids_list.uuids[i], list->data, + BLUETOOTH_UUID_STRING_MAX); + } + g_array_append_vals(*out_param1, &uuids_list, sizeof(bt_dpm_uuids_list_t)); + } else { + ret = DPM_RESULT_SUCCESS; + uuids_list.count = 0; + g_array_append_vals(*out_param1, &uuids_list, sizeof(bt_dpm_uuids_list_t)); + } + + return ret; + +} + +dpm_result_t _bt_dpm_set_allow_bluetooth_outgoing_call(dpm_status_t value) +{ + BT_INFO("_bt_dpm_activate_bluetooth_device_restriction"); + if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED) + return DPM_RESULT_ACCESS_DENIED; + + policy_table[DPM_POLICY_ALLOW_BLUETOOTH_OUTGOING_CALL].value = value; + + return DPM_RESULT_SUCCESS; +} + +dpm_status_t _bt_dpm_get_allow_bluetooth_outgoing_call(void) +{ + BT_INFO("_bt_dpm_get_allow_bluetooth_outgoing_call"); + + if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED) + return DPM_RESTRICTED; + + return policy_table[DPM_POLICY_ALLOW_BLUETOOTH_OUTGOING_CALL].value; +} + +dpm_result_t _bt_dpm_clear_bluetooth_devices_from_blacklist(void) +{ + GSList *l = NULL; + BT_INFO("_bt_dpm_clear_bluetooth_devices_from_blacklist"); + + if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED) + return DPM_RESULT_ACCESS_DENIED; + + for (l = policy_table[DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST].list; l; l = g_slist_next(l)) { + char *address = l->data; + if (address) { + policy_table[DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST].list = g_slist_remove(policy_table[DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST].list, address); + g_free(address); + } + } + g_slist_free(policy_table[DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST].list); + policy_table[DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST].list = NULL; + return DPM_RESULT_SUCCESS; +} + +dpm_result_t _bt_dpm_clear_bluetooth_devices_from_whitelist(void) +{ + GSList *l = NULL; + BT_INFO("_bt_dpm_clear_bluetooth_devices_from_blacklist"); + + if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED) + return DPM_RESULT_ACCESS_DENIED; + + for (l = policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list; l; l = g_slist_next(l)) { + char *address = l->data; + if (address) { + policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list = g_slist_remove(policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list, address); + g_free(address); + } + } + g_slist_free(policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list); + policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list = NULL; + return DPM_RESULT_SUCCESS; +} + +dpm_result_t _bt_dpm_clear_bluetooth_uuids_from_blacklist(void) +{ + GSList *l = NULL; + BT_INFO("_bt_dpm_clear_bluetooth_devices_from_blacklist"); + + if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED) + return DPM_RESULT_ACCESS_DENIED; + + for (l = policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list; l; l = g_slist_next(l)) { + char *l_uuid = l->data; + if (l_uuid) + policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list = g_slist_remove(policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list, l_uuid); + g_free(l_uuid); + } + g_slist_free(policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list); + policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list = NULL; + return DPM_RESULT_SUCCESS; +} + +dpm_result_t _bt_dpm_clear_bluetooth_uuids_from_whitelist(void) +{ + GSList *l = NULL; + BT_INFO("_bt_dpm_clear_bluetooth_uuids_from_whitelist"); + + if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED) + return DPM_RESULT_ACCESS_DENIED; + + for (l = policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list; l; l = g_slist_next(l)) { + char *l_uuid = l->data; + if (l_uuid) { + policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list = g_slist_remove(policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list, l_uuid); + g_free(l_uuid); + } + } + g_slist_free(policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list); + policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list = NULL; + return DPM_RESULT_SUCCESS; +} + +dpm_status_t _bt_dpm_set_bluetooth_pairing_state(dpm_status_t value) +{ + BT_INFO("_bt_dpm_set_bluetooth_pairing_state"); + + if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED) + return DPM_RESTRICTED; + + policy_table[DPM_POLICY_BLUETOOTH_PAIRING_STATE].value = value; + + return DPM_RESULT_SUCCESS; +} + +dpm_status_t _bt_dpm_get_bluetooth_pairing_state(void) +{ + BT_INFO("_bt_dpm_get_bluetooth_pairing_state"); + + if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED) + return DPM_RESTRICTED; + + return policy_table[DPM_POLICY_BLUETOOTH_PAIRING_STATE].value; +} + +dpm_status_t _bt_dpm_set_bluetooth_profile_state(dpm_profile_t profile, dpm_status_t value) +{ + BT_INFO("_bt_dpm_set_bluetooth_profile_state"); + + if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED) + return DPM_RESTRICTED; + + dpm_profile_state[profile].value = value; + + return DPM_RESULT_SUCCESS; +} + +dpm_status_t _bt_dpm_get_bluetooth_profile_state(dpm_profile_t profile) +{ + BT_INFO("_bt_dpm_get_bluetooth_profile_state"); + + if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED) + return DPM_RESTRICTED; + + return dpm_profile_state[profile].value; +} + +dpm_status_t _bt_dpm_set_bluetooth_desktop_connectivity_state(dpm_status_t value) +{ + BT_INFO("_bt_dpm_set_bluetooth_desktop_connectivity_state"); + + if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED) + return DPM_RESTRICTED; + + policy_table[DPM_POLICY_BLUETOOTH_DESKTOP_CONNECTIVITY_STATE].value = value; + + return DPM_RESULT_SUCCESS; +} + +dpm_status_t _bt_dpm_get_bluetooth_desktop_connectivity_state(void) +{ + BT_INFO("_bt_dpm_get_bluetooth_desktop_connectivity_state"); + + if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED) + return DPM_RESTRICTED; + + return policy_table[DPM_POLICY_BLUETOOTH_DESKTOP_CONNECTIVITY_STATE].value; +} + +dpm_status_t _bt_dpm_set_bluetooth_discoverable_state(dpm_status_t value) +{ + BT_INFO("_bt_dpm_set_bluetooth_discoverable_state"); + + if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED) + return DPM_RESTRICTED; + + if (value == DPM_RESTRICTED) { + /* Since Discoverable mode is restricted, stop the ongoing discoverable mode */ + _bt_set_discoverable_mode(BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE, 0); + } + + policy_table[DPM_POLICY_BLUETOOTH_DISCOVERABLE_STATE].value = value; + + return DPM_RESULT_SUCCESS; +} + +dpm_status_t _bt_dpm_get_bluetooth_discoverable_state(void) +{ + BT_INFO("_bt_dpm_get_bluetooth_discoverable_state"); + + if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED) + return DPM_RESTRICTED; + + return policy_table[DPM_POLICY_BLUETOOTH_DISCOVERABLE_STATE].value; +} + +dpm_status_t _bt_dpm_set_bluetooth_limited_discoverable_state(dpm_status_t value) +{ + BT_INFO("_bt_dpm_set_bluetooth_limited_discoverable_state"); + + if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED) + return DPM_RESTRICTED; + + if (value == DPM_RESTRICTED) { + /* Since Discoverable mode is restricted, stop the ongoing discoverable mode */ + _bt_set_discoverable_mode(BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE, 0); + } + + policy_table[DPM_POLICY_BLUETOOTH_LIMITED_DISCOVERABLE_STATE].value = value; + + return DPM_RESULT_SUCCESS; +} + +dpm_status_t _bt_dpm_get_bluetooth_limited_discoverable_state(void) +{ + BT_INFO("_bt_dpm_get_bluetooth_limited_discoverable_state"); + + if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED) + return DPM_RESTRICTED; + + return policy_table[DPM_POLICY_BLUETOOTH_LIMITED_DISCOVERABLE_STATE].value; +} + +dpm_status_t _bt_dpm_set_bluetooth_data_transfer_state(dpm_status_t value) +{ + BT_INFO("_bt_dpm_set_bluetooth_data_transfer_state"); + + if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED) + return DPM_RESTRICTED; + + return policy_table[DPM_POLICY_BLUETOOTH_DATA_TRANSFER_STATE].value = value; +} + +dpm_status_t _bt_dpm_get_allow_bluetooth_data_transfer_state(void) +{ + BT_INFO("_bt_dpm_get_allow_bluetooth_data_transfer_state"); + + if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED) + return DPM_RESTRICTED; + + return policy_table[DPM_POLICY_BLUETOOTH_DATA_TRANSFER_STATE].value; +} + +dpm_result_t _bt_dpm_remove_bluetooth_devices_from_whitelist(bluetooth_device_address_t *device_address) +{ + GSList *l = NULL; + char bd_addr[BT_ADDRESS_STRING_SIZE] = { 0 }; + BT_INFO("_bt_dpm_remove_bluetooth_devices_from_whitelist"); + + if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED) + return DPM_RESULT_ACCESS_DENIED; + + _bt_convert_addr_type_to_string(bd_addr, + (unsigned char *)device_address->addr); + + if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED) + return DPM_RESULT_ACCESS_DENIED; + + for (l = policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list; l; l = g_slist_next(l)) { + char *l_device = l->data; + if (l_device && g_strcmp0(l_device, bd_addr)) { + policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list = g_slist_remove(policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list, l_device); + g_free(l_device); + } + } + return DPM_RESULT_SUCCESS; +} + +dpm_result_t _bt_dpm_remove_bluetooth_devices_from_blacklist(bluetooth_device_address_t *device_address) +{ + GSList *l = NULL; + char bd_addr[BT_ADDRESS_STRING_SIZE] = { 0 }; + + BT_INFO("_bt_dpm_remove_bluetooth_devices_from_blacklist"); + + if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED) + return DPM_RESULT_ACCESS_DENIED; + + _bt_convert_addr_type_to_string(bd_addr, + (unsigned char *)device_address->addr); + + for (l = policy_table[DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST].list; l; l = g_slist_next(l)) { + char *l_device = l->data; + if (l_device && g_strcmp0(l_device, bd_addr)) { + policy_table[DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST].list = g_slist_remove(policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list, l_device); + g_free(l_device); + } + } + + return DPM_RESULT_SUCCESS; +} + +dpm_result_t _bt_dpm_remove_bluetooth_uuids_from_whitelist(const char *uuids) +{ + GSList *l = NULL; + BT_INFO("_bt_dpm_remove_bluetooth_uuids_from_whitelist"); + + if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED) + return DPM_RESULT_ACCESS_DENIED; + for (l = policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list; l; l = g_slist_next(l)) { + char *l_uuid = l->data; + if (l_uuid && g_strcmp0(l_uuid, uuids)) { + policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list = g_slist_remove(policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list, l_uuid); + g_free(l_uuid); + } + } + return DPM_RESULT_SUCCESS; +} + +dpm_result_t _bt_dpm_remove_bluetooth_uuids_from_blacklist(const char *uuids) +{ + GSList *l = NULL; + BT_INFO("_bt_dpm_remove_bluetooth_uuids_from_blacklist"); + + if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED) + return DPM_RESULT_ACCESS_DENIED; + + for (l = policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list; l; l = g_slist_next(l)) { + char *l_uuid = l->data; + if (l_uuid && g_strcmp0(l_uuid, uuids)) { + policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list = g_slist_remove(policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list, l_uuid); + g_free(l_uuid); + } + } + return DPM_RESULT_SUCCESS; +} + +dpm_result_t _bt_dpm_clear_bluetooth_uuids_from_list(void) +{ + BT_INFO("_bt_dpm_clear_bluetooth_uuids_from_list"); + dpm_result_t err = DPM_RESULT_FAIL; + + if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED) + return DPM_RESULT_ACCESS_DENIED; + + err = _bt_dpm_clear_bluetooth_uuids_from_blacklist(); + if (!err) + err = _bt_dpm_clear_bluetooth_uuids_from_blacklist(); + + return err; +} + +dpm_result_t _bt_dpm_clear_bluetooth_devices_from_list(void) +{ + BT_INFO("_bt_dpm_clear_bluetooth_devices_from_list"); + dpm_result_t err = DPM_RESULT_FAIL; + + if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED) + return DPM_RESULT_ACCESS_DENIED; + + err = _bt_dpm_clear_bluetooth_devices_from_blacklist(); + if (!err) + err = _bt_dpm_clear_bluetooth_devices_from_blacklist(); + + return err; +} +#endif /* #ifdef TIZEN_DPM_ENABLE */ diff --git a/bt-service-emul/bt-service-event-generator.c b/bt-service-emul/bt-service-event-generator.c new file mode 100644 index 0000000..422f97f --- /dev/null +++ b/bt-service-emul/bt-service-event-generator.c @@ -0,0 +1,25 @@ +/* + * 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 "bluetooth-api.h" +#include "bt-internal-types.h" + +#include "bt-service-common.h" +#include "bt-service-event.h" + diff --git a/bt-service-emul/bt-service-event-sender.c b/bt-service-emul/bt-service-event-sender.c new file mode 100644 index 0000000..6cb2e96 --- /dev/null +++ b/bt-service-emul/bt-service-event-sender.c @@ -0,0 +1,500 @@ +/* + * 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 "bluetooth-api.h" +#include "bt-internal-types.h" + +#include "bt-service-common.h" +#include "bt-service-event.h" + +static GDBusConnection *event_conn; + +int _bt_send_event(int event_type, int event, GVariant *param) +{ + BT_DBG("+"); + char *path; + char *signal; + GDBusMessage *msg1 = NULL; + + retv_if(event_conn == NULL, BLUETOOTH_ERROR_INTERNAL); + + BT_DBG("event_type [%d], event [%d]", event_type, event); + + switch (event_type) { + case BT_ADAPTER_EVENT: + path = BT_ADAPTER_PATH; + break; + case BT_LE_ADAPTER_EVENT: + path = BT_LE_ADAPTER_PATH; + break; + case BT_DEVICE_EVENT: + path = BT_DEVICE_PATH; + break; + case BT_HID_EVENT: + path = BT_HID_PATH; + break; + case BT_HEADSET_EVENT: + path = BT_HEADSET_PATH; + break; + case BT_AVRCP_EVENT: + path = BT_AVRCP_PATH; + break; + case BT_AVRCP_CONTROL_EVENT: + path = BT_AVRCP_CONTROL_PATH; + break; + case BT_NETWORK_EVENT: + path = BT_NETWORK_PATH; + break; + case BT_OPP_CLIENT_EVENT: + path = BT_OPP_CLIENT_PATH; + break; + case BT_OPP_SERVER_EVENT: + path = BT_OPP_SERVER_PATH; + break; + case BT_PBAP_CLIENT_EVENT: + path = BT_PBAP_CLIENT_PATH; + break; + case BT_RFCOMM_CLIENT_EVENT: + path = BT_RFCOMM_CLIENT_PATH; + break; + case BT_RFCOMM_SERVER_EVENT: + path = BT_RFCOMM_SERVER_PATH; + break; + case BT_A2DP_SOURCE_EVENT: + path = BT_A2DP_SOURCE_PATH; + break; + default: + BT_ERR("Unknown event"); + return BLUETOOTH_ERROR_INTERNAL; + } + + switch (event) { + case BLUETOOTH_EVENT_ENABLED: + signal = BT_ENABLED; + break; + case BLUETOOTH_EVENT_DISABLED: + signal = BT_DISABLED; + break; + case BLUETOOTH_EVENT_LE_ENABLED: + signal = BT_LE_ENABLED; + break; + case BLUETOOTH_EVENT_LE_DISABLED: + signal = BT_LE_DISABLED; + break; + case BLUETOOTH_EVENT_LOCAL_NAME_CHANGED: + signal = BT_ADAPTER_NAME_CHANGED; + break; + case BLUETOOTH_EVENT_DISCOVERABLE_MODE_CHANGED: + signal = BT_DISCOVERABLE_MODE_CHANGED; + break; + case BLUETOOTH_EVENT_DISCOVERABLE_TIMEOUT_CHANGED: + signal = BT_DISCOVERABLE_TIMEOUT_CHANGED; + break; + case BLUETOOTH_EVENT_CONNECTABLE_CHANGED: + signal = BT_CONNECTABLE_CHANGED; + break; + case BLUETOOTH_EVENT_DISCOVERY_STARTED: + signal = BT_DISCOVERY_STARTED; + break; + case BLUETOOTH_EVENT_REMOTE_DEVICE_FOUND: + signal = BT_DEVICE_FOUND; + break; + case BLUETOOTH_EVENT_DISCOVERY_FINISHED: + signal = BT_DISCOVERY_FINISHED; + break; + case BLUETOOTH_EVENT_LE_DISCOVERY_STARTED: + signal = BT_LE_DISCOVERY_STARTED; + break; + case BLUETOOTH_EVENT_REMOTE_LE_DEVICE_FOUND: + signal = BT_LE_DEVICE_FOUND; + break; + case BLUETOOTH_EVENT_LE_DISCOVERY_FINISHED: + signal = BT_LE_DISCOVERY_FINISHED; + break; + case BLUETOOTH_EVENT_ADVERTISING_STARTED: + signal = BT_ADVERTISING_STARTED; + break; + case BLUETOOTH_EVENT_ADVERTISING_STOPPED: + signal = BT_ADVERTISING_STOPPED; + break; + case BLUETOOTH_EVENT_ADVERTISING_MANUFACTURER_DATA_CHANGED: + signal = BT_ADVERTISING_MANUFACTURER_DATA_CHANGED; + break; + case BLUETOOTH_EVENT_SCAN_RESPONSE_MANUFACTURER_DATA_CHANGED: + signal = BT_SCAN_RESPONSE_MANUFACTURER_DATA_CHANGED; + break; + case BLUETOOTH_EVENT_MANUFACTURER_DATA_CHANGED: + signal = BT_MANUFACTURER_DATA_CHANGED; + break; + case BLUETOOTH_EVENT_BONDING_FINISHED: + signal = BT_BOND_CREATED; + break; + case BLUETOOTH_EVENT_BONDED_DEVICE_REMOVED: + signal = BT_BOND_DESTROYED; + break; + case BLUETOOTH_EVENT_DEVICE_AUTHORIZED: + signal = BT_DEVICE_AUTHORIZED; + break; + case BLUETOOTH_EVENT_DEVICE_UNAUTHORIZED: + signal = BT_DEVICE_UNAUTHORIZED; + break; + case BLUETOOTH_EVENT_RSSI_ENABLED: + signal = BT_RSSI_MONITORING_ENABLED; + break; + case BLUETOOTH_EVENT_RSSI_ALERT: + signal = BT_RSSI_ALERT; + break; + case BLUETOOTH_EVENT_RAW_RSSI: + signal = BT_RAW_RSSI_EVENT; + break; + case BLUETOOTH_EVENT_KEYBOARD_PASSKEY_DISPLAY: + signal = BT_KBD_PASSKEY_DISPLAY_REQ_RECEIVED; + break; + case BLUETOOTH_EVENT_PIN_REQUEST: + signal = BT_PIN_REQ_RECEIVED; + break; + case BLUETOOTH_EVENT_PASSKEY_REQUEST: + signal = BT_PASSKEY_REQ_RECEIVED; + break; + case BLUETOOTH_EVENT_PASSKEY_CONFIRM_REQUEST: + signal = BT_PASSKEY_CFM_REQ_RECEIVED; + break; + case BLUETOOTH_EVENT_SERVICE_SEARCHED: + signal = BT_SERVICE_SEARCHED; + break; + case BLUETOOTH_HID_CONNECTED: + signal = BT_INPUT_CONNECTED; + BT_INFO_C("Connected [HID]"); + break; + case BLUETOOTH_HID_DISCONNECTED: + signal = BT_INPUT_DISCONNECTED; + BT_INFO_C("Disconnected [HID]"); + break; + case BLUETOOTH_PBAP_CONNECTED: + signal = BT_PBAP_CONNECTED; + BT_INFO_C("Connected [PBAP Client]"); + break; + case BLUETOOTH_PBAP_DISCONNECTED: + signal = BT_PBAP_DISCONNECTED; + BT_INFO_C("Disconnected [PBAP Client]"); + break; + case BLUETOOTH_PBAP_PHONEBOOK_SIZE: + signal = BT_PBAP_PHONEBOOK_SIZE; + break; + case BLUETOOTH_PBAP_PHONEBOOK_PULL: + signal = BT_PBAP_PHONEBOOK_PULL; + break; + case BLUETOOTH_PBAP_VCARD_LIST: + signal = BT_PBAP_VCARD_LIST; + break; + case BLUETOOTH_PBAP_VCARD_PULL: + signal = BT_PBAP_VCARD_PULL; + break; + case BLUETOOTH_PBAP_PHONEBOOK_SEARCH: + signal = BT_PBAP_SEARCH_PHONEBOOK; + break; + case BLUETOOTH_EVENT_AG_CONNECTED: + signal = BT_HEADSET_CONNECTED; + BT_INFO_C("Connected [HSP/HFP]"); + break; + case BLUETOOTH_EVENT_AG_DISCONNECTED: + signal = BT_HEADSET_DISCONNECTED; + BT_INFO_C("Disconnected [HSP/HFP]"); + break; + case BLUETOOTH_EVENT_AV_CONNECTED: + signal = BT_STEREO_HEADSET_CONNECTED; + BT_INFO_C("Connected [A2DP]"); + break; + case BLUETOOTH_EVENT_AV_DISCONNECTED: + signal = BT_STEREO_HEADSET_DISCONNECTED; + BT_INFO_C("Disconnected [A2DP]"); + break; + case BLUETOOTH_EVENT_AG_AUDIO_CONNECTED: + signal = BT_SCO_CONNECTED; + BT_INFO_C("Connected [SCO]"); + break; + case BLUETOOTH_EVENT_AG_AUDIO_DISCONNECTED: + signal = BT_SCO_DISCONNECTED; + BT_INFO_C("Disonnected [SCO]"); + break; + case BLUETOOTH_EVENT_AG_SPEAKER_GAIN: + signal = BT_SPEAKER_GAIN; + break; + case BLUETOOTH_EVENT_AG_MIC_GAIN: + signal = BT_MICROPHONE_GAIN; + break; + case BLUETOOTH_EVENT_NETWORK_CONNECTED: + signal = BT_NETWORK_CONNECTED; + BT_INFO_C("Connected [Newwork]"); + break; + case BLUETOOTH_EVENT_NETWORK_DISCONNECTED: + signal = BT_NETWORK_DISCONNECTED; + BT_INFO_C("Disconnected [Newwork]"); + break; + case BLUETOOTH_EVENT_NETWORK_SERVER_CONNECTED: + signal = BT_NETWORK_SERVER_CONNECTED; + BT_INFO_C("Connected [Network Server]"); + break; + case BLUETOOTH_EVENT_NETWORK_SERVER_DISCONNECTED: + signal = BT_NETWORK_SERVER_DISCONNECTED; + BT_INFO_C("Disconnected [Network Server]"); + break; + case BLUETOOTH_EVENT_OPC_CONNECTED: + signal = BT_OPP_CONNECTED; + BT_INFO_C("Connected [OPP]"); + break; + case BLUETOOTH_EVENT_OPC_DISCONNECTED: + signal = BT_OPP_DISCONNECTED; + BT_INFO_C("Disconnected [OPP]"); + break; + case BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_CONNECTED: + signal = BT_TRANSFER_CONNECTED; + break; + case BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_DISCONNECTED: + signal = BT_TRANSFER_DISCONNECTED; + break; + case BLUETOOTH_EVENT_OPC_TRANSFER_STARTED: + case BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_STARTED: + signal = BT_TRANSFER_STARTED; + break; + case BLUETOOTH_EVENT_OPC_TRANSFER_PROGRESS: + case BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_PROGRESS: + signal = BT_TRANSFER_PROGRESS; + break; + case BLUETOOTH_EVENT_OPC_TRANSFER_COMPLETE: + case BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_COMPLETED: + signal = BT_TRANSFER_COMPLETED; + break; + case BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_AUTHORIZE: + signal = BT_TRANSFER_AUTHORIZED; + break; + case BLUETOOTH_EVENT_OBEX_SERVER_CONNECTION_AUTHORIZE: + case BLUETOOTH_EVENT_RFCOMM_AUTHORIZE: + signal = BT_CONNECTION_AUTHORIZED; + break; + case BLUETOOTH_EVENT_RFCOMM_CONNECTED: + signal = BT_RFCOMM_CONNECTED; + break; + case BLUETOOTH_EVENT_RFCOMM_DISCONNECTED: + signal = BT_RFCOMM_DISCONNECTED; + break; + case BLUETOOTH_EVENT_RFCOMM_DATA_RECEIVED: + signal = BT_RFCOMM_DATA_RECEIVED; + break; + case BLUETOOTH_EVENT_RFCOMM_SERVER_REMOVED: + signal = BT_RFCOMM_SERVER_REMOVED; + break; + case BLUETOOTH_EVENT_DEVICE_CONNECTED: + signal = BT_DEVICE_CONNECTED; + break; + case BLUETOOTH_EVENT_DEVICE_DISCONNECTED: + signal = BT_DEVICE_DISCONNECTED; + break; + case BLUETOOTH_EVENT_AV_SOURCE_CONNECTED: + signal = BT_A2DP_SOURCE_CONNECTED; + BT_INFO_C("Connected [A2DP Source]"); + break; + case BLUETOOTH_EVENT_AV_SOURCE_DISCONNECTED: + signal = BT_A2DP_SOURCE_DISCONNECTED; + BT_INFO_C("Disconnected [A2DP Source]"); + break; + case BLUETOOTH_EVENT_AVRCP_CONNECTED: + case BLUETOOTH_EVENT_AVRCP_CONTROL_CONNECTED: + signal = BT_AVRCP_CONNECTED; + BT_INFO_C("Connected [AVRCP]"); + break; + case BLUETOOTH_EVENT_AVRCP_DISCONNECTED: + case BLUETOOTH_EVENT_AVRCP_CONTROL_DISCONNECTED: + signal = BT_AVRCP_DISCONNECTED; + BT_INFO_C("Disconnected [AVRCP]"); + break; + case BLUETOOTH_EVENT_AVRCP_SETTING_SHUFFLE_STATUS: + case BLUETOOTH_EVENT_AVRCP_CONTROL_SHUFFLE_STATUS: + signal = BT_MEDIA_SHUFFLE_STATUS; + break; + case BLUETOOTH_EVENT_AVRCP_SETTING_EQUALIZER_STATUS: + case BLUETOOTH_EVENT_AVRCP_CONTROL_EQUALIZER_STATUS: + signal = BT_MEDIA_EQUALIZER_STATUS; + break; + case BLUETOOTH_EVENT_AVRCP_SETTING_REPEAT_STATUS: + case BLUETOOTH_EVENT_AVRCP_CONTROL_REPEAT_STATUS: + signal = BT_MEDIA_REPEAT_STATUS; + break; + case BLUETOOTH_EVENT_AVRCP_SETTING_SCAN_STATUS: + case BLUETOOTH_EVENT_AVRCP_CONTROL_SCAN_STATUS: + signal = BT_MEDIA_SCAN_STATUS; + break; + case BLUETOOTH_EVENT_AVRCP_SONG_POSITION_STATUS: + signal = BT_MEDIA_POSITION_STATUS; + break; + case BLUETOOTH_EVENT_AVRCP_PLAY_STATUS_CHANGED: + signal = BT_MEDIA_PLAY_STATUS; + break; + case BLUETOOTH_EVENT_AVRCP_TRACK_CHANGED: + signal = BT_MEDIA_TRACK_CHANGE; + break; + case BLUETOOTH_EVENT_GATT_CONNECTED: + signal = BT_GATT_CONNECTED; + break; + case BLUETOOTH_EVENT_GATT_DISCONNECTED: + signal = BT_GATT_DISCONNECTED; + break; + case BLUETOOTH_EVENT_IPSP_INIT_STATE_CHANGED: + signal = BT_IPSP_INITIALIZED; + break; + case BLUETOOTH_EVENT_IPSP_CONNECTED: + signal = BT_IPSP_CONNECTED; + break; + case BLUETOOTH_EVENT_IPSP_DISCONNECTED: + signal = BT_IPSP_DISCONNECTED; + break; + case BLUETOOTH_EVENT_IPSP_BT_INTERFACE_INFO: + signal = BT_IPSP_BT_INTERFACE_INFO; + break; + case BLUETOOTH_EVENT_GATT_CHAR_VAL_CHANGED: + signal = BT_GATT_CHAR_VAL_CHANGED; + break; + case BLUETOOTH_EVENT_LE_DATA_LENGTH_CHANGED: + signal = BT_LE_DATA_LENGTH_CHANGED; + break; + default: + BT_ERR("Unknown event"); + return BLUETOOTH_ERROR_INTERNAL; + } + + BT_DBG("Path : %s", path); + BT_INFO_C("Signal : %s", signal); + + msg1 = g_dbus_message_new_signal(path, BT_EVENT_SERVICE, signal); + g_dbus_message_set_body(msg1, param); + if (!g_dbus_connection_send_message(event_conn, msg1, G_DBUS_SEND_MESSAGE_FLAGS_NONE, 0, NULL)) { + BT_ERR("Error while sending"); + } + + g_object_unref(msg1); + + return BLUETOOTH_ERROR_NONE; +} + +int _bt_send_event_to_dest(const char* dest, int event_type, + int event, GVariant *param) +{ + BT_DBG("+"); + char *path; + char *signal; + GError *error = NULL; + + retv_if(event_conn == NULL, BLUETOOTH_ERROR_INTERNAL); + + BT_DBG("dest : %s", dest); + BT_DBG("event_type [%d], event [%d]", event_type, event); + + switch (event_type) { + case BT_ADAPTER_EVENT: + path = BT_ADAPTER_PATH; + break; + case BT_LE_ADAPTER_EVENT: + path = BT_LE_ADAPTER_PATH; + break; + case BT_DEVICE_EVENT: + path = BT_DEVICE_PATH; + break; + default: + BT_ERR("Unknown event"); + return BLUETOOTH_ERROR_INTERNAL; + } + + switch (event) { + case BLUETOOTH_EVENT_ADVERTISING_STARTED: + signal = BT_ADVERTISING_STARTED; + break; + case BLUETOOTH_EVENT_ADVERTISING_STOPPED: + signal = BT_ADVERTISING_STOPPED; + break; + case BLUETOOTH_EVENT_LE_DISCOVERY_STARTED: + signal = BT_LE_DISCOVERY_STARTED; + break; + case BLUETOOTH_EVENT_REMOTE_LE_DEVICE_FOUND: + signal = BT_LE_DEVICE_FOUND; + break; + case BLUETOOTH_EVENT_LE_DISCOVERY_FINISHED: + signal = BT_LE_DISCOVERY_FINISHED; + break; + case BLUETOOTH_EVENT_GATT_CHAR_VAL_CHANGED: + signal = BT_GATT_CHAR_VAL_CHANGED; + break; + default: + BT_ERR("Unknown event"); + return BLUETOOTH_ERROR_INTERNAL; + } + + BT_DBG("Path : %s", path); + BT_INFO_C("Signal : %s", signal); + + if (!g_dbus_connection_emit_signal(event_conn, dest, path, BT_EVENT_SERVICE, + signal, param, &error)) { + BT_ERR("Error while sending Signal: %s", signal); + if (error) { + BT_ERR("Error Code [%d], Error Message [%s]", + error->code, error->message); + g_clear_error(&error); + } + } + + BT_DBG("-"); + return BLUETOOTH_ERROR_NONE; +} + +/* To send the event from service daemon to application*/ +int _bt_init_service_event_sender(void) +{ + GDBusConnection *conn; + GError *err = NULL; + + if (event_conn) { + BT_ERR("Event handler is already exist"); + return BLUETOOTH_ERROR_INTERNAL; + } + + conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &err); + retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL); + if (conn == NULL) { + BT_ERR("conn == NULL"); + if (err) { + BT_ERR("Code[%d], Message[%s]", + err->code, err->message); + g_clear_error(&err); + } + + return BLUETOOTH_ERROR_INTERNAL; + } + + event_conn = conn; + return BLUETOOTH_ERROR_NONE; +} + +void _bt_deinit_service_event_sender(void) +{ + if (event_conn) { + g_object_unref(event_conn); + event_conn = NULL; + } +} + diff --git a/bt-service-emul/bt-service-hid.c b/bt-service-emul/bt-service-hid.c new file mode 100644 index 0000000..023e63f --- /dev/null +++ b/bt-service-emul/bt-service-hid.c @@ -0,0 +1,45 @@ +/* + * 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 "bluetooth-api.h" + +#include "bt-service-common.h" +#include "bt-service-hid.h" +#include "bt-service-event.h" +#include "bt-service-util.h" + +/********************************************************************** +* HID APIs * +***********************************************************************/ + +int _bt_hid_connect(int request_id, + bluetooth_device_address_t *device_address) +{ + BT_CHECK_PARAMETER(device_address, return); + + return BLUETOOTH_ERROR_NOT_SUPPORT; +} + +int _bt_hid_disconnect(int request_id, + bluetooth_device_address_t *device_address) +{ + BT_CHECK_PARAMETER(device_address, return); + + return BLUETOOTH_ERROR_NOT_SUPPORT; +} diff --git a/bt-service-emul/bt-service-main.c b/bt-service-emul/bt-service-main.c new file mode 100644 index 0000000..a6591df --- /dev/null +++ b/bt-service-emul/bt-service-main.c @@ -0,0 +1,233 @@ +/* + * 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 "bt-internal-types.h" +#include "bt-service-common.h" +#include "bt-service-event.h" +#include "bt-service-main.h" +#include "bt-service-util.h" +#include "bt-request-handler.h" +#include "bt-service-adapter.h" +#include "bt-service-adapter-le.h" + +static GMainLoop *main_loop; +static gboolean terminated = FALSE; + +static void __bt_release_service(void) +{ + _bt_service_unregister_vconf_handler(); + + _bt_deinit_service_event_sender(); + + _bt_service_unregister(); + + _bt_deinit_proxys(); + + _bt_clear_request_list(); + + _bt_service_cynara_deinit(); + + BT_DBG("Terminating the bt-service daemon"); +} + +static void __bt_sigterm_handler(int signo, siginfo_t *info, void *data) +{ + BT_INFO("signal [%d] is sent by [%d]", signo, info->si_pid); + + return; +} + +gboolean _bt_terminate_service(gpointer user_data) +{ + int bt_status = VCONFKEY_BT_STATUS_OFF; + + if (vconf_get_int(VCONFKEY_BT_STATUS, &bt_status) < 0) { + BT_ERR("no bluetooth device info, so BT was disabled at previous session"); + } else { + if (bt_status != VCONFKEY_BT_STATUS_OFF) { + if (vconf_set_int(VCONFKEY_BT_STATUS, + VCONFKEY_BT_STATUS_OFF) != 0) + BT_ERR("Set vconf failed\n"); + + if (_bt_eventsystem_set_value(SYS_EVENT_BT_STATE, EVT_KEY_BT_STATE, + EVT_VAL_BT_OFF) != ES_R_OK) + BT_ERR("Fail to set value"); + } + } + + if (vconf_get_int(VCONFKEY_BT_LE_STATUS, &bt_status) < 0) { + BT_ERR("no bluetooth device info, so BT was disabled at previous session"); + } else { + if (bt_status != VCONFKEY_BT_LE_STATUS_OFF) { + if (vconf_set_int(VCONFKEY_BT_LE_STATUS, + VCONFKEY_BT_LE_STATUS_OFF) != 0) + BT_ERR("Set vconf failed\n"); + if (_bt_eventsystem_set_value(SYS_EVENT_BT_STATE, EVT_KEY_BT_LE_STATE, + EVT_VAL_BT_LE_OFF) != ES_R_OK) + BT_ERR("Fail to set value"); + } + } + + if (main_loop != NULL) { + g_main_loop_quit(main_loop); + } else { + BT_ERR("main_loop == NULL"); + __bt_release_service(); + terminated = TRUE; + exit(0); + } + + return FALSE; +} + +gboolean _bt_reliable_terminate_service(gpointer user_data) +{ + _bt_deinit_proxys(); + + _bt_clear_request_list(); + + _bt_set_disabled(BLUETOOTH_ERROR_NONE); + + _bt_deinit_service_event_sender(); + + _bt_service_unregister(); + + terminated = TRUE; + + BT_INFO_C("Terminating the bt-service daemon"); + + if (main_loop != NULL) { + g_main_loop_quit(main_loop); + } else { + exit(0); + } + + return FALSE; +} + +static gboolean __bt_check_bt_service(void *data) +{ + bt_status_t status = BT_DEACTIVATED; + bt_le_status_t le_status = BT_LE_DEACTIVATED; +#ifndef TIZEN_TV + int bt_status = VCONFKEY_BT_STATUS_OFF; + int bt_le_status = VCONFKEY_BT_LE_STATUS_OFF; +#endif + + status = _bt_adapter_get_status(); + le_status = _bt_adapter_get_le_status(); + BT_DBG("State: %d, LE State: %d", status, le_status); + +#ifdef TIZEN_TV + _bt_enable_adapter(); +#else + if (vconf_get_int(VCONFKEY_BT_STATUS, &bt_status) < 0) { + BT_DBG("no bluetooth device info, so BT was disabled at previous session"); + } + + if (vconf_get_int(VCONFKEY_BT_LE_STATUS, &bt_le_status) < 0) { + BT_ERR("no bluetooth le info, so BT LE was disabled at previous session"); + } + + if ((bt_status != VCONFKEY_BT_STATUS_OFF) && + (status == BT_DEACTIVATED)) { + BT_DBG("Previous session was enabled."); + + /* Enable the BT */ + _bt_enable_adapter(); + } + + if ((bt_le_status == VCONFKEY_BT_LE_STATUS_ON) && (le_status == BT_LE_DEACTIVATED)) { + BT_DBG("Previous session was le enabled. Turn BT LE on automatically."); + + /* Enable the BT LE */ + _bt_enable_adapter_le(); + } else { + status = _bt_adapter_get_status(); + le_status = _bt_adapter_get_le_status(); + BT_DBG("State: %d, LE State: %d", status, le_status); + + if ((status != BT_ACTIVATING && status != BT_ACTIVATED) && + (le_status != BT_LE_ACTIVATING && le_status != BT_LE_ACTIVATED)) { + _bt_terminate_service(NULL); + } + } +#endif + return FALSE; +} + +int main(void) +{ + struct sigaction sa; + BT_INFO_C("Starting the bt-service daemon"); + + memset(&sa, 0, sizeof(sa)); + sa.sa_sigaction = __bt_sigterm_handler; + sa.sa_flags = SA_SIGINFO; + sigaction(SIGINT, &sa, NULL); + sigaction(SIGTERM, &sa, NULL); + + /* Security Initialization */ + if (_bt_service_cynara_init() != BLUETOOTH_ERROR_NONE) { + BT_ERR("Fail to init cynara"); + return EXIT_FAILURE; + } + + /* Event sender Init */ + if (_bt_init_service_event_sender() != BLUETOOTH_ERROR_NONE) { + BT_ERR("Fail to init event sender"); + return 0; + } + + if (_bt_service_register() != BLUETOOTH_ERROR_NONE) { + BT_ERR("Fail to register service"); + return 0; + } + + _bt_init_request_id(); + + _bt_init_request_list(); + + g_timeout_add(500, (GSourceFunc)__bt_check_bt_service, NULL); + + if (terminated == TRUE) { + __bt_release_service(); + return 0; + } + + main_loop = g_main_loop_new(NULL, FALSE); + + g_main_loop_run(main_loop); + BT_DBG("g_main_loop_quit called!"); + + if (main_loop != NULL) { + g_main_loop_unref(main_loop); + } + + if (terminated == FALSE) + __bt_release_service(); + + return 0; +} + diff --git a/bt-service-emul/bt-service-network.c b/bt-service-emul/bt-service-network.c new file mode 100644 index 0000000..07c7c26 --- /dev/null +++ b/bt-service-emul/bt-service-network.c @@ -0,0 +1,61 @@ +/* + * 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 "bluetooth-api.h" +#include "bt-internal-types.h" +#include "bt-service-network.h" +#include "bt-service-common.h" +#include "bt-service-event.h" +#include "bt-service-util.h" + +int _bt_network_activate(void) +{ + return BLUETOOTH_ERROR_NOT_SUPPORT; +} + +int _bt_network_deactivate(void) +{ + return BLUETOOTH_ERROR_NOT_SUPPORT; +} + +int _bt_network_connect(int request_id, int role, + bluetooth_device_address_t *device_address) +{ + BT_CHECK_PARAMETER(device_address, return); + + return BLUETOOTH_ERROR_NOT_SUPPORT; +} + +int _bt_network_disconnect(int request_id, + bluetooth_device_address_t *device_address) +{ + BT_CHECK_PARAMETER(device_address, return); + + return BLUETOOTH_ERROR_NOT_SUPPORT; +} + +int _bt_network_server_disconnect(int request_id, + bluetooth_device_address_t *device_address) +{ + BT_CHECK_PARAMETER(device_address, return); + + return BLUETOOTH_ERROR_NOT_SUPPORT; +} diff --git a/bt-service-emul/bt-service-obex-server.c b/bt-service-emul/bt-service-obex-server.c new file mode 100644 index 0000000..3610769 --- /dev/null +++ b/bt-service-emul/bt-service-obex-server.c @@ -0,0 +1,135 @@ +/* + * 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 "bluetooth-api.h" +#include "bt-internal-types.h" + +#include "bt-service-common.h" +#include "bt-service-event.h" +#include "bt-service-util.h" +#include "bt-service-obex-server.h" + +typedef struct { + GDBusMethodInvocation *reply_context; + guint64 file_size; + char *filename; + char *file_path; + char *device_name; + char *transfer_path; + char *address; +} bt_auth_info_t; + +typedef struct { + char *dest_path; + char *sender; + int app_pid; +} bt_server_info_t; + +typedef struct { + GDBusProxy *proxy; + int server_type; + int accept_id; + bt_auth_info_t *auth_info; + bt_server_info_t *native_server; + bt_server_info_t *custom_server; +} bt_obex_agent_info_t; + +static bt_obex_agent_info_t agent_info; + +int _bt_obex_server_allocate(char *sender, const char *dest_path, int app_pid, gboolean is_native) +{ + return BLUETOOTH_ERROR_NOT_SUPPORT; +} + +int _bt_obex_server_deallocate(int app_pid, gboolean is_native) +{ + return BLUETOOTH_ERROR_NOT_SUPPORT; +} + +int _bt_obex_server_accept_authorize(const char *filename, gboolean is_native) +{ + BT_CHECK_PARAMETER(filename, return); + + return BLUETOOTH_ERROR_NOT_SUPPORT; +} + +int _bt_obex_server_reject_authorize(void) +{ + return BLUETOOTH_ERROR_NOT_SUPPORT; +} + +int _bt_obex_server_set_destination_path(const char *dest_path, + gboolean is_native) +{ + BT_CHECK_PARAMETER(dest_path, return); + + return BLUETOOTH_ERROR_NOT_SUPPORT; +} + +int _bt_obex_server_set_root(const char *root) +{ + BT_CHECK_PARAMETER(root, return); + + return BLUETOOTH_ERROR_NOT_SUPPORT; +} + +int _bt_obex_server_cancel_transfer(int transfer_id) +{ + return BLUETOOTH_ERROR_NOT_SUPPORT; +} + +int _bt_obex_server_cancel_all_transfers(void) +{ + return BLUETOOTH_ERROR_NOT_SUPPORT; +} + +int _bt_obex_server_is_activated(gboolean *activated) +{ + BT_CHECK_PARAMETER(activated, return); + + return BLUETOOTH_ERROR_NOT_SUPPORT; +} + +/* To support the BOT */ +int _bt_obex_server_accept_connection(int request_id) +{ + return BLUETOOTH_ERROR_NOT_SUPPORT; +} + +/* To support the BOT */ +int _bt_obex_server_reject_connection(void) +{ + return BLUETOOTH_ERROR_NOT_SUPPORT; +} + +int _bt_obex_server_is_receiving(gboolean *receiving) +{ + BT_CHECK_PARAMETER(receiving, return); + + return BLUETOOTH_ERROR_NOT_SUPPORT; +} + +int _bt_obex_get_native_pid(void) +{ + return agent_info.native_server->app_pid; +} + diff --git a/bt-service-emul/bt-service-oob.c b/bt-service-emul/bt-service-oob.c new file mode 100644 index 0000000..1a16a3f --- /dev/null +++ b/bt-service-emul/bt-service-oob.c @@ -0,0 +1,50 @@ +/* + * 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 "bluetooth-api.h" +#include "bt-service-common.h" +#include "bt-service-oob.h" +#include "bt-service-event.h" + +int _bt_oob_read_local_data(bt_oob_data_t *local_oob_data) +{ + BT_CHECK_PARAMETER(local_oob_data, return); + + return BLUETOOTH_ERROR_NOT_SUPPORT; +} + +int _bt_oob_add_remote_data( + bluetooth_device_address_t *remote_device_address, + bt_oob_data_t *remote_oob_data) +{ + BT_CHECK_PARAMETER(remote_device_address, return); + BT_CHECK_PARAMETER(remote_oob_data, return); + + return BLUETOOTH_ERROR_NOT_SUPPORT; +} + +int _bt_oob_remove_remote_data( + bluetooth_device_address_t *remote_device_address) +{ + BT_CHECK_PARAMETER(remote_device_address, return); + + return BLUETOOTH_ERROR_NOT_SUPPORT; +} + diff --git a/bt-service-emul/bt-service-opp-client.c b/bt-service-emul/bt-service-opp-client.c new file mode 100644 index 0000000..7755d2a --- /dev/null +++ b/bt-service-emul/bt-service-opp-client.c @@ -0,0 +1,55 @@ +/* + * 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 "bluetooth-api.h" +#include "bt-internal-types.h" + +#include "bt-service-common.h" +#include "bt-service-event.h" +#include "bt-service-util.h" +#include "bt-service-opp-client.h" + +int _bt_opp_client_push_files(int request_id, GDBusMethodInvocation *context, + bluetooth_device_address_t *remote_address, + char **file_path, int file_count) +{ + BT_CHECK_PARAMETER(remote_address, return); + BT_CHECK_PARAMETER(file_path, return); + + return BLUETOOTH_ERROR_NOT_SUPPORT; +} + +int _bt_opp_client_cancel_push(void) +{ + return BLUETOOTH_ERROR_NOT_SUPPORT; +} + +int _bt_opp_client_cancel_all_transfers(void) +{ + return BLUETOOTH_ERROR_NOT_SUPPORT; +} + +int _bt_opp_client_is_sending(gboolean *sending) +{ + BT_CHECK_PARAMETER(sending, return); + + return BLUETOOTH_ERROR_NOT_SUPPORT; +} + diff --git a/bt-service-emul/bt-service-pbap.c b/bt-service-emul/bt-service-pbap.c new file mode 100644 index 0000000..422194f --- /dev/null +++ b/bt-service-emul/bt-service-pbap.c @@ -0,0 +1,80 @@ +/* + * 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 "bt-internal-types.h" +#include "bt-service-common.h" +#include "bt-service-event.h" +#include "bt-service-pbap.h" + +int _bt_pbap_connect(const bluetooth_device_address_t *address) +{ + BT_CHECK_PARAMETER(address, return); + + return BLUETOOTH_ERROR_NOT_SUPPORT; +} + +int _bt_pbap_disconnect(const bluetooth_device_address_t *address) +{ + BT_CHECK_PARAMETER(address, return); + + return BLUETOOTH_ERROR_NOT_SUPPORT; +} + +int _bt_pbap_get_phonebook_size(const bluetooth_device_address_t *address, + int source, int type) +{ + BT_CHECK_PARAMETER(address, return); + + return BLUETOOTH_ERROR_NOT_SUPPORT; +} + +int _bt_pbap_get_phonebook(const bluetooth_device_address_t *address, + int source, int type, bt_pbap_pull_parameters_t *app_param) +{ + BT_CHECK_PARAMETER(address, return); + + return BLUETOOTH_ERROR_NOT_SUPPORT; +} + +int _bt_pbap_get_list(const bluetooth_device_address_t *address, int source, + int type, bt_pbap_list_parameters_t *app_param) +{ + BT_CHECK_PARAMETER(address, return); + + return BLUETOOTH_ERROR_NOT_SUPPORT; +} + + +int _bt_pbap_pull_vcard(const bluetooth_device_address_t *address, + int source, int type, bt_pbap_pull_vcard_parameters_t *app_param) +{ + BT_CHECK_PARAMETER(address, return); + + return BLUETOOTH_ERROR_NOT_SUPPORT; +} + +int _bt_pbap_phonebook_search(const bluetooth_device_address_t *address, + int source, int type, bt_pbap_search_parameters_t *app_param) +{ + BT_CHECK_PARAMETER(address, return); + + return BLUETOOTH_ERROR_NOT_SUPPORT; +} + diff --git a/bt-service-emul/bt-service-rfcomm-client.c b/bt-service-emul/bt-service-rfcomm-client.c new file mode 100644 index 0000000..f6859b5 --- /dev/null +++ b/bt-service-emul/bt-service-rfcomm-client.c @@ -0,0 +1,75 @@ +/* + * 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 "bluetooth-api.h" +#include "bt-internal-types.h" + +#include "bt-service-common.h" +#include "bt-service-event.h" +#include "bt-service-util.h" +#include "bt-service-rfcomm-client.h" + +int _bt_rfcomm_connect_using_uuid(int request_id, + bluetooth_device_address_t *device_address, + char *remote_uuid) +{ + return BLUETOOTH_ERROR_NOT_SUPPORT; +} + +/* Range of the Channel : 0 <= channel <= 30 */ +int _bt_rfcomm_connect_using_channel(int request_id, + bluetooth_device_address_t *device_address, + char *channel) +{ + return BLUETOOTH_ERROR_NOT_SUPPORT; +} + +/* Be used in RFCOMM client /server */ +int _bt_rfcomm_disconnect(int socket_fd) +{ + return BLUETOOTH_ERROR_NOT_SUPPORT; +} + +/* Be used in RFCOMM client /server */ +int _bt_rfcomm_write(int socket_fd, char *buf, int length) +{ + return BLUETOOTH_ERROR_NOT_SUPPORT; +} + +int _bt_rfcomm_cancel_connect(void) +{ + return BLUETOOTH_ERROR_NOT_SUPPORT; +} + +int _bt_rfcomm_is_connected(gboolean *connected) +{ + BT_CHECK_PARAMETER(connected, return); + + return BLUETOOTH_ERROR_NOT_SUPPORT; +} + +int _bt_rfcomm_is_device_connected(bluetooth_device_address_t *device_address, + gboolean *connected) +{ + BT_CHECK_PARAMETER(device_address, return); + BT_CHECK_PARAMETER(connected, return); + + return BLUETOOTH_ERROR_NOT_SUPPORT; +} + diff --git a/bt-service-emul/bt-service-rfcomm-server.c b/bt-service-emul/bt-service-rfcomm-server.c new file mode 100644 index 0000000..89c03f7 --- /dev/null +++ b/bt-service-emul/bt-service-rfcomm-server.c @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include "bluetooth-api.h" +#include "bt-internal-types.h" + +#include "bt-service-common.h" +#include "bt-service-event.h" +#include "bt-service-util.h" +#include "bt-service-rfcomm-server.h" + +int _bt_rfcomm_create_socket(char *sender, char *uuid) +{ + return BLUETOOTH_ERROR_NOT_SUPPORT; +} + +int _bt_rfcomm_listen(int socket_fd, int max_pending, gboolean is_native) +{ + return BLUETOOTH_ERROR_NOT_SUPPORT; +} + +int _bt_rfcomm_remove_socket(int socket_fd) +{ + return BLUETOOTH_ERROR_NOT_SUPPORT; +} + +/* To support the BOT */ +int _bt_rfcomm_is_uuid_available(char *uuid, gboolean *available) +{ + return BLUETOOTH_ERROR_NOT_SUPPORT; +} + +/* To support the BOT */ +int _bt_rfcomm_accept_connection(void) +{ + return BLUETOOTH_ERROR_NOT_SUPPORT; +} + +/* To support the BOT */ +int _bt_rfcomm_reject_connection(void) +{ + return BLUETOOTH_ERROR_NOT_SUPPORT; +} + diff --git a/bt-service-emul/bt-service-util.c b/bt-service-emul/bt-service-util.c new file mode 100644 index 0000000..681d35c --- /dev/null +++ b/bt-service-emul/bt-service-util.c @@ -0,0 +1,148 @@ +/* + * 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-api.h" +#include "bt-service-common.h" +#include "bt-service-util.h" + +static GSList *req_list = NULL; + +/* available request id : 0 ~ 244 */ +#define BT_REQUEST_ID_RANGE_MAX 245 + +static int assigned_id; +static gboolean req_id_used[BT_REQUEST_ID_RANGE_MAX]; + +void _bt_init_request_id(void) +{ + assigned_id = 0; + memset(req_id_used, 0x00, BT_REQUEST_ID_RANGE_MAX); +} + +int _bt_assign_request_id(void) +{ + int index; + + index = assigned_id + 1; + + if (index >= BT_REQUEST_ID_RANGE_MAX) + index = 0; + + while (req_id_used[index] == TRUE) { + if (index == assigned_id) { + /* No available ID */ + BT_ERR("All request ID is used"); + return -1; + } + + index++; + + if (index >= BT_REQUEST_ID_RANGE_MAX) + index = 0; + } + + assigned_id = index; + req_id_used[index] = TRUE; + + return assigned_id; +} + +void _bt_delete_request_id(int request_id) +{ + ret_if(request_id >= BT_REQUEST_ID_RANGE_MAX); + ret_if(request_id < 0); + + req_id_used[request_id] = FALSE; +} + +void _bt_init_request_list(void) +{ + _bt_clear_request_list(); +} + +/* insert request next to head */ +int _bt_insert_request_list(int req_id, int service_function, + char *name, GDBusMethodInvocation *context) +{ + request_info_t *info; + + info = g_malloc0(sizeof(request_info_t)); + /* Fix : NULL_RETURNS */ + retv_if(info == NULL, BLUETOOTH_ERROR_MEMORY_ALLOCATION); + + info->req_id = req_id; + info->service_function = service_function; + info->context = context; + + req_list = g_slist_append(req_list, info); + + return BLUETOOTH_ERROR_NONE; +} + +request_info_t *_bt_get_request_info(int req_id) +{ + GSList *l; + request_info_t *info; + + for (l = req_list; l != NULL; l = g_slist_next(l)) { + info = l->data; + if (info == NULL) + continue; + + if (info->req_id == req_id) + return info; + } + + return NULL; +} + +/* delete request which has the target req_id */ +int _bt_delete_request_list(int req_id) +{ + GSList *l; + request_info_t *info; + + for (l = req_list; l != NULL; l = g_slist_next(l)) { + info = l->data; + if (info == NULL) + continue; + + if (info->req_id == req_id) { + req_list = g_slist_remove(req_list, info); + _bt_delete_request_id(info->req_id); + g_free(info); + return BLUETOOTH_ERROR_NONE; + } + } + + return BLUETOOTH_ERROR_NOT_FOUND; +} + +void _bt_clear_request_list(void) +{ + if (req_list) { + g_slist_foreach(req_list, (GFunc)g_free, NULL); + g_slist_free(req_list); + req_list = NULL; + } +} + diff --git a/bt-service-emul/include/bt-request-handler.h b/bt-service-emul/include/bt-request-handler.h new file mode 100644 index 0000000..2d769f4 --- /dev/null +++ b/bt-service-emul/include/bt-request-handler.h @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + + +#ifndef _BT_REQUEST_HANDLER_H_ +#define _BT_REQUEST_HANDLER_H_ + +#include +#include +#include + +#include "bt-internal-types.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define BT_SERVICE_NAME "org.projectx.bt" +#define BT_SERVICE_PATH "/org/projectx/bt_service" + +int _bt_service_register(void); + +void _bt_service_unregister(void); + +int _bt_service_cynara_init(void); + +void _bt_service_cynara_deinit(void); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ +#endif /*_BT_REQUEST_HANDLER_H_*/ + diff --git a/bt-service-emul/include/bt-service-adapter-le.h b/bt-service-emul/include/bt-service-adapter-le.h new file mode 100644 index 0000000..cd1873b --- /dev/null +++ b/bt-service-emul/include/bt-service-adapter-le.h @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + + +#ifndef _BT_SERVICE_ADAPTER_LE_H_ +#define _BT_SERVICE_ADAPTER_LE_H_ + +#include +#include +#include "bluetooth-api.h" + +#ifdef __cplusplus +extern "C" { +#endif + +gboolean _bt_is_advertising(void); + +int _bt_set_advertising(const char *sender, int adv_handle, gboolean enable, gboolean use_reserved_slot); + +int _bt_set_custom_advertising(const char *sender, int adv_handle, gboolean enable, bluetooth_advertising_params_t *params, gboolean use_reserved_slot); + +int _bt_get_advertising_data(bluetooth_advertising_data_t *adv, int *length); + +int _bt_set_advertising_data(const char *sender, int adv_handle, bluetooth_advertising_data_t *data, int length, gboolean use_reserved_slot); + +int _bt_get_scan_response_data(bluetooth_scan_resp_data_t *response, int *length); + +int _bt_set_scan_response_data(const char *sender, int adv_handle, bluetooth_scan_resp_data_t *response, int length, gboolean use_reserved_slot); + +int _bt_set_scan_parameters(bluetooth_le_scan_params_t *params); + +int _bt_register_scan_filter(const char *sender, bluetooth_le_scan_filter_t *filter, int *slot_id); + +int _bt_unregister_scan_filter(const char *sender, int slot_id); + +int _bt_unregister_all_scan_filters(const char *sender); + +int _bt_start_le_scan(const char *sender); + +int _bt_stop_le_scan(const char *sender); + +gboolean _bt_is_le_scanning(void); + +int _bt_add_white_list(bluetooth_device_address_t *device_address, bluetooth_device_address_type_t address_type); + +int _bt_remove_white_list(bluetooth_device_address_t *device_address, bluetooth_device_address_type_t address_type); + +int _bt_clear_white_list(void); + +int _bt_le_read_maximum_data_length(bluetooth_le_read_maximum_data_length_t *max_le_datalength); + +int _bt_le_write_host_suggested_default_data_length(const unsigned int def_tx_Octets, const unsigned int def_tx_Time); + +int _bt_le_read_host_suggested_default_data_length(bluetooth_le_read_host_suggested_data_length_t *def_data_length); + +int _bt_le_set_data_length(bluetooth_device_address_t *device_address, const unsigned int max_tx_Octets, const unsigned int max_tx_Time); + +int _bt_initialize_ipsp(void); + +int _bt_deinitialize_ipsp(void); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ +#endif /*_BT_SERVICE_ADAPTER_LE_H_*/ + diff --git a/bt-service-emul/include/bt-service-adapter.h b/bt-service-emul/include/bt-service-adapter.h new file mode 100644 index 0000000..88b68d5 --- /dev/null +++ b/bt-service-emul/include/bt-service-adapter.h @@ -0,0 +1,133 @@ +/* + * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + + +#ifndef _BT_SERVICE_ADAPTER_H_ +#define _BT_SERVICE_ADAPTER_H_ + +#include +#include +#include "bluetooth-api.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef enum { + BT_DEACTIVATED, + BT_ACTIVATED, + BT_ACTIVATING, + BT_DEACTIVATING, +} bt_status_t; + +typedef enum { + BT_LE_DEACTIVATED, + BT_LE_ACTIVATED, + BT_LE_ACTIVATING, + BT_LE_DEACTIVATING, +} bt_le_status_t; + +int _bt_enable_adapter(void); + +int _bt_disable_adapter(void); + +int _bt_recover_adapter(void); + +int _bt_enable_adapter_le(void); + +int _bt_disable_adapter_le(void); + +int _bt_reset_adapter(void); + +int _bt_enable_core(void); + +void _bt_handle_adapter_added(void); + +void _bt_handle_adapter_removed(void); + +int _bt_check_adapter(int *status); + +void _bt_service_register_vconf_handler(void); + +void _bt_service_unregister_vconf_handler(void); + +void _bt_set_discovery_status(gboolean mode); + +int _bt_get_local_address(bluetooth_device_address_t *local_address); + +int _bt_get_local_version(bluetooth_version_t *local_version); + +int _bt_get_local_name(bluetooth_device_name_t *local_name); + +int _bt_set_local_name(char *local_name); + +int _bt_is_service_used(char *service_uuid, gboolean *used); + +int _bt_get_discoverable_mode(int *mode); + +int _bt_set_discoverable_mode(int discoverable_mode, int timeout); + +gboolean _bt_is_connectable(void); + +int _bt_set_connectable(gboolean connectable); + +int _bt_start_discovery(void); + +int _bt_start_custom_discovery(bt_discovery_role_type_t role); + +int _bt_cancel_discovery(void); + +int _bt_get_bonded_devices(GArray **dev_list); + +int _bt_get_bonded_device_info(bluetooth_device_address_t *device_address, + bluetooth_device_info_t *dev_info); + +int _bt_get_timeout_value(int *timeout); + +gboolean _bt_is_discovering(void); + +gboolean _bt_get_advertising_params(bluetooth_advertising_params_t *params); + +gboolean _bt_get_cancel_by_user(void); + +void _bt_set_cancel_by_user(gboolean value); + +void _bt_adapter_set_status(bt_status_t status); + +bt_status_t _bt_adapter_get_status(void); + +void _bt_adapter_set_le_status(bt_le_status_t status); + +bt_le_status_t _bt_adapter_get_le_status(void); + +void _bt_adapter_start_enable_timer(void); + +void _bt_adapter_start_le_enable_timer(void); + +void _bt_set_disabled(int result); + +void _bt_set_le_disabled(int result); + +int _bt_set_le_privacy(gboolean set_privacy); + +int _bt_set_manufacturer_data(bluetooth_manufacturer_data_t *m_data); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ +#endif /*_BT_SERVICE_ADAPTER_H_*/ + diff --git a/bt-service-emul/include/bt-service-audio.h b/bt-service-emul/include/bt-service-audio.h new file mode 100644 index 0000000..dc9af43 --- /dev/null +++ b/bt-service-emul/include/bt-service-audio.h @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + + +#ifndef _BT_SERVICE_AUDIO_H_ +#define _BT_SERVICE_AUDIO_H_ + +#include +#include +#include "bluetooth-api.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef enum { + BT_AUDIO_HSP = 0x01, + BT_AUDIO_A2DP, + BT_AUDIO_ALL, + BT_AVRCP, + BT_AUDIO_A2DP_SOURCE +} bt_audio_type_t; + +int _bt_audio_connect(int request_id, int type, + bluetooth_device_address_t *device_address, + GArray **out_param1); + +int _bt_audio_disconnect(int request_id, int type, + bluetooth_device_address_t *device_address, + GArray **out_param1); + +int _bt_hf_connect(int request_id, + bluetooth_device_address_t *device_address, + GArray **out_param1); + +int _bt_hf_disconnect(int request_id, + bluetooth_device_address_t *device_address, + GArray **out_param1); + + +int _bt_audio_set_content_protect(gboolean status); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ +#endif /*_BT_SERVICE_AUDIO_H_*/ + diff --git a/bt-service-emul/include/bt-service-avrcp-controller.h b/bt-service-emul/include/bt-service-avrcp-controller.h new file mode 100644 index 0000000..50a583b --- /dev/null +++ b/bt-service-emul/include/bt-service-avrcp-controller.h @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + + +#ifndef _BT_SERVICE_AVRCP_CONTROLLER_H_ +#define _BT_SERVICE_AVRCP_CONTROLLER_H_ + +#include +#include +#include + +#include "bluetooth-api.h" +#include "bluetooth-media-control.h" + +#ifdef __cplusplus +extern "C" { +#endif + + +int _bt_avrcp_control_cmd(int type); + +int _bt_avrcp_control_set_property(int type, unsigned int value); + +int _bt_avrcp_control_get_property(int type, unsigned int *value); + +int _bt_avrcp_control_get_track_info(media_metadata_attributes_t *metadata); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ +#endif /*_BT_SERVICE_AVRCP_CONTROLLER_H_*/ + + diff --git a/bt-service-emul/include/bt-service-avrcp.h b/bt-service-emul/include/bt-service-avrcp.h new file mode 100644 index 0000000..18253c5 --- /dev/null +++ b/bt-service-emul/include/bt-service-avrcp.h @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + + +#ifndef _BT_SERVICE_AVRCP_H_ +#define _BT_SERVICE_AVRCP_H_ + +#include +#include + +#include "bluetooth-api.h" +#include "bluetooth-media-control.h" + +#ifdef __cplusplus +extern "C" { +#endif + +int _bt_avrcp_set_track_info(media_metadata_attributes_t *meta_data); + +int _bt_avrcp_set_properties(media_player_settings_t *properties); + +int _bt_avrcp_set_property(int type, unsigned int value); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ +#endif /*_BT_SERVICE_AVRCP_H_*/ + diff --git a/bt-service-emul/include/bt-service-common.h b/bt-service-emul/include/bt-service-common.h new file mode 100644 index 0000000..adcd4d9 --- /dev/null +++ b/bt-service-emul/include/bt-service-common.h @@ -0,0 +1,371 @@ +/* + * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + + +#ifndef _BT_SERVICE_COMMON_H_ +#define _BT_SERVICE_COMMON_H_ + +#include +#include +#include +#include + +#include "bluetooth-api.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#undef LOG_TAG +#define LOG_TAG "BLUETOOTH_FRWK_SERVICE" + +#ifdef FUNCTION_TRACE +#define FN_START BT_DBG("[ENTER FUNC]") +#define FN_END BT_DBG("[EXIT FUNC]") +#else +#define FN_START +#define FN_END +#endif + +#define LOG_COLOR_RESET "\033[0m" +#define LOG_COLOR_RED "\033[31m" +#define LOG_COLOR_YELLOW "\033[33m" +#define LOG_COLOR_GREEN "\033[32m" +#define LOG_COLOR_BLUE "\033[36m" +#define LOG_COLOR_PURPLE "\033[35m" + +#define BT_DBG(fmt, args...) \ + SLOGD(fmt, ##args) +#define BT_INFO(fmt, args...) \ + SLOGI(fmt, ##args) +#define BT_ERR(fmt, args...) \ + SLOGE(fmt, ##args) + +#define BT_INFO_C(fmt, arg...) \ + SLOGI_IF(TRUE, LOG_COLOR_GREEN" "fmt" "LOG_COLOR_RESET, ##arg) +#define BT_ERR_C(fmt, arg...) \ + SLOGI_IF(TRUE, LOG_COLOR_RED" "fmt" "LOG_COLOR_RESET, ##arg) + +#define DBG_SECURE(fmt, args...) SECURE_SLOGD(fmt, ##args) +#define ERR_SECURE(fmt, args...) SECURE_SLOGE(fmt, ##args) + +#define ret_if(expr) \ + do { \ + if (expr) { \ + BT_ERR("(%s) return", #expr); \ + return; \ + } \ + } while (0) + +#define retv_if(expr, val) \ + do { \ + if (expr) { \ + BT_ERR("(%s) return", #expr); \ + return (val); \ + } \ + } while (0) + +#define BT_CHECK_PARAMETER(arg, func) \ + do { \ + if (arg == NULL) { \ + BT_ERR("%s is NULL", #arg); \ + func BLUETOOTH_ERROR_INVALID_PARAM; \ + } \ + } while (0) + + +#define BT_ADDRESS_LENGTH_MAX 6 +#define BT_ADDRESS_STRING_SIZE 18 +#define BT_RFCOMM_BUFFER_MAX 1024 +#define BT_LOWER_ADDRESS_LENGTH 9 + +#define BT_AGENT_AUTO_PAIR_BLACKLIST_FILE (APP_SYSCONFDIR"/auto-pair-blacklist") +#define BT_AGENT_NEW_LINE "\r\n" + +#define BT_MAX_DBUS_TIMEOUT 45000 +#ifndef TIZEN_TV +#define BT_ENABLE_TIMEOUT 20000 /* 20 seconds */ +#else +#define BT_ENABLE_TIMEOUT 5000 /* 5 seconds */ +#endif +#define BT_DISCOVERY_FINISHED_DELAY 200 + +#define MANAGER_EVENT_MATCH_RULE \ + "type='signal'," \ + "interface='%s'," \ + "member='%s'" + +#define EVENT_MATCH_RULE \ + "type='signal'," \ + "interface='%s'," + +#define BT_TEMINATING_WAIT_TIME 200 + +#define BT_TIMEOUT_MESSAGE "Did not receive a reply. Possible causes include: " \ + "the remote application did not send a reply, " \ + "the message bus security policy blocked the reply, " \ + "the reply timeout expired, or the network connection " \ + "was broken." + +#define BT_BLUEZ_NAME "org.bluez" + +#define BT_BLUEZ_PATH "/org/bluez" +#define BT_BLUEZ_HCI_PATH "/org/bluez/hci0" +#define BT_AGENT_NAME "org.bluez.frwk_agent" +#define BT_AGENT_PATH "/org/bluez/agent/frwk_agent" +#define BT_DEVICE_AGENT_PATH "/org/tizen/device_agent" +#define BT_ADAPTER_AGENT_PATH "/org/tizen/adapter_agent" +#define BT_MANAGER_PATH "/" + + +#define BT_MANAGER_INTERFACE "org.freedesktop.DBus.ObjectManager" +#define BT_ADAPTER_INTERFACE "org.bluez.Adapter1" +#define BT_AGENT_INTERFACE "org.bluez.Agent1" +#define BT_AGENT_MANAGER_INTERFACE "org.bluez.AgentManager1" +#define BT_DEVICE_INTERFACE "org.bluez.Device1" +#define BT_NETWORK_SERVER_INTERFACE "org.bluez.NetworkServer1" +#define BT_MEDIA_INTERFACE "org.bluez.Media1" +#define BT_MEDIA_PLAYER_INTERFACE "org.mpris.MediaPlayer2.Player" +#define BT_MEDIATRANSPORT_INTERFACE "org.bluez.MediaTransport1" +#define BT_MEDIA_CONTROL_INTERFACE "org.bluez.MediaControl1" +#define BT_PLAYER_CONTROL_INTERFACE "org.bluez.MediaPlayer1" +#define BT_GATT_CHAR_INTERFACE "org.bluez.GattCharacteristic1" + +#define BT_INPUT_INTERFACE "org.bluez.Input1" +#define BT_NETWORK_INTERFACE "org.bluez.Network" +#define BT_NETWORK_CLIENT_INTERFACE "org.bluez.Network1" +#define BT_SERIAL_INTERFACE "org.bluez.Serial" +#define BT_SERIAL_MANAGER_INTERFACE "org.bluez.SerialProxyManager" +#define BT_SERIAL_PROXY_INTERFACE "org.bluez.SerialProxy" +#define BT_SINK_INTERFACE "org.bluez.AudioSink" +#define BT_AUDIO_INTERFACE "org.bluez.Audio" +#define BT_HEADSET_INTERFACE "org.bluez.Headset" +#define BT_OOB_INTERFACE "org.bluez.OutOfBand" +#define BT_HANDSFREE_GATEWAY_INTERFACE "org.bluez.HandsfreeGateway" +#define BT_OBEXD_INTERFACE "org.openobex" +#define BT_OBEXD_MANAGER_INTERFACE "org.openobex.Manager" +#define BT_OBEXD_TRANSFER_INTERFACE "org.openobex.Transfer" +#define BT_A2DP_SOURCE_INTERFACE "org.bluez.AudioSource" + +#define BT_PROPERTIES_INTERFACE "org.freedesktop.DBus.Properties" + + +#define BT_OBEX_SERVICE_NAME "org.bluez.obex" +#define BT_OBEX_CLIENT_PATH "/org/bluez/obex" +#define BT_OBEX_CLIENT_INTERFACE "org.bluez.obex.Client1" + + + +#define BT_OBEX_TRANSFER_INTERFACE "org.bluez.obex.Transfer1" +#define BT_OBEX_AGENT_INTERFACE "org.bluez.obex.Agent1" + + + +#define BT_OBEXD_DBUS_NAME "org.bluez.obex" +#define BT_OBEX_OBJECT_PUSH_INTERFACE "org.bluez.obex.ObjectPush1" + + +#define BT_FREEDESKTOP_INTERFACE "org.freedesktop.DBus" +#define BT_FREEDESKTOP_PATH "/org/freedesktop/DBus" + + +#define BT_INTERFACES_ADDED "InterfacesAdded" +#define BT_INTERFACES_REMOVED "InterfacesRemoved" +#define BT_NAME_OWNER_CHANGED "NameOwnerChanged" +#define BT_PROPERTIES_CHANGED "PropertiesChanged" + + + +#define BT_SESSION_BASEPATH_SERVER "/org/bluez/obex/server" +#define BT_SESSION_BASEPATH_CLIENT "/org/bluez/obex/client" + +#define BT_SERVICE_ERR_MSG_NOT_SUPPORTED "Operation is not supported" + +/* UUID */ +#define GENERIC_AUDIO_UUID "00001203-0000-1000-8000-00805f9b34fb" + +#define OBEX_OPP_UUID "00001105-0000-1000-8000-00805f9b34fb" + +#define HSP_HS_UUID "00001108-0000-1000-8000-00805f9b34fb" +#define HSP_AG_UUID "00001112-0000-1000-8000-00805f9b34fb" + +#define HFP_HS_UUID "0000111e-0000-1000-8000-00805f9b34fb" +#define HFP_AG_UUID "0000111f-0000-1000-8000-00805f9b34fb" + +#define ADVANCED_AUDIO_UUID "0000110d-0000-1000-8000-00805f9b34fb" + +#define A2DP_SOURCE_UUID "0000110a-0000-1000-8000-00805f9b34fb" +#define A2DP_SINK_UUID "0000110b-0000-1000-8000-00805f9b34fb" + +#define AVRCP_REMOTE_UUID "0000110e-0000-1000-8000-00805f9b34fb" +#define AVRCP_TARGET_UUID "0000110c-0000-1000-8000-00805f9b34fb" + +#define HID_UUID "00001124-0000-1000-8000-00805f9b34fb" +#define PNP_UUID "00001200-0000-1000-8000-00805f9b34fb" +#define RFCOMM_UUID_STR "00000003-0000-1000-8000-00805f9b34fb" +#define PANU_UUID "00001115-0000-1000-8000-00805f9b34fb" +#define NAP_UUID "00001116-0000-1000-8000-00805f9b34fb" +#define OBEX_PSE_UUID "0000112f-0000-1000-8000-00805f9b34fb" +#define GATT_UUID "00001801-0000-1000-8000-00805f9b34fb" + +/* Privilege */ +#define BT_PRIVILEGE_PUBLIC "http://tizen.org/privilege/bluetooth" +#define BT_PRIVILEGE_PLATFORM "http://tizen.org/privilege/bluetooth.admin" +#define MEDIASTORAGE_PRIVILEGE "http://tizen.org/privilege/mediastorage" + +/* BD Address type */ +#define BDADDR_BREDR 0x00 +#define BDADDR_LE_PUBLIC 0x01 +#define BDADDR_LE_RANDOM 0x02 + +/* Advertising report event types */ +#define BT_LE_ADV_IND 0x00 +#define BT_LE_ADV_DIRECT_IND 0x01 +#define BT_LE_ADV_SCAN_IND 0x02 +#define BT_LE_ADV_NONCONN_IND 0x03 +#define BT_LE_ADV_SCAN_RSP 0x04 + +/* Profile states matched to btd_service_state_t of bluez service.h */ +typedef enum { + BT_PROFILE_STATE_UNAVAILABLE, + BT_PROFILE_STATE_DISCONNECTED, + BT_PROFILE_STATE_CONNECTING, + BT_PROFILE_STATE_CONNECTED, + BT_PROFILE_STATE_DISCONNECTING, +} bt_profile_state_t; + +typedef enum { + BT_ADV_IND_INFO = 0x00, + BT_SCAN_RSP_INFO = 0x01, +} bt_le_device_info_type_t; + +typedef enum { + BT_PROFILE_CONN_RFCOMM = 0x01, + BT_PROFILE_CONN_A2DP = 0x02, + BT_PROFILE_CONN_HSP = 0x04, + BT_PROFILE_CONN_HID = 0x08, + BT_PROFILE_CONN_NAP = 0x10, + BT_PROFILE_CONN_HFG = 0x20, + BT_PROFILE_CONN_GATT = 0x40, + BT_PROGILE_CONN_NAP = 0x80, + BT_PROFILE_CONN_A2DP_SINK = 0x100, + BT_PROFILE_CONN_ALL = 0xffffffff, +} bt_profile_type_t; + +typedef struct { + char *address; + int addr_type; + int rssi; + int adv_type; + bt_le_device_info_type_t dev_type; + int adv_data_len; + char *adv_data; +} bt_remote_le_dev_info_t; + +typedef struct { + int rssi; + int class; + char *address; + char *name; + char **uuids; + unsigned int uuid_count; + gboolean paired; + bluetooth_connected_link_t connected; + gboolean trust; + char *manufacturer_data; + int manufacturer_data_len; + guchar addr_type; +#if 0 /* Should match with bt_dev_info_t in bluetooth-api.h */ + bt_remote_le_dev_info_t le_dev_info; +#endif +} bt_remote_dev_info_t; + +/* RFCOMM client /server will use this structure*/ +typedef struct { + int fd; + GIOChannel *io_channel; + guint io_event; + char *dev_node; + char *address; + char *uuid; +} bt_rfcomm_info_t; + +typedef struct { + int req_id; + char *address; +} bt_function_data_t; + +GDBusConnection *_bt_get_system_conn(void); + +GDBusConnection *_bt_get_system_gconn(void); + +GDBusConnection *_bt_get_session_gconn(void); + +char *_bt_get_profile_uuid128(bt_profile_type_t profile_type); + +char *_bt_convert_error_to_string(int error); + +char * _bt_convert_disc_reason_to_string(int reason); + +void _bt_logging_connection(gboolean connect, int addr_type); + +void _bt_deinit_proxys(void); + +void _bt_convert_device_path_to_address(const char *device_path, + char *device_address); + +void _bt_convert_addr_string_to_type(unsigned char *addr, + const char *address); + +void _bt_convert_addr_type_to_string(char *address, + unsigned char *addr); + +void _bt_swap_byte_ordering(char *data, int data_len); + +int _bt_byte_arr_cmp(const char *data1, const char *data2, int data_len); + +int _bt_byte_arr_cmp_with_mask(const char *data1, const char *data2, + const char *mask, int data_len); + +void _bt_print_device_address_t(const bluetooth_device_address_t *addr); + +void _bt_divide_device_class(bluetooth_device_class_t *device_class, + unsigned int cod); + +void _bt_free_device_info(bt_remote_dev_info_t *dev_info); + +void _bt_free_le_device_info(bt_remote_le_dev_info_t *le_dev_info); + +int _bt_copy_utf8_string(char *dest, const char *src, unsigned int length); + +gboolean _bt_utf8_validate(char *name); + +int _bt_register_osp_server_in_agent(int type, char *uuid, char *path, int fd); + +int _bt_unregister_osp_server_in_agent(int type, char *uuid); + +int _bt_set_socket_non_blocking(int socket_fd); + +int _bt_set_non_blocking_tty(int sk); + +int _bt_eventsystem_set_value(const char *event, const char *key, const char *value); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ +#endif /*_BT_COMMON_H_*/ + diff --git a/bt-service-emul/include/bt-service-device.h b/bt-service-emul/include/bt-service-device.h new file mode 100644 index 0000000..7d7195f --- /dev/null +++ b/bt-service-emul/include/bt-service-device.h @@ -0,0 +1,107 @@ +/* + * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + + +#ifndef _BT_SERVICE_DEVICE_H_ +#define _BT_SERVICE_DEVICE_H_ + +#include +#include +#include "bluetooth-api.h" + +#ifdef __cplusplus +extern "C" { +#endif + +int _bt_bond_device(int request_id, + bluetooth_device_address_t *device_address, + unsigned short conn_type, GArray **out_param1); + +int _bt_cancel_bonding(void); + +int _bt_passkey_reply(const char *passkey, gboolean authentication_reply); + +int _bt_passkey_confirmation_reply(gboolean confirmation_reply); + +int _bt_unbond_device(int request_id, + bluetooth_device_address_t *device_address, + GArray **out_param1); + +int _bt_cancel_search_device(void); + +int _bt_search_device(int request_id, + bluetooth_device_address_t *device_address); + +int _bt_set_alias(bluetooth_device_address_t *device_address, + const char *alias); + +int _bt_set_authorization(bluetooth_device_address_t *device_address, + gboolean authorize); + +int _bt_is_gatt_connected(bluetooth_device_address_t *device_address, + gboolean *is_connected); + +int _bt_is_device_connected(bluetooth_device_address_t *device_address, + int connection_type, gboolean *is_connected); + +int _bt_get_connected_link(bluetooth_device_address_t *device_address, + bluetooth_connected_link_t *connected); + +int _bt_set_pin_code(bluetooth_device_address_t *device_address, + bluetooth_device_pin_code_t *pin_code); + +int _bt_unset_pin_code(bluetooth_device_address_t *device_address); + +int _bt_get_device_pin_code(const char *address, char *pin_code); + +gboolean _bt_is_device_creating(void); + +int _bt_connect_le_device(int request_id, + const bluetooth_device_address_t *bd_addr, + gboolean auto_connect); + +int _bt_disconnect_le_device(int request_id, + const bluetooth_device_address_t *bd_addr); + +int _bt_enable_rssi(bluetooth_device_address_t *bd_addr, int link_type, + int low_threshold, int in_range_threshold, int high_threshold); + +int _bt_get_rssi_strength(bluetooth_device_address_t *bd_addr, + int link_type); + +int _bt_le_conn_update(unsigned char *device_address, + guint16 interval_min, guint16 interval_max, + guint16 latency, guint16 time_out); + +int _bt_get_le_connection_parameter(bluetooth_le_connection_mode_t mode, + bluetooth_le_connection_param_t *param); + +int _bt_connect_profile(char *address, char *uuid, + void *cb, gpointer func_data); + +int _bt_disconnect_profile(char *address, char *uuid, + void *cb, gpointer func_data); +int _bt_connect_le_ipsp_device(const bluetooth_device_address_t *bd_addr); + +int _bt_disconnect_le_ipsp_device(const bluetooth_device_address_t *bd_addr); + + +#ifdef __cplusplus +} +#endif /* __cplusplus */ +#endif /*_BT_SERVICE_ADAPTER_H_*/ + diff --git a/bt-service-emul/include/bt-service-dpm.h b/bt-service-emul/include/bt-service-dpm.h new file mode 100644 index 0000000..9b31549 --- /dev/null +++ b/bt-service-emul/include/bt-service-dpm.h @@ -0,0 +1,165 @@ +/* + * 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. + * + */ +#ifdef TIZEN_DPM_ENABLE + +#ifndef _BT_SERVICE_DPM_H_ +#define _BT_SERVICE_DPM_H_ + +#include +#include +#include "bluetooth-api.h" + +#ifdef __cplusplus + extern "C" { +#endif + + + /** + * @brief DPM BT allowance state + * @see + */ + typedef enum { + DPM_BT_ERROR = -1, /**< bluetooth allowance error */ + DPM_BT_ALLOWED, /**< bluetooth allowance allowed */ + DPM_BT_HANDSFREE_ONLY, /**< bluetooth allowance handsfree only */ + DPM_BT_RESTRICTED, /**< bluetooth allowance restricted */ + } dpm_bt_allow_t; + + /** + * @brief DPM API result + * @see + */ +typedef enum _dpm_result { + DPM_RESULT_SERVICE_NOT_ENABLED = -5, /**< DPM API result service not enabled. */ + DPM_RESULT_ACCESS_DENIED = -4, /**< DPM API result access denied. */ + DPM_RESULT_INVALID_PARAM = -3, /**< DPM API result invalid parameter. */ + DPM_RESULT_NOT_SUPPORTED = -2, /**< DPM API result not supported. */ + DPM_RESULT_FAIL = -1, /**< DPM API result fail. */ + DPM_RESULT_SUCCESS = 0, /**< DPM API result success. */ +} dpm_result_t; + +/** + * @brief DPM Policy status + * @see + */ +typedef enum _dpm_status { + DPM_STATUS_ERROR = -1, + + DPM_ALLOWED = 0, /**< DPM Policy status allowed. */ + DPM_RESTRICTED = 1, /**< DPM Policy status restricted. */ + + DPM_ENABLE = 1, /**< DPM Policy status enabled. */ + DPM_DISABLE = 0, /**< DPM Policy status disabled. */ + + DPM_FALSE = 0, /**< DPM Policy status false. */ + DPM_TRUE = 1, /**< DPM Policy status true. */ +} dpm_status_t; + +typedef enum _dpm_policy_cmd { + /* policy-group : BLUETOOTH */ + DPM_POLICY_ALLOW_BLUETOOTH, + DPM_POLICY_BLUETOOTH_DEVICE_RESTRICTION, + DPM_POLICY_BLUETOOTH_UUID_RESTRICTION, + DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST, + DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST, + DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST, + DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST, + DPM_POLICY_ALLOW_BLUETOOTH_OUTGOING_CALL, + DPM_POLICY_BLUETOOTH_PAIRING_STATE, + DPM_POLICY_BLUETOOTH_DESKTOP_CONNECTIVITY_STATE, + DPM_POLICY_BLUETOOTH_DISCOVERABLE_STATE, + DPM_POLICY_BLUETOOTH_LIMITED_DISCOVERABLE_STATE, + DPM_POLICY_BLUETOOTH_DATA_TRANSFER_STATE, + DPM_POLICY_END, +} dpm_policy_cmd_t; + + +struct dpm_policy { + union { + int value; + GSList *list; + }; +}; +typedef struct dpm_policy dpm_policy_t; + + +typedef enum dpm_profile { + DPM_POLICY_BLUETOOTH_A2DP_PROFILE_STATE, + DPM_POLICY_BLUETOOTH_AVRCP_PROFILE_STATE, + DPM_POLICY_BLUETOOTH_BPP_PROFILE_STATE, + DPM_POLICY_BLUETOOTH_DUN_PROFILE_STATE, + DPM_POLICY_BLUETOOTH_FTP_PROFILE_STATE, + DPM_POLICY_BLUETOOTH_HFP_PROFILE_STATE, + DPM_POLICY_BLUETOOTH_HSP_PROFILE_STATE, + DPM_POLICY_BLUETOOTH_PBAP_PROFILE_STATE, + DPM_POLICY_BLUETOOTH_SAP_PROFILE_STATE, + DPM_POLICY_BLUETOOTH_SPP_PROFILE_STATE, + DPM_PROFILE_NONE, +} dpm_profile_t; + +struct dpm_profile_val { + int value; /* tells whether the profile is enabled or disabled */ +}; +typedef struct dpm_profile_val dpm_profile_state_t; + +dpm_result_t _bt_dpm_set_allow_bluetooth_mode(dpm_bt_allow_t value); +dpm_bt_allow_t _bt_dpm_get_allow_bluetooth_mode(void); +dpm_result_t _bt_dpm_activate_bluetooth_device_restriction(dpm_status_t value); +dpm_status_t _bt_dpm_is_bluetooth_device_restriction_active(void); +dpm_result_t _bt_dpm_activate_bluetoooth_uuid_restriction(dpm_status_t value); +dpm_status_t _bt_dpm_is_bluetooth_uuid_restriction_active(void); +dpm_result_t _bt_dpm_add_bluetooth_devices_to_blacklist(bluetooth_device_address_t *bd_addr); +dpm_result_t _bt_dpm_add_bluetooth_devices_to_whitelist(bluetooth_device_address_t *bd_addr); +dpm_result_t _bt_dpm_add_bluetooth_uuids_to_blacklist(const char *uuid); +dpm_result_t _bt_dpm_add_bluetooth_uuids_to_whitelist(const char *uuid); +dpm_result_t _bt_dpm_set_allow_bluetooth_outgoing_call(dpm_status_t value); +dpm_status_t _bt_dpm_get_allow_bluetooth_outgoing_call(void); +dpm_result_t _bt_dpm_clear_bluetooth_devices_from_blacklist(void); +dpm_result_t _bt_dpm_clear_bluetooth_devices_from_whitelist(void); +dpm_result_t _bt_dpm_clear_bluetooth_uuids_from_blacklist(void); +dpm_result_t _bt_dpm_clear_bluetooth_uuids_from_whitelist(void); +dpm_result_t _bt_dpm_get_bluetooth_devices_from_blacklist(GArray **out_param1); +dpm_result_t _bt_dpm_get_bluetooth_devices_from_whitelist(GArray **out_param1); +dpm_result_t _bt_dpm_get_bluetooth_uuids_from_blacklist(GArray **out_param1); +dpm_result_t _bt_dpm_get_bluetooth_uuids_from_whitelist(GArray **out_param1); +dpm_status_t _bt_dpm_is_bluetooth_device_restriction_active(void); +dpm_status_t _bt_dpm_is_bluetooth_uuid_restriction_active(void); +dpm_status_t _bt_dpm_set_bluetooth_pairing_state(dpm_status_t value); +dpm_status_t _bt_dpm_get_bluetooth_pairing_state(void); +dpm_status_t _bt_dpm_set_bluetooth_profile_state(dpm_profile_t profile, dpm_status_t value); +dpm_status_t _bt_dpm_get_bluetooth_profile_state(dpm_profile_t profile); +dpm_status_t _bt_dpm_set_bluetooth_desktop_connectivity_state(dpm_status_t value); +dpm_status_t _bt_dpm_get_bluetooth_desktop_connectivity_state(void); +dpm_status_t _bt_dpm_set_bluetooth_discoverable_state(dpm_status_t value); +dpm_status_t _bt_dpm_get_bluetooth_discoverable_state(void); +dpm_result_t _bt_dpm_clear_bluetooth_devices_from_list(void); +dpm_result_t _bt_dpm_clear_bluetooth_uuids_from_list(void); +dpm_status_t _bt_dpm_set_bluetooth_limited_discoverable_state(dpm_status_t value); +dpm_status_t _bt_dpm_get_bluetooth_limited_discoverable_state(void); +dpm_status_t _bt_dpm_set_bluetooth_data_transfer_state(dpm_status_t value); +dpm_status_t _bt_dpm_get_allow_bluetooth_data_transfer_state(void); +dpm_result_t _bt_dpm_remove_bluetooth_devices_from_whitelist(bluetooth_device_address_t *bd_addr); +dpm_result_t _bt_dpm_remove_bluetooth_devices_from_blacklist(bluetooth_device_address_t *bd_addr); +dpm_result_t _bt_dpm_remove_bluetooth_uuids_from_whitelist(const char *uuids); +dpm_result_t _bt_dpm_remove_bluetooth_uuids_from_blacklist(const char *uuids); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ +#endif /*_BT_SERVICE_DPM_H_*/ +#endif /* #ifdef TIZEN_DPM_ENABLE */ + diff --git a/bt-service-emul/include/bt-service-event.h b/bt-service-emul/include/bt-service-event.h new file mode 100644 index 0000000..95edaf6 --- /dev/null +++ b/bt-service-emul/include/bt-service-event.h @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + + +#ifndef _BT_SERVICE_EVENT_H_ +#define _BT_SERVICE_EVENT_H_ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +int _bt_send_event(int event_type, int event, GVariant *param); + +int _bt_send_event_to_dest(const char* dest, int event_type, int event, GVariant *param); + +int _bt_init_service_event_sender(void); +void _bt_deinit_service_event_sender(void); + + +#ifdef __cplusplus +} +#endif /* __cplusplus */ +#endif /*_BT_SERVICE_EVENT_H_*/ + diff --git a/bt-service-emul/include/bt-service-hid.h b/bt-service-emul/include/bt-service-hid.h new file mode 100644 index 0000000..ce3d0dd --- /dev/null +++ b/bt-service-emul/include/bt-service-hid.h @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + + +#ifndef _BT_SERVICE_HID_H_ +#define _BT_SERVICE_HID_H_ + +#include +#include +#include "bluetooth-api.h" + +#ifdef __cplusplus +extern "C" { +#endif + +int _bt_hid_connect(int request_id, + bluetooth_device_address_t *device_address); + +int _bt_hid_disconnect(int request_id, + bluetooth_device_address_t *device_address); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ +#endif /*_BT_SERVICE_HID_H_*/ + diff --git a/bt-service-emul/include/bt-service-main.h b/bt-service-emul/include/bt-service-main.h new file mode 100644 index 0000000..866df9b --- /dev/null +++ b/bt-service-emul/include/bt-service-main.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + + +#ifndef _BT_SERVICE_MAIN_H_ +#define _BT_SERVICE_MAIN_H_ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +gboolean _bt_terminate_service(gpointer user_data); + +gboolean _bt_reliable_terminate_service(gpointer user_data); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ +#endif /*_BT_SERVICE_MAIN_H_*/ + diff --git a/bt-service-emul/include/bt-service-network.h b/bt-service-emul/include/bt-service-network.h new file mode 100644 index 0000000..45ab52e --- /dev/null +++ b/bt-service-emul/include/bt-service-network.h @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + + +#ifndef _BT_SERVICE_NETWORK_H_ +#define _BT_SERVICE_NETWORK_H_ + +#include +#include +#include "bluetooth-api.h" + +#ifdef __cplusplus +extern "C" { +#endif + +int _bt_network_activate(void); + +int _bt_network_deactivate(void); + +int _bt_network_connect(int request_id, int role, + bluetooth_device_address_t *device_address); + +int _bt_network_disconnect(int request_id, + bluetooth_device_address_t *device_address); + +int _bt_network_server_disconnect(int request_id, + bluetooth_device_address_t *device_address); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ +#endif /*_BT_SERVICE_NETWORK_H_*/ + diff --git a/bt-service-emul/include/bt-service-obex-server.h b/bt-service-emul/include/bt-service-obex-server.h new file mode 100644 index 0000000..65f8f13 --- /dev/null +++ b/bt-service-emul/include/bt-service-obex-server.h @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + + +#ifndef _BT_SERVICE_OBEX_SERVER_H_ +#define _BT_SERVICE_OBEX_SERVER_H_ + +#include +#include +#include "bluetooth-api.h" + +#ifdef __cplusplus +extern "C" { +#endif + +int _bt_obex_server_allocate(char *sender, const char *dest_path, int app_pid, + gboolean is_native); + +int _bt_obex_server_deallocate(int app_pid, gboolean is_native); + +int _bt_obex_server_accept_authorize(const char *filename, gboolean is_native); + +int _bt_obex_server_reject_authorize(void); + +int _bt_obex_server_set_destination_path(const char *dest_path, + gboolean is_native); + +int _bt_obex_server_set_root(const char *root); + +int _bt_obex_server_cancel_transfer(int transfer_id); + +int _bt_obex_server_cancel_all_transfers(void); + +int _bt_obex_server_is_activated(gboolean *activated); + +int _bt_obex_server_check_allocation(gboolean *allocation); + +int _bt_obex_server_check_termination(char *sender); + +int _bt_obex_server_accept_connection(int request_id); + +int _bt_obex_server_reject_connection(void); + +int _bt_obex_server_is_receiving(gboolean *receiving); + +int _bt_obex_get_native_pid(void); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ +#endif /*_BT_SERVICE_OBEX_SERVER_H_*/ + diff --git a/bt-service-emul/include/bt-service-oob.h b/bt-service-emul/include/bt-service-oob.h new file mode 100644 index 0000000..4d3b971 --- /dev/null +++ b/bt-service-emul/include/bt-service-oob.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + + +#ifndef _BT_SERVICE_OOB_H_ +#define _BT_SERVICE_OOB_H_ + +#include +#include +#include "bluetooth-api.h" + +#ifdef __cplusplus +extern "C" { +#endif + +int _bt_oob_read_local_data(bt_oob_data_t *local_oob_data); + +int _bt_oob_add_remote_data( + bluetooth_device_address_t *remote_device_address, + bt_oob_data_t *remote_oob_data); + +int _bt_oob_remove_remote_data( + bluetooth_device_address_t *remote_device_address); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ +#endif /*_BT_SERVICE_OOB_H_*/ + diff --git a/bt-service-emul/include/bt-service-opp-client.h b/bt-service-emul/include/bt-service-opp-client.h new file mode 100644 index 0000000..1b8e187 --- /dev/null +++ b/bt-service-emul/include/bt-service-opp-client.h @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + + +#ifndef _BT_SERVICE_OPP_CLIENT_H_ +#define _BT_SERVICE_OPP_CLIENT_H_ + +#include +#include +#include +#include "bluetooth-api.h" +#include "bt-internal-types.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct { + char path[BT_FILE_PATH_MAX]; +} bt_file_path_t; + +int _bt_opp_client_push_files(int request_id, GDBusMethodInvocation *context, + bluetooth_device_address_t *remote_address, + char **file_path, int file_count); + +int _bt_opp_client_cancel_push(void); + +int _bt_opp_client_cancel_all_transfers(void); + +int _bt_opp_client_is_sending(gboolean *sending); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ +#endif /*_BT_SERVICE_OPP_CLIENT_H_*/ + diff --git a/bt-service-emul/include/bt-service-pbap.h b/bt-service-emul/include/bt-service-pbap.h new file mode 100644 index 0000000..f988769 --- /dev/null +++ b/bt-service-emul/include/bt-service-pbap.h @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#ifndef BT_SERVICE_PBAP_H +#define BT_SERVICE_PBAP_H + +#include +#include +#include +#include +#include + +#undef LOG_TAG +#define LOG_TAG "BLUETOOTH_FRWK_SERVICE" +#define ERR(fmt, args...) SLOGE(fmt, ##args) + +int _bt_pbap_connect(const bluetooth_device_address_t *address); + +int _bt_pbap_disconnect(const bluetooth_device_address_t *address); + +int _bt_pbap_get_phonebook_size(const bluetooth_device_address_t *address, + int source, int type); + +int _bt_pbap_get_phonebook(const bluetooth_device_address_t *address, + int source, int type, bt_pbap_pull_parameters_t *app_param); + +int _bt_pbap_get_list(const bluetooth_device_address_t *address, int source, + int type, bt_pbap_list_parameters_t *app_param); + +int _bt_pbap_pull_vcard(const bluetooth_device_address_t *address, + int source, int type, bt_pbap_pull_vcard_parameters_t *app_param); + +int _bt_pbap_phonebook_search(const bluetooth_device_address_t *address, + int source, int type, bt_pbap_search_parameters_t *app_param); + +#endif diff --git a/bt-service-emul/include/bt-service-rfcomm-client.h b/bt-service-emul/include/bt-service-rfcomm-client.h new file mode 100644 index 0000000..24dceff --- /dev/null +++ b/bt-service-emul/include/bt-service-rfcomm-client.h @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#ifndef _BT_SERVICE_RFCOMM_CLIENT_H_ +#define _BT_SERVICE_RFCOMM_CLIENT_H_ + +#include +#include +#include "bluetooth-api.h" + +#ifdef __cplusplus +extern "C" { +#endif + +int _bt_rfcomm_connect_using_uuid(int request_id, + bluetooth_device_address_t *device_address, + char *remote_uuid); + +int _bt_rfcomm_connect_using_channel(int request_id, + bluetooth_device_address_t *device_address, + char *channel); + +int _bt_rfcomm_disconnect(int socket_fd); + +int _bt_rfcomm_write(int socket_fd, char *buf, int length); + +int _bt_rfcomm_cancel_connect(void); + +int _bt_rfcomm_is_device_connected(bluetooth_device_address_t *device_address, + gboolean *connected); + +int _bt_rfcomm_is_connected(gboolean *connected); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ +#endif /*_BT_SERVICE_RFCOMM_CLIENT_H_*/ + diff --git a/bt-service-emul/include/bt-service-rfcomm-server.h b/bt-service-emul/include/bt-service-rfcomm-server.h new file mode 100644 index 0000000..ea84435 --- /dev/null +++ b/bt-service-emul/include/bt-service-rfcomm-server.h @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#ifndef _BT_SERVICE_RFCOMM_SERVER_H_ +#define _BT_SERVICE_RFCOMM_SERVER_H_ + +#include +#include +#include "bluetooth-api.h" + +#ifdef __cplusplus +extern "C" { +#endif + + +#ifdef __cplusplus +} +#endif /* __cplusplus */ +#endif /*_BT_SERVICE_RFCOMM_SERVER_H_*/ + +int _bt_rfcomm_create_socket(char *sender, char *uuid); + +int _bt_rfcomm_remove_socket(int socket_fd); + +int _bt_rfcomm_listen(int socket_fd, int max_pending, gboolean is_native); + +int _bt_rfcomm_is_uuid_available(char *uuid, gboolean *available); + +int _bt_rfcomm_accept_connection(void); + +int _bt_rfcomm_reject_connection(void); + diff --git a/bt-service-emul/include/bt-service-util.h b/bt-service-emul/include/bt-service-util.h new file mode 100644 index 0000000..edb42b4 --- /dev/null +++ b/bt-service-emul/include/bt-service-util.h @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + + +#ifndef _BT_SERVICE_UTIL_H_ +#define _BT_SERVICE_UTIL_H_ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +#define BT_NODE_NAME_LEN 50 + +typedef struct { + int req_id; + int service_function; + char name[BT_NODE_NAME_LEN]; + GDBusMethodInvocation *context; +} request_info_t; + + +void _bt_init_request_id(void); + +int _bt_assign_request_id(void); + +void _bt_delete_request_id(int request_id); + + +void _bt_init_request_list(void); + +int _bt_insert_request_list(int req_id, int service_function, + char *name, GDBusMethodInvocation *context); + +int _bt_delete_request_list(int req_id); + +request_info_t *_bt_get_request_info(int req_id); + +void _bt_clear_request_list(void); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ +#endif /*_BT_SERVICE_UTIL_H_*/ + diff --git a/bt-service-emul/marshal.list b/bt-service-emul/marshal.list new file mode 100644 index 0000000..96af15b --- /dev/null +++ b/bt-service-emul/marshal.list @@ -0,0 +1,18 @@ +# DBUS Signal argument converting list for bluetooth frwk lib +VOID:STRING +VOID:STRING,UINT,INT +VOID:STRING,STRING +VOID:STRING,STRING,INT +VOID:UINT +VOID:STRING,STRING,INT,UINT +VOID:STRING,VARIANT +# for BlueZ4 +VOID:STRING,BOXED +# for obex +VOID:STRING,STRING,UINT64 +VOID:UINT64 +VOID:STRING,STRING,STRING +# for obexd +VOID:OBJECT,BOOLEAN +VOID:INT,INT + diff --git a/bt-service-emul/mobile/stack_info b/bt-service-emul/mobile/stack_info new file mode 100644 index 0000000..52a9c7a --- /dev/null +++ b/bt-service-emul/mobile/stack_info @@ -0,0 +1,10 @@ +Bluez 5.16, +HFP AG 1.6 +HSP AG 1.2 +A2DP Source 1.2 +AVRCP Target 1.3 +GAVDP 1.2 +OPP 1.1 +PBAP PSE 1.1 +PAN NAP 1.0 +PAN USER 1.0 diff --git a/bt-service-emul/org.projectx.bt.service b/bt-service-emul/org.projectx.bt.service new file mode 100644 index 0000000..7444ab5 --- /dev/null +++ b/bt-service-emul/org.projectx.bt.service @@ -0,0 +1,5 @@ +[D-BUS Service] +Name=org.projectx.bt +Exec=/bin/false +User=root +SystemdService=bluetooth-frwk.service diff --git a/bt-service-emul/wearable/stack_info b/bt-service-emul/wearable/stack_info new file mode 100644 index 0000000..ea7c1ea --- /dev/null +++ b/bt-service-emul/wearable/stack_info @@ -0,0 +1,7 @@ +Bluez 5.16, +HFP 1.6 +HSP AG 1.2 +SPP 1.1 +A2DP Source 1.2 +AVRCP Target 1.3 +GAVDP 1.2 diff --git a/packaging/bluetooth-frwk.spec b/packaging/bluetooth-frwk.spec index 3e64775..a0458cc 100644 --- a/packaging/bluetooth-frwk.spec +++ b/packaging/bluetooth-frwk.spec @@ -154,6 +154,12 @@ export LDFLAGS="$CFLAGS -pie" export CFLAGS="$CFLAGS -DRFCOMM_DIRECT" export LDFLAGS="$CFLAGS -Wl,--rpath=%{_libdir} -Wl,--as-needed -Wl,--unresolved-symbols=ignore-in-shared-libs" +%if "%{?_with_emulator}" == "1" +export CFLAGS="$CFLAGS -DEMUL" +export CXXFLAGS="$CXXFLAGS -DEMUL" +export FFLAGS="$FFLAGS -DEMUL" +%endif + cmake . -DCMAKE_INSTALL_PREFIX=/usr \ -DCMAKE_LIB_DIR=%{_libdir} \ -DTZ_SYS_USER_GROUP=%TZ_SYS_USER_GROUP \