4 * Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
20 #include <dbus/dbus-glib.h>
21 #include <dbus/dbus.h>
26 #include "bluetooth-api.h"
27 #include "bt-service-common.h"
28 #include "bt-service-oob.h"
29 #include "bt-service-event.h"
31 int _bt_oob_read_local_data(bt_oob_data_t *local_oob_data)
37 unsigned char *local_hash = NULL;
38 unsigned char *local_randomizer = NULL;
41 BT_CHECK_PARAMETER(local_oob_data, return);
43 conn = _bt_get_system_conn();
44 retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
46 adapter_path = _bt_get_adapter_path();
47 retv_if(adapter_path == NULL, BLUETOOTH_ERROR_INTERNAL);
49 msg = dbus_message_new_method_call(BT_BLUEZ_NAME, adapter_path,
50 BT_OOB_INTERFACE, "ReadLocalData");
54 retv_if(msg == NULL, BLUETOOTH_ERROR_INTERNAL);
56 dbus_error_init(&err);
57 reply = dbus_connection_send_with_reply_and_block(conn,
60 dbus_message_unref(msg);
62 BT_ERR("Error in ReadLocalData \n");
63 if (dbus_error_is_set(&err)) {
64 BT_ERR("%s", err.message);
65 dbus_error_free(&err);
67 return BLUETOOTH_ERROR_INTERNAL;
70 if (!dbus_message_get_args(reply, NULL,
71 DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE,
72 &local_hash, &local_oob_data->hash_len,
73 DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE,
74 &local_randomizer, &local_oob_data->randomizer_len,
76 BT_ERR("Error in reading arguments\n");
77 dbus_message_unref(reply);
78 return BLUETOOTH_ERROR_INVALID_DATA;
81 if (NULL != local_hash)
82 memcpy(local_oob_data->hash, local_hash, local_oob_data->hash_len);
84 if (NULL != local_randomizer)
85 memcpy(local_oob_data->randomizer, local_randomizer,
86 local_oob_data->randomizer_len);
88 dbus_message_unref(reply);
90 return BLUETOOTH_ERROR_NONE;
93 int _bt_oob_add_remote_data(
94 bluetooth_device_address_t *remote_device_address,
95 bt_oob_data_t *remote_oob_data)
102 char address[BT_ADDRESS_STRING_SIZE] = { 0 };
103 unsigned char *remote_hash;
104 unsigned char *remote_randomizer;
105 DBusConnection *conn;
107 BT_CHECK_PARAMETER(remote_device_address, return);
108 BT_CHECK_PARAMETER(remote_oob_data, return);
110 conn = _bt_get_system_conn();
111 retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
113 adapter_path = _bt_get_adapter_path();
114 retv_if(adapter_path == NULL, BLUETOOTH_ERROR_INTERNAL);
116 _bt_convert_addr_type_to_string(address,
117 remote_device_address->addr);
119 msg = dbus_message_new_method_call(BT_BLUEZ_NAME, adapter_path,
120 BT_OOB_INTERFACE, "AddRemoteData");
122 retv_if(msg == NULL, BLUETOOTH_ERROR_INTERNAL);
124 BT_DBG("remote hash len = [%d] and remote random len = [%d]\n",
125 remote_oob_data->hash_len, remote_oob_data->randomizer_len);
127 remote_hash = remote_oob_data->hash;
128 remote_randomizer = remote_oob_data->randomizer;
130 dev_addr = g_strdup(address);
132 dbus_message_append_args(msg,
133 DBUS_TYPE_STRING, &dev_addr,
134 DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE,
135 &remote_hash, remote_oob_data->hash_len,
136 DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE,
137 &remote_randomizer, remote_oob_data->randomizer_len,
140 dbus_error_init(&err);
141 reply = dbus_connection_send_with_reply_and_block(conn,
144 dbus_message_unref(msg);
146 BT_ERR("Error in AddRemoteData \n");
147 if (dbus_error_is_set(&err)) {
148 BT_ERR("%s", err.message);
149 dbus_error_free(&err);
151 return BLUETOOTH_ERROR_INTERNAL;
156 dbus_message_unref(reply);
158 return BLUETOOTH_ERROR_NONE;
161 int _bt_oob_remove_remote_data(
162 bluetooth_device_address_t *remote_device_address)
169 char address[BT_ADDRESS_STRING_SIZE] = { 0 };
170 DBusConnection *conn;
172 BT_CHECK_PARAMETER(remote_device_address, return);
174 conn = _bt_get_system_conn();
175 retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
177 adapter_path = _bt_get_adapter_path();
178 retv_if(adapter_path == NULL, BLUETOOTH_ERROR_INTERNAL);
180 _bt_convert_addr_type_to_string(address,
181 remote_device_address->addr);
183 msg = dbus_message_new_method_call(BT_BLUEZ_NAME, adapter_path,
184 BT_OOB_INTERFACE, "RemoveRemoteData");
186 retv_if(msg == NULL, BLUETOOTH_ERROR_INTERNAL);
188 dev_addr = g_strdup(address);
190 dbus_message_append_args(msg, DBUS_TYPE_STRING,
191 &dev_addr, DBUS_TYPE_INVALID);
193 dbus_error_init(&err);
194 reply = dbus_connection_send_with_reply_and_block(conn,
197 dbus_message_unref(msg);
199 BT_ERR("Error in RemoveRemoteData \n");
200 if (dbus_error_is_set(&err)) {
201 BT_DBG("%s", err.message);
202 dbus_error_free(&err);
204 return BLUETOOTH_ERROR_INTERNAL;
209 dbus_message_unref(reply);
211 return BLUETOOTH_ERROR_NONE;