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 = adv_info->data_len;
159 adv_info->timer_id = 0;
161 _bt_send_scan_result_event(&le_dev_info, NULL);
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, "LegacyManufacturerDataLen") == 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, "LegacyManufacturerData") == 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, "(&s&s&s)", 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 void _bt_handle_adapter_event(GVariant *msg, const char *member)
437 int result = BLUETOOTH_ERROR_NONE;
438 GVariant *param = NULL;
439 ret_if(member == NULL);
441 if (strcasecmp(member, "DeviceCreated") == 0) {
442 char *object_path = NULL;
444 bt_remote_dev_info_t *remote_dev_info;
446 ret_if(_bt_is_device_creating() == FALSE);
448 /* Bonding from remote device */
449 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
451 g_variant_get(msg, "(&o)", &object_path);
452 _bt_convert_device_path_to_address((const char*)object_path, address);
454 remote_dev_info = _bt_get_remote_device_info_by_object_path(object_path);
455 if (remote_dev_info == NULL) {
460 _bt_free_device_info(remote_dev_info);
462 } else if (strcasecmp(member, "InterfacesRemoved") == 0) {
463 char *object_path = NULL;
465 bt_cache_info_t *cache_info;
466 bt_remote_dev_info_t *dev_info;
469 /* Bonding from remote device */
470 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
472 g_variant_get(msg, "(&o)", &object_path);
474 _bt_convert_device_path_to_address((const char *)object_path, address);
476 node = g_list_first(p_cache_list);
478 while (node != NULL) {
479 cache_info = (bt_cache_info_t *)node->data;
481 if (cache_info == NULL) {
482 node = g_list_next(node);
486 dev_info = cache_info->dev_info;
487 if (strcasecmp(dev_info->address,
489 p_cache_list = g_list_remove(p_cache_list,
491 __bt_free_cache_info(cache_info);
494 node = g_list_next(node);
497 } else if (strcasecmp(member, "AdvertisingEnabled") == 0) {
498 BT_DBG("Advertising Enabled");
502 gboolean status = FALSE;
504 g_variant_get(msg, "(ib)", &slot_id, &status);
506 BT_DBG("Advertising Enabled : slot_id [%d] status [%d]", slot_id, status);
508 /* Send event to application */
509 _bt_set_advertising_status(slot_id, status);
511 adv_handle = _bt_get_adv_slot_adv_handle(slot_id);
514 event = BLUETOOTH_EVENT_ADVERTISING_STARTED;
516 event = BLUETOOTH_EVENT_ADVERTISING_STOPPED;
517 param = g_variant_new("(ii)", result,
522 sender = _bt_get_adv_slot_owner(slot_id);
523 _bt_send_event_to_dest(sender, BT_ADAPTER_EVENT,
527 _bt_send_event(BT_ADAPTER_EVENT, event, param);
530 if (event == BLUETOOTH_EVENT_ADVERTISING_STOPPED)
531 _bt_unregister_adv_slot_owner(slot_id);
532 } else if (strcasecmp(member, "RssiEnabled") == 0) {
533 BT_DBG("RSSI Enabled");
534 gboolean status = FALSE;
535 char *address = NULL;
537 g_variant_get(msg, "(sib)", &address, &link_type, &status);
539 BT_DBG("RSSI Enabled [%s %d]", address, status);
540 param = g_variant_new("(isib)", result,
541 address, link_type, status);
542 _bt_send_event(BT_DEVICE_EVENT,
543 BLUETOOTH_EVENT_RSSI_ENABLED,
546 } else if (strcasecmp(member, "RssiAlert") == 0) {
547 BT_DBG("RSSI Alert");
551 char *address = NULL;
552 g_variant_get(msg, "(siii)", &address, &link_type, &alert_type, &rssi_dbm);
554 BT_DBG("RSSI Alert: [Address %s LinkType %d] [Type %d DBM %d]",
555 address, alert_type, rssi_dbm);
556 param = g_variant_new("(isiii)", result,
557 address, link_type, alert_type, rssi_dbm);
558 _bt_send_event(BT_DEVICE_EVENT,
559 BLUETOOTH_EVENT_RSSI_ALERT,
562 } else if (strcasecmp(member, "RawRssi") == 0) {
566 char *address = NULL;
567 g_variant_get(msg, "(sii)", &address, &link_type, &rssi_dbm);
569 BT_DBG("Raw RSSI: [Address %s] [Link Type %d][RSSI DBM %d]",
570 address, link_type, rssi_dbm);
571 param = g_variant_new("(isii)", result,
572 address, link_type, rssi_dbm);
573 _bt_send_event(BT_DEVICE_EVENT,
574 BLUETOOTH_EVENT_RAW_RSSI,
577 } else if (strcasecmp(member, BT_HARDWARE_ERROR) == 0) {
578 BT_ERR_C("### Hardware error received from BLUEZ");
579 /* Don't add the recovery logic into platform */
581 _bt_recover_adapter();
583 } else if (strcasecmp(member, BT_TX_TIMEOUT_ERROR) == 0) {
584 BT_ERR_C("### Tx timeout error received from BLUEZ");
585 /* Don't add the recovery logic into platform */
587 _bt_recover_adapter();
593 static void __bt_adapter_property_changed_event(GVariant *msg, const char *path)
595 GDBusProxy *adapter_proxy;
597 int result = BLUETOOTH_ERROR_NONE;
598 GVariantIter value_iter;
599 GVariant *val = NULL;
600 GVariant *ret = NULL;
602 char *property = NULL;
603 GVariant *param = NULL;
605 g_variant_iter_init(&value_iter, msg);
606 while ((g_variant_iter_loop(&value_iter, "{sv}", &property, &val))) {
607 BT_INFO("Property %s", property);
609 if (strcasecmp(property, "Discovering") == 0) {
610 gboolean discovering = FALSE;
612 if (_bt_adapter_get_status() != BT_ACTIVATED)
615 g_variant_get(val, "b", &discovering);
616 BT_DBG("Discovering %d", discovering);
618 /* Send event to application */
619 if (discovering == TRUE) {
620 _bt_set_discovery_status(TRUE);
621 param = g_variant_new("(i)", result);
622 _bt_send_event(BT_ADAPTER_EVENT,
623 BLUETOOTH_EVENT_DISCOVERY_STARTED,
629 adapter_proxy = _bt_get_adapter_proxy();
630 if (adapter_proxy == NULL)
633 /* Need to stop searching */
634 ret = g_dbus_proxy_call_sync(adapter_proxy, "StopDiscovery",
636 G_DBUS_CALL_FLAGS_NONE,
640 BT_ERR("Dbus Error : %s", err->message);
644 g_variant_unref(ret);
646 event_id = g_timeout_add(BT_DISCOVERY_FINISHED_DELAY,
647 (GSourceFunc)_bt_discovery_finished_cb, NULL);
649 } else if (strcasecmp(property, "LEDiscovering") == 0) {
650 gboolean le_discovering = FALSE;
652 if (_bt_adapter_get_status() != BT_ACTIVATED ||
653 _bt_adapter_get_le_status() != BT_LE_ACTIVATED)
656 g_variant_get(val, "b", &le_discovering);
657 BT_DBG("LEDiscovering %d", le_discovering);
659 /* Send event to application */
660 if (le_discovering == TRUE) {
661 _bt_set_le_scan_status(TRUE);
662 param = g_variant_new("(i)", result);
663 _bt_send_event(BT_LE_ADAPTER_EVENT,
664 BLUETOOTH_EVENT_LE_DISCOVERY_STARTED,
670 adapter_proxy = _bt_get_adapter_proxy();
671 if (adapter_proxy == NULL)
674 /* Need to stop searching */
675 ret = g_dbus_proxy_call_sync(adapter_proxy, "StopLEDiscovery",
677 G_DBUS_CALL_FLAGS_NONE,
681 BT_ERR("Dbus Error %s", err->message);
685 g_variant_unref(ret);
687 event_id = g_timeout_add(BT_DISCOVERY_FINISHED_DELAY,
688 (GSourceFunc)__bt_le_discovery_finished_cb, NULL);
690 } else if (strcasecmp(property, "Name") == 0) {
692 g_variant_get(val, "&s", &name);
693 param = g_variant_new("(is)", result, name);
694 /* Send event to application */
695 _bt_send_event(BT_ADAPTER_EVENT,
696 BLUETOOTH_EVENT_LOCAL_NAME_CHANGED,
698 } else if (strcasecmp(property, "Alias") == 0) {
700 g_variant_get(val, "&s", &alias);
701 param = g_variant_new("(is)", result, alias);
702 /* Send event to application */
703 _bt_send_event(BT_ADAPTER_EVENT,
704 BLUETOOTH_EVENT_LOCAL_NAME_CHANGED,
706 } else if (strcasecmp(property, "Discoverable") == 0) {
707 gboolean discoverable = FALSE;
709 g_variant_get(val, "b", &discoverable);
710 BT_DBG("discoverable %d", discoverable);
712 if (discoverable == FALSE) {
713 if (_bt_get_discoverable_timeout_property() > 0) {
714 unsigned int time = 0;
716 adapter_proxy = _bt_get_adapter_properties_proxy();
717 if (adapter_proxy == NULL)
720 ret = g_dbus_proxy_call_sync(adapter_proxy, "Set",
721 g_variant_new("(ssv)", BT_ADAPTER_INTERFACE,
722 "DiscoverableTimeout",
723 g_variant_new("u", time)),
724 G_DBUS_CALL_FLAGS_NONE,
729 BT_ERR("Set DiscoverableTimeout Failed: %s", err->message);
733 g_variant_unref(ret);
736 mode = BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE;
738 /* Send event to application */
739 BT_INFO("[Non Discoverable]");
740 param = g_variant_new("(in)", result, mode);
741 _bt_send_event(BT_ADAPTER_EVENT,
742 BLUETOOTH_EVENT_DISCOVERABLE_MODE_CHANGED,
745 _bt_get_discoverable_mode(&mode);
747 /* Event will be sent by "DiscoverableTimeout" signal */
748 if (mode != BLUETOOTH_DISCOVERABLE_MODE_GENERAL_DISCOVERABLE) {
750 g_variant_unref(val);
754 /* Send event to application */
755 BT_INFO("[General Discoverable]");
756 param = g_variant_new("(in)", result, mode);
757 _bt_send_event(BT_ADAPTER_EVENT,
758 BLUETOOTH_EVENT_DISCOVERABLE_MODE_CHANGED,
761 } else if (strcasecmp(property, "DiscoverableTimeout") == 0) {
762 _bt_get_discoverable_mode(&mode);
764 /* Event was already sent by "Discoverable" signal */
765 if (mode == BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE ||
766 mode == BLUETOOTH_DISCOVERABLE_MODE_GENERAL_DISCOVERABLE)
769 /* Send event to application */
770 BT_INFO("[Limited Discoverable (Timeout %u secs)]",
771 _bt_get_discoverable_timeout_property());
772 param = g_variant_new("(in)", result, mode);
773 _bt_send_event(BT_ADAPTER_EVENT,
774 BLUETOOTH_EVENT_DISCOVERABLE_MODE_CHANGED,
776 } else if (strcasecmp(property, "Powered") == 0) {
777 gboolean powered = FALSE;
778 int bt_state = VCONFKEY_BT_STATUS_OFF;
779 int le_state = VCONFKEY_BT_LE_STATUS_OFF;
781 g_variant_get(val, "b", &powered);
782 BT_DBG("Powered = %d", powered);
786 _bt_handle_adapter_added();
790 _bt_handle_adapter_removed();
792 vconf_get_int(VCONFKEY_BT_LE_STATUS, &le_state);
793 if (le_state != VCONFKEY_BT_LE_STATUS_OFF)
794 _bt_set_le_disabled(BLUETOOTH_ERROR_NONE);
799 vconf_get_int(VCONFKEY_BT_STATUS, &bt_state);
800 if (bt_state != VCONFKEY_BT_STATUS_OFF)
801 _bt_disable_adapter();
803 vconf_get_int(VCONFKEY_BT_LE_STATUS, &le_state);
804 if (le_state != VCONFKEY_BT_LE_STATUS_OFF)
805 _bt_set_le_disabled(BLUETOOTH_ERROR_NONE);
807 } else if (strcasecmp(property, "Connectable") == 0) {
808 gboolean connectable = FALSE;
810 g_variant_get(val, "b", &connectable);
812 BT_DBG("Connectable property is changed : %d", connectable);
813 param = g_variant_new("(b)", connectable);
814 _bt_send_event(BT_ADAPTER_EVENT,
815 BLUETOOTH_EVENT_CONNECTABLE_CHANGED,
818 if (_bt_adapter_get_status() == BT_DEACTIVATING &&
819 _bt_adapter_get_le_status() == BT_LE_ACTIVATED &&
821 _bt_set_disabled(BLUETOOTH_ERROR_NONE);
823 } else if (strcasecmp(property, "SupportedLEFeatures") == 0) {
826 GVariantIter *iter = NULL;
828 g_variant_get(val, "as", &iter);
832 while (g_variant_iter_next(iter, "&s", &name) &&
833 g_variant_iter_next(iter, "&s", &value)) {
834 BT_DBG("name = %s, Value = %s", name, value);
835 if (!_bt_update_le_feature_support(name, value))
836 BT_ERR("Failed to update LE feature (name = %s, value = %s)", name, value);
838 g_variant_iter_free(iter);
839 } else if (strcasecmp(property, "IpspInitStateChanged") == 0) {
840 gboolean ipsp_initialized = FALSE;
842 g_variant_get(val, "b", &ipsp_initialized);
843 BT_DBG("IPSP init state changed: %d", ipsp_initialized);
844 param = g_variant_new("(b)", ipsp_initialized);
846 /* Send event to application */
847 _bt_send_event(BT_ADAPTER_EVENT,
848 BLUETOOTH_EVENT_IPSP_INIT_STATE_CHANGED,
851 BT_DBG("Unhandled property : [%s]", property);
856 static void __bt_obex_property_changed_event(GVariant *msg, const char *path)
860 GVariantIter value_iter;
861 GVariant *child = NULL, *val = NULL;
862 char *property = NULL;
863 g_variant_iter_init(&value_iter, msg);
864 while ((child = g_variant_iter_next_value(&value_iter))) {
865 g_variant_get(child, "{sv}", &property, &val);
867 ret_if(property == NULL);
869 BT_DBG("property :%s", property);
871 if (strcasecmp(property, "Status") == 0) {
873 g_variant_get(val, "s", &status);
875 if (strcasecmp(status, "active") == 0) {
876 _bt_obex_transfer_started(path);
877 } else if (strcasecmp(status, "complete") == 0) {
878 _bt_obex_transfer_completed(path, TRUE);
879 _bt_pbap_obex_transfer_completed(path, TRUE);
880 } else if (strcasecmp(status, "error") == 0) {
881 _bt_obex_transfer_completed(path, FALSE);
882 _bt_pbap_obex_transfer_completed(path, FALSE);
885 } else if (strcasecmp(property, "Transferred") == 0) {
886 guint64 transferred = 0;
887 /* As Transferred is expected guint64 so change int to guint64 and
888 * eariler transferred is static because of it can overwrite data
889 * on present on opc_obex_conn or obexd_conn as these are
890 * static memory are in sequential */
891 g_variant_get(val, "t", &transferred);
893 _bt_obex_transfer_progress(path, transferred);
896 g_variant_unref(val);
897 g_variant_unref(child);
902 static void __bt_device_property_changed_event(GVariant *msg, const char *path)
907 int result = BLUETOOTH_ERROR_NONE;
908 GVariantIter value_iter;
910 char *property = NULL;
912 GVariant *param = NULL;
913 bt_remote_dev_info_t *remote_dev_info;
914 g_variant_iter_init(&value_iter, msg);
915 while ((g_variant_iter_loop(&value_iter, "{sv}", &property, &val))) {
916 BT_DBG("Property %s", property);
917 if (strcasecmp(property, "Connected") == 0) {
920 g_variant_get(val, "i", &connected);
922 event = (connected != BLUETOOTH_CONNECTED_LINK_NONE) ?
923 BLUETOOTH_EVENT_DEVICE_CONNECTED :
924 BLUETOOTH_EVENT_DEVICE_DISCONNECTED;
926 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
928 _bt_convert_device_path_to_address(path, address);
930 BT_DBG("connected: %d", connected);
931 BT_DBG("address: %s", address);
933 remote_dev_info = _bt_get_remote_device_info_by_object_path(path);
935 if (remote_dev_info != NULL) {
936 __bt_device_remote_connected_properties(
937 remote_dev_info, address,
938 connected != BLUETOOTH_CONNECTED_LINK_NONE ?
940 _bt_free_device_info(remote_dev_info);
942 param = g_variant_new("(is)", result, address);
943 /* Send event to application */
944 _bt_send_event(BT_DEVICE_EVENT,
948 } else if (strcasecmp(property, "RSSI") == 0) {
949 bt_remote_dev_info_t *remote_dev_info;
951 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
953 _bt_convert_device_path_to_address(path, address);
954 BT_DBG("address: %s", address);
956 remote_dev_info = _bt_get_remote_device_info_by_object_path(path);
957 if (remote_dev_info == NULL) {
959 g_variant_unref(val);
963 BT_DBG("Address type %d", remote_dev_info->addr_type);
965 if (remote_dev_info->addr_type == 0) {
966 BT_DBG("Name %s", remote_dev_info->name);
968 #ifdef TIZEN_DPM_ENABLE
969 if (_bt_dpm_get_bluetooth_desktop_connectivity_state() ==
971 bluetooth_device_class_t device_class;
972 _bt_divide_device_class(&device_class, remote_dev_info->class);
974 if (device_class.major_class ==
975 BLUETOOTH_DEVICE_MAJOR_CLASS_COMPUTER) {
976 _bt_free_device_info(remote_dev_info);
978 g_variant_unref(val);
985 GVariant *uuids = NULL;
986 GVariantBuilder *builder = NULL;
988 builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
989 for (i = 0; i < remote_dev_info->uuid_count; i++) {
990 g_variant_builder_add(builder, "s",
991 remote_dev_info->uuids[i]);
993 uuids = g_variant_new("as", builder);
994 g_variant_builder_unref(builder);
995 GVariant *manufacturer_data = NULL;
996 manufacturer_data = g_variant_new_from_data(G_VARIANT_TYPE_BYTESTRING,
997 remote_dev_info->manufacturer_data,
998 remote_dev_info->manufacturer_data_len,
1001 param = g_variant_new("(isunsbub@asn@ay)", result,
1002 remote_dev_info->address,
1003 remote_dev_info->class,
1004 remote_dev_info->rssi,
1005 remote_dev_info->name,
1006 remote_dev_info->paired,
1007 remote_dev_info->connected,
1008 remote_dev_info->trust,
1010 remote_dev_info->manufacturer_data_len,
1013 _bt_send_event(BT_ADAPTER_EVENT,
1014 BLUETOOTH_EVENT_REMOTE_DEVICE_FOUND,
1018 _bt_free_device_info(remote_dev_info);
1019 } else if (strcasecmp(property, "GattConnected") == 0) {
1020 gboolean gatt_connected = FALSE;
1022 g_variant_get(val, "b", &gatt_connected);
1024 event = gatt_connected ? BLUETOOTH_EVENT_GATT_CONNECTED :
1025 BLUETOOTH_EVENT_GATT_DISCONNECTED;
1027 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1029 _bt_convert_device_path_to_address(path, address);
1031 BT_DBG("gatt_connected: %d", gatt_connected);
1032 BT_DBG("address: %s", address);
1033 param = g_variant_new("(is)", result, address);
1034 /* Send event to application */
1035 _bt_send_event(BT_DEVICE_EVENT,
1039 } else if (strcasecmp(property, "Paired") == 0) {
1040 gboolean paired = FALSE;
1041 bt_remote_dev_info_t *remote_dev_info;
1042 g_variant_get(val, "b", &paired);
1043 _bt_agent_set_canceled(FALSE);
1044 /* BlueZ sends paired signal for each paired device */
1045 /* during activation, We should ignore this, otherwise*/
1046 /* application thinks that a new device got paired */
1047 if (_bt_adapter_get_status() != BT_ACTIVATED) {
1048 BT_DBG("BT is not activated, so ignore this");
1050 g_variant_unref(val);
1054 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1056 _bt_convert_device_path_to_address(path, address);
1058 remote_dev_info = _bt_get_remote_device_info_by_object_path(path);
1059 if (remote_dev_info == NULL) {
1061 g_variant_unref(val);
1066 if (paired == FALSE) {
1067 BT_INFO("Unpaired: %s", address);
1068 __bt_update_remote_cache_devinfo(address, FALSE);
1069 param = g_variant_new("(is)", result, address);
1070 _bt_send_event(BT_ADAPTER_EVENT,
1071 BLUETOOTH_EVENT_BONDED_DEVICE_REMOVED,
1073 #ifdef TIZEN_BT_A2DP_SINK_AUTO_CONNECT
1075 char *last_connected = NULL;
1076 last_connected = vconf_get_str(BT_LAST_CONNECTED_DEVICE);
1077 if (!g_strcmp0(address, last_connected))
1078 _bt_audio_set_auto_connect_device_addr("");
1080 free(last_connected);
1084 char secure_addr[BT_ADDRESS_STRING_SIZE] = { 0 };
1086 _bt_convert_addr_string_to_secure_string(secure_addr, address);
1087 BT_INFO(" ### Paired: %s", secure_addr);
1088 __bt_update_remote_cache_devinfo(address, TRUE);
1090 GVariant *uuids = NULL;
1091 GVariantBuilder *builder = NULL;
1093 builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
1094 for (i = 0; i < remote_dev_info->uuid_count; i++) {
1095 g_variant_builder_add(builder, "s",
1096 remote_dev_info->uuids[i]);
1098 uuids = g_variant_new("as", builder);
1099 g_variant_builder_unref(builder);
1100 GVariant *manufacturer_data = NULL;
1101 manufacturer_data = g_variant_new_from_data(G_VARIANT_TYPE_BYTESTRING,
1102 remote_dev_info->manufacturer_data,
1103 remote_dev_info->manufacturer_data_len,
1107 param = g_variant_new("(isunsbub@asn@ay)", result,
1108 address, remote_dev_info->class,
1109 remote_dev_info->rssi,
1110 remote_dev_info->name,
1111 remote_dev_info->paired,
1112 remote_dev_info->connected,
1113 remote_dev_info->trust,
1115 remote_dev_info->manufacturer_data_len,
1117 _bt_send_event(BT_ADAPTER_EVENT,
1118 BLUETOOTH_EVENT_BONDING_FINISHED,
1121 _bt_free_device_info(remote_dev_info);
1123 } else if (strcasecmp(property, "LegacyPaired") == 0) {
1124 gboolean paired = FALSE;
1125 bt_remote_dev_info_t *remote_dev_info;
1126 unsigned char auth_info[5] = {0, };
1128 if (_bt_adapter_get_status() != BT_ACTIVATED) {
1129 BT_DBG("BT is not activated, so ignore this");
1131 g_variant_unref(val);
1135 g_variant_get(val, "b", &paired);
1136 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1137 BT_DBG("LegacyPaired: %d", paired);
1138 _bt_convert_device_path_to_address(path, address);
1140 remote_dev_info = _bt_get_remote_device_info_by_object_path(path);
1141 if (remote_dev_info == NULL) {
1144 g_variant_unref(val);
1147 if (remote_dev_info->is_alias_set == FALSE) {
1148 /*minimum Size of the samsung specific manufacturer data is greater than 30 */
1149 if ((remote_dev_info->manufacturer_data_len > 30) &&
1150 (remote_dev_info->manufacturer_data[0] == 0x00) &&
1151 (remote_dev_info->manufacturer_data[1] == 0x75)) {
1153 /* 2 samsung (0x00 0x75) + 1 (control and version) + 1 (service ID) +
1154 1 (discovery version) + 1 (associated service ID)
1155 2 (Proxamity and locality) + 2 (Device type and icon) = 10 */
1157 memcpy(auth_info, &(remote_dev_info->manufacturer_data[10]), 5);
1161 BT_DBG("LegacyPairing Failed with %s. Show Error Popup", remote_dev_info->name);
1162 _bt_launch_system_popup(BT_AGENT_EVENT_LEGACY_PAIR_FAILED_FROM_REMOTE,
1163 remote_dev_info->name, auth_info, NULL, NULL, NULL);
1165 _bt_free_device_info(remote_dev_info);
1167 } else if (strcasecmp(property, "Trusted") == 0) {
1168 gboolean trusted = FALSE;
1170 g_variant_get(val, "b", &trusted);
1172 event = trusted ? BLUETOOTH_EVENT_DEVICE_AUTHORIZED :
1173 BLUETOOTH_EVENT_DEVICE_UNAUTHORIZED;
1175 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1177 _bt_convert_device_path_to_address(path, address);
1179 BT_DBG("trusted: %d", trusted);
1180 BT_DBG("address: %s", address);
1181 param = g_variant_new("(is)", result, address);
1182 /* Send event to application */
1183 _bt_send_event(BT_DEVICE_EVENT,
1187 } else if (strcasecmp(property, "TrustedProfiles") == 0) {
1190 g_variant_get(val, "u", &trusted);
1192 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1193 _bt_convert_device_path_to_address(path, address);
1195 BT_DBG("Address: %s, TrustedProfiles: %d", address, trusted);
1196 _bt_send_event(BT_DEVICE_EVENT,
1197 BLUETOOTH_EVENT_SUPPORTED_PROFILE_TRUSTED,
1198 g_variant_new("(isi)", result, address, trusted));
1200 } else if (strcasecmp(property, "IpspConnected") == 0) {
1201 gboolean connected = FALSE;
1203 g_variant_get(val, "b", &connected);
1206 event = connected ? BLUETOOTH_EVENT_IPSP_CONNECTED :
1207 BLUETOOTH_EVENT_IPSP_DISCONNECTED;
1209 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1211 _bt_convert_device_path_to_address(path, address);
1213 BT_DBG("Ipspconnected: %d", connected);
1214 BT_DBG("address: %s", address);
1215 param = g_variant_new("(is)", result, address);
1217 /* Send event to application */
1218 _bt_send_event(BT_DEVICE_EVENT,
1222 } else if (strcasecmp(property, "IpspBtInterfaceInfo") == 0) {
1223 char *ifname = NULL;
1225 g_variant_get(val, "&s", &ifname);
1227 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1229 _bt_convert_device_path_to_address(path, address);
1231 BT_DBG("Ipsp BT Interface Name: %s", ifname);
1232 BT_DBG("address: %s", address);
1233 param = g_variant_new("(iss)", result, address, ifname);
1235 /* Send event to application */
1236 _bt_send_event(BT_DEVICE_EVENT,
1237 BLUETOOTH_EVENT_IPSP_INTERFACE_INFO,
1245 static void __bt_media_control_changed_event(GVariant *msg, const char *path)
1248 int result = BLUETOOTH_ERROR_NONE;
1249 GVariantIter value_iter;
1250 char *property = NULL;
1252 GVariant *val = NULL;
1253 GVariant *child = NULL;
1254 bt_remote_dev_info_t *remote_dev_info;
1255 GVariant *param = NULL;
1256 g_variant_iter_init(&value_iter, msg);
1257 while ((child = g_variant_iter_next_value(&value_iter))) {
1258 g_variant_get(child, "{sv}", &property, &val);
1259 BT_INFO("Property %s", property);
1260 if (strcasecmp(property, "Connected") == 0) {
1261 gboolean connected = FALSE;
1263 g_variant_get(val, "b", &connected);
1265 event = connected ? BLUETOOTH_EVENT_AVRCP_CONNECTED :
1266 BLUETOOTH_EVENT_AVRCP_DISCONNECTED;
1268 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1270 _bt_convert_device_path_to_address(path, address);
1272 BT_DBG("connected: %d", connected);
1273 BT_DBG("address: %s", address);
1275 remote_dev_info = _bt_get_remote_device_info(address);
1277 if (remote_dev_info != NULL) {
1278 __bt_device_remote_connected_properties(
1279 remote_dev_info, address, connected);
1280 _bt_free_device_info(remote_dev_info);
1282 param = g_variant_new("(is)", result, address);
1283 /* Send event to application */
1284 _bt_send_event(BT_AVRCP_EVENT,
1290 g_variant_unref(child);
1291 g_variant_unref(val);
1296 int get_alert_level_enum(const char *alert)
1300 if (strcmp(alert, "none") == 0)
1301 lvl = BT_PXP_ALERT_NONE;
1302 else if (strcmp(alert, "mild") == 0)
1303 lvl = BT_PXP_ALERT_MILD;
1304 else if (strcmp(alert, "high") == 0)
1305 lvl = BT_PXP_ALERT_HIGH;
1310 static void _bt_handle_pxp_property_changed_event(GVariant *msg, const char *path, int role)
1312 int result = BLUETOOTH_ERROR_NONE;
1315 GVariantIter value_iter;
1316 char *property = NULL;
1318 GVariant *val = NULL;
1319 GVariant *child = NULL;
1320 GVariant *param = NULL;
1321 g_variant_iter_init(&value_iter, msg);
1324 while ((child = g_variant_iter_next_value(&value_iter))) {
1325 g_variant_get(child, "{sv}", &property, &val);
1326 BT_INFO("Property %s", property);
1328 if ((strcasecmp(property, "LinkLossAlertLevel") == 0) ||
1329 (strcasecmp(property, "ImmediateAlertLevel") == 0)) {
1330 char *alert_str = NULL;
1332 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1333 _bt_convert_device_path_to_address(path, address);
1335 if (strcasecmp(property, "LinkLossAlertLevel") == 0)
1336 service_type = BT_PXP_PROPERTY_LLS;
1338 service_type = BT_PXP_PROPERTY_IAS;
1340 g_variant_get(val, "s", &alert_str);
1341 alert_lvl = get_alert_level_enum(alert_str);
1343 param = g_variant_new("(isiii)", result, address,
1344 role, service_type, alert_lvl);
1346 /* Send event to application */
1347 _bt_send_event(BT_DEVICE_EVENT,
1348 BLUETOOTH_EVENT_PXP_PROPERTY_CHANGED,
1354 g_variant_unref(child);
1355 g_variant_unref(val);
1360 void _bt_handle_property_changed_event(GVariant *msg, const char *object_path)
1362 char *interface_name = NULL;
1363 GVariant *val = NULL;
1365 g_variant_get(msg, "(&s@a{sv}@as)", &interface_name, &val, NULL);
1367 if (strcasecmp(interface_name, BT_ADAPTER_INTERFACE) == 0) {
1368 __bt_adapter_property_changed_event(val,
1370 } else if (strcasecmp(interface_name, BT_DEVICE_INTERFACE) == 0) {
1371 __bt_device_property_changed_event(val, object_path);
1372 } else if (strcasecmp(interface_name, BT_OBEX_TRANSFER_INTERFACE) == 0) {
1373 BT_DBG("BT_OBEX_TRANSFER_INTERFACE");
1374 __bt_obex_property_changed_event(val,
1376 } else if (strcasecmp(interface_name, BT_MEDIA_CONTROL_INTERFACE) == 0) {
1377 __bt_media_control_changed_event(val,
1379 } else if (strcasecmp(interface_name, BT_PLAYER_CONTROL_INTERFACE) == 0) {
1380 _bt_handle_avrcp_control_event(val,
1382 } else if (strcasecmp(interface_name, BT_NETWORK_CLIENT_INTERFACE) == 0) {
1383 BT_DBG("BT_NETWORK_CLIENT_INTERFACE");
1384 _bt_handle_network_client_event(val,
1386 } else if (strcasecmp(interface_name, BT_GATT_CHAR_INTERFACE) == 0) {
1387 __bt_gatt_char_property_changed_event(val,
1389 } else if (strcasecmp(interface_name, BT_PROXIMITY_REPORTER_INTERFACE) == 0) {
1390 BT_DBG("BT_PROXIMITY_REPORTER_INTERFACE");
1391 _bt_handle_pxp_property_changed_event(val,
1392 object_path, BT_PXP_REPORTER_ROLE);
1393 } else if (strcasecmp(interface_name, BT_PROXIMITY_MONITOR_INTERFACE) == 0) {
1394 BT_DBG("BT_PROXIMITY_MONITOR_INTERFACE");
1395 _bt_handle_pxp_property_changed_event(val,
1396 object_path, BT_PXP_MONITOR_ROLE);
1398 g_variant_unref(val);
1401 void __bt_opc_property_changed_event(GVariant *msg,
1404 GVariantIter value_iter;
1405 char *property = NULL;
1406 GVariant *val = NULL;
1407 GVariant *child = NULL;
1409 g_variant_iter_init(&value_iter, msg);
1410 while ((child = g_variant_iter_next_value(&value_iter))) {
1411 g_variant_get(child, "{sv}", &property, &val);
1412 ret_if(property == NULL);
1414 if (strcasecmp(property, "Status") == 0) {
1415 char *status = NULL;
1416 g_variant_get(val, "s", &status);
1417 BT_DBG("Status is %s", status);
1419 if (strcasecmp(status, "active") == 0)
1420 _bt_obex_client_started(path);
1421 else if (strcasecmp(status, "complete") == 0)
1422 _bt_obex_client_completed(path, TRUE);
1423 else if (strcasecmp(status, "error") == 0)
1424 _bt_obex_client_completed(path, FALSE);
1427 } else if (strcasecmp(property, "Transferred") == 0) {
1428 guint64 transferred = 0;
1429 g_variant_get(val, "t", &transferred);
1431 _bt_obex_client_progress(path, transferred);
1433 BT_DBG("property : [%s]", property);
1436 g_variant_unref(child);
1437 g_variant_unref(val);
1441 void _bt_opc_property_changed_event(GVariant *msg, char *path)
1443 char *interface_name = NULL;
1444 GVariant *value = NULL;
1445 g_variant_get(msg, "(&s@a{sv}@as)", &interface_name, &value, NULL);
1446 BT_INFO("interface_name = %s", interface_name);
1447 if (strcasecmp(interface_name, BT_OBEX_TRANSFER_INTERFACE) == 0) {
1448 __bt_opc_property_changed_event(value,
1451 BT_DBG("interface_name : [%s]", interface_name);
1453 g_variant_unref(value);
1457 void _bt_handle_input_event(GVariant *msg, const char *path)
1459 int result = BLUETOOTH_ERROR_NONE;
1460 gboolean property_flag = FALSE;
1461 GVariantIter value_iter;
1462 char *property = NULL;
1463 GVariant *child = NULL, *val = NULL;
1464 bt_remote_dev_info_t *remote_dev_info;
1465 GVariant *param = NULL;
1466 g_variant_iter_init(&value_iter, msg);
1467 while ((child = g_variant_iter_next_value(&value_iter))) {
1468 g_variant_get(child, "{sv}", &property, &val);
1470 ret_if(property == NULL);
1472 if (strcasecmp(property, "Connected") == 0) {
1473 int event = BLUETOOTH_EVENT_NONE;
1475 g_variant_get(val, "b", &property_flag);
1477 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1479 _bt_convert_device_path_to_address(path, address);
1481 event = (property_flag == TRUE) ?
1482 BLUETOOTH_HID_CONNECTED :
1483 BLUETOOTH_HID_DISCONNECTED;
1484 param = g_variant_new("(is)", result, address);
1485 _bt_send_event(BT_HID_EVENT, event,
1487 /* Check HID connection type (Keyboard or Mouse) and update the status */
1488 remote_dev_info = _bt_get_remote_device_info_by_object_path(path);
1490 if (property_flag == TRUE) {
1491 hid_connected_device_count++;
1492 __bt_set_device_values(TRUE,
1493 VCONFKEY_BT_DEVICE_HID_CONNECTED);
1495 hid_connected_device_count--;
1496 if (hid_connected_device_count == 0)
1497 __bt_set_device_values(FALSE,
1498 VCONFKEY_BT_DEVICE_HID_CONNECTED);
1501 if (remote_dev_info != NULL) {
1502 BT_DBG("HID device class [%x]", remote_dev_info->class);
1503 if (remote_dev_info->class &
1504 BLUETOOTH_DEVICE_MINOR_CLASS_KEY_BOARD) {
1505 __bt_set_device_values(property_flag,
1506 VCONFKEY_BT_DEVICE_HID_KEYBOARD_CONNECTED);
1510 if (remote_dev_info->class &
1511 BLUETOOTH_DEVICE_MINOR_CLASS_POINTING_DEVICE) {
1512 __bt_set_device_values(property_flag,
1513 VCONFKEY_BT_DEVICE_HID_MOUSE_CONNECTED);
1515 _bt_free_device_info(remote_dev_info);
1520 g_variant_unref(val);
1521 g_variant_unref(child);
1525 void _bt_handle_network_server_event(GVariant *msg, const char *member)
1527 int result = BLUETOOTH_ERROR_NONE;
1528 char *address = NULL;
1529 char *device = NULL;
1530 GVariant *param = NULL;
1531 ret_if(member == NULL);
1532 if (strcasecmp(member, "PeerConnected") == 0) {
1533 g_variant_get(msg, "(ss)", &device, &address);
1535 __bt_set_device_values(TRUE,
1536 VCONFKEY_BT_DEVICE_PAN_CONNECTED);
1537 param = g_variant_new("(iss)", result, device, address);
1538 _bt_send_event(BT_NETWORK_EVENT, BLUETOOTH_EVENT_NETWORK_SERVER_CONNECTED,
1542 nap_connected_device_count++;
1543 } else if (strcasecmp(member, "PeerDisconnected") == 0) {
1544 g_variant_get(msg, "(ss)", &device, &address);
1545 nap_connected_device_count--;
1546 if (nap_connected_device_count == 0)
1547 __bt_set_device_values(FALSE,
1548 VCONFKEY_BT_DEVICE_PAN_CONNECTED);
1549 param = g_variant_new("(iss)", result, device, address);
1550 _bt_send_event(BT_NETWORK_EVENT, BLUETOOTH_EVENT_NETWORK_SERVER_DISCONNECTED,
1557 void _bt_handle_network_client_event(GVariant *msg,
1562 int result = BLUETOOTH_ERROR_NONE;
1563 gboolean property_flag = FALSE;
1564 char *property = NULL;
1565 GVariant *val = NULL;
1566 GVariantIter value_iter;
1567 GVariant *param = NULL;
1568 g_variant_iter_init(&value_iter, msg);
1569 while ((g_variant_iter_loop(&value_iter, "{sv}", &property, &val))) {
1570 if (strcasecmp(property, "Connected") == 0) {
1571 int event = BLUETOOTH_EVENT_NONE;
1574 g_variant_get(val, "b", &property_flag);
1575 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1577 _bt_convert_device_path_to_address(path, address);
1579 BT_DBG("property_flag %d", property_flag);
1580 if (property_flag == TRUE) {
1581 event = BLUETOOTH_EVENT_NETWORK_CONNECTED;
1582 nap_connected_device_count++;
1583 __bt_set_device_values(TRUE,
1584 VCONFKEY_BT_DEVICE_PAN_CONNECTED);
1586 event = BLUETOOTH_EVENT_NETWORK_DISCONNECTED;
1587 nap_connected_device_count--;
1588 if (nap_connected_device_count == 0)
1589 __bt_set_device_values(FALSE,
1590 VCONFKEY_BT_DEVICE_PAN_CONNECTED);
1592 param = g_variant_new("(is)", result, address);
1593 _bt_send_event(BT_NETWORK_EVENT, event,
1602 void __bt_gatt_char_property_changed_event(GVariant *msg,
1605 GVariantIter value_iter;
1606 char *property = NULL;
1607 char * char_handle = NULL;
1608 GVariant *val = NULL;
1609 int result = BLUETOOTH_ERROR_NONE;
1610 GVariant *param = NULL;
1611 g_variant_iter_init(&value_iter, msg);
1612 char_handle = g_strdup(path);
1613 while ((g_variant_iter_loop(&value_iter, "{sv}", &property, &val))) {
1614 BT_DBG("Property %s", property);
1616 ret_if(property == NULL);
1618 if (strcasecmp(property, "Notifying") == 0) {
1619 gboolean property_flag = FALSE;
1620 g_variant_get(val, "b", &property_flag);
1621 BT_INFO("Notifying is %s", property_flag ? "enabled" : "disabled");
1622 } else if (strcasecmp(property, "ChangedValue") == 0) {
1624 GByteArray *gp_byte_array = NULL;
1625 BT_INFO("Type '%s'\n", g_variant_get_type_string(val));
1628 gp_byte_array = g_byte_array_new();
1629 len = g_variant_get_size(val);
1630 BT_DBG("Len = %d", len);
1631 g_byte_array_append(gp_byte_array,
1632 (const guint8 *) g_variant_get_data(val), len);
1633 if (gp_byte_array->len != 0) {
1634 GVariant *byte_array = NULL;
1635 byte_array = g_variant_new_from_data(
1636 G_VARIANT_TYPE_BYTESTRING,
1637 gp_byte_array->data,
1640 param = g_variant_new("(is@ay)", result, char_handle,
1643 /* Send event only registered client */
1644 _bt_send_char_value_changed_event(param);
1646 g_byte_array_free(gp_byte_array, TRUE);
1650 g_free(char_handle);
1653 void _bt_handle_gatt_event(GVariant *msg, const char *member, const char *path)
1655 ret_if(path == NULL);
1657 if (strcasecmp(member, "GattValueChanged") == 0) {
1660 /*** Debug only ***/
1661 GVariant *value = NULL;
1663 char *buffer = NULL;
1665 g_variant_get(msg, "(is@ay)", NULL, NULL, &value);
1666 value_len = g_variant_get_size(value);
1667 if (value_len > 0) {
1668 char buf[8 * 5 + 1] = { 0 };
1671 buffer = (char *)g_variant_get_data(value);
1672 to = value_len > (sizeof(buf) / 5) ? sizeof(buf) / 5 : value_len;
1674 for (i = 0; i < to; i++)
1675 snprintf(&buf[i * 5], 6, "0x%02x ", buffer[i]);
1677 BT_DBG("GATT Val[%d] %s", value_len, buf);
1679 g_variant_unref(value);
1683 /* Send event only registered client */
1684 _bt_send_char_value_changed_event(msg);
1689 void _bt_handle_device_event(GVariant *msg, const char *member, const char *path)
1692 int result = BLUETOOTH_ERROR_NONE;
1694 char *dev_name = NULL;
1695 const char *property = NULL;
1696 GVariant *param = NULL;
1697 char secure_address[BT_ADDRESS_STRING_SIZE] = { 0 };
1698 ret_if(path == NULL);
1700 if (strcasecmp(member, "PropertyChanged") == 0) {
1702 g_variant_get(msg, "(s)", &property);
1704 ret_if(property == NULL);
1706 if (strcasecmp(property, "GattConnected") == 0) {
1707 gboolean connected = FALSE;
1709 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1711 _bt_convert_device_path_to_address(path, address);
1712 g_variant_get(msg, "(b)", &connected);
1714 event = connected ? BLUETOOTH_EVENT_GATT_CONNECTED :
1715 BLUETOOTH_EVENT_GATT_DISCONNECTED;
1716 param = g_variant_new("(is)", result, address);
1717 _bt_send_event(BT_DEVICE_EVENT,
1721 } else if (strcasecmp(property, "Paired") == 0) {
1722 gboolean paired = FALSE;
1723 bt_remote_dev_info_t *remote_dev_info;
1724 g_variant_get(msg, "(b)", &paired);
1726 ret_if(paired == FALSE);
1728 /* BlueZ sends paired signal for each paired device */
1729 /* during activation, We should ignore this, otherwise*/
1730 /* application thinks that a new device got paired */
1731 if (_bt_adapter_get_status() != BT_ACTIVATED) {
1732 BT_DBG("BT is not activated, so ignore this");
1736 if (_bt_is_device_creating() == TRUE) {
1737 BT_DBG("Try to Pair by me");
1741 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1743 _bt_convert_device_path_to_address(path, address);
1745 remote_dev_info = _bt_get_remote_device_info_by_object_path(path);
1746 if (remote_dev_info == NULL) {
1750 GVariant *uuids = NULL;
1751 GVariantBuilder *builder = NULL;
1753 builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
1754 for (i = 0; i < remote_dev_info->uuid_count; i++) {
1755 g_variant_builder_add(builder, "s",
1756 remote_dev_info->uuids[i]);
1758 uuids = g_variant_new("as", builder);
1759 g_variant_builder_unref(builder);
1760 GVariant *manufacturer_data = NULL;
1761 manufacturer_data = g_variant_new_from_data(
1762 G_VARIANT_TYPE_BYTESTRING,
1763 remote_dev_info->manufacturer_data,
1764 remote_dev_info->manufacturer_data_len,
1766 param = g_variant_new("(isunsbub@asn@ay)", result,
1768 remote_dev_info->class,
1769 remote_dev_info->rssi,
1770 remote_dev_info->name,
1771 remote_dev_info->paired,
1772 remote_dev_info->connected,
1773 remote_dev_info->trust,
1775 remote_dev_info->manufacturer_data_len,
1777 _bt_send_event(BT_ADAPTER_EVENT,
1778 BLUETOOTH_EVENT_BONDING_FINISHED,
1780 _bt_free_device_info(remote_dev_info);
1783 } else if (strcasecmp(property, "UUIDs") == 0) {
1784 /* Once we get the updated uuid information after
1785 * reverse service search, update it to application */
1787 bt_remote_dev_info_t *remote_dev_info;
1789 ret_if(_bt_is_device_creating() == TRUE);
1791 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1793 _bt_convert_device_path_to_address(path, address);
1795 remote_dev_info = _bt_get_remote_device_info_by_object_path(path);
1796 if (remote_dev_info == NULL) {
1801 BT_DBG("UUID's count = %d", remote_dev_info->uuid_count);
1802 if (remote_dev_info->paired && remote_dev_info->uuid_count) {
1803 GVariant *uuids = NULL;
1804 GVariantBuilder *builder = NULL;
1806 builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
1807 for (i = 0; i < remote_dev_info->uuid_count; i++) {
1808 g_variant_builder_add(builder, "s",
1809 remote_dev_info->uuids[i]);
1811 uuids = g_variant_new("as", builder);
1812 g_variant_builder_unref(builder);
1813 GVariant *manufacture_data = g_variant_new_from_data((const GVariantType *)"ay",
1814 remote_dev_info->manufacturer_data, remote_dev_info->manufacturer_data_len,
1817 param = g_variant_new("(isunsbub@asn@ay)", result,
1818 address, remote_dev_info->class,
1819 remote_dev_info->rssi,
1820 remote_dev_info->name,
1821 remote_dev_info->paired,
1822 remote_dev_info->connected,
1823 remote_dev_info->trust,
1825 remote_dev_info->manufacturer_data_len,
1827 _bt_send_event(BT_ADAPTER_EVENT,
1828 BLUETOOTH_EVENT_SERVICE_SEARCHED,
1832 _bt_free_device_info(remote_dev_info);
1835 } else if (strcasecmp(member, "DeviceConnected") == 0) {
1836 unsigned char addr_type = 0;
1838 g_variant_get(msg, "(y)", &addr_type);
1840 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1842 _bt_convert_device_path_to_address(path, address);
1843 dev_name = _bt_get_device_name(address);
1845 _bt_convert_addr_string_to_secure_string(secure_address, address);
1846 BT_INFO("Address : %s Type : %d", secure_address, addr_type);
1847 BT_ERR_C("### Connected [%s] [%s]", !addr_type ? "BREDR" : "LE",
1848 !addr_type ? dev_name : secure_address);
1852 _bt_add_le_connected_dev_info(address);
1854 _bt_logging_connection(TRUE, addr_type);
1855 param = g_variant_new("(isy)", result, address, addr_type);
1856 /*Send event to application*/
1857 _bt_send_event(BT_DEVICE_EVENT,
1858 BLUETOOTH_EVENT_DEVICE_CONNECTED,
1861 } else if (strcasecmp(member, "Disconnected") == 0) {
1862 unsigned char disc_reason = 0;
1863 unsigned char addr_type = 0;
1864 char *dev_name = NULL;
1865 gboolean sending = FALSE;
1867 g_variant_get(msg, "(yys)", &addr_type, &disc_reason, &dev_name);
1869 result = disc_reason;
1871 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1873 _bt_convert_device_path_to_address(path, address);
1875 /* 0x00 BDADDR_BRDER
1876 0x01 BDADDR_LE_PUBLIC
1877 0x02 BDADDR_LE_RANDOM */
1878 _bt_convert_addr_string_to_secure_string(secure_address, address);
1879 BT_INFO("Address : %s Type : %d", secure_address, addr_type);
1880 BT_ERR_C("### Disconnected [%s] [%s] [%d : %s]", !addr_type ? "BREDR" : "LE",
1881 !addr_type ? dev_name : secure_address,
1882 disc_reason, _bt_convert_disc_reason_to_string(disc_reason));
1885 _bt_headset_set_local_connection(FALSE);
1886 _bt_logging_connection(FALSE, addr_type);
1889 _bt_remove_le_connected_dev_info(address);
1891 #ifdef TIZEN_BT_A2DP_SINK_AUTO_CONNECT
1893 int bt_device_state = VCONFKEY_BT_DEVICE_NONE;
1895 if (vconf_get_int(VCONFKEY_BT_DEVICE, &bt_device_state) != 0)
1896 BT_ERR("vconf_get_int failed");
1898 BT_INFO("conn_state[0x%x], adapter_state [%d]",
1899 bt_device_state, _bt_adapter_get_status());
1901 if (disc_reason == BLUETOOTH_ERROR_CONNECTION_TIMEOUT) {
1902 _bt_audio_start_auto_connect(TRUE);
1903 } else if (bt_device_state &
1904 VCONFKEY_BT_DEVICE_A2DP_SOURCE_CONNECTED) {
1905 BT_INFO("Disconnected due to turning BT off. Skip a address");
1907 char *last_connected = NULL;
1908 last_connected = vconf_get_str(BT_LAST_CONNECTED_DEVICE);
1909 if (!g_strcmp0(address, last_connected))
1910 _bt_audio_set_auto_connect_device_addr("");
1912 free(last_connected);
1917 /*Check for any OPP transfer on the device and cancel
1920 _bt_obex_check_pending_transfer(address);
1921 _bt_opp_client_is_sending(&sending);
1922 if (sending == TRUE)
1923 _bt_opp_client_check_pending_transfer(address);
1925 param = g_variant_new("(isy)", result, address, addr_type);
1926 _bt_send_event(BT_DEVICE_EVENT,
1927 BLUETOOTH_EVENT_DEVICE_DISCONNECTED,
1930 } else if (strcasecmp(member, "ProfileStateChanged") == 0) {
1932 char *profile_uuid = NULL;
1933 bt_headset_wait_t *wait_list;
1934 bluetooth_device_address_t bd_addr;
1936 g_variant_get(msg, "(si)", &profile_uuid, &state);
1938 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1940 _bt_convert_device_path_to_address(path, address);
1941 _bt_convert_addr_string_to_type(bd_addr.addr, address);
1943 _bt_convert_addr_string_to_secure_string(secure_address, address);
1944 BT_INFO_C("[%s] state: %s, addr: %s",
1945 _bt_convert_uuid_to_string(profile_uuid),
1946 _bt_convert_profile_state_to_string(state), secure_address);
1948 if (strcmp(profile_uuid, A2DP_SINK_UUID) == 0) {
1949 if (state == BT_PROFILE_STATE_CONNECTED) {
1951 int event = BLUETOOTH_EVENT_AV_CONNECTED;
1952 char connected_address[BT_ADDRESS_STRING_SIZE + 1];
1953 bluetooth_device_address_t device_address;
1955 bt_headset_wait_t *wait_list;
1956 guint restricted = 0x0;
1958 __bt_set_device_values(TRUE,
1959 VCONFKEY_BT_DEVICE_A2DP_HEADSET_CONNECTED);
1961 __bt_connection_manager_set_state(address, event);
1963 _bt_get_restrict_profile(&bd_addr, RESTRICTED_PROFILE_HFP_HS, &restricted);
1965 if (_bt_headset_get_local_connection() == FALSE) {
1966 if (restricted == 0x0) /* not restricted*/
1967 _bt_start_timer_for_connection(address, BT_AUDIO_HSP);
1969 /* Connection Started from local device therefore no need to
1970 * intiate connection for pending profile */
1971 _bt_headset_set_local_connection(FALSE);
1973 param = g_variant_new("(is)", result, address);
1974 _bt_send_event(BT_HEADSET_EVENT, event,
1976 connected = _bt_is_headset_type_connected(BT_AUDIO_A2DP,
1979 if (g_strcmp0(connected_address, address) != 0) {
1980 _bt_convert_addr_string_to_type(
1981 device_address.addr,
1983 _bt_audio_disconnect(0, BT_AUDIO_A2DP,
1984 &device_address, NULL);
1988 _bt_add_headset_to_list(BT_AUDIO_A2DP,
1989 BT_STATE_CONNECTED, address);
1991 wait_list = _bt_get_audio_wait_data();
1992 if (wait_list != NULL &&
1993 (g_strcmp0(wait_list->address, address) == 0))
1994 _bt_rel_wait_data();
1996 } else if (state == BT_PROFILE_STATE_DISCONNECTED) {
1998 int event = BLUETOOTH_EVENT_AV_DISCONNECTED;
2000 if (!_bt_is_service_connected(address, BT_AUDIO_A2DP)) {
2002 g_free(profile_uuid);
2006 __bt_set_device_values(FALSE,
2007 VCONFKEY_BT_DEVICE_A2DP_HEADSET_CONNECTED);
2009 __bt_connection_manager_set_state(address, event);
2010 param = g_variant_new("(is)", result, address);
2011 _bt_send_event(BT_HEADSET_EVENT, event,
2013 /* Remove data from the connected list */
2014 _bt_remove_headset_from_list(BT_AUDIO_A2DP, address);
2015 wait_list = _bt_get_audio_wait_data();
2017 if (wait_list == NULL) {
2019 g_free(profile_uuid);
2023 if (((wait_list->type == BT_AUDIO_ALL) &&
2024 (wait_list->ag_flag == TRUE)) ||
2025 (wait_list->type == BT_AUDIO_A2DP) ||
2026 (wait_list->disconnection_type == BT_AUDIO_A2DP)) {
2027 bluetooth_device_address_t device_address;
2028 _bt_convert_addr_string_to_type(
2029 device_address.addr,
2030 wait_list->address);
2032 _bt_audio_connect(wait_list->req_id,
2038 } else if (strcmp(profile_uuid, AVRCP_TARGET_UUID) == 0) {
2040 if (state == BT_PROFILE_STATE_CONNECTED) {
2041 int event = BLUETOOTH_EVENT_AVRCP_CONTROL_CONNECTED;
2042 char connected_address[BT_ADDRESS_STRING_SIZE + 1];
2043 bluetooth_device_address_t device_address;
2045 param = g_variant_new("(is)", result, address);
2046 _bt_send_event(BT_AVRCP_CONTROL_EVENT, event,
2048 connected = _bt_is_headset_type_connected(
2052 if (g_strcmp0(connected_address,
2054 _bt_convert_addr_string_to_type(
2055 device_address.addr,
2057 _bt_audio_disconnect(0,
2059 &device_address, NULL);
2062 BT_DBG("device Path: %s", path);
2063 _bt_add_headset_to_list(BT_AVRCP,
2064 BT_STATE_CONNECTED, address);
2065 } else if (state == BT_PROFILE_STATE_DISCONNECTED) {
2066 int event = BLUETOOTH_EVENT_AVRCP_CONTROL_DISCONNECTED;
2067 param = g_variant_new("(is)", result, address);
2068 _bt_send_event(BT_AVRCP_CONTROL_EVENT, event,
2070 /* Remove data from the connected list */
2071 _bt_remove_headset_from_list(BT_AVRCP, address);
2073 } else if (strcasecmp(profile_uuid, A2DP_SOURCE_UUID) == 0) {
2074 if (state == BT_PROFILE_STATE_CONNECTED) {
2075 int event = BLUETOOTH_EVENT_AV_SOURCE_CONNECTED;
2076 BT_INFO("A2DP Source is connected");
2077 #ifdef TIZEN_BT_A2DP_SINK_ENABLE
2078 __bt_set_device_values(TRUE,
2079 VCONFKEY_BT_DEVICE_A2DP_SOURCE_CONNECTED);
2082 #ifdef TIZEN_BT_A2DP_SINK_AUTO_CONNECT
2083 _bt_audio_set_auto_connect_device_addr(address);
2084 _bt_audio_stop_auto_connect();
2086 _bt_add_headset_to_list(BT_AUDIO_A2DP_SOURCE,
2087 BT_STATE_CONNECTED, address);
2088 _bt_send_event(BT_A2DP_SOURCE_EVENT, event,
2089 g_variant_new("(is)", result, address));
2090 } else if (state == BT_PROFILE_STATE_DISCONNECTED) {
2091 int event = BLUETOOTH_EVENT_AV_SOURCE_DISCONNECTED;
2092 BT_INFO("A2DP Source Disconnected");
2093 #ifdef TIZEN_BT_A2DP_SINK_ENABLE
2094 __bt_set_device_values(FALSE,
2095 VCONFKEY_BT_DEVICE_A2DP_SOURCE_CONNECTED);
2097 _bt_remove_headset_from_list(BT_AUDIO_A2DP_SOURCE, address);
2098 _bt_send_event(BT_A2DP_SOURCE_EVENT, event,
2099 g_variant_new("(is)", result, address));
2101 wait_list = _bt_get_audio_wait_data();
2102 if (wait_list && wait_list->type == BT_AUDIO_A2DP_SOURCE) {
2103 bluetooth_device_address_t device_address;
2104 _bt_convert_addr_string_to_type(
2105 device_address.addr,
2106 wait_list->address);
2108 _bt_audio_connect(wait_list->req_id,
2112 /* Now free the wait list */
2113 _bt_rel_wait_data();
2116 } else if ((strcmp(profile_uuid, HID_UUID) == 0) &&
2117 ((state == BT_PROFILE_STATE_CONNECTED) ||
2118 (state == BT_PROFILE_STATE_DISCONNECTED))) {
2120 if (state == BT_PROFILE_STATE_CONNECTED)
2121 event = BLUETOOTH_HID_CONNECTED;
2123 event = BLUETOOTH_HID_DISCONNECTED;
2124 param = g_variant_new("(is)", result, address);
2125 _bt_send_event(BT_HID_EVENT, event,
2127 } else if (strcmp(profile_uuid, HID_DEVICE_UUID) == 0) {
2128 if (state == BT_PROFILE_STATE_CONNECTED) {
2130 event = BLUETOOTH_HID_DEVICE_CONNECTED;
2131 param = g_variant_new("(is)", result, address);
2132 _bt_send_event(BT_HID_DEVICE_EVENT, event,
2134 } else if (state == BT_PROFILE_STATE_DISCONNECTED) {
2135 event = BLUETOOTH_HID_DEVICE_DISCONNECTED;
2136 param = g_variant_new("(is)", result, address);
2137 _bt_send_event(BT_HID_DEVICE_EVENT, event,
2142 g_free(profile_uuid);
2143 } else if (strcasecmp(member, "AdvReport") == 0) {
2145 bt_remote_le_dev_info_t *le_dev_info = NULL;
2146 char *buffer = NULL;
2148 bt_le_adv_info_t *adv_info = NULL;
2149 GVariant *value = NULL;
2150 ret_if(_bt_is_le_scanning() == FALSE);
2152 le_dev_info = g_malloc0(sizeof(bt_remote_le_dev_info_t));
2154 g_variant_get(msg, "(&syyii@ay)", &le_dev_info->address,
2155 &le_dev_info->addr_type,
2156 &le_dev_info->adv_type,
2158 &le_dev_info->adv_data_len,
2160 if (value == NULL) {
2161 _bt_free_le_device_info(le_dev_info);
2165 _bt_convert_device_path_to_address(path, le_dev_info->address);
2167 buffer_len = g_variant_get_size(value);
2169 buffer = (char *)g_variant_get_data(value);
2171 le_dev_info->adv_data = g_memdup(buffer, buffer_len);
2172 if (le_dev_info->adv_data == NULL &&
2173 le_dev_info->adv_type != BT_LE_ADV_SCAN_RSP) {
2174 _bt_free_le_device_info(le_dev_info);
2175 g_variant_unref(value);
2179 if (_bt_get_le_scan_type() == BT_LE_PASSIVE_SCAN) {
2180 _bt_send_scan_result_event(le_dev_info, NULL);
2181 _bt_free_le_device_info(le_dev_info);
2182 g_variant_unref(value);
2186 if (le_dev_info->adv_type == BT_LE_ADV_DIRECT_IND ||
2187 le_dev_info->adv_type == BT_LE_ADV_NONCONN_IND) {
2188 _bt_send_scan_result_event(le_dev_info, NULL);
2189 } else if (le_dev_info->adv_type == BT_LE_ADV_IND ||
2190 le_dev_info->adv_type == BT_LE_ADV_SCAN_IND) {
2191 adv_info = g_malloc0(sizeof(bt_le_adv_info_t));
2192 adv_info->addr = g_strdup(le_dev_info->address);
2193 adv_info->addr_type = le_dev_info->addr_type;
2194 adv_info->rssi = le_dev_info->rssi;
2195 adv_info->data_len = le_dev_info->adv_data_len;
2196 adv_info->data = g_malloc0(le_dev_info->adv_data_len);
2197 memcpy(adv_info->data, le_dev_info->adv_data,
2198 le_dev_info->adv_data_len);
2200 if (__bt_add_adv_ind_info(adv_info) == 0) {
2201 adv_info->timer_id = g_timeout_add(1000,
2202 (GSourceFunc)__bt_adv_scan_req_timeout_cb, (void*)adv_info);
2204 } else { /* SCAN_RSP */
2205 adv_info = __bt_get_adv_ind_info(le_dev_info->address);
2207 _bt_send_scan_result_event(le_dev_info, adv_info);
2208 __bt_del_adv_ind_info(le_dev_info->address);
2211 _bt_free_le_device_info(le_dev_info);
2212 g_variant_unref(value);
2213 } else if (strcasecmp(member, "LEDataLengthChanged") == 0) {
2214 guint16 tx_octets = 0;
2215 guint16 tx_time = 0;
2216 guint16 rx_octets = 0;
2217 guint16 rx_time = 0;
2219 g_variant_get(msg, "(qqqq)",
2220 &tx_octets, &tx_time, &rx_octets, &rx_time);
2222 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
2223 _bt_convert_device_path_to_address(path, address);
2225 param = g_variant_new("(isqqqq)", result, address, tx_octets, tx_time,
2226 rx_octets, rx_time);
2227 /* Send event to application */
2228 _bt_send_event(BT_DEVICE_EVENT,
2229 BLUETOOTH_EVENT_LE_DATA_LENGTH_CHANGED, param);
2231 } else if (strcasecmp(member, "IpspStateChanged") == 0) {
2232 gboolean connected = FALSE;
2233 char *ifname = NULL;
2235 g_variant_get(msg, "(bs)", &connected, &ifname);
2237 event = connected ? BLUETOOTH_EVENT_IPSP_CONNECTED :
2238 BLUETOOTH_EVENT_IPSP_DISCONNECTED;
2240 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
2241 _bt_convert_device_path_to_address(path, address);
2243 BT_DBG("Ipsp BT Interface Name: %s", ifname);
2244 BT_DBG("address: %s", address);
2245 param = g_variant_new("(iss)", result, address, ifname);
2247 /* Send event to application */
2248 _bt_send_event(BT_DEVICE_EVENT, event, param);
2250 } else if (strcasecmp(member, "AttMtuChanged") == 0) {
2251 int result = BLUETOOTH_ERROR_NONE;
2255 g_variant_get(msg, "(q)", &mtu);
2257 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
2259 _bt_convert_device_path_to_address(path, address);
2260 BT_DBG("Address : %s Server MTU changed : %d", address, mtu);
2262 param = g_variant_new("(isqy)",
2268 /* Send the event to application */
2269 _bt_send_event(BT_DEVICE_EVENT,
2270 BLUETOOTH_EVENT_GATT_SERVER_ATT_MTU_CHANGED,
2274 } else if (strcasecmp(member, "iBeaconReport") == 0) {
2275 bt_remote_ibeacon_dev_info_t *ibeacon_dev_info = NULL;
2277 ret_if(_bt_is_le_scanning() == FALSE);
2279 ibeacon_dev_info = g_malloc0(sizeof(bt_remote_ibeacon_dev_info_t));
2281 g_variant_get(msg, "(syuusuuy)", &ibeacon_dev_info->address,
2282 &ibeacon_dev_info->addr_type,
2283 &ibeacon_dev_info->company_id,
2284 &ibeacon_dev_info->ibeacon_type,
2285 &ibeacon_dev_info->uuid,
2286 &ibeacon_dev_info->major_id,
2287 &ibeacon_dev_info->minor_id,
2288 &ibeacon_dev_info->measured_power);
2289 _bt_send_ibeacon_scan_result_event(ibeacon_dev_info);
2290 g_free(ibeacon_dev_info);
2294 void __bt_set_audio_values(gboolean connected, char *address)
2297 int bt_device_state = VCONFKEY_BT_DEVICE_NONE;
2299 /* Set the headset name */
2300 if (connected == TRUE)
2301 name = _bt_get_device_name(address);
2303 name = g_strdup("");
2305 if (vconf_set_str(VCONFKEY_BT_HEADSET_NAME, name) != 0)
2306 BT_ERR("vconf_set_str failed");
2310 /* Set the headset state */
2311 if (vconf_get_int(VCONFKEY_BT_DEVICE, &bt_device_state) != 0)
2312 BT_ERR("vconf_get_int failed");
2314 #ifdef TIZEN_SUPPORT_DUAL_HF
2315 if ((connected == TRUE) &&
2316 (FALSE == __bt_is_companion_device(address))) {
2317 bt_device_state |= VCONFKEY_BT_DEVICE_HEADSET_CONNECTED;
2318 } else if ((bt_device_state & VCONFKEY_BT_DEVICE_HEADSET_CONNECTED) &&
2319 (FALSE == __bt_is_companion_device(address))) {
2320 bt_device_state ^= VCONFKEY_BT_DEVICE_HEADSET_CONNECTED;
2323 if (connected == TRUE)
2324 bt_device_state |= VCONFKEY_BT_DEVICE_HEADSET_CONNECTED;
2325 else if (bt_device_state & VCONFKEY_BT_DEVICE_HEADSET_CONNECTED)
2326 bt_device_state ^= VCONFKEY_BT_DEVICE_HEADSET_CONNECTED;
2329 if (vconf_set_int(VCONFKEY_BT_DEVICE,
2330 bt_device_state) != 0) {
2331 BT_ERR("vconf_set_int failed");
2335 void _bt_handle_headset_event(GVariant *msg, const char *path)
2337 int result = BLUETOOTH_ERROR_NONE;
2338 gboolean property_flag = FALSE;
2339 char *property = NULL;
2340 GVariant *value = NULL;
2341 GVariant *param = NULL;
2342 g_variant_get(msg, "(sv)", &property, &value);
2343 bluetooth_device_address_t bd_addr;
2345 ret_if(property == NULL);
2347 BT_DBG("Property = %s \n", property);
2348 /* We allow only 1 headset connection (HSP or HFP)*/
2349 if (strcasecmp(property, "Connected") == 0) {
2350 int event = BLUETOOTH_EVENT_NONE;
2351 bt_headset_wait_t *wait_list;
2353 guint restricted = 0x0;
2354 g_variant_get(value, "b", &property_flag);
2356 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
2358 _bt_convert_device_path_to_address(path, address);
2359 _bt_convert_addr_string_to_type(bd_addr.addr, address);
2361 if (property_flag == TRUE) {
2362 event = BLUETOOTH_EVENT_AG_CONNECTED;
2363 _bt_get_restrict_profile(&bd_addr, RESTRICTED_PROFILE_A2DP, &restricted);
2365 if (_bt_headset_get_local_connection() == FALSE) {
2366 if (restricted == 0x0) /* not restricted*/
2367 _bt_start_timer_for_connection(address, BT_AUDIO_A2DP);
2369 _bt_headset_set_local_connection(FALSE);
2373 event = BLUETOOTH_EVENT_AG_DISCONNECTED;
2375 previous_state = _bt_get_device_state_from_list(BT_AUDIO_HSP, address);
2376 if (previous_state == BT_STATE_DISCONNECTING)
2377 _bt_send_hf_local_term_event(address);
2379 /* Set the State machine here */
2380 __bt_connection_manager_set_state(address, event);
2381 __bt_set_audio_values(property_flag, address);
2382 param = g_variant_new("(is)", result, address);
2383 _bt_send_event(BT_HEADSET_EVENT, event,
2386 if (event == BLUETOOTH_EVENT_AG_DISCONNECTED) {
2387 /* Remove data from the connected list */
2388 _bt_remove_headset_from_list(BT_AUDIO_HSP, address);
2390 wait_list = _bt_get_audio_wait_data();
2391 if (wait_list == NULL) {
2396 bluetooth_device_address_t device_address;
2398 _bt_set_audio_wait_data_flag(TRUE);
2400 _bt_convert_addr_string_to_type(device_address.addr,
2401 wait_list->address);
2402 _bt_audio_connect(wait_list->req_id, wait_list->type,
2403 &device_address, NULL);
2404 _bt_rel_wait_data();
2405 } else if (event == BLUETOOTH_EVENT_AG_CONNECTED) {
2406 /* Add data to the connected list */
2407 _bt_add_headset_to_list(BT_AUDIO_HSP,
2408 BT_STATE_CONNECTED, address);
2410 wait_list = _bt_get_audio_wait_data();
2411 if (wait_list != NULL &&
2412 (g_strcmp0(wait_list->address, address) == 0))
2413 _bt_rel_wait_data();
2415 BT_INFO("Check A2DP pending connect");
2416 _bt_audio_check_pending_connect();
2419 } else if (strcasecmp(property, "State") == 0) {
2422 g_variant_get(value, "s", &state);
2424 /* This code assumes we support only 1 headset connection */
2425 /* Need to use the headset list, if we support multi-headsets */
2426 if (strcasecmp(state, "Playing") == 0) {
2427 BT_DBG("Playing: Sco Connected");
2428 } else if (strcasecmp(state, "connected") == 0 ||
2429 strcasecmp(state, "disconnected") == 0) {
2430 BT_DBG("connected/disconnected: Sco Disconnected");
2432 BT_ERR("Not handled state - %s", state);
2437 } else if (strcasecmp(property, "SpeakerGain") == 0) {
2441 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
2443 _bt_convert_device_path_to_address(path, address);
2445 spkr_gain = g_variant_get_uint16(value);
2447 BT_DBG("spkr_gain: %d", spkr_gain);
2449 param = g_variant_new("(i&sq)", result, address, spkr_gain);
2450 _bt_send_event(BT_HEADSET_EVENT, BLUETOOTH_EVENT_AG_SPEAKER_GAIN,
2454 } else if (strcasecmp(property, "MicrophoneGain") == 0) {
2458 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
2460 _bt_convert_device_path_to_address(path, address);
2462 mic_gain = g_variant_get_uint16(value);
2464 param = g_variant_new("(i&sq)", result, address, mic_gain);
2465 _bt_send_event(BT_HEADSET_EVENT, BLUETOOTH_EVENT_AG_MIC_GAIN,
2472 g_variant_unref(value);
2475 void _bt_handle_sink_event(GVariant *msg, const char *path)
2477 GVariantIter value_iter;
2478 char *property = NULL;
2480 bt_headset_wait_t *wait_list;
2482 GVariant *child = NULL;
2483 GVariant *val = NULL;
2484 GVariant *param = NULL;
2485 g_variant_iter_init(&value_iter, msg);
2486 while ((child = g_variant_iter_next_value(&value_iter))) {
2488 g_variant_get(child, "{sv}", &property, &val);
2490 ret_if(property == NULL);
2492 BT_DBG("Property = %s \n", property);
2495 if (strcasecmp(property, "State") == 0) {
2496 int result = BLUETOOTH_ERROR_NONE;
2499 g_variant_get(val, "s", &value);
2500 BT_DBG("value: %s", value);
2502 if (g_strcmp0(value, "disconnected") == 0) {
2505 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
2507 _bt_convert_device_path_to_address(path, address);
2509 __bt_set_device_values(FALSE,
2510 VCONFKEY_BT_DEVICE_A2DP_HEADSET_CONNECTED);
2511 param = g_variant_new("(is)", result, address);
2512 _bt_send_event(BT_HEADSET_EVENT,
2513 BLUETOOTH_EVENT_AV_DISCONNECTED,
2516 /* Remove data from the connected list */
2517 _bt_remove_headset_from_list(BT_AUDIO_A2DP, address);
2518 wait_list = _bt_get_audio_wait_data();
2519 if (wait_list == NULL) {
2522 g_variant_unref(val);
2523 g_variant_unref(child);
2528 if (((wait_list->type == BT_AUDIO_ALL) &&
2529 (wait_list->ag_flag == TRUE)) ||
2530 (wait_list->type == BT_AUDIO_A2DP) ||
2531 (wait_list->disconnection_type == BT_AUDIO_A2DP)) {
2532 bluetooth_device_address_t device_address;
2533 _bt_convert_addr_string_to_type(
2534 device_address.addr,
2535 wait_list->address);
2537 _bt_audio_connect(wait_list->req_id,
2543 } else if (strcasecmp(value, "Connected") == 0) {
2545 char connected_address[BT_ADDRESS_STRING_SIZE + 1];
2546 bluetooth_device_address_t device_address;
2549 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
2551 _bt_convert_device_path_to_address(path, address);
2553 __bt_set_device_values(TRUE,
2554 VCONFKEY_BT_DEVICE_A2DP_HEADSET_CONNECTED);
2555 param = g_variant_new("(is)", result, address);
2556 _bt_send_event(BT_HEADSET_EVENT,
2557 BLUETOOTH_EVENT_AV_CONNECTED,
2559 /* Check for existing Media device to disconnect */
2560 connected = _bt_is_headset_type_connected(BT_AUDIO_A2DP,
2563 /* Match connected device address */
2564 if (g_strcmp0(connected_address, address) != 0) {
2565 /* Convert BD address from string type */
2566 _bt_convert_addr_string_to_type(
2567 device_address.addr,
2569 _bt_audio_disconnect(0, BT_AUDIO_A2DP,
2570 &device_address, NULL);
2574 /* Add data to the connected list */
2575 _bt_add_headset_to_list(BT_AUDIO_A2DP,
2576 BT_STATE_CONNECTED, address);
2583 g_variant_unref(val);
2584 g_variant_unref(child);
2588 void _bt_handle_agent_event(GVariant *msg, const char *member)
2590 int result = BLUETOOTH_ERROR_NONE;
2591 char *address = NULL;
2594 GVariant *param = NULL;
2595 ret_if(member == NULL);
2597 if (strcasecmp(member, "ObexAuthorize") == 0) {
2598 __bt_get_agent_signal_info(msg, &address, &name, &uuid);
2599 param = g_variant_new("(i&s&s)", result, address, name);
2600 _bt_send_event(BT_OPP_SERVER_EVENT,
2601 BLUETOOTH_EVENT_OBEX_SERVER_CONNECTION_AUTHORIZE,
2603 } else if (strcasecmp(member, "RfcommAuthorize") == 0) {
2604 bt_rfcomm_server_info_t *server_info;
2606 __bt_get_agent_signal_info(msg, &address, &name, &uuid);
2608 server_info = _bt_rfcomm_get_server_info_using_uuid(uuid);
2609 ret_if(server_info == NULL);
2610 ret_if(server_info->server_type != BT_CUSTOM_SERVER);
2611 param = g_variant_new("(i&s&s&sn)", result, address, uuid, name,
2612 server_info->control_fd);
2613 _bt_send_event(BT_RFCOMM_SERVER_EVENT,
2614 BLUETOOTH_EVENT_RFCOMM_AUTHORIZE,
2619 static int __bt_get_object_path(GVariant *msg, char **path)
2621 g_variant_get(msg, "(o*)", path, NULL);
2623 return BLUETOOTH_ERROR_INTERNAL;
2625 return BLUETOOTH_ERROR_NONE;
2628 static void __bt_devices_list_free(void)
2630 bt_cache_info_t *cache_info;
2633 node = g_list_first(p_cache_list);
2635 while (node != NULL) {
2636 cache_info = (bt_cache_info_t *)node->data;
2637 p_cache_list = g_list_remove(p_cache_list, cache_info);
2638 __bt_free_cache_info(cache_info);
2640 node = g_list_next(node);
2644 static int __bt_parse_event(GVariant *msg)
2648 char *interface_name = NULL;
2649 GVariant *inner_iter = NULL;
2651 g_variant_iter_init(&iter, msg);
2653 while ((child = g_variant_iter_next_value(&iter))) {
2654 g_variant_get(child, "{&s@a{sv}}", &interface_name, &inner_iter);
2655 if (g_strcmp0(interface_name,
2656 BT_DEVICE_INTERFACE) == 0) {
2657 g_variant_unref(inner_iter);
2658 g_variant_unref(child);
2659 return BT_DEVICE_EVENT;
2660 } else if (g_strcmp0(interface_name,
2661 BT_MEDIATRANSPORT_INTERFACE) == 0) {
2662 g_variant_unref(inner_iter);
2663 g_variant_unref(child);
2664 return BT_MEDIA_TRANSFER_EVENT;
2665 } else if (g_strcmp0(interface_name,
2666 BT_PLAYER_CONTROL_INTERFACE) == 0) {
2667 g_variant_unref(inner_iter);
2668 g_variant_unref(child);
2669 return BT_AVRCP_CONTROL_EVENT;
2671 g_variant_unref(inner_iter);
2672 g_variant_unref(child);
2678 static void __bt_manager_event_filter(GDBusConnection *connection,
2679 const gchar *sender_name,
2680 const gchar *object_path,
2681 const gchar *interface_name,
2682 const gchar *signal_name,
2683 GVariant *parameters,
2686 bt_event_type_t bt_event = 0x00;
2687 int result = BLUETOOTH_ERROR_NONE;
2689 char *obj_path = NULL;
2690 GVariant *param = NULL;
2691 if (signal_name == NULL)
2693 if (strcasecmp(signal_name, "InterfacesAdded") == 0) {
2694 g_variant_get(parameters, "(&o@a{sa{sv}})", &obj_path, &value);
2696 if (strcasecmp(obj_path, BT_BLUEZ_HCI_PATH) == 0) {
2697 #ifdef USB_BLUETOOTH
2698 BT_DBG("Enable Adapter");
2699 _bt_enable_adapter();
2701 _bt_handle_adapter_added();
2704 bt_event = __bt_parse_event(value);
2705 if (bt_event == BT_DEVICE_EVENT) {
2706 bt_cache_info_t *cache_info;
2707 bt_remote_dev_info_t *dev_info;
2709 if (_bt_is_discovering() == FALSE &&
2710 _bt_is_le_scanning() == FALSE) {
2711 g_variant_unref(value);
2715 cache_info = g_malloc0(sizeof(bt_cache_info_t));
2717 dev_info = g_malloc0(sizeof(bt_remote_dev_info_t));
2719 cache_info->dev_info = dev_info;
2721 if (__bt_parse_interface(parameters, dev_info) == FALSE) {
2722 BT_ERR("Fail to parse the properies");
2723 __bt_free_cache_info(cache_info);
2724 g_variant_unref(value);
2728 if (dev_info->addr_type != BDADDR_BREDR) {
2729 /* Whenever emit the property changed from bluez,
2730 some property doesn't reach to bt-service.
2731 So LE device is handled as AdvReport signal */
2732 __bt_free_cache_info(cache_info);
2733 g_variant_unref(value);
2737 if (dev_info->name == NULL)
2738 /* If Remote device name is NULL or still RNR is not done
2739 * then display address as name.
2741 dev_info->name = g_strdup(dev_info->address);
2743 #ifdef TIZEN_DPM_ENABLE
2744 if (_bt_dpm_get_bluetooth_desktop_connectivity_state() ==
2746 bluetooth_device_class_t device_class;
2747 _bt_divide_device_class(&device_class, dev_info->class);
2748 BT_DBG("[%s]device_class.major_class : %d", dev_info->name, device_class.major_class);
2750 if (device_class.major_class ==
2751 BLUETOOTH_DEVICE_MAJOR_CLASS_COMPUTER) {
2752 __bt_free_cache_info(cache_info);
2753 g_variant_unref(value);
2759 GVariant *uuids = NULL;
2760 GVariantBuilder *builder = NULL;
2762 builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
2763 for (i = 0; i < dev_info->uuid_count; i++) {
2764 g_variant_builder_add(builder, "s",
2765 dev_info->uuids[i]);
2767 uuids = g_variant_new("as", builder);
2768 g_variant_builder_unref(builder);
2769 GVariant *manufacturer_data = NULL;
2770 manufacturer_data = g_variant_new_from_data(
2771 G_VARIANT_TYPE_BYTESTRING,
2772 dev_info->manufacturer_data,
2773 dev_info->manufacturer_data_len,
2775 param = g_variant_new("(isunsbub@asn@ay)", result,
2781 dev_info->connected,
2784 dev_info->manufacturer_data_len,
2786 _bt_send_event(BT_ADAPTER_EVENT,
2787 BLUETOOTH_EVENT_REMOTE_DEVICE_FOUND,
2789 p_cache_list = g_list_append(p_cache_list, cache_info);
2790 } else if (bt_event == BT_AVRCP_CONTROL_EVENT) {
2791 BT_DBG("Device path : %s ", obj_path);
2792 _bt_set_control_device_path(obj_path);
2795 g_variant_unref(value);
2796 } else if (strcasecmp(signal_name, "InterfacesRemoved") == 0) {
2797 #ifdef USB_BLUETOOTH
2798 BT_DBG("InterfacesRemoved");
2799 _bt_handle_adapter_removed();
2801 if (g_strcmp0(interface_name, BT_MEDIATRANSPORT_INTERFACE) == 0)
2802 bt_event = BT_MEDIA_TRANSFER_EVENT;
2803 else if (g_strcmp0(interface_name, BT_DEVICE_INTERFACE) == 0)
2804 bt_event = BT_DEVICE_EVENT;
2805 else if (g_strcmp0(interface_name, BT_PLAYER_CONTROL_INTERFACE) == 0)
2806 bt_event = BT_AVRCP_CONTROL_EVENT;
2808 if ((bt_event != 0) && (bt_event != BT_MEDIA_TRANSFER_EVENT)) {
2809 _bt_handle_adapter_event(parameters, signal_name);
2810 if (bt_event == BT_AVRCP_CONTROL_EVENT) {
2811 BT_INFO("Object Path %s", obj_path);
2812 _bt_remove_control_device_path(obj_path);
2815 } else if (strcasecmp(signal_name, "NameOwnerChanged") == 0) {
2818 char *previous = NULL;
2819 char *current = NULL;
2821 if (g_strcmp0(g_variant_get_type_string(parameters), "(sss)") != 0) {
2822 BT_ERR("Invalid variant format");
2826 if (__bt_get_owner_info(parameters, &name, &previous, ¤t)) {
2827 BT_ERR("Fail to get the owner info");
2831 if (*current != '\0')
2837 if (strcasecmp(name, BT_BLUEZ_NAME) == 0) {
2838 BT_INFO_C("### Bluetoothd is terminated");
2839 if (_bt_adapter_get_status() == BT_ACTIVATED)
2842 _bt_handle_adapter_removed();
2843 __bt_devices_list_free();
2844 _bt_service_adapter_le_deinit();
2847 _bt_obex_server_check_allocation(&value);
2849 if (value == TRUE) {
2850 /* Check if the obex server was terminated abnormally */
2851 _bt_obex_server_check_termination(name);
2854 _bt_rfcomm_server_check_existence(&value);
2856 if (value == TRUE) {
2857 /* The obex server was terminated abnormally */
2858 _bt_rfcomm_server_check_termination(name);
2861 /* Reset connection interval */
2862 _bt_remove_all_le_conn_param_info(name);
2864 /* Stop advertising started by terminated process */
2865 _bt_stop_advertising_by_terminated_process(name);
2868 _bt_stop_le_scan(name);
2869 } else if (g_strcmp0(interface_name, BT_PROPERTIES_INTERFACE) == 0) {
2870 const char *path = object_path;
2872 if (strncmp(path, BT_MEDIA_OBJECT_PATH,
2873 strlen(BT_MEDIA_OBJECT_PATH)) == 0)
2876 _bt_handle_property_changed_event(parameters, object_path);
2877 } else if (g_strcmp0(interface_name, BT_ADAPTER_INTERFACE) == 0) {
2878 _bt_handle_adapter_event(parameters, signal_name);
2879 } else if (g_strcmp0(interface_name, BT_INPUT_INTERFACE) == 0) {
2880 _bt_handle_input_event(parameters, object_path);
2881 } else if (g_strcmp0(interface_name, BT_NETWORK_SERVER_INTERFACE) == 0) {
2882 _bt_handle_network_server_event(parameters, signal_name);
2883 } else if (g_strcmp0(interface_name, BT_HEADSET_INTERFACE) == 0) {
2884 if (g_strcmp0(signal_name, "PropertyChanged") == 0) {
2885 _bt_handle_headset_event(parameters, object_path);
2887 } else if (g_strcmp0(interface_name, BT_SINK_INTERFACE) == 0) {
2888 _bt_handle_sink_event(parameters, object_path);
2889 } else if (g_strcmp0(interface_name, BT_AGENT_INTERFACE) == 0) {
2890 _bt_handle_agent_event(parameters, signal_name);
2891 } else if (g_strcmp0(interface_name, BT_DEVICE_INTERFACE) == 0) {
2892 _bt_handle_device_event(parameters, signal_name, object_path);
2893 } else if (g_strcmp0(interface_name, BT_GATT_CHAR_INTERFACE) == 0) {
2894 _bt_handle_gatt_event(parameters, signal_name, object_path);
2900 static gboolean __bt_is_obexd_event(GVariant *msg, const char *interface)
2903 if (g_strcmp0(interface, BT_PROPERTIES_INTERFACE) == 0) {
2904 char *interface_name = NULL;
2906 g_variant_get(msg, "(&s@a{sv}@as)", &interface_name, NULL, NULL);
2907 retv_if(interface_name == NULL, FALSE);
2909 if (strcasecmp(interface_name, BT_OBEX_TRANSFER_INTERFACE) == 0) {
2910 BT_DBG("BT_OBEX_TRANSFER_INTERFACE");
2918 static void __bt_obexd_event_filter(GDBusConnection *connection,
2919 const gchar *sender_name,
2920 const gchar *object_path,
2921 const gchar *interface_name,
2922 const gchar *signal_name,
2923 GVariant *parameters,
2926 const char *member = signal_name;
2927 char *obj_path = NULL;
2928 ret_if(member == NULL);
2930 if (strcasecmp(member, "InterfacesAdded") == 0) {
2931 if (__bt_get_object_path(parameters, &obj_path)) {
2932 BT_ERR("Fail to get the path");
2935 BT_DBG("object_path = [%s]", obj_path);
2937 /*Handle OPP_SERVER_CONNECTED_EVENT here */
2938 if (strncmp(obj_path, BT_SESSION_BASEPATH_SERVER,
2939 strlen(BT_SESSION_BASEPATH_SERVER)) != 0) {
2944 if (g_strrstr(obj_path, "session") && g_strrstr(obj_path, "transfer")) {
2945 BT_DBG("Obex_Server_Session_Transfer connected");
2946 _bt_obex_transfer_connected(obj_path);
2949 } else if (strcasecmp(member, "InterfacesRemoved") == 0) {
2950 /*Handle OPP_SERVER_DISCONNECTED_EVENT here */
2951 if (__bt_get_object_path(parameters, &obj_path)) {
2952 BT_ERR("Fail to get the path");
2955 BT_DBG("object_path = [%s]", obj_path);
2957 if (strncmp(obj_path, BT_SESSION_BASEPATH_CLIENT,
2958 strlen(BT_SESSION_BASEPATH_CLIENT)) == 0) {
2959 BT_DBG("Call PBAP Disconnected");
2960 _bt_obex_pbap_client_disconnect(obj_path);
2963 if (strncmp(obj_path, BT_SESSION_BASEPATH_SERVER,
2964 strlen(BT_SESSION_BASEPATH_SERVER)) != 0) {
2969 if (g_strrstr(obj_path, "session") && g_strrstr(obj_path, "transfer")) {
2970 BT_DBG("Obex_Server_Session_Transfer disconnected %s",
2973 _bt_obex_transfer_disconnected(obj_path);
2976 } else if (__bt_is_obexd_event(parameters, interface_name) == TRUE) {
2977 const char *path = object_path;
2979 if (strncmp(path, BT_SESSION_BASEPATH_SERVER,
2980 strlen(BT_SESSION_BASEPATH_SERVER)) != 0 &&
2981 strncmp(path, BT_SESSION_BASEPATH_CLIENT,
2982 strlen(BT_SESSION_BASEPATH_CLIENT)) != 0) {
2983 BT_DBG("DBUS_HANDLER_RESULT_NOT_YET_HANDLED");
2987 _bt_handle_property_changed_event(parameters, path);
2993 static gboolean __bt_is_obexd_client_event(GVariant *msg, const char *interface)
2997 if (g_strcmp0(interface, BT_PROPERTIES_INTERFACE) == 0) {
2998 char *interface_name = NULL;
3000 g_variant_get(msg, "(&s@a{sv}@as)", &interface_name, NULL, NULL);
3002 retv_if(interface_name == NULL, FALSE);
3004 if (strcasecmp(interface_name,
3005 BT_OBEX_TRANSFER_INTERFACE) == 0) {
3016 static void __bt_opc_event_filter(GDBusConnection *connection,
3017 const gchar *sender_name,
3018 const gchar *object_path,
3019 const gchar *interface_name,
3020 const gchar *signal_name,
3021 GVariant *parameters,
3024 const char *member = signal_name;
3025 char *obj_path = NULL;
3026 if (strcasecmp(member, "InterfacesAdded") == 0) {
3027 BT_DBG("InterfacesAdded");
3028 } else if (strcasecmp(member, "InterfacesRemoved") == 0) {
3030 if (__bt_get_object_path(parameters, &obj_path)) {
3031 BT_ERR("Fail to get the path");
3035 BT_DBG("object_path = %s", obj_path);
3037 if (strncmp(obj_path, BT_SESSION_BASEPATH_CLIENT,
3038 strlen(BT_SESSION_BASEPATH_CLIENT)) != 0
3039 || strstr(obj_path, "transfer") == NULL) {
3042 } else if (strncmp(obj_path, BT_SESSION_BASEPATH_CLIENT,
3043 strlen(BT_SESSION_BASEPATH_CLIENT)) == 0) {
3044 BT_DBG("Going to call opc disconnected");
3045 _bt_opc_disconnected(obj_path);
3048 _bt_sending_files();
3050 } else if (__bt_is_obexd_client_event(parameters, interface_name) == TRUE) {
3051 char *path = (char *)object_path;
3052 BT_INFO("object_path %s", path);
3053 if (strncmp(path, BT_SESSION_BASEPATH_CLIENT,
3054 strlen(BT_SESSION_BASEPATH_CLIENT)) != 0) {
3055 BT_DBG("NOT BT_SESSION_BASEPATH_CLIENT");
3059 _bt_opc_property_changed_event(parameters, path);
3065 int _bt_opp_client_event_init(void)
3067 GError *error = NULL;
3069 if (opc_obexd_conn == NULL) {
3070 opc_obexd_conn = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &error);
3072 if (!opc_obexd_conn) {
3074 BT_ERR("Unable to connect to dbus: %s", error->message);
3075 g_clear_error(&error);
3077 return BLUETOOTH_ERROR_INTERNAL;
3081 if (_bt_register_service_event(opc_obexd_conn,
3082 BT_OPP_CLIENT_EVENT) != BLUETOOTH_ERROR_NONE) {
3083 g_object_unref(opc_obexd_conn);
3084 opc_obexd_conn = NULL;
3085 return BLUETOOTH_ERROR_INTERNAL;
3088 return BLUETOOTH_ERROR_NONE;
3091 void _bt_opp_client_event_deinit(void)
3093 if (opc_obexd_conn) {
3094 _bt_unregister_service_event(opc_obexd_conn,
3095 BT_OPP_CLIENT_EVENT);
3096 g_object_unref(opc_obexd_conn);
3097 opc_obexd_conn = NULL;
3101 int _bt_register_manager_subscribe_signal(GDBusConnection *conn,
3107 static int subs_interface_added_id = -1;
3108 static int subs_interface_removed_id = -1;
3109 static int subs_name_owner_id = -1;
3110 static int subs_property_id = -1;
3111 static int subs_adapter_id = -1;
3112 static int subs_gatt_id = -1;
3115 if (subs_interface_added_id == -1) {
3116 subs_interface_added_id = g_dbus_connection_signal_subscribe(conn,
3117 NULL, BT_MANAGER_INTERFACE,
3118 BT_INTERFACES_ADDED, NULL, NULL, 0,
3119 __bt_manager_event_filter,
3122 if (subs_interface_removed_id == -1) {
3123 subs_interface_removed_id = g_dbus_connection_signal_subscribe(conn,
3124 NULL, BT_MANAGER_INTERFACE,
3125 BT_INTERFACES_REMOVED, NULL, NULL, 0,
3126 __bt_manager_event_filter,
3129 if (subs_name_owner_id == -1) {
3130 subs_name_owner_id = g_dbus_connection_signal_subscribe(conn,
3131 NULL, BT_FREEDESKTOP_INTERFACE,
3132 BT_NAME_OWNER_CHANGED, NULL, NULL, 0,
3133 __bt_manager_event_filter,
3136 if (subs_property_id == -1) {
3137 subs_property_id = g_dbus_connection_signal_subscribe(conn,
3138 NULL, BT_PROPERTIES_INTERFACE,
3139 BT_PROPERTIES_CHANGED, NULL, NULL, 0,
3140 __bt_manager_event_filter,
3143 if (subs_adapter_id == -1) {
3144 subs_adapter_id = g_dbus_connection_signal_subscribe(conn,
3145 NULL, BT_ADAPTER_INTERFACE,
3146 NULL, NULL, NULL, 0,
3147 __bt_manager_event_filter,
3150 if (subs_gatt_id == -1) {
3151 subs_gatt_id = g_dbus_connection_signal_subscribe(conn,
3152 NULL, BT_GATT_CHAR_INTERFACE,
3153 NULL, NULL, NULL, 0,
3154 __bt_manager_event_filter,
3158 if (subs_interface_added_id != -1) {
3159 g_dbus_connection_signal_unsubscribe(conn,
3160 subs_interface_added_id);
3161 subs_interface_added_id = -1;
3163 if (subs_interface_removed_id != -1) {
3164 g_dbus_connection_signal_unsubscribe(conn,
3165 subs_interface_removed_id);
3166 subs_interface_removed_id = -1;
3168 if (subs_name_owner_id != -1) {
3169 g_dbus_connection_signal_unsubscribe(conn,
3170 subs_name_owner_id);
3171 subs_name_owner_id = -1;
3173 if (subs_property_id != -1) {
3174 g_dbus_connection_signal_unsubscribe(conn,
3176 subs_property_id = -1;
3178 if (subs_adapter_id != -1) {
3179 g_dbus_connection_signal_unsubscribe(conn, subs_adapter_id);
3180 subs_adapter_id = -1;
3182 if (subs_gatt_id != -1) {
3183 g_dbus_connection_signal_unsubscribe(conn, subs_gatt_id);
3190 int _bt_register_device_subscribe_signal(GDBusConnection *conn,
3196 static int subs_device_id = -1;
3199 if (subs_device_id == -1) {
3200 subs_device_id = g_dbus_connection_signal_subscribe(conn,
3201 NULL, BT_DEVICE_INTERFACE,
3202 NULL, NULL, NULL, 0,
3203 __bt_manager_event_filter,
3207 if (subs_device_id != -1) {
3208 g_dbus_connection_signal_unsubscribe(conn,
3210 subs_device_id = -1;
3216 int _bt_register_input_subscribe_signal(GDBusConnection *conn,
3222 static int subs_input_id = -1;
3225 if (subs_input_id == -1) {
3226 subs_input_id = g_dbus_connection_signal_subscribe(conn,
3227 NULL, BT_INPUT_INTERFACE,
3228 NULL, NULL, NULL, 0,
3229 __bt_manager_event_filter,
3233 if (subs_input_id != -1) {
3234 g_dbus_connection_signal_unsubscribe(conn,
3242 int _bt_register_network_subscribe_signal(GDBusConnection *conn,
3248 static int subs_serv_id = -1;
3249 static int subs_client_id = -1;
3252 if (subs_serv_id == -1) {
3253 subs_serv_id = g_dbus_connection_signal_subscribe(conn,
3254 NULL, BT_NETWORK_SERVER_INTERFACE,
3255 NULL, NULL, NULL, 0,
3256 __bt_manager_event_filter,
3259 if (subs_client_id == -1) {
3260 subs_client_id = g_dbus_connection_signal_subscribe(conn,
3261 NULL, BT_NETWORK_CLIENT_INTERFACE,
3262 NULL, NULL, NULL, 0,
3263 __bt_manager_event_filter,
3267 if (subs_serv_id != -1) {
3268 g_dbus_connection_signal_unsubscribe(conn,
3272 if (subs_client_id != -1) {
3273 g_dbus_connection_signal_unsubscribe(conn,
3275 subs_client_id = -1;
3281 int _bt_register_audio_subscribe_signal(GDBusConnection *conn,
3287 static int subs_headset_id = -1;
3288 static int subs_sink_id = -1;
3291 if (subs_headset_id == -1) {
3292 subs_headset_id = g_dbus_connection_signal_subscribe(conn,
3293 NULL, BT_HEADSET_INTERFACE,
3294 "PropertyChanged", NULL, NULL, 0,
3295 __bt_manager_event_filter,
3298 if (subs_sink_id == -1) {
3299 subs_sink_id = g_dbus_connection_signal_subscribe(conn,
3300 NULL, BT_SINK_INTERFACE,
3301 NULL, NULL, NULL, 0,
3302 __bt_manager_event_filter,
3306 if (subs_headset_id != -1) {
3307 g_dbus_connection_signal_unsubscribe(conn,
3309 subs_headset_id = -1;
3311 if (subs_sink_id != -1) {
3312 g_dbus_connection_signal_unsubscribe(conn,
3320 int _bt_register_opp_server_subscribe_signal(GDBusConnection *conn,
3326 static int subs_opp_server_interface_added_id = -1;
3327 static int subs_opp_server_interface_removed_id = -1;
3328 static int subs_opp_server_property_id = -1;
3332 if (subs_opp_server_interface_added_id == -1) {
3333 subs_opp_server_interface_added_id = g_dbus_connection_signal_subscribe(conn,
3334 NULL, BT_MANAGER_INTERFACE,
3335 BT_INTERFACES_ADDED, NULL, NULL, 0,
3336 __bt_obexd_event_filter,
3339 if (subs_opp_server_interface_removed_id == -1) {
3340 subs_opp_server_interface_removed_id = g_dbus_connection_signal_subscribe(conn,
3341 NULL, BT_MANAGER_INTERFACE,
3342 BT_INTERFACES_REMOVED, NULL, NULL, 0,
3343 __bt_obexd_event_filter,
3346 if (subs_opp_server_property_id == -1) {
3347 subs_opp_server_property_id = g_dbus_connection_signal_subscribe(conn,
3348 NULL, BT_PROPERTIES_INTERFACE,
3349 BT_PROPERTIES_CHANGED, NULL, NULL, 0,
3350 __bt_obexd_event_filter,
3354 if (subs_opp_server_interface_added_id != -1) {
3355 g_dbus_connection_signal_unsubscribe(conn,
3356 subs_opp_server_interface_added_id);
3357 subs_opp_server_interface_added_id = -1;
3359 if (subs_opp_server_interface_removed_id != -1) {
3360 g_dbus_connection_signal_unsubscribe(conn,
3361 subs_opp_server_interface_removed_id);
3362 subs_opp_server_interface_removed_id = -1;
3364 if (subs_opp_server_property_id != -1) {
3365 g_dbus_connection_signal_unsubscribe(conn,
3366 subs_opp_server_property_id);
3367 subs_opp_server_property_id = -1;
3373 int _bt_register_opp_client_subscribe_signal(GDBusConnection *conn,
3379 static int subs_opp_client_interface_added_id = -1;
3380 static int subs_opp_client_interface_removed_id = -1;
3381 static int subs_opp_client_property_id = -1;
3385 if (subs_opp_client_interface_added_id == -1) {
3386 subs_opp_client_interface_added_id = g_dbus_connection_signal_subscribe(conn,
3387 NULL, BT_MANAGER_INTERFACE,
3388 BT_INTERFACES_ADDED, NULL, NULL, 0,
3389 __bt_opc_event_filter,
3392 if (subs_opp_client_interface_removed_id == -1) {
3393 subs_opp_client_interface_removed_id = g_dbus_connection_signal_subscribe(conn,
3394 NULL, BT_MANAGER_INTERFACE,
3395 BT_INTERFACES_REMOVED, NULL, NULL, 0,
3396 __bt_opc_event_filter,
3399 if (subs_opp_client_property_id == -1) {
3400 subs_opp_client_property_id = g_dbus_connection_signal_subscribe(conn,
3401 NULL, BT_PROPERTIES_INTERFACE,
3402 BT_PROPERTIES_CHANGED, NULL, NULL, 0,
3403 __bt_opc_event_filter,
3407 if (subs_opp_client_interface_added_id != -1) {
3408 g_dbus_connection_signal_unsubscribe(conn,
3409 subs_opp_client_interface_added_id);
3410 subs_opp_client_interface_added_id = -1;
3412 if (subs_opp_client_interface_removed_id != -1) {
3413 g_dbus_connection_signal_unsubscribe(conn,
3414 subs_opp_client_interface_removed_id);
3415 subs_opp_client_interface_removed_id = -1;
3417 if (subs_opp_client_property_id != -1) {
3418 g_dbus_connection_signal_unsubscribe(conn,
3419 subs_opp_client_property_id);
3420 subs_opp_client_property_id = -1;
3426 int _bt_register_a2dp_subscribe_signal(GDBusConnection *conn,
3432 static int subs_a2dp_source_id = -1;
3433 static int subs_a2dp_sink_id = -1;
3436 if (subs_a2dp_source_id == -1) {
3437 subs_a2dp_source_id = g_dbus_connection_signal_subscribe(conn,
3438 NULL, BT_A2DP_SOURCE_INTERFACE,
3439 NULL, NULL, NULL, 0,
3440 __bt_opc_event_filter,
3443 if (subs_a2dp_sink_id == -1) {
3444 subs_a2dp_sink_id = g_dbus_connection_signal_subscribe(conn,
3445 NULL, BT_SINK_INTERFACE,
3446 NULL, NULL, NULL, 0,
3447 __bt_opc_event_filter,
3451 if (subs_a2dp_source_id != -1) {
3452 g_dbus_connection_signal_unsubscribe(conn,
3453 subs_a2dp_source_id);
3454 subs_a2dp_source_id = -1;
3456 if (subs_a2dp_sink_id != -1) {
3457 g_dbus_connection_signal_unsubscribe(conn,
3459 subs_a2dp_sink_id = -1;
3465 static void __bt_dump_event_filter(GDBusConnection *connection,
3466 const gchar *sender_name,
3467 const gchar *object_path,
3468 const gchar *interface_name,
3469 const gchar *signal_name,
3470 GVariant *parameters,
3476 int __bt_register_dump_subscribe_signal(GDBusConnection *conn,
3482 static int subs_source_id = -1;
3485 if (subs_source_id == -1) {
3486 subs_source_id = g_dbus_connection_signal_subscribe(conn,
3487 NULL, BT_DUMP_SERVICE_INTERFACE,
3488 BT_DUMP_SERVICE_SIGNAL, BT_DUMP_SERVICE_PATH, NULL, 0,
3489 __bt_dump_event_filter,
3493 if (subs_source_id != -1) {
3494 g_dbus_connection_signal_unsubscribe(conn,
3496 subs_source_id = -1;
3502 int _bt_register_service_event(GDBusConnection *g_conn, int event_type)
3506 retv_if(g_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
3508 switch (event_type) {
3509 case BT_MANAGER_EVENT:
3510 _bt_register_manager_subscribe_signal(g_conn, TRUE);
3512 case BT_DEVICE_EVENT:
3513 _bt_register_device_subscribe_signal(g_conn, TRUE);
3516 _bt_register_input_subscribe_signal(g_conn, TRUE);
3518 case BT_NETWORK_EVENT:
3519 _bt_register_network_subscribe_signal(g_conn, TRUE);
3521 case BT_HEADSET_EVENT:
3522 _bt_register_audio_subscribe_signal(g_conn, TRUE);
3525 case BT_OPP_SERVER_EVENT:
3526 BT_ERR("BT_OPP_SERVER_EVENT: register service event");
3527 _bt_register_opp_server_subscribe_signal(g_conn, TRUE);
3529 case BT_OPP_CLIENT_EVENT:
3530 BT_ERR("BT_OPP_CLIENT_EVENT: register service event");
3531 _bt_register_opp_client_subscribe_signal(g_conn, TRUE);
3533 case BT_A2DP_SOURCE_EVENT:
3534 BT_INFO("A2dp Source event");
3535 _bt_register_a2dp_subscribe_signal(g_conn, TRUE);
3538 BT_ERR("Unknown event");
3539 return BLUETOOTH_ERROR_INTERNAL;
3542 return BLUETOOTH_ERROR_NONE;
3545 void _bt_unregister_service_event(GDBusConnection *g_conn, int event_type)
3549 ret_if(g_conn == NULL);
3551 switch (event_type) {
3552 case BT_MANAGER_EVENT:
3553 _bt_register_manager_subscribe_signal(g_conn, FALSE);
3554 _bt_register_device_subscribe_signal(g_conn, FALSE);
3555 _bt_register_input_subscribe_signal(g_conn, FALSE);
3556 _bt_register_network_subscribe_signal(g_conn, FALSE);
3557 _bt_register_audio_subscribe_signal(g_conn, FALSE);
3559 case BT_OPP_SERVER_EVENT:
3560 _bt_register_opp_server_subscribe_signal(g_conn, FALSE);
3562 case BT_OPP_CLIENT_EVENT:
3563 _bt_register_opp_client_subscribe_signal(g_conn, FALSE);
3566 BT_ERR("Unknown event");
3573 static int __bt_init_manager_receiver(void)
3577 GError *error = NULL;
3579 if (manager_conn == NULL) {
3580 manager_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
3581 if (error != NULL) {
3582 BT_ERR("ERROR: Can't get on system bus [%s]", error->message);
3583 g_clear_error(&error);
3585 retv_if(manager_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
3588 if (_bt_register_service_event(manager_conn,
3589 BT_MANAGER_EVENT) != BLUETOOTH_ERROR_NONE)
3591 if (_bt_register_service_event(manager_conn,
3592 BT_DEVICE_EVENT) != BLUETOOTH_ERROR_NONE)
3595 if (_bt_register_service_event(manager_conn,
3596 BT_HID_EVENT) != BLUETOOTH_ERROR_NONE)
3599 if (_bt_register_service_event(manager_conn,
3600 BT_HEADSET_EVENT) != BLUETOOTH_ERROR_NONE)
3603 if (_bt_register_service_event(manager_conn,
3604 BT_NETWORK_EVENT) != BLUETOOTH_ERROR_NONE)
3607 __bt_register_dump_subscribe_signal(manager_conn, TRUE);
3608 return BLUETOOTH_ERROR_NONE;
3611 g_object_unref(manager_conn);
3612 manager_conn = NULL;
3617 return BLUETOOTH_ERROR_INTERNAL;
3620 static int __bt_init_obexd_receiver(void)
3623 #ifndef TIZEN_TV /* TODO: obexd doesn't work in TV profile. It should be resolved later. */
3624 GError *error = NULL;
3626 if (obexd_conn == NULL) {
3627 obexd_conn = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &error);
3628 if (error != NULL) {
3629 BT_ERR("ERROR: Can't get on session bus [%s]", error->message);
3630 g_clear_error(&error);
3632 retv_if(obexd_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
3635 if (_bt_register_service_event(obexd_conn,
3636 BT_OPP_SERVER_EVENT) != BLUETOOTH_ERROR_NONE) {
3637 BT_ERR("Error while registering service event");
3638 g_object_unref(obexd_conn);
3640 return BLUETOOTH_ERROR_INTERNAL;
3645 return BLUETOOTH_ERROR_NONE;
3648 gboolean __bt_reinit_obexd_receiver(gpointer user_data)
3650 static int retry_cnt = 0;
3651 int result = BLUETOOTH_ERROR_NONE;
3655 result = __bt_init_obexd_receiver();
3656 if (result != BLUETOOTH_ERROR_NONE) {
3657 /* 20 ms * 50 = 10 seconds. During 10 seconds fail to initialize,
3658 then it is not the timing issue. Just can't use the session bus connection */
3659 if (retry_cnt > 100) {
3660 BT_ERR("Fail to init obexd receiver by 50 times.");
3662 session_reinit_timer = 0;
3666 BT_DBG("Retry to initialize the obexd receiver");
3671 session_reinit_timer = 0;
3678 /* To receive the event from bluez */
3679 int _bt_init_service_event_receiver(void)
3685 result = __bt_init_manager_receiver();
3686 retv_if(result != BLUETOOTH_ERROR_NONE, result);
3688 result = __bt_init_obexd_receiver();
3689 if (result != BLUETOOTH_ERROR_NONE) {
3690 BT_ERR("Fail to init obexd receiver");
3692 /* Try to re-initialize obexd receiver in the timer */
3693 if (session_reinit_timer > 0)
3694 g_source_remove(session_reinit_timer);
3696 session_reinit_timer = g_timeout_add(BT_SESSION_BUS_GET_TIMEOUT,
3697 (GSourceFunc)__bt_reinit_obexd_receiver, NULL);
3702 return BLUETOOTH_ERROR_NONE;
3705 void _bt_deinit_service_event_receiver(void)
3709 _bt_unregister_service_event(manager_conn, BT_MANAGER_EVENT);
3711 _bt_unregister_service_event(obexd_conn, BT_OPP_SERVER_EVENT);
3713 __bt_register_dump_subscribe_signal(manager_conn, FALSE);
3716 g_object_unref(manager_conn);
3717 manager_conn = NULL;
3721 g_object_unref(obexd_conn);
3726 g_source_remove(event_id);