2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
22 #include <vconf-internal-bt-keys.h>
24 #include "bluetooth-api.h"
25 #include "bt-internal-types.h"
27 #include "bt-service-common.h"
28 #include "bt-service-event.h"
29 #include "bt-service-main.h"
30 #include "bt-service-adapter.h"
31 #include "bt-service-adapter-le.h"
32 #include "bt-service-device.h"
33 #include "bt-service-avrcp.h"
34 #include "bt-service-obex-server.h"
35 #include "bt-service-rfcomm-server.h"
36 #include "bt-service-audio.h"
37 #include "bt-service-agent.h"
38 #include "bt-service-pbap.h"
39 #include "bt-service-headset-connection.h"
40 #include "bt-service-avrcp-controller.h"
41 #include "bt-service-hid.h"
42 #include "bt-service-proximity.h"
44 #include "bt-service-opp-client.h"
46 #ifdef TIZEN_DPM_ENABLE
47 #include "bt-service-dpm.h"
50 #define DBUS_TIMEOUT 20 * 1000 /* 20 Sec */
51 static GDBusConnection *manager_conn;
52 static GDBusConnection *obexd_conn;
53 static GDBusConnection *opc_obexd_conn;
55 static GList *p_cache_list = NULL;
57 static guint event_id;
58 static guint session_reinit_timer;
59 guint nap_connected_device_count = 0;
60 static guint hid_connected_device_count = 0;
61 static GList *p_adv_ind_list = NULL;
64 bt_remote_dev_info_t *dev_info;
68 * obexd connection type
76 OBEX_PCSUITE = (1 << 6),
77 OBEX_SYNCEVOLUTION = (1 << 7),
79 } bluetooth_obex_connection_type_t;
81 void _bt_handle_property_changed_event(GVariant *msg, const char *object_path);
82 void _bt_opc_property_changed_event(GVariant *msg, char *path);
83 int _bt_register_service_event(GDBusConnection *g_conn, int event_type);
84 void _bt_unregister_service_event(GDBusConnection *g_conn, int event_type);
85 void _bt_opp_client_event_deinit(void);
86 void _bt_handle_network_client_event(GVariant *msg_iter,
88 void __bt_gatt_char_property_changed_event(GVariant *msg_iter,
91 static void __bt_free_bt_le_adv_info_t(gpointer data)
93 bt_le_adv_info_t *adv_info = data;
95 if (adv_info->timer_id)
96 g_source_remove(adv_info->timer_id);
97 adv_info->timer_id = 0;
99 g_free(adv_info->addr);
100 g_free(adv_info->data);
104 static bt_le_adv_info_t *__bt_get_adv_ind_info(char *addr)
106 retv_if(!addr, NULL);
107 bt_le_adv_info_t *adv_info = NULL;
108 GList *current = g_list_first((GList *)p_adv_ind_list);
109 while (current && current->data) {
110 adv_info = (bt_le_adv_info_t *)current->data;
111 if (adv_info && !g_strcmp0(adv_info->addr, addr))
113 current = g_list_next(current);
118 static int __bt_add_adv_ind_info(bt_le_adv_info_t *adv_info)
120 retv_if(!adv_info, -1);
121 if (__bt_get_adv_ind_info(adv_info->addr) != NULL) {
122 __bt_free_bt_le_adv_info_t(adv_info);
125 p_adv_ind_list = g_list_append(p_adv_ind_list, adv_info);
130 static void __bt_del_adv_ind_info(char *addr)
133 ret_if(!p_adv_ind_list);
134 bt_le_adv_info_t *adv_info = NULL;
135 GList *current = g_list_first((GList *)p_adv_ind_list);
136 while (current && current->data) {
137 adv_info = (bt_le_adv_info_t *)current->data;
138 if (adv_info && !g_strcmp0(adv_info->addr, addr)) {
139 p_adv_ind_list = g_list_remove(p_adv_ind_list, adv_info);
140 __bt_free_bt_le_adv_info_t(adv_info);
143 current = g_list_next(current);
147 static gboolean __bt_adv_scan_req_timeout_cb(gpointer user_data)
149 bt_remote_le_dev_info_t le_dev_info;
150 bt_le_adv_info_t *adv_info = (bt_le_adv_info_t*)user_data;
152 memset(&le_dev_info, 0x00, sizeof(bt_remote_le_dev_info_t));
154 le_dev_info.address = adv_info->addr;
155 le_dev_info.addr_type = adv_info->addr_type;
156 le_dev_info.rssi = adv_info->rssi;
157 le_dev_info.adv_data = adv_info->data;
158 le_dev_info.adv_data_len = 0;
159 adv_info->timer_id = 0;
161 _bt_send_scan_result_event(&le_dev_info, adv_info);
162 __bt_del_adv_ind_info(adv_info->addr);
167 static void __bt_free_cache_info(bt_cache_info_t *cache_info)
169 ret_if(cache_info == NULL);
170 _bt_free_device_info(cache_info->dev_info);
174 static gboolean __bt_parse_device_properties(GVariant *item,
175 bt_remote_dev_info_t *dev_info)
184 g_variant_iter_init(&iter, item);
185 while (g_variant_iter_loop(&iter, "{sv}", &key, &val)) {
186 if (strcasecmp(key, "Address") == 0) {
187 dev_info->address = g_variant_dup_string(val, &len);
188 } else if (strcasecmp(key, "Class") == 0) {
189 dev_info->class = g_variant_get_uint32(val);
190 } else if (strcasecmp(key, "name") == 0) {
191 if (dev_info->name == NULL)
192 dev_info->name = g_variant_dup_string(val, &len);
193 } else if (strcasecmp(key, "Connected") == 0) {
194 dev_info->connected = g_variant_get_byte(val);
195 } else if (strcasecmp(key, "paired") == 0) {
196 dev_info->paired = g_variant_get_boolean(val);
197 } else if (strcasecmp(key, "Trusted") == 0) {
198 dev_info->trust = g_variant_get_boolean(val);
199 } else if (strcasecmp(key, "RSSI") == 0) {
200 dev_info->rssi = g_variant_get_int16(val);
201 } else if (strcasecmp(key, "LastAddrType") == 0) {
202 dev_info->addr_type = g_variant_get_byte(val);
203 } else if (strcasecmp(key, "UUIDs") == 0) {
207 size = g_variant_get_size(val);
210 uuid_value = (char **)g_variant_get_strv(val, &size);
211 if (dev_info->uuids == NULL)
212 dev_info->uuids = g_malloc0(sizeof(char *) * size);
214 for (i = 0; uuid_value[i] != NULL; i++) {
215 dev_info->uuid_count++;
216 dev_info->uuids[i] = g_strdup(uuid_value[i]);
220 } else if (strcasecmp(key, "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, "(sss)", name, previous, current);
298 return BLUETOOTH_ERROR_NONE;
301 static int __bt_get_agent_signal_info(GVariant *msg, char **address,
302 char **name, char **uuid)
304 g_variant_get(msg, "(sss)", address, name, uuid);
305 return BLUETOOTH_ERROR_NONE;
308 void __bt_set_device_values(gboolean connected, int state)
310 int bt_device_state = VCONFKEY_BT_DEVICE_NONE;
312 if (vconf_get_int(VCONFKEY_BT_DEVICE, &bt_device_state) != 0)
313 BT_ERR("vconf_get_int failed");
315 if (connected == TRUE)
316 bt_device_state |= state;
317 else if (bt_device_state & state)
318 bt_device_state ^= state;
320 if (vconf_set_int(VCONFKEY_BT_DEVICE, bt_device_state) != 0)
321 BT_ERR("vconf_set_int failed");
324 gboolean _bt_discovery_finished_cb(gpointer user_data)
326 int result = BLUETOOTH_ERROR_NONE;
328 GVariant *param = NULL;
329 if (_bt_get_discovering_property(DISCOVERY_ROLE_BREDR) == FALSE) {
330 if (_bt_get_cancel_by_user() == TRUE)
331 result = BLUETOOTH_ERROR_CANCEL_BY_USER;
333 _bt_set_cancel_by_user(FALSE);
334 _bt_set_discovery_status(FALSE);
335 param = g_variant_new("(i)", result);
336 _bt_send_event(BT_ADAPTER_EVENT,
337 BLUETOOTH_EVENT_DISCOVERY_FINISHED,
344 static gboolean __bt_le_discovery_finished_cb(gpointer user_data)
346 int result = BLUETOOTH_ERROR_NONE;
348 GVariant *param = NULL;
349 if (_bt_get_discovering_property(DISCOVERY_ROLE_LE) == FALSE) {
350 if (_bt_get_cancel_by_user() == TRUE)
351 result = BLUETOOTH_ERROR_CANCEL_BY_USER;
353 g_list_free_full(p_adv_ind_list, __bt_free_bt_le_adv_info_t);
354 p_adv_ind_list = NULL;
356 _bt_set_cancel_by_user(FALSE);
357 _bt_disable_all_scanner_status();
358 _bt_set_le_scan_status(FALSE);
359 param = g_variant_new("(i)", result);
360 _bt_send_event(BT_LE_ADAPTER_EVENT,
361 BLUETOOTH_EVENT_LE_DISCOVERY_FINISHED,
368 void __bt_update_remote_cache_devinfo(const char *address, gboolean paired_status)
372 ret_if(address == NULL);
375 bt_cache_info_t *cache_info;
376 bt_remote_dev_info_t *dev_info;
378 node = g_list_first(p_cache_list);
380 while (node != NULL) {
381 cache_info = (bt_cache_info_t *)node->data;
383 if (cache_info == NULL) {
384 node = g_list_next(node);
388 dev_info = cache_info->dev_info;
389 if (strcasecmp(dev_info->address,
391 BT_DBG("Device Found");
392 if (paired_status == TRUE)
393 cache_info->dev_info->paired = TRUE;
395 cache_info->dev_info->paired = FALSE;
398 node = g_list_next(node);
403 static void __bt_device_remote_connected_properties(
404 bt_remote_dev_info_t *remote_dev_info,
405 char *address, gboolean connected)
407 int result = BLUETOOTH_ERROR_NONE;
409 GVariant *param = NULL;
412 if (remote_dev_info->uuid_count > 0) {
413 for (i = 0; i < remote_dev_info->uuid_count; i++) {
414 char *uuid = remote_dev_info->uuids[i];
415 if (strcasecmp(uuid, HID_UUID) == 0) {
416 int event = BLUETOOTH_EVENT_NONE;
418 event = (connected == TRUE) ?
419 BLUETOOTH_HID_CONNECTED :
420 BLUETOOTH_HID_DISCONNECTED;
421 param = g_variant_new("(is)", result,
423 _bt_send_event(BT_HID_EVENT, event,
433 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 if (_bt_is_device_creating() == TRUE) {
1091 BT_DBG("Try to Pair by me");
1092 _bt_free_device_info(remote_dev_info);
1095 g_variant_unref(val);
1098 GVariant *uuids = NULL;
1099 GVariantBuilder *builder = NULL;
1101 builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
1102 for (i = 0; i < remote_dev_info->uuid_count; i++) {
1103 g_variant_builder_add(builder, "s",
1104 remote_dev_info->uuids[i]);
1106 uuids = g_variant_new("as", builder);
1107 g_variant_builder_unref(builder);
1108 GVariant *manufacturer_data = NULL;
1109 manufacturer_data = g_variant_new_from_data(G_VARIANT_TYPE_BYTESTRING,
1110 remote_dev_info->manufacturer_data,
1111 remote_dev_info->manufacturer_data_len,
1115 param = g_variant_new("(isunsbub@asn@ay)", result,
1116 address, remote_dev_info->class,
1117 remote_dev_info->rssi,
1118 remote_dev_info->name,
1119 remote_dev_info->paired,
1120 remote_dev_info->connected,
1121 remote_dev_info->trust,
1123 remote_dev_info->manufacturer_data_len,
1125 _bt_send_event(BT_ADAPTER_EVENT,
1126 BLUETOOTH_EVENT_BONDING_FINISHED,
1129 _bt_free_device_info(remote_dev_info);
1131 } else if (strcasecmp(property, "LegacyPaired") == 0) {
1132 gboolean paired = FALSE;
1133 bt_remote_dev_info_t *remote_dev_info;
1134 unsigned char auth_info[5] = {0, };
1136 if (_bt_adapter_get_status() != BT_ACTIVATED) {
1137 BT_DBG("BT is not activated, so ignore this");
1139 g_variant_unref(val);
1143 g_variant_get(val, "b", &paired);
1144 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1145 BT_DBG("LegacyPaired: %d", paired);
1146 _bt_convert_device_path_to_address(path, address);
1148 remote_dev_info = _bt_get_remote_device_info_by_object_path(path);
1149 if (remote_dev_info == NULL) {
1152 g_variant_unref(val);
1155 if (remote_dev_info->is_alias_set == FALSE) {
1156 /*minimum Size of the samsung specific manufacturer data is greater than 30 */
1157 if ((remote_dev_info->manufacturer_data_len > 30) &&
1158 (remote_dev_info->manufacturer_data[0] == 0x00) &&
1159 (remote_dev_info->manufacturer_data[1] == 0x75)) {
1161 /* 2 samsung (0x00 0x75) + 1 (control and version) + 1 (service ID) +
1162 1 (discovery version) + 1 (associated service ID)
1163 2 (Proxamity and locality) + 2 (Device type and icon) = 10 */
1165 memcpy(auth_info, &(remote_dev_info->manufacturer_data[10]), 5);
1169 BT_DBG("LegacyPairing Failed with %s. Show Error Popup", remote_dev_info->name);
1170 _bt_launch_system_popup(BT_AGENT_EVENT_LEGACY_PAIR_FAILED_FROM_REMOTE,
1171 remote_dev_info->name, auth_info, NULL, NULL, NULL);
1173 _bt_free_device_info(remote_dev_info);
1175 } else if (strcasecmp(property, "Trusted") == 0) {
1176 gboolean trusted = FALSE;
1178 g_variant_get(val, "b", &trusted);
1180 event = trusted ? BLUETOOTH_EVENT_DEVICE_AUTHORIZED :
1181 BLUETOOTH_EVENT_DEVICE_UNAUTHORIZED;
1183 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1185 _bt_convert_device_path_to_address(path, address);
1187 BT_DBG("trusted: %d", trusted);
1188 BT_DBG("address: %s", address);
1189 param = g_variant_new("(is)", result, address);
1190 /* Send event to application */
1191 _bt_send_event(BT_DEVICE_EVENT,
1195 } else if (strcasecmp(property, "TrustedProfiles") == 0) {
1198 g_variant_get(val, "u", &trusted);
1200 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1201 _bt_convert_device_path_to_address(path, address);
1203 BT_DBG("Address: %s, TrustedProfiles: %d", address, trusted);
1204 _bt_send_event(BT_DEVICE_EVENT,
1205 BLUETOOTH_EVENT_SUPPORTED_PROFILE_TRUSTED,
1206 g_variant_new("(isi)", result, address, trusted));
1208 } else if (strcasecmp(property, "IpspConnected") == 0) {
1209 gboolean connected = FALSE;
1211 g_variant_get(val, "b", &connected);
1214 event = connected ? BLUETOOTH_EVENT_IPSP_CONNECTED :
1215 BLUETOOTH_EVENT_IPSP_DISCONNECTED;
1217 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1219 _bt_convert_device_path_to_address(path, address);
1221 BT_DBG("Ipspconnected: %d", connected);
1222 BT_DBG("address: %s", address);
1223 param = g_variant_new("(is)", result, address);
1225 /* Send event to application */
1226 _bt_send_event(BT_DEVICE_EVENT,
1230 } else if (strcasecmp(property, "IpspBtInterfaceInfo") == 0) {
1231 char *ifname = NULL;
1233 g_variant_get(val, "s", &ifname);
1235 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1237 _bt_convert_device_path_to_address(path, address);
1239 BT_DBG("Ipsp BT Interface Name: %s", ifname);
1240 BT_DBG("address: %s", address);
1241 param = g_variant_new("(iss)", result, address, ifname);
1243 /* Send event to application */
1244 _bt_send_event(BT_DEVICE_EVENT,
1245 BLUETOOTH_EVENT_IPSP_INTERFACE_INFO,
1253 static void __bt_media_control_changed_event(GVariant *msg, const char *path)
1256 int result = BLUETOOTH_ERROR_NONE;
1257 GVariantIter value_iter;
1258 char *property = NULL;
1260 GVariant *val = NULL;
1261 GVariant *child = NULL;
1262 bt_remote_dev_info_t *remote_dev_info;
1263 GVariant *param = NULL;
1264 g_variant_iter_init(&value_iter, msg);
1265 while ((child = g_variant_iter_next_value(&value_iter))) {
1266 g_variant_get(child, "{sv}", &property, &val);
1267 BT_INFO("Property %s", property);
1268 if (strcasecmp(property, "Connected") == 0) {
1269 gboolean connected = FALSE;
1271 g_variant_get(val, "b", &connected);
1273 event = connected ? BLUETOOTH_EVENT_AVRCP_CONNECTED :
1274 BLUETOOTH_EVENT_AVRCP_DISCONNECTED;
1276 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1278 _bt_convert_device_path_to_address(path, address);
1280 BT_DBG("connected: %d", connected);
1281 BT_DBG("address: %s", address);
1283 remote_dev_info = _bt_get_remote_device_info(address);
1285 if (remote_dev_info != NULL) {
1286 __bt_device_remote_connected_properties(
1287 remote_dev_info, address, connected);
1288 _bt_free_device_info(remote_dev_info);
1290 param = g_variant_new("(is)", result, address);
1291 /* Send event to application */
1292 _bt_send_event(BT_AVRCP_EVENT,
1298 g_variant_unref(child);
1299 g_variant_unref(val);
1304 int get_alert_level_enum(const char *alert)
1308 if (strcmp(alert, "none") == 0)
1309 lvl = BT_PXP_ALERT_NONE;
1310 else if (strcmp(alert, "mild") == 0)
1311 lvl = BT_PXP_ALERT_MILD;
1312 else if (strcmp(alert, "high") == 0)
1313 lvl = BT_PXP_ALERT_HIGH;
1318 static void _bt_handle_pxp_property_changed_event(GVariant *msg, const char *path, int role)
1320 int result = BLUETOOTH_ERROR_NONE;
1323 GVariantIter value_iter;
1324 char *property = NULL;
1326 GVariant *val = NULL;
1327 GVariant *child = NULL;
1328 GVariant *param = NULL;
1329 g_variant_iter_init(&value_iter, msg);
1332 while ((child = g_variant_iter_next_value(&value_iter))) {
1333 g_variant_get(child, "{sv}", &property, &val);
1334 BT_INFO("Property %s", property);
1336 if ((strcasecmp(property, "LinkLossAlertLevel") == 0) ||
1337 (strcasecmp(property, "ImmediateAlertLevel") == 0)) {
1338 char *alert_str = NULL;
1340 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1341 _bt_convert_device_path_to_address(path, address);
1343 if (strcasecmp(property, "LinkLossAlertLevel") == 0)
1344 service_type = BT_PXP_PROPERTY_LLS;
1346 service_type = BT_PXP_PROPERTY_IAS;
1348 g_variant_get(val, "s", &alert_str);
1349 alert_lvl = get_alert_level_enum(alert_str);
1351 param = g_variant_new("(isiii)", result, address,
1352 role, service_type, alert_lvl);
1354 /* Send event to application */
1355 _bt_send_event(BT_DEVICE_EVENT,
1356 BLUETOOTH_EVENT_PXP_PROPERTY_CHANGED,
1362 g_variant_unref(child);
1363 g_variant_unref(val);
1368 void _bt_handle_property_changed_event(GVariant *msg, const char *object_path)
1370 char *interface_name = NULL;
1371 GVariant *val = NULL;
1373 g_variant_get(msg, "(&s@a{sv}@as)", &interface_name, &val, NULL);
1375 if (strcasecmp(interface_name, BT_ADAPTER_INTERFACE) == 0) {
1376 __bt_adapter_property_changed_event(val,
1378 } else if (strcasecmp(interface_name, BT_DEVICE_INTERFACE) == 0) {
1379 __bt_device_property_changed_event(val, object_path);
1380 } else if (strcasecmp(interface_name, BT_OBEX_TRANSFER_INTERFACE) == 0) {
1381 BT_DBG("BT_OBEX_TRANSFER_INTERFACE");
1382 __bt_obex_property_changed_event(val,
1384 } else if (strcasecmp(interface_name, BT_MEDIA_CONTROL_INTERFACE) == 0) {
1385 __bt_media_control_changed_event(val,
1387 } else if (strcasecmp(interface_name, BT_PLAYER_CONTROL_INTERFACE) == 0) {
1388 _bt_handle_avrcp_control_event(val,
1390 } else if (strcasecmp(interface_name, BT_NETWORK_CLIENT_INTERFACE) == 0) {
1391 BT_DBG("BT_NETWORK_CLIENT_INTERFACE");
1392 _bt_handle_network_client_event(val,
1394 } else if (strcasecmp(interface_name, BT_GATT_CHAR_INTERFACE) == 0) {
1395 __bt_gatt_char_property_changed_event(val,
1397 } else if (strcasecmp(interface_name, BT_PROXIMITY_REPORTER_INTERFACE) == 0) {
1398 BT_DBG("BT_PROXIMITY_REPORTER_INTERFACE");
1399 _bt_handle_pxp_property_changed_event(val,
1400 object_path, BT_PXP_REPORTER_ROLE);
1401 } else if (strcasecmp(interface_name, BT_PROXIMITY_MONITOR_INTERFACE) == 0) {
1402 BT_DBG("BT_PROXIMITY_MONITOR_INTERFACE");
1403 _bt_handle_pxp_property_changed_event(val,
1404 object_path, BT_PXP_MONITOR_ROLE);
1406 g_variant_unref(val);
1409 void __bt_opc_property_changed_event(GVariant *msg,
1412 GVariantIter value_iter;
1413 char *property = NULL;
1414 GVariant *val = NULL;
1415 GVariant *child = NULL;
1417 g_variant_iter_init(&value_iter, msg);
1418 while ((child = g_variant_iter_next_value(&value_iter))) {
1419 g_variant_get(child, "{sv}", &property, &val);
1420 ret_if(property == NULL);
1422 if (strcasecmp(property, "Status") == 0) {
1423 char *status = NULL;
1424 g_variant_get(val, "s", &status);
1425 BT_DBG("Status is %s", status);
1427 if (strcasecmp(status, "active") == 0)
1428 _bt_obex_client_started(path);
1429 else if (strcasecmp(status, "complete") == 0)
1430 _bt_obex_client_completed(path, TRUE);
1431 else if (strcasecmp(status, "error") == 0)
1432 _bt_obex_client_completed(path, FALSE);
1435 } else if (strcasecmp(property, "Transferred") == 0) {
1436 guint64 transferred = 0;
1437 g_variant_get(val, "t", &transferred);
1439 _bt_obex_client_progress(path, transferred);
1441 BT_DBG("property : [%s]", property);
1444 g_variant_unref(child);
1445 g_variant_unref(val);
1449 void _bt_opc_property_changed_event(GVariant *msg, char *path)
1451 char *interface_name = NULL;
1452 GVariant *value = NULL;
1453 g_variant_get(msg, "(&s@a{sv}@as)", &interface_name, &value, NULL);
1454 BT_INFO("interface_name = %s", interface_name);
1455 if (strcasecmp(interface_name, BT_OBEX_TRANSFER_INTERFACE) == 0) {
1456 __bt_opc_property_changed_event(value,
1459 BT_DBG("interface_name : [%s]", interface_name);
1461 g_variant_unref(value);
1465 void _bt_handle_input_event(GVariant *msg, const char *path)
1467 int result = BLUETOOTH_ERROR_NONE;
1468 gboolean property_flag = FALSE;
1469 GVariantIter value_iter;
1470 char *property = NULL;
1471 GVariant *child = NULL, *val = NULL;
1472 bt_remote_dev_info_t *remote_dev_info;
1473 GVariant *param = NULL;
1474 g_variant_iter_init(&value_iter, msg);
1475 while ((child = g_variant_iter_next_value(&value_iter))) {
1476 g_variant_get(child, "{sv}", &property, &val);
1478 ret_if(property == NULL);
1480 if (strcasecmp(property, "Connected") == 0) {
1481 int event = BLUETOOTH_EVENT_NONE;
1483 g_variant_get(val, "b", &property_flag);
1485 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1487 _bt_convert_device_path_to_address(path, address);
1489 event = (property_flag == TRUE) ?
1490 BLUETOOTH_HID_CONNECTED :
1491 BLUETOOTH_HID_DISCONNECTED;
1492 param = g_variant_new("(is)", result, address);
1493 _bt_send_event(BT_HID_EVENT, event,
1495 /* Check HID connection type (Keyboard or Mouse) and update the status */
1496 remote_dev_info = _bt_get_remote_device_info_by_object_path(path);
1498 if (property_flag == TRUE) {
1499 hid_connected_device_count++;
1500 __bt_set_device_values(TRUE,
1501 VCONFKEY_BT_DEVICE_HID_CONNECTED);
1503 hid_connected_device_count--;
1504 if (hid_connected_device_count == 0)
1505 __bt_set_device_values(FALSE,
1506 VCONFKEY_BT_DEVICE_HID_CONNECTED);
1509 if (remote_dev_info != NULL) {
1510 BT_DBG("HID device class [%x]", remote_dev_info->class);
1511 if (remote_dev_info->class &
1512 BLUETOOTH_DEVICE_MINOR_CLASS_KEY_BOARD) {
1513 __bt_set_device_values(property_flag,
1514 VCONFKEY_BT_DEVICE_HID_KEYBOARD_CONNECTED);
1518 if (remote_dev_info->class &
1519 BLUETOOTH_DEVICE_MINOR_CLASS_POINTING_DEVICE) {
1520 __bt_set_device_values(property_flag,
1521 VCONFKEY_BT_DEVICE_HID_MOUSE_CONNECTED);
1523 _bt_free_device_info(remote_dev_info);
1528 g_variant_unref(val);
1529 g_variant_unref(child);
1533 void _bt_handle_network_server_event(GVariant *msg, const char *member)
1535 int result = BLUETOOTH_ERROR_NONE;
1536 char *address = NULL;
1537 char *device = NULL;
1538 GVariant *param = NULL;
1539 ret_if(member == NULL);
1540 if (strcasecmp(member, "PeerConnected") == 0) {
1541 g_variant_get(msg, "(ss)", &device, &address);
1543 __bt_set_device_values(TRUE,
1544 VCONFKEY_BT_DEVICE_PAN_CONNECTED);
1545 param = g_variant_new("(iss)", result, device, address);
1546 _bt_send_event(BT_NETWORK_EVENT, BLUETOOTH_EVENT_NETWORK_SERVER_CONNECTED,
1550 nap_connected_device_count++;
1551 } else if (strcasecmp(member, "PeerDisconnected") == 0) {
1552 g_variant_get(msg, "(ss)", &device, &address);
1553 nap_connected_device_count--;
1554 if (nap_connected_device_count == 0)
1555 __bt_set_device_values(FALSE,
1556 VCONFKEY_BT_DEVICE_PAN_CONNECTED);
1557 param = g_variant_new("(iss)", result, device, address);
1558 _bt_send_event(BT_NETWORK_EVENT, BLUETOOTH_EVENT_NETWORK_SERVER_DISCONNECTED,
1565 void _bt_handle_network_client_event(GVariant *msg,
1570 int result = BLUETOOTH_ERROR_NONE;
1571 gboolean property_flag = FALSE;
1572 char *property = NULL;
1573 GVariant *val = NULL;
1574 GVariantIter value_iter;
1575 GVariant *param = NULL;
1576 g_variant_iter_init(&value_iter, msg);
1577 while ((g_variant_iter_loop(&value_iter, "{sv}", &property, &val))) {
1578 if (strcasecmp(property, "Connected") == 0) {
1579 int event = BLUETOOTH_EVENT_NONE;
1582 g_variant_get(val, "b", &property_flag);
1583 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1585 _bt_convert_device_path_to_address(path, address);
1587 BT_DBG("property_flag %d", property_flag);
1588 if (property_flag == TRUE) {
1589 event = BLUETOOTH_EVENT_NETWORK_CONNECTED;
1590 nap_connected_device_count++;
1591 __bt_set_device_values(TRUE,
1592 VCONFKEY_BT_DEVICE_PAN_CONNECTED);
1594 event = BLUETOOTH_EVENT_NETWORK_DISCONNECTED;
1595 nap_connected_device_count--;
1596 if (nap_connected_device_count == 0)
1597 __bt_set_device_values(FALSE,
1598 VCONFKEY_BT_DEVICE_PAN_CONNECTED);
1600 param = g_variant_new("(is)", result, address);
1601 _bt_send_event(BT_NETWORK_EVENT, event,
1610 void __bt_gatt_char_property_changed_event(GVariant *msg,
1613 GVariantIter value_iter;
1614 char *property = NULL;
1615 char * char_handle = NULL;
1616 GVariant *val = NULL;
1617 int result = BLUETOOTH_ERROR_NONE;
1618 GVariant *param = NULL;
1619 g_variant_iter_init(&value_iter, msg);
1620 char_handle = g_strdup(path);
1621 while ((g_variant_iter_loop(&value_iter, "{sv}", &property, &val))) {
1622 BT_DBG("Property %s", property);
1624 ret_if(property == NULL);
1626 if (strcasecmp(property, "Notifying") == 0) {
1627 gboolean property_flag = FALSE;
1628 g_variant_get(val, "b", &property_flag);
1629 BT_INFO("Notifying is %s", property_flag ? "enabled" : "disabled");
1630 } else if (strcasecmp(property, "ChangedValue") == 0) {
1632 GByteArray *gp_byte_array = NULL;
1633 BT_INFO("Type '%s'\n", g_variant_get_type_string(val));
1636 gp_byte_array = g_byte_array_new();
1637 len = g_variant_get_size(val);
1638 BT_DBG("Len = %d", len);
1639 g_byte_array_append(gp_byte_array,
1640 (const guint8 *) g_variant_get_data(val), len);
1641 if (gp_byte_array->len != 0) {
1642 GVariant *byte_array = NULL;
1643 byte_array = g_variant_new_from_data(
1644 G_VARIANT_TYPE_BYTESTRING,
1645 gp_byte_array->data,
1648 param = g_variant_new("(is@ay)", result, char_handle,
1651 /* Send event only registered client */
1652 _bt_send_char_value_changed_event(param);
1654 g_byte_array_free(gp_byte_array, TRUE);
1658 g_free(char_handle);
1661 void _bt_handle_gatt_event(GVariant *msg, const char *member, const char *path)
1663 ret_if(path == NULL);
1665 if (strcasecmp(member, "GattValueChanged") == 0) {
1668 /*** Debug only ***/
1669 GVariant *value = NULL;
1671 char *buffer = NULL;
1673 g_variant_get(msg, "(is@ay)", NULL, NULL, &value);
1674 value_len = g_variant_get_size(value);
1675 if (value_len > 0) {
1676 char buf[8 * 5 + 1] = { 0 };
1679 buffer = (char *)g_variant_get_data(value);
1680 to = value_len > (sizeof(buf) / 5) ? sizeof(buf) / 5 : value_len;
1682 for (i = 0; i < to; i++)
1683 snprintf(&buf[i * 5], 6, "0x%02x ", buffer[i]);
1685 BT_DBG("GATT Val[%d] %s", value_len, buf);
1687 g_variant_unref(value);
1691 /* Send event only registered client */
1692 _bt_send_char_value_changed_event(msg);
1697 void _bt_handle_device_event(GVariant *msg, const char *member, const char *path)
1700 int result = BLUETOOTH_ERROR_NONE;
1702 char *dev_name = NULL;
1703 const char *property = NULL;
1704 GVariant *param = NULL;
1705 char secure_address[BT_ADDRESS_STRING_SIZE] = { 0 };
1706 ret_if(path == NULL);
1708 if (strcasecmp(member, "PropertyChanged") == 0) {
1710 g_variant_get(msg, "(s)", &property);
1712 ret_if(property == NULL);
1714 if (strcasecmp(property, "GattConnected") == 0) {
1715 gboolean connected = FALSE;
1717 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1719 _bt_convert_device_path_to_address(path, address);
1720 g_variant_get(msg, "(b)", &connected);
1722 event = connected ? BLUETOOTH_EVENT_GATT_CONNECTED :
1723 BLUETOOTH_EVENT_GATT_DISCONNECTED;
1724 param = g_variant_new("(is)", result, address);
1725 _bt_send_event(BT_DEVICE_EVENT,
1729 } else if (strcasecmp(property, "Paired") == 0) {
1730 gboolean paired = FALSE;
1731 bt_remote_dev_info_t *remote_dev_info;
1732 g_variant_get(msg, "(b)", &paired);
1734 ret_if(paired == FALSE);
1736 /* BlueZ sends paired signal for each paired device */
1737 /* during activation, We should ignore this, otherwise*/
1738 /* application thinks that a new device got paired */
1739 if (_bt_adapter_get_status() != BT_ACTIVATED) {
1740 BT_DBG("BT is not activated, so ignore this");
1744 if (_bt_is_device_creating() == TRUE) {
1745 BT_DBG("Try to Pair by me");
1749 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1751 _bt_convert_device_path_to_address(path, address);
1753 remote_dev_info = _bt_get_remote_device_info_by_object_path(path);
1754 if (remote_dev_info == NULL) {
1758 GVariant *uuids = NULL;
1759 GVariantBuilder *builder = NULL;
1761 builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
1762 for (i = 0; i < remote_dev_info->uuid_count; i++) {
1763 g_variant_builder_add(builder, "s",
1764 remote_dev_info->uuids[i]);
1766 uuids = g_variant_new("as", builder);
1767 g_variant_builder_unref(builder);
1768 GVariant *manufacturer_data = NULL;
1769 manufacturer_data = g_variant_new_from_data(
1770 G_VARIANT_TYPE_BYTESTRING,
1771 remote_dev_info->manufacturer_data,
1772 remote_dev_info->manufacturer_data_len,
1774 param = g_variant_new("(isunsbub@asn@ay)", result,
1776 remote_dev_info->class,
1777 remote_dev_info->rssi,
1778 remote_dev_info->name,
1779 remote_dev_info->paired,
1780 remote_dev_info->connected,
1781 remote_dev_info->trust,
1783 remote_dev_info->manufacturer_data_len,
1785 _bt_send_event(BT_ADAPTER_EVENT,
1786 BLUETOOTH_EVENT_BONDING_FINISHED,
1788 _bt_free_device_info(remote_dev_info);
1791 } else if (strcasecmp(property, "UUIDs") == 0) {
1792 /* Once we get the updated uuid information after
1793 * reverse service search, update it to application */
1795 bt_remote_dev_info_t *remote_dev_info;
1797 ret_if(_bt_is_device_creating() == TRUE);
1799 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1801 _bt_convert_device_path_to_address(path, address);
1803 remote_dev_info = _bt_get_remote_device_info_by_object_path(path);
1804 if (remote_dev_info == NULL) {
1809 BT_DBG("UUID's count = %d", remote_dev_info->uuid_count);
1810 if (remote_dev_info->paired && remote_dev_info->uuid_count) {
1811 GVariant *uuids = NULL;
1812 GVariantBuilder *builder = NULL;
1814 builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
1815 for (i = 0; i < remote_dev_info->uuid_count; i++) {
1816 g_variant_builder_add(builder, "s",
1817 remote_dev_info->uuids[i]);
1819 uuids = g_variant_new("as", builder);
1820 g_variant_builder_unref(builder);
1821 GVariant *manufacture_data = g_variant_new_from_data((const GVariantType *)"ay",
1822 remote_dev_info->manufacturer_data, remote_dev_info->manufacturer_data_len,
1825 param = g_variant_new("(isunsbub@asn@ay)", result,
1826 address, remote_dev_info->class,
1827 remote_dev_info->rssi,
1828 remote_dev_info->name,
1829 remote_dev_info->paired,
1830 remote_dev_info->connected,
1831 remote_dev_info->trust,
1833 remote_dev_info->manufacturer_data_len,
1835 _bt_send_event(BT_ADAPTER_EVENT,
1836 BLUETOOTH_EVENT_SERVICE_SEARCHED,
1840 _bt_free_device_info(remote_dev_info);
1843 } else if (strcasecmp(member, "DeviceConnected") == 0) {
1844 unsigned char addr_type = 0;
1846 g_variant_get(msg, "(y)", &addr_type);
1848 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1850 _bt_convert_device_path_to_address(path, address);
1851 dev_name = _bt_get_device_name(address);
1853 _bt_convert_addr_string_to_secure_string(secure_address, address);
1854 BT_INFO("Address : %s Type : %d", secure_address, addr_type);
1855 BT_ERR_C("### Connected [%s] [%s]", !addr_type ? "BREDR" : "LE",
1856 !addr_type ? dev_name : secure_address);
1860 _bt_add_le_connected_dev_info(address);
1862 _bt_logging_connection(TRUE, addr_type);
1863 param = g_variant_new("(isy)", result, address, addr_type);
1864 /*Send event to application*/
1865 _bt_send_event(BT_DEVICE_EVENT,
1866 BLUETOOTH_EVENT_DEVICE_CONNECTED,
1869 } else if (strcasecmp(member, "Disconnected") == 0) {
1870 unsigned char disc_reason = 0;
1871 unsigned char addr_type = 0;
1872 char *dev_name = NULL;
1873 gboolean sending = FALSE;
1875 g_variant_get(msg, "(yys)", &addr_type, &disc_reason, &dev_name);
1877 result = disc_reason;
1879 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1881 _bt_convert_device_path_to_address(path, address);
1883 /* 0x00 BDADDR_BRDER
1884 0x01 BDADDR_LE_PUBLIC
1885 0x02 BDADDR_LE_RANDOM */
1886 _bt_convert_addr_string_to_secure_string(secure_address, address);
1887 BT_INFO("Address : %s Type : %d", secure_address, addr_type);
1888 BT_ERR_C("### Disconnected [%s] [%s] [%d : %s]", !addr_type ? "BREDR" : "LE",
1889 !addr_type ? dev_name : secure_address,
1890 disc_reason, _bt_convert_disc_reason_to_string(disc_reason));
1893 _bt_headset_set_local_connection(FALSE);
1894 _bt_logging_connection(FALSE, addr_type);
1897 _bt_remove_le_connected_dev_info(address);
1899 #ifdef TIZEN_BT_A2DP_SINK_AUTO_CONNECT
1901 int bt_device_state = VCONFKEY_BT_DEVICE_NONE;
1903 if (vconf_get_int(VCONFKEY_BT_DEVICE, &bt_device_state) != 0)
1904 BT_ERR("vconf_get_int failed");
1906 BT_INFO("conn_state[0x%x], adapter_state [%d]",
1907 bt_device_state, _bt_adapter_get_status());
1909 if (disc_reason == BLUETOOTH_ERROR_CONNECTION_TIMEOUT) {
1910 _bt_audio_start_auto_connect(TRUE);
1911 } else if (bt_device_state &
1912 VCONFKEY_BT_DEVICE_A2DP_SOURCE_CONNECTED) {
1913 BT_INFO("Disconnected due to turning BT off. Skip a address");
1915 char *last_connected = NULL;
1916 last_connected = vconf_get_str(BT_LAST_CONNECTED_DEVICE);
1917 if (!g_strcmp0(address, last_connected))
1918 _bt_audio_set_auto_connect_device_addr("");
1920 free(last_connected);
1925 /*Check for any OPP transfer on the device and cancel
1928 _bt_obex_check_pending_transfer(address);
1929 _bt_opp_client_is_sending(&sending);
1930 if (sending == TRUE)
1931 _bt_opp_client_check_pending_transfer(address);
1933 param = g_variant_new("(isy)", result, address, addr_type);
1934 _bt_send_event(BT_DEVICE_EVENT,
1935 BLUETOOTH_EVENT_DEVICE_DISCONNECTED,
1938 } else if (strcasecmp(member, "ProfileStateChanged") == 0) {
1940 char *profile_uuid = NULL;
1941 bt_headset_wait_t *wait_list;
1942 bluetooth_device_address_t bd_addr;
1944 g_variant_get(msg, "(si)", &profile_uuid, &state);
1946 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1948 _bt_convert_device_path_to_address(path, address);
1949 _bt_convert_addr_string_to_type(bd_addr.addr, address);
1951 _bt_convert_addr_string_to_secure_string(secure_address, address);
1952 BT_INFO_C("[%s] state: %s, addr: %s",
1953 _bt_convert_uuid_to_string(profile_uuid),
1954 _bt_convert_profile_state_to_string(state), secure_address);
1956 if (strcmp(profile_uuid, A2DP_SINK_UUID) == 0) {
1957 if (state == BT_PROFILE_STATE_CONNECTED) {
1959 int event = BLUETOOTH_EVENT_AV_CONNECTED;
1960 char connected_address[BT_ADDRESS_STRING_SIZE + 1];
1961 bluetooth_device_address_t device_address;
1963 bt_headset_wait_t *wait_list;
1964 guint restricted = 0x0;
1966 __bt_set_device_values(TRUE,
1967 VCONFKEY_BT_DEVICE_A2DP_HEADSET_CONNECTED);
1969 __bt_connection_manager_set_state(address, event);
1971 _bt_get_restrict_profile(&bd_addr, RESTRICTED_PROFILE_HFP_HS, &restricted);
1973 if (_bt_headset_get_local_connection() == FALSE) {
1974 if (restricted == 0x0) /* not restricted*/
1975 _bt_start_timer_for_connection(address, BT_AUDIO_HSP);
1977 /* Connection Started from local device therefore no need to
1978 * intiate connection for pending profile */
1979 _bt_headset_set_local_connection(FALSE);
1981 param = g_variant_new("(is)", result, address);
1982 _bt_send_event(BT_HEADSET_EVENT, event,
1984 connected = _bt_is_headset_type_connected(BT_AUDIO_A2DP,
1987 if (g_strcmp0(connected_address, address) != 0) {
1988 _bt_convert_addr_string_to_type(
1989 device_address.addr,
1991 _bt_audio_disconnect(0, BT_AUDIO_A2DP,
1992 &device_address, NULL);
1996 _bt_add_headset_to_list(BT_AUDIO_A2DP,
1997 BT_STATE_CONNECTED, address);
1999 wait_list = _bt_get_audio_wait_data();
2000 if (wait_list != NULL &&
2001 (g_strcmp0(wait_list->address, address) == 0))
2002 _bt_rel_wait_data();
2004 } else if (state == BT_PROFILE_STATE_DISCONNECTED) {
2006 int event = BLUETOOTH_EVENT_AV_DISCONNECTED;
2008 if (!_bt_is_service_connected(address, BT_AUDIO_A2DP)) {
2010 g_free(profile_uuid);
2014 __bt_set_device_values(FALSE,
2015 VCONFKEY_BT_DEVICE_A2DP_HEADSET_CONNECTED);
2017 __bt_connection_manager_set_state(address, event);
2018 param = g_variant_new("(is)", result, address);
2019 _bt_send_event(BT_HEADSET_EVENT, event,
2021 /* Remove data from the connected list */
2022 _bt_remove_headset_from_list(BT_AUDIO_A2DP, address);
2023 wait_list = _bt_get_audio_wait_data();
2025 if (wait_list == NULL) {
2027 g_free(profile_uuid);
2031 if (((wait_list->type == BT_AUDIO_ALL) &&
2032 (wait_list->ag_flag == TRUE)) ||
2033 (wait_list->type == BT_AUDIO_A2DP) ||
2034 (wait_list->disconnection_type == BT_AUDIO_A2DP)) {
2035 bluetooth_device_address_t device_address;
2036 _bt_convert_addr_string_to_type(
2037 device_address.addr,
2038 wait_list->address);
2040 _bt_audio_connect(wait_list->req_id,
2046 } else if (strcmp(profile_uuid, AVRCP_TARGET_UUID) == 0) {
2048 if (state == BT_PROFILE_STATE_CONNECTED) {
2049 int event = BLUETOOTH_EVENT_AVRCP_CONTROL_CONNECTED;
2050 char connected_address[BT_ADDRESS_STRING_SIZE + 1];
2051 bluetooth_device_address_t device_address;
2053 param = g_variant_new("(is)", result, address);
2054 _bt_send_event(BT_AVRCP_CONTROL_EVENT, event,
2056 connected = _bt_is_headset_type_connected(
2060 if (g_strcmp0(connected_address,
2062 _bt_convert_addr_string_to_type(
2063 device_address.addr,
2065 _bt_audio_disconnect(0,
2067 &device_address, NULL);
2070 BT_DBG("device Path: %s", path);
2071 _bt_add_headset_to_list(BT_AVRCP,
2072 BT_STATE_CONNECTED, address);
2073 } else if (state == BT_PROFILE_STATE_DISCONNECTED) {
2074 int event = BLUETOOTH_EVENT_AVRCP_CONTROL_DISCONNECTED;
2075 param = g_variant_new("(is)", result, address);
2076 _bt_send_event(BT_AVRCP_CONTROL_EVENT, event,
2078 /* Remove data from the connected list */
2079 _bt_remove_headset_from_list(BT_AVRCP, address);
2081 } else if (strcasecmp(profile_uuid, A2DP_SOURCE_UUID) == 0) {
2082 if (state == BT_PROFILE_STATE_CONNECTED) {
2083 int event = BLUETOOTH_EVENT_AV_SOURCE_CONNECTED;
2084 BT_INFO("A2DP Source is connected");
2085 #ifdef TIZEN_BT_A2DP_SINK_ENABLE
2086 __bt_set_device_values(TRUE,
2087 VCONFKEY_BT_DEVICE_A2DP_SOURCE_CONNECTED);
2090 #ifdef TIZEN_BT_A2DP_SINK_AUTO_CONNECT
2091 _bt_audio_set_auto_connect_device_addr(address);
2092 _bt_audio_stop_auto_connect();
2094 _bt_add_headset_to_list(BT_AUDIO_A2DP_SOURCE,
2095 BT_STATE_CONNECTED, address);
2096 _bt_send_event(BT_A2DP_SOURCE_EVENT, event,
2097 g_variant_new("(is)", result, address));
2098 } else if (state == BT_PROFILE_STATE_DISCONNECTED) {
2099 int event = BLUETOOTH_EVENT_AV_SOURCE_DISCONNECTED;
2100 BT_INFO("A2DP Source Disconnected");
2101 #ifdef TIZEN_BT_A2DP_SINK_ENABLE
2102 __bt_set_device_values(FALSE,
2103 VCONFKEY_BT_DEVICE_A2DP_SOURCE_CONNECTED);
2105 _bt_remove_headset_from_list(BT_AUDIO_A2DP_SOURCE, address);
2106 _bt_send_event(BT_A2DP_SOURCE_EVENT, event,
2107 g_variant_new("(is)", result, address));
2109 wait_list = _bt_get_audio_wait_data();
2110 if (wait_list && wait_list->type == BT_AUDIO_A2DP_SOURCE) {
2111 bluetooth_device_address_t device_address;
2112 _bt_convert_addr_string_to_type(
2113 device_address.addr,
2114 wait_list->address);
2116 _bt_audio_connect(wait_list->req_id,
2120 /* Now free the wait list */
2121 _bt_rel_wait_data();
2124 } else if ((strcmp(profile_uuid, HID_UUID) == 0) &&
2125 ((state == BT_PROFILE_STATE_CONNECTED) ||
2126 (state == BT_PROFILE_STATE_DISCONNECTED))) {
2128 if (state == BT_PROFILE_STATE_CONNECTED)
2129 event = BLUETOOTH_HID_CONNECTED;
2131 event = BLUETOOTH_HID_DISCONNECTED;
2132 param = g_variant_new("(is)", result, address);
2133 _bt_send_event(BT_HID_EVENT, event,
2135 } else if (strcmp(profile_uuid, HID_DEVICE_UUID) == 0) {
2136 if (state == BT_PROFILE_STATE_CONNECTED) {
2138 event = BLUETOOTH_HID_DEVICE_CONNECTED;
2139 param = g_variant_new("(is)", result, address);
2140 _bt_send_event(BT_HID_DEVICE_EVENT, event,
2142 } else if (state == BT_PROFILE_STATE_DISCONNECTED) {
2143 event = BLUETOOTH_HID_DEVICE_DISCONNECTED;
2144 param = g_variant_new("(is)", result, address);
2145 _bt_send_event(BT_HID_DEVICE_EVENT, event,
2150 g_free(profile_uuid);
2151 } else if (strcasecmp(member, "AdvReport") == 0) {
2153 bt_remote_le_dev_info_t *le_dev_info = NULL;
2154 char *buffer = NULL;
2156 bt_le_adv_info_t *adv_info = NULL;
2157 GVariant *value = NULL;
2158 ret_if(_bt_is_le_scanning() == FALSE);
2160 le_dev_info = g_malloc0(sizeof(bt_remote_le_dev_info_t));
2162 g_variant_get(msg, "(&syyii@ay)", &le_dev_info->address,
2163 &le_dev_info->addr_type,
2164 &le_dev_info->adv_type,
2166 &le_dev_info->adv_data_len,
2168 if (value == NULL) {
2169 _bt_free_le_device_info(le_dev_info);
2173 _bt_convert_device_path_to_address(path, le_dev_info->address);
2175 buffer_len = g_variant_get_size(value);
2177 buffer = (char *)g_variant_get_data(value);
2179 le_dev_info->adv_data = g_memdup(buffer, buffer_len);
2180 if (le_dev_info->adv_data == NULL &&
2181 le_dev_info->adv_type != BT_LE_ADV_SCAN_RSP) {
2182 _bt_free_le_device_info(le_dev_info);
2183 g_variant_unref(value);
2187 if (_bt_get_le_scan_type() == BT_LE_PASSIVE_SCAN) {
2188 _bt_send_scan_result_event(le_dev_info, NULL);
2189 _bt_free_le_device_info(le_dev_info);
2190 g_variant_unref(value);
2194 if (le_dev_info->adv_type != BT_LE_ADV_SCAN_RSP) { /* ADV_IND */
2195 adv_info = g_malloc0(sizeof(bt_le_adv_info_t));
2196 adv_info->addr = g_strdup(le_dev_info->address);
2197 adv_info->addr_type = le_dev_info->addr_type;
2198 adv_info->rssi = le_dev_info->rssi;
2199 adv_info->data_len = le_dev_info->adv_data_len;
2200 adv_info->data = g_malloc0(le_dev_info->adv_data_len);
2201 memcpy(adv_info->data, le_dev_info->adv_data,
2202 le_dev_info->adv_data_len);
2204 if (__bt_add_adv_ind_info(adv_info) == 0) {
2205 adv_info->timer_id = g_timeout_add(1000,
2206 (GSourceFunc)__bt_adv_scan_req_timeout_cb, (void*)adv_info);
2208 } else { /* SCAN_RSP */
2209 adv_info = __bt_get_adv_ind_info(le_dev_info->address);
2211 _bt_send_scan_result_event(le_dev_info, adv_info);
2212 __bt_del_adv_ind_info(le_dev_info->address);
2215 _bt_free_le_device_info(le_dev_info);
2216 g_variant_unref(value);
2217 } else if (strcasecmp(member, "LEDataLengthChanged") == 0) {
2218 guint16 tx_octets = 0;
2219 guint16 tx_time = 0;
2220 guint16 rx_octets = 0;
2221 guint16 rx_time = 0;
2223 g_variant_get(msg, "(qqqq)",
2224 &tx_octets, &tx_time, &rx_octets, &rx_time);
2226 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
2227 _bt_convert_device_path_to_address(path, address);
2229 param = g_variant_new("(isqqqq)", result, address, tx_octets, tx_time,
2230 rx_octets, rx_time);
2231 /* Send event to application */
2232 _bt_send_event(BT_DEVICE_EVENT,
2233 BLUETOOTH_EVENT_LE_DATA_LENGTH_CHANGED, param);
2235 } else if (strcasecmp(member, "IpspStateChanged") == 0) {
2236 gboolean connected = FALSE;
2237 char *ifname = NULL;
2239 g_variant_get(msg, "(bs)", &connected, &ifname);
2241 event = connected ? BLUETOOTH_EVENT_IPSP_CONNECTED :
2242 BLUETOOTH_EVENT_IPSP_DISCONNECTED;
2244 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
2245 _bt_convert_device_path_to_address(path, address);
2247 BT_DBG("Ipsp BT Interface Name: %s", ifname);
2248 BT_DBG("address: %s", address);
2249 param = g_variant_new("(iss)", result, address, ifname);
2251 /* Send event to application */
2252 _bt_send_event(BT_DEVICE_EVENT,
2256 } else if (strcasecmp(member, "iBeaconReport") == 0) {
2257 bt_remote_ibeacon_dev_info_t *ibeacon_dev_info = NULL;
2259 ret_if(_bt_is_le_scanning() == FALSE);
2261 ibeacon_dev_info = g_malloc0(sizeof(bt_remote_ibeacon_dev_info_t));
2263 g_variant_get(msg, "(syuusuuy)", &ibeacon_dev_info->address,
2264 &ibeacon_dev_info->addr_type,
2265 &ibeacon_dev_info->company_id,
2266 &ibeacon_dev_info->ibeacon_type,
2267 &ibeacon_dev_info->uuid,
2268 &ibeacon_dev_info->major_id,
2269 &ibeacon_dev_info->minor_id,
2270 &ibeacon_dev_info->measured_power);
2271 _bt_send_ibeacon_scan_result_event(ibeacon_dev_info);
2272 g_free(ibeacon_dev_info);
2276 void __bt_set_audio_values(gboolean connected, char *address)
2279 int bt_device_state = VCONFKEY_BT_DEVICE_NONE;
2281 /* Set the headset name */
2282 if (connected == TRUE)
2283 name = _bt_get_device_name(address);
2285 name = g_strdup("");
2287 if (vconf_set_str(VCONFKEY_BT_HEADSET_NAME, name) != 0)
2288 BT_ERR("vconf_set_str failed");
2292 /* Set the headset state */
2293 if (vconf_get_int(VCONFKEY_BT_DEVICE, &bt_device_state) != 0)
2294 BT_ERR("vconf_get_int failed");
2296 #ifdef TIZEN_SUPPORT_DUAL_HF
2297 if ((connected == TRUE) &&
2298 (FALSE == __bt_is_companion_device(address))) {
2299 bt_device_state |= VCONFKEY_BT_DEVICE_HEADSET_CONNECTED;
2300 } else if ((bt_device_state & VCONFKEY_BT_DEVICE_HEADSET_CONNECTED) &&
2301 (FALSE == __bt_is_companion_device(address))) {
2302 bt_device_state ^= VCONFKEY_BT_DEVICE_HEADSET_CONNECTED;
2305 if (connected == TRUE)
2306 bt_device_state |= VCONFKEY_BT_DEVICE_HEADSET_CONNECTED;
2307 else if (bt_device_state & VCONFKEY_BT_DEVICE_HEADSET_CONNECTED)
2308 bt_device_state ^= VCONFKEY_BT_DEVICE_HEADSET_CONNECTED;
2311 if (vconf_set_int(VCONFKEY_BT_DEVICE,
2312 bt_device_state) != 0) {
2313 BT_ERR("vconf_set_int failed");
2317 void _bt_handle_headset_event(GVariant *msg, const char *path)
2319 int result = BLUETOOTH_ERROR_NONE;
2320 gboolean property_flag = FALSE;
2321 char *property = NULL;
2322 GVariant *value = NULL;
2323 GVariant *param = NULL;
2324 g_variant_get(msg, "(sv)", &property, &value);
2325 bluetooth_device_address_t bd_addr;
2327 ret_if(property == NULL);
2329 BT_DBG("Property = %s \n", property);
2330 /* We allow only 1 headset connection (HSP or HFP)*/
2331 if (strcasecmp(property, "Connected") == 0) {
2332 int event = BLUETOOTH_EVENT_NONE;
2333 bt_headset_wait_t *wait_list;
2335 guint restricted = 0x0;
2336 g_variant_get(value, "b", &property_flag);
2338 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
2340 _bt_convert_device_path_to_address(path, address);
2341 _bt_convert_addr_string_to_type(bd_addr.addr, address);
2343 if (property_flag == TRUE) {
2344 event = BLUETOOTH_EVENT_AG_CONNECTED;
2345 _bt_get_restrict_profile(&bd_addr, RESTRICTED_PROFILE_A2DP, &restricted);
2347 if (_bt_headset_get_local_connection() == FALSE) {
2348 if (restricted == 0x0) /* not restricted*/
2349 _bt_start_timer_for_connection(address, BT_AUDIO_A2DP);
2351 _bt_headset_set_local_connection(FALSE);
2355 event = BLUETOOTH_EVENT_AG_DISCONNECTED;
2357 previous_state = _bt_get_device_state_from_list(BT_AUDIO_HSP, address);
2358 if (previous_state == BT_STATE_DISCONNECTING)
2359 _bt_send_hf_local_term_event(address);
2361 /* Set the State machine here */
2362 __bt_connection_manager_set_state(address, event);
2363 __bt_set_audio_values(property_flag, address);
2364 param = g_variant_new("(is)", result, address);
2365 _bt_send_event(BT_HEADSET_EVENT, event,
2368 if (event == BLUETOOTH_EVENT_AG_DISCONNECTED) {
2369 /* Remove data from the connected list */
2370 _bt_remove_headset_from_list(BT_AUDIO_HSP, address);
2372 wait_list = _bt_get_audio_wait_data();
2373 if (wait_list == NULL) {
2378 bluetooth_device_address_t device_address;
2380 _bt_set_audio_wait_data_flag(TRUE);
2382 _bt_convert_addr_string_to_type(device_address.addr,
2383 wait_list->address);
2384 _bt_audio_connect(wait_list->req_id, wait_list->type,
2385 &device_address, NULL);
2386 _bt_rel_wait_data();
2387 } else if (event == BLUETOOTH_EVENT_AG_CONNECTED) {
2388 /* Add data to the connected list */
2389 _bt_add_headset_to_list(BT_AUDIO_HSP,
2390 BT_STATE_CONNECTED, address);
2392 wait_list = _bt_get_audio_wait_data();
2393 if (wait_list != NULL &&
2394 (g_strcmp0(wait_list->address, address) == 0))
2395 _bt_rel_wait_data();
2397 BT_INFO("Check A2DP pending connect");
2398 _bt_audio_check_pending_connect();
2401 } else if (strcasecmp(property, "State") == 0) {
2404 g_variant_get(value, "s", &state);
2406 /* This code assumes we support only 1 headset connection */
2407 /* Need to use the headset list, if we support multi-headsets */
2408 if (strcasecmp(state, "Playing") == 0) {
2409 BT_DBG("Playing: Sco Connected");
2410 } else if (strcasecmp(state, "connected") == 0 ||
2411 strcasecmp(state, "disconnected") == 0) {
2412 BT_DBG("connected/disconnected: Sco Disconnected");
2414 BT_ERR("Not handled state - %s", state);
2419 } else if (strcasecmp(property, "SpeakerGain") == 0) {
2423 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
2425 _bt_convert_device_path_to_address(path, address);
2427 spkr_gain = g_variant_get_uint16(value);
2429 BT_DBG("spkr_gain: %d", spkr_gain);
2431 param = g_variant_new("(i&sq)", result, address, spkr_gain);
2432 _bt_send_event(BT_HEADSET_EVENT, BLUETOOTH_EVENT_AG_SPEAKER_GAIN,
2436 } else if (strcasecmp(property, "MicrophoneGain") == 0) {
2440 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
2442 _bt_convert_device_path_to_address(path, address);
2444 mic_gain = g_variant_get_uint16(value);
2446 param = g_variant_new("(i&sq)", result, address, mic_gain);
2447 _bt_send_event(BT_HEADSET_EVENT, BLUETOOTH_EVENT_AG_MIC_GAIN,
2454 g_variant_unref(value);
2457 void _bt_handle_sink_event(GVariant *msg, const char *path)
2459 GVariantIter value_iter;
2460 char *property = NULL;
2462 bt_headset_wait_t *wait_list;
2464 GVariant *child = NULL;
2465 GVariant *val = NULL;
2466 GVariant *param = NULL;
2467 g_variant_iter_init(&value_iter, msg);
2468 while ((child = g_variant_iter_next_value(&value_iter))) {
2470 g_variant_get(child, "{sv}", &property, &val);
2472 ret_if(property == NULL);
2474 BT_DBG("Property = %s \n", property);
2477 if (strcasecmp(property, "State") == 0) {
2478 int result = BLUETOOTH_ERROR_NONE;
2481 g_variant_get(val, "s", &value);
2482 BT_DBG("value: %s", value);
2484 if (g_strcmp0(value, "disconnected") == 0) {
2487 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
2489 _bt_convert_device_path_to_address(path, address);
2491 __bt_set_device_values(FALSE,
2492 VCONFKEY_BT_DEVICE_A2DP_HEADSET_CONNECTED);
2493 param = g_variant_new("(is)", result, address);
2494 _bt_send_event(BT_HEADSET_EVENT,
2495 BLUETOOTH_EVENT_AV_DISCONNECTED,
2498 /* Remove data from the connected list */
2499 _bt_remove_headset_from_list(BT_AUDIO_A2DP, address);
2500 wait_list = _bt_get_audio_wait_data();
2501 if (wait_list == NULL) {
2504 g_variant_unref(val);
2505 g_variant_unref(child);
2510 if (((wait_list->type == BT_AUDIO_ALL) &&
2511 (wait_list->ag_flag == TRUE)) ||
2512 (wait_list->type == BT_AUDIO_A2DP) ||
2513 (wait_list->disconnection_type == BT_AUDIO_A2DP)) {
2514 bluetooth_device_address_t device_address;
2515 _bt_convert_addr_string_to_type(
2516 device_address.addr,
2517 wait_list->address);
2519 _bt_audio_connect(wait_list->req_id,
2525 } else if (strcasecmp(value, "Connected") == 0) {
2527 char connected_address[BT_ADDRESS_STRING_SIZE + 1];
2528 bluetooth_device_address_t device_address;
2531 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
2533 _bt_convert_device_path_to_address(path, address);
2535 __bt_set_device_values(TRUE,
2536 VCONFKEY_BT_DEVICE_A2DP_HEADSET_CONNECTED);
2537 param = g_variant_new("(is)", result, address);
2538 _bt_send_event(BT_HEADSET_EVENT,
2539 BLUETOOTH_EVENT_AV_CONNECTED,
2541 /* Check for existing Media device to disconnect */
2542 connected = _bt_is_headset_type_connected(BT_AUDIO_A2DP,
2545 /* Match connected device address */
2546 if (g_strcmp0(connected_address, address) != 0) {
2547 /* Convert BD address from string type */
2548 _bt_convert_addr_string_to_type(
2549 device_address.addr,
2551 _bt_audio_disconnect(0, BT_AUDIO_A2DP,
2552 &device_address, NULL);
2556 /* Add data to the connected list */
2557 _bt_add_headset_to_list(BT_AUDIO_A2DP,
2558 BT_STATE_CONNECTED, address);
2565 g_variant_unref(val);
2566 g_variant_unref(child);
2570 void _bt_handle_agent_event(GVariant *msg, const char *member)
2572 int result = BLUETOOTH_ERROR_NONE;
2573 char *address = NULL;
2576 GVariant *param = NULL;
2577 ret_if(member == NULL);
2579 if (strcasecmp(member, "ObexAuthorize") == 0) {
2580 __bt_get_agent_signal_info(msg, &address, &name, &uuid);
2581 param = g_variant_new("(iss)", result, address, name);
2582 _bt_send_event(BT_OPP_SERVER_EVENT,
2583 BLUETOOTH_EVENT_OBEX_SERVER_CONNECTION_AUTHORIZE,
2587 } else if (strcasecmp(member, "RfcommAuthorize") == 0) {
2588 bt_rfcomm_server_info_t *server_info;
2590 __bt_get_agent_signal_info(msg, &address, &name, &uuid);
2592 server_info = _bt_rfcomm_get_server_info_using_uuid(uuid);
2593 ret_if(server_info == NULL);
2594 ret_if(server_info->server_type != BT_CUSTOM_SERVER);
2595 param = g_variant_new("(isssn)", result, address, uuid, name,
2596 server_info->control_fd);
2597 _bt_send_event(BT_RFCOMM_SERVER_EVENT,
2598 BLUETOOTH_EVENT_RFCOMM_AUTHORIZE,
2606 static int __bt_get_object_path(GVariant *msg, char **path)
2608 g_variant_get(msg, "(o*)", path, NULL);
2610 return BLUETOOTH_ERROR_INTERNAL;
2612 return BLUETOOTH_ERROR_NONE;
2615 static void __bt_devices_list_free(void)
2617 bt_cache_info_t *cache_info;
2620 node = g_list_first(p_cache_list);
2622 while (node != NULL) {
2623 cache_info = (bt_cache_info_t *)node->data;
2624 p_cache_list = g_list_remove(p_cache_list, cache_info);
2625 __bt_free_cache_info(cache_info);
2627 node = g_list_next(node);
2631 static int __bt_parse_event(GVariant *msg)
2635 char *interface_name = NULL;
2636 GVariant *inner_iter = NULL;
2638 g_variant_iter_init(&iter, msg);
2640 while ((child = g_variant_iter_next_value(&iter))) {
2641 g_variant_get(child, "{&s@a{sv}}", &interface_name, &inner_iter);
2642 if (g_strcmp0(interface_name,
2643 BT_DEVICE_INTERFACE) == 0) {
2644 g_variant_unref(inner_iter);
2645 g_variant_unref(child);
2646 return BT_DEVICE_EVENT;
2647 } else if (g_strcmp0(interface_name,
2648 BT_MEDIATRANSPORT_INTERFACE) == 0) {
2649 g_variant_unref(inner_iter);
2650 g_variant_unref(child);
2651 return BT_MEDIA_TRANSFER_EVENT;
2652 } else if (g_strcmp0(interface_name,
2653 BT_PLAYER_CONTROL_INTERFACE) == 0) {
2654 g_variant_unref(inner_iter);
2655 g_variant_unref(child);
2656 return BT_AVRCP_CONTROL_EVENT;
2658 g_variant_unref(inner_iter);
2659 g_variant_unref(child);
2665 static void __bt_manager_event_filter(GDBusConnection *connection,
2666 const gchar *sender_name,
2667 const gchar *object_path,
2668 const gchar *interface_name,
2669 const gchar *signal_name,
2670 GVariant *parameters,
2673 bt_event_type_t bt_event = 0x00;
2674 int result = BLUETOOTH_ERROR_NONE;
2676 char *obj_path = NULL;
2677 GVariant *param = NULL;
2678 if (signal_name == NULL)
2680 if (strcasecmp(signal_name, "InterfacesAdded") == 0) {
2681 g_variant_get(parameters, "(&o@a{sa{sv}})", &obj_path, &value);
2683 if (strcasecmp(obj_path, BT_BLUEZ_HCI_PATH) == 0) {
2684 #ifdef USB_BLUETOOTH
2685 BT_DBG("Enable Adapter");
2686 _bt_enable_adapter();
2688 _bt_handle_adapter_added();
2691 bt_event = __bt_parse_event(value);
2692 if (bt_event == BT_DEVICE_EVENT) {
2693 bt_cache_info_t *cache_info;
2694 bt_remote_dev_info_t *dev_info;
2696 if (_bt_is_discovering() == FALSE &&
2697 _bt_is_le_scanning() == FALSE) {
2698 g_variant_unref(value);
2702 cache_info = g_malloc0(sizeof(bt_cache_info_t));
2704 dev_info = g_malloc0(sizeof(bt_remote_dev_info_t));
2706 cache_info->dev_info = dev_info;
2708 if (__bt_parse_interface(parameters, dev_info) == FALSE) {
2709 BT_ERR("Fail to parse the properies");
2710 __bt_free_cache_info(cache_info);
2711 g_variant_unref(value);
2715 if (dev_info->addr_type != BDADDR_BREDR) {
2716 /* Whenever emit the property changed from bluez,
2717 some property doesn't reach to bt-service.
2718 So LE device is handled as AdvReport signal */
2719 __bt_free_cache_info(cache_info);
2720 g_variant_unref(value);
2724 if (dev_info->name == NULL)
2725 /* If Remote device name is NULL or still RNR is not done
2726 * then display address as name.
2728 dev_info->name = g_strdup(dev_info->address);
2730 #ifdef TIZEN_DPM_ENABLE
2731 if (_bt_dpm_get_bluetooth_desktop_connectivity_state() ==
2733 bluetooth_device_class_t device_class;
2734 _bt_divide_device_class(&device_class, dev_info->class);
2735 BT_DBG("[%s]device_class.major_class : %d", dev_info->name, device_class.major_class);
2737 if (device_class.major_class ==
2738 BLUETOOTH_DEVICE_MAJOR_CLASS_COMPUTER) {
2739 __bt_free_cache_info(cache_info);
2740 g_variant_unref(value);
2746 GVariant *uuids = NULL;
2747 GVariantBuilder *builder = NULL;
2749 builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
2750 for (i = 0; i < dev_info->uuid_count; i++) {
2751 g_variant_builder_add(builder, "s",
2752 dev_info->uuids[i]);
2754 uuids = g_variant_new("as", builder);
2755 g_variant_builder_unref(builder);
2756 GVariant *manufacturer_data = NULL;
2757 manufacturer_data = g_variant_new_from_data(
2758 G_VARIANT_TYPE_BYTESTRING,
2759 dev_info->manufacturer_data,
2760 dev_info->manufacturer_data_len,
2762 param = g_variant_new("(isunsbub@asn@ay)", result,
2768 dev_info->connected,
2771 dev_info->manufacturer_data_len,
2773 _bt_send_event(BT_ADAPTER_EVENT,
2774 BLUETOOTH_EVENT_REMOTE_DEVICE_FOUND,
2776 p_cache_list = g_list_append(p_cache_list, cache_info);
2777 } else if (bt_event == BT_AVRCP_CONTROL_EVENT) {
2778 BT_DBG("Device path : %s ", obj_path);
2779 _bt_set_control_device_path(obj_path);
2782 g_variant_unref(value);
2783 } else if (strcasecmp(signal_name, "InterfacesRemoved") == 0) {
2784 #ifdef USB_BLUETOOTH
2785 BT_DBG("InterfacesRemoved");
2786 _bt_handle_adapter_removed();
2788 if (g_strcmp0(interface_name, BT_MEDIATRANSPORT_INTERFACE) == 0)
2789 bt_event = BT_MEDIA_TRANSFER_EVENT;
2790 else if (g_strcmp0(interface_name, BT_DEVICE_INTERFACE) == 0)
2791 bt_event = BT_DEVICE_EVENT;
2792 else if (g_strcmp0(interface_name, BT_PLAYER_CONTROL_INTERFACE) == 0)
2793 bt_event = BT_AVRCP_CONTROL_EVENT;
2795 if ((bt_event != 0) && (bt_event != BT_MEDIA_TRANSFER_EVENT)) {
2796 _bt_handle_adapter_event(parameters, signal_name);
2797 if (bt_event == BT_AVRCP_CONTROL_EVENT) {
2798 BT_INFO("Object Path %s", obj_path);
2799 _bt_remove_control_device_path(obj_path);
2802 } else if (strcasecmp(signal_name, "NameOwnerChanged") == 0) {
2805 char *previous = NULL;
2806 char *current = NULL;
2808 if (__bt_get_owner_info(parameters, &name, &previous, ¤t)) {
2809 BT_ERR("Fail to get the owner info");
2813 if (*current != '\0') {
2822 if (strcasecmp(name, BT_BLUEZ_NAME) == 0) {
2823 BT_INFO_C("### Bluetoothd is terminated");
2824 if (_bt_adapter_get_status() == BT_ACTIVATED)
2827 _bt_handle_adapter_removed();
2828 __bt_devices_list_free();
2829 _bt_service_adapter_le_deinit();
2832 _bt_obex_server_check_allocation(&value);
2834 if (value == TRUE) {
2835 /* Check if the obex server was terminated abnormally */
2836 _bt_obex_server_check_termination(name);
2839 _bt_rfcomm_server_check_existence(&value);
2841 if (value == TRUE) {
2842 /* The obex server was terminated abnormally */
2843 _bt_rfcomm_server_check_termination(name);
2846 /* Reset connection interval */
2847 _bt_remove_all_le_conn_param_info(name);
2849 /* Stop advertising started by terminated process */
2850 _bt_stop_advertising_by_terminated_process(name);
2853 _bt_stop_le_scan(name);
2858 } else if (g_strcmp0(interface_name, BT_PROPERTIES_INTERFACE) == 0) {
2859 const char *path = object_path;
2861 if (strncmp(path, BT_MEDIA_OBJECT_PATH,
2862 strlen(BT_MEDIA_OBJECT_PATH)) == 0)
2865 _bt_handle_property_changed_event(parameters, object_path);
2866 } else if (g_strcmp0(interface_name, BT_ADAPTER_INTERFACE) == 0) {
2867 _bt_handle_adapter_event(parameters, signal_name);
2868 } else if (g_strcmp0(interface_name, BT_INPUT_INTERFACE) == 0) {
2869 _bt_handle_input_event(parameters, object_path);
2870 } else if (g_strcmp0(interface_name, BT_NETWORK_SERVER_INTERFACE) == 0) {
2871 _bt_handle_network_server_event(parameters, signal_name);
2872 } else if (g_strcmp0(interface_name, BT_HEADSET_INTERFACE) == 0) {
2873 _bt_handle_headset_event(parameters, object_path);
2874 } else if (g_strcmp0(interface_name, BT_SINK_INTERFACE) == 0) {
2875 _bt_handle_sink_event(parameters, object_path);
2876 } else if (g_strcmp0(interface_name, BT_AGENT_INTERFACE) == 0) {
2877 _bt_handle_agent_event(parameters, signal_name);
2878 } else if (g_strcmp0(interface_name, BT_DEVICE_INTERFACE) == 0) {
2879 _bt_handle_device_event(parameters, signal_name, object_path);
2880 } else if (g_strcmp0(interface_name, BT_GATT_CHAR_INTERFACE) == 0) {
2881 _bt_handle_gatt_event(parameters, signal_name, object_path);
2887 static gboolean __bt_is_obexd_event(GVariant *msg, const char *interface)
2890 if (g_strcmp0(interface, BT_PROPERTIES_INTERFACE) == 0) {
2891 char *interface_name = NULL;
2893 g_variant_get(msg, "(&s@a{sv}@as)", &interface_name, NULL, NULL);
2894 retv_if(interface_name == NULL, FALSE);
2896 if (strcasecmp(interface_name, BT_OBEX_TRANSFER_INTERFACE) == 0) {
2897 BT_DBG("BT_OBEX_TRANSFER_INTERFACE");
2905 static void __bt_obexd_event_filter(GDBusConnection *connection,
2906 const gchar *sender_name,
2907 const gchar *object_path,
2908 const gchar *interface_name,
2909 const gchar *signal_name,
2910 GVariant *parameters,
2913 const char *member = signal_name;
2914 char *obj_path = NULL;
2915 ret_if(member == NULL);
2917 if (strcasecmp(member, "InterfacesAdded") == 0) {
2918 if (__bt_get_object_path(parameters, &obj_path)) {
2919 BT_ERR("Fail to get the path");
2922 BT_INFO("object_path = [%s]", obj_path);
2924 /*Handle OPP_SERVER_CONNECTED_EVENT here */
2925 if (strncmp(obj_path, BT_SESSION_BASEPATH_SERVER,
2926 strlen(BT_SESSION_BASEPATH_SERVER)) != 0) {
2931 if (g_strrstr(obj_path, "session") && g_strrstr(obj_path, "transfer")) {
2932 BT_DBG("Obex_Server_Session_Transfer connected");
2933 _bt_obex_transfer_connected(obj_path);
2936 } else if (strcasecmp(member, "InterfacesRemoved") == 0) {
2937 /*Handle OPP_SERVER_DISCONNECTED_EVENT here */
2938 if (__bt_get_object_path(parameters, &obj_path)) {
2939 BT_ERR("Fail to get the path");
2942 BT_INFO("object_path = [%s]", obj_path);
2944 if (strncmp(obj_path, BT_SESSION_BASEPATH_CLIENT,
2945 strlen(BT_SESSION_BASEPATH_CLIENT)) == 0) {
2946 BT_DBG("Call PBAP Disconnected");
2947 _bt_obex_pbap_client_disconnect(obj_path);
2950 if (strncmp(obj_path, BT_SESSION_BASEPATH_SERVER,
2951 strlen(BT_SESSION_BASEPATH_SERVER)) != 0) {
2956 if (g_strrstr(obj_path, "session") && g_strrstr(obj_path, "transfer")) {
2957 BT_DBG("Obex_Server_Session_Transfer disconnected %s",
2960 _bt_obex_transfer_disconnected(obj_path);
2963 } else if (__bt_is_obexd_event(parameters, interface_name) == TRUE) {
2964 const char *path = object_path;
2966 if (strncmp(path, BT_SESSION_BASEPATH_SERVER,
2967 strlen(BT_SESSION_BASEPATH_SERVER)) != 0 &&
2968 strncmp(path, BT_SESSION_BASEPATH_CLIENT,
2969 strlen(BT_SESSION_BASEPATH_CLIENT)) != 0) {
2970 BT_DBG("DBUS_HANDLER_RESULT_NOT_YET_HANDLED");
2974 _bt_handle_property_changed_event(parameters, path);
2980 static gboolean __bt_is_obexd_client_event(GVariant *msg, const char *interface)
2984 if (g_strcmp0(interface, BT_PROPERTIES_INTERFACE) == 0) {
2985 char *interface_name = NULL;
2987 g_variant_get(msg, "(&s@a{sv}@as)", &interface_name, NULL, NULL);
2989 retv_if(interface_name == NULL, FALSE);
2991 if (strcasecmp(interface_name,
2992 BT_OBEX_TRANSFER_INTERFACE) == 0) {
3003 static void __bt_opc_event_filter(GDBusConnection *connection,
3004 const gchar *sender_name,
3005 const gchar *object_path,
3006 const gchar *interface_name,
3007 const gchar *signal_name,
3008 GVariant *parameters,
3011 const char *member = signal_name;
3012 char *obj_path = NULL;
3013 if (strcasecmp(member, "InterfacesAdded") == 0) {
3014 BT_DBG("InterfacesAdded");
3015 } else if (strcasecmp(member, "InterfacesRemoved") == 0) {
3017 if (__bt_get_object_path(parameters, &obj_path)) {
3018 BT_ERR("Fail to get the path");
3022 BT_DBG("object_path = %s", obj_path);
3024 if (strncmp(obj_path, BT_SESSION_BASEPATH_CLIENT,
3025 strlen(BT_SESSION_BASEPATH_CLIENT)) != 0
3026 || strstr(obj_path, "transfer") == NULL) {
3029 } else if (strncmp(obj_path, BT_SESSION_BASEPATH_CLIENT,
3030 strlen(BT_SESSION_BASEPATH_CLIENT)) == 0) {
3031 BT_DBG("Going to call opc disconnected");
3032 _bt_opc_disconnected(obj_path);
3035 _bt_sending_files();
3037 } else if (__bt_is_obexd_client_event(parameters, interface_name) == TRUE) {
3038 char *path = (char *)object_path;
3039 BT_INFO("object_path %s", path);
3040 if (strncmp(path, BT_SESSION_BASEPATH_CLIENT,
3041 strlen(BT_SESSION_BASEPATH_CLIENT)) != 0) {
3042 BT_DBG("NOT BT_SESSION_BASEPATH_CLIENT");
3046 _bt_opc_property_changed_event(parameters, path);
3052 int _bt_opp_client_event_init(void)
3054 GError *error = NULL;
3056 if (opc_obexd_conn == NULL) {
3057 opc_obexd_conn = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &error);
3059 if (!opc_obexd_conn) {
3061 BT_ERR("Unable to connect to dbus: %s", error->message);
3062 g_clear_error(&error);
3064 return BLUETOOTH_ERROR_INTERNAL;
3068 if (_bt_register_service_event(opc_obexd_conn,
3069 BT_OPP_CLIENT_EVENT) != BLUETOOTH_ERROR_NONE) {
3070 g_object_unref(opc_obexd_conn);
3071 opc_obexd_conn = NULL;
3072 return BLUETOOTH_ERROR_INTERNAL;
3075 return BLUETOOTH_ERROR_NONE;
3078 void _bt_opp_client_event_deinit(void)
3080 if (opc_obexd_conn) {
3081 _bt_unregister_service_event(opc_obexd_conn,
3082 BT_OPP_CLIENT_EVENT);
3083 g_object_unref(opc_obexd_conn);
3084 opc_obexd_conn = NULL;
3088 int _bt_register_manager_subscribe_signal(GDBusConnection *conn,
3094 static int subs_interface_added_id = -1;
3095 static int subs_interface_removed_id = -1;
3096 static int subs_name_owner_id = -1;
3097 static int subs_property_id = -1;
3098 static int subs_adapter_id = -1;
3099 static int subs_gatt_id = -1;
3102 if (subs_interface_added_id == -1) {
3103 subs_interface_added_id = g_dbus_connection_signal_subscribe(conn,
3104 NULL, BT_MANAGER_INTERFACE,
3105 BT_INTERFACES_ADDED, NULL, NULL, 0,
3106 __bt_manager_event_filter,
3109 if (subs_interface_removed_id == -1) {
3110 subs_interface_removed_id = g_dbus_connection_signal_subscribe(conn,
3111 NULL, BT_MANAGER_INTERFACE,
3112 BT_INTERFACES_REMOVED, NULL, NULL, 0,
3113 __bt_manager_event_filter,
3116 if (subs_name_owner_id == -1) {
3117 subs_name_owner_id = g_dbus_connection_signal_subscribe(conn,
3118 NULL, BT_FREEDESKTOP_INTERFACE,
3119 BT_NAME_OWNER_CHANGED, NULL, NULL, 0,
3120 __bt_manager_event_filter,
3123 if (subs_property_id == -1) {
3124 subs_property_id = g_dbus_connection_signal_subscribe(conn,
3125 NULL, BT_PROPERTIES_INTERFACE,
3126 BT_PROPERTIES_CHANGED, NULL, NULL, 0,
3127 __bt_manager_event_filter,
3130 if (subs_adapter_id == -1) {
3131 subs_adapter_id = g_dbus_connection_signal_subscribe(conn,
3132 NULL, BT_ADAPTER_INTERFACE,
3133 NULL, NULL, NULL, 0,
3134 __bt_manager_event_filter,
3137 if (subs_gatt_id == -1) {
3138 subs_gatt_id = g_dbus_connection_signal_subscribe(conn,
3139 NULL, BT_GATT_CHAR_INTERFACE,
3140 NULL, NULL, NULL, 0,
3141 __bt_manager_event_filter,
3145 if (subs_interface_added_id != -1) {
3146 g_dbus_connection_signal_unsubscribe(conn,
3147 subs_interface_added_id);
3148 subs_interface_added_id = -1;
3150 if (subs_interface_removed_id != -1) {
3151 g_dbus_connection_signal_unsubscribe(conn,
3152 subs_interface_removed_id);
3153 subs_interface_removed_id = -1;
3155 if (subs_name_owner_id != -1) {
3156 g_dbus_connection_signal_unsubscribe(conn,
3157 subs_name_owner_id);
3158 subs_name_owner_id = -1;
3160 if (subs_property_id != -1) {
3161 g_dbus_connection_signal_unsubscribe(conn,
3163 subs_property_id = -1;
3165 if (subs_adapter_id != -1) {
3166 g_dbus_connection_signal_unsubscribe(conn, subs_adapter_id);
3167 subs_adapter_id = -1;
3169 if (subs_gatt_id != -1) {
3170 g_dbus_connection_signal_unsubscribe(conn, subs_gatt_id);
3177 int _bt_register_device_subscribe_signal(GDBusConnection *conn,
3183 static int subs_device_id = -1;
3186 if (subs_device_id == -1) {
3187 subs_device_id = g_dbus_connection_signal_subscribe(conn,
3188 NULL, BT_DEVICE_INTERFACE,
3189 NULL, NULL, NULL, 0,
3190 __bt_manager_event_filter,
3194 if (subs_device_id != -1) {
3195 g_dbus_connection_signal_unsubscribe(conn,
3197 subs_device_id = -1;
3203 int _bt_register_input_subscribe_signal(GDBusConnection *conn,
3209 static int subs_input_id = -1;
3212 if (subs_input_id == -1) {
3213 subs_input_id = g_dbus_connection_signal_subscribe(conn,
3214 NULL, BT_INPUT_INTERFACE,
3215 NULL, NULL, NULL, 0,
3216 __bt_manager_event_filter,
3220 if (subs_input_id != -1) {
3221 g_dbus_connection_signal_unsubscribe(conn,
3229 int _bt_register_network_subscribe_signal(GDBusConnection *conn,
3235 static int subs_serv_id = -1;
3236 static int subs_client_id = -1;
3239 if (subs_serv_id == -1) {
3240 subs_serv_id = g_dbus_connection_signal_subscribe(conn,
3241 NULL, BT_NETWORK_SERVER_INTERFACE,
3242 NULL, NULL, NULL, 0,
3243 __bt_manager_event_filter,
3246 if (subs_client_id == -1) {
3247 subs_client_id = g_dbus_connection_signal_subscribe(conn,
3248 NULL, BT_NETWORK_CLIENT_INTERFACE,
3249 NULL, NULL, NULL, 0,
3250 __bt_manager_event_filter,
3254 if (subs_serv_id != -1) {
3255 g_dbus_connection_signal_unsubscribe(conn,
3259 if (subs_client_id != -1) {
3260 g_dbus_connection_signal_unsubscribe(conn,
3262 subs_client_id = -1;
3268 int _bt_register_audio_subscribe_signal(GDBusConnection *conn,
3274 static int subs_headset_id = -1;
3275 static int subs_sink_id = -1;
3278 if (subs_headset_id == -1) {
3279 subs_headset_id = g_dbus_connection_signal_subscribe(conn,
3280 NULL, BT_HEADSET_INTERFACE,
3281 NULL, NULL, NULL, 0,
3282 __bt_manager_event_filter,
3285 if (subs_sink_id == -1) {
3286 subs_sink_id = g_dbus_connection_signal_subscribe(conn,
3287 NULL, BT_SINK_INTERFACE,
3288 NULL, NULL, NULL, 0,
3289 __bt_manager_event_filter,
3293 if (subs_headset_id != -1) {
3294 g_dbus_connection_signal_unsubscribe(conn,
3296 subs_headset_id = -1;
3298 if (subs_sink_id != -1) {
3299 g_dbus_connection_signal_unsubscribe(conn,
3307 int _bt_register_opp_server_subscribe_signal(GDBusConnection *conn,
3313 static int subs_opp_server_interface_added_id = -1;
3314 static int subs_opp_server_interface_removed_id = -1;
3315 static int subs_opp_server_property_id = -1;
3319 if (subs_opp_server_interface_added_id == -1) {
3320 subs_opp_server_interface_added_id = g_dbus_connection_signal_subscribe(conn,
3321 NULL, BT_MANAGER_INTERFACE,
3322 BT_INTERFACES_ADDED, NULL, NULL, 0,
3323 __bt_obexd_event_filter,
3326 if (subs_opp_server_interface_removed_id == -1) {
3327 subs_opp_server_interface_removed_id = g_dbus_connection_signal_subscribe(conn,
3328 NULL, BT_MANAGER_INTERFACE,
3329 BT_INTERFACES_REMOVED, NULL, NULL, 0,
3330 __bt_obexd_event_filter,
3333 if (subs_opp_server_property_id == -1) {
3334 subs_opp_server_property_id = g_dbus_connection_signal_subscribe(conn,
3335 NULL, BT_PROPERTIES_INTERFACE,
3336 BT_PROPERTIES_CHANGED, NULL, NULL, 0,
3337 __bt_obexd_event_filter,
3341 if (subs_opp_server_interface_added_id != -1) {
3342 g_dbus_connection_signal_unsubscribe(conn,
3343 subs_opp_server_interface_added_id);
3344 subs_opp_server_interface_added_id = -1;
3346 if (subs_opp_server_interface_removed_id != -1) {
3347 g_dbus_connection_signal_unsubscribe(conn,
3348 subs_opp_server_interface_removed_id);
3349 subs_opp_server_interface_removed_id = -1;
3351 if (subs_opp_server_property_id != -1) {
3352 g_dbus_connection_signal_unsubscribe(conn,
3353 subs_opp_server_property_id);
3354 subs_opp_server_property_id = -1;
3360 int _bt_register_opp_client_subscribe_signal(GDBusConnection *conn,
3366 static int subs_opp_client_interface_added_id = -1;
3367 static int subs_opp_client_interface_removed_id = -1;
3368 static int subs_opp_client_property_id = -1;
3372 if (subs_opp_client_interface_added_id == -1) {
3373 subs_opp_client_interface_added_id = g_dbus_connection_signal_subscribe(conn,
3374 NULL, BT_MANAGER_INTERFACE,
3375 BT_INTERFACES_ADDED, NULL, NULL, 0,
3376 __bt_opc_event_filter,
3379 if (subs_opp_client_interface_removed_id == -1) {
3380 subs_opp_client_interface_removed_id = g_dbus_connection_signal_subscribe(conn,
3381 NULL, BT_MANAGER_INTERFACE,
3382 BT_INTERFACES_REMOVED, NULL, NULL, 0,
3383 __bt_opc_event_filter,
3386 if (subs_opp_client_property_id == -1) {
3387 subs_opp_client_property_id = g_dbus_connection_signal_subscribe(conn,
3388 NULL, BT_PROPERTIES_INTERFACE,
3389 BT_PROPERTIES_CHANGED, NULL, NULL, 0,
3390 __bt_opc_event_filter,
3394 if (subs_opp_client_interface_added_id != -1) {
3395 g_dbus_connection_signal_unsubscribe(conn,
3396 subs_opp_client_interface_added_id);
3397 subs_opp_client_interface_added_id = -1;
3399 if (subs_opp_client_interface_removed_id != -1) {
3400 g_dbus_connection_signal_unsubscribe(conn,
3401 subs_opp_client_interface_removed_id);
3402 subs_opp_client_interface_removed_id = -1;
3404 if (subs_opp_client_property_id != -1) {
3405 g_dbus_connection_signal_unsubscribe(conn,
3406 subs_opp_client_property_id);
3407 subs_opp_client_property_id = -1;
3413 int _bt_register_a2dp_subscribe_signal(GDBusConnection *conn,
3419 static int subs_a2dp_source_id = -1;
3420 static int subs_a2dp_sink_id = -1;
3423 if (subs_a2dp_source_id == -1) {
3424 subs_a2dp_source_id = g_dbus_connection_signal_subscribe(conn,
3425 NULL, BT_A2DP_SOURCE_INTERFACE,
3426 NULL, NULL, NULL, 0,
3427 __bt_opc_event_filter,
3430 if (subs_a2dp_sink_id == -1) {
3431 subs_a2dp_sink_id = g_dbus_connection_signal_subscribe(conn,
3432 NULL, BT_SINK_INTERFACE,
3433 NULL, NULL, NULL, 0,
3434 __bt_opc_event_filter,
3438 if (subs_a2dp_source_id != -1) {
3439 g_dbus_connection_signal_unsubscribe(conn,
3440 subs_a2dp_source_id);
3441 subs_a2dp_source_id = -1;
3443 if (subs_a2dp_sink_id != -1) {
3444 g_dbus_connection_signal_unsubscribe(conn,
3446 subs_a2dp_sink_id = -1;
3452 static void __bt_dump_event_filter(GDBusConnection *connection,
3453 const gchar *sender_name,
3454 const gchar *object_path,
3455 const gchar *interface_name,
3456 const gchar *signal_name,
3457 GVariant *parameters,
3463 int __bt_register_dump_subscribe_signal(GDBusConnection *conn,
3469 static int subs_source_id = -1;
3472 if (subs_source_id == -1) {
3473 subs_source_id = g_dbus_connection_signal_subscribe(conn,
3474 NULL, BT_DUMP_SERVICE_INTERFACE,
3475 BT_DUMP_SERVICE_SIGNAL, BT_DUMP_SERVICE_PATH, NULL, 0,
3476 __bt_dump_event_filter,
3480 if (subs_source_id != -1) {
3481 g_dbus_connection_signal_unsubscribe(conn,
3483 subs_source_id = -1;
3489 int _bt_register_service_event(GDBusConnection *g_conn, int event_type)
3493 retv_if(g_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
3495 switch (event_type) {
3496 case BT_MANAGER_EVENT:
3497 _bt_register_manager_subscribe_signal(g_conn, TRUE);
3499 case BT_DEVICE_EVENT:
3500 _bt_register_device_subscribe_signal(g_conn, TRUE);
3503 _bt_register_input_subscribe_signal(g_conn, TRUE);
3505 case BT_NETWORK_EVENT:
3506 _bt_register_network_subscribe_signal(g_conn, TRUE);
3508 case BT_HEADSET_EVENT:
3509 _bt_register_audio_subscribe_signal(g_conn, TRUE);
3512 case BT_OPP_SERVER_EVENT:
3513 BT_ERR("BT_OPP_SERVER_EVENT: register service event");
3514 _bt_register_opp_server_subscribe_signal(g_conn, TRUE);
3516 case BT_OPP_CLIENT_EVENT:
3517 BT_ERR("BT_OPP_CLIENT_EVENT: register service event");
3518 _bt_register_opp_client_subscribe_signal(g_conn, TRUE);
3520 case BT_A2DP_SOURCE_EVENT:
3521 BT_INFO("A2dp Source event");
3522 _bt_register_a2dp_subscribe_signal(g_conn, TRUE);
3525 BT_ERR("Unknown event");
3526 return BLUETOOTH_ERROR_INTERNAL;
3529 return BLUETOOTH_ERROR_NONE;
3532 void _bt_unregister_service_event(GDBusConnection *g_conn, int event_type)
3536 ret_if(g_conn == NULL);
3538 switch (event_type) {
3539 case BT_MANAGER_EVENT:
3540 _bt_register_manager_subscribe_signal(g_conn, FALSE);
3541 _bt_register_device_subscribe_signal(g_conn, FALSE);
3542 _bt_register_input_subscribe_signal(g_conn, FALSE);
3543 _bt_register_network_subscribe_signal(g_conn, FALSE);
3544 _bt_register_audio_subscribe_signal(g_conn, FALSE);
3546 case BT_OPP_SERVER_EVENT:
3547 _bt_register_opp_server_subscribe_signal(g_conn, FALSE);
3549 case BT_OPP_CLIENT_EVENT:
3550 _bt_register_opp_client_subscribe_signal(g_conn, FALSE);
3553 BT_ERR("Unknown event");
3560 static int __bt_init_manager_receiver(void)
3564 GError *error = NULL;
3566 if (manager_conn == NULL) {
3567 manager_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
3568 if (error != NULL) {
3569 BT_ERR("ERROR: Can't get on system bus [%s]", error->message);
3570 g_clear_error(&error);
3572 retv_if(manager_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
3575 if (_bt_register_service_event(manager_conn,
3576 BT_MANAGER_EVENT) != BLUETOOTH_ERROR_NONE)
3578 if (_bt_register_service_event(manager_conn,
3579 BT_DEVICE_EVENT) != BLUETOOTH_ERROR_NONE)
3582 if (_bt_register_service_event(manager_conn,
3583 BT_HID_EVENT) != BLUETOOTH_ERROR_NONE)
3586 if (_bt_register_service_event(manager_conn,
3587 BT_HEADSET_EVENT) != BLUETOOTH_ERROR_NONE)
3590 if (_bt_register_service_event(manager_conn,
3591 BT_NETWORK_EVENT) != BLUETOOTH_ERROR_NONE)
3594 __bt_register_dump_subscribe_signal(manager_conn, TRUE);
3595 return BLUETOOTH_ERROR_NONE;
3598 g_object_unref(manager_conn);
3599 manager_conn = NULL;
3604 return BLUETOOTH_ERROR_INTERNAL;
3607 static int __bt_init_obexd_receiver(void)
3610 #ifndef TIZEN_TV /* TODO: obexd doesn't work in TV profile. It should be resolved later. */
3611 GError *error = NULL;
3613 if (obexd_conn == NULL) {
3614 obexd_conn = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &error);
3615 if (error != NULL) {
3616 BT_ERR("ERROR: Can't get on session bus [%s]", error->message);
3617 g_clear_error(&error);
3619 retv_if(obexd_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
3622 if (_bt_register_service_event(obexd_conn,
3623 BT_OPP_SERVER_EVENT) != BLUETOOTH_ERROR_NONE) {
3624 BT_ERR("Error while registering service event");
3625 g_object_unref(obexd_conn);
3627 return BLUETOOTH_ERROR_INTERNAL;
3632 return BLUETOOTH_ERROR_NONE;
3635 gboolean __bt_reinit_obexd_receiver(gpointer user_data)
3637 static int retry_cnt = 0;
3638 int result = BLUETOOTH_ERROR_NONE;
3642 result = __bt_init_obexd_receiver();
3643 if (result != BLUETOOTH_ERROR_NONE) {
3644 /* 20 ms * 50 = 10 seconds. During 10 seconds fail to initialize,
3645 then it is not the timing issue. Just can't use the session bus connection */
3646 if (retry_cnt > 100) {
3647 BT_ERR("Fail to init obexd receiver by 50 times.");
3649 session_reinit_timer = 0;
3653 BT_DBG("Retry to initialize the obexd receiver");
3658 session_reinit_timer = 0;
3665 /* To receive the event from bluez */
3666 int _bt_init_service_event_receiver(void)
3672 result = __bt_init_manager_receiver();
3673 retv_if(result != BLUETOOTH_ERROR_NONE, result);
3675 result = __bt_init_obexd_receiver();
3676 if (result != BLUETOOTH_ERROR_NONE) {
3677 BT_ERR("Fail to init obexd receiver");
3679 /* Try to re-initialize obexd receiver in the timer */
3680 if (session_reinit_timer > 0)
3681 g_source_remove(session_reinit_timer);
3683 session_reinit_timer = g_timeout_add(BT_SESSION_BUS_GET_TIMEOUT,
3684 (GSourceFunc)__bt_reinit_obexd_receiver, NULL);
3689 return BLUETOOTH_ERROR_NONE;
3692 void _bt_deinit_service_event_receiver(void)
3696 _bt_unregister_service_event(manager_conn, BT_MANAGER_EVENT);
3698 _bt_unregister_service_event(obexd_conn, BT_OPP_SERVER_EVENT);
3700 __bt_register_dump_subscribe_signal(manager_conn, FALSE);
3703 g_object_unref(manager_conn);
3704 manager_conn = NULL;
3708 g_object_unref(obexd_conn);
3713 g_source_remove(event_id);