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"
47 #ifdef TIZEN_FEATURE_BT_DPM
48 #include "bt-service-dpm.h"
51 #define DBUS_TIMEOUT 20 * 1000 /* 20 Sec */
52 static GDBusConnection *manager_conn;
53 static GDBusConnection *obexd_conn;
54 static GDBusConnection *opc_obexd_conn;
55 static GDBusConnection *map_obexd_conn;
57 static GList *p_cache_list = NULL;
59 static guint event_id;
60 static guint le_scan_event_id = 0;
61 static guint session_reinit_timer;
62 guint nap_connected_device_count = 0;
63 static guint hid_connected_device_count = 0;
64 static GList *p_adv_ind_list = NULL;
67 bt_remote_dev_info_t *dev_info;
71 * obexd connection type
79 OBEX_PCSUITE = (1 << 6),
80 OBEX_SYNCEVOLUTION = (1 << 7),
83 } bluetooth_obex_connection_type_t;
85 void _bt_handle_property_changed_event(GVariant *msg, const char *object_path);
86 void _bt_opc_property_changed_event(GVariant *msg, char *path);
87 void _bt_map_property_changed_event(GVariant *msg, char *path); /* TODO: MAP, do we need this? */
88 int _bt_register_service_event(GDBusConnection *g_conn, int event_type);
89 void _bt_unregister_service_event(GDBusConnection *g_conn, int event_type);
90 void _bt_opp_client_event_deinit(void);
91 void _bt_map_client_event_deinit(void);
92 void _bt_handle_network_client_event(GVariant *msg_iter,
94 void __bt_gatt_char_property_changed_event(GVariant *msg_iter,
97 static void __bt_free_bt_le_adv_info_t(gpointer data)
99 bt_le_adv_info_t *adv_info = data;
101 if (adv_info->timer_id)
102 g_source_remove(adv_info->timer_id);
103 adv_info->timer_id = 0;
105 g_free(adv_info->addr);
106 g_free(adv_info->data);
110 static bt_le_adv_info_t *__bt_get_adv_ind_info(char *addr)
112 retv_if(!addr, NULL);
113 bt_le_adv_info_t *adv_info = NULL;
114 GList *current = g_list_first((GList *)p_adv_ind_list);
115 while (current && current->data) {
116 adv_info = (bt_le_adv_info_t *)current->data;
117 if (adv_info && !g_strcmp0(adv_info->addr, addr))
119 current = g_list_next(current);
124 static int __bt_add_adv_ind_info(bt_le_adv_info_t *adv_info)
126 retv_if(!adv_info, -1);
127 if (__bt_get_adv_ind_info(adv_info->addr) != NULL) {
128 __bt_free_bt_le_adv_info_t(adv_info);
131 p_adv_ind_list = g_list_append(p_adv_ind_list, adv_info);
136 static void __bt_del_adv_ind_info(char *addr)
139 ret_if(!p_adv_ind_list);
140 bt_le_adv_info_t *adv_info = NULL;
141 GList *current = g_list_first((GList *)p_adv_ind_list);
142 while (current && current->data) {
143 adv_info = (bt_le_adv_info_t *)current->data;
144 if (adv_info && !g_strcmp0(adv_info->addr, addr)) {
145 p_adv_ind_list = g_list_remove(p_adv_ind_list, adv_info);
146 __bt_free_bt_le_adv_info_t(adv_info);
149 current = g_list_next(current);
153 static gboolean __bt_adv_scan_req_timeout_cb(gpointer user_data)
155 bt_remote_le_dev_info_t le_dev_info;
156 bt_le_adv_info_t *adv_info = (bt_le_adv_info_t*)user_data;
158 memset(&le_dev_info, 0x00, sizeof(bt_remote_le_dev_info_t));
160 le_dev_info.address = adv_info->addr;
161 le_dev_info.addr_type = adv_info->addr_type;
162 le_dev_info.rssi = adv_info->rssi;
163 le_dev_info.adv_data = adv_info->data;
164 le_dev_info.adv_data_len = 0;
165 adv_info->timer_id = 0;
167 _bt_send_scan_result_event(&le_dev_info, adv_info);
168 __bt_del_adv_ind_info(adv_info->addr);
173 static void __bt_free_cache_info(bt_cache_info_t *cache_info)
175 ret_if(cache_info == NULL);
176 _bt_free_device_info(cache_info->dev_info);
180 static gboolean __bt_parse_device_properties(GVariant *item,
181 bt_remote_dev_info_t *dev_info)
190 g_variant_iter_init(&iter, item);
191 while (g_variant_iter_loop(&iter, "{sv}", &key, &val)) {
192 if (strcasecmp(key, "Address") == 0) {
193 dev_info->address = g_variant_dup_string(val, &len);
194 } else if (strcasecmp(key, "Class") == 0) {
195 dev_info->class = g_variant_get_uint32(val);
196 } else if (strcasecmp(key, "name") == 0) {
197 if (dev_info->name == NULL)
198 dev_info->name = g_variant_dup_string(val, &len);
199 } else if (strcasecmp(key, "Connected") == 0) {
200 dev_info->connected = g_variant_get_byte(val);
201 } else if (strcasecmp(key, "paired") == 0) {
202 dev_info->paired = g_variant_get_boolean(val);
203 } else if (strcasecmp(key, "Trusted") == 0) {
204 dev_info->trust = g_variant_get_boolean(val);
205 } else if (strcasecmp(key, "RSSI") == 0) {
206 dev_info->rssi = g_variant_get_int16(val);
207 } else if (strcasecmp(key, "LastAddrType") == 0) {
208 dev_info->addr_type = g_variant_get_byte(val);
209 } else if (strcasecmp(key, "UUIDs") == 0) {
213 size = g_variant_get_size(val);
216 uuid_value = (char **)g_variant_get_strv(val, &size);
217 if (dev_info->uuids == NULL)
218 dev_info->uuids = g_malloc0(sizeof(char *) * size);
220 for (i = 0; uuid_value[i] != NULL; i++) {
221 dev_info->uuid_count++;
222 dev_info->uuids[i] = g_strdup(uuid_value[i]);
226 } else if (strcasecmp(key, "ManufacturerDataLen") == 0) {
227 g_variant_get(val, "q", &dev_info->manufacturer_data_len);
228 if (dev_info->manufacturer_data_len > BLUETOOTH_MANUFACTURER_DATA_LENGTH_MAX) {
229 BT_ERR("manufacturer_data_len is too long(len = %d)", dev_info->manufacturer_data_len);
230 dev_info->manufacturer_data_len = BLUETOOTH_MANUFACTURER_DATA_LENGTH_MAX;
233 if (dev_info->manufacturer_data_len == 0)
234 dev_info->manufacturer_data = g_strdup("");
235 } else if (strcasecmp(key, "ManufacturerData") == 0) {
238 GVariantIter *value_iter;
241 len = g_variant_get_size(val);
245 dev_info->manufacturer_data = g_malloc0(len);
247 g_variant_get(val, "ay", &value_iter);
248 while (g_variant_iter_loop(value_iter, "y", &m_value))
249 dev_info->manufacturer_data[i++] = m_value;
250 g_variant_iter_free(value_iter);
258 static gboolean __bt_parse_interface(GVariant *msg,
259 bt_remote_dev_info_t *dev_info)
262 GVariant *optional_param = NULL;
265 char *interface_name = NULL;
266 GVariant *inner_iter = NULL;
267 g_variant_get(msg, "(&o@a{sa{sv}})",
268 &path, &optional_param);
269 g_variant_iter_init(&iter, optional_param);
271 retv_if(optional_param == NULL, FALSE);
273 while ((child = g_variant_iter_next_value(&iter))) {
274 g_variant_get(child, "{&s@a{sv}}", &interface_name, &inner_iter);
275 if (g_strcmp0(interface_name, BT_DEVICE_INTERFACE) == 0) {
276 BT_DBG("Found a device: %s", path);
277 if (__bt_parse_device_properties(inner_iter,
278 dev_info) == FALSE) {
279 g_variant_unref(inner_iter);
280 g_variant_unref(child);
281 g_variant_unref(optional_param);
282 BT_ERR("Fail to parse the properies");
285 g_variant_unref(inner_iter);
286 g_variant_unref(child);
287 g_variant_unref(optional_param);
291 g_variant_unref(inner_iter);
292 g_variant_unref(child);
295 g_variant_unref(optional_param);
300 static int __bt_get_owner_info(GVariant *msg, char **name,
301 char **previous, char **current)
303 g_variant_get(msg, "(sss)", name, previous, current);
304 return BLUETOOTH_ERROR_NONE;
307 static int __bt_get_agent_signal_info(GVariant *msg, char **address,
308 char **name, char **uuid)
310 g_variant_get(msg, "(sss)", address, name, uuid);
311 return BLUETOOTH_ERROR_NONE;
314 void __bt_set_device_values(gboolean connected, int state)
316 int bt_device_state = VCONFKEY_BT_DEVICE_NONE;
318 if (vconf_get_int(VCONFKEY_BT_DEVICE, &bt_device_state) != 0)
319 BT_ERR("vconf_get_int failed");
321 if (connected == TRUE)
322 bt_device_state |= state;
323 else if (bt_device_state & state)
324 bt_device_state ^= state;
326 if (vconf_set_int(VCONFKEY_BT_DEVICE, bt_device_state) != 0)
327 BT_ERR("vconf_set_int failed");
330 gboolean _bt_discovery_finished_cb(gpointer user_data)
332 int result = BLUETOOTH_ERROR_NONE;
334 GVariant *param = NULL;
335 if (_bt_get_discovering_property(DISCOVERY_ROLE_BREDR) == FALSE) {
336 if (_bt_get_cancel_by_user() == TRUE)
337 result = BLUETOOTH_ERROR_CANCEL_BY_USER;
339 _bt_set_cancel_by_user(FALSE);
340 _bt_set_discovery_status(FALSE);
341 param = g_variant_new("(i)", result);
342 _bt_send_event(BT_ADAPTER_EVENT,
343 BLUETOOTH_EVENT_DISCOVERY_FINISHED,
350 static gboolean __bt_le_discovery_finished_cb(gpointer user_data)
352 int result = BLUETOOTH_ERROR_NONE;
353 le_scan_event_id = 0;
354 GVariant *param = NULL;
355 if (_bt_get_discovering_property(DISCOVERY_ROLE_LE) == FALSE) {
356 if (_bt_get_cancel_by_user() == TRUE)
357 result = BLUETOOTH_ERROR_CANCEL_BY_USER;
359 g_list_free_full(p_adv_ind_list, __bt_free_bt_le_adv_info_t);
360 p_adv_ind_list = NULL;
362 _bt_set_cancel_by_user(FALSE);
363 _bt_disable_all_scanner_status();
364 _bt_set_le_scan_status(FALSE);
365 param = g_variant_new("(i)", result);
366 _bt_send_event(BT_LE_ADAPTER_EVENT,
367 BLUETOOTH_EVENT_LE_DISCOVERY_FINISHED,
374 void __bt_update_remote_cache_devinfo(const char *address, gboolean paired_status)
378 ret_if(address == NULL);
381 bt_cache_info_t *cache_info;
382 bt_remote_dev_info_t *dev_info;
384 node = g_list_first(p_cache_list);
386 while (node != NULL) {
387 cache_info = (bt_cache_info_t *)node->data;
389 if (cache_info == NULL) {
390 node = g_list_next(node);
394 dev_info = cache_info->dev_info;
395 if (strcasecmp(dev_info->address,
397 BT_DBG("Device Found");
398 if (paired_status == TRUE)
399 cache_info->dev_info->paired = TRUE;
401 cache_info->dev_info->paired = FALSE;
404 node = g_list_next(node);
409 static void __bt_device_remote_connected_properties(
410 bt_remote_dev_info_t *remote_dev_info,
411 char *address, gboolean connected)
413 int result = BLUETOOTH_ERROR_NONE;
415 GVariant *param = NULL;
418 if (remote_dev_info->uuid_count > 0) {
419 for (i = 0; i < remote_dev_info->uuid_count; i++) {
420 char *uuid = remote_dev_info->uuids[i];
421 if (strcasecmp(uuid, HID_UUID) == 0) {
422 int event = BLUETOOTH_EVENT_NONE;
424 event = (connected == TRUE) ?
425 BLUETOOTH_HID_CONNECTED :
426 BLUETOOTH_HID_DISCONNECTED;
427 param = g_variant_new("(is)", result,
429 _bt_send_event(BT_HID_EVENT, event,
439 gboolean __bt_handle_is_flight_mode_enabled(void)
441 #ifdef TIZEN_FEATURE_FLIGHTMODE_ENABLED
442 int is_flight_mode = 0;
445 ret = vconf_get_bool(VCONFKEY_TELEPHONY_FLIGHT_MODE, &is_flight_mode);
447 BT_ERR("vconf_get_bool failed");
449 return (is_flight_mode == 0) ? FALSE : TRUE;
455 void _bt_handle_adapter_event(GVariant *msg, const char *member)
459 int result = BLUETOOTH_ERROR_NONE;
460 GVariant *param = NULL;
461 ret_if(member == NULL);
463 if (strcasecmp(member, "DeviceCreated") == 0) {
464 char *object_path = NULL;
466 bt_remote_dev_info_t *remote_dev_info;
468 ret_if(_bt_is_device_creating() == FALSE);
470 /* Bonding from remote device */
471 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
473 g_variant_get(msg, "(&o)", &object_path);
474 _bt_convert_device_path_to_address((const char*)object_path, address);
476 remote_dev_info = _bt_get_remote_device_info_by_object_path(object_path);
477 if (remote_dev_info == NULL) {
482 _bt_free_device_info(remote_dev_info);
484 } else if (strcasecmp(member, "InterfacesRemoved") == 0) {
485 char *object_path = NULL;
487 bt_cache_info_t *cache_info;
488 bt_remote_dev_info_t *dev_info;
491 /* Bonding from remote device */
492 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
494 g_variant_get(msg, "(&o)", &object_path);
496 _bt_convert_device_path_to_address((const char *)object_path, address);
498 node = g_list_first(p_cache_list);
500 while (node != NULL) {
501 cache_info = (bt_cache_info_t *)node->data;
503 if (cache_info == NULL) {
504 node = g_list_next(node);
508 dev_info = cache_info->dev_info;
509 if (strcasecmp(dev_info->address,
511 p_cache_list = g_list_remove(p_cache_list,
513 __bt_free_cache_info(cache_info);
516 node = g_list_next(node);
519 } else if (strcasecmp(member, "AdvertisingEnabled") == 0) {
520 BT_DBG("Advertising Enabled");
524 gboolean status = FALSE;
526 g_variant_get(msg, "(ib)", &slot_id, &status);
528 BT_DBG("Advertising Enabled : slot_id [%d] status [%d]", slot_id, status);
530 /* Send event to application */
531 _bt_set_advertising_status(slot_id, status);
533 adv_handle = _bt_get_adv_slot_adv_handle(slot_id);
536 event = BLUETOOTH_EVENT_ADVERTISING_STARTED;
538 event = BLUETOOTH_EVENT_ADVERTISING_STOPPED;
539 param = g_variant_new("(ii)", result,
543 sender = _bt_get_adv_slot_owner(slot_id);
544 _bt_send_event_to_dest(sender, BT_ADAPTER_EVENT,
548 if (event == BLUETOOTH_EVENT_ADVERTISING_STOPPED)
549 _bt_unregister_adv_slot_owner(slot_id);
550 } else if (strcasecmp(member, "RssiEnabled") == 0) {
551 BT_DBG("RSSI Enabled");
552 gboolean status = FALSE;
553 char *address = NULL;
555 g_variant_get(msg, "(sib)", &address, &link_type, &status);
557 BT_DBG("RSSI Enabled [%s %d]", address, status);
558 param = g_variant_new("(isib)", result,
559 address, link_type, status);
560 _bt_send_event(BT_DEVICE_EVENT,
561 BLUETOOTH_EVENT_RSSI_ENABLED,
564 } else if (strcasecmp(member, "RssiAlert") == 0) {
565 BT_DBG("RSSI Alert");
569 char *address = NULL;
570 g_variant_get(msg, "(siii)", &address, &link_type, &alert_type, &rssi_dbm);
572 BT_DBG("RSSI Alert: [Address %s LinkType %d] [Type %d DBM %d]",
573 address, alert_type, rssi_dbm);
574 param = g_variant_new("(isiii)", result,
575 address, link_type, alert_type, rssi_dbm);
576 _bt_send_event(BT_DEVICE_EVENT,
577 BLUETOOTH_EVENT_RSSI_ALERT,
580 } else if (strcasecmp(member, "RawRssi") == 0) {
584 char *address = NULL;
585 g_variant_get(msg, "(sii)", &address, &link_type, &rssi_dbm);
587 BT_DBG("Raw RSSI: [Address %s] [Link Type %d][RSSI DBM %d]",
588 address, link_type, rssi_dbm);
589 param = g_variant_new("(isii)", result,
590 address, link_type, rssi_dbm);
591 _bt_send_event(BT_DEVICE_EVENT,
592 BLUETOOTH_EVENT_RAW_RSSI,
595 } else if (strcasecmp(member, BT_HARDWARE_ERROR) == 0) {
596 BT_ERR_C("Hardware error received from BLUEZ");
597 /* Don't add the recovery logic into platform */
599 _bt_recover_adapter();
601 } else if (strcasecmp(member, BT_TX_TIMEOUT_ERROR) == 0) {
602 BT_ERR_C("Tx timeout error received from BLUEZ");
603 /* Don't add the recovery logic into platform */
605 _bt_recover_adapter();
611 static void __bt_adapter_property_changed_event(GVariant *msg, const char *path)
613 GDBusProxy *adapter_proxy;
615 int result = BLUETOOTH_ERROR_NONE;
616 GVariantIter value_iter;
617 GVariant *val = NULL;
618 GVariant *ret = NULL;
620 char *property = NULL;
621 GVariant *param = NULL;
622 g_variant_iter_init(&value_iter, msg);
623 while ((g_variant_iter_loop(&value_iter, "{sv}", &property, &val))) {
624 BT_INFO("Property %s", property);
626 if (strcasecmp(property, "Discovering") == 0) {
627 gboolean discovering = FALSE;
628 g_variant_get(val, "b", &discovering);
629 /* Send event to application */
630 BT_DBG("Discovering %d", discovering);
631 if (discovering == TRUE) {
632 _bt_set_discovery_status(TRUE);
633 param = g_variant_new("(i)", result);
634 _bt_send_event(BT_ADAPTER_EVENT,
635 BLUETOOTH_EVENT_DISCOVERY_STARTED,
638 ret_if(event_id > 0);
640 adapter_proxy = _bt_get_adapter_proxy();
641 ret_if(adapter_proxy == NULL);
643 /* Need to stop searching */
644 ret = g_dbus_proxy_call_sync(adapter_proxy, "StopDiscovery",
646 G_DBUS_CALL_FLAGS_NONE,
650 BT_ERR("Dbus Error : %s", err->message);
654 g_variant_unref(ret);
656 event_id = g_timeout_add(BT_DISCOVERY_FINISHED_DELAY,
657 (GSourceFunc)_bt_discovery_finished_cb, NULL);
659 } else if (strcasecmp(property, "LEDiscovering") == 0) {
660 gboolean le_discovering = FALSE;
662 g_variant_get(val, "b", &le_discovering);
663 /* Send event to application */
664 if (le_discovering == TRUE) {
665 _bt_set_le_scan_status(TRUE);
666 param = g_variant_new("(i)", result);
667 _bt_send_event(BT_LE_ADAPTER_EVENT,
668 BLUETOOTH_EVENT_LE_DISCOVERY_STARTED,
671 ret_if(le_scan_event_id > 0);
673 adapter_proxy = _bt_get_adapter_proxy();
674 ret_if(adapter_proxy == NULL);
676 /* Need to stop searching */
677 ret = g_dbus_proxy_call_sync(adapter_proxy, "StopLEDiscovery",
679 G_DBUS_CALL_FLAGS_NONE,
683 BT_ERR("Dbus Error %s", err->message);
687 g_variant_unref(ret);
689 le_scan_event_id = g_timeout_add(BT_DISCOVERY_FINISHED_DELAY,
690 (GSourceFunc)__bt_le_discovery_finished_cb, NULL);
692 } else if (strcasecmp(property, "Name") == 0) {
694 g_variant_get(val, "s", &name);
695 param = g_variant_new("(is)", result, name);
696 /* Send event to application */
697 _bt_send_event(BT_ADAPTER_EVENT,
698 BLUETOOTH_EVENT_LOCAL_NAME_CHANGED,
701 } else if (strcasecmp(property, "Alias") == 0) {
703 g_variant_get(val, "s", &alias);
704 param = g_variant_new("(is)", result, alias);
705 /* Send event to application */
706 _bt_send_event(BT_ADAPTER_EVENT,
707 BLUETOOTH_EVENT_LOCAL_NAME_CHANGED,
710 } else if (strcasecmp(property, "Discoverable") == 0) {
711 gboolean discoverable = FALSE;
713 g_variant_get(val, "b", &discoverable);
714 BT_DBG("discoverable %d", discoverable);
716 if (discoverable == FALSE) {
717 if (_bt_get_discoverable_timeout_property() > 0) {
719 adapter_proxy = _bt_get_adapter_properties_proxy();
720 ret_if(adapter_proxy == NULL);
721 ret = g_dbus_proxy_call_sync(adapter_proxy, "Set",
722 g_variant_new("(ssv)", BT_ADAPTER_INTERFACE,
723 "DiscoverableTimeout",
724 g_variant_new("i", time)),
725 G_DBUS_CALL_FLAGS_NONE,
730 BT_ERR("StopLEDiscovery Failed: %s", err->message);
734 g_variant_unref(ret);
737 mode = BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE;
739 /* Send event to application */
740 BT_INFO("[Connectable]");
741 param = g_variant_new("(in)", result, mode);
742 _bt_send_event(BT_ADAPTER_EVENT,
743 BLUETOOTH_EVENT_DISCOVERABLE_MODE_CHANGED,
746 _bt_get_discoverable_mode(&mode);
748 /* Event will be sent by "DiscoverableTimeout" signal */
749 if (mode != BLUETOOTH_DISCOVERABLE_MODE_GENERAL_DISCOVERABLE) {
751 g_variant_unref(val);
755 /* Send event to application */
756 BT_INFO("[General Discoverable]");
757 param = g_variant_new("(in)", result, mode);
758 _bt_send_event(BT_ADAPTER_EVENT,
759 BLUETOOTH_EVENT_DISCOVERABLE_MODE_CHANGED,
762 } else if (strcasecmp(property, "DiscoverableTimeout") == 0) {
763 _bt_get_discoverable_mode(&mode);
765 /* Event was already sent by "Discoverable" signal */
766 if (mode == BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE ||
767 mode == BLUETOOTH_DISCOVERABLE_MODE_GENERAL_DISCOVERABLE) {
769 g_variant_unref(val);
773 /* Send event to application */
774 BT_INFO("[Limited Discoverable (Timeout %u secs)]",
775 _bt_get_discoverable_timeout_property());
776 param = g_variant_new("(in)", result, mode);
777 _bt_send_event(BT_ADAPTER_EVENT,
778 BLUETOOTH_EVENT_DISCOVERABLE_MODE_CHANGED,
780 } else if (strcasecmp(property, "Powered") == 0) {
781 /* TODO: Need to check this operation!! */
782 gboolean powered = FALSE;
785 g_variant_get(val, "b", &powered);
786 BT_DBG("Powered = %d", powered);
787 if (powered == FALSE) {
788 #ifdef TIZEN_FEATURE_BT_USB_DONGLE
789 _bt_handle_adapter_removed();
791 if (vconf_get_int(VCONFKEY_BT_STATUS, &bt_state) == 0 &&
792 bt_state != VCONFKEY_BT_STATUS_OFF) {
793 if (__bt_handle_is_flight_mode_enabled() == FALSE)
794 _bt_disable_adapter();
796 _bt_handle_adapter_removed();
799 if (vconf_get_int(VCONFKEY_BT_LE_STATUS, &bt_state) == 0 &&
800 bt_state != VCONFKEY_BT_LE_STATUS_OFF) {
801 _bt_set_le_disabled(BLUETOOTH_ERROR_NONE);
804 #ifdef TIZEN_FEATURE_BT_USB_DONGLE
805 _bt_handle_adapter_added();
808 } else if (strcasecmp(property, "Connectable") == 0) {
809 gboolean connectable = FALSE;
811 g_variant_get(val, "b", &connectable);
813 BT_DBG("Connectable property is changed : %d", connectable);
814 param = g_variant_new("(b)", connectable);
815 _bt_send_event(BT_ADAPTER_EVENT,
816 BLUETOOTH_EVENT_CONNECTABLE_CHANGED,
819 if (_bt_adapter_get_status() == BT_DEACTIVATING &&
820 _bt_adapter_get_le_status() == BT_LE_ACTIVATED &&
822 _bt_set_disabled(BLUETOOTH_ERROR_NONE);
824 } else if (strcasecmp(property, "SupportedLEFeatures") == 0) {
827 GVariantIter *iter = NULL;
828 g_variant_get(val, "as", &iter);
830 ret_if(iter == NULL);
832 while (g_variant_iter_loop(iter, "s", &name)) {
833 BT_DBG("name = %s", name);
834 g_variant_iter_loop(iter, "s", &value);
835 BT_DBG("Value = %s", value);
836 if (FALSE == _bt_update_le_feature_support(name, value))
837 BT_INFO("Fail to update LE feature info");
840 g_variant_iter_free(iter);
841 } else if (strcasecmp(property, "IpspInitStateChanged") == 0) {
842 gboolean ipsp_initialized = FALSE;
844 g_variant_get(val, "b", &ipsp_initialized);
845 BT_DBG("IPSP init state changed: %d", ipsp_initialized);
846 param = g_variant_new("(b)", ipsp_initialized);
848 /* Send event to application */
849 _bt_send_event(BT_ADAPTER_EVENT,
850 BLUETOOTH_EVENT_IPSP_INIT_STATE_CHANGED,
853 BT_DBG("property : [%s]", property);
858 static void __bt_obex_property_changed_event(GVariant *msg, const char *path)
862 GVariantIter value_iter;
863 GVariant *child = NULL, *val = NULL;
864 char *property = NULL;
865 g_variant_iter_init(&value_iter, msg);
866 while ((child = g_variant_iter_next_value(&value_iter))) {
867 g_variant_get(child, "{sv}", &property, &val);
869 ret_if(property == NULL);
871 BT_DBG("property :%s", property);
873 if (strcasecmp(property, "Status") == 0) {
875 g_variant_get(val, "s", &status);
877 if (strcasecmp(status, "active") == 0) {
878 _bt_obex_transfer_started(path);
879 } else if (strcasecmp(status, "complete") == 0) {
880 _bt_obex_transfer_completed(path, TRUE);
881 _bt_pbap_obex_transfer_completed(path, TRUE);
882 } else if (strcasecmp(status, "error") == 0) {
883 _bt_obex_transfer_completed(path, FALSE);
884 _bt_pbap_obex_transfer_completed(path, FALSE);
887 } else if (strcasecmp(property, "Transferred") == 0) {
888 guint64 transferred = 0;
889 /* As Transferred is expected guint64 so change int to guint64 and
890 * eariler transferred is static because of it can overwrite data
891 * on present on opc_obex_conn or obexd_conn as these are
892 * static memory are in sequential */
893 g_variant_get(val, "t", &transferred);
895 _bt_obex_transfer_progress(path, transferred);
897 /* TODO: MAP, "Complete"? see above */
899 g_variant_unref(val);
900 g_variant_unref(child);
905 static void __bt_device_property_changed_event(GVariant *msg, const char *path)
910 int result = BLUETOOTH_ERROR_NONE;
911 GVariantIter value_iter;
913 char *property = NULL;
915 GVariant *param = NULL;
916 bt_remote_dev_info_t *remote_dev_info;
917 g_variant_iter_init(&value_iter, msg);
918 #ifdef TIZEN_FEATURE_BT_DPM
919 int desktop_state = DPM_BT_ERROR;
921 while ((g_variant_iter_loop(&value_iter, "{sv}", &property, &val))) {
922 BT_DBG("Property %s", property);
923 if (strcasecmp(property, "Connected") == 0) {
926 g_variant_get(val, "i", &connected);
928 event = (connected != BLUETOOTH_CONNECTED_LINK_NONE) ?
929 BLUETOOTH_EVENT_DEVICE_CONNECTED :
930 BLUETOOTH_EVENT_DEVICE_DISCONNECTED;
932 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
934 _bt_convert_device_path_to_address(path, address);
936 BT_DBG("connected: %d", connected);
937 BT_DBG("address: %s", address);
939 remote_dev_info = _bt_get_remote_device_info_by_object_path(path);
941 if (remote_dev_info != NULL) {
942 __bt_device_remote_connected_properties(
943 remote_dev_info, address,
944 connected != BLUETOOTH_CONNECTED_LINK_NONE ?
946 _bt_free_device_info(remote_dev_info);
948 param = g_variant_new("(is)", result, address);
949 /* Send event to application */
950 _bt_send_event(BT_DEVICE_EVENT,
954 } else if (strcasecmp(property, "RSSI") == 0) {
955 bt_remote_dev_info_t *remote_dev_info;
957 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
959 _bt_convert_device_path_to_address(path, address);
960 BT_DBG("address: %s", address);
964 remote_dev_info = _bt_get_remote_device_info_by_object_path(path);
965 if (remote_dev_info == NULL) {
967 g_variant_unref(val);
970 BT_DBG("Address type %d", remote_dev_info->addr_type);
972 if (remote_dev_info->addr_type == 0) {
973 BT_DBG("Name %s", remote_dev_info->name);
975 #ifdef TIZEN_FEATURE_BT_DPM
976 _bt_dpm_get_bluetooth_desktop_connectivity_state(&desktop_state);
977 if (desktop_state == DPM_RESTRICTED) {
978 bluetooth_device_class_t device_class;
979 _bt_divide_device_class(&device_class, remote_dev_info->class);
981 if (device_class.major_class ==
982 BLUETOOTH_DEVICE_MAJOR_CLASS_COMPUTER) {
983 _bt_free_device_info(remote_dev_info);
985 g_variant_unref(val);
991 GVariant *uuids = NULL;
992 GVariantBuilder *builder = NULL;
994 builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
995 for (i = 0; i < remote_dev_info->uuid_count; i++) {
996 g_variant_builder_add(builder, "s",
997 remote_dev_info->uuids[i]);
999 uuids = g_variant_new("as", builder);
1000 g_variant_builder_unref(builder);
1001 GVariant *manufacturer_data = NULL;
1002 manufacturer_data = g_variant_new_from_data(G_VARIANT_TYPE_BYTESTRING,
1003 remote_dev_info->manufacturer_data,
1004 remote_dev_info->manufacturer_data_len,
1007 param = g_variant_new("(isunsbub@asn@ay)", result,
1008 remote_dev_info->address,
1009 remote_dev_info->class,
1010 remote_dev_info->rssi,
1011 remote_dev_info->name,
1012 remote_dev_info->paired,
1013 remote_dev_info->connected,
1014 remote_dev_info->trust,
1016 remote_dev_info->manufacturer_data_len,
1019 _bt_send_event(BT_ADAPTER_EVENT,
1020 BLUETOOTH_EVENT_REMOTE_DEVICE_FOUND,
1023 _bt_free_device_info(remote_dev_info);
1024 } else if (strcasecmp(property, "GattConnected") == 0) {
1025 gboolean gatt_connected = FALSE;
1027 g_variant_get(val, "b", &gatt_connected);
1029 event = gatt_connected ? BLUETOOTH_EVENT_GATT_CONNECTED :
1030 BLUETOOTH_EVENT_GATT_DISCONNECTED;
1032 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1034 _bt_convert_device_path_to_address(path, address);
1036 BT_DBG("gatt_connected: %d", gatt_connected);
1037 BT_DBG("address: %s", address);
1038 param = g_variant_new("(is)", result, address);
1039 /* Send event to application */
1040 _bt_send_event(BT_DEVICE_EVENT,
1044 } else if (strcasecmp(property, "Paired") == 0) {
1045 gboolean paired = FALSE;
1046 bt_remote_dev_info_t *remote_dev_info;
1047 g_variant_get(val, "b", &paired);
1048 _bt_agent_set_canceled(FALSE);
1049 /* BlueZ sends paired signal for each paired device */
1050 /* during activation, We should ignore this, otherwise*/
1051 /* application thinks that a new device got paired */
1052 if (_bt_adapter_get_status() != BT_ACTIVATED) {
1053 BT_DBG("BT is not activated, so ignore this");
1055 g_variant_unref(val);
1059 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1061 _bt_convert_device_path_to_address(path, address);
1063 remote_dev_info = _bt_get_remote_device_info_by_object_path(path);
1064 if (remote_dev_info == NULL) {
1066 g_variant_unref(val);
1071 if (paired == FALSE) {
1072 BT_INFO("Unpaired: %s", address);
1073 __bt_update_remote_cache_devinfo(address, FALSE);
1074 param = g_variant_new("(is)", result, address);
1075 _bt_send_event(BT_ADAPTER_EVENT,
1076 BLUETOOTH_EVENT_BONDED_DEVICE_REMOVED,
1078 #ifdef TIZEN_BT_A2DP_SINK_AUTO_CONNECT
1080 char *last_connected = NULL;
1081 last_connected = vconf_get_str(BT_LAST_CONNECTED_DEVICE);
1082 if (!g_strcmp0(address, last_connected))
1083 _bt_audio_set_auto_connect_device_addr("");
1085 free(last_connected);
1089 char secure_addr[BT_ADDRESS_STRING_SIZE] = { 0 };
1091 _bt_convert_addr_string_to_secure_string(secure_addr, address);
1092 BT_INFO("### Paired: %s", secure_addr);
1093 __bt_update_remote_cache_devinfo(address, TRUE);
1095 if (_bt_is_device_creating() == TRUE) {
1096 BT_DBG("Try to Pair by me");
1097 _bt_free_device_info(remote_dev_info);
1100 g_variant_unref(val);
1103 GVariant *uuids = NULL;
1104 GVariantBuilder *builder = NULL;
1106 builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
1107 for (i = 0; i < remote_dev_info->uuid_count; i++) {
1108 g_variant_builder_add(builder, "s",
1109 remote_dev_info->uuids[i]);
1111 uuids = g_variant_new("as", builder);
1112 g_variant_builder_unref(builder);
1113 GVariant *manufacturer_data = NULL;
1114 manufacturer_data = g_variant_new_from_data(G_VARIANT_TYPE_BYTESTRING,
1115 remote_dev_info->manufacturer_data,
1116 remote_dev_info->manufacturer_data_len,
1120 param = g_variant_new("(isunsbub@asn@ay)", result,
1121 address, remote_dev_info->class,
1122 remote_dev_info->rssi,
1123 remote_dev_info->name,
1124 remote_dev_info->paired,
1125 remote_dev_info->connected,
1126 remote_dev_info->trust,
1128 remote_dev_info->manufacturer_data_len,
1130 _bt_send_event(BT_ADAPTER_EVENT,
1131 BLUETOOTH_EVENT_BONDING_FINISHED,
1134 _bt_free_device_info(remote_dev_info);
1136 } else if (strcasecmp(property, "LegacyPaired") == 0) {
1137 gboolean paired = FALSE;
1138 bt_remote_dev_info_t *remote_dev_info;
1139 unsigned char auth_info[5] = {0, };
1141 if (_bt_adapter_get_status() != BT_ACTIVATED) {
1142 BT_DBG("BT is not activated, so ignore this");
1144 g_variant_unref(val);
1148 g_variant_get(val, "b", &paired);
1149 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1150 BT_DBG("LegacyPaired: %d", paired);
1151 _bt_convert_device_path_to_address(path, address);
1153 remote_dev_info = _bt_get_remote_device_info_by_object_path(path);
1154 if (remote_dev_info == NULL) {
1157 g_variant_unref(val);
1160 if (remote_dev_info->is_alias_set == FALSE) {
1161 /*minimum Size of the samsung specific manufacturer data is greater than 30 */
1162 if ((remote_dev_info->manufacturer_data_len > 30) &&
1163 (remote_dev_info->manufacturer_data[0] == 0x00) &&
1164 (remote_dev_info->manufacturer_data[1] == 0x75)) {
1166 /* 2 samsung (0x00 0x75) + 1 (control and version) + 1 (service ID) +
1167 1 (discovery version) + 1 (associated service ID)
1168 2 (Proxamity and locality) + 2 (Device type and icon) = 10 */
1170 memcpy(auth_info, &(remote_dev_info->manufacturer_data[10]), 5);
1174 BT_DBG("LegacyPairing Failed with %s. Show Error Popup", remote_dev_info->name);
1175 _bt_launch_system_popup(BT_AGENT_EVENT_LEGACY_PAIR_FAILED_FROM_REMOTE,
1176 remote_dev_info->name, auth_info, NULL, NULL, NULL);
1178 _bt_free_device_info(remote_dev_info);
1180 } else if (strcasecmp(property, "Trusted") == 0) {
1181 gboolean trusted = FALSE;
1183 g_variant_get(val, "b", &trusted);
1185 event = trusted ? BLUETOOTH_EVENT_DEVICE_AUTHORIZED :
1186 BLUETOOTH_EVENT_DEVICE_UNAUTHORIZED;
1188 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1190 _bt_convert_device_path_to_address(path, address);
1192 BT_DBG("trusted: %d", trusted);
1193 BT_DBG("address: %s", address);
1194 param = g_variant_new("(is)", result, address);
1195 /* Send event to application */
1196 _bt_send_event(BT_DEVICE_EVENT,
1200 } else if (strcasecmp(property, "TrustedProfiles") == 0) {
1203 g_variant_get(val, "u", &trusted);
1205 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1206 _bt_convert_device_path_to_address(path, address);
1208 BT_DBG("Address: %s, TrustedProfiles: %d", address, trusted);
1209 _bt_send_event(BT_DEVICE_EVENT,
1210 BLUETOOTH_EVENT_SUPPORTED_PROFILE_TRUSTED,
1211 g_variant_new("(isi)", result, address, trusted));
1213 } else if (strcasecmp(property, "IpspConnected") == 0) {
1214 gboolean connected = FALSE;
1216 g_variant_get(val, "b", &connected);
1219 event = connected ? BLUETOOTH_EVENT_IPSP_CONNECTED :
1220 BLUETOOTH_EVENT_IPSP_DISCONNECTED;
1222 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1224 _bt_convert_device_path_to_address(path, address);
1226 BT_DBG("Ipspconnected: %d", connected);
1227 BT_DBG("address: %s", address);
1228 param = g_variant_new("(is)", result, address);
1230 /* Send event to application */
1231 _bt_send_event(BT_DEVICE_EVENT,
1235 } else if (strcasecmp(property, "IpspBtInterfaceInfo") == 0) {
1236 char *ifname = NULL;
1238 g_variant_get(val, "s", &ifname);
1240 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1242 _bt_convert_device_path_to_address(path, address);
1244 BT_DBG("Ipsp BT Interface Name: %s", ifname);
1245 BT_DBG("address: %s", address);
1246 param = g_variant_new("(iss)", result, address, ifname);
1248 /* Send event to application */
1249 _bt_send_event(BT_DEVICE_EVENT,
1250 BLUETOOTH_EVENT_IPSP_INTERFACE_INFO,
1258 static void __bt_media_control_changed_event(GVariant *msg, const char *path)
1261 int result = BLUETOOTH_ERROR_NONE;
1262 GVariantIter value_iter;
1263 char *property = NULL;
1265 GVariant *val = NULL;
1266 GVariant *child = NULL;
1267 bt_remote_dev_info_t *remote_dev_info;
1268 GVariant *param = NULL;
1269 g_variant_iter_init(&value_iter, msg);
1270 while ((child = g_variant_iter_next_value(&value_iter))) {
1271 g_variant_get(child, "{sv}", &property, &val);
1272 BT_INFO("Property %s", property);
1273 if (strcasecmp(property, "Connected") == 0) {
1274 gboolean connected = FALSE;
1276 g_variant_get(val, "b", &connected);
1278 event = connected ? BLUETOOTH_EVENT_AVRCP_CONNECTED :
1279 BLUETOOTH_EVENT_AVRCP_DISCONNECTED;
1281 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1283 _bt_convert_device_path_to_address(path, address);
1285 BT_DBG("connected: %d", connected);
1286 BT_DBG("address: %s", address);
1288 remote_dev_info = _bt_get_remote_device_info(address);
1290 if (remote_dev_info != NULL) {
1291 __bt_device_remote_connected_properties(
1292 remote_dev_info, address, connected);
1293 _bt_free_device_info(remote_dev_info);
1295 param = g_variant_new("(is)", result, address);
1296 /* Send event to application */
1297 _bt_send_event(BT_AVRCP_EVENT,
1303 g_variant_unref(child);
1304 g_variant_unref(val);
1309 int get_alert_level_enum(const char *alert)
1313 if (strcmp(alert, "none") == 0)
1314 lvl = BT_PXP_ALERT_NONE;
1315 else if (strcmp(alert, "mild") == 0)
1316 lvl = BT_PXP_ALERT_MILD;
1317 else if (strcmp(alert, "high") == 0)
1318 lvl = BT_PXP_ALERT_HIGH;
1323 static void _bt_handle_pxp_property_changed_event(GVariant *msg, const char *path, int role)
1325 int result = BLUETOOTH_ERROR_NONE;
1328 GVariantIter value_iter;
1329 char *property = NULL;
1331 GVariant *val = NULL;
1332 GVariant *child = NULL;
1333 GVariant *param = NULL;
1334 g_variant_iter_init(&value_iter, msg);
1337 while ((child = g_variant_iter_next_value(&value_iter))) {
1338 g_variant_get(child, "{sv}", &property, &val);
1339 BT_INFO("Property %s", property);
1341 if ((strcasecmp(property, "LinkLossAlertLevel") == 0) ||
1342 (strcasecmp(property, "ImmediateAlertLevel") == 0)) {
1343 char *alert_str = NULL;
1345 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1346 _bt_convert_device_path_to_address(path, address);
1348 if (strcasecmp(property, "LinkLossAlertLevel") == 0)
1349 service_type = BT_PXP_PROPERTY_LLS;
1351 service_type = BT_PXP_PROPERTY_IAS;
1353 g_variant_get(val, "s", &alert_str);
1355 alert_lvl = get_alert_level_enum(alert_str);
1357 param = g_variant_new("(isiii)", result, address,
1358 role, service_type, alert_lvl);
1360 /* Send event to application */
1361 _bt_send_event(BT_DEVICE_EVENT,
1362 BLUETOOTH_EVENT_PXP_PROPERTY_CHANGED,
1368 g_variant_unref(child);
1369 g_variant_unref(val);
1374 void _bt_handle_property_changed_event(GVariant *msg, const char *object_path)
1376 char *interface_name = NULL;
1377 GVariant *val = NULL;
1379 g_variant_get(msg, "(&s@a{sv}@as)", &interface_name, &val, NULL);
1381 if (strcasecmp(interface_name, BT_ADAPTER_INTERFACE) == 0) {
1382 __bt_adapter_property_changed_event(val,
1384 } else if (strcasecmp(interface_name, BT_DEVICE_INTERFACE) == 0) {
1385 __bt_device_property_changed_event(val, object_path);
1386 } else if (strcasecmp(interface_name, BT_OBEX_TRANSFER_INTERFACE) == 0) {
1387 BT_DBG("BT_OBEX_TRANSFER_INTERFACE");
1388 __bt_obex_property_changed_event(val,
1390 } else if (strcasecmp(interface_name, BT_MEDIA_CONTROL_INTERFACE) == 0) {
1391 __bt_media_control_changed_event(val,
1393 } else if (strcasecmp(interface_name, BT_PLAYER_CONTROL_INTERFACE) == 0) {
1394 _bt_handle_avrcp_control_event(val,
1396 } else if (strcasecmp(interface_name, BT_NETWORK_CLIENT_INTERFACE) == 0) {
1397 BT_DBG("BT_NETWORK_CLIENT_INTERFACE");
1398 _bt_handle_network_client_event(val,
1400 } else if (strcasecmp(interface_name, BT_GATT_CHAR_INTERFACE) == 0) {
1401 __bt_gatt_char_property_changed_event(val,
1403 } else if (strcasecmp(interface_name, BT_PROXIMITY_REPORTER_INTERFACE) == 0) {
1404 BT_DBG("BT_PROXIMITY_REPORTER_INTERFACE");
1405 _bt_handle_pxp_property_changed_event(val,
1406 object_path, BT_PXP_REPORTER_ROLE);
1408 g_variant_unref(val);
1411 void __bt_opc_property_changed_event(GVariant *msg,
1414 GVariantIter value_iter;
1415 char *property = NULL;
1416 GVariant *val = NULL;
1417 GVariant *child = NULL;
1419 g_variant_iter_init(&value_iter, msg);
1420 while ((child = g_variant_iter_next_value(&value_iter))) {
1421 g_variant_get(child, "{sv}", &property, &val);
1422 ret_if(property == NULL);
1424 if (strcasecmp(property, "Status") == 0) {
1425 char *status = NULL;
1426 g_variant_get(val, "s", &status);
1427 BT_DBG("Status is %s", status);
1429 if (strcasecmp(status, "active") == 0)
1430 _bt_obex_client_started(path);
1431 else if (strcasecmp(status, "complete") == 0)
1432 _bt_obex_client_completed(path, TRUE);
1433 else if (strcasecmp(status, "error") == 0)
1434 _bt_obex_client_completed(path, FALSE);
1437 } else if (strcasecmp(property, "Transferred") == 0) {
1438 guint64 transferred = 0;
1439 g_variant_get(val, "t", &transferred);
1441 _bt_obex_client_progress(path, transferred);
1443 BT_DBG("property : [%s]", property);
1446 g_variant_unref(child);
1447 g_variant_unref(val);
1451 void _bt_opc_property_changed_event(GVariant *msg, char *path)
1453 char *interface_name = NULL;
1454 GVariant *value = NULL;
1455 g_variant_get(msg, "(&s@a{sv}@as)", &interface_name, &value, NULL);
1456 BT_INFO("interface_name = %s", interface_name);
1457 if (strcasecmp(interface_name, BT_OBEX_TRANSFER_INTERFACE) == 0) {
1458 __bt_opc_property_changed_event(value,
1461 BT_DBG("interface_name : [%s]", interface_name);
1463 g_variant_unref(value);
1467 void __bt_map_property_changed_event(GVariant *msg,
1471 GVariantIter value_iter;
1472 char *property = NULL;
1473 GVariant *val = NULL;
1474 GVariant *child = NULL;
1476 g_variant_iter_init(&value_iter, msg);
1477 while ((child = g_variant_iter_next_value(&value_iter))) {
1478 g_variant_get(child, "{sv}", &property, &val);
1479 ret_if(property == NULL);
1481 if (strcasecmp(property, "Status") == 0) {
1482 char *status = NULL;
1483 g_variant_get(val, "s", &status);
1484 BT_DBG("Status is %s", status);
1486 if (strcasecmp(status, "active") == 0) {
1487 BT_DBG("EVENT : STARTED");
1488 // currently doing nothing
1489 } else if (strcasecmp(status, "complete") == 0) {
1490 BT_DBG("EVENT : COMPLETED");
1491 _bt_on_get_message_finished(path);
1492 } else if (strcasecmp(status, "error") == 0) {
1493 BT_DBG("EVENT : FAILED");
1494 // currently doing nothing
1497 } else if (strcasecmp(property, "Transferred") == 0) {
1498 guint64 transferred = 0;
1499 g_variant_get(val, "t", &transferred);
1501 BT_DBG("EVENT : PROGRESS CALLBACK");
1502 // currently doing nothing - progress callback type is not used
1504 BT_DBG("OTHER EVENT : property : [%s]", property);
1507 g_variant_unref(child);
1508 g_variant_unref(val);
1512 void _bt_map_property_changed_event(GVariant *msg, char *path)
1514 BT_DBG("Entered _bt_map_property_changed_event");
1515 char *interface_name = NULL;
1516 GVariant *value = NULL;
1517 g_variant_get(msg, "(&s@a{sv}@as)", &interface_name, &value, NULL);
1518 BT_INFO("interface_name = %s", interface_name);
1519 if (strcasecmp(interface_name, BT_OBEX_TRANSFER_INTERFACE) == 0) {
1520 __bt_map_property_changed_event(value,
1523 BT_DBG("interface_name : [%s]", interface_name);
1525 g_variant_unref(value);
1529 void _bt_handle_input_event(GVariant *msg, const char *path)
1531 int result = BLUETOOTH_ERROR_NONE;
1532 gboolean property_flag = FALSE;
1533 GVariantIter value_iter;
1534 char *property = NULL;
1535 GVariant *child = NULL, *val = NULL;
1536 bt_remote_dev_info_t *remote_dev_info;
1537 GVariant *param = NULL;
1538 g_variant_iter_init(&value_iter, msg);
1539 while ((child = g_variant_iter_next_value(&value_iter))) {
1540 g_variant_get(child, "{sv}", &property, &val);
1542 ret_if(property == NULL);
1544 if (strcasecmp(property, "Connected") == 0) {
1545 int event = BLUETOOTH_EVENT_NONE;
1547 g_variant_get(val, "b", &property_flag);
1549 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1551 _bt_convert_device_path_to_address(path, address);
1553 event = (property_flag == TRUE) ?
1554 BLUETOOTH_HID_CONNECTED :
1555 BLUETOOTH_HID_DISCONNECTED;
1556 param = g_variant_new("(is)", result, address);
1557 _bt_send_event(BT_HID_EVENT, event,
1559 /* Check HID connection type (Keyboard or Mouse) and update the status */
1560 remote_dev_info = _bt_get_remote_device_info_by_object_path(path);
1562 if (property_flag == TRUE) {
1563 hid_connected_device_count++;
1564 __bt_set_device_values(TRUE,
1565 VCONFKEY_BT_DEVICE_HID_CONNECTED);
1567 hid_connected_device_count--;
1568 if (hid_connected_device_count == 0)
1569 __bt_set_device_values(FALSE,
1570 VCONFKEY_BT_DEVICE_HID_CONNECTED);
1573 if (remote_dev_info != NULL) {
1574 BT_DBG("HID device class [%x]", remote_dev_info->class);
1575 if (remote_dev_info->class &
1576 BLUETOOTH_DEVICE_MINOR_CLASS_KEY_BOARD) {
1577 __bt_set_device_values(property_flag,
1578 VCONFKEY_BT_DEVICE_HID_KEYBOARD_CONNECTED);
1582 if (remote_dev_info->class &
1583 BLUETOOTH_DEVICE_MINOR_CLASS_POINTING_DEVICE) {
1584 __bt_set_device_values(property_flag,
1585 VCONFKEY_BT_DEVICE_HID_MOUSE_CONNECTED);
1587 _bt_free_device_info(remote_dev_info);
1592 g_variant_unref(val);
1593 g_variant_unref(child);
1597 void _bt_handle_network_server_event(GVariant *msg, const char *member)
1599 int result = BLUETOOTH_ERROR_NONE;
1600 char *address = NULL;
1601 char *device = NULL;
1602 GVariant *param = NULL;
1603 ret_if(member == NULL);
1604 if (strcasecmp(member, "PeerConnected") == 0) {
1605 g_variant_get(msg, "(ss)", &device, &address);
1607 __bt_set_device_values(TRUE,
1608 VCONFKEY_BT_DEVICE_PAN_CONNECTED);
1609 param = g_variant_new("(iss)", result, device, address);
1610 _bt_send_event(BT_NETWORK_EVENT, BLUETOOTH_EVENT_NETWORK_SERVER_CONNECTED,
1614 nap_connected_device_count++;
1615 } else if (strcasecmp(member, "PeerDisconnected") == 0) {
1616 g_variant_get(msg, "(ss)", &device, &address);
1617 nap_connected_device_count--;
1618 if (nap_connected_device_count == 0)
1619 __bt_set_device_values(FALSE,
1620 VCONFKEY_BT_DEVICE_PAN_CONNECTED);
1621 param = g_variant_new("(iss)", result, device, address);
1622 _bt_send_event(BT_NETWORK_EVENT, BLUETOOTH_EVENT_NETWORK_SERVER_DISCONNECTED,
1629 void _bt_handle_network_client_event(GVariant *msg,
1634 int result = BLUETOOTH_ERROR_NONE;
1635 gboolean property_flag = FALSE;
1636 char *property = NULL;
1637 GVariant *val = NULL;
1638 GVariantIter value_iter;
1639 GVariant *param = NULL;
1640 g_variant_iter_init(&value_iter, msg);
1641 while ((g_variant_iter_loop(&value_iter, "{sv}", &property, &val))) {
1642 if (strcasecmp(property, "Connected") == 0) {
1643 int event = BLUETOOTH_EVENT_NONE;
1646 g_variant_get(val, "b", &property_flag);
1647 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1649 _bt_convert_device_path_to_address(path, address);
1651 BT_DBG("property_flag %d", property_flag);
1652 if (property_flag == TRUE) {
1653 event = BLUETOOTH_EVENT_NETWORK_CONNECTED;
1654 nap_connected_device_count++;
1655 __bt_set_device_values(TRUE,
1656 VCONFKEY_BT_DEVICE_PAN_CONNECTED);
1658 event = BLUETOOTH_EVENT_NETWORK_DISCONNECTED;
1659 nap_connected_device_count--;
1660 if (nap_connected_device_count == 0)
1661 __bt_set_device_values(FALSE,
1662 VCONFKEY_BT_DEVICE_PAN_CONNECTED);
1664 param = g_variant_new("(is)", result, address);
1665 _bt_send_event(BT_NETWORK_EVENT, event,
1674 void __bt_gatt_char_property_changed_event(GVariant *msg,
1677 GVariantIter value_iter;
1678 char *property = NULL;
1679 char * char_handle = NULL;
1680 GVariant *val = NULL;
1681 int result = BLUETOOTH_ERROR_NONE;
1682 GVariant *param = NULL;
1683 g_variant_iter_init(&value_iter, msg);
1684 char_handle = g_strdup(path);
1685 while ((g_variant_iter_loop(&value_iter, "{sv}", &property, &val))) {
1686 BT_INFO("Property %s", property);
1688 ret_if(property == NULL);
1690 if (strcasecmp(property, "Notifying") == 0) {
1691 gboolean property_flag = FALSE;
1692 g_variant_get(val, "b", &property_flag);
1693 if (property_flag == TRUE)
1694 BT_DBG("notifying is enabled");
1696 BT_DBG("notifying is disabled");
1697 } else if (strcasecmp(property, "ChangedValue") == 0) {
1699 GByteArray *gp_byte_array = NULL;
1700 BT_INFO("Type '%s'\n", g_variant_get_type_string(val));
1703 gp_byte_array = g_byte_array_new();
1704 len = g_variant_get_size(val);
1705 BT_DBG("Len = %d", len);
1706 g_byte_array_append(gp_byte_array,
1707 (const guint8 *) g_variant_get_data(val), len);
1708 if (gp_byte_array->len != 0) {
1709 GVariant *byte_array = NULL;
1710 byte_array = g_variant_new_from_data(
1711 G_VARIANT_TYPE_BYTESTRING,
1712 gp_byte_array->data,
1715 param = g_variant_new("(is@ay)", result, char_handle,
1718 /* Send event only registered client */
1719 _bt_send_char_value_changed_event(param);
1721 g_byte_array_free(gp_byte_array, TRUE);
1725 g_free(char_handle);
1728 void _bt_handle_gatt_event(GVariant *msg, const char *member, const char *path)
1730 ret_if(path == NULL);
1732 if (strcasecmp(member, "GattValueChanged") == 0) {
1735 /*** Debug only ***/
1736 GVariant *value = NULL;
1738 char *buffer = NULL;
1740 g_variant_get(msg, "(is@ay)", NULL, NULL, &value);
1741 value_len = g_variant_get_size(value);
1742 if (value_len > 0) {
1743 char buf[8 * 5 + 1] = { 0 };
1746 buffer = (char *)g_variant_get_data(value);
1747 to = value_len > (sizeof(buf) / 5) ? sizeof(buf) / 5 : value_len;
1749 for (i = 0; i < to; i++)
1750 snprintf(&buf[i * 5], 6, "0x%02x ", buffer[i]);
1752 BT_DBG("GATT Val[%d] %s", value_len, buf);
1754 g_variant_unref(value);
1758 /* Send event only registered client */
1759 _bt_send_char_value_changed_event(msg);
1764 void _bt_handle_device_event(GVariant *msg, const char *member, const char *path)
1767 int result = BLUETOOTH_ERROR_NONE;
1769 char *dev_name = NULL;
1770 const char *property = NULL;
1771 GVariant *param = NULL;
1772 char secure_address[BT_ADDRESS_STRING_SIZE] = { 0 };
1773 ret_if(path == NULL);
1775 if (strcasecmp(member, "PropertyChanged") == 0) {
1777 g_variant_get(msg, "(s)", &property);
1779 ret_if(property == NULL);
1781 if (strcasecmp(property, "GattConnected") == 0) {
1782 gboolean connected = FALSE;
1784 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1786 _bt_convert_device_path_to_address(path, address);
1787 g_variant_get(msg, "(b)", &connected);
1789 event = connected ? BLUETOOTH_EVENT_GATT_CONNECTED :
1790 BLUETOOTH_EVENT_GATT_DISCONNECTED;
1791 param = g_variant_new("(is)", result, address);
1792 _bt_send_event(BT_DEVICE_EVENT,
1796 } else if (strcasecmp(property, "Paired") == 0) {
1797 gboolean paired = FALSE;
1798 bt_remote_dev_info_t *remote_dev_info;
1799 g_variant_get(msg, "(b)", &paired);
1801 ret_if(paired == FALSE);
1803 /* BlueZ sends paired signal for each paired device */
1804 /* during activation, We should ignore this, otherwise*/
1805 /* application thinks that a new device got paired */
1806 if (_bt_adapter_get_status() != BT_ACTIVATED) {
1807 BT_DBG("BT is not activated, so ignore this");
1811 if (_bt_is_device_creating() == TRUE) {
1812 BT_DBG("Try to Pair by me");
1816 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1818 _bt_convert_device_path_to_address(path, address);
1820 remote_dev_info = _bt_get_remote_device_info_by_object_path(path);
1821 if (remote_dev_info == NULL) {
1825 GVariant *uuids = NULL;
1826 GVariantBuilder *builder = NULL;
1828 builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
1829 for (i = 0; i < remote_dev_info->uuid_count; i++) {
1830 g_variant_builder_add(builder, "s",
1831 remote_dev_info->uuids[i]);
1833 uuids = g_variant_new("as", builder);
1834 g_variant_builder_unref(builder);
1835 GVariant *manufacturer_data = NULL;
1836 manufacturer_data = g_variant_new_from_data(
1837 G_VARIANT_TYPE_BYTESTRING,
1838 remote_dev_info->manufacturer_data,
1839 remote_dev_info->manufacturer_data_len,
1841 param = g_variant_new("(isunsbub@asn@ay)", result,
1843 remote_dev_info->class,
1844 remote_dev_info->rssi,
1845 remote_dev_info->name,
1846 remote_dev_info->paired,
1847 remote_dev_info->connected,
1848 remote_dev_info->trust,
1850 remote_dev_info->manufacturer_data_len,
1852 _bt_send_event(BT_ADAPTER_EVENT,
1853 BLUETOOTH_EVENT_BONDING_FINISHED,
1855 _bt_free_device_info(remote_dev_info);
1858 } else if (strcasecmp(property, "UUIDs") == 0) {
1859 /* Once we get the updated uuid information after
1860 * reverse service search, update it to application */
1862 bt_remote_dev_info_t *remote_dev_info;
1864 ret_if(_bt_is_device_creating() == TRUE);
1866 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1868 _bt_convert_device_path_to_address(path, address);
1870 remote_dev_info = _bt_get_remote_device_info_by_object_path(path);
1871 if (remote_dev_info == NULL) {
1876 BT_DBG("UUID's count = %d", remote_dev_info->uuid_count);
1877 if (remote_dev_info->paired && remote_dev_info->uuid_count) {
1878 GVariant *uuids = NULL;
1879 GVariantBuilder *builder = NULL;
1881 builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
1882 for (i = 0; i < remote_dev_info->uuid_count; i++) {
1883 g_variant_builder_add(builder, "s",
1884 remote_dev_info->uuids[i]);
1886 uuids = g_variant_new("as", builder);
1887 g_variant_builder_unref(builder);
1888 GVariant *manufacture_data = g_variant_new_from_data((const GVariantType *)"ay",
1889 remote_dev_info->manufacturer_data, remote_dev_info->manufacturer_data_len,
1892 param = g_variant_new("(isunsbub@asn@ay)", result,
1893 address, remote_dev_info->class,
1894 remote_dev_info->rssi,
1895 remote_dev_info->name,
1896 remote_dev_info->paired,
1897 remote_dev_info->connected,
1898 remote_dev_info->trust,
1900 remote_dev_info->manufacturer_data_len,
1902 _bt_send_event(BT_ADAPTER_EVENT,
1903 BLUETOOTH_EVENT_SERVICE_SEARCHED,
1907 _bt_free_device_info(remote_dev_info);
1910 } else if (strcasecmp(member, "DeviceConnected") == 0) {
1911 unsigned char addr_type = 0;
1913 g_variant_get(msg, "(y)", &addr_type);
1915 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1917 _bt_convert_device_path_to_address(path, address);
1918 dev_name = _bt_get_bonded_device_name(address);
1920 _bt_convert_addr_string_to_secure_string(secure_address, address);
1921 BT_INFO("Address : %s Type : %d", secure_address, addr_type);
1922 BT_ERR_C("### Connected [%s] [%s]", !addr_type ? "BREDR" : "LE",
1923 !addr_type ? dev_name : secure_address);
1926 _bt_logging_connection(TRUE, addr_type);
1927 param = g_variant_new("(isy)", result, address, addr_type);
1928 /*Send event to application*/
1929 _bt_send_event(BT_DEVICE_EVENT,
1930 BLUETOOTH_EVENT_DEVICE_CONNECTED,
1933 } else if (strcasecmp(member, "Disconnected") == 0) {
1934 unsigned char disc_reason = 0;
1935 unsigned char addr_type = 0;
1936 char *dev_name = NULL;
1937 gboolean sending = FALSE;
1939 g_variant_get(msg, "(yys)", &addr_type, &disc_reason, &dev_name);
1941 result = disc_reason;
1943 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1945 _bt_convert_device_path_to_address(path, address);
1947 /* 0x00 BDADDR_BRDER
1948 0x01 BDADDR_LE_PUBLIC
1949 0x02 BDADDR_LE_RANDOM */
1950 _bt_convert_addr_string_to_secure_string(secure_address, address);
1951 BT_INFO("Address : %s Type : %d", secure_address, addr_type);
1952 BT_ERR_C("### Disconnected [%s] [%d : %s] [%s]", !addr_type ? "BREDR" : "LE",
1953 disc_reason, _bt_convert_disc_reason_to_string(disc_reason),
1954 !addr_type ? dev_name : secure_address);
1957 _bt_headset_set_local_connection(FALSE);
1958 _bt_logging_connection(FALSE, addr_type);
1961 #ifdef TIZEN_BT_A2DP_SINK_AUTO_CONNECT
1963 int bt_device_state = VCONFKEY_BT_DEVICE_NONE;
1965 if (vconf_get_int(VCONFKEY_BT_DEVICE, &bt_device_state) != 0)
1966 BT_ERR("vconf_get_int failed");
1968 BT_INFO("conn_state[0x%x], adapter_state [%d]",
1969 bt_device_state, _bt_adapter_get_status());
1971 if (disc_reason == BLUETOOTH_ERROR_CONNECTION_TIMEOUT) {
1972 _bt_audio_start_auto_connect(TRUE);
1973 } else if (bt_device_state &
1974 VCONFKEY_BT_DEVICE_A2DP_SOURCE_CONNECTED) {
1975 BT_INFO("Disconnected due to turning BT off. Skip a address");
1977 char *last_connected = NULL;
1978 last_connected = vconf_get_str(BT_LAST_CONNECTED_DEVICE);
1979 if (!g_strcmp0(address, last_connected))
1980 _bt_audio_set_auto_connect_device_addr("");
1982 free(last_connected);
1987 /*Check for any OPP transfer on the device and cancel
1990 _bt_obex_check_pending_transfer(address);
1991 _bt_opp_client_is_sending(&sending);
1992 if (sending == TRUE)
1993 _bt_opp_client_check_pending_transfer(address);
1994 /* TODO: MAP? see above */
1996 param = g_variant_new("(isy)", result, address, addr_type);
1997 _bt_send_event(BT_DEVICE_EVENT,
1998 BLUETOOTH_EVENT_DEVICE_DISCONNECTED,
2001 } else if (strcasecmp(member, "ProfileStateChanged") == 0) {
2003 char *profile_uuid = NULL;
2004 bt_headset_wait_t *wait_list;
2005 bluetooth_device_address_t bd_addr;
2007 g_variant_get(msg, "(si)", &profile_uuid, &state);
2009 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
2011 _bt_convert_device_path_to_address(path, address);
2012 _bt_convert_addr_string_to_type(bd_addr.addr, address);
2014 _bt_convert_addr_string_to_secure_string(secure_address, address);
2015 BT_DBG("Address: %s", secure_address);
2016 BT_DBG("Profile UUID: %s", profile_uuid);
2017 BT_DBG("State: %d", state);
2019 if ((strcmp(profile_uuid, A2DP_SINK_UUID) == 0) &&
2020 (state == BT_PROFILE_STATE_CONNECTED)) {
2022 int event = BLUETOOTH_EVENT_AV_CONNECTED;
2023 char connected_address[BT_ADDRESS_STRING_SIZE + 1];
2024 bluetooth_device_address_t device_address;
2026 bt_headset_wait_t *wait_list;
2027 guint restricted = 0x0;
2029 __bt_set_device_values(TRUE,
2030 VCONFKEY_BT_DEVICE_A2DP_HEADSET_CONNECTED);
2032 __bt_connection_manager_set_state(address, event);
2034 _bt_get_restrict_profile(&bd_addr, RESTRICTED_PROFILE_HFP_HS, &restricted);
2036 if (_bt_headset_get_local_connection() == FALSE) {
2037 if (restricted == 0x0) /* not restricted*/
2038 _bt_start_timer_for_connection(address, BT_AUDIO_HSP);
2040 /* Connection Started from local device therefore no need to
2041 * intiate connection for pending profile */
2042 _bt_headset_set_local_connection(FALSE);
2044 param = g_variant_new("(is)", result, address);
2045 _bt_send_event(BT_HEADSET_EVENT, event,
2047 connected = _bt_is_headset_type_connected(BT_AUDIO_A2DP,
2050 if (g_strcmp0(connected_address, address) != 0) {
2051 _bt_convert_addr_string_to_type(
2052 device_address.addr,
2054 _bt_audio_disconnect(0, BT_AUDIO_A2DP,
2055 &device_address, NULL);
2059 _bt_add_headset_to_list(BT_AUDIO_A2DP,
2060 BT_STATE_CONNECTED, address);
2062 wait_list = _bt_get_audio_wait_data();
2063 if (wait_list != NULL &&
2064 (g_strcmp0(wait_list->address, address) == 0))
2065 _bt_rel_wait_data();
2067 } else if ((strcmp(profile_uuid, A2DP_SINK_UUID) == 0) &&
2068 (state == BT_PROFILE_STATE_DISCONNECTED)) {
2070 int event = BLUETOOTH_EVENT_AV_DISCONNECTED;
2072 if (!_bt_is_service_connected(address, BT_AUDIO_A2DP)) {
2074 g_free(profile_uuid);
2078 __bt_set_device_values(FALSE,
2079 VCONFKEY_BT_DEVICE_A2DP_HEADSET_CONNECTED);
2081 __bt_connection_manager_set_state(address, event);
2082 param = g_variant_new("(is)", result, address);
2083 _bt_send_event(BT_HEADSET_EVENT, event,
2085 /* Remove data from the connected list */
2086 _bt_remove_headset_from_list(BT_AUDIO_A2DP, address);
2087 wait_list = _bt_get_audio_wait_data();
2089 if (wait_list == NULL) {
2091 g_free(profile_uuid);
2095 if (((wait_list->type == BT_AUDIO_ALL) &&
2096 (wait_list->ag_flag == TRUE)) ||
2097 (wait_list->type == BT_AUDIO_A2DP) ||
2098 (wait_list->disconnection_type == BT_AUDIO_A2DP)) {
2099 bluetooth_device_address_t device_address;
2100 _bt_convert_addr_string_to_type(
2101 device_address.addr,
2102 wait_list->address);
2104 _bt_audio_connect(wait_list->req_id,
2109 } else if (strcmp(profile_uuid, AVRCP_TARGET_UUID) == 0) {
2111 if (state == BT_PROFILE_STATE_CONNECTED) {
2112 int event = BLUETOOTH_EVENT_AVRCP_CONTROL_CONNECTED;
2113 char connected_address[BT_ADDRESS_STRING_SIZE + 1];
2114 bluetooth_device_address_t device_address;
2116 param = g_variant_new("(is)", result, address);
2117 _bt_send_event(BT_AVRCP_CONTROL_EVENT, event,
2119 connected = _bt_is_headset_type_connected(
2123 if (g_strcmp0(connected_address,
2125 _bt_convert_addr_string_to_type(
2126 device_address.addr,
2128 _bt_audio_disconnect(0,
2130 &device_address, NULL);
2133 BT_DBG("device Path: %s", path);
2134 _bt_add_headset_to_list(BT_AVRCP,
2135 BT_STATE_CONNECTED, address);
2136 } else if (state == BT_PROFILE_STATE_DISCONNECTED) {
2137 int event = BLUETOOTH_EVENT_AVRCP_CONTROL_DISCONNECTED;
2138 param = g_variant_new("(is)", result, address);
2139 _bt_send_event(BT_AVRCP_CONTROL_EVENT, event,
2141 /* Remove data from the connected list */
2142 _bt_remove_headset_from_list(BT_AVRCP, address);
2144 } else if (strcasecmp(profile_uuid, A2DP_SOURCE_UUID) == 0) {
2145 if (state == BT_PROFILE_STATE_CONNECTED) {
2146 int event = BLUETOOTH_EVENT_AV_SOURCE_CONNECTED;
2147 BT_INFO("A2DP Source is connected");
2148 #ifdef TIZEN_BT_A2DP_SINK_ENABLE
2149 __bt_set_device_values(TRUE,
2150 VCONFKEY_BT_DEVICE_A2DP_SOURCE_CONNECTED);
2153 #ifdef TIZEN_BT_A2DP_SINK_AUTO_CONNECT
2154 _bt_audio_set_auto_connect_device_addr(address);
2155 _bt_audio_stop_auto_connect();
2157 _bt_add_headset_to_list(BT_AUDIO_A2DP_SOURCE,
2158 BT_STATE_CONNECTED, address);
2159 _bt_send_event(BT_A2DP_SOURCE_EVENT, event,
2160 g_variant_new("(is)", result, address));
2161 } else if (state == BT_PROFILE_STATE_DISCONNECTED) {
2162 int event = BLUETOOTH_EVENT_AV_SOURCE_DISCONNECTED;
2163 BT_INFO("A2DP Source Disconnected");
2164 #ifdef TIZEN_BT_A2DP_SINK_ENABLE
2165 __bt_set_device_values(FALSE,
2166 VCONFKEY_BT_DEVICE_A2DP_SOURCE_CONNECTED);
2168 _bt_remove_headset_from_list(BT_AUDIO_A2DP_SOURCE, address);
2169 _bt_send_event(BT_A2DP_SOURCE_EVENT, event,
2170 g_variant_new("(is)", result, address));
2172 wait_list = _bt_get_audio_wait_data();
2173 if (wait_list && wait_list->type == BT_AUDIO_A2DP_SOURCE) {
2174 bluetooth_device_address_t device_address;
2175 _bt_convert_addr_string_to_type(
2176 device_address.addr,
2177 wait_list->address);
2179 _bt_audio_connect(wait_list->req_id,
2183 /* Now free the wait list */
2184 _bt_rel_wait_data();
2187 } else if ((strcmp(profile_uuid, HID_UUID) == 0) &&
2188 ((state == BT_PROFILE_STATE_CONNECTED) ||
2189 (state == BT_PROFILE_STATE_DISCONNECTED))) {
2191 if (state == BT_PROFILE_STATE_CONNECTED)
2192 event = BLUETOOTH_HID_CONNECTED;
2194 event = BLUETOOTH_HID_DISCONNECTED;
2195 param = g_variant_new("(is)", result, address);
2196 _bt_send_event(BT_HID_EVENT, event,
2198 } else if (strcmp(profile_uuid, HID_DEVICE_UUID) == 0) {
2199 if (state == BT_PROFILE_STATE_CONNECTED) {
2201 event = BLUETOOTH_HID_DEVICE_CONNECTED;
2202 param = g_variant_new("(is)", result, address);
2203 _bt_send_event(BT_HID_DEVICE_EVENT, event,
2205 } else if (state == BT_PROFILE_STATE_DISCONNECTED) {
2206 event = BLUETOOTH_HID_DEVICE_DISCONNECTED;
2207 param = g_variant_new("(is)", result, address);
2208 _bt_send_event(BT_HID_DEVICE_EVENT, event,
2213 g_free(profile_uuid);
2214 } else if (strcasecmp(member, "AdvReport") == 0) {
2216 bt_remote_le_dev_info_t *le_dev_info = NULL;
2217 char *buffer = NULL;
2219 bt_le_adv_info_t *adv_info = NULL;
2220 GVariant *value = NULL;
2221 ret_if(_bt_is_le_scanning() == FALSE);
2223 le_dev_info = g_malloc0(sizeof(bt_remote_le_dev_info_t));
2225 g_variant_get(msg, "(syyii@ay)", &le_dev_info->address,
2226 &le_dev_info->addr_type,
2227 &le_dev_info->adv_type,
2229 &le_dev_info->adv_data_len,
2232 ret_if(value == NULL);
2234 _bt_convert_device_path_to_address(path, le_dev_info->address);
2236 buffer_len = g_variant_get_size(value);
2238 buffer = (char *)g_variant_get_data(value);
2240 le_dev_info->adv_data = g_memdup(buffer, buffer_len);
2241 if (le_dev_info->adv_data == NULL &&
2242 le_dev_info->adv_type != BT_LE_ADV_SCAN_RSP) {
2243 _bt_free_le_device_info(le_dev_info);
2244 g_variant_unref(value);
2248 if (_bt_get_le_scan_type() == BT_LE_PASSIVE_SCAN) {
2249 _bt_send_scan_result_event(le_dev_info, NULL);
2250 _bt_free_le_device_info(le_dev_info);
2251 g_variant_unref(value);
2255 if (le_dev_info->adv_type != BT_LE_ADV_SCAN_RSP) { /* ADV_IND */
2256 adv_info = g_malloc0(sizeof(bt_le_adv_info_t));
2257 adv_info->addr = g_strdup(le_dev_info->address);
2258 adv_info->addr_type = le_dev_info->addr_type;
2259 adv_info->rssi = le_dev_info->rssi;
2260 adv_info->data_len = le_dev_info->adv_data_len;
2261 adv_info->data = g_malloc0(le_dev_info->adv_data_len);
2262 memcpy(adv_info->data, le_dev_info->adv_data,
2263 le_dev_info->adv_data_len);
2265 if (__bt_add_adv_ind_info(adv_info) == 0) {
2266 adv_info->timer_id = g_timeout_add(1000,
2267 (GSourceFunc)__bt_adv_scan_req_timeout_cb, (void*)adv_info);
2269 } else { /* SCAN_RSP */
2270 adv_info = __bt_get_adv_ind_info(le_dev_info->address);
2272 _bt_send_scan_result_event(le_dev_info, adv_info);
2273 __bt_del_adv_ind_info(le_dev_info->address);
2276 _bt_free_le_device_info(le_dev_info);
2277 g_variant_unref(value);
2278 } else if (strcasecmp(member, "LEDataLengthChanged") == 0) {
2279 guint16 tx_octets = 0;
2280 guint16 tx_time = 0;
2281 guint16 rx_octets = 0;
2282 guint16 rx_time = 0;
2284 g_variant_get(msg, "(qqqq)",
2285 &tx_octets, &tx_time, &rx_octets, &rx_time);
2287 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
2288 _bt_convert_device_path_to_address(path, address);
2290 param = g_variant_new("(isqqqq)", result, address, tx_octets, tx_time,
2291 rx_octets, rx_time);
2292 /* Send event to application */
2293 _bt_send_event(BT_DEVICE_EVENT,
2294 BLUETOOTH_EVENT_LE_DATA_LENGTH_CHANGED, param);
2296 } else if (strcasecmp(member, "IpspStateChanged") == 0) {
2297 gboolean connected = FALSE;
2298 char *ifname = NULL;
2300 g_variant_get(msg, "(bs)", &connected, &ifname);
2302 event = connected ? BLUETOOTH_EVENT_IPSP_CONNECTED :
2303 BLUETOOTH_EVENT_IPSP_DISCONNECTED;
2305 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
2306 _bt_convert_device_path_to_address(path, address);
2308 BT_DBG("Ipsp BT Interface Name: %s", ifname);
2309 BT_DBG("address: %s", address);
2310 param = g_variant_new("(iss)", result, address, ifname);
2312 /* Send event to application */
2313 _bt_send_event(BT_DEVICE_EVENT,
2320 void __bt_set_audio_values(gboolean connected, char *address)
2323 int bt_device_state = VCONFKEY_BT_DEVICE_NONE;
2325 /* Set the headset name */
2326 if (connected == TRUE)
2327 name = _bt_get_bonded_device_name(address);
2329 name = g_strdup("");
2331 if (vconf_set_str(VCONFKEY_BT_HEADSET_NAME, name) != 0)
2332 BT_ERR("vconf_set_str failed");
2336 /* Set the headset state */
2337 if (vconf_get_int(VCONFKEY_BT_DEVICE, &bt_device_state) != 0)
2338 BT_ERR("vconf_get_int failed");
2340 #ifdef TIZEN_SUPPORT_DUAL_HF
2341 if ((connected == TRUE) &&
2342 (FALSE == __bt_is_companion_device(address))) {
2343 bt_device_state |= VCONFKEY_BT_DEVICE_HEADSET_CONNECTED;
2344 } else if ((bt_device_state & VCONFKEY_BT_DEVICE_HEADSET_CONNECTED) &&
2345 (FALSE == __bt_is_companion_device(address))) {
2346 bt_device_state ^= VCONFKEY_BT_DEVICE_HEADSET_CONNECTED;
2349 if (connected == TRUE)
2350 bt_device_state |= VCONFKEY_BT_DEVICE_HEADSET_CONNECTED;
2351 else if (bt_device_state & VCONFKEY_BT_DEVICE_HEADSET_CONNECTED)
2352 bt_device_state ^= VCONFKEY_BT_DEVICE_HEADSET_CONNECTED;
2355 if (vconf_set_int(VCONFKEY_BT_DEVICE,
2356 bt_device_state) != 0) {
2357 BT_ERR("vconf_set_int failed");
2361 void _bt_handle_headset_event(GVariant *msg, const char *path)
2363 int result = BLUETOOTH_ERROR_NONE;
2364 gboolean property_flag = FALSE;
2365 char *property = NULL;
2366 GVariant *value = NULL;
2367 GVariant *param = NULL;
2368 g_variant_get(msg, "(sv)", &property, &value);
2369 bluetooth_device_address_t bd_addr;
2371 ret_if(property == NULL);
2373 BT_DBG("Property = %s \n", property);
2374 /* We allow only 1 headset connection (HSP or HFP)*/
2375 if (strcasecmp(property, "Connected") == 0) {
2376 int event = BLUETOOTH_EVENT_NONE;
2377 bt_headset_wait_t *wait_list;
2379 guint restricted = 0x0;
2380 g_variant_get(value, "b", &property_flag);
2382 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
2384 _bt_convert_device_path_to_address(path, address);
2385 _bt_convert_addr_string_to_type(bd_addr.addr, address);
2387 if (property_flag == TRUE) {
2388 event = BLUETOOTH_EVENT_AG_CONNECTED;
2389 _bt_get_restrict_profile(&bd_addr, RESTRICTED_PROFILE_A2DP, &restricted);
2391 if (_bt_headset_get_local_connection() == FALSE) {
2392 if (restricted == 0x0) /* not restricted*/
2393 _bt_start_timer_for_connection(address, BT_AUDIO_A2DP);
2395 _bt_headset_set_local_connection(FALSE);
2399 event = BLUETOOTH_EVENT_AG_DISCONNECTED;
2401 previous_state = _bt_get_device_state_from_list(BT_AUDIO_HSP, address);
2402 if (previous_state == BT_STATE_DISCONNECTING)
2403 _bt_send_hf_local_term_event(address);
2405 /* Set the State machine here */
2406 __bt_connection_manager_set_state(address, event);
2407 __bt_set_audio_values(property_flag, address);
2408 param = g_variant_new("(is)", result, address);
2409 _bt_send_event(BT_HEADSET_EVENT, event,
2412 if (event == BLUETOOTH_EVENT_AG_DISCONNECTED) {
2413 /* Remove data from the connected list */
2414 _bt_remove_headset_from_list(BT_AUDIO_HSP, address);
2416 wait_list = _bt_get_audio_wait_data();
2417 if (wait_list == NULL) {
2422 bluetooth_device_address_t device_address;
2424 _bt_set_audio_wait_data_flag(TRUE);
2426 _bt_convert_addr_string_to_type(device_address.addr,
2427 wait_list->address);
2428 _bt_audio_connect(wait_list->req_id, wait_list->type,
2429 &device_address, NULL);
2430 _bt_rel_wait_data();
2431 } else if (event == BLUETOOTH_EVENT_AG_CONNECTED) {
2432 /* Add data to the connected list */
2433 _bt_add_headset_to_list(BT_AUDIO_HSP,
2434 BT_STATE_CONNECTED, address);
2436 wait_list = _bt_get_audio_wait_data();
2437 if (wait_list != NULL &&
2438 (g_strcmp0(wait_list->address, address) == 0))
2439 _bt_rel_wait_data();
2441 BT_INFO("Check A2DP pending connect");
2442 _bt_audio_check_pending_connect();
2445 } else if (strcasecmp(property, "State") == 0) {
2448 g_variant_get(value, "s", &state);
2450 /* This code assumes we support only 1 headset connection */
2451 /* Need to use the headset list, if we support multi-headsets */
2452 if (strcasecmp(state, "Playing") == 0) {
2453 BT_DBG("Playing: Sco Connected");
2454 } else if (strcasecmp(state, "connected") == 0 ||
2455 strcasecmp(state, "disconnected") == 0) {
2456 BT_DBG("connected/disconnected: Sco Disconnected");
2458 BT_ERR("Not handled state - %s", state);
2463 } else if (strcasecmp(property, "SpeakerGain") == 0) {
2467 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
2469 _bt_convert_device_path_to_address(path, address);
2471 spkr_gain = g_variant_get_uint16(value);
2473 BT_DBG("spkr_gain: %d", spkr_gain);
2475 param = g_variant_new("(i&sq)", result, address, spkr_gain);
2476 _bt_send_event(BT_HEADSET_EVENT, BLUETOOTH_EVENT_AG_SPEAKER_GAIN,
2480 } else if (strcasecmp(property, "MicrophoneGain") == 0) {
2484 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
2486 _bt_convert_device_path_to_address(path, address);
2488 mic_gain = g_variant_get_uint16(value);
2490 param = g_variant_new("(i&sq)", result, address, mic_gain);
2491 _bt_send_event(BT_HEADSET_EVENT, BLUETOOTH_EVENT_AG_MIC_GAIN,
2498 g_variant_unref(value);
2501 void _bt_handle_sink_event(GVariant *msg, const char *path)
2503 GVariantIter value_iter;
2504 char *property = NULL;
2506 bt_headset_wait_t *wait_list;
2508 GVariant *child = NULL;
2509 GVariant *val = NULL;
2510 GVariant *param = NULL;
2511 g_variant_iter_init(&value_iter, msg);
2512 while ((child = g_variant_iter_next_value(&value_iter))) {
2514 g_variant_get(child, "{sv}", &property, &val);
2516 ret_if(property == NULL);
2518 BT_DBG("Property = %s \n", property);
2521 if (strcasecmp(property, "State") == 0) {
2522 int result = BLUETOOTH_ERROR_NONE;
2525 g_variant_get(val, "s", &value);
2526 BT_DBG("value: %s", value);
2528 if (g_strcmp0(value, "disconnected") == 0) {
2531 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
2533 _bt_convert_device_path_to_address(path, address);
2535 __bt_set_device_values(FALSE,
2536 VCONFKEY_BT_DEVICE_A2DP_HEADSET_CONNECTED);
2537 param = g_variant_new("(is)", result, address);
2538 _bt_send_event(BT_HEADSET_EVENT,
2539 BLUETOOTH_EVENT_AV_DISCONNECTED,
2542 /* Remove data from the connected list */
2543 _bt_remove_headset_from_list(BT_AUDIO_A2DP, address);
2544 wait_list = _bt_get_audio_wait_data();
2545 if (wait_list == NULL) {
2548 g_variant_unref(val);
2549 g_variant_unref(child);
2554 if (((wait_list->type == BT_AUDIO_ALL) &&
2555 (wait_list->ag_flag == TRUE)) ||
2556 (wait_list->type == BT_AUDIO_A2DP) ||
2557 (wait_list->disconnection_type == BT_AUDIO_A2DP)) {
2558 bluetooth_device_address_t device_address;
2559 _bt_convert_addr_string_to_type(
2560 device_address.addr,
2561 wait_list->address);
2563 _bt_audio_connect(wait_list->req_id,
2569 } else if (strcasecmp(value, "Connected") == 0) {
2571 char connected_address[BT_ADDRESS_STRING_SIZE + 1];
2572 bluetooth_device_address_t device_address;
2575 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
2577 _bt_convert_device_path_to_address(path, address);
2579 __bt_set_device_values(TRUE,
2580 VCONFKEY_BT_DEVICE_A2DP_HEADSET_CONNECTED);
2581 param = g_variant_new("(is)", result, address);
2582 _bt_send_event(BT_HEADSET_EVENT,
2583 BLUETOOTH_EVENT_AV_CONNECTED,
2585 /* Check for existing Media device to disconnect */
2586 connected = _bt_is_headset_type_connected(BT_AUDIO_A2DP,
2589 /* Match connected device address */
2590 if (g_strcmp0(connected_address, address) != 0) {
2591 /* Convert BD adress from string type */
2592 _bt_convert_addr_string_to_type(
2593 device_address.addr,
2595 _bt_audio_disconnect(0, BT_AUDIO_A2DP,
2596 &device_address, NULL);
2600 /* Add data to the connected list */
2601 _bt_add_headset_to_list(BT_AUDIO_A2DP,
2602 BT_STATE_CONNECTED, address);
2609 g_variant_unref(val);
2610 g_variant_unref(child);
2614 void _bt_handle_agent_event(GVariant *msg, const char *member)
2616 int result = BLUETOOTH_ERROR_NONE;
2617 char *address = NULL;
2620 GVariant *param = NULL;
2621 ret_if(member == NULL);
2623 if (strcasecmp(member, "ObexAuthorize") == 0) {
2624 __bt_get_agent_signal_info(msg, &address, &name, &uuid);
2625 param = g_variant_new("(iss)", result, address, name);
2626 _bt_send_event(BT_OPP_SERVER_EVENT,
2627 BLUETOOTH_EVENT_OBEX_SERVER_CONNECTION_AUTHORIZE,
2629 /* TODO: MAP? see above */
2632 } else if (strcasecmp(member, "RfcommAuthorize") == 0) {
2633 bt_rfcomm_server_info_t *server_info;
2635 __bt_get_agent_signal_info(msg, &address, &name, &uuid);
2637 server_info = _bt_rfcomm_get_server_info_using_uuid(uuid);
2638 ret_if(server_info == NULL);
2639 ret_if(server_info->server_type != BT_CUSTOM_SERVER);
2640 param = g_variant_new("(isssn)", result, address, uuid, name,
2641 server_info->control_fd);
2642 _bt_send_event(BT_RFCOMM_SERVER_EVENT,
2643 BLUETOOTH_EVENT_RFCOMM_AUTHORIZE,
2651 static int __bt_get_object_path(GVariant *msg, char **path)
2653 g_variant_get(msg, "(o*)", path, NULL);
2655 return BLUETOOTH_ERROR_INTERNAL;
2657 return BLUETOOTH_ERROR_NONE;
2660 static void __bt_devices_list_free(void)
2662 bt_cache_info_t *cache_info;
2665 node = g_list_first(p_cache_list);
2667 while (node != NULL) {
2668 cache_info = (bt_cache_info_t *)node->data;
2669 p_cache_list = g_list_remove(p_cache_list, cache_info);
2670 __bt_free_cache_info(cache_info);
2672 node = g_list_next(node);
2676 static int __bt_parse_event(GVariant *msg)
2680 char *interface_name = NULL;
2681 GVariant *inner_iter = NULL;
2683 g_variant_iter_init(&iter, msg);
2685 while ((child = g_variant_iter_next_value(&iter))) {
2686 g_variant_get(child, "{&s@a{sv}}", &interface_name, &inner_iter);
2687 if (g_strcmp0(interface_name,
2688 BT_DEVICE_INTERFACE) == 0) {
2689 g_variant_unref(inner_iter);
2690 g_variant_unref(child);
2691 return BT_DEVICE_EVENT;
2692 } else if (g_strcmp0(interface_name,
2693 BT_MEDIATRANSPORT_INTERFACE) == 0) {
2694 g_variant_unref(inner_iter);
2695 g_variant_unref(child);
2696 return BT_MEDIA_TRANSFER_EVENT;
2697 } else if (g_strcmp0(interface_name,
2698 BT_PLAYER_CONTROL_INTERFACE) == 0) {
2699 g_variant_unref(inner_iter);
2700 g_variant_unref(child);
2701 return BT_AVRCP_CONTROL_EVENT;
2703 g_variant_unref(inner_iter);
2704 g_variant_unref(child);
2710 static void __bt_manager_event_filter(GDBusConnection *connection,
2711 const gchar *sender_name,
2712 const gchar *object_path,
2713 const gchar *interface_name,
2714 const gchar *signal_name,
2715 GVariant *parameters,
2718 bt_event_type_t bt_event = 0x00;
2719 int result = BLUETOOTH_ERROR_NONE;
2721 char *obj_path = NULL;
2722 GVariant *param = NULL;
2723 if (signal_name == NULL)
2725 if (strcasecmp(signal_name, "InterfacesAdded") == 0) {
2726 g_variant_get(parameters, "(&o@a{sa{sv}})", &obj_path, &value);
2728 if (strcasecmp(obj_path, BT_BLUEZ_HCI_PATH) == 0) {
2729 #ifdef TIZEN_FEATURE_BT_USB_DONGLE
2730 BT_DBG("Enable Adapter");
2731 _bt_enable_adapter();
2733 _bt_handle_adapter_added();
2736 bt_event = __bt_parse_event(value);
2737 if (bt_event == BT_DEVICE_EVENT) {
2738 bt_cache_info_t *cache_info;
2739 bt_remote_dev_info_t *dev_info;
2740 #ifdef TIZEN_FEATURE_BT_DPM
2741 int desktop_state = DPM_BT_ERROR;
2743 ret_if(_bt_is_discovering() == FALSE &&
2744 _bt_is_le_scanning() == FALSE);
2746 cache_info = g_malloc0(sizeof(bt_cache_info_t));
2748 dev_info = g_malloc0(sizeof(bt_remote_dev_info_t));
2750 cache_info->dev_info = dev_info;
2752 if (__bt_parse_interface(parameters, dev_info) == FALSE) {
2753 BT_ERR("Fail to parse the properies");
2754 __bt_free_cache_info(cache_info);
2755 g_variant_unref(value);
2759 if (dev_info->addr_type != BDADDR_BREDR) {
2760 /* Whenever emit the property changed from bluez,
2761 some property doesn't reach to bt-service.
2762 So LE device is handled as AdvReport signal */
2763 __bt_free_cache_info(cache_info);
2764 g_variant_unref(value);
2768 if (dev_info->name == NULL)
2769 /* If Remote device name is NULL or still RNR is not done
2770 * then display address as name.
2772 dev_info->name = g_strdup(dev_info->address);
2774 #ifdef TIZEN_FEATURE_BT_DPM
2775 _bt_dpm_get_bluetooth_desktop_connectivity_state(&desktop_state);
2776 if (desktop_state == DPM_RESTRICTED) {
2777 bluetooth_device_class_t device_class;
2778 _bt_divide_device_class(&device_class, dev_info->class);
2779 BT_DBG("[%s]device_class.major_class : %d", dev_info->name, device_class.major_class);
2781 if (device_class.major_class ==
2782 BLUETOOTH_DEVICE_MAJOR_CLASS_COMPUTER) {
2783 __bt_free_cache_info(cache_info);
2784 g_variant_unref(value);
2790 GVariant *uuids = NULL;
2791 GVariantBuilder *builder = NULL;
2793 builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
2794 for (i = 0; i < dev_info->uuid_count; i++) {
2795 g_variant_builder_add(builder, "s",
2796 dev_info->uuids[i]);
2798 uuids = g_variant_new("as", builder);
2799 g_variant_builder_unref(builder);
2800 GVariant *manufacturer_data = NULL;
2801 manufacturer_data = g_variant_new_from_data(
2802 G_VARIANT_TYPE_BYTESTRING,
2803 dev_info->manufacturer_data,
2804 dev_info->manufacturer_data_len,
2806 param = g_variant_new("(isunsbub@asn@ay)", result,
2812 dev_info->connected,
2815 dev_info->manufacturer_data_len,
2817 _bt_send_event(BT_ADAPTER_EVENT,
2818 BLUETOOTH_EVENT_REMOTE_DEVICE_FOUND,
2820 p_cache_list = g_list_append(p_cache_list, cache_info);
2821 } else if (bt_event == BT_AVRCP_CONTROL_EVENT) {
2822 BT_DBG("Device path : %s ", obj_path);
2823 _bt_set_control_device_path(obj_path);
2826 g_variant_unref(value);
2827 } else if (strcasecmp(signal_name, "InterfacesRemoved") == 0) {
2828 #ifdef TIZEN_FEATURE_BT_USB_DONGLE
2829 BT_DBG("InterfacesRemoved");
2830 _bt_handle_adapter_removed();
2832 if (g_strcmp0(interface_name, BT_MEDIATRANSPORT_INTERFACE) == 0)
2833 bt_event = BT_MEDIA_TRANSFER_EVENT;
2834 else if (g_strcmp0(interface_name, BT_DEVICE_INTERFACE) == 0)
2835 bt_event = BT_DEVICE_EVENT;
2836 else if (g_strcmp0(interface_name, BT_PLAYER_CONTROL_INTERFACE) == 0)
2837 bt_event = BT_AVRCP_CONTROL_EVENT;
2839 if ((bt_event != 0) && (bt_event != BT_MEDIA_TRANSFER_EVENT)) {
2840 _bt_handle_adapter_event(parameters, signal_name);
2841 if (bt_event == BT_AVRCP_CONTROL_EVENT) {
2842 BT_INFO("Object Path %s", obj_path);
2843 _bt_remove_control_device_path(obj_path);
2846 } else if (strcasecmp(signal_name, "NameOwnerChanged") == 0) {
2849 char *previous = NULL;
2850 char *current = NULL;
2852 if (__bt_get_owner_info(parameters, &name, &previous, ¤t)) {
2853 BT_ERR("Fail to get the owner info");
2857 if (*current != '\0') {
2866 if (strcasecmp(name, BT_BLUEZ_NAME) == 0) {
2867 BT_INFO_C("### Bluetoothd is terminated");
2868 if (_bt_adapter_get_status() != BT_DEACTIVATING &&
2869 _bt_adapter_get_status() != BT_DEACTIVATED) {
2870 BT_INFO_C("### Recover it");
2871 _bt_recover_adapter();
2873 _bt_handle_adapter_removed();
2874 __bt_devices_list_free();
2877 _bt_obex_server_check_allocation(&value);
2879 if (value == TRUE) {
2880 /* Check if the obex server was terminated abnormally */
2881 _bt_obex_server_check_termination(name);
2884 _bt_rfcomm_server_check_existence(&value);
2886 if (value == TRUE) {
2887 /* The obex server was terminated abnormally */
2888 _bt_rfcomm_server_check_termination(name);
2891 /* Stop advertising started by terminated process */
2892 _bt_stop_advertising_by_terminated_process(name);
2894 _bt_stop_le_scan(name);
2896 /* Stop the Proximity reporter service */
2897 _bt_proximity_reporter_stop_by_terminated_process(name);
2902 } else if (g_strcmp0(interface_name, BT_PROPERTIES_INTERFACE) == 0) {
2903 const char *path = object_path;
2905 if (strncmp(path, BT_MEDIA_OBJECT_PATH,
2906 strlen(BT_MEDIA_OBJECT_PATH)) == 0)
2909 _bt_handle_property_changed_event(parameters, object_path);
2910 } else if (g_strcmp0(interface_name, BT_ADAPTER_INTERFACE) == 0) {
2911 _bt_handle_adapter_event(parameters, signal_name);
2912 } else if (g_strcmp0(interface_name, BT_INPUT_INTERFACE) == 0) {
2913 _bt_handle_input_event(parameters, object_path);
2914 } else if (g_strcmp0(interface_name, BT_NETWORK_SERVER_INTERFACE) == 0) {
2915 _bt_handle_network_server_event(parameters, signal_name);
2916 } else if (g_strcmp0(interface_name, BT_HEADSET_INTERFACE) == 0) {
2917 _bt_handle_headset_event(parameters, object_path);
2918 } else if (g_strcmp0(interface_name, BT_SINK_INTERFACE) == 0) {
2919 _bt_handle_sink_event(parameters, object_path);
2920 } else if (g_strcmp0(interface_name, BT_AGENT_INTERFACE) == 0) {
2921 _bt_handle_agent_event(parameters, signal_name);
2922 } else if (g_strcmp0(interface_name, BT_DEVICE_INTERFACE) == 0) {
2923 _bt_handle_device_event(parameters, signal_name, object_path);
2924 } else if (g_strcmp0(interface_name, BT_GATT_CHAR_INTERFACE) == 0) {
2925 _bt_handle_gatt_event(parameters, signal_name, object_path);
2931 static gboolean __bt_is_obexd_event(GVariant *msg, const char *interface)
2934 if (g_strcmp0(interface, BT_PROPERTIES_INTERFACE) == 0) {
2935 char *interface_name = NULL;
2937 g_variant_get(msg, "(&s@a{sv}@as)", &interface_name, NULL, NULL);
2938 retv_if(interface_name == NULL, FALSE);
2940 if (strcasecmp(interface_name, BT_OBEX_TRANSFER_INTERFACE) == 0) {
2941 BT_DBG("BT_OBEX_TRANSFER_INTERFACE");
2949 static void __bt_obexd_event_filter(GDBusConnection *connection,
2950 const gchar *sender_name,
2951 const gchar *object_path,
2952 const gchar *interface_name,
2953 const gchar *signal_name,
2954 GVariant *parameters,
2957 const char *member = signal_name;
2958 char *obj_path = NULL;
2959 ret_if(member == NULL);
2961 if (strcasecmp(member, "InterfacesAdded") == 0) {
2962 if (__bt_get_object_path(parameters, &obj_path)) {
2963 BT_ERR("Fail to get the path");
2966 BT_INFO("object_path = [%s]", obj_path);
2968 /*Handle OPP_SERVER_CONNECTED_EVENT here */
2969 /* TODO: MAP? see above */
2970 if (strncmp(obj_path, BT_SESSION_BASEPATH_SERVER,
2971 strlen(BT_SESSION_BASEPATH_SERVER)) != 0) {
2976 if (g_strrstr(obj_path, "session") && g_strrstr(obj_path, "transfer")) {
2977 BT_DBG("Obex_Server_Session_Transfer connected");
2978 _bt_obex_transfer_connected(obj_path);
2981 } else if (strcasecmp(member, "InterfacesRemoved") == 0) {
2982 /*Handle OPP_SERVER_DISCONNECTED_EVENT here */
2983 /* TODO: MAP? see above */
2984 if (__bt_get_object_path(parameters, &obj_path)) {
2985 BT_ERR("Fail to get the path");
2988 BT_INFO("object_path = [%s]", obj_path);
2990 if (strncmp(obj_path, BT_SESSION_BASEPATH_CLIENT,
2991 strlen(BT_SESSION_BASEPATH_CLIENT)) == 0) {
2992 BT_DBG("Call PBAP Disconnected");
2993 _bt_obex_pbap_client_disconnect(obj_path);
2996 if (strncmp(obj_path, BT_SESSION_BASEPATH_SERVER,
2997 strlen(BT_SESSION_BASEPATH_SERVER)) != 0) {
3002 if (g_strrstr(obj_path, "session") && g_strrstr(obj_path, "transfer")) {
3003 BT_DBG("Obex_Server_Session_Transfer disconnected %s",
3006 _bt_obex_transfer_disconnected(obj_path);
3009 } else if (__bt_is_obexd_event(parameters, interface_name) == TRUE) {
3010 const char *path = object_path;
3012 if (strncmp(path, BT_SESSION_BASEPATH_SERVER,
3013 strlen(BT_SESSION_BASEPATH_SERVER)) != 0 &&
3014 strncmp(path, BT_SESSION_BASEPATH_CLIENT,
3015 strlen(BT_SESSION_BASEPATH_CLIENT)) != 0) {
3016 BT_DBG("DBUS_HANDLER_RESULT_NOT_YET_HANDLED");
3020 _bt_handle_property_changed_event(parameters, path);
3026 static gboolean __bt_is_obexd_client_event(GVariant *msg, const char *interface)
3030 if (g_strcmp0(interface, BT_PROPERTIES_INTERFACE) == 0) {
3031 char *interface_name = NULL;
3033 g_variant_get(msg, "(&s@a{sv}@as)", &interface_name, NULL, NULL);
3035 retv_if(interface_name == NULL, FALSE);
3037 if (strcasecmp(interface_name,
3038 BT_OBEX_TRANSFER_INTERFACE) == 0) {
3049 static void __bt_opc_event_filter(GDBusConnection *connection,
3050 const gchar *sender_name,
3051 const gchar *object_path,
3052 const gchar *interface_name,
3053 const gchar *signal_name,
3054 GVariant *parameters,
3057 const char *member = signal_name;
3058 char *obj_path = NULL;
3059 if (strcasecmp(member, "InterfacesAdded") == 0) {
3060 BT_DBG("InterfacesAdded");
3061 } else if (strcasecmp(member, "InterfacesRemoved") == 0) {
3063 if (__bt_get_object_path(parameters, &obj_path)) {
3064 BT_ERR("Fail to get the path");
3068 BT_DBG("object_path = %s", obj_path);
3070 if (strncmp(obj_path, BT_SESSION_BASEPATH_CLIENT,
3071 strlen(BT_SESSION_BASEPATH_CLIENT)) != 0
3072 || strstr(obj_path, "transfer") == NULL) {
3075 } else if (strncmp(obj_path, BT_SESSION_BASEPATH_CLIENT,
3076 strlen(BT_SESSION_BASEPATH_CLIENT)) == 0) {
3077 BT_DBG("Going to call opc disconnected");
3078 _bt_opc_disconnected(obj_path);
3081 _bt_sending_files();
3083 } else if (__bt_is_obexd_client_event(parameters, interface_name) == TRUE) {
3084 char *path = (char *)object_path;
3085 BT_INFO("object_path %s", path);
3086 if (strncmp(path, BT_SESSION_BASEPATH_CLIENT,
3087 strlen(BT_SESSION_BASEPATH_CLIENT)) != 0) {
3088 BT_DBG("NOT BT_SESSION_BASEPATH_CLIENT");
3092 _bt_opc_property_changed_event(parameters, path);
3098 int _bt_opp_client_event_init(void)
3100 GError *error = NULL;
3102 if (opc_obexd_conn == NULL) {
3103 opc_obexd_conn = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &error);
3105 if (!opc_obexd_conn) {
3107 BT_ERR("Unable to connect to dbus: %s", error->message);
3108 g_clear_error(&error);
3110 return BLUETOOTH_ERROR_INTERNAL;
3114 if (_bt_register_service_event(opc_obexd_conn,
3115 BT_OPP_CLIENT_EVENT) != BLUETOOTH_ERROR_NONE) {
3116 g_object_unref(opc_obexd_conn);
3117 opc_obexd_conn = NULL;
3118 return BLUETOOTH_ERROR_INTERNAL;
3121 return BLUETOOTH_ERROR_NONE;
3124 void _bt_opp_client_event_deinit(void)
3126 if (opc_obexd_conn) {
3127 _bt_unregister_service_event(opc_obexd_conn,
3128 BT_OPP_CLIENT_EVENT);
3129 g_object_unref(opc_obexd_conn);
3130 opc_obexd_conn = NULL;
3134 static void __bt_map_event_filter(GDBusConnection *connection,
3135 const gchar *sender_name,
3136 const gchar *object_path,
3137 const gchar *interface_name,
3138 const gchar *signal_name,
3139 GVariant *parameters,
3142 BT_DBG("Entered __bt_map_event_filter");
3143 const char *member = signal_name;
3145 if (strcasecmp(member, "InterfacesAdded") == 0) {
3146 BT_DBG("------------------------------------ADDED------------------------------------");
3147 // currently doing nothing
3148 } else if (strcasecmp(member, "InterfacesRemoved") == 0) {
3149 BT_DBG("------------------------------------REMOVED------------------------------------");
3150 // TODO check if something should be called here?
3151 //_bt_on_get_message_finished(object_path);
3152 } else if (__bt_is_obexd_client_event(parameters, interface_name) == TRUE) {
3153 BT_DBG("------------------------------------CLIENT EVENT------------------------------------");
3154 _bt_map_property_changed_event(parameters, object_path);
3160 int _bt_map_client_event_init(void)
3162 GError *error = NULL;
3164 if (map_obexd_conn == NULL) {
3165 map_obexd_conn = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &error);
3167 if (!map_obexd_conn) {
3169 BT_ERR("Unable to connect to dbus: %s", error->message);
3170 g_clear_error(&error);
3172 return BLUETOOTH_ERROR_INTERNAL;
3176 if (_bt_register_service_event(map_obexd_conn,
3177 BT_MAP_CLIENT_EVENT) != BLUETOOTH_ERROR_NONE) {
3178 g_object_unref(map_obexd_conn);
3179 map_obexd_conn = NULL;
3180 return BLUETOOTH_ERROR_INTERNAL;
3183 return BLUETOOTH_ERROR_NONE;
3186 void _bt_map_client_event_deinit(void)
3188 if (map_obexd_conn) {
3189 _bt_unregister_service_event(map_obexd_conn,
3190 BT_MAP_CLIENT_EVENT);
3191 g_object_unref(map_obexd_conn);
3192 map_obexd_conn = NULL;
3196 int _bt_register_manager_subscribe_signal(GDBusConnection *conn,
3202 static int subs_interface_added_id = -1;
3203 static int subs_interface_removed_id = -1;
3204 static int subs_name_owner_id = -1;
3205 static int subs_property_id = -1;
3206 static int subs_adapter_id = -1;
3207 static int subs_gatt_id = -1;
3210 if (subs_interface_added_id == -1) {
3211 subs_interface_added_id = g_dbus_connection_signal_subscribe(conn,
3212 NULL, BT_MANAGER_INTERFACE,
3213 BT_INTERFACES_ADDED, NULL, NULL, 0,
3214 __bt_manager_event_filter,
3217 if (subs_interface_removed_id == -1) {
3218 subs_interface_removed_id = g_dbus_connection_signal_subscribe(conn,
3219 NULL, BT_MANAGER_INTERFACE,
3220 BT_INTERFACES_REMOVED, NULL, NULL, 0,
3221 __bt_manager_event_filter,
3224 if (subs_name_owner_id == -1) {
3225 subs_name_owner_id = g_dbus_connection_signal_subscribe(conn,
3226 NULL, BT_FREEDESKTOP_INTERFACE,
3227 BT_NAME_OWNER_CHANGED, NULL, NULL, 0,
3228 __bt_manager_event_filter,
3231 if (subs_property_id == -1) {
3232 subs_property_id = g_dbus_connection_signal_subscribe(conn,
3233 NULL, BT_PROPERTIES_INTERFACE,
3234 BT_PROPERTIES_CHANGED, NULL, NULL, 0,
3235 __bt_manager_event_filter,
3238 if (subs_adapter_id == -1) {
3239 subs_adapter_id = g_dbus_connection_signal_subscribe(conn,
3240 NULL, BT_ADAPTER_INTERFACE,
3241 NULL, NULL, NULL, 0,
3242 __bt_manager_event_filter,
3245 if (subs_gatt_id == -1) {
3246 subs_gatt_id = g_dbus_connection_signal_subscribe(conn,
3247 NULL, BT_GATT_CHAR_INTERFACE,
3248 NULL, NULL, NULL, 0,
3249 __bt_manager_event_filter,
3253 if (subs_interface_added_id != -1) {
3254 g_dbus_connection_signal_unsubscribe(conn,
3255 subs_interface_added_id);
3256 subs_interface_added_id = -1;
3258 if (subs_interface_removed_id != -1) {
3259 g_dbus_connection_signal_unsubscribe(conn,
3260 subs_interface_removed_id);
3261 subs_interface_removed_id = -1;
3263 if (subs_name_owner_id != -1) {
3264 g_dbus_connection_signal_unsubscribe(conn,
3265 subs_name_owner_id);
3266 subs_name_owner_id = -1;
3268 if (subs_property_id != -1) {
3269 g_dbus_connection_signal_unsubscribe(conn,
3271 subs_property_id = -1;
3273 if (subs_adapter_id != -1) {
3274 g_dbus_connection_signal_unsubscribe(conn, subs_adapter_id);
3275 subs_adapter_id = -1;
3277 if (subs_gatt_id != -1) {
3278 g_dbus_connection_signal_unsubscribe(conn, subs_gatt_id);
3285 int _bt_register_device_subscribe_signal(GDBusConnection *conn,
3291 static int subs_device_id = -1;
3294 if (subs_device_id == -1) {
3295 subs_device_id = g_dbus_connection_signal_subscribe(conn,
3296 NULL, BT_DEVICE_INTERFACE,
3297 NULL, NULL, NULL, 0,
3298 __bt_manager_event_filter,
3302 if (subs_device_id != -1) {
3303 g_dbus_connection_signal_unsubscribe(conn,
3305 subs_device_id = -1;
3311 int _bt_register_input_subscribe_signal(GDBusConnection *conn,
3317 static int subs_input_id = -1;
3320 if (subs_input_id == -1) {
3321 subs_input_id = g_dbus_connection_signal_subscribe(conn,
3322 NULL, BT_INPUT_INTERFACE,
3323 NULL, NULL, NULL, 0,
3324 __bt_manager_event_filter,
3328 if (subs_input_id != -1) {
3329 g_dbus_connection_signal_unsubscribe(conn,
3337 int _bt_register_network_subscribe_signal(GDBusConnection *conn,
3343 static int subs_serv_id = -1;
3344 static int subs_client_id = -1;
3347 if (subs_serv_id == -1) {
3348 subs_serv_id = g_dbus_connection_signal_subscribe(conn,
3349 NULL, BT_NETWORK_SERVER_INTERFACE,
3350 NULL, NULL, NULL, 0,
3351 __bt_manager_event_filter,
3354 if (subs_client_id == -1) {
3355 subs_client_id = g_dbus_connection_signal_subscribe(conn,
3356 NULL, BT_NETWORK_CLIENT_INTERFACE,
3357 NULL, NULL, NULL, 0,
3358 __bt_manager_event_filter,
3362 if (subs_serv_id != -1) {
3363 g_dbus_connection_signal_unsubscribe(conn,
3367 if (subs_client_id != -1) {
3368 g_dbus_connection_signal_unsubscribe(conn,
3370 subs_client_id = -1;
3376 int _bt_register_audio_subscribe_signal(GDBusConnection *conn,
3382 static int subs_headset_id = -1;
3383 static int subs_sink_id = -1;
3386 if (subs_headset_id == -1) {
3387 subs_headset_id = g_dbus_connection_signal_subscribe(conn,
3388 NULL, BT_HEADSET_INTERFACE,
3389 NULL, NULL, NULL, 0,
3390 __bt_manager_event_filter,
3393 if (subs_sink_id == -1) {
3394 subs_sink_id = g_dbus_connection_signal_subscribe(conn,
3395 NULL, BT_SINK_INTERFACE,
3396 NULL, NULL, NULL, 0,
3397 __bt_manager_event_filter,
3401 if (subs_headset_id != -1) {
3402 g_dbus_connection_signal_unsubscribe(conn,
3404 subs_headset_id = -1;
3406 if (subs_sink_id != -1) {
3407 g_dbus_connection_signal_unsubscribe(conn,
3415 int _bt_register_opp_server_subscribe_signal(GDBusConnection *conn,
3421 static int subs_opp_server_interface_added_id = -1;
3422 static int subs_opp_server_interface_removed_id = -1;
3423 static int subs_opp_server_property_id = -1;
3427 if (subs_opp_server_interface_added_id == -1) {
3428 subs_opp_server_interface_added_id = g_dbus_connection_signal_subscribe(conn,
3429 NULL, BT_MANAGER_INTERFACE,
3430 BT_INTERFACES_ADDED, NULL, NULL, 0,
3431 __bt_obexd_event_filter,
3434 if (subs_opp_server_interface_removed_id == -1) {
3435 subs_opp_server_interface_removed_id = g_dbus_connection_signal_subscribe(conn,
3436 NULL, BT_MANAGER_INTERFACE,
3437 BT_INTERFACES_REMOVED, NULL, NULL, 0,
3438 __bt_obexd_event_filter,
3441 if (subs_opp_server_property_id == -1) {
3442 subs_opp_server_property_id = g_dbus_connection_signal_subscribe(conn,
3443 NULL, BT_PROPERTIES_INTERFACE,
3444 BT_PROPERTIES_CHANGED, NULL, NULL, 0,
3445 __bt_obexd_event_filter,
3449 if (subs_opp_server_interface_added_id != -1) {
3450 g_dbus_connection_signal_unsubscribe(conn,
3451 subs_opp_server_interface_added_id);
3452 subs_opp_server_interface_added_id = -1;
3454 if (subs_opp_server_interface_removed_id != -1) {
3455 g_dbus_connection_signal_unsubscribe(conn,
3456 subs_opp_server_interface_removed_id);
3457 subs_opp_server_interface_removed_id = -1;
3459 if (subs_opp_server_property_id != -1) {
3460 g_dbus_connection_signal_unsubscribe(conn,
3461 subs_opp_server_property_id);
3462 subs_opp_server_property_id = -1;
3468 int _bt_register_opp_client_subscribe_signal(GDBusConnection *conn,
3474 static int subs_opp_client_interface_added_id = -1;
3475 static int subs_opp_client_interface_removed_id = -1;
3476 static int subs_opp_client_property_id = -1;
3480 if (subs_opp_client_interface_added_id == -1) {
3481 subs_opp_client_interface_added_id = g_dbus_connection_signal_subscribe(conn,
3482 NULL, BT_MANAGER_INTERFACE,
3483 BT_INTERFACES_ADDED, NULL, NULL, 0,
3484 __bt_opc_event_filter,
3487 if (subs_opp_client_interface_removed_id == -1) {
3488 subs_opp_client_interface_removed_id = g_dbus_connection_signal_subscribe(conn,
3489 NULL, BT_MANAGER_INTERFACE,
3490 BT_INTERFACES_REMOVED, NULL, NULL, 0,
3491 __bt_opc_event_filter,
3494 if (subs_opp_client_property_id == -1) {
3495 subs_opp_client_property_id = g_dbus_connection_signal_subscribe(conn,
3496 NULL, BT_PROPERTIES_INTERFACE,
3497 BT_PROPERTIES_CHANGED, NULL, NULL, 0,
3498 __bt_opc_event_filter,
3502 if (subs_opp_client_interface_added_id != -1) {
3503 g_dbus_connection_signal_unsubscribe(conn,
3504 subs_opp_client_interface_added_id);
3505 subs_opp_client_interface_added_id = -1;
3507 if (subs_opp_client_interface_removed_id != -1) {
3508 g_dbus_connection_signal_unsubscribe(conn,
3509 subs_opp_client_interface_removed_id);
3510 subs_opp_client_interface_removed_id = -1;
3512 if (subs_opp_client_property_id != -1) {
3513 g_dbus_connection_signal_unsubscribe(conn,
3514 subs_opp_client_property_id);
3515 subs_opp_client_property_id = -1;
3521 int _bt_register_map_client_subscribe_signal(GDBusConnection *conn,
3527 static int subs_map_client_interface_added_id = -1;
3528 static int subs_map_client_interface_removed_id = -1;
3529 static int subs_map_client_property_id = -1;
3533 if (subs_map_client_interface_added_id == -1) {
3534 subs_map_client_interface_added_id = g_dbus_connection_signal_subscribe(conn,
3535 NULL, BT_MANAGER_INTERFACE,
3536 BT_INTERFACES_ADDED, NULL, NULL, 0,
3537 __bt_map_event_filter,
3540 if (subs_map_client_interface_removed_id == -1) {
3541 subs_map_client_interface_removed_id = g_dbus_connection_signal_subscribe(conn,
3542 NULL, BT_MANAGER_INTERFACE,
3543 BT_INTERFACES_REMOVED, NULL, NULL, 0,
3544 __bt_map_event_filter,
3547 if (subs_map_client_property_id == -1) {
3548 subs_map_client_property_id = g_dbus_connection_signal_subscribe(conn,
3549 NULL, BT_PROPERTIES_INTERFACE,
3550 BT_PROPERTIES_CHANGED, NULL, NULL, 0,
3551 __bt_map_event_filter,
3555 if (subs_map_client_interface_added_id != -1) {
3556 g_dbus_connection_signal_unsubscribe(conn,
3557 subs_map_client_interface_added_id);
3558 subs_map_client_interface_added_id = -1;
3560 if (subs_map_client_interface_removed_id != -1) {
3561 g_dbus_connection_signal_unsubscribe(conn,
3562 subs_map_client_interface_removed_id);
3563 subs_map_client_interface_removed_id = -1;
3565 if (subs_map_client_property_id != -1) {
3566 g_dbus_connection_signal_unsubscribe(conn,
3567 subs_map_client_property_id);
3568 subs_map_client_property_id = -1;
3574 int _bt_register_a2dp_subscribe_signal(GDBusConnection *conn,
3580 static int subs_a2dp_source_id = -1;
3581 static int subs_a2dp_sink_id = -1;
3584 if (subs_a2dp_source_id == -1) {
3585 subs_a2dp_source_id = g_dbus_connection_signal_subscribe(conn,
3586 NULL, BT_A2DP_SOURCE_INTERFACE,
3587 NULL, NULL, NULL, 0,
3588 __bt_opc_event_filter,
3591 if (subs_a2dp_sink_id == -1) {
3592 subs_a2dp_sink_id = g_dbus_connection_signal_subscribe(conn,
3593 NULL, BT_SINK_INTERFACE,
3594 NULL, NULL, NULL, 0,
3595 __bt_opc_event_filter,
3599 if (subs_a2dp_source_id != -1) {
3600 g_dbus_connection_signal_unsubscribe(conn,
3601 subs_a2dp_source_id);
3602 subs_a2dp_source_id = -1;
3604 if (subs_a2dp_sink_id != -1) {
3605 g_dbus_connection_signal_unsubscribe(conn,
3607 subs_a2dp_sink_id = -1;
3613 static void __bt_dump_event_filter(GDBusConnection *connection,
3614 const gchar *sender_name,
3615 const gchar *object_path,
3616 const gchar *interface_name,
3617 const gchar *signal_name,
3618 GVariant *parameters,
3624 int __bt_register_dump_subscribe_signal(GDBusConnection *conn,
3630 static int subs_source_id = -1;
3633 if (subs_source_id == -1) {
3634 subs_source_id = g_dbus_connection_signal_subscribe(conn,
3635 NULL, BT_DUMP_SERVICE_INTERFACE,
3636 BT_DUMP_SERVICE_SIGNAL, BT_DUMP_SERVICE_PATH, NULL, 0,
3637 __bt_dump_event_filter,
3641 if (subs_source_id != -1) {
3642 g_dbus_connection_signal_unsubscribe(conn,
3644 subs_source_id = -1;
3650 int _bt_register_service_event(GDBusConnection *g_conn, int event_type)
3654 retv_if(g_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
3656 switch (event_type) {
3657 case BT_MANAGER_EVENT:
3658 _bt_register_manager_subscribe_signal(g_conn, TRUE);
3660 case BT_DEVICE_EVENT:
3661 _bt_register_device_subscribe_signal(g_conn, TRUE);
3664 _bt_register_input_subscribe_signal(g_conn, TRUE);
3666 case BT_NETWORK_EVENT:
3667 _bt_register_network_subscribe_signal(g_conn, TRUE);
3669 case BT_HEADSET_EVENT:
3670 _bt_register_audio_subscribe_signal(g_conn, TRUE);
3672 case BT_OPP_SERVER_EVENT:
3673 BT_ERR("BT_OPP_SERVER_EVENT: register service event");
3674 _bt_register_opp_server_subscribe_signal(g_conn, TRUE);
3677 case BT_OPP_CLIENT_EVENT:
3678 BT_ERR("BT_OPP_CLIENT_EVENT: register service event");
3679 _bt_register_opp_client_subscribe_signal(g_conn, TRUE);
3681 case BT_MAP_CLIENT_EVENT:
3682 BT_ERR("BT_MAP_CLIENT_EVENT: register service event");
3683 _bt_register_map_client_subscribe_signal(g_conn, TRUE);
3685 case BT_A2DP_SOURCE_EVENT:
3686 BT_INFO("A2dp Source event");
3687 _bt_register_a2dp_subscribe_signal(g_conn, TRUE);
3690 BT_ERR("Unknown event");
3691 return BLUETOOTH_ERROR_INTERNAL;
3694 return BLUETOOTH_ERROR_NONE;
3697 void _bt_unregister_service_event(GDBusConnection *g_conn, int event_type)
3701 ret_if(g_conn == NULL);
3703 switch (event_type) {
3704 case BT_MANAGER_EVENT:
3705 _bt_register_manager_subscribe_signal(g_conn, FALSE);
3706 _bt_register_device_subscribe_signal(g_conn, FALSE);
3707 _bt_register_input_subscribe_signal(g_conn, FALSE);
3708 _bt_register_network_subscribe_signal(g_conn, FALSE);
3709 _bt_register_audio_subscribe_signal(g_conn, FALSE);
3711 case BT_OPP_SERVER_EVENT:
3712 _bt_register_opp_server_subscribe_signal(g_conn, FALSE);
3714 case BT_OPP_CLIENT_EVENT:
3715 _bt_register_opp_client_subscribe_signal(g_conn, FALSE);
3717 case BT_MAP_CLIENT_EVENT:
3718 _bt_register_map_client_subscribe_signal(g_conn, FALSE);
3721 BT_ERR("Unknown event");
3728 static int __bt_init_manager_receiver(void)
3732 GError *error = NULL;
3734 if (manager_conn == NULL) {
3735 manager_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
3736 if (error != NULL) {
3737 BT_ERR("ERROR: Can't get on system bus [%s]", error->message);
3738 g_clear_error(&error);
3740 retv_if(manager_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
3743 if (_bt_register_service_event(manager_conn,
3744 BT_MANAGER_EVENT) != BLUETOOTH_ERROR_NONE)
3746 if (_bt_register_service_event(manager_conn,
3747 BT_DEVICE_EVENT) != BLUETOOTH_ERROR_NONE)
3750 if (_bt_register_service_event(manager_conn,
3751 BT_HID_EVENT) != BLUETOOTH_ERROR_NONE)
3754 if (_bt_register_service_event(manager_conn,
3755 BT_HEADSET_EVENT) != BLUETOOTH_ERROR_NONE)
3758 if (_bt_register_service_event(manager_conn,
3759 BT_NETWORK_EVENT) != BLUETOOTH_ERROR_NONE)
3762 __bt_register_dump_subscribe_signal(manager_conn, TRUE);
3763 return BLUETOOTH_ERROR_NONE;
3766 g_object_unref(manager_conn);
3767 manager_conn = NULL;
3772 return BLUETOOTH_ERROR_INTERNAL;
3775 static int __bt_init_obexd_receiver(void)
3778 #ifndef TIZEN_PROFILE_TV /* TODO: obexd doesn't work in TV profile. It should be resolved later. */
3779 GError *error = NULL;
3781 if (obexd_conn == NULL) {
3782 obexd_conn = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &error);
3783 if (error != NULL) {
3784 BT_ERR("ERROR: Can't get on session bus [%s]", error->message);
3785 g_clear_error(&error);
3787 retv_if(obexd_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
3790 if (_bt_register_service_event(obexd_conn,
3791 BT_OPP_SERVER_EVENT) != BLUETOOTH_ERROR_NONE) {
3792 BT_ERR("Error while registering service event");
3793 g_object_unref(obexd_conn);
3795 return BLUETOOTH_ERROR_INTERNAL;
3800 return BLUETOOTH_ERROR_NONE;
3803 gboolean __bt_reinit_obexd_receiver(gpointer user_data)
3805 static int retry_cnt = 0;
3806 int result = BLUETOOTH_ERROR_NONE;
3810 result = __bt_init_obexd_receiver();
3811 if (result != BLUETOOTH_ERROR_NONE) {
3812 /* 20 ms * 50 = 10 seconds. During 10 seconds fail to initialize,
3813 then it is not the timing issue. Just can't use the session bus connection */
3814 if (retry_cnt > 100) {
3815 BT_ERR("Fail to init obexd receiver by 50 times.");
3817 session_reinit_timer = 0;
3821 BT_DBG("Retry to initialize the obexd receiver");
3826 session_reinit_timer = 0;
3833 /* To receive the event from bluez */
3834 int _bt_init_service_event_receiver(void)
3840 result = __bt_init_manager_receiver();
3841 retv_if(result != BLUETOOTH_ERROR_NONE, result);
3843 result = __bt_init_obexd_receiver();
3844 if (result != BLUETOOTH_ERROR_NONE) {
3845 BT_ERR("Fail to init obexd receiver");
3847 /* Try to re-initialize obexd receiver in the timer */
3848 if (session_reinit_timer > 0)
3849 g_source_remove(session_reinit_timer);
3851 session_reinit_timer = g_timeout_add(BT_SESSION_BUS_GET_TIMEOUT,
3852 (GSourceFunc)__bt_reinit_obexd_receiver, NULL);
3857 return BLUETOOTH_ERROR_NONE;
3860 void _bt_deinit_service_event_receiver(void)
3864 _bt_unregister_service_event(manager_conn, BT_MANAGER_EVENT);
3866 _bt_unregister_service_event(obexd_conn, BT_OPP_SERVER_EVENT);
3868 __bt_register_dump_subscribe_signal(manager_conn, FALSE);
3871 g_object_unref(manager_conn);
3872 manager_conn = NULL;
3876 g_object_unref(obexd_conn);
3881 g_source_remove(event_id);
3884 if (le_scan_event_id > 0)
3885 g_source_remove(le_scan_event_id);
3886 le_scan_event_id = 0;