From cd3b189f5355ec65adab26fe891463e3fec5b2bf Mon Sep 17 00:00:00 2001 From: Atul Rai Date: Tue, 5 Jul 2016 11:35:46 +0900 Subject: [PATCH] [Adapt] Implement set discoverable mode API This patch adds implementation for following APIs in bluetooth-frwk and OAL: 1/ _bt_get_timeout_value() 2/ _bt_set_discoverable_mode() Change-Id: Iccdac813f37d54299349787f5fb8525d935d0cff Signed-off-by: Atul Rai --- bt-oal/include/oal-adapter-mgr.h | 35 +- bt-oal/oal-adapter-mgr.c | 28 + bt-service-adaptation/CMakeLists.txt | 1 + .../services/adapter/bt-service-core-adapter.c | 223 ++++++- .../services/bt-request-handler.c | 663 +++++++++---------- bt-service-adaptation/services/bt-service-dpm.c | 706 +++++++++++++++++++++ .../services/include/bt-service-core-adapter.h | 4 + .../services/include/bt-service-dpm.h | 163 +++++ 8 files changed, 1497 insertions(+), 326 deletions(-) create mode 100644 bt-service-adaptation/services/bt-service-dpm.c create mode 100644 bt-service-adaptation/services/include/bt-service-dpm.h diff --git a/bt-oal/include/oal-adapter-mgr.h b/bt-oal/include/oal-adapter-mgr.h index 9063d3f..c8c2369 100755 --- a/bt-oal/include/oal-adapter-mgr.h +++ b/bt-oal/include/oal-adapter-mgr.h @@ -207,8 +207,41 @@ oal_status_t adapter_get_bonded_devices(void); */ oal_status_t adapter_set_connectable(int connectable); +/** + * @brief Make adapter discoverable + * + * @remarks This device appears in inquiries and can be connected by remote device. + * + * @details If operation successful OAL_EVENT_ADAPTER_MODE_DISCOVERABLE is generated + * + * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value. + * @retval #OAL_STATUS_SUCCESS Successful + * + * @pre Adapter must be enabled with adapter_enable() followed by OAL_EVENT_ADAPTER_ENABLED + * + * @see adapter_is_discoverable() + * @see OAL_EVENT_ADAPTER_MODE_DISCOVERABLE + */ +oal_status_t adapter_set_discoverable(void); + +/** + * @brief Set discoverable timeout + * + * @param timeout Timeout in seconds after which device cannot be found in discoveries + * + * @details Event OAL_EVENT_ADAPTER_MODE_DISCOVERABLE_TIMEOUT will be generated. + * + * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value. + * @retval #OAL_STATUS_SUCCESS Successful + * + * @pre Adapter must be enabled with adapter_enable() followed by OAL_EVENT_ADAPTER_ENABLED + * + * @see adapter_is_discoverable() + * @see OAL_EVENT_ADAPTER_MODE_DISCOVERABLE_TIMEOUT + */ +oal_status_t adapter_set_discoverable_timeout(int timeout); + #ifdef __cplusplus } #endif /* __cplusplus */ #endif /*_OAL_ADAPTER_MGR_H_*/ - diff --git a/bt-oal/oal-adapter-mgr.c b/bt-oal/oal-adapter-mgr.c index 3b92102..8a4f8fd 100755 --- a/bt-oal/oal-adapter-mgr.c +++ b/bt-oal/oal-adapter-mgr.c @@ -365,6 +365,34 @@ oal_status_t adapter_set_connectable(int connectable) return set_scan_mode(mode); } +oal_status_t adapter_set_discoverable(void) +{ + CHECK_OAL_INITIALIZED(); + API_TRACE(); + + return set_scan_mode(BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE); +} + +oal_status_t adapter_set_discoverable_timeout(int timeout) +{ + bt_property_t prop; + int res; + uint32_t prop_val = timeout; + + CHECK_OAL_INITIALIZED(); + API_TRACE("%d", timeout); + + prop.type = BT_PROPERTY_ADAPTER_DISCOVERY_TIMEOUT; + prop.len = sizeof(prop_val); + prop.val = &prop_val; + res = blued_api->set_adapter_property(&prop); + if (res != BT_STATUS_SUCCESS) { + BT_ERR("set_adapter_property failed [%s]", status2string(res)); + return convert_to_oal_status(res); + } + return OAL_STATUS_SUCCESS; +} + static void cb_adapter_properties(bt_status_t status, int num_properties, bt_property_t *properties) diff --git a/bt-service-adaptation/CMakeLists.txt b/bt-service-adaptation/CMakeLists.txt index 43862d7..822a1be 100644 --- a/bt-service-adaptation/CMakeLists.txt +++ b/bt-service-adaptation/CMakeLists.txt @@ -12,6 +12,7 @@ marshal.c ./services/adapter/bt-service-core-adapter.c ./services/device/bt-service-core-device.c ./services/bt-service-event-receiver.c +./services/bt-service-dpm.c ) IF("${CMAKE_BUILD_TYPE}" STREQUAL "") diff --git a/bt-service-adaptation/services/adapter/bt-service-core-adapter.c b/bt-service-adaptation/services/adapter/bt-service-core-adapter.c index 0ae0938..5c26f54 100644 --- a/bt-service-adaptation/services/adapter/bt-service-core-adapter.c +++ b/bt-service-adaptation/services/adapter/bt-service-core-adapter.c @@ -29,6 +29,8 @@ #include #include +#include "alarm.h" + /*bt-service headers */ #include "bt-internal-types.h" #include "bt-service-common.h" @@ -39,6 +41,9 @@ #include "bt-service-event-receiver.h" #include "bt-request-handler.h" #include "bt-service-event.h" +#ifdef TIZEN_DPM_ENABLE +#include "bt-service-dpm.h" +#endif /* OAL headers */ #include @@ -50,6 +55,16 @@ /*This file will contain state machines related to adapter and remote device */ /* Global variables */ +typedef struct { + guint event_id; + int timeout; + time_t start_time; + gboolean alarm_init; + int alarm_id; +} bt_adapter_timer_t; + +static bt_adapter_timer_t visible_timer; + static guint timer_id = 0; /* Adapter default states */ @@ -218,9 +233,9 @@ int _bt_get_discoverable_mode(int *mode) /* * TODO: NON CONNECTABLE is not defined in bluetooth_discoverable_mode_t. * After adding BLUETOOTH_DISCOVERABLE_MODE_NON_CONNECTABLE, set mode as - * BLUETOOTH_DISCOVERABLE_MODE_NON_CONNECTABLE. Until then return error. + * BLUETOOTH_DISCOVERABLE_MODE_NON_CONNECTABLE. Until then return -1. */ - return BLUETOOTH_ERROR_INTERNAL; + return -1; } } @@ -228,6 +243,210 @@ int _bt_get_discoverable_mode(int *mode) 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; +} + +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; + } +} + +static int __bt_visibility_alarm_cb(alarm_id_t alarm_id, void* user_param) +{ + int result = BLUETOOTH_ERROR_NONE; + int timeout = 0; + + BT_DBG("__bt_visibility_alarm_cb - alram id = [%d] \n", alarm_id); + + 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 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 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 int __bt_set_visible_time(int timeout) +{ + int result; + + __bt_visibility_alarm_remove(); + + visible_timer.timeout = timeout; + +#ifndef TIZEN_WEARABLE +#ifdef TIZEN_DPM_ENABLE + if (_bt_dpm_get_bluetooth_limited_discoverable_state() != DPM_RESTRICTED) { +#endif + if (vconf_set_int(BT_FILE_VISIBLE_TIME, timeout) != 0) + BT_ERR("Set vconf failed"); +#ifdef TIZEN_DPM_ENABLE + } +#endif +#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; +} + +int _bt_set_discoverable_mode(int discoverable_mode, int timeout) +{ + int result; + + BT_DBG("+"); + + BT_INFO("discoverable_mode: %d, timeout: %d", discoverable_mode, timeout); + +#ifdef TIZEN_DPM_ENABLE + if (discoverable_mode != BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE && + _bt_dpm_get_bluetooth_limited_discoverable_state() == DPM_RESTRICTED) { + _bt_launch_dpm_popup("DPM_POLICY_DISABLE_BT_HANDSFREE"); + return BLUETOOTH_ERROR_ACCESS_DENIED; + } + if (discoverable_mode != BLUETOOTH_DISCOVERABLE_MODE_GENERAL_DISCOVERABLE && + _bt_dpm_get_bluetooth_limited_discoverable_state() == DPM_RESTRICTED) { + _bt_launch_dpm_popup("DPM_POLICY_DISABLE_BT"); + return BLUETOOTH_ERROR_ACCESS_DENIED; + } +#endif + + switch (discoverable_mode) { + case BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE: + result = adapter_set_connectable(TRUE); + timeout = 0; + break; + case BLUETOOTH_DISCOVERABLE_MODE_GENERAL_DISCOVERABLE: + result = adapter_set_discoverable(); + timeout = 0; + break; + case BLUETOOTH_DISCOVERABLE_MODE_TIME_LIMITED_DISCOVERABLE: + result = adapter_set_discoverable(); + break; + default: + return BLUETOOTH_ERROR_INVALID_PARAM; + } + + if (result != OAL_STATUS_SUCCESS) { + BT_ERR("set scan mode failed %d", result); + return BLUETOOTH_ERROR_INTERNAL; + } + + result = adapter_set_discoverable_timeout(timeout); + if (result != OAL_STATUS_SUCCESS) { + BT_ERR("adapter_set_discoverable_timeout failed %d", result); + return BLUETOOTH_ERROR_INTERNAL; + } + + if (discoverable_mode == BLUETOOTH_DISCOVERABLE_MODE_GENERAL_DISCOVERABLE) + timeout = -1; + + result = __bt_set_visible_time(timeout); + + BT_DBG("-"); + return result; +} + gboolean _bt_is_connectable(void) { int connectable = 0; diff --git a/bt-service-adaptation/services/bt-request-handler.c b/bt-service-adaptation/services/bt-request-handler.c index c211111..6a62353 100644 --- a/bt-service-adaptation/services/bt-request-handler.c +++ b/bt-service-adaptation/services/bt-request-handler.c @@ -110,7 +110,7 @@ gboolean __bt_service_check_privilege(int function_name, /* Function definitions*/ GSList *_bt_get_invocation_list(void) { - return invocation_list; + return invocation_list; } void _bt_free_info_from_invocation_list(invocation_info_t *req_info) @@ -158,8 +158,8 @@ static gboolean __bt_is_sync_function(int service_function) } void _bt_save_invocation_context(GDBusMethodInvocation *invocation, int result, - char *sender, int service_function, - gpointer invocation_data) + char *sender, int service_function, + gpointer invocation_data) { BT_DBG("Saving the invocation context: service_function [%d]", service_function); invocation_info_t *info; @@ -443,6 +443,23 @@ int __bt_bluez_request(int function_name, g_array_append_vals(*out_param1, &discoverable_mode, sizeof(int)); 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_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_IS_CONNECTABLE: { gboolean is_connectable = FALSE; @@ -582,304 +599,304 @@ 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_HDP_REGISTER_SINK_APP: - case BT_HDP_UNREGISTER_SINK_APP: - - 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; + 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_HDP_REGISTER_SINK_APP: + case BT_HDP_UNREGISTER_SINK_APP: + + 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 @@ -995,43 +1012,43 @@ void _bt_service_unregister(void) int _bt_service_cynara_init(void) { - int result; - char err_msg[256] = {0, }; + int result; + char err_msg[256] = {0, }; - retv_if(p_cynara != NULL, BLUETOOTH_ERROR_ALREADY_INITIALIZED); + retv_if(p_cynara != NULL, BLUETOOTH_ERROR_ALREADY_INITIALIZED); - result = cynara_initialize(&p_cynara, conf); + 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; - } + 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; + return BLUETOOTH_ERROR_NONE; } void _bt_service_cynara_deinit(void) { - int result; - char err_msg[256] = {0, }; + int result; + char err_msg[256] = {0, }; - ret_if(p_cynara == NULL); + ret_if(p_cynara == NULL); - result = cynara_finish(p_cynara); + 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; - } + 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; + p_cynara = NULL; + conf = NULL; } void _bt_service_method_return(GDBusMethodInvocation *invocation, - GArray *out_param, int result) + GArray *out_param, int result) { GVariant *out_var; BT_DBG("+"); diff --git a/bt-service-adaptation/services/bt-service-dpm.c b/bt-service-adaptation/services/bt-service-dpm.c new file mode 100644 index 0000000..ddb0b9e --- /dev/null +++ b/bt-service-adaptation/services/bt-service-dpm.c @@ -0,0 +1,706 @@ +/* + * 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 + +#include "bluetooth-api.h" +#include "bt-internal-types.h" + +#include "bt-service-common.h" +#include "bt-service-core-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}, +}; + +int _bt_launch_dpm_popup(char *mode) +{ + int ret = 0; + bundle *b; + + b = bundle_create(); + retv_if(b == NULL, BLUETOOTH_ERROR_INTERNAL); + + bundle_add(b, "mode", mode); + + ret = syspopup_launch(BT_DPM_SYSPOPUP, b); + + if (ret < 0) + BT_ERR("Popup launch failed: %d\n", ret); + + bundle_free(b); + + return ret; +} + +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-adaptation/services/include/bt-service-core-adapter.h b/bt-service-adaptation/services/include/bt-service-core-adapter.h index 6dc516f..f72bd62 100755 --- a/bt-service-adaptation/services/include/bt-service-core-adapter.h +++ b/bt-service-adaptation/services/include/bt-service-core-adapter.h @@ -63,6 +63,10 @@ int _bt_set_local_name(char *local_name); int _bt_get_discoverable_mode(int *mode); +int _bt_get_timeout_value(int *timeout); + +int _bt_set_discoverable_mode(int discoverable_mode, int timeout); + gboolean _bt_is_connectable(void); int _bt_is_service_used(void); diff --git a/bt-service-adaptation/services/include/bt-service-dpm.h b/bt-service-adaptation/services/include/bt-service-dpm.h new file mode 100644 index 0000000..bdac494 --- /dev/null +++ b/bt-service-adaptation/services/include/bt-service-dpm.h @@ -0,0 +1,163 @@ +/* + * 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; + +int _bt_launch_dpm_popup(char *mode); +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 */ + -- 2.7.4