/*
- * 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 <dlog.h>
#include <string.h>
+#include <gio/gio.h>
#include "bluetooth-api.h"
#include "bt-service-common.h"
int _bt_oob_read_local_data(bt_oob_data_t *local_oob_data)
{
- DBusMessage *msg;
- DBusMessage *reply;
- DBusError err;
+ GDBusProxy *proxy;
+ GVariant *reply;
+ GError *err = NULL;
char *adapter_path;
unsigned char *local_hash = NULL;
unsigned char *local_randomizer = NULL;
- DBusConnection *conn;
+ GDBusConnection *conn;
+ GVariant *hash = NULL;
+ GVariant *randomizer = NULL;
BT_CHECK_PARAMETER(local_oob_data, return);
adapter_path = _bt_get_adapter_path();
retv_if(adapter_path == NULL, BLUETOOTH_ERROR_INTERNAL);
- msg = dbus_message_new_method_call(BT_BLUEZ_NAME, adapter_path,
- BT_OOB_INTERFACE, "ReadLocalData");
+ proxy = g_dbus_proxy_new_sync(conn,
+ G_DBUS_PROXY_FLAGS_NONE, NULL,
+ BT_BLUEZ_NAME, adapter_path,
+ BT_OOB_INTERFACE, NULL, &err);
g_free(adapter_path);
+ if (!proxy) {
+ BT_ERR("Unable to create proxy");
+ if (err) {
+ BT_ERR("Error: %s", err->message);
+ g_clear_error(&err);
+ }
+ return BLUETOOTH_ERROR_INTERNAL;
+ }
- retv_if(msg == NULL, BLUETOOTH_ERROR_INTERNAL);
+ reply = g_dbus_proxy_call_sync(proxy, "ReadLocalData",
+ NULL,
+ G_DBUS_CALL_FLAGS_NONE, -1,
+ NULL, &err);
+ g_object_unref(proxy);
+
+ if (reply == NULL) {
+ BT_ERR("ReadLocalData dBUS-RPC is failed");
+ if (err != NULL) {
+ BT_ERR("D-Bus API failure: errCode[%x], message[%s]",
+ err->code, err->message);
+ g_clear_error(&err);
+ }
+ return BLUETOOTH_ERROR_INTERNAL;
+ }
- dbus_error_init(&err);
- reply = dbus_connection_send_with_reply_and_block(conn,
- msg, -1, &err);
+ g_variant_get(reply, "(@ay@ay)", &hash, &randomizer);
+ g_variant_unref(reply);
- dbus_message_unref(msg);
- if (!reply) {
- BT_ERR("Error in ReadLocalData \n");
- if (dbus_error_is_set(&err)) {
- BT_ERR("%s", err.message);
- dbus_error_free(&err);
- }
+ if (hash != NULL) {
+ local_oob_data->hash_len = (unsigned int)g_variant_get_size(hash);
+ local_hash = (unsigned char *)g_variant_get_data(hash);
+ } else {
+ BT_ERR("hash is NULL");
return BLUETOOTH_ERROR_INTERNAL;
}
- if (!dbus_message_get_args(reply, NULL,
- DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE,
- &local_hash, &local_oob_data->hash_len,
- DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE,
- &local_randomizer, &local_oob_data->randomizer_len,
- DBUS_TYPE_INVALID)) {
- BT_ERR("Error in reading arguments\n");
- dbus_message_unref(reply);
- return BLUETOOTH_ERROR_INVALID_DATA;
+ g_variant_unref(hash);
+
+ if (randomizer != NULL) {
+ local_oob_data->randomizer_len = (unsigned int)g_variant_get_size(randomizer);
+ local_randomizer = (unsigned char *)g_variant_get_data(randomizer);
+ } else {
+ BT_ERR("randomizer is NULL");
+ return BLUETOOTH_ERROR_INTERNAL;
}
- if (NULL != local_hash)
+ g_variant_unref(randomizer);
+
+ if (local_oob_data->hash_len > 0)
memcpy(local_oob_data->hash, local_hash, local_oob_data->hash_len);
- if (NULL != local_randomizer)
+ if (local_oob_data->randomizer_len > 0)
memcpy(local_oob_data->randomizer, local_randomizer,
- local_oob_data->randomizer_len);
-
- dbus_message_unref(reply);
+ local_oob_data->randomizer_len);
return BLUETOOTH_ERROR_NONE;
}
bluetooth_device_address_t *remote_device_address,
bt_oob_data_t *remote_oob_data)
{
- DBusMessage *msg;
- DBusMessage *reply;
- DBusError err;
+ GDBusProxy *proxy;
+ GVariant *reply;
+ GError *err = NULL;
char *dev_addr;
char *adapter_path;
char address[BT_ADDRESS_STRING_SIZE] = { 0 };
unsigned char *remote_hash;
unsigned char *remote_randomizer;
- DBusConnection *conn;
+ GDBusConnection *conn;
+ GArray *in_param1 = NULL;
+ GArray *in_param2 = NULL;
+ GVariant *hash;
+ GVariant *randomizer;
BT_CHECK_PARAMETER(remote_device_address, return);
BT_CHECK_PARAMETER(remote_oob_data, return);
_bt_convert_addr_type_to_string(address,
remote_device_address->addr);
- msg = dbus_message_new_method_call(BT_BLUEZ_NAME, adapter_path,
- BT_OOB_INTERFACE, "AddRemoteData");
-
+ proxy = g_dbus_proxy_new_sync(conn,
+ G_DBUS_PROXY_FLAGS_NONE, NULL,
+ BT_BLUEZ_NAME, adapter_path,
+ BT_OOB_INTERFACE, NULL, &err);
g_free(adapter_path);
-
- retv_if(msg == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- BT_DBG("remote hash len = [%d] and remote random len = [%d]\n",
- remote_oob_data->hash_len, remote_oob_data->randomizer_len);
+ if (!proxy) {
+ BT_ERR("Unable to create proxy");
+ if (err) {
+ BT_ERR("Error: %s", err->message);
+ g_clear_error(&err);
+ }
+ return BLUETOOTH_ERROR_INTERNAL;
+ }
remote_hash = remote_oob_data->hash;
remote_randomizer = remote_oob_data->randomizer;
-
dev_addr = g_strdup(address);
- dbus_message_append_args(msg,
- DBUS_TYPE_STRING, &dev_addr,
- DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE,
- &remote_hash, remote_oob_data->hash_len,
- DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE,
- &remote_randomizer, remote_oob_data->randomizer_len,
- DBUS_TYPE_INVALID);
-
- dbus_error_init(&err);
- reply = dbus_connection_send_with_reply_and_block(conn,
- msg, -1, &err);
-
- dbus_message_unref(msg);
- if (!reply) {
- BT_ERR("Error in AddRemoteData \n");
- if (dbus_error_is_set(&err)) {
- BT_ERR("%s", err.message);
- dbus_error_free(&err);
- g_free(dev_addr);
- return BLUETOOTH_ERROR_INTERNAL;
+ BT_DBG("remote hash len = [%d] and remote random len = [%d]\n",
+ remote_oob_data->hash_len, remote_oob_data->randomizer_len);
+ /*Create array of bytes variant*/
+ in_param1 = g_array_new(TRUE, TRUE, sizeof(gchar));
+ in_param2 = g_array_new(TRUE, TRUE, sizeof(gchar));
+
+ g_array_append_vals(in_param1, remote_hash,
+ remote_oob_data->hash_len);
+ g_array_append_vals(in_param2, remote_randomizer,
+ remote_oob_data->randomizer_len);
+
+ hash = g_variant_new_from_data((const GVariantType *)"ay",
+ in_param1->data, in_param1->len,
+ TRUE, NULL, NULL);
+
+ randomizer = g_variant_new_from_data((const GVariantType *)"ay",
+ in_param2->data, in_param2->len,
+ TRUE, NULL, NULL);
+
+ g_array_free(in_param1, TRUE);
+ g_array_free(in_param2, TRUE);
+
+ /* Call AddRemoteData Method*/
+ reply = g_dbus_proxy_call_sync(proxy, "AddRemoteData",
+ g_variant_new("s@ay@ay", dev_addr, hash, randomizer),
+ G_DBUS_CALL_FLAGS_NONE, -1,
+ NULL, &err);
+ g_object_unref(proxy);
+ g_free(dev_addr);
+
+ /* Check the reply*/
+ if (reply == NULL) {
+ BT_ERR("AddRemoteData dBUS-RPC is failed");
+ if (err != NULL) {
+ BT_ERR("D-Bus API failure: errCode[%x], message[%s]",
+ err->code, err->message);
+ g_clear_error(&err);
}
+ return BLUETOOTH_ERROR_INTERNAL;
}
- g_free(dev_addr);
- dbus_message_unref(reply);
-
+ g_variant_unref(reply);
return BLUETOOTH_ERROR_NONE;
}
int _bt_oob_remove_remote_data(
bluetooth_device_address_t *remote_device_address)
{
- DBusMessage *msg;
- DBusMessage *reply;
- DBusError err;
+ GDBusProxy *proxy;
+ GVariant *reply;
+ GError *err = NULL;
char *dev_addr;
char *adapter_path;
char address[BT_ADDRESS_STRING_SIZE] = { 0 };
- DBusConnection *conn;
+ GDBusConnection *conn;
BT_CHECK_PARAMETER(remote_device_address, return);
_bt_convert_addr_type_to_string(address,
remote_device_address->addr);
- msg = dbus_message_new_method_call(BT_BLUEZ_NAME, adapter_path,
- BT_OOB_INTERFACE, "RemoveRemoteData");
-
+ proxy = g_dbus_proxy_new_sync(conn,
+ G_DBUS_PROXY_FLAGS_NONE, NULL,
+ BT_BLUEZ_NAME, adapter_path,
+ BT_OOB_INTERFACE, NULL, &err);
g_free(adapter_path);
-
- retv_if(msg == NULL, BLUETOOTH_ERROR_INTERNAL);
+ if (!proxy) {
+ BT_ERR("Unable to create proxy");
+ if (err) {
+ BT_ERR("Error: %s", err->message);
+ g_clear_error(&err);
+ }
+ return BLUETOOTH_ERROR_INTERNAL;
+ }
dev_addr = g_strdup(address);
- dbus_message_append_args(msg, DBUS_TYPE_STRING,
- &dev_addr, DBUS_TYPE_INVALID);
-
- dbus_error_init(&err);
- reply = dbus_connection_send_with_reply_and_block(conn,
- msg, -1, &err);
-
- dbus_message_unref(msg);
- if (!reply) {
- BT_ERR("Error in RemoveRemoteData \n");
- if (dbus_error_is_set(&err)) {
- BT_DBG("%s", err.message);
- dbus_error_free(&err);
- g_free(dev_addr);
- return BLUETOOTH_ERROR_INTERNAL;
+ /* Call RemoveRemoteData Method*/
+ reply = g_dbus_proxy_call_sync(proxy, "RemoveRemoteData",
+ g_variant_new("s", dev_addr),
+ G_DBUS_CALL_FLAGS_NONE, -1,
+ NULL, &err);
+ g_object_unref(proxy);
+ g_free(dev_addr);
+
+ /* Check the reply*/
+ if (reply == NULL) {
+ BT_ERR("RemoveRemoteData dBUS-RPC is failed");
+ if (err != NULL) {
+ BT_ERR("D-Bus API failure: errCode[%x], message[%s]",
+ err->code, err->message);
+ g_clear_error(&err);
}
+ return BLUETOOTH_ERROR_INTERNAL;
}
- g_free(dev_addr);
- dbus_message_unref(reply);
-
+ g_variant_unref(reply);
return BLUETOOTH_ERROR_NONE;
}