X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=bt-api%2Fbt-adapter.c;h=6a0ccb2149897a2a39bdebca0dd9d6971782b7d1;hb=593b79876bfe833f9468521f047933f5efe87746;hp=3da83d43f530b1f5ea3fdd76caad87aaea48271a;hpb=1949924f13f1b9323f90ef6af6e70d87e1663ef7;p=platform%2Fcore%2Fconnectivity%2Fbluetooth-frwk.git diff --git a/bt-api/bt-adapter.c b/bt-api/bt-adapter.c index 3da83d4..6a0ccb2 100644 --- a/bt-api/bt-adapter.c +++ b/bt-api/bt-adapter.c @@ -24,11 +24,16 @@ #include "bt-request-sender.h" #include "bt-event-handler.h" +/* Avoid the build error related to vconf.h's dependency */ +#ifndef VCONFKEY_BATTERY_MONITOR_STATUS +#define VCONFKEY_BATTERY_MONITOR_STATUS "db/bluetooth/bmstatus" +#endif + static int __bt_fill_device_list(GArray *out_param2, GPtrArray **dev_list) { int i; guint size; - bluetooth_device_info_t info; + bluetooth_device_info_t *info; BT_CHECK_PARAMETER(out_param2, return); BT_CHECK_PARAMETER(dev_list, return); @@ -45,14 +50,13 @@ static int __bt_fill_device_list(GArray *out_param2, GPtrArray **dev_list) for (i = 0; i < size; i++) { bluetooth_device_info_t *dev_info = NULL; - info = g_array_index(out_param2, + info = &g_array_index(out_param2, bluetooth_device_info_t, i); - dev_info = g_memdup(&info, sizeof(bluetooth_device_info_t)); + 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,14 +64,16 @@ 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; - int value; - ret = _bt_get_adapter_path(_bt_gdbus_get_system_gconn(), NULL); + ret = _bt_get_adapter_path(_bt_get_system_private_conn(), NULL); - if (ret != BLUETOOTH_ERROR_NONE) { + if (ret != BLUETOOTH_ERROR_NONE) return BLUETOOTH_ADAPTER_DISABLED; - } +#endif /* check VCONFKEY_BT_STATUS */ if (vconf_get_int(VCONFKEY_BT_STATUS, &value) != 0) { @@ -82,26 +88,112 @@ BT_EXPORT_API int bluetooth_check_adapter(void) BT_EXPORT_API int bluetooth_enable_adapter(void) { int result; - bt_user_info_t *user_info; - BT_INFO(""); + BT_INFO_C("### Enable adapter"); + _bt_print_api_caller_name(); 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, +#ifdef TIZEN_FEATURE_BT_DPM + retv_if(bluetooth_dpm_is_mode_allowed() == BLUETOOTH_ERROR_PERMISSION_DEINED, BLUETOOTH_ERROR_PERMISSION_DEINED); #endif - user_info = _bt_get_user_data(BT_COMMON); - retv_if(user_info->cb == NULL, BLUETOOTH_ERROR_INTERNAL); + 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); + + BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param); + + return result; +} + +BT_EXPORT_API int bluetooth_set_battery_monitor_state(bool state) +{ + BT_INFO("Setting vconf key"); + if (vconf_set_bool(VCONFKEY_BATTERY_MONITOR_STATUS, state) != 0) + { + BT_ERR("vconf_set_bool failed"); + return BLUETOOTH_ERROR_INTERNAL; + } + return BLUETOOTH_ERROR_NONE; +} + +BT_EXPORT_API int bluetooth_get_battery_monitor_state() +{ + int state = 0; + BT_INFO("Getting vconf key value"); + if (vconf_get_bool(VCONFKEY_BATTERY_MONITOR_STATUS, &state) != 0) + BT_ERR("vconf_get_bool failed"); + return state; +} + +BT_EXPORT_API int bluetooth_read_battery_data(bt_battery_data *data) +{ + int result; + bt_battery_dbus_data_t *info = NULL; + + BT_CHECK_PARAMETER(data, return); + + BT_INFO("### Requesting battery data"); + retv_if(bluetooth_check_adapter() != BLUETOOTH_ADAPTER_ENABLED, + BLUETOOTH_ADAPTER_DISABLED); + + retv_if(bluetooth_get_battery_monitor_state() == FALSE, + BLUETOOTH_ERROR_NOT_SUPPORT); + +#ifdef TIZEN_FEATURE_BT_DPM + retv_if(bluetooth_dpm_is_mode_allowed() == BLUETOOTH_ERROR_PERMISSION_DEINED, + 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_async(BT_BLUEZ_SERVICE, BT_ENABLE_ADAPTER, - in_param1, in_param2, in_param3, in_param4, - user_info->cb, user_info->user_data); + result = _bt_send_request(BT_BLUEZ_SERVICE, BT_BATTERY_READ_DATA, + in_param1, in_param2, in_param3, in_param4, &out_param); + + if (result != BLUETOOTH_ERROR_NONE) { + BT_ERR("Error encountered"); + BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param); + return result; + } + + info = &g_array_index(out_param, bt_battery_dbus_data_t, 0); + + data->session_start_time = info->session_start_time; + data->session_end_time = info->session_end_time; + data->session_scan_time = info->session_scan_time; + data->session_connected_time = info->session_connected_time; + data->atm_list = NULL; + + BT_DBG("Received battery data in bt-api: %ld %ld %d %d.", + data->session_start_time, data->session_end_time, + data->session_scan_time, data->session_connected_time); + + /*Copying app wise details*/ + int n = NUM_APP_MAX < info->num_app ? NUM_APP_MAX : info->num_app; //Maximum NUM_APP_MAX details will be fetched + + for (int i = 0; i < n; i++) { + bt_battery_app_data *app_data = NULL; + app_data = g_malloc0(sizeof(bt_battery_app_data)); + memcpy(app_data, &(info->app_data[i]), sizeof(bt_battery_app_data)); + data->atm_list = g_slist_append(data->atm_list, app_data); + } + + if (data->atm_list == NULL) { + BT_DBG("No app data transaction in this session"); + BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param); + return result; + } + + BT_DBG("App-wise data transaction details:"); + for (GSList *l = data->atm_list; l != NULL; l = g_slist_next(l)) { + bt_battery_app_data *t = (bt_battery_app_data *)(l->data); + BT_DBG("%ld %ld %d %d %u", (long int)(t->uid), (long int)(t->pid), t->rx_bytes, t->tx_bytes, t->time); + } BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param); @@ -111,20 +203,16 @@ BT_EXPORT_API int bluetooth_enable_adapter(void) BT_EXPORT_API int bluetooth_disable_adapter(void) { int result; - bt_user_info_t *user_info; - BT_INFO(""); + BT_INFO_C("### Disable adapter"); + _bt_print_api_caller_name(); BT_CHECK_ENABLED(return); - user_info = _bt_get_user_data(BT_COMMON); - retv_if(user_info->cb == NULL, BLUETOOTH_ERROR_INTERNAL); - BT_INIT_PARAMS(); BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param); - result = _bt_send_request_async(BT_BLUEZ_SERVICE, BT_DISABLE_ADAPTER, - in_param1, in_param2, in_param3, in_param4, - user_info->cb, user_info->user_data); + result = _bt_send_request(BT_BLUEZ_SERVICE, BT_DISABLE_ADAPTER, + in_param1, in_param2, in_param3, in_param4, &out_param); BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param); @@ -135,7 +223,7 @@ BT_EXPORT_API int bluetooth_recover_adapter(void) { int result; - BT_INFO(""); + BT_INFO_C("### Recover adapter"); BT_CHECK_ENABLED(return); BT_INIT_PARAMS(); @@ -201,9 +289,8 @@ BT_EXPORT_API int bluetooth_get_local_version(bluetooth_version_t *local_version 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) { + 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); @@ -272,9 +359,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); @@ -288,26 +374,25 @@ BT_EXPORT_API int bluetooth_get_discoverable_mode(bluetooth_discoverable_mode_t BT_CHECK_PARAMETER(discoverable_mode_ptr, return); -#ifndef TIZEN_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_DEVICE_NOT_ENABLED; - } - - if (timeout == -1) { - *discoverable_mode_ptr = BLUETOOTH_DISCOVERABLE_MODE_GENERAL_DISCOVERABLE; - } else { - *discoverable_mode_ptr = BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE; + if (!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_DEVICE_NOT_ENABLED; + } + + if (timeout == -1) + *discoverable_mode_ptr = BLUETOOTH_DISCOVERABLE_MODE_GENERAL_DISCOVERABLE; + else + *discoverable_mode_ptr = BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE; + + return BLUETOOTH_ERROR_NONE; } - - return BLUETOOTH_ERROR_NONE; + } else { + BT_CHECK_ENABLED(return); } -#else - BT_CHECK_ENABLED(return); -#endif BT_INIT_PARAMS(); BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param); @@ -315,9 +400,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) { + 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); @@ -358,9 +442,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); @@ -378,6 +461,10 @@ BT_EXPORT_API int bluetooth_start_discovery(unsigned short max_response, BT_INIT_PARAMS(); BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param); + g_array_append_vals(in_param1, &max_response, sizeof(unsigned short)); + g_array_append_vals(in_param2, &discovery_duration, sizeof(unsigned short)); + g_array_append_vals(in_param3, &classOfDeviceMask, sizeof(unsigned int)); + result = _bt_send_request(BT_BLUEZ_SERVICE, BT_START_DISCOVERY, in_param1, in_param2, in_param3, in_param4, &out_param); @@ -446,6 +533,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); @@ -462,14 +550,13 @@ BT_EXPORT_API int bluetooth_is_connectable(gboolean *is_connectable) 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, + result = _bt_send_request(BT_BLUEZ_SERVICE, BT_GET_CONNECTABLE, in_param1, in_param2, in_param3, in_param4, &out_param); - if (result == BLUETOOTH_ERROR_NONE) { + if (result == BLUETOOTH_ERROR_NONE) *is_connectable = g_array_index(out_param, int, 0); - } else { + else BT_ERR("Fail to send request"); - } BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param); @@ -516,6 +603,59 @@ BT_EXPORT_API int bluetooth_get_bonded_device_list(GPtrArray **dev_list) 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); + + return result; +} + BT_EXPORT_API int bluetooth_set_manufacturer_data(const bluetooth_manufacturer_data_t *value) { int result; @@ -538,3 +678,23 @@ BT_EXPORT_API int bluetooth_set_manufacturer_data(const bluetooth_manufacturer_d 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; +} +