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.
24 #if !defined(LIBNOTIFY_SUPPORT) && !defined(LIBNOTIFICATION_SUPPORT)
25 #include <syspopup_caller.h>
28 #include <dbus/dbus-glib.h>
29 #include <dbus/dbus.h>
31 #include <eventsystem.h>
32 #include <bundle_internal.h>
35 #include "bluetooth-api.h"
36 #include "bt-internal-types.h"
37 #include "bt-service-common.h"
38 #include "bt-service-event.h"
39 #include "bt-service-adapter.h"
40 #include "bt-service-util.h"
41 #include "bt-service-network.h"
42 #include "bt-service-obex-server.h"
43 #include "bt-service-agent.h"
44 #include "bt-service-main.h"
45 #include "bt-service-avrcp.h"
46 #include "bt-service-device.h"
47 #ifdef TIZEN_DPM_ENABLE
48 #include "bt-service-dpm.h"
59 bt_adapter_timer_t visible_timer = {0, };
61 static gboolean is_discovering;
62 static gboolean cancel_by_user;
63 static bt_status_t adapter_status = BT_DEACTIVATED;
64 static bt_le_status_t adapter_le_status = BT_LE_DEACTIVATED;
65 static void *adapter_agent = NULL;
66 static GDBusProxy *core_proxy = NULL;
67 static guint timer_id = 0;
68 static guint le_timer_id = 0;
70 static uint status_reg_id;
72 #define BT_CORE_NAME "org.projectx.bt_core"
73 #define BT_CORE_PATH "/org/projectx/bt_core"
74 #define BT_CORE_INTERFACE "org.projectx.btcore"
76 #define BT_DISABLE_TIME 500 /* 500 ms */
78 GDBusProxy *_bt_init_core_proxy(void)
81 GDBusConnection *conn;
83 conn = _bt_get_system_gconn();
87 proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
102 static GDBusProxy *__bt_get_core_proxy(void)
104 return (core_proxy) ? core_proxy : _bt_init_core_proxy();
107 static gboolean __bt_is_factory_test_mode(void)
111 #ifdef ENABLE_TIZEN_2_4
112 if (vconf_get_bool(VCONFKEY_BT_DUT_MODE, &mode)) {
113 BT_ERR("Get the DUT Mode fail");
119 BT_INFO("DUT Test Mode !!");
126 static gboolean __bt_timeout_handler(gpointer user_data)
128 int result = BLUETOOTH_ERROR_NONE;
132 /* Take current time */
134 time_diff = difftime(current_time, visible_timer.start_time);
136 /* Send event to application */
137 _bt_send_event(BT_ADAPTER_EVENT,
138 BLUETOOTH_EVENT_DISCOVERABLE_TIMEOUT_CHANGED,
139 g_variant_new("(in)", result, time_diff));
141 if (visible_timer.timeout <= time_diff) {
142 g_source_remove(visible_timer.event_id);
143 visible_timer.event_id = 0;
144 visible_timer.timeout = 0;
146 #ifndef TIZEN_WEARABLE
147 if (vconf_set_int(BT_FILE_VISIBLE_TIME, 0) != 0)
148 BT_ERR("Set vconf failed\n");
156 static int __bt_visibility_alarm_cb(alarm_id_t alarm_id, void* user_param)
158 BT_DBG("__bt_visibility_alarm_cb - alram id = [%d] \n", alarm_id);
160 int result = BLUETOOTH_ERROR_NONE;
163 if (alarm_id != visible_timer.alarm_id)
166 if (visible_timer.event_id) {
167 _bt_send_event(BT_ADAPTER_EVENT,
168 BLUETOOTH_EVENT_DISCOVERABLE_TIMEOUT_CHANGED,
169 g_variant_new("(in)", result, timeout));
170 g_source_remove(visible_timer.event_id);
171 visible_timer.event_id = 0;
172 visible_timer.timeout = 0;
174 #ifndef TIZEN_WEARABLE
175 if (vconf_set_int(BT_FILE_VISIBLE_TIME, 0) != 0)
176 BT_ERR("Set vconf failed\n");
179 /* Switch Off visibility in Bluez */
180 _bt_set_discoverable_mode(BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE, 0);
181 visible_timer.alarm_id = 0;
185 static void __bt_visibility_alarm_create()
190 result = alarmmgr_add_alarm(ALARM_TYPE_VOLATILE, visible_timer.timeout,
193 BT_ERR("Failed to create alarm error = %d\n", result);
195 BT_DBG("Alarm created = %d\n", alarm_id);
196 visible_timer.alarm_id = alarm_id;
200 static void __bt_visibility_alarm_remove()
202 if (visible_timer.event_id > 0) {
203 g_source_remove(visible_timer.event_id);
204 visible_timer.event_id = 0;
207 if (visible_timer.alarm_id > 0) {
208 alarmmgr_remove_alarm(visible_timer.alarm_id);
209 visible_timer.alarm_id = 0;
213 int __bt_set_visible_time(int timeout)
217 __bt_visibility_alarm_remove();
219 visible_timer.timeout = timeout;
221 #ifndef TIZEN_WEARABLE
222 #ifdef TIZEN_DPM_ENABLE
223 if (_bt_dpm_get_bluetooth_limited_discoverable_state() != DPM_RESTRICTED) {
225 if (vconf_set_int(BT_FILE_VISIBLE_TIME, timeout) != 0)
226 BT_ERR("Set vconf failed");
227 #ifdef TIZEN_DPM_ENABLE
233 return BLUETOOTH_ERROR_NONE;
235 if (!visible_timer.alarm_init) {
236 /* Set Alarm timer to switch off BT */
237 result = alarmmgr_init("bt-service");
239 return BLUETOOTH_ERROR_INTERNAL;
241 visible_timer.alarm_init = TRUE;
244 result = alarmmgr_set_cb(__bt_visibility_alarm_cb, NULL);
246 return BLUETOOTH_ERROR_INTERNAL;
248 /* Take start time */
249 time(&(visible_timer.start_time));
250 visible_timer.event_id = g_timeout_add_seconds(1,
251 __bt_timeout_handler, NULL);
253 __bt_visibility_alarm_create();
255 return BLUETOOTH_ERROR_NONE;
258 static void __bt_get_service_list(GVariant *value, bluetooth_device_info_t *dev)
265 ret_if(value == NULL);
268 dev->service_index = 0;
270 g_variant_get(value, "as", &iter);
271 while (g_variant_iter_loop(iter, "s", &uuid)) {
272 g_strlcpy(dev->uuids[i], uuid, BLUETOOTH_UUID_STRING_MAX);
273 parts = g_strsplit(uuid, "-", -1);
275 if (parts == NULL || parts[0] == NULL) {
280 dev->service_list_array[i] = g_ascii_strtoull(parts[0], NULL, 16);
283 dev->service_index++;
286 g_variant_iter_free(iter);
289 static int __bt_get_bonded_device_info(gchar *device_path,
290 bluetooth_device_info_t *dev_info)
292 GError *error = NULL;
293 GDBusProxy *device_proxy;
294 gchar *address = NULL;
296 unsigned int cod = 0;
298 gboolean trust = FALSE;
299 gboolean paired = FALSE;
300 guchar connected = 0;
301 GByteArray *manufacturer_data = NULL;
303 GDBusConnection *conn;
305 GVariantIter *property_iter;
309 GVariantIter *char_value_iter;
311 BT_CHECK_PARAMETER(device_path, return);
312 BT_CHECK_PARAMETER(dev_info, return);
314 conn = _bt_get_system_gconn();
315 retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
317 device_proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
321 BT_PROPERTIES_INTERFACE,
324 retv_if(device_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
326 result = g_dbus_proxy_call_sync(device_proxy,
328 g_variant_new("(s)", BT_DEVICE_INTERFACE),
329 G_DBUS_CALL_FLAGS_NONE,
335 BT_ERR("Error occured in Proxy call");
337 BT_ERR("Error occured in Proxy call (Error: %s)", error->message);
338 g_clear_error(&error);
340 g_object_unref(device_proxy);
341 return BLUETOOTH_ERROR_INTERNAL;
344 g_object_unref(device_proxy);
346 g_variant_get(result, "(a{sv})", &property_iter);
348 while (g_variant_iter_loop(property_iter, "{sv}", &key, &value)) {
349 if (!g_strcmp0(key, "Paired")) {
350 paired = g_variant_get_boolean(value);
351 } else if (!g_strcmp0(key, "Address")) {
352 g_variant_get(value, "s", &address);
353 } else if (!g_strcmp0(key, "Alias")) {
354 g_variant_get(value, "s", &name);
355 } else if (!g_strcmp0(key, "Name")) {
357 g_variant_get(value, "s", &name);
358 } else if (!g_strcmp0(key, "Class")) {
359 cod = g_variant_get_uint32(value);
360 } else if (!g_strcmp0(key, "Connected")) {
361 connected = g_variant_get_byte(value);
362 } else if (!g_strcmp0(key, "Trusted")) {
363 trust = g_variant_get_boolean(value);
364 } else if (!g_strcmp0(key, "RSSI")) {
365 rssi = g_variant_get_int16(value);
366 } else if (!g_strcmp0(key, "UUIDs")) {
367 __bt_get_service_list(value, dev_info);
368 } else if (!g_strcmp0(key, "ManufacturerDataLen")) {
369 dev_info->manufacturer_data.data_len = g_variant_get_uint16(value);
370 } else if (!g_strcmp0(key, "ManufacturerData")) {
371 manufacturer_data = g_byte_array_new();
372 g_variant_get(value, "ay", &char_value_iter);
374 while (g_variant_iter_loop(char_value_iter, "y", &char_value))
375 g_byte_array_append(manufacturer_data, &char_value, 1);
377 g_variant_iter_free(char_value_iter);
379 if (manufacturer_data) {
380 if (manufacturer_data->len > 0) {
381 memcpy(dev_info->manufacturer_data.data, manufacturer_data->data,
382 manufacturer_data->len);
387 g_variant_iter_free(property_iter);
389 BT_DBG("trust: %d, paired: %d", trust, paired);
391 g_variant_unref(result);
393 if ((paired == FALSE) && (trust == FALSE)) {
396 return BLUETOOTH_ERROR_NOT_PAIRED;
399 _bt_convert_addr_string_to_type(dev_info->device_address.addr,
402 _bt_divide_device_class(&dev_info->device_class, cod);
404 g_strlcpy(dev_info->device_name.name, name,
405 BLUETOOTH_DEVICE_NAME_LENGTH_MAX+1);
407 dev_info->rssi = rssi;
408 dev_info->trust = trust;
409 dev_info->paired = paired;
410 dev_info->connected = connected;
411 ret = BLUETOOTH_ERROR_NONE;
418 void _bt_set_discovery_status(gboolean mode)
420 is_discovering = mode;
423 void _bt_set_cancel_by_user(gboolean value)
425 cancel_by_user = value;
428 gboolean _bt_get_cancel_by_user(void)
430 return cancel_by_user;
433 void _bt_adapter_set_status(bt_status_t status)
435 BT_INFO("adapter_status changed [%d] -> [%d]", adapter_status, status);
436 adapter_status = status;
439 bt_status_t _bt_adapter_get_status(void)
441 return adapter_status;
444 void _bt_adapter_set_le_status(bt_le_status_t status)
446 BT_INFO("adapter_le_status changed [%d] -> [%d]", adapter_le_status, status);
447 adapter_le_status = status;
450 bt_le_status_t _bt_adapter_get_le_status(void)
452 return adapter_le_status;
455 static void __bt_phone_name_changed_cb(keynode_t *node, void *data)
457 char *phone_name = NULL;
463 if (vconf_keynode_get_type(node) == VCONF_TYPE_STRING) {
464 phone_name = vconf_keynode_get_str(node);
466 if (phone_name && strlen(phone_name) != 0) {
467 if (!g_utf8_validate(phone_name, -1,
468 (const char **)&ptr))
471 _bt_set_local_name(phone_name);
477 static void __bt_set_visible_mode(void)
481 if (vconf_get_int(BT_FILE_VISIBLE_TIME, &timeout) != 0)
482 BT_ERR("Fail to get the timeout value");
484 #ifdef TIZEN_DPM_ENABLE
486 _bt_dpm_get_bluetooth_limited_discoverable_state() == DPM_RESTRICTED) {
487 if (_bt_set_discoverable_mode(
488 BLUETOOTH_DISCOVERABLE_MODE_GENERAL_DISCOVERABLE,
489 timeout) != BLUETOOTH_ERROR_NONE) {
490 if (vconf_set_int(BT_FILE_VISIBLE_TIME, 0) != 0)
491 BT_ERR("Set vconf failed");
494 if (_bt_set_discoverable_mode(
495 BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE,
496 timeout) != BLUETOOTH_ERROR_NONE) {
497 BT_ERR("Set connectable mode failed");
502 if (_bt_set_discoverable_mode(
503 BLUETOOTH_DISCOVERABLE_MODE_GENERAL_DISCOVERABLE,
504 timeout) != BLUETOOTH_ERROR_NONE) {
505 if (vconf_set_int(BT_FILE_VISIBLE_TIME, 0) != 0)
506 BT_ERR("Set vconf failed");
509 if (_bt_set_discoverable_mode(
510 BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE,
511 timeout) != BLUETOOTH_ERROR_NONE) {
512 BT_ERR("Set connectable mode failed");
519 static void __bt_set_local_name(void)
521 char *phone_name = NULL;
524 phone_name = vconf_get_str(VCONFKEY_SETAPPL_DEVICE_NAME_STR);
529 if (strlen(phone_name) != 0) {
530 if (!g_utf8_validate(phone_name, -1, (const char **)&ptr))
533 _bt_set_local_name(phone_name);
538 static int __bt_set_enabled(void)
541 int adapter_status = BT_ADAPTER_DISABLED;
542 int result = BLUETOOTH_ERROR_NONE;
544 _bt_check_adapter(&adapter_status);
546 if (adapter_status == BT_ADAPTER_DISABLED) {
547 BT_ERR("Bluetoothd is not running");
548 return BLUETOOTH_ERROR_INTERNAL;
552 __bt_set_visible_mode();
555 if (_bt_set_discoverable_mode(
556 BLUETOOTH_DISCOVERABLE_MODE_GENERAL_DISCOVERABLE, 0) != BLUETOOTH_ERROR_NONE)
557 BT_ERR("Fail to set discoverable mode");
560 __bt_set_local_name();
562 /* Update Bluetooth Status to notify other modules */
563 if (vconf_set_int(VCONFKEY_BT_STATUS, VCONFKEY_BT_STATUS_ON) != 0)
564 BT_ERR("Set vconf failed\n");
566 if (vconf_set_int(VCONFKEY_BT_DEVICE, VCONFKEY_BT_DEVICE_NONE) != 0)
567 BT_ERR("Set vconf failed\n");
569 if (_bt_eventsystem_set_value(SYS_EVENT_BT_STATE, EVT_KEY_BT_STATE,
570 EVT_VAL_BT_ON) != ES_R_OK)
571 BT_ERR("Fail to set value");
574 /* Send enabled event to API */
575 _bt_send_event(BT_ADAPTER_EVENT, BLUETOOTH_EVENT_ENABLED,
576 g_variant_new("(i)", result));
579 return BLUETOOTH_ERROR_NONE;
582 void _bt_set_disabled(int result)
584 int power_off_status = 0;
587 int pm_ignore_mode = 0;
589 ret = vconf_get_int(VCONFKEY_SYSMAN_POWER_OFF_STATUS, &power_off_status);
590 BT_DBG("ret : %d, power_off_status : %d", ret, power_off_status);
592 ret_pm_ignore = vconf_get_int(VCONFKEY_PM_KEY_IGNORE, &pm_ignore_mode);
594 /* Update the vconf BT status in normal Deactivation case only */
595 if (ret == 0 && power_off_status == VCONFKEY_SYSMAN_POWER_OFF_NONE &&
596 ret_pm_ignore == 0 && pm_ignore_mode != VCONFKEY_PM_KEY_LOCK) {
598 BT_DBG("Update vconf for BT normal Deactivation");
600 if (result == BLUETOOTH_ERROR_TIMEOUT)
601 if (vconf_set_int(BT_OFF_DUE_TO_TIMEOUT, 1) != 0)
602 BT_ERR("Set vconf failed");
604 /* Update Bluetooth Status to notify other modules */
605 if (vconf_set_int(VCONFKEY_BT_STATUS, VCONFKEY_BT_STATUS_OFF) != 0)
606 BT_ERR("Set vconf failed");
608 if (_bt_eventsystem_set_value(SYS_EVENT_BT_STATE, EVT_KEY_BT_STATE,
609 EVT_VAL_BT_OFF) != ES_R_OK)
610 BT_ERR("Fail to set value");
613 if (vconf_set_int(VCONFKEY_BT_DEVICE, VCONFKEY_BT_DEVICE_NONE) != 0)
614 BT_ERR("Set vconf failed\n");
616 _bt_adapter_set_status(BT_DEACTIVATED);
618 if (_bt_adapter_get_le_status() != BT_LE_DEACTIVATED) {
619 /* Send disabled event */
620 _bt_send_event(BT_ADAPTER_EVENT, BLUETOOTH_EVENT_DISABLED,
621 g_variant_new("(i)", result));
624 BT_INFO("Adapter disabled");
627 static int __bt_set_le_enabled(void)
630 int result = BLUETOOTH_ERROR_NONE;
633 __bt_set_local_name();
635 /* Update Bluetooth Status to notify other modules */
636 if (vconf_set_int(VCONFKEY_BT_LE_STATUS, VCONFKEY_BT_LE_STATUS_ON) != 0)
637 BT_ERR("Set vconf failed\n");
639 if (_bt_eventsystem_set_value(SYS_EVENT_BT_STATE, EVT_KEY_BT_LE_STATE,
640 EVT_VAL_BT_LE_ON) != ES_R_OK)
641 BT_ERR("Fail to set value");
643 /* Send enabled event to API */
645 _bt_send_event(BT_ADAPTER_EVENT, BLUETOOTH_EVENT_ENABLED,
646 DBUS_TYPE_INT32, &result, DBUS_TYPE_INVALID);
648 status = _bt_adapter_get_status();
649 if (status == BT_DEACTIVATED) {
650 BT_INFO("BREDR is off, turn off PSCAN");
651 _bt_set_connectable(FALSE);
653 if (le_timer_id > 0) {
654 g_source_remove(le_timer_id);
658 /* Send enabled event to API */
659 _bt_send_event(BT_LE_ADAPTER_EVENT, BLUETOOTH_EVENT_LE_ENABLED,
660 g_variant_new("(i)", result));
663 return BLUETOOTH_ERROR_NONE;
666 void _bt_set_le_disabled(int result)
668 int power_off_status;
671 ret = vconf_get_int(VCONFKEY_SYSMAN_POWER_OFF_STATUS, &power_off_status);
672 BT_DBG("ret : %d", ret);
673 BT_DBG("power_off_status : %d", power_off_status);
675 /* Update Bluetooth Status to notify other modules */
676 BT_DBG("Update vconf for BT LE normal Deactivation");
677 if (vconf_set_int(VCONFKEY_BT_LE_STATUS, VCONFKEY_BT_LE_STATUS_OFF) != 0)
678 BT_ERR("Set vconf failed\n");
679 _bt_adapter_set_le_status(BT_LE_DEACTIVATED);
681 if (_bt_eventsystem_set_value(SYS_EVENT_BT_STATE, EVT_KEY_BT_LE_STATE,
682 EVT_VAL_BT_LE_OFF) != ES_R_OK)
683 BT_ERR("Fail to set value");
685 /* Send disabled event */
686 _bt_send_event(BT_LE_ADAPTER_EVENT, BLUETOOTH_EVENT_LE_DISABLED,
687 g_variant_new_int32(result));
690 void *_bt_get_adapter_agent(void)
692 return adapter_agent;
695 int _bt_enable_core(void)
699 GError *error = NULL;
701 proxy = __bt_get_core_proxy();
702 retv_if(!proxy, BLUETOOTH_ERROR_INTERNAL);
704 /* Clean up the process */
705 result = g_dbus_proxy_call_sync(proxy,
708 G_DBUS_CALL_FLAGS_NONE,
715 BT_ERR("Bt core call failed(Error: %s)", error->message);
716 g_clear_error(&error);
718 BT_ERR("Bt core call failed");
719 return BLUETOOTH_ERROR_INTERNAL;
722 g_variant_unref(result);
723 return BLUETOOTH_ERROR_NONE;
726 #if defined(TIZEN_BT_FLIGHTMODE_ENABLED) || (!defined(TIZEN_WEARABLE) && defined(ENABLE_TIZEN_2_4))
727 static void __bt_service_flight_ps_mode_cb(keynode_t *node, void *data)
729 gboolean flight_mode = FALSE;
730 int power_saving_mode = 0;
733 DBG_SECURE("key=%s", vconf_keynode_get_name(node));
734 type = vconf_keynode_get_type(node);
735 if (type == VCONF_TYPE_BOOL) {
736 flight_mode = vconf_keynode_get_bool(node);
737 if (flight_mode != TRUE) {
738 BT_ERR("Ignore the event");
741 } else if (type == VCONF_TYPE_INT) {
742 power_saving_mode = vconf_keynode_get_int(node);
743 if (power_saving_mode != 2) {
744 BT_ERR("Ignore the event");
748 BT_ERR("Invaild vconf key type : %d", type);
756 void _bt_service_register_vconf_handler(void)
760 #ifdef TIZEN_BT_FLIGHTMODE_ENABLED
761 if (vconf_notify_key_changed(VCONFKEY_TELEPHONY_FLIGHT_MODE,
762 (vconf_callback_fn)__bt_service_flight_ps_mode_cb, NULL) < 0)
763 BT_ERR("Unable to register key handler");
765 BT_DBG("Telephony is disabled");
768 #ifndef TIZEN_WEARABLE
769 #ifdef ENABLE_TIZEN_2_4
770 if (vconf_notify_key_changed(VCONFKEY_SETAPPL_PSMODE,
771 (vconf_callback_fn)__bt_service_flight_ps_mode_cb, NULL) < 0)
772 BT_ERR("Unable to register key handler");
777 void _bt_service_unregister_vconf_handler(void)
781 #ifdef TIZEN_BT_FLIGHTMODE_ENABLED
782 vconf_ignore_key_changed(VCONFKEY_TELEPHONY_FLIGHT_MODE,
783 (vconf_callback_fn)__bt_service_flight_ps_mode_cb);
786 #ifndef TIZEN_WEARABLE
787 #ifdef ENABLE_TIZEN_2_4
788 vconf_ignore_key_changed(VCONFKEY_SETAPPL_PSMODE,
789 (vconf_callback_fn)__bt_service_flight_ps_mode_cb);
794 static void __bt_state_event_handler(const char *event_name, bundle *data, void *user_data)
796 #ifdef ENABLE_TIZEN_2_4
797 const char *bt_status = NULL;
798 const char *bt_le_status = NULL;
799 BT_DBG("bt state set event(%s) received", event_name);
800 bt_status = bundle_get_val(data, EVT_KEY_BT_STATE);
801 BT_DBG("bt_state: (%s)", bt_status);
803 bt_le_status = bundle_get_val(data, EVT_KEY_BT_LE_STATE);
804 BT_DBG("bt_state: (%s)", bt_le_status);
808 void _bt_handle_adapter_added(void)
812 bt_le_status_t le_status;
816 BT_DBG("g_source is removed");
817 g_source_remove(timer_id);
821 status = _bt_adapter_get_status();
822 le_status = _bt_adapter_get_le_status();
823 BT_DBG("status : %d", status);
824 BT_DBG("le_status : %d", le_status);
826 adapter_agent = _bt_create_agent(BT_ADAPTER_AGENT_PATH, TRUE);
827 if (!adapter_agent) {
828 BT_ERR("Fail to register agent");
832 if (_bt_register_media_player() != BLUETOOTH_ERROR_NONE)
833 BT_ERR("Fail to register media player");
835 if (_bt_register_obex_server() != BLUETOOTH_ERROR_NONE)
836 BT_ERR("Fail to init obex server");
838 #ifdef TIZEN_BT_PAN_NAP_ENABLE
839 if (_bt_network_activate() != BLUETOOTH_ERROR_NONE)
840 BT_ERR("Fail to activate network");
843 /* add the vconf noti handler */
844 ret = vconf_notify_key_changed(VCONFKEY_SETAPPL_DEVICE_NAME_STR,
845 __bt_phone_name_changed_cb, NULL);
847 BT_ERR("Unable to register key handler");
849 if (le_status == BT_LE_ACTIVATING ||
850 status == BT_ACTIVATING) {
851 __bt_set_le_enabled();
852 _bt_adapter_set_le_status(BT_LE_ACTIVATED);
855 if (status == BT_ACTIVATING) {
857 _bt_adapter_set_status(BT_ACTIVATED);
859 #ifdef ENABLE_TIZEN_2_4
863 _bt_service_register_vconf_handler();
866 if (eventsystem_register_event(SYS_EVENT_BT_STATE, &status_reg_id,
867 (eventsystem_handler)__bt_state_event_handler, NULL) != ES_R_OK) {
868 BT_ERR("Fail to register system event");
872 void _bt_handle_adapter_removed(void)
876 _bt_adapter_set_status(BT_DEACTIVATED);
877 #ifdef ENABLE_TIZEN_2_4
881 __bt_visibility_alarm_remove();
883 if (visible_timer.alarm_init) {
885 visible_timer.alarm_init = FALSE;
888 ret = vconf_ignore_key_changed(VCONFKEY_SETAPPL_DEVICE_NAME_STR,
889 (vconf_callback_fn)__bt_phone_name_changed_cb);
891 ERR("vconf_ignore_key_changed failed\n");
894 _bt_destroy_agent(adapter_agent);
895 adapter_agent = NULL;
897 _bt_reliable_terminate_service(NULL);
899 if (eventsystem_unregister_event(status_reg_id) != ES_R_OK) {
900 BT_ERR("Fail to unregister system event");
905 static gboolean __bt_enable_timeout_cb(gpointer user_data)
909 GError *error = NULL;
913 retv_if(_bt_adapter_get_status() == BT_ACTIVATED, FALSE);
915 BT_ERR("EnableAdapter is failed");
917 proxy = __bt_get_core_proxy();
921 /* Clean up the process */
922 result = g_dbus_proxy_call_sync(proxy,
925 G_DBUS_CALL_FLAGS_NONE,
932 BT_ERR("Bt core call failed(Error: %s)", error->message);
933 g_clear_error(&error);
935 BT_ERR("Bt core call failed");
940 g_variant_unref(result);
941 _bt_set_disabled(BLUETOOTH_ERROR_TIMEOUT);
943 _bt_terminate_service(NULL);
948 static gboolean __bt_enable_le_timeout_cb(gpointer user_data)
952 GError *error = NULL;
956 retv_if(_bt_adapter_get_le_status() == BT_LE_ACTIVATED, FALSE);
958 BT_ERR("EnableAdapterLE is failed");
960 proxy = __bt_get_core_proxy();
964 /* Clean up the process */
965 result = g_dbus_proxy_call_sync(proxy,
968 G_DBUS_CALL_FLAGS_NONE,
975 BT_ERR("Bt core call failed(Error: %s)", error->message);
976 g_clear_error(&error);
978 BT_ERR("Bt core call failed");
982 g_variant_unref(result);
983 _bt_adapter_set_le_status(BT_LE_DEACTIVATED);
985 _bt_set_le_disabled(BLUETOOTH_ERROR_TIMEOUT);
987 if (_bt_adapter_get_status() == BT_DEACTIVATED)
988 _bt_terminate_service(NULL);
993 void _bt_adapter_start_le_enable_timer(void)
995 if (le_timer_id > 0) {
996 g_source_remove(le_timer_id);
1000 le_timer_id = g_timeout_add(BT_ENABLE_TIMEOUT,
1001 __bt_enable_le_timeout_cb, NULL);
1006 void _bt_adapter_start_enable_timer(void)
1009 g_source_remove(timer_id);
1013 timer_id = g_timeout_add(BT_ENABLE_TIMEOUT,
1014 __bt_enable_timeout_cb, NULL);
1020 static gboolean __bt_adapter_enabled_cb(gpointer user_data)
1025 _bt_adapter_set_status(BT_ACTIVATED);
1031 int _bt_enable_adapter(void)
1034 GError *error = NULL;
1036 GVariant *result = NULL;
1037 bt_status_t status = _bt_adapter_get_status();
1038 bt_le_status_t le_status = _bt_adapter_get_le_status();
1042 if (status == BT_ACTIVATING) {
1043 BT_ERR("Enabling in progress");
1044 return BLUETOOTH_ERROR_IN_PROGRESS;
1047 if (status == BT_ACTIVATED) {
1048 BT_ERR("Already enabled");
1049 return BLUETOOTH_ERROR_DEVICE_ALREADY_ENABLED;
1052 if (status == BT_DEACTIVATING || le_status == BT_LE_DEACTIVATING) {
1053 BT_ERR("Disabling in progress");
1054 return BLUETOOTH_ERROR_DEVICE_BUSY;
1057 _bt_adapter_set_status(BT_ACTIVATING);
1061 int adapter_status = BT_ADAPTER_DISABLED;
1063 if (vconf_set_int(VCONFKEY_BT_STATUS, VCONFKEY_BT_STATUS_OFF) != 0)
1064 BT_ERR("Set vconf failed");
1066 _bt_check_adapter(&adapter_status);
1067 if (adapter_status == BT_ADAPTER_ENABLED) {
1068 g_idle_add(__bt_adapter_enabled_cb, NULL);
1069 _bt_adapter_start_enable_timer();
1070 return BLUETOOTH_ERROR_NONE;
1075 proxy = __bt_get_core_proxy();
1077 return BLUETOOTH_ERROR_INTERNAL;
1079 if (le_status == BT_LE_ACTIVATED) {
1080 BT_INFO("LE Already enabled. Just turn on PSCAN");
1081 ret = _bt_set_connectable(TRUE);
1082 if (ret == BLUETOOTH_ERROR_NONE) {
1083 _bt_adapter_set_status(BT_ACTIVATED);
1085 return BLUETOOTH_ERROR_INTERNAL;
1089 result = g_dbus_proxy_call_sync(proxy, "EnableAdapter",
1091 G_DBUS_CALL_FLAGS_NONE, BT_ENABLE_TIMEOUT,
1094 BT_ERR("EnableAdapterLe failed: %s", error->message);
1095 _bt_adapter_set_status(BT_DEACTIVATED);
1096 g_clear_error(&error);
1098 result = g_dbus_proxy_call_sync(proxy,
1101 G_DBUS_CALL_FLAGS_NONE,
1106 if (error != NULL) {
1107 BT_ERR("Bt core call failed(Error: %s)", error->message);
1108 g_clear_error(&error);
1110 g_variant_unref(result);
1111 /* Terminate myself */
1112 g_idle_add((GSourceFunc)_bt_terminate_service, NULL);
1113 return BLUETOOTH_ERROR_INTERNAL;
1115 g_variant_unref(result);
1116 if (le_status == BT_LE_ACTIVATED) {
1119 _bt_adapter_start_enable_timer();
1122 return BLUETOOTH_ERROR_NONE;
1125 static gboolean __bt_disconnect_all(void)
1128 GDBusConnection *conn;
1129 GDBusProxy *dev_proxy;
1130 gboolean ret = FALSE;
1132 GError *error = NULL;
1133 GArray *device_list;
1134 bluetooth_device_info_t info;
1136 char *device_path = NULL;
1137 char address[BT_ADDRESS_STRING_SIZE] = { 0 };
1142 conn = _bt_get_system_gconn();
1144 device_list = g_array_new(FALSE, FALSE, sizeof(gchar));
1146 if (_bt_get_bonded_devices(&device_list)
1147 != BLUETOOTH_ERROR_NONE) {
1148 g_array_free(device_list, TRUE);
1152 size = (device_list->len) / sizeof(bluetooth_device_info_t);
1154 for (i = 0; i < size; i++) {
1156 info = g_array_index(device_list,
1157 bluetooth_device_info_t, i);
1159 if (info.connected != BLUETOOTH_CONNECTED_LINK_NONE) {
1160 BT_DBG("Found Connected device");
1161 _bt_convert_addr_type_to_string(address, info.device_address.addr);
1162 device_path = _bt_get_device_object_path(address);
1163 if (device_path == NULL)
1166 BT_DBG("Disconnecting : %s", device_path);
1168 dev_proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
1172 BT_DEVICE_INTERFACE,
1175 if (dev_proxy == NULL)
1178 result = g_dbus_proxy_call_sync(dev_proxy,
1181 G_DBUS_CALL_FLAGS_NONE,
1187 if (error != NULL) {
1188 BT_ERR("Disconnect call failed(Error: %s)", error->message);
1189 g_clear_error(&error);
1191 BT_ERR("Disconnect call failed");
1192 g_object_unref(dev_proxy);
1196 g_variant_unref(result);
1197 g_object_unref(dev_proxy);
1201 g_array_free(device_list, TRUE);
1207 static gboolean __bt_set_disabled_timeout_cb(gpointer user_data)
1210 _bt_set_disabled(BLUETOOTH_ERROR_NONE);
1216 int __bt_disable_cb(void)
1224 GError *error = NULL;
1226 _bt_adapter_set_status(BT_DEACTIVATING);
1228 bt_le_status_t le_status;
1229 le_status = _bt_adapter_get_le_status();
1230 BT_DBG("le_status : %d", le_status);
1231 if (le_status == BT_LE_ACTIVATED) {
1232 BT_INFO("LE is enabled. Just turn off PSCAN");
1234 if (_bt_is_discovering())
1235 _bt_cancel_discovery();
1237 if (_bt_is_connectable() == FALSE) {
1238 g_timeout_add(100, (GSourceFunc)__bt_set_disabled_timeout_cb, NULL);
1240 ret = _bt_set_connectable(FALSE);
1241 if (ret != BLUETOOTH_ERROR_NONE) {
1242 BT_ERR("_bt_set_connectable fail!");
1243 _bt_adapter_set_status(BT_ACTIVATED);
1244 return BLUETOOTH_ERROR_INTERNAL;
1249 proxy = __bt_get_core_proxy();
1250 retv_if(!proxy, BLUETOOTH_ERROR_INTERNAL);
1252 result = g_dbus_proxy_call_sync(proxy,
1255 G_DBUS_CALL_FLAGS_NONE,
1261 if (error != NULL) {
1262 BT_ERR("Failed to DisableAdapter (Error: %s)", error->message);
1263 g_clear_error(&error);
1265 BT_ERR("Failed to DisableAdapter");
1266 _bt_adapter_set_status(BT_ACTIVATED);
1267 return BLUETOOTH_ERROR_INTERNAL;
1270 g_variant_unref(result);
1271 return BLUETOOTH_ERROR_NONE;
1274 int _bt_disable_adapter(void)
1279 if (_bt_adapter_get_status() == BT_DEACTIVATING) {
1280 BT_DBG("Disabling in progress");
1281 return BLUETOOTH_ERROR_IN_PROGRESS;
1284 if (_bt_adapter_get_status() == BT_DEACTIVATED) {
1285 BT_DBG("Already disabled");
1286 return BLUETOOTH_ERROR_DEVICE_NOT_ENABLED;
1290 g_source_remove(timer_id);
1294 __bt_disconnect_all();
1295 ret = __bt_disable_cb();
1301 int _bt_recover_adapter(void)
1306 GError *error = NULL;
1308 if (_bt_adapter_get_status() == BT_DEACTIVATING) {
1309 BT_DBG("Disabling in progress");
1310 return BLUETOOTH_ERROR_IN_PROGRESS;
1313 if (_bt_adapter_get_status() == BT_DEACTIVATED) {
1314 BT_DBG("Already disabled");
1315 return BLUETOOTH_ERROR_DEVICE_NOT_ENABLED;
1318 _bt_adapter_set_status(BT_DEACTIVATING);
1320 proxy = __bt_get_core_proxy();
1321 retv_if(!proxy, BLUETOOTH_ERROR_INTERNAL);
1323 result = g_dbus_proxy_call_sync(proxy,
1326 G_DBUS_CALL_FLAGS_NONE,
1332 if (error != NULL) {
1333 BT_ERR("Failed to RecoverAdapter (Error: %s)", error->message);
1334 g_clear_error(&error);
1336 BT_ERR("Failed to RecoverAdapter");
1337 return BLUETOOTH_ERROR_INTERNAL;
1340 g_variant_unref(result);
1341 __bt_disconnect_all();
1344 return BLUETOOTH_ERROR_NONE;
1347 int _bt_reset_adapter(void)
1351 GError *error = NULL;
1355 proxy = __bt_get_core_proxy();
1357 return BLUETOOTH_ERROR_INTERNAL;
1359 result = g_dbus_proxy_call_sync(proxy,
1362 G_DBUS_CALL_FLAGS_NONE,
1368 if (error != NULL) {
1369 BT_ERR("Failed to ResetAdapter (Error: %s)", error->message);
1370 g_clear_error(&error);
1372 BT_ERR("Failed to ResetAdapter");
1373 return BLUETOOTH_ERROR_INTERNAL;
1376 g_variant_unref(result);
1377 /* Terminate myself */
1378 if (_bt_adapter_get_status() == BT_DEACTIVATED) {
1379 g_idle_add((GSourceFunc)_bt_terminate_service, NULL);
1382 return BLUETOOTH_ERROR_NONE;
1386 int _bt_check_adapter(int *status)
1389 char *adapter_path = NULL;
1391 BT_CHECK_PARAMETER(status, return);
1393 *status = BT_ADAPTER_DISABLED;
1395 adapter_path = _bt_get_adapter_path();
1398 if (adapter_path != NULL)
1399 *status = BT_ADAPTER_ENABLED;
1401 g_free(adapter_path);
1402 return BLUETOOTH_ERROR_NONE;
1405 int _bt_check_adapter(int *status)
1408 GError *error = NULL;
1411 gboolean powered = FALSE;
1413 BT_CHECK_PARAMETER(status, return);
1415 *status = BT_ADAPTER_DISABLED;
1417 proxy = _bt_get_adapter_properties_proxy();
1418 retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
1420 result = g_dbus_proxy_call_sync(proxy,
1422 g_variant_new("(ss)", BT_ADAPTER_INTERFACE,
1424 G_DBUS_CALL_FLAGS_NONE,
1430 BT_ERR("Failed to get local address");
1431 if (error != NULL) {
1432 BT_ERR("Failed to get local address (Error: %s)", error->message);
1433 g_clear_error(&error);
1435 return BLUETOOTH_ERROR_INTERNAL;
1438 g_variant_get(result, "(v)", &temp);
1439 powered = g_variant_get_boolean(temp);
1440 BT_DBG("powered: %d", powered);
1443 *status = BT_ADAPTER_ENABLED;
1445 g_variant_unref(result);
1446 g_variant_unref(temp);
1447 return BLUETOOTH_ERROR_NONE;
1451 int _bt_enable_adapter_le(void)
1455 GError *error = NULL;
1456 bt_status_t status = _bt_adapter_get_status();
1457 bt_le_status_t le_status = _bt_adapter_get_le_status();
1460 if (le_status == BT_LE_ACTIVATING) {
1461 BT_ERR("Enabling in progress");
1462 return BLUETOOTH_ERROR_IN_PROGRESS;
1465 if (le_status == BT_LE_ACTIVATED) {
1466 BT_ERR("Already enabled");
1467 return BLUETOOTH_ERROR_DEVICE_ALREADY_ENABLED;
1470 if (status == BT_DEACTIVATING || le_status == BT_LE_DEACTIVATING) {
1471 BT_ERR("Disabling in progress");
1472 return BLUETOOTH_ERROR_DEVICE_BUSY;
1475 _bt_adapter_set_le_status(BT_LE_ACTIVATING);
1477 proxy = __bt_get_core_proxy();
1478 retv_if(!proxy, BLUETOOTH_ERROR_INTERNAL);
1480 result = g_dbus_proxy_call_sync(proxy, "EnableAdapterLe",
1482 G_DBUS_CALL_FLAGS_NONE, BT_ENABLE_TIMEOUT,
1485 BT_ERR("EnableAdapterLe failed: %s", error->message);
1486 _bt_adapter_set_le_status(BT_DEACTIVATED);
1487 g_clear_error(&error);
1489 /* Clean up the process */
1490 result = g_dbus_proxy_call_sync(proxy,
1493 G_DBUS_CALL_FLAGS_NONE,
1499 BT_ERR("Bt core call failed");
1501 BT_ERR("EnableAdapterLE Failed %s", error->message);
1502 g_clear_error(&error);
1505 g_variant_unref(result);
1506 /* Terminate myself */
1507 if (_bt_adapter_get_status() == BT_DEACTIVATED)
1508 g_idle_add((GSourceFunc)_bt_terminate_service, NULL);
1509 return BLUETOOTH_ERROR_INTERNAL;
1513 g_variant_unref(result);
1515 _bt_adapter_start_le_enable_timer();
1517 if (status == BT_ACTIVATED) {
1518 _bt_adapter_set_le_status(BT_LE_ACTIVATED);
1519 __bt_set_le_enabled();
1521 BT_DBG("le status : %d", _bt_adapter_get_le_status());
1523 return BLUETOOTH_ERROR_NONE;
1526 int _bt_disable_adapter_le(void)
1530 bt_le_status_t bt_le_state;
1532 GError *error = NULL;
1534 bt_le_state = _bt_adapter_get_le_status();
1535 if (bt_le_state == BT_LE_DEACTIVATING) {
1536 BT_DBG("Disabling in progress");
1537 return BLUETOOTH_ERROR_IN_PROGRESS;
1540 if (bt_le_state == BT_LE_DEACTIVATED) {
1541 BT_DBG("Already disabled");
1542 return BLUETOOTH_ERROR_DEVICE_NOT_ENABLED;
1545 _bt_adapter_set_le_status(BT_LE_DEACTIVATING);
1547 proxy = __bt_get_core_proxy();
1549 return BLUETOOTH_ERROR_INTERNAL;
1551 result = g_dbus_proxy_call_sync(proxy,
1554 G_DBUS_CALL_FLAGS_NONE,
1560 if (error != NULL) {
1561 BT_ERR("Bt core call failed (Error: %s)", error->message);
1562 g_clear_error(&error);
1564 BT_ERR("Bt core call failed");
1565 _bt_adapter_set_le_status(BT_LE_ACTIVATED);
1566 return BLUETOOTH_ERROR_INTERNAL;
1569 g_variant_unref(result);
1570 _bt_set_le_disabled(BLUETOOTH_ERROR_NONE);
1571 BT_DBG("le status : %d", _bt_adapter_get_le_status());
1573 return BLUETOOTH_ERROR_NONE;
1576 int _bt_get_local_address(bluetooth_device_address_t *local_address)
1580 GError *error = NULL;
1581 const char *address;
1585 BT_CHECK_PARAMETER(local_address, return);
1587 proxy = _bt_get_adapter_properties_proxy();
1588 retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
1590 result = g_dbus_proxy_call_sync(proxy,
1592 g_variant_new("(ss)", BT_ADAPTER_INTERFACE,
1594 G_DBUS_CALL_FLAGS_NONE,
1600 BT_ERR("Failed to get local address");
1601 if (error != NULL) {
1602 BT_ERR("Failed to get local address (Error: %s)", error->message);
1603 g_clear_error(&error);
1605 return BLUETOOTH_ERROR_INTERNAL;
1608 g_variant_get(result, "(v)", &temp);
1609 address = g_variant_get_string(temp, NULL);
1610 BT_DBG("Address:%s", address);
1613 _bt_convert_addr_string_to_type(local_address->addr, address);
1615 return BLUETOOTH_ERROR_INTERNAL;
1618 g_variant_unref(result);
1619 g_variant_unref(temp);
1620 return BLUETOOTH_ERROR_NONE;
1623 int _bt_get_local_version(bluetooth_version_t *local_version)
1626 const char *ver = NULL;
1628 int ret = BLUETOOTH_ERROR_NONE;
1632 BT_CHECK_PARAMETER(local_version, return);
1634 GError *error = NULL;
1636 proxy = _bt_get_adapter_properties_proxy();
1637 retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
1639 result = g_dbus_proxy_call_sync(proxy,
1641 g_variant_new("(ss)", BT_ADAPTER_INTERFACE,
1643 G_DBUS_CALL_FLAGS_NONE,
1649 if (error != NULL) {
1650 BT_ERR("Failed to get local version (Error: %s)", error->message);
1651 g_clear_error(&error);
1653 BT_ERR("Failed to get local version");
1654 return BLUETOOTH_ERROR_INTERNAL;
1657 g_variant_get(result, "(v)", &temp);
1658 ver = g_variant_get_string(temp, NULL);
1659 BT_DBG("VERSION: %s", ver);
1661 if (ver && (strlen(ver) > 0)) {
1662 /* Check the utf8 valitation & Fill the NULL in the invalid location*/
1663 if (!g_utf8_validate(ver, -1, (const char **)&ptr))
1666 g_strlcpy(local_version->version, ver,
1667 BLUETOOTH_VERSION_LENGTH_MAX + 1);
1670 ret = BLUETOOTH_ERROR_INTERNAL;
1673 g_variant_unref(result);
1674 g_variant_unref(temp);
1678 int _bt_get_local_name(bluetooth_device_name_t *local_name)
1681 const char *name = NULL;
1683 int ret = BLUETOOTH_ERROR_NONE;
1686 GError *error = NULL;
1688 BT_CHECK_PARAMETER(local_name, return);
1690 proxy = _bt_get_adapter_properties_proxy();
1691 retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
1693 result = g_dbus_proxy_call_sync(proxy,
1695 g_variant_new("(ss)", BT_ADAPTER_INTERFACE,
1697 G_DBUS_CALL_FLAGS_NONE,
1703 if (error != NULL) {
1704 BT_ERR("Failed to get local name (Error: %s)", error->message);
1705 g_clear_error(&error);
1707 BT_ERR("Failed to get local name");
1708 return BLUETOOTH_ERROR_INTERNAL;
1711 g_variant_get(result, "(v)", &temp);
1712 name = g_variant_get_string(temp, NULL);
1713 BT_DBG("LOCAL NAME:%s", name);
1715 if (name && (strlen(name) > 0)) {
1716 /* Check the utf8 valitation & Fill the NULL in the invalid location*/
1717 if (!g_utf8_validate(name, -1, (const char **)&ptr))
1720 g_strlcpy(local_name->name, name,
1721 BLUETOOTH_DEVICE_NAME_LENGTH_MAX + 1);
1723 ret = BLUETOOTH_ERROR_INTERNAL;
1725 g_variant_unref(result);
1726 g_variant_unref(temp);
1730 int _bt_set_local_name(char *local_name)
1733 GError *error = NULL;
1737 BT_CHECK_PARAMETER(local_name, return);
1739 proxy = _bt_get_adapter_properties_proxy();
1741 retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
1743 if (!g_utf8_validate(local_name, -1, (const char **)&ptr))
1746 result = g_dbus_proxy_call_sync(proxy,
1748 g_variant_new("(ssv)", BT_ADAPTER_INTERFACE,
1749 "Alias", g_variant_new("s", local_name)),
1750 G_DBUS_CALL_FLAGS_NONE,
1756 if (error != NULL) {
1757 BT_ERR("Failed to set Alias (Error: %s)", error->message);
1758 g_clear_error(&error);
1760 BT_ERR("Failed to set Alias");
1761 return BLUETOOTH_ERROR_INTERNAL;
1764 g_variant_unref(result);
1765 return BLUETOOTH_ERROR_NONE;
1768 int _bt_is_service_used(char *service_uuid, gboolean *used)
1771 GError *error = NULL;
1772 int ret = BLUETOOTH_ERROR_NONE;
1775 GVariantIter *iter = NULL;
1779 BT_CHECK_PARAMETER(service_uuid, return);
1780 BT_CHECK_PARAMETER(used, return);
1782 proxy = _bt_get_adapter_properties_proxy();
1783 retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
1785 result = g_dbus_proxy_call_sync(proxy,
1787 g_variant_new("(ss)", BT_ADAPTER_INTERFACE,
1789 G_DBUS_CALL_FLAGS_NONE,
1795 if (error != NULL) {
1796 BT_ERR("Failed to get UUIDs (Error: %s)", error->message);
1797 g_clear_error(&error);
1799 BT_ERR("Failed to get UUIDs");
1800 return BLUETOOTH_ERROR_INTERNAL;
1803 g_variant_get(result, "(v)", &value);
1804 g_variant_get(value, "as", &iter);
1806 BT_ERR("Failed to get UUIDs(%s)", service_uuid);
1808 g_variant_unref(result);
1809 g_variant_unref(value);
1813 while (g_variant_iter_loop(iter, "s", &uuid)) {
1814 if (strcasecmp(uuid, service_uuid) == 0) {
1824 g_variant_iter_free(iter);
1825 g_variant_unref(value);
1826 g_variant_unref(result);
1827 BT_DBG("Service Used? %d", *used);
1831 static gboolean __bt_get_discoverable_property(void)
1834 gboolean discoverable_v;
1835 GError *error = NULL;
1839 proxy = _bt_get_adapter_properties_proxy();
1840 retv_if(proxy == NULL, FALSE);
1842 result = g_dbus_proxy_call_sync(proxy,
1844 g_variant_new("(ss)", BT_ADAPTER_INTERFACE,
1846 G_DBUS_CALL_FLAGS_NONE,
1852 if (error != NULL) {
1853 BT_ERR("Failed to get Discoverable property (Error: %s)", error->message);
1854 g_clear_error(&error);
1856 BT_ERR("Failed to get Discoverable property");
1857 return BLUETOOTH_ERROR_INTERNAL;
1860 g_variant_get(result, "(v)", &temp);
1861 discoverable_v = g_variant_get_boolean(temp);
1862 BT_DBG("discoverable_v:%d", discoverable_v);
1864 g_variant_unref(result);
1865 g_variant_unref(temp);
1867 return discoverable_v;
1870 int _bt_get_discoverable_mode(int *mode)
1872 gboolean discoverable;
1873 unsigned int timeout;
1875 BT_CHECK_PARAMETER(mode, return);
1877 discoverable = __bt_get_discoverable_property();
1878 timeout = _bt_get_discoverable_timeout_property();
1880 if (discoverable == TRUE) {
1882 *mode = BLUETOOTH_DISCOVERABLE_MODE_GENERAL_DISCOVERABLE;
1884 *mode = BLUETOOTH_DISCOVERABLE_MODE_TIME_LIMITED_DISCOVERABLE;
1886 *mode = BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE;
1888 return BLUETOOTH_ERROR_NONE;
1892 int _bt_set_discoverable_mode(int discoverable_mode, int timeout)
1894 int ret = BLUETOOTH_ERROR_NONE;
1897 GError *error = NULL;
1901 proxy = _bt_get_adapter_properties_proxy();
1903 retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
1905 #ifdef TIZEN_DPM_ENABLE
1906 if (discoverable_mode != BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE &&
1907 _bt_dpm_get_bluetooth_limited_discoverable_state() == DPM_RESTRICTED) {
1908 _bt_launch_dpm_popup("DPM_POLICY_DISABLE_BT_HANDSFREE");
1909 return BLUETOOTH_ERROR_ACCESS_DENIED;
1911 if (discoverable_mode != BLUETOOTH_DISCOVERABLE_MODE_GENERAL_DISCOVERABLE &&
1912 _bt_dpm_get_bluetooth_limited_discoverable_state() == DPM_RESTRICTED) {
1913 _bt_launch_dpm_popup("DPM_POLICY_DISABLE_BT");
1914 return BLUETOOTH_ERROR_ACCESS_DENIED;
1918 switch (discoverable_mode) {
1919 case BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE:
1924 case BLUETOOTH_DISCOVERABLE_MODE_GENERAL_DISCOVERABLE:
1929 case BLUETOOTH_DISCOVERABLE_MODE_TIME_LIMITED_DISCOVERABLE:
1934 return BLUETOOTH_ERROR_INVALID_PARAM;
1937 BT_INFO("Req. discoverable_mode : %d, timeout : %d",
1938 discoverable_mode, timeout);
1940 result = g_dbus_proxy_call_sync(proxy,
1942 g_variant_new("(ssv)", BT_ADAPTER_INTERFACE,
1943 "Connectable", g_variant_new("b", pg_scan)),
1944 G_DBUS_CALL_FLAGS_NONE,
1950 if (error != NULL) {
1951 BT_ERR("Failed to set connectable property (Error: %s)", error->message);
1952 g_clear_error(&error);
1954 BT_ERR("Failed to set connectable property");
1955 return BLUETOOTH_ERROR_INTERNAL;
1957 g_variant_unref(result);
1958 result = g_dbus_proxy_call_sync(proxy,
1960 g_variant_new("(ssv)", BT_ADAPTER_INTERFACE, "Discoverable",
1961 g_variant_new("b", inq_scan)),
1962 G_DBUS_CALL_FLAGS_NONE,
1968 if (error != NULL) {
1969 BT_ERR("Failed to set Discoverable property (Error: %s)", error->message);
1970 g_clear_error(&error);
1972 BT_ERR("Failed to set Discoverable property");
1973 return BLUETOOTH_ERROR_INTERNAL;
1975 g_variant_unref(result);
1976 result = g_dbus_proxy_call_sync(proxy,
1978 g_variant_new("(ssv)", BT_ADAPTER_INTERFACE,
1979 "DiscoverableTimeout", g_variant_new("u", timeout)),
1980 G_DBUS_CALL_FLAGS_NONE,
1986 if (error != NULL) {
1987 BT_ERR("Failed to set DiscoverableTimeout property (Error: %s)", error->message);
1988 g_clear_error(&error);
1990 BT_ERR("Failed to set DiscoverableTimeout property");
1991 return BLUETOOTH_ERROR_INTERNAL;
1994 if (discoverable_mode == BLUETOOTH_DISCOVERABLE_MODE_GENERAL_DISCOVERABLE)
1997 ret = __bt_set_visible_time(timeout);
1999 g_variant_unref(result);
2004 int _bt_start_discovery(void)
2007 GError *error = NULL;
2010 if (_bt_is_discovering() == TRUE) {
2011 BT_ERR("BT is already in discovering");
2012 return BLUETOOTH_ERROR_IN_PROGRESS;
2013 } else if (_bt_is_device_creating() == TRUE) {
2014 BT_ERR("Bonding device is going on");
2015 return BLUETOOTH_ERROR_DEVICE_BUSY;
2018 proxy = _bt_get_adapter_proxy();
2019 retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
2021 result = g_dbus_proxy_call_sync(proxy,
2024 G_DBUS_CALL_FLAGS_NONE,
2030 if (error != NULL) {
2031 BT_ERR("StartDiscovery failed (Error: %s)", error->message);
2032 g_clear_error(&error);
2034 BT_ERR("StartDiscovery failed");
2035 return BLUETOOTH_ERROR_INTERNAL;
2038 is_discovering = TRUE;
2039 cancel_by_user = FALSE;
2040 /* discovery status will be change in event */
2041 g_variant_unref(result);
2042 return BLUETOOTH_ERROR_NONE;
2045 int _bt_start_custom_discovery(bt_discovery_role_type_t role)
2049 GError *error = NULL;
2050 const gchar *disc_type;
2052 if (_bt_is_discovering() == TRUE) {
2053 BT_ERR("BT is already in discovering");
2054 return BLUETOOTH_ERROR_IN_PROGRESS;
2057 proxy = _bt_get_adapter_proxy();
2058 retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
2060 if (role == DISCOVERY_ROLE_BREDR)
2061 disc_type = "BREDR";
2062 else if (role == DISCOVERY_ROLE_LE)
2064 else if (role == DISCOVERY_ROLE_LE_BREDR)
2065 disc_type = "LE_BREDR";
2067 return BLUETOOTH_ERROR_INVALID_PARAM;
2069 result = g_dbus_proxy_call_sync(proxy,
2070 "StartCustomDiscovery",
2071 g_variant_new("s", disc_type),
2072 G_DBUS_CALL_FLAGS_NONE,
2078 if (error != NULL) {
2079 BT_ERR("StartCustomDiscovery failed (Error: %s)", error->message);
2080 g_clear_error(&error);
2082 BT_ERR("StartCustomDiscovery failed");
2083 return BLUETOOTH_ERROR_INTERNAL;
2086 is_discovering = TRUE;
2087 cancel_by_user = FALSE;
2088 /* discovery status will be change in event */
2089 g_variant_unref(result);
2090 return BLUETOOTH_ERROR_NONE;
2093 int _bt_cancel_discovery(void)
2096 GError *error = NULL;
2099 if (_bt_is_discovering() == FALSE) {
2100 BT_ERR("BT is not in discovering");
2101 return BLUETOOTH_ERROR_NOT_IN_OPERATION;
2104 proxy = _bt_get_adapter_proxy();
2105 retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
2107 result = g_dbus_proxy_call_sync(proxy,
2110 G_DBUS_CALL_FLAGS_NONE,
2116 if (error != NULL) {
2117 BT_ERR("StopDiscovery failed (Error: %s)", error->message);
2118 g_clear_error(&error);
2120 BT_ERR("StopDiscovery failed");
2121 return BLUETOOTH_ERROR_INTERNAL;
2124 cancel_by_user = TRUE;
2125 /* discovery status will be change in event */
2126 g_variant_unref(result);
2127 return BLUETOOTH_ERROR_NONE;
2130 gboolean _bt_is_discovering(void)
2132 return is_discovering;
2135 gboolean _bt_is_connectable(void)
2138 GError *error = NULL;
2139 gboolean is_connectable = FALSE;
2143 proxy = _bt_get_adapter_properties_proxy();
2144 retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
2146 result = g_dbus_proxy_call_sync(proxy,
2148 g_variant_new("(ss)", BT_ADAPTER_INTERFACE,
2150 G_DBUS_CALL_FLAGS_NONE,
2156 if (error != NULL) {
2157 BT_ERR("Failed to get connectable property (Error: %s)", error->message);
2158 g_clear_error(&error);
2160 BT_ERR("Failed to get connectable property");
2161 return BLUETOOTH_ERROR_INTERNAL;
2164 g_variant_get(result, "(v)", &temp);
2165 is_connectable = g_variant_get_boolean(temp);
2166 BT_DBG("discoverable_v:%d", is_connectable);
2168 g_variant_unref(result);
2169 g_variant_unref(temp);
2171 BT_INFO("Get connectable [%d]", is_connectable);
2172 return is_connectable;
2175 int _bt_set_connectable(gboolean is_connectable)
2178 GError *error = NULL;
2181 if (__bt_is_factory_test_mode()) {
2182 BT_ERR("Unable to set connectable in factory binary !!");
2183 return BLUETOOTH_ERROR_NOT_SUPPORT;
2186 proxy = _bt_get_adapter_properties_proxy();
2188 retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
2190 result = g_dbus_proxy_call_sync(proxy,
2192 g_variant_new("(ssv)", BT_ADAPTER_INTERFACE, "Connectable",
2193 g_variant_new("b", is_connectable)),
2194 G_DBUS_CALL_FLAGS_NONE,
2200 if (error != NULL) {
2201 BT_ERR("Failed to set connectable property (Error: %s)", error->message);
2202 g_clear_error(&error);
2204 BT_ERR("Failed to set connectable property");
2205 return BLUETOOTH_ERROR_INTERNAL;
2208 BT_INFO("Set connectable [%d]", is_connectable);
2209 g_variant_unref(result);
2210 return BLUETOOTH_ERROR_NONE;
2213 gboolean _bt_get_discovering_property(bt_discovery_role_type_t discovery_type)
2216 gboolean discovering_v;
2217 GError *error = NULL;
2218 char *discovering_type = NULL;
2222 proxy = _bt_get_adapter_properties_proxy();
2223 retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
2225 if (discovery_type == DISCOVERY_ROLE_BREDR)
2226 discovering_type = "Discovering";
2227 else if (discovery_type == DISCOVERY_ROLE_LE)
2228 discovering_type = "LEDiscovering";
2230 result = g_dbus_proxy_call_sync(proxy,
2232 g_variant_new("(ss)", BT_ADAPTER_INTERFACE,
2234 G_DBUS_CALL_FLAGS_NONE,
2240 if (error != NULL) {
2241 BT_ERR("Failed to get discovering property (Error: %s)", error->message);
2242 g_clear_error(&error);
2244 BT_ERR("Failed to get discovering property");
2245 return BLUETOOTH_ERROR_INTERNAL;
2248 g_variant_get(result, "(v)", &temp);
2249 discovering_v = g_variant_get_boolean(temp);
2250 BT_DBG("discoverable_v:%d", discovering_v);
2252 g_variant_unref(result);
2253 g_variant_unref(temp);
2255 return discovering_v;
2258 unsigned int _bt_get_discoverable_timeout_property(void)
2261 unsigned int timeout_v;
2262 GError *error = NULL;
2266 proxy = _bt_get_adapter_properties_proxy();
2267 retv_if(proxy == NULL, 0);
2269 result = g_dbus_proxy_call_sync(proxy,
2271 g_variant_new("(ss)", BT_ADAPTER_INTERFACE,
2272 "DiscoverableTimeout"),
2273 G_DBUS_CALL_FLAGS_NONE,
2279 BT_ERR("Fail to get discoverable timeout");
2280 if (error != NULL) {
2281 BT_ERR("Fail to get discoverable timeout (Error: %s)", error->message);
2282 g_clear_error(&error);
2287 g_variant_get(result, "(v)", &temp);
2288 timeout_v = g_variant_get_uint32(temp);
2289 BT_DBG("discoverable_v:%d", timeout_v);
2291 g_variant_unref(result);
2292 g_variant_unref(temp);
2297 static bluetooth_device_info_t *__bt_parse_device_info(GVariantIter *item_iter)
2299 bluetooth_device_info_t *dev_info;
2302 GByteArray *manufacturer_data = NULL;
2304 GVariantIter *char_value_iter;
2306 dev_info = g_malloc0(sizeof(bluetooth_device_info_t));
2308 while (g_variant_iter_loop(item_iter, "{sv}", &key, &value)) {
2313 if (!g_strcmp0(key, "Address")) {
2314 const char *address = NULL;
2315 address = g_variant_get_string(value, NULL);
2316 _bt_convert_addr_string_to_type(dev_info->device_address.addr,
2318 } else if (!g_strcmp0(key, "Class")) {
2320 cod = g_variant_get_uint32(value);
2321 _bt_divide_device_class(&dev_info->device_class, cod);
2322 } else if (!g_strcmp0(key, "Name")) {
2323 const char *name = NULL;
2324 name = g_variant_get_string(value, NULL);
2325 /* If there is no Alias */
2326 if (strlen(dev_info->device_name.name) == 0) {
2327 g_strlcpy(dev_info->device_name.name, name,
2328 BLUETOOTH_DEVICE_NAME_LENGTH_MAX+1);
2330 } else if (!g_strcmp0(key, "Alias")) {
2331 const char *alias = NULL;
2332 alias = g_variant_get_string(value, NULL);
2333 /* Overwrite the name */
2335 memset(dev_info->device_name.name, 0x00,
2336 BLUETOOTH_DEVICE_NAME_LENGTH_MAX+1);
2337 g_strlcpy(dev_info->device_name.name, alias,
2338 BLUETOOTH_DEVICE_NAME_LENGTH_MAX+1);
2340 } else if (!g_strcmp0(key, "Connected")) {
2341 dev_info->connected = g_variant_get_byte(value);
2342 } else if (!g_strcmp0(key, "Paired")) {
2343 dev_info->paired = g_variant_get_boolean(value);
2344 } else if (!g_strcmp0(key, "Trusted")) {
2345 dev_info->trust = g_variant_get_boolean(value);
2346 } else if (!g_strcmp0(key, "RSSI")) {
2347 dev_info->rssi = g_variant_get_int16(value);
2348 } else if (!g_strcmp0(key, "UUIDs")) {
2354 dev_info->service_index = 0;
2355 g_variant_get(value, "as", &iter);
2356 while (g_variant_iter_loop(iter, "s", &uuid)) {
2357 g_strlcpy(dev_info->uuids[i], uuid, BLUETOOTH_UUID_STRING_MAX);
2358 parts = g_strsplit(uuid, "-", -1);
2360 if (parts == NULL || parts[0] == NULL) {
2365 dev_info->service_list_array[i] = g_ascii_strtoull(parts[0], NULL, 16);
2370 dev_info->service_index = i;
2371 g_variant_iter_free(iter);
2372 } else if (strcasecmp(key, "ManufacturerDataLen") == 0) {
2373 dev_info->manufacturer_data.data_len = g_variant_get_uint16(value);
2374 } else if (strcasecmp(key, "ManufacturerData") == 0) {
2375 manufacturer_data = g_byte_array_new();
2376 g_variant_get(value, "ay", &char_value_iter);
2378 while (g_variant_iter_loop(char_value_iter, "y", &char_value))
2379 g_byte_array_append(manufacturer_data, &char_value, 1);
2381 if (manufacturer_data) {
2382 if (manufacturer_data->len > 0) {
2383 memcpy(dev_info->manufacturer_data.data, manufacturer_data->data, manufacturer_data->len);
2386 g_variant_iter_free(char_value_iter);
2387 g_byte_array_free(manufacturer_data, TRUE);
2394 static void __bt_extract_device_info(GVariantIter *iter,
2397 bluetooth_device_info_t *dev_info = NULL;
2398 char *object_path = NULL;
2399 GVariantIter *interface_iter;
2400 GVariantIter *svc_iter;
2401 char *interface_str = NULL;
2403 /* Parse the signature: oa{sa{sv}}} */
2404 while (g_variant_iter_loop(iter, "{&oa{sa{sv}}}", &object_path,
2407 if (object_path == NULL)
2410 while (g_variant_iter_loop(interface_iter, "{sa{sv}}",
2411 &interface_str, &svc_iter)) {
2412 if (g_strcmp0(interface_str, "org.bluez.Device1") == 0) {
2413 BT_DBG("Found a device: %s", object_path);
2414 dev_info = __bt_parse_device_info(svc_iter);
2416 if (dev_info->paired == TRUE) {
2417 g_array_append_vals(*dev_list, dev_info,
2418 sizeof(bluetooth_device_info_t));
2422 g_free(interface_str);
2423 g_variant_iter_free(svc_iter);
2431 int _bt_get_bonded_devices(GArray **dev_list)
2434 GDBusConnection *conn;
2435 GDBusProxy *manager_proxy;
2436 GVariant *result = NULL;
2437 GVariantIter *iter = NULL;
2438 GError *error = NULL;
2440 conn = _bt_get_system_conn();
2441 retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
2443 manager_proxy = _bt_get_manager_proxy();
2444 retv_if(manager_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
2446 result = g_dbus_proxy_call_sync(manager_proxy, "GetManagedObjects",
2448 G_DBUS_CALL_FLAGS_NONE,
2454 if (error != NULL) {
2455 BT_ERR("Failed to GetManagedObjects (Error: %s)", error->message);
2456 g_clear_error(&error);
2458 BT_ERR("Failed to Failed to GetManagedObjects");
2459 return BLUETOOTH_ERROR_INTERNAL;
2462 /* signature of GetManagedObjects: a{oa{sa{sv}}} */
2463 g_variant_get(result, "(a{oa{sa{sv}}})", &iter);
2465 __bt_extract_device_info(iter, dev_list);
2466 g_variant_iter_free(iter);
2467 g_variant_unref(result);
2470 return BLUETOOTH_ERROR_NONE;
2473 int _bt_get_bonded_device_info(bluetooth_device_address_t *device_address,
2474 bluetooth_device_info_t *dev_info)
2476 char *object_path = NULL;
2477 GDBusProxy *adapter_proxy;
2478 char address[BT_ADDRESS_STRING_SIZE] = { 0 };
2479 int ret = BLUETOOTH_ERROR_NONE;
2481 BT_CHECK_PARAMETER(device_address, return);
2482 BT_CHECK_PARAMETER(dev_info, return);
2484 adapter_proxy = _bt_get_adapter_proxy();
2485 retv_if(adapter_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
2487 _bt_convert_addr_type_to_string(address, device_address->addr);
2489 object_path = _bt_get_device_object_path(address);
2491 retv_if(object_path == NULL, BLUETOOTH_ERROR_NOT_PAIRED);
2493 ret = __bt_get_bonded_device_info(object_path, dev_info);
2494 g_free(object_path);
2499 int _bt_get_timeout_value(int *timeout)
2501 time_t current_time;
2504 /* Take current time */
2505 time(¤t_time);
2506 time_diff = difftime(current_time, visible_timer.start_time);
2508 BT_DBG("Time diff = %d\n", time_diff);
2510 *timeout = visible_timer.timeout - time_diff;
2512 return BLUETOOTH_ERROR_NONE;
2515 int _bt_set_le_privacy(gboolean set_privacy)
2518 GError *error = NULL;
2519 GVariant *result = NULL;
2521 if (__bt_is_factory_test_mode()) {
2522 BT_ERR("Unable to set le privacy in factory binary !!");
2523 return BLUETOOTH_ERROR_NOT_SUPPORT;
2526 if (_bt_adapter_get_status() != BT_ACTIVATED &&
2527 _bt_adapter_get_le_status() != BT_LE_ACTIVATED) {
2528 return BLUETOOTH_ERROR_DEVICE_NOT_ENABLED;
2531 proxy = _bt_get_adapter_proxy();
2532 retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
2534 result = g_dbus_proxy_call_sync(proxy,
2536 g_variant_new("(b)", set_privacy),
2537 G_DBUS_CALL_FLAGS_NONE,
2543 if (error != NULL) {
2544 BT_ERR("Failed to SetLePrivacy (Error: %s)", error->message);
2545 g_clear_error(&error);
2547 BT_ERR("Failed to SetLePrivacy");
2548 return BLUETOOTH_ERROR_INTERNAL;
2551 g_variant_unref(result);
2552 BT_INFO("SetLePrivacy as %d", set_privacy);
2553 return BLUETOOTH_ERROR_NONE;
2556 int _bt_set_manufacturer_data(bluetooth_manufacturer_data_t *m_data)
2559 GError *error = NULL;
2563 GVariantBuilder *builder;
2565 BT_CHECK_PARAMETER(m_data, return);
2567 if (_bt_adapter_get_status() != BT_ACTIVATED &&
2568 _bt_adapter_get_le_status() != BT_LE_ACTIVATED) {
2569 return BLUETOOTH_ERROR_DEVICE_NOT_ENABLED;
2572 proxy = _bt_get_adapter_proxy();
2573 retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
2575 builder = g_variant_builder_new(G_VARIANT_TYPE("ay"));
2577 for (i = 0; i < (m_data->data_len) + 2; i++) {
2578 g_variant_builder_add(builder, "y", m_data->data[i]);
2581 val = g_variant_new("(ay)", builder);
2583 result = g_dbus_proxy_call_sync(proxy,
2584 "SetManufacturerData",
2586 G_DBUS_CALL_FLAGS_NONE,
2590 g_variant_builder_unref(builder);
2592 if (error != NULL) {
2593 BT_ERR("Failed to SetManufacturerData (Error: %s)", error->message);
2594 g_clear_error(&error);
2596 BT_ERR("Failed to SetManufacturerData");
2598 return BLUETOOTH_ERROR_INTERNAL;
2600 builder = g_variant_builder_new(G_VARIANT_TYPE("ay"));
2602 for (i = 0; i < (m_data->data_len) + 2; i++) {
2603 g_variant_builder_add(builder, "y", m_data->data[i]);
2606 val = g_variant_new("(ay)", builder);
2608 _bt_send_event(BT_ADAPTER_EVENT,
2609 BLUETOOTH_EVENT_MANUFACTURER_DATA_CHANGED,
2612 BT_INFO("Set manufacturer data");
2614 g_variant_builder_unref(builder);
2615 g_variant_unref(result);
2617 return BLUETOOTH_ERROR_NONE;
2621 int _bt_get_enable_timer_id(void)