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.
29 #include "bluetooth-api.h"
30 #include "bt-service-common.h"
31 #include "bt-service-oob.h"
32 #include "bt-service-event.h"
34 static int __get_oob_data_from_variant(GVariant *variant,
35 unsigned char *buf, int size)
40 i = g_variant_get_size(variant);
41 v = (unsigned char *)g_variant_get_data(variant);
43 i = i > size ? size : i;
50 int _bt_oob_read_local_data(bt_oob_data_t *local_oob_data)
56 GDBusConnection *conn;
57 GVariant *hash192 = NULL;
58 GVariant *randomizer192 = NULL;
59 GVariant *hash256 = NULL;
60 GVariant *randomizer256 = NULL;
62 BT_CHECK_PARAMETER(local_oob_data, return);
64 conn = _bt_gdbus_get_system_gconn();
65 retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
67 adapter_path = _bt_get_adapter_path();
68 retv_if(adapter_path == NULL, BLUETOOTH_ERROR_INTERNAL);
70 proxy = g_dbus_proxy_new_sync(conn,
71 G_DBUS_PROXY_FLAGS_NONE, NULL,
72 BT_BLUEZ_NAME, adapter_path,
73 BT_OOB_INTERFACE, NULL, &err);
76 BT_ERR("Unable to create proxy");
78 BT_ERR("Error: %s", err->message);
81 return BLUETOOTH_ERROR_INTERNAL;
84 reply = g_dbus_proxy_call_sync(proxy, "ReadLocalData",
86 G_DBUS_CALL_FLAGS_NONE, -1,
88 g_object_unref(proxy);
91 BT_ERR("ReadLocalData dBUS-RPC is failed");
93 BT_ERR("D-Bus API failure: errCode[%x], message[%s]",
94 err->code, err->message);
97 return BLUETOOTH_ERROR_INTERNAL;
100 g_variant_get(reply, "(@ay@ay@ay@ay)", &hash192, &randomizer192,
101 &hash256, &randomizer256);
102 g_variant_unref(reply);
105 local_oob_data->hash_len = __get_oob_data_from_variant(hash192,
106 local_oob_data->hash,
107 sizeof(local_oob_data->hash));
108 g_variant_unref(hash192);
112 local_oob_data->randomizer_len = __get_oob_data_from_variant(randomizer192,
113 local_oob_data->randomizer,
114 sizeof(local_oob_data->randomizer));
115 g_variant_unref(randomizer192);
119 local_oob_data->hash256_len = __get_oob_data_from_variant(hash256,
120 local_oob_data->hash256,
121 sizeof(local_oob_data->hash256));
122 g_variant_unref(hash256);
126 local_oob_data->randomizer256_len = __get_oob_data_from_variant(randomizer256,
127 local_oob_data->randomizer256,
128 sizeof(local_oob_data->randomizer256));
129 g_variant_unref(randomizer256);
132 return BLUETOOTH_ERROR_NONE;
135 int _bt_oob_add_remote_data(
136 bluetooth_device_address_t *remote_device_address,
137 unsigned short address_type,
138 bt_oob_data_t *remote_oob_data)
146 char address[BT_ADDRESS_STRING_SIZE] = { 0 };
147 unsigned char *remote_hash;
148 unsigned char *remote_randomizer;
149 GDBusConnection *conn;
150 GVariantBuilder *builder;
151 GVariantBuilder *builder2;
153 GVariant *randomizer192;
155 GVariant *randomizer256;
157 BT_CHECK_PARAMETER(remote_device_address, return);
158 BT_CHECK_PARAMETER(remote_oob_data, return);
160 conn = _bt_gdbus_get_system_gconn();
161 retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
163 adapter_path = _bt_get_adapter_path();
164 retv_if(adapter_path == NULL, BLUETOOTH_ERROR_INTERNAL);
166 _bt_convert_addr_type_to_string(address, remote_device_address->addr);
168 proxy = g_dbus_proxy_new_sync(conn,
169 G_DBUS_PROXY_FLAGS_NONE, NULL,
170 BT_BLUEZ_NAME, adapter_path,
171 BT_OOB_INTERFACE, NULL, &err);
172 g_free(adapter_path);
174 BT_ERR("Unable to create proxy");
176 BT_ERR("Error: %s", err->message);
179 return BLUETOOTH_ERROR_INTERNAL;
182 BT_DBG("address type: %d", address_type);
185 dev_addr = g_strdup(address);
188 remote_hash = remote_oob_data->hash;
189 remote_randomizer = remote_oob_data->randomizer;
191 builder = g_variant_builder_new(G_VARIANT_TYPE("ay"));
192 builder2 = g_variant_builder_new(G_VARIANT_TYPE("ay"));
194 for (i = 0; i < remote_oob_data->hash_len; i++)
195 g_variant_builder_add(builder, "y", remote_hash[i]);
197 for (i = 0; i < remote_oob_data->randomizer_len; i++)
198 g_variant_builder_add(builder2, "y", remote_randomizer[i]);
200 hash192 = g_variant_new("ay", builder);
201 randomizer192 = g_variant_new("ay", builder2);
203 g_variant_builder_unref(builder2);
204 g_variant_builder_unref(builder);
207 remote_hash = remote_oob_data->hash256;
208 remote_randomizer = remote_oob_data->randomizer256;
210 builder = g_variant_builder_new(G_VARIANT_TYPE("ay"));
211 builder2 = g_variant_builder_new(G_VARIANT_TYPE("ay"));
213 for (i = 0; i < remote_oob_data->hash256_len; i++)
214 g_variant_builder_add(builder, "y", remote_hash[i]);
216 for (i = 0; i < remote_oob_data->randomizer256_len; i++)
217 g_variant_builder_add(builder2, "y", remote_randomizer[i]);
219 hash256 = g_variant_new("ay", builder);
220 randomizer256 = g_variant_new("ay", builder2);
222 g_variant_builder_unref(builder2);
223 g_variant_builder_unref(builder);
225 /* Call AddRemoteData Method */
226 reply = g_dbus_proxy_call_sync(proxy, "AddRemoteData",
227 g_variant_new("(sy@ay@ay@ay@ay)", dev_addr, address_type,
228 hash192, randomizer192, hash256, randomizer256),
229 G_DBUS_CALL_FLAGS_NONE, -1,
231 g_object_unref(proxy);
234 BT_DBG("Add remote OOB data!!");
236 /* Check the reply */
238 BT_ERR("AddRemoteData dBUS-RPC is failed");
240 BT_ERR("D-Bus API failure: errCode[%x], message[%s]",
241 err->code, err->message);
244 return BLUETOOTH_ERROR_INTERNAL;
246 g_variant_unref(reply);
250 return BLUETOOTH_ERROR_NONE;
253 int _bt_oob_remove_remote_data(
254 bluetooth_device_address_t *remote_device_address)
261 char address[BT_ADDRESS_STRING_SIZE] = { 0 };
262 GDBusConnection *conn;
264 BT_CHECK_PARAMETER(remote_device_address, return);
266 conn = _bt_gdbus_get_system_gconn();
267 retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
269 adapter_path = _bt_get_adapter_path();
270 retv_if(adapter_path == NULL, BLUETOOTH_ERROR_INTERNAL);
272 _bt_convert_addr_type_to_string(address,
273 remote_device_address->addr);
275 proxy = g_dbus_proxy_new_sync(conn,
276 G_DBUS_PROXY_FLAGS_NONE, NULL,
277 BT_BLUEZ_NAME, adapter_path,
278 BT_OOB_INTERFACE, NULL, &err);
279 g_free(adapter_path);
281 BT_ERR("Unable to create proxy");
283 BT_ERR("Error: %s", err->message);
286 return BLUETOOTH_ERROR_INTERNAL;
289 dev_addr = g_strdup(address);
291 /* Call RemoveRemoteData Method*/
292 reply = g_dbus_proxy_call_sync(proxy, "RemoveRemoteData",
293 g_variant_new("(s)", dev_addr),
294 G_DBUS_CALL_FLAGS_NONE, -1,
296 g_object_unref(proxy);
301 BT_ERR("RemoveRemoteData dBUS-RPC is failed");
303 BT_ERR("D-Bus API failure: errCode[%x], message[%s]",
304 err->code, err->message);
307 return BLUETOOTH_ERROR_INTERNAL;
310 g_variant_unref(reply);
311 return BLUETOOTH_ERROR_NONE;
314 int _bt_le_oob_read_local_data(bt_oob_data_t *local_oob_data)
320 GDBusConnection *conn;
321 GVariant *eir = NULL;
323 BT_CHECK_PARAMETER(local_oob_data, return);
325 conn = _bt_gdbus_get_system_gconn();
326 retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
328 adapter_path = _bt_get_adapter_path();
329 retv_if(adapter_path == NULL, BLUETOOTH_ERROR_INTERNAL);
331 proxy = g_dbus_proxy_new_sync(conn,
332 G_DBUS_PROXY_FLAGS_NONE, NULL,
333 BT_BLUEZ_NAME, adapter_path,
334 BT_OOB_INTERFACE, NULL, &err);
335 g_free(adapter_path);
337 BT_ERR("Unable to create proxy");
339 BT_ERR("Error: %s", err->message);
342 return BLUETOOTH_ERROR_INTERNAL;
345 reply = g_dbus_proxy_call_sync(proxy, "LEReadLocalData",
347 G_DBUS_CALL_FLAGS_NONE, -1,
349 g_object_unref(proxy);
352 BT_ERR("LEReadLocalData dBUS-RPC is failed");
354 BT_ERR("D-Bus API failure: errCode[%x], message[%s]",
355 err->code, err->message);
358 return BLUETOOTH_ERROR_INTERNAL;
361 g_variant_get(reply, "(@ay)", &eir);
362 g_variant_unref(reply);
365 local_oob_data->eir_len = __get_oob_data_from_variant(eir,
367 sizeof(local_oob_data->eir));
368 g_variant_unref(eir);
371 return BLUETOOTH_ERROR_NONE;