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 const gchar *address = NULL;
295 const gchar *name = 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 address = g_variant_get_string(value, NULL);
353 } else if (!g_strcmp0(key, "Alias")) {
354 name = g_variant_get_string(value, NULL);
355 } else if (!g_strcmp0(key, "Name")) {
357 name = g_variant_get_string(value, NULL);
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);
373 while(g_variant_iter_loop(char_value_iter, "y", &char_value)) {
374 g_byte_array_append(manufacturer_data, &char_value, 1);
376 g_variant_iter_free(char_value_iter);
378 if (manufacturer_data) {
379 if (manufacturer_data->len > 0) {
380 memcpy(dev_info->manufacturer_data.data, manufacturer_data->data,
381 manufacturer_data->len);
386 g_variant_iter_free(property_iter);
388 BT_DBG("trust: %d, paired: %d", trust, paired);
390 g_variant_unref(result);
392 if ((paired == FALSE) && (trust == FALSE)) {
393 return BLUETOOTH_ERROR_NOT_PAIRED;
396 _bt_convert_addr_string_to_type(dev_info->device_address.addr,
399 _bt_divide_device_class(&dev_info->device_class, cod);
401 g_strlcpy(dev_info->device_name.name, name,
402 BLUETOOTH_DEVICE_NAME_LENGTH_MAX+1);
404 dev_info->rssi = rssi;
405 dev_info->trust = trust;
406 dev_info->paired = paired;
407 dev_info->connected = connected;
408 ret = BLUETOOTH_ERROR_NONE;
413 void _bt_set_discovery_status(gboolean mode)
415 is_discovering = mode;
418 void _bt_set_cancel_by_user(gboolean value)
420 cancel_by_user = value;
423 gboolean _bt_get_cancel_by_user(void)
425 return cancel_by_user;
428 void _bt_adapter_set_status(bt_status_t status)
430 BT_INFO("adapter_status changed [%d] -> [%d]", adapter_status, status);
431 adapter_status = status;
434 bt_status_t _bt_adapter_get_status(void)
436 return adapter_status;
439 void _bt_adapter_set_le_status(bt_le_status_t status)
441 BT_INFO("adapter_le_status changed [%d] -> [%d]", adapter_le_status, status);
442 adapter_le_status = status;
445 bt_le_status_t _bt_adapter_get_le_status(void)
447 return adapter_le_status;
450 static void __bt_phone_name_changed_cb(keynode_t *node, void *data)
452 char *phone_name = NULL;
458 if (vconf_keynode_get_type(node) == VCONF_TYPE_STRING) {
459 phone_name = vconf_keynode_get_str(node);
461 if (phone_name && strlen(phone_name) != 0) {
462 if (!g_utf8_validate(phone_name, -1,
463 (const char **)&ptr))
466 _bt_set_local_name(phone_name);
472 static void __bt_set_visible_mode(void)
476 if (vconf_get_int(BT_FILE_VISIBLE_TIME, &timeout) != 0)
477 BT_ERR("Fail to get the timeout value");
479 #ifdef TIZEN_DPM_ENABLE
481 _bt_dpm_get_bluetooth_limited_discoverable_state() == DPM_RESTRICTED) {
482 if (_bt_set_discoverable_mode(
483 BLUETOOTH_DISCOVERABLE_MODE_GENERAL_DISCOVERABLE,
484 timeout) != BLUETOOTH_ERROR_NONE) {
485 if (vconf_set_int(BT_FILE_VISIBLE_TIME, 0) != 0)
486 BT_ERR("Set vconf failed");
489 if (_bt_set_discoverable_mode(
490 BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE,
491 timeout) != BLUETOOTH_ERROR_NONE) {
492 BT_ERR("Set connectable mode failed");
497 if (_bt_set_discoverable_mode(
498 BLUETOOTH_DISCOVERABLE_MODE_GENERAL_DISCOVERABLE,
499 timeout) != BLUETOOTH_ERROR_NONE) {
500 if (vconf_set_int(BT_FILE_VISIBLE_TIME, 0) != 0)
501 BT_ERR("Set vconf failed");
504 if (_bt_set_discoverable_mode(
505 BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE,
506 timeout) != BLUETOOTH_ERROR_NONE) {
507 BT_ERR("Set connectable mode failed");
514 static void __bt_set_local_name(void)
516 char *phone_name = NULL;
519 phone_name = vconf_get_str(VCONFKEY_SETAPPL_DEVICE_NAME_STR);
524 if (strlen(phone_name) != 0) {
525 if (!g_utf8_validate(phone_name, -1, (const char **)&ptr))
528 _bt_set_local_name(phone_name);
533 static int __bt_set_enabled(void)
536 int adapter_status = BT_ADAPTER_DISABLED;
537 int result = BLUETOOTH_ERROR_NONE;
539 _bt_check_adapter(&adapter_status);
541 if (adapter_status == BT_ADAPTER_DISABLED) {
542 BT_ERR("Bluetoothd is not running");
543 return BLUETOOTH_ERROR_INTERNAL;
547 __bt_set_visible_mode();
550 if (_bt_set_discoverable_mode(
551 BLUETOOTH_DISCOVERABLE_MODE_GENERAL_DISCOVERABLE, 0)!= BLUETOOTH_ERROR_NONE)
552 BT_ERR("Fail to set discoverable mode");
555 __bt_set_local_name();
557 /* Update Bluetooth Status to notify other modules */
558 if (vconf_set_int(VCONFKEY_BT_STATUS, VCONFKEY_BT_STATUS_ON) != 0)
559 BT_ERR("Set vconf failed\n");
561 if (vconf_set_int(VCONFKEY_BT_DEVICE, VCONFKEY_BT_DEVICE_NONE) != 0)
562 BT_ERR("Set vconf failed\n");
564 if (_bt_eventsystem_set_value(SYS_EVENT_BT_STATE, EVT_KEY_BT_STATE,
565 EVT_VAL_BT_ON) != ES_R_OK)
566 BT_ERR("Fail to set value");
569 /* Send enabled event to API */
570 _bt_send_event(BT_ADAPTER_EVENT, BLUETOOTH_EVENT_ENABLED,
571 g_variant_new("(i)", result));
574 return BLUETOOTH_ERROR_NONE;
577 void _bt_set_disabled(int result)
579 int power_off_status = 0;
582 int pm_ignore_mode = 0;
584 ret = vconf_get_int(VCONFKEY_SYSMAN_POWER_OFF_STATUS, &power_off_status);
585 BT_DBG("ret : %d, power_off_status : %d", ret, power_off_status);
587 ret_pm_ignore = vconf_get_int(VCONFKEY_PM_KEY_IGNORE, &pm_ignore_mode);
589 /* Update the vconf BT status in normal Deactivation case only */
590 if (ret == 0 && power_off_status == VCONFKEY_SYSMAN_POWER_OFF_NONE &&
591 ret_pm_ignore == 0 && pm_ignore_mode != VCONFKEY_PM_KEY_LOCK) {
593 BT_DBG("Update vconf for BT normal Deactivation");
595 if (result == BLUETOOTH_ERROR_TIMEOUT)
596 if (vconf_set_int(BT_OFF_DUE_TO_TIMEOUT, 1) != 0 )
597 BT_ERR("Set vconf failed");
599 /* Update Bluetooth Status to notify other modules */
600 if (vconf_set_int(VCONFKEY_BT_STATUS, VCONFKEY_BT_STATUS_OFF) != 0)
601 BT_ERR("Set vconf failed");
603 if (_bt_eventsystem_set_value(SYS_EVENT_BT_STATE, EVT_KEY_BT_STATE,
604 EVT_VAL_BT_OFF) != ES_R_OK)
605 BT_ERR("Fail to set value");
608 if (vconf_set_int(VCONFKEY_BT_DEVICE, VCONFKEY_BT_DEVICE_NONE) != 0)
609 BT_ERR("Set vconf failed\n");
611 _bt_adapter_set_status(BT_DEACTIVATED);
613 if (_bt_adapter_get_le_status() != BT_LE_DEACTIVATED) {
614 /* Send disabled event */
615 _bt_send_event(BT_ADAPTER_EVENT, BLUETOOTH_EVENT_DISABLED,
616 g_variant_new("(i)", result));
619 BT_INFO("Adapter disabled");
622 static int __bt_set_le_enabled(void)
625 int result = BLUETOOTH_ERROR_NONE;
628 __bt_set_local_name();
630 /* Update Bluetooth Status to notify other modules */
631 if (vconf_set_int(VCONFKEY_BT_LE_STATUS, VCONFKEY_BT_LE_STATUS_ON) != 0)
632 BT_ERR("Set vconf failed\n");
634 if (_bt_eventsystem_set_value(SYS_EVENT_BT_STATE, EVT_KEY_BT_LE_STATE,
635 EVT_VAL_BT_LE_ON) != ES_R_OK)
636 BT_ERR("Fail to set value");
638 /* Send enabled event to API */
640 _bt_send_event(BT_ADAPTER_EVENT, BLUETOOTH_EVENT_ENABLED,
641 DBUS_TYPE_INT32, &result, DBUS_TYPE_INVALID);
643 status = _bt_adapter_get_status();
644 if (status == BT_DEACTIVATED) {
645 BT_INFO("BREDR is off, turn off PSCAN");
646 _bt_set_connectable(FALSE);
648 if (le_timer_id > 0) {
649 g_source_remove(le_timer_id);
653 /* Send enabled event to API */
654 _bt_send_event(BT_LE_ADAPTER_EVENT, BLUETOOTH_EVENT_LE_ENABLED,
655 g_variant_new("(i)", result));
658 return BLUETOOTH_ERROR_NONE;
661 void _bt_set_le_disabled(int result)
663 int power_off_status;
666 ret = vconf_get_int(VCONFKEY_SYSMAN_POWER_OFF_STATUS, &power_off_status);
667 BT_DBG("ret : %d", ret);
668 BT_DBG("power_off_status : %d", power_off_status);
670 /* Update Bluetooth Status to notify other modules */
671 BT_DBG("Update vconf for BT LE normal Deactivation");
672 if (vconf_set_int(VCONFKEY_BT_LE_STATUS, VCONFKEY_BT_LE_STATUS_OFF) != 0)
673 BT_ERR("Set vconf failed\n");
674 _bt_adapter_set_le_status(BT_LE_DEACTIVATED);
676 if (_bt_eventsystem_set_value(SYS_EVENT_BT_STATE, EVT_KEY_BT_LE_STATE,
677 EVT_VAL_BT_LE_OFF) != ES_R_OK)
678 BT_ERR("Fail to set value");
680 /* Send disabled event */
681 _bt_send_event(BT_LE_ADAPTER_EVENT, BLUETOOTH_EVENT_LE_DISABLED,
682 g_variant_new_int32(result));
685 void *_bt_get_adapter_agent(void)
687 return adapter_agent;
690 int _bt_enable_core(void)
694 GError *error = NULL;
696 proxy = __bt_get_core_proxy();
697 retv_if(!proxy, BLUETOOTH_ERROR_INTERNAL);
699 /* Clean up the process */
700 result = g_dbus_proxy_call_sync(proxy,
703 G_DBUS_CALL_FLAGS_NONE,
710 BT_ERR("Bt core call failed(Error: %s)", error->message);
711 g_clear_error(&error);
713 BT_ERR("Bt core call failed");
714 return BLUETOOTH_ERROR_INTERNAL;
717 g_variant_unref(result);
718 return BLUETOOTH_ERROR_NONE;
721 #if defined(TIZEN_TELEPHONY_ENABLED) || (!defined(TIZEN_WEARABLE) && defined(ENABLE_TIZEN_2_4))
722 static void __bt_service_flight_ps_mode_cb(keynode_t *node, void *data)
724 gboolean flight_mode = FALSE;
725 int power_saving_mode = 0;
728 DBG_SECURE("key=%s", vconf_keynode_get_name(node));
729 type = vconf_keynode_get_type(node);
730 if (type == VCONF_TYPE_BOOL) {
731 flight_mode = vconf_keynode_get_bool(node);
732 if (flight_mode != TRUE) {
733 BT_ERR("Ignore the event");
736 } else if (type == VCONF_TYPE_INT) {
737 power_saving_mode = vconf_keynode_get_int(node);
738 if (power_saving_mode != 2) {
739 BT_ERR("Ignore the event");
743 BT_ERR("Invaild vconf key type : %d", type);
751 void _bt_service_register_vconf_handler(void)
755 #ifdef TIZEN_TELEPHONY_ENABLED
756 if (vconf_notify_key_changed(VCONFKEY_TELEPHONY_FLIGHT_MODE,
757 (vconf_callback_fn)__bt_service_flight_ps_mode_cb, NULL) < 0)
758 BT_ERR("Unable to register key handler");
760 BT_DBG("Telephony is disabled");
763 #ifndef TIZEN_WEARABLE
764 #ifdef ENABLE_TIZEN_2_4
765 if (vconf_notify_key_changed(VCONFKEY_SETAPPL_PSMODE,
766 (vconf_callback_fn)__bt_service_flight_ps_mode_cb, NULL) < 0)
767 BT_ERR("Unable to register key handler");
772 void _bt_service_unregister_vconf_handler(void)
776 #ifdef TIZEN_TELEPHONY_ENABLED
777 vconf_ignore_key_changed(VCONFKEY_TELEPHONY_FLIGHT_MODE,
778 (vconf_callback_fn)__bt_service_flight_ps_mode_cb);
781 #ifndef TIZEN_WEARABLE
782 #ifdef ENABLE_TIZEN_2_4
783 vconf_ignore_key_changed(VCONFKEY_SETAPPL_PSMODE,
784 (vconf_callback_fn)__bt_service_flight_ps_mode_cb);
789 static void __bt_state_event_handler(const char *event_name, bundle *data, void *user_data)
791 #ifdef ENABLE_TIZEN_2_4
792 const char *bt_status = NULL;
793 const char *bt_le_status = NULL;
794 BT_DBG("bt state set event(%s) received", event_name);
795 bt_status = bundle_get_val(data, EVT_KEY_BT_STATE);
796 BT_DBG("bt_state: (%s)", bt_status);
798 bt_le_status = bundle_get_val(data, EVT_KEY_BT_LE_STATE);
799 BT_DBG("bt_state: (%s)", bt_le_status);
803 void _bt_handle_adapter_added(void)
807 bt_le_status_t le_status;
811 BT_DBG("g_source is removed");
812 g_source_remove(timer_id);
816 status = _bt_adapter_get_status();
817 le_status = _bt_adapter_get_le_status();
818 BT_DBG("status : %d", status);
819 BT_DBG("le_status : %d", le_status);
821 adapter_agent = _bt_create_agent(BT_ADAPTER_AGENT_PATH, TRUE);
822 if (!adapter_agent) {
823 BT_ERR("Fail to register agent");
827 if (_bt_register_media_player() != BLUETOOTH_ERROR_NONE)
828 BT_ERR("Fail to register media player");
830 if (_bt_register_obex_server() != BLUETOOTH_ERROR_NONE)
831 BT_ERR("Fail to init obex server");
833 #ifdef TIZEN_BT_PAN_NAP_ENABLE
834 if (_bt_network_activate() != BLUETOOTH_ERROR_NONE)
835 BT_ERR("Fail to activate network");
838 /* add the vconf noti handler */
839 ret = vconf_notify_key_changed(VCONFKEY_SETAPPL_DEVICE_NAME_STR,
840 __bt_phone_name_changed_cb, NULL);
842 BT_ERR("Unable to register key handler");
844 if (le_status == BT_LE_ACTIVATING ||
845 status == BT_ACTIVATING) {
846 __bt_set_le_enabled();
847 _bt_adapter_set_le_status(BT_LE_ACTIVATED);
850 if (status == BT_ACTIVATING) {
852 _bt_adapter_set_status(BT_ACTIVATED);
854 #ifdef ENABLE_TIZEN_2_4
858 _bt_service_register_vconf_handler();
861 if (eventsystem_register_event(SYS_EVENT_BT_STATE, &status_reg_id,
862 (eventsystem_handler)__bt_state_event_handler, NULL) != ES_R_OK) {
863 BT_ERR("Fail to register system event");
867 void _bt_handle_adapter_removed(void)
871 _bt_adapter_set_status(BT_DEACTIVATED);
872 #ifdef ENABLE_TIZEN_2_4
876 __bt_visibility_alarm_remove();
878 if (visible_timer.alarm_init) {
880 visible_timer.alarm_init = FALSE;
883 ret = vconf_ignore_key_changed(VCONFKEY_SETAPPL_DEVICE_NAME_STR,
884 (vconf_callback_fn)__bt_phone_name_changed_cb);
886 ERR("vconf_ignore_key_changed failed\n");
889 _bt_destroy_agent(adapter_agent);
890 adapter_agent = NULL;
892 _bt_reliable_terminate_service(NULL);
894 if (eventsystem_unregister_event(status_reg_id) != ES_R_OK) {
895 BT_ERR("Fail to unregister system event");
900 static gboolean __bt_enable_timeout_cb(gpointer user_data)
904 GError *error = NULL;
908 retv_if(_bt_adapter_get_status() == BT_ACTIVATED, FALSE);
910 BT_ERR("EnableAdapter is failed");
912 proxy = __bt_get_core_proxy();
916 /* Clean up the process */
917 result = g_dbus_proxy_call_sync(proxy,
920 G_DBUS_CALL_FLAGS_NONE,
927 BT_ERR("Bt core call failed(Error: %s)", error->message);
928 g_clear_error(&error);
930 BT_ERR("Bt core call failed");
935 g_variant_unref(result);
936 _bt_set_disabled(BLUETOOTH_ERROR_TIMEOUT);
938 _bt_terminate_service(NULL);
943 static gboolean __bt_enable_le_timeout_cb(gpointer user_data)
947 GError *error = NULL;
951 retv_if(_bt_adapter_get_le_status() == BT_LE_ACTIVATED, FALSE);
953 BT_ERR("EnableAdapterLE is failed");
955 proxy = __bt_get_core_proxy();
959 /* Clean up the process */
960 result = g_dbus_proxy_call_sync(proxy,
963 G_DBUS_CALL_FLAGS_NONE,
970 BT_ERR("Bt core call failed(Error: %s)", error->message);
971 g_clear_error(&error);
973 BT_ERR("Bt core call failed");
977 g_variant_unref(result);
978 _bt_adapter_set_le_status(BT_LE_DEACTIVATED);
980 _bt_set_le_disabled(BLUETOOTH_ERROR_TIMEOUT);
982 if (_bt_adapter_get_status() == BT_DEACTIVATED)
983 _bt_terminate_service(NULL);
988 void _bt_adapter_start_le_enable_timer(void)
990 if (le_timer_id > 0) {
991 g_source_remove(le_timer_id);
995 le_timer_id = g_timeout_add(BT_ENABLE_TIMEOUT,
996 __bt_enable_le_timeout_cb, NULL);
1001 void _bt_adapter_start_enable_timer(void)
1004 g_source_remove(timer_id);
1008 timer_id = g_timeout_add(BT_ENABLE_TIMEOUT,
1009 __bt_enable_timeout_cb, NULL);
1015 static gboolean __bt_adapter_enabled_cb(gpointer user_data)
1020 _bt_adapter_set_status(BT_ACTIVATED);
1026 int _bt_enable_adapter(void)
1029 GError *error = NULL;
1031 GVariant *result = NULL;
1032 bt_status_t status = _bt_adapter_get_status();
1033 bt_le_status_t le_status = _bt_adapter_get_le_status();
1037 if (status == BT_ACTIVATING) {
1038 BT_ERR("Enabling in progress");
1039 return BLUETOOTH_ERROR_IN_PROGRESS;
1042 if (status == BT_ACTIVATED) {
1043 BT_ERR("Already enabled");
1044 return BLUETOOTH_ERROR_DEVICE_ALREADY_ENABLED;
1047 if (status == BT_DEACTIVATING || le_status == BT_LE_DEACTIVATING) {
1048 BT_ERR("Disabling in progress");
1049 return BLUETOOTH_ERROR_DEVICE_BUSY;
1052 _bt_adapter_set_status(BT_ACTIVATING);
1056 int adapter_status = BT_ADAPTER_DISABLED;
1058 if (vconf_set_int(VCONFKEY_BT_STATUS, VCONFKEY_BT_STATUS_OFF) != 0)
1059 BT_ERR("Set vconf failed");
1061 _bt_check_adapter(&adapter_status);
1062 if (adapter_status == BT_ADAPTER_ENABLED) {
1063 g_idle_add(__bt_adapter_enabled_cb, NULL);
1064 _bt_adapter_start_enable_timer();
1065 return BLUETOOTH_ERROR_NONE;
1070 proxy = __bt_get_core_proxy();
1072 return BLUETOOTH_ERROR_INTERNAL;
1074 if (le_status == BT_LE_ACTIVATED) {
1075 BT_INFO("LE Already enabled. Just turn on PSCAN");
1076 ret = _bt_set_connectable(TRUE);
1077 if (ret == BLUETOOTH_ERROR_NONE) {
1078 _bt_adapter_set_status(BT_ACTIVATED);
1080 return BLUETOOTH_ERROR_INTERNAL;
1084 result = g_dbus_proxy_call_sync(proxy, "EnableAdapter",
1086 G_DBUS_CALL_FLAGS_NONE, BT_ENABLE_TIMEOUT,
1089 BT_ERR("EnableAdapterLe failed: %s", error->message);
1090 _bt_adapter_set_status(BT_DEACTIVATED);
1091 g_clear_error(&error);
1093 result = g_dbus_proxy_call_sync(proxy,
1096 G_DBUS_CALL_FLAGS_NONE,
1101 if (error != NULL) {
1102 BT_ERR("Bt core call failed(Error: %s)", error->message);
1103 g_clear_error(&error);
1105 g_variant_unref(result);
1106 /* Terminate myself */
1107 g_idle_add((GSourceFunc)_bt_terminate_service, NULL);
1108 return BLUETOOTH_ERROR_INTERNAL;
1110 g_variant_unref(result);
1111 if (le_status == BT_LE_ACTIVATED) {
1114 _bt_adapter_start_enable_timer();
1117 return BLUETOOTH_ERROR_NONE;
1120 static gboolean __bt_disconnect_all(void)
1123 GDBusConnection *conn;
1124 GDBusProxy *dev_proxy;
1125 gboolean ret = FALSE;
1127 GError *error = NULL;
1128 GArray *device_list;
1129 bluetooth_device_info_t info;
1131 char *device_path = NULL;
1132 char address[BT_ADDRESS_STRING_SIZE] = { 0 };
1137 conn = _bt_get_system_gconn();
1139 device_list = g_array_new(FALSE, FALSE, sizeof(gchar));
1141 if (_bt_get_bonded_devices(&device_list)
1142 != BLUETOOTH_ERROR_NONE) {
1143 g_array_free(device_list, TRUE);
1147 size = (device_list->len) / sizeof(bluetooth_device_info_t);
1149 for (i = 0; i < size; i++) {
1151 info = g_array_index(device_list,
1152 bluetooth_device_info_t, i);
1154 if (info.connected != BLUETOOTH_CONNECTED_LINK_NONE) {
1155 BT_DBG("Found Connected device");
1156 _bt_convert_addr_type_to_string(address, info.device_address.addr);
1157 device_path = _bt_get_device_object_path(address);
1158 if (device_path == NULL)
1161 BT_DBG("Disconnecting : %s", device_path);
1163 dev_proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
1167 BT_DEVICE_INTERFACE,
1170 if (dev_proxy == NULL)
1173 result = g_dbus_proxy_call_sync(dev_proxy,
1176 G_DBUS_CALL_FLAGS_NONE,
1182 if (error != NULL) {
1183 BT_ERR("Disconnect call failed(Error: %s)", error->message);
1184 g_clear_error(&error);
1186 BT_ERR("Disconnect call failed");
1187 g_object_unref(dev_proxy);
1191 g_variant_unref(result);
1192 g_object_unref(dev_proxy);
1196 g_array_free(device_list, TRUE);
1201 static gboolean __bt_set_disabled_timeout_cb(gpointer user_data)
1204 _bt_set_disabled(BLUETOOTH_ERROR_NONE);
1209 int __bt_disable_cb(void)
1213 bt_le_status_t le_status;
1216 GError *error = NULL;
1218 _bt_adapter_set_status(BT_DEACTIVATING);
1219 le_status = _bt_adapter_get_le_status();
1220 BT_DBG("le_status : %d", le_status);
1221 if (le_status == BT_LE_ACTIVATED) {
1222 BT_INFO("LE is enabled. Just turn off PSCAN");
1224 if (_bt_is_discovering())
1225 _bt_cancel_discovery();
1227 if (_bt_is_connectable() == FALSE) {
1228 g_timeout_add(100, (GSourceFunc)__bt_set_disabled_timeout_cb, NULL);
1230 ret = _bt_set_connectable(FALSE);
1231 if (ret != BLUETOOTH_ERROR_NONE) {
1232 BT_ERR("_bt_set_connectable fail!");
1233 _bt_adapter_set_status(BT_ACTIVATED);
1234 return BLUETOOTH_ERROR_INTERNAL;
1239 proxy = __bt_get_core_proxy();
1240 retv_if(!proxy, BLUETOOTH_ERROR_INTERNAL);
1242 result = g_dbus_proxy_call_sync(proxy,
1245 G_DBUS_CALL_FLAGS_NONE,
1251 if (error != NULL) {
1252 BT_ERR("Failed to DisableAdapter (Error: %s)", error->message);
1253 g_clear_error(&error);
1255 BT_ERR("Failed to DisableAdapter");
1256 _bt_adapter_set_status(BT_ACTIVATED);
1257 return BLUETOOTH_ERROR_INTERNAL;
1260 g_variant_unref(result);
1261 return BLUETOOTH_ERROR_NONE;
1264 int _bt_disable_adapter(void)
1269 if (_bt_adapter_get_status() == BT_DEACTIVATING) {
1270 BT_DBG("Disabling in progress");
1271 return BLUETOOTH_ERROR_IN_PROGRESS;
1274 if (_bt_adapter_get_status() == BT_DEACTIVATED) {
1275 BT_DBG("Already disabled");
1276 return BLUETOOTH_ERROR_DEVICE_NOT_ENABLED;
1280 g_source_remove(timer_id);
1284 __bt_disconnect_all();
1285 ret = __bt_disable_cb();
1291 int _bt_recover_adapter(void)
1296 GError *error = NULL;
1298 if (_bt_adapter_get_status() == BT_DEACTIVATING) {
1299 BT_DBG("Disabling in progress");
1300 return BLUETOOTH_ERROR_IN_PROGRESS;
1303 if (_bt_adapter_get_status() == BT_DEACTIVATED) {
1304 BT_DBG("Already disabled");
1305 return BLUETOOTH_ERROR_DEVICE_NOT_ENABLED;
1308 _bt_adapter_set_status(BT_DEACTIVATING);
1310 proxy = __bt_get_core_proxy();
1311 retv_if(!proxy, BLUETOOTH_ERROR_INTERNAL);
1313 result = g_dbus_proxy_call_sync(proxy,
1316 G_DBUS_CALL_FLAGS_NONE,
1322 if (error != NULL) {
1323 BT_ERR("Failed to RecoverAdapter (Error: %s)", error->message);
1324 g_clear_error(&error);
1326 BT_ERR("Failed to RecoverAdapter");
1327 return BLUETOOTH_ERROR_INTERNAL;
1330 g_variant_unref(result);
1331 __bt_disconnect_all();
1334 return BLUETOOTH_ERROR_NONE;
1337 int _bt_reset_adapter(void)
1341 GError *error = NULL;
1345 proxy = __bt_get_core_proxy();
1347 return BLUETOOTH_ERROR_INTERNAL;
1349 result = g_dbus_proxy_call_sync(proxy,
1352 G_DBUS_CALL_FLAGS_NONE,
1358 if (error != NULL) {
1359 BT_ERR("Failed to ResetAdapter (Error: %s)", error->message);
1360 g_clear_error(&error);
1362 BT_ERR("Failed to ResetAdapter");
1363 return BLUETOOTH_ERROR_INTERNAL;
1366 g_variant_unref(result);
1367 /* Terminate myself */
1368 if (_bt_adapter_get_status() == BT_DEACTIVATED) {
1369 g_idle_add((GSourceFunc)_bt_terminate_service, NULL);
1372 return BLUETOOTH_ERROR_NONE;
1376 int _bt_check_adapter(int *status)
1379 char *adapter_path = NULL;
1381 BT_CHECK_PARAMETER(status, return);
1383 *status = BT_ADAPTER_DISABLED;
1385 adapter_path = _bt_get_adapter_path();
1388 if (adapter_path != NULL)
1389 *status = BT_ADAPTER_ENABLED;
1391 g_free(adapter_path);
1392 return BLUETOOTH_ERROR_NONE;
1395 int _bt_check_adapter(int *status)
1398 GError *error = NULL;
1401 gboolean powered = FALSE;
1403 BT_CHECK_PARAMETER(status, return);
1405 *status = BT_ADAPTER_DISABLED;
1407 proxy = _bt_get_adapter_properties_proxy();
1408 retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
1410 result = g_dbus_proxy_call_sync(proxy,
1412 g_variant_new("(ss)", BT_ADAPTER_INTERFACE,
1414 G_DBUS_CALL_FLAGS_NONE,
1420 BT_ERR("Failed to get local address");
1421 if (error != NULL) {
1422 BT_ERR("Failed to get local address (Error: %s)", error->message);
1423 g_clear_error(&error);
1425 return BLUETOOTH_ERROR_INTERNAL;
1428 g_variant_get(result, "(v)", &temp);
1429 powered = g_variant_get_boolean(temp);
1430 BT_DBG("powered: %d", powered);
1433 *status = BT_ADAPTER_ENABLED;
1435 g_variant_unref(result);
1436 g_variant_unref(temp);
1437 return BLUETOOTH_ERROR_NONE;
1441 int _bt_enable_adapter_le(void)
1445 GError *error = NULL;
1446 bt_status_t status = _bt_adapter_get_status();
1447 bt_le_status_t le_status = _bt_adapter_get_le_status();
1450 if (le_status == BT_LE_ACTIVATING) {
1451 BT_ERR("Enabling in progress");
1452 return BLUETOOTH_ERROR_IN_PROGRESS;
1455 if (le_status == BT_LE_ACTIVATED) {
1456 BT_ERR("Already enabled");
1457 return BLUETOOTH_ERROR_DEVICE_ALREADY_ENABLED;
1460 if (status == BT_DEACTIVATING || le_status == BT_LE_DEACTIVATING) {
1461 BT_ERR("Disabling in progress");
1462 return BLUETOOTH_ERROR_DEVICE_BUSY;
1465 _bt_adapter_set_le_status(BT_LE_ACTIVATING);
1467 proxy = __bt_get_core_proxy();
1468 retv_if(!proxy, BLUETOOTH_ERROR_INTERNAL);
1470 result = g_dbus_proxy_call_sync(proxy, "EnableAdapterLe",
1472 G_DBUS_CALL_FLAGS_NONE, BT_ENABLE_TIMEOUT,
1475 BT_ERR("EnableAdapterLe failed: %s", error->message);
1476 _bt_adapter_set_le_status(BT_DEACTIVATED);
1477 g_clear_error(&error);
1479 /* Clean up the process */
1480 result = g_dbus_proxy_call_sync(proxy,
1483 G_DBUS_CALL_FLAGS_NONE,
1489 BT_ERR("Bt core call failed");
1491 BT_ERR("EnableAdapterLE Failed %s", error->message);
1492 g_clear_error(&error);
1495 g_variant_unref(result);
1496 /* Terminate myself */
1497 if (_bt_adapter_get_status() == BT_DEACTIVATED)
1498 g_idle_add((GSourceFunc)_bt_terminate_service, NULL);
1499 return BLUETOOTH_ERROR_INTERNAL;
1503 g_variant_unref(result);
1505 _bt_adapter_start_le_enable_timer();
1507 if (status == BT_ACTIVATED) {
1508 _bt_adapter_set_le_status(BT_LE_ACTIVATED);
1509 __bt_set_le_enabled();
1511 BT_DBG("le status : %d", _bt_adapter_get_le_status());
1513 return BLUETOOTH_ERROR_NONE;
1516 int _bt_disable_adapter_le(void)
1520 bt_le_status_t bt_le_state;
1522 GError *error = NULL;
1524 bt_le_state = _bt_adapter_get_le_status();
1525 if (bt_le_state == BT_LE_DEACTIVATING) {
1526 BT_DBG("Disabling in progress");
1527 return BLUETOOTH_ERROR_IN_PROGRESS;
1530 if (bt_le_state == BT_LE_DEACTIVATED) {
1531 BT_DBG("Already disabled");
1532 return BLUETOOTH_ERROR_DEVICE_NOT_ENABLED;
1535 _bt_adapter_set_le_status(BT_LE_DEACTIVATING);
1537 proxy = __bt_get_core_proxy();
1539 return BLUETOOTH_ERROR_INTERNAL;
1541 result = g_dbus_proxy_call_sync(proxy,
1544 G_DBUS_CALL_FLAGS_NONE,
1550 if (error != NULL) {
1551 BT_ERR("Bt core call failed (Error: %s)", error->message);
1552 g_clear_error(&error);
1554 BT_ERR("Bt core call failed");
1555 _bt_adapter_set_le_status(BT_LE_ACTIVATED);
1556 return BLUETOOTH_ERROR_INTERNAL;
1559 g_variant_unref(result);
1560 _bt_set_le_disabled(BLUETOOTH_ERROR_NONE);
1561 BT_DBG("le status : %d", _bt_adapter_get_le_status());
1563 return BLUETOOTH_ERROR_NONE;
1566 int _bt_get_local_address(bluetooth_device_address_t *local_address)
1570 GError *error = NULL;
1571 const char *address;
1575 BT_CHECK_PARAMETER(local_address, return);
1577 proxy = _bt_get_adapter_properties_proxy();
1578 retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
1580 result = g_dbus_proxy_call_sync(proxy,
1582 g_variant_new("(ss)", BT_ADAPTER_INTERFACE,
1584 G_DBUS_CALL_FLAGS_NONE,
1590 BT_ERR("Failed to get local address");
1591 if (error != NULL) {
1592 BT_ERR("Failed to get local address (Error: %s)", error->message);
1593 g_clear_error(&error);
1595 return BLUETOOTH_ERROR_INTERNAL;
1598 g_variant_get(result, "(v)", &temp);
1599 address = g_variant_get_string(temp, NULL);
1600 BT_DBG("Address:%s", address);
1603 _bt_convert_addr_string_to_type(local_address->addr, address);
1605 return BLUETOOTH_ERROR_INTERNAL;
1608 g_variant_unref(result);
1609 g_variant_unref(temp);
1610 return BLUETOOTH_ERROR_NONE;
1613 int _bt_get_local_version(bluetooth_version_t *local_version)
1616 const char *ver = NULL;
1618 int ret = BLUETOOTH_ERROR_NONE;
1622 BT_CHECK_PARAMETER(local_version, return);
1624 GError *error = NULL;
1626 proxy = _bt_get_adapter_properties_proxy();
1627 retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
1629 result = g_dbus_proxy_call_sync(proxy,
1631 g_variant_new("(ss)", BT_ADAPTER_INTERFACE,
1633 G_DBUS_CALL_FLAGS_NONE,
1639 if (error != NULL) {
1640 BT_ERR("Failed to get local version (Error: %s)", error->message);
1641 g_clear_error(&error);
1643 BT_ERR("Failed to get local version");
1644 return BLUETOOTH_ERROR_INTERNAL;
1647 g_variant_get(result, "(v)", &temp);
1648 ver = g_variant_get_string(temp, NULL);
1649 BT_DBG("VERSION: %s", ver);
1651 if (ver && (strlen(ver) > 0)) {
1652 /* Check the utf8 valitation & Fill the NULL in the invalid location*/
1653 if (!g_utf8_validate(ver, -1, (const char **)&ptr))
1656 g_strlcpy(local_version->version, ver,
1657 BLUETOOTH_VERSION_LENGTH_MAX + 1);
1660 ret = BLUETOOTH_ERROR_INTERNAL;
1663 g_variant_unref(result);
1664 g_variant_unref(temp);
1668 int _bt_get_local_name(bluetooth_device_name_t *local_name)
1671 const char *name = NULL;
1673 int ret = BLUETOOTH_ERROR_NONE;
1676 GError *error = NULL;
1678 BT_CHECK_PARAMETER(local_name, return);
1680 proxy = _bt_get_adapter_properties_proxy();
1681 retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
1683 result = g_dbus_proxy_call_sync(proxy,
1685 g_variant_new("(ss)", BT_ADAPTER_INTERFACE,
1687 G_DBUS_CALL_FLAGS_NONE,
1693 if (error != NULL) {
1694 BT_ERR("Failed to get local name (Error: %s)", error->message);
1695 g_clear_error(&error);
1697 BT_ERR("Failed to get local name");
1698 return BLUETOOTH_ERROR_INTERNAL;
1701 g_variant_get(result, "(v)", &temp);
1702 name = g_variant_get_string(temp, NULL);
1703 BT_DBG("LOCAL NAME:%s", name);
1705 if (name && (strlen(name) > 0)) {
1706 /* Check the utf8 valitation & Fill the NULL in the invalid location*/
1707 if (!g_utf8_validate(name, -1, (const char **)&ptr))
1710 g_strlcpy(local_name->name, name,
1711 BLUETOOTH_DEVICE_NAME_LENGTH_MAX + 1);
1713 ret = BLUETOOTH_ERROR_INTERNAL;
1715 g_variant_unref(result);
1716 g_variant_unref(temp);
1720 int _bt_set_local_name(char *local_name)
1723 GError *error = NULL;
1727 BT_CHECK_PARAMETER(local_name, return);
1729 proxy = _bt_get_adapter_properties_proxy();
1731 retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
1733 if (!g_utf8_validate(local_name, -1, (const char **)&ptr))
1736 result = g_dbus_proxy_call_sync(proxy,
1738 g_variant_new("(ssv)", BT_ADAPTER_INTERFACE,
1739 "Alias", g_variant_new("s", local_name)),
1740 G_DBUS_CALL_FLAGS_NONE,
1746 if (error != NULL) {
1747 BT_ERR("Failed to set Alias (Error: %s)", error->message);
1748 g_clear_error(&error);
1750 BT_ERR("Failed to set Alias");
1751 return BLUETOOTH_ERROR_INTERNAL;
1754 g_variant_unref(result);
1755 return BLUETOOTH_ERROR_NONE;
1758 int _bt_is_service_used(char *service_uuid, gboolean *used)
1761 GError *error = NULL;
1762 int ret = BLUETOOTH_ERROR_NONE;
1765 GVariantIter *iter = NULL;
1769 BT_CHECK_PARAMETER(service_uuid, return);
1770 BT_CHECK_PARAMETER(used, return);
1772 proxy = _bt_get_adapter_properties_proxy();
1773 retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
1775 result = g_dbus_proxy_call_sync(proxy,
1777 g_variant_new("(ss)", BT_ADAPTER_INTERFACE,
1779 G_DBUS_CALL_FLAGS_NONE,
1785 if (error != NULL) {
1786 BT_ERR("Failed to get UUIDs (Error: %s)", error->message);
1787 g_clear_error(&error);
1789 BT_ERR("Failed to get UUIDs");
1790 return BLUETOOTH_ERROR_INTERNAL;
1793 g_variant_get(result, "(v)", &value);
1794 g_variant_get(value, "as", &iter);
1796 BT_ERR("Failed to get UUIDs(%s)",service_uuid);
1798 g_variant_unref(result);
1799 g_variant_unref(value);
1803 while (g_variant_iter_loop(iter, "s", &uuid)) {
1804 if (strcasecmp(uuid, service_uuid) == 0) {
1814 g_variant_iter_free(iter);
1815 g_variant_unref(value);
1816 g_variant_unref(result);
1817 BT_DBG("Service Used? %d", *used);
1821 static gboolean __bt_get_discoverable_property(void)
1824 gboolean discoverable_v;
1825 GError *error = NULL;
1829 proxy = _bt_get_adapter_properties_proxy();
1830 retv_if(proxy == NULL, FALSE);
1832 result = g_dbus_proxy_call_sync(proxy,
1834 g_variant_new("(ss)", BT_ADAPTER_INTERFACE,
1836 G_DBUS_CALL_FLAGS_NONE,
1842 if (error != NULL) {
1843 BT_ERR("Failed to get Discoverable property (Error: %s)", error->message);
1844 g_clear_error(&error);
1846 BT_ERR("Failed to get Discoverable property");
1847 return BLUETOOTH_ERROR_INTERNAL;
1850 g_variant_get(result, "(v)", &temp);
1851 discoverable_v = g_variant_get_boolean(temp);
1852 BT_DBG("discoverable_v:%d", discoverable_v);
1854 g_variant_unref(result);
1855 g_variant_unref(temp);
1857 return discoverable_v;
1860 int _bt_get_discoverable_mode(int *mode)
1862 gboolean discoverable;
1863 unsigned int timeout;
1865 BT_CHECK_PARAMETER(mode, return);
1867 discoverable = __bt_get_discoverable_property();
1868 timeout = _bt_get_discoverable_timeout_property();
1870 if (discoverable == TRUE) {
1872 *mode = BLUETOOTH_DISCOVERABLE_MODE_GENERAL_DISCOVERABLE;
1874 *mode = BLUETOOTH_DISCOVERABLE_MODE_TIME_LIMITED_DISCOVERABLE;
1876 *mode = BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE;
1878 return BLUETOOTH_ERROR_NONE;
1882 int _bt_set_discoverable_mode(int discoverable_mode, int timeout)
1884 int ret = BLUETOOTH_ERROR_NONE;
1887 GError *error = NULL;
1891 proxy = _bt_get_adapter_properties_proxy();
1893 retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
1895 #ifdef TIZEN_DPM_ENABLE
1896 if (discoverable_mode != BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE &&
1897 _bt_dpm_get_bluetooth_limited_discoverable_state() == DPM_RESTRICTED) {
1898 _bt_launch_dpm_popup("DPM_POLICY_DISABLE_BT_HANDSFREE");
1899 return BLUETOOTH_ERROR_ACCESS_DENIED;
1901 if (discoverable_mode != BLUETOOTH_DISCOVERABLE_MODE_GENERAL_DISCOVERABLE &&
1902 _bt_dpm_get_bluetooth_limited_discoverable_state() == DPM_RESTRICTED) {
1903 _bt_launch_dpm_popup("DPM_POLICY_DISABLE_BT");
1904 return BLUETOOTH_ERROR_ACCESS_DENIED;
1908 switch (discoverable_mode) {
1909 case BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE:
1914 case BLUETOOTH_DISCOVERABLE_MODE_GENERAL_DISCOVERABLE:
1919 case BLUETOOTH_DISCOVERABLE_MODE_TIME_LIMITED_DISCOVERABLE:
1924 return BLUETOOTH_ERROR_INVALID_PARAM;
1927 BT_INFO("Req. discoverable_mode : %d, timeout : %d",
1928 discoverable_mode, timeout);
1930 result = g_dbus_proxy_call_sync(proxy,
1932 g_variant_new("(ssv)", BT_ADAPTER_INTERFACE,
1933 "Connectable", g_variant_new("b", pg_scan)),
1934 G_DBUS_CALL_FLAGS_NONE,
1940 if (error != NULL) {
1941 BT_ERR("Failed to set connectable property (Error: %s)", error->message);
1942 g_clear_error(&error);
1944 BT_ERR("Failed to set connectable property");
1945 return BLUETOOTH_ERROR_INTERNAL;
1947 g_variant_unref(result);
1948 result = g_dbus_proxy_call_sync(proxy,
1950 g_variant_new("(ssv)", BT_ADAPTER_INTERFACE, "Discoverable",
1951 g_variant_new("b", inq_scan)),
1952 G_DBUS_CALL_FLAGS_NONE,
1958 if (error != NULL) {
1959 BT_ERR("Failed to set Discoverable property (Error: %s)", error->message);
1960 g_clear_error(&error);
1962 BT_ERR("Failed to set Discoverable property");
1963 return BLUETOOTH_ERROR_INTERNAL;
1965 g_variant_unref(result);
1966 result = g_dbus_proxy_call_sync(proxy,
1968 g_variant_new("(ssv)", BT_ADAPTER_INTERFACE,
1969 "DiscoverableTimeout", g_variant_new("u", timeout)),
1970 G_DBUS_CALL_FLAGS_NONE,
1976 if (error != NULL) {
1977 BT_ERR("Failed to set DiscoverableTimeout property (Error: %s)", error->message);
1978 g_clear_error(&error);
1980 BT_ERR("Failed to set DiscoverableTimeout property");
1981 return BLUETOOTH_ERROR_INTERNAL;
1984 if (discoverable_mode == BLUETOOTH_DISCOVERABLE_MODE_GENERAL_DISCOVERABLE)
1987 ret = __bt_set_visible_time(timeout);
1989 g_variant_unref(result);
1994 int _bt_start_discovery(void)
1997 GError *error = NULL;
2000 if (_bt_is_discovering() == TRUE) {
2001 BT_ERR("BT is already in discovering");
2002 return BLUETOOTH_ERROR_IN_PROGRESS;
2003 } else if (_bt_is_device_creating() == TRUE) {
2004 BT_ERR("Bonding device is going on");
2005 return BLUETOOTH_ERROR_DEVICE_BUSY;
2008 proxy = _bt_get_adapter_proxy();
2009 retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
2011 result = g_dbus_proxy_call_sync(proxy,
2014 G_DBUS_CALL_FLAGS_NONE,
2020 if (error != NULL) {
2021 BT_ERR("StartDiscovery failed (Error: %s)", error->message);
2022 g_clear_error(&error);
2024 BT_ERR("StartDiscovery failed");
2025 return BLUETOOTH_ERROR_INTERNAL;
2028 is_discovering = TRUE;
2029 cancel_by_user = FALSE;
2030 /* discovery status will be change in event */
2031 g_variant_unref(result);
2032 return BLUETOOTH_ERROR_NONE;
2035 int _bt_start_custom_discovery(bt_discovery_role_type_t role)
2039 GError *error = NULL;
2040 const gchar *disc_type;
2042 if (_bt_is_discovering() == TRUE) {
2043 BT_ERR("BT is already in discovering");
2044 return BLUETOOTH_ERROR_IN_PROGRESS;
2047 proxy = _bt_get_adapter_proxy();
2048 retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
2050 if (role == DISCOVERY_ROLE_BREDR)
2051 disc_type = "BREDR";
2052 else if (role == DISCOVERY_ROLE_LE)
2054 else if (role == DISCOVERY_ROLE_LE_BREDR)
2055 disc_type = "LE_BREDR";
2057 return BLUETOOTH_ERROR_INVALID_PARAM;
2059 result = g_dbus_proxy_call_sync(proxy,
2060 "StartCustomDiscovery",
2061 g_variant_new("s", disc_type),
2062 G_DBUS_CALL_FLAGS_NONE,
2068 if (error != NULL) {
2069 BT_ERR("StartCustomDiscovery failed (Error: %s)", error->message);
2070 g_clear_error(&error);
2072 BT_ERR("StartCustomDiscovery failed");
2073 return BLUETOOTH_ERROR_INTERNAL;
2076 is_discovering = TRUE;
2077 cancel_by_user = FALSE;
2078 /* discovery status will be change in event */
2079 g_variant_unref(result);
2080 return BLUETOOTH_ERROR_NONE;
2083 int _bt_cancel_discovery(void)
2086 GError *error = NULL;
2089 if (_bt_is_discovering() == FALSE) {
2090 BT_ERR("BT is not in discovering");
2091 return BLUETOOTH_ERROR_NOT_IN_OPERATION;
2094 proxy = _bt_get_adapter_proxy();
2095 retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
2097 result = g_dbus_proxy_call_sync(proxy,
2100 G_DBUS_CALL_FLAGS_NONE,
2106 if (error != NULL) {
2107 BT_ERR("StopDiscovery failed (Error: %s)", error->message);
2108 g_clear_error(&error);
2110 BT_ERR("StopDiscovery failed");
2111 return BLUETOOTH_ERROR_INTERNAL;
2114 cancel_by_user = TRUE;
2115 /* discovery status will be change in event */
2116 g_variant_unref(result);
2117 return BLUETOOTH_ERROR_NONE;
2120 gboolean _bt_is_discovering(void)
2122 return is_discovering;
2125 gboolean _bt_is_connectable(void)
2128 GError *error = NULL;
2129 gboolean is_connectable = FALSE;
2133 proxy = _bt_get_adapter_properties_proxy();
2134 retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
2136 result = g_dbus_proxy_call_sync(proxy,
2138 g_variant_new("(ss)", BT_ADAPTER_INTERFACE,
2140 G_DBUS_CALL_FLAGS_NONE,
2146 if (error != NULL) {
2147 BT_ERR("Failed to get connectable property (Error: %s)", error->message);
2148 g_clear_error(&error);
2150 BT_ERR("Failed to get connectable property");
2151 return BLUETOOTH_ERROR_INTERNAL;
2154 g_variant_get(result, "(v)", &temp);
2155 is_connectable = g_variant_get_boolean(temp);
2156 BT_DBG("discoverable_v:%d", is_connectable);
2158 g_variant_unref(result);
2159 g_variant_unref(temp);
2161 BT_INFO("Get connectable [%d]", is_connectable);
2162 return is_connectable;
2165 int _bt_set_connectable(gboolean is_connectable)
2168 GError *error = NULL;
2171 if (__bt_is_factory_test_mode()) {
2172 BT_ERR("Unable to set connectable in factory binary !!");
2173 return BLUETOOTH_ERROR_NOT_SUPPORT;
2176 proxy = _bt_get_adapter_properties_proxy();
2178 retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
2180 result = g_dbus_proxy_call_sync(proxy,
2182 g_variant_new("(ssv)", BT_ADAPTER_INTERFACE, "Connectable",
2183 g_variant_new("b", is_connectable)),
2184 G_DBUS_CALL_FLAGS_NONE,
2190 if (error != NULL) {
2191 BT_ERR("Failed to set connectable property (Error: %s)", error->message);
2192 g_clear_error(&error);
2194 BT_ERR("Failed to set connectable property");
2195 return BLUETOOTH_ERROR_INTERNAL;
2198 BT_INFO("Set connectable [%d]", is_connectable);
2199 g_variant_unref(result);
2200 return BLUETOOTH_ERROR_NONE;
2203 gboolean _bt_get_discovering_property(bt_discovery_role_type_t discovery_type)
2206 gboolean discovering_v;
2207 GError *error = NULL;
2208 char *discovering_type = NULL;
2212 proxy = _bt_get_adapter_properties_proxy();
2213 retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
2215 if (discovery_type == DISCOVERY_ROLE_BREDR)
2216 discovering_type = "Discovering";
2217 else if (discovery_type == DISCOVERY_ROLE_LE)
2218 discovering_type = "LEDiscovering";
2220 result = g_dbus_proxy_call_sync(proxy,
2222 g_variant_new("(ss)", BT_ADAPTER_INTERFACE,
2224 G_DBUS_CALL_FLAGS_NONE,
2230 if (error != NULL) {
2231 BT_ERR("Failed to get discovering property (Error: %s)", error->message);
2232 g_clear_error(&error);
2234 BT_ERR("Failed to get discovering property");
2235 return BLUETOOTH_ERROR_INTERNAL;
2238 g_variant_get(result, "(v)", &temp);
2239 discovering_v = g_variant_get_boolean(temp);
2240 BT_DBG("discoverable_v:%d", discovering_v);
2242 g_variant_unref(result);
2243 g_variant_unref(temp);
2245 return discovering_v;
2248 unsigned int _bt_get_discoverable_timeout_property(void)
2251 unsigned int timeout_v;
2252 GError *error = NULL;
2256 proxy = _bt_get_adapter_properties_proxy();
2257 retv_if(proxy == NULL, 0);
2259 result = g_dbus_proxy_call_sync(proxy,
2261 g_variant_new("(ss)", BT_ADAPTER_INTERFACE,
2262 "DiscoverableTimeout"),
2263 G_DBUS_CALL_FLAGS_NONE,
2269 BT_ERR("Fail to get discoverable timeout");
2270 if (error != NULL) {
2271 BT_ERR("Fail to get discoverable timeout (Error: %s)", error->message);
2272 g_clear_error(&error);
2277 g_variant_get(result, "(v)", &temp);
2278 timeout_v = g_variant_get_uint32(temp);
2279 BT_DBG("discoverable_v:%d", timeout_v);
2281 g_variant_unref(result);
2282 g_variant_unref(temp);
2287 static bluetooth_device_info_t *__bt_parse_device_info(GVariantIter *item_iter)
2289 bluetooth_device_info_t *dev_info;
2292 GByteArray *manufacturer_data = NULL;
2294 GVariantIter *char_value_iter;
2296 dev_info = g_malloc0(sizeof(bluetooth_device_info_t));
2298 while (g_variant_iter_loop(item_iter, "{sv}", &key, &value)) {
2303 if (!g_strcmp0(key, "Address")) {
2304 const char *address = NULL;
2305 address = g_variant_get_string(value, NULL);
2306 _bt_convert_addr_string_to_type(dev_info->device_address.addr,
2308 } else if(!g_strcmp0(key, "Class")) {
2310 cod = g_variant_get_uint32(value);
2311 _bt_divide_device_class(&dev_info->device_class, cod);
2312 } else if(!g_strcmp0(key, "Name")) {
2313 const char *name = NULL;
2314 name = g_variant_get_string(value, NULL);
2315 /* If there is no Alias */
2316 if (strlen(dev_info->device_name.name) == 0) {
2317 g_strlcpy(dev_info->device_name.name, name,
2318 BLUETOOTH_DEVICE_NAME_LENGTH_MAX+1);
2320 } else if(!g_strcmp0(key, "Alias")) {
2321 const char *alias = NULL;
2322 alias = g_variant_get_string(value, NULL);
2323 /* Overwrite the name */
2325 memset(dev_info->device_name.name, 0x00,
2326 BLUETOOTH_DEVICE_NAME_LENGTH_MAX+1);
2327 g_strlcpy(dev_info->device_name.name, alias,
2328 BLUETOOTH_DEVICE_NAME_LENGTH_MAX+1);
2330 } else if (!g_strcmp0(key, "Connected")) {
2331 dev_info->connected = g_variant_get_byte(value);
2332 } else if (!g_strcmp0(key, "Paired")) {
2333 dev_info->paired = g_variant_get_boolean(value);
2334 } else if (!g_strcmp0(key, "Trusted")) {
2335 dev_info->trust = g_variant_get_boolean(value);
2336 } else if (!g_strcmp0(key, "RSSI")) {
2337 dev_info->rssi = g_variant_get_int16(value);
2338 } else if (!g_strcmp0(key, "UUIDs")) {
2344 dev_info->service_index = 0;
2345 g_variant_get(value, "as", &iter);
2346 while (g_variant_iter_loop(iter, "s", &uuid)) {
2347 g_strlcpy(dev_info->uuids[i], uuid, BLUETOOTH_UUID_STRING_MAX);
2348 parts = g_strsplit(uuid, "-", -1);
2350 if (parts == NULL || parts[0] == NULL) {
2355 dev_info->service_list_array[i] = g_ascii_strtoull(parts[0], NULL, 16);
2360 dev_info->service_index = i;
2361 g_variant_iter_free(iter);
2362 } else if (strcasecmp(key, "ManufacturerDataLen") == 0) {
2363 dev_info->manufacturer_data.data_len = g_variant_get_uint16(value);
2364 } else if (strcasecmp(key, "ManufacturerData") == 0) {
2365 manufacturer_data = g_byte_array_new();
2366 g_variant_get(value, "ay", &char_value_iter);
2367 while(g_variant_iter_loop(char_value_iter, "y", &char_value)) {
2368 g_byte_array_append(manufacturer_data, &char_value, 1);
2370 if (manufacturer_data) {
2371 if (manufacturer_data->len > 0) {
2372 memcpy(dev_info->manufacturer_data.data, manufacturer_data->data, manufacturer_data->len);
2375 g_variant_iter_free(char_value_iter);
2376 g_byte_array_free(manufacturer_data, TRUE);
2383 static void __bt_extract_device_info(GVariantIter *iter,
2386 bluetooth_device_info_t *dev_info = NULL;
2387 char *object_path = NULL;
2388 GVariantIter *interface_iter;
2389 GVariantIter *svc_iter;
2390 char *interface_str = NULL;
2392 /* Parse the signature: oa{sa{sv}}} */
2393 while (g_variant_iter_loop(iter, "{&oa{sa{sv}}}", &object_path,
2396 if (object_path == NULL)
2399 while (g_variant_iter_loop(interface_iter, "{sa{sv}}",
2400 &interface_str, &svc_iter)) {
2401 if (g_strcmp0(interface_str, "org.bluez.Device1") == 0) {
2402 BT_DBG("Found a device: %s", object_path);
2403 dev_info = __bt_parse_device_info(svc_iter);
2405 if (dev_info->paired == TRUE) {
2406 g_array_append_vals(*dev_list, dev_info,
2407 sizeof(bluetooth_device_info_t));
2411 g_free(interface_str);
2412 g_variant_iter_free(svc_iter);
2420 int _bt_get_bonded_devices(GArray **dev_list)
2423 GDBusConnection *conn;
2424 GDBusProxy *manager_proxy;
2425 GVariant *result = NULL;
2426 GVariantIter *iter = NULL;
2427 GError *error = NULL;
2429 conn = _bt_get_system_conn();
2430 retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
2432 manager_proxy = _bt_get_manager_proxy();
2433 retv_if(manager_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
2435 result = g_dbus_proxy_call_sync(manager_proxy, "GetManagedObjects",
2437 G_DBUS_CALL_FLAGS_NONE,
2443 if (error != NULL) {
2444 BT_ERR("Failed to GetManagedObjects (Error: %s)", error->message);
2445 g_clear_error(&error);
2447 BT_ERR("Failed to Failed to GetManagedObjects");
2448 return BLUETOOTH_ERROR_INTERNAL;
2451 /* signature of GetManagedObjects: a{oa{sa{sv}}} */
2452 g_variant_get(result, "(a{oa{sa{sv}}})", &iter);
2454 __bt_extract_device_info(iter, dev_list);
2455 g_variant_iter_free(iter);
2456 g_variant_unref(result);
2459 return BLUETOOTH_ERROR_NONE;
2462 int _bt_get_bonded_device_info(bluetooth_device_address_t *device_address,
2463 bluetooth_device_info_t *dev_info)
2465 char *object_path = NULL;
2466 GDBusProxy *adapter_proxy;
2467 char address[BT_ADDRESS_STRING_SIZE] = { 0 };
2468 int ret = BLUETOOTH_ERROR_NONE;
2470 BT_CHECK_PARAMETER(device_address, return);
2471 BT_CHECK_PARAMETER(dev_info, return);
2473 adapter_proxy = _bt_get_adapter_proxy();
2474 retv_if(adapter_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
2476 _bt_convert_addr_type_to_string(address, device_address->addr);
2478 object_path = _bt_get_device_object_path(address);
2480 retv_if(object_path == NULL, BLUETOOTH_ERROR_NOT_PAIRED);
2482 ret = __bt_get_bonded_device_info(object_path, dev_info);
2483 g_free(object_path);
2488 int _bt_get_timeout_value(int *timeout)
2490 time_t current_time;
2493 /* Take current time */
2494 time(¤t_time);
2495 time_diff = difftime(current_time, visible_timer.start_time);
2497 BT_DBG("Time diff = %d\n", time_diff);
2499 *timeout = visible_timer.timeout - time_diff;
2501 return BLUETOOTH_ERROR_NONE;
2504 int _bt_set_le_privacy(gboolean set_privacy)
2507 GError *error = NULL;
2508 GVariant *result = NULL;
2510 if (__bt_is_factory_test_mode()) {
2511 BT_ERR("Unable to set le privacy in factory binary !!");
2512 return BLUETOOTH_ERROR_NOT_SUPPORT;
2515 if (_bt_adapter_get_status() != BT_ACTIVATED &&
2516 _bt_adapter_get_le_status() != BT_LE_ACTIVATED) {
2517 return BLUETOOTH_ERROR_DEVICE_NOT_ENABLED;
2520 proxy = _bt_get_adapter_proxy();
2521 retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
2523 result = g_dbus_proxy_call_sync(proxy,
2525 g_variant_new("(b)", set_privacy),
2526 G_DBUS_CALL_FLAGS_NONE,
2532 if (error != NULL) {
2533 BT_ERR("Failed to SetLePrivacy (Error: %s)", error->message);
2534 g_clear_error(&error);
2536 BT_ERR("Failed to SetLePrivacy");
2537 return BLUETOOTH_ERROR_INTERNAL;
2540 g_variant_unref(result);
2541 BT_INFO("SetLePrivacy as %d", set_privacy);
2542 return BLUETOOTH_ERROR_NONE;
2545 int _bt_set_manufacturer_data(bluetooth_manufacturer_data_t *m_data)
2548 GError *error = NULL;
2552 GVariantBuilder *builder;
2554 BT_CHECK_PARAMETER(m_data, return);
2556 if (_bt_adapter_get_status() != BT_ACTIVATED &&
2557 _bt_adapter_get_le_status() != BT_LE_ACTIVATED) {
2558 return BLUETOOTH_ERROR_DEVICE_NOT_ENABLED;
2561 proxy = _bt_get_adapter_proxy();
2562 retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
2564 builder = g_variant_builder_new(G_VARIANT_TYPE("ay"));
2566 for (i = 0; i < (m_data->data_len) + 2; i++) {
2567 g_variant_builder_add(builder, "y", m_data->data[i]);
2570 val = g_variant_new("(ay)", builder);
2572 result = g_dbus_proxy_call_sync(proxy,
2573 "SetManufacturerData",
2575 G_DBUS_CALL_FLAGS_NONE,
2579 g_variant_builder_unref(builder);
2581 if (error != NULL) {
2582 BT_ERR("Failed to SetManufacturerData (Error: %s)", error->message);
2583 g_clear_error(&error);
2585 BT_ERR("Failed to SetManufacturerData");
2587 return BLUETOOTH_ERROR_INTERNAL;
2589 builder = g_variant_builder_new(G_VARIANT_TYPE("ay"));
2591 for (i = 0; i < (m_data->data_len) + 2; i++) {
2592 g_variant_builder_add(builder, "y", m_data->data[i]);
2595 val = g_variant_new("(ay)", builder);
2597 _bt_send_event(BT_ADAPTER_EVENT,
2598 BLUETOOTH_EVENT_MANUFACTURER_DATA_CHANGED,
2601 BT_INFO("Set manufacturer data");
2603 g_variant_builder_unref(builder);
2604 g_variant_unref(result);
2606 return BLUETOOTH_ERROR_NONE;
2610 int _bt_get_enable_timer_id(void)