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"
45 #include "bt-service-map-client.h"
46 #include "bt-service-tds.h"
48 #ifdef TIZEN_FEATURE_BT_DPM
49 #include "bt-service-dpm.h"
52 #define DBUS_TIMEOUT 20 * 1000 /* 20 Sec */
53 static GDBusConnection *manager_conn;
54 static GDBusConnection *obexd_conn;
55 static GDBusConnection *opc_obexd_conn;
56 static GDBusConnection *map_obexd_conn;
58 static GList *p_cache_list = NULL;
60 static guint event_id;
61 static guint le_scan_event_id = 0;
62 static guint session_reinit_timer;
63 guint nap_connected_device_count = 0;
64 static guint hid_connected_device_count = 0;
65 static GList *p_adv_ind_list = NULL;
68 bt_remote_dev_info_t *dev_info;
72 * obexd connection type
80 OBEX_PCSUITE = (1 << 6),
81 OBEX_SYNCEVOLUTION = (1 << 7),
84 } bluetooth_obex_connection_type_t;
86 void _bt_handle_property_changed_event(GVariant *msg, const char *object_path);
87 void _bt_opc_property_changed_event(GVariant *msg, char *path);
88 void _bt_map_property_changed_event(GVariant *msg, const char *path);
89 int _bt_register_service_event(GDBusConnection *g_conn, int event_type);
90 void _bt_unregister_service_event(GDBusConnection *g_conn, int event_type);
91 void _bt_opp_client_event_deinit(void);
92 void _bt_map_client_event_deinit(void);
93 void _bt_handle_network_client_event(GVariant *msg_iter,
95 void __bt_gatt_char_property_changed_event(GVariant *msg_iter,
97 void _bt_map_on_transfer_finished(const char *transfer_object_path, const int error);
99 static void __bt_free_bt_le_adv_info_t(gpointer data)
101 bt_le_adv_info_t *adv_info = data;
103 if (adv_info->timer_id)
104 g_source_remove(adv_info->timer_id);
105 adv_info->timer_id = 0;
107 g_free(adv_info->addr);
108 g_free(adv_info->data);
112 static bt_le_adv_info_t *__bt_get_adv_ind_info(char *addr)
114 retv_if(!addr, NULL);
115 bt_le_adv_info_t *adv_info = NULL;
116 GList *current = g_list_first((GList *)p_adv_ind_list);
117 while (current && current->data) {
118 adv_info = (bt_le_adv_info_t *)current->data;
119 if (adv_info && !g_strcmp0(adv_info->addr, addr))
121 current = g_list_next(current);
126 static int __bt_add_adv_ind_info(bt_le_adv_info_t *adv_info)
128 retv_if(!adv_info, -1);
129 if (__bt_get_adv_ind_info(adv_info->addr) != NULL) {
130 __bt_free_bt_le_adv_info_t(adv_info);
133 p_adv_ind_list = g_list_append(p_adv_ind_list, adv_info);
138 static void __bt_del_adv_ind_info(char *addr)
141 ret_if(!p_adv_ind_list);
142 bt_le_adv_info_t *adv_info = NULL;
143 GList *current = g_list_first((GList *)p_adv_ind_list);
144 while (current && current->data) {
145 adv_info = (bt_le_adv_info_t *)current->data;
146 if (adv_info && !g_strcmp0(adv_info->addr, addr)) {
147 p_adv_ind_list = g_list_remove(p_adv_ind_list, adv_info);
148 __bt_free_bt_le_adv_info_t(adv_info);
151 current = g_list_next(current);
155 static gboolean __bt_adv_scan_req_timeout_cb(gpointer user_data)
157 bt_remote_le_dev_info_t le_dev_info;
158 bt_le_adv_info_t *adv_info = (bt_le_adv_info_t*)user_data;
160 memset(&le_dev_info, 0x00, sizeof(bt_remote_le_dev_info_t));
162 le_dev_info.address = adv_info->addr;
163 le_dev_info.addr_type = adv_info->addr_type;
164 le_dev_info.rssi = adv_info->rssi;
165 le_dev_info.adv_data = adv_info->data;
166 le_dev_info.adv_data_len = 0;
167 adv_info->timer_id = 0;
169 _bt_send_scan_result_event(&le_dev_info, adv_info);
170 __bt_del_adv_ind_info(adv_info->addr);
175 static void __bt_free_cache_info(bt_cache_info_t *cache_info)
177 ret_if(cache_info == NULL);
178 _bt_free_device_info(cache_info->dev_info);
182 static gboolean __bt_parse_device_properties(GVariant *item,
183 bt_remote_dev_info_t *dev_info)
192 g_variant_iter_init(&iter, item);
193 while (g_variant_iter_loop(&iter, "{sv}", &key, &val)) {
194 if (strcasecmp(key, "Address") == 0) {
195 dev_info->address = g_variant_dup_string(val, &len);
196 } else if (strcasecmp(key, "Class") == 0) {
197 dev_info->class = g_variant_get_uint32(val);
198 } else if (strcasecmp(key, "name") == 0) {
199 if (dev_info->name == NULL)
200 dev_info->name = g_variant_dup_string(val, &len);
201 } else if (strcasecmp(key, "Connected") == 0) {
202 dev_info->connected = g_variant_get_byte(val);
203 } else if (strcasecmp(key, "paired") == 0) {
204 dev_info->paired = g_variant_get_boolean(val);
205 } else if (strcasecmp(key, "Trusted") == 0) {
206 dev_info->trust = g_variant_get_boolean(val);
207 } else if (strcasecmp(key, "RSSI") == 0) {
208 dev_info->rssi = g_variant_get_int16(val);
209 } else if (strcasecmp(key, "LastAddrType") == 0) {
210 dev_info->addr_type = g_variant_get_byte(val);
211 } else if (strcasecmp(key, "UUIDs") == 0) {
215 size = g_variant_get_size(val);
218 uuid_value = (char **)g_variant_get_strv(val, &size);
219 if (dev_info->uuids == NULL)
220 dev_info->uuids = g_malloc0(sizeof(char *) * size);
222 for (i = 0; uuid_value[i] != NULL; i++) {
223 dev_info->uuid_count++;
224 dev_info->uuids[i] = g_strdup(uuid_value[i]);
228 } else if (strcasecmp(key, "ManufacturerDataLen") == 0) {
229 g_variant_get(val, "q", &dev_info->manufacturer_data_len);
230 if (dev_info->manufacturer_data_len > BLUETOOTH_MANUFACTURER_DATA_LENGTH_MAX) {
231 BT_ERR("manufacturer_data_len is too long(len = %d)", dev_info->manufacturer_data_len);
232 dev_info->manufacturer_data_len = BLUETOOTH_MANUFACTURER_DATA_LENGTH_MAX;
235 if (dev_info->manufacturer_data_len == 0)
236 dev_info->manufacturer_data = g_strdup("");
237 } else if (strcasecmp(key, "ManufacturerData") == 0) {
240 GVariantIter *value_iter;
243 len = g_variant_get_size(val);
247 dev_info->manufacturer_data = g_malloc0(len);
249 g_variant_get(val, "ay", &value_iter);
250 while (g_variant_iter_loop(value_iter, "y", &m_value))
251 dev_info->manufacturer_data[i++] = m_value;
252 g_variant_iter_free(value_iter);
260 static gboolean __bt_parse_interface(GVariant *msg,
261 bt_remote_dev_info_t *dev_info)
264 GVariant *optional_param = NULL;
267 char *interface_name = NULL;
268 GVariant *inner_iter = NULL;
269 g_variant_get(msg, "(&o@a{sa{sv}})",
270 &path, &optional_param);
271 g_variant_iter_init(&iter, optional_param);
273 retv_if(optional_param == NULL, FALSE);
275 while ((child = g_variant_iter_next_value(&iter))) {
276 g_variant_get(child, "{&s@a{sv}}", &interface_name, &inner_iter);
277 if (g_strcmp0(interface_name, BT_DEVICE_INTERFACE) == 0) {
278 BT_DBG("Found a device: %s", path);
279 if (__bt_parse_device_properties(inner_iter,
280 dev_info) == FALSE) {
281 g_variant_unref(inner_iter);
282 g_variant_unref(child);
283 g_variant_unref(optional_param);
284 BT_ERR("Fail to parse the properies");
287 g_variant_unref(inner_iter);
288 g_variant_unref(child);
289 g_variant_unref(optional_param);
293 g_variant_unref(inner_iter);
294 g_variant_unref(child);
297 g_variant_unref(optional_param);
302 static int __bt_get_owner_info(GVariant *msg, char **name,
303 char **previous, char **current)
305 g_variant_get(msg, "(sss)", name, previous, current);
306 return BLUETOOTH_ERROR_NONE;
309 static int __bt_get_agent_signal_info(GVariant *msg, char **address,
310 char **name, char **uuid)
312 g_variant_get(msg, "(sss)", address, name, uuid);
313 return BLUETOOTH_ERROR_NONE;
316 void __bt_set_device_values(gboolean connected, int state)
318 int bt_device_state = VCONFKEY_BT_DEVICE_NONE;
320 if (vconf_get_int(VCONFKEY_BT_DEVICE, &bt_device_state) != 0)
321 BT_ERR("vconf_get_int failed");
323 if (connected == TRUE)
324 bt_device_state |= state;
325 else if (bt_device_state & state)
326 bt_device_state ^= state;
328 if (vconf_set_int(VCONFKEY_BT_DEVICE, bt_device_state) != 0)
329 BT_ERR("vconf_set_int failed");
332 gboolean _bt_discovery_finished_cb(gpointer user_data)
334 int result = BLUETOOTH_ERROR_NONE;
336 GVariant *param = NULL;
337 if (_bt_get_discovering_property(DISCOVERY_ROLE_BREDR) == FALSE) {
338 if (_bt_get_cancel_by_user() == TRUE)
339 result = BLUETOOTH_ERROR_CANCEL_BY_USER;
341 _bt_set_cancel_by_user(FALSE);
342 _bt_set_discovery_status(FALSE);
343 param = g_variant_new("(i)", result);
344 _bt_send_event(BT_ADAPTER_EVENT,
345 BLUETOOTH_EVENT_DISCOVERY_FINISHED,
352 static gboolean __bt_le_discovery_finished_cb(gpointer user_data)
354 int result = BLUETOOTH_ERROR_NONE;
355 le_scan_event_id = 0;
356 GVariant *param = NULL;
357 if (_bt_get_discovering_property(DISCOVERY_ROLE_LE) == FALSE) {
358 if (_bt_get_cancel_by_user() == TRUE)
359 result = BLUETOOTH_ERROR_CANCEL_BY_USER;
361 g_list_free_full(p_adv_ind_list, __bt_free_bt_le_adv_info_t);
362 p_adv_ind_list = NULL;
364 _bt_set_cancel_by_user(FALSE);
365 _bt_disable_all_scanner_status();
366 _bt_set_le_scan_status(FALSE);
367 param = g_variant_new("(i)", result);
368 _bt_send_event(BT_LE_ADAPTER_EVENT,
369 BLUETOOTH_EVENT_LE_DISCOVERY_FINISHED,
376 void __bt_update_remote_cache_devinfo(const char *address, gboolean paired_status)
380 ret_if(address == NULL);
383 bt_cache_info_t *cache_info;
384 bt_remote_dev_info_t *dev_info;
386 node = g_list_first(p_cache_list);
388 while (node != NULL) {
389 cache_info = (bt_cache_info_t *)node->data;
391 if (cache_info == NULL) {
392 node = g_list_next(node);
396 dev_info = cache_info->dev_info;
397 if (strcasecmp(dev_info->address,
399 BT_DBG("Device Found");
400 if (paired_status == TRUE)
401 cache_info->dev_info->paired = TRUE;
403 cache_info->dev_info->paired = FALSE;
406 node = g_list_next(node);
411 static void __bt_device_remote_connected_properties(
412 bt_remote_dev_info_t *remote_dev_info,
413 char *address, gboolean connected)
415 int result = BLUETOOTH_ERROR_NONE;
417 GVariant *param = NULL;
420 if (remote_dev_info->uuid_count > 0) {
421 for (i = 0; i < remote_dev_info->uuid_count; i++) {
422 char *uuid = remote_dev_info->uuids[i];
423 if (strcasecmp(uuid, HID_UUID) == 0) {
424 int event = BLUETOOTH_EVENT_NONE;
426 event = (connected == TRUE) ?
427 BLUETOOTH_HID_CONNECTED :
428 BLUETOOTH_HID_DISCONNECTED;
429 param = g_variant_new("(is)", result,
431 _bt_send_event(BT_HID_EVENT, event,
441 gboolean __bt_handle_is_flight_mode_enabled(void)
443 #ifdef TIZEN_FEATURE_FLIGHTMODE_ENABLED
444 int is_flight_mode = 0;
447 ret = vconf_get_bool(VCONFKEY_TELEPHONY_FLIGHT_MODE, &is_flight_mode);
449 BT_ERR("vconf_get_bool failed");
451 return (is_flight_mode == 0) ? FALSE : TRUE;
457 void _bt_handle_adapter_event(GVariant *msg, const char *member)
461 int result = BLUETOOTH_ERROR_NONE;
462 GVariant *param = NULL;
463 ret_if(member == NULL);
465 if (strcasecmp(member, "DeviceCreated") == 0) {
466 char *object_path = NULL;
468 bt_remote_dev_info_t *remote_dev_info;
470 ret_if(_bt_is_device_creating() == FALSE);
472 /* Bonding from remote device */
473 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
475 g_variant_get(msg, "(&o)", &object_path);
476 _bt_convert_device_path_to_address((const char*)object_path, address);
478 remote_dev_info = _bt_get_remote_device_info_by_object_path(object_path);
479 if (remote_dev_info == NULL) {
484 _bt_free_device_info(remote_dev_info);
486 } else if (strcasecmp(member, "InterfacesRemoved") == 0) {
487 char *object_path = NULL;
489 bt_cache_info_t *cache_info;
490 bt_remote_dev_info_t *dev_info;
493 /* Bonding from remote device */
494 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
496 g_variant_get(msg, "(&o)", &object_path);
498 _bt_convert_device_path_to_address((const char *)object_path, address);
500 node = g_list_first(p_cache_list);
502 while (node != NULL) {
503 cache_info = (bt_cache_info_t *)node->data;
505 if (cache_info == NULL) {
506 node = g_list_next(node);
510 dev_info = cache_info->dev_info;
511 if (strcasecmp(dev_info->address,
513 p_cache_list = g_list_remove(p_cache_list,
515 __bt_free_cache_info(cache_info);
518 node = g_list_next(node);
521 } else if (strcasecmp(member, "AdvertisingEnabled") == 0) {
522 BT_DBG("Advertising Enabled");
526 gboolean status = FALSE;
528 g_variant_get(msg, "(ib)", &slot_id, &status);
530 BT_DBG("Advertising Enabled : slot_id [%d] status [%d]", slot_id, status);
532 /* Send event to application */
533 _bt_set_advertising_status(slot_id, status);
535 adv_handle = _bt_get_adv_slot_adv_handle(slot_id);
538 event = BLUETOOTH_EVENT_ADVERTISING_STARTED;
540 event = BLUETOOTH_EVENT_ADVERTISING_STOPPED;
541 param = g_variant_new("(ii)", result,
545 sender = _bt_get_adv_slot_owner(slot_id);
546 _bt_send_event_to_dest(sender, BT_ADAPTER_EVENT,
550 if (event == BLUETOOTH_EVENT_ADVERTISING_STOPPED) {
551 char *name = g_strdup(sender);
553 _bt_unregister_adv_slot_owner(slot_id);
555 /* Advertising disabled, notify TDS */
556 _bt_tds_handle_adv_disabled(name, adv_handle);
559 } else if (strcasecmp(member, "RssiEnabled") == 0) {
560 BT_DBG("RSSI Enabled");
561 gboolean status = FALSE;
562 char *address = NULL;
564 g_variant_get(msg, "(sib)", &address, &link_type, &status);
566 BT_DBG("RSSI Enabled [%s %d]", address, status);
567 param = g_variant_new("(isib)", result,
568 address, link_type, status);
569 _bt_send_event(BT_DEVICE_EVENT,
570 BLUETOOTH_EVENT_RSSI_ENABLED,
573 } else if (strcasecmp(member, "RssiAlert") == 0) {
574 BT_DBG("RSSI Alert");
578 char *address = NULL;
579 g_variant_get(msg, "(siii)", &address, &link_type, &alert_type, &rssi_dbm);
581 BT_DBG("RSSI Alert: [Address %s LinkType %d] [Type %d DBM %d]",
582 address, alert_type, rssi_dbm);
583 param = g_variant_new("(isiii)", result,
584 address, link_type, alert_type, rssi_dbm);
585 _bt_send_event(BT_DEVICE_EVENT,
586 BLUETOOTH_EVENT_RSSI_ALERT,
589 } else if (strcasecmp(member, "RawRssi") == 0) {
593 char *address = NULL;
594 g_variant_get(msg, "(sii)", &address, &link_type, &rssi_dbm);
596 BT_DBG("Raw RSSI: [Address %s] [Link Type %d][RSSI DBM %d]",
597 address, link_type, rssi_dbm);
598 param = g_variant_new("(isii)", result,
599 address, link_type, rssi_dbm);
600 _bt_send_event(BT_DEVICE_EVENT,
601 BLUETOOTH_EVENT_RAW_RSSI,
604 } else if (strcasecmp(member, BT_HARDWARE_ERROR) == 0) {
605 BT_ERR_C("### Hardware error received from BLUEZ");
606 /* Don't add the recovery logic into platform */
608 _bt_recover_adapter();
610 } else if (strcasecmp(member, BT_TX_TIMEOUT_ERROR) == 0) {
611 BT_ERR_C("### Tx timeout error received from BLUEZ");
612 /* Don't add the recovery logic into platform */
614 _bt_recover_adapter();
620 static void __bt_adapter_property_changed_event(GVariant *msg, const char *path)
622 GDBusProxy *adapter_proxy;
624 int result = BLUETOOTH_ERROR_NONE;
625 GVariantIter value_iter;
626 GVariant *val = NULL;
627 GVariant *ret = NULL;
629 char *property = NULL;
630 GVariant *param = NULL;
631 g_variant_iter_init(&value_iter, msg);
632 while ((g_variant_iter_loop(&value_iter, "{sv}", &property, &val))) {
633 BT_INFO("Property %s", property);
635 if (strcasecmp(property, "Discovering") == 0) {
636 gboolean discovering = FALSE;
637 g_variant_get(val, "b", &discovering);
638 /* Send event to application */
639 BT_DBG("Discovering %d", discovering);
640 if (discovering == TRUE) {
641 _bt_set_discovery_status(TRUE);
642 param = g_variant_new("(i)", result);
643 _bt_send_event(BT_ADAPTER_EVENT,
644 BLUETOOTH_EVENT_DISCOVERY_STARTED,
647 ret_if(event_id > 0);
649 adapter_proxy = _bt_get_adapter_proxy();
650 ret_if(adapter_proxy == NULL);
652 /* Need to stop searching */
653 ret = g_dbus_proxy_call_sync(adapter_proxy, "StopDiscovery",
655 G_DBUS_CALL_FLAGS_NONE,
659 BT_ERR("Dbus Error : %s", err->message);
663 g_variant_unref(ret);
665 event_id = g_timeout_add(BT_DISCOVERY_FINISHED_DELAY,
666 (GSourceFunc)_bt_discovery_finished_cb, NULL);
668 } else if (strcasecmp(property, "LEDiscovering") == 0) {
669 gboolean le_discovering = FALSE;
671 g_variant_get(val, "b", &le_discovering);
672 /* Send event to application */
673 if (le_discovering == TRUE) {
674 _bt_set_le_scan_status(TRUE);
675 param = g_variant_new("(i)", result);
676 _bt_send_event(BT_LE_ADAPTER_EVENT,
677 BLUETOOTH_EVENT_LE_DISCOVERY_STARTED,
680 ret_if(le_scan_event_id > 0);
682 adapter_proxy = _bt_get_adapter_proxy();
683 ret_if(adapter_proxy == NULL);
685 /* Need to stop searching */
686 ret = g_dbus_proxy_call_sync(adapter_proxy, "StopLEDiscovery",
688 G_DBUS_CALL_FLAGS_NONE,
692 BT_ERR("Dbus Error %s", err->message);
696 g_variant_unref(ret);
698 le_scan_event_id = g_timeout_add(BT_DISCOVERY_FINISHED_DELAY,
699 (GSourceFunc)__bt_le_discovery_finished_cb, NULL);
701 } else if (strcasecmp(property, "Name") == 0) {
703 g_variant_get(val, "s", &name);
704 param = g_variant_new("(is)", result, name);
705 /* Send event to application */
706 _bt_send_event(BT_ADAPTER_EVENT,
707 BLUETOOTH_EVENT_LOCAL_NAME_CHANGED,
710 } else if (strcasecmp(property, "Alias") == 0) {
712 g_variant_get(val, "s", &alias);
713 param = g_variant_new("(is)", result, alias);
714 /* Send event to application */
715 _bt_send_event(BT_ADAPTER_EVENT,
716 BLUETOOTH_EVENT_LOCAL_NAME_CHANGED,
719 } else if (strcasecmp(property, "Discoverable") == 0) {
720 gboolean discoverable = FALSE;
722 g_variant_get(val, "b", &discoverable);
723 BT_DBG("discoverable %d", discoverable);
725 if (discoverable == FALSE) {
726 if (_bt_get_discoverable_timeout_property() > 0) {
728 adapter_proxy = _bt_get_adapter_properties_proxy();
729 ret_if(adapter_proxy == NULL);
730 ret = g_dbus_proxy_call_sync(adapter_proxy, "Set",
731 g_variant_new("(ssv)", BT_ADAPTER_INTERFACE,
732 "DiscoverableTimeout",
733 g_variant_new("i", time)),
734 G_DBUS_CALL_FLAGS_NONE,
739 BT_ERR("StopLEDiscovery Failed: %s", err->message);
743 g_variant_unref(ret);
746 mode = BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE;
748 /* Send event to application */
749 BT_INFO("[Connectable]");
750 param = g_variant_new("(in)", result, mode);
751 _bt_send_event(BT_ADAPTER_EVENT,
752 BLUETOOTH_EVENT_DISCOVERABLE_MODE_CHANGED,
755 _bt_get_discoverable_mode(&mode);
757 /* Event will be sent by "DiscoverableTimeout" signal */
758 if (mode != BLUETOOTH_DISCOVERABLE_MODE_GENERAL_DISCOVERABLE) {
760 g_variant_unref(val);
764 /* Send event to application */
765 BT_INFO("[General Discoverable]");
766 param = g_variant_new("(in)", result, mode);
767 _bt_send_event(BT_ADAPTER_EVENT,
768 BLUETOOTH_EVENT_DISCOVERABLE_MODE_CHANGED,
771 } else if (strcasecmp(property, "DiscoverableTimeout") == 0) {
772 _bt_get_discoverable_mode(&mode);
774 /* Event was already sent by "Discoverable" signal */
775 if (mode == BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE ||
776 mode == BLUETOOTH_DISCOVERABLE_MODE_GENERAL_DISCOVERABLE) {
778 g_variant_unref(val);
782 /* Send event to application */
783 BT_INFO("[Limited Discoverable (Timeout %u secs)]",
784 _bt_get_discoverable_timeout_property());
785 param = g_variant_new("(in)", result, mode);
786 _bt_send_event(BT_ADAPTER_EVENT,
787 BLUETOOTH_EVENT_DISCOVERABLE_MODE_CHANGED,
789 } else if (strcasecmp(property, "Powered") == 0) {
790 /* TODO: Need to check this operation!! */
791 gboolean powered = FALSE;
794 g_variant_get(val, "b", &powered);
795 BT_DBG("Powered = %d", powered);
796 if (powered == FALSE) {
797 #ifdef TIZEN_FEATURE_BT_USB_DONGLE
798 _bt_handle_adapter_removed();
800 if (vconf_get_int(VCONFKEY_BT_STATUS, &bt_state) == 0 &&
801 bt_state != VCONFKEY_BT_STATUS_OFF) {
802 if (__bt_handle_is_flight_mode_enabled() == FALSE)
803 _bt_disable_adapter();
805 _bt_handle_adapter_removed();
808 if (vconf_get_int(VCONFKEY_BT_LE_STATUS, &bt_state) == 0 &&
809 bt_state != VCONFKEY_BT_LE_STATUS_OFF) {
810 _bt_set_le_disabled(BLUETOOTH_ERROR_NONE);
813 #ifdef TIZEN_FEATURE_BT_USB_DONGLE
814 _bt_handle_adapter_added();
817 } else if (strcasecmp(property, "Connectable") == 0) {
818 gboolean connectable = FALSE;
820 g_variant_get(val, "b", &connectable);
822 BT_DBG("Connectable property is changed : %d", connectable);
823 param = g_variant_new("(b)", connectable);
824 _bt_send_event(BT_ADAPTER_EVENT,
825 BLUETOOTH_EVENT_CONNECTABLE_CHANGED,
828 if (_bt_adapter_get_status() == BT_DEACTIVATING &&
829 _bt_adapter_get_le_status() == BT_LE_ACTIVATED &&
831 _bt_set_disabled(BLUETOOTH_ERROR_NONE);
833 } else if (strcasecmp(property, "SupportedLEFeatures") == 0) {
836 GVariantIter *iter = NULL;
837 g_variant_get(val, "as", &iter);
839 ret_if(iter == NULL);
841 while (g_variant_iter_loop(iter, "s", &name)) {
842 BT_DBG("name = %s", name);
843 g_variant_iter_loop(iter, "s", &value);
844 BT_DBG("Value = %s", value);
845 if (FALSE == _bt_update_le_feature_support(name, value))
846 BT_INFO("Fail to update LE feature info");
849 g_variant_iter_free(iter);
850 } else if (strcasecmp(property, "IpspInitStateChanged") == 0) {
851 gboolean ipsp_initialized = FALSE;
853 g_variant_get(val, "b", &ipsp_initialized);
854 BT_DBG("IPSP init state changed: %d", ipsp_initialized);
855 param = g_variant_new("(b)", ipsp_initialized);
857 /* Send event to application */
858 _bt_send_event(BT_ADAPTER_EVENT,
859 BLUETOOTH_EVENT_IPSP_INIT_STATE_CHANGED,
862 BT_DBG("property : [%s]", property);
867 static void __bt_obex_property_changed_event(GVariant *msg, const char *path)
871 GVariantIter value_iter;
872 GVariant *child = NULL, *val = NULL;
873 char *property = NULL;
874 g_variant_iter_init(&value_iter, msg);
875 while ((child = g_variant_iter_next_value(&value_iter))) {
876 g_variant_get(child, "{sv}", &property, &val);
878 ret_if(property == NULL);
880 BT_DBG("property :%s", property);
882 if (strcasecmp(property, "Status") == 0) {
884 g_variant_get(val, "s", &status);
886 if (strcasecmp(status, "active") == 0) {
887 _bt_obex_transfer_started(path);
888 } else if (strcasecmp(status, "complete") == 0) {
889 _bt_obex_transfer_completed(path, TRUE);
890 _bt_pbap_obex_transfer_completed(path, TRUE);
891 } else if (strcasecmp(status, "error") == 0) {
892 _bt_obex_transfer_completed(path, FALSE);
893 _bt_pbap_obex_transfer_completed(path, FALSE);
896 } else if (strcasecmp(property, "Transferred") == 0) {
897 guint64 transferred = 0;
898 /* As Transferred is expected guint64 so change int to guint64 and
899 * eariler transferred is static because of it can overwrite data
900 * on present on opc_obex_conn or obexd_conn as these are
901 * static memory are in sequential */
902 g_variant_get(val, "t", &transferred);
904 _bt_obex_transfer_progress(path, transferred);
906 /* TODO: MAP, "Complete"? see above */
908 g_variant_unref(val);
909 g_variant_unref(child);
914 static void __bt_device_property_changed_event(GVariant *msg, const char *path)
919 int result = BLUETOOTH_ERROR_NONE;
920 GVariantIter value_iter;
922 char *property = NULL;
924 GVariant *param = NULL;
925 bt_remote_dev_info_t *remote_dev_info;
926 g_variant_iter_init(&value_iter, msg);
927 #ifdef TIZEN_FEATURE_BT_DPM
928 int desktop_state = DPM_BT_ERROR;
930 while ((g_variant_iter_loop(&value_iter, "{sv}", &property, &val))) {
931 BT_DBG("Property %s", property);
932 if (strcasecmp(property, "Connected") == 0) {
935 g_variant_get(val, "i", &connected);
937 event = (connected != BLUETOOTH_CONNECTED_LINK_NONE) ?
938 BLUETOOTH_EVENT_DEVICE_CONNECTED :
939 BLUETOOTH_EVENT_DEVICE_DISCONNECTED;
941 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
943 _bt_convert_device_path_to_address(path, address);
945 BT_DBG("connected: %d", connected);
946 BT_DBG("address: %s", address);
948 remote_dev_info = _bt_get_remote_device_info_by_object_path(path);
950 if (remote_dev_info != NULL) {
951 __bt_device_remote_connected_properties(
952 remote_dev_info, address,
953 connected != BLUETOOTH_CONNECTED_LINK_NONE ?
955 _bt_free_device_info(remote_dev_info);
957 param = g_variant_new("(is)", result, address);
958 /* Send event to application */
959 _bt_send_event(BT_DEVICE_EVENT,
963 } else if (strcasecmp(property, "RSSI") == 0) {
964 bt_remote_dev_info_t *remote_dev_info;
966 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
968 _bt_convert_device_path_to_address(path, address);
969 BT_DBG("address: %s", address);
973 remote_dev_info = _bt_get_remote_device_info_by_object_path(path);
974 if (remote_dev_info == NULL) {
976 g_variant_unref(val);
979 BT_DBG("Address type %d", remote_dev_info->addr_type);
981 if (remote_dev_info->addr_type == 0) {
982 BT_DBG("Name %s", remote_dev_info->name);
984 #ifdef TIZEN_FEATURE_BT_DPM
985 _bt_dpm_get_bluetooth_desktop_connectivity_state(&desktop_state);
986 if (desktop_state == DPM_RESTRICTED) {
987 bluetooth_device_class_t device_class;
988 _bt_divide_device_class(&device_class, remote_dev_info->class);
990 if (device_class.major_class ==
991 BLUETOOTH_DEVICE_MAJOR_CLASS_COMPUTER) {
992 _bt_free_device_info(remote_dev_info);
994 g_variant_unref(val);
1000 GVariant *uuids = NULL;
1001 GVariantBuilder *builder = NULL;
1003 builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
1004 for (i = 0; i < remote_dev_info->uuid_count; i++) {
1005 g_variant_builder_add(builder, "s",
1006 remote_dev_info->uuids[i]);
1008 uuids = g_variant_new("as", builder);
1009 g_variant_builder_unref(builder);
1010 GVariant *manufacturer_data = NULL;
1011 manufacturer_data = g_variant_new_from_data(G_VARIANT_TYPE_BYTESTRING,
1012 remote_dev_info->manufacturer_data,
1013 remote_dev_info->manufacturer_data_len,
1016 param = g_variant_new("(isunsbub@asn@ay)", result,
1017 remote_dev_info->address,
1018 remote_dev_info->class,
1019 remote_dev_info->rssi,
1020 remote_dev_info->name,
1021 remote_dev_info->paired,
1022 remote_dev_info->connected,
1023 remote_dev_info->trust,
1025 remote_dev_info->manufacturer_data_len,
1028 _bt_send_event(BT_ADAPTER_EVENT,
1029 BLUETOOTH_EVENT_REMOTE_DEVICE_FOUND,
1032 _bt_free_device_info(remote_dev_info);
1033 } else if (strcasecmp(property, "GattConnected") == 0) {
1034 gboolean gatt_connected = FALSE;
1036 g_variant_get(val, "b", &gatt_connected);
1038 event = gatt_connected ? BLUETOOTH_EVENT_GATT_CONNECTED :
1039 BLUETOOTH_EVENT_GATT_DISCONNECTED;
1041 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1043 _bt_convert_device_path_to_address(path, address);
1045 BT_DBG("gatt_connected: %d", gatt_connected);
1046 BT_DBG("address: %s", address);
1047 param = g_variant_new("(is)", result, address);
1048 /* Send event to application */
1049 _bt_send_event(BT_DEVICE_EVENT,
1053 } else if (strcasecmp(property, "Paired") == 0) {
1054 gboolean paired = FALSE;
1055 bt_remote_dev_info_t *remote_dev_info;
1056 g_variant_get(val, "b", &paired);
1057 _bt_agent_set_canceled(FALSE);
1058 /* BlueZ sends paired signal for each paired device */
1059 /* during activation, We should ignore this, otherwise*/
1060 /* application thinks that a new device got paired */
1061 if (_bt_adapter_get_status() != BT_ACTIVATED) {
1062 BT_DBG("BT is not activated, so ignore this");
1064 g_variant_unref(val);
1068 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1070 _bt_convert_device_path_to_address(path, address);
1072 remote_dev_info = _bt_get_remote_device_info_by_object_path(path);
1073 if (remote_dev_info == NULL) {
1075 g_variant_unref(val);
1080 if (paired == FALSE) {
1081 BT_INFO("Unpaired: %s", address);
1082 __bt_update_remote_cache_devinfo(address, FALSE);
1083 param = g_variant_new("(is)", result, address);
1084 _bt_send_event(BT_ADAPTER_EVENT,
1085 BLUETOOTH_EVENT_BONDED_DEVICE_REMOVED,
1087 #ifdef TIZEN_BT_A2DP_SINK_AUTO_CONNECT
1089 char *last_connected = NULL;
1090 last_connected = vconf_get_str(BT_LAST_CONNECTED_DEVICE);
1091 if (!g_strcmp0(address, last_connected))
1092 _bt_audio_set_auto_connect_device_addr("");
1094 free(last_connected);
1098 char secure_addr[BT_ADDRESS_STRING_SIZE] = { 0 };
1100 _bt_convert_addr_string_to_secure_string(secure_addr, address);
1101 BT_INFO("### Paired: %s", secure_addr);
1102 __bt_update_remote_cache_devinfo(address, TRUE);
1104 if (_bt_is_device_creating() == TRUE) {
1105 BT_DBG("Try to Pair by me");
1106 _bt_free_device_info(remote_dev_info);
1109 g_variant_unref(val);
1112 GVariant *uuids = NULL;
1113 GVariantBuilder *builder = NULL;
1115 builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
1116 for (i = 0; i < remote_dev_info->uuid_count; i++) {
1117 g_variant_builder_add(builder, "s",
1118 remote_dev_info->uuids[i]);
1120 uuids = g_variant_new("as", builder);
1121 g_variant_builder_unref(builder);
1122 GVariant *manufacturer_data = NULL;
1123 manufacturer_data = g_variant_new_from_data(G_VARIANT_TYPE_BYTESTRING,
1124 remote_dev_info->manufacturer_data,
1125 remote_dev_info->manufacturer_data_len,
1129 param = g_variant_new("(isunsbub@asn@ay)", result,
1130 address, remote_dev_info->class,
1131 remote_dev_info->rssi,
1132 remote_dev_info->name,
1133 remote_dev_info->paired,
1134 remote_dev_info->connected,
1135 remote_dev_info->trust,
1137 remote_dev_info->manufacturer_data_len,
1139 _bt_send_event(BT_ADAPTER_EVENT,
1140 BLUETOOTH_EVENT_BONDING_FINISHED,
1143 _bt_free_device_info(remote_dev_info);
1145 } else if (strcasecmp(property, "LegacyPaired") == 0) {
1146 gboolean paired = FALSE;
1147 bt_remote_dev_info_t *remote_dev_info;
1148 unsigned char auth_info[5] = {0, };
1150 if (_bt_adapter_get_status() != BT_ACTIVATED) {
1151 BT_DBG("BT is not activated, so ignore this");
1153 g_variant_unref(val);
1157 g_variant_get(val, "b", &paired);
1158 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1159 BT_DBG("LegacyPaired: %d", paired);
1160 _bt_convert_device_path_to_address(path, address);
1162 remote_dev_info = _bt_get_remote_device_info_by_object_path(path);
1163 if (remote_dev_info == NULL) {
1166 g_variant_unref(val);
1169 if (remote_dev_info->is_alias_set == FALSE) {
1170 /*minimum Size of the samsung specific manufacturer data is greater than 30 */
1171 if ((remote_dev_info->manufacturer_data_len > 30) &&
1172 (remote_dev_info->manufacturer_data[0] == 0x00) &&
1173 (remote_dev_info->manufacturer_data[1] == 0x75)) {
1175 /* 2 samsung (0x00 0x75) + 1 (control and version) + 1 (service ID) +
1176 1 (discovery version) + 1 (associated service ID)
1177 2 (Proxamity and locality) + 2 (Device type and icon) = 10 */
1179 memcpy(auth_info, &(remote_dev_info->manufacturer_data[10]), 5);
1183 BT_DBG("LegacyPairing Failed with %s. Show Error Popup", remote_dev_info->name);
1184 _bt_launch_system_popup(BT_AGENT_EVENT_LEGACY_PAIR_FAILED_FROM_REMOTE,
1185 remote_dev_info->name, auth_info, NULL, NULL, NULL);
1187 _bt_free_device_info(remote_dev_info);
1189 } else if (strcasecmp(property, "Trusted") == 0) {
1190 gboolean trusted = FALSE;
1192 g_variant_get(val, "b", &trusted);
1194 event = trusted ? BLUETOOTH_EVENT_DEVICE_AUTHORIZED :
1195 BLUETOOTH_EVENT_DEVICE_UNAUTHORIZED;
1197 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1199 _bt_convert_device_path_to_address(path, address);
1201 BT_DBG("trusted: %d", trusted);
1202 BT_DBG("address: %s", address);
1203 param = g_variant_new("(is)", result, address);
1204 /* Send event to application */
1205 _bt_send_event(BT_DEVICE_EVENT,
1209 } else if (strcasecmp(property, "TrustedProfiles") == 0) {
1212 g_variant_get(val, "u", &trusted);
1214 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1215 _bt_convert_device_path_to_address(path, address);
1217 BT_DBG("Address: %s, TrustedProfiles: %d", address, trusted);
1218 _bt_send_event(BT_DEVICE_EVENT,
1219 BLUETOOTH_EVENT_SUPPORTED_PROFILE_TRUSTED,
1220 g_variant_new("(isi)", result, address, trusted));
1222 } else if (strcasecmp(property, "IpspConnected") == 0) {
1223 gboolean connected = FALSE;
1225 g_variant_get(val, "b", &connected);
1228 event = connected ? BLUETOOTH_EVENT_IPSP_CONNECTED :
1229 BLUETOOTH_EVENT_IPSP_DISCONNECTED;
1231 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1233 _bt_convert_device_path_to_address(path, address);
1235 BT_DBG("Ipspconnected: %d", connected);
1236 BT_DBG("address: %s", address);
1237 param = g_variant_new("(is)", result, address);
1239 /* Send event to application */
1240 _bt_send_event(BT_DEVICE_EVENT,
1244 } else if (strcasecmp(property, "IpspBtInterfaceInfo") == 0) {
1245 char *ifname = NULL;
1247 g_variant_get(val, "s", &ifname);
1249 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1251 _bt_convert_device_path_to_address(path, address);
1253 BT_DBG("Ipsp BT Interface Name: %s", ifname);
1254 BT_DBG("address: %s", address);
1255 param = g_variant_new("(iss)", result, address, ifname);
1257 /* Send event to application */
1258 _bt_send_event(BT_DEVICE_EVENT,
1259 BLUETOOTH_EVENT_IPSP_INTERFACE_INFO,
1267 static void __bt_media_control_changed_event(GVariant *msg, const char *path)
1270 int result = BLUETOOTH_ERROR_NONE;
1271 GVariantIter value_iter;
1272 char *property = NULL;
1274 GVariant *val = NULL;
1275 GVariant *child = NULL;
1276 bt_remote_dev_info_t *remote_dev_info;
1277 GVariant *param = NULL;
1278 g_variant_iter_init(&value_iter, msg);
1279 while ((child = g_variant_iter_next_value(&value_iter))) {
1280 g_variant_get(child, "{sv}", &property, &val);
1281 BT_INFO("Property %s", property);
1282 if (strcasecmp(property, "Connected") == 0) {
1283 gboolean connected = FALSE;
1285 g_variant_get(val, "b", &connected);
1287 event = connected ? BLUETOOTH_EVENT_AVRCP_CONNECTED :
1288 BLUETOOTH_EVENT_AVRCP_DISCONNECTED;
1290 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1292 _bt_convert_device_path_to_address(path, address);
1294 BT_DBG("connected: %d", connected);
1295 BT_DBG("address: %s", address);
1297 remote_dev_info = _bt_get_remote_device_info(address);
1299 if (remote_dev_info != NULL) {
1300 __bt_device_remote_connected_properties(
1301 remote_dev_info, address, connected);
1302 _bt_free_device_info(remote_dev_info);
1304 param = g_variant_new("(is)", result, address);
1305 /* Send event to application */
1306 _bt_send_event(BT_AVRCP_EVENT,
1312 g_variant_unref(child);
1313 g_variant_unref(val);
1318 int get_alert_level_enum(const char *alert)
1322 if (strcmp(alert, "none") == 0)
1323 lvl = BT_PXP_ALERT_NONE;
1324 else if (strcmp(alert, "mild") == 0)
1325 lvl = BT_PXP_ALERT_MILD;
1326 else if (strcmp(alert, "high") == 0)
1327 lvl = BT_PXP_ALERT_HIGH;
1332 static void _bt_handle_pxp_property_changed_event(GVariant *msg, const char *path, int role)
1334 int result = BLUETOOTH_ERROR_NONE;
1337 GVariantIter value_iter;
1338 char *property = NULL;
1340 GVariant *val = NULL;
1341 GVariant *child = NULL;
1342 GVariant *param = NULL;
1343 g_variant_iter_init(&value_iter, msg);
1346 while ((child = g_variant_iter_next_value(&value_iter))) {
1347 g_variant_get(child, "{sv}", &property, &val);
1348 BT_INFO("Property %s", property);
1350 if ((strcasecmp(property, "LinkLossAlertLevel") == 0) ||
1351 (strcasecmp(property, "ImmediateAlertLevel") == 0)) {
1352 char *alert_str = NULL;
1354 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1355 _bt_convert_device_path_to_address(path, address);
1357 if (strcasecmp(property, "LinkLossAlertLevel") == 0)
1358 service_type = BT_PXP_PROPERTY_LLS;
1360 service_type = BT_PXP_PROPERTY_IAS;
1362 g_variant_get(val, "s", &alert_str);
1364 alert_lvl = get_alert_level_enum(alert_str);
1366 param = g_variant_new("(isiii)", result, address,
1367 role, service_type, alert_lvl);
1369 /* Send event to application */
1370 _bt_send_event(BT_DEVICE_EVENT,
1371 BLUETOOTH_EVENT_PXP_PROPERTY_CHANGED,
1377 g_variant_unref(child);
1378 g_variant_unref(val);
1383 void _bt_handle_property_changed_event(GVariant *msg, const char *object_path)
1385 char *interface_name = NULL;
1386 GVariant *val = NULL;
1388 g_variant_get(msg, "(&s@a{sv}@as)", &interface_name, &val, NULL);
1390 if (strcasecmp(interface_name, BT_ADAPTER_INTERFACE) == 0) {
1391 __bt_adapter_property_changed_event(val,
1393 } else if (strcasecmp(interface_name, BT_DEVICE_INTERFACE) == 0) {
1394 __bt_device_property_changed_event(val, object_path);
1395 } else if (strcasecmp(interface_name, BT_OBEX_TRANSFER_INTERFACE) == 0) {
1396 BT_DBG("BT_OBEX_TRANSFER_INTERFACE");
1397 __bt_obex_property_changed_event(val,
1399 } else if (strcasecmp(interface_name, BT_MEDIA_CONTROL_INTERFACE) == 0) {
1400 __bt_media_control_changed_event(val,
1402 } else if (strcasecmp(interface_name, BT_PLAYER_CONTROL_INTERFACE) == 0) {
1403 _bt_handle_avrcp_control_event(val,
1405 } else if (strcasecmp(interface_name, BT_NETWORK_CLIENT_INTERFACE) == 0) {
1406 BT_DBG("BT_NETWORK_CLIENT_INTERFACE");
1407 _bt_handle_network_client_event(val,
1409 } else if (strcasecmp(interface_name, BT_GATT_CHAR_INTERFACE) == 0) {
1410 __bt_gatt_char_property_changed_event(val,
1412 } else if (strcasecmp(interface_name, BT_PROXIMITY_REPORTER_INTERFACE) == 0) {
1413 BT_DBG("BT_PROXIMITY_REPORTER_INTERFACE");
1414 _bt_handle_pxp_property_changed_event(val,
1415 object_path, BT_PXP_REPORTER_ROLE);
1417 g_variant_unref(val);
1420 void __bt_opc_property_changed_event(GVariant *msg,
1423 GVariantIter value_iter;
1424 char *property = NULL;
1425 GVariant *val = NULL;
1426 GVariant *child = NULL;
1428 g_variant_iter_init(&value_iter, msg);
1429 if ((child = g_variant_iter_next_value(&value_iter))) {
1430 g_variant_get(child, "{sv}", &property, &val);
1431 ret_if(property == NULL);
1433 if (strcasecmp(property, "Status") == 0) {
1434 char *status = NULL;
1435 g_variant_get(val, "s", &status);
1436 BT_DBG("Status is %s", status);
1438 if (strcasecmp(status, "active") == 0)
1439 _bt_obex_client_started(path);
1440 else if (strcasecmp(status, "complete") == 0)
1441 _bt_obex_client_completed(path, TRUE);
1442 else if (strcasecmp(status, "error") == 0)
1443 _bt_obex_client_completed(path, FALSE);
1446 } else if (strcasecmp(property, "Transferred") == 0) {
1447 guint64 transferred = 0;
1448 g_variant_get(val, "t", &transferred);
1450 _bt_obex_client_progress(path, transferred);
1452 BT_DBG("property : [%s]", property);
1455 g_variant_unref(child);
1456 g_variant_unref(val);
1460 void _bt_opc_property_changed_event(GVariant *msg, char *path)
1462 char *interface_name = NULL;
1463 GVariant *value = NULL;
1464 g_variant_get(msg, "(&s@a{sv}@as)", &interface_name, &value, NULL);
1465 BT_INFO("interface_name = %s", interface_name);
1466 if (strcasecmp(interface_name, BT_OBEX_TRANSFER_INTERFACE) == 0) {
1467 __bt_opc_property_changed_event(value,
1470 BT_DBG("interface_name : [%s]", interface_name);
1472 g_variant_unref(value);
1476 void __bt_map_property_changed_event(GVariant *msg,
1480 GVariantIter value_iter;
1481 char *property = NULL;
1482 GVariant *val = NULL;
1483 GVariant *child = NULL;
1485 g_variant_iter_init(&value_iter, msg);
1486 while ((child = g_variant_iter_next_value(&value_iter))) {
1487 g_variant_get(child, "{sv}", &property, &val);
1488 ret_if(property == NULL);
1490 if (strcasecmp(property, "Status") == 0) {
1491 char *status = NULL;
1492 g_variant_get(val, "s", &status);
1493 BT_DBG("Status is %s", status);
1495 if (strcasecmp(status, "active") == 0) {
1496 BT_DBG("EVENT : STARTED");
1497 // currently doing nothing
1498 } else if (strcasecmp(status, "complete") == 0) {
1499 BT_DBG("EVENT : COMPLETED");
1500 _bt_map_on_transfer_finished(path, BLUETOOTH_ERROR_NONE);
1501 } else if (strcasecmp(status, "error") == 0) {
1502 BT_DBG("EVENT : FAILED");
1503 _bt_map_on_transfer_finished(path, BLUETOOTH_ERROR_INTERNAL);
1506 } else if (strcasecmp(property, "Transferred") == 0) {
1507 guint64 transferred = 0;
1508 g_variant_get(val, "t", &transferred);
1510 BT_DBG("EVENT : PROGRESS CALLBACK");
1511 // currently doing nothing - progress callback type is not used
1513 BT_DBG("OTHER EVENT : property : [%s]", property);
1516 g_variant_unref(child);
1517 g_variant_unref(val);
1521 void _bt_map_property_changed_event(GVariant *msg, const char *path)
1523 BT_DBG("Entered _bt_map_property_changed_event");
1524 char *interface_name = NULL;
1525 GVariant *value = NULL;
1526 g_variant_get(msg, "(&s@a{sv}@as)", &interface_name, &value, NULL);
1527 BT_INFO("interface_name = %s", interface_name);
1528 if (strcasecmp(interface_name, BT_OBEX_TRANSFER_INTERFACE) == 0) {
1529 __bt_map_property_changed_event(value,
1532 BT_DBG("interface_name : [%s]", interface_name);
1534 g_variant_unref(value);
1538 void _bt_handle_input_event(GVariant *msg, const char *path)
1540 int result = BLUETOOTH_ERROR_NONE;
1541 gboolean property_flag = FALSE;
1542 GVariantIter value_iter;
1543 char *property = NULL;
1544 GVariant *child = NULL, *val = NULL;
1545 bt_remote_dev_info_t *remote_dev_info;
1546 GVariant *param = NULL;
1547 g_variant_iter_init(&value_iter, msg);
1548 while ((child = g_variant_iter_next_value(&value_iter))) {
1549 g_variant_get(child, "{sv}", &property, &val);
1551 ret_if(property == NULL);
1553 if (strcasecmp(property, "Connected") == 0) {
1554 int event = BLUETOOTH_EVENT_NONE;
1556 g_variant_get(val, "b", &property_flag);
1558 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1560 _bt_convert_device_path_to_address(path, address);
1562 event = (property_flag == TRUE) ?
1563 BLUETOOTH_HID_CONNECTED :
1564 BLUETOOTH_HID_DISCONNECTED;
1565 param = g_variant_new("(is)", result, address);
1566 _bt_send_event(BT_HID_EVENT, event,
1568 /* Check HID connection type (Keyboard or Mouse) and update the status */
1569 remote_dev_info = _bt_get_remote_device_info_by_object_path(path);
1571 if (property_flag == TRUE) {
1572 hid_connected_device_count++;
1573 __bt_set_device_values(TRUE,
1574 VCONFKEY_BT_DEVICE_HID_CONNECTED);
1576 hid_connected_device_count--;
1577 if (hid_connected_device_count == 0)
1578 __bt_set_device_values(FALSE,
1579 VCONFKEY_BT_DEVICE_HID_CONNECTED);
1582 if (remote_dev_info != NULL) {
1583 BT_DBG("HID device class [%x]", remote_dev_info->class);
1584 if (remote_dev_info->class &
1585 BLUETOOTH_DEVICE_MINOR_CLASS_KEY_BOARD) {
1586 __bt_set_device_values(property_flag,
1587 VCONFKEY_BT_DEVICE_HID_KEYBOARD_CONNECTED);
1591 if (remote_dev_info->class &
1592 BLUETOOTH_DEVICE_MINOR_CLASS_POINTING_DEVICE) {
1593 __bt_set_device_values(property_flag,
1594 VCONFKEY_BT_DEVICE_HID_MOUSE_CONNECTED);
1596 _bt_free_device_info(remote_dev_info);
1601 g_variant_unref(val);
1602 g_variant_unref(child);
1606 void _bt_handle_network_server_event(GVariant *msg, const char *member)
1608 int result = BLUETOOTH_ERROR_NONE;
1609 char *address = NULL;
1610 char *device = NULL;
1611 GVariant *param = NULL;
1612 ret_if(member == NULL);
1613 if (strcasecmp(member, "PeerConnected") == 0) {
1614 g_variant_get(msg, "(ss)", &device, &address);
1616 __bt_set_device_values(TRUE,
1617 VCONFKEY_BT_DEVICE_PAN_CONNECTED);
1618 param = g_variant_new("(iss)", result, device, address);
1619 _bt_send_event(BT_NETWORK_EVENT, BLUETOOTH_EVENT_NETWORK_SERVER_CONNECTED,
1623 nap_connected_device_count++;
1624 } else if (strcasecmp(member, "PeerDisconnected") == 0) {
1625 g_variant_get(msg, "(ss)", &device, &address);
1626 nap_connected_device_count--;
1627 if (nap_connected_device_count == 0)
1628 __bt_set_device_values(FALSE,
1629 VCONFKEY_BT_DEVICE_PAN_CONNECTED);
1630 param = g_variant_new("(iss)", result, device, address);
1631 _bt_send_event(BT_NETWORK_EVENT, BLUETOOTH_EVENT_NETWORK_SERVER_DISCONNECTED,
1638 void _bt_handle_network_client_event(GVariant *msg,
1643 int result = BLUETOOTH_ERROR_NONE;
1644 gboolean property_flag = FALSE;
1645 char *property = NULL;
1646 GVariant *val = NULL;
1647 GVariantIter value_iter;
1648 GVariant *param = NULL;
1649 g_variant_iter_init(&value_iter, msg);
1650 while ((g_variant_iter_loop(&value_iter, "{sv}", &property, &val))) {
1651 if (strcasecmp(property, "Connected") == 0) {
1652 int event = BLUETOOTH_EVENT_NONE;
1655 g_variant_get(val, "b", &property_flag);
1656 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1658 _bt_convert_device_path_to_address(path, address);
1660 BT_DBG("property_flag %d", property_flag);
1661 if (property_flag == TRUE) {
1662 event = BLUETOOTH_EVENT_NETWORK_CONNECTED;
1663 nap_connected_device_count++;
1664 __bt_set_device_values(TRUE,
1665 VCONFKEY_BT_DEVICE_PAN_CONNECTED);
1667 event = BLUETOOTH_EVENT_NETWORK_DISCONNECTED;
1668 nap_connected_device_count--;
1669 if (nap_connected_device_count == 0)
1670 __bt_set_device_values(FALSE,
1671 VCONFKEY_BT_DEVICE_PAN_CONNECTED);
1673 param = g_variant_new("(is)", result, address);
1674 _bt_send_event(BT_NETWORK_EVENT, event,
1683 void __bt_gatt_char_property_changed_event(GVariant *msg,
1686 GVariantIter value_iter;
1687 char *property = NULL;
1688 GVariant *val = NULL;
1689 g_variant_iter_init(&value_iter, msg);
1690 while ((g_variant_iter_loop(&value_iter, "{sv}", &property, &val))) {
1691 BT_INFO("Property %s", property);
1693 ret_if(property == NULL);
1695 if (strcasecmp(property, "Notifying") == 0) {
1696 gboolean property_flag = FALSE;
1697 g_variant_get(val, "b", &property_flag);
1698 if (property_flag == TRUE)
1699 BT_DBG("notifying is enabled");
1701 BT_DBG("notifying is disabled");
1706 void _bt_handle_gatt_event(GVariant *msg, const char *member, const char *path)
1708 ret_if(path == NULL);
1709 if (strcasecmp(member, "GattValueChanged") == 0) {
1710 /* Check TDS seekers waiting for Indication */
1711 _bt_tds_check_indication(path, msg);
1713 BT_INFO("Unhandled event");
1717 void _bt_handle_device_event(GVariant *msg, const char *member, const char *path)
1720 int result = BLUETOOTH_ERROR_NONE;
1722 char *dev_name = NULL;
1723 const char *property = NULL;
1724 GVariant *param = NULL;
1725 char secure_address[BT_ADDRESS_STRING_SIZE] = { 0 };
1726 ret_if(path == NULL);
1728 if (strcasecmp(member, "PropertyChanged") == 0) {
1730 g_variant_get(msg, "(s)", &property);
1732 ret_if(property == NULL);
1734 if (strcasecmp(property, "GattConnected") == 0) {
1735 gboolean connected = FALSE;
1737 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1739 _bt_convert_device_path_to_address(path, address);
1740 g_variant_get(msg, "(b)", &connected);
1742 event = connected ? BLUETOOTH_EVENT_GATT_CONNECTED :
1743 BLUETOOTH_EVENT_GATT_DISCONNECTED;
1744 param = g_variant_new("(is)", result, address);
1745 _bt_send_event(BT_DEVICE_EVENT,
1749 } else if (strcasecmp(property, "Paired") == 0) {
1750 gboolean paired = FALSE;
1751 bt_remote_dev_info_t *remote_dev_info;
1752 g_variant_get(msg, "(b)", &paired);
1754 ret_if(paired == FALSE);
1756 /* BlueZ sends paired signal for each paired device */
1757 /* during activation, We should ignore this, otherwise*/
1758 /* application thinks that a new device got paired */
1759 if (_bt_adapter_get_status() != BT_ACTIVATED) {
1760 BT_DBG("BT is not activated, so ignore this");
1764 if (_bt_is_device_creating() == TRUE) {
1765 BT_DBG("Try to Pair by me");
1769 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1771 _bt_convert_device_path_to_address(path, address);
1773 remote_dev_info = _bt_get_remote_device_info_by_object_path(path);
1774 if (remote_dev_info == NULL) {
1778 GVariant *uuids = NULL;
1779 GVariantBuilder *builder = NULL;
1781 builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
1782 for (i = 0; i < remote_dev_info->uuid_count; i++) {
1783 g_variant_builder_add(builder, "s",
1784 remote_dev_info->uuids[i]);
1786 uuids = g_variant_new("as", builder);
1787 g_variant_builder_unref(builder);
1788 GVariant *manufacturer_data = NULL;
1789 manufacturer_data = g_variant_new_from_data(
1790 G_VARIANT_TYPE_BYTESTRING,
1791 remote_dev_info->manufacturer_data,
1792 remote_dev_info->manufacturer_data_len,
1794 param = g_variant_new("(isunsbub@asn@ay)", result,
1796 remote_dev_info->class,
1797 remote_dev_info->rssi,
1798 remote_dev_info->name,
1799 remote_dev_info->paired,
1800 remote_dev_info->connected,
1801 remote_dev_info->trust,
1803 remote_dev_info->manufacturer_data_len,
1805 _bt_send_event(BT_ADAPTER_EVENT,
1806 BLUETOOTH_EVENT_BONDING_FINISHED,
1808 _bt_free_device_info(remote_dev_info);
1811 } else if (strcasecmp(property, "UUIDs") == 0) {
1812 /* Once we get the updated uuid information after
1813 * reverse service search, update it to application */
1815 bt_remote_dev_info_t *remote_dev_info;
1817 ret_if(_bt_is_device_creating() == TRUE);
1819 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1821 _bt_convert_device_path_to_address(path, address);
1823 remote_dev_info = _bt_get_remote_device_info_by_object_path(path);
1824 if (remote_dev_info == NULL) {
1829 BT_DBG("UUID's count = %d", remote_dev_info->uuid_count);
1830 if (remote_dev_info->paired && remote_dev_info->uuid_count) {
1831 GVariant *uuids = NULL;
1832 GVariantBuilder *builder = NULL;
1834 builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
1835 for (i = 0; i < remote_dev_info->uuid_count; i++) {
1836 g_variant_builder_add(builder, "s",
1837 remote_dev_info->uuids[i]);
1839 uuids = g_variant_new("as", builder);
1840 g_variant_builder_unref(builder);
1841 GVariant *manufacture_data = g_variant_new_from_data((const GVariantType *)"ay",
1842 remote_dev_info->manufacturer_data, remote_dev_info->manufacturer_data_len,
1845 param = g_variant_new("(isunsbub@asn@ay)", result,
1846 address, remote_dev_info->class,
1847 remote_dev_info->rssi,
1848 remote_dev_info->name,
1849 remote_dev_info->paired,
1850 remote_dev_info->connected,
1851 remote_dev_info->trust,
1853 remote_dev_info->manufacturer_data_len,
1855 _bt_send_event(BT_ADAPTER_EVENT,
1856 BLUETOOTH_EVENT_SERVICE_SEARCHED,
1860 _bt_free_device_info(remote_dev_info);
1863 } else if (strcasecmp(member, "DeviceConnected") == 0) {
1864 unsigned char addr_type = 0;
1866 g_variant_get(msg, "(y)", &addr_type);
1868 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1870 _bt_convert_device_path_to_address(path, address);
1871 dev_name = _bt_get_bonded_device_name(address);
1873 _bt_convert_addr_string_to_secure_string(secure_address, address);
1874 BT_INFO("Address : %s Type : %d", secure_address, addr_type);
1875 BT_ERR_C("### Connected [%s] [%s]", !addr_type ? "BREDR" : "LE",
1876 !addr_type ? dev_name : secure_address);
1879 _bt_logging_connection(TRUE, addr_type);
1880 param = g_variant_new("(isy)", result, address, addr_type);
1881 /*Send event to application*/
1882 _bt_send_event(BT_DEVICE_EVENT,
1883 BLUETOOTH_EVENT_DEVICE_CONNECTED,
1886 } else if (strcasecmp(member, "Disconnected") == 0) {
1887 unsigned char disc_reason = 0;
1888 unsigned char addr_type = 0;
1889 char *dev_name = NULL;
1890 gboolean sending = FALSE;
1892 g_variant_get(msg, "(yys)", &addr_type, &disc_reason, &dev_name);
1894 result = disc_reason;
1896 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1898 _bt_convert_device_path_to_address(path, address);
1900 /* 0x00 BDADDR_BRDER
1901 0x01 BDADDR_LE_PUBLIC
1902 0x02 BDADDR_LE_RANDOM */
1903 _bt_convert_addr_string_to_secure_string(secure_address, address);
1904 BT_INFO("Address : %s Type : %d", secure_address, addr_type);
1905 BT_ERR_C("### Disconnected [%s] [%d : %s] [%s]", !addr_type ? "BREDR" : "LE",
1906 disc_reason, _bt_convert_disc_reason_to_string(disc_reason),
1907 !addr_type ? dev_name : secure_address);
1910 _bt_headset_set_local_connection(FALSE);
1911 _bt_logging_connection(FALSE, addr_type);
1914 #ifdef TIZEN_BT_A2DP_SINK_AUTO_CONNECT
1916 int bt_device_state = VCONFKEY_BT_DEVICE_NONE;
1918 if (vconf_get_int(VCONFKEY_BT_DEVICE, &bt_device_state) != 0)
1919 BT_ERR("vconf_get_int failed");
1921 BT_INFO("conn_state[0x%x], adapter_state [%d]",
1922 bt_device_state, _bt_adapter_get_status());
1924 if (disc_reason == BLUETOOTH_ERROR_CONNECTION_TIMEOUT) {
1925 _bt_audio_start_auto_connect(TRUE);
1926 } else if (bt_device_state &
1927 VCONFKEY_BT_DEVICE_A2DP_SOURCE_CONNECTED) {
1928 BT_INFO("Disconnected due to turning BT off. Skip a address");
1930 char *last_connected = NULL;
1931 last_connected = vconf_get_str(BT_LAST_CONNECTED_DEVICE);
1932 if (!g_strcmp0(address, last_connected))
1933 _bt_audio_set_auto_connect_device_addr("");
1935 free(last_connected);
1940 /*Check for any OPP transfer on the device and cancel
1943 _bt_obex_check_pending_transfer(address);
1944 _bt_opp_client_is_sending(&sending);
1945 if (sending == TRUE)
1946 _bt_opp_client_check_pending_transfer(address);
1947 /* TODO: MAP? see above */
1949 param = g_variant_new("(isy)", result, address, addr_type);
1950 _bt_send_event(BT_DEVICE_EVENT,
1951 BLUETOOTH_EVENT_DEVICE_DISCONNECTED,
1954 } else if (strcasecmp(member, "ProfileStateChanged") == 0) {
1956 char *profile_uuid = NULL;
1957 bt_headset_wait_t *wait_list;
1958 bluetooth_device_address_t bd_addr;
1960 g_variant_get(msg, "(si)", &profile_uuid, &state);
1962 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1964 _bt_convert_device_path_to_address(path, address);
1965 _bt_convert_addr_string_to_type(bd_addr.addr, address);
1967 _bt_convert_addr_string_to_secure_string(secure_address, address);
1968 BT_DBG("Address: %s", secure_address);
1969 BT_DBG("Profile UUID: %s", profile_uuid);
1970 BT_DBG("State: %d", state);
1972 if ((strcmp(profile_uuid, A2DP_SINK_UUID) == 0) &&
1973 (state == BT_PROFILE_STATE_CONNECTED)) {
1975 int event = BLUETOOTH_EVENT_AV_CONNECTED;
1976 #ifndef TIZEN_BT_DUAL_HEADSET_CONNECT
1977 bluetooth_device_address_t device_address;
1978 char connected_address[BT_ADDRESS_STRING_SIZE + 1];
1981 bt_headset_wait_t *wait_list;
1982 guint restricted = 0x0;
1984 __bt_set_device_values(TRUE,
1985 VCONFKEY_BT_DEVICE_A2DP_HEADSET_CONNECTED);
1987 __bt_connection_manager_set_state(address, event);
1989 _bt_get_restrict_profile(&bd_addr, RESTRICTED_PROFILE_HFP_HS, &restricted);
1991 if (_bt_headset_get_local_connection() == FALSE) {
1992 if (restricted == 0x0) /* not restricted*/
1993 _bt_start_timer_for_connection(address, BT_AUDIO_HSP);
1995 /* Connection Started from local device therefore no need to
1996 * intiate connection for pending profile */
1997 _bt_headset_set_local_connection(FALSE);
1999 param = g_variant_new("(is)", result, address);
2000 _bt_send_event(BT_HEADSET_EVENT, event,
2002 #ifdef TIZEN_BT_DUAL_HEADSET_CONNECT
2003 _bt_check_already_connected_headset(BT_AUDIO_A2DP,
2006 connected = _bt_is_headset_type_connected(BT_AUDIO_A2DP,
2009 if (g_strcmp0(connected_address, address) != 0) {
2010 _bt_convert_addr_string_to_type(
2011 device_address.addr,
2013 _bt_audio_disconnect(0, BT_AUDIO_A2DP,
2014 &device_address, NULL);
2018 _bt_add_headset_to_list(BT_AUDIO_A2DP,
2019 BT_STATE_CONNECTED, address);
2021 wait_list = _bt_get_audio_wait_data();
2022 if (wait_list != NULL &&
2023 (g_strcmp0(wait_list->address, address) == 0))
2024 _bt_rel_wait_data();
2026 } else if ((strcmp(profile_uuid, A2DP_SINK_UUID) == 0) &&
2027 (state == BT_PROFILE_STATE_DISCONNECTED)) {
2029 int event = BLUETOOTH_EVENT_AV_DISCONNECTED;
2031 if (!_bt_is_service_connected(address, BT_AUDIO_A2DP)) {
2033 g_free(profile_uuid);
2037 __bt_set_device_values(FALSE,
2038 VCONFKEY_BT_DEVICE_A2DP_HEADSET_CONNECTED);
2040 __bt_connection_manager_set_state(address, event);
2041 param = g_variant_new("(is)", result, address);
2042 _bt_send_event(BT_HEADSET_EVENT, event,
2044 /* Remove data from the connected list */
2045 _bt_remove_headset_from_list(BT_AUDIO_A2DP, address);
2046 wait_list = _bt_get_audio_wait_data();
2048 if (wait_list == NULL) {
2050 g_free(profile_uuid);
2054 if (((wait_list->type == BT_AUDIO_ALL) &&
2055 (wait_list->ag_flag == TRUE)) ||
2056 (wait_list->type == BT_AUDIO_A2DP) ||
2057 (wait_list->disconnection_type == BT_AUDIO_A2DP)) {
2058 bluetooth_device_address_t device_address;
2059 _bt_convert_addr_string_to_type(
2060 device_address.addr,
2061 wait_list->address);
2063 _bt_audio_connect(wait_list->req_id,
2068 } else if (strcmp(profile_uuid, AVRCP_TARGET_UUID) == 0) {
2070 if (state == BT_PROFILE_STATE_CONNECTED) {
2071 int event = BLUETOOTH_EVENT_AVRCP_CONTROL_CONNECTED;
2072 char connected_address[BT_ADDRESS_STRING_SIZE + 1];
2073 bluetooth_device_address_t device_address;
2075 param = g_variant_new("(is)", result, address);
2076 _bt_send_event(BT_AVRCP_CONTROL_EVENT, event,
2078 connected = _bt_is_headset_type_connected(
2082 if (g_strcmp0(connected_address,
2084 _bt_convert_addr_string_to_type(
2085 device_address.addr,
2087 _bt_audio_disconnect(0,
2089 &device_address, NULL);
2092 BT_DBG("device Path: %s", path);
2093 _bt_add_headset_to_list(BT_AVRCP,
2094 BT_STATE_CONNECTED, address);
2095 } else if (state == BT_PROFILE_STATE_DISCONNECTED) {
2096 int event = BLUETOOTH_EVENT_AVRCP_CONTROL_DISCONNECTED;
2097 param = g_variant_new("(is)", result, address);
2098 _bt_send_event(BT_AVRCP_CONTROL_EVENT, event,
2100 /* Remove data from the connected list */
2101 _bt_remove_headset_from_list(BT_AVRCP, address);
2103 } else if (strcasecmp(profile_uuid, A2DP_SOURCE_UUID) == 0) {
2104 if (state == BT_PROFILE_STATE_CONNECTED) {
2105 int event = BLUETOOTH_EVENT_AV_SOURCE_CONNECTED;
2106 BT_INFO("A2DP Source is connected");
2107 #ifdef TIZEN_BT_A2DP_SINK_ENABLE
2108 __bt_set_device_values(TRUE,
2109 VCONFKEY_BT_DEVICE_A2DP_SOURCE_CONNECTED);
2112 #ifdef TIZEN_BT_A2DP_SINK_AUTO_CONNECT
2113 _bt_audio_set_auto_connect_device_addr(address);
2114 _bt_audio_stop_auto_connect();
2116 _bt_add_headset_to_list(BT_AUDIO_A2DP_SOURCE,
2117 BT_STATE_CONNECTED, address);
2118 _bt_send_event(BT_A2DP_SOURCE_EVENT, event,
2119 g_variant_new("(is)", result, address));
2120 } else if (state == BT_PROFILE_STATE_DISCONNECTED) {
2121 int event = BLUETOOTH_EVENT_AV_SOURCE_DISCONNECTED;
2122 BT_INFO("A2DP Source Disconnected");
2123 #ifdef TIZEN_BT_A2DP_SINK_ENABLE
2124 __bt_set_device_values(FALSE,
2125 VCONFKEY_BT_DEVICE_A2DP_SOURCE_CONNECTED);
2127 _bt_remove_headset_from_list(BT_AUDIO_A2DP_SOURCE, address);
2128 _bt_send_event(BT_A2DP_SOURCE_EVENT, event,
2129 g_variant_new("(is)", result, address));
2131 wait_list = _bt_get_audio_wait_data();
2132 if (wait_list && wait_list->type == BT_AUDIO_A2DP_SOURCE) {
2133 bluetooth_device_address_t device_address;
2134 _bt_convert_addr_string_to_type(
2135 device_address.addr,
2136 wait_list->address);
2138 _bt_audio_connect(wait_list->req_id,
2142 /* Now free the wait list */
2143 _bt_rel_wait_data();
2146 } else if ((strcmp(profile_uuid, HID_UUID) == 0) &&
2147 ((state == BT_PROFILE_STATE_CONNECTED) ||
2148 (state == BT_PROFILE_STATE_DISCONNECTED))) {
2150 if (state == BT_PROFILE_STATE_CONNECTED)
2151 event = BLUETOOTH_HID_CONNECTED;
2153 event = BLUETOOTH_HID_DISCONNECTED;
2154 param = g_variant_new("(is)", result, address);
2155 _bt_send_event(BT_HID_EVENT, event,
2158 /* Set the vconf value for device */
2159 if (state == BT_PROFILE_STATE_CONNECTED) {
2160 hid_connected_device_count++;
2161 __bt_set_device_values(TRUE,
2162 VCONFKEY_BT_DEVICE_HID_CONNECTED);
2164 hid_connected_device_count--;
2165 if (hid_connected_device_count == 0)
2166 __bt_set_device_values(FALSE,
2167 VCONFKEY_BT_DEVICE_HID_CONNECTED);
2169 } else if (strcmp(profile_uuid, HID_DEVICE_UUID) == 0) {
2170 if (state == BT_PROFILE_STATE_CONNECTED) {
2172 event = BLUETOOTH_HID_DEVICE_CONNECTED;
2173 param = g_variant_new("(is)", result, address);
2174 _bt_send_event(BT_HID_DEVICE_EVENT, event,
2176 } else if (state == BT_PROFILE_STATE_DISCONNECTED) {
2177 event = BLUETOOTH_HID_DEVICE_DISCONNECTED;
2178 param = g_variant_new("(is)", result, address);
2179 _bt_send_event(BT_HID_DEVICE_EVENT, event,
2184 g_free(profile_uuid);
2185 } else if (strcasecmp(member, "AdvReport") == 0) {
2187 bt_remote_le_dev_info_t *le_dev_info = NULL;
2188 char *buffer = NULL;
2190 bt_le_adv_info_t *adv_info = NULL;
2191 GVariant *value = NULL;
2192 ret_if(_bt_is_le_scanning() == FALSE);
2194 le_dev_info = g_malloc0(sizeof(bt_remote_le_dev_info_t));
2196 g_variant_get(msg, "(syyii@ay)", &le_dev_info->address,
2197 &le_dev_info->addr_type,
2198 &le_dev_info->adv_type,
2200 &le_dev_info->adv_data_len,
2203 if (value == NULL) {
2204 _bt_free_le_device_info(le_dev_info);
2208 _bt_convert_device_path_to_address(path, le_dev_info->address);
2210 buffer_len = g_variant_get_size(value);
2212 buffer = (char *)g_variant_get_data(value);
2214 le_dev_info->adv_data = g_memdup(buffer, buffer_len);
2215 if (le_dev_info->adv_data == NULL &&
2216 le_dev_info->adv_type != BT_LE_ADV_SCAN_RSP) {
2217 _bt_free_le_device_info(le_dev_info);
2218 g_variant_unref(value);
2222 if (_bt_get_le_scan_type() == BT_LE_PASSIVE_SCAN) {
2223 _bt_send_scan_result_event(le_dev_info, NULL);
2224 _bt_free_le_device_info(le_dev_info);
2225 g_variant_unref(value);
2229 if (le_dev_info->adv_type != BT_LE_ADV_SCAN_RSP) { /* ADV_IND */
2230 adv_info = g_malloc0(sizeof(bt_le_adv_info_t));
2231 adv_info->addr = g_strdup(le_dev_info->address);
2232 adv_info->addr_type = le_dev_info->addr_type;
2233 adv_info->rssi = le_dev_info->rssi;
2234 adv_info->data_len = le_dev_info->adv_data_len;
2235 adv_info->data = g_malloc0(le_dev_info->adv_data_len);
2236 memcpy(adv_info->data, le_dev_info->adv_data,
2237 le_dev_info->adv_data_len);
2239 if (__bt_add_adv_ind_info(adv_info) == 0) {
2240 adv_info->timer_id = g_timeout_add(1000,
2241 (GSourceFunc)__bt_adv_scan_req_timeout_cb, (void*)adv_info);
2243 } else { /* SCAN_RSP */
2244 adv_info = __bt_get_adv_ind_info(le_dev_info->address);
2246 _bt_send_scan_result_event(le_dev_info, adv_info);
2247 __bt_del_adv_ind_info(le_dev_info->address);
2250 _bt_free_le_device_info(le_dev_info);
2251 g_variant_unref(value);
2252 } else if (strcasecmp(member, "LEDataLengthChanged") == 0) {
2253 guint16 tx_octets = 0;
2254 guint16 tx_time = 0;
2255 guint16 rx_octets = 0;
2256 guint16 rx_time = 0;
2258 g_variant_get(msg, "(qqqq)",
2259 &tx_octets, &tx_time, &rx_octets, &rx_time);
2261 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
2262 _bt_convert_device_path_to_address(path, address);
2264 param = g_variant_new("(isqqqq)", result, address, tx_octets, tx_time,
2265 rx_octets, rx_time);
2266 /* Send event to application */
2267 _bt_send_event(BT_DEVICE_EVENT,
2268 BLUETOOTH_EVENT_LE_DATA_LENGTH_CHANGED, param);
2270 } else if (strcasecmp(member, "IpspStateChanged") == 0) {
2271 gboolean connected = FALSE;
2272 char *ifname = NULL;
2273 GVariant *ipsp_param = NULL;
2275 g_variant_get(msg, "(bs)", &connected, &ifname);
2277 event = connected ? BLUETOOTH_EVENT_IPSP_CONNECTED :
2278 BLUETOOTH_EVENT_IPSP_DISCONNECTED;
2280 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
2281 _bt_convert_device_path_to_address(path, address);
2283 BT_DBG("Ipsp BT Interface Name: %s", ifname);
2284 BT_DBG("address: %s", address);
2285 param = g_variant_new("(iss)", result, address, ifname);
2286 ipsp_param = g_variant_new("(ss)", ifname, address);
2289 GDBusProxy *ipsp_proxy;
2291 BT_DBG("IPSP connected, Set Ipv6 Addr");
2292 ipsp_proxy = _bt_get_ipsp_proxy();
2293 if (ipsp_proxy == NULL) {
2294 BT_ERR("can not get ipsp proxy");
2298 g_dbus_proxy_call(ipsp_proxy, "SetIpv6Addr",
2299 ipsp_param, G_DBUS_CALL_FLAGS_NONE,
2300 -1, NULL, NULL, NULL);
2302 BT_DBG("IPSP disconnected");
2303 ipsp_proxy = _bt_get_ipsp_proxy();
2304 if (ipsp_proxy == NULL) {
2305 BT_ERR("can not get ipsp proxy");
2309 g_dbus_proxy_call(ipsp_proxy, "DisableIpsp",
2310 NULL, G_DBUS_CALL_FLAGS_NONE,
2311 -1, NULL, NULL, NULL);
2314 /* Send event to application */
2315 _bt_send_event(BT_DEVICE_EVENT,
2319 } else if (strcasecmp(member, "AttMtuChanged") == 0) {
2320 int result = BLUETOOTH_ERROR_NONE;
2324 g_variant_get(msg, "(q)", &mtu);
2326 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
2328 _bt_convert_device_path_to_address(path, address);
2329 _bt_convert_addr_string_to_secure_string(secure_address, address);
2330 BT_DBG("Address : %s MTU changed : %d", secure_address, mtu);
2332 param = g_variant_new("(isqy)",
2338 /* Send the event to application */
2339 _bt_send_event(BT_DEVICE_EVENT,
2340 BLUETOOTH_EVENT_GATT_ATT_MTU_CHANGED,
2347 void __bt_set_audio_values(gboolean connected, char *address)
2350 int bt_device_state = VCONFKEY_BT_DEVICE_NONE;
2352 /* Set the headset name */
2353 if (connected == TRUE)
2354 name = _bt_get_bonded_device_name(address);
2356 name = g_strdup("");
2358 if (vconf_set_str(VCONFKEY_BT_HEADSET_NAME, name) != 0)
2359 BT_ERR("vconf_set_str failed");
2363 /* Set the headset state */
2364 if (vconf_get_int(VCONFKEY_BT_DEVICE, &bt_device_state) != 0)
2365 BT_ERR("vconf_get_int failed");
2367 #ifdef TIZEN_SUPPORT_DUAL_HF
2368 if ((connected == TRUE) &&
2369 (FALSE == __bt_is_companion_device(address))) {
2370 bt_device_state |= VCONFKEY_BT_DEVICE_HEADSET_CONNECTED;
2371 } else if ((bt_device_state & VCONFKEY_BT_DEVICE_HEADSET_CONNECTED) &&
2372 (FALSE == __bt_is_companion_device(address))) {
2373 bt_device_state ^= VCONFKEY_BT_DEVICE_HEADSET_CONNECTED;
2376 if (connected == TRUE)
2377 bt_device_state |= VCONFKEY_BT_DEVICE_HEADSET_CONNECTED;
2378 else if (bt_device_state & VCONFKEY_BT_DEVICE_HEADSET_CONNECTED)
2379 bt_device_state ^= VCONFKEY_BT_DEVICE_HEADSET_CONNECTED;
2382 if (vconf_set_int(VCONFKEY_BT_DEVICE,
2383 bt_device_state) != 0) {
2384 BT_ERR("vconf_set_int failed");
2388 void _bt_handle_headset_event(GVariant *msg, const char *path)
2390 int result = BLUETOOTH_ERROR_NONE;
2391 gboolean property_flag = FALSE;
2392 char *property = NULL;
2393 GVariant *value = NULL;
2394 GVariant *param = NULL;
2395 g_variant_get(msg, "(sv)", &property, &value);
2396 bluetooth_device_address_t bd_addr;
2398 ret_if(property == NULL);
2400 BT_DBG("Property = %s \n", property);
2401 /* We allow only 1 headset connection (HSP or HFP)*/
2402 if (strcasecmp(property, "Connected") == 0) {
2403 int event = BLUETOOTH_EVENT_NONE;
2404 bt_headset_wait_t *wait_list;
2406 guint restricted = 0x0;
2407 g_variant_get(value, "b", &property_flag);
2409 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
2411 _bt_convert_device_path_to_address(path, address);
2412 _bt_convert_addr_string_to_type(bd_addr.addr, address);
2414 if (property_flag == TRUE) {
2415 event = BLUETOOTH_EVENT_AG_CONNECTED;
2416 _bt_get_restrict_profile(&bd_addr, RESTRICTED_PROFILE_A2DP, &restricted);
2418 if (_bt_headset_get_local_connection() == FALSE) {
2419 if (restricted == 0x0) /* not restricted*/
2420 _bt_start_timer_for_connection(address, BT_AUDIO_A2DP);
2422 _bt_headset_set_local_connection(FALSE);
2426 event = BLUETOOTH_EVENT_AG_DISCONNECTED;
2428 previous_state = _bt_get_device_state_from_list(BT_AUDIO_HSP, address);
2429 if (previous_state == BT_STATE_DISCONNECTING)
2430 _bt_send_hf_local_term_event(address);
2432 /* Set the State machine here */
2433 __bt_connection_manager_set_state(address, event);
2434 __bt_set_audio_values(property_flag, address);
2435 param = g_variant_new("(is)", result, address);
2436 _bt_send_event(BT_HEADSET_EVENT, event,
2439 if (event == BLUETOOTH_EVENT_AG_DISCONNECTED) {
2440 /* Remove data from the connected list */
2441 _bt_remove_headset_from_list(BT_AUDIO_HSP, address);
2443 wait_list = _bt_get_audio_wait_data();
2444 if (wait_list == NULL) {
2449 bluetooth_device_address_t device_address;
2451 _bt_set_audio_wait_data_flag(TRUE);
2453 _bt_convert_addr_string_to_type(device_address.addr,
2454 wait_list->address);
2455 _bt_audio_connect(wait_list->req_id, wait_list->type,
2456 &device_address, NULL);
2457 _bt_rel_wait_data();
2458 } else if (event == BLUETOOTH_EVENT_AG_CONNECTED) {
2459 /* Add data to the connected list */
2460 _bt_add_headset_to_list(BT_AUDIO_HSP,
2461 BT_STATE_CONNECTED, address);
2463 wait_list = _bt_get_audio_wait_data();
2464 if (wait_list != NULL &&
2465 (g_strcmp0(wait_list->address, address) == 0))
2466 _bt_rel_wait_data();
2468 BT_INFO("Check A2DP pending connect");
2469 _bt_audio_check_pending_connect();
2472 } else if (strcasecmp(property, "State") == 0) {
2475 g_variant_get(value, "s", &state);
2477 /* This code assumes we support only 1 headset connection */
2478 /* Need to use the headset list, if we support multi-headsets */
2479 if (strcasecmp(state, "Playing") == 0) {
2480 BT_DBG("Playing: Sco Connected");
2481 } else if (strcasecmp(state, "connected") == 0 ||
2482 strcasecmp(state, "disconnected") == 0) {
2483 BT_DBG("connected/disconnected: Sco Disconnected");
2485 BT_ERR("Not handled state - %s", state);
2490 } else if (strcasecmp(property, "SpeakerGain") == 0) {
2494 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
2496 _bt_convert_device_path_to_address(path, address);
2498 spkr_gain = g_variant_get_uint16(value);
2500 BT_DBG("spkr_gain: %d", spkr_gain);
2502 param = g_variant_new("(i&sq)", result, address, spkr_gain);
2503 _bt_send_event(BT_HEADSET_EVENT, BLUETOOTH_EVENT_AG_SPEAKER_GAIN,
2507 } else if (strcasecmp(property, "MicrophoneGain") == 0) {
2511 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
2513 _bt_convert_device_path_to_address(path, address);
2515 mic_gain = g_variant_get_uint16(value);
2517 param = g_variant_new("(i&sq)", result, address, mic_gain);
2518 _bt_send_event(BT_HEADSET_EVENT, BLUETOOTH_EVENT_AG_MIC_GAIN,
2525 g_variant_unref(value);
2528 void _bt_handle_sink_event(GVariant *msg, const char *path)
2530 GVariantIter value_iter;
2531 char *property = NULL;
2533 bt_headset_wait_t *wait_list;
2535 GVariant *child = NULL;
2536 GVariant *val = NULL;
2537 GVariant *param = NULL;
2538 g_variant_iter_init(&value_iter, msg);
2539 while ((child = g_variant_iter_next_value(&value_iter))) {
2541 g_variant_get(child, "{sv}", &property, &val);
2543 ret_if(property == NULL);
2545 BT_DBG("Property = %s \n", property);
2548 if (strcasecmp(property, "State") == 0) {
2549 int result = BLUETOOTH_ERROR_NONE;
2552 g_variant_get(val, "s", &value);
2553 BT_DBG("value: %s", value);
2555 if (g_strcmp0(value, "disconnected") == 0) {
2558 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
2560 _bt_convert_device_path_to_address(path, address);
2562 __bt_set_device_values(FALSE,
2563 VCONFKEY_BT_DEVICE_A2DP_HEADSET_CONNECTED);
2564 param = g_variant_new("(is)", result, address);
2565 _bt_send_event(BT_HEADSET_EVENT,
2566 BLUETOOTH_EVENT_AV_DISCONNECTED,
2569 /* Remove data from the connected list */
2570 _bt_remove_headset_from_list(BT_AUDIO_A2DP, address);
2571 wait_list = _bt_get_audio_wait_data();
2572 if (wait_list == NULL) {
2575 g_variant_unref(val);
2576 g_variant_unref(child);
2581 if (((wait_list->type == BT_AUDIO_ALL) &&
2582 (wait_list->ag_flag == TRUE)) ||
2583 (wait_list->type == BT_AUDIO_A2DP) ||
2584 (wait_list->disconnection_type == BT_AUDIO_A2DP)) {
2585 bluetooth_device_address_t device_address;
2586 _bt_convert_addr_string_to_type(
2587 device_address.addr,
2588 wait_list->address);
2590 _bt_audio_connect(wait_list->req_id,
2596 } else if (strcasecmp(value, "Connected") == 0) {
2598 char connected_address[BT_ADDRESS_STRING_SIZE + 1];
2599 bluetooth_device_address_t device_address;
2602 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
2604 _bt_convert_device_path_to_address(path, address);
2606 __bt_set_device_values(TRUE,
2607 VCONFKEY_BT_DEVICE_A2DP_HEADSET_CONNECTED);
2608 param = g_variant_new("(is)", result, address);
2609 _bt_send_event(BT_HEADSET_EVENT,
2610 BLUETOOTH_EVENT_AV_CONNECTED,
2612 /* Check for existing Media device to disconnect */
2613 connected = _bt_is_headset_type_connected(BT_AUDIO_A2DP,
2616 /* Match connected device address */
2617 if (g_strcmp0(connected_address, address) != 0) {
2618 /* Convert BD adress from string type */
2619 _bt_convert_addr_string_to_type(
2620 device_address.addr,
2622 _bt_audio_disconnect(0, BT_AUDIO_A2DP,
2623 &device_address, NULL);
2627 /* Add data to the connected list */
2628 _bt_add_headset_to_list(BT_AUDIO_A2DP,
2629 BT_STATE_CONNECTED, address);
2636 g_variant_unref(val);
2637 g_variant_unref(child);
2641 void _bt_handle_agent_event(GVariant *msg, const char *member)
2643 int result = BLUETOOTH_ERROR_NONE;
2644 char *address = NULL;
2647 GVariant *param = NULL;
2648 ret_if(member == NULL);
2650 if (strcasecmp(member, "ObexAuthorize") == 0) {
2651 __bt_get_agent_signal_info(msg, &address, &name, &uuid);
2652 param = g_variant_new("(iss)", result, address, name);
2653 _bt_send_event(BT_OPP_SERVER_EVENT,
2654 BLUETOOTH_EVENT_OBEX_SERVER_CONNECTION_AUTHORIZE,
2656 /* TODO: MAP? see above */
2659 } else if (strcasecmp(member, "RfcommAuthorize") == 0) {
2660 bt_rfcomm_server_info_t *server_info;
2662 __bt_get_agent_signal_info(msg, &address, &name, &uuid);
2664 server_info = _bt_rfcomm_get_server_info_using_uuid(uuid);
2665 ret_if(server_info == NULL);
2666 ret_if(server_info->server_type != BT_CUSTOM_SERVER);
2667 param = g_variant_new("(isssn)", result, address, uuid, name,
2668 server_info->control_fd);
2669 _bt_send_event(BT_RFCOMM_SERVER_EVENT,
2670 BLUETOOTH_EVENT_RFCOMM_AUTHORIZE,
2678 void _bt_handle_tds_provider_event(GVariant *msg, const char *member, const char *path)
2680 BT_INFO("member: %s, path: %s", member, path);
2682 ret_if(path == NULL);
2684 if (strcasecmp(member, "TdsActivationRequested") == 0) {
2685 GVariant *value = NULL;
2687 unsigned char *buffer = NULL;
2688 unsigned char org_id;
2690 g_variant_get(msg, "(y@ay)", &org_id, &value);
2691 BT_DBG("org_id: %.2x", org_id);
2692 len = g_variant_get_size(value);
2695 buffer = (unsigned char *)g_variant_get_data(value);
2696 for (i = 0; i < len; i++)
2697 BT_DBG("%.2x", buffer[i]);
2700 /* Send event only registered client */
2701 _bt_tds_handle_activation_request(path, org_id, buffer, len);
2702 g_variant_unref(value);
2706 static int __bt_get_object_path(GVariant *msg, char **path)
2708 g_variant_get(msg, "(o*)", path, NULL);
2710 return BLUETOOTH_ERROR_INTERNAL;
2712 return BLUETOOTH_ERROR_NONE;
2715 static void __bt_devices_list_free(void)
2717 bt_cache_info_t *cache_info;
2720 node = g_list_first(p_cache_list);
2722 while (node != NULL) {
2723 cache_info = (bt_cache_info_t *)node->data;
2724 p_cache_list = g_list_remove(p_cache_list, cache_info);
2725 __bt_free_cache_info(cache_info);
2727 node = g_list_next(node);
2731 static int __bt_parse_event(GVariant *msg)
2735 char *interface_name = NULL;
2736 GVariant *inner_iter = NULL;
2738 g_variant_iter_init(&iter, msg);
2740 while ((child = g_variant_iter_next_value(&iter))) {
2741 g_variant_get(child, "{&s@a{sv}}", &interface_name, &inner_iter);
2742 if (g_strcmp0(interface_name,
2743 BT_DEVICE_INTERFACE) == 0) {
2744 g_variant_unref(inner_iter);
2745 g_variant_unref(child);
2746 return BT_DEVICE_EVENT;
2747 } else if (g_strcmp0(interface_name,
2748 BT_MEDIATRANSPORT_INTERFACE) == 0) {
2749 g_variant_unref(inner_iter);
2750 g_variant_unref(child);
2751 return BT_MEDIA_TRANSFER_EVENT;
2752 } else if (g_strcmp0(interface_name,
2753 BT_PLAYER_CONTROL_INTERFACE) == 0) {
2754 g_variant_unref(inner_iter);
2755 g_variant_unref(child);
2756 return BT_AVRCP_CONTROL_EVENT;
2758 g_variant_unref(inner_iter);
2759 g_variant_unref(child);
2765 static void __bt_manager_event_filter(GDBusConnection *connection,
2766 const gchar *sender_name,
2767 const gchar *object_path,
2768 const gchar *interface_name,
2769 const gchar *signal_name,
2770 GVariant *parameters,
2773 bt_event_type_t bt_event = 0x00;
2774 int result = BLUETOOTH_ERROR_NONE;
2776 char *obj_path = NULL;
2777 GVariant *param = NULL;
2778 if (signal_name == NULL)
2780 if (strcasecmp(signal_name, "InterfacesAdded") == 0) {
2781 g_variant_get(parameters, "(&o@a{sa{sv}})", &obj_path, &value);
2783 if (strcasecmp(obj_path, BT_BLUEZ_HCI_PATH) == 0) {
2784 #ifdef TIZEN_FEATURE_BT_USB_DONGLE
2785 BT_DBG("Enable Adapter");
2786 _bt_enable_adapter();
2788 _bt_handle_adapter_added();
2791 bt_event = __bt_parse_event(value);
2792 if (bt_event == BT_DEVICE_EVENT) {
2793 bt_cache_info_t *cache_info;
2794 bt_remote_dev_info_t *dev_info;
2795 #ifdef TIZEN_FEATURE_BT_DPM
2796 int desktop_state = DPM_BT_ERROR;
2798 ret_if(_bt_is_discovering() == FALSE &&
2799 _bt_is_le_scanning() == FALSE);
2801 cache_info = g_malloc0(sizeof(bt_cache_info_t));
2803 dev_info = g_malloc0(sizeof(bt_remote_dev_info_t));
2805 cache_info->dev_info = dev_info;
2807 if (__bt_parse_interface(parameters, dev_info) == FALSE) {
2808 BT_ERR("Fail to parse the properies");
2809 __bt_free_cache_info(cache_info);
2810 g_variant_unref(value);
2814 if (dev_info->addr_type != BDADDR_BREDR) {
2815 /* Whenever emit the property changed from bluez,
2816 some property doesn't reach to bt-service.
2817 So LE device is handled as AdvReport signal */
2818 __bt_free_cache_info(cache_info);
2819 g_variant_unref(value);
2823 if (dev_info->name == NULL)
2824 /* If Remote device name is NULL or still RNR is not done
2825 * then display address as name.
2827 dev_info->name = g_strdup(dev_info->address);
2829 #ifdef TIZEN_FEATURE_BT_DPM
2830 _bt_dpm_get_bluetooth_desktop_connectivity_state(&desktop_state);
2831 if (desktop_state == DPM_RESTRICTED) {
2832 bluetooth_device_class_t device_class;
2833 _bt_divide_device_class(&device_class, dev_info->class);
2834 BT_DBG("[%s]device_class.major_class : %d", dev_info->name, device_class.major_class);
2836 if (device_class.major_class ==
2837 BLUETOOTH_DEVICE_MAJOR_CLASS_COMPUTER) {
2838 __bt_free_cache_info(cache_info);
2839 g_variant_unref(value);
2845 GVariant *uuids = NULL;
2846 GVariantBuilder *builder = NULL;
2848 builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
2849 for (i = 0; i < dev_info->uuid_count; i++) {
2850 g_variant_builder_add(builder, "s",
2851 dev_info->uuids[i]);
2853 uuids = g_variant_new("as", builder);
2854 g_variant_builder_unref(builder);
2855 GVariant *manufacturer_data = NULL;
2856 manufacturer_data = g_variant_new_from_data(
2857 G_VARIANT_TYPE_BYTESTRING,
2858 dev_info->manufacturer_data,
2859 dev_info->manufacturer_data_len,
2861 param = g_variant_new("(isunsbub@asn@ay)", result,
2867 dev_info->connected,
2870 dev_info->manufacturer_data_len,
2872 _bt_send_event(BT_ADAPTER_EVENT,
2873 BLUETOOTH_EVENT_REMOTE_DEVICE_FOUND,
2875 p_cache_list = g_list_append(p_cache_list, cache_info);
2876 } else if (bt_event == BT_AVRCP_CONTROL_EVENT) {
2877 BT_DBG("Device path : %s ", obj_path);
2878 _bt_set_control_device_path(obj_path);
2881 g_variant_unref(value);
2882 } else if (strcasecmp(signal_name, "InterfacesRemoved") == 0) {
2883 #ifdef TIZEN_FEATURE_BT_USB_DONGLE
2884 BT_DBG("InterfacesRemoved");
2885 _bt_handle_adapter_removed();
2887 if (g_strcmp0(interface_name, BT_MEDIATRANSPORT_INTERFACE) == 0)
2888 bt_event = BT_MEDIA_TRANSFER_EVENT;
2889 else if (g_strcmp0(interface_name, BT_DEVICE_INTERFACE) == 0)
2890 bt_event = BT_DEVICE_EVENT;
2891 else if (g_strcmp0(interface_name, BT_PLAYER_CONTROL_INTERFACE) == 0)
2892 bt_event = BT_AVRCP_CONTROL_EVENT;
2894 if ((bt_event != 0) && (bt_event != BT_MEDIA_TRANSFER_EVENT)) {
2895 _bt_handle_adapter_event(parameters, signal_name);
2896 if (bt_event == BT_AVRCP_CONTROL_EVENT) {
2897 BT_INFO("Object Path %s", obj_path);
2898 _bt_remove_control_device_path(obj_path);
2901 } else if (strcasecmp(signal_name, "NameOwnerChanged") == 0) {
2904 char *previous = NULL;
2905 char *current = NULL;
2907 if (__bt_get_owner_info(parameters, &name, &previous, ¤t)) {
2908 BT_ERR("Fail to get the owner info");
2912 if (*current != '\0') {
2921 if (strcasecmp(name, BT_BLUEZ_NAME) == 0) {
2922 BT_INFO_C("### Bluetoothd is terminated");
2923 if (_bt_adapter_get_status() != BT_DEACTIVATING &&
2924 _bt_adapter_get_status() != BT_DEACTIVATED) {
2925 BT_INFO_C("### Recover it");
2926 _bt_recover_adapter();
2928 _bt_handle_adapter_removed();
2929 __bt_devices_list_free();
2932 _bt_obex_server_check_allocation(&value);
2934 if (value == TRUE) {
2935 /* Check if the obex server was terminated abnormally */
2936 _bt_obex_server_check_termination(name);
2939 _bt_rfcomm_server_check_existence(&value);
2941 if (value == TRUE) {
2942 /* The obex server was terminated abnormally */
2943 _bt_rfcomm_server_check_termination(name);
2946 /* Stop advertising started by terminated process */
2947 _bt_stop_advertising_by_terminated_process(name);
2949 _bt_stop_le_scan(name);
2951 /* Stop the Proximity reporter service */
2952 _bt_proximity_reporter_stop_by_terminated_process(name);
2954 /* Stop the Transport Discovery service */
2955 _bt_tds_stop_by_terminated_process(name);
2960 } else if (g_strcmp0(interface_name, BT_PROPERTIES_INTERFACE) == 0) {
2961 const char *path = object_path;
2963 if (strncmp(path, BT_MEDIA_OBJECT_PATH,
2964 strlen(BT_MEDIA_OBJECT_PATH)) == 0)
2967 _bt_handle_property_changed_event(parameters, object_path);
2968 } else if (g_strcmp0(interface_name, BT_ADAPTER_INTERFACE) == 0) {
2969 _bt_handle_adapter_event(parameters, signal_name);
2970 } else if (g_strcmp0(interface_name, BT_INPUT_INTERFACE) == 0) {
2971 _bt_handle_input_event(parameters, object_path);
2972 } else if (g_strcmp0(interface_name, BT_NETWORK_SERVER_INTERFACE) == 0) {
2973 _bt_handle_network_server_event(parameters, signal_name);
2974 } else if (g_strcmp0(interface_name, BT_HEADSET_INTERFACE) == 0) {
2975 _bt_handle_headset_event(parameters, object_path);
2976 } else if (g_strcmp0(interface_name, BT_SINK_INTERFACE) == 0) {
2977 _bt_handle_sink_event(parameters, object_path);
2978 } else if (g_strcmp0(interface_name, BT_AGENT_INTERFACE) == 0) {
2979 _bt_handle_agent_event(parameters, signal_name);
2980 } else if (g_strcmp0(interface_name, BT_DEVICE_INTERFACE) == 0) {
2981 _bt_handle_device_event(parameters, signal_name, object_path);
2982 } else if (g_strcmp0(interface_name, BT_TDS_PROVIDER_INTERFACE) == 0) {
2983 _bt_handle_tds_provider_event(parameters, signal_name, object_path);
2984 } else if (g_strcmp0(interface_name, BT_GATT_CHAR_INTERFACE) == 0) {
2985 _bt_handle_gatt_event(parameters, signal_name, object_path);
2991 static gboolean __bt_is_obexd_event(GVariant *msg, const char *interface)
2994 if (g_strcmp0(interface, BT_PROPERTIES_INTERFACE) == 0) {
2995 char *interface_name = NULL;
2997 g_variant_get(msg, "(&s@a{sv}@as)", &interface_name, NULL, NULL);
2998 retv_if(interface_name == NULL, FALSE);
3000 if (strcasecmp(interface_name, BT_OBEX_TRANSFER_INTERFACE) == 0) {
3001 BT_DBG("BT_OBEX_TRANSFER_INTERFACE");
3009 static void __bt_obexd_event_filter(GDBusConnection *connection,
3010 const gchar *sender_name,
3011 const gchar *object_path,
3012 const gchar *interface_name,
3013 const gchar *signal_name,
3014 GVariant *parameters,
3017 const char *member = signal_name;
3018 char *obj_path = NULL;
3019 ret_if(member == NULL);
3021 if (strcasecmp(member, "InterfacesAdded") == 0) {
3022 if (__bt_get_object_path(parameters, &obj_path)) {
3023 BT_ERR("Fail to get the path");
3026 BT_INFO("object_path = [%s]", obj_path);
3028 /*Handle OPP_SERVER_CONNECTED_EVENT here */
3029 /* TODO: MAP? see above */
3030 if (strncmp(obj_path, BT_SESSION_BASEPATH_SERVER,
3031 strlen(BT_SESSION_BASEPATH_SERVER)) != 0) {
3036 if (g_strrstr(obj_path, "session") && g_strrstr(obj_path, "transfer")) {
3037 BT_DBG("Obex_Server_Session_Transfer connected");
3038 _bt_obex_transfer_connected(obj_path);
3041 } else if (strcasecmp(member, "InterfacesRemoved") == 0) {
3042 /*Handle OPP_SERVER_DISCONNECTED_EVENT here */
3043 /* TODO: MAP? see above */
3044 if (__bt_get_object_path(parameters, &obj_path)) {
3045 BT_ERR("Fail to get the path");
3048 BT_INFO("object_path = [%s]", obj_path);
3050 if (strncmp(obj_path, BT_SESSION_BASEPATH_CLIENT,
3051 strlen(BT_SESSION_BASEPATH_CLIENT)) == 0) {
3052 BT_DBG("Call PBAP Disconnected");
3053 _bt_obex_pbap_client_disconnect(obj_path);
3056 if (strncmp(obj_path, BT_SESSION_BASEPATH_SERVER,
3057 strlen(BT_SESSION_BASEPATH_SERVER)) != 0) {
3062 if (g_strrstr(obj_path, "session") && g_strrstr(obj_path, "transfer")) {
3063 BT_DBG("Obex_Server_Session_Transfer disconnected %s",
3066 _bt_obex_transfer_disconnected(obj_path);
3069 } else if (__bt_is_obexd_event(parameters, interface_name) == TRUE) {
3070 const char *path = object_path;
3072 if (strncmp(path, BT_SESSION_BASEPATH_SERVER,
3073 strlen(BT_SESSION_BASEPATH_SERVER)) != 0 &&
3074 strncmp(path, BT_SESSION_BASEPATH_CLIENT,
3075 strlen(BT_SESSION_BASEPATH_CLIENT)) != 0) {
3076 BT_DBG("DBUS_HANDLER_RESULT_NOT_YET_HANDLED");
3080 _bt_handle_property_changed_event(parameters, path);
3086 static gboolean __bt_is_obexd_client_event(GVariant *msg, const char *interface)
3090 if (g_strcmp0(interface, BT_PROPERTIES_INTERFACE) == 0) {
3091 char *interface_name = NULL;
3093 g_variant_get(msg, "(&s@a{sv}@as)", &interface_name, NULL, NULL);
3095 retv_if(interface_name == NULL, FALSE);
3097 if (strcasecmp(interface_name,
3098 BT_OBEX_TRANSFER_INTERFACE) == 0) {
3109 static void __bt_opc_event_filter(GDBusConnection *connection,
3110 const gchar *sender_name,
3111 const gchar *object_path,
3112 const gchar *interface_name,
3113 const gchar *signal_name,
3114 GVariant *parameters,
3117 const char *member = signal_name;
3118 char *obj_path = NULL;
3119 if (strcasecmp(member, "InterfacesAdded") == 0) {
3120 BT_DBG("InterfacesAdded");
3121 } else if (strcasecmp(member, "InterfacesRemoved") == 0) {
3123 if (__bt_get_object_path(parameters, &obj_path)) {
3124 BT_ERR("Fail to get the path");
3128 BT_DBG("object_path = %s", obj_path);
3130 if (strncmp(obj_path, BT_SESSION_BASEPATH_CLIENT,
3131 strlen(BT_SESSION_BASEPATH_CLIENT)) != 0
3132 || strstr(obj_path, "transfer") == NULL) {
3135 } else if (strncmp(obj_path, BT_SESSION_BASEPATH_CLIENT,
3136 strlen(BT_SESSION_BASEPATH_CLIENT)) == 0) {
3137 BT_DBG("Going to call opc disconnected");
3138 _bt_opc_disconnected(obj_path);
3141 _bt_sending_files();
3143 } else if (__bt_is_obexd_client_event(parameters, interface_name) == TRUE) {
3144 char *path = (char *)object_path;
3145 BT_INFO("object_path %s", path);
3146 if (strncmp(path, BT_SESSION_BASEPATH_CLIENT,
3147 strlen(BT_SESSION_BASEPATH_CLIENT)) != 0) {
3148 BT_DBG("NOT BT_SESSION_BASEPATH_CLIENT");
3152 _bt_opc_property_changed_event(parameters, path);
3158 int _bt_opp_client_event_init(void)
3160 GError *error = NULL;
3162 if (opc_obexd_conn == NULL) {
3163 opc_obexd_conn = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &error);
3165 if (!opc_obexd_conn) {
3167 BT_ERR("Unable to connect to dbus: %s", error->message);
3168 g_clear_error(&error);
3170 return BLUETOOTH_ERROR_INTERNAL;
3174 if (_bt_register_service_event(opc_obexd_conn,
3175 BT_OPP_CLIENT_EVENT) != BLUETOOTH_ERROR_NONE) {
3176 g_object_unref(opc_obexd_conn);
3177 opc_obexd_conn = NULL;
3178 return BLUETOOTH_ERROR_INTERNAL;
3181 return BLUETOOTH_ERROR_NONE;
3184 void _bt_opp_client_event_deinit(void)
3186 if (opc_obexd_conn) {
3187 _bt_unregister_service_event(opc_obexd_conn,
3188 BT_OPP_CLIENT_EVENT);
3189 g_object_unref(opc_obexd_conn);
3190 opc_obexd_conn = NULL;
3194 static void __bt_map_event_filter(GDBusConnection *connection,
3195 const gchar *sender_name,
3196 const gchar *object_path,
3197 const gchar *interface_name,
3198 const gchar *signal_name,
3199 GVariant *parameters,
3202 BT_DBG("Entered __bt_map_event_filter");
3203 const char *member = signal_name;
3205 if (strcasecmp(member, "InterfacesAdded") == 0) {
3206 BT_DBG("------------------------------------ADDED------------------------------------");
3207 // currently doing nothing
3208 } else if (strcasecmp(member, "InterfacesRemoved") == 0) {
3209 BT_DBG("------------------------------------REMOVED------------------------------------");
3210 // TODO check if something should be called here?
3211 //_bt_map_on_transfer_finished(object_path, error);
3212 } else if (__bt_is_obexd_client_event(parameters, interface_name) == TRUE) {
3213 BT_DBG("------------------------------------CLIENT EVENT------------------------------------");
3214 _bt_map_property_changed_event(parameters, object_path);
3220 int _bt_map_client_event_init(void)
3222 GError *error = NULL;
3224 if (map_obexd_conn == NULL) {
3225 map_obexd_conn = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &error);
3227 if (!map_obexd_conn) {
3229 BT_ERR("Unable to connect to dbus: %s", error->message);
3230 g_clear_error(&error);
3232 return BLUETOOTH_ERROR_INTERNAL;
3236 if (_bt_register_service_event(map_obexd_conn,
3237 BT_MAP_CLIENT_EVENT) != BLUETOOTH_ERROR_NONE) {
3238 g_object_unref(map_obexd_conn);
3239 map_obexd_conn = NULL;
3240 return BLUETOOTH_ERROR_INTERNAL;
3243 return BLUETOOTH_ERROR_NONE;
3246 void _bt_map_client_event_deinit(void)
3248 if (map_obexd_conn) {
3249 _bt_unregister_service_event(map_obexd_conn,
3250 BT_MAP_CLIENT_EVENT);
3251 g_object_unref(map_obexd_conn);
3252 map_obexd_conn = NULL;
3256 int _bt_register_manager_subscribe_signal(GDBusConnection *conn,
3262 static int subs_interface_added_id = -1;
3263 static int subs_interface_removed_id = -1;
3264 static int subs_name_owner_id = -1;
3265 static int subs_property_id = -1;
3266 static int subs_adapter_id = -1;
3267 static int subs_gatt_id = -1;
3270 if (subs_interface_added_id == -1) {
3271 subs_interface_added_id = g_dbus_connection_signal_subscribe(conn,
3272 NULL, BT_MANAGER_INTERFACE,
3273 BT_INTERFACES_ADDED, NULL, NULL, 0,
3274 __bt_manager_event_filter,
3277 if (subs_interface_removed_id == -1) {
3278 subs_interface_removed_id = g_dbus_connection_signal_subscribe(conn,
3279 NULL, BT_MANAGER_INTERFACE,
3280 BT_INTERFACES_REMOVED, NULL, NULL, 0,
3281 __bt_manager_event_filter,
3284 if (subs_name_owner_id == -1) {
3285 subs_name_owner_id = g_dbus_connection_signal_subscribe(conn,
3286 NULL, BT_FREEDESKTOP_INTERFACE,
3287 BT_NAME_OWNER_CHANGED, NULL, NULL, 0,
3288 __bt_manager_event_filter,
3291 if (subs_property_id == -1) {
3292 subs_property_id = g_dbus_connection_signal_subscribe(conn,
3293 NULL, BT_PROPERTIES_INTERFACE,
3294 BT_PROPERTIES_CHANGED, NULL, NULL, 0,
3295 __bt_manager_event_filter,
3298 if (subs_adapter_id == -1) {
3299 subs_adapter_id = g_dbus_connection_signal_subscribe(conn,
3300 NULL, BT_ADAPTER_INTERFACE,
3301 NULL, NULL, NULL, 0,
3302 __bt_manager_event_filter,
3305 if (subs_gatt_id == -1) {
3306 subs_gatt_id = g_dbus_connection_signal_subscribe(conn,
3307 NULL, BT_GATT_CHAR_INTERFACE,
3308 NULL, NULL, NULL, 0,
3309 __bt_manager_event_filter,
3313 if (subs_interface_added_id != -1) {
3314 g_dbus_connection_signal_unsubscribe(conn,
3315 subs_interface_added_id);
3316 subs_interface_added_id = -1;
3318 if (subs_interface_removed_id != -1) {
3319 g_dbus_connection_signal_unsubscribe(conn,
3320 subs_interface_removed_id);
3321 subs_interface_removed_id = -1;
3323 if (subs_name_owner_id != -1) {
3324 g_dbus_connection_signal_unsubscribe(conn,
3325 subs_name_owner_id);
3326 subs_name_owner_id = -1;
3328 if (subs_property_id != -1) {
3329 g_dbus_connection_signal_unsubscribe(conn,
3331 subs_property_id = -1;
3333 if (subs_adapter_id != -1) {
3334 g_dbus_connection_signal_unsubscribe(conn, subs_adapter_id);
3335 subs_adapter_id = -1;
3337 if (subs_gatt_id != -1) {
3338 g_dbus_connection_signal_unsubscribe(conn, subs_gatt_id);
3345 int _bt_register_device_subscribe_signal(GDBusConnection *conn,
3351 static int subs_device_id = -1;
3354 if (subs_device_id == -1) {
3355 subs_device_id = g_dbus_connection_signal_subscribe(conn,
3356 NULL, BT_DEVICE_INTERFACE,
3357 NULL, NULL, NULL, 0,
3358 __bt_manager_event_filter,
3362 if (subs_device_id != -1) {
3363 g_dbus_connection_signal_unsubscribe(conn,
3365 subs_device_id = -1;
3371 int _bt_register_input_subscribe_signal(GDBusConnection *conn,
3377 static int subs_input_id = -1;
3380 if (subs_input_id == -1) {
3381 subs_input_id = g_dbus_connection_signal_subscribe(conn,
3382 NULL, BT_INPUT_INTERFACE,
3383 NULL, NULL, NULL, 0,
3384 __bt_manager_event_filter,
3388 if (subs_input_id != -1) {
3389 g_dbus_connection_signal_unsubscribe(conn,
3397 int _bt_register_network_subscribe_signal(GDBusConnection *conn,
3403 static int subs_serv_id = -1;
3404 static int subs_client_id = -1;
3407 if (subs_serv_id == -1) {
3408 subs_serv_id = g_dbus_connection_signal_subscribe(conn,
3409 NULL, BT_NETWORK_SERVER_INTERFACE,
3410 NULL, NULL, NULL, 0,
3411 __bt_manager_event_filter,
3414 if (subs_client_id == -1) {
3415 subs_client_id = g_dbus_connection_signal_subscribe(conn,
3416 NULL, BT_NETWORK_CLIENT_INTERFACE,
3417 NULL, NULL, NULL, 0,
3418 __bt_manager_event_filter,
3422 if (subs_serv_id != -1) {
3423 g_dbus_connection_signal_unsubscribe(conn,
3427 if (subs_client_id != -1) {
3428 g_dbus_connection_signal_unsubscribe(conn,
3430 subs_client_id = -1;
3436 int _bt_register_audio_subscribe_signal(GDBusConnection *conn,
3442 static int subs_headset_id = -1;
3443 static int subs_sink_id = -1;
3446 if (subs_headset_id == -1) {
3447 subs_headset_id = g_dbus_connection_signal_subscribe(conn,
3448 NULL, BT_HEADSET_INTERFACE,
3449 NULL, NULL, NULL, 0,
3450 __bt_manager_event_filter,
3453 if (subs_sink_id == -1) {
3454 subs_sink_id = g_dbus_connection_signal_subscribe(conn,
3455 NULL, BT_SINK_INTERFACE,
3456 NULL, NULL, NULL, 0,
3457 __bt_manager_event_filter,
3461 if (subs_headset_id != -1) {
3462 g_dbus_connection_signal_unsubscribe(conn,
3464 subs_headset_id = -1;
3466 if (subs_sink_id != -1) {
3467 g_dbus_connection_signal_unsubscribe(conn,
3475 int _bt_register_opp_server_subscribe_signal(GDBusConnection *conn,
3481 static int subs_opp_server_interface_added_id = -1;
3482 static int subs_opp_server_interface_removed_id = -1;
3483 static int subs_opp_server_property_id = -1;
3487 if (subs_opp_server_interface_added_id == -1) {
3488 subs_opp_server_interface_added_id = g_dbus_connection_signal_subscribe(conn,
3489 NULL, BT_MANAGER_INTERFACE,
3490 BT_INTERFACES_ADDED, NULL, NULL, 0,
3491 __bt_obexd_event_filter,
3494 if (subs_opp_server_interface_removed_id == -1) {
3495 subs_opp_server_interface_removed_id = g_dbus_connection_signal_subscribe(conn,
3496 NULL, BT_MANAGER_INTERFACE,
3497 BT_INTERFACES_REMOVED, NULL, NULL, 0,
3498 __bt_obexd_event_filter,
3501 if (subs_opp_server_property_id == -1) {
3502 subs_opp_server_property_id = g_dbus_connection_signal_subscribe(conn,
3503 NULL, BT_PROPERTIES_INTERFACE,
3504 BT_PROPERTIES_CHANGED, NULL, NULL, 0,
3505 __bt_obexd_event_filter,
3509 if (subs_opp_server_interface_added_id != -1) {
3510 g_dbus_connection_signal_unsubscribe(conn,
3511 subs_opp_server_interface_added_id);
3512 subs_opp_server_interface_added_id = -1;
3514 if (subs_opp_server_interface_removed_id != -1) {
3515 g_dbus_connection_signal_unsubscribe(conn,
3516 subs_opp_server_interface_removed_id);
3517 subs_opp_server_interface_removed_id = -1;
3519 if (subs_opp_server_property_id != -1) {
3520 g_dbus_connection_signal_unsubscribe(conn,
3521 subs_opp_server_property_id);
3522 subs_opp_server_property_id = -1;
3528 int _bt_register_opp_client_subscribe_signal(GDBusConnection *conn,
3534 static int subs_opp_client_interface_added_id = -1;
3535 static int subs_opp_client_interface_removed_id = -1;
3536 static int subs_opp_client_property_id = -1;
3540 if (subs_opp_client_interface_added_id == -1) {
3541 subs_opp_client_interface_added_id = g_dbus_connection_signal_subscribe(conn,
3542 NULL, BT_MANAGER_INTERFACE,
3543 BT_INTERFACES_ADDED, NULL, NULL, 0,
3544 __bt_opc_event_filter,
3547 if (subs_opp_client_interface_removed_id == -1) {
3548 subs_opp_client_interface_removed_id = g_dbus_connection_signal_subscribe(conn,
3549 NULL, BT_MANAGER_INTERFACE,
3550 BT_INTERFACES_REMOVED, NULL, NULL, 0,
3551 __bt_opc_event_filter,
3554 if (subs_opp_client_property_id == -1) {
3555 subs_opp_client_property_id = g_dbus_connection_signal_subscribe(conn,
3556 NULL, BT_PROPERTIES_INTERFACE,
3557 BT_PROPERTIES_CHANGED, NULL, NULL, 0,
3558 __bt_opc_event_filter,
3562 if (subs_opp_client_interface_added_id != -1) {
3563 g_dbus_connection_signal_unsubscribe(conn,
3564 subs_opp_client_interface_added_id);
3565 subs_opp_client_interface_added_id = -1;
3567 if (subs_opp_client_interface_removed_id != -1) {
3568 g_dbus_connection_signal_unsubscribe(conn,
3569 subs_opp_client_interface_removed_id);
3570 subs_opp_client_interface_removed_id = -1;
3572 if (subs_opp_client_property_id != -1) {
3573 g_dbus_connection_signal_unsubscribe(conn,
3574 subs_opp_client_property_id);
3575 subs_opp_client_property_id = -1;
3581 int _bt_register_map_client_subscribe_signal(GDBusConnection *conn,
3587 static int subs_map_client_interface_added_id = -1;
3588 static int subs_map_client_interface_removed_id = -1;
3589 static int subs_map_client_property_id = -1;
3593 if (subs_map_client_interface_added_id == -1) {
3594 subs_map_client_interface_added_id = g_dbus_connection_signal_subscribe(conn,
3595 NULL, BT_MANAGER_INTERFACE,
3596 BT_INTERFACES_ADDED, NULL, NULL, 0,
3597 __bt_map_event_filter,
3600 if (subs_map_client_interface_removed_id == -1) {
3601 subs_map_client_interface_removed_id = g_dbus_connection_signal_subscribe(conn,
3602 NULL, BT_MANAGER_INTERFACE,
3603 BT_INTERFACES_REMOVED, NULL, NULL, 0,
3604 __bt_map_event_filter,
3607 if (subs_map_client_property_id == -1) {
3608 subs_map_client_property_id = g_dbus_connection_signal_subscribe(conn,
3609 NULL, BT_PROPERTIES_INTERFACE,
3610 BT_PROPERTIES_CHANGED, NULL, NULL, 0,
3611 __bt_map_event_filter,
3615 if (subs_map_client_interface_added_id != -1) {
3616 g_dbus_connection_signal_unsubscribe(conn,
3617 subs_map_client_interface_added_id);
3618 subs_map_client_interface_added_id = -1;
3620 if (subs_map_client_interface_removed_id != -1) {
3621 g_dbus_connection_signal_unsubscribe(conn,
3622 subs_map_client_interface_removed_id);
3623 subs_map_client_interface_removed_id = -1;
3625 if (subs_map_client_property_id != -1) {
3626 g_dbus_connection_signal_unsubscribe(conn,
3627 subs_map_client_property_id);
3628 subs_map_client_property_id = -1;
3634 int _bt_register_a2dp_subscribe_signal(GDBusConnection *conn,
3640 static int subs_a2dp_source_id = -1;
3641 static int subs_a2dp_sink_id = -1;
3644 if (subs_a2dp_source_id == -1) {
3645 subs_a2dp_source_id = g_dbus_connection_signal_subscribe(conn,
3646 NULL, BT_A2DP_SOURCE_INTERFACE,
3647 NULL, NULL, NULL, 0,
3648 __bt_opc_event_filter,
3651 if (subs_a2dp_sink_id == -1) {
3652 subs_a2dp_sink_id = g_dbus_connection_signal_subscribe(conn,
3653 NULL, BT_SINK_INTERFACE,
3654 NULL, NULL, NULL, 0,
3655 __bt_opc_event_filter,
3659 if (subs_a2dp_source_id != -1) {
3660 g_dbus_connection_signal_unsubscribe(conn,
3661 subs_a2dp_source_id);
3662 subs_a2dp_source_id = -1;
3664 if (subs_a2dp_sink_id != -1) {
3665 g_dbus_connection_signal_unsubscribe(conn,
3667 subs_a2dp_sink_id = -1;
3673 int _bt_register_tds_provider_subscribe_signal(GDBusConnection *conn, int subscribe)
3678 static int subs_custom_id = -1;
3681 if (subs_custom_id == -1) {
3682 subs_custom_id = g_dbus_connection_signal_subscribe(conn,
3683 NULL, BT_TDS_PROVIDER_INTERFACE,
3684 NULL, NULL, NULL, 0,
3685 __bt_manager_event_filter,
3689 if (subs_custom_id != -1) {
3690 g_dbus_connection_signal_unsubscribe(conn,
3692 subs_custom_id = -1;
3699 static void __bt_dump_event_filter(GDBusConnection *connection,
3700 const gchar *sender_name,
3701 const gchar *object_path,
3702 const gchar *interface_name,
3703 const gchar *signal_name,
3704 GVariant *parameters,
3710 int __bt_register_dump_subscribe_signal(GDBusConnection *conn,
3716 static int subs_source_id = -1;
3719 if (subs_source_id == -1) {
3720 subs_source_id = g_dbus_connection_signal_subscribe(conn,
3721 NULL, BT_DUMP_SERVICE_INTERFACE,
3722 BT_DUMP_SERVICE_SIGNAL, BT_DUMP_SERVICE_PATH, NULL, 0,
3723 __bt_dump_event_filter,
3727 if (subs_source_id != -1) {
3728 g_dbus_connection_signal_unsubscribe(conn,
3730 subs_source_id = -1;
3736 int _bt_register_service_event(GDBusConnection *g_conn, int event_type)
3740 retv_if(g_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
3742 switch (event_type) {
3743 case BT_MANAGER_EVENT:
3744 _bt_register_manager_subscribe_signal(g_conn, TRUE);
3746 case BT_DEVICE_EVENT:
3747 _bt_register_device_subscribe_signal(g_conn, TRUE);
3750 _bt_register_input_subscribe_signal(g_conn, TRUE);
3752 case BT_NETWORK_EVENT:
3753 _bt_register_network_subscribe_signal(g_conn, TRUE);
3755 case BT_HEADSET_EVENT:
3756 _bt_register_audio_subscribe_signal(g_conn, TRUE);
3758 case BT_OPP_SERVER_EVENT:
3759 BT_ERR("BT_OPP_SERVER_EVENT: register service event");
3760 _bt_register_opp_server_subscribe_signal(g_conn, TRUE);
3763 case BT_OPP_CLIENT_EVENT:
3764 BT_ERR("BT_OPP_CLIENT_EVENT: register service event");
3765 _bt_register_opp_client_subscribe_signal(g_conn, TRUE);
3767 case BT_MAP_CLIENT_EVENT:
3768 BT_ERR("BT_MAP_CLIENT_EVENT: register service event");
3769 _bt_register_map_client_subscribe_signal(g_conn, TRUE);
3771 case BT_A2DP_SOURCE_EVENT:
3772 BT_INFO("A2dp Source event");
3773 _bt_register_a2dp_subscribe_signal(g_conn, TRUE);
3776 BT_INFO("TDS provider event");
3777 _bt_register_tds_provider_subscribe_signal(g_conn, TRUE);
3780 BT_ERR("Unknown event");
3781 return BLUETOOTH_ERROR_INTERNAL;
3784 return BLUETOOTH_ERROR_NONE;
3787 void _bt_unregister_service_event(GDBusConnection *g_conn, int event_type)
3791 ret_if(g_conn == NULL);
3793 switch (event_type) {
3794 case BT_MANAGER_EVENT:
3795 _bt_register_manager_subscribe_signal(g_conn, FALSE);
3796 _bt_register_device_subscribe_signal(g_conn, FALSE);
3797 _bt_register_input_subscribe_signal(g_conn, FALSE);
3798 _bt_register_network_subscribe_signal(g_conn, FALSE);
3799 _bt_register_audio_subscribe_signal(g_conn, FALSE);
3801 case BT_OPP_SERVER_EVENT:
3802 _bt_register_opp_server_subscribe_signal(g_conn, FALSE);
3804 case BT_OPP_CLIENT_EVENT:
3805 _bt_register_opp_client_subscribe_signal(g_conn, FALSE);
3807 case BT_MAP_CLIENT_EVENT:
3808 _bt_register_map_client_subscribe_signal(g_conn, FALSE);
3811 BT_ERR("Unknown event");
3818 static int __bt_init_manager_receiver(void)
3822 GError *error = NULL;
3824 if (manager_conn == NULL) {
3825 manager_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
3826 if (error != NULL) {
3827 BT_ERR("ERROR: Can't get on system bus [%s]", error->message);
3828 g_clear_error(&error);
3830 retv_if(manager_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
3833 if (_bt_register_service_event(manager_conn,
3834 BT_MANAGER_EVENT) != BLUETOOTH_ERROR_NONE)
3836 if (_bt_register_service_event(manager_conn,
3837 BT_DEVICE_EVENT) != BLUETOOTH_ERROR_NONE)
3840 if (_bt_register_service_event(manager_conn,
3841 BT_HID_EVENT) != BLUETOOTH_ERROR_NONE)
3844 if (_bt_register_service_event(manager_conn,
3845 BT_HEADSET_EVENT) != BLUETOOTH_ERROR_NONE)
3848 if (_bt_register_service_event(manager_conn,
3849 BT_NETWORK_EVENT) != BLUETOOTH_ERROR_NONE)
3852 if (_bt_register_service_event(manager_conn,
3853 BT_TDS_EVENT) != BLUETOOTH_ERROR_NONE)
3856 __bt_register_dump_subscribe_signal(manager_conn, TRUE);
3857 return BLUETOOTH_ERROR_NONE;
3860 g_object_unref(manager_conn);
3861 manager_conn = NULL;
3866 return BLUETOOTH_ERROR_INTERNAL;
3869 static int __bt_init_obexd_receiver(void)
3872 #ifndef TIZEN_PROFILE_TV /* TODO: obexd doesn't work in TV profile. It should be resolved later. */
3873 GError *error = NULL;
3875 if (obexd_conn == NULL) {
3876 obexd_conn = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &error);
3877 if (error != NULL) {
3878 BT_ERR("ERROR: Can't get on session bus [%s]", error->message);
3879 g_clear_error(&error);
3881 retv_if(obexd_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
3884 if (_bt_register_service_event(obexd_conn,
3885 BT_OPP_SERVER_EVENT) != BLUETOOTH_ERROR_NONE) {
3886 BT_ERR("Error while registering service event");
3887 g_object_unref(obexd_conn);
3889 return BLUETOOTH_ERROR_INTERNAL;
3894 return BLUETOOTH_ERROR_NONE;
3897 gboolean __bt_reinit_obexd_receiver(gpointer user_data)
3899 static int retry_cnt = 0;
3900 int result = BLUETOOTH_ERROR_NONE;
3904 result = __bt_init_obexd_receiver();
3905 if (result != BLUETOOTH_ERROR_NONE) {
3906 /* 20 ms * 50 = 10 seconds. During 10 seconds fail to initialize,
3907 then it is not the timing issue. Just can't use the session bus connection */
3908 if (retry_cnt > 100) {
3909 BT_ERR("Fail to init obexd receiver by 50 times.");
3911 session_reinit_timer = 0;
3915 BT_DBG("Retry to initialize the obexd receiver");
3920 session_reinit_timer = 0;
3927 /* To receive the event from bluez */
3928 int _bt_init_service_event_receiver(void)
3934 result = __bt_init_manager_receiver();
3935 retv_if(result != BLUETOOTH_ERROR_NONE, result);
3937 result = __bt_init_obexd_receiver();
3938 if (result != BLUETOOTH_ERROR_NONE) {
3939 BT_ERR("Fail to init obexd receiver");
3941 /* Try to re-initialize obexd receiver in the timer */
3942 if (session_reinit_timer > 0)
3943 g_source_remove(session_reinit_timer);
3945 session_reinit_timer = g_timeout_add(BT_SESSION_BUS_GET_TIMEOUT,
3946 (GSourceFunc)__bt_reinit_obexd_receiver, NULL);
3951 return BLUETOOTH_ERROR_NONE;
3954 void _bt_deinit_service_event_receiver(void)
3958 _bt_unregister_service_event(manager_conn, BT_MANAGER_EVENT);
3960 _bt_unregister_service_event(obexd_conn, BT_OPP_SERVER_EVENT);
3962 __bt_register_dump_subscribe_signal(manager_conn, FALSE);
3965 g_object_unref(manager_conn);
3966 manager_conn = NULL;
3970 g_object_unref(obexd_conn);
3975 g_source_remove(event_id);
3978 if (le_scan_event_id > 0)
3979 g_source_remove(le_scan_event_id);
3980 le_scan_event_id = 0;