2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
23 #include "bluetooth-api.h"
24 #include "bt-service-common.h"
25 #include "bt-service-oob.h"
26 #include "bt-service-event.h"
28 int _bt_oob_read_local_data(bt_oob_data_t *local_oob_data)
34 unsigned char *local_hash = NULL;
35 unsigned char *local_randomizer = NULL;
36 GDBusConnection *conn;
37 GVariant *hash = NULL;
38 GVariant *randomizer = NULL;
40 BT_CHECK_PARAMETER(local_oob_data, return);
42 conn = _bt_get_system_conn();
43 retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
45 adapter_path = _bt_get_adapter_path();
46 retv_if(adapter_path == NULL, BLUETOOTH_ERROR_INTERNAL);
49 proxy = g_dbus_proxy_new_sync(conn,
50 G_DBUS_PROXY_FLAGS_NONE, NULL,
51 BT_BLUEZ_NAME, adapter_path,
52 BT_OOB_INTERFACE, NULL, &err);
55 BT_ERR("Unable to create proxy");
57 BT_ERR("Error: %s", err->message);
60 return BLUETOOTH_ERROR_INTERNAL;
63 reply = g_dbus_proxy_call_sync(proxy, "ReadLocalData",
65 G_DBUS_CALL_FLAGS_NONE, -1,
67 g_object_unref(proxy);
70 BT_ERR("ReadLocalData dBUS-RPC is failed");
72 BT_ERR("D-Bus API failure: errCode[%x], message[%s]",
73 err->code, err->message);
76 return BLUETOOTH_ERROR_INTERNAL;
79 g_variant_get(reply ,"(@ay@ay)", &hash, &randomizer);
80 g_variant_unref(reply);
83 local_oob_data->hash_len = (unsigned int)g_variant_get_size(hash);
84 local_hash = (unsigned char *)g_variant_get_data(hash);
86 BT_ERR("hash is NULL");
87 return BLUETOOTH_ERROR_INTERNAL;
90 g_variant_unref(hash);
92 if(randomizer != NULL){
93 local_oob_data->randomizer_len = (unsigned int)g_variant_get_size(randomizer);
94 local_randomizer = (unsigned char *)g_variant_get_data(randomizer);
96 BT_ERR("randomizer is NULL");
97 return BLUETOOTH_ERROR_INTERNAL;
100 g_variant_unref(randomizer);
102 if (local_oob_data->hash_len > 0)
103 memcpy(local_oob_data->hash, local_hash, local_oob_data->hash_len);
105 if (local_oob_data->randomizer_len > 0)
106 memcpy(local_oob_data->randomizer, local_randomizer,
107 local_oob_data->randomizer_len);
109 return BLUETOOTH_ERROR_NONE;
112 int _bt_oob_add_remote_data(
113 bluetooth_device_address_t *remote_device_address,
114 bt_oob_data_t *remote_oob_data)
121 char address[BT_ADDRESS_STRING_SIZE] = { 0 };
122 unsigned char *remote_hash;
123 unsigned char *remote_randomizer;
124 GDBusConnection *conn;
125 GArray *in_param1 = NULL;
126 GArray *in_param2 = NULL;
128 GVariant *randomizer;
130 BT_CHECK_PARAMETER(remote_device_address, return);
131 BT_CHECK_PARAMETER(remote_oob_data, return);
133 conn = _bt_get_system_conn();
134 retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
136 adapter_path = _bt_get_adapter_path();
137 retv_if(adapter_path == NULL, BLUETOOTH_ERROR_INTERNAL);
139 _bt_convert_addr_type_to_string(address,
140 remote_device_address->addr);
142 proxy = g_dbus_proxy_new_sync(conn,
143 G_DBUS_PROXY_FLAGS_NONE, NULL,
144 BT_BLUEZ_NAME, adapter_path,
145 BT_OOB_INTERFACE, NULL, &err);
146 g_free(adapter_path);
148 BT_ERR("Unable to create proxy");
150 BT_ERR("Error: %s", err->message);
153 return BLUETOOTH_ERROR_INTERNAL;
156 remote_hash = remote_oob_data->hash;
157 remote_randomizer = remote_oob_data->randomizer;
158 dev_addr = g_strdup(address);
160 BT_DBG("remote hash len = [%d] and remote random len = [%d]\n",
161 remote_oob_data->hash_len, remote_oob_data->randomizer_len);
162 /*Create array of bytes variant*/
163 in_param1 = g_array_new(TRUE, TRUE, sizeof(gchar));
164 in_param2 = g_array_new(TRUE, TRUE, sizeof(gchar));
166 g_array_append_vals(in_param1, remote_hash,
167 remote_oob_data->hash_len);
168 g_array_append_vals(in_param2, remote_randomizer,
169 remote_oob_data->randomizer_len);
171 hash = g_variant_new_from_data((const GVariantType *)"ay",
172 in_param1->data, in_param1->len,
175 randomizer = g_variant_new_from_data((const GVariantType *)"ay",
176 in_param2->data, in_param2->len,
179 g_array_free(in_param1, TRUE);
180 g_array_free(in_param2, TRUE);
182 /* Call AddRemoteData Method*/
183 reply = g_dbus_proxy_call_sync(proxy, "AddRemoteData",
184 g_variant_new("s@ay@ay", dev_addr, hash, randomizer),
185 G_DBUS_CALL_FLAGS_NONE, -1,
187 g_object_unref(proxy);
192 BT_ERR("AddRemoteData dBUS-RPC is failed");
194 BT_ERR("D-Bus API failure: errCode[%x], message[%s]",
195 err->code, err->message);
198 return BLUETOOTH_ERROR_INTERNAL;
201 g_variant_unref(reply);
202 return BLUETOOTH_ERROR_NONE;
205 int _bt_oob_remove_remote_data(
206 bluetooth_device_address_t *remote_device_address)
213 char address[BT_ADDRESS_STRING_SIZE] = { 0 };
214 GDBusConnection *conn;
216 BT_CHECK_PARAMETER(remote_device_address, return);
218 conn = _bt_get_system_conn();
219 retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
221 adapter_path = _bt_get_adapter_path();
222 retv_if(adapter_path == NULL, BLUETOOTH_ERROR_INTERNAL);
224 _bt_convert_addr_type_to_string(address,
225 remote_device_address->addr);
227 proxy = g_dbus_proxy_new_sync(conn,
228 G_DBUS_PROXY_FLAGS_NONE, NULL,
229 BT_BLUEZ_NAME, adapter_path,
230 BT_OOB_INTERFACE, NULL, &err);
231 g_free(adapter_path);
233 BT_ERR("Unable to create proxy");
235 BT_ERR("Error: %s", err->message);
238 return BLUETOOTH_ERROR_INTERNAL;
241 dev_addr = g_strdup(address);
243 /* Call RemoveRemoteData Method*/
244 reply = g_dbus_proxy_call_sync(proxy, "RemoveRemoteData",
245 g_variant_new("s", dev_addr),
246 G_DBUS_CALL_FLAGS_NONE, -1,
248 g_object_unref(proxy);
253 BT_ERR("RemoveRemoteData dBUS-RPC is failed");
255 BT_ERR("D-Bus API failure: errCode[%x], message[%s]",
256 err->code, err->message);
259 return BLUETOOTH_ERROR_INTERNAL;
262 g_variant_unref(reply);
263 return BLUETOOTH_ERROR_NONE;