2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
22 #include <vconf-internal-bt-keys.h>
24 #include "bluetooth-api.h"
25 #include "bt-internal-types.h"
27 #include "bt-service-common.h"
28 #include "bt-service-event.h"
29 #include "bt-service-main.h"
30 #include "bt-service-adapter.h"
31 #include "bt-service-adapter-le.h"
32 #include "bt-service-device.h"
33 #include "bt-service-avrcp.h"
34 #include "bt-service-obex-server.h"
35 #include "bt-service-rfcomm-server.h"
36 #include "bt-service-audio.h"
37 #include "bt-service-agent.h"
38 #include "bt-service-pbap.h"
39 #include "bt-service-headset-connection.h"
40 #include "bt-service-avrcp-controller.h"
41 #include "bt-service-hid.h"
42 #include "bt-service-proximity.h"
44 #include "bt-service-opp-client.h"
46 #ifdef TIZEN_DPM_ENABLE
47 #include "bt-service-dpm.h"
50 #define DBUS_TIMEOUT 20 * 1000 /* 20 Sec */
51 static GDBusConnection *manager_conn;
52 static GDBusConnection *obexd_conn;
53 static GDBusConnection *opc_obexd_conn;
55 static GList *p_cache_list = NULL;
57 static guint event_id;
58 static guint session_reinit_timer;
59 guint nap_connected_device_count = 0;
60 static guint hid_connected_device_count = 0;
61 static GList *p_adv_ind_list = NULL;
64 bt_remote_dev_info_t *dev_info;
68 * obexd connection type
76 OBEX_PCSUITE = (1 << 6),
77 OBEX_SYNCEVOLUTION = (1 << 7),
79 } bluetooth_obex_connection_type_t;
81 void _bt_handle_property_changed_event(GVariant *msg, const char *object_path);
82 void _bt_opc_property_changed_event(GVariant *msg, char *path);
83 int _bt_register_service_event(GDBusConnection *g_conn, int event_type);
84 void _bt_unregister_service_event(GDBusConnection *g_conn, int event_type);
85 void _bt_opp_client_event_deinit(void);
86 void _bt_handle_network_client_event(GVariant *msg_iter,
88 void __bt_gatt_char_property_changed_event(GVariant *msg_iter,
91 static void __bt_free_bt_le_adv_info_t(gpointer data)
93 bt_le_adv_info_t *adv_info = data;
95 if (adv_info->timer_id)
96 g_source_remove(adv_info->timer_id);
97 adv_info->timer_id = 0;
99 g_free(adv_info->addr);
100 g_free(adv_info->data);
104 static bt_le_adv_info_t *__bt_get_adv_ind_info(char *addr)
106 retv_if(!addr, NULL);
107 bt_le_adv_info_t *adv_info = NULL;
108 GList *current = g_list_first((GList *)p_adv_ind_list);
109 while (current && current->data) {
110 adv_info = (bt_le_adv_info_t *)current->data;
111 if (adv_info && !g_strcmp0(adv_info->addr, addr))
113 current = g_list_next(current);
118 static int __bt_add_adv_ind_info(bt_le_adv_info_t *adv_info)
120 retv_if(!adv_info, -1);
121 if (__bt_get_adv_ind_info(adv_info->addr) != NULL) {
122 __bt_free_bt_le_adv_info_t(adv_info);
125 p_adv_ind_list = g_list_append(p_adv_ind_list, adv_info);
130 static void __bt_del_adv_ind_info(char *addr)
133 ret_if(!p_adv_ind_list);
134 bt_le_adv_info_t *adv_info = NULL;
135 GList *current = g_list_first((GList *)p_adv_ind_list);
136 while (current && current->data) {
137 adv_info = (bt_le_adv_info_t *)current->data;
138 if (adv_info && !g_strcmp0(adv_info->addr, addr)) {
139 p_adv_ind_list = g_list_remove(p_adv_ind_list, adv_info);
140 __bt_free_bt_le_adv_info_t(adv_info);
143 current = g_list_next(current);
147 static gboolean __bt_adv_scan_req_timeout_cb(gpointer user_data)
149 bt_remote_le_dev_info_t le_dev_info;
150 bt_le_adv_info_t *adv_info = (bt_le_adv_info_t*)user_data;
152 memset(&le_dev_info, 0x00, sizeof(bt_remote_le_dev_info_t));
154 le_dev_info.address = adv_info->addr;
155 le_dev_info.addr_type = adv_info->addr_type;
156 le_dev_info.rssi = adv_info->rssi;
157 le_dev_info.adv_data = adv_info->data;
158 le_dev_info.adv_data_len = 0;
159 adv_info->timer_id = 0;
161 _bt_send_scan_result_event(&le_dev_info, adv_info);
162 __bt_del_adv_ind_info(adv_info->addr);
167 static void __bt_free_cache_info(bt_cache_info_t *cache_info)
169 ret_if(cache_info == NULL);
170 _bt_free_device_info(cache_info->dev_info);
174 static gboolean __bt_parse_device_properties(GVariant *item,
175 bt_remote_dev_info_t *dev_info)
184 g_variant_iter_init(&iter, item);
185 while (g_variant_iter_loop(&iter, "{sv}", &key, &val)) {
186 if (strcasecmp(key, "Address") == 0) {
187 dev_info->address = g_variant_dup_string(val, &len);
188 } else if (strcasecmp(key, "Class") == 0) {
189 dev_info->class = g_variant_get_uint32(val);
190 } else if (strcasecmp(key, "name") == 0) {
191 if (dev_info->name == NULL)
192 dev_info->name = g_variant_dup_string(val, &len);
193 } else if (strcasecmp(key, "Connected") == 0) {
194 dev_info->connected = g_variant_get_byte(val);
195 } else if (strcasecmp(key, "paired") == 0) {
196 dev_info->paired = g_variant_get_boolean(val);
197 } else if (strcasecmp(key, "Trusted") == 0) {
198 dev_info->trust = g_variant_get_boolean(val);
199 } else if (strcasecmp(key, "RSSI") == 0) {
200 dev_info->rssi = g_variant_get_int16(val);
201 } else if (strcasecmp(key, "LastAddrType") == 0) {
202 dev_info->addr_type = g_variant_get_byte(val);
203 } else if (strcasecmp(key, "UUIDs") == 0) {
207 size = g_variant_get_size(val);
210 uuid_value = (char **)g_variant_get_strv(val, &size);
211 if (dev_info->uuids == NULL)
212 dev_info->uuids = g_malloc0(sizeof(char *) * size);
214 for (i = 0; uuid_value[i] != NULL; i++) {
215 dev_info->uuid_count++;
216 dev_info->uuids[i] = g_strdup(uuid_value[i]);
220 } else if (strcasecmp(key, "LegacyManufacturerDataLen") == 0) {
221 g_variant_get(val, "q", &dev_info->manufacturer_data_len);
222 if (dev_info->manufacturer_data_len > BLUETOOTH_MANUFACTURER_DATA_LENGTH_MAX) {
223 BT_ERR("manufacturer_data_len is too long(len = %d)", dev_info->manufacturer_data_len);
224 dev_info->manufacturer_data_len = BLUETOOTH_MANUFACTURER_DATA_LENGTH_MAX;
227 if (dev_info->manufacturer_data_len == 0)
228 dev_info->manufacturer_data = g_strdup("");
229 } else if (strcasecmp(key, "LegacyManufacturerData") == 0) {
232 GVariantIter *value_iter;
235 len = g_variant_get_size(val);
239 dev_info->manufacturer_data = g_malloc0(len);
241 g_variant_get(val, "ay", &value_iter);
242 while (g_variant_iter_loop(value_iter, "y", &m_value))
243 dev_info->manufacturer_data[i++] = m_value;
244 g_variant_iter_free(value_iter);
252 static gboolean __bt_parse_interface(GVariant *msg,
253 bt_remote_dev_info_t *dev_info)
256 GVariant *optional_param = NULL;
259 char *interface_name = NULL;
260 GVariant *inner_iter = NULL;
261 g_variant_get(msg, "(&o@a{sa{sv}})",
262 &path, &optional_param);
263 g_variant_iter_init(&iter, optional_param);
265 retv_if(optional_param == NULL, FALSE);
267 while ((child = g_variant_iter_next_value(&iter))) {
268 g_variant_get(child, "{&s@a{sv}}", &interface_name, &inner_iter);
269 if (g_strcmp0(interface_name, BT_DEVICE_INTERFACE) == 0) {
270 BT_DBG("Found a device: %s", path);
271 if (__bt_parse_device_properties(inner_iter,
272 dev_info) == FALSE) {
273 g_variant_unref(inner_iter);
274 g_variant_unref(child);
275 g_variant_unref(optional_param);
276 BT_ERR("Fail to parse the properies");
279 g_variant_unref(inner_iter);
280 g_variant_unref(child);
281 g_variant_unref(optional_param);
285 g_variant_unref(inner_iter);
286 g_variant_unref(child);
289 g_variant_unref(optional_param);
294 static int __bt_get_owner_info(GVariant *msg, char **name,
295 char **previous, char **current)
297 g_variant_get(msg, "(sss)", name, previous, current);
298 return BLUETOOTH_ERROR_NONE;
301 static int __bt_get_agent_signal_info(GVariant *msg, char **address,
302 char **name, char **uuid)
304 g_variant_get(msg, "(sss)", address, name, uuid);
305 return BLUETOOTH_ERROR_NONE;
308 void __bt_set_device_values(gboolean connected, int state)
310 int bt_device_state = VCONFKEY_BT_DEVICE_NONE;
312 if (vconf_get_int(VCONFKEY_BT_DEVICE, &bt_device_state) != 0)
313 BT_ERR("vconf_get_int failed");
315 if (connected == TRUE)
316 bt_device_state |= state;
317 else if (bt_device_state & state)
318 bt_device_state ^= state;
320 if (vconf_set_int(VCONFKEY_BT_DEVICE, bt_device_state) != 0)
321 BT_ERR("vconf_set_int failed");
324 gboolean _bt_discovery_finished_cb(gpointer user_data)
326 int result = BLUETOOTH_ERROR_NONE;
328 GVariant *param = NULL;
329 if (_bt_get_discovering_property(DISCOVERY_ROLE_BREDR) == FALSE) {
330 if (_bt_get_cancel_by_user() == TRUE)
331 result = BLUETOOTH_ERROR_CANCEL_BY_USER;
333 _bt_set_cancel_by_user(FALSE);
334 _bt_set_discovery_status(FALSE);
335 param = g_variant_new("(i)", result);
336 _bt_send_event(BT_ADAPTER_EVENT,
337 BLUETOOTH_EVENT_DISCOVERY_FINISHED,
344 static gboolean __bt_le_discovery_finished_cb(gpointer user_data)
346 int result = BLUETOOTH_ERROR_NONE;
348 GVariant *param = NULL;
349 if (_bt_get_discovering_property(DISCOVERY_ROLE_LE) == FALSE) {
350 if (_bt_get_cancel_by_user() == TRUE)
351 result = BLUETOOTH_ERROR_CANCEL_BY_USER;
353 g_list_free_full(p_adv_ind_list, __bt_free_bt_le_adv_info_t);
354 p_adv_ind_list = NULL;
356 _bt_set_cancel_by_user(FALSE);
357 _bt_disable_all_scanner_status();
358 _bt_set_le_scan_status(FALSE);
359 param = g_variant_new("(i)", result);
360 _bt_send_event(BT_LE_ADAPTER_EVENT,
361 BLUETOOTH_EVENT_LE_DISCOVERY_FINISHED,
368 void __bt_update_remote_cache_devinfo(const char *address, gboolean paired_status)
372 ret_if(address == NULL);
375 bt_cache_info_t *cache_info;
376 bt_remote_dev_info_t *dev_info;
378 node = g_list_first(p_cache_list);
380 while (node != NULL) {
381 cache_info = (bt_cache_info_t *)node->data;
383 if (cache_info == NULL) {
384 node = g_list_next(node);
388 dev_info = cache_info->dev_info;
389 if (strcasecmp(dev_info->address,
391 BT_DBG("Device Found");
392 if (paired_status == TRUE)
393 cache_info->dev_info->paired = TRUE;
395 cache_info->dev_info->paired = FALSE;
398 node = g_list_next(node);
403 static void __bt_device_remote_connected_properties(
404 bt_remote_dev_info_t *remote_dev_info,
405 char *address, gboolean connected)
407 int result = BLUETOOTH_ERROR_NONE;
409 GVariant *param = NULL;
412 if (remote_dev_info->uuid_count > 0) {
413 for (i = 0; i < remote_dev_info->uuid_count; i++) {
414 char *uuid = remote_dev_info->uuids[i];
415 if (strcasecmp(uuid, HID_UUID) == 0) {
416 int event = BLUETOOTH_EVENT_NONE;
418 event = (connected == TRUE) ?
419 BLUETOOTH_HID_CONNECTED :
420 BLUETOOTH_HID_DISCONNECTED;
421 param = g_variant_new("(is)", result,
423 _bt_send_event(BT_HID_EVENT, event,
433 gboolean __bt_handle_is_flight_mode_enabled(void)
435 #ifdef TIZEN_FEATURE_FLIGHTMODE_ENABLED
436 int is_flight_mode = 0;
439 ret = vconf_get_bool(VCONFKEY_TELEPHONY_FLIGHT_MODE, &is_flight_mode);
441 BT_ERR("vconf_get_bool failed");
443 return (is_flight_mode == 0) ? FALSE : TRUE;
449 void _bt_handle_adapter_event(GVariant *msg, const char *member)
453 int result = BLUETOOTH_ERROR_NONE;
454 GVariant *param = NULL;
455 ret_if(member == NULL);
457 if (strcasecmp(member, "DeviceCreated") == 0) {
458 char *object_path = NULL;
460 bt_remote_dev_info_t *remote_dev_info;
462 ret_if(_bt_is_device_creating() == FALSE);
464 /* Bonding from remote device */
465 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
467 g_variant_get(msg, "(&o)", &object_path);
468 _bt_convert_device_path_to_address((const char*)object_path, address);
470 remote_dev_info = _bt_get_remote_device_info_by_object_path(object_path);
471 if (remote_dev_info == NULL) {
476 _bt_free_device_info(remote_dev_info);
478 } else if (strcasecmp(member, "InterfacesRemoved") == 0) {
479 char *object_path = NULL;
481 bt_cache_info_t *cache_info;
482 bt_remote_dev_info_t *dev_info;
485 /* Bonding from remote device */
486 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
488 g_variant_get(msg, "(&o)", &object_path);
490 _bt_convert_device_path_to_address((const char *)object_path, address);
492 node = g_list_first(p_cache_list);
494 while (node != NULL) {
495 cache_info = (bt_cache_info_t *)node->data;
497 if (cache_info == NULL) {
498 node = g_list_next(node);
502 dev_info = cache_info->dev_info;
503 if (strcasecmp(dev_info->address,
505 p_cache_list = g_list_remove(p_cache_list,
507 __bt_free_cache_info(cache_info);
510 node = g_list_next(node);
513 } else if (strcasecmp(member, "AdvertisingEnabled") == 0) {
514 BT_DBG("Advertising Enabled");
518 gboolean status = FALSE;
520 g_variant_get(msg, "(ib)", &slot_id, &status);
522 BT_DBG("Advertising Enabled : slot_id [%d] status [%d]", slot_id, status);
524 /* Send event to application */
525 _bt_set_advertising_status(slot_id, status);
527 adv_handle = _bt_get_adv_slot_adv_handle(slot_id);
530 event = BLUETOOTH_EVENT_ADVERTISING_STARTED;
532 event = BLUETOOTH_EVENT_ADVERTISING_STOPPED;
533 param = g_variant_new("(ii)", result,
538 sender = _bt_get_adv_slot_owner(slot_id);
539 _bt_send_event_to_dest(sender, BT_ADAPTER_EVENT,
543 _bt_send_event(BT_ADAPTER_EVENT, event, param);
546 if (event == BLUETOOTH_EVENT_ADVERTISING_STOPPED)
547 _bt_unregister_adv_slot_owner(slot_id);
548 } else if (strcasecmp(member, "RssiEnabled") == 0) {
549 BT_DBG("RSSI Enabled");
550 gboolean status = FALSE;
551 char *address = NULL;
553 g_variant_get(msg, "(sib)", &address, &link_type, &status);
555 BT_DBG("RSSI Enabled [%s %d]", address, status);
556 param = g_variant_new("(isib)", result,
557 address, link_type, status);
558 _bt_send_event(BT_DEVICE_EVENT,
559 BLUETOOTH_EVENT_RSSI_ENABLED,
562 } else if (strcasecmp(member, "RssiAlert") == 0) {
563 BT_DBG("RSSI Alert");
567 char *address = NULL;
568 g_variant_get(msg, "(siii)", &address, &link_type, &alert_type, &rssi_dbm);
570 BT_DBG("RSSI Alert: [Address %s LinkType %d] [Type %d DBM %d]",
571 address, alert_type, rssi_dbm);
572 param = g_variant_new("(isiii)", result,
573 address, link_type, alert_type, rssi_dbm);
574 _bt_send_event(BT_DEVICE_EVENT,
575 BLUETOOTH_EVENT_RSSI_ALERT,
578 } else if (strcasecmp(member, "RawRssi") == 0) {
582 char *address = NULL;
583 g_variant_get(msg, "(sii)", &address, &link_type, &rssi_dbm);
585 BT_DBG("Raw RSSI: [Address %s] [Link Type %d][RSSI DBM %d]",
586 address, link_type, rssi_dbm);
587 param = g_variant_new("(isii)", result,
588 address, link_type, rssi_dbm);
589 _bt_send_event(BT_DEVICE_EVENT,
590 BLUETOOTH_EVENT_RAW_RSSI,
593 } else if (strcasecmp(member, BT_HARDWARE_ERROR) == 0) {
594 BT_ERR_C("### Hardware error received from BLUEZ");
595 /* Don't add the recovery logic into platform */
597 _bt_recover_adapter();
599 } else if (strcasecmp(member, BT_TX_TIMEOUT_ERROR) == 0) {
600 BT_ERR_C("### Tx timeout error received from BLUEZ");
601 /* Don't add the recovery logic into platform */
603 _bt_recover_adapter();
609 static void __bt_adapter_property_changed_event(GVariant *msg, const char *path)
611 GDBusProxy *adapter_proxy;
613 int result = BLUETOOTH_ERROR_NONE;
614 GVariantIter value_iter;
615 GVariant *val = NULL;
616 GVariant *ret = NULL;
618 char *property = NULL;
619 GVariant *param = NULL;
621 g_variant_iter_init(&value_iter, msg);
622 while ((g_variant_iter_loop(&value_iter, "{sv}", &property, &val))) {
623 BT_INFO("Property %s", property);
625 if (strcasecmp(property, "Discovering") == 0) {
626 gboolean discovering = FALSE;
628 if (_bt_adapter_get_status() != BT_ACTIVATED)
631 g_variant_get(val, "b", &discovering);
632 BT_DBG("Discovering %d", discovering);
634 /* Send event to application */
635 if (discovering == TRUE) {
636 _bt_set_discovery_status(TRUE);
637 param = g_variant_new("(i)", result);
638 _bt_send_event(BT_ADAPTER_EVENT,
639 BLUETOOTH_EVENT_DISCOVERY_STARTED,
645 adapter_proxy = _bt_get_adapter_proxy();
646 if (adapter_proxy == NULL)
649 /* Need to stop searching */
650 ret = g_dbus_proxy_call_sync(adapter_proxy, "StopDiscovery",
652 G_DBUS_CALL_FLAGS_NONE,
656 BT_ERR("Dbus Error : %s", err->message);
660 g_variant_unref(ret);
662 event_id = g_timeout_add(BT_DISCOVERY_FINISHED_DELAY,
663 (GSourceFunc)_bt_discovery_finished_cb, NULL);
665 } else if (strcasecmp(property, "LEDiscovering") == 0) {
666 gboolean le_discovering = FALSE;
668 if (_bt_adapter_get_status() != BT_ACTIVATED ||
669 _bt_adapter_get_le_status() != BT_LE_ACTIVATED)
672 g_variant_get(val, "b", &le_discovering);
673 BT_DBG("LEDiscovering %d", le_discovering);
675 /* Send event to application */
676 if (le_discovering == TRUE) {
677 _bt_set_le_scan_status(TRUE);
678 param = g_variant_new("(i)", result);
679 _bt_send_event(BT_LE_ADAPTER_EVENT,
680 BLUETOOTH_EVENT_LE_DISCOVERY_STARTED,
686 adapter_proxy = _bt_get_adapter_proxy();
687 if (adapter_proxy == NULL)
690 /* Need to stop searching */
691 ret = g_dbus_proxy_call_sync(adapter_proxy, "StopLEDiscovery",
693 G_DBUS_CALL_FLAGS_NONE,
697 BT_ERR("Dbus Error %s", err->message);
701 g_variant_unref(ret);
703 event_id = g_timeout_add(BT_DISCOVERY_FINISHED_DELAY,
704 (GSourceFunc)__bt_le_discovery_finished_cb, NULL);
706 } else if (strcasecmp(property, "Name") == 0) {
708 g_variant_get(val, "&s", &name);
709 param = g_variant_new("(is)", result, name);
710 /* Send event to application */
711 _bt_send_event(BT_ADAPTER_EVENT,
712 BLUETOOTH_EVENT_LOCAL_NAME_CHANGED,
714 } else if (strcasecmp(property, "Alias") == 0) {
716 g_variant_get(val, "&s", &alias);
717 param = g_variant_new("(is)", result, alias);
718 /* Send event to application */
719 _bt_send_event(BT_ADAPTER_EVENT,
720 BLUETOOTH_EVENT_LOCAL_NAME_CHANGED,
722 } else if (strcasecmp(property, "Discoverable") == 0) {
723 gboolean discoverable = FALSE;
725 g_variant_get(val, "b", &discoverable);
726 BT_DBG("discoverable %d", discoverable);
728 if (discoverable == FALSE) {
729 if (_bt_get_discoverable_timeout_property() > 0) {
730 unsigned int time = 0;
732 adapter_proxy = _bt_get_adapter_properties_proxy();
733 if (adapter_proxy == NULL)
736 ret = g_dbus_proxy_call_sync(adapter_proxy, "Set",
737 g_variant_new("(ssv)", BT_ADAPTER_INTERFACE,
738 "DiscoverableTimeout",
739 g_variant_new("u", time)),
740 G_DBUS_CALL_FLAGS_NONE,
745 BT_ERR("Set DiscoverableTimeout Failed: %s", err->message);
749 g_variant_unref(ret);
752 mode = BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE;
754 /* Send event to application */
755 BT_INFO("[Non Discoverable]");
756 param = g_variant_new("(in)", result, mode);
757 _bt_send_event(BT_ADAPTER_EVENT,
758 BLUETOOTH_EVENT_DISCOVERABLE_MODE_CHANGED,
761 _bt_get_discoverable_mode(&mode);
763 /* Event will be sent by "DiscoverableTimeout" signal */
764 if (mode != BLUETOOTH_DISCOVERABLE_MODE_GENERAL_DISCOVERABLE) {
766 g_variant_unref(val);
770 /* Send event to application */
771 BT_INFO("[General Discoverable]");
772 param = g_variant_new("(in)", result, mode);
773 _bt_send_event(BT_ADAPTER_EVENT,
774 BLUETOOTH_EVENT_DISCOVERABLE_MODE_CHANGED,
777 } else if (strcasecmp(property, "DiscoverableTimeout") == 0) {
778 _bt_get_discoverable_mode(&mode);
780 /* Event was already sent by "Discoverable" signal */
781 if (mode == BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE ||
782 mode == BLUETOOTH_DISCOVERABLE_MODE_GENERAL_DISCOVERABLE)
785 /* Send event to application */
786 BT_INFO("[Limited Discoverable (Timeout %u secs)]",
787 _bt_get_discoverable_timeout_property());
788 param = g_variant_new("(in)", result, mode);
789 _bt_send_event(BT_ADAPTER_EVENT,
790 BLUETOOTH_EVENT_DISCOVERABLE_MODE_CHANGED,
792 } else if (strcasecmp(property, "Powered") == 0) {
793 /* TODO: Need to check this operation!! */
794 gboolean powered = FALSE;
797 g_variant_get(val, "b", &powered);
798 BT_DBG("Powered = %d", powered);
799 if (powered == FALSE) {
801 _bt_handle_adapter_removed();
803 if (vconf_get_int(VCONFKEY_BT_STATUS, &bt_state) == 0 &&
804 bt_state != VCONFKEY_BT_STATUS_OFF) {
805 if (__bt_handle_is_flight_mode_enabled() == FALSE)
806 _bt_disable_adapter();
808 _bt_handle_adapter_removed();
811 if (vconf_get_int(VCONFKEY_BT_LE_STATUS, &bt_state) == 0 &&
812 bt_state != VCONFKEY_BT_LE_STATUS_OFF) {
813 _bt_set_le_disabled(BLUETOOTH_ERROR_NONE);
817 _bt_handle_adapter_added();
820 } else if (strcasecmp(property, "Connectable") == 0) {
821 gboolean connectable = FALSE;
823 g_variant_get(val, "b", &connectable);
825 BT_DBG("Connectable property is changed : %d", connectable);
826 param = g_variant_new("(b)", connectable);
827 _bt_send_event(BT_ADAPTER_EVENT,
828 BLUETOOTH_EVENT_CONNECTABLE_CHANGED,
831 if (_bt_adapter_get_status() == BT_DEACTIVATING &&
832 _bt_adapter_get_le_status() == BT_LE_ACTIVATED &&
834 _bt_set_disabled(BLUETOOTH_ERROR_NONE);
836 } else if (strcasecmp(property, "SupportedLEFeatures") == 0) {
839 GVariantIter *iter = NULL;
841 g_variant_get(val, "as", &iter);
845 while (g_variant_iter_next(iter, "&s", &name) &&
846 g_variant_iter_next(iter, "&s", &value)) {
847 BT_DBG("name = %s, Value = %s", name, value);
848 if (!_bt_update_le_feature_support(name, value))
849 BT_ERR("Failed to update LE feature (name = %s, value = %s)", name, value);
851 g_variant_iter_free(iter);
852 } else if (strcasecmp(property, "IpspInitStateChanged") == 0) {
853 gboolean ipsp_initialized = FALSE;
855 g_variant_get(val, "b", &ipsp_initialized);
856 BT_DBG("IPSP init state changed: %d", ipsp_initialized);
857 param = g_variant_new("(b)", ipsp_initialized);
859 /* Send event to application */
860 _bt_send_event(BT_ADAPTER_EVENT,
861 BLUETOOTH_EVENT_IPSP_INIT_STATE_CHANGED,
864 BT_DBG("Unhandled property : [%s]", property);
869 static void __bt_obex_property_changed_event(GVariant *msg, const char *path)
873 GVariantIter value_iter;
874 GVariant *child = NULL, *val = NULL;
875 char *property = NULL;
876 g_variant_iter_init(&value_iter, msg);
877 while ((child = g_variant_iter_next_value(&value_iter))) {
878 g_variant_get(child, "{sv}", &property, &val);
880 ret_if(property == NULL);
882 BT_DBG("property :%s", property);
884 if (strcasecmp(property, "Status") == 0) {
886 g_variant_get(val, "s", &status);
888 if (strcasecmp(status, "active") == 0) {
889 _bt_obex_transfer_started(path);
890 } else if (strcasecmp(status, "complete") == 0) {
891 _bt_obex_transfer_completed(path, TRUE);
892 _bt_pbap_obex_transfer_completed(path, TRUE);
893 } else if (strcasecmp(status, "error") == 0) {
894 _bt_obex_transfer_completed(path, FALSE);
895 _bt_pbap_obex_transfer_completed(path, FALSE);
898 } else if (strcasecmp(property, "Transferred") == 0) {
899 guint64 transferred = 0;
900 /* As Transferred is expected guint64 so change int to guint64 and
901 * eariler transferred is static because of it can overwrite data
902 * on present on opc_obex_conn or obexd_conn as these are
903 * static memory are in sequential */
904 g_variant_get(val, "t", &transferred);
906 _bt_obex_transfer_progress(path, transferred);
909 g_variant_unref(val);
910 g_variant_unref(child);
915 static void __bt_device_property_changed_event(GVariant *msg, const char *path)
920 int result = BLUETOOTH_ERROR_NONE;
921 GVariantIter value_iter;
923 char *property = NULL;
925 GVariant *param = NULL;
926 bt_remote_dev_info_t *remote_dev_info;
927 g_variant_iter_init(&value_iter, msg);
928 while ((g_variant_iter_loop(&value_iter, "{sv}", &property, &val))) {
929 BT_DBG("Property %s", property);
930 if (strcasecmp(property, "Connected") == 0) {
933 g_variant_get(val, "i", &connected);
935 event = (connected != BLUETOOTH_CONNECTED_LINK_NONE) ?
936 BLUETOOTH_EVENT_DEVICE_CONNECTED :
937 BLUETOOTH_EVENT_DEVICE_DISCONNECTED;
939 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
941 _bt_convert_device_path_to_address(path, address);
943 BT_DBG("connected: %d", connected);
944 BT_DBG("address: %s", address);
946 remote_dev_info = _bt_get_remote_device_info_by_object_path(path);
948 if (remote_dev_info != NULL) {
949 __bt_device_remote_connected_properties(
950 remote_dev_info, address,
951 connected != BLUETOOTH_CONNECTED_LINK_NONE ?
953 _bt_free_device_info(remote_dev_info);
955 param = g_variant_new("(is)", result, address);
956 /* Send event to application */
957 _bt_send_event(BT_DEVICE_EVENT,
961 } else if (strcasecmp(property, "RSSI") == 0) {
962 bt_remote_dev_info_t *remote_dev_info;
964 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
966 _bt_convert_device_path_to_address(path, address);
967 BT_DBG("address: %s", address);
969 remote_dev_info = _bt_get_remote_device_info_by_object_path(path);
970 if (remote_dev_info == NULL) {
972 g_variant_unref(val);
976 BT_DBG("Address type %d", remote_dev_info->addr_type);
978 if (remote_dev_info->addr_type == 0) {
979 BT_DBG("Name %s", remote_dev_info->name);
981 #ifdef TIZEN_DPM_ENABLE
982 if (_bt_dpm_get_bluetooth_desktop_connectivity_state() ==
984 bluetooth_device_class_t device_class;
985 _bt_divide_device_class(&device_class, remote_dev_info->class);
987 if (device_class.major_class ==
988 BLUETOOTH_DEVICE_MAJOR_CLASS_COMPUTER) {
989 _bt_free_device_info(remote_dev_info);
991 g_variant_unref(val);
998 GVariant *uuids = NULL;
999 GVariantBuilder *builder = NULL;
1001 builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
1002 for (i = 0; i < remote_dev_info->uuid_count; i++) {
1003 g_variant_builder_add(builder, "s",
1004 remote_dev_info->uuids[i]);
1006 uuids = g_variant_new("as", builder);
1007 g_variant_builder_unref(builder);
1008 GVariant *manufacturer_data = NULL;
1009 manufacturer_data = g_variant_new_from_data(G_VARIANT_TYPE_BYTESTRING,
1010 remote_dev_info->manufacturer_data,
1011 remote_dev_info->manufacturer_data_len,
1014 param = g_variant_new("(isunsbub@asn@ay)", result,
1015 remote_dev_info->address,
1016 remote_dev_info->class,
1017 remote_dev_info->rssi,
1018 remote_dev_info->name,
1019 remote_dev_info->paired,
1020 remote_dev_info->connected,
1021 remote_dev_info->trust,
1023 remote_dev_info->manufacturer_data_len,
1026 _bt_send_event(BT_ADAPTER_EVENT,
1027 BLUETOOTH_EVENT_REMOTE_DEVICE_FOUND,
1031 _bt_free_device_info(remote_dev_info);
1032 } else if (strcasecmp(property, "GattConnected") == 0) {
1033 gboolean gatt_connected = FALSE;
1035 g_variant_get(val, "b", &gatt_connected);
1037 event = gatt_connected ? BLUETOOTH_EVENT_GATT_CONNECTED :
1038 BLUETOOTH_EVENT_GATT_DISCONNECTED;
1040 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1042 _bt_convert_device_path_to_address(path, address);
1044 BT_DBG("gatt_connected: %d", gatt_connected);
1045 BT_DBG("address: %s", address);
1046 param = g_variant_new("(is)", result, address);
1047 /* Send event to application */
1048 _bt_send_event(BT_DEVICE_EVENT,
1052 } else if (strcasecmp(property, "Paired") == 0) {
1053 gboolean paired = FALSE;
1054 bt_remote_dev_info_t *remote_dev_info;
1055 g_variant_get(val, "b", &paired);
1056 _bt_agent_set_canceled(FALSE);
1057 /* BlueZ sends paired signal for each paired device */
1058 /* during activation, We should ignore this, otherwise*/
1059 /* application thinks that a new device got paired */
1060 if (_bt_adapter_get_status() != BT_ACTIVATED) {
1061 BT_DBG("BT is not activated, so ignore this");
1063 g_variant_unref(val);
1067 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1069 _bt_convert_device_path_to_address(path, address);
1071 remote_dev_info = _bt_get_remote_device_info_by_object_path(path);
1072 if (remote_dev_info == NULL) {
1074 g_variant_unref(val);
1079 if (paired == FALSE) {
1080 BT_INFO("Unpaired: %s", address);
1081 __bt_update_remote_cache_devinfo(address, FALSE);
1082 param = g_variant_new("(is)", result, address);
1083 _bt_send_event(BT_ADAPTER_EVENT,
1084 BLUETOOTH_EVENT_BONDED_DEVICE_REMOVED,
1086 #ifdef TIZEN_BT_A2DP_SINK_AUTO_CONNECT
1088 char *last_connected = NULL;
1089 last_connected = vconf_get_str(BT_LAST_CONNECTED_DEVICE);
1090 if (!g_strcmp0(address, last_connected))
1091 _bt_audio_set_auto_connect_device_addr("");
1093 free(last_connected);
1097 char secure_addr[BT_ADDRESS_STRING_SIZE] = { 0 };
1099 _bt_convert_addr_string_to_secure_string(secure_addr, address);
1100 BT_INFO("### Paired: %s", secure_addr);
1101 __bt_update_remote_cache_devinfo(address, TRUE);
1103 if (_bt_is_device_creating() == TRUE) {
1104 BT_DBG("Try to Pair by me");
1105 _bt_free_device_info(remote_dev_info);
1108 g_variant_unref(val);
1111 GVariant *uuids = NULL;
1112 GVariantBuilder *builder = NULL;
1114 builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
1115 for (i = 0; i < remote_dev_info->uuid_count; i++) {
1116 g_variant_builder_add(builder, "s",
1117 remote_dev_info->uuids[i]);
1119 uuids = g_variant_new("as", builder);
1120 g_variant_builder_unref(builder);
1121 GVariant *manufacturer_data = NULL;
1122 manufacturer_data = g_variant_new_from_data(G_VARIANT_TYPE_BYTESTRING,
1123 remote_dev_info->manufacturer_data,
1124 remote_dev_info->manufacturer_data_len,
1128 param = g_variant_new("(isunsbub@asn@ay)", result,
1129 address, remote_dev_info->class,
1130 remote_dev_info->rssi,
1131 remote_dev_info->name,
1132 remote_dev_info->paired,
1133 remote_dev_info->connected,
1134 remote_dev_info->trust,
1136 remote_dev_info->manufacturer_data_len,
1138 _bt_send_event(BT_ADAPTER_EVENT,
1139 BLUETOOTH_EVENT_BONDING_FINISHED,
1142 _bt_free_device_info(remote_dev_info);
1144 } else if (strcasecmp(property, "LegacyPaired") == 0) {
1145 gboolean paired = FALSE;
1146 bt_remote_dev_info_t *remote_dev_info;
1147 unsigned char auth_info[5] = {0, };
1149 if (_bt_adapter_get_status() != BT_ACTIVATED) {
1150 BT_DBG("BT is not activated, so ignore this");
1152 g_variant_unref(val);
1156 g_variant_get(val, "b", &paired);
1157 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1158 BT_DBG("LegacyPaired: %d", paired);
1159 _bt_convert_device_path_to_address(path, address);
1161 remote_dev_info = _bt_get_remote_device_info_by_object_path(path);
1162 if (remote_dev_info == NULL) {
1165 g_variant_unref(val);
1168 if (remote_dev_info->is_alias_set == FALSE) {
1169 /*minimum Size of the samsung specific manufacturer data is greater than 30 */
1170 if ((remote_dev_info->manufacturer_data_len > 30) &&
1171 (remote_dev_info->manufacturer_data[0] == 0x00) &&
1172 (remote_dev_info->manufacturer_data[1] == 0x75)) {
1174 /* 2 samsung (0x00 0x75) + 1 (control and version) + 1 (service ID) +
1175 1 (discovery version) + 1 (associated service ID)
1176 2 (Proxamity and locality) + 2 (Device type and icon) = 10 */
1178 memcpy(auth_info, &(remote_dev_info->manufacturer_data[10]), 5);
1182 BT_DBG("LegacyPairing Failed with %s. Show Error Popup", remote_dev_info->name);
1183 _bt_launch_system_popup(BT_AGENT_EVENT_LEGACY_PAIR_FAILED_FROM_REMOTE,
1184 remote_dev_info->name, auth_info, NULL, NULL, NULL);
1186 _bt_free_device_info(remote_dev_info);
1188 } else if (strcasecmp(property, "Trusted") == 0) {
1189 gboolean trusted = FALSE;
1191 g_variant_get(val, "b", &trusted);
1193 event = trusted ? BLUETOOTH_EVENT_DEVICE_AUTHORIZED :
1194 BLUETOOTH_EVENT_DEVICE_UNAUTHORIZED;
1196 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1198 _bt_convert_device_path_to_address(path, address);
1200 BT_DBG("trusted: %d", trusted);
1201 BT_DBG("address: %s", address);
1202 param = g_variant_new("(is)", result, address);
1203 /* Send event to application */
1204 _bt_send_event(BT_DEVICE_EVENT,
1208 } else if (strcasecmp(property, "TrustedProfiles") == 0) {
1211 g_variant_get(val, "u", &trusted);
1213 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1214 _bt_convert_device_path_to_address(path, address);
1216 BT_DBG("Address: %s, TrustedProfiles: %d", address, trusted);
1217 _bt_send_event(BT_DEVICE_EVENT,
1218 BLUETOOTH_EVENT_SUPPORTED_PROFILE_TRUSTED,
1219 g_variant_new("(isi)", result, address, trusted));
1221 } else if (strcasecmp(property, "IpspConnected") == 0) {
1222 gboolean connected = FALSE;
1224 g_variant_get(val, "b", &connected);
1227 event = connected ? BLUETOOTH_EVENT_IPSP_CONNECTED :
1228 BLUETOOTH_EVENT_IPSP_DISCONNECTED;
1230 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1232 _bt_convert_device_path_to_address(path, address);
1234 BT_DBG("Ipspconnected: %d", connected);
1235 BT_DBG("address: %s", address);
1236 param = g_variant_new("(is)", result, address);
1238 /* Send event to application */
1239 _bt_send_event(BT_DEVICE_EVENT,
1243 } else if (strcasecmp(property, "IpspBtInterfaceInfo") == 0) {
1244 char *ifname = NULL;
1246 g_variant_get(val, "s", &ifname);
1248 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1250 _bt_convert_device_path_to_address(path, address);
1252 BT_DBG("Ipsp BT Interface Name: %s", ifname);
1253 BT_DBG("address: %s", address);
1254 param = g_variant_new("(iss)", result, address, ifname);
1256 /* Send event to application */
1257 _bt_send_event(BT_DEVICE_EVENT,
1258 BLUETOOTH_EVENT_IPSP_INTERFACE_INFO,
1266 static void __bt_media_control_changed_event(GVariant *msg, const char *path)
1269 int result = BLUETOOTH_ERROR_NONE;
1270 GVariantIter value_iter;
1271 char *property = NULL;
1273 GVariant *val = NULL;
1274 GVariant *child = NULL;
1275 bt_remote_dev_info_t *remote_dev_info;
1276 GVariant *param = NULL;
1277 g_variant_iter_init(&value_iter, msg);
1278 while ((child = g_variant_iter_next_value(&value_iter))) {
1279 g_variant_get(child, "{sv}", &property, &val);
1280 BT_INFO("Property %s", property);
1281 if (strcasecmp(property, "Connected") == 0) {
1282 gboolean connected = FALSE;
1284 g_variant_get(val, "b", &connected);
1286 event = connected ? BLUETOOTH_EVENT_AVRCP_CONNECTED :
1287 BLUETOOTH_EVENT_AVRCP_DISCONNECTED;
1289 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1291 _bt_convert_device_path_to_address(path, address);
1293 BT_DBG("connected: %d", connected);
1294 BT_DBG("address: %s", address);
1296 remote_dev_info = _bt_get_remote_device_info(address);
1298 if (remote_dev_info != NULL) {
1299 __bt_device_remote_connected_properties(
1300 remote_dev_info, address, connected);
1301 _bt_free_device_info(remote_dev_info);
1303 param = g_variant_new("(is)", result, address);
1304 /* Send event to application */
1305 _bt_send_event(BT_AVRCP_EVENT,
1311 g_variant_unref(child);
1312 g_variant_unref(val);
1317 int get_alert_level_enum(const char *alert)
1321 if (strcmp(alert, "none") == 0)
1322 lvl = BT_PXP_ALERT_NONE;
1323 else if (strcmp(alert, "mild") == 0)
1324 lvl = BT_PXP_ALERT_MILD;
1325 else if (strcmp(alert, "high") == 0)
1326 lvl = BT_PXP_ALERT_HIGH;
1331 static void _bt_handle_pxp_property_changed_event(GVariant *msg, const char *path, int role)
1333 int result = BLUETOOTH_ERROR_NONE;
1336 GVariantIter value_iter;
1337 char *property = NULL;
1339 GVariant *val = NULL;
1340 GVariant *child = NULL;
1341 GVariant *param = NULL;
1342 g_variant_iter_init(&value_iter, msg);
1345 while ((child = g_variant_iter_next_value(&value_iter))) {
1346 g_variant_get(child, "{sv}", &property, &val);
1347 BT_INFO("Property %s", property);
1349 if ((strcasecmp(property, "LinkLossAlertLevel") == 0) ||
1350 (strcasecmp(property, "ImmediateAlertLevel") == 0)) {
1351 char *alert_str = NULL;
1353 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1354 _bt_convert_device_path_to_address(path, address);
1356 if (strcasecmp(property, "LinkLossAlertLevel") == 0)
1357 service_type = BT_PXP_PROPERTY_LLS;
1359 service_type = BT_PXP_PROPERTY_IAS;
1361 g_variant_get(val, "s", &alert_str);
1362 alert_lvl = get_alert_level_enum(alert_str);
1364 param = g_variant_new("(isiii)", result, address,
1365 role, service_type, alert_lvl);
1367 /* Send event to application */
1368 _bt_send_event(BT_DEVICE_EVENT,
1369 BLUETOOTH_EVENT_PXP_PROPERTY_CHANGED,
1375 g_variant_unref(child);
1376 g_variant_unref(val);
1381 void _bt_handle_property_changed_event(GVariant *msg, const char *object_path)
1383 char *interface_name = NULL;
1384 GVariant *val = NULL;
1386 g_variant_get(msg, "(&s@a{sv}@as)", &interface_name, &val, NULL);
1388 if (strcasecmp(interface_name, BT_ADAPTER_INTERFACE) == 0) {
1389 __bt_adapter_property_changed_event(val,
1391 } else if (strcasecmp(interface_name, BT_DEVICE_INTERFACE) == 0) {
1392 __bt_device_property_changed_event(val, object_path);
1393 } else if (strcasecmp(interface_name, BT_OBEX_TRANSFER_INTERFACE) == 0) {
1394 BT_DBG("BT_OBEX_TRANSFER_INTERFACE");
1395 __bt_obex_property_changed_event(val,
1397 } else if (strcasecmp(interface_name, BT_MEDIA_CONTROL_INTERFACE) == 0) {
1398 __bt_media_control_changed_event(val,
1400 } else if (strcasecmp(interface_name, BT_PLAYER_CONTROL_INTERFACE) == 0) {
1401 _bt_handle_avrcp_control_event(val,
1403 } else if (strcasecmp(interface_name, BT_NETWORK_CLIENT_INTERFACE) == 0) {
1404 BT_DBG("BT_NETWORK_CLIENT_INTERFACE");
1405 _bt_handle_network_client_event(val,
1407 } else if (strcasecmp(interface_name, BT_GATT_CHAR_INTERFACE) == 0) {
1408 __bt_gatt_char_property_changed_event(val,
1410 } else if (strcasecmp(interface_name, BT_PROXIMITY_REPORTER_INTERFACE) == 0) {
1411 BT_DBG("BT_PROXIMITY_REPORTER_INTERFACE");
1412 _bt_handle_pxp_property_changed_event(val,
1413 object_path, BT_PXP_REPORTER_ROLE);
1414 } else if (strcasecmp(interface_name, BT_PROXIMITY_MONITOR_INTERFACE) == 0) {
1415 BT_DBG("BT_PROXIMITY_MONITOR_INTERFACE");
1416 _bt_handle_pxp_property_changed_event(val,
1417 object_path, BT_PXP_MONITOR_ROLE);
1419 g_variant_unref(val);
1422 void __bt_opc_property_changed_event(GVariant *msg,
1425 GVariantIter value_iter;
1426 char *property = NULL;
1427 GVariant *val = NULL;
1428 GVariant *child = NULL;
1430 g_variant_iter_init(&value_iter, msg);
1431 while ((child = g_variant_iter_next_value(&value_iter))) {
1432 g_variant_get(child, "{sv}", &property, &val);
1433 ret_if(property == NULL);
1435 if (strcasecmp(property, "Status") == 0) {
1436 char *status = NULL;
1437 g_variant_get(val, "s", &status);
1438 BT_DBG("Status is %s", status);
1440 if (strcasecmp(status, "active") == 0)
1441 _bt_obex_client_started(path);
1442 else if (strcasecmp(status, "complete") == 0)
1443 _bt_obex_client_completed(path, TRUE);
1444 else if (strcasecmp(status, "error") == 0)
1445 _bt_obex_client_completed(path, FALSE);
1448 } else if (strcasecmp(property, "Transferred") == 0) {
1449 guint64 transferred = 0;
1450 g_variant_get(val, "t", &transferred);
1452 _bt_obex_client_progress(path, transferred);
1454 BT_DBG("property : [%s]", property);
1457 g_variant_unref(child);
1458 g_variant_unref(val);
1462 void _bt_opc_property_changed_event(GVariant *msg, char *path)
1464 char *interface_name = NULL;
1465 GVariant *value = NULL;
1466 g_variant_get(msg, "(&s@a{sv}@as)", &interface_name, &value, NULL);
1467 BT_INFO("interface_name = %s", interface_name);
1468 if (strcasecmp(interface_name, BT_OBEX_TRANSFER_INTERFACE) == 0) {
1469 __bt_opc_property_changed_event(value,
1472 BT_DBG("interface_name : [%s]", interface_name);
1474 g_variant_unref(value);
1478 void _bt_handle_input_event(GVariant *msg, const char *path)
1480 int result = BLUETOOTH_ERROR_NONE;
1481 gboolean property_flag = FALSE;
1482 GVariantIter value_iter;
1483 char *property = NULL;
1484 GVariant *child = NULL, *val = NULL;
1485 bt_remote_dev_info_t *remote_dev_info;
1486 GVariant *param = NULL;
1487 g_variant_iter_init(&value_iter, msg);
1488 while ((child = g_variant_iter_next_value(&value_iter))) {
1489 g_variant_get(child, "{sv}", &property, &val);
1491 ret_if(property == NULL);
1493 if (strcasecmp(property, "Connected") == 0) {
1494 int event = BLUETOOTH_EVENT_NONE;
1496 g_variant_get(val, "b", &property_flag);
1498 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1500 _bt_convert_device_path_to_address(path, address);
1502 event = (property_flag == TRUE) ?
1503 BLUETOOTH_HID_CONNECTED :
1504 BLUETOOTH_HID_DISCONNECTED;
1505 param = g_variant_new("(is)", result, address);
1506 _bt_send_event(BT_HID_EVENT, event,
1508 /* Check HID connection type (Keyboard or Mouse) and update the status */
1509 remote_dev_info = _bt_get_remote_device_info_by_object_path(path);
1511 if (property_flag == TRUE) {
1512 hid_connected_device_count++;
1513 __bt_set_device_values(TRUE,
1514 VCONFKEY_BT_DEVICE_HID_CONNECTED);
1516 hid_connected_device_count--;
1517 if (hid_connected_device_count == 0)
1518 __bt_set_device_values(FALSE,
1519 VCONFKEY_BT_DEVICE_HID_CONNECTED);
1522 if (remote_dev_info != NULL) {
1523 BT_DBG("HID device class [%x]", remote_dev_info->class);
1524 if (remote_dev_info->class &
1525 BLUETOOTH_DEVICE_MINOR_CLASS_KEY_BOARD) {
1526 __bt_set_device_values(property_flag,
1527 VCONFKEY_BT_DEVICE_HID_KEYBOARD_CONNECTED);
1531 if (remote_dev_info->class &
1532 BLUETOOTH_DEVICE_MINOR_CLASS_POINTING_DEVICE) {
1533 __bt_set_device_values(property_flag,
1534 VCONFKEY_BT_DEVICE_HID_MOUSE_CONNECTED);
1536 _bt_free_device_info(remote_dev_info);
1541 g_variant_unref(val);
1542 g_variant_unref(child);
1546 void _bt_handle_network_server_event(GVariant *msg, const char *member)
1548 int result = BLUETOOTH_ERROR_NONE;
1549 char *address = NULL;
1550 char *device = NULL;
1551 GVariant *param = NULL;
1552 ret_if(member == NULL);
1553 if (strcasecmp(member, "PeerConnected") == 0) {
1554 g_variant_get(msg, "(ss)", &device, &address);
1556 __bt_set_device_values(TRUE,
1557 VCONFKEY_BT_DEVICE_PAN_CONNECTED);
1558 param = g_variant_new("(iss)", result, device, address);
1559 _bt_send_event(BT_NETWORK_EVENT, BLUETOOTH_EVENT_NETWORK_SERVER_CONNECTED,
1563 nap_connected_device_count++;
1564 } else if (strcasecmp(member, "PeerDisconnected") == 0) {
1565 g_variant_get(msg, "(ss)", &device, &address);
1566 nap_connected_device_count--;
1567 if (nap_connected_device_count == 0)
1568 __bt_set_device_values(FALSE,
1569 VCONFKEY_BT_DEVICE_PAN_CONNECTED);
1570 param = g_variant_new("(iss)", result, device, address);
1571 _bt_send_event(BT_NETWORK_EVENT, BLUETOOTH_EVENT_NETWORK_SERVER_DISCONNECTED,
1578 void _bt_handle_network_client_event(GVariant *msg,
1583 int result = BLUETOOTH_ERROR_NONE;
1584 gboolean property_flag = FALSE;
1585 char *property = NULL;
1586 GVariant *val = NULL;
1587 GVariantIter value_iter;
1588 GVariant *param = NULL;
1589 g_variant_iter_init(&value_iter, msg);
1590 while ((g_variant_iter_loop(&value_iter, "{sv}", &property, &val))) {
1591 if (strcasecmp(property, "Connected") == 0) {
1592 int event = BLUETOOTH_EVENT_NONE;
1595 g_variant_get(val, "b", &property_flag);
1596 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1598 _bt_convert_device_path_to_address(path, address);
1600 BT_DBG("property_flag %d", property_flag);
1601 if (property_flag == TRUE) {
1602 event = BLUETOOTH_EVENT_NETWORK_CONNECTED;
1603 nap_connected_device_count++;
1604 __bt_set_device_values(TRUE,
1605 VCONFKEY_BT_DEVICE_PAN_CONNECTED);
1607 event = BLUETOOTH_EVENT_NETWORK_DISCONNECTED;
1608 nap_connected_device_count--;
1609 if (nap_connected_device_count == 0)
1610 __bt_set_device_values(FALSE,
1611 VCONFKEY_BT_DEVICE_PAN_CONNECTED);
1613 param = g_variant_new("(is)", result, address);
1614 _bt_send_event(BT_NETWORK_EVENT, event,
1623 void __bt_gatt_char_property_changed_event(GVariant *msg,
1626 GVariantIter value_iter;
1627 char *property = NULL;
1628 char * char_handle = NULL;
1629 GVariant *val = NULL;
1630 int result = BLUETOOTH_ERROR_NONE;
1631 GVariant *param = NULL;
1632 g_variant_iter_init(&value_iter, msg);
1633 char_handle = g_strdup(path);
1634 while ((g_variant_iter_loop(&value_iter, "{sv}", &property, &val))) {
1635 BT_DBG("Property %s", property);
1637 ret_if(property == NULL);
1639 if (strcasecmp(property, "Notifying") == 0) {
1640 gboolean property_flag = FALSE;
1641 g_variant_get(val, "b", &property_flag);
1642 BT_INFO("Notifying is %s", property_flag ? "enabled" : "disabled");
1643 } else if (strcasecmp(property, "ChangedValue") == 0) {
1645 GByteArray *gp_byte_array = NULL;
1646 BT_INFO("Type '%s'\n", g_variant_get_type_string(val));
1649 gp_byte_array = g_byte_array_new();
1650 len = g_variant_get_size(val);
1651 BT_DBG("Len = %d", len);
1652 g_byte_array_append(gp_byte_array,
1653 (const guint8 *) g_variant_get_data(val), len);
1654 if (gp_byte_array->len != 0) {
1655 GVariant *byte_array = NULL;
1656 byte_array = g_variant_new_from_data(
1657 G_VARIANT_TYPE_BYTESTRING,
1658 gp_byte_array->data,
1661 param = g_variant_new("(is@ay)", result, char_handle,
1664 /* Send event only registered client */
1665 _bt_send_char_value_changed_event(param);
1667 g_byte_array_free(gp_byte_array, TRUE);
1671 g_free(char_handle);
1674 void _bt_handle_gatt_event(GVariant *msg, const char *member, const char *path)
1676 ret_if(path == NULL);
1678 if (strcasecmp(member, "GattValueChanged") == 0) {
1681 /*** Debug only ***/
1682 GVariant *value = NULL;
1684 char *buffer = NULL;
1686 g_variant_get(msg, "(is@ay)", NULL, NULL, &value);
1687 value_len = g_variant_get_size(value);
1688 if (value_len > 0) {
1689 char buf[8 * 5 + 1] = { 0 };
1692 buffer = (char *)g_variant_get_data(value);
1693 to = value_len > (sizeof(buf) / 5) ? sizeof(buf) / 5 : value_len;
1695 for (i = 0; i < to; i++)
1696 snprintf(&buf[i * 5], 6, "0x%02x ", buffer[i]);
1698 BT_DBG("GATT Val[%d] %s", value_len, buf);
1700 g_variant_unref(value);
1704 /* Send event only registered client */
1705 _bt_send_char_value_changed_event(msg);
1710 void _bt_handle_device_event(GVariant *msg, const char *member, const char *path)
1713 int result = BLUETOOTH_ERROR_NONE;
1715 char *dev_name = NULL;
1716 const char *property = NULL;
1717 GVariant *param = NULL;
1718 char secure_address[BT_ADDRESS_STRING_SIZE] = { 0 };
1719 ret_if(path == NULL);
1721 if (strcasecmp(member, "PropertyChanged") == 0) {
1723 g_variant_get(msg, "(s)", &property);
1725 ret_if(property == NULL);
1727 if (strcasecmp(property, "GattConnected") == 0) {
1728 gboolean connected = FALSE;
1730 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1732 _bt_convert_device_path_to_address(path, address);
1733 g_variant_get(msg, "(b)", &connected);
1735 event = connected ? BLUETOOTH_EVENT_GATT_CONNECTED :
1736 BLUETOOTH_EVENT_GATT_DISCONNECTED;
1737 param = g_variant_new("(is)", result, address);
1738 _bt_send_event(BT_DEVICE_EVENT,
1742 } else if (strcasecmp(property, "Paired") == 0) {
1743 gboolean paired = FALSE;
1744 bt_remote_dev_info_t *remote_dev_info;
1745 g_variant_get(msg, "(b)", &paired);
1747 ret_if(paired == FALSE);
1749 /* BlueZ sends paired signal for each paired device */
1750 /* during activation, We should ignore this, otherwise*/
1751 /* application thinks that a new device got paired */
1752 if (_bt_adapter_get_status() != BT_ACTIVATED) {
1753 BT_DBG("BT is not activated, so ignore this");
1757 if (_bt_is_device_creating() == TRUE) {
1758 BT_DBG("Try to Pair by me");
1762 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1764 _bt_convert_device_path_to_address(path, address);
1766 remote_dev_info = _bt_get_remote_device_info_by_object_path(path);
1767 if (remote_dev_info == NULL) {
1771 GVariant *uuids = NULL;
1772 GVariantBuilder *builder = NULL;
1774 builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
1775 for (i = 0; i < remote_dev_info->uuid_count; i++) {
1776 g_variant_builder_add(builder, "s",
1777 remote_dev_info->uuids[i]);
1779 uuids = g_variant_new("as", builder);
1780 g_variant_builder_unref(builder);
1781 GVariant *manufacturer_data = NULL;
1782 manufacturer_data = g_variant_new_from_data(
1783 G_VARIANT_TYPE_BYTESTRING,
1784 remote_dev_info->manufacturer_data,
1785 remote_dev_info->manufacturer_data_len,
1787 param = g_variant_new("(isunsbub@asn@ay)", result,
1789 remote_dev_info->class,
1790 remote_dev_info->rssi,
1791 remote_dev_info->name,
1792 remote_dev_info->paired,
1793 remote_dev_info->connected,
1794 remote_dev_info->trust,
1796 remote_dev_info->manufacturer_data_len,
1798 _bt_send_event(BT_ADAPTER_EVENT,
1799 BLUETOOTH_EVENT_BONDING_FINISHED,
1801 _bt_free_device_info(remote_dev_info);
1804 } else if (strcasecmp(property, "UUIDs") == 0) {
1805 /* Once we get the updated uuid information after
1806 * reverse service search, update it to application */
1808 bt_remote_dev_info_t *remote_dev_info;
1810 ret_if(_bt_is_device_creating() == TRUE);
1812 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1814 _bt_convert_device_path_to_address(path, address);
1816 remote_dev_info = _bt_get_remote_device_info_by_object_path(path);
1817 if (remote_dev_info == NULL) {
1822 BT_DBG("UUID's count = %d", remote_dev_info->uuid_count);
1823 if (remote_dev_info->paired && remote_dev_info->uuid_count) {
1824 GVariant *uuids = NULL;
1825 GVariantBuilder *builder = NULL;
1827 builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
1828 for (i = 0; i < remote_dev_info->uuid_count; i++) {
1829 g_variant_builder_add(builder, "s",
1830 remote_dev_info->uuids[i]);
1832 uuids = g_variant_new("as", builder);
1833 g_variant_builder_unref(builder);
1834 GVariant *manufacture_data = g_variant_new_from_data((const GVariantType *)"ay",
1835 remote_dev_info->manufacturer_data, remote_dev_info->manufacturer_data_len,
1838 param = g_variant_new("(isunsbub@asn@ay)", result,
1839 address, remote_dev_info->class,
1840 remote_dev_info->rssi,
1841 remote_dev_info->name,
1842 remote_dev_info->paired,
1843 remote_dev_info->connected,
1844 remote_dev_info->trust,
1846 remote_dev_info->manufacturer_data_len,
1848 _bt_send_event(BT_ADAPTER_EVENT,
1849 BLUETOOTH_EVENT_SERVICE_SEARCHED,
1853 _bt_free_device_info(remote_dev_info);
1856 } else if (strcasecmp(member, "DeviceConnected") == 0) {
1857 unsigned char addr_type = 0;
1859 g_variant_get(msg, "(y)", &addr_type);
1861 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1863 _bt_convert_device_path_to_address(path, address);
1864 dev_name = _bt_get_device_name(address);
1866 _bt_convert_addr_string_to_secure_string(secure_address, address);
1867 BT_INFO("Address : %s Type : %d", secure_address, addr_type);
1868 BT_ERR_C("### Connected [%s] [%s]", !addr_type ? "BREDR" : "LE",
1869 !addr_type ? dev_name : secure_address);
1873 _bt_add_le_connected_dev_info(address);
1875 _bt_logging_connection(TRUE, addr_type);
1876 param = g_variant_new("(isy)", result, address, addr_type);
1877 /*Send event to application*/
1878 _bt_send_event(BT_DEVICE_EVENT,
1879 BLUETOOTH_EVENT_DEVICE_CONNECTED,
1882 } else if (strcasecmp(member, "Disconnected") == 0) {
1883 unsigned char disc_reason = 0;
1884 unsigned char addr_type = 0;
1885 char *dev_name = NULL;
1886 gboolean sending = FALSE;
1888 g_variant_get(msg, "(yys)", &addr_type, &disc_reason, &dev_name);
1890 result = disc_reason;
1892 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1894 _bt_convert_device_path_to_address(path, address);
1896 /* 0x00 BDADDR_BRDER
1897 0x01 BDADDR_LE_PUBLIC
1898 0x02 BDADDR_LE_RANDOM */
1899 _bt_convert_addr_string_to_secure_string(secure_address, address);
1900 BT_INFO("Address : %s Type : %d", secure_address, addr_type);
1901 BT_ERR_C("### Disconnected [%s] [%s] [%d : %s]", !addr_type ? "BREDR" : "LE",
1902 !addr_type ? dev_name : secure_address,
1903 disc_reason, _bt_convert_disc_reason_to_string(disc_reason));
1906 _bt_headset_set_local_connection(FALSE);
1907 _bt_logging_connection(FALSE, addr_type);
1910 _bt_remove_le_connected_dev_info(address);
1912 #ifdef TIZEN_BT_A2DP_SINK_AUTO_CONNECT
1914 int bt_device_state = VCONFKEY_BT_DEVICE_NONE;
1916 if (vconf_get_int(VCONFKEY_BT_DEVICE, &bt_device_state) != 0)
1917 BT_ERR("vconf_get_int failed");
1919 BT_INFO("conn_state[0x%x], adapter_state [%d]",
1920 bt_device_state, _bt_adapter_get_status());
1922 if (disc_reason == BLUETOOTH_ERROR_CONNECTION_TIMEOUT) {
1923 _bt_audio_start_auto_connect(TRUE);
1924 } else if (bt_device_state &
1925 VCONFKEY_BT_DEVICE_A2DP_SOURCE_CONNECTED) {
1926 BT_INFO("Disconnected due to turning BT off. Skip a address");
1928 char *last_connected = NULL;
1929 last_connected = vconf_get_str(BT_LAST_CONNECTED_DEVICE);
1930 if (!g_strcmp0(address, last_connected))
1931 _bt_audio_set_auto_connect_device_addr("");
1933 free(last_connected);
1938 /*Check for any OPP transfer on the device and cancel
1941 _bt_obex_check_pending_transfer(address);
1942 _bt_opp_client_is_sending(&sending);
1943 if (sending == TRUE)
1944 _bt_opp_client_check_pending_transfer(address);
1946 param = g_variant_new("(isy)", result, address, addr_type);
1947 _bt_send_event(BT_DEVICE_EVENT,
1948 BLUETOOTH_EVENT_DEVICE_DISCONNECTED,
1951 } else if (strcasecmp(member, "ProfileStateChanged") == 0) {
1953 char *profile_uuid = NULL;
1954 bt_headset_wait_t *wait_list;
1955 bluetooth_device_address_t bd_addr;
1957 g_variant_get(msg, "(si)", &profile_uuid, &state);
1959 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1961 _bt_convert_device_path_to_address(path, address);
1962 _bt_convert_addr_string_to_type(bd_addr.addr, address);
1964 _bt_convert_addr_string_to_secure_string(secure_address, address);
1965 BT_INFO_C("[%s] state: %s, addr: %s",
1966 _bt_convert_uuid_to_string(profile_uuid),
1967 _bt_convert_profile_state_to_string(state), secure_address);
1969 if ((strcmp(profile_uuid, A2DP_SINK_UUID) == 0) &&
1970 (state == BT_PROFILE_STATE_CONNECTED)) {
1972 int event = BLUETOOTH_EVENT_AV_CONNECTED;
1973 char connected_address[BT_ADDRESS_STRING_SIZE + 1];
1974 bluetooth_device_address_t device_address;
1976 bt_headset_wait_t *wait_list;
1977 guint restricted = 0x0;
1979 __bt_set_device_values(TRUE,
1980 VCONFKEY_BT_DEVICE_A2DP_HEADSET_CONNECTED);
1982 __bt_connection_manager_set_state(address, event);
1984 _bt_get_restrict_profile(&bd_addr, RESTRICTED_PROFILE_HFP_HS, &restricted);
1986 if (_bt_headset_get_local_connection() == FALSE) {
1987 if (restricted == 0x0) /* not restricted*/
1988 _bt_start_timer_for_connection(address, BT_AUDIO_HSP);
1990 /* Connection Started from local device therefore no need to
1991 * intiate connection for pending profile */
1992 _bt_headset_set_local_connection(FALSE);
1994 param = g_variant_new("(is)", result, address);
1995 _bt_send_event(BT_HEADSET_EVENT, event,
1997 connected = _bt_is_headset_type_connected(BT_AUDIO_A2DP,
2000 if (g_strcmp0(connected_address, address) != 0) {
2001 _bt_convert_addr_string_to_type(
2002 device_address.addr,
2004 _bt_audio_disconnect(0, BT_AUDIO_A2DP,
2005 &device_address, NULL);
2009 _bt_add_headset_to_list(BT_AUDIO_A2DP,
2010 BT_STATE_CONNECTED, address);
2012 wait_list = _bt_get_audio_wait_data();
2013 if (wait_list != NULL &&
2014 (g_strcmp0(wait_list->address, address) == 0))
2015 _bt_rel_wait_data();
2017 } else if ((strcmp(profile_uuid, A2DP_SINK_UUID) == 0) &&
2018 (state == BT_PROFILE_STATE_DISCONNECTED)) {
2020 int event = BLUETOOTH_EVENT_AV_DISCONNECTED;
2022 if (!_bt_is_service_connected(address, BT_AUDIO_A2DP)) {
2024 g_free(profile_uuid);
2028 __bt_set_device_values(FALSE,
2029 VCONFKEY_BT_DEVICE_A2DP_HEADSET_CONNECTED);
2031 __bt_connection_manager_set_state(address, event);
2032 param = g_variant_new("(is)", result, address);
2033 _bt_send_event(BT_HEADSET_EVENT, event,
2035 /* Remove data from the connected list */
2036 _bt_remove_headset_from_list(BT_AUDIO_A2DP, address);
2037 wait_list = _bt_get_audio_wait_data();
2039 if (wait_list == NULL) {
2041 g_free(profile_uuid);
2045 if (((wait_list->type == BT_AUDIO_ALL) &&
2046 (wait_list->ag_flag == TRUE)) ||
2047 (wait_list->type == BT_AUDIO_A2DP) ||
2048 (wait_list->disconnection_type == BT_AUDIO_A2DP)) {
2049 bluetooth_device_address_t device_address;
2050 _bt_convert_addr_string_to_type(
2051 device_address.addr,
2052 wait_list->address);
2054 _bt_audio_connect(wait_list->req_id,
2059 } else if (strcmp(profile_uuid, AVRCP_TARGET_UUID) == 0) {
2061 if (state == BT_PROFILE_STATE_CONNECTED) {
2062 int event = BLUETOOTH_EVENT_AVRCP_CONTROL_CONNECTED;
2063 char connected_address[BT_ADDRESS_STRING_SIZE + 1];
2064 bluetooth_device_address_t device_address;
2066 param = g_variant_new("(is)", result, address);
2067 _bt_send_event(BT_AVRCP_CONTROL_EVENT, event,
2069 connected = _bt_is_headset_type_connected(
2073 if (g_strcmp0(connected_address,
2075 _bt_convert_addr_string_to_type(
2076 device_address.addr,
2078 _bt_audio_disconnect(0,
2080 &device_address, NULL);
2083 BT_DBG("device Path: %s", path);
2084 _bt_add_headset_to_list(BT_AVRCP,
2085 BT_STATE_CONNECTED, address);
2086 } else if (state == BT_PROFILE_STATE_DISCONNECTED) {
2087 int event = BLUETOOTH_EVENT_AVRCP_CONTROL_DISCONNECTED;
2088 param = g_variant_new("(is)", result, address);
2089 _bt_send_event(BT_AVRCP_CONTROL_EVENT, event,
2091 /* Remove data from the connected list */
2092 _bt_remove_headset_from_list(BT_AVRCP, address);
2094 } else if (strcasecmp(profile_uuid, A2DP_SOURCE_UUID) == 0) {
2095 if (state == BT_PROFILE_STATE_CONNECTED) {
2096 int event = BLUETOOTH_EVENT_AV_SOURCE_CONNECTED;
2097 BT_INFO("A2DP Source is connected");
2098 #ifdef TIZEN_BT_A2DP_SINK_ENABLE
2099 __bt_set_device_values(TRUE,
2100 VCONFKEY_BT_DEVICE_A2DP_SOURCE_CONNECTED);
2103 #ifdef TIZEN_BT_A2DP_SINK_AUTO_CONNECT
2104 _bt_audio_set_auto_connect_device_addr(address);
2105 _bt_audio_stop_auto_connect();
2107 _bt_add_headset_to_list(BT_AUDIO_A2DP_SOURCE,
2108 BT_STATE_CONNECTED, address);
2109 _bt_send_event(BT_A2DP_SOURCE_EVENT, event,
2110 g_variant_new("(is)", result, address));
2111 } else if (state == BT_PROFILE_STATE_DISCONNECTED) {
2112 int event = BLUETOOTH_EVENT_AV_SOURCE_DISCONNECTED;
2113 BT_INFO("A2DP Source Disconnected");
2114 #ifdef TIZEN_BT_A2DP_SINK_ENABLE
2115 __bt_set_device_values(FALSE,
2116 VCONFKEY_BT_DEVICE_A2DP_SOURCE_CONNECTED);
2118 _bt_remove_headset_from_list(BT_AUDIO_A2DP_SOURCE, address);
2119 _bt_send_event(BT_A2DP_SOURCE_EVENT, event,
2120 g_variant_new("(is)", result, address));
2122 wait_list = _bt_get_audio_wait_data();
2123 if (wait_list && wait_list->type == BT_AUDIO_A2DP_SOURCE) {
2124 bluetooth_device_address_t device_address;
2125 _bt_convert_addr_string_to_type(
2126 device_address.addr,
2127 wait_list->address);
2129 _bt_audio_connect(wait_list->req_id,
2133 /* Now free the wait list */
2134 _bt_rel_wait_data();
2137 } else if ((strcmp(profile_uuid, HID_UUID) == 0) &&
2138 ((state == BT_PROFILE_STATE_CONNECTED) ||
2139 (state == BT_PROFILE_STATE_DISCONNECTED))) {
2141 if (state == BT_PROFILE_STATE_CONNECTED)
2142 event = BLUETOOTH_HID_CONNECTED;
2144 event = BLUETOOTH_HID_DISCONNECTED;
2145 param = g_variant_new("(is)", result, address);
2146 _bt_send_event(BT_HID_EVENT, event,
2148 } else if (strcmp(profile_uuid, HID_DEVICE_UUID) == 0) {
2149 if (state == BT_PROFILE_STATE_CONNECTED) {
2151 event = BLUETOOTH_HID_DEVICE_CONNECTED;
2152 param = g_variant_new("(is)", result, address);
2153 _bt_send_event(BT_HID_DEVICE_EVENT, event,
2155 } else if (state == BT_PROFILE_STATE_DISCONNECTED) {
2156 event = BLUETOOTH_HID_DEVICE_DISCONNECTED;
2157 param = g_variant_new("(is)", result, address);
2158 _bt_send_event(BT_HID_DEVICE_EVENT, event,
2163 g_free(profile_uuid);
2164 } else if (strcasecmp(member, "AdvReport") == 0) {
2166 bt_remote_le_dev_info_t *le_dev_info = NULL;
2167 char *buffer = NULL;
2169 bt_le_adv_info_t *adv_info = NULL;
2170 GVariant *value = NULL;
2171 ret_if(_bt_is_le_scanning() == FALSE);
2173 le_dev_info = g_malloc0(sizeof(bt_remote_le_dev_info_t));
2175 g_variant_get(msg, "(&syyii@ay)", &le_dev_info->address,
2176 &le_dev_info->addr_type,
2177 &le_dev_info->adv_type,
2179 &le_dev_info->adv_data_len,
2181 if (value == NULL) {
2182 _bt_free_le_device_info(le_dev_info);
2186 _bt_convert_device_path_to_address(path, le_dev_info->address);
2188 buffer_len = g_variant_get_size(value);
2190 buffer = (char *)g_variant_get_data(value);
2192 le_dev_info->adv_data = g_memdup(buffer, buffer_len);
2193 if (le_dev_info->adv_data == NULL &&
2194 le_dev_info->adv_type != BT_LE_ADV_SCAN_RSP) {
2195 _bt_free_le_device_info(le_dev_info);
2196 g_variant_unref(value);
2200 if (_bt_get_le_scan_type() == BT_LE_PASSIVE_SCAN) {
2201 _bt_send_scan_result_event(le_dev_info, NULL);
2202 _bt_free_le_device_info(le_dev_info);
2203 g_variant_unref(value);
2207 if (le_dev_info->adv_type != BT_LE_ADV_SCAN_RSP) { /* ADV_IND */
2208 adv_info = g_malloc0(sizeof(bt_le_adv_info_t));
2209 adv_info->addr = g_strdup(le_dev_info->address);
2210 adv_info->addr_type = le_dev_info->addr_type;
2211 adv_info->rssi = le_dev_info->rssi;
2212 adv_info->data_len = le_dev_info->adv_data_len;
2213 adv_info->data = g_malloc0(le_dev_info->adv_data_len);
2214 memcpy(adv_info->data, le_dev_info->adv_data,
2215 le_dev_info->adv_data_len);
2217 if (__bt_add_adv_ind_info(adv_info) == 0) {
2218 adv_info->timer_id = g_timeout_add(1000,
2219 (GSourceFunc)__bt_adv_scan_req_timeout_cb, (void*)adv_info);
2221 } else { /* SCAN_RSP */
2222 adv_info = __bt_get_adv_ind_info(le_dev_info->address);
2224 _bt_send_scan_result_event(le_dev_info, adv_info);
2225 __bt_del_adv_ind_info(le_dev_info->address);
2228 _bt_free_le_device_info(le_dev_info);
2229 g_variant_unref(value);
2230 } else if (strcasecmp(member, "LEDataLengthChanged") == 0) {
2231 guint16 tx_octets = 0;
2232 guint16 tx_time = 0;
2233 guint16 rx_octets = 0;
2234 guint16 rx_time = 0;
2236 g_variant_get(msg, "(qqqq)",
2237 &tx_octets, &tx_time, &rx_octets, &rx_time);
2239 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
2240 _bt_convert_device_path_to_address(path, address);
2242 param = g_variant_new("(isqqqq)", result, address, tx_octets, tx_time,
2243 rx_octets, rx_time);
2244 /* Send event to application */
2245 _bt_send_event(BT_DEVICE_EVENT,
2246 BLUETOOTH_EVENT_LE_DATA_LENGTH_CHANGED, param);
2248 } else if (strcasecmp(member, "IpspStateChanged") == 0) {
2249 gboolean connected = FALSE;
2250 char *ifname = NULL;
2252 g_variant_get(msg, "(bs)", &connected, &ifname);
2254 event = connected ? BLUETOOTH_EVENT_IPSP_CONNECTED :
2255 BLUETOOTH_EVENT_IPSP_DISCONNECTED;
2257 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
2258 _bt_convert_device_path_to_address(path, address);
2260 BT_DBG("Ipsp BT Interface Name: %s", ifname);
2261 BT_DBG("address: %s", address);
2262 param = g_variant_new("(iss)", result, address, ifname);
2264 /* Send event to application */
2265 _bt_send_event(BT_DEVICE_EVENT,
2269 } else if (strcasecmp(member, "iBeaconReport") == 0) {
2270 bt_remote_ibeacon_dev_info_t *ibeacon_dev_info = NULL;
2272 ret_if(_bt_is_le_scanning() == FALSE);
2274 ibeacon_dev_info = g_malloc0(sizeof(bt_remote_ibeacon_dev_info_t));
2276 g_variant_get(msg, "(syuusuuy)", &ibeacon_dev_info->address,
2277 &ibeacon_dev_info->addr_type,
2278 &ibeacon_dev_info->company_id,
2279 &ibeacon_dev_info->ibeacon_type,
2280 &ibeacon_dev_info->uuid,
2281 &ibeacon_dev_info->major_id,
2282 &ibeacon_dev_info->minor_id,
2283 &ibeacon_dev_info->measured_power);
2284 _bt_send_ibeacon_scan_result_event(ibeacon_dev_info);
2285 g_free(ibeacon_dev_info);
2289 void __bt_set_audio_values(gboolean connected, char *address)
2292 int bt_device_state = VCONFKEY_BT_DEVICE_NONE;
2294 /* Set the headset name */
2295 if (connected == TRUE)
2296 name = _bt_get_device_name(address);
2298 name = g_strdup("");
2300 if (vconf_set_str(VCONFKEY_BT_HEADSET_NAME, name) != 0)
2301 BT_ERR("vconf_set_str failed");
2305 /* Set the headset state */
2306 if (vconf_get_int(VCONFKEY_BT_DEVICE, &bt_device_state) != 0)
2307 BT_ERR("vconf_get_int failed");
2309 #ifdef TIZEN_SUPPORT_DUAL_HF
2310 if ((connected == TRUE) &&
2311 (FALSE == __bt_is_companion_device(address))) {
2312 bt_device_state |= VCONFKEY_BT_DEVICE_HEADSET_CONNECTED;
2313 } else if ((bt_device_state & VCONFKEY_BT_DEVICE_HEADSET_CONNECTED) &&
2314 (FALSE == __bt_is_companion_device(address))) {
2315 bt_device_state ^= VCONFKEY_BT_DEVICE_HEADSET_CONNECTED;
2318 if (connected == TRUE)
2319 bt_device_state |= VCONFKEY_BT_DEVICE_HEADSET_CONNECTED;
2320 else if (bt_device_state & VCONFKEY_BT_DEVICE_HEADSET_CONNECTED)
2321 bt_device_state ^= VCONFKEY_BT_DEVICE_HEADSET_CONNECTED;
2324 if (vconf_set_int(VCONFKEY_BT_DEVICE,
2325 bt_device_state) != 0) {
2326 BT_ERR("vconf_set_int failed");
2330 void _bt_handle_headset_event(GVariant *msg, const char *path)
2332 int result = BLUETOOTH_ERROR_NONE;
2333 gboolean property_flag = FALSE;
2334 char *property = NULL;
2335 GVariant *value = NULL;
2336 GVariant *param = NULL;
2337 g_variant_get(msg, "(sv)", &property, &value);
2338 bluetooth_device_address_t bd_addr;
2340 ret_if(property == NULL);
2342 BT_DBG("Property = %s \n", property);
2343 /* We allow only 1 headset connection (HSP or HFP)*/
2344 if (strcasecmp(property, "Connected") == 0) {
2345 int event = BLUETOOTH_EVENT_NONE;
2346 bt_headset_wait_t *wait_list;
2348 guint restricted = 0x0;
2349 g_variant_get(value, "b", &property_flag);
2351 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
2353 _bt_convert_device_path_to_address(path, address);
2354 _bt_convert_addr_string_to_type(bd_addr.addr, address);
2356 if (property_flag == TRUE) {
2357 event = BLUETOOTH_EVENT_AG_CONNECTED;
2358 _bt_get_restrict_profile(&bd_addr, RESTRICTED_PROFILE_A2DP, &restricted);
2360 if (_bt_headset_get_local_connection() == FALSE) {
2361 if (restricted == 0x0) /* not restricted*/
2362 _bt_start_timer_for_connection(address, BT_AUDIO_A2DP);
2364 _bt_headset_set_local_connection(FALSE);
2368 event = BLUETOOTH_EVENT_AG_DISCONNECTED;
2370 previous_state = _bt_get_device_state_from_list(BT_AUDIO_HSP, address);
2371 if (previous_state == BT_STATE_DISCONNECTING)
2372 _bt_send_hf_local_term_event(address);
2374 /* Set the State machine here */
2375 __bt_connection_manager_set_state(address, event);
2376 __bt_set_audio_values(property_flag, address);
2377 param = g_variant_new("(is)", result, address);
2378 _bt_send_event(BT_HEADSET_EVENT, event,
2381 if (event == BLUETOOTH_EVENT_AG_DISCONNECTED) {
2382 /* Remove data from the connected list */
2383 _bt_remove_headset_from_list(BT_AUDIO_HSP, address);
2385 wait_list = _bt_get_audio_wait_data();
2386 if (wait_list == NULL) {
2391 bluetooth_device_address_t device_address;
2393 _bt_set_audio_wait_data_flag(TRUE);
2395 _bt_convert_addr_string_to_type(device_address.addr,
2396 wait_list->address);
2397 _bt_audio_connect(wait_list->req_id, wait_list->type,
2398 &device_address, NULL);
2399 _bt_rel_wait_data();
2400 } else if (event == BLUETOOTH_EVENT_AG_CONNECTED) {
2401 /* Add data to the connected list */
2402 _bt_add_headset_to_list(BT_AUDIO_HSP,
2403 BT_STATE_CONNECTED, address);
2405 wait_list = _bt_get_audio_wait_data();
2406 if (wait_list != NULL &&
2407 (g_strcmp0(wait_list->address, address) == 0))
2408 _bt_rel_wait_data();
2410 BT_INFO("Check A2DP pending connect");
2411 _bt_audio_check_pending_connect();
2414 } else if (strcasecmp(property, "State") == 0) {
2417 g_variant_get(value, "s", &state);
2419 /* This code assumes we support only 1 headset connection */
2420 /* Need to use the headset list, if we support multi-headsets */
2421 if (strcasecmp(state, "Playing") == 0) {
2422 BT_DBG("Playing: Sco Connected");
2423 } else if (strcasecmp(state, "connected") == 0 ||
2424 strcasecmp(state, "disconnected") == 0) {
2425 BT_DBG("connected/disconnected: Sco Disconnected");
2427 BT_ERR("Not handled state - %s", state);
2432 } else if (strcasecmp(property, "SpeakerGain") == 0) {
2436 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
2438 _bt_convert_device_path_to_address(path, address);
2440 spkr_gain = g_variant_get_uint16(value);
2442 BT_DBG("spkr_gain: %d", spkr_gain);
2444 param = g_variant_new("(i&sq)", result, address, spkr_gain);
2445 _bt_send_event(BT_HEADSET_EVENT, BLUETOOTH_EVENT_AG_SPEAKER_GAIN,
2449 } else if (strcasecmp(property, "MicrophoneGain") == 0) {
2453 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
2455 _bt_convert_device_path_to_address(path, address);
2457 mic_gain = g_variant_get_uint16(value);
2459 param = g_variant_new("(i&sq)", result, address, mic_gain);
2460 _bt_send_event(BT_HEADSET_EVENT, BLUETOOTH_EVENT_AG_MIC_GAIN,
2467 g_variant_unref(value);
2470 void _bt_handle_sink_event(GVariant *msg, const char *path)
2472 GVariantIter value_iter;
2473 char *property = NULL;
2475 bt_headset_wait_t *wait_list;
2477 GVariant *child = NULL;
2478 GVariant *val = NULL;
2479 GVariant *param = NULL;
2480 g_variant_iter_init(&value_iter, msg);
2481 while ((child = g_variant_iter_next_value(&value_iter))) {
2483 g_variant_get(child, "{sv}", &property, &val);
2485 ret_if(property == NULL);
2487 BT_DBG("Property = %s \n", property);
2490 if (strcasecmp(property, "State") == 0) {
2491 int result = BLUETOOTH_ERROR_NONE;
2494 g_variant_get(val, "s", &value);
2495 BT_DBG("value: %s", value);
2497 if (g_strcmp0(value, "disconnected") == 0) {
2500 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
2502 _bt_convert_device_path_to_address(path, address);
2504 __bt_set_device_values(FALSE,
2505 VCONFKEY_BT_DEVICE_A2DP_HEADSET_CONNECTED);
2506 param = g_variant_new("(is)", result, address);
2507 _bt_send_event(BT_HEADSET_EVENT,
2508 BLUETOOTH_EVENT_AV_DISCONNECTED,
2511 /* Remove data from the connected list */
2512 _bt_remove_headset_from_list(BT_AUDIO_A2DP, address);
2513 wait_list = _bt_get_audio_wait_data();
2514 if (wait_list == NULL) {
2517 g_variant_unref(val);
2518 g_variant_unref(child);
2523 if (((wait_list->type == BT_AUDIO_ALL) &&
2524 (wait_list->ag_flag == TRUE)) ||
2525 (wait_list->type == BT_AUDIO_A2DP) ||
2526 (wait_list->disconnection_type == BT_AUDIO_A2DP)) {
2527 bluetooth_device_address_t device_address;
2528 _bt_convert_addr_string_to_type(
2529 device_address.addr,
2530 wait_list->address);
2532 _bt_audio_connect(wait_list->req_id,
2538 } else if (strcasecmp(value, "Connected") == 0) {
2540 char connected_address[BT_ADDRESS_STRING_SIZE + 1];
2541 bluetooth_device_address_t device_address;
2544 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
2546 _bt_convert_device_path_to_address(path, address);
2548 __bt_set_device_values(TRUE,
2549 VCONFKEY_BT_DEVICE_A2DP_HEADSET_CONNECTED);
2550 param = g_variant_new("(is)", result, address);
2551 _bt_send_event(BT_HEADSET_EVENT,
2552 BLUETOOTH_EVENT_AV_CONNECTED,
2554 /* Check for existing Media device to disconnect */
2555 connected = _bt_is_headset_type_connected(BT_AUDIO_A2DP,
2558 /* Match connected device address */
2559 if (g_strcmp0(connected_address, address) != 0) {
2560 /* Convert BD adress from string type */
2561 _bt_convert_addr_string_to_type(
2562 device_address.addr,
2564 _bt_audio_disconnect(0, BT_AUDIO_A2DP,
2565 &device_address, NULL);
2569 /* Add data to the connected list */
2570 _bt_add_headset_to_list(BT_AUDIO_A2DP,
2571 BT_STATE_CONNECTED, address);
2578 g_variant_unref(val);
2579 g_variant_unref(child);
2583 void _bt_handle_agent_event(GVariant *msg, const char *member)
2585 int result = BLUETOOTH_ERROR_NONE;
2586 char *address = NULL;
2589 GVariant *param = NULL;
2590 ret_if(member == NULL);
2592 if (strcasecmp(member, "ObexAuthorize") == 0) {
2593 __bt_get_agent_signal_info(msg, &address, &name, &uuid);
2594 param = g_variant_new("(iss)", result, address, name);
2595 _bt_send_event(BT_OPP_SERVER_EVENT,
2596 BLUETOOTH_EVENT_OBEX_SERVER_CONNECTION_AUTHORIZE,
2600 } else if (strcasecmp(member, "RfcommAuthorize") == 0) {
2601 bt_rfcomm_server_info_t *server_info;
2603 __bt_get_agent_signal_info(msg, &address, &name, &uuid);
2605 server_info = _bt_rfcomm_get_server_info_using_uuid(uuid);
2606 ret_if(server_info == NULL);
2607 ret_if(server_info->server_type != BT_CUSTOM_SERVER);
2608 param = g_variant_new("(isssn)", result, address, uuid, name,
2609 server_info->control_fd);
2610 _bt_send_event(BT_RFCOMM_SERVER_EVENT,
2611 BLUETOOTH_EVENT_RFCOMM_AUTHORIZE,
2619 static int __bt_get_object_path(GVariant *msg, char **path)
2621 g_variant_get(msg, "(o*)", path, NULL);
2623 return BLUETOOTH_ERROR_INTERNAL;
2625 return BLUETOOTH_ERROR_NONE;
2628 static void __bt_devices_list_free(void)
2630 bt_cache_info_t *cache_info;
2633 node = g_list_first(p_cache_list);
2635 while (node != NULL) {
2636 cache_info = (bt_cache_info_t *)node->data;
2637 p_cache_list = g_list_remove(p_cache_list, cache_info);
2638 __bt_free_cache_info(cache_info);
2640 node = g_list_next(node);
2644 static int __bt_parse_event(GVariant *msg)
2648 char *interface_name = NULL;
2649 GVariant *inner_iter = NULL;
2651 g_variant_iter_init(&iter, msg);
2653 while ((child = g_variant_iter_next_value(&iter))) {
2654 g_variant_get(child, "{&s@a{sv}}", &interface_name, &inner_iter);
2655 if (g_strcmp0(interface_name,
2656 BT_DEVICE_INTERFACE) == 0) {
2657 g_variant_unref(inner_iter);
2658 g_variant_unref(child);
2659 return BT_DEVICE_EVENT;
2660 } else if (g_strcmp0(interface_name,
2661 BT_MEDIATRANSPORT_INTERFACE) == 0) {
2662 g_variant_unref(inner_iter);
2663 g_variant_unref(child);
2664 return BT_MEDIA_TRANSFER_EVENT;
2665 } else if (g_strcmp0(interface_name,
2666 BT_PLAYER_CONTROL_INTERFACE) == 0) {
2667 g_variant_unref(inner_iter);
2668 g_variant_unref(child);
2669 return BT_AVRCP_CONTROL_EVENT;
2671 g_variant_unref(inner_iter);
2672 g_variant_unref(child);
2678 static void __bt_manager_event_filter(GDBusConnection *connection,
2679 const gchar *sender_name,
2680 const gchar *object_path,
2681 const gchar *interface_name,
2682 const gchar *signal_name,
2683 GVariant *parameters,
2686 bt_event_type_t bt_event = 0x00;
2687 int result = BLUETOOTH_ERROR_NONE;
2689 char *obj_path = NULL;
2690 GVariant *param = NULL;
2691 if (signal_name == NULL)
2693 if (strcasecmp(signal_name, "InterfacesAdded") == 0) {
2694 g_variant_get(parameters, "(&o@a{sa{sv}})", &obj_path, &value);
2696 if (strcasecmp(obj_path, BT_BLUEZ_HCI_PATH) == 0) {
2697 #ifdef USB_BLUETOOTH
2698 BT_DBG("Enable Adapter");
2699 _bt_enable_adapter();
2701 _bt_handle_adapter_added();
2704 bt_event = __bt_parse_event(value);
2705 if (bt_event == BT_DEVICE_EVENT) {
2706 bt_cache_info_t *cache_info;
2707 bt_remote_dev_info_t *dev_info;
2709 if (_bt_is_discovering() == FALSE &&
2710 _bt_is_le_scanning() == FALSE) {
2711 g_variant_unref(value);
2715 cache_info = g_malloc0(sizeof(bt_cache_info_t));
2717 dev_info = g_malloc0(sizeof(bt_remote_dev_info_t));
2719 cache_info->dev_info = dev_info;
2721 if (__bt_parse_interface(parameters, dev_info) == FALSE) {
2722 BT_ERR("Fail to parse the properies");
2723 __bt_free_cache_info(cache_info);
2724 g_variant_unref(value);
2728 if (dev_info->addr_type != BDADDR_BREDR) {
2729 /* Whenever emit the property changed from bluez,
2730 some property doesn't reach to bt-service.
2731 So LE device is handled as AdvReport signal */
2732 __bt_free_cache_info(cache_info);
2733 g_variant_unref(value);
2737 if (dev_info->name == NULL)
2738 /* If Remote device name is NULL or still RNR is not done
2739 * then display address as name.
2741 dev_info->name = g_strdup(dev_info->address);
2743 #ifdef TIZEN_DPM_ENABLE
2744 if (_bt_dpm_get_bluetooth_desktop_connectivity_state() ==
2746 bluetooth_device_class_t device_class;
2747 _bt_divide_device_class(&device_class, dev_info->class);
2748 BT_DBG("[%s]device_class.major_class : %d", dev_info->name, device_class.major_class);
2750 if (device_class.major_class ==
2751 BLUETOOTH_DEVICE_MAJOR_CLASS_COMPUTER) {
2752 __bt_free_cache_info(cache_info);
2753 g_variant_unref(value);
2759 GVariant *uuids = NULL;
2760 GVariantBuilder *builder = NULL;
2762 builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
2763 for (i = 0; i < dev_info->uuid_count; i++) {
2764 g_variant_builder_add(builder, "s",
2765 dev_info->uuids[i]);
2767 uuids = g_variant_new("as", builder);
2768 g_variant_builder_unref(builder);
2769 GVariant *manufacturer_data = NULL;
2770 manufacturer_data = g_variant_new_from_data(
2771 G_VARIANT_TYPE_BYTESTRING,
2772 dev_info->manufacturer_data,
2773 dev_info->manufacturer_data_len,
2775 param = g_variant_new("(isunsbub@asn@ay)", result,
2781 dev_info->connected,
2784 dev_info->manufacturer_data_len,
2786 _bt_send_event(BT_ADAPTER_EVENT,
2787 BLUETOOTH_EVENT_REMOTE_DEVICE_FOUND,
2789 p_cache_list = g_list_append(p_cache_list, cache_info);
2790 } else if (bt_event == BT_AVRCP_CONTROL_EVENT) {
2791 BT_DBG("Device path : %s ", obj_path);
2792 _bt_set_control_device_path(obj_path);
2795 g_variant_unref(value);
2796 } else if (strcasecmp(signal_name, "InterfacesRemoved") == 0) {
2797 #ifdef USB_BLUETOOTH
2798 BT_DBG("InterfacesRemoved");
2799 _bt_handle_adapter_removed();
2801 if (g_strcmp0(interface_name, BT_MEDIATRANSPORT_INTERFACE) == 0)
2802 bt_event = BT_MEDIA_TRANSFER_EVENT;
2803 else if (g_strcmp0(interface_name, BT_DEVICE_INTERFACE) == 0)
2804 bt_event = BT_DEVICE_EVENT;
2805 else if (g_strcmp0(interface_name, BT_PLAYER_CONTROL_INTERFACE) == 0)
2806 bt_event = BT_AVRCP_CONTROL_EVENT;
2808 if ((bt_event != 0) && (bt_event != BT_MEDIA_TRANSFER_EVENT)) {
2809 _bt_handle_adapter_event(parameters, signal_name);
2810 if (bt_event == BT_AVRCP_CONTROL_EVENT) {
2811 BT_INFO("Object Path %s", obj_path);
2812 _bt_remove_control_device_path(obj_path);
2815 } else if (strcasecmp(signal_name, "NameOwnerChanged") == 0) {
2818 char *previous = NULL;
2819 char *current = NULL;
2821 if (__bt_get_owner_info(parameters, &name, &previous, ¤t)) {
2822 BT_ERR("Fail to get the owner info");
2826 if (*current != '\0') {
2835 if (strcasecmp(name, BT_BLUEZ_NAME) == 0) {
2836 BT_INFO_C("### Bluetoothd is terminated");
2837 if (_bt_adapter_get_status() == BT_ACTIVATED)
2840 _bt_handle_adapter_removed();
2841 __bt_devices_list_free();
2842 _bt_service_adapter_le_deinit();
2845 _bt_obex_server_check_allocation(&value);
2847 if (value == TRUE) {
2848 /* Check if the obex server was terminated abnormally */
2849 _bt_obex_server_check_termination(name);
2852 _bt_rfcomm_server_check_existence(&value);
2854 if (value == TRUE) {
2855 /* The obex server was terminated abnormally */
2856 _bt_rfcomm_server_check_termination(name);
2859 /* Reset connection interval */
2860 _bt_remove_all_le_conn_param_info(name);
2862 /* Stop advertising started by terminated process */
2863 _bt_stop_advertising_by_terminated_process(name);
2866 _bt_stop_le_scan(name);
2871 } else if (g_strcmp0(interface_name, BT_PROPERTIES_INTERFACE) == 0) {
2872 const char *path = object_path;
2874 if (strncmp(path, BT_MEDIA_OBJECT_PATH,
2875 strlen(BT_MEDIA_OBJECT_PATH)) == 0)
2878 _bt_handle_property_changed_event(parameters, object_path);
2879 } else if (g_strcmp0(interface_name, BT_ADAPTER_INTERFACE) == 0) {
2880 _bt_handle_adapter_event(parameters, signal_name);
2881 } else if (g_strcmp0(interface_name, BT_INPUT_INTERFACE) == 0) {
2882 _bt_handle_input_event(parameters, object_path);
2883 } else if (g_strcmp0(interface_name, BT_NETWORK_SERVER_INTERFACE) == 0) {
2884 _bt_handle_network_server_event(parameters, signal_name);
2885 } else if (g_strcmp0(interface_name, BT_HEADSET_INTERFACE) == 0) {
2886 _bt_handle_headset_event(parameters, object_path);
2887 } else if (g_strcmp0(interface_name, BT_SINK_INTERFACE) == 0) {
2888 _bt_handle_sink_event(parameters, object_path);
2889 } else if (g_strcmp0(interface_name, BT_AGENT_INTERFACE) == 0) {
2890 _bt_handle_agent_event(parameters, signal_name);
2891 } else if (g_strcmp0(interface_name, BT_DEVICE_INTERFACE) == 0) {
2892 _bt_handle_device_event(parameters, signal_name, object_path);
2893 } else if (g_strcmp0(interface_name, BT_GATT_CHAR_INTERFACE) == 0) {
2894 _bt_handle_gatt_event(parameters, signal_name, object_path);
2900 static gboolean __bt_is_obexd_event(GVariant *msg, const char *interface)
2903 if (g_strcmp0(interface, BT_PROPERTIES_INTERFACE) == 0) {
2904 char *interface_name = NULL;
2906 g_variant_get(msg, "(&s@a{sv}@as)", &interface_name, NULL, NULL);
2907 retv_if(interface_name == NULL, FALSE);
2909 if (strcasecmp(interface_name, BT_OBEX_TRANSFER_INTERFACE) == 0) {
2910 BT_DBG("BT_OBEX_TRANSFER_INTERFACE");
2918 static void __bt_obexd_event_filter(GDBusConnection *connection,
2919 const gchar *sender_name,
2920 const gchar *object_path,
2921 const gchar *interface_name,
2922 const gchar *signal_name,
2923 GVariant *parameters,
2926 const char *member = signal_name;
2927 char *obj_path = NULL;
2928 ret_if(member == NULL);
2930 if (strcasecmp(member, "InterfacesAdded") == 0) {
2931 if (__bt_get_object_path(parameters, &obj_path)) {
2932 BT_ERR("Fail to get the path");
2935 BT_INFO("object_path = [%s]", obj_path);
2937 /*Handle OPP_SERVER_CONNECTED_EVENT here */
2938 if (strncmp(obj_path, BT_SESSION_BASEPATH_SERVER,
2939 strlen(BT_SESSION_BASEPATH_SERVER)) != 0) {
2944 if (g_strrstr(obj_path, "session") && g_strrstr(obj_path, "transfer")) {
2945 BT_DBG("Obex_Server_Session_Transfer connected");
2946 _bt_obex_transfer_connected(obj_path);
2949 } else if (strcasecmp(member, "InterfacesRemoved") == 0) {
2950 /*Handle OPP_SERVER_DISCONNECTED_EVENT here */
2951 if (__bt_get_object_path(parameters, &obj_path)) {
2952 BT_ERR("Fail to get the path");
2955 BT_INFO("object_path = [%s]", obj_path);
2957 if (strncmp(obj_path, BT_SESSION_BASEPATH_CLIENT,
2958 strlen(BT_SESSION_BASEPATH_CLIENT)) == 0) {
2959 BT_DBG("Call PBAP Disconnected");
2960 _bt_obex_pbap_client_disconnect(obj_path);
2963 if (strncmp(obj_path, BT_SESSION_BASEPATH_SERVER,
2964 strlen(BT_SESSION_BASEPATH_SERVER)) != 0) {
2969 if (g_strrstr(obj_path, "session") && g_strrstr(obj_path, "transfer")) {
2970 BT_DBG("Obex_Server_Session_Transfer disconnected %s",
2973 _bt_obex_transfer_disconnected(obj_path);
2976 } else if (__bt_is_obexd_event(parameters, interface_name) == TRUE) {
2977 const char *path = object_path;
2979 if (strncmp(path, BT_SESSION_BASEPATH_SERVER,
2980 strlen(BT_SESSION_BASEPATH_SERVER)) != 0 &&
2981 strncmp(path, BT_SESSION_BASEPATH_CLIENT,
2982 strlen(BT_SESSION_BASEPATH_CLIENT)) != 0) {
2983 BT_DBG("DBUS_HANDLER_RESULT_NOT_YET_HANDLED");
2987 _bt_handle_property_changed_event(parameters, path);
2993 static gboolean __bt_is_obexd_client_event(GVariant *msg, const char *interface)
2997 if (g_strcmp0(interface, BT_PROPERTIES_INTERFACE) == 0) {
2998 char *interface_name = NULL;
3000 g_variant_get(msg, "(&s@a{sv}@as)", &interface_name, NULL, NULL);
3002 retv_if(interface_name == NULL, FALSE);
3004 if (strcasecmp(interface_name,
3005 BT_OBEX_TRANSFER_INTERFACE) == 0) {
3016 static void __bt_opc_event_filter(GDBusConnection *connection,
3017 const gchar *sender_name,
3018 const gchar *object_path,
3019 const gchar *interface_name,
3020 const gchar *signal_name,
3021 GVariant *parameters,
3024 const char *member = signal_name;
3025 char *obj_path = NULL;
3026 if (strcasecmp(member, "InterfacesAdded") == 0) {
3027 BT_DBG("InterfacesAdded");
3028 } else if (strcasecmp(member, "InterfacesRemoved") == 0) {
3030 if (__bt_get_object_path(parameters, &obj_path)) {
3031 BT_ERR("Fail to get the path");
3035 BT_DBG("object_path = %s", obj_path);
3037 if (strncmp(obj_path, BT_SESSION_BASEPATH_CLIENT,
3038 strlen(BT_SESSION_BASEPATH_CLIENT)) != 0
3039 || strstr(obj_path, "transfer") == NULL) {
3042 } else if (strncmp(obj_path, BT_SESSION_BASEPATH_CLIENT,
3043 strlen(BT_SESSION_BASEPATH_CLIENT)) == 0) {
3044 BT_DBG("Going to call opc disconnected");
3045 _bt_opc_disconnected(obj_path);
3048 _bt_sending_files();
3050 } else if (__bt_is_obexd_client_event(parameters, interface_name) == TRUE) {
3051 char *path = (char *)object_path;
3052 BT_INFO("object_path %s", path);
3053 if (strncmp(path, BT_SESSION_BASEPATH_CLIENT,
3054 strlen(BT_SESSION_BASEPATH_CLIENT)) != 0) {
3055 BT_DBG("NOT BT_SESSION_BASEPATH_CLIENT");
3059 _bt_opc_property_changed_event(parameters, path);
3065 int _bt_opp_client_event_init(void)
3067 GError *error = NULL;
3069 if (opc_obexd_conn == NULL) {
3070 opc_obexd_conn = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &error);
3072 if (!opc_obexd_conn) {
3074 BT_ERR("Unable to connect to dbus: %s", error->message);
3075 g_clear_error(&error);
3077 return BLUETOOTH_ERROR_INTERNAL;
3081 if (_bt_register_service_event(opc_obexd_conn,
3082 BT_OPP_CLIENT_EVENT) != BLUETOOTH_ERROR_NONE) {
3083 g_object_unref(opc_obexd_conn);
3084 opc_obexd_conn = NULL;
3085 return BLUETOOTH_ERROR_INTERNAL;
3088 return BLUETOOTH_ERROR_NONE;
3091 void _bt_opp_client_event_deinit(void)
3093 if (opc_obexd_conn) {
3094 _bt_unregister_service_event(opc_obexd_conn,
3095 BT_OPP_CLIENT_EVENT);
3096 g_object_unref(opc_obexd_conn);
3097 opc_obexd_conn = NULL;
3101 int _bt_register_manager_subscribe_signal(GDBusConnection *conn,
3107 static int subs_interface_added_id = -1;
3108 static int subs_interface_removed_id = -1;
3109 static int subs_name_owner_id = -1;
3110 static int subs_property_id = -1;
3111 static int subs_adapter_id = -1;
3112 static int subs_gatt_id = -1;
3115 if (subs_interface_added_id == -1) {
3116 subs_interface_added_id = g_dbus_connection_signal_subscribe(conn,
3117 NULL, BT_MANAGER_INTERFACE,
3118 BT_INTERFACES_ADDED, NULL, NULL, 0,
3119 __bt_manager_event_filter,
3122 if (subs_interface_removed_id == -1) {
3123 subs_interface_removed_id = g_dbus_connection_signal_subscribe(conn,
3124 NULL, BT_MANAGER_INTERFACE,
3125 BT_INTERFACES_REMOVED, NULL, NULL, 0,
3126 __bt_manager_event_filter,
3129 if (subs_name_owner_id == -1) {
3130 subs_name_owner_id = g_dbus_connection_signal_subscribe(conn,
3131 NULL, BT_FREEDESKTOP_INTERFACE,
3132 BT_NAME_OWNER_CHANGED, NULL, NULL, 0,
3133 __bt_manager_event_filter,
3136 if (subs_property_id == -1) {
3137 subs_property_id = g_dbus_connection_signal_subscribe(conn,
3138 NULL, BT_PROPERTIES_INTERFACE,
3139 BT_PROPERTIES_CHANGED, NULL, NULL, 0,
3140 __bt_manager_event_filter,
3143 if (subs_adapter_id == -1) {
3144 subs_adapter_id = g_dbus_connection_signal_subscribe(conn,
3145 NULL, BT_ADAPTER_INTERFACE,
3146 NULL, NULL, NULL, 0,
3147 __bt_manager_event_filter,
3150 if (subs_gatt_id == -1) {
3151 subs_gatt_id = g_dbus_connection_signal_subscribe(conn,
3152 NULL, BT_GATT_CHAR_INTERFACE,
3153 NULL, NULL, NULL, 0,
3154 __bt_manager_event_filter,
3158 if (subs_interface_added_id != -1) {
3159 g_dbus_connection_signal_unsubscribe(conn,
3160 subs_interface_added_id);
3161 subs_interface_added_id = -1;
3163 if (subs_interface_removed_id != -1) {
3164 g_dbus_connection_signal_unsubscribe(conn,
3165 subs_interface_removed_id);
3166 subs_interface_removed_id = -1;
3168 if (subs_name_owner_id != -1) {
3169 g_dbus_connection_signal_unsubscribe(conn,
3170 subs_name_owner_id);
3171 subs_name_owner_id = -1;
3173 if (subs_property_id != -1) {
3174 g_dbus_connection_signal_unsubscribe(conn,
3176 subs_property_id = -1;
3178 if (subs_adapter_id != -1) {
3179 g_dbus_connection_signal_unsubscribe(conn, subs_adapter_id);
3180 subs_adapter_id = -1;
3182 if (subs_gatt_id != -1) {
3183 g_dbus_connection_signal_unsubscribe(conn, subs_gatt_id);
3190 int _bt_register_device_subscribe_signal(GDBusConnection *conn,
3196 static int subs_device_id = -1;
3199 if (subs_device_id == -1) {
3200 subs_device_id = g_dbus_connection_signal_subscribe(conn,
3201 NULL, BT_DEVICE_INTERFACE,
3202 NULL, NULL, NULL, 0,
3203 __bt_manager_event_filter,
3207 if (subs_device_id != -1) {
3208 g_dbus_connection_signal_unsubscribe(conn,
3210 subs_device_id = -1;
3216 int _bt_register_input_subscribe_signal(GDBusConnection *conn,
3222 static int subs_input_id = -1;
3225 if (subs_input_id == -1) {
3226 subs_input_id = g_dbus_connection_signal_subscribe(conn,
3227 NULL, BT_INPUT_INTERFACE,
3228 NULL, NULL, NULL, 0,
3229 __bt_manager_event_filter,
3233 if (subs_input_id != -1) {
3234 g_dbus_connection_signal_unsubscribe(conn,
3242 int _bt_register_network_subscribe_signal(GDBusConnection *conn,
3248 static int subs_serv_id = -1;
3249 static int subs_client_id = -1;
3252 if (subs_serv_id == -1) {
3253 subs_serv_id = g_dbus_connection_signal_subscribe(conn,
3254 NULL, BT_NETWORK_SERVER_INTERFACE,
3255 NULL, NULL, NULL, 0,
3256 __bt_manager_event_filter,
3259 if (subs_client_id == -1) {
3260 subs_client_id = g_dbus_connection_signal_subscribe(conn,
3261 NULL, BT_NETWORK_CLIENT_INTERFACE,
3262 NULL, NULL, NULL, 0,
3263 __bt_manager_event_filter,
3267 if (subs_serv_id != -1) {
3268 g_dbus_connection_signal_unsubscribe(conn,
3272 if (subs_client_id != -1) {
3273 g_dbus_connection_signal_unsubscribe(conn,
3275 subs_client_id = -1;
3281 int _bt_register_audio_subscribe_signal(GDBusConnection *conn,
3287 static int subs_headset_id = -1;
3288 static int subs_sink_id = -1;
3291 if (subs_headset_id == -1) {
3292 subs_headset_id = g_dbus_connection_signal_subscribe(conn,
3293 NULL, BT_HEADSET_INTERFACE,
3294 NULL, NULL, NULL, 0,
3295 __bt_manager_event_filter,
3298 if (subs_sink_id == -1) {
3299 subs_sink_id = g_dbus_connection_signal_subscribe(conn,
3300 NULL, BT_SINK_INTERFACE,
3301 NULL, NULL, NULL, 0,
3302 __bt_manager_event_filter,
3306 if (subs_headset_id != -1) {
3307 g_dbus_connection_signal_unsubscribe(conn,
3309 subs_headset_id = -1;
3311 if (subs_sink_id != -1) {
3312 g_dbus_connection_signal_unsubscribe(conn,
3320 int _bt_register_opp_server_subscribe_signal(GDBusConnection *conn,
3326 static int subs_opp_server_interface_added_id = -1;
3327 static int subs_opp_server_interface_removed_id = -1;
3328 static int subs_opp_server_property_id = -1;
3332 if (subs_opp_server_interface_added_id == -1) {
3333 subs_opp_server_interface_added_id = g_dbus_connection_signal_subscribe(conn,
3334 NULL, BT_MANAGER_INTERFACE,
3335 BT_INTERFACES_ADDED, NULL, NULL, 0,
3336 __bt_obexd_event_filter,
3339 if (subs_opp_server_interface_removed_id == -1) {
3340 subs_opp_server_interface_removed_id = g_dbus_connection_signal_subscribe(conn,
3341 NULL, BT_MANAGER_INTERFACE,
3342 BT_INTERFACES_REMOVED, NULL, NULL, 0,
3343 __bt_obexd_event_filter,
3346 if (subs_opp_server_property_id == -1) {
3347 subs_opp_server_property_id = g_dbus_connection_signal_subscribe(conn,
3348 NULL, BT_PROPERTIES_INTERFACE,
3349 BT_PROPERTIES_CHANGED, NULL, NULL, 0,
3350 __bt_obexd_event_filter,
3354 if (subs_opp_server_interface_added_id != -1) {
3355 g_dbus_connection_signal_unsubscribe(conn,
3356 subs_opp_server_interface_added_id);
3357 subs_opp_server_interface_added_id = -1;
3359 if (subs_opp_server_interface_removed_id != -1) {
3360 g_dbus_connection_signal_unsubscribe(conn,
3361 subs_opp_server_interface_removed_id);
3362 subs_opp_server_interface_removed_id = -1;
3364 if (subs_opp_server_property_id != -1) {
3365 g_dbus_connection_signal_unsubscribe(conn,
3366 subs_opp_server_property_id);
3367 subs_opp_server_property_id = -1;
3373 int _bt_register_opp_client_subscribe_signal(GDBusConnection *conn,
3379 static int subs_opp_client_interface_added_id = -1;
3380 static int subs_opp_client_interface_removed_id = -1;
3381 static int subs_opp_client_property_id = -1;
3385 if (subs_opp_client_interface_added_id == -1) {
3386 subs_opp_client_interface_added_id = g_dbus_connection_signal_subscribe(conn,
3387 NULL, BT_MANAGER_INTERFACE,
3388 BT_INTERFACES_ADDED, NULL, NULL, 0,
3389 __bt_opc_event_filter,
3392 if (subs_opp_client_interface_removed_id == -1) {
3393 subs_opp_client_interface_removed_id = g_dbus_connection_signal_subscribe(conn,
3394 NULL, BT_MANAGER_INTERFACE,
3395 BT_INTERFACES_REMOVED, NULL, NULL, 0,
3396 __bt_opc_event_filter,
3399 if (subs_opp_client_property_id == -1) {
3400 subs_opp_client_property_id = g_dbus_connection_signal_subscribe(conn,
3401 NULL, BT_PROPERTIES_INTERFACE,
3402 BT_PROPERTIES_CHANGED, NULL, NULL, 0,
3403 __bt_opc_event_filter,
3407 if (subs_opp_client_interface_added_id != -1) {
3408 g_dbus_connection_signal_unsubscribe(conn,
3409 subs_opp_client_interface_added_id);
3410 subs_opp_client_interface_added_id = -1;
3412 if (subs_opp_client_interface_removed_id != -1) {
3413 g_dbus_connection_signal_unsubscribe(conn,
3414 subs_opp_client_interface_removed_id);
3415 subs_opp_client_interface_removed_id = -1;
3417 if (subs_opp_client_property_id != -1) {
3418 g_dbus_connection_signal_unsubscribe(conn,
3419 subs_opp_client_property_id);
3420 subs_opp_client_property_id = -1;
3426 int _bt_register_a2dp_subscribe_signal(GDBusConnection *conn,
3432 static int subs_a2dp_source_id = -1;
3433 static int subs_a2dp_sink_id = -1;
3436 if (subs_a2dp_source_id == -1) {
3437 subs_a2dp_source_id = g_dbus_connection_signal_subscribe(conn,
3438 NULL, BT_A2DP_SOURCE_INTERFACE,
3439 NULL, NULL, NULL, 0,
3440 __bt_opc_event_filter,
3443 if (subs_a2dp_sink_id == -1) {
3444 subs_a2dp_sink_id = g_dbus_connection_signal_subscribe(conn,
3445 NULL, BT_SINK_INTERFACE,
3446 NULL, NULL, NULL, 0,
3447 __bt_opc_event_filter,
3451 if (subs_a2dp_source_id != -1) {
3452 g_dbus_connection_signal_unsubscribe(conn,
3453 subs_a2dp_source_id);
3454 subs_a2dp_source_id = -1;
3456 if (subs_a2dp_sink_id != -1) {
3457 g_dbus_connection_signal_unsubscribe(conn,
3459 subs_a2dp_sink_id = -1;
3465 static void __bt_dump_event_filter(GDBusConnection *connection,
3466 const gchar *sender_name,
3467 const gchar *object_path,
3468 const gchar *interface_name,
3469 const gchar *signal_name,
3470 GVariant *parameters,
3476 int __bt_register_dump_subscribe_signal(GDBusConnection *conn,
3482 static int subs_source_id = -1;
3485 if (subs_source_id == -1) {
3486 subs_source_id = g_dbus_connection_signal_subscribe(conn,
3487 NULL, BT_DUMP_SERVICE_INTERFACE,
3488 BT_DUMP_SERVICE_SIGNAL, BT_DUMP_SERVICE_PATH, NULL, 0,
3489 __bt_dump_event_filter,
3493 if (subs_source_id != -1) {
3494 g_dbus_connection_signal_unsubscribe(conn,
3496 subs_source_id = -1;
3502 int _bt_register_service_event(GDBusConnection *g_conn, int event_type)
3506 retv_if(g_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
3508 switch (event_type) {
3509 case BT_MANAGER_EVENT:
3510 _bt_register_manager_subscribe_signal(g_conn, TRUE);
3512 case BT_DEVICE_EVENT:
3513 _bt_register_device_subscribe_signal(g_conn, TRUE);
3516 _bt_register_input_subscribe_signal(g_conn, TRUE);
3518 case BT_NETWORK_EVENT:
3519 _bt_register_network_subscribe_signal(g_conn, TRUE);
3521 case BT_HEADSET_EVENT:
3522 _bt_register_audio_subscribe_signal(g_conn, TRUE);
3525 case BT_OPP_SERVER_EVENT:
3526 BT_ERR("BT_OPP_SERVER_EVENT: register service event");
3527 _bt_register_opp_server_subscribe_signal(g_conn, TRUE);
3529 case BT_OPP_CLIENT_EVENT:
3530 BT_ERR("BT_OPP_CLIENT_EVENT: register service event");
3531 _bt_register_opp_client_subscribe_signal(g_conn, TRUE);
3533 case BT_A2DP_SOURCE_EVENT:
3534 BT_INFO("A2dp Source event");
3535 _bt_register_a2dp_subscribe_signal(g_conn, TRUE);
3538 BT_ERR("Unknown event");
3539 return BLUETOOTH_ERROR_INTERNAL;
3542 return BLUETOOTH_ERROR_NONE;
3545 void _bt_unregister_service_event(GDBusConnection *g_conn, int event_type)
3549 ret_if(g_conn == NULL);
3551 switch (event_type) {
3552 case BT_MANAGER_EVENT:
3553 _bt_register_manager_subscribe_signal(g_conn, FALSE);
3554 _bt_register_device_subscribe_signal(g_conn, FALSE);
3555 _bt_register_input_subscribe_signal(g_conn, FALSE);
3556 _bt_register_network_subscribe_signal(g_conn, FALSE);
3557 _bt_register_audio_subscribe_signal(g_conn, FALSE);
3559 case BT_OPP_SERVER_EVENT:
3560 _bt_register_opp_server_subscribe_signal(g_conn, FALSE);
3562 case BT_OPP_CLIENT_EVENT:
3563 _bt_register_opp_client_subscribe_signal(g_conn, FALSE);
3566 BT_ERR("Unknown event");
3573 static int __bt_init_manager_receiver(void)
3577 GError *error = NULL;
3579 if (manager_conn == NULL) {
3580 manager_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
3581 if (error != NULL) {
3582 BT_ERR("ERROR: Can't get on system bus [%s]", error->message);
3583 g_clear_error(&error);
3585 retv_if(manager_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
3588 if (_bt_register_service_event(manager_conn,
3589 BT_MANAGER_EVENT) != BLUETOOTH_ERROR_NONE)
3591 if (_bt_register_service_event(manager_conn,
3592 BT_DEVICE_EVENT) != BLUETOOTH_ERROR_NONE)
3595 if (_bt_register_service_event(manager_conn,
3596 BT_HID_EVENT) != BLUETOOTH_ERROR_NONE)
3599 if (_bt_register_service_event(manager_conn,
3600 BT_HEADSET_EVENT) != BLUETOOTH_ERROR_NONE)
3603 if (_bt_register_service_event(manager_conn,
3604 BT_NETWORK_EVENT) != BLUETOOTH_ERROR_NONE)
3607 __bt_register_dump_subscribe_signal(manager_conn, TRUE);
3608 return BLUETOOTH_ERROR_NONE;
3611 g_object_unref(manager_conn);
3612 manager_conn = NULL;
3617 return BLUETOOTH_ERROR_INTERNAL;
3620 static int __bt_init_obexd_receiver(void)
3623 #ifndef TIZEN_TV /* TODO: obexd doesn't work in TV profile. It should be resolved later. */
3624 GError *error = NULL;
3626 if (obexd_conn == NULL) {
3627 obexd_conn = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &error);
3628 if (error != NULL) {
3629 BT_ERR("ERROR: Can't get on session bus [%s]", error->message);
3630 g_clear_error(&error);
3632 retv_if(obexd_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
3635 if (_bt_register_service_event(obexd_conn,
3636 BT_OPP_SERVER_EVENT) != BLUETOOTH_ERROR_NONE) {
3637 BT_ERR("Error while registering service event");
3638 g_object_unref(obexd_conn);
3640 return BLUETOOTH_ERROR_INTERNAL;
3645 return BLUETOOTH_ERROR_NONE;
3648 gboolean __bt_reinit_obexd_receiver(gpointer user_data)
3650 static int retry_cnt = 0;
3651 int result = BLUETOOTH_ERROR_NONE;
3655 result = __bt_init_obexd_receiver();
3656 if (result != BLUETOOTH_ERROR_NONE) {
3657 /* 20 ms * 50 = 10 seconds. During 10 seconds fail to initialize,
3658 then it is not the timing issue. Just can't use the session bus connection */
3659 if (retry_cnt > 100) {
3660 BT_ERR("Fail to init obexd receiver by 50 times.");
3662 session_reinit_timer = 0;
3666 BT_DBG("Retry to initialize the obexd receiver");
3671 session_reinit_timer = 0;
3678 /* To receive the event from bluez */
3679 int _bt_init_service_event_receiver(void)
3685 result = __bt_init_manager_receiver();
3686 retv_if(result != BLUETOOTH_ERROR_NONE, result);
3688 result = __bt_init_obexd_receiver();
3689 if (result != BLUETOOTH_ERROR_NONE) {
3690 BT_ERR("Fail to init obexd receiver");
3692 /* Try to re-initialize obexd receiver in the timer */
3693 if (session_reinit_timer > 0)
3694 g_source_remove(session_reinit_timer);
3696 session_reinit_timer = g_timeout_add(BT_SESSION_BUS_GET_TIMEOUT,
3697 (GSourceFunc)__bt_reinit_obexd_receiver, NULL);
3702 return BLUETOOTH_ERROR_NONE;
3705 void _bt_deinit_service_event_receiver(void)
3709 _bt_unregister_service_event(manager_conn, BT_MANAGER_EVENT);
3711 _bt_unregister_service_event(obexd_conn, BT_OPP_SERVER_EVENT);
3713 __bt_register_dump_subscribe_signal(manager_conn, FALSE);
3716 g_object_unref(manager_conn);
3717 manager_conn = NULL;
3721 g_object_unref(obexd_conn);
3726 g_source_remove(event_id);