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 int _bt_oob_read_local_data(bt_oob_data_t *local_oob_data)
40 unsigned char *local_hash = NULL;
41 unsigned char *local_randomizer = NULL;
42 GDBusConnection *conn;
43 GVariant *hash = NULL;
44 GVariant *randomizer = NULL;
46 BT_CHECK_PARAMETER(local_oob_data, return);
48 conn = _bt_get_system_conn();
49 retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
51 adapter_path = _bt_get_adapter_path();
52 retv_if(adapter_path == NULL, BLUETOOTH_ERROR_INTERNAL);
55 proxy = g_dbus_proxy_new_sync(conn,
56 G_DBUS_PROXY_FLAGS_NONE, NULL,
57 BT_BLUEZ_NAME, adapter_path,
58 BT_OOB_INTERFACE, NULL, &err);
61 BT_ERR("Unable to create proxy");
63 BT_ERR("Error: %s", err->message);
66 return BLUETOOTH_ERROR_INTERNAL;
69 reply = g_dbus_proxy_call_sync(proxy, "ReadLocalData",
71 G_DBUS_CALL_FLAGS_NONE, -1,
73 g_object_unref(proxy);
76 BT_ERR("ReadLocalData dBUS-RPC is failed");
78 BT_ERR("D-Bus API failure: errCode[%x], message[%s]",
79 err->code, err->message);
82 return BLUETOOTH_ERROR_INTERNAL;
85 g_variant_get(reply ,"(@ay@ay)", &hash, &randomizer);
86 g_variant_unref(reply);
89 local_oob_data->hash_len = (unsigned int)g_variant_get_size(hash);
90 local_hash = (unsigned char *)g_variant_get_data(hash);
92 BT_ERR("hash is NULL");
93 return BLUETOOTH_ERROR_INTERNAL;
96 g_variant_unref(hash);
98 if(randomizer != NULL){
99 local_oob_data->randomizer_len = (unsigned int)g_variant_get_size(randomizer);
100 local_randomizer = (unsigned char *)g_variant_get_data(randomizer);
102 BT_ERR("randomizer is NULL");
103 return BLUETOOTH_ERROR_INTERNAL;
106 g_variant_unref(randomizer);
108 if (local_oob_data->hash_len > 0)
109 memcpy(local_oob_data->hash, local_hash, local_oob_data->hash_len);
111 if (local_oob_data->randomizer_len > 0)
112 memcpy(local_oob_data->randomizer, local_randomizer,
113 local_oob_data->randomizer_len);
115 return BLUETOOTH_ERROR_NONE;
118 int _bt_oob_add_remote_data(
119 bluetooth_device_address_t *remote_device_address,
120 bt_oob_data_t *remote_oob_data)
127 char address[BT_ADDRESS_STRING_SIZE] = { 0 };
128 unsigned char *remote_hash;
129 unsigned char *remote_randomizer;
130 GDBusConnection *conn;
131 GArray *in_param1 = NULL;
132 GArray *in_param2 = NULL;
134 GVariant *randomizer;
136 BT_CHECK_PARAMETER(remote_device_address, return);
137 BT_CHECK_PARAMETER(remote_oob_data, return);
139 conn = _bt_get_system_conn();
140 retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
142 adapter_path = _bt_get_adapter_path();
143 retv_if(adapter_path == NULL, BLUETOOTH_ERROR_INTERNAL);
145 _bt_convert_addr_type_to_string(address,
146 remote_device_address->addr);
148 proxy = g_dbus_proxy_new_sync(conn,
149 G_DBUS_PROXY_FLAGS_NONE, NULL,
150 BT_BLUEZ_NAME, adapter_path,
151 BT_OOB_INTERFACE, NULL, &err);
152 g_free(adapter_path);
154 BT_ERR("Unable to create proxy");
156 BT_ERR("Error: %s", err->message);
159 return BLUETOOTH_ERROR_INTERNAL;
162 remote_hash = remote_oob_data->hash;
163 remote_randomizer = remote_oob_data->randomizer;
164 dev_addr = g_strdup(address);
166 BT_DBG("remote hash len = [%d] and remote random len = [%d]\n",
167 remote_oob_data->hash_len, remote_oob_data->randomizer_len);
168 /*Create array of bytes variant*/
169 in_param1 = g_array_new(TRUE, TRUE, sizeof(gchar));
170 in_param2 = g_array_new(TRUE, TRUE, sizeof(gchar));
172 g_array_append_vals(in_param1, remote_hash,
173 remote_oob_data->hash_len);
174 g_array_append_vals(in_param2, remote_randomizer,
175 remote_oob_data->randomizer_len);
177 hash = g_variant_new_from_data((const GVariantType *)"ay",
178 in_param1->data, in_param1->len,
181 randomizer = g_variant_new_from_data((const GVariantType *)"ay",
182 in_param2->data, in_param2->len,
185 g_array_free(in_param1, TRUE);
186 g_array_free(in_param2, TRUE);
188 /* Call AddRemoteData Method*/
189 reply = g_dbus_proxy_call_sync(proxy, "AddRemoteData",
190 g_variant_new("s@ay@ay", dev_addr, hash, randomizer),
191 G_DBUS_CALL_FLAGS_NONE, -1,
193 g_object_unref(proxy);
198 BT_ERR("AddRemoteData dBUS-RPC is failed");
200 BT_ERR("D-Bus API failure: errCode[%x], message[%s]",
201 err->code, err->message);
204 return BLUETOOTH_ERROR_INTERNAL;
207 g_variant_unref(reply);
208 return BLUETOOTH_ERROR_NONE;
211 int _bt_oob_remove_remote_data(
212 bluetooth_device_address_t *remote_device_address)
219 char address[BT_ADDRESS_STRING_SIZE] = { 0 };
220 GDBusConnection *conn;
222 BT_CHECK_PARAMETER(remote_device_address, return);
224 conn = _bt_get_system_conn();
225 retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
227 adapter_path = _bt_get_adapter_path();
228 retv_if(adapter_path == NULL, BLUETOOTH_ERROR_INTERNAL);
230 _bt_convert_addr_type_to_string(address,
231 remote_device_address->addr);
233 proxy = g_dbus_proxy_new_sync(conn,
234 G_DBUS_PROXY_FLAGS_NONE, NULL,
235 BT_BLUEZ_NAME, adapter_path,
236 BT_OOB_INTERFACE, NULL, &err);
237 g_free(adapter_path);
239 BT_ERR("Unable to create proxy");
241 BT_ERR("Error: %s", err->message);
244 return BLUETOOTH_ERROR_INTERNAL;
247 dev_addr = g_strdup(address);
249 /* Call RemoveRemoteData Method*/
250 reply = g_dbus_proxy_call_sync(proxy, "RemoveRemoteData",
251 g_variant_new("s", dev_addr),
252 G_DBUS_CALL_FLAGS_NONE, -1,
254 g_object_unref(proxy);
259 BT_ERR("RemoveRemoteData dBUS-RPC is failed");
261 BT_ERR("D-Bus API failure: errCode[%x], message[%s]",
262 err->code, err->message);
265 return BLUETOOTH_ERROR_INTERNAL;
268 g_variant_unref(reply);
269 return BLUETOOTH_ERROR_NONE;