/*
- * 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,
*
*/
-#include <dbus/dbus-glib.h>
-#include <dbus/dbus.h>
#include <glib.h>
+#include <gio/gio.h>
#include <dlog.h>
#include <string.h>
-#if !defined(LIBNOTIFY_SUPPORT) && !defined(LIBNOTIFICATION_SUPPORT)
#include <syspopup_caller.h>
-#endif
+#include <vconf.h>
+#include <bundle_internal.h>
+
#include "bluetooth-api.h"
#include "bt-internal-types.h"
#include "bt-service-common.h"
+#include "bt-service-adapter-le.h"
#include "bt-service-event.h"
#include "bt-service-device.h"
#include "bt-service-rfcomm-client.h"
#include "bt-service-util.h"
#include "bt-service-agent.h"
+#include "bt-service-network.h"
+#include "bt-service-adapter.h"
+#include "bt-service-gap-agent.h"
+
+#define BT_SYSPOPUP_IPC_RESPONSE_OBJECT "/org/projectx/bt_syspopup_res"
+#define BT_SYSPOPUP_INTERFACE "User.Bluetooth.syspopup"
+#define BT_SYSPOPUP_METHOD_RESPONSE "Response"
+
+#define BT_LE_CONN_INTERVAL_MIN 7.5 /* msec */
+#define BT_LE_CONN_INTERVAL_MAX 4000 /* msec */
+#define BT_LE_CONN_SUPER_TO_MIN 100 /* msec */
+#define BT_LE_CONN_SUPER_TO_MAX 32000 /* msec */
+#define BT_LE_CONN_SLAVE_LATENCY_MAX 499
+#define BT_LE_CONN_INTERVAL_SPLIT 1.25 /* msec */
+#define BT_LE_CONN_TO_SPLIT 10 /* msec */
+#define BT_DEVICE_PIN_CODE_SLOT_MAX 10
+
+#define BT_LE_CONN_PARAM_DEFAULT_SUPERVISION_TIMEOUT 6000 /* msec */
+
+#define BT_LE_CONN_PARAM_BALANCED_MIN_INTERVAL 30 /* msec */
+#define BT_LE_CONN_PARAM_BALANCED_MAX_INTERVAL 50 /* msec */
+#define BT_LE_CONN_PARAM_BALANCED_SLAVE_LATENCY 0 /* event */
+
+#define BT_LE_CONN_PARAM_LOW_LATENCY_MIN_INTERVAL 10 /* msec */
+#define BT_LE_CONN_PARAM_LOW_LATENCY_MAX_INTERVAL 30 /* msec */
+#define BT_LE_CONN_PARAM_LOW_LATENCY_SLAVE_LATENCY 0 /* event */
+
+#define BT_LE_CONN_PARAM_LOW_POWER_MIN_INTERVAL 80 /* msec */
+#define BT_LE_CONN_PARAM_LOW_POWER_MAX_INTERVAL 100 /* msec */
+#define BT_LE_CONN_PARAM_LOW_POWER_SLAVE_LATENCY 2 /* event */
+
+#define PROFILE_SUPPORTED 0x3 /* This corresponds to binary 0b11*/
typedef struct {
int req_id;
+ int result;
char *addr;
gboolean is_autopair;
- DBusGProxy *device_proxy;
- DBusGProxy *adapter_proxy;
+ GDBusProxy *device_proxy;
+ GDBusProxy *adapter_proxy;
+ void *agent;
+ unsigned short conn_type;
+ gboolean bonding_wo_discovery;
} bt_funcion_data_t;
-gboolean is_deivce_creating;
+typedef struct {
+ char *address;
+ char *pin_code;
+} bt_pin_code_info_t;
+
+typedef struct {
+ int req_id;
+ bluetooth_device_address_t bd_addr;
+ gboolean auto_connect;
+} bt_pending_le_conn_info_s;
+
+typedef struct {
+ char *address;
+ float interval_min;
+ float interval_max;
+ GSList *senders;
+} bt_connected_le_dev_t;
+
+typedef struct {
+ char *sender;
+ float interval_min;
+ float interval_max;
+ guint16 latency;
+ guint16 time_out;
+ float key;
+} bt_le_conn_param_t;
+
+gboolean is_device_creating;
bt_funcion_data_t *bonding_info;
bt_funcion_data_t *searching_info;
+bt_funcion_data_t *att_mtu_req_info;
+
+static GSList *le_connected_dev_list = NULL;
+static GSList *pin_info_list = NULL;
+static bt_pending_le_conn_info_s *pending_le_conn_info = NULL;
+static guint pending_le_conn_timer_id = 0;
/* This HID Mouse does not support pairing precedure. need to skip it. */
#define SMB_MOUSE_LAP_ADDR "00:12:A1"
-static void __bt_bond_device_cb(DBusGProxy *proxy, DBusGProxyCall *call,
- gpointer user_data);
-
+static void __bt_bond_device_cb(GDBusProxy *proxy, GAsyncResult *res,
+ gpointer user_data);
-gboolean _bt_is_device_creating(void)
+/*static void __bt_decline_pair_request()
{
- return is_deivce_creating;
-}
+ GVariant *out_param1;
+ GVariant *out_param2;
+ request_info_t *req_info;
+ bluetooth_device_info_t dev_info;
+ bt_remote_dev_info_t *remote_dev_info;
+ GVariant *uuid_list, *manufacture_data;
+ GVariant *param;
-void _bt_set_autopair_status_in_bonding_info(gboolean is_autopair)
+ BT_DBG("+");
+ if (bonding_info) {
+ req_info = _bt_get_request_info(bonding_info->req_id);
+ if (req_info == NULL) {
+ BT_ERR("req_info == NULL");
+ goto done;
+ }
+ remote_dev_info = _bt_get_remote_device_info(bonding_info->addr);
+ } else {
+ BT_DBG("bonding_info is NULL");
+ BT_DBG("-");
+ return;
+ }
+
+ uuid_list = g_variant_new_from_data((const GVariantType *)"as",
+ remote_dev_info->uuids, remote_dev_info->uuid_count,
+ TRUE, NULL, NULL);
+
+ 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("isunsbuba{s}na{y})",
+ bonding_info->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,
+ uuid_list,
+ remote_dev_info->manufacturer_data_len,
+ manufacture_data);
+
+
+ //Send the event to application
+ if (remote_dev_info != NULL) {
+ _bt_send_event(BT_ADAPTER_EVENT,
+ BLUETOOTH_EVENT_BONDING_FINISHED,
+ param);
+
+ _bt_free_device_info(remote_dev_info);
+ }
+
+ if (req_info->context == NULL)
+ goto done;
+
+ memset(&dev_info, 0x00, sizeof(bluetooth_device_info_t));
+ _bt_convert_addr_string_to_type(dev_info.device_address.addr,
+ bonding_info->addr);
+
+ out_param1 = g_variant_new_from_data((const GVariantType *)"ay",
+ &dev_info, sizeof(bluetooth_device_info_t), TRUE, NULL, NULL);
+
+ out_param2 = g_variant_new_from_data((const GVariantType *)"i",
+ &bonding_info->result, sizeof(int), TRUE, NULL, NULL);
+
+
+ g_dbus_method_invocation_return_value(req_info->context,
+ g_variant_new("@ayi", out_param1, out_param2));
+
+
+ _bt_delete_request_list(req_info->req_id);
+done:
+
+ g_free(bonding_info->addr);
+ g_free(bonding_info);
+ bonding_info = NULL;
+
+ BT_DBG("-");
+} */
+
+#ifdef TIZEN_PROFILE_WEARABLE
+static gboolean __bt_syspopup_timer_cb(gpointer user_data)
{
- ret_if(bonding_info == NULL);
- bonding_info->is_autopair = is_autopair;
+ 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;
}
-void _bt_device_path_to_address(const char *device_path,
- char *device_address)
+static gboolean __bt_launch_unable_to_pairing_syspopup(int result)
{
- char address[BT_ADDRESS_STRING_SIZE] = { 0 };
- char *dev_addr;
- char *pos;
+ 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_if(device_path == NULL);
- ret_if(device_address == NULL);
+ 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
- dev_addr = strstr(device_path, "dev_");
- ret_if(dev_addr == NULL);
+gboolean _bt_is_device_creating(void)
+{
+ return is_device_creating;
+}
- dev_addr += 4;
- g_strlcpy(address, dev_addr, sizeof(address));
+gboolean _bt_is_bonding_device_address(const char *address)
+{
+ if (bonding_info == NULL || bonding_info->addr == NULL)
+ return FALSE;
- while ((pos = strchr(address, '_')) != NULL) {
- *pos = ':';
+ if (g_strcmp0(bonding_info->addr, address) == 0) {
+ BT_DBG("[%s] is bonding device", address);
+ return TRUE;
}
- g_strlcpy(device_address, address, BT_ADDRESS_STRING_SIZE);
+ BT_DBG("[%s] is NOT bonding device", address);
+ return FALSE;
+}
+
+void _bt_set_autopair_status_in_bonding_info(gboolean is_autopair)
+{
+ ret_if(bonding_info == NULL);
+ bonding_info->is_autopair = is_autopair;
}
void __bt_cancel_search_service_done(void)
int result = BLUETOOTH_ERROR_CANCEL_BY_USER;
request_info_t *req_info;
bluetooth_device_info_t dev_info;
- GArray *out_param1;
- GArray *out_param2;
+ GVariant *out_param1;
ret_if(searching_info == NULL);
if (req_info->context == NULL)
goto done;
- out_param1 = g_array_new(FALSE, FALSE, sizeof(gchar));
- out_param2 = g_array_new(FALSE, FALSE, sizeof(gchar));
-
memset(&dev_info, 0x00, sizeof(bluetooth_device_info_t));
_bt_convert_addr_string_to_type(dev_info.device_address.addr,
searching_info->addr);
- g_array_append_vals(out_param1, &dev_info,
- sizeof(bluetooth_device_info_t));
- g_array_append_vals(out_param2, &result, sizeof(int));
+ out_param1 = g_variant_new_from_data((const GVariantType *)"ay",
+ &dev_info, sizeof(bluetooth_device_info_t), TRUE, NULL, NULL);
- dbus_g_method_return(req_info->context, out_param1, out_param2);
- g_array_free(out_param1, TRUE);
- g_array_free(out_param2, TRUE);
+ g_dbus_method_invocation_return_value(req_info->context,
+ g_variant_new("(iv)", result, out_param1));
_bt_delete_request_list(req_info->req_id);
done:
- if (searching_info->device_proxy)
- g_object_unref(searching_info->device_proxy);
-
- if (searching_info->adapter_proxy)
- g_object_unref(searching_info->adapter_proxy);
g_free(searching_info->addr);
g_free(searching_info);
searching_info = NULL;
}
-static void __bt_get_uuids(GValue *value, bt_remote_dev_info_t *info)
+static void __bt_get_uuids(GVariant *value, bt_remote_dev_info_t *info)
{
- int i = 0;
- char **uuid_value;
-
ret_if(value == NULL);
ret_if(info == NULL);
- info->uuid_count = 0;
+ info->uuid_count = g_variant_get_size(value);
+ info->uuids = g_variant_dup_strv(value, &info->uuid_count);
+}
- uuid_value = g_value_get_boxed(value);
- ret_if(uuid_value == NULL);
+bt_remote_dev_info_t *_bt_get_remote_device_info(char *address)
+{
+ char *object_path = NULL;
+ bt_remote_dev_info_t *dev_info;
- while (uuid_value[i]) {
- i++;
- }
- ret_if(i == 0);
+ retv_if(address == NULL, NULL);
- info->uuid_count = i;
+ object_path = _bt_get_device_object_path(address);
+ retv_if(object_path == NULL, NULL);
- info->uuids = g_new0(char *, info->uuid_count + 1);
+ dev_info = _bt_get_remote_device_info_by_object_path(object_path);
- for (i = 0; uuid_value[i] != NULL; i++) {
- info->uuids[i] = g_strdup(uuid_value[i]);
- }
+ g_free(object_path);
+ return dev_info;
}
-bt_remote_dev_info_t *_bt_get_remote_device_info(char *address)
+bt_remote_dev_info_t *_bt_get_remote_device_info_by_object_path(
+ const char *object_path)
{
bt_remote_dev_info_t *dev_info;
- char *object_path = NULL;
- DBusGProxy *adapter_proxy;
- DBusGProxy *device_proxy;
- GHashTable *hash = NULL;
- GValue *value;
- const gchar *name;
- DBusGConnection *conn;
-
- retv_if(address == NULL, NULL);
+ GDBusProxy *adapter_proxy;
+ GDBusProxy *device_proxy;
+ GVariant *value;
+ GVariant *tmp_value;
+ gchar *name;
+ gchar * address;
+ GDBusConnection *conn;
+ GError *error = NULL;
+ GVariant *result = NULL;
+ GVariantIter *value_iter;
+ guint8 m_value;
+ int i = 0;
adapter_proxy = _bt_get_adapter_proxy();
retv_if(adapter_proxy == NULL, NULL);
- object_path = _bt_get_device_object_path(address);
-
retv_if(object_path == NULL, NULL);
- conn = _bt_get_system_gconn();
+ conn = _bt_gdbus_get_system_gconn();
if (conn == NULL) {
BT_ERR("conn == NULL");
- g_free(object_path);
return NULL;
}
- device_proxy = dbus_g_proxy_new_for_name(conn, BT_BLUEZ_NAME,
- object_path, BT_PROPERTIES_INTERFACE);
- g_free(object_path);
+ device_proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
+ NULL, BT_BLUEZ_NAME, object_path,
+ BT_PROPERTIES_INTERFACE, NULL, NULL);
+
retv_if(device_proxy == NULL, NULL);
- dbus_g_proxy_call(device_proxy, "GetAll", NULL,
- G_TYPE_STRING, BT_DEVICE_INTERFACE,
- G_TYPE_INVALID,
- dbus_g_type_get_map("GHashTable", G_TYPE_STRING,
- G_TYPE_VALUE), &hash, G_TYPE_INVALID);
+ result = g_dbus_proxy_call_sync(device_proxy, "GetAll",
+ g_variant_new("(s)", BT_DEVICE_INTERFACE),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ &error);
g_object_unref(device_proxy);
dev_info = g_malloc0(sizeof(bt_remote_dev_info_t));
- if (hash != NULL) {
- value = g_hash_table_lookup(hash, "Alias");
- name = value ? g_value_get_string(value) : NULL;
+ if (result != NULL) {
+ g_variant_get(result , "(@a{sv})", &value);
+ g_variant_unref(result);
+
+ tmp_value = g_variant_lookup_value(value, "Alias", G_VARIANT_TYPE_STRING);
+ g_variant_get(tmp_value, "s", &name);
+ g_variant_unref(tmp_value);
if (name != NULL)
- BT_DBG("Alias Name [%s]", name);
+ DBG_SECURE("Alias Name [%s]", name);
else {
- value = g_hash_table_lookup(hash, "Name");
- name = value ? g_value_get_string(value) : NULL;
+ tmp_value = g_variant_lookup_value(value, "Name", G_VARIANT_TYPE_STRING);
+ g_variant_get(tmp_value, "s", &name);
+ g_variant_unref(tmp_value);
+ }
+
+ tmp_value = g_variant_lookup_value(value, "IsAliasSet", G_VARIANT_TYPE_BOOLEAN);
+ if (tmp_value) {
+ dev_info->is_alias_set = g_variant_get_boolean(tmp_value);
+ g_variant_unref(tmp_value);
+ } else {
+ dev_info->is_alias_set = FALSE;
+ }
+ BT_DBG("IsAliasSet: [%s]", dev_info->is_alias_set ? "TRUE" : "FALSE");
+
+ tmp_value = g_variant_lookup_value(value, "Class", G_VARIANT_TYPE_UINT32);
+ if (tmp_value) {
+ dev_info->class = g_variant_get_uint32(tmp_value);
+ g_variant_unref(tmp_value);
+ } else
+ dev_info->class = 0;
+
+ tmp_value = g_variant_lookup_value(value, "Connected", G_VARIANT_TYPE_BYTE);
+ if (tmp_value) {
+ dev_info->connected = g_variant_get_byte(tmp_value);
+ g_variant_unref(tmp_value);
+ } else
+ dev_info->connected = BLUETOOTH_CONNECTED_LINK_NONE;
+ BT_DBG("connected link : %d", dev_info->connected);
+
+ tmp_value = g_variant_lookup_value(value, "Trusted", G_VARIANT_TYPE_BOOLEAN);
+ if (tmp_value) {
+ dev_info->trust = g_variant_get_boolean(tmp_value);
+ g_variant_unref(tmp_value);
+ } else
+ dev_info->trust = FALSE;
+
+ tmp_value = g_variant_lookup_value(value, "Paired", G_VARIANT_TYPE_BOOLEAN);
+ if (tmp_value) {
+ dev_info->paired = g_variant_get_boolean(tmp_value);
+ g_variant_unref(tmp_value);
+ } else
+ dev_info->paired = FALSE;
+
+ tmp_value = g_variant_lookup_value(value, "RSSI", G_VARIANT_TYPE_INT16);
+ if (tmp_value) {
+ dev_info->rssi = g_variant_get_int16(tmp_value);
+ g_variant_unref(tmp_value);
+ } else
+ dev_info->rssi = 0;
+
+ tmp_value = g_variant_lookup_value(value, "LastAddrType", G_VARIANT_TYPE_BYTE);
+ if (tmp_value) {
+ dev_info->addr_type = g_variant_get_byte(tmp_value);
+ g_variant_unref(tmp_value);
+ } else
+ dev_info->addr_type = 0;
+
+ tmp_value = g_variant_lookup_value(value, "UUIDs", G_VARIANT_TYPE_STRING_ARRAY);
+ if (tmp_value) {
+ __bt_get_uuids(tmp_value, dev_info);
+ g_variant_unref(tmp_value);
+ }
+
+ 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) {
+ BT_ERR("manufacturer_data_len is too long(len = %d)", dev_info->manufacturer_data_len);
+ dev_info->manufacturer_data_len = BLUETOOTH_MANUFACTURER_DATA_LENGTH_MAX;
+ }
+ g_variant_unref(tmp_value);
+ } else
+ dev_info->manufacturer_data_len = 0;
+
+ 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)) {
+ BT_ERR("manufacturer data length doesn't match");
+ dev_info->manufacturer_data_len = 0;
+ dev_info->manufacturer_data = NULL;
+ } else {
+ dev_info->manufacturer_data = g_malloc0(dev_info->manufacturer_data_len);
+ 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 {
+ BT_INFO("manufacture data is not a G_VARIANT_TYPE_ARRAY ");
+ dev_info->manufacturer_data_len = 0;
+ dev_info->manufacturer_data = NULL;
}
- value = g_hash_table_lookup(hash, "Class");
- dev_info->class = value ? g_value_get_uint(value) : 0;
+ tmp_value = g_variant_lookup_value(value, "Address", G_VARIANT_TYPE_STRING);
+ g_variant_get(tmp_value, "s", &address);
+ g_variant_unref(tmp_value);
+
+ dev_info->address = address;
+ dev_info->name = name;
+ g_variant_unref(value);
+ } else {
+ BT_ERR("result is NULL\n");
+ g_free(dev_info);
+ dev_info = NULL;
+ }
- value = g_hash_table_lookup(hash, "Connected");
- dev_info->connected = value ? g_value_get_boolean(value) : FALSE;
+ return dev_info;
+}
- value = g_hash_table_lookup(hash, "Trusted");
- dev_info->trust = value ? g_value_get_boolean(value) : FALSE;
+char *_bt_get_device_name(const char *bdaddress)
+{
+ char *device_path = NULL;
+ const gchar *name = NULL;
+ gchar *dev_name = NULL;
+ gsize name_len = 0;
+ GVariant *result = NULL;
+ GError *err = NULL;
+ GDBusProxy *device_proxy;
+ GDBusConnection *conn;
- value = g_hash_table_lookup(hash, "RSSI");
- dev_info->rssi = value ? g_value_get_int(value) : 0;
+ retv_if(bdaddress == NULL, NULL);
- value = g_hash_table_lookup(hash, "UUIDs");
- __bt_get_uuids(value, dev_info);
+ device_path = _bt_get_device_object_path((char *)bdaddress);
+ retv_if(device_path == NULL, NULL);
- dev_info->address = g_strdup(address);
- dev_info->name = g_strdup(name);
+ conn = _bt_gdbus_get_system_gconn();
+ retv_if(conn == NULL, NULL);
+ INFO_SECURE("Device_path %s", device_path);
+ device_proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
+ NULL, BT_BLUEZ_NAME, device_path,
+ BT_PROPERTIES_INTERFACE, NULL, &err);
- value = g_hash_table_lookup(hash, "Paired");
- dev_info->paired = value ? g_value_get_boolean(value) : FALSE;
+ g_free(device_path);
+ retv_if(device_proxy == NULL, NULL);
- g_hash_table_destroy(hash);
+ result = g_dbus_proxy_call_sync(device_proxy, "Get",
+ g_variant_new("(ss)", BT_DEVICE_INTERFACE, "Alias"),
+ G_DBUS_CALL_FLAGS_NONE, -1, NULL, &err);
+ if (err) {
+ BT_ERR("DBus Error : %s", err->message);
+ g_clear_error(&err);
} else {
- BT_ERR("Hash is NULL\n");
- g_free(dev_info);
- dev_info = NULL;
+ GVariant *value;
+ g_variant_get(result, "(v)", &value);
+ name = g_variant_get_string(value, &name_len);
+ INFO_SECURE("Alias Name [%s]", name);
+ if (name_len)
+ dev_name = g_strdup(name);
+ g_variant_unref(value);
+ g_variant_unref(result);
}
- return dev_info;
+ if (name_len == 0) {
+ GVariant *value;
+ result = g_dbus_proxy_call_sync(device_proxy, "Get",
+ g_variant_new("(ss)", BT_DEVICE_INTERFACE, "Name"),
+ G_DBUS_CALL_FLAGS_NONE, -1, NULL, &err);
+ if (err) {
+ ERR("DBus Error : %s", err->message);
+ g_clear_error(&err);
+ } else {
+ g_variant_get(result, "(v)", &value);
+ name = g_variant_get_string(value, &name_len);
+ INFO_SECURE("Name = %s", name);
+ if (name_len)
+ dev_name = g_strdup(name);
+ g_variant_unref(value);
+ g_variant_unref(result);
+ }
+ }
+
+ g_object_unref(device_proxy);
+ return dev_name;
}
static gboolean __ignore_auto_pairing_request(const char *address)
fp = fopen(BT_AGENT_AUTO_PAIR_BLACKLIST_FILE, "r");
if (fp == NULL) {
- BT_DBG("fopen failed \n");
+ BT_ERR("fopen failed \n");
return FALSE;
}
rewind(fp);
if (size < 0) {
- BT_DBG("Get file size failed \n");
+ BT_ERR("Get file size failed \n");
fclose(fp);
return FALSE;
}
result = fread((char *)buffer, 1, size, fp);
fclose(fp);
if (result != size) {
- BT_DBG("Read Error\n");
+ BT_ERR("Read Error\n");
g_free(buffer);
return FALSE;
}
}
buffer = g_strjoinv(BT_AGENT_NEW_LINE, lines);
g_strfreev(lines);
+ /* Fix : NULL_RETURNS */
+ retv_if(buffer == NULL, FALSE);
fp = fopen(BT_AGENT_AUTO_PAIR_BLACKLIST_FILE, "w");
if (fp == NULL) {
- BT_DBG("fopen failed \n");
+ BT_ERR("fopen failed \n");
g_free(buffer);
return FALSE;
}
return FALSE;
}
-static int __bt_retry_bond(void)
+static int __bt_cancel_bonding(void)
{
- DBusGProxy *device_proxy;
- char *device_path;
- DBusGConnection *conn;
-
BT_CHECK_PARAMETER(bonding_info, return);
BT_CHECK_PARAMETER(bonding_info->addr, return);
-
- conn = _bt_get_system_gconn();
- retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- device_path = _bt_get_device_object_path(bonding_info->addr);
-
- if (device_path == NULL) {
- BT_ERR("No searched device");
- return BLUETOOTH_ERROR_NOT_PAIRED;
- }
-
- if (bonding_info->device_proxy) {
- device_proxy = bonding_info->device_proxy;
- } else {
- device_proxy = dbus_g_proxy_new_for_name(conn, BT_BLUEZ_NAME,
- device_path, BT_DEVICE_INTERFACE);
- }
-
- g_free(device_path);
- retv_if(device_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- is_deivce_creating = TRUE;
- bonding_info->device_proxy = device_proxy;
-
- if (!dbus_g_proxy_begin_call_with_timeout(device_proxy, "Pair",
- (DBusGProxyCallNotify) __bt_bond_device_cb,
- NULL, NULL, BT_MAX_DBUS_TIMEOUT,
- G_TYPE_INVALID,
- G_TYPE_INVALID)) {
- BT_ERR("Pair call fail");
- is_deivce_creating = FALSE;
- g_object_unref(device_proxy);
- return BLUETOOTH_ERROR_INTERNAL;
+ /* 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",
+ 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;
}
-
return BLUETOOTH_ERROR_NONE;
}
-
-static int __bt_remove_and_bond(void)
-{
- DBusGProxy *adapter_proxy;
- 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);
-
- device_path = _bt_get_device_object_path(bonding_info->addr);
-
- retv_if (device_path == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- dbus_g_proxy_call(adapter_proxy, "RemoveDevice",
- &err, DBUS_TYPE_G_OBJECT_PATH, device_path,
- G_TYPE_INVALID, G_TYPE_INVALID);
- g_free(device_path);
- if (err != NULL) {
- BT_ERR("RemoveDevice Fail: %s", err->message);
- g_error_free(err);
- return BLUETOOTH_ERROR_INTERNAL;
- }
-
- return __bt_retry_bond();
-}
-
-static int __bt_cancel_and_bond(void)
-{
- BT_CHECK_PARAMETER(bonding_info, return);
- BT_CHECK_PARAMETER(bonding_info->device_proxy, return);
-
- dbus_g_proxy_call_no_reply(bonding_info->device_proxy,
- "CancelPairing",
- G_TYPE_INVALID, G_TYPE_INVALID);
-
- return __bt_retry_bond();
-}
-
-
-static void __bt_bond_device_cb(DBusGProxy *proxy, DBusGProxyCall *call,
- gpointer user_data)
+static void __bt_bond_device_cb(GDBusProxy *proxy, GAsyncResult *res,
+ gpointer user_data)
{
int result = BLUETOOTH_ERROR_NONE;
GError *err = NULL;
- GArray *out_param1;
- GArray *out_param2;
+ GVariant *reply;
+ GVariant *out_param1;
request_info_t *req_info;
bluetooth_device_info_t dev_info;
- bt_remote_dev_info_t *remote_dev_info;
/* Terminate ALL system popup */
-#if !defined(LIBNOTIFY_SUPPORT) && !defined(LIBNOTIFICATION_SUPPORT)
syspopup_destroy_all();
-#endif
- dbus_g_proxy_end_call(proxy, call, &err, G_TYPE_INVALID);
+ reply = g_dbus_proxy_call_finish(proxy, res, &err);
+ if (reply)
+ g_variant_unref(reply);
- g_object_unref(proxy);
-
- is_deivce_creating = FALSE;
+ is_device_creating = FALSE;
if (bonding_info == NULL) {
/* Send reply */
return;
}
- bonding_info->device_proxy = NULL;
-
req_info = _bt_get_request_info(bonding_info->req_id);
if (req_info == NULL) {
BT_ERR("req_info == NULL");
}
if (err != NULL) {
- BT_ERR("Error occured in Pair [%s]", err->message);
-
- if (!strcmp(err->message, "Already Exists")) {
- BT_DBG("Existing Bond, remove and retry");
- ret_if(__bt_remove_and_bond() == BLUETOOTH_ERROR_NONE);
-
- result = BLUETOOTH_ERROR_PARING_FAILED;
- } else if (!strcmp(err->message, "Authentication Rejected")) {
+ g_dbus_error_strip_remote_error(err);
+ BT_ERR("Error occured in CreateBonding [%s]", err->message);
+
+ if (g_strrstr(err->message, "Already Exists")) {
+ 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");
+ result = BLUETOOTH_ERROR_CANCEL_BY_USER;
+ } else if (g_strrstr(err->message, "Authentication Rejected")) {
+ BT_INFO("REJECTED");
result = BLUETOOTH_ERROR_ACCESS_DENIED;
-// } else if (_bt_agent_is_canceled(bonding_info->agent) ||
-// !strcmp(err->message, "Authentication Canceled")) {
-// result = BLUETOOTH_ERROR_CANCEL_BY_USER;
- } else if (!strcmp(err->message, "In Progress")) {
- BT_DBG("Bond in progress, cancel and retry");
- ret_if(__bt_cancel_and_bond() == BLUETOOTH_ERROR_NONE);
-
- result = BLUETOOTH_ERROR_PARING_FAILED;
- } else if (!strcmp(err->message, "Authentication Failed")) {
+ } else if (g_strrstr(err->message, "In Progress")) {
+ 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) {
_bt_set_autopair_status_in_bonding_info(FALSE);
__ignore_auto_pairing_request(bonding_info->addr);
}
result = BLUETOOTH_ERROR_AUTHENTICATION_FAILED;
- } else if (!strcmp(err->message, "Page Timeout")) {
+ } else if (g_strrstr(err->message, "Page Timeout")) {
+ BT_INFO("Page Timeout");
/* This is the special case
As soon as call bluetooth_bond_device, try to cancel bonding.
In this case, before completing to call 'CreatePairedDevice' method
the procedure is stopped. So 'Cancle' error is not return.
*/
result = BLUETOOTH_ERROR_HOST_DOWN;
- } else if (!strcmp(err->message, BT_TIMEOUT_MESSAGE)) {
- dbus_g_proxy_call(proxy, "CancelDeviceCreation", NULL,
- G_TYPE_STRING, bonding_info->addr,
- G_TYPE_INVALID, G_TYPE_INVALID);
-
+ } else if (g_strrstr(err->message, BT_DBUS_TIMEOUT_MESSAGE)) {
+ BT_INFO("Cancel already running bonding");
+ if (__bt_cancel_bonding() != BLUETOOTH_ERROR_NONE) {
+ BT_INFO("Error while Cancelling bonding");
+ /* we need to unref proxy so continue */
+ }
+ result = BLUETOOTH_ERROR_INTERNAL;
+ } else if (g_strrstr(err->message, "Connection Timeout")) {
+ /* Pairing request timeout */
+ result = BLUETOOTH_ERROR_TIMEOUT;
+ } else if (g_strrstr(err->message, "Authentication Timeout")) {
+ /* Pairing request timeout */
result = BLUETOOTH_ERROR_TIMEOUT;
} else {
+ BT_DBG("Default case");
result = BLUETOOTH_ERROR_PARING_FAILED;
}
}
- if (result != BLUETOOTH_ERROR_NONE)
- goto dbus_return;
+ if (result == BLUETOOTH_ERROR_PARING_FAILED ||
+ result == BLUETOOTH_ERROR_AUTHENTICATION_FAILED ||
+ result == BLUETOOTH_ERROR_TIMEOUT ||
+ result == BLUETOOTH_ERROR_HOST_DOWN) {
+#ifdef TIZEN_PROFILE_WEARABLE
+ int is_sw_running = 0;
- remote_dev_info = _bt_get_remote_device_info(bonding_info->addr);
+ if (vconf_get_int(VCONFKEY_SETUP_WIZARD_STATE, &is_sw_running))
+ BT_ERR("vconf_get_int for setup wizard state failed");
- /* Send the event to application */
- if (remote_dev_info != NULL) {
- _bt_send_event(BT_ADAPTER_EVENT,
- BLUETOOTH_EVENT_BONDING_FINISHED,
- DBUS_TYPE_INT32, &result,
- DBUS_TYPE_STRING, &bonding_info->addr,
- DBUS_TYPE_UINT32, &remote_dev_info->class,
- DBUS_TYPE_INT16, &remote_dev_info->rssi,
- DBUS_TYPE_STRING, &remote_dev_info->name,
- DBUS_TYPE_BOOLEAN, &remote_dev_info->paired,
- DBUS_TYPE_BOOLEAN, &remote_dev_info->connected,
- DBUS_TYPE_BOOLEAN, &remote_dev_info->trust,
- DBUS_TYPE_ARRAY, DBUS_TYPE_STRING,
- &remote_dev_info->uuids, remote_dev_info->uuid_count,
- DBUS_TYPE_INVALID);
+ if (!is_sw_running)
+ __bt_launch_unable_to_pairing_syspopup(result);
+ else
+ BT_ERR("Unable to pair");
+#endif
+ bonding_info->result = result;
+ }
- _bt_free_device_info(remote_dev_info);
+ g_object_unref(proxy);
+ bonding_info->device_proxy = NULL;
+
+ if (result != BLUETOOTH_ERROR_NONE) {
+ if (bonding_info->bonding_wo_discovery) {
+ GDBusProxy *adapter_proxy;
+ GVariant *ret = NULL;
+ GError *error = NULL;
+ char *device_path;
+
+ BT_ERR("Bond was tried without discovery. Remove it");
+
+ adapter_proxy = _bt_get_adapter_proxy();
+ if (adapter_proxy == NULL) {
+ BT_ERR("Cannot get adapter_proxy");
+ goto dbus_return;
+ }
+
+ device_path = _bt_get_device_object_path(bonding_info->addr);
+ if (device_path == NULL) {
+ BT_ERR("Cannot get device path");
+ goto dbus_return;
+ }
+
+ ret = g_dbus_proxy_call_sync(adapter_proxy,
+ "RemoveDevice",
+ g_variant_new("(o)", device_path),
+ G_DBUS_CALL_FLAGS_NONE, -1, NULL,
+ &error);
+ if (error != NULL) {
+ BT_ERR("RemoveDevice Fail: %s", error->message);
+ g_clear_error(&error);
+ }
+
+ if (ret)
+ g_variant_unref(ret);
+
+ g_free(device_path);
+ }
+
+ goto dbus_return;
}
dbus_return:
if (req_info->context == NULL)
goto done;
- out_param1 = g_array_new(FALSE, FALSE, sizeof(gchar));
- out_param2 = g_array_new(FALSE, FALSE, sizeof(gchar));
-
memset(&dev_info, 0x00, sizeof(bluetooth_device_info_t));
_bt_convert_addr_string_to_type(dev_info.device_address.addr,
bonding_info->addr);
- g_array_append_vals(out_param1, &dev_info,
- sizeof(bluetooth_device_info_t));
- g_array_append_vals(out_param2, &result, sizeof(int));
+ if (_bt_adapter_get_status() != BT_ACTIVATED)
+ result = BLUETOOTH_ERROR_NOT_IN_OPERATION;
+
+ out_param1 = g_variant_new_from_data((const GVariantType *)"ay",
+ &dev_info, sizeof(bluetooth_device_info_t), TRUE, NULL, NULL);
- dbus_g_method_return(req_info->context, out_param1, out_param2);
+ g_dbus_method_invocation_return_value(req_info->context,
+ g_variant_new("(iv)", result, out_param1));
- g_array_free(out_param1, TRUE);
- g_array_free(out_param2, TRUE);
+ g_variant_unref(out_param1);
_bt_delete_request_list(req_info->req_id);
done:
if (err)
g_error_free(err);
+ _bt_agent_set_canceled(FALSE);
+
+
g_free(bonding_info->addr);
g_free(bonding_info);
bonding_info = NULL;
-
}
int _bt_bond_device(int request_id,
bluetooth_device_address_t *device_address,
- GArray **out_param1)
+ unsigned short conn_type, GArray **out_param1)
{
- DBusGProxy *proxy;
+ GDBusProxy *proxy;
char address[BT_ADDRESS_STRING_SIZE] = { 0 };
bluetooth_device_info_t dev_info;
- DBusGConnection *conn;
+
+ GDBusConnection *conn;
char *device_path = NULL;
+ GDBusProxy *adapter_proxy;
+ GError *error = NULL;
+ gboolean bonding_wo_discovery = FALSE;
BT_CHECK_PARAMETER(device_address, return);
if (bonding_info) {
BT_ERR("Bonding in progress");
+
+ memset(&dev_info, 0x00, sizeof(bluetooth_device_info_t));
+ memcpy(dev_info.device_address.addr, device_address->addr,
+ BLUETOOTH_ADDRESS_LENGTH);
+
+ g_array_append_vals(*out_param1, &dev_info,
+ sizeof(bluetooth_device_info_t));
+
return BLUETOOTH_ERROR_DEVICE_BUSY;
}
- conn = _bt_get_system_gconn();
+ conn = _bt_gdbus_get_system_gconn();
retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
_bt_convert_addr_type_to_string(address, device_address->addr);
if (device_path == NULL) {
BT_ERR("No searched device");
- return BLUETOOTH_ERROR_NOT_PAIRED;
+ GVariant *ret = NULL;
+ adapter_proxy = _bt_get_adapter_proxy();
+ retv_if(adapter_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
+
+ ret = g_dbus_proxy_call_sync(adapter_proxy, "CreateDevice",
+ g_variant_new("(s)", address),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ &error);
+
+ if (error != NULL) {
+ BT_ERR("CreateDevice Fail: %s", error->message);
+ g_clear_error(&error);
+ }
+ if (ret)
+ g_variant_unref(ret);
+ device_path = _bt_get_device_object_path(address);
+ if (device_path == NULL) {
+ memset(&dev_info, 0x00, sizeof(bluetooth_device_info_t));
+ memcpy(dev_info.device_address.addr, device_address->addr,
+ BLUETOOTH_ADDRESS_LENGTH);
+
+ g_array_append_vals(*out_param1, &dev_info,
+ sizeof(bluetooth_device_info_t));
+
+ return BLUETOOTH_ERROR_NOT_PAIRED;
+ } else {
+ BT_INFO("device_path is created[%s]", device_path);
+ }
+ bonding_wo_discovery = TRUE;
}
- proxy = dbus_g_proxy_new_for_name(conn, BT_BLUEZ_NAME,
- device_path, BT_DEVICE_INTERFACE);
+ 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);
bonding_info = g_malloc0(sizeof(bt_funcion_data_t));
bonding_info->addr = g_strdup(address);
bonding_info->req_id = request_id;
+
bonding_info->device_proxy = proxy;
+ bonding_info->conn_type = conn_type;
+ bonding_info->bonding_wo_discovery = bonding_wo_discovery;
- is_deivce_creating = TRUE;
+ is_device_creating = TRUE;
- if (!dbus_g_proxy_begin_call_with_timeout(proxy, "Pair",
- (DBusGProxyCallNotify) __bt_bond_device_cb,
- NULL, NULL, BT_MAX_DBUS_TIMEOUT,
- G_TYPE_INVALID,
- G_TYPE_INVALID)) {
- BT_ERR("Pair call fail");
- g_object_unref(proxy);
- goto fail;
- }
-
-
-/* To Do: We need to check if we can pair the specific device using 'pair' API of bluez 5.x */
-#if 0
- if (!strncmp(address, SMB_MOUSE_LAP_ADDR, strlen(SMB_MOUSE_LAP_ADDR))) {
- bluetooth_device_address_t device_addr = { {0} };
- BT_ERR("This device don't support pairing. So skip pairing.");
- if (!dbus_g_proxy_begin_call(proxy, "CreateDevice",
- (DBusGProxyCallNotify)__bt_bond_device_cb,
- NULL, NULL,
- G_TYPE_STRING, device_addr,
- G_TYPE_INVALID)) {
- BT_ERR("CreateDevice failed");
- goto fail;
- }
+ g_dbus_proxy_call(proxy, "Pair",
+ g_variant_new("(y)", conn_type),
+ G_DBUS_CALL_FLAGS_NONE,
+ BT_MAX_DBUS_TIMEOUT,
+ NULL,
+ (GAsyncReadyCallback)__bt_bond_device_cb,
+ NULL);
- _bt_convert_addr_string_to_type(device_addr.addr, address);
- if (_bt_set_authorization(&device_addr, TRUE))
- BT_ERR("_bt_set_authorization failed [%s]", address);
-
- } else {
- if (!dbus_g_proxy_begin_call_with_timeout(proxy, "CreatePairedDevice",
- (DBusGProxyCallNotify) __bt_bond_device_cb,
- NULL, NULL, BT_MAX_DBUS_TIMEOUT,
- G_TYPE_STRING, address,
- DBUS_TYPE_G_OBJECT_PATH, BT_DEVICE_AGENT_PATH,
- G_TYPE_STRING, "DisplayYesNo",
- G_TYPE_INVALID)) {
- BT_ERR("CreatePairedDevice call fail");
- goto fail;
- }
- }
-#endif
+/* TODO: We need to check if we can pair the specific device using 'pair' API of bluez 5.x */
return BLUETOOTH_ERROR_NONE;
-fail:
+/*fail:
memset(&dev_info, 0x00, sizeof(bluetooth_device_info_t));
_bt_convert_addr_string_to_type(dev_info.device_address.addr,
bonding_info->addr);
g_array_append_vals(*out_param1, &dev_info,
sizeof(bluetooth_device_info_t));
- is_deivce_creating = FALSE;
+ is_device_creating = FALSE;
g_free(bonding_info->addr);
g_free(bonding_info);
bonding_info = NULL;
- return BLUETOOTH_ERROR_INTERNAL;
+ return BLUETOOTH_ERROR_INTERNAL;*/
}
int _bt_cancel_bonding(void)
{
+ int ret = BLUETOOTH_ERROR_NONE;
+
retv_if(bonding_info == NULL, BLUETOOTH_ERROR_NOT_IN_OPERATION);
- retv_if(bonding_info->device_proxy == NULL,
- BLUETOOTH_ERROR_NOT_IN_OPERATION);
- dbus_g_proxy_call_no_reply(bonding_info->device_proxy,
- "CancelPairing",
- G_TYPE_INVALID, G_TYPE_INVALID);
+ ret = _bt_agent_reply_cancellation();
+ if (ret != BLUETOOTH_ERROR_NONE) {
+ BT_ERR("Fail to call reply cancellation");
+ return ret;
+ }
+
+ _bt_agent_set_canceled(TRUE);
return BLUETOOTH_ERROR_NONE;
}
-static void __bt_unbond_cb(DBusGProxy *proxy, DBusGProxyCall *call,
- gpointer user_data)
+static void __bt_unbond_cb(GDBusProxy *proxy, GAsyncResult *res,
+ gpointer user_data)
{
GError *err = NULL;
- GArray *out_param1;
- GArray *out_param2;
+ GVariant *reply;
+ GVariant *out_param1;
int result = BLUETOOTH_ERROR_NONE;
bt_funcion_data_t *unbonding_info;
bluetooth_device_info_t dev_info;
request_info_t *req_info;
- dbus_g_proxy_end_call(proxy, call, &err, G_TYPE_INVALID);
+ reply = g_dbus_proxy_call_finish(proxy, res, &err);
+ if (reply)
+ g_variant_unref(reply);
unbonding_info = user_data;
if (err != NULL) {
BT_ERR("Error occured in RemoveBonding [%s]\n", err->message);
result = BLUETOOTH_ERROR_INTERNAL;
- goto dbus_return;
}
-dbus_return:
if (req_info->context == NULL)
goto done;
- out_param1 = g_array_new(FALSE, FALSE, sizeof(gchar));
- out_param2 = g_array_new(FALSE, FALSE, sizeof(gchar));
-
memset(&dev_info, 0x00, sizeof(bluetooth_device_info_t));
_bt_convert_addr_string_to_type(dev_info.device_address.addr,
unbonding_info->addr);
- g_array_append_vals(out_param1, &dev_info,
- sizeof(bluetooth_device_info_t));
- g_array_append_vals(out_param2, &result, sizeof(int));
+ out_param1 = g_variant_new_from_data((const GVariantType *)"ay",
+ &dev_info, sizeof(bluetooth_device_info_t), TRUE, NULL, NULL);
- dbus_g_method_return(req_info->context, out_param1, out_param2);
+ g_dbus_method_invocation_return_value(req_info->context,
+ g_variant_new("(iv)", result, out_param1));
- _bt_delete_request_list(req_info->req_id);
- g_array_free(out_param1, TRUE);
- g_array_free(out_param2, TRUE);
+ _bt_delete_request_list(req_info->req_id);
done:
if (err)
{
char *device_path = NULL;
bt_funcion_data_t *unbonding_info;
- DBusGProxy *adapter_proxy;
+ GDBusProxy *adapter_proxy = NULL;
+ GDBusProxy *device_proxy = NULL;
+ GDBusConnection *conn;
int result = BLUETOOTH_ERROR_INTERNAL;
bluetooth_device_info_t dev_info;
+ GError *error = NULL;
+ GVariant *ret = NULL;
BT_CHECK_PARAMETER(device_address, return);
goto fail;
}
- if (!dbus_g_proxy_begin_call(adapter_proxy, "RemoveDevice",
- (DBusGProxyCallNotify) __bt_unbond_cb,
- (gpointer)unbonding_info, NULL,
- DBUS_TYPE_G_OBJECT_PATH, device_path,
- G_TYPE_INVALID)) {
- BT_ERR("RemoveBonding begin failed\n");
+ conn = _bt_gdbus_get_system_gconn();
+ if (conn == NULL) {
+ BT_ERR("conn is NULL");
+ result = BLUETOOTH_ERROR_INTERNAL;
goto fail;
}
+
+ device_proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
+ NULL, BT_BLUEZ_NAME,
+ device_path, BT_PROPERTIES_INTERFACE, NULL, NULL);
+
+ if (device_proxy != NULL) {
+
+ ret = g_dbus_proxy_call_sync(device_proxy, "Get",
+ g_variant_new("(ss)", BT_DEVICE_INTERFACE, "Paired"),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ &error);
+ if (error) {
+ BT_ERR("Getting property failed: [%s]\n", error->message);
+ g_error_free(error);
+ result = BLUETOOTH_ERROR_NOT_PAIRED;
+ goto fail;
+ } else {
+ if (!ret) {
+ BT_ERR("No paired device");
+ g_object_unref(device_proxy);
+ result = BLUETOOTH_ERROR_NOT_PAIRED;
+ goto fail;
+ }
+ g_variant_unref(ret);
+ }
+ g_object_unref(device_proxy);
+ }
+
+ g_dbus_proxy_call(adapter_proxy, "UnpairDevice",
+ g_variant_new("(o)", device_path),
+ G_DBUS_CALL_FLAGS_NONE,
+ BT_MAX_DBUS_TIMEOUT,
+ NULL,
+ (GAsyncReadyCallback)__bt_unbond_cb,
+ unbonding_info);
+
g_free(device_path);
return BLUETOOTH_ERROR_NONE;
return result;
}
-static void __bt_discover_cb(DBusGProxy *proxy, DBusGProxyCall *call,
- gpointer user_data)
+static void __bt_discover_cb(GDBusProxy *proxy, GAsyncResult *res,
+ gpointer user_data)
{
GError *err = NULL;
- GHashTable *hash = NULL;
- GArray *out_param1;
- GArray *out_param2;
- GValue uuid_v = { 0 };
+ GVariant *reply;
+ GVariant *out_param1;
int result = BLUETOOTH_ERROR_NONE;
bluetooth_device_info_t dev_info;
bt_remote_dev_info_t *remote_dev_info;
request_info_t *req_info;
+ GVariant *uuid_list, *manufacture_data;
+ GVariant *param;
+ GVariantBuilder *builder = NULL;
+ int i = 0;
- dbus_g_proxy_end_call(proxy, call, &err,
- G_TYPE_VALUE, &uuid_v,
- G_TYPE_INVALID);
+ reply = g_dbus_proxy_call_finish(proxy, res, &err);
+ if (reply)
+ g_variant_unref(reply);
g_object_unref(proxy);
if (searching_info == NULL) {
/* Send reply */
- BT_ERR("searching_info == NULL");
+ BT_ERR("unbonding_info == NULL");
goto done;
}
}
if (err != NULL) {
+ g_dbus_error_strip_remote_error(err);
BT_ERR("Error occured in Proxy call [%s]\n", err->message);
- if (!strcmp("Operation canceled", err->message)) {
+ if (g_strrstr("Operation canceled", err->message))
result = BLUETOOTH_ERROR_CANCEL_BY_USER;
- } else if (!strcmp("In Progress", err->message)) {
+ else if (g_strrstr("In Progress", err->message))
result = BLUETOOTH_ERROR_IN_PROGRESS;
- } else if (!strcmp("Host is down", err->message)) {
+ else if (g_strrstr("Host is down", err->message))
result = BLUETOOTH_ERROR_HOST_DOWN;
- } else {
+ else
result = BLUETOOTH_ERROR_CONNECTION_ERROR;
- }
if (result == BLUETOOTH_ERROR_HOST_DOWN ||
result == BLUETOOTH_ERROR_CONNECTION_ERROR) {
}
remote_dev_info = _bt_get_remote_device_info(searching_info->addr);
+ if (!remote_dev_info)
+ goto dbus_return;
event:
- /* Send the event to application */
- if (remote_dev_info != NULL) {
- _bt_send_event(BT_ADAPTER_EVENT,
- BLUETOOTH_EVENT_SERVICE_SEARCHED,
- DBUS_TYPE_INT32, &result,
- DBUS_TYPE_STRING, &searching_info->addr,
- DBUS_TYPE_UINT32, &remote_dev_info->class,
- DBUS_TYPE_INT16, &remote_dev_info->rssi,
- DBUS_TYPE_STRING, &remote_dev_info->name,
- DBUS_TYPE_BOOLEAN, &remote_dev_info->paired,
- DBUS_TYPE_BOOLEAN, &remote_dev_info->connected,
- DBUS_TYPE_BOOLEAN, &remote_dev_info->trust,
- DBUS_TYPE_ARRAY, DBUS_TYPE_STRING,
- &remote_dev_info->uuids, remote_dev_info->uuid_count,
- DBUS_TYPE_INVALID);
-
- _bt_free_device_info(remote_dev_info);
- }
-
-dbus_return:
- if (req_info->context == NULL)
- goto done;
-
- out_param1 = g_array_new(FALSE, FALSE, sizeof(gchar));
- out_param2 = g_array_new(FALSE, FALSE, sizeof(gchar));
-
- memset(&dev_info, 0x00, sizeof(bluetooth_device_info_t));
- _bt_convert_addr_string_to_type(dev_info.device_address.addr,
- searching_info->addr);
-
- g_array_append_vals(out_param1, &dev_info,
- sizeof(bluetooth_device_info_t));
- g_array_append_vals(out_param2, &result, sizeof(int));
-
- dbus_g_method_return(req_info->context, out_param1, out_param2);
-
- g_array_free(out_param1, TRUE);
- g_array_free(out_param2, TRUE);
-
- _bt_delete_request_list(req_info->req_id);
-done:
- if (err)
- g_error_free(err);
-
- g_hash_table_destroy(hash);
-
- if (searching_info) {
- g_free(searching_info->addr);
- g_free(searching_info);
- searching_info = NULL;
- }
-}
-
-static void __bt_create_device_cb(DBusGProxy *proxy, DBusGProxyCall *call,
- gpointer user_data)
-{
- GError *err = NULL;
- char *device_path = NULL;
- GArray *out_param1;
- GArray *out_param2;
- int result = BLUETOOTH_ERROR_NONE;
- bluetooth_device_info_t dev_info;
- bt_remote_dev_info_t *remote_dev_info;
- request_info_t *req_info;
-
- is_deivce_creating = FALSE;
-
- dbus_g_proxy_end_call(proxy, call, &err,
- DBUS_TYPE_G_OBJECT_PATH, &device_path,
- G_TYPE_INVALID);
- g_free(device_path);
- if (searching_info == NULL) {
- /* Send reply */
- BT_ERR("searching_info == NULL");
- goto done;
- }
-
- req_info = _bt_get_request_info(searching_info->req_id);
- if (req_info == NULL) {
- BT_ERR("req_info == NULL");
- goto done;
+ 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]);
}
-
- if (err != NULL) {
- BT_ERR("Error occured in Proxy call [%s]\n", err->message);
- result = BLUETOOTH_ERROR_CONNECTION_ERROR;
- goto dbus_return;
- }
-
- remote_dev_info = _bt_get_remote_device_info(searching_info->addr);
+ uuid_list = 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,
+ searching_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,
+ uuid_list,
+ remote_dev_info->manufacturer_data_len,
+ manufacture_data);
/* Send the event to application */
- if (remote_dev_info != NULL) {
- _bt_send_event(BT_ADAPTER_EVENT,
- BLUETOOTH_EVENT_SERVICE_SEARCHED,
- DBUS_TYPE_INT32, &result,
- DBUS_TYPE_STRING, &searching_info->addr,
- DBUS_TYPE_UINT32, &remote_dev_info->class,
- DBUS_TYPE_INT16, &remote_dev_info->rssi,
- DBUS_TYPE_STRING, &remote_dev_info->name,
- DBUS_TYPE_BOOLEAN, &remote_dev_info->paired,
- DBUS_TYPE_BOOLEAN, &remote_dev_info->connected,
- DBUS_TYPE_BOOLEAN, &remote_dev_info->trust,
- DBUS_TYPE_ARRAY, DBUS_TYPE_STRING,
- &remote_dev_info->uuids, remote_dev_info->uuid_count,
- DBUS_TYPE_INVALID);
+ _bt_send_event(BT_ADAPTER_EVENT,
+ BLUETOOTH_EVENT_SERVICE_SEARCHED,
+ param);
- _bt_free_device_info(remote_dev_info);
- }
+ _bt_free_device_info(remote_dev_info);
dbus_return:
if (req_info->context == NULL)
goto done;
- out_param1 = g_array_new(FALSE, FALSE, sizeof(gchar));
- out_param2 = g_array_new(FALSE, FALSE, sizeof(gchar));
-
memset(&dev_info, 0x00, sizeof(bluetooth_device_info_t));
_bt_convert_addr_string_to_type(dev_info.device_address.addr,
searching_info->addr);
- g_array_append_vals(out_param1, &dev_info,
- sizeof(bluetooth_device_info_t));
- g_array_append_vals(out_param2, &result, sizeof(int));
+ out_param1 = g_variant_new_from_data((const GVariantType *)"ay",
+ &dev_info, sizeof(bluetooth_device_info_t), TRUE, NULL, NULL);
- dbus_g_method_return(req_info->context, out_param1, out_param2);
+ g_dbus_method_invocation_return_value(req_info->context,
+ g_variant_new("(iv)", result, out_param1));
- g_array_free(out_param1, TRUE);
- g_array_free(out_param2, TRUE);
_bt_delete_request_list(req_info->req_id);
done:
bluetooth_device_address_t *device_address)
{
char *device_path = NULL;
- DBusGProxy *adapter_proxy;
- DBusGProxy *device_proxy = NULL;
- DBusGConnection *conn;
+ GDBusProxy *device_proxy = NULL;
+ GDBusConnection *conn;
+
+ GDBusProxy *adapter_proxy;
int result = BLUETOOTH_ERROR_INTERNAL;
BT_CHECK_PARAMETER(device_address, return);
+ if (bonding_info) {
+ BT_ERR("Bonding in progress");
+ return BLUETOOTH_ERROR_DEVICE_BUSY;
+ }
+
if (searching_info) {
BT_ERR("Service searching in progress");
return BLUETOOTH_ERROR_DEVICE_BUSY;
adapter_proxy = _bt_get_adapter_proxy();
retv_if(adapter_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
- conn = _bt_get_system_gconn();
- retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
-
/* allocate user data so that it can be retrieved in callback */
searching_info = g_malloc0(sizeof(bt_funcion_data_t));
searching_info->addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
_bt_convert_addr_type_to_string(searching_info->addr,
device_address->addr);
+ conn = _bt_gdbus_get_system_gconn();
+ retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
+
+
device_path = _bt_get_device_object_path(searching_info->addr);
if (device_path == NULL) {
- /* Not support this function in bluez 5.2 */
BT_ERR("No paired device");
+ result = BLUETOOTH_ERROR_NOT_PAIRED;
goto fail;
-
- is_deivce_creating = TRUE;
-
- if (!dbus_g_proxy_begin_call(adapter_proxy,
- "CreateDevice",
- (DBusGProxyCallNotify)__bt_create_device_cb,
- (gpointer)searching_info, NULL,
- G_TYPE_STRING, searching_info->addr,
- G_TYPE_INVALID)) {
- BT_ERR("CreateDevice failed");
- result = BLUETOOTH_ERROR_INTERNAL;
- is_deivce_creating = FALSE;
- goto fail;
- }
-
- searching_info->adapter_proxy = device_proxy;
-
- return BLUETOOTH_ERROR_NONE;
}
- device_proxy = dbus_g_proxy_new_for_name(conn, BT_BLUEZ_NAME,
- device_path, BT_PROPERTIES_INTERFACE);
+ device_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);
if (device_proxy == NULL) {
result = BLUETOOTH_ERROR_INTERNAL;
goto fail;
}
- if (!dbus_g_proxy_begin_call(device_proxy, "Get",
- (DBusGProxyCallNotify)__bt_discover_cb,
- (gpointer)searching_info, NULL,
- G_TYPE_STRING, BT_DEVICE_INTERFACE,
- G_TYPE_STRING, "UUIDs",
- G_TYPE_INVALID)) {
- BT_ERR("DiscoverServices failed");
- goto fail;
- }
+ g_dbus_proxy_call(device_proxy, "DiscoverServices",
+ g_variant_new("(s)", ""),
+ G_DBUS_CALL_FLAGS_NONE,
+ BT_MAX_DBUS_TIMEOUT,
+ NULL,
+ (GAsyncReadyCallback)__bt_discover_cb,
+ searching_info);
searching_info->device_proxy = device_proxy;
return BLUETOOTH_ERROR_NONE;
fail:
- if (device_proxy)
- g_object_unref(device_proxy);
g_free(searching_info->addr);
g_free(searching_info);
int _bt_cancel_search_device(void)
{
+ GVariant *ret = NULL;
GError *err = NULL;
retv_if(searching_info == NULL, BLUETOOTH_ERROR_NOT_IN_OPERATION);
if (searching_info->device_proxy) {
- dbus_g_proxy_call(searching_info->device_proxy,
- "CancelDiscovery",
- &err,
- G_TYPE_INVALID, G_TYPE_INVALID);
- } else if (searching_info->adapter_proxy) {
- dbus_g_proxy_call(searching_info->adapter_proxy,
- "CancelDeviceCreation",
- &err,
- G_TYPE_STRING, searching_info->addr,
- G_TYPE_INVALID);
- } else {
- BT_ERR("No proxy info");
- return BLUETOOTH_ERROR_NOT_IN_OPERATION;
- }
-
- if (err != NULL) {
- BT_ERR("Error occured [%s]\n", err->message);
- g_error_free(err);
- return BLUETOOTH_ERROR_INTERNAL;
+ ret = g_dbus_proxy_call_sync(searching_info->device_proxy, "CancelDiscovery",
+ NULL,
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ &err);
+ if (ret)
+ g_variant_unref(ret);
}
-
__bt_cancel_search_service_done();
return BLUETOOTH_ERROR_NONE;
{
char address[BT_ADDRESS_STRING_SIZE] = { 0 };
gchar *device_path = NULL;
- DBusGProxy *adapter_proxy;
- DBusGProxy *device_proxy;
+ GDBusProxy *adapter_proxy;
+ GDBusProxy *device_proxy;
+ GVariant *ret = NULL;
GError *error = NULL;
- GValue name = { 0 };
- DBusGConnection *conn;
+ GDBusConnection *conn;
BT_CHECK_PARAMETER(device_address, return);
BT_CHECK_PARAMETER(alias, return);
adapter_proxy = _bt_get_adapter_proxy();
retv_if(adapter_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
- conn = _bt_get_system_gconn();
+ conn = _bt_gdbus_get_system_gconn();
retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
_bt_convert_addr_type_to_string(address, device_address->addr);
return BLUETOOTH_ERROR_NOT_PAIRED;
}
- device_proxy = dbus_g_proxy_new_for_name(conn, BT_BLUEZ_NAME,
- device_path, BT_PROPERTIES_INTERFACE);
+ device_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(device_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
- g_value_init(&name, G_TYPE_STRING);
- g_value_set_string(&name, alias);
- dbus_g_proxy_call(device_proxy, "Set", &error,
- G_TYPE_STRING, BT_DEVICE_INTERFACE,
- G_TYPE_STRING, "Alias",
- G_TYPE_VALUE, &name,
- G_TYPE_INVALID, G_TYPE_INVALID);
+ ret = g_dbus_proxy_call_sync(device_proxy, "Set",
+ g_variant_new("(ssv)", BT_DEVICE_INTERFACE, "Alias", g_variant_new("s", alias)),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ &error);
+ if (ret)
+ g_variant_unref(ret);
g_object_unref(device_proxy);
- g_value_unset(&name);
-
if (error) {
BT_ERR("SetProperty error: [%s]", error->message);
g_error_free(error);
{
char address[BT_ADDRESS_STRING_SIZE] = { 0 };
gchar *device_path = NULL;
- DBusGProxy *device_proxy;
+ GDBusProxy *device_proxy;
gboolean previous_value;
GError *error = NULL;
- GValue trusted = { 0 };
- GValue trusted_v = { 0 };
- DBusGConnection *conn;
+ GDBusConnection *conn;
+ GVariant *result = NULL;
+ GVariant *temp = NULL;
int ret = BLUETOOTH_ERROR_NONE;
BT_CHECK_PARAMETER(device_address, return);
- conn = _bt_get_system_gconn();
+ conn = _bt_gdbus_get_system_gconn();
retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
_bt_convert_addr_type_to_string(address, device_address->addr);
return BLUETOOTH_ERROR_NOT_PAIRED;
}
- device_proxy = dbus_g_proxy_new_for_name(conn, BT_BLUEZ_NAME,
- device_path, BT_PROPERTIES_INTERFACE);
+ device_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(device_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
- if (!dbus_g_proxy_call(device_proxy, "Get", &error,
- G_TYPE_STRING, BT_DEVICE_INTERFACE,
- G_TYPE_STRING, "Trusted",
- G_TYPE_INVALID,
- G_TYPE_VALUE, &trusted_v,
- G_TYPE_INVALID)) {
- if (error != NULL) {
- BT_ERR("Getting property failed: [%s]\n", error->message);
- g_error_free(error);
- }
+ result = g_dbus_proxy_call_sync(device_proxy, "Get",
+ g_variant_new("(ss)", BT_DEVICE_INTERFACE, "Trusted"),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ &error);
+ if (error != NULL) {
+ BT_ERR("Getting property failed: [%s]\n", error->message);
+ g_error_free(error);
g_object_unref(device_proxy);
return BLUETOOTH_ERROR_INTERNAL;
}
- previous_value = g_value_get_boolean(&trusted_v);
-
+ g_variant_get(result, "(v)", &temp);
+ previous_value = g_variant_get_boolean(temp);
+ g_variant_unref(temp);
+ g_variant_unref(result);
/* If the input is same with previous value, return error. */
if (previous_value == authorize) {
BT_ERR("Same value: %d", previous_value);
goto done;
}
- g_value_init(&trusted, G_TYPE_BOOLEAN);
- g_value_set_boolean(&trusted, authorize);
-
- dbus_g_proxy_call(device_proxy, "Set", &error,
- G_TYPE_STRING, BT_DEVICE_INTERFACE,
- G_TYPE_STRING, "Trusted",
- G_TYPE_VALUE, &trusted,
- G_TYPE_INVALID, G_TYPE_INVALID);
+ result = g_dbus_proxy_call_sync(device_proxy, "Set",
+ g_variant_new("(ssv)", BT_DEVICE_INTERFACE, "Trusted", g_variant_new("b", authorize)),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ &error);
g_object_unref(device_proxy);
- g_value_unset(&trusted);
-
if (error) {
BT_ERR("SetProperty error: [%s]", error->message);
g_error_free(error);
ret = BLUETOOTH_ERROR_INTERNAL;
}
done:
+ if (result)
+ g_variant_unref(result);
+
+ return ret;
+}
+
+int _bt_is_gatt_connected(bluetooth_device_address_t *device_address,
+ gboolean *is_connected)
+{
+ char address[BT_ADDRESS_STRING_SIZE] = { 0 };
+ char *object_path = NULL;
+
+ GDBusProxy *device_proxy;
+ GError *error = NULL;
+ GVariant *value;
+ GDBusConnection *conn;
+ GVariant *result = NULL;
+ int ret = BLUETOOTH_ERROR_NONE;
+
+ BT_CHECK_PARAMETER(device_address, return);
+
+ conn = _bt_gdbus_get_system_gconn();
+ retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
+
+ _bt_convert_addr_type_to_string(address, device_address->addr);
+
+ object_path = _bt_get_device_object_path(address);
+ retv_if(object_path == NULL, BLUETOOTH_ERROR_NOT_PAIRED);
+
+ device_proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
+ NULL, BT_BLUEZ_NAME, object_path,
+ BT_PROPERTIES_INTERFACE, NULL, NULL);
+ g_free(object_path);
+ retv_if(device_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
+
+ result = g_dbus_proxy_call_sync(device_proxy, "Get",
+ g_variant_new("(ss)", BT_DEVICE_INTERFACE,
+ "GattConnected"),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ &error);
+ if (result == NULL) {
+ if (error != NULL) {
+ BT_ERR("Error occured in Proxy call [%s]\n", error->message);
+ g_error_free(error);
+ }
+ g_object_unref(device_proxy);
+ return BLUETOOTH_ERROR_INTERNAL;
+ }
+
+ g_variant_get(result, "(v)", &value);
+ *is_connected = g_variant_get_boolean(value);
+ g_variant_unref(result);
+
+ BT_DBG("gatt is connected : %d", *is_connected);
+
+ g_variant_unref(value);
+ g_object_unref(device_proxy);
+
return ret;
}
{
char *object_path = NULL;
char address[BT_ADDRESS_STRING_SIZE] = { 0 };
- DBusGProxy *device_proxy = NULL;
- DBusGProxy *adapter_proxy = NULL;
- DBusGConnection *conn;
+ char secure_address[BT_ADDRESS_STRING_SIZE] = { 0 };
+ GDBusProxy *device_proxy = NULL;
+ GDBusProxy *adapter_proxy = NULL;
+ GDBusConnection *conn;
GError *error = NULL;
- GHashTable *hash = NULL;
- GValue *value = NULL;
- char *interface = NULL;
+ GVariant *tmp_value = NULL;
+ GVariant *value = NULL;
+ GVariant *result = NULL;
+ char *uuid = NULL;
retv_if(device_address == NULL, BLUETOOTH_ERROR_INVALID_PARAM);
retv_if(is_connected == NULL, BLUETOOTH_ERROR_INVALID_PARAM);
+ _bt_convert_addr_type_to_string(address, device_address->addr);
+ _bt_convert_addr_string_to_secure_string(secure_address, address);
+
+ *is_connected = FALSE;
+ BT_DBG("%s connection_type: 0x%02x", secure_address, connection_type);
+
if (connection_type == BLUETOOTH_RFCOMM_SERVICE)
return _bt_rfcomm_is_device_connected(device_address,
is_connected);
+ else if (connection_type == BLUETOOTH_GATT_SERVICE)
+ return _bt_is_gatt_connected(device_address, is_connected);
+ else if (connection_type == BLUETOOTH_PBAP_SERVICE)
+ return _bt_pbap_is_connected(device_address, is_connected);
adapter_proxy = _bt_get_adapter_proxy();
retv_if(adapter_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
- conn = _bt_get_system_gconn();
+ conn = _bt_gdbus_get_system_gconn();
retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
_bt_convert_addr_type_to_string(address, device_address->addr);
- dbus_g_proxy_call(adapter_proxy, "FindDevice",
- &error, G_TYPE_STRING, address,
- G_TYPE_INVALID, DBUS_TYPE_G_OBJECT_PATH,
- &object_path, G_TYPE_INVALID);
+ if (connection_type == BLUETOOTH_NAP_SERVER_SERVICE) {
+ object_path = _bt_get_adapter_path();
+ device_proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
+ NULL, BT_BLUEZ_NAME,
+ object_path, BT_NETWORK_SERVER_INTERFACE, NULL, NULL);
+ g_free(object_path);
+ if (device_proxy == NULL) {
+ BT_DBG("Device don't have this service");
+ return BLUETOOTH_ERROR_INTERNAL;
+ }
- if (error != NULL) {
- BT_ERR("Failed to Find device: %s", error->message);
- g_error_free(error);
- return BLUETOOTH_ERROR_NOT_PAIRED;
+ result = g_dbus_proxy_call_sync(device_proxy, "GetProperties",
+ g_variant_new("(s)", address),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ &error);
+
+ if (result == NULL) {
+ BT_ERR("[GetProperties] Error occured in Proxy call");
+ if (error) {
+ BT_ERR("%s", error->message);
+ g_error_free(error);
+ }
+ *is_connected = FALSE;
+ g_object_unref(device_proxy);
+ return BLUETOOTH_ERROR_NONE;
+ }
+ g_variant_get(result , "(@a{sv})", &value);
+ g_variant_unref(result);
+
+ if (value) {
+ tmp_value = g_variant_lookup_value(value,
+ "Connected",
+ G_VARIANT_TYPE_BOOLEAN);
+ if (tmp_value) {
+ *is_connected = g_variant_get_boolean(tmp_value);
+ g_variant_unref(tmp_value);
+ }
+ g_variant_unref(value);
+ }
+ } else if (connection_type == BLUETOOTH_NAP_SERVICE) {
+ return _bt_is_network_connected(_bt_get_net_conn(),
+ device_address->addr, is_connected);
+ } else {
+ uuid = _bt_get_profile_uuid128(connection_type);
+ if (uuid == NULL) {
+ BT_ERR("connection_type: %d, uuid is NULL", connection_type);
+ return BLUETOOTH_ERROR_INTERNAL;
+ }
+ BT_DBG("uuid %s [%s]", uuid, _bt_convert_uuid_to_string(uuid));
+
+ object_path = _bt_get_device_object_path(address);
+ 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);
+ g_free(object_path);
+ if (device_proxy == NULL) {
+ BT_DBG("Device don't have this service");
+ g_free(uuid);
+ return BLUETOOTH_ERROR_INTERNAL;
+ }
+
+ result = g_dbus_proxy_call_sync(device_proxy, "IsConnectedProfile",
+ g_variant_new("(s)", uuid),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ &error);
+
+ if (result == NULL) {
+ BT_ERR("[IsConnectedProfile] Error occured in Proxy call");
+ if (error) {
+ BT_ERR("%s", error->message);
+ if (g_strrstr(error->message, "Not Connected"))
+ BT_DBG("Not connected");
+ g_error_free(error);
+ }
+ *is_connected = FALSE;
+ g_object_unref(device_proxy);
+ g_free(uuid);
+ return BLUETOOTH_ERROR_NONE;
+ }
+ g_variant_get(result, "(b)", is_connected);
+ g_free(uuid);
+ g_variant_unref(result);
}
- retv_if(object_path == NULL, BLUETOOTH_ERROR_INTERNAL);
+ g_object_unref(device_proxy);
+ return BLUETOOTH_ERROR_NONE;
+}
- switch (connection_type) {
- case BLUETOOTH_HSP_SERVICE:
- interface = BT_HFP_AGENT_INTERFACE;
- break;
- case BLUETOOTH_A2DP_SERVICE:
- interface = BT_SINK_INTERFACE;
- break;
- case BLUETOOTH_HID_SERVICE:
- interface = BT_INPUT_INTERFACE;
- break;
- default:
- BT_DBG("Unknown type!");
- g_free(object_path);
- return BLUETOOTH_ERROR_INVALID_PARAM;
- }
+int _bt_get_connected_link(bluetooth_device_address_t *device_address,
+ bluetooth_connected_link_t *connected)
+{
+ char address[BT_ADDRESS_STRING_SIZE] = { 0 };
+ char *object_path = NULL;
+
+ GDBusProxy *device_proxy;
+ GError *error = NULL;
+ GDBusConnection *conn;
+ GVariant *value = NULL;
+ GVariant *result = NULL;
+
+ BT_CHECK_PARAMETER(device_address, return);
+
+ conn = _bt_gdbus_get_system_gconn();
+ retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
+
+ _bt_convert_addr_type_to_string(address, device_address->addr);
- BT_DBG("Interface name: %s", interface);
+ object_path = _bt_get_device_object_path(address);
+ retv_if(object_path == NULL, BLUETOOTH_ERROR_NOT_PAIRED);
- device_proxy = dbus_g_proxy_new_for_name(conn, BT_BLUEZ_NAME, object_path, interface);
+ device_proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
+ NULL, BT_BLUEZ_NAME,
+ object_path, BT_PROPERTIES_INTERFACE, NULL, NULL);
g_free(object_path);
if (device_proxy == NULL) {
- BT_DBG("Device don't have this service");
- is_connected = FALSE;
+ *connected = BLUETOOTH_CONNECTED_LINK_NONE;
return BLUETOOTH_ERROR_NONE;
}
- dbus_g_proxy_call(device_proxy, "GetProperties", &error,
- G_TYPE_INVALID,
- dbus_g_type_get_map("GHashTable", G_TYPE_STRING, G_TYPE_VALUE),
- &hash, G_TYPE_INVALID);
+
+ result = g_dbus_proxy_call_sync(device_proxy, "Get",
+ g_variant_new("(ss)", BT_DEVICE_INTERFACE, "Connected"),
+ G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
if (error != NULL) {
- BT_DBG("Failed to get properties: %s\n", error->message);
+ BT_ERR("Error occured in Proxy call [%s]\n", error->message);
g_error_free(error);
g_object_unref(device_proxy);
- is_connected = FALSE;
- return BLUETOOTH_ERROR_NONE;
- }
-
- if (hash != NULL) {
- value = g_hash_table_lookup(hash, "Connected");
- *is_connected = value ? g_value_get_boolean(value) : FALSE;
- g_hash_table_destroy(hash);
+ return BLUETOOTH_ERROR_INTERNAL;
} else {
- *is_connected = FALSE;
+ g_variant_get(result, "(v)", &value);
+ *connected = g_variant_get_byte(value);
+ g_variant_unref(value);
+ g_variant_unref(result);
}
g_object_unref(device_proxy);
return BLUETOOTH_ERROR_NONE;
}
+static void __le_connection_req_cb(GDBusProxy *proxy, GAsyncResult *res,
+ gpointer user_data)
+{
+ GError *err = NULL;
+ GVariant *out_param1;
+ GVariant *reply;
+ int result = BLUETOOTH_ERROR_NONE;
+ bt_function_data_t *func_data = user_data;
+ request_info_t *req_info = NULL;
+ bluetooth_device_address_t device_addr = { {0} };
+
+ reply = g_dbus_proxy_call_finish(proxy, res, &err);
+ g_object_unref(proxy);
+
+ if (reply == NULL) {
+ BT_ERR("ConnectLE / DisconnectLE DBus call error");
+ if (err) {
+ BT_ERR("Error: %s", err->message);
+ g_clear_error(&err);
+ }
+ result = BLUETOOTH_ERROR_INTERNAL;
+ } else {
+ g_variant_unref(reply);
+ }
+
+ if (func_data == NULL) {
+ BT_ERR("func_data is NULL");
+ goto done;
+ }
+
+ req_info = _bt_get_request_info(func_data->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");
+ goto done;
+ }
+
+ _bt_convert_addr_string_to_type(device_addr.addr,
+ (const char *)func_data->address);
+
+ out_param1 = g_variant_new_from_data((const GVariantType *)"ay",
+ &device_addr, sizeof(bluetooth_device_address_t), TRUE,
+ NULL, NULL);
+
+ g_dbus_method_invocation_return_value(req_info->context,
+ g_variant_new("(iv)", result, out_param1));
+
+done:
+ if (req_info)
+ _bt_delete_request_list(req_info->req_id);
+
+ if (func_data) {
+ g_free(func_data->address);
+ g_free(func_data);
+ }
+}
+
+static int __bt_connect_le_device_internal(int req_id, const bluetooth_device_address_t *bd_addr,
+ gboolean auto_connect)
+{
+ char device_address[BT_ADDRESS_STRING_SIZE] = { 0 };
+ char secure_address[BT_ADDRESS_STRING_SIZE] = { 0 };
+ gchar *device_path = NULL;
+ GDBusProxy *device_proxy = NULL;
+ GDBusConnection *conn;
+ int ret = BLUETOOTH_ERROR_NONE;
+ bt_function_data_t *func_data;
+
+ BT_CHECK_PARAMETER(bd_addr, return);
+
+ conn = _bt_gdbus_get_system_gconn();
+ retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
+
+ _bt_convert_addr_type_to_string(device_address,
+ (unsigned char *)bd_addr->addr);
+ device_path = _bt_get_device_object_path(device_address);
+ if (device_path == NULL) {
+ BT_ERR_C("device_path NULL : [%s]", device_address);
+ ret = BLUETOOTH_ERROR_INTERNAL;
+ return ret;
+ }
+
+ device_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(device_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
+
+ func_data = g_malloc0(sizeof(bt_function_data_t));
+ func_data->address = g_strdup(device_address);
+ if (func_data->address == NULL) {
+ BT_ERR("Unable to allocate memory for address");
+ ret = BLUETOOTH_ERROR_MEMORY_ALLOCATION;
+ goto fail;
+ }
+
+ _bt_convert_addr_string_to_secure_string(secure_address, device_address);
+ BT_INFO("Connect LE [%s]", secure_address);
+
+ func_data->req_id = req_id;
+
+ g_dbus_proxy_call(device_proxy, "ConnectLE",
+ g_variant_new("(b)", auto_connect),
+ G_DBUS_CALL_FLAGS_NONE,
+ BT_MAX_DBUS_TIMEOUT,
+ NULL,
+ (GAsyncReadyCallback)__le_connection_req_cb, func_data);
+
+ return ret;
+
+fail:
+ if (device_proxy)
+ g_object_unref(device_proxy);
+
+ g_free(func_data->address);
+ g_free(func_data);
+
+ return ret;
+}
+
+static gboolean __bt_connect_le_timer_cb(gpointer user_data)
+{
+ BT_INFO("Try to initiate pending LE connection");
+
+ pending_le_conn_timer_id = 0;
+
+ __bt_connect_le_device_internal(pending_le_conn_info->req_id,
+ &pending_le_conn_info->bd_addr,
+ pending_le_conn_info->auto_connect);
+
+ g_free(pending_le_conn_info);
+ pending_le_conn_info = NULL;
+
+ return FALSE;
+}
+
+void _bt_pending_connect_le_device(void)
+{
+ if (pending_le_conn_timer_id > 0) {
+ g_source_remove(pending_le_conn_timer_id);
+ __bt_connect_le_timer_cb(NULL);
+ }
+}
+
+int _bt_connect_le_device(int req_id, const bluetooth_device_address_t *bd_addr,
+ gboolean auto_connect)
+{
+ int ret = BLUETOOTH_ERROR_NONE;
+
+ BT_CHECK_PARAMETER(bd_addr, return);
+
+ ret = _bt_hold_current_advertising();
+ if (ret == BLUETOOTH_ERROR_NONE) {
+ BT_INFO("Current advertising is held");
+ pending_le_conn_info = g_malloc0(sizeof(bt_pending_le_conn_info_s));
+ pending_le_conn_info->req_id = req_id;
+ memcpy(pending_le_conn_info->bd_addr.addr, bd_addr->addr,
+ BLUETOOTH_ADDRESS_LENGTH);
+ pending_le_conn_info->auto_connect = auto_connect;
+
+ pending_le_conn_timer_id =
+ g_timeout_add(1000, __bt_connect_le_timer_cb, NULL);
+
+ return BLUETOOTH_ERROR_NONE;
+ } else if (ret != BLUETOOTH_ERROR_NOT_IN_OPERATION) {
+ BT_ERR("Unable to hold advertising");
+ }
+
+ return __bt_connect_le_device_internal(req_id, bd_addr, auto_connect);
+}
+
+int _bt_disconnect_le_device(int req_id,
+ const bluetooth_device_address_t *bd_addr)
+{
+ char device_address[BT_ADDRESS_STRING_SIZE] = { 0 };
+ char secure_address[BT_ADDRESS_STRING_SIZE] = { 0 };
+ gchar *device_path;
+ GDBusProxy *device_proxy;
+ GDBusConnection *conn;
+ int ret = BLUETOOTH_ERROR_NONE;
+ bt_function_data_t *func_data;
+
+ BT_CHECK_PARAMETER(bd_addr, return);
+
+ conn = _bt_gdbus_get_system_gconn();
+ retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
+
+ _bt_convert_addr_type_to_string(device_address,
+ (unsigned char *)bd_addr->addr);
+ device_path = _bt_get_device_object_path(device_address);
+ if (device_path == NULL) {
+ BT_DBG("device_path NULL");
+ ret = BLUETOOTH_ERROR_INTERNAL;
+ return ret;
+ }
+
+ retv_if(device_path == NULL, BLUETOOTH_ERROR_INTERNAL);
+
+ device_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(device_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
+
+ func_data = g_malloc0(sizeof(bt_function_data_t));
+ func_data->address = g_strdup(device_address);
+ if (func_data->address == NULL) {
+ BT_ERR("Unable to allocate memory for address");
+ ret = BLUETOOTH_ERROR_MEMORY_ALLOCATION;
+ goto fail;
+ }
+
+ _bt_convert_addr_string_to_secure_string(secure_address, device_address);
+ BT_INFO("Disconnect LE [%s]", secure_address);
+
+ func_data->req_id = req_id;
+
+ g_dbus_proxy_call(device_proxy, "DisconnectLE",
+ NULL,
+ G_DBUS_CALL_FLAGS_NONE,
+ BT_MAX_DBUS_TIMEOUT,
+ NULL,
+ (GAsyncReadyCallback)__le_connection_req_cb, func_data);
+ return ret;
+
+fail:
+ if (device_proxy)
+ g_object_unref(device_proxy);
+
+ g_free(func_data->address);
+ g_free(func_data);
+
+ return ret;
+}
+
+int _bt_connect_le_ipsp_device(const bluetooth_device_address_t *bd_addr)
+{
+ char device_address[BT_ADDRESS_STRING_SIZE] = { 0 };
+ gchar *device_path = NULL;
+ GError *error = NULL;
+ GDBusProxy *device_proxy = NULL;
+ GDBusProxy *adapter_proxy;
+ GDBusConnection *conn;
+ int ret = BLUETOOTH_ERROR_NONE;
+
+ BT_CHECK_PARAMETER(bd_addr, return);
+
+ _bt_convert_addr_type_to_string(device_address,
+ (unsigned char *)bd_addr->addr);
+
+ conn = _bt_gdbus_get_system_gconn();
+ retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
+
+ adapter_proxy = _bt_get_adapter_proxy();
+ retv_if(adapter_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
+
+ device_path = _bt_get_device_object_path(device_address);
+ if (device_path == NULL) {
+ BT_DBG("device_path NULL");
+ ret = BLUETOOTH_ERROR_INTERNAL;
+ return ret;
+ }
+
+ retv_if(device_path == NULL, BLUETOOTH_ERROR_INTERNAL);
+
+ device_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(device_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
+
+ 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;
+ }
+
+ g_object_unref(device_proxy);
+
+ return ret;
+}
+
+int _bt_disconnect_le_ipsp_device(const bluetooth_device_address_t *bd_addr)
+{
+ char device_address[BT_ADDRESS_STRING_SIZE] = { 0 };
+ gchar *device_path = NULL;
+ GError *error = NULL;
+ GDBusProxy *device_proxy = NULL;
+ GDBusProxy *adapter_proxy;
+ GDBusConnection *conn;
+ int ret = BLUETOOTH_ERROR_NONE;
+
+ BT_CHECK_PARAMETER(bd_addr, return);
+
+ _bt_convert_addr_type_to_string(device_address,
+ (unsigned char *)bd_addr->addr);
+
+ conn = _bt_gdbus_get_system_gconn();
+ retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
+
+ adapter_proxy = _bt_get_adapter_proxy();
+ retv_if(adapter_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
+
+ device_path = _bt_get_device_object_path(device_address);
+ if (device_path == NULL) {
+ BT_DBG("device_path NULL");
+ ret = BLUETOOTH_ERROR_INTERNAL;
+ return ret;
+ }
+
+ retv_if(device_path == NULL, BLUETOOTH_ERROR_INTERNAL);
+
+ device_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(device_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
+
+ 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;
+ }
+
+ g_object_unref(device_proxy);
+
+ return ret;
+}
+
+int _bt_connect_profile(char *address, char *uuid,
+ void *cb, gpointer func_data)
+{
+ char *object_path;
+ GDBusProxy *proxy;
+ GDBusConnection *conn;
+ GDBusProxy *adapter_proxy;
+ GVariant *result = NULL;
+ GError *error = NULL;
+
+ conn = _bt_gdbus_get_system_gconn();
+ retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
+
+ object_path = _bt_get_device_object_path(address);
+ if (object_path == NULL) {
+ BT_ERR("No searched device");
+
+ adapter_proxy = _bt_get_adapter_proxy();
+ retv_if(adapter_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
+
+ result = g_dbus_proxy_call_sync(adapter_proxy, "CreateDevice",
+ g_variant_new("(s)", address),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ &error);
+
+ if (error != NULL) {
+ BT_ERR("CreateDevice Fail: %s", error->message);
+ g_error_free(error);
+ }
+ if (result)
+ g_variant_unref(result);
+
+ object_path = _bt_get_device_object_path(address);
+ }
+ retv_if(object_path == NULL, BLUETOOTH_ERROR_INTERNAL);
+
+ proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
+ NULL, BT_BLUEZ_NAME,
+ object_path, BT_DEVICE_INTERFACE, NULL, NULL);
+ g_free(object_path);
+ retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
+
+ g_dbus_proxy_call(proxy, "ConnectProfile",
+ g_variant_new("(s)", uuid),
+ G_DBUS_CALL_FLAGS_NONE,
+ BT_MAX_DBUS_TIMEOUT,
+ NULL,
+ (GAsyncReadyCallback)cb,
+ func_data);
+
+ return BLUETOOTH_ERROR_NONE;
+}
+
+int _bt_disconnect_all(char *address)
+{
+ int ret = BLUETOOTH_ERROR_NONE;
+ char *object_path;
+ GDBusProxy *proxy;
+ GDBusConnection *conn;
+ GVariant *result = NULL;
+ GError *err = NULL;
+
+ BT_DBG("");
+ conn = _bt_gdbus_get_system_gconn();
+ retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
+
+ object_path = _bt_get_device_object_path(address);
+ retv_if(object_path == NULL, BLUETOOTH_ERROR_INTERNAL);
+
+ proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
+ NULL, BT_BLUEZ_NAME,
+ object_path, BT_DEVICE_INTERFACE, NULL, NULL);
+ g_free(object_path);
+ retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
+
+ result = g_dbus_proxy_call_sync(proxy, "Disconnect",
+ NULL,
+ G_DBUS_CALL_FLAGS_NONE,
+ -1, NULL,
+ &err);
+
+ if (err != NULL) {
+ BT_ERR("Dbus Call Error:[%s]", err->message);
+ g_error_free(err);
+ ret = BLUETOOTH_ERROR_INTERNAL;
+ }
+
+ g_object_unref(proxy);
+ if (result)
+ g_variant_unref(result);
+
+ return ret;
+}
+
+int _bt_disconnect_profile(char *address, char *uuid,
+ void *cb, gpointer func_data)
+{
+ char *object_path;
+ GDBusProxy *proxy;
+ GDBusConnection *conn;
+
+ conn = _bt_gdbus_get_system_gconn();
+ retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
+
+ object_path = _bt_get_device_object_path(address);
+ retv_if(object_path == NULL, BLUETOOTH_ERROR_INTERNAL);
+
+ proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
+ NULL, BT_BLUEZ_NAME,
+ object_path, BT_DEVICE_INTERFACE, NULL, NULL);
+ g_free(object_path);
+ retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
+
+ g_dbus_proxy_call(proxy, "DisconnectProfile",
+ g_variant_new("(s)", uuid),
+ G_DBUS_CALL_FLAGS_NONE,
+ BT_MAX_DBUS_TIMEOUT,
+ NULL,
+ (GAsyncReadyCallback)cb,
+ func_data);
+
+ return BLUETOOTH_ERROR_NONE;
+}
+
+int _bt_enable_rssi(bluetooth_device_address_t *bd_addr, int link_type,
+ int low_threshold, int in_range_threshold, int high_threshold)
+{
+ int ret = BLUETOOTH_ERROR_NONE;
+ GDBusProxy *proxy;
+ GVariant *result = NULL;
+ GError *error = NULL;
+ char address[BT_ADDRESS_STRING_SIZE] = { 0 };
+
+ BT_CHECK_PARAMETER(bd_addr, return);
+ BT_DBG("BD Address [%2.2X %2.2X %2.2X %2.2X %2.2X %2.2X] Link Type[%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],
+ link_type);
+ BT_DBG("Enable RSSI: [Threshold %d %d %d]", low_threshold,
+ in_range_threshold, high_threshold);
+
+ _bt_convert_addr_type_to_string(address, bd_addr->addr);
+
+ proxy = _bt_get_adapter_proxy();
+ retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
+
+ result = g_dbus_proxy_call_sync(proxy, "EnableRssi",
+ g_variant_new("(siiii)", address, link_type, low_threshold, in_range_threshold, high_threshold),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ &error);
+ if (error != NULL) {
+ BT_ERR("Dbus Call Error:[%s]", error->message);
+ g_error_free(error);
+ ret = BLUETOOTH_ERROR_INTERNAL;
+ }
+
+ if (result)
+ g_variant_unref(result);
+
+ return ret;
+}
+
+int _bt_get_rssi_strength(bluetooth_device_address_t *bd_addr,
+ int link_type)
+{
+ int ret = BLUETOOTH_ERROR_NONE;
+ GDBusProxy *proxy;
+ GVariant *result = NULL;
+ GError *error = NULL;
+ char address[BT_ADDRESS_STRING_SIZE] = { 0 };
+
+ BT_CHECK_PARAMETER(bd_addr, return);
+ BT_DBG("BD Address [%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X] Link Type[%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],
+ link_type);
+
+ _bt_convert_addr_type_to_string(address, bd_addr->addr);
+
+ proxy = _bt_get_adapter_proxy();
+ retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
+
+ result = g_dbus_proxy_call_sync(proxy, "GetRssiStrength",
+ g_variant_new("(si)", address, link_type),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ &error);
+
+ if (error != NULL) {
+ BT_ERR("Dbus Call Error:[%s]", error->message);
+ g_error_free(error);
+ ret = BLUETOOTH_ERROR_INTERNAL;
+ }
+
+ if (result)
+ g_variant_unref(result);
+
+ return ret;
+}
+
+static int __bt_le_set_conn_parameter(const char *address,
+ float interval_min, float interval_max,
+ guint16 latency, guint16 time_out)
+{
+ gchar *device_path = NULL;
+ GError *error = NULL;
+ GDBusProxy *device_proxy = NULL;
+ GDBusConnection *conn;
+ GVariant *reply;
+ guint32 min, max, to;
+ int ret = BLUETOOTH_ERROR_NONE;
+
+ BT_CHECK_PARAMETER(address, return);
+
+ BT_INFO("Min interval: %f, Max interval: %f, Latency: %u, Supervision timeout: %u",
+ interval_min, interval_max, latency, time_out);
+
+ device_path = _bt_get_device_object_path((char *)address);
+
+ if (device_path == NULL) {
+ BT_ERR("device_path NULL");
+ ret = BLUETOOTH_ERROR_INTERNAL;
+ goto fail;
+ }
+
+ conn = _bt_gdbus_get_system_gconn();
+ if (conn == NULL) {
+ BT_ERR("conn NULL");
+ ret = BLUETOOTH_ERROR_INTERNAL;
+ goto fail;
+ }
+
+ device_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(device_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
+
+ min = interval_min / BT_LE_CONN_INTERVAL_SPLIT;
+ max = interval_max / BT_LE_CONN_INTERVAL_SPLIT;
+ to = time_out / BT_LE_CONN_TO_SPLIT;
+
+ reply = g_dbus_proxy_call_sync(device_proxy, "LeConnUpdate",
+ g_variant_new("(uuuu)", min, max, latency, to),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ &error);
+
+ g_object_unref(device_proxy);
+ if (reply == NULL) {
+ if (error) {
+ BT_ERR("Error %s[%s]", error->message, address);
+ if (g_strrstr(error->message, "In Progress"))
+ ret = BLUETOOTH_ERROR_IN_PROGRESS;
+ else
+ ret = BLUETOOTH_ERROR_INTERNAL;
+ g_error_free(error);
+ return ret;
+ }
+ }
+ g_variant_unref(reply);
+
+fail:
+ return ret;
+}
+
+static void __bt_le_conn_param_free(void *data)
+{
+ bt_le_conn_param_t *param = (bt_le_conn_param_t *)data;
+
+ BT_DBG("%s", param->sender);
+ g_free(param->sender);
+ g_free(param);
+}
+
+static gint __bt_compare_le_conn_param_key(gpointer *a, gpointer *b)
+{
+ bt_le_conn_param_t *parama = (bt_le_conn_param_t *)a;
+ bt_le_conn_param_t *paramb = (bt_le_conn_param_t *)b;
+
+ return parama->key > paramb->key;
+}
+
+static bt_connected_le_dev_t *__bt_get_le_connected_dev_info(const char *address)
+{
+ GSList *l = NULL;
+ bt_connected_le_dev_t *dev;
+
+ if (!address)
+ return NULL;
+
+ for (l = le_connected_dev_list; l; l = g_slist_next(l)) {
+ dev = l->data;
+
+ if (g_strcmp0(dev->address, address) == 0)
+ return dev;
+ }
+ return NULL;
+}
+
+static bt_le_conn_param_t *__bt_get_le_conn_param_info(bt_connected_le_dev_t *dev, const char *sender)
+{
+ GSList *l = NULL;
+ bt_le_conn_param_t *param = NULL;
+
+ if (!dev || !sender)
+ return NULL;
+
+ for (l = dev->senders; l; l = g_slist_next(l)) {
+ param = l->data;
+ if (g_strcmp0(param->sender, sender) == 0)
+ return param;
+ }
+
+ return NULL;
+}
+
+int _bt_add_le_conn_param_info(const char *address, const char *sender,
+ float interval_min, float interval_max, guint16 latency, guint16 time_out)
+{
+ bt_connected_le_dev_t *dev = NULL;
+ bt_le_conn_param_t *param = NULL;
+ bt_le_conn_param_t *data = NULL;
+
+ if (!address || !sender)
+ return BLUETOOTH_ERROR_INVALID_PARAM;
+
+ dev = __bt_get_le_connected_dev_info(address);
+ if (!dev)
+ return BLUETOOTH_ERROR_INTERNAL;
+
+ param = __bt_get_le_conn_param_info(dev, sender);
+
+ data = g_malloc0(sizeof(bt_le_conn_param_t));
+ data->sender = g_strdup(sender);
+ data->interval_min = interval_min;
+ data->interval_max = interval_max;
+ data->latency = latency;
+ data->time_out = time_out;
+ data->key = interval_min + (interval_max - interval_min)/2;
+
+ if (param == NULL) {
+ BT_DBG("Add param %s %s %f %f", address, sender, interval_min, interval_max);
+ dev->senders = g_slist_append(dev->senders, data);
+ } else {
+ BT_DBG("Update param %s %s %f %f", address, sender, interval_min, interval_max);
+ dev->senders = g_slist_remove(dev->senders, param);
+ g_free(param->sender);
+ g_free(param);
+ dev->senders = g_slist_append(dev->senders, data);
+ }
+
+ /* Sorting. First element have the minimum interval */
+ dev->senders = g_slist_sort(dev->senders,
+ (GCompareFunc)__bt_compare_le_conn_param_key);
+
+ return BLUETOOTH_ERROR_NONE;
+}
+
+int _bt_remove_le_conn_param_info(const char *address, const char *sender, gboolean *is_removed)
+{
+ bt_connected_le_dev_t *dev = NULL;
+ bt_le_conn_param_t *param = NULL;
+
+ if (!address || !sender)
+ return BLUETOOTH_ERROR_INVALID_PARAM;
+
+ dev = __bt_get_le_connected_dev_info(address);
+ if (!dev)
+ return BLUETOOTH_ERROR_INTERNAL;
+
+ param = __bt_get_le_conn_param_info(dev, sender);
+ if (param) {
+ BT_DBG("Remove param %s %s ", address, sender);
+ dev->senders = g_slist_remove(dev->senders, param);
+ g_free(param->sender);
+ g_free(param);
+ *is_removed = TRUE;
+ } else
+ *is_removed = FALSE;
+
+ return BLUETOOTH_ERROR_NONE;
+}
+
+int _bt_remove_all_le_conn_param_info(const char *sender)
+{
+ GSList *l = NULL;
+ bt_connected_le_dev_t *dev = NULL;
+ bt_le_conn_param_t *param = NULL;
+ gboolean is_removed = FALSE;
+ char *sender_new = NULL;
+ unsigned char addr[BLUETOOTH_ADDRESS_LENGTH];
+ int ret = BLUETOOTH_ERROR_NONE;
+
+ if (!sender)
+ return BLUETOOTH_ERROR_INVALID_PARAM;
+
+ for (l = le_connected_dev_list; l; l = g_slist_next(l)) {
+ dev = l->data;
+ _bt_remove_le_conn_param_info(dev->address, sender, &is_removed);
+
+ if (is_removed) {
+ BT_INFO("Sender terminated. Update le conn interval [senders %d]",
+ g_slist_length(dev->senders));
+ if (g_slist_length(dev->senders) > 0) {
+ param = dev->senders->data;
+ BT_DBG("dev %f %f, param %f %f", dev->interval_min, dev->interval_max,
+ param->interval_min, param->interval_max);
+
+ if (dev->interval_min != param->interval_min ||
+ dev->interval_max != param->interval_max) {
+ sender_new = g_strdup(param->sender);
+
+ _bt_convert_addr_string_to_type(addr, dev->address);
+ ret = _bt_le_conn_update(sender_new, addr,
+ param->interval_min, param->interval_max,
+ param->latency, param->time_out);
+ g_free(sender_new);
+
+ if (ret != BLUETOOTH_ERROR_NONE)
+ BT_ERR("Unable to set le connection parameter");
+ }
+ } else {
+ BT_INFO("Set the default interval");
+
+ bluetooth_le_connection_param_t param = { 0 };
+ _bt_get_le_connection_parameter(
+ BLUETOOTH_LE_CONNECTION_MODE_LOW_POWER,
+ ¶m);
+
+ ret = __bt_le_set_conn_parameter(dev->address,
+ param.interval_min, param.interval_max,
+ param.latency, param.timeout);
+ if (ret == BLUETOOTH_ERROR_NONE) {
+ dev->interval_min = param.interval_min;
+ dev->interval_max = param.interval_max;
+ }
+ }
+ }
+ }
+
+ return ret;
+}
+
+void _bt_add_le_connected_dev_info(const char *address)
+{
+ bt_connected_le_dev_t *dev = NULL;
+
+ if (!address)
+ return;
+
+ dev = g_malloc0(sizeof(bt_connected_le_dev_t));
+ dev->address = g_strdup(address);
+
+ le_connected_dev_list = g_slist_append(le_connected_dev_list, dev);
+
+ return;
+}
+
+void _bt_remove_le_connected_dev_info(const char *address)
+{
+ bt_connected_le_dev_t *dev = NULL;
+
+ if (!address)
+ return;
+
+ dev = __bt_get_le_connected_dev_info(address);
+ if (!dev)
+ return;
+
+ g_slist_free_full(dev->senders, __bt_le_conn_param_free);
+ le_connected_dev_list = g_slist_remove(le_connected_dev_list, dev);
+ g_free(dev->address);
+ g_free(dev);
+
+ return;
+}
+
+int _bt_le_conn_update(const char *sender,
+ unsigned char *device_address,
+ float interval_min, float interval_max,
+ guint16 latency, guint16 time_out)
+{
+ char address[BT_ADDRESS_STRING_SIZE] = { 0 };
+ guint32 min_supervision_to;
+ bt_connected_le_dev_t *dev = NULL;
+ bt_le_conn_param_t *param = NULL;
+ gboolean is_removed = FALSE;
+ int ret = BLUETOOTH_ERROR_NONE;
+
+ BT_CHECK_PARAMETER(device_address, return);
+
+ 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 ||
+ interval_min < BT_LE_CONN_INTERVAL_MIN ||
+ interval_max > BT_LE_CONN_INTERVAL_MAX) {
+ ret = BLUETOOTH_ERROR_INVALID_PARAM;
+ goto fail;
+ }
+
+ if (time_out < BT_LE_CONN_SUPER_TO_MIN ||
+ time_out > BT_LE_CONN_SUPER_TO_MAX) {
+ ret = BLUETOOTH_ERROR_INVALID_PARAM;
+ goto fail;
+ }
+
+ if (latency > BT_LE_CONN_SLAVE_LATENCY_MAX) {
+ ret = BLUETOOTH_ERROR_INVALID_PARAM;
+ goto fail;
+ }
+
+ /*
+ * The Supervision_Timeout in milliseconds shall be larger than
+ * (1 + Conn_Latency) * Conn_Interval_Max * 2,
+ * where Conn_Interval_Max is given in milliseconds.
+ */
+ min_supervision_to = (1 + latency) * interval_max * 2;
+ if (time_out <= min_supervision_to) {
+ ret = BLUETOOTH_ERROR_INVALID_PARAM;
+ goto fail;
+ }
+
+ _bt_convert_addr_type_to_string(address, device_address);
+ BT_DBG("Remote device address: %s", address);
+
+ _bt_add_le_conn_param_info(address, sender, interval_min, interval_max, 0, 2000);
+
+ dev = __bt_get_le_connected_dev_info(address);
+ if (dev == NULL) {
+ ret = BLUETOOTH_ERROR_NOT_CONNECTED;
+ goto fail;
+ }
+
+ if (g_slist_length(dev->senders) == 1)
+ goto update;
+ else {
+ param = dev->senders->data;
+
+ BT_DBG("dev %f, param %f, input %f", dev->interval_min, param->interval_min, interval_min);
+
+ if (dev->interval_min == param->interval_min && dev->interval_max == param->interval_max) {
+ BT_DBG("Skip due to same interval");
+ return ret;
+ }
+
+ interval_min = param->interval_min;
+ interval_max = param->interval_max;
+ }
+
+update:
+ ret = __bt_le_set_conn_parameter(address, interval_min, interval_max, latency, time_out);
+
+ if (ret != BLUETOOTH_ERROR_NONE) {
+ _bt_remove_le_conn_param_info(address, sender, &is_removed);
+ return ret;
+ }
+
+ dev->interval_min = interval_min;
+ dev->interval_max = interval_max;
+
+fail:
+ return ret;
+}
+
+int _bt_set_pin_code(bluetooth_device_address_t *device_address,
+ bluetooth_device_pin_code_t *pin_code)
+{
+ char address[BT_ADDRESS_STRING_SIZE] = { 0 };
+ GSList *l = NULL;
+ bt_pin_code_info_t *pin_info = NULL;
+
+ BT_CHECK_PARAMETER(device_address, return);
+ BT_CHECK_PARAMETER(pin_code, return);
+ retv_if(g_slist_length(pin_info_list) >= BT_DEVICE_PIN_CODE_SLOT_MAX,
+ BLUETOOTH_ERROR_NO_RESOURCES);
+
+ _bt_convert_addr_type_to_string(address, device_address->addr);
+
+ for (l = pin_info_list; l != NULL; l = l->next) {
+ pin_info = l->data;
+
+ if (g_strcmp0(pin_info->address, address) == 0) {
+ g_free(pin_info->pin_code);
+ pin_info->pin_code = g_strdup(pin_code->pin_code);
+ return BLUETOOTH_ERROR_NONE;
+ }
+ }
+
+ pin_info = g_malloc0(sizeof(bt_pin_code_info_t));
+ pin_info->address = g_strdup(address);
+ pin_info->pin_code = g_strdup(pin_code->pin_code);
+ pin_info_list = g_slist_append(pin_info_list, pin_info);
+
+ return BLUETOOTH_ERROR_NONE;
+}
+
+gint __bt_compare_address(gpointer *a, gpointer *b)
+{
+ bt_pin_code_info_t *pin_info = (bt_pin_code_info_t *)a;
+ char *address = (char *)b;
+ return g_strcmp0(pin_info->address, address);
+}
+
+int _bt_unset_pin_code(bluetooth_device_address_t *device_address)
+{
+ char address[BT_ADDRESS_STRING_SIZE] = { 0 };
+ GSList *l = NULL;
+ bt_pin_code_info_t *pin_info = NULL;
+
+ BT_CHECK_PARAMETER(device_address, return);
+
+ _bt_convert_addr_type_to_string(address, device_address->addr);
+
+ l = g_slist_find_custom(pin_info_list, address,
+ (GCompareFunc)__bt_compare_address);
+ if (l)
+ pin_info = l->data;
+ if (pin_info) {
+ pin_info_list = g_slist_remove(pin_info_list, pin_info);
+ g_free(pin_info->address);
+ g_free(pin_info->pin_code);
+ g_free(pin_info);
+ }
+
+ return BLUETOOTH_ERROR_NONE;
+}
+
+int _bt_get_device_pin_code(const char *address, char *pin_code)
+{
+ GSList *l = NULL;
+
+ BT_CHECK_PARAMETER(address, return);
+ BT_CHECK_PARAMETER(pin_code, return);
+
+ for (l = pin_info_list; l != NULL; l = l->next) {
+ bt_pin_code_info_t *pin_info = l->data;
+
+ if (g_strcmp0(pin_info->address, address) == 0) {
+ g_strlcpy(pin_code, pin_info->pin_code,
+ BLUETOOTH_PIN_CODE_MAX_LENGTH + 1);
+
+ return BLUETOOTH_ERROR_NONE;
+ }
+ }
+
+ return BLUETOOTH_ERROR_NOT_FOUND;
+}
+
+int _bt_get_le_connection_parameter(bluetooth_le_connection_mode_t mode,
+ bluetooth_le_connection_param_t *param)
+{
+ if (param == NULL)
+ return BLUETOOTH_ERROR_INVALID_PARAM;
+
+ if (mode < BLUETOOTH_LE_CONNECTION_MODE_BALANCED ||
+ mode > BLUETOOTH_LE_CONNECTION_MODE_LOW_POWER)
+ return BLUETOOTH_ERROR_INVALID_PARAM;
+
+ memset(param, 0x00, sizeof(bluetooth_le_connection_param_t));
+
+ switch (mode) {
+ case BLUETOOTH_LE_CONNECTION_MODE_BALANCED:
+ param->interval_min = BT_LE_CONN_PARAM_BALANCED_MIN_INTERVAL;
+ param->interval_max = BT_LE_CONN_PARAM_BALANCED_MAX_INTERVAL;
+ param->latency = BT_LE_CONN_PARAM_BALANCED_SLAVE_LATENCY;
+ param->timeout = BT_LE_CONN_PARAM_DEFAULT_SUPERVISION_TIMEOUT;
+ break;
+
+ case BLUETOOTH_LE_CONNECTION_MODE_LOW_LATENCY:
+ param->interval_min = BT_LE_CONN_PARAM_LOW_LATENCY_MIN_INTERVAL;
+ param->interval_max = BT_LE_CONN_PARAM_LOW_LATENCY_MAX_INTERVAL;
+ param->latency = BT_LE_CONN_PARAM_LOW_LATENCY_SLAVE_LATENCY;
+ param->timeout = BT_LE_CONN_PARAM_DEFAULT_SUPERVISION_TIMEOUT;
+ break;
+
+ case BLUETOOTH_LE_CONNECTION_MODE_LOW_POWER:
+ param->interval_min = BT_LE_CONN_PARAM_LOW_POWER_MIN_INTERVAL;
+ param->interval_max = BT_LE_CONN_PARAM_LOW_POWER_MAX_INTERVAL;
+ param->latency = BT_LE_CONN_PARAM_LOW_POWER_SLAVE_LATENCY;
+ param->timeout = BT_LE_CONN_PARAM_DEFAULT_SUPERVISION_TIMEOUT;
+ break;
+
+ default:
+ BT_ERR("Unhandled mode : %d", mode);
+ break;
+ }
+
+ return BLUETOOTH_ERROR_NONE;
+}
+
+int _bt_get_trusted_profile_from_flag(bluetooth_trusted_profile_t profile,
+ guint trusted_profile_flag, guint *trusted)
+{
+ int trust_profile;
+ *trusted = FALSE;
+
+ switch (profile) {
+ case TRUSTED_PROFILE_PBAP:
+ if (trusted_profile_flag & (PROFILE_SUPPORTED << 0))
+ trust_profile = trusted_profile_flag & (1 << 1);
+ else
+ return BLUETOOTH_ERROR_NOT_SUPPORT;
+ break;
+ case TRUSTED_PROFILE_MAP:
+ if (trusted_profile_flag & (PROFILE_SUPPORTED << 2))
+ trust_profile = trusted_profile_flag & (1 << 3);
+ else
+ return BLUETOOTH_ERROR_NOT_SUPPORT;
+ break;
+ case TRUSTED_PROFILE_SAP:
+ if (trusted_profile_flag & (PROFILE_SUPPORTED << 4))
+ trust_profile = trusted_profile_flag & (1 << 5);
+ else
+ return BLUETOOTH_ERROR_NOT_SUPPORT;
+ break;
+ case TRUSTED_PROFILE_ALL: /* Return Flag for All profiles*/
+ *trusted = trusted_profile_flag;
+ return BLUETOOTH_ERROR_NONE;
+ default:
+ return BLUETOOTH_ERROR_NOT_SUPPORT;
+ }
+
+ if (trust_profile)
+ *trusted = TRUE;
+
+ 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) {
+ case TRUSTED_PROFILE_PBAP:
+ return g_strdup("00001130-0000-1000-8000-00805f9b34fb");
+ case TRUSTED_PROFILE_MAP:
+ return g_strdup("00001134-0000-1000-8000-00805f9b34fb");
+ case TRUSTED_PROFILE_SAP:
+ return g_strdup("0000112D-0000-1000-8000-00805f9b34fb");
+ case TRUSTED_PROFILE_ALL:
+ return NULL;
+ }
+
+ 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)
+ return TRUSTED_PROFILE_PBAP;
+ else if (g_strcmp0("00001132-0000-1000-8000-00805f9b34fb", uuid) == 0)
+ return TRUSTED_PROFILE_MAP;
+ else if (g_strcmp0("0000112D-0000-1000-8000-00805f9b34fb", uuid) == 0)
+ return TRUSTED_PROFILE_SAP;
+
+ return 0; /* 0 - Unknown Profile */
+}
+
+int _bt_set_trust_profile(bluetooth_device_address_t *bd_addr,
+ bluetooth_trusted_profile_t profile, gboolean trust)
+{
+ 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] trust[%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, trust);
+
+ 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_trusted_profile_uuid(profile);
+ if (uuid == NULL) {
+ g_object_unref(proxy);
+ return BLUETOOTH_ERROR_NOT_SUPPORT;
+ }
+
+ reply = g_dbus_proxy_call_sync(proxy, "SetTrustedProfile",
+ g_variant_new("(sb)", uuid, trust),
+ G_DBUS_CALL_FLAGS_NONE, -1,
+ NULL, &error);
+ g_object_unref(proxy);
+
+ if (reply == NULL) {
+ BT_ERR("Failed to Set Profile Trusted");
+ 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_trust_profile(bluetooth_device_address_t *bd_addr,
+ bluetooth_trusted_profile_t profile, guint *trust)
+{
+ int ret = BLUETOOTH_ERROR_NONE;
+ GDBusConnection *conn;
+ GDBusProxy *proxy;
+ GError *error = NULL;
+ char *device_path = NULL;
+ guint trusted_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] trust[%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, *trust);
+
+ 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, "TrustedProfiles"),
+ G_DBUS_CALL_FLAGS_NONE, -1,
+ NULL, &error);
+ g_object_unref(proxy);
+
+ if (reply == NULL) {
+ BT_ERR("Failed to Get Profile Trusted");
+ ret = BLUETOOTH_ERROR_INTERNAL;
+ if (error) {
+ BT_ERR("Error %s[%s]", error->message, address);
+ g_error_free(error);
+ }
+ *trust = 0;
+ } else {
+ GVariant *temp;
+ g_variant_get(reply, "(v)", &temp);
+ trusted_profile_flag = g_variant_get_uint32(temp);
+ BT_DBG("TRUST_FLAG %d", trusted_profile_flag);
+
+ ret = _bt_get_trusted_profile_from_flag(profile,
+ trusted_profile_flag, trust);
+ g_variant_unref(temp);
+ g_variant_unref(reply);
+ }
+
+ BT_DBG("TRUST %d", *trust);
+ 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)
+{
+ GError *err = NULL;
+ GVariant *out_param1;
+ request_info_t *req_info;
+ GVariant *val = NULL;
+ GVariant *param = NULL;
+ guint8 status = 0;
+ guint16 mtu = 0;
+ bluetooth_device_address_t device_addr = { {0} };
+ int result = BLUETOOTH_ERROR_NONE;
+
+ BT_DBG("+");
+ val = g_dbus_proxy_call_finish(proxy, res, &err);
+
+ req_info = _bt_get_request_info(att_mtu_req_info->req_id);
+ if (req_info == NULL) {
+ BT_ERR("req_info == NULL");
+ g_object_unref(proxy);
+ att_mtu_req_info->device_proxy = NULL;
+ goto done;
+ }
+
+ if (err != NULL) {
+ BT_ERR("Error occured in RequestAttMtu [%s]", err->message);
+
+ if (g_strrstr(err->message, "NotSupported")) {
+ BT_INFO("Connection Not Supported");
+ result = BLUETOOTH_ERROR_NOT_SUPPORT;
+ } else if (g_strrstr(err->message, "NotConnected")) {
+ BT_INFO("Not connected");
+ result = BLUETOOTH_ERROR_NOT_CONNECTED;
+ } else if (g_strrstr(err->message, "InvalidArguments")) {
+ BT_INFO("Not connected");
+ result = BLUETOOTH_ERROR_INVALID_PARAM;
+ } else {
+ BT_DBG("Default case");
+ result = BLUETOOTH_ERROR_INTERNAL;
+ }
+ }
+
+ g_object_unref(proxy);
+ att_mtu_req_info->device_proxy = NULL;
+
+ if (result != BLUETOOTH_ERROR_NONE)
+ goto dbus_return;
+
+ if (val) {
+ g_variant_get(val, "(qy)", &mtu, &status);
+ g_variant_unref(val);
+ }
+
+ BT_DBG("MTU %d, Status %d, %s", mtu, status, att_mtu_req_info->addr);
+
+ param = g_variant_new("(isqy)",
+ result,
+ att_mtu_req_info->addr,
+ mtu,
+ status);
+
+ /* Send the event to application */
+ _bt_send_event(BT_DEVICE_EVENT,
+ BLUETOOTH_EVENT_GATT_ATT_MTU_CHANGED,
+ param);
+
+dbus_return:
+ if (req_info->context == NULL)
+ goto done;
+
+ _bt_convert_addr_string_to_type(device_addr.addr,
+ (const char *)att_mtu_req_info->addr);
+
+ out_param1 = g_variant_new_from_data((const GVariantType *)"ay",
+ &device_addr, sizeof(bluetooth_device_address_t), TRUE, NULL, NULL);
+ g_dbus_method_invocation_return_value(req_info->context,
+ g_variant_new("(iv)", result, out_param1));
+
+ _bt_delete_request_list(req_info->req_id);
+done:
+ if (err)
+ g_error_free(err);
+
+ g_free(att_mtu_req_info->addr);
+ g_free(att_mtu_req_info);
+ att_mtu_req_info = NULL;
+
+ BT_DBG("-");
+}
+
+int _bt_request_att_mtu(int request_id, bluetooth_device_address_t *device_address,
+ unsigned int mtu)
+{
+ char address[BT_ADDRESS_STRING_SIZE] = { 0 };
+ gchar *device_path = NULL;
+ GDBusProxy *adapter_proxy;
+ GDBusProxy *device_proxy;
+ GDBusConnection *conn;
+ int ret = BLUETOOTH_ERROR_NONE;
+
+ BT_CHECK_PARAMETER(device_address, return);
+
+ if (att_mtu_req_info) {
+ BT_ERR("ATT MTU request in progress");
+ return BLUETOOTH_ERROR_DEVICE_BUSY;
+ }
+
+ conn = _bt_gdbus_get_system_gconn();
+ retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
+
+ adapter_proxy = _bt_get_adapter_proxy();
+ retv_if(adapter_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
+
+ _bt_convert_addr_type_to_string(address, device_address->addr);
+
+ BT_DBG("Remote device address: %s", address);
+
+ device_path = _bt_get_device_object_path(address);
+
+ retv_if(device_path == NULL, BLUETOOTH_ERROR_INTERNAL);
+
+ device_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(device_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
+
+ att_mtu_req_info = g_malloc0(sizeof(bt_funcion_data_t));
+ att_mtu_req_info->addr = (char *)g_strdup(address);
+ att_mtu_req_info->req_id = request_id;
+ att_mtu_req_info->device_proxy = device_proxy;
+
+ g_dbus_proxy_call(device_proxy, "RequestAttMtu",
+ g_variant_new("(q)", mtu),
+ G_DBUS_CALL_FLAGS_NONE,
+ BT_MAX_DBUS_TIMEOUT,
+ NULL,
+ (GAsyncReadyCallback)__bt_request_att_mtu_device_cb,
+ NULL);
+
+ return ret;
+}
+
+int _bt_get_att_mtu(bluetooth_device_address_t *device_address,
+ unsigned int *mtu)
+{
+ char address[BT_ADDRESS_STRING_SIZE] = { 0 };
+ char *object_path = NULL;
+
+ GDBusProxy *device_proxy;
+ GError *error = NULL;
+ GVariant *value;
+ GDBusConnection *conn;
+ GVariant *result = NULL;
+
+ BT_CHECK_PARAMETER(device_address, return);
+
+ conn = _bt_gdbus_get_system_gconn();
+ retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
+
+ _bt_convert_addr_type_to_string(address, device_address->addr);
+
+ object_path = _bt_get_device_object_path(address);
+ retv_if(object_path == NULL, BLUETOOTH_ERROR_NOT_PAIRED);
+
+ device_proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
+ NULL, BT_BLUEZ_NAME, object_path,
+ BT_PROPERTIES_INTERFACE, NULL, NULL);
+ g_free(object_path);
+ retv_if(device_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
+
+ result = g_dbus_proxy_call_sync(device_proxy, "Get",
+ g_variant_new("(ss)", BT_DEVICE_INTERFACE, "AttMtu"),
+ G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
+ if (error) {
+ ERR("DBus Error : %s", error->message);
+ g_clear_error(&error);
+ g_object_unref(device_proxy);
+ return BLUETOOTH_ERROR_INTERNAL;
+ } else {
+ g_variant_get(result, "(v)", &value);
+ *mtu = g_variant_get_uint16(value);
+ 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);
+ return BLUETOOTH_ERROR_NONE;
+}
+
+int _bt_get_device_ida(bluetooth_device_address_t *device_address,
+ bluetooth_device_address_t *id_address)
+{
+ char address[BT_ADDRESS_STRING_SIZE] = { 0 };
+ gchar *device_path = NULL;
+ const gchar *idaddress = NULL;
+ GDBusProxy *device_proxy;
+ GError *error = NULL;
+ GVariant *result = NULL;
+ GDBusConnection *conn;
+ int ret = BLUETOOTH_ERROR_NONE;
+
+ BT_CHECK_PARAMETER(device_address, return);
+
+ conn = _bt_gdbus_get_system_gconn();
+ retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
+
+ _bt_convert_addr_type_to_string(address, device_address->addr);
+
+ device_path = _bt_get_device_object_path(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);
+ 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);
+ if (result == NULL) {
+ BT_ERR("Failed to get device ID address");
+
+ ret = BLUETOOTH_ERROR_INTERNAL;
+ if (error != NULL) {
+ 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 ret;
+ }
+
+ g_variant_get(result , "(&s)", &idaddress);
+
+ 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;
+}
+
+int _bt_passkey_reply(const char *passkey, gboolean authentication_reply)
+{
+ GapAgentPrivate *agent = _bt_get_adapter_agent();
+ retv_if(!agent, BLUETOOTH_ERROR_INTERNAL);
+
+ if (authentication_reply)
+ gap_agent_reply_pin_code(agent, GAP_AGENT_ACCEPT, passkey, NULL);
+ else
+ gap_agent_reply_pin_code(agent, GAP_AGENT_REJECT, passkey, NULL);
+
+ BT_DBG("BT_PASSKEY_REPLY");
+ return BLUETOOTH_ERROR_NONE;
+}
+
+int _bt_passkey_confirmation_reply(gboolean confirmation_reply)
+{
+ GapAgentPrivate *agent = _bt_get_adapter_agent();
+ retv_if(!agent, BLUETOOTH_ERROR_INTERNAL);
+
+ if (confirmation_reply)
+ gap_agent_reply_confirmation(agent, GAP_AGENT_ACCEPT, NULL);
+ else
+ gap_agent_reply_confirmation(agent, GAP_AGENT_REJECT, NULL);
+
+ BT_DBG("BT_PASSKEY_CONFIRMATION_REPLY");
+ return BLUETOOTH_ERROR_NONE;
+}