2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
22 #include <vconf-internal-bt-keys.h>
24 #include "bluetooth-api.h"
25 #include "bt-internal-types.h"
27 #include "bt-service-common.h"
28 #include "bt-service-event.h"
29 #include "bt-service-main.h"
30 #include "bt-service-adapter.h"
31 #include "bt-service-adapter-le.h"
32 #include "bt-service-device.h"
33 #include "bt-service-avrcp.h"
34 #include "bt-service-obex-server.h"
35 #include "bt-service-rfcomm-server.h"
36 #include "bt-service-audio.h"
37 #include "bt-service-agent.h"
38 #include "bt-service-pbap.h"
39 #include "bt-service-headset-connection.h"
40 #include "bt-service-avrcp-controller.h"
41 #include "bt-service-hid.h"
42 #include "bt-service-proximity.h"
44 #include "bt-service-opp-client.h"
45 #include "bt-service-map-client.h"
47 #ifdef TIZEN_FEATURE_BT_DPM
48 #include "bt-service-dpm.h"
51 #define DBUS_TIMEOUT 20 * 1000 /* 20 Sec */
52 static GDBusConnection *manager_conn;
53 static GDBusConnection *obexd_conn;
54 static GDBusConnection *opc_obexd_conn;
55 static GDBusConnection *map_obexd_conn;
57 static GList *p_cache_list = NULL;
59 static guint event_id;
60 static guint le_scan_event_id = 0;
61 static guint session_reinit_timer;
62 guint nap_connected_device_count = 0;
63 static guint hid_connected_device_count = 0;
64 static GList *p_adv_ind_list = NULL;
67 bt_remote_dev_info_t *dev_info;
71 * obexd connection type
79 OBEX_PCSUITE = (1 << 6),
80 OBEX_SYNCEVOLUTION = (1 << 7),
83 } bluetooth_obex_connection_type_t;
85 void _bt_handle_property_changed_event(GVariant *msg, const char *object_path);
86 void _bt_opc_property_changed_event(GVariant *msg, char *path);
87 void _bt_map_property_changed_event(GVariant *msg, const char *path);
88 int _bt_register_service_event(GDBusConnection *g_conn, int event_type);
89 void _bt_unregister_service_event(GDBusConnection *g_conn, int event_type);
90 void _bt_opp_client_event_deinit(void);
91 void _bt_map_client_event_deinit(void);
92 void _bt_handle_network_client_event(GVariant *msg_iter,
94 void __bt_gatt_char_property_changed_event(GVariant *msg_iter,
96 void _bt_map_on_transfer_finished(const char *transfer_object_path, const int error);
98 static void __bt_free_bt_le_adv_info_t(gpointer data)
100 bt_le_adv_info_t *adv_info = data;
102 if (adv_info->timer_id)
103 g_source_remove(adv_info->timer_id);
104 adv_info->timer_id = 0;
106 g_free(adv_info->addr);
107 g_free(adv_info->data);
111 static bt_le_adv_info_t *__bt_get_adv_ind_info(char *addr)
113 retv_if(!addr, NULL);
114 bt_le_adv_info_t *adv_info = NULL;
115 GList *current = g_list_first((GList *)p_adv_ind_list);
116 while (current && current->data) {
117 adv_info = (bt_le_adv_info_t *)current->data;
118 if (adv_info && !g_strcmp0(adv_info->addr, addr))
120 current = g_list_next(current);
125 static int __bt_add_adv_ind_info(bt_le_adv_info_t *adv_info)
127 retv_if(!adv_info, -1);
128 if (__bt_get_adv_ind_info(adv_info->addr) != NULL) {
129 __bt_free_bt_le_adv_info_t(adv_info);
132 p_adv_ind_list = g_list_append(p_adv_ind_list, adv_info);
137 static void __bt_del_adv_ind_info(char *addr)
140 ret_if(!p_adv_ind_list);
141 bt_le_adv_info_t *adv_info = NULL;
142 GList *current = g_list_first((GList *)p_adv_ind_list);
143 while (current && current->data) {
144 adv_info = (bt_le_adv_info_t *)current->data;
145 if (adv_info && !g_strcmp0(adv_info->addr, addr)) {
146 p_adv_ind_list = g_list_remove(p_adv_ind_list, adv_info);
147 __bt_free_bt_le_adv_info_t(adv_info);
150 current = g_list_next(current);
154 static gboolean __bt_adv_scan_req_timeout_cb(gpointer user_data)
156 bt_remote_le_dev_info_t le_dev_info;
157 bt_le_adv_info_t *adv_info = (bt_le_adv_info_t*)user_data;
159 memset(&le_dev_info, 0x00, sizeof(bt_remote_le_dev_info_t));
161 le_dev_info.address = adv_info->addr;
162 le_dev_info.addr_type = adv_info->addr_type;
163 le_dev_info.rssi = adv_info->rssi;
164 le_dev_info.adv_data = adv_info->data;
165 le_dev_info.adv_data_len = 0;
166 adv_info->timer_id = 0;
168 _bt_send_scan_result_event(&le_dev_info, adv_info);
169 __bt_del_adv_ind_info(adv_info->addr);
174 static void __bt_free_cache_info(bt_cache_info_t *cache_info)
176 ret_if(cache_info == NULL);
177 _bt_free_device_info(cache_info->dev_info);
181 static gboolean __bt_parse_device_properties(GVariant *item,
182 bt_remote_dev_info_t *dev_info)
191 g_variant_iter_init(&iter, item);
192 while (g_variant_iter_loop(&iter, "{sv}", &key, &val)) {
193 if (strcasecmp(key, "Address") == 0) {
194 dev_info->address = g_variant_dup_string(val, &len);
195 } else if (strcasecmp(key, "Class") == 0) {
196 dev_info->class = g_variant_get_uint32(val);
197 } else if (strcasecmp(key, "name") == 0) {
198 if (dev_info->name == NULL)
199 dev_info->name = g_variant_dup_string(val, &len);
200 } else if (strcasecmp(key, "Connected") == 0) {
201 dev_info->connected = g_variant_get_byte(val);
202 } else if (strcasecmp(key, "paired") == 0) {
203 dev_info->paired = g_variant_get_boolean(val);
204 } else if (strcasecmp(key, "Trusted") == 0) {
205 dev_info->trust = g_variant_get_boolean(val);
206 } else if (strcasecmp(key, "RSSI") == 0) {
207 dev_info->rssi = g_variant_get_int16(val);
208 } else if (strcasecmp(key, "LastAddrType") == 0) {
209 dev_info->addr_type = g_variant_get_byte(val);
210 } else if (strcasecmp(key, "UUIDs") == 0) {
214 size = g_variant_get_size(val);
217 uuid_value = (char **)g_variant_get_strv(val, &size);
218 if (dev_info->uuids == NULL)
219 dev_info->uuids = g_malloc0(sizeof(char *) * size);
221 for (i = 0; uuid_value[i] != NULL; i++) {
222 dev_info->uuid_count++;
223 dev_info->uuids[i] = g_strdup(uuid_value[i]);
227 } else if (strcasecmp(key, "ManufacturerDataLen") == 0) {
228 g_variant_get(val, "q", &dev_info->manufacturer_data_len);
229 if (dev_info->manufacturer_data_len > BLUETOOTH_MANUFACTURER_DATA_LENGTH_MAX) {
230 BT_ERR("manufacturer_data_len is too long(len = %d)", dev_info->manufacturer_data_len);
231 dev_info->manufacturer_data_len = BLUETOOTH_MANUFACTURER_DATA_LENGTH_MAX;
234 if (dev_info->manufacturer_data_len == 0)
235 dev_info->manufacturer_data = g_strdup("");
236 } else if (strcasecmp(key, "ManufacturerData") == 0) {
239 GVariantIter *value_iter;
242 len = g_variant_get_size(val);
246 dev_info->manufacturer_data = g_malloc0(len);
248 g_variant_get(val, "ay", &value_iter);
249 while (g_variant_iter_loop(value_iter, "y", &m_value))
250 dev_info->manufacturer_data[i++] = m_value;
251 g_variant_iter_free(value_iter);
259 static gboolean __bt_parse_interface(GVariant *msg,
260 bt_remote_dev_info_t *dev_info)
263 GVariant *optional_param = NULL;
266 char *interface_name = NULL;
267 GVariant *inner_iter = NULL;
268 g_variant_get(msg, "(&o@a{sa{sv}})",
269 &path, &optional_param);
270 g_variant_iter_init(&iter, optional_param);
272 retv_if(optional_param == NULL, FALSE);
274 while ((child = g_variant_iter_next_value(&iter))) {
275 g_variant_get(child, "{&s@a{sv}}", &interface_name, &inner_iter);
276 if (g_strcmp0(interface_name, BT_DEVICE_INTERFACE) == 0) {
277 BT_DBG("Found a device: %s", path);
278 if (__bt_parse_device_properties(inner_iter,
279 dev_info) == FALSE) {
280 g_variant_unref(inner_iter);
281 g_variant_unref(child);
282 g_variant_unref(optional_param);
283 BT_ERR("Fail to parse the properies");
286 g_variant_unref(inner_iter);
287 g_variant_unref(child);
288 g_variant_unref(optional_param);
292 g_variant_unref(inner_iter);
293 g_variant_unref(child);
296 g_variant_unref(optional_param);
301 static int __bt_get_owner_info(GVariant *msg, char **name,
302 char **previous, char **current)
304 g_variant_get(msg, "(sss)", name, previous, current);
305 return BLUETOOTH_ERROR_NONE;
308 static int __bt_get_agent_signal_info(GVariant *msg, char **address,
309 char **name, char **uuid)
311 g_variant_get(msg, "(sss)", address, name, uuid);
312 return BLUETOOTH_ERROR_NONE;
315 void __bt_set_device_values(gboolean connected, int state)
317 int bt_device_state = VCONFKEY_BT_DEVICE_NONE;
319 if (vconf_get_int(VCONFKEY_BT_DEVICE, &bt_device_state) != 0)
320 BT_ERR("vconf_get_int failed");
322 if (connected == TRUE)
323 bt_device_state |= state;
324 else if (bt_device_state & state)
325 bt_device_state ^= state;
327 if (vconf_set_int(VCONFKEY_BT_DEVICE, bt_device_state) != 0)
328 BT_ERR("vconf_set_int failed");
331 gboolean _bt_discovery_finished_cb(gpointer user_data)
333 int result = BLUETOOTH_ERROR_NONE;
335 GVariant *param = NULL;
336 if (_bt_get_discovering_property(DISCOVERY_ROLE_BREDR) == FALSE) {
337 if (_bt_get_cancel_by_user() == TRUE)
338 result = BLUETOOTH_ERROR_CANCEL_BY_USER;
340 _bt_set_cancel_by_user(FALSE);
341 _bt_set_discovery_status(FALSE);
342 param = g_variant_new("(i)", result);
343 _bt_send_event(BT_ADAPTER_EVENT,
344 BLUETOOTH_EVENT_DISCOVERY_FINISHED,
351 static gboolean __bt_le_discovery_finished_cb(gpointer user_data)
353 int result = BLUETOOTH_ERROR_NONE;
354 le_scan_event_id = 0;
355 GVariant *param = NULL;
356 if (_bt_get_discovering_property(DISCOVERY_ROLE_LE) == FALSE) {
357 if (_bt_get_cancel_by_user() == TRUE)
358 result = BLUETOOTH_ERROR_CANCEL_BY_USER;
360 g_list_free_full(p_adv_ind_list, __bt_free_bt_le_adv_info_t);
361 p_adv_ind_list = NULL;
363 _bt_set_cancel_by_user(FALSE);
364 _bt_disable_all_scanner_status();
365 _bt_set_le_scan_status(FALSE);
366 param = g_variant_new("(i)", result);
367 _bt_send_event(BT_LE_ADAPTER_EVENT,
368 BLUETOOTH_EVENT_LE_DISCOVERY_FINISHED,
375 void __bt_update_remote_cache_devinfo(const char *address, gboolean paired_status)
379 ret_if(address == NULL);
382 bt_cache_info_t *cache_info;
383 bt_remote_dev_info_t *dev_info;
385 node = g_list_first(p_cache_list);
387 while (node != NULL) {
388 cache_info = (bt_cache_info_t *)node->data;
390 if (cache_info == NULL) {
391 node = g_list_next(node);
395 dev_info = cache_info->dev_info;
396 if (strcasecmp(dev_info->address,
398 BT_DBG("Device Found");
399 if (paired_status == TRUE)
400 cache_info->dev_info->paired = TRUE;
402 cache_info->dev_info->paired = FALSE;
405 node = g_list_next(node);
410 static void __bt_device_remote_connected_properties(
411 bt_remote_dev_info_t *remote_dev_info,
412 char *address, gboolean connected)
414 int result = BLUETOOTH_ERROR_NONE;
416 GVariant *param = NULL;
419 if (remote_dev_info->uuid_count > 0) {
420 for (i = 0; i < remote_dev_info->uuid_count; i++) {
421 char *uuid = remote_dev_info->uuids[i];
422 if (strcasecmp(uuid, HID_UUID) == 0) {
423 int event = BLUETOOTH_EVENT_NONE;
425 event = (connected == TRUE) ?
426 BLUETOOTH_HID_CONNECTED :
427 BLUETOOTH_HID_DISCONNECTED;
428 param = g_variant_new("(is)", result,
430 _bt_send_event(BT_HID_EVENT, event,
440 gboolean __bt_handle_is_flight_mode_enabled(void)
442 #ifdef TIZEN_FEATURE_FLIGHTMODE_ENABLED
443 int is_flight_mode = 0;
446 ret = vconf_get_bool(VCONFKEY_TELEPHONY_FLIGHT_MODE, &is_flight_mode);
448 BT_ERR("vconf_get_bool failed");
450 return (is_flight_mode == 0) ? FALSE : TRUE;
456 void _bt_handle_adapter_event(GVariant *msg, const char *member)
460 int result = BLUETOOTH_ERROR_NONE;
461 GVariant *param = NULL;
462 ret_if(member == NULL);
464 if (strcasecmp(member, "DeviceCreated") == 0) {
465 char *object_path = NULL;
467 bt_remote_dev_info_t *remote_dev_info;
469 ret_if(_bt_is_device_creating() == FALSE);
471 /* Bonding from remote device */
472 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
474 g_variant_get(msg, "(&o)", &object_path);
475 _bt_convert_device_path_to_address((const char*)object_path, address);
477 remote_dev_info = _bt_get_remote_device_info_by_object_path(object_path);
478 if (remote_dev_info == NULL) {
483 _bt_free_device_info(remote_dev_info);
485 } else if (strcasecmp(member, "InterfacesRemoved") == 0) {
486 char *object_path = NULL;
488 bt_cache_info_t *cache_info;
489 bt_remote_dev_info_t *dev_info;
492 /* Bonding from remote device */
493 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
495 g_variant_get(msg, "(&o)", &object_path);
497 _bt_convert_device_path_to_address((const char *)object_path, address);
499 node = g_list_first(p_cache_list);
501 while (node != NULL) {
502 cache_info = (bt_cache_info_t *)node->data;
504 if (cache_info == NULL) {
505 node = g_list_next(node);
509 dev_info = cache_info->dev_info;
510 if (strcasecmp(dev_info->address,
512 p_cache_list = g_list_remove(p_cache_list,
514 __bt_free_cache_info(cache_info);
517 node = g_list_next(node);
520 } else if (strcasecmp(member, "AdvertisingEnabled") == 0) {
521 BT_DBG("Advertising Enabled");
525 gboolean status = FALSE;
527 g_variant_get(msg, "(ib)", &slot_id, &status);
529 BT_DBG("Advertising Enabled : slot_id [%d] status [%d]", slot_id, status);
531 /* Send event to application */
532 _bt_set_advertising_status(slot_id, status);
534 adv_handle = _bt_get_adv_slot_adv_handle(slot_id);
537 event = BLUETOOTH_EVENT_ADVERTISING_STARTED;
539 event = BLUETOOTH_EVENT_ADVERTISING_STOPPED;
540 param = g_variant_new("(ii)", result,
544 sender = _bt_get_adv_slot_owner(slot_id);
545 _bt_send_event_to_dest(sender, BT_ADAPTER_EVENT,
549 if (event == BLUETOOTH_EVENT_ADVERTISING_STOPPED)
550 _bt_unregister_adv_slot_owner(slot_id);
551 } else if (strcasecmp(member, "RssiEnabled") == 0) {
552 BT_DBG("RSSI Enabled");
553 gboolean status = FALSE;
554 char *address = NULL;
556 g_variant_get(msg, "(sib)", &address, &link_type, &status);
558 BT_DBG("RSSI Enabled [%s %d]", address, status);
559 param = g_variant_new("(isib)", result,
560 address, link_type, status);
561 _bt_send_event(BT_DEVICE_EVENT,
562 BLUETOOTH_EVENT_RSSI_ENABLED,
565 } else if (strcasecmp(member, "RssiAlert") == 0) {
566 BT_DBG("RSSI Alert");
570 char *address = NULL;
571 g_variant_get(msg, "(siii)", &address, &link_type, &alert_type, &rssi_dbm);
573 BT_DBG("RSSI Alert: [Address %s LinkType %d] [Type %d DBM %d]",
574 address, alert_type, rssi_dbm);
575 param = g_variant_new("(isiii)", result,
576 address, link_type, alert_type, rssi_dbm);
577 _bt_send_event(BT_DEVICE_EVENT,
578 BLUETOOTH_EVENT_RSSI_ALERT,
581 } else if (strcasecmp(member, "RawRssi") == 0) {
585 char *address = NULL;
586 g_variant_get(msg, "(sii)", &address, &link_type, &rssi_dbm);
588 BT_DBG("Raw RSSI: [Address %s] [Link Type %d][RSSI DBM %d]",
589 address, link_type, rssi_dbm);
590 param = g_variant_new("(isii)", result,
591 address, link_type, rssi_dbm);
592 _bt_send_event(BT_DEVICE_EVENT,
593 BLUETOOTH_EVENT_RAW_RSSI,
596 } else if (strcasecmp(member, BT_HARDWARE_ERROR) == 0) {
597 BT_ERR_C("Hardware error received from BLUEZ");
598 /* Don't add the recovery logic into platform */
600 _bt_recover_adapter();
602 } else if (strcasecmp(member, BT_TX_TIMEOUT_ERROR) == 0) {
603 BT_ERR_C("Tx timeout error received from BLUEZ");
604 /* Don't add the recovery logic into platform */
606 _bt_recover_adapter();
612 static void __bt_adapter_property_changed_event(GVariant *msg, const char *path)
614 GDBusProxy *adapter_proxy;
616 int result = BLUETOOTH_ERROR_NONE;
617 GVariantIter value_iter;
618 GVariant *val = NULL;
619 GVariant *ret = NULL;
621 char *property = NULL;
622 GVariant *param = NULL;
623 g_variant_iter_init(&value_iter, msg);
624 while ((g_variant_iter_loop(&value_iter, "{sv}", &property, &val))) {
625 BT_INFO("Property %s", property);
627 if (strcasecmp(property, "Discovering") == 0) {
628 gboolean discovering = FALSE;
629 g_variant_get(val, "b", &discovering);
630 /* Send event to application */
631 BT_DBG("Discovering %d", discovering);
632 if (discovering == TRUE) {
633 _bt_set_discovery_status(TRUE);
634 param = g_variant_new("(i)", result);
635 _bt_send_event(BT_ADAPTER_EVENT,
636 BLUETOOTH_EVENT_DISCOVERY_STARTED,
639 ret_if(event_id > 0);
641 adapter_proxy = _bt_get_adapter_proxy();
642 ret_if(adapter_proxy == NULL);
644 /* Need to stop searching */
645 ret = g_dbus_proxy_call_sync(adapter_proxy, "StopDiscovery",
647 G_DBUS_CALL_FLAGS_NONE,
651 BT_ERR("Dbus Error : %s", err->message);
655 g_variant_unref(ret);
657 event_id = g_timeout_add(BT_DISCOVERY_FINISHED_DELAY,
658 (GSourceFunc)_bt_discovery_finished_cb, NULL);
660 } else if (strcasecmp(property, "LEDiscovering") == 0) {
661 gboolean le_discovering = FALSE;
663 g_variant_get(val, "b", &le_discovering);
664 /* Send event to application */
665 if (le_discovering == TRUE) {
666 _bt_set_le_scan_status(TRUE);
667 param = g_variant_new("(i)", result);
668 _bt_send_event(BT_LE_ADAPTER_EVENT,
669 BLUETOOTH_EVENT_LE_DISCOVERY_STARTED,
672 ret_if(le_scan_event_id > 0);
674 adapter_proxy = _bt_get_adapter_proxy();
675 ret_if(adapter_proxy == NULL);
677 /* Need to stop searching */
678 ret = g_dbus_proxy_call_sync(adapter_proxy, "StopLEDiscovery",
680 G_DBUS_CALL_FLAGS_NONE,
684 BT_ERR("Dbus Error %s", err->message);
688 g_variant_unref(ret);
690 le_scan_event_id = g_timeout_add(BT_DISCOVERY_FINISHED_DELAY,
691 (GSourceFunc)__bt_le_discovery_finished_cb, NULL);
693 } else if (strcasecmp(property, "Name") == 0) {
695 g_variant_get(val, "s", &name);
696 param = g_variant_new("(is)", result, name);
697 /* Send event to application */
698 _bt_send_event(BT_ADAPTER_EVENT,
699 BLUETOOTH_EVENT_LOCAL_NAME_CHANGED,
702 } else if (strcasecmp(property, "Alias") == 0) {
704 g_variant_get(val, "s", &alias);
705 param = g_variant_new("(is)", result, alias);
706 /* Send event to application */
707 _bt_send_event(BT_ADAPTER_EVENT,
708 BLUETOOTH_EVENT_LOCAL_NAME_CHANGED,
711 } else if (strcasecmp(property, "Discoverable") == 0) {
712 gboolean discoverable = FALSE;
714 g_variant_get(val, "b", &discoverable);
715 BT_DBG("discoverable %d", discoverable);
717 if (discoverable == FALSE) {
718 if (_bt_get_discoverable_timeout_property() > 0) {
720 adapter_proxy = _bt_get_adapter_properties_proxy();
721 ret_if(adapter_proxy == NULL);
722 ret = g_dbus_proxy_call_sync(adapter_proxy, "Set",
723 g_variant_new("(ssv)", BT_ADAPTER_INTERFACE,
724 "DiscoverableTimeout",
725 g_variant_new("i", time)),
726 G_DBUS_CALL_FLAGS_NONE,
731 BT_ERR("StopLEDiscovery Failed: %s", err->message);
735 g_variant_unref(ret);
738 mode = BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE;
740 /* Send event to application */
741 BT_INFO("[Connectable]");
742 param = g_variant_new("(in)", result, mode);
743 _bt_send_event(BT_ADAPTER_EVENT,
744 BLUETOOTH_EVENT_DISCOVERABLE_MODE_CHANGED,
747 _bt_get_discoverable_mode(&mode);
749 /* Event will be sent by "DiscoverableTimeout" signal */
750 if (mode != BLUETOOTH_DISCOVERABLE_MODE_GENERAL_DISCOVERABLE) {
752 g_variant_unref(val);
756 /* Send event to application */
757 BT_INFO("[General Discoverable]");
758 param = g_variant_new("(in)", result, mode);
759 _bt_send_event(BT_ADAPTER_EVENT,
760 BLUETOOTH_EVENT_DISCOVERABLE_MODE_CHANGED,
763 } else if (strcasecmp(property, "DiscoverableTimeout") == 0) {
764 _bt_get_discoverable_mode(&mode);
766 /* Event was already sent by "Discoverable" signal */
767 if (mode == BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE ||
768 mode == BLUETOOTH_DISCOVERABLE_MODE_GENERAL_DISCOVERABLE) {
770 g_variant_unref(val);
774 /* Send event to application */
775 BT_INFO("[Limited Discoverable (Timeout %u secs)]",
776 _bt_get_discoverable_timeout_property());
777 param = g_variant_new("(in)", result, mode);
778 _bt_send_event(BT_ADAPTER_EVENT,
779 BLUETOOTH_EVENT_DISCOVERABLE_MODE_CHANGED,
781 } else if (strcasecmp(property, "Powered") == 0) {
782 /* TODO: Need to check this operation!! */
783 gboolean powered = FALSE;
786 g_variant_get(val, "b", &powered);
787 BT_DBG("Powered = %d", powered);
788 if (powered == FALSE) {
789 #ifdef TIZEN_FEATURE_BT_USB_DONGLE
790 _bt_handle_adapter_removed();
792 if (vconf_get_int(VCONFKEY_BT_STATUS, &bt_state) == 0 &&
793 bt_state != VCONFKEY_BT_STATUS_OFF) {
794 if (__bt_handle_is_flight_mode_enabled() == FALSE)
795 _bt_disable_adapter();
797 _bt_handle_adapter_removed();
800 if (vconf_get_int(VCONFKEY_BT_LE_STATUS, &bt_state) == 0 &&
801 bt_state != VCONFKEY_BT_LE_STATUS_OFF) {
802 _bt_set_le_disabled(BLUETOOTH_ERROR_NONE);
805 #ifdef TIZEN_FEATURE_BT_USB_DONGLE
806 _bt_handle_adapter_added();
809 } else if (strcasecmp(property, "Connectable") == 0) {
810 gboolean connectable = FALSE;
812 g_variant_get(val, "b", &connectable);
814 BT_DBG("Connectable property is changed : %d", connectable);
815 param = g_variant_new("(b)", connectable);
816 _bt_send_event(BT_ADAPTER_EVENT,
817 BLUETOOTH_EVENT_CONNECTABLE_CHANGED,
820 if (_bt_adapter_get_status() == BT_DEACTIVATING &&
821 _bt_adapter_get_le_status() == BT_LE_ACTIVATED &&
823 _bt_set_disabled(BLUETOOTH_ERROR_NONE);
825 } else if (strcasecmp(property, "SupportedLEFeatures") == 0) {
828 GVariantIter *iter = NULL;
829 g_variant_get(val, "as", &iter);
831 ret_if(iter == NULL);
833 while (g_variant_iter_loop(iter, "s", &name)) {
834 BT_DBG("name = %s", name);
835 g_variant_iter_loop(iter, "s", &value);
836 BT_DBG("Value = %s", value);
837 if (FALSE == _bt_update_le_feature_support(name, value))
838 BT_INFO("Fail to update LE feature info");
841 g_variant_iter_free(iter);
842 } else if (strcasecmp(property, "IpspInitStateChanged") == 0) {
843 gboolean ipsp_initialized = FALSE;
845 g_variant_get(val, "b", &ipsp_initialized);
846 BT_DBG("IPSP init state changed: %d", ipsp_initialized);
847 param = g_variant_new("(b)", ipsp_initialized);
849 /* Send event to application */
850 _bt_send_event(BT_ADAPTER_EVENT,
851 BLUETOOTH_EVENT_IPSP_INIT_STATE_CHANGED,
854 BT_DBG("property : [%s]", property);
859 static void __bt_obex_property_changed_event(GVariant *msg, const char *path)
863 GVariantIter value_iter;
864 GVariant *child = NULL, *val = NULL;
865 char *property = NULL;
866 g_variant_iter_init(&value_iter, msg);
867 while ((child = g_variant_iter_next_value(&value_iter))) {
868 g_variant_get(child, "{sv}", &property, &val);
870 ret_if(property == NULL);
872 BT_DBG("property :%s", property);
874 if (strcasecmp(property, "Status") == 0) {
876 g_variant_get(val, "s", &status);
878 if (strcasecmp(status, "active") == 0) {
879 _bt_obex_transfer_started(path);
880 } else if (strcasecmp(status, "complete") == 0) {
881 _bt_obex_transfer_completed(path, TRUE);
882 _bt_pbap_obex_transfer_completed(path, TRUE);
883 } else if (strcasecmp(status, "error") == 0) {
884 _bt_obex_transfer_completed(path, FALSE);
885 _bt_pbap_obex_transfer_completed(path, FALSE);
888 } else if (strcasecmp(property, "Transferred") == 0) {
889 guint64 transferred = 0;
890 /* As Transferred is expected guint64 so change int to guint64 and
891 * eariler transferred is static because of it can overwrite data
892 * on present on opc_obex_conn or obexd_conn as these are
893 * static memory are in sequential */
894 g_variant_get(val, "t", &transferred);
896 _bt_obex_transfer_progress(path, transferred);
898 /* TODO: MAP, "Complete"? see above */
900 g_variant_unref(val);
901 g_variant_unref(child);
906 static void __bt_device_property_changed_event(GVariant *msg, const char *path)
911 int result = BLUETOOTH_ERROR_NONE;
912 GVariantIter value_iter;
914 char *property = NULL;
916 GVariant *param = NULL;
917 bt_remote_dev_info_t *remote_dev_info;
918 g_variant_iter_init(&value_iter, msg);
919 #ifdef TIZEN_FEATURE_BT_DPM
920 int desktop_state = DPM_BT_ERROR;
922 while ((g_variant_iter_loop(&value_iter, "{sv}", &property, &val))) {
923 BT_DBG("Property %s", property);
924 if (strcasecmp(property, "Connected") == 0) {
927 g_variant_get(val, "i", &connected);
929 event = (connected != BLUETOOTH_CONNECTED_LINK_NONE) ?
930 BLUETOOTH_EVENT_DEVICE_CONNECTED :
931 BLUETOOTH_EVENT_DEVICE_DISCONNECTED;
933 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
935 _bt_convert_device_path_to_address(path, address);
937 BT_DBG("connected: %d", connected);
938 BT_DBG("address: %s", address);
940 remote_dev_info = _bt_get_remote_device_info_by_object_path(path);
942 if (remote_dev_info != NULL) {
943 __bt_device_remote_connected_properties(
944 remote_dev_info, address,
945 connected != BLUETOOTH_CONNECTED_LINK_NONE ?
947 _bt_free_device_info(remote_dev_info);
949 param = g_variant_new("(is)", result, address);
950 /* Send event to application */
951 _bt_send_event(BT_DEVICE_EVENT,
955 } else if (strcasecmp(property, "RSSI") == 0) {
956 bt_remote_dev_info_t *remote_dev_info;
958 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
960 _bt_convert_device_path_to_address(path, address);
961 BT_DBG("address: %s", address);
965 remote_dev_info = _bt_get_remote_device_info_by_object_path(path);
966 if (remote_dev_info == NULL) {
968 g_variant_unref(val);
971 BT_DBG("Address type %d", remote_dev_info->addr_type);
973 if (remote_dev_info->addr_type == 0) {
974 BT_DBG("Name %s", remote_dev_info->name);
976 #ifdef TIZEN_FEATURE_BT_DPM
977 _bt_dpm_get_bluetooth_desktop_connectivity_state(&desktop_state);
978 if (desktop_state == DPM_RESTRICTED) {
979 bluetooth_device_class_t device_class;
980 _bt_divide_device_class(&device_class, remote_dev_info->class);
982 if (device_class.major_class ==
983 BLUETOOTH_DEVICE_MAJOR_CLASS_COMPUTER) {
984 _bt_free_device_info(remote_dev_info);
986 g_variant_unref(val);
992 GVariant *uuids = NULL;
993 GVariantBuilder *builder = NULL;
995 builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
996 for (i = 0; i < remote_dev_info->uuid_count; i++) {
997 g_variant_builder_add(builder, "s",
998 remote_dev_info->uuids[i]);
1000 uuids = g_variant_new("as", builder);
1001 g_variant_builder_unref(builder);
1002 GVariant *manufacturer_data = NULL;
1003 manufacturer_data = g_variant_new_from_data(G_VARIANT_TYPE_BYTESTRING,
1004 remote_dev_info->manufacturer_data,
1005 remote_dev_info->manufacturer_data_len,
1008 param = g_variant_new("(isunsbub@asn@ay)", result,
1009 remote_dev_info->address,
1010 remote_dev_info->class,
1011 remote_dev_info->rssi,
1012 remote_dev_info->name,
1013 remote_dev_info->paired,
1014 remote_dev_info->connected,
1015 remote_dev_info->trust,
1017 remote_dev_info->manufacturer_data_len,
1020 _bt_send_event(BT_ADAPTER_EVENT,
1021 BLUETOOTH_EVENT_REMOTE_DEVICE_FOUND,
1024 _bt_free_device_info(remote_dev_info);
1025 } else if (strcasecmp(property, "GattConnected") == 0) {
1026 gboolean gatt_connected = FALSE;
1028 g_variant_get(val, "b", &gatt_connected);
1030 event = gatt_connected ? BLUETOOTH_EVENT_GATT_CONNECTED :
1031 BLUETOOTH_EVENT_GATT_DISCONNECTED;
1033 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1035 _bt_convert_device_path_to_address(path, address);
1037 BT_DBG("gatt_connected: %d", gatt_connected);
1038 BT_DBG("address: %s", address);
1039 param = g_variant_new("(is)", result, address);
1040 /* Send event to application */
1041 _bt_send_event(BT_DEVICE_EVENT,
1045 } else if (strcasecmp(property, "Paired") == 0) {
1046 gboolean paired = FALSE;
1047 bt_remote_dev_info_t *remote_dev_info;
1048 g_variant_get(val, "b", &paired);
1049 _bt_agent_set_canceled(FALSE);
1050 /* BlueZ sends paired signal for each paired device */
1051 /* during activation, We should ignore this, otherwise*/
1052 /* application thinks that a new device got paired */
1053 if (_bt_adapter_get_status() != BT_ACTIVATED) {
1054 BT_DBG("BT is not activated, so ignore this");
1056 g_variant_unref(val);
1060 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1062 _bt_convert_device_path_to_address(path, address);
1064 remote_dev_info = _bt_get_remote_device_info_by_object_path(path);
1065 if (remote_dev_info == NULL) {
1067 g_variant_unref(val);
1072 if (paired == FALSE) {
1073 BT_INFO("Unpaired: %s", address);
1074 __bt_update_remote_cache_devinfo(address, FALSE);
1075 param = g_variant_new("(is)", result, address);
1076 _bt_send_event(BT_ADAPTER_EVENT,
1077 BLUETOOTH_EVENT_BONDED_DEVICE_REMOVED,
1079 #ifdef TIZEN_BT_A2DP_SINK_AUTO_CONNECT
1081 char *last_connected = NULL;
1082 last_connected = vconf_get_str(BT_LAST_CONNECTED_DEVICE);
1083 if (!g_strcmp0(address, last_connected))
1084 _bt_audio_set_auto_connect_device_addr("");
1086 free(last_connected);
1090 char secure_addr[BT_ADDRESS_STRING_SIZE] = { 0 };
1092 _bt_convert_addr_string_to_secure_string(secure_addr, address);
1093 BT_INFO("### Paired: %s", secure_addr);
1094 __bt_update_remote_cache_devinfo(address, TRUE);
1096 if (_bt_is_device_creating() == TRUE) {
1097 BT_DBG("Try to Pair by me");
1098 _bt_free_device_info(remote_dev_info);
1101 g_variant_unref(val);
1104 GVariant *uuids = NULL;
1105 GVariantBuilder *builder = NULL;
1107 builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
1108 for (i = 0; i < remote_dev_info->uuid_count; i++) {
1109 g_variant_builder_add(builder, "s",
1110 remote_dev_info->uuids[i]);
1112 uuids = g_variant_new("as", builder);
1113 g_variant_builder_unref(builder);
1114 GVariant *manufacturer_data = NULL;
1115 manufacturer_data = g_variant_new_from_data(G_VARIANT_TYPE_BYTESTRING,
1116 remote_dev_info->manufacturer_data,
1117 remote_dev_info->manufacturer_data_len,
1121 param = g_variant_new("(isunsbub@asn@ay)", result,
1122 address, remote_dev_info->class,
1123 remote_dev_info->rssi,
1124 remote_dev_info->name,
1125 remote_dev_info->paired,
1126 remote_dev_info->connected,
1127 remote_dev_info->trust,
1129 remote_dev_info->manufacturer_data_len,
1131 _bt_send_event(BT_ADAPTER_EVENT,
1132 BLUETOOTH_EVENT_BONDING_FINISHED,
1135 _bt_free_device_info(remote_dev_info);
1137 } else if (strcasecmp(property, "LegacyPaired") == 0) {
1138 gboolean paired = FALSE;
1139 bt_remote_dev_info_t *remote_dev_info;
1140 unsigned char auth_info[5] = {0, };
1142 if (_bt_adapter_get_status() != BT_ACTIVATED) {
1143 BT_DBG("BT is not activated, so ignore this");
1145 g_variant_unref(val);
1149 g_variant_get(val, "b", &paired);
1150 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1151 BT_DBG("LegacyPaired: %d", paired);
1152 _bt_convert_device_path_to_address(path, address);
1154 remote_dev_info = _bt_get_remote_device_info_by_object_path(path);
1155 if (remote_dev_info == NULL) {
1158 g_variant_unref(val);
1161 if (remote_dev_info->is_alias_set == FALSE) {
1162 /*minimum Size of the samsung specific manufacturer data is greater than 30 */
1163 if ((remote_dev_info->manufacturer_data_len > 30) &&
1164 (remote_dev_info->manufacturer_data[0] == 0x00) &&
1165 (remote_dev_info->manufacturer_data[1] == 0x75)) {
1167 /* 2 samsung (0x00 0x75) + 1 (control and version) + 1 (service ID) +
1168 1 (discovery version) + 1 (associated service ID)
1169 2 (Proxamity and locality) + 2 (Device type and icon) = 10 */
1171 memcpy(auth_info, &(remote_dev_info->manufacturer_data[10]), 5);
1175 BT_DBG("LegacyPairing Failed with %s. Show Error Popup", remote_dev_info->name);
1176 _bt_launch_system_popup(BT_AGENT_EVENT_LEGACY_PAIR_FAILED_FROM_REMOTE,
1177 remote_dev_info->name, auth_info, NULL, NULL, NULL);
1179 _bt_free_device_info(remote_dev_info);
1181 } else if (strcasecmp(property, "Trusted") == 0) {
1182 gboolean trusted = FALSE;
1184 g_variant_get(val, "b", &trusted);
1186 event = trusted ? BLUETOOTH_EVENT_DEVICE_AUTHORIZED :
1187 BLUETOOTH_EVENT_DEVICE_UNAUTHORIZED;
1189 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1191 _bt_convert_device_path_to_address(path, address);
1193 BT_DBG("trusted: %d", trusted);
1194 BT_DBG("address: %s", address);
1195 param = g_variant_new("(is)", result, address);
1196 /* Send event to application */
1197 _bt_send_event(BT_DEVICE_EVENT,
1201 } else if (strcasecmp(property, "TrustedProfiles") == 0) {
1204 g_variant_get(val, "u", &trusted);
1206 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1207 _bt_convert_device_path_to_address(path, address);
1209 BT_DBG("Address: %s, TrustedProfiles: %d", address, trusted);
1210 _bt_send_event(BT_DEVICE_EVENT,
1211 BLUETOOTH_EVENT_SUPPORTED_PROFILE_TRUSTED,
1212 g_variant_new("(isi)", result, address, trusted));
1214 } else if (strcasecmp(property, "IpspConnected") == 0) {
1215 gboolean connected = FALSE;
1217 g_variant_get(val, "b", &connected);
1220 event = connected ? BLUETOOTH_EVENT_IPSP_CONNECTED :
1221 BLUETOOTH_EVENT_IPSP_DISCONNECTED;
1223 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1225 _bt_convert_device_path_to_address(path, address);
1227 BT_DBG("Ipspconnected: %d", connected);
1228 BT_DBG("address: %s", address);
1229 param = g_variant_new("(is)", result, address);
1231 /* Send event to application */
1232 _bt_send_event(BT_DEVICE_EVENT,
1236 } else if (strcasecmp(property, "IpspBtInterfaceInfo") == 0) {
1237 char *ifname = NULL;
1239 g_variant_get(val, "s", &ifname);
1241 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1243 _bt_convert_device_path_to_address(path, address);
1245 BT_DBG("Ipsp BT Interface Name: %s", ifname);
1246 BT_DBG("address: %s", address);
1247 param = g_variant_new("(iss)", result, address, ifname);
1249 /* Send event to application */
1250 _bt_send_event(BT_DEVICE_EVENT,
1251 BLUETOOTH_EVENT_IPSP_INTERFACE_INFO,
1259 static void __bt_media_control_changed_event(GVariant *msg, const char *path)
1262 int result = BLUETOOTH_ERROR_NONE;
1263 GVariantIter value_iter;
1264 char *property = NULL;
1266 GVariant *val = NULL;
1267 GVariant *child = NULL;
1268 bt_remote_dev_info_t *remote_dev_info;
1269 GVariant *param = NULL;
1270 g_variant_iter_init(&value_iter, msg);
1271 while ((child = g_variant_iter_next_value(&value_iter))) {
1272 g_variant_get(child, "{sv}", &property, &val);
1273 BT_INFO("Property %s", property);
1274 if (strcasecmp(property, "Connected") == 0) {
1275 gboolean connected = FALSE;
1277 g_variant_get(val, "b", &connected);
1279 event = connected ? BLUETOOTH_EVENT_AVRCP_CONNECTED :
1280 BLUETOOTH_EVENT_AVRCP_DISCONNECTED;
1282 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1284 _bt_convert_device_path_to_address(path, address);
1286 BT_DBG("connected: %d", connected);
1287 BT_DBG("address: %s", address);
1289 remote_dev_info = _bt_get_remote_device_info(address);
1291 if (remote_dev_info != NULL) {
1292 __bt_device_remote_connected_properties(
1293 remote_dev_info, address, connected);
1294 _bt_free_device_info(remote_dev_info);
1296 param = g_variant_new("(is)", result, address);
1297 /* Send event to application */
1298 _bt_send_event(BT_AVRCP_EVENT,
1304 g_variant_unref(child);
1305 g_variant_unref(val);
1310 int get_alert_level_enum(const char *alert)
1314 if (strcmp(alert, "none") == 0)
1315 lvl = BT_PXP_ALERT_NONE;
1316 else if (strcmp(alert, "mild") == 0)
1317 lvl = BT_PXP_ALERT_MILD;
1318 else if (strcmp(alert, "high") == 0)
1319 lvl = BT_PXP_ALERT_HIGH;
1324 static void _bt_handle_pxp_property_changed_event(GVariant *msg, const char *path, int role)
1326 int result = BLUETOOTH_ERROR_NONE;
1329 GVariantIter value_iter;
1330 char *property = NULL;
1332 GVariant *val = NULL;
1333 GVariant *child = NULL;
1334 GVariant *param = NULL;
1335 g_variant_iter_init(&value_iter, msg);
1338 while ((child = g_variant_iter_next_value(&value_iter))) {
1339 g_variant_get(child, "{sv}", &property, &val);
1340 BT_INFO("Property %s", property);
1342 if ((strcasecmp(property, "LinkLossAlertLevel") == 0) ||
1343 (strcasecmp(property, "ImmediateAlertLevel") == 0)) {
1344 char *alert_str = NULL;
1346 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1347 _bt_convert_device_path_to_address(path, address);
1349 if (strcasecmp(property, "LinkLossAlertLevel") == 0)
1350 service_type = BT_PXP_PROPERTY_LLS;
1352 service_type = BT_PXP_PROPERTY_IAS;
1354 g_variant_get(val, "s", &alert_str);
1356 alert_lvl = get_alert_level_enum(alert_str);
1358 param = g_variant_new("(isiii)", result, address,
1359 role, service_type, alert_lvl);
1361 /* Send event to application */
1362 _bt_send_event(BT_DEVICE_EVENT,
1363 BLUETOOTH_EVENT_PXP_PROPERTY_CHANGED,
1369 g_variant_unref(child);
1370 g_variant_unref(val);
1375 void _bt_handle_property_changed_event(GVariant *msg, const char *object_path)
1377 char *interface_name = NULL;
1378 GVariant *val = NULL;
1380 g_variant_get(msg, "(&s@a{sv}@as)", &interface_name, &val, NULL);
1382 if (strcasecmp(interface_name, BT_ADAPTER_INTERFACE) == 0) {
1383 __bt_adapter_property_changed_event(val,
1385 } else if (strcasecmp(interface_name, BT_DEVICE_INTERFACE) == 0) {
1386 __bt_device_property_changed_event(val, object_path);
1387 } else if (strcasecmp(interface_name, BT_OBEX_TRANSFER_INTERFACE) == 0) {
1388 BT_DBG("BT_OBEX_TRANSFER_INTERFACE");
1389 __bt_obex_property_changed_event(val,
1391 } else if (strcasecmp(interface_name, BT_MEDIA_CONTROL_INTERFACE) == 0) {
1392 __bt_media_control_changed_event(val,
1394 } else if (strcasecmp(interface_name, BT_PLAYER_CONTROL_INTERFACE) == 0) {
1395 _bt_handle_avrcp_control_event(val,
1397 } else if (strcasecmp(interface_name, BT_NETWORK_CLIENT_INTERFACE) == 0) {
1398 BT_DBG("BT_NETWORK_CLIENT_INTERFACE");
1399 _bt_handle_network_client_event(val,
1401 } else if (strcasecmp(interface_name, BT_GATT_CHAR_INTERFACE) == 0) {
1402 __bt_gatt_char_property_changed_event(val,
1404 } else if (strcasecmp(interface_name, BT_PROXIMITY_REPORTER_INTERFACE) == 0) {
1405 BT_DBG("BT_PROXIMITY_REPORTER_INTERFACE");
1406 _bt_handle_pxp_property_changed_event(val,
1407 object_path, BT_PXP_REPORTER_ROLE);
1409 g_variant_unref(val);
1412 void __bt_opc_property_changed_event(GVariant *msg,
1415 GVariantIter value_iter;
1416 char *property = NULL;
1417 GVariant *val = NULL;
1418 GVariant *child = NULL;
1420 g_variant_iter_init(&value_iter, msg);
1421 if ((child = g_variant_iter_next_value(&value_iter))) {
1422 g_variant_get(child, "{sv}", &property, &val);
1423 ret_if(property == NULL);
1425 if (strcasecmp(property, "Status") == 0) {
1426 char *status = NULL;
1427 g_variant_get(val, "s", &status);
1428 BT_DBG("Status is %s", status);
1430 if (strcasecmp(status, "active") == 0)
1431 _bt_obex_client_started(path);
1432 else if (strcasecmp(status, "complete") == 0)
1433 _bt_obex_client_completed(path, TRUE);
1434 else if (strcasecmp(status, "error") == 0)
1435 _bt_obex_client_completed(path, FALSE);
1438 } else if (strcasecmp(property, "Transferred") == 0) {
1439 guint64 transferred = 0;
1440 g_variant_get(val, "t", &transferred);
1442 _bt_obex_client_progress(path, transferred);
1444 BT_DBG("property : [%s]", property);
1447 g_variant_unref(child);
1448 g_variant_unref(val);
1452 void _bt_opc_property_changed_event(GVariant *msg, char *path)
1454 char *interface_name = NULL;
1455 GVariant *value = NULL;
1456 g_variant_get(msg, "(&s@a{sv}@as)", &interface_name, &value, NULL);
1457 BT_INFO("interface_name = %s", interface_name);
1458 if (strcasecmp(interface_name, BT_OBEX_TRANSFER_INTERFACE) == 0) {
1459 __bt_opc_property_changed_event(value,
1462 BT_DBG("interface_name : [%s]", interface_name);
1464 g_variant_unref(value);
1468 void __bt_map_property_changed_event(GVariant *msg,
1472 GVariantIter value_iter;
1473 char *property = NULL;
1474 GVariant *val = NULL;
1475 GVariant *child = NULL;
1477 g_variant_iter_init(&value_iter, msg);
1478 while ((child = g_variant_iter_next_value(&value_iter))) {
1479 g_variant_get(child, "{sv}", &property, &val);
1480 ret_if(property == NULL);
1482 if (strcasecmp(property, "Status") == 0) {
1483 char *status = NULL;
1484 g_variant_get(val, "s", &status);
1485 BT_DBG("Status is %s", status);
1487 if (strcasecmp(status, "active") == 0) {
1488 BT_DBG("EVENT : STARTED");
1489 // currently doing nothing
1490 } else if (strcasecmp(status, "complete") == 0) {
1491 BT_DBG("EVENT : COMPLETED");
1492 _bt_map_on_transfer_finished(path, BLUETOOTH_ERROR_NONE);
1493 } else if (strcasecmp(status, "error") == 0) {
1494 BT_DBG("EVENT : FAILED");
1495 _bt_map_on_transfer_finished(path, BLUETOOTH_ERROR_INTERNAL);
1498 } else if (strcasecmp(property, "Transferred") == 0) {
1499 guint64 transferred = 0;
1500 g_variant_get(val, "t", &transferred);
1502 BT_DBG("EVENT : PROGRESS CALLBACK");
1503 // currently doing nothing - progress callback type is not used
1505 BT_DBG("OTHER EVENT : property : [%s]", property);
1508 g_variant_unref(child);
1509 g_variant_unref(val);
1513 void _bt_map_property_changed_event(GVariant *msg, const char *path)
1515 BT_DBG("Entered _bt_map_property_changed_event");
1516 char *interface_name = NULL;
1517 GVariant *value = NULL;
1518 g_variant_get(msg, "(&s@a{sv}@as)", &interface_name, &value, NULL);
1519 BT_INFO("interface_name = %s", interface_name);
1520 if (strcasecmp(interface_name, BT_OBEX_TRANSFER_INTERFACE) == 0) {
1521 __bt_map_property_changed_event(value,
1524 BT_DBG("interface_name : [%s]", interface_name);
1526 g_variant_unref(value);
1530 void _bt_handle_input_event(GVariant *msg, const char *path)
1532 int result = BLUETOOTH_ERROR_NONE;
1533 gboolean property_flag = FALSE;
1534 GVariantIter value_iter;
1535 char *property = NULL;
1536 GVariant *child = NULL, *val = NULL;
1537 bt_remote_dev_info_t *remote_dev_info;
1538 GVariant *param = NULL;
1539 g_variant_iter_init(&value_iter, msg);
1540 while ((child = g_variant_iter_next_value(&value_iter))) {
1541 g_variant_get(child, "{sv}", &property, &val);
1543 ret_if(property == NULL);
1545 if (strcasecmp(property, "Connected") == 0) {
1546 int event = BLUETOOTH_EVENT_NONE;
1548 g_variant_get(val, "b", &property_flag);
1550 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1552 _bt_convert_device_path_to_address(path, address);
1554 event = (property_flag == TRUE) ?
1555 BLUETOOTH_HID_CONNECTED :
1556 BLUETOOTH_HID_DISCONNECTED;
1557 param = g_variant_new("(is)", result, address);
1558 _bt_send_event(BT_HID_EVENT, event,
1560 /* Check HID connection type (Keyboard or Mouse) and update the status */
1561 remote_dev_info = _bt_get_remote_device_info_by_object_path(path);
1563 if (property_flag == TRUE) {
1564 hid_connected_device_count++;
1565 __bt_set_device_values(TRUE,
1566 VCONFKEY_BT_DEVICE_HID_CONNECTED);
1568 hid_connected_device_count--;
1569 if (hid_connected_device_count == 0)
1570 __bt_set_device_values(FALSE,
1571 VCONFKEY_BT_DEVICE_HID_CONNECTED);
1574 if (remote_dev_info != NULL) {
1575 BT_DBG("HID device class [%x]", remote_dev_info->class);
1576 if (remote_dev_info->class &
1577 BLUETOOTH_DEVICE_MINOR_CLASS_KEY_BOARD) {
1578 __bt_set_device_values(property_flag,
1579 VCONFKEY_BT_DEVICE_HID_KEYBOARD_CONNECTED);
1583 if (remote_dev_info->class &
1584 BLUETOOTH_DEVICE_MINOR_CLASS_POINTING_DEVICE) {
1585 __bt_set_device_values(property_flag,
1586 VCONFKEY_BT_DEVICE_HID_MOUSE_CONNECTED);
1588 _bt_free_device_info(remote_dev_info);
1593 g_variant_unref(val);
1594 g_variant_unref(child);
1598 void _bt_handle_network_server_event(GVariant *msg, const char *member)
1600 int result = BLUETOOTH_ERROR_NONE;
1601 char *address = NULL;
1602 char *device = NULL;
1603 GVariant *param = NULL;
1604 ret_if(member == NULL);
1605 if (strcasecmp(member, "PeerConnected") == 0) {
1606 g_variant_get(msg, "(ss)", &device, &address);
1608 __bt_set_device_values(TRUE,
1609 VCONFKEY_BT_DEVICE_PAN_CONNECTED);
1610 param = g_variant_new("(iss)", result, device, address);
1611 _bt_send_event(BT_NETWORK_EVENT, BLUETOOTH_EVENT_NETWORK_SERVER_CONNECTED,
1615 nap_connected_device_count++;
1616 } else if (strcasecmp(member, "PeerDisconnected") == 0) {
1617 g_variant_get(msg, "(ss)", &device, &address);
1618 nap_connected_device_count--;
1619 if (nap_connected_device_count == 0)
1620 __bt_set_device_values(FALSE,
1621 VCONFKEY_BT_DEVICE_PAN_CONNECTED);
1622 param = g_variant_new("(iss)", result, device, address);
1623 _bt_send_event(BT_NETWORK_EVENT, BLUETOOTH_EVENT_NETWORK_SERVER_DISCONNECTED,
1630 void _bt_handle_network_client_event(GVariant *msg,
1635 int result = BLUETOOTH_ERROR_NONE;
1636 gboolean property_flag = FALSE;
1637 char *property = NULL;
1638 GVariant *val = NULL;
1639 GVariantIter value_iter;
1640 GVariant *param = NULL;
1641 g_variant_iter_init(&value_iter, msg);
1642 while ((g_variant_iter_loop(&value_iter, "{sv}", &property, &val))) {
1643 if (strcasecmp(property, "Connected") == 0) {
1644 int event = BLUETOOTH_EVENT_NONE;
1647 g_variant_get(val, "b", &property_flag);
1648 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1650 _bt_convert_device_path_to_address(path, address);
1652 BT_DBG("property_flag %d", property_flag);
1653 if (property_flag == TRUE) {
1654 event = BLUETOOTH_EVENT_NETWORK_CONNECTED;
1655 nap_connected_device_count++;
1656 __bt_set_device_values(TRUE,
1657 VCONFKEY_BT_DEVICE_PAN_CONNECTED);
1659 event = BLUETOOTH_EVENT_NETWORK_DISCONNECTED;
1660 nap_connected_device_count--;
1661 if (nap_connected_device_count == 0)
1662 __bt_set_device_values(FALSE,
1663 VCONFKEY_BT_DEVICE_PAN_CONNECTED);
1665 param = g_variant_new("(is)", result, address);
1666 _bt_send_event(BT_NETWORK_EVENT, event,
1675 void __bt_gatt_char_property_changed_event(GVariant *msg,
1678 GVariantIter value_iter;
1679 char *property = NULL;
1680 char * char_handle = NULL;
1681 GVariant *val = NULL;
1682 int result = BLUETOOTH_ERROR_NONE;
1683 GVariant *param = NULL;
1684 g_variant_iter_init(&value_iter, msg);
1685 char_handle = g_strdup(path);
1686 while ((g_variant_iter_loop(&value_iter, "{sv}", &property, &val))) {
1687 BT_INFO("Property %s", property);
1689 ret_if(property == NULL);
1691 if (strcasecmp(property, "Notifying") == 0) {
1692 gboolean property_flag = FALSE;
1693 g_variant_get(val, "b", &property_flag);
1694 if (property_flag == TRUE)
1695 BT_DBG("notifying is enabled");
1697 BT_DBG("notifying is disabled");
1698 } else if (strcasecmp(property, "ChangedValue") == 0) {
1700 GByteArray *gp_byte_array = NULL;
1701 BT_INFO("Type '%s'\n", g_variant_get_type_string(val));
1704 gp_byte_array = g_byte_array_new();
1705 len = g_variant_get_size(val);
1706 BT_DBG("Len = %d", len);
1707 g_byte_array_append(gp_byte_array,
1708 (const guint8 *) g_variant_get_data(val), len);
1709 if (gp_byte_array->len != 0) {
1710 GVariant *byte_array = NULL;
1711 byte_array = g_variant_new_from_data(
1712 G_VARIANT_TYPE_BYTESTRING,
1713 gp_byte_array->data,
1716 param = g_variant_new("(is@ay)", result, char_handle,
1719 /* Send event only registered client */
1720 _bt_send_char_value_changed_event(param);
1722 g_byte_array_free(gp_byte_array, TRUE);
1726 g_free(char_handle);
1729 void _bt_handle_gatt_event(GVariant *msg, const char *member, const char *path)
1731 ret_if(path == NULL);
1733 if (strcasecmp(member, "GattValueChanged") == 0) {
1736 /*** Debug only ***/
1737 GVariant *value = NULL;
1739 char *buffer = NULL;
1741 g_variant_get(msg, "(is@ay)", NULL, NULL, &value);
1742 value_len = g_variant_get_size(value);
1743 if (value_len > 0) {
1744 char buf[8 * 5 + 1] = { 0 };
1747 buffer = (char *)g_variant_get_data(value);
1748 to = value_len > (sizeof(buf) / 5) ? sizeof(buf) / 5 : value_len;
1750 for (i = 0; i < to; i++)
1751 snprintf(&buf[i * 5], 6, "0x%02x ", buffer[i]);
1753 BT_DBG("GATT Val[%d] %s", value_len, buf);
1755 g_variant_unref(value);
1759 /* Send event only registered client */
1760 _bt_send_char_value_changed_event(msg);
1765 void _bt_handle_device_event(GVariant *msg, const char *member, const char *path)
1768 int result = BLUETOOTH_ERROR_NONE;
1770 char *dev_name = NULL;
1771 const char *property = NULL;
1772 GVariant *param = NULL;
1773 char secure_address[BT_ADDRESS_STRING_SIZE] = { 0 };
1774 ret_if(path == NULL);
1776 if (strcasecmp(member, "PropertyChanged") == 0) {
1778 g_variant_get(msg, "(s)", &property);
1780 ret_if(property == NULL);
1782 if (strcasecmp(property, "GattConnected") == 0) {
1783 gboolean connected = FALSE;
1785 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1787 _bt_convert_device_path_to_address(path, address);
1788 g_variant_get(msg, "(b)", &connected);
1790 event = connected ? BLUETOOTH_EVENT_GATT_CONNECTED :
1791 BLUETOOTH_EVENT_GATT_DISCONNECTED;
1792 param = g_variant_new("(is)", result, address);
1793 _bt_send_event(BT_DEVICE_EVENT,
1797 } else if (strcasecmp(property, "Paired") == 0) {
1798 gboolean paired = FALSE;
1799 bt_remote_dev_info_t *remote_dev_info;
1800 g_variant_get(msg, "(b)", &paired);
1802 ret_if(paired == FALSE);
1804 /* BlueZ sends paired signal for each paired device */
1805 /* during activation, We should ignore this, otherwise*/
1806 /* application thinks that a new device got paired */
1807 if (_bt_adapter_get_status() != BT_ACTIVATED) {
1808 BT_DBG("BT is not activated, so ignore this");
1812 if (_bt_is_device_creating() == TRUE) {
1813 BT_DBG("Try to Pair by me");
1817 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1819 _bt_convert_device_path_to_address(path, address);
1821 remote_dev_info = _bt_get_remote_device_info_by_object_path(path);
1822 if (remote_dev_info == NULL) {
1826 GVariant *uuids = NULL;
1827 GVariantBuilder *builder = NULL;
1829 builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
1830 for (i = 0; i < remote_dev_info->uuid_count; i++) {
1831 g_variant_builder_add(builder, "s",
1832 remote_dev_info->uuids[i]);
1834 uuids = g_variant_new("as", builder);
1835 g_variant_builder_unref(builder);
1836 GVariant *manufacturer_data = NULL;
1837 manufacturer_data = g_variant_new_from_data(
1838 G_VARIANT_TYPE_BYTESTRING,
1839 remote_dev_info->manufacturer_data,
1840 remote_dev_info->manufacturer_data_len,
1842 param = g_variant_new("(isunsbub@asn@ay)", result,
1844 remote_dev_info->class,
1845 remote_dev_info->rssi,
1846 remote_dev_info->name,
1847 remote_dev_info->paired,
1848 remote_dev_info->connected,
1849 remote_dev_info->trust,
1851 remote_dev_info->manufacturer_data_len,
1853 _bt_send_event(BT_ADAPTER_EVENT,
1854 BLUETOOTH_EVENT_BONDING_FINISHED,
1856 _bt_free_device_info(remote_dev_info);
1859 } else if (strcasecmp(property, "UUIDs") == 0) {
1860 /* Once we get the updated uuid information after
1861 * reverse service search, update it to application */
1863 bt_remote_dev_info_t *remote_dev_info;
1865 ret_if(_bt_is_device_creating() == TRUE);
1867 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1869 _bt_convert_device_path_to_address(path, address);
1871 remote_dev_info = _bt_get_remote_device_info_by_object_path(path);
1872 if (remote_dev_info == NULL) {
1877 BT_DBG("UUID's count = %d", remote_dev_info->uuid_count);
1878 if (remote_dev_info->paired && remote_dev_info->uuid_count) {
1879 GVariant *uuids = NULL;
1880 GVariantBuilder *builder = NULL;
1882 builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
1883 for (i = 0; i < remote_dev_info->uuid_count; i++) {
1884 g_variant_builder_add(builder, "s",
1885 remote_dev_info->uuids[i]);
1887 uuids = g_variant_new("as", builder);
1888 g_variant_builder_unref(builder);
1889 GVariant *manufacture_data = g_variant_new_from_data((const GVariantType *)"ay",
1890 remote_dev_info->manufacturer_data, remote_dev_info->manufacturer_data_len,
1893 param = g_variant_new("(isunsbub@asn@ay)", result,
1894 address, remote_dev_info->class,
1895 remote_dev_info->rssi,
1896 remote_dev_info->name,
1897 remote_dev_info->paired,
1898 remote_dev_info->connected,
1899 remote_dev_info->trust,
1901 remote_dev_info->manufacturer_data_len,
1903 _bt_send_event(BT_ADAPTER_EVENT,
1904 BLUETOOTH_EVENT_SERVICE_SEARCHED,
1908 _bt_free_device_info(remote_dev_info);
1911 } else if (strcasecmp(member, "DeviceConnected") == 0) {
1912 unsigned char addr_type = 0;
1914 g_variant_get(msg, "(y)", &addr_type);
1916 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1918 _bt_convert_device_path_to_address(path, address);
1919 dev_name = _bt_get_bonded_device_name(address);
1921 _bt_convert_addr_string_to_secure_string(secure_address, address);
1922 BT_INFO("Address : %s Type : %d", secure_address, addr_type);
1923 BT_ERR_C("### Connected [%s] [%s]", !addr_type ? "BREDR" : "LE",
1924 !addr_type ? dev_name : secure_address);
1927 _bt_logging_connection(TRUE, addr_type);
1928 param = g_variant_new("(isy)", result, address, addr_type);
1929 /*Send event to application*/
1930 _bt_send_event(BT_DEVICE_EVENT,
1931 BLUETOOTH_EVENT_DEVICE_CONNECTED,
1934 } else if (strcasecmp(member, "Disconnected") == 0) {
1935 unsigned char disc_reason = 0;
1936 unsigned char addr_type = 0;
1937 char *dev_name = NULL;
1938 gboolean sending = FALSE;
1940 g_variant_get(msg, "(yys)", &addr_type, &disc_reason, &dev_name);
1942 result = disc_reason;
1944 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
1946 _bt_convert_device_path_to_address(path, address);
1948 /* 0x00 BDADDR_BRDER
1949 0x01 BDADDR_LE_PUBLIC
1950 0x02 BDADDR_LE_RANDOM */
1951 _bt_convert_addr_string_to_secure_string(secure_address, address);
1952 BT_INFO("Address : %s Type : %d", secure_address, addr_type);
1953 BT_ERR_C("### Disconnected [%s] [%d : %s] [%s]", !addr_type ? "BREDR" : "LE",
1954 disc_reason, _bt_convert_disc_reason_to_string(disc_reason),
1955 !addr_type ? dev_name : secure_address);
1958 _bt_headset_set_local_connection(FALSE);
1959 _bt_logging_connection(FALSE, addr_type);
1962 #ifdef TIZEN_BT_A2DP_SINK_AUTO_CONNECT
1964 int bt_device_state = VCONFKEY_BT_DEVICE_NONE;
1966 if (vconf_get_int(VCONFKEY_BT_DEVICE, &bt_device_state) != 0)
1967 BT_ERR("vconf_get_int failed");
1969 BT_INFO("conn_state[0x%x], adapter_state [%d]",
1970 bt_device_state, _bt_adapter_get_status());
1972 if (disc_reason == BLUETOOTH_ERROR_CONNECTION_TIMEOUT) {
1973 _bt_audio_start_auto_connect(TRUE);
1974 } else if (bt_device_state &
1975 VCONFKEY_BT_DEVICE_A2DP_SOURCE_CONNECTED) {
1976 BT_INFO("Disconnected due to turning BT off. Skip a address");
1978 char *last_connected = NULL;
1979 last_connected = vconf_get_str(BT_LAST_CONNECTED_DEVICE);
1980 if (!g_strcmp0(address, last_connected))
1981 _bt_audio_set_auto_connect_device_addr("");
1983 free(last_connected);
1988 /*Check for any OPP transfer on the device and cancel
1991 _bt_obex_check_pending_transfer(address);
1992 _bt_opp_client_is_sending(&sending);
1993 if (sending == TRUE)
1994 _bt_opp_client_check_pending_transfer(address);
1995 /* TODO: MAP? see above */
1997 param = g_variant_new("(isy)", result, address, addr_type);
1998 _bt_send_event(BT_DEVICE_EVENT,
1999 BLUETOOTH_EVENT_DEVICE_DISCONNECTED,
2002 } else if (strcasecmp(member, "ProfileStateChanged") == 0) {
2004 char *profile_uuid = NULL;
2005 bt_headset_wait_t *wait_list;
2006 bluetooth_device_address_t bd_addr;
2008 g_variant_get(msg, "(si)", &profile_uuid, &state);
2010 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
2012 _bt_convert_device_path_to_address(path, address);
2013 _bt_convert_addr_string_to_type(bd_addr.addr, address);
2015 _bt_convert_addr_string_to_secure_string(secure_address, address);
2016 BT_DBG("Address: %s", secure_address);
2017 BT_DBG("Profile UUID: %s", profile_uuid);
2018 BT_DBG("State: %d", state);
2020 if ((strcmp(profile_uuid, A2DP_SINK_UUID) == 0) &&
2021 (state == BT_PROFILE_STATE_CONNECTED)) {
2023 int event = BLUETOOTH_EVENT_AV_CONNECTED;
2024 char connected_address[BT_ADDRESS_STRING_SIZE + 1];
2025 bluetooth_device_address_t device_address;
2027 bt_headset_wait_t *wait_list;
2028 guint restricted = 0x0;
2030 __bt_set_device_values(TRUE,
2031 VCONFKEY_BT_DEVICE_A2DP_HEADSET_CONNECTED);
2033 __bt_connection_manager_set_state(address, event);
2035 _bt_get_restrict_profile(&bd_addr, RESTRICTED_PROFILE_HFP_HS, &restricted);
2037 if (_bt_headset_get_local_connection() == FALSE) {
2038 if (restricted == 0x0) /* not restricted*/
2039 _bt_start_timer_for_connection(address, BT_AUDIO_HSP);
2041 /* Connection Started from local device therefore no need to
2042 * intiate connection for pending profile */
2043 _bt_headset_set_local_connection(FALSE);
2045 param = g_variant_new("(is)", result, address);
2046 _bt_send_event(BT_HEADSET_EVENT, event,
2048 connected = _bt_is_headset_type_connected(BT_AUDIO_A2DP,
2051 if (g_strcmp0(connected_address, address) != 0) {
2052 _bt_convert_addr_string_to_type(
2053 device_address.addr,
2055 _bt_audio_disconnect(0, BT_AUDIO_A2DP,
2056 &device_address, NULL);
2060 _bt_add_headset_to_list(BT_AUDIO_A2DP,
2061 BT_STATE_CONNECTED, address);
2063 wait_list = _bt_get_audio_wait_data();
2064 if (wait_list != NULL &&
2065 (g_strcmp0(wait_list->address, address) == 0))
2066 _bt_rel_wait_data();
2068 } else if ((strcmp(profile_uuid, A2DP_SINK_UUID) == 0) &&
2069 (state == BT_PROFILE_STATE_DISCONNECTED)) {
2071 int event = BLUETOOTH_EVENT_AV_DISCONNECTED;
2073 if (!_bt_is_service_connected(address, BT_AUDIO_A2DP)) {
2075 g_free(profile_uuid);
2079 __bt_set_device_values(FALSE,
2080 VCONFKEY_BT_DEVICE_A2DP_HEADSET_CONNECTED);
2082 __bt_connection_manager_set_state(address, event);
2083 param = g_variant_new("(is)", result, address);
2084 _bt_send_event(BT_HEADSET_EVENT, event,
2086 /* Remove data from the connected list */
2087 _bt_remove_headset_from_list(BT_AUDIO_A2DP, address);
2088 wait_list = _bt_get_audio_wait_data();
2090 if (wait_list == NULL) {
2092 g_free(profile_uuid);
2096 if (((wait_list->type == BT_AUDIO_ALL) &&
2097 (wait_list->ag_flag == TRUE)) ||
2098 (wait_list->type == BT_AUDIO_A2DP) ||
2099 (wait_list->disconnection_type == BT_AUDIO_A2DP)) {
2100 bluetooth_device_address_t device_address;
2101 _bt_convert_addr_string_to_type(
2102 device_address.addr,
2103 wait_list->address);
2105 _bt_audio_connect(wait_list->req_id,
2110 } else if (strcmp(profile_uuid, AVRCP_TARGET_UUID) == 0) {
2112 if (state == BT_PROFILE_STATE_CONNECTED) {
2113 int event = BLUETOOTH_EVENT_AVRCP_CONTROL_CONNECTED;
2114 char connected_address[BT_ADDRESS_STRING_SIZE + 1];
2115 bluetooth_device_address_t device_address;
2117 param = g_variant_new("(is)", result, address);
2118 _bt_send_event(BT_AVRCP_CONTROL_EVENT, event,
2120 connected = _bt_is_headset_type_connected(
2124 if (g_strcmp0(connected_address,
2126 _bt_convert_addr_string_to_type(
2127 device_address.addr,
2129 _bt_audio_disconnect(0,
2131 &device_address, NULL);
2134 BT_DBG("device Path: %s", path);
2135 _bt_add_headset_to_list(BT_AVRCP,
2136 BT_STATE_CONNECTED, address);
2137 } else if (state == BT_PROFILE_STATE_DISCONNECTED) {
2138 int event = BLUETOOTH_EVENT_AVRCP_CONTROL_DISCONNECTED;
2139 param = g_variant_new("(is)", result, address);
2140 _bt_send_event(BT_AVRCP_CONTROL_EVENT, event,
2142 /* Remove data from the connected list */
2143 _bt_remove_headset_from_list(BT_AVRCP, address);
2145 } else if (strcasecmp(profile_uuid, A2DP_SOURCE_UUID) == 0) {
2146 if (state == BT_PROFILE_STATE_CONNECTED) {
2147 int event = BLUETOOTH_EVENT_AV_SOURCE_CONNECTED;
2148 BT_INFO("A2DP Source is connected");
2149 #ifdef TIZEN_BT_A2DP_SINK_ENABLE
2150 __bt_set_device_values(TRUE,
2151 VCONFKEY_BT_DEVICE_A2DP_SOURCE_CONNECTED);
2154 #ifdef TIZEN_BT_A2DP_SINK_AUTO_CONNECT
2155 _bt_audio_set_auto_connect_device_addr(address);
2156 _bt_audio_stop_auto_connect();
2158 _bt_add_headset_to_list(BT_AUDIO_A2DP_SOURCE,
2159 BT_STATE_CONNECTED, address);
2160 _bt_send_event(BT_A2DP_SOURCE_EVENT, event,
2161 g_variant_new("(is)", result, address));
2162 } else if (state == BT_PROFILE_STATE_DISCONNECTED) {
2163 int event = BLUETOOTH_EVENT_AV_SOURCE_DISCONNECTED;
2164 BT_INFO("A2DP Source Disconnected");
2165 #ifdef TIZEN_BT_A2DP_SINK_ENABLE
2166 __bt_set_device_values(FALSE,
2167 VCONFKEY_BT_DEVICE_A2DP_SOURCE_CONNECTED);
2169 _bt_remove_headset_from_list(BT_AUDIO_A2DP_SOURCE, address);
2170 _bt_send_event(BT_A2DP_SOURCE_EVENT, event,
2171 g_variant_new("(is)", result, address));
2173 wait_list = _bt_get_audio_wait_data();
2174 if (wait_list && wait_list->type == BT_AUDIO_A2DP_SOURCE) {
2175 bluetooth_device_address_t device_address;
2176 _bt_convert_addr_string_to_type(
2177 device_address.addr,
2178 wait_list->address);
2180 _bt_audio_connect(wait_list->req_id,
2184 /* Now free the wait list */
2185 _bt_rel_wait_data();
2188 } else if ((strcmp(profile_uuid, HID_UUID) == 0) &&
2189 ((state == BT_PROFILE_STATE_CONNECTED) ||
2190 (state == BT_PROFILE_STATE_DISCONNECTED))) {
2192 if (state == BT_PROFILE_STATE_CONNECTED)
2193 event = BLUETOOTH_HID_CONNECTED;
2195 event = BLUETOOTH_HID_DISCONNECTED;
2196 param = g_variant_new("(is)", result, address);
2197 _bt_send_event(BT_HID_EVENT, event,
2199 } else if (strcmp(profile_uuid, HID_DEVICE_UUID) == 0) {
2200 if (state == BT_PROFILE_STATE_CONNECTED) {
2202 event = BLUETOOTH_HID_DEVICE_CONNECTED;
2203 param = g_variant_new("(is)", result, address);
2204 _bt_send_event(BT_HID_DEVICE_EVENT, event,
2206 } else if (state == BT_PROFILE_STATE_DISCONNECTED) {
2207 event = BLUETOOTH_HID_DEVICE_DISCONNECTED;
2208 param = g_variant_new("(is)", result, address);
2209 _bt_send_event(BT_HID_DEVICE_EVENT, event,
2214 g_free(profile_uuid);
2215 } else if (strcasecmp(member, "AdvReport") == 0) {
2217 bt_remote_le_dev_info_t *le_dev_info = NULL;
2218 char *buffer = NULL;
2220 bt_le_adv_info_t *adv_info = NULL;
2221 GVariant *value = NULL;
2222 ret_if(_bt_is_le_scanning() == FALSE);
2224 le_dev_info = g_malloc0(sizeof(bt_remote_le_dev_info_t));
2226 g_variant_get(msg, "(syyii@ay)", &le_dev_info->address,
2227 &le_dev_info->addr_type,
2228 &le_dev_info->adv_type,
2230 &le_dev_info->adv_data_len,
2233 ret_if(value == NULL);
2235 _bt_convert_device_path_to_address(path, le_dev_info->address);
2237 buffer_len = g_variant_get_size(value);
2239 buffer = (char *)g_variant_get_data(value);
2241 le_dev_info->adv_data = g_memdup(buffer, buffer_len);
2242 if (le_dev_info->adv_data == NULL &&
2243 le_dev_info->adv_type != BT_LE_ADV_SCAN_RSP) {
2244 _bt_free_le_device_info(le_dev_info);
2245 g_variant_unref(value);
2249 if (_bt_get_le_scan_type() == BT_LE_PASSIVE_SCAN) {
2250 _bt_send_scan_result_event(le_dev_info, NULL);
2251 _bt_free_le_device_info(le_dev_info);
2252 g_variant_unref(value);
2256 if (le_dev_info->adv_type != BT_LE_ADV_SCAN_RSP) { /* ADV_IND */
2257 adv_info = g_malloc0(sizeof(bt_le_adv_info_t));
2258 adv_info->addr = g_strdup(le_dev_info->address);
2259 adv_info->addr_type = le_dev_info->addr_type;
2260 adv_info->rssi = le_dev_info->rssi;
2261 adv_info->data_len = le_dev_info->adv_data_len;
2262 adv_info->data = g_malloc0(le_dev_info->adv_data_len);
2263 memcpy(adv_info->data, le_dev_info->adv_data,
2264 le_dev_info->adv_data_len);
2266 if (__bt_add_adv_ind_info(adv_info) == 0) {
2267 adv_info->timer_id = g_timeout_add(1000,
2268 (GSourceFunc)__bt_adv_scan_req_timeout_cb, (void*)adv_info);
2270 } else { /* SCAN_RSP */
2271 adv_info = __bt_get_adv_ind_info(le_dev_info->address);
2273 _bt_send_scan_result_event(le_dev_info, adv_info);
2274 __bt_del_adv_ind_info(le_dev_info->address);
2277 _bt_free_le_device_info(le_dev_info);
2278 g_variant_unref(value);
2279 } else if (strcasecmp(member, "LEDataLengthChanged") == 0) {
2280 guint16 tx_octets = 0;
2281 guint16 tx_time = 0;
2282 guint16 rx_octets = 0;
2283 guint16 rx_time = 0;
2285 g_variant_get(msg, "(qqqq)",
2286 &tx_octets, &tx_time, &rx_octets, &rx_time);
2288 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
2289 _bt_convert_device_path_to_address(path, address);
2291 param = g_variant_new("(isqqqq)", result, address, tx_octets, tx_time,
2292 rx_octets, rx_time);
2293 /* Send event to application */
2294 _bt_send_event(BT_DEVICE_EVENT,
2295 BLUETOOTH_EVENT_LE_DATA_LENGTH_CHANGED, param);
2297 } else if (strcasecmp(member, "IpspStateChanged") == 0) {
2298 gboolean connected = FALSE;
2299 char *ifname = NULL;
2301 g_variant_get(msg, "(bs)", &connected, &ifname);
2303 event = connected ? BLUETOOTH_EVENT_IPSP_CONNECTED :
2304 BLUETOOTH_EVENT_IPSP_DISCONNECTED;
2306 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
2307 _bt_convert_device_path_to_address(path, address);
2309 BT_DBG("Ipsp BT Interface Name: %s", ifname);
2310 BT_DBG("address: %s", address);
2311 param = g_variant_new("(iss)", result, address, ifname);
2313 /* Send event to application */
2314 _bt_send_event(BT_DEVICE_EVENT,
2321 void __bt_set_audio_values(gboolean connected, char *address)
2324 int bt_device_state = VCONFKEY_BT_DEVICE_NONE;
2326 /* Set the headset name */
2327 if (connected == TRUE)
2328 name = _bt_get_bonded_device_name(address);
2330 name = g_strdup("");
2332 if (vconf_set_str(VCONFKEY_BT_HEADSET_NAME, name) != 0)
2333 BT_ERR("vconf_set_str failed");
2337 /* Set the headset state */
2338 if (vconf_get_int(VCONFKEY_BT_DEVICE, &bt_device_state) != 0)
2339 BT_ERR("vconf_get_int failed");
2341 #ifdef TIZEN_SUPPORT_DUAL_HF
2342 if ((connected == TRUE) &&
2343 (FALSE == __bt_is_companion_device(address))) {
2344 bt_device_state |= VCONFKEY_BT_DEVICE_HEADSET_CONNECTED;
2345 } else if ((bt_device_state & VCONFKEY_BT_DEVICE_HEADSET_CONNECTED) &&
2346 (FALSE == __bt_is_companion_device(address))) {
2347 bt_device_state ^= VCONFKEY_BT_DEVICE_HEADSET_CONNECTED;
2350 if (connected == TRUE)
2351 bt_device_state |= VCONFKEY_BT_DEVICE_HEADSET_CONNECTED;
2352 else if (bt_device_state & VCONFKEY_BT_DEVICE_HEADSET_CONNECTED)
2353 bt_device_state ^= VCONFKEY_BT_DEVICE_HEADSET_CONNECTED;
2356 if (vconf_set_int(VCONFKEY_BT_DEVICE,
2357 bt_device_state) != 0) {
2358 BT_ERR("vconf_set_int failed");
2362 void _bt_handle_headset_event(GVariant *msg, const char *path)
2364 int result = BLUETOOTH_ERROR_NONE;
2365 gboolean property_flag = FALSE;
2366 char *property = NULL;
2367 GVariant *value = NULL;
2368 GVariant *param = NULL;
2369 g_variant_get(msg, "(sv)", &property, &value);
2370 bluetooth_device_address_t bd_addr;
2372 ret_if(property == NULL);
2374 BT_DBG("Property = %s \n", property);
2375 /* We allow only 1 headset connection (HSP or HFP)*/
2376 if (strcasecmp(property, "Connected") == 0) {
2377 int event = BLUETOOTH_EVENT_NONE;
2378 bt_headset_wait_t *wait_list;
2380 guint restricted = 0x0;
2381 g_variant_get(value, "b", &property_flag);
2383 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
2385 _bt_convert_device_path_to_address(path, address);
2386 _bt_convert_addr_string_to_type(bd_addr.addr, address);
2388 if (property_flag == TRUE) {
2389 event = BLUETOOTH_EVENT_AG_CONNECTED;
2390 _bt_get_restrict_profile(&bd_addr, RESTRICTED_PROFILE_A2DP, &restricted);
2392 if (_bt_headset_get_local_connection() == FALSE) {
2393 if (restricted == 0x0) /* not restricted*/
2394 _bt_start_timer_for_connection(address, BT_AUDIO_A2DP);
2396 _bt_headset_set_local_connection(FALSE);
2400 event = BLUETOOTH_EVENT_AG_DISCONNECTED;
2402 previous_state = _bt_get_device_state_from_list(BT_AUDIO_HSP, address);
2403 if (previous_state == BT_STATE_DISCONNECTING)
2404 _bt_send_hf_local_term_event(address);
2406 /* Set the State machine here */
2407 __bt_connection_manager_set_state(address, event);
2408 __bt_set_audio_values(property_flag, address);
2409 param = g_variant_new("(is)", result, address);
2410 _bt_send_event(BT_HEADSET_EVENT, event,
2413 if (event == BLUETOOTH_EVENT_AG_DISCONNECTED) {
2414 /* Remove data from the connected list */
2415 _bt_remove_headset_from_list(BT_AUDIO_HSP, address);
2417 wait_list = _bt_get_audio_wait_data();
2418 if (wait_list == NULL) {
2423 bluetooth_device_address_t device_address;
2425 _bt_set_audio_wait_data_flag(TRUE);
2427 _bt_convert_addr_string_to_type(device_address.addr,
2428 wait_list->address);
2429 _bt_audio_connect(wait_list->req_id, wait_list->type,
2430 &device_address, NULL);
2431 _bt_rel_wait_data();
2432 } else if (event == BLUETOOTH_EVENT_AG_CONNECTED) {
2433 /* Add data to the connected list */
2434 _bt_add_headset_to_list(BT_AUDIO_HSP,
2435 BT_STATE_CONNECTED, address);
2437 wait_list = _bt_get_audio_wait_data();
2438 if (wait_list != NULL &&
2439 (g_strcmp0(wait_list->address, address) == 0))
2440 _bt_rel_wait_data();
2442 BT_INFO("Check A2DP pending connect");
2443 _bt_audio_check_pending_connect();
2446 } else if (strcasecmp(property, "State") == 0) {
2449 g_variant_get(value, "s", &state);
2451 /* This code assumes we support only 1 headset connection */
2452 /* Need to use the headset list, if we support multi-headsets */
2453 if (strcasecmp(state, "Playing") == 0) {
2454 BT_DBG("Playing: Sco Connected");
2455 } else if (strcasecmp(state, "connected") == 0 ||
2456 strcasecmp(state, "disconnected") == 0) {
2457 BT_DBG("connected/disconnected: Sco Disconnected");
2459 BT_ERR("Not handled state - %s", state);
2464 } else if (strcasecmp(property, "SpeakerGain") == 0) {
2468 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
2470 _bt_convert_device_path_to_address(path, address);
2472 spkr_gain = g_variant_get_uint16(value);
2474 BT_DBG("spkr_gain: %d", spkr_gain);
2476 param = g_variant_new("(i&sq)", result, address, spkr_gain);
2477 _bt_send_event(BT_HEADSET_EVENT, BLUETOOTH_EVENT_AG_SPEAKER_GAIN,
2481 } else if (strcasecmp(property, "MicrophoneGain") == 0) {
2485 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
2487 _bt_convert_device_path_to_address(path, address);
2489 mic_gain = g_variant_get_uint16(value);
2491 param = g_variant_new("(i&sq)", result, address, mic_gain);
2492 _bt_send_event(BT_HEADSET_EVENT, BLUETOOTH_EVENT_AG_MIC_GAIN,
2499 g_variant_unref(value);
2502 void _bt_handle_sink_event(GVariant *msg, const char *path)
2504 GVariantIter value_iter;
2505 char *property = NULL;
2507 bt_headset_wait_t *wait_list;
2509 GVariant *child = NULL;
2510 GVariant *val = NULL;
2511 GVariant *param = NULL;
2512 g_variant_iter_init(&value_iter, msg);
2513 while ((child = g_variant_iter_next_value(&value_iter))) {
2515 g_variant_get(child, "{sv}", &property, &val);
2517 ret_if(property == NULL);
2519 BT_DBG("Property = %s \n", property);
2522 if (strcasecmp(property, "State") == 0) {
2523 int result = BLUETOOTH_ERROR_NONE;
2526 g_variant_get(val, "s", &value);
2527 BT_DBG("value: %s", value);
2529 if (g_strcmp0(value, "disconnected") == 0) {
2532 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
2534 _bt_convert_device_path_to_address(path, address);
2536 __bt_set_device_values(FALSE,
2537 VCONFKEY_BT_DEVICE_A2DP_HEADSET_CONNECTED);
2538 param = g_variant_new("(is)", result, address);
2539 _bt_send_event(BT_HEADSET_EVENT,
2540 BLUETOOTH_EVENT_AV_DISCONNECTED,
2543 /* Remove data from the connected list */
2544 _bt_remove_headset_from_list(BT_AUDIO_A2DP, address);
2545 wait_list = _bt_get_audio_wait_data();
2546 if (wait_list == NULL) {
2549 g_variant_unref(val);
2550 g_variant_unref(child);
2555 if (((wait_list->type == BT_AUDIO_ALL) &&
2556 (wait_list->ag_flag == TRUE)) ||
2557 (wait_list->type == BT_AUDIO_A2DP) ||
2558 (wait_list->disconnection_type == BT_AUDIO_A2DP)) {
2559 bluetooth_device_address_t device_address;
2560 _bt_convert_addr_string_to_type(
2561 device_address.addr,
2562 wait_list->address);
2564 _bt_audio_connect(wait_list->req_id,
2570 } else if (strcasecmp(value, "Connected") == 0) {
2572 char connected_address[BT_ADDRESS_STRING_SIZE + 1];
2573 bluetooth_device_address_t device_address;
2576 address = g_malloc0(BT_ADDRESS_STRING_SIZE);
2578 _bt_convert_device_path_to_address(path, address);
2580 __bt_set_device_values(TRUE,
2581 VCONFKEY_BT_DEVICE_A2DP_HEADSET_CONNECTED);
2582 param = g_variant_new("(is)", result, address);
2583 _bt_send_event(BT_HEADSET_EVENT,
2584 BLUETOOTH_EVENT_AV_CONNECTED,
2586 /* Check for existing Media device to disconnect */
2587 connected = _bt_is_headset_type_connected(BT_AUDIO_A2DP,
2590 /* Match connected device address */
2591 if (g_strcmp0(connected_address, address) != 0) {
2592 /* Convert BD adress from string type */
2593 _bt_convert_addr_string_to_type(
2594 device_address.addr,
2596 _bt_audio_disconnect(0, BT_AUDIO_A2DP,
2597 &device_address, NULL);
2601 /* Add data to the connected list */
2602 _bt_add_headset_to_list(BT_AUDIO_A2DP,
2603 BT_STATE_CONNECTED, address);
2610 g_variant_unref(val);
2611 g_variant_unref(child);
2615 void _bt_handle_agent_event(GVariant *msg, const char *member)
2617 int result = BLUETOOTH_ERROR_NONE;
2618 char *address = NULL;
2621 GVariant *param = NULL;
2622 ret_if(member == NULL);
2624 if (strcasecmp(member, "ObexAuthorize") == 0) {
2625 __bt_get_agent_signal_info(msg, &address, &name, &uuid);
2626 param = g_variant_new("(iss)", result, address, name);
2627 _bt_send_event(BT_OPP_SERVER_EVENT,
2628 BLUETOOTH_EVENT_OBEX_SERVER_CONNECTION_AUTHORIZE,
2630 /* TODO: MAP? see above */
2633 } else if (strcasecmp(member, "RfcommAuthorize") == 0) {
2634 bt_rfcomm_server_info_t *server_info;
2636 __bt_get_agent_signal_info(msg, &address, &name, &uuid);
2638 server_info = _bt_rfcomm_get_server_info_using_uuid(uuid);
2639 ret_if(server_info == NULL);
2640 ret_if(server_info->server_type != BT_CUSTOM_SERVER);
2641 param = g_variant_new("(isssn)", result, address, uuid, name,
2642 server_info->control_fd);
2643 _bt_send_event(BT_RFCOMM_SERVER_EVENT,
2644 BLUETOOTH_EVENT_RFCOMM_AUTHORIZE,
2652 static int __bt_get_object_path(GVariant *msg, char **path)
2654 g_variant_get(msg, "(o*)", path, NULL);
2656 return BLUETOOTH_ERROR_INTERNAL;
2658 return BLUETOOTH_ERROR_NONE;
2661 static void __bt_devices_list_free(void)
2663 bt_cache_info_t *cache_info;
2666 node = g_list_first(p_cache_list);
2668 while (node != NULL) {
2669 cache_info = (bt_cache_info_t *)node->data;
2670 p_cache_list = g_list_remove(p_cache_list, cache_info);
2671 __bt_free_cache_info(cache_info);
2673 node = g_list_next(node);
2677 static int __bt_parse_event(GVariant *msg)
2681 char *interface_name = NULL;
2682 GVariant *inner_iter = NULL;
2684 g_variant_iter_init(&iter, msg);
2686 while ((child = g_variant_iter_next_value(&iter))) {
2687 g_variant_get(child, "{&s@a{sv}}", &interface_name, &inner_iter);
2688 if (g_strcmp0(interface_name,
2689 BT_DEVICE_INTERFACE) == 0) {
2690 g_variant_unref(inner_iter);
2691 g_variant_unref(child);
2692 return BT_DEVICE_EVENT;
2693 } else if (g_strcmp0(interface_name,
2694 BT_MEDIATRANSPORT_INTERFACE) == 0) {
2695 g_variant_unref(inner_iter);
2696 g_variant_unref(child);
2697 return BT_MEDIA_TRANSFER_EVENT;
2698 } else if (g_strcmp0(interface_name,
2699 BT_PLAYER_CONTROL_INTERFACE) == 0) {
2700 g_variant_unref(inner_iter);
2701 g_variant_unref(child);
2702 return BT_AVRCP_CONTROL_EVENT;
2704 g_variant_unref(inner_iter);
2705 g_variant_unref(child);
2711 static void __bt_manager_event_filter(GDBusConnection *connection,
2712 const gchar *sender_name,
2713 const gchar *object_path,
2714 const gchar *interface_name,
2715 const gchar *signal_name,
2716 GVariant *parameters,
2719 bt_event_type_t bt_event = 0x00;
2720 int result = BLUETOOTH_ERROR_NONE;
2722 char *obj_path = NULL;
2723 GVariant *param = NULL;
2724 if (signal_name == NULL)
2726 if (strcasecmp(signal_name, "InterfacesAdded") == 0) {
2727 g_variant_get(parameters, "(&o@a{sa{sv}})", &obj_path, &value);
2729 if (strcasecmp(obj_path, BT_BLUEZ_HCI_PATH) == 0) {
2730 #ifdef TIZEN_FEATURE_BT_USB_DONGLE
2731 BT_DBG("Enable Adapter");
2732 _bt_enable_adapter();
2734 _bt_handle_adapter_added();
2737 bt_event = __bt_parse_event(value);
2738 if (bt_event == BT_DEVICE_EVENT) {
2739 bt_cache_info_t *cache_info;
2740 bt_remote_dev_info_t *dev_info;
2741 #ifdef TIZEN_FEATURE_BT_DPM
2742 int desktop_state = DPM_BT_ERROR;
2744 ret_if(_bt_is_discovering() == FALSE &&
2745 _bt_is_le_scanning() == FALSE);
2747 cache_info = g_malloc0(sizeof(bt_cache_info_t));
2749 dev_info = g_malloc0(sizeof(bt_remote_dev_info_t));
2751 cache_info->dev_info = dev_info;
2753 if (__bt_parse_interface(parameters, dev_info) == FALSE) {
2754 BT_ERR("Fail to parse the properies");
2755 __bt_free_cache_info(cache_info);
2756 g_variant_unref(value);
2760 if (dev_info->addr_type != BDADDR_BREDR) {
2761 /* Whenever emit the property changed from bluez,
2762 some property doesn't reach to bt-service.
2763 So LE device is handled as AdvReport signal */
2764 __bt_free_cache_info(cache_info);
2765 g_variant_unref(value);
2769 if (dev_info->name == NULL)
2770 /* If Remote device name is NULL or still RNR is not done
2771 * then display address as name.
2773 dev_info->name = g_strdup(dev_info->address);
2775 #ifdef TIZEN_FEATURE_BT_DPM
2776 _bt_dpm_get_bluetooth_desktop_connectivity_state(&desktop_state);
2777 if (desktop_state == DPM_RESTRICTED) {
2778 bluetooth_device_class_t device_class;
2779 _bt_divide_device_class(&device_class, dev_info->class);
2780 BT_DBG("[%s]device_class.major_class : %d", dev_info->name, device_class.major_class);
2782 if (device_class.major_class ==
2783 BLUETOOTH_DEVICE_MAJOR_CLASS_COMPUTER) {
2784 __bt_free_cache_info(cache_info);
2785 g_variant_unref(value);
2791 GVariant *uuids = NULL;
2792 GVariantBuilder *builder = NULL;
2794 builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
2795 for (i = 0; i < dev_info->uuid_count; i++) {
2796 g_variant_builder_add(builder, "s",
2797 dev_info->uuids[i]);
2799 uuids = g_variant_new("as", builder);
2800 g_variant_builder_unref(builder);
2801 GVariant *manufacturer_data = NULL;
2802 manufacturer_data = g_variant_new_from_data(
2803 G_VARIANT_TYPE_BYTESTRING,
2804 dev_info->manufacturer_data,
2805 dev_info->manufacturer_data_len,
2807 param = g_variant_new("(isunsbub@asn@ay)", result,
2813 dev_info->connected,
2816 dev_info->manufacturer_data_len,
2818 _bt_send_event(BT_ADAPTER_EVENT,
2819 BLUETOOTH_EVENT_REMOTE_DEVICE_FOUND,
2821 p_cache_list = g_list_append(p_cache_list, cache_info);
2822 } else if (bt_event == BT_AVRCP_CONTROL_EVENT) {
2823 BT_DBG("Device path : %s ", obj_path);
2824 _bt_set_control_device_path(obj_path);
2827 g_variant_unref(value);
2828 } else if (strcasecmp(signal_name, "InterfacesRemoved") == 0) {
2829 #ifdef TIZEN_FEATURE_BT_USB_DONGLE
2830 BT_DBG("InterfacesRemoved");
2831 _bt_handle_adapter_removed();
2833 if (g_strcmp0(interface_name, BT_MEDIATRANSPORT_INTERFACE) == 0)
2834 bt_event = BT_MEDIA_TRANSFER_EVENT;
2835 else if (g_strcmp0(interface_name, BT_DEVICE_INTERFACE) == 0)
2836 bt_event = BT_DEVICE_EVENT;
2837 else if (g_strcmp0(interface_name, BT_PLAYER_CONTROL_INTERFACE) == 0)
2838 bt_event = BT_AVRCP_CONTROL_EVENT;
2840 if ((bt_event != 0) && (bt_event != BT_MEDIA_TRANSFER_EVENT)) {
2841 _bt_handle_adapter_event(parameters, signal_name);
2842 if (bt_event == BT_AVRCP_CONTROL_EVENT) {
2843 BT_INFO("Object Path %s", obj_path);
2844 _bt_remove_control_device_path(obj_path);
2847 } else if (strcasecmp(signal_name, "NameOwnerChanged") == 0) {
2850 char *previous = NULL;
2851 char *current = NULL;
2853 if (__bt_get_owner_info(parameters, &name, &previous, ¤t)) {
2854 BT_ERR("Fail to get the owner info");
2858 if (*current != '\0') {
2867 if (strcasecmp(name, BT_BLUEZ_NAME) == 0) {
2868 BT_INFO_C("### Bluetoothd is terminated");
2869 if (_bt_adapter_get_status() != BT_DEACTIVATING &&
2870 _bt_adapter_get_status() != BT_DEACTIVATED) {
2871 BT_INFO_C("### Recover it");
2872 _bt_recover_adapter();
2874 _bt_handle_adapter_removed();
2875 __bt_devices_list_free();
2878 _bt_obex_server_check_allocation(&value);
2880 if (value == TRUE) {
2881 /* Check if the obex server was terminated abnormally */
2882 _bt_obex_server_check_termination(name);
2885 _bt_rfcomm_server_check_existence(&value);
2887 if (value == TRUE) {
2888 /* The obex server was terminated abnormally */
2889 _bt_rfcomm_server_check_termination(name);
2892 /* Stop advertising started by terminated process */
2893 _bt_stop_advertising_by_terminated_process(name);
2895 _bt_stop_le_scan(name);
2897 /* Stop the Proximity reporter service */
2898 _bt_proximity_reporter_stop_by_terminated_process(name);
2903 } else if (g_strcmp0(interface_name, BT_PROPERTIES_INTERFACE) == 0) {
2904 const char *path = object_path;
2906 if (strncmp(path, BT_MEDIA_OBJECT_PATH,
2907 strlen(BT_MEDIA_OBJECT_PATH)) == 0)
2910 _bt_handle_property_changed_event(parameters, object_path);
2911 } else if (g_strcmp0(interface_name, BT_ADAPTER_INTERFACE) == 0) {
2912 _bt_handle_adapter_event(parameters, signal_name);
2913 } else if (g_strcmp0(interface_name, BT_INPUT_INTERFACE) == 0) {
2914 _bt_handle_input_event(parameters, object_path);
2915 } else if (g_strcmp0(interface_name, BT_NETWORK_SERVER_INTERFACE) == 0) {
2916 _bt_handle_network_server_event(parameters, signal_name);
2917 } else if (g_strcmp0(interface_name, BT_HEADSET_INTERFACE) == 0) {
2918 _bt_handle_headset_event(parameters, object_path);
2919 } else if (g_strcmp0(interface_name, BT_SINK_INTERFACE) == 0) {
2920 _bt_handle_sink_event(parameters, object_path);
2921 } else if (g_strcmp0(interface_name, BT_AGENT_INTERFACE) == 0) {
2922 _bt_handle_agent_event(parameters, signal_name);
2923 } else if (g_strcmp0(interface_name, BT_DEVICE_INTERFACE) == 0) {
2924 _bt_handle_device_event(parameters, signal_name, object_path);
2925 } else if (g_strcmp0(interface_name, BT_GATT_CHAR_INTERFACE) == 0) {
2926 _bt_handle_gatt_event(parameters, signal_name, object_path);
2932 static gboolean __bt_is_obexd_event(GVariant *msg, const char *interface)
2935 if (g_strcmp0(interface, BT_PROPERTIES_INTERFACE) == 0) {
2936 char *interface_name = NULL;
2938 g_variant_get(msg, "(&s@a{sv}@as)", &interface_name, NULL, NULL);
2939 retv_if(interface_name == NULL, FALSE);
2941 if (strcasecmp(interface_name, BT_OBEX_TRANSFER_INTERFACE) == 0) {
2942 BT_DBG("BT_OBEX_TRANSFER_INTERFACE");
2950 static void __bt_obexd_event_filter(GDBusConnection *connection,
2951 const gchar *sender_name,
2952 const gchar *object_path,
2953 const gchar *interface_name,
2954 const gchar *signal_name,
2955 GVariant *parameters,
2958 const char *member = signal_name;
2959 char *obj_path = NULL;
2960 ret_if(member == NULL);
2962 if (strcasecmp(member, "InterfacesAdded") == 0) {
2963 if (__bt_get_object_path(parameters, &obj_path)) {
2964 BT_ERR("Fail to get the path");
2967 BT_INFO("object_path = [%s]", obj_path);
2969 /*Handle OPP_SERVER_CONNECTED_EVENT here */
2970 /* TODO: MAP? see above */
2971 if (strncmp(obj_path, BT_SESSION_BASEPATH_SERVER,
2972 strlen(BT_SESSION_BASEPATH_SERVER)) != 0) {
2977 if (g_strrstr(obj_path, "session") && g_strrstr(obj_path, "transfer")) {
2978 BT_DBG("Obex_Server_Session_Transfer connected");
2979 _bt_obex_transfer_connected(obj_path);
2982 } else if (strcasecmp(member, "InterfacesRemoved") == 0) {
2983 /*Handle OPP_SERVER_DISCONNECTED_EVENT here */
2984 /* TODO: MAP? see above */
2985 if (__bt_get_object_path(parameters, &obj_path)) {
2986 BT_ERR("Fail to get the path");
2989 BT_INFO("object_path = [%s]", obj_path);
2991 if (strncmp(obj_path, BT_SESSION_BASEPATH_CLIENT,
2992 strlen(BT_SESSION_BASEPATH_CLIENT)) == 0) {
2993 BT_DBG("Call PBAP Disconnected");
2994 _bt_obex_pbap_client_disconnect(obj_path);
2997 if (strncmp(obj_path, BT_SESSION_BASEPATH_SERVER,
2998 strlen(BT_SESSION_BASEPATH_SERVER)) != 0) {
3003 if (g_strrstr(obj_path, "session") && g_strrstr(obj_path, "transfer")) {
3004 BT_DBG("Obex_Server_Session_Transfer disconnected %s",
3007 _bt_obex_transfer_disconnected(obj_path);
3010 } else if (__bt_is_obexd_event(parameters, interface_name) == TRUE) {
3011 const char *path = object_path;
3013 if (strncmp(path, BT_SESSION_BASEPATH_SERVER,
3014 strlen(BT_SESSION_BASEPATH_SERVER)) != 0 &&
3015 strncmp(path, BT_SESSION_BASEPATH_CLIENT,
3016 strlen(BT_SESSION_BASEPATH_CLIENT)) != 0) {
3017 BT_DBG("DBUS_HANDLER_RESULT_NOT_YET_HANDLED");
3021 _bt_handle_property_changed_event(parameters, path);
3027 static gboolean __bt_is_obexd_client_event(GVariant *msg, const char *interface)
3031 if (g_strcmp0(interface, BT_PROPERTIES_INTERFACE) == 0) {
3032 char *interface_name = NULL;
3034 g_variant_get(msg, "(&s@a{sv}@as)", &interface_name, NULL, NULL);
3036 retv_if(interface_name == NULL, FALSE);
3038 if (strcasecmp(interface_name,
3039 BT_OBEX_TRANSFER_INTERFACE) == 0) {
3050 static void __bt_opc_event_filter(GDBusConnection *connection,
3051 const gchar *sender_name,
3052 const gchar *object_path,
3053 const gchar *interface_name,
3054 const gchar *signal_name,
3055 GVariant *parameters,
3058 const char *member = signal_name;
3059 char *obj_path = NULL;
3060 if (strcasecmp(member, "InterfacesAdded") == 0) {
3061 BT_DBG("InterfacesAdded");
3062 } else if (strcasecmp(member, "InterfacesRemoved") == 0) {
3064 if (__bt_get_object_path(parameters, &obj_path)) {
3065 BT_ERR("Fail to get the path");
3069 BT_DBG("object_path = %s", obj_path);
3071 if (strncmp(obj_path, BT_SESSION_BASEPATH_CLIENT,
3072 strlen(BT_SESSION_BASEPATH_CLIENT)) != 0
3073 || strstr(obj_path, "transfer") == NULL) {
3076 } else if (strncmp(obj_path, BT_SESSION_BASEPATH_CLIENT,
3077 strlen(BT_SESSION_BASEPATH_CLIENT)) == 0) {
3078 BT_DBG("Going to call opc disconnected");
3079 _bt_opc_disconnected(obj_path);
3082 _bt_sending_files();
3084 } else if (__bt_is_obexd_client_event(parameters, interface_name) == TRUE) {
3085 char *path = (char *)object_path;
3086 BT_INFO("object_path %s", path);
3087 if (strncmp(path, BT_SESSION_BASEPATH_CLIENT,
3088 strlen(BT_SESSION_BASEPATH_CLIENT)) != 0) {
3089 BT_DBG("NOT BT_SESSION_BASEPATH_CLIENT");
3093 _bt_opc_property_changed_event(parameters, path);
3099 int _bt_opp_client_event_init(void)
3101 GError *error = NULL;
3103 if (opc_obexd_conn == NULL) {
3104 opc_obexd_conn = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &error);
3106 if (!opc_obexd_conn) {
3108 BT_ERR("Unable to connect to dbus: %s", error->message);
3109 g_clear_error(&error);
3111 return BLUETOOTH_ERROR_INTERNAL;
3115 if (_bt_register_service_event(opc_obexd_conn,
3116 BT_OPP_CLIENT_EVENT) != BLUETOOTH_ERROR_NONE) {
3117 g_object_unref(opc_obexd_conn);
3118 opc_obexd_conn = NULL;
3119 return BLUETOOTH_ERROR_INTERNAL;
3122 return BLUETOOTH_ERROR_NONE;
3125 void _bt_opp_client_event_deinit(void)
3127 if (opc_obexd_conn) {
3128 _bt_unregister_service_event(opc_obexd_conn,
3129 BT_OPP_CLIENT_EVENT);
3130 g_object_unref(opc_obexd_conn);
3131 opc_obexd_conn = NULL;
3135 static void __bt_map_event_filter(GDBusConnection *connection,
3136 const gchar *sender_name,
3137 const gchar *object_path,
3138 const gchar *interface_name,
3139 const gchar *signal_name,
3140 GVariant *parameters,
3143 BT_DBG("Entered __bt_map_event_filter");
3144 const char *member = signal_name;
3146 if (strcasecmp(member, "InterfacesAdded") == 0) {
3147 BT_DBG("------------------------------------ADDED------------------------------------");
3148 // currently doing nothing
3149 } else if (strcasecmp(member, "InterfacesRemoved") == 0) {
3150 BT_DBG("------------------------------------REMOVED------------------------------------");
3151 // TODO check if something should be called here?
3152 //_bt_map_on_transfer_finished(object_path, error);
3153 } else if (__bt_is_obexd_client_event(parameters, interface_name) == TRUE) {
3154 BT_DBG("------------------------------------CLIENT EVENT------------------------------------");
3155 _bt_map_property_changed_event(parameters, object_path);
3161 int _bt_map_client_event_init(void)
3163 GError *error = NULL;
3165 if (map_obexd_conn == NULL) {
3166 map_obexd_conn = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &error);
3168 if (!map_obexd_conn) {
3170 BT_ERR("Unable to connect to dbus: %s", error->message);
3171 g_clear_error(&error);
3173 return BLUETOOTH_ERROR_INTERNAL;
3177 if (_bt_register_service_event(map_obexd_conn,
3178 BT_MAP_CLIENT_EVENT) != BLUETOOTH_ERROR_NONE) {
3179 g_object_unref(map_obexd_conn);
3180 map_obexd_conn = NULL;
3181 return BLUETOOTH_ERROR_INTERNAL;
3184 return BLUETOOTH_ERROR_NONE;
3187 void _bt_map_client_event_deinit(void)
3189 if (map_obexd_conn) {
3190 _bt_unregister_service_event(map_obexd_conn,
3191 BT_MAP_CLIENT_EVENT);
3192 g_object_unref(map_obexd_conn);
3193 map_obexd_conn = NULL;
3197 int _bt_register_manager_subscribe_signal(GDBusConnection *conn,
3203 static int subs_interface_added_id = -1;
3204 static int subs_interface_removed_id = -1;
3205 static int subs_name_owner_id = -1;
3206 static int subs_property_id = -1;
3207 static int subs_adapter_id = -1;
3208 static int subs_gatt_id = -1;
3211 if (subs_interface_added_id == -1) {
3212 subs_interface_added_id = g_dbus_connection_signal_subscribe(conn,
3213 NULL, BT_MANAGER_INTERFACE,
3214 BT_INTERFACES_ADDED, NULL, NULL, 0,
3215 __bt_manager_event_filter,
3218 if (subs_interface_removed_id == -1) {
3219 subs_interface_removed_id = g_dbus_connection_signal_subscribe(conn,
3220 NULL, BT_MANAGER_INTERFACE,
3221 BT_INTERFACES_REMOVED, NULL, NULL, 0,
3222 __bt_manager_event_filter,
3225 if (subs_name_owner_id == -1) {
3226 subs_name_owner_id = g_dbus_connection_signal_subscribe(conn,
3227 NULL, BT_FREEDESKTOP_INTERFACE,
3228 BT_NAME_OWNER_CHANGED, NULL, NULL, 0,
3229 __bt_manager_event_filter,
3232 if (subs_property_id == -1) {
3233 subs_property_id = g_dbus_connection_signal_subscribe(conn,
3234 NULL, BT_PROPERTIES_INTERFACE,
3235 BT_PROPERTIES_CHANGED, NULL, NULL, 0,
3236 __bt_manager_event_filter,
3239 if (subs_adapter_id == -1) {
3240 subs_adapter_id = g_dbus_connection_signal_subscribe(conn,
3241 NULL, BT_ADAPTER_INTERFACE,
3242 NULL, NULL, NULL, 0,
3243 __bt_manager_event_filter,
3246 if (subs_gatt_id == -1) {
3247 subs_gatt_id = g_dbus_connection_signal_subscribe(conn,
3248 NULL, BT_GATT_CHAR_INTERFACE,
3249 NULL, NULL, NULL, 0,
3250 __bt_manager_event_filter,
3254 if (subs_interface_added_id != -1) {
3255 g_dbus_connection_signal_unsubscribe(conn,
3256 subs_interface_added_id);
3257 subs_interface_added_id = -1;
3259 if (subs_interface_removed_id != -1) {
3260 g_dbus_connection_signal_unsubscribe(conn,
3261 subs_interface_removed_id);
3262 subs_interface_removed_id = -1;
3264 if (subs_name_owner_id != -1) {
3265 g_dbus_connection_signal_unsubscribe(conn,
3266 subs_name_owner_id);
3267 subs_name_owner_id = -1;
3269 if (subs_property_id != -1) {
3270 g_dbus_connection_signal_unsubscribe(conn,
3272 subs_property_id = -1;
3274 if (subs_adapter_id != -1) {
3275 g_dbus_connection_signal_unsubscribe(conn, subs_adapter_id);
3276 subs_adapter_id = -1;
3278 if (subs_gatt_id != -1) {
3279 g_dbus_connection_signal_unsubscribe(conn, subs_gatt_id);
3286 int _bt_register_device_subscribe_signal(GDBusConnection *conn,
3292 static int subs_device_id = -1;
3295 if (subs_device_id == -1) {
3296 subs_device_id = g_dbus_connection_signal_subscribe(conn,
3297 NULL, BT_DEVICE_INTERFACE,
3298 NULL, NULL, NULL, 0,
3299 __bt_manager_event_filter,
3303 if (subs_device_id != -1) {
3304 g_dbus_connection_signal_unsubscribe(conn,
3306 subs_device_id = -1;
3312 int _bt_register_input_subscribe_signal(GDBusConnection *conn,
3318 static int subs_input_id = -1;
3321 if (subs_input_id == -1) {
3322 subs_input_id = g_dbus_connection_signal_subscribe(conn,
3323 NULL, BT_INPUT_INTERFACE,
3324 NULL, NULL, NULL, 0,
3325 __bt_manager_event_filter,
3329 if (subs_input_id != -1) {
3330 g_dbus_connection_signal_unsubscribe(conn,
3338 int _bt_register_network_subscribe_signal(GDBusConnection *conn,
3344 static int subs_serv_id = -1;
3345 static int subs_client_id = -1;
3348 if (subs_serv_id == -1) {
3349 subs_serv_id = g_dbus_connection_signal_subscribe(conn,
3350 NULL, BT_NETWORK_SERVER_INTERFACE,
3351 NULL, NULL, NULL, 0,
3352 __bt_manager_event_filter,
3355 if (subs_client_id == -1) {
3356 subs_client_id = g_dbus_connection_signal_subscribe(conn,
3357 NULL, BT_NETWORK_CLIENT_INTERFACE,
3358 NULL, NULL, NULL, 0,
3359 __bt_manager_event_filter,
3363 if (subs_serv_id != -1) {
3364 g_dbus_connection_signal_unsubscribe(conn,
3368 if (subs_client_id != -1) {
3369 g_dbus_connection_signal_unsubscribe(conn,
3371 subs_client_id = -1;
3377 int _bt_register_audio_subscribe_signal(GDBusConnection *conn,
3383 static int subs_headset_id = -1;
3384 static int subs_sink_id = -1;
3387 if (subs_headset_id == -1) {
3388 subs_headset_id = g_dbus_connection_signal_subscribe(conn,
3389 NULL, BT_HEADSET_INTERFACE,
3390 NULL, NULL, NULL, 0,
3391 __bt_manager_event_filter,
3394 if (subs_sink_id == -1) {
3395 subs_sink_id = g_dbus_connection_signal_subscribe(conn,
3396 NULL, BT_SINK_INTERFACE,
3397 NULL, NULL, NULL, 0,
3398 __bt_manager_event_filter,
3402 if (subs_headset_id != -1) {
3403 g_dbus_connection_signal_unsubscribe(conn,
3405 subs_headset_id = -1;
3407 if (subs_sink_id != -1) {
3408 g_dbus_connection_signal_unsubscribe(conn,
3416 int _bt_register_opp_server_subscribe_signal(GDBusConnection *conn,
3422 static int subs_opp_server_interface_added_id = -1;
3423 static int subs_opp_server_interface_removed_id = -1;
3424 static int subs_opp_server_property_id = -1;
3428 if (subs_opp_server_interface_added_id == -1) {
3429 subs_opp_server_interface_added_id = g_dbus_connection_signal_subscribe(conn,
3430 NULL, BT_MANAGER_INTERFACE,
3431 BT_INTERFACES_ADDED, NULL, NULL, 0,
3432 __bt_obexd_event_filter,
3435 if (subs_opp_server_interface_removed_id == -1) {
3436 subs_opp_server_interface_removed_id = g_dbus_connection_signal_subscribe(conn,
3437 NULL, BT_MANAGER_INTERFACE,
3438 BT_INTERFACES_REMOVED, NULL, NULL, 0,
3439 __bt_obexd_event_filter,
3442 if (subs_opp_server_property_id == -1) {
3443 subs_opp_server_property_id = g_dbus_connection_signal_subscribe(conn,
3444 NULL, BT_PROPERTIES_INTERFACE,
3445 BT_PROPERTIES_CHANGED, NULL, NULL, 0,
3446 __bt_obexd_event_filter,
3450 if (subs_opp_server_interface_added_id != -1) {
3451 g_dbus_connection_signal_unsubscribe(conn,
3452 subs_opp_server_interface_added_id);
3453 subs_opp_server_interface_added_id = -1;
3455 if (subs_opp_server_interface_removed_id != -1) {
3456 g_dbus_connection_signal_unsubscribe(conn,
3457 subs_opp_server_interface_removed_id);
3458 subs_opp_server_interface_removed_id = -1;
3460 if (subs_opp_server_property_id != -1) {
3461 g_dbus_connection_signal_unsubscribe(conn,
3462 subs_opp_server_property_id);
3463 subs_opp_server_property_id = -1;
3469 int _bt_register_opp_client_subscribe_signal(GDBusConnection *conn,
3475 static int subs_opp_client_interface_added_id = -1;
3476 static int subs_opp_client_interface_removed_id = -1;
3477 static int subs_opp_client_property_id = -1;
3481 if (subs_opp_client_interface_added_id == -1) {
3482 subs_opp_client_interface_added_id = g_dbus_connection_signal_subscribe(conn,
3483 NULL, BT_MANAGER_INTERFACE,
3484 BT_INTERFACES_ADDED, NULL, NULL, 0,
3485 __bt_opc_event_filter,
3488 if (subs_opp_client_interface_removed_id == -1) {
3489 subs_opp_client_interface_removed_id = g_dbus_connection_signal_subscribe(conn,
3490 NULL, BT_MANAGER_INTERFACE,
3491 BT_INTERFACES_REMOVED, NULL, NULL, 0,
3492 __bt_opc_event_filter,
3495 if (subs_opp_client_property_id == -1) {
3496 subs_opp_client_property_id = g_dbus_connection_signal_subscribe(conn,
3497 NULL, BT_PROPERTIES_INTERFACE,
3498 BT_PROPERTIES_CHANGED, NULL, NULL, 0,
3499 __bt_opc_event_filter,
3503 if (subs_opp_client_interface_added_id != -1) {
3504 g_dbus_connection_signal_unsubscribe(conn,
3505 subs_opp_client_interface_added_id);
3506 subs_opp_client_interface_added_id = -1;
3508 if (subs_opp_client_interface_removed_id != -1) {
3509 g_dbus_connection_signal_unsubscribe(conn,
3510 subs_opp_client_interface_removed_id);
3511 subs_opp_client_interface_removed_id = -1;
3513 if (subs_opp_client_property_id != -1) {
3514 g_dbus_connection_signal_unsubscribe(conn,
3515 subs_opp_client_property_id);
3516 subs_opp_client_property_id = -1;
3522 int _bt_register_map_client_subscribe_signal(GDBusConnection *conn,
3528 static int subs_map_client_interface_added_id = -1;
3529 static int subs_map_client_interface_removed_id = -1;
3530 static int subs_map_client_property_id = -1;
3534 if (subs_map_client_interface_added_id == -1) {
3535 subs_map_client_interface_added_id = g_dbus_connection_signal_subscribe(conn,
3536 NULL, BT_MANAGER_INTERFACE,
3537 BT_INTERFACES_ADDED, NULL, NULL, 0,
3538 __bt_map_event_filter,
3541 if (subs_map_client_interface_removed_id == -1) {
3542 subs_map_client_interface_removed_id = g_dbus_connection_signal_subscribe(conn,
3543 NULL, BT_MANAGER_INTERFACE,
3544 BT_INTERFACES_REMOVED, NULL, NULL, 0,
3545 __bt_map_event_filter,
3548 if (subs_map_client_property_id == -1) {
3549 subs_map_client_property_id = g_dbus_connection_signal_subscribe(conn,
3550 NULL, BT_PROPERTIES_INTERFACE,
3551 BT_PROPERTIES_CHANGED, NULL, NULL, 0,
3552 __bt_map_event_filter,
3556 if (subs_map_client_interface_added_id != -1) {
3557 g_dbus_connection_signal_unsubscribe(conn,
3558 subs_map_client_interface_added_id);
3559 subs_map_client_interface_added_id = -1;
3561 if (subs_map_client_interface_removed_id != -1) {
3562 g_dbus_connection_signal_unsubscribe(conn,
3563 subs_map_client_interface_removed_id);
3564 subs_map_client_interface_removed_id = -1;
3566 if (subs_map_client_property_id != -1) {
3567 g_dbus_connection_signal_unsubscribe(conn,
3568 subs_map_client_property_id);
3569 subs_map_client_property_id = -1;
3575 int _bt_register_a2dp_subscribe_signal(GDBusConnection *conn,
3581 static int subs_a2dp_source_id = -1;
3582 static int subs_a2dp_sink_id = -1;
3585 if (subs_a2dp_source_id == -1) {
3586 subs_a2dp_source_id = g_dbus_connection_signal_subscribe(conn,
3587 NULL, BT_A2DP_SOURCE_INTERFACE,
3588 NULL, NULL, NULL, 0,
3589 __bt_opc_event_filter,
3592 if (subs_a2dp_sink_id == -1) {
3593 subs_a2dp_sink_id = g_dbus_connection_signal_subscribe(conn,
3594 NULL, BT_SINK_INTERFACE,
3595 NULL, NULL, NULL, 0,
3596 __bt_opc_event_filter,
3600 if (subs_a2dp_source_id != -1) {
3601 g_dbus_connection_signal_unsubscribe(conn,
3602 subs_a2dp_source_id);
3603 subs_a2dp_source_id = -1;
3605 if (subs_a2dp_sink_id != -1) {
3606 g_dbus_connection_signal_unsubscribe(conn,
3608 subs_a2dp_sink_id = -1;
3614 static void __bt_dump_event_filter(GDBusConnection *connection,
3615 const gchar *sender_name,
3616 const gchar *object_path,
3617 const gchar *interface_name,
3618 const gchar *signal_name,
3619 GVariant *parameters,
3625 int __bt_register_dump_subscribe_signal(GDBusConnection *conn,
3631 static int subs_source_id = -1;
3634 if (subs_source_id == -1) {
3635 subs_source_id = g_dbus_connection_signal_subscribe(conn,
3636 NULL, BT_DUMP_SERVICE_INTERFACE,
3637 BT_DUMP_SERVICE_SIGNAL, BT_DUMP_SERVICE_PATH, NULL, 0,
3638 __bt_dump_event_filter,
3642 if (subs_source_id != -1) {
3643 g_dbus_connection_signal_unsubscribe(conn,
3645 subs_source_id = -1;
3651 int _bt_register_service_event(GDBusConnection *g_conn, int event_type)
3655 retv_if(g_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
3657 switch (event_type) {
3658 case BT_MANAGER_EVENT:
3659 _bt_register_manager_subscribe_signal(g_conn, TRUE);
3661 case BT_DEVICE_EVENT:
3662 _bt_register_device_subscribe_signal(g_conn, TRUE);
3665 _bt_register_input_subscribe_signal(g_conn, TRUE);
3667 case BT_NETWORK_EVENT:
3668 _bt_register_network_subscribe_signal(g_conn, TRUE);
3670 case BT_HEADSET_EVENT:
3671 _bt_register_audio_subscribe_signal(g_conn, TRUE);
3673 case BT_OPP_SERVER_EVENT:
3674 BT_ERR("BT_OPP_SERVER_EVENT: register service event");
3675 _bt_register_opp_server_subscribe_signal(g_conn, TRUE);
3678 case BT_OPP_CLIENT_EVENT:
3679 BT_ERR("BT_OPP_CLIENT_EVENT: register service event");
3680 _bt_register_opp_client_subscribe_signal(g_conn, TRUE);
3682 case BT_MAP_CLIENT_EVENT:
3683 BT_ERR("BT_MAP_CLIENT_EVENT: register service event");
3684 _bt_register_map_client_subscribe_signal(g_conn, TRUE);
3686 case BT_A2DP_SOURCE_EVENT:
3687 BT_INFO("A2dp Source event");
3688 _bt_register_a2dp_subscribe_signal(g_conn, TRUE);
3691 BT_ERR("Unknown event");
3692 return BLUETOOTH_ERROR_INTERNAL;
3695 return BLUETOOTH_ERROR_NONE;
3698 void _bt_unregister_service_event(GDBusConnection *g_conn, int event_type)
3702 ret_if(g_conn == NULL);
3704 switch (event_type) {
3705 case BT_MANAGER_EVENT:
3706 _bt_register_manager_subscribe_signal(g_conn, FALSE);
3707 _bt_register_device_subscribe_signal(g_conn, FALSE);
3708 _bt_register_input_subscribe_signal(g_conn, FALSE);
3709 _bt_register_network_subscribe_signal(g_conn, FALSE);
3710 _bt_register_audio_subscribe_signal(g_conn, FALSE);
3712 case BT_OPP_SERVER_EVENT:
3713 _bt_register_opp_server_subscribe_signal(g_conn, FALSE);
3715 case BT_OPP_CLIENT_EVENT:
3716 _bt_register_opp_client_subscribe_signal(g_conn, FALSE);
3718 case BT_MAP_CLIENT_EVENT:
3719 _bt_register_map_client_subscribe_signal(g_conn, FALSE);
3722 BT_ERR("Unknown event");
3729 static int __bt_init_manager_receiver(void)
3733 GError *error = NULL;
3735 if (manager_conn == NULL) {
3736 manager_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
3737 if (error != NULL) {
3738 BT_ERR("ERROR: Can't get on system bus [%s]", error->message);
3739 g_clear_error(&error);
3741 retv_if(manager_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
3744 if (_bt_register_service_event(manager_conn,
3745 BT_MANAGER_EVENT) != BLUETOOTH_ERROR_NONE)
3747 if (_bt_register_service_event(manager_conn,
3748 BT_DEVICE_EVENT) != BLUETOOTH_ERROR_NONE)
3751 if (_bt_register_service_event(manager_conn,
3752 BT_HID_EVENT) != BLUETOOTH_ERROR_NONE)
3755 if (_bt_register_service_event(manager_conn,
3756 BT_HEADSET_EVENT) != BLUETOOTH_ERROR_NONE)
3759 if (_bt_register_service_event(manager_conn,
3760 BT_NETWORK_EVENT) != BLUETOOTH_ERROR_NONE)
3763 __bt_register_dump_subscribe_signal(manager_conn, TRUE);
3764 return BLUETOOTH_ERROR_NONE;
3767 g_object_unref(manager_conn);
3768 manager_conn = NULL;
3773 return BLUETOOTH_ERROR_INTERNAL;
3776 static int __bt_init_obexd_receiver(void)
3779 #ifndef TIZEN_PROFILE_TV /* TODO: obexd doesn't work in TV profile. It should be resolved later. */
3780 GError *error = NULL;
3782 if (obexd_conn == NULL) {
3783 obexd_conn = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &error);
3784 if (error != NULL) {
3785 BT_ERR("ERROR: Can't get on session bus [%s]", error->message);
3786 g_clear_error(&error);
3788 retv_if(obexd_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
3791 if (_bt_register_service_event(obexd_conn,
3792 BT_OPP_SERVER_EVENT) != BLUETOOTH_ERROR_NONE) {
3793 BT_ERR("Error while registering service event");
3794 g_object_unref(obexd_conn);
3796 return BLUETOOTH_ERROR_INTERNAL;
3801 return BLUETOOTH_ERROR_NONE;
3804 gboolean __bt_reinit_obexd_receiver(gpointer user_data)
3806 static int retry_cnt = 0;
3807 int result = BLUETOOTH_ERROR_NONE;
3811 result = __bt_init_obexd_receiver();
3812 if (result != BLUETOOTH_ERROR_NONE) {
3813 /* 20 ms * 50 = 10 seconds. During 10 seconds fail to initialize,
3814 then it is not the timing issue. Just can't use the session bus connection */
3815 if (retry_cnt > 100) {
3816 BT_ERR("Fail to init obexd receiver by 50 times.");
3818 session_reinit_timer = 0;
3822 BT_DBG("Retry to initialize the obexd receiver");
3827 session_reinit_timer = 0;
3834 /* To receive the event from bluez */
3835 int _bt_init_service_event_receiver(void)
3841 result = __bt_init_manager_receiver();
3842 retv_if(result != BLUETOOTH_ERROR_NONE, result);
3844 result = __bt_init_obexd_receiver();
3845 if (result != BLUETOOTH_ERROR_NONE) {
3846 BT_ERR("Fail to init obexd receiver");
3848 /* Try to re-initialize obexd receiver in the timer */
3849 if (session_reinit_timer > 0)
3850 g_source_remove(session_reinit_timer);
3852 session_reinit_timer = g_timeout_add(BT_SESSION_BUS_GET_TIMEOUT,
3853 (GSourceFunc)__bt_reinit_obexd_receiver, NULL);
3858 return BLUETOOTH_ERROR_NONE;
3861 void _bt_deinit_service_event_receiver(void)
3865 _bt_unregister_service_event(manager_conn, BT_MANAGER_EVENT);
3867 _bt_unregister_service_event(obexd_conn, BT_OPP_SERVER_EVENT);
3869 __bt_register_dump_subscribe_signal(manager_conn, FALSE);
3872 g_object_unref(manager_conn);
3873 manager_conn = NULL;
3877 g_object_unref(obexd_conn);
3882 g_source_remove(event_id);
3885 if (le_scan_event_id > 0)
3886 g_source_remove(le_scan_event_id);
3887 le_scan_event_id = 0;