4 * Copyright (c) 2015 -2016 Samsung Electronics Co., Ltd All Rights Reserved.
6 * Contact: Anupam Roy <anupam.r@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
33 #include "bt-hal-log.h"
34 #include "bt-hal-msg.h"
35 #include "bt-hal-utils.h"
36 #include "bt-hal-adapter-le.h"
37 #include "bt-hal-adapter-dbus-handler.h"
38 #include "bt-hal-dbus-common-utils.h"
40 #include "bt-internal-types.h"
42 #define BT_ENABLE_TIMEOUT 20000 /* 20 seconds */
43 #define BT_CORE_NAME "org.projectx.bt_core"
44 #define BT_CORE_PATH "/org/projectx/bt_core"
45 #define BT_CORE_INTERFACE "org.projectx.btcore"
47 static GDBusProxy *core_proxy = NULL;
48 static GDBusConnection *system_conn = NULL;
49 static handle_stack_msg event_cb = NULL;
51 handle_stack_msg _bt_get_adapter_event_cb(void)
59 GDBusConnection *__bt_hal_get_system_gconn(void)
61 if (system_conn == NULL)
62 system_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, NULL);
67 GDBusProxy *_bt_init_core_proxy(void)
69 GDBusConnection *conn;
71 conn = __bt_hal_get_system_gconn();
75 proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
90 static GDBusProxy *__bt_get_core_proxy(void)
92 return (core_proxy) ? core_proxy : _bt_init_core_proxy();
95 /* To send stack event to hal-bluetooth handler */
96 void _bt_hal_dbus_store_stack_msg_cb(handle_stack_msg cb)
101 int _bt_hal_enable_core(void)
106 GError *error = NULL;
108 proxy = __bt_get_core_proxy();
110 return BT_HAL_ERROR_INTERNAL;
112 /* Clean up the process */
113 result = g_dbus_proxy_call_sync(proxy,
116 G_DBUS_CALL_FLAGS_NONE,
123 ERR("Bt core call failed(Error: %s)", error->message);
124 g_clear_error(&error);
126 ERR("Bt core call failed");
127 return BT_HAL_ERROR_INTERNAL;
130 g_variant_unref(result);
131 return BT_HAL_ERROR_NONE;
134 static gboolean __bt_hal_send_adapter_event(gpointer user_data)
136 struct hal_ev_adapter_state_changed ev;
137 gboolean *enable = (gboolean *)user_data;
140 ev.state = HAL_POWER_ON;
142 ev.state = HAL_POWER_OFF;
145 event_cb = _bt_get_adapter_event_cb();
148 event_cb(HAL_EV_ADAPTER_STATE_CHANGED, &ev, sizeof(ev));
154 static gboolean __bt_hal_send_le_event(gpointer user_data)
156 struct hal_ev_le_state_changed ev;
157 gboolean *enable = (gboolean *)user_data;
160 ev.state = HAL_POWER_ON;
162 ev.state = HAL_POWER_OFF;
165 event_cb = _bt_get_adapter_event_cb();
168 event_cb(HAL_EV_LE_STATE_CHANGED, &ev, sizeof(ev));
175 int _bt_hal_dbus_enable_adapter(void)
178 GError *error = NULL;
179 GVariant *result = NULL;
180 unsigned char powered = 0;
184 int le_value = VCONFKEY_BT_LE_STATUS_OFF;
185 if (vconf_get_int(VCONFKEY_BT_LE_STATUS, &le_value))
186 ERR("fail to get vconf key!");
188 if (_bt_hal_get_adapter_powered_state(&powered) == BT_STATUS_FAIL)
189 ERR("_bt_hal_get_adapter_powered_state failed");
191 /*if LE is enabled and bluez is UP , send event from here and return.*/
192 if ((le_value == VCONFKEY_BT_LE_STATUS_ON) && (powered == 1)) {
193 gboolean *user_data = g_new0(int, 1);
195 g_idle_add(__bt_hal_send_adapter_event, (gpointer)user_data);
196 return BT_STATUS_SUCCESS;
199 if (TIZEN_FEATURE_BT_USB_DONGLE && powered == 1) {
200 gboolean *user_data = g_new0(int, 1);
202 g_idle_add(__bt_hal_send_adapter_event, (gpointer)user_data);
203 return BT_STATUS_SUCCESS;
206 proxy = __bt_get_core_proxy();
209 ERR("_bt_hal_dbus_enable_adapter: Core proxy get failed!!!");
210 return BT_STATUS_FAIL;
213 _bt_hal_set_adapter_request_state(TRUE);
214 _bt_hal_set_le_request_state(TRUE);
215 result = g_dbus_proxy_call_sync(proxy, "EnableAdapter",
217 G_DBUS_CALL_FLAGS_NONE, BT_ENABLE_TIMEOUT,
220 ERR("EnableAdapter failed: %s", error->message);
221 g_clear_error(&error);
223 _bt_hal_set_adapter_request_state(FALSE);
224 _bt_hal_set_le_request_state(FALSE);
225 result = g_dbus_proxy_call_sync(proxy,
228 G_DBUS_CALL_FLAGS_NONE,
234 ERR("Bt core call failed(Error: %s)", error->message);
235 g_clear_error(&error);
237 g_variant_unref(result);
239 /* TODO: Terminate bluetooth service or not, need to check */
240 /*g_idle_add((GSourceFunc)_bt_terminate_service, NULL);*/
241 return BT_STATUS_FAIL;
244 g_variant_unref(result);
245 return BT_STATUS_SUCCESS;
248 int _bt_hal_dbus_disable_adapter(void)
251 GError *error = NULL;
252 GVariant *result = NULL;
255 proxy = __bt_get_core_proxy();
257 ERR("_bt_hal_dbus_enable_adapter: Core proxy get failed!!!");
258 return BT_STATUS_FAIL;
261 result = g_dbus_proxy_call_sync(proxy, "DisableAdapter",
263 G_DBUS_CALL_FLAGS_NONE, -1,
266 ERR("DisableAdapter failed: %s", error->message);
267 g_clear_error(&error);
269 g_variant_unref(result);
271 /* TODO: Terminate bluetooth service or not, need to check */
272 /*g_idle_add((GSourceFunc)_bt_terminate_service, NULL);*/
273 return BT_STATUS_FAIL;
276 g_variant_unref(result);
277 return BT_STATUS_SUCCESS;
280 int _bt_hal_dbus_recover_adapter(void)
283 GVariant *result = NULL;
284 GError *error = NULL;
287 proxy = __bt_get_core_proxy();
289 ERR("_bt_hal_dbus_recover_adapter: Core proxy get failed!!!");
290 return BT_STATUS_FAIL;
293 result = g_dbus_proxy_call_sync(proxy, "RecoverAdapter",
295 G_DBUS_CALL_FLAGS_NONE, -1,
298 ERR("RecoverAdapter failed: %s", error->message);
299 g_clear_error(&error);
301 return BT_STATUS_FAIL;
304 g_variant_unref(result);
305 return BT_STATUS_SUCCESS;
309 int _bt_hal_dbus_enable_le(void)
312 GError *error = NULL;
313 GVariant *result = NULL;
314 int adapter_value = VCONFKEY_BT_STATUS_OFF;
315 unsigned char powered = 0;
319 if (vconf_get_int(VCONFKEY_BT_STATUS, &adapter_value) != 0)
320 ERR("fail to get vconf key!");
322 if (_bt_hal_get_adapter_powered_state(&powered) == BT_STATUS_FAIL)
323 ERR("_bt_hal_get_adapter_powered_state failed");
325 if ((adapter_value == VCONFKEY_BT_STATUS_ON) && (powered == 1)) {
326 gboolean *user_data = g_new0(int, 1);
328 g_idle_add(__bt_hal_send_le_event, (gpointer)user_data);
329 return BT_STATUS_SUCCESS;
332 proxy = __bt_get_core_proxy();
335 DBG("_bt_hal_dbus_enable_le: Core proxy get failed!!!");
336 return BT_STATUS_FAIL;
338 _bt_hal_set_le_request_state(TRUE);
340 result = g_dbus_proxy_call_sync(proxy, "EnableAdapterLe",
342 G_DBUS_CALL_FLAGS_NONE, BT_ENABLE_TIMEOUT,
345 DBG("EnableAdapterLe failed: %s", error->message);
346 g_clear_error(&error);
348 result = g_dbus_proxy_call_sync(proxy,
351 G_DBUS_CALL_FLAGS_NONE,
356 _bt_hal_set_le_request_state(FALSE);
358 DBG("Bt core call failed(Error: %s)", error->message);
359 g_clear_error(&error);
361 g_variant_unref(result);
363 return BT_STATUS_FAIL;
367 g_variant_unref(result);
368 return BT_STATUS_SUCCESS;
371 int _bt_hal_dbus_disable_le(void)
374 GError *error = NULL;
375 GVariant *result = NULL;
376 int adapter_value = VCONFKEY_BT_STATUS_OFF;
379 if (vconf_get_int(VCONFKEY_BT_STATUS, &adapter_value) != 0)
380 ERR("fail to get vconf key!");
382 if (adapter_value == VCONFKEY_BT_STATUS_ON) {
383 gboolean *user_data = g_new0(int, 1);
385 g_idle_add(__bt_hal_send_le_event, (gpointer)user_data);
386 return BT_STATUS_SUCCESS;
389 proxy = __bt_get_core_proxy();
392 DBG("_bt_hal_dbus_disable_le: Core proxy get failed!!!");
393 return BT_STATUS_FAIL;
396 result = g_dbus_proxy_call_sync(proxy, "DisableAdapterLe",
398 G_DBUS_CALL_FLAGS_NONE, -1,
401 DBG("DisableAdapter failed: %s", error->message);
402 g_clear_error(&error);
404 g_variant_unref(result);
405 return BT_STATUS_FAIL;
411 g_variant_unref(result);
412 return BT_STATUS_SUCCESS;
417 int _bt_hal_dbus_reset_adapter(void)
421 GError *error = NULL;
424 proxy = __bt_get_core_proxy();
426 return BT_STATUS_FAIL;
428 result = g_dbus_proxy_call_sync(proxy,
431 G_DBUS_CALL_FLAGS_NONE,
438 ERR("Failed to ResetAdapter (Error: %s)", error->message);
439 g_clear_error(&error);
441 ERR("Failed to ResetAdapter");
442 return BT_STATUS_FAIL;
445 g_variant_unref(result);
446 return BT_STATUS_SUCCESS;
450 int _bt_hal_dbus_start_discovery(gboolean is_custom,
451 bt_disc_role_type_t role)
454 GError *error = NULL;
456 const gchar *disc_type;
457 DBG("Discovery Type: Is Custom : [%s]", is_custom ? "TRUE" : "FALSE");
459 proxy = _bt_hal_get_adapter_proxy();
461 DBG("Adapter proxy get failed!!!");
462 return BT_STATUS_FAIL;
466 if (role == BT_DISC_ROLE_BREDR)
468 else if (role == BT_DISC_ROLE_LE)
470 else if (role == BT_DISC_ROLE_DUAL)
471 disc_type = "LE_BREDR";
473 return BT_STATUS_PARM_INVALID;
475 result = g_dbus_proxy_call_sync(proxy,
476 "StartCustomDiscovery",
477 g_variant_new("s", disc_type),
478 G_DBUS_CALL_FLAGS_NONE,
483 result = g_dbus_proxy_call_sync(proxy,
486 G_DBUS_CALL_FLAGS_NONE,
493 ERR("StartDiscovery failed (Error: %s)", error->message);
494 g_clear_error(&error);
496 ERR("StartDiscovery failed");
497 return BT_STATUS_FAIL;
500 /* discovery status will be change in event */
502 g_variant_unref(result);
503 return BT_STATUS_SUCCESS;
506 int _bt_hal_dbus_stop_discovery(void)
509 GError *error = NULL;
513 proxy = _bt_hal_get_adapter_proxy();
515 DBG("_bt_hal_dbus_stop_discovery: Adapter proxy get failed!!!");
516 return BT_STATUS_FAIL;
519 result = g_dbus_proxy_call_sync(proxy,
522 G_DBUS_CALL_FLAGS_NONE,
529 ERR("StopDiscovery failed (Error: %s)", error->message);
530 g_clear_error(&error);
532 ERR("StopDiscovery failed");
533 return BT_STATUS_FAIL;
536 /* discovery status will be change in event */
538 g_variant_unref(result);
539 return BT_STATUS_SUCCESS;
542 int _bt_hal_dbus_get_energy_info(uint32_t *tx_time, uint32_t *rx_time,
543 uint32_t *idle_time, uint32_t *energy_used)
546 GError *error = NULL;
551 if (!tx_time || !rx_time || !idle_time || !energy_used) {
552 ERR("Invalid parameter");
553 return BT_STATUS_FAIL;
556 proxy = _bt_hal_get_adapter_proxy();
558 DBG("_bt_hal_dbus_get_energy_info: Adapter proxy get failed!!!");
559 return BT_STATUS_FAIL;
562 result = g_dbus_proxy_call_sync(proxy,
565 G_DBUS_CALL_FLAGS_NONE,
572 ERR("GetEnergyInfo failed (Error: %s)", error->message);
573 g_clear_error(&error);
575 ERR("GetEnergyInfo failed");
577 return BT_STATUS_FAIL;
580 g_variant_get(result, "(uuuu)", tx_time, rx_time, idle_time, energy_used);
582 DBG("Tx time: %d", *tx_time);
583 DBG("Rx time: %d", *rx_time);
584 DBG("Idle time: %d", *idle_time);
587 g_variant_unref(result);
588 return BT_STATUS_SUCCESS;
591 static gboolean __bt_adapter_all_properties_cb(gpointer user_data)
593 GVariant *result = user_data;
594 GVariantIter *property_iter;
598 /* Buffer and propety count management */
599 uint8_t buf[BT_HAL_MAX_PROPERTY_BUF_SIZE];
600 struct hal_ev_adapter_props_changed *ev = (void*) buf;
602 gchar *address = NULL;
604 unsigned int cod = 0;
605 gboolean discoverable;
606 gboolean connectable;
607 unsigned int scan_mode = BT_SCAN_MODE_NONE;
608 unsigned int disc_timeout;
610 gboolean is_discovering;
611 gboolean is_le_discovering;
612 uint8_t ipsp_initialized;
615 unsigned int pairable_timeout;
616 gboolean scan_mode_property_update = FALSE;
620 memset(buf, 0, sizeof(buf));
623 ev->status = BT_STATUS_SUCCESS;
625 DBG("@@Start parsing properties");
626 g_variant_get(result, "(a{sv})", &property_iter);
627 while (g_variant_iter_loop(property_iter, "{sv}", &key, &value)) {
628 if (!g_strcmp0(key, "Address")) {
631 address = (gchar *) g_variant_get_string(value, NULL);
632 DBG("Address [%s]", address);
633 _bt_hal_convert_addr_string_to_type(bdaddr, address);
634 size += __bt_insert_hal_properties(buf + size,
635 HAL_PROP_ADAPTER_ADDR, sizeof(bdaddr), bdaddr);
637 } else if (!g_strcmp0(key, "Alias")) {
638 name = (gchar *) g_variant_get_string(value, NULL);
639 DBG("Alias [%s]", name);
640 size += __bt_insert_hal_properties(buf + size,
641 HAL_PROP_ADAPTER_NAME, strlen(name) + 1, name);
643 } else if (!g_strcmp0(key, "Class")) {
644 cod = g_variant_get_uint32(value);
645 DBG("Class [%d]", cod);
646 size += __bt_insert_hal_properties(buf + size,
647 HAL_PROP_ADAPTER_CLASS, sizeof(unsigned int), &cod);
649 } else if (!g_strcmp0(key, "Discoverable")) {
650 discoverable = g_variant_get_boolean(value);
651 DBG("Discoverable [%d]", discoverable);
653 scan_mode = BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE;
654 scan_mode_property_update = TRUE;
655 } else if (!g_strcmp0(key, "DiscoverableTimeout")) {
656 disc_timeout = g_variant_get_uint32(value);
657 DBG("Discoverable Timeout [%d]", disc_timeout);
658 size += __bt_insert_hal_properties(buf + size,
659 HAL_PROP_ADAPTER_DISC_TIMEOUT, sizeof(unsigned int), &disc_timeout);
661 } else if (!g_strcmp0(key, "Connectable")) {
662 connectable = g_variant_get_boolean(value);
663 DBG("Connectable [%d]", connectable);
664 if (scan_mode == BT_SCAN_MODE_NONE)
665 scan_mode = BT_SCAN_MODE_CONNECTABLE;
666 scan_mode_property_update = TRUE;
667 } else if (!g_strcmp0(key, "Version")) {
668 version = (gchar *) g_variant_get_string(value, NULL);
669 DBG("Version [%s]", version);
670 size += __bt_insert_hal_properties(buf + size,
671 HAL_PROP_ADAPTER_VERSION, strlen(version) + 1, version);
673 } else if (!g_strcmp0(key, "Name")) {
674 name = (gchar *) g_variant_get_string(value, NULL);
675 DBG("Name [%s]", name);
676 size += __bt_insert_hal_properties(buf + size,
677 HAL_PROP_ADAPTER_NAME, strlen(name) + 1, name);
679 } else if (!g_strcmp0(key, "Powered")) {
680 powered = g_variant_get_boolean(value);
681 DBG("Powered = [%d]", powered);
682 } else if (!g_strcmp0(key, "Pairable")) {
683 pairable = (g_variant_get_boolean(value) ? 1 : 0);
684 DBG("Pairable [%d]", pairable);
685 size += __bt_insert_hal_properties(buf + size,
686 HAL_PROP_ADAPTER_PAIRABLE, sizeof(uint8_t), &pairable);
688 } else if (!g_strcmp0(key, "PairableTimeout")) {
689 pairable_timeout = g_variant_get_uint32(value);
690 DBG("Pairable Timeout = [%d]", pairable_timeout);
691 size += __bt_insert_hal_properties(buf + size,
692 HAL_PROP_ADAPTER_PAIRABLE_TIMEOUT, sizeof(unsigned int), &pairable_timeout);
694 } else if (!g_strcmp0(key, "UUIDs")) {
699 size1 = g_variant_get_size(value);
700 int num_props_tmp = ev->num_props;
702 uuid_value = (char **)g_variant_get_strv(value, &size1);
703 for (i = 0; uuid_value[i] != NULL; i++)
705 /* UUID collection */
706 uint8_t uuids[HAL_UUID_LEN * uuid_count];
707 for (i = 0; uuid_value[i] != NULL; i++) {
708 char *uuid_str = NULL;
709 uint8_t uuid[HAL_UUID_LEN];
710 uuid_str = g_strdup(uuid_value[i]);
711 DBG("UUID string [%s]\n", uuid_str);
712 _bt_hal_convert_uuid_string_to_type(uuid, uuid_str);
713 memcpy(uuids + i * HAL_UUID_LEN, uuid, HAL_UUID_LEN);
716 size += __bt_insert_hal_properties(buf + size, HAL_PROP_ADAPTER_UUIDS,
717 (HAL_UUID_LEN * uuid_count),
719 ev->num_props = num_props_tmp + 1;
722 } else if (!g_strcmp0(key, "Discovering")) {
723 is_discovering = g_variant_get_boolean(value);
724 DBG("Discovering = [%d]", is_discovering);
725 } else if (!g_strcmp0(key, "LEDiscovering")) {
726 is_le_discovering = g_variant_get_boolean(value);
727 DBG("LE Discovering = [%d]", is_le_discovering);
728 } else if (!g_strcmp0(key, "Modalias")) {
729 char *modalias = NULL;
730 g_variant_get(value, "s", &modalias);
731 DBG("Adapter ModAlias [%s]", modalias);
732 size += __bt_insert_hal_properties(buf + size,
733 HAL_PROP_ADAPTER_MODALIAS, strlen(modalias) + 1, modalias);
736 } else if (!g_strcmp0(key, "SupportedLEFeatures")) {
737 DBG("LE Supported features");
740 GVariantIter *iter = NULL;
741 bt_local_le_features_t le_features;
742 gboolean le_features_present = FALSE;
744 memset(&le_features, 0x00, sizeof(le_features));
746 g_variant_get(value, "as", &iter);
748 while (g_variant_iter_loop(iter, "s", &name)) {
749 DBG("name = %s", name);
750 g_variant_iter_loop(iter, "s", &val);
751 DBG("Value = %s", val);
752 _bt_hal_update_le_feature_support(name, val, &le_features);
753 le_features_present = TRUE;
755 g_variant_iter_free(iter);
757 if (le_features_present) {
758 size += __bt_insert_hal_properties(buf + size,
759 HAL_PROP_ADAPTER_LOCAL_LE_FEAT, sizeof(le_features), &le_features);
762 DBG("le supported features values are NOT provided by Stack");
765 } else if (!g_strcmp0(key, "IpspInitStateChanged")) {
766 ipsp_initialized = (g_variant_get_boolean(value) ? 1 : 0);
767 DBG("IPSP Initialized = %d", ipsp_initialized);
768 size += __bt_insert_hal_properties(buf + size,
769 HAL_PROP_ADAPTER_IPSP_INITIALIZED, sizeof(uint8_t), &ipsp_initialized);
772 ERR("Unhandled Property:[%s]", key);
776 if (scan_mode_property_update) {
777 size += __bt_insert_hal_properties(buf + size,
778 HAL_PROP_ADAPTER_SCAN_MODE, sizeof(int), &scan_mode);
783 event_cb = _bt_get_adapter_event_cb();
785 ERR("event_cb is NULL");
790 DBG("Send Adapter properties changed event to HAL user,"
791 " Num Prop [%d] total size [%zd]", ev->num_props, size);
792 event_cb(HAL_EV_ADAPTER_PROPS_CHANGED, (void*) buf, size);
795 g_variant_unref(result);
796 g_variant_iter_free(property_iter);
800 static int __bt_hal_dbus_get_all_adapter_properties(void)
804 GError *error = NULL;
808 proxy = _bt_hal_get_adapter_properties_proxy();
810 DBG("Adapter Properties proxy get failed!!!");
811 return BT_STATUS_FAIL;
814 result = g_dbus_proxy_call_sync(proxy,
816 g_variant_new("(s)", BT_HAL_ADAPTER_INTERFACE),
817 G_DBUS_CALL_FLAGS_NONE,
824 ERR("Failed to get all adapter properties (Error: %s)", error->message);
825 g_clear_error(&error);
827 ERR("Failed to get all adapter properties");
828 return BT_STATUS_FAIL;
831 DBG("Got All properties from Bluez Stack!!, time to start parsing");
833 * As we need to provide async callback to user from HAL, simply schedule a
834 * callback method which will carry actual result
836 g_idle_add(__bt_adapter_all_properties_cb, (gpointer)result);
839 return BT_STATUS_SUCCESS;
842 int _bt_hal_dbus_get_adapter_properties(void)
846 return __bt_hal_dbus_get_all_adapter_properties();
849 int _bt_hal_get_adapter_powered_state(uint8_t *state)
851 char *adapter_path = NULL;
852 gboolean powered = FALSE;
853 int ret = BT_STATUS_FAIL;
855 /* Check Valid Adapter Path, followed by Adapter Powered state.
856 If any of these fails, adapter will be considered Disabled */
857 adapter_path = _bt_hal_get_adapter_path();
859 if (adapter_path == NULL) {
860 INFO("adapter_path is NULL");
861 g_free(adapter_path);
866 /* Check Adapter Powered Status */
867 ret = _bt_hal_is_adapter_powered(&powered);
868 if (BT_STATUS_FAIL == ret) {
869 INFO("Adapter is not powered");
870 g_free(adapter_path);
875 g_free(adapter_path);
885 /* Get Discoverable timeout API and callback */
886 static gboolean __bt_adapter_discovery_timeout_cb(gpointer user_data)
888 /* Buffer and propety count management */
889 uint8_t buf[BT_HAL_MAX_PROPERTY_BUF_SIZE];
890 struct hal_ev_adapter_props_changed *ev = (void*) buf;;
892 unsigned int *timeout = user_data;
894 memset(buf, 0, sizeof(buf));
897 ev->status = BT_STATUS_SUCCESS;
899 DBG("Discovery timeout in callback: [%d]", *timeout);
901 size += __bt_insert_hal_properties(buf + size, HAL_PROP_ADAPTER_DISC_TIMEOUT,
902 sizeof(unsigned int), timeout);
905 DBG("Timeout value [%d] property Num [%d]", *timeout, ev->num_props);
908 event_cb = _bt_get_adapter_event_cb();
910 ERR("event_cb is NULL");
915 DBG("Send Adapter Properties changed event to HAL user,"
916 " Num Prop [%d] total size [%zd]", ev->num_props, size);
917 event_cb(HAL_EV_ADAPTER_PROPS_CHANGED, (void*) buf, size);
924 int _bt_hal_dbus_get_discovery_timeout(void)
929 GError *error = NULL;
930 unsigned int *timeout;
933 proxy = _bt_hal_get_adapter_properties_proxy();
935 DBG("Adapter Properties proxy get failed!!!");
936 return BT_STATUS_FAIL;
939 result = g_dbus_proxy_call_sync(proxy,
941 g_variant_new("(ss)", BT_HAL_ADAPTER_INTERFACE,
942 "DiscoverableTimeout"),
943 G_DBUS_CALL_FLAGS_NONE,
950 ERR("Failed to get local version (Error: %s)", error->message);
951 g_clear_error(&error);
953 ERR("Failed to get local version");
954 return BT_STATUS_FAIL;
957 timeout = g_malloc0(sizeof(int));
959 ERR("Memory allocation failed");
960 g_variant_unref(result);
961 return BT_STATUS_FAIL;
964 g_variant_get(result, "(v)", &temp);
965 *timeout = g_variant_get_uint32(temp);
966 DBG("Timeout value: [%d]", *timeout);
968 g_variant_unref(result);
969 g_variant_unref(temp);
972 * As we need to provide async callback to user from HAL, simply schedule a
973 * callback method which will carry actual result
975 g_idle_add(__bt_adapter_discovery_timeout_cb, (gpointer) timeout);
978 return BT_STATUS_SUCCESS;
981 int _bt_hal_dbus_get_adapter_class(unsigned int *adapter_class)
986 GError *error = NULL;
989 proxy = _bt_hal_get_adapter_properties_proxy();
991 DBG("Adapter Properties proxy get failed!!!");
992 return BT_STATUS_FAIL;
995 result = g_dbus_proxy_call_sync(proxy,
997 g_variant_new("(ss)", BT_HAL_ADAPTER_INTERFACE,
999 G_DBUS_CALL_FLAGS_NONE,
1005 if (error != NULL) {
1006 ERR("Failed to get class (Error: %s)", error->message);
1007 g_clear_error(&error);
1009 ERR("Failed to get class");
1010 return BT_STATUS_FAIL;
1014 g_variant_get(result, "(v)", &temp);
1015 *adapter_class = g_variant_get_uint32(temp);
1016 DBG("Class value: [0x%06x]", *adapter_class);
1018 g_variant_unref(result);
1019 g_variant_unref(temp);
1022 return BT_STATUS_SUCCESS;
1025 /* Get Discoverable Mode API and callback */
1026 static gboolean __bt_adapter_scan_mode_cb(gpointer user_data)
1028 /* Buffer and propety count management */
1029 uint8_t buf[BT_HAL_MAX_PROPERTY_BUF_SIZE];
1030 struct hal_ev_adapter_props_changed *ev = (void*) buf;;
1032 int *mode = user_data;
1034 memset(buf, 0, sizeof(buf));
1037 ev->status = BT_STATUS_SUCCESS;
1039 DBG("Scan mode callback: [%d]", *mode);
1041 size += __bt_insert_hal_properties(buf + size, HAL_PROP_ADAPTER_SCAN_MODE,
1045 DBG("Scan mode [%d] property Num [%d]", *mode, ev->num_props);
1048 event_cb = _bt_get_adapter_event_cb();
1050 ERR("event_cb is NULL");
1055 DBG("Send Adapter Properties changed event to HAL user,"
1056 " Num Prop [%d] total size [%zd]", ev->num_props, size);
1057 event_cb(HAL_EV_ADAPTER_PROPS_CHANGED, (void*) buf, size);
1064 int _bt_hal_dbus_get_scan_mode(void)
1067 gboolean discoverable;
1068 gboolean connectable;
1071 GError *error = NULL;
1076 proxy = _bt_hal_get_adapter_properties_proxy();
1078 DBG("Adapter Properties proxy get failed!!!");
1079 return BT_STATUS_FAIL;
1082 result = g_dbus_proxy_call_sync(proxy,
1084 g_variant_new("(ss)", BT_HAL_ADAPTER_INTERFACE,
1086 G_DBUS_CALL_FLAGS_NONE,
1092 if (error != NULL) {
1093 ERR("Failed to get discoverable mode (Error: %s)", error->message);
1094 g_clear_error(&error);
1096 ERR("Failed to get discoverable mode");
1097 return BT_STATUS_FAIL;
1100 g_variant_get(result, "(v)", &temp);
1101 discoverable = g_variant_get_boolean(temp);
1102 DBG("discoverable:%d", discoverable);
1104 g_variant_unref(result);
1105 g_variant_unref(temp);
1107 if (!discoverable) {
1108 result = g_dbus_proxy_call_sync(proxy,
1110 g_variant_new("(ss)", BT_HAL_ADAPTER_INTERFACE,
1112 G_DBUS_CALL_FLAGS_NONE,
1117 if (error != NULL) {
1118 ERR("Failed to get connectable mode (Error: %s)", error->message);
1119 g_clear_error(&error);
1121 ERR("Failed to get connectable mode");
1122 return BT_STATUS_FAIL;
1125 g_variant_get(result, "(v)", &temp);
1126 connectable = g_variant_get_boolean(temp);
1127 DBG("connectable:%d", connectable);
1129 g_variant_unref(result);
1130 g_variant_unref(temp);
1133 scan_mode = g_malloc0(sizeof(int));
1135 ERR("Memory allocation failed");
1136 return BT_STATUS_FAIL;
1140 *scan_mode = BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE;
1141 else if (connectable)
1142 *scan_mode = BT_SCAN_MODE_CONNECTABLE;
1144 *scan_mode = BT_SCAN_MODE_NONE;
1147 * As we need to provide async callback to user from HAL, simply schedule a
1148 * callback method which will carry actual result
1150 g_idle_add(__bt_adapter_scan_mode_cb, (gpointer) scan_mode);
1153 return BT_STATUS_SUCCESS;
1156 /* Get Local Version API and callback */
1157 static gboolean __bt_adapter_local_version_cb(gpointer user_data)
1159 /* Buffer and propety count management */
1160 uint8_t buf[BT_HAL_MAX_PROPERTY_BUF_SIZE];
1161 struct hal_ev_adapter_props_changed *ev = (void*) buf;;
1163 char *version = NULL;
1165 memset(buf, 0, sizeof(buf));
1168 ev->status = BT_STATUS_SUCCESS;
1170 version = (char*) user_data;
1171 DBG("Local Version in callback: [%s]", version);
1173 size += __bt_insert_hal_properties(buf + size, HAL_PROP_ADAPTER_VERSION,
1174 (strlen(version) + 1), version);
1177 DBG("Device version [%s] property Num [%d]", version, ev->num_props);
1180 event_cb = _bt_get_adapter_event_cb();
1182 ERR("event_cb is NULL");
1187 DBG("Send Adapter Properties changed event to HAL user,"
1188 " Num Prop [%d] total size [%zd]", ev->num_props, size);
1189 event_cb(HAL_EV_ADAPTER_PROPS_CHANGED, (void*) buf, size);
1196 int _bt_hal_dbus_get_local_version(void)
1199 const char *version = NULL;
1202 GError *error = NULL;
1205 proxy = _bt_hal_get_adapter_properties_proxy();
1207 DBG("Adapter Properties proxy get failed!!!");
1208 return BT_STATUS_FAIL;
1211 result = g_dbus_proxy_call_sync(proxy,
1213 g_variant_new("(ss)", BT_HAL_ADAPTER_INTERFACE,
1215 G_DBUS_CALL_FLAGS_NONE,
1221 if (error != NULL) {
1222 ERR("Failed to get local version (Error: %s)", error->message);
1223 g_clear_error(&error);
1225 ERR("Failed to get local version");
1226 return BT_STATUS_FAIL;
1229 g_variant_get(result, "(v)", &temp);
1230 version = g_variant_dup_string(temp, NULL);
1231 DBG("Local Version: [%s]", version);
1233 g_variant_unref(result);
1234 g_variant_unref(temp);
1237 * As we need to provide async callback to user from HAL, simply schedule a
1238 * callback method which will carry actual result
1240 g_idle_add(__bt_adapter_local_version_cb, (gpointer) version);
1243 return BT_STATUS_SUCCESS;
1246 /* Get Local Name API and callback */
1247 static gboolean __bt_adapter_local_name_cb(gpointer user_data)
1249 /* Buffer and propety count management */
1250 uint8_t buf[BT_HAL_MAX_PROPERTY_BUF_SIZE];
1251 struct hal_ev_adapter_props_changed *ev = (void*) buf;;
1255 memset(buf, 0, sizeof(buf));
1258 ev->status = BT_STATUS_SUCCESS;
1260 name = (char*) user_data;
1261 DBG("Local Name in callback: [%s]", name);
1263 size += __bt_insert_hal_properties(buf + size, HAL_PROP_ADAPTER_NAME,
1264 strlen(name) + 1, name);
1267 DBG("Device name [%s] property Num [%d]", name, ev->num_props);
1270 event_cb = _bt_get_adapter_event_cb();
1272 ERR("event_cb is NULL");
1277 DBG("Send Adapter Properties changed event to HAL user,"
1278 " Num Prop [%d] total size [%zd]", ev->num_props, size);
1279 event_cb(HAL_EV_ADAPTER_PROPS_CHANGED, (void*) buf, size);
1286 int _bt_hal_dbus_get_local_name(void)
1289 const char *name = NULL;
1292 GError *error = NULL;
1294 proxy = _bt_hal_get_adapter_properties_proxy();
1296 DBG("Adapter Properties proxy get failed!!!");
1297 return BT_STATUS_FAIL;
1300 result = g_dbus_proxy_call_sync(proxy,
1302 g_variant_new("(ss)", BT_HAL_ADAPTER_INTERFACE,
1304 G_DBUS_CALL_FLAGS_NONE,
1310 if (error != NULL) {
1311 ERR("Failed to get local name (Error: %s)", error->message);
1312 g_clear_error(&error);
1314 ERR("Failed to get local name");
1315 return BT_STATUS_FAIL;
1318 g_variant_get(result, "(v)", &temp);
1319 name = g_variant_dup_string(temp, NULL);
1320 DBG("Local Name: [%s]", name);
1322 g_variant_unref(result);
1323 g_variant_unref(temp);
1326 * As we need to provide async callback to user from HAL, simply schedule a
1327 * callback method which will carry actual result
1329 g_idle_add(__bt_adapter_local_name_cb, (gpointer) name);
1331 return BT_STATUS_SUCCESS;
1334 /* Get Local Address API and callback */
1335 static gboolean __bt_adapter_local_address_cb(gpointer user_data)
1337 /* Buffer and propety count management */
1338 uint8_t buf[BT_HAL_MAX_PROPERTY_BUF_SIZE];
1339 struct hal_ev_adapter_props_changed *ev = (void*) buf;
1341 char * address = NULL;
1343 memset(buf, 0, sizeof(buf));
1346 ev->status = BT_STATUS_SUCCESS;
1348 address = (char*) user_data;
1351 _bt_hal_convert_addr_string_to_type(bdaddr, address);
1353 size += __bt_insert_hal_properties(buf + size, HAL_PROP_DEVICE_ADDR,
1354 sizeof(bdaddr), bdaddr);
1357 DBG("Device address [%s] property Num [%d]", address, ev->num_props);
1359 size += __bt_insert_hal_properties(buf + size, HAL_PROP_ADAPTER_ADDR,
1360 sizeof(bdaddr), bdaddr);
1363 event_cb = _bt_get_adapter_event_cb();
1365 ERR("event_cb is NULL");
1370 DBG("Send Device found event to HAL user,"
1371 " Num Prop [%d] total size [%zd]", ev->num_props, size);
1372 event_cb(HAL_EV_ADAPTER_PROPS_CHANGED, (void*) buf, size);
1379 int _bt_hal_dbus_get_local_address(void)
1382 GError *error = NULL;
1383 const char *address;
1387 proxy = _bt_hal_get_adapter_properties_proxy();
1389 DBG("_bt_hal_dbus_get_local_address: Adapter Properties proxy get failed!!!");
1390 return BT_STATUS_FAIL;
1393 result = g_dbus_proxy_call_sync(proxy,
1395 g_variant_new("(ss)", BT_HAL_ADAPTER_INTERFACE,
1397 G_DBUS_CALL_FLAGS_NONE,
1403 ERR("Failed to get local address");
1404 if (error != NULL) {
1405 ERR("Failed to get local address (Error: %s)", error->message);
1406 g_clear_error(&error);
1408 return BT_STATUS_FAIL;
1411 g_variant_get(result, "(v)", &temp);
1412 address = g_variant_dup_string(temp, NULL);
1415 DBG("Address:%s", address);
1417 return BT_STATUS_FAIL;
1419 g_variant_unref(result);
1420 g_variant_unref(temp);
1423 * As we need to provide async callback to user from HAL, simply schedule a
1424 * callback method which will carry actual result
1426 g_idle_add(__bt_adapter_local_address_cb, (gpointer) address);
1428 return BT_STATUS_SUCCESS;
1431 /* Get Local services API and callback */
1432 static gboolean __bt_adapter_service_uuids_cb(gpointer user_data)
1434 GVariant *result = user_data;
1436 GVariantIter *iter = NULL;
1439 /* Buffer and propety count management */
1440 uint8_t buf[BT_HAL_MAX_PROPERTY_BUF_SIZE];
1441 struct hal_ev_adapter_props_changed *ev = (void*) buf;
1444 /* UUID collection */
1445 uint8_t uuids[HAL_UUID_LEN * MAX_UUID_COUNT];
1448 memset(buf, 0, sizeof(buf));
1451 ev->status = BT_STATUS_SUCCESS;
1453 g_variant_get(result, "(v)", &temp);
1454 g_variant_get(temp, "as", &iter);
1456 ERR("Failed to get UUIDs");
1460 while (g_variant_iter_loop(iter, "s", &uuid_str)) {
1461 uint8_t uuid[HAL_UUID_LEN];
1463 DBG("UUID string [%s]\n", uuid_str);
1464 _bt_hal_convert_uuid_string_to_type(uuid, uuid_str);
1465 memcpy(uuids + uuid_count * HAL_UUID_LEN, uuid, HAL_UUID_LEN);
1469 size += __bt_insert_hal_properties(buf + size,
1470 HAL_PROP_ADAPTER_UUIDS,
1471 (HAL_UUID_LEN * uuid_count),
1476 event_cb = _bt_get_adapter_event_cb();
1478 ERR("event_cb is NULL");
1483 DBG("Send Adapter properties changed event to HAL user,"
1484 " Num Prop [%d] total size [%zd]", ev->num_props, size);
1485 event_cb(HAL_EV_ADAPTER_PROPS_CHANGED, (void*) buf, size);
1488 g_variant_iter_free(iter);
1489 g_variant_unref(result);
1490 g_variant_unref(temp);
1494 event_cb = _bt_get_adapter_event_cb();
1496 ev->status = BT_STATUS_FAIL;
1498 DBG("Send Adapter properties changed event to HAL user,"
1499 " Num Prop [%d] total size [%zd]", ev->num_props, size);
1500 event_cb(HAL_EV_ADAPTER_PROPS_CHANGED, (void*) buf, size);
1503 g_variant_unref(result);
1507 int _bt_hal_dbus_get_adapter_supported_uuids(void)
1510 GError *error = NULL;
1513 proxy = _bt_hal_get_adapter_properties_proxy();
1515 DBG("Adapter Properties proxy get failed!!!");
1516 return BT_STATUS_FAIL;
1519 result = g_dbus_proxy_call_sync(proxy,
1521 g_variant_new("(ss)", BT_HAL_ADAPTER_INTERFACE,
1523 G_DBUS_CALL_FLAGS_NONE,
1529 if (error != NULL) {
1530 ERR("Failed to get UUIDs (Error: %s)", error->message);
1531 g_clear_error(&error);
1533 ERR("Failed to get UUIDs");
1534 return BT_STATUS_FAIL;
1538 DBG("Got All Adaptr service UUID's from Bluez Stack!!, time to start parsing");
1541 * As we need to provide async callback to user from HAL, simply schedule a
1542 * callback method which will carry actual result
1544 g_idle_add(__bt_adapter_service_uuids_cb, (gpointer)result);
1546 return BT_STATUS_SUCCESS;
1549 static gboolean __is_device_paired(GVariantIter *item_iter)
1551 gboolean paired = FALSE;
1555 while (g_variant_iter_loop(item_iter, "{sv}", &key, &value)) {
1556 if (NULL == key || g_strcmp0(key, "Paired"))
1559 paired = g_variant_get_boolean(value);
1560 g_variant_unref(value);
1568 static gboolean __bt_adapter_bonded_devices_cb(gpointer user_data)
1570 /* Buffer and propety count management */
1571 uint8_t buf[BT_HAL_MAX_PROPERTY_BUF_SIZE];
1572 uint8_t addresses[BT_HAL_MAX_PROPERTY_BUF_SIZE];
1573 struct hal_ev_adapter_props_changed *ev = (void*) buf;;
1577 GVariant *result = user_data;
1579 GVariantIter *interface_iter;
1580 GVariantIter *svc_iter;
1581 char *object_path = NULL;
1582 char *interface_str = NULL;
1584 char device_address[BT_HAL_ADDRESS_STRING_SIZE];
1585 uint8_t bdaddr[BT_HAL_ADDRESS_LENGTH_MAX];
1587 memset(buf, 0, sizeof(buf));
1590 ev->status = BT_STATUS_SUCCESS;
1592 INFO("Size [%zd]", size);
1594 /* signature of GetManagedObjects: a{oa{sa{sv}}} */
1595 g_variant_get(result, "(a{oa{sa{sv}}})", &iter);
1597 /* Parse the signature: {oa{sa{sv}}} */
1598 while (g_variant_iter_loop(iter, "{&oa{sa{sv}}}", &object_path, &interface_iter)) {
1599 if (object_path == NULL)
1602 while (g_variant_iter_loop(interface_iter, "{sa{sv}}",
1603 &interface_str, &svc_iter)) {
1604 if (g_strcmp0(interface_str, "org.bluez.Device1") == 0) {
1605 DBG("Found a device: %s", object_path);
1606 if (__is_device_paired(svc_iter)) {
1607 _bt_hal_convert_device_path_to_address(object_path, device_address);
1608 DBG("Paired Device Address: [%s]", device_address);
1610 _bt_hal_convert_addr_string_to_type(bdaddr, device_address);
1611 memcpy((addresses + (count * BT_HAL_ADDRESS_LENGTH_MAX)),
1612 bdaddr, BT_HAL_ADDRESS_LENGTH_MAX);
1615 g_variant_iter_free(svc_iter);
1616 g_free(interface_str);
1617 interface_str = NULL;
1623 g_variant_iter_free(iter);
1624 g_variant_unref(result);
1626 size += __bt_insert_hal_properties((buf + size),
1627 HAL_PROP_ADAPTER_BONDED_DEVICES,
1628 (count * BT_HAL_ADDRESS_LENGTH_MAX), addresses);
1632 event_cb = _bt_get_adapter_event_cb();
1634 ERR("event_cb is NULL");
1639 DBG("Send Adapter properties changed event to HAL user,"
1640 " Num Prop [%d] total size [%zd]", ev->num_props, size);
1641 event_cb(HAL_EV_ADAPTER_PROPS_CHANGED, (void*) buf, size);
1647 int _bt_hal_dbus_get_bonded_devices(void)
1649 GDBusProxy *manager_proxy;
1650 GVariant *result = NULL;
1652 manager_proxy = _bt_hal_get_manager_proxy();
1653 if (manager_proxy == NULL)
1654 return BT_STATUS_FAIL;
1656 result = g_dbus_proxy_call_sync(manager_proxy, "GetManagedObjects",
1658 G_DBUS_CALL_FLAGS_NONE,
1663 ERR("Can't get managed objects");
1664 return BT_STATUS_FAIL;
1668 * As we need to provide async callback to user from HAL, simply schedule a
1669 * callback method which will carry actual result
1671 g_idle_add(__bt_adapter_bonded_devices_cb, (gpointer) result);
1673 return BT_STATUS_SUCCESS;
1676 int _bt_hal_dbus_get_adapter_property(bt_property_type_t property_type)
1678 DBG("property_type: %d", property_type);
1680 switch (property_type) {
1681 case BT_PROPERTY_BDADDR:
1682 return _bt_hal_dbus_get_local_address();
1683 case BT_PROPERTY_BDNAME:
1684 return _bt_hal_dbus_get_local_name();
1685 case BT_PROPERTY_VERSION:
1686 return _bt_hal_dbus_get_local_version();
1687 case BT_PROPERTY_ADAPTER_DISCOVERY_TIMEOUT:
1688 return _bt_hal_dbus_get_discovery_timeout();
1689 case BT_PROPERTY_ADAPTER_SCAN_MODE:
1690 return _bt_hal_dbus_get_scan_mode();
1691 case BT_PROPERTY_CLASS_OF_DEVICE:
1692 return BT_STATUS_UNSUPPORTED;
1693 case BT_PROPERTY_UUIDS:
1694 return _bt_hal_dbus_get_adapter_supported_uuids();
1695 case BT_PROPERTY_ADAPTER_BONDED_DEVICES:
1696 return _bt_hal_dbus_get_bonded_devices();
1698 return BT_STATUS_UNSUPPORTED;
1702 static int __bt_hal_dbus_set_local_name(void *data)
1705 const char *name = data;
1707 GError *error = NULL;
1709 DBG("Local Name: [%s]", name);
1710 proxy = _bt_hal_get_adapter_properties_proxy();
1712 DBG("_bt_hal_dbus_get_local_name: Adapter Properties proxy get failed!!!");
1713 return BT_STATUS_FAIL;
1716 result = g_dbus_proxy_call_sync(proxy,
1718 g_variant_new("(ssv)", BT_HAL_ADAPTER_INTERFACE,
1719 "Alias", g_variant_new("s", name)),
1720 G_DBUS_CALL_FLAGS_NONE,
1725 if (error != NULL) {
1726 ERR("Failed to set local name (Error: %s)", error->message);
1727 g_clear_error(&error);
1729 ERR("Failed to set local name");
1730 return BT_STATUS_FAIL;
1732 g_variant_unref(result);
1734 return BT_STATUS_SUCCESS;
1737 static int __bt_hal_dbus_set_scan_mode(void *data)
1742 GError *error = NULL;
1746 DBG("Scan mode: [%d]", *mode);
1747 proxy = _bt_hal_get_adapter_properties_proxy();
1749 DBG("Adapter Properties proxy get failed!!!");
1750 return BT_STATUS_FAIL;
1754 case BT_SCAN_MODE_NONE:
1758 case BT_SCAN_MODE_CONNECTABLE:
1762 case BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE:
1767 ERR("Invalid scan mode");
1768 return BT_STATUS_FAIL;
1771 result = g_dbus_proxy_call_sync(proxy,
1773 g_variant_new("(ssv)", BT_HAL_ADAPTER_INTERFACE,
1774 "Connectable", g_variant_new("b", pg_scan)),
1775 G_DBUS_CALL_FLAGS_NONE,
1780 if (error != NULL) {
1781 ERR("Failed to set connectable property (Error: %s)", error->message);
1782 g_clear_error(&error);
1784 ERR("Failed to set connectable property");
1785 return BT_STATUS_FAIL;
1787 g_variant_unref(result);
1789 result = g_dbus_proxy_call_sync(proxy,
1791 g_variant_new("(ssv)", BT_HAL_ADAPTER_INTERFACE, "Discoverable",
1792 g_variant_new("b", inq_scan)),
1793 G_DBUS_CALL_FLAGS_NONE,
1798 if (error != NULL) {
1799 ERR("Failed to set Discoverable property (Error: %s)", error->message);
1800 g_clear_error(&error);
1802 ERR("Failed to set Discoverable property");
1803 return BT_STATUS_FAIL;
1805 g_variant_unref(result);
1807 return BT_STATUS_SUCCESS;
1810 static int __bt_hal_dbus_set_discovery_timeout(void *data)
1813 unsigned int *timeout = data;
1815 GError *error = NULL;
1817 DBG("Discovery Timeout: [%d]", *timeout);
1818 proxy = _bt_hal_get_adapter_properties_proxy();
1820 DBG("Adapter Properties proxy get failed!!!");
1821 return BT_STATUS_FAIL;
1824 result = g_dbus_proxy_call_sync(proxy,
1826 g_variant_new("(ssv)", BT_HAL_ADAPTER_INTERFACE,
1827 "DiscoverableTimeout", g_variant_new("u", *timeout)),
1828 G_DBUS_CALL_FLAGS_NONE,
1833 if (error != NULL) {
1834 ERR("Failed to set DiscoverableTimeout property (Error: %s)", error->message);
1835 g_clear_error(&error);
1837 ERR("Failed to set DiscoverableTimeout property");
1838 return BT_STATUS_FAIL;
1840 g_variant_unref(result);
1842 return BT_STATUS_SUCCESS;
1845 /* Set Adapter Properties */
1846 int _bt_hal_dbus_set_adapter_property(const bt_property_t *property)
1850 if (property == NULL || property->val == NULL) {
1851 ERR("Invalid parameters received");
1852 return BT_STATUS_FAIL;
1855 switch (property->type) {
1856 case BT_PROPERTY_BDNAME:
1857 result = __bt_hal_dbus_set_local_name(property->val);
1859 case BT_PROPERTY_ADAPTER_SCAN_MODE:
1860 result = __bt_hal_dbus_set_scan_mode(property->val);
1862 case BT_PROPERTY_ADAPTER_DISCOVERY_TIMEOUT:
1863 result = __bt_hal_dbus_set_discovery_timeout(property->val);
1866 result = BT_STATUS_UNSUPPORTED;