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.
22 #include <syspopup_caller.h>
24 #include <bundle_internal.h>
27 #include "bluetooth-api.h"
28 #include "bt-internal-types.h"
30 #include "bt-service-common.h"
31 #include "bt-service-adapter-le.h"
32 #include "bt-service-event.h"
33 #include "bt-service-device.h"
34 #include "bt-service-rfcomm-client.h"
35 #include "bt-service-util.h"
36 #include "bt-service-agent.h"
37 #include "bt-service-network.h"
38 #include "bt-service-adapter.h"
39 #include "bt-service-gap-agent.h"
41 #define BT_SYSPOPUP_IPC_RESPONSE_OBJECT "/org/projectx/bt_syspopup_res"
42 #define BT_SYSPOPUP_INTERFACE "User.Bluetooth.syspopup"
43 #define BT_SYSPOPUP_METHOD_RESPONSE "Response"
45 #define BT_LE_CONN_INTERVAL_MIN 7.5 /* msec */
46 #define BT_LE_CONN_INTERVAL_MAX 4000 /* msec */
47 #define BT_LE_CONN_SUPER_TO_MIN 100 /* msec */
48 #define BT_LE_CONN_SUPER_TO_MAX 32000 /* msec */
49 #define BT_LE_CONN_SLAVE_LATENCY_MAX 499
50 #define BT_LE_CONN_INTERVAL_SPLIT 1.25 /* msec */
51 #define BT_LE_CONN_TO_SPLIT 10 /* msec */
52 #define BT_DEVICE_PIN_CODE_SLOT_MAX 10
54 #define BT_LE_CONN_PARAM_DEFAULT_SUPERVISION_TIMEOUT 6000 /* msec */
56 #define BT_LE_CONN_PARAM_BALANCED_MIN_INTERVAL 30 /* msec */
57 #define BT_LE_CONN_PARAM_BALANCED_MAX_INTERVAL 50 /* msec */
58 #define BT_LE_CONN_PARAM_BALANCED_SLAVE_LATENCY 0 /* event */
60 #define BT_LE_CONN_PARAM_LOW_LATENCY_MIN_INTERVAL 10 /* msec */
61 #define BT_LE_CONN_PARAM_LOW_LATENCY_MAX_INTERVAL 30 /* msec */
62 #define BT_LE_CONN_PARAM_LOW_LATENCY_SLAVE_LATENCY 0 /* event */
64 #define BT_LE_CONN_PARAM_LOW_POWER_MIN_INTERVAL 80 /* msec */
65 #define BT_LE_CONN_PARAM_LOW_POWER_MAX_INTERVAL 100 /* msec */
66 #define BT_LE_CONN_PARAM_LOW_POWER_SLAVE_LATENCY 2 /* event */
68 #define PROFILE_SUPPORTED 0x3 /* This corresponds to binary 0b11*/
75 GDBusProxy *device_proxy;
76 GDBusProxy *adapter_proxy;
78 unsigned short conn_type;
79 gboolean bonding_wo_discovery;
87 gboolean is_device_creating;
88 bt_funcion_data_t *bonding_info;
89 bt_funcion_data_t *searching_info;
90 bt_funcion_data_t *att_mtu_req_info;
92 static GSList *pin_info_list = NULL;
94 /* This HID Mouse does not support pairing precedure. need to skip it. */
95 #define SMB_MOUSE_LAP_ADDR "00:12:A1"
97 static void __bt_bond_device_cb(GDBusProxy *proxy, GAsyncResult *res,
100 static int __bt_retry_bond(void);
103 /*static void __bt_decline_pair_request()
105 GVariant *out_param1;
106 GVariant *out_param2;
107 request_info_t *req_info;
108 bluetooth_device_info_t dev_info;
109 bt_remote_dev_info_t *remote_dev_info;
110 GVariant *uuid_list, *manufacture_data;
115 req_info = _bt_get_request_info(bonding_info->req_id);
116 if (req_info == NULL) {
117 BT_ERR("req_info == NULL");
120 remote_dev_info = _bt_get_remote_device_info(bonding_info->addr);
122 BT_DBG("bonding_info is NULL");
127 uuid_list = g_variant_new_from_data((const GVariantType *)"as",
128 remote_dev_info->uuids, remote_dev_info->uuid_count,
131 manufacture_data = g_variant_new_from_data((const GVariantType *)"ay",
132 remote_dev_info->manufacturer_data, remote_dev_info->manufacturer_data_len,
135 param = g_variant_new("isunsbuba{s}na{y})",
136 bonding_info->result,
138 remote_dev_info->class,
139 remote_dev_info->rssi,
140 remote_dev_info->name,
141 remote_dev_info->paired,
142 remote_dev_info->connected,
143 remote_dev_info->trust,
145 remote_dev_info->manufacturer_data_len,
149 //Send the event to application
150 if (remote_dev_info != NULL) {
151 _bt_send_event(BT_ADAPTER_EVENT,
152 BLUETOOTH_EVENT_BONDING_FINISHED,
155 _bt_free_device_info(remote_dev_info);
158 if (req_info->context == NULL)
161 memset(&dev_info, 0x00, sizeof(bluetooth_device_info_t));
162 _bt_convert_addr_string_to_type(dev_info.device_address.addr,
165 out_param1 = g_variant_new_from_data((const GVariantType *)"ay",
166 &dev_info, sizeof(bluetooth_device_info_t), TRUE, NULL, NULL);
168 out_param2 = g_variant_new_from_data((const GVariantType *)"i",
169 &bonding_info->result, sizeof(int), TRUE, NULL, NULL);
172 g_dbus_method_invocation_return_value(req_info->context,
173 g_variant_new("@ayi", out_param1, out_param2));
176 _bt_delete_request_list(req_info->req_id);
179 g_free(bonding_info->addr);
180 g_free(bonding_info);
186 #ifdef TIZEN_WEARABLE
187 static gboolean __bt_syspopup_timer_cb(gpointer user_data)
191 retv_if(user_data == NULL, FALSE);
193 b = (bundle *)user_data;
195 ret = syspopup_launch("bt-syspopup", b);
197 BT_ERR("Sorry!! Cannot launch popup return = %d, Retrying...", ret);
199 BT_DBG("Hurray!!! Finally Popup launched");
202 return (ret < 0) ? TRUE : FALSE;
205 static gboolean __bt_launch_unable_to_pairing_syspopup(int result)
210 GDBusConnection *conn;
212 conn = _bt_get_system_gconn();
220 bundle_add(b, "event-type", "unable-to-pairing");
222 if (result == BLUETOOTH_ERROR_TIMEOUT)
223 bundle_add(b, "error", "timeout");
224 else if (result == BLUETOOTH_ERROR_AUTHENTICATION_FAILED)
225 bundle_add(b, "error", "authfailed");
227 bundle_add(b, "error", "error");
229 ret = syspopup_launch("bt-syspopup", b);
231 BT_ERR("Popup launch failed...retry %d \n", ret);
232 g_timeout_add(200, (GSourceFunc) __bt_syspopup_timer_cb,
243 gboolean _bt_is_device_creating(void)
245 return is_device_creating;
248 gboolean _bt_is_bonding_device_address(const char *address)
250 if (bonding_info == NULL || bonding_info->addr == NULL)
253 if (g_strcmp0(bonding_info->addr, address) == 0) {
254 BT_DBG("[%s] is bonding device", address);
258 BT_DBG("[%s] is NOT bonding device", address);
262 void _bt_set_autopair_status_in_bonding_info(gboolean is_autopair)
264 ret_if(bonding_info == NULL);
265 bonding_info->is_autopair = is_autopair;
268 void __bt_cancel_search_service_done(void)
270 int result = BLUETOOTH_ERROR_CANCEL_BY_USER;
271 request_info_t *req_info;
272 bluetooth_device_info_t dev_info;
273 GVariant *out_param1;
275 ret_if(searching_info == NULL);
277 req_info = _bt_get_request_info(searching_info->req_id);
278 if (req_info == NULL) {
279 BT_ERR("req_info == NULL");
283 if (req_info->context == NULL)
286 memset(&dev_info, 0x00, sizeof(bluetooth_device_info_t));
287 _bt_convert_addr_string_to_type(dev_info.device_address.addr,
288 searching_info->addr);
290 out_param1 = g_variant_new_from_data((const GVariantType *)"ay",
291 &dev_info, sizeof(bluetooth_device_info_t), TRUE, NULL, NULL);
294 g_dbus_method_invocation_return_value(req_info->context,
295 g_variant_new("(iv)", result, out_param1));
297 _bt_delete_request_list(req_info->req_id);
301 g_free(searching_info->addr);
302 g_free(searching_info);
303 searching_info = NULL;
306 static void __bt_get_uuids(GVariant *value, bt_remote_dev_info_t *info)
308 ret_if(value == NULL);
309 ret_if(info == NULL);
311 info->uuid_count = g_variant_get_size(value);
312 info->uuids = g_variant_dup_strv(value, &info->uuid_count);
315 bt_remote_dev_info_t *_bt_get_remote_device_info(char *address)
317 char *object_path = NULL;
318 bt_remote_dev_info_t *dev_info;
320 retv_if(address == NULL, NULL);
322 object_path = _bt_get_device_object_path(address);
323 retv_if(object_path == NULL, NULL);
325 dev_info = _bt_get_remote_device_info_by_object_path(object_path);
331 bt_remote_dev_info_t *_bt_get_remote_device_info_by_object_path(
332 const char *object_path)
334 bt_remote_dev_info_t *dev_info;
335 GDBusProxy *adapter_proxy;
336 GDBusProxy *device_proxy;
341 GDBusConnection *conn;
342 GError *error = NULL;
343 GVariant *result = NULL;
344 GVariantIter *value_iter;
348 adapter_proxy = _bt_get_adapter_proxy();
349 retv_if(adapter_proxy == NULL, NULL);
351 retv_if(object_path == NULL, NULL);
353 conn = _bt_get_system_gconn();
355 BT_ERR("conn == NULL");
359 device_proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
360 NULL, BT_BLUEZ_NAME, object_path,
361 BT_PROPERTIES_INTERFACE, NULL, NULL);
363 retv_if(device_proxy == NULL, NULL);
365 result = g_dbus_proxy_call_sync(device_proxy, "GetAll",
366 g_variant_new("(s)", BT_DEVICE_INTERFACE),
367 G_DBUS_CALL_FLAGS_NONE,
372 g_object_unref(device_proxy);
374 dev_info = g_malloc0(sizeof(bt_remote_dev_info_t));
376 if (result != NULL) {
377 g_variant_get(result , "(@a{sv})", &value);
378 g_variant_unref(result);
380 tmp_value = g_variant_lookup_value(value, "Alias", G_VARIANT_TYPE_STRING);
382 g_variant_get(tmp_value, "s", &name);
383 g_variant_unref(tmp_value);
385 DBG_SECURE("Alias Name [%s]", name);
387 tmp_value = g_variant_lookup_value(value, "Name", G_VARIANT_TYPE_STRING);
388 g_variant_get(tmp_value, "s", &name);
389 g_variant_unref(tmp_value);
392 tmp_value = g_variant_lookup_value (value, "IsAliasSet", G_VARIANT_TYPE_BOOLEAN);
394 dev_info->is_alias_set = g_variant_get_boolean(tmp_value);
395 g_variant_unref(tmp_value);
397 dev_info->is_alias_set = FALSE;
399 BT_DBG("IsAliasSet: [%s]", dev_info->is_alias_set ? "TRUE" : "FALSE");
401 tmp_value = g_variant_lookup_value(value, "Class", G_VARIANT_TYPE_UINT32);
403 dev_info->class = g_variant_get_uint32(tmp_value);
404 g_variant_unref(tmp_value);
408 tmp_value = g_variant_lookup_value(value, "Connected", G_VARIANT_TYPE_BYTE);
410 dev_info->connected = g_variant_get_byte(tmp_value);
411 g_variant_unref(tmp_value);
413 dev_info->connected = BLUETOOTH_CONNECTED_LINK_NONE;
414 BT_DBG("connected link : %d", dev_info->connected);
416 tmp_value = g_variant_lookup_value(value, "Trusted", G_VARIANT_TYPE_BOOLEAN);
418 dev_info->trust = g_variant_get_boolean(tmp_value);
419 g_variant_unref(tmp_value);
421 dev_info->trust = FALSE;
423 tmp_value = g_variant_lookup_value(value, "Paired", G_VARIANT_TYPE_BOOLEAN);
425 dev_info->paired = g_variant_get_boolean(tmp_value);
426 g_variant_unref(tmp_value);
428 dev_info->paired = FALSE;
430 tmp_value = g_variant_lookup_value(value, "RSSI", G_VARIANT_TYPE_INT16);
432 dev_info->rssi = g_variant_get_int16(tmp_value);
433 g_variant_unref(tmp_value);
437 tmp_value = g_variant_lookup_value(value, "LastAddrType", G_VARIANT_TYPE_BYTE);
439 dev_info->addr_type = g_variant_get_byte(tmp_value);
440 g_variant_unref(tmp_value);
442 dev_info->addr_type = 0;
444 tmp_value = g_variant_lookup_value(value, "UUIDs", G_VARIANT_TYPE_STRING_ARRAY);
446 __bt_get_uuids(tmp_value, dev_info);
447 g_variant_unref(tmp_value);
450 tmp_value = g_variant_lookup_value(value, "ManufacturerDataLen", G_VARIANT_TYPE_UINT16);
452 dev_info->manufacturer_data_len = g_variant_get_uint16(tmp_value);
453 if (dev_info->manufacturer_data_len > BLUETOOTH_MANUFACTURER_DATA_LENGTH_MAX) {
454 BT_ERR("manufacturer_data_len is too long(len = %d)", dev_info->manufacturer_data_len);
455 dev_info->manufacturer_data_len = BLUETOOTH_MANUFACTURER_DATA_LENGTH_MAX;
457 g_variant_unref(tmp_value);
459 dev_info->manufacturer_data_len = 0;
461 tmp_value = g_variant_lookup_value(value, "ManufacturerData", G_VARIANT_TYPE_ARRAY);
463 if ((dev_info->manufacturer_data_len == 0) ||
464 dev_info->manufacturer_data_len != g_variant_get_size(tmp_value)) {
465 BT_ERR("manufacturer data length doesn't match");
466 dev_info->manufacturer_data_len = 0;
467 dev_info->manufacturer_data = NULL;
469 dev_info->manufacturer_data = g_malloc0(dev_info->manufacturer_data_len);
470 g_variant_get(tmp_value, "ay", &value_iter);
471 while (g_variant_iter_loop(value_iter, "y", &m_value))
472 dev_info->manufacturer_data[i++] = m_value;
474 g_variant_unref(tmp_value);
476 BT_INFO("manufacture data is not a G_VARIANT_TYPE_ARRAY ");
477 dev_info->manufacturer_data_len = 0;
478 dev_info->manufacturer_data = NULL;
481 tmp_value = g_variant_lookup_value(value, "Address", G_VARIANT_TYPE_STRING);
482 g_variant_get(tmp_value, "s", &address);
483 g_variant_unref(tmp_value);
485 dev_info->address = g_strdup(address);
486 dev_info->name = g_strdup(name);
488 g_variant_unref(value);
490 BT_ERR("result is NULL\n");
498 char *_bt_get_bonded_device_name(char *address)
500 bluetooth_device_address_t device_address = { {0} };
501 bluetooth_device_info_t dev_info;
503 retv_if(address == NULL, strdup(""));
505 _bt_convert_addr_string_to_type(device_address.addr, address);
507 memset(&dev_info, 0x00, sizeof(bluetooth_device_info_t));
509 _bt_get_bonded_device_info(&device_address, &dev_info);
511 return g_strdup(dev_info.device_name.name);
514 static gboolean __ignore_auto_pairing_request(const char *address)
519 char lap_address[BT_LOWER_ADDRESS_LENGTH + 1] = {0,};
530 /* Get the LAP(Lower Address part) */
531 /* User BT_LOWER_ADDRESS_LENGTH+1 for lap_address to accomodate
533 snprintf(lap_address, sizeof(lap_address), ",%s", address);
535 fp = fopen(BT_AGENT_AUTO_PAIR_BLACKLIST_FILE, "r");
538 BT_ERR("fopen failed \n");
542 fseek(fp, 0, SEEK_END);
547 BT_ERR("Get file size failed \n");
552 buffer = g_malloc0(sizeof(char) * size);
553 /* Fix : NULL_RETURNS */
554 if (buffer == NULL) {
555 BT_ERR("Memory allocation error\n");
559 result = fread((char *)buffer, 1, size, fp);
561 if (result != size) {
562 BT_ERR("Read Error\n");
567 BT_DBG("Buffer = %s\n", buffer);
569 lines = g_strsplit_set(buffer, BT_AGENT_NEW_LINE, 0);
575 /* Write the data and insert new device data */
576 for (i = 0; lines[i] != NULL; i++) {
577 if (g_str_has_prefix(lines[i], "AddressBlacklist")) {
578 temp_buffer = g_strconcat(lines[i], lap_address, NULL);
580 lines[i] = temp_buffer;
583 buffer = g_strjoinv(BT_AGENT_NEW_LINE, lines);
585 /* Fix : NULL_RETURNS */
586 retv_if(buffer == NULL, FALSE);
588 fp = fopen(BT_AGENT_AUTO_PAIR_BLACKLIST_FILE, "w");
591 BT_ERR("fopen failed \n");
596 BT_DBG("Buffer = %s\n", buffer);
597 fwrite(buffer, 1, strlen(buffer), fp);
607 static int __bt_cancel_bonding(void)
609 BT_CHECK_PARAMETER(bonding_info, return);
610 BT_CHECK_PARAMETER(bonding_info->addr, return);
611 /* First Cancel the ongoing pairing in bluez otherwise if we send
612 * pair request bluez will send inprogress and we again retry bond so
613 * this cycle continues */
615 g_dbus_proxy_call_sync(bonding_info->device_proxy, "CancelPairing",
616 NULL, G_DBUS_CALL_FLAGS_NONE,
619 BT_ERR("Cancelling bonding request error msg (%s)", err->message);
621 return BLUETOOTH_ERROR_PARING_FAILED;
623 return BLUETOOTH_ERROR_NONE;
626 static int __bt_retry_bond(void)
628 BT_CHECK_PARAMETER(bonding_info, return);
629 BT_CHECK_PARAMETER(bonding_info->addr, return);
631 g_dbus_proxy_call(bonding_info->device_proxy, "Pair",
632 g_variant_new("(y)", bonding_info->conn_type),
633 G_DBUS_CALL_FLAGS_NONE,
636 (GAsyncReadyCallback)__bt_bond_device_cb,
639 return BLUETOOTH_ERROR_NONE;
643 static int __bt_remove_and_bond(void)
645 GDBusProxy *adapter_proxy;
646 GVariant *result = NULL;
648 char *device_path = NULL;
650 BT_CHECK_PARAMETER(bonding_info, return);
651 BT_CHECK_PARAMETER(bonding_info->addr, return);
653 adapter_proxy = _bt_get_adapter_proxy();
654 retv_if(adapter_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
656 result = g_dbus_proxy_call_sync(adapter_proxy, "FindDevice",
657 g_variant_new("(s)", bonding_info->addr),
658 G_DBUS_CALL_FLAGS_NONE,
663 return BLUETOOTH_ERROR_INTERNAL;
665 g_variant_get(result , "(o)", &device_path);
666 g_variant_unref(result);
668 retv_if(device_path == NULL, BLUETOOTH_ERROR_INTERNAL);
670 result = g_dbus_proxy_call_sync(adapter_proxy, "UnpairDevice",
671 g_variant_new("(o)", device_path),
672 G_DBUS_CALL_FLAGS_NONE,
678 BT_ERR("UnpairDevice Fail: %s", err->message);
680 return BLUETOOTH_ERROR_INTERNAL;
683 return __bt_retry_bond();
686 static int __bt_cancel_and_bond(void)
688 int ret = BLUETOOTH_ERROR_NONE;
690 ret = _bt_agent_reply_cancellation();
691 if (ret != BLUETOOTH_ERROR_NONE) {
692 BT_ERR("Fail to call reply cancellation");
695 return __bt_retry_bond();
699 static void __bt_bond_device_cb(GDBusProxy *proxy, GAsyncResult *res,
702 int result = BLUETOOTH_ERROR_NONE;
704 GVariant *out_param1;
705 request_info_t *req_info;
706 bluetooth_device_info_t dev_info;
707 bt_remote_dev_info_t *remote_dev_info;
708 GVariant *manufacture_data;
711 /* Terminate ALL system popup */
712 syspopup_destroy_all();
714 g_dbus_proxy_call_finish(proxy, res, &err);
716 is_device_creating = FALSE;
718 if (bonding_info == NULL) {
720 BT_ERR("bonding_info == NULL");
726 req_info = _bt_get_request_info(bonding_info->req_id);
727 if (req_info == NULL) {
728 BT_ERR("req_info == NULL");
733 g_dbus_error_strip_remote_error(err);
734 BT_ERR("Error occured in CreateBonding [%s]", err->message);
736 if (g_strrstr(err->message, "Already Exists")) {
737 BT_INFO("Existing Bond, remove and retry");
738 ret_if(__bt_remove_and_bond() == BLUETOOTH_ERROR_NONE);
740 result = BLUETOOTH_ERROR_PARING_FAILED;
741 } else if (_bt_agent_is_canceled() ||
742 g_strrstr(err->message, "Authentication Canceled")) {
743 BT_INFO("Cancelled by USER");
744 result = BLUETOOTH_ERROR_CANCEL_BY_USER;
745 } else if (g_strrstr(err->message, "Authentication Rejected")) {
747 result = BLUETOOTH_ERROR_ACCESS_DENIED;
748 } else if (g_strrstr(err->message, "In Progress")) {
749 BT_INFO("Bond in progress, cancel and retry");
750 ret_if(__bt_cancel_and_bond() == BLUETOOTH_ERROR_NONE);
752 result = BLUETOOTH_ERROR_PARING_FAILED;
753 } else if (g_strrstr(err->message, "Authentication Failed")) {
754 BT_INFO("Authentication Failed");
755 if (bonding_info->is_autopair == TRUE) {
756 _bt_set_autopair_status_in_bonding_info(FALSE);
757 __ignore_auto_pairing_request(bonding_info->addr);
759 result = BLUETOOTH_ERROR_AUTHENTICATION_FAILED;
760 } else if (g_strrstr(err->message, "Page Timeout")) {
761 BT_INFO("Page Timeout");
762 /* This is the special case
763 As soon as call bluetooth_bond_device, try to cancel bonding.
764 In this case, before completing to call 'CreatePairedDevice' method
765 the procedure is stopped. So 'Cancle' error is not return.
767 result = BLUETOOTH_ERROR_HOST_DOWN;
768 } else if (g_strrstr(err->message, BT_DBUS_TIMEOUT_MESSAGE)) {
769 BT_INFO("Cancel already running bonding");
770 if(__bt_cancel_bonding() != BLUETOOTH_ERROR_NONE) {
771 BT_INFO("Error while Cancelling bonding");
772 /* we need to unref proxy so continue */
774 result = BLUETOOTH_ERROR_INTERNAL;
775 } else if (g_strrstr(err->message, "Connection Timeout")) {
776 /* Pairing request timeout */
777 result = BLUETOOTH_ERROR_TIMEOUT;
778 } else if (g_strrstr(err->message, "Authentication Timeout")) {
779 /* Pairing request timeout */
780 result = BLUETOOTH_ERROR_TIMEOUT;
782 BT_DBG("Default case");
783 result = BLUETOOTH_ERROR_PARING_FAILED;
787 if (result == BLUETOOTH_ERROR_PARING_FAILED ||
788 result == BLUETOOTH_ERROR_AUTHENTICATION_FAILED ||
789 result == BLUETOOTH_ERROR_TIMEOUT ||
790 result == BLUETOOTH_ERROR_HOST_DOWN) {
791 #ifdef TIZEN_WEARABLE
792 int is_sw_running = 0;
794 if (vconf_get_int(VCONFKEY_SETUP_WIZARD_STATE, &is_sw_running))
795 BT_ERR("vconf_get_int for setup wizard state failed");
798 __bt_launch_unable_to_pairing_syspopup(result);
800 BT_ERR("Unable to pair");
802 bonding_info->result = result;
805 g_object_unref(proxy);
806 bonding_info->device_proxy = NULL;
808 if (result != BLUETOOTH_ERROR_NONE) {
809 if (bonding_info->bonding_wo_discovery) {
810 GDBusProxy *adapter_proxy;
811 GVariant *ret = NULL;
812 GError *error = NULL;
815 BT_ERR("Bond was tried without discovery. Remove it");
817 adapter_proxy = _bt_get_adapter_proxy();
818 if (adapter_proxy == NULL) {
819 BT_ERR("Cannot get adapter_proxy");
823 device_path = _bt_get_device_object_path(bonding_info->addr);
824 if (device_path == NULL) {
825 BT_ERR("Cannot get device path");
829 ret = g_dbus_proxy_call_sync(adapter_proxy,
831 g_variant_new("(o)", device_path),
832 G_DBUS_CALL_FLAGS_NONE, -1, NULL,
835 BT_ERR("RemoveDevice Fail: %s", error->message);
836 g_clear_error(&error);
840 g_variant_unref(ret);
848 remote_dev_info = _bt_get_remote_device_info(bonding_info->addr);
852 GVariant *uuids = NULL;
853 GVariantBuilder *builder = NULL;
855 builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
856 for (i = 0; i < remote_dev_info->uuid_count; i++) {
857 g_variant_builder_add(builder, "s",
858 remote_dev_info->uuids[i]);
860 uuids = g_variant_new("as", builder);
861 g_variant_builder_unref(builder);
862 manufacture_data = g_variant_new_from_data((const GVariantType *)"ay",
863 remote_dev_info->manufacturer_data, remote_dev_info->manufacturer_data_len,
866 param = g_variant_new("(isunsbub@asn@ay)",
869 remote_dev_info->class,
870 remote_dev_info->rssi,
871 remote_dev_info->name,
872 remote_dev_info->paired,
873 remote_dev_info->connected,
874 remote_dev_info->trust,
876 remote_dev_info->manufacturer_data_len,
880 /* Send the event to application */
881 _bt_send_event(BT_ADAPTER_EVENT,
882 BLUETOOTH_EVENT_BONDING_FINISHED,
885 _bt_free_device_info(remote_dev_info);
888 if (req_info->context == NULL)
891 memset(&dev_info, 0x00, sizeof(bluetooth_device_info_t));
892 _bt_convert_addr_string_to_type(dev_info.device_address.addr,
895 if (_bt_adapter_get_status() != BT_ACTIVATED)
896 result = BLUETOOTH_ERROR_NOT_IN_OPERATION;
898 out_param1 = g_variant_new_from_data((const GVariantType *)"ay",
899 &dev_info, sizeof(bluetooth_device_info_t), TRUE, NULL, NULL);
901 g_dbus_method_invocation_return_value(req_info->context,
902 g_variant_new("(iv)", result, out_param1));
904 g_variant_unref(out_param1);
906 _bt_delete_request_list(req_info->req_id);
911 _bt_agent_set_canceled(FALSE);
914 g_free(bonding_info->addr);
915 g_free(bonding_info);
919 int _bt_bond_device(int request_id,
920 bluetooth_device_address_t *device_address,
921 unsigned short conn_type, GArray **out_param1)
924 char address[BT_ADDRESS_STRING_SIZE] = { 0 };
925 bluetooth_device_info_t dev_info;
927 GDBusConnection *conn;
928 char *device_path = NULL;
929 GDBusProxy *adapter_proxy;
930 GError *error = NULL;
931 gboolean bonding_wo_discovery = FALSE;
933 BT_CHECK_PARAMETER(device_address, return);
936 BT_ERR("Bonding in progress");
938 memset(&dev_info, 0x00, sizeof(bluetooth_device_info_t));
939 memcpy(dev_info.device_address.addr, device_address->addr,
940 BLUETOOTH_ADDRESS_LENGTH);
942 g_array_append_vals(*out_param1, &dev_info,
943 sizeof(bluetooth_device_info_t));
945 return BLUETOOTH_ERROR_DEVICE_BUSY;
948 conn = _bt_get_system_gconn();
949 retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
951 _bt_convert_addr_type_to_string(address, device_address->addr);
953 device_path = _bt_get_device_object_path(address);
955 if (device_path == NULL) {
956 BT_ERR("No searched device");
957 GVariant *ret = NULL;
958 adapter_proxy = _bt_get_adapter_proxy();
959 retv_if(adapter_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
961 ret = g_dbus_proxy_call_sync(adapter_proxy, "CreateDevice",
962 g_variant_new("(s)", address),
963 G_DBUS_CALL_FLAGS_NONE,
969 BT_ERR("CreateDevice Fail: %s", error->message);
970 g_clear_error(&error);
973 g_variant_unref(ret);
974 device_path = _bt_get_device_object_path(address);
975 if (device_path == NULL) {
976 memset(&dev_info, 0x00, sizeof(bluetooth_device_info_t));
977 memcpy(dev_info.device_address.addr, device_address->addr,
978 BLUETOOTH_ADDRESS_LENGTH);
980 g_array_append_vals(*out_param1, &dev_info,
981 sizeof(bluetooth_device_info_t));
983 return BLUETOOTH_ERROR_NOT_PAIRED;
985 BT_INFO("device_path is created[%s]", device_path);
987 bonding_wo_discovery = TRUE;
990 proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
992 device_path, BT_DEVICE_INTERFACE, NULL, NULL);
995 retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
997 bonding_info = g_malloc0(sizeof(bt_funcion_data_t));
998 bonding_info->addr = g_strdup(address);
999 bonding_info->req_id = request_id;
1001 bonding_info->device_proxy = proxy;
1002 bonding_info->conn_type = conn_type;
1003 bonding_info->bonding_wo_discovery = bonding_wo_discovery;
1005 is_device_creating = TRUE;
1007 g_dbus_proxy_call(proxy, "Pair",
1008 g_variant_new("(y)", conn_type),
1009 G_DBUS_CALL_FLAGS_NONE,
1010 BT_MAX_DBUS_TIMEOUT,
1012 (GAsyncReadyCallback)__bt_bond_device_cb,
1015 /* TODO: We need to check if we can pair the specific device using 'pair' API of bluez 5.x */
1017 return BLUETOOTH_ERROR_NONE;
1019 memset(&dev_info, 0x00, sizeof(bluetooth_device_info_t));
1020 _bt_convert_addr_string_to_type(dev_info.device_address.addr,
1021 bonding_info->addr);
1023 g_array_append_vals(*out_param1, &dev_info,
1024 sizeof(bluetooth_device_info_t));
1026 is_device_creating = FALSE;
1028 g_free(bonding_info->addr);
1029 g_free(bonding_info);
1030 bonding_info = NULL;
1032 return BLUETOOTH_ERROR_INTERNAL;*/
1035 int _bt_cancel_bonding(void)
1037 int ret = BLUETOOTH_ERROR_NONE;
1039 retv_if(bonding_info == NULL, BLUETOOTH_ERROR_NOT_IN_OPERATION);
1041 ret = _bt_agent_reply_cancellation();
1042 if (ret != BLUETOOTH_ERROR_NONE) {
1043 BT_ERR("Fail to call reply cancellation");
1047 _bt_agent_set_canceled(TRUE);
1049 return BLUETOOTH_ERROR_NONE;
1052 static void __bt_unbond_cb(GDBusProxy *proxy, GAsyncResult *res,
1056 GVariant *out_param1;
1057 int result = BLUETOOTH_ERROR_NONE;
1058 bt_funcion_data_t *unbonding_info;
1059 bluetooth_device_info_t dev_info;
1060 request_info_t *req_info;
1062 g_dbus_proxy_call_finish(proxy, res, &err);
1064 unbonding_info = user_data;
1066 if (unbonding_info == NULL) {
1068 BT_ERR("unbonding_info == NULL");
1072 req_info = _bt_get_request_info(unbonding_info->req_id);
1073 if (req_info == NULL) {
1074 BT_ERR("req_info == NULL");
1079 BT_ERR("Error occured in RemoveBonding [%s]\n", err->message);
1080 result = BLUETOOTH_ERROR_INTERNAL;
1083 if (req_info->context == NULL)
1086 memset(&dev_info, 0x00, sizeof(bluetooth_device_info_t));
1087 _bt_convert_addr_string_to_type(dev_info.device_address.addr,
1088 unbonding_info->addr);
1090 out_param1 = g_variant_new_from_data((const GVariantType *)"ay",
1091 &dev_info, sizeof(bluetooth_device_info_t), TRUE, NULL, NULL);
1093 g_dbus_method_invocation_return_value(req_info->context,
1094 g_variant_new("(iv)", result, out_param1));
1097 _bt_delete_request_list(req_info->req_id);
1103 if (unbonding_info) {
1104 g_free(unbonding_info->addr);
1105 g_free(unbonding_info);
1109 int _bt_unbond_device(int request_id,
1110 bluetooth_device_address_t *device_address,
1111 GArray **out_param1)
1113 char *device_path = NULL;
1114 bt_funcion_data_t *unbonding_info;
1115 GDBusProxy *adapter_proxy = NULL;
1116 GDBusProxy *device_proxy = NULL;
1117 GDBusConnection *conn;
1118 int result = BLUETOOTH_ERROR_INTERNAL;
1119 bluetooth_device_info_t dev_info;
1120 GError *error = NULL;
1121 GVariant *ret = NULL;
1123 BT_CHECK_PARAMETER(device_address, return);
1125 adapter_proxy = _bt_get_adapter_proxy();
1126 retv_if(adapter_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
1128 /* allocate user data so that it can be retrieved in callback */
1129 unbonding_info = g_malloc0(sizeof(bt_funcion_data_t));
1130 /* Fix : NULL_RETURNS */
1131 if (unbonding_info == NULL) {
1132 BT_ERR("Memory not allocated !");
1133 return BLUETOOTH_ERROR_MEMORY_ALLOCATION;
1136 unbonding_info->addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
1137 unbonding_info->req_id = request_id;
1139 _bt_convert_addr_type_to_string(unbonding_info->addr,
1140 device_address->addr);
1142 device_path = _bt_get_device_object_path(unbonding_info->addr);
1144 if (device_path == NULL) {
1145 BT_ERR("No paired device");
1146 result = BLUETOOTH_ERROR_NOT_PAIRED;
1150 conn = _bt_get_system_gconn();
1152 BT_ERR("conn is NULL");
1153 result = BLUETOOTH_ERROR_INTERNAL;
1157 device_proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
1158 NULL, BT_BLUEZ_NAME,
1159 device_path, BT_PROPERTIES_INTERFACE, NULL, NULL);
1161 if (device_proxy != NULL) {
1163 ret = g_dbus_proxy_call_sync(device_proxy, "Get",
1164 g_variant_new("(ss)", BT_DEVICE_INTERFACE, "Paired"),
1165 G_DBUS_CALL_FLAGS_NONE,
1170 BT_ERR("Getting property failed: [%s]\n", error->message);
1171 g_error_free(error);
1172 result = BLUETOOTH_ERROR_NOT_PAIRED;
1176 BT_ERR("No paired device");
1177 g_object_unref(device_proxy);
1178 result = BLUETOOTH_ERROR_NOT_PAIRED;
1181 g_variant_unref(ret);
1183 g_object_unref(device_proxy);
1186 g_dbus_proxy_call(adapter_proxy, "UnpairDevice",
1187 g_variant_new("(o)", device_path),
1188 G_DBUS_CALL_FLAGS_NONE,
1189 BT_MAX_DBUS_TIMEOUT,
1191 (GAsyncReadyCallback)__bt_unbond_cb,
1194 g_free(device_path);
1195 return BLUETOOTH_ERROR_NONE;
1198 memset(&dev_info, 0x00, sizeof(bluetooth_device_info_t));
1199 _bt_convert_addr_string_to_type(dev_info.device_address.addr,
1200 unbonding_info->addr);
1202 g_array_append_vals(*out_param1, &dev_info,
1203 sizeof(bluetooth_device_info_t));
1204 g_free(device_path);
1205 g_free(unbonding_info->addr);
1206 g_free(unbonding_info);
1210 static void __bt_discover_cb(GDBusProxy *proxy, GAsyncResult *res,
1214 GVariant *out_param1;
1215 int result = BLUETOOTH_ERROR_NONE;
1216 bluetooth_device_info_t dev_info;
1217 bt_remote_dev_info_t *remote_dev_info;
1218 request_info_t *req_info;
1219 GVariant *uuid_list, *manufacture_data;
1221 GVariantBuilder *builder = NULL;
1224 g_dbus_proxy_call_finish(proxy, res, &err);
1226 g_object_unref(proxy);
1228 if (searching_info == NULL) {
1230 BT_ERR("unbonding_info == NULL");
1234 req_info = _bt_get_request_info(searching_info->req_id);
1235 if (req_info == NULL) {
1236 BT_ERR("req_info == NULL");
1241 g_dbus_error_strip_remote_error(err);
1242 BT_ERR("Error occured in Proxy call [%s]\n", err->message);
1244 if (g_strrstr("Operation canceled", err->message)) {
1245 result = BLUETOOTH_ERROR_CANCEL_BY_USER;
1246 } else if (g_strrstr("In Progress", err->message)) {
1247 result = BLUETOOTH_ERROR_IN_PROGRESS;
1248 } else if (g_strrstr("Host is down", err->message)) {
1249 result = BLUETOOTH_ERROR_HOST_DOWN;
1251 result = BLUETOOTH_ERROR_CONNECTION_ERROR;
1254 if (result == BLUETOOTH_ERROR_HOST_DOWN ||
1255 result == BLUETOOTH_ERROR_CONNECTION_ERROR) {
1256 remote_dev_info = _bt_get_remote_device_info(searching_info->addr);
1257 if (remote_dev_info && remote_dev_info->uuids != NULL &&
1258 remote_dev_info->uuid_count > 0) {
1259 result = BLUETOOTH_ERROR_NONE;
1262 _bt_free_device_info(remote_dev_info);
1267 remote_dev_info = _bt_get_remote_device_info(searching_info->addr);
1268 if(!remote_dev_info)
1272 builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
1273 for (i = 0; i < remote_dev_info->uuid_count; i++) {
1274 g_variant_builder_add(builder, "s",
1275 remote_dev_info->uuids[i]);
1277 uuid_list = g_variant_new("as", builder);
1278 g_variant_builder_unref(builder);
1279 manufacture_data = g_variant_new_from_data((const GVariantType *)"ay",
1280 remote_dev_info->manufacturer_data, remote_dev_info->manufacturer_data_len,
1283 param = g_variant_new("(isunsbub@asn@ay)",
1285 searching_info->addr,
1286 remote_dev_info->class,
1287 remote_dev_info->rssi,
1288 remote_dev_info->name,
1289 remote_dev_info->paired,
1290 remote_dev_info->connected,
1291 remote_dev_info->trust,
1293 remote_dev_info->manufacturer_data_len,
1296 /* Send the event to application */
1297 _bt_send_event(BT_ADAPTER_EVENT,
1298 BLUETOOTH_EVENT_SERVICE_SEARCHED,
1301 _bt_free_device_info(remote_dev_info);
1304 if (req_info->context == NULL)
1307 memset(&dev_info, 0x00, sizeof(bluetooth_device_info_t));
1308 _bt_convert_addr_string_to_type(dev_info.device_address.addr,
1309 searching_info->addr);
1311 out_param1 = g_variant_new_from_data((const GVariantType *)"ay",
1312 &dev_info, sizeof(bluetooth_device_info_t), TRUE, NULL, NULL);
1314 g_dbus_method_invocation_return_value(req_info->context,
1315 g_variant_new("(iv)", result, out_param1));
1318 _bt_delete_request_list(req_info->req_id);
1323 if (searching_info) {
1324 g_free(searching_info->addr);
1325 g_free(searching_info);
1326 searching_info = NULL;
1330 int _bt_search_device(int request_id,
1331 bluetooth_device_address_t *device_address)
1333 char *device_path = NULL;
1334 GDBusProxy *device_proxy = NULL;
1335 GDBusConnection *conn;
1337 GDBusProxy *adapter_proxy;
1338 int result = BLUETOOTH_ERROR_INTERNAL;
1340 BT_CHECK_PARAMETER(device_address, return);
1343 BT_ERR("Bonding in progress");
1344 return BLUETOOTH_ERROR_DEVICE_BUSY;
1347 if (searching_info) {
1348 BT_ERR("Service searching in progress");
1349 return BLUETOOTH_ERROR_DEVICE_BUSY;
1352 adapter_proxy = _bt_get_adapter_proxy();
1353 retv_if(adapter_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
1355 /* allocate user data so that it can be retrieved in callback */
1356 searching_info = g_malloc0(sizeof(bt_funcion_data_t));
1357 searching_info->addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
1358 searching_info->req_id = request_id;
1360 _bt_convert_addr_type_to_string(searching_info->addr,
1361 device_address->addr);
1363 conn = _bt_get_system_gconn();
1364 retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
1367 device_path = _bt_get_device_object_path(searching_info->addr);
1369 if (device_path == NULL) {
1370 BT_ERR("No paired device");
1371 result = BLUETOOTH_ERROR_NOT_PAIRED;
1375 device_proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
1376 NULL, BT_BLUEZ_NAME,
1377 device_path, BT_DEVICE_INTERFACE, NULL, NULL);
1378 g_free(device_path);
1379 if (device_proxy == NULL) {
1380 result = BLUETOOTH_ERROR_INTERNAL;
1384 g_dbus_proxy_call(device_proxy, "DiscoverServices",
1385 g_variant_new("(s)", ""),
1386 G_DBUS_CALL_FLAGS_NONE,
1387 BT_MAX_DBUS_TIMEOUT,
1389 (GAsyncReadyCallback)__bt_discover_cb,
1392 searching_info->device_proxy = device_proxy;
1394 return BLUETOOTH_ERROR_NONE;
1397 g_free(searching_info->addr);
1398 g_free(searching_info);
1399 searching_info = NULL;
1403 int _bt_cancel_search_device(void)
1405 GVariant *ret = NULL;
1408 retv_if(searching_info == NULL, BLUETOOTH_ERROR_NOT_IN_OPERATION);
1410 if (searching_info->device_proxy) {
1411 ret = g_dbus_proxy_call_sync(searching_info->device_proxy, "CancelDiscovery",
1413 G_DBUS_CALL_FLAGS_NONE,
1418 g_variant_unref(ret);
1420 __bt_cancel_search_service_done();
1422 return BLUETOOTH_ERROR_NONE;
1425 int _bt_set_alias(bluetooth_device_address_t *device_address,
1428 char address[BT_ADDRESS_STRING_SIZE] = { 0 };
1429 gchar *device_path = NULL;
1430 GDBusProxy *adapter_proxy;
1431 GDBusProxy *device_proxy;
1432 GVariant *ret = NULL;
1433 GError *error = NULL;
1434 GDBusConnection *conn;
1436 BT_CHECK_PARAMETER(device_address, return);
1437 BT_CHECK_PARAMETER(alias, return);
1439 adapter_proxy = _bt_get_adapter_proxy();
1440 retv_if(adapter_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
1442 conn = _bt_get_system_gconn();
1443 retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
1445 _bt_convert_addr_type_to_string(address, device_address->addr);
1447 device_path = _bt_get_device_object_path(address);
1449 if (device_path == NULL) {
1450 BT_ERR("No paired device");
1451 return BLUETOOTH_ERROR_NOT_PAIRED;
1454 device_proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
1455 NULL, BT_BLUEZ_NAME,
1456 device_path, BT_PROPERTIES_INTERFACE, NULL, NULL);
1458 g_free(device_path);
1459 retv_if(device_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
1461 ret = g_dbus_proxy_call_sync(device_proxy, "Set",
1462 g_variant_new("(ssv)", BT_DEVICE_INTERFACE, "Alias", g_variant_new("s", alias)),
1463 G_DBUS_CALL_FLAGS_NONE,
1468 g_variant_unref(ret);
1470 g_object_unref(device_proxy);
1473 BT_ERR("SetProperty error: [%s]", error->message);
1474 g_error_free(error);
1475 return BLUETOOTH_ERROR_INTERNAL;
1478 return BLUETOOTH_ERROR_NONE;
1481 int _bt_set_authorization(bluetooth_device_address_t *device_address,
1484 char address[BT_ADDRESS_STRING_SIZE] = { 0 };
1485 gchar *device_path = NULL;
1486 GDBusProxy *device_proxy;
1487 gboolean previous_value;
1488 GError *error = NULL;
1489 GDBusConnection *conn;
1490 GVariant *result = NULL;
1491 GVariant *temp = NULL;
1492 int ret = BLUETOOTH_ERROR_NONE;
1494 BT_CHECK_PARAMETER(device_address, return);
1496 conn = _bt_get_system_gconn();
1497 retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
1499 _bt_convert_addr_type_to_string(address, device_address->addr);
1501 device_path = _bt_get_device_object_path(address);
1503 if (device_path == NULL) {
1504 BT_ERR("No paired device");
1505 return BLUETOOTH_ERROR_NOT_PAIRED;
1508 device_proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
1509 NULL, BT_BLUEZ_NAME,
1510 device_path, BT_PROPERTIES_INTERFACE, NULL, NULL);
1512 g_free(device_path);
1513 retv_if(device_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
1515 result = g_dbus_proxy_call_sync(device_proxy, "Get",
1516 g_variant_new("(ss)", BT_DEVICE_INTERFACE, "Trusted"),
1517 G_DBUS_CALL_FLAGS_NONE,
1521 if (error != NULL) {
1522 BT_ERR("Getting property failed: [%s]\n", error->message);
1523 g_error_free(error);
1524 g_object_unref(device_proxy);
1525 return BLUETOOTH_ERROR_INTERNAL;
1528 g_variant_get(result, "(v)", &temp);
1529 previous_value = g_variant_get_boolean(temp);
1530 g_variant_unref(temp);
1531 g_variant_unref(result);
1532 /* If the input is same with previous value, return error. */
1533 if (previous_value == authorize) {
1534 BT_ERR("Same value: %d", previous_value);
1535 g_object_unref(device_proxy);
1536 ret = BLUETOOTH_ERROR_INVALID_PARAM;
1540 result = g_dbus_proxy_call_sync(device_proxy, "Set",
1541 g_variant_new("(ssv)", BT_DEVICE_INTERFACE, "Trusted", g_variant_new("b",authorize)),
1542 G_DBUS_CALL_FLAGS_NONE,
1547 g_object_unref(device_proxy);
1549 BT_ERR("SetProperty error: [%s]", error->message);
1550 g_error_free(error);
1551 ret = BLUETOOTH_ERROR_INTERNAL;
1555 g_variant_unref(result);
1560 int _bt_is_gatt_connected(bluetooth_device_address_t *device_address,
1561 gboolean *is_connected)
1563 char address[BT_ADDRESS_STRING_SIZE] = { 0 };
1564 char *object_path = NULL;
1566 GDBusProxy *device_proxy;
1567 GError *error = NULL;
1569 GVariant *tmp_value;
1570 GDBusConnection *conn;
1571 GVariant *result = NULL;
1572 int ret = BLUETOOTH_ERROR_NONE;
1574 BT_CHECK_PARAMETER(device_address, return);
1576 conn = _bt_get_system_gconn();
1577 retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
1579 _bt_convert_addr_type_to_string(address, device_address->addr);
1581 object_path = _bt_get_device_object_path(address);
1582 retv_if(object_path == NULL, BLUETOOTH_ERROR_NOT_PAIRED);
1584 device_proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
1585 NULL, BT_BLUEZ_NAME, object_path,
1586 BT_PROPERTIES_INTERFACE, NULL, NULL);
1587 g_free(object_path);
1588 retv_if(device_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
1590 result = g_dbus_proxy_call_sync(device_proxy, "GetAll",
1591 g_variant_new("(s)", BT_DEVICE_INTERFACE),
1592 G_DBUS_CALL_FLAGS_NONE,
1596 if (result == NULL) {
1597 if (error != NULL) {
1598 BT_ERR("Error occured in Proxy call [%s]\n", error->message);
1599 g_error_free(error);
1601 g_object_unref(device_proxy);
1602 return BLUETOOTH_ERROR_INTERNAL;
1605 g_variant_get(result , "(@a{sv})", &value);
1606 g_variant_unref(result);
1608 tmp_value = g_variant_lookup_value(value, "GattConnected", G_VARIANT_TYPE_BOOLEAN);
1609 if (tmp_value == NULL) {
1610 g_object_unref(device_proxy);
1611 g_variant_unref(value);
1612 return BLUETOOTH_ERROR_INTERNAL;
1615 *is_connected = g_variant_get_boolean(tmp_value);
1617 BT_DBG("gatt is connected : %d", *is_connected);
1619 g_variant_unref(tmp_value);
1620 g_variant_unref(value);
1621 g_object_unref(device_proxy);
1626 int _bt_is_device_connected(bluetooth_device_address_t *device_address,
1627 int connection_type, gboolean *is_connected)
1629 char *object_path = NULL;
1630 char address[BT_ADDRESS_STRING_SIZE] = { 0 };
1631 GDBusProxy *device_proxy = NULL;
1632 GDBusProxy *adapter_proxy = NULL;
1633 GDBusConnection *conn;
1634 GError *error = NULL;
1635 GVariant *tmp_value = NULL;
1636 GVariant *value = NULL;
1637 GVariant *result = NULL;
1640 retv_if(device_address == NULL, BLUETOOTH_ERROR_INVALID_PARAM);
1641 retv_if(is_connected == NULL, BLUETOOTH_ERROR_INVALID_PARAM);
1643 *is_connected = FALSE;
1644 BT_DBG("connection_type: %d", connection_type);
1645 if (connection_type == BLUETOOTH_RFCOMM_SERVICE)
1646 return _bt_rfcomm_is_device_connected(device_address,
1648 else if (connection_type == BLUETOOTH_GATT_SERVICE)
1649 return _bt_is_gatt_connected(device_address, is_connected);
1651 adapter_proxy = _bt_get_adapter_proxy();
1652 retv_if(adapter_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
1654 conn = _bt_get_system_gconn();
1655 retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
1657 _bt_convert_addr_type_to_string(address, device_address->addr);
1659 if (connection_type == BLUETOOTH_NAP_SERVER_SERVICE) {
1660 object_path = _bt_get_adapter_path();
1661 device_proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
1662 NULL, BT_BLUEZ_NAME,
1663 object_path, BT_NETWORK_SERVER_INTERFACE, NULL, NULL);
1664 g_free(object_path);
1665 if (device_proxy == NULL) {
1666 BT_DBG("Device don't have this service");
1667 return BLUETOOTH_ERROR_INTERNAL;
1670 result = g_dbus_proxy_call_sync(device_proxy, "GetProperties",
1671 g_variant_new("(s)", address),
1672 G_DBUS_CALL_FLAGS_NONE,
1677 if (result == NULL) {
1678 BT_ERR("[GetProperties] Error occured in Proxy call");
1680 BT_ERR("%s", error->message);
1681 g_error_free(error);
1683 g_object_unref(device_proxy);
1684 return BLUETOOTH_ERROR_INTERNAL;
1686 g_variant_get(result , "(@a{sv})", &value);
1687 g_variant_unref(result);
1690 tmp_value = g_variant_lookup_value(value,
1692 G_VARIANT_TYPE_BOOLEAN);
1694 *is_connected = g_variant_get_boolean(tmp_value);
1695 g_variant_unref(tmp_value);
1697 g_variant_unref(value);
1699 } else if (connection_type == BLUETOOTH_NAP_SERVICE) {
1700 return _bt_is_network_connected(_bt_get_net_conn(),
1701 device_address->addr, is_connected);
1703 uuid = _bt_get_profile_uuid128(connection_type);
1705 BT_ERR("uuid is NULL");
1706 return BLUETOOTH_ERROR_INTERNAL;
1709 BT_DBG("uuid: %s", uuid);
1711 object_path = _bt_get_device_object_path(address);
1712 retv_if(object_path == NULL, BLUETOOTH_ERROR_NOT_PAIRED);
1713 BT_DBG("object_path: %s", object_path);
1714 device_proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
1715 NULL, BT_BLUEZ_NAME,
1716 object_path, BT_DEVICE_INTERFACE, NULL, NULL);
1717 g_free(object_path);
1718 if (device_proxy == NULL) {
1719 BT_DBG("Device don't have this service");
1721 return BLUETOOTH_ERROR_INTERNAL;
1724 result = g_dbus_proxy_call_sync(device_proxy, "IsConnectedProfile",
1725 g_variant_new("(s)", uuid),
1726 G_DBUS_CALL_FLAGS_NONE,
1731 if (result == NULL) {
1732 int ret = BLUETOOTH_ERROR_INTERNAL;
1733 BT_ERR("[IsConnectedProfile] Error occured in Proxy call");
1735 BT_ERR("%s", error->message);
1736 if (g_strrstr(error->message, "Not Connected"))
1737 ret = BLUETOOTH_ERROR_NOT_CONNECTED;
1738 g_error_free(error);
1740 g_object_unref(device_proxy);
1743 g_variant_get(result, "(b)", is_connected);
1745 g_variant_unref(result);
1748 g_object_unref(device_proxy);
1749 return BLUETOOTH_ERROR_NONE;
1752 int _bt_get_connected_link(bluetooth_device_address_t *device_address,
1753 bluetooth_connected_link_t *connected)
1755 char address[BT_ADDRESS_STRING_SIZE] = { 0 };
1756 char *object_path = NULL;
1758 GDBusProxy *device_proxy;
1759 GError *error = NULL;
1760 GDBusConnection *conn;
1761 GVariant *tmp_value = NULL;
1762 GVariant *value = NULL;
1763 GVariant *result = NULL;
1765 BT_CHECK_PARAMETER(device_address, return);
1767 conn = _bt_get_system_gconn();
1768 retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
1770 _bt_convert_addr_type_to_string(address, device_address->addr);
1772 object_path = _bt_get_device_object_path(address);
1773 retv_if(object_path == NULL, BLUETOOTH_ERROR_NOT_PAIRED);
1775 device_proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
1776 NULL, BT_BLUEZ_NAME,
1777 object_path, BT_PROPERTIES_INTERFACE, NULL, NULL);
1778 g_free(object_path);
1779 if (device_proxy == NULL) {
1780 *connected = BLUETOOTH_CONNECTED_LINK_NONE;
1781 return BLUETOOTH_ERROR_NONE;
1784 result = g_dbus_proxy_call_sync(device_proxy, "GetAll",
1785 g_variant_new("(s)", BT_DEVICE_INTERFACE),
1786 G_DBUS_CALL_FLAGS_NONE,
1791 if (error != NULL) {
1792 BT_ERR("Error occured in Proxy call [%s]\n", error->message);
1793 g_error_free(error);
1794 g_object_unref(device_proxy);
1795 return BLUETOOTH_ERROR_INTERNAL;
1798 g_variant_get(result , "(@a{sv})", &value);
1799 g_variant_unref(result);
1801 tmp_value = g_variant_lookup_value(value, "Connected", G_VARIANT_TYPE_BYTE);
1802 if (tmp_value != NULL) {
1803 *connected = g_variant_get_byte(tmp_value);
1804 g_variant_unref(tmp_value);
1805 g_object_unref(device_proxy);
1806 return BLUETOOTH_ERROR_NONE;
1808 BT_ERR("g_variant value is NULL");
1809 return BLUETOOTH_ERROR_INTERNAL;
1813 static void __le_connection_req_cb(GDBusProxy *proxy, GAsyncResult *res,
1817 GVariant *out_param1;
1819 int result = BLUETOOTH_ERROR_NONE;
1820 bt_function_data_t *func_data = user_data;
1821 request_info_t *req_info = NULL;
1822 bluetooth_device_address_t device_addr = { {0} };
1824 reply = g_dbus_proxy_call_finish(proxy, res, &err);
1825 g_object_unref(proxy);
1827 if (reply == NULL) {
1828 BT_ERR("ConnectLE / DisconnectLE DBus call error");
1830 BT_ERR("Error: %s", err->message);
1831 g_clear_error(&err);
1833 result = BLUETOOTH_ERROR_INTERNAL;
1835 g_variant_unref(reply);
1838 if (func_data == NULL) {
1839 BT_ERR("func_data is NULL");
1843 req_info = _bt_get_request_info(func_data->req_id);
1844 if (req_info == NULL) {
1845 BT_ERR("req_info is NULL");
1849 if (req_info->context == NULL) {
1850 BT_ERR("req_info->context is NULL");
1854 _bt_convert_addr_string_to_type(device_addr.addr,
1855 (const char *)func_data->address);
1857 out_param1 = g_variant_new_from_data((const GVariantType *)"ay",
1858 &device_addr, sizeof(bluetooth_device_address_t), TRUE,
1861 g_dbus_method_invocation_return_value(req_info->context,
1862 g_variant_new("(iv)", result, out_param1));
1866 _bt_delete_request_list(req_info->req_id);
1869 g_free(func_data->address);
1874 int _bt_connect_le_device(int req_id, const bluetooth_device_address_t *bd_addr,
1875 gboolean auto_connect)
1877 char device_address[BT_ADDRESS_STRING_SIZE] = { 0 };
1878 gchar *device_path = NULL;
1879 GDBusProxy *device_proxy = NULL;
1880 GDBusConnection *conn;
1881 int ret = BLUETOOTH_ERROR_NONE;
1882 bt_function_data_t *func_data;
1884 BT_CHECK_PARAMETER(bd_addr, return);
1886 conn = _bt_get_system_gconn();
1887 retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
1889 _bt_convert_addr_type_to_string(device_address,
1890 (unsigned char *)bd_addr->addr);
1891 device_path = _bt_get_device_object_path(device_address);
1892 if (device_path == NULL) {
1893 BT_ERR_C("device_path NULL : [%s]", device_address);
1894 ret = BLUETOOTH_ERROR_INTERNAL;
1898 device_proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
1899 NULL, BT_BLUEZ_NAME,
1900 device_path, BT_DEVICE_INTERFACE, NULL, NULL);
1901 g_free(device_path);
1902 retv_if(device_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
1904 func_data = g_malloc0(sizeof(bt_function_data_t));
1905 func_data->address = g_strdup(device_address);
1906 if (func_data->address == NULL) {
1907 BT_ERR("Unable to allocate memory for address");
1908 ret = BLUETOOTH_ERROR_MEMORY_ALLOCATION;
1912 func_data->req_id = req_id;
1914 ret = _bt_hold_current_advertising();
1915 if (ret != BLUETOOTH_ERROR_NONE) {
1916 BT_ERR("Unable to hold advertising");
1919 g_dbus_proxy_call(device_proxy, "ConnectLE",
1920 g_variant_new("(b)", auto_connect),
1921 G_DBUS_CALL_FLAGS_NONE,
1922 BT_MAX_DBUS_TIMEOUT,
1924 (GAsyncReadyCallback)__le_connection_req_cb, func_data);
1930 g_object_unref(device_proxy);
1932 g_free(func_data->address);
1938 int _bt_disconnect_le_device(int req_id,
1939 const bluetooth_device_address_t *bd_addr)
1941 char device_address[BT_ADDRESS_STRING_SIZE] = { 0 };
1943 GDBusProxy *device_proxy;
1944 GDBusConnection *conn;
1945 int ret = BLUETOOTH_ERROR_NONE;
1946 bt_function_data_t *func_data;
1948 BT_CHECK_PARAMETER(bd_addr, return);
1950 conn = _bt_get_system_gconn();
1951 retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
1953 _bt_convert_addr_type_to_string(device_address,
1954 (unsigned char *)bd_addr->addr);
1955 device_path = _bt_get_device_object_path(device_address);
1956 if (device_path == NULL) {
1957 BT_DBG("device_path NULL");
1958 ret = BLUETOOTH_ERROR_INTERNAL;
1962 retv_if(device_path == NULL, BLUETOOTH_ERROR_INTERNAL);
1964 device_proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
1965 NULL, BT_BLUEZ_NAME,
1966 device_path, BT_DEVICE_INTERFACE, NULL, NULL);
1967 g_free(device_path);
1968 retv_if(device_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
1970 func_data = g_malloc0(sizeof(bt_function_data_t));
1971 func_data->address = g_strdup(device_address);
1972 if (func_data->address == NULL) {
1973 BT_ERR("Unable to allocate memory for address");
1974 ret = BLUETOOTH_ERROR_MEMORY_ALLOCATION;
1978 func_data->req_id = req_id;
1980 g_dbus_proxy_call(device_proxy, "DisconnectLE",
1982 G_DBUS_CALL_FLAGS_NONE,
1983 BT_MAX_DBUS_TIMEOUT,
1985 (GAsyncReadyCallback)__le_connection_req_cb, func_data);
1990 g_object_unref(device_proxy);
1992 g_free(func_data->address);
1998 int _bt_connect_le_ipsp_device(const bluetooth_device_address_t *bd_addr)
2000 char device_address[BT_ADDRESS_STRING_SIZE] = { 0 };
2001 gchar *device_path = NULL;
2002 GError *error = NULL;
2003 GDBusProxy *device_proxy = NULL;
2004 GDBusProxy *adapter_proxy;
2005 GDBusConnection *conn;
2006 int ret = BLUETOOTH_ERROR_NONE;
2008 BT_CHECK_PARAMETER(bd_addr, return);
2010 _bt_convert_addr_type_to_string(device_address,
2011 (unsigned char *)bd_addr->addr);
2013 conn = _bt_get_system_gconn();
2014 retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
2016 adapter_proxy = _bt_get_adapter_proxy();
2017 retv_if(adapter_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
2019 device_path = _bt_get_device_object_path(device_address);
2020 if (device_path == NULL) {
2021 BT_DBG("device_path NULL");
2022 ret = BLUETOOTH_ERROR_INTERNAL;
2026 retv_if(device_path == NULL, BLUETOOTH_ERROR_INTERNAL);
2028 device_proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
2029 NULL, BT_BLUEZ_NAME,
2030 device_path, BT_DEVICE_INTERFACE, NULL, NULL);
2031 g_free(device_path);
2032 retv_if(device_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
2034 g_dbus_proxy_call_sync(device_proxy, "ConnectIpsp",
2036 G_DBUS_CALL_FLAGS_NONE,
2041 BT_ERR("ConnectIpsp Call Error %s[%s]", error->message, device_address);
2042 g_error_free(error);
2043 g_object_unref(device_proxy);
2044 return BLUETOOTH_ERROR_INTERNAL;
2047 g_object_unref(device_proxy);
2052 int _bt_disconnect_le_ipsp_device(const bluetooth_device_address_t *bd_addr)
2054 char device_address[BT_ADDRESS_STRING_SIZE] = { 0 };
2055 gchar *device_path = NULL;
2056 GError *error = NULL;
2057 GDBusProxy *device_proxy = NULL;
2058 GDBusProxy *adapter_proxy;
2059 GDBusConnection *conn;
2060 int ret = BLUETOOTH_ERROR_NONE;
2062 BT_CHECK_PARAMETER(bd_addr, return);
2064 _bt_convert_addr_type_to_string(device_address,
2065 (unsigned char *)bd_addr->addr);
2067 conn = _bt_get_system_gconn();
2068 retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
2070 adapter_proxy = _bt_get_adapter_proxy();
2071 retv_if(adapter_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
2073 device_path = _bt_get_device_object_path(device_address);
2074 if (device_path == NULL) {
2075 BT_DBG("device_path NULL");
2076 ret = BLUETOOTH_ERROR_INTERNAL;
2080 retv_if(device_path == NULL, BLUETOOTH_ERROR_INTERNAL);
2082 device_proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
2083 NULL, BT_BLUEZ_NAME,
2084 device_path, BT_DEVICE_INTERFACE, NULL, NULL);
2085 g_free(device_path);
2086 retv_if(device_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
2088 g_dbus_proxy_call_sync(device_proxy, "DisconnectIpsp",
2090 G_DBUS_CALL_FLAGS_NONE,
2095 BT_ERR("DisconnectIpsp Call Error %s[%s]", error->message, device_address);
2096 g_error_free(error);
2097 g_object_unref(device_proxy);
2098 return BLUETOOTH_ERROR_INTERNAL;
2101 g_object_unref(device_proxy);
2106 int _bt_connect_profile(char *address, char *uuid,
2107 void *cb, gpointer func_data)
2111 GDBusConnection *conn;
2112 GDBusProxy *adapter_proxy;
2113 GVariant *result = NULL;
2114 GError *error = NULL;
2116 conn = _bt_get_system_gconn();
2117 retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
2119 object_path = _bt_get_device_object_path(address);
2120 if (object_path == NULL) {
2121 BT_ERR("No searched device");
2123 adapter_proxy = _bt_get_adapter_proxy();
2124 retv_if(adapter_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
2126 result = g_dbus_proxy_call_sync(adapter_proxy, "CreateDevice",
2127 g_variant_new("(s)", address),
2128 G_DBUS_CALL_FLAGS_NONE,
2133 if (error != NULL) {
2134 BT_ERR("CreateDevice Fail: %s", error->message);
2135 g_error_free(error);
2138 g_variant_unref(result);
2140 object_path = _bt_get_device_object_path(address);
2142 retv_if(object_path == NULL, BLUETOOTH_ERROR_INTERNAL);
2144 proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
2145 NULL, BT_BLUEZ_NAME,
2146 object_path, BT_DEVICE_INTERFACE, NULL, NULL);
2147 g_free(object_path);
2148 retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
2150 g_dbus_proxy_call(proxy, "ConnectProfile",
2151 g_variant_new("(s)", uuid),
2152 G_DBUS_CALL_FLAGS_NONE,
2153 BT_MAX_DBUS_TIMEOUT,
2155 (GAsyncReadyCallback)cb,
2158 return BLUETOOTH_ERROR_NONE;
2161 int _bt_disconnect_profile(char *address, char *uuid,
2162 void *cb, gpointer func_data)
2166 GDBusConnection *conn;
2168 conn = _bt_get_system_gconn();
2169 retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
2171 object_path = _bt_get_device_object_path(address);
2172 retv_if(object_path == NULL, BLUETOOTH_ERROR_INTERNAL);
2174 proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
2175 NULL, BT_BLUEZ_NAME,
2176 object_path, BT_DEVICE_INTERFACE, NULL, NULL);
2177 g_free(object_path);
2178 retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
2180 g_dbus_proxy_call(proxy, "DisconnectProfile",
2181 g_variant_new("(s)", uuid),
2182 G_DBUS_CALL_FLAGS_NONE,
2183 BT_MAX_DBUS_TIMEOUT,
2185 (GAsyncReadyCallback)cb,
2188 return BLUETOOTH_ERROR_NONE;
2191 int _bt_enable_rssi(bluetooth_device_address_t *bd_addr, int link_type,
2192 int low_threshold, int in_range_threshold, int high_threshold)
2194 int ret = BLUETOOTH_ERROR_NONE;
2196 GVariant *result = NULL;
2197 GError *error = NULL;
2198 char address[BT_ADDRESS_STRING_SIZE] = { 0 };
2200 BT_CHECK_PARAMETER(bd_addr, return);
2201 BT_DBG("BD Address [%2.2X %2.2X %2.2X %2.2X %2.2X %2.2X] Link Type[%d]",
2202 bd_addr->addr[0], bd_addr->addr[1],
2203 bd_addr->addr[2], bd_addr->addr[3],
2204 bd_addr->addr[4], bd_addr->addr[5],
2206 BT_DBG("Enable RSSI: [Threshold %d %d %d]", low_threshold,
2207 in_range_threshold, high_threshold);
2209 _bt_convert_addr_type_to_string(address, bd_addr->addr);
2211 proxy = _bt_get_adapter_proxy();
2212 retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
2214 result = g_dbus_proxy_call_sync(proxy, "EnableRssi",
2215 g_variant_new("(siiii)", address, link_type, low_threshold, in_range_threshold, high_threshold),
2216 G_DBUS_CALL_FLAGS_NONE,
2220 if (error != NULL) {
2221 BT_ERR("Dbus Call Error:[%s]", error->message);
2222 g_error_free(error);
2223 ret = BLUETOOTH_ERROR_INTERNAL;
2227 g_variant_unref(result);
2232 int _bt_get_rssi_strength(bluetooth_device_address_t *bd_addr,
2235 int ret = BLUETOOTH_ERROR_NONE;
2237 GVariant *result = NULL;
2238 GError *error = NULL;
2239 char address[BT_ADDRESS_STRING_SIZE] = { 0 };
2241 BT_CHECK_PARAMETER(bd_addr, return);
2242 BT_DBG("BD Address [%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X] Link Type[%d]",
2243 bd_addr->addr[0], bd_addr->addr[1],
2244 bd_addr->addr[2], bd_addr->addr[3],
2245 bd_addr->addr[4], bd_addr->addr[5],
2248 _bt_convert_addr_type_to_string(address, bd_addr->addr);
2250 proxy = _bt_get_adapter_proxy();
2251 retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
2253 result = g_dbus_proxy_call_sync(proxy, "GetRssiStrength",
2254 g_variant_new("(si)", address, link_type),
2255 G_DBUS_CALL_FLAGS_NONE,
2260 if (error != NULL) {
2261 BT_ERR("Dbus Call Error:[%s]", error->message);
2262 g_error_free(error);
2263 ret = BLUETOOTH_ERROR_INTERNAL;
2267 g_variant_unref(result);
2272 int _bt_le_conn_update(unsigned char *device_address,
2273 float interval_min, float interval_max,
2274 guint16 latency, guint16 time_out)
2276 char address[BT_ADDRESS_STRING_SIZE] = { 0 };
2277 gchar *device_path = NULL;
2278 GError *error = NULL;
2279 GDBusProxy *device_proxy = NULL;
2280 GDBusConnection *conn;
2282 guint32 min, max, to;
2283 guint32 min_supervision_to;
2284 int ret = BLUETOOTH_ERROR_NONE;
2286 BT_CHECK_PARAMETER(device_address, return);
2288 BT_INFO("Min interval: %f, Max interval: %f, Latency: %u, Supervision timeout: %u",
2289 interval_min, interval_max, latency, time_out);
2291 if (interval_min > interval_max ||
2292 interval_min < BT_LE_CONN_INTERVAL_MIN ||
2293 interval_max > BT_LE_CONN_INTERVAL_MAX) {
2294 ret = BLUETOOTH_ERROR_INVALID_PARAM;
2298 if (time_out < BT_LE_CONN_SUPER_TO_MIN ||
2299 time_out > BT_LE_CONN_SUPER_TO_MAX) {
2300 ret = BLUETOOTH_ERROR_INVALID_PARAM;
2304 if (latency > BT_LE_CONN_SLAVE_LATENCY_MAX) {
2305 ret = BLUETOOTH_ERROR_INVALID_PARAM;
2310 * The Supervision_Timeout in milliseconds shall be larger than
2311 * (1 + Conn_Latency) * Conn_Interval_Max * 2,
2312 * where Conn_Interval_Max is given in milliseconds.
2314 min_supervision_to = (1 + latency) * interval_max * 2;
2315 if (time_out <= min_supervision_to) {
2316 ret = BLUETOOTH_ERROR_INVALID_PARAM;
2320 _bt_convert_addr_type_to_string(address, device_address);
2322 BT_DBG("Remote device address: %s", address);
2324 device_path = _bt_get_device_object_path(address);
2326 if (device_path == NULL) {
2327 BT_ERR("device_path NULL");
2328 ret = BLUETOOTH_ERROR_INTERNAL;
2332 conn = _bt_get_system_gconn();
2334 BT_ERR("conn NULL");
2335 ret = BLUETOOTH_ERROR_INTERNAL;
2339 device_proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
2340 NULL, BT_BLUEZ_NAME,
2341 device_path, BT_DEVICE_INTERFACE, NULL, NULL);
2343 g_free(device_path);
2344 retv_if(device_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
2346 min = interval_min / BT_LE_CONN_INTERVAL_SPLIT;
2347 max = interval_max / BT_LE_CONN_INTERVAL_SPLIT;
2348 to = time_out / BT_LE_CONN_TO_SPLIT;
2350 reply = g_dbus_proxy_call_sync(device_proxy, "LeConnUpdate",
2351 g_variant_new("(uuuu)", min, max, latency, to),
2352 G_DBUS_CALL_FLAGS_NONE,
2357 g_object_unref(device_proxy);
2358 if (reply == NULL) {
2360 BT_ERR("Error %s[%s]", error->message, address);
2361 if (g_strrstr(error->message, "In Progress"))
2362 ret = BLUETOOTH_ERROR_IN_PROGRESS;
2364 ret = BLUETOOTH_ERROR_INTERNAL;
2365 g_error_free(error);
2369 g_variant_unref(reply);
2375 int _bt_set_pin_code(bluetooth_device_address_t *device_address,
2376 bluetooth_device_pin_code_t *pin_code)
2378 char address[BT_ADDRESS_STRING_SIZE] = { 0 };
2380 bt_pin_code_info_t *pin_info = NULL;
2382 BT_CHECK_PARAMETER(device_address, return);
2383 BT_CHECK_PARAMETER(pin_code, return);
2384 retv_if(g_slist_length(pin_info_list) >= BT_DEVICE_PIN_CODE_SLOT_MAX,
2385 BLUETOOTH_ERROR_NO_RESOURCES);
2387 _bt_convert_addr_type_to_string(address, device_address->addr);
2389 for (l = pin_info_list; l != NULL; l = l->next) {
2392 if (g_strcmp0(pin_info->address, address) == 0) {
2393 g_free(pin_info->pin_code);
2394 pin_info->pin_code = g_strdup(pin_code->pin_code);
2395 return BLUETOOTH_ERROR_NONE;
2399 pin_info = g_malloc0(sizeof(bt_pin_code_info_t));
2400 pin_info->address = g_strdup(address);
2401 pin_info->pin_code = g_strdup(pin_code->pin_code);
2402 pin_info_list = g_slist_append(pin_info_list, pin_info);
2404 return BLUETOOTH_ERROR_NONE;
2407 gint __bt_compare_address(gpointer *a, gpointer *b)
2409 bt_pin_code_info_t *pin_info = (bt_pin_code_info_t *)a;
2410 char *address = (char *)b;
2411 return g_strcmp0(pin_info->address, address);
2414 int _bt_unset_pin_code(bluetooth_device_address_t *device_address)
2416 char address[BT_ADDRESS_STRING_SIZE] = { 0 };
2418 bt_pin_code_info_t *pin_info = NULL;
2420 BT_CHECK_PARAMETER(device_address, return);
2422 _bt_convert_addr_type_to_string(address, device_address->addr);
2424 l = g_slist_find_custom(pin_info_list, address,
2425 (GCompareFunc)__bt_compare_address);
2429 pin_info_list = g_slist_remove(pin_info_list, pin_info);
2430 g_free(pin_info->address);
2431 g_free(pin_info->pin_code);
2435 return BLUETOOTH_ERROR_NONE;
2438 int _bt_get_device_pin_code(const char *address, char *pin_code)
2442 BT_CHECK_PARAMETER(address, return);
2443 BT_CHECK_PARAMETER(pin_code, return);
2445 for (l = pin_info_list; l != NULL; l = l->next) {
2446 bt_pin_code_info_t *pin_info = l->data;
2448 if (g_strcmp0(pin_info->address, address) == 0) {
2449 g_strlcpy(pin_code, pin_info->pin_code,
2450 BLUETOOTH_PIN_CODE_MAX_LENGTH + 1);
2452 return BLUETOOTH_ERROR_NONE;
2456 return BLUETOOTH_ERROR_NOT_FOUND;
2459 int _bt_get_le_connection_parameter(bluetooth_le_connection_mode_t mode,
2460 bluetooth_le_connection_param_t *param)
2463 return BLUETOOTH_ERROR_INVALID_PARAM;
2465 if (mode < BLUETOOTH_LE_CONNECTION_MODE_BALANCED ||
2466 mode > BLUETOOTH_LE_CONNECTION_MODE_LOW_POWER)
2467 return BLUETOOTH_ERROR_INVALID_PARAM;
2469 memset(param, 0x00, sizeof(bluetooth_le_connection_param_t));
2472 case BLUETOOTH_LE_CONNECTION_MODE_BALANCED:
2473 param->interval_min = BT_LE_CONN_PARAM_BALANCED_MIN_INTERVAL;
2474 param->interval_max = BT_LE_CONN_PARAM_BALANCED_MAX_INTERVAL;
2475 param->latency = BT_LE_CONN_PARAM_BALANCED_SLAVE_LATENCY;
2476 param->timeout = BT_LE_CONN_PARAM_DEFAULT_SUPERVISION_TIMEOUT;
2479 case BLUETOOTH_LE_CONNECTION_MODE_LOW_LATENCY:
2480 param->interval_min = BT_LE_CONN_PARAM_LOW_LATENCY_MIN_INTERVAL;
2481 param->interval_max = BT_LE_CONN_PARAM_LOW_LATENCY_MAX_INTERVAL;
2482 param->latency = BT_LE_CONN_PARAM_LOW_LATENCY_SLAVE_LATENCY;
2483 param->timeout = BT_LE_CONN_PARAM_DEFAULT_SUPERVISION_TIMEOUT;
2486 case BLUETOOTH_LE_CONNECTION_MODE_LOW_POWER:
2487 param->interval_min = BT_LE_CONN_PARAM_LOW_POWER_MIN_INTERVAL;
2488 param->interval_max = BT_LE_CONN_PARAM_LOW_POWER_MAX_INTERVAL;
2489 param->latency = BT_LE_CONN_PARAM_LOW_POWER_SLAVE_LATENCY;
2490 param->timeout = BT_LE_CONN_PARAM_DEFAULT_SUPERVISION_TIMEOUT;
2494 BT_ERR("Unhandled mode : %d", mode);
2498 return BLUETOOTH_ERROR_NONE;
2501 int _bt_get_trusted_profile_from_flag(bluetooth_trusted_profile_t profile,
2502 guint trusted_profile_flag, guint *trusted)
2508 case TRUSTED_PROFILE_PBAP:
2509 if (trusted_profile_flag & (PROFILE_SUPPORTED << 0))
2510 trust_profile = trusted_profile_flag & (1 << 1);
2512 return BLUETOOTH_ERROR_NOT_SUPPORT;
2514 case TRUSTED_PROFILE_MAP:
2515 if (trusted_profile_flag & (PROFILE_SUPPORTED << 2))
2516 trust_profile = trusted_profile_flag & (1 << 3);
2518 return BLUETOOTH_ERROR_NOT_SUPPORT;
2520 case TRUSTED_PROFILE_SAP:
2521 if (trusted_profile_flag & (PROFILE_SUPPORTED << 4))
2522 trust_profile = trusted_profile_flag & (1 << 5);
2524 return BLUETOOTH_ERROR_NOT_SUPPORT;
2526 case TRUSTED_PROFILE_ALL: /* Return Flag for All profiles*/
2527 *trusted = trusted_profile_flag;
2528 return BLUETOOTH_ERROR_NONE;
2530 return BLUETOOTH_ERROR_NOT_SUPPORT;
2536 return BLUETOOTH_ERROR_NONE;
2539 char *_bt_get_trusted_profile_uuid(bluetooth_trusted_profile_t profile)
2542 case TRUSTED_PROFILE_PBAP:
2543 return g_strdup("00001130-0000-1000-8000-00805f9b34fb");
2544 case TRUSTED_PROFILE_MAP:
2545 return g_strdup("00001134-0000-1000-8000-00805f9b34fb");
2546 case TRUSTED_PROFILE_SAP:
2547 return g_strdup("0000112D-0000-1000-8000-00805f9b34fb");
2548 case TRUSTED_PROFILE_ALL:
2555 bluetooth_trusted_profile_t _bt_get_trusted_profile_enum(const char *uuid)
2557 if (g_strcmp0("0000112f-0000-1000-8000-00805f9b34fb", uuid) == 0) {
2558 return TRUSTED_PROFILE_PBAP;
2559 } else if (g_strcmp0("00001132-0000-1000-8000-00805f9b34fb", uuid) == 0) {
2560 return TRUSTED_PROFILE_MAP;
2561 } else if (g_strcmp0("0000112D-0000-1000-8000-00805f9b34fb", uuid) == 0) {
2562 return TRUSTED_PROFILE_SAP;
2564 return 0; /* 0 - Unknown Profile */
2567 int _bt_set_trust_profile(bluetooth_device_address_t *bd_addr,
2568 bluetooth_trusted_profile_t profile, gboolean trust)
2570 int ret = BLUETOOTH_ERROR_NONE;
2571 GDBusConnection *conn;
2573 GError *error = NULL;
2574 char *device_path = NULL;
2576 char address[BT_ADDRESS_STRING_SIZE] = { 0 };
2579 BT_CHECK_PARAMETER(bd_addr, return);
2580 BT_DBG("BD Address [%2.2X %2.2X %2.2X %2.2X %2.2X %2.2X] profile[%d] trust[%d]",
2581 bd_addr->addr[0], bd_addr->addr[1],
2582 bd_addr->addr[2], bd_addr->addr[3],
2583 bd_addr->addr[4], bd_addr->addr[5],
2586 conn = _bt_get_system_gconn();
2587 retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
2589 _bt_convert_addr_type_to_string(address, bd_addr->addr);
2591 device_path = _bt_get_device_object_path(address);
2592 retv_if(device_path == NULL, BLUETOOTH_ERROR_INTERNAL);
2594 proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
2595 NULL, BT_BLUEZ_NAME, device_path,
2596 BT_DEVICE_INTERFACE, NULL, NULL);
2598 g_free(device_path);
2599 retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
2601 uuid = _bt_get_trusted_profile_uuid(profile);
2603 g_object_unref(proxy);
2604 return BLUETOOTH_ERROR_NOT_SUPPORT;
2607 reply = g_dbus_proxy_call_sync(proxy, "SetTrustedProfile",
2608 g_variant_new("(sb)", uuid, trust),
2609 G_DBUS_CALL_FLAGS_NONE, -1,
2611 g_object_unref(proxy);
2613 if (reply == NULL) {
2614 BT_ERR("Failed to Set Profile Trusted");
2615 ret = BLUETOOTH_ERROR_INTERNAL;
2617 BT_ERR("Error %s[%s]", error->message, address);
2618 g_error_free(error);
2622 g_variant_unref(reply);
2629 int _bt_get_trust_profile(bluetooth_device_address_t *bd_addr,
2630 bluetooth_trusted_profile_t profile, guint *trust)
2632 int ret = BLUETOOTH_ERROR_NONE;
2633 GDBusConnection *conn;
2635 GError *error = NULL;
2636 char *device_path = NULL;
2637 guint trusted_profile_flag;
2638 char address[BT_ADDRESS_STRING_SIZE] = { 0 };
2641 BT_CHECK_PARAMETER(bd_addr, return);
2642 BT_DBG("BD Address [%2.2X %2.2X %2.2X %2.2X %2.2X %2.2X] profile[%d] trust[%d]",
2643 bd_addr->addr[0], bd_addr->addr[1],
2644 bd_addr->addr[2], bd_addr->addr[3],
2645 bd_addr->addr[4], bd_addr->addr[5],
2648 conn = _bt_get_system_gconn();
2649 retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
2651 _bt_convert_addr_type_to_string(address, bd_addr->addr);
2653 device_path = _bt_get_device_object_path(address);
2654 retv_if(device_path == NULL, BLUETOOTH_ERROR_INTERNAL);
2656 proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
2657 NULL, BT_BLUEZ_NAME, device_path,
2658 BT_PROPERTIES_INTERFACE, NULL, NULL);
2660 g_free(device_path);
2661 retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
2663 reply = g_dbus_proxy_call_sync(proxy, "Get",
2664 g_variant_new("(ss)", BT_DEVICE_INTERFACE, "TrustedProfiles"),
2665 G_DBUS_CALL_FLAGS_NONE, -1,
2667 g_object_unref(proxy);
2669 if (reply == NULL) {
2670 BT_ERR("Failed to Get Profile Trusted");
2671 ret = BLUETOOTH_ERROR_INTERNAL;
2673 BT_ERR("Error %s[%s]", error->message, address);
2674 g_error_free(error);
2679 g_variant_get(reply, "(v)", &temp);
2680 trusted_profile_flag = g_variant_get_uint32(temp);
2681 BT_DBG("TRUST_FLAG %d", trusted_profile_flag);
2683 ret = _bt_get_trusted_profile_from_flag(profile,
2684 trusted_profile_flag, trust);
2685 g_variant_unref(temp);
2686 g_variant_unref(reply);
2689 BT_DBG("TRUST %d", *trust);
2693 static void __bt_request_att_mtu_device_cb(GDBusProxy *proxy, GAsyncResult *res,
2697 GVariant *out_param1;
2698 request_info_t *req_info;
2699 GVariant *val = NULL;
2700 GVariant *param = NULL;
2703 bluetooth_device_address_t device_addr = { {0} };
2704 int result = BLUETOOTH_ERROR_NONE;
2707 val = g_dbus_proxy_call_finish(proxy, res, &err);
2709 req_info = _bt_get_request_info(att_mtu_req_info->req_id);
2710 if (req_info == NULL) {
2711 BT_ERR("req_info == NULL");
2712 g_object_unref(proxy);
2713 att_mtu_req_info->device_proxy = NULL;
2718 BT_ERR("Error occured in RequestAttMtu [%s]", err->message);
2720 if (g_strrstr(err->message, "NotSupported")) {
2721 BT_INFO("Connection Not Supported");
2722 result = BLUETOOTH_ERROR_NOT_SUPPORT;
2723 } else if (g_strrstr(err->message, "NotConnected")) {
2724 BT_INFO("Not connected");
2725 result = BLUETOOTH_ERROR_NOT_CONNECTED;
2726 } else if (g_strrstr(err->message, "InvalidArguments")) {
2727 BT_INFO("Not connected");
2728 result = BLUETOOTH_ERROR_INVALID_PARAM;
2730 BT_DBG("Default case");
2731 result = BLUETOOTH_ERROR_INTERNAL;
2735 g_object_unref(proxy);
2736 att_mtu_req_info->device_proxy = NULL;
2738 if (result != BLUETOOTH_ERROR_NONE)
2742 g_variant_get (val, "(qy)", &mtu, &status);
2743 g_variant_unref (val);
2746 BT_DBG("MTU %d, Status %d, %s", mtu, status, att_mtu_req_info->addr);
2748 param = g_variant_new("(isqy)",
2750 att_mtu_req_info->addr,
2754 /* Send the event to application */
2755 _bt_send_event(BT_DEVICE_EVENT,
2756 BLUETOOTH_EVENT_GATT_ATT_MTU_CHANGED,
2760 if (req_info->context == NULL)
2763 _bt_convert_addr_string_to_type(device_addr.addr,
2764 (const char *)att_mtu_req_info->addr);
2766 out_param1 = g_variant_new_from_data((const GVariantType *)"ay",
2767 &device_addr, sizeof(bluetooth_device_address_t), TRUE, NULL, NULL);
2768 g_dbus_method_invocation_return_value(req_info->context,
2769 g_variant_new("(iv)", result, out_param1));
2771 _bt_delete_request_list(req_info->req_id);
2776 g_free(att_mtu_req_info->addr);
2777 g_free(att_mtu_req_info);
2778 att_mtu_req_info = NULL;
2783 int _bt_request_att_mtu(int request_id, bluetooth_device_address_t *device_address,
2786 char address[BT_ADDRESS_STRING_SIZE] = { 0 };
2787 gchar *device_path = NULL;
2788 GDBusProxy *adapter_proxy;
2789 GDBusProxy *device_proxy;
2790 GDBusConnection *conn;
2791 int ret = BLUETOOTH_ERROR_NONE;
2793 BT_CHECK_PARAMETER(device_address, return);
2795 if (att_mtu_req_info) {
2796 BT_ERR("ATT MTU request in progress");
2797 return BLUETOOTH_ERROR_DEVICE_BUSY;
2800 conn = _bt_get_system_gconn();
2801 retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
2803 adapter_proxy = _bt_get_adapter_proxy();
2804 retv_if(adapter_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
2806 _bt_convert_addr_type_to_string(address, device_address->addr);
2808 BT_DBG("Remote device address: %s", address);
2810 device_path = _bt_get_device_object_path(address);
2812 retv_if(device_path == NULL, BLUETOOTH_ERROR_INTERNAL);
2814 device_proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
2815 NULL, BT_BLUEZ_NAME,
2816 device_path, BT_DEVICE_INTERFACE, NULL, NULL);
2817 g_free(device_path);
2818 retv_if(device_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
2820 if (device_path == NULL) {
2821 BT_DBG("device_path NULL");
2822 ret = BLUETOOTH_ERROR_INTERNAL;
2826 att_mtu_req_info = g_malloc0(sizeof(bt_funcion_data_t));
2827 att_mtu_req_info->addr = (char *)g_strdup(address);
2828 att_mtu_req_info->req_id = request_id;
2829 att_mtu_req_info->device_proxy = device_proxy;
2831 g_dbus_proxy_call(device_proxy, "RequestAttMtu",
2832 g_variant_new("(q)", mtu),
2833 G_DBUS_CALL_FLAGS_NONE,
2834 BT_MAX_DBUS_TIMEOUT,
2836 (GAsyncReadyCallback)__bt_request_att_mtu_device_cb,
2842 int _bt_get_att_mtu(bluetooth_device_address_t *device_address,
2845 char address[BT_ADDRESS_STRING_SIZE] = { 0 };
2846 char *object_path = NULL;
2848 GDBusProxy *device_proxy;
2849 GError *error = NULL;
2851 GVariant *tmp_value;
2852 GDBusConnection *conn;
2853 GVariant *result = NULL;
2854 int ret = BLUETOOTH_ERROR_NONE;
2856 BT_CHECK_PARAMETER(device_address, return);
2858 conn = _bt_get_system_gconn();
2859 retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
2861 _bt_convert_addr_type_to_string(address, device_address->addr);
2863 object_path = _bt_get_device_object_path(address);
2864 retv_if(object_path == NULL, BLUETOOTH_ERROR_NOT_PAIRED);
2866 device_proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
2867 NULL, BT_BLUEZ_NAME, object_path,
2868 BT_PROPERTIES_INTERFACE, NULL, NULL);
2869 g_free(object_path);
2870 retv_if(device_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
2872 result = g_dbus_proxy_call_sync(device_proxy, "GetAll",
2873 g_variant_new("(s)", BT_DEVICE_INTERFACE),
2874 G_DBUS_CALL_FLAGS_NONE,
2878 if (result == NULL) {
2879 if (error != NULL) {
2880 BT_ERR("Error occured in Proxy call [%s]\n", error->message);
2881 g_error_free(error);
2883 g_object_unref(device_proxy);
2884 return BLUETOOTH_ERROR_INTERNAL;
2887 g_variant_get(result , "(@a{sv})", &value);
2888 g_variant_unref(result);
2890 tmp_value = g_variant_lookup_value(value, "AttMtu", G_VARIANT_TYPE_UINT16);
2891 if (tmp_value == NULL) {
2892 g_object_unref(device_proxy);
2893 g_variant_unref(value);
2894 return BLUETOOTH_ERROR_INTERNAL;
2897 *mtu = g_variant_get_uint16(tmp_value);
2899 BT_DBG("ATT MTU : %d", *mtu);
2901 g_variant_unref(tmp_value);
2902 g_variant_unref(value);
2903 g_object_unref(device_proxy);
2908 int _bt_get_device_ida(bluetooth_device_address_t *device_address,
2909 bluetooth_device_address_t *id_address)
2911 char address[BT_ADDRESS_STRING_SIZE] = { 0 };
2912 gchar *device_path = NULL;
2913 const gchar *idaddress = NULL;
2914 GDBusProxy *device_proxy;
2915 GError *error = NULL;
2916 GVariant *result = NULL;
2917 GDBusConnection *conn;
2918 int ret = BLUETOOTH_ERROR_NONE;
2920 BT_CHECK_PARAMETER(device_address, return);
2922 conn = _bt_get_system_gconn();
2923 retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
2925 _bt_convert_addr_type_to_string(address, device_address->addr);
2927 device_path = _bt_get_device_object_path(address);
2928 retv_if(device_path == NULL, BLUETOOTH_ERROR_NOT_PAIRED);
2930 device_proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
2931 NULL, BT_BLUEZ_NAME,
2932 device_path, BT_DEVICE_INTERFACE, NULL, NULL);
2933 g_free(device_path);
2934 if (!device_proxy) {
2935 BT_ERR("Unable to get proxy");
2936 return BLUETOOTH_ERROR_INTERNAL;
2939 result = g_dbus_proxy_call_sync(device_proxy, "GetIDAddress",
2941 G_DBUS_CALL_FLAGS_NONE,
2946 if (result == NULL) {
2947 BT_ERR("Failed to get device ID address");
2948 if (error != NULL) {
2949 BT_ERR("Error occured in Proxy call [%s]\n", error->message);
2950 g_error_free(error);
2952 g_object_unref(device_proxy);
2953 return BLUETOOTH_ERROR_INTERNAL;
2956 g_variant_get(result , "(s)", &idaddress);
2957 g_variant_unref(result);
2959 if (idaddress == NULL) {
2960 BT_ERR("No paired device");
2961 g_object_unref(device_proxy);
2962 return BLUETOOTH_ERROR_NOT_PAIRED;
2965 BT_DBG("ID Address:%s", idaddress);
2968 _bt_convert_addr_string_to_type(id_address->addr, idaddress);
2970 ret = BLUETOOTH_ERROR_INTERNAL;
2973 g_object_unref(device_proxy);
2978 int _bt_passkey_reply(const char *passkey, gboolean authentication_reply)
2980 GapAgentPrivate *agent = _bt_get_adapter_agent();
2981 retv_if(!agent, BLUETOOTH_ERROR_INTERNAL);
2983 if (authentication_reply)
2984 gap_agent_reply_pin_code(agent, GAP_AGENT_ACCEPT, passkey, NULL);
2986 gap_agent_reply_pin_code(agent, GAP_AGENT_REJECT, passkey, NULL);
2988 BT_DBG("BT_PASSKEY_REPLY");
2989 return BLUETOOTH_ERROR_NONE;
2992 int _bt_passkey_confirmation_reply(gboolean confirmation_reply)
2994 GapAgentPrivate *agent = _bt_get_adapter_agent();
2995 retv_if(!agent, BLUETOOTH_ERROR_INTERNAL);
2997 if (confirmation_reply)
2998 gap_agent_reply_confirmation(agent, GAP_AGENT_ACCEPT, NULL);
3000 gap_agent_reply_confirmation(agent, GAP_AGENT_REJECT, NULL);
3002 BT_DBG("BT_PASSKEY_CONFIRMATION_REPLY");
3003 return BLUETOOTH_ERROR_NONE;