X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=bt-service%2Fbt-service-device.c;h=83c358a3e9f2e0125932af5872feaa4abd77a7fc;hb=d3f64e9c21a3743c3b8fb36e4524a030945e3333;hp=d2f939c45e7087103cc2383b9b592b8b4e225cea;hpb=d925e8ae132cfc9edd08f1f615d4ceb1a78b8905;p=platform%2Fcore%2Fconnectivity%2Fbluetooth-frwk.git diff --git a/bt-service/bt-service-device.c b/bt-service/bt-service-device.c index d2f939c..83c358a 100644 --- a/bt-service/bt-service-device.c +++ b/bt-service/bt-service-device.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include @@ -36,7 +37,6 @@ #include "bt-service-network.h" #include "bt-service-adapter.h" #include "bt-service-gap-agent.h" -#include "bt-service-pbap.h" #define BT_SYSPOPUP_IPC_RESPONSE_OBJECT "/org/projectx/bt_syspopup_res" #define BT_SYSPOPUP_INTERFACE "User.Bluetooth.syspopup" @@ -66,9 +66,6 @@ #define BT_LE_CONN_PARAM_LOW_POWER_SLAVE_LATENCY 2 /* event */ #define PROFILE_SUPPORTED 0x3 /* This corresponds to binary 0b11*/ -#define PROFILE_TRUSTED 0x2 /* This corresponds to binary 0b10*/ -#define PROFILE_BLOCKED 0x1 /* This corresponds to binary 0b01*/ -#define PROFILE_SHOW_AUTH 0x0 /* This corresponds to binary 0b00*/ typedef struct { int req_id; @@ -125,9 +122,6 @@ static guint pending_le_conn_timer_id = 0; static void __bt_bond_device_cb(GDBusProxy *proxy, GAsyncResult *res, gpointer user_data); -static int __bt_retry_bond(void); - - /*static void __bt_decline_pair_request() { GVariant *out_param1; @@ -211,6 +205,63 @@ done: BT_DBG("-"); } */ +#ifdef TIZEN_PROFILE_WEARABLE +static gboolean __bt_syspopup_timer_cb(gpointer user_data) +{ + int ret; + bundle *b; + retv_if(user_data == NULL, FALSE); + + b = (bundle *)user_data; + + ret = syspopup_launch("bt-syspopup", b); + if (ret < 0) { + BT_ERR("Sorry!! Cannot launch popup return = %d, Retrying...", ret); + } else { + BT_DBG("Hurray!!! Finally Popup launched"); + bundle_free(b); + } + return (ret < 0) ? TRUE : FALSE; +} + +static gboolean __bt_launch_unable_to_pairing_syspopup(int result) +{ + BT_DBG("+"); + int ret = 0; + bundle *b = NULL; + GDBusConnection *conn; + + conn = _bt_gdbus_get_system_gconn(); + if (conn == NULL) + return FALSE; + + b = bundle_create(); + if (b == NULL) + return FALSE; + + bundle_add(b, "event-type", "unable-to-pairing"); + + if (result == BLUETOOTH_ERROR_TIMEOUT) + bundle_add(b, "error", "timeout"); + else if (result == BLUETOOTH_ERROR_AUTHENTICATION_FAILED) + bundle_add(b, "error", "authfailed"); + else + bundle_add(b, "error", "error"); + + ret = syspopup_launch("bt-syspopup", b); + if (0 > ret) { + BT_ERR("Popup launch failed...retry %d \n", ret); + g_timeout_add(200, (GSourceFunc) __bt_syspopup_timer_cb, + b); + } else { + bundle_free(b); + } + + BT_DBG("-"); + return TRUE; +} +#endif + gboolean _bt_is_device_creating(void) { return is_device_creating; @@ -279,12 +330,8 @@ static void __bt_get_uuids(GVariant *value, bt_remote_dev_info_t *info) ret_if(value == NULL); ret_if(info == NULL); - gsize uuid_count = 0; - - info->uuids = g_variant_dup_strv(value, &uuid_count); - info->uuid_count = (unsigned int)uuid_count; - - BT_DBG("uuid count : %d", uuid_count); + info->uuid_count = g_variant_get_size(value); + info->uuids = g_variant_dup_strv(value, &info->uuid_count); } bt_remote_dev_info_t *_bt_get_remote_device_info(char *address) @@ -422,7 +469,7 @@ bt_remote_dev_info_t *_bt_get_remote_device_info_by_object_path( g_variant_unref(tmp_value); } - tmp_value = g_variant_lookup_value(value, "ManufacturerDataLen", G_VARIANT_TYPE_UINT16); + tmp_value = g_variant_lookup_value(value, "LegacyManufacturerDataLen", G_VARIANT_TYPE_UINT16); if (tmp_value) { dev_info->manufacturer_data_len = g_variant_get_uint16(tmp_value); if (dev_info->manufacturer_data_len > BLUETOOTH_MANUFACTURER_DATA_LENGTH_MAX) { @@ -433,7 +480,7 @@ bt_remote_dev_info_t *_bt_get_remote_device_info_by_object_path( } else dev_info->manufacturer_data_len = 0; - tmp_value = g_variant_lookup_value(value, "ManufacturerData", G_VARIANT_TYPE_ARRAY); + tmp_value = g_variant_lookup_value(value, "LegacyManufacturerData", G_VARIANT_TYPE_ARRAY); if (tmp_value) { if ((dev_info->manufacturer_data_len == 0) || dev_info->manufacturer_data_len != g_variant_get_size(tmp_value)) { @@ -445,6 +492,8 @@ bt_remote_dev_info_t *_bt_get_remote_device_info_by_object_path( g_variant_get(tmp_value, "ay", &value_iter); while (g_variant_iter_loop(value_iter, "y", &m_value)) dev_info->manufacturer_data[i++] = m_value; + + g_variant_iter_free(value_iter); } g_variant_unref(tmp_value); } else { @@ -457,9 +506,8 @@ bt_remote_dev_info_t *_bt_get_remote_device_info_by_object_path( g_variant_get(tmp_value, "s", &address); g_variant_unref(tmp_value); - dev_info->address = g_strdup(address); - dev_info->name = g_strdup(name); - g_free(name); + dev_info->address = address; + dev_info->name = name; g_variant_unref(value); } else { BT_ERR("result is NULL\n"); @@ -630,93 +678,23 @@ static int __bt_cancel_bonding(void) /* First Cancel the ongoing pairing in bluez otherwise if we send * pair request bluez will send inprogress and we again retry bond so * this cycle continues */ - GError *err = NULL; - g_dbus_proxy_call_sync(bonding_info->device_proxy, "CancelPairing", + GError *err = NULL; + GVariant *result; + result = g_dbus_proxy_call_sync(bonding_info->device_proxy, "CancelPairing", NULL, G_DBUS_CALL_FLAGS_NONE, 10000, NULL, &err); - if (err) { - BT_ERR("Cancelling bonding request error msg (%s)", err->message); - g_clear_error(&err); - return BLUETOOTH_ERROR_PARING_FAILED; + if (!result) { + if (err) { + BT_ERR("Cancelling bonding request error msg (%s)", err->message); + g_clear_error(&err); + return BLUETOOTH_ERROR_PARING_FAILED; + } + } else { + g_variant_unref(result); } return BLUETOOTH_ERROR_NONE; } -static int __bt_retry_bond(void) -{ - BT_CHECK_PARAMETER(bonding_info, return); - BT_CHECK_PARAMETER(bonding_info->addr, return); - - is_device_creating = TRUE; - - g_dbus_proxy_call(bonding_info->device_proxy, "Pair", - g_variant_new("(y)", bonding_info->conn_type), - G_DBUS_CALL_FLAGS_NONE, - BT_MAX_DBUS_TIMEOUT, - NULL, - (GAsyncReadyCallback)__bt_bond_device_cb, - NULL); - - return BLUETOOTH_ERROR_NONE; -} - - -static int __bt_remove_and_bond(void) -{ - GDBusProxy *adapter_proxy; - GVariant *result = NULL; - GError *err = NULL; - char *device_path = NULL; - - BT_CHECK_PARAMETER(bonding_info, return); - BT_CHECK_PARAMETER(bonding_info->addr, return); - - adapter_proxy = _bt_get_adapter_proxy(); - retv_if(adapter_proxy == NULL, BLUETOOTH_ERROR_INTERNAL); - - result = g_dbus_proxy_call_sync(adapter_proxy, "FindDevice", - g_variant_new("(s)", bonding_info->addr), - G_DBUS_CALL_FLAGS_NONE, - -1, - NULL, - NULL); - if (result == NULL) - return BLUETOOTH_ERROR_INTERNAL; - - g_variant_get(result , "(o)", &device_path); - g_variant_unref(result); - - retv_if(device_path == NULL, BLUETOOTH_ERROR_INTERNAL); - - result = g_dbus_proxy_call_sync(adapter_proxy, "UnpairDevice", - g_variant_new("(o)", device_path), - G_DBUS_CALL_FLAGS_NONE, - -1, - NULL, - &err); - g_free(device_path); - if (err != NULL) { - BT_ERR("UnpairDevice Fail: %s", err->message); - g_error_free(err); - return BLUETOOTH_ERROR_INTERNAL; - } - - return __bt_retry_bond(); -} - -static int __bt_cancel_and_bond(void) -{ - int ret = BLUETOOTH_ERROR_NONE; - - ret = _bt_agent_reply_cancellation(); - if (ret != BLUETOOTH_ERROR_NONE) { - BT_ERR("Fail to call reply cancellation"); - return ret; - } - return __bt_retry_bond(); -} - - static void __bt_bond_device_cb(GDBusProxy *proxy, GAsyncResult *res, gpointer user_data) { @@ -726,13 +704,9 @@ static void __bt_bond_device_cb(GDBusProxy *proxy, GAsyncResult *res, GVariant *out_param1; request_info_t *req_info; bluetooth_device_info_t dev_info; - bt_remote_dev_info_t *remote_dev_info; - GVariant *manufacture_data; - GVariant *param; /* Terminate ALL system popup */ - if (headed_plugin_info->plugin_headed_enabled) - headed_plugin_info->headed_plugin->bt_destroy_popup_all(); + syspopup_destroy_all(); reply = g_dbus_proxy_call_finish(proxy, res, &err); if (reply) @@ -759,10 +733,8 @@ static void __bt_bond_device_cb(GDBusProxy *proxy, GAsyncResult *res, BT_ERR("Error occured in CreateBonding [%s]", err->message); if (g_strrstr(err->message, "Already Exists")) { - BT_INFO("Existing Bond, remove and retry"); - ret_if(__bt_remove_and_bond() == BLUETOOTH_ERROR_NONE); - - result = BLUETOOTH_ERROR_PARING_FAILED; + BT_INFO("Existing Bond"); + result = BLUETOOTH_ERROR_ALREADY_CONNECT; } else if (_bt_agent_is_canceled() || g_strrstr(err->message, "Authentication Canceled")) { BT_INFO("Cancelled by USER"); @@ -771,10 +743,8 @@ static void __bt_bond_device_cb(GDBusProxy *proxy, GAsyncResult *res, BT_INFO("REJECTED"); result = BLUETOOTH_ERROR_ACCESS_DENIED; } else if (g_strrstr(err->message, "In Progress")) { - BT_INFO("Bond in progress, cancel and retry"); - ret_if(__bt_cancel_and_bond() == BLUETOOTH_ERROR_NONE); - - result = BLUETOOTH_ERROR_PARING_FAILED; + BT_INFO("Bond in progress"); + result = BLUETOOTH_ERROR_IN_PROGRESS; } else if (g_strrstr(err->message, "Authentication Failed")) { BT_INFO("Authentication Failed"); if (bonding_info->is_autopair == TRUE) { @@ -813,19 +783,17 @@ static void __bt_bond_device_cb(GDBusProxy *proxy, GAsyncResult *res, result == BLUETOOTH_ERROR_AUTHENTICATION_FAILED || result == BLUETOOTH_ERROR_TIMEOUT || result == BLUETOOTH_ERROR_HOST_DOWN) { - if (TIZEN_PROFILE_WEARABLE) { - int is_sw_running = 0; +#ifdef TIZEN_PROFILE_WEARABLE + int is_sw_running = 0; - if (vconf_get_int(VCONFKEY_SETUP_WIZARD_STATE, &is_sw_running)) - BT_ERR("vconf_get_int for setup wizard state failed"); + if (vconf_get_int(VCONFKEY_SETUP_WIZARD_STATE, &is_sw_running)) + BT_ERR("vconf_get_int for setup wizard state failed"); - if (!is_sw_running) { - if (headed_plugin_info->plugin_headed_enabled) - headed_plugin_info->headed_plugin->bt_launch_unable_to_pairing_syspopup(result); - } else { - BT_ERR("Unable to pair"); - } - } + if (!is_sw_running) + __bt_launch_unable_to_pairing_syspopup(result); + else + BT_ERR("Unable to pair"); +#endif bonding_info->result = result; } @@ -872,45 +840,6 @@ static void __bt_bond_device_cb(GDBusProxy *proxy, GAsyncResult *res, goto dbus_return; } - remote_dev_info = _bt_get_remote_device_info(bonding_info->addr); - if (!remote_dev_info) - goto dbus_return; - - GVariant *uuids = NULL; - GVariantBuilder *builder = NULL; - int i = 0; - builder = g_variant_builder_new(G_VARIANT_TYPE("as")); - for (i = 0; i < remote_dev_info->uuid_count; i++) { - g_variant_builder_add(builder, "s", - remote_dev_info->uuids[i]); - } - uuids = g_variant_new("as", builder); - g_variant_builder_unref(builder); - manufacture_data = g_variant_new_from_data((const GVariantType *)"ay", - remote_dev_info->manufacturer_data, remote_dev_info->manufacturer_data_len, - TRUE, NULL, NULL); - - param = g_variant_new("(isunsbub@asn@ay)", - result, - bonding_info->addr, - remote_dev_info->class, - remote_dev_info->rssi, - remote_dev_info->name, - remote_dev_info->paired, - remote_dev_info->connected, - remote_dev_info->trust, - uuids, - remote_dev_info->manufacturer_data_len, - manufacture_data); - - - /* Send the event to application */ - _bt_send_event(BT_ADAPTER_EVENT, - BLUETOOTH_EVENT_BONDING_FINISHED, - param); - - _bt_free_device_info(remote_dev_info); - dbus_return: if (req_info->context == NULL) goto done; @@ -928,6 +857,8 @@ dbus_return: g_dbus_method_invocation_return_value(req_info->context, g_variant_new("(iv)", result, out_param1)); + g_variant_unref(out_param1); + _bt_delete_request_list(req_info->req_id); done: if (err) @@ -1731,12 +1662,8 @@ int _bt_is_device_connected(bluetooth_device_address_t *device_address, BT_DBG("uuid %s [%s]", uuid, _bt_convert_uuid_to_string(uuid)); object_path = _bt_get_device_object_path(address); - if (!object_path) { - BT_ERR("object_path is NULL"); - g_free(uuid); - return BLUETOOTH_ERROR_NOT_PAIRED; - } - + retv_if(object_path == NULL, BLUETOOTH_ERROR_NOT_PAIRED); + BT_DBG("object_path: %s", object_path); device_proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE, NULL, BT_BLUEZ_NAME, object_path, BT_DEVICE_INTERFACE, NULL, NULL); @@ -1953,41 +1880,14 @@ fail: static gboolean __bt_connect_le_timer_cb(gpointer user_data) { - int ret; - BT_INFO("Try to initiate pending LE connection"); pending_le_conn_timer_id = 0; - ret = __bt_connect_le_device_internal(pending_le_conn_info->req_id, - &pending_le_conn_info->bd_addr, - pending_le_conn_info->auto_connect); - if (ret != BLUETOOTH_ERROR_NONE) { - request_info_t *req_info = NULL; - GVariant *out_param1; - - req_info = _bt_get_request_info(pending_le_conn_info->req_id); - if (req_info == NULL) { - BT_ERR("req_info is NULL"); - goto done; - } - - if (req_info->context == NULL) { - BT_ERR("req_info->context is NULL"); - _bt_delete_request_list(req_info->req_id); - goto done; - } - - out_param1 = g_variant_new_from_data((const GVariantType *)"ay", - &pending_le_conn_info->bd_addr, - sizeof(bluetooth_device_address_t), TRUE, - NULL, NULL); + __bt_connect_le_device_internal(pending_le_conn_info->req_id, + &pending_le_conn_info->bd_addr, + pending_le_conn_info->auto_connect); - g_dbus_method_invocation_return_value(req_info->context, - g_variant_new("(iv)", ret, out_param1)); - } - -done: g_free(pending_le_conn_info); pending_le_conn_info = NULL; @@ -2102,6 +2002,7 @@ int _bt_connect_le_ipsp_device(const bluetooth_device_address_t *bd_addr) GDBusProxy *adapter_proxy; GDBusConnection *conn; int ret = BLUETOOTH_ERROR_NONE; + GVariant *result; BT_CHECK_PARAMETER(bd_addr, return); @@ -2129,29 +2030,24 @@ int _bt_connect_le_ipsp_device(const bluetooth_device_address_t *bd_addr) g_free(device_path); retv_if(device_proxy == NULL, BLUETOOTH_ERROR_INTERNAL); - g_dbus_proxy_call_sync(device_proxy, "ConnectIpsp", + result = g_dbus_proxy_call_sync(device_proxy, "ConnectIpsp", NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); - if (error) { - BT_ERR("ConnectIpsp Call Error %s[%s]", error->message, device_address); - g_error_free(error); - g_object_unref(device_proxy); - return BLUETOOTH_ERROR_INTERNAL; + if (!result) { + if (error) { + BT_ERR("ConnectIpsp Call Error %s[%s]", error->message, device_address); + g_error_free(error); + g_object_unref(device_proxy); + return BLUETOOTH_ERROR_INTERNAL; + } + } else { + g_variant_unref(result); } - g_object_unref(device_proxy); - - /* IPSP daemon launch */ - GDBusProxy *ipsp_proxy; - ipsp_proxy = _bt_get_ipsp_proxy(); - retv_if(ipsp_proxy == NULL, BLUETOOTH_ERROR_INTERNAL); - - g_dbus_proxy_call(ipsp_proxy, "EnableIpsp", - NULL, G_DBUS_CALL_FLAGS_NONE, - -1, NULL, NULL, NULL); + g_object_unref(device_proxy); return ret; } @@ -2165,6 +2061,7 @@ int _bt_disconnect_le_ipsp_device(const bluetooth_device_address_t *bd_addr) GDBusProxy *adapter_proxy; GDBusConnection *conn; int ret = BLUETOOTH_ERROR_NONE; + GVariant *result; BT_CHECK_PARAMETER(bd_addr, return); @@ -2192,17 +2089,21 @@ int _bt_disconnect_le_ipsp_device(const bluetooth_device_address_t *bd_addr) g_free(device_path); retv_if(device_proxy == NULL, BLUETOOTH_ERROR_INTERNAL); - g_dbus_proxy_call_sync(device_proxy, "DisconnectIpsp", + result = g_dbus_proxy_call_sync(device_proxy, "DisconnectIpsp", NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); - if (error) { - BT_ERR("DisconnectIpsp Call Error %s[%s]", error->message, device_address); - g_error_free(error); - g_object_unref(device_proxy); - return BLUETOOTH_ERROR_INTERNAL; + if (!result) { + if (error) { + BT_ERR("DisconnectIpsp Call Error %s[%s]", error->message, device_address); + g_error_free(error); + g_object_unref(device_proxy); + return BLUETOOTH_ERROR_INTERNAL; + } + } else { + g_variant_unref(result); } g_object_unref(device_proxy); @@ -2711,7 +2612,7 @@ int _bt_le_conn_update(const char *sender, BT_CHECK_PARAMETER(device_address, return); - BT_INFO("Sender %s, Min interval: %f, Max interval: %f, Latency: %u, Supervision timeout: %u", + BT_DBG("Sender %s, Min interval: %f, Max interval: %f, Latency: %u, Supervision timeout: %u", sender, interval_min, interval_max, latency, time_out); if (interval_min > interval_max || @@ -2914,7 +2815,7 @@ int _bt_get_le_connection_parameter(bluetooth_le_connection_mode_t mode, int _bt_get_trusted_profile_from_flag(bluetooth_trusted_profile_t profile, guint trusted_profile_flag, guint *trusted) { - int trust_profile = FALSE; + int trust_profile; *trusted = FALSE; switch (profile) { @@ -2936,24 +2837,6 @@ int _bt_get_trusted_profile_from_flag(bluetooth_trusted_profile_t profile, else return BLUETOOTH_ERROR_NOT_SUPPORT; break; - case TRUSTED_PROFILE_HFP_HF: { - guint flag = (trusted_profile_flag & (PROFILE_SUPPORTED << 6)) >> 6; - BT_DBG("trusted_profile_flag %x", trusted_profile_flag); - if (flag != PROFILE_BLOCKED) - trust_profile = TRUE; - else - *trusted = FALSE; - break; - } - case TRUSTED_PROFILE_A2DP: { - guint flag = (trusted_profile_flag & (PROFILE_SUPPORTED << 8)) >> 8; - BT_DBG("trusted_profile_flag %x", trusted_profile_flag); - if (flag != PROFILE_BLOCKED) - trust_profile = TRUE; - else - *trusted = FALSE; - break; - } case TRUSTED_PROFILE_ALL: /* Return Flag for All profiles*/ *trusted = trusted_profile_flag; return BLUETOOTH_ERROR_NONE; @@ -2967,6 +2850,29 @@ int _bt_get_trusted_profile_from_flag(bluetooth_trusted_profile_t profile, return BLUETOOTH_ERROR_NONE; } +int _bt_get_restricted_profile_from_flag(bluetooth_restricted_profile_t profile, + guint restricted_profile_flag, guint *restricted) +{ + int restrict_profile; + *restricted = FALSE; + + switch (profile) { + case RESTRICTED_PROFILE_HFP_HS: + restrict_profile = restricted_profile_flag & (1 << 0); + break; + case RESTRICTED_PROFILE_A2DP: + restrict_profile = restricted_profile_flag & (1 << 2); + break; + default: + return BLUETOOTH_ERROR_NOT_SUPPORT; + } + + if (restrict_profile) + *restricted = TRUE; + + return BLUETOOTH_ERROR_NONE; +} + char *_bt_get_trusted_profile_uuid(bluetooth_trusted_profile_t profile) { switch (profile) { @@ -2976,10 +2882,6 @@ char *_bt_get_trusted_profile_uuid(bluetooth_trusted_profile_t profile) return g_strdup("00001134-0000-1000-8000-00805f9b34fb"); case TRUSTED_PROFILE_SAP: return g_strdup("0000112D-0000-1000-8000-00805f9b34fb"); - case TRUSTED_PROFILE_HFP_HF: - return g_strdup("0000111e-0000-1000-8000-00805f9b34fb"); - case TRUSTED_PROFILE_A2DP: - return g_strdup("0000110b-0000-1000-8000-00805f9b34fb"); case TRUSTED_PROFILE_ALL: return NULL; } @@ -2987,6 +2889,18 @@ char *_bt_get_trusted_profile_uuid(bluetooth_trusted_profile_t profile) return NULL; } +char *_bt_get_restricted_profile_uuid(bluetooth_restricted_profile_t profile) +{ + switch (profile) { + case RESTRICTED_PROFILE_HFP_HS: + return g_strdup("0000111e-0000-1000-8000-00805f9b34fb"); + case RESTRICTED_PROFILE_A2DP: + return g_strdup("0000110b-0000-1000-8000-00805f9b34fb"); + } + + return NULL; +} + bluetooth_trusted_profile_t _bt_get_trusted_profile_enum(const char *uuid) { if (g_strcmp0("0000112f-0000-1000-8000-00805f9b34fb", uuid) == 0) @@ -3125,6 +3039,132 @@ int _bt_get_trust_profile(bluetooth_device_address_t *bd_addr, return ret; } +int _bt_set_restrict_profile(bluetooth_device_address_t *bd_addr, + bluetooth_restricted_profile_t profile, gboolean restricted) +{ + int ret = BLUETOOTH_ERROR_NONE; + GDBusConnection *conn; + GDBusProxy *proxy; + GError *error = NULL; + char *device_path = NULL; + char *uuid = NULL; + char address[BT_ADDRESS_STRING_SIZE] = { 0 }; + GVariant *reply; + + BT_CHECK_PARAMETER(bd_addr, return); + BT_DBG("BD Address [%2.2X %2.2X %2.2X %2.2X %2.2X %2.2X] profile[%d] restricted[%d]", + bd_addr->addr[0], bd_addr->addr[1], + bd_addr->addr[2], bd_addr->addr[3], + bd_addr->addr[4], bd_addr->addr[5], + profile, restricted); + + conn = _bt_gdbus_get_system_gconn(); + retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL); + + _bt_convert_addr_type_to_string(address, bd_addr->addr); + + device_path = _bt_get_device_object_path(address); + retv_if(device_path == NULL, BLUETOOTH_ERROR_INTERNAL); + + proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE, + NULL, BT_BLUEZ_NAME, device_path, + BT_DEVICE_INTERFACE, NULL, NULL); + + g_free(device_path); + retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL); + + uuid = _bt_get_restricted_profile_uuid(profile); + if (uuid == NULL) { + g_object_unref(proxy); + return BLUETOOTH_ERROR_NOT_SUPPORT; + } + + reply = g_dbus_proxy_call_sync(proxy, "SetRestrictedProfile", + g_variant_new("(sb)", uuid, restricted), + G_DBUS_CALL_FLAGS_NONE, -1, + NULL, &error); + g_object_unref(proxy); + + if (reply == NULL) { + BT_ERR("Failed to Set Profile Restricted"); + ret = BLUETOOTH_ERROR_INTERNAL; + if (error) { + BT_ERR("Error %s[%s]", error->message, address); + g_error_free(error); + } + goto finish; + } + g_variant_unref(reply); + +finish: + g_free(uuid); + return ret; +} + +int _bt_get_restrict_profile(bluetooth_device_address_t *bd_addr, + bluetooth_restricted_profile_t profile, guint *restricted) +{ + int ret = BLUETOOTH_ERROR_NONE; + GDBusConnection *conn; + GDBusProxy *proxy; + GError *error = NULL; + char *device_path = NULL; + guint restricted_profile_flag; + char address[BT_ADDRESS_STRING_SIZE] = { 0 }; + GVariant *reply; + + BT_CHECK_PARAMETER(bd_addr, return); + BT_DBG("BD Address [%2.2X %2.2X %2.2X %2.2X %2.2X %2.2X] profile[%d] restricted[%d]", + bd_addr->addr[0], bd_addr->addr[1], + bd_addr->addr[2], bd_addr->addr[3], + bd_addr->addr[4], bd_addr->addr[5], + profile, *restricted); + + conn = _bt_gdbus_get_system_gconn(); + retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL); + + _bt_convert_addr_type_to_string(address, bd_addr->addr); + + device_path = _bt_get_device_object_path(address); + retv_if(device_path == NULL, BLUETOOTH_ERROR_INTERNAL); + + proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE, + NULL, BT_BLUEZ_NAME, device_path, + BT_PROPERTIES_INTERFACE, NULL, NULL); + + g_free(device_path); + retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL); + + reply = g_dbus_proxy_call_sync(proxy, "Get", + g_variant_new("(ss)", BT_DEVICE_INTERFACE, "RestrictedProfiles"), + G_DBUS_CALL_FLAGS_NONE, -1, + NULL, &error); + g_object_unref(proxy); + + if (reply == NULL) { + BT_ERR("Failed to Get Profile Restricted"); + ret = BLUETOOTH_ERROR_INTERNAL; + if (error) { + BT_ERR("Error %s[%s]", error->message, address); + g_error_free(error); + } + *restricted = 0; + } else { + GVariant *temp; + g_variant_get(reply, "(v)", &temp); + restricted_profile_flag = g_variant_get_uint32(temp); + BT_DBG("Restricted_FLAG %d", restricted_profile_flag); + + ret = _bt_get_restricted_profile_from_flag(profile, + restricted_profile_flag, restricted); + g_variant_unref(temp); + g_variant_unref(reply); + } + + BT_DBG("TRUST %d", *restricted); + return ret; +} + static void __bt_request_att_mtu_device_cb(GDBusProxy *proxy, GAsyncResult *res, gpointer user_data) { @@ -3310,6 +3350,11 @@ int _bt_get_att_mtu(bluetooth_device_address_t *device_address, BT_DBG("ATT MTU : %d", *mtu); g_variant_unref(value); g_variant_unref(result); + + if (*mtu == 0) { + g_object_unref(device_proxy); + return BLUETOOTH_ERROR_NOT_CONNECTED; + } } g_object_unref(device_proxy); @@ -3339,47 +3384,37 @@ int _bt_get_device_ida(bluetooth_device_address_t *device_address, retv_if(device_path == NULL, BLUETOOTH_ERROR_NOT_PAIRED); device_proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE, - NULL, BT_BLUEZ_NAME, - device_path, BT_DEVICE_INTERFACE, NULL, NULL); + NULL, BT_BLUEZ_NAME, + device_path, BT_DEVICE_INTERFACE, NULL, NULL); g_free(device_path); if (!device_proxy) { BT_ERR("Unable to get proxy"); return BLUETOOTH_ERROR_INTERNAL; } - result = g_dbus_proxy_call_sync(device_proxy, "GetIDAddress", - NULL, - G_DBUS_CALL_FLAGS_NONE, - -1, - NULL, - &error); - + result = g_dbus_proxy_call_sync(device_proxy, "GetIDAddress", NULL, + G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); if (result == NULL) { BT_ERR("Failed to get device ID address"); + + ret = BLUETOOTH_ERROR_INTERNAL; if (error != NULL) { - BT_ERR("Error occured in Proxy call [%s]\n", error->message); + g_dbus_error_strip_remote_error(error); + BT_ERR("Error occured in Proxy call [%s]", error->message); + if (g_strcmp0(error->message, "Does Not Exist") == 0) + ret = BLUETOOTH_ERROR_NOT_PAIRED; g_error_free(error); } g_object_unref(device_proxy); - return BLUETOOTH_ERROR_INTERNAL; - } - - g_variant_get(result , "(s)", &idaddress); - g_variant_unref(result); - - if (idaddress == NULL) { - BT_ERR("No paired device"); - g_object_unref(device_proxy); - return BLUETOOTH_ERROR_NOT_PAIRED; + return ret; } - BT_DBG("ID Address:%s", idaddress); + g_variant_get(result , "(&s)", &idaddress); - if (idaddress) - _bt_convert_addr_string_to_type(id_address->addr, idaddress); - else - ret = BLUETOOTH_ERROR_INTERNAL; + DBG_SECURE("ID Address : %s", idaddress); + _bt_convert_addr_string_to_type(id_address->addr, idaddress); + g_variant_unref(result); g_object_unref(device_proxy); return ret;