4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Hocheol Seo <hocheol.seo@samsung.com>
7 * Girishashok Joshi <girish.joshi@samsung.com>
8 * Chanyeol Park <chanyeol.park@samsung.com>
10 * Licensed under the Apache License, Version 2.0 (the "License");
11 * you may not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
14 * http://www.apache.org/licenses/LICENSE-2.0
16 * Unless required by applicable law or agreed to in writing, software
17 * distributed under the License is distributed on an "AS IS" BASIS,
18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 * See the License for the specific language governing permissions and
20 * limitations under the License.
24 #include <dbus/dbus-glib.h>
25 #include <dbus/dbus.h>
30 #include "bluetooth-api.h"
31 #include "bt-service-common.h"
32 #include "bt-service-oob.h"
33 #include "bt-service-event.h"
35 int _bt_oob_read_local_data(bt_oob_data_t *local_oob_data)
41 unsigned char *local_hash = NULL;
42 unsigned char *local_randomizer = NULL;
45 BT_CHECK_PARAMETER(local_oob_data, return);
47 conn = _bt_get_system_conn();
48 retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
50 adapter_path = _bt_get_adapter_path();
51 retv_if(adapter_path == NULL, BLUETOOTH_ERROR_INTERNAL);
53 msg = dbus_message_new_method_call(BT_BLUEZ_NAME, adapter_path,
54 BT_OOB_INTERFACE, "ReadLocalData");
58 retv_if(msg == NULL, BLUETOOTH_ERROR_INTERNAL);
60 dbus_error_init(&err);
61 reply = dbus_connection_send_with_reply_and_block(conn,
64 dbus_message_unref(msg);
66 BT_ERR("Error in ReadLocalData \n");
67 if (dbus_error_is_set(&err)) {
68 BT_ERR("%s", err.message);
69 dbus_error_free(&err);
71 return BLUETOOTH_ERROR_INTERNAL;
74 if (!dbus_message_get_args(reply, NULL,
75 DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE,
76 &local_hash, &local_oob_data->hash_len,
77 DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE,
78 &local_randomizer, &local_oob_data->randomizer_len,
80 BT_ERR("Error in reading arguments\n");
81 dbus_message_unref(reply);
82 return BLUETOOTH_ERROR_INVALID_DATA;
85 if (NULL != local_hash)
86 memcpy(local_oob_data->hash, local_hash, local_oob_data->hash_len);
88 if (NULL != local_randomizer)
89 memcpy(local_oob_data->randomizer, local_randomizer,
90 local_oob_data->randomizer_len);
92 dbus_message_unref(reply);
94 return BLUETOOTH_ERROR_NONE;
97 int _bt_oob_add_remote_data(
98 bluetooth_device_address_t *remote_device_address,
99 bt_oob_data_t *remote_oob_data)
106 char address[BT_ADDRESS_STRING_SIZE] = { 0 };
107 unsigned char *remote_hash;
108 unsigned char *remote_randomizer;
109 DBusConnection *conn;
111 BT_CHECK_PARAMETER(remote_device_address, return);
112 BT_CHECK_PARAMETER(remote_oob_data, return);
114 conn = _bt_get_system_conn();
115 retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
117 adapter_path = _bt_get_adapter_path();
118 retv_if(adapter_path == NULL, BLUETOOTH_ERROR_INTERNAL);
120 _bt_convert_addr_type_to_string(address,
121 remote_device_address->addr);
123 msg = dbus_message_new_method_call(BT_BLUEZ_NAME, adapter_path,
124 BT_OOB_INTERFACE, "AddRemoteData");
126 g_free(adapter_path);
128 retv_if(msg == NULL, BLUETOOTH_ERROR_INTERNAL);
130 BT_DBG("remote hash len = [%d] and remote random len = [%d]\n",
131 remote_oob_data->hash_len, remote_oob_data->randomizer_len);
133 remote_hash = remote_oob_data->hash;
134 remote_randomizer = remote_oob_data->randomizer;
136 dev_addr = g_strdup(address);
138 dbus_message_append_args(msg,
139 DBUS_TYPE_STRING, &dev_addr,
140 DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE,
141 &remote_hash, remote_oob_data->hash_len,
142 DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE,
143 &remote_randomizer, remote_oob_data->randomizer_len,
146 dbus_error_init(&err);
147 reply = dbus_connection_send_with_reply_and_block(conn,
150 dbus_message_unref(msg);
152 BT_ERR("Error in AddRemoteData \n");
153 if (dbus_error_is_set(&err)) {
154 BT_ERR("%s", err.message);
155 dbus_error_free(&err);
157 return BLUETOOTH_ERROR_INTERNAL;
162 dbus_message_unref(reply);
164 return BLUETOOTH_ERROR_NONE;
167 int _bt_oob_remove_remote_data(
168 bluetooth_device_address_t *remote_device_address)
175 char address[BT_ADDRESS_STRING_SIZE] = { 0 };
176 DBusConnection *conn;
178 BT_CHECK_PARAMETER(remote_device_address, return);
180 conn = _bt_get_system_conn();
181 retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
183 adapter_path = _bt_get_adapter_path();
184 retv_if(adapter_path == NULL, BLUETOOTH_ERROR_INTERNAL);
186 _bt_convert_addr_type_to_string(address,
187 remote_device_address->addr);
189 msg = dbus_message_new_method_call(BT_BLUEZ_NAME, adapter_path,
190 BT_OOB_INTERFACE, "RemoveRemoteData");
192 g_free(adapter_path);
194 retv_if(msg == NULL, BLUETOOTH_ERROR_INTERNAL);
196 dev_addr = g_strdup(address);
198 dbus_message_append_args(msg, DBUS_TYPE_STRING,
199 &dev_addr, DBUS_TYPE_INVALID);
201 dbus_error_init(&err);
202 reply = dbus_connection_send_with_reply_and_block(conn,
205 dbus_message_unref(msg);
207 BT_ERR("Error in RemoveRemoteData \n");
208 if (dbus_error_is_set(&err)) {
209 BT_ERR("%s", err.message);
210 dbus_error_free(&err);
212 return BLUETOOTH_ERROR_INTERNAL;
217 dbus_message_unref(reply);
219 return BLUETOOTH_ERROR_NONE;