X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=bt-api%2Fbt-adapter.c;h=8dcc4f2c64bfd7169c941e5d60ca32e4ab685192;hb=746add44a75b1d26885dea82fe90652bae4de57c;hp=01acfefa18a73f04ed0d91b007472780bf50ba32;hpb=008772c3a4c662bd78b145032df59153d96517be;p=platform%2Fcore%2Fconnectivity%2Fbluetooth-frwk.git diff --git a/bt-api/bt-adapter.c b/bt-api/bt-adapter.c index 01acfef..8dcc4f2 100644 --- a/bt-api/bt-adapter.c +++ b/bt-api/bt-adapter.c @@ -1,13 +1,11 @@ /* - * bluetooth-frwk - * - * Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. + * 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 + * 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, @@ -17,9 +15,7 @@ * */ - #include -#include #include "bluetooth-api.h" #include "bt-internal-types.h" @@ -38,7 +34,11 @@ static int __bt_fill_device_list(GArray *out_param2, GPtrArray **dev_list) BT_CHECK_PARAMETER(dev_list, return); size = out_param2->len; - retv_if(size == 0, BLUETOOTH_ERROR_NONE); + + if (size == 0) { + BT_ERR("No bonded device"); + return BLUETOOTH_ERROR_NONE; + } size = (out_param2->len) / sizeof(bluetooth_device_info_t); @@ -50,9 +50,8 @@ static int __bt_fill_device_list(GArray *out_param2, GPtrArray **dev_list) dev_info = g_memdup(&info, sizeof(bluetooth_device_info_t)); - if (dev_info) { + if (dev_info) g_ptr_array_add(*dev_list, (gpointer)dev_info); - } } return BLUETOOTH_ERROR_NONE; @@ -60,24 +59,43 @@ static int __bt_fill_device_list(GArray *out_param2, GPtrArray **dev_list) BT_EXPORT_API int bluetooth_check_adapter(void) { + int value = VCONFKEY_BT_STATUS_OFF; + +#ifndef TIZEN_TEST_EMUL int ret; - ret = _bt_get_adapter_path(_bt_get_system_gconn(), NULL); + ret = _bt_get_adapter_path(_bt_gdbus_get_system_gconn(), NULL); + + if (ret != BLUETOOTH_ERROR_NONE) + return BLUETOOTH_ADAPTER_DISABLED; +#endif - return ret == BLUETOOTH_ERROR_NONE ? BLUETOOTH_ADAPTER_ENABLED : - BLUETOOTH_ADAPTER_DISABLED; + /* check VCONFKEY_BT_STATUS */ + if (vconf_get_int(VCONFKEY_BT_STATUS, &value) != 0) { + BT_ERR("fail to get vconf key!"); + return BLUETOOTH_ADAPTER_DISABLED; + } + + return value == VCONFKEY_BT_STATUS_OFF ? BLUETOOTH_ADAPTER_DISABLED : + BLUETOOTH_ADAPTER_ENABLED; } BT_EXPORT_API int bluetooth_enable_adapter(void) { int result; - BT_INIT_PARAMS(); - BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param); - + BT_INFO_C("### Enable adapter"); retv_if(bluetooth_check_adapter() == BLUETOOTH_ADAPTER_ENABLED, BLUETOOTH_ERROR_DEVICE_ALREADY_ENABLED); +#ifdef TIZEN_DPM_VCONF_ENABLE + retv_if(bluetooth_dpm_is_mode_allowed() == BLUETOOTH_DPM_RESULT_ACCESS_DENIED, + BLUETOOTH_ERROR_PERMISSION_DEINED); +#endif + + BT_INIT_PARAMS(); + BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param); + result = _bt_send_request(BT_BLUEZ_SERVICE, BT_ENABLE_ADAPTER, in_param1, in_param2, in_param3, in_param4, &out_param); @@ -90,6 +108,7 @@ BT_EXPORT_API int bluetooth_disable_adapter(void) { int result; + BT_INFO_C("### Disable adapter"); BT_CHECK_ENABLED(return); BT_INIT_PARAMS(); @@ -103,10 +122,29 @@ BT_EXPORT_API int bluetooth_disable_adapter(void) return result; } +BT_EXPORT_API int bluetooth_recover_adapter(void) +{ + int result; + + BT_INFO("Recover adapter"); + BT_CHECK_ENABLED(return); + + BT_INIT_PARAMS(); + BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param); + + result = _bt_send_request(BT_BLUEZ_SERVICE, BT_RECOVER_ADAPTER, + in_param1, in_param2, in_param3, in_param4, &out_param); + + BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param); + + return result; +} + BT_EXPORT_API int bluetooth_reset_adapter(void) { int result; + BT_INFO(""); BT_INIT_PARAMS(); BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param); @@ -123,7 +161,7 @@ BT_EXPORT_API int bluetooth_get_local_address(bluetooth_device_address_t *local_ int result; BT_CHECK_PARAMETER(local_address, return); - BT_CHECK_ENABLED(return); + BT_CHECK_ENABLED_ANY(return); BT_INIT_PARAMS(); BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param); @@ -141,12 +179,33 @@ BT_EXPORT_API int bluetooth_get_local_address(bluetooth_device_address_t *local_ return result; } +BT_EXPORT_API int bluetooth_get_local_version(bluetooth_version_t *local_version) +{ + int result; + + BT_CHECK_PARAMETER(local_version, return); + BT_CHECK_ENABLED_ANY(return); + + BT_INIT_PARAMS(); + BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param); + + result = _bt_send_request(BT_BLUEZ_SERVICE, BT_GET_LOCAL_VERSION, + in_param1, in_param2, in_param3, in_param4, &out_param); + + if (result == BLUETOOTH_ERROR_NONE) + *local_version = g_array_index(out_param, bluetooth_version_t, 0); + + BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param); + + return result; +} + BT_EXPORT_API int bluetooth_get_local_name(bluetooth_device_name_t *local_name) { int result; BT_CHECK_PARAMETER(local_name, return); - BT_CHECK_ENABLED(return); + BT_CHECK_ENABLED_ANY(return); BT_INIT_PARAMS(); BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param); @@ -169,7 +228,7 @@ BT_EXPORT_API int bluetooth_set_local_name(const bluetooth_device_name_t *local_ int result; BT_CHECK_PARAMETER(local_name, return); - BT_CHECK_ENABLED(return); + BT_CHECK_ENABLED_ANY(return); BT_INIT_PARAMS(); BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param); @@ -203,9 +262,8 @@ BT_EXPORT_API int bluetooth_is_service_used(const char *service_uuid, result = _bt_send_request(BT_BLUEZ_SERVICE, BT_IS_SERVICE_USED, in_param1, in_param2, in_param3, in_param4, &out_param); - if (result == BLUETOOTH_ERROR_NONE) { + if (result == BLUETOOTH_ERROR_NONE) *used = g_array_index(out_param, gboolean, 0); - } BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param); @@ -216,25 +274,28 @@ BT_EXPORT_API int bluetooth_get_discoverable_mode(bluetooth_discoverable_mode_t discoverable_mode_ptr) { int result; - int timeout = 0; BT_CHECK_PARAMETER(discoverable_mode_ptr, return); +#ifndef TIZEN_PROFILE_WEARABLE + int timeout = 0; /* Requirement in OSP */ if (bluetooth_check_adapter() == BLUETOOTH_ADAPTER_DISABLED) { if (vconf_get_int(BT_FILE_VISIBLE_TIME, &timeout) != 0) { BT_ERR("Fail to get the timeout value"); - return BLUETOOTH_ERROR_INTERNAL; + return BLUETOOTH_ERROR_DEVICE_NOT_ENABLED; } - if (timeout == -1) { + if (timeout == -1) *discoverable_mode_ptr = BLUETOOTH_DISCOVERABLE_MODE_GENERAL_DISCOVERABLE; - } else { + else *discoverable_mode_ptr = BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE; - } return BLUETOOTH_ERROR_NONE; } +#else + BT_CHECK_ENABLED(return); +#endif BT_INIT_PARAMS(); BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param); @@ -242,10 +303,8 @@ BT_EXPORT_API int bluetooth_get_discoverable_mode(bluetooth_discoverable_mode_t result = _bt_send_request(BT_BLUEZ_SERVICE, BT_GET_DISCOVERABLE_MODE, in_param1, in_param2, in_param3, in_param4, &out_param); - if (result == BLUETOOTH_ERROR_NONE) { - *discoverable_mode_ptr = g_array_index(out_param, - int, 0); - } + if (result == BLUETOOTH_ERROR_NONE) + *discoverable_mode_ptr = g_array_index(out_param, int, 0); BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param); @@ -286,9 +345,8 @@ BT_EXPORT_API int bluetooth_get_timeout_value(int *timeout) result = _bt_send_request(BT_BLUEZ_SERVICE, BT_GET_DISCOVERABLE_TIME, in_param1, in_param2, in_param3, in_param4, &out_param); - if (result == BLUETOOTH_ERROR_NONE) { + if (result == BLUETOOTH_ERROR_NONE) *timeout = g_array_index(out_param, int, 0); - } BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param); @@ -314,6 +372,30 @@ BT_EXPORT_API int bluetooth_start_discovery(unsigned short max_response, return result; } +BT_EXPORT_API int bluetooth_start_custom_discovery(bt_discovery_role_type_t role, + unsigned short max_response, + unsigned short discovery_duration, + unsigned int classOfDeviceMask) +{ + int result; + + if (role == DISCOVERY_ROLE_LE) + BT_CHECK_ENABLED_LE(return); + else + BT_CHECK_ENABLED(return); + + BT_INIT_PARAMS(); + BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param); + + g_array_append_vals(in_param1, &role, sizeof(bt_discovery_role_type_t)); + result = _bt_send_request(BT_BLUEZ_SERVICE, BT_START_CUSTOM_DISCOVERY, + in_param1, in_param2, in_param3, in_param4, &out_param); + + BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param); + + return result; +} + BT_EXPORT_API int bluetooth_cancel_discovery(void) { int result; @@ -350,6 +432,7 @@ BT_EXPORT_API int bluetooth_is_discovering(void) int, 0); } else { BT_ERR("Fail to send request"); + is_discovering = result; } BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param); @@ -357,6 +440,47 @@ BT_EXPORT_API int bluetooth_is_discovering(void) return is_discovering; } +BT_EXPORT_API int bluetooth_is_connectable(gboolean *is_connectable) +{ + int result; + + BT_CHECK_ENABLED_ANY(return); + + BT_INIT_PARAMS(); + BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param); + + result = _bt_send_request(BT_BLUEZ_SERVICE, BT_IS_CONNECTABLE, + in_param1, in_param2, in_param3, in_param4, &out_param); + + if (result == BLUETOOTH_ERROR_NONE) + *is_connectable = g_array_index(out_param, int, 0); + else + BT_ERR("Fail to send request"); + + BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param); + + return result; +} + +BT_EXPORT_API int bluetooth_set_connectable(gboolean is_connectable) +{ + int result; + + BT_CHECK_ENABLED_ANY(return); + + BT_INIT_PARAMS(); + BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param); + + g_array_append_vals(in_param1, &is_connectable, sizeof(gboolean)); + + result = _bt_send_request(BT_BLUEZ_SERVICE, BT_SET_CONNECTABLE, + in_param1, in_param2, in_param3, in_param4, &out_param); + + BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param); + + return result; +} + BT_EXPORT_API int bluetooth_get_bonded_device_list(GPtrArray **dev_list) { int result; @@ -370,8 +494,60 @@ BT_EXPORT_API int bluetooth_get_bonded_device_list(GPtrArray **dev_list) result = _bt_send_request(BT_BLUEZ_SERVICE, BT_GET_BONDED_DEVICES, in_param1, in_param2, in_param3, in_param4, &out_param); - if (result == BLUETOOTH_ERROR_NONE) { + if (result == BLUETOOTH_ERROR_NONE) result = __bt_fill_device_list(out_param, dev_list); + + BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param); + + return result; +} + +BT_EXPORT_API int bluetooth_get_profile_connected_device_list( + const char *profile_uuid, GPtrArray **addr_list) +{ + char uuid[BLUETOOTH_UUID_STRING_MAX]; + int result; + guint size; + int i; + + BT_CHECK_PARAMETER(profile_uuid, return); + BT_CHECK_PARAMETER(addr_list, return); + BT_CHECK_ENABLED(return); + + BT_INIT_PARAMS(); + BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param); + + g_strlcpy(uuid, profile_uuid, sizeof(uuid)); + g_array_append_vals(in_param1, uuid, BLUETOOTH_UUID_STRING_MAX); + + result = _bt_send_request(BT_BLUEZ_SERVICE, BT_GET_PROFILE_CONNECTED_DEVICES, + in_param1, in_param2, in_param3, in_param4, &out_param); + + if (result == BLUETOOTH_ERROR_NONE) { + if (out_param == NULL) { + BT_ERR("out_param is NULL"); + result = BLUETOOTH_ERROR_INTERNAL; + } else { + size = (out_param->len) / sizeof(bluetooth_device_address_t); + + if (size == 0) { + BT_ERR("No connected device"); + result = BLUETOOTH_ERROR_NOT_CONNECTED; + } + + for (i = 0; i < size; i++) { + bluetooth_device_address_t *addr = NULL; + bluetooth_device_address_t *ptr = NULL; + + ptr = &g_array_index(out_param, + bluetooth_device_address_t, i); + + addr = g_memdup(ptr, sizeof(bluetooth_device_address_t)); + + if (addr) + g_ptr_array_add(*addr_list, (gpointer)addr); + } + } } BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param); @@ -379,3 +555,45 @@ BT_EXPORT_API int bluetooth_get_bonded_device_list(GPtrArray **dev_list) return result; } +BT_EXPORT_API int bluetooth_set_manufacturer_data(const bluetooth_manufacturer_data_t *value) +{ + int result; + + BT_CHECK_PARAMETER(value, return); + BT_CHECK_ENABLED_ANY(return); + + if (value->data_len > BLUETOOTH_MANUFACTURER_DATA_LENGTH_MAX) + return BLUETOOTH_ERROR_INVALID_PARAM; + + BT_INIT_PARAMS(); + BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param); + + g_array_append_vals(in_param1, value, sizeof(bluetooth_manufacturer_data_t)); + + result = _bt_send_request(BT_BLUEZ_SERVICE, BT_SET_MANUFACTURER_DATA, + in_param1, in_param2, in_param3, in_param4, &out_param); + + BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param); + + return result; +} + +BT_EXPORT_API int bluetooth_set_passkey_notification(gboolean enable) +{ + int result; + + BT_CHECK_ENABLED_ANY(return); + + BT_INIT_PARAMS(); + BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param); + + g_array_append_vals(in_param1, &enable, sizeof(gboolean)); + + result = _bt_send_request(BT_BLUEZ_SERVICE, BT_SET_PASSKEY_NOTIFICATION, + in_param1, in_param2, in_param3, in_param4, &out_param); + + BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param); + + return result; +} +