2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
22 #include <vconf-internal-bt-keys.h>
24 #include "bluetooth-api.h"
25 #include "bt-internal-types.h"
27 #include "bt-service-common.h"
28 #include "bt-service-event.h"
29 #include "bt-service-main.h"
30 #include "bt-service-adapter.h"
31 #include "bt-service-adapter-le.h"
32 #include "bt-service-device.h"
33 #include "bt-service-avrcp.h"
34 #include "bt-service-obex-server.h"
35 #include "bt-service-rfcomm-server.h"
36 #include "bt-service-audio.h"
37 #include "bt-service-agent.h"
38 #include "bt-service-pbap.h"
39 #include "bt-service-headset-connection.h"
40 #include "bt-service-avrcp-controller.h"
41 #include "bt-service-hid.h"
42 #include "bt-service-proximity.h"
44 #include "bt-service-opp-client.h"
46 #ifdef TIZEN_DPM_ENABLE
47 #include "bt-service-dpm.h"
50 #define DBUS_TIMEOUT 20 * 1000 /* 20 Sec */
51 static GDBusConnection *manager_conn;
52 static GDBusConnection *obexd_conn;
53 static GDBusConnection *opc_obexd_conn;
55 static GList *p_cache_list = NULL;
57 static guint event_id;
58 static guint session_reinit_timer;
59 guint nap_connected_device_count = 0;
60 static guint hid_connected_device_count = 0;
61 static GList *p_adv_ind_list = NULL;
64 bt_remote_dev_info_t *dev_info;
68 * obexd connection type
76 OBEX_PCSUITE = (1 << 6),
77 OBEX_SYNCEVOLUTION = (1 << 7),
79 } bluetooth_obex_connection_type_t;
81 void _bt_handle_property_changed_event(GVariant *msg, const char *object_path);
82 void _bt_opc_property_changed_event(GVariant *msg, char *path);
83 int _bt_register_service_event(GDBusConnection *g_conn, int event_type);
84 void _bt_unregister_service_event(GDBusConnection *g_conn, int event_type);
85 void _bt_opp_client_event_deinit(void);
86 void _bt_handle_network_client_event(GVariant *msg_iter,
88 void __bt_gatt_char_property_changed_event(GVariant *msg_iter,
91 static void __bt_free_bt_le_adv_info_t(gpointer data)
93 bt_le_adv_info_t *adv_info = data;
95 if (adv_info->timer_id)
96 g_source_remove(adv_info->timer_id);
97 adv_info->timer_id = 0;
99 g_free(adv_info->addr);
100 g_free(adv_info->data);
104 static bt_le_adv_info_t *__bt_get_adv_ind_info(char *addr)
106 retv_if(!addr, NULL);
107 bt_le_adv_info_t *adv_info = NULL;
108 GList *current = g_list_first((GList *)p_adv_ind_list);
109 while (current && current->data) {
110 adv_info = (bt_le_adv_info_t *)current->data;
111 if (adv_info && !g_strcmp0(adv_info->addr, addr))
113 current = g_list_next(current);
118 static int __bt_add_adv_ind_info(bt_le_adv_info_t *adv_info)
120 retv_if(!adv_info, -1);
121 if (__bt_get_adv_ind_info(adv_info->addr) != NULL) {
122 __bt_free_bt_le_adv_info_t(adv_info);
125 p_adv_ind_list = g_list_append(p_adv_ind_list, adv_info);
130 static void __bt_del_adv_ind_info(char *addr)
133 ret_if(!p_adv_ind_list);
134 bt_le_adv_info_t *adv_info = NULL;
135 GList *current = g_list_first((GList *)p_adv_ind_list);
136 while (current && current->data) {
137 adv_info = (bt_le_adv_info_t *)current->data;
138 if (adv_info && !g_strcmp0(adv_info->addr, addr)) {
139 p_adv_ind_list = g_list_remove(p_adv_ind_list, adv_info);
140 __bt_free_bt_le_adv_info_t(adv_info);
143 current = g_list_next(current);
147 static gboolean __bt_adv_scan_req_timeout_cb(gpointer user_data)
149 bt_remote_le_dev_info_t le_dev_info;
150 bt_le_adv_info_t *adv_info = (bt_le_adv_info_t*)user_data;
152 memset(&le_dev_info, 0x00, sizeof(bt_remote_le_dev_info_t));
154 le_dev_info.address = adv_info->addr;
155 le_dev_info.addr_type = adv_info->addr_type;
156 le_dev_info.rssi = adv_info->rssi;
157 le_dev_info.adv_data = adv_info->data;
158 le_dev_info.adv_data_len = 0;
159 adv_info->timer_id = 0;
161 _bt_send_scan_result_event(&le_dev_info, adv_info);
162 __bt_del_adv_ind_info(adv_info->addr);
167 static void __bt_free_cache_info(bt_cache_info_t *cache_info)
169 ret_if(cache_info == NULL);
170 _bt_free_device_info(cache_info->dev_info);
174 static gboolean __bt_parse_device_properties(GVariant *item,
175 bt_remote_dev_info_t *dev_info)
184 g_variant_iter_init(&iter, item);
185 while (g_variant_iter_loop(&iter, "{sv}", &key, &val)) {
186 if (strcasecmp(key, "Address") == 0) {
187 dev_info->address = g_variant_dup_string(val, &len);
188 } else if (strcasecmp(key, "Class") == 0) {
189 dev_info->class = g_variant_get_uint32(val);
190 } else if (strcasecmp(key, "name") == 0) {
191 if (dev_info->name == NULL)
192 dev_info->name = g_variant_dup_string(val, &len);
193 } else if (strcasecmp(key, "Connected") == 0) {
194 dev_info->connected = g_variant_get_byte(val);
195 } else if (strcasecmp(key, "paired") == 0) {
196 dev_info->paired = g_variant_get_boolean(val);
197 } else if (strcasecmp(key, "Trusted") == 0) {
198 dev_info->trust = g_variant_get_boolean(val);
199 } else if (strcasecmp(key, "RSSI") == 0) {
200 dev_info->rssi = g_variant_get_int16(val);
201 } else if (strcasecmp(key, "LastAddrType") == 0) {
202 dev_info->addr_type = g_variant_get_byte(val);
203 } else if (strcasecmp(key, "UUIDs") == 0) {
207 size = g_variant_get_size(val);
210 uuid_value = (char **)g_variant_get_strv(val, &size);
211 if (dev_info->uuids == NULL)
212 dev_info->uuids = g_malloc0(sizeof(char *) * size);
214 for (i = 0; uuid_value[i] != NULL; i++) {
215 dev_info->uuid_count++;
216 dev_info->uuids[i] = g_strdup(uuid_value[i]);
220 } else if (strcasecmp(key, "ManufacturerDataLen") == 0) {
221 g_variant_get(val, "q", &dev_info->manufacturer_data_len);
222 if (dev_info->manufacturer_data_len > BLUETOOTH_MANUFACTURER_DATA_LENGTH_MAX) {
223 BT_ERR("manufacturer_data_len is too long(len = %d)", dev_info->manufacturer_data_len);
224 dev_info->manufacturer_data_len = BLUETOOTH_MANUFACTURER_DATA_LENGTH_MAX;
227 if (dev_info->manufacturer_data_len == 0)
228 dev_info->manufacturer_data = g_strdup("");
229 } else if (strcasecmp(key, "ManufacturerData") == 0) {
232 GVariantIter *value_iter;
235 len = g_variant_get_size(val);
239 dev_info->manufacturer_data = g_malloc0(len);
241 g_variant_get(val, "ay", &value_iter);
242 while (g_variant_iter_loop(value_iter, "y", &m_value))
243 dev_info->manufacturer_data[i++] = m_value;
244 g_variant_iter_free(value_iter);
252 static gboolean __bt_parse_interface(GVariant *msg,
253 bt_remote_dev_info_t *dev_info)
256 GVariant *optional_param = NULL;
259 char *interface_name = NULL;
260 GVariant *inner_iter = NULL;
261 g_variant_get(msg, "(&o@a{sa{sv}})",
262 &path, &optional_param);
263 g_variant_iter_init(&iter, optional_param);
265 retv_if(optional_param == NULL, FALSE);
267 while ((child = g_variant_iter_next_value(&iter))) {
268 g_variant_get(child, "{&s@a{sv}}", &interface_name, &inner_iter);
269 if (g_strcmp0(interface_name, BT_DEVICE_INTERFACE) == 0) {
270 BT_DBG("Found a device: %s", path);
271 if (__bt_parse_device_properties(inner_iter,
272 dev_info) == FALSE) {
273 g_variant_unref(inner_iter);
274 g_variant_unref(child);
275 g_variant_unref(optional_param);
276 BT_ERR("Fail to parse the properies");
279 g_variant_unref(inner_iter);
280 g_variant_unref(child);
281 g_variant_unref(optional_param);
285 g_variant_unref(inner_iter);
286 g_variant_unref(child);
289 g_variant_unref(optional_param);
294 static int __bt_get_owner_info(GVariant *msg, char **name,
295 char **previous, char **current)
297 g_variant_get(msg, "(sss)", name, previous, current);
298 return BLUETOOTH_ERROR_NONE;
301 static int __bt_get_agent_signal_info(GVariant *msg, char **address,
302 char **name, char **uuid)
304 g_variant_get(msg, "(sss)", address, name, uuid);
305 return BLUETOOTH_ERROR_NONE;
308 void __bt_set_device_values(gboolean connected, int state)
310 int bt_device_state = VCONFKEY_BT_DEVICE_NONE;
312 if (vconf_get_int(VCONFKEY_BT_DEVICE, &bt_device_state) != 0)
313 BT_ERR("vconf_get_int failed");
315 if (connected == TRUE)
316 bt_device_state |= state;
317 else if (bt_device_state & state)
318 bt_device_state ^= state;
320 if (vconf_set_int(VCONFKEY_BT_DEVICE, bt_device_state) != 0)
321 BT_ERR("vconf_set_int failed");
324 gboolean _bt_discovery_finished_cb(gpointer user_data)
326 int result = BLUETOOTH_ERROR_NONE;
328 GVariant *param = NULL;
329 if (_bt_get_discovering_property(DISCOVERY_ROLE_BREDR) == FALSE) {
330 if (_bt_get_cancel_by_user() == TRUE)
331 result = BLUETOOTH_ERROR_CANCEL_BY_USER;
333 _bt_set_cancel_by_user(FALSE);
334 _bt_set_discovery_status(FALSE);
335 param = g_variant_new("(i)", result);
336 _bt_send_event(BT_ADAPTER_EVENT,
337 BLUETOOTH_EVENT_DISCOVERY_FINISHED,
344 static gboolean __bt_le_discovery_finished_cb(gpointer user_data)
346 int result = BLUETOOTH_ERROR_NONE;
348 GVariant *param = NULL;
349 if (_bt_get_discovering_property(DISCOVERY_ROLE_LE) == FALSE) {
350 if (_bt_get_cancel_by_user() == TRUE)
351 result = BLUETOOTH_ERROR_CANCEL_BY_USER;
353 g_list_free_full(p_adv_ind_list, __bt_free_bt_le_adv_info_t);
354 p_adv_ind_list = NULL;
356 _bt_set_cancel_by_user(FALSE);
357 _bt_disable_all_scanner_status();
358 _bt_set_le_scan_status(FALSE);
359 param = g_variant_new("(i)", result);
360 _bt_send_event(BT_LE_ADAPTER_EVENT,
361 BLUETOOTH_EVENT_LE_DISCOVERY_FINISHED,
368 void __bt_update_remote_cache_devinfo(const char *address, gboolean paired_status)
372 ret_if(address == NULL);
375 bt_cache_info_t *cache_info;
376 bt_remote_dev_info_t *dev_info;
378 node = g_list_first(p_cache_list);
380 while (node != NULL) {
381 cache_info = (bt_cache_info_t *)node->data;
383 if (cache_info == NULL) {
384 node = g_list_next(node);
388 dev_info = cache_info->dev_info;
389 if (strcasecmp(dev_info->address,
391 BT_DBG("Device Found");
392 if (paired_status == TRUE)
393 cache_info->dev_info->paired = TRUE;
395 cache_info->dev_info->paired = FALSE;
398 node = g_list_next(node);
403 static void __bt_device_remote_connected_properties(
404 bt_remote_dev_info_t *remote_dev_info,
405 char *address, gboolean connected)
407 int result = BLUETOOTH_ERROR_NONE;
409 GVariant *param = NULL;
412 if (remote_dev_info->uuid_count > 0) {
413 for (i = 0; i < remote_dev_info->uuid_count; i++) {
414 char *uuid = remote_dev_info->uuids[i];
415 if (strcasecmp(uuid, HID_UUID) == 0) {
416 int event = BLUETOOTH_EVENT_NONE;
418 event = (connected == TRUE) ?
419 BLUETOOTH_HID_CONNECTED :
420 BLUETOOTH_HID_DISCONNECTED;
421 param = g_variant_new("(is)", result,
423 _bt_send_event(BT_HID_EVENT, event,
433 gboolean __bt_handle_is_flight_mode_enabled(void)
435 #ifdef TIZEN_FEATURE_FLIGHTMODE_ENABLED
436 int is_flight_mode = 0;
439 ret = vconf_get_bool(VCONFKEY_TELEPHONY_FLIGHT_MODE, &is_flight_mode);
441 BT_ERR("vconf_get_bool failed");
443 return (is_flight_mode == 0) ? FALSE : TRUE;
449 void _bt_handle_adapter_event(GVariant *msg, const char *member)
453 int result = BLUETOOTH_ERROR_NONE;
454 GVariant *param = NULL;
455 ret_if(member == NULL);
457 if (strcasecmp(member, "DeviceCreated") == 0) {
458 char *object_path = NULL;
460 bt_remote_dev_info_t *remote_dev_info;
462 ret_if(_bt_is_device_creating() == FALSE);
464 /* Bonding from remote device */
465 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
467 g_variant_get(msg, "(&o)", &object_path);
468 _bt_convert_device_path_to_address((const char*)object_path, address);
470 remote_dev_info = _bt_get_remote_device_info_by_object_path(object_path);
471 if (remote_dev_info == NULL) {
476 _bt_free_device_info(remote_dev_info);
478 } else if (strcasecmp(member, "InterfacesRemoved") == 0) {
479 char *object_path = NULL;
481 bt_cache_info_t *cache_info;
482 bt_remote_dev_info_t *dev_info;
485 /* Bonding from remote device */
486 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
490 g_variant_get(msg, "(&o)", &object_path);
492 _bt_convert_device_path_to_address((const char *)object_path, address);
494 node = g_list_first(p_cache_list);
496 while (node != NULL) {
497 cache_info = (bt_cache_info_t *)node->data;
499 if (cache_info == NULL) {
500 node = g_list_next(node);
504 dev_info = cache_info->dev_info;
505 if (strcasecmp(dev_info->address,
507 p_cache_list = g_list_remove(p_cache_list,
509 __bt_free_cache_info(cache_info);
512 node = g_list_next(node);
515 } else if (strcasecmp(member, "AdvertisingEnabled") == 0) {
516 BT_DBG("Advertising Enabled");
520 gboolean status = FALSE;
522 g_variant_get(msg, "(ib)", &slot_id, &status);
524 BT_DBG("Advertising Enabled : slot_id [%d] status [%d]", slot_id, status);
526 /* Send event to application */
527 _bt_set_advertising_status(slot_id, status);
529 adv_handle = _bt_get_adv_slot_adv_handle(slot_id);
532 event = BLUETOOTH_EVENT_ADVERTISING_STARTED;
534 event = BLUETOOTH_EVENT_ADVERTISING_STOPPED;
535 param = g_variant_new("(ii)", result,
540 sender = _bt_get_adv_slot_owner(slot_id);
541 _bt_send_event_to_dest(sender, BT_ADAPTER_EVENT,
545 _bt_send_event(BT_ADAPTER_EVENT, event, param);
548 if (event == BLUETOOTH_EVENT_ADVERTISING_STOPPED)
549 _bt_unregister_adv_slot_owner(slot_id);
550 } else if (strcasecmp(member, "RssiEnabled") == 0) {
551 BT_DBG("RSSI Enabled");
552 gboolean status = FALSE;
553 char *address = NULL;
555 g_variant_get(msg, "(sib)", &address, &link_type, &status);
557 BT_DBG("RSSI Enabled [%s %d]", address, status);
558 param = g_variant_new("(isib)", result,
559 address, link_type, status);
560 _bt_send_event(BT_DEVICE_EVENT,
561 BLUETOOTH_EVENT_RSSI_ENABLED,
564 } else if (strcasecmp(member, "RssiAlert") == 0) {
565 BT_DBG("RSSI Alert");
569 char *address = NULL;
570 g_variant_get(msg, "(siii)", &address, &link_type, &alert_type, &rssi_dbm);
572 BT_DBG("RSSI Alert: [Address %s LinkType %d] [Type %d DBM %d]",
573 address, alert_type, rssi_dbm);
574 param = g_variant_new("(isiii)", result,
575 address, link_type, alert_type, rssi_dbm);
576 _bt_send_event(BT_DEVICE_EVENT,
577 BLUETOOTH_EVENT_RSSI_ALERT,
580 } else if (strcasecmp(member, "RawRssi") == 0) {
584 char *address = NULL;
585 g_variant_get(msg, "(sii)", &address, &link_type, &rssi_dbm);
587 BT_DBG("Raw RSSI: [Address %s] [Link Type %d][RSSI DBM %d]",
588 address, link_type, rssi_dbm);
589 param = g_variant_new("(isii)", result,
590 address, link_type, rssi_dbm);
591 _bt_send_event(BT_DEVICE_EVENT,
592 BLUETOOTH_EVENT_RAW_RSSI,
595 } else if (strcasecmp(member, BT_HARDWARE_ERROR) == 0) {
596 BT_ERR_C("Hardware error received from BLUEZ");
597 /* Don't add the recovery logic into platform */
599 _bt_recover_adapter();
601 } else if (strcasecmp(member, BT_TX_TIMEOUT_ERROR) == 0) {
602 BT_ERR_C("Tx timeout error received from BLUEZ");
603 /* Don't add the recovery logic into platform */
605 _bt_recover_adapter();
611 static void __bt_adapter_property_changed_event(GVariant *msg, const char *path)
613 GDBusProxy *adapter_proxy;
615 int result = BLUETOOTH_ERROR_NONE;
616 GVariantIter value_iter;
617 GVariant *val = NULL;
618 GVariant *ret = NULL;
620 char *property = NULL;
621 GVariant *param = NULL;
622 g_variant_iter_init(&value_iter, msg);
623 while ((g_variant_iter_loop(&value_iter, "{sv}", &property, &val))) {
624 BT_INFO("Property %s", property);
626 if (strcasecmp(property, "Discovering") == 0) {
627 gboolean discovering = FALSE;
628 g_variant_get(val, "b", &discovering);
629 /* Send event to application */
630 BT_DBG("Discovering %d", discovering);
631 if (discovering == TRUE) {
632 _bt_set_discovery_status(TRUE);
633 param = g_variant_new("(i)", result);
634 _bt_send_event(BT_ADAPTER_EVENT,
635 BLUETOOTH_EVENT_DISCOVERY_STARTED,
638 ret_if(event_id > 0);
640 adapter_proxy = _bt_get_adapter_proxy();
641 ret_if(adapter_proxy == NULL);
643 /* Need to stop searching */
644 ret = g_dbus_proxy_call_sync(adapter_proxy, "StopDiscovery",
646 G_DBUS_CALL_FLAGS_NONE,
650 BT_ERR("Dbus Error : %s", err->message);
654 g_variant_unref(ret);
656 event_id = g_timeout_add(BT_DISCOVERY_FINISHED_DELAY,
657 (GSourceFunc)_bt_discovery_finished_cb, NULL);
659 } else if (strcasecmp(property, "LEDiscovering") == 0) {
660 gboolean le_discovering = FALSE;
662 g_variant_get(val, "b", &le_discovering);
663 /* Send event to application */
664 if (le_discovering == TRUE) {
665 _bt_set_le_scan_status(TRUE);
666 param = g_variant_new("(i)", result);
667 _bt_send_event(BT_LE_ADAPTER_EVENT,
668 BLUETOOTH_EVENT_LE_DISCOVERY_STARTED,
671 ret_if(event_id > 0);
673 adapter_proxy = _bt_get_adapter_proxy();
674 ret_if(adapter_proxy == NULL);
676 /* Need to stop searching */
677 ret = g_dbus_proxy_call_sync(adapter_proxy, "StopLEDiscovery",
679 G_DBUS_CALL_FLAGS_NONE,
683 BT_ERR("Dbus Error %s", err->message);
687 g_variant_unref(ret);
689 event_id = g_timeout_add(BT_DISCOVERY_FINISHED_DELAY,
690 (GSourceFunc)__bt_le_discovery_finished_cb, NULL);
692 } else if (strcasecmp(property, "Name") == 0) {
694 g_variant_get(val, "s", &name);
695 param = g_variant_new("(is)", result, name);
696 /* Send event to application */
697 _bt_send_event(BT_ADAPTER_EVENT,
698 BLUETOOTH_EVENT_LOCAL_NAME_CHANGED,
701 } else if (strcasecmp(property, "Alias") == 0) {
703 g_variant_get(val, "s", &alias);
704 param = g_variant_new("(is)", result, alias);
705 /* Send event to application */
706 _bt_send_event(BT_ADAPTER_EVENT,
707 BLUETOOTH_EVENT_LOCAL_NAME_CHANGED,
710 } else if (strcasecmp(property, "Discoverable") == 0) {
711 gboolean discoverable = FALSE;
713 g_variant_get(val, "b", &discoverable);
714 BT_DBG("discoverable %d", discoverable);
716 if (discoverable == FALSE) {
717 if (_bt_get_discoverable_timeout_property() > 0) {
719 adapter_proxy = _bt_get_adapter_properties_proxy();
720 ret_if(adapter_proxy == NULL);
721 ret = g_dbus_proxy_call_sync(adapter_proxy, "Set",
722 g_variant_new("(ssv)", BT_ADAPTER_INTERFACE,
723 "DiscoverableTimeout",
724 g_variant_new("i", time)),
725 G_DBUS_CALL_FLAGS_NONE,
730 BT_ERR("StopLEDiscovery Failed: %s", err->message);
734 g_variant_unref(ret);
737 mode = BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE;
739 /* Send event to application */
740 BT_INFO("[Connectable]");
741 param = g_variant_new("(in)", result, mode);
742 _bt_send_event(BT_ADAPTER_EVENT,
743 BLUETOOTH_EVENT_DISCOVERABLE_MODE_CHANGED,
746 _bt_get_discoverable_mode(&mode);
748 /* Event will be sent by "DiscoverableTimeout" signal */
749 if (mode != BLUETOOTH_DISCOVERABLE_MODE_GENERAL_DISCOVERABLE) {
751 g_variant_unref(val);
755 /* Send event to application */
756 BT_INFO("[General Discoverable]");
757 param = g_variant_new("(in)", result, mode);
758 _bt_send_event(BT_ADAPTER_EVENT,
759 BLUETOOTH_EVENT_DISCOVERABLE_MODE_CHANGED,
762 } else if (strcasecmp(property, "DiscoverableTimeout") == 0) {
763 _bt_get_discoverable_mode(&mode);
765 /* Event was already sent by "Discoverable" signal */
766 if (mode == BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE ||
767 mode == BLUETOOTH_DISCOVERABLE_MODE_GENERAL_DISCOVERABLE) {
769 g_variant_unref(val);
773 /* Send event to application */
774 BT_INFO("[Limited Discoverable (Timeout %u secs)]",
775 _bt_get_discoverable_timeout_property());
776 param = g_variant_new("(in)", result, mode);
777 _bt_send_event(BT_ADAPTER_EVENT,
778 BLUETOOTH_EVENT_DISCOVERABLE_MODE_CHANGED,
780 } else if (strcasecmp(property, "Powered") == 0) {
781 /* TODO: Need to check this operation!! */
782 gboolean powered = FALSE;
785 g_variant_get(val, "b", &powered);
786 BT_DBG("Powered = %d", powered);
787 if (powered == FALSE) {
789 _bt_handle_adapter_removed();
791 if (vconf_get_int(VCONFKEY_BT_STATUS, &bt_state) == 0 &&
792 bt_state != VCONFKEY_BT_STATUS_OFF) {
793 if (__bt_handle_is_flight_mode_enabled() == FALSE)
794 _bt_disable_adapter();
796 _bt_handle_adapter_removed();
799 if (vconf_get_int(VCONFKEY_BT_LE_STATUS, &bt_state) == 0 &&
800 bt_state != VCONFKEY_BT_LE_STATUS_OFF) {
801 _bt_set_le_disabled(BLUETOOTH_ERROR_NONE);
805 _bt_handle_adapter_added();
808 } else if (strcasecmp(property, "Connectable") == 0) {
809 gboolean connectable = FALSE;
811 g_variant_get(val, "b", &connectable);
813 BT_DBG("Connectable property is changed : %d", connectable);
814 param = g_variant_new("(b)", connectable);
815 _bt_send_event(BT_ADAPTER_EVENT,
816 BLUETOOTH_EVENT_CONNECTABLE_CHANGED,
819 if (_bt_adapter_get_status() == BT_DEACTIVATING &&
820 _bt_adapter_get_le_status() == BT_LE_ACTIVATED &&
822 _bt_set_disabled(BLUETOOTH_ERROR_NONE);
824 } else if (strcasecmp(property, "SupportedLEFeatures") == 0) {
827 GVariantIter *iter = NULL;
828 g_variant_get(val, "as", &iter);
829 while (g_variant_iter_loop(iter, "s", &name)) {
830 BT_DBG("name = %s", name);
831 g_variant_iter_loop(iter, "s", &value);
832 BT_DBG("Value = %s", value);
833 if (FALSE == _bt_update_le_feature_support(name, value))
834 BT_INFO("Fail to update LE feature info");
837 g_variant_iter_free(iter);
838 } else if (strcasecmp(property, "IpspInitStateChanged") == 0) {
839 gboolean ipsp_initialized = FALSE;
841 g_variant_get(val, "b", &ipsp_initialized);
842 BT_DBG("IPSP init state changed: %d", ipsp_initialized);
843 param = g_variant_new("(b)", ipsp_initialized);
845 /* Send event to application */
846 _bt_send_event(BT_ADAPTER_EVENT,
847 BLUETOOTH_EVENT_IPSP_INIT_STATE_CHANGED,
850 BT_DBG("property : [%s]", property);
855 static void __bt_obex_property_changed_event(GVariant *msg, const char *path)
859 GVariantIter value_iter;
860 GVariant *child = NULL, *val = NULL;
861 char *property = NULL;
862 g_variant_iter_init(&value_iter, msg);
863 while ((child = g_variant_iter_next_value(&value_iter))) {
864 g_variant_get(child, "{sv}", &property, &val);
866 ret_if(property == NULL);
868 BT_DBG("property :%s", property);
870 if (strcasecmp(property, "Status") == 0) {
872 g_variant_get(val, "s", &status);
874 if (strcasecmp(status, "active") == 0) {
875 _bt_obex_transfer_started(path);
876 } else if (strcasecmp(status, "complete") == 0) {
877 _bt_obex_transfer_completed(path, TRUE);
878 _bt_pbap_obex_transfer_completed(path, TRUE);
879 } else if (strcasecmp(status, "error") == 0) {
880 _bt_obex_transfer_completed(path, FALSE);
881 _bt_pbap_obex_transfer_completed(path, FALSE);
884 } else if (strcasecmp(property, "Transferred") == 0) {
885 guint64 transferred = 0;
886 /* As Transferred is expected guint64 so change int to guint64 and
887 * eariler transferred is static because of it can overwrite data
888 * on present on opc_obex_conn or obexd_conn as these are
889 * static memory are in sequential */
890 g_variant_get(val, "t", &transferred);
892 _bt_obex_transfer_progress(path, transferred);
895 g_variant_unref(val);
896 g_variant_unref(child);
901 static void __bt_device_property_changed_event(GVariant *msg, const char *path)
906 int result = BLUETOOTH_ERROR_NONE;
907 GVariantIter value_iter;
909 char *property = NULL;
911 GVariant *param = NULL;
912 bt_remote_dev_info_t *remote_dev_info;
913 g_variant_iter_init(&value_iter, msg);
914 while ((g_variant_iter_loop(&value_iter, "{sv}", &property, &val))) {
915 BT_DBG("Property %s", property);
916 if (strcasecmp(property, "Connected") == 0) {
919 g_variant_get(val, "i", &connected);
921 event = (connected != BLUETOOTH_CONNECTED_LINK_NONE) ?
922 BLUETOOTH_EVENT_DEVICE_CONNECTED :
923 BLUETOOTH_EVENT_DEVICE_DISCONNECTED;
925 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
927 _bt_convert_device_path_to_address(path, address);
929 BT_DBG("connected: %d", connected);
930 BT_DBG("address: %s", address);
932 remote_dev_info = _bt_get_remote_device_info_by_object_path(path);
934 if (remote_dev_info != NULL) {
935 __bt_device_remote_connected_properties(
936 remote_dev_info, address,
937 connected != BLUETOOTH_CONNECTED_LINK_NONE ?
939 _bt_free_device_info(remote_dev_info);
941 param = g_variant_new("(is)", result, address);
942 /* Send event to application */
943 _bt_send_event(BT_DEVICE_EVENT,
947 } else if (strcasecmp(property, "RSSI") == 0) {
948 bt_remote_dev_info_t *remote_dev_info;
950 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
952 _bt_convert_device_path_to_address(path, address);
953 BT_DBG("address: %s", address);
955 remote_dev_info = _bt_get_remote_device_info_by_object_path(path);
956 if (remote_dev_info == NULL) {
958 g_variant_unref(val);
962 BT_DBG("Address type %d", remote_dev_info->addr_type);
964 if (remote_dev_info->addr_type == 0) {
965 BT_DBG("Name %s", remote_dev_info->name);
967 #ifdef TIZEN_DPM_ENABLE
968 if (_bt_dpm_get_bluetooth_desktop_connectivity_state() ==
970 bluetooth_device_class_t device_class;
971 _bt_divide_device_class(&device_class, remote_dev_info->class);
973 if (device_class.major_class ==
974 BLUETOOTH_DEVICE_MAJOR_CLASS_COMPUTER) {
975 _bt_free_device_info(remote_dev_info);
977 g_variant_unref(val);
984 GVariant *uuids = NULL;
985 GVariantBuilder *builder = NULL;
987 builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
988 for (i = 0; i < remote_dev_info->uuid_count; i++) {
989 g_variant_builder_add(builder, "s",
990 remote_dev_info->uuids[i]);
992 uuids = g_variant_new("as", builder);
993 g_variant_builder_unref(builder);
994 GVariant *manufacturer_data = NULL;
995 manufacturer_data = g_variant_new_from_data(G_VARIANT_TYPE_BYTESTRING,
996 remote_dev_info->manufacturer_data,
997 remote_dev_info->manufacturer_data_len,
1000 param = g_variant_new("(isunsbub@asn@ay)", result,
1001 remote_dev_info->address,
1002 remote_dev_info->class,
1003 remote_dev_info->rssi,
1004 remote_dev_info->name,
1005 remote_dev_info->paired,
1006 remote_dev_info->connected,
1007 remote_dev_info->trust,
1009 remote_dev_info->manufacturer_data_len,
1012 _bt_send_event(BT_ADAPTER_EVENT,
1013 BLUETOOTH_EVENT_REMOTE_DEVICE_FOUND,
1017 _bt_free_device_info(remote_dev_info);
1018 } else if (strcasecmp(property, "GattConnected") == 0) {
1019 gboolean gatt_connected = FALSE;
1021 g_variant_get(val, "b", &gatt_connected);
1023 event = gatt_connected ? BLUETOOTH_EVENT_GATT_CONNECTED :
1024 BLUETOOTH_EVENT_GATT_DISCONNECTED;
1026 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1028 _bt_convert_device_path_to_address(path, address);
1030 BT_DBG("gatt_connected: %d", gatt_connected);
1031 BT_DBG("address: %s", address);
1032 param = g_variant_new("(is)", result, address);
1033 /* Send event to application */
1034 _bt_send_event(BT_DEVICE_EVENT,
1038 } else if (strcasecmp(property, "Paired") == 0) {
1039 gboolean paired = FALSE;
1040 bt_remote_dev_info_t *remote_dev_info;
1041 g_variant_get(val, "b", &paired);
1042 _bt_agent_set_canceled(FALSE);
1043 /* BlueZ sends paired signal for each paired device */
1044 /* during activation, We should ignore this, otherwise*/
1045 /* application thinks that a new device got paired */
1046 if (_bt_adapter_get_status() != BT_ACTIVATED) {
1047 BT_DBG("BT is not activated, so ignore this");
1049 g_variant_unref(val);
1053 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1055 _bt_convert_device_path_to_address(path, address);
1057 remote_dev_info = _bt_get_remote_device_info_by_object_path(path);
1058 if (remote_dev_info == NULL) {
1060 g_variant_unref(val);
1065 if (paired == FALSE) {
1066 BT_INFO("Unpaired: %s", address);
1067 __bt_update_remote_cache_devinfo(address, FALSE);
1068 param = g_variant_new("(is)", result, address);
1069 _bt_send_event(BT_ADAPTER_EVENT,
1070 BLUETOOTH_EVENT_BONDED_DEVICE_REMOVED,
1072 #ifdef TIZEN_BT_A2DP_SINK_AUTO_CONNECT
1074 char *last_connected = NULL;
1075 last_connected = vconf_get_str(BT_LAST_CONNECTED_DEVICE);
1076 if (!g_strcmp0(address, last_connected))
1077 _bt_audio_set_auto_connect_device_addr("");
1079 free(last_connected);
1083 char secure_addr[BT_ADDRESS_STRING_SIZE] = { 0 };
1085 _bt_convert_addr_string_to_secure_string(secure_addr, address);
1086 BT_INFO("### Paired: %s", secure_addr);
1087 __bt_update_remote_cache_devinfo(address, TRUE);
1089 if (_bt_is_device_creating() == TRUE) {
1090 BT_DBG("Try to Pair by me");
1091 _bt_free_device_info(remote_dev_info);
1094 g_variant_unref(val);
1097 GVariant *uuids = NULL;
1098 GVariantBuilder *builder = NULL;
1100 builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
1101 for (i = 0; i < remote_dev_info->uuid_count; i++) {
1102 g_variant_builder_add(builder, "s",
1103 remote_dev_info->uuids[i]);
1105 uuids = g_variant_new("as", builder);
1106 g_variant_builder_unref(builder);
1107 GVariant *manufacturer_data = NULL;
1108 manufacturer_data = g_variant_new_from_data(G_VARIANT_TYPE_BYTESTRING,
1109 remote_dev_info->manufacturer_data,
1110 remote_dev_info->manufacturer_data_len,
1114 param = g_variant_new("(isunsbub@asn@ay)", result,
1115 address, remote_dev_info->class,
1116 remote_dev_info->rssi,
1117 remote_dev_info->name,
1118 remote_dev_info->paired,
1119 remote_dev_info->connected,
1120 remote_dev_info->trust,
1122 remote_dev_info->manufacturer_data_len,
1124 _bt_send_event(BT_ADAPTER_EVENT,
1125 BLUETOOTH_EVENT_BONDING_FINISHED,
1128 _bt_free_device_info(remote_dev_info);
1130 } else if (strcasecmp(property, "LegacyPaired") == 0) {
1131 gboolean paired = FALSE;
1132 bt_remote_dev_info_t *remote_dev_info;
1133 unsigned char auth_info[5] = {0, };
1135 if (_bt_adapter_get_status() != BT_ACTIVATED) {
1136 BT_DBG("BT is not activated, so ignore this");
1138 g_variant_unref(val);
1142 g_variant_get(val, "b", &paired);
1143 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1144 BT_DBG("LegacyPaired: %d", paired);
1145 _bt_convert_device_path_to_address(path, address);
1147 remote_dev_info = _bt_get_remote_device_info_by_object_path(path);
1148 if (remote_dev_info == NULL) {
1151 g_variant_unref(val);
1154 if (remote_dev_info->is_alias_set == FALSE) {
1155 /*minimum Size of the samsung specific manufacturer data is greater than 30 */
1156 if ((remote_dev_info->manufacturer_data_len > 30) &&
1157 (remote_dev_info->manufacturer_data[0] == 0x00) &&
1158 (remote_dev_info->manufacturer_data[1] == 0x75)) {
1160 /* 2 samsung (0x00 0x75) + 1 (control and version) + 1 (service ID) +
1161 1 (discovery version) + 1 (associated service ID)
1162 2 (Proxamity and locality) + 2 (Device type and icon) = 10 */
1164 memcpy(auth_info, &(remote_dev_info->manufacturer_data[10]), 5);
1168 BT_DBG("LegacyPairing Failed with %s. Show Error Popup", remote_dev_info->name);
1169 _bt_launch_system_popup(BT_AGENT_EVENT_LEGACY_PAIR_FAILED_FROM_REMOTE,
1170 remote_dev_info->name, auth_info, NULL, NULL, NULL);
1172 _bt_free_device_info(remote_dev_info);
1174 } else if (strcasecmp(property, "Trusted") == 0) {
1175 gboolean trusted = FALSE;
1177 g_variant_get(val, "b", &trusted);
1179 event = trusted ? BLUETOOTH_EVENT_DEVICE_AUTHORIZED :
1180 BLUETOOTH_EVENT_DEVICE_UNAUTHORIZED;
1182 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1184 _bt_convert_device_path_to_address(path, address);
1186 BT_DBG("trusted: %d", trusted);
1187 BT_DBG("address: %s", address);
1188 param = g_variant_new("(is)", result, address);
1189 /* Send event to application */
1190 _bt_send_event(BT_DEVICE_EVENT,
1194 } else if (strcasecmp(property, "TrustedProfiles") == 0) {
1197 g_variant_get(val, "u", &trusted);
1199 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1200 _bt_convert_device_path_to_address(path, address);
1202 BT_DBG("Address: %s, TrustedProfiles: %d", address, trusted);
1203 _bt_send_event(BT_DEVICE_EVENT,
1204 BLUETOOTH_EVENT_SUPPORTED_PROFILE_TRUSTED,
1205 g_variant_new("(isi)", result, address, trusted));
1207 } else if (strcasecmp(property, "IpspConnected") == 0) {
1208 gboolean connected = FALSE;
1210 g_variant_get(val, "b", &connected);
1213 event = connected ? BLUETOOTH_EVENT_IPSP_CONNECTED :
1214 BLUETOOTH_EVENT_IPSP_DISCONNECTED;
1216 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1218 _bt_convert_device_path_to_address(path, address);
1220 BT_DBG("Ipspconnected: %d", connected);
1221 BT_DBG("address: %s", address);
1222 param = g_variant_new("(is)", result, address);
1224 /* Send event to application */
1225 _bt_send_event(BT_DEVICE_EVENT,
1229 } else if (strcasecmp(property, "IpspBtInterfaceInfo") == 0) {
1230 char *ifname = NULL;
1232 g_variant_get(val, "s", &ifname);
1234 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1236 _bt_convert_device_path_to_address(path, address);
1238 BT_DBG("Ipsp BT Interface Name: %s", ifname);
1239 BT_DBG("address: %s", address);
1240 param = g_variant_new("(iss)", result, address, ifname);
1242 /* Send event to application */
1243 _bt_send_event(BT_DEVICE_EVENT,
1244 BLUETOOTH_EVENT_IPSP_INTERFACE_INFO,
1252 static void __bt_media_control_changed_event(GVariant *msg, const char *path)
1255 int result = BLUETOOTH_ERROR_NONE;
1256 GVariantIter value_iter;
1257 char *property = NULL;
1259 GVariant *val = NULL;
1260 GVariant *child = NULL;
1261 bt_remote_dev_info_t *remote_dev_info;
1262 GVariant *param = NULL;
1263 g_variant_iter_init(&value_iter, msg);
1264 while ((child = g_variant_iter_next_value(&value_iter))) {
1265 g_variant_get(child, "{sv}", &property, &val);
1266 BT_INFO("Property %s", property);
1267 if (strcasecmp(property, "Connected") == 0) {
1268 gboolean connected = FALSE;
1270 g_variant_get(val, "b", &connected);
1272 event = connected ? BLUETOOTH_EVENT_AVRCP_CONNECTED :
1273 BLUETOOTH_EVENT_AVRCP_DISCONNECTED;
1275 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1277 _bt_convert_device_path_to_address(path, address);
1279 BT_DBG("connected: %d", connected);
1280 BT_DBG("address: %s", address);
1282 remote_dev_info = _bt_get_remote_device_info(address);
1284 if (remote_dev_info != NULL) {
1285 __bt_device_remote_connected_properties(
1286 remote_dev_info, address, connected);
1287 _bt_free_device_info(remote_dev_info);
1289 param = g_variant_new("(is)", result, address);
1290 /* Send event to application */
1291 _bt_send_event(BT_AVRCP_EVENT,
1297 g_variant_unref(child);
1298 g_variant_unref(val);
1303 int get_alert_level_enum(const char *alert)
1307 if (strcmp(alert, "none") == 0)
1308 lvl = BT_PXP_ALERT_NONE;
1309 else if (strcmp(alert, "mild") == 0)
1310 lvl = BT_PXP_ALERT_MILD;
1311 else if (strcmp(alert, "high") == 0)
1312 lvl = BT_PXP_ALERT_HIGH;
1317 static void _bt_handle_pxp_property_changed_event(GVariant *msg, const char *path, int role)
1319 int result = BLUETOOTH_ERROR_NONE;
1322 GVariantIter value_iter;
1323 char *property = NULL;
1325 GVariant *val = NULL;
1326 GVariant *child = NULL;
1327 GVariant *param = NULL;
1328 g_variant_iter_init(&value_iter, msg);
1331 while ((child = g_variant_iter_next_value(&value_iter))) {
1332 g_variant_get(child, "{sv}", &property, &val);
1333 BT_INFO("Property %s", property);
1335 if ((strcasecmp(property, "LinkLossAlertLevel") == 0) ||
1336 (strcasecmp(property, "ImmediateAlertLevel") == 0)) {
1337 char *alert_str = NULL;
1339 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1340 _bt_convert_device_path_to_address(path, address);
1342 if (strcasecmp(property, "LinkLossAlertLevel") == 0)
1343 service_type = BT_PXP_PROPERTY_LLS;
1345 service_type = BT_PXP_PROPERTY_IAS;
1347 g_variant_get(val, "s", &alert_str);
1348 alert_lvl = get_alert_level_enum(alert_str);
1350 param = g_variant_new("(isiii)", result, address,
1351 role, service_type, alert_lvl);
1353 /* Send event to application */
1354 _bt_send_event(BT_DEVICE_EVENT,
1355 BLUETOOTH_EVENT_PXP_PROPERTY_CHANGED,
1361 g_variant_unref(child);
1362 g_variant_unref(val);
1367 void _bt_handle_property_changed_event(GVariant *msg, const char *object_path)
1369 char *interface_name = NULL;
1370 GVariant *val = NULL;
1372 g_variant_get(msg, "(&s@a{sv}@as)", &interface_name, &val, NULL);
1374 if (strcasecmp(interface_name, BT_ADAPTER_INTERFACE) == 0) {
1375 __bt_adapter_property_changed_event(val,
1377 } else if (strcasecmp(interface_name, BT_DEVICE_INTERFACE) == 0) {
1378 __bt_device_property_changed_event(val, object_path);
1379 } else if (strcasecmp(interface_name, BT_OBEX_TRANSFER_INTERFACE) == 0) {
1380 BT_DBG("BT_OBEX_TRANSFER_INTERFACE");
1381 __bt_obex_property_changed_event(val,
1383 } else if (strcasecmp(interface_name, BT_MEDIA_CONTROL_INTERFACE) == 0) {
1384 __bt_media_control_changed_event(val,
1386 } else if (strcasecmp(interface_name, BT_PLAYER_CONTROL_INTERFACE) == 0) {
1387 _bt_handle_avrcp_control_event(val,
1389 } else if (strcasecmp(interface_name, BT_NETWORK_CLIENT_INTERFACE) == 0) {
1390 BT_DBG("BT_NETWORK_CLIENT_INTERFACE");
1391 _bt_handle_network_client_event(val,
1393 } else if (strcasecmp(interface_name, BT_GATT_CHAR_INTERFACE) == 0) {
1394 __bt_gatt_char_property_changed_event(val,
1396 } else if (strcasecmp(interface_name, BT_PROXIMITY_REPORTER_INTERFACE) == 0) {
1397 BT_DBG("BT_PROXIMITY_REPORTER_INTERFACE");
1398 _bt_handle_pxp_property_changed_event(val,
1399 object_path, BT_PXP_REPORTER_ROLE);
1400 } else if (strcasecmp(interface_name, BT_PROXIMITY_MONITOR_INTERFACE) == 0) {
1401 BT_DBG("BT_PROXIMITY_MONITOR_INTERFACE");
1402 _bt_handle_pxp_property_changed_event(val,
1403 object_path, BT_PXP_MONITOR_ROLE);
1405 g_variant_unref(val);
1408 void __bt_opc_property_changed_event(GVariant *msg,
1411 GVariantIter value_iter;
1412 char *property = NULL;
1413 GVariant *val = NULL;
1414 GVariant *child = NULL;
1416 g_variant_iter_init(&value_iter, msg);
1417 while ((child = g_variant_iter_next_value(&value_iter))) {
1418 g_variant_get(child, "{sv}", &property, &val);
1419 ret_if(property == NULL);
1421 if (strcasecmp(property, "Status") == 0) {
1422 char *status = NULL;
1423 g_variant_get(val, "s", &status);
1424 BT_DBG("Status is %s", status);
1426 if (strcasecmp(status, "active") == 0)
1427 _bt_obex_client_started(path);
1428 else if (strcasecmp(status, "complete") == 0)
1429 _bt_obex_client_completed(path, TRUE);
1430 else if (strcasecmp(status, "error") == 0)
1431 _bt_obex_client_completed(path, FALSE);
1434 } else if (strcasecmp(property, "Transferred") == 0) {
1435 guint64 transferred = 0;
1436 g_variant_get(val, "t", &transferred);
1438 _bt_obex_client_progress(path, transferred);
1440 BT_DBG("property : [%s]", property);
1443 g_variant_unref(child);
1444 g_variant_unref(val);
1448 void _bt_opc_property_changed_event(GVariant *msg, char *path)
1450 char *interface_name = NULL;
1451 GVariant *value = NULL;
1452 g_variant_get(msg, "(&s@a{sv}@as)", &interface_name, &value, NULL);
1453 BT_INFO("interface_name = %s", interface_name);
1454 if (strcasecmp(interface_name, BT_OBEX_TRANSFER_INTERFACE) == 0) {
1455 __bt_opc_property_changed_event(value,
1458 BT_DBG("interface_name : [%s]", interface_name);
1460 g_variant_unref(value);
1464 void _bt_handle_input_event(GVariant *msg, const char *path)
1466 int result = BLUETOOTH_ERROR_NONE;
1467 gboolean property_flag = FALSE;
1468 GVariantIter value_iter;
1469 char *property = NULL;
1470 GVariant *child = NULL, *val = NULL;
1471 bt_remote_dev_info_t *remote_dev_info;
1472 GVariant *param = NULL;
1473 g_variant_iter_init(&value_iter, msg);
1474 while ((child = g_variant_iter_next_value(&value_iter))) {
1475 g_variant_get(child, "{sv}", &property, &val);
1477 ret_if(property == NULL);
1479 if (strcasecmp(property, "Connected") == 0) {
1480 int event = BLUETOOTH_EVENT_NONE;
1482 g_variant_get(val, "b", &property_flag);
1484 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1486 _bt_convert_device_path_to_address(path, address);
1488 event = (property_flag == TRUE) ?
1489 BLUETOOTH_HID_CONNECTED :
1490 BLUETOOTH_HID_DISCONNECTED;
1491 param = g_variant_new("(is)", result, address);
1492 _bt_send_event(BT_HID_EVENT, event,
1494 /* Check HID connection type (Keyboard or Mouse) and update the status */
1495 remote_dev_info = _bt_get_remote_device_info_by_object_path(path);
1497 if (property_flag == TRUE) {
1498 hid_connected_device_count++;
1499 __bt_set_device_values(TRUE,
1500 VCONFKEY_BT_DEVICE_HID_CONNECTED);
1502 hid_connected_device_count--;
1503 if (hid_connected_device_count == 0)
1504 __bt_set_device_values(FALSE,
1505 VCONFKEY_BT_DEVICE_HID_CONNECTED);
1508 if (remote_dev_info != NULL) {
1509 BT_DBG("HID device class [%x]", remote_dev_info->class);
1510 if (remote_dev_info->class &
1511 BLUETOOTH_DEVICE_MINOR_CLASS_KEY_BOARD) {
1512 __bt_set_device_values(property_flag,
1513 VCONFKEY_BT_DEVICE_HID_KEYBOARD_CONNECTED);
1517 if (remote_dev_info->class &
1518 BLUETOOTH_DEVICE_MINOR_CLASS_POINTING_DEVICE) {
1519 __bt_set_device_values(property_flag,
1520 VCONFKEY_BT_DEVICE_HID_MOUSE_CONNECTED);
1522 _bt_free_device_info(remote_dev_info);
1527 g_variant_unref(val);
1528 g_variant_unref(child);
1532 void _bt_handle_network_server_event(GVariant *msg, const char *member)
1534 int result = BLUETOOTH_ERROR_NONE;
1535 char *address = NULL;
1536 char *device = NULL;
1537 GVariant *param = NULL;
1538 ret_if(member == NULL);
1539 if (strcasecmp(member, "PeerConnected") == 0) {
1540 g_variant_get(msg, "(ss)", &device, &address);
1542 __bt_set_device_values(TRUE,
1543 VCONFKEY_BT_DEVICE_PAN_CONNECTED);
1544 param = g_variant_new("(iss)", result, device, address);
1545 _bt_send_event(BT_NETWORK_EVENT, BLUETOOTH_EVENT_NETWORK_SERVER_CONNECTED,
1549 nap_connected_device_count++;
1550 } else if (strcasecmp(member, "PeerDisconnected") == 0) {
1551 g_variant_get(msg, "(ss)", &device, &address);
1552 nap_connected_device_count--;
1553 if (nap_connected_device_count == 0)
1554 __bt_set_device_values(FALSE,
1555 VCONFKEY_BT_DEVICE_PAN_CONNECTED);
1556 param = g_variant_new("(iss)", result, device, address);
1557 _bt_send_event(BT_NETWORK_EVENT, BLUETOOTH_EVENT_NETWORK_SERVER_DISCONNECTED,
1564 void _bt_handle_network_client_event(GVariant *msg,
1569 int result = BLUETOOTH_ERROR_NONE;
1570 gboolean property_flag = FALSE;
1571 char *property = NULL;
1572 GVariant *val = NULL;
1573 GVariantIter value_iter;
1574 GVariant *param = NULL;
1575 g_variant_iter_init(&value_iter, msg);
1576 while ((g_variant_iter_loop(&value_iter, "{sv}", &property, &val))) {
1577 if (strcasecmp(property, "Connected") == 0) {
1578 int event = BLUETOOTH_EVENT_NONE;
1581 g_variant_get(val, "b", &property_flag);
1582 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1584 _bt_convert_device_path_to_address(path, address);
1586 BT_DBG("property_flag %d", property_flag);
1587 if (property_flag == TRUE) {
1588 event = BLUETOOTH_EVENT_NETWORK_CONNECTED;
1589 nap_connected_device_count++;
1590 __bt_set_device_values(TRUE,
1591 VCONFKEY_BT_DEVICE_PAN_CONNECTED);
1593 event = BLUETOOTH_EVENT_NETWORK_DISCONNECTED;
1594 nap_connected_device_count--;
1595 if (nap_connected_device_count == 0)
1596 __bt_set_device_values(FALSE,
1597 VCONFKEY_BT_DEVICE_PAN_CONNECTED);
1599 param = g_variant_new("(is)", result, address);
1600 _bt_send_event(BT_NETWORK_EVENT, event,
1609 void __bt_gatt_char_property_changed_event(GVariant *msg,
1612 GVariantIter value_iter;
1613 char *property = NULL;
1614 char * char_handle = NULL;
1615 GVariant *val = NULL;
1616 int result = BLUETOOTH_ERROR_NONE;
1617 GVariant *param = NULL;
1618 g_variant_iter_init(&value_iter, msg);
1619 char_handle = g_strdup(path);
1620 while ((g_variant_iter_loop(&value_iter, "{sv}", &property, &val))) {
1621 BT_INFO("Property %s", property);
1623 ret_if(property == NULL);
1625 if (strcasecmp(property, "Notifying") == 0) {
1626 gboolean property_flag = FALSE;
1627 g_variant_get(val, "b", &property_flag);
1628 if (property_flag == TRUE)
1629 BT_DBG("notifying is enabled");
1631 BT_DBG("notifying is disabled");
1632 } else if (strcasecmp(property, "ChangedValue") == 0) {
1634 GByteArray *gp_byte_array = NULL;
1635 BT_INFO("Type '%s'\n", g_variant_get_type_string(val));
1638 gp_byte_array = g_byte_array_new();
1639 len = g_variant_get_size(val);
1640 BT_DBG("Len = %d", len);
1641 g_byte_array_append(gp_byte_array,
1642 (const guint8 *) g_variant_get_data(val), len);
1643 if (gp_byte_array->len != 0) {
1644 GVariant *byte_array = NULL;
1645 byte_array = g_variant_new_from_data(
1646 G_VARIANT_TYPE_BYTESTRING,
1647 gp_byte_array->data,
1650 param = g_variant_new("(is@ay)", result, char_handle,
1653 /* Send event only registered client */
1654 _bt_send_char_value_changed_event(param);
1656 g_byte_array_free(gp_byte_array, TRUE);
1660 g_free(char_handle);
1663 void _bt_handle_gatt_event(GVariant *msg, const char *member, const char *path)
1665 ret_if(path == NULL);
1667 if (strcasecmp(member, "GattValueChanged") == 0) {
1670 /*** Debug only ***/
1671 GVariant *value = NULL;
1673 char *buffer = NULL;
1675 g_variant_get(msg, "(is@ay)", NULL, NULL, &value);
1676 value_len = g_variant_get_size(value);
1677 if (value_len > 0) {
1678 char buf[8 * 5 + 1] = { 0 };
1681 buffer = (char *)g_variant_get_data(value);
1682 to = value_len > (sizeof(buf) / 5) ? sizeof(buf) / 5 : value_len;
1684 for (i = 0; i < to; i++)
1685 snprintf(&buf[i * 5], 6, "0x%02x ", buffer[i]);
1687 BT_DBG("GATT Val[%d] %s", value_len, buf);
1689 g_variant_unref(value);
1693 /* Send event only registered client */
1694 _bt_send_char_value_changed_event(msg);
1699 void _bt_handle_device_event(GVariant *msg, const char *member, const char *path)
1702 int result = BLUETOOTH_ERROR_NONE;
1704 char *dev_name = NULL;
1705 const char *property = NULL;
1706 GVariant *param = NULL;
1707 char secure_address[BT_ADDRESS_STRING_SIZE] = { 0 };
1708 ret_if(path == NULL);
1710 if (strcasecmp(member, "PropertyChanged") == 0) {
1712 g_variant_get(msg, "(s)", &property);
1714 ret_if(property == NULL);
1716 if (strcasecmp(property, "GattConnected") == 0) {
1717 gboolean connected = FALSE;
1719 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1720 ret_if(address == NULL);
1722 _bt_convert_device_path_to_address(path, address);
1723 g_variant_get(msg, "(b)", &connected);
1725 event = connected ? BLUETOOTH_EVENT_GATT_CONNECTED :
1726 BLUETOOTH_EVENT_GATT_DISCONNECTED;
1727 param = g_variant_new("(is)", result, address);
1728 _bt_send_event(BT_DEVICE_EVENT,
1732 } else if (strcasecmp(property, "Paired") == 0) {
1733 gboolean paired = FALSE;
1734 bt_remote_dev_info_t *remote_dev_info;
1735 g_variant_get(msg, "(b)", &paired);
1737 ret_if(paired == FALSE);
1739 /* BlueZ sends paired signal for each paired device */
1740 /* during activation, We should ignore this, otherwise*/
1741 /* application thinks that a new device got paired */
1742 if (_bt_adapter_get_status() != BT_ACTIVATED) {
1743 BT_DBG("BT is not activated, so ignore this");
1747 if (_bt_is_device_creating() == TRUE) {
1748 BT_DBG("Try to Pair by me");
1752 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1753 ret_if(address == NULL);
1755 _bt_convert_device_path_to_address(path, address);
1757 remote_dev_info = _bt_get_remote_device_info_by_object_path(path);
1758 if (remote_dev_info == NULL) {
1762 GVariant *uuids = NULL;
1763 GVariantBuilder *builder = NULL;
1765 builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
1766 for (i = 0; i < remote_dev_info->uuid_count; i++) {
1767 g_variant_builder_add(builder, "s",
1768 remote_dev_info->uuids[i]);
1770 uuids = g_variant_new("as", builder);
1771 g_variant_builder_unref(builder);
1772 GVariant *manufacturer_data = NULL;
1773 manufacturer_data = g_variant_new_from_data(
1774 G_VARIANT_TYPE_BYTESTRING,
1775 remote_dev_info->manufacturer_data,
1776 remote_dev_info->manufacturer_data_len,
1778 param = g_variant_new("(isunsbub@asn@ay)", result,
1780 remote_dev_info->class,
1781 remote_dev_info->rssi,
1782 remote_dev_info->name,
1783 remote_dev_info->paired,
1784 remote_dev_info->connected,
1785 remote_dev_info->trust,
1787 remote_dev_info->manufacturer_data_len,
1789 _bt_send_event(BT_ADAPTER_EVENT,
1790 BLUETOOTH_EVENT_BONDING_FINISHED,
1792 _bt_free_device_info(remote_dev_info);
1795 } else if (strcasecmp(property, "UUIDs") == 0) {
1796 /* Once we get the updated uuid information after
1797 * reverse service search, update it to application */
1799 bt_remote_dev_info_t *remote_dev_info;
1801 ret_if(_bt_is_device_creating() == TRUE);
1803 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1804 ret_if(address == NULL);
1806 _bt_convert_device_path_to_address(path, address);
1808 remote_dev_info = _bt_get_remote_device_info_by_object_path(path);
1809 if (remote_dev_info == NULL) {
1814 BT_DBG("UUID's count = %d", remote_dev_info->uuid_count);
1815 if (remote_dev_info->paired && remote_dev_info->uuid_count) {
1816 GVariant *uuids = NULL;
1817 GVariantBuilder *builder = NULL;
1819 builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
1820 for (i = 0; i < remote_dev_info->uuid_count; i++) {
1821 g_variant_builder_add(builder, "s",
1822 remote_dev_info->uuids[i]);
1824 uuids = g_variant_new("as", builder);
1825 g_variant_builder_unref(builder);
1826 GVariant *manufacture_data = g_variant_new_from_data((const GVariantType *)"ay",
1827 remote_dev_info->manufacturer_data, remote_dev_info->manufacturer_data_len,
1830 param = g_variant_new("(isunsbub@asn@ay)", result,
1831 address, remote_dev_info->class,
1832 remote_dev_info->rssi,
1833 remote_dev_info->name,
1834 remote_dev_info->paired,
1835 remote_dev_info->connected,
1836 remote_dev_info->trust,
1838 remote_dev_info->manufacturer_data_len,
1840 _bt_send_event(BT_ADAPTER_EVENT,
1841 BLUETOOTH_EVENT_SERVICE_SEARCHED,
1845 _bt_free_device_info(remote_dev_info);
1848 } else if (strcasecmp(member, "DeviceConnected") == 0) {
1849 unsigned char addr_type = 0;
1851 g_variant_get(msg, "(y)", &addr_type);
1853 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1854 ret_if(address == NULL);
1856 _bt_convert_device_path_to_address(path, address);
1857 dev_name = _bt_get_bonded_device_name(address);
1859 _bt_convert_addr_string_to_secure_string(secure_address, address);
1860 BT_INFO("Address : %s Type : %d", secure_address, addr_type);
1861 BT_ERR_C("### Connected [%s] [%s]", !addr_type ? "BREDR" : "LE",
1862 !addr_type ? dev_name : secure_address);
1865 _bt_logging_connection(TRUE, addr_type);
1866 param = g_variant_new("(isy)", result, address, addr_type);
1867 /*Send event to application*/
1868 _bt_send_event(BT_DEVICE_EVENT,
1869 BLUETOOTH_EVENT_DEVICE_CONNECTED,
1872 } else if (strcasecmp(member, "Disconnected") == 0) {
1873 unsigned char disc_reason = 0;
1874 unsigned char addr_type = 0;
1875 char *dev_name = NULL;
1876 gboolean sending = FALSE;
1878 g_variant_get(msg, "(yys)", &addr_type, &disc_reason, &dev_name);
1880 result = disc_reason;
1882 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1883 ret_if(address == NULL);
1885 _bt_convert_device_path_to_address(path, address);
1887 /* 0x00 BDADDR_BRDER
1888 0x01 BDADDR_LE_PUBLIC
1889 0x02 BDADDR_LE_RANDOM */
1890 _bt_convert_addr_string_to_secure_string(secure_address, address);
1891 BT_INFO("Address : %s Type : %d", secure_address, addr_type);
1892 BT_ERR_C("### Disconnected [%s] [%d : %s] [%s]", !addr_type ? "BREDR" : "LE",
1893 disc_reason, _bt_convert_disc_reason_to_string(disc_reason),
1894 !addr_type ? dev_name : secure_address);
1897 _bt_headset_set_local_connection(FALSE);
1898 _bt_logging_connection(FALSE, addr_type);
1901 #ifdef TIZEN_BT_A2DP_SINK_AUTO_CONNECT
1903 int bt_device_state = VCONFKEY_BT_DEVICE_NONE;
1905 if (vconf_get_int(VCONFKEY_BT_DEVICE, &bt_device_state) != 0)
1906 BT_ERR("vconf_get_int failed");
1908 BT_INFO("conn_state[0x%x], adapter_state [%d]",
1909 bt_device_state, _bt_adapter_get_status());
1911 if (disc_reason == BLUETOOTH_ERROR_CONNECTION_TIMEOUT) {
1912 _bt_audio_start_auto_connect(TRUE);
1913 } else if (bt_device_state &
1914 VCONFKEY_BT_DEVICE_A2DP_SOURCE_CONNECTED) {
1915 BT_INFO("Disconnected due to turning BT off. Skip a address");
1917 char *last_connected = NULL;
1918 last_connected = vconf_get_str(BT_LAST_CONNECTED_DEVICE);
1919 if (!g_strcmp0(address, last_connected))
1920 _bt_audio_set_auto_connect_device_addr("");
1922 free(last_connected);
1927 /*Check for any OPP transfer on the device and cancel
1930 _bt_obex_check_pending_transfer(address);
1931 _bt_opp_client_is_sending(&sending);
1932 if (sending == TRUE)
1933 _bt_opp_client_check_pending_transfer(address);
1935 param = g_variant_new("(isy)", result, address, addr_type);
1936 _bt_send_event(BT_DEVICE_EVENT,
1937 BLUETOOTH_EVENT_DEVICE_DISCONNECTED,
1940 } else if (strcasecmp(member, "ProfileStateChanged") == 0) {
1942 char *profile_uuid = NULL;
1943 bt_headset_wait_t *wait_list;
1944 bluetooth_device_address_t bd_addr;
1946 g_variant_get(msg, "(si)", &profile_uuid, &state);
1948 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1949 ret_if(address == NULL);
1951 _bt_convert_device_path_to_address(path, address);
1952 _bt_convert_addr_string_to_type(bd_addr.addr, address);
1954 _bt_convert_addr_string_to_secure_string(secure_address, address);
1955 BT_DBG("Address: %s", secure_address);
1956 BT_DBG("Profile UUID: %s", profile_uuid);
1957 BT_DBG("State: %d", state);
1959 if ((strcmp(profile_uuid, A2DP_SINK_UUID) == 0) &&
1960 (state == BT_PROFILE_STATE_CONNECTED)) {
1962 int event = BLUETOOTH_EVENT_AV_CONNECTED;
1963 char connected_address[BT_ADDRESS_STRING_SIZE + 1];
1964 bluetooth_device_address_t device_address;
1966 bt_headset_wait_t *wait_list;
1967 guint restricted = 0x0;
1969 __bt_set_device_values(TRUE,
1970 VCONFKEY_BT_DEVICE_A2DP_HEADSET_CONNECTED);
1972 __bt_connection_manager_set_state(address, event);
1974 _bt_get_restrict_profile(&bd_addr, RESTRICTED_PROFILE_HFP_HS, &restricted);
1976 if (_bt_headset_get_local_connection() == FALSE) {
1977 if (restricted == 0x0) /* not restricted*/
1978 _bt_start_timer_for_connection(address, BT_AUDIO_HSP);
1980 /* Connection Started from local device therefore no need to
1981 * intiate connection for pending profile */
1982 _bt_headset_set_local_connection(FALSE);
1984 param = g_variant_new("(is)", result, address);
1985 _bt_send_event(BT_HEADSET_EVENT, event,
1987 connected = _bt_is_headset_type_connected(BT_AUDIO_A2DP,
1990 if (g_strcmp0(connected_address, address) != 0) {
1991 _bt_convert_addr_string_to_type(
1992 device_address.addr,
1994 _bt_audio_disconnect(0, BT_AUDIO_A2DP,
1995 &device_address, NULL);
1999 _bt_add_headset_to_list(BT_AUDIO_A2DP,
2000 BT_STATE_CONNECTED, address);
2002 wait_list = _bt_get_audio_wait_data();
2003 if (wait_list != NULL &&
2004 (g_strcmp0(wait_list->address, address) == 0))
2005 _bt_rel_wait_data();
2007 } else if ((strcmp(profile_uuid, A2DP_SINK_UUID) == 0) &&
2008 (state == BT_PROFILE_STATE_DISCONNECTED)) {
2010 int event = BLUETOOTH_EVENT_AV_DISCONNECTED;
2012 if (!_bt_is_service_connected(address, BT_AUDIO_A2DP)) {
2014 g_free(profile_uuid);
2018 __bt_set_device_values(FALSE,
2019 VCONFKEY_BT_DEVICE_A2DP_HEADSET_CONNECTED);
2021 __bt_connection_manager_set_state(address, event);
2022 param = g_variant_new("(is)", result, address);
2023 _bt_send_event(BT_HEADSET_EVENT, event,
2025 /* Remove data from the connected list */
2026 _bt_remove_headset_from_list(BT_AUDIO_A2DP, address);
2027 wait_list = _bt_get_audio_wait_data();
2029 if (wait_list == NULL) {
2031 g_free(profile_uuid);
2035 if (((wait_list->type == BT_AUDIO_ALL) &&
2036 (wait_list->ag_flag == TRUE)) ||
2037 (wait_list->type == BT_AUDIO_A2DP) ||
2038 (wait_list->disconnection_type == BT_AUDIO_A2DP)) {
2039 bluetooth_device_address_t device_address;
2040 _bt_convert_addr_string_to_type(
2041 device_address.addr,
2042 wait_list->address);
2044 _bt_audio_connect(wait_list->req_id,
2049 } else if (strcmp(profile_uuid, AVRCP_TARGET_UUID) == 0) {
2051 if (state == BT_PROFILE_STATE_CONNECTED) {
2052 int event = BLUETOOTH_EVENT_AVRCP_CONTROL_CONNECTED;
2053 char connected_address[BT_ADDRESS_STRING_SIZE + 1];
2054 bluetooth_device_address_t device_address;
2056 param = g_variant_new("(is)", result, address);
2057 _bt_send_event(BT_AVRCP_CONTROL_EVENT, event,
2059 connected = _bt_is_headset_type_connected(
2063 if (g_strcmp0(connected_address,
2065 _bt_convert_addr_string_to_type(
2066 device_address.addr,
2068 _bt_audio_disconnect(0,
2070 &device_address, NULL);
2073 BT_DBG("device Path: %s", path);
2074 _bt_add_headset_to_list(BT_AVRCP,
2075 BT_STATE_CONNECTED, address);
2076 } else if (state == BT_PROFILE_STATE_DISCONNECTED) {
2077 int event = BLUETOOTH_EVENT_AVRCP_CONTROL_DISCONNECTED;
2078 param = g_variant_new("(is)", result, address);
2079 _bt_send_event(BT_AVRCP_CONTROL_EVENT, event,
2081 /* Remove data from the connected list */
2082 _bt_remove_headset_from_list(BT_AVRCP, address);
2084 } else if (strcasecmp(profile_uuid, A2DP_SOURCE_UUID) == 0) {
2085 if (state == BT_PROFILE_STATE_CONNECTED) {
2086 int event = BLUETOOTH_EVENT_AV_SOURCE_CONNECTED;
2087 BT_INFO("A2DP Source is connected");
2088 #ifdef TIZEN_BT_A2DP_SINK_ENABLE
2089 __bt_set_device_values(TRUE,
2090 VCONFKEY_BT_DEVICE_A2DP_SOURCE_CONNECTED);
2093 #ifdef TIZEN_BT_A2DP_SINK_AUTO_CONNECT
2094 _bt_audio_set_auto_connect_device_addr(address);
2095 _bt_audio_stop_auto_connect();
2097 _bt_add_headset_to_list(BT_AUDIO_A2DP_SOURCE,
2098 BT_STATE_CONNECTED, address);
2099 _bt_send_event(BT_A2DP_SOURCE_EVENT, event,
2100 g_variant_new("(is)", result, address));
2101 } else if (state == BT_PROFILE_STATE_DISCONNECTED) {
2102 int event = BLUETOOTH_EVENT_AV_SOURCE_DISCONNECTED;
2103 BT_INFO("A2DP Source Disconnected");
2104 #ifdef TIZEN_BT_A2DP_SINK_ENABLE
2105 __bt_set_device_values(FALSE,
2106 VCONFKEY_BT_DEVICE_A2DP_SOURCE_CONNECTED);
2108 _bt_remove_headset_from_list(BT_AUDIO_A2DP_SOURCE, address);
2109 _bt_send_event(BT_A2DP_SOURCE_EVENT, event,
2110 g_variant_new("(is)", result, address));
2112 wait_list = _bt_get_audio_wait_data();
2113 if (wait_list && wait_list->type == BT_AUDIO_A2DP_SOURCE) {
2114 bluetooth_device_address_t device_address;
2115 _bt_convert_addr_string_to_type(
2116 device_address.addr,
2117 wait_list->address);
2119 _bt_audio_connect(wait_list->req_id,
2123 /* Now free the wait list */
2124 _bt_rel_wait_data();
2127 } else if ((strcmp(profile_uuid, HID_UUID) == 0) &&
2128 ((state == BT_PROFILE_STATE_CONNECTED) ||
2129 (state == BT_PROFILE_STATE_DISCONNECTED))) {
2131 if (state == BT_PROFILE_STATE_CONNECTED)
2132 event = BLUETOOTH_HID_CONNECTED;
2134 event = BLUETOOTH_HID_DISCONNECTED;
2135 param = g_variant_new("(is)", result, address);
2136 _bt_send_event(BT_HID_EVENT, event,
2138 } else if (strcmp(profile_uuid, HID_DEVICE_UUID) == 0) {
2139 if (state == BT_PROFILE_STATE_CONNECTED) {
2141 event = BLUETOOTH_HID_DEVICE_CONNECTED;
2142 param = g_variant_new("(is)", result, address);
2143 _bt_send_event(BT_HID_DEVICE_EVENT, event,
2145 } else if (state == BT_PROFILE_STATE_DISCONNECTED) {
2146 event = BLUETOOTH_HID_DEVICE_DISCONNECTED;
2147 param = g_variant_new("(is)", result, address);
2148 _bt_send_event(BT_HID_DEVICE_EVENT, event,
2153 g_free(profile_uuid);
2154 } else if (strcasecmp(member, "AdvReport") == 0) {
2156 bt_remote_le_dev_info_t *le_dev_info = NULL;
2157 char *buffer = NULL;
2159 bt_le_adv_info_t *adv_info = NULL;
2160 GVariant *value = NULL;
2161 ret_if(_bt_is_le_scanning() == FALSE);
2163 le_dev_info = g_malloc0(sizeof(bt_remote_le_dev_info_t));
2164 if (le_dev_info == NULL)
2167 g_variant_get(msg, "(syyii@ay)", &le_dev_info->address,
2168 &le_dev_info->addr_type,
2169 &le_dev_info->adv_type,
2171 &le_dev_info->adv_data_len,
2173 _bt_convert_device_path_to_address(path, le_dev_info->address);
2175 buffer_len = g_variant_get_size(value);
2177 buffer = (char *)g_variant_get_data(value);
2179 le_dev_info->adv_data = g_memdup(buffer, buffer_len);
2180 if (le_dev_info->adv_data == NULL &&
2181 le_dev_info->adv_type != BT_LE_ADV_SCAN_RSP) {
2182 _bt_free_le_device_info(le_dev_info);
2183 g_variant_unref(value);
2187 if (_bt_get_le_scan_type() == BT_LE_PASSIVE_SCAN) {
2188 _bt_send_scan_result_event(le_dev_info, NULL);
2189 _bt_free_le_device_info(le_dev_info);
2190 g_variant_unref(value);
2194 if (le_dev_info->adv_type != BT_LE_ADV_SCAN_RSP) { /* ADV_IND */
2195 adv_info = g_malloc0(sizeof(bt_le_adv_info_t));
2196 if (adv_info == NULL) {
2197 _bt_free_le_device_info(le_dev_info);
2198 g_variant_unref(value);
2202 adv_info->addr = g_strdup(le_dev_info->address);
2203 adv_info->addr_type = le_dev_info->addr_type;
2204 adv_info->rssi = le_dev_info->rssi;
2205 adv_info->data_len = le_dev_info->adv_data_len;
2206 adv_info->data = g_malloc0(le_dev_info->adv_data_len);
2207 if (adv_info->data) {
2208 memcpy(adv_info->data, le_dev_info->adv_data,
2209 le_dev_info->adv_data_len);
2212 if (__bt_add_adv_ind_info(adv_info) == 0) {
2213 adv_info->timer_id = g_timeout_add(1000,
2214 (GSourceFunc)__bt_adv_scan_req_timeout_cb, (void*)adv_info);
2216 } else { /* SCAN_RSP */
2217 adv_info = __bt_get_adv_ind_info(le_dev_info->address);
2219 _bt_send_scan_result_event(le_dev_info, adv_info);
2220 __bt_del_adv_ind_info(le_dev_info->address);
2223 _bt_free_le_device_info(le_dev_info);
2224 g_variant_unref(value);
2225 } else if (strcasecmp(member, "LEDataLengthChanged") == 0) {
2226 guint16 tx_octets = 0;
2227 guint16 tx_time = 0;
2228 guint16 rx_octets = 0;
2229 guint16 rx_time = 0;
2231 g_variant_get(msg, "(qqqq)",
2232 &tx_octets, &tx_time, &rx_octets, &rx_time);
2234 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
2235 _bt_convert_device_path_to_address(path, address);
2237 param = g_variant_new("(isqqqq)", result, address, tx_octets, tx_time,
2238 rx_octets, rx_time);
2239 /* Send event to application */
2240 _bt_send_event(BT_DEVICE_EVENT,
2241 BLUETOOTH_EVENT_LE_DATA_LENGTH_CHANGED, param);
2243 } else if (strcasecmp(member, "IpspStateChanged") == 0) {
2244 gboolean connected = FALSE;
2245 char *ifname = NULL;
2247 g_variant_get(msg, "(bs)", &connected, &ifname);
2249 event = connected ? BLUETOOTH_EVENT_IPSP_CONNECTED :
2250 BLUETOOTH_EVENT_IPSP_DISCONNECTED;
2252 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
2253 _bt_convert_device_path_to_address(path, address);
2255 BT_DBG("Ipsp BT Interface Name: %s", ifname);
2256 BT_DBG("address: %s", address);
2257 param = g_variant_new("(iss)", result, address, ifname);
2259 /* Send event to application */
2260 _bt_send_event(BT_DEVICE_EVENT,
2267 void __bt_set_audio_values(gboolean connected, char *address)
2270 int bt_device_state = VCONFKEY_BT_DEVICE_NONE;
2272 /* Set the headset name */
2273 if (connected == TRUE)
2274 name = _bt_get_bonded_device_name(address);
2276 name = g_strdup("");
2278 if (vconf_set_str(VCONFKEY_BT_HEADSET_NAME, name) != 0)
2279 BT_ERR("vconf_set_str failed");
2283 /* Set the headset state */
2284 if (vconf_get_int(VCONFKEY_BT_DEVICE, &bt_device_state) != 0)
2285 BT_ERR("vconf_get_int failed");
2287 #ifdef TIZEN_SUPPORT_DUAL_HF
2288 if ((connected == TRUE) &&
2289 (FALSE == __bt_is_companion_device(address))) {
2290 bt_device_state |= VCONFKEY_BT_DEVICE_HEADSET_CONNECTED;
2291 } else if ((bt_device_state & VCONFKEY_BT_DEVICE_HEADSET_CONNECTED) &&
2292 (FALSE == __bt_is_companion_device(address))) {
2293 bt_device_state ^= VCONFKEY_BT_DEVICE_HEADSET_CONNECTED;
2296 if (connected == TRUE)
2297 bt_device_state |= VCONFKEY_BT_DEVICE_HEADSET_CONNECTED;
2298 else if (bt_device_state & VCONFKEY_BT_DEVICE_HEADSET_CONNECTED)
2299 bt_device_state ^= VCONFKEY_BT_DEVICE_HEADSET_CONNECTED;
2302 if (vconf_set_int(VCONFKEY_BT_DEVICE,
2303 bt_device_state) != 0) {
2304 BT_ERR("vconf_set_int failed");
2308 void _bt_handle_headset_event(GVariant *msg, const char *path)
2310 int result = BLUETOOTH_ERROR_NONE;
2311 gboolean property_flag = FALSE;
2312 char *property = NULL;
2313 GVariant *value = NULL;
2314 GVariant *param = NULL;
2315 g_variant_get(msg, "(sv)", &property, &value);
2316 bluetooth_device_address_t bd_addr;
2318 ret_if(property == NULL);
2320 BT_DBG("Property = %s \n", property);
2321 /* We allow only 1 headset connection (HSP or HFP)*/
2322 if (strcasecmp(property, "Connected") == 0) {
2323 int event = BLUETOOTH_EVENT_NONE;
2324 bt_headset_wait_t *wait_list;
2326 guint restricted = 0x0;
2327 g_variant_get(value, "b", &property_flag);
2329 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
2330 if (address == NULL)
2333 _bt_convert_device_path_to_address(path, address);
2334 _bt_convert_addr_string_to_type(bd_addr.addr, address);
2336 if (property_flag == TRUE) {
2337 event = BLUETOOTH_EVENT_AG_CONNECTED;
2338 _bt_get_restrict_profile(&bd_addr, RESTRICTED_PROFILE_A2DP, &restricted);
2340 if (_bt_headset_get_local_connection() == FALSE) {
2341 if (restricted == 0x0) /* not restricted*/
2342 _bt_start_timer_for_connection(address, BT_AUDIO_A2DP);
2344 _bt_headset_set_local_connection(FALSE);
2348 event = BLUETOOTH_EVENT_AG_DISCONNECTED;
2350 previous_state = _bt_get_device_state_from_list(BT_AUDIO_HSP, address);
2351 if (previous_state == BT_STATE_DISCONNECTING)
2352 _bt_send_hf_local_term_event(address);
2354 /* Set the State machine here */
2355 __bt_connection_manager_set_state(address, event);
2356 __bt_set_audio_values(property_flag, address);
2357 param = g_variant_new("(is)", result, address);
2358 _bt_send_event(BT_HEADSET_EVENT, event,
2361 if (event == BLUETOOTH_EVENT_AG_DISCONNECTED) {
2362 /* Remove data from the connected list */
2363 _bt_remove_headset_from_list(BT_AUDIO_HSP, address);
2365 wait_list = _bt_get_audio_wait_data();
2366 if (wait_list == NULL) {
2371 bluetooth_device_address_t device_address;
2373 _bt_set_audio_wait_data_flag(TRUE);
2375 _bt_convert_addr_string_to_type(device_address.addr,
2376 wait_list->address);
2377 _bt_audio_connect(wait_list->req_id, wait_list->type,
2378 &device_address, NULL);
2379 _bt_rel_wait_data();
2380 } else if (event == BLUETOOTH_EVENT_AG_CONNECTED) {
2381 /* Add data to the connected list */
2382 _bt_add_headset_to_list(BT_AUDIO_HSP,
2383 BT_STATE_CONNECTED, address);
2385 wait_list = _bt_get_audio_wait_data();
2386 if (wait_list != NULL &&
2387 (g_strcmp0(wait_list->address, address) == 0))
2388 _bt_rel_wait_data();
2390 BT_INFO("Check A2DP pending connect");
2391 _bt_audio_check_pending_connect();
2394 } else if (strcasecmp(property, "State") == 0) {
2397 g_variant_get(value, "s", &state);
2399 /* This code assumes we support only 1 headset connection */
2400 /* Need to use the headset list, if we support multi-headsets */
2401 if (strcasecmp(state, "Playing") == 0) {
2402 BT_DBG("Playing: Sco Connected");
2403 } else if (strcasecmp(state, "connected") == 0 ||
2404 strcasecmp(state, "disconnected") == 0) {
2405 BT_DBG("connected/disconnected: Sco Disconnected");
2407 BT_ERR("Not handled state - %s", state);
2412 } else if (strcasecmp(property, "SpeakerGain") == 0) {
2416 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
2418 _bt_convert_device_path_to_address(path, address);
2420 spkr_gain = g_variant_get_uint16(value);
2422 BT_DBG("spkr_gain: %d", spkr_gain);
2424 param = g_variant_new("(i&sq)", result, address, spkr_gain);
2425 _bt_send_event(BT_HEADSET_EVENT, BLUETOOTH_EVENT_AG_SPEAKER_GAIN,
2429 } else if (strcasecmp(property, "MicrophoneGain") == 0) {
2433 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
2435 _bt_convert_device_path_to_address(path, address);
2437 mic_gain = g_variant_get_uint16(value);
2439 param = g_variant_new("(i&sq)", result, address, mic_gain);
2440 _bt_send_event(BT_HEADSET_EVENT, BLUETOOTH_EVENT_AG_MIC_GAIN,
2447 g_variant_unref(value);
2450 void _bt_handle_sink_event(GVariant *msg, const char *path)
2452 GVariantIter value_iter;
2453 char *property = NULL;
2455 bt_headset_wait_t *wait_list;
2457 GVariant *child = NULL;
2458 GVariant *val = NULL;
2459 GVariant *param = NULL;
2460 g_variant_iter_init(&value_iter, msg);
2461 while ((child = g_variant_iter_next_value(&value_iter))) {
2463 g_variant_get(child, "{sv}", &property, &val);
2465 ret_if(property == NULL);
2467 BT_DBG("Property = %s \n", property);
2470 if (strcasecmp(property, "State") == 0) {
2471 int result = BLUETOOTH_ERROR_NONE;
2474 g_variant_get(val, "s", &value);
2475 BT_DBG("value: %s", value);
2477 if (g_strcmp0(value, "disconnected") == 0) {
2480 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
2482 _bt_convert_device_path_to_address(path, address);
2484 __bt_set_device_values(FALSE,
2485 VCONFKEY_BT_DEVICE_A2DP_HEADSET_CONNECTED);
2486 param = g_variant_new("(is)", result, address);
2487 _bt_send_event(BT_HEADSET_EVENT,
2488 BLUETOOTH_EVENT_AV_DISCONNECTED,
2491 /* Remove data from the connected list */
2492 _bt_remove_headset_from_list(BT_AUDIO_A2DP, address);
2493 wait_list = _bt_get_audio_wait_data();
2494 if (wait_list == NULL) {
2497 g_variant_unref(val);
2498 g_variant_unref(child);
2503 if (((wait_list->type == BT_AUDIO_ALL) &&
2504 (wait_list->ag_flag == TRUE)) ||
2505 (wait_list->type == BT_AUDIO_A2DP) ||
2506 (wait_list->disconnection_type == BT_AUDIO_A2DP)) {
2507 bluetooth_device_address_t device_address;
2508 _bt_convert_addr_string_to_type(
2509 device_address.addr,
2510 wait_list->address);
2512 _bt_audio_connect(wait_list->req_id,
2518 } else if (strcasecmp(value, "Connected") == 0) {
2520 char connected_address[BT_ADDRESS_STRING_SIZE + 1];
2521 bluetooth_device_address_t device_address;
2524 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
2526 _bt_convert_device_path_to_address(path, address);
2528 __bt_set_device_values(TRUE,
2529 VCONFKEY_BT_DEVICE_A2DP_HEADSET_CONNECTED);
2530 param = g_variant_new("(is)", result, address);
2531 _bt_send_event(BT_HEADSET_EVENT,
2532 BLUETOOTH_EVENT_AV_CONNECTED,
2534 /* Check for existing Media device to disconnect */
2535 connected = _bt_is_headset_type_connected(BT_AUDIO_A2DP,
2538 /* Match connected device address */
2539 if (g_strcmp0(connected_address, address) != 0) {
2540 /* Convert BD adress from string type */
2541 _bt_convert_addr_string_to_type(
2542 device_address.addr,
2544 _bt_audio_disconnect(0, BT_AUDIO_A2DP,
2545 &device_address, NULL);
2549 /* Add data to the connected list */
2550 _bt_add_headset_to_list(BT_AUDIO_A2DP,
2551 BT_STATE_CONNECTED, address);
2558 g_variant_unref(val);
2559 g_variant_unref(child);
2563 void _bt_handle_agent_event(GVariant *msg, const char *member)
2565 int result = BLUETOOTH_ERROR_NONE;
2566 char *address = NULL;
2569 GVariant *param = NULL;
2570 ret_if(member == NULL);
2572 if (strcasecmp(member, "ObexAuthorize") == 0) {
2573 __bt_get_agent_signal_info(msg, &address, &name, &uuid);
2574 param = g_variant_new("(iss)", result, address, name);
2575 _bt_send_event(BT_OPP_SERVER_EVENT,
2576 BLUETOOTH_EVENT_OBEX_SERVER_CONNECTION_AUTHORIZE,
2580 } else if (strcasecmp(member, "RfcommAuthorize") == 0) {
2581 bt_rfcomm_server_info_t *server_info;
2583 __bt_get_agent_signal_info(msg, &address, &name, &uuid);
2585 server_info = _bt_rfcomm_get_server_info_using_uuid(uuid);
2586 ret_if(server_info == NULL);
2587 ret_if(server_info->server_type != BT_CUSTOM_SERVER);
2588 param = g_variant_new("(isssn)", result, address, uuid, name,
2589 server_info->control_fd);
2590 _bt_send_event(BT_RFCOMM_SERVER_EVENT,
2591 BLUETOOTH_EVENT_RFCOMM_AUTHORIZE,
2599 static int __bt_get_object_path(GVariant *msg, char **path)
2601 g_variant_get(msg, "(o*)", path, NULL);
2603 return BLUETOOTH_ERROR_INTERNAL;
2605 return BLUETOOTH_ERROR_NONE;
2608 static void __bt_devices_list_free(void)
2610 bt_cache_info_t *cache_info;
2613 node = g_list_first(p_cache_list);
2615 while (node != NULL) {
2616 cache_info = (bt_cache_info_t *)node->data;
2617 p_cache_list = g_list_remove(p_cache_list, cache_info);
2618 __bt_free_cache_info(cache_info);
2620 node = g_list_next(node);
2624 static int __bt_parse_event(GVariant *msg)
2628 char *interface_name = NULL;
2629 GVariant *inner_iter = NULL;
2631 g_variant_iter_init(&iter, msg);
2633 while ((child = g_variant_iter_next_value(&iter))) {
2634 g_variant_get(child, "{&s@a{sv}}", &interface_name, &inner_iter);
2635 if (g_strcmp0(interface_name,
2636 BT_DEVICE_INTERFACE) == 0) {
2637 g_variant_unref(inner_iter);
2638 g_variant_unref(child);
2639 return BT_DEVICE_EVENT;
2640 } else if (g_strcmp0(interface_name,
2641 BT_MEDIATRANSPORT_INTERFACE) == 0) {
2642 g_variant_unref(inner_iter);
2643 g_variant_unref(child);
2644 return BT_MEDIA_TRANSFER_EVENT;
2645 } else if (g_strcmp0(interface_name,
2646 BT_PLAYER_CONTROL_INTERFACE) == 0) {
2647 g_variant_unref(inner_iter);
2648 g_variant_unref(child);
2649 return BT_AVRCP_CONTROL_EVENT;
2651 g_variant_unref(inner_iter);
2652 g_variant_unref(child);
2658 static void __bt_manager_event_filter(GDBusConnection *connection,
2659 const gchar *sender_name,
2660 const gchar *object_path,
2661 const gchar *interface_name,
2662 const gchar *signal_name,
2663 GVariant *parameters,
2666 bt_event_type_t bt_event = 0x00;
2667 int result = BLUETOOTH_ERROR_NONE;
2669 char *obj_path = NULL;
2670 GVariant *param = NULL;
2671 if (signal_name == NULL)
2673 if (strcasecmp(signal_name, "InterfacesAdded") == 0) {
2674 g_variant_get(parameters, "(&o@a{sa{sv}})", &obj_path, &value);
2676 if (strcasecmp(obj_path, BT_BLUEZ_HCI_PATH) == 0) {
2677 #ifdef USB_BLUETOOTH
2678 BT_DBG("Enable Adapter");
2679 _bt_enable_adapter();
2681 _bt_handle_adapter_added();
2684 bt_event = __bt_parse_event(value);
2685 if (bt_event == BT_DEVICE_EVENT) {
2686 bt_cache_info_t *cache_info;
2687 bt_remote_dev_info_t *dev_info;
2689 ret_if(_bt_is_discovering() == FALSE &&
2690 _bt_is_le_scanning() == FALSE);
2692 cache_info = g_malloc0(sizeof(bt_cache_info_t));
2693 ret_if(cache_info == NULL);
2695 dev_info = g_malloc0(sizeof(bt_remote_dev_info_t));
2696 if (dev_info == NULL) {
2697 __bt_free_cache_info(cache_info);
2701 cache_info->dev_info = dev_info;
2703 if (__bt_parse_interface(parameters, dev_info) == FALSE) {
2704 BT_ERR("Fail to parse the properies");
2705 __bt_free_cache_info(cache_info);
2706 g_variant_unref(value);
2710 if (dev_info->addr_type != BDADDR_BREDR) {
2711 /* Whenever emit the property changed from bluez,
2712 some property doesn't reach to bt-service.
2713 So LE device is handled as AdvReport signal */
2714 __bt_free_cache_info(cache_info);
2715 g_variant_unref(value);
2719 if (dev_info->name == NULL)
2720 /* If Remote device name is NULL or still RNR is not done
2721 * then display address as name.
2723 dev_info->name = g_strdup(dev_info->address);
2725 #ifdef TIZEN_DPM_ENABLE
2726 if (_bt_dpm_get_bluetooth_desktop_connectivity_state() ==
2728 bluetooth_device_class_t device_class;
2729 _bt_divide_device_class(&device_class, dev_info->class);
2730 BT_DBG("[%s]device_class.major_class : %d", dev_info->name, device_class.major_class);
2732 if (device_class.major_class ==
2733 BLUETOOTH_DEVICE_MAJOR_CLASS_COMPUTER) {
2734 __bt_free_cache_info(cache_info);
2735 g_variant_unref(value);
2741 GVariant *uuids = NULL;
2742 GVariantBuilder *builder = NULL;
2744 builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
2745 for (i = 0; i < dev_info->uuid_count; i++) {
2746 g_variant_builder_add(builder, "s",
2747 dev_info->uuids[i]);
2749 uuids = g_variant_new("as", builder);
2750 g_variant_builder_unref(builder);
2751 GVariant *manufacturer_data = NULL;
2752 manufacturer_data = g_variant_new_from_data(
2753 G_VARIANT_TYPE_BYTESTRING,
2754 dev_info->manufacturer_data,
2755 dev_info->manufacturer_data_len,
2757 param = g_variant_new("(isunsbub@asn@ay)", result,
2763 dev_info->connected,
2766 dev_info->manufacturer_data_len,
2768 _bt_send_event(BT_ADAPTER_EVENT,
2769 BLUETOOTH_EVENT_REMOTE_DEVICE_FOUND,
2771 p_cache_list = g_list_append(p_cache_list, cache_info);
2772 } else if (bt_event == BT_AVRCP_CONTROL_EVENT) {
2773 BT_DBG("Device path : %s ", obj_path);
2774 _bt_set_control_device_path(obj_path);
2777 g_variant_unref(value);
2778 } else if (strcasecmp(signal_name, "InterfacesRemoved") == 0) {
2779 #ifdef USB_BLUETOOTH
2780 BT_DBG("InterfacesRemoved");
2781 _bt_handle_adapter_removed();
2783 if (g_strcmp0(interface_name, BT_MEDIATRANSPORT_INTERFACE) == 0)
2784 bt_event = BT_MEDIA_TRANSFER_EVENT;
2785 else if (g_strcmp0(interface_name, BT_DEVICE_INTERFACE) == 0)
2786 bt_event = BT_DEVICE_EVENT;
2787 else if (g_strcmp0(interface_name, BT_PLAYER_CONTROL_INTERFACE) == 0)
2788 bt_event = BT_AVRCP_CONTROL_EVENT;
2790 if ((bt_event != 0) && (bt_event != BT_MEDIA_TRANSFER_EVENT)) {
2791 _bt_handle_adapter_event(parameters, signal_name);
2792 if (bt_event == BT_AVRCP_CONTROL_EVENT) {
2793 BT_INFO("Object Path %s", obj_path);
2794 _bt_remove_control_device_path(obj_path);
2797 } else if (strcasecmp(signal_name, "NameOwnerChanged") == 0) {
2800 char *previous = NULL;
2801 char *current = NULL;
2803 if (__bt_get_owner_info(parameters, &name, &previous, ¤t)) {
2804 BT_ERR("Fail to get the owner info");
2808 if (*current != '\0') {
2817 if (strcasecmp(name, BT_BLUEZ_NAME) == 0) {
2818 BT_DBG("Bluetoothd is terminated");
2819 if (_bt_adapter_get_status() == BT_ACTIVATED)
2822 _bt_handle_adapter_removed();
2823 __bt_devices_list_free();
2826 _bt_obex_server_check_allocation(&value);
2828 if (value == TRUE) {
2829 /* Check if the obex server was terminated abnormally */
2830 _bt_obex_server_check_termination(name);
2833 _bt_rfcomm_server_check_existence(&value);
2835 if (value == TRUE) {
2836 /* The obex server was terminated abnormally */
2837 _bt_rfcomm_server_check_termination(name);
2840 /* Stop advertising started by terminated process */
2841 _bt_stop_advertising_by_terminated_process(name);
2843 _bt_stop_le_scan(name);
2847 } else if (g_strcmp0(interface_name, BT_PROPERTIES_INTERFACE) == 0) {
2848 const char *path = object_path;
2850 if (strncmp(path, BT_MEDIA_OBJECT_PATH,
2851 strlen(BT_MEDIA_OBJECT_PATH)) == 0)
2854 _bt_handle_property_changed_event(parameters, object_path);
2855 } else if (g_strcmp0(interface_name, BT_ADAPTER_INTERFACE) == 0) {
2856 _bt_handle_adapter_event(parameters, signal_name);
2857 } else if (g_strcmp0(interface_name, BT_INPUT_INTERFACE) == 0) {
2858 _bt_handle_input_event(parameters, object_path);
2859 } else if (g_strcmp0(interface_name, BT_NETWORK_SERVER_INTERFACE) == 0) {
2860 _bt_handle_network_server_event(parameters, signal_name);
2861 } else if (g_strcmp0(interface_name, BT_HEADSET_INTERFACE) == 0) {
2862 _bt_handle_headset_event(parameters, object_path);
2863 } else if (g_strcmp0(interface_name, BT_SINK_INTERFACE) == 0) {
2864 _bt_handle_sink_event(parameters, object_path);
2865 } else if (g_strcmp0(interface_name, BT_AGENT_INTERFACE) == 0) {
2866 _bt_handle_agent_event(parameters, signal_name);
2867 } else if (g_strcmp0(interface_name, BT_DEVICE_INTERFACE) == 0) {
2868 _bt_handle_device_event(parameters, signal_name, object_path);
2869 } else if (g_strcmp0(interface_name, BT_GATT_CHAR_INTERFACE) == 0) {
2870 _bt_handle_gatt_event(parameters, signal_name, object_path);
2876 static gboolean __bt_is_obexd_event(GVariant *msg, const char *interface)
2879 if (g_strcmp0(interface, BT_PROPERTIES_INTERFACE) == 0) {
2880 char *interface_name = NULL;
2882 g_variant_get(msg, "(&s@a{sv}@as)", &interface_name, NULL, NULL);
2883 retv_if(interface_name == NULL, FALSE);
2885 if (strcasecmp(interface_name, BT_OBEX_TRANSFER_INTERFACE) == 0) {
2886 BT_DBG("BT_OBEX_TRANSFER_INTERFACE");
2894 static void __bt_obexd_event_filter(GDBusConnection *connection,
2895 const gchar *sender_name,
2896 const gchar *object_path,
2897 const gchar *interface_name,
2898 const gchar *signal_name,
2899 GVariant *parameters,
2902 const char *member = signal_name;
2903 char *obj_path = NULL;
2904 ret_if(member == NULL);
2906 if (strcasecmp(member, "InterfacesAdded") == 0) {
2907 if (__bt_get_object_path(parameters, &obj_path)) {
2908 BT_ERR("Fail to get the path");
2911 BT_INFO("object_path = [%s]", obj_path);
2913 /*Handle OPP_SERVER_CONNECTED_EVENT here */
2914 if (strncmp(obj_path, BT_SESSION_BASEPATH_SERVER,
2915 strlen(BT_SESSION_BASEPATH_SERVER)) != 0) {
2920 if (g_strrstr(obj_path, "session") && g_strrstr(obj_path, "transfer")) {
2921 BT_DBG("Obex_Server_Session_Transfer connected");
2922 _bt_obex_transfer_connected(obj_path);
2925 } else if (strcasecmp(member, "InterfacesRemoved") == 0) {
2926 /*Handle OPP_SERVER_DISCONNECTED_EVENT here */
2927 if (__bt_get_object_path(parameters, &obj_path)) {
2928 BT_ERR("Fail to get the path");
2931 BT_INFO("object_path = [%s]", obj_path);
2933 if (strncmp(obj_path, BT_SESSION_BASEPATH_CLIENT,
2934 strlen(BT_SESSION_BASEPATH_CLIENT)) == 0) {
2935 BT_DBG("Call PBAP Disconnected");
2936 _bt_obex_pbap_client_disconnect(obj_path);
2939 if (strncmp(obj_path, BT_SESSION_BASEPATH_SERVER,
2940 strlen(BT_SESSION_BASEPATH_SERVER)) != 0) {
2945 if (g_strrstr(obj_path, "session") && g_strrstr(obj_path, "transfer")) {
2946 BT_DBG("Obex_Server_Session_Transfer disconnected %s",
2949 _bt_obex_transfer_disconnected(obj_path);
2952 } else if (__bt_is_obexd_event(parameters, interface_name) == TRUE) {
2953 const char *path = object_path;
2955 if (strncmp(path, BT_SESSION_BASEPATH_SERVER,
2956 strlen(BT_SESSION_BASEPATH_SERVER)) != 0 &&
2957 strncmp(path, BT_SESSION_BASEPATH_CLIENT,
2958 strlen(BT_SESSION_BASEPATH_CLIENT)) != 0) {
2959 BT_DBG("DBUS_HANDLER_RESULT_NOT_YET_HANDLED");
2963 _bt_handle_property_changed_event(parameters, path);
2969 static gboolean __bt_is_obexd_client_event(GVariant *msg, const char *interface)
2973 if (g_strcmp0(interface, BT_PROPERTIES_INTERFACE) == 0) {
2974 char *interface_name = NULL;
2976 g_variant_get(msg, "(&s@a{sv}@as)", &interface_name, NULL, NULL);
2978 retv_if(interface_name == NULL, FALSE);
2980 if (strcasecmp(interface_name,
2981 BT_OBEX_TRANSFER_INTERFACE) == 0) {
2992 static void __bt_opc_event_filter(GDBusConnection *connection,
2993 const gchar *sender_name,
2994 const gchar *object_path,
2995 const gchar *interface_name,
2996 const gchar *signal_name,
2997 GVariant *parameters,
3000 const char *member = signal_name;
3001 char *obj_path = NULL;
3002 if (strcasecmp(member, "InterfacesAdded") == 0) {
3003 BT_DBG("InterfacesAdded");
3004 } else if (strcasecmp(member, "InterfacesRemoved") == 0) {
3006 if (__bt_get_object_path(parameters, &obj_path)) {
3007 BT_ERR("Fail to get the path");
3011 BT_DBG("object_path = %s", obj_path);
3013 if (strncmp(obj_path, BT_SESSION_BASEPATH_CLIENT,
3014 strlen(BT_SESSION_BASEPATH_CLIENT)) != 0
3015 || strstr(obj_path, "transfer") == NULL) {
3018 } else if (strncmp(obj_path, BT_SESSION_BASEPATH_CLIENT,
3019 strlen(BT_SESSION_BASEPATH_CLIENT)) == 0) {
3020 BT_DBG("Going to call opc disconnected");
3021 _bt_opc_disconnected(obj_path);
3024 _bt_sending_files();
3026 } else if (__bt_is_obexd_client_event(parameters, interface_name) == TRUE) {
3027 char *path = (char *)object_path;
3028 BT_INFO("object_path %s", path);
3029 if (strncmp(path, BT_SESSION_BASEPATH_CLIENT,
3030 strlen(BT_SESSION_BASEPATH_CLIENT)) != 0) {
3031 BT_DBG("NOT BT_SESSION_BASEPATH_CLIENT");
3035 _bt_opc_property_changed_event(parameters, path);
3041 int _bt_opp_client_event_init(void)
3043 GError *error = NULL;
3045 if (opc_obexd_conn == NULL) {
3046 opc_obexd_conn = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &error);
3048 if (!opc_obexd_conn) {
3050 BT_ERR("Unable to connect to dbus: %s", error->message);
3051 g_clear_error(&error);
3053 return BLUETOOTH_ERROR_INTERNAL;
3057 if (_bt_register_service_event(opc_obexd_conn,
3058 BT_OPP_CLIENT_EVENT) != BLUETOOTH_ERROR_NONE) {
3059 g_object_unref(opc_obexd_conn);
3060 opc_obexd_conn = NULL;
3061 return BLUETOOTH_ERROR_INTERNAL;
3064 return BLUETOOTH_ERROR_NONE;
3067 void _bt_opp_client_event_deinit(void)
3069 if (opc_obexd_conn) {
3070 _bt_unregister_service_event(opc_obexd_conn,
3071 BT_OPP_CLIENT_EVENT);
3072 g_object_unref(opc_obexd_conn);
3073 opc_obexd_conn = NULL;
3077 int _bt_register_manager_subscribe_signal(GDBusConnection *conn,
3083 static int subs_interface_added_id = -1;
3084 static int subs_interface_removed_id = -1;
3085 static int subs_name_owner_id = -1;
3086 static int subs_property_id = -1;
3087 static int subs_adapter_id = -1;
3088 static int subs_gatt_id = -1;
3091 if (subs_interface_added_id == -1) {
3092 subs_interface_added_id = g_dbus_connection_signal_subscribe(conn,
3093 NULL, BT_MANAGER_INTERFACE,
3094 BT_INTERFACES_ADDED, NULL, NULL, 0,
3095 __bt_manager_event_filter,
3098 if (subs_interface_removed_id == -1) {
3099 subs_interface_removed_id = g_dbus_connection_signal_subscribe(conn,
3100 NULL, BT_MANAGER_INTERFACE,
3101 BT_INTERFACES_REMOVED, NULL, NULL, 0,
3102 __bt_manager_event_filter,
3105 if (subs_name_owner_id == -1) {
3106 subs_name_owner_id = g_dbus_connection_signal_subscribe(conn,
3107 NULL, BT_FREEDESKTOP_INTERFACE,
3108 BT_NAME_OWNER_CHANGED, NULL, NULL, 0,
3109 __bt_manager_event_filter,
3112 if (subs_property_id == -1) {
3113 subs_property_id = g_dbus_connection_signal_subscribe(conn,
3114 NULL, BT_PROPERTIES_INTERFACE,
3115 BT_PROPERTIES_CHANGED, NULL, NULL, 0,
3116 __bt_manager_event_filter,
3119 if (subs_adapter_id == -1) {
3120 subs_adapter_id = g_dbus_connection_signal_subscribe(conn,
3121 NULL, BT_ADAPTER_INTERFACE,
3122 NULL, NULL, NULL, 0,
3123 __bt_manager_event_filter,
3126 if (subs_gatt_id == -1) {
3127 subs_gatt_id = g_dbus_connection_signal_subscribe(conn,
3128 NULL, BT_GATT_CHAR_INTERFACE,
3129 NULL, NULL, NULL, 0,
3130 __bt_manager_event_filter,
3134 if (subs_interface_added_id != -1) {
3135 g_dbus_connection_signal_unsubscribe(conn,
3136 subs_interface_added_id);
3137 subs_interface_added_id = -1;
3139 if (subs_interface_removed_id != -1) {
3140 g_dbus_connection_signal_unsubscribe(conn,
3141 subs_interface_removed_id);
3142 subs_interface_removed_id = -1;
3144 if (subs_name_owner_id != -1) {
3145 g_dbus_connection_signal_unsubscribe(conn,
3146 subs_name_owner_id);
3147 subs_name_owner_id = -1;
3149 if (subs_property_id != -1) {
3150 g_dbus_connection_signal_unsubscribe(conn,
3152 subs_property_id = -1;
3154 if (subs_adapter_id != -1) {
3155 g_dbus_connection_signal_unsubscribe(conn, subs_adapter_id);
3156 subs_adapter_id = -1;
3158 if (subs_gatt_id != -1) {
3159 g_dbus_connection_signal_unsubscribe(conn, subs_gatt_id);
3166 int _bt_register_device_subscribe_signal(GDBusConnection *conn,
3172 static int subs_device_id = -1;
3175 if (subs_device_id == -1) {
3176 subs_device_id = g_dbus_connection_signal_subscribe(conn,
3177 NULL, BT_DEVICE_INTERFACE,
3178 NULL, NULL, NULL, 0,
3179 __bt_manager_event_filter,
3183 if (subs_device_id != -1) {
3184 g_dbus_connection_signal_unsubscribe(conn,
3186 subs_device_id = -1;
3192 int _bt_register_input_subscribe_signal(GDBusConnection *conn,
3198 static int subs_input_id = -1;
3201 if (subs_input_id == -1) {
3202 subs_input_id = g_dbus_connection_signal_subscribe(conn,
3203 NULL, BT_INPUT_INTERFACE,
3204 NULL, NULL, NULL, 0,
3205 __bt_manager_event_filter,
3209 if (subs_input_id != -1) {
3210 g_dbus_connection_signal_unsubscribe(conn,
3218 int _bt_register_network_subscribe_signal(GDBusConnection *conn,
3224 static int subs_serv_id = -1;
3225 static int subs_client_id = -1;
3228 if (subs_serv_id == -1) {
3229 subs_serv_id = g_dbus_connection_signal_subscribe(conn,
3230 NULL, BT_NETWORK_SERVER_INTERFACE,
3231 NULL, NULL, NULL, 0,
3232 __bt_manager_event_filter,
3235 if (subs_client_id == -1) {
3236 subs_client_id = g_dbus_connection_signal_subscribe(conn,
3237 NULL, BT_NETWORK_CLIENT_INTERFACE,
3238 NULL, NULL, NULL, 0,
3239 __bt_manager_event_filter,
3243 if (subs_serv_id != -1) {
3244 g_dbus_connection_signal_unsubscribe(conn,
3248 if (subs_client_id != -1) {
3249 g_dbus_connection_signal_unsubscribe(conn,
3251 subs_client_id = -1;
3257 int _bt_register_audio_subscribe_signal(GDBusConnection *conn,
3263 static int subs_headset_id = -1;
3264 static int subs_sink_id = -1;
3267 if (subs_headset_id == -1) {
3268 subs_headset_id = g_dbus_connection_signal_subscribe(conn,
3269 NULL, BT_HEADSET_INTERFACE,
3270 NULL, NULL, NULL, 0,
3271 __bt_manager_event_filter,
3274 if (subs_sink_id == -1) {
3275 subs_sink_id = g_dbus_connection_signal_subscribe(conn,
3276 NULL, BT_SINK_INTERFACE,
3277 NULL, NULL, NULL, 0,
3278 __bt_manager_event_filter,
3282 if (subs_headset_id != -1) {
3283 g_dbus_connection_signal_unsubscribe(conn,
3285 subs_headset_id = -1;
3287 if (subs_sink_id != -1) {
3288 g_dbus_connection_signal_unsubscribe(conn,
3296 int _bt_register_opp_server_subscribe_signal(GDBusConnection *conn,
3302 static int subs_opp_server_interface_added_id = -1;
3303 static int subs_opp_server_interface_removed_id = -1;
3304 static int subs_opp_server_property_id = -1;
3308 if (subs_opp_server_interface_added_id == -1) {
3309 subs_opp_server_interface_added_id = g_dbus_connection_signal_subscribe(conn,
3310 NULL, BT_MANAGER_INTERFACE,
3311 BT_INTERFACES_ADDED, NULL, NULL, 0,
3312 __bt_obexd_event_filter,
3315 if (subs_opp_server_interface_removed_id == -1) {
3316 subs_opp_server_interface_removed_id = g_dbus_connection_signal_subscribe(conn,
3317 NULL, BT_MANAGER_INTERFACE,
3318 BT_INTERFACES_REMOVED, NULL, NULL, 0,
3319 __bt_obexd_event_filter,
3322 if (subs_opp_server_property_id == -1) {
3323 subs_opp_server_property_id = g_dbus_connection_signal_subscribe(conn,
3324 NULL, BT_PROPERTIES_INTERFACE,
3325 BT_PROPERTIES_CHANGED, NULL, NULL, 0,
3326 __bt_obexd_event_filter,
3330 if (subs_opp_server_interface_added_id != -1) {
3331 g_dbus_connection_signal_unsubscribe(conn,
3332 subs_opp_server_interface_added_id);
3333 subs_opp_server_interface_added_id = -1;
3335 if (subs_opp_server_interface_removed_id != -1) {
3336 g_dbus_connection_signal_unsubscribe(conn,
3337 subs_opp_server_interface_removed_id);
3338 subs_opp_server_interface_removed_id = -1;
3340 if (subs_opp_server_property_id != -1) {
3341 g_dbus_connection_signal_unsubscribe(conn,
3342 subs_opp_server_property_id);
3343 subs_opp_server_property_id = -1;
3349 int _bt_register_opp_client_subscribe_signal(GDBusConnection *conn,
3355 static int subs_opp_client_interface_added_id = -1;
3356 static int subs_opp_client_interface_removed_id = -1;
3357 static int subs_opp_client_property_id = -1;
3361 if (subs_opp_client_interface_added_id == -1) {
3362 subs_opp_client_interface_added_id = g_dbus_connection_signal_subscribe(conn,
3363 NULL, BT_MANAGER_INTERFACE,
3364 BT_INTERFACES_ADDED, NULL, NULL, 0,
3365 __bt_opc_event_filter,
3368 if (subs_opp_client_interface_removed_id == -1) {
3369 subs_opp_client_interface_removed_id = g_dbus_connection_signal_subscribe(conn,
3370 NULL, BT_MANAGER_INTERFACE,
3371 BT_INTERFACES_REMOVED, NULL, NULL, 0,
3372 __bt_opc_event_filter,
3375 if (subs_opp_client_property_id == -1) {
3376 subs_opp_client_property_id = g_dbus_connection_signal_subscribe(conn,
3377 NULL, BT_PROPERTIES_INTERFACE,
3378 BT_PROPERTIES_CHANGED, NULL, NULL, 0,
3379 __bt_opc_event_filter,
3383 if (subs_opp_client_interface_added_id != -1) {
3384 g_dbus_connection_signal_unsubscribe(conn,
3385 subs_opp_client_interface_added_id);
3386 subs_opp_client_interface_added_id = -1;
3388 if (subs_opp_client_interface_removed_id != -1) {
3389 g_dbus_connection_signal_unsubscribe(conn,
3390 subs_opp_client_interface_removed_id);
3391 subs_opp_client_interface_removed_id = -1;
3393 if (subs_opp_client_property_id != -1) {
3394 g_dbus_connection_signal_unsubscribe(conn,
3395 subs_opp_client_property_id);
3396 subs_opp_client_property_id = -1;
3402 int _bt_register_a2dp_subscribe_signal(GDBusConnection *conn,
3408 static int subs_a2dp_source_id = -1;
3409 static int subs_a2dp_sink_id = -1;
3412 if (subs_a2dp_source_id == -1) {
3413 subs_a2dp_source_id = g_dbus_connection_signal_subscribe(conn,
3414 NULL, BT_A2DP_SOURCE_INTERFACE,
3415 NULL, NULL, NULL, 0,
3416 __bt_opc_event_filter,
3419 if (subs_a2dp_sink_id == -1) {
3420 subs_a2dp_sink_id = g_dbus_connection_signal_subscribe(conn,
3421 NULL, BT_SINK_INTERFACE,
3422 NULL, NULL, NULL, 0,
3423 __bt_opc_event_filter,
3427 if (subs_a2dp_source_id != -1) {
3428 g_dbus_connection_signal_unsubscribe(conn,
3429 subs_a2dp_source_id);
3430 subs_a2dp_source_id = -1;
3432 if (subs_a2dp_sink_id != -1) {
3433 g_dbus_connection_signal_unsubscribe(conn,
3435 subs_a2dp_sink_id = -1;
3441 static void __bt_dump_event_filter(GDBusConnection *connection,
3442 const gchar *sender_name,
3443 const gchar *object_path,
3444 const gchar *interface_name,
3445 const gchar *signal_name,
3446 GVariant *parameters,
3452 int __bt_register_dump_subscribe_signal(GDBusConnection *conn,
3458 static int subs_source_id = -1;
3461 if (subs_source_id == -1) {
3462 subs_source_id = g_dbus_connection_signal_subscribe(conn,
3463 NULL, BT_DUMP_SERVICE_INTERFACE,
3464 BT_DUMP_SERVICE_SIGNAL, BT_DUMP_SERVICE_PATH, NULL, 0,
3465 __bt_dump_event_filter,
3469 if (subs_source_id != -1) {
3470 g_dbus_connection_signal_unsubscribe(conn,
3472 subs_source_id = -1;
3478 int _bt_register_service_event(GDBusConnection *g_conn, int event_type)
3482 retv_if(g_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
3484 switch (event_type) {
3485 case BT_MANAGER_EVENT:
3486 _bt_register_manager_subscribe_signal(g_conn, TRUE);
3488 case BT_DEVICE_EVENT:
3489 _bt_register_device_subscribe_signal(g_conn, TRUE);
3492 _bt_register_input_subscribe_signal(g_conn, TRUE);
3494 case BT_NETWORK_EVENT:
3495 _bt_register_network_subscribe_signal(g_conn, TRUE);
3497 case BT_HEADSET_EVENT:
3498 _bt_register_audio_subscribe_signal(g_conn, TRUE);
3501 case BT_OPP_SERVER_EVENT:
3502 BT_ERR("BT_OPP_SERVER_EVENT: register service event");
3503 _bt_register_opp_server_subscribe_signal(g_conn, TRUE);
3505 case BT_OPP_CLIENT_EVENT:
3506 BT_ERR("BT_OPP_CLIENT_EVENT: register service event");
3507 _bt_register_opp_client_subscribe_signal(g_conn, TRUE);
3509 case BT_A2DP_SOURCE_EVENT:
3510 BT_INFO("A2dp Source event");
3511 _bt_register_a2dp_subscribe_signal(g_conn, TRUE);
3514 BT_ERR("Unknown event");
3515 return BLUETOOTH_ERROR_INTERNAL;
3518 return BLUETOOTH_ERROR_NONE;
3521 void _bt_unregister_service_event(GDBusConnection *g_conn, int event_type)
3525 ret_if(g_conn == NULL);
3527 switch (event_type) {
3528 case BT_MANAGER_EVENT:
3529 _bt_register_manager_subscribe_signal(g_conn, FALSE);
3530 _bt_register_device_subscribe_signal(g_conn, FALSE);
3531 _bt_register_input_subscribe_signal(g_conn, FALSE);
3532 _bt_register_network_subscribe_signal(g_conn, FALSE);
3533 _bt_register_audio_subscribe_signal(g_conn, FALSE);
3535 case BT_OPP_SERVER_EVENT:
3536 _bt_register_opp_server_subscribe_signal(g_conn, FALSE);
3538 case BT_OPP_CLIENT_EVENT:
3539 _bt_register_opp_client_subscribe_signal(g_conn, FALSE);
3542 BT_ERR("Unknown event");
3549 static int __bt_init_manager_receiver(void)
3553 GError *error = NULL;
3555 if (manager_conn == NULL) {
3556 manager_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
3557 if (error != NULL) {
3558 BT_ERR("ERROR: Can't get on system bus [%s]", error->message);
3559 g_clear_error(&error);
3561 retv_if(manager_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
3564 if (_bt_register_service_event(manager_conn,
3565 BT_MANAGER_EVENT) != BLUETOOTH_ERROR_NONE)
3567 if (_bt_register_service_event(manager_conn,
3568 BT_DEVICE_EVENT) != BLUETOOTH_ERROR_NONE)
3571 if (_bt_register_service_event(manager_conn,
3572 BT_HID_EVENT) != BLUETOOTH_ERROR_NONE)
3575 if (_bt_register_service_event(manager_conn,
3576 BT_HEADSET_EVENT) != BLUETOOTH_ERROR_NONE)
3579 if (_bt_register_service_event(manager_conn,
3580 BT_NETWORK_EVENT) != BLUETOOTH_ERROR_NONE)
3583 __bt_register_dump_subscribe_signal(manager_conn, TRUE);
3584 return BLUETOOTH_ERROR_NONE;
3587 g_object_unref(manager_conn);
3588 manager_conn = NULL;
3593 return BLUETOOTH_ERROR_INTERNAL;
3596 static int __bt_init_obexd_receiver(void)
3599 #ifndef TIZEN_TV /* TODO: obexd doesn't work in TV profile. It should be resolved later. */
3600 GError *error = NULL;
3602 if (obexd_conn == NULL) {
3603 obexd_conn = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &error);
3604 if (error != NULL) {
3605 BT_ERR("ERROR: Can't get on session bus [%s]", error->message);
3606 g_clear_error(&error);
3608 retv_if(obexd_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
3611 if (_bt_register_service_event(obexd_conn,
3612 BT_OPP_SERVER_EVENT) != BLUETOOTH_ERROR_NONE) {
3613 BT_ERR("Error while registering service event");
3614 g_object_unref(obexd_conn);
3616 return BLUETOOTH_ERROR_INTERNAL;
3621 return BLUETOOTH_ERROR_NONE;
3624 gboolean __bt_reinit_obexd_receiver(gpointer user_data)
3626 static int retry_cnt = 0;
3627 int result = BLUETOOTH_ERROR_NONE;
3631 result = __bt_init_obexd_receiver();
3632 if (result != BLUETOOTH_ERROR_NONE) {
3633 /* 20 ms * 50 = 10 seconds. During 10 seconds fail to initialize,
3634 then it is not the timing issue. Just can't use the session bus connection */
3635 if (retry_cnt > 100) {
3636 BT_ERR("Fail to init obexd receiver by 50 times.");
3638 session_reinit_timer = 0;
3642 BT_DBG("Retry to initialize the obexd receiver");
3647 session_reinit_timer = 0;
3654 /* To receive the event from bluez */
3655 int _bt_init_service_event_receiver(void)
3661 result = __bt_init_manager_receiver();
3662 retv_if(result != BLUETOOTH_ERROR_NONE, result);
3664 result = __bt_init_obexd_receiver();
3665 if (result != BLUETOOTH_ERROR_NONE) {
3666 BT_ERR("Fail to init obexd receiver");
3668 /* Try to re-initialize obexd receiver in the timer */
3669 if (session_reinit_timer > 0)
3670 g_source_remove(session_reinit_timer);
3672 session_reinit_timer = g_timeout_add(BT_SESSION_BUS_GET_TIMEOUT,
3673 (GSourceFunc)__bt_reinit_obexd_receiver, NULL);
3678 return BLUETOOTH_ERROR_NONE;
3681 void _bt_deinit_service_event_receiver(void)
3685 _bt_unregister_service_event(manager_conn, BT_MANAGER_EVENT);
3687 _bt_unregister_service_event(obexd_conn, BT_OPP_SERVER_EVENT);
3689 __bt_register_dump_subscribe_signal(manager_conn, FALSE);
3692 g_object_unref(manager_conn);
3693 manager_conn = NULL;
3697 g_object_unref(obexd_conn);
3702 g_source_remove(event_id);