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 int is_flight_mode = 0;
446 if (TIZEN_FEATURE_FLIGHTMODE_ENABLED) {
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 if (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 if (TIZEN_FEATURE_BT_USB_DONGLE)
814 _bt_handle_adapter_added();
816 } else if (strcasecmp(property, "Connectable") == 0) {
817 gboolean connectable = FALSE;
819 g_variant_get(val, "b", &connectable);
821 BT_DBG("Connectable property is changed : %d", connectable);
822 param = g_variant_new("(b)", connectable);
823 _bt_send_event(BT_ADAPTER_EVENT,
824 BLUETOOTH_EVENT_CONNECTABLE_CHANGED,
827 if (_bt_adapter_get_status() == BT_DEACTIVATING &&
828 _bt_adapter_get_le_status() == BT_LE_ACTIVATED &&
830 _bt_set_disabled(BLUETOOTH_ERROR_NONE);
832 } else if (strcasecmp(property, "SupportedLEFeatures") == 0) {
835 GVariantIter *iter = NULL;
836 g_variant_get(val, "as", &iter);
838 ret_if(iter == NULL);
840 while (g_variant_iter_loop(iter, "s", &name)) {
841 BT_DBG("name = %s", name);
842 g_variant_iter_loop(iter, "s", &value);
843 BT_DBG("Value = %s", value);
844 if (FALSE == _bt_update_le_feature_support(name, value))
845 BT_INFO("Fail to update LE feature info");
848 g_variant_iter_free(iter);
849 } else if (strcasecmp(property, "IpspInitStateChanged") == 0) {
850 gboolean ipsp_initialized = FALSE;
852 g_variant_get(val, "b", &ipsp_initialized);
853 BT_DBG("IPSP init state changed: %d", ipsp_initialized);
854 param = g_variant_new("(b)", ipsp_initialized);
856 /* Send event to application */
857 _bt_send_event(BT_ADAPTER_EVENT,
858 BLUETOOTH_EVENT_IPSP_INIT_STATE_CHANGED,
861 BT_DBG("property : [%s]", property);
866 static void __bt_obex_property_changed_event(GVariant *msg, const char *path)
870 GVariantIter value_iter;
871 GVariant *child = NULL, *val = NULL;
872 char *property = NULL;
873 g_variant_iter_init(&value_iter, msg);
874 while ((child = g_variant_iter_next_value(&value_iter))) {
875 g_variant_get(child, "{sv}", &property, &val);
877 ret_if(property == NULL);
879 BT_DBG("property :%s", property);
881 if (strcasecmp(property, "Status") == 0) {
883 g_variant_get(val, "s", &status);
885 if (strcasecmp(status, "active") == 0) {
886 _bt_obex_transfer_started(path);
887 } else if (strcasecmp(status, "complete") == 0) {
888 _bt_obex_transfer_completed(path, TRUE);
889 _bt_pbap_obex_transfer_completed(path, TRUE);
890 } else if (strcasecmp(status, "error") == 0) {
891 _bt_obex_transfer_completed(path, FALSE);
892 _bt_pbap_obex_transfer_completed(path, FALSE);
895 } else if (strcasecmp(property, "Transferred") == 0) {
896 guint64 transferred = 0;
897 /* As Transferred is expected guint64 so change int to guint64 and
898 * eariler transferred is static because of it can overwrite data
899 * on present on opc_obex_conn or obexd_conn as these are
900 * static memory are in sequential */
901 g_variant_get(val, "t", &transferred);
903 _bt_obex_transfer_progress(path, transferred);
905 /* TODO: MAP, "Complete"? see above */
907 g_variant_unref(val);
908 g_variant_unref(child);
913 static void __bt_device_property_changed_event(GVariant *msg, const char *path)
918 int result = BLUETOOTH_ERROR_NONE;
919 GVariantIter value_iter;
921 char *property = NULL;
923 GVariant *param = NULL;
924 bt_remote_dev_info_t *remote_dev_info;
925 g_variant_iter_init(&value_iter, msg);
926 #ifdef TIZEN_FEATURE_BT_DPM
927 int desktop_state = DPM_BT_ERROR;
929 while ((g_variant_iter_loop(&value_iter, "{sv}", &property, &val))) {
930 BT_DBG("Property %s", property);
931 if (strcasecmp(property, "Connected") == 0) {
934 g_variant_get(val, "i", &connected);
936 event = (connected != BLUETOOTH_CONNECTED_LINK_NONE) ?
937 BLUETOOTH_EVENT_DEVICE_CONNECTED :
938 BLUETOOTH_EVENT_DEVICE_DISCONNECTED;
940 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
942 _bt_convert_device_path_to_address(path, address);
944 BT_DBG("connected: %d", connected);
945 BT_DBG("address: %s", address);
947 remote_dev_info = _bt_get_remote_device_info_by_object_path(path);
949 if (remote_dev_info != NULL) {
950 __bt_device_remote_connected_properties(
951 remote_dev_info, address,
952 connected != BLUETOOTH_CONNECTED_LINK_NONE ?
954 _bt_free_device_info(remote_dev_info);
956 param = g_variant_new("(is)", result, address);
957 /* Send event to application */
958 _bt_send_event(BT_DEVICE_EVENT,
962 } else if (strcasecmp(property, "RSSI") == 0) {
963 bt_remote_dev_info_t *remote_dev_info;
965 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
967 _bt_convert_device_path_to_address(path, address);
968 BT_DBG("address: %s", address);
972 remote_dev_info = _bt_get_remote_device_info_by_object_path(path);
973 if (remote_dev_info == NULL) {
975 g_variant_unref(val);
978 BT_DBG("Address type %d", remote_dev_info->addr_type);
980 if (remote_dev_info->addr_type == 0) {
981 BT_DBG("Name %s", remote_dev_info->name);
983 #ifdef TIZEN_FEATURE_BT_DPM
984 _bt_dpm_get_bluetooth_desktop_connectivity_state(&desktop_state);
985 if (desktop_state == DPM_RESTRICTED) {
986 bluetooth_device_class_t device_class;
987 _bt_divide_device_class(&device_class, remote_dev_info->class);
989 if (device_class.major_class ==
990 BLUETOOTH_DEVICE_MAJOR_CLASS_COMPUTER) {
991 _bt_free_device_info(remote_dev_info);
993 g_variant_unref(val);
999 GVariant *uuids = NULL;
1000 GVariantBuilder *builder = NULL;
1002 builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
1003 for (i = 0; i < remote_dev_info->uuid_count; i++) {
1004 g_variant_builder_add(builder, "s",
1005 remote_dev_info->uuids[i]);
1007 uuids = g_variant_new("as", builder);
1008 g_variant_builder_unref(builder);
1009 GVariant *manufacturer_data = NULL;
1010 manufacturer_data = g_variant_new_from_data(G_VARIANT_TYPE_BYTESTRING,
1011 remote_dev_info->manufacturer_data,
1012 remote_dev_info->manufacturer_data_len,
1015 param = g_variant_new("(isunsbub@asn@ay)", result,
1016 remote_dev_info->address,
1017 remote_dev_info->class,
1018 remote_dev_info->rssi,
1019 remote_dev_info->name,
1020 remote_dev_info->paired,
1021 remote_dev_info->connected,
1022 remote_dev_info->trust,
1024 remote_dev_info->manufacturer_data_len,
1027 _bt_send_event(BT_ADAPTER_EVENT,
1028 BLUETOOTH_EVENT_REMOTE_DEVICE_FOUND,
1031 _bt_free_device_info(remote_dev_info);
1032 } else if (strcasecmp(property, "GattConnected") == 0) {
1033 gboolean gatt_connected = FALSE;
1035 g_variant_get(val, "b", &gatt_connected);
1037 event = gatt_connected ? BLUETOOTH_EVENT_GATT_CONNECTED :
1038 BLUETOOTH_EVENT_GATT_DISCONNECTED;
1040 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1042 _bt_convert_device_path_to_address(path, address);
1044 BT_DBG("gatt_connected: %d", gatt_connected);
1045 BT_DBG("address: %s", address);
1046 param = g_variant_new("(is)", result, address);
1047 /* Send event to application */
1048 _bt_send_event(BT_DEVICE_EVENT,
1052 } else if (strcasecmp(property, "Paired") == 0) {
1053 gboolean paired = FALSE;
1054 bt_remote_dev_info_t *remote_dev_info;
1055 g_variant_get(val, "b", &paired);
1056 _bt_agent_set_canceled(FALSE);
1057 /* BlueZ sends paired signal for each paired device */
1058 /* during activation, We should ignore this, otherwise*/
1059 /* application thinks that a new device got paired */
1060 if (_bt_adapter_get_status() != BT_ACTIVATED) {
1061 BT_DBG("BT is not activated, so ignore this");
1063 g_variant_unref(val);
1067 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1069 _bt_convert_device_path_to_address(path, address);
1071 remote_dev_info = _bt_get_remote_device_info_by_object_path(path);
1072 if (remote_dev_info == NULL) {
1074 g_variant_unref(val);
1079 if (paired == FALSE) {
1080 BT_INFO("Unpaired: %s", address);
1081 __bt_update_remote_cache_devinfo(address, FALSE);
1082 param = g_variant_new("(is)", result, address);
1083 _bt_send_event(BT_ADAPTER_EVENT,
1084 BLUETOOTH_EVENT_BONDED_DEVICE_REMOVED,
1086 #ifdef TIZEN_BT_A2DP_SINK_AUTO_CONNECT
1088 char *last_connected = NULL;
1089 last_connected = vconf_get_str(BT_LAST_CONNECTED_DEVICE);
1090 if (!g_strcmp0(address, last_connected))
1091 _bt_audio_set_auto_connect_device_addr("");
1093 free(last_connected);
1097 char secure_addr[BT_ADDRESS_STRING_SIZE] = { 0 };
1099 _bt_convert_addr_string_to_secure_string(secure_addr, address);
1100 BT_INFO("### Paired: %s", secure_addr);
1101 __bt_update_remote_cache_devinfo(address, TRUE);
1103 if (_bt_is_device_creating() == TRUE) {
1104 BT_DBG("Try to Pair by me");
1105 _bt_free_device_info(remote_dev_info);
1108 g_variant_unref(val);
1111 GVariant *uuids = NULL;
1112 GVariantBuilder *builder = NULL;
1114 builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
1115 for (i = 0; i < remote_dev_info->uuid_count; i++) {
1116 g_variant_builder_add(builder, "s",
1117 remote_dev_info->uuids[i]);
1119 uuids = g_variant_new("as", builder);
1120 g_variant_builder_unref(builder);
1121 GVariant *manufacturer_data = NULL;
1122 manufacturer_data = g_variant_new_from_data(G_VARIANT_TYPE_BYTESTRING,
1123 remote_dev_info->manufacturer_data,
1124 remote_dev_info->manufacturer_data_len,
1128 param = g_variant_new("(isunsbub@asn@ay)", result,
1129 address, remote_dev_info->class,
1130 remote_dev_info->rssi,
1131 remote_dev_info->name,
1132 remote_dev_info->paired,
1133 remote_dev_info->connected,
1134 remote_dev_info->trust,
1136 remote_dev_info->manufacturer_data_len,
1138 _bt_send_event(BT_ADAPTER_EVENT,
1139 BLUETOOTH_EVENT_BONDING_FINISHED,
1142 _bt_free_device_info(remote_dev_info);
1144 } else if (strcasecmp(property, "LegacyPaired") == 0) {
1145 gboolean paired = FALSE;
1146 bt_remote_dev_info_t *remote_dev_info;
1147 unsigned char auth_info[5] = {0, };
1149 if (_bt_adapter_get_status() != BT_ACTIVATED) {
1150 BT_DBG("BT is not activated, so ignore this");
1152 g_variant_unref(val);
1156 g_variant_get(val, "b", &paired);
1157 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1158 BT_DBG("LegacyPaired: %d", paired);
1159 _bt_convert_device_path_to_address(path, address);
1161 remote_dev_info = _bt_get_remote_device_info_by_object_path(path);
1162 if (remote_dev_info == NULL) {
1165 g_variant_unref(val);
1168 if (remote_dev_info->is_alias_set == FALSE) {
1169 /*minimum Size of the samsung specific manufacturer data is greater than 30 */
1170 if ((remote_dev_info->manufacturer_data_len > 30) &&
1171 (remote_dev_info->manufacturer_data[0] == 0x00) &&
1172 (remote_dev_info->manufacturer_data[1] == 0x75)) {
1174 /* 2 samsung (0x00 0x75) + 1 (control and version) + 1 (service ID) +
1175 1 (discovery version) + 1 (associated service ID)
1176 2 (Proxamity and locality) + 2 (Device type and icon) = 10 */
1178 memcpy(auth_info, &(remote_dev_info->manufacturer_data[10]), 5);
1182 BT_DBG("LegacyPairing Failed with %s. Show Error Popup", remote_dev_info->name);
1183 _bt_launch_system_popup(BT_AGENT_EVENT_LEGACY_PAIR_FAILED_FROM_REMOTE,
1184 remote_dev_info->name, auth_info, NULL, NULL, NULL);
1186 _bt_free_device_info(remote_dev_info);
1188 } else if (strcasecmp(property, "Trusted") == 0) {
1189 gboolean trusted = FALSE;
1191 g_variant_get(val, "b", &trusted);
1193 event = trusted ? BLUETOOTH_EVENT_DEVICE_AUTHORIZED :
1194 BLUETOOTH_EVENT_DEVICE_UNAUTHORIZED;
1196 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1198 _bt_convert_device_path_to_address(path, address);
1200 BT_DBG("trusted: %d", trusted);
1201 BT_DBG("address: %s", address);
1202 param = g_variant_new("(is)", result, address);
1203 /* Send event to application */
1204 _bt_send_event(BT_DEVICE_EVENT,
1208 } else if (strcasecmp(property, "TrustedProfiles") == 0) {
1211 g_variant_get(val, "u", &trusted);
1213 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1214 _bt_convert_device_path_to_address(path, address);
1216 BT_DBG("Address: %s, TrustedProfiles: %d", address, trusted);
1217 _bt_send_event(BT_DEVICE_EVENT,
1218 BLUETOOTH_EVENT_SUPPORTED_PROFILE_TRUSTED,
1219 g_variant_new("(isi)", result, address, trusted));
1221 } else if (strcasecmp(property, "IpspConnected") == 0) {
1222 gboolean connected = FALSE;
1224 g_variant_get(val, "b", &connected);
1227 event = connected ? BLUETOOTH_EVENT_IPSP_CONNECTED :
1228 BLUETOOTH_EVENT_IPSP_DISCONNECTED;
1230 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1232 _bt_convert_device_path_to_address(path, address);
1234 BT_DBG("Ipspconnected: %d", connected);
1235 BT_DBG("address: %s", address);
1236 param = g_variant_new("(is)", result, address);
1238 /* Send event to application */
1239 _bt_send_event(BT_DEVICE_EVENT,
1243 } else if (strcasecmp(property, "IpspBtInterfaceInfo") == 0) {
1244 char *ifname = NULL;
1246 g_variant_get(val, "s", &ifname);
1248 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1250 _bt_convert_device_path_to_address(path, address);
1252 BT_DBG("Ipsp BT Interface Name: %s", ifname);
1253 BT_DBG("address: %s", address);
1254 param = g_variant_new("(iss)", result, address, ifname);
1256 /* Send event to application */
1257 _bt_send_event(BT_DEVICE_EVENT,
1258 BLUETOOTH_EVENT_IPSP_INTERFACE_INFO,
1266 static void __bt_media_control_changed_event(GVariant *msg, const char *path)
1269 int result = BLUETOOTH_ERROR_NONE;
1270 GVariantIter value_iter;
1271 char *property = NULL;
1273 GVariant *val = NULL;
1274 GVariant *child = NULL;
1275 bt_remote_dev_info_t *remote_dev_info;
1276 GVariant *param = NULL;
1277 g_variant_iter_init(&value_iter, msg);
1278 while ((child = g_variant_iter_next_value(&value_iter))) {
1279 g_variant_get(child, "{sv}", &property, &val);
1280 BT_INFO("Property %s", property);
1281 if (strcasecmp(property, "Connected") == 0) {
1282 gboolean connected = FALSE;
1284 g_variant_get(val, "b", &connected);
1286 event = connected ? BLUETOOTH_EVENT_AVRCP_CONNECTED :
1287 BLUETOOTH_EVENT_AVRCP_DISCONNECTED;
1289 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1291 _bt_convert_device_path_to_address(path, address);
1293 BT_DBG("connected: %d", connected);
1294 BT_DBG("address: %s", address);
1296 remote_dev_info = _bt_get_remote_device_info(address);
1298 if (remote_dev_info != NULL) {
1299 __bt_device_remote_connected_properties(
1300 remote_dev_info, address, connected);
1301 _bt_free_device_info(remote_dev_info);
1303 param = g_variant_new("(is)", result, address);
1304 /* Send event to application */
1305 _bt_send_event(BT_AVRCP_EVENT,
1311 g_variant_unref(child);
1312 g_variant_unref(val);
1317 int get_alert_level_enum(const char *alert)
1321 if (strcmp(alert, "none") == 0)
1322 lvl = BT_PXP_ALERT_NONE;
1323 else if (strcmp(alert, "mild") == 0)
1324 lvl = BT_PXP_ALERT_MILD;
1325 else if (strcmp(alert, "high") == 0)
1326 lvl = BT_PXP_ALERT_HIGH;
1331 static void _bt_handle_pxp_property_changed_event(GVariant *msg, const char *path, int role)
1333 int result = BLUETOOTH_ERROR_NONE;
1336 GVariantIter value_iter;
1337 char *property = NULL;
1339 GVariant *val = NULL;
1340 GVariant *child = NULL;
1341 GVariant *param = NULL;
1342 g_variant_iter_init(&value_iter, msg);
1345 while ((child = g_variant_iter_next_value(&value_iter))) {
1346 g_variant_get(child, "{sv}", &property, &val);
1347 BT_INFO("Property %s", property);
1349 if ((strcasecmp(property, "LinkLossAlertLevel") == 0) ||
1350 (strcasecmp(property, "ImmediateAlertLevel") == 0)) {
1351 char *alert_str = NULL;
1353 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1354 _bt_convert_device_path_to_address(path, address);
1356 if (strcasecmp(property, "LinkLossAlertLevel") == 0)
1357 service_type = BT_PXP_PROPERTY_LLS;
1359 service_type = BT_PXP_PROPERTY_IAS;
1361 g_variant_get(val, "s", &alert_str);
1363 alert_lvl = get_alert_level_enum(alert_str);
1365 param = g_variant_new("(isiii)", result, address,
1366 role, service_type, alert_lvl);
1368 /* Send event to application */
1369 _bt_send_event(BT_DEVICE_EVENT,
1370 BLUETOOTH_EVENT_PXP_PROPERTY_CHANGED,
1376 g_variant_unref(child);
1377 g_variant_unref(val);
1382 void _bt_handle_property_changed_event(GVariant *msg, const char *object_path)
1384 char *interface_name = NULL;
1385 GVariant *val = NULL;
1387 g_variant_get(msg, "(&s@a{sv}@as)", &interface_name, &val, NULL);
1389 if (strcasecmp(interface_name, BT_ADAPTER_INTERFACE) == 0) {
1390 __bt_adapter_property_changed_event(val,
1392 } else if (strcasecmp(interface_name, BT_DEVICE_INTERFACE) == 0) {
1393 __bt_device_property_changed_event(val, object_path);
1394 } else if (strcasecmp(interface_name, BT_OBEX_TRANSFER_INTERFACE) == 0) {
1395 BT_DBG("BT_OBEX_TRANSFER_INTERFACE");
1396 __bt_obex_property_changed_event(val,
1398 } else if (strcasecmp(interface_name, BT_MEDIA_CONTROL_INTERFACE) == 0) {
1399 __bt_media_control_changed_event(val,
1401 } else if (strcasecmp(interface_name, BT_PLAYER_CONTROL_INTERFACE) == 0) {
1402 _bt_handle_avrcp_control_event(val,
1404 } else if (strcasecmp(interface_name, BT_NETWORK_CLIENT_INTERFACE) == 0) {
1405 BT_DBG("BT_NETWORK_CLIENT_INTERFACE");
1406 _bt_handle_network_client_event(val,
1408 } else if (strcasecmp(interface_name, BT_GATT_CHAR_INTERFACE) == 0) {
1409 __bt_gatt_char_property_changed_event(val,
1411 } else if (strcasecmp(interface_name, BT_PROXIMITY_REPORTER_INTERFACE) == 0) {
1412 BT_DBG("BT_PROXIMITY_REPORTER_INTERFACE");
1413 _bt_handle_pxp_property_changed_event(val,
1414 object_path, BT_PXP_REPORTER_ROLE);
1416 g_variant_unref(val);
1419 void __bt_opc_property_changed_event(GVariant *msg,
1422 GVariantIter value_iter;
1423 char *property = NULL;
1424 GVariant *val = NULL;
1425 GVariant *child = NULL;
1427 g_variant_iter_init(&value_iter, msg);
1428 if ((child = g_variant_iter_next_value(&value_iter))) {
1429 g_variant_get(child, "{sv}", &property, &val);
1430 ret_if(property == NULL);
1432 if (strcasecmp(property, "Status") == 0) {
1433 char *status = NULL;
1434 g_variant_get(val, "s", &status);
1435 BT_DBG("Status is %s", status);
1437 if (strcasecmp(status, "active") == 0)
1438 _bt_obex_client_started(path);
1439 else if (strcasecmp(status, "complete") == 0)
1440 _bt_obex_client_completed(path, TRUE);
1441 else if (strcasecmp(status, "error") == 0)
1442 _bt_obex_client_completed(path, FALSE);
1445 } else if (strcasecmp(property, "Transferred") == 0) {
1446 guint64 transferred = 0;
1447 g_variant_get(val, "t", &transferred);
1449 _bt_obex_client_progress(path, transferred);
1451 BT_DBG("property : [%s]", property);
1454 g_variant_unref(child);
1455 g_variant_unref(val);
1459 void _bt_opc_property_changed_event(GVariant *msg, char *path)
1461 char *interface_name = NULL;
1462 GVariant *value = NULL;
1463 g_variant_get(msg, "(&s@a{sv}@as)", &interface_name, &value, NULL);
1464 BT_INFO("interface_name = %s", interface_name);
1465 if (strcasecmp(interface_name, BT_OBEX_TRANSFER_INTERFACE) == 0) {
1466 __bt_opc_property_changed_event(value,
1469 BT_DBG("interface_name : [%s]", interface_name);
1471 g_variant_unref(value);
1475 void __bt_map_property_changed_event(GVariant *msg,
1479 GVariantIter value_iter;
1480 char *property = NULL;
1481 GVariant *val = NULL;
1482 GVariant *child = NULL;
1484 g_variant_iter_init(&value_iter, msg);
1485 while ((child = g_variant_iter_next_value(&value_iter))) {
1486 g_variant_get(child, "{sv}", &property, &val);
1487 ret_if(property == NULL);
1489 if (strcasecmp(property, "Status") == 0) {
1490 char *status = NULL;
1491 g_variant_get(val, "s", &status);
1492 BT_DBG("Status is %s", status);
1494 if (strcasecmp(status, "active") == 0) {
1495 BT_DBG("EVENT : STARTED");
1496 // currently doing nothing
1497 } else if (strcasecmp(status, "complete") == 0) {
1498 BT_DBG("EVENT : COMPLETED");
1499 _bt_map_on_transfer_finished(path, BLUETOOTH_ERROR_NONE);
1500 } else if (strcasecmp(status, "error") == 0) {
1501 BT_DBG("EVENT : FAILED");
1502 _bt_map_on_transfer_finished(path, BLUETOOTH_ERROR_INTERNAL);
1505 } else if (strcasecmp(property, "Transferred") == 0) {
1506 guint64 transferred = 0;
1507 g_variant_get(val, "t", &transferred);
1509 BT_DBG("EVENT : PROGRESS CALLBACK");
1510 // currently doing nothing - progress callback type is not used
1512 BT_DBG("OTHER EVENT : property : [%s]", property);
1515 g_variant_unref(child);
1516 g_variant_unref(val);
1520 void _bt_map_property_changed_event(GVariant *msg, const char *path)
1522 BT_DBG("Entered _bt_map_property_changed_event");
1523 char *interface_name = NULL;
1524 GVariant *value = NULL;
1525 g_variant_get(msg, "(&s@a{sv}@as)", &interface_name, &value, NULL);
1526 BT_INFO("interface_name = %s", interface_name);
1527 if (strcasecmp(interface_name, BT_OBEX_TRANSFER_INTERFACE) == 0) {
1528 __bt_map_property_changed_event(value,
1531 BT_DBG("interface_name : [%s]", interface_name);
1533 g_variant_unref(value);
1537 void _bt_handle_input_event(GVariant *msg, const char *path)
1539 int result = BLUETOOTH_ERROR_NONE;
1540 gboolean property_flag = FALSE;
1541 GVariantIter value_iter;
1542 char *property = NULL;
1543 GVariant *child = NULL, *val = NULL;
1544 bt_remote_dev_info_t *remote_dev_info;
1545 GVariant *param = NULL;
1546 g_variant_iter_init(&value_iter, msg);
1547 while ((child = g_variant_iter_next_value(&value_iter))) {
1548 g_variant_get(child, "{sv}", &property, &val);
1550 ret_if(property == NULL);
1552 if (strcasecmp(property, "Connected") == 0) {
1553 int event = BLUETOOTH_EVENT_NONE;
1555 g_variant_get(val, "b", &property_flag);
1557 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1559 _bt_convert_device_path_to_address(path, address);
1561 event = (property_flag == TRUE) ?
1562 BLUETOOTH_HID_CONNECTED :
1563 BLUETOOTH_HID_DISCONNECTED;
1564 param = g_variant_new("(is)", result, address);
1565 _bt_send_event(BT_HID_EVENT, event,
1567 /* Check HID connection type (Keyboard or Mouse) and update the status */
1568 remote_dev_info = _bt_get_remote_device_info_by_object_path(path);
1570 if (property_flag == TRUE) {
1571 hid_connected_device_count++;
1572 __bt_set_device_values(TRUE,
1573 VCONFKEY_BT_DEVICE_HID_CONNECTED);
1575 hid_connected_device_count--;
1576 if (hid_connected_device_count == 0)
1577 __bt_set_device_values(FALSE,
1578 VCONFKEY_BT_DEVICE_HID_CONNECTED);
1581 if (remote_dev_info != NULL) {
1582 BT_DBG("HID device class [%x]", remote_dev_info->class);
1583 if (remote_dev_info->class &
1584 BLUETOOTH_DEVICE_MINOR_CLASS_KEY_BOARD) {
1585 __bt_set_device_values(property_flag,
1586 VCONFKEY_BT_DEVICE_HID_KEYBOARD_CONNECTED);
1590 if (remote_dev_info->class &
1591 BLUETOOTH_DEVICE_MINOR_CLASS_POINTING_DEVICE) {
1592 __bt_set_device_values(property_flag,
1593 VCONFKEY_BT_DEVICE_HID_MOUSE_CONNECTED);
1595 _bt_free_device_info(remote_dev_info);
1600 g_variant_unref(val);
1601 g_variant_unref(child);
1605 void _bt_handle_network_server_event(GVariant *msg, const char *member)
1607 int result = BLUETOOTH_ERROR_NONE;
1608 char *address = NULL;
1609 char *device = NULL;
1610 GVariant *param = NULL;
1611 ret_if(member == NULL);
1612 if (strcasecmp(member, "PeerConnected") == 0) {
1613 g_variant_get(msg, "(ss)", &device, &address);
1615 __bt_set_device_values(TRUE,
1616 VCONFKEY_BT_DEVICE_PAN_CONNECTED);
1617 param = g_variant_new("(iss)", result, device, address);
1618 _bt_send_event(BT_NETWORK_EVENT, BLUETOOTH_EVENT_NETWORK_SERVER_CONNECTED,
1622 nap_connected_device_count++;
1623 } else if (strcasecmp(member, "PeerDisconnected") == 0) {
1624 g_variant_get(msg, "(ss)", &device, &address);
1625 nap_connected_device_count--;
1626 if (nap_connected_device_count == 0)
1627 __bt_set_device_values(FALSE,
1628 VCONFKEY_BT_DEVICE_PAN_CONNECTED);
1629 param = g_variant_new("(iss)", result, device, address);
1630 _bt_send_event(BT_NETWORK_EVENT, BLUETOOTH_EVENT_NETWORK_SERVER_DISCONNECTED,
1637 void _bt_handle_network_client_event(GVariant *msg,
1642 int result = BLUETOOTH_ERROR_NONE;
1643 gboolean property_flag = FALSE;
1644 char *property = NULL;
1645 GVariant *val = NULL;
1646 GVariantIter value_iter;
1647 GVariant *param = NULL;
1648 g_variant_iter_init(&value_iter, msg);
1649 while ((g_variant_iter_loop(&value_iter, "{sv}", &property, &val))) {
1650 if (strcasecmp(property, "Connected") == 0) {
1651 int event = BLUETOOTH_EVENT_NONE;
1654 g_variant_get(val, "b", &property_flag);
1655 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1657 _bt_convert_device_path_to_address(path, address);
1659 BT_DBG("property_flag %d", property_flag);
1660 if (property_flag == TRUE) {
1661 event = BLUETOOTH_EVENT_NETWORK_CONNECTED;
1662 nap_connected_device_count++;
1663 __bt_set_device_values(TRUE,
1664 VCONFKEY_BT_DEVICE_PAN_CONNECTED);
1666 event = BLUETOOTH_EVENT_NETWORK_DISCONNECTED;
1667 nap_connected_device_count--;
1668 if (nap_connected_device_count == 0)
1669 __bt_set_device_values(FALSE,
1670 VCONFKEY_BT_DEVICE_PAN_CONNECTED);
1672 param = g_variant_new("(is)", result, address);
1673 _bt_send_event(BT_NETWORK_EVENT, event,
1682 void __bt_gatt_char_property_changed_event(GVariant *msg,
1685 GVariantIter value_iter;
1686 char *property = NULL;
1687 GVariant *val = NULL;
1688 g_variant_iter_init(&value_iter, msg);
1689 while ((g_variant_iter_loop(&value_iter, "{sv}", &property, &val))) {
1690 BT_INFO("Property %s", property);
1692 ret_if(property == NULL);
1694 if (strcasecmp(property, "Notifying") == 0) {
1695 gboolean property_flag = FALSE;
1696 g_variant_get(val, "b", &property_flag);
1697 if (property_flag == TRUE)
1698 BT_DBG("notifying is enabled");
1700 BT_DBG("notifying is disabled");
1705 void _bt_handle_gatt_event(GVariant *msg, const char *member, const char *path)
1707 ret_if(path == NULL);
1708 if (strcasecmp(member, "GattValueChanged") == 0) {
1709 /* Check TDS seekers waiting for Indication */
1710 _bt_tds_check_indication(path, msg);
1712 BT_INFO("Unhandled event");
1716 void _bt_handle_device_event(GVariant *msg, const char *member, const char *path)
1719 int result = BLUETOOTH_ERROR_NONE;
1721 char *dev_name = NULL;
1722 const char *property = NULL;
1723 GVariant *param = NULL;
1724 char secure_address[BT_ADDRESS_STRING_SIZE] = { 0 };
1725 ret_if(path == NULL);
1727 if (strcasecmp(member, "PropertyChanged") == 0) {
1729 g_variant_get(msg, "(s)", &property);
1731 ret_if(property == NULL);
1733 if (strcasecmp(property, "GattConnected") == 0) {
1734 gboolean connected = FALSE;
1736 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1738 _bt_convert_device_path_to_address(path, address);
1739 g_variant_get(msg, "(b)", &connected);
1741 event = connected ? BLUETOOTH_EVENT_GATT_CONNECTED :
1742 BLUETOOTH_EVENT_GATT_DISCONNECTED;
1743 param = g_variant_new("(is)", result, address);
1744 _bt_send_event(BT_DEVICE_EVENT,
1748 } else if (strcasecmp(property, "Paired") == 0) {
1749 gboolean paired = FALSE;
1750 bt_remote_dev_info_t *remote_dev_info;
1751 g_variant_get(msg, "(b)", &paired);
1753 ret_if(paired == FALSE);
1755 /* BlueZ sends paired signal for each paired device */
1756 /* during activation, We should ignore this, otherwise*/
1757 /* application thinks that a new device got paired */
1758 if (_bt_adapter_get_status() != BT_ACTIVATED) {
1759 BT_DBG("BT is not activated, so ignore this");
1763 if (_bt_is_device_creating() == TRUE) {
1764 BT_DBG("Try to Pair by me");
1768 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1770 _bt_convert_device_path_to_address(path, address);
1772 remote_dev_info = _bt_get_remote_device_info_by_object_path(path);
1773 if (remote_dev_info == NULL) {
1777 GVariant *uuids = NULL;
1778 GVariantBuilder *builder = NULL;
1780 builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
1781 for (i = 0; i < remote_dev_info->uuid_count; i++) {
1782 g_variant_builder_add(builder, "s",
1783 remote_dev_info->uuids[i]);
1785 uuids = g_variant_new("as", builder);
1786 g_variant_builder_unref(builder);
1787 GVariant *manufacturer_data = NULL;
1788 manufacturer_data = g_variant_new_from_data(
1789 G_VARIANT_TYPE_BYTESTRING,
1790 remote_dev_info->manufacturer_data,
1791 remote_dev_info->manufacturer_data_len,
1793 param = g_variant_new("(isunsbub@asn@ay)", result,
1795 remote_dev_info->class,
1796 remote_dev_info->rssi,
1797 remote_dev_info->name,
1798 remote_dev_info->paired,
1799 remote_dev_info->connected,
1800 remote_dev_info->trust,
1802 remote_dev_info->manufacturer_data_len,
1804 _bt_send_event(BT_ADAPTER_EVENT,
1805 BLUETOOTH_EVENT_BONDING_FINISHED,
1807 _bt_free_device_info(remote_dev_info);
1810 } else if (strcasecmp(property, "UUIDs") == 0) {
1811 /* Once we get the updated uuid information after
1812 * reverse service search, update it to application */
1814 bt_remote_dev_info_t *remote_dev_info;
1816 ret_if(_bt_is_device_creating() == TRUE);
1818 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1820 _bt_convert_device_path_to_address(path, address);
1822 remote_dev_info = _bt_get_remote_device_info_by_object_path(path);
1823 if (remote_dev_info == NULL) {
1828 BT_DBG("UUID's count = %d", remote_dev_info->uuid_count);
1829 if (remote_dev_info->paired && remote_dev_info->uuid_count) {
1830 GVariant *uuids = NULL;
1831 GVariantBuilder *builder = NULL;
1833 builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
1834 for (i = 0; i < remote_dev_info->uuid_count; i++) {
1835 g_variant_builder_add(builder, "s",
1836 remote_dev_info->uuids[i]);
1838 uuids = g_variant_new("as", builder);
1839 g_variant_builder_unref(builder);
1840 GVariant *manufacture_data = g_variant_new_from_data((const GVariantType *)"ay",
1841 remote_dev_info->manufacturer_data, remote_dev_info->manufacturer_data_len,
1844 param = g_variant_new("(isunsbub@asn@ay)", result,
1845 address, remote_dev_info->class,
1846 remote_dev_info->rssi,
1847 remote_dev_info->name,
1848 remote_dev_info->paired,
1849 remote_dev_info->connected,
1850 remote_dev_info->trust,
1852 remote_dev_info->manufacturer_data_len,
1854 _bt_send_event(BT_ADAPTER_EVENT,
1855 BLUETOOTH_EVENT_SERVICE_SEARCHED,
1859 _bt_free_device_info(remote_dev_info);
1862 } else if (strcasecmp(member, "DeviceConnected") == 0) {
1863 unsigned char addr_type = 0;
1865 g_variant_get(msg, "(y)", &addr_type);
1867 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1869 _bt_convert_device_path_to_address(path, address);
1870 dev_name = _bt_get_bonded_device_name(address);
1872 _bt_convert_addr_string_to_secure_string(secure_address, address);
1873 BT_INFO("Address : %s Type : %d", secure_address, addr_type);
1874 BT_ERR_C("### Connected [%s] [%s]", !addr_type ? "BREDR" : "LE",
1875 !addr_type ? dev_name : secure_address);
1878 _bt_logging_connection(TRUE, addr_type);
1879 param = g_variant_new("(isy)", result, address, addr_type);
1880 /*Send event to application*/
1881 _bt_send_event(BT_DEVICE_EVENT,
1882 BLUETOOTH_EVENT_DEVICE_CONNECTED,
1885 } else if (strcasecmp(member, "Disconnected") == 0) {
1886 unsigned char disc_reason = 0;
1887 unsigned char addr_type = 0;
1888 char *dev_name = NULL;
1889 gboolean sending = FALSE;
1891 g_variant_get(msg, "(yys)", &addr_type, &disc_reason, &dev_name);
1893 result = disc_reason;
1895 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1897 _bt_convert_device_path_to_address(path, address);
1899 /* 0x00 BDADDR_BRDER
1900 0x01 BDADDR_LE_PUBLIC
1901 0x02 BDADDR_LE_RANDOM */
1902 _bt_convert_addr_string_to_secure_string(secure_address, address);
1903 BT_INFO("Address : %s Type : %d", secure_address, addr_type);
1904 BT_ERR_C("### Disconnected [%s] [%d : %s] [%s]", !addr_type ? "BREDR" : "LE",
1905 disc_reason, _bt_convert_disc_reason_to_string(disc_reason),
1906 !addr_type ? dev_name : secure_address);
1909 _bt_headset_set_local_connection(FALSE);
1910 _bt_logging_connection(FALSE, addr_type);
1913 #ifdef TIZEN_BT_A2DP_SINK_AUTO_CONNECT
1915 int bt_device_state = VCONFKEY_BT_DEVICE_NONE;
1917 if (vconf_get_int(VCONFKEY_BT_DEVICE, &bt_device_state) != 0)
1918 BT_ERR("vconf_get_int failed");
1920 BT_INFO("conn_state[0x%x], adapter_state [%d]",
1921 bt_device_state, _bt_adapter_get_status());
1923 if (disc_reason == BLUETOOTH_ERROR_CONNECTION_TIMEOUT) {
1924 _bt_audio_start_auto_connect(TRUE);
1925 } else if (bt_device_state &
1926 VCONFKEY_BT_DEVICE_A2DP_SOURCE_CONNECTED) {
1927 BT_INFO("Disconnected due to turning BT off. Skip a address");
1929 char *last_connected = NULL;
1930 last_connected = vconf_get_str(BT_LAST_CONNECTED_DEVICE);
1931 if (!g_strcmp0(address, last_connected))
1932 _bt_audio_set_auto_connect_device_addr("");
1934 free(last_connected);
1939 /*Check for any OPP transfer on the device and cancel
1942 _bt_obex_check_pending_transfer(address);
1943 _bt_opp_client_is_sending(&sending);
1944 if (sending == TRUE)
1945 _bt_opp_client_check_pending_transfer(address);
1946 /* TODO: MAP? see above */
1948 param = g_variant_new("(isy)", result, address, addr_type);
1949 _bt_send_event(BT_DEVICE_EVENT,
1950 BLUETOOTH_EVENT_DEVICE_DISCONNECTED,
1953 } else if (strcasecmp(member, "ProfileStateChanged") == 0) {
1955 char *profile_uuid = NULL;
1956 bt_headset_wait_t *wait_list;
1957 bluetooth_device_address_t bd_addr;
1959 g_variant_get(msg, "(si)", &profile_uuid, &state);
1961 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1963 _bt_convert_device_path_to_address(path, address);
1964 _bt_convert_addr_string_to_type(bd_addr.addr, address);
1966 _bt_convert_addr_string_to_secure_string(secure_address, address);
1967 BT_DBG("Address: %s", secure_address);
1968 BT_DBG("Profile UUID: %s", profile_uuid);
1969 BT_DBG("State: %d", state);
1971 if ((strcmp(profile_uuid, A2DP_SINK_UUID) == 0) &&
1972 (state == BT_PROFILE_STATE_CONNECTED)) {
1974 int event = BLUETOOTH_EVENT_AV_CONNECTED;
1975 #ifndef TIZEN_BT_DUAL_HEADSET_CONNECT
1976 bluetooth_device_address_t device_address;
1977 char connected_address[BT_ADDRESS_STRING_SIZE + 1];
1980 bt_headset_wait_t *wait_list;
1981 guint restricted = 0x0;
1983 __bt_set_device_values(TRUE,
1984 VCONFKEY_BT_DEVICE_A2DP_HEADSET_CONNECTED);
1986 __bt_connection_manager_set_state(address, event);
1988 _bt_get_restrict_profile(&bd_addr, RESTRICTED_PROFILE_HFP_HS, &restricted);
1990 if (_bt_headset_get_local_connection() == FALSE) {
1991 if (restricted == 0x0) /* not restricted*/
1992 _bt_start_timer_for_connection(address, BT_AUDIO_HSP);
1994 /* Connection Started from local device therefore no need to
1995 * intiate connection for pending profile */
1996 _bt_headset_set_local_connection(FALSE);
1998 param = g_variant_new("(is)", result, address);
1999 _bt_send_event(BT_HEADSET_EVENT, event,
2001 #ifdef TIZEN_BT_DUAL_HEADSET_CONNECT
2002 _bt_check_already_connected_headset(BT_AUDIO_A2DP,
2005 connected = _bt_is_headset_type_connected(BT_AUDIO_A2DP,
2008 if (g_strcmp0(connected_address, address) != 0) {
2009 _bt_convert_addr_string_to_type(
2010 device_address.addr,
2012 _bt_audio_disconnect(0, BT_AUDIO_A2DP,
2013 &device_address, NULL);
2017 _bt_add_headset_to_list(BT_AUDIO_A2DP,
2018 BT_STATE_CONNECTED, address);
2020 wait_list = _bt_get_audio_wait_data();
2021 if (wait_list != NULL &&
2022 (g_strcmp0(wait_list->address, address) == 0))
2023 _bt_rel_wait_data();
2025 } else if ((strcmp(profile_uuid, A2DP_SINK_UUID) == 0) &&
2026 (state == BT_PROFILE_STATE_DISCONNECTED)) {
2028 int event = BLUETOOTH_EVENT_AV_DISCONNECTED;
2030 if (!_bt_is_service_connected(address, BT_AUDIO_A2DP)) {
2032 g_free(profile_uuid);
2036 __bt_set_device_values(FALSE,
2037 VCONFKEY_BT_DEVICE_A2DP_HEADSET_CONNECTED);
2039 __bt_connection_manager_set_state(address, event);
2040 param = g_variant_new("(is)", result, address);
2041 _bt_send_event(BT_HEADSET_EVENT, event,
2043 /* Remove data from the connected list */
2044 _bt_remove_headset_from_list(BT_AUDIO_A2DP, address);
2045 wait_list = _bt_get_audio_wait_data();
2047 if (wait_list == NULL) {
2049 g_free(profile_uuid);
2053 if (((wait_list->type == BT_AUDIO_ALL) &&
2054 (wait_list->ag_flag == TRUE)) ||
2055 (wait_list->type == BT_AUDIO_A2DP) ||
2056 (wait_list->disconnection_type == BT_AUDIO_A2DP)) {
2057 bluetooth_device_address_t device_address;
2058 _bt_convert_addr_string_to_type(
2059 device_address.addr,
2060 wait_list->address);
2062 _bt_audio_connect(wait_list->req_id,
2067 } else if (strcmp(profile_uuid, AVRCP_TARGET_UUID) == 0) {
2069 if (state == BT_PROFILE_STATE_CONNECTED) {
2070 int event = BLUETOOTH_EVENT_AVRCP_CONTROL_CONNECTED;
2071 char connected_address[BT_ADDRESS_STRING_SIZE + 1];
2072 bluetooth_device_address_t device_address;
2074 param = g_variant_new("(is)", result, address);
2075 _bt_send_event(BT_AVRCP_CONTROL_EVENT, event,
2077 connected = _bt_is_headset_type_connected(
2081 if (g_strcmp0(connected_address,
2083 _bt_convert_addr_string_to_type(
2084 device_address.addr,
2086 _bt_audio_disconnect(0,
2088 &device_address, NULL);
2091 BT_DBG("device Path: %s", path);
2092 _bt_add_headset_to_list(BT_AVRCP,
2093 BT_STATE_CONNECTED, address);
2094 } else if (state == BT_PROFILE_STATE_DISCONNECTED) {
2095 int event = BLUETOOTH_EVENT_AVRCP_CONTROL_DISCONNECTED;
2096 param = g_variant_new("(is)", result, address);
2097 _bt_send_event(BT_AVRCP_CONTROL_EVENT, event,
2099 /* Remove data from the connected list */
2100 _bt_remove_headset_from_list(BT_AVRCP, address);
2102 } else if (strcasecmp(profile_uuid, A2DP_SOURCE_UUID) == 0) {
2103 if (state == BT_PROFILE_STATE_CONNECTED) {
2104 int event = BLUETOOTH_EVENT_AV_SOURCE_CONNECTED;
2105 BT_INFO("A2DP Source is connected");
2106 #ifdef TIZEN_BT_A2DP_SINK_ENABLE
2107 __bt_set_device_values(TRUE,
2108 VCONFKEY_BT_DEVICE_A2DP_SOURCE_CONNECTED);
2111 #ifdef TIZEN_BT_A2DP_SINK_AUTO_CONNECT
2112 _bt_audio_set_auto_connect_device_addr(address);
2113 _bt_audio_stop_auto_connect();
2115 _bt_add_headset_to_list(BT_AUDIO_A2DP_SOURCE,
2116 BT_STATE_CONNECTED, address);
2117 _bt_send_event(BT_A2DP_SOURCE_EVENT, event,
2118 g_variant_new("(is)", result, address));
2119 } else if (state == BT_PROFILE_STATE_DISCONNECTED) {
2120 int event = BLUETOOTH_EVENT_AV_SOURCE_DISCONNECTED;
2121 BT_INFO("A2DP Source Disconnected");
2122 #ifdef TIZEN_BT_A2DP_SINK_ENABLE
2123 __bt_set_device_values(FALSE,
2124 VCONFKEY_BT_DEVICE_A2DP_SOURCE_CONNECTED);
2126 _bt_remove_headset_from_list(BT_AUDIO_A2DP_SOURCE, address);
2127 _bt_send_event(BT_A2DP_SOURCE_EVENT, event,
2128 g_variant_new("(is)", result, address));
2130 wait_list = _bt_get_audio_wait_data();
2131 if (wait_list && wait_list->type == BT_AUDIO_A2DP_SOURCE) {
2132 bluetooth_device_address_t device_address;
2133 _bt_convert_addr_string_to_type(
2134 device_address.addr,
2135 wait_list->address);
2137 _bt_audio_connect(wait_list->req_id,
2141 /* Now free the wait list */
2142 _bt_rel_wait_data();
2145 } else if ((strcmp(profile_uuid, HID_UUID) == 0) &&
2146 ((state == BT_PROFILE_STATE_CONNECTED) ||
2147 (state == BT_PROFILE_STATE_DISCONNECTED))) {
2149 if (state == BT_PROFILE_STATE_CONNECTED)
2150 event = BLUETOOTH_HID_CONNECTED;
2152 event = BLUETOOTH_HID_DISCONNECTED;
2153 param = g_variant_new("(is)", result, address);
2154 _bt_send_event(BT_HID_EVENT, event,
2157 /* Set the vconf value for device */
2158 if (state == BT_PROFILE_STATE_CONNECTED) {
2159 hid_connected_device_count++;
2160 __bt_set_device_values(TRUE,
2161 VCONFKEY_BT_DEVICE_HID_CONNECTED);
2163 hid_connected_device_count--;
2164 if (hid_connected_device_count == 0)
2165 __bt_set_device_values(FALSE,
2166 VCONFKEY_BT_DEVICE_HID_CONNECTED);
2168 } else if (strcmp(profile_uuid, HID_DEVICE_UUID) == 0) {
2169 if (state == BT_PROFILE_STATE_CONNECTED) {
2171 event = BLUETOOTH_HID_DEVICE_CONNECTED;
2172 param = g_variant_new("(is)", result, address);
2173 _bt_send_event(BT_HID_DEVICE_EVENT, event,
2175 } else if (state == BT_PROFILE_STATE_DISCONNECTED) {
2176 event = BLUETOOTH_HID_DEVICE_DISCONNECTED;
2177 param = g_variant_new("(is)", result, address);
2178 _bt_send_event(BT_HID_DEVICE_EVENT, event,
2183 g_free(profile_uuid);
2184 } else if (strcasecmp(member, "AdvReport") == 0) {
2186 bt_remote_le_dev_info_t *le_dev_info = NULL;
2187 char *buffer = NULL;
2189 bt_le_adv_info_t *adv_info = NULL;
2190 GVariant *value = NULL;
2191 ret_if(_bt_is_le_scanning() == FALSE);
2193 le_dev_info = g_malloc0(sizeof(bt_remote_le_dev_info_t));
2195 g_variant_get(msg, "(syyii@ay)", &le_dev_info->address,
2196 &le_dev_info->addr_type,
2197 &le_dev_info->adv_type,
2199 &le_dev_info->adv_data_len,
2202 ret_if(value == NULL);
2204 _bt_convert_device_path_to_address(path, le_dev_info->address);
2206 buffer_len = g_variant_get_size(value);
2208 buffer = (char *)g_variant_get_data(value);
2210 le_dev_info->adv_data = g_memdup(buffer, buffer_len);
2211 if (le_dev_info->adv_data == NULL &&
2212 le_dev_info->adv_type != BT_LE_ADV_SCAN_RSP) {
2213 _bt_free_le_device_info(le_dev_info);
2214 g_variant_unref(value);
2218 if (_bt_get_le_scan_type() == BT_LE_PASSIVE_SCAN) {
2219 _bt_send_scan_result_event(le_dev_info, NULL);
2220 _bt_free_le_device_info(le_dev_info);
2221 g_variant_unref(value);
2225 if (le_dev_info->adv_type != BT_LE_ADV_SCAN_RSP) { /* ADV_IND */
2226 adv_info = g_malloc0(sizeof(bt_le_adv_info_t));
2227 adv_info->addr = g_strdup(le_dev_info->address);
2228 adv_info->addr_type = le_dev_info->addr_type;
2229 adv_info->rssi = le_dev_info->rssi;
2230 adv_info->data_len = le_dev_info->adv_data_len;
2231 adv_info->data = g_malloc0(le_dev_info->adv_data_len);
2232 memcpy(adv_info->data, le_dev_info->adv_data,
2233 le_dev_info->adv_data_len);
2235 if (__bt_add_adv_ind_info(adv_info) == 0) {
2236 adv_info->timer_id = g_timeout_add(1000,
2237 (GSourceFunc)__bt_adv_scan_req_timeout_cb, (void*)adv_info);
2239 } else { /* SCAN_RSP */
2240 adv_info = __bt_get_adv_ind_info(le_dev_info->address);
2242 _bt_send_scan_result_event(le_dev_info, adv_info);
2243 __bt_del_adv_ind_info(le_dev_info->address);
2246 _bt_free_le_device_info(le_dev_info);
2247 g_variant_unref(value);
2248 } else if (strcasecmp(member, "LEDataLengthChanged") == 0) {
2249 guint16 tx_octets = 0;
2250 guint16 tx_time = 0;
2251 guint16 rx_octets = 0;
2252 guint16 rx_time = 0;
2254 g_variant_get(msg, "(qqqq)",
2255 &tx_octets, &tx_time, &rx_octets, &rx_time);
2257 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
2258 _bt_convert_device_path_to_address(path, address);
2260 param = g_variant_new("(isqqqq)", result, address, tx_octets, tx_time,
2261 rx_octets, rx_time);
2262 /* Send event to application */
2263 _bt_send_event(BT_DEVICE_EVENT,
2264 BLUETOOTH_EVENT_LE_DATA_LENGTH_CHANGED, param);
2266 } else if (strcasecmp(member, "IpspStateChanged") == 0) {
2267 gboolean connected = FALSE;
2268 char *ifname = NULL;
2269 GVariant *ipsp_param = NULL;
2271 g_variant_get(msg, "(bs)", &connected, &ifname);
2273 event = connected ? BLUETOOTH_EVENT_IPSP_CONNECTED :
2274 BLUETOOTH_EVENT_IPSP_DISCONNECTED;
2276 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
2277 _bt_convert_device_path_to_address(path, address);
2279 BT_DBG("Ipsp BT Interface Name: %s", ifname);
2280 BT_DBG("address: %s", address);
2281 param = g_variant_new("(iss)", result, address, ifname);
2282 ipsp_param = g_variant_new("(ss)", ifname, address);
2285 GDBusProxy *ipsp_proxy;
2287 BT_DBG("IPSP connected, Set Ipv6 Addr");
2288 ipsp_proxy = _bt_get_ipsp_proxy();
2289 if (ipsp_proxy == NULL) {
2290 BT_ERR("can not get ipsp proxy");
2294 g_dbus_proxy_call(ipsp_proxy, "SetIpv6Addr",
2295 ipsp_param, G_DBUS_CALL_FLAGS_NONE,
2296 -1, NULL, NULL, NULL);
2298 BT_DBG("IPSP disconnected");
2299 ipsp_proxy = _bt_get_ipsp_proxy();
2300 if (ipsp_proxy == NULL) {
2301 BT_ERR("can not get ipsp proxy");
2305 g_dbus_proxy_call(ipsp_proxy, "DisableIpsp",
2306 NULL, G_DBUS_CALL_FLAGS_NONE,
2307 -1, NULL, NULL, NULL);
2310 /* Send event to application */
2311 _bt_send_event(BT_DEVICE_EVENT,
2315 } else if (strcasecmp(member, "AttMtuChanged") == 0) {
2316 int result = BLUETOOTH_ERROR_NONE;
2320 g_variant_get(msg, "(q)", &mtu);
2322 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
2324 _bt_convert_device_path_to_address(path, address);
2325 _bt_convert_addr_string_to_secure_string(secure_address, address);
2326 BT_DBG("Address : %s MTU changed : %d", secure_address, mtu);
2328 param = g_variant_new("(isqy)",
2334 /* Send the event to application */
2335 _bt_send_event(BT_DEVICE_EVENT,
2336 BLUETOOTH_EVENT_GATT_ATT_MTU_CHANGED,
2343 void __bt_set_audio_values(gboolean connected, char *address)
2346 int bt_device_state = VCONFKEY_BT_DEVICE_NONE;
2348 /* Set the headset name */
2349 if (connected == TRUE)
2350 name = _bt_get_bonded_device_name(address);
2352 name = g_strdup("");
2354 if (vconf_set_str(VCONFKEY_BT_HEADSET_NAME, name) != 0)
2355 BT_ERR("vconf_set_str failed");
2359 /* Set the headset state */
2360 if (vconf_get_int(VCONFKEY_BT_DEVICE, &bt_device_state) != 0)
2361 BT_ERR("vconf_get_int failed");
2363 #ifdef TIZEN_SUPPORT_DUAL_HF
2364 if ((connected == TRUE) &&
2365 (FALSE == __bt_is_companion_device(address))) {
2366 bt_device_state |= VCONFKEY_BT_DEVICE_HEADSET_CONNECTED;
2367 } else if ((bt_device_state & VCONFKEY_BT_DEVICE_HEADSET_CONNECTED) &&
2368 (FALSE == __bt_is_companion_device(address))) {
2369 bt_device_state ^= VCONFKEY_BT_DEVICE_HEADSET_CONNECTED;
2372 if (connected == TRUE)
2373 bt_device_state |= VCONFKEY_BT_DEVICE_HEADSET_CONNECTED;
2374 else if (bt_device_state & VCONFKEY_BT_DEVICE_HEADSET_CONNECTED)
2375 bt_device_state ^= VCONFKEY_BT_DEVICE_HEADSET_CONNECTED;
2378 if (vconf_set_int(VCONFKEY_BT_DEVICE,
2379 bt_device_state) != 0) {
2380 BT_ERR("vconf_set_int failed");
2384 void _bt_handle_headset_event(GVariant *msg, const char *path)
2386 int result = BLUETOOTH_ERROR_NONE;
2387 gboolean property_flag = FALSE;
2388 char *property = NULL;
2389 GVariant *value = NULL;
2390 GVariant *param = NULL;
2391 g_variant_get(msg, "(sv)", &property, &value);
2392 bluetooth_device_address_t bd_addr;
2394 ret_if(property == NULL);
2396 BT_DBG("Property = %s \n", property);
2397 /* We allow only 1 headset connection (HSP or HFP)*/
2398 if (strcasecmp(property, "Connected") == 0) {
2399 int event = BLUETOOTH_EVENT_NONE;
2400 bt_headset_wait_t *wait_list;
2402 guint restricted = 0x0;
2403 g_variant_get(value, "b", &property_flag);
2405 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
2407 _bt_convert_device_path_to_address(path, address);
2408 _bt_convert_addr_string_to_type(bd_addr.addr, address);
2410 if (property_flag == TRUE) {
2411 event = BLUETOOTH_EVENT_AG_CONNECTED;
2412 _bt_get_restrict_profile(&bd_addr, RESTRICTED_PROFILE_A2DP, &restricted);
2414 if (_bt_headset_get_local_connection() == FALSE) {
2415 if (restricted == 0x0) /* not restricted*/
2416 _bt_start_timer_for_connection(address, BT_AUDIO_A2DP);
2418 _bt_headset_set_local_connection(FALSE);
2422 event = BLUETOOTH_EVENT_AG_DISCONNECTED;
2424 previous_state = _bt_get_device_state_from_list(BT_AUDIO_HSP, address);
2425 if (previous_state == BT_STATE_DISCONNECTING)
2426 _bt_send_hf_local_term_event(address);
2428 /* Set the State machine here */
2429 __bt_connection_manager_set_state(address, event);
2430 __bt_set_audio_values(property_flag, address);
2431 param = g_variant_new("(is)", result, address);
2432 _bt_send_event(BT_HEADSET_EVENT, event,
2435 if (event == BLUETOOTH_EVENT_AG_DISCONNECTED) {
2436 /* Remove data from the connected list */
2437 _bt_remove_headset_from_list(BT_AUDIO_HSP, address);
2439 wait_list = _bt_get_audio_wait_data();
2440 if (wait_list == NULL) {
2445 bluetooth_device_address_t device_address;
2447 _bt_set_audio_wait_data_flag(TRUE);
2449 _bt_convert_addr_string_to_type(device_address.addr,
2450 wait_list->address);
2451 _bt_audio_connect(wait_list->req_id, wait_list->type,
2452 &device_address, NULL);
2453 _bt_rel_wait_data();
2454 } else if (event == BLUETOOTH_EVENT_AG_CONNECTED) {
2455 /* Add data to the connected list */
2456 _bt_add_headset_to_list(BT_AUDIO_HSP,
2457 BT_STATE_CONNECTED, address);
2459 wait_list = _bt_get_audio_wait_data();
2460 if (wait_list != NULL &&
2461 (g_strcmp0(wait_list->address, address) == 0))
2462 _bt_rel_wait_data();
2464 BT_INFO("Check A2DP pending connect");
2465 _bt_audio_check_pending_connect();
2468 } else if (strcasecmp(property, "State") == 0) {
2471 g_variant_get(value, "s", &state);
2473 /* This code assumes we support only 1 headset connection */
2474 /* Need to use the headset list, if we support multi-headsets */
2475 if (strcasecmp(state, "Playing") == 0) {
2476 BT_DBG("Playing: Sco Connected");
2477 } else if (strcasecmp(state, "connected") == 0 ||
2478 strcasecmp(state, "disconnected") == 0) {
2479 BT_DBG("connected/disconnected: Sco Disconnected");
2481 BT_ERR("Not handled state - %s", state);
2486 } else if (strcasecmp(property, "SpeakerGain") == 0) {
2490 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
2492 _bt_convert_device_path_to_address(path, address);
2494 spkr_gain = g_variant_get_uint16(value);
2496 BT_DBG("spkr_gain: %d", spkr_gain);
2498 param = g_variant_new("(i&sq)", result, address, spkr_gain);
2499 _bt_send_event(BT_HEADSET_EVENT, BLUETOOTH_EVENT_AG_SPEAKER_GAIN,
2503 } else if (strcasecmp(property, "MicrophoneGain") == 0) {
2507 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
2509 _bt_convert_device_path_to_address(path, address);
2511 mic_gain = g_variant_get_uint16(value);
2513 param = g_variant_new("(i&sq)", result, address, mic_gain);
2514 _bt_send_event(BT_HEADSET_EVENT, BLUETOOTH_EVENT_AG_MIC_GAIN,
2521 g_variant_unref(value);
2524 void _bt_handle_sink_event(GVariant *msg, const char *path)
2526 GVariantIter value_iter;
2527 char *property = NULL;
2529 bt_headset_wait_t *wait_list;
2531 GVariant *child = NULL;
2532 GVariant *val = NULL;
2533 GVariant *param = NULL;
2534 g_variant_iter_init(&value_iter, msg);
2535 while ((child = g_variant_iter_next_value(&value_iter))) {
2537 g_variant_get(child, "{sv}", &property, &val);
2539 ret_if(property == NULL);
2541 BT_DBG("Property = %s \n", property);
2544 if (strcasecmp(property, "State") == 0) {
2545 int result = BLUETOOTH_ERROR_NONE;
2548 g_variant_get(val, "s", &value);
2549 BT_DBG("value: %s", value);
2551 if (g_strcmp0(value, "disconnected") == 0) {
2554 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
2556 _bt_convert_device_path_to_address(path, address);
2558 __bt_set_device_values(FALSE,
2559 VCONFKEY_BT_DEVICE_A2DP_HEADSET_CONNECTED);
2560 param = g_variant_new("(is)", result, address);
2561 _bt_send_event(BT_HEADSET_EVENT,
2562 BLUETOOTH_EVENT_AV_DISCONNECTED,
2565 /* Remove data from the connected list */
2566 _bt_remove_headset_from_list(BT_AUDIO_A2DP, address);
2567 wait_list = _bt_get_audio_wait_data();
2568 if (wait_list == NULL) {
2571 g_variant_unref(val);
2572 g_variant_unref(child);
2577 if (((wait_list->type == BT_AUDIO_ALL) &&
2578 (wait_list->ag_flag == TRUE)) ||
2579 (wait_list->type == BT_AUDIO_A2DP) ||
2580 (wait_list->disconnection_type == BT_AUDIO_A2DP)) {
2581 bluetooth_device_address_t device_address;
2582 _bt_convert_addr_string_to_type(
2583 device_address.addr,
2584 wait_list->address);
2586 _bt_audio_connect(wait_list->req_id,
2592 } else if (strcasecmp(value, "Connected") == 0) {
2594 char connected_address[BT_ADDRESS_STRING_SIZE + 1];
2595 bluetooth_device_address_t device_address;
2598 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
2600 _bt_convert_device_path_to_address(path, address);
2602 __bt_set_device_values(TRUE,
2603 VCONFKEY_BT_DEVICE_A2DP_HEADSET_CONNECTED);
2604 param = g_variant_new("(is)", result, address);
2605 _bt_send_event(BT_HEADSET_EVENT,
2606 BLUETOOTH_EVENT_AV_CONNECTED,
2608 /* Check for existing Media device to disconnect */
2609 connected = _bt_is_headset_type_connected(BT_AUDIO_A2DP,
2612 /* Match connected device address */
2613 if (g_strcmp0(connected_address, address) != 0) {
2614 /* Convert BD adress from string type */
2615 _bt_convert_addr_string_to_type(
2616 device_address.addr,
2618 _bt_audio_disconnect(0, BT_AUDIO_A2DP,
2619 &device_address, NULL);
2623 /* Add data to the connected list */
2624 _bt_add_headset_to_list(BT_AUDIO_A2DP,
2625 BT_STATE_CONNECTED, address);
2632 g_variant_unref(val);
2633 g_variant_unref(child);
2637 void _bt_handle_agent_event(GVariant *msg, const char *member)
2639 int result = BLUETOOTH_ERROR_NONE;
2640 char *address = NULL;
2643 GVariant *param = NULL;
2644 ret_if(member == NULL);
2646 if (strcasecmp(member, "ObexAuthorize") == 0) {
2647 __bt_get_agent_signal_info(msg, &address, &name, &uuid);
2648 param = g_variant_new("(iss)", result, address, name);
2649 _bt_send_event(BT_OPP_SERVER_EVENT,
2650 BLUETOOTH_EVENT_OBEX_SERVER_CONNECTION_AUTHORIZE,
2652 /* TODO: MAP? see above */
2655 } else if (strcasecmp(member, "RfcommAuthorize") == 0) {
2656 bt_rfcomm_server_info_t *server_info;
2658 __bt_get_agent_signal_info(msg, &address, &name, &uuid);
2660 server_info = _bt_rfcomm_get_server_info_using_uuid(uuid);
2661 ret_if(server_info == NULL);
2662 ret_if(server_info->server_type != BT_CUSTOM_SERVER);
2663 param = g_variant_new("(isssn)", result, address, uuid, name,
2664 server_info->control_fd);
2665 _bt_send_event(BT_RFCOMM_SERVER_EVENT,
2666 BLUETOOTH_EVENT_RFCOMM_AUTHORIZE,
2674 void _bt_handle_tds_provider_event(GVariant *msg, const char *member, const char *path)
2676 BT_INFO("member: %s, path: %s", member, path);
2678 ret_if(path == NULL);
2680 if (strcasecmp(member, "TdsActivationRequested") == 0) {
2681 GVariant *value = NULL;
2683 unsigned char *buffer = NULL;
2684 unsigned char org_id;
2686 g_variant_get(msg, "(y@ay)", &org_id, &value);
2687 BT_DBG("org_id: %.2x", org_id);
2688 len = g_variant_get_size(value);
2691 buffer = (unsigned char *)g_variant_get_data(value);
2692 for (i = 0; i < len; i++)
2693 BT_DBG("%.2x", buffer[i]);
2696 /* Send event only registered client */
2697 _bt_tds_handle_activation_request(path, org_id, buffer, len);
2698 g_variant_unref(value);
2702 static int __bt_get_object_path(GVariant *msg, char **path)
2704 g_variant_get(msg, "(o*)", path, NULL);
2706 return BLUETOOTH_ERROR_INTERNAL;
2708 return BLUETOOTH_ERROR_NONE;
2711 static void __bt_devices_list_free(void)
2713 bt_cache_info_t *cache_info;
2716 node = g_list_first(p_cache_list);
2718 while (node != NULL) {
2719 cache_info = (bt_cache_info_t *)node->data;
2720 p_cache_list = g_list_remove(p_cache_list, cache_info);
2721 __bt_free_cache_info(cache_info);
2723 node = g_list_next(node);
2727 static int __bt_parse_event(GVariant *msg)
2731 char *interface_name = NULL;
2732 GVariant *inner_iter = NULL;
2734 g_variant_iter_init(&iter, msg);
2736 while ((child = g_variant_iter_next_value(&iter))) {
2737 g_variant_get(child, "{&s@a{sv}}", &interface_name, &inner_iter);
2738 if (g_strcmp0(interface_name,
2739 BT_DEVICE_INTERFACE) == 0) {
2740 g_variant_unref(inner_iter);
2741 g_variant_unref(child);
2742 return BT_DEVICE_EVENT;
2743 } else if (g_strcmp0(interface_name,
2744 BT_MEDIATRANSPORT_INTERFACE) == 0) {
2745 g_variant_unref(inner_iter);
2746 g_variant_unref(child);
2747 return BT_MEDIA_TRANSFER_EVENT;
2748 } else if (g_strcmp0(interface_name,
2749 BT_PLAYER_CONTROL_INTERFACE) == 0) {
2750 g_variant_unref(inner_iter);
2751 g_variant_unref(child);
2752 return BT_AVRCP_CONTROL_EVENT;
2754 g_variant_unref(inner_iter);
2755 g_variant_unref(child);
2761 static void __bt_manager_event_filter(GDBusConnection *connection,
2762 const gchar *sender_name,
2763 const gchar *object_path,
2764 const gchar *interface_name,
2765 const gchar *signal_name,
2766 GVariant *parameters,
2769 bt_event_type_t bt_event = 0x00;
2770 int result = BLUETOOTH_ERROR_NONE;
2772 char *obj_path = NULL;
2773 GVariant *param = NULL;
2774 if (signal_name == NULL)
2776 if (strcasecmp(signal_name, "InterfacesAdded") == 0) {
2777 g_variant_get(parameters, "(&o@a{sa{sv}})", &obj_path, &value);
2779 if (strcasecmp(obj_path, BT_BLUEZ_HCI_PATH) == 0) {
2780 if (TIZEN_FEATURE_BT_USB_DONGLE) {
2781 BT_DBG("Enable Adapter");
2782 _bt_enable_adapter();
2784 _bt_handle_adapter_added();
2787 bt_event = __bt_parse_event(value);
2788 if (bt_event == BT_DEVICE_EVENT) {
2789 bt_cache_info_t *cache_info;
2790 bt_remote_dev_info_t *dev_info;
2791 #ifdef TIZEN_FEATURE_BT_DPM
2792 int desktop_state = DPM_BT_ERROR;
2794 ret_if(_bt_is_discovering() == FALSE &&
2795 _bt_is_le_scanning() == FALSE);
2797 cache_info = g_malloc0(sizeof(bt_cache_info_t));
2799 dev_info = g_malloc0(sizeof(bt_remote_dev_info_t));
2801 cache_info->dev_info = dev_info;
2803 if (__bt_parse_interface(parameters, dev_info) == FALSE) {
2804 BT_ERR("Fail to parse the properies");
2805 __bt_free_cache_info(cache_info);
2806 g_variant_unref(value);
2810 if (dev_info->addr_type != BDADDR_BREDR) {
2811 /* Whenever emit the property changed from bluez,
2812 some property doesn't reach to bt-service.
2813 So LE device is handled as AdvReport signal */
2814 __bt_free_cache_info(cache_info);
2815 g_variant_unref(value);
2819 if (dev_info->name == NULL)
2820 /* If Remote device name is NULL or still RNR is not done
2821 * then display address as name.
2823 dev_info->name = g_strdup(dev_info->address);
2825 #ifdef TIZEN_FEATURE_BT_DPM
2826 _bt_dpm_get_bluetooth_desktop_connectivity_state(&desktop_state);
2827 if (desktop_state == DPM_RESTRICTED) {
2828 bluetooth_device_class_t device_class;
2829 _bt_divide_device_class(&device_class, dev_info->class);
2830 BT_DBG("[%s]device_class.major_class : %d", dev_info->name, device_class.major_class);
2832 if (device_class.major_class ==
2833 BLUETOOTH_DEVICE_MAJOR_CLASS_COMPUTER) {
2834 __bt_free_cache_info(cache_info);
2835 g_variant_unref(value);
2841 GVariant *uuids = NULL;
2842 GVariantBuilder *builder = NULL;
2844 builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
2845 for (i = 0; i < dev_info->uuid_count; i++) {
2846 g_variant_builder_add(builder, "s",
2847 dev_info->uuids[i]);
2849 uuids = g_variant_new("as", builder);
2850 g_variant_builder_unref(builder);
2851 GVariant *manufacturer_data = NULL;
2852 manufacturer_data = g_variant_new_from_data(
2853 G_VARIANT_TYPE_BYTESTRING,
2854 dev_info->manufacturer_data,
2855 dev_info->manufacturer_data_len,
2857 param = g_variant_new("(isunsbub@asn@ay)", result,
2863 dev_info->connected,
2866 dev_info->manufacturer_data_len,
2868 _bt_send_event(BT_ADAPTER_EVENT,
2869 BLUETOOTH_EVENT_REMOTE_DEVICE_FOUND,
2871 p_cache_list = g_list_append(p_cache_list, cache_info);
2872 } else if (bt_event == BT_AVRCP_CONTROL_EVENT) {
2873 BT_DBG("Device path : %s ", obj_path);
2874 _bt_set_control_device_path(obj_path);
2877 g_variant_unref(value);
2878 } else if (strcasecmp(signal_name, "InterfacesRemoved") == 0) {
2879 if (TIZEN_FEATURE_BT_USB_DONGLE) {
2880 BT_DBG("InterfacesRemoved");
2881 _bt_handle_adapter_removed();
2883 if (g_strcmp0(interface_name, BT_MEDIATRANSPORT_INTERFACE) == 0)
2884 bt_event = BT_MEDIA_TRANSFER_EVENT;
2885 else if (g_strcmp0(interface_name, BT_DEVICE_INTERFACE) == 0)
2886 bt_event = BT_DEVICE_EVENT;
2887 else if (g_strcmp0(interface_name, BT_PLAYER_CONTROL_INTERFACE) == 0)
2888 bt_event = BT_AVRCP_CONTROL_EVENT;
2890 if ((bt_event != 0) && (bt_event != BT_MEDIA_TRANSFER_EVENT)) {
2891 _bt_handle_adapter_event(parameters, signal_name);
2892 if (bt_event == BT_AVRCP_CONTROL_EVENT) {
2893 BT_INFO("Object Path %s", obj_path);
2894 _bt_remove_control_device_path(obj_path);
2897 } else if (strcasecmp(signal_name, "NameOwnerChanged") == 0) {
2900 char *previous = NULL;
2901 char *current = NULL;
2903 if (__bt_get_owner_info(parameters, &name, &previous, ¤t)) {
2904 BT_ERR("Fail to get the owner info");
2908 if (*current != '\0') {
2917 if (strcasecmp(name, BT_BLUEZ_NAME) == 0) {
2918 BT_INFO_C("### Bluetoothd is terminated");
2919 if (_bt_adapter_get_status() != BT_DEACTIVATING &&
2920 _bt_adapter_get_status() != BT_DEACTIVATED) {
2921 BT_INFO_C("### Recover it");
2922 _bt_recover_adapter();
2924 _bt_handle_adapter_removed();
2925 __bt_devices_list_free();
2928 _bt_obex_server_check_allocation(&value);
2930 if (value == TRUE) {
2931 /* Check if the obex server was terminated abnormally */
2932 _bt_obex_server_check_termination(name);
2935 _bt_rfcomm_server_check_existence(&value);
2937 if (value == TRUE) {
2938 /* The obex server was terminated abnormally */
2939 _bt_rfcomm_server_check_termination(name);
2942 /* Stop advertising started by terminated process */
2943 _bt_stop_advertising_by_terminated_process(name);
2945 _bt_stop_le_scan(name);
2947 /* Stop the Proximity reporter service */
2948 _bt_proximity_reporter_stop_by_terminated_process(name);
2950 /* Stop the Transport Discovery service */
2951 _bt_tds_stop_by_terminated_process(name);
2956 } else if (g_strcmp0(interface_name, BT_PROPERTIES_INTERFACE) == 0) {
2957 const char *path = object_path;
2959 if (strncmp(path, BT_MEDIA_OBJECT_PATH,
2960 strlen(BT_MEDIA_OBJECT_PATH)) == 0)
2963 _bt_handle_property_changed_event(parameters, object_path);
2964 } else if (g_strcmp0(interface_name, BT_ADAPTER_INTERFACE) == 0) {
2965 _bt_handle_adapter_event(parameters, signal_name);
2966 } else if (g_strcmp0(interface_name, BT_INPUT_INTERFACE) == 0) {
2967 _bt_handle_input_event(parameters, object_path);
2968 } else if (g_strcmp0(interface_name, BT_NETWORK_SERVER_INTERFACE) == 0) {
2969 _bt_handle_network_server_event(parameters, signal_name);
2970 } else if (g_strcmp0(interface_name, BT_HEADSET_INTERFACE) == 0) {
2971 _bt_handle_headset_event(parameters, object_path);
2972 } else if (g_strcmp0(interface_name, BT_SINK_INTERFACE) == 0) {
2973 _bt_handle_sink_event(parameters, object_path);
2974 } else if (g_strcmp0(interface_name, BT_AGENT_INTERFACE) == 0) {
2975 _bt_handle_agent_event(parameters, signal_name);
2976 } else if (g_strcmp0(interface_name, BT_DEVICE_INTERFACE) == 0) {
2977 _bt_handle_device_event(parameters, signal_name, object_path);
2978 } else if (g_strcmp0(interface_name, BT_TDS_PROVIDER_INTERFACE) == 0) {
2979 _bt_handle_tds_provider_event(parameters, signal_name, object_path);
2980 } else if (g_strcmp0(interface_name, BT_GATT_CHAR_INTERFACE) == 0) {
2981 _bt_handle_gatt_event(parameters, signal_name, object_path);
2987 static gboolean __bt_is_obexd_event(GVariant *msg, const char *interface)
2990 if (g_strcmp0(interface, BT_PROPERTIES_INTERFACE) == 0) {
2991 char *interface_name = NULL;
2993 g_variant_get(msg, "(&s@a{sv}@as)", &interface_name, NULL, NULL);
2994 retv_if(interface_name == NULL, FALSE);
2996 if (strcasecmp(interface_name, BT_OBEX_TRANSFER_INTERFACE) == 0) {
2997 BT_DBG("BT_OBEX_TRANSFER_INTERFACE");
3005 static void __bt_obexd_event_filter(GDBusConnection *connection,
3006 const gchar *sender_name,
3007 const gchar *object_path,
3008 const gchar *interface_name,
3009 const gchar *signal_name,
3010 GVariant *parameters,
3013 const char *member = signal_name;
3014 char *obj_path = NULL;
3015 ret_if(member == NULL);
3017 if (strcasecmp(member, "InterfacesAdded") == 0) {
3018 if (__bt_get_object_path(parameters, &obj_path)) {
3019 BT_ERR("Fail to get the path");
3022 BT_INFO("object_path = [%s]", obj_path);
3024 /*Handle OPP_SERVER_CONNECTED_EVENT here */
3025 /* TODO: MAP? see above */
3026 if (strncmp(obj_path, BT_SESSION_BASEPATH_SERVER,
3027 strlen(BT_SESSION_BASEPATH_SERVER)) != 0) {
3032 if (g_strrstr(obj_path, "session") && g_strrstr(obj_path, "transfer")) {
3033 BT_DBG("Obex_Server_Session_Transfer connected");
3034 _bt_obex_transfer_connected(obj_path);
3037 } else if (strcasecmp(member, "InterfacesRemoved") == 0) {
3038 /*Handle OPP_SERVER_DISCONNECTED_EVENT here */
3039 /* TODO: MAP? see above */
3040 if (__bt_get_object_path(parameters, &obj_path)) {
3041 BT_ERR("Fail to get the path");
3044 BT_INFO("object_path = [%s]", obj_path);
3046 if (strncmp(obj_path, BT_SESSION_BASEPATH_CLIENT,
3047 strlen(BT_SESSION_BASEPATH_CLIENT)) == 0) {
3048 BT_DBG("Call PBAP Disconnected");
3049 _bt_obex_pbap_client_disconnect(obj_path);
3052 if (strncmp(obj_path, BT_SESSION_BASEPATH_SERVER,
3053 strlen(BT_SESSION_BASEPATH_SERVER)) != 0) {
3058 if (g_strrstr(obj_path, "session") && g_strrstr(obj_path, "transfer")) {
3059 BT_DBG("Obex_Server_Session_Transfer disconnected %s",
3062 _bt_obex_transfer_disconnected(obj_path);
3065 } else if (__bt_is_obexd_event(parameters, interface_name) == TRUE) {
3066 const char *path = object_path;
3068 if (strncmp(path, BT_SESSION_BASEPATH_SERVER,
3069 strlen(BT_SESSION_BASEPATH_SERVER)) != 0 &&
3070 strncmp(path, BT_SESSION_BASEPATH_CLIENT,
3071 strlen(BT_SESSION_BASEPATH_CLIENT)) != 0) {
3072 BT_DBG("DBUS_HANDLER_RESULT_NOT_YET_HANDLED");
3076 _bt_handle_property_changed_event(parameters, path);
3082 static gboolean __bt_is_obexd_client_event(GVariant *msg, const char *interface)
3086 if (g_strcmp0(interface, BT_PROPERTIES_INTERFACE) == 0) {
3087 char *interface_name = NULL;
3089 g_variant_get(msg, "(&s@a{sv}@as)", &interface_name, NULL, NULL);
3091 retv_if(interface_name == NULL, FALSE);
3093 if (strcasecmp(interface_name,
3094 BT_OBEX_TRANSFER_INTERFACE) == 0) {
3105 static void __bt_opc_event_filter(GDBusConnection *connection,
3106 const gchar *sender_name,
3107 const gchar *object_path,
3108 const gchar *interface_name,
3109 const gchar *signal_name,
3110 GVariant *parameters,
3113 const char *member = signal_name;
3114 char *obj_path = NULL;
3115 if (strcasecmp(member, "InterfacesAdded") == 0) {
3116 BT_DBG("InterfacesAdded");
3117 } else if (strcasecmp(member, "InterfacesRemoved") == 0) {
3119 if (__bt_get_object_path(parameters, &obj_path)) {
3120 BT_ERR("Fail to get the path");
3124 BT_DBG("object_path = %s", obj_path);
3126 if (strncmp(obj_path, BT_SESSION_BASEPATH_CLIENT,
3127 strlen(BT_SESSION_BASEPATH_CLIENT)) != 0
3128 || strstr(obj_path, "transfer") == NULL) {
3131 } else if (strncmp(obj_path, BT_SESSION_BASEPATH_CLIENT,
3132 strlen(BT_SESSION_BASEPATH_CLIENT)) == 0) {
3133 BT_DBG("Going to call opc disconnected");
3134 _bt_opc_disconnected(obj_path);
3137 _bt_sending_files();
3139 } else if (__bt_is_obexd_client_event(parameters, interface_name) == TRUE) {
3140 char *path = (char *)object_path;
3141 BT_INFO("object_path %s", path);
3142 if (strncmp(path, BT_SESSION_BASEPATH_CLIENT,
3143 strlen(BT_SESSION_BASEPATH_CLIENT)) != 0) {
3144 BT_DBG("NOT BT_SESSION_BASEPATH_CLIENT");
3148 _bt_opc_property_changed_event(parameters, path);
3154 int _bt_opp_client_event_init(void)
3156 GError *error = NULL;
3158 if (opc_obexd_conn == NULL) {
3159 opc_obexd_conn = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &error);
3161 if (!opc_obexd_conn) {
3163 BT_ERR("Unable to connect to dbus: %s", error->message);
3164 g_clear_error(&error);
3166 return BLUETOOTH_ERROR_INTERNAL;
3170 if (_bt_register_service_event(opc_obexd_conn,
3171 BT_OPP_CLIENT_EVENT) != BLUETOOTH_ERROR_NONE) {
3172 g_object_unref(opc_obexd_conn);
3173 opc_obexd_conn = NULL;
3174 return BLUETOOTH_ERROR_INTERNAL;
3177 return BLUETOOTH_ERROR_NONE;
3180 void _bt_opp_client_event_deinit(void)
3182 if (opc_obexd_conn) {
3183 _bt_unregister_service_event(opc_obexd_conn,
3184 BT_OPP_CLIENT_EVENT);
3185 g_object_unref(opc_obexd_conn);
3186 opc_obexd_conn = NULL;
3190 static void __bt_map_event_filter(GDBusConnection *connection,
3191 const gchar *sender_name,
3192 const gchar *object_path,
3193 const gchar *interface_name,
3194 const gchar *signal_name,
3195 GVariant *parameters,
3198 BT_DBG("Entered __bt_map_event_filter");
3199 const char *member = signal_name;
3201 if (strcasecmp(member, "InterfacesAdded") == 0) {
3202 BT_DBG("------------------------------------ADDED------------------------------------");
3203 // currently doing nothing
3204 } else if (strcasecmp(member, "InterfacesRemoved") == 0) {
3205 BT_DBG("------------------------------------REMOVED------------------------------------");
3206 // TODO check if something should be called here?
3207 //_bt_map_on_transfer_finished(object_path, error);
3208 } else if (__bt_is_obexd_client_event(parameters, interface_name) == TRUE) {
3209 BT_DBG("------------------------------------CLIENT EVENT------------------------------------");
3210 _bt_map_property_changed_event(parameters, object_path);
3216 int _bt_map_client_event_init(void)
3218 GError *error = NULL;
3220 if (map_obexd_conn == NULL) {
3221 map_obexd_conn = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &error);
3223 if (!map_obexd_conn) {
3225 BT_ERR("Unable to connect to dbus: %s", error->message);
3226 g_clear_error(&error);
3228 return BLUETOOTH_ERROR_INTERNAL;
3232 if (_bt_register_service_event(map_obexd_conn,
3233 BT_MAP_CLIENT_EVENT) != BLUETOOTH_ERROR_NONE) {
3234 g_object_unref(map_obexd_conn);
3235 map_obexd_conn = NULL;
3236 return BLUETOOTH_ERROR_INTERNAL;
3239 return BLUETOOTH_ERROR_NONE;
3242 void _bt_map_client_event_deinit(void)
3244 if (map_obexd_conn) {
3245 _bt_unregister_service_event(map_obexd_conn,
3246 BT_MAP_CLIENT_EVENT);
3247 g_object_unref(map_obexd_conn);
3248 map_obexd_conn = NULL;
3252 int _bt_register_manager_subscribe_signal(GDBusConnection *conn,
3258 static int subs_interface_added_id = -1;
3259 static int subs_interface_removed_id = -1;
3260 static int subs_name_owner_id = -1;
3261 static int subs_property_id = -1;
3262 static int subs_adapter_id = -1;
3263 static int subs_gatt_id = -1;
3266 if (subs_interface_added_id == -1) {
3267 subs_interface_added_id = g_dbus_connection_signal_subscribe(conn,
3268 NULL, BT_MANAGER_INTERFACE,
3269 BT_INTERFACES_ADDED, NULL, NULL, 0,
3270 __bt_manager_event_filter,
3273 if (subs_interface_removed_id == -1) {
3274 subs_interface_removed_id = g_dbus_connection_signal_subscribe(conn,
3275 NULL, BT_MANAGER_INTERFACE,
3276 BT_INTERFACES_REMOVED, NULL, NULL, 0,
3277 __bt_manager_event_filter,
3280 if (subs_name_owner_id == -1) {
3281 subs_name_owner_id = g_dbus_connection_signal_subscribe(conn,
3282 NULL, BT_FREEDESKTOP_INTERFACE,
3283 BT_NAME_OWNER_CHANGED, NULL, NULL, 0,
3284 __bt_manager_event_filter,
3287 if (subs_property_id == -1) {
3288 subs_property_id = g_dbus_connection_signal_subscribe(conn,
3289 NULL, BT_PROPERTIES_INTERFACE,
3290 BT_PROPERTIES_CHANGED, NULL, NULL, 0,
3291 __bt_manager_event_filter,
3294 if (subs_adapter_id == -1) {
3295 subs_adapter_id = g_dbus_connection_signal_subscribe(conn,
3296 NULL, BT_ADAPTER_INTERFACE,
3297 NULL, NULL, NULL, 0,
3298 __bt_manager_event_filter,
3301 if (subs_gatt_id == -1) {
3302 subs_gatt_id = g_dbus_connection_signal_subscribe(conn,
3303 NULL, BT_GATT_CHAR_INTERFACE,
3304 NULL, NULL, NULL, 0,
3305 __bt_manager_event_filter,
3309 if (subs_interface_added_id != -1) {
3310 g_dbus_connection_signal_unsubscribe(conn,
3311 subs_interface_added_id);
3312 subs_interface_added_id = -1;
3314 if (subs_interface_removed_id != -1) {
3315 g_dbus_connection_signal_unsubscribe(conn,
3316 subs_interface_removed_id);
3317 subs_interface_removed_id = -1;
3319 if (subs_name_owner_id != -1) {
3320 g_dbus_connection_signal_unsubscribe(conn,
3321 subs_name_owner_id);
3322 subs_name_owner_id = -1;
3324 if (subs_property_id != -1) {
3325 g_dbus_connection_signal_unsubscribe(conn,
3327 subs_property_id = -1;
3329 if (subs_adapter_id != -1) {
3330 g_dbus_connection_signal_unsubscribe(conn, subs_adapter_id);
3331 subs_adapter_id = -1;
3333 if (subs_gatt_id != -1) {
3334 g_dbus_connection_signal_unsubscribe(conn, subs_gatt_id);
3341 int _bt_register_device_subscribe_signal(GDBusConnection *conn,
3347 static int subs_device_id = -1;
3350 if (subs_device_id == -1) {
3351 subs_device_id = g_dbus_connection_signal_subscribe(conn,
3352 NULL, BT_DEVICE_INTERFACE,
3353 NULL, NULL, NULL, 0,
3354 __bt_manager_event_filter,
3358 if (subs_device_id != -1) {
3359 g_dbus_connection_signal_unsubscribe(conn,
3361 subs_device_id = -1;
3367 int _bt_register_input_subscribe_signal(GDBusConnection *conn,
3373 static int subs_input_id = -1;
3376 if (subs_input_id == -1) {
3377 subs_input_id = g_dbus_connection_signal_subscribe(conn,
3378 NULL, BT_INPUT_INTERFACE,
3379 NULL, NULL, NULL, 0,
3380 __bt_manager_event_filter,
3384 if (subs_input_id != -1) {
3385 g_dbus_connection_signal_unsubscribe(conn,
3393 int _bt_register_network_subscribe_signal(GDBusConnection *conn,
3399 static int subs_serv_id = -1;
3400 static int subs_client_id = -1;
3403 if (subs_serv_id == -1) {
3404 subs_serv_id = g_dbus_connection_signal_subscribe(conn,
3405 NULL, BT_NETWORK_SERVER_INTERFACE,
3406 NULL, NULL, NULL, 0,
3407 __bt_manager_event_filter,
3410 if (subs_client_id == -1) {
3411 subs_client_id = g_dbus_connection_signal_subscribe(conn,
3412 NULL, BT_NETWORK_CLIENT_INTERFACE,
3413 NULL, NULL, NULL, 0,
3414 __bt_manager_event_filter,
3418 if (subs_serv_id != -1) {
3419 g_dbus_connection_signal_unsubscribe(conn,
3423 if (subs_client_id != -1) {
3424 g_dbus_connection_signal_unsubscribe(conn,
3426 subs_client_id = -1;
3432 int _bt_register_audio_subscribe_signal(GDBusConnection *conn,
3438 static int subs_headset_id = -1;
3439 static int subs_sink_id = -1;
3442 if (subs_headset_id == -1) {
3443 subs_headset_id = g_dbus_connection_signal_subscribe(conn,
3444 NULL, BT_HEADSET_INTERFACE,
3445 NULL, NULL, NULL, 0,
3446 __bt_manager_event_filter,
3449 if (subs_sink_id == -1) {
3450 subs_sink_id = g_dbus_connection_signal_subscribe(conn,
3451 NULL, BT_SINK_INTERFACE,
3452 NULL, NULL, NULL, 0,
3453 __bt_manager_event_filter,
3457 if (subs_headset_id != -1) {
3458 g_dbus_connection_signal_unsubscribe(conn,
3460 subs_headset_id = -1;
3462 if (subs_sink_id != -1) {
3463 g_dbus_connection_signal_unsubscribe(conn,
3471 int _bt_register_opp_server_subscribe_signal(GDBusConnection *conn,
3477 static int subs_opp_server_interface_added_id = -1;
3478 static int subs_opp_server_interface_removed_id = -1;
3479 static int subs_opp_server_property_id = -1;
3483 if (subs_opp_server_interface_added_id == -1) {
3484 subs_opp_server_interface_added_id = g_dbus_connection_signal_subscribe(conn,
3485 NULL, BT_MANAGER_INTERFACE,
3486 BT_INTERFACES_ADDED, NULL, NULL, 0,
3487 __bt_obexd_event_filter,
3490 if (subs_opp_server_interface_removed_id == -1) {
3491 subs_opp_server_interface_removed_id = g_dbus_connection_signal_subscribe(conn,
3492 NULL, BT_MANAGER_INTERFACE,
3493 BT_INTERFACES_REMOVED, NULL, NULL, 0,
3494 __bt_obexd_event_filter,
3497 if (subs_opp_server_property_id == -1) {
3498 subs_opp_server_property_id = g_dbus_connection_signal_subscribe(conn,
3499 NULL, BT_PROPERTIES_INTERFACE,
3500 BT_PROPERTIES_CHANGED, NULL, NULL, 0,
3501 __bt_obexd_event_filter,
3505 if (subs_opp_server_interface_added_id != -1) {
3506 g_dbus_connection_signal_unsubscribe(conn,
3507 subs_opp_server_interface_added_id);
3508 subs_opp_server_interface_added_id = -1;
3510 if (subs_opp_server_interface_removed_id != -1) {
3511 g_dbus_connection_signal_unsubscribe(conn,
3512 subs_opp_server_interface_removed_id);
3513 subs_opp_server_interface_removed_id = -1;
3515 if (subs_opp_server_property_id != -1) {
3516 g_dbus_connection_signal_unsubscribe(conn,
3517 subs_opp_server_property_id);
3518 subs_opp_server_property_id = -1;
3524 int _bt_register_opp_client_subscribe_signal(GDBusConnection *conn,
3530 static int subs_opp_client_interface_added_id = -1;
3531 static int subs_opp_client_interface_removed_id = -1;
3532 static int subs_opp_client_property_id = -1;
3536 if (subs_opp_client_interface_added_id == -1) {
3537 subs_opp_client_interface_added_id = g_dbus_connection_signal_subscribe(conn,
3538 NULL, BT_MANAGER_INTERFACE,
3539 BT_INTERFACES_ADDED, NULL, NULL, 0,
3540 __bt_opc_event_filter,
3543 if (subs_opp_client_interface_removed_id == -1) {
3544 subs_opp_client_interface_removed_id = g_dbus_connection_signal_subscribe(conn,
3545 NULL, BT_MANAGER_INTERFACE,
3546 BT_INTERFACES_REMOVED, NULL, NULL, 0,
3547 __bt_opc_event_filter,
3550 if (subs_opp_client_property_id == -1) {
3551 subs_opp_client_property_id = g_dbus_connection_signal_subscribe(conn,
3552 NULL, BT_PROPERTIES_INTERFACE,
3553 BT_PROPERTIES_CHANGED, NULL, NULL, 0,
3554 __bt_opc_event_filter,
3558 if (subs_opp_client_interface_added_id != -1) {
3559 g_dbus_connection_signal_unsubscribe(conn,
3560 subs_opp_client_interface_added_id);
3561 subs_opp_client_interface_added_id = -1;
3563 if (subs_opp_client_interface_removed_id != -1) {
3564 g_dbus_connection_signal_unsubscribe(conn,
3565 subs_opp_client_interface_removed_id);
3566 subs_opp_client_interface_removed_id = -1;
3568 if (subs_opp_client_property_id != -1) {
3569 g_dbus_connection_signal_unsubscribe(conn,
3570 subs_opp_client_property_id);
3571 subs_opp_client_property_id = -1;
3577 int _bt_register_map_client_subscribe_signal(GDBusConnection *conn,
3583 static int subs_map_client_interface_added_id = -1;
3584 static int subs_map_client_interface_removed_id = -1;
3585 static int subs_map_client_property_id = -1;
3589 if (subs_map_client_interface_added_id == -1) {
3590 subs_map_client_interface_added_id = g_dbus_connection_signal_subscribe(conn,
3591 NULL, BT_MANAGER_INTERFACE,
3592 BT_INTERFACES_ADDED, NULL, NULL, 0,
3593 __bt_map_event_filter,
3596 if (subs_map_client_interface_removed_id == -1) {
3597 subs_map_client_interface_removed_id = g_dbus_connection_signal_subscribe(conn,
3598 NULL, BT_MANAGER_INTERFACE,
3599 BT_INTERFACES_REMOVED, NULL, NULL, 0,
3600 __bt_map_event_filter,
3603 if (subs_map_client_property_id == -1) {
3604 subs_map_client_property_id = g_dbus_connection_signal_subscribe(conn,
3605 NULL, BT_PROPERTIES_INTERFACE,
3606 BT_PROPERTIES_CHANGED, NULL, NULL, 0,
3607 __bt_map_event_filter,
3611 if (subs_map_client_interface_added_id != -1) {
3612 g_dbus_connection_signal_unsubscribe(conn,
3613 subs_map_client_interface_added_id);
3614 subs_map_client_interface_added_id = -1;
3616 if (subs_map_client_interface_removed_id != -1) {
3617 g_dbus_connection_signal_unsubscribe(conn,
3618 subs_map_client_interface_removed_id);
3619 subs_map_client_interface_removed_id = -1;
3621 if (subs_map_client_property_id != -1) {
3622 g_dbus_connection_signal_unsubscribe(conn,
3623 subs_map_client_property_id);
3624 subs_map_client_property_id = -1;
3630 int _bt_register_a2dp_subscribe_signal(GDBusConnection *conn,
3636 static int subs_a2dp_source_id = -1;
3637 static int subs_a2dp_sink_id = -1;
3640 if (subs_a2dp_source_id == -1) {
3641 subs_a2dp_source_id = g_dbus_connection_signal_subscribe(conn,
3642 NULL, BT_A2DP_SOURCE_INTERFACE,
3643 NULL, NULL, NULL, 0,
3644 __bt_opc_event_filter,
3647 if (subs_a2dp_sink_id == -1) {
3648 subs_a2dp_sink_id = g_dbus_connection_signal_subscribe(conn,
3649 NULL, BT_SINK_INTERFACE,
3650 NULL, NULL, NULL, 0,
3651 __bt_opc_event_filter,
3655 if (subs_a2dp_source_id != -1) {
3656 g_dbus_connection_signal_unsubscribe(conn,
3657 subs_a2dp_source_id);
3658 subs_a2dp_source_id = -1;
3660 if (subs_a2dp_sink_id != -1) {
3661 g_dbus_connection_signal_unsubscribe(conn,
3663 subs_a2dp_sink_id = -1;
3669 int _bt_register_tds_provider_subscribe_signal(GDBusConnection *conn, int subscribe)
3674 static int subs_custom_id = -1;
3677 if (subs_custom_id == -1) {
3678 subs_custom_id = g_dbus_connection_signal_subscribe(conn,
3679 NULL, BT_TDS_PROVIDER_INTERFACE,
3680 NULL, NULL, NULL, 0,
3681 __bt_manager_event_filter,
3685 if (subs_custom_id != -1) {
3686 g_dbus_connection_signal_unsubscribe(conn,
3688 subs_custom_id = -1;
3695 static void __bt_dump_event_filter(GDBusConnection *connection,
3696 const gchar *sender_name,
3697 const gchar *object_path,
3698 const gchar *interface_name,
3699 const gchar *signal_name,
3700 GVariant *parameters,
3706 int __bt_register_dump_subscribe_signal(GDBusConnection *conn,
3712 static int subs_source_id = -1;
3715 if (subs_source_id == -1) {
3716 subs_source_id = g_dbus_connection_signal_subscribe(conn,
3717 NULL, BT_DUMP_SERVICE_INTERFACE,
3718 BT_DUMP_SERVICE_SIGNAL, BT_DUMP_SERVICE_PATH, NULL, 0,
3719 __bt_dump_event_filter,
3723 if (subs_source_id != -1) {
3724 g_dbus_connection_signal_unsubscribe(conn,
3726 subs_source_id = -1;
3732 int _bt_register_service_event(GDBusConnection *g_conn, int event_type)
3736 retv_if(g_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
3738 switch (event_type) {
3739 case BT_MANAGER_EVENT:
3740 _bt_register_manager_subscribe_signal(g_conn, TRUE);
3742 case BT_DEVICE_EVENT:
3743 _bt_register_device_subscribe_signal(g_conn, TRUE);
3746 _bt_register_input_subscribe_signal(g_conn, TRUE);
3748 case BT_NETWORK_EVENT:
3749 _bt_register_network_subscribe_signal(g_conn, TRUE);
3751 case BT_HEADSET_EVENT:
3752 _bt_register_audio_subscribe_signal(g_conn, TRUE);
3754 case BT_OPP_SERVER_EVENT:
3755 BT_ERR("BT_OPP_SERVER_EVENT: register service event");
3756 _bt_register_opp_server_subscribe_signal(g_conn, TRUE);
3759 case BT_OPP_CLIENT_EVENT:
3760 BT_ERR("BT_OPP_CLIENT_EVENT: register service event");
3761 _bt_register_opp_client_subscribe_signal(g_conn, TRUE);
3763 case BT_MAP_CLIENT_EVENT:
3764 BT_ERR("BT_MAP_CLIENT_EVENT: register service event");
3765 _bt_register_map_client_subscribe_signal(g_conn, TRUE);
3767 case BT_A2DP_SOURCE_EVENT:
3768 BT_INFO("A2dp Source event");
3769 _bt_register_a2dp_subscribe_signal(g_conn, TRUE);
3772 BT_INFO("TDS provider event");
3773 _bt_register_tds_provider_subscribe_signal(g_conn, TRUE);
3776 BT_ERR("Unknown event");
3777 return BLUETOOTH_ERROR_INTERNAL;
3780 return BLUETOOTH_ERROR_NONE;
3783 void _bt_unregister_service_event(GDBusConnection *g_conn, int event_type)
3787 ret_if(g_conn == NULL);
3789 switch (event_type) {
3790 case BT_MANAGER_EVENT:
3791 _bt_register_manager_subscribe_signal(g_conn, FALSE);
3792 _bt_register_device_subscribe_signal(g_conn, FALSE);
3793 _bt_register_input_subscribe_signal(g_conn, FALSE);
3794 _bt_register_network_subscribe_signal(g_conn, FALSE);
3795 _bt_register_audio_subscribe_signal(g_conn, FALSE);
3797 case BT_OPP_SERVER_EVENT:
3798 _bt_register_opp_server_subscribe_signal(g_conn, FALSE);
3800 case BT_OPP_CLIENT_EVENT:
3801 _bt_register_opp_client_subscribe_signal(g_conn, FALSE);
3803 case BT_MAP_CLIENT_EVENT:
3804 _bt_register_map_client_subscribe_signal(g_conn, FALSE);
3807 BT_ERR("Unknown event");
3814 static int __bt_init_manager_receiver(void)
3818 GError *error = NULL;
3820 if (manager_conn == NULL) {
3821 manager_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
3822 if (error != NULL) {
3823 BT_ERR("ERROR: Can't get on system bus [%s]", error->message);
3824 g_clear_error(&error);
3826 retv_if(manager_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
3829 if (_bt_register_service_event(manager_conn,
3830 BT_MANAGER_EVENT) != BLUETOOTH_ERROR_NONE)
3832 if (_bt_register_service_event(manager_conn,
3833 BT_DEVICE_EVENT) != BLUETOOTH_ERROR_NONE)
3836 if (_bt_register_service_event(manager_conn,
3837 BT_HID_EVENT) != BLUETOOTH_ERROR_NONE)
3840 if (_bt_register_service_event(manager_conn,
3841 BT_HEADSET_EVENT) != BLUETOOTH_ERROR_NONE)
3844 if (_bt_register_service_event(manager_conn,
3845 BT_NETWORK_EVENT) != BLUETOOTH_ERROR_NONE)
3848 if (_bt_register_service_event(manager_conn,
3849 BT_TDS_EVENT) != BLUETOOTH_ERROR_NONE)
3852 __bt_register_dump_subscribe_signal(manager_conn, TRUE);
3853 return BLUETOOTH_ERROR_NONE;
3856 g_object_unref(manager_conn);
3857 manager_conn = NULL;
3862 return BLUETOOTH_ERROR_INTERNAL;
3865 static int __bt_init_obexd_receiver(void)
3868 if (!TIZEN_PROFILE_TV) { /* TODO: obexd doesn't work in TV profile. It should be resolved later. */
3869 GError *error = NULL;
3871 if (obexd_conn == NULL) {
3872 obexd_conn = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &error);
3873 if (error != NULL) {
3874 BT_ERR("ERROR: Can't get on session bus [%s]", error->message);
3875 g_clear_error(&error);
3877 retv_if(obexd_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
3880 if (_bt_register_service_event(obexd_conn,
3881 BT_OPP_SERVER_EVENT) != BLUETOOTH_ERROR_NONE) {
3882 BT_ERR("Error while registering service event");
3883 g_object_unref(obexd_conn);
3885 return BLUETOOTH_ERROR_INTERNAL;
3890 return BLUETOOTH_ERROR_NONE;
3893 gboolean __bt_reinit_obexd_receiver(gpointer user_data)
3895 static int retry_cnt = 0;
3896 int result = BLUETOOTH_ERROR_NONE;
3900 result = __bt_init_obexd_receiver();
3901 if (result != BLUETOOTH_ERROR_NONE) {
3902 /* 20 ms * 50 = 10 seconds. During 10 seconds fail to initialize,
3903 then it is not the timing issue. Just can't use the session bus connection */
3904 if (retry_cnt > 100) {
3905 BT_ERR("Fail to init obexd receiver by 50 times.");
3907 session_reinit_timer = 0;
3911 BT_DBG("Retry to initialize the obexd receiver");
3916 session_reinit_timer = 0;
3923 /* To receive the event from bluez */
3924 int _bt_init_service_event_receiver(void)
3930 result = __bt_init_manager_receiver();
3931 retv_if(result != BLUETOOTH_ERROR_NONE, result);
3933 result = __bt_init_obexd_receiver();
3934 if (result != BLUETOOTH_ERROR_NONE) {
3935 BT_ERR("Fail to init obexd receiver");
3937 /* Try to re-initialize obexd receiver in the timer */
3938 if (session_reinit_timer > 0)
3939 g_source_remove(session_reinit_timer);
3941 session_reinit_timer = g_timeout_add(BT_SESSION_BUS_GET_TIMEOUT,
3942 (GSourceFunc)__bt_reinit_obexd_receiver, NULL);
3947 return BLUETOOTH_ERROR_NONE;
3950 void _bt_deinit_service_event_receiver(void)
3954 _bt_unregister_service_event(manager_conn, BT_MANAGER_EVENT);
3956 _bt_unregister_service_event(obexd_conn, BT_OPP_SERVER_EVENT);
3958 __bt_register_dump_subscribe_signal(manager_conn, FALSE);
3961 g_object_unref(manager_conn);
3962 manager_conn = NULL;
3966 g_object_unref(obexd_conn);
3971 g_source_remove(event_id);
3974 if (le_scan_event_id > 0)
3975 g_source_remove(le_scan_event_id);
3976 le_scan_event_id = 0;