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);
116 return BLUETOOTH_ERROR_NONE;
119 int _bt_oob_add_remote_data(
120 bluetooth_device_address_t *remote_device_address,
121 bt_oob_data_t *remote_oob_data)
128 char address[BT_ADDRESS_STRING_SIZE] = { 0 };
129 unsigned char *remote_hash;
130 unsigned char *remote_randomizer;
131 GDBusConnection *conn;
132 GArray *in_param1 = NULL;
133 GArray *in_param2 = NULL;
135 GVariant *randomizer;
137 BT_CHECK_PARAMETER(remote_device_address, return);
138 BT_CHECK_PARAMETER(remote_oob_data, return);
140 conn = _bt_get_system_conn();
141 retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
143 adapter_path = _bt_get_adapter_path();
144 retv_if(adapter_path == NULL, BLUETOOTH_ERROR_INTERNAL);
146 _bt_convert_addr_type_to_string(address,
147 remote_device_address->addr);
149 proxy = g_dbus_proxy_new_sync(conn,
150 G_DBUS_PROXY_FLAGS_NONE, NULL,
151 BT_BLUEZ_NAME, adapter_path,
152 BT_OOB_INTERFACE, NULL, &err);
153 g_free(adapter_path);
155 BT_ERR("Unable to create proxy");
157 BT_ERR("Error: %s", err->message);
160 return BLUETOOTH_ERROR_INTERNAL;
163 remote_hash = remote_oob_data->hash;
164 remote_randomizer = remote_oob_data->randomizer;
165 dev_addr = g_strdup(address);
167 BT_DBG("remote hash len = [%d] and remote random len = [%d]\n",
168 remote_oob_data->hash_len, remote_oob_data->randomizer_len);
169 /*Create array of bytes variant*/
170 in_param1 = g_array_new(TRUE, TRUE, sizeof(gchar));
171 in_param2 = g_array_new(TRUE, TRUE, sizeof(gchar));
173 g_array_append_vals(in_param1, remote_hash,
174 remote_oob_data->hash_len);
175 g_array_append_vals(in_param2, remote_randomizer,
176 remote_oob_data->randomizer_len);
178 hash = g_variant_new_from_data((const GVariantType *)"ay",
179 in_param1->data, in_param1->len,
182 randomizer = g_variant_new_from_data((const GVariantType *)"ay",
183 in_param2->data, in_param2->len,
186 g_array_free(in_param1, TRUE);
187 g_array_free(in_param2, TRUE);
189 /* Call AddRemoteData Method*/
190 reply = g_dbus_proxy_call_sync(proxy, "AddRemoteData",
191 g_variant_new("s@ay@ay", dev_addr, hash, randomizer),
192 G_DBUS_CALL_FLAGS_NONE, -1,
194 g_object_unref(proxy);
199 BT_ERR("AddRemoteData dBUS-RPC is failed");
201 BT_ERR("D-Bus API failure: errCode[%x], message[%s]",
202 err->code, err->message);
205 return BLUETOOTH_ERROR_INTERNAL;
208 g_variant_unref(reply);
209 return BLUETOOTH_ERROR_NONE;
212 int _bt_oob_remove_remote_data(
213 bluetooth_device_address_t *remote_device_address)
220 char address[BT_ADDRESS_STRING_SIZE] = { 0 };
221 GDBusConnection *conn;
223 BT_CHECK_PARAMETER(remote_device_address, return);
225 conn = _bt_get_system_conn();
226 retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
228 adapter_path = _bt_get_adapter_path();
229 retv_if(adapter_path == NULL, BLUETOOTH_ERROR_INTERNAL);
231 _bt_convert_addr_type_to_string(address,
232 remote_device_address->addr);
234 proxy = g_dbus_proxy_new_sync(conn,
235 G_DBUS_PROXY_FLAGS_NONE, NULL,
236 BT_BLUEZ_NAME, adapter_path,
237 BT_OOB_INTERFACE, NULL, &err);
238 g_free(adapter_path);
240 BT_ERR("Unable to create proxy");
242 BT_ERR("Error: %s", err->message);
245 return BLUETOOTH_ERROR_INTERNAL;
248 dev_addr = g_strdup(address);
250 /* Call RemoveRemoteData Method*/
251 reply = g_dbus_proxy_call_sync(proxy, "RemoveRemoteData",
252 g_variant_new("s", dev_addr),
253 G_DBUS_CALL_FLAGS_NONE, -1,
255 g_object_unref(proxy);
260 BT_ERR("RemoveRemoteData dBUS-RPC is failed");
262 BT_ERR("D-Bus API failure: errCode[%x], message[%s]",
263 err->code, err->message);
266 return BLUETOOTH_ERROR_INTERNAL;
269 g_variant_unref(reply);
270 return BLUETOOTH_ERROR_NONE;